1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright(c) 2018-2021 HiSilicon Limited. 3 */ 4 5 #ifndef HNS3_RSS_H 6 #define HNS3_RSS_H 7 8 #include <rte_ethdev.h> 9 #include <rte_flow.h> 10 11 #define HNS3_ETH_RSS_SUPPORT ( \ 12 RTE_ETH_RSS_IPV4 | \ 13 RTE_ETH_RSS_FRAG_IPV4 | \ 14 RTE_ETH_RSS_NONFRAG_IPV4_TCP | \ 15 RTE_ETH_RSS_NONFRAG_IPV4_UDP | \ 16 RTE_ETH_RSS_NONFRAG_IPV4_SCTP | \ 17 RTE_ETH_RSS_NONFRAG_IPV4_OTHER | \ 18 RTE_ETH_RSS_IPV6 | \ 19 RTE_ETH_RSS_FRAG_IPV6 | \ 20 RTE_ETH_RSS_NONFRAG_IPV6_TCP | \ 21 RTE_ETH_RSS_NONFRAG_IPV6_UDP | \ 22 RTE_ETH_RSS_NONFRAG_IPV6_SCTP | \ 23 RTE_ETH_RSS_NONFRAG_IPV6_OTHER | \ 24 RTE_ETH_RSS_L3_SRC_ONLY | \ 25 RTE_ETH_RSS_L3_DST_ONLY | \ 26 RTE_ETH_RSS_L4_SRC_ONLY | \ 27 RTE_ETH_RSS_L4_DST_ONLY) 28 29 #define HNS3_RSS_IND_TBL_SIZE 512 /* The size of hash lookup table */ 30 #define HNS3_RSS_IND_TBL_SIZE_MAX 2048 31 #define HNS3_RSS_KEY_SIZE 40 32 #define HNS3_RSS_KEY_SIZE_MAX 128 33 #define HNS3_RSS_SET_BITMAP_MSK 0xffff 34 35 #define HNS3_RSS_HASH_ALGO_TOEPLITZ 0 36 #define HNS3_RSS_HASH_ALGO_SIMPLE 1 37 #define HNS3_RSS_HASH_ALGO_SYMMETRIC_TOEP 2 38 #define HNS3_RSS_HASH_ALGO_MASK 0xf 39 40 #define HNS3_RSS_QUEUES_BUFFER_NUM 64 /* Same as the Max rx/tx queue num */ 41 struct hns3_rss_conf { 42 /* RSS parameters :algorithm, flow_types, key, queue */ 43 struct rte_flow_action_rss conf; 44 uint8_t hash_algo; /* hash function type defined by hardware */ 45 uint8_t key[HNS3_RSS_KEY_SIZE_MAX]; /* Hash key */ 46 uint16_t rss_indirection_tbl[HNS3_RSS_IND_TBL_SIZE_MAX]; 47 uint16_t queue[HNS3_RSS_QUEUES_BUFFER_NUM]; /* Queues indices to use */ 48 bool valid; /* check if RSS rule is valid */ 49 /* 50 * For IPv6 SCTP packets type, check whether the NIC hardware support 51 * RSS hash using the src/dst port as the input tuple. For Kunpeng920 52 * NIC hardware, it is not supported 53 */ 54 bool ipv6_sctp_offload_supported; 55 }; 56 57 #ifndef ilog2 58 static inline int rss_ilog2(uint32_t x) 59 { 60 int log = 0; 61 x >>= 1; 62 63 while (x) { 64 log++; 65 x >>= 1; 66 } 67 return log; 68 } 69 #define ilog2(x) rss_ilog2(x) 70 #endif 71 72 static inline uint32_t fls(uint32_t x) 73 { 74 uint32_t position; 75 uint32_t i; 76 77 if (x == 0) 78 return 0; 79 80 for (i = (x >> 1), position = 0; i != 0; ++position) 81 i >>= 1; 82 83 return position + 1; 84 } 85 86 static inline uint32_t roundup_pow_of_two(uint32_t x) 87 { 88 return 1UL << fls(x - 1); 89 } 90 91 extern const uint8_t hns3_hash_key[HNS3_RSS_KEY_SIZE]; 92 93 struct hns3_adapter; 94 struct hns3_hw; 95 96 int hns3_dev_rss_hash_update(struct rte_eth_dev *dev, 97 struct rte_eth_rss_conf *rss_conf); 98 int hns3_dev_rss_hash_conf_get(struct rte_eth_dev *dev, 99 struct rte_eth_rss_conf *rss_conf); 100 int hns3_dev_rss_reta_update(struct rte_eth_dev *dev, 101 struct rte_eth_rss_reta_entry64 *reta_conf, 102 uint16_t reta_size); 103 int hns3_dev_rss_reta_query(struct rte_eth_dev *dev, 104 struct rte_eth_rss_reta_entry64 *reta_conf, 105 uint16_t reta_size); 106 void hns3_rss_set_default_args(struct hns3_hw *hw); 107 int hns3_set_rss_indir_table(struct hns3_hw *hw, uint16_t *indir, 108 uint16_t size); 109 int hns3_rss_reset_indir_table(struct hns3_hw *hw); 110 int hns3_config_rss(struct hns3_adapter *hns); 111 void hns3_rss_uninit(struct hns3_adapter *hns); 112 int hns3_set_rss_tuple_by_rss_hf(struct hns3_hw *hw, uint64_t rss_hf); 113 int hns3_rss_set_algo_key(struct hns3_hw *hw, uint8_t hash_algo, 114 const uint8_t *key, uint8_t key_len); 115 116 117 #endif /* HNS3_RSS_H */ 118