Commit | Line | Data |
---|---|---|
1f4d4ed6 | 1 | /* SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause) */ |
32a47e72 | 2 | /* QLogic qed NIC Driver |
e8f1cb50 | 3 | * Copyright (c) 2015-2017 QLogic Corporation |
663eacd8 | 4 | * Copyright (c) 2019-2020 Marvell International Ltd. |
32a47e72 YM |
5 | */ |
6 | ||
7 | #ifndef _QED_SRIOV_H | |
8 | #define _QED_SRIOV_H | |
9 | #include <linux/types.h> | |
10 | #include "qed_vf.h" | |
1cf2b1a9 YM |
11 | |
12 | #define QED_ETH_VF_NUM_MAC_FILTERS 1 | |
13 | #define QED_ETH_VF_NUM_VLAN_FILTERS 2 | |
32a47e72 YM |
14 | #define QED_VF_ARRAY_LENGTH (3) |
15 | ||
14b84e86 | 16 | #ifdef CONFIG_QED_SRIOV |
6da95b52 AP |
17 | #define IS_VF(cdev) ((cdev)->b_is_vf) |
18 | #define IS_PF(cdev) (!((cdev)->b_is_vf)) | |
19 | #define IS_PF_SRIOV(p_hwfn) (!!((p_hwfn)->cdev->p_iov_info)) | |
32a47e72 | 20 | #else |
14b84e86 AB |
21 | #define IS_VF(cdev) (0) |
22 | #define IS_PF(cdev) (1) | |
32a47e72 YM |
23 | #define IS_PF_SRIOV(p_hwfn) (0) |
24 | #endif | |
25 | #define IS_PF_SRIOV_ALLOC(p_hwfn) (!!((p_hwfn)->pf_iov_info)) | |
26 | ||
1408cc1f | 27 | #define QED_MAX_VF_CHAINS_PER_PF 16 |
1408cc1f | 28 | |
08feecd7 YM |
29 | #define QED_ETH_MAX_VF_NUM_VLAN_FILTERS \ |
30 | (MAX_NUM_VFS * QED_ETH_VF_NUM_VLAN_FILTERS) | |
31 | ||
dacd88d6 YM |
32 | enum qed_iov_vport_update_flag { |
33 | QED_IOV_VP_UPDATE_ACTIVATE, | |
17b235c1 YM |
34 | QED_IOV_VP_UPDATE_VLAN_STRIP, |
35 | QED_IOV_VP_UPDATE_TX_SWITCH, | |
dacd88d6 YM |
36 | QED_IOV_VP_UPDATE_MCAST, |
37 | QED_IOV_VP_UPDATE_ACCEPT_PARAM, | |
38 | QED_IOV_VP_UPDATE_RSS, | |
17b235c1 YM |
39 | QED_IOV_VP_UPDATE_ACCEPT_ANY_VLAN, |
40 | QED_IOV_VP_UPDATE_SGE_TPA, | |
dacd88d6 YM |
41 | QED_IOV_VP_UPDATE_MAX, |
42 | }; | |
43 | ||
0b55e27d YM |
44 | struct qed_public_vf_info { |
45 | /* These copies will later be reflected in the bulletin board, | |
46 | * but this copy should be newer. | |
47 | */ | |
eff16960 | 48 | u8 forced_mac[ETH_ALEN]; |
08feecd7 | 49 | u16 forced_vlan; |
0b55e27d | 50 | u8 mac[ETH_ALEN]; |
733def6a YM |
51 | |
52 | /* IFLA_VF_LINK_STATE_<X> */ | |
53 | int link_state; | |
54 | ||
55 | /* Currently configured Tx rate in MB/sec. 0 if unconfigured */ | |
56 | int tx_rate; | |
f990c82c MY |
57 | |
58 | /* Trusted VFs can configure promiscuous mode. | |
59 | * Also store shadow promisc configuration if needed. | |
60 | */ | |
61 | bool is_trusted_configured; | |
62 | bool is_trusted_request; | |
63 | u8 rx_accept_mode; | |
64 | u8 tx_accept_mode; | |
0b55e27d YM |
65 | }; |
66 | ||
3da7a37a MY |
67 | struct qed_iov_vf_init_params { |
68 | u16 rel_vf_id; | |
69 | ||
70 | /* Number of requested Queues; Currently, don't support different | |
71 | * number of Rx/Tx queues. | |
72 | */ | |
73 | ||
74 | u16 num_queues; | |
75 | ||
76 | /* Allow the client to choose which qzones to use for Rx/Tx, | |
77 | * and which queue_base to use for Tx queues on a per-queue basis. | |
78 | * Notice values should be relative to the PF resources. | |
79 | */ | |
80 | u16 req_rx_queue[QED_MAX_VF_CHAINS_PER_PF]; | |
81 | u16 req_tx_queue[QED_MAX_VF_CHAINS_PER_PF]; | |
82 | }; | |
83 | ||
32a47e72 YM |
84 | /* This struct is part of qed_dev and contains data relevant to all hwfns; |
85 | * Initialized only if SR-IOV cpabability is exposed in PCIe config space. | |
86 | */ | |
87 | struct qed_hw_sriov_info { | |
88 | int pos; /* capability position */ | |
89 | int nres; /* number of resources */ | |
90 | u32 cap; /* SR-IOV Capabilities */ | |
91 | u16 ctrl; /* SR-IOV Control */ | |
92 | u16 total_vfs; /* total VFs associated with the PF */ | |
93 | u16 num_vfs; /* number of vfs that have been started */ | |
94 | u16 initial_vfs; /* initial VFs associated with the PF */ | |
95 | u16 nr_virtfn; /* number of VFs available */ | |
96 | u16 offset; /* first VF Routing ID offset */ | |
97 | u16 stride; /* following VF stride */ | |
98 | u16 vf_device_id; /* VF device id */ | |
99 | u32 pgsz; /* page size for BAR alignment */ | |
100 | u8 link; /* Function Dependency Link */ | |
101 | ||
102 | u32 first_vf_in_pf; | |
103 | }; | |
104 | ||
105 | /* This mailbox is maintained per VF in its PF contains all information | |
106 | * required for sending / receiving a message. | |
107 | */ | |
108 | struct qed_iov_vf_mbx { | |
109 | union vfpf_tlvs *req_virt; | |
110 | dma_addr_t req_phys; | |
111 | union pfvf_tlvs *reply_virt; | |
112 | dma_addr_t reply_phys; | |
37bff2b9 YM |
113 | |
114 | /* Address in VF where a pending message is located */ | |
115 | dma_addr_t pending_req; | |
116 | ||
fd3c615a MY |
117 | /* Message from VF awaits handling */ |
118 | bool b_pending_msg; | |
119 | ||
37bff2b9 YM |
120 | u8 *offset; |
121 | ||
122 | /* saved VF request header */ | |
123 | struct vfpf_first_tlv first_tlv; | |
32a47e72 YM |
124 | }; |
125 | ||
bbe3f233 MY |
126 | #define QED_IOV_LEGACY_QID_RX (0) |
127 | #define QED_IOV_LEGACY_QID_TX (1) | |
08bc8f15 | 128 | #define QED_IOV_QID_INVALID (0xFE) |
bbe3f233 | 129 | |
007bc371 MY |
130 | struct qed_vf_queue_cid { |
131 | bool b_is_tx; | |
132 | struct qed_queue_cid *p_cid; | |
133 | }; | |
134 | ||
135 | /* Describes a qzone associated with the VF */ | |
136 | struct qed_vf_queue { | |
1408cc1f YM |
137 | u16 fw_rx_qid; |
138 | u16 fw_tx_qid; | |
007bc371 MY |
139 | |
140 | struct qed_vf_queue_cid cids[MAX_QUEUES_PER_QZONE]; | |
1408cc1f YM |
141 | }; |
142 | ||
32a47e72 | 143 | enum vf_state { |
1408cc1f YM |
144 | VF_FREE = 0, /* VF ready to be acquired holds no resc */ |
145 | VF_ACQUIRED, /* VF, acquired, but not initalized */ | |
dacd88d6 | 146 | VF_ENABLED, /* VF, Enabled */ |
0b55e27d | 147 | VF_RESET, /* VF, FLR'd, pending cleanup */ |
32a47e72 YM |
148 | VF_STOPPED /* VF, Stopped */ |
149 | }; | |
150 | ||
08feecd7 YM |
151 | struct qed_vf_vlan_shadow { |
152 | bool used; | |
153 | u16 vid; | |
154 | }; | |
155 | ||
156 | struct qed_vf_shadow_config { | |
157 | /* Shadow copy of all guest vlans */ | |
158 | struct qed_vf_vlan_shadow vlans[QED_ETH_VF_NUM_VLAN_FILTERS + 1]; | |
159 | ||
8246d0b4 YM |
160 | /* Shadow copy of all configured MACs; Empty if forcing MACs */ |
161 | u8 macs[QED_ETH_VF_NUM_MAC_FILTERS][ETH_ALEN]; | |
08feecd7 YM |
162 | u8 inner_vlan_removal; |
163 | }; | |
164 | ||
32a47e72 YM |
165 | /* PFs maintain an array of this structure, per VF */ |
166 | struct qed_vf_info { | |
167 | struct qed_iov_vf_mbx vf_mbx; | |
168 | enum vf_state state; | |
169 | bool b_init; | |
7eff82b0 | 170 | bool b_malicious; |
0b55e27d | 171 | u8 to_disable; |
32a47e72 YM |
172 | |
173 | struct qed_bulletin bulletin; | |
174 | dma_addr_t vf_bulletin; | |
175 | ||
1fe614d1 YM |
176 | /* PF saves a copy of the last VF acquire message */ |
177 | struct vfpf_acquire_tlv acquire; | |
178 | ||
32a47e72 YM |
179 | u32 concrete_fid; |
180 | u16 opaque_fid; | |
dacd88d6 | 181 | u16 mtu; |
32a47e72 YM |
182 | |
183 | u8 vport_id; | |
184 | u8 relative_vf_id; | |
185 | u8 abs_vf_id; | |
186 | #define QED_VF_ABS_ID(p_hwfn, p_vf) (QED_PATH_ID(p_hwfn) ? \ | |
187 | (p_vf)->abs_vf_id + MAX_NUM_VFS_BB : \ | |
188 | (p_vf)->abs_vf_id) | |
1408cc1f | 189 | |
dacd88d6 | 190 | u8 vport_instance; |
1408cc1f YM |
191 | u8 num_rxqs; |
192 | u8 num_txqs; | |
193 | ||
bf5a94bf RV |
194 | u16 rx_coal; |
195 | u16 tx_coal; | |
196 | ||
1408cc1f YM |
197 | u8 num_sbs; |
198 | ||
199 | u8 num_mac_filters; | |
200 | u8 num_vlan_filters; | |
007bc371 MY |
201 | |
202 | struct qed_vf_queue vf_queues[QED_MAX_VF_CHAINS_PER_PF]; | |
1408cc1f | 203 | u16 igu_sbs[QED_MAX_VF_CHAINS_PER_PF]; |
dacd88d6 | 204 | u8 num_active_rxqs; |
0b55e27d | 205 | struct qed_public_vf_info p_vf_info; |
6ddc7608 YM |
206 | bool spoof_chk; |
207 | bool req_spoofchk_val; | |
08feecd7 YM |
208 | |
209 | /* Stores the configuration requested by VF */ | |
210 | struct qed_vf_shadow_config shadow_config; | |
211 | ||
212 | /* A bitfield using bulletin's valid-map bits, used to indicate | |
213 | * which of the bulletin board features have been configured. | |
214 | */ | |
215 | u64 configured_features; | |
216 | #define QED_IOV_CONFIGURED_FEATURES_MASK ((1 << MAC_ADDR_FORCED) | \ | |
217 | (1 << VLAN_ADDR_FORCED)) | |
32a47e72 YM |
218 | }; |
219 | ||
220 | /* This structure is part of qed_hwfn and used only for PFs that have sriov | |
221 | * capability enabled. | |
222 | */ | |
223 | struct qed_pf_iov { | |
224 | struct qed_vf_info vfs_array[MAX_NUM_VFS]; | |
32a47e72 YM |
225 | u64 pending_flr[QED_VF_ARRAY_LENGTH]; |
226 | ||
227 | /* Allocate message address continuosuly and split to each VF */ | |
228 | void *mbx_msg_virt_addr; | |
229 | dma_addr_t mbx_msg_phys_addr; | |
230 | u32 mbx_msg_size; | |
231 | void *mbx_reply_virt_addr; | |
232 | dma_addr_t mbx_reply_phys_addr; | |
233 | u32 mbx_reply_size; | |
234 | void *p_bulletins; | |
235 | dma_addr_t bulletins_phys; | |
236 | u32 bulletins_size; | |
237 | }; | |
238 | ||
37bff2b9 YM |
239 | enum qed_iov_wq_flag { |
240 | QED_IOV_WQ_MSG_FLAG, | |
241 | QED_IOV_WQ_SET_UNICAST_FILTER_FLAG, | |
242 | QED_IOV_WQ_BULLETIN_UPDATE_FLAG, | |
243 | QED_IOV_WQ_STOP_WQ_FLAG, | |
244 | QED_IOV_WQ_FLR_FLAG, | |
f990c82c | 245 | QED_IOV_WQ_TRUST_FLAG, |
65ed2ffd | 246 | QED_IOV_WQ_VF_FORCE_LINK_QUERY_FLAG, |
37bff2b9 YM |
247 | }; |
248 | ||
32a47e72 | 249 | #ifdef CONFIG_QED_SRIOV |
da090917 TT |
250 | /** |
251 | * @brief Check if given VF ID @vfid is valid | |
252 | * w.r.t. @b_enabled_only value | |
253 | * if b_enabled_only = true - only enabled VF id is valid | |
254 | * else any VF id less than max_vfs is valid | |
255 | * | |
256 | * @param p_hwfn | |
257 | * @param rel_vf_id - Relative VF ID | |
258 | * @param b_enabled_only - consider only enabled VF | |
259 | * @param b_non_malicious - true iff we want to validate vf isn't malicious. | |
260 | * | |
261 | * @return bool - true for valid VF ID | |
262 | */ | |
263 | bool qed_iov_is_valid_vfid(struct qed_hwfn *p_hwfn, | |
264 | int rel_vf_id, | |
265 | bool b_enabled_only, bool b_non_malicious); | |
266 | ||
32a47e72 YM |
267 | /** |
268 | * @brief - Given a VF index, return index of next [including that] active VF. | |
269 | * | |
270 | * @param p_hwfn | |
271 | * @param rel_vf_id | |
272 | * | |
273 | * @return MAX_NUM_VFS in case no further active VFs, otherwise index. | |
274 | */ | |
275 | u16 qed_iov_get_next_active_vf(struct qed_hwfn *p_hwfn, u16 rel_vf_id); | |
276 | ||
97379f15 CM |
277 | void qed_iov_bulletin_set_udp_ports(struct qed_hwfn *p_hwfn, |
278 | int vfid, u16 vxlan_port, u16 geneve_port); | |
279 | ||
32a47e72 YM |
280 | /** |
281 | * @brief Read sriov related information and allocated resources | |
c199ce4f | 282 | * reads from configuration space, shmem, etc. |
32a47e72 YM |
283 | * |
284 | * @param p_hwfn | |
285 | * | |
286 | * @return int | |
287 | */ | |
288 | int qed_iov_hw_info(struct qed_hwfn *p_hwfn); | |
289 | ||
1408cc1f YM |
290 | /** |
291 | * @brief qed_add_tlv - place a given tlv on the tlv buffer at next offset | |
292 | * | |
293 | * @param p_hwfn | |
294 | * @param p_iov | |
295 | * @param type | |
296 | * @param length | |
297 | * | |
298 | * @return pointer to the newly placed tlv | |
299 | */ | |
300 | void *qed_add_tlv(struct qed_hwfn *p_hwfn, u8 **offset, u16 type, u16 length); | |
301 | ||
302 | /** | |
303 | * @brief list the types and lengths of the tlvs on the buffer | |
304 | * | |
305 | * @param p_hwfn | |
306 | * @param tlvs_list | |
307 | */ | |
308 | void qed_dp_tlv_list(struct qed_hwfn *p_hwfn, void *tlvs_list); | |
309 | ||
32a47e72 YM |
310 | /** |
311 | * @brief qed_iov_alloc - allocate sriov related resources | |
312 | * | |
313 | * @param p_hwfn | |
314 | * | |
315 | * @return int | |
316 | */ | |
317 | int qed_iov_alloc(struct qed_hwfn *p_hwfn); | |
318 | ||
319 | /** | |
320 | * @brief qed_iov_setup - setup sriov related resources | |
321 | * | |
322 | * @param p_hwfn | |
32a47e72 | 323 | */ |
1ee240e3 | 324 | void qed_iov_setup(struct qed_hwfn *p_hwfn); |
32a47e72 YM |
325 | |
326 | /** | |
327 | * @brief qed_iov_free - free sriov related resources | |
328 | * | |
329 | * @param p_hwfn | |
330 | */ | |
331 | void qed_iov_free(struct qed_hwfn *p_hwfn); | |
332 | ||
333 | /** | |
334 | * @brief free sriov related memory that was allocated during hw_prepare | |
335 | * | |
336 | * @param cdev | |
337 | */ | |
338 | void qed_iov_free_hw_info(struct qed_dev *cdev); | |
37bff2b9 | 339 | |
0b55e27d YM |
340 | /** |
341 | * @brief Mark structs of vfs that have been FLR-ed. | |
342 | * | |
343 | * @param p_hwfn | |
344 | * @param disabled_vfs - bitmask of all VFs on path that were FLRed | |
345 | * | |
cccf6f5c | 346 | * @return true iff one of the PF's vfs got FLRed. false otherwise. |
0b55e27d | 347 | */ |
cccf6f5c | 348 | bool qed_iov_mark_vf_flr(struct qed_hwfn *p_hwfn, u32 *disabled_vfs); |
0b55e27d | 349 | |
dacd88d6 YM |
350 | /** |
351 | * @brief Search extended TLVs in request/reply buffer. | |
352 | * | |
353 | * @param p_hwfn | |
354 | * @param p_tlvs_list - Pointer to tlvs list | |
355 | * @param req_type - Type of TLV | |
356 | * | |
357 | * @return pointer to tlv type if found, otherwise returns NULL. | |
358 | */ | |
359 | void *qed_iov_search_list_tlvs(struct qed_hwfn *p_hwfn, | |
360 | void *p_tlvs_list, u16 req_type); | |
361 | ||
37bff2b9 YM |
362 | void qed_iov_wq_stop(struct qed_dev *cdev, bool schedule_first); |
363 | int qed_iov_wq_start(struct qed_dev *cdev); | |
364 | ||
365 | void qed_schedule_iov(struct qed_hwfn *hwfn, enum qed_iov_wq_flag flag); | |
1408cc1f | 366 | void qed_vf_start_iov_wq(struct qed_dev *cdev); |
0b55e27d | 367 | int qed_sriov_disable(struct qed_dev *cdev, bool pci_enabled); |
36558c3d | 368 | void qed_inform_vf_link_state(struct qed_hwfn *hwfn); |
32a47e72 | 369 | #else |
da090917 TT |
370 | static inline bool |
371 | qed_iov_is_valid_vfid(struct qed_hwfn *p_hwfn, | |
372 | int rel_vf_id, bool b_enabled_only, bool b_non_malicious) | |
373 | { | |
374 | return false; | |
375 | } | |
376 | ||
32a47e72 YM |
377 | static inline u16 qed_iov_get_next_active_vf(struct qed_hwfn *p_hwfn, |
378 | u16 rel_vf_id) | |
379 | { | |
380 | return MAX_NUM_VFS; | |
381 | } | |
382 | ||
97379f15 CM |
383 | static inline void |
384 | qed_iov_bulletin_set_udp_ports(struct qed_hwfn *p_hwfn, int vfid, | |
385 | u16 vxlan_port, u16 geneve_port) | |
386 | { | |
387 | } | |
388 | ||
32a47e72 YM |
389 | static inline int qed_iov_hw_info(struct qed_hwfn *p_hwfn) |
390 | { | |
391 | return 0; | |
392 | } | |
393 | ||
394 | static inline int qed_iov_alloc(struct qed_hwfn *p_hwfn) | |
395 | { | |
396 | return 0; | |
397 | } | |
398 | ||
1ee240e3 | 399 | static inline void qed_iov_setup(struct qed_hwfn *p_hwfn) |
32a47e72 YM |
400 | { |
401 | } | |
402 | ||
403 | static inline void qed_iov_free(struct qed_hwfn *p_hwfn) | |
404 | { | |
405 | } | |
406 | ||
407 | static inline void qed_iov_free_hw_info(struct qed_dev *cdev) | |
408 | { | |
409 | } | |
37bff2b9 | 410 | |
cccf6f5c MY |
411 | static inline bool qed_iov_mark_vf_flr(struct qed_hwfn *p_hwfn, |
412 | u32 *disabled_vfs) | |
0b55e27d | 413 | { |
cccf6f5c | 414 | return false; |
0b55e27d YM |
415 | } |
416 | ||
37bff2b9 YM |
417 | static inline void qed_iov_wq_stop(struct qed_dev *cdev, bool schedule_first) |
418 | { | |
419 | } | |
420 | ||
421 | static inline int qed_iov_wq_start(struct qed_dev *cdev) | |
422 | { | |
423 | return 0; | |
424 | } | |
425 | ||
426 | static inline void qed_schedule_iov(struct qed_hwfn *hwfn, | |
427 | enum qed_iov_wq_flag flag) | |
428 | { | |
429 | } | |
1408cc1f YM |
430 | |
431 | static inline void qed_vf_start_iov_wq(struct qed_dev *cdev) | |
432 | { | |
433 | } | |
0b55e27d YM |
434 | |
435 | static inline int qed_sriov_disable(struct qed_dev *cdev, bool pci_enabled) | |
436 | { | |
437 | return 0; | |
438 | } | |
36558c3d YM |
439 | |
440 | static inline void qed_inform_vf_link_state(struct qed_hwfn *hwfn) | |
441 | { | |
442 | } | |
32a47e72 YM |
443 | #endif |
444 | ||
445 | #define qed_for_each_vf(_p_hwfn, _i) \ | |
446 | for (_i = qed_iov_get_next_active_vf(_p_hwfn, 0); \ | |
447 | _i < MAX_NUM_VFS; \ | |
448 | _i = qed_iov_get_next_active_vf(_p_hwfn, _i + 1)) | |
449 | ||
450 | #endif |