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 14 #include <linux/clk.h> 15 #include <linux/hrtimer.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 u8 mac[ETH_ALEN]; 29 int wol_irq; 30 int lpi_irq; 31 int irq; 32 int sfty_ce_irq; 33 int sfty_ue_irq; 34 int rx_irq[MTL_MAX_RX_QUEUES]; 35 int tx_irq[MTL_MAX_TX_QUEUES]; 36 }; 37 38 enum stmmac_txbuf_type { 39 STMMAC_TXBUF_T_SKB, 40 STMMAC_TXBUF_T_XDP_TX, 41 STMMAC_TXBUF_T_XDP_NDO, 42 STMMAC_TXBUF_T_XSK_TX, 43 }; 44 45 struct stmmac_tx_info { 46 dma_addr_t buf; 47 bool map_as_page; 48 unsigned len; 49 bool last_segment; 50 bool is_jumbo; 51 enum stmmac_txbuf_type buf_type; 52 }; 53 54 #define STMMAC_TBS_AVAIL BIT(0) 55 #define STMMAC_TBS_EN BIT(1) 56 57 /* Frequently used values are kept adjacent for cache effect */ 58 struct stmmac_tx_queue { 59 u32 tx_count_frames; 60 int tbs; 61 struct hrtimer txtimer; 62 u32 queue_index; 63 struct stmmac_priv *priv_data; 64 struct dma_extended_desc *dma_etx ____cacheline_aligned_in_smp; 65 struct dma_edesc *dma_entx; 66 struct dma_desc *dma_tx; 67 union { 68 struct sk_buff **tx_skbuff; 69 struct xdp_frame **xdpf; 70 }; 71 struct stmmac_tx_info *tx_skbuff_dma; 72 struct xsk_buff_pool *xsk_pool; 73 u32 xsk_frames_done; 74 unsigned int cur_tx; 75 unsigned int dirty_tx; 76 dma_addr_t dma_tx_phy; 77 dma_addr_t tx_tail_addr; 78 u32 mss; 79 }; 80 81 struct stmmac_rx_buffer { 82 union { 83 struct { 84 struct page *page; 85 dma_addr_t addr; 86 __u32 page_offset; 87 }; 88 struct xdp_buff *xdp; 89 }; 90 struct page *sec_page; 91 dma_addr_t sec_addr; 92 }; 93 94 struct stmmac_rx_queue { 95 u32 rx_count_frames; 96 u32 queue_index; 97 struct xdp_rxq_info xdp_rxq; 98 struct xsk_buff_pool *xsk_pool; 99 struct page_pool *page_pool; 100 struct stmmac_rx_buffer *buf_pool; 101 struct stmmac_priv *priv_data; 102 struct dma_extended_desc *dma_erx; 103 struct dma_desc *dma_rx ____cacheline_aligned_in_smp; 104 unsigned int cur_rx; 105 unsigned int dirty_rx; 106 unsigned int buf_alloc_num; 107 u32 rx_zeroc_thresh; 108 dma_addr_t dma_rx_phy; 109 u32 rx_tail_addr; 110 unsigned int state_saved; 111 struct { 112 struct sk_buff *skb; 113 unsigned int len; 114 unsigned int error; 115 } state; 116 }; 117 118 struct stmmac_channel { 119 struct napi_struct rx_napi ____cacheline_aligned_in_smp; 120 struct napi_struct tx_napi ____cacheline_aligned_in_smp; 121 struct napi_struct rxtx_napi ____cacheline_aligned_in_smp; 122 struct stmmac_priv *priv_data; 123 spinlock_t lock; 124 u32 index; 125 }; 126 127 struct stmmac_tc_entry { 128 bool in_use; 129 bool in_hw; 130 bool is_last; 131 bool is_frag; 132 void *frag_ptr; 133 unsigned int table_pos; 134 u32 handle; 135 u32 prio; 136 struct { 137 u32 match_data; 138 u32 match_en; 139 u8 af:1; 140 u8 rf:1; 141 u8 im:1; 142 u8 nc:1; 143 u8 res1:4; 144 u8 frame_offset; 145 u8 ok_index; 146 u8 dma_ch_no; 147 u32 res2; 148 } __packed val; 149 }; 150 151 #define STMMAC_PPS_MAX 4 152 struct stmmac_pps_cfg { 153 bool available; 154 struct timespec64 start; 155 struct timespec64 period; 156 }; 157 158 struct stmmac_rss { 159 int enable; 160 u8 key[STMMAC_RSS_HASH_KEY_SIZE]; 161 u32 table[STMMAC_RSS_MAX_TABLE_SIZE]; 162 }; 163 164 #define STMMAC_FLOW_ACTION_DROP BIT(0) 165 struct stmmac_flow_entry { 166 unsigned long cookie; 167 unsigned long action; 168 u8 ip_proto; 169 int in_use; 170 int idx; 171 int is_l4; 172 }; 173 174 struct stmmac_priv { 175 /* Frequently used values are kept adjacent for cache effect */ 176 u32 tx_coal_frames[MTL_MAX_TX_QUEUES]; 177 u32 tx_coal_timer[MTL_MAX_TX_QUEUES]; 178 u32 rx_coal_frames[MTL_MAX_TX_QUEUES]; 179 180 int tx_coalesce; 181 int hwts_tx_en; 182 bool tx_path_in_lpi_mode; 183 bool tso; 184 int sph; 185 int sph_cap; 186 u32 sarc_type; 187 188 unsigned int dma_buf_sz; 189 unsigned int rx_copybreak; 190 u32 rx_riwt[MTL_MAX_TX_QUEUES]; 191 int hwts_rx_en; 192 193 void __iomem *ioaddr; 194 struct net_device *dev; 195 struct device *device; 196 struct mac_device_info *hw; 197 int (*hwif_quirks)(struct stmmac_priv *priv); 198 struct mutex lock; 199 200 /* RX Queue */ 201 struct stmmac_rx_queue rx_queue[MTL_MAX_RX_QUEUES]; 202 unsigned int dma_rx_size; 203 204 /* TX Queue */ 205 struct stmmac_tx_queue tx_queue[MTL_MAX_TX_QUEUES]; 206 unsigned int dma_tx_size; 207 208 /* Generic channel for NAPI */ 209 struct stmmac_channel channel[STMMAC_CH_MAX]; 210 211 int speed; 212 unsigned int flow_ctrl; 213 unsigned int pause; 214 struct mii_bus *mii; 215 int mii_irq[PHY_MAX_ADDR]; 216 217 struct phylink_config phylink_config; 218 struct phylink *phylink; 219 220 struct stmmac_extra_stats xstats ____cacheline_aligned_in_smp; 221 struct stmmac_safety_stats sstats; 222 struct plat_stmmacenet_data *plat; 223 struct dma_features dma_cap; 224 struct stmmac_counters mmc; 225 int hw_cap_support; 226 int synopsys_id; 227 u32 msg_enable; 228 int wolopts; 229 int wol_irq; 230 int clk_csr; 231 struct timer_list eee_ctrl_timer; 232 int lpi_irq; 233 int eee_enabled; 234 int eee_active; 235 int tx_lpi_timer; 236 int tx_lpi_enabled; 237 int eee_tw_timer; 238 bool eee_sw_timer_en; 239 unsigned int mode; 240 unsigned int chain_mode; 241 int extend_desc; 242 struct hwtstamp_config tstamp_config; 243 struct ptp_clock *ptp_clock; 244 struct ptp_clock_info ptp_clock_ops; 245 unsigned int default_addend; 246 u32 sub_second_inc; 247 u32 systime_flags; 248 u32 adv_ts; 249 int use_riwt; 250 int irq_wake; 251 spinlock_t ptp_lock; 252 /* Protects auxiliary snapshot registers from concurrent access. */ 253 struct mutex aux_ts_lock; 254 255 void __iomem *mmcaddr; 256 void __iomem *ptpaddr; 257 unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)]; 258 int sfty_ce_irq; 259 int sfty_ue_irq; 260 int rx_irq[MTL_MAX_RX_QUEUES]; 261 int tx_irq[MTL_MAX_TX_QUEUES]; 262 /*irq name */ 263 char int_name_mac[IFNAMSIZ + 9]; 264 char int_name_wol[IFNAMSIZ + 9]; 265 char int_name_lpi[IFNAMSIZ + 9]; 266 char int_name_sfty_ce[IFNAMSIZ + 10]; 267 char int_name_sfty_ue[IFNAMSIZ + 10]; 268 char int_name_rx_irq[MTL_MAX_TX_QUEUES][IFNAMSIZ + 14]; 269 char int_name_tx_irq[MTL_MAX_TX_QUEUES][IFNAMSIZ + 18]; 270 271 #ifdef CONFIG_DEBUG_FS 272 struct dentry *dbgfs_dir; 273 #endif 274 275 unsigned long state; 276 struct workqueue_struct *wq; 277 struct work_struct service_task; 278 279 /* Workqueue for handling FPE hand-shaking */ 280 unsigned long fpe_task_state; 281 struct workqueue_struct *fpe_wq; 282 struct work_struct fpe_task; 283 char wq_name[IFNAMSIZ + 4]; 284 285 /* TC Handling */ 286 unsigned int tc_entries_max; 287 unsigned int tc_off_max; 288 struct stmmac_tc_entry *tc_entries; 289 unsigned int flow_entries_max; 290 struct stmmac_flow_entry *flow_entries; 291 292 /* Pulse Per Second output */ 293 struct stmmac_pps_cfg pps[STMMAC_PPS_MAX]; 294 295 /* Receive Side Scaling */ 296 struct stmmac_rss rss; 297 298 /* XDP BPF Program */ 299 unsigned long *af_xdp_zc_qps; 300 struct bpf_prog *xdp_prog; 301 }; 302 303 enum stmmac_state { 304 STMMAC_DOWN, 305 STMMAC_RESET_REQUESTED, 306 STMMAC_RESETING, 307 STMMAC_SERVICE_SCHED, 308 }; 309 310 int stmmac_mdio_unregister(struct net_device *ndev); 311 int stmmac_mdio_register(struct net_device *ndev); 312 int stmmac_mdio_reset(struct mii_bus *mii); 313 int stmmac_xpcs_setup(struct mii_bus *mii); 314 void stmmac_set_ethtool_ops(struct net_device *netdev); 315 316 int stmmac_init_tstamp_counter(struct stmmac_priv *priv, u32 systime_flags); 317 void stmmac_ptp_register(struct stmmac_priv *priv); 318 void stmmac_ptp_unregister(struct stmmac_priv *priv); 319 int stmmac_xdp_open(struct net_device *dev); 320 void stmmac_xdp_release(struct net_device *dev); 321 int stmmac_resume(struct device *dev); 322 int stmmac_suspend(struct device *dev); 323 int stmmac_dvr_remove(struct device *dev); 324 int stmmac_dvr_probe(struct device *device, 325 struct plat_stmmacenet_data *plat_dat, 326 struct stmmac_resources *res); 327 void stmmac_disable_eee_mode(struct stmmac_priv *priv); 328 bool stmmac_eee_init(struct stmmac_priv *priv); 329 int stmmac_reinit_queues(struct net_device *dev, u32 rx_cnt, u32 tx_cnt); 330 int stmmac_reinit_ringparam(struct net_device *dev, u32 rx_size, u32 tx_size); 331 int stmmac_bus_clks_config(struct stmmac_priv *priv, bool enabled); 332 void stmmac_fpe_handshake(struct stmmac_priv *priv, bool enable); 333 334 static inline bool stmmac_xdp_is_enabled(struct stmmac_priv *priv) 335 { 336 return !!priv->xdp_prog; 337 } 338 339 static inline unsigned int stmmac_rx_offset(struct stmmac_priv *priv) 340 { 341 if (stmmac_xdp_is_enabled(priv)) 342 return XDP_PACKET_HEADROOM; 343 344 return 0; 345 } 346 347 void stmmac_disable_rx_queue(struct stmmac_priv *priv, u32 queue); 348 void stmmac_enable_rx_queue(struct stmmac_priv *priv, u32 queue); 349 void stmmac_disable_tx_queue(struct stmmac_priv *priv, u32 queue); 350 void stmmac_enable_tx_queue(struct stmmac_priv *priv, u32 queue); 351 int stmmac_xsk_wakeup(struct net_device *dev, u32 queue, u32 flags); 352 struct timespec64 stmmac_calc_tas_basetime(ktime_t old_base_time, 353 ktime_t current_time, 354 u64 cycle_time); 355 356 #if IS_ENABLED(CONFIG_STMMAC_SELFTESTS) 357 void stmmac_selftest_run(struct net_device *dev, 358 struct ethtool_test *etest, u64 *buf); 359 void stmmac_selftest_get_strings(struct stmmac_priv *priv, u8 *data); 360 int stmmac_selftest_get_count(struct stmmac_priv *priv); 361 #else 362 static inline void stmmac_selftest_run(struct net_device *dev, 363 struct ethtool_test *etest, u64 *buf) 364 { 365 /* Not enabled */ 366 } 367 static inline void stmmac_selftest_get_strings(struct stmmac_priv *priv, 368 u8 *data) 369 { 370 /* Not enabled */ 371 } 372 static inline int stmmac_selftest_get_count(struct stmmac_priv *priv) 373 { 374 return -EOPNOTSUPP; 375 } 376 #endif /* CONFIG_STMMAC_SELFTESTS */ 377 378 #endif /* __STMMAC_H__ */ 379