1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* Copyright (C) 2019-2021, Intel Corporation. */ 3 4 #ifndef _ICE_TC_LIB_H_ 5 #define _ICE_TC_LIB_H_ 6 7 #define ICE_TC_FLWR_FIELD_DST_MAC BIT(0) 8 #define ICE_TC_FLWR_FIELD_SRC_MAC BIT(1) 9 #define ICE_TC_FLWR_FIELD_VLAN BIT(2) 10 #define ICE_TC_FLWR_FIELD_DEST_IPV4 BIT(3) 11 #define ICE_TC_FLWR_FIELD_SRC_IPV4 BIT(4) 12 #define ICE_TC_FLWR_FIELD_DEST_IPV6 BIT(5) 13 #define ICE_TC_FLWR_FIELD_SRC_IPV6 BIT(6) 14 #define ICE_TC_FLWR_FIELD_DEST_L4_PORT BIT(7) 15 #define ICE_TC_FLWR_FIELD_SRC_L4_PORT BIT(8) 16 #define ICE_TC_FLWR_FIELD_TENANT_ID BIT(9) 17 #define ICE_TC_FLWR_FIELD_ENC_DEST_IPV4 BIT(10) 18 #define ICE_TC_FLWR_FIELD_ENC_SRC_IPV4 BIT(11) 19 #define ICE_TC_FLWR_FIELD_ENC_DEST_IPV6 BIT(12) 20 #define ICE_TC_FLWR_FIELD_ENC_SRC_IPV6 BIT(13) 21 #define ICE_TC_FLWR_FIELD_ENC_DEST_L4_PORT BIT(14) 22 #define ICE_TC_FLWR_FIELD_ENC_SRC_L4_PORT BIT(15) 23 #define ICE_TC_FLWR_FIELD_ENC_DST_MAC BIT(16) 24 #define ICE_TC_FLWR_FIELD_ETH_TYPE_ID BIT(17) 25 #define ICE_TC_FLWR_FIELD_ENC_OPTS BIT(18) 26 #define ICE_TC_FLWR_FIELD_CVLAN BIT(19) 27 #define ICE_TC_FLWR_FIELD_PPPOE_SESSID BIT(20) 28 #define ICE_TC_FLWR_FIELD_PPP_PROTO BIT(21) 29 #define ICE_TC_FLWR_FIELD_IP_TOS BIT(22) 30 #define ICE_TC_FLWR_FIELD_IP_TTL BIT(23) 31 #define ICE_TC_FLWR_FIELD_ENC_IP_TOS BIT(24) 32 #define ICE_TC_FLWR_FIELD_ENC_IP_TTL BIT(25) 33 #define ICE_TC_FLWR_FIELD_L2TPV3_SESSID BIT(26) 34 #define ICE_TC_FLWR_FIELD_VLAN_PRIO BIT(27) 35 #define ICE_TC_FLWR_FIELD_CVLAN_PRIO BIT(28) 36 #define ICE_TC_FLWR_FIELD_VLAN_TPID BIT(29) 37 38 #define ICE_TC_FLOWER_MASK_32 0xFFFFFFFF 39 40 #define ICE_IPV6_HDR_TC_MASK 0xFF00000 41 42 struct ice_indr_block_priv { 43 struct net_device *netdev; 44 struct ice_netdev_priv *np; 45 struct list_head list; 46 }; 47 48 struct ice_tc_flower_action { 49 /* forward action specific params */ 50 union { 51 struct { 52 u32 tc_class; /* forward to hw_tc */ 53 u32 rsvd; 54 } tc; 55 struct { 56 u16 queue; /* forward to queue */ 57 /* To add filter in HW, absolute queue number in global 58 * space of queues (between 0...N) is needed 59 */ 60 u16 hw_queue; 61 } q; 62 } fwd; 63 enum ice_sw_fwd_act_type fltr_act; 64 }; 65 66 struct ice_tc_vlan_hdr { 67 __be16 vlan_id; /* Only last 12 bits valid */ 68 __be16 vlan_prio; /* Only last 3 bits valid (valid values: 0..7) */ 69 __be16 vlan_tpid; 70 }; 71 72 struct ice_tc_pppoe_hdr { 73 __be16 session_id; 74 __be16 ppp_proto; 75 }; 76 77 struct ice_tc_l2_hdr { 78 u8 dst_mac[ETH_ALEN]; 79 u8 src_mac[ETH_ALEN]; 80 __be16 n_proto; /* Ethernet Protocol */ 81 }; 82 83 struct ice_tc_l3_hdr { 84 u8 ip_proto; /* IPPROTO value */ 85 union { 86 struct { 87 struct in_addr dst_ip; 88 struct in_addr src_ip; 89 } v4; 90 struct { 91 struct in6_addr dst_ip6; 92 struct in6_addr src_ip6; 93 } v6; 94 } ip; 95 #define dst_ipv6 ip.v6.dst_ip6.s6_addr32 96 #define dst_ipv6_addr ip.v6.dst_ip6.s6_addr 97 #define src_ipv6 ip.v6.src_ip6.s6_addr32 98 #define src_ipv6_addr ip.v6.src_ip6.s6_addr 99 #define dst_ipv4 ip.v4.dst_ip.s_addr 100 #define src_ipv4 ip.v4.src_ip.s_addr 101 102 u8 tos; 103 u8 ttl; 104 }; 105 106 struct ice_tc_l2tpv3_hdr { 107 __be32 session_id; 108 }; 109 110 struct ice_tc_l4_hdr { 111 __be16 dst_port; 112 __be16 src_port; 113 }; 114 115 struct ice_tc_flower_lyr_2_4_hdrs { 116 /* L2 layer fields with their mask */ 117 struct ice_tc_l2_hdr l2_key; 118 struct ice_tc_l2_hdr l2_mask; 119 struct ice_tc_vlan_hdr vlan_hdr; 120 struct ice_tc_vlan_hdr cvlan_hdr; 121 struct ice_tc_pppoe_hdr pppoe_hdr; 122 struct ice_tc_l2tpv3_hdr l2tpv3_hdr; 123 /* L3 (IPv4[6]) layer fields with their mask */ 124 struct ice_tc_l3_hdr l3_key; 125 struct ice_tc_l3_hdr l3_mask; 126 127 /* L4 layer fields with their mask */ 128 struct ice_tc_l4_hdr l4_key; 129 struct ice_tc_l4_hdr l4_mask; 130 }; 131 132 enum ice_eswitch_fltr_direction { 133 ICE_ESWITCH_FLTR_INGRESS, 134 ICE_ESWITCH_FLTR_EGRESS, 135 }; 136 137 struct ice_tc_flower_fltr { 138 struct hlist_node tc_flower_node; 139 140 /* cookie becomes filter_rule_id if rule is added successfully */ 141 unsigned long cookie; 142 143 /* add_adv_rule returns information like recipe ID, rule_id. Store 144 * those values since they are needed to remove advanced rule 145 */ 146 u16 rid; 147 u16 rule_id; 148 /* VSI handle of the destination VSI (it could be main PF VSI, CHNL_VSI, 149 * VF VSI) 150 */ 151 u16 dest_vsi_handle; 152 /* ptr to destination VSI */ 153 struct ice_vsi *dest_vsi; 154 /* direction of fltr for eswitch use case */ 155 enum ice_eswitch_fltr_direction direction; 156 157 /* Parsed TC flower configuration params */ 158 struct ice_tc_flower_lyr_2_4_hdrs outer_headers; 159 struct ice_tc_flower_lyr_2_4_hdrs inner_headers; 160 struct ice_vsi *src_vsi; 161 __be32 tenant_id; 162 struct gtp_pdu_session_info gtp_pdu_info_keys; 163 struct gtp_pdu_session_info gtp_pdu_info_masks; 164 u32 flags; 165 u8 tunnel_type; 166 struct ice_tc_flower_action action; 167 168 /* cache ptr which is used wherever needed to communicate netlink 169 * messages 170 */ 171 struct netlink_ext_ack *extack; 172 }; 173 174 /** 175 * ice_is_chnl_fltr - is this a valid channel filter 176 * @f: Pointer to tc-flower filter 177 * 178 * Criteria to determine of given filter is valid channel filter 179 * or not is based on its destination. 180 * For forward to VSI action, if destination is valid hw_tc (aka tc_class) 181 * and in supported range of TCs for ADQ, then return true. 182 * For forward to queue, as long as dest_vsi is valid and it is of type 183 * VSI_CHNL (PF ADQ VSI is of type VSI_CHNL), return true. 184 * NOTE: For forward to queue, correct dest_vsi is still set in tc_fltr based 185 * on destination queue specified. 186 */ 187 static inline bool ice_is_chnl_fltr(struct ice_tc_flower_fltr *f) 188 { 189 if (f->action.fltr_act == ICE_FWD_TO_VSI) 190 return f->action.fwd.tc.tc_class >= ICE_CHNL_START_TC && 191 f->action.fwd.tc.tc_class < ICE_CHNL_MAX_TC; 192 else if (f->action.fltr_act == ICE_FWD_TO_Q) 193 return f->dest_vsi && f->dest_vsi->type == ICE_VSI_CHNL; 194 195 return false; 196 } 197 198 /** 199 * ice_chnl_dmac_fltr_cnt - DMAC based CHNL filter count 200 * @pf: Pointer to PF 201 */ 202 static inline int ice_chnl_dmac_fltr_cnt(struct ice_pf *pf) 203 { 204 return pf->num_dmac_chnl_fltrs; 205 } 206 207 struct ice_vsi *ice_locate_vsi_using_queue(struct ice_vsi *vsi, int queue); 208 int 209 ice_add_cls_flower(struct net_device *netdev, struct ice_vsi *vsi, 210 struct flow_cls_offload *cls_flower); 211 int 212 ice_del_cls_flower(struct ice_vsi *vsi, struct flow_cls_offload *cls_flower); 213 void ice_replay_tc_fltrs(struct ice_pf *pf); 214 bool ice_is_tunnel_supported(struct net_device *dev); 215 216 static inline bool ice_is_forward_action(enum ice_sw_fwd_act_type fltr_act) 217 { 218 switch (fltr_act) { 219 case ICE_FWD_TO_VSI: 220 case ICE_FWD_TO_Q: 221 return true; 222 default: 223 return false; 224 } 225 } 226 #endif /* _ICE_TC_LIB_H_ */ 227