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