1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* Copyright (C) 2018-2020, Intel Corporation. */ 3 4 #ifndef _ICE_FDIR_H_ 5 #define _ICE_FDIR_H_ 6 7 #define ICE_FDIR_TUN_PKT_OFF 50 8 #define ICE_FDIR_MAX_RAW_PKT_SIZE (512 + ICE_FDIR_TUN_PKT_OFF) 9 10 /* macros for offsets into packets for flow director programming */ 11 #define ICE_ETH_TYPE_F_OFFSET 12 12 #define ICE_ETH_VLAN_TCI_OFFSET 14 13 #define ICE_ETH_TYPE_VLAN_OFFSET 16 14 #define ICE_IPV4_SRC_ADDR_OFFSET 26 15 #define ICE_IPV4_DST_ADDR_OFFSET 30 16 #define ICE_IPV4_TCP_SRC_PORT_OFFSET 34 17 #define ICE_IPV4_TCP_DST_PORT_OFFSET 36 18 #define ICE_IPV4_UDP_SRC_PORT_OFFSET 34 19 #define ICE_IPV4_UDP_DST_PORT_OFFSET 36 20 #define ICE_IPV4_SCTP_SRC_PORT_OFFSET 34 21 #define ICE_IPV4_SCTP_DST_PORT_OFFSET 36 22 #define ICE_IPV4_PROTO_OFFSET 23 23 #define ICE_IPV6_SRC_ADDR_OFFSET 22 24 #define ICE_IPV6_DST_ADDR_OFFSET 38 25 #define ICE_IPV6_TCP_SRC_PORT_OFFSET 54 26 #define ICE_IPV6_TCP_DST_PORT_OFFSET 56 27 #define ICE_IPV6_UDP_SRC_PORT_OFFSET 54 28 #define ICE_IPV6_UDP_DST_PORT_OFFSET 56 29 #define ICE_IPV6_SCTP_SRC_PORT_OFFSET 54 30 #define ICE_IPV6_SCTP_DST_PORT_OFFSET 56 31 #define ICE_MAC_ETHTYPE_OFFSET 12 32 #define ICE_IPV4_TOS_OFFSET 15 33 #define ICE_IPV4_TTL_OFFSET 22 34 #define ICE_IPV6_TC_OFFSET 14 35 #define ICE_IPV6_HLIM_OFFSET 21 36 #define ICE_IPV6_PROTO_OFFSET 20 37 #define ICE_IPV4_GTPU_TEID_OFFSET 46 38 #define ICE_IPV4_GTPU_QFI_OFFSET 56 39 #define ICE_IPV4_L2TPV3_SESS_ID_OFFSET 34 40 #define ICE_IPV6_L2TPV3_SESS_ID_OFFSET 54 41 #define ICE_IPV4_ESP_SPI_OFFSET 34 42 #define ICE_IPV6_ESP_SPI_OFFSET 54 43 #define ICE_IPV4_AH_SPI_OFFSET 38 44 #define ICE_IPV6_AH_SPI_OFFSET 58 45 #define ICE_IPV4_NAT_T_ESP_SPI_OFFSET 42 46 #define ICE_IPV6_NAT_T_ESP_SPI_OFFSET 62 47 48 #define ICE_FDIR_MAX_FLTRS 16384 49 50 /* IP v4 has 2 flag bits that enable fragment processing: DF and MF. DF 51 * requests that the packet not be fragmented. MF indicates that a packet has 52 * been fragmented. 53 */ 54 #define ICE_FDIR_IPV4_PKT_FLAG_MF 0x20 55 56 enum ice_fltr_prgm_desc_dest { 57 ICE_FLTR_PRGM_DESC_DEST_DROP_PKT, 58 ICE_FLTR_PRGM_DESC_DEST_DIRECT_PKT_QINDEX, 59 ICE_FLTR_PRGM_DESC_DEST_DIRECT_PKT_QGROUP, 60 ICE_FLTR_PRGM_DESC_DEST_DIRECT_PKT_OTHER, 61 }; 62 63 enum ice_fltr_prgm_desc_fd_status { 64 ICE_FLTR_PRGM_DESC_FD_STATUS_NONE, 65 ICE_FLTR_PRGM_DESC_FD_STATUS_FD_ID, 66 }; 67 68 /* Flow Director (FD) Filter Programming descriptor */ 69 struct ice_fd_fltr_desc_ctx { 70 u32 fdid; 71 u16 qindex; 72 u16 cnt_index; 73 u16 fd_vsi; 74 u16 flex_val; 75 u8 comp_q; 76 u8 comp_report; 77 u8 fd_space; 78 u8 cnt_ena; 79 u8 evict_ena; 80 u8 toq; 81 u8 toq_prio; 82 u8 dpu_recipe; 83 u8 drop; 84 u8 flex_prio; 85 u8 flex_mdid; 86 u8 dtype; 87 u8 pcmd; 88 u8 desc_prof_prio; 89 u8 desc_prof; 90 u8 swap; 91 u8 fdid_prio; 92 u8 fdid_mdid; 93 }; 94 95 #define ICE_FLTR_PRGM_FLEX_WORD_SIZE sizeof(__be16) 96 97 struct ice_rx_flow_userdef { 98 u16 flex_word; 99 u16 flex_offset; 100 u16 flex_fltr; 101 }; 102 103 struct ice_fdir_v4 { 104 __be32 dst_ip; 105 __be32 src_ip; 106 __be16 dst_port; 107 __be16 src_port; 108 __be32 l4_header; 109 __be32 sec_parm_idx; /* security parameter index */ 110 u8 tos; 111 u8 ip_ver; 112 u8 proto; 113 u8 ttl; 114 }; 115 116 #define ICE_IPV6_ADDR_LEN_AS_U32 4 117 118 struct ice_fdir_v6 { 119 __be32 dst_ip[ICE_IPV6_ADDR_LEN_AS_U32]; 120 __be32 src_ip[ICE_IPV6_ADDR_LEN_AS_U32]; 121 __be16 dst_port; 122 __be16 src_port; 123 __be32 l4_header; /* next header */ 124 __be32 sec_parm_idx; /* security parameter index */ 125 u8 tc; 126 u8 proto; 127 u8 hlim; 128 }; 129 130 struct ice_fdir_udp_gtp { 131 u8 flags; 132 u8 msg_type; 133 __be16 rsrvd_len; 134 __be32 teid; 135 __be16 rsrvd_seq_nbr; 136 u8 rsrvd_n_pdu_nbr; 137 u8 rsrvd_next_ext_type; 138 u8 rsvrd_ext_len; 139 u8 pdu_type:4, 140 spare:4; 141 u8 ppp:1, 142 rqi:1, 143 qfi:6; 144 u32 rsvrd; 145 u8 next_ext; 146 }; 147 148 struct ice_fdir_l2tpv3 { 149 __be32 session_id; 150 }; 151 152 struct ice_fdir_extra { 153 u8 dst_mac[ETH_ALEN]; /* dest MAC address */ 154 u8 src_mac[ETH_ALEN]; /* src MAC address */ 155 __be16 ether_type; /* for NON_IP_L2 */ 156 u32 usr_def[2]; /* user data */ 157 __be16 vlan_type; /* VLAN ethertype */ 158 __be16 vlan_tag; /* VLAN tag info */ 159 }; 160 161 struct ice_fdir_fltr { 162 struct list_head fltr_node; 163 enum ice_fltr_ptype flow_type; 164 165 struct ethhdr eth, eth_mask; 166 167 union { 168 struct ice_fdir_v4 v4; 169 struct ice_fdir_v6 v6; 170 } ip, mask; 171 172 struct ice_fdir_udp_gtp gtpu_data; 173 struct ice_fdir_udp_gtp gtpu_mask; 174 175 struct ice_fdir_l2tpv3 l2tpv3_data; 176 struct ice_fdir_l2tpv3 l2tpv3_mask; 177 178 struct ice_fdir_extra ext_data; 179 struct ice_fdir_extra ext_mask; 180 181 /* flex byte filter data */ 182 __be16 flex_word; 183 /* queue region size (=2^q_region) */ 184 u8 q_region; 185 u16 flex_offset; 186 u16 flex_fltr; 187 188 /* filter control */ 189 u16 q_index; 190 u16 orig_q_index; 191 u16 dest_vsi; 192 u8 dest_ctl; 193 u8 cnt_ena; 194 u8 fltr_status; 195 u16 cnt_index; 196 u32 fltr_id; 197 u8 fdid_prio; 198 u8 comp_report; 199 }; 200 201 /* Dummy packet filter definition structure */ 202 struct ice_fdir_base_pkt { 203 enum ice_fltr_ptype flow; 204 u16 pkt_len; 205 const u8 *pkt; 206 u16 tun_pkt_len; 207 const u8 *tun_pkt; 208 }; 209 210 struct ice_vsi; 211 212 int ice_alloc_fd_res_cntr(struct ice_hw *hw, u16 *cntr_id); 213 int ice_free_fd_res_cntr(struct ice_hw *hw, u16 cntr_id); 214 int ice_alloc_fd_guar_item(struct ice_hw *hw, u16 *cntr_id, u16 num_fltr); 215 int ice_alloc_fd_shrd_item(struct ice_hw *hw, u16 *cntr_id, u16 num_fltr); 216 void 217 ice_fdir_get_prgm_desc(struct ice_hw *hw, struct ice_fdir_fltr *input, 218 struct ice_fltr_desc *fdesc, bool add); 219 int 220 ice_fdir_get_gen_prgm_pkt(struct ice_hw *hw, struct ice_fdir_fltr *input, 221 u8 *pkt, bool frag, bool tun); 222 int ice_get_fdir_cnt_all(struct ice_hw *hw); 223 int ice_fdir_num_avail_fltr(struct ice_hw *hw, struct ice_vsi *vsi); 224 bool ice_fdir_is_dup_fltr(struct ice_hw *hw, struct ice_fdir_fltr *input); 225 bool ice_fdir_has_frag(enum ice_fltr_ptype flow); 226 struct ice_fdir_fltr * 227 ice_fdir_find_fltr_by_idx(struct ice_hw *hw, u32 fltr_idx); 228 void 229 ice_fdir_update_cntrs(struct ice_hw *hw, enum ice_fltr_ptype flow, bool add); 230 void ice_fdir_list_add_fltr(struct ice_hw *hw, struct ice_fdir_fltr *input); 231 #endif /* _ICE_FDIR_H_ */ 232