1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright(c) 2001-2019 3 */ 4 5 #ifndef _ICE_FDIR_H_ 6 #define _ICE_FDIR_H_ 7 8 #include "ice_common.h" 9 10 /* Flow Director (FD) Filter Programming descriptor */ 11 struct ice_fd_fltr_desc_ctx { 12 u32 fdid; 13 u16 qindex; 14 u16 cnt_index; 15 u16 fd_vsi; 16 u16 flex_val; 17 u8 comp_q; 18 u8 comp_report; 19 u8 fd_space; 20 u8 cnt_ena; 21 u8 evict_ena; 22 u8 toq; 23 u8 toq_prio; 24 u8 dpu_recipe; 25 u8 drop; 26 u8 flex_prio; 27 u8 flex_mdid; 28 u8 dtype; 29 u8 pcmd; 30 u8 desc_prof_prio; 31 u8 desc_prof; 32 u8 swap; 33 u8 fdid_prio; 34 u8 fdid_mdid; 35 }; 36 37 enum ice_status ice_alloc_fd_res_cntr(struct ice_hw *hw, u16 *cntr_id); 38 enum ice_status ice_free_fd_res_cntr(struct ice_hw *hw, u16 cntr_id); 39 void 40 ice_set_fd_desc_val(struct ice_fd_fltr_desc_ctx *fd_fltr_ctx, 41 struct ice_fltr_desc *fdir_desc); 42 void ice_set_dflt_val_fd_desc(struct ice_fd_fltr_desc_ctx *fd_fltr_ctx); 43 enum ice_status 44 ice_alloc_fd_guar_item(struct ice_hw *hw, u16 *cntr_id, u16 num_fltr); 45 enum ice_status 46 ice_free_fd_guar_item(struct ice_hw *hw, u16 cntr_id, u16 num_fltr); 47 enum ice_status 48 ice_alloc_fd_shrd_item(struct ice_hw *hw, u16 *cntr_id, u16 num_fltr); 49 enum ice_status 50 ice_free_fd_shrd_item(struct ice_hw *hw, u16 cntr_id, u16 num_fltr); 51 enum ice_status ice_clear_vsi_fd_table(struct ice_hw *hw, u16 vsi_num); 52 enum ice_status ice_clear_pf_fd_table(struct ice_hw *hw); 53 54 #define ICE_FDIR_IP_PROTOCOLS 55 #define ICE_IP_PROTO_TCP 6 56 #define ICE_IP_PROTO_UDP 17 57 #define ICE_IP_PROTO_SCTP 132 58 #define ICE_IP_PROTO_IP 0 59 #define ICE_IP_PROTO_ESP 50 60 61 #define ICE_FDIR_MAX_RAW_PKT_SIZE 512 62 #define ICE_FDIR_BUF_FULL_MARGIN 10 63 #define ICE_FDIR_BUF_HEAD_ROOM 32 64 65 /* macros for offsets into packets for flow director programming */ 66 #define ICE_IPV4_SRC_ADDR_OFFSET 26 67 #define ICE_IPV4_DST_ADDR_OFFSET 30 68 #define ICE_IPV4_TCP_SRC_PORT_OFFSET 34 69 #define ICE_IPV4_TCP_DST_PORT_OFFSET 36 70 #define ICE_IPV4_UDP_SRC_PORT_OFFSET 34 71 #define ICE_IPV4_UDP_DST_PORT_OFFSET 36 72 #define ICE_IPV4_SCTP_SRC_PORT_OFFSET 34 73 #define ICE_IPV4_SCTP_DST_PORT_OFFSET 36 74 #define ICE_IPV4_PROTO_OFFSET 23 75 #define ICE_IPV6_SRC_ADDR_OFFSET 22 76 #define ICE_IPV6_DST_ADDR_OFFSET 38 77 #define ICE_IPV6_TCP_SRC_PORT_OFFSET 54 78 #define ICE_IPV6_TCP_DST_PORT_OFFSET 56 79 #define ICE_IPV6_UDP_SRC_PORT_OFFSET 54 80 #define ICE_IPV6_UDP_DST_PORT_OFFSET 56 81 #define ICE_IPV6_SCTP_SRC_PORT_OFFSET 54 82 #define ICE_IPV6_SCTP_DST_PORT_OFFSET 56 83 84 #define ICE_FDIR_MAX_FLTRS 16384 85 86 /* IP v4 has 2 flag bits that enable fragment processing: DF and MF. DF 87 * requests that the packet not be fragmented. MF indicates that a packet has 88 * been fragmented. 89 */ 90 #define ICE_FDIR_IPV4_PKT_FLAG_DF 0x20 91 #define ICE_FDIR_IPV4_PKT_FLAG_MF 0x40 92 93 enum ice_fltr_prgm_desc_dest { 94 ICE_FLTR_PRGM_DESC_DEST_DROP_PKT, 95 ICE_FLTR_PRGM_DESC_DEST_DIRECT_PKT_QINDEX, 96 ICE_FLTR_PRGM_DESC_DEST_DIRECT_PKT_QGROUP, 97 ICE_FLTR_PRGM_DESC_DEST_DIRECT_PKT_OTHER, 98 }; 99 100 enum ice_fltr_prgm_desc_fd_status { 101 ICE_FLTR_PRGM_DESC_FD_STATUS_NONE, 102 ICE_FLTR_PRGM_DESC_FD_STATUS_FD_ID, 103 ICE_FLTR_PRGM_DESC_FD_STATUS_FD_ID_4FLEX_BYTES, 104 ICE_FLTR_PRGM_DESC_FD_STATUS_8FLEX_BYTES, 105 }; 106 107 #define ICE_FLTR_PRGM_FLEX_WORD_SIZE sizeof(__be16) 108 109 struct ice_rx_flow_userdef { 110 u16 flex_word; 111 u16 flex_offset; 112 u16 flex_fltr; 113 }; 114 115 struct ice_fdir_v4 { 116 __be32 dst_ip; 117 __be32 src_ip; 118 __be16 dst_port; 119 __be16 src_port; 120 __be32 l4_header; 121 __be32 sec_parm_idx; /* security parameter index */ 122 u8 tos; 123 u8 ip_ver; 124 u8 proto; 125 }; 126 127 #define ICE_IPV6_ADDR_LEN_AS_U32 4 128 129 struct ice_fdir_v6 { 130 __be32 dst_ip[ICE_IPV6_ADDR_LEN_AS_U32]; 131 __be32 src_ip[ICE_IPV6_ADDR_LEN_AS_U32]; 132 __be16 dst_port; 133 __be16 src_port; 134 __be32 l4_header; /* next header */ 135 __be32 sec_parm_idx; /* security parameter index */ 136 u8 tc; 137 u8 proto; 138 }; 139 140 struct ice_fdir_extra { 141 u8 dst_mac[ETH_ALEN]; /* dest MAC address */ 142 u32 usr_def[2]; /* user data */ 143 __be16 vlan_type; /* VLAN ethertype */ 144 __be16 vlan_tag; /* VLAN tag info */ 145 }; 146 147 struct ice_fdir_fltr { 148 struct LIST_ENTRY_TYPE fltr_node; 149 enum ice_fltr_ptype flow_type; 150 151 union { 152 struct ice_fdir_v4 v4; 153 struct ice_fdir_v6 v6; 154 } ip, mask; 155 156 struct ice_fdir_extra ext_data; 157 struct ice_fdir_extra ext_mask; 158 159 /* flex byte filter data */ 160 __be16 flex_word; 161 u16 flex_offset; 162 u16 flex_fltr; 163 164 /* filter control */ 165 u16 q_index; 166 #ifdef ADQ_SUPPORT 167 u16 orig_q_index; 168 #endif /* ADQ_SUPPORT */ 169 u16 dest_vsi; 170 u8 dest_ctl; 171 u8 fltr_status; 172 u16 cnt_index; 173 u32 fltr_id; 174 }; 175 176 177 /* Dummy packet filter definition structure. */ 178 struct ice_fdir_base_pkt { 179 enum ice_fltr_ptype flow; 180 u16 pkt_len; 181 const u8 *pkt; 182 }; 183 184 void 185 ice_fdir_get_prgm_desc(struct ice_hw *hw, struct ice_fdir_fltr *input, 186 struct ice_fltr_desc *fdesc, bool add); 187 enum ice_status 188 ice_fdir_get_prgm_pkt(struct ice_fdir_fltr *input, u8 *pkt, bool frag); 189 enum ice_status 190 ice_add_del_fdir(struct ice_hw *hw, struct ice_fdir_fltr *input, bool add); 191 int ice_get_fdir_cnt_all(struct ice_hw *hw); 192 bool ice_fdir_is_dup_fltr(struct ice_hw *hw, struct ice_fdir_fltr *input); 193 enum ice_status 194 ice_update_fdir_list_entry(struct ice_hw *hw, struct ice_fdir_fltr *input, 195 u16 sw_idx); 196 bool ice_fdir_has_frag(enum ice_fltr_ptype flow); 197 struct ice_fdir_fltr * 198 ice_fdir_find_fltr_by_idx(struct ice_hw *hw, u32 fltr_idx); 199 void 200 ice_fdir_update_cntrs(struct ice_hw *hw, enum ice_fltr_ptype flow, bool add); 201 void ice_fdir_list_add_fltr(struct ice_hw *hw, struct ice_fdir_fltr *input); 202 #endif /* _ICE_FDIR_H_ */ 203