1 /* QLogic qed NIC Driver
2 * Copyright (c) 2015-2017 QLogic Corporation
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:
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
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.
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
33 #include <linux/etherdevice.h>
34 #include <linux/crc32.h>
35 #include <linux/vmalloc.h>
36 #include <linux/qed/qed_iov_if.h>
40 #include "qed_init_ops.h"
43 #include "qed_reg_addr.h"
45 #include "qed_sriov.h"
49 static int qed_sp_vf_start(struct qed_hwfn
*p_hwfn
, struct qed_vf_info
*p_vf
)
51 struct vf_start_ramrod_data
*p_ramrod
= NULL
;
52 struct qed_spq_entry
*p_ent
= NULL
;
53 struct qed_sp_init_data init_data
;
58 memset(&init_data
, 0, sizeof(init_data
));
59 init_data
.cid
= qed_spq_get_cid(p_hwfn
);
60 init_data
.opaque_fid
= p_vf
->opaque_fid
;
61 init_data
.comp_mode
= QED_SPQ_MODE_EBLOCK
;
63 rc
= qed_sp_init_request(p_hwfn
, &p_ent
,
64 COMMON_RAMROD_VF_START
,
65 PROTOCOLID_COMMON
, &init_data
);
69 p_ramrod
= &p_ent
->ramrod
.vf_start
;
71 p_ramrod
->vf_id
= GET_FIELD(p_vf
->concrete_fid
, PXP_CONCRETE_FID_VFID
);
72 p_ramrod
->opaque_fid
= cpu_to_le16(p_vf
->opaque_fid
);
74 switch (p_hwfn
->hw_info
.personality
) {
76 p_ramrod
->personality
= PERSONALITY_ETH
;
78 case QED_PCI_ETH_ROCE
:
79 p_ramrod
->personality
= PERSONALITY_RDMA_AND_ETH
;
82 DP_NOTICE(p_hwfn
, "Unknown VF personality %d\n",
83 p_hwfn
->hw_info
.personality
);
87 fp_minor
= p_vf
->acquire
.vfdev_info
.eth_fp_hsi_minor
;
88 if (fp_minor
> ETH_HSI_VER_MINOR
&&
89 fp_minor
!= ETH_HSI_VER_NO_PKT_LEN_TUNN
) {
92 "VF [%d] - Requested fp hsi %02x.%02x which is slightly newer than PF's %02x.%02x; Configuring PFs version\n",
95 fp_minor
, ETH_HSI_VER_MAJOR
, ETH_HSI_VER_MINOR
);
96 fp_minor
= ETH_HSI_VER_MINOR
;
99 p_ramrod
->hsi_fp_ver
.major_ver_arr
[ETH_VER_KEY
] = ETH_HSI_VER_MAJOR
;
100 p_ramrod
->hsi_fp_ver
.minor_ver_arr
[ETH_VER_KEY
] = fp_minor
;
102 DP_VERBOSE(p_hwfn
, QED_MSG_IOV
,
103 "VF[%d] - Starting using HSI %02x.%02x\n",
104 p_vf
->abs_vf_id
, ETH_HSI_VER_MAJOR
, fp_minor
);
106 return qed_spq_post(p_hwfn
, p_ent
, NULL
);
109 static int qed_sp_vf_stop(struct qed_hwfn
*p_hwfn
,
110 u32 concrete_vfid
, u16 opaque_vfid
)
112 struct vf_stop_ramrod_data
*p_ramrod
= NULL
;
113 struct qed_spq_entry
*p_ent
= NULL
;
114 struct qed_sp_init_data init_data
;
118 memset(&init_data
, 0, sizeof(init_data
));
119 init_data
.cid
= qed_spq_get_cid(p_hwfn
);
120 init_data
.opaque_fid
= opaque_vfid
;
121 init_data
.comp_mode
= QED_SPQ_MODE_EBLOCK
;
123 rc
= qed_sp_init_request(p_hwfn
, &p_ent
,
124 COMMON_RAMROD_VF_STOP
,
125 PROTOCOLID_COMMON
, &init_data
);
129 p_ramrod
= &p_ent
->ramrod
.vf_stop
;
131 p_ramrod
->vf_id
= GET_FIELD(concrete_vfid
, PXP_CONCRETE_FID_VFID
);
133 return qed_spq_post(p_hwfn
, p_ent
, NULL
);
136 static bool qed_iov_is_valid_vfid(struct qed_hwfn
*p_hwfn
,
138 bool b_enabled_only
, bool b_non_malicious
)
140 if (!p_hwfn
->pf_iov_info
) {
141 DP_NOTICE(p_hwfn
->cdev
, "No iov info\n");
145 if ((rel_vf_id
>= p_hwfn
->cdev
->p_iov_info
->total_vfs
) ||
149 if ((!p_hwfn
->pf_iov_info
->vfs_array
[rel_vf_id
].b_init
) &&
153 if ((p_hwfn
->pf_iov_info
->vfs_array
[rel_vf_id
].b_malicious
) &&
160 static struct qed_vf_info
*qed_iov_get_vf_info(struct qed_hwfn
*p_hwfn
,
164 struct qed_vf_info
*vf
= NULL
;
166 if (!p_hwfn
->pf_iov_info
) {
167 DP_NOTICE(p_hwfn
->cdev
, "No iov info\n");
171 if (qed_iov_is_valid_vfid(p_hwfn
, relative_vf_id
,
172 b_enabled_only
, false))
173 vf
= &p_hwfn
->pf_iov_info
->vfs_array
[relative_vf_id
];
175 DP_ERR(p_hwfn
, "qed_iov_get_vf_info: VF[%d] is not enabled\n",
181 static bool qed_iov_validate_rxq(struct qed_hwfn
*p_hwfn
,
182 struct qed_vf_info
*p_vf
, u16 rx_qid
)
184 if (rx_qid
>= p_vf
->num_rxqs
)
187 "VF[0x%02x] - can't touch Rx queue[%04x]; Only 0x%04x are allocated\n",
188 p_vf
->abs_vf_id
, rx_qid
, p_vf
->num_rxqs
);
189 return rx_qid
< p_vf
->num_rxqs
;
192 static bool qed_iov_validate_txq(struct qed_hwfn
*p_hwfn
,
193 struct qed_vf_info
*p_vf
, u16 tx_qid
)
195 if (tx_qid
>= p_vf
->num_txqs
)
198 "VF[0x%02x] - can't touch Tx queue[%04x]; Only 0x%04x are allocated\n",
199 p_vf
->abs_vf_id
, tx_qid
, p_vf
->num_txqs
);
200 return tx_qid
< p_vf
->num_txqs
;
203 static bool qed_iov_validate_sb(struct qed_hwfn
*p_hwfn
,
204 struct qed_vf_info
*p_vf
, u16 sb_idx
)
208 for (i
= 0; i
< p_vf
->num_sbs
; i
++)
209 if (p_vf
->igu_sbs
[i
] == sb_idx
)
214 "VF[0%02x] - tried using sb_idx %04x which doesn't exist as one of its 0x%02x SBs\n",
215 p_vf
->abs_vf_id
, sb_idx
, p_vf
->num_sbs
);
220 static int qed_iov_post_vf_bulletin(struct qed_hwfn
*p_hwfn
,
221 int vfid
, struct qed_ptt
*p_ptt
)
223 struct qed_bulletin_content
*p_bulletin
;
224 int crc_size
= sizeof(p_bulletin
->crc
);
225 struct qed_dmae_params params
;
226 struct qed_vf_info
*p_vf
;
228 p_vf
= qed_iov_get_vf_info(p_hwfn
, (u16
) vfid
, true);
232 if (!p_vf
->vf_bulletin
)
235 p_bulletin
= p_vf
->bulletin
.p_virt
;
237 /* Increment bulletin board version and compute crc */
238 p_bulletin
->version
++;
239 p_bulletin
->crc
= crc32(0, (u8
*)p_bulletin
+ crc_size
,
240 p_vf
->bulletin
.size
- crc_size
);
242 DP_VERBOSE(p_hwfn
, QED_MSG_IOV
,
243 "Posting Bulletin 0x%08x to VF[%d] (CRC 0x%08x)\n",
244 p_bulletin
->version
, p_vf
->relative_vf_id
, p_bulletin
->crc
);
246 /* propagate bulletin board via dmae to vm memory */
247 memset(¶ms
, 0, sizeof(params
));
248 params
.flags
= QED_DMAE_FLAG_VF_DST
;
249 params
.dst_vfid
= p_vf
->abs_vf_id
;
250 return qed_dmae_host2host(p_hwfn
, p_ptt
, p_vf
->bulletin
.phys
,
251 p_vf
->vf_bulletin
, p_vf
->bulletin
.size
/ 4,
255 static int qed_iov_pci_cfg_info(struct qed_dev
*cdev
)
257 struct qed_hw_sriov_info
*iov
= cdev
->p_iov_info
;
260 DP_VERBOSE(cdev
, QED_MSG_IOV
, "sriov ext pos %d\n", pos
);
261 pci_read_config_word(cdev
->pdev
, pos
+ PCI_SRIOV_CTRL
, &iov
->ctrl
);
263 pci_read_config_word(cdev
->pdev
,
264 pos
+ PCI_SRIOV_TOTAL_VF
, &iov
->total_vfs
);
265 pci_read_config_word(cdev
->pdev
,
266 pos
+ PCI_SRIOV_INITIAL_VF
, &iov
->initial_vfs
);
268 pci_read_config_word(cdev
->pdev
, pos
+ PCI_SRIOV_NUM_VF
, &iov
->num_vfs
);
272 "Number of VFs are already set to non-zero value. Ignoring PCI configuration value\n");
276 pci_read_config_word(cdev
->pdev
,
277 pos
+ PCI_SRIOV_VF_OFFSET
, &iov
->offset
);
279 pci_read_config_word(cdev
->pdev
,
280 pos
+ PCI_SRIOV_VF_STRIDE
, &iov
->stride
);
282 pci_read_config_word(cdev
->pdev
,
283 pos
+ PCI_SRIOV_VF_DID
, &iov
->vf_device_id
);
285 pci_read_config_dword(cdev
->pdev
,
286 pos
+ PCI_SRIOV_SUP_PGSIZE
, &iov
->pgsz
);
288 pci_read_config_dword(cdev
->pdev
, pos
+ PCI_SRIOV_CAP
, &iov
->cap
);
290 pci_read_config_byte(cdev
->pdev
, pos
+ PCI_SRIOV_FUNC_LINK
, &iov
->link
);
294 "IOV info: nres %d, cap 0x%x, ctrl 0x%x, total %d, initial %d, num vfs %d, offset %d, stride %d, page size 0x%x\n",
300 iov
->nr_virtfn
, iov
->offset
, iov
->stride
, iov
->pgsz
);
302 /* Some sanity checks */
303 if (iov
->num_vfs
> NUM_OF_VFS(cdev
) ||
304 iov
->total_vfs
> NUM_OF_VFS(cdev
)) {
305 /* This can happen only due to a bug. In this case we set
306 * num_vfs to zero to avoid memory corruption in the code that
307 * assumes max number of vfs
310 "IOV: Unexpected number of vfs set: %d setting num_vf to zero\n",
320 static void qed_iov_clear_vf_igu_blocks(struct qed_hwfn
*p_hwfn
,
321 struct qed_ptt
*p_ptt
)
323 struct qed_igu_block
*p_sb
;
327 if (!p_hwfn
->hw_info
.p_igu_info
) {
329 "qed_iov_clear_vf_igu_blocks IGU Info not initialized\n");
333 for (sb_id
= 0; sb_id
< QED_MAPPING_MEMORY_SIZE(p_hwfn
->cdev
);
335 p_sb
= &p_hwfn
->hw_info
.p_igu_info
->igu_map
.igu_blocks
[sb_id
];
336 if ((p_sb
->status
& QED_IGU_STATUS_FREE
) &&
337 !(p_sb
->status
& QED_IGU_STATUS_PF
)) {
338 val
= qed_rd(p_hwfn
, p_ptt
,
339 IGU_REG_MAPPING_MEMORY
+ sb_id
* 4);
340 SET_FIELD(val
, IGU_MAPPING_LINE_VALID
, 0);
341 qed_wr(p_hwfn
, p_ptt
,
342 IGU_REG_MAPPING_MEMORY
+ 4 * sb_id
, val
);
347 static void qed_iov_setup_vfdb(struct qed_hwfn
*p_hwfn
)
349 struct qed_hw_sriov_info
*p_iov
= p_hwfn
->cdev
->p_iov_info
;
350 struct qed_pf_iov
*p_iov_info
= p_hwfn
->pf_iov_info
;
351 struct qed_bulletin_content
*p_bulletin_virt
;
352 dma_addr_t req_p
, rply_p
, bulletin_p
;
353 union pfvf_tlvs
*p_reply_virt_addr
;
354 union vfpf_tlvs
*p_req_virt_addr
;
357 memset(p_iov_info
->vfs_array
, 0, sizeof(p_iov_info
->vfs_array
));
359 p_req_virt_addr
= p_iov_info
->mbx_msg_virt_addr
;
360 req_p
= p_iov_info
->mbx_msg_phys_addr
;
361 p_reply_virt_addr
= p_iov_info
->mbx_reply_virt_addr
;
362 rply_p
= p_iov_info
->mbx_reply_phys_addr
;
363 p_bulletin_virt
= p_iov_info
->p_bulletins
;
364 bulletin_p
= p_iov_info
->bulletins_phys
;
365 if (!p_req_virt_addr
|| !p_reply_virt_addr
|| !p_bulletin_virt
) {
367 "qed_iov_setup_vfdb called without allocating mem first\n");
371 for (idx
= 0; idx
< p_iov
->total_vfs
; idx
++) {
372 struct qed_vf_info
*vf
= &p_iov_info
->vfs_array
[idx
];
375 vf
->vf_mbx
.req_virt
= p_req_virt_addr
+ idx
;
376 vf
->vf_mbx
.req_phys
= req_p
+ idx
* sizeof(union vfpf_tlvs
);
377 vf
->vf_mbx
.reply_virt
= p_reply_virt_addr
+ idx
;
378 vf
->vf_mbx
.reply_phys
= rply_p
+ idx
* sizeof(union pfvf_tlvs
);
380 vf
->state
= VF_STOPPED
;
383 vf
->bulletin
.phys
= idx
*
384 sizeof(struct qed_bulletin_content
) +
386 vf
->bulletin
.p_virt
= p_bulletin_virt
+ idx
;
387 vf
->bulletin
.size
= sizeof(struct qed_bulletin_content
);
389 vf
->relative_vf_id
= idx
;
390 vf
->abs_vf_id
= idx
+ p_iov
->first_vf_in_pf
;
391 concrete
= qed_vfid_to_concrete(p_hwfn
, vf
->abs_vf_id
);
392 vf
->concrete_fid
= concrete
;
393 vf
->opaque_fid
= (p_hwfn
->hw_info
.opaque_fid
& 0xff) |
394 (vf
->abs_vf_id
<< 8);
395 vf
->vport_id
= idx
+ 1;
397 vf
->num_mac_filters
= QED_ETH_VF_NUM_MAC_FILTERS
;
398 vf
->num_vlan_filters
= QED_ETH_VF_NUM_VLAN_FILTERS
;
402 static int qed_iov_allocate_vfdb(struct qed_hwfn
*p_hwfn
)
404 struct qed_pf_iov
*p_iov_info
= p_hwfn
->pf_iov_info
;
408 num_vfs
= p_hwfn
->cdev
->p_iov_info
->total_vfs
;
410 DP_VERBOSE(p_hwfn
, QED_MSG_IOV
,
411 "qed_iov_allocate_vfdb for %d VFs\n", num_vfs
);
413 /* Allocate PF Mailbox buffer (per-VF) */
414 p_iov_info
->mbx_msg_size
= sizeof(union vfpf_tlvs
) * num_vfs
;
415 p_v_addr
= &p_iov_info
->mbx_msg_virt_addr
;
416 *p_v_addr
= dma_alloc_coherent(&p_hwfn
->cdev
->pdev
->dev
,
417 p_iov_info
->mbx_msg_size
,
418 &p_iov_info
->mbx_msg_phys_addr
,
423 /* Allocate PF Mailbox Reply buffer (per-VF) */
424 p_iov_info
->mbx_reply_size
= sizeof(union pfvf_tlvs
) * num_vfs
;
425 p_v_addr
= &p_iov_info
->mbx_reply_virt_addr
;
426 *p_v_addr
= dma_alloc_coherent(&p_hwfn
->cdev
->pdev
->dev
,
427 p_iov_info
->mbx_reply_size
,
428 &p_iov_info
->mbx_reply_phys_addr
,
433 p_iov_info
->bulletins_size
= sizeof(struct qed_bulletin_content
) *
435 p_v_addr
= &p_iov_info
->p_bulletins
;
436 *p_v_addr
= dma_alloc_coherent(&p_hwfn
->cdev
->pdev
->dev
,
437 p_iov_info
->bulletins_size
,
438 &p_iov_info
->bulletins_phys
,
445 "PF's Requests mailbox [%p virt 0x%llx phys], Response mailbox [%p virt 0x%llx phys] Bulletins [%p virt 0x%llx phys]\n",
446 p_iov_info
->mbx_msg_virt_addr
,
447 (u64
) p_iov_info
->mbx_msg_phys_addr
,
448 p_iov_info
->mbx_reply_virt_addr
,
449 (u64
) p_iov_info
->mbx_reply_phys_addr
,
450 p_iov_info
->p_bulletins
, (u64
) p_iov_info
->bulletins_phys
);
455 static void qed_iov_free_vfdb(struct qed_hwfn
*p_hwfn
)
457 struct qed_pf_iov
*p_iov_info
= p_hwfn
->pf_iov_info
;
459 if (p_hwfn
->pf_iov_info
->mbx_msg_virt_addr
)
460 dma_free_coherent(&p_hwfn
->cdev
->pdev
->dev
,
461 p_iov_info
->mbx_msg_size
,
462 p_iov_info
->mbx_msg_virt_addr
,
463 p_iov_info
->mbx_msg_phys_addr
);
465 if (p_hwfn
->pf_iov_info
->mbx_reply_virt_addr
)
466 dma_free_coherent(&p_hwfn
->cdev
->pdev
->dev
,
467 p_iov_info
->mbx_reply_size
,
468 p_iov_info
->mbx_reply_virt_addr
,
469 p_iov_info
->mbx_reply_phys_addr
);
471 if (p_iov_info
->p_bulletins
)
472 dma_free_coherent(&p_hwfn
->cdev
->pdev
->dev
,
473 p_iov_info
->bulletins_size
,
474 p_iov_info
->p_bulletins
,
475 p_iov_info
->bulletins_phys
);
478 int qed_iov_alloc(struct qed_hwfn
*p_hwfn
)
480 struct qed_pf_iov
*p_sriov
;
482 if (!IS_PF_SRIOV(p_hwfn
)) {
483 DP_VERBOSE(p_hwfn
, QED_MSG_IOV
,
484 "No SR-IOV - no need for IOV db\n");
488 p_sriov
= kzalloc(sizeof(*p_sriov
), GFP_KERNEL
);
492 p_hwfn
->pf_iov_info
= p_sriov
;
494 return qed_iov_allocate_vfdb(p_hwfn
);
497 void qed_iov_setup(struct qed_hwfn
*p_hwfn
, struct qed_ptt
*p_ptt
)
499 if (!IS_PF_SRIOV(p_hwfn
) || !IS_PF_SRIOV_ALLOC(p_hwfn
))
502 qed_iov_setup_vfdb(p_hwfn
);
503 qed_iov_clear_vf_igu_blocks(p_hwfn
, p_ptt
);
506 void qed_iov_free(struct qed_hwfn
*p_hwfn
)
508 if (IS_PF_SRIOV_ALLOC(p_hwfn
)) {
509 qed_iov_free_vfdb(p_hwfn
);
510 kfree(p_hwfn
->pf_iov_info
);
514 void qed_iov_free_hw_info(struct qed_dev
*cdev
)
516 kfree(cdev
->p_iov_info
);
517 cdev
->p_iov_info
= NULL
;
520 int qed_iov_hw_info(struct qed_hwfn
*p_hwfn
)
522 struct qed_dev
*cdev
= p_hwfn
->cdev
;
526 if (IS_VF(p_hwfn
->cdev
))
529 /* Learn the PCI configuration */
530 pos
= pci_find_ext_capability(p_hwfn
->cdev
->pdev
,
531 PCI_EXT_CAP_ID_SRIOV
);
533 DP_VERBOSE(p_hwfn
, QED_MSG_IOV
, "No PCIe IOV support\n");
537 /* Allocate a new struct for IOV information */
538 cdev
->p_iov_info
= kzalloc(sizeof(*cdev
->p_iov_info
), GFP_KERNEL
);
539 if (!cdev
->p_iov_info
)
542 cdev
->p_iov_info
->pos
= pos
;
544 rc
= qed_iov_pci_cfg_info(cdev
);
548 /* We want PF IOV to be synonemous with the existance of p_iov_info;
549 * In case the capability is published but there are no VFs, simply
550 * de-allocate the struct.
552 if (!cdev
->p_iov_info
->total_vfs
) {
553 DP_VERBOSE(p_hwfn
, QED_MSG_IOV
,
554 "IOV capabilities, but no VFs are published\n");
555 kfree(cdev
->p_iov_info
);
556 cdev
->p_iov_info
= NULL
;
560 /* First VF index based on offset is tricky:
561 * - If ARI is supported [likely], offset - (16 - pf_id) would
562 * provide the number for eng0. 2nd engine Vfs would begin
563 * after the first engine's VFs.
564 * - If !ARI, VFs would start on next device.
565 * so offset - (256 - pf_id) would provide the number.
566 * Utilize the fact that (256 - pf_id) is achieved only by later
567 * to diffrentiate between the two.
570 if (p_hwfn
->cdev
->p_iov_info
->offset
< (256 - p_hwfn
->abs_pf_id
)) {
571 u32 first
= p_hwfn
->cdev
->p_iov_info
->offset
+
572 p_hwfn
->abs_pf_id
- 16;
574 cdev
->p_iov_info
->first_vf_in_pf
= first
;
576 if (QED_PATH_ID(p_hwfn
))
577 cdev
->p_iov_info
->first_vf_in_pf
-= MAX_NUM_VFS_BB
;
579 u32 first
= p_hwfn
->cdev
->p_iov_info
->offset
+
580 p_hwfn
->abs_pf_id
- 256;
582 cdev
->p_iov_info
->first_vf_in_pf
= first
;
585 DP_VERBOSE(p_hwfn
, QED_MSG_IOV
,
586 "First VF in hwfn 0x%08x\n",
587 cdev
->p_iov_info
->first_vf_in_pf
);
592 bool _qed_iov_pf_sanity_check(struct qed_hwfn
*p_hwfn
,
593 int vfid
, bool b_fail_malicious
)
595 /* Check PF supports sriov */
596 if (IS_VF(p_hwfn
->cdev
) || !IS_QED_SRIOV(p_hwfn
->cdev
) ||
597 !IS_PF_SRIOV_ALLOC(p_hwfn
))
600 /* Check VF validity */
601 if (!qed_iov_is_valid_vfid(p_hwfn
, vfid
, true, b_fail_malicious
))
607 bool qed_iov_pf_sanity_check(struct qed_hwfn
*p_hwfn
, int vfid
)
609 return _qed_iov_pf_sanity_check(p_hwfn
, vfid
, true);
612 static void qed_iov_set_vf_to_disable(struct qed_dev
*cdev
,
613 u16 rel_vf_id
, u8 to_disable
)
615 struct qed_vf_info
*vf
;
618 for_each_hwfn(cdev
, i
) {
619 struct qed_hwfn
*p_hwfn
= &cdev
->hwfns
[i
];
621 vf
= qed_iov_get_vf_info(p_hwfn
, rel_vf_id
, false);
625 vf
->to_disable
= to_disable
;
629 static void qed_iov_set_vfs_to_disable(struct qed_dev
*cdev
, u8 to_disable
)
633 if (!IS_QED_SRIOV(cdev
))
636 for (i
= 0; i
< cdev
->p_iov_info
->total_vfs
; i
++)
637 qed_iov_set_vf_to_disable(cdev
, i
, to_disable
);
640 static void qed_iov_vf_pglue_clear_err(struct qed_hwfn
*p_hwfn
,
641 struct qed_ptt
*p_ptt
, u8 abs_vfid
)
643 qed_wr(p_hwfn
, p_ptt
,
644 PGLUE_B_REG_WAS_ERROR_VF_31_0_CLR
+ (abs_vfid
>> 5) * 4,
645 1 << (abs_vfid
& 0x1f));
648 static void qed_iov_vf_igu_reset(struct qed_hwfn
*p_hwfn
,
649 struct qed_ptt
*p_ptt
, struct qed_vf_info
*vf
)
653 /* Set VF masks and configuration - pretend */
654 qed_fid_pretend(p_hwfn
, p_ptt
, (u16
) vf
->concrete_fid
);
656 qed_wr(p_hwfn
, p_ptt
, IGU_REG_STATISTIC_NUM_VF_MSG_SENT
, 0);
659 qed_fid_pretend(p_hwfn
, p_ptt
, (u16
) p_hwfn
->hw_info
.concrete_fid
);
661 /* iterate over all queues, clear sb consumer */
662 for (i
= 0; i
< vf
->num_sbs
; i
++)
663 qed_int_igu_init_pure_rt_single(p_hwfn
, p_ptt
,
665 vf
->opaque_fid
, true);
668 static void qed_iov_vf_igu_set_int(struct qed_hwfn
*p_hwfn
,
669 struct qed_ptt
*p_ptt
,
670 struct qed_vf_info
*vf
, bool enable
)
674 qed_fid_pretend(p_hwfn
, p_ptt
, (u16
) vf
->concrete_fid
);
676 igu_vf_conf
= qed_rd(p_hwfn
, p_ptt
, IGU_REG_VF_CONFIGURATION
);
679 igu_vf_conf
|= IGU_VF_CONF_MSI_MSIX_EN
;
681 igu_vf_conf
&= ~IGU_VF_CONF_MSI_MSIX_EN
;
683 qed_wr(p_hwfn
, p_ptt
, IGU_REG_VF_CONFIGURATION
, igu_vf_conf
);
686 qed_fid_pretend(p_hwfn
, p_ptt
, (u16
) p_hwfn
->hw_info
.concrete_fid
);
689 static int qed_iov_enable_vf_access(struct qed_hwfn
*p_hwfn
,
690 struct qed_ptt
*p_ptt
,
691 struct qed_vf_info
*vf
)
693 u32 igu_vf_conf
= IGU_VF_CONF_FUNC_EN
;
701 "Enable internal access for vf %x [abs %x]\n",
702 vf
->abs_vf_id
, QED_VF_ABS_ID(p_hwfn
, vf
));
704 qed_iov_vf_pglue_clear_err(p_hwfn
, p_ptt
, QED_VF_ABS_ID(p_hwfn
, vf
));
706 qed_iov_vf_igu_reset(p_hwfn
, p_ptt
, vf
);
708 /* It's possible VF was previously considered malicious */
709 vf
->b_malicious
= false;
711 rc
= qed_mcp_config_vf_msix(p_hwfn
, p_ptt
, vf
->abs_vf_id
, vf
->num_sbs
);
715 qed_fid_pretend(p_hwfn
, p_ptt
, (u16
) vf
->concrete_fid
);
717 SET_FIELD(igu_vf_conf
, IGU_VF_CONF_PARENT
, p_hwfn
->rel_pf_id
);
718 STORE_RT_REG(p_hwfn
, IGU_REG_VF_CONFIGURATION_RT_OFFSET
, igu_vf_conf
);
720 qed_init_run(p_hwfn
, p_ptt
, PHASE_VF
, vf
->abs_vf_id
,
721 p_hwfn
->hw_info
.hw_mode
);
724 qed_fid_pretend(p_hwfn
, p_ptt
, (u16
) p_hwfn
->hw_info
.concrete_fid
);
732 * @brief qed_iov_config_perm_table - configure the permission
734 * In E4, queue zone permission table size is 320x9. There
735 * are 320 VF queues for single engine device (256 for dual
736 * engine device), and each entry has the following format:
743 static void qed_iov_config_perm_table(struct qed_hwfn
*p_hwfn
,
744 struct qed_ptt
*p_ptt
,
745 struct qed_vf_info
*vf
, u8 enable
)
751 for (qid
= 0; qid
< vf
->num_rxqs
; qid
++) {
752 qed_fw_l2_queue(p_hwfn
, vf
->vf_queues
[qid
].fw_rx_qid
,
755 reg_addr
= PSWHST_REG_ZONE_PERMISSION_TABLE
+ qzone_id
* 4;
756 val
= enable
? (vf
->abs_vf_id
| BIT(8)) : 0;
757 qed_wr(p_hwfn
, p_ptt
, reg_addr
, val
);
761 static void qed_iov_enable_vf_traffic(struct qed_hwfn
*p_hwfn
,
762 struct qed_ptt
*p_ptt
,
763 struct qed_vf_info
*vf
)
765 /* Reset vf in IGU - interrupts are still disabled */
766 qed_iov_vf_igu_reset(p_hwfn
, p_ptt
, vf
);
768 qed_iov_vf_igu_set_int(p_hwfn
, p_ptt
, vf
, 1);
770 /* Permission Table */
771 qed_iov_config_perm_table(p_hwfn
, p_ptt
, vf
, true);
774 static u8
qed_iov_alloc_vf_igu_sbs(struct qed_hwfn
*p_hwfn
,
775 struct qed_ptt
*p_ptt
,
776 struct qed_vf_info
*vf
, u16 num_rx_queues
)
778 struct qed_igu_block
*igu_blocks
;
779 int qid
= 0, igu_id
= 0;
782 igu_blocks
= p_hwfn
->hw_info
.p_igu_info
->igu_map
.igu_blocks
;
784 if (num_rx_queues
> p_hwfn
->hw_info
.p_igu_info
->free_blks
)
785 num_rx_queues
= p_hwfn
->hw_info
.p_igu_info
->free_blks
;
786 p_hwfn
->hw_info
.p_igu_info
->free_blks
-= num_rx_queues
;
788 SET_FIELD(val
, IGU_MAPPING_LINE_FUNCTION_NUMBER
, vf
->abs_vf_id
);
789 SET_FIELD(val
, IGU_MAPPING_LINE_VALID
, 1);
790 SET_FIELD(val
, IGU_MAPPING_LINE_PF_VALID
, 0);
792 while ((qid
< num_rx_queues
) &&
793 (igu_id
< QED_MAPPING_MEMORY_SIZE(p_hwfn
->cdev
))) {
794 if (igu_blocks
[igu_id
].status
& QED_IGU_STATUS_FREE
) {
795 struct cau_sb_entry sb_entry
;
797 vf
->igu_sbs
[qid
] = (u16
)igu_id
;
798 igu_blocks
[igu_id
].status
&= ~QED_IGU_STATUS_FREE
;
800 SET_FIELD(val
, IGU_MAPPING_LINE_VECTOR_NUMBER
, qid
);
802 qed_wr(p_hwfn
, p_ptt
,
803 IGU_REG_MAPPING_MEMORY
+ sizeof(u32
) * igu_id
,
806 /* Configure igu sb in CAU which were marked valid */
807 qed_init_cau_sb_entry(p_hwfn
, &sb_entry
,
810 qed_dmae_host2grc(p_hwfn
, p_ptt
,
811 (u64
)(uintptr_t)&sb_entry
,
812 CAU_REG_SB_VAR_MEMORY
+
813 igu_id
* sizeof(u64
), 2, 0);
819 vf
->num_sbs
= (u8
) num_rx_queues
;
824 static void qed_iov_free_vf_igu_sbs(struct qed_hwfn
*p_hwfn
,
825 struct qed_ptt
*p_ptt
,
826 struct qed_vf_info
*vf
)
828 struct qed_igu_info
*p_info
= p_hwfn
->hw_info
.p_igu_info
;
832 /* Invalidate igu CAM lines and mark them as free */
833 for (idx
= 0; idx
< vf
->num_sbs
; idx
++) {
834 igu_id
= vf
->igu_sbs
[idx
];
835 addr
= IGU_REG_MAPPING_MEMORY
+ sizeof(u32
) * igu_id
;
837 val
= qed_rd(p_hwfn
, p_ptt
, addr
);
838 SET_FIELD(val
, IGU_MAPPING_LINE_VALID
, 0);
839 qed_wr(p_hwfn
, p_ptt
, addr
, val
);
841 p_info
->igu_map
.igu_blocks
[igu_id
].status
|=
844 p_hwfn
->hw_info
.p_igu_info
->free_blks
++;
850 static void qed_iov_set_link(struct qed_hwfn
*p_hwfn
,
852 struct qed_mcp_link_params
*params
,
853 struct qed_mcp_link_state
*link
,
854 struct qed_mcp_link_capabilities
*p_caps
)
856 struct qed_vf_info
*p_vf
= qed_iov_get_vf_info(p_hwfn
,
859 struct qed_bulletin_content
*p_bulletin
;
864 p_bulletin
= p_vf
->bulletin
.p_virt
;
865 p_bulletin
->req_autoneg
= params
->speed
.autoneg
;
866 p_bulletin
->req_adv_speed
= params
->speed
.advertised_speeds
;
867 p_bulletin
->req_forced_speed
= params
->speed
.forced_speed
;
868 p_bulletin
->req_autoneg_pause
= params
->pause
.autoneg
;
869 p_bulletin
->req_forced_rx
= params
->pause
.forced_rx
;
870 p_bulletin
->req_forced_tx
= params
->pause
.forced_tx
;
871 p_bulletin
->req_loopback
= params
->loopback_mode
;
873 p_bulletin
->link_up
= link
->link_up
;
874 p_bulletin
->speed
= link
->speed
;
875 p_bulletin
->full_duplex
= link
->full_duplex
;
876 p_bulletin
->autoneg
= link
->an
;
877 p_bulletin
->autoneg_complete
= link
->an_complete
;
878 p_bulletin
->parallel_detection
= link
->parallel_detection
;
879 p_bulletin
->pfc_enabled
= link
->pfc_enabled
;
880 p_bulletin
->partner_adv_speed
= link
->partner_adv_speed
;
881 p_bulletin
->partner_tx_flow_ctrl_en
= link
->partner_tx_flow_ctrl_en
;
882 p_bulletin
->partner_rx_flow_ctrl_en
= link
->partner_rx_flow_ctrl_en
;
883 p_bulletin
->partner_adv_pause
= link
->partner_adv_pause
;
884 p_bulletin
->sfp_tx_fault
= link
->sfp_tx_fault
;
886 p_bulletin
->capability_speed
= p_caps
->speed_capabilities
;
889 static int qed_iov_init_hw_for_vf(struct qed_hwfn
*p_hwfn
,
890 struct qed_ptt
*p_ptt
,
891 struct qed_iov_vf_init_params
*p_params
)
893 struct qed_mcp_link_capabilities link_caps
;
894 struct qed_mcp_link_params link_params
;
895 struct qed_mcp_link_state link_state
;
896 u8 num_of_vf_avaiable_chains
= 0;
897 struct qed_vf_info
*vf
= NULL
;
903 vf
= qed_iov_get_vf_info(p_hwfn
, p_params
->rel_vf_id
, false);
905 DP_ERR(p_hwfn
, "qed_iov_init_hw_for_vf : vf is NULL\n");
910 DP_NOTICE(p_hwfn
, "VF[%d] is already active.\n",
911 p_params
->rel_vf_id
);
915 /* Perform sanity checking on the requested queue_id */
916 for (i
= 0; i
< p_params
->num_queues
; i
++) {
917 u16 min_vf_qzone
= FEAT_NUM(p_hwfn
, QED_PF_L2_QUE
);
918 u16 max_vf_qzone
= min_vf_qzone
+
919 FEAT_NUM(p_hwfn
, QED_VF_L2_QUE
) - 1;
921 qid
= p_params
->req_rx_queue
[i
];
922 if (qid
< min_vf_qzone
|| qid
> max_vf_qzone
) {
924 "Can't enable Rx qid [%04x] for VF[%d]: qids [0x%04x,...,0x%04x] available\n",
927 min_vf_qzone
, max_vf_qzone
);
931 qid
= p_params
->req_tx_queue
[i
];
932 if (qid
> max_vf_qzone
) {
934 "Can't enable Tx qid [%04x] for VF[%d]: max qid 0x%04x\n",
935 qid
, p_params
->rel_vf_id
, max_vf_qzone
);
939 /* If client *really* wants, Tx qid can be shared with PF */
940 if (qid
< min_vf_qzone
)
943 "VF[%d] is using PF qid [0x%04x] for Txq[0x%02x]\n",
944 p_params
->rel_vf_id
, qid
, i
);
947 /* Limit number of queues according to number of CIDs */
948 qed_cxt_get_proto_cid_count(p_hwfn
, PROTOCOLID_ETH
, &cids
);
951 "VF[%d] - requesting to initialize for 0x%04x queues [0x%04x CIDs available]\n",
952 vf
->relative_vf_id
, p_params
->num_queues
, (u16
)cids
);
953 num_irqs
= min_t(u16
, p_params
->num_queues
, ((u16
)cids
));
955 num_of_vf_avaiable_chains
= qed_iov_alloc_vf_igu_sbs(p_hwfn
,
958 if (!num_of_vf_avaiable_chains
) {
959 DP_ERR(p_hwfn
, "no available igu sbs\n");
963 /* Choose queue number and index ranges */
964 vf
->num_rxqs
= num_of_vf_avaiable_chains
;
965 vf
->num_txqs
= num_of_vf_avaiable_chains
;
967 for (i
= 0; i
< vf
->num_rxqs
; i
++) {
968 struct qed_vf_q_info
*p_queue
= &vf
->vf_queues
[i
];
970 p_queue
->fw_rx_qid
= p_params
->req_rx_queue
[i
];
971 p_queue
->fw_tx_qid
= p_params
->req_tx_queue
[i
];
973 /* CIDs are per-VF, so no problem having them 0-based. */
976 DP_VERBOSE(p_hwfn
, QED_MSG_IOV
,
977 "VF[%d] - Q[%d] SB %04x, qid [Rx %04x Tx %04x] CID %04x\n",
981 p_queue
->fw_tx_qid
, p_queue
->fw_cid
);
984 /* Update the link configuration in bulletin */
985 memcpy(&link_params
, qed_mcp_get_link_params(p_hwfn
),
986 sizeof(link_params
));
987 memcpy(&link_state
, qed_mcp_get_link_state(p_hwfn
), sizeof(link_state
));
988 memcpy(&link_caps
, qed_mcp_get_link_capabilities(p_hwfn
),
990 qed_iov_set_link(p_hwfn
, p_params
->rel_vf_id
,
991 &link_params
, &link_state
, &link_caps
);
993 rc
= qed_iov_enable_vf_access(p_hwfn
, p_ptt
, vf
);
997 if (IS_LEAD_HWFN(p_hwfn
))
998 p_hwfn
->cdev
->p_iov_info
->num_vfs
++;
1004 static int qed_iov_release_hw_for_vf(struct qed_hwfn
*p_hwfn
,
1005 struct qed_ptt
*p_ptt
, u16 rel_vf_id
)
1007 struct qed_mcp_link_capabilities caps
;
1008 struct qed_mcp_link_params params
;
1009 struct qed_mcp_link_state link
;
1010 struct qed_vf_info
*vf
= NULL
;
1012 vf
= qed_iov_get_vf_info(p_hwfn
, rel_vf_id
, true);
1014 DP_ERR(p_hwfn
, "qed_iov_release_hw_for_vf : vf is NULL\n");
1018 if (vf
->bulletin
.p_virt
)
1019 memset(vf
->bulletin
.p_virt
, 0, sizeof(*vf
->bulletin
.p_virt
));
1021 memset(&vf
->p_vf_info
, 0, sizeof(vf
->p_vf_info
));
1023 /* Get the link configuration back in bulletin so
1024 * that when VFs are re-enabled they get the actual
1025 * link configuration.
1027 memcpy(¶ms
, qed_mcp_get_link_params(p_hwfn
), sizeof(params
));
1028 memcpy(&link
, qed_mcp_get_link_state(p_hwfn
), sizeof(link
));
1029 memcpy(&caps
, qed_mcp_get_link_capabilities(p_hwfn
), sizeof(caps
));
1030 qed_iov_set_link(p_hwfn
, rel_vf_id
, ¶ms
, &link
, &caps
);
1032 /* Forget the VF's acquisition message */
1033 memset(&vf
->acquire
, 0, sizeof(vf
->acquire
));
1035 /* disablng interrupts and resetting permission table was done during
1036 * vf-close, however, we could get here without going through vf_close
1038 /* Disable Interrupts for VF */
1039 qed_iov_vf_igu_set_int(p_hwfn
, p_ptt
, vf
, 0);
1041 /* Reset Permission table */
1042 qed_iov_config_perm_table(p_hwfn
, p_ptt
, vf
, 0);
1046 qed_iov_free_vf_igu_sbs(p_hwfn
, p_ptt
, vf
);
1051 if (IS_LEAD_HWFN(p_hwfn
))
1052 p_hwfn
->cdev
->p_iov_info
->num_vfs
--;
1058 static bool qed_iov_tlv_supported(u16 tlvtype
)
1060 return CHANNEL_TLV_NONE
< tlvtype
&& tlvtype
< CHANNEL_TLV_MAX
;
1063 /* place a given tlv on the tlv buffer, continuing current tlv list */
1064 void *qed_add_tlv(struct qed_hwfn
*p_hwfn
, u8
**offset
, u16 type
, u16 length
)
1066 struct channel_tlv
*tl
= (struct channel_tlv
*)*offset
;
1069 tl
->length
= length
;
1071 /* Offset should keep pointing to next TLV (the end of the last) */
1074 /* Return a pointer to the start of the added tlv */
1075 return *offset
- length
;
1078 /* list the types and lengths of the tlvs on the buffer */
1079 void qed_dp_tlv_list(struct qed_hwfn
*p_hwfn
, void *tlvs_list
)
1081 u16 i
= 1, total_length
= 0;
1082 struct channel_tlv
*tlv
;
1085 tlv
= (struct channel_tlv
*)((u8
*)tlvs_list
+ total_length
);
1088 DP_VERBOSE(p_hwfn
, QED_MSG_IOV
,
1089 "TLV number %d: type %d, length %d\n",
1090 i
, tlv
->type
, tlv
->length
);
1092 if (tlv
->type
== CHANNEL_TLV_LIST_END
)
1095 /* Validate entry - protect against malicious VFs */
1097 DP_NOTICE(p_hwfn
, "TLV of length 0 found\n");
1101 total_length
+= tlv
->length
;
1103 if (total_length
>= sizeof(struct tlv_buffer_size
)) {
1104 DP_NOTICE(p_hwfn
, "TLV ==> Buffer overflow\n");
1112 static void qed_iov_send_response(struct qed_hwfn
*p_hwfn
,
1113 struct qed_ptt
*p_ptt
,
1114 struct qed_vf_info
*p_vf
,
1115 u16 length
, u8 status
)
1117 struct qed_iov_vf_mbx
*mbx
= &p_vf
->vf_mbx
;
1118 struct qed_dmae_params params
;
1121 mbx
->reply_virt
->default_resp
.hdr
.status
= status
;
1123 qed_dp_tlv_list(p_hwfn
, mbx
->reply_virt
);
1125 eng_vf_id
= p_vf
->abs_vf_id
;
1127 memset(¶ms
, 0, sizeof(struct qed_dmae_params
));
1128 params
.flags
= QED_DMAE_FLAG_VF_DST
;
1129 params
.dst_vfid
= eng_vf_id
;
1131 qed_dmae_host2host(p_hwfn
, p_ptt
, mbx
->reply_phys
+ sizeof(u64
),
1132 mbx
->req_virt
->first_tlv
.reply_address
+
1134 (sizeof(union pfvf_tlvs
) - sizeof(u64
)) / 4,
1137 qed_dmae_host2host(p_hwfn
, p_ptt
, mbx
->reply_phys
,
1138 mbx
->req_virt
->first_tlv
.reply_address
,
1139 sizeof(u64
) / 4, ¶ms
);
1142 GTT_BAR0_MAP_REG_USDM_RAM
+
1143 USTORM_VF_PF_CHANNEL_READY_OFFSET(eng_vf_id
), 1);
1146 static u16
qed_iov_vport_to_tlv(struct qed_hwfn
*p_hwfn
,
1147 enum qed_iov_vport_update_flag flag
)
1150 case QED_IOV_VP_UPDATE_ACTIVATE
:
1151 return CHANNEL_TLV_VPORT_UPDATE_ACTIVATE
;
1152 case QED_IOV_VP_UPDATE_VLAN_STRIP
:
1153 return CHANNEL_TLV_VPORT_UPDATE_VLAN_STRIP
;
1154 case QED_IOV_VP_UPDATE_TX_SWITCH
:
1155 return CHANNEL_TLV_VPORT_UPDATE_TX_SWITCH
;
1156 case QED_IOV_VP_UPDATE_MCAST
:
1157 return CHANNEL_TLV_VPORT_UPDATE_MCAST
;
1158 case QED_IOV_VP_UPDATE_ACCEPT_PARAM
:
1159 return CHANNEL_TLV_VPORT_UPDATE_ACCEPT_PARAM
;
1160 case QED_IOV_VP_UPDATE_RSS
:
1161 return CHANNEL_TLV_VPORT_UPDATE_RSS
;
1162 case QED_IOV_VP_UPDATE_ACCEPT_ANY_VLAN
:
1163 return CHANNEL_TLV_VPORT_UPDATE_ACCEPT_ANY_VLAN
;
1164 case QED_IOV_VP_UPDATE_SGE_TPA
:
1165 return CHANNEL_TLV_VPORT_UPDATE_SGE_TPA
;
1171 static u16
qed_iov_prep_vp_update_resp_tlvs(struct qed_hwfn
*p_hwfn
,
1172 struct qed_vf_info
*p_vf
,
1173 struct qed_iov_vf_mbx
*p_mbx
,
1175 u16 tlvs_mask
, u16 tlvs_accepted
)
1177 struct pfvf_def_resp_tlv
*resp
;
1178 u16 size
, total_len
, i
;
1180 memset(p_mbx
->reply_virt
, 0, sizeof(union pfvf_tlvs
));
1181 p_mbx
->offset
= (u8
*)p_mbx
->reply_virt
;
1182 size
= sizeof(struct pfvf_def_resp_tlv
);
1185 qed_add_tlv(p_hwfn
, &p_mbx
->offset
, CHANNEL_TLV_VPORT_UPDATE
, size
);
1187 /* Prepare response for all extended tlvs if they are found by PF */
1188 for (i
= 0; i
< QED_IOV_VP_UPDATE_MAX
; i
++) {
1189 if (!(tlvs_mask
& BIT(i
)))
1192 resp
= qed_add_tlv(p_hwfn
, &p_mbx
->offset
,
1193 qed_iov_vport_to_tlv(p_hwfn
, i
), size
);
1195 if (tlvs_accepted
& BIT(i
))
1196 resp
->hdr
.status
= status
;
1198 resp
->hdr
.status
= PFVF_STATUS_NOT_SUPPORTED
;
1202 "VF[%d] - vport_update response: TLV %d, status %02x\n",
1203 p_vf
->relative_vf_id
,
1204 qed_iov_vport_to_tlv(p_hwfn
, i
), resp
->hdr
.status
);
1209 qed_add_tlv(p_hwfn
, &p_mbx
->offset
, CHANNEL_TLV_LIST_END
,
1210 sizeof(struct channel_list_end_tlv
));
1215 static void qed_iov_prepare_resp(struct qed_hwfn
*p_hwfn
,
1216 struct qed_ptt
*p_ptt
,
1217 struct qed_vf_info
*vf_info
,
1218 u16 type
, u16 length
, u8 status
)
1220 struct qed_iov_vf_mbx
*mbx
= &vf_info
->vf_mbx
;
1222 mbx
->offset
= (u8
*)mbx
->reply_virt
;
1224 qed_add_tlv(p_hwfn
, &mbx
->offset
, type
, length
);
1225 qed_add_tlv(p_hwfn
, &mbx
->offset
, CHANNEL_TLV_LIST_END
,
1226 sizeof(struct channel_list_end_tlv
));
1228 qed_iov_send_response(p_hwfn
, p_ptt
, vf_info
, length
, status
);
1232 qed_public_vf_info
*qed_iov_get_public_vf_info(struct qed_hwfn
*p_hwfn
,
1234 bool b_enabled_only
)
1236 struct qed_vf_info
*vf
= NULL
;
1238 vf
= qed_iov_get_vf_info(p_hwfn
, relative_vf_id
, b_enabled_only
);
1242 return &vf
->p_vf_info
;
1245 static void qed_iov_clean_vf(struct qed_hwfn
*p_hwfn
, u8 vfid
)
1247 struct qed_public_vf_info
*vf_info
;
1249 vf_info
= qed_iov_get_public_vf_info(p_hwfn
, vfid
, false);
1254 /* Clear the VF mac */
1255 eth_zero_addr(vf_info
->mac
);
1257 vf_info
->rx_accept_mode
= 0;
1258 vf_info
->tx_accept_mode
= 0;
1261 static void qed_iov_vf_cleanup(struct qed_hwfn
*p_hwfn
,
1262 struct qed_vf_info
*p_vf
)
1266 p_vf
->vf_bulletin
= 0;
1267 p_vf
->vport_instance
= 0;
1268 p_vf
->configured_features
= 0;
1270 /* If VF previously requested less resources, go back to default */
1271 p_vf
->num_rxqs
= p_vf
->num_sbs
;
1272 p_vf
->num_txqs
= p_vf
->num_sbs
;
1274 p_vf
->num_active_rxqs
= 0;
1276 for (i
= 0; i
< QED_MAX_VF_CHAINS_PER_PF
; i
++) {
1277 struct qed_vf_q_info
*p_queue
= &p_vf
->vf_queues
[i
];
1279 if (p_queue
->p_rx_cid
) {
1280 qed_eth_queue_cid_release(p_hwfn
, p_queue
->p_rx_cid
);
1281 p_queue
->p_rx_cid
= NULL
;
1284 if (p_queue
->p_tx_cid
) {
1285 qed_eth_queue_cid_release(p_hwfn
, p_queue
->p_tx_cid
);
1286 p_queue
->p_tx_cid
= NULL
;
1290 memset(&p_vf
->shadow_config
, 0, sizeof(p_vf
->shadow_config
));
1291 memset(&p_vf
->acquire
, 0, sizeof(p_vf
->acquire
));
1292 qed_iov_clean_vf(p_hwfn
, p_vf
->relative_vf_id
);
1295 static u8
qed_iov_vf_mbx_acquire_resc(struct qed_hwfn
*p_hwfn
,
1296 struct qed_ptt
*p_ptt
,
1297 struct qed_vf_info
*p_vf
,
1298 struct vf_pf_resc_request
*p_req
,
1299 struct pf_vf_resc
*p_resp
)
1303 /* Queue related information */
1304 p_resp
->num_rxqs
= p_vf
->num_rxqs
;
1305 p_resp
->num_txqs
= p_vf
->num_txqs
;
1306 p_resp
->num_sbs
= p_vf
->num_sbs
;
1308 for (i
= 0; i
< p_resp
->num_sbs
; i
++) {
1309 p_resp
->hw_sbs
[i
].hw_sb_id
= p_vf
->igu_sbs
[i
];
1310 p_resp
->hw_sbs
[i
].sb_qid
= 0;
1313 /* These fields are filled for backward compatibility.
1314 * Unused by modern vfs.
1316 for (i
= 0; i
< p_resp
->num_rxqs
; i
++) {
1317 qed_fw_l2_queue(p_hwfn
, p_vf
->vf_queues
[i
].fw_rx_qid
,
1318 (u16
*)&p_resp
->hw_qid
[i
]);
1319 p_resp
->cid
[i
] = p_vf
->vf_queues
[i
].fw_cid
;
1322 /* Filter related information */
1323 p_resp
->num_mac_filters
= min_t(u8
, p_vf
->num_mac_filters
,
1324 p_req
->num_mac_filters
);
1325 p_resp
->num_vlan_filters
= min_t(u8
, p_vf
->num_vlan_filters
,
1326 p_req
->num_vlan_filters
);
1328 /* This isn't really needed/enforced, but some legacy VFs might depend
1329 * on the correct filling of this field.
1331 p_resp
->num_mc_filters
= QED_MAX_MC_ADDRS
;
1333 /* Validate sufficient resources for VF */
1334 if (p_resp
->num_rxqs
< p_req
->num_rxqs
||
1335 p_resp
->num_txqs
< p_req
->num_txqs
||
1336 p_resp
->num_sbs
< p_req
->num_sbs
||
1337 p_resp
->num_mac_filters
< p_req
->num_mac_filters
||
1338 p_resp
->num_vlan_filters
< p_req
->num_vlan_filters
||
1339 p_resp
->num_mc_filters
< p_req
->num_mc_filters
) {
1342 "VF[%d] - Insufficient resources: rxq [%02x/%02x] txq [%02x/%02x] sbs [%02x/%02x] mac [%02x/%02x] vlan [%02x/%02x] mc [%02x/%02x]\n",
1350 p_req
->num_mac_filters
,
1351 p_resp
->num_mac_filters
,
1352 p_req
->num_vlan_filters
,
1353 p_resp
->num_vlan_filters
,
1354 p_req
->num_mc_filters
, p_resp
->num_mc_filters
);
1356 /* Some legacy OSes are incapable of correctly handling this
1359 if ((p_vf
->acquire
.vfdev_info
.eth_fp_hsi_minor
==
1360 ETH_HSI_VER_NO_PKT_LEN_TUNN
) &&
1361 (p_vf
->acquire
.vfdev_info
.os_type
==
1362 VFPF_ACQUIRE_OS_WINDOWS
))
1363 return PFVF_STATUS_SUCCESS
;
1365 return PFVF_STATUS_NO_RESOURCE
;
1368 return PFVF_STATUS_SUCCESS
;
1371 static void qed_iov_vf_mbx_acquire_stats(struct qed_hwfn
*p_hwfn
,
1372 struct pfvf_stats_info
*p_stats
)
1374 p_stats
->mstats
.address
= PXP_VF_BAR0_START_MSDM_ZONE_B
+
1375 offsetof(struct mstorm_vf_zone
,
1376 non_trigger
.eth_queue_stat
);
1377 p_stats
->mstats
.len
= sizeof(struct eth_mstorm_per_queue_stat
);
1378 p_stats
->ustats
.address
= PXP_VF_BAR0_START_USDM_ZONE_B
+
1379 offsetof(struct ustorm_vf_zone
,
1380 non_trigger
.eth_queue_stat
);
1381 p_stats
->ustats
.len
= sizeof(struct eth_ustorm_per_queue_stat
);
1382 p_stats
->pstats
.address
= PXP_VF_BAR0_START_PSDM_ZONE_B
+
1383 offsetof(struct pstorm_vf_zone
,
1384 non_trigger
.eth_queue_stat
);
1385 p_stats
->pstats
.len
= sizeof(struct eth_pstorm_per_queue_stat
);
1386 p_stats
->tstats
.address
= 0;
1387 p_stats
->tstats
.len
= 0;
1390 static void qed_iov_vf_mbx_acquire(struct qed_hwfn
*p_hwfn
,
1391 struct qed_ptt
*p_ptt
,
1392 struct qed_vf_info
*vf
)
1394 struct qed_iov_vf_mbx
*mbx
= &vf
->vf_mbx
;
1395 struct pfvf_acquire_resp_tlv
*resp
= &mbx
->reply_virt
->acquire_resp
;
1396 struct pf_vf_pfdev_info
*pfdev_info
= &resp
->pfdev_info
;
1397 struct vfpf_acquire_tlv
*req
= &mbx
->req_virt
->acquire
;
1398 u8 vfpf_status
= PFVF_STATUS_NOT_SUPPORTED
;
1399 struct pf_vf_resc
*resc
= &resp
->resc
;
1402 memset(resp
, 0, sizeof(*resp
));
1404 /* Write the PF version so that VF would know which version
1405 * is supported - might be later overriden. This guarantees that
1406 * VF could recognize legacy PF based on lack of versions in reply.
1408 pfdev_info
->major_fp_hsi
= ETH_HSI_VER_MAJOR
;
1409 pfdev_info
->minor_fp_hsi
= ETH_HSI_VER_MINOR
;
1411 if (vf
->state
!= VF_FREE
&& vf
->state
!= VF_STOPPED
) {
1414 "VF[%d] sent ACQUIRE but is already in state %d - fail request\n",
1415 vf
->abs_vf_id
, vf
->state
);
1419 /* Validate FW compatibility */
1420 if (req
->vfdev_info
.eth_fp_hsi_major
!= ETH_HSI_VER_MAJOR
) {
1421 if (req
->vfdev_info
.capabilities
&
1422 VFPF_ACQUIRE_CAP_PRE_FP_HSI
) {
1423 struct vf_pf_vfdev_info
*p_vfdev
= &req
->vfdev_info
;
1425 DP_VERBOSE(p_hwfn
, QED_MSG_IOV
,
1426 "VF[%d] is pre-fastpath HSI\n",
1428 p_vfdev
->eth_fp_hsi_major
= ETH_HSI_VER_MAJOR
;
1429 p_vfdev
->eth_fp_hsi_minor
= ETH_HSI_VER_NO_PKT_LEN_TUNN
;
1432 "VF[%d] needs fastpath HSI %02x.%02x, which is incompatible with loaded FW's faspath HSI %02x.%02x\n",
1434 req
->vfdev_info
.eth_fp_hsi_major
,
1435 req
->vfdev_info
.eth_fp_hsi_minor
,
1436 ETH_HSI_VER_MAJOR
, ETH_HSI_VER_MINOR
);
1442 /* On 100g PFs, prevent old VFs from loading */
1443 if ((p_hwfn
->cdev
->num_hwfns
> 1) &&
1444 !(req
->vfdev_info
.capabilities
& VFPF_ACQUIRE_CAP_100G
)) {
1446 "VF[%d] is running an old driver that doesn't support 100g\n",
1451 /* Store the acquire message */
1452 memcpy(&vf
->acquire
, req
, sizeof(vf
->acquire
));
1454 vf
->opaque_fid
= req
->vfdev_info
.opaque_fid
;
1456 vf
->vf_bulletin
= req
->bulletin_addr
;
1457 vf
->bulletin
.size
= (vf
->bulletin
.size
< req
->bulletin_size
) ?
1458 vf
->bulletin
.size
: req
->bulletin_size
;
1460 /* fill in pfdev info */
1461 pfdev_info
->chip_num
= p_hwfn
->cdev
->chip_num
;
1462 pfdev_info
->db_size
= 0;
1463 pfdev_info
->indices_per_sb
= PIS_PER_SB
;
1465 pfdev_info
->capabilities
= PFVF_ACQUIRE_CAP_DEFAULT_UNTAGGED
|
1466 PFVF_ACQUIRE_CAP_POST_FW_OVERRIDE
;
1467 if (p_hwfn
->cdev
->num_hwfns
> 1)
1468 pfdev_info
->capabilities
|= PFVF_ACQUIRE_CAP_100G
;
1470 qed_iov_vf_mbx_acquire_stats(p_hwfn
, &pfdev_info
->stats_info
);
1472 memcpy(pfdev_info
->port_mac
, p_hwfn
->hw_info
.hw_mac_addr
, ETH_ALEN
);
1474 pfdev_info
->fw_major
= FW_MAJOR_VERSION
;
1475 pfdev_info
->fw_minor
= FW_MINOR_VERSION
;
1476 pfdev_info
->fw_rev
= FW_REVISION_VERSION
;
1477 pfdev_info
->fw_eng
= FW_ENGINEERING_VERSION
;
1479 /* Incorrect when legacy, but doesn't matter as legacy isn't reading
1482 pfdev_info
->minor_fp_hsi
= min_t(u8
, ETH_HSI_VER_MINOR
,
1483 req
->vfdev_info
.eth_fp_hsi_minor
);
1484 pfdev_info
->os_type
= VFPF_ACQUIRE_OS_LINUX
;
1485 qed_mcp_get_mfw_ver(p_hwfn
, p_ptt
, &pfdev_info
->mfw_ver
, NULL
);
1487 pfdev_info
->dev_type
= p_hwfn
->cdev
->type
;
1488 pfdev_info
->chip_rev
= p_hwfn
->cdev
->chip_rev
;
1490 /* Fill resources available to VF; Make sure there are enough to
1491 * satisfy the VF's request.
1493 vfpf_status
= qed_iov_vf_mbx_acquire_resc(p_hwfn
, p_ptt
, vf
,
1494 &req
->resc_request
, resc
);
1495 if (vfpf_status
!= PFVF_STATUS_SUCCESS
)
1498 /* Start the VF in FW */
1499 rc
= qed_sp_vf_start(p_hwfn
, vf
);
1501 DP_NOTICE(p_hwfn
, "Failed to start VF[%02x]\n", vf
->abs_vf_id
);
1502 vfpf_status
= PFVF_STATUS_FAILURE
;
1506 /* Fill agreed size of bulletin board in response */
1507 resp
->bulletin_size
= vf
->bulletin
.size
;
1508 qed_iov_post_vf_bulletin(p_hwfn
, vf
->relative_vf_id
, p_ptt
);
1512 "VF[%d] ACQUIRE_RESPONSE: pfdev_info- chip_num=0x%x, db_size=%d, idx_per_sb=%d, pf_cap=0x%llx\n"
1513 "resources- n_rxq-%d, n_txq-%d, n_sbs-%d, n_macs-%d, n_vlans-%d\n",
1515 resp
->pfdev_info
.chip_num
,
1516 resp
->pfdev_info
.db_size
,
1517 resp
->pfdev_info
.indices_per_sb
,
1518 resp
->pfdev_info
.capabilities
,
1522 resc
->num_mac_filters
,
1523 resc
->num_vlan_filters
);
1524 vf
->state
= VF_ACQUIRED
;
1526 /* Prepare Response */
1528 qed_iov_prepare_resp(p_hwfn
, p_ptt
, vf
, CHANNEL_TLV_ACQUIRE
,
1529 sizeof(struct pfvf_acquire_resp_tlv
), vfpf_status
);
1532 static int __qed_iov_spoofchk_set(struct qed_hwfn
*p_hwfn
,
1533 struct qed_vf_info
*p_vf
, bool val
)
1535 struct qed_sp_vport_update_params params
;
1538 if (val
== p_vf
->spoof_chk
) {
1539 DP_VERBOSE(p_hwfn
, QED_MSG_IOV
,
1540 "Spoofchk value[%d] is already configured\n", val
);
1544 memset(¶ms
, 0, sizeof(struct qed_sp_vport_update_params
));
1545 params
.opaque_fid
= p_vf
->opaque_fid
;
1546 params
.vport_id
= p_vf
->vport_id
;
1547 params
.update_anti_spoofing_en_flg
= 1;
1548 params
.anti_spoofing_en
= val
;
1550 rc
= qed_sp_vport_update(p_hwfn
, ¶ms
, QED_SPQ_MODE_EBLOCK
, NULL
);
1552 p_vf
->spoof_chk
= val
;
1553 p_vf
->req_spoofchk_val
= p_vf
->spoof_chk
;
1554 DP_VERBOSE(p_hwfn
, QED_MSG_IOV
,
1555 "Spoofchk val[%d] configured\n", val
);
1557 DP_VERBOSE(p_hwfn
, QED_MSG_IOV
,
1558 "Spoofchk configuration[val:%d] failed for VF[%d]\n",
1559 val
, p_vf
->relative_vf_id
);
1565 static int qed_iov_reconfigure_unicast_vlan(struct qed_hwfn
*p_hwfn
,
1566 struct qed_vf_info
*p_vf
)
1568 struct qed_filter_ucast filter
;
1572 memset(&filter
, 0, sizeof(filter
));
1573 filter
.is_rx_filter
= 1;
1574 filter
.is_tx_filter
= 1;
1575 filter
.vport_to_add_to
= p_vf
->vport_id
;
1576 filter
.opcode
= QED_FILTER_ADD
;
1578 /* Reconfigure vlans */
1579 for (i
= 0; i
< QED_ETH_VF_NUM_VLAN_FILTERS
+ 1; i
++) {
1580 if (!p_vf
->shadow_config
.vlans
[i
].used
)
1583 filter
.type
= QED_FILTER_VLAN
;
1584 filter
.vlan
= p_vf
->shadow_config
.vlans
[i
].vid
;
1585 DP_VERBOSE(p_hwfn
, QED_MSG_IOV
,
1586 "Reconfiguring VLAN [0x%04x] for VF [%04x]\n",
1587 filter
.vlan
, p_vf
->relative_vf_id
);
1588 rc
= qed_sp_eth_filter_ucast(p_hwfn
, p_vf
->opaque_fid
,
1589 &filter
, QED_SPQ_MODE_CB
, NULL
);
1592 "Failed to configure VLAN [%04x] to VF [%04x]\n",
1593 filter
.vlan
, p_vf
->relative_vf_id
);
1602 qed_iov_reconfigure_unicast_shadow(struct qed_hwfn
*p_hwfn
,
1603 struct qed_vf_info
*p_vf
, u64 events
)
1607 if ((events
& BIT(VLAN_ADDR_FORCED
)) &&
1608 !(p_vf
->configured_features
& (1 << VLAN_ADDR_FORCED
)))
1609 rc
= qed_iov_reconfigure_unicast_vlan(p_hwfn
, p_vf
);
1614 static int qed_iov_configure_vport_forced(struct qed_hwfn
*p_hwfn
,
1615 struct qed_vf_info
*p_vf
, u64 events
)
1618 struct qed_filter_ucast filter
;
1620 if (!p_vf
->vport_instance
)
1623 if (events
& BIT(MAC_ADDR_FORCED
)) {
1624 /* Since there's no way [currently] of removing the MAC,
1625 * we can always assume this means we need to force it.
1627 memset(&filter
, 0, sizeof(filter
));
1628 filter
.type
= QED_FILTER_MAC
;
1629 filter
.opcode
= QED_FILTER_REPLACE
;
1630 filter
.is_rx_filter
= 1;
1631 filter
.is_tx_filter
= 1;
1632 filter
.vport_to_add_to
= p_vf
->vport_id
;
1633 ether_addr_copy(filter
.mac
, p_vf
->bulletin
.p_virt
->mac
);
1635 rc
= qed_sp_eth_filter_ucast(p_hwfn
, p_vf
->opaque_fid
,
1636 &filter
, QED_SPQ_MODE_CB
, NULL
);
1639 "PF failed to configure MAC for VF\n");
1643 p_vf
->configured_features
|= 1 << MAC_ADDR_FORCED
;
1646 if (events
& BIT(VLAN_ADDR_FORCED
)) {
1647 struct qed_sp_vport_update_params vport_update
;
1651 memset(&filter
, 0, sizeof(filter
));
1652 filter
.type
= QED_FILTER_VLAN
;
1653 filter
.is_rx_filter
= 1;
1654 filter
.is_tx_filter
= 1;
1655 filter
.vport_to_add_to
= p_vf
->vport_id
;
1656 filter
.vlan
= p_vf
->bulletin
.p_virt
->pvid
;
1657 filter
.opcode
= filter
.vlan
? QED_FILTER_REPLACE
:
1660 /* Send the ramrod */
1661 rc
= qed_sp_eth_filter_ucast(p_hwfn
, p_vf
->opaque_fid
,
1662 &filter
, QED_SPQ_MODE_CB
, NULL
);
1665 "PF failed to configure VLAN for VF\n");
1669 /* Update the default-vlan & silent vlan stripping */
1670 memset(&vport_update
, 0, sizeof(vport_update
));
1671 vport_update
.opaque_fid
= p_vf
->opaque_fid
;
1672 vport_update
.vport_id
= p_vf
->vport_id
;
1673 vport_update
.update_default_vlan_enable_flg
= 1;
1674 vport_update
.default_vlan_enable_flg
= filter
.vlan
? 1 : 0;
1675 vport_update
.update_default_vlan_flg
= 1;
1676 vport_update
.default_vlan
= filter
.vlan
;
1678 vport_update
.update_inner_vlan_removal_flg
= 1;
1679 removal
= filter
.vlan
? 1
1680 : p_vf
->shadow_config
.inner_vlan_removal
;
1681 vport_update
.inner_vlan_removal_flg
= removal
;
1682 vport_update
.silent_vlan_removal_flg
= filter
.vlan
? 1 : 0;
1683 rc
= qed_sp_vport_update(p_hwfn
,
1685 QED_SPQ_MODE_EBLOCK
, NULL
);
1688 "PF failed to configure VF vport for vlan\n");
1692 /* Update all the Rx queues */
1693 for (i
= 0; i
< QED_MAX_VF_CHAINS_PER_PF
; i
++) {
1694 struct qed_queue_cid
*p_cid
;
1696 p_cid
= p_vf
->vf_queues
[i
].p_rx_cid
;
1700 rc
= qed_sp_eth_rx_queues_update(p_hwfn
,
1703 QED_SPQ_MODE_EBLOCK
,
1707 "Failed to send Rx update fo queue[0x%04x]\n",
1708 p_cid
->rel
.queue_id
);
1714 p_vf
->configured_features
|= 1 << VLAN_ADDR_FORCED
;
1716 p_vf
->configured_features
&= ~BIT(VLAN_ADDR_FORCED
);
1719 /* If forced features are terminated, we need to configure the shadow
1720 * configuration back again.
1723 qed_iov_reconfigure_unicast_shadow(p_hwfn
, p_vf
, events
);
1728 static void qed_iov_vf_mbx_start_vport(struct qed_hwfn
*p_hwfn
,
1729 struct qed_ptt
*p_ptt
,
1730 struct qed_vf_info
*vf
)
1732 struct qed_sp_vport_start_params params
= { 0 };
1733 struct qed_iov_vf_mbx
*mbx
= &vf
->vf_mbx
;
1734 struct vfpf_vport_start_tlv
*start
;
1735 u8 status
= PFVF_STATUS_SUCCESS
;
1736 struct qed_vf_info
*vf_info
;
1741 vf_info
= qed_iov_get_vf_info(p_hwfn
, (u16
) vf
->relative_vf_id
, true);
1743 DP_NOTICE(p_hwfn
->cdev
,
1744 "Failed to get VF info, invalid vfid [%d]\n",
1745 vf
->relative_vf_id
);
1749 vf
->state
= VF_ENABLED
;
1750 start
= &mbx
->req_virt
->start_vport
;
1752 /* Initialize Status block in CAU */
1753 for (sb_id
= 0; sb_id
< vf
->num_sbs
; sb_id
++) {
1754 if (!start
->sb_addr
[sb_id
]) {
1755 DP_VERBOSE(p_hwfn
, QED_MSG_IOV
,
1756 "VF[%d] did not fill the address of SB %d\n",
1757 vf
->relative_vf_id
, sb_id
);
1761 qed_int_cau_conf_sb(p_hwfn
, p_ptt
,
1762 start
->sb_addr
[sb_id
],
1763 vf
->igu_sbs
[sb_id
], vf
->abs_vf_id
, 1);
1765 qed_iov_enable_vf_traffic(p_hwfn
, p_ptt
, vf
);
1767 vf
->mtu
= start
->mtu
;
1768 vf
->shadow_config
.inner_vlan_removal
= start
->inner_vlan_removal
;
1770 /* Take into consideration configuration forced by hypervisor;
1771 * If none is configured, use the supplied VF values [for old
1772 * vfs that would still be fine, since they passed '0' as padding].
1774 p_bitmap
= &vf_info
->bulletin
.p_virt
->valid_bitmap
;
1775 if (!(*p_bitmap
& BIT(VFPF_BULLETIN_UNTAGGED_DEFAULT_FORCED
))) {
1776 u8 vf_req
= start
->only_untagged
;
1778 vf_info
->bulletin
.p_virt
->default_only_untagged
= vf_req
;
1779 *p_bitmap
|= 1 << VFPF_BULLETIN_UNTAGGED_DEFAULT
;
1782 params
.tpa_mode
= start
->tpa_mode
;
1783 params
.remove_inner_vlan
= start
->inner_vlan_removal
;
1784 params
.tx_switching
= true;
1786 params
.only_untagged
= vf_info
->bulletin
.p_virt
->default_only_untagged
;
1787 params
.drop_ttl0
= false;
1788 params
.concrete_fid
= vf
->concrete_fid
;
1789 params
.opaque_fid
= vf
->opaque_fid
;
1790 params
.vport_id
= vf
->vport_id
;
1791 params
.max_buffers_per_cqe
= start
->max_buffers_per_cqe
;
1792 params
.mtu
= vf
->mtu
;
1793 params
.check_mac
= true;
1795 rc
= qed_sp_eth_vport_start(p_hwfn
, ¶ms
);
1798 "qed_iov_vf_mbx_start_vport returned error %d\n", rc
);
1799 status
= PFVF_STATUS_FAILURE
;
1801 vf
->vport_instance
++;
1803 /* Force configuration if needed on the newly opened vport */
1804 qed_iov_configure_vport_forced(p_hwfn
, vf
, *p_bitmap
);
1806 __qed_iov_spoofchk_set(p_hwfn
, vf
, vf
->req_spoofchk_val
);
1808 qed_iov_prepare_resp(p_hwfn
, p_ptt
, vf
, CHANNEL_TLV_VPORT_START
,
1809 sizeof(struct pfvf_def_resp_tlv
), status
);
1812 static void qed_iov_vf_mbx_stop_vport(struct qed_hwfn
*p_hwfn
,
1813 struct qed_ptt
*p_ptt
,
1814 struct qed_vf_info
*vf
)
1816 u8 status
= PFVF_STATUS_SUCCESS
;
1819 vf
->vport_instance
--;
1820 vf
->spoof_chk
= false;
1822 rc
= qed_sp_vport_stop(p_hwfn
, vf
->opaque_fid
, vf
->vport_id
);
1824 DP_ERR(p_hwfn
, "qed_iov_vf_mbx_stop_vport returned error %d\n",
1826 status
= PFVF_STATUS_FAILURE
;
1829 /* Forget the configuration on the vport */
1830 vf
->configured_features
= 0;
1831 memset(&vf
->shadow_config
, 0, sizeof(vf
->shadow_config
));
1833 qed_iov_prepare_resp(p_hwfn
, p_ptt
, vf
, CHANNEL_TLV_VPORT_TEARDOWN
,
1834 sizeof(struct pfvf_def_resp_tlv
), status
);
1837 static void qed_iov_vf_mbx_start_rxq_resp(struct qed_hwfn
*p_hwfn
,
1838 struct qed_ptt
*p_ptt
,
1839 struct qed_vf_info
*vf
,
1840 u8 status
, bool b_legacy
)
1842 struct qed_iov_vf_mbx
*mbx
= &vf
->vf_mbx
;
1843 struct pfvf_start_queue_resp_tlv
*p_tlv
;
1844 struct vfpf_start_rxq_tlv
*req
;
1847 mbx
->offset
= (u8
*)mbx
->reply_virt
;
1849 /* Taking a bigger struct instead of adding a TLV to list was a
1850 * mistake, but one which we're now stuck with, as some older
1851 * clients assume the size of the previous response.
1854 length
= sizeof(*p_tlv
);
1856 length
= sizeof(struct pfvf_def_resp_tlv
);
1858 p_tlv
= qed_add_tlv(p_hwfn
, &mbx
->offset
, CHANNEL_TLV_START_RXQ
,
1860 qed_add_tlv(p_hwfn
, &mbx
->offset
, CHANNEL_TLV_LIST_END
,
1861 sizeof(struct channel_list_end_tlv
));
1863 /* Update the TLV with the response */
1864 if ((status
== PFVF_STATUS_SUCCESS
) && !b_legacy
) {
1865 req
= &mbx
->req_virt
->start_rxq
;
1866 p_tlv
->offset
= PXP_VF_BAR0_START_MSDM_ZONE_B
+
1867 offsetof(struct mstorm_vf_zone
,
1868 non_trigger
.eth_rx_queue_producers
) +
1869 sizeof(struct eth_rx_prod_data
) * req
->rx_qid
;
1872 qed_iov_send_response(p_hwfn
, p_ptt
, vf
, length
, status
);
1875 static void qed_iov_vf_mbx_start_rxq(struct qed_hwfn
*p_hwfn
,
1876 struct qed_ptt
*p_ptt
,
1877 struct qed_vf_info
*vf
)
1879 struct qed_queue_start_common_params params
;
1880 struct qed_iov_vf_mbx
*mbx
= &vf
->vf_mbx
;
1881 u8 status
= PFVF_STATUS_NO_RESOURCE
;
1882 struct qed_vf_q_info
*p_queue
;
1883 struct vfpf_start_rxq_tlv
*req
;
1884 bool b_legacy_vf
= false;
1887 req
= &mbx
->req_virt
->start_rxq
;
1889 if (!qed_iov_validate_rxq(p_hwfn
, vf
, req
->rx_qid
) ||
1890 !qed_iov_validate_sb(p_hwfn
, vf
, req
->hw_sb
))
1893 /* Acquire a new queue-cid */
1894 p_queue
= &vf
->vf_queues
[req
->rx_qid
];
1896 memset(¶ms
, 0, sizeof(params
));
1897 params
.queue_id
= p_queue
->fw_rx_qid
;
1898 params
.vport_id
= vf
->vport_id
;
1899 params
.stats_id
= vf
->abs_vf_id
+ 0x10;
1900 params
.sb
= req
->hw_sb
;
1901 params
.sb_idx
= req
->sb_index
;
1903 p_queue
->p_rx_cid
= _qed_eth_queue_to_cid(p_hwfn
,
1906 req
->rx_qid
, ¶ms
);
1907 if (!p_queue
->p_rx_cid
)
1910 /* Legacy VFs have their Producers in a different location, which they
1911 * calculate on their own and clean the producer prior to this.
1913 if (vf
->acquire
.vfdev_info
.eth_fp_hsi_minor
==
1914 ETH_HSI_VER_NO_PKT_LEN_TUNN
) {
1918 GTT_BAR0_MAP_REG_MSDM_RAM
+
1919 MSTORM_ETH_VF_PRODS_OFFSET(vf
->abs_vf_id
, req
->rx_qid
),
1922 p_queue
->p_rx_cid
->b_legacy_vf
= b_legacy_vf
;
1924 rc
= qed_eth_rxq_start_ramrod(p_hwfn
,
1928 req
->cqe_pbl_addr
, req
->cqe_pbl_size
);
1930 status
= PFVF_STATUS_FAILURE
;
1931 qed_eth_queue_cid_release(p_hwfn
, p_queue
->p_rx_cid
);
1932 p_queue
->p_rx_cid
= NULL
;
1934 status
= PFVF_STATUS_SUCCESS
;
1935 vf
->num_active_rxqs
++;
1939 qed_iov_vf_mbx_start_rxq_resp(p_hwfn
, p_ptt
, vf
, status
, b_legacy_vf
);
1942 static void qed_iov_vf_mbx_start_txq_resp(struct qed_hwfn
*p_hwfn
,
1943 struct qed_ptt
*p_ptt
,
1944 struct qed_vf_info
*p_vf
, u8 status
)
1946 struct qed_iov_vf_mbx
*mbx
= &p_vf
->vf_mbx
;
1947 struct pfvf_start_queue_resp_tlv
*p_tlv
;
1948 bool b_legacy
= false;
1951 mbx
->offset
= (u8
*)mbx
->reply_virt
;
1953 /* Taking a bigger struct instead of adding a TLV to list was a
1954 * mistake, but one which we're now stuck with, as some older
1955 * clients assume the size of the previous response.
1957 if (p_vf
->acquire
.vfdev_info
.eth_fp_hsi_minor
==
1958 ETH_HSI_VER_NO_PKT_LEN_TUNN
)
1962 length
= sizeof(*p_tlv
);
1964 length
= sizeof(struct pfvf_def_resp_tlv
);
1966 p_tlv
= qed_add_tlv(p_hwfn
, &mbx
->offset
, CHANNEL_TLV_START_TXQ
,
1968 qed_add_tlv(p_hwfn
, &mbx
->offset
, CHANNEL_TLV_LIST_END
,
1969 sizeof(struct channel_list_end_tlv
));
1971 /* Update the TLV with the response */
1972 if ((status
== PFVF_STATUS_SUCCESS
) && !b_legacy
) {
1973 u16 qid
= mbx
->req_virt
->start_txq
.tx_qid
;
1975 p_tlv
->offset
= qed_db_addr_vf(p_vf
->vf_queues
[qid
].fw_cid
,
1979 qed_iov_send_response(p_hwfn
, p_ptt
, p_vf
, length
, status
);
1982 static void qed_iov_vf_mbx_start_txq(struct qed_hwfn
*p_hwfn
,
1983 struct qed_ptt
*p_ptt
,
1984 struct qed_vf_info
*vf
)
1986 struct qed_queue_start_common_params params
;
1987 struct qed_iov_vf_mbx
*mbx
= &vf
->vf_mbx
;
1988 u8 status
= PFVF_STATUS_NO_RESOURCE
;
1989 union qed_qm_pq_params pq_params
;
1990 struct vfpf_start_txq_tlv
*req
;
1991 struct qed_vf_q_info
*p_queue
;
1995 /* Prepare the parameters which would choose the right PQ */
1996 memset(&pq_params
, 0, sizeof(pq_params
));
1997 pq_params
.eth
.is_vf
= 1;
1998 pq_params
.eth
.vf_id
= vf
->relative_vf_id
;
2000 memset(¶ms
, 0, sizeof(params
));
2001 req
= &mbx
->req_virt
->start_txq
;
2003 if (!qed_iov_validate_txq(p_hwfn
, vf
, req
->tx_qid
) ||
2004 !qed_iov_validate_sb(p_hwfn
, vf
, req
->hw_sb
))
2007 /* Acquire a new queue-cid */
2008 p_queue
= &vf
->vf_queues
[req
->tx_qid
];
2010 params
.queue_id
= p_queue
->fw_tx_qid
;
2011 params
.vport_id
= vf
->vport_id
;
2012 params
.stats_id
= vf
->abs_vf_id
+ 0x10;
2013 params
.sb
= req
->hw_sb
;
2014 params
.sb_idx
= req
->sb_index
;
2016 p_queue
->p_tx_cid
= _qed_eth_queue_to_cid(p_hwfn
,
2019 req
->tx_qid
, ¶ms
);
2020 if (!p_queue
->p_tx_cid
)
2023 pq
= qed_get_qm_pq(p_hwfn
, PROTOCOLID_ETH
, &pq_params
);
2024 rc
= qed_eth_txq_start_ramrod(p_hwfn
, p_queue
->p_tx_cid
,
2025 req
->pbl_addr
, req
->pbl_size
, pq
);
2027 status
= PFVF_STATUS_FAILURE
;
2028 qed_eth_queue_cid_release(p_hwfn
, p_queue
->p_tx_cid
);
2029 p_queue
->p_tx_cid
= NULL
;
2031 status
= PFVF_STATUS_SUCCESS
;
2035 qed_iov_vf_mbx_start_txq_resp(p_hwfn
, p_ptt
, vf
, status
);
2038 static int qed_iov_vf_stop_rxqs(struct qed_hwfn
*p_hwfn
,
2039 struct qed_vf_info
*vf
,
2040 u16 rxq_id
, u8 num_rxqs
, bool cqe_completion
)
2042 struct qed_vf_q_info
*p_queue
;
2046 if (rxq_id
+ num_rxqs
> ARRAY_SIZE(vf
->vf_queues
))
2049 for (qid
= rxq_id
; qid
< rxq_id
+ num_rxqs
; qid
++) {
2050 p_queue
= &vf
->vf_queues
[qid
];
2052 if (!p_queue
->p_rx_cid
)
2055 rc
= qed_eth_rx_queue_stop(p_hwfn
,
2057 false, cqe_completion
);
2061 vf
->vf_queues
[qid
].p_rx_cid
= NULL
;
2062 vf
->num_active_rxqs
--;
2068 static int qed_iov_vf_stop_txqs(struct qed_hwfn
*p_hwfn
,
2069 struct qed_vf_info
*vf
, u16 txq_id
, u8 num_txqs
)
2072 struct qed_vf_q_info
*p_queue
;
2075 if (txq_id
+ num_txqs
> ARRAY_SIZE(vf
->vf_queues
))
2078 for (qid
= txq_id
; qid
< txq_id
+ num_txqs
; qid
++) {
2079 p_queue
= &vf
->vf_queues
[qid
];
2080 if (!p_queue
->p_tx_cid
)
2083 rc
= qed_eth_tx_queue_stop(p_hwfn
, p_queue
->p_tx_cid
);
2087 p_queue
->p_tx_cid
= NULL
;
2093 static void qed_iov_vf_mbx_stop_rxqs(struct qed_hwfn
*p_hwfn
,
2094 struct qed_ptt
*p_ptt
,
2095 struct qed_vf_info
*vf
)
2097 u16 length
= sizeof(struct pfvf_def_resp_tlv
);
2098 struct qed_iov_vf_mbx
*mbx
= &vf
->vf_mbx
;
2099 u8 status
= PFVF_STATUS_SUCCESS
;
2100 struct vfpf_stop_rxqs_tlv
*req
;
2103 /* We give the option of starting from qid != 0, in this case we
2104 * need to make sure that qid + num_qs doesn't exceed the actual
2105 * amount of queues that exist.
2107 req
= &mbx
->req_virt
->stop_rxqs
;
2108 rc
= qed_iov_vf_stop_rxqs(p_hwfn
, vf
, req
->rx_qid
,
2109 req
->num_rxqs
, req
->cqe_completion
);
2111 status
= PFVF_STATUS_FAILURE
;
2113 qed_iov_prepare_resp(p_hwfn
, p_ptt
, vf
, CHANNEL_TLV_STOP_RXQS
,
2117 static void qed_iov_vf_mbx_stop_txqs(struct qed_hwfn
*p_hwfn
,
2118 struct qed_ptt
*p_ptt
,
2119 struct qed_vf_info
*vf
)
2121 u16 length
= sizeof(struct pfvf_def_resp_tlv
);
2122 struct qed_iov_vf_mbx
*mbx
= &vf
->vf_mbx
;
2123 u8 status
= PFVF_STATUS_SUCCESS
;
2124 struct vfpf_stop_txqs_tlv
*req
;
2127 /* We give the option of starting from qid != 0, in this case we
2128 * need to make sure that qid + num_qs doesn't exceed the actual
2129 * amount of queues that exist.
2131 req
= &mbx
->req_virt
->stop_txqs
;
2132 rc
= qed_iov_vf_stop_txqs(p_hwfn
, vf
, req
->tx_qid
, req
->num_txqs
);
2134 status
= PFVF_STATUS_FAILURE
;
2136 qed_iov_prepare_resp(p_hwfn
, p_ptt
, vf
, CHANNEL_TLV_STOP_TXQS
,
2140 static void qed_iov_vf_mbx_update_rxqs(struct qed_hwfn
*p_hwfn
,
2141 struct qed_ptt
*p_ptt
,
2142 struct qed_vf_info
*vf
)
2144 struct qed_queue_cid
*handlers
[QED_MAX_VF_CHAINS_PER_PF
];
2145 u16 length
= sizeof(struct pfvf_def_resp_tlv
);
2146 struct qed_iov_vf_mbx
*mbx
= &vf
->vf_mbx
;
2147 struct vfpf_update_rxq_tlv
*req
;
2148 u8 status
= PFVF_STATUS_FAILURE
;
2149 u8 complete_event_flg
;
2150 u8 complete_cqe_flg
;
2155 req
= &mbx
->req_virt
->update_rxq
;
2156 complete_cqe_flg
= !!(req
->flags
& VFPF_RXQ_UPD_COMPLETE_CQE_FLAG
);
2157 complete_event_flg
= !!(req
->flags
& VFPF_RXQ_UPD_COMPLETE_EVENT_FLAG
);
2159 /* Validate inputs */
2160 if (req
->num_rxqs
+ req
->rx_qid
> QED_MAX_VF_CHAINS_PER_PF
||
2161 !qed_iov_validate_rxq(p_hwfn
, vf
, req
->rx_qid
)) {
2162 DP_INFO(p_hwfn
, "VF[%d]: Incorrect Rxqs [%04x, %02x]\n",
2163 vf
->relative_vf_id
, req
->rx_qid
, req
->num_rxqs
);
2167 for (i
= 0; i
< req
->num_rxqs
; i
++) {
2168 qid
= req
->rx_qid
+ i
;
2169 if (!vf
->vf_queues
[qid
].p_rx_cid
) {
2171 "VF[%d] rx_qid = %d isn`t active!\n",
2172 vf
->relative_vf_id
, qid
);
2176 handlers
[i
] = vf
->vf_queues
[qid
].p_rx_cid
;
2179 rc
= qed_sp_eth_rx_queues_update(p_hwfn
, (void **)&handlers
,
2183 QED_SPQ_MODE_EBLOCK
, NULL
);
2187 status
= PFVF_STATUS_SUCCESS
;
2189 qed_iov_prepare_resp(p_hwfn
, p_ptt
, vf
, CHANNEL_TLV_UPDATE_RXQ
,
2193 void *qed_iov_search_list_tlvs(struct qed_hwfn
*p_hwfn
,
2194 void *p_tlvs_list
, u16 req_type
)
2196 struct channel_tlv
*p_tlv
= (struct channel_tlv
*)p_tlvs_list
;
2200 if (!p_tlv
->length
) {
2201 DP_NOTICE(p_hwfn
, "Zero length TLV found\n");
2205 if (p_tlv
->type
== req_type
) {
2206 DP_VERBOSE(p_hwfn
, QED_MSG_IOV
,
2207 "Extended tlv type %d, length %d found\n",
2208 p_tlv
->type
, p_tlv
->length
);
2212 len
+= p_tlv
->length
;
2213 p_tlv
= (struct channel_tlv
*)((u8
*)p_tlv
+ p_tlv
->length
);
2215 if ((len
+ p_tlv
->length
) > TLV_BUFFER_SIZE
) {
2216 DP_NOTICE(p_hwfn
, "TLVs has overrun the buffer size\n");
2219 } while (p_tlv
->type
!= CHANNEL_TLV_LIST_END
);
2225 qed_iov_vp_update_act_param(struct qed_hwfn
*p_hwfn
,
2226 struct qed_sp_vport_update_params
*p_data
,
2227 struct qed_iov_vf_mbx
*p_mbx
, u16
*tlvs_mask
)
2229 struct vfpf_vport_update_activate_tlv
*p_act_tlv
;
2230 u16 tlv
= CHANNEL_TLV_VPORT_UPDATE_ACTIVATE
;
2232 p_act_tlv
= (struct vfpf_vport_update_activate_tlv
*)
2233 qed_iov_search_list_tlvs(p_hwfn
, p_mbx
->req_virt
, tlv
);
2237 p_data
->update_vport_active_rx_flg
= p_act_tlv
->update_rx
;
2238 p_data
->vport_active_rx_flg
= p_act_tlv
->active_rx
;
2239 p_data
->update_vport_active_tx_flg
= p_act_tlv
->update_tx
;
2240 p_data
->vport_active_tx_flg
= p_act_tlv
->active_tx
;
2241 *tlvs_mask
|= 1 << QED_IOV_VP_UPDATE_ACTIVATE
;
2245 qed_iov_vp_update_vlan_param(struct qed_hwfn
*p_hwfn
,
2246 struct qed_sp_vport_update_params
*p_data
,
2247 struct qed_vf_info
*p_vf
,
2248 struct qed_iov_vf_mbx
*p_mbx
, u16
*tlvs_mask
)
2250 struct vfpf_vport_update_vlan_strip_tlv
*p_vlan_tlv
;
2251 u16 tlv
= CHANNEL_TLV_VPORT_UPDATE_VLAN_STRIP
;
2253 p_vlan_tlv
= (struct vfpf_vport_update_vlan_strip_tlv
*)
2254 qed_iov_search_list_tlvs(p_hwfn
, p_mbx
->req_virt
, tlv
);
2258 p_vf
->shadow_config
.inner_vlan_removal
= p_vlan_tlv
->remove_vlan
;
2260 /* Ignore the VF request if we're forcing a vlan */
2261 if (!(p_vf
->configured_features
& BIT(VLAN_ADDR_FORCED
))) {
2262 p_data
->update_inner_vlan_removal_flg
= 1;
2263 p_data
->inner_vlan_removal_flg
= p_vlan_tlv
->remove_vlan
;
2266 *tlvs_mask
|= 1 << QED_IOV_VP_UPDATE_VLAN_STRIP
;
2270 qed_iov_vp_update_tx_switch(struct qed_hwfn
*p_hwfn
,
2271 struct qed_sp_vport_update_params
*p_data
,
2272 struct qed_iov_vf_mbx
*p_mbx
, u16
*tlvs_mask
)
2274 struct vfpf_vport_update_tx_switch_tlv
*p_tx_switch_tlv
;
2275 u16 tlv
= CHANNEL_TLV_VPORT_UPDATE_TX_SWITCH
;
2277 p_tx_switch_tlv
= (struct vfpf_vport_update_tx_switch_tlv
*)
2278 qed_iov_search_list_tlvs(p_hwfn
, p_mbx
->req_virt
,
2280 if (!p_tx_switch_tlv
)
2283 p_data
->update_tx_switching_flg
= 1;
2284 p_data
->tx_switching_flg
= p_tx_switch_tlv
->tx_switching
;
2285 *tlvs_mask
|= 1 << QED_IOV_VP_UPDATE_TX_SWITCH
;
2289 qed_iov_vp_update_mcast_bin_param(struct qed_hwfn
*p_hwfn
,
2290 struct qed_sp_vport_update_params
*p_data
,
2291 struct qed_iov_vf_mbx
*p_mbx
, u16
*tlvs_mask
)
2293 struct vfpf_vport_update_mcast_bin_tlv
*p_mcast_tlv
;
2294 u16 tlv
= CHANNEL_TLV_VPORT_UPDATE_MCAST
;
2296 p_mcast_tlv
= (struct vfpf_vport_update_mcast_bin_tlv
*)
2297 qed_iov_search_list_tlvs(p_hwfn
, p_mbx
->req_virt
, tlv
);
2301 p_data
->update_approx_mcast_flg
= 1;
2302 memcpy(p_data
->bins
, p_mcast_tlv
->bins
,
2303 sizeof(unsigned long) * ETH_MULTICAST_MAC_BINS_IN_REGS
);
2304 *tlvs_mask
|= 1 << QED_IOV_VP_UPDATE_MCAST
;
2308 qed_iov_vp_update_accept_flag(struct qed_hwfn
*p_hwfn
,
2309 struct qed_sp_vport_update_params
*p_data
,
2310 struct qed_iov_vf_mbx
*p_mbx
, u16
*tlvs_mask
)
2312 struct qed_filter_accept_flags
*p_flags
= &p_data
->accept_flags
;
2313 struct vfpf_vport_update_accept_param_tlv
*p_accept_tlv
;
2314 u16 tlv
= CHANNEL_TLV_VPORT_UPDATE_ACCEPT_PARAM
;
2316 p_accept_tlv
= (struct vfpf_vport_update_accept_param_tlv
*)
2317 qed_iov_search_list_tlvs(p_hwfn
, p_mbx
->req_virt
, tlv
);
2321 p_flags
->update_rx_mode_config
= p_accept_tlv
->update_rx_mode
;
2322 p_flags
->rx_accept_filter
= p_accept_tlv
->rx_accept_filter
;
2323 p_flags
->update_tx_mode_config
= p_accept_tlv
->update_tx_mode
;
2324 p_flags
->tx_accept_filter
= p_accept_tlv
->tx_accept_filter
;
2325 *tlvs_mask
|= 1 << QED_IOV_VP_UPDATE_ACCEPT_PARAM
;
2329 qed_iov_vp_update_accept_any_vlan(struct qed_hwfn
*p_hwfn
,
2330 struct qed_sp_vport_update_params
*p_data
,
2331 struct qed_iov_vf_mbx
*p_mbx
, u16
*tlvs_mask
)
2333 struct vfpf_vport_update_accept_any_vlan_tlv
*p_accept_any_vlan
;
2334 u16 tlv
= CHANNEL_TLV_VPORT_UPDATE_ACCEPT_ANY_VLAN
;
2336 p_accept_any_vlan
= (struct vfpf_vport_update_accept_any_vlan_tlv
*)
2337 qed_iov_search_list_tlvs(p_hwfn
, p_mbx
->req_virt
,
2339 if (!p_accept_any_vlan
)
2342 p_data
->accept_any_vlan
= p_accept_any_vlan
->accept_any_vlan
;
2343 p_data
->update_accept_any_vlan_flg
=
2344 p_accept_any_vlan
->update_accept_any_vlan_flg
;
2345 *tlvs_mask
|= 1 << QED_IOV_VP_UPDATE_ACCEPT_ANY_VLAN
;
2349 qed_iov_vp_update_rss_param(struct qed_hwfn
*p_hwfn
,
2350 struct qed_vf_info
*vf
,
2351 struct qed_sp_vport_update_params
*p_data
,
2352 struct qed_rss_params
*p_rss
,
2353 struct qed_iov_vf_mbx
*p_mbx
,
2354 u16
*tlvs_mask
, u16
*tlvs_accepted
)
2356 struct vfpf_vport_update_rss_tlv
*p_rss_tlv
;
2357 u16 tlv
= CHANNEL_TLV_VPORT_UPDATE_RSS
;
2358 bool b_reject
= false;
2362 p_rss_tlv
= (struct vfpf_vport_update_rss_tlv
*)
2363 qed_iov_search_list_tlvs(p_hwfn
, p_mbx
->req_virt
, tlv
);
2365 p_data
->rss_params
= NULL
;
2369 memset(p_rss
, 0, sizeof(struct qed_rss_params
));
2371 p_rss
->update_rss_config
= !!(p_rss_tlv
->update_rss_flags
&
2372 VFPF_UPDATE_RSS_CONFIG_FLAG
);
2373 p_rss
->update_rss_capabilities
= !!(p_rss_tlv
->update_rss_flags
&
2374 VFPF_UPDATE_RSS_CAPS_FLAG
);
2375 p_rss
->update_rss_ind_table
= !!(p_rss_tlv
->update_rss_flags
&
2376 VFPF_UPDATE_RSS_IND_TABLE_FLAG
);
2377 p_rss
->update_rss_key
= !!(p_rss_tlv
->update_rss_flags
&
2378 VFPF_UPDATE_RSS_KEY_FLAG
);
2380 p_rss
->rss_enable
= p_rss_tlv
->rss_enable
;
2381 p_rss
->rss_eng_id
= vf
->relative_vf_id
+ 1;
2382 p_rss
->rss_caps
= p_rss_tlv
->rss_caps
;
2383 p_rss
->rss_table_size_log
= p_rss_tlv
->rss_table_size_log
;
2384 memcpy(p_rss
->rss_key
, p_rss_tlv
->rss_key
, sizeof(p_rss
->rss_key
));
2386 table_size
= min_t(u16
, ARRAY_SIZE(p_rss
->rss_ind_table
),
2387 (1 << p_rss_tlv
->rss_table_size_log
));
2389 for (i
= 0; i
< table_size
; i
++) {
2390 q_idx
= p_rss_tlv
->rss_ind_table
[i
];
2391 if (!qed_iov_validate_rxq(p_hwfn
, vf
, q_idx
)) {
2394 "VF[%d]: Omitting RSS due to wrong queue %04x\n",
2395 vf
->relative_vf_id
, q_idx
);
2400 if (!vf
->vf_queues
[q_idx
].p_rx_cid
) {
2403 "VF[%d]: Omitting RSS due to inactive queue %08x\n",
2404 vf
->relative_vf_id
, q_idx
);
2409 p_rss
->rss_ind_table
[i
] = vf
->vf_queues
[q_idx
].p_rx_cid
;
2412 p_data
->rss_params
= p_rss
;
2414 *tlvs_mask
|= 1 << QED_IOV_VP_UPDATE_RSS
;
2416 *tlvs_accepted
|= 1 << QED_IOV_VP_UPDATE_RSS
;
2420 qed_iov_vp_update_sge_tpa_param(struct qed_hwfn
*p_hwfn
,
2421 struct qed_vf_info
*vf
,
2422 struct qed_sp_vport_update_params
*p_data
,
2423 struct qed_sge_tpa_params
*p_sge_tpa
,
2424 struct qed_iov_vf_mbx
*p_mbx
, u16
*tlvs_mask
)
2426 struct vfpf_vport_update_sge_tpa_tlv
*p_sge_tpa_tlv
;
2427 u16 tlv
= CHANNEL_TLV_VPORT_UPDATE_SGE_TPA
;
2429 p_sge_tpa_tlv
= (struct vfpf_vport_update_sge_tpa_tlv
*)
2430 qed_iov_search_list_tlvs(p_hwfn
, p_mbx
->req_virt
, tlv
);
2432 if (!p_sge_tpa_tlv
) {
2433 p_data
->sge_tpa_params
= NULL
;
2437 memset(p_sge_tpa
, 0, sizeof(struct qed_sge_tpa_params
));
2439 p_sge_tpa
->update_tpa_en_flg
=
2440 !!(p_sge_tpa_tlv
->update_sge_tpa_flags
& VFPF_UPDATE_TPA_EN_FLAG
);
2441 p_sge_tpa
->update_tpa_param_flg
=
2442 !!(p_sge_tpa_tlv
->update_sge_tpa_flags
&
2443 VFPF_UPDATE_TPA_PARAM_FLAG
);
2445 p_sge_tpa
->tpa_ipv4_en_flg
=
2446 !!(p_sge_tpa_tlv
->sge_tpa_flags
& VFPF_TPA_IPV4_EN_FLAG
);
2447 p_sge_tpa
->tpa_ipv6_en_flg
=
2448 !!(p_sge_tpa_tlv
->sge_tpa_flags
& VFPF_TPA_IPV6_EN_FLAG
);
2449 p_sge_tpa
->tpa_pkt_split_flg
=
2450 !!(p_sge_tpa_tlv
->sge_tpa_flags
& VFPF_TPA_PKT_SPLIT_FLAG
);
2451 p_sge_tpa
->tpa_hdr_data_split_flg
=
2452 !!(p_sge_tpa_tlv
->sge_tpa_flags
& VFPF_TPA_HDR_DATA_SPLIT_FLAG
);
2453 p_sge_tpa
->tpa_gro_consistent_flg
=
2454 !!(p_sge_tpa_tlv
->sge_tpa_flags
& VFPF_TPA_GRO_CONSIST_FLAG
);
2456 p_sge_tpa
->tpa_max_aggs_num
= p_sge_tpa_tlv
->tpa_max_aggs_num
;
2457 p_sge_tpa
->tpa_max_size
= p_sge_tpa_tlv
->tpa_max_size
;
2458 p_sge_tpa
->tpa_min_size_to_start
= p_sge_tpa_tlv
->tpa_min_size_to_start
;
2459 p_sge_tpa
->tpa_min_size_to_cont
= p_sge_tpa_tlv
->tpa_min_size_to_cont
;
2460 p_sge_tpa
->max_buffers_per_cqe
= p_sge_tpa_tlv
->max_buffers_per_cqe
;
2462 p_data
->sge_tpa_params
= p_sge_tpa
;
2464 *tlvs_mask
|= 1 << QED_IOV_VP_UPDATE_SGE_TPA
;
2467 static int qed_iov_pre_update_vport(struct qed_hwfn
*hwfn
,
2469 struct qed_sp_vport_update_params
*params
,
2472 u8 mask
= QED_ACCEPT_UCAST_UNMATCHED
| QED_ACCEPT_MCAST_UNMATCHED
;
2473 struct qed_filter_accept_flags
*flags
= ¶ms
->accept_flags
;
2474 struct qed_public_vf_info
*vf_info
;
2476 /* Untrusted VFs can't even be trusted to know that fact.
2477 * Simply indicate everything is configured fine, and trace
2478 * configuration 'behind their back'.
2480 if (!(*tlvs
& BIT(QED_IOV_VP_UPDATE_ACCEPT_PARAM
)))
2483 vf_info
= qed_iov_get_public_vf_info(hwfn
, vfid
, true);
2485 if (flags
->update_rx_mode_config
) {
2486 vf_info
->rx_accept_mode
= flags
->rx_accept_filter
;
2487 if (!vf_info
->is_trusted_configured
)
2488 flags
->rx_accept_filter
&= ~mask
;
2491 if (flags
->update_tx_mode_config
) {
2492 vf_info
->tx_accept_mode
= flags
->tx_accept_filter
;
2493 if (!vf_info
->is_trusted_configured
)
2494 flags
->tx_accept_filter
&= ~mask
;
2500 static void qed_iov_vf_mbx_vport_update(struct qed_hwfn
*p_hwfn
,
2501 struct qed_ptt
*p_ptt
,
2502 struct qed_vf_info
*vf
)
2504 struct qed_rss_params
*p_rss_params
= NULL
;
2505 struct qed_sp_vport_update_params params
;
2506 struct qed_iov_vf_mbx
*mbx
= &vf
->vf_mbx
;
2507 struct qed_sge_tpa_params sge_tpa_params
;
2508 u16 tlvs_mask
= 0, tlvs_accepted
= 0;
2509 u8 status
= PFVF_STATUS_SUCCESS
;
2513 /* Valiate PF can send such a request */
2514 if (!vf
->vport_instance
) {
2517 "No VPORT instance available for VF[%d], failing vport update\n",
2519 status
= PFVF_STATUS_FAILURE
;
2522 p_rss_params
= vzalloc(sizeof(*p_rss_params
));
2523 if (p_rss_params
== NULL
) {
2524 status
= PFVF_STATUS_FAILURE
;
2528 memset(¶ms
, 0, sizeof(params
));
2529 params
.opaque_fid
= vf
->opaque_fid
;
2530 params
.vport_id
= vf
->vport_id
;
2531 params
.rss_params
= NULL
;
2533 /* Search for extended tlvs list and update values
2534 * from VF in struct qed_sp_vport_update_params.
2536 qed_iov_vp_update_act_param(p_hwfn
, ¶ms
, mbx
, &tlvs_mask
);
2537 qed_iov_vp_update_vlan_param(p_hwfn
, ¶ms
, vf
, mbx
, &tlvs_mask
);
2538 qed_iov_vp_update_tx_switch(p_hwfn
, ¶ms
, mbx
, &tlvs_mask
);
2539 qed_iov_vp_update_mcast_bin_param(p_hwfn
, ¶ms
, mbx
, &tlvs_mask
);
2540 qed_iov_vp_update_accept_flag(p_hwfn
, ¶ms
, mbx
, &tlvs_mask
);
2541 qed_iov_vp_update_accept_any_vlan(p_hwfn
, ¶ms
, mbx
, &tlvs_mask
);
2542 qed_iov_vp_update_sge_tpa_param(p_hwfn
, vf
, ¶ms
,
2543 &sge_tpa_params
, mbx
, &tlvs_mask
);
2545 tlvs_accepted
= tlvs_mask
;
2547 /* Some of the extended TLVs need to be validated first; In that case,
2548 * they can update the mask without updating the accepted [so that
2549 * PF could communicate to VF it has rejected request].
2551 qed_iov_vp_update_rss_param(p_hwfn
, vf
, ¶ms
, p_rss_params
,
2552 mbx
, &tlvs_mask
, &tlvs_accepted
);
2554 if (qed_iov_pre_update_vport(p_hwfn
, vf
->relative_vf_id
,
2555 ¶ms
, &tlvs_accepted
)) {
2557 status
= PFVF_STATUS_NOT_SUPPORTED
;
2561 if (!tlvs_accepted
) {
2563 DP_VERBOSE(p_hwfn
, QED_MSG_IOV
,
2564 "Upper-layer prevents VF vport configuration\n");
2566 DP_VERBOSE(p_hwfn
, QED_MSG_IOV
,
2567 "No feature tlvs found for vport update\n");
2568 status
= PFVF_STATUS_NOT_SUPPORTED
;
2572 rc
= qed_sp_vport_update(p_hwfn
, ¶ms
, QED_SPQ_MODE_EBLOCK
, NULL
);
2575 status
= PFVF_STATUS_FAILURE
;
2578 vfree(p_rss_params
);
2579 length
= qed_iov_prep_vp_update_resp_tlvs(p_hwfn
, vf
, mbx
, status
,
2580 tlvs_mask
, tlvs_accepted
);
2581 qed_iov_send_response(p_hwfn
, p_ptt
, vf
, length
, status
);
2584 static int qed_iov_vf_update_vlan_shadow(struct qed_hwfn
*p_hwfn
,
2585 struct qed_vf_info
*p_vf
,
2586 struct qed_filter_ucast
*p_params
)
2590 /* First remove entries and then add new ones */
2591 if (p_params
->opcode
== QED_FILTER_REMOVE
) {
2592 for (i
= 0; i
< QED_ETH_VF_NUM_VLAN_FILTERS
+ 1; i
++)
2593 if (p_vf
->shadow_config
.vlans
[i
].used
&&
2594 p_vf
->shadow_config
.vlans
[i
].vid
==
2596 p_vf
->shadow_config
.vlans
[i
].used
= false;
2599 if (i
== QED_ETH_VF_NUM_VLAN_FILTERS
+ 1) {
2602 "VF [%d] - Tries to remove a non-existing vlan\n",
2603 p_vf
->relative_vf_id
);
2606 } else if (p_params
->opcode
== QED_FILTER_REPLACE
||
2607 p_params
->opcode
== QED_FILTER_FLUSH
) {
2608 for (i
= 0; i
< QED_ETH_VF_NUM_VLAN_FILTERS
+ 1; i
++)
2609 p_vf
->shadow_config
.vlans
[i
].used
= false;
2612 /* In forced mode, we're willing to remove entries - but we don't add
2615 if (p_vf
->bulletin
.p_virt
->valid_bitmap
& BIT(VLAN_ADDR_FORCED
))
2618 if (p_params
->opcode
== QED_FILTER_ADD
||
2619 p_params
->opcode
== QED_FILTER_REPLACE
) {
2620 for (i
= 0; i
< QED_ETH_VF_NUM_VLAN_FILTERS
+ 1; i
++) {
2621 if (p_vf
->shadow_config
.vlans
[i
].used
)
2624 p_vf
->shadow_config
.vlans
[i
].used
= true;
2625 p_vf
->shadow_config
.vlans
[i
].vid
= p_params
->vlan
;
2629 if (i
== QED_ETH_VF_NUM_VLAN_FILTERS
+ 1) {
2632 "VF [%d] - Tries to configure more than %d vlan filters\n",
2633 p_vf
->relative_vf_id
,
2634 QED_ETH_VF_NUM_VLAN_FILTERS
+ 1);
2642 static int qed_iov_vf_update_mac_shadow(struct qed_hwfn
*p_hwfn
,
2643 struct qed_vf_info
*p_vf
,
2644 struct qed_filter_ucast
*p_params
)
2648 /* If we're in forced-mode, we don't allow any change */
2649 if (p_vf
->bulletin
.p_virt
->valid_bitmap
& BIT(MAC_ADDR_FORCED
))
2652 /* First remove entries and then add new ones */
2653 if (p_params
->opcode
== QED_FILTER_REMOVE
) {
2654 for (i
= 0; i
< QED_ETH_VF_NUM_MAC_FILTERS
; i
++) {
2655 if (ether_addr_equal(p_vf
->shadow_config
.macs
[i
],
2657 eth_zero_addr(p_vf
->shadow_config
.macs
[i
]);
2662 if (i
== QED_ETH_VF_NUM_MAC_FILTERS
) {
2663 DP_VERBOSE(p_hwfn
, QED_MSG_IOV
,
2664 "MAC isn't configured\n");
2667 } else if (p_params
->opcode
== QED_FILTER_REPLACE
||
2668 p_params
->opcode
== QED_FILTER_FLUSH
) {
2669 for (i
= 0; i
< QED_ETH_VF_NUM_MAC_FILTERS
; i
++)
2670 eth_zero_addr(p_vf
->shadow_config
.macs
[i
]);
2673 /* List the new MAC address */
2674 if (p_params
->opcode
!= QED_FILTER_ADD
&&
2675 p_params
->opcode
!= QED_FILTER_REPLACE
)
2678 for (i
= 0; i
< QED_ETH_VF_NUM_MAC_FILTERS
; i
++) {
2679 if (is_zero_ether_addr(p_vf
->shadow_config
.macs
[i
])) {
2680 ether_addr_copy(p_vf
->shadow_config
.macs
[i
],
2682 DP_VERBOSE(p_hwfn
, QED_MSG_IOV
,
2683 "Added MAC at %d entry in shadow\n", i
);
2688 if (i
== QED_ETH_VF_NUM_MAC_FILTERS
) {
2689 DP_VERBOSE(p_hwfn
, QED_MSG_IOV
, "No available place for MAC\n");
2697 qed_iov_vf_update_unicast_shadow(struct qed_hwfn
*p_hwfn
,
2698 struct qed_vf_info
*p_vf
,
2699 struct qed_filter_ucast
*p_params
)
2703 if (p_params
->type
== QED_FILTER_MAC
) {
2704 rc
= qed_iov_vf_update_mac_shadow(p_hwfn
, p_vf
, p_params
);
2709 if (p_params
->type
== QED_FILTER_VLAN
)
2710 rc
= qed_iov_vf_update_vlan_shadow(p_hwfn
, p_vf
, p_params
);
2715 static int qed_iov_chk_ucast(struct qed_hwfn
*hwfn
,
2716 int vfid
, struct qed_filter_ucast
*params
)
2718 struct qed_public_vf_info
*vf
;
2720 vf
= qed_iov_get_public_vf_info(hwfn
, vfid
, true);
2724 /* No real decision to make; Store the configured MAC */
2725 if (params
->type
== QED_FILTER_MAC
||
2726 params
->type
== QED_FILTER_MAC_VLAN
)
2727 ether_addr_copy(vf
->mac
, params
->mac
);
2732 static void qed_iov_vf_mbx_ucast_filter(struct qed_hwfn
*p_hwfn
,
2733 struct qed_ptt
*p_ptt
,
2734 struct qed_vf_info
*vf
)
2736 struct qed_bulletin_content
*p_bulletin
= vf
->bulletin
.p_virt
;
2737 struct qed_iov_vf_mbx
*mbx
= &vf
->vf_mbx
;
2738 struct vfpf_ucast_filter_tlv
*req
;
2739 u8 status
= PFVF_STATUS_SUCCESS
;
2740 struct qed_filter_ucast params
;
2743 /* Prepare the unicast filter params */
2744 memset(¶ms
, 0, sizeof(struct qed_filter_ucast
));
2745 req
= &mbx
->req_virt
->ucast_filter
;
2746 params
.opcode
= (enum qed_filter_opcode
)req
->opcode
;
2747 params
.type
= (enum qed_filter_ucast_type
)req
->type
;
2749 params
.is_rx_filter
= 1;
2750 params
.is_tx_filter
= 1;
2751 params
.vport_to_remove_from
= vf
->vport_id
;
2752 params
.vport_to_add_to
= vf
->vport_id
;
2753 memcpy(params
.mac
, req
->mac
, ETH_ALEN
);
2754 params
.vlan
= req
->vlan
;
2758 "VF[%d]: opcode 0x%02x type 0x%02x [%s %s] [vport 0x%02x] MAC %02x:%02x:%02x:%02x:%02x:%02x, vlan 0x%04x\n",
2759 vf
->abs_vf_id
, params
.opcode
, params
.type
,
2760 params
.is_rx_filter
? "RX" : "",
2761 params
.is_tx_filter
? "TX" : "",
2762 params
.vport_to_add_to
,
2763 params
.mac
[0], params
.mac
[1],
2764 params
.mac
[2], params
.mac
[3],
2765 params
.mac
[4], params
.mac
[5], params
.vlan
);
2767 if (!vf
->vport_instance
) {
2770 "No VPORT instance available for VF[%d], failing ucast MAC configuration\n",
2772 status
= PFVF_STATUS_FAILURE
;
2776 /* Update shadow copy of the VF configuration */
2777 if (qed_iov_vf_update_unicast_shadow(p_hwfn
, vf
, ¶ms
)) {
2778 status
= PFVF_STATUS_FAILURE
;
2782 /* Determine if the unicast filtering is acceptible by PF */
2783 if ((p_bulletin
->valid_bitmap
& BIT(VLAN_ADDR_FORCED
)) &&
2784 (params
.type
== QED_FILTER_VLAN
||
2785 params
.type
== QED_FILTER_MAC_VLAN
)) {
2786 /* Once VLAN is forced or PVID is set, do not allow
2787 * to add/replace any further VLANs.
2789 if (params
.opcode
== QED_FILTER_ADD
||
2790 params
.opcode
== QED_FILTER_REPLACE
)
2791 status
= PFVF_STATUS_FORCED
;
2795 if ((p_bulletin
->valid_bitmap
& BIT(MAC_ADDR_FORCED
)) &&
2796 (params
.type
== QED_FILTER_MAC
||
2797 params
.type
== QED_FILTER_MAC_VLAN
)) {
2798 if (!ether_addr_equal(p_bulletin
->mac
, params
.mac
) ||
2799 (params
.opcode
!= QED_FILTER_ADD
&&
2800 params
.opcode
!= QED_FILTER_REPLACE
))
2801 status
= PFVF_STATUS_FORCED
;
2805 rc
= qed_iov_chk_ucast(p_hwfn
, vf
->relative_vf_id
, ¶ms
);
2807 status
= PFVF_STATUS_FAILURE
;
2811 rc
= qed_sp_eth_filter_ucast(p_hwfn
, vf
->opaque_fid
, ¶ms
,
2812 QED_SPQ_MODE_CB
, NULL
);
2814 status
= PFVF_STATUS_FAILURE
;
2817 qed_iov_prepare_resp(p_hwfn
, p_ptt
, vf
, CHANNEL_TLV_UCAST_FILTER
,
2818 sizeof(struct pfvf_def_resp_tlv
), status
);
2821 static void qed_iov_vf_mbx_int_cleanup(struct qed_hwfn
*p_hwfn
,
2822 struct qed_ptt
*p_ptt
,
2823 struct qed_vf_info
*vf
)
2828 for (i
= 0; i
< vf
->num_sbs
; i
++)
2829 qed_int_igu_init_pure_rt_single(p_hwfn
, p_ptt
,
2831 vf
->opaque_fid
, false);
2833 qed_iov_prepare_resp(p_hwfn
, p_ptt
, vf
, CHANNEL_TLV_INT_CLEANUP
,
2834 sizeof(struct pfvf_def_resp_tlv
),
2835 PFVF_STATUS_SUCCESS
);
2838 static void qed_iov_vf_mbx_close(struct qed_hwfn
*p_hwfn
,
2839 struct qed_ptt
*p_ptt
, struct qed_vf_info
*vf
)
2841 u16 length
= sizeof(struct pfvf_def_resp_tlv
);
2842 u8 status
= PFVF_STATUS_SUCCESS
;
2844 /* Disable Interrupts for VF */
2845 qed_iov_vf_igu_set_int(p_hwfn
, p_ptt
, vf
, 0);
2847 /* Reset Permission table */
2848 qed_iov_config_perm_table(p_hwfn
, p_ptt
, vf
, 0);
2850 qed_iov_prepare_resp(p_hwfn
, p_ptt
, vf
, CHANNEL_TLV_CLOSE
,
2854 static void qed_iov_vf_mbx_release(struct qed_hwfn
*p_hwfn
,
2855 struct qed_ptt
*p_ptt
,
2856 struct qed_vf_info
*p_vf
)
2858 u16 length
= sizeof(struct pfvf_def_resp_tlv
);
2859 u8 status
= PFVF_STATUS_SUCCESS
;
2862 qed_iov_vf_cleanup(p_hwfn
, p_vf
);
2864 if (p_vf
->state
!= VF_STOPPED
&& p_vf
->state
!= VF_FREE
) {
2865 /* Stopping the VF */
2866 rc
= qed_sp_vf_stop(p_hwfn
, p_vf
->concrete_fid
,
2870 DP_ERR(p_hwfn
, "qed_sp_vf_stop returned error %d\n",
2872 status
= PFVF_STATUS_FAILURE
;
2875 p_vf
->state
= VF_STOPPED
;
2878 qed_iov_prepare_resp(p_hwfn
, p_ptt
, p_vf
, CHANNEL_TLV_RELEASE
,
2883 qed_iov_vf_flr_poll_dorq(struct qed_hwfn
*p_hwfn
,
2884 struct qed_vf_info
*p_vf
, struct qed_ptt
*p_ptt
)
2889 qed_fid_pretend(p_hwfn
, p_ptt
, (u16
) p_vf
->concrete_fid
);
2891 for (cnt
= 0; cnt
< 50; cnt
++) {
2892 val
= qed_rd(p_hwfn
, p_ptt
, DORQ_REG_VF_USAGE_CNT
);
2897 qed_fid_pretend(p_hwfn
, p_ptt
, (u16
) p_hwfn
->hw_info
.concrete_fid
);
2901 "VF[%d] - dorq failed to cleanup [usage 0x%08x]\n",
2902 p_vf
->abs_vf_id
, val
);
2910 qed_iov_vf_flr_poll_pbf(struct qed_hwfn
*p_hwfn
,
2911 struct qed_vf_info
*p_vf
, struct qed_ptt
*p_ptt
)
2913 u32 cons
[MAX_NUM_VOQS
], distance
[MAX_NUM_VOQS
];
2916 /* Read initial consumers & producers */
2917 for (i
= 0; i
< MAX_NUM_VOQS
; i
++) {
2920 cons
[i
] = qed_rd(p_hwfn
, p_ptt
,
2921 PBF_REG_NUM_BLOCKS_ALLOCATED_CONS_VOQ0
+
2923 prod
= qed_rd(p_hwfn
, p_ptt
,
2924 PBF_REG_NUM_BLOCKS_ALLOCATED_PROD_VOQ0
+
2926 distance
[i
] = prod
- cons
[i
];
2929 /* Wait for consumers to pass the producers */
2931 for (cnt
= 0; cnt
< 50; cnt
++) {
2932 for (; i
< MAX_NUM_VOQS
; i
++) {
2935 tmp
= qed_rd(p_hwfn
, p_ptt
,
2936 PBF_REG_NUM_BLOCKS_ALLOCATED_CONS_VOQ0
+
2938 if (distance
[i
] > tmp
- cons
[i
])
2942 if (i
== MAX_NUM_VOQS
)
2949 DP_ERR(p_hwfn
, "VF[%d] - pbf polling failed on VOQ %d\n",
2950 p_vf
->abs_vf_id
, i
);
2957 static int qed_iov_vf_flr_poll(struct qed_hwfn
*p_hwfn
,
2958 struct qed_vf_info
*p_vf
, struct qed_ptt
*p_ptt
)
2962 rc
= qed_iov_vf_flr_poll_dorq(p_hwfn
, p_vf
, p_ptt
);
2966 rc
= qed_iov_vf_flr_poll_pbf(p_hwfn
, p_vf
, p_ptt
);
2974 qed_iov_execute_vf_flr_cleanup(struct qed_hwfn
*p_hwfn
,
2975 struct qed_ptt
*p_ptt
,
2976 u16 rel_vf_id
, u32
*ack_vfs
)
2978 struct qed_vf_info
*p_vf
;
2981 p_vf
= qed_iov_get_vf_info(p_hwfn
, rel_vf_id
, false);
2985 if (p_hwfn
->pf_iov_info
->pending_flr
[rel_vf_id
/ 64] &
2986 (1ULL << (rel_vf_id
% 64))) {
2987 u16 vfid
= p_vf
->abs_vf_id
;
2989 DP_VERBOSE(p_hwfn
, QED_MSG_IOV
,
2990 "VF[%d] - Handling FLR\n", vfid
);
2992 qed_iov_vf_cleanup(p_hwfn
, p_vf
);
2994 /* If VF isn't active, no need for anything but SW */
2998 rc
= qed_iov_vf_flr_poll(p_hwfn
, p_vf
, p_ptt
);
3002 rc
= qed_final_cleanup(p_hwfn
, p_ptt
, vfid
, true);
3004 DP_ERR(p_hwfn
, "Failed handle FLR of VF[%d]\n", vfid
);
3008 /* Workaround to make VF-PF channel ready, as FW
3009 * doesn't do that as a part of FLR.
3012 GTT_BAR0_MAP_REG_USDM_RAM
+
3013 USTORM_VF_PF_CHANNEL_READY_OFFSET(vfid
), 1);
3015 /* VF_STOPPED has to be set only after final cleanup
3016 * but prior to re-enabling the VF.
3018 p_vf
->state
= VF_STOPPED
;
3020 rc
= qed_iov_enable_vf_access(p_hwfn
, p_ptt
, p_vf
);
3022 DP_ERR(p_hwfn
, "Failed to re-enable VF[%d] acces\n",
3027 /* Mark VF for ack and clean pending state */
3028 if (p_vf
->state
== VF_RESET
)
3029 p_vf
->state
= VF_STOPPED
;
3030 ack_vfs
[vfid
/ 32] |= BIT((vfid
% 32));
3031 p_hwfn
->pf_iov_info
->pending_flr
[rel_vf_id
/ 64] &=
3032 ~(1ULL << (rel_vf_id
% 64));
3033 p_vf
->vf_mbx
.b_pending_msg
= false;
3040 qed_iov_vf_flr_cleanup(struct qed_hwfn
*p_hwfn
, struct qed_ptt
*p_ptt
)
3042 u32 ack_vfs
[VF_MAX_STATIC
/ 32];
3046 memset(ack_vfs
, 0, sizeof(u32
) * (VF_MAX_STATIC
/ 32));
3048 /* Since BRB <-> PRS interface can't be tested as part of the flr
3049 * polling due to HW limitations, simply sleep a bit. And since
3050 * there's no need to wait per-vf, do it before looping.
3054 for (i
= 0; i
< p_hwfn
->cdev
->p_iov_info
->total_vfs
; i
++)
3055 qed_iov_execute_vf_flr_cleanup(p_hwfn
, p_ptt
, i
, ack_vfs
);
3057 rc
= qed_mcp_ack_vf_flr(p_hwfn
, p_ptt
, ack_vfs
);
3061 int qed_iov_mark_vf_flr(struct qed_hwfn
*p_hwfn
, u32
*p_disabled_vfs
)
3065 DP_VERBOSE(p_hwfn
, QED_MSG_IOV
, "Marking FLR-ed VFs\n");
3066 for (i
= 0; i
< (VF_MAX_STATIC
/ 32); i
++)
3067 DP_VERBOSE(p_hwfn
, QED_MSG_IOV
,
3068 "[%08x,...,%08x]: %08x\n",
3069 i
* 32, (i
+ 1) * 32 - 1, p_disabled_vfs
[i
]);
3071 if (!p_hwfn
->cdev
->p_iov_info
) {
3072 DP_NOTICE(p_hwfn
, "VF flr but no IOV\n");
3077 for (i
= 0; i
< p_hwfn
->cdev
->p_iov_info
->total_vfs
; i
++) {
3078 struct qed_vf_info
*p_vf
;
3081 p_vf
= qed_iov_get_vf_info(p_hwfn
, i
, false);
3085 vfid
= p_vf
->abs_vf_id
;
3086 if (BIT((vfid
% 32)) & p_disabled_vfs
[vfid
/ 32]) {
3087 u64
*p_flr
= p_hwfn
->pf_iov_info
->pending_flr
;
3088 u16 rel_vf_id
= p_vf
->relative_vf_id
;
3090 DP_VERBOSE(p_hwfn
, QED_MSG_IOV
,
3091 "VF[%d] [rel %d] got FLR-ed\n",
3094 p_vf
->state
= VF_RESET
;
3096 /* No need to lock here, since pending_flr should
3097 * only change here and before ACKing MFw. Since
3098 * MFW will not trigger an additional attention for
3099 * VF flr until ACKs, we're safe.
3101 p_flr
[rel_vf_id
/ 64] |= 1ULL << (rel_vf_id
% 64);
3109 static void qed_iov_get_link(struct qed_hwfn
*p_hwfn
,
3111 struct qed_mcp_link_params
*p_params
,
3112 struct qed_mcp_link_state
*p_link
,
3113 struct qed_mcp_link_capabilities
*p_caps
)
3115 struct qed_vf_info
*p_vf
= qed_iov_get_vf_info(p_hwfn
,
3118 struct qed_bulletin_content
*p_bulletin
;
3123 p_bulletin
= p_vf
->bulletin
.p_virt
;
3126 __qed_vf_get_link_params(p_hwfn
, p_params
, p_bulletin
);
3128 __qed_vf_get_link_state(p_hwfn
, p_link
, p_bulletin
);
3130 __qed_vf_get_link_caps(p_hwfn
, p_caps
, p_bulletin
);
3133 static void qed_iov_process_mbx_req(struct qed_hwfn
*p_hwfn
,
3134 struct qed_ptt
*p_ptt
, int vfid
)
3136 struct qed_iov_vf_mbx
*mbx
;
3137 struct qed_vf_info
*p_vf
;
3139 p_vf
= qed_iov_get_vf_info(p_hwfn
, (u16
) vfid
, true);
3143 mbx
= &p_vf
->vf_mbx
;
3145 /* qed_iov_process_mbx_request */
3146 if (!mbx
->b_pending_msg
) {
3148 "VF[%02x]: Trying to process mailbox message when none is pending\n",
3152 mbx
->b_pending_msg
= false;
3154 mbx
->first_tlv
= mbx
->req_virt
->first_tlv
;
3156 DP_VERBOSE(p_hwfn
, QED_MSG_IOV
,
3157 "VF[%02x]: Processing mailbox message [type %04x]\n",
3158 p_vf
->abs_vf_id
, mbx
->first_tlv
.tl
.type
);
3160 /* check if tlv type is known */
3161 if (qed_iov_tlv_supported(mbx
->first_tlv
.tl
.type
) &&
3162 !p_vf
->b_malicious
) {
3163 switch (mbx
->first_tlv
.tl
.type
) {
3164 case CHANNEL_TLV_ACQUIRE
:
3165 qed_iov_vf_mbx_acquire(p_hwfn
, p_ptt
, p_vf
);
3167 case CHANNEL_TLV_VPORT_START
:
3168 qed_iov_vf_mbx_start_vport(p_hwfn
, p_ptt
, p_vf
);
3170 case CHANNEL_TLV_VPORT_TEARDOWN
:
3171 qed_iov_vf_mbx_stop_vport(p_hwfn
, p_ptt
, p_vf
);
3173 case CHANNEL_TLV_START_RXQ
:
3174 qed_iov_vf_mbx_start_rxq(p_hwfn
, p_ptt
, p_vf
);
3176 case CHANNEL_TLV_START_TXQ
:
3177 qed_iov_vf_mbx_start_txq(p_hwfn
, p_ptt
, p_vf
);
3179 case CHANNEL_TLV_STOP_RXQS
:
3180 qed_iov_vf_mbx_stop_rxqs(p_hwfn
, p_ptt
, p_vf
);
3182 case CHANNEL_TLV_STOP_TXQS
:
3183 qed_iov_vf_mbx_stop_txqs(p_hwfn
, p_ptt
, p_vf
);
3185 case CHANNEL_TLV_UPDATE_RXQ
:
3186 qed_iov_vf_mbx_update_rxqs(p_hwfn
, p_ptt
, p_vf
);
3188 case CHANNEL_TLV_VPORT_UPDATE
:
3189 qed_iov_vf_mbx_vport_update(p_hwfn
, p_ptt
, p_vf
);
3191 case CHANNEL_TLV_UCAST_FILTER
:
3192 qed_iov_vf_mbx_ucast_filter(p_hwfn
, p_ptt
, p_vf
);
3194 case CHANNEL_TLV_CLOSE
:
3195 qed_iov_vf_mbx_close(p_hwfn
, p_ptt
, p_vf
);
3197 case CHANNEL_TLV_INT_CLEANUP
:
3198 qed_iov_vf_mbx_int_cleanup(p_hwfn
, p_ptt
, p_vf
);
3200 case CHANNEL_TLV_RELEASE
:
3201 qed_iov_vf_mbx_release(p_hwfn
, p_ptt
, p_vf
);
3204 } else if (qed_iov_tlv_supported(mbx
->first_tlv
.tl
.type
)) {
3205 DP_VERBOSE(p_hwfn
, QED_MSG_IOV
,
3206 "VF [%02x] - considered malicious; Ignoring TLV [%04x]\n",
3207 p_vf
->abs_vf_id
, mbx
->first_tlv
.tl
.type
);
3209 qed_iov_prepare_resp(p_hwfn
, p_ptt
, p_vf
,
3210 mbx
->first_tlv
.tl
.type
,
3211 sizeof(struct pfvf_def_resp_tlv
),
3212 PFVF_STATUS_MALICIOUS
);
3214 /* unknown TLV - this may belong to a VF driver from the future
3215 * - a version written after this PF driver was written, which
3216 * supports features unknown as of yet. Too bad since we don't
3217 * support them. Or this may be because someone wrote a crappy
3218 * VF driver and is sending garbage over the channel.
3221 "VF[%02x]: unknown TLV. type %04x length %04x padding %08x reply address %llu\n",
3223 mbx
->first_tlv
.tl
.type
,
3224 mbx
->first_tlv
.tl
.length
,
3225 mbx
->first_tlv
.padding
, mbx
->first_tlv
.reply_address
);
3227 /* Try replying in case reply address matches the acquisition's
3230 if (p_vf
->acquire
.first_tlv
.reply_address
&&
3231 (mbx
->first_tlv
.reply_address
==
3232 p_vf
->acquire
.first_tlv
.reply_address
)) {
3233 qed_iov_prepare_resp(p_hwfn
, p_ptt
, p_vf
,
3234 mbx
->first_tlv
.tl
.type
,
3235 sizeof(struct pfvf_def_resp_tlv
),
3236 PFVF_STATUS_NOT_SUPPORTED
);
3240 "VF[%02x]: Can't respond to TLV - no valid reply address\n",
3246 void qed_iov_pf_get_pending_events(struct qed_hwfn
*p_hwfn
, u64
*events
)
3250 memset(events
, 0, sizeof(u64
) * QED_VF_ARRAY_LENGTH
);
3252 qed_for_each_vf(p_hwfn
, i
) {
3253 struct qed_vf_info
*p_vf
;
3255 p_vf
= &p_hwfn
->pf_iov_info
->vfs_array
[i
];
3256 if (p_vf
->vf_mbx
.b_pending_msg
)
3257 events
[i
/ 64] |= 1ULL << (i
% 64);
3261 static struct qed_vf_info
*qed_sriov_get_vf_from_absid(struct qed_hwfn
*p_hwfn
,
3264 u8 min
= (u8
) p_hwfn
->cdev
->p_iov_info
->first_vf_in_pf
;
3266 if (!_qed_iov_pf_sanity_check(p_hwfn
, (int)abs_vfid
- min
, false)) {
3269 "Got indication for VF [abs 0x%08x] that cannot be handled by PF\n",
3274 return &p_hwfn
->pf_iov_info
->vfs_array
[(u8
) abs_vfid
- min
];
3277 static int qed_sriov_vfpf_msg(struct qed_hwfn
*p_hwfn
,
3278 u16 abs_vfid
, struct regpair
*vf_msg
)
3280 struct qed_vf_info
*p_vf
= qed_sriov_get_vf_from_absid(p_hwfn
,
3286 /* List the physical address of the request so that handler
3287 * could later on copy the message from it.
3289 p_vf
->vf_mbx
.pending_req
= (((u64
)vf_msg
->hi
) << 32) | vf_msg
->lo
;
3291 /* Mark the event and schedule the workqueue */
3292 p_vf
->vf_mbx
.b_pending_msg
= true;
3293 qed_schedule_iov(p_hwfn
, QED_IOV_WQ_MSG_FLAG
);
3298 static void qed_sriov_vfpf_malicious(struct qed_hwfn
*p_hwfn
,
3299 struct malicious_vf_eqe_data
*p_data
)
3301 struct qed_vf_info
*p_vf
;
3303 p_vf
= qed_sriov_get_vf_from_absid(p_hwfn
, p_data
->vf_id
);
3309 "VF [%d] - Malicious behavior [%02x]\n",
3310 p_vf
->abs_vf_id
, p_data
->err_id
);
3312 p_vf
->b_malicious
= true;
3315 int qed_sriov_eqe_event(struct qed_hwfn
*p_hwfn
,
3316 u8 opcode
, __le16 echo
, union event_ring_data
*data
)
3319 case COMMON_EVENT_VF_PF_CHANNEL
:
3320 return qed_sriov_vfpf_msg(p_hwfn
, le16_to_cpu(echo
),
3321 &data
->vf_pf_channel
.msg_addr
);
3322 case COMMON_EVENT_MALICIOUS_VF
:
3323 qed_sriov_vfpf_malicious(p_hwfn
, &data
->malicious_vf
);
3326 DP_INFO(p_hwfn
->cdev
, "Unknown sriov eqe event 0x%02x\n",
3332 u16
qed_iov_get_next_active_vf(struct qed_hwfn
*p_hwfn
, u16 rel_vf_id
)
3334 struct qed_hw_sriov_info
*p_iov
= p_hwfn
->cdev
->p_iov_info
;
3340 for (i
= rel_vf_id
; i
< p_iov
->total_vfs
; i
++)
3341 if (qed_iov_is_valid_vfid(p_hwfn
, rel_vf_id
, true, false))
3348 static int qed_iov_copy_vf_msg(struct qed_hwfn
*p_hwfn
, struct qed_ptt
*ptt
,
3351 struct qed_dmae_params params
;
3352 struct qed_vf_info
*vf_info
;
3354 vf_info
= qed_iov_get_vf_info(p_hwfn
, (u16
) vfid
, true);
3358 memset(¶ms
, 0, sizeof(struct qed_dmae_params
));
3359 params
.flags
= QED_DMAE_FLAG_VF_SRC
| QED_DMAE_FLAG_COMPLETION_DST
;
3360 params
.src_vfid
= vf_info
->abs_vf_id
;
3362 if (qed_dmae_host2host(p_hwfn
, ptt
,
3363 vf_info
->vf_mbx
.pending_req
,
3364 vf_info
->vf_mbx
.req_phys
,
3365 sizeof(union vfpf_tlvs
) / 4, ¶ms
)) {
3366 DP_VERBOSE(p_hwfn
, QED_MSG_IOV
,
3367 "Failed to copy message from VF 0x%02x\n", vfid
);
3375 static void qed_iov_bulletin_set_forced_mac(struct qed_hwfn
*p_hwfn
,
3378 struct qed_vf_info
*vf_info
;
3381 vf_info
= qed_iov_get_vf_info(p_hwfn
, (u16
)vfid
, true);
3383 DP_NOTICE(p_hwfn
->cdev
,
3384 "Can not set forced MAC, invalid vfid [%d]\n", vfid
);
3388 if (vf_info
->b_malicious
) {
3389 DP_NOTICE(p_hwfn
->cdev
,
3390 "Can't set forced MAC to malicious VF [%d]\n", vfid
);
3394 feature
= 1 << MAC_ADDR_FORCED
;
3395 memcpy(vf_info
->bulletin
.p_virt
->mac
, mac
, ETH_ALEN
);
3397 vf_info
->bulletin
.p_virt
->valid_bitmap
|= feature
;
3398 /* Forced MAC will disable MAC_ADDR */
3399 vf_info
->bulletin
.p_virt
->valid_bitmap
&= ~BIT(VFPF_BULLETIN_MAC_ADDR
);
3401 qed_iov_configure_vport_forced(p_hwfn
, vf_info
, feature
);
3404 static void qed_iov_bulletin_set_forced_vlan(struct qed_hwfn
*p_hwfn
,
3407 struct qed_vf_info
*vf_info
;
3410 vf_info
= qed_iov_get_vf_info(p_hwfn
, (u16
) vfid
, true);
3412 DP_NOTICE(p_hwfn
->cdev
,
3413 "Can not set forced MAC, invalid vfid [%d]\n", vfid
);
3417 if (vf_info
->b_malicious
) {
3418 DP_NOTICE(p_hwfn
->cdev
,
3419 "Can't set forced vlan to malicious VF [%d]\n", vfid
);
3423 feature
= 1 << VLAN_ADDR_FORCED
;
3424 vf_info
->bulletin
.p_virt
->pvid
= pvid
;
3426 vf_info
->bulletin
.p_virt
->valid_bitmap
|= feature
;
3428 vf_info
->bulletin
.p_virt
->valid_bitmap
&= ~feature
;
3430 qed_iov_configure_vport_forced(p_hwfn
, vf_info
, feature
);
3433 static bool qed_iov_vf_has_vport_instance(struct qed_hwfn
*p_hwfn
, int vfid
)
3435 struct qed_vf_info
*p_vf_info
;
3437 p_vf_info
= qed_iov_get_vf_info(p_hwfn
, (u16
) vfid
, true);
3441 return !!p_vf_info
->vport_instance
;
3444 static bool qed_iov_is_vf_stopped(struct qed_hwfn
*p_hwfn
, int vfid
)
3446 struct qed_vf_info
*p_vf_info
;
3448 p_vf_info
= qed_iov_get_vf_info(p_hwfn
, (u16
) vfid
, true);
3452 return p_vf_info
->state
== VF_STOPPED
;
3455 static bool qed_iov_spoofchk_get(struct qed_hwfn
*p_hwfn
, int vfid
)
3457 struct qed_vf_info
*vf_info
;
3459 vf_info
= qed_iov_get_vf_info(p_hwfn
, (u16
) vfid
, true);
3463 return vf_info
->spoof_chk
;
3466 static int qed_iov_spoofchk_set(struct qed_hwfn
*p_hwfn
, int vfid
, bool val
)
3468 struct qed_vf_info
*vf
;
3471 if (!qed_iov_pf_sanity_check(p_hwfn
, vfid
)) {
3473 "SR-IOV sanity check failed, can't set spoofchk\n");
3477 vf
= qed_iov_get_vf_info(p_hwfn
, (u16
) vfid
, true);
3481 if (!qed_iov_vf_has_vport_instance(p_hwfn
, vfid
)) {
3482 /* After VF VPORT start PF will configure spoof check */
3483 vf
->req_spoofchk_val
= val
;
3488 rc
= __qed_iov_spoofchk_set(p_hwfn
, vf
, val
);
3494 static u8
*qed_iov_bulletin_get_forced_mac(struct qed_hwfn
*p_hwfn
,
3497 struct qed_vf_info
*p_vf
;
3499 p_vf
= qed_iov_get_vf_info(p_hwfn
, rel_vf_id
, true);
3500 if (!p_vf
|| !p_vf
->bulletin
.p_virt
)
3503 if (!(p_vf
->bulletin
.p_virt
->valid_bitmap
& BIT(MAC_ADDR_FORCED
)))
3506 return p_vf
->bulletin
.p_virt
->mac
;
3510 qed_iov_bulletin_get_forced_vlan(struct qed_hwfn
*p_hwfn
, u16 rel_vf_id
)
3512 struct qed_vf_info
*p_vf
;
3514 p_vf
= qed_iov_get_vf_info(p_hwfn
, rel_vf_id
, true);
3515 if (!p_vf
|| !p_vf
->bulletin
.p_virt
)
3518 if (!(p_vf
->bulletin
.p_virt
->valid_bitmap
& BIT(VLAN_ADDR_FORCED
)))
3521 return p_vf
->bulletin
.p_virt
->pvid
;
3524 static int qed_iov_configure_tx_rate(struct qed_hwfn
*p_hwfn
,
3525 struct qed_ptt
*p_ptt
, int vfid
, int val
)
3527 struct qed_vf_info
*vf
;
3531 vf
= qed_iov_get_vf_info(p_hwfn
, (u16
)vfid
, true);
3535 rc
= qed_fw_vport(p_hwfn
, vf
->vport_id
, &abs_vp_id
);
3539 return qed_init_vport_rl(p_hwfn
, p_ptt
, abs_vp_id
, (u32
)val
);
3543 qed_iov_configure_min_tx_rate(struct qed_dev
*cdev
, int vfid
, u32 rate
)
3545 struct qed_vf_info
*vf
;
3549 for_each_hwfn(cdev
, i
) {
3550 struct qed_hwfn
*p_hwfn
= &cdev
->hwfns
[i
];
3552 if (!qed_iov_pf_sanity_check(p_hwfn
, vfid
)) {
3554 "SR-IOV sanity check failed, can't set min rate\n");
3559 vf
= qed_iov_get_vf_info(QED_LEADING_HWFN(cdev
), (u16
)vfid
, true);
3560 vport_id
= vf
->vport_id
;
3562 return qed_configure_vport_wfq(cdev
, vport_id
, rate
);
3565 static int qed_iov_get_vf_min_rate(struct qed_hwfn
*p_hwfn
, int vfid
)
3567 struct qed_wfq_data
*vf_vp_wfq
;
3568 struct qed_vf_info
*vf_info
;
3570 vf_info
= qed_iov_get_vf_info(p_hwfn
, (u16
) vfid
, true);
3574 vf_vp_wfq
= &p_hwfn
->qm_info
.wfq_data
[vf_info
->vport_id
];
3576 if (vf_vp_wfq
->configured
)
3577 return vf_vp_wfq
->min_speed
;
3583 * qed_schedule_iov - schedules IOV task for VF and PF
3584 * @hwfn: hardware function pointer
3585 * @flag: IOV flag for VF/PF
3587 void qed_schedule_iov(struct qed_hwfn
*hwfn
, enum qed_iov_wq_flag flag
)
3589 smp_mb__before_atomic();
3590 set_bit(flag
, &hwfn
->iov_task_flags
);
3591 smp_mb__after_atomic();
3592 DP_VERBOSE(hwfn
, QED_MSG_IOV
, "Scheduling iov task [Flag: %d]\n", flag
);
3593 queue_delayed_work(hwfn
->iov_wq
, &hwfn
->iov_task
, 0);
3596 void qed_vf_start_iov_wq(struct qed_dev
*cdev
)
3600 for_each_hwfn(cdev
, i
)
3601 queue_delayed_work(cdev
->hwfns
[i
].iov_wq
,
3602 &cdev
->hwfns
[i
].iov_task
, 0);
3605 int qed_sriov_disable(struct qed_dev
*cdev
, bool pci_enabled
)
3609 for_each_hwfn(cdev
, i
)
3610 if (cdev
->hwfns
[i
].iov_wq
)
3611 flush_workqueue(cdev
->hwfns
[i
].iov_wq
);
3613 /* Mark VFs for disablement */
3614 qed_iov_set_vfs_to_disable(cdev
, true);
3616 if (cdev
->p_iov_info
&& cdev
->p_iov_info
->num_vfs
&& pci_enabled
)
3617 pci_disable_sriov(cdev
->pdev
);
3619 for_each_hwfn(cdev
, i
) {
3620 struct qed_hwfn
*hwfn
= &cdev
->hwfns
[i
];
3621 struct qed_ptt
*ptt
= qed_ptt_acquire(hwfn
);
3623 /* Failure to acquire the ptt in 100g creates an odd error
3624 * where the first engine has already relased IOV.
3627 DP_ERR(hwfn
, "Failed to acquire ptt\n");
3631 /* Clean WFQ db and configure equal weight for all vports */
3632 qed_clean_wfq_db(hwfn
, ptt
);
3634 qed_for_each_vf(hwfn
, j
) {
3637 if (!qed_iov_is_valid_vfid(hwfn
, j
, true, false))
3640 /* Wait until VF is disabled before releasing */
3641 for (k
= 0; k
< 100; k
++) {
3642 if (!qed_iov_is_vf_stopped(hwfn
, j
))
3649 qed_iov_release_hw_for_vf(&cdev
->hwfns
[i
],
3653 "Timeout waiting for VF's FLR to end\n");
3656 qed_ptt_release(hwfn
, ptt
);
3659 qed_iov_set_vfs_to_disable(cdev
, false);
3664 static void qed_sriov_enable_qid_config(struct qed_hwfn
*hwfn
,
3666 struct qed_iov_vf_init_params
*params
)
3670 /* Since we have an equal resource distribution per-VF, and we assume
3671 * PF has acquired the QED_PF_L2_QUE first queues, we start setting
3672 * sequentially from there.
3674 base
= FEAT_NUM(hwfn
, QED_PF_L2_QUE
) + vfid
* params
->num_queues
;
3676 params
->rel_vf_id
= vfid
;
3677 for (i
= 0; i
< params
->num_queues
; i
++) {
3678 params
->req_rx_queue
[i
] = base
+ i
;
3679 params
->req_tx_queue
[i
] = base
+ i
;
3683 static int qed_sriov_enable(struct qed_dev
*cdev
, int num
)
3685 struct qed_iov_vf_init_params params
;
3688 if (num
>= RESC_NUM(&cdev
->hwfns
[0], QED_VPORT
)) {
3689 DP_NOTICE(cdev
, "Can start at most %d VFs\n",
3690 RESC_NUM(&cdev
->hwfns
[0], QED_VPORT
) - 1);
3694 memset(¶ms
, 0, sizeof(params
));
3696 /* Initialize HW for VF access */
3697 for_each_hwfn(cdev
, j
) {
3698 struct qed_hwfn
*hwfn
= &cdev
->hwfns
[j
];
3699 struct qed_ptt
*ptt
= qed_ptt_acquire(hwfn
);
3701 /* Make sure not to use more than 16 queues per VF */
3702 params
.num_queues
= min_t(int,
3703 FEAT_NUM(hwfn
, QED_VF_L2_QUE
) / num
,
3707 DP_ERR(hwfn
, "Failed to acquire ptt\n");
3712 for (i
= 0; i
< num
; i
++) {
3713 if (!qed_iov_is_valid_vfid(hwfn
, i
, false, true))
3716 qed_sriov_enable_qid_config(hwfn
, i
, ¶ms
);
3717 rc
= qed_iov_init_hw_for_vf(hwfn
, ptt
, ¶ms
);
3719 DP_ERR(cdev
, "Failed to enable VF[%d]\n", i
);
3720 qed_ptt_release(hwfn
, ptt
);
3725 qed_ptt_release(hwfn
, ptt
);
3728 /* Enable SRIOV PCIe functions */
3729 rc
= pci_enable_sriov(cdev
->pdev
, num
);
3731 DP_ERR(cdev
, "Failed to enable sriov [%d]\n", rc
);
3738 qed_sriov_disable(cdev
, false);
3742 static int qed_sriov_configure(struct qed_dev
*cdev
, int num_vfs_param
)
3744 if (!IS_QED_SRIOV(cdev
)) {
3745 DP_VERBOSE(cdev
, QED_MSG_IOV
, "SR-IOV is not supported\n");
3750 return qed_sriov_enable(cdev
, num_vfs_param
);
3752 return qed_sriov_disable(cdev
, true);
3755 static int qed_sriov_pf_set_mac(struct qed_dev
*cdev
, u8
*mac
, int vfid
)
3759 if (!IS_QED_SRIOV(cdev
) || !IS_PF_SRIOV_ALLOC(&cdev
->hwfns
[0])) {
3760 DP_VERBOSE(cdev
, QED_MSG_IOV
,
3761 "Cannot set a VF MAC; Sriov is not enabled\n");
3765 if (!qed_iov_is_valid_vfid(&cdev
->hwfns
[0], vfid
, true, true)) {
3766 DP_VERBOSE(cdev
, QED_MSG_IOV
,
3767 "Cannot set VF[%d] MAC (VF is not active)\n", vfid
);
3771 for_each_hwfn(cdev
, i
) {
3772 struct qed_hwfn
*hwfn
= &cdev
->hwfns
[i
];
3773 struct qed_public_vf_info
*vf_info
;
3775 vf_info
= qed_iov_get_public_vf_info(hwfn
, vfid
, true);
3779 /* Set the forced MAC, and schedule the IOV task */
3780 ether_addr_copy(vf_info
->forced_mac
, mac
);
3781 qed_schedule_iov(hwfn
, QED_IOV_WQ_SET_UNICAST_FILTER_FLAG
);
3787 static int qed_sriov_pf_set_vlan(struct qed_dev
*cdev
, u16 vid
, int vfid
)
3791 if (!IS_QED_SRIOV(cdev
) || !IS_PF_SRIOV_ALLOC(&cdev
->hwfns
[0])) {
3792 DP_VERBOSE(cdev
, QED_MSG_IOV
,
3793 "Cannot set a VF MAC; Sriov is not enabled\n");
3797 if (!qed_iov_is_valid_vfid(&cdev
->hwfns
[0], vfid
, true, true)) {
3798 DP_VERBOSE(cdev
, QED_MSG_IOV
,
3799 "Cannot set VF[%d] MAC (VF is not active)\n", vfid
);
3803 for_each_hwfn(cdev
, i
) {
3804 struct qed_hwfn
*hwfn
= &cdev
->hwfns
[i
];
3805 struct qed_public_vf_info
*vf_info
;
3807 vf_info
= qed_iov_get_public_vf_info(hwfn
, vfid
, true);
3811 /* Set the forced vlan, and schedule the IOV task */
3812 vf_info
->forced_vlan
= vid
;
3813 qed_schedule_iov(hwfn
, QED_IOV_WQ_SET_UNICAST_FILTER_FLAG
);
3819 static int qed_get_vf_config(struct qed_dev
*cdev
,
3820 int vf_id
, struct ifla_vf_info
*ivi
)
3822 struct qed_hwfn
*hwfn
= QED_LEADING_HWFN(cdev
);
3823 struct qed_public_vf_info
*vf_info
;
3824 struct qed_mcp_link_state link
;
3827 /* Sanitize request */
3831 if (!qed_iov_is_valid_vfid(&cdev
->hwfns
[0], vf_id
, true, false)) {
3832 DP_VERBOSE(cdev
, QED_MSG_IOV
,
3833 "VF index [%d] isn't active\n", vf_id
);
3837 vf_info
= qed_iov_get_public_vf_info(hwfn
, vf_id
, true);
3839 qed_iov_get_link(hwfn
, vf_id
, NULL
, &link
, NULL
);
3841 /* Fill information about VF */
3844 if (is_valid_ether_addr(vf_info
->forced_mac
))
3845 ether_addr_copy(ivi
->mac
, vf_info
->forced_mac
);
3847 ether_addr_copy(ivi
->mac
, vf_info
->mac
);
3849 ivi
->vlan
= vf_info
->forced_vlan
;
3850 ivi
->spoofchk
= qed_iov_spoofchk_get(hwfn
, vf_id
);
3851 ivi
->linkstate
= vf_info
->link_state
;
3852 tx_rate
= vf_info
->tx_rate
;
3853 ivi
->max_tx_rate
= tx_rate
? tx_rate
: link
.speed
;
3854 ivi
->min_tx_rate
= qed_iov_get_vf_min_rate(hwfn
, vf_id
);
3859 void qed_inform_vf_link_state(struct qed_hwfn
*hwfn
)
3861 struct qed_mcp_link_capabilities caps
;
3862 struct qed_mcp_link_params params
;
3863 struct qed_mcp_link_state link
;
3866 if (!hwfn
->pf_iov_info
)
3869 /* Update bulletin of all future possible VFs with link configuration */
3870 for (i
= 0; i
< hwfn
->cdev
->p_iov_info
->total_vfs
; i
++) {
3871 struct qed_public_vf_info
*vf_info
;
3873 vf_info
= qed_iov_get_public_vf_info(hwfn
, i
, false);
3877 memcpy(¶ms
, qed_mcp_get_link_params(hwfn
), sizeof(params
));
3878 memcpy(&link
, qed_mcp_get_link_state(hwfn
), sizeof(link
));
3879 memcpy(&caps
, qed_mcp_get_link_capabilities(hwfn
),
3882 /* Modify link according to the VF's configured link state */
3883 switch (vf_info
->link_state
) {
3884 case IFLA_VF_LINK_STATE_DISABLE
:
3885 link
.link_up
= false;
3887 case IFLA_VF_LINK_STATE_ENABLE
:
3888 link
.link_up
= true;
3889 /* Set speed according to maximum supported by HW.
3890 * that is 40G for regular devices and 100G for CMT
3893 link
.speed
= (hwfn
->cdev
->num_hwfns
> 1) ?
3896 /* In auto mode pass PF link image to VF */
3900 if (link
.link_up
&& vf_info
->tx_rate
) {
3901 struct qed_ptt
*ptt
;
3904 rate
= min_t(int, vf_info
->tx_rate
, link
.speed
);
3906 ptt
= qed_ptt_acquire(hwfn
);
3908 DP_NOTICE(hwfn
, "Failed to acquire PTT\n");
3912 if (!qed_iov_configure_tx_rate(hwfn
, ptt
, i
, rate
)) {
3913 vf_info
->tx_rate
= rate
;
3917 qed_ptt_release(hwfn
, ptt
);
3920 qed_iov_set_link(hwfn
, i
, ¶ms
, &link
, &caps
);
3923 qed_schedule_iov(hwfn
, QED_IOV_WQ_BULLETIN_UPDATE_FLAG
);
3926 static int qed_set_vf_link_state(struct qed_dev
*cdev
,
3927 int vf_id
, int link_state
)
3931 /* Sanitize request */
3935 if (!qed_iov_is_valid_vfid(&cdev
->hwfns
[0], vf_id
, true, true)) {
3936 DP_VERBOSE(cdev
, QED_MSG_IOV
,
3937 "VF index [%d] isn't active\n", vf_id
);
3941 /* Handle configuration of link state */
3942 for_each_hwfn(cdev
, i
) {
3943 struct qed_hwfn
*hwfn
= &cdev
->hwfns
[i
];
3944 struct qed_public_vf_info
*vf
;
3946 vf
= qed_iov_get_public_vf_info(hwfn
, vf_id
, true);
3950 if (vf
->link_state
== link_state
)
3953 vf
->link_state
= link_state
;
3954 qed_inform_vf_link_state(&cdev
->hwfns
[i
]);
3960 static int qed_spoof_configure(struct qed_dev
*cdev
, int vfid
, bool val
)
3962 int i
, rc
= -EINVAL
;
3964 for_each_hwfn(cdev
, i
) {
3965 struct qed_hwfn
*p_hwfn
= &cdev
->hwfns
[i
];
3967 rc
= qed_iov_spoofchk_set(p_hwfn
, vfid
, val
);
3975 static int qed_configure_max_vf_rate(struct qed_dev
*cdev
, int vfid
, int rate
)
3979 for_each_hwfn(cdev
, i
) {
3980 struct qed_hwfn
*p_hwfn
= &cdev
->hwfns
[i
];
3981 struct qed_public_vf_info
*vf
;
3983 if (!qed_iov_pf_sanity_check(p_hwfn
, vfid
)) {
3985 "SR-IOV sanity check failed, can't set tx rate\n");
3989 vf
= qed_iov_get_public_vf_info(p_hwfn
, vfid
, true);
3993 qed_inform_vf_link_state(p_hwfn
);
3999 static int qed_set_vf_rate(struct qed_dev
*cdev
,
4000 int vfid
, u32 min_rate
, u32 max_rate
)
4002 int rc_min
= 0, rc_max
= 0;
4005 rc_max
= qed_configure_max_vf_rate(cdev
, vfid
, max_rate
);
4008 rc_min
= qed_iov_configure_min_tx_rate(cdev
, vfid
, min_rate
);
4010 if (rc_max
| rc_min
)
4016 static int qed_set_vf_trust(struct qed_dev
*cdev
, int vfid
, bool trust
)
4020 for_each_hwfn(cdev
, i
) {
4021 struct qed_hwfn
*hwfn
= &cdev
->hwfns
[i
];
4022 struct qed_public_vf_info
*vf
;
4024 if (!qed_iov_pf_sanity_check(hwfn
, vfid
)) {
4026 "SR-IOV sanity check failed, can't set trust\n");
4030 vf
= qed_iov_get_public_vf_info(hwfn
, vfid
, true);
4032 if (vf
->is_trusted_request
== trust
)
4034 vf
->is_trusted_request
= trust
;
4036 qed_schedule_iov(hwfn
, QED_IOV_WQ_TRUST_FLAG
);
4042 static void qed_handle_vf_msg(struct qed_hwfn
*hwfn
)
4044 u64 events
[QED_VF_ARRAY_LENGTH
];
4045 struct qed_ptt
*ptt
;
4048 ptt
= qed_ptt_acquire(hwfn
);
4050 DP_VERBOSE(hwfn
, QED_MSG_IOV
,
4051 "Can't acquire PTT; re-scheduling\n");
4052 qed_schedule_iov(hwfn
, QED_IOV_WQ_MSG_FLAG
);
4056 qed_iov_pf_get_pending_events(hwfn
, events
);
4058 DP_VERBOSE(hwfn
, QED_MSG_IOV
,
4059 "Event mask of VF events: 0x%llx 0x%llx 0x%llx\n",
4060 events
[0], events
[1], events
[2]);
4062 qed_for_each_vf(hwfn
, i
) {
4063 /* Skip VFs with no pending messages */
4064 if (!(events
[i
/ 64] & (1ULL << (i
% 64))))
4067 DP_VERBOSE(hwfn
, QED_MSG_IOV
,
4068 "Handling VF message from VF 0x%02x [Abs 0x%02x]\n",
4069 i
, hwfn
->cdev
->p_iov_info
->first_vf_in_pf
+ i
);
4071 /* Copy VF's message to PF's request buffer for that VF */
4072 if (qed_iov_copy_vf_msg(hwfn
, ptt
, i
))
4075 qed_iov_process_mbx_req(hwfn
, ptt
, i
);
4078 qed_ptt_release(hwfn
, ptt
);
4081 static void qed_handle_pf_set_vf_unicast(struct qed_hwfn
*hwfn
)
4085 qed_for_each_vf(hwfn
, i
) {
4086 struct qed_public_vf_info
*info
;
4087 bool update
= false;
4090 info
= qed_iov_get_public_vf_info(hwfn
, i
, true);
4094 /* Update data on bulletin board */
4095 mac
= qed_iov_bulletin_get_forced_mac(hwfn
, i
);
4096 if (is_valid_ether_addr(info
->forced_mac
) &&
4097 (!mac
|| !ether_addr_equal(mac
, info
->forced_mac
))) {
4100 "Handling PF setting of VF MAC to VF 0x%02x [Abs 0x%02x]\n",
4102 hwfn
->cdev
->p_iov_info
->first_vf_in_pf
+ i
);
4104 /* Update bulletin board with forced MAC */
4105 qed_iov_bulletin_set_forced_mac(hwfn
,
4106 info
->forced_mac
, i
);
4110 if (qed_iov_bulletin_get_forced_vlan(hwfn
, i
) ^
4111 info
->forced_vlan
) {
4114 "Handling PF setting of pvid [0x%04x] to VF 0x%02x [Abs 0x%02x]\n",
4117 hwfn
->cdev
->p_iov_info
->first_vf_in_pf
+ i
);
4118 qed_iov_bulletin_set_forced_vlan(hwfn
,
4119 info
->forced_vlan
, i
);
4124 qed_schedule_iov(hwfn
, QED_IOV_WQ_BULLETIN_UPDATE_FLAG
);
4128 static void qed_handle_bulletin_post(struct qed_hwfn
*hwfn
)
4130 struct qed_ptt
*ptt
;
4133 ptt
= qed_ptt_acquire(hwfn
);
4135 DP_NOTICE(hwfn
, "Failed allocating a ptt entry\n");
4136 qed_schedule_iov(hwfn
, QED_IOV_WQ_BULLETIN_UPDATE_FLAG
);
4140 qed_for_each_vf(hwfn
, i
)
4141 qed_iov_post_vf_bulletin(hwfn
, i
, ptt
);
4143 qed_ptt_release(hwfn
, ptt
);
4146 static void qed_iov_handle_trust_change(struct qed_hwfn
*hwfn
)
4148 struct qed_sp_vport_update_params params
;
4149 struct qed_filter_accept_flags
*flags
;
4150 struct qed_public_vf_info
*vf_info
;
4151 struct qed_vf_info
*vf
;
4155 mask
= QED_ACCEPT_UCAST_UNMATCHED
| QED_ACCEPT_MCAST_UNMATCHED
;
4156 flags
= ¶ms
.accept_flags
;
4158 qed_for_each_vf(hwfn
, i
) {
4159 /* Need to make sure current requested configuration didn't
4160 * flip so that we'll end up configuring something that's not
4163 vf_info
= qed_iov_get_public_vf_info(hwfn
, i
, true);
4164 if (vf_info
->is_trusted_configured
==
4165 vf_info
->is_trusted_request
)
4167 vf_info
->is_trusted_configured
= vf_info
->is_trusted_request
;
4169 /* Validate that the VF has a configured vport */
4170 vf
= qed_iov_get_vf_info(hwfn
, i
, true);
4171 if (!vf
->vport_instance
)
4174 memset(¶ms
, 0, sizeof(params
));
4175 params
.opaque_fid
= vf
->opaque_fid
;
4176 params
.vport_id
= vf
->vport_id
;
4178 if (vf_info
->rx_accept_mode
& mask
) {
4179 flags
->update_rx_mode_config
= 1;
4180 flags
->rx_accept_filter
= vf_info
->rx_accept_mode
;
4183 if (vf_info
->tx_accept_mode
& mask
) {
4184 flags
->update_tx_mode_config
= 1;
4185 flags
->tx_accept_filter
= vf_info
->tx_accept_mode
;
4188 /* Remove if needed; Otherwise this would set the mask */
4189 if (!vf_info
->is_trusted_configured
) {
4190 flags
->rx_accept_filter
&= ~mask
;
4191 flags
->tx_accept_filter
&= ~mask
;
4194 if (flags
->update_rx_mode_config
||
4195 flags
->update_tx_mode_config
)
4196 qed_sp_vport_update(hwfn
, ¶ms
,
4197 QED_SPQ_MODE_EBLOCK
, NULL
);
4201 static void qed_iov_pf_task(struct work_struct
*work
)
4204 struct qed_hwfn
*hwfn
= container_of(work
, struct qed_hwfn
,
4208 if (test_and_clear_bit(QED_IOV_WQ_STOP_WQ_FLAG
, &hwfn
->iov_task_flags
))
4211 if (test_and_clear_bit(QED_IOV_WQ_FLR_FLAG
, &hwfn
->iov_task_flags
)) {
4212 struct qed_ptt
*ptt
= qed_ptt_acquire(hwfn
);
4215 qed_schedule_iov(hwfn
, QED_IOV_WQ_FLR_FLAG
);
4219 rc
= qed_iov_vf_flr_cleanup(hwfn
, ptt
);
4221 qed_schedule_iov(hwfn
, QED_IOV_WQ_FLR_FLAG
);
4223 qed_ptt_release(hwfn
, ptt
);
4226 if (test_and_clear_bit(QED_IOV_WQ_MSG_FLAG
, &hwfn
->iov_task_flags
))
4227 qed_handle_vf_msg(hwfn
);
4229 if (test_and_clear_bit(QED_IOV_WQ_SET_UNICAST_FILTER_FLAG
,
4230 &hwfn
->iov_task_flags
))
4231 qed_handle_pf_set_vf_unicast(hwfn
);
4233 if (test_and_clear_bit(QED_IOV_WQ_BULLETIN_UPDATE_FLAG
,
4234 &hwfn
->iov_task_flags
))
4235 qed_handle_bulletin_post(hwfn
);
4237 if (test_and_clear_bit(QED_IOV_WQ_TRUST_FLAG
, &hwfn
->iov_task_flags
))
4238 qed_iov_handle_trust_change(hwfn
);
4241 void qed_iov_wq_stop(struct qed_dev
*cdev
, bool schedule_first
)
4245 for_each_hwfn(cdev
, i
) {
4246 if (!cdev
->hwfns
[i
].iov_wq
)
4249 if (schedule_first
) {
4250 qed_schedule_iov(&cdev
->hwfns
[i
],
4251 QED_IOV_WQ_STOP_WQ_FLAG
);
4252 cancel_delayed_work_sync(&cdev
->hwfns
[i
].iov_task
);
4255 flush_workqueue(cdev
->hwfns
[i
].iov_wq
);
4256 destroy_workqueue(cdev
->hwfns
[i
].iov_wq
);
4260 int qed_iov_wq_start(struct qed_dev
*cdev
)
4262 char name
[NAME_SIZE
];
4265 for_each_hwfn(cdev
, i
) {
4266 struct qed_hwfn
*p_hwfn
= &cdev
->hwfns
[i
];
4268 /* PFs needs a dedicated workqueue only if they support IOV.
4269 * VFs always require one.
4271 if (IS_PF(p_hwfn
->cdev
) && !IS_PF_SRIOV(p_hwfn
))
4274 snprintf(name
, NAME_SIZE
, "iov-%02x:%02x.%02x",
4275 cdev
->pdev
->bus
->number
,
4276 PCI_SLOT(cdev
->pdev
->devfn
), p_hwfn
->abs_pf_id
);
4278 p_hwfn
->iov_wq
= create_singlethread_workqueue(name
);
4279 if (!p_hwfn
->iov_wq
) {
4280 DP_NOTICE(p_hwfn
, "Cannot create iov workqueue\n");
4285 INIT_DELAYED_WORK(&p_hwfn
->iov_task
, qed_iov_pf_task
);
4287 INIT_DELAYED_WORK(&p_hwfn
->iov_task
, qed_iov_vf_task
);
4293 const struct qed_iov_hv_ops qed_iov_ops_pass
= {
4294 .configure
= &qed_sriov_configure
,
4295 .set_mac
= &qed_sriov_pf_set_mac
,
4296 .set_vlan
= &qed_sriov_pf_set_vlan
,
4297 .get_config
= &qed_get_vf_config
,
4298 .set_link_state
= &qed_set_vf_link_state
,
4299 .set_spoof
= &qed_spoof_configure
,
4300 .set_rate
= &qed_set_vf_rate
,
4301 .set_trust
= &qed_set_vf_trust
,