gt64240eth.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (C) 2001 Patton Electronics Company
  7. * Copyright (C) 2002 Momentum Computer
  8. *
  9. * Copyright 2000 MontaVista Software Inc.
  10. * Author: MontaVista Software, Inc.
  11. * stevel@mvista.com or support@mvista.com
  12. *
  13. * This program is free software; you can distribute it and/or modify it
  14. * under the terms of the GNU General Public License (Version 2) as
  15. * published by the Free Software Foundation.
  16. *
  17. * This program is distributed in the hope it will be useful, but WITHOUT
  18. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  19. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  20. * for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License along
  23. * with this program; if not, write to the Free Software Foundation, Inc.,
  24. * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
  25. *
  26. * Ethernet driver definitions for the MIPS GT96100 Advanced
  27. * Communication Controller.
  28. *
  29. * Modified for the Marvellous GT64240 Retarded Communication Controller.
  30. */
  31. #ifndef _GT64240ETH_H
  32. #define _GT64240ETH_H
  33. #include <asm/gt64240.h>
  34. #define ETHERNET_PORTS_DIFFERENCE_OFFSETS 0x400
  35. /* Translate those weanie names from Galileo/VxWorks header files: */
  36. #define GT64240_MRR MAIN_ROUTING_REGISTER
  37. #define GT64240_CIU_ARBITER_CONFIG COMM_UNIT_ARBITER_CONFIGURATION_REGISTER
  38. #define GT64240_CIU_ARBITER_CONTROL COMM_UNIT_ARBITER_CONTROL
  39. #define GT64240_MAIN_LOW_CAUSE LOW_INTERRUPT_CAUSE_REGISTER
  40. #define GT64240_MAIN_HIGH_CAUSE HIGH_INTERRUPT_CAUSE_REGISTER
  41. #define GT64240_CPU_LOW_MASK CPU_INTERRUPT_MASK_REGISTER_LOW
  42. #define GT64240_CPU_HIGH_MASK CPU_INTERRUPT_MASK_REGISTER_HIGH
  43. #define GT64240_CPU_SELECT_CAUSE CPU_SELECT_CAUSE_REGISTER
  44. #define GT64240_ETH_PHY_ADDR_REG ETHERNET_PHY_ADDRESS_REGISTER
  45. #define GT64240_ETH_PORT_CONFIG ETHERNET0_PORT_CONFIGURATION_REGISTER
  46. #define GT64240_ETH_PORT_CONFIG_EXT ETHERNET0_PORT_CONFIGURATION_EXTEND_REGISTER
  47. #define GT64240_ETH_PORT_COMMAND ETHERNET0_PORT_COMMAND_REGISTER
  48. #define GT64240_ETH_PORT_STATUS ETHERNET0_PORT_STATUS_REGISTER
  49. #define GT64240_ETH_IO_SIZE ETHERNET_PORTS_DIFFERENCE_OFFSETS
  50. #define GT64240_ETH_SMI_REG ETHERNET_SMI_REGISTER
  51. #define GT64240_ETH_MIB_COUNT_BASE ETHERNET0_MIB_COUNTER_BASE
  52. #define GT64240_ETH_SDMA_CONFIG ETHERNET0_SDMA_CONFIGURATION_REGISTER
  53. #define GT64240_ETH_SDMA_COMM ETHERNET0_SDMA_COMMAND_REGISTER
  54. #define GT64240_ETH_INT_MASK ETHERNET0_INTERRUPT_MASK_REGISTER
  55. #define GT64240_ETH_INT_CAUSE ETHERNET0_INTERRUPT_CAUSE_REGISTER
  56. #define GT64240_ETH_CURR_TX_DESC_PTR0 ETHERNET0_CURRENT_TX_DESCRIPTOR_POINTER0
  57. #define GT64240_ETH_CURR_TX_DESC_PTR1 ETHERNET0_CURRENT_TX_DESCRIPTOR_POINTER1
  58. #define GT64240_ETH_1ST_RX_DESC_PTR0 ETHERNET0_FIRST_RX_DESCRIPTOR_POINTER0
  59. #define GT64240_ETH_CURR_RX_DESC_PTR0 ETHERNET0_CURRENT_RX_DESCRIPTOR_POINTER0
  60. #define GT64240_ETH_HASH_TBL_PTR ETHERNET0_HASH_TABLE_POINTER_REGISTER
  61. /* Turn on NAPI by default */
  62. #define GT64240_NAPI 1
  63. /* Some 64240 settings that SHOULD eventually be setup in PROM monitor: */
  64. /* (Board-specific to the DSL3224 Rev A board ONLY!) */
  65. #define D3224_MPP_CTRL0_SETTING 0x66669900
  66. #define D3224_MPP_CTRL1_SETTING 0x00000000
  67. #define D3224_MPP_CTRL2_SETTING 0x00887700
  68. #define D3224_MPP_CTRL3_SETTING 0x00000044
  69. #define D3224_GPP_IO_CTRL_SETTING 0x0000e800
  70. #define D3224_GPP_LEVEL_CTRL_SETTING 0xf001f703
  71. #define D3224_GPP_VALUE_SETTING 0x00000000
  72. /* Keep the ring sizes a power of two for efficiency. */
  73. //-#define TX_RING_SIZE 16
  74. #define TX_RING_SIZE 64 /* TESTING !!! */
  75. #define RX_RING_SIZE 32
  76. #define PKT_BUF_SZ 1536 /* Size of each temporary Rx buffer. */
  77. #define RX_HASH_TABLE_SIZE 16384
  78. #define HASH_HOP_NUMBER 12
  79. #define NUM_INTERFACES 3
  80. #define GT64240ETH_TX_TIMEOUT HZ/4
  81. #define MIPS_GT64240_BASE 0xf4000000
  82. #define GT64240_ETH0_BASE (MIPS_GT64240_BASE + GT64240_ETH_PORT_CONFIG)
  83. #define GT64240_ETH1_BASE (GT64240_ETH0_BASE + GT64240_ETH_IO_SIZE)
  84. #define GT64240_ETH2_BASE (GT64240_ETH1_BASE + GT64240_ETH_IO_SIZE)
  85. #if defined(CONFIG_MIPS_DSL3224)
  86. #define GT64240_ETHER0_IRQ 4
  87. #define GT64240_ETHER1_IRQ 4
  88. #else
  89. #define GT64240_ETHER0_IRQ -1
  90. #define GT64240_ETHER1_IRQ -1
  91. #endif
  92. #define REV_GT64240 0x1
  93. #define REV_GT64240A 0x10
  94. #define GT64240ETH_READ(gp, offset) \
  95. GT_READ((gp)->port_offset + (offset))
  96. #define GT64240ETH_WRITE(gp, offset, data) \
  97. GT_WRITE((gp)->port_offset + (offset), (data))
  98. #define GT64240ETH_SETBIT(gp, offset, bits) \
  99. GT64240ETH_WRITE((gp), (offset), \
  100. GT64240ETH_READ((gp), (offset)) | (bits))
  101. #define GT64240ETH_CLRBIT(gp, offset, bits) \
  102. GT64240ETH_WRITE((gp), (offset), \
  103. GT64240ETH_READ((gp), (offset)) & ~(bits))
  104. #define GT64240_READ(ofs) GT_READ(ofs)
  105. #define GT64240_WRITE(ofs, data) GT_WRITE((ofs), (data))
  106. /* Bit definitions of the SMI Reg */
  107. enum {
  108. smirDataMask = 0xffff,
  109. smirPhyAdMask = 0x1f << 16,
  110. smirPhyAdBit = 16,
  111. smirRegAdMask = 0x1f << 21,
  112. smirRegAdBit = 21,
  113. smirOpCode = 1 << 26,
  114. smirReadValid = 1 << 27,
  115. smirBusy = 1 << 28
  116. };
  117. /* Bit definitions of the Port Config Reg */
  118. enum pcr_bits {
  119. pcrPM = 1 << 0,
  120. pcrRBM = 1 << 1,
  121. pcrPBF = 1 << 2,
  122. pcrEN = 1 << 7,
  123. pcrLPBKMask = 0x3 << 8,
  124. pcrLPBKBit = 1 << 8,
  125. pcrFC = 1 << 10,
  126. pcrHS = 1 << 12,
  127. pcrHM = 1 << 13,
  128. pcrHDM = 1 << 14,
  129. pcrHD = 1 << 15,
  130. pcrISLMask = 0x7 << 28,
  131. pcrISLBit = 28,
  132. pcrACCS = 1 << 31
  133. };
  134. /* Bit definitions of the Port Config Extend Reg */
  135. enum pcxr_bits {
  136. pcxrIGMP = 1,
  137. pcxrSPAN = 2,
  138. pcxrPAR = 4,
  139. pcxrPRIOtxMask = 0x7 << 3,
  140. pcxrPRIOtxBit = 3,
  141. pcxrPRIOrxMask = 0x3 << 6,
  142. pcxrPRIOrxBit = 6,
  143. pcxrPRIOrxOverride = 1 << 8,
  144. pcxrDPLXen = 1 << 9,
  145. pcxrFCTLen = 1 << 10,
  146. pcxrFLP = 1 << 11,
  147. pcxrFCTL = 1 << 12,
  148. pcxrMFLMask = 0x3 << 14,
  149. pcxrMFLBit = 14,
  150. pcxrMIBclrMode = 1 << 16,
  151. pcxrSpeed = 1 << 18,
  152. pcxrSpeeden = 1 << 19,
  153. pcxrRMIIen = 1 << 20,
  154. pcxrDSCPen = 1 << 21
  155. };
  156. /* Bit definitions of the Port Command Reg */
  157. enum pcmr_bits {
  158. pcmrFJ = 1 << 15
  159. };
  160. /* Bit definitions of the Port Status Reg */
  161. enum psr_bits {
  162. psrSpeed = 1,
  163. psrDuplex = 2,
  164. psrFctl = 4,
  165. psrLink = 8,
  166. psrPause = 1 << 4,
  167. psrTxLow = 1 << 5,
  168. psrTxHigh = 1 << 6,
  169. psrTxInProg = 1 << 7
  170. };
  171. /* Bit definitions of the SDMA Config Reg */
  172. enum sdcr_bits {
  173. sdcrRCMask = 0xf << 2,
  174. sdcrRCBit = 2,
  175. sdcrBLMR = 1 << 6,
  176. sdcrBLMT = 1 << 7,
  177. sdcrPOVR = 1 << 8,
  178. sdcrRIFB = 1 << 9,
  179. sdcrBSZMask = 0x3 << 12,
  180. sdcrBSZBit = 12
  181. };
  182. /* Bit definitions of the SDMA Command Reg */
  183. enum sdcmr_bits {
  184. sdcmrERD = 1 << 7,
  185. sdcmrAR = 1 << 15,
  186. sdcmrSTDH = 1 << 16,
  187. sdcmrSTDL = 1 << 17,
  188. sdcmrTXDH = 1 << 23,
  189. sdcmrTXDL = 1 << 24,
  190. sdcmrAT = 1 << 31
  191. };
  192. /* Bit definitions of the Interrupt Cause Reg */
  193. enum icr_bits {
  194. icrRxBuffer = 1,
  195. icrTxBufferHigh = 1 << 2,
  196. icrTxBufferLow = 1 << 3,
  197. icrTxEndHigh = 1 << 6,
  198. icrTxEndLow = 1 << 7,
  199. icrRxError = 1 << 8,
  200. icrTxErrorHigh = 1 << 10,
  201. icrTxErrorLow = 1 << 11,
  202. icrRxOVR = 1 << 12,
  203. icrTxUdr = 1 << 13,
  204. icrRxBufferQ0 = 1 << 16,
  205. icrRxBufferQ1 = 1 << 17,
  206. icrRxBufferQ2 = 1 << 18,
  207. icrRxBufferQ3 = 1 << 19,
  208. icrRxErrorQ0 = 1 << 20,
  209. icrRxErrorQ1 = 1 << 21,
  210. icrRxErrorQ2 = 1 << 22,
  211. icrRxErrorQ3 = 1 << 23,
  212. icrMIIPhySTC = 1 << 28,
  213. icrSMIdone = 1 << 29,
  214. icrEtherIntSum = 1 << 31
  215. };
  216. /* The Rx and Tx descriptor lists. */
  217. #ifdef __LITTLE_ENDIAN
  218. typedef struct {
  219. u32 cmdstat;
  220. u16 reserved; //-prk21aug01 u32 reserved:16;
  221. u16 byte_cnt; //-prk21aug01 u32 byte_cnt:16;
  222. u32 buff_ptr;
  223. u32 next;
  224. } gt64240_td_t;
  225. typedef struct {
  226. u32 cmdstat;
  227. u16 byte_cnt; //-prk21aug01 u32 byte_cnt:16;
  228. u16 buff_sz; //-prk21aug01 u32 buff_sz:16;
  229. u32 buff_ptr;
  230. u32 next;
  231. } gt64240_rd_t;
  232. #elif defined(__BIG_ENDIAN)
  233. typedef struct {
  234. u16 byte_cnt; //-prk21aug01 u32 byte_cnt:16;
  235. u16 reserved; //-prk21aug01 u32 reserved:16;
  236. u32 cmdstat;
  237. u32 next;
  238. u32 buff_ptr;
  239. } gt64240_td_t;
  240. typedef struct {
  241. u16 buff_sz; //-prk21aug01 u32 buff_sz:16;
  242. u16 byte_cnt; //-prk21aug01 u32 byte_cnt:16;
  243. u32 cmdstat;
  244. u32 next;
  245. u32 buff_ptr;
  246. } gt64240_rd_t;
  247. #else
  248. #error Either __BIG_ENDIAN or __LITTLE_ENDIAN must be defined!
  249. #endif
  250. /* Values for the Tx command-status descriptor entry. */
  251. enum td_cmdstat {
  252. txOwn = 1 << 31,
  253. txAutoMode = 1 << 30,
  254. txEI = 1 << 23,
  255. txGenCRC = 1 << 22,
  256. txPad = 1 << 18,
  257. txFirst = 1 << 17,
  258. txLast = 1 << 16,
  259. txErrorSummary = 1 << 15,
  260. txReTxCntMask = 0x0f << 10,
  261. txReTxCntBit = 10,
  262. txCollision = 1 << 9,
  263. txReTxLimit = 1 << 8,
  264. txUnderrun = 1 << 6,
  265. txLateCollision = 1 << 5
  266. };
  267. /* Values for the Rx command-status descriptor entry. */
  268. enum rd_cmdstat {
  269. rxOwn = 1 << 31,
  270. rxAutoMode = 1 << 30,
  271. rxEI = 1 << 23,
  272. rxFirst = 1 << 17,
  273. rxLast = 1 << 16,
  274. rxErrorSummary = 1 << 15,
  275. rxIGMP = 1 << 14,
  276. rxHashExpired = 1 << 13,
  277. rxMissedFrame = 1 << 12,
  278. rxFrameType = 1 << 11,
  279. rxShortFrame = 1 << 8,
  280. rxMaxFrameLen = 1 << 7,
  281. rxOverrun = 1 << 6,
  282. rxCollision = 1 << 4,
  283. rxCRCError = 1
  284. };
  285. /* Bit fields of a Hash Table Entry */
  286. enum hash_table_entry {
  287. hteValid = 1,
  288. hteSkip = 2,
  289. hteRD = 4
  290. };
  291. // The MIB counters
  292. typedef struct {
  293. u32 byteReceived;
  294. u32 byteSent;
  295. u32 framesReceived;
  296. u32 framesSent;
  297. u32 totalByteReceived;
  298. u32 totalFramesReceived;
  299. u32 broadcastFramesReceived;
  300. u32 multicastFramesReceived;
  301. u32 cRCError;
  302. u32 oversizeFrames;
  303. u32 fragments;
  304. u32 jabber;
  305. u32 collision;
  306. u32 lateCollision;
  307. u32 frames64;
  308. u32 frames65_127;
  309. u32 frames128_255;
  310. u32 frames256_511;
  311. u32 frames512_1023;
  312. u32 frames1024_MaxSize;
  313. u32 macRxError;
  314. u32 droppedFrames;
  315. u32 outMulticastFrames;
  316. u32 outBroadcastFrames;
  317. u32 undersizeFrames;
  318. } mib_counters_t;
  319. struct gt64240_private {
  320. gt64240_rd_t *rx_ring;
  321. gt64240_td_t *tx_ring;
  322. // The Rx and Tx rings must be 16-byte aligned
  323. dma_addr_t rx_ring_dma;
  324. dma_addr_t tx_ring_dma;
  325. char *hash_table;
  326. // The Hash Table must be 8-byte aligned
  327. dma_addr_t hash_table_dma;
  328. int hash_mode;
  329. // The Rx buffers must be 8-byte aligned
  330. char *rx_buff;
  331. dma_addr_t rx_buff_dma;
  332. // Tx buffers (tx_skbuff[i]->data) with less than 8 bytes
  333. // of payload must be 8-byte aligned
  334. struct sk_buff *tx_skbuff[TX_RING_SIZE];
  335. int rx_next_out; /* The next free ring entry to receive */
  336. int tx_next_in; /* The next free ring entry to send */
  337. int tx_next_out; /* The last ring entry the ISR processed */
  338. int tx_count; /* current # of pkts waiting to be sent in Tx ring */
  339. int intr_work_done; /* number of Rx and Tx pkts processed in the isr */
  340. int tx_full; /* Tx ring is full */
  341. mib_counters_t mib;
  342. struct net_device_stats stats;
  343. int io_size;
  344. int port_num; // 0 or 1
  345. u32 port_offset;
  346. int phy_addr; // PHY address
  347. u32 last_psr; // last value of the port status register
  348. int options; /* User-settable misc. driver options. */
  349. int drv_flags;
  350. spinlock_t lock; /* Serialise access to device */
  351. struct mii_if_info mii_if;
  352. u32 msg_enable;
  353. };
  354. #endif /* _GT64240ETH_H */