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