Loading...
1/* SPDX-License-Identifier: GPL-2.0 */
2/* Copyright (c) 2018, Intel Corporation. */
3
4#ifndef _ICE_VIRTCHNL_PF_H_
5#define _ICE_VIRTCHNL_PF_H_
6#include "ice.h"
7
8#define ICE_MAX_VLANID 4095
9#define ICE_VLAN_PRIORITY_S 12
10#define ICE_VLAN_M 0xFFF
11#define ICE_PRIORITY_M 0x7000
12
13/* Restrict number of MAC Addr and VLAN that non-trusted VF can programmed */
14#define ICE_MAX_VLAN_PER_VF 8
15#define ICE_MAX_MACADDR_PER_VF 12
16
17/* Malicious Driver Detection */
18#define ICE_DFLT_NUM_INVAL_MSGS_ALLOWED 10
19#define ICE_MDD_EVENTS_THRESHOLD 30
20
21/* Static VF transaction/status register def */
22#define VF_DEVICE_STATUS 0xAA
23#define VF_TRANS_PENDING_M 0x20
24
25/* wait defines for polling PF_PCI_CIAD register status */
26#define ICE_PCI_CIAD_WAIT_COUNT 100
27#define ICE_PCI_CIAD_WAIT_DELAY_US 1
28
29/* VF resources default values and limitation */
30#define ICE_MAX_VF_COUNT 256
31#define ICE_MAX_QS_PER_VF 256
32#define ICE_MIN_QS_PER_VF 1
33#define ICE_DFLT_QS_PER_VF 4
34#define ICE_NONQ_VECS_VF 1
35#define ICE_MAX_SCATTER_QS_PER_VF 16
36#define ICE_MAX_BASE_QS_PER_VF 16
37#define ICE_MAX_INTR_PER_VF 65
38#define ICE_MAX_POLICY_INTR_PER_VF 33
39#define ICE_MIN_INTR_PER_VF (ICE_MIN_QS_PER_VF + 1)
40#define ICE_DFLT_INTR_PER_VF (ICE_DFLT_QS_PER_VF + 1)
41
42/* Specific VF states */
43enum ice_vf_states {
44 ICE_VF_STATE_INIT = 0, /* PF is initializing VF */
45 ICE_VF_STATE_ACTIVE, /* VF resources are allocated for use */
46 ICE_VF_STATE_QS_ENA, /* VF queue(s) enabled */
47 ICE_VF_STATE_DIS,
48 ICE_VF_STATE_MC_PROMISC,
49 ICE_VF_STATE_UC_PROMISC,
50 ICE_VF_STATES_NBITS
51};
52
53/* VF capabilities */
54enum ice_virtchnl_cap {
55 ICE_VIRTCHNL_VF_CAP_L2 = 0,
56 ICE_VIRTCHNL_VF_CAP_PRIVILEGE,
57};
58
59/* VF information structure */
60struct ice_vf {
61 struct ice_pf *pf;
62
63 s16 vf_id; /* VF ID in the PF space */
64 u16 lan_vsi_idx; /* index into PF struct */
65 /* first vector index of this VF in the PF space */
66 int first_vector_idx;
67 struct ice_sw *vf_sw_id; /* switch ID the VF VSIs connect to */
68 struct virtchnl_version_info vf_ver;
69 u32 driver_caps; /* reported by VF driver */
70 struct virtchnl_ether_addr dflt_lan_addr;
71 DECLARE_BITMAP(txq_ena, ICE_MAX_BASE_QS_PER_VF);
72 DECLARE_BITMAP(rxq_ena, ICE_MAX_BASE_QS_PER_VF);
73 u16 port_vlan_id;
74 u8 pf_set_mac:1; /* VF MAC address set by VMM admin */
75 u8 trusted:1;
76 u8 spoofchk:1;
77 u8 link_forced:1;
78 u8 link_up:1; /* only valid if VF link is forced */
79 /* VSI indices - actual VSI pointers are maintained in the PF structure
80 * When assigned, these will be non-zero, because VSI 0 is always
81 * the main LAN VSI for the PF.
82 */
83 u16 lan_vsi_num; /* ID as used by firmware */
84 unsigned int tx_rate; /* Tx bandwidth limit in Mbps */
85 DECLARE_BITMAP(vf_states, ICE_VF_STATES_NBITS); /* VF runtime states */
86
87 u64 num_mdd_events; /* number of MDD events detected */
88 u64 num_inval_msgs; /* number of continuous invalid msgs */
89 u64 num_valid_msgs; /* number of valid msgs detected */
90 unsigned long vf_caps; /* VF's adv. capabilities */
91 u8 num_req_qs; /* num of queue pairs requested by VF */
92 u16 num_mac;
93 u16 num_vlan;
94 u16 num_vf_qs; /* num of queue configured per VF */
95 u16 num_qs_ena; /* total num of Tx/Rx queue enabled */
96};
97
98#ifdef CONFIG_PCI_IOV
99void ice_process_vflr_event(struct ice_pf *pf);
100int ice_sriov_configure(struct pci_dev *pdev, int num_vfs);
101int ice_set_vf_mac(struct net_device *netdev, int vf_id, u8 *mac);
102int
103ice_get_vf_cfg(struct net_device *netdev, int vf_id, struct ifla_vf_info *ivi);
104
105void ice_free_vfs(struct ice_pf *pf);
106void ice_vc_process_vf_msg(struct ice_pf *pf, struct ice_rq_event_info *event);
107void ice_vc_notify_link_state(struct ice_pf *pf);
108void ice_vc_notify_reset(struct ice_pf *pf);
109bool ice_reset_all_vfs(struct ice_pf *pf, bool is_vflr);
110
111int
112ice_set_vf_port_vlan(struct net_device *netdev, int vf_id, u16 vlan_id, u8 qos,
113 __be16 vlan_proto);
114
115int ice_set_vf_trust(struct net_device *netdev, int vf_id, bool trusted);
116
117int ice_set_vf_link_state(struct net_device *netdev, int vf_id, int link_state);
118
119int ice_set_vf_spoofchk(struct net_device *netdev, int vf_id, bool ena);
120
121int ice_calc_vf_reg_idx(struct ice_vf *vf, struct ice_q_vector *q_vector);
122
123void ice_set_vf_state_qs_dis(struct ice_vf *vf);
124#else /* CONFIG_PCI_IOV */
125#define ice_process_vflr_event(pf) do {} while (0)
126#define ice_free_vfs(pf) do {} while (0)
127#define ice_vc_process_vf_msg(pf, event) do {} while (0)
128#define ice_vc_notify_link_state(pf) do {} while (0)
129#define ice_vc_notify_reset(pf) do {} while (0)
130#define ice_set_vf_state_qs_dis(vf) do {} while (0)
131
132static inline bool
133ice_reset_all_vfs(struct ice_pf __always_unused *pf,
134 bool __always_unused is_vflr)
135{
136 return true;
137}
138
139static inline int
140ice_sriov_configure(struct pci_dev __always_unused *pdev,
141 int __always_unused num_vfs)
142{
143 return -EOPNOTSUPP;
144}
145
146static inline int
147ice_set_vf_mac(struct net_device __always_unused *netdev,
148 int __always_unused vf_id, u8 __always_unused *mac)
149{
150 return -EOPNOTSUPP;
151}
152
153static inline int
154ice_get_vf_cfg(struct net_device __always_unused *netdev,
155 int __always_unused vf_id,
156 struct ifla_vf_info __always_unused *ivi)
157{
158 return -EOPNOTSUPP;
159}
160
161static inline int
162ice_set_vf_trust(struct net_device __always_unused *netdev,
163 int __always_unused vf_id, bool __always_unused trusted)
164{
165 return -EOPNOTSUPP;
166}
167
168static inline int
169ice_set_vf_port_vlan(struct net_device __always_unused *netdev,
170 int __always_unused vf_id, u16 __always_unused vid,
171 u8 __always_unused qos, __be16 __always_unused v_proto)
172{
173 return -EOPNOTSUPP;
174}
175
176static inline int
177ice_set_vf_spoofchk(struct net_device __always_unused *netdev,
178 int __always_unused vf_id, bool __always_unused ena)
179{
180 return -EOPNOTSUPP;
181}
182
183static inline int
184ice_set_vf_link_state(struct net_device __always_unused *netdev,
185 int __always_unused vf_id, int __always_unused link_state)
186{
187 return -EOPNOTSUPP;
188}
189
190static inline int
191ice_calc_vf_reg_idx(struct ice_vf __always_unused *vf,
192 struct ice_q_vector __always_unused *q_vector)
193{
194 return 0;
195}
196#endif /* CONFIG_PCI_IOV */
197#endif /* _ICE_VIRTCHNL_PF_H_ */
1/* SPDX-License-Identifier: GPL-2.0 */
2/* Copyright (c) 2018, Intel Corporation. */
3
4#ifndef _ICE_VIRTCHNL_PF_H_
5#define _ICE_VIRTCHNL_PF_H_
6#include "ice.h"
7#include "ice_virtchnl_fdir.h"
8
9/* Restrict number of MAC Addr and VLAN that non-trusted VF can programmed */
10#define ICE_MAX_VLAN_PER_VF 8
11/* MAC filters: 1 is reserved for the VF's default/perm_addr/LAA MAC, 1 for
12 * broadcast, and 16 for additional unicast/multicast filters
13 */
14#define ICE_MAX_MACADDR_PER_VF 18
15
16/* Malicious Driver Detection */
17#define ICE_DFLT_NUM_INVAL_MSGS_ALLOWED 10
18#define ICE_MDD_EVENTS_THRESHOLD 30
19
20/* Static VF transaction/status register def */
21#define VF_DEVICE_STATUS 0xAA
22#define VF_TRANS_PENDING_M 0x20
23
24/* wait defines for polling PF_PCI_CIAD register status */
25#define ICE_PCI_CIAD_WAIT_COUNT 100
26#define ICE_PCI_CIAD_WAIT_DELAY_US 1
27
28/* VF resource constraints */
29#define ICE_MAX_VF_COUNT 256
30#define ICE_MIN_QS_PER_VF 1
31#define ICE_NONQ_VECS_VF 1
32#define ICE_MAX_SCATTER_QS_PER_VF 16
33#define ICE_MAX_RSS_QS_PER_VF 16
34#define ICE_NUM_VF_MSIX_MED 17
35#define ICE_NUM_VF_MSIX_SMALL 5
36#define ICE_NUM_VF_MSIX_MULTIQ_MIN 3
37#define ICE_MIN_INTR_PER_VF (ICE_MIN_QS_PER_VF + 1)
38#define ICE_MAX_VF_RESET_TRIES 40
39#define ICE_MAX_VF_RESET_SLEEP_MS 20
40
41#define ice_for_each_vf(pf, i) \
42 for ((i) = 0; (i) < (pf)->num_alloc_vfs; (i)++)
43
44/* Specific VF states */
45enum ice_vf_states {
46 ICE_VF_STATE_INIT = 0, /* PF is initializing VF */
47 ICE_VF_STATE_ACTIVE, /* VF resources are allocated for use */
48 ICE_VF_STATE_QS_ENA, /* VF queue(s) enabled */
49 ICE_VF_STATE_DIS,
50 ICE_VF_STATE_MC_PROMISC,
51 ICE_VF_STATE_UC_PROMISC,
52 ICE_VF_STATES_NBITS
53};
54
55/* VF capabilities */
56enum ice_virtchnl_cap {
57 ICE_VIRTCHNL_VF_CAP_L2 = 0,
58 ICE_VIRTCHNL_VF_CAP_PRIVILEGE,
59};
60
61struct ice_time_mac {
62 unsigned long time_modified;
63 u8 addr[ETH_ALEN];
64};
65
66/* VF MDD events print structure */
67struct ice_mdd_vf_events {
68 u16 count; /* total count of Rx|Tx events */
69 /* count number of the last printed event */
70 u16 last_printed;
71};
72
73/* VF information structure */
74struct ice_vf {
75 struct ice_pf *pf;
76
77 u16 vf_id; /* VF ID in the PF space */
78 u16 lan_vsi_idx; /* index into PF struct */
79 u16 ctrl_vsi_idx;
80 struct ice_vf_fdir fdir;
81 /* first vector index of this VF in the PF space */
82 int first_vector_idx;
83 struct ice_sw *vf_sw_id; /* switch ID the VF VSIs connect to */
84 struct virtchnl_version_info vf_ver;
85 u32 driver_caps; /* reported by VF driver */
86 struct virtchnl_ether_addr dev_lan_addr;
87 struct virtchnl_ether_addr hw_lan_addr;
88 struct ice_time_mac legacy_last_added_umac;
89 DECLARE_BITMAP(txq_ena, ICE_MAX_RSS_QS_PER_VF);
90 DECLARE_BITMAP(rxq_ena, ICE_MAX_RSS_QS_PER_VF);
91 u16 port_vlan_info; /* Port VLAN ID and QoS */
92 u8 pf_set_mac:1; /* VF MAC address set by VMM admin */
93 u8 trusted:1;
94 u8 spoofchk:1;
95 u8 link_forced:1;
96 u8 link_up:1; /* only valid if VF link is forced */
97 /* VSI indices - actual VSI pointers are maintained in the PF structure
98 * When assigned, these will be non-zero, because VSI 0 is always
99 * the main LAN VSI for the PF.
100 */
101 u16 lan_vsi_num; /* ID as used by firmware */
102 unsigned int tx_rate; /* Tx bandwidth limit in Mbps */
103 DECLARE_BITMAP(vf_states, ICE_VF_STATES_NBITS); /* VF runtime states */
104
105 u64 num_inval_msgs; /* number of continuous invalid msgs */
106 u64 num_valid_msgs; /* number of valid msgs detected */
107 unsigned long vf_caps; /* VF's adv. capabilities */
108 u8 num_req_qs; /* num of queue pairs requested by VF */
109 u16 num_mac;
110 u16 num_vf_qs; /* num of queue configured per VF */
111 struct ice_mdd_vf_events mdd_rx_events;
112 struct ice_mdd_vf_events mdd_tx_events;
113 DECLARE_BITMAP(opcodes_allowlist, VIRTCHNL_OP_MAX);
114};
115
116#ifdef CONFIG_PCI_IOV
117void ice_process_vflr_event(struct ice_pf *pf);
118int ice_sriov_configure(struct pci_dev *pdev, int num_vfs);
119int ice_set_vf_mac(struct net_device *netdev, int vf_id, u8 *mac);
120int
121ice_get_vf_cfg(struct net_device *netdev, int vf_id, struct ifla_vf_info *ivi);
122
123void ice_free_vfs(struct ice_pf *pf);
124void ice_vc_process_vf_msg(struct ice_pf *pf, struct ice_rq_event_info *event);
125void ice_vc_notify_link_state(struct ice_pf *pf);
126void ice_vc_notify_reset(struct ice_pf *pf);
127bool ice_reset_all_vfs(struct ice_pf *pf, bool is_vflr);
128bool ice_reset_vf(struct ice_vf *vf, bool is_vflr);
129void ice_restore_all_vfs_msi_state(struct pci_dev *pdev);
130bool
131ice_is_malicious_vf(struct ice_pf *pf, struct ice_rq_event_info *event,
132 u16 num_msg_proc, u16 num_msg_pending);
133
134int
135ice_set_vf_port_vlan(struct net_device *netdev, int vf_id, u16 vlan_id, u8 qos,
136 __be16 vlan_proto);
137
138int ice_set_vf_trust(struct net_device *netdev, int vf_id, bool trusted);
139
140int ice_set_vf_link_state(struct net_device *netdev, int vf_id, int link_state);
141
142int ice_set_vf_spoofchk(struct net_device *netdev, int vf_id, bool ena);
143
144int ice_calc_vf_reg_idx(struct ice_vf *vf, struct ice_q_vector *q_vector);
145
146void ice_set_vf_state_qs_dis(struct ice_vf *vf);
147int
148ice_get_vf_stats(struct net_device *netdev, int vf_id,
149 struct ifla_vf_stats *vf_stats);
150bool ice_is_any_vf_in_promisc(struct ice_pf *pf);
151void
152ice_vf_lan_overflow_event(struct ice_pf *pf, struct ice_rq_event_info *event);
153void ice_print_vfs_mdd_events(struct ice_pf *pf);
154void ice_print_vf_rx_mdd_event(struct ice_vf *vf);
155struct ice_vsi *ice_vf_ctrl_vsi_setup(struct ice_vf *vf);
156int
157ice_vc_send_msg_to_vf(struct ice_vf *vf, u32 v_opcode,
158 enum virtchnl_status_code v_retval, u8 *msg, u16 msglen);
159bool ice_vc_isvalid_vsi_id(struct ice_vf *vf, u16 vsi_id);
160#else /* CONFIG_PCI_IOV */
161static inline void ice_process_vflr_event(struct ice_pf *pf) { }
162static inline void ice_free_vfs(struct ice_pf *pf) { }
163static inline
164void ice_vc_process_vf_msg(struct ice_pf *pf, struct ice_rq_event_info *event) { }
165static inline void ice_vc_notify_link_state(struct ice_pf *pf) { }
166static inline void ice_vc_notify_reset(struct ice_pf *pf) { }
167static inline void ice_set_vf_state_qs_dis(struct ice_vf *vf) { }
168static inline
169void ice_vf_lan_overflow_event(struct ice_pf *pf, struct ice_rq_event_info *event) { }
170static inline void ice_print_vfs_mdd_events(struct ice_pf *pf) { }
171static inline void ice_print_vf_rx_mdd_event(struct ice_vf *vf) { }
172static inline void ice_restore_all_vfs_msi_state(struct pci_dev *pdev) { }
173
174static inline bool
175ice_is_malicious_vf(struct ice_pf __always_unused *pf,
176 struct ice_rq_event_info __always_unused *event,
177 u16 __always_unused num_msg_proc,
178 u16 __always_unused num_msg_pending)
179{
180 return false;
181}
182
183static inline bool
184ice_reset_all_vfs(struct ice_pf __always_unused *pf,
185 bool __always_unused is_vflr)
186{
187 return true;
188}
189
190static inline bool
191ice_reset_vf(struct ice_vf __always_unused *vf, bool __always_unused is_vflr)
192{
193 return true;
194}
195
196static inline int
197ice_sriov_configure(struct pci_dev __always_unused *pdev,
198 int __always_unused num_vfs)
199{
200 return -EOPNOTSUPP;
201}
202
203static inline int
204ice_set_vf_mac(struct net_device __always_unused *netdev,
205 int __always_unused vf_id, u8 __always_unused *mac)
206{
207 return -EOPNOTSUPP;
208}
209
210static inline int
211ice_get_vf_cfg(struct net_device __always_unused *netdev,
212 int __always_unused vf_id,
213 struct ifla_vf_info __always_unused *ivi)
214{
215 return -EOPNOTSUPP;
216}
217
218static inline int
219ice_set_vf_trust(struct net_device __always_unused *netdev,
220 int __always_unused vf_id, bool __always_unused trusted)
221{
222 return -EOPNOTSUPP;
223}
224
225static inline int
226ice_set_vf_port_vlan(struct net_device __always_unused *netdev,
227 int __always_unused vf_id, u16 __always_unused vid,
228 u8 __always_unused qos, __be16 __always_unused v_proto)
229{
230 return -EOPNOTSUPP;
231}
232
233static inline int
234ice_set_vf_spoofchk(struct net_device __always_unused *netdev,
235 int __always_unused vf_id, bool __always_unused ena)
236{
237 return -EOPNOTSUPP;
238}
239
240static inline int
241ice_set_vf_link_state(struct net_device __always_unused *netdev,
242 int __always_unused vf_id, int __always_unused link_state)
243{
244 return -EOPNOTSUPP;
245}
246
247static inline int
248ice_calc_vf_reg_idx(struct ice_vf __always_unused *vf,
249 struct ice_q_vector __always_unused *q_vector)
250{
251 return 0;
252}
253
254static inline int
255ice_get_vf_stats(struct net_device __always_unused *netdev,
256 int __always_unused vf_id,
257 struct ifla_vf_stats __always_unused *vf_stats)
258{
259 return -EOPNOTSUPP;
260}
261
262static inline bool ice_is_any_vf_in_promisc(struct ice_pf __always_unused *pf)
263{
264 return false;
265}
266#endif /* CONFIG_PCI_IOV */
267#endif /* _ICE_VIRTCHNL_PF_H_ */