summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorMarcus Glocker <mglocker@cvs.openbsd.org>2007-09-12 12:59:56 +0000
committerMarcus Glocker <mglocker@cvs.openbsd.org>2007-09-12 12:59:56 +0000
commit70bf5c87dcdf414ec5d5bae8ec24817389b561ef (patch)
tree9d74226851859abde59de68ee97a1a8a9f6f58ca /sys
parent914fcdd6199fcc818f165290bea0fd6859e8c804 (diff)
PCI and Cardbus hookup for the Broadcom AirForce devices.
OK jsg@
Diffstat (limited to 'sys')
-rw-r--r--sys/conf/files6
-rw-r--r--sys/dev/cardbus/files.cardbus8
-rw-r--r--sys/dev/cardbus/if_bwi_cardbus.c230
-rw-r--r--sys/dev/pci/files.pci8
-rw-r--r--sys/dev/pci/if_bwi_pci.c150
5 files changed, 399 insertions, 3 deletions
diff --git a/sys/conf/files b/sys/conf/files
index 2e82568f8d6..2ab1b985dde 100644
--- a/sys/conf/files
+++ b/sys/conf/files
@@ -1,4 +1,4 @@
-# $OpenBSD: files,v 1.409 2007/07/18 18:17:09 damien Exp $
+# $OpenBSD: files,v 1.410 2007/09/12 12:59:55 mglocker Exp $
# $NetBSD: files,v 1.87 1996/05/19 17:17:50 jonathan Exp $
# @(#)files.newconf 7.5 (Berkeley) 5/10/93
@@ -390,6 +390,10 @@ file dev/ic/aic6915.c sf
device malo: ether, ifnet, ifmedia, firmload, wlan
file dev/ic/malo.c malo
+# Broadcom AirForce
+device bwi: ether, ifnet, ifmedia, firmload, wlan
+file dev/ic/bwi.c bwi
+
# Attributes which machine-independent bus support can be attached to.
# These should be defined here, because some of these busses can have
# devices which provide these attributes, and we'd like to avoid hairy
diff --git a/sys/dev/cardbus/files.cardbus b/sys/dev/cardbus/files.cardbus
index a5ab8431b14..3d97e6bdf8c 100644
--- a/sys/dev/cardbus/files.cardbus
+++ b/sys/dev/cardbus/files.cardbus
@@ -1,4 +1,4 @@
-# $OpenBSD: files.cardbus,v 1.25 2007/04/05 16:25:25 mglocker Exp $
+# $OpenBSD: files.cardbus,v 1.26 2007/09/12 12:59:55 mglocker Exp $
# $NetBSD: files.cardbus,v 1.8 2000/01/26 06:37:24 thorpej Exp $
#
# files.cardbus
@@ -117,3 +117,9 @@ file dev/cardbus/uhci_cardbus.c uhci_cardbus
#
attach malo at cardbus with malo_cardbus
file dev/cardbus/if_malo_cardbus.c malo_cardbus
+
+#
+# Broadcom AirForce
+#
+attach bwi at cardbus with bwi_cardbus
+file dev/cardbus/if_bwi_cardbus.c bwi_cardbus
diff --git a/sys/dev/cardbus/if_bwi_cardbus.c b/sys/dev/cardbus/if_bwi_cardbus.c
new file mode 100644
index 00000000000..8123b0bc704
--- /dev/null
+++ b/sys/dev/cardbus/if_bwi_cardbus.c
@@ -0,0 +1,230 @@
+/* $OpenBSD: if_bwi_cardbus.c,v 1.1 2007/09/12 12:59:55 mglocker Exp $ */
+
+/*
+ * Copyright (c) 2007 Marcus Glocker <mglocker@openbsd.org>
+ * Copyright (c) 2006 Claudio Jeker <claudio@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+/*
+ * Cardbus front-end for the Broadcom AirForce
+ */
+
+#include "bpfilter.h"
+
+#include <sys/param.h>
+#include <sys/mbuf.h>
+#include <sys/socket.h>
+#include <sys/systm.h>
+#include <sys/timeout.h>
+
+#include <net/if.h>
+#include <net/if_media.h>
+
+#include <netinet/in.h>
+#include <netinet/if_ether.h>
+
+#include <net80211/ieee80211_var.h>
+#include <net80211/ieee80211_radiotap.h>
+
+#include <dev/pci/pcireg.h>
+#include <dev/pci/pcivar.h>
+#include <dev/pci/pcidevs.h>
+
+#include <dev/cardbus/cardbusvar.h>
+
+#include <dev/ic/bwivar.h>
+
+struct bwi_cardbus_softc {
+ struct bwi_softc sc_bwi;
+
+ /* cardbus specific goo */
+ cardbus_devfunc_t sc_ct;
+ cardbustag_t sc_tag;
+ void *sc_ih;
+
+ bus_size_t sc_mapsize;
+ pcireg_t sc_bar_val;
+ int sc_intrline;
+};
+
+int bwi_cardbus_match(struct device *parent, void *match, void *aux);
+void bwi_cardbus_attach(struct device *parent, struct device *self,
+ void *aux);
+int bwi_cardbus_detach(struct device *self, int flags);
+void bwi_cardbus_setup(struct bwi_cardbus_softc *csc);
+int bwi_cardbus_enable(struct bwi_softc *sc);
+void bwi_cardbus_disable(struct bwi_softc *sc);
+
+struct cfattach bwi_cardbus_ca = {
+ sizeof (struct bwi_cardbus_softc), bwi_cardbus_match,
+ bwi_cardbus_attach, bwi_cardbus_detach
+};
+
+static const struct cardbus_matchid bwi_cardbus_devices[] = {
+ { PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM4303 },
+ { PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM4306 },
+ { PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM4306_2 },
+ { PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM4307 },
+ { PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM4309 },
+ { PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM4311 },
+ { PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM4312 },
+ { PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM4318 },
+ { PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM4319 },
+ { PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM4322 },
+ { PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM43XG }
+};
+
+int
+bwi_cardbus_match(struct device *parent, void *match, void *aux)
+{
+ return (cardbus_matchbyid(aux, bwi_cardbus_devices,
+ sizeof (bwi_cardbus_devices) / sizeof (bwi_cardbus_devices[0])));
+}
+
+void
+bwi_cardbus_attach(struct device *parent, struct device *self, void *aux)
+{
+ struct bwi_cardbus_softc *csc = (struct bwi_cardbus_softc *)self;
+ struct cardbus_attach_args *ca = aux;
+ struct bwi_softc *sc = &csc->sc_bwi;
+ cardbus_devfunc_t ct = ca->ca_ct;
+ bus_addr_t base;
+ int error;
+
+ sc->sc_dmat = ca->ca_dmat;
+ csc->sc_ct = ct;
+ csc->sc_tag = ca->ca_tag;
+ csc->sc_intrline = ca->ca_intrline;
+
+ /* power management hooks */
+ sc->sc_enable = bwi_cardbus_enable;
+ sc->sc_disable = bwi_cardbus_disable;
+ //sc->sc_power = bwi_cardbus_power;
+
+ /* map control/status registers */
+ error = Cardbus_mapreg_map(ct, CARDBUS_BASE0_REG,
+ CARDBUS_MAPREG_TYPE_MEM, 0, &sc->sc_mem_bt,
+ &sc->sc_mem_bh, &base, &csc->sc_mapsize);
+ if (error != 0) {
+ printf(": could not map memory space\n");
+ return;
+ }
+ csc->sc_bar_val = base | CARDBUS_MAPREG_TYPE_MEM;
+
+ /* set up the PCI configuration registers */
+ bwi_cardbus_setup(csc);
+
+ printf(": irq %d", csc->sc_intrline);
+
+ error = bwi_attach(sc);
+ if (error != 0)
+ bwi_cardbus_detach(&sc->sc_dev, 0);
+
+ Cardbus_function_disable(ct);
+}
+
+int
+bwi_cardbus_detach(struct device *self, int flags)
+{
+ struct bwi_cardbus_softc *csc = (struct bwi_cardbus_softc *)self;
+ struct bwi_softc *sc = &csc->sc_bwi;
+ cardbus_devfunc_t ct = csc->sc_ct;
+ cardbus_chipset_tag_t cc = ct->ct_cc;
+ cardbus_function_tag_t cf = ct->ct_cf;
+ int error;
+
+ error = bwi_detach(sc);
+ if (error != 0)
+ return (error);
+
+ /* unhook the interrupt handler */
+ if (csc->sc_ih != NULL) {
+ cardbus_intr_disestablish(cc, cf, csc->sc_ih);
+ csc->sc_ih = NULL;
+ }
+
+ /* release bus space and close window */
+ Cardbus_mapreg_unmap(ct, CARDBUS_BASE0_REG, sc->sc_mem_bt,
+ sc->sc_mem_bh, csc->sc_mapsize);
+
+ return (0);
+}
+
+void
+bwi_cardbus_setup(struct bwi_cardbus_softc *csc)
+{
+ cardbus_devfunc_t ct = csc->sc_ct;
+ cardbus_chipset_tag_t cc = ct->ct_cc;
+ cardbus_function_tag_t cf = ct->ct_cf;
+ pcireg_t reg;
+
+ /* program the BAR */
+ cardbus_conf_write(cc, cf, csc->sc_tag, CARDBUS_BASE0_REG,
+ csc->sc_bar_val);
+
+ /* make sure the right access type is on the cardbus bridge */
+ (*cf->cardbus_ctrl)(cc, CARDBUS_MEM_ENABLE);
+ (*cf->cardbus_ctrl)(cc, CARDBUS_BM_ENABLE);
+
+ /* enable the appropriate bits in the PCI CSR */
+ reg = cardbus_conf_read(cc, cf, csc->sc_tag,
+ CARDBUS_COMMAND_STATUS_REG);
+ reg |= CARDBUS_COMMAND_MASTER_ENABLE | CARDBUS_COMMAND_MEM_ENABLE;
+ cardbus_conf_write(cc, cf, csc->sc_tag, CARDBUS_COMMAND_STATUS_REG,
+ reg);
+}
+
+int
+bwi_cardbus_enable(struct bwi_softc *sc)
+{
+ struct bwi_cardbus_softc *csc = (struct bwi_cardbus_softc *)sc;
+ cardbus_devfunc_t ct = csc->sc_ct;
+ cardbus_chipset_tag_t cc = ct->ct_cc;
+ cardbus_function_tag_t cf = ct->ct_cf;
+
+ /* power on the socket */
+ Cardbus_function_enable(ct);
+
+ /* setup the PCI configuration registers */
+ bwi_cardbus_setup(csc);
+
+ /* map and establish the interrupt handler */
+ csc->sc_ih = cardbus_intr_establish(cc, cf, csc->sc_intrline, IPL_NET,
+ bwi_intr, sc, sc->sc_dev.dv_xname);
+ if (csc->sc_ih == NULL) {
+ printf("%s: could not establish interrupt at %d\n",
+ sc->sc_dev.dv_xname, csc->sc_intrline);
+ Cardbus_function_disable(ct);
+ return (1);
+ }
+
+ return (0);
+}
+
+void
+bwi_cardbus_disable(struct bwi_softc *sc)
+{
+ struct bwi_cardbus_softc *csc = (struct bwi_cardbus_softc *)sc;
+ cardbus_devfunc_t ct = csc->sc_ct;
+ cardbus_chipset_tag_t cc = ct->ct_cc;
+ cardbus_function_tag_t cf = ct->ct_cf;
+
+ /* unhook the interrupt handler */
+ cardbus_intr_disestablish(cc, cf, csc->sc_ih);
+ csc->sc_ih = NULL;
+
+ /* power down the socket */
+ Cardbus_function_disable(ct);
+}
diff --git a/sys/dev/pci/files.pci b/sys/dev/pci/files.pci
index 6148233fc5f..9af8017417c 100644
--- a/sys/dev/pci/files.pci
+++ b/sys/dev/pci/files.pci
@@ -1,4 +1,4 @@
-# $OpenBSD: files.pci,v 1.244 2007/09/06 16:37:03 damien Exp $
+# $OpenBSD: files.pci,v 1.245 2007/09/12 12:59:55 mglocker Exp $
# $NetBSD: files.pci,v 1.20 1996/09/24 17:47:15 christos Exp $
#
# Config file and device description for machine-independent PCI code.
@@ -659,6 +659,12 @@ file dev/pci/if_pgt_pci.c pgt_pci
attach malo at pci with malo_pci
file dev/pci/if_malo_pci.c malo_pci
+#
+# Broadcom AirForce
+#
+attach bwi at pci with bwi_pci
+file dev/pci/if_bwi_pci.c bwi_pci
+
# Sangoma PCI card
device san: ifnet, ifmedia, sppp
attach san at pci
diff --git a/sys/dev/pci/if_bwi_pci.c b/sys/dev/pci/if_bwi_pci.c
new file mode 100644
index 00000000000..2e2abda4a11
--- /dev/null
+++ b/sys/dev/pci/if_bwi_pci.c
@@ -0,0 +1,150 @@
+/* $OpenBSD: if_bwi_pci.c,v 1.1 2007/09/12 12:59:55 mglocker Exp $ */
+
+/*
+ * Copyright (c) 2007 Marcus Glocker <mglocker@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+/*
+ * PCI front-end for the Broadcom AirForce
+ */
+
+#include "bpfilter.h"
+
+#include <sys/param.h>
+#include <sys/sockio.h>
+#include <sys/mbuf.h>
+#include <sys/kernel.h>
+#include <sys/socket.h>
+#include <sys/systm.h>
+#include <sys/malloc.h>
+#include <sys/timeout.h>
+#include <sys/device.h>
+
+#include <machine/bus.h>
+#include <machine/intr.h>
+
+#include <net/if.h>
+#include <net/if_dl.h>
+#include <net/if_media.h>
+
+#include <netinet/in.h>
+#include <netinet/if_ether.h>
+
+#include <net80211/ieee80211_var.h>
+#include <net80211/ieee80211_radiotap.h>
+
+#include <dev/ic/bwivar.h>
+
+#include <dev/pci/pcireg.h>
+#include <dev/pci/pcivar.h>
+#include <dev/pci/pcidevs.h>
+
+/* Base Address Register */
+#define BWI_PCI_BAR0 0x10
+
+int bwi_pci_match(struct device *, void *, void *);
+void bwi_pci_attach(struct device *, struct device *, void *);
+int bwi_pci_detach(struct device *, int);
+
+struct bwi_pci_softc {
+ struct bwi_softc sc_bwi;
+
+ pci_chipset_tag_t sc_pc;
+ void *sc_ih;
+
+ bus_size_t sc_mapsize;
+};
+
+struct cfattach bwi_pci_ca = {
+ sizeof(struct bwi_pci_softc), bwi_pci_match, bwi_pci_attach,
+ bwi_pci_detach
+};
+
+const struct pci_matchid bwi_pci_devices[] = {
+ { PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM4303 },
+ { PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM4306 },
+ { PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM4306_2 },
+ { PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM4307 },
+ { PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM4309 },
+ { PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM4311 },
+ { PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM4312 },
+ { PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM4318 },
+ { PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM4319 },
+ { PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM4322 },
+ { PCI_VENDOR_BROADCOM, PCI_PRODUCT_BROADCOM_BCM43XG }
+};
+
+int
+bwi_pci_match(struct device *parent, void *match, void *aux)
+{
+ return (pci_matchbyid((struct pci_attach_args *)aux, bwi_pci_devices,
+ sizeof(bwi_pci_devices) / sizeof(bwi_pci_devices[0])));
+}
+
+void
+bwi_pci_attach(struct device *parent, struct device *self, void *aux)
+{
+ struct bwi_pci_softc *psc = (struct bwi_pci_softc *)self;
+ struct pci_attach_args *pa = aux;
+ struct bwi_softc *sc = &psc->sc_bwi;
+ const char *intrstr = NULL;
+ pci_intr_handle_t ih;
+ int error;
+
+ sc->sc_dmat = pa->pa_dmat;
+ psc->sc_pc = pa->pa_pc;
+
+ /* map control / status registers */
+ error = pci_mapreg_map(pa, BWI_PCI_BAR0,
+ PCI_MAPREG_TYPE_MEM | PCI_MAPREG_MEM_TYPE_32BIT, 0,
+ &sc->sc_mem_bt, &sc->sc_mem_bh, NULL, &psc->sc_mapsize, 0);
+ if (error != 0) {
+ printf(": could not map memory space\n");
+ return;
+ }
+
+ /* map interrupt */
+ if (pci_intr_map(pa, &ih) != 0) {
+ printf(": could not map interrupt\n");
+ return;
+ }
+
+ /* establish interrupt */
+ intrstr = pci_intr_string(psc->sc_pc, ih);
+ psc->sc_ih = pci_intr_establish(psc->sc_pc, ih, IPL_NET, bwi_intr, sc,
+ sc->sc_dev.dv_xname);
+ if (psc->sc_ih == NULL) {
+ printf(": could not establish interrupt");
+ if (intrstr != NULL)
+ printf(" at %s", intrstr);
+ printf("\n");
+ return;
+ }
+ printf(": %s", intrstr);
+
+ bwi_attach(sc);
+}
+
+int
+bwi_pci_detach(struct device *self, int flags)
+{
+ struct bwi_pci_softc *psc = (struct bwi_pci_softc *)self;
+ struct bwi_softc *sc = &psc->sc_bwi;
+
+ bwi_detach(sc);
+ pci_intr_disestablish(psc->sc_pc, psc->sc_ih);
+
+ return (0);
+}