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