stmmac.h 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*******************************************************************************
  3. Copyright (C) 2007-2009 STMicroelectronics Ltd
  4. Author: Giuseppe Cavallaro <[email protected]>
  5. *******************************************************************************/
  6. #ifndef __STMMAC_H__
  7. #define __STMMAC_H__
  8. #define STMMAC_RESOURCE_NAME "stmmaceth"
  9. #include <linux/clk.h>
  10. #include <linux/hrtimer.h>
  11. #include <linux/if_vlan.h>
  12. #include <linux/stmmac.h>
  13. #include <linux/phylink.h>
  14. #include <linux/pci.h>
  15. #include "common.h"
  16. #include <linux/ptp_clock_kernel.h>
  17. #include <linux/net_tstamp.h>
  18. #include <linux/reset.h>
  19. #include <net/page_pool.h>
  20. #include <uapi/linux/bpf.h>
  21. struct stmmac_resources {
  22. void __iomem *addr;
  23. u8 mac[ETH_ALEN];
  24. int wol_irq;
  25. int lpi_irq;
  26. int irq;
  27. int sfty_ce_irq;
  28. int sfty_ue_irq;
  29. int rx_irq[MTL_MAX_RX_QUEUES];
  30. int tx_irq[MTL_MAX_TX_QUEUES];
  31. };
  32. enum stmmac_txbuf_type {
  33. STMMAC_TXBUF_T_SKB,
  34. STMMAC_TXBUF_T_XDP_TX,
  35. STMMAC_TXBUF_T_XDP_NDO,
  36. STMMAC_TXBUF_T_XSK_TX,
  37. };
  38. struct stmmac_tx_info {
  39. dma_addr_t buf;
  40. bool map_as_page;
  41. unsigned len;
  42. bool last_segment;
  43. bool is_jumbo;
  44. enum stmmac_txbuf_type buf_type;
  45. };
  46. #define STMMAC_TBS_AVAIL BIT(0)
  47. #define STMMAC_TBS_EN BIT(1)
  48. /* Frequently used values are kept adjacent for cache effect */
  49. struct stmmac_tx_queue {
  50. u32 tx_count_frames;
  51. int tbs;
  52. struct hrtimer txtimer;
  53. u32 queue_index;
  54. struct stmmac_priv *priv_data;
  55. struct dma_extended_desc *dma_etx ____cacheline_aligned_in_smp;
  56. struct dma_edesc *dma_entx;
  57. struct dma_desc *dma_tx;
  58. union {
  59. struct sk_buff **tx_skbuff;
  60. struct xdp_frame **xdpf;
  61. };
  62. struct stmmac_tx_info *tx_skbuff_dma;
  63. struct xsk_buff_pool *xsk_pool;
  64. u32 xsk_frames_done;
  65. unsigned int cur_tx;
  66. unsigned int dirty_tx;
  67. dma_addr_t dma_tx_phy;
  68. dma_addr_t tx_tail_addr;
  69. u32 mss;
  70. };
  71. struct stmmac_rx_buffer {
  72. union {
  73. struct {
  74. struct page *page;
  75. dma_addr_t addr;
  76. __u32 page_offset;
  77. };
  78. struct xdp_buff *xdp;
  79. };
  80. struct page *sec_page;
  81. dma_addr_t sec_addr;
  82. };
  83. struct stmmac_rx_queue {
  84. u32 rx_count_frames;
  85. u32 queue_index;
  86. struct xdp_rxq_info xdp_rxq;
  87. struct xsk_buff_pool *xsk_pool;
  88. struct page_pool *page_pool;
  89. struct stmmac_rx_buffer *buf_pool;
  90. struct stmmac_priv *priv_data;
  91. struct dma_extended_desc *dma_erx;
  92. struct dma_desc *dma_rx ____cacheline_aligned_in_smp;
  93. unsigned int cur_rx;
  94. unsigned int dirty_rx;
  95. unsigned int buf_alloc_num;
  96. u32 rx_zeroc_thresh;
  97. dma_addr_t dma_rx_phy;
  98. u32 rx_tail_addr;
  99. unsigned int state_saved;
  100. struct {
  101. struct sk_buff *skb;
  102. unsigned int len;
  103. unsigned int error;
  104. } state;
  105. };
  106. struct stmmac_channel {
  107. struct napi_struct rx_napi ____cacheline_aligned_in_smp;
  108. struct napi_struct tx_napi ____cacheline_aligned_in_smp;
  109. struct napi_struct rxtx_napi ____cacheline_aligned_in_smp;
  110. struct stmmac_priv *priv_data;
  111. spinlock_t lock;
  112. u32 index;
  113. };
  114. struct stmmac_tc_entry {
  115. bool in_use;
  116. bool in_hw;
  117. bool is_last;
  118. bool is_frag;
  119. void *frag_ptr;
  120. unsigned int table_pos;
  121. u32 handle;
  122. u32 prio;
  123. struct {
  124. u32 match_data;
  125. u32 match_en;
  126. u8 af:1;
  127. u8 rf:1;
  128. u8 im:1;
  129. u8 nc:1;
  130. u8 res1:4;
  131. u8 frame_offset;
  132. u8 ok_index;
  133. u8 dma_ch_no;
  134. u32 res2;
  135. } __packed val;
  136. };
  137. #define STMMAC_PPS_MAX 4
  138. struct stmmac_pps_cfg {
  139. bool available;
  140. struct timespec64 start;
  141. struct timespec64 period;
  142. };
  143. struct stmmac_rss {
  144. int enable;
  145. u8 key[STMMAC_RSS_HASH_KEY_SIZE];
  146. u32 table[STMMAC_RSS_MAX_TABLE_SIZE];
  147. };
  148. #define STMMAC_FLOW_ACTION_DROP BIT(0)
  149. struct stmmac_flow_entry {
  150. unsigned long cookie;
  151. unsigned long action;
  152. u8 ip_proto;
  153. int in_use;
  154. int idx;
  155. int is_l4;
  156. };
  157. /* Rx Frame Steering */
  158. enum stmmac_rfs_type {
  159. STMMAC_RFS_T_VLAN,
  160. STMMAC_RFS_T_LLDP,
  161. STMMAC_RFS_T_1588,
  162. STMMAC_RFS_T_MAX,
  163. };
  164. struct stmmac_rfs_entry {
  165. unsigned long cookie;
  166. u16 etype;
  167. int in_use;
  168. int type;
  169. int tc;
  170. };
  171. struct stmmac_dma_conf {
  172. unsigned int dma_buf_sz;
  173. /* RX Queue */
  174. struct stmmac_rx_queue rx_queue[MTL_MAX_RX_QUEUES];
  175. unsigned int dma_rx_size;
  176. /* TX Queue */
  177. struct stmmac_tx_queue tx_queue[MTL_MAX_TX_QUEUES];
  178. unsigned int dma_tx_size;
  179. };
  180. struct stmmac_priv {
  181. /* Frequently used values are kept adjacent for cache effect */
  182. u32 tx_coal_frames[MTL_MAX_TX_QUEUES];
  183. u32 tx_coal_timer[MTL_MAX_TX_QUEUES];
  184. u32 rx_coal_frames[MTL_MAX_TX_QUEUES];
  185. bool tx_coal_timer_disable;
  186. int hwts_tx_en;
  187. bool tx_path_in_lpi_mode;
  188. bool tso;
  189. int sph;
  190. int sph_cap;
  191. u32 sarc_type;
  192. unsigned int rx_copybreak;
  193. u32 rx_riwt[MTL_MAX_TX_QUEUES];
  194. int hwts_rx_en;
  195. void __iomem *ioaddr;
  196. struct net_device *dev;
  197. struct device *device;
  198. struct mac_device_info *hw;
  199. int (*hwif_quirks)(struct stmmac_priv *priv);
  200. struct mutex lock;
  201. struct phy_device *phydev;
  202. struct stmmac_dma_conf dma_conf;
  203. /* Generic channel for NAPI */
  204. struct stmmac_channel channel[STMMAC_CH_MAX];
  205. int speed;
  206. unsigned int flow_ctrl;
  207. unsigned int pause;
  208. struct mii_bus *mii;
  209. struct phylink_config phylink_config;
  210. struct phylink *phylink;
  211. struct stmmac_extra_stats xstats ____cacheline_aligned_in_smp;
  212. struct stmmac_safety_stats sstats;
  213. struct plat_stmmacenet_data *plat;
  214. struct dma_features dma_cap;
  215. struct stmmac_counters mmc;
  216. int hw_cap_support;
  217. int synopsys_id;
  218. u32 msg_enable;
  219. int wolopts;
  220. int wol_irq;
  221. int clk_csr;
  222. struct timer_list eee_ctrl_timer;
  223. int lpi_irq;
  224. int eee_enabled;
  225. int eee_active;
  226. int tx_lpi_timer;
  227. int tx_lpi_enabled;
  228. int eee_tw_timer;
  229. bool eee_sw_timer_en;
  230. unsigned int mode;
  231. unsigned int chain_mode;
  232. int extend_desc;
  233. struct hwtstamp_config tstamp_config;
  234. struct ptp_clock *ptp_clock;
  235. struct ptp_clock_info ptp_clock_ops;
  236. unsigned int default_addend;
  237. u32 sub_second_inc;
  238. u32 systime_flags;
  239. u32 adv_ts;
  240. int use_riwt;
  241. int irq_wake;
  242. rwlock_t ptp_lock;
  243. /* Protects auxiliary snapshot registers from concurrent access. */
  244. struct mutex aux_ts_lock;
  245. wait_queue_head_t tstamp_busy_wait;
  246. void __iomem *mmcaddr;
  247. void __iomem *ptpaddr;
  248. unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)];
  249. int sfty_ce_irq;
  250. int sfty_ue_irq;
  251. int rx_irq[MTL_MAX_RX_QUEUES];
  252. int tx_irq[MTL_MAX_TX_QUEUES];
  253. /*irq name */
  254. char int_name_mac[IFNAMSIZ + 9];
  255. char int_name_wol[IFNAMSIZ + 9];
  256. char int_name_lpi[IFNAMSIZ + 9];
  257. char int_name_sfty_ce[IFNAMSIZ + 10];
  258. char int_name_sfty_ue[IFNAMSIZ + 10];
  259. char int_name_rx_irq[MTL_MAX_TX_QUEUES][IFNAMSIZ + 14];
  260. char int_name_tx_irq[MTL_MAX_TX_QUEUES][IFNAMSIZ + 18];
  261. #ifdef CONFIG_DEBUG_FS
  262. struct dentry *dbgfs_dir;
  263. #endif
  264. unsigned long state;
  265. struct workqueue_struct *wq;
  266. struct work_struct service_task;
  267. /* Workqueue for handling FPE hand-shaking */
  268. unsigned long fpe_task_state;
  269. struct workqueue_struct *fpe_wq;
  270. struct work_struct fpe_task;
  271. char wq_name[IFNAMSIZ + 4];
  272. /* TC Handling */
  273. unsigned int tc_entries_max;
  274. unsigned int tc_off_max;
  275. struct stmmac_tc_entry *tc_entries;
  276. unsigned int flow_entries_max;
  277. struct stmmac_flow_entry *flow_entries;
  278. unsigned int rfs_entries_max[STMMAC_RFS_T_MAX];
  279. unsigned int rfs_entries_cnt[STMMAC_RFS_T_MAX];
  280. unsigned int rfs_entries_total;
  281. struct stmmac_rfs_entry *rfs_entries;
  282. /* Pulse Per Second output */
  283. struct stmmac_pps_cfg pps[STMMAC_PPS_MAX];
  284. /* Receive Side Scaling */
  285. struct stmmac_rss rss;
  286. /* XDP BPF Program */
  287. unsigned long *af_xdp_zc_qps;
  288. struct bpf_prog *xdp_prog;
  289. bool phy_irq_enabled;
  290. bool boot_kpi;
  291. bool early_eth;
  292. bool early_eth_config_set;
  293. };
  294. enum stmmac_state {
  295. STMMAC_DOWN,
  296. STMMAC_RESET_REQUESTED,
  297. STMMAC_RESETING,
  298. STMMAC_SERVICE_SCHED,
  299. };
  300. #define GET_MEM_PDEV_DEV (priv->plat->stmmac_emb_smmu_ctx.valid ? \
  301. &priv->plat->stmmac_emb_smmu_ctx.smmu_pdev->dev : priv->device)
  302. int stmmac_mdio_unregister(struct net_device *ndev);
  303. int stmmac_mdio_register(struct net_device *ndev);
  304. int stmmac_mdio_reset(struct mii_bus *mii);
  305. int stmmac_xpcs_setup(struct mii_bus *mii);
  306. void stmmac_set_ethtool_ops(struct net_device *netdev);
  307. int stmmac_init_tstamp_counter(struct stmmac_priv *priv, u32 systime_flags);
  308. void stmmac_ptp_register(struct stmmac_priv *priv);
  309. void stmmac_ptp_unregister(struct stmmac_priv *priv);
  310. int stmmac_xdp_open(struct net_device *dev);
  311. void stmmac_xdp_release(struct net_device *dev);
  312. int stmmac_resume(struct device *dev);
  313. int stmmac_suspend(struct device *dev);
  314. int stmmac_dvr_remove(struct device *dev);
  315. int stmmac_dvr_probe(struct device *device,
  316. struct plat_stmmacenet_data *plat_dat,
  317. struct stmmac_resources *res);
  318. void stmmac_disable_eee_mode(struct stmmac_priv *priv);
  319. bool stmmac_eee_init(struct stmmac_priv *priv);
  320. int stmmac_reinit_queues(struct net_device *dev, u32 rx_cnt, u32 tx_cnt);
  321. int stmmac_reinit_ringparam(struct net_device *dev, u32 rx_size, u32 tx_size);
  322. int stmmac_bus_clks_config(struct stmmac_priv *priv, bool enabled);
  323. void stmmac_fpe_handshake(struct stmmac_priv *priv, bool enable);
  324. static inline bool stmmac_xdp_is_enabled(struct stmmac_priv *priv)
  325. {
  326. return !!priv->xdp_prog;
  327. }
  328. static inline unsigned int stmmac_rx_offset(struct stmmac_priv *priv)
  329. {
  330. if (stmmac_xdp_is_enabled(priv))
  331. return XDP_PACKET_HEADROOM;
  332. return 0;
  333. }
  334. void stmmac_disable_rx_queue(struct stmmac_priv *priv, u32 queue);
  335. void stmmac_enable_rx_queue(struct stmmac_priv *priv, u32 queue);
  336. void stmmac_disable_tx_queue(struct stmmac_priv *priv, u32 queue);
  337. void stmmac_enable_tx_queue(struct stmmac_priv *priv, u32 queue);
  338. int stmmac_xsk_wakeup(struct net_device *dev, u32 queue, u32 flags);
  339. struct timespec64 stmmac_calc_tas_basetime(ktime_t old_base_time,
  340. ktime_t current_time,
  341. u64 cycle_time);
  342. #if IS_ENABLED(CONFIG_STMMAC_SELFTESTS)
  343. void stmmac_selftest_run(struct net_device *dev,
  344. struct ethtool_test *etest, u64 *buf);
  345. void stmmac_selftest_get_strings(struct stmmac_priv *priv, u8 *data);
  346. int stmmac_selftest_get_count(struct stmmac_priv *priv);
  347. #else
  348. static inline void stmmac_selftest_run(struct net_device *dev,
  349. struct ethtool_test *etest, u64 *buf)
  350. {
  351. /* Not enabled */
  352. }
  353. static inline void stmmac_selftest_get_strings(struct stmmac_priv *priv,
  354. u8 *data)
  355. {
  356. /* Not enabled */
  357. }
  358. static inline int stmmac_selftest_get_count(struct stmmac_priv *priv)
  359. {
  360. return -EOPNOTSUPP;
  361. }
  362. #endif /* CONFIG_STMMAC_SELFTESTS */
  363. #endif /* __STMMAC_H__ */