| .. | .. |
|---|
| 1 | +/* SPDX-License-Identifier: GPL-2.0-only */ |
|---|
| 1 | 2 | /******************************************************************************* |
|---|
| 2 | 3 | Copyright (C) 2007-2009 STMicroelectronics Ltd |
|---|
| 3 | 4 | |
|---|
| 4 | | - This program is free software; you can redistribute it and/or modify it |
|---|
| 5 | | - under the terms and conditions of the GNU General Public License, |
|---|
| 6 | | - version 2, as published by the Free Software Foundation. |
|---|
| 7 | | - |
|---|
| 8 | | - This program is distributed in the hope it will be useful, but WITHOUT |
|---|
| 9 | | - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|---|
| 10 | | - FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
|---|
| 11 | | - more details. |
|---|
| 12 | | - |
|---|
| 13 | | - The full GNU General Public License is included in this distribution in |
|---|
| 14 | | - the file called "COPYING". |
|---|
| 15 | 5 | |
|---|
| 16 | 6 | Author: Giuseppe Cavallaro <peppe.cavallaro@st.com> |
|---|
| 17 | 7 | *******************************************************************************/ |
|---|
| .. | .. |
|---|
| 23 | 13 | #define DRV_MODULE_VERSION "Jan_2016" |
|---|
| 24 | 14 | |
|---|
| 25 | 15 | #include <linux/clk.h> |
|---|
| 16 | +#include <linux/if_vlan.h> |
|---|
| 26 | 17 | #include <linux/stmmac.h> |
|---|
| 27 | | -#include <linux/phy.h> |
|---|
| 18 | +#include <linux/phylink.h> |
|---|
| 28 | 19 | #include <linux/pci.h> |
|---|
| 29 | 20 | #include "common.h" |
|---|
| 30 | 21 | #include <linux/ptp_clock_kernel.h> |
|---|
| 31 | 22 | #include <linux/net_tstamp.h> |
|---|
| 32 | 23 | #include <linux/reset.h> |
|---|
| 24 | +#include <net/page_pool.h> |
|---|
| 33 | 25 | |
|---|
| 34 | 26 | struct stmmac_resources { |
|---|
| 35 | 27 | void __iomem *addr; |
|---|
| .. | .. |
|---|
| 47 | 39 | bool is_jumbo; |
|---|
| 48 | 40 | }; |
|---|
| 49 | 41 | |
|---|
| 42 | +#define STMMAC_TBS_AVAIL BIT(0) |
|---|
| 43 | +#define STMMAC_TBS_EN BIT(1) |
|---|
| 44 | + |
|---|
| 50 | 45 | /* Frequently used values are kept adjacent for cache effect */ |
|---|
| 51 | 46 | struct stmmac_tx_queue { |
|---|
| 52 | 47 | u32 tx_count_frames; |
|---|
| 48 | + int tbs; |
|---|
| 53 | 49 | struct timer_list txtimer; |
|---|
| 54 | 50 | u32 queue_index; |
|---|
| 55 | 51 | struct stmmac_priv *priv_data; |
|---|
| 56 | 52 | struct dma_extended_desc *dma_etx ____cacheline_aligned_in_smp; |
|---|
| 53 | + struct dma_edesc *dma_entx; |
|---|
| 57 | 54 | struct dma_desc *dma_tx; |
|---|
| 58 | 55 | struct sk_buff **tx_skbuff; |
|---|
| 59 | 56 | struct stmmac_tx_info *tx_skbuff_dma; |
|---|
| .. | .. |
|---|
| 64 | 61 | u32 mss; |
|---|
| 65 | 62 | }; |
|---|
| 66 | 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 | + |
|---|
| 67 | 71 | struct stmmac_rx_queue { |
|---|
| 72 | + u32 rx_count_frames; |
|---|
| 68 | 73 | u32 queue_index; |
|---|
| 74 | + struct page_pool *page_pool; |
|---|
| 75 | + struct stmmac_rx_buffer *buf_pool; |
|---|
| 69 | 76 | struct stmmac_priv *priv_data; |
|---|
| 70 | 77 | struct dma_extended_desc *dma_erx; |
|---|
| 71 | 78 | struct dma_desc *dma_rx ____cacheline_aligned_in_smp; |
|---|
| 72 | | - struct sk_buff **rx_skbuff; |
|---|
| 73 | | - dma_addr_t *rx_skbuff_dma; |
|---|
| 74 | 79 | unsigned int cur_rx; |
|---|
| 75 | 80 | unsigned int dirty_rx; |
|---|
| 76 | 81 | u32 rx_zeroc_thresh; |
|---|
| 77 | 82 | dma_addr_t dma_rx_phy; |
|---|
| 78 | 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; |
|---|
| 79 | 90 | }; |
|---|
| 80 | 91 | |
|---|
| 81 | 92 | struct stmmac_channel { |
|---|
| 82 | | - struct napi_struct napi ____cacheline_aligned_in_smp; |
|---|
| 93 | + struct napi_struct rx_napi ____cacheline_aligned_in_smp; |
|---|
| 94 | + struct napi_struct tx_napi ____cacheline_aligned_in_smp; |
|---|
| 83 | 95 | struct stmmac_priv *priv_data; |
|---|
| 96 | + spinlock_t lock; |
|---|
| 84 | 97 | u32 index; |
|---|
| 85 | | - int has_rx; |
|---|
| 86 | | - int has_tx; |
|---|
| 87 | 98 | }; |
|---|
| 88 | 99 | |
|---|
| 89 | 100 | struct stmmac_tc_entry { |
|---|
| .. | .. |
|---|
| 117 | 128 | struct timespec64 period; |
|---|
| 118 | 129 | }; |
|---|
| 119 | 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 | + |
|---|
| 120 | 147 | struct stmmac_priv { |
|---|
| 121 | 148 | /* Frequently used values are kept adjacent for cache effect */ |
|---|
| 122 | 149 | u32 tx_coal_frames; |
|---|
| 123 | 150 | u32 tx_coal_timer; |
|---|
| 151 | + u32 rx_coal_frames; |
|---|
| 124 | 152 | |
|---|
| 125 | 153 | int tx_coalesce; |
|---|
| 126 | 154 | int hwts_tx_en; |
|---|
| 127 | 155 | bool tx_path_in_lpi_mode; |
|---|
| 128 | 156 | bool tso; |
|---|
| 157 | + int sph; |
|---|
| 158 | + u32 sarc_type; |
|---|
| 129 | 159 | |
|---|
| 130 | 160 | unsigned int dma_buf_sz; |
|---|
| 131 | 161 | unsigned int rx_copybreak; |
|---|
| .. | .. |
|---|
| 141 | 171 | |
|---|
| 142 | 172 | /* RX Queue */ |
|---|
| 143 | 173 | struct stmmac_rx_queue rx_queue[MTL_MAX_RX_QUEUES]; |
|---|
| 174 | + unsigned int dma_rx_size; |
|---|
| 144 | 175 | |
|---|
| 145 | 176 | /* TX Queue */ |
|---|
| 146 | 177 | struct stmmac_tx_queue tx_queue[MTL_MAX_TX_QUEUES]; |
|---|
| 178 | + unsigned int dma_tx_size; |
|---|
| 147 | 179 | |
|---|
| 148 | 180 | /* Generic channel for NAPI */ |
|---|
| 149 | 181 | struct stmmac_channel channel[STMMAC_CH_MAX]; |
|---|
| 150 | 182 | |
|---|
| 151 | | - bool oldlink; |
|---|
| 152 | 183 | int speed; |
|---|
| 153 | | - int oldduplex; |
|---|
| 154 | 184 | unsigned int flow_ctrl; |
|---|
| 155 | 185 | unsigned int pause; |
|---|
| 156 | 186 | struct mii_bus *mii; |
|---|
| 157 | 187 | int mii_irq[PHY_MAX_ADDR]; |
|---|
| 188 | + |
|---|
| 189 | + struct phylink_config phylink_config; |
|---|
| 190 | + struct phylink *phylink; |
|---|
| 158 | 191 | |
|---|
| 159 | 192 | struct stmmac_extra_stats xstats ____cacheline_aligned_in_smp; |
|---|
| 160 | 193 | struct stmmac_safety_stats sstats; |
|---|
| .. | .. |
|---|
| 172 | 205 | int eee_enabled; |
|---|
| 173 | 206 | int eee_active; |
|---|
| 174 | 207 | int tx_lpi_timer; |
|---|
| 208 | + int tx_lpi_enabled; |
|---|
| 209 | + int eee_tw_timer; |
|---|
| 175 | 210 | unsigned int mode; |
|---|
| 176 | 211 | unsigned int chain_mode; |
|---|
| 177 | 212 | int extend_desc; |
|---|
| .. | .. |
|---|
| 187 | 222 | spinlock_t ptp_lock; |
|---|
| 188 | 223 | void __iomem *mmcaddr; |
|---|
| 189 | 224 | void __iomem *ptpaddr; |
|---|
| 225 | + unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)]; |
|---|
| 190 | 226 | |
|---|
| 191 | 227 | #ifdef CONFIG_DEBUG_FS |
|---|
| 192 | 228 | struct dentry *dbgfs_dir; |
|---|
| 193 | | - struct dentry *dbgfs_rings_status; |
|---|
| 194 | | - struct dentry *dbgfs_dma_cap; |
|---|
| 195 | 229 | #endif |
|---|
| 196 | 230 | |
|---|
| 197 | 231 | unsigned long state; |
|---|
| .. | .. |
|---|
| 202 | 236 | unsigned int tc_entries_max; |
|---|
| 203 | 237 | unsigned int tc_off_max; |
|---|
| 204 | 238 | struct stmmac_tc_entry *tc_entries; |
|---|
| 239 | + unsigned int flow_entries_max; |
|---|
| 240 | + struct stmmac_flow_entry *flow_entries; |
|---|
| 205 | 241 | |
|---|
| 206 | 242 | /* Pulse Per Second output */ |
|---|
| 207 | 243 | struct stmmac_pps_cfg pps[STMMAC_PPS_MAX]; |
|---|
| 244 | + |
|---|
| 245 | + /* Receive Side Scaling */ |
|---|
| 246 | + struct stmmac_rss rss; |
|---|
| 208 | 247 | }; |
|---|
| 209 | 248 | |
|---|
| 210 | 249 | enum stmmac_state { |
|---|
| .. | .. |
|---|
| 226 | 265 | } |
|---|
| 227 | 266 | #endif |
|---|
| 228 | 267 | |
|---|
| 229 | | -#ifdef CONFIG_STMMAC_PTP |
|---|
| 268 | +int stmmac_init_tstamp_counter(struct stmmac_priv *priv, u32 systime_flags); |
|---|
| 230 | 269 | void stmmac_ptp_register(struct stmmac_priv *priv); |
|---|
| 231 | 270 | void stmmac_ptp_unregister(struct stmmac_priv *priv); |
|---|
| 232 | | -#else |
|---|
| 233 | | -static inline void stmmac_ptp_register(struct stmmac_priv *priv) |
|---|
| 234 | | -{ |
|---|
| 235 | | -} |
|---|
| 236 | | - |
|---|
| 237 | | -static inline void stmmac_ptp_unregister(struct stmmac_priv *priv) |
|---|
| 238 | | -{ |
|---|
| 239 | | -} |
|---|
| 240 | | -#endif |
|---|
| 241 | 271 | int stmmac_resume(struct device *dev); |
|---|
| 242 | 272 | int stmmac_suspend(struct device *dev); |
|---|
| 243 | 273 | int stmmac_dvr_remove(struct device *dev); |
|---|
| .. | .. |
|---|
| 246 | 276 | struct stmmac_resources *res); |
|---|
| 247 | 277 | void stmmac_disable_eee_mode(struct stmmac_priv *priv); |
|---|
| 248 | 278 | bool stmmac_eee_init(struct stmmac_priv *priv); |
|---|
| 279 | +int stmmac_reinit_queues(struct net_device *dev, u32 rx_cnt, u32 tx_cnt); |
|---|
| 280 | +int stmmac_reinit_ringparam(struct net_device *dev, u32 rx_size, u32 tx_size); |
|---|
| 281 | +int stmmac_bus_clks_config(struct stmmac_priv *priv, bool enabled); |
|---|
| 282 | + |
|---|
| 283 | +#if IS_ENABLED(CONFIG_STMMAC_SELFTESTS) |
|---|
| 284 | +void stmmac_selftest_run(struct net_device *dev, |
|---|
| 285 | + struct ethtool_test *etest, u64 *buf); |
|---|
| 286 | +void stmmac_selftest_get_strings(struct stmmac_priv *priv, u8 *data); |
|---|
| 287 | +int stmmac_selftest_get_count(struct stmmac_priv *priv); |
|---|
| 288 | +#else |
|---|
| 289 | +static inline void stmmac_selftest_run(struct net_device *dev, |
|---|
| 290 | + struct ethtool_test *etest, u64 *buf) |
|---|
| 291 | +{ |
|---|
| 292 | + /* Not enabled */ |
|---|
| 293 | +} |
|---|
| 294 | +static inline void stmmac_selftest_get_strings(struct stmmac_priv *priv, |
|---|
| 295 | + u8 *data) |
|---|
| 296 | +{ |
|---|
| 297 | + /* Not enabled */ |
|---|
| 298 | +} |
|---|
| 299 | +static inline int stmmac_selftest_get_count(struct stmmac_priv *priv) |
|---|
| 300 | +{ |
|---|
| 301 | + return -EOPNOTSUPP; |
|---|
| 302 | +} |
|---|
| 303 | +#endif /* CONFIG_STMMAC_SELFTESTS */ |
|---|
| 249 | 304 | |
|---|
| 250 | 305 | #endif /* __STMMAC_H__ */ |
|---|