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/pci/if_en_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_en_pci.c,v 1.1 1996/06/22 02:00:31 chuck Exp $      */
    2 
    3 /*
    4  *
    5  * Copyright (c) 1996 Charles D. Cranor and Washington University.
    6  * All rights reserved.
    7  *
    8  * Redistribution and use in source and binary forms, with or without
    9  * modification, are permitted provided that the following conditions
   10  * are met:
   11  * 1. Redistributions of source code must retain the above copyright
   12  *    notice, this list of conditions and the following disclaimer.
   13  * 2. Redistributions in binary form must reproduce the above copyright
   14  *    notice, this list of conditions and the following disclaimer in the
   15  *    documentation and/or other materials provided with the distribution.
   16  * 3. All advertising materials mentioning features or use of this software
   17  *    must display the following acknowledgement:
   18  *      This product includes software developed by Charles D. Cranor and
   19  *      Washington University.
   20  * 4. The name of the author may not be used to endorse or promote products
   21  *    derived from this software without specific prior written permission.
   22  *
   23  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
   24  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   25  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
   26  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
   27  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
   28  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
   29  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
   30  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
   31  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
   32  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   33  */
   34 
   35 /*
   36  *
   37  * i f _ e n _ p c i . c  
   38  *
   39  * author: Chuck Cranor <chuck@ccrc.wustl.edu>
   40  * started: spring, 1996.
   41  *
   42  * FreeBSD PCI glue for the eni155p card.
   43  * thanks to Matt Thomas for figuring out FreeBSD vs NetBSD vs etc.. diffs.
   44  */
   45 
   46 #include "en.h"
   47 #include "pci.h"
   48 #if (NEN > 0) && (NPCI > 0)
   49 
   50 #include <sys/param.h>
   51 #include <sys/kernel.h>
   52 #include <sys/systm.h>
   53 #include <sys/malloc.h>
   54 #include <sys/socket.h>
   55 
   56 #include <machine/clock.h>              /* for DELAY */
   57 
   58 #include <net/if.h>
   59 
   60 #include <pci/pcivar.h>
   61 #include <pci/pcireg.h>
   62 
   63 #include <dev/en/midwayreg.h>
   64 #include <dev/en/midwayvar.h>
   65 
   66 
   67 /*
   68  * prototypes
   69  */
   70 
   71 static  void en_pci_attach __P((pcici_t, int));
   72 static  const char *en_pci_probe __P((pcici_t, pcidi_t));
   73 static void en_pci_shutdown __P((int, void *));
   74 
   75 /*
   76  * local structures
   77  */
   78 
   79 struct en_pci_softc {
   80   /* bus independent stuff */
   81   struct en_softc esc;          /* includes "device" structure */
   82 
   83   /* PCI bus glue */
   84   void *sc_ih;                  /* interrupt handle */
   85   pci_chipset_tag_t en_pc;      /* for PCI calls */
   86   pcici_t en_confid;            /* config id */
   87 };
   88 
   89 #if !defined(MIDWAY_ENIONLY)
   90 static  void eni_get_macaddr __P((struct en_pci_softc *));
   91 #endif
   92 #if !defined(MIDWAY_ADPONLY)
   93 static  void adp_get_macaddr __P((struct en_pci_softc *));
   94 #endif
   95 
   96 /*
   97  * pointers to softcs (we alloc)
   98  */
   99 
  100 static struct en_pci_softc *enpcis[NEN] = {0};
  101 extern struct cfdriver en_cd;
  102 
  103 /*
  104  * autoconfig structures
  105  */
  106 
  107 static u_long en_pci_count;
  108 
  109 static struct pci_device endevice = {
  110         "en",
  111         en_pci_probe,
  112         en_pci_attach,
  113         &en_pci_count,
  114         NULL,
  115 };  
  116 
  117 DATA_SET (pcidevice_set, endevice);
  118 
  119 /*
  120  * local defines (PCI specific stuff)
  121  */
  122 
  123 /* 
  124  * address of config base memory address register in PCI config space
  125  * (this is card specific)
  126  */
  127         
  128 #define PCI_CBMA        0x10
  129 
  130 /*
  131  * tonga (pci bridge).   ENI cards only!
  132  */
  133 
  134 #define EN_TONGA        0x60            /* PCI config addr of tonga reg */
  135 
  136 #define TONGA_SWAP_DMA  0x80            /* endian swap control */
  137 #define TONGA_SWAP_BYTE 0x40
  138 #define TONGA_SWAP_WORD 0x20
  139 
  140 /*
  141  * adaptec pci bridge.   ADP cards only!
  142  */
  143 
  144 #define ADP_PCIREG      0x050040        /* PCI control register */
  145 
  146 #define ADP_PCIREG_RESET        0x1     /* reset card */
  147 #define ADP_PCIREG_IENABLE      0x2     /* interrupt enable */
  148 #define ADP_PCIREG_SWAP_WORD    0x4     /* swap byte on slave access */
  149 #define ADP_PCIREG_SWAP_DMA     0x8     /* swap byte on DMA */
  150 
  151 #define PCI_VENDOR_EFFICIENTNETS 0x111a                 /* Efficent Networks */
  152 #define PCI_PRODUCT_EFFICIENTNETS_ENI155PF 0x0000       /* ENI-155P ATM */
  153 #define PCI_PRODUCT_EFFICIENTNETS_ENI155PA 0x0002       /* ENI-155P ATM */
  154 #define PCI_VENDOR_ADP 0x9004                           /* adaptec */
  155 #define PCI_PRODUCT_ADP_AIC5900 0x5900
  156 #define PCI_PRODUCT_ADP_AIC5905 0x5905
  157 #define PCI_VENDOR(x)           ((x) & 0xFFFF)
  158 #define PCI_CHIPID(x)           (((x) >> 16) & 0xFFFF)
  159 
  160 #if !defined(MIDWAY_ENIONLY)
  161 
  162 static void adp_busreset __P((void *));
  163 
  164 /*
  165  * bus specific reset function [ADP only!]
  166  */
  167 
  168 static void adp_busreset(v)
  169 
  170 void *v;
  171 
  172 {
  173   struct en_softc *sc = (struct en_softc *) v;
  174   u_int32_t dummy;
  175 
  176   bus_space_write_4(sc->en_memt, sc->en_base, ADP_PCIREG, ADP_PCIREG_RESET);
  177   DELAY(1000);  /* let it reset */
  178   dummy = bus_space_read_4(sc->en_memt, sc->en_base, ADP_PCIREG);
  179   bus_space_write_4(sc->en_memt, sc->en_base, ADP_PCIREG, 
  180                 (ADP_PCIREG_SWAP_WORD|ADP_PCIREG_SWAP_DMA|ADP_PCIREG_IENABLE));
  181   dummy = bus_space_read_4(sc->en_memt, sc->en_base, ADP_PCIREG);
  182   if ((dummy & (ADP_PCIREG_SWAP_WORD|ADP_PCIREG_SWAP_DMA)) !=
  183                 (ADP_PCIREG_SWAP_WORD|ADP_PCIREG_SWAP_DMA))
  184     printf("adp_busreset: Adaptec ATM did NOT reset!\n");
  185 }
  186 #endif
  187 
  188 /***********************************************************************/
  189 
  190 /*
  191  * autoconfig stuff
  192  */
  193 
  194 static const char *en_pci_probe(config_id, device_id)
  195 
  196 pcici_t config_id;
  197 pcidi_t device_id;
  198 
  199 {
  200 #if !defined(MIDWAY_ADPONLY)
  201   if (PCI_VENDOR(device_id) == PCI_VENDOR_EFFICIENTNETS && 
  202       (PCI_CHIPID(device_id) == PCI_PRODUCT_EFFICIENTNETS_ENI155PF ||
  203        PCI_CHIPID(device_id) == PCI_PRODUCT_EFFICIENTNETS_ENI155PA))
  204     return "Efficient Networks ENI-155p";
  205 #endif
  206 
  207 #if !defined(MIDWAY_ENIONLY)
  208   if (PCI_VENDOR(device_id) == PCI_VENDOR_ADP && 
  209       (PCI_CHIPID(device_id) == PCI_PRODUCT_ADP_AIC5900 ||
  210        PCI_CHIPID(device_id) == PCI_PRODUCT_ADP_AIC5905))
  211     return "Adaptec 155 ATM";
  212 #endif
  213 
  214   return 0;
  215 }
  216 
  217 static void en_pci_attach(config_id, unit)
  218 
  219 pcici_t config_id;
  220 int unit;
  221 
  222 {
  223   struct en_softc *sc;
  224   struct en_pci_softc *scp;
  225   pcidi_t device_id;
  226   int retval;
  227   vm_offset_t pa;
  228 
  229   if (unit >= NEN) {
  230     printf("en%d: not configured; kernel is built for only %d device%s.\n",
  231         unit, NEN, NEN == 1 ? "" : "s");
  232     return;
  233   }
  234 
  235   scp = (struct en_pci_softc *) malloc(sizeof(*scp), M_DEVBUF, M_NOWAIT);
  236   if (scp == NULL)
  237     return;
  238   bzero(scp, sizeof(*scp));             /* zero */
  239   sc = &scp->esc;
  240 
  241   retval = pci_map_mem(config_id, PCI_CBMA, (vm_offset_t *) &sc->en_base, &pa);
  242 
  243   if (!retval) {
  244     free((caddr_t) scp, M_DEVBUF);
  245     return;
  246   }
  247   enpcis[unit] = scp;                   /* lock it in */
  248   en_cd.cd_devs[unit] = sc;             /* fake a cfdriver structure */
  249   en_cd.cd_ndevs = NEN;
  250   snprintf(sc->sc_dev.dv_xname, sizeof(sc->sc_dev.dv_xname), "en%d", unit);
  251   sc->enif.if_unit = unit;
  252   sc->enif.if_name = "en";
  253   scp->en_confid = config_id;
  254 
  255   /*
  256    * figure out if we are an adaptec card or not.
  257    * XXX: why do we have to re-read PC_ID_REG when en_pci_probe already
  258    * had that info?
  259    */
  260 
  261   device_id = pci_conf_read(config_id, PCI_ID_REG);
  262   sc->is_adaptec = (PCI_VENDOR(device_id) == PCI_VENDOR_ADP) ? 1 : 0;
  263   
  264   /*
  265    * Add shutdown hook so that DMA is disabled prior to reboot. Not
  266    * doing so could allow DMA to corrupt kernel memory during the
  267    * reboot before the driver initializes.
  268    */
  269   at_shutdown(en_pci_shutdown, scp, SHUTDOWN_POST_SYNC);
  270 
  271   if (!pci_map_int(config_id, en_intr, (void *) sc, &net_imask)) {
  272     printf("%s: couldn't establish interrupt\n", sc->sc_dev.dv_xname);
  273     return;
  274   }
  275   sc->ipl = 1; /* XXX */
  276 
  277   /*
  278    * set up pci bridge
  279    */
  280 
  281 #if !defined(MIDWAY_ENIONLY)
  282   if (sc->is_adaptec) {
  283     adp_get_macaddr(scp);
  284     sc->en_busreset = adp_busreset;
  285     adp_busreset(sc);
  286   }
  287 #endif
  288 
  289 #if !defined(MIDWAY_ADPONLY)
  290   if (!sc->is_adaptec) {
  291     eni_get_macaddr(scp);
  292     sc->en_busreset = NULL;
  293     pci_conf_write(config_id, EN_TONGA, (TONGA_SWAP_DMA|TONGA_SWAP_WORD));
  294   }
  295 #endif
  296 
  297   /*
  298    * done PCI specific stuff
  299    */
  300 
  301   en_attach(sc);
  302 
  303 }
  304 
  305 static void
  306 en_pci_shutdown(
  307         int howto,
  308         void *sc)
  309 {
  310     struct en_pci_softc *psc = (struct en_pci_softc *)sc;
  311     
  312     en_reset(&psc->esc);
  313     DELAY(10);
  314 }
  315 
  316 #if !defined(MIDWAY_ENIONLY)
  317 
  318 #if defined(sparc) || defined(__FreeBSD__)
  319 #define bus_space_read_1(t, h, o) \
  320                 ((void)t, (*(volatile u_int8_t *)((h) + (o))))
  321 #endif
  322 
  323 static void 
  324 adp_get_macaddr(scp)
  325      struct en_pci_softc *scp;
  326 {
  327   struct en_softc * sc = (struct en_softc *)scp;
  328   int lcv;
  329 
  330   for (lcv = 0; lcv < sizeof(sc->macaddr); lcv++)
  331     sc->macaddr[lcv] = bus_space_read_1(sc->en_memt, sc->en_base,
  332                                         MID_ADPMACOFF + lcv);
  333 }
  334 
  335 #endif /* MIDWAY_ENIONLY */
  336 
  337 #if !defined(MIDWAY_ADPONLY)
  338 
  339 /*
  340  * Read station (MAC) address from serial EEPROM.
  341  * derived from linux drivers/atm/eni.c by Werner Almesberger, EPFL LRC.
  342  */
  343 #define EN_PROM_MAGIC  0x0c
  344 #define EN_PROM_DATA   0x02
  345 #define EN_PROM_CLK    0x01
  346 #define EN_ESI         64
  347 
  348 static void 
  349 eni_get_macaddr(scp)
  350      struct en_pci_softc *scp;
  351 {
  352   struct en_softc * sc = (struct en_softc *)scp;
  353   pcici_t id = scp->en_confid;
  354   int i, j, address, status;
  355   u_int32_t data, t_data;
  356   u_int8_t tmp;
  357   
  358   t_data = pci_conf_read(id, EN_TONGA) & 0xffffff00;
  359 
  360   data =  EN_PROM_MAGIC | EN_PROM_DATA | EN_PROM_CLK;
  361   pci_conf_write(id, EN_TONGA, data);
  362 
  363   for (i = 0; i < sizeof(sc->macaddr); i ++){
  364     /* start operation */
  365     data |= EN_PROM_DATA ;
  366     pci_conf_write(id, EN_TONGA, data);
  367     data |= EN_PROM_CLK ;
  368     pci_conf_write(id, EN_TONGA, data);
  369     data &= ~EN_PROM_DATA ;
  370     pci_conf_write(id, EN_TONGA, data);
  371     data &= ~EN_PROM_CLK ;
  372     pci_conf_write(id, EN_TONGA, data);
  373     /* send address with serial line */
  374     address = ((i + EN_ESI) << 1) + 1;
  375     for ( j = 7 ; j >= 0 ; j --){
  376       data = (address >> j) & 1 ? data | EN_PROM_DATA :
  377       data & ~EN_PROM_DATA;
  378       pci_conf_write(id, EN_TONGA, data);
  379       data |= EN_PROM_CLK ;
  380       pci_conf_write(id, EN_TONGA, data);
  381       data &= ~EN_PROM_CLK ;
  382       pci_conf_write(id, EN_TONGA, data);
  383     }
  384     /* get ack */
  385     data |= EN_PROM_DATA ;
  386     pci_conf_write(id, EN_TONGA, data);
  387     data |= EN_PROM_CLK ;
  388     pci_conf_write(id, EN_TONGA, data);
  389     data = pci_conf_read(id, EN_TONGA);
  390     status = data & EN_PROM_DATA;
  391     data &= ~EN_PROM_CLK ;
  392     pci_conf_write(id, EN_TONGA, data);
  393     data |= EN_PROM_DATA ;
  394     pci_conf_write(id, EN_TONGA, data);
  395 
  396     tmp = 0;
  397 
  398     for ( j = 7 ; j >= 0 ; j --){
  399       tmp <<= 1;
  400       data |= EN_PROM_DATA ;
  401       pci_conf_write(id, EN_TONGA, data);
  402       data |= EN_PROM_CLK ;
  403       pci_conf_write(id, EN_TONGA, data);
  404       data = pci_conf_read(id, EN_TONGA);
  405       if(data & EN_PROM_DATA) tmp |= 1;
  406       data &= ~EN_PROM_CLK ;
  407       pci_conf_write(id, EN_TONGA, data);
  408       data |= EN_PROM_DATA ;
  409       pci_conf_write(id, EN_TONGA, data);
  410     }
  411     /* get ack */
  412     data |= EN_PROM_DATA ;
  413     pci_conf_write(id, EN_TONGA, data);
  414     data |= EN_PROM_CLK ;
  415     pci_conf_write(id, EN_TONGA, data);
  416     data = pci_conf_read(id, EN_TONGA);
  417     status = data & EN_PROM_DATA;
  418     data &= ~EN_PROM_CLK ;
  419     pci_conf_write(id, EN_TONGA, data);
  420     data |= EN_PROM_DATA ;
  421     pci_conf_write(id, EN_TONGA, data);
  422 
  423     sc->macaddr[i] = tmp;
  424   }
  425   /* stop operation */
  426   data &=  ~EN_PROM_DATA;
  427   pci_conf_write(id, EN_TONGA, data);
  428   data |=  EN_PROM_CLK;
  429   pci_conf_write(id, EN_TONGA, data);
  430   data |=  EN_PROM_DATA;
  431   pci_conf_write(id, EN_TONGA, data);
  432   pci_conf_write(id, EN_TONGA, t_data);
  433 }
  434 
  435 #endif /* !MIDWAY_ADPONLY */
  436 
  437 #endif /* NEN > 0 && NPCI > 0 */

Cache object: 1d73538dc956d8ee35bb68e0a2256fec


[ 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.