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 #define STMMAC_TBS_AVAIL BIT(0) 43 #define STMMAC_TBS_EN BIT(1) 44 45 /* Frequently used values are kept adjacent for cache effect */ 46 struct stmmac_tx_queue { 47 u32 tx_count_frames; 48 int tbs; 49 struct timer_list txtimer; 50 u32 queue_index; 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; 57 unsigned int cur_tx; 58 unsigned int dirty_tx; 59 dma_addr_t dma_tx_phy; 60 u32 tx_tail_addr; 61 u32 mss; 62 }; 63 64 struct stmmac_rx_buffer { 65 struct page *page; 66 struct page *sec_page; 67 dma_addr_t addr; 68 dma_addr_t sec_addr; 69 }; 70 71 struct stmmac_rx_queue { 72 u32 rx_count_frames; 73 u32 queue_index; 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; 79 unsigned int cur_rx; 80 unsigned int dirty_rx; 81 u32 rx_zeroc_thresh; 82 dma_addr_t dma_rx_phy; 83 u32 rx_tail_addr; 84 unsigned int state_saved; 85 struct { 86 struct sk_buff *skb; 87 unsigned int len; 88 unsigned int error; 89 } state; 90 }; 91 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; 96 spinlock_t lock; 97 u32 index; 98 }; 99 100 struct stmmac_tc_entry { 101 bool in_use; 102 bool in_hw; 103 bool is_last; 104 bool is_frag; 105 void *frag_ptr; 106 unsigned int table_pos; 107 u32 handle; 108 u32 prio; 109 struct { 110 u32 match_data; 111 u32 match_en; 112 u8 af:1; 113 u8 rf:1; 114 u8 im:1; 115 u8 nc:1; 116 u8 res1:4; 117 u8 frame_offset; 118 u8 ok_index; 119 u8 dma_ch_no; 120 u32 res2; 121 } __packed val; 122 }; 123 124 #define STMMAC_PPS_MAX 4 125 struct stmmac_pps_cfg { 126 bool available; 127 struct timespec64 start; 128 struct timespec64 period; 129 }; 130 131 struct stmmac_rss { 132 int enable; 133 u8 key[STMMAC_RSS_HASH_KEY_SIZE]; 134 u32 table[STMMAC_RSS_MAX_TABLE_SIZE]; 135 }; 136 137 #define STMMAC_FLOW_ACTION_DROP BIT(0) 138 struct stmmac_flow_entry { 139 unsigned long cookie; 140 unsigned long action; 141 u8 ip_proto; 142 int in_use; 143 int idx; 144 int is_l4; 145 }; 146 147 struct stmmac_priv { 148 /* Frequently used values are kept adjacent for cache effect */ 149 u32 tx_coal_frames; 150 u32 tx_coal_timer; 151 u32 rx_coal_frames; 152 153 int tx_coalesce; 154 int hwts_tx_en; 155 bool tx_path_in_lpi_mode; 156 bool tso; 157 int sph; 158 u32 sarc_type; 159 160 unsigned int dma_buf_sz; 161 unsigned int rx_copybreak; 162 u32 rx_riwt; 163 int hwts_rx_en; 164 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); 170 struct mutex lock; 171 172 /* RX Queue */ 173 struct stmmac_rx_queue rx_queue[MTL_MAX_RX_QUEUES]; 174 175 /* TX Queue */ 176 struct stmmac_tx_queue tx_queue[MTL_MAX_TX_QUEUES]; 177 178 /* Generic channel for NAPI */ 179 struct stmmac_channel channel[STMMAC_CH_MAX]; 180 181 int speed; 182 unsigned int flow_ctrl; 183 unsigned int pause; 184 struct mii_bus *mii; 185 int mii_irq[PHY_MAX_ADDR]; 186 187 struct phylink_config phylink_config; 188 struct phylink *phylink; 189 190 struct stmmac_extra_stats xstats ____cacheline_aligned_in_smp; 191 struct stmmac_safety_stats sstats; 192 struct plat_stmmacenet_data *plat; 193 struct dma_features dma_cap; 194 struct stmmac_counters mmc; 195 int hw_cap_support; 196 int synopsys_id; 197 u32 msg_enable; 198 int wolopts; 199 int wol_irq; 200 int clk_csr; 201 struct timer_list eee_ctrl_timer; 202 int lpi_irq; 203 int eee_enabled; 204 int eee_active; 205 int tx_lpi_timer; 206 unsigned int mode; 207 unsigned int chain_mode; 208 int extend_desc; 209 struct hwtstamp_config tstamp_config; 210 struct ptp_clock *ptp_clock; 211 struct ptp_clock_info ptp_clock_ops; 212 unsigned int default_addend; 213 u32 sub_second_inc; 214 u32 systime_flags; 215 u32 adv_ts; 216 int use_riwt; 217 int irq_wake; 218 spinlock_t ptp_lock; 219 void __iomem *mmcaddr; 220 void __iomem *ptpaddr; 221 unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)]; 222 223 #ifdef CONFIG_DEBUG_FS 224 struct dentry *dbgfs_dir; 225 #endif 226 227 unsigned long state; 228 struct workqueue_struct *wq; 229 struct work_struct service_task; 230 231 /* TC Handling */ 232 unsigned int tc_entries_max; 233 unsigned int tc_off_max; 234 struct stmmac_tc_entry *tc_entries; 235 unsigned int flow_entries_max; 236 struct stmmac_flow_entry *flow_entries; 237 238 /* Pulse Per Second output */ 239 struct stmmac_pps_cfg pps[STMMAC_PPS_MAX]; 240 241 /* Receive Side Scaling */ 242 struct stmmac_rss rss; 243 }; 244 245 enum stmmac_state { 246 STMMAC_DOWN, 247 STMMAC_RESET_REQUESTED, 248 STMMAC_RESETING, 249 STMMAC_SERVICE_SCHED, 250 }; 251 252 int stmmac_mdio_unregister(struct net_device *ndev); 253 int stmmac_mdio_register(struct net_device *ndev); 254 int stmmac_mdio_reset(struct mii_bus *mii); 255 void stmmac_set_ethtool_ops(struct net_device *netdev); 256 257 void stmmac_ptp_register(struct stmmac_priv *priv); 258 void stmmac_ptp_unregister(struct stmmac_priv *priv); 259 int stmmac_resume(struct device *dev); 260 int stmmac_suspend(struct device *dev); 261 int stmmac_dvr_remove(struct device *dev); 262 int stmmac_dvr_probe(struct device *device, 263 struct plat_stmmacenet_data *plat_dat, 264 struct stmmac_resources *res); 265 void stmmac_disable_eee_mode(struct stmmac_priv *priv); 266 bool stmmac_eee_init(struct stmmac_priv *priv); 267 268 #if IS_ENABLED(CONFIG_STMMAC_SELFTESTS) 269 void stmmac_selftest_run(struct net_device *dev, 270 struct ethtool_test *etest, u64 *buf); 271 void stmmac_selftest_get_strings(struct stmmac_priv *priv, u8 *data); 272 int stmmac_selftest_get_count(struct stmmac_priv *priv); 273 #else 274 static inline void stmmac_selftest_run(struct net_device *dev, 275 struct ethtool_test *etest, u64 *buf) 276 { 277 /* Not enabled */ 278 } 279 static inline void stmmac_selftest_get_strings(struct stmmac_priv *priv, 280 u8 *data) 281 { 282 /* Not enabled */ 283 } 284 static inline int stmmac_selftest_get_count(struct stmmac_priv *priv) 285 { 286 return -EOPNOTSUPP; 287 } 288 #endif /* CONFIG_STMMAC_SELFTESTS */ 289 290 #endif /* __STMMAC_H__ */ 291