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/if_vlan.h>
17 #include <linux/stmmac.h>
18 #include <linux/phylink.h>
19 #include <linux/pci.h>
21 #include <linux/ptp_clock_kernel.h>
22 #include <linux/net_tstamp.h>
23 #include <linux/reset.h>
24 #include <net/page_pool.h>
26 struct stmmac_resources {
34 struct stmmac_tx_info {
42 #define STMMAC_TBS_AVAIL BIT(0)
43 #define STMMAC_TBS_EN BIT(1)
45 /* Frequently used values are kept adjacent for cache effect */
46 struct stmmac_tx_queue {
49 struct timer_list txtimer;
51 struct stmmac_priv *priv_data;
52 struct dma_extended_desc *dma_etx ____cacheline_aligned_in_smp;
53 struct dma_edesc *dma_entx;
54 struct dma_desc *dma_tx;
55 struct sk_buff **tx_skbuff;
56 struct stmmac_tx_info *tx_skbuff_dma;
58 unsigned int dirty_tx;
59 dma_addr_t dma_tx_phy;
64 struct stmmac_rx_buffer {
66 struct page *sec_page;
71 struct stmmac_rx_queue {
74 struct page_pool *page_pool;
75 struct stmmac_rx_buffer *buf_pool;
76 struct stmmac_priv *priv_data;
77 struct dma_extended_desc *dma_erx;
78 struct dma_desc *dma_rx ____cacheline_aligned_in_smp;
80 unsigned int dirty_rx;
82 dma_addr_t dma_rx_phy;
84 unsigned int state_saved;
92 struct stmmac_channel {
93 struct napi_struct rx_napi ____cacheline_aligned_in_smp;
94 struct napi_struct tx_napi ____cacheline_aligned_in_smp;
95 struct stmmac_priv *priv_data;
100 struct stmmac_tc_entry {
106 unsigned int table_pos;
124 #define STMMAC_PPS_MAX 4
125 struct stmmac_pps_cfg {
127 struct timespec64 start;
128 struct timespec64 period;
133 u8 key[STMMAC_RSS_HASH_KEY_SIZE];
134 u32 table[STMMAC_RSS_MAX_TABLE_SIZE];
137 #define STMMAC_FLOW_ACTION_DROP BIT(0)
138 struct stmmac_flow_entry {
139 unsigned long cookie;
140 unsigned long action;
148 /* Frequently used values are kept adjacent for cache effect */
155 bool tx_path_in_lpi_mode;
160 unsigned int dma_buf_sz;
161 unsigned int rx_copybreak;
165 void __iomem *ioaddr;
166 struct net_device *dev;
167 struct device *device;
168 struct mac_device_info *hw;
169 int (*hwif_quirks)(struct stmmac_priv *priv);
173 struct stmmac_rx_queue rx_queue[MTL_MAX_RX_QUEUES];
174 unsigned int dma_rx_size;
177 struct stmmac_tx_queue tx_queue[MTL_MAX_TX_QUEUES];
178 unsigned int dma_tx_size;
180 /* Generic channel for NAPI */
181 struct stmmac_channel channel[STMMAC_CH_MAX];
184 unsigned int flow_ctrl;
187 int mii_irq[PHY_MAX_ADDR];
189 struct phylink_config phylink_config;
190 struct phylink *phylink;
192 struct stmmac_extra_stats xstats ____cacheline_aligned_in_smp;
193 struct stmmac_safety_stats sstats;
194 struct plat_stmmacenet_data *plat;
195 struct dma_features dma_cap;
196 struct stmmac_counters mmc;
203 struct timer_list eee_ctrl_timer;
211 unsigned int chain_mode;
213 struct hwtstamp_config tstamp_config;
214 struct ptp_clock *ptp_clock;
215 struct ptp_clock_info ptp_clock_ops;
216 unsigned int default_addend;
223 void __iomem *mmcaddr;
224 void __iomem *ptpaddr;
225 unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)];
227 #ifdef CONFIG_DEBUG_FS
228 struct dentry *dbgfs_dir;
232 struct workqueue_struct *wq;
233 struct work_struct service_task;
236 unsigned int tc_entries_max;
237 unsigned int tc_off_max;
238 struct stmmac_tc_entry *tc_entries;
239 unsigned int flow_entries_max;
240 struct stmmac_flow_entry *flow_entries;
242 /* Pulse Per Second output */
243 struct stmmac_pps_cfg pps[STMMAC_PPS_MAX];
245 /* Receive Side Scaling */
246 struct stmmac_rss rss;
251 STMMAC_RESET_REQUESTED,
253 STMMAC_SERVICE_SCHED,
256 int stmmac_mdio_unregister(struct net_device *ndev);
257 int stmmac_mdio_register(struct net_device *ndev);
258 int stmmac_mdio_reset(struct mii_bus *mii);
259 void stmmac_set_ethtool_ops(struct net_device *netdev);
261 int stmmac_init_tstamp_counter(struct stmmac_priv *priv, u32 systime_flags);
262 void stmmac_ptp_register(struct stmmac_priv *priv);
263 void stmmac_ptp_unregister(struct stmmac_priv *priv);
264 int stmmac_resume(struct device *dev);
265 int stmmac_suspend(struct device *dev);
266 int stmmac_dvr_remove(struct device *dev);
267 int stmmac_dvr_probe(struct device *device,
268 struct plat_stmmacenet_data *plat_dat,
269 struct stmmac_resources *res);
270 void stmmac_disable_eee_mode(struct stmmac_priv *priv);
271 bool stmmac_eee_init(struct stmmac_priv *priv);
272 int stmmac_reinit_queues(struct net_device *dev, u32 rx_cnt, u32 tx_cnt);
273 int stmmac_reinit_ringparam(struct net_device *dev, u32 rx_size, u32 tx_size);
274 int stmmac_bus_clks_config(struct stmmac_priv *priv, bool enabled);
276 #if IS_ENABLED(CONFIG_STMMAC_SELFTESTS)
277 void stmmac_selftest_run(struct net_device *dev,
278 struct ethtool_test *etest, u64 *buf);
279 void stmmac_selftest_get_strings(struct stmmac_priv *priv, u8 *data);
280 int stmmac_selftest_get_count(struct stmmac_priv *priv);
282 static inline void stmmac_selftest_run(struct net_device *dev,
283 struct ethtool_test *etest, u64 *buf)
287 static inline void stmmac_selftest_get_strings(struct stmmac_priv *priv,
292 static inline int stmmac_selftest_get_count(struct stmmac_priv *priv)
296 #endif /* CONFIG_STMMAC_SELFTESTS */
298 #endif /* __STMMAC_H__ */