if_eidve.c
上传用户:luoyougen
上传日期:2008-05-12
资源大小:23136k
文件大小:60k
源码类别:

VxWorks

开发平台:

C/C++

  1. /* if_eidve.c - Intel 82596 Ethernet network interface driver for DVE-SH7XXX */
  2. /* Copyright 1989-1997 Wind River Systems, Inc. */
  3. #include "copyright_wrs.h"
  4. /*
  5. modification history
  6. --------------------
  7. 03k,03mar99,jmb  Implement 2-byte alignment shift for RFD's, similar to
  8.                  offset shift in ei82596End.c
  9. 03j,15dec98,jmb  Bring driver up to BSD 4.4 for SENS compatibility.
  10. 03i,24apr97,hk   added DVE-SH7XXX support.
  11. 03h,05feb97,dat  fixed wdog reset action to use netJobAdd(). SPR 7771
  12. 03g,13aug96,dat  fixed wdog timer restart. SPR 6958
  13. 03g,12nov94,tmk  removed some IMPORTed function decs and included unixLib.h
  14. 03h,10oct94,caf  suppress buffer loaning for MIPS targets due to
  15.  problem with misaligned accesses.
  16. 03g,14oct93,wmd  Added initialization of pointer pDrvCtrl in eiWatchDog(),
  17.  SPR #2567.
  18. 03f,30sep93,wmd  Added changes to include timeout check of the receiver 
  19.  as done in the 5.0.6 release. Recreated eiInit() to allow
  20.  resetting the 596 if it locks up.
  21. 03e,11aug93,jmm  Changed ioctl.h and socket.h to sys/ioctl.h and sys/socket.h
  22. 03d,19feb93,jdi  documentation cleanup.
  23. 03c,15jan93,wmd  added setting of errno to S_ioslib_INVALID_ETHERNET_ADDRESS.
  24. 03b,11dec92,rfs  Removed dummy eiChipReset(), no longer needed for TP41.
  25. 03a,05oct92,rfs  Added documentation.
  26. 02z,02oct92,rfs  Made multiple attach calls per unit return OK, not ERROR.
  27. 02y,01oct92,rfs  Added 16 byte page alignment for SCP.
  28. 02x,28sep92,rfs  Modified the eiAction() routine to clear all events.  This
  29.                  makes the diagnostics pass, for some undocumented reason.
  30. 02w,09sep92,gae  documentation tweaks.
  31. 02v,11aug92,rfs  Slight change to memory carving.  Also fixed receive bug
  32.                  that was due to device manual incorrectly describing bit 7
  33.                  of config byte 10 and added error checks to RFDs.  Changed
  34.                  the device startup routine.
  35. 02u,26aug92,kdl  moved internal notes to file header (were just #ifdef'd out).
  36. 02t,19aug92,smb  changed systime.h to sys/times.h
  37. 02s,31jul92,dave Changed to new cacheLib.
  38. 02r,28jul92,rfs  Adapted to latest cache coherency model.
  39.                  Renamed driver control structure and moved it to bss.
  40.                  Combined the init() routine with the attach() routine and
  41.                  made attach() reject multiple invocations.  Rewrote the
  42.                  ioctl() routine to do the right stuff.  Reworked the action
  43.                  command routine and the primary command routine.  Other misc.
  44. 02q,16jul92,rfs  Moved driver specific items from header file to here,
  45.                  where they belong.
  46. 02p,16jul92,rfs  Moved internal comments to end of file, where they belong.
  47. 02o,03jul92,jwt  converted cacheClearEntry() calls to cacheClear() for 5.1.
  48. 02n,26jun92,rrr  make eiBusSnoop global again (needed by bsps)
  49. 02m,25jun92,rfs  backed out last mod; the manual is incorrect about the
  50.                  state of the bit that configures CRC inclusion
  51. 02l,25jun92,rfs  bug fix, changed a receive config parm that selects whether
  52.                  the CRC is included in the buffer
  53. 02k,23jun92,ajm  made eiChipReset global for tp41 BSP
  54. 02j,08jun92,ajm  modified so eiattach is only external function
  55.                  got rid of MEM_ROUND_UP macro now pulled in with vxWorks.h
  56.                  got rid of many ansi complaints
  57. 02i,26may92,rrr  the tree shuffle
  58.                  -changed includes to have absolute path from h/
  59. 02h,22feb92,wmd  added conditional compiles for 040, ansi fixes.
  60. 02g,07jan92,shl  made driver cache safe. added eiBusSnoop(). eliminated some
  61.                  ANSI warnings.
  62. 02f,12nov91,wmd  Added fix, courtesy of jrb-Intel, which added a watchdog to
  63.                  timeout any stalls due to hardware lockup and resets the
  64.                  82596.
  65. 02e,25oct91,rfs  Changed eiChipReset() to not depend on valid *es, and
  66.                  made it global for TP41 usage. Also eliminated ANSI
  67.                  warnings.
  68. 02d,04oct91,rrr  passed through the ansification filter
  69.                  -changed functions to ansi style
  70.                  -changed includes to have absolute path from h/
  71.                  -changed VOID to void
  72.                  -changed copyright notice
  73. 02c,15sep91,rfs  Bug fix. Eliminated lock condition when output queue full
  74.                  and out of TFDs. Added major comment to eiTxStartup. Also,
  75.                  major changes to eiChipReset() to make more robust. All
  76.                  instances of intLock()/intUnlock() changed to
  77.                  sys596IntDisable()/sys596IntEnable respectively. Statistic
  78.                  counters now being used, which required moderate changes to
  79.                  the transmit side design. More comments added.
  80. 02b,21aug91,rfs  changed method of obtaining Ethernet address.
  81. 02a,22jul91,jcf  completely rewritten to utilize simplified mode,
  82.             rfs  added big endian support, reworked buffer loaning.
  83. 01h,01may91,elh  fixed ethernet addressing problem, upgraded to 5.0,
  84.                  added buffer loanouts, fixed ifAddrSet bug by disabling
  85.                  interrupts in eiHardReset.
  86. 01g,28apr91,del  added #define of ETHER_HEADER_SIZE as workaround for
  87.                  gnu960 pading of struct ether_header.
  88. 01f,05jan91,gae  added global eiSCPSysConfig for board specific SCP parameters.
  89.                  moved CDELAY here from if_ei.h and renamed eichkcca.
  90. 01e,03jan91,gae  more cleanup and merged with Intel's fixes.
  91.                  Ethernet address (eiEnetAddr) is set in sysHwInit.
  92.                  cleaned up error printing & no carrier message always printed.
  93.                  changed printf's to printErr's (logMsg if at int level).
  94.                  made most routines local -- not available outside this module.
  95. 01d,31dec90,gae  removed 68K stuff.
  96. 01c,14dec90,elh  more cleanup.
  97. 01b,12dec90,elh  fixed buffer problems, cleaned up, added etherhooks.
  98. 01a,06feb90,djk  written
  99. */
  100. /*
  101. This module implements the Intel 82596 Ethernet network interface driver.
  102. This driver is designed to be moderately generic, operating unmodified
  103. across the range of architectures and targets supported by VxWorks.  
  104. To achieve this, this driver must be given several
  105. target-specific parameters, and some external support routines must be
  106. provided.  These parameters, and the mechanisms used to communicate them to the
  107. driver, are detailed below.
  108. This driver can run with the device configured in either
  109. big-endian or little-endian modes.  Error recovery code has been added to
  110. deal with some of the known errata in the A0 version of the device.  This
  111. driver supports up to four individual units per CPU.
  112. BOARD LAYOUT
  113. This device is on-board.  No jumpering diagram is necessary.
  114. EXTERNAL INTERFACE
  115. This driver provides the standard external interface with the following
  116. exceptions.  All initialization is performed within the attach routine;
  117. there is no separate initialization routine.  Therefore, in the global interface
  118. structure, the function pointer to the initialization routine is NULL.
  119. The only user-callable routine is eiattach(), which publishes the `ei'
  120. interface and initializes the driver and device.
  121. TARGET-SPECIFIC PARAMETERS
  122. .iP "the <sysbus> value"
  123. This parameter is passed to the driver by eiattach().
  124. The Intel 82596 requires this parameter during initialization.  This
  125. parameter tells the device about the system bus, hence the name "sysbus."
  126. To determine the correct value for a target, refer to the document
  127. .I "Intel 32-bit Local Area Network (LAN) Component User's Manual."
  128. .iP "interrupt vector"
  129. This parameter is passed to the driver by eiattach().
  130. The Intel 82596 generates hardware interrupts for various events within
  131. the device; thus it contains an interrupt handler routine.
  132. This driver calls intConnect() to connect its interrupt handler to the 
  133. interrupt vector generated as a result of the 82596 interrupt.
  134. .iP "shared memory address"
  135. This parameter is passed to the driver by eiattach().
  136. The Intel 82596 device is a DMA type device and typically shares
  137. access to some region of memory with the CPU.  This driver is designed
  138. for systems that directly share memory between the CPU and the 82596.
  139. This parameter can be used to specify an explicit memory region for use
  140. by the 82596.  This should be done on targets that restrict the 82596
  141. to a particular memory region.  The constant NONE can be used to indicate
  142. that there are no memory limitations, in which case, the driver 
  143. attempts to allocate the shared memory from the system space.
  144. .iP "number of Receive and Transmit Frame Descriptors"
  145. These parameters are passed to the driver by eiattach().
  146. The Intel 82596 accesses frame descriptors in memory for each frame
  147. transmitted or received.  The number of frame descriptors 
  148. at run-time can be configured using these parameters.
  149. .iP "Ethernet address"
  150. This parameter is obtained by a call to an external support routine.
  151. During initialization, the driver needs to know the Ethernet address for
  152. the Intel 82596 device.  The driver calls the external support routine,
  153. sysEnetAddrGet(), to obtain the Ethernet address.  For a description of
  154. sysEnetAddrGet(), see "External Support Requirements" below.
  155. .LP
  156. EXTERNAL SUPPORT REQUIREMENTS
  157. This driver requires seven external support functions:
  158. .iP "STATUS sysEnetAddrGet (int unit, char *pCopy)" "" 9 -1
  159. This routine provides the six-byte Ethernet address
  160. used by <unit>.  It must copy the six-byte address
  161. to the space provided by <pCopy>.  This routine 
  162. returns OK, or ERROR if it fails.  The driver calls this 
  163. routine, once per unit, using eiattach().
  164. .iP "STATUS sys596Init (int unit)"
  165. This routine performs any target-specific initialization
  166. required before the 82596 is initialized.  Typically, it is empty.  
  167. This routine must return OK, or ERROR if it fails.
  168. The driver calls this routine, once per unit, using eiattach().
  169. .iP "void sys596Port (int unit, int cmd, UINT32 addr)"
  170. This routine provides access to the special port
  171. function of the 82596.  It delivers the command and
  172. address arguments to the port of the specified unit.
  173. The driver calls this routine primarily during
  174. initialization, but may also call it during error
  175. recovery procedures.
  176. .iP "void sys596ChanAtn (int unit)"
  177. This routine provides the channel attention signal to
  178. the 82596, for the specified <unit>.  The driver calls
  179. this routine frequently throughout all phases of
  180. operation.
  181. .iP "void sys596IntEnable (int unit), void sys596IntDisable (int unit)"
  182. These routines enable or disable the interrupt from
  183. the 82596 for the specified <unit>.  Typically, this
  184. involves interrupt controller hardware, either
  185. internal or external to the CPU.  Since the 82596
  186. itself has no mechanism for controlling its interrupt
  187. activity, these routines are vital to the correct
  188. operation of the driver.  The driver calls these
  189. routines throughout normal operation to protect
  190. certain critical sections of code from interrupt
  191. handler intervention.
  192. .iP "void sys596IntAck (int unit)"
  193. This routine must perform any required interrupt acknowledgment 
  194. or clearing.  Typically, this involves an operation to some interrupt
  195. control hardware.  Note that the INT signal from the 82596
  196. behaves in an "edge-triggered" mode; therefore, this routine 
  197. typically clears a latch within the control circuitry.
  198. The driver calls this routine from the interrupt handler.
  199. .LP
  200. SYSTEM RESOURCE USAGE
  201. When implemented, this driver requires the following system resources:
  202.     - one mutual exclusion semaphore
  203.     - one interrupt vector
  204.     - one watchdog timer.
  205.     - 8 bytes in the initialized data section (data)
  206.     - 912 bytes in the uninitialized data section (BSS)
  207. The above data and BSS requirements are for the MC68020 architecture 
  208. and may vary for other architectures.  Code size (text) varies greatly between
  209. architectures and is therefore not quoted here.
  210. The driver uses cacheDmaMalloc() to allocate memory to share with the 82596.  
  211. The fixed-size pieces in this area total 160 bytes.  The variable-size 
  212. pieces in this area are affected by the configuration parameters specified 
  213. in the eiattach() call.  The size of one RFD (Receive Frame
  214. Descriptor) is 1536 bytes.  The size of one TFD (Transmit Frame Descriptor) 
  215. is 1534 bytes.  For more information about RFDs and TFDs, see the 
  216. .I "Intel 82596 User's Manual."
  217. The 82596 can be operated only if this shared memory region is non-cacheable
  218. or if the hardware implements bus snooping.  The driver cannot maintain
  219. cache coherency for the device because fields within the command
  220. structures are asynchronously modified by both the driver and the device,
  221. and these fields may share the same cache line.
  222. TUNING HINTS
  223. The only adjustable parameters are the number of TFDs and RFDs that will be
  224. created at run-time.  These parameters are given to the driver when eiattach()
  225. is called.  There is one TFD and one RFD associated with each transmitted
  226. frame and each received frame respectively.  For memory-limited applications,
  227. decreasing the number of TFDs and RFDs may be desirable.  Increasing the number
  228. of TFDs will provide no performance benefit after a certain point.
  229. Increasing the number of RFDs will provide more buffering before packets are
  230. dropped.  This can be useful if there are tasks running at a higher priority
  231. than the net task.
  232. SEE ALSO: ifLib,
  233. .I "Intel 82596 User's Manual,"
  234. .I "Intel 32-bit Local Area Network (LAN) Component User's Manual"
  235. */
  236. #include "vxWorks.h"
  237. #include "wdLib.h"
  238. #include "iv.h"
  239. #include "vme.h"
  240. #include "net/mbuf.h"
  241. #include "net/unixLib.h"
  242. #include "net/protosw.h"
  243. #include "sys/socket.h"
  244. #include "sys/ioctl.h"
  245. #include "errno.h"
  246. #include "memLib.h"
  247. #include "intLib.h"
  248. #include "net/if.h"
  249. #include "net/route.h"
  250. #include "iosLib.h"
  251. #include "errnoLib.h"
  252. #include "cacheLib.h"
  253. #include "logLib.h"
  254. #include "netLib.h"
  255. #include "stdio.h"
  256. #include "stdlib.h"
  257. #include "sysLib.h"
  258. #ifdef  INET
  259. #include "netinet/in.h"
  260. #include "netinet/in_systm.h"
  261. #include "netinet/in_var.h"
  262. #include "netinet/ip.h"
  263. #include "netinet/if_ether.h"
  264. #endif  /* INET */
  265. #include "etherLib.h"
  266. #include "net/systm.h"
  267. #include "sys/times.h"
  268. #include "drv/netif/if_ei.h"
  269. #include "net/if_subr.h"
  270. /***** LOCAL DEFINITIONS *****/
  271. #define DMA_MEMORY_IS_DUALPORTED /* DVE-SH7XXX specific */
  272. #undef EI_DEBUG                             /* Compiles debug output */
  273. #define MAX_UNITS       4                   /* maximum units to support */
  274. #define DEF_NUM_TFDS    32                  /* default number of TFDs */
  275. #define DEF_NUM_RFDS    32                  /* default number of RFDs */
  276. #if     (CPU_FAMILY == MIPS)
  277. #define MAX_RFDS_LOANED 0                   /* suppress buffer loaning */
  278. #else
  279. #define MAX_RFDS_LOANED 8                   /* max RFDs that can be loaned */
  280. #endif  /* (CPU_FAMILY == MIPS) */
  281. /* Typedefs for external structures that are not typedef'd in their .h files */
  282. typedef struct mbuf MBUF;
  283. typedef struct arpcom IDR;                  /* Interface Data Record wrapper */
  284. typedef struct ifnet IFNET;                 /* real Interface Data Record */
  285. typedef struct sockaddr SOCK;
  286. typedef struct ether_header ETH_HDR;
  287. /* The definition of our linked list management structure */
  288. typedef struct ei_list                       /* EI_LIST - 82596 queue head */
  289.     {
  290.     volatile EI_NODE *  head;       /* header of list */
  291.     volatile EI_NODE *  tail;       /* tail of list */
  292.     } EI_LIST;
  293. /* The definition of the driver control structure */
  294. typedef struct drv_ctrl
  295.     {
  296.     IDR                 idr;        /* interface data record */
  297.     BOOL                attached;   /* indicates attach() called */
  298.     char                *memBase;   /* 82596 memory pool base */
  299.     SCP                 *pScp;      /* SCP ptr */
  300.     ISCP                *pIscp;     /* ISCP ptr */
  301.     SCB                 *pScb;      /* SCB ptr */
  302.     CFD                 *pCfd;      /* synchronous command frame */
  303.     RFD                 *rfdPool;   /* RFD pool */
  304.     TFD                 *tfdPool;   /* TFD pool */
  305.     RFD                 *pFreeRfd;  /* first empty RFD in rxQueue */
  306.     volatile EI_LIST    rxQueue;    /* receive queue */
  307.     volatile EI_LIST    txQueue;    /* to be sent queue */
  308.     volatile EI_LIST    tfdQueue;   /* free transmit frame descriptors */
  309.     volatile EI_LIST    cblQueue;   /* actual chip transmit queue */
  310.     volatile EI_LIST    cleanQueue; /* queue of TFDs to cleanup */
  311.     volatile BOOL       rcvHandling;/* flag, indicates netTask active */
  312.     volatile BOOL       txCleaning; /* flag, indicates netTask active */
  313.     volatile BOOL       txIdle;     /* flag, indicates idle transmitter */
  314.     int                 nTFDs;      /* how many TFDs to create */
  315.     int                 nRFDs;      /* how many RFDs to create */
  316.     int                 nLoanRfds;  /* number of loanable RFDs left */
  317.     UINT8               sysbus;     /* SCP sysbus value */
  318.     int                 ivec;       /* interrupt vector */
  319.     CACHE_FUNCS         cacheFuncs; /* cache descriptor */
  320.     WDOG_ID             wid;        /* watchdog timer for transmit */
  321.     int                 wdInterval; /* ticks between eiWatchDog runs */
  322.     long recvLocks;  /* count for receive lockup failures */
  323.     long                transLocks; /* count for transmit lockup failures */
  324.     volatile char wdTxTimeout;/* watchdog runs with transmit hung */
  325.     volatile char wdRxTimeout;/* watchdog runs with receive hung */
  326.     } DRV_CTRL;
  327. #define DRV_CTRL_SIZ  sizeof(DRV_CTRL)
  328. #define EI_RX_TIMEOUT 3         /* # watchdog runs for receive timeout */
  329. #define EI_TX_TIMEOUT 2         /* # watchdog runs for transmit timeout */
  330. /***** GLOBALS *****/
  331. /* Function declarations not in any header files */
  332. IMPORT STATUS sysEnetAddrGet (int unit, char addr[]);
  333. IMPORT STATUS sys596Init (int unit);
  334. IMPORT STATUS sys596IntAck (int unit);
  335. IMPORT STATUS sys596IntEnable (int unit);
  336. IMPORT void   sys596IntDisable (int unit);
  337. IMPORT void   sys596Port (int unit, int cmd, UINT32 addr);
  338. IMPORT void   sys596ChanAtn (int unit);
  339. #ifdef DMA_MEMORY_IS_DUALPORTED
  340. IMPORT void *sysDmaVirtToPhys (void * address);
  341. IMPORT void *sysDmaPhysToVirt (void * address);
  342. #endif /* DMA_MEMORY_IS_DUALPORTED */
  343. /***** LOCALS *****/
  344. /* The array of driver control structs */
  345. LOCAL DRV_CTRL drvCtrl [MAX_UNITS];
  346. /* forward function declarations */
  347. static STATUS eiInit (int unit);
  348. static void eiReset (int unit);
  349. static int eiIoctl (IFNET *pIfNet, int cmd, caddr_t data);
  350. static void eiTxStartup (DRV_CTRL * pDrvCtrl);
  351. static void eiInt (DRV_CTRL *pDrvCtrl);
  352. static void eiTxCleanQ (DRV_CTRL *pDrvCtrl);
  353. static void eiHandleRecvInt (DRV_CTRL *pDrvCtrl);
  354. static STATUS eiReceive (DRV_CTRL *pDrvCtrl, RFD *pRfd);
  355. static void eiLoanFree (DRV_CTRL *pDrvCtrl, RFD *pRfd);
  356. static void eiDiag (int unit);
  357. static void eiConfig (int unit);
  358. static void eiIASetup (int unit);
  359. static void eiRxStartup (DRV_CTRL *pDrvCtrl);
  360. static void eiAction (int unit, UINT16 action);
  361. static STATUS eiCommand (DRV_CTRL *pDrvCtrl, UINT16 cmd);
  362. static void eiTxQPut (DRV_CTRL *pDrvCtrl, TFD *pTfd);
  363. static void eiTxQFlush (DRV_CTRL *pDrvCtrl);
  364. static void eiRxQPut (DRV_CTRL *pDrvCtrl, RFD *pRfd);
  365. static RFD *eiRxQGet (DRV_CTRL *pDrvCtrl);
  366. static BOOL eiRxQFull (DRV_CTRL *pDrvCtrl);
  367. static void eiQInit (EI_LIST *pHead);
  368. static EI_NODE *eiQGet (EI_LIST *pQueue);
  369. static void eiQPut (int unit, EI_LIST *pQueue, EI_NODE *pNode);
  370. static STATUS eiDeviceStart (int unit);
  371. static void eiWatchDog(int unit);
  372. /*******************************************************************************
  373. *
  374. * eiattach - publish the `ei' network interface and initialize the driver and device
  375. *
  376. * This routine publishes the `ei' interface by filling in a network interface
  377. * record and adding this record to the system list.  This routine also
  378. * initializes the driver and the device to the operational state.
  379. *
  380. * The 82596 shares a region of memory with the driver.  The caller of this
  381. * routine can specify the address of this memory region, or can specify that
  382. * the driver must obtain this memory region from the system resources.
  383. *
  384. * The <sysbus> parameter accepts values as described in the Intel manual
  385. * for the 82596.  A default number of transmit/receive frames of 32 can be
  386. * selected by passing zero in the parameters <nTfds> and <nRfds>.
  387. * In other cases, the number of frames selected should be greater than two.
  388. *
  389. * The <memBase> parameter is used to inform the driver about the shared
  390. * memory region.  If this parameter is set to the constant "NONE," then this
  391. * routine will attempt to allocate the shared memory from the system.  Any
  392. * other value for this parameter is interpreted by this routine as the address
  393. * of the shared memory region to be used.
  394. *
  395. * If the caller provides the shared memory region, then the driver assumes
  396. * that this region does not require cache coherency operations, nor does it
  397. * require conversions between virtual and physical addresses.
  398. *
  399. * If the caller indicates that this routine must allocate the shared memory
  400. * region, then this routine will use cacheDmaMalloc() to obtain
  401. * some  non-cacheable memory.  The attributes of this memory will be checked,
  402. * and if the memory is not both read and write coherent, this routine will
  403. * abort and return ERROR.
  404. *
  405. * RETURNS: OK or ERROR.
  406. *
  407. * SEE ALSO: ifLib,
  408. * .I "Intel 82596 User's Manual"
  409. */
  410. STATUS eidveattach
  411.     (
  412.     int         unit,       /* unit number */
  413.     int         ivec,       /* interrupt vector number */
  414.     UINT8       sysbus,     /* sysbus field of SCP */
  415.     char *      memBase,    /* address of memory pool or NONE */
  416.     int         nTfds,      /* no. of transmit frames (0 = default) */
  417.     int         nRfds       /* no. of receive frames (0 = default) */
  418.     )
  419.     {
  420.     DRV_CTRL    *pDrvCtrl;
  421.     UINT        size;                           /* temporary size holder */
  422.     UINT        sizeScp;
  423.     UINT        sizeIscp;
  424.     UINT        sizeScb;
  425.     UINT        sizeCfd;
  426.     RFD *       pRfd;                   /* pointer to RFD's */
  427.     int         ix;
  428.     static char *errMsg1 = "neidveattach: could not obtain memoryn";
  429.     static char *errMsg2 = "neidveattach: shared memory not cache coherentn";
  430.     sizeScp  = MEM_ROUND_UP (sizeof (SCP));
  431.     sizeIscp = MEM_ROUND_UP (sizeof (ISCP));
  432.     sizeScb  = MEM_ROUND_UP (sizeof (SCB));
  433.     sizeCfd  = MEM_ROUND_UP (sizeof (CFD));
  434.     /* Sanity check the unit number */
  435.     if (unit < 0 || unit >= MAX_UNITS)
  436.         return (ERROR);
  437.     /* Ensure single invocation per system life */
  438.     pDrvCtrl = & drvCtrl [unit];
  439.     if (pDrvCtrl->attached)
  440.         return (OK);
  441.     /* Determine number of Tx and Rx descriptors to use */
  442.     pDrvCtrl->nTFDs = nTfds ? nTfds : DEF_NUM_TFDS;
  443.     pDrvCtrl->nRFDs = nRfds ? nRfds : DEF_NUM_RFDS;
  444.     /* calculate the total size of 82596 memory pool */
  445.     size =
  446.             24 +                                /* allow for alignment */
  447.             sizeScp +
  448.             sizeIscp +
  449.             sizeScb +
  450.             sizeCfd +                           /* synch'ed command frame */
  451.             (sizeof (RFD) * pDrvCtrl->nRFDs) +  /* pool of receive frames */
  452.             (sizeof (TFD) * pDrvCtrl->nTFDs);   /* pool of transmit frames */
  453.     /* Establish the memory area that we will share with the device.  If
  454.      * the caller has provided an area, then we assume it is non-cacheable
  455.      * and will not require the use of the special cache routines.
  456.      * If the caller did not provide an area, then we must obtain it from
  457.      * the system, using the cache savvy allocation routine.
  458.      */
  459.     switch ((int) memBase)
  460.         {
  461.         case NONE :                            /* we must obtain it */
  462.             /* this driver can't handle incoherent caches */
  463.             if (!CACHE_DMA_IS_WRITE_COHERENT () ||
  464.                 !CACHE_DMA_IS_READ_COHERENT ())
  465.                 {
  466.                 printf (errMsg2);
  467.                 goto error;
  468.                 }
  469.             pDrvCtrl->memBase = cacheDmaMalloc (size);
  470.             if (pDrvCtrl->memBase == NULL)    /* no memory available */
  471.                 {
  472.                 printf (errMsg1);
  473.                 goto error;
  474.                 }
  475. #ifndef DMA_MEMORY_IS_DUALPORTED
  476.             pDrvCtrl->cacheFuncs = cacheDmaFuncs;
  477. #endif /* DMA_MEMORY_IS_DUALPORTED */
  478.             break;
  479.         default :                               /* the user provided an area */
  480.             pDrvCtrl->memBase = memBase;        /* use the provided address */
  481. #ifndef DMA_MEMORY_IS_DUALPORTED
  482.             pDrvCtrl->cacheFuncs = cacheNullFuncs;
  483. #else
  484.     printf ("neidveattach: allocate 0x%x bytes from address 0x%x... ",
  485. size, (UINT)(pDrvCtrl->memBase));
  486. #endif /* DMA_MEMORY_IS_DUALPORTED */
  487.             break;
  488.         }
  489. #ifdef DMA_MEMORY_IS_DUALPORTED
  490. pDrvCtrl->cacheFuncs.flushRtn      = NULL;
  491. pDrvCtrl->cacheFuncs.invalidateRtn = NULL;
  492. pDrvCtrl->cacheFuncs.virtToPhysRtn = (FUNCPTR)sysDmaVirtToPhys;
  493. pDrvCtrl->cacheFuncs.physToVirtRtn = (FUNCPTR)sysDmaPhysToVirt;
  494. #endif /* DMA_MEMORY_IS_DUALPORTED */
  495.     /* Save other passed-in parameters */
  496.     pDrvCtrl->sysbus = sysbus;                  /* remember sysbus value */
  497.     pDrvCtrl->ivec = ivec;                      /* interrupt vector */
  498.     /* Carve up the shared memory region into the specific sections */
  499.     bzero ((char *) pDrvCtrl->memBase, size);
  500.     pDrvCtrl->pScp  = (SCP *)                /* align to first 16 byte page */
  501.                       ( ((u_long) pDrvCtrl->memBase + 0xf) & ~0xf );
  502.     pDrvCtrl->pIscp = (ISCP *)((int)pDrvCtrl->pScp   + sizeScp);
  503.     pDrvCtrl->pScb  = (SCB *) ((int)pDrvCtrl->pIscp  + sizeIscp);
  504.     pDrvCtrl->pCfd  = (CFD *) ((int)pDrvCtrl->pScb   + sizeScb);
  505.     /*
  506.      * Align the RFD pool on a 2-byte boundary.  This causes the IP
  507.      * header to be aligned on a 4-byte boundary and enables the protocol
  508.      * layer (ip_input) to access long fields without getting a bus error.
  509.      */
  510.     pDrvCtrl->rfdPool = (RFD *) 
  511.         (MEM_ROUND_UP (((int)pDrvCtrl->pCfd + sizeCfd)) + 2);
  512.     pDrvCtrl->tfdPool = (TFD *) /* TFD is OK on a 4-byte boundary */
  513.       MEM_ROUND_UP ((int)pDrvCtrl->rfdPool+ (sizeof (RFD) * pDrvCtrl->nRFDs));
  514.     for (ix = 0, pRfd = pDrvCtrl->rfdPool; ix < DEF_NUM_RFDS; ix++, pRfd++)
  515.         {
  516.         pRfd->refCnt = 0;                    /* initialize ref cnt */
  517.         }
  518.     /* Init the watchdog that will patrol for device lockups */
  519.  
  520.     pDrvCtrl->transLocks = 0;
  521.     pDrvCtrl->recvLocks = 0;
  522.     pDrvCtrl->wid = wdCreate ();                      /* create watchdog */
  523.     if (pDrvCtrl->wid == NULL)                        /* no resource */
  524.         goto error;
  525.     pDrvCtrl->wdInterval = sysClkRateGet() >> 1;
  526.     /* get our enet addr */
  527.     if (sysEnetAddrGet (unit, (char *)pDrvCtrl->idr.ac_enaddr) == ERROR)
  528. {
  529. errnoSet (S_iosLib_INVALID_ETHERNET_ADDRESS);
  530.         goto error;
  531. }
  532.     /* Publish the interface record */
  533.     ether_attach    (
  534.                     (IFNET *) & pDrvCtrl->idr,
  535.                     unit,
  536.                     "ei",
  537.                     (FUNCPTR) NULL,
  538.                     (FUNCPTR) eiIoctl,
  539.                     (FUNCPTR) ether_output,
  540.                     (FUNCPTR) eiReset
  541.                     );
  542.     pDrvCtrl->idr.ac_if.if_start = (FUNCPTR) eiTxStartup;
  543.     /* initialize the unit */
  544.     if (eiInit (unit) == ERROR)
  545.         goto error;
  546.     /* Set our flag */
  547.     pDrvCtrl->attached = TRUE;
  548.     /* Set status flags in IDR */
  549.     pDrvCtrl->idr.ac_if.if_flags |= (IFF_UP | IFF_RUNNING | IFF_NOTRAILERS);
  550.     /* Successful return */
  551.     return (OK);
  552.     /***** Handle error cases *****/
  553.     error:
  554.         {
  555.         /* Release system memory */
  556.         if (((int) memBase == NONE) && ((int) pDrvCtrl->memBase != NULL))
  557.             cacheDmaFree (pDrvCtrl->memBase);
  558.         /* Release watchdog */
  559.         if (pDrvCtrl->wid != NULL)
  560.             wdDelete (pDrvCtrl->wid);
  561.         return (ERROR);
  562.         }
  563.     }
  564. /*******************************************************************************
  565. *
  566. * eiInit - Initialize the interface.
  567. *
  568. * Initialization of interface; clear recorded pending operations.
  569. * Called at boot time and by eiWatchDog() if a reset is required.
  570. *
  571. * RETURNS: OK or ERROR
  572. */
  573. static STATUS eiInit 
  574.     (
  575.     int unit /* unit number */
  576.     )
  577.     {
  578.     DRV_CTRL    *pDrvCtrl = & drvCtrl [unit];
  579.     pDrvCtrl->rcvHandling   = FALSE;  /* netTask not running our receive job */
  580.     pDrvCtrl->txCleaning    = FALSE;  /* netTask not running our clean job */
  581.     pDrvCtrl->txIdle        = TRUE;         /* transmitter idle */
  582.     eiQInit ((EI_LIST *)&pDrvCtrl->rxQueue);    /* to be received queue */
  583.     eiQInit ((EI_LIST *)&pDrvCtrl->txQueue);    /* to be sent queue */
  584.     eiQInit ((EI_LIST *)&pDrvCtrl->tfdQueue);   /* free tfds to add to send q */
  585.     eiQInit ((EI_LIST *)&pDrvCtrl->cblQueue);   /* actively sending queue */
  586.     eiQInit ((EI_LIST *)&pDrvCtrl->cleanQueue); /* queue of TFDs to clean */
  587.     pDrvCtrl->wdTxTimeout = 0;
  588.     pDrvCtrl->wdRxTimeout = 0;
  589.     { /***** Perform device initialization *****/
  590.     /* Block local variables */
  591.     int ix;
  592.     sys596IntDisable (unit);            /* disable device interrupts */
  593.     (void) sys596Init (unit);           /* do board specific init */
  594.     /* Connect the interrupt handler */
  595.     if (intConnect ((VOIDFUNCPTR *)INUM_TO_IVEC (pDrvCtrl->ivec),
  596.     eiInt, (int)pDrvCtrl) == ERROR)
  597.         return (ERROR);
  598.     /* Start the device */
  599.     if ( eiDeviceStart (unit) == ERROR )
  600.         return (ERROR);
  601.     eiDiag (unit);                             /* run diagnostics */
  602.     eiConfig (unit);                           /* configure chip */
  603.     eiIASetup (unit);                          /* setup address */
  604.     for (ix = 0; ix < pDrvCtrl->nTFDs; ix ++)  /* tank up the free tfd queue */
  605.         {
  606.         eiQPut  (
  607.                 unit,
  608.                 (EI_LIST *) & pDrvCtrl->tfdQueue,
  609.                 (EI_NODE *) & pDrvCtrl->tfdPool [ix]
  610.                 );
  611.         }
  612.     pDrvCtrl->pFreeRfd  = NULL;                  /* first free RFD */
  613.     pDrvCtrl->nLoanRfds = MAX_RFDS_LOANED;       /* number of loanable RFD's */
  614.     for (ix = 0; ix < pDrvCtrl->nRFDs; ix ++)   /* tank up the receive queue */
  615. {
  616. if (pDrvCtrl->rfdPool[ix].refCnt == 0)
  617.         eiRxQPut (pDrvCtrl, & pDrvCtrl->rfdPool [ix]);
  618. }
  619.     sys596IntAck (unit);                     /* clear any pended dev ints */
  620.     sys596IntEnable (unit);                  /* enable interrupts at system */
  621.     } /* End block */
  622.     wdCancel(pDrvCtrl->wid);                  /* in case re-initializing */
  623.     wdStart(pDrvCtrl->wid, 
  624.     (int) pDrvCtrl->wdInterval, 
  625.     (FUNCPTR) eiWatchDog, 
  626.     pDrvCtrl->idr.ac_if.if_unit
  627.    );
  628.     return (OK);
  629.     }
  630. /*******************************************************************************
  631. *
  632. * eiReset - reset the ei interface
  633. *
  634. * Mark interface as inactive and reset the chip.
  635. */
  636. static void eiReset
  637.     (
  638.     int unit
  639.     )
  640.     {
  641.     DRV_CTRL *pDrvCtrl;
  642.     pDrvCtrl = & drvCtrl [unit];
  643.     pDrvCtrl->idr.ac_if.if_flags = 0;
  644.     sys596IntDisable (unit);                    /* disable ints from the dev */
  645.     sys596Port (unit, PORT_RESET, NULL);        /* reset the 596 chip */
  646.     }
  647. /*******************************************************************************
  648. *
  649. * eiIoctl - interface ioctl procedure
  650. *
  651. * Process an interface ioctl request.
  652. */
  653. static int eiIoctl
  654.     (
  655.     IFNET  *pIfNet,
  656.     int     cmd,
  657.     caddr_t data
  658.     )
  659.     {
  660.     int error;
  661. #ifdef EI_DEBUG
  662.     printf ("ei: ioctl: pIDR=%x cmd=%x data=%xn", pIDR, cmd, data);
  663. #endif /* EI_DEBUG */
  664.     error = 0;
  665.     switch (cmd)
  666.         {
  667.         case SIOCSIFADDR:
  668.             ((struct arpcom *)pIfNet)->ac_ipaddr = IA_SIN (data)->sin_addr;
  669.             arpwhohas (pIfNet, &IA_SIN (data)->sin_addr);
  670.             break;
  671.         case SIOCSIFFLAGS:
  672.             /* Flags are set outside this module. No additional work to do. */
  673.             break;
  674.         default:
  675.             error = EINVAL;
  676.         }
  677.     return (error);
  678.     }
  679. /*******************************************************************************
  680. *
  681. * eiTxStartup - start output on the chip
  682. *
  683. * Looks for any action on the queue, and begins output if there is anything
  684. * there.  This routine is called from several possible threads.  Each will be
  685. * described below.
  686. *
  687. * The first, and most common thread, is when a user task requests the
  688. * transmission of data.  This will cause eiOutput() to be called, which will
  689. * cause ether_output() to be called, which will cause this routine to be
  690. * called (usually).  This routine will not be called if ether_output() finds
  691. * that our interface output queue is full.  In this case, the outgoing data
  692. * will be thrown out.
  693. *
  694. * The second, and most obscure thread, is when the reception of certain
  695. * packets causes an immediate (attempted) response.  For example, ICMP echo
  696. * packets (ping), and ICMP "no listener on that port" notifications.  All
  697. * functions in this driver that handle the reception side are executed in the
  698. * context of netTask().  Always.  So, in the case being discussed, netTask() 
  699. * will receive these certain packets, cause IP to be stimulated, and cause the
  700. * generation of a response to be sent.  We then find ourselves following the
  701. * thread explained in the second example, with the important distinction that
  702. * the context is that of netTask().
  703. *
  704. * The third thread occurs when this routine runs out of TFDs and returns.  If
  705. * this occurs when our output queue is not empty, this routine would typically
  706. * not get called again until new output was requested.  Even worse, if the
  707. * output queue was also full, this routine would never get called again and
  708. * we would have a lock state.  It DOES happen.  To guard against this, the
  709. * transmit clean-up handler detects the out-of-TFDs state and calls this
  710. * function.  The clean-up handler also runs from netTask.
  711. *
  712. * Note that this function is ALWAYS called between an splnet() and an splx().
  713. * This is true because netTask(), and ether_output() take care of
  714. * this when calling this function.  Therefore, no calls to these spl functions
  715. * are needed anywhere in this output thread.
  716. */
  717. void eiTxStartup
  718.     (
  719.     DRV_CTRL * pDrvCtrl
  720.     )
  721.     {
  722.     MBUF * pMbuf;
  723.     int length;
  724.     TFD * pTfd;
  725.     /*
  726.      * Loop until there are no more packets ready to send or we
  727.      * have insufficient resources left to send another one.
  728.      */
  729.     while (pDrvCtrl->idr.ac_if.if_snd.ifq_head)
  730.         {
  731.         IF_DEQUEUE (&pDrvCtrl->idr.ac_if.if_snd, pMbuf);  /* dequeue a packet */
  732.         /* get free tfd */
  733.         pTfd = (TFD *) eiQGet ((EI_LIST *)&pDrvCtrl->tfdQueue);
  734.         if (pTfd == NULL)
  735.             {
  736.             m_freem (pMbuf);
  737.             break;                              /* out of TFD's */
  738.             }
  739.         copy_from_mbufs ((ETH_HDR *)pTfd->enetHdr, pMbuf, length);
  740.         length = max (ETHERSMALL, length);
  741.         if ((etherOutputHookRtn != NULL) &&
  742.             (* etherOutputHookRtn)
  743.             (&pDrvCtrl->idr, (ETH_HDR *)pTfd->enetHdr, length))
  744.             continue;
  745.         pTfd->count = length & ~0xc000;     /* fill in length */
  746.         eiTxQPut (pDrvCtrl, pTfd);
  747.         }
  748.     }
  749. /*******************************************************************************
  750. *
  751. * eiInt - entry point for handling interrupts from the 82596
  752. *
  753. * The interrupting events are acknowledged to the device, so that the device
  754. * will deassert its interrupt signal.  The amount of work done here is kept
  755. * to a minimum; the bulk of the work is defered to the netTask.  Several flags
  756. * are used here to synchronize with task level code and eliminate races.
  757. */
  758. static void eiInt
  759.     (
  760.     DRV_CTRL *pDrvCtrl
  761.     )
  762.     {
  763.     UINT16  event;
  764.     SCB *pScb;
  765.     int unit;
  766.     pScb = pDrvCtrl->pScb;
  767.     unit = pDrvCtrl->idr.ac_if.if_unit;
  768.     event = pScb->scbStatus & (SCB_S_CX | SCB_S_FR | SCB_S_CNA | SCB_S_RNR);
  769. #ifdef EI_DEBUG
  770.     logMsg ("ei: interrupt: event=%xn", event, 0, 0, 0, 0, 0);
  771. #endif /* EI_DEBUG */
  772.     eiCommand (pDrvCtrl, event);                        /* ack the events */
  773.     sys596IntAck (unit);                                /* ack 596 interrupt */
  774.     /* Handle transmitter interrupt */
  775.     if (event & SCB_S_CNA)                              /* reclaim tx tfds */
  776.         {
  777.         pDrvCtrl->wdTxTimeout = 0;              /* reset timeout count */
  778.         if (pDrvCtrl->cleanQueue.head == NULL)      /* clean queue empty */
  779.             {
  780.             pDrvCtrl->cleanQueue.head = pDrvCtrl->cblQueue.head; /* new head */
  781.             pDrvCtrl->cleanQueue.tail = pDrvCtrl->cblQueue.tail; /* new tail */
  782.             }
  783.         else                                            /* concatenate queues */
  784.             {
  785.             LINK_WR ( (EI_LINK * ) &(pDrvCtrl->cleanQueue.tail->pNext),
  786.                         (void*) pDrvCtrl->cblQueue.head); 
  787.             pDrvCtrl->cleanQueue.tail = pDrvCtrl->cblQueue.tail;
  788.             }
  789.         if (!pDrvCtrl->txCleaning)                          /* not cleaning? */
  790.             {
  791.             pDrvCtrl->txCleaning = TRUE;                    /* set flag */
  792.             netJobAdd ((FUNCPTR) eiTxCleanQ, (int) pDrvCtrl, 0, 0, 0, 0);
  793.                             /* defer cleanup */
  794.             }
  795.         if (pDrvCtrl->txQueue.head != NULL)             /* anything to flush? */
  796.             eiTxQFlush (pDrvCtrl);                      /* flush the tx q */
  797.         else
  798.             pDrvCtrl->txIdle = TRUE;                    /* transmitter idle */
  799.         }
  800.     /* Handle receiver interrupt */
  801.     if (event & SCB_S_FR)
  802. {
  803. pDrvCtrl->wdRxTimeout = 0;                  /* reset timeout count */
  804. if (!(pDrvCtrl->rcvHandling))
  805.             {
  806.             pDrvCtrl->rcvHandling = TRUE;
  807.             (void) netJobAdd ((FUNCPTR) eiHandleRecvInt, (int) pDrvCtrl,0, 0, 0, 0);         /* netTask processes */
  808.     }
  809.         }
  810.     }
  811. /*******************************************************************************
  812. *
  813. * eiTxCleanQ - checks errors in completed TFDs and moves TFDs to free queue
  814. *
  815. * This routine is executed by netTask.  It "cleans" the TFDs on the clean-up
  816. * queue by checking each one for errors and then returning the TFD to the
  817. * "free TFD" queue.  The startup routine is sometimes called here to eliminate
  818. * the lock-out case where the driver input queue is full but there are no
  819. * TFDs available.
  820. */
  821. static void eiTxCleanQ
  822.     (
  823.     DRV_CTRL *pDrvCtrl
  824.     )
  825.     {
  826.     TFD *pTfd;
  827.     BOOL needTxStart;
  828.     int unit;
  829.     unit = pDrvCtrl->idr.ac_if.if_unit;
  830.     do
  831.         {
  832.         pDrvCtrl->txCleaning = TRUE;
  833.         if (pDrvCtrl->tfdQueue.head == NULL)              /* tfd queue empty */
  834.             needTxStart = TRUE;                           /* set flag */
  835.         else
  836.             needTxStart = FALSE;
  837.         /* process transmitted frames */
  838.         while (1)
  839.             {
  840.             /* Get TFD. No ints allowed while manipulating this queue. */
  841.             sys596IntDisable (unit);
  842.             pTfd = (TFD*) eiQGet ((EI_LIST *)&pDrvCtrl->cleanQueue);
  843.             sys596IntEnable (unit);
  844.             if (pTfd == NULL)
  845.                 break;
  846.             pDrvCtrl->idr.ac_if.if_collisions +=         /* add any colls */
  847.                 (pTfd->status & CFD_S_RETRY) ? 16 :  /* excessive colls */
  848.                 (pTfd->status & CFD_S_COLL_MASK);    /* some colls */
  849.             if (!(pTfd->status & CFD_S_OK))          /* packet not sent */
  850.                 {
  851.                 pDrvCtrl->idr.ac_if.if_oerrors++;        /* incr err count */
  852.                 pDrvCtrl->idr.ac_if.if_opackets--;       /* decr sent count */
  853.                 }
  854.             /* return to tfdQ */
  855.             eiQPut (unit,(EI_LIST *)&pDrvCtrl->tfdQueue, (EI_NODE*)pTfd);
  856.             }
  857.         if (needTxStart)                                  /* check flag */
  858.             eiTxStartup (pDrvCtrl);
  859.         pDrvCtrl->txCleaning = FALSE;
  860.         }
  861.     while (pDrvCtrl->cleanQueue.head != NULL);            /* check again */
  862.     }
  863. /*******************************************************************************
  864. *
  865. * eiHandleRecvInt - task level interrupt service for input packets
  866. *
  867. * This routine is called at task level indirectly by the interrupt
  868. * service routine to do any message received processing.
  869. */
  870. static void eiHandleRecvInt
  871.     (
  872.     DRV_CTRL *pDrvCtrl
  873.     )
  874.     {
  875.     RFD *pRfd;
  876.     do
  877.         {
  878.         pDrvCtrl->rcvHandling = TRUE;             /* interlock with eiInt() */
  879.         while ((pRfd = eiRxQGet (pDrvCtrl)) != NULL)
  880.             if (eiReceive (pDrvCtrl, pRfd) == OK)
  881.                 eiRxQPut (pDrvCtrl, pRfd);
  882.         pDrvCtrl->rcvHandling = FALSE;            /* interlock with eiInt() */
  883.         }
  884.     while (eiRxQFull (pDrvCtrl));              /* make sure rx q still empty */
  885.     }
  886. /*******************************************************************************
  887. *
  888. * eiReceive - pass a received frame to the next layer up
  889. *
  890. * Strips the Ethernet header and passes the packet to the appropriate
  891. * protocol.  The return value indicates if buffer loaning was used to hold
  892. * the data.  A return value of OK means that loaning was not done, and it
  893. * is therefore 'ok' to return the RFD to the Rx queue.  A return value of ERROR
  894. * means that buffer loaning was employed, and so the RFD is still in use and
  895. * should not be returned to the Rx queue.  In this latter case, the RFD will
  896. * eventually be returned by the protocol, via a call to our eiLoanFree().
  897. */
  898. static STATUS eiReceive
  899.     (
  900.     DRV_CTRL *pDrvCtrl,
  901.     RFD *pRfd
  902.     )
  903.     {
  904.     ETH_HDR     *pEh;
  905.     u_char      *pData;
  906.     int         len;
  907.     UINT16      etherType;
  908.     MBUF        *m = NULL;
  909.     BOOL        rfdLoaned = FALSE;
  910.     /* Check packet for errors.  This should be completely unnecessary,
  911.      * but since Intel does not seem capable of explaining the exact
  912.      * functioning of the 'save bad frames' config bit, we will look for
  913.      * errors.
  914.      */
  915.     if  (
  916.         ( pRfd->status & ( RFD_S_OK | RFD_S_COMPLETE ) ) !=
  917.         ( RFD_S_OK | RFD_S_COMPLETE )
  918.         )
  919.         {
  920.         ++pDrvCtrl->idr.ac_if.if_ierrors;            /* bump error counter */
  921.         eiRxQPut (pDrvCtrl, pRfd);                   /* free the RFD */
  922.         return (ERROR);
  923.         }
  924.     /* Bump input packet counter. */
  925.     ++pDrvCtrl->idr.ac_if.if_ipackets;
  926.     len = pRfd->actualCnt & ~0xc000;        /* get frame length */
  927.     pEh = (ETH_HDR *)pRfd->enetHdr;         /* get ptr to ethernet header */
  928.     /* Service input hook */
  929.     if ( (etherInputHookRtn != NULL) )
  930.         {
  931.         if  ( (* etherInputHookRtn) (&pDrvCtrl->idr, (char *)pEh, len) )
  932.             {
  933.             eiRxQPut (pDrvCtrl, pRfd);                  /* free the RFD */
  934.             return (OK);
  935.             }
  936.         }
  937.     len -= EH_SIZE;
  938.     pData = (u_char *) pRfd->enetData;
  939.     etherType = ntohs (pEh->ether_type);
  940.     /* we can loan out receive frames from 82596 receive queue if:
  941.      *
  942.      * 1) the threshold of loanable frames has not been exceeded
  943.      * 2) size of the input ethernet frame is large enough to be used with
  944.      *    clustering.
  945.      */
  946.     if ((pDrvCtrl->nLoanRfds > 0) &&
  947.         ((m = build_cluster (pData, len, &pDrvCtrl->idr, MC_EI, &pRfd->refCnt,
  948.                  eiLoanFree, (int) pDrvCtrl, (int) pRfd, NULL)) != NULL))
  949.         {
  950.         pDrvCtrl->nLoanRfds --;             /* one less to loan */
  951.         rfdLoaned = TRUE;               /* we loaned a frame */
  952.         }
  953.     else
  954.         m = copy_to_mbufs (pData, len, 0, &pDrvCtrl->idr);
  955.     if (m != NULL)
  956. #ifdef BSD43_DRIVER
  957.         do_protocol_with_type (etherType, m, &pDrvCtrl->idr, len);
  958. #else
  959.         do_protocol (pEh, m, &pDrvCtrl->idr, len);
  960. #endif
  961.     return ((rfdLoaned) ? ERROR : OK);
  962.     }
  963. /*******************************************************************************
  964. *
  965. * eiLoanFree - return a loaned receive frame descriptor
  966. *
  967. * This routine is called by the protocol code when it has completed use of
  968. * an RFD that we loaned to it.
  969. */
  970. static void eiLoanFree
  971.     (
  972.     DRV_CTRL *pDrvCtrl,
  973.     RFD *pRfd
  974.     )
  975.     {
  976.     eiRxQPut (pDrvCtrl, pRfd);
  977.     pDrvCtrl->nLoanRfds ++;
  978.     }
  979. /*******************************************************************************
  980. *
  981. * eiDeviceStart - reset and start the device
  982. *
  983. * This routine assumes interrupts from the device have been disabled, and
  984. * that the driver control structure has been initialized.
  985. */
  986. static STATUS eiDeviceStart
  987.     (
  988.     int unit                              /* physical unit number */
  989.     )
  990.     {
  991.     void     *pTemp;
  992.     DRV_CTRL *pDrvCtrl;
  993.     SCP      *pScp;                       /* system config ptr */
  994.     ISCP     *pIscp;                      /* intermediate system config ptr */
  995.     SCB      *pScb;                       /* system control block ptr */
  996.     /* Get pointers */
  997.     pDrvCtrl = & drvCtrl [unit];
  998.     pScp = pDrvCtrl->pScp;
  999.     pIscp = pDrvCtrl->pIscp;
  1000.     pScb = pDrvCtrl->pScb;
  1001.     /* Issue the reset operation to the device */
  1002.     sys596Port (unit, PORT_RESET, NULL);
  1003.     /* Initialize the SCP */
  1004.     pScp->scpRsv1 =
  1005.     pScp->scpRsv2 =
  1006.     pScp->scpRsv3 = 0;
  1007.     pScp->scpSysbus = pDrvCtrl->sysbus;
  1008.     pTemp = CACHE_DRV_VIRT_TO_PHYS (&pDrvCtrl->cacheFuncs, pIscp);
  1009.     LINK_WR (&pScp->pIscp, pTemp);              /* point SCP to ISCP */
  1010.     /* Initialize the ISCP */
  1011.     pIscp->iscpBusy = 1;
  1012.     pIscp->iscpRsv1 = 0;
  1013.     pTemp = CACHE_DRV_VIRT_TO_PHYS (&pDrvCtrl->cacheFuncs, pScb);
  1014.     LINK_WR (&pIscp->pScb, pTemp);              /* point ISCP to SCB */
  1015.     /* Initialize the SCB */
  1016.     bzero ((char *)pScb, sizeof (SCB));
  1017.     /* Tell the device where the SCP is located */
  1018.     pTemp = CACHE_DRV_VIRT_TO_PHYS (&pDrvCtrl->cacheFuncs, pScp);
  1019.     sys596Port (unit, PORT_NEWSCP, (UINT32) pTemp);
  1020.     sys596ChanAtn (unit);
  1021.     /*
  1022.      * The device will now read our SCP and ISCP. It will clear the busy
  1023.      * flag in the ISCP.
  1024.      */
  1025.     taskDelay (50);
  1026.     if ( pIscp->iscpBusy == 1 )
  1027.         {
  1028.         printf ("nei: device did not initializen");
  1029.         return (ERROR);
  1030.         }
  1031.     return (OK);
  1032.     }
  1033. /*******************************************************************************
  1034. *
  1035. * eiDiag - format and issue a diagnostic command
  1036. */
  1037. static void eiDiag
  1038.     (
  1039.     int unit
  1040.     )
  1041.     {
  1042.     DRV_CTRL *pDrvCtrl;
  1043.     pDrvCtrl = & drvCtrl [unit];
  1044.     bzero ((char *)pDrvCtrl->pCfd, sizeof (CFD));       /* zero command frame */
  1045.     eiAction (unit, CFD_C_DIAG);                /* run diagnostics */
  1046.     if (!(pDrvCtrl->pCfd->cfdStatus & CFD_S_OK))
  1047.         printErr ("eiDiag: i82596 diagnostics failed.n");
  1048.     }
  1049. /*******************************************************************************
  1050. *
  1051. * eiConfig - format and issue a config command
  1052. */
  1053. static void eiConfig
  1054.     (
  1055.     int unit
  1056.     )
  1057.     {
  1058.     DRV_CTRL *pDrvCtrl;
  1059.     pDrvCtrl = & drvCtrl [unit];
  1060.     bzero ((char *)pDrvCtrl->pCfd, sizeof (CFD));       /* zero command frame */
  1061.     /* Recommeded i82596 User's Manual configuration values.  Note that
  1062.      * the original manual, #296443-001, was full of errors.  Errors in the
  1063.      * description of the config bytes that I am aware of are noted below.
  1064.      * It is possible there are further errors.  Intel has replaced the
  1065.      * manual with #296853-001, which does correct some errors, but not all.
  1066.      */
  1067.     pDrvCtrl->pCfd->cfdConfig.ccByte8  = 0x8e;
  1068.     pDrvCtrl->pCfd->cfdConfig.ccByte9  = 0xc8;
  1069.     /* The manual is wrong about bit 7 in byte 10.
  1070.      * A '0' allows reception of bad packets.
  1071.      * A '1' causes rejection of bad packets.
  1072.      */
  1073.     pDrvCtrl->pCfd->cfdConfig.ccByte10 = 0xc0;
  1074.     pDrvCtrl->pCfd->cfdConfig.ccByte11 = 0x2e;      /* loopback, NSAI */
  1075.     pDrvCtrl->pCfd->cfdConfig.ccByte12 = 0x00;
  1076.     pDrvCtrl->pCfd->cfdConfig.ccByte13 = 0x60;
  1077.     pDrvCtrl->pCfd->cfdConfig.ccByte14 = 0x00;
  1078.     pDrvCtrl->pCfd->cfdConfig.ccByte15 = 0xf2;
  1079.     pDrvCtrl->pCfd->cfdConfig.ccByte16 = 0x00;      /* promiscuous off */
  1080.     pDrvCtrl->pCfd->cfdConfig.ccByte17 = 0x00;
  1081.     pDrvCtrl->pCfd->cfdConfig.ccByte18 = 0x40;
  1082.     /* The manual is wrong about 2 bits in byte 19.
  1083.      * Bit 5, multicast, a '1' disables.
  1084.      * Bit 2, include CRC, a '1' disables.
  1085.      */
  1086.     pDrvCtrl->pCfd->cfdConfig.ccByte19 = 0xff;
  1087.     pDrvCtrl->pCfd->cfdConfig.ccByte20 = 0x00;
  1088.     pDrvCtrl->pCfd->cfdConfig.ccByte21 = 0x3f;
  1089.     eiAction (unit, CFD_C_CONFIG);          /* configure the chip */
  1090.     }
  1091. /*******************************************************************************
  1092. *
  1093. * eiIASetup - format and issue an interface address command
  1094. */
  1095. static void eiIASetup
  1096.     (
  1097.     int unit
  1098.     )
  1099.     {
  1100.     DRV_CTRL *pDrvCtrl;
  1101.     pDrvCtrl = & drvCtrl [unit];
  1102.     bzero ((char *)pDrvCtrl->pCfd, sizeof (CFD));       /* zero command frame */
  1103.     bcopy   (
  1104.             (char *)pDrvCtrl->idr.ac_enaddr,
  1105.             (char *)pDrvCtrl->pCfd->cfdIASetup.ciAddress,
  1106.             6
  1107.             );
  1108.     eiAction (unit, CFD_C_IASETUP);         /* setup the address */
  1109.     }
  1110. /*******************************************************************************
  1111. *
  1112. * eiRxStartup - start up the Receive Unit
  1113. *
  1114. * Starts up the Receive Unit.  Assumes that the receive structures are set up.
  1115. */
  1116. static void eiRxStartup
  1117.     (
  1118.     DRV_CTRL *pDrvCtrl
  1119.     )
  1120.     {
  1121.     SCB *pScb = pDrvCtrl->pScb;
  1122.     void * pTemp;
  1123.     if (pScb->scbStatus & SCB_S_RUREADY)        /* already running */
  1124.         return;
  1125.     pTemp = CACHE_DRV_VIRT_TO_PHYS (&pDrvCtrl->cacheFuncs, pDrvCtrl->pFreeRfd);
  1126.     LINK_WR (&pScb->pRF, pTemp);            /* point to free Rfd */
  1127.     sys596IntDisable (pDrvCtrl->idr.ac_if.if_unit);
  1128.     if ((pScb->scbStatus & SCB_S_RUMASK) != SCB_S_RUIDLE)
  1129.         eiCommand (pDrvCtrl, SCB_C_RUABORT);            /* abort if not idle */
  1130.     eiCommand (pDrvCtrl, SCB_C_RUSTART);              /* start receive unit */
  1131.     sys596IntEnable (pDrvCtrl->idr.ac_if.if_unit);
  1132.     }
  1133. /*******************************************************************************
  1134. *
  1135. * eiAction - execute the specified action with the CFD pointed to in pDrvCtrl
  1136. *
  1137. * Do the command contained in the CFD synchronously, so that we know
  1138. * it's complete upon return.  This routine assumes that interrupts from the
  1139. * device have been disabled.
  1140. */
  1141. static void eiAction
  1142.     (
  1143.     int    unit,
  1144.     UINT16 action
  1145.     )
  1146.     {
  1147.     void     *pTemp;
  1148.     CFD      *pCfd;
  1149.     SCB      *pScb;
  1150.     DRV_CTRL *pDrvCtrl;
  1151.     pDrvCtrl = & drvCtrl [unit];
  1152.     pCfd = pDrvCtrl->pCfd;
  1153.     pScb = pDrvCtrl->pScb;
  1154.     while (1)                   /* wait for idle command unit */
  1155.         {
  1156.         if ((pScb->scbStatus & SCB_S_CUMASK) == SCB_S_CUIDLE)
  1157.             break;
  1158.         }
  1159.     { /* Prepare and issue the command to the device */
  1160.     /* fill in CFD */
  1161.     pCfd->cfdStatus  = 0;                       /* clear status */
  1162.     pCfd->cfdCommand = CFD_C_EL | action;       /* fill in action */
  1163.     LINK_WR (&pCfd->link, NULL);                /* terminate link */
  1164.     /* and the SCB */
  1165.     pScb->scbCommand =
  1166.                         SCB_S_CX |              /* ack any events */
  1167.                         SCB_S_FR |
  1168.                         SCB_S_CNA |
  1169.                         SCB_S_RNR |
  1170.                         SCB_C_CUSTART;          /* start command unit */
  1171.     pTemp = CACHE_DRV_VIRT_TO_PHYS (&pDrvCtrl->cacheFuncs, pCfd);
  1172.     LINK_WR (&pScb->pCB, pTemp);                /* point chip at CFD */
  1173.     sys596ChanAtn (unit);               /* notify device of new command */
  1174.     }
  1175.     while (1)               /* wait for command acceptance and interrupt */
  1176.         {
  1177.         if ((pScb->scbCommand == 0) && (pScb->scbStatus & SCB_S_CNA))
  1178.             break;
  1179.         }
  1180.     /* Acknowledge the event to the device */
  1181.     pScb->scbCommand = (SCB_S_CX | SCB_S_CNA);
  1182.     sys596ChanAtn (unit);
  1183.     while (1)               /* wait for acknowledge acceptance */
  1184.         {
  1185.         if (pScb->scbCommand == 0)
  1186.             break;
  1187.         }
  1188.     }
  1189. /*******************************************************************************
  1190. *
  1191. * eiCommand - deliver a command to the 82596 via SCB
  1192. *
  1193. * This function causes the device to execute a command.  It should be called
  1194. * with interrupts from the device disabled.  An error status is returned if
  1195. * the command field does not return to zero, from a previous command, in a
  1196. * reasonable amount of time.
  1197. */
  1198. static STATUS eiCommand
  1199.     (
  1200.     DRV_CTRL *pDrvCtrl,
  1201.     UINT16    cmd
  1202.     )
  1203.     {
  1204.     int loopy;
  1205.     SCB * pScb;
  1206.     pScb = pDrvCtrl->pScb;
  1207.     for (loopy = 0x8000; loopy--;)
  1208.         {
  1209.         if (pScb->scbCommand == 0)                  /* wait for cmd zero */
  1210.             break;
  1211.         }
  1212.     if (loopy > 0)
  1213.         {
  1214.         pScb->scbCommand = cmd;                     /* fill in command */
  1215.         sys596ChanAtn (pDrvCtrl->idr.ac_if.if_unit);    /* channel attention */
  1216.         return (OK);
  1217.         }
  1218.     else
  1219.         {
  1220.         logMsg("ei driver: command field frozenn", 0, 0, 0, 0, 0, 0);
  1221.         return (ERROR);
  1222.         }
  1223.     }
  1224. /*******************************************************************************
  1225. *
  1226. * eiTxQPut - place a transmit frame on the transmit queue
  1227. *
  1228. * The TFD has been filled in with the network pertinent data.  This
  1229. * routine will enqueue the TFD for transmission and attempt to feed
  1230. * the queue to the device.
  1231. */
  1232. static void eiTxQPut
  1233.     (
  1234.     DRV_CTRL *pDrvCtrl,
  1235.     TFD *pTfd
  1236.     )
  1237.     {
  1238.     int unit;
  1239.     unit = pDrvCtrl->idr.ac_if.if_unit;
  1240.     pTfd->status    = 0;                    /* fill in TFD fields */
  1241.     pTfd->command   = CFD_C_XMIT;           /* EL set later */
  1242.     pTfd->count     |= TFD_CNT_EOF;         /* data kept in frame */
  1243.     pTfd->reserved  = 0;                    /* must be zero */
  1244.     LINK_WR (& pTfd->lBufDesc, NULL);                /* TBDs not used */
  1245.     sys596IntDisable (pDrvCtrl->idr.ac_if.if_unit);  /* disable dev ints */
  1246.     /* enqueue the TFD */
  1247.     eiQPut (unit,(EI_LIST *)&pDrvCtrl->txQueue, (EI_NODE*)pTfd);
  1248.     if (pDrvCtrl->txIdle)                             /* transmitter idle */
  1249.         eiTxQFlush (pDrvCtrl);                        /* flush txQueue */
  1250.     sys596IntEnable (pDrvCtrl->idr.ac_if.if_unit);  /* enable dev ints */
  1251.     }
  1252. /*******************************************************************************
  1253. *
  1254. * eiTxQFlush - make cmd unit of device start processing cmds
  1255. *
  1256. * This routine flushes the contents of the txQ to the cblQ and starts the
  1257. * device transmitting the cblQ.  Called only if transmit queue is not empty.
  1258. * Sometimes called from interrupt handler.
  1259. */
  1260. static void eiTxQFlush
  1261.     (
  1262.     DRV_CTRL *pDrvCtrl
  1263.     )
  1264.     {
  1265.     void * pTemp;
  1266.     extern int sysClkRateGet();     /* we call this */
  1267.     ((TFD*)pDrvCtrl->txQueue.tail)->command |= CFD_C_EL;  /* EL terminate q */
  1268.     pDrvCtrl->cblQueue.head = pDrvCtrl->txQueue.head;   /* remember cbl head */
  1269.     pDrvCtrl->cblQueue.tail = pDrvCtrl->txQueue.tail;   /* remember cbl tail */
  1270.     eiQInit ((EI_LIST *)&pDrvCtrl->txQueue);            /* tx queue now empty */
  1271.     pTemp = CACHE_DRV_VIRT_TO_PHYS (&pDrvCtrl->cacheFuncs,
  1272.                                     pDrvCtrl->cblQueue.head);
  1273.     LINK_WR (&pDrvCtrl->pScb->pCB, pTemp);          /* point CU to head */
  1274.     pDrvCtrl->txIdle = FALSE;                   /* transmitter busy */
  1275.     /* start command unit */
  1276.     eiCommand (pDrvCtrl, SCB_C_CUSTART);
  1277.     }
  1278. /*******************************************************************************
  1279. *
  1280. * eiRxQPut - return a RFD to the receive queue for use by the device
  1281. */
  1282. static void eiRxQPut
  1283.     (
  1284.     DRV_CTRL *pDrvCtrl,
  1285.     RFD *pRfd
  1286.     )
  1287.     {
  1288.     int unit;
  1289.     RFD *pTail;
  1290.     unit = pDrvCtrl->idr.ac_if.if_unit;
  1291.     pRfd->status    = 0;                    /* clear status */
  1292.     pRfd->command   = CFD_C_EL;             /* new end of list */
  1293.     pRfd->actualCnt  = 0;                   /* clear actual count */
  1294.     pRfd->bufSize   = ETHERMTU + EH_SIZE;   /* fill in size */
  1295.     pRfd->refCnt    = 0;                    /* initialize ref cnt */
  1296.     LINK_WR (& pRfd->lBufDesc, 0xffffffff);         /* no RBD used */
  1297.     pTail = (RFD *) pDrvCtrl->rxQueue.tail;         /* remember tail */
  1298.     /* Put the RFD on the list */
  1299.     eiQPut (unit, (EI_LIST *) & pDrvCtrl->rxQueue, (EI_NODE *) pRfd);
  1300.     if (pTail != NULL)
  1301.         {
  1302.         pDrvCtrl->wdRxTimeout = 0;          /* reset timeout count */
  1303.         pTail->command &= ~CFD_C_EL;        /* clear old tail EL */
  1304.         if (pTail->status & (CFD_S_COMPLETE | CFD_S_BUSY))
  1305.             {
  1306.             pDrvCtrl->pFreeRfd = pRfd;          /* link questionable */
  1307.             }
  1308.         else if (!(pDrvCtrl->pScb->scbStatus & SCB_S_RUREADY))
  1309.             /* receiver dormant */
  1310.             {
  1311.             eiRxStartup (pDrvCtrl);             /* start receive unit */
  1312.             }
  1313.         }
  1314.     else
  1315.         {
  1316.         pDrvCtrl->pFreeRfd = pRfd;              /* first free RFD */
  1317.         }
  1318.     }
  1319. /*******************************************************************************
  1320. *
  1321. * eiRxQGet - get a successfully received frame from the receive queue
  1322. *
  1323. * RETURNS: ptr to valid RFD, or NULL if none available
  1324. */
  1325. static RFD *eiRxQGet
  1326.     (
  1327.     DRV_CTRL *pDrvCtrl
  1328.     )
  1329.     {
  1330.     RFD *pRfd = NULL;
  1331.     if (eiRxQFull (pDrvCtrl))
  1332.         pRfd = (RFD *) eiQGet ((EI_LIST *)&pDrvCtrl->rxQueue);
  1333.     return (pRfd);
  1334.     }
  1335. /*******************************************************************************
  1336. *
  1337. * eiRxQFull - boolean function to determine fullness of receive queue
  1338. *
  1339. * RETURNS: TRUE if completely received frame is available, FALSE otherwise.
  1340. */
  1341. static BOOL eiRxQFull
  1342.     (
  1343.     DRV_CTRL *pDrvCtrl
  1344.     )
  1345.     {
  1346.     return ((pDrvCtrl->rxQueue.head != NULL) &&
  1347.         (((RFD*)pDrvCtrl->rxQueue.head)->status & CFD_S_COMPLETE));
  1348.     }
  1349. /*******************************************************************************
  1350. *
  1351. * eiQInit - initialize a singly linked node queue
  1352. */
  1353. static void eiQInit
  1354.     (
  1355.     EI_LIST *pQueue
  1356.     )
  1357.     {
  1358.     pQueue->head = pQueue->tail = NULL;         /* init head & tail */
  1359.     }
  1360. /*******************************************************************************
  1361. *
  1362. * eiQGet - get a node from the head of a node queue
  1363. *
  1364. * RETURNS: ptr to useable node, or NULL ptr if none available
  1365. */
  1366. static EI_NODE *eiQGet
  1367.     (
  1368.     EI_LIST *pQueue
  1369.     )
  1370.     {
  1371.     EI_NODE *pNode;
  1372.     if ((pNode = (EI_NODE *) pQueue->head) != NULL)     /* if list not empty */
  1373.         pQueue->head = (EI_NODE *) LINK_RD ( (EI_LINK *) &pNode->pNext);    /* advance ptr */
  1374.     return (pNode);
  1375.     }
  1376. /*******************************************************************************
  1377. *
  1378. * eiQPut - put a node on the tail of a node queue
  1379. */
  1380. static void eiQPut
  1381.     (
  1382.     int unit,
  1383.     EI_LIST *pQueue,
  1384.     EI_NODE *pNode
  1385.     )
  1386.     {
  1387.     void * pTemp;
  1388.     DRV_CTRL *pDrvCtrl;
  1389.     pDrvCtrl = & drvCtrl [unit];
  1390.     LINK_WR (&pNode->lNext, NULL);                    /* mark "end of list" */
  1391.     LINK_WR ((EI_LINK *) &pNode->pNext, NULL);
  1392.     if (pQueue->head == NULL)                        /* if list empty */
  1393.         pQueue->tail = pQueue->head = pNode;         /* set both ptrs */
  1394.     else
  1395.         {
  1396.         pTemp = CACHE_DRV_VIRT_TO_PHYS (&pDrvCtrl->cacheFuncs, pNode);
  1397.         LINK_WR (&pQueue->tail->lNext, pTemp);       /* link node on tail */
  1398.         LINK_WR ((EI_LINK *) & pQueue->tail->pNext, pNode);
  1399.         pQueue->tail = pNode;                        /* update tail ptr */
  1400.         }
  1401.     }
  1402. /*******************************************************************************
  1403. *
  1404. * eiWatchDog - if the watchdog timer fired off, we've hung during a transmit
  1405. *
  1406. * Check the scb command to verify and if so, reinit.
  1407. */
  1408. static void eiWatchDog
  1409.     (
  1410.     int unit        /* unit number */
  1411.     )
  1412.     {
  1413.     DRV_CTRL *pDrvCtrl = &drvCtrl [unit];
  1414.     SCB *pScb;
  1415.     int reset = FALSE;
  1416.     pScb = pDrvCtrl->pScb;
  1417.     /* Test for transmit timeout.
  1418.      *
  1419.      * Timeout occurs if the scb status indicates that CU (transmit) 
  1420.      * remains active for EI_TX_TIMEOUT iterations of eiWatchDog.
  1421.      * It might make sense to loop through the cfd's to look for
  1422.      * a complete bit as a sanity check, but given that transmit
  1423.      * was active, we will go ahead and do a reset.
  1424.      */
  1425.     if ((pDrvCtrl->txIdle == FALSE)
  1426.         && (pScb->scbStatus & SCB_S_CUACTIVE))
  1427.         {
  1428.         if (++(pDrvCtrl->wdTxTimeout) > EI_TX_TIMEOUT)
  1429.             {
  1430.             pDrvCtrl->transLocks++;   /* failure count */
  1431.             pDrvCtrl->idr.ac_if.if_oerrors++;             /* incr err count */
  1432.             pDrvCtrl->idr.ac_if.if_opackets--;            /* decr sent count */
  1433.             reset = TRUE;
  1434.             }
  1435.         }
  1436.     /* Test for receive timeout.
  1437.      *
  1438.      * Timeout occurs if the scb status indicates that RU (receive) 
  1439.      * remains out of resources for EI_RX_TIMEOUT iterations of eiWatchDog.
  1440.      */
  1441.     if (pScb->scbStatus & SCB_S_RUNORSRC)
  1442.         {
  1443.         if (++(pDrvCtrl->wdRxTimeout) > EI_RX_TIMEOUT)
  1444.             {
  1445.             pDrvCtrl->recvLocks++;   /* failure count */
  1446.             reset = TRUE;
  1447.             }
  1448.         }
  1449.     /* reinitialize the unit or restart the watchdog */
  1450.     if (reset)
  1451. netJobAdd ((FUNCPTR) eiInit, unit, 0, 0, 0, 0);
  1452.     else
  1453.         wdStart (pDrvCtrl->wid, 
  1454. (int) pDrvCtrl->wdInterval, 
  1455. (FUNCPTR) eiWatchDog, 
  1456. unit);
  1457.     }
  1458. /******************************************************************************/
  1459. /* END OF FILE */