dpdk/drivers/common/cnxk/roc_npc_priv.h
<<
>>
Prefs
   1/* SPDX-License-Identifier: BSD-3-Clause
   2 * Copyright(C) 2021 Marvell.
   3 */
   4
   5#ifndef _ROC_NPC_PRIV_H_
   6#define _ROC_NPC_PRIV_H_
   7
   8#define NPC_IH_LENGTH        8
   9#define NPC_TPID_LENGTH      2
  10#define NPC_HIGIG2_LENGTH    16
  11#define NPC_MAX_RAW_ITEM_LEN 16
  12#define NPC_COUNTER_NONE     (-1)
  13
  14#define NPC_RSS_GRPS 8
  15
  16#define NPC_ACTION_FLAG_DEFAULT 0xffff
  17
  18#define NPC_PFVF_FUNC_MASK 0x3FF
  19
  20/* 32 bytes from LDATA_CFG & 32 bytes from FLAGS_CFG */
  21#define NPC_MAX_EXTRACT_DATA_LEN (64)
  22#define NPC_MAX_EXTRACT_HW_LEN   (4 * NPC_MAX_EXTRACT_DATA_LEN)
  23#define NPC_LDATA_LFLAG_LEN      (16)
  24#define NPC_MAX_KEY_NIBBLES      (31)
  25
  26/* Nibble offsets */
  27#define NPC_LAYER_KEYX_SZ         (3)
  28#define NPC_PARSE_KEX_S_LA_OFFSET (7)
  29#define NPC_PARSE_KEX_S_LID_OFFSET(lid)                                        \
  30        ((((lid) - (NPC_LID_LA)) * NPC_LAYER_KEYX_SZ) +                        \
  31         NPC_PARSE_KEX_S_LA_OFFSET)
  32
  33/* This mark value indicates flag action */
  34#define NPC_FLOW_FLAG_VAL (0xffff)
  35
  36#define NPC_RX_ACT_MATCH_OFFSET (40)
  37#define NPC_RX_ACT_MATCH_MASK   (0xFFFF)
  38
  39#define NPC_RSS_ACT_GRP_OFFSET (20)
  40#define NPC_RSS_ACT_ALG_OFFSET (56)
  41#define NPC_RSS_ACT_GRP_MASK   (0xFFFFF)
  42#define NPC_RSS_ACT_ALG_MASK   (0x1F)
  43
  44#define NPC_MCAM_KEX_FIELD_MAX    23
  45#define NPC_MCAM_MAX_PROTO_FIELDS (NPC_MCAM_KEX_FIELD_MAX + 1)
  46#define NPC_MCAM_KEY_X4_WORDS     7 /* Number of 64-bit words */
  47
  48#define NPC_RVUPF_MAX_9XXX 0x10 /* HRM: RVU_PRIV_CONST */
  49#define NPC_RVUPF_MAX_98XX 0x18 /* HRM: RVU_PRIV_CONST */
  50#define NPC_RVUPF_MAX_10XX 0x20 /* HRM: RVU_PRIV_CONST */
  51#define NPC_NIXLF_MAX      0x80 /* HRM: NIX_AF_CONST2 */
  52#define NPC_MCAME_PER_PF   3    /* DRV: RSVD_MCAM_ENTRIES_PER_PF */
  53#define NPC_MCAME_PER_LF   1    /* DRV: RSVD_MCAM_ENTRIES_PER_NIXLF */
  54#define NPC_NIXLF_MAX_98XX (2 * NPC_NIXLF_MAX) /*2 NIXLFs */
  55#define NPC_MCAME_RESVD_9XXX                                                   \
  56        (NPC_NIXLF_MAX * NPC_MCAME_PER_LF +                                    \
  57         (NPC_RVUPF_MAX_9XXX - 1) * NPC_MCAME_PER_PF)
  58
  59#define NPC_MCAME_RESVD_10XX                                                   \
  60        (NPC_NIXLF_MAX * NPC_MCAME_PER_LF +                                    \
  61         (NPC_RVUPF_MAX_10XX - 1) * NPC_MCAME_PER_PF)
  62
  63#define NPC_MCAME_RESVD_98XX                                                   \
  64        (NPC_NIXLF_MAX_98XX * NPC_MCAME_PER_LF +                               \
  65         (NPC_RVUPF_MAX_98XX - 1) * NPC_MCAME_PER_PF)
  66
  67#define NPC_ACTION_MAX_VLAN_PARAMS    3
  68#define NPC_ACTION_MAX_VLANS_STRIPPED 2
  69
  70struct npc_action_vtag_info {
  71        uint16_t vlan_id;
  72        uint16_t vlan_ethtype;
  73        uint8_t vlan_pcp;
  74};
  75
  76enum npc_err_status {
  77        NPC_ERR_PARAM = -1024,
  78        NPC_ERR_NO_MEM,
  79        NPC_ERR_INVALID_SPEC,
  80        NPC_ERR_INVALID_MASK,
  81        NPC_ERR_INVALID_RANGE,
  82        NPC_ERR_INVALID_KEX,
  83        NPC_ERR_INVALID_SIZE,
  84        NPC_ERR_INTERNAL,
  85        NPC_ERR_MCAM_ALLOC,
  86        NPC_ERR_ACTION_NOTSUP,
  87        NPC_ERR_PATTERN_NOTSUP,
  88};
  89
  90enum npc_mcam_intf { NPC_MCAM_RX, NPC_MCAM_TX };
  91
  92typedef union npc_kex_cap_terms_t {
  93        struct {
  94                /** Total length of received packet */
  95                uint64_t len : 1;
  96                /** Initial (outer) Ethertype only */
  97                uint64_t ethtype_0 : 1;
  98                /** Ethertype of most inner VLAN tag */
  99                uint64_t ethtype_x : 1;
 100                /** First VLAN ID (outer) */
 101                uint64_t vlan_id_0 : 1;
 102                /** Last VLAN ID (inner) */
 103                uint64_t vlan_id_x : 1;
 104                /** destination MAC address */
 105                uint64_t dmac : 1;
 106                /** IP Protocol or IPv6 Next Header */
 107                uint64_t ip_proto : 1;
 108                /** Destination UDP port, implies IPPROTO=17 */
 109                uint64_t udp_dport : 1;
 110                /** Destination TCP port implies IPPROTO=6 */
 111                uint64_t tcp_dport : 1;
 112                /** Source UDP Port */
 113                uint64_t udp_sport : 1;
 114                /** Source TCP port */
 115                uint64_t tcp_sport : 1;
 116                /** Source IP address */
 117                uint64_t sip_addr : 1;
 118                /** Destination IP address */
 119                uint64_t dip_addr : 1;
 120                /** Source IP address */
 121                uint64_t sip6_addr : 1;
 122                /** Destination IP address */
 123                uint64_t dip6_addr : 1;
 124                /** IPsec session identifier */
 125                uint64_t ipsec_spi : 1;
 126                /** NVGRE/VXLAN network identifier */
 127                uint64_t ld_vni : 1;
 128                /** Custom frame match rule. PMR offset is counted from
 129                 *  the start of the packet.
 130                 */
 131                uint64_t custom_frame : 1;
 132                /** Custom layer 3 match rule. PMR offset is counted from
 133                 *  the start of layer 3 in the packet.
 134                 */
 135                uint64_t custom_l3 : 1;
 136                /** IGMP Group address */
 137                uint64_t igmp_grp_addr : 1;
 138                /** ICMP identifier */
 139                uint64_t icmp_id : 1;
 140                /** ICMP type */
 141                uint64_t icmp_type : 1;
 142                /** ICMP code */
 143                uint64_t icmp_code : 1;
 144                /** Source SCTP port */
 145                uint64_t sctp_sport : 1;
 146                /** Destination SCTP port */
 147                uint64_t sctp_dport : 1;
 148                /** GTPU Tunnel endpoint identifier */
 149                uint64_t gtpu_teid : 1;
 150
 151        } bit;
 152        /** All bits of the bit field structure */
 153        uint64_t all_bits;
 154} npc_kex_cap_terms_t;
 155
 156struct npc_parse_item_info {
 157        const void *def_mask; /* default mask */
 158        void *hw_mask;        /* hardware supported mask */
 159        int len;              /* length of item */
 160        const void *spec;     /* spec to use, NULL implies match any */
 161        const void *mask;     /* mask to use */
 162        uint8_t hw_hdr_len;   /* Extra data len at each layer*/
 163};
 164
 165struct npc_parse_state {
 166        struct npc *npc;
 167        const struct roc_npc_item_info *pattern;
 168        const struct roc_npc_item_info *last_pattern;
 169        struct roc_npc_flow *flow;
 170        uint8_t nix_intf;
 171        uint8_t tunnel;
 172        uint8_t terminate;
 173        uint8_t layer_mask;
 174        uint8_t lt[NPC_MAX_LID];
 175        uint8_t flags[NPC_MAX_LID];
 176        uint8_t *mcam_data; /* point to flow->mcam_data + key_len */
 177        uint8_t *mcam_mask; /* point to flow->mcam_mask + key_len */
 178        bool is_vf;
 179};
 180
 181enum npc_kpu_parser_flag {
 182        NPC_F_NA = 0,
 183        NPC_F_PKI,
 184        NPC_F_PKI_VLAN,
 185        NPC_F_PKI_ETAG,
 186        NPC_F_PKI_ITAG,
 187        NPC_F_PKI_MPLS,
 188        NPC_F_PKI_NSH,
 189        NPC_F_ETYPE_UNK,
 190        NPC_F_ETHER_VLAN,
 191        NPC_F_ETHER_ETAG,
 192        NPC_F_ETHER_ITAG,
 193        NPC_F_ETHER_MPLS,
 194        NPC_F_ETHER_NSH,
 195        NPC_F_STAG_CTAG,
 196        NPC_F_STAG_CTAG_UNK,
 197        NPC_F_STAG_STAG_CTAG,
 198        NPC_F_STAG_STAG_STAG,
 199        NPC_F_QINQ_CTAG,
 200        NPC_F_QINQ_CTAG_UNK,
 201        NPC_F_QINQ_QINQ_CTAG,
 202        NPC_F_QINQ_QINQ_QINQ,
 203        NPC_F_BTAG_ITAG,
 204        NPC_F_BTAG_ITAG_STAG,
 205        NPC_F_BTAG_ITAG_CTAG,
 206        NPC_F_BTAG_ITAG_UNK,
 207        NPC_F_ETAG_CTAG,
 208        NPC_F_ETAG_BTAG_ITAG,
 209        NPC_F_ETAG_STAG,
 210        NPC_F_ETAG_QINQ,
 211        NPC_F_ETAG_ITAG,
 212        NPC_F_ETAG_ITAG_STAG,
 213        NPC_F_ETAG_ITAG_CTAG,
 214        NPC_F_ETAG_ITAG_UNK,
 215        NPC_F_ITAG_STAG_CTAG,
 216        NPC_F_ITAG_STAG,
 217        NPC_F_ITAG_CTAG,
 218        NPC_F_MPLS_4_LABELS,
 219        NPC_F_MPLS_3_LABELS,
 220        NPC_F_MPLS_2_LABELS,
 221        NPC_F_IP_HAS_OPTIONS,
 222        NPC_F_IP_IP_IN_IP,
 223        NPC_F_IP_6TO4,
 224        NPC_F_IP_MPLS_IN_IP,
 225        NPC_F_IP_UNK_PROTO,
 226        NPC_F_IP_IP_IN_IP_HAS_OPTIONS,
 227        NPC_F_IP_6TO4_HAS_OPTIONS,
 228        NPC_F_IP_MPLS_IN_IP_HAS_OPTIONS,
 229        NPC_F_IP_UNK_PROTO_HAS_OPTIONS,
 230        NPC_F_IP6_HAS_EXT,
 231        NPC_F_IP6_TUN_IP6,
 232        NPC_F_IP6_MPLS_IN_IP,
 233        NPC_F_TCP_HAS_OPTIONS,
 234        NPC_F_TCP_HTTP,
 235        NPC_F_TCP_HTTPS,
 236        NPC_F_TCP_PPTP,
 237        NPC_F_TCP_UNK_PORT,
 238        NPC_F_TCP_HTTP_HAS_OPTIONS,
 239        NPC_F_TCP_HTTPS_HAS_OPTIONS,
 240        NPC_F_TCP_PPTP_HAS_OPTIONS,
 241        NPC_F_TCP_UNK_PORT_HAS_OPTIONS,
 242        NPC_F_UDP_VXLAN,
 243        NPC_F_UDP_VXLAN_NOVNI,
 244        NPC_F_UDP_VXLAN_NOVNI_NSH,
 245        NPC_F_UDP_VXLANGPE,
 246        NPC_F_UDP_VXLANGPE_NSH,
 247        NPC_F_UDP_VXLANGPE_MPLS,
 248        NPC_F_UDP_VXLANGPE_NOVNI,
 249        NPC_F_UDP_VXLANGPE_NOVNI_NSH,
 250        NPC_F_UDP_VXLANGPE_NOVNI_MPLS,
 251        NPC_F_UDP_VXLANGPE_UNK,
 252        NPC_F_UDP_VXLANGPE_NONP,
 253        NPC_F_UDP_GTP_GTPC,
 254        NPC_F_UDP_GTP_GTPU_G_PDU,
 255        NPC_F_UDP_GTP_GTPU_UNK,
 256        NPC_F_UDP_UNK_PORT,
 257        NPC_F_UDP_GENEVE,
 258        NPC_F_UDP_GENEVE_OAM,
 259        NPC_F_UDP_GENEVE_CRI_OPT,
 260        NPC_F_UDP_GENEVE_OAM_CRI_OPT,
 261        NPC_F_GRE_NVGRE,
 262        NPC_F_GRE_HAS_SRE,
 263        NPC_F_GRE_HAS_CSUM,
 264        NPC_F_GRE_HAS_KEY,
 265        NPC_F_GRE_HAS_SEQ,
 266        NPC_F_GRE_HAS_CSUM_KEY,
 267        NPC_F_GRE_HAS_CSUM_SEQ,
 268        NPC_F_GRE_HAS_KEY_SEQ,
 269        NPC_F_GRE_HAS_CSUM_KEY_SEQ,
 270        NPC_F_GRE_HAS_ROUTE,
 271        NPC_F_GRE_UNK_PROTO,
 272        NPC_F_GRE_VER1,
 273        NPC_F_GRE_VER1_HAS_SEQ,
 274        NPC_F_GRE_VER1_HAS_ACK,
 275        NPC_F_GRE_VER1_HAS_SEQ_ACK,
 276        NPC_F_GRE_VER1_UNK_PROTO,
 277        NPC_F_TU_ETHER_UNK,
 278        NPC_F_TU_ETHER_CTAG,
 279        NPC_F_TU_ETHER_CTAG_UNK,
 280        NPC_F_TU_ETHER_STAG_CTAG,
 281        NPC_F_TU_ETHER_STAG_CTAG_UNK,
 282        NPC_F_TU_ETHER_STAG,
 283        NPC_F_TU_ETHER_STAG_UNK,
 284        NPC_F_TU_ETHER_QINQ_CTAG,
 285        NPC_F_TU_ETHER_QINQ_CTAG_UNK,
 286        NPC_F_TU_ETHER_QINQ,
 287        NPC_F_TU_ETHER_QINQ_UNK,
 288        NPC_F_LAST /* has to be the last item */
 289};
 290
 291#define NPC_ACTION_TERM                                                        \
 292        (ROC_NPC_ACTION_TYPE_DROP | ROC_NPC_ACTION_TYPE_QUEUE |                \
 293         ROC_NPC_ACTION_TYPE_RSS | ROC_NPC_ACTION_TYPE_DUP |                   \
 294         ROC_NPC_ACTION_TYPE_SEC)
 295
 296struct npc_xtract_info {
 297        /* Length in bytes of pkt data extracted. len = 0
 298         * indicates that extraction is disabled.
 299         */
 300        uint8_t len;
 301        uint8_t hdr_off;      /* Byte offset of proto hdr: extract_src */
 302        uint8_t key_off;      /* Byte offset in MCAM key where data is placed */
 303        uint8_t enable;       /* Extraction enabled or disabled */
 304        uint8_t flags_enable; /* Flags extraction enabled */
 305};
 306
 307/* Information for a given {LAYER, LTYPE} */
 308struct npc_lid_lt_xtract_info {
 309        /* Info derived from parser configuration */
 310        uint16_t npc_proto;         /* Network protocol identified */
 311        uint8_t valid_flags_mask;   /* Flags applicable */
 312        uint8_t is_terminating : 1; /* No more parsing */
 313        struct npc_xtract_info xtract[NPC_MAX_LD];
 314};
 315
 316union npc_kex_ldata_flags_cfg {
 317        struct {
 318                uint64_t lid : 3;
 319                uint64_t rvsd_62_1 : 61;
 320        } s;
 321
 322        uint64_t i;
 323};
 324
 325typedef struct npc_lid_lt_xtract_info npc_dxcfg_t[NPC_MAX_INTF][NPC_MAX_LID]
 326                                                 [NPC_MAX_LT];
 327typedef struct npc_lid_lt_xtract_info npc_fxcfg_t[NPC_MAX_INTF][NPC_MAX_LD]
 328                                                 [NPC_MAX_LFL];
 329typedef union npc_kex_ldata_flags_cfg npc_ld_flags_t[NPC_MAX_LD];
 330
 331/* MBOX_MSG_NPC_GET_DATAX_CFG Response */
 332struct npc_get_datax_cfg {
 333        /* NPC_AF_KEX_LDATA(0..1)_FLAGS_CFG */
 334        union npc_kex_ldata_flags_cfg ld_flags[NPC_MAX_LD];
 335        /* Extract information indexed with [LID][LTYPE] */
 336        struct npc_lid_lt_xtract_info lid_lt_xtract[NPC_MAX_LID][NPC_MAX_LT];
 337        /* Flags based extract indexed with [LDATA][FLAGS_LOWER_NIBBLE]
 338         * Fields flags_ena_ld0, flags_ena_ld1 in
 339         * struct npc_lid_lt_xtract_info indicate if this is applicable
 340         * for a given {LAYER, LTYPE}
 341         */
 342        struct npc_xtract_info flag_xtract[NPC_MAX_LD][NPC_MAX_LT];
 343};
 344
 345TAILQ_HEAD(npc_flow_list, roc_npc_flow);
 346
 347struct npc_prio_flow_entry {
 348        struct roc_npc_flow *flow;
 349        TAILQ_ENTRY(npc_prio_flow_entry) next;
 350};
 351
 352TAILQ_HEAD(npc_prio_flow_list_head, npc_prio_flow_entry);
 353
 354struct npc {
 355        struct mbox *mbox;                      /* Mbox */
 356        uint32_t keyx_supp_nmask[NPC_MAX_INTF]; /* nibble mask */
 357        uint8_t profile_name[MKEX_NAME_LEN];    /* KEX profile name */
 358        uint32_t keyx_len[NPC_MAX_INTF];        /* per intf key len in bits */
 359        uint32_t datax_len[NPC_MAX_INTF];       /* per intf data len in bits */
 360        uint32_t keyw[NPC_MAX_INTF];            /* max key + data len bits */
 361        uint32_t mcam_entries;                  /* mcam entries supported */
 362        uint16_t channel;                       /* RX Channel number */
 363        uint32_t rss_grps;                      /* rss groups supported */
 364        uint16_t flow_prealloc_size;            /* Pre allocated mcam size */
 365        uint16_t flow_max_priority;             /* Max priority for flow */
 366        uint16_t switch_header_type; /* Suppprted switch header type */
 367        uint32_t mark_actions;       /* Number of mark actions */
 368        uint32_t vtag_strip_actions; /* vtag insert/strip actions */
 369        uint16_t pf_func;            /* pf_func of device */
 370        npc_dxcfg_t prx_dxcfg;       /* intf, lid, lt, extract */
 371        npc_fxcfg_t prx_fxcfg;       /* Flag extract */
 372        npc_ld_flags_t prx_lfcfg;    /* KEX LD_Flags CFG */
 373        struct npc_flow_list *flow_list;
 374        struct npc_prio_flow_list_head *prio_flow_list;
 375        struct plt_bitmap *rss_grp_entries;
 376};
 377
 378static inline struct npc *
 379roc_npc_to_npc_priv(struct roc_npc *npc)
 380{
 381        return (struct npc *)npc->reserved;
 382}
 383
 384int npc_mcam_free_counter(struct npc *npc, uint16_t ctr_id);
 385int npc_mcam_read_counter(struct npc *npc, uint32_t ctr_id, uint64_t *count);
 386int npc_mcam_clear_counter(struct npc *npc, uint32_t ctr_id);
 387int npc_mcam_free_entry(struct npc *npc, uint32_t entry);
 388int npc_mcam_free_all_entries(struct npc *npc);
 389int npc_mcam_alloc_and_write(struct npc *npc, struct roc_npc_flow *flow,
 390                             struct npc_parse_state *pst);
 391int npc_mcam_alloc_entry(struct npc *npc, struct roc_npc_flow *mcam,
 392                         struct roc_npc_flow *ref_mcam, int prio,
 393                         int *resp_count);
 394int npc_mcam_alloc_entries(struct npc *npc, int ref_mcam, int *alloc_entry,
 395                           int req_count, int prio, int *resp_count);
 396
 397int npc_mcam_ena_dis_entry(struct npc *npc, struct roc_npc_flow *mcam,
 398                           bool enable);
 399int npc_mcam_write_entry(struct npc *npc, struct roc_npc_flow *mcam);
 400int npc_update_parse_state(struct npc_parse_state *pst,
 401                           struct npc_parse_item_info *info, int lid, int lt,
 402                           uint8_t flags);
 403void npc_get_hw_supp_mask(struct npc_parse_state *pst,
 404                          struct npc_parse_item_info *info, int lid, int lt);
 405int npc_parse_item_basic(const struct roc_npc_item_info *item,
 406                         struct npc_parse_item_info *info);
 407int npc_parse_meta_items(struct npc_parse_state *pst);
 408int npc_parse_higig2_hdr(struct npc_parse_state *pst);
 409int npc_parse_cpt_hdr(struct npc_parse_state *pst);
 410int npc_parse_la(struct npc_parse_state *pst);
 411int npc_parse_lb(struct npc_parse_state *pst);
 412int npc_parse_lc(struct npc_parse_state *pst);
 413int npc_parse_ld(struct npc_parse_state *pst);
 414int npc_parse_le(struct npc_parse_state *pst);
 415int npc_parse_lf(struct npc_parse_state *pst);
 416int npc_parse_lg(struct npc_parse_state *pst);
 417int npc_parse_lh(struct npc_parse_state *pst);
 418int npc_mcam_fetch_kex_cfg(struct npc *npc);
 419int npc_get_free_mcam_entry(struct mbox *mbox, struct roc_npc_flow *flow,
 420                            struct npc *npc);
 421void npc_delete_prio_list_entry(struct npc *npc, struct roc_npc_flow *flow);
 422int npc_flow_free_all_resources(struct npc *npc);
 423const struct roc_npc_item_info *
 424npc_parse_skip_void_and_any_items(const struct roc_npc_item_info *pattern);
 425int npc_program_mcam(struct npc *npc, struct npc_parse_state *pst,
 426                     bool mcam_alloc);
 427uint64_t npc_get_kex_capability(struct npc *npc);
 428int npc_rss_free_grp_get(struct npc *npc, uint32_t *grp);
 429int npc_rss_action_configure(struct roc_npc *roc_npc,
 430                             const struct roc_npc_action_rss *rss,
 431                             uint8_t *alg_idx, uint32_t *rss_grp,
 432                             uint32_t mcam_id);
 433int npc_rss_action_program(struct roc_npc *roc_npc,
 434                           const struct roc_npc_action actions[],
 435                           struct roc_npc_flow *flow);
 436int npc_rss_group_free(struct npc *npc, struct roc_npc_flow *flow);
 437#endif /* _ROC_NPC_PRIV_H_ */
 438