Branch data Line data Source code
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 : : int
9 : 0 : roc_nix_vlan_mcam_entry_read(struct roc_nix *roc_nix, uint32_t index,
10 : : void **rsp)
11 : : {
12 : : struct nix *nix = roc_nix_to_nix_priv(roc_nix);
13 : : struct dev *dev = &nix->dev;
14 : 0 : struct mbox *mbox = mbox_get(dev->mbox);
15 : : struct npc_mcam_read_entry_req *req;
16 : : int rc = -ENOSPC;
17 : :
18 : 0 : req = mbox_alloc_msg_npc_mcam_read_entry(mbox);
19 [ # # ]: 0 : if (req == NULL)
20 : 0 : goto exit;
21 : 0 : req->entry = index;
22 : :
23 : : rc = mbox_process_msg(mbox, (void **)rsp);
24 : 0 : exit:
25 : : mbox_put(mbox);
26 : 0 : return rc;
27 : : }
28 : :
29 : : int
30 : 0 : roc_nix_vlan_mcam_entry_write(struct roc_nix *roc_nix, uint32_t index, void *entry, uint8_t intf,
31 : : uint8_t enable)
32 : : {
33 : : struct nix *nix = roc_nix_to_nix_priv(roc_nix);
34 : : struct dev *dev = &nix->dev;
35 : 0 : struct mbox *mbox = mbox_get(dev->mbox);
36 : : struct npc_mcam_write_entry_req *req;
37 : : struct npc_cn20k_mcam_write_entry_req *cn20k_req;
38 : : struct msghdr *rsp;
39 : : int rc = -ENOSPC;
40 : :
41 [ # # ]: 0 : if (roc_model_is_cn20k()) {
42 : 0 : cn20k_req = mbox_alloc_msg_npc_cn20k_mcam_write_entry(mbox);
43 [ # # ]: 0 : if (cn20k_req == NULL)
44 : 0 : goto exit;
45 : 0 : cn20k_req->entry = index;
46 : 0 : cn20k_req->intf = intf;
47 : 0 : cn20k_req->enable_entry = enable;
48 [ # # ]: 0 : mbox_memcpy(&cn20k_req->entry_data, entry, sizeof(struct cn20k_mcam_entry));
49 : : } else {
50 : 0 : req = mbox_alloc_msg_npc_mcam_write_entry(mbox);
51 [ # # ]: 0 : if (req == NULL)
52 : 0 : goto exit;
53 : 0 : req->entry = index;
54 : 0 : req->intf = intf;
55 : 0 : req->enable_entry = enable;
56 [ # # ]: 0 : mbox_memcpy(&req->entry_data, entry, sizeof(struct mcam_entry));
57 : : }
58 : :
59 : : rc = mbox_process_msg(mbox, (void *)&rsp);
60 : 0 : exit:
61 : : mbox_put(mbox);
62 : 0 : return rc;
63 : : }
64 : :
65 : : int
66 : 0 : roc_nix_vlan_mcam_entry_alloc_and_write(struct roc_nix *roc_nix, void *entry, uint8_t intf,
67 : : uint8_t priority, uint8_t ref_entry)
68 : : {
69 : : struct npc_mcam_alloc_and_write_entry_rsp *rsp;
70 : : struct nix *nix = roc_nix_to_nix_priv(roc_nix);
71 : : struct dev *dev = &nix->dev;
72 : 0 : struct mbox *mbox = mbox_get(dev->mbox);
73 : : int rc = -ENOSPC;
74 : :
75 [ # # ]: 0 : if (roc_model_is_cn20k()) {
76 : : struct npc_cn20k_mcam_alloc_and_write_entry_req *req;
77 : :
78 : 0 : req = mbox_alloc_msg_npc_cn20k_mcam_alloc_and_write_entry(mbox);
79 [ # # ]: 0 : if (req == NULL)
80 : 0 : goto exit;
81 : 0 : req->ref_prio = priority;
82 : 0 : req->ref_entry = ref_entry;
83 : 0 : req->intf = intf;
84 : 0 : req->enable_entry = true;
85 [ # # ]: 0 : mbox_memcpy(&req->entry_data, entry, sizeof(struct cn20k_mcam_entry));
86 : :
87 : : } else {
88 : : struct npc_mcam_alloc_and_write_entry_req *req;
89 : :
90 : 0 : req = mbox_alloc_msg_npc_mcam_alloc_and_write_entry(mbox);
91 [ # # ]: 0 : if (req == NULL)
92 : 0 : goto exit;
93 : 0 : req->ref_priority = priority;
94 : 0 : req->ref_entry = ref_entry;
95 : 0 : req->intf = intf;
96 : 0 : req->enable_entry = true;
97 [ # # ]: 0 : mbox_memcpy(&req->entry_data, entry, sizeof(struct mcam_entry));
98 : : }
99 : :
100 : : rc = mbox_process_msg(mbox, (void *)&rsp);
101 [ # # ]: 0 : if (rc)
102 : 0 : goto exit;
103 : :
104 : 0 : rc = rsp->entry;
105 : 0 : exit:
106 : : mbox_put(mbox);
107 : 0 : return rc;
108 : : }
109 : :
110 : : int
111 : 0 : roc_nix_vlan_mcam_entry_free(struct roc_nix *roc_nix, uint32_t index)
112 : : {
113 : : struct nix *nix = roc_nix_to_nix_priv(roc_nix);
114 : : struct dev *dev = &nix->dev;
115 : 0 : struct mbox *mbox = mbox_get(dev->mbox);
116 : : struct npc_mcam_free_entry_req *req;
117 : : int rc = -ENOSPC;
118 : :
119 : 0 : req = mbox_alloc_msg_npc_mcam_free_entry(mbox);
120 [ # # ]: 0 : if (req == NULL)
121 : 0 : goto exit;
122 : 0 : req->entry = index;
123 : :
124 : : rc = mbox_process_msg(mbox, NULL);
125 : 0 : exit:
126 : : mbox_put(mbox);
127 : 0 : return rc;
128 : : }
129 : :
130 : : int
131 : 0 : roc_nix_vlan_mcam_entry_ena_dis(struct roc_nix *roc_nix, uint32_t index,
132 : : const int enable)
133 : : {
134 : : struct npc_mcam_ena_dis_entry_req *req;
135 : : struct nix *nix = roc_nix_to_nix_priv(roc_nix);
136 : : struct dev *dev = &nix->dev;
137 : 0 : struct mbox *mbox = mbox_get(dev->mbox);
138 : : int rc = -ENOSPC;
139 : :
140 [ # # ]: 0 : if (enable) {
141 : 0 : req = mbox_alloc_msg_npc_mcam_ena_entry(mbox);
142 [ # # ]: 0 : if (req == NULL)
143 : 0 : goto exit;
144 : : } else {
145 : 0 : req = mbox_alloc_msg_npc_mcam_dis_entry(mbox);
146 [ # # ]: 0 : if (req == NULL)
147 : 0 : goto exit;
148 : : }
149 : :
150 : 0 : req->entry = index;
151 : : rc = mbox_process_msg(mbox, NULL);
152 : 0 : exit:
153 : : mbox_put(mbox);
154 : 0 : return rc;
155 : : }
156 : :
157 : : int
158 : 0 : roc_nix_vlan_strip_vtag_ena_dis(struct roc_nix *roc_nix, bool enable)
159 : : {
160 : : struct nix *nix = roc_nix_to_nix_priv(roc_nix);
161 : : struct dev *dev = &nix->dev;
162 : 0 : struct mbox *mbox = mbox_get(dev->mbox);
163 : : struct nix_vtag_config *vtag_cfg;
164 : : int rc = -ENOSPC;
165 : :
166 : 0 : vtag_cfg = mbox_alloc_msg_nix_vtag_cfg(mbox);
167 [ # # ]: 0 : if (vtag_cfg == NULL)
168 : 0 : goto exit;
169 : 0 : vtag_cfg->vtag_size = NIX_VTAGSIZE_T4;
170 : 0 : vtag_cfg->cfg_type = 1; /* Rx VLAN configuration */
171 : 0 : vtag_cfg->rx.capture_vtag = 1; /* Always capture */
172 : 0 : vtag_cfg->rx.vtag_type = 0; /* Use index 0 */
173 : :
174 [ # # ]: 0 : if (enable)
175 : 0 : vtag_cfg->rx.strip_vtag = 1;
176 : : else
177 : 0 : vtag_cfg->rx.strip_vtag = 0;
178 : :
179 : 0 : rc = mbox_process(mbox);
180 : 0 : exit:
181 : : mbox_put(mbox);
182 : 0 : return rc;
183 : : }
184 : :
185 : : int
186 : 0 : roc_nix_vlan_insert_ena_dis(struct roc_nix *roc_nix,
187 : : struct roc_nix_vlan_config *vlan_cfg,
188 : : uint64_t *mcam_index, bool enable)
189 : : {
190 : : struct nix *nix = roc_nix_to_nix_priv(roc_nix);
191 : : struct dev *dev = &nix->dev;
192 : 0 : struct mbox *mbox = mbox_get(dev->mbox);
193 : : struct nix_vtag_config *vtag_cfg;
194 : : struct nix_vtag_config_rsp *rsp;
195 : : int rc = -ENOSPC;
196 : :
197 : 0 : vtag_cfg = mbox_alloc_msg_nix_vtag_cfg(mbox);
198 [ # # ]: 0 : if (vtag_cfg == NULL)
199 : 0 : goto exit;
200 : 0 : vtag_cfg->cfg_type = 0; /* Tx VLAN configuration */
201 : 0 : vtag_cfg->vtag_size = NIX_VTAGSIZE_T4;
202 : :
203 [ # # ]: 0 : if (enable) {
204 [ # # ]: 0 : if (vlan_cfg->type & ROC_NIX_VLAN_TYPE_INNER) {
205 : 0 : vtag_cfg->tx.vtag0 = vlan_cfg->vlan.vtag_inner;
206 : 0 : vtag_cfg->tx.cfg_vtag0 = true;
207 : : }
208 [ # # ]: 0 : if (vlan_cfg->type & ROC_NIX_VLAN_TYPE_OUTER) {
209 : 0 : vtag_cfg->tx.vtag1 = vlan_cfg->vlan.vtag_outer;
210 : 0 : vtag_cfg->tx.cfg_vtag1 = true;
211 : : }
212 : : } else {
213 [ # # ]: 0 : if (vlan_cfg->type & ROC_NIX_VLAN_TYPE_INNER) {
214 : 0 : vtag_cfg->tx.vtag0_idx = vlan_cfg->mcam.idx_inner;
215 : 0 : vtag_cfg->tx.free_vtag0 = true;
216 : : }
217 [ # # ]: 0 : if (vlan_cfg->type & ROC_NIX_VLAN_TYPE_OUTER) {
218 : 0 : vtag_cfg->tx.vtag1_idx = vlan_cfg->mcam.idx_outer;
219 : 0 : vtag_cfg->tx.free_vtag1 = true;
220 : : }
221 : : }
222 : :
223 : : rc = mbox_process_msg(mbox, (void *)&rsp);
224 [ # # ]: 0 : if (rc)
225 : 0 : goto exit;
226 : :
227 [ # # ]: 0 : if (enable)
228 : 0 : *mcam_index =
229 : 0 : (((uint64_t)rsp->vtag1_idx << 32) | rsp->vtag0_idx);
230 : :
231 : : rc = 0;
232 : 0 : exit:
233 : : mbox_put(mbox);
234 : 0 : return rc;
235 : : }
236 : :
237 : : int
238 : 0 : nix_vlan_tpid_set(struct mbox *mbox, uint16_t pcifunc, uint32_t type, uint16_t tpid)
239 : : {
240 : : struct nix_set_vlan_tpid *tpid_cfg;
241 : : int rc = -ENOSPC;
242 : :
243 : : /* Configuring for PF */
244 : 0 : tpid_cfg = mbox_alloc_msg_nix_set_vlan_tpid(mbox_get(mbox));
245 [ # # ]: 0 : if (tpid_cfg == NULL)
246 : 0 : goto exit;
247 : 0 : tpid_cfg->tpid = tpid;
248 : 0 : tpid_cfg->hdr.pcifunc = pcifunc;
249 : :
250 [ # # ]: 0 : if (type & ROC_NIX_VLAN_TYPE_OUTER)
251 : 0 : tpid_cfg->vlan_type = NIX_VLAN_TYPE_OUTER;
252 : : else
253 : 0 : tpid_cfg->vlan_type = NIX_VLAN_TYPE_INNER;
254 : :
255 : 0 : rc = mbox_process(mbox);
256 : 0 : exit:
257 : : mbox_put(mbox);
258 : 0 : return rc;
259 : : }
260 : :
261 : : int
262 : 0 : roc_nix_vlan_tpid_set(struct roc_nix *roc_nix, uint32_t type, uint16_t tpid)
263 : : {
264 : : struct nix *nix = roc_nix_to_nix_priv(roc_nix);
265 : : struct dev *dev = &nix->dev;
266 : : int rc;
267 : :
268 : 0 : rc = nix_vlan_tpid_set(dev->mbox, dev->pf_func, type, tpid);
269 [ # # ]: 0 : if (rc)
270 : 0 : plt_err("Failed to set tpid for PF, rc %d", rc);
271 : :
272 : 0 : return rc;
273 : : }
|