xref: /linux/drivers/net/ethernet/stmicro/stmmac/stmmac.h (revision 10a708c24a31ae1be1ea23d1c38da2691d1fd65c)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*******************************************************************************
3   Copyright (C) 2007-2009  STMicroelectronics Ltd
4 
5 
6   Author: Giuseppe Cavallaro <peppe.cavallaro@st.com>
7 *******************************************************************************/
8 
9 #ifndef __STMMAC_H__
10 #define __STMMAC_H__
11 
12 #define STMMAC_RESOURCE_NAME   "stmmaceth"
13 #define DRV_MODULE_VERSION	"Jan_2016"
14 
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>
20 #include "common.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>
25 
26 struct stmmac_resources {
27 	void __iomem *addr;
28 	const char *mac;
29 	int wol_irq;
30 	int lpi_irq;
31 	int irq;
32 };
33 
34 struct stmmac_tx_info {
35 	dma_addr_t buf;
36 	bool map_as_page;
37 	unsigned len;
38 	bool last_segment;
39 	bool is_jumbo;
40 };
41 
42 /* Frequently used values are kept adjacent for cache effect */
43 struct stmmac_tx_queue {
44 	u32 tx_count_frames;
45 	struct timer_list txtimer;
46 	u32 queue_index;
47 	struct stmmac_priv *priv_data;
48 	struct dma_extended_desc *dma_etx ____cacheline_aligned_in_smp;
49 	struct dma_desc *dma_tx;
50 	struct sk_buff **tx_skbuff;
51 	struct stmmac_tx_info *tx_skbuff_dma;
52 	unsigned int cur_tx;
53 	unsigned int dirty_tx;
54 	dma_addr_t dma_tx_phy;
55 	u32 tx_tail_addr;
56 	u32 mss;
57 };
58 
59 struct stmmac_rx_buffer {
60 	struct page *page;
61 	dma_addr_t addr;
62 };
63 
64 struct stmmac_rx_queue {
65 	u32 rx_count_frames;
66 	u32 queue_index;
67 	struct page_pool *page_pool;
68 	struct stmmac_rx_buffer *buf_pool;
69 	struct stmmac_priv *priv_data;
70 	struct dma_extended_desc *dma_erx;
71 	struct dma_desc *dma_rx ____cacheline_aligned_in_smp;
72 	unsigned int cur_rx;
73 	unsigned int dirty_rx;
74 	u32 rx_zeroc_thresh;
75 	dma_addr_t dma_rx_phy;
76 	u32 rx_tail_addr;
77 };
78 
79 struct stmmac_channel {
80 	struct napi_struct rx_napi ____cacheline_aligned_in_smp;
81 	struct napi_struct tx_napi ____cacheline_aligned_in_smp;
82 	struct stmmac_priv *priv_data;
83 	u32 index;
84 };
85 
86 struct stmmac_tc_entry {
87 	bool in_use;
88 	bool in_hw;
89 	bool is_last;
90 	bool is_frag;
91 	void *frag_ptr;
92 	unsigned int table_pos;
93 	u32 handle;
94 	u32 prio;
95 	struct {
96 		u32 match_data;
97 		u32 match_en;
98 		u8 af:1;
99 		u8 rf:1;
100 		u8 im:1;
101 		u8 nc:1;
102 		u8 res1:4;
103 		u8 frame_offset;
104 		u8 ok_index;
105 		u8 dma_ch_no;
106 		u32 res2;
107 	} __packed val;
108 };
109 
110 #define STMMAC_PPS_MAX		4
111 struct stmmac_pps_cfg {
112 	bool available;
113 	struct timespec64 start;
114 	struct timespec64 period;
115 };
116 
117 struct stmmac_rss {
118 	int enable;
119 	u8 key[STMMAC_RSS_HASH_KEY_SIZE];
120 	u32 table[STMMAC_RSS_MAX_TABLE_SIZE];
121 };
122 
123 struct stmmac_priv {
124 	/* Frequently used values are kept adjacent for cache effect */
125 	u32 tx_coal_frames;
126 	u32 tx_coal_timer;
127 	u32 rx_coal_frames;
128 
129 	int tx_coalesce;
130 	int hwts_tx_en;
131 	bool tx_path_in_lpi_mode;
132 	bool tso;
133 
134 	unsigned int dma_buf_sz;
135 	unsigned int rx_copybreak;
136 	u32 rx_riwt;
137 	int hwts_rx_en;
138 
139 	void __iomem *ioaddr;
140 	struct net_device *dev;
141 	struct device *device;
142 	struct mac_device_info *hw;
143 	int (*hwif_quirks)(struct stmmac_priv *priv);
144 	struct mutex lock;
145 
146 	/* RX Queue */
147 	struct stmmac_rx_queue rx_queue[MTL_MAX_RX_QUEUES];
148 
149 	/* TX Queue */
150 	struct stmmac_tx_queue tx_queue[MTL_MAX_TX_QUEUES];
151 
152 	/* Generic channel for NAPI */
153 	struct stmmac_channel channel[STMMAC_CH_MAX];
154 
155 	int speed;
156 	unsigned int flow_ctrl;
157 	unsigned int pause;
158 	struct mii_bus *mii;
159 	int mii_irq[PHY_MAX_ADDR];
160 
161 	struct phylink_config phylink_config;
162 	struct phylink *phylink;
163 
164 	struct stmmac_extra_stats xstats ____cacheline_aligned_in_smp;
165 	struct stmmac_safety_stats sstats;
166 	struct plat_stmmacenet_data *plat;
167 	struct dma_features dma_cap;
168 	struct stmmac_counters mmc;
169 	int hw_cap_support;
170 	int synopsys_id;
171 	u32 msg_enable;
172 	int wolopts;
173 	int wol_irq;
174 	int clk_csr;
175 	struct timer_list eee_ctrl_timer;
176 	int lpi_irq;
177 	int eee_enabled;
178 	int eee_active;
179 	int tx_lpi_timer;
180 	unsigned int mode;
181 	unsigned int chain_mode;
182 	int extend_desc;
183 	struct hwtstamp_config tstamp_config;
184 	struct ptp_clock *ptp_clock;
185 	struct ptp_clock_info ptp_clock_ops;
186 	unsigned int default_addend;
187 	u32 sub_second_inc;
188 	u32 systime_flags;
189 	u32 adv_ts;
190 	int use_riwt;
191 	int irq_wake;
192 	spinlock_t ptp_lock;
193 	void __iomem *mmcaddr;
194 	void __iomem *ptpaddr;
195 	unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)];
196 
197 #ifdef CONFIG_DEBUG_FS
198 	struct dentry *dbgfs_dir;
199 #endif
200 
201 	unsigned long state;
202 	struct workqueue_struct *wq;
203 	struct work_struct service_task;
204 
205 	/* TC Handling */
206 	unsigned int tc_entries_max;
207 	unsigned int tc_off_max;
208 	struct stmmac_tc_entry *tc_entries;
209 
210 	/* Pulse Per Second output */
211 	struct stmmac_pps_cfg pps[STMMAC_PPS_MAX];
212 
213 	/* Receive Side Scaling */
214 	struct stmmac_rss rss;
215 };
216 
217 enum stmmac_state {
218 	STMMAC_DOWN,
219 	STMMAC_RESET_REQUESTED,
220 	STMMAC_RESETING,
221 	STMMAC_SERVICE_SCHED,
222 };
223 
224 int stmmac_mdio_unregister(struct net_device *ndev);
225 int stmmac_mdio_register(struct net_device *ndev);
226 int stmmac_mdio_reset(struct mii_bus *mii);
227 void stmmac_set_ethtool_ops(struct net_device *netdev);
228 
229 void stmmac_ptp_register(struct stmmac_priv *priv);
230 void stmmac_ptp_unregister(struct stmmac_priv *priv);
231 int stmmac_resume(struct device *dev);
232 int stmmac_suspend(struct device *dev);
233 int stmmac_dvr_remove(struct device *dev);
234 int stmmac_dvr_probe(struct device *device,
235 		     struct plat_stmmacenet_data *plat_dat,
236 		     struct stmmac_resources *res);
237 void stmmac_disable_eee_mode(struct stmmac_priv *priv);
238 bool stmmac_eee_init(struct stmmac_priv *priv);
239 
240 #if IS_ENABLED(CONFIG_STMMAC_SELFTESTS)
241 void stmmac_selftest_run(struct net_device *dev,
242 			 struct ethtool_test *etest, u64 *buf);
243 void stmmac_selftest_get_strings(struct stmmac_priv *priv, u8 *data);
244 int stmmac_selftest_get_count(struct stmmac_priv *priv);
245 #else
246 static inline void stmmac_selftest_run(struct net_device *dev,
247 				       struct ethtool_test *etest, u64 *buf)
248 {
249 	/* Not enabled */
250 }
251 static inline void stmmac_selftest_get_strings(struct stmmac_priv *priv,
252 					       u8 *data)
253 {
254 	/* Not enabled */
255 }
256 static inline int stmmac_selftest_get_count(struct stmmac_priv *priv)
257 {
258 	return -EOPNOTSUPP;
259 }
260 #endif /* CONFIG_STMMAC_SELFTESTS */
261 
262 #endif /* __STMMAC_H__ */
263