gt96100eth.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  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. #define dbg(lvl, format, arg...) \
  31. if (lvl <= GT96100_DEBUG) \
  32. printk(KERN_DEBUG "%s: " format, dev->name , ## arg)
  33. #define err(format, arg...) \
  34. printk(KERN_ERR "%s: " format, dev->name , ## arg)
  35. #define info(format, arg...) \
  36. printk(KERN_INFO "%s: " format, dev->name , ## arg)
  37. #define warn(format, arg...) \
  38. printk(KERN_WARNING "%s: " format, dev->name , ## arg)
  39. /* Keep the ring sizes a power of two for efficiency. */
  40. #define TX_RING_SIZE 16
  41. #define RX_RING_SIZE 32
  42. #define PKT_BUF_SZ 1536 /* Size of each temporary Rx buffer.*/
  43. #define RX_HASH_TABLE_SIZE 16384
  44. #define HASH_HOP_NUMBER 12
  45. #define NUM_INTERFACES 2
  46. #define GT96100ETH_TX_TIMEOUT HZ/4
  47. #define GT96100_ETH0_BASE (MIPS_GT96100_BASE + GT96100_ETH_PORT_CONFIG)
  48. #define GT96100_ETH1_BASE (GT96100_ETH0_BASE + GT96100_ETH_IO_SIZE)
  49. #ifdef CONFIG_MIPS_EV96100
  50. #define GT96100_ETHER0_IRQ 3
  51. #define GT96100_ETHER1_IRQ 4
  52. #else
  53. #define GT96100_ETHER0_IRQ -1
  54. #define GT96100_ETHER1_IRQ -1
  55. #endif
  56. #define REV_GT96100 1
  57. #define REV_GT96100A_1 2
  58. #define REV_GT96100A 3
  59. #define GT96100ETH_READ(gp, offset) \
  60. GT96100_READ((gp->port_offset + offset))
  61. #define GT96100ETH_WRITE(gp, offset, data) \
  62. GT96100_WRITE((gp->port_offset + offset), data)
  63. #define GT96100ETH_SETBIT(gp, offset, bits) {\
  64. u32 val = GT96100ETH_READ(gp, offset); val |= (u32)(bits); \
  65. GT96100ETH_WRITE(gp, offset, val); }
  66. #define GT96100ETH_CLRBIT(gp, offset, bits) {\
  67. u32 val = GT96100ETH_READ(gp, offset); val &= (u32)(~(bits)); \
  68. GT96100ETH_WRITE(gp, offset, val); }
  69. /* Bit definitions of the SMI Reg */
  70. enum {
  71. smirDataMask = 0xffff,
  72. smirPhyAdMask = 0x1f<<16,
  73. smirPhyAdBit = 16,
  74. smirRegAdMask = 0x1f<<21,
  75. smirRegAdBit = 21,
  76. smirOpCode = 1<<26,
  77. smirReadValid = 1<<27,
  78. smirBusy = 1<<28
  79. };
  80. /* Bit definitions of the Port Config Reg */
  81. enum pcr_bits {
  82. pcrPM = 1,
  83. pcrRBM = 2,
  84. pcrPBF = 4,
  85. pcrEN = 1<<7,
  86. pcrLPBKMask = 0x3<<8,
  87. pcrLPBKBit = 8,
  88. pcrFC = 1<<10,
  89. pcrHS = 1<<12,
  90. pcrHM = 1<<13,
  91. pcrHDM = 1<<14,
  92. pcrHD = 1<<15,
  93. pcrISLMask = 0x7<<28,
  94. pcrISLBit = 28,
  95. pcrACCS = 1<<31
  96. };
  97. /* Bit definitions of the Port Config Extend Reg */
  98. enum pcxr_bits {
  99. pcxrIGMP = 1,
  100. pcxrSPAN = 2,
  101. pcxrPAR = 4,
  102. pcxrPRIOtxMask = 0x7<<3,
  103. pcxrPRIOtxBit = 3,
  104. pcxrPRIOrxMask = 0x3<<6,
  105. pcxrPRIOrxBit = 6,
  106. pcxrPRIOrxOverride = 1<<8,
  107. pcxrDPLXen = 1<<9,
  108. pcxrFCTLen = 1<<10,
  109. pcxrFLP = 1<<11,
  110. pcxrFCTL = 1<<12,
  111. pcxrMFLMask = 0x3<<14,
  112. pcxrMFLBit = 14,
  113. pcxrMIBclrMode = 1<<16,
  114. pcxrSpeed = 1<<18,
  115. pcxrSpeeden = 1<<19,
  116. pcxrRMIIen = 1<<20,
  117. pcxrDSCPen = 1<<21
  118. };
  119. /* Bit definitions of the Port Command Reg */
  120. enum pcmr_bits {
  121. pcmrFJ = 1<<15
  122. };
  123. /* Bit definitions of the Port Status Reg */
  124. enum psr_bits {
  125. psrSpeed = 1,
  126. psrDuplex = 2,
  127. psrFctl = 4,
  128. psrLink = 8,
  129. psrPause = 1<<4,
  130. psrTxLow = 1<<5,
  131. psrTxHigh = 1<<6,
  132. psrTxInProg = 1<<7
  133. };
  134. /* Bit definitions of the SDMA Config Reg */
  135. enum sdcr_bits {
  136. sdcrRCMask = 0xf<<2,
  137. sdcrRCBit = 2,
  138. sdcrBLMR = 1<<6,
  139. sdcrBLMT = 1<<7,
  140. sdcrPOVR = 1<<8,
  141. sdcrRIFB = 1<<9,
  142. sdcrBSZMask = 0x3<<12,
  143. sdcrBSZBit = 12
  144. };
  145. /* Bit definitions of the SDMA Command Reg */
  146. enum sdcmr_bits {
  147. sdcmrERD = 1<<7,
  148. sdcmrAR = 1<<15,
  149. sdcmrSTDH = 1<<16,
  150. sdcmrSTDL = 1<<17,
  151. sdcmrTXDH = 1<<23,
  152. sdcmrTXDL = 1<<24,
  153. sdcmrAT = 1<<31
  154. };
  155. /* Bit definitions of the Interrupt Cause Reg */
  156. enum icr_bits {
  157. icrRxBuffer = 1,
  158. icrTxBufferHigh = 1<<2,
  159. icrTxBufferLow = 1<<3,
  160. icrTxEndHigh = 1<<6,
  161. icrTxEndLow = 1<<7,
  162. icrRxError = 1<<8,
  163. icrTxErrorHigh = 1<<10,
  164. icrTxErrorLow = 1<<11,
  165. icrRxOVR = 1<<12,
  166. icrTxUdr = 1<<13,
  167. icrRxBufferQ0 = 1<<16,
  168. icrRxBufferQ1 = 1<<17,
  169. icrRxBufferQ2 = 1<<18,
  170. icrRxBufferQ3 = 1<<19,
  171. icrRxErrorQ0 = 1<<20,
  172. icrRxErrorQ1 = 1<<21,
  173. icrRxErrorQ2 = 1<<22,
  174. icrRxErrorQ3 = 1<<23,
  175. icrMIIPhySTC = 1<<28,
  176. icrSMIdone = 1<<29,
  177. icrEtherIntSum = 1<<31
  178. };
  179. /* The Rx and Tx descriptor lists. */
  180. typedef struct {
  181. #ifdef DESC_BE
  182. u16 byte_cnt;
  183. u16 reserved;
  184. #else
  185. u16 reserved;
  186. u16 byte_cnt;
  187. #endif
  188. u32 cmdstat;
  189. u32 next;
  190. u32 buff_ptr;
  191. } __attribute__ ((packed)) gt96100_td_t;
  192. typedef struct {
  193. #ifdef DESC_BE
  194. u16 buff_sz;
  195. u16 byte_cnt;
  196. #else
  197. u16 byte_cnt;
  198. u16 buff_sz;
  199. #endif
  200. u32 cmdstat;
  201. u32 next;
  202. u32 buff_ptr;
  203. } __attribute__ ((packed)) gt96100_rd_t;
  204. /* Values for the Tx command-status descriptor entry. */
  205. enum td_cmdstat {
  206. txOwn = 1<<31,
  207. txAutoMode = 1<<30,
  208. txEI = 1<<23,
  209. txGenCRC = 1<<22,
  210. txPad = 1<<18,
  211. txFirst = 1<<17,
  212. txLast = 1<<16,
  213. txErrorSummary = 1<<15,
  214. txReTxCntMask = 0x0f<<10,
  215. txReTxCntBit = 10,
  216. txCollision = 1<<9,
  217. txReTxLimit = 1<<8,
  218. txUnderrun = 1<<6,
  219. txLateCollision = 1<<5
  220. };
  221. /* Values for the Rx command-status descriptor entry. */
  222. enum rd_cmdstat {
  223. rxOwn = 1<<31,
  224. rxAutoMode = 1<<30,
  225. rxEI = 1<<23,
  226. rxFirst = 1<<17,
  227. rxLast = 1<<16,
  228. rxErrorSummary = 1<<15,
  229. rxIGMP = 1<<14,
  230. rxHashExpired = 1<<13,
  231. rxMissedFrame = 1<<12,
  232. rxFrameType = 1<<11,
  233. rxShortFrame = 1<<8,
  234. rxMaxFrameLen = 1<<7,
  235. rxOverrun = 1<<6,
  236. rxCollision = 1<<4,
  237. rxCRCError = 1
  238. };
  239. /* Bit fields of a Hash Table Entry */
  240. enum hash_table_entry {
  241. hteValid = 1,
  242. hteSkip = 2,
  243. hteRD = 4
  244. };
  245. // The MIB counters
  246. typedef struct {
  247. u32 byteReceived;
  248. u32 byteSent;
  249. u32 framesReceived;
  250. u32 framesSent;
  251. u32 totalByteReceived;
  252. u32 totalFramesReceived;
  253. u32 broadcastFramesReceived;
  254. u32 multicastFramesReceived;
  255. u32 cRCError;
  256. u32 oversizeFrames;
  257. u32 fragments;
  258. u32 jabber;
  259. u32 collision;
  260. u32 lateCollision;
  261. u32 frames64;
  262. u32 frames65_127;
  263. u32 frames128_255;
  264. u32 frames256_511;
  265. u32 frames512_1023;
  266. u32 frames1024_MaxSize;
  267. u32 macRxError;
  268. u32 droppedFrames;
  269. u32 outMulticastFrames;
  270. u32 outBroadcastFrames;
  271. u32 undersizeFrames;
  272. } mib_counters_t;
  273. struct gt96100_private {
  274. gt96100_rd_t* rx_ring;
  275. gt96100_td_t* tx_ring;
  276. // The Rx and Tx rings must be 16-byte aligned
  277. dma_addr_t rx_ring_dma;
  278. dma_addr_t tx_ring_dma;
  279. char* hash_table;
  280. // The Hash Table must be 8-byte aligned
  281. dma_addr_t hash_table_dma;
  282. int hash_mode;
  283. // The Rx buffers must be 8-byte aligned
  284. char* rx_buff;
  285. dma_addr_t rx_buff_dma;
  286. // Tx buffers (tx_skbuff[i]->data) with less than 8 bytes
  287. // of payload must be 8-byte aligned
  288. struct sk_buff* tx_skbuff[TX_RING_SIZE];
  289. int rx_next_out; /* The next free ring entry to receive */
  290. int tx_next_in; /* The next free ring entry to send */
  291. int tx_next_out; /* The last ring entry the ISR processed */
  292. int tx_count; /* current # of pkts waiting to be sent in Tx ring */
  293. int intr_work_done; /* number of Rx and Tx pkts processed in the isr */
  294. int tx_full; /* Tx ring is full */
  295. mib_counters_t mib;
  296. struct net_device_stats stats;
  297. int port_num; // 0 or 1
  298. int chip_rev;
  299. u32 port_offset;
  300. int phy_addr; // PHY address
  301. u32 last_psr; // last value of the port status register
  302. int options; /* User-settable misc. driver options. */
  303. struct timer_list timer;
  304. spinlock_t lock; /* Serialise access to device */
  305. };
  306. #endif