1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Copyright (c) 2018, Intel Corporation. */
3 
4 #ifndef _ICE_SRIOV_H_
5 #define _ICE_SRIOV_H_
6 #include "ice_virtchnl_fdir.h"
7 #include "ice_vf_lib.h"
8 #include "ice_virtchnl.h"
9 
10 /* Static VF transaction/status register def */
11 #define VF_DEVICE_STATUS		0xAA
12 #define VF_TRANS_PENDING_M		0x20
13 
14 /* wait defines for polling PF_PCI_CIAD register status */
15 #define ICE_PCI_CIAD_WAIT_COUNT		100
16 #define ICE_PCI_CIAD_WAIT_DELAY_US	1
17 
18 /* VF resource constraints */
19 #define ICE_MIN_QS_PER_VF		1
20 #define ICE_NONQ_VECS_VF		1
21 #define ICE_NUM_VF_MSIX_MED		17
22 #define ICE_NUM_VF_MSIX_SMALL		5
23 #define ICE_NUM_VF_MSIX_MULTIQ_MIN	3
24 #define ICE_MIN_INTR_PER_VF		(ICE_MIN_QS_PER_VF + 1)
25 #define ICE_MAX_VF_RESET_TRIES		40
26 #define ICE_MAX_VF_RESET_SLEEP_MS	20
27 
28 #ifdef CONFIG_PCI_IOV
29 void ice_process_vflr_event(struct ice_pf *pf);
30 int ice_sriov_configure(struct pci_dev *pdev, int num_vfs);
31 int ice_set_vf_mac(struct net_device *netdev, int vf_id, u8 *mac);
32 int
33 ice_get_vf_cfg(struct net_device *netdev, int vf_id, struct ifla_vf_info *ivi);
34 
35 void ice_free_vfs(struct ice_pf *pf);
36 void ice_restore_all_vfs_msi_state(struct pci_dev *pdev);
37 
38 int
39 ice_set_vf_port_vlan(struct net_device *netdev, int vf_id, u16 vlan_id, u8 qos,
40 		     __be16 vlan_proto);
41 
42 int
43 ice_set_vf_bw(struct net_device *netdev, int vf_id, int min_tx_rate,
44 	      int max_tx_rate);
45 
46 int ice_set_vf_trust(struct net_device *netdev, int vf_id, bool trusted);
47 
48 int ice_set_vf_link_state(struct net_device *netdev, int vf_id, int link_state);
49 
50 int ice_set_vf_spoofchk(struct net_device *netdev, int vf_id, bool ena);
51 
52 int ice_calc_vf_reg_idx(struct ice_vf *vf, struct ice_q_vector *q_vector);
53 
54 int
55 ice_get_vf_stats(struct net_device *netdev, int vf_id,
56 		 struct ifla_vf_stats *vf_stats);
57 void
58 ice_vf_lan_overflow_event(struct ice_pf *pf, struct ice_rq_event_info *event);
59 void ice_print_vfs_mdd_events(struct ice_pf *pf);
60 void ice_print_vf_rx_mdd_event(struct ice_vf *vf);
61 bool
62 ice_vc_validate_pattern(struct ice_vf *vf, struct virtchnl_proto_hdrs *proto);
63 #else /* CONFIG_PCI_IOV */
ice_process_vflr_event(struct ice_pf * pf)64 static inline void ice_process_vflr_event(struct ice_pf *pf) { }
ice_free_vfs(struct ice_pf * pf)65 static inline void ice_free_vfs(struct ice_pf *pf) { }
66 static inline
ice_vf_lan_overflow_event(struct ice_pf * pf,struct ice_rq_event_info * event)67 void ice_vf_lan_overflow_event(struct ice_pf *pf, struct ice_rq_event_info *event) { }
ice_print_vfs_mdd_events(struct ice_pf * pf)68 static inline void ice_print_vfs_mdd_events(struct ice_pf *pf) { }
ice_print_vf_rx_mdd_event(struct ice_vf * vf)69 static inline void ice_print_vf_rx_mdd_event(struct ice_vf *vf) { }
ice_restore_all_vfs_msi_state(struct pci_dev * pdev)70 static inline void ice_restore_all_vfs_msi_state(struct pci_dev *pdev) { }
71 
72 static inline int
ice_sriov_configure(struct pci_dev __always_unused * pdev,int __always_unused num_vfs)73 ice_sriov_configure(struct pci_dev __always_unused *pdev,
74 		    int __always_unused num_vfs)
75 {
76 	return -EOPNOTSUPP;
77 }
78 
79 static inline int
ice_set_vf_mac(struct net_device __always_unused * netdev,int __always_unused vf_id,u8 __always_unused * mac)80 ice_set_vf_mac(struct net_device __always_unused *netdev,
81 	       int __always_unused vf_id, u8 __always_unused *mac)
82 {
83 	return -EOPNOTSUPP;
84 }
85 
86 static inline int
ice_get_vf_cfg(struct net_device __always_unused * netdev,int __always_unused vf_id,struct ifla_vf_info __always_unused * ivi)87 ice_get_vf_cfg(struct net_device __always_unused *netdev,
88 	       int __always_unused vf_id,
89 	       struct ifla_vf_info __always_unused *ivi)
90 {
91 	return -EOPNOTSUPP;
92 }
93 
94 static inline int
ice_set_vf_trust(struct net_device __always_unused * netdev,int __always_unused vf_id,bool __always_unused trusted)95 ice_set_vf_trust(struct net_device __always_unused *netdev,
96 		 int __always_unused vf_id, bool __always_unused trusted)
97 {
98 	return -EOPNOTSUPP;
99 }
100 
101 static inline int
ice_set_vf_port_vlan(struct net_device __always_unused * netdev,int __always_unused vf_id,u16 __always_unused vid,u8 __always_unused qos,__be16 __always_unused v_proto)102 ice_set_vf_port_vlan(struct net_device __always_unused *netdev,
103 		     int __always_unused vf_id, u16 __always_unused vid,
104 		     u8 __always_unused qos, __be16 __always_unused v_proto)
105 {
106 	return -EOPNOTSUPP;
107 }
108 
109 static inline int
ice_set_vf_spoofchk(struct net_device __always_unused * netdev,int __always_unused vf_id,bool __always_unused ena)110 ice_set_vf_spoofchk(struct net_device __always_unused *netdev,
111 		    int __always_unused vf_id, bool __always_unused ena)
112 {
113 	return -EOPNOTSUPP;
114 }
115 
116 static inline int
ice_set_vf_link_state(struct net_device __always_unused * netdev,int __always_unused vf_id,int __always_unused link_state)117 ice_set_vf_link_state(struct net_device __always_unused *netdev,
118 		      int __always_unused vf_id, int __always_unused link_state)
119 {
120 	return -EOPNOTSUPP;
121 }
122 
123 static inline int
ice_set_vf_bw(struct net_device __always_unused * netdev,int __always_unused vf_id,int __always_unused min_tx_rate,int __always_unused max_tx_rate)124 ice_set_vf_bw(struct net_device __always_unused *netdev,
125 	      int __always_unused vf_id, int __always_unused min_tx_rate,
126 	      int __always_unused max_tx_rate)
127 {
128 	return -EOPNOTSUPP;
129 }
130 
131 static inline int
ice_calc_vf_reg_idx(struct ice_vf __always_unused * vf,struct ice_q_vector __always_unused * q_vector)132 ice_calc_vf_reg_idx(struct ice_vf __always_unused *vf,
133 		    struct ice_q_vector __always_unused *q_vector)
134 {
135 	return 0;
136 }
137 
138 static inline int
ice_get_vf_stats(struct net_device __always_unused * netdev,int __always_unused vf_id,struct ifla_vf_stats __always_unused * vf_stats)139 ice_get_vf_stats(struct net_device __always_unused *netdev,
140 		 int __always_unused vf_id,
141 		 struct ifla_vf_stats __always_unused *vf_stats)
142 {
143 	return -EOPNOTSUPP;
144 }
145 #endif /* CONFIG_PCI_IOV */
146 #endif /* _ICE_SRIOV_H_ */
147