dpdk/drivers/net/bnxt/hcapi/cfa/hcapi_cfa_defs.h
<<
>>
Prefs
   1/* SPDX-License-Identifier: BSD-3-Clause
   2 * Copyright(c) 2019-2021 Broadcom
   3 * All rights reserved.
   4 */
   5
   6/*!
   7 *   \file
   8 *   \brief Exported functions for CFA HW programming
   9 */
  10#ifndef _HCAPI_CFA_DEFS_H_
  11#define _HCAPI_CFA_DEFS_H_
  12
  13#include <stdio.h>
  14#include <string.h>
  15#include <stdbool.h>
  16#include <stddef.h>
  17#include <stdint.h>
  18
  19#if !defined(__GNUC__)
  20#pragma anon_unions
  21#endif
  22
  23#define CFA_BITS_PER_BYTE (8)
  24#define CFA_BITS_PER_WORD (sizeof(uint32_t) * CFA_BITS_PER_BYTE)
  25#define __CFA_ALIGN_MASK(x, mask) (((x) + (mask)) & ~(mask))
  26#define CFA_ALIGN(x, a) __CFA_ALIGN_MASK((x), (a) - 1)
  27#define CFA_ALIGN_256(x) CFA_ALIGN(x, 256)
  28#define CFA_ALIGN_128(x) CFA_ALIGN(x, 128)
  29#define CFA_ALIGN_32(x) CFA_ALIGN(x, 32)
  30
  31#define NUM_WORDS_ALIGN_32BIT(x) (CFA_ALIGN_32(x) / CFA_BITS_PER_WORD)
  32#define NUM_WORDS_ALIGN_128BIT(x) (CFA_ALIGN_128(x) / CFA_BITS_PER_WORD)
  33#define NUM_WORDS_ALIGN_256BIT(x) (CFA_ALIGN_256(x) / CFA_BITS_PER_WORD)
  34
  35/* TODO: redefine according to chip variant */
  36#define CFA_GLOBAL_CFG_DATA_SZ (100)
  37
  38#ifndef SUPPORT_CFA_HW_P4
  39#define SUPPORT_CFA_HW_P4 (0)
  40#endif
  41
  42#ifndef SUPPORT_CFA_HW_P45
  43#define SUPPORT_CFA_HW_P45 (0)
  44#endif
  45
  46#ifndef SUPPORT_CFA_HW_P58
  47#define SUPPORT_CFA_HW_P58 (0)
  48#endif
  49
  50#if SUPPORT_CFA_HW_ALL
  51#include "hcapi_cfa_p4.h"
  52#include "hcapi_cfa_p58.h"
  53#endif /* SUPPORT_CFA_HW_ALL */
  54
  55/*
  56 * Hashing defines
  57 */
  58#define HCAPI_CFA_LKUP_SEED_MEM_SIZE 512
  59
  60/* CRC32i support for Key0 hash */
  61#define ucrc32(ch, crc) (crc32tbl[((crc) ^ (ch)) & 0xff] ^ ((crc) >> 8))
  62#define crc32(x, y) crc32i(~0, x, y)
  63
  64/**
  65 * CFA HW version definition
  66 */
  67enum hcapi_cfa_ver {
  68        HCAPI_CFA_P40 = 0, /**< CFA phase 4.0 */
  69        HCAPI_CFA_P45 = 1, /**< CFA phase 4.5 */
  70        HCAPI_CFA_P58 = 2, /**< CFA phase 5.8 */
  71        HCAPI_CFA_PMAX = 3
  72};
  73
  74/**
  75 * CFA direction definition
  76 */
  77enum hcapi_cfa_dir {
  78        HCAPI_CFA_DIR_RX = 0, /**< Receive */
  79        HCAPI_CFA_DIR_TX = 1, /**< Transmit */
  80        HCAPI_CFA_DIR_MAX = 2
  81};
  82
  83/**
  84 * CFA HW OPCODE definition
  85 */
  86enum hcapi_cfa_hwops {
  87        HCAPI_CFA_HWOPS_PUT,   /**< Write to HW operation */
  88        HCAPI_CFA_HWOPS_GET,   /**< Read from HW operation */
  89        HCAPI_CFA_HWOPS_ADD,   /*<
  90                                * For operations which require more then
  91                                * simple writes to HW, this operation is
  92                                * used.  The distinction with this operation
  93                                * when compared to the PUT ops is that this
  94                                * operation is used in conjunction with
  95                                * the HCAPI_CFA_HWOPS_DEL op to remove
  96                                * the operations issued by the ADD OP.
  97                                */
  98        HCAPI_CFA_HWOPS_DEL,   /*<
  99                                *  Beside to delete from the hardware, this
 100                                *   operation is also undo the add operation
 101                                *   performed by the HCAPI_CFA_HWOPS_ADD op.
 102                                */
 103        HCAPI_CFA_HWOPS_EVICT, /*< This operation is used to evict entries from
 104                                *   CFA cache memories. This operation is only
 105                                *   applicable to tables that use CFA caches.
 106                                */
 107        HCAPI_CFA_HWOPS_MAX
 108};
 109
 110/**
 111 * CFA HW KEY CONTROL OPCODE definition
 112 */
 113enum hcapi_cfa_key_ctrlops {
 114        HCAPI_CFA_KEY_CTRLOPS_INSERT, /**< insert control bits */
 115        HCAPI_CFA_KEY_CTRLOPS_STRIP,  /**< strip control bits */
 116        HCAPI_CFA_KEY_CTRLOPS_MAX
 117};
 118
 119/**
 120 * CFA HW definition
 121 */
 122struct hcapi_cfa_hw {
 123        /** [in] HW table base address for the operation with optional device
 124         *  handle. For on-chip HW table operation, this is the either the TX
 125         *  or RX CFA HW base address. For off-chip table, this field is the
 126         *  base memory address of the off-chip table.
 127         */
 128        uint64_t base_addr;
 129        /** [in] Optional opaque device handle. It is generally used to access
 130         *  an GRC register space through PCIE BAR and passed to the BAR memory
 131         *  accessor routine.
 132         */
 133        void *handle;
 134};
 135
 136/**
 137 * CFA HW operation definition
 138 *
 139 */
 140struct hcapi_cfa_hwop {
 141        /** [in] HW opcode */
 142        enum hcapi_cfa_hwops opcode;
 143        /** [in] CFA HW information used by accessor routines.
 144         */
 145        struct hcapi_cfa_hw hw;
 146};
 147
 148/**
 149 * CFA HW data structure definition
 150 */
 151struct hcapi_cfa_data {
 152        /** [in] physical offset to the HW table for the data to be
 153         *  written to.  If this is an array of registers, this is the
 154         *  index into the array of registers.  For writing keys, this
 155         *  is the byte pointer into the memory where the key should be
 156         *  written.
 157         */
 158        union {
 159                uint32_t index;
 160                uint32_t byte_offset;
 161        };
 162        /** [in] HW data buffer pointer */
 163        uint8_t *data;
 164        /** [in] HW data mask buffer pointer.
 165         *  When the CFA data is a FKB and  data_mask pointer
 166         *  is NULL, then the default mask to enable all bit will
 167         *  be used.
 168         */
 169        uint8_t *data_mask;
 170        /** [in/out] size of the HW data buffer in bytes
 171         */
 172        uint16_t data_sz;
 173};
 174
 175/*********************** Truflow start ***************************/
 176enum hcapi_cfa_pg_tbl_lvl {
 177        TF_PT_LVL_0,
 178        TF_PT_LVL_1,
 179        TF_PT_LVL_2,
 180        TF_PT_LVL_MAX
 181};
 182
 183enum hcapi_cfa_em_table_type {
 184        TF_KEY0_TABLE,
 185        TF_KEY1_TABLE,
 186        TF_RECORD_TABLE,
 187        TF_EFC_TABLE,
 188        TF_ACTION_TABLE,
 189        TF_EM_LKUP_TABLE,
 190        TF_MAX_TABLE
 191};
 192
 193struct hcapi_cfa_em_page_tbl {
 194        uint32_t pg_count;
 195        uint32_t pg_size;
 196        void **pg_va_tbl;
 197        uint64_t *pg_pa_tbl;
 198};
 199
 200struct hcapi_cfa_em_table {
 201        int type;
 202        uint32_t num_entries;
 203        uint16_t ctx_id;
 204        uint32_t entry_size;
 205        int num_lvl;
 206        uint32_t page_cnt[TF_PT_LVL_MAX];
 207        uint64_t num_data_pages;
 208        void *l0_addr;
 209        uint64_t l0_dma_addr;
 210        struct hcapi_cfa_em_page_tbl pg_tbl[TF_PT_LVL_MAX];
 211};
 212
 213struct hcapi_cfa_em_ctx_mem_info {
 214        struct hcapi_cfa_em_table em_tables[TF_MAX_TABLE];
 215};
 216
 217/*********************** Truflow end ****************************/
 218/**
 219 * CFA HW key table definition
 220 *
 221 * Applicable to EEM and off-chip EM table only.
 222 */
 223struct hcapi_cfa_key_tbl {
 224        /** [in] For EEM, this is the KEY0 base mem pointer. For off-chip EM,
 225         *  this is the base mem pointer of the key table.
 226         */
 227        uint8_t *base0;
 228        /** [in] total size of the key table in bytes. For EEM, this size is
 229         *  same for both KEY0 and KEY1 table.
 230         */
 231        uint32_t size;
 232        /** [in] number of key buckets, applicable for newer chips */
 233        uint32_t num_buckets;
 234        /** [in] For EEM, this is KEY1 base mem pointer. For off-chip EM,
 235         *  this is the key record memory base pointer within the key table,
 236         *  applicable for newer chip
 237         */
 238        uint8_t *base1;
 239        /** [in] Optional - If the table is managed by a Backing Store
 240         *  database, then this object can be use to configure the EM Key.
 241         */
 242        struct hcapi_cfa_bs_db *bs_db;
 243        /** [in] Page size for EEM tables */
 244        uint32_t page_size;
 245};
 246
 247/**
 248 * CFA HW key buffer definition
 249 */
 250struct hcapi_cfa_key_obj {
 251        /** [in] pointer to the key data buffer */
 252        uint32_t *data;
 253        /** [in] buffer len in bytes */
 254        uint32_t len;
 255        /** [in] Pointer to the key layout */
 256        struct hcapi_cfa_key_layout *layout;
 257};
 258
 259/**
 260 * CFA HW key data definition
 261 */
 262struct hcapi_cfa_key_data {
 263        /** [in] For on-chip key table, it is the offset in unit of smallest
 264         *  key. For off-chip key table, it is the byte offset relative
 265         *  to the key record memory base and adjusted for page and entry size.
 266         */
 267        uint32_t offset;
 268        /** [in] HW key data buffer pointer */
 269        uint8_t *data;
 270        /** [in] size of the key in bytes */
 271        uint16_t size;
 272        /** [in] optional table scope ID */
 273        uint8_t tbl_scope;
 274        /** [in] the fid owner of the key */
 275        uint64_t metadata;
 276        /** [in] stored with the bucket which can be used by
 277         *       the caller to retrieve later via the GET HW OP.
 278         */
 279};
 280
 281/**
 282 * CFA HW key location definition
 283 */
 284struct hcapi_cfa_key_loc {
 285        /** [out] on-chip EM bucket offset or off-chip EM bucket mem pointer */
 286        uint64_t bucket_mem_ptr;
 287        /** [out] off-chip EM key offset mem pointer */
 288        uint64_t mem_ptr;
 289        /** [out] index within the array of the EM buckets */
 290        uint32_t bucket_mem_idx;
 291        /** [out] index within the EM bucket */
 292        uint8_t bucket_idx;
 293        /** [out] index within the EM records */
 294        uint32_t mem_idx;
 295};
 296
 297/**
 298 *  Action record info
 299 */
 300struct hcapi_cfa_action_addr {
 301        /** [in] action SRAM block ID for on-chip action records or table
 302         *  scope of the action backing store
 303         */
 304        uint16_t blk_id;
 305        /** [in] ar_id or cache line aligned address offset for the action
 306         *  record
 307         */
 308        uint32_t offset;
 309};
 310
 311/**
 312 * Action data definition
 313 */
 314struct hcapi_cfa_action_data {
 315        /** [in] action record addr info for on-chip action records */
 316        struct hcapi_cfa_action_addr addr;
 317        /** [in/out] pointer to the action data buffer */
 318        uint32_t *data;
 319        /** [in] action data buffer len in bytes */
 320        uint32_t len;
 321};
 322
 323/**
 324 * Action object definition
 325 */
 326struct hcapi_cfa_action_obj {
 327        /** [in] pointer to the action data buffer */
 328        uint32_t *data;
 329        /** [in] buffer len in bytes */
 330        uint32_t len;
 331        /** [in] pointer to the action layout */
 332        struct hcapi_cfa_action_layout *layout;
 333};
 334
 335/**
 336 * This function is used to hash E/EM keys
 337 *
 338 *
 339 * @param[in] key_data
 340 *  A pointer of the key
 341 *
 342 * @param[in] bitlen
 343 *  Number of bits in the key
 344 *
 345 * @return
 346 *   CRC32 and Lookup3 hashes of the input key
 347 */
 348uint64_t hcapi_cfa_key_hash(uint64_t *key_data,
 349                            uint16_t bitlen);
 350
 351/**
 352 * This function is used to execute an operation
 353 *
 354 *
 355 * @param[in] op
 356 *  Operation
 357 *
 358 * @param[in] key_tbl
 359 *  Table
 360 *
 361 * @param[in] key_obj
 362 *  Key data
 363 *
 364 * @param[in] key_key_loc
 365 *
 366 * @return
 367 *   0 for SUCCESS, negative value for FAILURE
 368 */
 369int hcapi_cfa_key_hw_op(struct hcapi_cfa_hwop *op,
 370                        struct hcapi_cfa_key_tbl *key_tbl,
 371                        struct hcapi_cfa_key_data *key_obj,
 372                        struct hcapi_cfa_key_loc *key_loc);
 373
 374uint64_t hcapi_get_table_page(struct hcapi_cfa_em_table *mem,
 375                              uint32_t page);
 376uint32_t hcapi_cfa_crc32i(uint32_t crc, const uint8_t *buf, size_t len);
 377uint64_t hcapi_cfa_p4_key_hash(uint64_t *key_data,
 378                               uint16_t bitlen);
 379uint64_t hcapi_cfa_p58_key_hash(uint64_t *key_data,
 380                                uint16_t bitlen);
 381#endif /* HCAPI_CFA_DEFS_H_ */
 382