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 struct stmmac_tx_info {
47 #define STMMAC_TBS_AVAIL BIT(0)
48 #define STMMAC_TBS_EN BIT(1)
50 /* Frequently used values are kept adjacent for cache effect */
51 struct stmmac_tx_queue {
54 struct hrtimer txtimer;
56 struct stmmac_priv *priv_data;
57 struct dma_extended_desc *dma_etx ____cacheline_aligned_in_smp;
58 struct dma_edesc *dma_entx;
59 struct dma_desc *dma_tx;
60 struct sk_buff **tx_skbuff;
61 struct stmmac_tx_info *tx_skbuff_dma;
63 unsigned int dirty_tx;
64 dma_addr_t dma_tx_phy;
69 struct stmmac_rx_buffer {
71 struct page *sec_page;
76 struct stmmac_rx_queue {
79 struct page_pool *page_pool;
80 struct stmmac_rx_buffer *buf_pool;
81 struct stmmac_priv *priv_data;
82 struct dma_extended_desc *dma_erx;
83 struct dma_desc *dma_rx ____cacheline_aligned_in_smp;
85 unsigned int dirty_rx;
87 dma_addr_t dma_rx_phy;
89 unsigned int state_saved;
97 struct stmmac_channel {
98 struct napi_struct rx_napi ____cacheline_aligned_in_smp;
99 struct napi_struct tx_napi ____cacheline_aligned_in_smp;
100 struct stmmac_priv *priv_data;
105 struct stmmac_tc_entry {
111 unsigned int table_pos;
129 #define STMMAC_PPS_MAX 4
130 struct stmmac_pps_cfg {
132 struct timespec64 start;
133 struct timespec64 period;
138 u8 key[STMMAC_RSS_HASH_KEY_SIZE];
139 u32 table[STMMAC_RSS_MAX_TABLE_SIZE];
142 #define STMMAC_FLOW_ACTION_DROP BIT(0)
143 struct stmmac_flow_entry {
144 unsigned long cookie;
145 unsigned long action;
153 /* Frequently used values are kept adjacent for cache effect */
154 u32 tx_coal_frames[MTL_MAX_TX_QUEUES];
155 u32 tx_coal_timer[MTL_MAX_TX_QUEUES];
156 u32 rx_coal_frames[MTL_MAX_TX_QUEUES];
160 bool tx_path_in_lpi_mode;
166 unsigned int dma_buf_sz;
167 unsigned int rx_copybreak;
168 u32 rx_riwt[MTL_MAX_TX_QUEUES];
171 void __iomem *ioaddr;
172 struct net_device *dev;
173 struct device *device;
174 struct mac_device_info *hw;
175 int (*hwif_quirks)(struct stmmac_priv *priv);
179 struct stmmac_rx_queue rx_queue[MTL_MAX_RX_QUEUES];
180 unsigned int dma_rx_size;
183 struct stmmac_tx_queue tx_queue[MTL_MAX_TX_QUEUES];
184 unsigned int dma_tx_size;
186 /* Generic channel for NAPI */
187 struct stmmac_channel channel[STMMAC_CH_MAX];
190 unsigned int flow_ctrl;
193 int mii_irq[PHY_MAX_ADDR];
195 struct phylink_config phylink_config;
196 struct phylink *phylink;
198 struct stmmac_extra_stats xstats ____cacheline_aligned_in_smp;
199 struct stmmac_safety_stats sstats;
200 struct plat_stmmacenet_data *plat;
201 struct dma_features dma_cap;
202 struct stmmac_counters mmc;
209 struct timer_list eee_ctrl_timer;
216 bool eee_sw_timer_en;
218 unsigned int chain_mode;
220 struct hwtstamp_config tstamp_config;
221 struct ptp_clock *ptp_clock;
222 struct ptp_clock_info ptp_clock_ops;
223 unsigned int default_addend;
230 void __iomem *mmcaddr;
231 void __iomem *ptpaddr;
232 unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)];
235 int rx_irq[MTL_MAX_RX_QUEUES];
236 int tx_irq[MTL_MAX_TX_QUEUES];
238 char int_name_mac[IFNAMSIZ + 9];
239 char int_name_wol[IFNAMSIZ + 9];
240 char int_name_lpi[IFNAMSIZ + 9];
241 char int_name_sfty_ce[IFNAMSIZ + 10];
242 char int_name_sfty_ue[IFNAMSIZ + 10];
243 char int_name_rx_irq[MTL_MAX_TX_QUEUES][IFNAMSIZ + 14];
244 char int_name_tx_irq[MTL_MAX_TX_QUEUES][IFNAMSIZ + 18];
246 #ifdef CONFIG_DEBUG_FS
247 struct dentry *dbgfs_dir;
251 struct workqueue_struct *wq;
252 struct work_struct service_task;
254 /* Workqueue for handling FPE hand-shaking */
255 unsigned long fpe_task_state;
256 struct workqueue_struct *fpe_wq;
257 struct work_struct fpe_task;
258 char wq_name[IFNAMSIZ + 4];
261 unsigned int tc_entries_max;
262 unsigned int tc_off_max;
263 struct stmmac_tc_entry *tc_entries;
264 unsigned int flow_entries_max;
265 struct stmmac_flow_entry *flow_entries;
267 /* Pulse Per Second output */
268 struct stmmac_pps_cfg pps[STMMAC_PPS_MAX];
270 /* Receive Side Scaling */
271 struct stmmac_rss rss;
276 STMMAC_RESET_REQUESTED,
278 STMMAC_SERVICE_SCHED,
281 int stmmac_mdio_unregister(struct net_device *ndev);
282 int stmmac_mdio_register(struct net_device *ndev);
283 int stmmac_mdio_reset(struct mii_bus *mii);
284 void stmmac_set_ethtool_ops(struct net_device *netdev);
286 void stmmac_ptp_register(struct stmmac_priv *priv);
287 void stmmac_ptp_unregister(struct stmmac_priv *priv);
288 int stmmac_resume(struct device *dev);
289 int stmmac_suspend(struct device *dev);
290 int stmmac_dvr_remove(struct device *dev);
291 int stmmac_dvr_probe(struct device *device,
292 struct plat_stmmacenet_data *plat_dat,
293 struct stmmac_resources *res);
294 void stmmac_disable_eee_mode(struct stmmac_priv *priv);
295 bool stmmac_eee_init(struct stmmac_priv *priv);
296 int stmmac_reinit_queues(struct net_device *dev, u32 rx_cnt, u32 tx_cnt);
297 int stmmac_reinit_ringparam(struct net_device *dev, u32 rx_size, u32 tx_size);
298 int stmmac_bus_clks_config(struct stmmac_priv *priv, bool enabled);
299 void stmmac_fpe_handshake(struct stmmac_priv *priv, bool enable);
301 #if IS_ENABLED(CONFIG_STMMAC_SELFTESTS)
302 void stmmac_selftest_run(struct net_device *dev,
303 struct ethtool_test *etest, u64 *buf);
304 void stmmac_selftest_get_strings(struct stmmac_priv *priv, u8 *data);
305 int stmmac_selftest_get_count(struct stmmac_priv *priv);
307 static inline void stmmac_selftest_run(struct net_device *dev,
308 struct ethtool_test *etest, u64 *buf)
312 static inline void stmmac_selftest_get_strings(struct stmmac_priv *priv,
317 static inline int stmmac_selftest_get_count(struct stmmac_priv *priv)
321 #endif /* CONFIG_STMMAC_SELFTESTS */
323 #endif /* __STMMAC_H__ */