dwc-xlgmac.h 19 KB

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