]> git.ipfire.org Git - thirdparty/kernel/stable.git/blame - drivers/net/ethernet/stmicro/stmmac/stmmac.h
Merge tag 'kvm-x86-docs-6.7' of https://github.com/kvm-x86/linux into HEAD
[thirdparty/kernel/stable.git] / drivers / net / ethernet / stmicro / stmmac / stmmac.h
CommitLineData
4fa9c49f 1/* SPDX-License-Identifier: GPL-2.0-only */
47dd7a54
GC
2/*******************************************************************************
3 Copyright (C) 2007-2009 STMicroelectronics Ltd
4
47dd7a54
GC
5
6 Author: Giuseppe Cavallaro <peppe.cavallaro@st.com>
7*******************************************************************************/
8
bd4242df
RK
9#ifndef __STMMAC_H__
10#define __STMMAC_H__
11
bfab27a1 12#define STMMAC_RESOURCE_NAME "stmmaceth"
ba1377ff
GC
13
14#include <linux/clk.h>
d5a05e69 15#include <linux/hrtimer.h>
3cd1cfcb 16#include <linux/if_vlan.h>
ee7946a7 17#include <linux/stmmac.h>
eeef2f6b 18#include <linux/phylink.h>
33d5e332 19#include <linux/pci.h>
47dd7a54 20#include "common.h"
92ba6888 21#include <linux/ptp_clock_kernel.h>
d6228b7c 22#include <linux/net_tstamp.h>
c5e4ddbd 23#include <linux/reset.h>
a9ca9f9c 24#include <net/page_pool/types.h>
92272ec4 25#include <net/xdp.h>
3b80b73a 26#include <uapi/linux/bpf.h>
47dd7a54 27
e56788cf
JE
28struct stmmac_resources {
29 void __iomem *addr;
83216e39 30 u8 mac[ETH_ALEN];
e56788cf
JE
31 int wol_irq;
32 int lpi_irq;
33 int irq;
8532f613
OBL
34 int sfty_ce_irq;
35 int sfty_ue_irq;
36 int rx_irq[MTL_MAX_RX_QUEUES];
37 int tx_irq[MTL_MAX_TX_QUEUES];
e56788cf
JE
38};
39
be8b38a7
OBL
40enum stmmac_txbuf_type {
41 STMMAC_TXBUF_T_SKB,
42 STMMAC_TXBUF_T_XDP_TX,
8b278a5b 43 STMMAC_TXBUF_T_XDP_NDO,
132c32ee 44 STMMAC_TXBUF_T_XSK_TX,
be8b38a7
OBL
45};
46
362b37be
GC
47struct stmmac_tx_info {
48 dma_addr_t buf;
49 bool map_as_page;
553e2ab3 50 unsigned len;
2a6d8e17 51 bool last_segment;
96951366 52 bool is_jumbo;
be8b38a7 53 enum stmmac_txbuf_type buf_type;
362b37be
GC
54};
55
579a25a8
JA
56#define STMMAC_TBS_AVAIL BIT(0)
57#define STMMAC_TBS_EN BIT(1)
58
ce736788
JP
59/* Frequently used values are kept adjacent for cache effect */
60struct stmmac_tx_queue {
8fce3331 61 u32 tx_count_frames;
579a25a8 62 int tbs;
d5a05e69 63 struct hrtimer txtimer;
ce736788
JP
64 u32 queue_index;
65 struct stmmac_priv *priv_data;
66 struct dma_extended_desc *dma_etx ____cacheline_aligned_in_smp;
579a25a8 67 struct dma_edesc *dma_entx;
ce736788 68 struct dma_desc *dma_tx;
be8b38a7
OBL
69 union {
70 struct sk_buff **tx_skbuff;
71 struct xdp_frame **xdpf;
72 };
ce736788 73 struct stmmac_tx_info *tx_skbuff_dma;
132c32ee
OBL
74 struct xsk_buff_pool *xsk_pool;
75 u32 xsk_frames_done;
ce736788
JP
76 unsigned int cur_tx;
77 unsigned int dirty_tx;
78 dma_addr_t dma_tx_phy;
52e597d3 79 dma_addr_t tx_tail_addr;
8d212a9e 80 u32 mss;
ce736788
JP
81};
82
2af6106a 83struct stmmac_rx_buffer {
bba2556e
OBL
84 union {
85 struct {
86 struct page *page;
87 dma_addr_t addr;
88 __u32 page_offset;
89 };
90 struct xdp_buff *xdp;
91 };
5fabb012 92 struct page *sec_page;
67afd6d1 93 dma_addr_t sec_addr;
2af6106a
JA
94};
95
5b24324a
SYS
96struct stmmac_xdp_buff {
97 struct xdp_buff xdp;
e3f9c3e3
SYS
98 struct stmmac_priv *priv;
99 struct dma_desc *desc;
100 struct dma_desc *ndesc;
5b24324a
SYS
101};
102
54139cf3 103struct stmmac_rx_queue {
d429b66e 104 u32 rx_count_frames;
54139cf3 105 u32 queue_index;
be8b38a7 106 struct xdp_rxq_info xdp_rxq;
bba2556e 107 struct xsk_buff_pool *xsk_pool;
2af6106a
JA
108 struct page_pool *page_pool;
109 struct stmmac_rx_buffer *buf_pool;
54139cf3
JP
110 struct stmmac_priv *priv_data;
111 struct dma_extended_desc *dma_erx;
112 struct dma_desc *dma_rx ____cacheline_aligned_in_smp;
54139cf3
JP
113 unsigned int cur_rx;
114 unsigned int dirty_rx;
bba2556e 115 unsigned int buf_alloc_num;
54139cf3
JP
116 u32 rx_zeroc_thresh;
117 dma_addr_t dma_rx_phy;
118 u32 rx_tail_addr;
ec222003
JA
119 unsigned int state_saved;
120 struct {
121 struct sk_buff *skb;
122 unsigned int len;
123 unsigned int error;
124 } state;
8fce3331
JA
125};
126
127struct stmmac_channel {
4ccb4585
JA
128 struct napi_struct rx_napi ____cacheline_aligned_in_smp;
129 struct napi_struct tx_napi ____cacheline_aligned_in_smp;
132c32ee 130 struct napi_struct rxtx_napi ____cacheline_aligned_in_smp;
8fce3331 131 struct stmmac_priv *priv_data;
021bd5e3 132 spinlock_t lock;
8fce3331 133 u32 index;
54139cf3
JP
134};
135
4dbbe8dd
JA
136struct stmmac_tc_entry {
137 bool in_use;
138 bool in_hw;
139 bool is_last;
140 bool is_frag;
141 void *frag_ptr;
142 unsigned int table_pos;
143 u32 handle;
144 u32 prio;
145 struct {
146 u32 match_data;
147 u32 match_en;
148 u8 af:1;
149 u8 rf:1;
150 u8 im:1;
151 u8 nc:1;
152 u8 res1:4;
153 u8 frame_offset;
154 u8 ok_index;
155 u8 dma_ch_no;
156 u32 res2;
157 } __packed val;
158};
159
9a8a02c9
JA
160#define STMMAC_PPS_MAX 4
161struct stmmac_pps_cfg {
162 bool available;
163 struct timespec64 start;
164 struct timespec64 period;
165};
166
76067459
JA
167struct stmmac_rss {
168 int enable;
169 u8 key[STMMAC_RSS_HASH_KEY_SIZE];
170 u32 table[STMMAC_RSS_MAX_TABLE_SIZE];
171};
172
425eabdd
JA
173#define STMMAC_FLOW_ACTION_DROP BIT(0)
174struct stmmac_flow_entry {
175 unsigned long cookie;
176 unsigned long action;
177 u8 ip_proto;
178 int in_use;
179 int idx;
180 int is_l4;
181};
182
aeb7c75c
OBL
183/* Rx Frame Steering */
184enum stmmac_rfs_type {
185 STMMAC_RFS_T_VLAN,
e48cb313
OBL
186 STMMAC_RFS_T_LLDP,
187 STMMAC_RFS_T_1588,
aeb7c75c
OBL
188 STMMAC_RFS_T_MAX,
189};
190
191struct stmmac_rfs_entry {
192 unsigned long cookie;
e48cb313 193 u16 etype;
aeb7c75c
OBL
194 int in_use;
195 int type;
196 int tc;
197};
198
8531c808
CM
199struct stmmac_dma_conf {
200 unsigned int dma_buf_sz;
201
202 /* RX Queue */
203 struct stmmac_rx_queue rx_queue[MTL_MAX_RX_QUEUES];
204 unsigned int dma_rx_size;
205
206 /* TX Queue */
207 struct stmmac_tx_queue tx_queue[MTL_MAX_TX_QUEUES];
208 unsigned int dma_tx_size;
209};
210
47dd7a54
GC
211struct stmmac_priv {
212 /* Frequently used values are kept adjacent for cache effect */
db2f2842
OBL
213 u32 tx_coal_frames[MTL_MAX_TX_QUEUES];
214 u32 tx_coal_timer[MTL_MAX_TX_QUEUES];
215 u32 rx_coal_frames[MTL_MAX_TX_QUEUES];
ce736788 216
1bb6dea8 217 int hwts_tx_en;
1bb6dea8 218 bool tx_path_in_lpi_mode;
f748be53 219 bool tso;
67afd6d1 220 int sph;
d08d32d1 221 int sph_cap;
8000ddc0 222 u32 sarc_type;
47dd7a54 223
22ad3838 224 unsigned int rx_copybreak;
db2f2842 225 u32 rx_riwt[MTL_MAX_TX_QUEUES];
1bb6dea8 226 int hwts_rx_en;
5bacd778 227
1bb6dea8 228 void __iomem *ioaddr;
47dd7a54 229 struct net_device *dev;
47dd7a54 230 struct device *device;
db98a0b0 231 struct mac_device_info *hw;
7cfde0af 232 int (*hwif_quirks)(struct stmmac_priv *priv);
29555fa3 233 struct mutex lock;
47dd7a54 234
8531c808 235 struct stmmac_dma_conf dma_conf;
ce736788 236
8fce3331
JA
237 /* Generic channel for NAPI */
238 struct stmmac_channel channel[STMMAC_CH_MAX];
239
47dd7a54 240 int speed;
47dd7a54
GC
241 unsigned int flow_ctrl;
242 unsigned int pause;
243 struct mii_bus *mii;
244
eeef2f6b
JA
245 struct phylink_config phylink_config;
246 struct phylink *phylink;
247
1bb6dea8 248 struct stmmac_extra_stats xstats ____cacheline_aligned_in_smp;
8bf993a5 249 struct stmmac_safety_stats sstats;
9dfeb4d9 250 struct plat_stmmacenet_data *plat;
e7434821 251 struct dma_features dma_cap;
1bb6dea8 252 struct stmmac_counters mmc;
19e30c14 253 int hw_cap_support;
1bb6dea8
GC
254 int synopsys_id;
255 u32 msg_enable;
256 int wolopts;
257 int wol_irq;
cd7201f4 258 int clk_csr;
d765955d 259 struct timer_list eee_ctrl_timer;
d765955d
GC
260 int lpi_irq;
261 int eee_enabled;
262 int eee_active;
263 int tx_lpi_timer;
388e201d
VJK
264 int tx_lpi_enabled;
265 int eee_tw_timer;
be1c7eae 266 bool eee_sw_timer_en;
4a7d666a 267 unsigned int mode;
5f0456b4 268 unsigned int chain_mode;
c24602ef 269 int extend_desc;
d6228b7c 270 struct hwtstamp_config tstamp_config;
92ba6888
RK
271 struct ptp_clock *ptp_clock;
272 struct ptp_clock_info ptp_clock_ops;
1bb6dea8 273 unsigned int default_addend;
9a8a02c9
JA
274 u32 sub_second_inc;
275 u32 systime_flags;
1bb6dea8
GC
276 u32 adv_ts;
277 int use_riwt;
89f7f2cf 278 int irq_wake;
642436a1 279 rwlock_t ptp_lock;
f4da5652
TTM
280 /* Protects auxiliary snapshot registers from concurrent access. */
281 struct mutex aux_ts_lock;
76c16d3e 282 wait_queue_head_t tstamp_busy_wait;
f4da5652 283
36ff7c1e 284 void __iomem *mmcaddr;
ba1ffd74 285 void __iomem *ptpaddr;
3cd1cfcb 286 unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)];
8532f613
OBL
287 int sfty_ce_irq;
288 int sfty_ue_irq;
289 int rx_irq[MTL_MAX_RX_QUEUES];
290 int tx_irq[MTL_MAX_TX_QUEUES];
291 /*irq name */
292 char int_name_mac[IFNAMSIZ + 9];
293 char int_name_wol[IFNAMSIZ + 9];
294 char int_name_lpi[IFNAMSIZ + 9];
295 char int_name_sfty_ce[IFNAMSIZ + 10];
296 char int_name_sfty_ue[IFNAMSIZ + 10];
297 char int_name_rx_irq[MTL_MAX_TX_QUEUES][IFNAMSIZ + 14];
298 char int_name_tx_irq[MTL_MAX_TX_QUEUES][IFNAMSIZ + 18];
466c5ac8
MO
299
300#ifdef CONFIG_DEBUG_FS
301 struct dentry *dbgfs_dir;
466c5ac8 302#endif
34877a15
JA
303
304 unsigned long state;
305 struct workqueue_struct *wq;
306 struct work_struct service_task;
4dbbe8dd 307
5a558611
OBL
308 /* Workqueue for handling FPE hand-shaking */
309 unsigned long fpe_task_state;
310 struct workqueue_struct *fpe_wq;
311 struct work_struct fpe_task;
312 char wq_name[IFNAMSIZ + 4];
313
4dbbe8dd
JA
314 /* TC Handling */
315 unsigned int tc_entries_max;
316 unsigned int tc_off_max;
317 struct stmmac_tc_entry *tc_entries;
425eabdd
JA
318 unsigned int flow_entries_max;
319 struct stmmac_flow_entry *flow_entries;
aeb7c75c
OBL
320 unsigned int rfs_entries_max[STMMAC_RFS_T_MAX];
321 unsigned int rfs_entries_cnt[STMMAC_RFS_T_MAX];
322 unsigned int rfs_entries_total;
323 struct stmmac_rfs_entry *rfs_entries;
9a8a02c9
JA
324
325 /* Pulse Per Second output */
326 struct stmmac_pps_cfg pps[STMMAC_PPS_MAX];
76067459
JA
327
328 /* Receive Side Scaling */
329 struct stmmac_rss rss;
5fabb012
OBL
330
331 /* XDP BPF Program */
bba2556e 332 unsigned long *af_xdp_zc_qps;
5fabb012 333 struct bpf_prog *xdp_prog;
34877a15
JA
334};
335
336enum stmmac_state {
337 STMMAC_DOWN,
338 STMMAC_RESET_REQUESTED,
339 STMMAC_RESETING,
340 STMMAC_SERVICE_SCHED,
47dd7a54
GC
341};
342
d6cc64ef
JP
343int stmmac_mdio_unregister(struct net_device *ndev);
344int stmmac_mdio_register(struct net_device *ndev);
073752aa 345int stmmac_mdio_reset(struct mii_bus *mii);
597a68ce 346int stmmac_xpcs_setup(struct mii_bus *mii);
d6cc64ef 347void stmmac_set_ethtool_ops(struct net_device *netdev);
915af656 348
a6da2bbb 349int stmmac_init_tstamp_counter(struct stmmac_priv *priv, u32 systime_flags);
c30a70d3 350void stmmac_ptp_register(struct stmmac_priv *priv);
d6cc64ef 351void stmmac_ptp_unregister(struct stmmac_priv *priv);
ac746c85
OBL
352int stmmac_xdp_open(struct net_device *dev);
353void stmmac_xdp_release(struct net_device *dev);
f4e7bd81
JE
354int stmmac_resume(struct device *dev);
355int stmmac_suspend(struct device *dev);
ff0011cf 356void stmmac_dvr_remove(struct device *dev);
15ffac73
JE
357int stmmac_dvr_probe(struct device *device,
358 struct plat_stmmacenet_data *plat_dat,
359 struct stmmac_resources *res);
d765955d
GC
360void stmmac_disable_eee_mode(struct stmmac_priv *priv);
361bool stmmac_eee_init(struct stmmac_priv *priv);
0366f7e0 362int stmmac_reinit_queues(struct net_device *dev, u32 rx_cnt, u32 tx_cnt);
aa042f60 363int stmmac_reinit_ringparam(struct net_device *dev, u32 rx_size, u32 tx_size);
5ec55823 364int stmmac_bus_clks_config(struct stmmac_priv *priv, bool enabled);
5a558611 365void stmmac_fpe_handshake(struct stmmac_priv *priv, bool enable);
ba1377ff 366
5fabb012
OBL
367static inline bool stmmac_xdp_is_enabled(struct stmmac_priv *priv)
368{
369 return !!priv->xdp_prog;
370}
371
372static inline unsigned int stmmac_rx_offset(struct stmmac_priv *priv)
373{
374 if (stmmac_xdp_is_enabled(priv))
12d125b4 375 return XDP_PACKET_HEADROOM;
5fabb012 376
12d125b4 377 return 0;
5fabb012
OBL
378}
379
bba2556e
OBL
380void stmmac_disable_rx_queue(struct stmmac_priv *priv, u32 queue);
381void stmmac_enable_rx_queue(struct stmmac_priv *priv, u32 queue);
132c32ee
OBL
382void stmmac_disable_tx_queue(struct stmmac_priv *priv, u32 queue);
383void stmmac_enable_tx_queue(struct stmmac_priv *priv, u32 queue);
bba2556e 384int stmmac_xsk_wakeup(struct net_device *dev, u32 queue, u32 flags);
81c52c42
XY
385struct timespec64 stmmac_calc_tas_basetime(ktime_t old_base_time,
386 ktime_t current_time,
387 u64 cycle_time);
bba2556e 388
091810db
JA
389#if IS_ENABLED(CONFIG_STMMAC_SELFTESTS)
390void stmmac_selftest_run(struct net_device *dev,
391 struct ethtool_test *etest, u64 *buf);
392void stmmac_selftest_get_strings(struct stmmac_priv *priv, u8 *data);
393int stmmac_selftest_get_count(struct stmmac_priv *priv);
394#else
395static inline void stmmac_selftest_run(struct net_device *dev,
396 struct ethtool_test *etest, u64 *buf)
397{
398 /* Not enabled */
399}
400static inline void stmmac_selftest_get_strings(struct stmmac_priv *priv,
401 u8 *data)
402{
403 /* Not enabled */
404}
405static inline int stmmac_selftest_get_count(struct stmmac_priv *priv)
406{
407 return -EOPNOTSUPP;
408}
409#endif /* CONFIG_STMMAC_SELFTESTS */
410
bd4242df 411#endif /* __STMMAC_H__ */