GNU Linux-libre 5.10.215-gnu1
[releases.git] / drivers / net / ethernet / intel / ice / 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
8 /* Restrict number of MAC Addr and VLAN that non-trusted VF can programmed */
9 #define ICE_MAX_VLAN_PER_VF             8
10 /* MAC filters: 1 is reserved for the VF's default/perm_addr/LAA MAC, 1 for
11  * broadcast, and 16 for additional unicast/multicast filters
12  */
13 #define ICE_MAX_MACADDR_PER_VF          18
14
15 /* Malicious Driver Detection */
16 #define ICE_MDD_EVENTS_THRESHOLD                30
17
18 /* Static VF transaction/status register def */
19 #define VF_DEVICE_STATUS                0xAA
20 #define VF_TRANS_PENDING_M              0x20
21
22 /* wait defines for polling PF_PCI_CIAD register status */
23 #define ICE_PCI_CIAD_WAIT_COUNT         100
24 #define ICE_PCI_CIAD_WAIT_DELAY_US      1
25
26 /* VF resource constraints */
27 #define ICE_MAX_VF_COUNT                256
28 #define ICE_MIN_QS_PER_VF               1
29 #define ICE_NONQ_VECS_VF                1
30 #define ICE_MAX_SCATTER_QS_PER_VF       16
31 #define ICE_MAX_RSS_QS_PER_VF           16
32 #define ICE_NUM_VF_MSIX_MED             17
33 #define ICE_NUM_VF_MSIX_SMALL           5
34 #define ICE_NUM_VF_MSIX_MULTIQ_MIN      3
35 #define ICE_MIN_INTR_PER_VF             (ICE_MIN_QS_PER_VF + 1)
36 #define ICE_MAX_VF_RESET_TRIES          40
37 #define ICE_MAX_VF_RESET_SLEEP_MS       20
38
39 #define ice_for_each_vf(pf, i) \
40         for ((i) = 0; (i) < (pf)->num_alloc_vfs; (i)++)
41
42 /* Specific VF states */
43 enum 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 */
54 enum ice_virtchnl_cap {
55         ICE_VIRTCHNL_VF_CAP_L2 = 0,
56         ICE_VIRTCHNL_VF_CAP_PRIVILEGE,
57 };
58
59 /* VF MDD events print structure */
60 struct ice_mdd_vf_events {
61         u16 count;                      /* total count of Rx|Tx events */
62         /* count number of the last printed event */
63         u16 last_printed;
64 };
65
66 /* VF information structure */
67 struct ice_vf {
68         struct ice_pf *pf;
69
70         /* Used during virtchnl message handling and NDO ops against the VF
71          * that will trigger a VFR
72          */
73         struct mutex cfg_lock;
74
75         u16 vf_id;                      /* VF ID in the PF space */
76         u16 lan_vsi_idx;                /* index into PF struct */
77         /* first vector index of this VF in the PF space */
78         int first_vector_idx;
79         struct ice_sw *vf_sw_id;        /* switch ID the VF VSIs connect to */
80         struct virtchnl_version_info vf_ver;
81         u32 driver_caps;                /* reported by VF driver */
82         struct virtchnl_ether_addr dflt_lan_addr;
83         DECLARE_BITMAP(txq_ena, ICE_MAX_RSS_QS_PER_VF);
84         DECLARE_BITMAP(rxq_ena, ICE_MAX_RSS_QS_PER_VF);
85         u16 port_vlan_info;             /* Port VLAN ID and QoS */
86         u8 pf_set_mac:1;                /* VF MAC address set by VMM admin */
87         u8 trusted:1;
88         u8 spoofchk:1;
89         u8 link_forced:1;
90         u8 link_up:1;                   /* only valid if VF link is forced */
91         /* VSI indices - actual VSI pointers are maintained in the PF structure
92          * When assigned, these will be non-zero, because VSI 0 is always
93          * the main LAN VSI for the PF.
94          */
95         u16 lan_vsi_num;                /* ID as used by firmware */
96         unsigned int tx_rate;           /* Tx bandwidth limit in Mbps */
97         DECLARE_BITMAP(vf_states, ICE_VF_STATES_NBITS); /* VF runtime states */
98
99         unsigned long vf_caps;          /* VF's adv. capabilities */
100         u8 num_req_qs;                  /* num of queue pairs requested by VF */
101         u16 num_mac;
102         u16 num_vf_qs;                  /* num of queue configured per VF */
103         struct ice_mdd_vf_events mdd_rx_events;
104         struct ice_mdd_vf_events mdd_tx_events;
105 };
106
107 #ifdef CONFIG_PCI_IOV
108 void ice_process_vflr_event(struct ice_pf *pf);
109 int ice_sriov_configure(struct pci_dev *pdev, int num_vfs);
110 int ice_set_vf_mac(struct net_device *netdev, int vf_id, u8 *mac);
111 int
112 ice_get_vf_cfg(struct net_device *netdev, int vf_id, struct ifla_vf_info *ivi);
113
114 void ice_free_vfs(struct ice_pf *pf);
115 void ice_vc_process_vf_msg(struct ice_pf *pf, struct ice_rq_event_info *event);
116 void ice_vc_notify_link_state(struct ice_pf *pf);
117 void ice_vc_notify_reset(struct ice_pf *pf);
118 bool ice_reset_all_vfs(struct ice_pf *pf, bool is_vflr);
119 bool ice_reset_vf(struct ice_vf *vf, bool is_vflr);
120 void ice_restore_all_vfs_msi_state(struct pci_dev *pdev);
121
122 int
123 ice_set_vf_port_vlan(struct net_device *netdev, int vf_id, u16 vlan_id, u8 qos,
124                      __be16 vlan_proto);
125
126 int ice_set_vf_trust(struct net_device *netdev, int vf_id, bool trusted);
127
128 int ice_set_vf_link_state(struct net_device *netdev, int vf_id, int link_state);
129
130 int ice_set_vf_spoofchk(struct net_device *netdev, int vf_id, bool ena);
131
132 int ice_calc_vf_reg_idx(struct ice_vf *vf, struct ice_q_vector *q_vector);
133
134 void ice_set_vf_state_qs_dis(struct ice_vf *vf);
135 int
136 ice_get_vf_stats(struct net_device *netdev, int vf_id,
137                  struct ifla_vf_stats *vf_stats);
138 bool ice_is_any_vf_in_promisc(struct ice_pf *pf);
139 void
140 ice_vf_lan_overflow_event(struct ice_pf *pf, struct ice_rq_event_info *event);
141 void ice_print_vfs_mdd_events(struct ice_pf *pf);
142 void ice_print_vf_rx_mdd_event(struct ice_vf *vf);
143 #else /* CONFIG_PCI_IOV */
144 #define ice_process_vflr_event(pf) do {} while (0)
145 #define ice_free_vfs(pf) do {} while (0)
146 #define ice_vc_process_vf_msg(pf, event) do {} while (0)
147 #define ice_vc_notify_link_state(pf) do {} while (0)
148 #define ice_vc_notify_reset(pf) do {} while (0)
149 #define ice_set_vf_state_qs_dis(vf) do {} while (0)
150 #define ice_vf_lan_overflow_event(pf, event) do {} while (0)
151 #define ice_print_vfs_mdd_events(pf) do {} while (0)
152 #define ice_print_vf_rx_mdd_event(vf) do {} while (0)
153 #define ice_restore_all_vfs_msi_state(pdev) do {} while (0)
154
155 static inline bool
156 ice_reset_all_vfs(struct ice_pf __always_unused *pf,
157                   bool __always_unused is_vflr)
158 {
159         return true;
160 }
161
162 static inline bool
163 ice_reset_vf(struct ice_vf __always_unused *vf, bool __always_unused is_vflr)
164 {
165         return true;
166 }
167
168 static inline int
169 ice_sriov_configure(struct pci_dev __always_unused *pdev,
170                     int __always_unused num_vfs)
171 {
172         return -EOPNOTSUPP;
173 }
174
175 static inline int
176 ice_set_vf_mac(struct net_device __always_unused *netdev,
177                int __always_unused vf_id, u8 __always_unused *mac)
178 {
179         return -EOPNOTSUPP;
180 }
181
182 static inline int
183 ice_get_vf_cfg(struct net_device __always_unused *netdev,
184                int __always_unused vf_id,
185                struct ifla_vf_info __always_unused *ivi)
186 {
187         return -EOPNOTSUPP;
188 }
189
190 static inline int
191 ice_set_vf_trust(struct net_device __always_unused *netdev,
192                  int __always_unused vf_id, bool __always_unused trusted)
193 {
194         return -EOPNOTSUPP;
195 }
196
197 static inline int
198 ice_set_vf_port_vlan(struct net_device __always_unused *netdev,
199                      int __always_unused vf_id, u16 __always_unused vid,
200                      u8 __always_unused qos, __be16 __always_unused v_proto)
201 {
202         return -EOPNOTSUPP;
203 }
204
205 static inline int
206 ice_set_vf_spoofchk(struct net_device __always_unused *netdev,
207                     int __always_unused vf_id, bool __always_unused ena)
208 {
209         return -EOPNOTSUPP;
210 }
211
212 static inline int
213 ice_set_vf_link_state(struct net_device __always_unused *netdev,
214                       int __always_unused vf_id, int __always_unused link_state)
215 {
216         return -EOPNOTSUPP;
217 }
218
219 static inline int
220 ice_calc_vf_reg_idx(struct ice_vf __always_unused *vf,
221                     struct ice_q_vector __always_unused *q_vector)
222 {
223         return 0;
224 }
225
226 static inline int
227 ice_get_vf_stats(struct net_device __always_unused *netdev,
228                  int __always_unused vf_id,
229                  struct ifla_vf_stats __always_unused *vf_stats)
230 {
231         return -EOPNOTSUPP;
232 }
233
234 static inline bool ice_is_any_vf_in_promisc(struct ice_pf __always_unused *pf)
235 {
236         return false;
237 }
238 #endif /* CONFIG_PCI_IOV */
239 #endif /* _ICE_VIRTCHNL_PF_H_ */