1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*******************************************************************************
3 Copyright (C) 2007-2009 STMicroelectronics Ltd
6 Author: Giuseppe Cavallaro <peppe.cavallaro@st.com>
7 *******************************************************************************/
12 #define STMMAC_RESOURCE_NAME "stmmaceth"
13 #define DRV_MODULE_VERSION "Jan_2016"
15 #include <linux/clk.h>
16 #include <linux/hrtimer.h>
17 #include <linux/if_vlan.h>
18 #include <linux/stmmac.h>
19 #include <linux/phylink.h>
20 #include <linux/pci.h>
22 #include <linux/ptp_clock_kernel.h>
23 #include <linux/net_tstamp.h>
24 #include <linux/reset.h>
25 #include <net/page_pool.h>
27 struct stmmac_resources {
35 int rx_irq[MTL_MAX_RX_QUEUES];
36 int tx_irq[MTL_MAX_TX_QUEUES];
39 enum stmmac_txbuf_type {
41 STMMAC_TXBUF_T_XDP_TX,
42 STMMAC_TXBUF_T_XDP_NDO,
43 STMMAC_TXBUF_T_XSK_TX,
46 struct stmmac_tx_info {
52 enum stmmac_txbuf_type buf_type;
55 #define STMMAC_TBS_AVAIL BIT(0)
56 #define STMMAC_TBS_EN BIT(1)
58 /* Frequently used values are kept adjacent for cache effect */
59 struct stmmac_tx_queue {
62 struct hrtimer txtimer;
64 struct stmmac_priv *priv_data;
65 struct dma_extended_desc *dma_etx ____cacheline_aligned_in_smp;
66 struct dma_edesc *dma_entx;
67 struct dma_desc *dma_tx;
69 struct sk_buff **tx_skbuff;
70 struct xdp_frame **xdpf;
72 struct stmmac_tx_info *tx_skbuff_dma;
73 struct xsk_buff_pool *xsk_pool;
76 unsigned int dirty_tx;
77 dma_addr_t dma_tx_phy;
78 dma_addr_t tx_tail_addr;
82 struct stmmac_rx_buffer {
91 struct page *sec_page;
95 struct stmmac_rx_queue {
98 struct xdp_rxq_info xdp_rxq;
99 struct xsk_buff_pool *xsk_pool;
100 struct page_pool *page_pool;
101 struct stmmac_rx_buffer *buf_pool;
102 struct stmmac_priv *priv_data;
103 struct dma_extended_desc *dma_erx;
104 struct dma_desc *dma_rx ____cacheline_aligned_in_smp;
106 unsigned int dirty_rx;
107 unsigned int buf_alloc_num;
109 dma_addr_t dma_rx_phy;
111 unsigned int state_saved;
119 struct stmmac_channel {
120 struct napi_struct rx_napi ____cacheline_aligned_in_smp;
121 struct napi_struct tx_napi ____cacheline_aligned_in_smp;
122 struct napi_struct rxtx_napi ____cacheline_aligned_in_smp;
123 struct stmmac_priv *priv_data;
128 struct stmmac_tc_entry {
134 unsigned int table_pos;
152 #define STMMAC_PPS_MAX 4
153 struct stmmac_pps_cfg {
155 struct timespec64 start;
156 struct timespec64 period;
161 u8 key[STMMAC_RSS_HASH_KEY_SIZE];
162 u32 table[STMMAC_RSS_MAX_TABLE_SIZE];
165 #define STMMAC_FLOW_ACTION_DROP BIT(0)
166 struct stmmac_flow_entry {
167 unsigned long cookie;
168 unsigned long action;
176 /* Frequently used values are kept adjacent for cache effect */
177 u32 tx_coal_frames[MTL_MAX_TX_QUEUES];
178 u32 tx_coal_timer[MTL_MAX_TX_QUEUES];
179 u32 rx_coal_frames[MTL_MAX_TX_QUEUES];
183 bool tx_path_in_lpi_mode;
189 unsigned int dma_buf_sz;
190 unsigned int rx_copybreak;
191 u32 rx_riwt[MTL_MAX_TX_QUEUES];
194 void __iomem *ioaddr;
195 struct net_device *dev;
196 struct device *device;
197 struct mac_device_info *hw;
198 int (*hwif_quirks)(struct stmmac_priv *priv);
202 struct stmmac_rx_queue rx_queue[MTL_MAX_RX_QUEUES];
203 unsigned int dma_rx_size;
206 struct stmmac_tx_queue tx_queue[MTL_MAX_TX_QUEUES];
207 unsigned int dma_tx_size;
209 /* Generic channel for NAPI */
210 struct stmmac_channel channel[STMMAC_CH_MAX];
213 unsigned int flow_ctrl;
216 int mii_irq[PHY_MAX_ADDR];
218 struct phylink_config phylink_config;
219 struct phylink *phylink;
221 struct stmmac_extra_stats xstats ____cacheline_aligned_in_smp;
222 struct stmmac_safety_stats sstats;
223 struct plat_stmmacenet_data *plat;
224 struct dma_features dma_cap;
225 struct stmmac_counters mmc;
232 struct timer_list eee_ctrl_timer;
239 bool eee_sw_timer_en;
241 unsigned int chain_mode;
243 struct hwtstamp_config tstamp_config;
244 struct ptp_clock *ptp_clock;
245 struct ptp_clock_info ptp_clock_ops;
246 unsigned int default_addend;
253 /* Protects auxiliary snapshot registers from concurrent access. */
254 struct mutex aux_ts_lock;
256 void __iomem *mmcaddr;
257 void __iomem *ptpaddr;
258 unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)];
261 int rx_irq[MTL_MAX_RX_QUEUES];
262 int tx_irq[MTL_MAX_TX_QUEUES];
264 char int_name_mac[IFNAMSIZ + 9];
265 char int_name_wol[IFNAMSIZ + 9];
266 char int_name_lpi[IFNAMSIZ + 9];
267 char int_name_sfty_ce[IFNAMSIZ + 10];
268 char int_name_sfty_ue[IFNAMSIZ + 10];
269 char int_name_rx_irq[MTL_MAX_TX_QUEUES][IFNAMSIZ + 14];
270 char int_name_tx_irq[MTL_MAX_TX_QUEUES][IFNAMSIZ + 18];
272 #ifdef CONFIG_DEBUG_FS
273 struct dentry *dbgfs_dir;
277 struct workqueue_struct *wq;
278 struct work_struct service_task;
280 /* Workqueue for handling FPE hand-shaking */
281 unsigned long fpe_task_state;
282 struct workqueue_struct *fpe_wq;
283 struct work_struct fpe_task;
284 char wq_name[IFNAMSIZ + 4];
287 unsigned int tc_entries_max;
288 unsigned int tc_off_max;
289 struct stmmac_tc_entry *tc_entries;
290 unsigned int flow_entries_max;
291 struct stmmac_flow_entry *flow_entries;
293 /* Pulse Per Second output */
294 struct stmmac_pps_cfg pps[STMMAC_PPS_MAX];
296 /* Receive Side Scaling */
297 struct stmmac_rss rss;
299 /* XDP BPF Program */
300 unsigned long *af_xdp_zc_qps;
301 struct bpf_prog *xdp_prog;
306 STMMAC_RESET_REQUESTED,
308 STMMAC_SERVICE_SCHED,
311 int stmmac_mdio_unregister(struct net_device *ndev);
312 int stmmac_mdio_register(struct net_device *ndev);
313 int stmmac_mdio_reset(struct mii_bus *mii);
314 int stmmac_xpcs_setup(struct mii_bus *mii);
315 void stmmac_set_ethtool_ops(struct net_device *netdev);
317 void stmmac_ptp_register(struct stmmac_priv *priv);
318 void stmmac_ptp_unregister(struct stmmac_priv *priv);
319 int stmmac_open(struct net_device *dev);
320 int stmmac_release(struct net_device *dev);
321 int stmmac_resume(struct device *dev);
322 int stmmac_suspend(struct device *dev);
323 int stmmac_dvr_remove(struct device *dev);
324 int stmmac_dvr_probe(struct device *device,
325 struct plat_stmmacenet_data *plat_dat,
326 struct stmmac_resources *res);
327 void stmmac_disable_eee_mode(struct stmmac_priv *priv);
328 bool stmmac_eee_init(struct stmmac_priv *priv);
329 int stmmac_reinit_queues(struct net_device *dev, u32 rx_cnt, u32 tx_cnt);
330 int stmmac_reinit_ringparam(struct net_device *dev, u32 rx_size, u32 tx_size);
331 int stmmac_bus_clks_config(struct stmmac_priv *priv, bool enabled);
332 void stmmac_fpe_handshake(struct stmmac_priv *priv, bool enable);
334 static inline bool stmmac_xdp_is_enabled(struct stmmac_priv *priv)
336 return !!priv->xdp_prog;
339 static inline unsigned int stmmac_rx_offset(struct stmmac_priv *priv)
341 if (stmmac_xdp_is_enabled(priv))
342 return XDP_PACKET_HEADROOM + NET_IP_ALIGN;
344 return NET_SKB_PAD + NET_IP_ALIGN;
347 void stmmac_disable_rx_queue(struct stmmac_priv *priv, u32 queue);
348 void stmmac_enable_rx_queue(struct stmmac_priv *priv, u32 queue);
349 void stmmac_disable_tx_queue(struct stmmac_priv *priv, u32 queue);
350 void stmmac_enable_tx_queue(struct stmmac_priv *priv, u32 queue);
351 int stmmac_xsk_wakeup(struct net_device *dev, u32 queue, u32 flags);
353 #if IS_ENABLED(CONFIG_STMMAC_SELFTESTS)
354 void stmmac_selftest_run(struct net_device *dev,
355 struct ethtool_test *etest, u64 *buf);
356 void stmmac_selftest_get_strings(struct stmmac_priv *priv, u8 *data);
357 int stmmac_selftest_get_count(struct stmmac_priv *priv);
359 static inline void stmmac_selftest_run(struct net_device *dev,
360 struct ethtool_test *etest, u64 *buf)
364 static inline void stmmac_selftest_get_strings(struct stmmac_priv *priv,
369 static inline int stmmac_selftest_get_count(struct stmmac_priv *priv)
373 #endif /* CONFIG_STMMAC_SELFTESTS */
375 #endif /* __STMMAC_H__ */