18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci/* Copyright (c) 2019, Intel Corporation. */ 38c2ecf20Sopenharmony_ci 48c2ecf20Sopenharmony_ci#ifndef _ICE_FLOW_H_ 58c2ecf20Sopenharmony_ci#define _ICE_FLOW_H_ 68c2ecf20Sopenharmony_ci 78c2ecf20Sopenharmony_ci#define ICE_FLOW_ENTRY_HANDLE_INVAL 0 88c2ecf20Sopenharmony_ci#define ICE_FLOW_FLD_OFF_INVAL 0xffff 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ci/* Generate flow hash field from flow field type(s) */ 118c2ecf20Sopenharmony_ci#define ICE_FLOW_HASH_IPV4 \ 128c2ecf20Sopenharmony_ci (BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_SA) | \ 138c2ecf20Sopenharmony_ci BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_DA)) 148c2ecf20Sopenharmony_ci#define ICE_FLOW_HASH_IPV6 \ 158c2ecf20Sopenharmony_ci (BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_SA) | \ 168c2ecf20Sopenharmony_ci BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_DA)) 178c2ecf20Sopenharmony_ci#define ICE_FLOW_HASH_TCP_PORT \ 188c2ecf20Sopenharmony_ci (BIT_ULL(ICE_FLOW_FIELD_IDX_TCP_SRC_PORT) | \ 198c2ecf20Sopenharmony_ci BIT_ULL(ICE_FLOW_FIELD_IDX_TCP_DST_PORT)) 208c2ecf20Sopenharmony_ci#define ICE_FLOW_HASH_UDP_PORT \ 218c2ecf20Sopenharmony_ci (BIT_ULL(ICE_FLOW_FIELD_IDX_UDP_SRC_PORT) | \ 228c2ecf20Sopenharmony_ci BIT_ULL(ICE_FLOW_FIELD_IDX_UDP_DST_PORT)) 238c2ecf20Sopenharmony_ci#define ICE_FLOW_HASH_SCTP_PORT \ 248c2ecf20Sopenharmony_ci (BIT_ULL(ICE_FLOW_FIELD_IDX_SCTP_SRC_PORT) | \ 258c2ecf20Sopenharmony_ci BIT_ULL(ICE_FLOW_FIELD_IDX_SCTP_DST_PORT)) 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_ci#define ICE_HASH_INVALID 0 288c2ecf20Sopenharmony_ci#define ICE_HASH_TCP_IPV4 (ICE_FLOW_HASH_IPV4 | ICE_FLOW_HASH_TCP_PORT) 298c2ecf20Sopenharmony_ci#define ICE_HASH_TCP_IPV6 (ICE_FLOW_HASH_IPV6 | ICE_FLOW_HASH_TCP_PORT) 308c2ecf20Sopenharmony_ci#define ICE_HASH_UDP_IPV4 (ICE_FLOW_HASH_IPV4 | ICE_FLOW_HASH_UDP_PORT) 318c2ecf20Sopenharmony_ci#define ICE_HASH_UDP_IPV6 (ICE_FLOW_HASH_IPV6 | ICE_FLOW_HASH_UDP_PORT) 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_ci/* Protocol header fields within a packet segment. A segment consists of one or 348c2ecf20Sopenharmony_ci * more protocol headers that make up a logical group of protocol headers. Each 358c2ecf20Sopenharmony_ci * logical group of protocol headers encapsulates or is encapsulated using/by 368c2ecf20Sopenharmony_ci * tunneling or encapsulation protocols for network virtualization such as GRE, 378c2ecf20Sopenharmony_ci * VxLAN, etc. 388c2ecf20Sopenharmony_ci */ 398c2ecf20Sopenharmony_cienum ice_flow_seg_hdr { 408c2ecf20Sopenharmony_ci ICE_FLOW_SEG_HDR_NONE = 0x00000000, 418c2ecf20Sopenharmony_ci ICE_FLOW_SEG_HDR_IPV4 = 0x00000004, 428c2ecf20Sopenharmony_ci ICE_FLOW_SEG_HDR_IPV6 = 0x00000008, 438c2ecf20Sopenharmony_ci ICE_FLOW_SEG_HDR_TCP = 0x00000040, 448c2ecf20Sopenharmony_ci ICE_FLOW_SEG_HDR_UDP = 0x00000080, 458c2ecf20Sopenharmony_ci ICE_FLOW_SEG_HDR_SCTP = 0x00000100, 468c2ecf20Sopenharmony_ci ICE_FLOW_SEG_HDR_GRE = 0x00000200, 478c2ecf20Sopenharmony_ci}; 488c2ecf20Sopenharmony_ci 498c2ecf20Sopenharmony_cienum ice_flow_field { 508c2ecf20Sopenharmony_ci /* L3 */ 518c2ecf20Sopenharmony_ci ICE_FLOW_FIELD_IDX_IPV4_SA, 528c2ecf20Sopenharmony_ci ICE_FLOW_FIELD_IDX_IPV4_DA, 538c2ecf20Sopenharmony_ci ICE_FLOW_FIELD_IDX_IPV6_SA, 548c2ecf20Sopenharmony_ci ICE_FLOW_FIELD_IDX_IPV6_DA, 558c2ecf20Sopenharmony_ci /* L4 */ 568c2ecf20Sopenharmony_ci ICE_FLOW_FIELD_IDX_TCP_SRC_PORT, 578c2ecf20Sopenharmony_ci ICE_FLOW_FIELD_IDX_TCP_DST_PORT, 588c2ecf20Sopenharmony_ci ICE_FLOW_FIELD_IDX_UDP_SRC_PORT, 598c2ecf20Sopenharmony_ci ICE_FLOW_FIELD_IDX_UDP_DST_PORT, 608c2ecf20Sopenharmony_ci ICE_FLOW_FIELD_IDX_SCTP_SRC_PORT, 618c2ecf20Sopenharmony_ci ICE_FLOW_FIELD_IDX_SCTP_DST_PORT, 628c2ecf20Sopenharmony_ci /* GRE */ 638c2ecf20Sopenharmony_ci ICE_FLOW_FIELD_IDX_GRE_KEYID, 648c2ecf20Sopenharmony_ci /* The total number of enums must not exceed 64 */ 658c2ecf20Sopenharmony_ci ICE_FLOW_FIELD_IDX_MAX 668c2ecf20Sopenharmony_ci}; 678c2ecf20Sopenharmony_ci 688c2ecf20Sopenharmony_ci/* Flow headers and fields for AVF support */ 698c2ecf20Sopenharmony_cienum ice_flow_avf_hdr_field { 708c2ecf20Sopenharmony_ci /* Values 0 - 28 are reserved for future use */ 718c2ecf20Sopenharmony_ci ICE_AVF_FLOW_FIELD_INVALID = 0, 728c2ecf20Sopenharmony_ci ICE_AVF_FLOW_FIELD_UNICAST_IPV4_UDP = 29, 738c2ecf20Sopenharmony_ci ICE_AVF_FLOW_FIELD_MULTICAST_IPV4_UDP, 748c2ecf20Sopenharmony_ci ICE_AVF_FLOW_FIELD_IPV4_UDP, 758c2ecf20Sopenharmony_ci ICE_AVF_FLOW_FIELD_IPV4_TCP_SYN_NO_ACK, 768c2ecf20Sopenharmony_ci ICE_AVF_FLOW_FIELD_IPV4_TCP, 778c2ecf20Sopenharmony_ci ICE_AVF_FLOW_FIELD_IPV4_SCTP, 788c2ecf20Sopenharmony_ci ICE_AVF_FLOW_FIELD_IPV4_OTHER, 798c2ecf20Sopenharmony_ci ICE_AVF_FLOW_FIELD_FRAG_IPV4, 808c2ecf20Sopenharmony_ci /* Values 37-38 are reserved */ 818c2ecf20Sopenharmony_ci ICE_AVF_FLOW_FIELD_UNICAST_IPV6_UDP = 39, 828c2ecf20Sopenharmony_ci ICE_AVF_FLOW_FIELD_MULTICAST_IPV6_UDP, 838c2ecf20Sopenharmony_ci ICE_AVF_FLOW_FIELD_IPV6_UDP, 848c2ecf20Sopenharmony_ci ICE_AVF_FLOW_FIELD_IPV6_TCP_SYN_NO_ACK, 858c2ecf20Sopenharmony_ci ICE_AVF_FLOW_FIELD_IPV6_TCP, 868c2ecf20Sopenharmony_ci ICE_AVF_FLOW_FIELD_IPV6_SCTP, 878c2ecf20Sopenharmony_ci ICE_AVF_FLOW_FIELD_IPV6_OTHER, 888c2ecf20Sopenharmony_ci ICE_AVF_FLOW_FIELD_FRAG_IPV6, 898c2ecf20Sopenharmony_ci ICE_AVF_FLOW_FIELD_RSVD47, 908c2ecf20Sopenharmony_ci ICE_AVF_FLOW_FIELD_FCOE_OX, 918c2ecf20Sopenharmony_ci ICE_AVF_FLOW_FIELD_FCOE_RX, 928c2ecf20Sopenharmony_ci ICE_AVF_FLOW_FIELD_FCOE_OTHER, 938c2ecf20Sopenharmony_ci /* Values 51-62 are reserved */ 948c2ecf20Sopenharmony_ci ICE_AVF_FLOW_FIELD_L2_PAYLOAD = 63, 958c2ecf20Sopenharmony_ci ICE_AVF_FLOW_FIELD_MAX 968c2ecf20Sopenharmony_ci}; 978c2ecf20Sopenharmony_ci 988c2ecf20Sopenharmony_ci/* Supported RSS offloads This macro is defined to support 998c2ecf20Sopenharmony_ci * VIRTCHNL_OP_GET_RSS_HENA_CAPS ops. PF driver sends the RSS hardware 1008c2ecf20Sopenharmony_ci * capabilities to the caller of this ops. 1018c2ecf20Sopenharmony_ci */ 1028c2ecf20Sopenharmony_ci#define ICE_DEFAULT_RSS_HENA ( \ 1038c2ecf20Sopenharmony_ci BIT_ULL(ICE_AVF_FLOW_FIELD_IPV4_UDP) | \ 1048c2ecf20Sopenharmony_ci BIT_ULL(ICE_AVF_FLOW_FIELD_IPV4_SCTP) | \ 1058c2ecf20Sopenharmony_ci BIT_ULL(ICE_AVF_FLOW_FIELD_IPV4_TCP) | \ 1068c2ecf20Sopenharmony_ci BIT_ULL(ICE_AVF_FLOW_FIELD_IPV4_OTHER) | \ 1078c2ecf20Sopenharmony_ci BIT_ULL(ICE_AVF_FLOW_FIELD_FRAG_IPV4) | \ 1088c2ecf20Sopenharmony_ci BIT_ULL(ICE_AVF_FLOW_FIELD_IPV6_UDP) | \ 1098c2ecf20Sopenharmony_ci BIT_ULL(ICE_AVF_FLOW_FIELD_IPV6_TCP) | \ 1108c2ecf20Sopenharmony_ci BIT_ULL(ICE_AVF_FLOW_FIELD_IPV6_SCTP) | \ 1118c2ecf20Sopenharmony_ci BIT_ULL(ICE_AVF_FLOW_FIELD_IPV6_OTHER) | \ 1128c2ecf20Sopenharmony_ci BIT_ULL(ICE_AVF_FLOW_FIELD_FRAG_IPV6) | \ 1138c2ecf20Sopenharmony_ci BIT_ULL(ICE_AVF_FLOW_FIELD_IPV4_TCP_SYN_NO_ACK) | \ 1148c2ecf20Sopenharmony_ci BIT_ULL(ICE_AVF_FLOW_FIELD_UNICAST_IPV4_UDP) | \ 1158c2ecf20Sopenharmony_ci BIT_ULL(ICE_AVF_FLOW_FIELD_MULTICAST_IPV4_UDP) | \ 1168c2ecf20Sopenharmony_ci BIT_ULL(ICE_AVF_FLOW_FIELD_IPV6_TCP_SYN_NO_ACK) | \ 1178c2ecf20Sopenharmony_ci BIT_ULL(ICE_AVF_FLOW_FIELD_UNICAST_IPV6_UDP) | \ 1188c2ecf20Sopenharmony_ci BIT_ULL(ICE_AVF_FLOW_FIELD_MULTICAST_IPV6_UDP)) 1198c2ecf20Sopenharmony_ci 1208c2ecf20Sopenharmony_cienum ice_flow_dir { 1218c2ecf20Sopenharmony_ci ICE_FLOW_RX = 0x02, 1228c2ecf20Sopenharmony_ci}; 1238c2ecf20Sopenharmony_ci 1248c2ecf20Sopenharmony_cienum ice_flow_priority { 1258c2ecf20Sopenharmony_ci ICE_FLOW_PRIO_LOW, 1268c2ecf20Sopenharmony_ci ICE_FLOW_PRIO_NORMAL, 1278c2ecf20Sopenharmony_ci ICE_FLOW_PRIO_HIGH 1288c2ecf20Sopenharmony_ci}; 1298c2ecf20Sopenharmony_ci 1308c2ecf20Sopenharmony_ci#define ICE_FLOW_SEG_MAX 2 1318c2ecf20Sopenharmony_ci#define ICE_FLOW_SEG_RAW_FLD_MAX 2 1328c2ecf20Sopenharmony_ci#define ICE_FLOW_FV_EXTRACT_SZ 2 1338c2ecf20Sopenharmony_ci 1348c2ecf20Sopenharmony_ci#define ICE_FLOW_SET_HDRS(seg, val) ((seg)->hdrs |= (u32)(val)) 1358c2ecf20Sopenharmony_ci 1368c2ecf20Sopenharmony_cistruct ice_flow_seg_xtrct { 1378c2ecf20Sopenharmony_ci u8 prot_id; /* Protocol ID of extracted header field */ 1388c2ecf20Sopenharmony_ci u16 off; /* Starting offset of the field in header in bytes */ 1398c2ecf20Sopenharmony_ci u8 idx; /* Index of FV entry used */ 1408c2ecf20Sopenharmony_ci u8 disp; /* Displacement of field in bits fr. FV entry's start */ 1418c2ecf20Sopenharmony_ci}; 1428c2ecf20Sopenharmony_ci 1438c2ecf20Sopenharmony_cienum ice_flow_fld_match_type { 1448c2ecf20Sopenharmony_ci ICE_FLOW_FLD_TYPE_REG, /* Value, mask */ 1458c2ecf20Sopenharmony_ci ICE_FLOW_FLD_TYPE_RANGE, /* Value, mask, last (upper bound) */ 1468c2ecf20Sopenharmony_ci ICE_FLOW_FLD_TYPE_PREFIX, /* IP address, prefix, size of prefix */ 1478c2ecf20Sopenharmony_ci ICE_FLOW_FLD_TYPE_SIZE, /* Value, mask, size of match */ 1488c2ecf20Sopenharmony_ci}; 1498c2ecf20Sopenharmony_ci 1508c2ecf20Sopenharmony_cistruct ice_flow_fld_loc { 1518c2ecf20Sopenharmony_ci /* Describe offsets of field information relative to the beginning of 1528c2ecf20Sopenharmony_ci * input buffer provided when adding flow entries. 1538c2ecf20Sopenharmony_ci */ 1548c2ecf20Sopenharmony_ci u16 val; /* Offset where the value is located */ 1558c2ecf20Sopenharmony_ci u16 mask; /* Offset where the mask/prefix value is located */ 1568c2ecf20Sopenharmony_ci u16 last; /* Length or offset where the upper value is located */ 1578c2ecf20Sopenharmony_ci}; 1588c2ecf20Sopenharmony_ci 1598c2ecf20Sopenharmony_cistruct ice_flow_fld_info { 1608c2ecf20Sopenharmony_ci enum ice_flow_fld_match_type type; 1618c2ecf20Sopenharmony_ci /* Location where to retrieve data from an input buffer */ 1628c2ecf20Sopenharmony_ci struct ice_flow_fld_loc src; 1638c2ecf20Sopenharmony_ci /* Location where to put the data into the final entry buffer */ 1648c2ecf20Sopenharmony_ci struct ice_flow_fld_loc entry; 1658c2ecf20Sopenharmony_ci struct ice_flow_seg_xtrct xtrct; 1668c2ecf20Sopenharmony_ci}; 1678c2ecf20Sopenharmony_ci 1688c2ecf20Sopenharmony_cistruct ice_flow_seg_fld_raw { 1698c2ecf20Sopenharmony_ci struct ice_flow_fld_info info; 1708c2ecf20Sopenharmony_ci u16 off; /* Offset from the start of the segment */ 1718c2ecf20Sopenharmony_ci}; 1728c2ecf20Sopenharmony_ci 1738c2ecf20Sopenharmony_cistruct ice_flow_seg_info { 1748c2ecf20Sopenharmony_ci u32 hdrs; /* Bitmask indicating protocol headers present */ 1758c2ecf20Sopenharmony_ci u64 match; /* Bitmask indicating header fields to be matched */ 1768c2ecf20Sopenharmony_ci u64 range; /* Bitmask indicating header fields matched as ranges */ 1778c2ecf20Sopenharmony_ci 1788c2ecf20Sopenharmony_ci struct ice_flow_fld_info fields[ICE_FLOW_FIELD_IDX_MAX]; 1798c2ecf20Sopenharmony_ci 1808c2ecf20Sopenharmony_ci u8 raws_cnt; /* Number of raw fields to be matched */ 1818c2ecf20Sopenharmony_ci struct ice_flow_seg_fld_raw raws[ICE_FLOW_SEG_RAW_FLD_MAX]; 1828c2ecf20Sopenharmony_ci}; 1838c2ecf20Sopenharmony_ci 1848c2ecf20Sopenharmony_ci/* This structure describes a flow entry, and is tracked only in this file */ 1858c2ecf20Sopenharmony_cistruct ice_flow_entry { 1868c2ecf20Sopenharmony_ci struct list_head l_entry; 1878c2ecf20Sopenharmony_ci 1888c2ecf20Sopenharmony_ci u64 id; 1898c2ecf20Sopenharmony_ci struct ice_flow_prof *prof; 1908c2ecf20Sopenharmony_ci /* Flow entry's content */ 1918c2ecf20Sopenharmony_ci void *entry; 1928c2ecf20Sopenharmony_ci enum ice_flow_priority priority; 1938c2ecf20Sopenharmony_ci u16 vsi_handle; 1948c2ecf20Sopenharmony_ci u16 entry_sz; 1958c2ecf20Sopenharmony_ci}; 1968c2ecf20Sopenharmony_ci 1978c2ecf20Sopenharmony_ci#define ICE_FLOW_ENTRY_HNDL(e) ((u64)(uintptr_t)e) 1988c2ecf20Sopenharmony_ci#define ICE_FLOW_ENTRY_PTR(h) ((struct ice_flow_entry *)(uintptr_t)(h)) 1998c2ecf20Sopenharmony_ci 2008c2ecf20Sopenharmony_cistruct ice_flow_prof { 2018c2ecf20Sopenharmony_ci struct list_head l_entry; 2028c2ecf20Sopenharmony_ci 2038c2ecf20Sopenharmony_ci u64 id; 2048c2ecf20Sopenharmony_ci enum ice_flow_dir dir; 2058c2ecf20Sopenharmony_ci u8 segs_cnt; 2068c2ecf20Sopenharmony_ci 2078c2ecf20Sopenharmony_ci /* Keep track of flow entries associated with this flow profile */ 2088c2ecf20Sopenharmony_ci struct mutex entries_lock; 2098c2ecf20Sopenharmony_ci struct list_head entries; 2108c2ecf20Sopenharmony_ci 2118c2ecf20Sopenharmony_ci struct ice_flow_seg_info segs[ICE_FLOW_SEG_MAX]; 2128c2ecf20Sopenharmony_ci 2138c2ecf20Sopenharmony_ci /* software VSI handles referenced by this flow profile */ 2148c2ecf20Sopenharmony_ci DECLARE_BITMAP(vsis, ICE_MAX_VSI); 2158c2ecf20Sopenharmony_ci}; 2168c2ecf20Sopenharmony_ci 2178c2ecf20Sopenharmony_cistruct ice_rss_cfg { 2188c2ecf20Sopenharmony_ci struct list_head l_entry; 2198c2ecf20Sopenharmony_ci /* bitmap of VSIs added to the RSS entry */ 2208c2ecf20Sopenharmony_ci DECLARE_BITMAP(vsis, ICE_MAX_VSI); 2218c2ecf20Sopenharmony_ci u64 hashed_flds; 2228c2ecf20Sopenharmony_ci u32 packet_hdr; 2238c2ecf20Sopenharmony_ci}; 2248c2ecf20Sopenharmony_ci 2258c2ecf20Sopenharmony_cienum ice_status 2268c2ecf20Sopenharmony_ciice_flow_add_prof(struct ice_hw *hw, enum ice_block blk, enum ice_flow_dir dir, 2278c2ecf20Sopenharmony_ci u64 prof_id, struct ice_flow_seg_info *segs, u8 segs_cnt, 2288c2ecf20Sopenharmony_ci struct ice_flow_prof **prof); 2298c2ecf20Sopenharmony_cienum ice_status 2308c2ecf20Sopenharmony_ciice_flow_rem_prof(struct ice_hw *hw, enum ice_block blk, u64 prof_id); 2318c2ecf20Sopenharmony_cienum ice_status 2328c2ecf20Sopenharmony_ciice_flow_add_entry(struct ice_hw *hw, enum ice_block blk, u64 prof_id, 2338c2ecf20Sopenharmony_ci u64 entry_id, u16 vsi, enum ice_flow_priority prio, 2348c2ecf20Sopenharmony_ci void *data, u64 *entry_h); 2358c2ecf20Sopenharmony_cienum ice_status 2368c2ecf20Sopenharmony_ciice_flow_rem_entry(struct ice_hw *hw, enum ice_block blk, u64 entry_h); 2378c2ecf20Sopenharmony_civoid 2388c2ecf20Sopenharmony_ciice_flow_set_fld(struct ice_flow_seg_info *seg, enum ice_flow_field fld, 2398c2ecf20Sopenharmony_ci u16 val_loc, u16 mask_loc, u16 last_loc, bool range); 2408c2ecf20Sopenharmony_civoid 2418c2ecf20Sopenharmony_ciice_flow_add_fld_raw(struct ice_flow_seg_info *seg, u16 off, u8 len, 2428c2ecf20Sopenharmony_ci u16 val_loc, u16 mask_loc); 2438c2ecf20Sopenharmony_civoid ice_rem_vsi_rss_list(struct ice_hw *hw, u16 vsi_handle); 2448c2ecf20Sopenharmony_cienum ice_status ice_replay_rss_cfg(struct ice_hw *hw, u16 vsi_handle); 2458c2ecf20Sopenharmony_cienum ice_status 2468c2ecf20Sopenharmony_ciice_add_avf_rss_cfg(struct ice_hw *hw, u16 vsi_handle, u64 hashed_flds); 2478c2ecf20Sopenharmony_cienum ice_status ice_rem_vsi_rss_cfg(struct ice_hw *hw, u16 vsi_handle); 2488c2ecf20Sopenharmony_cienum ice_status 2498c2ecf20Sopenharmony_ciice_add_rss_cfg(struct ice_hw *hw, u16 vsi_handle, u64 hashed_flds, 2508c2ecf20Sopenharmony_ci u32 addl_hdrs); 2518c2ecf20Sopenharmony_ciu64 ice_get_rss_cfg(struct ice_hw *hw, u16 vsi_handle, u32 hdrs); 2528c2ecf20Sopenharmony_ci#endif /* _ICE_FLOW_H_ */ 253