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_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.20 2003/10/30 01:58:17 simonb 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  * PCI glue for the eni155p card.
   43  */
   44 
   45 #include <sys/cdefs.h>
   46 __KERNEL_RCSID(0, "$NetBSD: if_en_pci.c,v 1.20 2003/10/30 01:58:17 simonb Exp $");
   47 
   48 #include <sys/param.h>
   49 #include <sys/systm.h>
   50 #include <sys/device.h>
   51 #include <sys/mbuf.h>
   52 #include <sys/socket.h>
   53 #include <sys/socketvar.h>
   54 
   55 #include <net/if.h>
   56 
   57 #include <dev/pci/pcivar.h>
   58 #include <dev/pci/pcireg.h>
   59 #include <dev/pci/pcidevs.h>
   60 
   61 #include <dev/ic/midwayreg.h>
   62 #include <dev/ic/midwayvar.h>
   63 
   64 
   65 /*
   66  * local structures
   67  */
   68 
   69 struct en_pci_softc {
   70   /* bus independent stuff */
   71   struct en_softc esc;          /* includes "device" structure */
   72 
   73   /* PCI bus glue */
   74   void *sc_ih;                  /* interrupt handle */
   75   pci_chipset_tag_t en_pc;      /* for PCI calls */
   76 
   77 };
   78 
   79 /*
   80  * local defines (PCI specific stuff)
   81  */
   82 
   83 #if !defined(MIDWAY_ENIONLY)
   84 static  void eni_get_macaddr __P((struct en_pci_softc *,
   85                 struct pci_attach_args *));
   86 #endif
   87 #if !defined(MIDWAY_ADPONLY)
   88 static  void adp_get_macaddr __P((struct en_pci_softc *,
   89                 struct pci_attach_args *));
   90 #endif
   91 
   92 /* 
   93  * address of config base memory address register in PCI config space
   94  * (this is card specific)
   95  */
   96         
   97 #define PCI_CBMA        0x10
   98 
   99 /*
  100  * tonga (pci bridge).   ENI cards only!
  101  */
  102 
  103 #define EN_TONGA        0x60            /* PCI config addr of tonga reg */
  104 
  105 #define TONGA_SWAP_DMA  0x80            /* endian swap control */
  106 #define TONGA_SWAP_BYTE 0x40
  107 #define TONGA_SWAP_WORD 0x20
  108 
  109 /*
  110  * adaptec pci bridge.   ADP cards only!
  111  */
  112 
  113 #define ADP_PCIREG      0x050040        /* PCI control register */
  114 
  115 #define ADP_PCIREG_RESET        0x1     /* reset card */
  116 #define ADP_PCIREG_IENABLE      0x2     /* interrupt enable */
  117 #define ADP_PCIREG_SWAP_WORD    0x4     /* swap byte on slave access */
  118 #define ADP_PCIREG_SWAP_DMA     0x8     /* swap bytes on DMA */
  119 
  120 /*
  121  * prototypes
  122  */
  123 
  124 static  int en_pci_match __P((struct device *, struct cfdata *, void *));
  125 static  void en_pci_attach __P((struct device *, struct device *, void *));
  126 
  127 /*
  128  * PCI autoconfig attachments
  129  */
  130 
  131 CFATTACH_DECL(en_pci, sizeof(struct en_pci_softc),
  132     en_pci_match, en_pci_attach, NULL, NULL);
  133 
  134 #if !defined(MIDWAY_ENIONLY)
  135 
  136 static void adp_busreset __P((void *));
  137 
  138 /*
  139  * bus specific reset function [ADP only!]
  140  */
  141 
  142 static void adp_busreset(v)
  143 
  144 void *v;
  145 
  146 {
  147   struct en_softc *sc = (struct en_softc *) v;
  148   u_int32_t dummy;
  149 
  150   bus_space_write_4(sc->en_memt, sc->en_base, ADP_PCIREG, ADP_PCIREG_RESET);
  151   DELAY(1000);  /* let it reset */
  152   dummy = bus_space_read_4(sc->en_memt, sc->en_base, ADP_PCIREG);
  153   bus_space_write_4(sc->en_memt, sc->en_base, ADP_PCIREG, 
  154                 (ADP_PCIREG_SWAP_WORD|ADP_PCIREG_SWAP_DMA|ADP_PCIREG_IENABLE));
  155   dummy = bus_space_read_4(sc->en_memt, sc->en_base, ADP_PCIREG);
  156   if ((dummy & (ADP_PCIREG_SWAP_WORD|ADP_PCIREG_SWAP_DMA)) !=
  157                 (ADP_PCIREG_SWAP_WORD|ADP_PCIREG_SWAP_DMA))
  158     printf("adp_busreset: Adaptec ATM did NOT reset!\n");
  159 
  160 }
  161 #endif
  162 
  163 /***********************************************************************/
  164 
  165 /*
  166  * autoconfig stuff
  167  */
  168 
  169 static int en_pci_match(parent, match, aux)
  170 
  171 struct device *parent;
  172 struct cfdata *match;
  173 void *aux;
  174 
  175 {
  176   struct pci_attach_args *pa = (struct pci_attach_args *) aux;
  177 
  178 #if !defined(MIDWAY_ADPONLY)
  179   if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_EFFICIENTNETS && 
  180       (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_EFFICIENTNETS_ENI155PF ||
  181        PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_EFFICIENTNETS_ENI155PA))
  182     return 1;
  183 #endif
  184 
  185 #if !defined(MIDWAY_ENIONLY)
  186   if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_ADP && 
  187       (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_ADP_AIC5900 ||
  188        PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_ADP_AIC5905))
  189     return 1;
  190 #endif
  191 
  192   return 0;
  193 }
  194 
  195 
  196 static void en_pci_attach(parent, self, aux)
  197 
  198 struct device *parent, *self;
  199 void *aux;
  200 
  201 {
  202   struct en_softc *sc = (void *)self;
  203   struct en_pci_softc *scp = (void *)self;
  204   struct pci_attach_args *pa = aux;
  205   pci_intr_handle_t ih;
  206   const char *intrstr;
  207   int retval;
  208 
  209   aprint_naive(": ATM controller\n");
  210   aprint_normal("\n");
  211 
  212   sc->is_adaptec = (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_ADP) ? 1 : 0;
  213   scp->en_pc = pa->pa_pc;
  214 
  215   /*
  216    * make sure bus mastering is enabled
  217    */
  218   pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG,
  219     pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG) |
  220     PCI_COMMAND_MASTER_ENABLE);
  221 
  222   /*
  223    * interrupt map
  224    */
  225 
  226   if (pci_intr_map(pa, &ih)) {
  227     aprint_error("%s: couldn't map interrupt\n", sc->sc_dev.dv_xname);
  228     return;
  229   }
  230   intrstr = pci_intr_string(scp->en_pc, ih);
  231   scp->sc_ih = pci_intr_establish(scp->en_pc, ih, IPL_NET, en_intr, sc);
  232   if (scp->sc_ih == NULL) {
  233     aprint_error("%s: couldn't establish interrupt\n", sc->sc_dev.dv_xname);
  234     if (intrstr != NULL)
  235       aprint_normal(" at %s", intrstr);
  236     aprint_normal("\n");
  237     return;
  238   }
  239   aprint_normal("%s: interrupting at %s\n", sc->sc_dev.dv_xname, intrstr);
  240   sc->ipl = 1; /* XXX */
  241 
  242   /*
  243    * memory map
  244    */
  245 
  246   retval = pci_mapreg_map(pa, PCI_CBMA,
  247                           PCI_MAPREG_TYPE_MEM | PCI_MAPREG_MEM_TYPE_32BIT, 0,
  248                           &sc->en_memt, &sc->en_base, NULL, &sc->en_obmemsz);
  249   if (retval) {
  250     aprint_error("%s: couldn't map memory\n", sc->sc_dev.dv_xname);
  251     return;
  252   }
  253         
  254   /*
  255    * set up pci bridge
  256    */
  257 
  258 #if !defined(MIDWAY_ENIONLY)
  259   if (sc->is_adaptec) {
  260     adp_get_macaddr(scp, pa);
  261     sc->en_busreset = adp_busreset;
  262     adp_busreset(sc);
  263   }
  264 #endif
  265 
  266 #if !defined(MIDWAY_ADPONLY)
  267   if (!sc->is_adaptec) {
  268     eni_get_macaddr(scp, pa);
  269     sc->en_busreset = NULL;
  270     pci_conf_write(scp->en_pc, pa->pa_tag, EN_TONGA, 
  271                   (TONGA_SWAP_DMA|TONGA_SWAP_WORD));
  272   }
  273 #endif
  274 
  275   /*
  276    * done PCI specific stuff
  277    */
  278 
  279   en_attach(sc);
  280 
  281 }
  282 
  283 #if 0
  284 static void
  285 en_pci_shutdown(
  286         int howto,
  287         void *sc)
  288 {
  289     struct en_pci_softc *psc = (struct en_pci_softc *)sc;
  290     
  291     en_reset(&psc->esc);
  292     DELAY(10);
  293 }
  294 #endif
  295 
  296 #if !defined(MIDWAY_ENIONLY)
  297 
  298 #if defined(sparc) || defined(__FreeBSD__)
  299 #define bus_space_read_1(t, h, o) \
  300                 ((void)t, (*(volatile u_int8_t *)((h) + (o))))
  301 #endif
  302 
  303 static void 
  304 adp_get_macaddr(scp, pa)
  305      struct en_pci_softc *scp;
  306      struct pci_attach_args *pa;
  307 {
  308   struct en_softc * sc = (struct en_softc *)scp;
  309   int lcv;
  310 
  311   for (lcv = 0; lcv < sizeof(sc->macaddr); lcv++)
  312     sc->macaddr[lcv] = bus_space_read_1(sc->en_memt, sc->en_base,
  313                                         MID_ADPMACOFF + lcv);
  314 }
  315 
  316 #endif /* MIDWAY_ENIONLY */
  317 
  318 #if !defined(MIDWAY_ADPONLY)
  319 
  320 /*
  321  * Read station (MAC) address from serial EEPROM.
  322  * derived from linux drivers/atm/eni.c by Werner Almesberger, EPFL LRC.
  323  */
  324 #define EN_PROM_MAGIC  0x0c
  325 #define EN_PROM_DATA   0x02
  326 #define EN_PROM_CLK    0x01
  327 #define EN_ESI         64
  328 
  329 static void 
  330 eni_get_macaddr(scp, pa)
  331   struct en_pci_softc *scp;
  332   struct pci_attach_args *pa;
  333 {
  334   struct en_softc *sc = (struct en_softc *)scp;
  335   pci_chipset_tag_t id = scp->en_pc;
  336   pcitag_t tag = pa->pa_tag;
  337   int i, j, address;
  338   u_int32_t data, t_data;
  339   u_int8_t tmp;
  340   
  341   t_data = pci_conf_read(id, tag, EN_TONGA) & 0xffffff00;
  342 
  343   data =  EN_PROM_MAGIC | EN_PROM_DATA | EN_PROM_CLK;
  344   pci_conf_write(id, tag, EN_TONGA, data);
  345 
  346   for (i = 0; i < sizeof(sc->macaddr); i ++){
  347     /* start operation */
  348     data |= EN_PROM_DATA ;
  349     pci_conf_write(id, tag, EN_TONGA, data);
  350     data |= EN_PROM_CLK ;
  351     pci_conf_write(id, tag, EN_TONGA, data);
  352     data &= ~EN_PROM_DATA ;
  353     pci_conf_write(id, tag, EN_TONGA, data);
  354     data &= ~EN_PROM_CLK ;
  355     pci_conf_write(id, tag, EN_TONGA, data);
  356     /* send address with serial line */
  357     address = ((i + EN_ESI) << 1) + 1;
  358     for ( j = 7 ; j >= 0 ; j --){
  359       data = (address >> j) & 1 ? data | EN_PROM_DATA :
  360       data & ~EN_PROM_DATA;
  361       pci_conf_write(id, tag, EN_TONGA, data);
  362       data |= EN_PROM_CLK ;
  363       pci_conf_write(id, tag, EN_TONGA, data);
  364       data &= ~EN_PROM_CLK ;
  365       pci_conf_write(id, tag, EN_TONGA, data);
  366     }
  367     /* get ack */
  368     data |= EN_PROM_DATA ;
  369     pci_conf_write(id, tag, EN_TONGA, data);
  370     data |= EN_PROM_CLK ;
  371     pci_conf_write(id, tag, EN_TONGA, data);
  372     data = pci_conf_read(id, tag, EN_TONGA);
  373     data &= ~EN_PROM_CLK ;
  374     pci_conf_write(id, tag, EN_TONGA, data);
  375     data |= EN_PROM_DATA ;
  376     pci_conf_write(id, tag, EN_TONGA, data);
  377 
  378     tmp = 0;
  379 
  380     for ( j = 7 ; j >= 0 ; j --){
  381       tmp <<= 1;
  382       data |= EN_PROM_DATA ;
  383       pci_conf_write(id, tag, EN_TONGA, data);
  384       data |= EN_PROM_CLK ;
  385       pci_conf_write(id, tag, EN_TONGA, data);
  386       data = pci_conf_read(id, tag, EN_TONGA);
  387       if(data & EN_PROM_DATA) tmp |= 1;
  388       data &= ~EN_PROM_CLK ;
  389       pci_conf_write(id, tag, EN_TONGA, data);
  390       data |= EN_PROM_DATA ;
  391       pci_conf_write(id, tag, EN_TONGA, data);
  392     }
  393     /* get ack */
  394     data |= EN_PROM_DATA ;
  395     pci_conf_write(id, tag, EN_TONGA, data);
  396     data |= EN_PROM_CLK ;
  397     pci_conf_write(id, tag, EN_TONGA, data);
  398     data = pci_conf_read(id, tag, EN_TONGA);
  399     data &= ~EN_PROM_CLK ;
  400     pci_conf_write(id, tag, EN_TONGA, data);
  401     data |= EN_PROM_DATA ;
  402     pci_conf_write(id, tag, EN_TONGA, data);
  403 
  404     sc->macaddr[i] = tmp;
  405   }
  406   /* stop operation */
  407   data &=  ~EN_PROM_DATA;
  408   pci_conf_write(id, tag, EN_TONGA, data);
  409   data |=  EN_PROM_CLK;
  410   pci_conf_write(id, tag, EN_TONGA, data);
  411   data |=  EN_PROM_DATA;
  412   pci_conf_write(id, tag, EN_TONGA, data);
  413   pci_conf_write(id, tag, EN_TONGA, t_data);
  414 }
  415 
  416 #endif /* !MIDWAY_ADPONLY */

Cache object: 5a4f372211b2f6a89c41b3dabb20bb73


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