xref: /dpdk/drivers/common/cnxk/roc_nix_vlan.c (revision 62240569)
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_vlan_mcam_entry_read(struct roc_nix * roc_nix,uint32_t index,struct npc_mcam_read_entry_rsp ** rsp)18 roc_nix_vlan_mcam_entry_read(struct roc_nix *roc_nix, uint32_t index,
19 			     struct npc_mcam_read_entry_rsp **rsp)
20 {
21 	struct mbox *mbox = get_mbox(roc_nix);
22 	struct npc_mcam_read_entry_req *req;
23 	int rc = -ENOSPC;
24 
25 	req = mbox_alloc_msg_npc_mcam_read_entry(mbox);
26 	if (req == NULL)
27 		return rc;
28 	req->entry = index;
29 
30 	return mbox_process_msg(mbox, (void **)rsp);
31 }
32 
33 int
roc_nix_vlan_mcam_entry_write(struct roc_nix * roc_nix,uint32_t index,struct mcam_entry * entry,uint8_t intf,uint8_t enable)34 roc_nix_vlan_mcam_entry_write(struct roc_nix *roc_nix, uint32_t index,
35 			      struct mcam_entry *entry, uint8_t intf,
36 			      uint8_t enable)
37 {
38 	struct mbox *mbox = get_mbox(roc_nix);
39 	struct npc_mcam_write_entry_req *req;
40 	struct msghdr *rsp;
41 	int rc = -ENOSPC;
42 
43 	req = mbox_alloc_msg_npc_mcam_write_entry(mbox);
44 	if (req == NULL)
45 		return rc;
46 	req->entry = index;
47 	req->intf = intf;
48 	req->enable_entry = enable;
49 	mbox_memcpy(&req->entry_data, entry, sizeof(struct mcam_entry));
50 
51 	return mbox_process_msg(mbox, (void *)&rsp);
52 }
53 
54 int
roc_nix_vlan_mcam_entry_alloc_and_write(struct roc_nix * roc_nix,struct mcam_entry * entry,uint8_t intf,uint8_t priority,uint8_t ref_entry)55 roc_nix_vlan_mcam_entry_alloc_and_write(struct roc_nix *roc_nix,
56 					struct mcam_entry *entry, uint8_t intf,
57 					uint8_t priority, uint8_t ref_entry)
58 {
59 	struct npc_mcam_alloc_and_write_entry_req *req;
60 	struct npc_mcam_alloc_and_write_entry_rsp *rsp;
61 	struct mbox *mbox = get_mbox(roc_nix);
62 	int rc = -ENOSPC;
63 
64 	req = mbox_alloc_msg_npc_mcam_alloc_and_write_entry(mbox);
65 	if (req == NULL)
66 		return rc;
67 	req->priority = priority;
68 	req->ref_entry = ref_entry;
69 	req->intf = intf;
70 	req->enable_entry = true;
71 	mbox_memcpy(&req->entry_data, entry, sizeof(struct mcam_entry));
72 
73 	rc = mbox_process_msg(mbox, (void *)&rsp);
74 	if (rc)
75 		return rc;
76 
77 	return rsp->entry;
78 }
79 
80 int
roc_nix_vlan_mcam_entry_free(struct roc_nix * roc_nix,uint32_t index)81 roc_nix_vlan_mcam_entry_free(struct roc_nix *roc_nix, uint32_t index)
82 {
83 	struct mbox *mbox = get_mbox(roc_nix);
84 	struct npc_mcam_free_entry_req *req;
85 	int rc = -ENOSPC;
86 
87 	req = mbox_alloc_msg_npc_mcam_free_entry(mbox);
88 	if (req == NULL)
89 		return rc;
90 	req->entry = index;
91 
92 	return mbox_process_msg(mbox, NULL);
93 }
94 
95 int
roc_nix_vlan_mcam_entry_ena_dis(struct roc_nix * roc_nix,uint32_t index,const int enable)96 roc_nix_vlan_mcam_entry_ena_dis(struct roc_nix *roc_nix, uint32_t index,
97 				const int enable)
98 {
99 	struct npc_mcam_ena_dis_entry_req *req;
100 	struct mbox *mbox = get_mbox(roc_nix);
101 	int rc = -ENOSPC;
102 
103 	if (enable) {
104 		req = mbox_alloc_msg_npc_mcam_ena_entry(mbox);
105 		if (req == NULL)
106 			return rc;
107 	} else {
108 		req = mbox_alloc_msg_npc_mcam_dis_entry(mbox);
109 		if (req == NULL)
110 			return rc;
111 	}
112 
113 	req->entry = index;
114 	return mbox_process_msg(mbox, NULL);
115 }
116 
117 int
roc_nix_vlan_strip_vtag_ena_dis(struct roc_nix * roc_nix,bool enable)118 roc_nix_vlan_strip_vtag_ena_dis(struct roc_nix *roc_nix, bool enable)
119 {
120 	struct mbox *mbox = get_mbox(roc_nix);
121 	struct nix_vtag_config *vtag_cfg;
122 	int rc = -ENOSPC;
123 
124 	vtag_cfg = mbox_alloc_msg_nix_vtag_cfg(mbox);
125 	if (vtag_cfg == NULL)
126 		return rc;
127 	vtag_cfg->vtag_size = NIX_VTAGSIZE_T4;
128 	vtag_cfg->cfg_type = 1;	       /* Rx VLAN configuration */
129 	vtag_cfg->rx.capture_vtag = 1; /* Always capture */
130 	vtag_cfg->rx.vtag_type = 0;    /* Use index 0 */
131 
132 	if (enable)
133 		vtag_cfg->rx.strip_vtag = 1;
134 	else
135 		vtag_cfg->rx.strip_vtag = 0;
136 
137 	return mbox_process(mbox);
138 }
139 
140 int
roc_nix_vlan_insert_ena_dis(struct roc_nix * roc_nix,struct roc_nix_vlan_config * vlan_cfg,uint64_t * mcam_index,bool enable)141 roc_nix_vlan_insert_ena_dis(struct roc_nix *roc_nix,
142 			    struct roc_nix_vlan_config *vlan_cfg,
143 			    uint64_t *mcam_index, bool enable)
144 {
145 	struct mbox *mbox = get_mbox(roc_nix);
146 	struct nix_vtag_config *vtag_cfg;
147 	struct nix_vtag_config_rsp *rsp;
148 	int rc = -ENOSPC;
149 
150 	vtag_cfg = mbox_alloc_msg_nix_vtag_cfg(mbox);
151 	if (vtag_cfg == NULL)
152 		return rc;
153 	vtag_cfg->cfg_type = 0; /* Tx VLAN configuration */
154 	vtag_cfg->vtag_size = NIX_VTAGSIZE_T4;
155 
156 	if (enable) {
157 		if (vlan_cfg->type & ROC_NIX_VLAN_TYPE_INNER) {
158 			vtag_cfg->tx.vtag0 = vlan_cfg->vlan.vtag_inner;
159 			vtag_cfg->tx.cfg_vtag0 = true;
160 		}
161 		if (vlan_cfg->type & ROC_NIX_VLAN_TYPE_OUTER) {
162 			vtag_cfg->tx.vtag1 = vlan_cfg->vlan.vtag_outer;
163 			vtag_cfg->tx.cfg_vtag1 = true;
164 		}
165 	} else {
166 		if (vlan_cfg->type & ROC_NIX_VLAN_TYPE_INNER) {
167 			vtag_cfg->tx.vtag0_idx = vlan_cfg->mcam.idx_inner;
168 			vtag_cfg->tx.free_vtag0 = true;
169 		}
170 		if (vlan_cfg->type & ROC_NIX_VLAN_TYPE_OUTER) {
171 			vtag_cfg->tx.vtag1_idx = vlan_cfg->mcam.idx_outer;
172 			vtag_cfg->tx.free_vtag1 = true;
173 		}
174 	}
175 
176 	rc = mbox_process_msg(mbox, (void *)&rsp);
177 	if (rc)
178 		return rc;
179 
180 	if (enable)
181 		*mcam_index =
182 			(((uint64_t)rsp->vtag1_idx << 32) | rsp->vtag0_idx);
183 
184 	return 0;
185 }
186 
187 int
roc_nix_vlan_tpid_set(struct roc_nix * roc_nix,uint32_t type,uint16_t tpid)188 roc_nix_vlan_tpid_set(struct roc_nix *roc_nix, uint32_t type, uint16_t tpid)
189 {
190 	struct mbox *mbox = get_mbox(roc_nix);
191 	struct nix_set_vlan_tpid *tpid_cfg;
192 	int rc = -ENOSPC;
193 
194 	tpid_cfg = mbox_alloc_msg_nix_set_vlan_tpid(mbox);
195 	if (tpid_cfg == NULL)
196 		return rc;
197 	tpid_cfg->tpid = tpid;
198 
199 	if (type & ROC_NIX_VLAN_TYPE_OUTER)
200 		tpid_cfg->vlan_type = NIX_VLAN_TYPE_OUTER;
201 	else
202 		tpid_cfg->vlan_type = NIX_VLAN_TYPE_INNER;
203 
204 	return mbox_process(mbox);
205 }
206