1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* Copyright (c) 2019, Intel Corporation. */ 3 4 #ifndef _ICE_FLOW_H_ 5 #define _ICE_FLOW_H_ 6 7 #define ICE_FLOW_ENTRY_HANDLE_INVAL 0 8 #define ICE_FLOW_FLD_OFF_INVAL 0xffff 9 10 /* Generate flow hash field from flow field type(s) */ 11 #define ICE_FLOW_HASH_IPV4 \ 12 (BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_SA) | \ 13 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_DA)) 14 #define ICE_FLOW_HASH_IPV6 \ 15 (BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_SA) | \ 16 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_DA)) 17 #define ICE_FLOW_HASH_TCP_PORT \ 18 (BIT_ULL(ICE_FLOW_FIELD_IDX_TCP_SRC_PORT) | \ 19 BIT_ULL(ICE_FLOW_FIELD_IDX_TCP_DST_PORT)) 20 #define ICE_FLOW_HASH_UDP_PORT \ 21 (BIT_ULL(ICE_FLOW_FIELD_IDX_UDP_SRC_PORT) | \ 22 BIT_ULL(ICE_FLOW_FIELD_IDX_UDP_DST_PORT)) 23 #define ICE_FLOW_HASH_SCTP_PORT \ 24 (BIT_ULL(ICE_FLOW_FIELD_IDX_SCTP_SRC_PORT) | \ 25 BIT_ULL(ICE_FLOW_FIELD_IDX_SCTP_DST_PORT)) 26 27 #define ICE_HASH_INVALID 0 28 #define ICE_HASH_TCP_IPV4 (ICE_FLOW_HASH_IPV4 | ICE_FLOW_HASH_TCP_PORT) 29 #define ICE_HASH_TCP_IPV6 (ICE_FLOW_HASH_IPV6 | ICE_FLOW_HASH_TCP_PORT) 30 #define ICE_HASH_UDP_IPV4 (ICE_FLOW_HASH_IPV4 | ICE_FLOW_HASH_UDP_PORT) 31 #define ICE_HASH_UDP_IPV6 (ICE_FLOW_HASH_IPV6 | ICE_FLOW_HASH_UDP_PORT) 32 33 /* Protocol header fields within a packet segment. A segment consists of one or 34 * more protocol headers that make up a logical group of protocol headers. Each 35 * logical group of protocol headers encapsulates or is encapsulated using/by 36 * tunneling or encapsulation protocols for network virtualization such as GRE, 37 * VxLAN, etc. 38 */ 39 enum ice_flow_seg_hdr { 40 ICE_FLOW_SEG_HDR_NONE = 0x00000000, 41 ICE_FLOW_SEG_HDR_ETH = 0x00000001, 42 ICE_FLOW_SEG_HDR_VLAN = 0x00000002, 43 ICE_FLOW_SEG_HDR_IPV4 = 0x00000004, 44 ICE_FLOW_SEG_HDR_IPV6 = 0x00000008, 45 ICE_FLOW_SEG_HDR_ARP = 0x00000010, 46 ICE_FLOW_SEG_HDR_ICMP = 0x00000020, 47 ICE_FLOW_SEG_HDR_TCP = 0x00000040, 48 ICE_FLOW_SEG_HDR_UDP = 0x00000080, 49 ICE_FLOW_SEG_HDR_SCTP = 0x00000100, 50 ICE_FLOW_SEG_HDR_GRE = 0x00000200, 51 }; 52 53 enum ice_flow_field { 54 /* L2 */ 55 ICE_FLOW_FIELD_IDX_ETH_DA, 56 ICE_FLOW_FIELD_IDX_ETH_SA, 57 ICE_FLOW_FIELD_IDX_S_VLAN, 58 ICE_FLOW_FIELD_IDX_C_VLAN, 59 ICE_FLOW_FIELD_IDX_ETH_TYPE, 60 /* L3 */ 61 ICE_FLOW_FIELD_IDX_IPV4_DSCP, 62 ICE_FLOW_FIELD_IDX_IPV6_DSCP, 63 ICE_FLOW_FIELD_IDX_IPV4_TTL, 64 ICE_FLOW_FIELD_IDX_IPV4_PROT, 65 ICE_FLOW_FIELD_IDX_IPV6_TTL, 66 ICE_FLOW_FIELD_IDX_IPV6_PROT, 67 ICE_FLOW_FIELD_IDX_IPV4_SA, 68 ICE_FLOW_FIELD_IDX_IPV4_DA, 69 ICE_FLOW_FIELD_IDX_IPV6_SA, 70 ICE_FLOW_FIELD_IDX_IPV6_DA, 71 /* L4 */ 72 ICE_FLOW_FIELD_IDX_TCP_SRC_PORT, 73 ICE_FLOW_FIELD_IDX_TCP_DST_PORT, 74 ICE_FLOW_FIELD_IDX_UDP_SRC_PORT, 75 ICE_FLOW_FIELD_IDX_UDP_DST_PORT, 76 ICE_FLOW_FIELD_IDX_SCTP_SRC_PORT, 77 ICE_FLOW_FIELD_IDX_SCTP_DST_PORT, 78 ICE_FLOW_FIELD_IDX_TCP_FLAGS, 79 /* ARP */ 80 ICE_FLOW_FIELD_IDX_ARP_SIP, 81 ICE_FLOW_FIELD_IDX_ARP_DIP, 82 ICE_FLOW_FIELD_IDX_ARP_SHA, 83 ICE_FLOW_FIELD_IDX_ARP_DHA, 84 ICE_FLOW_FIELD_IDX_ARP_OP, 85 /* ICMP */ 86 ICE_FLOW_FIELD_IDX_ICMP_TYPE, 87 ICE_FLOW_FIELD_IDX_ICMP_CODE, 88 /* GRE */ 89 ICE_FLOW_FIELD_IDX_GRE_KEYID, 90 /* The total number of enums must not exceed 64 */ 91 ICE_FLOW_FIELD_IDX_MAX 92 }; 93 94 /* Flow headers and fields for AVF support */ 95 enum ice_flow_avf_hdr_field { 96 /* Values 0 - 28 are reserved for future use */ 97 ICE_AVF_FLOW_FIELD_INVALID = 0, 98 ICE_AVF_FLOW_FIELD_UNICAST_IPV4_UDP = 29, 99 ICE_AVF_FLOW_FIELD_MULTICAST_IPV4_UDP, 100 ICE_AVF_FLOW_FIELD_IPV4_UDP, 101 ICE_AVF_FLOW_FIELD_IPV4_TCP_SYN_NO_ACK, 102 ICE_AVF_FLOW_FIELD_IPV4_TCP, 103 ICE_AVF_FLOW_FIELD_IPV4_SCTP, 104 ICE_AVF_FLOW_FIELD_IPV4_OTHER, 105 ICE_AVF_FLOW_FIELD_FRAG_IPV4, 106 /* Values 37-38 are reserved */ 107 ICE_AVF_FLOW_FIELD_UNICAST_IPV6_UDP = 39, 108 ICE_AVF_FLOW_FIELD_MULTICAST_IPV6_UDP, 109 ICE_AVF_FLOW_FIELD_IPV6_UDP, 110 ICE_AVF_FLOW_FIELD_IPV6_TCP_SYN_NO_ACK, 111 ICE_AVF_FLOW_FIELD_IPV6_TCP, 112 ICE_AVF_FLOW_FIELD_IPV6_SCTP, 113 ICE_AVF_FLOW_FIELD_IPV6_OTHER, 114 ICE_AVF_FLOW_FIELD_FRAG_IPV6, 115 ICE_AVF_FLOW_FIELD_RSVD47, 116 ICE_AVF_FLOW_FIELD_FCOE_OX, 117 ICE_AVF_FLOW_FIELD_FCOE_RX, 118 ICE_AVF_FLOW_FIELD_FCOE_OTHER, 119 /* Values 51-62 are reserved */ 120 ICE_AVF_FLOW_FIELD_L2_PAYLOAD = 63, 121 ICE_AVF_FLOW_FIELD_MAX 122 }; 123 124 /* Supported RSS offloads This macro is defined to support 125 * VIRTCHNL_OP_GET_RSS_HENA_CAPS ops. PF driver sends the RSS hardware 126 * capabilities to the caller of this ops. 127 */ 128 #define ICE_DEFAULT_RSS_HENA ( \ 129 BIT_ULL(ICE_AVF_FLOW_FIELD_IPV4_UDP) | \ 130 BIT_ULL(ICE_AVF_FLOW_FIELD_IPV4_SCTP) | \ 131 BIT_ULL(ICE_AVF_FLOW_FIELD_IPV4_TCP) | \ 132 BIT_ULL(ICE_AVF_FLOW_FIELD_IPV4_OTHER) | \ 133 BIT_ULL(ICE_AVF_FLOW_FIELD_FRAG_IPV4) | \ 134 BIT_ULL(ICE_AVF_FLOW_FIELD_IPV6_UDP) | \ 135 BIT_ULL(ICE_AVF_FLOW_FIELD_IPV6_TCP) | \ 136 BIT_ULL(ICE_AVF_FLOW_FIELD_IPV6_SCTP) | \ 137 BIT_ULL(ICE_AVF_FLOW_FIELD_IPV6_OTHER) | \ 138 BIT_ULL(ICE_AVF_FLOW_FIELD_FRAG_IPV6) | \ 139 BIT_ULL(ICE_AVF_FLOW_FIELD_IPV4_TCP_SYN_NO_ACK) | \ 140 BIT_ULL(ICE_AVF_FLOW_FIELD_UNICAST_IPV4_UDP) | \ 141 BIT_ULL(ICE_AVF_FLOW_FIELD_MULTICAST_IPV4_UDP) | \ 142 BIT_ULL(ICE_AVF_FLOW_FIELD_IPV6_TCP_SYN_NO_ACK) | \ 143 BIT_ULL(ICE_AVF_FLOW_FIELD_UNICAST_IPV6_UDP) | \ 144 BIT_ULL(ICE_AVF_FLOW_FIELD_MULTICAST_IPV6_UDP)) 145 146 enum ice_flow_dir { 147 ICE_FLOW_RX = 0x02, 148 }; 149 150 enum ice_flow_priority { 151 ICE_FLOW_PRIO_LOW, 152 ICE_FLOW_PRIO_NORMAL, 153 ICE_FLOW_PRIO_HIGH 154 }; 155 156 #define ICE_FLOW_SEG_MAX 2 157 #define ICE_FLOW_SEG_RAW_FLD_MAX 2 158 #define ICE_FLOW_FV_EXTRACT_SZ 2 159 160 #define ICE_FLOW_SET_HDRS(seg, val) ((seg)->hdrs |= (u32)(val)) 161 162 struct ice_flow_seg_xtrct { 163 u8 prot_id; /* Protocol ID of extracted header field */ 164 u16 off; /* Starting offset of the field in header in bytes */ 165 u8 idx; /* Index of FV entry used */ 166 u8 disp; /* Displacement of field in bits fr. FV entry's start */ 167 u16 mask; /* Mask for field */ 168 }; 169 170 enum ice_flow_fld_match_type { 171 ICE_FLOW_FLD_TYPE_REG, /* Value, mask */ 172 ICE_FLOW_FLD_TYPE_RANGE, /* Value, mask, last (upper bound) */ 173 ICE_FLOW_FLD_TYPE_PREFIX, /* IP address, prefix, size of prefix */ 174 ICE_FLOW_FLD_TYPE_SIZE, /* Value, mask, size of match */ 175 }; 176 177 struct ice_flow_fld_loc { 178 /* Describe offsets of field information relative to the beginning of 179 * input buffer provided when adding flow entries. 180 */ 181 u16 val; /* Offset where the value is located */ 182 u16 mask; /* Offset where the mask/prefix value is located */ 183 u16 last; /* Length or offset where the upper value is located */ 184 }; 185 186 struct ice_flow_fld_info { 187 enum ice_flow_fld_match_type type; 188 /* Location where to retrieve data from an input buffer */ 189 struct ice_flow_fld_loc src; 190 /* Location where to put the data into the final entry buffer */ 191 struct ice_flow_fld_loc entry; 192 struct ice_flow_seg_xtrct xtrct; 193 }; 194 195 struct ice_flow_seg_fld_raw { 196 struct ice_flow_fld_info info; 197 u16 off; /* Offset from the start of the segment */ 198 }; 199 200 struct ice_flow_seg_info { 201 u32 hdrs; /* Bitmask indicating protocol headers present */ 202 u64 match; /* Bitmask indicating header fields to be matched */ 203 u64 range; /* Bitmask indicating header fields matched as ranges */ 204 205 struct ice_flow_fld_info fields[ICE_FLOW_FIELD_IDX_MAX]; 206 207 u8 raws_cnt; /* Number of raw fields to be matched */ 208 struct ice_flow_seg_fld_raw raws[ICE_FLOW_SEG_RAW_FLD_MAX]; 209 }; 210 211 /* This structure describes a flow entry, and is tracked only in this file */ 212 struct ice_flow_entry { 213 struct list_head l_entry; 214 215 u64 id; 216 struct ice_flow_prof *prof; 217 /* Flow entry's content */ 218 void *entry; 219 enum ice_flow_priority priority; 220 u16 vsi_handle; 221 u16 entry_sz; 222 }; 223 224 #define ICE_FLOW_ENTRY_HNDL(e) ((u64)(uintptr_t)e) 225 #define ICE_FLOW_ENTRY_PTR(h) ((struct ice_flow_entry *)(uintptr_t)(h)) 226 227 struct ice_flow_prof { 228 struct list_head l_entry; 229 230 u64 id; 231 enum ice_flow_dir dir; 232 u8 segs_cnt; 233 234 /* Keep track of flow entries associated with this flow profile */ 235 struct mutex entries_lock; 236 struct list_head entries; 237 238 struct ice_flow_seg_info segs[ICE_FLOW_SEG_MAX]; 239 240 /* software VSI handles referenced by this flow profile */ 241 DECLARE_BITMAP(vsis, ICE_MAX_VSI); 242 }; 243 244 struct ice_rss_cfg { 245 struct list_head l_entry; 246 /* bitmap of VSIs added to the RSS entry */ 247 DECLARE_BITMAP(vsis, ICE_MAX_VSI); 248 u64 hashed_flds; 249 u32 packet_hdr; 250 }; 251 252 enum ice_status 253 ice_flow_add_prof(struct ice_hw *hw, enum ice_block blk, enum ice_flow_dir dir, 254 u64 prof_id, struct ice_flow_seg_info *segs, u8 segs_cnt, 255 struct ice_flow_prof **prof); 256 enum ice_status 257 ice_flow_rem_prof(struct ice_hw *hw, enum ice_block blk, u64 prof_id); 258 enum ice_status 259 ice_flow_add_entry(struct ice_hw *hw, enum ice_block blk, u64 prof_id, 260 u64 entry_id, u16 vsi, enum ice_flow_priority prio, 261 void *data, u64 *entry_h); 262 enum ice_status 263 ice_flow_rem_entry(struct ice_hw *hw, enum ice_block blk, u64 entry_h); 264 void 265 ice_flow_set_fld(struct ice_flow_seg_info *seg, enum ice_flow_field fld, 266 u16 val_loc, u16 mask_loc, u16 last_loc, bool range); 267 void 268 ice_flow_add_fld_raw(struct ice_flow_seg_info *seg, u16 off, u8 len, 269 u16 val_loc, u16 mask_loc); 270 void ice_rem_vsi_rss_list(struct ice_hw *hw, u16 vsi_handle); 271 enum ice_status ice_replay_rss_cfg(struct ice_hw *hw, u16 vsi_handle); 272 enum ice_status 273 ice_add_avf_rss_cfg(struct ice_hw *hw, u16 vsi_handle, u64 hashed_flds); 274 enum ice_status ice_rem_vsi_rss_cfg(struct ice_hw *hw, u16 vsi_handle); 275 enum ice_status 276 ice_add_rss_cfg(struct ice_hw *hw, u16 vsi_handle, u64 hashed_flds, 277 u32 addl_hdrs); 278 u64 ice_get_rss_cfg(struct ice_hw *hw, u16 vsi_handle, u32 hdrs); 279 #endif /* _ICE_FLOW_H_ */ 280