1 // SPDX-License-Identifier: (GPL-2.0 OR MIT)
2 // Copyright (c) 2018 Synopsys, Inc. and/or its affiliates.
3 // stmmac HW Interface Callbacks
5 #ifndef __STMMAC_HWIF_H__
6 #define __STMMAC_HWIF_H__
8 #define stmmac_do_void_callback(__priv, __module, __cname, __arg0, __args...) \
10 int __result = -EINVAL; \
11 if ((__priv)->hw->__module->__cname) { \
12 (__priv)->hw->__module->__cname((__arg0), ##__args); \
17 #define stmmac_do_callback(__priv, __module, __cname, __arg0, __args...) \
19 int __result = -EINVAL; \
20 if ((__priv)->hw->__module->__cname) \
21 __result = (__priv)->hw->__module->__cname((__arg0), ##__args); \
25 struct stmmac_extra_stats
;
26 struct stmmac_safety_stats
;
28 struct dma_extended_desc
;
30 /* Descriptors helpers */
31 struct stmmac_desc_ops
{
32 /* DMA RX descriptor ring initialization */
33 void (*init_rx_desc
)(struct dma_desc
*p
, int disable_rx_ic
, int mode
,
35 /* DMA TX descriptor ring initialization */
36 void (*init_tx_desc
)(struct dma_desc
*p
, int mode
, int end
);
37 /* Invoked by the xmit function to prepare the tx descriptor */
38 void (*prepare_tx_desc
)(struct dma_desc
*p
, int is_fs
, int len
,
39 bool csum_flag
, int mode
, bool tx_own
, bool ls
,
40 unsigned int tot_pkt_len
);
41 void (*prepare_tso_tx_desc
)(struct dma_desc
*p
, int is_fs
, int len1
,
42 int len2
, bool tx_own
, bool ls
, unsigned int tcphdrlen
,
43 unsigned int tcppayloadlen
);
44 /* Set/get the owner of the descriptor */
45 void (*set_tx_owner
)(struct dma_desc
*p
);
46 int (*get_tx_owner
)(struct dma_desc
*p
);
47 /* Clean the tx descriptor as soon as the tx irq is received */
48 void (*release_tx_desc
)(struct dma_desc
*p
, int mode
);
49 /* Clear interrupt on tx frame completion. When this bit is
50 * set an interrupt happens as soon as the frame is transmitted */
51 void (*set_tx_ic
)(struct dma_desc
*p
);
52 /* Last tx segment reports the transmit status */
53 int (*get_tx_ls
)(struct dma_desc
*p
);
54 /* Return the transmit status looking at the TDES1 */
55 int (*tx_status
)(void *data
, struct stmmac_extra_stats
*x
,
56 struct dma_desc
*p
, void __iomem
*ioaddr
);
57 /* Get the buffer size from the descriptor */
58 int (*get_tx_len
)(struct dma_desc
*p
);
59 /* Handle extra events on specific interrupts hw dependent */
60 void (*set_rx_owner
)(struct dma_desc
*p
);
61 /* Get the receive frame size */
62 int (*get_rx_frame_len
)(struct dma_desc
*p
, int rx_coe_type
);
63 /* Return the reception status looking at the RDES1 */
64 int (*rx_status
)(void *data
, struct stmmac_extra_stats
*x
,
66 void (*rx_extended_status
)(void *data
, struct stmmac_extra_stats
*x
,
67 struct dma_extended_desc
*p
);
68 /* Set tx timestamp enable bit */
69 void (*enable_tx_timestamp
) (struct dma_desc
*p
);
70 /* get tx timestamp status */
71 int (*get_tx_timestamp_status
) (struct dma_desc
*p
);
72 /* get timestamp value */
73 void (*get_timestamp
)(void *desc
, u32 ats
, u64
*ts
);
74 /* get rx timestamp status */
75 int (*get_rx_timestamp_status
)(void *desc
, void *next_desc
, u32 ats
);
77 void (*display_ring
)(void *head
, unsigned int size
, bool rx
);
78 /* set MSS via context descriptor */
79 void (*set_mss
)(struct dma_desc
*p
, unsigned int mss
);
82 #define stmmac_init_rx_desc(__priv, __args...) \
83 stmmac_do_void_callback(__priv, desc, init_rx_desc, __args)
84 #define stmmac_init_tx_desc(__priv, __args...) \
85 stmmac_do_void_callback(__priv, desc, init_tx_desc, __args)
86 #define stmmac_prepare_tx_desc(__priv, __args...) \
87 stmmac_do_void_callback(__priv, desc, prepare_tx_desc, __args)
88 #define stmmac_prepare_tso_tx_desc(__priv, __args...) \
89 stmmac_do_void_callback(__priv, desc, prepare_tso_tx_desc, __args)
90 #define stmmac_set_tx_owner(__priv, __args...) \
91 stmmac_do_void_callback(__priv, desc, set_tx_owner, __args)
92 #define stmmac_get_tx_owner(__priv, __args...) \
93 stmmac_do_callback(__priv, desc, get_tx_owner, __args)
94 #define stmmac_release_tx_desc(__priv, __args...) \
95 stmmac_do_void_callback(__priv, desc, release_tx_desc, __args)
96 #define stmmac_set_tx_ic(__priv, __args...) \
97 stmmac_do_void_callback(__priv, desc, set_tx_ic, __args)
98 #define stmmac_get_tx_ls(__priv, __args...) \
99 stmmac_do_callback(__priv, desc, get_tx_ls, __args)
100 #define stmmac_tx_status(__priv, __args...) \
101 stmmac_do_callback(__priv, desc, tx_status, __args)
102 #define stmmac_get_tx_len(__priv, __args...) \
103 stmmac_do_callback(__priv, desc, get_tx_len, __args)
104 #define stmmac_set_rx_owner(__priv, __args...) \
105 stmmac_do_void_callback(__priv, desc, set_rx_owner, __args)
106 #define stmmac_get_rx_frame_len(__priv, __args...) \
107 stmmac_do_callback(__priv, desc, get_rx_frame_len, __args)
108 #define stmmac_rx_status(__priv, __args...) \
109 stmmac_do_callback(__priv, desc, rx_status, __args)
110 #define stmmac_rx_extended_status(__priv, __args...) \
111 stmmac_do_void_callback(__priv, desc, rx_extended_status, __args)
112 #define stmmac_enable_tx_timestamp(__priv, __args...) \
113 stmmac_do_void_callback(__priv, desc, enable_tx_timestamp, __args)
114 #define stmmac_get_tx_timestamp_status(__priv, __args...) \
115 stmmac_do_callback(__priv, desc, get_tx_timestamp_status, __args)
116 #define stmmac_get_timestamp(__priv, __args...) \
117 stmmac_do_void_callback(__priv, desc, get_timestamp, __args)
118 #define stmmac_get_rx_timestamp_status(__priv, __args...) \
119 stmmac_do_callback(__priv, desc, get_rx_timestamp_status, __args)
120 #define stmmac_display_ring(__priv, __args...) \
121 stmmac_do_void_callback(__priv, desc, display_ring, __args)
122 #define stmmac_set_mss(__priv, __args...) \
123 stmmac_do_void_callback(__priv, desc, set_mss, __args)
125 struct stmmac_dma_cfg
;
128 /* Specific DMA helpers */
129 struct stmmac_dma_ops
{
130 /* DMA core initialization */
131 int (*reset
)(void __iomem
*ioaddr
);
132 void (*init
)(void __iomem
*ioaddr
, struct stmmac_dma_cfg
*dma_cfg
,
133 u32 dma_tx
, u32 dma_rx
, int atds
);
134 void (*init_chan
)(void __iomem
*ioaddr
,
135 struct stmmac_dma_cfg
*dma_cfg
, u32 chan
);
136 void (*init_rx_chan
)(void __iomem
*ioaddr
,
137 struct stmmac_dma_cfg
*dma_cfg
,
138 u32 dma_rx_phy
, u32 chan
);
139 void (*init_tx_chan
)(void __iomem
*ioaddr
,
140 struct stmmac_dma_cfg
*dma_cfg
,
141 u32 dma_tx_phy
, u32 chan
);
142 /* Configure the AXI Bus Mode Register */
143 void (*axi
)(void __iomem
*ioaddr
, struct stmmac_axi
*axi
);
144 /* Dump DMA registers */
145 void (*dump_regs
)(void __iomem
*ioaddr
, u32
*reg_space
);
146 /* Set tx/rx threshold in the csr6 register
147 * An invalid value enables the store-and-forward mode */
148 void (*dma_mode
)(void __iomem
*ioaddr
, int txmode
, int rxmode
,
150 void (*dma_rx_mode
)(void __iomem
*ioaddr
, int mode
, u32 channel
,
151 int fifosz
, u8 qmode
);
152 void (*dma_tx_mode
)(void __iomem
*ioaddr
, int mode
, u32 channel
,
153 int fifosz
, u8 qmode
);
154 /* To track extra statistic (if supported) */
155 void (*dma_diagnostic_fr
) (void *data
, struct stmmac_extra_stats
*x
,
156 void __iomem
*ioaddr
);
157 void (*enable_dma_transmission
) (void __iomem
*ioaddr
);
158 void (*enable_dma_irq
)(void __iomem
*ioaddr
, u32 chan
);
159 void (*disable_dma_irq
)(void __iomem
*ioaddr
, u32 chan
);
160 void (*start_tx
)(void __iomem
*ioaddr
, u32 chan
);
161 void (*stop_tx
)(void __iomem
*ioaddr
, u32 chan
);
162 void (*start_rx
)(void __iomem
*ioaddr
, u32 chan
);
163 void (*stop_rx
)(void __iomem
*ioaddr
, u32 chan
);
164 int (*dma_interrupt
) (void __iomem
*ioaddr
,
165 struct stmmac_extra_stats
*x
, u32 chan
);
166 /* If supported then get the optional core features */
167 void (*get_hw_feature
)(void __iomem
*ioaddr
,
168 struct dma_features
*dma_cap
);
169 /* Program the HW RX Watchdog */
170 void (*rx_watchdog
)(void __iomem
*ioaddr
, u32 riwt
, u32 number_chan
);
171 void (*set_tx_ring_len
)(void __iomem
*ioaddr
, u32 len
, u32 chan
);
172 void (*set_rx_ring_len
)(void __iomem
*ioaddr
, u32 len
, u32 chan
);
173 void (*set_rx_tail_ptr
)(void __iomem
*ioaddr
, u32 tail_ptr
, u32 chan
);
174 void (*set_tx_tail_ptr
)(void __iomem
*ioaddr
, u32 tail_ptr
, u32 chan
);
175 void (*enable_tso
)(void __iomem
*ioaddr
, bool en
, u32 chan
);
178 #define stmmac_reset(__priv, __args...) \
179 stmmac_do_callback(__priv, dma, reset, __args)
180 #define stmmac_dma_init(__priv, __args...) \
181 stmmac_do_void_callback(__priv, dma, init, __args)
182 #define stmmac_init_chan(__priv, __args...) \
183 stmmac_do_void_callback(__priv, dma, init_chan, __args)
184 #define stmmac_init_rx_chan(__priv, __args...) \
185 stmmac_do_void_callback(__priv, dma, init_rx_chan, __args)
186 #define stmmac_init_tx_chan(__priv, __args...) \
187 stmmac_do_void_callback(__priv, dma, init_tx_chan, __args)
188 #define stmmac_axi(__priv, __args...) \
189 stmmac_do_void_callback(__priv, dma, axi, __args)
190 #define stmmac_dump_dma_regs(__priv, __args...) \
191 stmmac_do_void_callback(__priv, dma, dump_regs, __args)
192 #define stmmac_dma_mode(__priv, __args...) \
193 stmmac_do_void_callback(__priv, dma, dma_mode, __args)
194 #define stmmac_dma_rx_mode(__priv, __args...) \
195 stmmac_do_void_callback(__priv, dma, dma_rx_mode, __args)
196 #define stmmac_dma_tx_mode(__priv, __args...) \
197 stmmac_do_void_callback(__priv, dma, dma_tx_mode, __args)
198 #define stmmac_dma_diagnostic_fr(__priv, __args...) \
199 stmmac_do_void_callback(__priv, dma, dma_diagnostic_fr, __args)
200 #define stmmac_enable_dma_transmission(__priv, __args...) \
201 stmmac_do_void_callback(__priv, dma, enable_dma_transmission, __args)
202 #define stmmac_enable_dma_irq(__priv, __args...) \
203 stmmac_do_void_callback(__priv, dma, enable_dma_irq, __args)
204 #define stmmac_disable_dma_irq(__priv, __args...) \
205 stmmac_do_void_callback(__priv, dma, disable_dma_irq, __args)
206 #define stmmac_start_tx(__priv, __args...) \
207 stmmac_do_void_callback(__priv, dma, start_tx, __args)
208 #define stmmac_stop_tx(__priv, __args...) \
209 stmmac_do_void_callback(__priv, dma, stop_tx, __args)
210 #define stmmac_start_rx(__priv, __args...) \
211 stmmac_do_void_callback(__priv, dma, start_rx, __args)
212 #define stmmac_stop_rx(__priv, __args...) \
213 stmmac_do_void_callback(__priv, dma, stop_rx, __args)
214 #define stmmac_dma_interrupt_status(__priv, __args...) \
215 stmmac_do_callback(__priv, dma, dma_interrupt, __args)
216 #define stmmac_get_hw_feature(__priv, __args...) \
217 stmmac_do_void_callback(__priv, dma, get_hw_feature, __args)
218 #define stmmac_rx_watchdog(__priv, __args...) \
219 stmmac_do_void_callback(__priv, dma, rx_watchdog, __args)
220 #define stmmac_set_tx_ring_len(__priv, __args...) \
221 stmmac_do_void_callback(__priv, dma, set_tx_ring_len, __args)
222 #define stmmac_set_rx_ring_len(__priv, __args...) \
223 stmmac_do_void_callback(__priv, dma, set_rx_ring_len, __args)
224 #define stmmac_set_rx_tail_ptr(__priv, __args...) \
225 stmmac_do_void_callback(__priv, dma, set_rx_tail_ptr, __args)
226 #define stmmac_set_tx_tail_ptr(__priv, __args...) \
227 stmmac_do_void_callback(__priv, dma, set_tx_tail_ptr, __args)
228 #define stmmac_enable_tso(__priv, __args...) \
229 stmmac_do_void_callback(__priv, dma, enable_tso, __args)
231 struct mac_device_info
;
234 struct stmmac_safety_stats
;
236 /* Helpers to program the MAC core */
238 /* MAC core initialization */
239 void (*core_init
)(struct mac_device_info
*hw
, struct net_device
*dev
);
240 /* Enable the MAC RX/TX */
241 void (*set_mac
)(void __iomem
*ioaddr
, bool enable
);
242 /* Enable and verify that the IPC module is supported */
243 int (*rx_ipc
)(struct mac_device_info
*hw
);
244 /* Enable RX Queues */
245 void (*rx_queue_enable
)(struct mac_device_info
*hw
, u8 mode
, u32 queue
);
246 /* RX Queues Priority */
247 void (*rx_queue_prio
)(struct mac_device_info
*hw
, u32 prio
, u32 queue
);
248 /* TX Queues Priority */
249 void (*tx_queue_prio
)(struct mac_device_info
*hw
, u32 prio
, u32 queue
);
250 /* RX Queues Routing */
251 void (*rx_queue_routing
)(struct mac_device_info
*hw
, u8 packet
,
253 /* Program RX Algorithms */
254 void (*prog_mtl_rx_algorithms
)(struct mac_device_info
*hw
, u32 rx_alg
);
255 /* Program TX Algorithms */
256 void (*prog_mtl_tx_algorithms
)(struct mac_device_info
*hw
, u32 tx_alg
);
257 /* Set MTL TX queues weight */
258 void (*set_mtl_tx_queue_weight
)(struct mac_device_info
*hw
,
259 u32 weight
, u32 queue
);
260 /* RX MTL queue to RX dma mapping */
261 void (*map_mtl_to_dma
)(struct mac_device_info
*hw
, u32 queue
, u32 chan
);
262 /* Configure AV Algorithm */
263 void (*config_cbs
)(struct mac_device_info
*hw
, u32 send_slope
,
264 u32 idle_slope
, u32 high_credit
, u32 low_credit
,
266 /* Dump MAC registers */
267 void (*dump_regs
)(struct mac_device_info
*hw
, u32
*reg_space
);
268 /* Handle extra events on specific interrupts hw dependent */
269 int (*host_irq_status
)(struct mac_device_info
*hw
,
270 struct stmmac_extra_stats
*x
);
271 /* Handle MTL interrupts */
272 int (*host_mtl_irq_status
)(struct mac_device_info
*hw
, u32 chan
);
273 /* Multicast filter setting */
274 void (*set_filter
)(struct mac_device_info
*hw
, struct net_device
*dev
);
275 /* Flow control setting */
276 void (*flow_ctrl
)(struct mac_device_info
*hw
, unsigned int duplex
,
277 unsigned int fc
, unsigned int pause_time
, u32 tx_cnt
);
278 /* Set power management mode (e.g. magic frame) */
279 void (*pmt
)(struct mac_device_info
*hw
, unsigned long mode
);
280 /* Set/Get Unicast MAC addresses */
281 void (*set_umac_addr
)(struct mac_device_info
*hw
, unsigned char *addr
,
283 void (*get_umac_addr
)(struct mac_device_info
*hw
, unsigned char *addr
,
285 void (*set_eee_mode
)(struct mac_device_info
*hw
,
286 bool en_tx_lpi_clockgating
);
287 void (*reset_eee_mode
)(struct mac_device_info
*hw
);
288 void (*set_eee_timer
)(struct mac_device_info
*hw
, int ls
, int tw
);
289 void (*set_eee_pls
)(struct mac_device_info
*hw
, int link
);
290 void (*debug
)(void __iomem
*ioaddr
, struct stmmac_extra_stats
*x
,
291 u32 rx_queues
, u32 tx_queues
);
293 void (*pcs_ctrl_ane
)(void __iomem
*ioaddr
, bool ane
, bool srgmi_ral
,
295 void (*pcs_rane
)(void __iomem
*ioaddr
, bool restart
);
296 void (*pcs_get_adv_lp
)(void __iomem
*ioaddr
, struct rgmii_adv
*adv
);
297 /* Safety Features */
298 int (*safety_feat_config
)(void __iomem
*ioaddr
, unsigned int asp
);
299 int (*safety_feat_irq_status
)(struct net_device
*ndev
,
300 void __iomem
*ioaddr
, unsigned int asp
,
301 struct stmmac_safety_stats
*stats
);
302 int (*safety_feat_dump
)(struct stmmac_safety_stats
*stats
,
303 int index
, unsigned long *count
, const char **desc
);
306 #define stmmac_core_init(__priv, __args...) \
307 stmmac_do_void_callback(__priv, mac, core_init, __args)
308 #define stmmac_mac_set(__priv, __args...) \
309 stmmac_do_void_callback(__priv, mac, set_mac, __args)
310 #define stmmac_rx_ipc(__priv, __args...) \
311 stmmac_do_callback(__priv, mac, rx_ipc, __args)
312 #define stmmac_rx_queue_enable(__priv, __args...) \
313 stmmac_do_void_callback(__priv, mac, rx_queue_enable, __args)
314 #define stmmac_rx_queue_prio(__priv, __args...) \
315 stmmac_do_void_callback(__priv, mac, rx_queue_prio, __args)
316 #define stmmac_tx_queue_prio(__priv, __args...) \
317 stmmac_do_void_callback(__priv, mac, tx_queue_prio, __args)
318 #define stmmac_rx_queue_routing(__priv, __args...) \
319 stmmac_do_void_callback(__priv, mac, rx_queue_routing, __args)
320 #define stmmac_prog_mtl_rx_algorithms(__priv, __args...) \
321 stmmac_do_void_callback(__priv, mac, prog_mtl_rx_algorithms, __args)
322 #define stmmac_prog_mtl_tx_algorithms(__priv, __args...) \
323 stmmac_do_void_callback(__priv, mac, prog_mtl_tx_algorithms, __args)
324 #define stmmac_set_mtl_tx_queue_weight(__priv, __args...) \
325 stmmac_do_void_callback(__priv, mac, set_mtl_tx_queue_weight, __args)
326 #define stmmac_map_mtl_to_dma(__priv, __args...) \
327 stmmac_do_void_callback(__priv, mac, map_mtl_to_dma, __args)
328 #define stmmac_config_cbs(__priv, __args...) \
329 stmmac_do_void_callback(__priv, mac, config_cbs, __args)
330 #define stmmac_dump_mac_regs(__priv, __args...) \
331 stmmac_do_void_callback(__priv, mac, dump_regs, __args)
332 #define stmmac_host_irq_status(__priv, __args...) \
333 stmmac_do_callback(__priv, mac, host_irq_status, __args)
334 #define stmmac_host_mtl_irq_status(__priv, __args...) \
335 stmmac_do_callback(__priv, mac, host_mtl_irq_status, __args)
336 #define stmmac_set_filter(__priv, __args...) \
337 stmmac_do_void_callback(__priv, mac, set_filter, __args)
338 #define stmmac_flow_ctrl(__priv, __args...) \
339 stmmac_do_void_callback(__priv, mac, flow_ctrl, __args)
340 #define stmmac_pmt(__priv, __args...) \
341 stmmac_do_void_callback(__priv, mac, pmt, __args)
342 #define stmmac_set_umac_addr(__priv, __args...) \
343 stmmac_do_void_callback(__priv, mac, set_umac_addr, __args)
344 #define stmmac_get_umac_addr(__priv, __args...) \
345 stmmac_do_void_callback(__priv, mac, get_umac_addr, __args)
346 #define stmmac_set_eee_mode(__priv, __args...) \
347 stmmac_do_void_callback(__priv, mac, set_eee_mode, __args)
348 #define stmmac_reset_eee_mode(__priv, __args...) \
349 stmmac_do_void_callback(__priv, mac, reset_eee_mode, __args)
350 #define stmmac_set_eee_timer(__priv, __args...) \
351 stmmac_do_void_callback(__priv, mac, set_eee_timer, __args)
352 #define stmmac_set_eee_pls(__priv, __args...) \
353 stmmac_do_void_callback(__priv, mac, set_eee_pls, __args)
354 #define stmmac_mac_debug(__priv, __args...) \
355 stmmac_do_void_callback(__priv, mac, debug, __args)
356 #define stmmac_pcs_ctrl_ane(__priv, __args...) \
357 stmmac_do_void_callback(__priv, mac, pcs_ctrl_ane, __args)
358 #define stmmac_pcs_rane(__priv, __args...) \
359 stmmac_do_void_callback(__priv, mac, pcs_rane, __args)
360 #define stmmac_pcs_get_adv_lp(__priv, __args...) \
361 stmmac_do_void_callback(__priv, mac, pcs_get_adv_lp, __args)
362 #define stmmac_safety_feat_config(__priv, __args...) \
363 stmmac_do_callback(__priv, mac, safety_feat_config, __args)
364 #define stmmac_safety_feat_irq_status(__priv, __args...) \
365 stmmac_do_callback(__priv, mac, safety_feat_irq_status, __args)
366 #define stmmac_safety_feat_dump(__priv, __args...) \
367 stmmac_do_callback(__priv, mac, safety_feat_dump, __args)
369 #endif /* __STMMAC_HWIF_H__ */