1 /* SPDX-License-Identifier: GPL-2.0+ */
2 // Copyright (c) 2021-2021 Hisilicon Limited.
3 
4 #ifndef __HCLGE_COMM_RSS_H
5 #define __HCLGE_COMM_RSS_H
6 #include <linux/types.h>
7 
8 #include "hnae3.h"
9 #include "hclge_comm_cmd.h"
10 
11 #define HCLGE_COMM_RSS_HASH_ALGO_TOEPLITZ	0
12 #define HCLGE_COMM_RSS_HASH_ALGO_SIMPLE		1
13 #define HCLGE_COMM_RSS_HASH_ALGO_SYMMETRIC	2
14 
15 #define HCLGE_COMM_RSS_INPUT_TUPLE_OTHER	GENMASK(3, 0)
16 #define HCLGE_COMM_RSS_INPUT_TUPLE_SCTP		GENMASK(4, 0)
17 
18 #define HCLGE_COMM_D_PORT_BIT		BIT(0)
19 #define HCLGE_COMM_S_PORT_BIT		BIT(1)
20 #define HCLGE_COMM_D_IP_BIT		BIT(2)
21 #define HCLGE_COMM_S_IP_BIT		BIT(3)
22 #define HCLGE_COMM_V_TAG_BIT		BIT(4)
23 #define HCLGE_COMM_RSS_INPUT_TUPLE_SCTP_NO_PORT	\
24 	(HCLGE_COMM_D_IP_BIT | HCLGE_COMM_S_IP_BIT | HCLGE_COMM_V_TAG_BIT)
25 #define HCLGE_COMM_MAX_TC_NUM		8
26 
27 #define HCLGE_COMM_RSS_TC_OFFSET_S		0
28 #define HCLGE_COMM_RSS_TC_OFFSET_M		GENMASK(10, 0)
29 #define HCLGE_COMM_RSS_TC_SIZE_MSB_B	11
30 #define HCLGE_COMM_RSS_TC_SIZE_S		12
31 #define HCLGE_COMM_RSS_TC_SIZE_M		GENMASK(14, 12)
32 #define HCLGE_COMM_RSS_TC_VALID_B		15
33 #define HCLGE_COMM_RSS_TC_SIZE_MSB_OFFSET	3
34 
35 struct hclge_comm_rss_tuple_cfg {
36 	u8 ipv4_tcp_en;
37 	u8 ipv4_udp_en;
38 	u8 ipv4_sctp_en;
39 	u8 ipv4_fragment_en;
40 	u8 ipv6_tcp_en;
41 	u8 ipv6_udp_en;
42 	u8 ipv6_sctp_en;
43 	u8 ipv6_fragment_en;
44 };
45 
46 #define HCLGE_COMM_RSS_KEY_SIZE		40
47 #define HCLGE_COMM_RSS_CFG_TBL_SIZE	16
48 #define HCLGE_COMM_RSS_CFG_TBL_BW_H	2U
49 #define HCLGE_COMM_RSS_CFG_TBL_BW_L	8U
50 #define HCLGE_COMM_RSS_CFG_TBL_SIZE_H	4
51 #define HCLGE_COMM_RSS_SET_BITMAP_MSK	GENMASK(15, 0)
52 #define HCLGE_COMM_RSS_HASH_ALGO_MASK	GENMASK(3, 0)
53 #define HCLGE_COMM_RSS_HASH_KEY_OFFSET_B	4
54 
55 #define HCLGE_COMM_RSS_HASH_KEY_NUM	16
56 struct hclge_comm_rss_config_cmd {
57 	u8 hash_config;
58 	u8 rsv[7];
59 	u8 hash_key[HCLGE_COMM_RSS_HASH_KEY_NUM];
60 };
61 
62 struct hclge_comm_rss_cfg {
63 	u8 rss_hash_key[HCLGE_COMM_RSS_KEY_SIZE]; /* user configured hash keys */
64 
65 	/* shadow table */
66 	u16 *rss_indirection_tbl;
67 	u32 rss_algo;
68 
69 	struct hclge_comm_rss_tuple_cfg rss_tuple_sets;
70 	u32 rss_size;
71 };
72 
73 struct hclge_comm_rss_input_tuple_cmd {
74 	u8 ipv4_tcp_en;
75 	u8 ipv4_udp_en;
76 	u8 ipv4_sctp_en;
77 	u8 ipv4_fragment_en;
78 	u8 ipv6_tcp_en;
79 	u8 ipv6_udp_en;
80 	u8 ipv6_sctp_en;
81 	u8 ipv6_fragment_en;
82 	u8 rsv[16];
83 };
84 
85 struct hclge_comm_rss_ind_tbl_cmd {
86 	__le16 start_table_index;
87 	__le16 rss_set_bitmap;
88 	u8 rss_qid_h[HCLGE_COMM_RSS_CFG_TBL_SIZE_H];
89 	u8 rss_qid_l[HCLGE_COMM_RSS_CFG_TBL_SIZE];
90 };
91 
92 struct hclge_comm_rss_tc_mode_cmd {
93 	__le16 rss_tc_mode[HCLGE_COMM_MAX_TC_NUM];
94 	u8 rsv[8];
95 };
96 
97 u32 hclge_comm_get_rss_key_size(struct hnae3_handle *handle);
98 void hclge_comm_get_rss_type(struct hnae3_handle *nic,
99 			     struct hclge_comm_rss_tuple_cfg *rss_tuple_sets);
100 void hclge_comm_rss_indir_init_cfg(struct hnae3_ae_dev *ae_dev,
101 				   struct hclge_comm_rss_cfg *rss_cfg);
102 int hclge_comm_get_rss_tuple(struct hclge_comm_rss_cfg *rss_cfg, int flow_type,
103 			     u8 *tuple_sets);
104 int hclge_comm_parse_rss_hfunc(struct hclge_comm_rss_cfg *rss_cfg,
105 			       const u8 hfunc, u8 *hash_algo);
106 void hclge_comm_get_rss_hash_info(struct hclge_comm_rss_cfg *rss_cfg, u8 *key,
107 				  u8 *hfunc);
108 void hclge_comm_get_rss_indir_tbl(struct hclge_comm_rss_cfg *rss_cfg,
109 				  u32 *indir, u16 rss_ind_tbl_size);
110 int hclge_comm_set_rss_algo_key(struct hclge_comm_hw *hw, const u8 hfunc,
111 				const u8 *key);
112 int hclge_comm_init_rss_tuple_cmd(struct hclge_comm_rss_cfg *rss_cfg,
113 				  struct ethtool_rxnfc *nfc,
114 				  struct hnae3_ae_dev *ae_dev,
115 				  struct hclge_comm_rss_input_tuple_cmd *req);
116 u64 hclge_comm_convert_rss_tuple(u8 tuple_sets);
117 int hclge_comm_set_rss_input_tuple(struct hnae3_handle *nic,
118 				   struct hclge_comm_hw *hw, bool is_pf,
119 				   struct hclge_comm_rss_cfg *rss_cfg);
120 int hclge_comm_set_rss_indir_table(struct hnae3_ae_dev *ae_dev,
121 				   struct hclge_comm_hw *hw, const u16 *indir);
122 int hclge_comm_rss_init_cfg(struct hnae3_handle *nic,
123 			    struct hnae3_ae_dev *ae_dev,
124 			    struct hclge_comm_rss_cfg *rss_cfg);
125 void hclge_comm_get_rss_tc_info(u16 rss_size, u8 hw_tc_map, u16 *tc_offset,
126 				u16 *tc_valid, u16 *tc_size);
127 int hclge_comm_set_rss_tc_mode(struct hclge_comm_hw *hw, u16 *tc_offset,
128 			       u16 *tc_valid, u16 *tc_size);
129 int hclge_comm_set_rss_hash_key(struct hclge_comm_rss_cfg *rss_cfg,
130 				struct hclge_comm_hw *hw, const u8 *key,
131 				const u8 hfunc);
132 int hclge_comm_set_rss_tuple(struct hnae3_ae_dev *ae_dev,
133 			     struct hclge_comm_hw *hw,
134 			     struct hclge_comm_rss_cfg *rss_cfg,
135 			     struct ethtool_rxnfc *nfc);
136 #endif
137