1bf93bf79SJacob Keller /* SPDX-License-Identifier: GPL-2.0 */
2bf93bf79SJacob Keller /* Copyright (C) 2022, Intel Corporation. */
3bf93bf79SJacob Keller 
4bf93bf79SJacob Keller #ifndef _ICE_VIRTCHNL_H_
5bf93bf79SJacob Keller #define _ICE_VIRTCHNL_H_
6bf93bf79SJacob Keller 
7bf93bf79SJacob Keller #include <linux/types.h>
8bf93bf79SJacob Keller #include <linux/bitops.h>
9bf93bf79SJacob Keller #include <linux/if_ether.h>
10bf93bf79SJacob Keller #include <linux/avf/virtchnl.h>
11bf93bf79SJacob Keller #include "ice_vf_lib.h"
12bf93bf79SJacob Keller 
13bf93bf79SJacob Keller /* Restrict number of MAC Addr and VLAN that non-trusted VF can programmed */
14bf93bf79SJacob Keller #define ICE_MAX_VLAN_PER_VF		8
15bf93bf79SJacob Keller 
16bf93bf79SJacob Keller /* MAC filters: 1 is reserved for the VF's default/perm_addr/LAA MAC, 1 for
17bf93bf79SJacob Keller  * broadcast, and 16 for additional unicast/multicast filters
18bf93bf79SJacob Keller  */
19bf93bf79SJacob Keller #define ICE_MAX_MACADDR_PER_VF		18
20e753df8fSMichal Jaron #define ICE_FLEX_DESC_RXDID_MAX_NUM	64
21bf93bf79SJacob Keller 
22c926393dSJacob Keller /* VFs only get a single VSI. For ice hardware, the VF does not need to know
23c926393dSJacob Keller  * its VSI index. However, the virtchnl interface requires a VSI number,
24c926393dSJacob Keller  * mainly due to legacy hardware.
25c926393dSJacob Keller  *
26c926393dSJacob Keller  * Since the VF doesn't need this information, report a static value to the VF
27c926393dSJacob Keller  * instead of leaking any information about the PF or hardware setup.
28c926393dSJacob Keller  */
29c926393dSJacob Keller #define ICE_VF_VSI_ID	1
30c926393dSJacob Keller 
31bf93bf79SJacob Keller struct ice_virtchnl_ops {
32bf93bf79SJacob Keller 	int (*get_ver_msg)(struct ice_vf *vf, u8 *msg);
33bf93bf79SJacob Keller 	int (*get_vf_res_msg)(struct ice_vf *vf, u8 *msg);
34bf93bf79SJacob Keller 	void (*reset_vf)(struct ice_vf *vf);
35bf93bf79SJacob Keller 	int (*add_mac_addr_msg)(struct ice_vf *vf, u8 *msg);
36bf93bf79SJacob Keller 	int (*del_mac_addr_msg)(struct ice_vf *vf, u8 *msg);
37bf93bf79SJacob Keller 	int (*cfg_qs_msg)(struct ice_vf *vf, u8 *msg);
38bf93bf79SJacob Keller 	int (*ena_qs_msg)(struct ice_vf *vf, u8 *msg);
39bf93bf79SJacob Keller 	int (*dis_qs_msg)(struct ice_vf *vf, u8 *msg);
40bf93bf79SJacob Keller 	int (*request_qs_msg)(struct ice_vf *vf, u8 *msg);
41bf93bf79SJacob Keller 	int (*cfg_irq_map_msg)(struct ice_vf *vf, u8 *msg);
42bf93bf79SJacob Keller 	int (*config_rss_key)(struct ice_vf *vf, u8 *msg);
43bf93bf79SJacob Keller 	int (*config_rss_lut)(struct ice_vf *vf, u8 *msg);
44bf93bf79SJacob Keller 	int (*get_stats_msg)(struct ice_vf *vf, u8 *msg);
45bf93bf79SJacob Keller 	int (*cfg_promiscuous_mode_msg)(struct ice_vf *vf, u8 *msg);
46bf93bf79SJacob Keller 	int (*add_vlan_msg)(struct ice_vf *vf, u8 *msg);
47bf93bf79SJacob Keller 	int (*remove_vlan_msg)(struct ice_vf *vf, u8 *msg);
48e753df8fSMichal Jaron 	int (*query_rxdid)(struct ice_vf *vf);
49e384cf35SMd Fahad Iqbal Polash 	int (*get_rss_hena)(struct ice_vf *vf);
50e384cf35SMd Fahad Iqbal Polash 	int (*set_rss_hena_msg)(struct ice_vf *vf, u8 *msg);
51bf93bf79SJacob Keller 	int (*ena_vlan_stripping)(struct ice_vf *vf);
52bf93bf79SJacob Keller 	int (*dis_vlan_stripping)(struct ice_vf *vf);
53bf93bf79SJacob Keller 	int (*handle_rss_cfg_msg)(struct ice_vf *vf, u8 *msg, bool add);
54bf93bf79SJacob Keller 	int (*add_fdir_fltr_msg)(struct ice_vf *vf, u8 *msg);
55bf93bf79SJacob Keller 	int (*del_fdir_fltr_msg)(struct ice_vf *vf, u8 *msg);
56bf93bf79SJacob Keller 	int (*get_offload_vlan_v2_caps)(struct ice_vf *vf);
57bf93bf79SJacob Keller 	int (*add_vlan_v2_msg)(struct ice_vf *vf, u8 *msg);
58bf93bf79SJacob Keller 	int (*remove_vlan_v2_msg)(struct ice_vf *vf, u8 *msg);
59bf93bf79SJacob Keller 	int (*ena_vlan_stripping_v2_msg)(struct ice_vf *vf, u8 *msg);
60bf93bf79SJacob Keller 	int (*dis_vlan_stripping_v2_msg)(struct ice_vf *vf, u8 *msg);
61bf93bf79SJacob Keller 	int (*ena_vlan_insertion_v2_msg)(struct ice_vf *vf, u8 *msg);
62bf93bf79SJacob Keller 	int (*dis_vlan_insertion_v2_msg)(struct ice_vf *vf, u8 *msg);
63bf93bf79SJacob Keller };
64bf93bf79SJacob Keller 
65bf93bf79SJacob Keller #ifdef CONFIG_PCI_IOV
66bf93bf79SJacob Keller void ice_virtchnl_set_dflt_ops(struct ice_vf *vf);
67bf93bf79SJacob Keller void ice_virtchnl_set_repr_ops(struct ice_vf *vf);
68bf93bf79SJacob Keller void ice_vc_notify_vf_link_state(struct ice_vf *vf);
69bf93bf79SJacob Keller void ice_vc_notify_link_state(struct ice_pf *pf);
70bf93bf79SJacob Keller void ice_vc_notify_reset(struct ice_pf *pf);
71bf93bf79SJacob Keller int
72bf93bf79SJacob Keller ice_vc_send_msg_to_vf(struct ice_vf *vf, u32 v_opcode,
73bf93bf79SJacob Keller 		      enum virtchnl_status_code v_retval, u8 *msg, u16 msglen);
74bf93bf79SJacob Keller bool ice_vc_isvalid_vsi_id(struct ice_vf *vf, u16 vsi_id);
75be96815cSJacob Keller void ice_vc_process_vf_msg(struct ice_pf *pf, struct ice_rq_event_info *event,
76c414463aSJacob Keller 			   struct ice_mbx_data *mbxdata);
77bf93bf79SJacob Keller #else /* CONFIG_PCI_IOV */
ice_virtchnl_set_dflt_ops(struct ice_vf * vf)78bf93bf79SJacob Keller static inline void ice_virtchnl_set_dflt_ops(struct ice_vf *vf) { }
ice_virtchnl_set_repr_ops(struct ice_vf * vf)79bf93bf79SJacob Keller static inline void ice_virtchnl_set_repr_ops(struct ice_vf *vf) { }
ice_vc_notify_vf_link_state(struct ice_vf * vf)80bf93bf79SJacob Keller static inline void ice_vc_notify_vf_link_state(struct ice_vf *vf) { }
ice_vc_notify_link_state(struct ice_pf * pf)81bf93bf79SJacob Keller static inline void ice_vc_notify_link_state(struct ice_pf *pf) { }
ice_vc_notify_reset(struct ice_pf * pf)82bf93bf79SJacob Keller static inline void ice_vc_notify_reset(struct ice_pf *pf) { }
83bf93bf79SJacob Keller 
84bf93bf79SJacob Keller static inline int
ice_vc_send_msg_to_vf(struct ice_vf * vf,u32 v_opcode,enum virtchnl_status_code v_retval,u8 * msg,u16 msglen)85bf93bf79SJacob Keller ice_vc_send_msg_to_vf(struct ice_vf *vf, u32 v_opcode,
86bf93bf79SJacob Keller 		      enum virtchnl_status_code v_retval, u8 *msg, u16 msglen)
87bf93bf79SJacob Keller {
88bf93bf79SJacob Keller 	return -EOPNOTSUPP;
89bf93bf79SJacob Keller }
90bf93bf79SJacob Keller 
ice_vc_isvalid_vsi_id(struct ice_vf * vf,u16 vsi_id)91bf93bf79SJacob Keller static inline bool ice_vc_isvalid_vsi_id(struct ice_vf *vf, u16 vsi_id)
92bf93bf79SJacob Keller {
93bf93bf79SJacob Keller 	return false;
94bf93bf79SJacob Keller }
9533b035e7SJacob Keller 
9633b035e7SJacob Keller static inline void
ice_vc_process_vf_msg(struct ice_pf * pf,struct ice_rq_event_info * event,struct ice_mbx_data * mbxdata)97be96815cSJacob Keller ice_vc_process_vf_msg(struct ice_pf *pf, struct ice_rq_event_info *event,
98be96815cSJacob Keller 		      struct ice_mbx_data *mbxdata)
9933b035e7SJacob Keller {
10033b035e7SJacob Keller }
101bf93bf79SJacob Keller #endif /* !CONFIG_PCI_IOV */
102bf93bf79SJacob Keller 
103bf93bf79SJacob Keller #endif /* _ICE_VIRTCHNL_H_ */
104