mv643xx_eth.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  1. #ifndef __MV643XX_ETH_H__
  2. #define __MV643XX_ETH_H__
  3. #include <linux/version.h>
  4. #include <linux/module.h>
  5. #include <linux/kernel.h>
  6. #include <linux/spinlock.h>
  7. #include <linux/workqueue.h>
  8. #include <linux/mv643xx.h>
  9. #define BIT0 0x00000001
  10. #define BIT1 0x00000002
  11. #define BIT2 0x00000004
  12. #define BIT3 0x00000008
  13. #define BIT4 0x00000010
  14. #define BIT5 0x00000020
  15. #define BIT6 0x00000040
  16. #define BIT7 0x00000080
  17. #define BIT8 0x00000100
  18. #define BIT9 0x00000200
  19. #define BIT10 0x00000400
  20. #define BIT11 0x00000800
  21. #define BIT12 0x00001000
  22. #define BIT13 0x00002000
  23. #define BIT14 0x00004000
  24. #define BIT15 0x00008000
  25. #define BIT16 0x00010000
  26. #define BIT17 0x00020000
  27. #define BIT18 0x00040000
  28. #define BIT19 0x00080000
  29. #define BIT20 0x00100000
  30. #define BIT21 0x00200000
  31. #define BIT22 0x00400000
  32. #define BIT23 0x00800000
  33. #define BIT24 0x01000000
  34. #define BIT25 0x02000000
  35. #define BIT26 0x04000000
  36. #define BIT27 0x08000000
  37. #define BIT28 0x10000000
  38. #define BIT29 0x20000000
  39. #define BIT30 0x40000000
  40. #define BIT31 0x80000000
  41. /*
  42. * The first part is the high level driver of the gigE ethernet ports.
  43. */
  44. /* Checksum offload for Tx works for most packets, but
  45. * fails if previous packet sent did not use hw csum
  46. */
  47. #define MV643XX_CHECKSUM_OFFLOAD_TX
  48. #define MV643XX_NAPI
  49. #define MV643XX_TX_FAST_REFILL
  50. #undef MV643XX_RX_QUEUE_FILL_ON_TASK /* Does not work, yet */
  51. #undef MV643XX_COAL
  52. /*
  53. * Number of RX / TX descriptors on RX / TX rings.
  54. * Note that allocating RX descriptors is done by allocating the RX
  55. * ring AND a preallocated RX buffers (skb's) for each descriptor.
  56. * The TX descriptors only allocates the TX descriptors ring,
  57. * with no pre allocated TX buffers (skb's are allocated by higher layers.
  58. */
  59. /* Default TX ring size is 1000 descriptors */
  60. #define MV643XX_DEFAULT_TX_QUEUE_SIZE 1000
  61. /* Default RX ring size is 400 descriptors */
  62. #define MV643XX_DEFAULT_RX_QUEUE_SIZE 400
  63. #define MV643XX_TX_COAL 100
  64. #ifdef MV643XX_COAL
  65. #define MV643XX_RX_COAL 100
  66. #endif
  67. /*
  68. * The second part is the low level driver of the gigE ethernet ports.
  69. */
  70. /*
  71. * Header File for : MV-643xx network interface header
  72. *
  73. * DESCRIPTION:
  74. * This header file contains macros typedefs and function declaration for
  75. * the Marvell Gig Bit Ethernet Controller.
  76. *
  77. * DEPENDENCIES:
  78. * None.
  79. *
  80. */
  81. /* MAC accepet/reject macros */
  82. #define ACCEPT_MAC_ADDR 0
  83. #define REJECT_MAC_ADDR 1
  84. /* Buffer offset from buffer pointer */
  85. #define RX_BUF_OFFSET 0x2
  86. /* Gigabit Ethernet Unit Global Registers */
  87. /* MIB Counters register definitions */
  88. #define ETH_MIB_GOOD_OCTETS_RECEIVED_LOW 0x0
  89. #define ETH_MIB_GOOD_OCTETS_RECEIVED_HIGH 0x4
  90. #define ETH_MIB_BAD_OCTETS_RECEIVED 0x8
  91. #define ETH_MIB_INTERNAL_MAC_TRANSMIT_ERR 0xc
  92. #define ETH_MIB_GOOD_FRAMES_RECEIVED 0x10
  93. #define ETH_MIB_BAD_FRAMES_RECEIVED 0x14
  94. #define ETH_MIB_BROADCAST_FRAMES_RECEIVED 0x18
  95. #define ETH_MIB_MULTICAST_FRAMES_RECEIVED 0x1c
  96. #define ETH_MIB_FRAMES_64_OCTETS 0x20
  97. #define ETH_MIB_FRAMES_65_TO_127_OCTETS 0x24
  98. #define ETH_MIB_FRAMES_128_TO_255_OCTETS 0x28
  99. #define ETH_MIB_FRAMES_256_TO_511_OCTETS 0x2c
  100. #define ETH_MIB_FRAMES_512_TO_1023_OCTETS 0x30
  101. #define ETH_MIB_FRAMES_1024_TO_MAX_OCTETS 0x34
  102. #define ETH_MIB_GOOD_OCTETS_SENT_LOW 0x38
  103. #define ETH_MIB_GOOD_OCTETS_SENT_HIGH 0x3c
  104. #define ETH_MIB_GOOD_FRAMES_SENT 0x40
  105. #define ETH_MIB_EXCESSIVE_COLLISION 0x44
  106. #define ETH_MIB_MULTICAST_FRAMES_SENT 0x48
  107. #define ETH_MIB_BROADCAST_FRAMES_SENT 0x4c
  108. #define ETH_MIB_UNREC_MAC_CONTROL_RECEIVED 0x50
  109. #define ETH_MIB_FC_SENT 0x54
  110. #define ETH_MIB_GOOD_FC_RECEIVED 0x58
  111. #define ETH_MIB_BAD_FC_RECEIVED 0x5c
  112. #define ETH_MIB_UNDERSIZE_RECEIVED 0x60
  113. #define ETH_MIB_FRAGMENTS_RECEIVED 0x64
  114. #define ETH_MIB_OVERSIZE_RECEIVED 0x68
  115. #define ETH_MIB_JABBER_RECEIVED 0x6c
  116. #define ETH_MIB_MAC_RECEIVE_ERROR 0x70
  117. #define ETH_MIB_BAD_CRC_EVENT 0x74
  118. #define ETH_MIB_COLLISION 0x78
  119. #define ETH_MIB_LATE_COLLISION 0x7c
  120. /* Port serial status reg (PSR) */
  121. #define ETH_INTERFACE_GMII_MII 0
  122. #define ETH_INTERFACE_PCM BIT0
  123. #define ETH_LINK_IS_DOWN 0
  124. #define ETH_LINK_IS_UP BIT1
  125. #define ETH_PORT_AT_HALF_DUPLEX 0
  126. #define ETH_PORT_AT_FULL_DUPLEX BIT2
  127. #define ETH_RX_FLOW_CTRL_DISABLED 0
  128. #define ETH_RX_FLOW_CTRL_ENBALED BIT3
  129. #define ETH_GMII_SPEED_100_10 0
  130. #define ETH_GMII_SPEED_1000 BIT4
  131. #define ETH_MII_SPEED_10 0
  132. #define ETH_MII_SPEED_100 BIT5
  133. #define ETH_NO_TX 0
  134. #define ETH_TX_IN_PROGRESS BIT7
  135. #define ETH_BYPASS_NO_ACTIVE 0
  136. #define ETH_BYPASS_ACTIVE BIT8
  137. #define ETH_PORT_NOT_AT_PARTITION_STATE 0
  138. #define ETH_PORT_AT_PARTITION_STATE BIT9
  139. #define ETH_PORT_TX_FIFO_NOT_EMPTY 0
  140. #define ETH_PORT_TX_FIFO_EMPTY BIT10
  141. #define ETH_DEFAULT_RX_BPDU_QUEUE_3 (BIT23 | BIT22)
  142. #define ETH_DEFAULT_RX_BPDU_QUEUE_4 BIT24
  143. #define ETH_DEFAULT_RX_BPDU_QUEUE_5 (BIT24 | BIT22)
  144. #define ETH_DEFAULT_RX_BPDU_QUEUE_6 (BIT24 | BIT23)
  145. #define ETH_DEFAULT_RX_BPDU_QUEUE_7 (BIT24 | BIT23 | BIT22)
  146. /* SMI reg */
  147. #define ETH_SMI_BUSY BIT28 /* 0 - Write, 1 - Read */
  148. #define ETH_SMI_READ_VALID BIT27 /* 0 - Write, 1 - Read */
  149. #define ETH_SMI_OPCODE_WRITE 0 /* Completion of Read operation */
  150. #define ETH_SMI_OPCODE_READ BIT26 /* Operation is in progress */
  151. /* SDMA command status fields macros */
  152. /* Tx & Rx descriptors status */
  153. #define ETH_ERROR_SUMMARY (BIT0)
  154. /* Tx & Rx descriptors command */
  155. #define ETH_BUFFER_OWNED_BY_DMA (BIT31)
  156. /* Tx descriptors status */
  157. #define ETH_LC_ERROR (0 )
  158. #define ETH_UR_ERROR (BIT1 )
  159. #define ETH_RL_ERROR (BIT2 )
  160. #define ETH_LLC_SNAP_FORMAT (BIT9 )
  161. /* Rx descriptors status */
  162. #define ETH_CRC_ERROR (0 )
  163. #define ETH_OVERRUN_ERROR (BIT1 )
  164. #define ETH_MAX_FRAME_LENGTH_ERROR (BIT2 )
  165. #define ETH_RESOURCE_ERROR ((BIT2 | BIT1))
  166. #define ETH_VLAN_TAGGED (BIT19)
  167. #define ETH_BPDU_FRAME (BIT20)
  168. #define ETH_TCP_FRAME_OVER_IP_V_4 (0 )
  169. #define ETH_UDP_FRAME_OVER_IP_V_4 (BIT21)
  170. #define ETH_OTHER_FRAME_TYPE (BIT22)
  171. #define ETH_LAYER_2_IS_ETH_V_2 (BIT23)
  172. #define ETH_FRAME_TYPE_IP_V_4 (BIT24)
  173. #define ETH_FRAME_HEADER_OK (BIT25)
  174. #define ETH_RX_LAST_DESC (BIT26)
  175. #define ETH_RX_FIRST_DESC (BIT27)
  176. #define ETH_UNKNOWN_DESTINATION_ADDR (BIT28)
  177. #define ETH_RX_ENABLE_INTERRUPT (BIT29)
  178. #define ETH_LAYER_4_CHECKSUM_OK (BIT30)
  179. /* Rx descriptors byte count */
  180. #define ETH_FRAME_FRAGMENTED (BIT2)
  181. /* Tx descriptors command */
  182. #define ETH_LAYER_4_CHECKSUM_FIRST_DESC (BIT10)
  183. #define ETH_FRAME_SET_TO_VLAN (BIT15)
  184. #define ETH_TCP_FRAME (0 )
  185. #define ETH_UDP_FRAME (BIT16)
  186. #define ETH_GEN_TCP_UDP_CHECKSUM (BIT17)
  187. #define ETH_GEN_IP_V_4_CHECKSUM (BIT18)
  188. #define ETH_ZERO_PADDING (BIT19)
  189. #define ETH_TX_LAST_DESC (BIT20)
  190. #define ETH_TX_FIRST_DESC (BIT21)
  191. #define ETH_GEN_CRC (BIT22)
  192. #define ETH_TX_ENABLE_INTERRUPT (BIT23)
  193. #define ETH_AUTO_MODE (BIT30)
  194. #define ETH_TX_IHL_SHIFT 11
  195. /* typedefs */
  196. typedef enum _eth_func_ret_status {
  197. ETH_OK, /* Returned as expected. */
  198. ETH_ERROR, /* Fundamental error. */
  199. ETH_RETRY, /* Could not process request. Try later.*/
  200. ETH_END_OF_JOB, /* Ring has nothing to process. */
  201. ETH_QUEUE_FULL, /* Ring resource error. */
  202. ETH_QUEUE_LAST_RESOURCE /* Ring resources about to exhaust. */
  203. } ETH_FUNC_RET_STATUS;
  204. typedef enum _eth_target {
  205. ETH_TARGET_DRAM,
  206. ETH_TARGET_DEVICE,
  207. ETH_TARGET_CBS,
  208. ETH_TARGET_PCI0,
  209. ETH_TARGET_PCI1
  210. } ETH_TARGET;
  211. /* These are for big-endian machines. Little endian needs different
  212. * definitions.
  213. */
  214. #if defined(__BIG_ENDIAN)
  215. struct eth_rx_desc {
  216. u16 byte_cnt; /* Descriptor buffer byte count */
  217. u16 buf_size; /* Buffer size */
  218. u32 cmd_sts; /* Descriptor command status */
  219. u32 next_desc_ptr; /* Next descriptor pointer */
  220. u32 buf_ptr; /* Descriptor buffer pointer */
  221. };
  222. struct eth_tx_desc {
  223. u16 byte_cnt; /* buffer byte count */
  224. u16 l4i_chk; /* CPU provided TCP checksum */
  225. u32 cmd_sts; /* Command/status field */
  226. u32 next_desc_ptr; /* Pointer to next descriptor */
  227. u32 buf_ptr; /* pointer to buffer for this descriptor*/
  228. };
  229. #elif defined(__LITTLE_ENDIAN)
  230. struct eth_rx_desc {
  231. u32 cmd_sts; /* Descriptor command status */
  232. u16 buf_size; /* Buffer size */
  233. u16 byte_cnt; /* Descriptor buffer byte count */
  234. u32 buf_ptr; /* Descriptor buffer pointer */
  235. u32 next_desc_ptr; /* Next descriptor pointer */
  236. };
  237. struct eth_tx_desc {
  238. u32 cmd_sts; /* Command/status field */
  239. u16 l4i_chk; /* CPU provided TCP checksum */
  240. u16 byte_cnt; /* buffer byte count */
  241. u32 buf_ptr; /* pointer to buffer for this descriptor*/
  242. u32 next_desc_ptr; /* Pointer to next descriptor */
  243. };
  244. #else
  245. #error One of __BIG_ENDIAN or __LITTLE_ENDIAN must be defined
  246. #endif
  247. /* Unified struct for Rx and Tx operations. The user is not required to */
  248. /* be familier with neither Tx nor Rx descriptors. */
  249. struct pkt_info {
  250. unsigned short byte_cnt; /* Descriptor buffer byte count */
  251. unsigned short l4i_chk; /* Tx CPU provided TCP Checksum */
  252. unsigned int cmd_sts; /* Descriptor command status */
  253. dma_addr_t buf_ptr; /* Descriptor buffer pointer */
  254. struct sk_buff *return_info; /* User resource return information */
  255. };
  256. /* Ethernet port specific infomation */
  257. struct mv643xx_mib_counters {
  258. u64 good_octets_received;
  259. u32 bad_octets_received;
  260. u32 internal_mac_transmit_err;
  261. u32 good_frames_received;
  262. u32 bad_frames_received;
  263. u32 broadcast_frames_received;
  264. u32 multicast_frames_received;
  265. u32 frames_64_octets;
  266. u32 frames_65_to_127_octets;
  267. u32 frames_128_to_255_octets;
  268. u32 frames_256_to_511_octets;
  269. u32 frames_512_to_1023_octets;
  270. u32 frames_1024_to_max_octets;
  271. u64 good_octets_sent;
  272. u32 good_frames_sent;
  273. u32 excessive_collision;
  274. u32 multicast_frames_sent;
  275. u32 broadcast_frames_sent;
  276. u32 unrec_mac_control_received;
  277. u32 fc_sent;
  278. u32 good_fc_received;
  279. u32 bad_fc_received;
  280. u32 undersize_received;
  281. u32 fragments_received;
  282. u32 oversize_received;
  283. u32 jabber_received;
  284. u32 mac_receive_error;
  285. u32 bad_crc_event;
  286. u32 collision;
  287. u32 late_collision;
  288. };
  289. struct mv643xx_private {
  290. int port_num; /* User Ethernet port number */
  291. u8 port_mac_addr[6]; /* User defined port MAC address.*/
  292. u32 port_config; /* User port configuration value*/
  293. u32 port_config_extend; /* User port config extend value*/
  294. u32 port_sdma_config; /* User port SDMA config value */
  295. u32 port_serial_control; /* User port serial control value */
  296. u32 port_tx_queue_command; /* Port active Tx queues summary*/
  297. u32 port_rx_queue_command; /* Port active Rx queues summary*/
  298. u32 rx_sram_addr; /* Base address of rx sram area */
  299. u32 rx_sram_size; /* Size of rx sram area */
  300. u32 tx_sram_addr; /* Base address of tx sram area */
  301. u32 tx_sram_size; /* Size of tx sram area */
  302. int rx_resource_err; /* Rx ring resource error flag */
  303. int tx_resource_err; /* Tx ring resource error flag */
  304. /* Tx/Rx rings managment indexes fields. For driver use */
  305. /* Next available and first returning Rx resource */
  306. int rx_curr_desc_q, rx_used_desc_q;
  307. /* Next available and first returning Tx resource */
  308. int tx_curr_desc_q, tx_used_desc_q;
  309. #ifdef MV643XX_CHECKSUM_OFFLOAD_TX
  310. int tx_first_desc_q;
  311. u32 tx_first_command;
  312. #endif
  313. #ifdef MV643XX_TX_FAST_REFILL
  314. u32 tx_clean_threshold;
  315. #endif
  316. struct eth_rx_desc *p_rx_desc_area;
  317. dma_addr_t rx_desc_dma;
  318. unsigned int rx_desc_area_size;
  319. struct sk_buff **rx_skb;
  320. struct eth_tx_desc *p_tx_desc_area;
  321. dma_addr_t tx_desc_dma;
  322. unsigned int tx_desc_area_size;
  323. struct sk_buff **tx_skb;
  324. struct work_struct tx_timeout_task;
  325. /*
  326. * Former struct mv643xx_eth_priv members start here
  327. */
  328. struct net_device_stats stats;
  329. struct mv643xx_mib_counters mib_counters;
  330. spinlock_t lock;
  331. /* Size of Tx Ring per queue */
  332. unsigned int tx_ring_size;
  333. /* Ammont of SKBs outstanding on Tx queue */
  334. unsigned int tx_ring_skbs;
  335. /* Size of Rx Ring per queue */
  336. unsigned int rx_ring_size;
  337. /* Ammount of SKBs allocated to Rx Ring per queue */
  338. unsigned int rx_ring_skbs;
  339. /*
  340. * rx_task used to fill RX ring out of bottom half context
  341. */
  342. struct work_struct rx_task;
  343. /*
  344. * Used in case RX Ring is empty, which can be caused when
  345. * system does not have resources (skb's)
  346. */
  347. struct timer_list timeout;
  348. long rx_task_busy __attribute__ ((aligned(SMP_CACHE_BYTES)));
  349. unsigned rx_timer_flag;
  350. u32 rx_int_coal;
  351. u32 tx_int_coal;
  352. };
  353. /* ethernet.h API list */
  354. /* Port operation control routines */
  355. static void eth_port_init(struct mv643xx_private *mp);
  356. static void eth_port_reset(unsigned int eth_port_num);
  357. static void eth_port_start(struct mv643xx_private *mp);
  358. /* Port MAC address routines */
  359. static void eth_port_uc_addr_set(unsigned int eth_port_num,
  360. unsigned char *p_addr);
  361. /* PHY and MIB routines */
  362. static void ethernet_phy_reset(unsigned int eth_port_num);
  363. static void eth_port_write_smi_reg(unsigned int eth_port_num,
  364. unsigned int phy_reg, unsigned int value);
  365. static void eth_port_read_smi_reg(unsigned int eth_port_num,
  366. unsigned int phy_reg, unsigned int *value);
  367. static void eth_clear_mib_counters(unsigned int eth_port_num);
  368. /* Port data flow control routines */
  369. static ETH_FUNC_RET_STATUS eth_port_send(struct mv643xx_private *mp,
  370. struct pkt_info *p_pkt_info);
  371. static ETH_FUNC_RET_STATUS eth_tx_return_desc(struct mv643xx_private *mp,
  372. struct pkt_info *p_pkt_info);
  373. static ETH_FUNC_RET_STATUS eth_port_receive(struct mv643xx_private *mp,
  374. struct pkt_info *p_pkt_info);
  375. static ETH_FUNC_RET_STATUS eth_rx_return_buff(struct mv643xx_private *mp,
  376. struct pkt_info *p_pkt_info);
  377. #endif /* __MV643XX_ETH_H__ */