dwc-xlgmac.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661
  1. /* Synopsys DesignWare Core Enterprise Ethernet (XLGMAC) Driver
  2. *
  3. * Copyright (c) 2017 Synopsys, Inc. (www.synopsys.com)
  4. *
  5. * This program is dual-licensed; you may select either version 2 of
  6. * the GNU General Public License ("GPL") or BSD license ("BSD").
  7. *
  8. * This Synopsys DWC XLGMAC software driver and associated documentation
  9. * (hereinafter the "Software") is an unsupported proprietary work of
  10. * Synopsys, Inc. unless otherwise expressly agreed to in writing between
  11. * Synopsys and you. The Software IS NOT an item of Licensed Software or a
  12. * Licensed Product under any End User Software License Agreement or
  13. * Agreement for Licensed Products with Synopsys or any supplement thereto.
  14. * Synopsys is a registered trademark of Synopsys, Inc. Other names included
  15. * in the SOFTWARE may be the trademarks of their respective owners.
  16. */
  17. #ifndef __DWC_XLGMAC_H__
  18. #define __DWC_XLGMAC_H__
  19. #include <linux/dma-mapping.h>
  20. #include <linux/netdevice.h>
  21. #include <linux/workqueue.h>
  22. #include <linux/phy.h>
  23. #include <linux/if_vlan.h>
  24. #include <linux/bitops.h>
  25. #include <linux/timecounter.h>
  26. #define XLGMAC_DRV_NAME "dwc-xlgmac"
  27. #define XLGMAC_DRV_VERSION "1.0.0"
  28. #define XLGMAC_DRV_DESC "Synopsys DWC XLGMAC Driver"
  29. /* Descriptor related parameters */
  30. #define XLGMAC_TX_DESC_CNT 1024
  31. #define XLGMAC_TX_DESC_MIN_FREE (XLGMAC_TX_DESC_CNT >> 3)
  32. #define XLGMAC_TX_DESC_MAX_PROC (XLGMAC_TX_DESC_CNT >> 1)
  33. #define XLGMAC_RX_DESC_CNT 1024
  34. #define XLGMAC_RX_DESC_MAX_DIRTY (XLGMAC_RX_DESC_CNT >> 3)
  35. /* Descriptors required for maximum contiguous TSO/GSO packet */
  36. #define XLGMAC_TX_MAX_SPLIT \
  37. ((GSO_LEGACY_MAX_SIZE / XLGMAC_TX_MAX_BUF_SIZE) + 1)
  38. /* Maximum possible descriptors needed for a SKB */
  39. #define XLGMAC_TX_MAX_DESC_NR (MAX_SKB_FRAGS + XLGMAC_TX_MAX_SPLIT + 2)
  40. #define XLGMAC_TX_MAX_BUF_SIZE (0x3fff & ~(64 - 1))
  41. #define XLGMAC_RX_MIN_BUF_SIZE (ETH_FRAME_LEN + ETH_FCS_LEN + VLAN_HLEN)
  42. #define XLGMAC_RX_BUF_ALIGN 64
  43. /* Maximum Size for Splitting the Header Data
  44. * Keep in sync with SKB_ALLOC_SIZE
  45. * 3'b000: 64 bytes, 3'b001: 128 bytes
  46. * 3'b010: 256 bytes, 3'b011: 512 bytes
  47. * 3'b100: 1023 bytes , 3'b101'3'b111: Reserved
  48. */
  49. #define XLGMAC_SPH_HDSMS_SIZE 3
  50. #define XLGMAC_SKB_ALLOC_SIZE 512
  51. #define XLGMAC_MAX_FIFO 81920
  52. #define XLGMAC_MAX_DMA_CHANNELS 16
  53. #define XLGMAC_DMA_STOP_TIMEOUT 5
  54. #define XLGMAC_DMA_INTERRUPT_MASK 0x31c7
  55. /* Default coalescing parameters */
  56. #define XLGMAC_INIT_DMA_TX_USECS 1000
  57. #define XLGMAC_INIT_DMA_TX_FRAMES 25
  58. #define XLGMAC_INIT_DMA_RX_USECS 30
  59. #define XLGMAC_INIT_DMA_RX_FRAMES 25
  60. #define XLGMAC_MAX_DMA_RIWT 0xff
  61. #define XLGMAC_MIN_DMA_RIWT 0x01
  62. /* Flow control queue count */
  63. #define XLGMAC_MAX_FLOW_CONTROL_QUEUES 8
  64. /* System clock is 125 MHz */
  65. #define XLGMAC_SYSCLOCK 125000000
  66. /* Maximum MAC address hash table size (256 bits = 8 bytes) */
  67. #define XLGMAC_MAC_HASH_TABLE_SIZE 8
  68. /* Receive Side Scaling */
  69. #define XLGMAC_RSS_HASH_KEY_SIZE 40
  70. #define XLGMAC_RSS_MAX_TABLE_SIZE 256
  71. #define XLGMAC_RSS_LOOKUP_TABLE_TYPE 0
  72. #define XLGMAC_RSS_HASH_KEY_TYPE 1
  73. #define XLGMAC_STD_PACKET_MTU 1500
  74. #define XLGMAC_JUMBO_PACKET_MTU 9000
  75. /* Helper macro for descriptor handling
  76. * Always use XLGMAC_GET_DESC_DATA to access the descriptor data
  77. */
  78. #define XLGMAC_GET_DESC_DATA(ring, idx) ({ \
  79. typeof(ring) _ring = (ring); \
  80. ((_ring)->desc_data_head + \
  81. ((idx) & ((_ring)->dma_desc_count - 1))); \
  82. })
  83. #define XLGMAC_GET_REG_BITS(var, pos, len) ({ \
  84. typeof(pos) _pos = (pos); \
  85. typeof(len) _len = (len); \
  86. ((var) & GENMASK(_pos + _len - 1, _pos)) >> (_pos); \
  87. })
  88. #define XLGMAC_GET_REG_BITS_LE(var, pos, len) ({ \
  89. typeof(pos) _pos = (pos); \
  90. typeof(len) _len = (len); \
  91. typeof(var) _var = le32_to_cpu((var)); \
  92. ((_var) & GENMASK(_pos + _len - 1, _pos)) >> (_pos); \
  93. })
  94. #define XLGMAC_SET_REG_BITS(var, pos, len, val) ({ \
  95. typeof(var) _var = (var); \
  96. typeof(pos) _pos = (pos); \
  97. typeof(len) _len = (len); \
  98. typeof(val) _val = (val); \
  99. _val = (_val << _pos) & GENMASK(_pos + _len - 1, _pos); \
  100. _var = (_var & ~GENMASK(_pos + _len - 1, _pos)) | _val; \
  101. })
  102. #define XLGMAC_SET_REG_BITS_LE(var, pos, len, val) ({ \
  103. typeof(var) _var = (var); \
  104. typeof(pos) _pos = (pos); \
  105. typeof(len) _len = (len); \
  106. typeof(val) _val = (val); \
  107. _val = (_val << _pos) & GENMASK(_pos + _len - 1, _pos); \
  108. _var = (_var & ~GENMASK(_pos + _len - 1, _pos)) | _val; \
  109. cpu_to_le32(_var); \
  110. })
  111. struct xlgmac_pdata;
  112. enum xlgmac_int {
  113. XLGMAC_INT_DMA_CH_SR_TI,
  114. XLGMAC_INT_DMA_CH_SR_TPS,
  115. XLGMAC_INT_DMA_CH_SR_TBU,
  116. XLGMAC_INT_DMA_CH_SR_RI,
  117. XLGMAC_INT_DMA_CH_SR_RBU,
  118. XLGMAC_INT_DMA_CH_SR_RPS,
  119. XLGMAC_INT_DMA_CH_SR_TI_RI,
  120. XLGMAC_INT_DMA_CH_SR_FBE,
  121. XLGMAC_INT_DMA_ALL,
  122. };
  123. struct xlgmac_stats {
  124. /* MMC TX counters */
  125. u64 txoctetcount_gb;
  126. u64 txframecount_gb;
  127. u64 txbroadcastframes_g;
  128. u64 txmulticastframes_g;
  129. u64 tx64octets_gb;
  130. u64 tx65to127octets_gb;
  131. u64 tx128to255octets_gb;
  132. u64 tx256to511octets_gb;
  133. u64 tx512to1023octets_gb;
  134. u64 tx1024tomaxoctets_gb;
  135. u64 txunicastframes_gb;
  136. u64 txmulticastframes_gb;
  137. u64 txbroadcastframes_gb;
  138. u64 txunderflowerror;
  139. u64 txoctetcount_g;
  140. u64 txframecount_g;
  141. u64 txpauseframes;
  142. u64 txvlanframes_g;
  143. /* MMC RX counters */
  144. u64 rxframecount_gb;
  145. u64 rxoctetcount_gb;
  146. u64 rxoctetcount_g;
  147. u64 rxbroadcastframes_g;
  148. u64 rxmulticastframes_g;
  149. u64 rxcrcerror;
  150. u64 rxrunterror;
  151. u64 rxjabbererror;
  152. u64 rxundersize_g;
  153. u64 rxoversize_g;
  154. u64 rx64octets_gb;
  155. u64 rx65to127octets_gb;
  156. u64 rx128to255octets_gb;
  157. u64 rx256to511octets_gb;
  158. u64 rx512to1023octets_gb;
  159. u64 rx1024tomaxoctets_gb;
  160. u64 rxunicastframes_g;
  161. u64 rxlengtherror;
  162. u64 rxoutofrangetype;
  163. u64 rxpauseframes;
  164. u64 rxfifooverflow;
  165. u64 rxvlanframes_gb;
  166. u64 rxwatchdogerror;
  167. /* Extra counters */
  168. u64 tx_tso_packets;
  169. u64 rx_split_header_packets;
  170. u64 tx_process_stopped;
  171. u64 rx_process_stopped;
  172. u64 tx_buffer_unavailable;
  173. u64 rx_buffer_unavailable;
  174. u64 fatal_bus_error;
  175. u64 tx_vlan_packets;
  176. u64 rx_vlan_packets;
  177. u64 napi_poll_isr;
  178. u64 napi_poll_txtimer;
  179. };
  180. struct xlgmac_ring_buf {
  181. struct sk_buff *skb;
  182. dma_addr_t skb_dma;
  183. unsigned int skb_len;
  184. };
  185. /* Common Tx and Rx DMA hardware descriptor */
  186. struct xlgmac_dma_desc {
  187. __le32 desc0;
  188. __le32 desc1;
  189. __le32 desc2;
  190. __le32 desc3;
  191. };
  192. /* Page allocation related values */
  193. struct xlgmac_page_alloc {
  194. struct page *pages;
  195. unsigned int pages_len;
  196. unsigned int pages_offset;
  197. dma_addr_t pages_dma;
  198. };
  199. /* Ring entry buffer data */
  200. struct xlgmac_buffer_data {
  201. struct xlgmac_page_alloc pa;
  202. struct xlgmac_page_alloc pa_unmap;
  203. dma_addr_t dma_base;
  204. unsigned long dma_off;
  205. unsigned int dma_len;
  206. };
  207. /* Tx-related desc data */
  208. struct xlgmac_tx_desc_data {
  209. unsigned int packets; /* BQL packet count */
  210. unsigned int bytes; /* BQL byte count */
  211. };
  212. /* Rx-related desc data */
  213. struct xlgmac_rx_desc_data {
  214. struct xlgmac_buffer_data hdr; /* Header locations */
  215. struct xlgmac_buffer_data buf; /* Payload locations */
  216. unsigned short hdr_len; /* Length of received header */
  217. unsigned short len; /* Length of received packet */
  218. };
  219. struct xlgmac_pkt_info {
  220. struct sk_buff *skb;
  221. unsigned int attributes;
  222. unsigned int errors;
  223. /* descriptors needed for this packet */
  224. unsigned int desc_count;
  225. unsigned int length;
  226. unsigned int tx_packets;
  227. unsigned int tx_bytes;
  228. unsigned int header_len;
  229. unsigned int tcp_header_len;
  230. unsigned int tcp_payload_len;
  231. unsigned short mss;
  232. unsigned short vlan_ctag;
  233. u64 rx_tstamp;
  234. u32 rss_hash;
  235. enum pkt_hash_types rss_hash_type;
  236. };
  237. struct xlgmac_desc_data {
  238. /* dma_desc: Virtual address of descriptor
  239. * dma_desc_addr: DMA address of descriptor
  240. */
  241. struct xlgmac_dma_desc *dma_desc;
  242. dma_addr_t dma_desc_addr;
  243. /* skb: Virtual address of SKB
  244. * skb_dma: DMA address of SKB data
  245. * skb_dma_len: Length of SKB DMA area
  246. */
  247. struct sk_buff *skb;
  248. dma_addr_t skb_dma;
  249. unsigned int skb_dma_len;
  250. /* Tx/Rx -related data */
  251. struct xlgmac_tx_desc_data tx;
  252. struct xlgmac_rx_desc_data rx;
  253. unsigned int mapped_as_page;
  254. /* Incomplete receive save location. If the budget is exhausted
  255. * or the last descriptor (last normal descriptor or a following
  256. * context descriptor) has not been DMA'd yet the current state
  257. * of the receive processing needs to be saved.
  258. */
  259. unsigned int state_saved;
  260. struct {
  261. struct sk_buff *skb;
  262. unsigned int len;
  263. unsigned int error;
  264. } state;
  265. };
  266. struct xlgmac_ring {
  267. /* Per packet related information */
  268. struct xlgmac_pkt_info pkt_info;
  269. /* Virtual/DMA addresses of DMA descriptor list and the total count */
  270. struct xlgmac_dma_desc *dma_desc_head;
  271. dma_addr_t dma_desc_head_addr;
  272. unsigned int dma_desc_count;
  273. /* Array of descriptor data corresponding the DMA descriptor
  274. * (always use the XLGMAC_GET_DESC_DATA macro to access this data)
  275. */
  276. struct xlgmac_desc_data *desc_data_head;
  277. /* Page allocation for RX buffers */
  278. struct xlgmac_page_alloc rx_hdr_pa;
  279. struct xlgmac_page_alloc rx_buf_pa;
  280. /* Ring index values
  281. * cur - Tx: index of descriptor to be used for current transfer
  282. * Rx: index of descriptor to check for packet availability
  283. * dirty - Tx: index of descriptor to check for transfer complete
  284. * Rx: index of descriptor to check for buffer reallocation
  285. */
  286. unsigned int cur;
  287. unsigned int dirty;
  288. /* Coalesce frame count used for interrupt bit setting */
  289. unsigned int coalesce_count;
  290. union {
  291. struct {
  292. unsigned int xmit_more;
  293. unsigned int queue_stopped;
  294. unsigned short cur_mss;
  295. unsigned short cur_vlan_ctag;
  296. } tx;
  297. };
  298. } ____cacheline_aligned;
  299. struct xlgmac_channel {
  300. char name[16];
  301. /* Address of private data area for device */
  302. struct xlgmac_pdata *pdata;
  303. /* Queue index and base address of queue's DMA registers */
  304. unsigned int queue_index;
  305. void __iomem *dma_regs;
  306. /* Per channel interrupt irq number */
  307. int dma_irq;
  308. char dma_irq_name[IFNAMSIZ + 32];
  309. /* Netdev related settings */
  310. struct napi_struct napi;
  311. unsigned int saved_ier;
  312. unsigned int tx_timer_active;
  313. struct timer_list tx_timer;
  314. struct xlgmac_ring *tx_ring;
  315. struct xlgmac_ring *rx_ring;
  316. } ____cacheline_aligned;
  317. struct xlgmac_desc_ops {
  318. int (*alloc_channels_and_rings)(struct xlgmac_pdata *pdata);
  319. void (*free_channels_and_rings)(struct xlgmac_pdata *pdata);
  320. int (*map_tx_skb)(struct xlgmac_channel *channel,
  321. struct sk_buff *skb);
  322. int (*map_rx_buffer)(struct xlgmac_pdata *pdata,
  323. struct xlgmac_ring *ring,
  324. struct xlgmac_desc_data *desc_data);
  325. void (*unmap_desc_data)(struct xlgmac_pdata *pdata,
  326. struct xlgmac_desc_data *desc_data);
  327. void (*tx_desc_init)(struct xlgmac_pdata *pdata);
  328. void (*rx_desc_init)(struct xlgmac_pdata *pdata);
  329. };
  330. struct xlgmac_hw_ops {
  331. int (*init)(struct xlgmac_pdata *pdata);
  332. int (*exit)(struct xlgmac_pdata *pdata);
  333. int (*tx_complete)(struct xlgmac_dma_desc *dma_desc);
  334. void (*enable_tx)(struct xlgmac_pdata *pdata);
  335. void (*disable_tx)(struct xlgmac_pdata *pdata);
  336. void (*enable_rx)(struct xlgmac_pdata *pdata);
  337. void (*disable_rx)(struct xlgmac_pdata *pdata);
  338. int (*enable_int)(struct xlgmac_channel *channel,
  339. enum xlgmac_int int_id);
  340. int (*disable_int)(struct xlgmac_channel *channel,
  341. enum xlgmac_int int_id);
  342. void (*dev_xmit)(struct xlgmac_channel *channel);
  343. int (*dev_read)(struct xlgmac_channel *channel);
  344. int (*set_mac_address)(struct xlgmac_pdata *pdata, const u8 *addr);
  345. int (*config_rx_mode)(struct xlgmac_pdata *pdata);
  346. int (*enable_rx_csum)(struct xlgmac_pdata *pdata);
  347. int (*disable_rx_csum)(struct xlgmac_pdata *pdata);
  348. /* For MII speed configuration */
  349. int (*set_xlgmii_25000_speed)(struct xlgmac_pdata *pdata);
  350. int (*set_xlgmii_40000_speed)(struct xlgmac_pdata *pdata);
  351. int (*set_xlgmii_50000_speed)(struct xlgmac_pdata *pdata);
  352. int (*set_xlgmii_100000_speed)(struct xlgmac_pdata *pdata);
  353. /* For descriptor related operation */
  354. void (*tx_desc_init)(struct xlgmac_channel *channel);
  355. void (*rx_desc_init)(struct xlgmac_channel *channel);
  356. void (*tx_desc_reset)(struct xlgmac_desc_data *desc_data);
  357. void (*rx_desc_reset)(struct xlgmac_pdata *pdata,
  358. struct xlgmac_desc_data *desc_data,
  359. unsigned int index);
  360. int (*is_last_desc)(struct xlgmac_dma_desc *dma_desc);
  361. int (*is_context_desc)(struct xlgmac_dma_desc *dma_desc);
  362. void (*tx_start_xmit)(struct xlgmac_channel *channel,
  363. struct xlgmac_ring *ring);
  364. /* For Flow Control */
  365. int (*config_tx_flow_control)(struct xlgmac_pdata *pdata);
  366. int (*config_rx_flow_control)(struct xlgmac_pdata *pdata);
  367. /* For Vlan related config */
  368. int (*enable_rx_vlan_stripping)(struct xlgmac_pdata *pdata);
  369. int (*disable_rx_vlan_stripping)(struct xlgmac_pdata *pdata);
  370. int (*enable_rx_vlan_filtering)(struct xlgmac_pdata *pdata);
  371. int (*disable_rx_vlan_filtering)(struct xlgmac_pdata *pdata);
  372. int (*update_vlan_hash_table)(struct xlgmac_pdata *pdata);
  373. /* For RX coalescing */
  374. int (*config_rx_coalesce)(struct xlgmac_pdata *pdata);
  375. int (*config_tx_coalesce)(struct xlgmac_pdata *pdata);
  376. unsigned int (*usec_to_riwt)(struct xlgmac_pdata *pdata,
  377. unsigned int usec);
  378. unsigned int (*riwt_to_usec)(struct xlgmac_pdata *pdata,
  379. unsigned int riwt);
  380. /* For RX and TX threshold config */
  381. int (*config_rx_threshold)(struct xlgmac_pdata *pdata,
  382. unsigned int val);
  383. int (*config_tx_threshold)(struct xlgmac_pdata *pdata,
  384. unsigned int val);
  385. /* For RX and TX Store and Forward Mode config */
  386. int (*config_rsf_mode)(struct xlgmac_pdata *pdata,
  387. unsigned int val);
  388. int (*config_tsf_mode)(struct xlgmac_pdata *pdata,
  389. unsigned int val);
  390. /* For TX DMA Operate on Second Frame config */
  391. int (*config_osp_mode)(struct xlgmac_pdata *pdata);
  392. /* For RX and TX PBL config */
  393. int (*config_rx_pbl_val)(struct xlgmac_pdata *pdata);
  394. int (*get_rx_pbl_val)(struct xlgmac_pdata *pdata);
  395. int (*config_tx_pbl_val)(struct xlgmac_pdata *pdata);
  396. int (*get_tx_pbl_val)(struct xlgmac_pdata *pdata);
  397. int (*config_pblx8)(struct xlgmac_pdata *pdata);
  398. /* For MMC statistics */
  399. void (*rx_mmc_int)(struct xlgmac_pdata *pdata);
  400. void (*tx_mmc_int)(struct xlgmac_pdata *pdata);
  401. void (*read_mmc_stats)(struct xlgmac_pdata *pdata);
  402. /* For Receive Side Scaling */
  403. int (*enable_rss)(struct xlgmac_pdata *pdata);
  404. int (*disable_rss)(struct xlgmac_pdata *pdata);
  405. int (*set_rss_hash_key)(struct xlgmac_pdata *pdata,
  406. const u8 *key);
  407. int (*set_rss_lookup_table)(struct xlgmac_pdata *pdata,
  408. const u32 *table);
  409. };
  410. /* This structure contains flags that indicate what hardware features
  411. * or configurations are present in the device.
  412. */
  413. struct xlgmac_hw_features {
  414. /* HW Version */
  415. unsigned int version;
  416. /* HW Feature Register0 */
  417. unsigned int phyifsel; /* PHY interface support */
  418. unsigned int vlhash; /* VLAN Hash Filter */
  419. unsigned int sma; /* SMA(MDIO) Interface */
  420. unsigned int rwk; /* PMT remote wake-up packet */
  421. unsigned int mgk; /* PMT magic packet */
  422. unsigned int mmc; /* RMON module */
  423. unsigned int aoe; /* ARP Offload */
  424. unsigned int ts; /* IEEE 1588-2008 Advanced Timestamp */
  425. unsigned int eee; /* Energy Efficient Ethernet */
  426. unsigned int tx_coe; /* Tx Checksum Offload */
  427. unsigned int rx_coe; /* Rx Checksum Offload */
  428. unsigned int addn_mac; /* Additional MAC Addresses */
  429. unsigned int ts_src; /* Timestamp Source */
  430. unsigned int sa_vlan_ins; /* Source Address or VLAN Insertion */
  431. /* HW Feature Register1 */
  432. unsigned int rx_fifo_size; /* MTL Receive FIFO Size */
  433. unsigned int tx_fifo_size; /* MTL Transmit FIFO Size */
  434. unsigned int adv_ts_hi; /* Advance Timestamping High Word */
  435. unsigned int dma_width; /* DMA width */
  436. unsigned int dcb; /* DCB Feature */
  437. unsigned int sph; /* Split Header Feature */
  438. unsigned int tso; /* TCP Segmentation Offload */
  439. unsigned int dma_debug; /* DMA Debug Registers */
  440. unsigned int rss; /* Receive Side Scaling */
  441. unsigned int tc_cnt; /* Number of Traffic Classes */
  442. unsigned int hash_table_size; /* Hash Table Size */
  443. unsigned int l3l4_filter_num; /* Number of L3-L4 Filters */
  444. /* HW Feature Register2 */
  445. unsigned int rx_q_cnt; /* Number of MTL Receive Queues */
  446. unsigned int tx_q_cnt; /* Number of MTL Transmit Queues */
  447. unsigned int rx_ch_cnt; /* Number of DMA Receive Channels */
  448. unsigned int tx_ch_cnt; /* Number of DMA Transmit Channels */
  449. unsigned int pps_out_num; /* Number of PPS outputs */
  450. unsigned int aux_snap_num; /* Number of Aux snapshot inputs */
  451. };
  452. struct xlgmac_resources {
  453. void __iomem *addr;
  454. int irq;
  455. };
  456. struct xlgmac_pdata {
  457. struct net_device *netdev;
  458. struct device *dev;
  459. struct xlgmac_hw_ops hw_ops;
  460. struct xlgmac_desc_ops desc_ops;
  461. /* Device statistics */
  462. struct xlgmac_stats stats;
  463. u32 msg_enable;
  464. /* MAC registers base */
  465. void __iomem *mac_regs;
  466. /* Hardware features of the device */
  467. struct xlgmac_hw_features hw_feat;
  468. struct work_struct restart_work;
  469. /* Rings for Tx/Rx on a DMA channel */
  470. struct xlgmac_channel *channel_head;
  471. unsigned int channel_count;
  472. unsigned int tx_ring_count;
  473. unsigned int rx_ring_count;
  474. unsigned int tx_desc_count;
  475. unsigned int rx_desc_count;
  476. unsigned int tx_q_count;
  477. unsigned int rx_q_count;
  478. /* Tx/Rx common settings */
  479. unsigned int pblx8;
  480. /* Tx settings */
  481. unsigned int tx_sf_mode;
  482. unsigned int tx_threshold;
  483. unsigned int tx_pbl;
  484. unsigned int tx_osp_mode;
  485. /* Rx settings */
  486. unsigned int rx_sf_mode;
  487. unsigned int rx_threshold;
  488. unsigned int rx_pbl;
  489. /* Tx coalescing settings */
  490. unsigned int tx_usecs;
  491. unsigned int tx_frames;
  492. /* Rx coalescing settings */
  493. unsigned int rx_riwt;
  494. unsigned int rx_usecs;
  495. unsigned int rx_frames;
  496. /* Current Rx buffer size */
  497. unsigned int rx_buf_size;
  498. /* Flow control settings */
  499. unsigned int tx_pause;
  500. unsigned int rx_pause;
  501. /* Device interrupt number */
  502. int dev_irq;
  503. unsigned int per_channel_irq;
  504. int channel_irq[XLGMAC_MAX_DMA_CHANNELS];
  505. /* Netdev related settings */
  506. unsigned char mac_addr[ETH_ALEN];
  507. netdev_features_t netdev_features;
  508. struct napi_struct napi;
  509. /* Filtering support */
  510. unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)];
  511. /* Device clocks */
  512. unsigned long sysclk_rate;
  513. /* RSS addressing mutex */
  514. struct mutex rss_mutex;
  515. /* Receive Side Scaling settings */
  516. u8 rss_key[XLGMAC_RSS_HASH_KEY_SIZE];
  517. u32 rss_table[XLGMAC_RSS_MAX_TABLE_SIZE];
  518. u32 rss_options;
  519. int phy_speed;
  520. char drv_name[32];
  521. char drv_ver[32];
  522. };
  523. void xlgmac_init_desc_ops(struct xlgmac_desc_ops *desc_ops);
  524. void xlgmac_init_hw_ops(struct xlgmac_hw_ops *hw_ops);
  525. const struct net_device_ops *xlgmac_get_netdev_ops(void);
  526. const struct ethtool_ops *xlgmac_get_ethtool_ops(void);
  527. void xlgmac_dump_tx_desc(struct xlgmac_pdata *pdata,
  528. struct xlgmac_ring *ring,
  529. unsigned int idx,
  530. unsigned int count,
  531. unsigned int flag);
  532. void xlgmac_dump_rx_desc(struct xlgmac_pdata *pdata,
  533. struct xlgmac_ring *ring,
  534. unsigned int idx);
  535. void xlgmac_print_pkt(struct net_device *netdev,
  536. struct sk_buff *skb, bool tx_rx);
  537. void xlgmac_get_all_hw_features(struct xlgmac_pdata *pdata);
  538. void xlgmac_print_all_hw_features(struct xlgmac_pdata *pdata);
  539. int xlgmac_drv_probe(struct device *dev,
  540. struct xlgmac_resources *res);
  541. int xlgmac_drv_remove(struct device *dev);
  542. /* For debug prints */
  543. #ifdef XLGMAC_DEBUG
  544. #define XLGMAC_PR(fmt, args...) \
  545. pr_alert("[%s,%d]:" fmt, __func__, __LINE__, ## args)
  546. #else
  547. #define XLGMAC_PR(x...) do { } while (0)
  548. #endif
  549. #endif /* __DWC_XLGMAC_H__ */