1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591
|
/* SPDX-License-Identifier: BSD-3-Clause
* Copyright(c) 2001-2023 Intel Corporation
*/
#include "ice_common.h"
#include "ice_parser_util.h"
#define ICE_SEC_DATA_OFFSET 4
#define ICE_SID_RXPARSER_IMEM_ENTRY_SIZE 48
#define ICE_SID_RXPARSER_METADATA_INIT_ENTRY_SIZE 24
#define ICE_SID_RXPARSER_CAM_ENTRY_SIZE 16
#define ICE_SID_RXPARSER_PG_SPILL_ENTRY_SIZE 17
#define ICE_SID_RXPARSER_NOMATCH_CAM_ENTRY_SIZE 12
#define ICE_SID_RXPARSER_NOMATCH_SPILL_ENTRY_SIZE 13
#define ICE_SID_RXPARSER_BOOST_TCAM_ENTRY_SIZE 88
#define ICE_SID_RXPARSER_MARKER_TYPE_ENTRY_SIZE 24
#define ICE_SID_RXPARSER_MARKER_GRP_ENTRY_SIZE 8
#define ICE_SID_RXPARSER_PROTO_GRP_ENTRY_SIZE 24
#define ICE_SID_RXPARSER_FLAG_REDIR_ENTRY_SIZE 1
#define ICE_SEC_LBL_DATA_OFFSET 2
#define ICE_SID_LBL_ENTRY_SIZE 66
void ice_lbl_dump(struct ice_hw *hw, struct ice_lbl_item *item)
{
ice_info(hw, "index = %d\n", item->idx);
ice_info(hw, "label = %s\n", item->label);
}
void ice_parse_item_dflt(struct ice_hw *hw, u16 idx, void *item,
void *data, int size)
{
ice_memcpy(item, data, size, ICE_DMA_TO_NONDMA);
}
/**
* ice_parser_sect_item_get - parse a item from a section
* @sect_type: section type
* @section: section object
* @index: index of the item to get
* @offset: dummy as prototype of ice_pkg_enum_entry's last parameter
*/
void *ice_parser_sect_item_get(u32 sect_type, void *section,
u32 index, u32 *offset)
{
struct ice_pkg_sect_hdr *hdr;
int data_off = ICE_SEC_DATA_OFFSET;
int size;
if (!section)
return NULL;
switch (sect_type) {
case ICE_SID_RXPARSER_IMEM:
size = ICE_SID_RXPARSER_IMEM_ENTRY_SIZE;
break;
case ICE_SID_RXPARSER_METADATA_INIT:
size = ICE_SID_RXPARSER_METADATA_INIT_ENTRY_SIZE;
break;
case ICE_SID_RXPARSER_CAM:
size = ICE_SID_RXPARSER_CAM_ENTRY_SIZE;
break;
case ICE_SID_RXPARSER_PG_SPILL:
size = ICE_SID_RXPARSER_PG_SPILL_ENTRY_SIZE;
break;
case ICE_SID_RXPARSER_NOMATCH_CAM:
size = ICE_SID_RXPARSER_NOMATCH_CAM_ENTRY_SIZE;
break;
case ICE_SID_RXPARSER_NOMATCH_SPILL:
size = ICE_SID_RXPARSER_NOMATCH_SPILL_ENTRY_SIZE;
break;
case ICE_SID_RXPARSER_BOOST_TCAM:
size = ICE_SID_RXPARSER_BOOST_TCAM_ENTRY_SIZE;
break;
case ICE_SID_LBL_RXPARSER_TMEM:
data_off = ICE_SEC_LBL_DATA_OFFSET;
size = ICE_SID_LBL_ENTRY_SIZE;
break;
case ICE_SID_RXPARSER_MARKER_PTYPE:
size = ICE_SID_RXPARSER_MARKER_TYPE_ENTRY_SIZE;
break;
case ICE_SID_RXPARSER_MARKER_GRP:
size = ICE_SID_RXPARSER_MARKER_GRP_ENTRY_SIZE;
break;
case ICE_SID_RXPARSER_PROTO_GRP:
size = ICE_SID_RXPARSER_PROTO_GRP_ENTRY_SIZE;
break;
case ICE_SID_RXPARSER_FLAG_REDIR:
size = ICE_SID_RXPARSER_FLAG_REDIR_ENTRY_SIZE;
break;
default:
return NULL;
}
hdr = (struct ice_pkg_sect_hdr *)section;
if (index >= LE16_TO_CPU(hdr->count))
return NULL;
return (void *)((uintptr_t)section + data_off + index * size);
}
/**
* ice_parser_create_table - create a item table from a section
* @hw: pointer to the hardware structure
* @sect_type: section type
* @item_size: item size in byte
* @length: number of items in the table to create
* @item_get: the function will be parsed to ice_pkg_enum_entry
* @parse_item: the function to parse the item
* @no_offset: ignore header offset, calculate index from 0
*/
void *ice_parser_create_table(struct ice_hw *hw, u32 sect_type,
u32 item_size, u32 length,
void *(*item_get)(u32 sect_type, void *section,
u32 index, u32 *offset),
void (*parse_item)(struct ice_hw *hw, u16 idx,
void *item, void *data,
int size),
bool no_offset)
{
struct ice_seg *seg = hw->seg;
struct ice_pkg_enum state;
u16 idx = 0xffff;
void *table;
void *data;
if (!seg)
return NULL;
table = ice_malloc(hw, item_size * length);
if (!table) {
ice_debug(hw, ICE_DBG_PARSER, "failed to allocate memory for table type %d.\n",
sect_type);
return NULL;
}
ice_memset(&state, 0, sizeof(state), ICE_NONDMA_MEM);
do {
data = ice_pkg_enum_entry(seg, &state, sect_type, NULL,
item_get);
seg = NULL;
if (data) {
struct ice_pkg_sect_hdr *hdr =
(struct ice_pkg_sect_hdr *)state.sect;
if (no_offset)
idx++;
else
idx = LE16_TO_CPU(hdr->offset) +
state.entry_idx;
parse_item(hw, idx,
(void *)((uintptr_t)table + idx * item_size),
data, item_size);
}
} while (data);
return table;
}
/**
* ice_parser_create - create a parser instance
* @hw: pointer to the hardware structure
* @psr: output parameter for a new parser instance be created
*/
int ice_parser_create(struct ice_hw *hw, struct ice_parser **psr)
{
struct ice_parser *p;
int status;
p = (struct ice_parser *)ice_malloc(hw, sizeof(struct ice_parser));
if (!p)
return ICE_ERR_NO_MEMORY;
p->hw = hw;
p->rt.psr = p;
p->imem_table = ice_imem_table_get(hw);
if (!p->imem_table) {
status = ICE_ERR_PARAM;
goto err;
}
p->mi_table = ice_metainit_table_get(hw);
if (!p->mi_table) {
status = ICE_ERR_PARAM;
goto err;
}
p->pg_cam_table = ice_pg_cam_table_get(hw);
if (!p->pg_cam_table) {
status = ICE_ERR_PARAM;
goto err;
}
p->pg_sp_cam_table = ice_pg_sp_cam_table_get(hw);
if (!p->pg_sp_cam_table) {
status = ICE_ERR_PARAM;
goto err;
}
p->pg_nm_cam_table = ice_pg_nm_cam_table_get(hw);
if (!p->pg_nm_cam_table) {
status = ICE_ERR_PARAM;
goto err;
}
p->pg_nm_sp_cam_table = ice_pg_nm_sp_cam_table_get(hw);
if (!p->pg_nm_sp_cam_table) {
status = ICE_ERR_PARAM;
goto err;
}
p->bst_tcam_table = ice_bst_tcam_table_get(hw);
if (!p->bst_tcam_table) {
status = ICE_ERR_PARAM;
goto err;
}
p->bst_lbl_table = ice_bst_lbl_table_get(hw);
if (!p->bst_lbl_table) {
status = ICE_ERR_PARAM;
goto err;
}
p->ptype_mk_tcam_table = ice_ptype_mk_tcam_table_get(hw);
if (!p->ptype_mk_tcam_table) {
status = ICE_ERR_PARAM;
goto err;
}
p->mk_grp_table = ice_mk_grp_table_get(hw);
if (!p->mk_grp_table) {
status = ICE_ERR_PARAM;
goto err;
}
p->proto_grp_table = ice_proto_grp_table_get(hw);
if (!p->proto_grp_table) {
status = ICE_ERR_PARAM;
goto err;
}
p->flg_rd_table = ice_flg_rd_table_get(hw);
if (!p->flg_rd_table) {
status = ICE_ERR_PARAM;
goto err;
}
p->xlt_kb_sw = ice_xlt_kb_get_sw(hw);
if (!p->xlt_kb_sw) {
status = ICE_ERR_PARAM;
goto err;
}
p->xlt_kb_acl = ice_xlt_kb_get_acl(hw);
if (!p->xlt_kb_acl) {
status = ICE_ERR_PARAM;
goto err;
}
p->xlt_kb_fd = ice_xlt_kb_get_fd(hw);
if (!p->xlt_kb_fd) {
status = ICE_ERR_PARAM;
goto err;
}
p->xlt_kb_rss = ice_xlt_kb_get_rss(hw);
if (!p->xlt_kb_rss) {
status = ICE_ERR_PARAM;
goto err;
}
*psr = p;
return 0;
err:
ice_parser_destroy(p);
return status;
}
/**
* ice_parser_destroy - destroy a parser instance
* @psr: pointer to a parser instance
*/
void ice_parser_destroy(struct ice_parser *psr)
{
ice_free(psr->hw, psr->imem_table);
ice_free(psr->hw, psr->mi_table);
ice_free(psr->hw, psr->pg_cam_table);
ice_free(psr->hw, psr->pg_sp_cam_table);
ice_free(psr->hw, psr->pg_nm_cam_table);
ice_free(psr->hw, psr->pg_nm_sp_cam_table);
ice_free(psr->hw, psr->bst_tcam_table);
ice_free(psr->hw, psr->bst_lbl_table);
ice_free(psr->hw, psr->ptype_mk_tcam_table);
ice_free(psr->hw, psr->mk_grp_table);
ice_free(psr->hw, psr->proto_grp_table);
ice_free(psr->hw, psr->flg_rd_table);
ice_free(psr->hw, psr->xlt_kb_sw);
ice_free(psr->hw, psr->xlt_kb_acl);
ice_free(psr->hw, psr->xlt_kb_fd);
ice_free(psr->hw, psr->xlt_kb_rss);
ice_free(psr->hw, psr);
}
/**
* ice_parser_run - parse on a packet in binary and return the result
* @psr: pointer to a parser instance
* @pkt_buf: packet data
* @pkt_len: packet length
* @rslt: input/output parameter to save parser result.
*/
int ice_parser_run(struct ice_parser *psr, const u8 *pkt_buf,
int pkt_len, struct ice_parser_result *rslt)
{
ice_parser_rt_reset(&psr->rt);
ice_parser_rt_pktbuf_set(&psr->rt, pkt_buf, pkt_len);
return ice_parser_rt_execute(&psr->rt, rslt);
}
/**
* ice_parser_result_dump - dump a parser result info
* @hw: pointer to the hardware structure
* @rslt: parser result info to dump
*/
void ice_parser_result_dump(struct ice_hw *hw, struct ice_parser_result *rslt)
{
int i;
ice_info(hw, "ptype = %d\n", rslt->ptype);
for (i = 0; i < rslt->po_num; i++)
ice_info(hw, "proto = %d, offset = %d\n",
rslt->po[i].proto_id, rslt->po[i].offset);
ice_info(hw, "flags_psr = 0x%016" PRIx64 "\n", rslt->flags_psr);
ice_info(hw, "flags_pkt = 0x%016" PRIx64 "\n", rslt->flags_pkt);
ice_info(hw, "flags_sw = 0x%04x\n", rslt->flags_sw);
ice_info(hw, "flags_fd = 0x%04x\n", rslt->flags_fd);
ice_info(hw, "flags_rss = 0x%04x\n", rslt->flags_rss);
}
static void _bst_vm_set(struct ice_parser *psr, const char *prefix, bool on)
{
u16 i = 0;
while (true) {
struct ice_bst_tcam_item *item;
item = ice_bst_tcam_search(psr->bst_tcam_table,
psr->bst_lbl_table,
prefix, &i);
if (!item)
break;
item->key[0] = (u8)(on ? 0xff : 0xfe);
item->key_inv[0] = (u8)(on ? 0xff : 0xfe);
i++;
}
}
/**
* ice_parser_dvm_set - configure double vlan mode for parser
* @psr: pointer to a parser instance
* @on: true to turn on; false to turn off
*/
void ice_parser_dvm_set(struct ice_parser *psr, bool on)
{
_bst_vm_set(psr, "BOOST_MAC_VLAN_DVM", on);
_bst_vm_set(psr, "BOOST_MAC_VLAN_SVM", !on);
}
static int
_tunnel_port_set(struct ice_parser *psr, const char *prefix, u16 udp_port,
bool on)
{
u8 *buf = (u8 *)&udp_port;
u16 i = 0;
while (true) {
struct ice_bst_tcam_item *item;
item = ice_bst_tcam_search(psr->bst_tcam_table,
psr->bst_lbl_table,
prefix, &i);
if (!item)
break;
/* found empty slot to add */
if (on && item->key[16] == 0xfe && item->key_inv[16] == 0xfe) {
item->key_inv[15] = buf[0];
item->key_inv[16] = buf[1];
item->key[15] = (u8)(0xff - buf[0]);
item->key[16] = (u8)(0xff - buf[1]);
return 0;
/* found a matched slot to delete */
} else if (!on && (item->key_inv[15] == buf[0] ||
item->key_inv[16] == buf[1])) {
item->key_inv[15] = 0xff;
item->key_inv[16] = 0xfe;
item->key[15] = 0xff;
item->key[16] = 0xfe;
return 0;
}
i++;
}
return ICE_ERR_PARAM;
}
/**
* ice_parser_vxlan_tunnel_set - configure vxlan tunnel for parser
* @psr: pointer to a parser instance
* @udp_port: vxlan tunnel port in UDP header
* @on: true to turn on; false to turn off
*/
int ice_parser_vxlan_tunnel_set(struct ice_parser *psr,
u16 udp_port, bool on)
{
return _tunnel_port_set(psr, "TNL_VXLAN", udp_port, on);
}
/**
* ice_parser_geneve_tunnel_set - configure geneve tunnel for parser
* @psr: pointer to a parser instance
* @udp_port: geneve tunnel port in UDP header
* @on: true to turn on; false to turn off
*/
int ice_parser_geneve_tunnel_set(struct ice_parser *psr,
u16 udp_port, bool on)
{
return _tunnel_port_set(psr, "TNL_GENEVE", udp_port, on);
}
/**
* ice_parser_ecpri_tunnel_set - configure ecpri tunnel for parser
* @psr: pointer to a parser instance
* @udp_port: ecpri tunnel port in UDP header
* @on: true to turn on; false to turn off
*/
int ice_parser_ecpri_tunnel_set(struct ice_parser *psr,
u16 udp_port, bool on)
{
return _tunnel_port_set(psr, "TNL_UDP_ECPRI", udp_port, on);
}
static bool _nearest_proto_id(struct ice_parser_result *rslt, u16 offset,
u8 *proto_id, u16 *proto_off)
{
u16 dist = 0xffff;
u8 p = 0;
int i;
for (i = 0; i < rslt->po_num; i++) {
if (offset < rslt->po[i].offset)
continue;
if (offset - rslt->po[i].offset < dist) {
p = rslt->po[i].proto_id;
dist = offset - rslt->po[i].offset;
}
}
if (dist % 2)
return false;
*proto_id = p;
*proto_off = dist;
return true;
}
/** default flag mask to cover GTP_EH_PDU, GTP_EH_PDU_LINK and TUN2
* In future, the flag masks should learn from DDP
*/
#define ICE_KEYBUILD_FLAG_MASK_DEFAULT_SW 0x4002
#define ICE_KEYBUILD_FLAG_MASK_DEFAULT_ACL 0x0000
#define ICE_KEYBUILD_FLAG_MASK_DEFAULT_FD 0x6080
#define ICE_KEYBUILD_FLAG_MASK_DEFAULT_RSS 0x6010
/**
* ice_parser_profile_init - initialize a FXP profile base on parser result
* @rslt: a instance of a parser result
* @pkt_buf: packet data buffer
* @msk_buf: packet mask buffer
* @buf_len: packet length
* @blk: FXP pipeline stage
* @prefix_match: match protocol stack exactly or only prefix
* @prof: input/output parameter to save the profile
*/
int ice_parser_profile_init(struct ice_parser_result *rslt,
const u8 *pkt_buf, const u8 *msk_buf,
int buf_len, enum ice_block blk,
bool prefix_match,
struct ice_parser_profile *prof)
{
u8 proto_id = 0xff;
u16 proto_off = 0;
u16 off;
ice_memset(prof, 0, sizeof(*prof), ICE_NONDMA_MEM);
ice_set_bit(rslt->ptype, prof->ptypes);
if (blk == ICE_BLK_SW) {
prof->flags = rslt->flags_sw;
prof->flags_msk = ICE_KEYBUILD_FLAG_MASK_DEFAULT_SW;
} else if (blk == ICE_BLK_ACL) {
prof->flags = rslt->flags_acl;
prof->flags_msk = ICE_KEYBUILD_FLAG_MASK_DEFAULT_ACL;
} else if (blk == ICE_BLK_FD) {
prof->flags = rslt->flags_fd;
prof->flags_msk = ICE_KEYBUILD_FLAG_MASK_DEFAULT_FD;
} else if (blk == ICE_BLK_RSS) {
prof->flags = rslt->flags_rss;
prof->flags_msk = ICE_KEYBUILD_FLAG_MASK_DEFAULT_RSS;
} else {
return ICE_ERR_PARAM;
}
for (off = 0; off < buf_len - 1; off++) {
if (msk_buf[off] == 0 && msk_buf[off + 1] == 0)
continue;
if (!_nearest_proto_id(rslt, off, &proto_id, &proto_off))
continue;
if (prof->fv_num >= 32)
return ICE_ERR_PARAM;
prof->fv[prof->fv_num].proto_id = proto_id;
prof->fv[prof->fv_num].offset = proto_off;
prof->fv[prof->fv_num].spec = *(const u16 *)&pkt_buf[off];
prof->fv[prof->fv_num].msk = *(const u16 *)&msk_buf[off];
prof->fv_num++;
}
return 0;
}
/**
* ice_parser_profile_dump - dump an FXP profile info
* @hw: pointer to the hardware structure
* @prof: profile info to dump
*/
void ice_parser_profile_dump(struct ice_hw *hw, struct ice_parser_profile *prof)
{
u16 i;
ice_info(hw, "ptypes:\n");
for (i = 0; i < ICE_FLOW_PTYPE_MAX; i++)
if (ice_is_bit_set(prof->ptypes, i))
ice_info(hw, "\t%d\n", i);
for (i = 0; i < prof->fv_num; i++)
ice_info(hw, "proto = %d, offset = %d spec = 0x%04x, mask = 0x%04x\n",
prof->fv[i].proto_id, prof->fv[i].offset,
prof->fv[i].spec, prof->fv[i].msk);
ice_info(hw, "flags = 0x%04x\n", prof->flags);
ice_info(hw, "flags_msk = 0x%04x\n", prof->flags_msk);
}
/**
* ice_check_ddp_support_proto_id - check DDP package file support protocol ID
* @hw: pointer to the HW struct
* @proto_id: protocol ID value
*
* This function maintains the compatibility of the program process by checking
* whether the current DDP file supports the required protocol ID.
*/
bool ice_check_ddp_support_proto_id(struct ice_hw *hw,
enum ice_prot_id proto_id)
{
struct ice_proto_grp_item *proto_grp_table;
struct ice_proto_grp_item *proto_grp;
bool exist = false;
u16 idx, i;
proto_grp_table = ice_proto_grp_table_get(hw);
if (!proto_grp_table)
return false;
for (idx = 0; idx < ICE_PROTO_GRP_TABLE_SIZE; idx++) {
proto_grp = &proto_grp_table[idx];
for (i = 0; i < ICE_PROTO_COUNT_PER_GRP; i++) {
if (proto_grp->po[i].proto_id == proto_id) {
exist = true;
goto exit;
}
}
}
exit:
ice_free(hw, proto_grp_table);
return exist;
}
|