Annotation of sys/dev/pci/if_malo_pci.c, Revision 1.1
1.1 ! nbrk 1: /* $OpenBSD: if_malo_pci.c,v 1.3 2006/12/29 07:17:53 mglocker Exp $ */
! 2:
! 3: /*
! 4: * Copyright (c) 2006 Marcus Glocker <mglocker@openbsd.org>
! 5: *
! 6: * Permission to use, copy, modify, and distribute this software for any
! 7: * purpose with or without fee is hereby granted, provided that the above
! 8: * copyright notice and this permission notice appear in all copies.
! 9: *
! 10: * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
! 11: * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
! 12: * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
! 13: * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
! 14: * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
! 15: * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
! 16: * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
! 17: */
! 18:
! 19: /*
! 20: * PCI front-end for the Marvell Libertas
! 21: */
! 22:
! 23: #include "bpfilter.h"
! 24:
! 25: #include <sys/param.h>
! 26: #include <sys/sockio.h>
! 27: #include <sys/mbuf.h>
! 28: #include <sys/kernel.h>
! 29: #include <sys/socket.h>
! 30: #include <sys/systm.h>
! 31: #include <sys/malloc.h>
! 32: #include <sys/timeout.h>
! 33: #include <sys/device.h>
! 34:
! 35: #include <machine/bus.h>
! 36: #include <machine/intr.h>
! 37:
! 38: #include <net/if.h>
! 39: #include <net/if_dl.h>
! 40: #include <net/if_media.h>
! 41:
! 42: #include <netinet/in.h>
! 43: #include <netinet/if_ether.h>
! 44:
! 45: #include <net80211/ieee80211_var.h>
! 46: #include <net80211/ieee80211_radiotap.h>
! 47:
! 48: #include <dev/ic/malo.h>
! 49:
! 50: #include <dev/pci/pcireg.h>
! 51: #include <dev/pci/pcivar.h>
! 52: #include <dev/pci/pcidevs.h>
! 53:
! 54: /* Base Address Register */
! 55: #define MALO_PCI_BAR1 0x10
! 56: #define MALO_PCI_BAR2 0x14
! 57:
! 58: int malo_pci_match(struct device *, void *, void *);
! 59: void malo_pci_attach(struct device *, struct device *, void *);
! 60: int malo_pci_detach(struct device *, int);
! 61:
! 62: struct malo_pci_softc {
! 63: struct malo_softc sc_malo;
! 64:
! 65: pci_chipset_tag_t sc_pc;
! 66: void *sc_ih;
! 67:
! 68: bus_size_t sc_mapsize1;
! 69: bus_size_t sc_mapsize2;
! 70: };
! 71:
! 72: struct cfattach malo_pci_ca = {
! 73: sizeof(struct malo_pci_softc), malo_pci_match, malo_pci_attach,
! 74: malo_pci_detach
! 75: };
! 76:
! 77: const struct pci_matchid malo_pci_devices[] = {
! 78: { PCI_VENDOR_MARVELL, PCI_PRODUCT_MARVELL_88W8310 },
! 79: { PCI_VENDOR_MARVELL, PCI_PRODUCT_MARVELL_88W8335_1 },
! 80: { PCI_VENDOR_MARVELL, PCI_PRODUCT_MARVELL_88W8335_2 }
! 81: };
! 82:
! 83: int
! 84: malo_pci_match(struct device *parent, void *match, void *aux)
! 85: {
! 86: return (pci_matchbyid((struct pci_attach_args *)aux, malo_pci_devices,
! 87: sizeof(malo_pci_devices) / sizeof(malo_pci_devices[0])));
! 88: }
! 89:
! 90: void
! 91: malo_pci_attach(struct device *parent, struct device *self, void *aux)
! 92: {
! 93: struct malo_pci_softc *psc = (struct malo_pci_softc *)self;
! 94: struct pci_attach_args *pa = aux;
! 95: struct malo_softc *sc = &psc->sc_malo;
! 96: const char *intrstr = NULL;
! 97: pci_intr_handle_t ih;
! 98: int error;
! 99:
! 100: sc->sc_dmat = pa->pa_dmat;
! 101: psc->sc_pc = pa->pa_pc;
! 102:
! 103: /* map control / status registers */
! 104: error = pci_mapreg_map(pa, MALO_PCI_BAR1,
! 105: PCI_MAPREG_TYPE_MEM | PCI_MAPREG_MEM_TYPE_32BIT, 0,
! 106: &sc->sc_mem1_bt, &sc->sc_mem1_bh, NULL, &psc->sc_mapsize1, 0);
! 107: if (error != 0) {
! 108: printf(": could not map 1st memory space\n");
! 109: return;
! 110: }
! 111:
! 112: /* map control / status registers */
! 113: error = pci_mapreg_map(pa, MALO_PCI_BAR2,
! 114: PCI_MAPREG_TYPE_MEM | PCI_MAPREG_MEM_TYPE_32BIT, 0,
! 115: &sc->sc_mem2_bt, &sc->sc_mem2_bh, NULL, &psc->sc_mapsize2, 0);
! 116: if (error != 0) {
! 117: printf(": could not map 2nd memory space\n");
! 118: return;
! 119: }
! 120:
! 121: /* map interrupt */
! 122: if (pci_intr_map(pa, &ih) != 0) {
! 123: printf(": could not map interrupt\n");
! 124: return;
! 125: }
! 126:
! 127: /* establish interrupt */
! 128: intrstr = pci_intr_string(psc->sc_pc, ih);
! 129: psc->sc_ih = pci_intr_establish(psc->sc_pc, ih, IPL_NET, malo_intr, sc,
! 130: sc->sc_dev.dv_xname);
! 131: if (psc->sc_ih == NULL) {
! 132: printf(": could not establish interrupt");
! 133: if (intrstr != NULL)
! 134: printf(" at %s", intrstr);
! 135: printf("\n");
! 136: return;
! 137: }
! 138: printf(": %s", intrstr);
! 139:
! 140: malo_attach(sc);
! 141: }
! 142:
! 143: int
! 144: malo_pci_detach(struct device *self, int flags)
! 145: {
! 146: struct malo_pci_softc *psc = (struct malo_pci_softc *)self;
! 147: struct malo_softc *sc = &psc->sc_malo;
! 148:
! 149: malo_detach(sc);
! 150: pci_intr_disestablish(psc->sc_pc, psc->sc_ih);
! 151:
! 152: return (0);
! 153: }
CVSweb