1 /* QLogic qed NIC Driver
2 * Copyright (c) 2015 QLogic Corporation
4 * This software is available under the terms of the GNU General Public License
5 * (GPL) Version 2, available from the file COPYING in the main directory of
9 #include <linux/etherdevice.h>
10 #include <linux/crc32.h>
11 #include <linux/qed/qed_iov_if.h>
15 #include "qed_init_ops.h"
18 #include "qed_reg_addr.h"
20 #include "qed_sriov.h"
24 static int qed_sp_vf_start(struct qed_hwfn *p_hwfn, struct qed_vf_info *p_vf)
26 struct vf_start_ramrod_data *p_ramrod = NULL;
27 struct qed_spq_entry *p_ent = NULL;
28 struct qed_sp_init_data init_data;
33 memset(&init_data, 0, sizeof(init_data));
34 init_data.cid = qed_spq_get_cid(p_hwfn);
35 init_data.opaque_fid = p_vf->opaque_fid;
36 init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
38 rc = qed_sp_init_request(p_hwfn, &p_ent,
39 COMMON_RAMROD_VF_START,
40 PROTOCOLID_COMMON, &init_data);
44 p_ramrod = &p_ent->ramrod.vf_start;
46 p_ramrod->vf_id = GET_FIELD(p_vf->concrete_fid, PXP_CONCRETE_FID_VFID);
47 p_ramrod->opaque_fid = cpu_to_le16(p_vf->opaque_fid);
49 switch (p_hwfn->hw_info.personality) {
51 p_ramrod->personality = PERSONALITY_ETH;
53 case QED_PCI_ETH_ROCE:
54 p_ramrod->personality = PERSONALITY_RDMA_AND_ETH;
57 DP_NOTICE(p_hwfn, "Unknown VF personality %d\n",
58 p_hwfn->hw_info.personality);
62 fp_minor = p_vf->acquire.vfdev_info.eth_fp_hsi_minor;
63 if (fp_minor > ETH_HSI_VER_MINOR) {
66 "VF [%d] - Requested fp hsi %02x.%02x which is slightly newer than PF's %02x.%02x; Configuring PFs version\n",
69 fp_minor, ETH_HSI_VER_MAJOR, ETH_HSI_VER_MINOR);
70 fp_minor = ETH_HSI_VER_MINOR;
73 p_ramrod->hsi_fp_ver.major_ver_arr[ETH_VER_KEY] = ETH_HSI_VER_MAJOR;
74 p_ramrod->hsi_fp_ver.minor_ver_arr[ETH_VER_KEY] = fp_minor;
76 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
77 "VF[%d] - Starting using HSI %02x.%02x\n",
78 p_vf->abs_vf_id, ETH_HSI_VER_MAJOR, fp_minor);
80 return qed_spq_post(p_hwfn, p_ent, NULL);
83 static int qed_sp_vf_stop(struct qed_hwfn *p_hwfn,
84 u32 concrete_vfid, u16 opaque_vfid)
86 struct vf_stop_ramrod_data *p_ramrod = NULL;
87 struct qed_spq_entry *p_ent = NULL;
88 struct qed_sp_init_data init_data;
92 memset(&init_data, 0, sizeof(init_data));
93 init_data.cid = qed_spq_get_cid(p_hwfn);
94 init_data.opaque_fid = opaque_vfid;
95 init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
97 rc = qed_sp_init_request(p_hwfn, &p_ent,
98 COMMON_RAMROD_VF_STOP,
99 PROTOCOLID_COMMON, &init_data);
103 p_ramrod = &p_ent->ramrod.vf_stop;
105 p_ramrod->vf_id = GET_FIELD(concrete_vfid, PXP_CONCRETE_FID_VFID);
107 return qed_spq_post(p_hwfn, p_ent, NULL);
110 bool qed_iov_is_valid_vfid(struct qed_hwfn *p_hwfn,
111 int rel_vf_id, bool b_enabled_only)
113 if (!p_hwfn->pf_iov_info) {
114 DP_NOTICE(p_hwfn->cdev, "No iov info\n");
118 if ((rel_vf_id >= p_hwfn->cdev->p_iov_info->total_vfs) ||
122 if ((!p_hwfn->pf_iov_info->vfs_array[rel_vf_id].b_init) &&
129 static struct qed_vf_info *qed_iov_get_vf_info(struct qed_hwfn *p_hwfn,
133 struct qed_vf_info *vf = NULL;
135 if (!p_hwfn->pf_iov_info) {
136 DP_NOTICE(p_hwfn->cdev, "No iov info\n");
140 if (qed_iov_is_valid_vfid(p_hwfn, relative_vf_id, b_enabled_only))
141 vf = &p_hwfn->pf_iov_info->vfs_array[relative_vf_id];
143 DP_ERR(p_hwfn, "qed_iov_get_vf_info: VF[%d] is not enabled\n",
149 static bool qed_iov_validate_rxq(struct qed_hwfn *p_hwfn,
150 struct qed_vf_info *p_vf, u16 rx_qid)
152 if (rx_qid >= p_vf->num_rxqs)
155 "VF[0x%02x] - can't touch Rx queue[%04x]; Only 0x%04x are allocated\n",
156 p_vf->abs_vf_id, rx_qid, p_vf->num_rxqs);
157 return rx_qid < p_vf->num_rxqs;
160 static bool qed_iov_validate_txq(struct qed_hwfn *p_hwfn,
161 struct qed_vf_info *p_vf, u16 tx_qid)
163 if (tx_qid >= p_vf->num_txqs)
166 "VF[0x%02x] - can't touch Tx queue[%04x]; Only 0x%04x are allocated\n",
167 p_vf->abs_vf_id, tx_qid, p_vf->num_txqs);
168 return tx_qid < p_vf->num_txqs;
171 static bool qed_iov_validate_sb(struct qed_hwfn *p_hwfn,
172 struct qed_vf_info *p_vf, u16 sb_idx)
176 for (i = 0; i < p_vf->num_sbs; i++)
177 if (p_vf->igu_sbs[i] == sb_idx)
182 "VF[0%02x] - tried using sb_idx %04x which doesn't exist as one of its 0x%02x SBs\n",
183 p_vf->abs_vf_id, sb_idx, p_vf->num_sbs);
188 int qed_iov_post_vf_bulletin(struct qed_hwfn *p_hwfn,
189 int vfid, struct qed_ptt *p_ptt)
191 struct qed_bulletin_content *p_bulletin;
192 int crc_size = sizeof(p_bulletin->crc);
193 struct qed_dmae_params params;
194 struct qed_vf_info *p_vf;
196 p_vf = qed_iov_get_vf_info(p_hwfn, (u16) vfid, true);
200 if (!p_vf->vf_bulletin)
203 p_bulletin = p_vf->bulletin.p_virt;
205 /* Increment bulletin board version and compute crc */
206 p_bulletin->version++;
207 p_bulletin->crc = crc32(0, (u8 *)p_bulletin + crc_size,
208 p_vf->bulletin.size - crc_size);
210 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
211 "Posting Bulletin 0x%08x to VF[%d] (CRC 0x%08x)\n",
212 p_bulletin->version, p_vf->relative_vf_id, p_bulletin->crc);
214 /* propagate bulletin board via dmae to vm memory */
215 memset(¶ms, 0, sizeof(params));
216 params.flags = QED_DMAE_FLAG_VF_DST;
217 params.dst_vfid = p_vf->abs_vf_id;
218 return qed_dmae_host2host(p_hwfn, p_ptt, p_vf->bulletin.phys,
219 p_vf->vf_bulletin, p_vf->bulletin.size / 4,
223 static int qed_iov_pci_cfg_info(struct qed_dev *cdev)
225 struct qed_hw_sriov_info *iov = cdev->p_iov_info;
228 DP_VERBOSE(cdev, QED_MSG_IOV, "sriov ext pos %d\n", pos);
229 pci_read_config_word(cdev->pdev, pos + PCI_SRIOV_CTRL, &iov->ctrl);
231 pci_read_config_word(cdev->pdev,
232 pos + PCI_SRIOV_TOTAL_VF, &iov->total_vfs);
233 pci_read_config_word(cdev->pdev,
234 pos + PCI_SRIOV_INITIAL_VF, &iov->initial_vfs);
236 pci_read_config_word(cdev->pdev, pos + PCI_SRIOV_NUM_VF, &iov->num_vfs);
240 "Number of VFs are already set to non-zero value. Ignoring PCI configuration value\n");
244 pci_read_config_word(cdev->pdev,
245 pos + PCI_SRIOV_VF_OFFSET, &iov->offset);
247 pci_read_config_word(cdev->pdev,
248 pos + PCI_SRIOV_VF_STRIDE, &iov->stride);
250 pci_read_config_word(cdev->pdev,
251 pos + PCI_SRIOV_VF_DID, &iov->vf_device_id);
253 pci_read_config_dword(cdev->pdev,
254 pos + PCI_SRIOV_SUP_PGSIZE, &iov->pgsz);
256 pci_read_config_dword(cdev->pdev, pos + PCI_SRIOV_CAP, &iov->cap);
258 pci_read_config_byte(cdev->pdev, pos + PCI_SRIOV_FUNC_LINK, &iov->link);
262 "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",
268 iov->nr_virtfn, iov->offset, iov->stride, iov->pgsz);
270 /* Some sanity checks */
271 if (iov->num_vfs > NUM_OF_VFS(cdev) ||
272 iov->total_vfs > NUM_OF_VFS(cdev)) {
273 /* This can happen only due to a bug. In this case we set
274 * num_vfs to zero to avoid memory corruption in the code that
275 * assumes max number of vfs
278 "IOV: Unexpected number of vfs set: %d setting num_vf to zero\n",
288 static void qed_iov_clear_vf_igu_blocks(struct qed_hwfn *p_hwfn,
289 struct qed_ptt *p_ptt)
291 struct qed_igu_block *p_sb;
295 if (!p_hwfn->hw_info.p_igu_info) {
297 "qed_iov_clear_vf_igu_blocks IGU Info not initialized\n");
301 for (sb_id = 0; sb_id < QED_MAPPING_MEMORY_SIZE(p_hwfn->cdev);
303 p_sb = &p_hwfn->hw_info.p_igu_info->igu_map.igu_blocks[sb_id];
304 if ((p_sb->status & QED_IGU_STATUS_FREE) &&
305 !(p_sb->status & QED_IGU_STATUS_PF)) {
306 val = qed_rd(p_hwfn, p_ptt,
307 IGU_REG_MAPPING_MEMORY + sb_id * 4);
308 SET_FIELD(val, IGU_MAPPING_LINE_VALID, 0);
309 qed_wr(p_hwfn, p_ptt,
310 IGU_REG_MAPPING_MEMORY + 4 * sb_id, val);
315 static void qed_iov_setup_vfdb(struct qed_hwfn *p_hwfn)
317 struct qed_hw_sriov_info *p_iov = p_hwfn->cdev->p_iov_info;
318 struct qed_pf_iov *p_iov_info = p_hwfn->pf_iov_info;
319 struct qed_bulletin_content *p_bulletin_virt;
320 dma_addr_t req_p, rply_p, bulletin_p;
321 union pfvf_tlvs *p_reply_virt_addr;
322 union vfpf_tlvs *p_req_virt_addr;
325 memset(p_iov_info->vfs_array, 0, sizeof(p_iov_info->vfs_array));
327 p_req_virt_addr = p_iov_info->mbx_msg_virt_addr;
328 req_p = p_iov_info->mbx_msg_phys_addr;
329 p_reply_virt_addr = p_iov_info->mbx_reply_virt_addr;
330 rply_p = p_iov_info->mbx_reply_phys_addr;
331 p_bulletin_virt = p_iov_info->p_bulletins;
332 bulletin_p = p_iov_info->bulletins_phys;
333 if (!p_req_virt_addr || !p_reply_virt_addr || !p_bulletin_virt) {
335 "qed_iov_setup_vfdb called without allocating mem first\n");
339 for (idx = 0; idx < p_iov->total_vfs; idx++) {
340 struct qed_vf_info *vf = &p_iov_info->vfs_array[idx];
343 vf->vf_mbx.req_virt = p_req_virt_addr + idx;
344 vf->vf_mbx.req_phys = req_p + idx * sizeof(union vfpf_tlvs);
345 vf->vf_mbx.reply_virt = p_reply_virt_addr + idx;
346 vf->vf_mbx.reply_phys = rply_p + idx * sizeof(union pfvf_tlvs);
348 vf->state = VF_STOPPED;
351 vf->bulletin.phys = idx *
352 sizeof(struct qed_bulletin_content) +
354 vf->bulletin.p_virt = p_bulletin_virt + idx;
355 vf->bulletin.size = sizeof(struct qed_bulletin_content);
357 vf->relative_vf_id = idx;
358 vf->abs_vf_id = idx + p_iov->first_vf_in_pf;
359 concrete = qed_vfid_to_concrete(p_hwfn, vf->abs_vf_id);
360 vf->concrete_fid = concrete;
361 vf->opaque_fid = (p_hwfn->hw_info.opaque_fid & 0xff) |
362 (vf->abs_vf_id << 8);
363 vf->vport_id = idx + 1;
365 vf->num_mac_filters = QED_ETH_VF_NUM_MAC_FILTERS;
366 vf->num_vlan_filters = QED_ETH_VF_NUM_VLAN_FILTERS;
370 static int qed_iov_allocate_vfdb(struct qed_hwfn *p_hwfn)
372 struct qed_pf_iov *p_iov_info = p_hwfn->pf_iov_info;
376 num_vfs = p_hwfn->cdev->p_iov_info->total_vfs;
378 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
379 "qed_iov_allocate_vfdb for %d VFs\n", num_vfs);
381 /* Allocate PF Mailbox buffer (per-VF) */
382 p_iov_info->mbx_msg_size = sizeof(union vfpf_tlvs) * num_vfs;
383 p_v_addr = &p_iov_info->mbx_msg_virt_addr;
384 *p_v_addr = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev,
385 p_iov_info->mbx_msg_size,
386 &p_iov_info->mbx_msg_phys_addr,
391 /* Allocate PF Mailbox Reply buffer (per-VF) */
392 p_iov_info->mbx_reply_size = sizeof(union pfvf_tlvs) * num_vfs;
393 p_v_addr = &p_iov_info->mbx_reply_virt_addr;
394 *p_v_addr = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev,
395 p_iov_info->mbx_reply_size,
396 &p_iov_info->mbx_reply_phys_addr,
401 p_iov_info->bulletins_size = sizeof(struct qed_bulletin_content) *
403 p_v_addr = &p_iov_info->p_bulletins;
404 *p_v_addr = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev,
405 p_iov_info->bulletins_size,
406 &p_iov_info->bulletins_phys,
413 "PF's Requests mailbox [%p virt 0x%llx phys], Response mailbox [%p virt 0x%llx phys] Bulletins [%p virt 0x%llx phys]\n",
414 p_iov_info->mbx_msg_virt_addr,
415 (u64) p_iov_info->mbx_msg_phys_addr,
416 p_iov_info->mbx_reply_virt_addr,
417 (u64) p_iov_info->mbx_reply_phys_addr,
418 p_iov_info->p_bulletins, (u64) p_iov_info->bulletins_phys);
423 static void qed_iov_free_vfdb(struct qed_hwfn *p_hwfn)
425 struct qed_pf_iov *p_iov_info = p_hwfn->pf_iov_info;
427 if (p_hwfn->pf_iov_info->mbx_msg_virt_addr)
428 dma_free_coherent(&p_hwfn->cdev->pdev->dev,
429 p_iov_info->mbx_msg_size,
430 p_iov_info->mbx_msg_virt_addr,
431 p_iov_info->mbx_msg_phys_addr);
433 if (p_hwfn->pf_iov_info->mbx_reply_virt_addr)
434 dma_free_coherent(&p_hwfn->cdev->pdev->dev,
435 p_iov_info->mbx_reply_size,
436 p_iov_info->mbx_reply_virt_addr,
437 p_iov_info->mbx_reply_phys_addr);
439 if (p_iov_info->p_bulletins)
440 dma_free_coherent(&p_hwfn->cdev->pdev->dev,
441 p_iov_info->bulletins_size,
442 p_iov_info->p_bulletins,
443 p_iov_info->bulletins_phys);
446 int qed_iov_alloc(struct qed_hwfn *p_hwfn)
448 struct qed_pf_iov *p_sriov;
450 if (!IS_PF_SRIOV(p_hwfn)) {
451 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
452 "No SR-IOV - no need for IOV db\n");
456 p_sriov = kzalloc(sizeof(*p_sriov), GFP_KERNEL);
458 DP_NOTICE(p_hwfn, "Failed to allocate `struct qed_sriov'\n");
462 p_hwfn->pf_iov_info = p_sriov;
464 return qed_iov_allocate_vfdb(p_hwfn);
467 void qed_iov_setup(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
469 if (!IS_PF_SRIOV(p_hwfn) || !IS_PF_SRIOV_ALLOC(p_hwfn))
472 qed_iov_setup_vfdb(p_hwfn);
473 qed_iov_clear_vf_igu_blocks(p_hwfn, p_ptt);
476 void qed_iov_free(struct qed_hwfn *p_hwfn)
478 if (IS_PF_SRIOV_ALLOC(p_hwfn)) {
479 qed_iov_free_vfdb(p_hwfn);
480 kfree(p_hwfn->pf_iov_info);
484 void qed_iov_free_hw_info(struct qed_dev *cdev)
486 kfree(cdev->p_iov_info);
487 cdev->p_iov_info = NULL;
490 int qed_iov_hw_info(struct qed_hwfn *p_hwfn)
492 struct qed_dev *cdev = p_hwfn->cdev;
496 if (IS_VF(p_hwfn->cdev))
499 /* Learn the PCI configuration */
500 pos = pci_find_ext_capability(p_hwfn->cdev->pdev,
501 PCI_EXT_CAP_ID_SRIOV);
503 DP_VERBOSE(p_hwfn, QED_MSG_IOV, "No PCIe IOV support\n");
507 /* Allocate a new struct for IOV information */
508 cdev->p_iov_info = kzalloc(sizeof(*cdev->p_iov_info), GFP_KERNEL);
509 if (!cdev->p_iov_info) {
510 DP_NOTICE(p_hwfn, "Can't support IOV due to lack of memory\n");
513 cdev->p_iov_info->pos = pos;
515 rc = qed_iov_pci_cfg_info(cdev);
519 /* We want PF IOV to be synonemous with the existance of p_iov_info;
520 * In case the capability is published but there are no VFs, simply
521 * de-allocate the struct.
523 if (!cdev->p_iov_info->total_vfs) {
524 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
525 "IOV capabilities, but no VFs are published\n");
526 kfree(cdev->p_iov_info);
527 cdev->p_iov_info = NULL;
531 /* Calculate the first VF index - this is a bit tricky; Basically,
532 * VFs start at offset 16 relative to PF0, and 2nd engine VFs begin
533 * after the first engine's VFs.
535 cdev->p_iov_info->first_vf_in_pf = p_hwfn->cdev->p_iov_info->offset +
536 p_hwfn->abs_pf_id - 16;
537 if (QED_PATH_ID(p_hwfn))
538 cdev->p_iov_info->first_vf_in_pf -= MAX_NUM_VFS_BB;
540 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
541 "First VF in hwfn 0x%08x\n",
542 cdev->p_iov_info->first_vf_in_pf);
547 static bool qed_iov_pf_sanity_check(struct qed_hwfn *p_hwfn, int vfid)
549 /* Check PF supports sriov */
550 if (IS_VF(p_hwfn->cdev) || !IS_QED_SRIOV(p_hwfn->cdev) ||
551 !IS_PF_SRIOV_ALLOC(p_hwfn))
554 /* Check VF validity */
555 if (!qed_iov_is_valid_vfid(p_hwfn, vfid, true))
561 static void qed_iov_set_vf_to_disable(struct qed_dev *cdev,
562 u16 rel_vf_id, u8 to_disable)
564 struct qed_vf_info *vf;
567 for_each_hwfn(cdev, i) {
568 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
570 vf = qed_iov_get_vf_info(p_hwfn, rel_vf_id, false);
574 vf->to_disable = to_disable;
578 void qed_iov_set_vfs_to_disable(struct qed_dev *cdev, u8 to_disable)
582 if (!IS_QED_SRIOV(cdev))
585 for (i = 0; i < cdev->p_iov_info->total_vfs; i++)
586 qed_iov_set_vf_to_disable(cdev, i, to_disable);
589 static void qed_iov_vf_pglue_clear_err(struct qed_hwfn *p_hwfn,
590 struct qed_ptt *p_ptt, u8 abs_vfid)
592 qed_wr(p_hwfn, p_ptt,
593 PGLUE_B_REG_WAS_ERROR_VF_31_0_CLR + (abs_vfid >> 5) * 4,
594 1 << (abs_vfid & 0x1f));
597 static void qed_iov_vf_igu_reset(struct qed_hwfn *p_hwfn,
598 struct qed_ptt *p_ptt, struct qed_vf_info *vf)
602 /* Set VF masks and configuration - pretend */
603 qed_fid_pretend(p_hwfn, p_ptt, (u16) vf->concrete_fid);
605 qed_wr(p_hwfn, p_ptt, IGU_REG_STATISTIC_NUM_VF_MSG_SENT, 0);
608 qed_fid_pretend(p_hwfn, p_ptt, (u16) p_hwfn->hw_info.concrete_fid);
610 /* iterate over all queues, clear sb consumer */
611 for (i = 0; i < vf->num_sbs; i++)
612 qed_int_igu_init_pure_rt_single(p_hwfn, p_ptt,
614 vf->opaque_fid, true);
617 static void qed_iov_vf_igu_set_int(struct qed_hwfn *p_hwfn,
618 struct qed_ptt *p_ptt,
619 struct qed_vf_info *vf, bool enable)
623 qed_fid_pretend(p_hwfn, p_ptt, (u16) vf->concrete_fid);
625 igu_vf_conf = qed_rd(p_hwfn, p_ptt, IGU_REG_VF_CONFIGURATION);
628 igu_vf_conf |= IGU_VF_CONF_MSI_MSIX_EN;
630 igu_vf_conf &= ~IGU_VF_CONF_MSI_MSIX_EN;
632 qed_wr(p_hwfn, p_ptt, IGU_REG_VF_CONFIGURATION, igu_vf_conf);
635 qed_fid_pretend(p_hwfn, p_ptt, (u16) p_hwfn->hw_info.concrete_fid);
638 static int qed_iov_enable_vf_access(struct qed_hwfn *p_hwfn,
639 struct qed_ptt *p_ptt,
640 struct qed_vf_info *vf)
642 u32 igu_vf_conf = IGU_VF_CONF_FUNC_EN;
650 "Enable internal access for vf %x [abs %x]\n",
651 vf->abs_vf_id, QED_VF_ABS_ID(p_hwfn, vf));
653 qed_iov_vf_pglue_clear_err(p_hwfn, p_ptt, QED_VF_ABS_ID(p_hwfn, vf));
655 qed_iov_vf_igu_reset(p_hwfn, p_ptt, vf);
657 rc = qed_mcp_config_vf_msix(p_hwfn, p_ptt, vf->abs_vf_id, vf->num_sbs);
661 qed_fid_pretend(p_hwfn, p_ptt, (u16) vf->concrete_fid);
663 SET_FIELD(igu_vf_conf, IGU_VF_CONF_PARENT, p_hwfn->rel_pf_id);
664 STORE_RT_REG(p_hwfn, IGU_REG_VF_CONFIGURATION_RT_OFFSET, igu_vf_conf);
666 qed_init_run(p_hwfn, p_ptt, PHASE_VF, vf->abs_vf_id,
667 p_hwfn->hw_info.hw_mode);
670 qed_fid_pretend(p_hwfn, p_ptt, (u16) p_hwfn->hw_info.concrete_fid);
678 * @brief qed_iov_config_perm_table - configure the permission
680 * In E4, queue zone permission table size is 320x9. There
681 * are 320 VF queues for single engine device (256 for dual
682 * engine device), and each entry has the following format:
689 static void qed_iov_config_perm_table(struct qed_hwfn *p_hwfn,
690 struct qed_ptt *p_ptt,
691 struct qed_vf_info *vf, u8 enable)
697 for (qid = 0; qid < vf->num_rxqs; qid++) {
698 qed_fw_l2_queue(p_hwfn, vf->vf_queues[qid].fw_rx_qid,
701 reg_addr = PSWHST_REG_ZONE_PERMISSION_TABLE + qzone_id * 4;
702 val = enable ? (vf->abs_vf_id | BIT(8)) : 0;
703 qed_wr(p_hwfn, p_ptt, reg_addr, val);
707 static void qed_iov_enable_vf_traffic(struct qed_hwfn *p_hwfn,
708 struct qed_ptt *p_ptt,
709 struct qed_vf_info *vf)
711 /* Reset vf in IGU - interrupts are still disabled */
712 qed_iov_vf_igu_reset(p_hwfn, p_ptt, vf);
714 qed_iov_vf_igu_set_int(p_hwfn, p_ptt, vf, 1);
716 /* Permission Table */
717 qed_iov_config_perm_table(p_hwfn, p_ptt, vf, true);
720 static u8 qed_iov_alloc_vf_igu_sbs(struct qed_hwfn *p_hwfn,
721 struct qed_ptt *p_ptt,
722 struct qed_vf_info *vf, u16 num_rx_queues)
724 struct qed_igu_block *igu_blocks;
725 int qid = 0, igu_id = 0;
728 igu_blocks = p_hwfn->hw_info.p_igu_info->igu_map.igu_blocks;
730 if (num_rx_queues > p_hwfn->hw_info.p_igu_info->free_blks)
731 num_rx_queues = p_hwfn->hw_info.p_igu_info->free_blks;
732 p_hwfn->hw_info.p_igu_info->free_blks -= num_rx_queues;
734 SET_FIELD(val, IGU_MAPPING_LINE_FUNCTION_NUMBER, vf->abs_vf_id);
735 SET_FIELD(val, IGU_MAPPING_LINE_VALID, 1);
736 SET_FIELD(val, IGU_MAPPING_LINE_PF_VALID, 0);
738 while ((qid < num_rx_queues) &&
739 (igu_id < QED_MAPPING_MEMORY_SIZE(p_hwfn->cdev))) {
740 if (igu_blocks[igu_id].status & QED_IGU_STATUS_FREE) {
741 struct cau_sb_entry sb_entry;
743 vf->igu_sbs[qid] = (u16)igu_id;
744 igu_blocks[igu_id].status &= ~QED_IGU_STATUS_FREE;
746 SET_FIELD(val, IGU_MAPPING_LINE_VECTOR_NUMBER, qid);
748 qed_wr(p_hwfn, p_ptt,
749 IGU_REG_MAPPING_MEMORY + sizeof(u32) * igu_id,
752 /* Configure igu sb in CAU which were marked valid */
753 qed_init_cau_sb_entry(p_hwfn, &sb_entry,
756 qed_dmae_host2grc(p_hwfn, p_ptt,
757 (u64)(uintptr_t)&sb_entry,
758 CAU_REG_SB_VAR_MEMORY +
759 igu_id * sizeof(u64), 2, 0);
765 vf->num_sbs = (u8) num_rx_queues;
770 static void qed_iov_free_vf_igu_sbs(struct qed_hwfn *p_hwfn,
771 struct qed_ptt *p_ptt,
772 struct qed_vf_info *vf)
774 struct qed_igu_info *p_info = p_hwfn->hw_info.p_igu_info;
778 /* Invalidate igu CAM lines and mark them as free */
779 for (idx = 0; idx < vf->num_sbs; idx++) {
780 igu_id = vf->igu_sbs[idx];
781 addr = IGU_REG_MAPPING_MEMORY + sizeof(u32) * igu_id;
783 val = qed_rd(p_hwfn, p_ptt, addr);
784 SET_FIELD(val, IGU_MAPPING_LINE_VALID, 0);
785 qed_wr(p_hwfn, p_ptt, addr, val);
787 p_info->igu_map.igu_blocks[igu_id].status |=
790 p_hwfn->hw_info.p_igu_info->free_blks++;
796 static int qed_iov_init_hw_for_vf(struct qed_hwfn *p_hwfn,
797 struct qed_ptt *p_ptt,
798 u16 rel_vf_id, u16 num_rx_queues)
800 u8 num_of_vf_avaiable_chains = 0;
801 struct qed_vf_info *vf = NULL;
806 vf = qed_iov_get_vf_info(p_hwfn, rel_vf_id, false);
808 DP_ERR(p_hwfn, "qed_iov_init_hw_for_vf : vf is NULL\n");
813 DP_NOTICE(p_hwfn, "VF[%d] is already active.\n", rel_vf_id);
817 /* Limit number of queues according to number of CIDs */
818 qed_cxt_get_proto_cid_count(p_hwfn, PROTOCOLID_ETH, &cids);
821 "VF[%d] - requesting to initialize for 0x%04x queues [0x%04x CIDs available]\n",
822 vf->relative_vf_id, num_rx_queues, (u16) cids);
823 num_rx_queues = min_t(u16, num_rx_queues, ((u16) cids));
825 num_of_vf_avaiable_chains = qed_iov_alloc_vf_igu_sbs(p_hwfn,
829 if (!num_of_vf_avaiable_chains) {
830 DP_ERR(p_hwfn, "no available igu sbs\n");
834 /* Choose queue number and index ranges */
835 vf->num_rxqs = num_of_vf_avaiable_chains;
836 vf->num_txqs = num_of_vf_avaiable_chains;
838 for (i = 0; i < vf->num_rxqs; i++) {
839 u16 queue_id = qed_int_queue_id_from_sb_id(p_hwfn,
842 if (queue_id > RESC_NUM(p_hwfn, QED_L2_QUEUE)) {
844 "VF[%d] will require utilizing of out-of-bounds queues - %04x\n",
845 vf->relative_vf_id, queue_id);
849 /* CIDs are per-VF, so no problem having them 0-based. */
850 vf->vf_queues[i].fw_rx_qid = queue_id;
851 vf->vf_queues[i].fw_tx_qid = queue_id;
852 vf->vf_queues[i].fw_cid = i;
854 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
855 "VF[%d] - [%d] SB %04x, Tx/Rx queue %04x CID %04x\n",
856 vf->relative_vf_id, i, vf->igu_sbs[i], queue_id, i);
858 rc = qed_iov_enable_vf_access(p_hwfn, p_ptt, vf);
862 if (IS_LEAD_HWFN(p_hwfn))
863 p_hwfn->cdev->p_iov_info->num_vfs++;
869 static void qed_iov_set_link(struct qed_hwfn *p_hwfn,
871 struct qed_mcp_link_params *params,
872 struct qed_mcp_link_state *link,
873 struct qed_mcp_link_capabilities *p_caps)
875 struct qed_vf_info *p_vf = qed_iov_get_vf_info(p_hwfn,
878 struct qed_bulletin_content *p_bulletin;
883 p_bulletin = p_vf->bulletin.p_virt;
884 p_bulletin->req_autoneg = params->speed.autoneg;
885 p_bulletin->req_adv_speed = params->speed.advertised_speeds;
886 p_bulletin->req_forced_speed = params->speed.forced_speed;
887 p_bulletin->req_autoneg_pause = params->pause.autoneg;
888 p_bulletin->req_forced_rx = params->pause.forced_rx;
889 p_bulletin->req_forced_tx = params->pause.forced_tx;
890 p_bulletin->req_loopback = params->loopback_mode;
892 p_bulletin->link_up = link->link_up;
893 p_bulletin->speed = link->speed;
894 p_bulletin->full_duplex = link->full_duplex;
895 p_bulletin->autoneg = link->an;
896 p_bulletin->autoneg_complete = link->an_complete;
897 p_bulletin->parallel_detection = link->parallel_detection;
898 p_bulletin->pfc_enabled = link->pfc_enabled;
899 p_bulletin->partner_adv_speed = link->partner_adv_speed;
900 p_bulletin->partner_tx_flow_ctrl_en = link->partner_tx_flow_ctrl_en;
901 p_bulletin->partner_rx_flow_ctrl_en = link->partner_rx_flow_ctrl_en;
902 p_bulletin->partner_adv_pause = link->partner_adv_pause;
903 p_bulletin->sfp_tx_fault = link->sfp_tx_fault;
905 p_bulletin->capability_speed = p_caps->speed_capabilities;
908 static int qed_iov_release_hw_for_vf(struct qed_hwfn *p_hwfn,
909 struct qed_ptt *p_ptt, u16 rel_vf_id)
911 struct qed_mcp_link_capabilities caps;
912 struct qed_mcp_link_params params;
913 struct qed_mcp_link_state link;
914 struct qed_vf_info *vf = NULL;
916 vf = qed_iov_get_vf_info(p_hwfn, rel_vf_id, true);
918 DP_ERR(p_hwfn, "qed_iov_release_hw_for_vf : vf is NULL\n");
922 if (vf->bulletin.p_virt)
923 memset(vf->bulletin.p_virt, 0, sizeof(*vf->bulletin.p_virt));
925 memset(&vf->p_vf_info, 0, sizeof(vf->p_vf_info));
927 /* Get the link configuration back in bulletin so
928 * that when VFs are re-enabled they get the actual
929 * link configuration.
931 memcpy(¶ms, qed_mcp_get_link_params(p_hwfn), sizeof(params));
932 memcpy(&link, qed_mcp_get_link_state(p_hwfn), sizeof(link));
933 memcpy(&caps, qed_mcp_get_link_capabilities(p_hwfn), sizeof(caps));
934 qed_iov_set_link(p_hwfn, rel_vf_id, ¶ms, &link, &caps);
936 /* Forget the VF's acquisition message */
937 memset(&vf->acquire, 0, sizeof(vf->acquire));
939 /* disablng interrupts and resetting permission table was done during
940 * vf-close, however, we could get here without going through vf_close
942 /* Disable Interrupts for VF */
943 qed_iov_vf_igu_set_int(p_hwfn, p_ptt, vf, 0);
945 /* Reset Permission table */
946 qed_iov_config_perm_table(p_hwfn, p_ptt, vf, 0);
950 qed_iov_free_vf_igu_sbs(p_hwfn, p_ptt, vf);
955 if (IS_LEAD_HWFN(p_hwfn))
956 p_hwfn->cdev->p_iov_info->num_vfs--;
962 static bool qed_iov_tlv_supported(u16 tlvtype)
964 return CHANNEL_TLV_NONE < tlvtype && tlvtype < CHANNEL_TLV_MAX;
967 /* place a given tlv on the tlv buffer, continuing current tlv list */
968 void *qed_add_tlv(struct qed_hwfn *p_hwfn, u8 **offset, u16 type, u16 length)
970 struct channel_tlv *tl = (struct channel_tlv *)*offset;
975 /* Offset should keep pointing to next TLV (the end of the last) */
978 /* Return a pointer to the start of the added tlv */
979 return *offset - length;
982 /* list the types and lengths of the tlvs on the buffer */
983 void qed_dp_tlv_list(struct qed_hwfn *p_hwfn, void *tlvs_list)
985 u16 i = 1, total_length = 0;
986 struct channel_tlv *tlv;
989 tlv = (struct channel_tlv *)((u8 *)tlvs_list + total_length);
992 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
993 "TLV number %d: type %d, length %d\n",
994 i, tlv->type, tlv->length);
996 if (tlv->type == CHANNEL_TLV_LIST_END)
999 /* Validate entry - protect against malicious VFs */
1001 DP_NOTICE(p_hwfn, "TLV of length 0 found\n");
1005 total_length += tlv->length;
1007 if (total_length >= sizeof(struct tlv_buffer_size)) {
1008 DP_NOTICE(p_hwfn, "TLV ==> Buffer overflow\n");
1016 static void qed_iov_send_response(struct qed_hwfn *p_hwfn,
1017 struct qed_ptt *p_ptt,
1018 struct qed_vf_info *p_vf,
1019 u16 length, u8 status)
1021 struct qed_iov_vf_mbx *mbx = &p_vf->vf_mbx;
1022 struct qed_dmae_params params;
1025 mbx->reply_virt->default_resp.hdr.status = status;
1027 qed_dp_tlv_list(p_hwfn, mbx->reply_virt);
1029 eng_vf_id = p_vf->abs_vf_id;
1031 memset(¶ms, 0, sizeof(struct qed_dmae_params));
1032 params.flags = QED_DMAE_FLAG_VF_DST;
1033 params.dst_vfid = eng_vf_id;
1035 qed_dmae_host2host(p_hwfn, p_ptt, mbx->reply_phys + sizeof(u64),
1036 mbx->req_virt->first_tlv.reply_address +
1038 (sizeof(union pfvf_tlvs) - sizeof(u64)) / 4,
1041 qed_dmae_host2host(p_hwfn, p_ptt, mbx->reply_phys,
1042 mbx->req_virt->first_tlv.reply_address,
1043 sizeof(u64) / 4, ¶ms);
1046 GTT_BAR0_MAP_REG_USDM_RAM +
1047 USTORM_VF_PF_CHANNEL_READY_OFFSET(eng_vf_id), 1);
1050 static u16 qed_iov_vport_to_tlv(struct qed_hwfn *p_hwfn,
1051 enum qed_iov_vport_update_flag flag)
1054 case QED_IOV_VP_UPDATE_ACTIVATE:
1055 return CHANNEL_TLV_VPORT_UPDATE_ACTIVATE;
1056 case QED_IOV_VP_UPDATE_VLAN_STRIP:
1057 return CHANNEL_TLV_VPORT_UPDATE_VLAN_STRIP;
1058 case QED_IOV_VP_UPDATE_TX_SWITCH:
1059 return CHANNEL_TLV_VPORT_UPDATE_TX_SWITCH;
1060 case QED_IOV_VP_UPDATE_MCAST:
1061 return CHANNEL_TLV_VPORT_UPDATE_MCAST;
1062 case QED_IOV_VP_UPDATE_ACCEPT_PARAM:
1063 return CHANNEL_TLV_VPORT_UPDATE_ACCEPT_PARAM;
1064 case QED_IOV_VP_UPDATE_RSS:
1065 return CHANNEL_TLV_VPORT_UPDATE_RSS;
1066 case QED_IOV_VP_UPDATE_ACCEPT_ANY_VLAN:
1067 return CHANNEL_TLV_VPORT_UPDATE_ACCEPT_ANY_VLAN;
1068 case QED_IOV_VP_UPDATE_SGE_TPA:
1069 return CHANNEL_TLV_VPORT_UPDATE_SGE_TPA;
1075 static u16 qed_iov_prep_vp_update_resp_tlvs(struct qed_hwfn *p_hwfn,
1076 struct qed_vf_info *p_vf,
1077 struct qed_iov_vf_mbx *p_mbx,
1079 u16 tlvs_mask, u16 tlvs_accepted)
1081 struct pfvf_def_resp_tlv *resp;
1082 u16 size, total_len, i;
1084 memset(p_mbx->reply_virt, 0, sizeof(union pfvf_tlvs));
1085 p_mbx->offset = (u8 *)p_mbx->reply_virt;
1086 size = sizeof(struct pfvf_def_resp_tlv);
1089 qed_add_tlv(p_hwfn, &p_mbx->offset, CHANNEL_TLV_VPORT_UPDATE, size);
1091 /* Prepare response for all extended tlvs if they are found by PF */
1092 for (i = 0; i < QED_IOV_VP_UPDATE_MAX; i++) {
1093 if (!(tlvs_mask & BIT(i)))
1096 resp = qed_add_tlv(p_hwfn, &p_mbx->offset,
1097 qed_iov_vport_to_tlv(p_hwfn, i), size);
1099 if (tlvs_accepted & BIT(i))
1100 resp->hdr.status = status;
1102 resp->hdr.status = PFVF_STATUS_NOT_SUPPORTED;
1106 "VF[%d] - vport_update response: TLV %d, status %02x\n",
1107 p_vf->relative_vf_id,
1108 qed_iov_vport_to_tlv(p_hwfn, i), resp->hdr.status);
1113 qed_add_tlv(p_hwfn, &p_mbx->offset, CHANNEL_TLV_LIST_END,
1114 sizeof(struct channel_list_end_tlv));
1119 static void qed_iov_prepare_resp(struct qed_hwfn *p_hwfn,
1120 struct qed_ptt *p_ptt,
1121 struct qed_vf_info *vf_info,
1122 u16 type, u16 length, u8 status)
1124 struct qed_iov_vf_mbx *mbx = &vf_info->vf_mbx;
1126 mbx->offset = (u8 *)mbx->reply_virt;
1128 qed_add_tlv(p_hwfn, &mbx->offset, type, length);
1129 qed_add_tlv(p_hwfn, &mbx->offset, CHANNEL_TLV_LIST_END,
1130 sizeof(struct channel_list_end_tlv));
1132 qed_iov_send_response(p_hwfn, p_ptt, vf_info, length, status);
1135 struct qed_public_vf_info *qed_iov_get_public_vf_info(struct qed_hwfn *p_hwfn,
1137 bool b_enabled_only)
1139 struct qed_vf_info *vf = NULL;
1141 vf = qed_iov_get_vf_info(p_hwfn, relative_vf_id, b_enabled_only);
1145 return &vf->p_vf_info;
1148 void qed_iov_clean_vf(struct qed_hwfn *p_hwfn, u8 vfid)
1150 struct qed_public_vf_info *vf_info;
1152 vf_info = qed_iov_get_public_vf_info(p_hwfn, vfid, false);
1157 /* Clear the VF mac */
1158 memset(vf_info->mac, 0, ETH_ALEN);
1161 static void qed_iov_vf_cleanup(struct qed_hwfn *p_hwfn,
1162 struct qed_vf_info *p_vf)
1166 p_vf->vf_bulletin = 0;
1167 p_vf->vport_instance = 0;
1168 p_vf->configured_features = 0;
1170 /* If VF previously requested less resources, go back to default */
1171 p_vf->num_rxqs = p_vf->num_sbs;
1172 p_vf->num_txqs = p_vf->num_sbs;
1174 p_vf->num_active_rxqs = 0;
1176 for (i = 0; i < QED_MAX_VF_CHAINS_PER_PF; i++)
1177 p_vf->vf_queues[i].rxq_active = 0;
1179 memset(&p_vf->shadow_config, 0, sizeof(p_vf->shadow_config));
1180 memset(&p_vf->acquire, 0, sizeof(p_vf->acquire));
1181 qed_iov_clean_vf(p_hwfn, p_vf->relative_vf_id);
1184 static u8 qed_iov_vf_mbx_acquire_resc(struct qed_hwfn *p_hwfn,
1185 struct qed_ptt *p_ptt,
1186 struct qed_vf_info *p_vf,
1187 struct vf_pf_resc_request *p_req,
1188 struct pf_vf_resc *p_resp)
1192 /* Queue related information */
1193 p_resp->num_rxqs = p_vf->num_rxqs;
1194 p_resp->num_txqs = p_vf->num_txqs;
1195 p_resp->num_sbs = p_vf->num_sbs;
1197 for (i = 0; i < p_resp->num_sbs; i++) {
1198 p_resp->hw_sbs[i].hw_sb_id = p_vf->igu_sbs[i];
1199 p_resp->hw_sbs[i].sb_qid = 0;
1202 /* These fields are filled for backward compatibility.
1203 * Unused by modern vfs.
1205 for (i = 0; i < p_resp->num_rxqs; i++) {
1206 qed_fw_l2_queue(p_hwfn, p_vf->vf_queues[i].fw_rx_qid,
1207 (u16 *)&p_resp->hw_qid[i]);
1208 p_resp->cid[i] = p_vf->vf_queues[i].fw_cid;
1211 /* Filter related information */
1212 p_resp->num_mac_filters = min_t(u8, p_vf->num_mac_filters,
1213 p_req->num_mac_filters);
1214 p_resp->num_vlan_filters = min_t(u8, p_vf->num_vlan_filters,
1215 p_req->num_vlan_filters);
1217 /* This isn't really needed/enforced, but some legacy VFs might depend
1218 * on the correct filling of this field.
1220 p_resp->num_mc_filters = QED_MAX_MC_ADDRS;
1222 /* Validate sufficient resources for VF */
1223 if (p_resp->num_rxqs < p_req->num_rxqs ||
1224 p_resp->num_txqs < p_req->num_txqs ||
1225 p_resp->num_sbs < p_req->num_sbs ||
1226 p_resp->num_mac_filters < p_req->num_mac_filters ||
1227 p_resp->num_vlan_filters < p_req->num_vlan_filters ||
1228 p_resp->num_mc_filters < p_req->num_mc_filters) {
1231 "VF[%d] - Insufficient resources: rxq [%02x/%02x] txq [%02x/%02x] sbs [%02x/%02x] mac [%02x/%02x] vlan [%02x/%02x] mc [%02x/%02x]\n",
1239 p_req->num_mac_filters,
1240 p_resp->num_mac_filters,
1241 p_req->num_vlan_filters,
1242 p_resp->num_vlan_filters,
1243 p_req->num_mc_filters, p_resp->num_mc_filters);
1244 return PFVF_STATUS_NO_RESOURCE;
1247 return PFVF_STATUS_SUCCESS;
1250 static void qed_iov_vf_mbx_acquire_stats(struct qed_hwfn *p_hwfn,
1251 struct pfvf_stats_info *p_stats)
1253 p_stats->mstats.address = PXP_VF_BAR0_START_MSDM_ZONE_B +
1254 offsetof(struct mstorm_vf_zone,
1255 non_trigger.eth_queue_stat);
1256 p_stats->mstats.len = sizeof(struct eth_mstorm_per_queue_stat);
1257 p_stats->ustats.address = PXP_VF_BAR0_START_USDM_ZONE_B +
1258 offsetof(struct ustorm_vf_zone,
1259 non_trigger.eth_queue_stat);
1260 p_stats->ustats.len = sizeof(struct eth_ustorm_per_queue_stat);
1261 p_stats->pstats.address = PXP_VF_BAR0_START_PSDM_ZONE_B +
1262 offsetof(struct pstorm_vf_zone,
1263 non_trigger.eth_queue_stat);
1264 p_stats->pstats.len = sizeof(struct eth_pstorm_per_queue_stat);
1265 p_stats->tstats.address = 0;
1266 p_stats->tstats.len = 0;
1269 static void qed_iov_vf_mbx_acquire(struct qed_hwfn *p_hwfn,
1270 struct qed_ptt *p_ptt,
1271 struct qed_vf_info *vf)
1273 struct qed_iov_vf_mbx *mbx = &vf->vf_mbx;
1274 struct pfvf_acquire_resp_tlv *resp = &mbx->reply_virt->acquire_resp;
1275 struct pf_vf_pfdev_info *pfdev_info = &resp->pfdev_info;
1276 struct vfpf_acquire_tlv *req = &mbx->req_virt->acquire;
1277 u8 vfpf_status = PFVF_STATUS_NOT_SUPPORTED;
1278 struct pf_vf_resc *resc = &resp->resc;
1281 memset(resp, 0, sizeof(*resp));
1283 /* Validate FW compatibility */
1284 if (req->vfdev_info.eth_fp_hsi_major != ETH_HSI_VER_MAJOR) {
1286 "VF[%d] needs fastpath HSI %02x.%02x, which is incompatible with loaded FW's faspath HSI %02x.%02x\n",
1288 req->vfdev_info.eth_fp_hsi_major,
1289 req->vfdev_info.eth_fp_hsi_minor,
1290 ETH_HSI_VER_MAJOR, ETH_HSI_VER_MINOR);
1292 /* Write the PF version so that VF would know which version
1295 pfdev_info->major_fp_hsi = ETH_HSI_VER_MAJOR;
1296 pfdev_info->minor_fp_hsi = ETH_HSI_VER_MINOR;
1301 /* On 100g PFs, prevent old VFs from loading */
1302 if ((p_hwfn->cdev->num_hwfns > 1) &&
1303 !(req->vfdev_info.capabilities & VFPF_ACQUIRE_CAP_100G)) {
1305 "VF[%d] is running an old driver that doesn't support 100g\n",
1310 /* Store the acquire message */
1311 memcpy(&vf->acquire, req, sizeof(vf->acquire));
1313 vf->opaque_fid = req->vfdev_info.opaque_fid;
1315 vf->vf_bulletin = req->bulletin_addr;
1316 vf->bulletin.size = (vf->bulletin.size < req->bulletin_size) ?
1317 vf->bulletin.size : req->bulletin_size;
1319 /* fill in pfdev info */
1320 pfdev_info->chip_num = p_hwfn->cdev->chip_num;
1321 pfdev_info->db_size = 0;
1322 pfdev_info->indices_per_sb = PIS_PER_SB;
1324 pfdev_info->capabilities = PFVF_ACQUIRE_CAP_DEFAULT_UNTAGGED |
1325 PFVF_ACQUIRE_CAP_POST_FW_OVERRIDE;
1326 if (p_hwfn->cdev->num_hwfns > 1)
1327 pfdev_info->capabilities |= PFVF_ACQUIRE_CAP_100G;
1329 qed_iov_vf_mbx_acquire_stats(p_hwfn, &pfdev_info->stats_info);
1331 memcpy(pfdev_info->port_mac, p_hwfn->hw_info.hw_mac_addr, ETH_ALEN);
1333 pfdev_info->fw_major = FW_MAJOR_VERSION;
1334 pfdev_info->fw_minor = FW_MINOR_VERSION;
1335 pfdev_info->fw_rev = FW_REVISION_VERSION;
1336 pfdev_info->fw_eng = FW_ENGINEERING_VERSION;
1337 pfdev_info->minor_fp_hsi = min_t(u8, ETH_HSI_VER_MINOR,
1338 req->vfdev_info.eth_fp_hsi_minor);
1339 pfdev_info->os_type = VFPF_ACQUIRE_OS_LINUX;
1340 qed_mcp_get_mfw_ver(p_hwfn, p_ptt, &pfdev_info->mfw_ver, NULL);
1342 pfdev_info->dev_type = p_hwfn->cdev->type;
1343 pfdev_info->chip_rev = p_hwfn->cdev->chip_rev;
1345 /* Fill resources available to VF; Make sure there are enough to
1346 * satisfy the VF's request.
1348 vfpf_status = qed_iov_vf_mbx_acquire_resc(p_hwfn, p_ptt, vf,
1349 &req->resc_request, resc);
1350 if (vfpf_status != PFVF_STATUS_SUCCESS)
1353 /* Start the VF in FW */
1354 rc = qed_sp_vf_start(p_hwfn, vf);
1356 DP_NOTICE(p_hwfn, "Failed to start VF[%02x]\n", vf->abs_vf_id);
1357 vfpf_status = PFVF_STATUS_FAILURE;
1361 /* Fill agreed size of bulletin board in response */
1362 resp->bulletin_size = vf->bulletin.size;
1363 qed_iov_post_vf_bulletin(p_hwfn, vf->relative_vf_id, p_ptt);
1367 "VF[%d] ACQUIRE_RESPONSE: pfdev_info- chip_num=0x%x, db_size=%d, idx_per_sb=%d, pf_cap=0x%llx\n"
1368 "resources- n_rxq-%d, n_txq-%d, n_sbs-%d, n_macs-%d, n_vlans-%d\n",
1370 resp->pfdev_info.chip_num,
1371 resp->pfdev_info.db_size,
1372 resp->pfdev_info.indices_per_sb,
1373 resp->pfdev_info.capabilities,
1377 resc->num_mac_filters,
1378 resc->num_vlan_filters);
1379 vf->state = VF_ACQUIRED;
1381 /* Prepare Response */
1383 qed_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_ACQUIRE,
1384 sizeof(struct pfvf_acquire_resp_tlv), vfpf_status);
1387 static int __qed_iov_spoofchk_set(struct qed_hwfn *p_hwfn,
1388 struct qed_vf_info *p_vf, bool val)
1390 struct qed_sp_vport_update_params params;
1393 if (val == p_vf->spoof_chk) {
1394 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
1395 "Spoofchk value[%d] is already configured\n", val);
1399 memset(¶ms, 0, sizeof(struct qed_sp_vport_update_params));
1400 params.opaque_fid = p_vf->opaque_fid;
1401 params.vport_id = p_vf->vport_id;
1402 params.update_anti_spoofing_en_flg = 1;
1403 params.anti_spoofing_en = val;
1405 rc = qed_sp_vport_update(p_hwfn, ¶ms, QED_SPQ_MODE_EBLOCK, NULL);
1407 p_vf->spoof_chk = val;
1408 p_vf->req_spoofchk_val = p_vf->spoof_chk;
1409 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
1410 "Spoofchk val[%d] configured\n", val);
1412 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
1413 "Spoofchk configuration[val:%d] failed for VF[%d]\n",
1414 val, p_vf->relative_vf_id);
1420 static int qed_iov_reconfigure_unicast_vlan(struct qed_hwfn *p_hwfn,
1421 struct qed_vf_info *p_vf)
1423 struct qed_filter_ucast filter;
1427 memset(&filter, 0, sizeof(filter));
1428 filter.is_rx_filter = 1;
1429 filter.is_tx_filter = 1;
1430 filter.vport_to_add_to = p_vf->vport_id;
1431 filter.opcode = QED_FILTER_ADD;
1433 /* Reconfigure vlans */
1434 for (i = 0; i < QED_ETH_VF_NUM_VLAN_FILTERS + 1; i++) {
1435 if (!p_vf->shadow_config.vlans[i].used)
1438 filter.type = QED_FILTER_VLAN;
1439 filter.vlan = p_vf->shadow_config.vlans[i].vid;
1440 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
1441 "Reconfiguring VLAN [0x%04x] for VF [%04x]\n",
1442 filter.vlan, p_vf->relative_vf_id);
1443 rc = qed_sp_eth_filter_ucast(p_hwfn, p_vf->opaque_fid,
1444 &filter, QED_SPQ_MODE_CB, NULL);
1447 "Failed to configure VLAN [%04x] to VF [%04x]\n",
1448 filter.vlan, p_vf->relative_vf_id);
1457 qed_iov_reconfigure_unicast_shadow(struct qed_hwfn *p_hwfn,
1458 struct qed_vf_info *p_vf, u64 events)
1462 if ((events & BIT(VLAN_ADDR_FORCED)) &&
1463 !(p_vf->configured_features & (1 << VLAN_ADDR_FORCED)))
1464 rc = qed_iov_reconfigure_unicast_vlan(p_hwfn, p_vf);
1469 static int qed_iov_configure_vport_forced(struct qed_hwfn *p_hwfn,
1470 struct qed_vf_info *p_vf, u64 events)
1473 struct qed_filter_ucast filter;
1475 if (!p_vf->vport_instance)
1478 if (events & BIT(MAC_ADDR_FORCED)) {
1479 /* Since there's no way [currently] of removing the MAC,
1480 * we can always assume this means we need to force it.
1482 memset(&filter, 0, sizeof(filter));
1483 filter.type = QED_FILTER_MAC;
1484 filter.opcode = QED_FILTER_REPLACE;
1485 filter.is_rx_filter = 1;
1486 filter.is_tx_filter = 1;
1487 filter.vport_to_add_to = p_vf->vport_id;
1488 ether_addr_copy(filter.mac, p_vf->bulletin.p_virt->mac);
1490 rc = qed_sp_eth_filter_ucast(p_hwfn, p_vf->opaque_fid,
1491 &filter, QED_SPQ_MODE_CB, NULL);
1494 "PF failed to configure MAC for VF\n");
1498 p_vf->configured_features |= 1 << MAC_ADDR_FORCED;
1501 if (events & BIT(VLAN_ADDR_FORCED)) {
1502 struct qed_sp_vport_update_params vport_update;
1506 memset(&filter, 0, sizeof(filter));
1507 filter.type = QED_FILTER_VLAN;
1508 filter.is_rx_filter = 1;
1509 filter.is_tx_filter = 1;
1510 filter.vport_to_add_to = p_vf->vport_id;
1511 filter.vlan = p_vf->bulletin.p_virt->pvid;
1512 filter.opcode = filter.vlan ? QED_FILTER_REPLACE :
1515 /* Send the ramrod */
1516 rc = qed_sp_eth_filter_ucast(p_hwfn, p_vf->opaque_fid,
1517 &filter, QED_SPQ_MODE_CB, NULL);
1520 "PF failed to configure VLAN for VF\n");
1524 /* Update the default-vlan & silent vlan stripping */
1525 memset(&vport_update, 0, sizeof(vport_update));
1526 vport_update.opaque_fid = p_vf->opaque_fid;
1527 vport_update.vport_id = p_vf->vport_id;
1528 vport_update.update_default_vlan_enable_flg = 1;
1529 vport_update.default_vlan_enable_flg = filter.vlan ? 1 : 0;
1530 vport_update.update_default_vlan_flg = 1;
1531 vport_update.default_vlan = filter.vlan;
1533 vport_update.update_inner_vlan_removal_flg = 1;
1534 removal = filter.vlan ? 1
1535 : p_vf->shadow_config.inner_vlan_removal;
1536 vport_update.inner_vlan_removal_flg = removal;
1537 vport_update.silent_vlan_removal_flg = filter.vlan ? 1 : 0;
1538 rc = qed_sp_vport_update(p_hwfn,
1540 QED_SPQ_MODE_EBLOCK, NULL);
1543 "PF failed to configure VF vport for vlan\n");
1547 /* Update all the Rx queues */
1548 for (i = 0; i < QED_MAX_VF_CHAINS_PER_PF; i++) {
1551 if (!p_vf->vf_queues[i].rxq_active)
1554 qid = p_vf->vf_queues[i].fw_rx_qid;
1556 rc = qed_sp_eth_rx_queues_update(p_hwfn, qid,
1558 QED_SPQ_MODE_EBLOCK,
1562 "Failed to send Rx update fo queue[0x%04x]\n",
1569 p_vf->configured_features |= 1 << VLAN_ADDR_FORCED;
1571 p_vf->configured_features &= ~BIT(VLAN_ADDR_FORCED);
1574 /* If forced features are terminated, we need to configure the shadow
1575 * configuration back again.
1578 qed_iov_reconfigure_unicast_shadow(p_hwfn, p_vf, events);
1583 static void qed_iov_vf_mbx_start_vport(struct qed_hwfn *p_hwfn,
1584 struct qed_ptt *p_ptt,
1585 struct qed_vf_info *vf)
1587 struct qed_sp_vport_start_params params = { 0 };
1588 struct qed_iov_vf_mbx *mbx = &vf->vf_mbx;
1589 struct vfpf_vport_start_tlv *start;
1590 u8 status = PFVF_STATUS_SUCCESS;
1591 struct qed_vf_info *vf_info;
1596 vf_info = qed_iov_get_vf_info(p_hwfn, (u16) vf->relative_vf_id, true);
1598 DP_NOTICE(p_hwfn->cdev,
1599 "Failed to get VF info, invalid vfid [%d]\n",
1600 vf->relative_vf_id);
1604 vf->state = VF_ENABLED;
1605 start = &mbx->req_virt->start_vport;
1607 /* Initialize Status block in CAU */
1608 for (sb_id = 0; sb_id < vf->num_sbs; sb_id++) {
1609 if (!start->sb_addr[sb_id]) {
1610 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
1611 "VF[%d] did not fill the address of SB %d\n",
1612 vf->relative_vf_id, sb_id);
1616 qed_int_cau_conf_sb(p_hwfn, p_ptt,
1617 start->sb_addr[sb_id],
1618 vf->igu_sbs[sb_id], vf->abs_vf_id, 1);
1620 qed_iov_enable_vf_traffic(p_hwfn, p_ptt, vf);
1622 vf->mtu = start->mtu;
1623 vf->shadow_config.inner_vlan_removal = start->inner_vlan_removal;
1625 /* Take into consideration configuration forced by hypervisor;
1626 * If none is configured, use the supplied VF values [for old
1627 * vfs that would still be fine, since they passed '0' as padding].
1629 p_bitmap = &vf_info->bulletin.p_virt->valid_bitmap;
1630 if (!(*p_bitmap & BIT(VFPF_BULLETIN_UNTAGGED_DEFAULT_FORCED))) {
1631 u8 vf_req = start->only_untagged;
1633 vf_info->bulletin.p_virt->default_only_untagged = vf_req;
1634 *p_bitmap |= 1 << VFPF_BULLETIN_UNTAGGED_DEFAULT;
1637 params.tpa_mode = start->tpa_mode;
1638 params.remove_inner_vlan = start->inner_vlan_removal;
1639 params.tx_switching = true;
1641 params.only_untagged = vf_info->bulletin.p_virt->default_only_untagged;
1642 params.drop_ttl0 = false;
1643 params.concrete_fid = vf->concrete_fid;
1644 params.opaque_fid = vf->opaque_fid;
1645 params.vport_id = vf->vport_id;
1646 params.max_buffers_per_cqe = start->max_buffers_per_cqe;
1647 params.mtu = vf->mtu;
1649 rc = qed_sp_eth_vport_start(p_hwfn, ¶ms);
1652 "qed_iov_vf_mbx_start_vport returned error %d\n", rc);
1653 status = PFVF_STATUS_FAILURE;
1655 vf->vport_instance++;
1657 /* Force configuration if needed on the newly opened vport */
1658 qed_iov_configure_vport_forced(p_hwfn, vf, *p_bitmap);
1660 __qed_iov_spoofchk_set(p_hwfn, vf, vf->req_spoofchk_val);
1662 qed_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_VPORT_START,
1663 sizeof(struct pfvf_def_resp_tlv), status);
1666 static void qed_iov_vf_mbx_stop_vport(struct qed_hwfn *p_hwfn,
1667 struct qed_ptt *p_ptt,
1668 struct qed_vf_info *vf)
1670 u8 status = PFVF_STATUS_SUCCESS;
1673 vf->vport_instance--;
1674 vf->spoof_chk = false;
1676 rc = qed_sp_vport_stop(p_hwfn, vf->opaque_fid, vf->vport_id);
1678 DP_ERR(p_hwfn, "qed_iov_vf_mbx_stop_vport returned error %d\n",
1680 status = PFVF_STATUS_FAILURE;
1683 /* Forget the configuration on the vport */
1684 vf->configured_features = 0;
1685 memset(&vf->shadow_config, 0, sizeof(vf->shadow_config));
1687 qed_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_VPORT_TEARDOWN,
1688 sizeof(struct pfvf_def_resp_tlv), status);
1691 static void qed_iov_vf_mbx_start_rxq_resp(struct qed_hwfn *p_hwfn,
1692 struct qed_ptt *p_ptt,
1693 struct qed_vf_info *vf, u8 status)
1695 struct qed_iov_vf_mbx *mbx = &vf->vf_mbx;
1696 struct pfvf_start_queue_resp_tlv *p_tlv;
1697 struct vfpf_start_rxq_tlv *req;
1699 mbx->offset = (u8 *)mbx->reply_virt;
1701 p_tlv = qed_add_tlv(p_hwfn, &mbx->offset, CHANNEL_TLV_START_RXQ,
1703 qed_add_tlv(p_hwfn, &mbx->offset, CHANNEL_TLV_LIST_END,
1704 sizeof(struct channel_list_end_tlv));
1706 /* Update the TLV with the response */
1707 if (status == PFVF_STATUS_SUCCESS) {
1708 req = &mbx->req_virt->start_rxq;
1709 p_tlv->offset = PXP_VF_BAR0_START_MSDM_ZONE_B +
1710 offsetof(struct mstorm_vf_zone,
1711 non_trigger.eth_rx_queue_producers) +
1712 sizeof(struct eth_rx_prod_data) * req->rx_qid;
1715 qed_iov_send_response(p_hwfn, p_ptt, vf, sizeof(*p_tlv), status);
1718 static void qed_iov_vf_mbx_start_rxq(struct qed_hwfn *p_hwfn,
1719 struct qed_ptt *p_ptt,
1720 struct qed_vf_info *vf)
1722 struct qed_queue_start_common_params params;
1723 struct qed_iov_vf_mbx *mbx = &vf->vf_mbx;
1724 u8 status = PFVF_STATUS_NO_RESOURCE;
1725 struct vfpf_start_rxq_tlv *req;
1728 memset(¶ms, 0, sizeof(params));
1729 req = &mbx->req_virt->start_rxq;
1731 if (!qed_iov_validate_rxq(p_hwfn, vf, req->rx_qid) ||
1732 !qed_iov_validate_sb(p_hwfn, vf, req->hw_sb))
1735 params.queue_id = vf->vf_queues[req->rx_qid].fw_rx_qid;
1736 params.vf_qid = req->rx_qid;
1737 params.vport_id = vf->vport_id;
1738 params.sb = req->hw_sb;
1739 params.sb_idx = req->sb_index;
1741 rc = qed_sp_eth_rxq_start_ramrod(p_hwfn, vf->opaque_fid,
1742 vf->vf_queues[req->rx_qid].fw_cid,
1744 vf->abs_vf_id + 0x10,
1747 req->cqe_pbl_addr, req->cqe_pbl_size);
1750 status = PFVF_STATUS_FAILURE;
1752 status = PFVF_STATUS_SUCCESS;
1753 vf->vf_queues[req->rx_qid].rxq_active = true;
1754 vf->num_active_rxqs++;
1758 qed_iov_vf_mbx_start_rxq_resp(p_hwfn, p_ptt, vf, status);
1761 static void qed_iov_vf_mbx_start_txq_resp(struct qed_hwfn *p_hwfn,
1762 struct qed_ptt *p_ptt,
1763 struct qed_vf_info *p_vf, u8 status)
1765 struct qed_iov_vf_mbx *mbx = &p_vf->vf_mbx;
1766 struct pfvf_start_queue_resp_tlv *p_tlv;
1768 mbx->offset = (u8 *)mbx->reply_virt;
1770 p_tlv = qed_add_tlv(p_hwfn, &mbx->offset, CHANNEL_TLV_START_TXQ,
1772 qed_add_tlv(p_hwfn, &mbx->offset, CHANNEL_TLV_LIST_END,
1773 sizeof(struct channel_list_end_tlv));
1775 /* Update the TLV with the response */
1776 if (status == PFVF_STATUS_SUCCESS) {
1777 u16 qid = mbx->req_virt->start_txq.tx_qid;
1779 p_tlv->offset = qed_db_addr(p_vf->vf_queues[qid].fw_cid,
1783 qed_iov_send_response(p_hwfn, p_ptt, p_vf, sizeof(*p_tlv), status);
1786 static void qed_iov_vf_mbx_start_txq(struct qed_hwfn *p_hwfn,
1787 struct qed_ptt *p_ptt,
1788 struct qed_vf_info *vf)
1790 struct qed_queue_start_common_params params;
1791 struct qed_iov_vf_mbx *mbx = &vf->vf_mbx;
1792 u8 status = PFVF_STATUS_NO_RESOURCE;
1793 union qed_qm_pq_params pq_params;
1794 struct vfpf_start_txq_tlv *req;
1797 /* Prepare the parameters which would choose the right PQ */
1798 memset(&pq_params, 0, sizeof(pq_params));
1799 pq_params.eth.is_vf = 1;
1800 pq_params.eth.vf_id = vf->relative_vf_id;
1802 memset(¶ms, 0, sizeof(params));
1803 req = &mbx->req_virt->start_txq;
1805 if (!qed_iov_validate_txq(p_hwfn, vf, req->tx_qid) ||
1806 !qed_iov_validate_sb(p_hwfn, vf, req->hw_sb))
1809 params.queue_id = vf->vf_queues[req->tx_qid].fw_tx_qid;
1810 params.vport_id = vf->vport_id;
1811 params.sb = req->hw_sb;
1812 params.sb_idx = req->sb_index;
1814 rc = qed_sp_eth_txq_start_ramrod(p_hwfn,
1816 vf->vf_queues[req->tx_qid].fw_cid,
1818 vf->abs_vf_id + 0x10,
1820 req->pbl_size, &pq_params);
1823 status = PFVF_STATUS_FAILURE;
1825 status = PFVF_STATUS_SUCCESS;
1826 vf->vf_queues[req->tx_qid].txq_active = true;
1830 qed_iov_vf_mbx_start_txq_resp(p_hwfn, p_ptt, vf, status);
1833 static int qed_iov_vf_stop_rxqs(struct qed_hwfn *p_hwfn,
1834 struct qed_vf_info *vf,
1835 u16 rxq_id, u8 num_rxqs, bool cqe_completion)
1840 if (rxq_id + num_rxqs > ARRAY_SIZE(vf->vf_queues))
1843 for (qid = rxq_id; qid < rxq_id + num_rxqs; qid++) {
1844 if (vf->vf_queues[qid].rxq_active) {
1845 rc = qed_sp_eth_rx_queue_stop(p_hwfn,
1853 vf->vf_queues[qid].rxq_active = false;
1854 vf->num_active_rxqs--;
1860 static int qed_iov_vf_stop_txqs(struct qed_hwfn *p_hwfn,
1861 struct qed_vf_info *vf, u16 txq_id, u8 num_txqs)
1866 if (txq_id + num_txqs > ARRAY_SIZE(vf->vf_queues))
1869 for (qid = txq_id; qid < txq_id + num_txqs; qid++) {
1870 if (vf->vf_queues[qid].txq_active) {
1871 rc = qed_sp_eth_tx_queue_stop(p_hwfn,
1878 vf->vf_queues[qid].txq_active = false;
1883 static void qed_iov_vf_mbx_stop_rxqs(struct qed_hwfn *p_hwfn,
1884 struct qed_ptt *p_ptt,
1885 struct qed_vf_info *vf)
1887 u16 length = sizeof(struct pfvf_def_resp_tlv);
1888 struct qed_iov_vf_mbx *mbx = &vf->vf_mbx;
1889 u8 status = PFVF_STATUS_SUCCESS;
1890 struct vfpf_stop_rxqs_tlv *req;
1893 /* We give the option of starting from qid != 0, in this case we
1894 * need to make sure that qid + num_qs doesn't exceed the actual
1895 * amount of queues that exist.
1897 req = &mbx->req_virt->stop_rxqs;
1898 rc = qed_iov_vf_stop_rxqs(p_hwfn, vf, req->rx_qid,
1899 req->num_rxqs, req->cqe_completion);
1901 status = PFVF_STATUS_FAILURE;
1903 qed_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_STOP_RXQS,
1907 static void qed_iov_vf_mbx_stop_txqs(struct qed_hwfn *p_hwfn,
1908 struct qed_ptt *p_ptt,
1909 struct qed_vf_info *vf)
1911 u16 length = sizeof(struct pfvf_def_resp_tlv);
1912 struct qed_iov_vf_mbx *mbx = &vf->vf_mbx;
1913 u8 status = PFVF_STATUS_SUCCESS;
1914 struct vfpf_stop_txqs_tlv *req;
1917 /* We give the option of starting from qid != 0, in this case we
1918 * need to make sure that qid + num_qs doesn't exceed the actual
1919 * amount of queues that exist.
1921 req = &mbx->req_virt->stop_txqs;
1922 rc = qed_iov_vf_stop_txqs(p_hwfn, vf, req->tx_qid, req->num_txqs);
1924 status = PFVF_STATUS_FAILURE;
1926 qed_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_STOP_TXQS,
1930 static void qed_iov_vf_mbx_update_rxqs(struct qed_hwfn *p_hwfn,
1931 struct qed_ptt *p_ptt,
1932 struct qed_vf_info *vf)
1934 u16 length = sizeof(struct pfvf_def_resp_tlv);
1935 struct qed_iov_vf_mbx *mbx = &vf->vf_mbx;
1936 struct vfpf_update_rxq_tlv *req;
1937 u8 status = PFVF_STATUS_SUCCESS;
1938 u8 complete_event_flg;
1939 u8 complete_cqe_flg;
1944 req = &mbx->req_virt->update_rxq;
1945 complete_cqe_flg = !!(req->flags & VFPF_RXQ_UPD_COMPLETE_CQE_FLAG);
1946 complete_event_flg = !!(req->flags & VFPF_RXQ_UPD_COMPLETE_EVENT_FLAG);
1948 for (i = 0; i < req->num_rxqs; i++) {
1949 qid = req->rx_qid + i;
1951 if (!vf->vf_queues[qid].rxq_active) {
1952 DP_NOTICE(p_hwfn, "VF rx_qid = %d isn`t active!\n",
1954 status = PFVF_STATUS_FAILURE;
1958 rc = qed_sp_eth_rx_queues_update(p_hwfn,
1959 vf->vf_queues[qid].fw_rx_qid,
1963 QED_SPQ_MODE_EBLOCK, NULL);
1966 status = PFVF_STATUS_FAILURE;
1971 qed_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_UPDATE_RXQ,
1975 void *qed_iov_search_list_tlvs(struct qed_hwfn *p_hwfn,
1976 void *p_tlvs_list, u16 req_type)
1978 struct channel_tlv *p_tlv = (struct channel_tlv *)p_tlvs_list;
1982 if (!p_tlv->length) {
1983 DP_NOTICE(p_hwfn, "Zero length TLV found\n");
1987 if (p_tlv->type == req_type) {
1988 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
1989 "Extended tlv type %d, length %d found\n",
1990 p_tlv->type, p_tlv->length);
1994 len += p_tlv->length;
1995 p_tlv = (struct channel_tlv *)((u8 *)p_tlv + p_tlv->length);
1997 if ((len + p_tlv->length) > TLV_BUFFER_SIZE) {
1998 DP_NOTICE(p_hwfn, "TLVs has overrun the buffer size\n");
2001 } while (p_tlv->type != CHANNEL_TLV_LIST_END);
2007 qed_iov_vp_update_act_param(struct qed_hwfn *p_hwfn,
2008 struct qed_sp_vport_update_params *p_data,
2009 struct qed_iov_vf_mbx *p_mbx, u16 *tlvs_mask)
2011 struct vfpf_vport_update_activate_tlv *p_act_tlv;
2012 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_ACTIVATE;
2014 p_act_tlv = (struct vfpf_vport_update_activate_tlv *)
2015 qed_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
2019 p_data->update_vport_active_rx_flg = p_act_tlv->update_rx;
2020 p_data->vport_active_rx_flg = p_act_tlv->active_rx;
2021 p_data->update_vport_active_tx_flg = p_act_tlv->update_tx;
2022 p_data->vport_active_tx_flg = p_act_tlv->active_tx;
2023 *tlvs_mask |= 1 << QED_IOV_VP_UPDATE_ACTIVATE;
2027 qed_iov_vp_update_vlan_param(struct qed_hwfn *p_hwfn,
2028 struct qed_sp_vport_update_params *p_data,
2029 struct qed_vf_info *p_vf,
2030 struct qed_iov_vf_mbx *p_mbx, u16 *tlvs_mask)
2032 struct vfpf_vport_update_vlan_strip_tlv *p_vlan_tlv;
2033 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_VLAN_STRIP;
2035 p_vlan_tlv = (struct vfpf_vport_update_vlan_strip_tlv *)
2036 qed_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
2040 p_vf->shadow_config.inner_vlan_removal = p_vlan_tlv->remove_vlan;
2042 /* Ignore the VF request if we're forcing a vlan */
2043 if (!(p_vf->configured_features & BIT(VLAN_ADDR_FORCED))) {
2044 p_data->update_inner_vlan_removal_flg = 1;
2045 p_data->inner_vlan_removal_flg = p_vlan_tlv->remove_vlan;
2048 *tlvs_mask |= 1 << QED_IOV_VP_UPDATE_VLAN_STRIP;
2052 qed_iov_vp_update_tx_switch(struct qed_hwfn *p_hwfn,
2053 struct qed_sp_vport_update_params *p_data,
2054 struct qed_iov_vf_mbx *p_mbx, u16 *tlvs_mask)
2056 struct vfpf_vport_update_tx_switch_tlv *p_tx_switch_tlv;
2057 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_TX_SWITCH;
2059 p_tx_switch_tlv = (struct vfpf_vport_update_tx_switch_tlv *)
2060 qed_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt,
2062 if (!p_tx_switch_tlv)
2065 p_data->update_tx_switching_flg = 1;
2066 p_data->tx_switching_flg = p_tx_switch_tlv->tx_switching;
2067 *tlvs_mask |= 1 << QED_IOV_VP_UPDATE_TX_SWITCH;
2071 qed_iov_vp_update_mcast_bin_param(struct qed_hwfn *p_hwfn,
2072 struct qed_sp_vport_update_params *p_data,
2073 struct qed_iov_vf_mbx *p_mbx, u16 *tlvs_mask)
2075 struct vfpf_vport_update_mcast_bin_tlv *p_mcast_tlv;
2076 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_MCAST;
2078 p_mcast_tlv = (struct vfpf_vport_update_mcast_bin_tlv *)
2079 qed_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
2083 p_data->update_approx_mcast_flg = 1;
2084 memcpy(p_data->bins, p_mcast_tlv->bins,
2085 sizeof(unsigned long) * ETH_MULTICAST_MAC_BINS_IN_REGS);
2086 *tlvs_mask |= 1 << QED_IOV_VP_UPDATE_MCAST;
2090 qed_iov_vp_update_accept_flag(struct qed_hwfn *p_hwfn,
2091 struct qed_sp_vport_update_params *p_data,
2092 struct qed_iov_vf_mbx *p_mbx, u16 *tlvs_mask)
2094 struct qed_filter_accept_flags *p_flags = &p_data->accept_flags;
2095 struct vfpf_vport_update_accept_param_tlv *p_accept_tlv;
2096 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_ACCEPT_PARAM;
2098 p_accept_tlv = (struct vfpf_vport_update_accept_param_tlv *)
2099 qed_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
2103 p_flags->update_rx_mode_config = p_accept_tlv->update_rx_mode;
2104 p_flags->rx_accept_filter = p_accept_tlv->rx_accept_filter;
2105 p_flags->update_tx_mode_config = p_accept_tlv->update_tx_mode;
2106 p_flags->tx_accept_filter = p_accept_tlv->tx_accept_filter;
2107 *tlvs_mask |= 1 << QED_IOV_VP_UPDATE_ACCEPT_PARAM;
2111 qed_iov_vp_update_accept_any_vlan(struct qed_hwfn *p_hwfn,
2112 struct qed_sp_vport_update_params *p_data,
2113 struct qed_iov_vf_mbx *p_mbx, u16 *tlvs_mask)
2115 struct vfpf_vport_update_accept_any_vlan_tlv *p_accept_any_vlan;
2116 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_ACCEPT_ANY_VLAN;
2118 p_accept_any_vlan = (struct vfpf_vport_update_accept_any_vlan_tlv *)
2119 qed_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt,
2121 if (!p_accept_any_vlan)
2124 p_data->accept_any_vlan = p_accept_any_vlan->accept_any_vlan;
2125 p_data->update_accept_any_vlan_flg =
2126 p_accept_any_vlan->update_accept_any_vlan_flg;
2127 *tlvs_mask |= 1 << QED_IOV_VP_UPDATE_ACCEPT_ANY_VLAN;
2131 qed_iov_vp_update_rss_param(struct qed_hwfn *p_hwfn,
2132 struct qed_vf_info *vf,
2133 struct qed_sp_vport_update_params *p_data,
2134 struct qed_rss_params *p_rss,
2135 struct qed_iov_vf_mbx *p_mbx, u16 *tlvs_mask)
2137 struct vfpf_vport_update_rss_tlv *p_rss_tlv;
2138 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_RSS;
2139 u16 i, q_idx, max_q_idx;
2142 p_rss_tlv = (struct vfpf_vport_update_rss_tlv *)
2143 qed_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
2145 p_data->rss_params = NULL;
2149 memset(p_rss, 0, sizeof(struct qed_rss_params));
2151 p_rss->update_rss_config = !!(p_rss_tlv->update_rss_flags &
2152 VFPF_UPDATE_RSS_CONFIG_FLAG);
2153 p_rss->update_rss_capabilities = !!(p_rss_tlv->update_rss_flags &
2154 VFPF_UPDATE_RSS_CAPS_FLAG);
2155 p_rss->update_rss_ind_table = !!(p_rss_tlv->update_rss_flags &
2156 VFPF_UPDATE_RSS_IND_TABLE_FLAG);
2157 p_rss->update_rss_key = !!(p_rss_tlv->update_rss_flags &
2158 VFPF_UPDATE_RSS_KEY_FLAG);
2160 p_rss->rss_enable = p_rss_tlv->rss_enable;
2161 p_rss->rss_eng_id = vf->relative_vf_id + 1;
2162 p_rss->rss_caps = p_rss_tlv->rss_caps;
2163 p_rss->rss_table_size_log = p_rss_tlv->rss_table_size_log;
2164 memcpy(p_rss->rss_ind_table, p_rss_tlv->rss_ind_table,
2165 sizeof(p_rss->rss_ind_table));
2166 memcpy(p_rss->rss_key, p_rss_tlv->rss_key, sizeof(p_rss->rss_key));
2168 table_size = min_t(u16, ARRAY_SIZE(p_rss->rss_ind_table),
2169 (1 << p_rss_tlv->rss_table_size_log));
2171 max_q_idx = ARRAY_SIZE(vf->vf_queues);
2173 for (i = 0; i < table_size; i++) {
2174 u16 index = vf->vf_queues[0].fw_rx_qid;
2176 q_idx = p_rss->rss_ind_table[i];
2177 if (q_idx >= max_q_idx)
2179 "rss_ind_table[%d] = %d, rxq is out of range\n",
2181 else if (!vf->vf_queues[q_idx].rxq_active)
2183 "rss_ind_table[%d] = %d, rxq is not active\n",
2186 index = vf->vf_queues[q_idx].fw_rx_qid;
2187 p_rss->rss_ind_table[i] = index;
2190 p_data->rss_params = p_rss;
2191 *tlvs_mask |= 1 << QED_IOV_VP_UPDATE_RSS;
2195 qed_iov_vp_update_sge_tpa_param(struct qed_hwfn *p_hwfn,
2196 struct qed_vf_info *vf,
2197 struct qed_sp_vport_update_params *p_data,
2198 struct qed_sge_tpa_params *p_sge_tpa,
2199 struct qed_iov_vf_mbx *p_mbx, u16 *tlvs_mask)
2201 struct vfpf_vport_update_sge_tpa_tlv *p_sge_tpa_tlv;
2202 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_SGE_TPA;
2204 p_sge_tpa_tlv = (struct vfpf_vport_update_sge_tpa_tlv *)
2205 qed_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
2207 if (!p_sge_tpa_tlv) {
2208 p_data->sge_tpa_params = NULL;
2212 memset(p_sge_tpa, 0, sizeof(struct qed_sge_tpa_params));
2214 p_sge_tpa->update_tpa_en_flg =
2215 !!(p_sge_tpa_tlv->update_sge_tpa_flags & VFPF_UPDATE_TPA_EN_FLAG);
2216 p_sge_tpa->update_tpa_param_flg =
2217 !!(p_sge_tpa_tlv->update_sge_tpa_flags &
2218 VFPF_UPDATE_TPA_PARAM_FLAG);
2220 p_sge_tpa->tpa_ipv4_en_flg =
2221 !!(p_sge_tpa_tlv->sge_tpa_flags & VFPF_TPA_IPV4_EN_FLAG);
2222 p_sge_tpa->tpa_ipv6_en_flg =
2223 !!(p_sge_tpa_tlv->sge_tpa_flags & VFPF_TPA_IPV6_EN_FLAG);
2224 p_sge_tpa->tpa_pkt_split_flg =
2225 !!(p_sge_tpa_tlv->sge_tpa_flags & VFPF_TPA_PKT_SPLIT_FLAG);
2226 p_sge_tpa->tpa_hdr_data_split_flg =
2227 !!(p_sge_tpa_tlv->sge_tpa_flags & VFPF_TPA_HDR_DATA_SPLIT_FLAG);
2228 p_sge_tpa->tpa_gro_consistent_flg =
2229 !!(p_sge_tpa_tlv->sge_tpa_flags & VFPF_TPA_GRO_CONSIST_FLAG);
2231 p_sge_tpa->tpa_max_aggs_num = p_sge_tpa_tlv->tpa_max_aggs_num;
2232 p_sge_tpa->tpa_max_size = p_sge_tpa_tlv->tpa_max_size;
2233 p_sge_tpa->tpa_min_size_to_start = p_sge_tpa_tlv->tpa_min_size_to_start;
2234 p_sge_tpa->tpa_min_size_to_cont = p_sge_tpa_tlv->tpa_min_size_to_cont;
2235 p_sge_tpa->max_buffers_per_cqe = p_sge_tpa_tlv->max_buffers_per_cqe;
2237 p_data->sge_tpa_params = p_sge_tpa;
2239 *tlvs_mask |= 1 << QED_IOV_VP_UPDATE_SGE_TPA;
2242 static void qed_iov_vf_mbx_vport_update(struct qed_hwfn *p_hwfn,
2243 struct qed_ptt *p_ptt,
2244 struct qed_vf_info *vf)
2246 struct qed_sp_vport_update_params params;
2247 struct qed_iov_vf_mbx *mbx = &vf->vf_mbx;
2248 struct qed_sge_tpa_params sge_tpa_params;
2249 struct qed_rss_params rss_params;
2250 u8 status = PFVF_STATUS_SUCCESS;
2255 /* Valiate PF can send such a request */
2256 if (!vf->vport_instance) {
2259 "No VPORT instance available for VF[%d], failing vport update\n",
2261 status = PFVF_STATUS_FAILURE;
2265 memset(¶ms, 0, sizeof(params));
2266 params.opaque_fid = vf->opaque_fid;
2267 params.vport_id = vf->vport_id;
2268 params.rss_params = NULL;
2270 /* Search for extended tlvs list and update values
2271 * from VF in struct qed_sp_vport_update_params.
2273 qed_iov_vp_update_act_param(p_hwfn, ¶ms, mbx, &tlvs_mask);
2274 qed_iov_vp_update_vlan_param(p_hwfn, ¶ms, vf, mbx, &tlvs_mask);
2275 qed_iov_vp_update_tx_switch(p_hwfn, ¶ms, mbx, &tlvs_mask);
2276 qed_iov_vp_update_mcast_bin_param(p_hwfn, ¶ms, mbx, &tlvs_mask);
2277 qed_iov_vp_update_accept_flag(p_hwfn, ¶ms, mbx, &tlvs_mask);
2278 qed_iov_vp_update_rss_param(p_hwfn, vf, ¶ms, &rss_params,
2280 qed_iov_vp_update_accept_any_vlan(p_hwfn, ¶ms, mbx, &tlvs_mask);
2281 qed_iov_vp_update_sge_tpa_param(p_hwfn, vf, ¶ms,
2282 &sge_tpa_params, mbx, &tlvs_mask);
2284 /* Just log a message if there is no single extended tlv in buffer.
2285 * When all features of vport update ramrod would be requested by VF
2286 * as extended TLVs in buffer then an error can be returned in response
2287 * if there is no extended TLV present in buffer.
2291 "No feature tlvs found for vport update\n");
2292 status = PFVF_STATUS_NOT_SUPPORTED;
2296 rc = qed_sp_vport_update(p_hwfn, ¶ms, QED_SPQ_MODE_EBLOCK, NULL);
2299 status = PFVF_STATUS_FAILURE;
2302 length = qed_iov_prep_vp_update_resp_tlvs(p_hwfn, vf, mbx, status,
2303 tlvs_mask, tlvs_mask);
2304 qed_iov_send_response(p_hwfn, p_ptt, vf, length, status);
2307 static int qed_iov_vf_update_vlan_shadow(struct qed_hwfn *p_hwfn,
2308 struct qed_vf_info *p_vf,
2309 struct qed_filter_ucast *p_params)
2313 /* First remove entries and then add new ones */
2314 if (p_params->opcode == QED_FILTER_REMOVE) {
2315 for (i = 0; i < QED_ETH_VF_NUM_VLAN_FILTERS + 1; i++)
2316 if (p_vf->shadow_config.vlans[i].used &&
2317 p_vf->shadow_config.vlans[i].vid ==
2319 p_vf->shadow_config.vlans[i].used = false;
2322 if (i == QED_ETH_VF_NUM_VLAN_FILTERS + 1) {
2325 "VF [%d] - Tries to remove a non-existing vlan\n",
2326 p_vf->relative_vf_id);
2329 } else if (p_params->opcode == QED_FILTER_REPLACE ||
2330 p_params->opcode == QED_FILTER_FLUSH) {
2331 for (i = 0; i < QED_ETH_VF_NUM_VLAN_FILTERS + 1; i++)
2332 p_vf->shadow_config.vlans[i].used = false;
2335 /* In forced mode, we're willing to remove entries - but we don't add
2338 if (p_vf->bulletin.p_virt->valid_bitmap & BIT(VLAN_ADDR_FORCED))
2341 if (p_params->opcode == QED_FILTER_ADD ||
2342 p_params->opcode == QED_FILTER_REPLACE) {
2343 for (i = 0; i < QED_ETH_VF_NUM_VLAN_FILTERS + 1; i++) {
2344 if (p_vf->shadow_config.vlans[i].used)
2347 p_vf->shadow_config.vlans[i].used = true;
2348 p_vf->shadow_config.vlans[i].vid = p_params->vlan;
2352 if (i == QED_ETH_VF_NUM_VLAN_FILTERS + 1) {
2355 "VF [%d] - Tries to configure more than %d vlan filters\n",
2356 p_vf->relative_vf_id,
2357 QED_ETH_VF_NUM_VLAN_FILTERS + 1);
2365 static int qed_iov_vf_update_mac_shadow(struct qed_hwfn *p_hwfn,
2366 struct qed_vf_info *p_vf,
2367 struct qed_filter_ucast *p_params)
2371 /* If we're in forced-mode, we don't allow any change */
2372 if (p_vf->bulletin.p_virt->valid_bitmap & BIT(MAC_ADDR_FORCED))
2375 /* First remove entries and then add new ones */
2376 if (p_params->opcode == QED_FILTER_REMOVE) {
2377 for (i = 0; i < QED_ETH_VF_NUM_MAC_FILTERS; i++) {
2378 if (ether_addr_equal(p_vf->shadow_config.macs[i],
2380 memset(p_vf->shadow_config.macs[i], 0,
2386 if (i == QED_ETH_VF_NUM_MAC_FILTERS) {
2387 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
2388 "MAC isn't configured\n");
2391 } else if (p_params->opcode == QED_FILTER_REPLACE ||
2392 p_params->opcode == QED_FILTER_FLUSH) {
2393 for (i = 0; i < QED_ETH_VF_NUM_MAC_FILTERS; i++)
2394 memset(p_vf->shadow_config.macs[i], 0, ETH_ALEN);
2397 /* List the new MAC address */
2398 if (p_params->opcode != QED_FILTER_ADD &&
2399 p_params->opcode != QED_FILTER_REPLACE)
2402 for (i = 0; i < QED_ETH_VF_NUM_MAC_FILTERS; i++) {
2403 if (is_zero_ether_addr(p_vf->shadow_config.macs[i])) {
2404 ether_addr_copy(p_vf->shadow_config.macs[i],
2406 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
2407 "Added MAC at %d entry in shadow\n", i);
2412 if (i == QED_ETH_VF_NUM_MAC_FILTERS) {
2413 DP_VERBOSE(p_hwfn, QED_MSG_IOV, "No available place for MAC\n");
2421 qed_iov_vf_update_unicast_shadow(struct qed_hwfn *p_hwfn,
2422 struct qed_vf_info *p_vf,
2423 struct qed_filter_ucast *p_params)
2427 if (p_params->type == QED_FILTER_MAC) {
2428 rc = qed_iov_vf_update_mac_shadow(p_hwfn, p_vf, p_params);
2433 if (p_params->type == QED_FILTER_VLAN)
2434 rc = qed_iov_vf_update_vlan_shadow(p_hwfn, p_vf, p_params);
2439 int qed_iov_chk_ucast(struct qed_hwfn *hwfn,
2440 int vfid, struct qed_filter_ucast *params)
2442 struct qed_public_vf_info *vf;
2444 vf = qed_iov_get_public_vf_info(hwfn, vfid, true);
2448 /* No real decision to make; Store the configured MAC */
2449 if (params->type == QED_FILTER_MAC ||
2450 params->type == QED_FILTER_MAC_VLAN)
2451 ether_addr_copy(vf->mac, params->mac);
2456 static void qed_iov_vf_mbx_ucast_filter(struct qed_hwfn *p_hwfn,
2457 struct qed_ptt *p_ptt,
2458 struct qed_vf_info *vf)
2460 struct qed_bulletin_content *p_bulletin = vf->bulletin.p_virt;
2461 struct qed_iov_vf_mbx *mbx = &vf->vf_mbx;
2462 struct vfpf_ucast_filter_tlv *req;
2463 u8 status = PFVF_STATUS_SUCCESS;
2464 struct qed_filter_ucast params;
2467 /* Prepare the unicast filter params */
2468 memset(¶ms, 0, sizeof(struct qed_filter_ucast));
2469 req = &mbx->req_virt->ucast_filter;
2470 params.opcode = (enum qed_filter_opcode)req->opcode;
2471 params.type = (enum qed_filter_ucast_type)req->type;
2473 params.is_rx_filter = 1;
2474 params.is_tx_filter = 1;
2475 params.vport_to_remove_from = vf->vport_id;
2476 params.vport_to_add_to = vf->vport_id;
2477 memcpy(params.mac, req->mac, ETH_ALEN);
2478 params.vlan = req->vlan;
2482 "VF[%d]: opcode 0x%02x type 0x%02x [%s %s] [vport 0x%02x] MAC %02x:%02x:%02x:%02x:%02x:%02x, vlan 0x%04x\n",
2483 vf->abs_vf_id, params.opcode, params.type,
2484 params.is_rx_filter ? "RX" : "",
2485 params.is_tx_filter ? "TX" : "",
2486 params.vport_to_add_to,
2487 params.mac[0], params.mac[1],
2488 params.mac[2], params.mac[3],
2489 params.mac[4], params.mac[5], params.vlan);
2491 if (!vf->vport_instance) {
2494 "No VPORT instance available for VF[%d], failing ucast MAC configuration\n",
2496 status = PFVF_STATUS_FAILURE;
2500 /* Update shadow copy of the VF configuration */
2501 if (qed_iov_vf_update_unicast_shadow(p_hwfn, vf, ¶ms)) {
2502 status = PFVF_STATUS_FAILURE;
2506 /* Determine if the unicast filtering is acceptible by PF */
2507 if ((p_bulletin->valid_bitmap & BIT(VLAN_ADDR_FORCED)) &&
2508 (params.type == QED_FILTER_VLAN ||
2509 params.type == QED_FILTER_MAC_VLAN)) {
2510 /* Once VLAN is forced or PVID is set, do not allow
2511 * to add/replace any further VLANs.
2513 if (params.opcode == QED_FILTER_ADD ||
2514 params.opcode == QED_FILTER_REPLACE)
2515 status = PFVF_STATUS_FORCED;
2519 if ((p_bulletin->valid_bitmap & BIT(MAC_ADDR_FORCED)) &&
2520 (params.type == QED_FILTER_MAC ||
2521 params.type == QED_FILTER_MAC_VLAN)) {
2522 if (!ether_addr_equal(p_bulletin->mac, params.mac) ||
2523 (params.opcode != QED_FILTER_ADD &&
2524 params.opcode != QED_FILTER_REPLACE))
2525 status = PFVF_STATUS_FORCED;
2529 rc = qed_iov_chk_ucast(p_hwfn, vf->relative_vf_id, ¶ms);
2531 status = PFVF_STATUS_FAILURE;
2535 rc = qed_sp_eth_filter_ucast(p_hwfn, vf->opaque_fid, ¶ms,
2536 QED_SPQ_MODE_CB, NULL);
2538 status = PFVF_STATUS_FAILURE;
2541 qed_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_UCAST_FILTER,
2542 sizeof(struct pfvf_def_resp_tlv), status);
2545 static void qed_iov_vf_mbx_int_cleanup(struct qed_hwfn *p_hwfn,
2546 struct qed_ptt *p_ptt,
2547 struct qed_vf_info *vf)
2552 for (i = 0; i < vf->num_sbs; i++)
2553 qed_int_igu_init_pure_rt_single(p_hwfn, p_ptt,
2555 vf->opaque_fid, false);
2557 qed_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_INT_CLEANUP,
2558 sizeof(struct pfvf_def_resp_tlv),
2559 PFVF_STATUS_SUCCESS);
2562 static void qed_iov_vf_mbx_close(struct qed_hwfn *p_hwfn,
2563 struct qed_ptt *p_ptt, struct qed_vf_info *vf)
2565 u16 length = sizeof(struct pfvf_def_resp_tlv);
2566 u8 status = PFVF_STATUS_SUCCESS;
2568 /* Disable Interrupts for VF */
2569 qed_iov_vf_igu_set_int(p_hwfn, p_ptt, vf, 0);
2571 /* Reset Permission table */
2572 qed_iov_config_perm_table(p_hwfn, p_ptt, vf, 0);
2574 qed_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_CLOSE,
2578 static void qed_iov_vf_mbx_release(struct qed_hwfn *p_hwfn,
2579 struct qed_ptt *p_ptt,
2580 struct qed_vf_info *p_vf)
2582 u16 length = sizeof(struct pfvf_def_resp_tlv);
2583 u8 status = PFVF_STATUS_SUCCESS;
2586 qed_iov_vf_cleanup(p_hwfn, p_vf);
2588 if (p_vf->state != VF_STOPPED && p_vf->state != VF_FREE) {
2589 /* Stopping the VF */
2590 rc = qed_sp_vf_stop(p_hwfn, p_vf->concrete_fid,
2594 DP_ERR(p_hwfn, "qed_sp_vf_stop returned error %d\n",
2596 status = PFVF_STATUS_FAILURE;
2599 p_vf->state = VF_STOPPED;
2602 qed_iov_prepare_resp(p_hwfn, p_ptt, p_vf, CHANNEL_TLV_RELEASE,
2607 qed_iov_vf_flr_poll_dorq(struct qed_hwfn *p_hwfn,
2608 struct qed_vf_info *p_vf, struct qed_ptt *p_ptt)
2613 qed_fid_pretend(p_hwfn, p_ptt, (u16) p_vf->concrete_fid);
2615 for (cnt = 0; cnt < 50; cnt++) {
2616 val = qed_rd(p_hwfn, p_ptt, DORQ_REG_VF_USAGE_CNT);
2621 qed_fid_pretend(p_hwfn, p_ptt, (u16) p_hwfn->hw_info.concrete_fid);
2625 "VF[%d] - dorq failed to cleanup [usage 0x%08x]\n",
2626 p_vf->abs_vf_id, val);
2634 qed_iov_vf_flr_poll_pbf(struct qed_hwfn *p_hwfn,
2635 struct qed_vf_info *p_vf, struct qed_ptt *p_ptt)
2637 u32 cons[MAX_NUM_VOQS], distance[MAX_NUM_VOQS];
2640 /* Read initial consumers & producers */
2641 for (i = 0; i < MAX_NUM_VOQS; i++) {
2644 cons[i] = qed_rd(p_hwfn, p_ptt,
2645 PBF_REG_NUM_BLOCKS_ALLOCATED_CONS_VOQ0 +
2647 prod = qed_rd(p_hwfn, p_ptt,
2648 PBF_REG_NUM_BLOCKS_ALLOCATED_PROD_VOQ0 +
2650 distance[i] = prod - cons[i];
2653 /* Wait for consumers to pass the producers */
2655 for (cnt = 0; cnt < 50; cnt++) {
2656 for (; i < MAX_NUM_VOQS; i++) {
2659 tmp = qed_rd(p_hwfn, p_ptt,
2660 PBF_REG_NUM_BLOCKS_ALLOCATED_CONS_VOQ0 +
2662 if (distance[i] > tmp - cons[i])
2666 if (i == MAX_NUM_VOQS)
2673 DP_ERR(p_hwfn, "VF[%d] - pbf polling failed on VOQ %d\n",
2674 p_vf->abs_vf_id, i);
2681 static int qed_iov_vf_flr_poll(struct qed_hwfn *p_hwfn,
2682 struct qed_vf_info *p_vf, struct qed_ptt *p_ptt)
2686 rc = qed_iov_vf_flr_poll_dorq(p_hwfn, p_vf, p_ptt);
2690 rc = qed_iov_vf_flr_poll_pbf(p_hwfn, p_vf, p_ptt);
2698 qed_iov_execute_vf_flr_cleanup(struct qed_hwfn *p_hwfn,
2699 struct qed_ptt *p_ptt,
2700 u16 rel_vf_id, u32 *ack_vfs)
2702 struct qed_vf_info *p_vf;
2705 p_vf = qed_iov_get_vf_info(p_hwfn, rel_vf_id, false);
2709 if (p_hwfn->pf_iov_info->pending_flr[rel_vf_id / 64] &
2710 (1ULL << (rel_vf_id % 64))) {
2711 u16 vfid = p_vf->abs_vf_id;
2713 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
2714 "VF[%d] - Handling FLR\n", vfid);
2716 qed_iov_vf_cleanup(p_hwfn, p_vf);
2718 /* If VF isn't active, no need for anything but SW */
2722 rc = qed_iov_vf_flr_poll(p_hwfn, p_vf, p_ptt);
2726 rc = qed_final_cleanup(p_hwfn, p_ptt, vfid, true);
2728 DP_ERR(p_hwfn, "Failed handle FLR of VF[%d]\n", vfid);
2732 /* VF_STOPPED has to be set only after final cleanup
2733 * but prior to re-enabling the VF.
2735 p_vf->state = VF_STOPPED;
2737 rc = qed_iov_enable_vf_access(p_hwfn, p_ptt, p_vf);
2739 DP_ERR(p_hwfn, "Failed to re-enable VF[%d] acces\n",
2744 /* Mark VF for ack and clean pending state */
2745 if (p_vf->state == VF_RESET)
2746 p_vf->state = VF_STOPPED;
2747 ack_vfs[vfid / 32] |= BIT((vfid % 32));
2748 p_hwfn->pf_iov_info->pending_flr[rel_vf_id / 64] &=
2749 ~(1ULL << (rel_vf_id % 64));
2750 p_hwfn->pf_iov_info->pending_events[rel_vf_id / 64] &=
2751 ~(1ULL << (rel_vf_id % 64));
2757 int qed_iov_vf_flr_cleanup(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
2759 u32 ack_vfs[VF_MAX_STATIC / 32];
2763 memset(ack_vfs, 0, sizeof(u32) * (VF_MAX_STATIC / 32));
2765 /* Since BRB <-> PRS interface can't be tested as part of the flr
2766 * polling due to HW limitations, simply sleep a bit. And since
2767 * there's no need to wait per-vf, do it before looping.
2771 for (i = 0; i < p_hwfn->cdev->p_iov_info->total_vfs; i++)
2772 qed_iov_execute_vf_flr_cleanup(p_hwfn, p_ptt, i, ack_vfs);
2774 rc = qed_mcp_ack_vf_flr(p_hwfn, p_ptt, ack_vfs);
2778 int qed_iov_mark_vf_flr(struct qed_hwfn *p_hwfn, u32 *p_disabled_vfs)
2782 DP_VERBOSE(p_hwfn, QED_MSG_IOV, "Marking FLR-ed VFs\n");
2783 for (i = 0; i < (VF_MAX_STATIC / 32); i++)
2784 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
2785 "[%08x,...,%08x]: %08x\n",
2786 i * 32, (i + 1) * 32 - 1, p_disabled_vfs[i]);
2788 if (!p_hwfn->cdev->p_iov_info) {
2789 DP_NOTICE(p_hwfn, "VF flr but no IOV\n");
2794 for (i = 0; i < p_hwfn->cdev->p_iov_info->total_vfs; i++) {
2795 struct qed_vf_info *p_vf;
2798 p_vf = qed_iov_get_vf_info(p_hwfn, i, false);
2802 vfid = p_vf->abs_vf_id;
2803 if (BIT((vfid % 32)) & p_disabled_vfs[vfid / 32]) {
2804 u64 *p_flr = p_hwfn->pf_iov_info->pending_flr;
2805 u16 rel_vf_id = p_vf->relative_vf_id;
2807 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
2808 "VF[%d] [rel %d] got FLR-ed\n",
2811 p_vf->state = VF_RESET;
2813 /* No need to lock here, since pending_flr should
2814 * only change here and before ACKing MFw. Since
2815 * MFW will not trigger an additional attention for
2816 * VF flr until ACKs, we're safe.
2818 p_flr[rel_vf_id / 64] |= 1ULL << (rel_vf_id % 64);
2826 static void qed_iov_get_link(struct qed_hwfn *p_hwfn,
2828 struct qed_mcp_link_params *p_params,
2829 struct qed_mcp_link_state *p_link,
2830 struct qed_mcp_link_capabilities *p_caps)
2832 struct qed_vf_info *p_vf = qed_iov_get_vf_info(p_hwfn,
2835 struct qed_bulletin_content *p_bulletin;
2840 p_bulletin = p_vf->bulletin.p_virt;
2843 __qed_vf_get_link_params(p_hwfn, p_params, p_bulletin);
2845 __qed_vf_get_link_state(p_hwfn, p_link, p_bulletin);
2847 __qed_vf_get_link_caps(p_hwfn, p_caps, p_bulletin);
2850 static void qed_iov_process_mbx_req(struct qed_hwfn *p_hwfn,
2851 struct qed_ptt *p_ptt, int vfid)
2853 struct qed_iov_vf_mbx *mbx;
2854 struct qed_vf_info *p_vf;
2856 p_vf = qed_iov_get_vf_info(p_hwfn, (u16) vfid, true);
2860 mbx = &p_vf->vf_mbx;
2862 /* qed_iov_process_mbx_request */
2863 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
2864 "VF[%02x]: Processing mailbox message\n", p_vf->abs_vf_id);
2866 mbx->first_tlv = mbx->req_virt->first_tlv;
2868 /* check if tlv type is known */
2869 if (qed_iov_tlv_supported(mbx->first_tlv.tl.type)) {
2870 switch (mbx->first_tlv.tl.type) {
2871 case CHANNEL_TLV_ACQUIRE:
2872 qed_iov_vf_mbx_acquire(p_hwfn, p_ptt, p_vf);
2874 case CHANNEL_TLV_VPORT_START:
2875 qed_iov_vf_mbx_start_vport(p_hwfn, p_ptt, p_vf);
2877 case CHANNEL_TLV_VPORT_TEARDOWN:
2878 qed_iov_vf_mbx_stop_vport(p_hwfn, p_ptt, p_vf);
2880 case CHANNEL_TLV_START_RXQ:
2881 qed_iov_vf_mbx_start_rxq(p_hwfn, p_ptt, p_vf);
2883 case CHANNEL_TLV_START_TXQ:
2884 qed_iov_vf_mbx_start_txq(p_hwfn, p_ptt, p_vf);
2886 case CHANNEL_TLV_STOP_RXQS:
2887 qed_iov_vf_mbx_stop_rxqs(p_hwfn, p_ptt, p_vf);
2889 case CHANNEL_TLV_STOP_TXQS:
2890 qed_iov_vf_mbx_stop_txqs(p_hwfn, p_ptt, p_vf);
2892 case CHANNEL_TLV_UPDATE_RXQ:
2893 qed_iov_vf_mbx_update_rxqs(p_hwfn, p_ptt, p_vf);
2895 case CHANNEL_TLV_VPORT_UPDATE:
2896 qed_iov_vf_mbx_vport_update(p_hwfn, p_ptt, p_vf);
2898 case CHANNEL_TLV_UCAST_FILTER:
2899 qed_iov_vf_mbx_ucast_filter(p_hwfn, p_ptt, p_vf);
2901 case CHANNEL_TLV_CLOSE:
2902 qed_iov_vf_mbx_close(p_hwfn, p_ptt, p_vf);
2904 case CHANNEL_TLV_INT_CLEANUP:
2905 qed_iov_vf_mbx_int_cleanup(p_hwfn, p_ptt, p_vf);
2907 case CHANNEL_TLV_RELEASE:
2908 qed_iov_vf_mbx_release(p_hwfn, p_ptt, p_vf);
2912 /* unknown TLV - this may belong to a VF driver from the future
2913 * - a version written after this PF driver was written, which
2914 * supports features unknown as of yet. Too bad since we don't
2915 * support them. Or this may be because someone wrote a crappy
2916 * VF driver and is sending garbage over the channel.
2919 "VF[%02x]: unknown TLV. type %04x length %04x padding %08x reply address %llu\n",
2921 mbx->first_tlv.tl.type,
2922 mbx->first_tlv.tl.length,
2923 mbx->first_tlv.padding, mbx->first_tlv.reply_address);
2925 /* Try replying in case reply address matches the acquisition's
2928 if (p_vf->acquire.first_tlv.reply_address &&
2929 (mbx->first_tlv.reply_address ==
2930 p_vf->acquire.first_tlv.reply_address)) {
2931 qed_iov_prepare_resp(p_hwfn, p_ptt, p_vf,
2932 mbx->first_tlv.tl.type,
2933 sizeof(struct pfvf_def_resp_tlv),
2934 PFVF_STATUS_NOT_SUPPORTED);
2938 "VF[%02x]: Can't respond to TLV - no valid reply address\n",
2944 void qed_iov_pf_add_pending_events(struct qed_hwfn *p_hwfn, u8 vfid)
2946 u64 add_bit = 1ULL << (vfid % 64);
2948 p_hwfn->pf_iov_info->pending_events[vfid / 64] |= add_bit;
2951 static void qed_iov_pf_get_and_clear_pending_events(struct qed_hwfn *p_hwfn,
2954 u64 *p_pending_events = p_hwfn->pf_iov_info->pending_events;
2956 memcpy(events, p_pending_events, sizeof(u64) * QED_VF_ARRAY_LENGTH);
2957 memset(p_pending_events, 0, sizeof(u64) * QED_VF_ARRAY_LENGTH);
2960 static int qed_sriov_vfpf_msg(struct qed_hwfn *p_hwfn,
2961 u16 abs_vfid, struct regpair *vf_msg)
2963 u8 min = (u8)p_hwfn->cdev->p_iov_info->first_vf_in_pf;
2964 struct qed_vf_info *p_vf;
2966 if (!qed_iov_pf_sanity_check(p_hwfn, (int)abs_vfid - min)) {
2969 "Got a message from VF [abs 0x%08x] that cannot be handled by PF\n",
2973 p_vf = &p_hwfn->pf_iov_info->vfs_array[(u8)abs_vfid - min];
2975 /* List the physical address of the request so that handler
2976 * could later on copy the message from it.
2978 p_vf->vf_mbx.pending_req = (((u64)vf_msg->hi) << 32) | vf_msg->lo;
2980 /* Mark the event and schedule the workqueue */
2981 qed_iov_pf_add_pending_events(p_hwfn, p_vf->relative_vf_id);
2982 qed_schedule_iov(p_hwfn, QED_IOV_WQ_MSG_FLAG);
2987 int qed_sriov_eqe_event(struct qed_hwfn *p_hwfn,
2988 u8 opcode, __le16 echo, union event_ring_data *data)
2991 case COMMON_EVENT_VF_PF_CHANNEL:
2992 return qed_sriov_vfpf_msg(p_hwfn, le16_to_cpu(echo),
2993 &data->vf_pf_channel.msg_addr);
2995 DP_INFO(p_hwfn->cdev, "Unknown sriov eqe event 0x%02x\n",
3001 u16 qed_iov_get_next_active_vf(struct qed_hwfn *p_hwfn, u16 rel_vf_id)
3003 struct qed_hw_sriov_info *p_iov = p_hwfn->cdev->p_iov_info;
3009 for (i = rel_vf_id; i < p_iov->total_vfs; i++)
3010 if (qed_iov_is_valid_vfid(p_hwfn, rel_vf_id, true))
3017 static int qed_iov_copy_vf_msg(struct qed_hwfn *p_hwfn, struct qed_ptt *ptt,
3020 struct qed_dmae_params params;
3021 struct qed_vf_info *vf_info;
3023 vf_info = qed_iov_get_vf_info(p_hwfn, (u16) vfid, true);
3027 memset(¶ms, 0, sizeof(struct qed_dmae_params));
3028 params.flags = QED_DMAE_FLAG_VF_SRC | QED_DMAE_FLAG_COMPLETION_DST;
3029 params.src_vfid = vf_info->abs_vf_id;
3031 if (qed_dmae_host2host(p_hwfn, ptt,
3032 vf_info->vf_mbx.pending_req,
3033 vf_info->vf_mbx.req_phys,
3034 sizeof(union vfpf_tlvs) / 4, ¶ms)) {
3035 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
3036 "Failed to copy message from VF 0x%02x\n", vfid);
3044 static void qed_iov_bulletin_set_forced_mac(struct qed_hwfn *p_hwfn,
3047 struct qed_vf_info *vf_info;
3050 vf_info = qed_iov_get_vf_info(p_hwfn, (u16)vfid, true);
3052 DP_NOTICE(p_hwfn->cdev,
3053 "Can not set forced MAC, invalid vfid [%d]\n", vfid);
3057 feature = 1 << MAC_ADDR_FORCED;
3058 memcpy(vf_info->bulletin.p_virt->mac, mac, ETH_ALEN);
3060 vf_info->bulletin.p_virt->valid_bitmap |= feature;
3061 /* Forced MAC will disable MAC_ADDR */
3062 vf_info->bulletin.p_virt->valid_bitmap &= ~BIT(VFPF_BULLETIN_MAC_ADDR);
3064 qed_iov_configure_vport_forced(p_hwfn, vf_info, feature);
3067 void qed_iov_bulletin_set_forced_vlan(struct qed_hwfn *p_hwfn,
3070 struct qed_vf_info *vf_info;
3073 vf_info = qed_iov_get_vf_info(p_hwfn, (u16) vfid, true);
3075 DP_NOTICE(p_hwfn->cdev,
3076 "Can not set forced MAC, invalid vfid [%d]\n", vfid);
3080 feature = 1 << VLAN_ADDR_FORCED;
3081 vf_info->bulletin.p_virt->pvid = pvid;
3083 vf_info->bulletin.p_virt->valid_bitmap |= feature;
3085 vf_info->bulletin.p_virt->valid_bitmap &= ~feature;
3087 qed_iov_configure_vport_forced(p_hwfn, vf_info, feature);
3090 static bool qed_iov_vf_has_vport_instance(struct qed_hwfn *p_hwfn, int vfid)
3092 struct qed_vf_info *p_vf_info;
3094 p_vf_info = qed_iov_get_vf_info(p_hwfn, (u16) vfid, true);
3098 return !!p_vf_info->vport_instance;
3101 bool qed_iov_is_vf_stopped(struct qed_hwfn *p_hwfn, int vfid)
3103 struct qed_vf_info *p_vf_info;
3105 p_vf_info = qed_iov_get_vf_info(p_hwfn, (u16) vfid, true);
3109 return p_vf_info->state == VF_STOPPED;
3112 static bool qed_iov_spoofchk_get(struct qed_hwfn *p_hwfn, int vfid)
3114 struct qed_vf_info *vf_info;
3116 vf_info = qed_iov_get_vf_info(p_hwfn, (u16) vfid, true);
3120 return vf_info->spoof_chk;
3123 int qed_iov_spoofchk_set(struct qed_hwfn *p_hwfn, int vfid, bool val)
3125 struct qed_vf_info *vf;
3128 if (!qed_iov_pf_sanity_check(p_hwfn, vfid)) {
3130 "SR-IOV sanity check failed, can't set spoofchk\n");
3134 vf = qed_iov_get_vf_info(p_hwfn, (u16) vfid, true);
3138 if (!qed_iov_vf_has_vport_instance(p_hwfn, vfid)) {
3139 /* After VF VPORT start PF will configure spoof check */
3140 vf->req_spoofchk_val = val;
3145 rc = __qed_iov_spoofchk_set(p_hwfn, vf, val);
3151 static u8 *qed_iov_bulletin_get_forced_mac(struct qed_hwfn *p_hwfn,
3154 struct qed_vf_info *p_vf;
3156 p_vf = qed_iov_get_vf_info(p_hwfn, rel_vf_id, true);
3157 if (!p_vf || !p_vf->bulletin.p_virt)
3160 if (!(p_vf->bulletin.p_virt->valid_bitmap & BIT(MAC_ADDR_FORCED)))
3163 return p_vf->bulletin.p_virt->mac;
3166 u16 qed_iov_bulletin_get_forced_vlan(struct qed_hwfn *p_hwfn, u16 rel_vf_id)
3168 struct qed_vf_info *p_vf;
3170 p_vf = qed_iov_get_vf_info(p_hwfn, rel_vf_id, true);
3171 if (!p_vf || !p_vf->bulletin.p_virt)
3174 if (!(p_vf->bulletin.p_virt->valid_bitmap & BIT(VLAN_ADDR_FORCED)))
3177 return p_vf->bulletin.p_virt->pvid;
3180 static int qed_iov_configure_tx_rate(struct qed_hwfn *p_hwfn,
3181 struct qed_ptt *p_ptt, int vfid, int val)
3183 struct qed_vf_info *vf;
3187 vf = qed_iov_get_vf_info(p_hwfn, (u16)vfid, true);
3191 rc = qed_fw_vport(p_hwfn, vf->vport_id, &abs_vp_id);
3195 return qed_init_vport_rl(p_hwfn, p_ptt, abs_vp_id, (u32)val);
3198 int qed_iov_configure_min_tx_rate(struct qed_dev *cdev, int vfid, u32 rate)
3200 struct qed_vf_info *vf;
3204 for_each_hwfn(cdev, i) {
3205 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
3207 if (!qed_iov_pf_sanity_check(p_hwfn, vfid)) {
3209 "SR-IOV sanity check failed, can't set min rate\n");
3214 vf = qed_iov_get_vf_info(QED_LEADING_HWFN(cdev), (u16)vfid, true);
3215 vport_id = vf->vport_id;
3217 return qed_configure_vport_wfq(cdev, vport_id, rate);
3220 static int qed_iov_get_vf_min_rate(struct qed_hwfn *p_hwfn, int vfid)
3222 struct qed_wfq_data *vf_vp_wfq;
3223 struct qed_vf_info *vf_info;
3225 vf_info = qed_iov_get_vf_info(p_hwfn, (u16) vfid, true);
3229 vf_vp_wfq = &p_hwfn->qm_info.wfq_data[vf_info->vport_id];
3231 if (vf_vp_wfq->configured)
3232 return vf_vp_wfq->min_speed;
3238 * qed_schedule_iov - schedules IOV task for VF and PF
3239 * @hwfn: hardware function pointer
3240 * @flag: IOV flag for VF/PF
3242 void qed_schedule_iov(struct qed_hwfn *hwfn, enum qed_iov_wq_flag flag)
3244 smp_mb__before_atomic();
3245 set_bit(flag, &hwfn->iov_task_flags);
3246 smp_mb__after_atomic();
3247 DP_VERBOSE(hwfn, QED_MSG_IOV, "Scheduling iov task [Flag: %d]\n", flag);
3248 queue_delayed_work(hwfn->iov_wq, &hwfn->iov_task, 0);
3251 void qed_vf_start_iov_wq(struct qed_dev *cdev)
3255 for_each_hwfn(cdev, i)
3256 queue_delayed_work(cdev->hwfns[i].iov_wq,
3257 &cdev->hwfns[i].iov_task, 0);
3260 int qed_sriov_disable(struct qed_dev *cdev, bool pci_enabled)
3264 for_each_hwfn(cdev, i)
3265 if (cdev->hwfns[i].iov_wq)
3266 flush_workqueue(cdev->hwfns[i].iov_wq);
3268 /* Mark VFs for disablement */
3269 qed_iov_set_vfs_to_disable(cdev, true);
3271 if (cdev->p_iov_info && cdev->p_iov_info->num_vfs && pci_enabled)
3272 pci_disable_sriov(cdev->pdev);
3274 for_each_hwfn(cdev, i) {
3275 struct qed_hwfn *hwfn = &cdev->hwfns[i];
3276 struct qed_ptt *ptt = qed_ptt_acquire(hwfn);
3278 /* Failure to acquire the ptt in 100g creates an odd error
3279 * where the first engine has already relased IOV.
3282 DP_ERR(hwfn, "Failed to acquire ptt\n");
3286 /* Clean WFQ db and configure equal weight for all vports */
3287 qed_clean_wfq_db(hwfn, ptt);
3289 qed_for_each_vf(hwfn, j) {
3292 if (!qed_iov_is_valid_vfid(hwfn, j, true))
3295 /* Wait until VF is disabled before releasing */
3296 for (k = 0; k < 100; k++) {
3297 if (!qed_iov_is_vf_stopped(hwfn, j))
3304 qed_iov_release_hw_for_vf(&cdev->hwfns[i],
3308 "Timeout waiting for VF's FLR to end\n");
3311 qed_ptt_release(hwfn, ptt);
3314 qed_iov_set_vfs_to_disable(cdev, false);
3319 static int qed_sriov_enable(struct qed_dev *cdev, int num)
3321 struct qed_sb_cnt_info sb_cnt_info;
3324 if (num >= RESC_NUM(&cdev->hwfns[0], QED_VPORT)) {
3325 DP_NOTICE(cdev, "Can start at most %d VFs\n",
3326 RESC_NUM(&cdev->hwfns[0], QED_VPORT) - 1);
3330 /* Initialize HW for VF access */
3331 for_each_hwfn(cdev, j) {
3332 struct qed_hwfn *hwfn = &cdev->hwfns[j];
3333 struct qed_ptt *ptt = qed_ptt_acquire(hwfn);
3334 int num_sbs = 0, limit = 16;
3337 DP_ERR(hwfn, "Failed to acquire ptt\n");
3342 if (IS_MF_DEFAULT(hwfn))
3343 limit = MAX_NUM_VFS_BB / hwfn->num_funcs_on_engine;
3345 memset(&sb_cnt_info, 0, sizeof(sb_cnt_info));
3346 qed_int_get_num_sbs(hwfn, &sb_cnt_info);
3347 num_sbs = min_t(int, sb_cnt_info.sb_free_blk, limit);
3349 for (i = 0; i < num; i++) {
3350 if (!qed_iov_is_valid_vfid(hwfn, i, false))
3353 rc = qed_iov_init_hw_for_vf(hwfn,
3354 ptt, i, num_sbs / num);
3356 DP_ERR(cdev, "Failed to enable VF[%d]\n", i);
3357 qed_ptt_release(hwfn, ptt);
3362 qed_ptt_release(hwfn, ptt);
3365 /* Enable SRIOV PCIe functions */
3366 rc = pci_enable_sriov(cdev->pdev, num);
3368 DP_ERR(cdev, "Failed to enable sriov [%d]\n", rc);
3375 qed_sriov_disable(cdev, false);
3379 static int qed_sriov_configure(struct qed_dev *cdev, int num_vfs_param)
3381 if (!IS_QED_SRIOV(cdev)) {
3382 DP_VERBOSE(cdev, QED_MSG_IOV, "SR-IOV is not supported\n");
3387 return qed_sriov_enable(cdev, num_vfs_param);
3389 return qed_sriov_disable(cdev, true);
3392 static int qed_sriov_pf_set_mac(struct qed_dev *cdev, u8 *mac, int vfid)
3396 if (!IS_QED_SRIOV(cdev) || !IS_PF_SRIOV_ALLOC(&cdev->hwfns[0])) {
3397 DP_VERBOSE(cdev, QED_MSG_IOV,
3398 "Cannot set a VF MAC; Sriov is not enabled\n");
3402 if (!qed_iov_is_valid_vfid(&cdev->hwfns[0], vfid, true)) {
3403 DP_VERBOSE(cdev, QED_MSG_IOV,
3404 "Cannot set VF[%d] MAC (VF is not active)\n", vfid);
3408 for_each_hwfn(cdev, i) {
3409 struct qed_hwfn *hwfn = &cdev->hwfns[i];
3410 struct qed_public_vf_info *vf_info;
3412 vf_info = qed_iov_get_public_vf_info(hwfn, vfid, true);
3416 /* Set the forced MAC, and schedule the IOV task */
3417 ether_addr_copy(vf_info->forced_mac, mac);
3418 qed_schedule_iov(hwfn, QED_IOV_WQ_SET_UNICAST_FILTER_FLAG);
3424 static int qed_sriov_pf_set_vlan(struct qed_dev *cdev, u16 vid, int vfid)
3428 if (!IS_QED_SRIOV(cdev) || !IS_PF_SRIOV_ALLOC(&cdev->hwfns[0])) {
3429 DP_VERBOSE(cdev, QED_MSG_IOV,
3430 "Cannot set a VF MAC; Sriov is not enabled\n");
3434 if (!qed_iov_is_valid_vfid(&cdev->hwfns[0], vfid, true)) {
3435 DP_VERBOSE(cdev, QED_MSG_IOV,
3436 "Cannot set VF[%d] MAC (VF is not active)\n", vfid);
3440 for_each_hwfn(cdev, i) {
3441 struct qed_hwfn *hwfn = &cdev->hwfns[i];
3442 struct qed_public_vf_info *vf_info;
3444 vf_info = qed_iov_get_public_vf_info(hwfn, vfid, true);
3448 /* Set the forced vlan, and schedule the IOV task */
3449 vf_info->forced_vlan = vid;
3450 qed_schedule_iov(hwfn, QED_IOV_WQ_SET_UNICAST_FILTER_FLAG);
3456 static int qed_get_vf_config(struct qed_dev *cdev,
3457 int vf_id, struct ifla_vf_info *ivi)
3459 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
3460 struct qed_public_vf_info *vf_info;
3461 struct qed_mcp_link_state link;
3464 /* Sanitize request */
3468 if (!qed_iov_is_valid_vfid(&cdev->hwfns[0], vf_id, true)) {
3469 DP_VERBOSE(cdev, QED_MSG_IOV,
3470 "VF index [%d] isn't active\n", vf_id);
3474 vf_info = qed_iov_get_public_vf_info(hwfn, vf_id, true);
3476 qed_iov_get_link(hwfn, vf_id, NULL, &link, NULL);
3478 /* Fill information about VF */
3481 if (is_valid_ether_addr(vf_info->forced_mac))
3482 ether_addr_copy(ivi->mac, vf_info->forced_mac);
3484 ether_addr_copy(ivi->mac, vf_info->mac);
3486 ivi->vlan = vf_info->forced_vlan;
3487 ivi->spoofchk = qed_iov_spoofchk_get(hwfn, vf_id);
3488 ivi->linkstate = vf_info->link_state;
3489 tx_rate = vf_info->tx_rate;
3490 ivi->max_tx_rate = tx_rate ? tx_rate : link.speed;
3491 ivi->min_tx_rate = qed_iov_get_vf_min_rate(hwfn, vf_id);
3496 void qed_inform_vf_link_state(struct qed_hwfn *hwfn)
3498 struct qed_mcp_link_capabilities caps;
3499 struct qed_mcp_link_params params;
3500 struct qed_mcp_link_state link;
3503 if (!hwfn->pf_iov_info)
3506 /* Update bulletin of all future possible VFs with link configuration */
3507 for (i = 0; i < hwfn->cdev->p_iov_info->total_vfs; i++) {
3508 struct qed_public_vf_info *vf_info;
3510 vf_info = qed_iov_get_public_vf_info(hwfn, i, false);
3514 memcpy(¶ms, qed_mcp_get_link_params(hwfn), sizeof(params));
3515 memcpy(&link, qed_mcp_get_link_state(hwfn), sizeof(link));
3516 memcpy(&caps, qed_mcp_get_link_capabilities(hwfn),
3519 /* Modify link according to the VF's configured link state */
3520 switch (vf_info->link_state) {
3521 case IFLA_VF_LINK_STATE_DISABLE:
3522 link.link_up = false;
3524 case IFLA_VF_LINK_STATE_ENABLE:
3525 link.link_up = true;
3526 /* Set speed according to maximum supported by HW.
3527 * that is 40G for regular devices and 100G for CMT
3530 link.speed = (hwfn->cdev->num_hwfns > 1) ?
3533 /* In auto mode pass PF link image to VF */
3537 if (link.link_up && vf_info->tx_rate) {
3538 struct qed_ptt *ptt;
3541 rate = min_t(int, vf_info->tx_rate, link.speed);
3543 ptt = qed_ptt_acquire(hwfn);
3545 DP_NOTICE(hwfn, "Failed to acquire PTT\n");
3549 if (!qed_iov_configure_tx_rate(hwfn, ptt, i, rate)) {
3550 vf_info->tx_rate = rate;
3554 qed_ptt_release(hwfn, ptt);
3557 qed_iov_set_link(hwfn, i, ¶ms, &link, &caps);
3560 qed_schedule_iov(hwfn, QED_IOV_WQ_BULLETIN_UPDATE_FLAG);
3563 static int qed_set_vf_link_state(struct qed_dev *cdev,
3564 int vf_id, int link_state)
3568 /* Sanitize request */
3572 if (!qed_iov_is_valid_vfid(&cdev->hwfns[0], vf_id, true)) {
3573 DP_VERBOSE(cdev, QED_MSG_IOV,
3574 "VF index [%d] isn't active\n", vf_id);
3578 /* Handle configuration of link state */
3579 for_each_hwfn(cdev, i) {
3580 struct qed_hwfn *hwfn = &cdev->hwfns[i];
3581 struct qed_public_vf_info *vf;
3583 vf = qed_iov_get_public_vf_info(hwfn, vf_id, true);
3587 if (vf->link_state == link_state)
3590 vf->link_state = link_state;
3591 qed_inform_vf_link_state(&cdev->hwfns[i]);
3597 static int qed_spoof_configure(struct qed_dev *cdev, int vfid, bool val)
3599 int i, rc = -EINVAL;
3601 for_each_hwfn(cdev, i) {
3602 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
3604 rc = qed_iov_spoofchk_set(p_hwfn, vfid, val);
3612 static int qed_configure_max_vf_rate(struct qed_dev *cdev, int vfid, int rate)
3616 for_each_hwfn(cdev, i) {
3617 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
3618 struct qed_public_vf_info *vf;
3620 if (!qed_iov_pf_sanity_check(p_hwfn, vfid)) {
3622 "SR-IOV sanity check failed, can't set tx rate\n");
3626 vf = qed_iov_get_public_vf_info(p_hwfn, vfid, true);
3630 qed_inform_vf_link_state(p_hwfn);
3636 static int qed_set_vf_rate(struct qed_dev *cdev,
3637 int vfid, u32 min_rate, u32 max_rate)
3639 int rc_min = 0, rc_max = 0;
3642 rc_max = qed_configure_max_vf_rate(cdev, vfid, max_rate);
3645 rc_min = qed_iov_configure_min_tx_rate(cdev, vfid, min_rate);
3647 if (rc_max | rc_min)
3653 static void qed_handle_vf_msg(struct qed_hwfn *hwfn)
3655 u64 events[QED_VF_ARRAY_LENGTH];
3656 struct qed_ptt *ptt;
3659 ptt = qed_ptt_acquire(hwfn);
3661 DP_VERBOSE(hwfn, QED_MSG_IOV,
3662 "Can't acquire PTT; re-scheduling\n");
3663 qed_schedule_iov(hwfn, QED_IOV_WQ_MSG_FLAG);
3667 qed_iov_pf_get_and_clear_pending_events(hwfn, events);
3669 DP_VERBOSE(hwfn, QED_MSG_IOV,
3670 "Event mask of VF events: 0x%llx 0x%llx 0x%llx\n",
3671 events[0], events[1], events[2]);
3673 qed_for_each_vf(hwfn, i) {
3674 /* Skip VFs with no pending messages */
3675 if (!(events[i / 64] & (1ULL << (i % 64))))
3678 DP_VERBOSE(hwfn, QED_MSG_IOV,
3679 "Handling VF message from VF 0x%02x [Abs 0x%02x]\n",
3680 i, hwfn->cdev->p_iov_info->first_vf_in_pf + i);
3682 /* Copy VF's message to PF's request buffer for that VF */
3683 if (qed_iov_copy_vf_msg(hwfn, ptt, i))
3686 qed_iov_process_mbx_req(hwfn, ptt, i);
3689 qed_ptt_release(hwfn, ptt);
3692 static void qed_handle_pf_set_vf_unicast(struct qed_hwfn *hwfn)
3696 qed_for_each_vf(hwfn, i) {
3697 struct qed_public_vf_info *info;
3698 bool update = false;
3701 info = qed_iov_get_public_vf_info(hwfn, i, true);
3705 /* Update data on bulletin board */
3706 mac = qed_iov_bulletin_get_forced_mac(hwfn, i);
3707 if (is_valid_ether_addr(info->forced_mac) &&
3708 (!mac || !ether_addr_equal(mac, info->forced_mac))) {
3711 "Handling PF setting of VF MAC to VF 0x%02x [Abs 0x%02x]\n",
3713 hwfn->cdev->p_iov_info->first_vf_in_pf + i);
3715 /* Update bulletin board with forced MAC */
3716 qed_iov_bulletin_set_forced_mac(hwfn,
3717 info->forced_mac, i);
3721 if (qed_iov_bulletin_get_forced_vlan(hwfn, i) ^
3722 info->forced_vlan) {
3725 "Handling PF setting of pvid [0x%04x] to VF 0x%02x [Abs 0x%02x]\n",
3728 hwfn->cdev->p_iov_info->first_vf_in_pf + i);
3729 qed_iov_bulletin_set_forced_vlan(hwfn,
3730 info->forced_vlan, i);
3735 qed_schedule_iov(hwfn, QED_IOV_WQ_BULLETIN_UPDATE_FLAG);
3739 static void qed_handle_bulletin_post(struct qed_hwfn *hwfn)
3741 struct qed_ptt *ptt;
3744 ptt = qed_ptt_acquire(hwfn);
3746 DP_NOTICE(hwfn, "Failed allocating a ptt entry\n");
3747 qed_schedule_iov(hwfn, QED_IOV_WQ_BULLETIN_UPDATE_FLAG);
3751 qed_for_each_vf(hwfn, i)
3752 qed_iov_post_vf_bulletin(hwfn, i, ptt);
3754 qed_ptt_release(hwfn, ptt);
3757 void qed_iov_pf_task(struct work_struct *work)
3759 struct qed_hwfn *hwfn = container_of(work, struct qed_hwfn,
3763 if (test_and_clear_bit(QED_IOV_WQ_STOP_WQ_FLAG, &hwfn->iov_task_flags))
3766 if (test_and_clear_bit(QED_IOV_WQ_FLR_FLAG, &hwfn->iov_task_flags)) {
3767 struct qed_ptt *ptt = qed_ptt_acquire(hwfn);
3770 qed_schedule_iov(hwfn, QED_IOV_WQ_FLR_FLAG);
3774 rc = qed_iov_vf_flr_cleanup(hwfn, ptt);
3776 qed_schedule_iov(hwfn, QED_IOV_WQ_FLR_FLAG);
3778 qed_ptt_release(hwfn, ptt);
3781 if (test_and_clear_bit(QED_IOV_WQ_MSG_FLAG, &hwfn->iov_task_flags))
3782 qed_handle_vf_msg(hwfn);
3784 if (test_and_clear_bit(QED_IOV_WQ_SET_UNICAST_FILTER_FLAG,
3785 &hwfn->iov_task_flags))
3786 qed_handle_pf_set_vf_unicast(hwfn);
3788 if (test_and_clear_bit(QED_IOV_WQ_BULLETIN_UPDATE_FLAG,
3789 &hwfn->iov_task_flags))
3790 qed_handle_bulletin_post(hwfn);
3793 void qed_iov_wq_stop(struct qed_dev *cdev, bool schedule_first)
3797 for_each_hwfn(cdev, i) {
3798 if (!cdev->hwfns[i].iov_wq)
3801 if (schedule_first) {
3802 qed_schedule_iov(&cdev->hwfns[i],
3803 QED_IOV_WQ_STOP_WQ_FLAG);
3804 cancel_delayed_work_sync(&cdev->hwfns[i].iov_task);
3807 flush_workqueue(cdev->hwfns[i].iov_wq);
3808 destroy_workqueue(cdev->hwfns[i].iov_wq);
3812 int qed_iov_wq_start(struct qed_dev *cdev)
3814 char name[NAME_SIZE];
3817 for_each_hwfn(cdev, i) {
3818 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
3820 /* PFs needs a dedicated workqueue only if they support IOV.
3821 * VFs always require one.
3823 if (IS_PF(p_hwfn->cdev) && !IS_PF_SRIOV(p_hwfn))
3826 snprintf(name, NAME_SIZE, "iov-%02x:%02x.%02x",
3827 cdev->pdev->bus->number,
3828 PCI_SLOT(cdev->pdev->devfn), p_hwfn->abs_pf_id);
3830 p_hwfn->iov_wq = create_singlethread_workqueue(name);
3831 if (!p_hwfn->iov_wq) {
3832 DP_NOTICE(p_hwfn, "Cannot create iov workqueue\n");
3837 INIT_DELAYED_WORK(&p_hwfn->iov_task, qed_iov_pf_task);
3839 INIT_DELAYED_WORK(&p_hwfn->iov_task, qed_iov_vf_task);
3845 const struct qed_iov_hv_ops qed_iov_ops_pass = {
3846 .configure = &qed_sriov_configure,
3847 .set_mac = &qed_sriov_pf_set_mac,
3848 .set_vlan = &qed_sriov_pf_set_vlan,
3849 .get_config = &qed_get_vf_config,
3850 .set_link_state = &qed_set_vf_link_state,
3851 .set_spoof = &qed_spoof_configure,
3852 .set_rate = &qed_set_vf_rate,