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

VxWorks

开发平台:

C/C++

  1. /* if_med.h - Matrix DB-ETH ethernet driver header file */
  2. /* Copyright 1984-1997 Wind River Systems, Inc. */
  3. /*
  4. modification history
  5. --------------------
  6. 02g,15jul97,spm  removed unused control field bPromisc from BSD 4.4 driver
  7. 02g,06dec96,cdp  changed ARM to DCR_ARM to avoid clash with ARM arch.
  8. 02f,22sep92,rrr  added support for c++
  9. 02e,26may92,rrr  the tree shuffle
  10. 02d,04oct91,rrr  passed through the ansification filter
  11.   -changed copyright notice
  12. 02c,05oct90,shl  added copyright notice.
  13.                  made #endif ANSI style.
  14. 02b,26jun90,hjb  upgrade to use cluster and if_subr routines;
  15.    +dab  integrated in the new distribution from Matrix.
  16. 02a,05may90,dab  cleanup of Matrix version 01g.
  17. 01a,24sep89,srm  written.
  18. */
  19. #ifndef __INCif_medh
  20. #define __INCif_medh
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. /*
  25.  * DB_ETH definitions
  26.  */
  27. /* DB-ETH local memory map. */
  28. #define  dbeth_NIC_MEM                   0x00000
  29. #define  dbeth_DBETH_CPU_BFR             0x10000
  30. #define  dbeth_ETH_ADDR_ROM              0x20000
  31. #define  dbeth_NIC_ADDR                  0x30000
  32. /* transmit and receive buffer parameters */
  33. #define  dbeth_NIC_MEM_SIZE  0x10000
  34. #define  dbeth_NIC_RECV_BFR  (dbeth_NIC_MEM+0)
  35. #define  dbeth_NIC_RECV_BFR_SIZE ((dbeth_NIC_MEM_SIZE*7)/8)
  36. #define  dbeth_NIC_RECV_BFR_END  (dbeth_NIC_RECV_BFR+dbeth_NIC_RECV_BFR_SIZE)
  37. #define  dbeth_NIC_XMIT_BFR  (dbeth_NIC_MEM+dbeth_NIC_RECV_BFR_SIZE)
  38. #define  dbeth_NIC_XMIT_BFR_SIZE (dbeth_NIC_MEM_SIZE-dbeth_NIC_RECV_BFR_SIZE)
  39. /*
  40.  * NIC definitions
  41.  */
  42. #define  nic_PAGE_SIZE               256
  43. #define  nic_CPU_TO_NIC_ADRS(Adrs)   ((u_char)((u_long)Adrs >> 8))
  44. /*
  45.  * NIC received packet header.
  46.  */
  47. typedef struct
  48.     {
  49.     u_char nextPkt;
  50.     u_char recvStatus;
  51.     u_char byteCntL;
  52.     u_char byteCntH;
  53.     struct ether_header eh;
  54.     } nic_RecvHdr_s;
  55. /*
  56.  * All NIC registers are accessable at odd byte locations.
  57.  */
  58. typedef struct
  59.     {
  60.     u_char pad;      /* pad even (most significant) byte */
  61.     u_char reg;      /* the actual NIC register          */
  62.     } NIC_REG;
  63. typedef union
  64.     {
  65.     NIC_REG reg [16];
  66.     struct
  67. {
  68. NIC_REG cr;
  69. NIC_REG pstart;
  70. NIC_REG pstop;
  71. NIC_REG bnry;
  72. NIC_REG tpsr;
  73. NIC_REG tbcr0;
  74. NIC_REG tbcr1;
  75. NIC_REG isr;
  76. NIC_REG rsar0;
  77. NIC_REG rsar1;
  78. NIC_REG rbcr0;
  79. NIC_REG rbcr1;
  80. NIC_REG rcr;
  81. NIC_REG tcr;
  82. NIC_REG dcr;
  83. NIC_REG imr;
  84. } nic_pg0;
  85.     struct
  86. {
  87. NIC_REG cr;
  88. NIC_REG clda0;
  89. NIC_REG clda1;
  90. NIC_REG bnry;
  91. NIC_REG tsr;
  92. NIC_REG ncr;
  93. NIC_REG fifo;
  94. NIC_REG isr;
  95. NIC_REG crda0;
  96. NIC_REG crda1;
  97. NIC_REG reserved0;
  98. NIC_REG reserved1;
  99. NIC_REG rsr;
  100. NIC_REG cntr0;
  101. NIC_REG cntr1;
  102. NIC_REG cntr2;
  103. } nic_pg0_read;
  104.     struct
  105. {
  106. NIC_REG cr;
  107. NIC_REG par0;
  108. NIC_REG par1;
  109. NIC_REG par2;
  110. NIC_REG par3;
  111. NIC_REG par4;
  112. NIC_REG par5;
  113. NIC_REG curr;
  114. NIC_REG mar0;
  115. NIC_REG mar1;
  116. NIC_REG mar2;
  117. NIC_REG mar3;
  118. NIC_REG mar4;
  119. NIC_REG mar5;
  120. NIC_REG mar6;
  121. NIC_REG mar7;
  122. } nic_pg1;
  123.     struct
  124. {
  125. NIC_REG cr;
  126. NIC_REG clda0;
  127. NIC_REG clda1;
  128. NIC_REG rnpp;
  129. NIC_REG res;
  130. NIC_REG lnpp;
  131. NIC_REG upper;
  132. NIC_REG lower;
  133. NIC_REG reg[4];          /* reserved */
  134. NIC_REG rcr_read;
  135. NIC_REG tcr_read;
  136. NIC_REG dcr_read;
  137. NIC_REG imr_read;
  138. } nic_pg2;
  139.     } NIC_DEVICE;
  140. #define Cr nic_pg0.cr.reg
  141. #define Pstart nic_pg0.pstart.reg
  142. #define Pstop nic_pg0.pstop.reg
  143. #define Bnry nic_pg0.bnry.reg
  144. #define Tpsr nic_pg0.tpsr.reg
  145. #define Tsr nic_pg0_read.tsr.reg
  146. #define Tbcr0 nic_pg0.tbcr0.reg
  147. #define Tbcr1 nic_pg0.tbcr1.reg
  148. #define Isr nic_pg0.isr.reg
  149. #define Rsar0 nic_pg0.rsar0.reg
  150. #define Rsar1 nic_pg0.rsar1.reg
  151. #define Rbcr0 nic_pg0.rbcr0.reg
  152. #define Rbcr1 nic_pg0.rbcr1.reg
  153. #define Rcr nic_pg0.rcr.reg
  154. #define Tcr nic_pg0.tcr.reg
  155. #define FaeErr nic_pg0_read.cntr0.reg
  156. #define Dcr nic_pg0.dcr.reg
  157. #define CrcErr nic_pg0_read.cntr1.reg
  158. #define Imr nic_pg0.imr.reg
  159. #define MspErr nic_pg0_read.cntr2.reg
  160. #define Par0 nic_pg1.par0.reg
  161. #define Par1 nic_pg1.par1.reg
  162. #define Par2 nic_pg1.par2.reg
  163. #define Par3 nic_pg1.par3.reg
  164. #define Par4 nic_pg1.par4.reg
  165. #define Par5 nic_pg1.par5.reg
  166. #define Curr nic_pg1.curr.reg
  167. #define ImrRD nic_pg2.imr_read.reg
  168. /*
  169.  * CR Register bits - Command Register
  170.  */
  171. #define STP 0x1
  172. #define STA 0x2
  173. #define TXP 0x4
  174. #define RREAD 0x8
  175. #define RWRITE 0x10
  176. #define SPKT 0x18
  177. #define ABORT 0x20
  178. #define RPAGE0 0x00
  179. #define RPAGE1 0x40
  180. #define RPAGE2 0x80
  181. #define nic_XMTR_BUSY  0x4
  182. /*
  183.  * ISR Register - Interrupt Status Register
  184.  */
  185. #define PRX 0x1
  186. #define PTX 0x2
  187. #define RXE 0x4
  188. #define TXE 0x8
  189. #define OVW 0x10
  190. #define CNT 0x20
  191. #define RDC 0x40
  192. #define RST 0x80
  193. #define  nic_STOP_MODE    RST
  194. /*
  195.  * IMR - Interrupt Mask Register - 0F (write-only)
  196.  */
  197. #define  PRXE 0x1
  198. #define  PTXE 0x2
  199. #define  RXEE 0x4
  200. #define  TXEE 0x8
  201. #define  OVWE 0x10
  202. #define  CNTE 0x20
  203. #define  RDCE 0x40
  204. #define  nic_PKT_RECV_NO_ERRORS         PRXE
  205. #define  nic_PKT_RECV_ERROR             RXEE
  206. #define  nic_PKT_XMIT_NO_ERRORS         PTXE
  207. #define  nic_PKT_XMIT_ERROR             TXEE
  208. #define  nic_RECV_BFR_OVF_WARN          OVWE
  209. #define  nic_NET_STATS_CNTR_OVF         CNTE
  210. /*
  211.  * DCR
  212.  */
  213. #define WTS 0x1        /* word-wide DMA transfers        */
  214. #define BOS 0x2        /* 680x0-style byte ordering      */
  215. #define LAS 0x4        /* remote DMA long address select */
  216. #define BMS 0x8        /* transfer FIFO threshold bytes  */
  217. #define DCR_ARM 0x10       /* autoinitialize remote DMA      */
  218. #define FT1 0x00       /* FIFO threshold, 1 word         */
  219. #define FT2   0x20
  220. #define FT4   0x40
  221. #define FT6    0x60
  222. /*
  223.  * TCR - Transmit Configuration Register - 0D ( write-only)
  224.  */
  225. #define CRC  0x1
  226. #define MODE0 0x0
  227. #define MODE1 0x2
  228. #define MODE2 0x4
  229. #define MODE3 0x6
  230. #define ATD 0x8
  231. #define OFST 0x10
  232. #define  nic_NORMAL_XMIT_CTRL     MODE0
  233. /*
  234.  * TSR
  235.  */
  236. #define TPTX 0x1
  237. #define COL 0x4
  238. #define ABT 0x8
  239. #define CRS 0x10
  240. #define FU 0x20
  241. #define CDH 0x40
  242. #define OWC 0x80
  243. /*
  244.  * RCR
  245.  */
  246. #define SEP 0x1
  247. #define AR 0x2
  248. #define AB 0x4
  249. #define AM 0x8
  250. #define PRO 0x10
  251. #define MON 0x20
  252. /*
  253.  * RSR
  254.  */
  255. #define PRX 0x1
  256. #define CRCR 0x2
  257. #define FAE 0x4
  258. #define FO 0x8
  259. #define MPA 0x10
  260. #define PHY 0x20
  261. #define DIS 0x40
  262. #define DFR 0x80
  263. #define nic_RECV_NO_ERROR  PRX
  264. #define nic_RCVR_DISABLED  DIS
  265. #define nic_RCVR_DEFERRING DFR
  266. #define  NNIC            1    /* max number of nic controllers */
  267. /*
  268.  * Overflow buffer. This buffer is used when received packets are
  269.  * "wrapped around" in the receive buffer ring by the NIC.
  270.  * Type nic_RecvHdr_s includes "struct ether_header".
  271.  */
  272. #define  OVERFLOW_BFR_SIZE (sizeof (nic_RecvHdr_s) + ETHERMTU)
  273. /* driver statistics, for debug and performance monitoring */
  274. typedef struct
  275.     {
  276.     u_long   noXmitBfrs;
  277.     u_long   intrCount;
  278.     u_long   PRX_intrCount;
  279.     u_long   PTX_intrCount;
  280.     u_long   RXE_intrCount;
  281.     u_long   TXE_intrCount;
  282.     u_long   OVW_intrCount;
  283.     u_long   CNT_intrCount;
  284.     u_long   carrierLost;    /* transmission error, not aborted           */
  285.     u_long   outOfWndColl;   /* transmission error, not aborted           */
  286.     u_long   FIFO_UdrRun;    /* fatal transmission error, aborted         */
  287.     u_long   excessColl;     /* fatal transmission error, aborted         */
  288.     u_long   frameAlign;     /* frame alignment error on packet reception */
  289.     u_long   misMatchCRC;    /* CRC error on packet reception             */
  290.     u_long   missedPkt;      /* packet missed, no receive buffers avail.  */
  291.     } med_Stats_s;
  292. /*_____________________________________________________________________
  293.  * Transmit Queue (xmitQ) definition.
  294.  *_____________________________________________________________________
  295.  *
  296.  *  Transmit Queue - showing transmit buffer control block (xmitBCB_s)
  297.  *                   structure
  298.  *
  299.  *    +-------------------------------------------------------+
  300.  *    |                                                       |
  301.  *    |   +-----------+    +-----------+  //   +-----------+  |
  302.  *    +-->|    next   |--->|    next   |--\-->|    next   |--+
  303.  *        +-----------+    +-----------+  //   +-----------+
  304.  *        |  bPktRdy  |    |  bPktRdy  |  \   |  bPktRdy  |
  305.  *        +-----------+    +-----------+  //   +-----------+
  306.  *        |   pktLen  |    |   pktLen  |  \   |   pktLen  |
  307.  *        +-----------+    +-----------+  //   +-----------+
  308.  *        |  pPktBfr  |    |  pPktBfr  |  \   |   pPktBfr |
  309.  *        +-----------+    +-----------+  //   +-----------+
  310.  *              |                |                   |
  311.  *              |                |                   |
  312.  *          +---+                |                   |
  313.  *          |    +---------------+                   |
  314.  *          |    |                                   |
  315.  *          |    |                                   |
  316.  *          |    |        NIC accessable memory      |
  317.  *          |    |   +----------------------------+  |  <----+
  318.  *          |    |   |                            |  |       |
  319.  *          +------->|      packet buffer 0       |  |       |
  320.  *               |   |                            |  |       |
  321.  *               |   +----------------------------+  |  <----+
  322.  *               |   |                            |  |       |
  323.  *               +-->|      packet buffer 1       |  |       |- NIC page
  324.  *                   |                            |  |       |  boundaries
  325.  *                   +----------------------------+  |  <----+
  326.  *                   |                            |  |       |
  327.  *                  //////////////////////
  328.  *                   |                            |  |       |
  329.  *                   +----------------------------+  |  <----+
  330.  *                   |                            |  |
  331.  *                   |      packet buffer n       |<-+
  332.  *                   |                            |
  333.  *                   +----------------------------+
  334.  *
  335.  *
  336.  *  Transmit Queue - showing buffer indexing
  337.  *
  338.  *    +-----------------------------------------------------------+
  339.  *    |                                                           |
  340.  *    |   +---+    +---+    +---+    +---+    +---+  //    +---+  |
  341.  *    |   |   |    |###|    |###|    |###|    |   |  \    |   |  |
  342.  *    +-->|   +--->|###+--->|###+--->|###+--->|   +--// -->|   |--+
  343.  *        |   |    |###|    |###|    |###|    |   |  \    |   |
  344.  *        +---+    +---+    +---+    +---+    +---+  //    +---+
  345.  *                   |                          |
  346.  *                   |                          |
  347.  *                   +-- head                   +-- tail
  348.  *
  349.  *  tail (tail buffer index)
  350.  *    Unless the xmitQ is full, Tail always indexes the next empty
  351.  *    buffer into which a packet to be transmitted may be written.
  352.  *
  353.  *  head (head buffer index)
  354.  *    Unless the xmitQ is empty, Head always indexes the next data
  355.  *    buffer (containing a packet) to be transmitted by the NIC.
  356.  *___________________________________________________________________*/
  357. /*
  358.  * A 'lock' is used as the mutual exclusion mechanism for the NIC transmitter.
  359.  */
  360. typedef unsigned long lockID_t;
  361. #define LOCKED ((lockID_t) 0)
  362. #define UNLOCKED ((lockID_t) 1)
  363. /* Transmit Buffer Control Blocks are referenced by an index.  */
  364. typedef unsigned long  XBIdx_t;       /* Transmit Buffer Index */
  365. /* Transmit Buffer Control Block (xmitBCB) */
  366. typedef struct
  367.     {
  368.     XBIdx_t      next;           /* index of the next xmitBfrContolBlock */
  369.     BOOL         bPktRdy;        /* data is available in packet buffer   */
  370.     u_short      pktLen;
  371.     u_short      dummy;          /* pad to longword */
  372.     char        *pPktBfr;
  373.     } xmitBCB_s;
  374. /*
  375.  * Calculate the maximum transmit buffer size, and round-up to the nearest
  376.  * NIC page size...
  377.  */
  378. #define  XMIT_BFR_SIZE         (((ETHERMTU + sizeof (struct ether_header)) 
  379.                                 + (nic_PAGE_SIZE - 1))                      
  380.                                 & ~(nic_PAGE_SIZE - 1))
  381. #define  NUM_XMIT_BFRS         (dbeth_NIC_XMIT_BFR_SIZE / XMIT_BFR_SIZE)
  382. /* Transmit Queue Control Block (xmitQCB). */
  383. typedef struct
  384.     {
  385.     XBIdx_t        head;
  386.     XBIdx_t        tail;
  387.     BOOL           bEmpty;
  388.     BOOL           bFull;
  389.     lockID_t       lockNIC_Xmtr;
  390.     xmitBCB_s      xmitBCB [NUM_XMIT_BFRS];
  391.     } xmitQCB_s;
  392. /*
  393.  * MED definitions
  394.  */
  395. /*
  396.  * Ethernet software status per interface.
  397.  *
  398.  * Each interface is referenced by a network interface structure,
  399.  * es_if, which the routing code uses to locate the interface.
  400.  * This structure contains the output queue for the interface, its address, ...
  401.  */
  402. struct med_softc
  403.     {
  404.     struct arpcom  es_ac;         /* common ethernet structures               */
  405.     NIC_DEVICE    *nicAddr;       /* address of nic Chip                      */
  406.     int            nicIntLevel;   /* interrupt level                          */
  407.     int            nicIntVec;     /* interrupt vector                         */
  408. #ifdef BSD43_DRIVER
  409.     BOOL           bPromisc;      /* if TRUE, NIC retrieves all packets       */
  410. #endif
  411.     nic_RecvHdr_s *pOvfRecvBfr;   /* buffer for wrapped receive packets       */
  412.     BOOL           bxmitBfrBusy;  /* for initial version, single xmit buffer  */
  413.     BOOL           bRecvBfrOvfl;  /* when TRUE, receive packets not processed */
  414.     BOOL           bFirstInit;    /* TRUE when NIC/driver first initialized   */
  415.     xmitQCB_s      xmitQCB;       /* transmit queue control block             */
  416.     u_char         pktNextToRead; /* next received packet to read             */
  417.     u_char         currentIMR;    /* NIC IMR shadow register                  */
  418.     };
  419. #define es_if es_ac.ac_if     /* network-visible interface */
  420. #define es_enaddr       es_ac.ac_enaddr /* hardware ethernet address */
  421. #ifdef __cplusplus
  422. }
  423. #endif
  424. #endif /* __INCif_medh */