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_IPV4_SRC_ADDR_OFFSET 26 12 #define ICE_IPV4_DST_ADDR_OFFSET 30 13 #define ICE_IPV4_TCP_SRC_PORT_OFFSET 34 14 #define ICE_IPV4_TCP_DST_PORT_OFFSET 36 15 #define ICE_IPV4_UDP_SRC_PORT_OFFSET 34 16 #define ICE_IPV4_UDP_DST_PORT_OFFSET 36 17 #define ICE_IPV4_SCTP_SRC_PORT_OFFSET 34 18 #define ICE_IPV4_SCTP_DST_PORT_OFFSET 36 19 #define ICE_IPV4_PROTO_OFFSET 23 20 #define ICE_IPV6_SRC_ADDR_OFFSET 22 21 #define ICE_IPV6_DST_ADDR_OFFSET 38 22 #define ICE_IPV6_TCP_SRC_PORT_OFFSET 54 23 #define ICE_IPV6_TCP_DST_PORT_OFFSET 56 24 #define ICE_IPV6_UDP_SRC_PORT_OFFSET 54 25 #define ICE_IPV6_UDP_DST_PORT_OFFSET 56 26 #define ICE_IPV6_SCTP_SRC_PORT_OFFSET 54 27 #define ICE_IPV6_SCTP_DST_PORT_OFFSET 56 28 /* IP v4 has 2 flag bits that enable fragment processing: DF and MF. DF 29 * requests that the packet not be fragmented. MF indicates that a packet has 30 * been fragmented. 31 */ 32 #define ICE_FDIR_IPV4_PKT_FLAG_DF 0x20 33 34 enum ice_fltr_prgm_desc_dest { 35 ICE_FLTR_PRGM_DESC_DEST_DROP_PKT, 36 ICE_FLTR_PRGM_DESC_DEST_DIRECT_PKT_QINDEX, 37 }; 38 39 enum ice_fltr_prgm_desc_fd_status { 40 ICE_FLTR_PRGM_DESC_FD_STATUS_NONE, 41 ICE_FLTR_PRGM_DESC_FD_STATUS_FD_ID, 42 }; 43 44 /* Flow Director (FD) Filter Programming descriptor */ 45 struct ice_fd_fltr_desc_ctx { 46 u32 fdid; 47 u16 qindex; 48 u16 cnt_index; 49 u16 fd_vsi; 50 u16 flex_val; 51 u8 comp_q; 52 u8 comp_report; 53 u8 fd_space; 54 u8 cnt_ena; 55 u8 evict_ena; 56 u8 toq; 57 u8 toq_prio; 58 u8 dpu_recipe; 59 u8 drop; 60 u8 flex_prio; 61 u8 flex_mdid; 62 u8 dtype; 63 u8 pcmd; 64 u8 desc_prof_prio; 65 u8 desc_prof; 66 u8 swap; 67 u8 fdid_prio; 68 u8 fdid_mdid; 69 }; 70 71 #define ICE_FLTR_PRGM_FLEX_WORD_SIZE sizeof(__be16) 72 73 struct ice_rx_flow_userdef { 74 u16 flex_word; 75 u16 flex_offset; 76 u16 flex_fltr; 77 }; 78 79 struct ice_fdir_v4 { 80 __be32 dst_ip; 81 __be32 src_ip; 82 __be16 dst_port; 83 __be16 src_port; 84 __be32 l4_header; 85 __be32 sec_parm_idx; /* security parameter index */ 86 u8 tos; 87 u8 ip_ver; 88 u8 proto; 89 }; 90 91 #define ICE_IPV6_ADDR_LEN_AS_U32 4 92 93 struct ice_fdir_v6 { 94 __be32 dst_ip[ICE_IPV6_ADDR_LEN_AS_U32]; 95 __be32 src_ip[ICE_IPV6_ADDR_LEN_AS_U32]; 96 __be16 dst_port; 97 __be16 src_port; 98 __be32 l4_header; /* next header */ 99 __be32 sec_parm_idx; /* security parameter index */ 100 u8 tc; 101 u8 proto; 102 }; 103 104 struct ice_fdir_extra { 105 u8 dst_mac[ETH_ALEN]; /* dest MAC address */ 106 u32 usr_def[2]; /* user data */ 107 __be16 vlan_type; /* VLAN ethertype */ 108 __be16 vlan_tag; /* VLAN tag info */ 109 }; 110 111 struct ice_fdir_fltr { 112 struct list_head fltr_node; 113 enum ice_fltr_ptype flow_type; 114 115 union { 116 struct ice_fdir_v4 v4; 117 struct ice_fdir_v6 v6; 118 } ip, mask; 119 120 struct ice_fdir_extra ext_data; 121 struct ice_fdir_extra ext_mask; 122 123 /* flex byte filter data */ 124 __be16 flex_word; 125 u16 flex_offset; 126 u16 flex_fltr; 127 128 /* filter control */ 129 u16 q_index; 130 u16 dest_vsi; 131 u8 dest_ctl; 132 u8 fltr_status; 133 u16 cnt_index; 134 u32 fltr_id; 135 }; 136 137 /* Dummy packet filter definition structure */ 138 struct ice_fdir_base_pkt { 139 enum ice_fltr_ptype flow; 140 u16 pkt_len; 141 const u8 *pkt; 142 u16 tun_pkt_len; 143 const u8 *tun_pkt; 144 }; 145 146 enum ice_status ice_alloc_fd_res_cntr(struct ice_hw *hw, u16 *cntr_id); 147 enum ice_status ice_free_fd_res_cntr(struct ice_hw *hw, u16 cntr_id); 148 enum ice_status 149 ice_alloc_fd_guar_item(struct ice_hw *hw, u16 *cntr_id, u16 num_fltr); 150 enum ice_status 151 ice_alloc_fd_shrd_item(struct ice_hw *hw, u16 *cntr_id, u16 num_fltr); 152 void 153 ice_fdir_get_prgm_desc(struct ice_hw *hw, struct ice_fdir_fltr *input, 154 struct ice_fltr_desc *fdesc, bool add); 155 enum ice_status 156 ice_fdir_get_gen_prgm_pkt(struct ice_hw *hw, struct ice_fdir_fltr *input, 157 u8 *pkt, bool frag, bool tun); 158 int ice_get_fdir_cnt_all(struct ice_hw *hw); 159 bool ice_fdir_is_dup_fltr(struct ice_hw *hw, struct ice_fdir_fltr *input); 160 bool ice_fdir_has_frag(enum ice_fltr_ptype flow); 161 struct ice_fdir_fltr * 162 ice_fdir_find_fltr_by_idx(struct ice_hw *hw, u32 fltr_idx); 163 void 164 ice_fdir_update_cntrs(struct ice_hw *hw, enum ice_fltr_ptype flow, bool add); 165 void ice_fdir_list_add_fltr(struct ice_hw *hw, struct ice_fdir_fltr *input); 166 #endif /* _ICE_FDIR_H_ */ 167