gt96100eth.h
上传用户:lgb322
上传日期:2013-02-24
资源大小:30529k
文件大小:7k
源码类别:

嵌入式Linux

开发平台:

Unix_Linux

  1. /*
  2.  * Copyright 2000 MontaVista Software Inc.
  3.  * Author: MontaVista Software, Inc.
  4.  *          stevel@mvista.com or source@mvista.com
  5.  *
  6.  * ########################################################################
  7.  *
  8.  *  This program is free software; you can distribute it and/or modify it
  9.  *  under the terms of the GNU General Public License (Version 2) as
  10.  *  published by the Free Software Foundation.
  11.  *
  12.  *  This program is distributed in the hope it will be useful, but WITHOUT
  13.  *  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14.  *  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  15.  *  for more details.
  16.  *
  17.  *  You should have received a copy of the GNU General Public License along
  18.  *  with this program; if not, write to the Free Software Foundation, Inc.,
  19.  *  59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
  20.  *
  21.  * ########################################################################
  22.  *
  23.  * Ethernet driver definitions for the MIPS GT96100 Advanced
  24.  * Communication Controller.
  25.  * 
  26.  */
  27. #ifndef _GT96100ETH_H
  28. #define _GT96100ETH_H
  29. #include <asm/galileo-boards/gt96100.h>
  30. /* Keep the ring sizes a power of two for efficiency. */
  31. #define TX_RING_SIZE 16
  32. #define RX_RING_SIZE 32
  33. #define PKT_BUF_SZ 1536 /* Size of each temporary Rx buffer. */
  34. #define RX_HASH_TABLE_SIZE 16384
  35. #define HASH_HOP_NUMBER 12
  36. #define NUM_INTERFACES 2
  37. #define GT96100ETH_TX_TIMEOUT HZ
  38. #define GT96100_ETH0_BASE (MIPS_GT96100_BASE + GT96100_ETH_PORT_CONFIG)
  39. #define GT96100_ETH1_BASE (GT96100_ETH0_BASE + GT96100_ETH_IO_SIZE)
  40. #ifdef CONFIG_MIPS_EV96100
  41. #define GT96100_ETHER0_IRQ 4
  42. #define GT96100_ETHER1_IRQ 4
  43. #else
  44. #define GT96100_ETHER0_IRQ -1
  45. #define GT96100_ETHER1_IRQ -1
  46. #endif
  47. #define GT96100ETH_READ(gp, offset) 
  48.     GT96100_READ((gp->port_offset + offset))
  49. #define GT96100ETH_WRITE(gp, offset, data) 
  50.     GT96100_WRITE((gp->port_offset + offset), data)
  51. #define GT96100ETH_SETBIT(gp, offset, bits) {
  52.     u32 val = GT96100ETH_READ(gp, offset); val |= (u32)(bits); 
  53.     GT96100ETH_WRITE(gp, offset, val); }
  54. #define GT96100ETH_CLRBIT(gp, offset, bits) {
  55.     u32 val = GT96100ETH_READ(gp, offset); val &= (u32)(~(bits)); 
  56.     GT96100ETH_WRITE(gp, offset, val); }
  57. /* Bit definitions of the SMI Reg */
  58. enum {
  59. smirDataMask = 0xffff,
  60. smirPhyAdMask = 0x1f << 16,
  61. smirPhyAdBit = 16,
  62. smirRegAdMask = 0x1f << 21,
  63. smirRegAdBit = 21,
  64. smirOpCode = 1 << 26,
  65. smirReadValid = 1 << 27,
  66. smirBusy = 1 << 28
  67. };
  68. /* Bit definitions of the Port Config Reg */
  69. enum pcr_bits {
  70. pcrPM = 1,
  71. pcrRBM = 2,
  72. pcrPBF = 4,
  73. pcrEN = 1 << 7,
  74. pcrLPBKMask = 0x3 << 8,
  75. pcrLPBKBit = 8,
  76. pcrFC = 1 << 10,
  77. pcrHS = 1 << 12,
  78. pcrHM = 1 << 13,
  79. pcrHDM = 1 << 14,
  80. pcrHD = 1 << 15,
  81. pcrISLMask = 0x7 << 28,
  82. pcrISLBit = 28,
  83. pcrACCS = 1 << 31
  84. };
  85. /* Bit definitions of the Port Config Extend Reg */
  86. enum pcxr_bits {
  87. pcxrIGMP = 1,
  88. pcxrSPAN = 2,
  89. pcxrPAR = 4,
  90. pcxrPRIOtxMask = 0x7 << 3,
  91. pcxrPRIOtxBit = 3,
  92. pcxrPRIOrxMask = 0x3 << 6,
  93. pcxrPRIOrxBit = 6,
  94. pcxrPRIOrxOverride = 1 << 8,
  95. pcxrDPLXen = 1 << 9,
  96. pcxrFCTLen = 1 << 10,
  97. pcxrFLP = 1 << 11,
  98. pcxrFCTL = 1 << 12,
  99. pcxrMFLMask = 0x3 << 14,
  100. pcxrMFLBit = 14,
  101. pcxrMIBclrMode = 1 << 16,
  102. pcxrSpeed = 1 << 18,
  103. pcxrSpeeden = 1 << 19,
  104. pcxrRMIIen = 1 << 20,
  105. pcxrDSCPen = 1 << 21
  106. };
  107. /* Bit definitions of the Port Command Reg */
  108. enum pcmr_bits {
  109. pcmrFJ = 1 << 15
  110. };
  111. /* Bit definitions of the Port Status Reg */
  112. enum psr_bits {
  113. psrSpeed = 1,
  114. psrDuplex = 2,
  115. psrFctl = 4,
  116. psrLink = 8,
  117. psrPause = 1 << 4,
  118. psrTxLow = 1 << 5,
  119. psrTxHigh = 1 << 6,
  120. psrTxInProg = 1 << 7
  121. };
  122. /* Bit definitions of the SDMA Config Reg */
  123. enum sdcr_bits {
  124. sdcrRCMask = 0xf << 2,
  125. sdcrRCBit = 2,
  126. sdcrBLMR = 1 << 6,
  127. sdcrBLMT = 1 << 7,
  128. sdcrPOVR = 1 << 8,
  129. sdcrRIFB = 1 << 9,
  130. sdcrBSZMask = 0x3 << 12,
  131. sdcrBSZBit = 12
  132. };
  133. /* Bit definitions of the SDMA Command Reg */
  134. enum sdcmr_bits {
  135. sdcmrERD = 1 << 7,
  136. sdcmrAR = 1 << 15,
  137. sdcmrSTDH = 1 << 16,
  138. sdcmrSTDL = 1 << 17,
  139. sdcmrTXDH = 1 << 23,
  140. sdcmrTXDL = 1 << 24,
  141. sdcmrAT = 1 << 31
  142. };
  143. /* Bit definitions of the Interrupt Cause Reg */
  144. enum icr_bits {
  145. icrRxBuffer = 1,
  146. icrTxBufferHigh = 1 << 2,
  147. icrTxBufferLow = 1 << 3,
  148. icrTxEndHigh = 1 << 6,
  149. icrTxEndLow = 1 << 7,
  150. icrRxError = 1 << 8,
  151. icrTxErrorHigh = 1 << 10,
  152. icrTxErrorLow = 1 << 11,
  153. icrRxOVR = 1 << 12,
  154. icrTxUdr = 1 << 13,
  155. icrRxBufferQ0 = 1 << 16,
  156. icrRxBufferQ1 = 1 << 17,
  157. icrRxBufferQ2 = 1 << 18,
  158. icrRxBufferQ3 = 1 << 19,
  159. icrRxErrorQ0 = 1 << 20,
  160. icrRxErrorQ1 = 1 << 21,
  161. icrRxErrorQ2 = 1 << 22,
  162. icrRxErrorQ3 = 1 << 23,
  163. icrMIIPhySTC = 1 << 28,
  164. icrSMIdone = 1 << 29,
  165. icrEtherIntSum = 1 << 31
  166. };
  167. /* The Rx and Tx descriptor lists. */
  168. typedef struct {
  169. u32 cmdstat;
  170. u32 byte_cnt;
  171. u32 buff_ptr;
  172. u32 next;
  173. } gt96100_td_t;
  174. #define tdByteCntBit 16
  175. typedef struct {
  176. u32 cmdstat;
  177. u32 buff_cnt_sz;
  178. u32 buff_ptr;
  179. u32 next;
  180. } gt96100_rd_t;
  181. #define rdBuffSzBit 16
  182. #define rdByteCntMask 0xffff
  183. /* Values for the Tx command-status descriptor entry. */
  184. enum td_cmdstat {
  185. txOwn = 1 << 31,
  186. txAutoMode = 1 << 30,
  187. txEI = 1 << 23,
  188. txGenCRC = 1 << 22,
  189. txPad = 1 << 18,
  190. txFirst = 1 << 17,
  191. txLast = 1 << 16,
  192. txErrorSummary = 1 << 15,
  193. txReTxCntMask = 0x0f << 10,
  194. txReTxCntBit = 10,
  195. txCollision = 1 << 9,
  196. txReTxLimit = 1 << 8,
  197. txUnderrun = 1 << 6,
  198. txLateCollision = 1 << 5
  199. };
  200. #define TxReTxCntBit 10
  201. /* Values for the Rx command-status descriptor entry. */
  202. enum rd_cmdstat {
  203. rxOwn = 1 << 31,
  204. rxAutoMode = 1 << 30,
  205. rxEI = 1 << 23,
  206. rxFirst = 1 << 17,
  207. rxLast = 1 << 16,
  208. rxErrorSummary = 1 << 15,
  209. rxIGMP = 1 << 14,
  210. rxHashExpired = 1 << 13,
  211. rxMissedFrame = 1 << 12,
  212. rxFrameType = 1 << 11,
  213. rxShortFrame = 1 << 8,
  214. rxMaxFrameLen = 1 << 7,
  215. rxOverrun = 1 << 6,
  216. rxCollision = 1 << 4,
  217. rxCRCError = 1
  218. };
  219. /* Bit fields of a Hash Table Entry */
  220. enum hash_table_entry {
  221. hteValid = 1,
  222. hteSkip = 2,
  223. hteRD = 4
  224. };
  225. // The MIB counters
  226. typedef struct {
  227. u32 byteReceived;
  228. u32 byteSent;
  229. u32 framesReceived;
  230. u32 framesSent;
  231. u32 totalByteReceived;
  232. u32 totalFramesReceived;
  233. u32 broadcastFramesReceived;
  234. u32 multicastFramesReceived;
  235. u32 cRCError;
  236. u32 oversizeFrames;
  237. u32 fragments;
  238. u32 jabber;
  239. u32 collision;
  240. u32 lateCollision;
  241. u32 frames64;
  242. u32 frames65_127;
  243. u32 frames128_255;
  244. u32 frames256_511;
  245. u32 frames512_1023;
  246. u32 frames1024_MaxSize;
  247. u32 macRxError;
  248. u32 droppedFrames;
  249. u32 outMulticastFrames;
  250. u32 outBroadcastFrames;
  251. u32 undersizeFrames;
  252. } mib_counters_t;
  253. struct gt96100_private {
  254. gt96100_rd_t *rx_ring;
  255. gt96100_td_t *tx_ring;
  256. // The Rx and Tx rings must be 16-byte aligned
  257. dma_addr_t rx_ring_dma;
  258. dma_addr_t tx_ring_dma;
  259. char *hash_table;
  260. // The Hash Table must be 8-byte aligned
  261. dma_addr_t hash_table_dma;
  262. int hash_mode;
  263. // The Rx buffers must be 8-byte aligned
  264. char *rx_buff[RX_RING_SIZE];
  265. // Tx buffers (tx_skbuff[i]->data) with less than 8 bytes
  266. // of payload must be 8-byte aligned
  267. struct sk_buff *tx_skbuff[TX_RING_SIZE];
  268. int rx_next_out; /* The next free ring entry to receive */
  269. int tx_next_in; /* The next free ring entry to send */
  270. int tx_next_out; /* The last ring entry the ISR processed */
  271. int tx_count; /* current # of pkts waiting to be sent in Tx ring */
  272. mib_counters_t mib;
  273. struct net_device_stats stats;
  274. int io_size;
  275. int port_num; // 0 or 1
  276. u32 port_offset;
  277. int phy_addr; // PHY address
  278. u32 last_psr; // last value of the port status register
  279. int options; /* User-settable misc. driver options. */
  280. int drv_flags;
  281. unsigned char phys[2]; /* MII device addresses. */
  282. spinlock_t lock; /* Serialise access to device */
  283. };
  284. #endif