ice: Fix Port VLAN priority bits
[openwrt/staging/blogic.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 #define ICE_MAX_MACADDR_PER_VF 12
11
12 /* Malicious Driver Detection */
13 #define ICE_DFLT_NUM_INVAL_MSGS_ALLOWED 10
14 #define ICE_MDD_EVENTS_THRESHOLD 30
15
16 /* Static VF transaction/status register def */
17 #define VF_DEVICE_STATUS 0xAA
18 #define VF_TRANS_PENDING_M 0x20
19
20 /* wait defines for polling PF_PCI_CIAD register status */
21 #define ICE_PCI_CIAD_WAIT_COUNT 100
22 #define ICE_PCI_CIAD_WAIT_DELAY_US 1
23
24 /* VF resources default values and limitation */
25 #define ICE_MAX_VF_COUNT 256
26 #define ICE_MAX_QS_PER_VF 256
27 #define ICE_MIN_QS_PER_VF 1
28 #define ICE_DFLT_QS_PER_VF 4
29 #define ICE_NONQ_VECS_VF 1
30 #define ICE_MAX_SCATTER_QS_PER_VF 16
31 #define ICE_MAX_BASE_QS_PER_VF 16
32 #define ICE_MAX_INTR_PER_VF 65
33 #define ICE_MAX_POLICY_INTR_PER_VF 33
34 #define ICE_MIN_INTR_PER_VF (ICE_MIN_QS_PER_VF + 1)
35 #define ICE_DFLT_INTR_PER_VF (ICE_DFLT_QS_PER_VF + 1)
36 #define ICE_MAX_VF_RESET_WAIT 15
37
38 #define ice_for_each_vf(pf, i) \
39 for ((i) = 0; (i) < (pf)->num_alloc_vfs; (i)++)
40
41 /* Specific VF states */
42 enum ice_vf_states {
43 ICE_VF_STATE_INIT = 0, /* PF is initializing VF */
44 ICE_VF_STATE_ACTIVE, /* VF resources are allocated for use */
45 ICE_VF_STATE_QS_ENA, /* VF queue(s) enabled */
46 ICE_VF_STATE_DIS,
47 ICE_VF_STATE_MC_PROMISC,
48 ICE_VF_STATE_UC_PROMISC,
49 ICE_VF_STATES_NBITS
50 };
51
52 /* VF capabilities */
53 enum ice_virtchnl_cap {
54 ICE_VIRTCHNL_VF_CAP_L2 = 0,
55 ICE_VIRTCHNL_VF_CAP_PRIVILEGE,
56 };
57
58 /* VF information structure */
59 struct ice_vf {
60 struct ice_pf *pf;
61
62 s16 vf_id; /* VF ID in the PF space */
63 u16 lan_vsi_idx; /* index into PF struct */
64 /* first vector index of this VF in the PF space */
65 int first_vector_idx;
66 struct ice_sw *vf_sw_id; /* switch ID the VF VSIs connect to */
67 struct virtchnl_version_info vf_ver;
68 u32 driver_caps; /* reported by VF driver */
69 struct virtchnl_ether_addr dflt_lan_addr;
70 DECLARE_BITMAP(txq_ena, ICE_MAX_BASE_QS_PER_VF);
71 DECLARE_BITMAP(rxq_ena, ICE_MAX_BASE_QS_PER_VF);
72 u16 port_vlan_info; /* Port VLAN ID and QoS */
73 u8 pf_set_mac:1; /* VF MAC address set by VMM admin */
74 u8 trusted:1;
75 u8 spoofchk:1;
76 u8 link_forced:1;
77 u8 link_up:1; /* only valid if VF link is forced */
78 /* VSI indices - actual VSI pointers are maintained in the PF structure
79 * When assigned, these will be non-zero, because VSI 0 is always
80 * the main LAN VSI for the PF.
81 */
82 u16 lan_vsi_num; /* ID as used by firmware */
83 unsigned int tx_rate; /* Tx bandwidth limit in Mbps */
84 DECLARE_BITMAP(vf_states, ICE_VF_STATES_NBITS); /* VF runtime states */
85
86 u64 num_mdd_events; /* number of MDD events detected */
87 u64 num_inval_msgs; /* number of continuous invalid msgs */
88 u64 num_valid_msgs; /* number of valid msgs detected */
89 unsigned long vf_caps; /* VF's adv. capabilities */
90 u8 num_req_qs; /* num of queue pairs requested by VF */
91 u16 num_mac;
92 u16 num_vf_qs; /* num of queue configured per VF */
93 u16 num_qs_ena; /* total num of Tx/Rx queue enabled */
94 };
95
96 #ifdef CONFIG_PCI_IOV
97 void ice_process_vflr_event(struct ice_pf *pf);
98 int ice_sriov_configure(struct pci_dev *pdev, int num_vfs);
99 int ice_set_vf_mac(struct net_device *netdev, int vf_id, u8 *mac);
100 int
101 ice_get_vf_cfg(struct net_device *netdev, int vf_id, struct ifla_vf_info *ivi);
102
103 void ice_free_vfs(struct ice_pf *pf);
104 void ice_vc_process_vf_msg(struct ice_pf *pf, struct ice_rq_event_info *event);
105 void ice_vc_notify_link_state(struct ice_pf *pf);
106 void ice_vc_notify_reset(struct ice_pf *pf);
107 bool ice_reset_all_vfs(struct ice_pf *pf, bool is_vflr);
108
109 int
110 ice_set_vf_port_vlan(struct net_device *netdev, int vf_id, u16 vlan_id, u8 qos,
111 __be16 vlan_proto);
112
113 int ice_set_vf_trust(struct net_device *netdev, int vf_id, bool trusted);
114
115 int ice_set_vf_link_state(struct net_device *netdev, int vf_id, int link_state);
116
117 int ice_set_vf_spoofchk(struct net_device *netdev, int vf_id, bool ena);
118
119 int ice_calc_vf_reg_idx(struct ice_vf *vf, struct ice_q_vector *q_vector);
120
121 void ice_set_vf_state_qs_dis(struct ice_vf *vf);
122 int
123 ice_get_vf_stats(struct net_device *netdev, int vf_id,
124 struct ifla_vf_stats *vf_stats);
125 #else /* CONFIG_PCI_IOV */
126 #define ice_process_vflr_event(pf) do {} while (0)
127 #define ice_free_vfs(pf) do {} while (0)
128 #define ice_vc_process_vf_msg(pf, event) do {} while (0)
129 #define ice_vc_notify_link_state(pf) do {} while (0)
130 #define ice_vc_notify_reset(pf) do {} while (0)
131 #define ice_set_vf_state_qs_dis(vf) do {} while (0)
132
133 static inline bool
134 ice_reset_all_vfs(struct ice_pf __always_unused *pf,
135 bool __always_unused is_vflr)
136 {
137 return true;
138 }
139
140 static inline int
141 ice_sriov_configure(struct pci_dev __always_unused *pdev,
142 int __always_unused num_vfs)
143 {
144 return -EOPNOTSUPP;
145 }
146
147 static inline int
148 ice_set_vf_mac(struct net_device __always_unused *netdev,
149 int __always_unused vf_id, u8 __always_unused *mac)
150 {
151 return -EOPNOTSUPP;
152 }
153
154 static inline int
155 ice_get_vf_cfg(struct net_device __always_unused *netdev,
156 int __always_unused vf_id,
157 struct ifla_vf_info __always_unused *ivi)
158 {
159 return -EOPNOTSUPP;
160 }
161
162 static inline int
163 ice_set_vf_trust(struct net_device __always_unused *netdev,
164 int __always_unused vf_id, bool __always_unused trusted)
165 {
166 return -EOPNOTSUPP;
167 }
168
169 static inline int
170 ice_set_vf_port_vlan(struct net_device __always_unused *netdev,
171 int __always_unused vf_id, u16 __always_unused vid,
172 u8 __always_unused qos, __be16 __always_unused v_proto)
173 {
174 return -EOPNOTSUPP;
175 }
176
177 static inline int
178 ice_set_vf_spoofchk(struct net_device __always_unused *netdev,
179 int __always_unused vf_id, bool __always_unused ena)
180 {
181 return -EOPNOTSUPP;
182 }
183
184 static inline int
185 ice_set_vf_link_state(struct net_device __always_unused *netdev,
186 int __always_unused vf_id, int __always_unused link_state)
187 {
188 return -EOPNOTSUPP;
189 }
190
191 static inline int
192 ice_calc_vf_reg_idx(struct ice_vf __always_unused *vf,
193 struct ice_q_vector __always_unused *q_vector)
194 {
195 return 0;
196 }
197
198 static inline int
199 ice_get_vf_stats(struct net_device __always_unused *netdev,
200 int __always_unused vf_id,
201 struct ifla_vf_stats __always_unused *vf_stats)
202 {
203 return -EOPNOTSUPP;
204 }
205 #endif /* CONFIG_PCI_IOV */
206 #endif /* _ICE_VIRTCHNL_PF_H_ */