2 * Copyright (c) 2009-2010 Weongyo Jeong <weongyo@freebsd.org>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer,
10 * without modification.
11 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
12 * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
13 * redistribution must be conditioned upon including a substantially
14 * similar Disclaimer requirement for further binary redistribution.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
20 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
21 * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
22 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
27 * THE POSSIBILITY OF SUCH DAMAGES.
30 #include <sys/cdefs.h>
31 __FBSDID("$FreeBSD: head/sys/dev/siba/siba_bwn.c 257241 2013-10-28 07:29:16Z glebius $");
34 * Sonics Silicon Backplane front-end for bwn(4).
37 #include <sys/param.h>
38 #include <sys/systm.h>
39 #include <sys/malloc.h>
40 #include <sys/module.h>
41 #include <sys/kernel.h>
43 #include <sys/mutex.h>
44 #include <sys/errno.h>
45 #include <machine/bus.h>
46 #include <machine/resource.h>
49 #include <sys/socket.h>
52 #include <net/if_media.h>
53 #include <net/if_arp.h>
55 #include <dev/pci/pcivar.h>
56 #include <dev/pci/pcireg.h>
58 #include <dev/siba/siba_ids.h>
59 #include <dev/siba/sibareg.h>
60 #include <dev/siba/sibavar.h>
66 struct siba_bwn_softc {
67 /* Child driver using MSI. */
68 device_t ssc_msi_child;
69 struct siba_softc ssc_siba;
73 #define PCI_VENDOR_BROADCOM 0x14e4
74 #define N(a) (sizeof(a) / sizeof(a[0]))
76 static const struct siba_dev {
81 { PCI_VENDOR_BROADCOM, 0x4301, "Broadcom BCM4301 802.11b Wireless" },
82 { PCI_VENDOR_BROADCOM, 0x4306, "Unknown" },
83 { PCI_VENDOR_BROADCOM, 0x4307, "Broadcom BCM4307 802.11b Wireless" },
84 { PCI_VENDOR_BROADCOM, 0x4311, "Broadcom BCM4311 802.11b/g Wireless" },
85 { PCI_VENDOR_BROADCOM, 0x4312,
86 "Broadcom BCM4312 802.11a/b/g Wireless" },
87 { PCI_VENDOR_BROADCOM, 0x4315, "Broadcom BCM4312 802.11b/g Wireless" },
88 { PCI_VENDOR_BROADCOM, 0x4318, "Broadcom BCM4318 802.11b/g Wireless" },
89 { PCI_VENDOR_BROADCOM, 0x4319,
90 "Broadcom BCM4318 802.11a/b/g Wireless" },
91 { PCI_VENDOR_BROADCOM, 0x4320, "Broadcom BCM4306 802.11b/g Wireless" },
92 { PCI_VENDOR_BROADCOM, 0x4321, "Broadcom BCM4306 802.11a Wireless" },
93 { PCI_VENDOR_BROADCOM, 0x4324,
94 "Broadcom BCM4309 802.11a/b/g Wireless" },
95 { PCI_VENDOR_BROADCOM, 0x4325, "Broadcom BCM4306 802.11b/g Wireless" },
96 { PCI_VENDOR_BROADCOM, 0x4328, "Unknown" },
97 { PCI_VENDOR_BROADCOM, 0x4329, "Unknown" },
98 { PCI_VENDOR_BROADCOM, 0x432b, "Unknown" }
101 int siba_core_attach(struct siba_softc *);
102 int siba_core_detach(struct siba_softc *);
103 int siba_core_suspend(struct siba_softc *);
104 int siba_core_resume(struct siba_softc *);
107 siba_bwn_probe(device_t dev)
112 did = pci_get_device(dev);
113 vid = pci_get_vendor(dev);
115 for (i = 0; i < N(siba_devices); i++) {
116 if (siba_devices[i].did == did && siba_devices[i].vid == vid) {
117 device_set_desc(dev, siba_devices[i].desc);
118 return (BUS_PROBE_DEFAULT);
125 siba_bwn_attach(device_t dev)
127 struct siba_bwn_softc *ssc = device_get_softc(dev);
128 struct siba_softc *siba = &ssc->ssc_siba;
130 siba->siba_dev = dev;
131 siba->siba_type = SIBA_TYPE_PCI;
134 * Enable bus mastering.
136 pci_enable_busmaster(dev);
139 * Setup memory-mapping of PCI registers.
141 siba->siba_mem_rid = SIBA_PCIR_BAR;
142 siba->siba_mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY,
143 &siba->siba_mem_rid, RF_ACTIVE);
144 if (siba->siba_mem_res == NULL) {
145 device_printf(dev, "cannot map register space\n");
148 siba->siba_mem_bt = rman_get_bustag(siba->siba_mem_res);
149 siba->siba_mem_bh = rman_get_bushandle(siba->siba_mem_res);
151 /* Get more PCI information */
152 siba->siba_pci_did = pci_get_device(dev);
153 siba->siba_pci_vid = pci_get_vendor(dev);
154 siba->siba_pci_subvid = pci_get_subvendor(dev);
155 siba->siba_pci_subdid = pci_get_subdevice(dev);
156 siba->siba_pci_revid = pci_get_revid(dev);
158 return (siba_core_attach(siba));
162 siba_bwn_detach(device_t dev)
164 struct siba_bwn_softc *ssc = device_get_softc(dev);
165 struct siba_softc *siba = &ssc->ssc_siba;
167 /* check if device was removed */
168 siba->siba_invalid = !bus_child_present(dev);
170 pci_disable_busmaster(dev);
171 bus_generic_detach(dev);
172 siba_core_detach(siba);
174 bus_release_resource(dev, SYS_RES_MEMORY, BS_BAR, siba->siba_mem_res);
180 siba_bwn_shutdown(device_t dev)
183 int devcnt, error = 0, i;
185 error = device_get_children(dev, &devlistp, &devcnt);
189 for (i = 0 ; i < devcnt ; i++)
190 device_shutdown(devlistp[i]);
191 free(devlistp, M_TEMP);
196 siba_bwn_suspend(device_t dev)
198 struct siba_bwn_softc *ssc = device_get_softc(dev);
199 struct siba_softc *siba = &ssc->ssc_siba;
201 int devcnt, error = 0, i, j;
203 error = device_get_children(dev, &devlistp, &devcnt);
207 for (i = 0 ; i < devcnt ; i++) {
208 error = DEVICE_SUSPEND(devlistp[i]);
210 for (j = 0; j < i; j++)
211 DEVICE_RESUME(devlistp[j]);
212 free(devlistp, M_TEMP);
216 free(devlistp, M_TEMP);
217 return (siba_core_suspend(siba));
221 siba_bwn_resume(device_t dev)
223 struct siba_bwn_softc *ssc = device_get_softc(dev);
224 struct siba_softc *siba = &ssc->ssc_siba;
226 int devcnt, error = 0, i;
228 error = siba_core_resume(siba);
232 error = device_get_children(dev, &devlistp, &devcnt);
236 for (i = 0 ; i < devcnt ; i++)
237 DEVICE_RESUME(devlistp[i]);
238 free(devlistp, M_TEMP);
242 /* proxying to the parent */
243 static struct resource *
244 siba_bwn_alloc_resource(device_t dev, device_t child, int type, int *rid,
245 u_long start, u_long end, u_long count, u_int flags)
248 return (BUS_ALLOC_RESOURCE(device_get_parent(dev), dev,
249 type, rid, start, end, count, flags));
252 /* proxying to the parent */
254 siba_bwn_release_resource(device_t dev, device_t child, int type,
255 int rid, struct resource *r)
258 return (BUS_RELEASE_RESOURCE(device_get_parent(dev), dev, type,
262 /* proxying to the parent */
264 siba_bwn_setup_intr(device_t dev, device_t child, struct resource *irq,
265 int flags, driver_filter_t *filter, driver_intr_t *intr, void *arg,
269 return (BUS_SETUP_INTR(device_get_parent(dev), dev, irq, flags,
270 filter, intr, arg, cookiep));
273 /* proxying to the parent */
275 siba_bwn_teardown_intr(device_t dev, device_t child, struct resource *irq,
279 return (BUS_TEARDOWN_INTR(device_get_parent(dev), dev, irq, cookie));
283 siba_bwn_find_cap(device_t dev, device_t child, int capability,
287 return (pci_find_cap(dev, capability, capreg));
291 siba_bwn_find_extcap(device_t dev, device_t child, int capability,
295 return (pci_find_extcap(dev, capability, capreg));
299 siba_bwn_find_htcap(device_t dev, device_t child, int capability,
303 return (pci_find_htcap(dev, capability, capreg));
307 siba_bwn_alloc_msi(device_t dev, device_t child, int *count)
309 struct siba_bwn_softc *ssc;
312 ssc = device_get_softc(dev);
313 if (ssc->ssc_msi_child != NULL)
315 error = pci_alloc_msi(dev, count);
317 ssc->ssc_msi_child = child;
322 siba_bwn_release_msi(device_t dev, device_t child)
324 struct siba_bwn_softc *ssc;
327 ssc = device_get_softc(dev);
328 if (ssc->ssc_msi_child != child)
330 error = pci_release_msi(dev);
332 ssc->ssc_msi_child = NULL;
337 siba_bwn_msi_count(device_t dev, device_t child)
340 return (pci_msi_count(dev));
344 siba_bwn_read_ivar(device_t dev, device_t child, int which, uintptr_t *result)
346 struct siba_dev_softc *sd;
347 struct siba_softc *siba;
349 sd = device_get_ivars(child);
353 case SIBA_IVAR_VENDOR:
354 *result = sd->sd_id.sd_vendor;
356 case SIBA_IVAR_DEVICE:
357 *result = sd->sd_id.sd_device;
359 case SIBA_IVAR_REVID:
360 *result = sd->sd_id.sd_rev;
362 case SIBA_IVAR_PCI_VENDOR:
363 *result = siba->siba_pci_vid;
365 case SIBA_IVAR_PCI_DEVICE:
366 *result = siba->siba_pci_did;
368 case SIBA_IVAR_PCI_SUBVENDOR:
369 *result = siba->siba_pci_subvid;
371 case SIBA_IVAR_PCI_SUBDEVICE:
372 *result = siba->siba_pci_subdid;
374 case SIBA_IVAR_PCI_REVID:
375 *result = siba->siba_pci_revid;
377 case SIBA_IVAR_CHIPID:
378 *result = siba->siba_chipid;
380 case SIBA_IVAR_CHIPREV:
381 *result = siba->siba_chiprev;
383 case SIBA_IVAR_CHIPPKG:
384 *result = siba->siba_chippkg;
387 *result = siba->siba_type;
389 case SIBA_IVAR_CC_PMUFREQ:
390 *result = siba->siba_cc.scc_pmu.freq;
392 case SIBA_IVAR_CC_CAPS:
393 *result = siba->siba_cc.scc_caps;
395 case SIBA_IVAR_CC_POWERDELAY:
396 *result = siba->siba_cc.scc_powerup_delay;
398 case SIBA_IVAR_PCICORE_REVID:
399 *result = siba->siba_pci.spc_dev->sd_id.sd_rev;
408 static device_method_t siba_bwn_methods[] = {
409 /* Device interface */
410 DEVMETHOD(device_probe, siba_bwn_probe),
411 DEVMETHOD(device_attach, siba_bwn_attach),
412 DEVMETHOD(device_detach, siba_bwn_detach),
413 DEVMETHOD(device_shutdown, siba_bwn_shutdown),
414 DEVMETHOD(device_suspend, siba_bwn_suspend),
415 DEVMETHOD(device_resume, siba_bwn_resume),
418 DEVMETHOD(bus_alloc_resource, siba_bwn_alloc_resource),
419 DEVMETHOD(bus_release_resource, siba_bwn_release_resource),
420 DEVMETHOD(bus_read_ivar, siba_bwn_read_ivar),
421 DEVMETHOD(bus_setup_intr, siba_bwn_setup_intr),
422 DEVMETHOD(bus_teardown_intr, siba_bwn_teardown_intr),
425 DEVMETHOD(pci_find_cap, siba_bwn_find_cap),
426 DEVMETHOD(pci_find_extcap, siba_bwn_find_extcap),
427 DEVMETHOD(pci_find_htcap, siba_bwn_find_htcap),
428 DEVMETHOD(pci_alloc_msi, siba_bwn_alloc_msi),
429 DEVMETHOD(pci_release_msi, siba_bwn_release_msi),
430 DEVMETHOD(pci_msi_count, siba_bwn_msi_count),
434 static driver_t siba_bwn_driver = {
437 sizeof(struct siba_bwn_softc)
439 static devclass_t siba_bwn_devclass;
440 DRIVER_MODULE(siba_bwn, pci, siba_bwn_driver, siba_bwn_devclass, 0, 0);
441 MODULE_VERSION(siba_bwn, 1);