Skip to content

Commit fd2a6b7

Browse files
DanNowlinanguy11
authored andcommitted
ice: create advanced switch recipe
These changes introduce code for creating advanced recipes for the switch in hardware. There are a couple of recipes already defined in the HW. They apply to matching on basic protocol headers, like MAC, VLAN, MACVLAN, ethertype or direction (promiscuous), etc.. If the user wants to match on other protocol headers (eg. ip address, src/dst port etc.) or different variation of already supported protocols, there is a need to create new, more complex recipe. That new recipe is referred as 'advanced recipe', and the filtering rule created on top of that recipe is called 'advanced rule'. One recipe can have up to 5 words, but the first word is always reserved for match on switch id, so the driver can define up to 4 words for one recipe. To support recipes with more words up to 5 recipes can be chained, so 20 words can be programmed for look up. Input for adding recipe function is a list of protocols to support. Based on this list correct profile is being chosen. Correct profile means that it contains all protocol types from a list. Each profile have up to 48 field vector words and each of this word have protocol id and offset. These two fields need to match with input data for adding recipe function. If the correct profile can't be found the function returns an error. The next step after finding the correct profile is grouping words into groups. One group can have up to 4 words. This is done to simplify sending recipes to HW (because recipe also can have up to 4 words). In case of chaining (so when look up consists of more than 4 words) last recipe will always have results from the previous recipes used as words. A recipe to profile map is used to store information about which profile is associate with this recipe. This map is an array of 64 elements (max number of recipes) and each element is a 256 bits bitmap (max number of profiles) Profile to recipe map is used to store information about which recipe is associate with this profile. This map is an array of 256 elements (max number of profiles) and each element is a 64 bits bitmap (max number of recipes) Signed-off-by: Dan Nowlin <dan.nowlin@intel.com> Signed-off-by: Wojciech Drewek <wojciech.drewek@intel.com> Tested-by: Sandeep Penigalapati <sandeep.penigalapati@intel.com> Signed-off-by: Tony Nguyen <anthony.l.nguyen@intel.com>
1 parent 450052a commit fd2a6b7

File tree

5 files changed

+1412
-22
lines changed

5 files changed

+1412
-22
lines changed

