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/drivers/dp8390/3c503.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 /*
    2  *      3c503.c         A shared memory driver for Etherlink II board.
    3  *
    4  *      Created:        Dec. 20, 1996 by G. Falzoni <falzoni@marina.scn.de>
    5  *
    6  *      Inspired by the TNET package by M. Ostrowski, the driver for Linux
    7  *      by D. Becker, the Crynwr 3c503 packet driver, and the Amoeba driver.
    8  *
    9  *      It works in shared memory mode and should be used with the
   10  *      device driver for NS 8390 based cards of Minix.  Programmed
   11  *      I/O could be used as well but would result in poor performance.
   12  */
   13 
   14 #include "../drivers.h"
   15 
   16 #include <net/gen/ether.h>
   17 #include <net/gen/eth_io.h>
   18 
   19 #include "local.h"
   20 #include "dp8390.h"
   21 #include "3c503.h"
   22 
   23 #if ENABLE_3C503
   24 
   25 #define MILLIS_TO_TICKS(m)  (((m)*HZ/1000)+1)
   26 
   27 _PROTOTYPE(static void el2_init, (dpeth_t *dep));
   28 _PROTOTYPE(static void el2_stop, (dpeth_t *dep));
   29 _PROTOTYPE( static void milli_delay, (unsigned long millis)             );
   30 
   31 /*===========================================================================*
   32  *                              el2_init                                     *
   33  *===========================================================================*/
   34 static void el2_init(dep)
   35 dpeth_t * dep;
   36 {
   37   /* Initalize hardware and data structures. */
   38   int ix, irq;
   39   int sendq_nr;
   40   int cntr;
   41 
   42   /* Map the address PROM to lower I/O address range */
   43   cntr = inb_el2(dep, EL2_CNTR);
   44   outb_el2(dep, EL2_CNTR, cntr | ECNTR_SAPROM);
   45 
   46   /* Read station address from PROM */
   47   for (ix = EL2_EA0; ix <= EL2_EA5; ix += 1)
   48         dep->de_address.ea_addr[ix] = inb_el2(dep, ix);
   49 
   50   /* Map the 8390 back to lower I/O address range */
   51   outb_el2(dep, EL2_CNTR, cntr);
   52 
   53   /* Enable memory, but turn off interrupts until we are ready */
   54   outb_el2(dep, EL2_CFGR, ECFGR_IRQOFF);
   55 
   56   dep->de_data_port = dep->de_dp8390_port = dep->de_base_port;
   57   dep->de_prog_IO = 0;          /* Programmed I/O not yet available */
   58 
   59   /* Check width of data bus:
   60    * 1. Write 0 to WTS bit.  The board will drive it to 1 if it is a
   61    *    16-bit card.
   62    * 2. Select page 2
   63    * 3. See if it is a 16-bit card
   64    * 4. Select page 0
   65    */
   66   outb_el2(dep, DP_CR, CR_PS_P0|CR_DM_ABORT|CR_STP);
   67   outb_el2(dep, DP_DCR, 0);
   68   outb_el2(dep, DP_CR, CR_PS_P2|CR_DM_ABORT|CR_STP);
   69   dep->de_16bit = (inb_el2(dep, DP_DCR) & DCR_WTS) != 0;
   70   outb_el2(dep, DP_CR, CR_PS_P0|CR_DM_ABORT|CR_STP);
   71 
   72   /* Allocate one send buffer (1.5KB) per 8KB of on board memory. */
   73   sendq_nr = (dep->de_ramsize - dep->de_offset_page) / 0x2000;
   74   if (sendq_nr < 1)
   75         sendq_nr = 1;
   76   else if (sendq_nr > SENDQ_NR)
   77         sendq_nr = SENDQ_NR;
   78 
   79   dep->de_sendq_nr = sendq_nr;
   80   for (ix = 0; ix < sendq_nr; ix++)
   81         dep->de_sendq[ix].sq_sendpage = (ix * SENDQ_PAGES) + EL2_SM_START_PG;
   82 
   83   dep->de_startpage = (ix * SENDQ_PAGES) + EL2_SM_START_PG;
   84   dep->de_stoppage = EL2_SM_STOP_PG;
   85 
   86   outb_el2(dep, EL2_STARTPG, dep->de_startpage);
   87   outb_el2(dep, EL2_STOPPG, dep->de_stoppage);
   88 
   89   /* Point the vector pointer registers somewhere ?harmless?. */
   90   outb_el2(dep, EL2_VP2, 0xFF); /* Point at the ROM restart location    */
   91   outb_el2(dep, EL2_VP1, 0xFF); /* 0xFFFF:0000  (from original sources) */
   92   outb_el2(dep, EL2_VP0, 0x00); /*           - What for protected mode? */
   93 
   94   /* Set interrupt level for 3c503 */
   95   irq = (dep->de_irq &= ~DEI_DEFAULT);  /* Strip the default flag. */
   96   if (irq == 9) irq = 2;
   97   if (irq < 2 || irq > 5) panic("", "bad 3c503 irq configuration", irq);
   98   outb_el2(dep, EL2_IDCFG, (0x04 << irq));
   99 
  100   outb_el2(dep, EL2_DRQCNT, 0x08);      /* Set burst size to 8 */
  101   outb_el2(dep, EL2_DMAAH, EL2_SM_START_PG);    /* Put start of TX  */
  102   outb_el2(dep, EL2_DMAAL, 0x00);       /* buffer in the GA DMA reg */
  103 
  104   outb_el2(dep, EL2_CFGR, ECFGR_NORM);  /* Enable shared memory */
  105 
  106   if (!debug) {
  107         printf("%s: 3c503 at %X:%d:%lX\n",
  108                 dep->de_name, dep->de_base_port, dep->de_irq,
  109                 dep->de_linmem + dep->de_offset_page);
  110   } else {
  111         printf("%s: 3Com Etherlink II %sat I/O address 0x%X, "
  112                         "memory address 0x%lX, irq %d\n",
  113                 dep->de_name, dep->de_16bit ? "(16-bit) " : "",
  114                 dep->de_base_port,
  115                 dep->de_linmem + dep->de_offset_page,
  116                 dep->de_irq);
  117   }
  118 }
  119 
  120 /*===========================================================================*
  121  *                              el2_stop                                     *
  122  *===========================================================================*/
  123 static void el2_stop(dep)
  124 dpeth_t * dep;
  125 {
  126   /* Stops board by disabling interrupts. */
  127 
  128 #if DEBUG
  129   printf("%s: stopping Etherlink\n", dep->de_name);
  130 #endif
  131   outb_el2(dep, EL2_CFGR, ECFGR_IRQOFF);
  132   return;
  133 }
  134 
  135 /*===========================================================================*
  136  *                              el2_probe                                    *
  137  *===========================================================================*/
  138 int el2_probe(dep)
  139 dpeth_t * dep;
  140 {
  141   /* Probe for the presence of an EtherLink II card.  Initialize memory
  142    * addressing if card detected.
  143    */
  144   int iobase, membase;
  145   int thin;
  146 
  147   /* Thin ethernet or AUI? */
  148   thin = (dep->de_linmem & 1) ? ECNTR_AUI : ECNTR_THIN;
  149 
  150   /* Location registers should have 1 bit set */
  151   if (!(iobase = inb_el2(dep, EL2_IOBASE))) return 0;
  152   if (!((membase = inb_el2(dep, EL2_MEMBASE)) & 0xF0)) return 0;
  153   if ((iobase & (iobase - 1)) || (membase & (membase - 1))) return 0;
  154 
  155   /* Resets board */
  156   outb_el2(dep, EL2_CNTR, ECNTR_RESET | thin);
  157   milli_delay(1);
  158   outb_el2(dep, EL2_CNTR, thin);
  159   milli_delay(5);
  160 
  161   /* Map the address PROM to lower I/O address range */
  162   outb_el2(dep, EL2_CNTR, ECNTR_SAPROM | thin);
  163   if (inb_el2(dep, EL2_EA0) != 0x02 ||  /* Etherlink II Station address */
  164       inb_el2(dep, EL2_EA1) != 0x60 ||  /* MUST be 02:60:8c:xx:xx:xx */
  165       inb_el2(dep, EL2_EA2) != 0x8C)
  166         return 0;               /* No Etherlink board at this address */
  167 
  168   /* Map the 8390 back to lower I/O address range */
  169   outb_el2(dep, EL2_CNTR, thin);
  170 
  171   /* Setup shared memory addressing for 3c503 */
  172   dep->de_linmem = ((membase & 0xC0) ? EL2_BASE_0D8000 : EL2_BASE_0C8000) +
  173         ((membase & 0xA0) ? (EL2_BASE_0CC000 - EL2_BASE_0C8000) : 0x0000);
  174   dep->de_offset_page = (EL2_SM_START_PG * DP_PAGESIZE);
  175   dep->de_ramsize = (EL2_SM_STOP_PG - EL2_SM_START_PG) * DP_PAGESIZE;
  176 
  177   /* (Bad kludge, something Philip needs to look into. -- kjb) */
  178   dep->de_linmem -= dep->de_offset_page;
  179   dep->de_ramsize += dep->de_offset_page;
  180 
  181   /* Board initialization and stop functions */
  182   dep->de_initf = el2_init;
  183   dep->de_stopf = el2_stop;
  184   return 1;
  185 }
  186 
  187 static void milli_delay(unsigned long millis)
  188 {
  189         tickdelay(MILLIS_TO_TICKS(millis));
  190 }
  191 
  192 #endif /* ENABLE_3C503 */
  193 
  194 /** 3c503.c **/
  195 
  196 /*
  197  * $PchId: 3c503.c,v 1.3 2003/09/10 15:33:04 philip Exp $
  198  */

Cache object: fb56c3146fd75a40c65cea2b62cd84f6


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