xref: /dpdk/drivers/common/cnxk/roc_nix_mcast.c (revision 1c518ee1)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(C) 2021 Marvell.
3  */
4 
5 #include "roc_api.h"
6 #include "roc_priv.h"
7 
8 static inline struct mbox *
get_mbox(struct roc_nix * roc_nix)9 get_mbox(struct roc_nix *roc_nix)
10 {
11 	struct nix *nix = roc_nix_to_nix_priv(roc_nix);
12 	struct dev *dev = &nix->dev;
13 
14 	return dev->mbox;
15 }
16 
17 int
roc_nix_mcast_mcam_entry_alloc(struct roc_nix * roc_nix,uint16_t nb_entries,uint8_t priority,uint16_t index[])18 roc_nix_mcast_mcam_entry_alloc(struct roc_nix *roc_nix, uint16_t nb_entries,
19 			       uint8_t priority, uint16_t index[])
20 {
21 	struct mbox *mbox = get_mbox(roc_nix);
22 	struct npc_mcam_alloc_entry_req *req;
23 	struct npc_mcam_alloc_entry_rsp *rsp;
24 	int rc = -ENOSPC, i;
25 
26 	req = mbox_alloc_msg_npc_mcam_alloc_entry(mbox);
27 	if (req == NULL)
28 		return rc;
29 	req->priority = priority;
30 	req->count = nb_entries;
31 
32 	rc = mbox_process_msg(mbox, (void *)&rsp);
33 	if (rc)
34 		return rc;
35 
36 	for (i = 0; i < rsp->count; i++)
37 		index[i] = rsp->entry_list[i];
38 
39 	return rsp->count;
40 }
41 
42 int
roc_nix_mcast_mcam_entry_free(struct roc_nix * roc_nix,uint32_t index)43 roc_nix_mcast_mcam_entry_free(struct roc_nix *roc_nix, uint32_t index)
44 {
45 	struct mbox *mbox = get_mbox(roc_nix);
46 	struct npc_mcam_free_entry_req *req;
47 	int rc = -ENOSPC;
48 
49 	req = mbox_alloc_msg_npc_mcam_free_entry(mbox);
50 	if (req == NULL)
51 		return rc;
52 	req->entry = index;
53 
54 	return mbox_process_msg(mbox, NULL);
55 }
56 
57 int
roc_nix_mcast_mcam_entry_write(struct roc_nix * roc_nix,struct mcam_entry * entry,uint32_t index,uint8_t intf,uint64_t action)58 roc_nix_mcast_mcam_entry_write(struct roc_nix *roc_nix,
59 			       struct mcam_entry *entry, uint32_t index,
60 			       uint8_t intf, uint64_t action)
61 {
62 	struct mbox *mbox = get_mbox(roc_nix);
63 	struct npc_mcam_write_entry_req *req;
64 	int rc = -ENOSPC;
65 
66 	req = mbox_alloc_msg_npc_mcam_write_entry(mbox);
67 	if (req == NULL)
68 		return rc;
69 	req->entry = index;
70 	req->intf = intf;
71 	req->enable_entry = true;
72 	mbox_memcpy(&req->entry_data, entry, sizeof(struct mcam_entry));
73 	req->entry_data.action = action;
74 
75 	return mbox_process(mbox);
76 }
77 
78 int
roc_nix_mcast_mcam_entry_ena_dis(struct roc_nix * roc_nix,uint32_t index,bool enable)79 roc_nix_mcast_mcam_entry_ena_dis(struct roc_nix *roc_nix, uint32_t index,
80 				 bool enable)
81 {
82 	struct npc_mcam_ena_dis_entry_req *req;
83 	struct mbox *mbox = get_mbox(roc_nix);
84 	int rc = -ENOSPC;
85 
86 	if (enable) {
87 		req = mbox_alloc_msg_npc_mcam_ena_entry(mbox);
88 		if (req == NULL)
89 			return rc;
90 	} else {
91 		req = mbox_alloc_msg_npc_mcam_dis_entry(mbox);
92 		if (req == NULL)
93 			return rc;
94 	}
95 
96 	req->entry = index;
97 	return mbox_process(mbox);
98 }
99