stmmac.h 11 KB

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