1/* SPDX-License-Identifier: GPL-2.0 */
2/*
3 * Copyright (C) 2020 Marvell International Ltd.
4 *
5 * Functions to configure the BGX MAC.
6 */
7
8#ifndef __CVMX_HELPER_BGX_H__
9#define __CVMX_HELPER_BGX_H__
10
11#define CVMX_BGX_RX_FIFO_SIZE (64 * 1024)
12#define CVMX_BGX_TX_FIFO_SIZE (32 * 1024)
13
14int __cvmx_helper_bgx_enumerate(int xiface);
15
16/**
17 * @INTERNAL
18 * Disable the BGX port
19 *
20 * @param xipd_port IPD port of the BGX interface to disable
21 */
22void cvmx_helper_bgx_disable(int xipd_port);
23
24/**
25 * @INTERNAL
26 * Probe a SGMII interface and determine the number of ports
27 * connected to it. The SGMII/XAUI interface should still be down after
28 * this call. This is used by interfaces using the bgx mac.
29 *
30 * @param xiface Interface to probe
31 *
32 * Return: Number of ports on the interface. Zero to disable.
33 */
34int __cvmx_helper_bgx_probe(int xiface);
35
36/**
37 * @INTERNAL
38 * Bringup and enable a SGMII interface. After this call packet
39 * I/O should be fully functional. This is called with IPD
40 * enabled but PKO disabled. This is used by interfaces using the
41 * bgx mac.
42 *
43 * @param xiface Interface to bring up
44 *
45 * Return: Zero on success, negative on failure
46 */
47int __cvmx_helper_bgx_sgmii_enable(int xiface);
48
49/**
50 * @INTERNAL
51 * Return the link state of an IPD/PKO port as returned by
52 * auto negotiation. The result of this function may not match
53 * Octeon's link config if auto negotiation has changed since
54 * the last call to cvmx_helper_link_set(). This is used by
55 * interfaces using the bgx mac.
56 *
57 * @param xipd_port IPD/PKO port to query
58 *
59 * Return: Link state
60 */
61cvmx_helper_link_info_t __cvmx_helper_bgx_sgmii_link_get(int xipd_port);
62
63/**
64 * @INTERNAL
65 * Configure an IPD/PKO port for the specified link state. This
66 * function does not influence auto negotiation at the PHY level.
67 * The passed link state must always match the link state returned
68 * by cvmx_helper_link_get(). It is normally best to use
69 * cvmx_helper_link_autoconf() instead. This is used by interfaces
70 * using the bgx mac.
71 *
72 * @param xipd_port  IPD/PKO port to configure
73 * @param link_info The new link state
74 *
75 * Return: Zero on success, negative on failure
76 */
77int __cvmx_helper_bgx_sgmii_link_set(int xipd_port, cvmx_helper_link_info_t link_info);
78
79/**
80 * @INTERNAL
81 * Configure a port for internal and/or external loopback. Internal loopback
82 * causes packets sent by the port to be received by Octeon. External loopback
83 * causes packets received from the wire to sent out again. This is used by
84 * interfaces using the bgx mac.
85 *
86 * @param xipd_port IPD/PKO port to loopback.
87 * @param enable_internal
88 *                 Non zero if you want internal loopback
89 * @param enable_external
90 *                 Non zero if you want external loopback
91 *
92 * Return: Zero on success, negative on failure.
93 */
94int __cvmx_helper_bgx_sgmii_configure_loopback(int xipd_port, int enable_internal,
95					       int enable_external);
96
97/**
98 * @INTERNAL
99 * Bringup and enable a XAUI interface. After this call packet
100 * I/O should be fully functional. This is called with IPD
101 * enabled but PKO disabled. This is used by interfaces using the
102 * bgx mac.
103 *
104 * @param xiface Interface to bring up
105 *
106 * Return: Zero on success, negative on failure
107 */
108int __cvmx_helper_bgx_xaui_enable(int xiface);
109
110/**
111 * @INTERNAL
112 * Return the link state of an IPD/PKO port as returned by
113 * auto negotiation. The result of this function may not match
114 * Octeon's link config if auto negotiation has changed since
115 * the last call to cvmx_helper_link_set(). This is used by
116 * interfaces using the bgx mac.
117 *
118 * @param xipd_port IPD/PKO port to query
119 *
120 * Return: Link state
121 */
122cvmx_helper_link_info_t __cvmx_helper_bgx_xaui_link_get(int xipd_port);
123
124/**
125 * @INTERNAL
126 * Configure an IPD/PKO port for the specified link state. This
127 * function does not influence auto negotiation at the PHY level.
128 * The passed link state must always match the link state returned
129 * by cvmx_helper_link_get(). It is normally best to use
130 * cvmx_helper_link_autoconf() instead. This is used by interfaces
131 * using the bgx mac.
132 *
133 * @param xipd_port  IPD/PKO port to configure
134 * @param link_info The new link state
135 *
136 * Return: Zero on success, negative on failure
137 */
138int __cvmx_helper_bgx_xaui_link_set(int xipd_port, cvmx_helper_link_info_t link_info);
139
140/**
141 * @INTERNAL
142 * Configure a port for internal and/or external loopback. Internal loopback
143 * causes packets sent by the port to be received by Octeon. External loopback
144 * causes packets received from the wire to sent out again. This is used by
145 * interfaces using the bgx mac.
146 *
147 * @param xipd_port IPD/PKO port to loopback.
148 * @param enable_internal
149 *                 Non zero if you want internal loopback
150 * @param enable_external
151 *                 Non zero if you want external loopback
152 *
153 * Return: Zero on success, negative on failure.
154 */
155int __cvmx_helper_bgx_xaui_configure_loopback(int xipd_port, int enable_internal,
156					      int enable_external);
157
158int __cvmx_helper_bgx_mixed_enable(int xiface);
159
160cvmx_helper_link_info_t __cvmx_helper_bgx_mixed_link_get(int xipd_port);
161
162int __cvmx_helper_bgx_mixed_link_set(int xipd_port, cvmx_helper_link_info_t link_info);
163
164int __cvmx_helper_bgx_mixed_configure_loopback(int xipd_port, int enable_internal,
165					       int enable_external);
166
167cvmx_helper_interface_mode_t cvmx_helper_bgx_get_mode(int xiface, int index);
168
169/**
170 * @INTERNAL
171 * Configure Priority-Based Flow Control (a.k.a. PFC/CBFC)
172 * on a specific BGX interface/port.
173 */
174void __cvmx_helper_bgx_xaui_config_pfc(unsigned int node, unsigned int interface, unsigned int port,
175				       bool pfc_enable);
176
177/**
178 * This function control how the hardware handles incoming PAUSE
179 * packets. The most common modes of operation:
180 * ctl_bck = 1, ctl_drp = 1: hardware handles everything
181 * ctl_bck = 0, ctl_drp = 0: software sees all PAUSE frames
182 * ctl_bck = 0, ctl_drp = 1: all PAUSE frames are completely ignored
183 * @param node		node number.
184 * @param interface	interface number
185 * @param port		port number
186 * @param ctl_bck	1: Forward PAUSE information to TX block
187 * @param ctl_drp	1: Drop control PAUSE frames.
188 */
189void cvmx_helper_bgx_rx_pause_ctl(unsigned int node, unsigned int interface, unsigned int port,
190				  unsigned int ctl_bck, unsigned int ctl_drp);
191
192/**
193 * This function configures the receive action taken for multicast, broadcast
194 * and dmac filter match packets.
195 * @param node		node number.
196 * @param interface	interface number
197 * @param port		port number
198 * @param cam_accept	0: reject packets on dmac filter match
199 *                      1: accept packet on dmac filter match
200 * @param mcast_mode	0x0 = Force reject all multicast packets
201 *                      0x1 = Force accept all multicast packets
202 *                      0x2 = Use the address filter CAM
203 * @param bcast_accept  0 = Reject all broadcast packets
204 *                      1 = Accept all broadcast packets
205 */
206void cvmx_helper_bgx_rx_adr_ctl(unsigned int node, unsigned int interface, unsigned int port,
207				unsigned int cam_accept, unsigned int mcast_mode,
208				unsigned int bcast_accept);
209
210/**
211 * Function to control the generation of FCS, padding by the BGX
212 *
213 */
214void cvmx_helper_bgx_tx_options(unsigned int node, unsigned int interface, unsigned int index,
215				bool fcs_enable, bool pad_enable);
216
217/**
218 * Set mac for the ipd_port
219 *
220 * @param xipd_port ipd_port to set the mac
221 * @param bcst      If set, accept all broadcast packets
222 * @param mcst      Multicast mode
223 *		    0 = Force reject all multicast packets
224 *		    1 = Force accept all multicast packets
225 *		    2 = use the address filter CAM.
226 * @param mac       mac address for the ipd_port
227 */
228void cvmx_helper_bgx_set_mac(int xipd_port, int bcst, int mcst, u64 mac);
229
230int __cvmx_helper_bgx_port_init(int xipd_port, int phy_pres);
231void cvmx_helper_bgx_set_jabber(int xiface, unsigned int index, unsigned int size);
232int cvmx_helper_bgx_shutdown_port(int xiface, int index);
233int cvmx_bgx_set_backpressure_override(int xiface, unsigned int port_mask);
234int __cvmx_helper_bgx_fifo_size(int xiface, unsigned int lmac);
235
236/**
237 * Returns if an interface is RGMII or not
238 *
239 * @param xiface	xinterface to check
240 * @param index		port index (must be 0 for rgmii)
241 *
242 * Return:	true if RGMII, false otherwise
243 */
244static inline bool cvmx_helper_bgx_is_rgmii(int xiface, int index)
245{
246	union cvmx_bgxx_cmrx_config cmr_config;
247
248	if (!OCTEON_IS_MODEL(OCTEON_CN73XX) || index != 0)
249		return false;
250	cmr_config.u64 = csr_rd(CVMX_BGXX_CMRX_CONFIG(index, xiface));
251	return cmr_config.s.lmac_type == 5;
252}
253
254/**
255 * Probes the BGX Super Path (SMU/SPU) mode
256 *
257 * @param xiface	global interface number
258 * @param index		interface index
259 *
260 * Return:	true, if Super-MAC/PCS mode, false -- otherwise
261 */
262bool cvmx_helper_bgx_is_smu(int xiface, int index);
263
264/**
265 * @INTERNAL
266 * Configure parameters of PAUSE packet.
267 *
268 * @param xipd_port		Global IPD port (node + IPD port).
269 * @param smac			Source MAC address.
270 * @param dmac			Destination MAC address.
271 * @param type			PAUSE packet type.
272 * @param time			Pause time for PAUSE packets (number of 512 bit-times).
273 * @param interval		Interval between PAUSE packets (number of 512 bit-times).
274 * Return: Zero on success, negative on failure.
275 */
276int cvmx_bgx_set_pause_pkt_param(int xipd_port, u64 smac, u64 dmac, unsigned int type,
277				 unsigned int time, unsigned int interval);
278
279/**
280 * @INTERNAL
281 * Setup the BGX flow-control mode.
282 *
283 * @param xipd_port		Global IPD port (node + IPD port).
284 * @param type			Flow-control type/protocol.
285 * @param mode			Flow-control mode.
286 * Return: Zero on success, negative on failure.
287 */
288int cvmx_bgx_set_flowctl_mode(int xipd_port, cvmx_qos_proto_t qos, cvmx_qos_pkt_mode_t mode);
289
290/**
291 * Enables or disables autonegotiation for an interface.
292 *
293 * @param	xiface	interface to set autonegotiation
294 * @param	index	port index
295 * @param	enable	true to enable autonegotiation, false to disable it
296 *
297 * Return:	0 for success, -1 on error.
298 */
299int cvmx_helper_set_autonegotiation(int xiface, int index, bool enable);
300
301/**
302 * Enables or disables forward error correction
303 *
304 * @param	xiface	interface
305 * @param	index	port index
306 * @param	enable	set to true to enable FEC, false to disable
307 *
308 * Return:	0 for success, -1 on error
309 *
310 * @NOTE:	If autonegotiation is enabled then autonegotiation will be
311 *		restarted for negotiating FEC.
312 */
313int cvmx_helper_set_fec(int xiface, int index, bool enable);
314
315#ifdef CVMX_DUMP_BGX
316/**
317 * Dump BGX configuration for node 0
318 */
319int cvmx_dump_bgx_config(unsigned int bgx);
320/**
321 * Dump BGX status for node 0
322 */
323int cvmx_dump_bgx_status(unsigned int bgx);
324/**
325 * Dump BGX configuration
326 */
327int cvmx_dump_bgx_config_node(unsigned int node, unsigned int bgx);
328/**
329 * Dump BGX status
330 */
331int cvmx_dump_bgx_status_node(unsigned int node, unsigned int bgx);
332
333#endif
334
335#endif
336