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"
47 static int qed_sriov_eqe_event(struct qed_hwfn *p_hwfn,
50 union event_ring_data *data, u8 fw_return_code);
51 static int qed_iov_bulletin_set_mac(struct qed_hwfn *p_hwfn, u8 *mac, int vfid);
53 static u8 qed_vf_calculate_legacy(struct qed_vf_info *p_vf)
57 if (p_vf->acquire.vfdev_info.eth_fp_hsi_minor ==
58 ETH_HSI_VER_NO_PKT_LEN_TUNN)
59 legacy |= QED_QCID_LEGACY_VF_RX_PROD;
61 if (!(p_vf->acquire.vfdev_info.capabilities &
62 VFPF_ACQUIRE_CAP_QUEUE_QIDS))
63 legacy |= QED_QCID_LEGACY_VF_CID;
69 static int qed_sp_vf_start(struct qed_hwfn *p_hwfn, struct qed_vf_info *p_vf)
71 struct vf_start_ramrod_data *p_ramrod = NULL;
72 struct qed_spq_entry *p_ent = NULL;
73 struct qed_sp_init_data init_data;
78 memset(&init_data, 0, sizeof(init_data));
79 init_data.cid = qed_spq_get_cid(p_hwfn);
80 init_data.opaque_fid = p_vf->opaque_fid;
81 init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
83 rc = qed_sp_init_request(p_hwfn, &p_ent,
84 COMMON_RAMROD_VF_START,
85 PROTOCOLID_COMMON, &init_data);
89 p_ramrod = &p_ent->ramrod.vf_start;
91 p_ramrod->vf_id = GET_FIELD(p_vf->concrete_fid, PXP_CONCRETE_FID_VFID);
92 p_ramrod->opaque_fid = cpu_to_le16(p_vf->opaque_fid);
94 switch (p_hwfn->hw_info.personality) {
96 p_ramrod->personality = PERSONALITY_ETH;
98 case QED_PCI_ETH_ROCE:
99 p_ramrod->personality = PERSONALITY_RDMA_AND_ETH;
102 DP_NOTICE(p_hwfn, "Unknown VF personality %d\n",
103 p_hwfn->hw_info.personality);
104 qed_sp_destroy_request(p_hwfn, p_ent);
108 fp_minor = p_vf->acquire.vfdev_info.eth_fp_hsi_minor;
109 if (fp_minor > ETH_HSI_VER_MINOR &&
110 fp_minor != ETH_HSI_VER_NO_PKT_LEN_TUNN) {
113 "VF [%d] - Requested fp hsi %02x.%02x which is slightly newer than PF's %02x.%02x; Configuring PFs version\n",
116 fp_minor, ETH_HSI_VER_MAJOR, ETH_HSI_VER_MINOR);
117 fp_minor = ETH_HSI_VER_MINOR;
120 p_ramrod->hsi_fp_ver.major_ver_arr[ETH_VER_KEY] = ETH_HSI_VER_MAJOR;
121 p_ramrod->hsi_fp_ver.minor_ver_arr[ETH_VER_KEY] = fp_minor;
123 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
124 "VF[%d] - Starting using HSI %02x.%02x\n",
125 p_vf->abs_vf_id, ETH_HSI_VER_MAJOR, fp_minor);
127 return qed_spq_post(p_hwfn, p_ent, NULL);
130 static int qed_sp_vf_stop(struct qed_hwfn *p_hwfn,
131 u32 concrete_vfid, u16 opaque_vfid)
133 struct vf_stop_ramrod_data *p_ramrod = NULL;
134 struct qed_spq_entry *p_ent = NULL;
135 struct qed_sp_init_data init_data;
139 memset(&init_data, 0, sizeof(init_data));
140 init_data.cid = qed_spq_get_cid(p_hwfn);
141 init_data.opaque_fid = opaque_vfid;
142 init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
144 rc = qed_sp_init_request(p_hwfn, &p_ent,
145 COMMON_RAMROD_VF_STOP,
146 PROTOCOLID_COMMON, &init_data);
150 p_ramrod = &p_ent->ramrod.vf_stop;
152 p_ramrod->vf_id = GET_FIELD(concrete_vfid, PXP_CONCRETE_FID_VFID);
154 return qed_spq_post(p_hwfn, p_ent, NULL);
157 bool qed_iov_is_valid_vfid(struct qed_hwfn *p_hwfn,
159 bool b_enabled_only, bool b_non_malicious)
161 if (!p_hwfn->pf_iov_info) {
162 DP_NOTICE(p_hwfn->cdev, "No iov info\n");
166 if ((rel_vf_id >= p_hwfn->cdev->p_iov_info->total_vfs) ||
170 if ((!p_hwfn->pf_iov_info->vfs_array[rel_vf_id].b_init) &&
174 if ((p_hwfn->pf_iov_info->vfs_array[rel_vf_id].b_malicious) &&
181 static struct qed_vf_info *qed_iov_get_vf_info(struct qed_hwfn *p_hwfn,
185 struct qed_vf_info *vf = NULL;
187 if (!p_hwfn->pf_iov_info) {
188 DP_NOTICE(p_hwfn->cdev, "No iov info\n");
192 if (qed_iov_is_valid_vfid(p_hwfn, relative_vf_id,
193 b_enabled_only, false))
194 vf = &p_hwfn->pf_iov_info->vfs_array[relative_vf_id];
196 DP_ERR(p_hwfn, "qed_iov_get_vf_info: VF[%d] is not enabled\n",
202 static struct qed_queue_cid *
203 qed_iov_get_vf_rx_queue_cid(struct qed_vf_queue *p_queue)
207 for (i = 0; i < MAX_QUEUES_PER_QZONE; i++) {
208 if (p_queue->cids[i].p_cid && !p_queue->cids[i].b_is_tx)
209 return p_queue->cids[i].p_cid;
215 enum qed_iov_validate_q_mode {
216 QED_IOV_VALIDATE_Q_NA,
217 QED_IOV_VALIDATE_Q_ENABLE,
218 QED_IOV_VALIDATE_Q_DISABLE,
221 static bool qed_iov_validate_queue_mode(struct qed_hwfn *p_hwfn,
222 struct qed_vf_info *p_vf,
224 enum qed_iov_validate_q_mode mode,
229 if (mode == QED_IOV_VALIDATE_Q_NA)
232 for (i = 0; i < MAX_QUEUES_PER_QZONE; i++) {
233 struct qed_vf_queue_cid *p_qcid;
235 p_qcid = &p_vf->vf_queues[qid].cids[i];
240 if (p_qcid->b_is_tx != b_is_tx)
243 return mode == QED_IOV_VALIDATE_Q_ENABLE;
246 /* In case we haven't found any valid cid, then its disabled */
247 return mode == QED_IOV_VALIDATE_Q_DISABLE;
250 static bool qed_iov_validate_rxq(struct qed_hwfn *p_hwfn,
251 struct qed_vf_info *p_vf,
253 enum qed_iov_validate_q_mode mode)
255 if (rx_qid >= p_vf->num_rxqs) {
258 "VF[0x%02x] - can't touch Rx queue[%04x]; Only 0x%04x are allocated\n",
259 p_vf->abs_vf_id, rx_qid, p_vf->num_rxqs);
263 return qed_iov_validate_queue_mode(p_hwfn, p_vf, rx_qid, mode, false);
266 static bool qed_iov_validate_txq(struct qed_hwfn *p_hwfn,
267 struct qed_vf_info *p_vf,
269 enum qed_iov_validate_q_mode mode)
271 if (tx_qid >= p_vf->num_txqs) {
274 "VF[0x%02x] - can't touch Tx queue[%04x]; Only 0x%04x are allocated\n",
275 p_vf->abs_vf_id, tx_qid, p_vf->num_txqs);
279 return qed_iov_validate_queue_mode(p_hwfn, p_vf, tx_qid, mode, true);
282 static bool qed_iov_validate_sb(struct qed_hwfn *p_hwfn,
283 struct qed_vf_info *p_vf, u16 sb_idx)
287 for (i = 0; i < p_vf->num_sbs; i++)
288 if (p_vf->igu_sbs[i] == sb_idx)
293 "VF[0%02x] - tried using sb_idx %04x which doesn't exist as one of its 0x%02x SBs\n",
294 p_vf->abs_vf_id, sb_idx, p_vf->num_sbs);
299 static bool qed_iov_validate_active_rxq(struct qed_hwfn *p_hwfn,
300 struct qed_vf_info *p_vf)
304 for (i = 0; i < p_vf->num_rxqs; i++)
305 if (qed_iov_validate_queue_mode(p_hwfn, p_vf, i,
306 QED_IOV_VALIDATE_Q_ENABLE,
313 static bool qed_iov_validate_active_txq(struct qed_hwfn *p_hwfn,
314 struct qed_vf_info *p_vf)
318 for (i = 0; i < p_vf->num_txqs; i++)
319 if (qed_iov_validate_queue_mode(p_hwfn, p_vf, i,
320 QED_IOV_VALIDATE_Q_ENABLE,
327 static int qed_iov_post_vf_bulletin(struct qed_hwfn *p_hwfn,
328 int vfid, struct qed_ptt *p_ptt)
330 struct qed_bulletin_content *p_bulletin;
331 int crc_size = sizeof(p_bulletin->crc);
332 struct qed_dmae_params params;
333 struct qed_vf_info *p_vf;
335 p_vf = qed_iov_get_vf_info(p_hwfn, (u16) vfid, true);
339 if (!p_vf->vf_bulletin)
342 p_bulletin = p_vf->bulletin.p_virt;
344 /* Increment bulletin board version and compute crc */
345 p_bulletin->version++;
346 p_bulletin->crc = crc32(0, (u8 *)p_bulletin + crc_size,
347 p_vf->bulletin.size - crc_size);
349 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
350 "Posting Bulletin 0x%08x to VF[%d] (CRC 0x%08x)\n",
351 p_bulletin->version, p_vf->relative_vf_id, p_bulletin->crc);
353 /* propagate bulletin board via dmae to vm memory */
354 memset(¶ms, 0, sizeof(params));
355 params.flags = QED_DMAE_FLAG_VF_DST;
356 params.dst_vfid = p_vf->abs_vf_id;
357 return qed_dmae_host2host(p_hwfn, p_ptt, p_vf->bulletin.phys,
358 p_vf->vf_bulletin, p_vf->bulletin.size / 4,
362 static int qed_iov_pci_cfg_info(struct qed_dev *cdev)
364 struct qed_hw_sriov_info *iov = cdev->p_iov_info;
367 DP_VERBOSE(cdev, QED_MSG_IOV, "sriov ext pos %d\n", pos);
368 pci_read_config_word(cdev->pdev, pos + PCI_SRIOV_CTRL, &iov->ctrl);
370 pci_read_config_word(cdev->pdev,
371 pos + PCI_SRIOV_TOTAL_VF, &iov->total_vfs);
372 pci_read_config_word(cdev->pdev,
373 pos + PCI_SRIOV_INITIAL_VF, &iov->initial_vfs);
375 pci_read_config_word(cdev->pdev, pos + PCI_SRIOV_NUM_VF, &iov->num_vfs);
379 "Number of VFs are already set to non-zero value. Ignoring PCI configuration value\n");
383 pci_read_config_word(cdev->pdev,
384 pos + PCI_SRIOV_VF_OFFSET, &iov->offset);
386 pci_read_config_word(cdev->pdev,
387 pos + PCI_SRIOV_VF_STRIDE, &iov->stride);
389 pci_read_config_word(cdev->pdev,
390 pos + PCI_SRIOV_VF_DID, &iov->vf_device_id);
392 pci_read_config_dword(cdev->pdev,
393 pos + PCI_SRIOV_SUP_PGSIZE, &iov->pgsz);
395 pci_read_config_dword(cdev->pdev, pos + PCI_SRIOV_CAP, &iov->cap);
397 pci_read_config_byte(cdev->pdev, pos + PCI_SRIOV_FUNC_LINK, &iov->link);
401 "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",
407 iov->nr_virtfn, iov->offset, iov->stride, iov->pgsz);
409 /* Some sanity checks */
410 if (iov->num_vfs > NUM_OF_VFS(cdev) ||
411 iov->total_vfs > NUM_OF_VFS(cdev)) {
412 /* This can happen only due to a bug. In this case we set
413 * num_vfs to zero to avoid memory corruption in the code that
414 * assumes max number of vfs
417 "IOV: Unexpected number of vfs set: %d setting num_vf to zero\n",
427 static void qed_iov_setup_vfdb(struct qed_hwfn *p_hwfn)
429 struct qed_hw_sriov_info *p_iov = p_hwfn->cdev->p_iov_info;
430 struct qed_pf_iov *p_iov_info = p_hwfn->pf_iov_info;
431 struct qed_bulletin_content *p_bulletin_virt;
432 dma_addr_t req_p, rply_p, bulletin_p;
433 union pfvf_tlvs *p_reply_virt_addr;
434 union vfpf_tlvs *p_req_virt_addr;
437 memset(p_iov_info->vfs_array, 0, sizeof(p_iov_info->vfs_array));
439 p_req_virt_addr = p_iov_info->mbx_msg_virt_addr;
440 req_p = p_iov_info->mbx_msg_phys_addr;
441 p_reply_virt_addr = p_iov_info->mbx_reply_virt_addr;
442 rply_p = p_iov_info->mbx_reply_phys_addr;
443 p_bulletin_virt = p_iov_info->p_bulletins;
444 bulletin_p = p_iov_info->bulletins_phys;
445 if (!p_req_virt_addr || !p_reply_virt_addr || !p_bulletin_virt) {
447 "qed_iov_setup_vfdb called without allocating mem first\n");
451 for (idx = 0; idx < p_iov->total_vfs; idx++) {
452 struct qed_vf_info *vf = &p_iov_info->vfs_array[idx];
455 vf->vf_mbx.req_virt = p_req_virt_addr + idx;
456 vf->vf_mbx.req_phys = req_p + idx * sizeof(union vfpf_tlvs);
457 vf->vf_mbx.reply_virt = p_reply_virt_addr + idx;
458 vf->vf_mbx.reply_phys = rply_p + idx * sizeof(union pfvf_tlvs);
460 vf->state = VF_STOPPED;
463 vf->bulletin.phys = idx *
464 sizeof(struct qed_bulletin_content) +
466 vf->bulletin.p_virt = p_bulletin_virt + idx;
467 vf->bulletin.size = sizeof(struct qed_bulletin_content);
469 vf->relative_vf_id = idx;
470 vf->abs_vf_id = idx + p_iov->first_vf_in_pf;
471 concrete = qed_vfid_to_concrete(p_hwfn, vf->abs_vf_id);
472 vf->concrete_fid = concrete;
473 vf->opaque_fid = (p_hwfn->hw_info.opaque_fid & 0xff) |
474 (vf->abs_vf_id << 8);
475 vf->vport_id = idx + 1;
477 vf->num_mac_filters = QED_ETH_VF_NUM_MAC_FILTERS;
478 vf->num_vlan_filters = QED_ETH_VF_NUM_VLAN_FILTERS;
482 static int qed_iov_allocate_vfdb(struct qed_hwfn *p_hwfn)
484 struct qed_pf_iov *p_iov_info = p_hwfn->pf_iov_info;
488 num_vfs = p_hwfn->cdev->p_iov_info->total_vfs;
490 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
491 "qed_iov_allocate_vfdb for %d VFs\n", num_vfs);
493 /* Allocate PF Mailbox buffer (per-VF) */
494 p_iov_info->mbx_msg_size = sizeof(union vfpf_tlvs) * num_vfs;
495 p_v_addr = &p_iov_info->mbx_msg_virt_addr;
496 *p_v_addr = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev,
497 p_iov_info->mbx_msg_size,
498 &p_iov_info->mbx_msg_phys_addr,
503 /* Allocate PF Mailbox Reply buffer (per-VF) */
504 p_iov_info->mbx_reply_size = sizeof(union pfvf_tlvs) * num_vfs;
505 p_v_addr = &p_iov_info->mbx_reply_virt_addr;
506 *p_v_addr = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev,
507 p_iov_info->mbx_reply_size,
508 &p_iov_info->mbx_reply_phys_addr,
513 p_iov_info->bulletins_size = sizeof(struct qed_bulletin_content) *
515 p_v_addr = &p_iov_info->p_bulletins;
516 *p_v_addr = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev,
517 p_iov_info->bulletins_size,
518 &p_iov_info->bulletins_phys,
525 "PF's Requests mailbox [%p virt 0x%llx phys], Response mailbox [%p virt 0x%llx phys] Bulletins [%p virt 0x%llx phys]\n",
526 p_iov_info->mbx_msg_virt_addr,
527 (u64) p_iov_info->mbx_msg_phys_addr,
528 p_iov_info->mbx_reply_virt_addr,
529 (u64) p_iov_info->mbx_reply_phys_addr,
530 p_iov_info->p_bulletins, (u64) p_iov_info->bulletins_phys);
535 static void qed_iov_free_vfdb(struct qed_hwfn *p_hwfn)
537 struct qed_pf_iov *p_iov_info = p_hwfn->pf_iov_info;
539 if (p_hwfn->pf_iov_info->mbx_msg_virt_addr)
540 dma_free_coherent(&p_hwfn->cdev->pdev->dev,
541 p_iov_info->mbx_msg_size,
542 p_iov_info->mbx_msg_virt_addr,
543 p_iov_info->mbx_msg_phys_addr);
545 if (p_hwfn->pf_iov_info->mbx_reply_virt_addr)
546 dma_free_coherent(&p_hwfn->cdev->pdev->dev,
547 p_iov_info->mbx_reply_size,
548 p_iov_info->mbx_reply_virt_addr,
549 p_iov_info->mbx_reply_phys_addr);
551 if (p_iov_info->p_bulletins)
552 dma_free_coherent(&p_hwfn->cdev->pdev->dev,
553 p_iov_info->bulletins_size,
554 p_iov_info->p_bulletins,
555 p_iov_info->bulletins_phys);
558 int qed_iov_alloc(struct qed_hwfn *p_hwfn)
560 struct qed_pf_iov *p_sriov;
562 if (!IS_PF_SRIOV(p_hwfn)) {
563 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
564 "No SR-IOV - no need for IOV db\n");
568 p_sriov = kzalloc(sizeof(*p_sriov), GFP_KERNEL);
572 p_hwfn->pf_iov_info = p_sriov;
574 qed_spq_register_async_cb(p_hwfn, PROTOCOLID_COMMON,
575 qed_sriov_eqe_event);
577 return qed_iov_allocate_vfdb(p_hwfn);
580 void qed_iov_setup(struct qed_hwfn *p_hwfn)
582 if (!IS_PF_SRIOV(p_hwfn) || !IS_PF_SRIOV_ALLOC(p_hwfn))
585 qed_iov_setup_vfdb(p_hwfn);
588 void qed_iov_free(struct qed_hwfn *p_hwfn)
590 qed_spq_unregister_async_cb(p_hwfn, PROTOCOLID_COMMON);
592 if (IS_PF_SRIOV_ALLOC(p_hwfn)) {
593 qed_iov_free_vfdb(p_hwfn);
594 kfree(p_hwfn->pf_iov_info);
598 void qed_iov_free_hw_info(struct qed_dev *cdev)
600 kfree(cdev->p_iov_info);
601 cdev->p_iov_info = NULL;
604 int qed_iov_hw_info(struct qed_hwfn *p_hwfn)
606 struct qed_dev *cdev = p_hwfn->cdev;
610 if (IS_VF(p_hwfn->cdev))
613 /* Learn the PCI configuration */
614 pos = pci_find_ext_capability(p_hwfn->cdev->pdev,
615 PCI_EXT_CAP_ID_SRIOV);
617 DP_VERBOSE(p_hwfn, QED_MSG_IOV, "No PCIe IOV support\n");
621 /* Allocate a new struct for IOV information */
622 cdev->p_iov_info = kzalloc(sizeof(*cdev->p_iov_info), GFP_KERNEL);
623 if (!cdev->p_iov_info)
626 cdev->p_iov_info->pos = pos;
628 rc = qed_iov_pci_cfg_info(cdev);
632 /* We want PF IOV to be synonemous with the existance of p_iov_info;
633 * In case the capability is published but there are no VFs, simply
634 * de-allocate the struct.
636 if (!cdev->p_iov_info->total_vfs) {
637 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
638 "IOV capabilities, but no VFs are published\n");
639 kfree(cdev->p_iov_info);
640 cdev->p_iov_info = NULL;
644 /* First VF index based on offset is tricky:
645 * - If ARI is supported [likely], offset - (16 - pf_id) would
646 * provide the number for eng0. 2nd engine Vfs would begin
647 * after the first engine's VFs.
648 * - If !ARI, VFs would start on next device.
649 * so offset - (256 - pf_id) would provide the number.
650 * Utilize the fact that (256 - pf_id) is achieved only by later
651 * to differentiate between the two.
654 if (p_hwfn->cdev->p_iov_info->offset < (256 - p_hwfn->abs_pf_id)) {
655 u32 first = p_hwfn->cdev->p_iov_info->offset +
656 p_hwfn->abs_pf_id - 16;
658 cdev->p_iov_info->first_vf_in_pf = first;
660 if (QED_PATH_ID(p_hwfn))
661 cdev->p_iov_info->first_vf_in_pf -= MAX_NUM_VFS_BB;
663 u32 first = p_hwfn->cdev->p_iov_info->offset +
664 p_hwfn->abs_pf_id - 256;
666 cdev->p_iov_info->first_vf_in_pf = first;
669 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
670 "First VF in hwfn 0x%08x\n",
671 cdev->p_iov_info->first_vf_in_pf);
676 static bool _qed_iov_pf_sanity_check(struct qed_hwfn *p_hwfn,
677 int vfid, bool b_fail_malicious)
679 /* Check PF supports sriov */
680 if (IS_VF(p_hwfn->cdev) || !IS_QED_SRIOV(p_hwfn->cdev) ||
681 !IS_PF_SRIOV_ALLOC(p_hwfn))
684 /* Check VF validity */
685 if (!qed_iov_is_valid_vfid(p_hwfn, vfid, true, b_fail_malicious))
691 static bool qed_iov_pf_sanity_check(struct qed_hwfn *p_hwfn, int vfid)
693 return _qed_iov_pf_sanity_check(p_hwfn, vfid, true);
696 static void qed_iov_set_vf_to_disable(struct qed_dev *cdev,
697 u16 rel_vf_id, u8 to_disable)
699 struct qed_vf_info *vf;
702 for_each_hwfn(cdev, i) {
703 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
705 vf = qed_iov_get_vf_info(p_hwfn, rel_vf_id, false);
709 vf->to_disable = to_disable;
713 static void qed_iov_set_vfs_to_disable(struct qed_dev *cdev, u8 to_disable)
717 if (!IS_QED_SRIOV(cdev))
720 for (i = 0; i < cdev->p_iov_info->total_vfs; i++)
721 qed_iov_set_vf_to_disable(cdev, i, to_disable);
724 static void qed_iov_vf_pglue_clear_err(struct qed_hwfn *p_hwfn,
725 struct qed_ptt *p_ptt, u8 abs_vfid)
727 qed_wr(p_hwfn, p_ptt,
728 PGLUE_B_REG_WAS_ERROR_VF_31_0_CLR + (abs_vfid >> 5) * 4,
729 1 << (abs_vfid & 0x1f));
732 static void qed_iov_vf_igu_reset(struct qed_hwfn *p_hwfn,
733 struct qed_ptt *p_ptt, struct qed_vf_info *vf)
737 /* Set VF masks and configuration - pretend */
738 qed_fid_pretend(p_hwfn, p_ptt, (u16) vf->concrete_fid);
740 qed_wr(p_hwfn, p_ptt, IGU_REG_STATISTIC_NUM_VF_MSG_SENT, 0);
743 qed_fid_pretend(p_hwfn, p_ptt, (u16) p_hwfn->hw_info.concrete_fid);
745 /* iterate over all queues, clear sb consumer */
746 for (i = 0; i < vf->num_sbs; i++)
747 qed_int_igu_init_pure_rt_single(p_hwfn, p_ptt,
749 vf->opaque_fid, true);
752 static void qed_iov_vf_igu_set_int(struct qed_hwfn *p_hwfn,
753 struct qed_ptt *p_ptt,
754 struct qed_vf_info *vf, bool enable)
758 qed_fid_pretend(p_hwfn, p_ptt, (u16) vf->concrete_fid);
760 igu_vf_conf = qed_rd(p_hwfn, p_ptt, IGU_REG_VF_CONFIGURATION);
763 igu_vf_conf |= IGU_VF_CONF_MSI_MSIX_EN;
765 igu_vf_conf &= ~IGU_VF_CONF_MSI_MSIX_EN;
767 qed_wr(p_hwfn, p_ptt, IGU_REG_VF_CONFIGURATION, igu_vf_conf);
770 qed_fid_pretend(p_hwfn, p_ptt, (u16) p_hwfn->hw_info.concrete_fid);
774 qed_iov_enable_vf_access_msix(struct qed_hwfn *p_hwfn,
775 struct qed_ptt *p_ptt, u8 abs_vf_id, u8 num_sbs)
780 /* For AH onward, configuration is per-PF. Find maximum of all
781 * the currently enabled child VFs, and set the number to be that.
783 if (!QED_IS_BB(p_hwfn->cdev)) {
784 qed_for_each_vf(p_hwfn, i) {
785 struct qed_vf_info *p_vf;
787 p_vf = qed_iov_get_vf_info(p_hwfn, (u16)i, true);
791 current_max = max_t(u8, current_max, p_vf->num_sbs);
795 if (num_sbs > current_max)
796 return qed_mcp_config_vf_msix(p_hwfn, p_ptt,
802 static int qed_iov_enable_vf_access(struct qed_hwfn *p_hwfn,
803 struct qed_ptt *p_ptt,
804 struct qed_vf_info *vf)
806 u32 igu_vf_conf = IGU_VF_CONF_FUNC_EN;
809 /* It's possible VF was previously considered malicious -
810 * clear the indication even if we're only going to disable VF.
812 vf->b_malicious = false;
819 "Enable internal access for vf %x [abs %x]\n",
820 vf->abs_vf_id, QED_VF_ABS_ID(p_hwfn, vf));
822 qed_iov_vf_pglue_clear_err(p_hwfn, p_ptt, QED_VF_ABS_ID(p_hwfn, vf));
824 qed_iov_vf_igu_reset(p_hwfn, p_ptt, vf);
826 rc = qed_iov_enable_vf_access_msix(p_hwfn, p_ptt,
827 vf->abs_vf_id, vf->num_sbs);
831 qed_fid_pretend(p_hwfn, p_ptt, (u16) vf->concrete_fid);
833 SET_FIELD(igu_vf_conf, IGU_VF_CONF_PARENT, p_hwfn->rel_pf_id);
834 STORE_RT_REG(p_hwfn, IGU_REG_VF_CONFIGURATION_RT_OFFSET, igu_vf_conf);
836 qed_init_run(p_hwfn, p_ptt, PHASE_VF, vf->abs_vf_id,
837 p_hwfn->hw_info.hw_mode);
840 qed_fid_pretend(p_hwfn, p_ptt, (u16) p_hwfn->hw_info.concrete_fid);
848 * @brief qed_iov_config_perm_table - configure the permission
850 * In E4, queue zone permission table size is 320x9. There
851 * are 320 VF queues for single engine device (256 for dual
852 * engine device), and each entry has the following format:
859 static void qed_iov_config_perm_table(struct qed_hwfn *p_hwfn,
860 struct qed_ptt *p_ptt,
861 struct qed_vf_info *vf, u8 enable)
867 for (qid = 0; qid < vf->num_rxqs; qid++) {
868 qed_fw_l2_queue(p_hwfn, vf->vf_queues[qid].fw_rx_qid,
871 reg_addr = PSWHST_REG_ZONE_PERMISSION_TABLE + qzone_id * 4;
872 val = enable ? (vf->abs_vf_id | BIT(8)) : 0;
873 qed_wr(p_hwfn, p_ptt, reg_addr, val);
877 static void qed_iov_enable_vf_traffic(struct qed_hwfn *p_hwfn,
878 struct qed_ptt *p_ptt,
879 struct qed_vf_info *vf)
881 /* Reset vf in IGU - interrupts are still disabled */
882 qed_iov_vf_igu_reset(p_hwfn, p_ptt, vf);
884 qed_iov_vf_igu_set_int(p_hwfn, p_ptt, vf, 1);
886 /* Permission Table */
887 qed_iov_config_perm_table(p_hwfn, p_ptt, vf, true);
890 static u8 qed_iov_alloc_vf_igu_sbs(struct qed_hwfn *p_hwfn,
891 struct qed_ptt *p_ptt,
892 struct qed_vf_info *vf, u16 num_rx_queues)
894 struct qed_igu_block *p_block;
895 struct cau_sb_entry sb_entry;
899 if (num_rx_queues > p_hwfn->hw_info.p_igu_info->usage.free_cnt_iov)
900 num_rx_queues = p_hwfn->hw_info.p_igu_info->usage.free_cnt_iov;
901 p_hwfn->hw_info.p_igu_info->usage.free_cnt_iov -= num_rx_queues;
903 SET_FIELD(val, IGU_MAPPING_LINE_FUNCTION_NUMBER, vf->abs_vf_id);
904 SET_FIELD(val, IGU_MAPPING_LINE_VALID, 1);
905 SET_FIELD(val, IGU_MAPPING_LINE_PF_VALID, 0);
907 for (qid = 0; qid < num_rx_queues; qid++) {
908 p_block = qed_get_igu_free_sb(p_hwfn, false);
909 vf->igu_sbs[qid] = p_block->igu_sb_id;
910 p_block->status &= ~QED_IGU_STATUS_FREE;
911 SET_FIELD(val, IGU_MAPPING_LINE_VECTOR_NUMBER, qid);
913 qed_wr(p_hwfn, p_ptt,
914 IGU_REG_MAPPING_MEMORY +
915 sizeof(u32) * p_block->igu_sb_id, val);
917 /* Configure igu sb in CAU which were marked valid */
918 qed_init_cau_sb_entry(p_hwfn, &sb_entry,
919 p_hwfn->rel_pf_id, vf->abs_vf_id, 1);
920 qed_dmae_host2grc(p_hwfn, p_ptt,
921 (u64)(uintptr_t)&sb_entry,
922 CAU_REG_SB_VAR_MEMORY +
923 p_block->igu_sb_id * sizeof(u64), 2, 0);
926 vf->num_sbs = (u8) num_rx_queues;
931 static void qed_iov_free_vf_igu_sbs(struct qed_hwfn *p_hwfn,
932 struct qed_ptt *p_ptt,
933 struct qed_vf_info *vf)
935 struct qed_igu_info *p_info = p_hwfn->hw_info.p_igu_info;
939 /* Invalidate igu CAM lines and mark them as free */
940 for (idx = 0; idx < vf->num_sbs; idx++) {
941 igu_id = vf->igu_sbs[idx];
942 addr = IGU_REG_MAPPING_MEMORY + sizeof(u32) * igu_id;
944 val = qed_rd(p_hwfn, p_ptt, addr);
945 SET_FIELD(val, IGU_MAPPING_LINE_VALID, 0);
946 qed_wr(p_hwfn, p_ptt, addr, val);
948 p_info->entry[igu_id].status |= QED_IGU_STATUS_FREE;
949 p_hwfn->hw_info.p_igu_info->usage.free_cnt_iov++;
955 static void qed_iov_set_link(struct qed_hwfn *p_hwfn,
957 struct qed_mcp_link_params *params,
958 struct qed_mcp_link_state *link,
959 struct qed_mcp_link_capabilities *p_caps)
961 struct qed_vf_info *p_vf = qed_iov_get_vf_info(p_hwfn,
964 struct qed_bulletin_content *p_bulletin;
969 p_bulletin = p_vf->bulletin.p_virt;
970 p_bulletin->req_autoneg = params->speed.autoneg;
971 p_bulletin->req_adv_speed = params->speed.advertised_speeds;
972 p_bulletin->req_forced_speed = params->speed.forced_speed;
973 p_bulletin->req_autoneg_pause = params->pause.autoneg;
974 p_bulletin->req_forced_rx = params->pause.forced_rx;
975 p_bulletin->req_forced_tx = params->pause.forced_tx;
976 p_bulletin->req_loopback = params->loopback_mode;
978 p_bulletin->link_up = link->link_up;
979 p_bulletin->speed = link->speed;
980 p_bulletin->full_duplex = link->full_duplex;
981 p_bulletin->autoneg = link->an;
982 p_bulletin->autoneg_complete = link->an_complete;
983 p_bulletin->parallel_detection = link->parallel_detection;
984 p_bulletin->pfc_enabled = link->pfc_enabled;
985 p_bulletin->partner_adv_speed = link->partner_adv_speed;
986 p_bulletin->partner_tx_flow_ctrl_en = link->partner_tx_flow_ctrl_en;
987 p_bulletin->partner_rx_flow_ctrl_en = link->partner_rx_flow_ctrl_en;
988 p_bulletin->partner_adv_pause = link->partner_adv_pause;
989 p_bulletin->sfp_tx_fault = link->sfp_tx_fault;
991 p_bulletin->capability_speed = p_caps->speed_capabilities;
994 static int qed_iov_init_hw_for_vf(struct qed_hwfn *p_hwfn,
995 struct qed_ptt *p_ptt,
996 struct qed_iov_vf_init_params *p_params)
998 struct qed_mcp_link_capabilities link_caps;
999 struct qed_mcp_link_params link_params;
1000 struct qed_mcp_link_state link_state;
1001 u8 num_of_vf_avaiable_chains = 0;
1002 struct qed_vf_info *vf = NULL;
1008 vf = qed_iov_get_vf_info(p_hwfn, p_params->rel_vf_id, false);
1010 DP_ERR(p_hwfn, "qed_iov_init_hw_for_vf : vf is NULL\n");
1015 DP_NOTICE(p_hwfn, "VF[%d] is already active.\n",
1016 p_params->rel_vf_id);
1020 /* Perform sanity checking on the requested queue_id */
1021 for (i = 0; i < p_params->num_queues; i++) {
1022 u16 min_vf_qzone = FEAT_NUM(p_hwfn, QED_PF_L2_QUE);
1023 u16 max_vf_qzone = min_vf_qzone +
1024 FEAT_NUM(p_hwfn, QED_VF_L2_QUE) - 1;
1026 qid = p_params->req_rx_queue[i];
1027 if (qid < min_vf_qzone || qid > max_vf_qzone) {
1029 "Can't enable Rx qid [%04x] for VF[%d]: qids [0x%04x,...,0x%04x] available\n",
1031 p_params->rel_vf_id,
1032 min_vf_qzone, max_vf_qzone);
1036 qid = p_params->req_tx_queue[i];
1037 if (qid > max_vf_qzone) {
1039 "Can't enable Tx qid [%04x] for VF[%d]: max qid 0x%04x\n",
1040 qid, p_params->rel_vf_id, max_vf_qzone);
1044 /* If client *really* wants, Tx qid can be shared with PF */
1045 if (qid < min_vf_qzone)
1048 "VF[%d] is using PF qid [0x%04x] for Txq[0x%02x]\n",
1049 p_params->rel_vf_id, qid, i);
1052 /* Limit number of queues according to number of CIDs */
1053 qed_cxt_get_proto_cid_count(p_hwfn, PROTOCOLID_ETH, &cids);
1056 "VF[%d] - requesting to initialize for 0x%04x queues [0x%04x CIDs available]\n",
1057 vf->relative_vf_id, p_params->num_queues, (u16)cids);
1058 num_irqs = min_t(u16, p_params->num_queues, ((u16)cids));
1060 num_of_vf_avaiable_chains = qed_iov_alloc_vf_igu_sbs(p_hwfn,
1063 if (!num_of_vf_avaiable_chains) {
1064 DP_ERR(p_hwfn, "no available igu sbs\n");
1068 /* Choose queue number and index ranges */
1069 vf->num_rxqs = num_of_vf_avaiable_chains;
1070 vf->num_txqs = num_of_vf_avaiable_chains;
1072 for (i = 0; i < vf->num_rxqs; i++) {
1073 struct qed_vf_queue *p_queue = &vf->vf_queues[i];
1075 p_queue->fw_rx_qid = p_params->req_rx_queue[i];
1076 p_queue->fw_tx_qid = p_params->req_tx_queue[i];
1078 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
1079 "VF[%d] - Q[%d] SB %04x, qid [Rx %04x Tx %04x]\n",
1080 vf->relative_vf_id, i, vf->igu_sbs[i],
1081 p_queue->fw_rx_qid, p_queue->fw_tx_qid);
1084 /* Update the link configuration in bulletin */
1085 memcpy(&link_params, qed_mcp_get_link_params(p_hwfn),
1086 sizeof(link_params));
1087 memcpy(&link_state, qed_mcp_get_link_state(p_hwfn), sizeof(link_state));
1088 memcpy(&link_caps, qed_mcp_get_link_capabilities(p_hwfn),
1090 qed_iov_set_link(p_hwfn, p_params->rel_vf_id,
1091 &link_params, &link_state, &link_caps);
1093 rc = qed_iov_enable_vf_access(p_hwfn, p_ptt, vf);
1097 if (IS_LEAD_HWFN(p_hwfn))
1098 p_hwfn->cdev->p_iov_info->num_vfs++;
1104 static int qed_iov_release_hw_for_vf(struct qed_hwfn *p_hwfn,
1105 struct qed_ptt *p_ptt, u16 rel_vf_id)
1107 struct qed_mcp_link_capabilities caps;
1108 struct qed_mcp_link_params params;
1109 struct qed_mcp_link_state link;
1110 struct qed_vf_info *vf = NULL;
1112 vf = qed_iov_get_vf_info(p_hwfn, rel_vf_id, true);
1114 DP_ERR(p_hwfn, "qed_iov_release_hw_for_vf : vf is NULL\n");
1118 if (vf->bulletin.p_virt)
1119 memset(vf->bulletin.p_virt, 0, sizeof(*vf->bulletin.p_virt));
1121 memset(&vf->p_vf_info, 0, sizeof(vf->p_vf_info));
1123 /* Get the link configuration back in bulletin so
1124 * that when VFs are re-enabled they get the actual
1125 * link configuration.
1127 memcpy(¶ms, qed_mcp_get_link_params(p_hwfn), sizeof(params));
1128 memcpy(&link, qed_mcp_get_link_state(p_hwfn), sizeof(link));
1129 memcpy(&caps, qed_mcp_get_link_capabilities(p_hwfn), sizeof(caps));
1130 qed_iov_set_link(p_hwfn, rel_vf_id, ¶ms, &link, &caps);
1132 /* Forget the VF's acquisition message */
1133 memset(&vf->acquire, 0, sizeof(vf->acquire));
1135 /* disablng interrupts and resetting permission table was done during
1136 * vf-close, however, we could get here without going through vf_close
1138 /* Disable Interrupts for VF */
1139 qed_iov_vf_igu_set_int(p_hwfn, p_ptt, vf, 0);
1141 /* Reset Permission table */
1142 qed_iov_config_perm_table(p_hwfn, p_ptt, vf, 0);
1146 qed_iov_free_vf_igu_sbs(p_hwfn, p_ptt, vf);
1151 if (IS_LEAD_HWFN(p_hwfn))
1152 p_hwfn->cdev->p_iov_info->num_vfs--;
1158 static bool qed_iov_tlv_supported(u16 tlvtype)
1160 return CHANNEL_TLV_NONE < tlvtype && tlvtype < CHANNEL_TLV_MAX;
1163 /* place a given tlv on the tlv buffer, continuing current tlv list */
1164 void *qed_add_tlv(struct qed_hwfn *p_hwfn, u8 **offset, u16 type, u16 length)
1166 struct channel_tlv *tl = (struct channel_tlv *)*offset;
1169 tl->length = length;
1171 /* Offset should keep pointing to next TLV (the end of the last) */
1174 /* Return a pointer to the start of the added tlv */
1175 return *offset - length;
1178 /* list the types and lengths of the tlvs on the buffer */
1179 void qed_dp_tlv_list(struct qed_hwfn *p_hwfn, void *tlvs_list)
1181 u16 i = 1, total_length = 0;
1182 struct channel_tlv *tlv;
1185 tlv = (struct channel_tlv *)((u8 *)tlvs_list + total_length);
1188 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
1189 "TLV number %d: type %d, length %d\n",
1190 i, tlv->type, tlv->length);
1192 if (tlv->type == CHANNEL_TLV_LIST_END)
1195 /* Validate entry - protect against malicious VFs */
1197 DP_NOTICE(p_hwfn, "TLV of length 0 found\n");
1201 total_length += tlv->length;
1203 if (total_length >= sizeof(struct tlv_buffer_size)) {
1204 DP_NOTICE(p_hwfn, "TLV ==> Buffer overflow\n");
1212 static void qed_iov_send_response(struct qed_hwfn *p_hwfn,
1213 struct qed_ptt *p_ptt,
1214 struct qed_vf_info *p_vf,
1215 u16 length, u8 status)
1217 struct qed_iov_vf_mbx *mbx = &p_vf->vf_mbx;
1218 struct qed_dmae_params params;
1221 mbx->reply_virt->default_resp.hdr.status = status;
1223 qed_dp_tlv_list(p_hwfn, mbx->reply_virt);
1225 eng_vf_id = p_vf->abs_vf_id;
1227 memset(¶ms, 0, sizeof(struct qed_dmae_params));
1228 params.flags = QED_DMAE_FLAG_VF_DST;
1229 params.dst_vfid = eng_vf_id;
1231 qed_dmae_host2host(p_hwfn, p_ptt, mbx->reply_phys + sizeof(u64),
1232 mbx->req_virt->first_tlv.reply_address +
1234 (sizeof(union pfvf_tlvs) - sizeof(u64)) / 4,
1237 /* Once PF copies the rc to the VF, the latter can continue
1238 * and send an additional message. So we have to make sure the
1239 * channel would be re-set to ready prior to that.
1242 GTT_BAR0_MAP_REG_USDM_RAM +
1243 USTORM_VF_PF_CHANNEL_READY_OFFSET(eng_vf_id), 1);
1245 qed_dmae_host2host(p_hwfn, p_ptt, mbx->reply_phys,
1246 mbx->req_virt->first_tlv.reply_address,
1247 sizeof(u64) / 4, ¶ms);
1250 static u16 qed_iov_vport_to_tlv(struct qed_hwfn *p_hwfn,
1251 enum qed_iov_vport_update_flag flag)
1254 case QED_IOV_VP_UPDATE_ACTIVATE:
1255 return CHANNEL_TLV_VPORT_UPDATE_ACTIVATE;
1256 case QED_IOV_VP_UPDATE_VLAN_STRIP:
1257 return CHANNEL_TLV_VPORT_UPDATE_VLAN_STRIP;
1258 case QED_IOV_VP_UPDATE_TX_SWITCH:
1259 return CHANNEL_TLV_VPORT_UPDATE_TX_SWITCH;
1260 case QED_IOV_VP_UPDATE_MCAST:
1261 return CHANNEL_TLV_VPORT_UPDATE_MCAST;
1262 case QED_IOV_VP_UPDATE_ACCEPT_PARAM:
1263 return CHANNEL_TLV_VPORT_UPDATE_ACCEPT_PARAM;
1264 case QED_IOV_VP_UPDATE_RSS:
1265 return CHANNEL_TLV_VPORT_UPDATE_RSS;
1266 case QED_IOV_VP_UPDATE_ACCEPT_ANY_VLAN:
1267 return CHANNEL_TLV_VPORT_UPDATE_ACCEPT_ANY_VLAN;
1268 case QED_IOV_VP_UPDATE_SGE_TPA:
1269 return CHANNEL_TLV_VPORT_UPDATE_SGE_TPA;
1275 static u16 qed_iov_prep_vp_update_resp_tlvs(struct qed_hwfn *p_hwfn,
1276 struct qed_vf_info *p_vf,
1277 struct qed_iov_vf_mbx *p_mbx,
1279 u16 tlvs_mask, u16 tlvs_accepted)
1281 struct pfvf_def_resp_tlv *resp;
1282 u16 size, total_len, i;
1284 memset(p_mbx->reply_virt, 0, sizeof(union pfvf_tlvs));
1285 p_mbx->offset = (u8 *)p_mbx->reply_virt;
1286 size = sizeof(struct pfvf_def_resp_tlv);
1289 qed_add_tlv(p_hwfn, &p_mbx->offset, CHANNEL_TLV_VPORT_UPDATE, size);
1291 /* Prepare response for all extended tlvs if they are found by PF */
1292 for (i = 0; i < QED_IOV_VP_UPDATE_MAX; i++) {
1293 if (!(tlvs_mask & BIT(i)))
1296 resp = qed_add_tlv(p_hwfn, &p_mbx->offset,
1297 qed_iov_vport_to_tlv(p_hwfn, i), size);
1299 if (tlvs_accepted & BIT(i))
1300 resp->hdr.status = status;
1302 resp->hdr.status = PFVF_STATUS_NOT_SUPPORTED;
1306 "VF[%d] - vport_update response: TLV %d, status %02x\n",
1307 p_vf->relative_vf_id,
1308 qed_iov_vport_to_tlv(p_hwfn, i), resp->hdr.status);
1313 qed_add_tlv(p_hwfn, &p_mbx->offset, CHANNEL_TLV_LIST_END,
1314 sizeof(struct channel_list_end_tlv));
1319 static void qed_iov_prepare_resp(struct qed_hwfn *p_hwfn,
1320 struct qed_ptt *p_ptt,
1321 struct qed_vf_info *vf_info,
1322 u16 type, u16 length, u8 status)
1324 struct qed_iov_vf_mbx *mbx = &vf_info->vf_mbx;
1326 mbx->offset = (u8 *)mbx->reply_virt;
1328 qed_add_tlv(p_hwfn, &mbx->offset, type, length);
1329 qed_add_tlv(p_hwfn, &mbx->offset, CHANNEL_TLV_LIST_END,
1330 sizeof(struct channel_list_end_tlv));
1332 qed_iov_send_response(p_hwfn, p_ptt, vf_info, length, status);
1336 qed_public_vf_info *qed_iov_get_public_vf_info(struct qed_hwfn *p_hwfn,
1338 bool b_enabled_only)
1340 struct qed_vf_info *vf = NULL;
1342 vf = qed_iov_get_vf_info(p_hwfn, relative_vf_id, b_enabled_only);
1346 return &vf->p_vf_info;
1349 static void qed_iov_clean_vf(struct qed_hwfn *p_hwfn, u8 vfid)
1351 struct qed_public_vf_info *vf_info;
1353 vf_info = qed_iov_get_public_vf_info(p_hwfn, vfid, false);
1358 /* Clear the VF mac */
1359 eth_zero_addr(vf_info->mac);
1361 vf_info->rx_accept_mode = 0;
1362 vf_info->tx_accept_mode = 0;
1365 static void qed_iov_vf_cleanup(struct qed_hwfn *p_hwfn,
1366 struct qed_vf_info *p_vf)
1370 p_vf->vf_bulletin = 0;
1371 p_vf->vport_instance = 0;
1372 p_vf->configured_features = 0;
1374 /* If VF previously requested less resources, go back to default */
1375 p_vf->num_rxqs = p_vf->num_sbs;
1376 p_vf->num_txqs = p_vf->num_sbs;
1378 p_vf->num_active_rxqs = 0;
1380 for (i = 0; i < QED_MAX_VF_CHAINS_PER_PF; i++) {
1381 struct qed_vf_queue *p_queue = &p_vf->vf_queues[i];
1383 for (j = 0; j < MAX_QUEUES_PER_QZONE; j++) {
1384 if (!p_queue->cids[j].p_cid)
1387 qed_eth_queue_cid_release(p_hwfn,
1388 p_queue->cids[j].p_cid);
1389 p_queue->cids[j].p_cid = NULL;
1393 memset(&p_vf->shadow_config, 0, sizeof(p_vf->shadow_config));
1394 memset(&p_vf->acquire, 0, sizeof(p_vf->acquire));
1395 qed_iov_clean_vf(p_hwfn, p_vf->relative_vf_id);
1398 /* Returns either 0, or log(size) */
1399 static u32 qed_iov_vf_db_bar_size(struct qed_hwfn *p_hwfn,
1400 struct qed_ptt *p_ptt)
1402 u32 val = qed_rd(p_hwfn, p_ptt, PGLUE_B_REG_VF_BAR1_SIZE);
1410 qed_iov_vf_mbx_acquire_resc_cids(struct qed_hwfn *p_hwfn,
1411 struct qed_ptt *p_ptt,
1412 struct qed_vf_info *p_vf,
1413 struct vf_pf_resc_request *p_req,
1414 struct pf_vf_resc *p_resp)
1416 u8 num_vf_cons = p_hwfn->pf_params.eth_pf_params.num_vf_cons;
1417 u8 db_size = qed_db_addr_vf(1, DQ_DEMS_LEGACY) -
1418 qed_db_addr_vf(0, DQ_DEMS_LEGACY);
1421 p_resp->num_cids = min_t(u8, p_req->num_cids, num_vf_cons);
1423 /* If VF didn't bother asking for QIDs than don't bother limiting
1424 * number of CIDs. The VF doesn't care about the number, and this
1425 * has the likely result of causing an additional acquisition.
1427 if (!(p_vf->acquire.vfdev_info.capabilities &
1428 VFPF_ACQUIRE_CAP_QUEUE_QIDS))
1431 /* If doorbell bar was mapped by VF, limit the VF CIDs to an amount
1432 * that would make sure doorbells for all CIDs fall within the bar.
1433 * If it doesn't, make sure regview window is sufficient.
1435 if (p_vf->acquire.vfdev_info.capabilities &
1436 VFPF_ACQUIRE_CAP_PHYSICAL_BAR) {
1437 bar_size = qed_iov_vf_db_bar_size(p_hwfn, p_ptt);
1439 bar_size = 1 << bar_size;
1441 if (p_hwfn->cdev->num_hwfns > 1)
1444 bar_size = PXP_VF_BAR0_DQ_LENGTH;
1447 if (bar_size / db_size < 256)
1448 p_resp->num_cids = min_t(u8, p_resp->num_cids,
1449 (u8)(bar_size / db_size));
1452 static u8 qed_iov_vf_mbx_acquire_resc(struct qed_hwfn *p_hwfn,
1453 struct qed_ptt *p_ptt,
1454 struct qed_vf_info *p_vf,
1455 struct vf_pf_resc_request *p_req,
1456 struct pf_vf_resc *p_resp)
1460 /* Queue related information */
1461 p_resp->num_rxqs = p_vf->num_rxqs;
1462 p_resp->num_txqs = p_vf->num_txqs;
1463 p_resp->num_sbs = p_vf->num_sbs;
1465 for (i = 0; i < p_resp->num_sbs; i++) {
1466 p_resp->hw_sbs[i].hw_sb_id = p_vf->igu_sbs[i];
1467 p_resp->hw_sbs[i].sb_qid = 0;
1470 /* These fields are filled for backward compatibility.
1471 * Unused by modern vfs.
1473 for (i = 0; i < p_resp->num_rxqs; i++) {
1474 qed_fw_l2_queue(p_hwfn, p_vf->vf_queues[i].fw_rx_qid,
1475 (u16 *)&p_resp->hw_qid[i]);
1479 /* Filter related information */
1480 p_resp->num_mac_filters = min_t(u8, p_vf->num_mac_filters,
1481 p_req->num_mac_filters);
1482 p_resp->num_vlan_filters = min_t(u8, p_vf->num_vlan_filters,
1483 p_req->num_vlan_filters);
1485 qed_iov_vf_mbx_acquire_resc_cids(p_hwfn, p_ptt, p_vf, p_req, p_resp);
1487 /* This isn't really needed/enforced, but some legacy VFs might depend
1488 * on the correct filling of this field.
1490 p_resp->num_mc_filters = QED_MAX_MC_ADDRS;
1492 /* Validate sufficient resources for VF */
1493 if (p_resp->num_rxqs < p_req->num_rxqs ||
1494 p_resp->num_txqs < p_req->num_txqs ||
1495 p_resp->num_sbs < p_req->num_sbs ||
1496 p_resp->num_mac_filters < p_req->num_mac_filters ||
1497 p_resp->num_vlan_filters < p_req->num_vlan_filters ||
1498 p_resp->num_mc_filters < p_req->num_mc_filters ||
1499 p_resp->num_cids < p_req->num_cids) {
1502 "VF[%d] - Insufficient resources: rxq [%02x/%02x] txq [%02x/%02x] sbs [%02x/%02x] mac [%02x/%02x] vlan [%02x/%02x] mc [%02x/%02x] cids [%02x/%02x]\n",
1510 p_req->num_mac_filters,
1511 p_resp->num_mac_filters,
1512 p_req->num_vlan_filters,
1513 p_resp->num_vlan_filters,
1514 p_req->num_mc_filters,
1515 p_resp->num_mc_filters,
1516 p_req->num_cids, p_resp->num_cids);
1518 /* Some legacy OSes are incapable of correctly handling this
1521 if ((p_vf->acquire.vfdev_info.eth_fp_hsi_minor ==
1522 ETH_HSI_VER_NO_PKT_LEN_TUNN) &&
1523 (p_vf->acquire.vfdev_info.os_type ==
1524 VFPF_ACQUIRE_OS_WINDOWS))
1525 return PFVF_STATUS_SUCCESS;
1527 return PFVF_STATUS_NO_RESOURCE;
1530 return PFVF_STATUS_SUCCESS;
1533 static void qed_iov_vf_mbx_acquire_stats(struct qed_hwfn *p_hwfn,
1534 struct pfvf_stats_info *p_stats)
1536 p_stats->mstats.address = PXP_VF_BAR0_START_MSDM_ZONE_B +
1537 offsetof(struct mstorm_vf_zone,
1538 non_trigger.eth_queue_stat);
1539 p_stats->mstats.len = sizeof(struct eth_mstorm_per_queue_stat);
1540 p_stats->ustats.address = PXP_VF_BAR0_START_USDM_ZONE_B +
1541 offsetof(struct ustorm_vf_zone,
1542 non_trigger.eth_queue_stat);
1543 p_stats->ustats.len = sizeof(struct eth_ustorm_per_queue_stat);
1544 p_stats->pstats.address = PXP_VF_BAR0_START_PSDM_ZONE_B +
1545 offsetof(struct pstorm_vf_zone,
1546 non_trigger.eth_queue_stat);
1547 p_stats->pstats.len = sizeof(struct eth_pstorm_per_queue_stat);
1548 p_stats->tstats.address = 0;
1549 p_stats->tstats.len = 0;
1552 static void qed_iov_vf_mbx_acquire(struct qed_hwfn *p_hwfn,
1553 struct qed_ptt *p_ptt,
1554 struct qed_vf_info *vf)
1556 struct qed_iov_vf_mbx *mbx = &vf->vf_mbx;
1557 struct pfvf_acquire_resp_tlv *resp = &mbx->reply_virt->acquire_resp;
1558 struct pf_vf_pfdev_info *pfdev_info = &resp->pfdev_info;
1559 struct vfpf_acquire_tlv *req = &mbx->req_virt->acquire;
1560 u8 vfpf_status = PFVF_STATUS_NOT_SUPPORTED;
1561 struct pf_vf_resc *resc = &resp->resc;
1564 memset(resp, 0, sizeof(*resp));
1566 /* Write the PF version so that VF would know which version
1567 * is supported - might be later overriden. This guarantees that
1568 * VF could recognize legacy PF based on lack of versions in reply.
1570 pfdev_info->major_fp_hsi = ETH_HSI_VER_MAJOR;
1571 pfdev_info->minor_fp_hsi = ETH_HSI_VER_MINOR;
1573 if (vf->state != VF_FREE && vf->state != VF_STOPPED) {
1576 "VF[%d] sent ACQUIRE but is already in state %d - fail request\n",
1577 vf->abs_vf_id, vf->state);
1581 /* Validate FW compatibility */
1582 if (req->vfdev_info.eth_fp_hsi_major != ETH_HSI_VER_MAJOR) {
1583 if (req->vfdev_info.capabilities &
1584 VFPF_ACQUIRE_CAP_PRE_FP_HSI) {
1585 struct vf_pf_vfdev_info *p_vfdev = &req->vfdev_info;
1587 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
1588 "VF[%d] is pre-fastpath HSI\n",
1590 p_vfdev->eth_fp_hsi_major = ETH_HSI_VER_MAJOR;
1591 p_vfdev->eth_fp_hsi_minor = ETH_HSI_VER_NO_PKT_LEN_TUNN;
1594 "VF[%d] needs fastpath HSI %02x.%02x, which is incompatible with loaded FW's faspath HSI %02x.%02x\n",
1596 req->vfdev_info.eth_fp_hsi_major,
1597 req->vfdev_info.eth_fp_hsi_minor,
1598 ETH_HSI_VER_MAJOR, ETH_HSI_VER_MINOR);
1604 /* On 100g PFs, prevent old VFs from loading */
1605 if ((p_hwfn->cdev->num_hwfns > 1) &&
1606 !(req->vfdev_info.capabilities & VFPF_ACQUIRE_CAP_100G)) {
1608 "VF[%d] is running an old driver that doesn't support 100g\n",
1613 /* Store the acquire message */
1614 memcpy(&vf->acquire, req, sizeof(vf->acquire));
1616 vf->opaque_fid = req->vfdev_info.opaque_fid;
1618 vf->vf_bulletin = req->bulletin_addr;
1619 vf->bulletin.size = (vf->bulletin.size < req->bulletin_size) ?
1620 vf->bulletin.size : req->bulletin_size;
1622 /* fill in pfdev info */
1623 pfdev_info->chip_num = p_hwfn->cdev->chip_num;
1624 pfdev_info->db_size = 0;
1625 pfdev_info->indices_per_sb = PIS_PER_SB_E4;
1627 pfdev_info->capabilities = PFVF_ACQUIRE_CAP_DEFAULT_UNTAGGED |
1628 PFVF_ACQUIRE_CAP_POST_FW_OVERRIDE;
1629 if (p_hwfn->cdev->num_hwfns > 1)
1630 pfdev_info->capabilities |= PFVF_ACQUIRE_CAP_100G;
1632 /* Share our ability to use multiple queue-ids only with VFs
1635 if (req->vfdev_info.capabilities & VFPF_ACQUIRE_CAP_QUEUE_QIDS)
1636 pfdev_info->capabilities |= PFVF_ACQUIRE_CAP_QUEUE_QIDS;
1638 /* Share the sizes of the bars with VF */
1639 resp->pfdev_info.bar_size = qed_iov_vf_db_bar_size(p_hwfn, p_ptt);
1641 qed_iov_vf_mbx_acquire_stats(p_hwfn, &pfdev_info->stats_info);
1643 memcpy(pfdev_info->port_mac, p_hwfn->hw_info.hw_mac_addr, ETH_ALEN);
1645 pfdev_info->fw_major = FW_MAJOR_VERSION;
1646 pfdev_info->fw_minor = FW_MINOR_VERSION;
1647 pfdev_info->fw_rev = FW_REVISION_VERSION;
1648 pfdev_info->fw_eng = FW_ENGINEERING_VERSION;
1650 /* Incorrect when legacy, but doesn't matter as legacy isn't reading
1653 pfdev_info->minor_fp_hsi = min_t(u8, ETH_HSI_VER_MINOR,
1654 req->vfdev_info.eth_fp_hsi_minor);
1655 pfdev_info->os_type = VFPF_ACQUIRE_OS_LINUX;
1656 qed_mcp_get_mfw_ver(p_hwfn, p_ptt, &pfdev_info->mfw_ver, NULL);
1658 pfdev_info->dev_type = p_hwfn->cdev->type;
1659 pfdev_info->chip_rev = p_hwfn->cdev->chip_rev;
1661 /* Fill resources available to VF; Make sure there are enough to
1662 * satisfy the VF's request.
1664 vfpf_status = qed_iov_vf_mbx_acquire_resc(p_hwfn, p_ptt, vf,
1665 &req->resc_request, resc);
1666 if (vfpf_status != PFVF_STATUS_SUCCESS)
1669 /* Start the VF in FW */
1670 rc = qed_sp_vf_start(p_hwfn, vf);
1672 DP_NOTICE(p_hwfn, "Failed to start VF[%02x]\n", vf->abs_vf_id);
1673 vfpf_status = PFVF_STATUS_FAILURE;
1677 /* Fill agreed size of bulletin board in response */
1678 resp->bulletin_size = vf->bulletin.size;
1679 qed_iov_post_vf_bulletin(p_hwfn, vf->relative_vf_id, p_ptt);
1683 "VF[%d] ACQUIRE_RESPONSE: pfdev_info- chip_num=0x%x, db_size=%d, idx_per_sb=%d, pf_cap=0x%llx\n"
1684 "resources- n_rxq-%d, n_txq-%d, n_sbs-%d, n_macs-%d, n_vlans-%d\n",
1686 resp->pfdev_info.chip_num,
1687 resp->pfdev_info.db_size,
1688 resp->pfdev_info.indices_per_sb,
1689 resp->pfdev_info.capabilities,
1693 resc->num_mac_filters,
1694 resc->num_vlan_filters);
1695 vf->state = VF_ACQUIRED;
1697 /* Prepare Response */
1699 qed_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_ACQUIRE,
1700 sizeof(struct pfvf_acquire_resp_tlv), vfpf_status);
1703 static int __qed_iov_spoofchk_set(struct qed_hwfn *p_hwfn,
1704 struct qed_vf_info *p_vf, bool val)
1706 struct qed_sp_vport_update_params params;
1709 if (val == p_vf->spoof_chk) {
1710 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
1711 "Spoofchk value[%d] is already configured\n", val);
1715 memset(¶ms, 0, sizeof(struct qed_sp_vport_update_params));
1716 params.opaque_fid = p_vf->opaque_fid;
1717 params.vport_id = p_vf->vport_id;
1718 params.update_anti_spoofing_en_flg = 1;
1719 params.anti_spoofing_en = val;
1721 rc = qed_sp_vport_update(p_hwfn, ¶ms, QED_SPQ_MODE_EBLOCK, NULL);
1723 p_vf->spoof_chk = val;
1724 p_vf->req_spoofchk_val = p_vf->spoof_chk;
1725 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
1726 "Spoofchk val[%d] configured\n", val);
1728 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
1729 "Spoofchk configuration[val:%d] failed for VF[%d]\n",
1730 val, p_vf->relative_vf_id);
1736 static int qed_iov_reconfigure_unicast_vlan(struct qed_hwfn *p_hwfn,
1737 struct qed_vf_info *p_vf)
1739 struct qed_filter_ucast filter;
1743 memset(&filter, 0, sizeof(filter));
1744 filter.is_rx_filter = 1;
1745 filter.is_tx_filter = 1;
1746 filter.vport_to_add_to = p_vf->vport_id;
1747 filter.opcode = QED_FILTER_ADD;
1749 /* Reconfigure vlans */
1750 for (i = 0; i < QED_ETH_VF_NUM_VLAN_FILTERS + 1; i++) {
1751 if (!p_vf->shadow_config.vlans[i].used)
1754 filter.type = QED_FILTER_VLAN;
1755 filter.vlan = p_vf->shadow_config.vlans[i].vid;
1756 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
1757 "Reconfiguring VLAN [0x%04x] for VF [%04x]\n",
1758 filter.vlan, p_vf->relative_vf_id);
1759 rc = qed_sp_eth_filter_ucast(p_hwfn, p_vf->opaque_fid,
1760 &filter, QED_SPQ_MODE_CB, NULL);
1763 "Failed to configure VLAN [%04x] to VF [%04x]\n",
1764 filter.vlan, p_vf->relative_vf_id);
1773 qed_iov_reconfigure_unicast_shadow(struct qed_hwfn *p_hwfn,
1774 struct qed_vf_info *p_vf, u64 events)
1778 if ((events & BIT(VLAN_ADDR_FORCED)) &&
1779 !(p_vf->configured_features & (1 << VLAN_ADDR_FORCED)))
1780 rc = qed_iov_reconfigure_unicast_vlan(p_hwfn, p_vf);
1785 static int qed_iov_configure_vport_forced(struct qed_hwfn *p_hwfn,
1786 struct qed_vf_info *p_vf, u64 events)
1789 struct qed_filter_ucast filter;
1791 if (!p_vf->vport_instance)
1794 if ((events & BIT(MAC_ADDR_FORCED)) ||
1795 p_vf->p_vf_info.is_trusted_configured) {
1796 /* Since there's no way [currently] of removing the MAC,
1797 * we can always assume this means we need to force it.
1799 memset(&filter, 0, sizeof(filter));
1800 filter.type = QED_FILTER_MAC;
1801 filter.opcode = QED_FILTER_REPLACE;
1802 filter.is_rx_filter = 1;
1803 filter.is_tx_filter = 1;
1804 filter.vport_to_add_to = p_vf->vport_id;
1805 ether_addr_copy(filter.mac, p_vf->bulletin.p_virt->mac);
1807 rc = qed_sp_eth_filter_ucast(p_hwfn, p_vf->opaque_fid,
1808 &filter, QED_SPQ_MODE_CB, NULL);
1811 "PF failed to configure MAC for VF\n");
1814 if (p_vf->p_vf_info.is_trusted_configured)
1815 p_vf->configured_features |=
1816 BIT(VFPF_BULLETIN_MAC_ADDR);
1818 p_vf->configured_features |=
1819 BIT(MAC_ADDR_FORCED);
1822 if (events & BIT(VLAN_ADDR_FORCED)) {
1823 struct qed_sp_vport_update_params vport_update;
1827 memset(&filter, 0, sizeof(filter));
1828 filter.type = QED_FILTER_VLAN;
1829 filter.is_rx_filter = 1;
1830 filter.is_tx_filter = 1;
1831 filter.vport_to_add_to = p_vf->vport_id;
1832 filter.vlan = p_vf->bulletin.p_virt->pvid;
1833 filter.opcode = filter.vlan ? QED_FILTER_REPLACE :
1836 /* Send the ramrod */
1837 rc = qed_sp_eth_filter_ucast(p_hwfn, p_vf->opaque_fid,
1838 &filter, QED_SPQ_MODE_CB, NULL);
1841 "PF failed to configure VLAN for VF\n");
1845 /* Update the default-vlan & silent vlan stripping */
1846 memset(&vport_update, 0, sizeof(vport_update));
1847 vport_update.opaque_fid = p_vf->opaque_fid;
1848 vport_update.vport_id = p_vf->vport_id;
1849 vport_update.update_default_vlan_enable_flg = 1;
1850 vport_update.default_vlan_enable_flg = filter.vlan ? 1 : 0;
1851 vport_update.update_default_vlan_flg = 1;
1852 vport_update.default_vlan = filter.vlan;
1854 vport_update.update_inner_vlan_removal_flg = 1;
1855 removal = filter.vlan ? 1
1856 : p_vf->shadow_config.inner_vlan_removal;
1857 vport_update.inner_vlan_removal_flg = removal;
1858 vport_update.silent_vlan_removal_flg = filter.vlan ? 1 : 0;
1859 rc = qed_sp_vport_update(p_hwfn,
1861 QED_SPQ_MODE_EBLOCK, NULL);
1864 "PF failed to configure VF vport for vlan\n");
1868 /* Update all the Rx queues */
1869 for (i = 0; i < QED_MAX_VF_CHAINS_PER_PF; i++) {
1870 struct qed_vf_queue *p_queue = &p_vf->vf_queues[i];
1871 struct qed_queue_cid *p_cid = NULL;
1873 /* There can be at most 1 Rx queue on qzone. Find it */
1874 p_cid = qed_iov_get_vf_rx_queue_cid(p_queue);
1878 rc = qed_sp_eth_rx_queues_update(p_hwfn,
1881 QED_SPQ_MODE_EBLOCK,
1885 "Failed to send Rx update fo queue[0x%04x]\n",
1886 p_cid->rel.queue_id);
1892 p_vf->configured_features |= 1 << VLAN_ADDR_FORCED;
1894 p_vf->configured_features &= ~BIT(VLAN_ADDR_FORCED);
1897 /* If forced features are terminated, we need to configure the shadow
1898 * configuration back again.
1901 qed_iov_reconfigure_unicast_shadow(p_hwfn, p_vf, events);
1906 static void qed_iov_vf_mbx_start_vport(struct qed_hwfn *p_hwfn,
1907 struct qed_ptt *p_ptt,
1908 struct qed_vf_info *vf)
1910 struct qed_sp_vport_start_params params = { 0 };
1911 struct qed_iov_vf_mbx *mbx = &vf->vf_mbx;
1912 struct vfpf_vport_start_tlv *start;
1913 u8 status = PFVF_STATUS_SUCCESS;
1914 struct qed_vf_info *vf_info;
1919 vf_info = qed_iov_get_vf_info(p_hwfn, (u16) vf->relative_vf_id, true);
1921 DP_NOTICE(p_hwfn->cdev,
1922 "Failed to get VF info, invalid vfid [%d]\n",
1923 vf->relative_vf_id);
1927 vf->state = VF_ENABLED;
1928 start = &mbx->req_virt->start_vport;
1930 qed_iov_enable_vf_traffic(p_hwfn, p_ptt, vf);
1932 /* Initialize Status block in CAU */
1933 for (sb_id = 0; sb_id < vf->num_sbs; sb_id++) {
1934 if (!start->sb_addr[sb_id]) {
1935 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
1936 "VF[%d] did not fill the address of SB %d\n",
1937 vf->relative_vf_id, sb_id);
1941 qed_int_cau_conf_sb(p_hwfn, p_ptt,
1942 start->sb_addr[sb_id],
1943 vf->igu_sbs[sb_id], vf->abs_vf_id, 1);
1946 vf->mtu = start->mtu;
1947 vf->shadow_config.inner_vlan_removal = start->inner_vlan_removal;
1949 /* Take into consideration configuration forced by hypervisor;
1950 * If none is configured, use the supplied VF values [for old
1951 * vfs that would still be fine, since they passed '0' as padding].
1953 p_bitmap = &vf_info->bulletin.p_virt->valid_bitmap;
1954 if (!(*p_bitmap & BIT(VFPF_BULLETIN_UNTAGGED_DEFAULT_FORCED))) {
1955 u8 vf_req = start->only_untagged;
1957 vf_info->bulletin.p_virt->default_only_untagged = vf_req;
1958 *p_bitmap |= 1 << VFPF_BULLETIN_UNTAGGED_DEFAULT;
1961 params.tpa_mode = start->tpa_mode;
1962 params.remove_inner_vlan = start->inner_vlan_removal;
1963 params.tx_switching = true;
1965 params.only_untagged = vf_info->bulletin.p_virt->default_only_untagged;
1966 params.drop_ttl0 = false;
1967 params.concrete_fid = vf->concrete_fid;
1968 params.opaque_fid = vf->opaque_fid;
1969 params.vport_id = vf->vport_id;
1970 params.max_buffers_per_cqe = start->max_buffers_per_cqe;
1971 params.mtu = vf->mtu;
1972 params.check_mac = true;
1974 rc = qed_sp_eth_vport_start(p_hwfn, ¶ms);
1977 "qed_iov_vf_mbx_start_vport returned error %d\n", rc);
1978 status = PFVF_STATUS_FAILURE;
1980 vf->vport_instance++;
1982 /* Force configuration if needed on the newly opened vport */
1983 qed_iov_configure_vport_forced(p_hwfn, vf, *p_bitmap);
1985 __qed_iov_spoofchk_set(p_hwfn, vf, vf->req_spoofchk_val);
1987 qed_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_VPORT_START,
1988 sizeof(struct pfvf_def_resp_tlv), status);
1991 static void qed_iov_vf_mbx_stop_vport(struct qed_hwfn *p_hwfn,
1992 struct qed_ptt *p_ptt,
1993 struct qed_vf_info *vf)
1995 u8 status = PFVF_STATUS_SUCCESS;
1998 vf->vport_instance--;
1999 vf->spoof_chk = false;
2001 if ((qed_iov_validate_active_rxq(p_hwfn, vf)) ||
2002 (qed_iov_validate_active_txq(p_hwfn, vf))) {
2003 vf->b_malicious = true;
2005 "VF [%02x] - considered malicious; Unable to stop RX/TX queuess\n",
2007 status = PFVF_STATUS_MALICIOUS;
2011 rc = qed_sp_vport_stop(p_hwfn, vf->opaque_fid, vf->vport_id);
2013 DP_ERR(p_hwfn, "qed_iov_vf_mbx_stop_vport returned error %d\n",
2015 status = PFVF_STATUS_FAILURE;
2018 /* Forget the configuration on the vport */
2019 vf->configured_features = 0;
2020 memset(&vf->shadow_config, 0, sizeof(vf->shadow_config));
2023 qed_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_VPORT_TEARDOWN,
2024 sizeof(struct pfvf_def_resp_tlv), status);
2027 static void qed_iov_vf_mbx_start_rxq_resp(struct qed_hwfn *p_hwfn,
2028 struct qed_ptt *p_ptt,
2029 struct qed_vf_info *vf,
2030 u8 status, bool b_legacy)
2032 struct qed_iov_vf_mbx *mbx = &vf->vf_mbx;
2033 struct pfvf_start_queue_resp_tlv *p_tlv;
2034 struct vfpf_start_rxq_tlv *req;
2037 mbx->offset = (u8 *)mbx->reply_virt;
2039 /* Taking a bigger struct instead of adding a TLV to list was a
2040 * mistake, but one which we're now stuck with, as some older
2041 * clients assume the size of the previous response.
2044 length = sizeof(*p_tlv);
2046 length = sizeof(struct pfvf_def_resp_tlv);
2048 p_tlv = qed_add_tlv(p_hwfn, &mbx->offset, CHANNEL_TLV_START_RXQ,
2050 qed_add_tlv(p_hwfn, &mbx->offset, CHANNEL_TLV_LIST_END,
2051 sizeof(struct channel_list_end_tlv));
2053 /* Update the TLV with the response */
2054 if ((status == PFVF_STATUS_SUCCESS) && !b_legacy) {
2055 req = &mbx->req_virt->start_rxq;
2056 p_tlv->offset = PXP_VF_BAR0_START_MSDM_ZONE_B +
2057 offsetof(struct mstorm_vf_zone,
2058 non_trigger.eth_rx_queue_producers) +
2059 sizeof(struct eth_rx_prod_data) * req->rx_qid;
2062 qed_iov_send_response(p_hwfn, p_ptt, vf, length, status);
2065 static u8 qed_iov_vf_mbx_qid(struct qed_hwfn *p_hwfn,
2066 struct qed_vf_info *p_vf, bool b_is_tx)
2068 struct qed_iov_vf_mbx *p_mbx = &p_vf->vf_mbx;
2069 struct vfpf_qid_tlv *p_qid_tlv;
2071 /* Search for the qid if the VF published its going to provide it */
2072 if (!(p_vf->acquire.vfdev_info.capabilities &
2073 VFPF_ACQUIRE_CAP_QUEUE_QIDS)) {
2075 return QED_IOV_LEGACY_QID_TX;
2077 return QED_IOV_LEGACY_QID_RX;
2080 p_qid_tlv = (struct vfpf_qid_tlv *)
2081 qed_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt,
2084 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
2085 "VF[%2x]: Failed to provide qid\n",
2086 p_vf->relative_vf_id);
2088 return QED_IOV_QID_INVALID;
2091 if (p_qid_tlv->qid >= MAX_QUEUES_PER_QZONE) {
2092 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
2093 "VF[%02x]: Provided qid out-of-bounds %02x\n",
2094 p_vf->relative_vf_id, p_qid_tlv->qid);
2095 return QED_IOV_QID_INVALID;
2098 return p_qid_tlv->qid;
2101 static void qed_iov_vf_mbx_start_rxq(struct qed_hwfn *p_hwfn,
2102 struct qed_ptt *p_ptt,
2103 struct qed_vf_info *vf)
2105 struct qed_queue_start_common_params params;
2106 struct qed_queue_cid_vf_params vf_params;
2107 struct qed_iov_vf_mbx *mbx = &vf->vf_mbx;
2108 u8 status = PFVF_STATUS_NO_RESOURCE;
2109 u8 qid_usage_idx, vf_legacy = 0;
2110 struct vfpf_start_rxq_tlv *req;
2111 struct qed_vf_queue *p_queue;
2112 struct qed_queue_cid *p_cid;
2113 struct qed_sb_info sb_dummy;
2116 req = &mbx->req_virt->start_rxq;
2118 if (!qed_iov_validate_rxq(p_hwfn, vf, req->rx_qid,
2119 QED_IOV_VALIDATE_Q_DISABLE) ||
2120 !qed_iov_validate_sb(p_hwfn, vf, req->hw_sb))
2123 qid_usage_idx = qed_iov_vf_mbx_qid(p_hwfn, vf, false);
2124 if (qid_usage_idx == QED_IOV_QID_INVALID)
2127 p_queue = &vf->vf_queues[req->rx_qid];
2128 if (p_queue->cids[qid_usage_idx].p_cid)
2131 vf_legacy = qed_vf_calculate_legacy(vf);
2133 /* Acquire a new queue-cid */
2134 memset(¶ms, 0, sizeof(params));
2135 params.queue_id = p_queue->fw_rx_qid;
2136 params.vport_id = vf->vport_id;
2137 params.stats_id = vf->abs_vf_id + 0x10;
2138 /* Since IGU index is passed via sb_info, construct a dummy one */
2139 memset(&sb_dummy, 0, sizeof(sb_dummy));
2140 sb_dummy.igu_sb_id = req->hw_sb;
2141 params.p_sb = &sb_dummy;
2142 params.sb_idx = req->sb_index;
2144 memset(&vf_params, 0, sizeof(vf_params));
2145 vf_params.vfid = vf->relative_vf_id;
2146 vf_params.vf_qid = (u8)req->rx_qid;
2147 vf_params.vf_legacy = vf_legacy;
2148 vf_params.qid_usage_idx = qid_usage_idx;
2149 p_cid = qed_eth_queue_to_cid(p_hwfn, vf->opaque_fid,
2150 ¶ms, true, &vf_params);
2154 /* Legacy VFs have their Producers in a different location, which they
2155 * calculate on their own and clean the producer prior to this.
2157 if (!(vf_legacy & QED_QCID_LEGACY_VF_RX_PROD))
2159 GTT_BAR0_MAP_REG_MSDM_RAM +
2160 MSTORM_ETH_VF_PRODS_OFFSET(vf->abs_vf_id, req->rx_qid),
2163 rc = qed_eth_rxq_start_ramrod(p_hwfn, p_cid,
2166 req->cqe_pbl_addr, req->cqe_pbl_size);
2168 status = PFVF_STATUS_FAILURE;
2169 qed_eth_queue_cid_release(p_hwfn, p_cid);
2171 p_queue->cids[qid_usage_idx].p_cid = p_cid;
2172 p_queue->cids[qid_usage_idx].b_is_tx = false;
2173 status = PFVF_STATUS_SUCCESS;
2174 vf->num_active_rxqs++;
2178 qed_iov_vf_mbx_start_rxq_resp(p_hwfn, p_ptt, vf, status,
2180 QED_QCID_LEGACY_VF_RX_PROD));
2184 qed_iov_pf_update_tun_response(struct pfvf_update_tunn_param_tlv *p_resp,
2185 struct qed_tunnel_info *p_tun,
2186 u16 tunn_feature_mask)
2188 p_resp->tunn_feature_mask = tunn_feature_mask;
2189 p_resp->vxlan_mode = p_tun->vxlan.b_mode_enabled;
2190 p_resp->l2geneve_mode = p_tun->l2_geneve.b_mode_enabled;
2191 p_resp->ipgeneve_mode = p_tun->ip_geneve.b_mode_enabled;
2192 p_resp->l2gre_mode = p_tun->l2_gre.b_mode_enabled;
2193 p_resp->ipgre_mode = p_tun->l2_gre.b_mode_enabled;
2194 p_resp->vxlan_clss = p_tun->vxlan.tun_cls;
2195 p_resp->l2gre_clss = p_tun->l2_gre.tun_cls;
2196 p_resp->ipgre_clss = p_tun->ip_gre.tun_cls;
2197 p_resp->l2geneve_clss = p_tun->l2_geneve.tun_cls;
2198 p_resp->ipgeneve_clss = p_tun->ip_geneve.tun_cls;
2199 p_resp->geneve_udp_port = p_tun->geneve_port.port;
2200 p_resp->vxlan_udp_port = p_tun->vxlan_port.port;
2204 __qed_iov_pf_update_tun_param(struct vfpf_update_tunn_param_tlv *p_req,
2205 struct qed_tunn_update_type *p_tun,
2206 enum qed_tunn_mode mask, u8 tun_cls)
2208 if (p_req->tun_mode_update_mask & BIT(mask)) {
2209 p_tun->b_update_mode = true;
2211 if (p_req->tunn_mode & BIT(mask))
2212 p_tun->b_mode_enabled = true;
2215 p_tun->tun_cls = tun_cls;
2219 qed_iov_pf_update_tun_param(struct vfpf_update_tunn_param_tlv *p_req,
2220 struct qed_tunn_update_type *p_tun,
2221 struct qed_tunn_update_udp_port *p_port,
2222 enum qed_tunn_mode mask,
2223 u8 tun_cls, u8 update_port, u16 port)
2226 p_port->b_update_port = true;
2227 p_port->port = port;
2230 __qed_iov_pf_update_tun_param(p_req, p_tun, mask, tun_cls);
2234 qed_iov_pf_validate_tunn_param(struct vfpf_update_tunn_param_tlv *p_req)
2236 bool b_update_requested = false;
2238 if (p_req->tun_mode_update_mask || p_req->update_tun_cls ||
2239 p_req->update_geneve_port || p_req->update_vxlan_port)
2240 b_update_requested = true;
2242 return b_update_requested;
2245 static void qed_pf_validate_tunn_mode(struct qed_tunn_update_type *tun, int *rc)
2247 if (tun->b_update_mode && !tun->b_mode_enabled) {
2248 tun->b_update_mode = false;
2254 qed_pf_validate_modify_tunn_config(struct qed_hwfn *p_hwfn,
2255 u16 *tun_features, bool *update,
2256 struct qed_tunnel_info *tun_src)
2258 struct qed_eth_cb_ops *ops = p_hwfn->cdev->protocol_ops.eth;
2259 struct qed_tunnel_info *tun = &p_hwfn->cdev->tunnel;
2260 u16 bultn_vxlan_port, bultn_geneve_port;
2261 void *cookie = p_hwfn->cdev->ops_cookie;
2264 *tun_features = p_hwfn->cdev->tunn_feature_mask;
2265 bultn_vxlan_port = tun->vxlan_port.port;
2266 bultn_geneve_port = tun->geneve_port.port;
2267 qed_pf_validate_tunn_mode(&tun_src->vxlan, &rc);
2268 qed_pf_validate_tunn_mode(&tun_src->l2_geneve, &rc);
2269 qed_pf_validate_tunn_mode(&tun_src->ip_geneve, &rc);
2270 qed_pf_validate_tunn_mode(&tun_src->l2_gre, &rc);
2271 qed_pf_validate_tunn_mode(&tun_src->ip_gre, &rc);
2273 if ((tun_src->b_update_rx_cls || tun_src->b_update_tx_cls) &&
2274 (tun_src->vxlan.tun_cls != QED_TUNN_CLSS_MAC_VLAN ||
2275 tun_src->l2_geneve.tun_cls != QED_TUNN_CLSS_MAC_VLAN ||
2276 tun_src->ip_geneve.tun_cls != QED_TUNN_CLSS_MAC_VLAN ||
2277 tun_src->l2_gre.tun_cls != QED_TUNN_CLSS_MAC_VLAN ||
2278 tun_src->ip_gre.tun_cls != QED_TUNN_CLSS_MAC_VLAN)) {
2279 tun_src->b_update_rx_cls = false;
2280 tun_src->b_update_tx_cls = false;
2284 if (tun_src->vxlan_port.b_update_port) {
2285 if (tun_src->vxlan_port.port == tun->vxlan_port.port) {
2286 tun_src->vxlan_port.b_update_port = false;
2289 bultn_vxlan_port = tun_src->vxlan_port.port;
2293 if (tun_src->geneve_port.b_update_port) {
2294 if (tun_src->geneve_port.port == tun->geneve_port.port) {
2295 tun_src->geneve_port.b_update_port = false;
2298 bultn_geneve_port = tun_src->geneve_port.port;
2302 qed_for_each_vf(p_hwfn, i) {
2303 qed_iov_bulletin_set_udp_ports(p_hwfn, i, bultn_vxlan_port,
2307 qed_schedule_iov(p_hwfn, QED_IOV_WQ_BULLETIN_UPDATE_FLAG);
2308 ops->ports_update(cookie, bultn_vxlan_port, bultn_geneve_port);
2313 static void qed_iov_vf_mbx_update_tunn_param(struct qed_hwfn *p_hwfn,
2314 struct qed_ptt *p_ptt,
2315 struct qed_vf_info *p_vf)
2317 struct qed_tunnel_info *p_tun = &p_hwfn->cdev->tunnel;
2318 struct qed_iov_vf_mbx *mbx = &p_vf->vf_mbx;
2319 struct pfvf_update_tunn_param_tlv *p_resp;
2320 struct vfpf_update_tunn_param_tlv *p_req;
2321 u8 status = PFVF_STATUS_SUCCESS;
2322 bool b_update_required = false;
2323 struct qed_tunnel_info tunn;
2324 u16 tunn_feature_mask = 0;
2327 mbx->offset = (u8 *)mbx->reply_virt;
2329 memset(&tunn, 0, sizeof(tunn));
2330 p_req = &mbx->req_virt->tunn_param_update;
2332 if (!qed_iov_pf_validate_tunn_param(p_req)) {
2333 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
2334 "No tunnel update requested by VF\n");
2335 status = PFVF_STATUS_FAILURE;
2339 tunn.b_update_rx_cls = p_req->update_tun_cls;
2340 tunn.b_update_tx_cls = p_req->update_tun_cls;
2342 qed_iov_pf_update_tun_param(p_req, &tunn.vxlan, &tunn.vxlan_port,
2343 QED_MODE_VXLAN_TUNN, p_req->vxlan_clss,
2344 p_req->update_vxlan_port,
2346 qed_iov_pf_update_tun_param(p_req, &tunn.l2_geneve, &tunn.geneve_port,
2347 QED_MODE_L2GENEVE_TUNN,
2348 p_req->l2geneve_clss,
2349 p_req->update_geneve_port,
2350 p_req->geneve_port);
2351 __qed_iov_pf_update_tun_param(p_req, &tunn.ip_geneve,
2352 QED_MODE_IPGENEVE_TUNN,
2353 p_req->ipgeneve_clss);
2354 __qed_iov_pf_update_tun_param(p_req, &tunn.l2_gre,
2355 QED_MODE_L2GRE_TUNN, p_req->l2gre_clss);
2356 __qed_iov_pf_update_tun_param(p_req, &tunn.ip_gre,
2357 QED_MODE_IPGRE_TUNN, p_req->ipgre_clss);
2359 /* If PF modifies VF's req then it should
2360 * still return an error in case of partial configuration
2361 * or modified configuration as opposed to requested one.
2363 rc = qed_pf_validate_modify_tunn_config(p_hwfn, &tunn_feature_mask,
2364 &b_update_required, &tunn);
2367 status = PFVF_STATUS_FAILURE;
2369 /* If QED client is willing to update anything ? */
2370 if (b_update_required) {
2373 rc = qed_sp_pf_update_tunn_cfg(p_hwfn, p_ptt, &tunn,
2374 QED_SPQ_MODE_EBLOCK, NULL);
2376 status = PFVF_STATUS_FAILURE;
2378 geneve_port = p_tun->geneve_port.port;
2379 qed_for_each_vf(p_hwfn, i) {
2380 qed_iov_bulletin_set_udp_ports(p_hwfn, i,
2381 p_tun->vxlan_port.port,
2387 p_resp = qed_add_tlv(p_hwfn, &mbx->offset,
2388 CHANNEL_TLV_UPDATE_TUNN_PARAM, sizeof(*p_resp));
2390 qed_iov_pf_update_tun_response(p_resp, p_tun, tunn_feature_mask);
2391 qed_add_tlv(p_hwfn, &mbx->offset, CHANNEL_TLV_LIST_END,
2392 sizeof(struct channel_list_end_tlv));
2394 qed_iov_send_response(p_hwfn, p_ptt, p_vf, sizeof(*p_resp), status);
2397 static void qed_iov_vf_mbx_start_txq_resp(struct qed_hwfn *p_hwfn,
2398 struct qed_ptt *p_ptt,
2399 struct qed_vf_info *p_vf,
2402 struct qed_iov_vf_mbx *mbx = &p_vf->vf_mbx;
2403 struct pfvf_start_queue_resp_tlv *p_tlv;
2404 bool b_legacy = false;
2407 mbx->offset = (u8 *)mbx->reply_virt;
2409 /* Taking a bigger struct instead of adding a TLV to list was a
2410 * mistake, but one which we're now stuck with, as some older
2411 * clients assume the size of the previous response.
2413 if (p_vf->acquire.vfdev_info.eth_fp_hsi_minor ==
2414 ETH_HSI_VER_NO_PKT_LEN_TUNN)
2418 length = sizeof(*p_tlv);
2420 length = sizeof(struct pfvf_def_resp_tlv);
2422 p_tlv = qed_add_tlv(p_hwfn, &mbx->offset, CHANNEL_TLV_START_TXQ,
2424 qed_add_tlv(p_hwfn, &mbx->offset, CHANNEL_TLV_LIST_END,
2425 sizeof(struct channel_list_end_tlv));
2427 /* Update the TLV with the response */
2428 if ((status == PFVF_STATUS_SUCCESS) && !b_legacy)
2429 p_tlv->offset = qed_db_addr_vf(cid, DQ_DEMS_LEGACY);
2431 qed_iov_send_response(p_hwfn, p_ptt, p_vf, length, status);
2434 static void qed_iov_vf_mbx_start_txq(struct qed_hwfn *p_hwfn,
2435 struct qed_ptt *p_ptt,
2436 struct qed_vf_info *vf)
2438 struct qed_queue_start_common_params params;
2439 struct qed_queue_cid_vf_params vf_params;
2440 struct qed_iov_vf_mbx *mbx = &vf->vf_mbx;
2441 u8 status = PFVF_STATUS_NO_RESOURCE;
2442 struct vfpf_start_txq_tlv *req;
2443 struct qed_vf_queue *p_queue;
2444 struct qed_queue_cid *p_cid;
2445 struct qed_sb_info sb_dummy;
2446 u8 qid_usage_idx, vf_legacy;
2451 memset(¶ms, 0, sizeof(params));
2452 req = &mbx->req_virt->start_txq;
2454 if (!qed_iov_validate_txq(p_hwfn, vf, req->tx_qid,
2455 QED_IOV_VALIDATE_Q_NA) ||
2456 !qed_iov_validate_sb(p_hwfn, vf, req->hw_sb))
2459 qid_usage_idx = qed_iov_vf_mbx_qid(p_hwfn, vf, true);
2460 if (qid_usage_idx == QED_IOV_QID_INVALID)
2463 p_queue = &vf->vf_queues[req->tx_qid];
2464 if (p_queue->cids[qid_usage_idx].p_cid)
2467 vf_legacy = qed_vf_calculate_legacy(vf);
2469 /* Acquire a new queue-cid */
2470 params.queue_id = p_queue->fw_tx_qid;
2471 params.vport_id = vf->vport_id;
2472 params.stats_id = vf->abs_vf_id + 0x10;
2474 /* Since IGU index is passed via sb_info, construct a dummy one */
2475 memset(&sb_dummy, 0, sizeof(sb_dummy));
2476 sb_dummy.igu_sb_id = req->hw_sb;
2477 params.p_sb = &sb_dummy;
2478 params.sb_idx = req->sb_index;
2480 memset(&vf_params, 0, sizeof(vf_params));
2481 vf_params.vfid = vf->relative_vf_id;
2482 vf_params.vf_qid = (u8)req->tx_qid;
2483 vf_params.vf_legacy = vf_legacy;
2484 vf_params.qid_usage_idx = qid_usage_idx;
2486 p_cid = qed_eth_queue_to_cid(p_hwfn, vf->opaque_fid,
2487 ¶ms, false, &vf_params);
2491 pq = qed_get_cm_pq_idx_vf(p_hwfn, vf->relative_vf_id);
2492 rc = qed_eth_txq_start_ramrod(p_hwfn, p_cid,
2493 req->pbl_addr, req->pbl_size, pq);
2495 status = PFVF_STATUS_FAILURE;
2496 qed_eth_queue_cid_release(p_hwfn, p_cid);
2498 status = PFVF_STATUS_SUCCESS;
2499 p_queue->cids[qid_usage_idx].p_cid = p_cid;
2500 p_queue->cids[qid_usage_idx].b_is_tx = true;
2505 qed_iov_vf_mbx_start_txq_resp(p_hwfn, p_ptt, vf, cid, status);
2508 static int qed_iov_vf_stop_rxqs(struct qed_hwfn *p_hwfn,
2509 struct qed_vf_info *vf,
2511 u8 qid_usage_idx, bool cqe_completion)
2513 struct qed_vf_queue *p_queue;
2516 if (!qed_iov_validate_rxq(p_hwfn, vf, rxq_id, QED_IOV_VALIDATE_Q_NA)) {
2519 "VF[%d] Tried Closing Rx 0x%04x.%02x which is inactive\n",
2520 vf->relative_vf_id, rxq_id, qid_usage_idx);
2524 p_queue = &vf->vf_queues[rxq_id];
2526 /* We've validated the index and the existence of the active RXQ -
2527 * now we need to make sure that it's using the correct qid.
2529 if (!p_queue->cids[qid_usage_idx].p_cid ||
2530 p_queue->cids[qid_usage_idx].b_is_tx) {
2531 struct qed_queue_cid *p_cid;
2533 p_cid = qed_iov_get_vf_rx_queue_cid(p_queue);
2536 "VF[%d] - Tried Closing Rx 0x%04x.%02x, but Rx is at %04x.%02x\n",
2538 rxq_id, qid_usage_idx, rxq_id, p_cid->qid_usage_idx);
2542 /* Now that we know we have a valid Rx-queue - close it */
2543 rc = qed_eth_rx_queue_stop(p_hwfn,
2544 p_queue->cids[qid_usage_idx].p_cid,
2545 false, cqe_completion);
2549 p_queue->cids[qid_usage_idx].p_cid = NULL;
2550 vf->num_active_rxqs--;
2555 static int qed_iov_vf_stop_txqs(struct qed_hwfn *p_hwfn,
2556 struct qed_vf_info *vf,
2557 u16 txq_id, u8 qid_usage_idx)
2559 struct qed_vf_queue *p_queue;
2562 if (!qed_iov_validate_txq(p_hwfn, vf, txq_id, QED_IOV_VALIDATE_Q_NA))
2565 p_queue = &vf->vf_queues[txq_id];
2566 if (!p_queue->cids[qid_usage_idx].p_cid ||
2567 !p_queue->cids[qid_usage_idx].b_is_tx)
2570 rc = qed_eth_tx_queue_stop(p_hwfn, p_queue->cids[qid_usage_idx].p_cid);
2574 p_queue->cids[qid_usage_idx].p_cid = NULL;
2578 static void qed_iov_vf_mbx_stop_rxqs(struct qed_hwfn *p_hwfn,
2579 struct qed_ptt *p_ptt,
2580 struct qed_vf_info *vf)
2582 u16 length = sizeof(struct pfvf_def_resp_tlv);
2583 struct qed_iov_vf_mbx *mbx = &vf->vf_mbx;
2584 u8 status = PFVF_STATUS_FAILURE;
2585 struct vfpf_stop_rxqs_tlv *req;
2589 /* There has never been an official driver that used this interface
2590 * for stopping multiple queues, and it is now considered deprecated.
2591 * Validate this isn't used here.
2593 req = &mbx->req_virt->stop_rxqs;
2594 if (req->num_rxqs != 1) {
2595 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
2596 "Odd; VF[%d] tried stopping multiple Rx queues\n",
2597 vf->relative_vf_id);
2598 status = PFVF_STATUS_NOT_SUPPORTED;
2602 /* Find which qid-index is associated with the queue */
2603 qid_usage_idx = qed_iov_vf_mbx_qid(p_hwfn, vf, false);
2604 if (qid_usage_idx == QED_IOV_QID_INVALID)
2607 rc = qed_iov_vf_stop_rxqs(p_hwfn, vf, req->rx_qid,
2608 qid_usage_idx, req->cqe_completion);
2610 status = PFVF_STATUS_SUCCESS;
2612 qed_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_STOP_RXQS,
2616 static void qed_iov_vf_mbx_stop_txqs(struct qed_hwfn *p_hwfn,
2617 struct qed_ptt *p_ptt,
2618 struct qed_vf_info *vf)
2620 u16 length = sizeof(struct pfvf_def_resp_tlv);
2621 struct qed_iov_vf_mbx *mbx = &vf->vf_mbx;
2622 u8 status = PFVF_STATUS_FAILURE;
2623 struct vfpf_stop_txqs_tlv *req;
2627 /* There has never been an official driver that used this interface
2628 * for stopping multiple queues, and it is now considered deprecated.
2629 * Validate this isn't used here.
2631 req = &mbx->req_virt->stop_txqs;
2632 if (req->num_txqs != 1) {
2633 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
2634 "Odd; VF[%d] tried stopping multiple Tx queues\n",
2635 vf->relative_vf_id);
2636 status = PFVF_STATUS_NOT_SUPPORTED;
2640 /* Find which qid-index is associated with the queue */
2641 qid_usage_idx = qed_iov_vf_mbx_qid(p_hwfn, vf, true);
2642 if (qid_usage_idx == QED_IOV_QID_INVALID)
2645 rc = qed_iov_vf_stop_txqs(p_hwfn, vf, req->tx_qid, qid_usage_idx);
2647 status = PFVF_STATUS_SUCCESS;
2650 qed_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_STOP_TXQS,
2654 static void qed_iov_vf_mbx_update_rxqs(struct qed_hwfn *p_hwfn,
2655 struct qed_ptt *p_ptt,
2656 struct qed_vf_info *vf)
2658 struct qed_queue_cid *handlers[QED_MAX_VF_CHAINS_PER_PF];
2659 u16 length = sizeof(struct pfvf_def_resp_tlv);
2660 struct qed_iov_vf_mbx *mbx = &vf->vf_mbx;
2661 struct vfpf_update_rxq_tlv *req;
2662 u8 status = PFVF_STATUS_FAILURE;
2663 u8 complete_event_flg;
2664 u8 complete_cqe_flg;
2669 req = &mbx->req_virt->update_rxq;
2670 complete_cqe_flg = !!(req->flags & VFPF_RXQ_UPD_COMPLETE_CQE_FLAG);
2671 complete_event_flg = !!(req->flags & VFPF_RXQ_UPD_COMPLETE_EVENT_FLAG);
2673 qid_usage_idx = qed_iov_vf_mbx_qid(p_hwfn, vf, false);
2674 if (qid_usage_idx == QED_IOV_QID_INVALID)
2677 /* There shouldn't exist a VF that uses queue-qids yet uses this
2678 * API with multiple Rx queues. Validate this.
2680 if ((vf->acquire.vfdev_info.capabilities &
2681 VFPF_ACQUIRE_CAP_QUEUE_QIDS) && req->num_rxqs != 1) {
2682 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
2683 "VF[%d] supports QIDs but sends multiple queues\n",
2684 vf->relative_vf_id);
2688 /* Validate inputs - for the legacy case this is still true since
2689 * qid_usage_idx for each Rx queue would be LEGACY_QID_RX.
2691 for (i = req->rx_qid; i < req->rx_qid + req->num_rxqs; i++) {
2692 if (!qed_iov_validate_rxq(p_hwfn, vf, i,
2693 QED_IOV_VALIDATE_Q_NA) ||
2694 !vf->vf_queues[i].cids[qid_usage_idx].p_cid ||
2695 vf->vf_queues[i].cids[qid_usage_idx].b_is_tx) {
2696 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
2697 "VF[%d]: Incorrect Rxqs [%04x, %02x]\n",
2698 vf->relative_vf_id, req->rx_qid,
2704 /* Prepare the handlers */
2705 for (i = 0; i < req->num_rxqs; i++) {
2706 u16 qid = req->rx_qid + i;
2708 handlers[i] = vf->vf_queues[qid].cids[qid_usage_idx].p_cid;
2711 rc = qed_sp_eth_rx_queues_update(p_hwfn, (void **)&handlers,
2715 QED_SPQ_MODE_EBLOCK, NULL);
2719 status = PFVF_STATUS_SUCCESS;
2721 qed_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_UPDATE_RXQ,
2725 void *qed_iov_search_list_tlvs(struct qed_hwfn *p_hwfn,
2726 void *p_tlvs_list, u16 req_type)
2728 struct channel_tlv *p_tlv = (struct channel_tlv *)p_tlvs_list;
2732 if (!p_tlv->length) {
2733 DP_NOTICE(p_hwfn, "Zero length TLV found\n");
2737 if (p_tlv->type == req_type) {
2738 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
2739 "Extended tlv type %d, length %d found\n",
2740 p_tlv->type, p_tlv->length);
2744 len += p_tlv->length;
2745 p_tlv = (struct channel_tlv *)((u8 *)p_tlv + p_tlv->length);
2747 if ((len + p_tlv->length) > TLV_BUFFER_SIZE) {
2748 DP_NOTICE(p_hwfn, "TLVs has overrun the buffer size\n");
2751 } while (p_tlv->type != CHANNEL_TLV_LIST_END);
2757 qed_iov_vp_update_act_param(struct qed_hwfn *p_hwfn,
2758 struct qed_sp_vport_update_params *p_data,
2759 struct qed_iov_vf_mbx *p_mbx, u16 *tlvs_mask)
2761 struct vfpf_vport_update_activate_tlv *p_act_tlv;
2762 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_ACTIVATE;
2764 p_act_tlv = (struct vfpf_vport_update_activate_tlv *)
2765 qed_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
2769 p_data->update_vport_active_rx_flg = p_act_tlv->update_rx;
2770 p_data->vport_active_rx_flg = p_act_tlv->active_rx;
2771 p_data->update_vport_active_tx_flg = p_act_tlv->update_tx;
2772 p_data->vport_active_tx_flg = p_act_tlv->active_tx;
2773 *tlvs_mask |= 1 << QED_IOV_VP_UPDATE_ACTIVATE;
2777 qed_iov_vp_update_vlan_param(struct qed_hwfn *p_hwfn,
2778 struct qed_sp_vport_update_params *p_data,
2779 struct qed_vf_info *p_vf,
2780 struct qed_iov_vf_mbx *p_mbx, u16 *tlvs_mask)
2782 struct vfpf_vport_update_vlan_strip_tlv *p_vlan_tlv;
2783 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_VLAN_STRIP;
2785 p_vlan_tlv = (struct vfpf_vport_update_vlan_strip_tlv *)
2786 qed_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
2790 p_vf->shadow_config.inner_vlan_removal = p_vlan_tlv->remove_vlan;
2792 /* Ignore the VF request if we're forcing a vlan */
2793 if (!(p_vf->configured_features & BIT(VLAN_ADDR_FORCED))) {
2794 p_data->update_inner_vlan_removal_flg = 1;
2795 p_data->inner_vlan_removal_flg = p_vlan_tlv->remove_vlan;
2798 *tlvs_mask |= 1 << QED_IOV_VP_UPDATE_VLAN_STRIP;
2802 qed_iov_vp_update_tx_switch(struct qed_hwfn *p_hwfn,
2803 struct qed_sp_vport_update_params *p_data,
2804 struct qed_iov_vf_mbx *p_mbx, u16 *tlvs_mask)
2806 struct vfpf_vport_update_tx_switch_tlv *p_tx_switch_tlv;
2807 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_TX_SWITCH;
2809 p_tx_switch_tlv = (struct vfpf_vport_update_tx_switch_tlv *)
2810 qed_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt,
2812 if (!p_tx_switch_tlv)
2815 p_data->update_tx_switching_flg = 1;
2816 p_data->tx_switching_flg = p_tx_switch_tlv->tx_switching;
2817 *tlvs_mask |= 1 << QED_IOV_VP_UPDATE_TX_SWITCH;
2821 qed_iov_vp_update_mcast_bin_param(struct qed_hwfn *p_hwfn,
2822 struct qed_sp_vport_update_params *p_data,
2823 struct qed_iov_vf_mbx *p_mbx, u16 *tlvs_mask)
2825 struct vfpf_vport_update_mcast_bin_tlv *p_mcast_tlv;
2826 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_MCAST;
2828 p_mcast_tlv = (struct vfpf_vport_update_mcast_bin_tlv *)
2829 qed_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
2833 p_data->update_approx_mcast_flg = 1;
2834 memcpy(p_data->bins, p_mcast_tlv->bins,
2835 sizeof(u32) * ETH_MULTICAST_MAC_BINS_IN_REGS);
2836 *tlvs_mask |= 1 << QED_IOV_VP_UPDATE_MCAST;
2840 qed_iov_vp_update_accept_flag(struct qed_hwfn *p_hwfn,
2841 struct qed_sp_vport_update_params *p_data,
2842 struct qed_iov_vf_mbx *p_mbx, u16 *tlvs_mask)
2844 struct qed_filter_accept_flags *p_flags = &p_data->accept_flags;
2845 struct vfpf_vport_update_accept_param_tlv *p_accept_tlv;
2846 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_ACCEPT_PARAM;
2848 p_accept_tlv = (struct vfpf_vport_update_accept_param_tlv *)
2849 qed_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
2853 p_flags->update_rx_mode_config = p_accept_tlv->update_rx_mode;
2854 p_flags->rx_accept_filter = p_accept_tlv->rx_accept_filter;
2855 p_flags->update_tx_mode_config = p_accept_tlv->update_tx_mode;
2856 p_flags->tx_accept_filter = p_accept_tlv->tx_accept_filter;
2857 *tlvs_mask |= 1 << QED_IOV_VP_UPDATE_ACCEPT_PARAM;
2861 qed_iov_vp_update_accept_any_vlan(struct qed_hwfn *p_hwfn,
2862 struct qed_sp_vport_update_params *p_data,
2863 struct qed_iov_vf_mbx *p_mbx, u16 *tlvs_mask)
2865 struct vfpf_vport_update_accept_any_vlan_tlv *p_accept_any_vlan;
2866 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_ACCEPT_ANY_VLAN;
2868 p_accept_any_vlan = (struct vfpf_vport_update_accept_any_vlan_tlv *)
2869 qed_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt,
2871 if (!p_accept_any_vlan)
2874 p_data->accept_any_vlan = p_accept_any_vlan->accept_any_vlan;
2875 p_data->update_accept_any_vlan_flg =
2876 p_accept_any_vlan->update_accept_any_vlan_flg;
2877 *tlvs_mask |= 1 << QED_IOV_VP_UPDATE_ACCEPT_ANY_VLAN;
2881 qed_iov_vp_update_rss_param(struct qed_hwfn *p_hwfn,
2882 struct qed_vf_info *vf,
2883 struct qed_sp_vport_update_params *p_data,
2884 struct qed_rss_params *p_rss,
2885 struct qed_iov_vf_mbx *p_mbx,
2886 u16 *tlvs_mask, u16 *tlvs_accepted)
2888 struct vfpf_vport_update_rss_tlv *p_rss_tlv;
2889 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_RSS;
2890 bool b_reject = false;
2894 p_rss_tlv = (struct vfpf_vport_update_rss_tlv *)
2895 qed_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
2897 p_data->rss_params = NULL;
2901 memset(p_rss, 0, sizeof(struct qed_rss_params));
2903 p_rss->update_rss_config = !!(p_rss_tlv->update_rss_flags &
2904 VFPF_UPDATE_RSS_CONFIG_FLAG);
2905 p_rss->update_rss_capabilities = !!(p_rss_tlv->update_rss_flags &
2906 VFPF_UPDATE_RSS_CAPS_FLAG);
2907 p_rss->update_rss_ind_table = !!(p_rss_tlv->update_rss_flags &
2908 VFPF_UPDATE_RSS_IND_TABLE_FLAG);
2909 p_rss->update_rss_key = !!(p_rss_tlv->update_rss_flags &
2910 VFPF_UPDATE_RSS_KEY_FLAG);
2912 p_rss->rss_enable = p_rss_tlv->rss_enable;
2913 p_rss->rss_eng_id = vf->relative_vf_id + 1;
2914 p_rss->rss_caps = p_rss_tlv->rss_caps;
2915 p_rss->rss_table_size_log = p_rss_tlv->rss_table_size_log;
2916 memcpy(p_rss->rss_key, p_rss_tlv->rss_key, sizeof(p_rss->rss_key));
2918 table_size = min_t(u16, ARRAY_SIZE(p_rss->rss_ind_table),
2919 (1 << p_rss_tlv->rss_table_size_log));
2921 for (i = 0; i < table_size; i++) {
2922 struct qed_queue_cid *p_cid;
2924 q_idx = p_rss_tlv->rss_ind_table[i];
2925 if (!qed_iov_validate_rxq(p_hwfn, vf, q_idx,
2926 QED_IOV_VALIDATE_Q_ENABLE)) {
2929 "VF[%d]: Omitting RSS due to wrong queue %04x\n",
2930 vf->relative_vf_id, q_idx);
2935 p_cid = qed_iov_get_vf_rx_queue_cid(&vf->vf_queues[q_idx]);
2936 p_rss->rss_ind_table[i] = p_cid;
2939 p_data->rss_params = p_rss;
2941 *tlvs_mask |= 1 << QED_IOV_VP_UPDATE_RSS;