gt96100eth.h 7.8 KB

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