xref: /dpdk/drivers/common/cnxk/roc_mcs_sec_cfg.c (revision 010db30feea1d6f5cef9668131c18c9370c1cf8b)
12211ef84SAkhil Goyal /* SPDX-License-Identifier: BSD-3-Clause
22211ef84SAkhil Goyal  * Copyright(C) 2023 Marvell.
32211ef84SAkhil Goyal  */
42211ef84SAkhil Goyal 
52211ef84SAkhil Goyal #include "roc_api.h"
62211ef84SAkhil Goyal #include "roc_priv.h"
72211ef84SAkhil Goyal 
82211ef84SAkhil Goyal int
roc_mcs_rsrc_alloc(struct roc_mcs * mcs,struct roc_mcs_alloc_rsrc_req * req,struct roc_mcs_alloc_rsrc_rsp * rsp)92211ef84SAkhil Goyal roc_mcs_rsrc_alloc(struct roc_mcs *mcs, struct roc_mcs_alloc_rsrc_req *req,
102211ef84SAkhil Goyal 		   struct roc_mcs_alloc_rsrc_rsp *rsp)
112211ef84SAkhil Goyal {
122211ef84SAkhil Goyal 	struct mcs_priv *priv = roc_mcs_to_mcs_priv(mcs);
132211ef84SAkhil Goyal 	struct mcs_alloc_rsrc_req *rsrc_req;
142211ef84SAkhil Goyal 	struct mcs_alloc_rsrc_rsp *rsrc_rsp;
152211ef84SAkhil Goyal 	int rc, i;
162211ef84SAkhil Goyal 
172211ef84SAkhil Goyal 	MCS_SUPPORT_CHECK;
182211ef84SAkhil Goyal 
192211ef84SAkhil Goyal 	if (req == NULL || rsp == NULL)
202211ef84SAkhil Goyal 		return -EINVAL;
212211ef84SAkhil Goyal 
222211ef84SAkhil Goyal 	rsrc_req = mbox_alloc_msg_mcs_alloc_resources(mcs->mbox);
232211ef84SAkhil Goyal 	if (rsrc_req == NULL)
242211ef84SAkhil Goyal 		return -ENOMEM;
252211ef84SAkhil Goyal 
262211ef84SAkhil Goyal 	rsrc_req->rsrc_type = req->rsrc_type;
272211ef84SAkhil Goyal 	rsrc_req->rsrc_cnt = req->rsrc_cnt;
282211ef84SAkhil Goyal 	rsrc_req->mcs_id = mcs->idx;
292211ef84SAkhil Goyal 	rsrc_req->dir = req->dir;
302211ef84SAkhil Goyal 	rsrc_req->all = req->all;
312211ef84SAkhil Goyal 
322211ef84SAkhil Goyal 	rc = mbox_process_msg(mcs->mbox, (void *)&rsrc_rsp);
332211ef84SAkhil Goyal 	if (rc)
342211ef84SAkhil Goyal 		return rc;
352211ef84SAkhil Goyal 
362211ef84SAkhil Goyal 	if (rsrc_rsp->all) {
372211ef84SAkhil Goyal 		rsrc_rsp->rsrc_cnt = 1;
382211ef84SAkhil Goyal 		rsrc_rsp->rsrc_type = 0xFF;
392211ef84SAkhil Goyal 	}
402211ef84SAkhil Goyal 
412211ef84SAkhil Goyal 	for (i = 0; i < rsrc_rsp->rsrc_cnt; i++) {
422211ef84SAkhil Goyal 		switch (rsrc_rsp->rsrc_type) {
432211ef84SAkhil Goyal 		case MCS_RSRC_TYPE_FLOWID:
442211ef84SAkhil Goyal 			rsp->flow_ids[i] = rsrc_rsp->flow_ids[i];
452211ef84SAkhil Goyal 			plt_bitmap_set(priv->dev_rsrc.tcam_bmap,
462211ef84SAkhil Goyal 				       rsp->flow_ids[i] +
472211ef84SAkhil Goyal 					       ((req->dir == MCS_TX) ? priv->tcam_entries : 0));
482211ef84SAkhil Goyal 			break;
492211ef84SAkhil Goyal 		case MCS_RSRC_TYPE_SECY:
502211ef84SAkhil Goyal 			rsp->secy_ids[i] = rsrc_rsp->secy_ids[i];
512211ef84SAkhil Goyal 			plt_bitmap_set(priv->dev_rsrc.secy_bmap,
522211ef84SAkhil Goyal 				       rsp->secy_ids[i] +
532211ef84SAkhil Goyal 					       ((req->dir == MCS_TX) ? priv->secy_entries : 0));
542211ef84SAkhil Goyal 			break;
552211ef84SAkhil Goyal 		case MCS_RSRC_TYPE_SC:
562211ef84SAkhil Goyal 			rsp->sc_ids[i] = rsrc_rsp->sc_ids[i];
572211ef84SAkhil Goyal 			plt_bitmap_set(priv->dev_rsrc.sc_bmap,
582211ef84SAkhil Goyal 				       rsp->sc_ids[i] +
592211ef84SAkhil Goyal 					       ((req->dir == MCS_TX) ? priv->sc_entries : 0));
602211ef84SAkhil Goyal 			break;
612211ef84SAkhil Goyal 		case MCS_RSRC_TYPE_SA:
622211ef84SAkhil Goyal 			rsp->sa_ids[i] = rsrc_rsp->sa_ids[i];
632211ef84SAkhil Goyal 			plt_bitmap_set(priv->dev_rsrc.sa_bmap,
642211ef84SAkhil Goyal 				       rsp->sa_ids[i] +
652211ef84SAkhil Goyal 					       ((req->dir == MCS_TX) ? priv->sa_entries : 0));
662211ef84SAkhil Goyal 			break;
672211ef84SAkhil Goyal 		default:
682211ef84SAkhil Goyal 			rsp->flow_ids[i] = rsrc_rsp->flow_ids[i];
692211ef84SAkhil Goyal 			rsp->secy_ids[i] = rsrc_rsp->secy_ids[i];
702211ef84SAkhil Goyal 			rsp->sc_ids[i] = rsrc_rsp->sc_ids[i];
712211ef84SAkhil Goyal 			rsp->sa_ids[i] = rsrc_rsp->sa_ids[i];
722211ef84SAkhil Goyal 			plt_bitmap_set(priv->dev_rsrc.tcam_bmap,
732211ef84SAkhil Goyal 				       rsp->flow_ids[i] +
742211ef84SAkhil Goyal 					       ((req->dir == MCS_TX) ? priv->tcam_entries : 0));
752211ef84SAkhil Goyal 			plt_bitmap_set(priv->dev_rsrc.secy_bmap,
762211ef84SAkhil Goyal 				       rsp->secy_ids[i] +
772211ef84SAkhil Goyal 					       ((req->dir == MCS_TX) ? priv->secy_entries : 0));
782211ef84SAkhil Goyal 			plt_bitmap_set(priv->dev_rsrc.sc_bmap,
792211ef84SAkhil Goyal 				       rsp->sc_ids[i] +
802211ef84SAkhil Goyal 					       ((req->dir == MCS_TX) ? priv->sc_entries : 0));
812211ef84SAkhil Goyal 			plt_bitmap_set(priv->dev_rsrc.sa_bmap,
822211ef84SAkhil Goyal 				       rsp->sa_ids[i] +
832211ef84SAkhil Goyal 					       ((req->dir == MCS_TX) ? priv->sa_entries : 0));
842211ef84SAkhil Goyal 			break;
852211ef84SAkhil Goyal 		}
862211ef84SAkhil Goyal 	}
872211ef84SAkhil Goyal 	rsp->rsrc_type = rsrc_rsp->rsrc_type;
882211ef84SAkhil Goyal 	rsp->rsrc_cnt = rsrc_rsp->rsrc_cnt;
892211ef84SAkhil Goyal 	rsp->dir = rsrc_rsp->dir;
902211ef84SAkhil Goyal 	rsp->all = rsrc_rsp->all;
912211ef84SAkhil Goyal 
922211ef84SAkhil Goyal 	return 0;
932211ef84SAkhil Goyal }
942211ef84SAkhil Goyal 
952211ef84SAkhil Goyal int
roc_mcs_rsrc_free(struct roc_mcs * mcs,struct roc_mcs_free_rsrc_req * free_req)962211ef84SAkhil Goyal roc_mcs_rsrc_free(struct roc_mcs *mcs, struct roc_mcs_free_rsrc_req *free_req)
972211ef84SAkhil Goyal {
982211ef84SAkhil Goyal 	struct mcs_priv *priv = roc_mcs_to_mcs_priv(mcs);
992211ef84SAkhil Goyal 	struct mcs_free_rsrc_req *req;
1002211ef84SAkhil Goyal 	struct msg_rsp *rsp;
1012211ef84SAkhil Goyal 	uint32_t pos;
1022211ef84SAkhil Goyal 	int i, rc;
1032211ef84SAkhil Goyal 
1042211ef84SAkhil Goyal 	MCS_SUPPORT_CHECK;
1052211ef84SAkhil Goyal 
1062211ef84SAkhil Goyal 	if (free_req == NULL)
1072211ef84SAkhil Goyal 		return -EINVAL;
1082211ef84SAkhil Goyal 
1092211ef84SAkhil Goyal 	req = mbox_alloc_msg_mcs_free_resources(mcs->mbox);
1102211ef84SAkhil Goyal 	if (req == NULL)
1112211ef84SAkhil Goyal 		return -ENOMEM;
1122211ef84SAkhil Goyal 
1132211ef84SAkhil Goyal 	req->rsrc_id = free_req->rsrc_id;
1142211ef84SAkhil Goyal 	req->rsrc_type = free_req->rsrc_type;
1152211ef84SAkhil Goyal 	req->mcs_id = mcs->idx;
1162211ef84SAkhil Goyal 	req->dir = free_req->dir;
1172211ef84SAkhil Goyal 	req->all = free_req->all;
1182211ef84SAkhil Goyal 
1192211ef84SAkhil Goyal 	rc = mbox_process_msg(mcs->mbox, (void *)&rsp);
1202211ef84SAkhil Goyal 	if (rc)
1212211ef84SAkhil Goyal 		return rc;
1222211ef84SAkhil Goyal 
1232211ef84SAkhil Goyal 	switch (free_req->rsrc_type) {
1242211ef84SAkhil Goyal 	case MCS_RSRC_TYPE_FLOWID:
1252211ef84SAkhil Goyal 		pos = free_req->rsrc_id + ((req->dir == MCS_TX) ? priv->tcam_entries : 0);
1262211ef84SAkhil Goyal 		plt_bitmap_clear(priv->dev_rsrc.tcam_bmap, pos);
1272211ef84SAkhil Goyal 		for (i = 0; i < MAX_PORTS_PER_MCS; i++) {
1282211ef84SAkhil Goyal 			uint32_t set = plt_bitmap_get(priv->port_rsrc[i].tcam_bmap, pos);
1292211ef84SAkhil Goyal 
1302211ef84SAkhil Goyal 			if (set) {
1312211ef84SAkhil Goyal 				plt_bitmap_clear(priv->port_rsrc[i].tcam_bmap, pos);
1322211ef84SAkhil Goyal 				break;
1332211ef84SAkhil Goyal 			}
1342211ef84SAkhil Goyal 		}
1352211ef84SAkhil Goyal 		break;
1362211ef84SAkhil Goyal 	case MCS_RSRC_TYPE_SECY:
1372211ef84SAkhil Goyal 		pos = free_req->rsrc_id + ((req->dir == MCS_TX) ? priv->secy_entries : 0);
1382211ef84SAkhil Goyal 		plt_bitmap_clear(priv->dev_rsrc.secy_bmap, pos);
1392211ef84SAkhil Goyal 		for (i = 0; i < MAX_PORTS_PER_MCS; i++) {
1402211ef84SAkhil Goyal 			uint32_t set = plt_bitmap_get(priv->port_rsrc[i].secy_bmap, pos);
1412211ef84SAkhil Goyal 
1422211ef84SAkhil Goyal 			if (set) {
1432211ef84SAkhil Goyal 				plt_bitmap_clear(priv->port_rsrc[i].secy_bmap, pos);
1442211ef84SAkhil Goyal 				break;
1452211ef84SAkhil Goyal 			}
1462211ef84SAkhil Goyal 		}
1472211ef84SAkhil Goyal 		break;
1482211ef84SAkhil Goyal 	case MCS_RSRC_TYPE_SC:
1492211ef84SAkhil Goyal 		pos = free_req->rsrc_id + ((req->dir == MCS_TX) ? priv->sc_entries : 0);
1502211ef84SAkhil Goyal 		plt_bitmap_clear(priv->dev_rsrc.sc_bmap, pos);
1512211ef84SAkhil Goyal 		for (i = 0; i < MAX_PORTS_PER_MCS; i++) {
1522211ef84SAkhil Goyal 			uint32_t set = plt_bitmap_get(priv->port_rsrc[i].sc_bmap, pos);
1532211ef84SAkhil Goyal 
1542211ef84SAkhil Goyal 			if (set) {
1552211ef84SAkhil Goyal 				plt_bitmap_clear(priv->port_rsrc[i].sc_bmap, pos);
1562211ef84SAkhil Goyal 				break;
1572211ef84SAkhil Goyal 			}
1582211ef84SAkhil Goyal 		}
1592211ef84SAkhil Goyal 		break;
1602211ef84SAkhil Goyal 	case MCS_RSRC_TYPE_SA:
1612211ef84SAkhil Goyal 		pos = free_req->rsrc_id + ((req->dir == MCS_TX) ? priv->sa_entries : 0);
1622211ef84SAkhil Goyal 		plt_bitmap_clear(priv->dev_rsrc.sa_bmap, pos);
1632211ef84SAkhil Goyal 		for (i = 0; i < MAX_PORTS_PER_MCS; i++) {
1642211ef84SAkhil Goyal 			uint32_t set = plt_bitmap_get(priv->port_rsrc[i].sa_bmap, pos);
1652211ef84SAkhil Goyal 
1662211ef84SAkhil Goyal 			if (set) {
1672211ef84SAkhil Goyal 				plt_bitmap_clear(priv->port_rsrc[i].sa_bmap, pos);
1682211ef84SAkhil Goyal 				break;
1692211ef84SAkhil Goyal 			}
1702211ef84SAkhil Goyal 		}
1712211ef84SAkhil Goyal 		break;
1722211ef84SAkhil Goyal 	default:
1732211ef84SAkhil Goyal 		break;
1742211ef84SAkhil Goyal 	}
1752211ef84SAkhil Goyal 
1762211ef84SAkhil Goyal 	return rc;
1772211ef84SAkhil Goyal }
1782211ef84SAkhil Goyal 
1792211ef84SAkhil Goyal int
roc_mcs_sa_policy_write(struct roc_mcs * mcs,struct roc_mcs_sa_plcy_write_req * sa_plcy)1802211ef84SAkhil Goyal roc_mcs_sa_policy_write(struct roc_mcs *mcs, struct roc_mcs_sa_plcy_write_req *sa_plcy)
1812211ef84SAkhil Goyal {
1822211ef84SAkhil Goyal 	struct mcs_sa_plcy_write_req *sa;
1832211ef84SAkhil Goyal 	struct msg_rsp *rsp;
1842211ef84SAkhil Goyal 
1852211ef84SAkhil Goyal 	MCS_SUPPORT_CHECK;
1862211ef84SAkhil Goyal 
1872211ef84SAkhil Goyal 	if (sa_plcy == NULL)
1882211ef84SAkhil Goyal 		return -EINVAL;
1892211ef84SAkhil Goyal 
1902211ef84SAkhil Goyal 	sa = mbox_alloc_msg_mcs_sa_plcy_write(mcs->mbox);
1912211ef84SAkhil Goyal 	if (sa == NULL)
1922211ef84SAkhil Goyal 		return -ENOMEM;
1932211ef84SAkhil Goyal 
1942211ef84SAkhil Goyal 	mbox_memcpy(sa->plcy, sa_plcy->plcy, sizeof(uint64_t) * 2 * 9);
1952211ef84SAkhil Goyal 	sa->sa_index[0] = sa_plcy->sa_index[0];
1962211ef84SAkhil Goyal 	sa->sa_index[1] = sa_plcy->sa_index[1];
1972211ef84SAkhil Goyal 	sa->sa_cnt = sa_plcy->sa_cnt;
1982211ef84SAkhil Goyal 	sa->mcs_id = mcs->idx;
1992211ef84SAkhil Goyal 	sa->dir = sa_plcy->dir;
2002211ef84SAkhil Goyal 
2012211ef84SAkhil Goyal 	return mbox_process_msg(mcs->mbox, (void *)&rsp);
2022211ef84SAkhil Goyal }
2032211ef84SAkhil Goyal 
2042211ef84SAkhil Goyal int
roc_mcs_sa_policy_read(struct roc_mcs * mcs __plt_unused,struct roc_mcs_sa_plcy_write_req * sa __plt_unused)2052211ef84SAkhil Goyal roc_mcs_sa_policy_read(struct roc_mcs *mcs __plt_unused,
2062211ef84SAkhil Goyal 		       struct roc_mcs_sa_plcy_write_req *sa __plt_unused)
2072211ef84SAkhil Goyal {
2082211ef84SAkhil Goyal 	MCS_SUPPORT_CHECK;
2092211ef84SAkhil Goyal 
2102211ef84SAkhil Goyal 	return -ENOTSUP;
2112211ef84SAkhil Goyal }
212f4bf4780SAkhil Goyal 
213e4a6ea54SAkhil Goyal int
roc_mcs_pn_table_write(struct roc_mcs * mcs,struct roc_mcs_pn_table_write_req * pn_table)214e4a6ea54SAkhil Goyal roc_mcs_pn_table_write(struct roc_mcs *mcs, struct roc_mcs_pn_table_write_req *pn_table)
215e4a6ea54SAkhil Goyal {
216e4a6ea54SAkhil Goyal 	struct mcs_pn_table_write_req *pn;
217e4a6ea54SAkhil Goyal 	struct msg_rsp *rsp;
218e4a6ea54SAkhil Goyal 
219e4a6ea54SAkhil Goyal 	MCS_SUPPORT_CHECK;
220e4a6ea54SAkhil Goyal 
221e4a6ea54SAkhil Goyal 	if (pn_table == NULL)
222e4a6ea54SAkhil Goyal 		return -EINVAL;
223e4a6ea54SAkhil Goyal 
224e4a6ea54SAkhil Goyal 	pn = mbox_alloc_msg_mcs_pn_table_write(mcs->mbox);
225e4a6ea54SAkhil Goyal 	if (pn == NULL)
226e4a6ea54SAkhil Goyal 		return -ENOMEM;
227e4a6ea54SAkhil Goyal 
228e4a6ea54SAkhil Goyal 	pn->next_pn = pn_table->next_pn;
229e4a6ea54SAkhil Goyal 	pn->pn_id = pn_table->pn_id;
230e4a6ea54SAkhil Goyal 	pn->mcs_id = mcs->idx;
231e4a6ea54SAkhil Goyal 	pn->dir = pn_table->dir;
232e4a6ea54SAkhil Goyal 
233e4a6ea54SAkhil Goyal 	return mbox_process_msg(mcs->mbox, (void *)&rsp);
234e4a6ea54SAkhil Goyal }
235e4a6ea54SAkhil Goyal 
236e4a6ea54SAkhil Goyal int
roc_mcs_pn_table_read(struct roc_mcs * mcs __plt_unused,struct roc_mcs_pn_table_write_req * sa __plt_unused)237e4a6ea54SAkhil Goyal roc_mcs_pn_table_read(struct roc_mcs *mcs __plt_unused,
238e4a6ea54SAkhil Goyal 		      struct roc_mcs_pn_table_write_req *sa __plt_unused)
239e4a6ea54SAkhil Goyal {
240e4a6ea54SAkhil Goyal 	MCS_SUPPORT_CHECK;
241e4a6ea54SAkhil Goyal 
242e4a6ea54SAkhil Goyal 	return -ENOTSUP;
243e4a6ea54SAkhil Goyal }
244f4bf4780SAkhil Goyal 
245f4bf4780SAkhil Goyal int
roc_mcs_rx_sc_cam_write(struct roc_mcs * mcs,struct roc_mcs_rx_sc_cam_write_req * rx_sc_cam)246f4bf4780SAkhil Goyal roc_mcs_rx_sc_cam_write(struct roc_mcs *mcs, struct roc_mcs_rx_sc_cam_write_req *rx_sc_cam)
247f4bf4780SAkhil Goyal {
248f4bf4780SAkhil Goyal 	struct mcs_priv *priv = roc_mcs_to_mcs_priv(mcs);
249f4bf4780SAkhil Goyal 	struct mcs_rx_sc_cam_write_req *rx_sc;
250f4bf4780SAkhil Goyal 	struct msg_rsp *rsp;
251f4bf4780SAkhil Goyal 	int i, rc;
252f4bf4780SAkhil Goyal 
253f4bf4780SAkhil Goyal 	MCS_SUPPORT_CHECK;
254f4bf4780SAkhil Goyal 
255f4bf4780SAkhil Goyal 	if (rx_sc_cam == NULL)
256f4bf4780SAkhil Goyal 		return -EINVAL;
257f4bf4780SAkhil Goyal 
258f4bf4780SAkhil Goyal 	rx_sc = mbox_alloc_msg_mcs_rx_sc_cam_write(mcs->mbox);
259f4bf4780SAkhil Goyal 	if (rx_sc == NULL)
260f4bf4780SAkhil Goyal 		return -ENOMEM;
261f4bf4780SAkhil Goyal 
262f4bf4780SAkhil Goyal 	rx_sc->sci = rx_sc_cam->sci;
263f4bf4780SAkhil Goyal 	rx_sc->secy_id = rx_sc_cam->secy_id;
264f4bf4780SAkhil Goyal 	rx_sc->sc_id = rx_sc_cam->sc_id;
265f4bf4780SAkhil Goyal 	rx_sc->mcs_id = mcs->idx;
266f4bf4780SAkhil Goyal 
267f4bf4780SAkhil Goyal 	rc = mbox_process_msg(mcs->mbox, (void *)&rsp);
268f4bf4780SAkhil Goyal 	if (rc)
269f4bf4780SAkhil Goyal 		return rc;
270f4bf4780SAkhil Goyal 
271f4bf4780SAkhil Goyal 	for (i = 0; i < MAX_PORTS_PER_MCS; i++) {
272f4bf4780SAkhil Goyal 		uint32_t set = plt_bitmap_get(priv->port_rsrc[i].secy_bmap, rx_sc_cam->secy_id);
273f4bf4780SAkhil Goyal 
274f4bf4780SAkhil Goyal 		if (set) {
275f4bf4780SAkhil Goyal 			plt_bitmap_set(priv->port_rsrc[i].sc_bmap, rx_sc_cam->sc_id);
276f4bf4780SAkhil Goyal 			break;
277f4bf4780SAkhil Goyal 		}
278f4bf4780SAkhil Goyal 	}
279f4bf4780SAkhil Goyal 
280f4bf4780SAkhil Goyal 	return 0;
281f4bf4780SAkhil Goyal }
282f4bf4780SAkhil Goyal 
283f4bf4780SAkhil Goyal int
roc_mcs_rx_sc_cam_read(struct roc_mcs * mcs __plt_unused,struct roc_mcs_rx_sc_cam_write_req * rx_sc_cam __plt_unused)284f4bf4780SAkhil Goyal roc_mcs_rx_sc_cam_read(struct roc_mcs *mcs __plt_unused,
285f4bf4780SAkhil Goyal 		       struct roc_mcs_rx_sc_cam_write_req *rx_sc_cam __plt_unused)
286f4bf4780SAkhil Goyal {
287f4bf4780SAkhil Goyal 	MCS_SUPPORT_CHECK;
288f4bf4780SAkhil Goyal 
289f4bf4780SAkhil Goyal 	return -ENOTSUP;
290f4bf4780SAkhil Goyal }
291f4bf4780SAkhil Goyal 
292f4bf4780SAkhil Goyal int
roc_mcs_rx_sc_cam_enable(struct roc_mcs * mcs __plt_unused,struct roc_mcs_rx_sc_cam_write_req * rx_sc_cam __plt_unused)293f4bf4780SAkhil Goyal roc_mcs_rx_sc_cam_enable(struct roc_mcs *mcs __plt_unused,
294f4bf4780SAkhil Goyal 			 struct roc_mcs_rx_sc_cam_write_req *rx_sc_cam __plt_unused)
295f4bf4780SAkhil Goyal {
296f4bf4780SAkhil Goyal 	MCS_SUPPORT_CHECK;
297f4bf4780SAkhil Goyal 
298f4bf4780SAkhil Goyal 	return -ENOTSUP;
299f4bf4780SAkhil Goyal }
300f4bf4780SAkhil Goyal 
301f4bf4780SAkhil Goyal int
roc_mcs_secy_policy_write(struct roc_mcs * mcs,struct roc_mcs_secy_plcy_write_req * secy_plcy)302ee71a3b2SAkhil Goyal roc_mcs_secy_policy_write(struct roc_mcs *mcs, struct roc_mcs_secy_plcy_write_req *secy_plcy)
303ee71a3b2SAkhil Goyal {
304ee71a3b2SAkhil Goyal 	struct mcs_secy_plcy_write_req *secy;
305ee71a3b2SAkhil Goyal 	struct msg_rsp *rsp;
306ee71a3b2SAkhil Goyal 
307ee71a3b2SAkhil Goyal 	MCS_SUPPORT_CHECK;
308ee71a3b2SAkhil Goyal 
309ee71a3b2SAkhil Goyal 	if (secy_plcy == NULL)
310ee71a3b2SAkhil Goyal 		return -EINVAL;
311ee71a3b2SAkhil Goyal 
312ee71a3b2SAkhil Goyal 	secy = mbox_alloc_msg_mcs_secy_plcy_write(mcs->mbox);
313ee71a3b2SAkhil Goyal 	if (secy == NULL)
314ee71a3b2SAkhil Goyal 		return -ENOMEM;
315ee71a3b2SAkhil Goyal 
316ee71a3b2SAkhil Goyal 	secy->plcy = secy_plcy->plcy;
317ee71a3b2SAkhil Goyal 	secy->secy_id = secy_plcy->secy_id;
318ee71a3b2SAkhil Goyal 	secy->mcs_id = mcs->idx;
319ee71a3b2SAkhil Goyal 	secy->dir = secy_plcy->dir;
320ee71a3b2SAkhil Goyal 
321ee71a3b2SAkhil Goyal 	return mbox_process_msg(mcs->mbox, (void *)&rsp);
322ee71a3b2SAkhil Goyal }
323ee71a3b2SAkhil Goyal 
324ee71a3b2SAkhil Goyal int
roc_mcs_secy_policy_read(struct roc_mcs * mcs __plt_unused,struct roc_mcs_rx_sc_cam_write_req * rx_sc_cam __plt_unused)325ee71a3b2SAkhil Goyal roc_mcs_secy_policy_read(struct roc_mcs *mcs __plt_unused,
326ee71a3b2SAkhil Goyal 			 struct roc_mcs_rx_sc_cam_write_req *rx_sc_cam __plt_unused)
327ee71a3b2SAkhil Goyal {
328ee71a3b2SAkhil Goyal 	MCS_SUPPORT_CHECK;
329ee71a3b2SAkhil Goyal 
330ee71a3b2SAkhil Goyal 	return -ENOTSUP;
331ee71a3b2SAkhil Goyal }
332ee71a3b2SAkhil Goyal 
333ee71a3b2SAkhil Goyal int
roc_mcs_rx_sc_sa_map_write(struct roc_mcs * mcs,struct roc_mcs_rx_sc_sa_map * rx_sc_sa_map)334f4bf4780SAkhil Goyal roc_mcs_rx_sc_sa_map_write(struct roc_mcs *mcs, struct roc_mcs_rx_sc_sa_map *rx_sc_sa_map)
335f4bf4780SAkhil Goyal {
336f4bf4780SAkhil Goyal 	struct mcs_priv *priv = roc_mcs_to_mcs_priv(mcs);
337f4bf4780SAkhil Goyal 	struct mcs_rx_sc_sa_map *sa_map;
338f4bf4780SAkhil Goyal 	struct msg_rsp *rsp;
339f4bf4780SAkhil Goyal 	uint16_t sc_id;
340f4bf4780SAkhil Goyal 	int i, rc;
341f4bf4780SAkhil Goyal 
342f4bf4780SAkhil Goyal 	MCS_SUPPORT_CHECK;
343f4bf4780SAkhil Goyal 
344f4bf4780SAkhil Goyal 	if (rx_sc_sa_map == NULL)
345f4bf4780SAkhil Goyal 		return -EINVAL;
346f4bf4780SAkhil Goyal 
347f4bf4780SAkhil Goyal 	sc_id = rx_sc_sa_map->sc_id;
348f4bf4780SAkhil Goyal 	sa_map = mbox_alloc_msg_mcs_rx_sc_sa_map_write(mcs->mbox);
349f4bf4780SAkhil Goyal 	if (sa_map == NULL)
350f4bf4780SAkhil Goyal 		return -ENOMEM;
351f4bf4780SAkhil Goyal 
352f4bf4780SAkhil Goyal 	sa_map->sa_index = rx_sc_sa_map->sa_index;
353f4bf4780SAkhil Goyal 	sa_map->sa_in_use = rx_sc_sa_map->sa_in_use;
354f4bf4780SAkhil Goyal 	sa_map->sc_id = rx_sc_sa_map->sc_id;
355f4bf4780SAkhil Goyal 	sa_map->an = rx_sc_sa_map->an;
356f4bf4780SAkhil Goyal 	sa_map->mcs_id = mcs->idx;
357f4bf4780SAkhil Goyal 
358f4bf4780SAkhil Goyal 	rc = mbox_process_msg(mcs->mbox, (void *)&rsp);
359f4bf4780SAkhil Goyal 	if (rc)
360f4bf4780SAkhil Goyal 		return rc;
361f4bf4780SAkhil Goyal 
362f4bf4780SAkhil Goyal 	for (i = 0; i < MAX_PORTS_PER_MCS; i++) {
363f4bf4780SAkhil Goyal 		uint32_t set = plt_bitmap_get(priv->port_rsrc[i].sc_bmap, sc_id);
364f4bf4780SAkhil Goyal 
365f4bf4780SAkhil Goyal 		if (set) {
366f4bf4780SAkhil Goyal 			plt_bitmap_set(priv->port_rsrc[i].sa_bmap, rx_sc_sa_map->sa_index);
367f4bf4780SAkhil Goyal 			priv->port_rsrc[i].sc_conf[sc_id].rx.sa_idx = rx_sc_sa_map->sa_index;
368f4bf4780SAkhil Goyal 			priv->port_rsrc[i].sc_conf[sc_id].rx.an = rx_sc_sa_map->an;
369f4bf4780SAkhil Goyal 			break;
370f4bf4780SAkhil Goyal 		}
371f4bf4780SAkhil Goyal 	}
372f4bf4780SAkhil Goyal 
373f4bf4780SAkhil Goyal 	return 0;
374f4bf4780SAkhil Goyal }
375f4bf4780SAkhil Goyal 
376f4bf4780SAkhil Goyal int
roc_mcs_rx_sc_sa_map_read(struct roc_mcs * mcs __plt_unused,struct roc_mcs_rx_sc_sa_map * rx_sc_sa_map __plt_unused)377f4bf4780SAkhil Goyal roc_mcs_rx_sc_sa_map_read(struct roc_mcs *mcs __plt_unused,
378f4bf4780SAkhil Goyal 			  struct roc_mcs_rx_sc_sa_map *rx_sc_sa_map __plt_unused)
379f4bf4780SAkhil Goyal {
380f4bf4780SAkhil Goyal 	MCS_SUPPORT_CHECK;
381f4bf4780SAkhil Goyal 
382f4bf4780SAkhil Goyal 	return -ENOTSUP;
383f4bf4780SAkhil Goyal }
384f4bf4780SAkhil Goyal 
385f4bf4780SAkhil Goyal int
roc_mcs_tx_sc_sa_map_write(struct roc_mcs * mcs,struct roc_mcs_tx_sc_sa_map * tx_sc_sa_map)386f4bf4780SAkhil Goyal roc_mcs_tx_sc_sa_map_write(struct roc_mcs *mcs, struct roc_mcs_tx_sc_sa_map *tx_sc_sa_map)
387f4bf4780SAkhil Goyal {
388f4bf4780SAkhil Goyal 	struct mcs_priv *priv = roc_mcs_to_mcs_priv(mcs);
389f4bf4780SAkhil Goyal 	struct mcs_tx_sc_sa_map *sa_map;
390f4bf4780SAkhil Goyal 	struct msg_rsp *rsp;
391f4bf4780SAkhil Goyal 	uint16_t sc_id;
392f4bf4780SAkhil Goyal 	int i, rc;
393f4bf4780SAkhil Goyal 
394f4bf4780SAkhil Goyal 	MCS_SUPPORT_CHECK;
395f4bf4780SAkhil Goyal 
396f4bf4780SAkhil Goyal 	if (tx_sc_sa_map == NULL)
397f4bf4780SAkhil Goyal 		return -EINVAL;
398f4bf4780SAkhil Goyal 
399f4bf4780SAkhil Goyal 	sa_map = mbox_alloc_msg_mcs_tx_sc_sa_map_write(mcs->mbox);
400f4bf4780SAkhil Goyal 	if (sa_map == NULL)
401f4bf4780SAkhil Goyal 		return -ENOMEM;
402f4bf4780SAkhil Goyal 
403f4bf4780SAkhil Goyal 	sa_map->sa_index0 = tx_sc_sa_map->sa_index0;
404f4bf4780SAkhil Goyal 	sa_map->sa_index1 = tx_sc_sa_map->sa_index1;
405f4bf4780SAkhil Goyal 	sa_map->rekey_ena = tx_sc_sa_map->rekey_ena;
406f4bf4780SAkhil Goyal 	sa_map->sa_index0_vld = tx_sc_sa_map->sa_index0_vld;
407f4bf4780SAkhil Goyal 	sa_map->sa_index1_vld = tx_sc_sa_map->sa_index1_vld;
408f4bf4780SAkhil Goyal 	sa_map->tx_sa_active = tx_sc_sa_map->tx_sa_active;
409f4bf4780SAkhil Goyal 	sa_map->sectag_sci = tx_sc_sa_map->sectag_sci;
410f4bf4780SAkhil Goyal 	sa_map->sc_id = tx_sc_sa_map->sc_id;
411f4bf4780SAkhil Goyal 	sa_map->mcs_id = mcs->idx;
412f4bf4780SAkhil Goyal 
413f4bf4780SAkhil Goyal 	rc = mbox_process_msg(mcs->mbox, (void *)&rsp);
414f4bf4780SAkhil Goyal 	if (rc)
415f4bf4780SAkhil Goyal 		return rc;
416f4bf4780SAkhil Goyal 
417f4bf4780SAkhil Goyal 	sc_id = tx_sc_sa_map->sc_id;
418f4bf4780SAkhil Goyal 	for (i = 0; i < MAX_PORTS_PER_MCS; i++) {
419f4bf4780SAkhil Goyal 		uint32_t set = plt_bitmap_get(priv->port_rsrc[i].sc_bmap, sc_id + priv->sc_entries);
420f4bf4780SAkhil Goyal 
421f4bf4780SAkhil Goyal 		if (set) {
422f4bf4780SAkhil Goyal 			uint32_t pos = priv->sa_entries + tx_sc_sa_map->sa_index0;
423f4bf4780SAkhil Goyal 
424f4bf4780SAkhil Goyal 			plt_bitmap_set(priv->port_rsrc[i].sa_bmap, pos);
425f4bf4780SAkhil Goyal 			priv->port_rsrc[i].sc_conf[sc_id].tx.sa_idx0 = tx_sc_sa_map->sa_index0;
426f4bf4780SAkhil Goyal 			pos = priv->sa_entries + tx_sc_sa_map->sa_index1;
427f4bf4780SAkhil Goyal 			plt_bitmap_set(priv->port_rsrc[i].sa_bmap, pos);
428f4bf4780SAkhil Goyal 			priv->port_rsrc[i].sc_conf[sc_id].tx.sa_idx1 = tx_sc_sa_map->sa_index1;
429f4bf4780SAkhil Goyal 			priv->port_rsrc[i].sc_conf[sc_id].tx.sci = tx_sc_sa_map->sectag_sci;
430f4bf4780SAkhil Goyal 			priv->port_rsrc[i].sc_conf[sc_id].tx.rekey_enb = tx_sc_sa_map->rekey_ena;
431f4bf4780SAkhil Goyal 			break;
432f4bf4780SAkhil Goyal 		}
433f4bf4780SAkhil Goyal 	}
434f4bf4780SAkhil Goyal 
435f4bf4780SAkhil Goyal 	return 0;
436f4bf4780SAkhil Goyal }
437f4bf4780SAkhil Goyal 
438f4bf4780SAkhil Goyal int
roc_mcs_tx_sc_sa_map_read(struct roc_mcs * mcs __plt_unused,struct roc_mcs_tx_sc_sa_map * tx_sc_sa_map __plt_unused)439f4bf4780SAkhil Goyal roc_mcs_tx_sc_sa_map_read(struct roc_mcs *mcs __plt_unused,
440f4bf4780SAkhil Goyal 			  struct roc_mcs_tx_sc_sa_map *tx_sc_sa_map __plt_unused)
441f4bf4780SAkhil Goyal {
442f4bf4780SAkhil Goyal 	MCS_SUPPORT_CHECK;
443f4bf4780SAkhil Goyal 
444f4bf4780SAkhil Goyal 	return -ENOTSUP;
445f4bf4780SAkhil Goyal }
446ee71a3b2SAkhil Goyal 
447ee71a3b2SAkhil Goyal int
roc_mcs_flowid_entry_write(struct roc_mcs * mcs,struct roc_mcs_flowid_entry_write_req * flowid_req)448ee71a3b2SAkhil Goyal roc_mcs_flowid_entry_write(struct roc_mcs *mcs, struct roc_mcs_flowid_entry_write_req *flowid_req)
449ee71a3b2SAkhil Goyal {
450ee71a3b2SAkhil Goyal 	struct mcs_priv *priv = roc_mcs_to_mcs_priv(mcs);
451ee71a3b2SAkhil Goyal 	struct mcs_flowid_entry_write_req *flow_req;
452ee71a3b2SAkhil Goyal 	struct msg_rsp *rsp;
453ee71a3b2SAkhil Goyal 	uint8_t port;
454ee71a3b2SAkhil Goyal 	int rc;
455ee71a3b2SAkhil Goyal 
456ee71a3b2SAkhil Goyal 	MCS_SUPPORT_CHECK;
457ee71a3b2SAkhil Goyal 
458ee71a3b2SAkhil Goyal 	if (flowid_req == NULL)
459ee71a3b2SAkhil Goyal 		return -EINVAL;
460ee71a3b2SAkhil Goyal 
461ee71a3b2SAkhil Goyal 	flow_req = mbox_alloc_msg_mcs_flowid_entry_write(mcs->mbox);
462ee71a3b2SAkhil Goyal 	if (flow_req == NULL)
463ee71a3b2SAkhil Goyal 		return -ENOMEM;
464ee71a3b2SAkhil Goyal 
465ee71a3b2SAkhil Goyal 	mbox_memcpy(flow_req->data, flowid_req->data, sizeof(uint64_t) * 4);
466ee71a3b2SAkhil Goyal 	mbox_memcpy(flow_req->mask, flowid_req->mask, sizeof(uint64_t) * 4);
467ee71a3b2SAkhil Goyal 	flow_req->sci = flowid_req->sci;
468ee71a3b2SAkhil Goyal 	flow_req->flow_id = flowid_req->flow_id;
469ee71a3b2SAkhil Goyal 	flow_req->secy_id = flowid_req->secy_id;
470ee71a3b2SAkhil Goyal 	flow_req->sc_id = flowid_req->sc_id;
471ee71a3b2SAkhil Goyal 	flow_req->ena = flowid_req->ena;
472ee71a3b2SAkhil Goyal 	flow_req->ctr_pkt = flowid_req->ctr_pkt;
473ee71a3b2SAkhil Goyal 	flow_req->mcs_id = mcs->idx;
474ee71a3b2SAkhil Goyal 	flow_req->dir = flowid_req->dir;
475ee71a3b2SAkhil Goyal 
476ee71a3b2SAkhil Goyal 	rc = mbox_process_msg(mcs->mbox, (void *)&rsp);
477ee71a3b2SAkhil Goyal 	if (rc)
478ee71a3b2SAkhil Goyal 		return rc;
479ee71a3b2SAkhil Goyal 
480ee71a3b2SAkhil Goyal 	if (flow_req->mask[3] & (BIT_ULL(10) | BIT_ULL(11)))
481ee71a3b2SAkhil Goyal 		return rc;
482ee71a3b2SAkhil Goyal 
483ee71a3b2SAkhil Goyal 	port = (flow_req->data[3] >> 10) & 0x3;
484ee71a3b2SAkhil Goyal 
485ee71a3b2SAkhil Goyal 	plt_bitmap_set(priv->port_rsrc[port].tcam_bmap,
486ee71a3b2SAkhil Goyal 		       flowid_req->flow_id +
487ee71a3b2SAkhil Goyal 			       ((flowid_req->dir == MCS_TX) ? priv->tcam_entries : 0));
488ee71a3b2SAkhil Goyal 	plt_bitmap_set(priv->port_rsrc[port].secy_bmap,
489ee71a3b2SAkhil Goyal 		       flowid_req->secy_id +
490ee71a3b2SAkhil Goyal 			       ((flowid_req->dir == MCS_TX) ? priv->secy_entries : 0));
491ee71a3b2SAkhil Goyal 
492ee71a3b2SAkhil Goyal 	if (flowid_req->dir == MCS_TX)
493ee71a3b2SAkhil Goyal 		plt_bitmap_set(priv->port_rsrc[port].sc_bmap, priv->sc_entries + flowid_req->sc_id);
494ee71a3b2SAkhil Goyal 
495ee71a3b2SAkhil Goyal 	return 0;
496ee71a3b2SAkhil Goyal }
497ee71a3b2SAkhil Goyal 
498ee71a3b2SAkhil Goyal int
roc_mcs_flowid_entry_read(struct roc_mcs * mcs __plt_unused,struct roc_mcs_flowid_entry_write_req * flowid_rsp __plt_unused)499ee71a3b2SAkhil Goyal roc_mcs_flowid_entry_read(struct roc_mcs *mcs __plt_unused,
500ee71a3b2SAkhil Goyal 			  struct roc_mcs_flowid_entry_write_req *flowid_rsp __plt_unused)
501ee71a3b2SAkhil Goyal {
502ee71a3b2SAkhil Goyal 	MCS_SUPPORT_CHECK;
503ee71a3b2SAkhil Goyal 
504ee71a3b2SAkhil Goyal 	return -ENOTSUP;
505ee71a3b2SAkhil Goyal }
506ee71a3b2SAkhil Goyal 
507ee71a3b2SAkhil Goyal int
roc_mcs_flowid_entry_enable(struct roc_mcs * mcs,struct roc_mcs_flowid_ena_dis_entry * entry)508ee71a3b2SAkhil Goyal roc_mcs_flowid_entry_enable(struct roc_mcs *mcs, struct roc_mcs_flowid_ena_dis_entry *entry)
509ee71a3b2SAkhil Goyal {
510ee71a3b2SAkhil Goyal 	struct mcs_flowid_ena_dis_entry *flow_entry;
511ee71a3b2SAkhil Goyal 	struct msg_rsp *rsp;
512ee71a3b2SAkhil Goyal 
513ee71a3b2SAkhil Goyal 	MCS_SUPPORT_CHECK;
514ee71a3b2SAkhil Goyal 
515ee71a3b2SAkhil Goyal 	if (entry == NULL)
516ee71a3b2SAkhil Goyal 		return -EINVAL;
517ee71a3b2SAkhil Goyal 
518ee71a3b2SAkhil Goyal 	flow_entry = mbox_alloc_msg_mcs_flowid_ena_entry(mcs->mbox);
519ee71a3b2SAkhil Goyal 	if (flow_entry == NULL)
520ee71a3b2SAkhil Goyal 		return -ENOMEM;
521ee71a3b2SAkhil Goyal 
522ee71a3b2SAkhil Goyal 	flow_entry->flow_id = entry->flow_id;
523ee71a3b2SAkhil Goyal 	flow_entry->ena = entry->ena;
524ee71a3b2SAkhil Goyal 	flow_entry->mcs_id = mcs->idx;
525ee71a3b2SAkhil Goyal 	flow_entry->dir = entry->dir;
526ee71a3b2SAkhil Goyal 
527ee71a3b2SAkhil Goyal 	return mbox_process_msg(mcs->mbox, (void *)&rsp);
528ee71a3b2SAkhil Goyal }
529*010db30fSAnkur Dwivedi 
530*010db30fSAnkur Dwivedi void
roc_mcs_sa_port_map_update(struct roc_mcs * mcs,int sa_id,uint8_t port_id)531*010db30fSAnkur Dwivedi roc_mcs_sa_port_map_update(struct roc_mcs *mcs, int sa_id, uint8_t port_id)
532*010db30fSAnkur Dwivedi {
533*010db30fSAnkur Dwivedi 	mcs->sa_port_map[sa_id] = port_id;
534*010db30fSAnkur Dwivedi }
535