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 
26 #define ICE_TC_FLOWER_MASK_32   0xFFFFFFFF
27 
28 struct ice_indr_block_priv {
29 	struct net_device *netdev;
30 	struct ice_netdev_priv *np;
31 	struct list_head list;
32 };
33 
34 struct ice_tc_flower_action {
35 	u32 tc_class;
36 	enum ice_sw_fwd_act_type fltr_act;
37 };
38 
39 struct ice_tc_vlan_hdr {
40 	__be16 vlan_id; /* Only last 12 bits valid */
41 	u16 vlan_prio; /* Only last 3 bits valid (valid values: 0..7) */
42 };
43 
44 struct ice_tc_l2_hdr {
45 	u8 dst_mac[ETH_ALEN];
46 	u8 src_mac[ETH_ALEN];
47 	__be16 n_proto;    /* Ethernet Protocol */
48 };
49 
50 struct ice_tc_l3_hdr {
51 	u8 ip_proto;    /* IPPROTO value */
52 	union {
53 		struct {
54 			struct in_addr dst_ip;
55 			struct in_addr src_ip;
56 		} v4;
57 		struct {
58 			struct in6_addr dst_ip6;
59 			struct in6_addr src_ip6;
60 		} v6;
61 	} ip;
62 #define dst_ipv6	ip.v6.dst_ip6.s6_addr32
63 #define dst_ipv6_addr	ip.v6.dst_ip6.s6_addr
64 #define src_ipv6	ip.v6.src_ip6.s6_addr32
65 #define src_ipv6_addr	ip.v6.src_ip6.s6_addr
66 #define dst_ipv4	ip.v4.dst_ip.s_addr
67 #define src_ipv4	ip.v4.src_ip.s_addr
68 
69 	u8 tos;
70 	u8 ttl;
71 };
72 
73 struct ice_tc_l4_hdr {
74 	__be16 dst_port;
75 	__be16 src_port;
76 };
77 
78 struct ice_tc_flower_lyr_2_4_hdrs {
79 	/* L2 layer fields with their mask */
80 	struct ice_tc_l2_hdr l2_key;
81 	struct ice_tc_l2_hdr l2_mask;
82 	struct ice_tc_vlan_hdr vlan_hdr;
83 	/* L3 (IPv4[6]) layer fields with their mask */
84 	struct ice_tc_l3_hdr l3_key;
85 	struct ice_tc_l3_hdr l3_mask;
86 
87 	/* L4 layer fields with their mask */
88 	struct ice_tc_l4_hdr l4_key;
89 	struct ice_tc_l4_hdr l4_mask;
90 };
91 
92 enum ice_eswitch_fltr_direction {
93 	ICE_ESWITCH_FLTR_INGRESS,
94 	ICE_ESWITCH_FLTR_EGRESS,
95 };
96 
97 struct ice_tc_flower_fltr {
98 	struct hlist_node tc_flower_node;
99 
100 	/* cookie becomes filter_rule_id if rule is added successfully */
101 	unsigned long cookie;
102 
103 	/* add_adv_rule returns information like recipe ID, rule_id. Store
104 	 * those values since they are needed to remove advanced rule
105 	 */
106 	u16 rid;
107 	u16 rule_id;
108 	/* this could be queue/vsi_idx (sw handle)/queue_group, depending upon
109 	 * destination type
110 	 */
111 	u16 dest_id;
112 	/* if dest_id is vsi_idx, then need to store destination VSI ptr */
113 	struct ice_vsi *dest_vsi;
114 	/* direction of fltr for eswitch use case */
115 	enum ice_eswitch_fltr_direction direction;
116 
117 	/* Parsed TC flower configuration params */
118 	struct ice_tc_flower_lyr_2_4_hdrs outer_headers;
119 	struct ice_tc_flower_lyr_2_4_hdrs inner_headers;
120 	struct ice_vsi *src_vsi;
121 	__be32 tenant_id;
122 	u32 flags;
123 	u8 tunnel_type;
124 	struct ice_tc_flower_action	action;
125 
126 	/* cache ptr which is used wherever needed to communicate netlink
127 	 * messages
128 	 */
129 	struct netlink_ext_ack *extack;
130 };
131 
132 /**
133  * ice_is_chnl_fltr - is this a valid channel filter
134  * @f: Pointer to tc-flower filter
135  *
136  * Criteria to determine of given filter is valid channel filter
137  * or not is based on its "destination". If destination is hw_tc (aka tc_class)
138  * and it is non-zero, then it is valid channel (aka ADQ) filter
139  */
140 static inline bool ice_is_chnl_fltr(struct ice_tc_flower_fltr *f)
141 {
142 	return !!f->action.tc_class;
143 }
144 
145 /**
146  * ice_chnl_dmac_fltr_cnt - DMAC based CHNL filter count
147  * @pf: Pointer to PF
148  */
149 static inline int ice_chnl_dmac_fltr_cnt(struct ice_pf *pf)
150 {
151 	return pf->num_dmac_chnl_fltrs;
152 }
153 
154 int
155 ice_add_cls_flower(struct net_device *netdev, struct ice_vsi *vsi,
156 		   struct flow_cls_offload *cls_flower);
157 int
158 ice_del_cls_flower(struct ice_vsi *vsi, struct flow_cls_offload *cls_flower);
159 void ice_replay_tc_fltrs(struct ice_pf *pf);
160 bool ice_is_tunnel_supported(struct net_device *dev);
161 
162 #endif /* _ICE_TC_LIB_H_ */
163