0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef __STMMAC_H__
0010 #define __STMMAC_H__
0011
0012 #define STMMAC_RESOURCE_NAME "stmmaceth"
0013
0014 #include <linux/clk.h>
0015 #include <linux/hrtimer.h>
0016 #include <linux/if_vlan.h>
0017 #include <linux/stmmac.h>
0018 #include <linux/phylink.h>
0019 #include <linux/pci.h>
0020 #include "common.h"
0021 #include <linux/ptp_clock_kernel.h>
0022 #include <linux/net_tstamp.h>
0023 #include <linux/reset.h>
0024 #include <net/page_pool.h>
0025 #include <uapi/linux/bpf.h>
0026
0027 struct stmmac_resources {
0028 void __iomem *addr;
0029 u8 mac[ETH_ALEN];
0030 int wol_irq;
0031 int lpi_irq;
0032 int irq;
0033 int sfty_ce_irq;
0034 int sfty_ue_irq;
0035 int rx_irq[MTL_MAX_RX_QUEUES];
0036 int tx_irq[MTL_MAX_TX_QUEUES];
0037 };
0038
0039 enum stmmac_txbuf_type {
0040 STMMAC_TXBUF_T_SKB,
0041 STMMAC_TXBUF_T_XDP_TX,
0042 STMMAC_TXBUF_T_XDP_NDO,
0043 STMMAC_TXBUF_T_XSK_TX,
0044 };
0045
0046 struct stmmac_tx_info {
0047 dma_addr_t buf;
0048 bool map_as_page;
0049 unsigned len;
0050 bool last_segment;
0051 bool is_jumbo;
0052 enum stmmac_txbuf_type buf_type;
0053 };
0054
0055 #define STMMAC_TBS_AVAIL BIT(0)
0056 #define STMMAC_TBS_EN BIT(1)
0057
0058
0059 struct stmmac_tx_queue {
0060 u32 tx_count_frames;
0061 int tbs;
0062 struct hrtimer txtimer;
0063 u32 queue_index;
0064 struct stmmac_priv *priv_data;
0065 struct dma_extended_desc *dma_etx ____cacheline_aligned_in_smp;
0066 struct dma_edesc *dma_entx;
0067 struct dma_desc *dma_tx;
0068 union {
0069 struct sk_buff **tx_skbuff;
0070 struct xdp_frame **xdpf;
0071 };
0072 struct stmmac_tx_info *tx_skbuff_dma;
0073 struct xsk_buff_pool *xsk_pool;
0074 u32 xsk_frames_done;
0075 unsigned int cur_tx;
0076 unsigned int dirty_tx;
0077 dma_addr_t dma_tx_phy;
0078 dma_addr_t tx_tail_addr;
0079 u32 mss;
0080 };
0081
0082 struct stmmac_rx_buffer {
0083 union {
0084 struct {
0085 struct page *page;
0086 dma_addr_t addr;
0087 __u32 page_offset;
0088 };
0089 struct xdp_buff *xdp;
0090 };
0091 struct page *sec_page;
0092 dma_addr_t sec_addr;
0093 };
0094
0095 struct stmmac_rx_queue {
0096 u32 rx_count_frames;
0097 u32 queue_index;
0098 struct xdp_rxq_info xdp_rxq;
0099 struct xsk_buff_pool *xsk_pool;
0100 struct page_pool *page_pool;
0101 struct stmmac_rx_buffer *buf_pool;
0102 struct stmmac_priv *priv_data;
0103 struct dma_extended_desc *dma_erx;
0104 struct dma_desc *dma_rx ____cacheline_aligned_in_smp;
0105 unsigned int cur_rx;
0106 unsigned int dirty_rx;
0107 unsigned int buf_alloc_num;
0108 u32 rx_zeroc_thresh;
0109 dma_addr_t dma_rx_phy;
0110 u32 rx_tail_addr;
0111 unsigned int state_saved;
0112 struct {
0113 struct sk_buff *skb;
0114 unsigned int len;
0115 unsigned int error;
0116 } state;
0117 };
0118
0119 struct stmmac_channel {
0120 struct napi_struct rx_napi ____cacheline_aligned_in_smp;
0121 struct napi_struct tx_napi ____cacheline_aligned_in_smp;
0122 struct napi_struct rxtx_napi ____cacheline_aligned_in_smp;
0123 struct stmmac_priv *priv_data;
0124 spinlock_t lock;
0125 u32 index;
0126 };
0127
0128 struct stmmac_tc_entry {
0129 bool in_use;
0130 bool in_hw;
0131 bool is_last;
0132 bool is_frag;
0133 void *frag_ptr;
0134 unsigned int table_pos;
0135 u32 handle;
0136 u32 prio;
0137 struct {
0138 u32 match_data;
0139 u32 match_en;
0140 u8 af:1;
0141 u8 rf:1;
0142 u8 im:1;
0143 u8 nc:1;
0144 u8 res1:4;
0145 u8 frame_offset;
0146 u8 ok_index;
0147 u8 dma_ch_no;
0148 u32 res2;
0149 } __packed val;
0150 };
0151
0152 #define STMMAC_PPS_MAX 4
0153 struct stmmac_pps_cfg {
0154 bool available;
0155 struct timespec64 start;
0156 struct timespec64 period;
0157 };
0158
0159 struct stmmac_rss {
0160 int enable;
0161 u8 key[STMMAC_RSS_HASH_KEY_SIZE];
0162 u32 table[STMMAC_RSS_MAX_TABLE_SIZE];
0163 };
0164
0165 #define STMMAC_FLOW_ACTION_DROP BIT(0)
0166 struct stmmac_flow_entry {
0167 unsigned long cookie;
0168 unsigned long action;
0169 u8 ip_proto;
0170 int in_use;
0171 int idx;
0172 int is_l4;
0173 };
0174
0175
0176 enum stmmac_rfs_type {
0177 STMMAC_RFS_T_VLAN,
0178 STMMAC_RFS_T_LLDP,
0179 STMMAC_RFS_T_1588,
0180 STMMAC_RFS_T_MAX,
0181 };
0182
0183 struct stmmac_rfs_entry {
0184 unsigned long cookie;
0185 u16 etype;
0186 int in_use;
0187 int type;
0188 int tc;
0189 };
0190
0191 struct stmmac_dma_conf {
0192 unsigned int dma_buf_sz;
0193
0194
0195 struct stmmac_rx_queue rx_queue[MTL_MAX_RX_QUEUES];
0196 unsigned int dma_rx_size;
0197
0198
0199 struct stmmac_tx_queue tx_queue[MTL_MAX_TX_QUEUES];
0200 unsigned int dma_tx_size;
0201 };
0202
0203 struct stmmac_priv {
0204
0205 u32 tx_coal_frames[MTL_MAX_TX_QUEUES];
0206 u32 tx_coal_timer[MTL_MAX_TX_QUEUES];
0207 u32 rx_coal_frames[MTL_MAX_TX_QUEUES];
0208
0209 int hwts_tx_en;
0210 bool tx_path_in_lpi_mode;
0211 bool tso;
0212 int sph;
0213 int sph_cap;
0214 u32 sarc_type;
0215
0216 unsigned int rx_copybreak;
0217 u32 rx_riwt[MTL_MAX_TX_QUEUES];
0218 int hwts_rx_en;
0219
0220 void __iomem *ioaddr;
0221 struct net_device *dev;
0222 struct device *device;
0223 struct mac_device_info *hw;
0224 int (*hwif_quirks)(struct stmmac_priv *priv);
0225 struct mutex lock;
0226
0227 struct stmmac_dma_conf dma_conf;
0228
0229
0230 struct stmmac_channel channel[STMMAC_CH_MAX];
0231
0232 int speed;
0233 unsigned int flow_ctrl;
0234 unsigned int pause;
0235 struct mii_bus *mii;
0236
0237 struct phylink_config phylink_config;
0238 struct phylink *phylink;
0239
0240 struct stmmac_extra_stats xstats ____cacheline_aligned_in_smp;
0241 struct stmmac_safety_stats sstats;
0242 struct plat_stmmacenet_data *plat;
0243 struct dma_features dma_cap;
0244 struct stmmac_counters mmc;
0245 int hw_cap_support;
0246 int synopsys_id;
0247 u32 msg_enable;
0248 int wolopts;
0249 int wol_irq;
0250 int clk_csr;
0251 struct timer_list eee_ctrl_timer;
0252 int lpi_irq;
0253 int eee_enabled;
0254 int eee_active;
0255 int tx_lpi_timer;
0256 int tx_lpi_enabled;
0257 int eee_tw_timer;
0258 bool eee_sw_timer_en;
0259 unsigned int mode;
0260 unsigned int chain_mode;
0261 int extend_desc;
0262 struct hwtstamp_config tstamp_config;
0263 struct ptp_clock *ptp_clock;
0264 struct ptp_clock_info ptp_clock_ops;
0265 unsigned int default_addend;
0266 u32 sub_second_inc;
0267 u32 systime_flags;
0268 u32 adv_ts;
0269 int use_riwt;
0270 int irq_wake;
0271 rwlock_t ptp_lock;
0272
0273 struct mutex aux_ts_lock;
0274 wait_queue_head_t tstamp_busy_wait;
0275
0276 void __iomem *mmcaddr;
0277 void __iomem *ptpaddr;
0278 unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)];
0279 int sfty_ce_irq;
0280 int sfty_ue_irq;
0281 int rx_irq[MTL_MAX_RX_QUEUES];
0282 int tx_irq[MTL_MAX_TX_QUEUES];
0283
0284 char int_name_mac[IFNAMSIZ + 9];
0285 char int_name_wol[IFNAMSIZ + 9];
0286 char int_name_lpi[IFNAMSIZ + 9];
0287 char int_name_sfty_ce[IFNAMSIZ + 10];
0288 char int_name_sfty_ue[IFNAMSIZ + 10];
0289 char int_name_rx_irq[MTL_MAX_TX_QUEUES][IFNAMSIZ + 14];
0290 char int_name_tx_irq[MTL_MAX_TX_QUEUES][IFNAMSIZ + 18];
0291
0292 #ifdef CONFIG_DEBUG_FS
0293 struct dentry *dbgfs_dir;
0294 #endif
0295
0296 unsigned long state;
0297 struct workqueue_struct *wq;
0298 struct work_struct service_task;
0299
0300
0301 unsigned long fpe_task_state;
0302 struct workqueue_struct *fpe_wq;
0303 struct work_struct fpe_task;
0304 char wq_name[IFNAMSIZ + 4];
0305
0306
0307 unsigned int tc_entries_max;
0308 unsigned int tc_off_max;
0309 struct stmmac_tc_entry *tc_entries;
0310 unsigned int flow_entries_max;
0311 struct stmmac_flow_entry *flow_entries;
0312 unsigned int rfs_entries_max[STMMAC_RFS_T_MAX];
0313 unsigned int rfs_entries_cnt[STMMAC_RFS_T_MAX];
0314 unsigned int rfs_entries_total;
0315 struct stmmac_rfs_entry *rfs_entries;
0316
0317
0318 struct stmmac_pps_cfg pps[STMMAC_PPS_MAX];
0319
0320
0321 struct stmmac_rss rss;
0322
0323
0324 unsigned long *af_xdp_zc_qps;
0325 struct bpf_prog *xdp_prog;
0326 };
0327
0328 enum stmmac_state {
0329 STMMAC_DOWN,
0330 STMMAC_RESET_REQUESTED,
0331 STMMAC_RESETING,
0332 STMMAC_SERVICE_SCHED,
0333 };
0334
0335 int stmmac_mdio_unregister(struct net_device *ndev);
0336 int stmmac_mdio_register(struct net_device *ndev);
0337 int stmmac_mdio_reset(struct mii_bus *mii);
0338 int stmmac_xpcs_setup(struct mii_bus *mii);
0339 void stmmac_set_ethtool_ops(struct net_device *netdev);
0340
0341 int stmmac_init_tstamp_counter(struct stmmac_priv *priv, u32 systime_flags);
0342 void stmmac_ptp_register(struct stmmac_priv *priv);
0343 void stmmac_ptp_unregister(struct stmmac_priv *priv);
0344 int stmmac_xdp_open(struct net_device *dev);
0345 void stmmac_xdp_release(struct net_device *dev);
0346 int stmmac_resume(struct device *dev);
0347 int stmmac_suspend(struct device *dev);
0348 int stmmac_dvr_remove(struct device *dev);
0349 int stmmac_dvr_probe(struct device *device,
0350 struct plat_stmmacenet_data *plat_dat,
0351 struct stmmac_resources *res);
0352 void stmmac_disable_eee_mode(struct stmmac_priv *priv);
0353 bool stmmac_eee_init(struct stmmac_priv *priv);
0354 int stmmac_reinit_queues(struct net_device *dev, u32 rx_cnt, u32 tx_cnt);
0355 int stmmac_reinit_ringparam(struct net_device *dev, u32 rx_size, u32 tx_size);
0356 int stmmac_bus_clks_config(struct stmmac_priv *priv, bool enabled);
0357 void stmmac_fpe_handshake(struct stmmac_priv *priv, bool enable);
0358
0359 static inline bool stmmac_xdp_is_enabled(struct stmmac_priv *priv)
0360 {
0361 return !!priv->xdp_prog;
0362 }
0363
0364 static inline unsigned int stmmac_rx_offset(struct stmmac_priv *priv)
0365 {
0366 if (stmmac_xdp_is_enabled(priv))
0367 return XDP_PACKET_HEADROOM;
0368
0369 return 0;
0370 }
0371
0372 void stmmac_disable_rx_queue(struct stmmac_priv *priv, u32 queue);
0373 void stmmac_enable_rx_queue(struct stmmac_priv *priv, u32 queue);
0374 void stmmac_disable_tx_queue(struct stmmac_priv *priv, u32 queue);
0375 void stmmac_enable_tx_queue(struct stmmac_priv *priv, u32 queue);
0376 int stmmac_xsk_wakeup(struct net_device *dev, u32 queue, u32 flags);
0377 struct timespec64 stmmac_calc_tas_basetime(ktime_t old_base_time,
0378 ktime_t current_time,
0379 u64 cycle_time);
0380
0381 #if IS_ENABLED(CONFIG_STMMAC_SELFTESTS)
0382 void stmmac_selftest_run(struct net_device *dev,
0383 struct ethtool_test *etest, u64 *buf);
0384 void stmmac_selftest_get_strings(struct stmmac_priv *priv, u8 *data);
0385 int stmmac_selftest_get_count(struct stmmac_priv *priv);
0386 #else
0387 static inline void stmmac_selftest_run(struct net_device *dev,
0388 struct ethtool_test *etest, u64 *buf)
0389 {
0390
0391 }
0392 static inline void stmmac_selftest_get_strings(struct stmmac_priv *priv,
0393 u8 *data)
0394 {
0395
0396 }
0397 static inline int stmmac_selftest_get_count(struct stmmac_priv *priv)
0398 {
0399 return -EOPNOTSUPP;
0400 }
0401 #endif
0402
0403 #endif