1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright(c) 2014-2023 Broadcom 3 * All rights reserved. 4 */ 5 6 #ifndef _BNXT_VNIC_H_ 7 #define _BNXT_VNIC_H_ 8 9 #include <sys/queue.h> 10 #include <stdbool.h> 11 #include <rte_hash.h> 12 13 #define INVALID_VNIC_ID ((uint16_t)-1) 14 #define BNXT_RSS_LEVEL_INNERMOST 0x2 15 #define BNXT_RSS_LEVEL_OUTERMOST 0x1 16 #define BNXT_VNIC_MAX_QUEUE_SIZE 256 17 #define BNXT_VNIC_MAX_QUEUE_SZ_IN_8BITS (BNXT_VNIC_MAX_QUEUE_SIZE / 8) 18 #define BNXT_VNIC_MAX_QUEUE_SZ_IN_64BITS (BNXT_VNIC_MAX_QUEUE_SIZE / 64) 19 /* Limit the number of vnic creations*/ 20 #define BNXT_VNIC_MAX_SUPPORTED_ID 64 21 22 #define BNXT_HASH_MODE_DEFAULT HWRM_VNIC_RSS_CFG_INPUT_HASH_MODE_FLAGS_DEFAULT 23 #define BNXT_HASH_MODE_INNERMOST \ 24 (HWRM_VNIC_RSS_CFG_INPUT_HASH_MODE_FLAGS_INNERMOST_4 | \ 25 HWRM_VNIC_RSS_CFG_INPUT_HASH_MODE_FLAGS_INNERMOST_2) 26 #define BNXT_HASH_MODE_OUTERMOST \ 27 (HWRM_VNIC_RSS_CFG_INPUT_HASH_MODE_FLAGS_OUTERMOST_4 | \ 28 HWRM_VNIC_RSS_CFG_INPUT_HASH_MODE_FLAGS_OUTERMOST_2) 29 #define BNXT_VNIC_OUTER_RSS_UNSUPPORTED(bp) \ 30 ((BNXT_PF(bp) && !((bp)->vnic_cap_flags & BNXT_VNIC_CAP_OUTER_RSS)) || \ 31 (BNXT_VF(bp) && BNXT_VF_IS_TRUSTED(bp) && \ 32 !((bp)->vnic_cap_flags & BNXT_VNIC_CAP_OUTER_RSS_TRUSTED_VF)) || \ 33 (BNXT_VF(bp) && !BNXT_VF_IS_TRUSTED(bp))) 34 #define BNXT_IS_HASH_FUNC_DEFAULT(f) ((f) != RTE_ETH_HASH_FUNCTION_DEFAULT) 35 #define BNXT_IS_HASH_FUNC_TOEPLITZ(f) ((f) != RTE_ETH_HASH_FUNCTION_TOEPLITZ) 36 #define BNXT_IS_HASH_FUNC_SIMPLE_XOR(b, f) \ 37 ((b)->vnic_cap_flags & BNXT_VNIC_CAP_XOR_MODE && \ 38 ((f) != RTE_ETH_HASH_FUNCTION_SIMPLE_XOR)) 39 40 struct bnxt_vnic_info { 41 STAILQ_ENTRY(bnxt_vnic_info) next; 42 uint8_t ff_pool_idx; 43 44 uint16_t fw_vnic_id; /* returned by Chimp during alloc */ 45 uint16_t rss_rule; 46 uint16_t start_grp_id; 47 uint16_t end_grp_id; 48 uint16_t *fw_grp_ids; 49 uint16_t num_lb_ctxts; 50 uint16_t dflt_ring_grp; 51 uint16_t mru; 52 uint16_t hash_type; 53 uint8_t hash_mode; 54 uint8_t prev_hash_mode; 55 rte_iova_t rss_table_dma_addr; 56 uint16_t *rss_table; 57 rte_iova_t rss_hash_key_dma_addr; 58 void *rss_hash_key; 59 uint32_t flags; 60 #define BNXT_VNIC_INFO_PROMISC (1 << 0) 61 #define BNXT_VNIC_INFO_ALLMULTI (1 << 1) 62 #define BNXT_VNIC_INFO_BCAST (1 << 2) 63 #define BNXT_VNIC_INFO_UCAST (1 << 3) 64 #define BNXT_VNIC_INFO_MCAST (1 << 4) 65 #define BNXT_VNIC_INFO_TAGGED (1 << 5) 66 #define BNXT_VNIC_INFO_UNTAGGED (1 << 6) 67 68 uint16_t cos_rule; 69 uint16_t lb_rule; 70 uint16_t rx_queue_cnt; 71 uint16_t cos_queue_id; 72 bool vlan_strip; 73 bool func_default; 74 bool bd_stall; 75 bool rss_dflt_cr; 76 uint16_t ref_cnt; 77 uint64_t queue_bitmap[BNXT_VNIC_MAX_QUEUE_SZ_IN_64BITS]; 78 uint64_t rss_types; 79 uint32_t key_len; /**< Hash key length in bytes. */ 80 81 STAILQ_HEAD(, bnxt_filter_info) filter; 82 STAILQ_HEAD(, rte_flow) flow_list; 83 uint8_t ring_select_mode; 84 enum rte_eth_hash_function hash_f; 85 enum rte_eth_hash_function hash_f_local; 86 uint64_t rss_types_local; 87 uint16_t hds_threshold; 88 uint8_t metadata_format; 89 uint8_t state; 90 }; 91 92 struct bnxt_vnic_queue_db { 93 uint16_t num_queues; 94 uint16_t dflt_vnic_id; 95 struct rte_hash *rss_q_db; 96 }; 97 98 /* RSS structure to pass values as an structure argument*/ 99 struct bnxt_vnic_rss_info { 100 uint32_t rss_func; 101 uint32_t rss_level; 102 uint64_t rss_types; 103 uint32_t key_len; /**< Hash key length in bytes. */ 104 const uint8_t *key; /**< Hash key. */ 105 uint32_t queue_num; /**< Number of entries in @p queue. */ 106 uint64_t queue_list[BNXT_VNIC_MAX_QUEUE_SZ_IN_64BITS]; 107 }; 108 109 struct bnxt; 110 int bnxt_free_vnic(struct bnxt *bp, struct bnxt_vnic_info *vnic, 111 int pool); 112 struct bnxt_vnic_info *bnxt_alloc_vnic(struct bnxt *bp); 113 void bnxt_free_all_vnics(struct bnxt *bp); 114 void bnxt_free_vnic_attributes(struct bnxt *bp); 115 int bnxt_alloc_vnic_attributes(struct bnxt *bp, bool reconfig); 116 void bnxt_free_vnic_mem(struct bnxt *bp); 117 int bnxt_alloc_vnic_mem(struct bnxt *bp); 118 int bnxt_vnic_grp_alloc(struct bnxt *bp, struct bnxt_vnic_info *vnic); 119 void bnxt_prandom_bytes(void *dest_ptr, size_t len); 120 uint32_t bnxt_rte_to_hwrm_hash_types(uint64_t rte_type); 121 int bnxt_rte_to_hwrm_hash_level(struct bnxt *bp, uint64_t hash_f, uint32_t lvl); 122 uint64_t bnxt_hwrm_to_rte_rss_level(struct bnxt *bp, uint32_t mode); 123 124 int32_t bnxt_vnic_queue_db_init(struct bnxt *bp); 125 int32_t bnxt_vnic_queue_db_deinit(struct bnxt *bp); 126 127 void bnxt_vnic_queue_db_update_dlft_vnic(struct bnxt *bp); 128 void bnxt_vnic_rss_query_info_fill(struct bnxt *bp, 129 struct rte_flow_action_rss *rss_conf, 130 uint16_t vnic_id); 131 int32_t 132 bnxt_vnic_rss_queue_status_update(struct bnxt *bp, struct bnxt_vnic_info *vnic); 133 134 int32_t bnxt_vnic_queue_action_alloc(struct bnxt *bp, uint16_t q_index, 135 uint16_t *vnic_idx, 136 uint16_t *vnicid); 137 int32_t bnxt_vnic_queue_action_free(struct bnxt *bp, uint16_t q_index); 138 139 int32_t bnxt_vnic_rss_action_alloc(struct bnxt *bp, 140 struct bnxt_vnic_rss_info *rss_info, 141 uint16_t *queue_id, 142 uint16_t *vnicid); 143 int32_t bnxt_vnic_rss_action_free(struct bnxt *bp, uint16_t q_index); 144 145 int32_t bnxt_vnic_reta_config_update(struct bnxt *bp, 146 struct bnxt_vnic_info *vnic_info, 147 struct rte_eth_rss_reta_entry64 *reta_conf, 148 uint16_t reta_size); 149 int32_t bnxt_vnic_queue_id_is_valid(struct bnxt_vnic_info *vnic_info, 150 uint16_t queue_id); 151 void bnxt_vnic_ring_grp_populate(struct bnxt *bp, struct bnxt_vnic_info *vnic); 152 void bnxt_vnic_rules_init(struct bnxt_vnic_info *vnic); 153 int32_t bnxt_vnic_mru_config(struct bnxt *bp, uint16_t new_mtu); 154 struct bnxt_vnic_info *bnxt_vnic_queue_db_get_vnic(struct bnxt *bp, 155 uint16_t vnic_idx); 156 struct bnxt_vnic_info * 157 bnxt_vnic_queue_id_get_next(struct bnxt *bp, uint16_t queue_id, 158 uint16_t *vnic_idx); 159 void bnxt_vnic_tpa_cfg(struct bnxt *bp, uint16_t queue_id, bool flag); 160 uint8_t _bnxt_rte_to_hwrm_ring_select_mode(enum rte_eth_hash_function hash_f); 161 int bnxt_rte_flow_to_hwrm_ring_select_mode(enum rte_eth_hash_function hash_f, 162 uint64_t types, struct bnxt *bp, 163 struct bnxt_vnic_info *vnic); 164 int bnxt_rte_eth_to_hwrm_ring_select_mode(struct bnxt *bp, uint64_t types, 165 struct bnxt_vnic_info *vnic); 166 void bnxt_hwrm_rss_to_rte_hash_conf(struct bnxt_vnic_info *vnic, 167 uint64_t *rss_conf); 168 #endif 169