drivers/net/ethernet/intel/ice/ice_flex_pipe.c

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,7 @@ static void ice_release_global_cfg_lock(struct ice_hw *hw)
735735
*
736736
* This function will request ownership of the change lock.
737737
*/
738-
static enum ice_status
738+
enum ice_status
739739
ice_acquire_change_lock(struct ice_hw *hw, enum ice_aq_res_access_type access)
740740
{
741741
return ice_acquire_res(hw, ICE_CHANGE_LOCK_RES_ID, access,
@@ -748,7 +748,7 @@ ice_acquire_change_lock(struct ice_hw *hw, enum ice_aq_res_access_type access)
748748
*
749749
* This function will release the change lock using the proper Admin Command.
750750
*/
751-
static void ice_release_change_lock(struct ice_hw *hw)
751+
void ice_release_change_lock(struct ice_hw *hw)
752752
{
753753
ice_release_res(hw, ICE_CHANGE_LOCK_RES_ID);
754754
}
@@ -2105,6 +2105,35 @@ int ice_udp_tunnel_unset_port(struct net_device *netdev, unsigned int table,
21052105
return 0;
21062106
}
21072107

2108+
/**
2109+
* ice_find_prot_off - find prot ID and offset pair, based on prof and FV index
2110+
* @hw: pointer to the hardware structure
2111+
* @blk: hardware block
2112+
* @prof: profile ID
2113+
* @fv_idx: field vector word index
2114+
* @prot: variable to receive the protocol ID
2115+
* @off: variable to receive the protocol offset
2116+
*/
2117+
enum ice_status
2118+
ice_find_prot_off(struct ice_hw *hw, enum ice_block blk, u8 prof, u16 fv_idx,
2119+
u8 *prot, u16 *off)
2120+
{
2121+
struct ice_fv_word *fv_ext;
2122+
2123+
if (prof >= hw->blk[blk].es.count)
2124+
return ICE_ERR_PARAM;
2125+
2126+
if (fv_idx >= hw->blk[blk].es.fvw)
2127+
return ICE_ERR_PARAM;
2128+
2129+
fv_ext = hw->blk[blk].es.t + (prof * hw->blk[blk].es.fvw);
2130+
2131+
*prot = fv_ext[fv_idx].prot_id;
2132+
*off = fv_ext[fv_idx].off;
2133+
2134+
return 0;
2135+
}
2136+
21082137
/* PTG Management */
21092138

21102139
/**

drivers/net/ethernet/intel/ice/ice_flex_pipe.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@
1818

1919
#define ICE_PKG_CNT 4
2020

21+
enum ice_status
22+
ice_acquire_change_lock(struct ice_hw *hw, enum ice_aq_res_access_type access);
23+
void ice_release_change_lock(struct ice_hw *hw);
24+
enum ice_status
25+
ice_find_prot_off(struct ice_hw *hw, enum ice_block blk, u8 prof, u16 fv_idx,
26+
u8 *prot, u16 *off);
2127
void
2228
ice_get_sw_fv_bitmap(struct ice_hw *hw, enum ice_prof_type type,
2329
unsigned long *bm);

drivers/net/ethernet/intel/ice/ice_protocol_type.h

Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,44 @@
33

44
#ifndef _ICE_PROTOCOL_TYPE_H_
55
#define _ICE_PROTOCOL_TYPE_H_
6+
#define ICE_IPV6_ADDR_LENGTH 16
7+
8+
/* Each recipe can match up to 5 different fields. Fields to match can be meta-
9+
* data, values extracted from packet headers, or results from other recipes.
10+
* One of the 5 fields is reserved for matching the switch ID. So, up to 4
11+
* recipes can provide intermediate results to another one through chaining,
12+
* e.g. recipes 0, 1, 2, and 3 can provide intermediate results to recipe 4.
13+
*/
14+
#define ICE_NUM_WORDS_RECIPE 4
15+
16+
/* Max recipes that can be chained */
17+
#define ICE_MAX_CHAIN_RECIPE 5
18+
19+
/* 1 word reserved for switch ID from allowed 5 words.
20+
* So a recipe can have max 4 words. And you can chain 5 such recipes
21+
* together. So maximum words that can be programmed for look up is 5 * 4.
22+
*/
23+
#define ICE_MAX_CHAIN_WORDS (ICE_NUM_WORDS_RECIPE * ICE_MAX_CHAIN_RECIPE)
24+
25+
/* Field vector index corresponding to chaining */
26+
#define ICE_CHAIN_FV_INDEX_START 47
27+
28+
enum ice_protocol_type {
29+
ICE_MAC_OFOS = 0,
30+
ICE_MAC_IL,
31+
ICE_ETYPE_OL,
32+
ICE_VLAN_OFOS,
33+
ICE_IPV4_OFOS,
34+
ICE_IPV4_IL,
35+
ICE_IPV6_OFOS,
36+
ICE_IPV6_IL,
37+
ICE_TCP_IL,
38+
ICE_UDP_OF,
39+
ICE_UDP_ILOS,
40+
ICE_SCTP_IL,
41+
ICE_PROTOCOL_LAST
42+
};
43+
644
/* Decoders for ice_prot_id:
745
* - F: First
846
* - I: Inner
@@ -35,4 +73,135 @@ enum ice_prot_id {
3573
ICE_PROT_META_ID = 255, /* when offset == metadata */
3674
ICE_PROT_INVALID = 255 /* when offset == ICE_FV_OFFSET_INVAL */
3775
};
76+
77+
#define ICE_MAC_OFOS_HW 1
78+
#define ICE_MAC_IL_HW 4
79+
#define ICE_ETYPE_OL_HW 9
80+
#define ICE_VLAN_OF_HW 16
81+
#define ICE_VLAN_OL_HW 17
82+
#define ICE_IPV4_OFOS_HW 32
83+
#define ICE_IPV4_IL_HW 33
84+
#define ICE_IPV6_OFOS_HW 40
85+
#define ICE_IPV6_IL_HW 41
86+
#define ICE_TCP_IL_HW 49
87+
#define ICE_UDP_ILOS_HW 53
88+
89+
#define ICE_UDP_OF_HW 52 /* UDP Tunnels */
90+
91+
#define ICE_TUN_FLAG_FV_IND 2
92+
93+
/* Mapping of software defined protocol ID to hardware defined protocol ID */
94+
struct ice_protocol_entry {
95+
enum ice_protocol_type type;
96+
u8 protocol_id;
97+
};
98+
99+
struct ice_ether_hdr {
100+
u8 dst_addr[ETH_ALEN];
101+
u8 src_addr[ETH_ALEN];
102+
};
103+
104+
struct ice_ethtype_hdr {
105+
__be16 ethtype_id;
106+
};
107+
108+
struct ice_ether_vlan_hdr {
109+
u8 dst_addr[ETH_ALEN];
110+
u8 src_addr[ETH_ALEN];
111+
__be32 vlan_id;
112+
};
113+
114+
struct ice_vlan_hdr {
115+
__be16 type;
116+
__be16 vlan;
117+
};
118+
119+
struct ice_ipv4_hdr {
120+
u8 version;
121+
u8 tos;
122+
__be16 total_length;
123+
__be16 id;
124+
__be16 frag_off;
125+
u8 time_to_live;
126+
u8 protocol;
127+
__be16 check;
128+
__be32 src_addr;
129+
__be32 dst_addr;
130+
};
131+
132+
struct ice_ipv6_hdr {
133+
__be32 be_ver_tc_flow;
134+
__be16 payload_len;
135+
u8 next_hdr;
136+
u8 hop_limit;
137+
u8 src_addr[ICE_IPV6_ADDR_LENGTH];
138+
u8 dst_addr[ICE_IPV6_ADDR_LENGTH];
139+
};
140+
141+
struct ice_sctp_hdr {
142+
__be16 src_port;
143+
__be16 dst_port;
144+
__be32 verification_tag;
145+
__be32 check;
146+
};
147+
148+
struct ice_l4_hdr {
149+
__be16 src_port;
150+
__be16 dst_port;
151+
__be16 len;
152+
__be16 check;
153+
};
154+
155+
union ice_prot_hdr {
156+
struct ice_ether_hdr eth_hdr;
157+
struct ice_ethtype_hdr ethertype;
158+
struct ice_vlan_hdr vlan_hdr;
159+
struct ice_ipv4_hdr ipv4_hdr;
160+
struct ice_ipv6_hdr ipv6_hdr;
161+
struct ice_l4_hdr l4_hdr;
162+
struct ice_sctp_hdr sctp_hdr;
163+
};
164+
165+
/* This is mapping table entry that maps every word within a given protocol
166+
* structure to the real byte offset as per the specification of that
167+
* protocol header.
168+
* for e.g. dst address is 3 words in ethertype header and corresponding bytes
169+
* are 0, 2, 3 in the actual packet header and src address is at 4, 6, 8
170+
*/
171+
struct ice_prot_ext_tbl_entry {
172+
enum ice_protocol_type prot_type;
173+
/* Byte offset into header of given protocol type */
174+
u8 offs[sizeof(union ice_prot_hdr)];
175+
};
176+
177+
/* Extractions to be looked up for a given recipe */
178+
struct ice_prot_lkup_ext {
179+
u16 prot_type;
180+
u8 n_val_words;
181+
/* create a buffer to hold max words per recipe */
182+
u16 field_off[ICE_MAX_CHAIN_WORDS];
183+
u16 field_mask[ICE_MAX_CHAIN_WORDS];
184+
185+
struct ice_fv_word fv_words[ICE_MAX_CHAIN_WORDS];
186+
187+
/* Indicate field offsets that have field vector indices assigned */
188+
DECLARE_BITMAP(done, ICE_MAX_CHAIN_WORDS);
189+
};
190+
191+
struct ice_pref_recipe_group {
192+
u8 n_val_pairs; /* Number of valid pairs */
193+
struct ice_fv_word pairs[ICE_NUM_WORDS_RECIPE];
194+
u16 mask[ICE_NUM_WORDS_RECIPE];
195+
};
196+
197+
struct ice_recp_grp_entry {
198+
struct list_head l_entry;
199+
200+
#define ICE_INVAL_CHAIN_IND 0xFF
201+
u16 rid;
202+
u8 chain_idx;
203+
u16 fv_idx[ICE_NUM_WORDS_RECIPE];
204+
u16 fv_mask[ICE_NUM_WORDS_RECIPE];
205+
struct ice_pref_recipe_group r_group;
206+
};
38207
#endif /* _ICE_PROTOCOL_TYPE_H_ */

0 commit comments

Comments
 (0)