18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci/* Copyright (C) 2018-2020, Intel Corporation. */
38c2ecf20Sopenharmony_ci
48c2ecf20Sopenharmony_ci#ifndef _ICE_FDIR_H_
58c2ecf20Sopenharmony_ci#define _ICE_FDIR_H_
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ci#define ICE_FDIR_TUN_PKT_OFF		50
88c2ecf20Sopenharmony_ci#define ICE_FDIR_MAX_RAW_PKT_SIZE	(512 + ICE_FDIR_TUN_PKT_OFF)
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci/* macros for offsets into packets for flow director programming */
118c2ecf20Sopenharmony_ci#define ICE_IPV4_SRC_ADDR_OFFSET	26
128c2ecf20Sopenharmony_ci#define ICE_IPV4_DST_ADDR_OFFSET	30
138c2ecf20Sopenharmony_ci#define ICE_IPV4_TCP_SRC_PORT_OFFSET	34
148c2ecf20Sopenharmony_ci#define ICE_IPV4_TCP_DST_PORT_OFFSET	36
158c2ecf20Sopenharmony_ci#define ICE_IPV4_UDP_SRC_PORT_OFFSET	34
168c2ecf20Sopenharmony_ci#define ICE_IPV4_UDP_DST_PORT_OFFSET	36
178c2ecf20Sopenharmony_ci#define ICE_IPV4_SCTP_SRC_PORT_OFFSET	34
188c2ecf20Sopenharmony_ci#define ICE_IPV4_SCTP_DST_PORT_OFFSET	36
198c2ecf20Sopenharmony_ci#define ICE_IPV4_PROTO_OFFSET		23
208c2ecf20Sopenharmony_ci#define ICE_IPV6_SRC_ADDR_OFFSET	22
218c2ecf20Sopenharmony_ci#define ICE_IPV6_DST_ADDR_OFFSET	38
228c2ecf20Sopenharmony_ci#define ICE_IPV6_TCP_SRC_PORT_OFFSET	54
238c2ecf20Sopenharmony_ci#define ICE_IPV6_TCP_DST_PORT_OFFSET	56
248c2ecf20Sopenharmony_ci#define ICE_IPV6_UDP_SRC_PORT_OFFSET	54
258c2ecf20Sopenharmony_ci#define ICE_IPV6_UDP_DST_PORT_OFFSET	56
268c2ecf20Sopenharmony_ci#define ICE_IPV6_SCTP_SRC_PORT_OFFSET	54
278c2ecf20Sopenharmony_ci#define ICE_IPV6_SCTP_DST_PORT_OFFSET	56
288c2ecf20Sopenharmony_ci/* IP v4 has 2 flag bits that enable fragment processing: DF and MF. DF
298c2ecf20Sopenharmony_ci * requests that the packet not be fragmented. MF indicates that a packet has
308c2ecf20Sopenharmony_ci * been fragmented.
318c2ecf20Sopenharmony_ci */
328c2ecf20Sopenharmony_ci#define ICE_FDIR_IPV4_PKT_FLAG_DF		0x20
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_cienum ice_fltr_prgm_desc_dest {
358c2ecf20Sopenharmony_ci	ICE_FLTR_PRGM_DESC_DEST_DROP_PKT,
368c2ecf20Sopenharmony_ci	ICE_FLTR_PRGM_DESC_DEST_DIRECT_PKT_QINDEX,
378c2ecf20Sopenharmony_ci};
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_cienum ice_fltr_prgm_desc_fd_status {
408c2ecf20Sopenharmony_ci	ICE_FLTR_PRGM_DESC_FD_STATUS_NONE,
418c2ecf20Sopenharmony_ci	ICE_FLTR_PRGM_DESC_FD_STATUS_FD_ID,
428c2ecf20Sopenharmony_ci};
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_ci/* Flow Director (FD) Filter Programming descriptor */
458c2ecf20Sopenharmony_cistruct ice_fd_fltr_desc_ctx {
468c2ecf20Sopenharmony_ci	u32 fdid;
478c2ecf20Sopenharmony_ci	u16 qindex;
488c2ecf20Sopenharmony_ci	u16 cnt_index;
498c2ecf20Sopenharmony_ci	u16 fd_vsi;
508c2ecf20Sopenharmony_ci	u16 flex_val;
518c2ecf20Sopenharmony_ci	u8 comp_q;
528c2ecf20Sopenharmony_ci	u8 comp_report;
538c2ecf20Sopenharmony_ci	u8 fd_space;
548c2ecf20Sopenharmony_ci	u8 cnt_ena;
558c2ecf20Sopenharmony_ci	u8 evict_ena;
568c2ecf20Sopenharmony_ci	u8 toq;
578c2ecf20Sopenharmony_ci	u8 toq_prio;
588c2ecf20Sopenharmony_ci	u8 dpu_recipe;
598c2ecf20Sopenharmony_ci	u8 drop;
608c2ecf20Sopenharmony_ci	u8 flex_prio;
618c2ecf20Sopenharmony_ci	u8 flex_mdid;
628c2ecf20Sopenharmony_ci	u8 dtype;
638c2ecf20Sopenharmony_ci	u8 pcmd;
648c2ecf20Sopenharmony_ci	u8 desc_prof_prio;
658c2ecf20Sopenharmony_ci	u8 desc_prof;
668c2ecf20Sopenharmony_ci	u8 swap;
678c2ecf20Sopenharmony_ci	u8 fdid_prio;
688c2ecf20Sopenharmony_ci	u8 fdid_mdid;
698c2ecf20Sopenharmony_ci};
708c2ecf20Sopenharmony_ci
718c2ecf20Sopenharmony_ci#define ICE_FLTR_PRGM_FLEX_WORD_SIZE	sizeof(__be16)
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_cistruct ice_rx_flow_userdef {
748c2ecf20Sopenharmony_ci	u16 flex_word;
758c2ecf20Sopenharmony_ci	u16 flex_offset;
768c2ecf20Sopenharmony_ci	u16 flex_fltr;
778c2ecf20Sopenharmony_ci};
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_cistruct ice_fdir_v4 {
808c2ecf20Sopenharmony_ci	__be32 dst_ip;
818c2ecf20Sopenharmony_ci	__be32 src_ip;
828c2ecf20Sopenharmony_ci	__be16 dst_port;
838c2ecf20Sopenharmony_ci	__be16 src_port;
848c2ecf20Sopenharmony_ci	__be32 l4_header;
858c2ecf20Sopenharmony_ci	__be32 sec_parm_idx;	/* security parameter index */
868c2ecf20Sopenharmony_ci	u8 tos;
878c2ecf20Sopenharmony_ci	u8 ip_ver;
888c2ecf20Sopenharmony_ci	u8 proto;
898c2ecf20Sopenharmony_ci};
908c2ecf20Sopenharmony_ci
918c2ecf20Sopenharmony_ci#define ICE_IPV6_ADDR_LEN_AS_U32		4
928c2ecf20Sopenharmony_ci
938c2ecf20Sopenharmony_cistruct ice_fdir_v6 {
948c2ecf20Sopenharmony_ci	__be32 dst_ip[ICE_IPV6_ADDR_LEN_AS_U32];
958c2ecf20Sopenharmony_ci	__be32 src_ip[ICE_IPV6_ADDR_LEN_AS_U32];
968c2ecf20Sopenharmony_ci	__be16 dst_port;
978c2ecf20Sopenharmony_ci	__be16 src_port;
988c2ecf20Sopenharmony_ci	__be32 l4_header; /* next header */
998c2ecf20Sopenharmony_ci	__be32 sec_parm_idx; /* security parameter index */
1008c2ecf20Sopenharmony_ci	u8 tc;
1018c2ecf20Sopenharmony_ci	u8 proto;
1028c2ecf20Sopenharmony_ci};
1038c2ecf20Sopenharmony_ci
1048c2ecf20Sopenharmony_cistruct ice_fdir_extra {
1058c2ecf20Sopenharmony_ci	u8 dst_mac[ETH_ALEN];	/* dest MAC address */
1068c2ecf20Sopenharmony_ci	u32 usr_def[2];		/* user data */
1078c2ecf20Sopenharmony_ci	__be16 vlan_type;	/* VLAN ethertype */
1088c2ecf20Sopenharmony_ci	__be16 vlan_tag;	/* VLAN tag info */
1098c2ecf20Sopenharmony_ci};
1108c2ecf20Sopenharmony_ci
1118c2ecf20Sopenharmony_cistruct ice_fdir_fltr {
1128c2ecf20Sopenharmony_ci	struct list_head fltr_node;
1138c2ecf20Sopenharmony_ci	enum ice_fltr_ptype flow_type;
1148c2ecf20Sopenharmony_ci
1158c2ecf20Sopenharmony_ci	union {
1168c2ecf20Sopenharmony_ci		struct ice_fdir_v4 v4;
1178c2ecf20Sopenharmony_ci		struct ice_fdir_v6 v6;
1188c2ecf20Sopenharmony_ci	} ip, mask;
1198c2ecf20Sopenharmony_ci
1208c2ecf20Sopenharmony_ci	struct ice_fdir_extra ext_data;
1218c2ecf20Sopenharmony_ci	struct ice_fdir_extra ext_mask;
1228c2ecf20Sopenharmony_ci
1238c2ecf20Sopenharmony_ci	/* flex byte filter data */
1248c2ecf20Sopenharmony_ci	__be16 flex_word;
1258c2ecf20Sopenharmony_ci	u16 flex_offset;
1268c2ecf20Sopenharmony_ci	u16 flex_fltr;
1278c2ecf20Sopenharmony_ci
1288c2ecf20Sopenharmony_ci	/* filter control */
1298c2ecf20Sopenharmony_ci	u16 q_index;
1308c2ecf20Sopenharmony_ci	u16 dest_vsi;
1318c2ecf20Sopenharmony_ci	u8 dest_ctl;
1328c2ecf20Sopenharmony_ci	u8 fltr_status;
1338c2ecf20Sopenharmony_ci	u16 cnt_index;
1348c2ecf20Sopenharmony_ci	u32 fltr_id;
1358c2ecf20Sopenharmony_ci};
1368c2ecf20Sopenharmony_ci
1378c2ecf20Sopenharmony_ci/* Dummy packet filter definition structure */
1388c2ecf20Sopenharmony_cistruct ice_fdir_base_pkt {
1398c2ecf20Sopenharmony_ci	enum ice_fltr_ptype flow;
1408c2ecf20Sopenharmony_ci	u16 pkt_len;
1418c2ecf20Sopenharmony_ci	const u8 *pkt;
1428c2ecf20Sopenharmony_ci	u16 tun_pkt_len;
1438c2ecf20Sopenharmony_ci	const u8 *tun_pkt;
1448c2ecf20Sopenharmony_ci};
1458c2ecf20Sopenharmony_ci
1468c2ecf20Sopenharmony_cienum ice_status ice_alloc_fd_res_cntr(struct ice_hw *hw, u16 *cntr_id);
1478c2ecf20Sopenharmony_cienum ice_status ice_free_fd_res_cntr(struct ice_hw *hw, u16 cntr_id);
1488c2ecf20Sopenharmony_cienum ice_status
1498c2ecf20Sopenharmony_ciice_alloc_fd_guar_item(struct ice_hw *hw, u16 *cntr_id, u16 num_fltr);
1508c2ecf20Sopenharmony_cienum ice_status
1518c2ecf20Sopenharmony_ciice_alloc_fd_shrd_item(struct ice_hw *hw, u16 *cntr_id, u16 num_fltr);
1528c2ecf20Sopenharmony_civoid
1538c2ecf20Sopenharmony_ciice_fdir_get_prgm_desc(struct ice_hw *hw, struct ice_fdir_fltr *input,
1548c2ecf20Sopenharmony_ci		       struct ice_fltr_desc *fdesc, bool add);
1558c2ecf20Sopenharmony_cienum ice_status
1568c2ecf20Sopenharmony_ciice_fdir_get_gen_prgm_pkt(struct ice_hw *hw, struct ice_fdir_fltr *input,
1578c2ecf20Sopenharmony_ci			  u8 *pkt, bool frag, bool tun);
1588c2ecf20Sopenharmony_ciint ice_get_fdir_cnt_all(struct ice_hw *hw);
1598c2ecf20Sopenharmony_cibool ice_fdir_is_dup_fltr(struct ice_hw *hw, struct ice_fdir_fltr *input);
1608c2ecf20Sopenharmony_cibool ice_fdir_has_frag(enum ice_fltr_ptype flow);
1618c2ecf20Sopenharmony_cistruct ice_fdir_fltr *
1628c2ecf20Sopenharmony_ciice_fdir_find_fltr_by_idx(struct ice_hw *hw, u32 fltr_idx);
1638c2ecf20Sopenharmony_civoid
1648c2ecf20Sopenharmony_ciice_fdir_update_cntrs(struct ice_hw *hw, enum ice_fltr_ptype flow, bool add);
1658c2ecf20Sopenharmony_civoid ice_fdir_list_add_fltr(struct ice_hw *hw, struct ice_fdir_fltr *input);
1668c2ecf20Sopenharmony_ci#endif /* _ICE_FDIR_H_ */
167