File: | dev/pci/if_xl_pci.c |
Warning: | line 285, column 4 3rd function call argument is an uninitialized value |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | /* $OpenBSD: if_xl_pci.c,v 1.48 2022/03/11 18:00:50 mpi Exp $ */ | |||
2 | ||||
3 | /* | |||
4 | * Copyright (c) 1997, 1998, 1999 | |||
5 | * Bill Paul <wpaul@ctr.columbia.edu>. All rights reserved. | |||
6 | * | |||
7 | * Redistribution and use in source and binary forms, with or without | |||
8 | * modification, are permitted provided that the following conditions | |||
9 | * are met: | |||
10 | * 1. Redistributions of source code must retain the above copyright | |||
11 | * notice, this list of conditions and the following disclaimer. | |||
12 | * 2. Redistributions in binary form must reproduce the above copyright | |||
13 | * notice, this list of conditions and the following disclaimer in the | |||
14 | * documentation and/or other materials provided with the distribution. | |||
15 | * 3. All advertising materials mentioning features or use of this software | |||
16 | * must display the following acknowledgement: | |||
17 | * This product includes software developed by Bill Paul. | |||
18 | * 4. Neither the name of the author nor the names of any co-contributors | |||
19 | * may be used to endorse or promote products derived from this software | |||
20 | * without specific prior written permission. | |||
21 | * | |||
22 | * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND | |||
23 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |||
24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |||
25 | * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD | |||
26 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |||
27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |||
28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |||
29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |||
30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |||
31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | |||
32 | * THE POSSIBILITY OF SUCH DAMAGE. | |||
33 | * | |||
34 | * $FreeBSD: if_xl.c,v 1.72 2000/01/09 21:12:59 wpaul Exp $ | |||
35 | */ | |||
36 | ||||
37 | #include "bpfilter.h" | |||
38 | ||||
39 | #include <sys/param.h> | |||
40 | #include <sys/systm.h> | |||
41 | #include <sys/mbuf.h> | |||
42 | #include <sys/socket.h> | |||
43 | #include <sys/ioctl.h> | |||
44 | #include <sys/errno.h> | |||
45 | #include <sys/malloc.h> | |||
46 | #include <sys/kernel.h> | |||
47 | #include <sys/device.h> | |||
48 | ||||
49 | #include <net/if.h> | |||
50 | #include <net/if_media.h> | |||
51 | ||||
52 | #include <netinet/in.h> | |||
53 | #include <netinet/if_ether.h> | |||
54 | ||||
55 | #include <dev/mii/miivar.h> | |||
56 | #include <dev/pci/pcireg.h> | |||
57 | #include <dev/pci/pcivar.h> | |||
58 | #include <dev/pci/pcidevs.h> | |||
59 | ||||
60 | #if NBPFILTER1 > 0 | |||
61 | #include <net/bpf.h> | |||
62 | #endif | |||
63 | ||||
64 | /* | |||
65 | * The following #define causes the code to use PIO to access the | |||
66 | * chip's registers instead of memory mapped mode. The reason PIO mode | |||
67 | * is on by default is that the Etherlink XL manual seems to indicate | |||
68 | * that only the newer revision chips (3c905B) support both PIO and | |||
69 | * memory mapped access. Since we want to be compatible with the older | |||
70 | * bus master chips, we use PIO here. If you comment this out, the | |||
71 | * driver will use memory mapped I/O, which may be faster but which | |||
72 | * might not work on some devices. | |||
73 | */ | |||
74 | #define XL_USEIOSPACE | |||
75 | ||||
76 | #define XL_PCI_FUNCMEM0x0018 0x0018 | |||
77 | #define XL_PCI_INTR0x0004 0x0004 | |||
78 | #define XL_PCI_INTRACK0x8000 0x8000 | |||
79 | ||||
80 | #include <dev/ic/xlreg.h> | |||
81 | ||||
82 | int xl_pci_match(struct device *, void *, void *); | |||
83 | void xl_pci_attach(struct device *, struct device *, void *); | |||
84 | int xl_pci_detach(struct device *, int); | |||
85 | void xl_pci_intr_ack(struct xl_softc *); | |||
86 | #ifndef SMALL_KERNEL | |||
87 | void xl_pci_wol_power(void *); | |||
88 | #endif | |||
89 | ||||
90 | struct xl_pci_softc { | |||
91 | struct xl_softc psc_softc; | |||
92 | pci_chipset_tag_t psc_pc; | |||
93 | pcitag_t psc_tag; | |||
94 | bus_size_t psc_iosize; | |||
95 | bus_size_t psc_funsize; | |||
96 | }; | |||
97 | ||||
98 | const struct cfattach xl_pci_ca = { | |||
99 | sizeof(struct xl_pci_softc), xl_pci_match, xl_pci_attach, | |||
100 | xl_pci_detach, xl_activate | |||
101 | }; | |||
102 | ||||
103 | const struct pci_matchid xl_pci_devices[] = { | |||
104 | { PCI_VENDOR_3COM0x10b7, PCI_PRODUCT_3COM_3CSOHO100TX0x7646 }, | |||
105 | { PCI_VENDOR_3COM0x10b7, PCI_PRODUCT_3COM_3C900TPO0x9000 }, | |||
106 | { PCI_VENDOR_3COM0x10b7, PCI_PRODUCT_3COM_3C900COMBO0x9001 }, | |||
107 | { PCI_VENDOR_3COM0x10b7, PCI_PRODUCT_3COM_3C900B0x9004 }, | |||
108 | { PCI_VENDOR_3COM0x10b7, PCI_PRODUCT_3COM_3C900BCOMBO0x9005 }, | |||
109 | { PCI_VENDOR_3COM0x10b7, PCI_PRODUCT_3COM_3C900BTPC0x9006 }, | |||
110 | { PCI_VENDOR_3COM0x10b7, PCI_PRODUCT_3COM_3C900BFL0x900a }, | |||
111 | { PCI_VENDOR_3COM0x10b7, PCI_PRODUCT_3COM_3C905TX0x9050 }, | |||
112 | { PCI_VENDOR_3COM0x10b7, PCI_PRODUCT_3COM_3C905T40x9051 }, | |||
113 | { PCI_VENDOR_3COM0x10b7, PCI_PRODUCT_3COM_3C905BTX0x9055 }, | |||
114 | { PCI_VENDOR_3COM0x10b7, PCI_PRODUCT_3COM_3C905BT40x9056 }, | |||
115 | { PCI_VENDOR_3COM0x10b7, PCI_PRODUCT_3COM_3C905BCOMBO0x9058 }, | |||
116 | { PCI_VENDOR_3COM0x10b7, PCI_PRODUCT_3COM_3C905BFX0x905a }, | |||
117 | { PCI_VENDOR_3COM0x10b7, PCI_PRODUCT_3COM_3C980TX0x9800 }, | |||
118 | { PCI_VENDOR_3COM0x10b7, PCI_PRODUCT_3COM_3C980CTX0x9805 }, | |||
119 | { PCI_VENDOR_3COM0x10b7, PCI_PRODUCT_3COM_3C905CTX0x9200 }, | |||
120 | { PCI_VENDOR_3COM0x10b7, PCI_PRODUCT_3COM_3C4500x4500 }, | |||
121 | { PCI_VENDOR_3COM0x10b7, PCI_PRODUCT_3COM_3C5550x5055 }, | |||
122 | { PCI_VENDOR_3COM0x10b7, PCI_PRODUCT_3COM_3C5560x6055 }, | |||
123 | { PCI_VENDOR_3COM0x10b7, PCI_PRODUCT_3COM_3C556B0x6056 }, | |||
124 | { PCI_VENDOR_3COM0x10b7, PCI_PRODUCT_3COM_3C92010x9201 }, | |||
125 | { PCI_VENDOR_3COM0x10b7, PCI_PRODUCT_3COM_3C920BEMBW0x9202 }, | |||
126 | { PCI_VENDOR_3COM0x10b7, PCI_PRODUCT_3COM_3C5750x5057 }, | |||
127 | { PCI_VENDOR_3COM0x10b7, PCI_PRODUCT_3COM_3CCFE575BT0x5157 }, | |||
128 | { PCI_VENDOR_3COM0x10b7, PCI_PRODUCT_3COM_3CCFE575CT0x5257 }, | |||
129 | { PCI_VENDOR_3COM0x10b7, PCI_PRODUCT_3COM_3CCFEM6560x6560 }, | |||
130 | { PCI_VENDOR_3COM0x10b7, PCI_PRODUCT_3COM_3CCFEM656B0x6562 }, | |||
131 | { PCI_VENDOR_3COM0x10b7, PCI_PRODUCT_3COM_3CCFEM656C0x6564 }, | |||
132 | }; | |||
133 | ||||
134 | int | |||
135 | xl_pci_match(struct device *parent, void *match, void *aux) | |||
136 | { | |||
137 | return (pci_matchbyid((struct pci_attach_args *)aux, xl_pci_devices, | |||
138 | nitems(xl_pci_devices)(sizeof((xl_pci_devices)) / sizeof((xl_pci_devices)[0])))); | |||
139 | } | |||
140 | ||||
141 | void | |||
142 | xl_pci_attach(struct device *parent, struct device *self, void *aux) | |||
143 | { | |||
144 | struct xl_pci_softc *psc = (void *)self; | |||
145 | struct xl_softc *sc = &psc->psc_softc; | |||
146 | struct pci_attach_args *pa = aux; | |||
147 | pci_chipset_tag_t pc = pa->pa_pc; | |||
148 | pci_intr_handle_t ih; | |||
149 | const char *intrstr = NULL((void *)0); | |||
150 | bus_size_t iosize, funsize; | |||
| ||||
151 | #ifndef SMALL_KERNEL | |||
152 | u_int32_t command; | |||
153 | #endif | |||
154 | ||||
155 | psc->psc_pc = pc; | |||
156 | psc->psc_tag = pa->pa_tag; | |||
157 | sc->sc_dmat = pa->pa_dmat; | |||
158 | ||||
159 | sc->xl_flags = 0; | |||
160 | sc->wol_power = sc->wol_power_arg = NULL((void *)0); | |||
161 | ||||
162 | /* set required flags */ | |||
163 | switch (PCI_PRODUCT(pa->pa_id)(((pa->pa_id) >> 16) & 0xffff)) { | |||
164 | case TC_DEVICEID_HURRICANE_5550x5055: | |||
165 | sc->xl_flags |= XL_FLAG_EEPROM_OFFSET_300x0004 | XL_FLAG_8BITROM0x0010; | |||
166 | break; | |||
167 | case TC_DEVICEID_HURRICANE_5560x6055: | |||
168 | sc->xl_flags |= XL_FLAG_FUNCREG0x0001 | XL_FLAG_PHYOK0x0002 | | |||
169 | XL_FLAG_EEPROM_OFFSET_300x0004 | XL_FLAG_WEIRDRESET0x0008; | |||
170 | sc->xl_flags |= XL_FLAG_INVERT_LED_PWR0x0020|XL_FLAG_INVERT_MII_PWR0x0040; | |||
171 | sc->xl_flags |= XL_FLAG_8BITROM0x0010; | |||
172 | break; | |||
173 | case TC_DEVICEID_HURRICANE_556B0x6056: | |||
174 | sc->xl_flags |= XL_FLAG_FUNCREG0x0001 | XL_FLAG_PHYOK0x0002 | | |||
175 | XL_FLAG_EEPROM_OFFSET_300x0004 | XL_FLAG_WEIRDRESET0x0008; | |||
176 | sc->xl_flags |= XL_FLAG_INVERT_LED_PWR0x0020|XL_FLAG_INVERT_MII_PWR0x0040; | |||
177 | break; | |||
178 | case PCI_PRODUCT_3COM_3C92010x9201: | |||
179 | case PCI_PRODUCT_3COM_3C920BEMBW0x9202: | |||
180 | sc->xl_flags |= XL_FLAG_PHYOK0x0002; | |||
181 | break; | |||
182 | case TC_DEVICEID_BOOMERANG_10_100BT0x9050: | |||
183 | sc->xl_flags |= XL_FLAG_NO_MMIO0x0200; | |||
184 | break; | |||
185 | case PCI_PRODUCT_3COM_3C5750x5057: | |||
186 | sc->xl_flags |= XL_FLAG_PHYOK0x0002 | XL_FLAG_EEPROM_OFFSET_300x0004 | | |||
187 | XL_FLAG_8BITROM0x0010; | |||
188 | break; | |||
189 | case PCI_PRODUCT_3COM_3CCFE575BT0x5157: | |||
190 | sc->xl_flags = XL_FLAG_PHYOK0x0002 | XL_FLAG_EEPROM_OFFSET_300x0004 | | |||
191 | XL_FLAG_8BITROM0x0010 | XL_FLAG_INVERT_LED_PWR0x0020; | |||
192 | sc->xl_flags |= XL_FLAG_FUNCREG0x0001; | |||
193 | break; | |||
194 | case PCI_PRODUCT_3COM_3CCFE575CT0x5257: | |||
195 | sc->xl_flags = XL_FLAG_PHYOK0x0002 | XL_FLAG_EEPROM_OFFSET_300x0004 | | |||
196 | XL_FLAG_8BITROM0x0010 | XL_FLAG_INVERT_MII_PWR0x0040; | |||
197 | sc->xl_flags |= XL_FLAG_FUNCREG0x0001; | |||
198 | break; | |||
199 | case PCI_PRODUCT_3COM_3CCFEM6560x6560: | |||
200 | sc->xl_flags = XL_FLAG_PHYOK0x0002 | XL_FLAG_EEPROM_OFFSET_300x0004 | | |||
201 | XL_FLAG_8BITROM0x0010 | XL_FLAG_INVERT_LED_PWR0x0020 | | |||
202 | XL_FLAG_INVERT_MII_PWR0x0040; | |||
203 | sc->xl_flags |= XL_FLAG_FUNCREG0x0001; | |||
204 | break; | |||
205 | case PCI_PRODUCT_3COM_3CCFEM656B0x6562: | |||
206 | sc->xl_flags = XL_FLAG_PHYOK0x0002 | XL_FLAG_EEPROM_OFFSET_300x0004 | | |||
207 | XL_FLAG_8BITROM0x0010 | XL_FLAG_INVERT_LED_PWR0x0020 | | |||
208 | XL_FLAG_INVERT_MII_PWR0x0040; | |||
209 | sc->xl_flags |= XL_FLAG_FUNCREG0x0001; | |||
210 | break; | |||
211 | case PCI_PRODUCT_3COM_3CCFEM656C0x6564: | |||
212 | sc->xl_flags = XL_FLAG_PHYOK0x0002 | XL_FLAG_EEPROM_OFFSET_300x0004 | | |||
213 | XL_FLAG_8BITROM0x0010 | XL_FLAG_INVERT_MII_PWR0x0040; | |||
214 | sc->xl_flags |= XL_FLAG_FUNCREG0x0001; | |||
215 | break; | |||
216 | default: | |||
217 | break; | |||
218 | } | |||
219 | ||||
220 | pci_set_powerstate(pa->pa_pc, pa->pa_tag, PCI_PMCSR_STATE_D00x0000); | |||
221 | ||||
222 | #ifndef SMALL_KERNEL | |||
223 | /* | |||
224 | * The card is WOL-capable if it supports PME# assertion | |||
225 | * from D3hot power state. Install a callback to configure | |||
226 | * PCI power state for WOL. It will be invoked when the | |||
227 | * interface stops and WOL was enabled. | |||
228 | */ | |||
229 | command = pci_conf_read(pc, pa->pa_tag, XL_PCI_CAPID0xDC); | |||
230 | if ((command >> 16) & XL_PME_CAP_D3_HOT0x4000) { | |||
231 | sc->wol_power = xl_pci_wol_power; | |||
232 | sc->wol_power_arg = psc; | |||
233 | } | |||
234 | #endif | |||
235 | ||||
236 | /* | |||
237 | * Map control/status registers. | |||
238 | */ | |||
239 | #ifdef XL_USEIOSPACE | |||
240 | if (pci_mapreg_map(pa, XL_PCI_LOIO0x10, PCI_MAPREG_TYPE_IO0x00000001, 0, | |||
241 | &sc->xl_btag, &sc->xl_bhandle, NULL((void *)0), &iosize, 0)) { | |||
242 | printf(": can't map i/o space\n"); | |||
243 | return; | |||
244 | } | |||
245 | #else | |||
246 | if (pci_mapreg_map(pa, XL_PCI_LOMEM0x14, PCI_MAPREG_TYPE_MEM0x00000000, 0, | |||
247 | &sc->xl_btag, &sc->xl_bhandle, NULL((void *)0), &iosize, 0)) { | |||
248 | printf(": can't map i/o space\n"); | |||
249 | return; | |||
250 | } | |||
251 | #endif | |||
252 | psc->psc_iosize = iosize; | |||
253 | ||||
254 | if (sc->xl_flags & XL_FLAG_FUNCREG0x0001) { | |||
255 | if (pci_mapreg_map(pa, XL_PCI_FUNCMEM0x0018, PCI_MAPREG_TYPE_MEM0x00000000, 0, | |||
256 | &sc->xl_funct, &sc->xl_funch, NULL((void *)0), &funsize, 0)) { | |||
257 | printf(": can't map i/o space\n"); | |||
258 | bus_space_unmap(sc->xl_btag, sc->xl_bhandle, iosize); | |||
259 | return; | |||
260 | } | |||
261 | psc->psc_funsize = funsize; | |||
262 | sc->intr_ack = xl_pci_intr_ack; | |||
263 | } | |||
264 | ||||
265 | /* | |||
266 | * Allocate our interrupt. | |||
267 | */ | |||
268 | if (pci_intr_map(pa, &ih)) { | |||
269 | printf(": couldn't map interrupt\n"); | |||
270 | bus_space_unmap(sc->xl_btag, sc->xl_bhandle, iosize); | |||
271 | if (sc->xl_flags & XL_FLAG_FUNCREG0x0001) | |||
272 | bus_space_unmap(sc->xl_funct, sc->xl_funch, funsize); | |||
273 | return; | |||
274 | } | |||
275 | ||||
276 | intrstr = pci_intr_string(pc, ih); | |||
277 | sc->xl_intrhand = pci_intr_establish(pc, ih, IPL_NET0x4, xl_intr, sc, | |||
278 | self->dv_xname); | |||
279 | if (sc->xl_intrhand == NULL((void *)0)) { | |||
280 | printf(": couldn't establish interrupt"); | |||
281 | if (intrstr != NULL((void *)0)) | |||
282 | printf(" at %s", intrstr); | |||
283 | bus_space_unmap(sc->xl_btag, sc->xl_bhandle, iosize); | |||
284 | if (sc->xl_flags & XL_FLAG_FUNCREG0x0001) | |||
285 | bus_space_unmap(sc->xl_funct, sc->xl_funch, funsize); | |||
| ||||
286 | return; | |||
287 | } | |||
288 | printf(": %s", intrstr); | |||
289 | ||||
290 | xl_attach(sc); | |||
291 | } | |||
292 | ||||
293 | int | |||
294 | xl_pci_detach(struct device *self, int flags) | |||
295 | { | |||
296 | struct xl_pci_softc *psc = (void *)self; | |||
297 | struct xl_softc *sc = &psc->psc_softc; | |||
298 | ||||
299 | if (sc->xl_intrhand != NULL((void *)0)) { | |||
300 | pci_intr_disestablish(psc->psc_pc, sc->xl_intrhand); | |||
301 | xl_detach(sc); | |||
302 | } | |||
303 | if (psc->psc_iosize > 0) | |||
304 | bus_space_unmap(sc->xl_btag, sc->xl_bhandle, psc->psc_iosize); | |||
305 | if (psc->psc_funsize > 0) | |||
306 | bus_space_unmap(sc->xl_funct, sc->xl_funch, psc->psc_funsize); | |||
307 | return (0); | |||
308 | } | |||
309 | ||||
310 | void | |||
311 | xl_pci_intr_ack(struct xl_softc *sc) | |||
312 | { | |||
313 | bus_space_write_4(sc->xl_funct, sc->xl_funch, XL_PCI_INTR,((sc->xl_funct)->write_4((sc->xl_funch), (0x0004), ( 0x8000))) | |||
314 | XL_PCI_INTRACK)((sc->xl_funct)->write_4((sc->xl_funch), (0x0004), ( 0x8000))); | |||
315 | } | |||
316 | ||||
317 | #ifndef SMALL_KERNEL | |||
318 | void | |||
319 | xl_pci_wol_power(void *ppsc) | |||
320 | { | |||
321 | struct xl_pci_softc *psc = (struct xl_pci_softc*)ppsc; | |||
322 | u_int32_t command; | |||
323 | ||||
324 | /* Make sure wake-up generation is enabled. */ | |||
325 | command = pci_conf_read(psc->psc_pc, psc->psc_tag, XL_PCI_PWRMGMTCTRL0xE0); | |||
326 | command |= XL_PME_EN0x0100; | |||
327 | pci_conf_write(psc->psc_pc, psc->psc_tag, XL_PCI_PWRMGMTCTRL0xE0, command); | |||
328 | } | |||
329 | #endif |