xref: /linux/drivers/net/ethernet/meta/fbnic/fbnic_rpc.h (revision a1ff5a7d78a036d6c2178ee5acd6ba4946243800)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Copyright (c) Meta Platforms, Inc. and affiliates. */
3 
4 #ifndef _FBNIC_RPC_H_
5 #define _FBNIC_RPC_H_
6 
7 #include <uapi/linux/in6.h>
8 #include <linux/bitfield.h>
9 
10 /*  The TCAM state definitions follow an expected ordering.
11  *  They start out disabled, then move through the following states:
12  *  Disabled  0	-> Add	      2
13  *  Add	      2	-> Valid      1
14  *
15  *  Valid     1	-> Add/Update 2
16  *  Add	      2	-> Valid      1
17  *
18  *  Valid     1	-> Delete     3
19  *  Delete    3	-> Disabled   0
20  */
21 enum {
22 	FBNIC_TCAM_S_DISABLED	= 0,
23 	FBNIC_TCAM_S_VALID	= 1,
24 	FBNIC_TCAM_S_ADD	= 2,
25 	FBNIC_TCAM_S_UPDATE	= FBNIC_TCAM_S_ADD,
26 	FBNIC_TCAM_S_DELETE	= 3,
27 };
28 
29 /* 32 MAC Destination Address TCAM Entries
30  * 4 registers DA[1:0], DA[3:2], DA[5:4], Validate
31  */
32 #define FBNIC_RPC_TCAM_MACDA_WORD_LEN		3
33 #define FBNIC_RPC_TCAM_MACDA_NUM_ENTRIES	32
34 
35 #define FBNIC_RPC_TCAM_ACT_WORD_LEN		11
36 #define FBNIC_RPC_TCAM_ACT_NUM_ENTRIES		64
37 
38 struct fbnic_mac_addr {
39 	union {
40 		unsigned char addr8[ETH_ALEN];
41 		__be16 addr16[FBNIC_RPC_TCAM_MACDA_WORD_LEN];
42 	} mask, value;
43 	unsigned char state;
44 	DECLARE_BITMAP(act_tcam, FBNIC_RPC_TCAM_ACT_NUM_ENTRIES);
45 };
46 
47 struct fbnic_act_tcam {
48 	struct {
49 		u16 tcam[FBNIC_RPC_TCAM_ACT_WORD_LEN];
50 	} mask, value;
51 	unsigned char state;
52 	u16 rss_en_mask;
53 	u32 dest;
54 };
55 
56 enum {
57 	FBNIC_RSS_EN_HOST_UDP6,
58 	FBNIC_RSS_EN_HOST_UDP4,
59 	FBNIC_RSS_EN_HOST_TCP6,
60 	FBNIC_RSS_EN_HOST_TCP4,
61 	FBNIC_RSS_EN_HOST_IP6,
62 	FBNIC_RSS_EN_HOST_IP4,
63 	FBNIC_RSS_EN_HOST_ETHER,
64 	FBNIC_RSS_EN_XCAST_UDP6,
65 #define FBNIC_RSS_EN_NUM_UNICAST FBNIC_RSS_EN_XCAST_UDP6
66 	FBNIC_RSS_EN_XCAST_UDP4,
67 	FBNIC_RSS_EN_XCAST_TCP6,
68 	FBNIC_RSS_EN_XCAST_TCP4,
69 	FBNIC_RSS_EN_XCAST_IP6,
70 	FBNIC_RSS_EN_XCAST_IP4,
71 	FBNIC_RSS_EN_XCAST_ETHER,
72 	FBNIC_RSS_EN_NUM_ENTRIES
73 };
74 
75 /* Reserve the first 2 entries for the use by the BMC so that we can
76  * avoid allowing rules to get in the way of BMC unicast traffic.
77  */
78 #define FBNIC_RPC_ACT_TBL_BMC_OFFSET		0
79 #define FBNIC_RPC_ACT_TBL_BMC_ALL_MULTI_OFFSET	1
80 
81 /* We reserve the last 14 entries for RSS rules on the host. The BMC
82  * unicast rule will need to be populated above these and is expected to
83  * use MACDA TCAM entry 23 to store the BMC MAC address.
84  */
85 #define FBNIC_RPC_ACT_TBL_RSS_OFFSET \
86 	(FBNIC_RPC_ACT_TBL_NUM_ENTRIES - FBNIC_RSS_EN_NUM_ENTRIES)
87 
88 /* Flags used to identify the owner for this MAC filter. Note that any
89  * flags set for Broadcast thru Promisc indicate that the rule belongs
90  * to the RSS filters for the host.
91  */
92 enum {
93 	FBNIC_MAC_ADDR_T_BMC            = 0,
94 	FBNIC_MAC_ADDR_T_BROADCAST	= FBNIC_RPC_ACT_TBL_RSS_OFFSET,
95 #define FBNIC_MAC_ADDR_T_HOST_START	FBNIC_MAC_ADDR_T_BROADCAST
96 	FBNIC_MAC_ADDR_T_MULTICAST,
97 	FBNIC_MAC_ADDR_T_UNICAST,
98 	FBNIC_MAC_ADDR_T_ALLMULTI,	/* BROADCAST ... MULTICAST*/
99 	FBNIC_MAC_ADDR_T_PROMISC,	/* BROADCAST ... UNICAST */
100 	FBNIC_MAC_ADDR_T_HOST_LAST
101 };
102 
103 #define FBNIC_MAC_ADDR_T_HOST_LEN \
104 	(FBNIC_MAC_ADDR_T_HOST_LAST - FBNIC_MAC_ADDR_T_HOST_START)
105 
106 #define FBNIC_RPC_TCAM_ACT0_IPSRC_IDX		CSR_GENMASK(2, 0)
107 #define FBNIC_RPC_TCAM_ACT0_IPSRC_VALID		CSR_BIT(3)
108 #define FBNIC_RPC_TCAM_ACT0_IPDST_IDX		CSR_GENMASK(6, 4)
109 #define FBNIC_RPC_TCAM_ACT0_IPDST_VALID		CSR_BIT(7)
110 #define FBNIC_RPC_TCAM_ACT0_OUTER_IPSRC_IDX	CSR_GENMASK(10, 8)
111 #define FBNIC_RPC_TCAM_ACT0_OUTER_IPSRC_VALID	CSR_BIT(11)
112 #define FBNIC_RPC_TCAM_ACT0_OUTER_IPDST_IDX	CSR_GENMASK(14, 12)
113 #define FBNIC_RPC_TCAM_ACT0_OUTER_IPDST_VALID	CSR_BIT(15)
114 
115 #define FBNIC_RPC_TCAM_ACT1_L2_MACDA_IDX	CSR_GENMASK(9, 5)
116 #define FBNIC_RPC_TCAM_ACT1_L2_MACDA_VALID	CSR_BIT(10)
117 #define FBNIC_RPC_TCAM_ACT1_IP_IS_V6		CSR_BIT(11)
118 #define FBNIC_RPC_TCAM_ACT1_IP_VALID		CSR_BIT(12)
119 #define FBNIC_RPC_TCAM_ACT1_OUTER_IP_VALID	CSR_BIT(13)
120 #define FBNIC_RPC_TCAM_ACT1_L4_IS_UDP		CSR_BIT(14)
121 #define FBNIC_RPC_TCAM_ACT1_L4_VALID		CSR_BIT(15)
122 
123 /* TCAM 0 - 3 reserved for BMC MAC addresses */
124 #define FBNIC_RPC_TCAM_MACDA_BMC_ADDR_IDX	0
125 /* TCAM 4 reserved for broadcast MAC address */
126 #define FBNIC_RPC_TCAM_MACDA_BROADCAST_IDX	4
127 /* TCAMs 5 - 30 will be used for multicast and unicast addresses. The
128  * boundary between the two can be variable it is currently set to 24
129  * on which the unicast addresses start. The general idea is that we will
130  * always go top-down with unicast, and bottom-up with multicast so that
131  * there should be free-space in the middle between the two.
132  *
133  * The entry at MADCA_DEFAULT_BOUNDARY is a special case as it can be used
134  * for the ALL MULTI address if the list is full, or the BMC has requested
135  * it.
136  */
137 #define FBNIC_RPC_TCAM_MACDA_MULTICAST_IDX	5
138 #define FBNIC_RPC_TCAM_MACDA_DEFAULT_BOUNDARY	24
139 #define FBNIC_RPC_TCAM_MACDA_HOST_ADDR_IDX	30
140 /* Reserved for use to record Multicast promisc, or Promiscuous */
141 #define FBNIC_RPC_TCAM_MACDA_PROMISC_IDX	31
142 
143 enum {
144 	FBNIC_UDP6_HASH_OPT,
145 	FBNIC_UDP4_HASH_OPT,
146 	FBNIC_TCP6_HASH_OPT,
147 	FBNIC_TCP4_HASH_OPT,
148 #define FBNIC_L4_HASH_OPT FBNIC_TCP4_HASH_OPT
149 	FBNIC_IPV6_HASH_OPT,
150 	FBNIC_IPV4_HASH_OPT,
151 #define FBNIC_IP_HASH_OPT FBNIC_IPV4_HASH_OPT
152 	FBNIC_ETHER_HASH_OPT,
153 	FBNIC_NUM_HASH_OPT,
154 };
155 
156 struct fbnic_dev;
157 struct fbnic_net;
158 
159 void fbnic_bmc_rpc_init(struct fbnic_dev *fbd);
160 void fbnic_bmc_rpc_all_multi_config(struct fbnic_dev *fbd, bool enable_host);
161 
162 void fbnic_reset_indir_tbl(struct fbnic_net *fbn);
163 void fbnic_rss_key_fill(u32 *buffer);
164 void fbnic_rss_init_en_mask(struct fbnic_net *fbn);
165 void fbnic_rss_disable_hw(struct fbnic_dev *fbd);
166 void fbnic_rss_reinit_hw(struct fbnic_dev *fbd, struct fbnic_net *fbn);
167 void fbnic_rss_reinit(struct fbnic_dev *fbd, struct fbnic_net *fbn);
168 
169 int __fbnic_xc_unsync(struct fbnic_mac_addr *mac_addr, unsigned int tcam_idx);
170 struct fbnic_mac_addr *__fbnic_uc_sync(struct fbnic_dev *fbd,
171 				       const unsigned char *addr);
172 struct fbnic_mac_addr *__fbnic_mc_sync(struct fbnic_dev *fbd,
173 				       const unsigned char *addr);
174 void fbnic_sift_macda(struct fbnic_dev *fbd);
175 void fbnic_write_macda(struct fbnic_dev *fbd);
176 
__fbnic_uc_unsync(struct fbnic_mac_addr * mac_addr)177 static inline int __fbnic_uc_unsync(struct fbnic_mac_addr *mac_addr)
178 {
179 	return __fbnic_xc_unsync(mac_addr, FBNIC_MAC_ADDR_T_UNICAST);
180 }
181 
__fbnic_mc_unsync(struct fbnic_mac_addr * mac_addr)182 static inline int __fbnic_mc_unsync(struct fbnic_mac_addr *mac_addr)
183 {
184 	return __fbnic_xc_unsync(mac_addr, FBNIC_MAC_ADDR_T_MULTICAST);
185 }
186 
187 void fbnic_clear_rules(struct fbnic_dev *fbd);
188 void fbnic_write_rules(struct fbnic_dev *fbd);
189 #endif /* _FBNIC_RPC_H_ */
190