The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/dev/pci/if_ath_pci.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*      $NetBSD: if_ath_pci.c,v 1.5.2.1 2004/07/02 22:28:31 he Exp $    */
    2 
    3 /*-
    4  * Copyright (c) 2002, 2003 Sam Leffler, Errno Consulting
    5  * 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  *    without modification.
   13  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
   14  *    similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
   15  *    redistribution must be conditioned upon including a substantially
   16  *    similar Disclaimer requirement for further binary redistribution.
   17  * 3. Neither the names of the above-listed copyright holders nor the names
   18  *    of any contributors may be used to endorse or promote products derived
   19  *    from this software without specific prior written permission.
   20  *
   21  * Alternatively, this software may be distributed under the terms of the
   22  * GNU General Public License ("GPL") version 2 as published by the Free
   23  * Software Foundation.
   24  *
   25  * NO WARRANTY
   26  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
   27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
   28  * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
   29  * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
   30  * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
   31  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
   32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
   33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
   34  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
   36  * THE POSSIBILITY OF SUCH DAMAGES.
   37  */
   38 
   39 #include <sys/cdefs.h>
   40 #ifdef __FreeBSD__
   41 __FBSDID("$FreeBSD: src/sys/dev/ath/if_ath_pci.c,v 1.6 2003/11/28 05:28:27 imp Exp $");
   42 #endif
   43 #ifdef __NetBSD__
   44 __KERNEL_RCSID(0, "$NetBSD: if_ath_pci.c,v 1.5.2.1 2004/07/02 22:28:31 he Exp $");
   45 #endif
   46 
   47 /*
   48  * PCI/Cardbus front-end for the Atheros Wireless LAN controller driver.
   49  */
   50 
   51 #include "opt_inet.h"
   52 
   53 #include <sys/param.h>
   54 #include <sys/systm.h> 
   55 #include <sys/mbuf.h>   
   56 #include <sys/malloc.h>
   57 #include <sys/kernel.h>
   58 #include <sys/lock.h>
   59 #include <sys/socket.h>
   60 #include <sys/sockio.h>
   61 #include <sys/errno.h>
   62 
   63 #include <machine/bus.h>
   64  
   65 #include <net/if.h>
   66 #include <net/if_dl.h>
   67 #include <net/if_media.h>
   68 #include <net/if_ether.h>
   69 #include <net/if_llc.h>
   70 #include <net/if_arp.h>
   71 
   72 #include <net80211/ieee80211_compat.h>
   73 #include <net80211/ieee80211_var.h>
   74 
   75 #ifdef INET
   76 #include <netinet/in.h> 
   77 #endif
   78 
   79 #include <dev/ic/athcompat.h>
   80 #include <dev/ic/athvar.h>
   81 #include <../contrib/sys/dev/ic/athhal.h>
   82 
   83 #include <dev/pci/pcivar.h>
   84 #include <dev/pci/pcireg.h>
   85 #include <dev/pci/pcidevs.h>
   86 
   87 #include <sys/device.h>
   88 
   89 /*
   90  * PCI glue.
   91  */
   92 
   93 struct ath_pci_softc {
   94         struct ath_softc        sc_sc;
   95 #ifdef __FreeBSD__
   96         struct resource         *sc_sr;         /* memory resource */
   97         struct resource         *sc_irq;        /* irq resource */
   98 #else
   99         pci_chipset_tag_t       sc_pc;
  100 #endif
  101         void                    *sc_ih;         /* intererupt handler */
  102         u_int8_t                sc_saved_intline;
  103         u_int8_t                sc_saved_cachelinesz;
  104         u_int8_t                sc_saved_lattimer;
  105 };
  106 
  107 #define BS_BAR  0x10
  108 
  109 static int ath_pci_match(struct device *, struct cfdata *, void *);
  110 static void ath_pci_attach(struct device *, struct device *, void *);
  111 static void ath_pci_shutdown(void *);
  112 static int ath_pci_detach(struct device *, int);
  113 
  114 CFATTACH_DECL(ath_pci,
  115     sizeof(struct ath_pci_softc),
  116     ath_pci_match,
  117     ath_pci_attach,
  118     ath_pci_detach,
  119     NULL);
  120 
  121 /*
  122  * translate some product code.  it is a workaround until HAL gets updated.
  123  */
  124 static u_int16_t
  125 ath_product(pcireg_t pa_id)
  126 {
  127         u_int16_t prodid;
  128 
  129         prodid = PCI_PRODUCT(pa_id);
  130         switch (prodid) {
  131         case 0x1014:    /* IBM 31P9702 minipci a/b/g card */
  132                 prodid = PCI_PRODUCT_ATHEROS_AR5212;
  133                 break;
  134         default:
  135                 break;
  136         }
  137         return prodid;
  138 }
  139 
  140 static int
  141 ath_pci_match(struct device *parent, struct cfdata *match, void *aux)
  142 {
  143         const char* devname;
  144         struct pci_attach_args *pa = aux;
  145         pci_vendor_id_t vendor;
  146 
  147         vendor = PCI_VENDOR(pa->pa_id);
  148         /* XXX HACK until HAL is updated. */
  149         if (vendor == 0x128c)
  150                 vendor = PCI_VENDOR_ATHEROS;
  151         devname = ath_hal_probe(vendor, ath_product(pa->pa_id));
  152         if (devname) 
  153                 return 1;
  154 
  155         return 0;
  156 }
  157 
  158 static void
  159 ath_pci_attach(struct device *parent, struct device *self, void *aux)
  160 {
  161         struct ath_pci_softc *psc = (struct ath_pci_softc *)self;
  162         struct ath_softc *sc = &psc->sc_sc;
  163         u_int32_t res;
  164         struct pci_attach_args *pa = aux;
  165         pci_chipset_tag_t pc = pa->pa_pc;
  166         bus_space_tag_t iot;
  167         bus_space_handle_t ioh;
  168         pci_intr_handle_t ih;
  169         void *hook;
  170         const char *intrstr = NULL;
  171 
  172         psc->sc_pc = pc;
  173 
  174         pci_conf_write(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG,
  175             pci_conf_read(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG) |
  176                 PCI_COMMAND_MASTER_ENABLE | PCI_COMMAND_MEM_ENABLE);
  177         res = pci_conf_read(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG);
  178 
  179         if ((res & PCI_COMMAND_MEM_ENABLE) == 0) {
  180                 aprint_error("couldn't enable memory mapping\n");
  181                 goto bad;
  182         }
  183 
  184         if ((res & PCI_COMMAND_MASTER_ENABLE) == 0) {
  185                 aprint_error("couldn't enable bus mastering\n");
  186                 goto bad;
  187         }
  188 
  189         if (pci_mapreg_map(pa, BS_BAR, PCI_MAPREG_TYPE_MEM, 0, &iot, &ioh, 
  190             NULL, NULL)) {
  191                 aprint_error("cannot map register space\n");
  192                 goto bad;
  193         }
  194         sc->sc_st = iot;
  195         sc->sc_sh = ioh;
  196 
  197         sc->sc_invalid = 1;
  198 
  199         if (pci_intr_map(pa, &ih)) {
  200                 aprint_error("couldn't map interrupt\n");
  201                 goto bad1;
  202         }
  203 
  204         intrstr = pci_intr_string(pc, ih); 
  205         psc->sc_ih = pci_intr_establish(pc, ih, IPL_NET, ath_intr, sc);
  206         if (psc->sc_ih == NULL) {
  207                 aprint_error("couldn't map interrupt\n");
  208                 goto bad2;
  209         }
  210 
  211         printf("\n");
  212         printf("%s: interrupting at %s\n", sc->sc_dev.dv_xname, intrstr);
  213 
  214         sc->sc_dmat = pa->pa_dmat;
  215 
  216         hook = shutdownhook_establish(ath_pci_shutdown, psc);
  217         if (hook == NULL) {
  218                 aprint_error("couldn't make shutdown hook\n");
  219                 goto bad3;
  220         }
  221 
  222         if (ath_attach(ath_product(pa->pa_id), sc) == 0)
  223                 return;
  224 
  225         shutdownhook_disestablish(hook);
  226 
  227 bad3:   pci_intr_disestablish(pc, psc->sc_ih);
  228 bad2:   /* XXX */
  229 bad1:   /* XXX */
  230 bad:
  231         return;
  232 }
  233 
  234 static int
  235 ath_pci_detach(struct device *self, int flags)
  236 {
  237         struct ath_pci_softc *psc = (struct ath_pci_softc *)self;
  238 
  239         ath_detach(&psc->sc_sc);
  240         pci_intr_disestablish(psc->sc_pc, psc->sc_ih);
  241 
  242         return (0);
  243 }
  244 
  245 static void
  246 ath_pci_shutdown(void *self)
  247 {
  248         struct ath_pci_softc *psc = (struct ath_pci_softc *)self;
  249 
  250         ath_shutdown(&psc->sc_sc);
  251 }

Cache object: 515430247828afff1d5c10aa718f6d82


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.