1/* SPDX-License-Identifier: GPL-2.0 */
2/*
3 * Copyright (C) 2020 Marvell International Ltd.
4 *
5 * Helper functions for PKI
6 */
7
8#ifndef __CVMX_HELPER_PKI_H__
9#define __CVMX_HELPER_PKI_H__
10
11#include "cvmx-pki.h"
12
13/* Modify this if more than 8 ilk channels need to be supported */
14#define CVMX_MAX_PORT_PER_INTERFACE  64
15#define CVMX_MAX_QOS_PRIORITY	     64
16#define CVMX_PKI_FIND_AVAILABLE_RSRC (-1)
17
18struct cvmx_pki_qos_schd {
19	cvmx_fpa3_gaura_t _aura;
20	cvmx_fpa3_pool_t _pool;
21	bool pool_per_qos;
22	int pool_num;
23	char *pool_name;
24	u64 pool_buff_size;
25	u64 pool_max_buff;
26	bool aura_per_qos;
27	int aura_num;
28	char *aura_name;
29	u64 aura_buff_cnt;
30	bool sso_grp_per_qos;
31	int sso_grp;
32	u16 port_add;
33	int qpg_base;
34};
35
36struct cvmx_pki_prt_schd {
37	cvmx_fpa3_pool_t _pool;
38	cvmx_fpa3_gaura_t _aura;
39	bool cfg_port;
40	int style;
41	bool pool_per_prt;
42	int pool_num;
43	char *pool_name;
44	u64 pool_buff_size;
45	u64 pool_max_buff;
46	bool aura_per_prt;
47	int aura_num;
48	char *aura_name;
49	u64 aura_buff_cnt;
50	bool sso_grp_per_prt;
51	int sso_grp;
52	enum cvmx_pki_qpg_qos qpg_qos;
53	int qpg_base;
54	struct cvmx_pki_qos_schd qos_s[CVMX_MAX_QOS_PRIORITY];
55};
56
57struct cvmx_pki_intf_schd {
58	cvmx_fpa3_pool_t _pool;
59	cvmx_fpa3_gaura_t _aura;
60	bool style_per_intf;
61	int style;
62	bool pool_per_intf;
63	int pool_num;
64	char *pool_name;
65	u64 pool_buff_size;
66	u64 pool_max_buff;
67	bool aura_per_intf;
68	int aura_num;
69	char *aura_name;
70	u64 aura_buff_cnt;
71	bool sso_grp_per_intf;
72	int sso_grp;
73	bool qos_share_aura;
74	bool qos_share_grp;
75	int qpg_base;
76	struct cvmx_pki_prt_schd prt_s[CVMX_MAX_PORT_PER_INTERFACE];
77};
78
79struct cvmx_pki_global_schd {
80	bool setup_pool;
81	int pool_num;
82	char *pool_name;
83	u64 pool_buff_size;
84	u64 pool_max_buff;
85	bool setup_aura;
86	int aura_num;
87	char *aura_name;
88	u64 aura_buff_cnt;
89	bool setup_sso_grp;
90	int sso_grp;
91	cvmx_fpa3_pool_t _pool;
92	cvmx_fpa3_gaura_t _aura;
93};
94
95struct cvmx_pki_legacy_qos_watcher {
96	bool configured;
97	enum cvmx_pki_term field;
98	u32 data;
99	u32 data_mask;
100	u8 advance;
101	u8 sso_grp;
102};
103
104extern bool cvmx_pki_dflt_init[CVMX_MAX_NODES];
105
106extern struct cvmx_pki_pool_config pki_dflt_pool[CVMX_MAX_NODES];
107extern struct cvmx_pki_aura_config pki_dflt_aura[CVMX_MAX_NODES];
108extern struct cvmx_pki_style_config pki_dflt_style[CVMX_MAX_NODES];
109extern struct cvmx_pki_pkind_config pki_dflt_pkind[CVMX_MAX_NODES];
110extern u64 pkind_style_map[CVMX_MAX_NODES][CVMX_PKI_NUM_PKIND];
111extern struct cvmx_pki_sso_grp_config pki_dflt_sso_grp[CVMX_MAX_NODES];
112extern struct cvmx_pki_legacy_qos_watcher qos_watcher[8];
113
114/**
115 * This function Enabled the PKI hardware to
116 * start accepting/processing packets.
117 * @param node    node number
118 */
119void cvmx_helper_pki_enable(int node);
120
121/**
122 * This function frees up PKI resources consumed by that port.
123 * This function should only be called if port resources
124 * (fpa pools aura, style qpg entry pcam entry etc.) are not shared
125 * @param xipd_port     ipd port number for which resources need to
126 *                      be freed.
127 */
128int cvmx_helper_pki_port_shutdown(int xipd_port);
129
130/**
131 * This function shuts down complete PKI hardware
132 * and software resources.
133 * @param node          node number where PKI needs to shutdown.
134 */
135void cvmx_helper_pki_shutdown(int node);
136
137/**
138 * This function calculates how mant qpf entries will be needed for
139 * a particular QOS.
140 * @param qpg_qos       qos value for which entries need to be calculated.
141 */
142int cvmx_helper_pki_get_num_qpg_entry(enum cvmx_pki_qpg_qos qpg_qos);
143
144/**
145 * This function setups the qos table by allocating qpg entry and writing
146 * the provided parameters to that entry (offset).
147 * @param node          node number.
148 * @param qpg_cfg       pointer to struct containing qpg configuration
149 */
150int cvmx_helper_pki_set_qpg_entry(int node, struct cvmx_pki_qpg_config *qpg_cfg);
151
152/**
153 * This function sets up aura QOS for RED, backpressure and tail-drop.
154 *
155 * @param node       node number.
156 * @param aura       aura to configure.
157 * @param ena_red       enable RED based on [DROP] and [PASS] levels
158 *			1: enable 0:disable
159 * @param pass_thresh   pass threshold for RED.
160 * @param drop_thresh   drop threshold for RED
161 * @param ena_bp        enable backpressure based on [BP] level.
162 *			1:enable 0:disable
163 * @param bp_thresh     backpressure threshold.
164 * @param ena_drop      enable tail drop.
165 *			1:enable 0:disable
166 * Return: Zero on success. Negative on failure
167 */
168int cvmx_helper_setup_aura_qos(int node, int aura, bool ena_red, bool ena_drop, u64 pass_thresh,
169			       u64 drop_thresh, bool ena_bp, u64 bp_thresh);
170
171/**
172 * This function maps specified bpid to all the auras from which it can receive bp and
173 * then maps that bpid to all the channels, that bpid can asserrt bp on.
174 *
175 * @param node          node number.
176 * @param aura          aura number which will back pressure specified bpid.
177 * @param bpid          bpid to map.
178 * @param chl_map       array of channels to map to that bpid.
179 * @param chl_cnt	number of channel/ports to map to that bpid.
180 * Return: Zero on success. Negative on failure
181 */
182int cvmx_helper_pki_map_aura_chl_bpid(int node, u16 aura, u16 bpid, u16 chl_map[], u16 chl_cnt);
183
184/**
185 * This function sets up the global pool, aura and sso group
186 * resources which application can use between any interfaces
187 * and ports.
188 * @param node          node number
189 * @param gblsch        pointer to struct containing global
190 *                      scheduling parameters.
191 */
192int cvmx_helper_pki_set_gbl_schd(int node, struct cvmx_pki_global_schd *gblsch);
193
194/**
195 * This function sets up scheduling parameters (pool, aura, sso group etc)
196 * of an ipd port.
197 * @param xipd_port     ipd port number
198 * @param prtsch        pointer to struct containing port's
199 *                      scheduling parameters.
200 */
201int cvmx_helper_pki_init_port(int xipd_port, struct cvmx_pki_prt_schd *prtsch);
202
203/**
204 * This function sets up scheduling parameters (pool, aura, sso group etc)
205 * of an interface (all ports/channels on that interface).
206 * @param xiface        interface number with node.
207 * @param intfsch      pointer to struct containing interface
208 *                      scheduling parameters.
209 * @param gblsch       pointer to struct containing global scheduling parameters
210 *                      (can be NULL if not used)
211 */
212int cvmx_helper_pki_init_interface(const int xiface, struct cvmx_pki_intf_schd *intfsch,
213				   struct cvmx_pki_global_schd *gblsch);
214/**
215 * This function gets all the PKI parameters related to that
216 * particular port from hardware.
217 * @param xipd_port     ipd port number to get parameter of
218 * @param port_cfg      pointer to structure where to store read parameters
219 */
220void cvmx_pki_get_port_config(int xipd_port, struct cvmx_pki_port_config *port_cfg);
221
222/**
223 * This function sets all the PKI parameters related to that
224 * particular port in hardware.
225 * @param xipd_port     ipd port number to get parameter of
226 * @param port_cfg      pointer to structure containing port parameters
227 */
228void cvmx_pki_set_port_config(int xipd_port, struct cvmx_pki_port_config *port_cfg);
229
230/**
231 * This function displays all the PKI parameters related to that
232 * particular port.
233 * @param xipd_port      ipd port number to display parameter of
234 */
235void cvmx_pki_show_port_config(int xipd_port);
236
237/**
238 * Modifies maximum frame length to check.
239 * It modifies the global frame length set used by this port, any other
240 * port using the same set will get affected too.
241 * @param xipd_port	ipd port for which to modify max len.
242 * @param max_size	maximum frame length
243 */
244void cvmx_pki_set_max_frm_len(int xipd_port, u32 max_size);
245
246/**
247 * This function sets up all the ports of particular interface
248 * for chosen fcs mode. (only use for backward compatibility).
249 * New application can control it via init_interface calls.
250 * @param node          node number.
251 * @param interface     interface number.
252 * @param nports        number of ports
253 * @param has_fcs       1 -- enable fcs check and fcs strip.
254 *                      0 -- disable fcs check.
255 */
256void cvmx_helper_pki_set_fcs_op(int node, int interface, int nports, int has_fcs);
257
258/**
259 * This function sets the wqe buffer mode of all ports. First packet data buffer can reside
260 * either in same buffer as wqe OR it can go in separate buffer. If used the later mode,
261 * make sure software allocate enough buffers to now have wqe separate from packet data.
262 * @param node	                node number.
263 * @param pkt_outside_wqe	0 = The packet link pointer will be at word [FIRST_SKIP]
264 *				    immediately followed by packet data, in the same buffer
265 *				    as the work queue entry.
266 *				1 = The packet link pointer will be at word [FIRST_SKIP] in a new
267 *				    buffer separate from the work queue entry. Words following the
268 *				    WQE in the same cache line will be zeroed, other lines in the
269 *				    buffer will not be modified and will retain stale data (from the
270 *				    buffer's previous use). This setting may decrease the peak PKI
271 *				    performance by up to half on small packets.
272 */
273void cvmx_helper_pki_set_wqe_mode(int node, bool pkt_outside_wqe);
274
275/**
276 * This function sets the Packet mode of all ports and styles to little-endian.
277 * It Changes write operations of packet data to L2C to
278 * be in little-endian. Does not change the WQE header format, which is
279 * properly endian neutral.
280 * @param node	                node number.
281 */
282void cvmx_helper_pki_set_little_endian(int node);
283
284void cvmx_helper_pki_set_dflt_pool(int node, int pool, int buffer_size, int buffer_count);
285void cvmx_helper_pki_set_dflt_aura(int node, int aura, int pool, int buffer_count);
286void cvmx_helper_pki_set_dflt_pool_buffer(int node, int buffer_count);
287
288void cvmx_helper_pki_set_dflt_aura_buffer(int node, int buffer_count);
289
290void cvmx_helper_pki_set_dflt_pkind_map(int node, int pkind, int style);
291
292void cvmx_helper_pki_get_dflt_style(int node, struct cvmx_pki_style_config *style_cfg);
293void cvmx_helper_pki_set_dflt_style(int node, struct cvmx_pki_style_config *style_cfg);
294
295void cvmx_helper_pki_get_dflt_qpg(int node, struct cvmx_pki_qpg_config *qpg_cfg);
296void cvmx_helper_pki_set_dflt_qpg(int node, struct cvmx_pki_qpg_config *qpg_cfg);
297
298void cvmx_helper_pki_no_dflt_init(int node);
299
300void cvmx_helper_pki_set_dflt_bp_en(int node, bool bp_en);
301
302void cvmx_pki_dump_wqe(const cvmx_wqe_78xx_t *wqp);
303
304int __cvmx_helper_pki_port_setup(int node, int xipd_port);
305
306int __cvmx_helper_pki_global_setup(int node);
307void cvmx_helper_pki_show_port_config(int xipd_port);
308
309int __cvmx_helper_pki_install_dflt_vlan(int node);
310void __cvmx_helper_pki_set_dflt_ltype_map(int node);
311int cvmx_helper_pki_route_dmac(int node, int style, u64 mac_addr, u64 mac_addr_mask,
312			       int final_style);
313int cvmx_pki_clone_style(int node, int style, u64 cluster_mask);
314void cvmx_helper_pki_modify_prtgrp(int xipd_port, int grp_ok, int grp_bad);
315int cvmx_helper_pki_route_prt_dmac(int xipd_port, u64 mac_addr, u64 mac_addr_mask, int grp);
316
317void cvmx_helper_pki_errata(int node);
318
319#endif /* __CVMX_HELPER_PKI_H__ */
320