1 /* SPDX-License-Identifier: (GPL-2.0 OR MIT) */
2 // Copyright (c) 2018 Synopsys, Inc. and/or its affiliates.
3 // stmmac HW Interface Callbacks
4 
5 #ifndef __STMMAC_HWIF_H__
6 #define __STMMAC_HWIF_H__
7 
8 #include <linux/netdevice.h>
9 #include <linux/stmmac.h>
10 
11 #define stmmac_do_void_callback(__priv, __module, __cname,  __arg0, __args...) \
12 ({ \
13 	int __result = -EINVAL; \
14 	if ((__priv)->hw->__module && (__priv)->hw->__module->__cname) { \
15 		(__priv)->hw->__module->__cname((__arg0), ##__args); \
16 		__result = 0; \
17 	} \
18 	__result; \
19 })
20 #define stmmac_do_callback(__priv, __module, __cname,  __arg0, __args...) \
21 ({ \
22 	int __result = -EINVAL; \
23 	if ((__priv)->hw->__module && (__priv)->hw->__module->__cname) \
24 		__result = (__priv)->hw->__module->__cname((__arg0), ##__args); \
25 	__result; \
26 })
27 
28 struct stmmac_extra_stats;
29 struct stmmac_safety_stats;
30 struct dma_desc;
31 struct dma_extended_desc;
32 struct dma_edesc;
33 
34 /* Descriptors helpers */
35 struct stmmac_desc_ops {
36 	/* DMA RX descriptor ring initialization */
37 	void (*init_rx_desc)(struct dma_desc *p, int disable_rx_ic, int mode,
38 			int end, int bfsize);
39 	/* DMA TX descriptor ring initialization */
40 	void (*init_tx_desc)(struct dma_desc *p, int mode, int end);
41 	/* Invoked by the xmit function to prepare the tx descriptor */
42 	void (*prepare_tx_desc)(struct dma_desc *p, int is_fs, int len,
43 			bool csum_flag, int mode, bool tx_own, bool ls,
44 			unsigned int tot_pkt_len);
45 	void (*prepare_tso_tx_desc)(struct dma_desc *p, int is_fs, int len1,
46 			int len2, bool tx_own, bool ls, unsigned int tcphdrlen,
47 			unsigned int tcppayloadlen);
48 	/* Set/get the owner of the descriptor */
49 	void (*set_tx_owner)(struct dma_desc *p);
50 	int (*get_tx_owner)(struct dma_desc *p);
51 	/* Clean the tx descriptor as soon as the tx irq is received */
52 	void (*release_tx_desc)(struct dma_desc *p, int mode);
53 	/* Clear interrupt on tx frame completion. When this bit is
54 	 * set an interrupt happens as soon as the frame is transmitted */
55 	void (*set_tx_ic)(struct dma_desc *p);
56 	/* Last tx segment reports the transmit status */
57 	int (*get_tx_ls)(struct dma_desc *p);
58 	/* Return the transmit status looking at the TDES1 */
59 	int (*tx_status)(void *data, struct stmmac_extra_stats *x,
60 			struct dma_desc *p, void __iomem *ioaddr);
61 	/* Get the buffer size from the descriptor */
62 	int (*get_tx_len)(struct dma_desc *p);
63 	/* Handle extra events on specific interrupts hw dependent */
64 	void (*set_rx_owner)(struct dma_desc *p, int disable_rx_ic);
65 	/* Get the receive frame size */
66 	int (*get_rx_frame_len)(struct dma_desc *p, int rx_coe_type);
67 	/* Return the reception status looking at the RDES1 */
68 	int (*rx_status)(void *data, struct stmmac_extra_stats *x,
69 			struct dma_desc *p);
70 	void (*rx_extended_status)(void *data, struct stmmac_extra_stats *x,
71 			struct dma_extended_desc *p);
72 	/* Set tx timestamp enable bit */
73 	void (*enable_tx_timestamp) (struct dma_desc *p);
74 	/* get tx timestamp status */
75 	int (*get_tx_timestamp_status) (struct dma_desc *p);
76 	/* get timestamp value */
77 	void (*get_timestamp)(void *desc, u32 ats, u64 *ts);
78 	/* get rx timestamp status */
79 	int (*get_rx_timestamp_status)(void *desc, void *next_desc, u32 ats);
80 	/* Display ring */
81 	void (*display_ring)(void *head, unsigned int size, bool rx,
82 			     dma_addr_t dma_rx_phy, unsigned int desc_size);
83 	/* set MSS via context descriptor */
84 	void (*set_mss)(struct dma_desc *p, unsigned int mss);
85 	/* get descriptor skbuff address */
86 	void (*get_addr)(struct dma_desc *p, unsigned int *addr);
87 	/* set descriptor skbuff address */
88 	void (*set_addr)(struct dma_desc *p, dma_addr_t addr);
89 	/* clear descriptor */
90 	void (*clear)(struct dma_desc *p);
91 	/* RSS */
92 	int (*get_rx_hash)(struct dma_desc *p, u32 *hash,
93 			   enum pkt_hash_types *type);
94 	void (*get_rx_header_len)(struct dma_desc *p, unsigned int *len);
95 	void (*set_sec_addr)(struct dma_desc *p, dma_addr_t addr, bool buf2_valid);
96 	void (*set_sarc)(struct dma_desc *p, u32 sarc_type);
97 	void (*set_vlan_tag)(struct dma_desc *p, u16 tag, u16 inner_tag,
98 			     u32 inner_type);
99 	void (*set_vlan)(struct dma_desc *p, u32 type);
100 	void (*set_tbs)(struct dma_edesc *p, u32 sec, u32 nsec);
101 };
102 
103 #define stmmac_init_rx_desc(__priv, __args...) \
104 	stmmac_do_void_callback(__priv, desc, init_rx_desc, __args)
105 #define stmmac_init_tx_desc(__priv, __args...) \
106 	stmmac_do_void_callback(__priv, desc, init_tx_desc, __args)
107 #define stmmac_prepare_tx_desc(__priv, __args...) \
108 	stmmac_do_void_callback(__priv, desc, prepare_tx_desc, __args)
109 #define stmmac_prepare_tso_tx_desc(__priv, __args...) \
110 	stmmac_do_void_callback(__priv, desc, prepare_tso_tx_desc, __args)
111 #define stmmac_set_tx_owner(__priv, __args...) \
112 	stmmac_do_void_callback(__priv, desc, set_tx_owner, __args)
113 #define stmmac_get_tx_owner(__priv, __args...) \
114 	stmmac_do_callback(__priv, desc, get_tx_owner, __args)
115 #define stmmac_release_tx_desc(__priv, __args...) \
116 	stmmac_do_void_callback(__priv, desc, release_tx_desc, __args)
117 #define stmmac_set_tx_ic(__priv, __args...) \
118 	stmmac_do_void_callback(__priv, desc, set_tx_ic, __args)
119 #define stmmac_get_tx_ls(__priv, __args...) \
120 	stmmac_do_callback(__priv, desc, get_tx_ls, __args)
121 #define stmmac_tx_status(__priv, __args...) \
122 	stmmac_do_callback(__priv, desc, tx_status, __args)
123 #define stmmac_get_tx_len(__priv, __args...) \
124 	stmmac_do_callback(__priv, desc, get_tx_len, __args)
125 #define stmmac_set_rx_owner(__priv, __args...) \
126 	stmmac_do_void_callback(__priv, desc, set_rx_owner, __args)
127 #define stmmac_get_rx_frame_len(__priv, __args...) \
128 	stmmac_do_callback(__priv, desc, get_rx_frame_len, __args)
129 #define stmmac_rx_status(__priv, __args...) \
130 	stmmac_do_callback(__priv, desc, rx_status, __args)
131 #define stmmac_rx_extended_status(__priv, __args...) \
132 	stmmac_do_void_callback(__priv, desc, rx_extended_status, __args)
133 #define stmmac_enable_tx_timestamp(__priv, __args...) \
134 	stmmac_do_void_callback(__priv, desc, enable_tx_timestamp, __args)
135 #define stmmac_get_tx_timestamp_status(__priv, __args...) \
136 	stmmac_do_callback(__priv, desc, get_tx_timestamp_status, __args)
137 #define stmmac_get_timestamp(__priv, __args...) \
138 	stmmac_do_void_callback(__priv, desc, get_timestamp, __args)
139 #define stmmac_get_rx_timestamp_status(__priv, __args...) \
140 	stmmac_do_callback(__priv, desc, get_rx_timestamp_status, __args)
141 #define stmmac_display_ring(__priv, __args...) \
142 	stmmac_do_void_callback(__priv, desc, display_ring, __args)
143 #define stmmac_set_mss(__priv, __args...) \
144 	stmmac_do_void_callback(__priv, desc, set_mss, __args)
145 #define stmmac_get_desc_addr(__priv, __args...) \
146 	stmmac_do_void_callback(__priv, desc, get_addr, __args)
147 #define stmmac_set_desc_addr(__priv, __args...) \
148 	stmmac_do_void_callback(__priv, desc, set_addr, __args)
149 #define stmmac_clear_desc(__priv, __args...) \
150 	stmmac_do_void_callback(__priv, desc, clear, __args)
151 #define stmmac_get_rx_hash(__priv, __args...) \
152 	stmmac_do_callback(__priv, desc, get_rx_hash, __args)
153 #define stmmac_get_rx_header_len(__priv, __args...) \
154 	stmmac_do_void_callback(__priv, desc, get_rx_header_len, __args)
155 #define stmmac_set_desc_sec_addr(__priv, __args...) \
156 	stmmac_do_void_callback(__priv, desc, set_sec_addr, __args)
157 #define stmmac_set_desc_sarc(__priv, __args...) \
158 	stmmac_do_void_callback(__priv, desc, set_sarc, __args)
159 #define stmmac_set_desc_vlan_tag(__priv, __args...) \
160 	stmmac_do_void_callback(__priv, desc, set_vlan_tag, __args)
161 #define stmmac_set_desc_vlan(__priv, __args...) \
162 	stmmac_do_void_callback(__priv, desc, set_vlan, __args)
163 #define stmmac_set_desc_tbs(__priv, __args...) \
164 	stmmac_do_void_callback(__priv, desc, set_tbs, __args)
165 
166 struct stmmac_dma_cfg;
167 struct dma_features;
168 
169 /* Specific DMA helpers */
170 struct stmmac_dma_ops {
171 	/* DMA core initialization */
172 	int (*reset)(void __iomem *ioaddr);
173 	void (*init)(void __iomem *ioaddr, struct stmmac_dma_cfg *dma_cfg,
174 		     int atds);
175 	void (*init_chan)(void __iomem *ioaddr,
176 			  struct stmmac_dma_cfg *dma_cfg, u32 chan);
177 	void (*init_rx_chan)(void __iomem *ioaddr,
178 			     struct stmmac_dma_cfg *dma_cfg,
179 			     dma_addr_t phy, u32 chan);
180 	void (*init_tx_chan)(void __iomem *ioaddr,
181 			     struct stmmac_dma_cfg *dma_cfg,
182 			     dma_addr_t phy, u32 chan);
183 	/* Configure the AXI Bus Mode Register */
184 	void (*axi)(void __iomem *ioaddr, struct stmmac_axi *axi);
185 	/* Dump DMA registers */
186 	void (*dump_regs)(void __iomem *ioaddr, u32 *reg_space);
187 	void (*dma_rx_mode)(void __iomem *ioaddr, int mode, u32 channel,
188 			    int fifosz, u8 qmode);
189 	void (*dma_tx_mode)(void __iomem *ioaddr, int mode, u32 channel,
190 			    int fifosz, u8 qmode);
191 	/* To track extra statistic (if supported) */
192 	void (*dma_diagnostic_fr) (void *data, struct stmmac_extra_stats *x,
193 				   void __iomem *ioaddr);
194 	void (*enable_dma_transmission) (void __iomem *ioaddr);
195 	void (*enable_dma_irq)(void __iomem *ioaddr, u32 chan,
196 			       bool rx, bool tx);
197 	void (*disable_dma_irq)(void __iomem *ioaddr, u32 chan,
198 				bool rx, bool tx);
199 	void (*start_tx)(void __iomem *ioaddr, u32 chan);
200 	void (*stop_tx)(void __iomem *ioaddr, u32 chan);
201 	void (*start_rx)(void __iomem *ioaddr, u32 chan);
202 	void (*stop_rx)(void __iomem *ioaddr, u32 chan);
203 	int (*dma_interrupt) (void __iomem *ioaddr,
204 			      struct stmmac_extra_stats *x, u32 chan, u32 dir);
205 	/* If supported then get the optional core features */
206 	void (*get_hw_feature)(void __iomem *ioaddr,
207 			       struct dma_features *dma_cap);
208 	/* Program the HW RX Watchdog */
209 	void (*rx_watchdog)(void __iomem *ioaddr, u32 riwt, u32 queue);
210 	void (*set_tx_ring_len)(void __iomem *ioaddr, u32 len, u32 chan);
211 	void (*set_rx_ring_len)(void __iomem *ioaddr, u32 len, u32 chan);
212 	void (*set_rx_tail_ptr)(void __iomem *ioaddr, u32 tail_ptr, u32 chan);
213 	void (*set_tx_tail_ptr)(void __iomem *ioaddr, u32 tail_ptr, u32 chan);
214 	void (*enable_tso)(void __iomem *ioaddr, bool en, u32 chan);
215 	void (*qmode)(void __iomem *ioaddr, u32 channel, u8 qmode);
216 	void (*set_bfsize)(void __iomem *ioaddr, int bfsize, u32 chan);
217 	void (*enable_sph)(void __iomem *ioaddr, bool en, u32 chan);
218 	int (*enable_tbs)(void __iomem *ioaddr, bool en, u32 chan);
219 };
220 
221 #define stmmac_reset(__priv, __args...) \
222 	stmmac_do_callback(__priv, dma, reset, __args)
223 #define stmmac_dma_init(__priv, __args...) \
224 	stmmac_do_void_callback(__priv, dma, init, __args)
225 #define stmmac_init_chan(__priv, __args...) \
226 	stmmac_do_void_callback(__priv, dma, init_chan, __args)
227 #define stmmac_init_rx_chan(__priv, __args...) \
228 	stmmac_do_void_callback(__priv, dma, init_rx_chan, __args)
229 #define stmmac_init_tx_chan(__priv, __args...) \
230 	stmmac_do_void_callback(__priv, dma, init_tx_chan, __args)
231 #define stmmac_axi(__priv, __args...) \
232 	stmmac_do_void_callback(__priv, dma, axi, __args)
233 #define stmmac_dump_dma_regs(__priv, __args...) \
234 	stmmac_do_void_callback(__priv, dma, dump_regs, __args)
235 #define stmmac_dma_rx_mode(__priv, __args...) \
236 	stmmac_do_void_callback(__priv, dma, dma_rx_mode, __args)
237 #define stmmac_dma_tx_mode(__priv, __args...) \
238 	stmmac_do_void_callback(__priv, dma, dma_tx_mode, __args)
239 #define stmmac_dma_diagnostic_fr(__priv, __args...) \
240 	stmmac_do_void_callback(__priv, dma, dma_diagnostic_fr, __args)
241 #define stmmac_enable_dma_transmission(__priv, __args...) \
242 	stmmac_do_void_callback(__priv, dma, enable_dma_transmission, __args)
243 #define stmmac_enable_dma_irq(__priv, __args...) \
244 	stmmac_do_void_callback(__priv, dma, enable_dma_irq, __args)
245 #define stmmac_disable_dma_irq(__priv, __args...) \
246 	stmmac_do_void_callback(__priv, dma, disable_dma_irq, __args)
247 #define stmmac_start_tx(__priv, __args...) \
248 	stmmac_do_void_callback(__priv, dma, start_tx, __args)
249 #define stmmac_stop_tx(__priv, __args...) \
250 	stmmac_do_void_callback(__priv, dma, stop_tx, __args)
251 #define stmmac_start_rx(__priv, __args...) \
252 	stmmac_do_void_callback(__priv, dma, start_rx, __args)
253 #define stmmac_stop_rx(__priv, __args...) \
254 	stmmac_do_void_callback(__priv, dma, stop_rx, __args)
255 #define stmmac_dma_interrupt_status(__priv, __args...) \
256 	stmmac_do_callback(__priv, dma, dma_interrupt, __args)
257 #define stmmac_get_hw_feature(__priv, __args...) \
258 	stmmac_do_void_callback(__priv, dma, get_hw_feature, __args)
259 #define stmmac_rx_watchdog(__priv, __args...) \
260 	stmmac_do_void_callback(__priv, dma, rx_watchdog, __args)
261 #define stmmac_set_tx_ring_len(__priv, __args...) \
262 	stmmac_do_void_callback(__priv, dma, set_tx_ring_len, __args)
263 #define stmmac_set_rx_ring_len(__priv, __args...) \
264 	stmmac_do_void_callback(__priv, dma, set_rx_ring_len, __args)
265 #define stmmac_set_rx_tail_ptr(__priv, __args...) \
266 	stmmac_do_void_callback(__priv, dma, set_rx_tail_ptr, __args)
267 #define stmmac_set_tx_tail_ptr(__priv, __args...) \
268 	stmmac_do_void_callback(__priv, dma, set_tx_tail_ptr, __args)
269 #define stmmac_enable_tso(__priv, __args...) \
270 	stmmac_do_void_callback(__priv, dma, enable_tso, __args)
271 #define stmmac_dma_qmode(__priv, __args...) \
272 	stmmac_do_void_callback(__priv, dma, qmode, __args)
273 #define stmmac_set_dma_bfsize(__priv, __args...) \
274 	stmmac_do_void_callback(__priv, dma, set_bfsize, __args)
275 #define stmmac_enable_sph(__priv, __args...) \
276 	stmmac_do_void_callback(__priv, dma, enable_sph, __args)
277 #define stmmac_enable_tbs(__priv, __args...) \
278 	stmmac_do_callback(__priv, dma, enable_tbs, __args)
279 
280 struct mac_device_info;
281 struct net_device;
282 struct rgmii_adv;
283 struct stmmac_tc_entry;
284 struct stmmac_pps_cfg;
285 struct stmmac_rss;
286 struct stmmac_est;
287 
288 /* Helpers to program the MAC core */
289 struct stmmac_ops {
290 	/* MAC core initialization */
291 	void (*core_init)(struct mac_device_info *hw, struct net_device *dev);
292 	/* Enable the MAC RX/TX */
293 	void (*set_mac)(void __iomem *ioaddr, bool enable);
294 	/* Enable and verify that the IPC module is supported */
295 	int (*rx_ipc)(struct mac_device_info *hw);
296 	/* Enable RX Queues */
297 	void (*rx_queue_enable)(struct mac_device_info *hw, u8 mode, u32 queue);
298 	/* RX Queues Priority */
299 	void (*rx_queue_prio)(struct mac_device_info *hw, u32 prio, u32 queue);
300 	/* TX Queues Priority */
301 	void (*tx_queue_prio)(struct mac_device_info *hw, u32 prio, u32 queue);
302 	/* RX Queues Routing */
303 	void (*rx_queue_routing)(struct mac_device_info *hw, u8 packet,
304 				 u32 queue);
305 	/* Program RX Algorithms */
306 	void (*prog_mtl_rx_algorithms)(struct mac_device_info *hw, u32 rx_alg);
307 	/* Program TX Algorithms */
308 	void (*prog_mtl_tx_algorithms)(struct mac_device_info *hw, u32 tx_alg);
309 	/* Set MTL TX queues weight */
310 	void (*set_mtl_tx_queue_weight)(struct mac_device_info *hw,
311 					u32 weight, u32 queue);
312 	/* RX MTL queue to RX dma mapping */
313 	void (*map_mtl_to_dma)(struct mac_device_info *hw, u32 queue, u32 chan);
314 	/* Configure AV Algorithm */
315 	void (*config_cbs)(struct mac_device_info *hw, u32 send_slope,
316 			   u32 idle_slope, u32 high_credit, u32 low_credit,
317 			   u32 queue);
318 	/* Dump MAC registers */
319 	void (*dump_regs)(struct mac_device_info *hw, u32 *reg_space);
320 	/* Handle extra events on specific interrupts hw dependent */
321 	int (*host_irq_status)(struct mac_device_info *hw,
322 			       struct stmmac_extra_stats *x);
323 	/* Handle MTL interrupts */
324 	int (*host_mtl_irq_status)(struct mac_device_info *hw, u32 chan);
325 	/* Multicast filter setting */
326 	void (*set_filter)(struct mac_device_info *hw, struct net_device *dev);
327 	/* Flow control setting */
328 	void (*flow_ctrl)(struct mac_device_info *hw, unsigned int duplex,
329 			  unsigned int fc, unsigned int pause_time, u32 tx_cnt);
330 	/* Set power management mode (e.g. magic frame) */
331 	void (*pmt)(struct mac_device_info *hw, unsigned long mode);
332 	/* Set/Get Unicast MAC addresses */
333 	void (*set_umac_addr)(struct mac_device_info *hw, unsigned char *addr,
334 			      unsigned int reg_n);
335 	void (*get_umac_addr)(struct mac_device_info *hw, unsigned char *addr,
336 			      unsigned int reg_n);
337 	void (*set_eee_mode)(struct mac_device_info *hw,
338 			     bool en_tx_lpi_clockgating);
339 	void (*reset_eee_mode)(struct mac_device_info *hw);
340 	void (*set_eee_lpi_entry_timer)(struct mac_device_info *hw, int et);
341 	void (*set_eee_timer)(struct mac_device_info *hw, int ls, int tw);
342 	void (*set_eee_pls)(struct mac_device_info *hw, int link);
343 	void (*debug)(void __iomem *ioaddr, struct stmmac_extra_stats *x,
344 		      u32 rx_queues, u32 tx_queues);
345 	/* PCS calls */
346 	void (*pcs_ctrl_ane)(void __iomem *ioaddr, bool ane, bool srgmi_ral,
347 			     bool loopback);
348 	void (*pcs_rane)(void __iomem *ioaddr, bool restart);
349 	void (*pcs_get_adv_lp)(void __iomem *ioaddr, struct rgmii_adv *adv);
350 	/* Safety Features */
351 	int (*safety_feat_config)(void __iomem *ioaddr, unsigned int asp,
352 				  struct stmmac_safety_feature_cfg *safety_cfg);
353 	int (*safety_feat_irq_status)(struct net_device *ndev,
354 			void __iomem *ioaddr, unsigned int asp,
355 			struct stmmac_safety_stats *stats);
356 	int (*safety_feat_dump)(struct stmmac_safety_stats *stats,
357 			int index, unsigned long *count, const char **desc);
358 	/* Flexible RX Parser */
359 	int (*rxp_config)(void __iomem *ioaddr, struct stmmac_tc_entry *entries,
360 			  unsigned int count);
361 	/* Flexible PPS */
362 	int (*flex_pps_config)(void __iomem *ioaddr, int index,
363 			       struct stmmac_pps_cfg *cfg, bool enable,
364 			       u32 sub_second_inc, u32 systime_flags);
365 	/* Loopback for selftests */
366 	void (*set_mac_loopback)(void __iomem *ioaddr, bool enable);
367 	/* RSS */
368 	int (*rss_configure)(struct mac_device_info *hw,
369 			     struct stmmac_rss *cfg, u32 num_rxq);
370 	/* VLAN */
371 	void (*update_vlan_hash)(struct mac_device_info *hw, u32 hash,
372 				 __le16 perfect_match, bool is_double);
373 	void (*enable_vlan)(struct mac_device_info *hw, u32 type);
374 	int (*add_hw_vlan_rx_fltr)(struct net_device *dev,
375 				   struct mac_device_info *hw,
376 				   __be16 proto, u16 vid);
377 	int (*del_hw_vlan_rx_fltr)(struct net_device *dev,
378 				   struct mac_device_info *hw,
379 				   __be16 proto, u16 vid);
380 	void (*restore_hw_vlan_rx_fltr)(struct net_device *dev,
381 					struct mac_device_info *hw);
382 	/* TX Timestamp */
383 	int (*get_mac_tx_timestamp)(struct mac_device_info *hw, u64 *ts);
384 	/* Source Address Insertion / Replacement */
385 	void (*sarc_configure)(void __iomem *ioaddr, int val);
386 	/* Filtering */
387 	int (*config_l3_filter)(struct mac_device_info *hw, u32 filter_no,
388 				bool en, bool ipv6, bool sa, bool inv,
389 				u32 match);
390 	int (*config_l4_filter)(struct mac_device_info *hw, u32 filter_no,
391 				bool en, bool udp, bool sa, bool inv,
392 				u32 match);
393 	void (*set_arp_offload)(struct mac_device_info *hw, bool en, u32 addr);
394 	int (*est_configure)(void __iomem *ioaddr, struct stmmac_est *cfg,
395 			     unsigned int ptp_rate);
396 	void (*est_irq_status)(void __iomem *ioaddr, struct net_device *dev,
397 			       struct stmmac_extra_stats *x, u32 txqcnt);
398 	void (*fpe_configure)(void __iomem *ioaddr, u32 num_txq, u32 num_rxq,
399 			      bool enable);
400 	void (*fpe_send_mpacket)(void __iomem *ioaddr,
401 				 enum stmmac_mpacket_type type);
402 	int (*fpe_irq_status)(void __iomem *ioaddr, struct net_device *dev);
403 };
404 
405 #define stmmac_core_init(__priv, __args...) \
406 	stmmac_do_void_callback(__priv, mac, core_init, __args)
407 #define stmmac_mac_set(__priv, __args...) \
408 	stmmac_do_void_callback(__priv, mac, set_mac, __args)
409 #define stmmac_rx_ipc(__priv, __args...) \
410 	stmmac_do_callback(__priv, mac, rx_ipc, __args)
411 #define stmmac_rx_queue_enable(__priv, __args...) \
412 	stmmac_do_void_callback(__priv, mac, rx_queue_enable, __args)
413 #define stmmac_rx_queue_prio(__priv, __args...) \
414 	stmmac_do_void_callback(__priv, mac, rx_queue_prio, __args)
415 #define stmmac_tx_queue_prio(__priv, __args...) \
416 	stmmac_do_void_callback(__priv, mac, tx_queue_prio, __args)
417 #define stmmac_rx_queue_routing(__priv, __args...) \
418 	stmmac_do_void_callback(__priv, mac, rx_queue_routing, __args)
419 #define stmmac_prog_mtl_rx_algorithms(__priv, __args...) \
420 	stmmac_do_void_callback(__priv, mac, prog_mtl_rx_algorithms, __args)
421 #define stmmac_prog_mtl_tx_algorithms(__priv, __args...) \
422 	stmmac_do_void_callback(__priv, mac, prog_mtl_tx_algorithms, __args)
423 #define stmmac_set_mtl_tx_queue_weight(__priv, __args...) \
424 	stmmac_do_void_callback(__priv, mac, set_mtl_tx_queue_weight, __args)
425 #define stmmac_map_mtl_to_dma(__priv, __args...) \
426 	stmmac_do_void_callback(__priv, mac, map_mtl_to_dma, __args)
427 #define stmmac_config_cbs(__priv, __args...) \
428 	stmmac_do_void_callback(__priv, mac, config_cbs, __args)
429 #define stmmac_dump_mac_regs(__priv, __args...) \
430 	stmmac_do_void_callback(__priv, mac, dump_regs, __args)
431 #define stmmac_host_irq_status(__priv, __args...) \
432 	stmmac_do_callback(__priv, mac, host_irq_status, __args)
433 #define stmmac_host_mtl_irq_status(__priv, __args...) \
434 	stmmac_do_callback(__priv, mac, host_mtl_irq_status, __args)
435 #define stmmac_set_filter(__priv, __args...) \
436 	stmmac_do_void_callback(__priv, mac, set_filter, __args)
437 #define stmmac_flow_ctrl(__priv, __args...) \
438 	stmmac_do_void_callback(__priv, mac, flow_ctrl, __args)
439 #define stmmac_pmt(__priv, __args...) \
440 	stmmac_do_void_callback(__priv, mac, pmt, __args)
441 #define stmmac_set_umac_addr(__priv, __args...) \
442 	stmmac_do_void_callback(__priv, mac, set_umac_addr, __args)
443 #define stmmac_get_umac_addr(__priv, __args...) \
444 	stmmac_do_void_callback(__priv, mac, get_umac_addr, __args)
445 #define stmmac_set_eee_mode(__priv, __args...) \
446 	stmmac_do_void_callback(__priv, mac, set_eee_mode, __args)
447 #define stmmac_reset_eee_mode(__priv, __args...) \
448 	stmmac_do_void_callback(__priv, mac, reset_eee_mode, __args)
449 #define stmmac_set_eee_lpi_timer(__priv, __args...) \
450 	stmmac_do_void_callback(__priv, mac, set_eee_lpi_entry_timer, __args)
451 #define stmmac_set_eee_timer(__priv, __args...) \
452 	stmmac_do_void_callback(__priv, mac, set_eee_timer, __args)
453 #define stmmac_set_eee_pls(__priv, __args...) \
454 	stmmac_do_void_callback(__priv, mac, set_eee_pls, __args)
455 #define stmmac_mac_debug(__priv, __args...) \
456 	stmmac_do_void_callback(__priv, mac, debug, __args)
457 #define stmmac_pcs_ctrl_ane(__priv, __args...) \
458 	stmmac_do_void_callback(__priv, mac, pcs_ctrl_ane, __args)
459 #define stmmac_pcs_rane(__priv, __args...) \
460 	stmmac_do_void_callback(__priv, mac, pcs_rane, __args)
461 #define stmmac_pcs_get_adv_lp(__priv, __args...) \
462 	stmmac_do_void_callback(__priv, mac, pcs_get_adv_lp, __args)
463 #define stmmac_safety_feat_config(__priv, __args...) \
464 	stmmac_do_callback(__priv, mac, safety_feat_config, __args)
465 #define stmmac_safety_feat_irq_status(__priv, __args...) \
466 	stmmac_do_callback(__priv, mac, safety_feat_irq_status, __args)
467 #define stmmac_safety_feat_dump(__priv, __args...) \
468 	stmmac_do_callback(__priv, mac, safety_feat_dump, __args)
469 #define stmmac_rxp_config(__priv, __args...) \
470 	stmmac_do_callback(__priv, mac, rxp_config, __args)
471 #define stmmac_flex_pps_config(__priv, __args...) \
472 	stmmac_do_callback(__priv, mac, flex_pps_config, __args)
473 #define stmmac_set_mac_loopback(__priv, __args...) \
474 	stmmac_do_void_callback(__priv, mac, set_mac_loopback, __args)
475 #define stmmac_rss_configure(__priv, __args...) \
476 	stmmac_do_callback(__priv, mac, rss_configure, __args)
477 #define stmmac_update_vlan_hash(__priv, __args...) \
478 	stmmac_do_void_callback(__priv, mac, update_vlan_hash, __args)
479 #define stmmac_enable_vlan(__priv, __args...) \
480 	stmmac_do_void_callback(__priv, mac, enable_vlan, __args)
481 #define stmmac_add_hw_vlan_rx_fltr(__priv, __args...) \
482 	stmmac_do_callback(__priv, mac, add_hw_vlan_rx_fltr, __args)
483 #define stmmac_del_hw_vlan_rx_fltr(__priv, __args...) \
484 	stmmac_do_callback(__priv, mac, del_hw_vlan_rx_fltr, __args)
485 #define stmmac_restore_hw_vlan_rx_fltr(__priv, __args...) \
486 	stmmac_do_void_callback(__priv, mac, restore_hw_vlan_rx_fltr, __args)
487 #define stmmac_get_mac_tx_timestamp(__priv, __args...) \
488 	stmmac_do_callback(__priv, mac, get_mac_tx_timestamp, __args)
489 #define stmmac_sarc_configure(__priv, __args...) \
490 	stmmac_do_void_callback(__priv, mac, sarc_configure, __args)
491 #define stmmac_config_l3_filter(__priv, __args...) \
492 	stmmac_do_callback(__priv, mac, config_l3_filter, __args)
493 #define stmmac_config_l4_filter(__priv, __args...) \
494 	stmmac_do_callback(__priv, mac, config_l4_filter, __args)
495 #define stmmac_set_arp_offload(__priv, __args...) \
496 	stmmac_do_void_callback(__priv, mac, set_arp_offload, __args)
497 #define stmmac_est_configure(__priv, __args...) \
498 	stmmac_do_callback(__priv, mac, est_configure, __args)
499 #define stmmac_est_irq_status(__priv, __args...) \
500 	stmmac_do_void_callback(__priv, mac, est_irq_status, __args)
501 #define stmmac_fpe_configure(__priv, __args...) \
502 	stmmac_do_void_callback(__priv, mac, fpe_configure, __args)
503 #define stmmac_fpe_send_mpacket(__priv, __args...) \
504 	stmmac_do_void_callback(__priv, mac, fpe_send_mpacket, __args)
505 #define stmmac_fpe_irq_status(__priv, __args...) \
506 	stmmac_do_callback(__priv, mac, fpe_irq_status, __args)
507 
508 struct stmmac_priv;
509 
510 /* PTP and HW Timer helpers */
511 struct stmmac_hwtimestamp {
512 	void (*config_hw_tstamping) (void __iomem *ioaddr, u32 data);
513 	void (*config_sub_second_increment)(void __iomem *ioaddr, u32 ptp_clock,
514 					   int gmac4, u32 *ssinc);
515 	int (*init_systime) (void __iomem *ioaddr, u32 sec, u32 nsec);
516 	int (*config_addend) (void __iomem *ioaddr, u32 addend);
517 	int (*adjust_systime) (void __iomem *ioaddr, u32 sec, u32 nsec,
518 			       int add_sub, int gmac4);
519 	void (*get_systime) (void __iomem *ioaddr, u64 *systime);
520 	void (*get_ptptime)(void __iomem *ioaddr, u64 *ptp_time);
521 	void (*timestamp_interrupt)(struct stmmac_priv *priv);
522 };
523 
524 #define stmmac_config_hw_tstamping(__priv, __args...) \
525 	stmmac_do_void_callback(__priv, ptp, config_hw_tstamping, __args)
526 #define stmmac_config_sub_second_increment(__priv, __args...) \
527 	stmmac_do_void_callback(__priv, ptp, config_sub_second_increment, __args)
528 #define stmmac_init_systime(__priv, __args...) \
529 	stmmac_do_callback(__priv, ptp, init_systime, __args)
530 #define stmmac_config_addend(__priv, __args...) \
531 	stmmac_do_callback(__priv, ptp, config_addend, __args)
532 #define stmmac_adjust_systime(__priv, __args...) \
533 	stmmac_do_callback(__priv, ptp, adjust_systime, __args)
534 #define stmmac_get_systime(__priv, __args...) \
535 	stmmac_do_void_callback(__priv, ptp, get_systime, __args)
536 #define stmmac_get_ptptime(__priv, __args...) \
537 	stmmac_do_void_callback(__priv, ptp, get_ptptime, __args)
538 #define stmmac_timestamp_interrupt(__priv, __args...) \
539 	stmmac_do_void_callback(__priv, ptp, timestamp_interrupt, __args)
540 
541 /* Helpers to manage the descriptors for chain and ring modes */
542 struct stmmac_mode_ops {
543 	void (*init) (void *des, dma_addr_t phy_addr, unsigned int size,
544 		      unsigned int extend_desc);
545 	unsigned int (*is_jumbo_frm) (int len, int ehn_desc);
546 	int (*jumbo_frm)(void *priv, struct sk_buff *skb, int csum);
547 	int (*set_16kib_bfsize)(int mtu);
548 	void (*init_desc3)(struct dma_desc *p);
549 	void (*refill_desc3) (void *priv, struct dma_desc *p);
550 	void (*clean_desc3) (void *priv, struct dma_desc *p);
551 };
552 
553 #define stmmac_mode_init(__priv, __args...) \
554 	stmmac_do_void_callback(__priv, mode, init, __args)
555 #define stmmac_is_jumbo_frm(__priv, __args...) \
556 	stmmac_do_callback(__priv, mode, is_jumbo_frm, __args)
557 #define stmmac_jumbo_frm(__priv, __args...) \
558 	stmmac_do_callback(__priv, mode, jumbo_frm, __args)
559 #define stmmac_set_16kib_bfsize(__priv, __args...) \
560 	stmmac_do_callback(__priv, mode, set_16kib_bfsize, __args)
561 #define stmmac_init_desc3(__priv, __args...) \
562 	stmmac_do_void_callback(__priv, mode, init_desc3, __args)
563 #define stmmac_refill_desc3(__priv, __args...) \
564 	stmmac_do_void_callback(__priv, mode, refill_desc3, __args)
565 #define stmmac_clean_desc3(__priv, __args...) \
566 	stmmac_do_void_callback(__priv, mode, clean_desc3, __args)
567 
568 struct tc_cls_u32_offload;
569 struct tc_cbs_qopt_offload;
570 struct flow_cls_offload;
571 struct tc_taprio_qopt_offload;
572 struct tc_etf_qopt_offload;
573 
574 struct stmmac_tc_ops {
575 	int (*init)(struct stmmac_priv *priv);
576 	int (*setup_cls_u32)(struct stmmac_priv *priv,
577 			     struct tc_cls_u32_offload *cls);
578 	int (*setup_cbs)(struct stmmac_priv *priv,
579 			 struct tc_cbs_qopt_offload *qopt);
580 	int (*setup_cls)(struct stmmac_priv *priv,
581 			 struct flow_cls_offload *cls);
582 	int (*setup_taprio)(struct stmmac_priv *priv,
583 			    struct tc_taprio_qopt_offload *qopt);
584 	int (*setup_etf)(struct stmmac_priv *priv,
585 			 struct tc_etf_qopt_offload *qopt);
586 };
587 
588 #define stmmac_tc_init(__priv, __args...) \
589 	stmmac_do_callback(__priv, tc, init, __args)
590 #define stmmac_tc_setup_cls_u32(__priv, __args...) \
591 	stmmac_do_callback(__priv, tc, setup_cls_u32, __args)
592 #define stmmac_tc_setup_cbs(__priv, __args...) \
593 	stmmac_do_callback(__priv, tc, setup_cbs, __args)
594 #define stmmac_tc_setup_cls(__priv, __args...) \
595 	stmmac_do_callback(__priv, tc, setup_cls, __args)
596 #define stmmac_tc_setup_taprio(__priv, __args...) \
597 	stmmac_do_callback(__priv, tc, setup_taprio, __args)
598 #define stmmac_tc_setup_etf(__priv, __args...) \
599 	stmmac_do_callback(__priv, tc, setup_etf, __args)
600 
601 struct stmmac_counters;
602 
603 struct stmmac_mmc_ops {
604 	void (*ctrl)(void __iomem *ioaddr, unsigned int mode);
605 	void (*intr_all_mask)(void __iomem *ioaddr);
606 	void (*read)(void __iomem *ioaddr, struct stmmac_counters *mmc);
607 };
608 
609 #define stmmac_mmc_ctrl(__priv, __args...) \
610 	stmmac_do_void_callback(__priv, mmc, ctrl, __args)
611 #define stmmac_mmc_intr_all_mask(__priv, __args...) \
612 	stmmac_do_void_callback(__priv, mmc, intr_all_mask, __args)
613 #define stmmac_mmc_read(__priv, __args...) \
614 	stmmac_do_void_callback(__priv, mmc, read, __args)
615 
616 struct stmmac_regs_off {
617 	u32 ptp_off;
618 	u32 mmc_off;
619 };
620 
621 extern const struct stmmac_ops dwmac100_ops;
622 extern const struct stmmac_dma_ops dwmac100_dma_ops;
623 extern const struct stmmac_ops dwmac1000_ops;
624 extern const struct stmmac_dma_ops dwmac1000_dma_ops;
625 extern const struct stmmac_ops dwmac4_ops;
626 extern const struct stmmac_dma_ops dwmac4_dma_ops;
627 extern const struct stmmac_ops dwmac410_ops;
628 extern const struct stmmac_dma_ops dwmac410_dma_ops;
629 extern const struct stmmac_ops dwmac510_ops;
630 extern const struct stmmac_tc_ops dwmac510_tc_ops;
631 extern const struct stmmac_ops dwxgmac210_ops;
632 extern const struct stmmac_ops dwxlgmac2_ops;
633 extern const struct stmmac_dma_ops dwxgmac210_dma_ops;
634 extern const struct stmmac_desc_ops dwxgmac210_desc_ops;
635 extern const struct stmmac_mmc_ops dwmac_mmc_ops;
636 extern const struct stmmac_mmc_ops dwxgmac_mmc_ops;
637 
638 #define GMAC_VERSION		0x00000020	/* GMAC CORE Version */
639 #define GMAC4_VERSION		0x00000110	/* GMAC4+ CORE Version */
640 
641 int stmmac_hwif_init(struct stmmac_priv *priv);
642 
643 #endif /* __STMMAC_HWIF_H__ */
644