1 /*
2 * Copyright 2022-2023 NXP
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7 #include "fsl_netc_hw.h"
8
9 /* Component ID definition, used by tools. */
10 #ifndef FSL_COMPONENT_ID
11 #define FSL_COMPONENT_ID "platform.drivers.netc"
12 #endif
13
14 #if !(defined(FSL_FEATURE_NETC_HAS_NO_SWITCH) && FSL_FEATURE_NETC_HAS_NO_SWITCH)
15 #define NETC_KC_CFG(x) \
16 (NETC_SW_ENETC_ISIDKC0CR0_ETP(x.etp) | NETC_SW_ENETC_ISIDKC0CR0_SQTP(x.sqtp) | \
17 NETC_SW_ENETC_ISIDKC0CR0_IPCPP(x.ipcpp) | NETC_SW_ENETC_ISIDKC0CR0_IVIDP(x.ividp) | \
18 NETC_SW_ENETC_ISIDKC0CR0_OPCPP(x.opcpp) | NETC_SW_ENETC_ISIDKC0CR0_OVIDP(x.ovidp) | \
19 NETC_SW_ENETC_ISIDKC0CR0_SMACP(x.smacp) | NETC_SW_ENETC_ISIDKC0CR0_DMACP(x.dmacp) | \
20 NETC_SW_ENETC_ISIDKC0CR0_SPMP(x.spmp) | NETC_SW_ENETC_ISIDKC0CR0_PORTP(x.portp) | \
21 NETC_SW_ENETC_ISIDKC0CR0_VALID(x.valid))
22 #else
23 #define NETC_KC_CFG(x) \
24 (NETC_SW_ENETC_ISIDKC0CR0_ETP(x.etp) | NETC_SW_ENETC_ISIDKC0CR0_SQTP(x.sqtp) | \
25 NETC_SW_ENETC_ISIDKC0CR0_IPCPP(x.ipcpp) | NETC_SW_ENETC_ISIDKC0CR0_IVIDP(x.ividp) | \
26 NETC_SW_ENETC_ISIDKC0CR0_OPCPP(x.opcpp) | NETC_SW_ENETC_ISIDKC0CR0_OVIDP(x.ovidp) | \
27 NETC_SW_ENETC_ISIDKC0CR0_SMACP(x.smacp) | NETC_SW_ENETC_ISIDKC0CR0_DMACP(x.dmacp) | \
28 NETC_SW_ENETC_ISIDKC0CR0_PORTP(x.portp) | \
29 NETC_SW_ENETC_ISIDKC0CR0_VALID(x.valid))
30 #endif
31
32 #define NETC_KC_PAYLOAD(x) \
33 (NETC_SW_ENETC_ISIDKC0PF0CR_LBMASK(x.lbMask) | NETC_SW_ENETC_ISIDKC0PF0CR_FBMASK(x.fbMask) | \
34 NETC_SW_ENETC_ISIDKC0PF0CR_BYTE_OFFSET(x.byteOffset) | NETC_SW_ENETC_ISIDKC0PF0CR_NUM_BYTES(x.numBytes) | \
35 NETC_SW_ENETC_ISIDKC0PF0CR_PFP(x.pfp))
36
NETC_SIGetVsiIndex(netc_vsi_number_t vsi)37 uint16_t NETC_SIGetVsiIndex(netc_vsi_number_t vsi)
38 {
39 uint32_t vsiIdx = (uint32_t)vsi;
40 uint16_t index = 0;
41
42 do
43 {
44 index++;
45 vsiIdx >>= 1U;
46 } while ((vsiIdx & 0x1U) == 0U);
47 return (index - 1U);
48 }
49
NETC_PSFPKcProfileInit(NETC_SW_ENETC_Type * base,const netc_isi_kc_rule_t * rule,bool enKcPair1)50 void NETC_PSFPKcProfileInit(NETC_SW_ENETC_Type *base, const netc_isi_kc_rule_t *rule, bool enKcPair1)
51 {
52 if (enKcPair1)
53 {
54 #if !(defined(FSL_FEATURE_NETC_HAS_NO_SWITCH) && FSL_FEATURE_NETC_HAS_NO_SWITCH)
55 base->ISIDKC2PF0CR = NETC_KC_PAYLOAD(rule[0].payload[0]);
56 base->ISIDKC2PF1CR = NETC_KC_PAYLOAD(rule[0].payload[1]);
57 base->ISIDKC2PF2CR = NETC_KC_PAYLOAD(rule[0].payload[2]);
58 base->ISIDKC2PF3CR = NETC_KC_PAYLOAD(rule[0].payload[3]);
59 base->ISIDKC3PF0CR = NETC_KC_PAYLOAD(rule[1].payload[0]);
60 base->ISIDKC3PF1CR = NETC_KC_PAYLOAD(rule[1].payload[1]);
61 base->ISIDKC3PF2CR = NETC_KC_PAYLOAD(rule[1].payload[2]);
62 base->ISIDKC3PF3CR = NETC_KC_PAYLOAD(rule[1].payload[3]);
63 base->ISIDKC2CR0 = NETC_KC_CFG(rule[0]);
64 base->ISIDKC3CR0 = NETC_KC_CFG(rule[1]);
65 #endif
66 }
67 else
68 {
69 base->ISIDKC0PF0CR = NETC_KC_PAYLOAD(rule[0].payload[0]);
70 base->ISIDKC0PF1CR = NETC_KC_PAYLOAD(rule[0].payload[1]);
71 base->ISIDKC0PF2CR = NETC_KC_PAYLOAD(rule[0].payload[2]);
72 base->ISIDKC0PF3CR = NETC_KC_PAYLOAD(rule[0].payload[3]);
73 base->ISIDKC1PF0CR = NETC_KC_PAYLOAD(rule[1].payload[0]);
74 base->ISIDKC1PF1CR = NETC_KC_PAYLOAD(rule[1].payload[1]);
75 base->ISIDKC1PF2CR = NETC_KC_PAYLOAD(rule[1].payload[2]);
76 base->ISIDKC1PF3CR = NETC_KC_PAYLOAD(rule[1].payload[3]);
77 base->ISIDKC0CR0 = NETC_KC_CFG(rule[0]);
78 base->ISIDKC1CR0 = NETC_KC_CFG(rule[1]);
79 }
80 }
81
NETC_RxVlanCInit(NETC_SW_ENETC_Type * base,const netc_vlan_classify_config_t * config,bool enRtag)82 void NETC_RxVlanCInit(NETC_SW_ENETC_Type *base, const netc_vlan_classify_config_t *config, bool enRtag)
83 {
84 base->CVLANR1 =
85 NETC_SW_ENETC_CVLANR1_V(config->enableCustom1) | NETC_SW_ENETC_CVLANR1_ETYPE(config->custom1EtherType);
86 base->CVLANR2 =
87 NETC_SW_ENETC_CVLANR2_V(config->enableCustom2) | NETC_SW_ENETC_CVLANR2_ETYPE(config->custom2EtherType);
88 if (enRtag)
89 {
90 #if !(defined(FSL_FEATURE_NETC_HAS_NO_SWITCH) && FSL_FEATURE_NETC_HAS_NO_SWITCH)
91 base->PSRTAGETR = NETC_SW_ENETC_PSRTAGETR_ETHERTYPE(config->preStandRTAGType);
92 #endif
93 }
94 }
95
NETC_RxQosCInit(NETC_SW_ENETC_Type * base,const netc_qos_classify_profile_t * profile,bool enProfile1)96 void NETC_RxQosCInit(NETC_SW_ENETC_Type *base, const netc_qos_classify_profile_t *profile, bool enProfile1)
97 {
98 uint32_t ipv[2] = {0};
99 uint32_t dr = 0;
100 for (uint32_t i = 0U; i < 8U; i++)
101 {
102 ipv[0] |= ((uint32_t)profile->ipv[i] & NETC_SW_ENETC_VLANIPVMPR0_PCP_DEI_0_MASK) << (4U * i);
103 ipv[1] |= ((uint32_t)profile->ipv[i + 8U] & NETC_SW_ENETC_VLANIPVMPR0_PCP_DEI_0_MASK) << (4U * i);
104 }
105 for (uint32_t i = 0U; i < 16U; i++)
106 {
107 dr |= ((uint32_t)profile->dr[i] & NETC_SW_ENETC_VLANDRMPR_PCP_DEI_0_MASK) << (2U * i);
108 }
109
110 if (enProfile1)
111 {
112 #if !(defined(FSL_FEATURE_NETC_HAS_NO_SWITCH) && FSL_FEATURE_NETC_HAS_NO_SWITCH)
113 base->NUM_PROFILE[1].VLANIPVMPR0 = ipv[0];
114 base->NUM_PROFILE[1].VLANIPVMPR1 = ipv[1];
115 base->NUM_PROFILE[1].VLANDRMPR = dr;
116 #endif
117 }
118 else
119 {
120 base->NUM_PROFILE[0].VLANIPVMPR0 = ipv[0];
121 base->NUM_PROFILE[0].VLANIPVMPR1 = ipv[1];
122 base->NUM_PROFILE[0].VLANDRMPR = dr;
123 }
124 }
125
NETC_CmdBDRInit(netc_cbdr_hw_t * base,const netc_cmd_bdr_config_t * config)126 status_t NETC_CmdBDRInit(netc_cbdr_hw_t *base, const netc_cmd_bdr_config_t *config)
127 {
128 assert((base != NULL) && (config != NULL));
129 status_t status = kStatus_Success;
130 uint64_t address;
131
132 if ((0U != ((uint32_t)config->bdBase % 128U)) || (0U != (config->bdLength % 8U)))
133 {
134 status = kStatus_InvalidArgument;
135 }
136 else
137 {
138 /* Map function only supports 32-bit now, so here limit 32-bit first */
139 #if defined(FSL_FEATURE_MEMORY_HAS_ADDRESS_OFFSET) && FSL_FEATURE_MEMORY_HAS_ADDRESS_OFFSET
140 address = MEMORY_ConvertMemoryMapAddress((uintptr_t)config->bdBase, kMEMORY_Local2DMA);
141 #else
142 address = (uintptr_t)config->bdBase;
143 #endif
144 base->CBDRBAR0 = NETC_ADDR_LOW_32BIT(address);
145 base->CBDRBAR1 = NETC_ADDR_HIGH_32BIT(address);
146 base->CBDRPIR = 0U;
147 base->CBDRCIR = 0U;
148 base->CBDRLENR = (uint32_t)config->bdLength & ENETC_SI_SICBDRLENR_LENGTH_MASK;
149 base->CBDRMR |= ENETC_SI_SICBDRMR_EN_MASK;
150 }
151 return status;
152 }
153
NETC_CmdBDRDeinit(netc_cbdr_hw_t * base)154 status_t NETC_CmdBDRDeinit(netc_cbdr_hw_t *base)
155 {
156 assert(base != NULL);
157
158 base->CBDRMR &= ~ENETC_SI_SICBDRMR_EN_MASK;
159 base->CBDRBAR0 = 0U;
160 base->CBDRBAR1 = 0U;
161 base->CBDRPIR = 0U;
162 base->CBDRCIR = 0U;
163 base->CBDRLENR = 0U;
164
165 return kStatus_Success;
166 }
167
EP_CleanUsedBD(netc_cbdr_hw_t * base,netc_cmd_bdr_t * cbdr)168 static void EP_CleanUsedBD(netc_cbdr_hw_t *base, netc_cmd_bdr_t *cbdr)
169 {
170 uint16_t curCleanIndex = cbdr->cleanIndex;
171
172 while (curCleanIndex != base->CBDRCIR)
173 {
174 (void)memset((void *)&cbdr->bdBase[curCleanIndex], 0, sizeof(netc_cmd_bd_t));
175 curCleanIndex = (curCleanIndex + 1U) % cbdr->bdLength;
176 }
177 cbdr->cleanIndex = curCleanIndex;
178 }
179
NETC_CmdBDSendCommand(netc_cbdr_hw_t * base,netc_cmd_bdr_t * cbdr,netc_cmd_bd_t * cbd,netc_cbd_version_t version)180 status_t NETC_CmdBDSendCommand(netc_cbdr_hw_t *base,
181 netc_cmd_bdr_t *cbdr,
182 netc_cmd_bd_t *cbd,
183 netc_cbd_version_t version)
184 {
185 assert((base != NULL) && (cbdr != NULL) && (cbd != NULL));
186
187 status_t status = kStatus_Success;
188 uint16_t curIndex;
189
190 if ((!cbdr->bdrEnable) || (cbdr->cleanIndex == (cbdr->producerIndex + 1U) % cbdr->bdLength))
191 {
192 /* Selected BD ring is disable or full */
193 status = kStatus_InvalidArgument;
194 }
195
196 if (kStatus_Success == status)
197 {
198 if (version == kNETC_NtmpV2_0)
199 {
200 if (((uintptr_t)cbd->req.addr % 16U) != 0U)
201 {
202 /* The request and response data buffers start address must be 16-byte aligned */
203 return kStatus_InvalidArgument;
204 }
205 else
206 {
207 cbd->req.version = 0x2;
208 cbd->req.npf = 1;
209 #if defined(FSL_FEATURE_MEMORY_HAS_ADDRESS_OFFSET) && FSL_FEATURE_MEMORY_HAS_ADDRESS_OFFSET
210 cbd->req.addr = (uintptr_t)MEMORY_ConvertMemoryMapAddress((uint32_t)cbd->req.addr, kMEMORY_Local2DMA);
211 #endif
212 }
213 }
214 curIndex = cbdr->producerIndex;
215 /* Copy command data to ring */
216 cbdr->bdBase[curIndex] = *cbd;
217 /* Update BD ring producer index */
218 cbdr->producerIndex = (curIndex + 1U) % cbdr->bdLength;
219
220 /* Make sure all data in the command BD is ready. */
221 __DSB();
222 /* Let hardware know command BD has been added */
223 base->CBDRPIR = ((uint32_t)curIndex + 1U) % cbdr->bdLength;
224
225 /* Wait until the command is execution completed */
226 while (cbdr->producerIndex != base->CBDRCIR)
227 {
228 }
229
230 /* Copy command BD responses data */
231 *cbd = cbdr->bdBase[curIndex];
232 /* Clean the unused BDs */
233 EP_CleanUsedBD(base, cbdr);
234 /* Return detail error status if not run success */
235 if (version == kNETC_NtmpV2_0)
236 {
237 if (cbd->resp.error != 0U)
238 {
239 status = (status_t)cbd->resp.error;
240 }
241 }
242 else
243 {
244 if (cbd->generic.status != 0U)
245 {
246 status = (status_t)cbd->generic.status;
247 }
248 }
249 }
250
251 return status;
252 }
253
NETC_AddIPFTableEntry(netc_cbdr_handle_t * handle,netc_tb_ipf_config_t * config,uint32_t * entryID)254 status_t NETC_AddIPFTableEntry(netc_cbdr_handle_t *handle, netc_tb_ipf_config_t *config, uint32_t *entryID)
255 {
256 netc_cmd_bd_t cmdBd = {0};
257 status_t status = kStatus_Success;
258 (void)memset(handle->buffer, 0, sizeof(netc_tb_ipf_req_data_t));
259 /* Add entry to IPF Table and query the ENTRY_ID */
260 handle->buffer->ipf.request.cfge = config->cfge;
261 handle->buffer->ipf.request.keye = config->keye;
262 handle->buffer->ipf.request.commonHeader.updateActions =
263 (uint16_t)kNETC_IPFStsEUpdate | (uint16_t)kNETC_IPFCfgEUpdate;
264 handle->buffer->ipf.request.commonHeader.queryActions = 0U;
265 cmdBd.req.addr = (uintptr_t)handle->buffer;
266 cmdBd.req.reqLength = sizeof(netc_tb_ipf_req_data_t);
267 cmdBd.req.resLength = sizeof(netc_tb_ipf_rsp_data_t);
268 cmdBd.req.tableId = kNETC_IPFTable;
269 cmdBd.req.cmd = kNETC_AddAndQueryEntry;
270 /* Add operation only support Ternary Match Key Element Match */
271 cmdBd.req.accessType = kNETC_TernaryKeyMatch;
272 status = NETC_CmdBDSendCommand(handle->base, handle->cmdr, &cmdBd, kNETC_NtmpV2_0);
273 if (kStatus_Success == status)
274 {
275 *entryID = handle->buffer->ipf.response.entryID;
276 }
277 return status;
278 }
279
NETC_UpdateIPFTableEntry(netc_cbdr_handle_t * handle,uint32_t entryID,netc_tb_ipf_cfge_t * cfg)280 status_t NETC_UpdateIPFTableEntry(netc_cbdr_handle_t *handle, uint32_t entryID, netc_tb_ipf_cfge_t *cfg)
281 {
282 netc_cmd_bd_t cmdBd = {0};
283 (void)memset(handle->buffer, 0, sizeof(netc_tb_ipf_req_data_t));
284 /* Update entry in IPF Table base on the ENTRY_ID */
285 handle->buffer->ipf.request.cfge = *cfg;
286 handle->buffer->ipf.request.entryID = entryID;
287 handle->buffer->ipf.request.commonHeader.updateActions =
288 (uint16_t)kNETC_IPFStsEUpdate | (uint16_t)kNETC_IPFCfgEUpdate;
289 handle->buffer->ipf.request.commonHeader.queryActions = 0U;
290 cmdBd.req.addr = (uintptr_t)handle->buffer;
291 cmdBd.req.reqLength = sizeof(netc_tb_ipf_req_data_t);
292 cmdBd.req.resLength = sizeof(netc_tb_ipf_rsp_data_t);
293 cmdBd.req.tableId = kNETC_IPFTable;
294 cmdBd.req.cmd = kNETC_UpdateEntry;
295 cmdBd.req.accessType = kNETC_EntryIDMatch;
296 return NETC_CmdBDSendCommand(handle->base, handle->cmdr, &cmdBd, kNETC_NtmpV2_0);
297 }
298
NETC_QueryIPFTableEntry(netc_cbdr_handle_t * handle,uint32_t entryID,netc_tb_ipf_config_t * config)299 status_t NETC_QueryIPFTableEntry(netc_cbdr_handle_t *handle, uint32_t entryID, netc_tb_ipf_config_t *config)
300 {
301 netc_cmd_bd_t cmdBd = {0};
302 status_t status = kStatus_Success;
303 (void)memset(handle->buffer, 0, sizeof(netc_tb_ipf_req_data_t));
304 handle->buffer->ipf.request.entryID = entryID;
305 handle->buffer->ipf.request.commonHeader.updateActions = 0U;
306 handle->buffer->ipf.request.commonHeader.queryActions = 0U;
307 cmdBd.req.addr = (uintptr_t)handle->buffer;
308 cmdBd.req.reqLength = sizeof(netc_tb_ipf_req_data_t);
309 cmdBd.req.resLength = sizeof(netc_tb_ipf_rsp_data_t);
310 cmdBd.req.tableId = kNETC_IPFTable;
311 cmdBd.req.cmd = kNETC_QueryEntry;
312 cmdBd.req.accessType = kNETC_EntryIDMatch;
313 status = NETC_CmdBDSendCommand(handle->base, handle->cmdr, &cmdBd, kNETC_NtmpV2_0);
314 if (kStatus_Success == status)
315 {
316 config->keye = handle->buffer->ipf.response.keye;
317 config->cfge = handle->buffer->ipf.response.cfge;
318 }
319
320 return status;
321 }
322
NETC_DelIPFTableEntry(netc_cbdr_handle_t * handle,uint32_t entryID)323 status_t NETC_DelIPFTableEntry(netc_cbdr_handle_t *handle, uint32_t entryID)
324 {
325 netc_cmd_bd_t cmdBd = {0};
326 (void)memset(handle->buffer, 0, sizeof(netc_tb_ipf_req_data_t));
327 handle->buffer->ipf.request.entryID = entryID;
328 handle->buffer->ipf.request.commonHeader.updateActions = 0;
329 handle->buffer->ipf.request.commonHeader.queryActions = 0U;
330 cmdBd.req.addr = (uintptr_t)handle->buffer;
331 cmdBd.req.reqLength = sizeof(netc_tb_ipf_req_data_t);
332 cmdBd.req.resLength = 4U;
333 cmdBd.req.tableId = kNETC_IPFTable;
334 cmdBd.req.cmd = kNETC_DeleteEntry;
335 cmdBd.req.accessType = kNETC_EntryIDMatch;
336 return NETC_CmdBDSendCommand(handle->base, handle->cmdr, &cmdBd, kNETC_NtmpV2_0);
337 }
338
NETC_ResetIPFMatchCounter(netc_cbdr_handle_t * handle,uint32_t entryID)339 status_t NETC_ResetIPFMatchCounter(netc_cbdr_handle_t *handle, uint32_t entryID)
340 {
341 netc_cmd_bd_t cmdBd = {0};
342 (void)memset(handle->buffer, 0, sizeof(netc_tb_ipf_req_data_t));
343 handle->buffer->ipf.request.entryID = entryID;
344 handle->buffer->ipf.request.commonHeader.updateActions = (uint16_t)kNETC_IPFStsEUpdate;
345 handle->buffer->ipf.request.commonHeader.queryActions = 0U;
346 cmdBd.req.addr = (uintptr_t)handle->buffer;
347 cmdBd.req.reqLength = sizeof(netc_tb_ipf_req_data_t);
348 cmdBd.req.resLength = 4U;
349 cmdBd.req.tableId = kNETC_IPFTable;
350 cmdBd.req.cmd = kNETC_UpdateEntry;
351 cmdBd.req.accessType = kNETC_EntryIDMatch;
352 return NETC_CmdBDSendCommand(handle->base, handle->cmdr, &cmdBd, kNETC_NtmpV2_0);
353 }
354
NETC_GetIPFMatchedCount(netc_cbdr_handle_t * handle,uint32_t entryID,uint64_t * count)355 status_t NETC_GetIPFMatchedCount(netc_cbdr_handle_t *handle, uint32_t entryID, uint64_t *count)
356 {
357 status_t status = kStatus_Success;
358 netc_cmd_bd_t cmdBd = {0};
359
360 (void)memset(handle->buffer, 0, sizeof(netc_tb_ipf_req_data_t));
361 handle->buffer->ipf.request.entryID = entryID;
362 handle->buffer->ipf.request.commonHeader.updateActions = 0U;
363 handle->buffer->ipf.request.commonHeader.queryActions = 0U;
364 cmdBd.req.addr = (uintptr_t)handle->buffer;
365 cmdBd.req.reqLength = sizeof(netc_tb_ipf_keye_t) + 4U;
366 cmdBd.req.resLength = sizeof(netc_tb_ipf_rsp_data_t);
367 cmdBd.req.tableId = kNETC_IPFTable;
368 cmdBd.req.cmd = kNETC_QueryEntry;
369 cmdBd.req.accessType = kNETC_EntryIDMatch;
370 status = NETC_CmdBDSendCommand(handle->base, handle->cmdr, &cmdBd, kNETC_NtmpV2_0);
371 if (kStatus_Success == status)
372 {
373 *count = ((uint64_t)handle->buffer->ipf.response.stse.matchCount[1] << 32U) |
374 handle->buffer->ipf.response.stse.matchCount[0];
375 }
376 return status;
377 }
378
NETC_AddISITableEntry(netc_cbdr_handle_t * handle,netc_tb_isi_config_t * config,uint32_t * entryID)379 status_t NETC_AddISITableEntry(netc_cbdr_handle_t *handle, netc_tb_isi_config_t *config, uint32_t *entryID)
380 {
381 netc_cmd_bd_t cmdBd = {0};
382 status_t status = kStatus_Success;
383 (void)memset(handle->buffer, 0, sizeof(netc_tb_isi_req_data_t));
384 /* Add entry to ISI Table and query the ENTRY_ID */
385 handle->buffer->isi.request.cfge = config->cfge;
386 handle->buffer->isi.request.keye = config->keye;
387 handle->buffer->isi.request.commonHeader.updateActions = 1U;
388 /* Query ENTRY_ID only */
389 handle->buffer->isi.request.commonHeader.queryActions = 1U;
390 cmdBd.req.addr = (uintptr_t)handle->buffer;
391 cmdBd.req.reqLength = sizeof(netc_tb_isi_req_data_t);
392 cmdBd.req.resLength = sizeof(netc_tb_isi_rsp_data_t);
393 cmdBd.req.tableId = kNETC_ISITable;
394 cmdBd.req.cmd = kNETC_AddAndQueryEntry;
395 /* Add operation only support Exact Match Key Element Match */
396 cmdBd.req.accessType = kNETC_ExactKeyMatch;
397 status = NETC_CmdBDSendCommand(handle->base, handle->cmdr, &cmdBd, kNETC_NtmpV2_0);
398 if (kStatus_Success == status)
399 {
400 *entryID = handle->buffer->isi.response.entryID;
401 }
402
403 return status;
404 }
405
NETC_QueryISITableEntry(netc_cbdr_handle_t * handle,uint32_t entryID,netc_tb_isi_config_t * config)406 status_t NETC_QueryISITableEntry(netc_cbdr_handle_t *handle, uint32_t entryID, netc_tb_isi_config_t *config)
407 {
408 netc_cmd_bd_t cmdBd = {0};
409 status_t status = kStatus_Success;
410 (void)memset(handle->buffer, 0, sizeof(netc_tb_isi_req_data_t));
411 handle->buffer->isi.request.entryID = entryID;
412 handle->buffer->isi.request.commonHeader.updateActions = 0U;
413 handle->buffer->isi.request.commonHeader.queryActions = 0U;
414 cmdBd.req.addr = (uintptr_t)handle->buffer;
415 cmdBd.req.reqLength = sizeof(netc_tb_isi_req_data_t);
416 cmdBd.req.resLength = sizeof(netc_tb_isi_rsp_data_t);
417 cmdBd.req.tableId = kNETC_ISITable;
418 cmdBd.req.cmd = kNETC_QueryEntry;
419 cmdBd.req.accessType = kNETC_EntryIDMatch;
420 status = NETC_CmdBDSendCommand(handle->base, handle->cmdr, &cmdBd, kNETC_NtmpV2_0);
421 if (kStatus_Success == status)
422 {
423 if (0U != cmdBd.resp.numMatched)
424 {
425 config->keye = handle->buffer->isi.response.keye;
426 config->cfge = handle->buffer->isi.response.cfge;
427 }
428 else
429 {
430 status = kStatus_NETC_NotFound;
431 }
432 }
433
434 return status;
435 }
436
NETC_QueryISITableEntryWithKey(netc_cbdr_handle_t * handle,netc_tb_isi_keye_t * keye,netc_tb_isi_rsp_data_t * rsp)437 status_t NETC_QueryISITableEntryWithKey(netc_cbdr_handle_t *handle, netc_tb_isi_keye_t *keye, netc_tb_isi_rsp_data_t *rsp)
438 {
439 netc_cmd_bd_t cmdBd = {0};
440 status_t status = kStatus_Success;
441 (void)memset(handle->buffer, 0, sizeof(netc_tb_isi_req_data_t));
442 handle->buffer->isi.request.keye = *keye;
443 handle->buffer->isi.request.commonHeader.updateActions = 0U;
444 handle->buffer->isi.request.commonHeader.queryActions = 0U;
445 cmdBd.req.addr = (uintptr_t)handle->buffer;
446 cmdBd.req.reqLength = sizeof(netc_tb_isi_req_data_t);
447 cmdBd.req.resLength = sizeof(netc_tb_isi_rsp_data_t);
448 cmdBd.req.tableId = kNETC_ISITable;
449 cmdBd.req.cmd = kNETC_QueryEntry;
450 cmdBd.req.accessType = kNETC_ExactKeyMatch;
451 status = NETC_CmdBDSendCommand(handle->base, handle->cmdr, &cmdBd, kNETC_NtmpV2_0);
452 if (kStatus_Success == status)
453 {
454 if (0U != cmdBd.resp.numMatched)
455 {
456 *rsp = handle->buffer->isi.response;
457 }
458 else
459 {
460 status = kStatus_NETC_NotFound;
461 }
462 }
463
464 return status;
465 }
466
NETC_DelISITableEntry(netc_cbdr_handle_t * handle,uint32_t entryID)467 status_t NETC_DelISITableEntry(netc_cbdr_handle_t *handle, uint32_t entryID)
468 {
469 netc_cmd_bd_t cmdBd = {0};
470 (void)memset(handle->buffer, 0, sizeof(netc_tb_isi_req_data_t));
471 handle->buffer->isi.request.entryID = entryID;
472 handle->buffer->isi.request.commonHeader.updateActions = 0;
473 handle->buffer->isi.request.commonHeader.queryActions = 0U;
474 cmdBd.req.addr = (uintptr_t)handle->buffer;
475 cmdBd.req.reqLength = 24U;
476 cmdBd.req.resLength = 4U;
477 cmdBd.req.tableId = kNETC_ISITable;
478 cmdBd.req.cmd = kNETC_DeleteEntry;
479 cmdBd.req.accessType = kNETC_EntryIDMatch;
480 return NETC_CmdBDSendCommand(handle->base, handle->cmdr, &cmdBd, kNETC_NtmpV2_0);
481 }
482
NETC_AddOrUpdateISTableEntry(netc_cbdr_handle_t * handle,netc_tb_is_config_t * config,bool isAdd)483 status_t NETC_AddOrUpdateISTableEntry(netc_cbdr_handle_t *handle, netc_tb_is_config_t *config, bool isAdd)
484 {
485 netc_cmd_bd_t cmdBd = {0};
486 (void)memset(handle->buffer, 0, sizeof(netc_tb_isi_req_data_t));
487 /* Add or Update entry in IS Table */
488 handle->buffer->is.request.cfge = config->cfge;
489 handle->buffer->is.request.entryID = config->entryID;
490 handle->buffer->is.request.commonHeader.updateActions = 1U;
491 handle->buffer->is.request.commonHeader.queryActions = 0U;
492 cmdBd.req.addr = (uintptr_t)handle->buffer;
493 cmdBd.req.reqLength = sizeof(netc_tb_is_req_data_t);
494 cmdBd.req.resLength = sizeof(netc_tb_is_rsp_data_t);
495 cmdBd.req.tableId = kNETC_ISTable;
496 if (isAdd)
497 {
498 cmdBd.req.cmd = kNETC_AddEntry;
499 }
500 else
501 {
502 cmdBd.req.cmd = kNETC_UpdateEntry;
503 }
504 /* Only support ID Match Key Element Match */
505 cmdBd.req.accessType = kNETC_EntryIDMatch;
506 return NETC_CmdBDSendCommand(handle->base, handle->cmdr, &cmdBd, kNETC_NtmpV2_0);
507 }
508
NETC_QueryISTableEntry(netc_cbdr_handle_t * handle,uint32_t entryID,netc_tb_is_config_t * config)509 status_t NETC_QueryISTableEntry(netc_cbdr_handle_t *handle, uint32_t entryID, netc_tb_is_config_t *config)
510 {
511 netc_cmd_bd_t cmdBd = {0};
512 status_t status = kStatus_Success;
513 (void)memset(handle->buffer, 0, sizeof(netc_tb_is_req_data_t));
514 handle->buffer->is.request.entryID = entryID;
515 handle->buffer->is.request.commonHeader.updateActions = 0U;
516 handle->buffer->is.request.commonHeader.queryActions = 0U;
517 cmdBd.req.addr = (uintptr_t)handle->buffer;
518 cmdBd.req.reqLength = sizeof(netc_tb_is_req_data_t);
519 cmdBd.req.resLength = sizeof(netc_tb_is_rsp_data_t);
520 cmdBd.req.tableId = kNETC_ISTable;
521 cmdBd.req.cmd = kNETC_QueryEntry;
522 cmdBd.req.accessType = kNETC_EntryIDMatch;
523 status = NETC_CmdBDSendCommand(handle->base, handle->cmdr, &cmdBd, kNETC_NtmpV2_0);
524 if (kStatus_Success == status)
525 {
526 if (0U != cmdBd.resp.numMatched)
527 {
528 config->entryID = handle->buffer->is.response.entryID;
529 config->cfge = handle->buffer->is.response.cfge;
530 }
531 else
532 {
533 status = kStatus_NETC_NotFound;
534 }
535 }
536
537 return status;
538 }
539
NETC_DelISTableEntry(netc_cbdr_handle_t * handle,uint32_t entryID)540 status_t NETC_DelISTableEntry(netc_cbdr_handle_t *handle, uint32_t entryID)
541 {
542 netc_cmd_bd_t cmdBd = {0};
543 (void)memset(handle->buffer, 0, sizeof(netc_tb_is_req_data_t));
544 handle->buffer->is.request.entryID = entryID;
545 handle->buffer->is.request.commonHeader.updateActions = 0;
546 handle->buffer->is.request.commonHeader.queryActions = 0U;
547 cmdBd.req.addr = (uintptr_t)handle->buffer;
548 cmdBd.req.reqLength = 8U;
549 cmdBd.req.resLength = 0U;
550 cmdBd.req.tableId = kNETC_ISTable;
551 cmdBd.req.cmd = kNETC_DeleteEntry;
552 cmdBd.req.accessType = kNETC_EntryIDMatch;
553 return NETC_CmdBDSendCommand(handle->base, handle->cmdr, &cmdBd, kNETC_NtmpV2_0);
554 }
555
NETC_AddISFTableEntry(netc_cbdr_handle_t * handle,netc_tb_isf_config_t * config,uint32_t * entryID)556 status_t NETC_AddISFTableEntry(netc_cbdr_handle_t *handle, netc_tb_isf_config_t *config, uint32_t *entryID)
557 {
558 netc_cmd_bd_t cmdBd = {0};
559 status_t status = kStatus_Success;
560 (void)memset(handle->buffer, 0, sizeof(netc_tb_isi_req_data_t));
561 /* Add entry to ISF Table and query the ENTRY_ID */
562 handle->buffer->isf.request.cfge = config->cfge;
563 handle->buffer->isf.request.keye = config->keye;
564 handle->buffer->isf.request.commonHeader.updateActions = 1U;
565 /* Query ENTRY_ID only */
566 handle->buffer->isi.request.commonHeader.queryActions = 1U;
567 cmdBd.req.addr = (uintptr_t)handle->buffer;
568 cmdBd.req.reqLength = sizeof(netc_tb_isf_req_data_t);
569 cmdBd.req.resLength = sizeof(netc_tb_isf_rsp_data_t);
570 cmdBd.req.tableId = kNETC_ISFTable;
571 cmdBd.req.cmd = kNETC_AddAndQueryEntry;
572 /* Add operation only support Exact Match Key Element Match */
573 cmdBd.req.accessType = kNETC_ExactKeyMatch;
574 status = NETC_CmdBDSendCommand(handle->base, handle->cmdr, &cmdBd, kNETC_NtmpV2_0);
575 if (kStatus_Success == status)
576 {
577 *entryID = handle->buffer->isf.response.entryID;
578 }
579
580 return status;
581 }
582
NETC_UpdateISFTableEntry(netc_cbdr_handle_t * handle,uint32_t entryID,netc_tb_isf_cfge_t * cfg)583 status_t NETC_UpdateISFTableEntry(netc_cbdr_handle_t *handle, uint32_t entryID, netc_tb_isf_cfge_t *cfg)
584 {
585 netc_cmd_bd_t cmdBd = {0};
586 (void)memset(handle->buffer, 0, sizeof(netc_tb_isi_req_data_t));
587 /* Update entry in ISF Table base on the ENTRY_ID */
588 handle->buffer->isf.request.cfge = *cfg;
589 handle->buffer->isf.request.entryID = entryID;
590 handle->buffer->isf.request.commonHeader.updateActions = 1U;
591 cmdBd.req.addr = (uintptr_t)handle->buffer;
592 cmdBd.req.reqLength = sizeof(netc_tb_isf_req_data_t);
593 cmdBd.req.resLength = sizeof(netc_tb_isf_rsp_data_t);
594 cmdBd.req.tableId = kNETC_ISFTable;
595 cmdBd.req.cmd = kNETC_UpdateEntry;
596 cmdBd.req.accessType = kNETC_EntryIDMatch;
597 return NETC_CmdBDSendCommand(handle->base, handle->cmdr, &cmdBd, kNETC_NtmpV2_0);
598 }
599
NETC_DelISFTableEntry(netc_cbdr_handle_t * handle,uint32_t entryID)600 status_t NETC_DelISFTableEntry(netc_cbdr_handle_t *handle, uint32_t entryID)
601 {
602 netc_cmd_bd_t cmdBd = {0};
603 (void)memset(handle->buffer, 0, sizeof(netc_tb_isf_req_data_t));
604 handle->buffer->isf.request.entryID = entryID;
605 handle->buffer->isf.request.commonHeader.updateActions = 0;
606 handle->buffer->isf.request.commonHeader.queryActions = 0U;
607 cmdBd.req.addr = (uintptr_t)handle->buffer;
608 cmdBd.req.reqLength = 12U;
609 cmdBd.req.resLength = 4U;
610 cmdBd.req.tableId = kNETC_ISFTable;
611 cmdBd.req.cmd = kNETC_DeleteEntry;
612 cmdBd.req.accessType = kNETC_EntryIDMatch;
613 return NETC_CmdBDSendCommand(handle->base, handle->cmdr, &cmdBd, kNETC_NtmpV2_0);
614 }
615
NETC_QueryISFTableEntry(netc_cbdr_handle_t * handle,netc_tb_isf_keye_t * keye,netc_tb_isf_rsp_data_t * rsp)616 status_t NETC_QueryISFTableEntry(netc_cbdr_handle_t *handle, netc_tb_isf_keye_t *keye, netc_tb_isf_rsp_data_t *rsp)
617 {
618 netc_cmd_bd_t cmdBd = {0};
619 status_t status = kStatus_Success;
620 (void)memset(handle->buffer, 0, sizeof(netc_tb_isf_req_data_t));
621 handle->buffer->isf.request.keye = *keye;
622 handle->buffer->isf.request.commonHeader.updateActions = 0U;
623 handle->buffer->isf.request.commonHeader.queryActions = 0U;
624 cmdBd.req.addr = (uintptr_t)handle->buffer;
625 cmdBd.req.reqLength = sizeof(netc_tb_isf_req_data_t);
626 cmdBd.req.resLength = sizeof(netc_tb_isf_rsp_data_t);
627 cmdBd.req.tableId = kNETC_ISFTable;
628 cmdBd.req.cmd = kNETC_QueryEntry;
629 cmdBd.req.accessType = kNETC_ExactKeyMatch;
630 status = NETC_CmdBDSendCommand(handle->base, handle->cmdr, &cmdBd, kNETC_NtmpV2_0);
631 if (kStatus_Success == status)
632 {
633 if (0U != cmdBd.resp.numMatched)
634 {
635 *rsp = handle->buffer->isf.response;
636 }
637 else
638 {
639 status = kStatus_NETC_NotFound;
640 }
641 }
642 return status;
643 }
644
NETC_AddISCTableEntry(netc_cbdr_handle_t * handle,uint32_t entryID)645 status_t NETC_AddISCTableEntry(netc_cbdr_handle_t *handle, uint32_t entryID)
646 {
647 netc_cmd_bd_t cmdBd = {0};
648 (void)memset(handle->buffer, 0, sizeof(netc_tb_isi_req_data_t));
649 /* Add entry to ISC Table according to the ENTRY_ID (ISC_EID) */
650 handle->buffer->isc.request.entryID = entryID;
651 handle->buffer->isc.request.commonHeader.updateActions = 0U;
652 handle->buffer->isc.request.commonHeader.queryActions = 0U;
653 cmdBd.req.addr = (uintptr_t)handle->buffer;
654 cmdBd.req.reqLength = sizeof(netc_tb_isc_req_data_t);
655 cmdBd.req.resLength = sizeof(netc_tb_isc_rsp_data_t);
656 cmdBd.req.tableId = kNETC_ISCTable;
657 cmdBd.req.cmd = kNETC_AddEntry;
658 /* Only support ID Match Key Element Match */
659 cmdBd.req.accessType = kNETC_EntryIDMatch;
660 return NETC_CmdBDSendCommand(handle->base, handle->cmdr, &cmdBd, kNETC_NtmpV2_0);
661 }
662
NETC_GetISCStatistic(netc_cbdr_handle_t * handle,uint32_t entryID,netc_tb_isc_stse_t * statistic)663 status_t NETC_GetISCStatistic(netc_cbdr_handle_t *handle, uint32_t entryID, netc_tb_isc_stse_t *statistic)
664 {
665 netc_cmd_bd_t cmdBd = {0};
666 status_t status = kStatus_Success;
667 (void)memset(handle->buffer, 0, sizeof(netc_tb_isc_req_data_t));
668 handle->buffer->isc.request.entryID = entryID;
669 handle->buffer->isc.request.commonHeader.updateActions = 0U;
670 handle->buffer->isc.request.commonHeader.queryActions = 0U;
671 cmdBd.req.addr = (uintptr_t)handle->buffer;
672 cmdBd.req.reqLength = sizeof(netc_tb_isc_req_data_t);
673 cmdBd.req.resLength = sizeof(netc_tb_isc_rsp_data_t);
674 cmdBd.req.tableId = kNETC_ISCTable;
675 cmdBd.req.cmd = kNETC_QueryEntry;
676 /* Only support ID Match Key Element Match */
677 cmdBd.req.accessType = kNETC_EntryIDMatch;
678 status = NETC_CmdBDSendCommand(handle->base, handle->cmdr, &cmdBd, kNETC_NtmpV2_0);
679 if (kStatus_Success == status)
680 {
681 *statistic = handle->buffer->isc.response.stse;
682 }
683 return status;
684 }
685
NETC_ResetISCStatistic(netc_cbdr_handle_t * handle,uint32_t entryID)686 status_t NETC_ResetISCStatistic(netc_cbdr_handle_t *handle, uint32_t entryID)
687 {
688 netc_cmd_bd_t cmdBd = {0};
689 (void)memset(handle->buffer, 0, sizeof(netc_tb_isc_req_data_t));
690 /* Reset ISC Table according to the ENTRY_ID (ISC_EID) */
691 handle->buffer->isc.request.entryID = entryID;
692 handle->buffer->isc.request.commonHeader.updateActions = 1U;
693 handle->buffer->isc.request.commonHeader.queryActions = 0U;
694 cmdBd.req.addr = (uintptr_t)handle->buffer;
695 cmdBd.req.reqLength = sizeof(netc_tb_isc_req_data_t);
696 cmdBd.req.resLength = sizeof(netc_tb_isc_rsp_data_t);
697 cmdBd.req.tableId = kNETC_ISCTable;
698 cmdBd.req.cmd = kNETC_UpdateEntry;
699 /* Only support ID Match Key Element Match */
700 cmdBd.req.accessType = kNETC_EntryIDMatch;
701 return NETC_CmdBDSendCommand(handle->base, handle->cmdr, &cmdBd, kNETC_NtmpV2_0);
702 }
703
NETC_AddOrUpdateSGITableEntry(netc_cbdr_handle_t * handle,netc_tb_sgi_config_t * config,bool isAdd)704 status_t NETC_AddOrUpdateSGITableEntry(netc_cbdr_handle_t *handle, netc_tb_sgi_config_t *config, bool isAdd)
705 {
706 netc_cmd_bd_t cmdBd = {0};
707 (void)memset(handle->buffer, 0, sizeof(netc_tb_sgi_req_data_t));
708 /* Add entry to SGI Table */
709 handle->buffer->sgi.request.acfge = config->acfge;
710 handle->buffer->sgi.request.cfge = config->cfge;
711 handle->buffer->sgi.request.icfge = config->icfge;
712 handle->buffer->sgi.request.entryID = config->entryID;
713 handle->buffer->sgi.request.commonHeader.updateActions =
714 (uint16_t)kNETC_SGIAcfEUpdate | (uint16_t)kNETC_SGICfgEUpdate | (uint16_t)kNETC_SGISgisEUpdate;
715 handle->buffer->sgi.request.commonHeader.queryActions = 0U;
716 cmdBd.req.addr = (uintptr_t)handle->buffer;
717 cmdBd.req.reqLength = sizeof(netc_tb_sgi_req_data_t);
718 cmdBd.req.resLength = sizeof(netc_tb_sgi_rsp_data_t);
719 cmdBd.req.tableId = kNETC_SGITable;
720 if (isAdd)
721 {
722 cmdBd.req.cmd = kNETC_AddEntry;
723 }
724 else
725 {
726 cmdBd.req.cmd = kNETC_UpdateEntry;
727 }
728 cmdBd.req.accessType = kNETC_EntryIDMatch;
729 return NETC_CmdBDSendCommand(handle->base, handle->cmdr, &cmdBd, kNETC_NtmpV2_0);
730 }
731
NETC_DelSGITableEntry(netc_cbdr_handle_t * handle,uint32_t entryID)732 status_t NETC_DelSGITableEntry(netc_cbdr_handle_t *handle, uint32_t entryID)
733 {
734 netc_cmd_bd_t cmdBd = {0};
735 (void)memset(handle->buffer, 0, sizeof(netc_tb_sgi_req_data_t));
736 /* Delete entry in SGI Table */
737 handle->buffer->sgi.request.entryID = entryID;
738 handle->buffer->sgi.request.commonHeader.updateActions = 0U;
739 handle->buffer->sgi.request.commonHeader.queryActions = 0U;
740 cmdBd.req.addr = (uintptr_t)handle->buffer;
741 cmdBd.req.reqLength = sizeof(netc_tb_sgi_req_data_t);
742 cmdBd.req.resLength = sizeof(netc_tb_sgi_rsp_data_t);
743 cmdBd.req.tableId = kNETC_SGITable;
744 cmdBd.req.cmd = kNETC_DeleteEntry;
745 cmdBd.req.accessType = kNETC_EntryIDMatch;
746 return NETC_CmdBDSendCommand(handle->base, handle->cmdr, &cmdBd, kNETC_NtmpV2_0);
747 }
748
NETC_GetSGIState(netc_cbdr_handle_t * handle,uint32_t entryID,netc_tb_sgi_sgise_t * statis)749 status_t NETC_GetSGIState(netc_cbdr_handle_t *handle, uint32_t entryID, netc_tb_sgi_sgise_t *statis)
750 {
751 netc_cmd_bd_t cmdBd = {0};
752 status_t status = kStatus_Success;
753 (void)memset(handle->buffer, 0, sizeof(netc_tb_sgi_rsp_data_t));
754 handle->buffer->sgi.request.entryID = entryID;
755 handle->buffer->sgi.request.commonHeader.updateActions = 0U;
756 handle->buffer->sgi.request.commonHeader.queryActions = 0U;
757 cmdBd.req.addr = (uintptr_t)handle->buffer;
758 cmdBd.req.reqLength = 8U;
759 cmdBd.req.resLength = sizeof(netc_tb_sgi_rsp_data_t);
760 cmdBd.req.tableId = kNETC_SGITable;
761 cmdBd.req.cmd = kNETC_QueryEntry;
762 cmdBd.req.accessType = kNETC_EntryIDMatch;
763 status = NETC_CmdBDSendCommand(handle->base, handle->cmdr, &cmdBd, kNETC_NtmpV2_0);
764 if (kStatus_Success == status)
765 {
766 *statis = handle->buffer->sgi.response.sgise;
767 }
768 return status;
769 }
770
NETC_QuerySGITableEntry(netc_cbdr_handle_t * handle,uint32_t entryID,netc_tb_sgi_rsp_data_t * rsp)771 status_t NETC_QuerySGITableEntry(netc_cbdr_handle_t *handle, uint32_t entryID, netc_tb_sgi_rsp_data_t *rsp)
772 {
773 netc_cmd_bd_t cmdBd = {0};
774 status_t status = kStatus_Success;
775 (void)memset(handle->buffer, 0, sizeof(netc_tb_sgi_rsp_data_t));
776 handle->buffer->sgi.request.entryID = entryID;
777 handle->buffer->sgi.request.commonHeader.updateActions = 0U;
778 handle->buffer->sgi.request.commonHeader.queryActions = 0U;
779 cmdBd.req.addr = (uintptr_t)handle->buffer;
780 cmdBd.req.reqLength = 8U;
781 cmdBd.req.resLength = sizeof(netc_tb_sgi_rsp_data_t);
782 cmdBd.req.tableId = kNETC_SGITable;
783 cmdBd.req.cmd = kNETC_QueryEntry;
784 cmdBd.req.accessType = kNETC_EntryIDMatch;
785 status = NETC_CmdBDSendCommand(handle->base, handle->cmdr, &cmdBd, kNETC_NtmpV2_0);
786 if (kStatus_Success == status)
787 {
788 if (cmdBd.resp.numMatched != 0U)
789 {
790 *rsp = handle->buffer->sgi.response;
791 }
792 else
793 {
794 status = kStatus_NETC_NotFound;
795 }
796 }
797
798 return status;
799 }
800
NETC_AddSGCLTableEntry(netc_cbdr_handle_t * handle,netc_tb_sgcl_gcl_t * config)801 status_t NETC_AddSGCLTableEntry(netc_cbdr_handle_t *handle, netc_tb_sgcl_gcl_t *config)
802 {
803 netc_cmd_bd_t cmdBd = {0};
804
805 if ((config->numEntries > NETC_TB_SGCL_MAX_ENTRY) || (config->numEntries == 0U) || (config->gcList == NULL))
806 {
807 return kStatus_InvalidArgument;
808 }
809 (void)memset(handle->buffer, 0, 24U + config->numEntries * 8U);
810 handle->buffer->sgcl.request.entryID = config->entryID;
811 handle->buffer->sgcl.request.commonHeader.updateActions = 0U;
812 handle->buffer->sgcl.request.commonHeader.queryActions = 0U;
813 /* Initialize Stream Gate Control List entry */
814 handle->buffer->sgcl.request.cfge.cycleTime = config->cycleTime;
815 /* The entry numbers is LIST_LENGTH -1 */
816 handle->buffer->sgcl.request.cfge.listLength = (uint8_t)(config->numEntries - 1U);
817 handle->buffer->sgcl.request.cfge.extOipv = config->extOipv;
818 handle->buffer->sgcl.request.cfge.extIpv = config->extIpv;
819 handle->buffer->sgcl.request.cfge.extCtd = config->extCtd;
820 handle->buffer->sgcl.request.cfge.extGtst = config->extGtst;
821 (void)memcpy(&handle->buffer->sgcl.request.cfge.ges[0], config->gcList, config->numEntries * 8U);
822 cmdBd.req.addr = (uintptr_t)handle->buffer;
823 cmdBd.req.reqLength = 24U + config->numEntries * 8U;
824 cmdBd.req.resLength = 0U;
825 cmdBd.req.tableId = kNETC_SGCLTable;
826 cmdBd.req.cmd = kNETC_AddEntry;
827 cmdBd.req.accessType = kNETC_EntryIDMatch;
828 return NETC_CmdBDSendCommand(handle->base, handle->cmdr, &cmdBd, kNETC_NtmpV2_0);
829 }
830
NETC_DelSGCLTableEntry(netc_cbdr_handle_t * handle,uint32_t entryID)831 status_t NETC_DelSGCLTableEntry(netc_cbdr_handle_t *handle, uint32_t entryID)
832 {
833 netc_cmd_bd_t cmdBd = {0};
834 (void)memset(handle->buffer, 0, sizeof(netc_tb_sgcl_req_data_t));
835 handle->buffer->sgcl.request.entryID = entryID;
836 handle->buffer->sgcl.request.commonHeader.updateActions = 0U;
837 handle->buffer->sgcl.request.commonHeader.queryActions = 0U;
838 cmdBd.req.addr = (uintptr_t)handle->buffer;
839 cmdBd.req.reqLength = 8U;
840 cmdBd.req.resLength = 0U;
841 cmdBd.req.tableId = kNETC_SGCLTable;
842 cmdBd.req.cmd = kNETC_DeleteEntry;
843 cmdBd.req.accessType = kNETC_EntryIDMatch;
844 return NETC_CmdBDSendCommand(handle->base, handle->cmdr, &cmdBd, kNETC_NtmpV2_0);
845 }
846
NETC_GetSGCLGateList(netc_cbdr_handle_t * handle,netc_tb_sgcl_gcl_t * gcl,uint32_t length)847 status_t NETC_GetSGCLGateList(netc_cbdr_handle_t *handle, netc_tb_sgcl_gcl_t *gcl, uint32_t length)
848 {
849 status_t status = kStatus_Success;
850 netc_cmd_bd_t cmdBd = {0};
851 if (gcl->gcList == NULL)
852 {
853 return kStatus_InvalidArgument;
854 }
855 (void)memset(handle->buffer, 0, sizeof(netc_tb_sgcl_req_data_t));
856 handle->buffer->sgcl.request.entryID = gcl->entryID;
857 handle->buffer->sgcl.request.commonHeader.updateActions = 0U;
858 handle->buffer->sgcl.request.commonHeader.queryActions = 0U;
859 cmdBd.req.addr = (uintptr_t)handle->buffer;
860 cmdBd.req.reqLength = 8U;
861 cmdBd.req.resLength = sizeof(netc_tb_sgcl_data_t);
862 cmdBd.req.tableId = kNETC_SGCLTable;
863 cmdBd.req.cmd = kNETC_QueryEntry;
864 cmdBd.req.accessType = kNETC_EntryIDMatch;
865 status = NETC_CmdBDSendCommand(handle->base, handle->cmdr, &cmdBd, kNETC_NtmpV2_0);
866 if (kStatus_Success == status)
867 {
868 if (cmdBd.resp.numMatched != 0U)
869 {
870 if (((uint32_t)handle->buffer->sgcl.request.cfge.listLength + 1U) > length)
871 {
872 status = kStatus_InvalidArgument;
873 }
874 else
875 {
876 gcl->cycleTime = handle->buffer->sgcl.request.cfge.cycleTime;
877 /* The entry numbers is LIST_LENGTH -1 */
878 gcl->numEntries = (uint32_t)handle->buffer->sgcl.request.cfge.listLength + 1U;
879 gcl->extOipv = handle->buffer->sgcl.request.cfge.extOipv;
880 gcl->extIpv = handle->buffer->sgcl.request.cfge.extIpv;
881 gcl->extCtd = handle->buffer->sgcl.request.cfge.extCtd;
882 gcl->extGtst = handle->buffer->sgcl.request.cfge.extGtst;
883 (void)memcpy(gcl->gcList, &handle->buffer->sgcl.request.cfge.ges[0], gcl->numEntries * 8U);
884 }
885 }
886 else
887 {
888 status = kStatus_NETC_NotFound;
889 }
890 }
891 return status;
892 }
NETC_GetSGCLState(netc_cbdr_handle_t * handle,uint32_t entryID,netc_tb_sgcl_sgclse_t * state)893 status_t NETC_GetSGCLState(netc_cbdr_handle_t *handle, uint32_t entryID, netc_tb_sgcl_sgclse_t *state)
894 {
895 status_t status = kStatus_Success;
896 netc_cmd_bd_t cmdBd = {0};
897 (void)memset(handle->buffer, 0, sizeof(netc_tb_sgcl_req_data_t));
898 handle->buffer->sgcl.request.entryID = entryID;
899 handle->buffer->sgcl.request.commonHeader.updateActions = 0U;
900 handle->buffer->sgcl.request.commonHeader.queryActions = 0U;
901 cmdBd.req.addr = (uintptr_t)handle->buffer;
902 cmdBd.req.reqLength = 8U;
903 cmdBd.req.resLength = sizeof(netc_tb_sgcl_data_t);
904 cmdBd.req.tableId = kNETC_SGCLTable;
905 cmdBd.req.cmd = kNETC_QueryEntry;
906 cmdBd.req.accessType = kNETC_EntryIDMatch;
907 status = NETC_CmdBDSendCommand(handle->base, handle->cmdr, &cmdBd, kNETC_NtmpV2_0);
908 if (kStatus_Success == status)
909 {
910 *state = handle->buffer->sgcl.response.sgclse;
911 }
912 return status;
913 }
914
NETC_AddOrUpdateRPTableEntry(netc_cbdr_handle_t * handle,netc_tb_rp_config_t * config,netc_tb_cmd_t cmd)915 status_t NETC_AddOrUpdateRPTableEntry(netc_cbdr_handle_t *handle, netc_tb_rp_config_t *config, netc_tb_cmd_t cmd)
916 {
917 status_t status;
918 netc_cmd_bd_t cmdBd = {0};
919 (void)memset(handle->buffer, 0, sizeof(netc_tb_rp_req_data_t));
920 /* Add or Update entry to Rate Policer Table */
921 handle->buffer->rp.request.entryID = config->entryID;
922 handle->buffer->rp.request.cfge = config->cfge;
923 handle->buffer->rp.request.fee = config->fee;
924 handle->buffer->rp.request.commonHeader.updateActions = (uint16_t)kNETC_RPCfgEUpdate | (uint16_t)kNETC_RPFeEUpdate;
925 handle->buffer->rp.request.commonHeader.queryActions = 0U;
926 cmdBd.req.addr = (uintptr_t)handle->buffer;
927 cmdBd.req.reqLength = sizeof(netc_tb_rp_req_data_t);
928 cmdBd.req.resLength = 0U;
929 cmdBd.req.tableId = kNETC_RPTable;
930 cmdBd.req.cmd = cmd;
931
932 /* Only support Entry ID Match */
933 cmdBd.req.accessType = kNETC_EntryIDMatch;
934 status = NETC_CmdBDSendCommand(handle->base, handle->cmdr, &cmdBd, kNETC_NtmpV2_0);
935 if (kStatus_Success == status)
936 {
937 if ((cmd == kNETC_AddEntry) && (cmdBd.resp.numMatched > 0U))
938 {
939 status = kStatus_NETC_EntryExists;
940 }
941 else if ((cmd == kNETC_UpdateEntry) && (cmdBd.resp.numMatched == 0U))
942 {
943 status = kStatus_NETC_NotFound;
944 }
945 else
946 {
947 /* Intentional empty */
948 }
949 }
950
951 return status;
952 }
953
NETC_DelRPTableEntry(netc_cbdr_handle_t * handle,uint32_t entryID)954 status_t NETC_DelRPTableEntry(netc_cbdr_handle_t *handle, uint32_t entryID)
955 {
956 netc_cmd_bd_t cmdBd = {0};
957 (void)memset(handle->buffer, 0, sizeof(netc_tb_rp_req_data_t));
958 handle->buffer->rp.request.entryID = entryID;
959 handle->buffer->rp.request.commonHeader.updateActions = 0;
960 handle->buffer->rp.request.commonHeader.queryActions = 0U;
961 cmdBd.req.addr = (uintptr_t)handle->buffer;
962 cmdBd.req.reqLength = 8U;
963 cmdBd.req.resLength = 0U;
964 cmdBd.req.tableId = kNETC_RPTable;
965 cmdBd.req.cmd = kNETC_DeleteEntry;
966 cmdBd.req.accessType = kNETC_EntryIDMatch;
967 return NETC_CmdBDSendCommand(handle->base, handle->cmdr, &cmdBd, kNETC_NtmpV2_0);
968 }
969
NETC_QueryRPTableEntry(netc_cbdr_handle_t * handle,uint32_t entryID,netc_tb_rp_rsp_data_t * rsp)970 status_t NETC_QueryRPTableEntry(netc_cbdr_handle_t *handle, uint32_t entryID, netc_tb_rp_rsp_data_t *rsp)
971 {
972 netc_cmd_bd_t cmdBd = {0};
973 status_t status = kStatus_Success;
974 (void)memset(handle->buffer, 0, sizeof(netc_tb_rp_rsp_data_t));
975 handle->buffer->rp.request.entryID = entryID;
976 handle->buffer->rp.request.commonHeader.updateActions = 0;
977 handle->buffer->rp.request.commonHeader.queryActions = 0U;
978 cmdBd.req.addr = (uintptr_t)handle->buffer;
979 cmdBd.req.reqLength = 8U;
980 cmdBd.req.resLength = sizeof(netc_tb_rp_rsp_data_t);
981 cmdBd.req.tableId = kNETC_RPTable;
982 cmdBd.req.cmd = kNETC_QueryEntry;
983 cmdBd.req.accessType = kNETC_EntryIDMatch;
984 status = NETC_CmdBDSendCommand(handle->base, handle->cmdr, &cmdBd, kNETC_NtmpV2_0);
985 if (kStatus_Success == status)
986 {
987 if (cmdBd.resp.numMatched != 0U)
988 {
989 *rsp = handle->buffer->rp.response;
990 }
991 else
992 {
993 status = kStatus_NETC_NotFound;
994 }
995 }
996 return status;
997 }
998
NETC_GetRPStatistic(netc_cbdr_handle_t * handle,uint32_t entryID,netc_tb_rp_stse_t * statis)999 status_t NETC_GetRPStatistic(netc_cbdr_handle_t *handle, uint32_t entryID, netc_tb_rp_stse_t *statis)
1000 {
1001 netc_cmd_bd_t cmdBd = {0};
1002 status_t status = kStatus_Success;
1003 (void)memset(handle->buffer, 0, sizeof(netc_tb_rp_req_data_t));
1004 handle->buffer->rp.request.entryID = entryID;
1005 handle->buffer->rp.request.commonHeader.updateActions = 0;
1006 handle->buffer->rp.request.commonHeader.queryActions = 0U;
1007 cmdBd.req.addr = (uintptr_t)handle->buffer;
1008 cmdBd.req.reqLength = 8U;
1009 cmdBd.req.resLength = sizeof(netc_tb_rp_rsp_data_t);
1010 cmdBd.req.tableId = kNETC_RPTable;
1011 cmdBd.req.cmd = kNETC_QueryEntry;
1012 cmdBd.req.accessType = kNETC_EntryIDMatch;
1013 status = NETC_CmdBDSendCommand(handle->base, handle->cmdr, &cmdBd, kNETC_NtmpV2_0);
1014 if (kStatus_Success == status)
1015 {
1016 *statis = handle->buffer->rp.response.stse;
1017 }
1018 return status;
1019 }
1020
NETC_ConfigTGSAdminList(netc_cbdr_handle_t * handle,netc_tb_tgs_gcl_t * config)1021 status_t NETC_ConfigTGSAdminList(netc_cbdr_handle_t *handle, netc_tb_tgs_gcl_t *config)
1022 {
1023 status_t status = kStatus_Success;
1024 netc_cmd_bd_t cmdBd = {0};
1025
1026 if ((config->numEntries > NETC_TB_TGS_MAX_ENTRY) || ((config->numEntries != 0U) && (config->gcList == NULL)))
1027 {
1028 return kStatus_InvalidArgument;
1029 }
1030
1031 (void)memset(handle->buffer, 0, 28U);
1032 handle->buffer->tgs.request.entryID = config->entryID;
1033 handle->buffer->tgs.request.commonHeader.updateActions = 1U;
1034 handle->buffer->tgs.request.commonHeader.queryActions = 0U;
1035 /* Initialize port Time Gate Scheduling entry administrative gate control list */
1036 (void)memcpy((void *)&handle->buffer->tgs.request.cfge, (void *)&config->baseTime, 20);
1037 if (0U != config->numEntries)
1038 {
1039 (void)memcpy((void *)&handle->buffer->tgs.request.cfge.adminGcl[0], (void *)config->gcList,
1040 config->numEntries * 8U);
1041 }
1042 cmdBd.req.addr = (uintptr_t)handle->buffer;
1043 cmdBd.req.reqLength = 28U + config->numEntries * 8U;
1044 cmdBd.req.resLength = 12U;
1045 cmdBd.req.tableId = kNETC_TGSTable;
1046 cmdBd.req.cmd = kNETC_UpdateEntry;
1047 cmdBd.req.accessType = kNETC_EntryIDMatch;
1048 status = NETC_CmdBDSendCommand(handle->base, handle->cmdr, &cmdBd, kNETC_NtmpV2_0);
1049
1050 #if defined(FSL_FEATURE_NETC_HAS_ERRATA_051254) && FSL_FEATURE_NETC_HAS_ERRATA_051254
1051 if (cmdBd.resp.error == 0xd6U)
1052 {
1053 /* If a command response with an error code set to 0x0D6 is returned in response to an update command request
1054 * against an Time Gate Scheduling table entry, software must issue another update command request against the
1055 * same Time Gate Scheduling table entry, to remove the administrative gate control list from the Time Gate
1056 * Scheduling table entry. */
1057 (void)memset(handle->buffer, 0, 28U);
1058 handle->buffer->tgs.request.cfge.adminControlListLength = 0U;
1059 handle->buffer->tgs.request.entryID = config->entryID;
1060 handle->buffer->tgs.request.commonHeader.updateActions = 1U;
1061 handle->buffer->tgs.request.commonHeader.queryActions = 0U;
1062 cmdBd.req.addr = (uintptr_t)handle->buffer;
1063 cmdBd.req.reqLength = 28U;
1064 cmdBd.req.resLength = 12U;
1065 cmdBd.req.tableId = kNETC_TGSTable;
1066 cmdBd.req.cmd = kNETC_UpdateEntry;
1067 cmdBd.req.accessType = kNETC_EntryIDMatch;
1068 (void)NETC_CmdBDSendCommand(handle->base, handle->cmdr, &cmdBd, kNETC_NtmpV2_0);
1069 }
1070 #endif
1071 return status;
1072 }
1073
NETC_GetTGSOperationList(netc_cbdr_handle_t * handle,netc_tb_tgs_gcl_t * gcl,uint32_t length)1074 status_t NETC_GetTGSOperationList(netc_cbdr_handle_t *handle, netc_tb_tgs_gcl_t *gcl, uint32_t length)
1075 {
1076 status_t status = kStatus_Success;
1077 netc_cmd_bd_t cmdBd = {0};
1078 uint32_t adminLen;
1079 netc_tb_tgs_olse_t *resOlseBase;
1080 if (gcl->gcList == NULL)
1081 {
1082 return kStatus_InvalidArgument;
1083 }
1084 (void)memset(handle->buffer, 0, sizeof(netc_tb_tgs_data_t));
1085 handle->buffer->tgs.request.entryID = gcl->entryID;
1086 handle->buffer->tgs.request.commonHeader.updateActions = 0U;
1087 handle->buffer->tgs.request.commonHeader.queryActions = 0U;
1088 cmdBd.req.addr = (uintptr_t)handle->buffer;
1089 cmdBd.req.reqLength = 8U;
1090 /* Set Response Data Buffer length to MAX */
1091 cmdBd.req.resLength = sizeof(netc_tb_tgs_data_t);
1092 cmdBd.req.tableId = kNETC_TGSTable;
1093 cmdBd.req.cmd = kNETC_QueryEntry;
1094 cmdBd.req.accessType = kNETC_EntryIDMatch;
1095 status = NETC_CmdBDSendCommand(handle->base, handle->cmdr, &cmdBd, kNETC_NtmpV2_0);
1096 if (kStatus_Success == status)
1097 {
1098 /* Get the administrative gate control list length from Response Data Buffer */
1099 adminLen = handle->buffer->tgs.response.cfge.adminControlListLength;
1100 resOlseBase = (netc_tb_tgs_olse_t *)(uintptr_t)(&((uint8_t *)handle->buffer)[36U + 8U * adminLen]);
1101 if (resOlseBase->operControlListLength > length)
1102 {
1103 status = kStatus_InvalidArgument;
1104 }
1105 else
1106 {
1107 gcl->baseTime = resOlseBase->operBaseTime;
1108 gcl->cycleTime = resOlseBase->operCycleTime;
1109 gcl->extTime = resOlseBase->operCycleTimeExt;
1110 gcl->numEntries = resOlseBase->operControlListLength;
1111 /* Copy the Operational gate control list length */
1112 (void)memcpy(gcl->gcList, &resOlseBase->operGcl[0], (gcl->numEntries * 8U));
1113 }
1114 }
1115 return status;
1116 }
1117