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 int qed_iov_post_vf_bulletin(struct qed_hwfn *p_hwfn,
150 int vfid, struct qed_ptt *p_ptt)
152 struct qed_bulletin_content *p_bulletin;
153 int crc_size = sizeof(p_bulletin->crc);
154 struct qed_dmae_params params;
155 struct qed_vf_info *p_vf;
157 p_vf = qed_iov_get_vf_info(p_hwfn, (u16) vfid, true);
161 if (!p_vf->vf_bulletin)
164 p_bulletin = p_vf->bulletin.p_virt;
166 /* Increment bulletin board version and compute crc */
167 p_bulletin->version++;
168 p_bulletin->crc = crc32(0, (u8 *)p_bulletin + crc_size,
169 p_vf->bulletin.size - crc_size);
171 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
172 "Posting Bulletin 0x%08x to VF[%d] (CRC 0x%08x)\n",
173 p_bulletin->version, p_vf->relative_vf_id, p_bulletin->crc);
175 /* propagate bulletin board via dmae to vm memory */
176 memset(¶ms, 0, sizeof(params));
177 params.flags = QED_DMAE_FLAG_VF_DST;
178 params.dst_vfid = p_vf->abs_vf_id;
179 return qed_dmae_host2host(p_hwfn, p_ptt, p_vf->bulletin.phys,
180 p_vf->vf_bulletin, p_vf->bulletin.size / 4,
184 static int qed_iov_pci_cfg_info(struct qed_dev *cdev)
186 struct qed_hw_sriov_info *iov = cdev->p_iov_info;
189 DP_VERBOSE(cdev, QED_MSG_IOV, "sriov ext pos %d\n", pos);
190 pci_read_config_word(cdev->pdev, pos + PCI_SRIOV_CTRL, &iov->ctrl);
192 pci_read_config_word(cdev->pdev,
193 pos + PCI_SRIOV_TOTAL_VF, &iov->total_vfs);
194 pci_read_config_word(cdev->pdev,
195 pos + PCI_SRIOV_INITIAL_VF, &iov->initial_vfs);
197 pci_read_config_word(cdev->pdev, pos + PCI_SRIOV_NUM_VF, &iov->num_vfs);
201 "Number of VFs are already set to non-zero value. Ignoring PCI configuration value\n");
205 pci_read_config_word(cdev->pdev,
206 pos + PCI_SRIOV_VF_OFFSET, &iov->offset);
208 pci_read_config_word(cdev->pdev,
209 pos + PCI_SRIOV_VF_STRIDE, &iov->stride);
211 pci_read_config_word(cdev->pdev,
212 pos + PCI_SRIOV_VF_DID, &iov->vf_device_id);
214 pci_read_config_dword(cdev->pdev,
215 pos + PCI_SRIOV_SUP_PGSIZE, &iov->pgsz);
217 pci_read_config_dword(cdev->pdev, pos + PCI_SRIOV_CAP, &iov->cap);
219 pci_read_config_byte(cdev->pdev, pos + PCI_SRIOV_FUNC_LINK, &iov->link);
223 "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",
229 iov->nr_virtfn, iov->offset, iov->stride, iov->pgsz);
231 /* Some sanity checks */
232 if (iov->num_vfs > NUM_OF_VFS(cdev) ||
233 iov->total_vfs > NUM_OF_VFS(cdev)) {
234 /* This can happen only due to a bug. In this case we set
235 * num_vfs to zero to avoid memory corruption in the code that
236 * assumes max number of vfs
239 "IOV: Unexpected number of vfs set: %d setting num_vf to zero\n",
249 static void qed_iov_clear_vf_igu_blocks(struct qed_hwfn *p_hwfn,
250 struct qed_ptt *p_ptt)
252 struct qed_igu_block *p_sb;
256 if (!p_hwfn->hw_info.p_igu_info) {
258 "qed_iov_clear_vf_igu_blocks IGU Info not initialized\n");
262 for (sb_id = 0; sb_id < QED_MAPPING_MEMORY_SIZE(p_hwfn->cdev);
264 p_sb = &p_hwfn->hw_info.p_igu_info->igu_map.igu_blocks[sb_id];
265 if ((p_sb->status & QED_IGU_STATUS_FREE) &&
266 !(p_sb->status & QED_IGU_STATUS_PF)) {
267 val = qed_rd(p_hwfn, p_ptt,
268 IGU_REG_MAPPING_MEMORY + sb_id * 4);
269 SET_FIELD(val, IGU_MAPPING_LINE_VALID, 0);
270 qed_wr(p_hwfn, p_ptt,
271 IGU_REG_MAPPING_MEMORY + 4 * sb_id, val);
276 static void qed_iov_setup_vfdb(struct qed_hwfn *p_hwfn)
278 struct qed_hw_sriov_info *p_iov = p_hwfn->cdev->p_iov_info;
279 struct qed_pf_iov *p_iov_info = p_hwfn->pf_iov_info;
280 struct qed_bulletin_content *p_bulletin_virt;
281 dma_addr_t req_p, rply_p, bulletin_p;
282 union pfvf_tlvs *p_reply_virt_addr;
283 union vfpf_tlvs *p_req_virt_addr;
286 memset(p_iov_info->vfs_array, 0, sizeof(p_iov_info->vfs_array));
288 p_req_virt_addr = p_iov_info->mbx_msg_virt_addr;
289 req_p = p_iov_info->mbx_msg_phys_addr;
290 p_reply_virt_addr = p_iov_info->mbx_reply_virt_addr;
291 rply_p = p_iov_info->mbx_reply_phys_addr;
292 p_bulletin_virt = p_iov_info->p_bulletins;
293 bulletin_p = p_iov_info->bulletins_phys;
294 if (!p_req_virt_addr || !p_reply_virt_addr || !p_bulletin_virt) {
296 "qed_iov_setup_vfdb called without allocating mem first\n");
300 for (idx = 0; idx < p_iov->total_vfs; idx++) {
301 struct qed_vf_info *vf = &p_iov_info->vfs_array[idx];
304 vf->vf_mbx.req_virt = p_req_virt_addr + idx;
305 vf->vf_mbx.req_phys = req_p + idx * sizeof(union vfpf_tlvs);
306 vf->vf_mbx.reply_virt = p_reply_virt_addr + idx;
307 vf->vf_mbx.reply_phys = rply_p + idx * sizeof(union pfvf_tlvs);
309 vf->state = VF_STOPPED;
312 vf->bulletin.phys = idx *
313 sizeof(struct qed_bulletin_content) +
315 vf->bulletin.p_virt = p_bulletin_virt + idx;
316 vf->bulletin.size = sizeof(struct qed_bulletin_content);
318 vf->relative_vf_id = idx;
319 vf->abs_vf_id = idx + p_iov->first_vf_in_pf;
320 concrete = qed_vfid_to_concrete(p_hwfn, vf->abs_vf_id);
321 vf->concrete_fid = concrete;
322 vf->opaque_fid = (p_hwfn->hw_info.opaque_fid & 0xff) |
323 (vf->abs_vf_id << 8);
324 vf->vport_id = idx + 1;
326 vf->num_mac_filters = QED_ETH_VF_NUM_MAC_FILTERS;
327 vf->num_vlan_filters = QED_ETH_VF_NUM_VLAN_FILTERS;
331 static int qed_iov_allocate_vfdb(struct qed_hwfn *p_hwfn)
333 struct qed_pf_iov *p_iov_info = p_hwfn->pf_iov_info;
337 num_vfs = p_hwfn->cdev->p_iov_info->total_vfs;
339 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
340 "qed_iov_allocate_vfdb for %d VFs\n", num_vfs);
342 /* Allocate PF Mailbox buffer (per-VF) */
343 p_iov_info->mbx_msg_size = sizeof(union vfpf_tlvs) * num_vfs;
344 p_v_addr = &p_iov_info->mbx_msg_virt_addr;
345 *p_v_addr = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev,
346 p_iov_info->mbx_msg_size,
347 &p_iov_info->mbx_msg_phys_addr,
352 /* Allocate PF Mailbox Reply buffer (per-VF) */
353 p_iov_info->mbx_reply_size = sizeof(union pfvf_tlvs) * num_vfs;
354 p_v_addr = &p_iov_info->mbx_reply_virt_addr;
355 *p_v_addr = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev,
356 p_iov_info->mbx_reply_size,
357 &p_iov_info->mbx_reply_phys_addr,
362 p_iov_info->bulletins_size = sizeof(struct qed_bulletin_content) *
364 p_v_addr = &p_iov_info->p_bulletins;
365 *p_v_addr = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev,
366 p_iov_info->bulletins_size,
367 &p_iov_info->bulletins_phys,
374 "PF's Requests mailbox [%p virt 0x%llx phys], Response mailbox [%p virt 0x%llx phys] Bulletins [%p virt 0x%llx phys]\n",
375 p_iov_info->mbx_msg_virt_addr,
376 (u64) p_iov_info->mbx_msg_phys_addr,
377 p_iov_info->mbx_reply_virt_addr,
378 (u64) p_iov_info->mbx_reply_phys_addr,
379 p_iov_info->p_bulletins, (u64) p_iov_info->bulletins_phys);
384 static void qed_iov_free_vfdb(struct qed_hwfn *p_hwfn)
386 struct qed_pf_iov *p_iov_info = p_hwfn->pf_iov_info;
388 if (p_hwfn->pf_iov_info->mbx_msg_virt_addr)
389 dma_free_coherent(&p_hwfn->cdev->pdev->dev,
390 p_iov_info->mbx_msg_size,
391 p_iov_info->mbx_msg_virt_addr,
392 p_iov_info->mbx_msg_phys_addr);
394 if (p_hwfn->pf_iov_info->mbx_reply_virt_addr)
395 dma_free_coherent(&p_hwfn->cdev->pdev->dev,
396 p_iov_info->mbx_reply_size,
397 p_iov_info->mbx_reply_virt_addr,
398 p_iov_info->mbx_reply_phys_addr);
400 if (p_iov_info->p_bulletins)
401 dma_free_coherent(&p_hwfn->cdev->pdev->dev,
402 p_iov_info->bulletins_size,
403 p_iov_info->p_bulletins,
404 p_iov_info->bulletins_phys);
407 int qed_iov_alloc(struct qed_hwfn *p_hwfn)
409 struct qed_pf_iov *p_sriov;
411 if (!IS_PF_SRIOV(p_hwfn)) {
412 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
413 "No SR-IOV - no need for IOV db\n");
417 p_sriov = kzalloc(sizeof(*p_sriov), GFP_KERNEL);
419 DP_NOTICE(p_hwfn, "Failed to allocate `struct qed_sriov'\n");
423 p_hwfn->pf_iov_info = p_sriov;
425 return qed_iov_allocate_vfdb(p_hwfn);
428 void qed_iov_setup(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
430 if (!IS_PF_SRIOV(p_hwfn) || !IS_PF_SRIOV_ALLOC(p_hwfn))
433 qed_iov_setup_vfdb(p_hwfn);
434 qed_iov_clear_vf_igu_blocks(p_hwfn, p_ptt);
437 void qed_iov_free(struct qed_hwfn *p_hwfn)
439 if (IS_PF_SRIOV_ALLOC(p_hwfn)) {
440 qed_iov_free_vfdb(p_hwfn);
441 kfree(p_hwfn->pf_iov_info);
445 void qed_iov_free_hw_info(struct qed_dev *cdev)
447 kfree(cdev->p_iov_info);
448 cdev->p_iov_info = NULL;
451 int qed_iov_hw_info(struct qed_hwfn *p_hwfn)
453 struct qed_dev *cdev = p_hwfn->cdev;
457 if (IS_VF(p_hwfn->cdev))
460 /* Learn the PCI configuration */
461 pos = pci_find_ext_capability(p_hwfn->cdev->pdev,
462 PCI_EXT_CAP_ID_SRIOV);
464 DP_VERBOSE(p_hwfn, QED_MSG_IOV, "No PCIe IOV support\n");
468 /* Allocate a new struct for IOV information */
469 cdev->p_iov_info = kzalloc(sizeof(*cdev->p_iov_info), GFP_KERNEL);
470 if (!cdev->p_iov_info) {
471 DP_NOTICE(p_hwfn, "Can't support IOV due to lack of memory\n");
474 cdev->p_iov_info->pos = pos;
476 rc = qed_iov_pci_cfg_info(cdev);
480 /* We want PF IOV to be synonemous with the existance of p_iov_info;
481 * In case the capability is published but there are no VFs, simply
482 * de-allocate the struct.
484 if (!cdev->p_iov_info->total_vfs) {
485 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
486 "IOV capabilities, but no VFs are published\n");
487 kfree(cdev->p_iov_info);
488 cdev->p_iov_info = NULL;
492 /* Calculate the first VF index - this is a bit tricky; Basically,
493 * VFs start at offset 16 relative to PF0, and 2nd engine VFs begin
494 * after the first engine's VFs.
496 cdev->p_iov_info->first_vf_in_pf = p_hwfn->cdev->p_iov_info->offset +
497 p_hwfn->abs_pf_id - 16;
498 if (QED_PATH_ID(p_hwfn))
499 cdev->p_iov_info->first_vf_in_pf -= MAX_NUM_VFS_BB;
501 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
502 "First VF in hwfn 0x%08x\n",
503 cdev->p_iov_info->first_vf_in_pf);
508 static bool qed_iov_pf_sanity_check(struct qed_hwfn *p_hwfn, int vfid)
510 /* Check PF supports sriov */
511 if (IS_VF(p_hwfn->cdev) || !IS_QED_SRIOV(p_hwfn->cdev) ||
512 !IS_PF_SRIOV_ALLOC(p_hwfn))
515 /* Check VF validity */
516 if (!qed_iov_is_valid_vfid(p_hwfn, vfid, true))
522 static void qed_iov_set_vf_to_disable(struct qed_dev *cdev,
523 u16 rel_vf_id, u8 to_disable)
525 struct qed_vf_info *vf;
528 for_each_hwfn(cdev, i) {
529 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
531 vf = qed_iov_get_vf_info(p_hwfn, rel_vf_id, false);
535 vf->to_disable = to_disable;
539 void qed_iov_set_vfs_to_disable(struct qed_dev *cdev, u8 to_disable)
543 if (!IS_QED_SRIOV(cdev))
546 for (i = 0; i < cdev->p_iov_info->total_vfs; i++)
547 qed_iov_set_vf_to_disable(cdev, i, to_disable);
550 static void qed_iov_vf_pglue_clear_err(struct qed_hwfn *p_hwfn,
551 struct qed_ptt *p_ptt, u8 abs_vfid)
553 qed_wr(p_hwfn, p_ptt,
554 PGLUE_B_REG_WAS_ERROR_VF_31_0_CLR + (abs_vfid >> 5) * 4,
555 1 << (abs_vfid & 0x1f));
558 static void qed_iov_vf_igu_reset(struct qed_hwfn *p_hwfn,
559 struct qed_ptt *p_ptt, struct qed_vf_info *vf)
563 /* Set VF masks and configuration - pretend */
564 qed_fid_pretend(p_hwfn, p_ptt, (u16) vf->concrete_fid);
566 qed_wr(p_hwfn, p_ptt, IGU_REG_STATISTIC_NUM_VF_MSG_SENT, 0);
569 qed_fid_pretend(p_hwfn, p_ptt, (u16) p_hwfn->hw_info.concrete_fid);
571 /* iterate over all queues, clear sb consumer */
572 for (i = 0; i < vf->num_sbs; i++)
573 qed_int_igu_init_pure_rt_single(p_hwfn, p_ptt,
575 vf->opaque_fid, true);
578 static void qed_iov_vf_igu_set_int(struct qed_hwfn *p_hwfn,
579 struct qed_ptt *p_ptt,
580 struct qed_vf_info *vf, bool enable)
584 qed_fid_pretend(p_hwfn, p_ptt, (u16) vf->concrete_fid);
586 igu_vf_conf = qed_rd(p_hwfn, p_ptt, IGU_REG_VF_CONFIGURATION);
589 igu_vf_conf |= IGU_VF_CONF_MSI_MSIX_EN;
591 igu_vf_conf &= ~IGU_VF_CONF_MSI_MSIX_EN;
593 qed_wr(p_hwfn, p_ptt, IGU_REG_VF_CONFIGURATION, igu_vf_conf);
596 qed_fid_pretend(p_hwfn, p_ptt, (u16) p_hwfn->hw_info.concrete_fid);
599 static int qed_iov_enable_vf_access(struct qed_hwfn *p_hwfn,
600 struct qed_ptt *p_ptt,
601 struct qed_vf_info *vf)
603 u32 igu_vf_conf = IGU_VF_CONF_FUNC_EN;
611 "Enable internal access for vf %x [abs %x]\n",
612 vf->abs_vf_id, QED_VF_ABS_ID(p_hwfn, vf));
614 qed_iov_vf_pglue_clear_err(p_hwfn, p_ptt, QED_VF_ABS_ID(p_hwfn, vf));
616 qed_iov_vf_igu_reset(p_hwfn, p_ptt, vf);
618 rc = qed_mcp_config_vf_msix(p_hwfn, p_ptt, vf->abs_vf_id, vf->num_sbs);
622 qed_fid_pretend(p_hwfn, p_ptt, (u16) vf->concrete_fid);
624 SET_FIELD(igu_vf_conf, IGU_VF_CONF_PARENT, p_hwfn->rel_pf_id);
625 STORE_RT_REG(p_hwfn, IGU_REG_VF_CONFIGURATION_RT_OFFSET, igu_vf_conf);
627 qed_init_run(p_hwfn, p_ptt, PHASE_VF, vf->abs_vf_id,
628 p_hwfn->hw_info.hw_mode);
631 qed_fid_pretend(p_hwfn, p_ptt, (u16) p_hwfn->hw_info.concrete_fid);
639 * @brief qed_iov_config_perm_table - configure the permission
641 * In E4, queue zone permission table size is 320x9. There
642 * are 320 VF queues for single engine device (256 for dual
643 * engine device), and each entry has the following format:
650 static void qed_iov_config_perm_table(struct qed_hwfn *p_hwfn,
651 struct qed_ptt *p_ptt,
652 struct qed_vf_info *vf, u8 enable)
658 for (qid = 0; qid < vf->num_rxqs; qid++) {
659 qed_fw_l2_queue(p_hwfn, vf->vf_queues[qid].fw_rx_qid,
662 reg_addr = PSWHST_REG_ZONE_PERMISSION_TABLE + qzone_id * 4;
663 val = enable ? (vf->abs_vf_id | (1 << 8)) : 0;
664 qed_wr(p_hwfn, p_ptt, reg_addr, val);
668 static void qed_iov_enable_vf_traffic(struct qed_hwfn *p_hwfn,
669 struct qed_ptt *p_ptt,
670 struct qed_vf_info *vf)
672 /* Reset vf in IGU - interrupts are still disabled */
673 qed_iov_vf_igu_reset(p_hwfn, p_ptt, vf);
675 qed_iov_vf_igu_set_int(p_hwfn, p_ptt, vf, 1);
677 /* Permission Table */
678 qed_iov_config_perm_table(p_hwfn, p_ptt, vf, true);
681 static u8 qed_iov_alloc_vf_igu_sbs(struct qed_hwfn *p_hwfn,
682 struct qed_ptt *p_ptt,
683 struct qed_vf_info *vf, u16 num_rx_queues)
685 struct qed_igu_block *igu_blocks;
686 int qid = 0, igu_id = 0;
689 igu_blocks = p_hwfn->hw_info.p_igu_info->igu_map.igu_blocks;
691 if (num_rx_queues > p_hwfn->hw_info.p_igu_info->free_blks)
692 num_rx_queues = p_hwfn->hw_info.p_igu_info->free_blks;
693 p_hwfn->hw_info.p_igu_info->free_blks -= num_rx_queues;
695 SET_FIELD(val, IGU_MAPPING_LINE_FUNCTION_NUMBER, vf->abs_vf_id);
696 SET_FIELD(val, IGU_MAPPING_LINE_VALID, 1);
697 SET_FIELD(val, IGU_MAPPING_LINE_PF_VALID, 0);
699 while ((qid < num_rx_queues) &&
700 (igu_id < QED_MAPPING_MEMORY_SIZE(p_hwfn->cdev))) {
701 if (igu_blocks[igu_id].status & QED_IGU_STATUS_FREE) {
702 struct cau_sb_entry sb_entry;
704 vf->igu_sbs[qid] = (u16)igu_id;
705 igu_blocks[igu_id].status &= ~QED_IGU_STATUS_FREE;
707 SET_FIELD(val, IGU_MAPPING_LINE_VECTOR_NUMBER, qid);
709 qed_wr(p_hwfn, p_ptt,
710 IGU_REG_MAPPING_MEMORY + sizeof(u32) * igu_id,
713 /* Configure igu sb in CAU which were marked valid */
714 qed_init_cau_sb_entry(p_hwfn, &sb_entry,
717 qed_dmae_host2grc(p_hwfn, p_ptt,
718 (u64)(uintptr_t)&sb_entry,
719 CAU_REG_SB_VAR_MEMORY +
720 igu_id * sizeof(u64), 2, 0);
726 vf->num_sbs = (u8) num_rx_queues;
731 static void qed_iov_free_vf_igu_sbs(struct qed_hwfn *p_hwfn,
732 struct qed_ptt *p_ptt,
733 struct qed_vf_info *vf)
735 struct qed_igu_info *p_info = p_hwfn->hw_info.p_igu_info;
739 /* Invalidate igu CAM lines and mark them as free */
740 for (idx = 0; idx < vf->num_sbs; idx++) {
741 igu_id = vf->igu_sbs[idx];
742 addr = IGU_REG_MAPPING_MEMORY + sizeof(u32) * igu_id;
744 val = qed_rd(p_hwfn, p_ptt, addr);
745 SET_FIELD(val, IGU_MAPPING_LINE_VALID, 0);
746 qed_wr(p_hwfn, p_ptt, addr, val);
748 p_info->igu_map.igu_blocks[igu_id].status |=
751 p_hwfn->hw_info.p_igu_info->free_blks++;
757 static int qed_iov_init_hw_for_vf(struct qed_hwfn *p_hwfn,
758 struct qed_ptt *p_ptt,
759 u16 rel_vf_id, u16 num_rx_queues)
761 u8 num_of_vf_avaiable_chains = 0;
762 struct qed_vf_info *vf = NULL;
767 vf = qed_iov_get_vf_info(p_hwfn, rel_vf_id, false);
769 DP_ERR(p_hwfn, "qed_iov_init_hw_for_vf : vf is NULL\n");
774 DP_NOTICE(p_hwfn, "VF[%d] is already active.\n", rel_vf_id);
778 /* Limit number of queues according to number of CIDs */
779 qed_cxt_get_proto_cid_count(p_hwfn, PROTOCOLID_ETH, &cids);
782 "VF[%d] - requesting to initialize for 0x%04x queues [0x%04x CIDs available]\n",
783 vf->relative_vf_id, num_rx_queues, (u16) cids);
784 num_rx_queues = min_t(u16, num_rx_queues, ((u16) cids));
786 num_of_vf_avaiable_chains = qed_iov_alloc_vf_igu_sbs(p_hwfn,
790 if (!num_of_vf_avaiable_chains) {
791 DP_ERR(p_hwfn, "no available igu sbs\n");
795 /* Choose queue number and index ranges */
796 vf->num_rxqs = num_of_vf_avaiable_chains;
797 vf->num_txqs = num_of_vf_avaiable_chains;
799 for (i = 0; i < vf->num_rxqs; i++) {
800 u16 queue_id = qed_int_queue_id_from_sb_id(p_hwfn,
803 if (queue_id > RESC_NUM(p_hwfn, QED_L2_QUEUE)) {
805 "VF[%d] will require utilizing of out-of-bounds queues - %04x\n",
806 vf->relative_vf_id, queue_id);
810 /* CIDs are per-VF, so no problem having them 0-based. */
811 vf->vf_queues[i].fw_rx_qid = queue_id;
812 vf->vf_queues[i].fw_tx_qid = queue_id;
813 vf->vf_queues[i].fw_cid = i;
815 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
816 "VF[%d] - [%d] SB %04x, Tx/Rx queue %04x CID %04x\n",
817 vf->relative_vf_id, i, vf->igu_sbs[i], queue_id, i);
819 rc = qed_iov_enable_vf_access(p_hwfn, p_ptt, vf);
823 if (IS_LEAD_HWFN(p_hwfn))
824 p_hwfn->cdev->p_iov_info->num_vfs++;
830 static void qed_iov_set_link(struct qed_hwfn *p_hwfn,
832 struct qed_mcp_link_params *params,
833 struct qed_mcp_link_state *link,
834 struct qed_mcp_link_capabilities *p_caps)
836 struct qed_vf_info *p_vf = qed_iov_get_vf_info(p_hwfn,
839 struct qed_bulletin_content *p_bulletin;
844 p_bulletin = p_vf->bulletin.p_virt;
845 p_bulletin->req_autoneg = params->speed.autoneg;
846 p_bulletin->req_adv_speed = params->speed.advertised_speeds;
847 p_bulletin->req_forced_speed = params->speed.forced_speed;
848 p_bulletin->req_autoneg_pause = params->pause.autoneg;
849 p_bulletin->req_forced_rx = params->pause.forced_rx;
850 p_bulletin->req_forced_tx = params->pause.forced_tx;
851 p_bulletin->req_loopback = params->loopback_mode;
853 p_bulletin->link_up = link->link_up;
854 p_bulletin->speed = link->speed;
855 p_bulletin->full_duplex = link->full_duplex;
856 p_bulletin->autoneg = link->an;
857 p_bulletin->autoneg_complete = link->an_complete;
858 p_bulletin->parallel_detection = link->parallel_detection;
859 p_bulletin->pfc_enabled = link->pfc_enabled;
860 p_bulletin->partner_adv_speed = link->partner_adv_speed;
861 p_bulletin->partner_tx_flow_ctrl_en = link->partner_tx_flow_ctrl_en;
862 p_bulletin->partner_rx_flow_ctrl_en = link->partner_rx_flow_ctrl_en;
863 p_bulletin->partner_adv_pause = link->partner_adv_pause;
864 p_bulletin->sfp_tx_fault = link->sfp_tx_fault;
866 p_bulletin->capability_speed = p_caps->speed_capabilities;
869 static int qed_iov_release_hw_for_vf(struct qed_hwfn *p_hwfn,
870 struct qed_ptt *p_ptt, u16 rel_vf_id)
872 struct qed_mcp_link_capabilities caps;
873 struct qed_mcp_link_params params;
874 struct qed_mcp_link_state link;
875 struct qed_vf_info *vf = NULL;
877 vf = qed_iov_get_vf_info(p_hwfn, rel_vf_id, true);
879 DP_ERR(p_hwfn, "qed_iov_release_hw_for_vf : vf is NULL\n");
883 if (vf->bulletin.p_virt)
884 memset(vf->bulletin.p_virt, 0, sizeof(*vf->bulletin.p_virt));
886 memset(&vf->p_vf_info, 0, sizeof(vf->p_vf_info));
888 /* Get the link configuration back in bulletin so
889 * that when VFs are re-enabled they get the actual
890 * link configuration.
892 memcpy(¶ms, qed_mcp_get_link_params(p_hwfn), sizeof(params));
893 memcpy(&link, qed_mcp_get_link_state(p_hwfn), sizeof(link));
894 memcpy(&caps, qed_mcp_get_link_capabilities(p_hwfn), sizeof(caps));
895 qed_iov_set_link(p_hwfn, rel_vf_id, ¶ms, &link, &caps);
897 /* Forget the VF's acquisition message */
898 memset(&vf->acquire, 0, sizeof(vf->acquire));
900 /* disablng interrupts and resetting permission table was done during
901 * vf-close, however, we could get here without going through vf_close
903 /* Disable Interrupts for VF */
904 qed_iov_vf_igu_set_int(p_hwfn, p_ptt, vf, 0);
906 /* Reset Permission table */
907 qed_iov_config_perm_table(p_hwfn, p_ptt, vf, 0);
911 qed_iov_free_vf_igu_sbs(p_hwfn, p_ptt, vf);
916 if (IS_LEAD_HWFN(p_hwfn))
917 p_hwfn->cdev->p_iov_info->num_vfs--;
923 static bool qed_iov_tlv_supported(u16 tlvtype)
925 return CHANNEL_TLV_NONE < tlvtype && tlvtype < CHANNEL_TLV_MAX;
928 /* place a given tlv on the tlv buffer, continuing current tlv list */
929 void *qed_add_tlv(struct qed_hwfn *p_hwfn, u8 **offset, u16 type, u16 length)
931 struct channel_tlv *tl = (struct channel_tlv *)*offset;
936 /* Offset should keep pointing to next TLV (the end of the last) */
939 /* Return a pointer to the start of the added tlv */
940 return *offset - length;
943 /* list the types and lengths of the tlvs on the buffer */
944 void qed_dp_tlv_list(struct qed_hwfn *p_hwfn, void *tlvs_list)
946 u16 i = 1, total_length = 0;
947 struct channel_tlv *tlv;
950 tlv = (struct channel_tlv *)((u8 *)tlvs_list + total_length);
953 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
954 "TLV number %d: type %d, length %d\n",
955 i, tlv->type, tlv->length);
957 if (tlv->type == CHANNEL_TLV_LIST_END)
960 /* Validate entry - protect against malicious VFs */
962 DP_NOTICE(p_hwfn, "TLV of length 0 found\n");
966 total_length += tlv->length;
968 if (total_length >= sizeof(struct tlv_buffer_size)) {
969 DP_NOTICE(p_hwfn, "TLV ==> Buffer overflow\n");
977 static void qed_iov_send_response(struct qed_hwfn *p_hwfn,
978 struct qed_ptt *p_ptt,
979 struct qed_vf_info *p_vf,
980 u16 length, u8 status)
982 struct qed_iov_vf_mbx *mbx = &p_vf->vf_mbx;
983 struct qed_dmae_params params;
986 mbx->reply_virt->default_resp.hdr.status = status;
988 qed_dp_tlv_list(p_hwfn, mbx->reply_virt);
990 eng_vf_id = p_vf->abs_vf_id;
992 memset(¶ms, 0, sizeof(struct qed_dmae_params));
993 params.flags = QED_DMAE_FLAG_VF_DST;
994 params.dst_vfid = eng_vf_id;
996 qed_dmae_host2host(p_hwfn, p_ptt, mbx->reply_phys + sizeof(u64),
997 mbx->req_virt->first_tlv.reply_address +
999 (sizeof(union pfvf_tlvs) - sizeof(u64)) / 4,
1002 qed_dmae_host2host(p_hwfn, p_ptt, mbx->reply_phys,
1003 mbx->req_virt->first_tlv.reply_address,
1004 sizeof(u64) / 4, ¶ms);
1007 GTT_BAR0_MAP_REG_USDM_RAM +
1008 USTORM_VF_PF_CHANNEL_READY_OFFSET(eng_vf_id), 1);
1011 static u16 qed_iov_vport_to_tlv(struct qed_hwfn *p_hwfn,
1012 enum qed_iov_vport_update_flag flag)
1015 case QED_IOV_VP_UPDATE_ACTIVATE:
1016 return CHANNEL_TLV_VPORT_UPDATE_ACTIVATE;
1017 case QED_IOV_VP_UPDATE_VLAN_STRIP:
1018 return CHANNEL_TLV_VPORT_UPDATE_VLAN_STRIP;
1019 case QED_IOV_VP_UPDATE_TX_SWITCH:
1020 return CHANNEL_TLV_VPORT_UPDATE_TX_SWITCH;
1021 case QED_IOV_VP_UPDATE_MCAST:
1022 return CHANNEL_TLV_VPORT_UPDATE_MCAST;
1023 case QED_IOV_VP_UPDATE_ACCEPT_PARAM:
1024 return CHANNEL_TLV_VPORT_UPDATE_ACCEPT_PARAM;
1025 case QED_IOV_VP_UPDATE_RSS:
1026 return CHANNEL_TLV_VPORT_UPDATE_RSS;
1027 case QED_IOV_VP_UPDATE_ACCEPT_ANY_VLAN:
1028 return CHANNEL_TLV_VPORT_UPDATE_ACCEPT_ANY_VLAN;
1029 case QED_IOV_VP_UPDATE_SGE_TPA:
1030 return CHANNEL_TLV_VPORT_UPDATE_SGE_TPA;
1036 static u16 qed_iov_prep_vp_update_resp_tlvs(struct qed_hwfn *p_hwfn,
1037 struct qed_vf_info *p_vf,
1038 struct qed_iov_vf_mbx *p_mbx,
1040 u16 tlvs_mask, u16 tlvs_accepted)
1042 struct pfvf_def_resp_tlv *resp;
1043 u16 size, total_len, i;
1045 memset(p_mbx->reply_virt, 0, sizeof(union pfvf_tlvs));
1046 p_mbx->offset = (u8 *)p_mbx->reply_virt;
1047 size = sizeof(struct pfvf_def_resp_tlv);
1050 qed_add_tlv(p_hwfn, &p_mbx->offset, CHANNEL_TLV_VPORT_UPDATE, size);
1052 /* Prepare response for all extended tlvs if they are found by PF */
1053 for (i = 0; i < QED_IOV_VP_UPDATE_MAX; i++) {
1054 if (!(tlvs_mask & (1 << i)))
1057 resp = qed_add_tlv(p_hwfn, &p_mbx->offset,
1058 qed_iov_vport_to_tlv(p_hwfn, i), size);
1060 if (tlvs_accepted & (1 << i))
1061 resp->hdr.status = status;
1063 resp->hdr.status = PFVF_STATUS_NOT_SUPPORTED;
1067 "VF[%d] - vport_update response: TLV %d, status %02x\n",
1068 p_vf->relative_vf_id,
1069 qed_iov_vport_to_tlv(p_hwfn, i), resp->hdr.status);
1074 qed_add_tlv(p_hwfn, &p_mbx->offset, CHANNEL_TLV_LIST_END,
1075 sizeof(struct channel_list_end_tlv));
1080 static void qed_iov_prepare_resp(struct qed_hwfn *p_hwfn,
1081 struct qed_ptt *p_ptt,
1082 struct qed_vf_info *vf_info,
1083 u16 type, u16 length, u8 status)
1085 struct qed_iov_vf_mbx *mbx = &vf_info->vf_mbx;
1087 mbx->offset = (u8 *)mbx->reply_virt;
1089 qed_add_tlv(p_hwfn, &mbx->offset, type, length);
1090 qed_add_tlv(p_hwfn, &mbx->offset, CHANNEL_TLV_LIST_END,
1091 sizeof(struct channel_list_end_tlv));
1093 qed_iov_send_response(p_hwfn, p_ptt, vf_info, length, status);
1096 struct qed_public_vf_info *qed_iov_get_public_vf_info(struct qed_hwfn *p_hwfn,
1098 bool b_enabled_only)
1100 struct qed_vf_info *vf = NULL;
1102 vf = qed_iov_get_vf_info(p_hwfn, relative_vf_id, b_enabled_only);
1106 return &vf->p_vf_info;
1109 void qed_iov_clean_vf(struct qed_hwfn *p_hwfn, u8 vfid)
1111 struct qed_public_vf_info *vf_info;
1113 vf_info = qed_iov_get_public_vf_info(p_hwfn, vfid, false);
1118 /* Clear the VF mac */
1119 memset(vf_info->mac, 0, ETH_ALEN);
1122 static void qed_iov_vf_cleanup(struct qed_hwfn *p_hwfn,
1123 struct qed_vf_info *p_vf)
1127 p_vf->vf_bulletin = 0;
1128 p_vf->vport_instance = 0;
1129 p_vf->configured_features = 0;
1131 /* If VF previously requested less resources, go back to default */
1132 p_vf->num_rxqs = p_vf->num_sbs;
1133 p_vf->num_txqs = p_vf->num_sbs;
1135 p_vf->num_active_rxqs = 0;
1137 for (i = 0; i < QED_MAX_VF_CHAINS_PER_PF; i++)
1138 p_vf->vf_queues[i].rxq_active = 0;
1140 memset(&p_vf->shadow_config, 0, sizeof(p_vf->shadow_config));
1141 memset(&p_vf->acquire, 0, sizeof(p_vf->acquire));
1142 qed_iov_clean_vf(p_hwfn, p_vf->relative_vf_id);
1145 static u8 qed_iov_vf_mbx_acquire_resc(struct qed_hwfn *p_hwfn,
1146 struct qed_ptt *p_ptt,
1147 struct qed_vf_info *p_vf,
1148 struct vf_pf_resc_request *p_req,
1149 struct pf_vf_resc *p_resp)
1153 /* Queue related information */
1154 p_resp->num_rxqs = p_vf->num_rxqs;
1155 p_resp->num_txqs = p_vf->num_txqs;
1156 p_resp->num_sbs = p_vf->num_sbs;
1158 for (i = 0; i < p_resp->num_sbs; i++) {
1159 p_resp->hw_sbs[i].hw_sb_id = p_vf->igu_sbs[i];
1160 p_resp->hw_sbs[i].sb_qid = 0;
1163 /* These fields are filled for backward compatibility.
1164 * Unused by modern vfs.
1166 for (i = 0; i < p_resp->num_rxqs; i++) {
1167 qed_fw_l2_queue(p_hwfn, p_vf->vf_queues[i].fw_rx_qid,
1168 (u16 *)&p_resp->hw_qid[i]);
1169 p_resp->cid[i] = p_vf->vf_queues[i].fw_cid;
1172 /* Filter related information */
1173 p_resp->num_mac_filters = min_t(u8, p_vf->num_mac_filters,
1174 p_req->num_mac_filters);
1175 p_resp->num_vlan_filters = min_t(u8, p_vf->num_vlan_filters,
1176 p_req->num_vlan_filters);
1178 /* This isn't really needed/enforced, but some legacy VFs might depend
1179 * on the correct filling of this field.
1181 p_resp->num_mc_filters = QED_MAX_MC_ADDRS;
1183 /* Validate sufficient resources for VF */
1184 if (p_resp->num_rxqs < p_req->num_rxqs ||
1185 p_resp->num_txqs < p_req->num_txqs ||
1186 p_resp->num_sbs < p_req->num_sbs ||
1187 p_resp->num_mac_filters < p_req->num_mac_filters ||
1188 p_resp->num_vlan_filters < p_req->num_vlan_filters ||
1189 p_resp->num_mc_filters < p_req->num_mc_filters) {
1192 "VF[%d] - Insufficient resources: rxq [%02x/%02x] txq [%02x/%02x] sbs [%02x/%02x] mac [%02x/%02x] vlan [%02x/%02x] mc [%02x/%02x]\n",
1200 p_req->num_mac_filters,
1201 p_resp->num_mac_filters,
1202 p_req->num_vlan_filters,
1203 p_resp->num_vlan_filters,
1204 p_req->num_mc_filters, p_resp->num_mc_filters);
1205 return PFVF_STATUS_NO_RESOURCE;
1208 return PFVF_STATUS_SUCCESS;
1211 static void qed_iov_vf_mbx_acquire_stats(struct qed_hwfn *p_hwfn,
1212 struct pfvf_stats_info *p_stats)
1214 p_stats->mstats.address = PXP_VF_BAR0_START_MSDM_ZONE_B +
1215 offsetof(struct mstorm_vf_zone,
1216 non_trigger.eth_queue_stat);
1217 p_stats->mstats.len = sizeof(struct eth_mstorm_per_queue_stat);
1218 p_stats->ustats.address = PXP_VF_BAR0_START_USDM_ZONE_B +
1219 offsetof(struct ustorm_vf_zone,
1220 non_trigger.eth_queue_stat);
1221 p_stats->ustats.len = sizeof(struct eth_ustorm_per_queue_stat);
1222 p_stats->pstats.address = PXP_VF_BAR0_START_PSDM_ZONE_B +
1223 offsetof(struct pstorm_vf_zone,
1224 non_trigger.eth_queue_stat);
1225 p_stats->pstats.len = sizeof(struct eth_pstorm_per_queue_stat);
1226 p_stats->tstats.address = 0;
1227 p_stats->tstats.len = 0;
1230 static void qed_iov_vf_mbx_acquire(struct qed_hwfn *p_hwfn,
1231 struct qed_ptt *p_ptt,
1232 struct qed_vf_info *vf)
1234 struct qed_iov_vf_mbx *mbx = &vf->vf_mbx;
1235 struct pfvf_acquire_resp_tlv *resp = &mbx->reply_virt->acquire_resp;
1236 struct pf_vf_pfdev_info *pfdev_info = &resp->pfdev_info;
1237 struct vfpf_acquire_tlv *req = &mbx->req_virt->acquire;
1238 u8 vfpf_status = PFVF_STATUS_NOT_SUPPORTED;
1239 struct pf_vf_resc *resc = &resp->resc;
1242 memset(resp, 0, sizeof(*resp));
1244 /* Validate FW compatibility */
1245 if (req->vfdev_info.eth_fp_hsi_major != ETH_HSI_VER_MAJOR) {
1247 "VF[%d] needs fastpath HSI %02x.%02x, which is incompatible with loaded FW's faspath HSI %02x.%02x\n",
1249 req->vfdev_info.eth_fp_hsi_major,
1250 req->vfdev_info.eth_fp_hsi_minor,
1251 ETH_HSI_VER_MAJOR, ETH_HSI_VER_MINOR);
1253 /* Write the PF version so that VF would know which version
1256 pfdev_info->major_fp_hsi = ETH_HSI_VER_MAJOR;
1257 pfdev_info->minor_fp_hsi = ETH_HSI_VER_MINOR;
1262 /* On 100g PFs, prevent old VFs from loading */
1263 if ((p_hwfn->cdev->num_hwfns > 1) &&
1264 !(req->vfdev_info.capabilities & VFPF_ACQUIRE_CAP_100G)) {
1266 "VF[%d] is running an old driver that doesn't support 100g\n",
1271 /* Store the acquire message */
1272 memcpy(&vf->acquire, req, sizeof(vf->acquire));
1274 vf->opaque_fid = req->vfdev_info.opaque_fid;
1276 vf->vf_bulletin = req->bulletin_addr;
1277 vf->bulletin.size = (vf->bulletin.size < req->bulletin_size) ?
1278 vf->bulletin.size : req->bulletin_size;
1280 /* fill in pfdev info */
1281 pfdev_info->chip_num = p_hwfn->cdev->chip_num;
1282 pfdev_info->db_size = 0;
1283 pfdev_info->indices_per_sb = PIS_PER_SB;
1285 pfdev_info->capabilities = PFVF_ACQUIRE_CAP_DEFAULT_UNTAGGED |
1286 PFVF_ACQUIRE_CAP_POST_FW_OVERRIDE;
1287 if (p_hwfn->cdev->num_hwfns > 1)
1288 pfdev_info->capabilities |= PFVF_ACQUIRE_CAP_100G;
1290 qed_iov_vf_mbx_acquire_stats(p_hwfn, &pfdev_info->stats_info);
1292 memcpy(pfdev_info->port_mac, p_hwfn->hw_info.hw_mac_addr, ETH_ALEN);
1294 pfdev_info->fw_major = FW_MAJOR_VERSION;
1295 pfdev_info->fw_minor = FW_MINOR_VERSION;
1296 pfdev_info->fw_rev = FW_REVISION_VERSION;
1297 pfdev_info->fw_eng = FW_ENGINEERING_VERSION;
1298 pfdev_info->minor_fp_hsi = min_t(u8,
1300 req->vfdev_info.eth_fp_hsi_minor);
1301 pfdev_info->os_type = VFPF_ACQUIRE_OS_LINUX;
1302 qed_mcp_get_mfw_ver(p_hwfn, p_ptt, &pfdev_info->mfw_ver, NULL);
1304 pfdev_info->dev_type = p_hwfn->cdev->type;
1305 pfdev_info->chip_rev = p_hwfn->cdev->chip_rev;
1307 /* Fill resources available to VF; Make sure there are enough to
1308 * satisfy the VF's request.
1310 vfpf_status = qed_iov_vf_mbx_acquire_resc(p_hwfn, p_ptt, vf,
1311 &req->resc_request, resc);
1312 if (vfpf_status != PFVF_STATUS_SUCCESS)
1315 /* Start the VF in FW */
1316 rc = qed_sp_vf_start(p_hwfn, vf);
1318 DP_NOTICE(p_hwfn, "Failed to start VF[%02x]\n", vf->abs_vf_id);
1319 vfpf_status = PFVF_STATUS_FAILURE;
1323 /* Fill agreed size of bulletin board in response */
1324 resp->bulletin_size = vf->bulletin.size;
1325 qed_iov_post_vf_bulletin(p_hwfn, vf->relative_vf_id, p_ptt);
1329 "VF[%d] ACQUIRE_RESPONSE: pfdev_info- chip_num=0x%x, db_size=%d, idx_per_sb=%d, pf_cap=0x%llx\n"
1330 "resources- n_rxq-%d, n_txq-%d, n_sbs-%d, n_macs-%d, n_vlans-%d\n",
1332 resp->pfdev_info.chip_num,
1333 resp->pfdev_info.db_size,
1334 resp->pfdev_info.indices_per_sb,
1335 resp->pfdev_info.capabilities,
1339 resc->num_mac_filters,
1340 resc->num_vlan_filters);
1341 vf->state = VF_ACQUIRED;
1343 /* Prepare Response */
1345 qed_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_ACQUIRE,
1346 sizeof(struct pfvf_acquire_resp_tlv), vfpf_status);
1349 static int __qed_iov_spoofchk_set(struct qed_hwfn *p_hwfn,
1350 struct qed_vf_info *p_vf, bool val)
1352 struct qed_sp_vport_update_params params;
1355 if (val == p_vf->spoof_chk) {
1356 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
1357 "Spoofchk value[%d] is already configured\n", val);
1361 memset(¶ms, 0, sizeof(struct qed_sp_vport_update_params));
1362 params.opaque_fid = p_vf->opaque_fid;
1363 params.vport_id = p_vf->vport_id;
1364 params.update_anti_spoofing_en_flg = 1;
1365 params.anti_spoofing_en = val;
1367 rc = qed_sp_vport_update(p_hwfn, ¶ms, QED_SPQ_MODE_EBLOCK, NULL);
1369 p_vf->spoof_chk = val;
1370 p_vf->req_spoofchk_val = p_vf->spoof_chk;
1371 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
1372 "Spoofchk val[%d] configured\n", val);
1374 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
1375 "Spoofchk configuration[val:%d] failed for VF[%d]\n",
1376 val, p_vf->relative_vf_id);
1382 static int qed_iov_reconfigure_unicast_vlan(struct qed_hwfn *p_hwfn,
1383 struct qed_vf_info *p_vf)
1385 struct qed_filter_ucast filter;
1389 memset(&filter, 0, sizeof(filter));
1390 filter.is_rx_filter = 1;
1391 filter.is_tx_filter = 1;
1392 filter.vport_to_add_to = p_vf->vport_id;
1393 filter.opcode = QED_FILTER_ADD;
1395 /* Reconfigure vlans */
1396 for (i = 0; i < QED_ETH_VF_NUM_VLAN_FILTERS + 1; i++) {
1397 if (!p_vf->shadow_config.vlans[i].used)
1400 filter.type = QED_FILTER_VLAN;
1401 filter.vlan = p_vf->shadow_config.vlans[i].vid;
1404 "Reconfiguring VLAN [0x%04x] for VF [%04x]\n",
1405 filter.vlan, p_vf->relative_vf_id);
1406 rc = qed_sp_eth_filter_ucast(p_hwfn,
1409 QED_SPQ_MODE_CB, NULL);
1412 "Failed to configure VLAN [%04x] to VF [%04x]\n",
1413 filter.vlan, p_vf->relative_vf_id);
1422 qed_iov_reconfigure_unicast_shadow(struct qed_hwfn *p_hwfn,
1423 struct qed_vf_info *p_vf, u64 events)
1427 if ((events & (1 << VLAN_ADDR_FORCED)) &&
1428 !(p_vf->configured_features & (1 << VLAN_ADDR_FORCED)))
1429 rc = qed_iov_reconfigure_unicast_vlan(p_hwfn, p_vf);
1434 static int qed_iov_configure_vport_forced(struct qed_hwfn *p_hwfn,
1435 struct qed_vf_info *p_vf, u64 events)
1438 struct qed_filter_ucast filter;
1440 if (!p_vf->vport_instance)
1443 if (events & (1 << MAC_ADDR_FORCED)) {
1444 /* Since there's no way [currently] of removing the MAC,
1445 * we can always assume this means we need to force it.
1447 memset(&filter, 0, sizeof(filter));
1448 filter.type = QED_FILTER_MAC;
1449 filter.opcode = QED_FILTER_REPLACE;
1450 filter.is_rx_filter = 1;
1451 filter.is_tx_filter = 1;
1452 filter.vport_to_add_to = p_vf->vport_id;
1453 ether_addr_copy(filter.mac, p_vf->bulletin.p_virt->mac);
1455 rc = qed_sp_eth_filter_ucast(p_hwfn, p_vf->opaque_fid,
1456 &filter, QED_SPQ_MODE_CB, NULL);
1459 "PF failed to configure MAC for VF\n");
1463 p_vf->configured_features |= 1 << MAC_ADDR_FORCED;
1466 if (events & (1 << VLAN_ADDR_FORCED)) {
1467 struct qed_sp_vport_update_params vport_update;
1471 memset(&filter, 0, sizeof(filter));
1472 filter.type = QED_FILTER_VLAN;
1473 filter.is_rx_filter = 1;
1474 filter.is_tx_filter = 1;
1475 filter.vport_to_add_to = p_vf->vport_id;
1476 filter.vlan = p_vf->bulletin.p_virt->pvid;
1477 filter.opcode = filter.vlan ? QED_FILTER_REPLACE :
1480 /* Send the ramrod */
1481 rc = qed_sp_eth_filter_ucast(p_hwfn, p_vf->opaque_fid,
1482 &filter, QED_SPQ_MODE_CB, NULL);
1485 "PF failed to configure VLAN for VF\n");
1489 /* Update the default-vlan & silent vlan stripping */
1490 memset(&vport_update, 0, sizeof(vport_update));
1491 vport_update.opaque_fid = p_vf->opaque_fid;
1492 vport_update.vport_id = p_vf->vport_id;
1493 vport_update.update_default_vlan_enable_flg = 1;
1494 vport_update.default_vlan_enable_flg = filter.vlan ? 1 : 0;
1495 vport_update.update_default_vlan_flg = 1;
1496 vport_update.default_vlan = filter.vlan;
1498 vport_update.update_inner_vlan_removal_flg = 1;
1499 removal = filter.vlan ? 1
1500 : p_vf->shadow_config.inner_vlan_removal;
1501 vport_update.inner_vlan_removal_flg = removal;
1502 vport_update.silent_vlan_removal_flg = filter.vlan ? 1 : 0;
1503 rc = qed_sp_vport_update(p_hwfn,
1505 QED_SPQ_MODE_EBLOCK, NULL);
1508 "PF failed to configure VF vport for vlan\n");
1512 /* Update all the Rx queues */
1513 for (i = 0; i < QED_MAX_VF_CHAINS_PER_PF; i++) {
1516 if (!p_vf->vf_queues[i].rxq_active)
1519 qid = p_vf->vf_queues[i].fw_rx_qid;
1521 rc = qed_sp_eth_rx_queues_update(p_hwfn, qid,
1523 QED_SPQ_MODE_EBLOCK,
1527 "Failed to send Rx update fo queue[0x%04x]\n",
1534 p_vf->configured_features |= 1 << VLAN_ADDR_FORCED;
1536 p_vf->configured_features &= ~(1 << VLAN_ADDR_FORCED);
1539 /* If forced features are terminated, we need to configure the shadow
1540 * configuration back again.
1543 qed_iov_reconfigure_unicast_shadow(p_hwfn, p_vf, events);
1548 static void qed_iov_vf_mbx_start_vport(struct qed_hwfn *p_hwfn,
1549 struct qed_ptt *p_ptt,
1550 struct qed_vf_info *vf)
1552 struct qed_sp_vport_start_params params = { 0 };
1553 struct qed_iov_vf_mbx *mbx = &vf->vf_mbx;
1554 struct vfpf_vport_start_tlv *start;
1555 u8 status = PFVF_STATUS_SUCCESS;
1556 struct qed_vf_info *vf_info;
1561 vf_info = qed_iov_get_vf_info(p_hwfn, (u16) vf->relative_vf_id, true);
1563 DP_NOTICE(p_hwfn->cdev,
1564 "Failed to get VF info, invalid vfid [%d]\n",
1565 vf->relative_vf_id);
1569 vf->state = VF_ENABLED;
1570 start = &mbx->req_virt->start_vport;
1572 /* Initialize Status block in CAU */
1573 for (sb_id = 0; sb_id < vf->num_sbs; sb_id++) {
1574 if (!start->sb_addr[sb_id]) {
1575 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
1576 "VF[%d] did not fill the address of SB %d\n",
1577 vf->relative_vf_id, sb_id);
1581 qed_int_cau_conf_sb(p_hwfn, p_ptt,
1582 start->sb_addr[sb_id],
1586 qed_iov_enable_vf_traffic(p_hwfn, p_ptt, vf);
1588 vf->mtu = start->mtu;
1589 vf->shadow_config.inner_vlan_removal = start->inner_vlan_removal;
1591 /* Take into consideration configuration forced by hypervisor;
1592 * If none is configured, use the supplied VF values [for old
1593 * vfs that would still be fine, since they passed '0' as padding].
1595 p_bitmap = &vf_info->bulletin.p_virt->valid_bitmap;
1596 if (!(*p_bitmap & (1 << VFPF_BULLETIN_UNTAGGED_DEFAULT_FORCED))) {
1597 u8 vf_req = start->only_untagged;
1599 vf_info->bulletin.p_virt->default_only_untagged = vf_req;
1600 *p_bitmap |= 1 << VFPF_BULLETIN_UNTAGGED_DEFAULT;
1603 params.tpa_mode = start->tpa_mode;
1604 params.remove_inner_vlan = start->inner_vlan_removal;
1605 params.tx_switching = true;
1607 params.only_untagged = vf_info->bulletin.p_virt->default_only_untagged;
1608 params.drop_ttl0 = false;
1609 params.concrete_fid = vf->concrete_fid;
1610 params.opaque_fid = vf->opaque_fid;
1611 params.vport_id = vf->vport_id;
1612 params.max_buffers_per_cqe = start->max_buffers_per_cqe;
1613 params.mtu = vf->mtu;
1615 rc = qed_sp_eth_vport_start(p_hwfn, ¶ms);
1618 "qed_iov_vf_mbx_start_vport returned error %d\n", rc);
1619 status = PFVF_STATUS_FAILURE;
1621 vf->vport_instance++;
1623 /* Force configuration if needed on the newly opened vport */
1624 qed_iov_configure_vport_forced(p_hwfn, vf, *p_bitmap);
1626 __qed_iov_spoofchk_set(p_hwfn, vf, vf->req_spoofchk_val);
1628 qed_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_VPORT_START,
1629 sizeof(struct pfvf_def_resp_tlv), status);
1632 static void qed_iov_vf_mbx_stop_vport(struct qed_hwfn *p_hwfn,
1633 struct qed_ptt *p_ptt,
1634 struct qed_vf_info *vf)
1636 u8 status = PFVF_STATUS_SUCCESS;
1639 vf->vport_instance--;
1640 vf->spoof_chk = false;
1642 rc = qed_sp_vport_stop(p_hwfn, vf->opaque_fid, vf->vport_id);
1644 DP_ERR(p_hwfn, "qed_iov_vf_mbx_stop_vport returned error %d\n",
1646 status = PFVF_STATUS_FAILURE;
1649 /* Forget the configuration on the vport */
1650 vf->configured_features = 0;
1651 memset(&vf->shadow_config, 0, sizeof(vf->shadow_config));
1653 qed_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_VPORT_TEARDOWN,
1654 sizeof(struct pfvf_def_resp_tlv), status);
1657 static void qed_iov_vf_mbx_start_rxq_resp(struct qed_hwfn *p_hwfn,
1658 struct qed_ptt *p_ptt,
1659 struct qed_vf_info *vf, u8 status)
1661 struct qed_iov_vf_mbx *mbx = &vf->vf_mbx;
1662 struct pfvf_start_queue_resp_tlv *p_tlv;
1663 struct vfpf_start_rxq_tlv *req;
1665 mbx->offset = (u8 *)mbx->reply_virt;
1667 p_tlv = qed_add_tlv(p_hwfn, &mbx->offset, CHANNEL_TLV_START_RXQ,
1669 qed_add_tlv(p_hwfn, &mbx->offset, CHANNEL_TLV_LIST_END,
1670 sizeof(struct channel_list_end_tlv));
1672 /* Update the TLV with the response */
1673 if (status == PFVF_STATUS_SUCCESS) {
1674 req = &mbx->req_virt->start_rxq;
1675 p_tlv->offset = PXP_VF_BAR0_START_MSDM_ZONE_B +
1676 offsetof(struct mstorm_vf_zone,
1677 non_trigger.eth_rx_queue_producers) +
1678 sizeof(struct eth_rx_prod_data) * req->rx_qid;
1681 qed_iov_send_response(p_hwfn, p_ptt, vf, sizeof(*p_tlv), status);
1684 static void qed_iov_vf_mbx_start_rxq(struct qed_hwfn *p_hwfn,
1685 struct qed_ptt *p_ptt,
1686 struct qed_vf_info *vf)
1688 struct qed_queue_start_common_params params;
1689 struct qed_iov_vf_mbx *mbx = &vf->vf_mbx;
1690 u8 status = PFVF_STATUS_SUCCESS;
1691 struct vfpf_start_rxq_tlv *req;
1694 memset(¶ms, 0, sizeof(params));
1695 req = &mbx->req_virt->start_rxq;
1696 params.queue_id = vf->vf_queues[req->rx_qid].fw_rx_qid;
1697 params.vf_qid = req->rx_qid;
1698 params.vport_id = vf->vport_id;
1699 params.sb = req->hw_sb;
1700 params.sb_idx = req->sb_index;
1702 rc = qed_sp_eth_rxq_start_ramrod(p_hwfn, vf->opaque_fid,
1703 vf->vf_queues[req->rx_qid].fw_cid,
1705 vf->abs_vf_id + 0x10,
1708 req->cqe_pbl_addr, req->cqe_pbl_size);
1711 status = PFVF_STATUS_FAILURE;
1713 vf->vf_queues[req->rx_qid].rxq_active = true;
1714 vf->num_active_rxqs++;
1717 qed_iov_vf_mbx_start_rxq_resp(p_hwfn, p_ptt, vf, status);
1720 static void qed_iov_vf_mbx_start_txq(struct qed_hwfn *p_hwfn,
1721 struct qed_ptt *p_ptt,
1722 struct qed_vf_info *vf)
1724 u16 length = sizeof(struct pfvf_def_resp_tlv);
1725 struct qed_queue_start_common_params params;
1726 struct qed_iov_vf_mbx *mbx = &vf->vf_mbx;
1727 union qed_qm_pq_params pq_params;
1728 u8 status = PFVF_STATUS_SUCCESS;
1729 struct vfpf_start_txq_tlv *req;
1732 /* Prepare the parameters which would choose the right PQ */
1733 memset(&pq_params, 0, sizeof(pq_params));
1734 pq_params.eth.is_vf = 1;
1735 pq_params.eth.vf_id = vf->relative_vf_id;
1737 memset(¶ms, 0, sizeof(params));
1738 req = &mbx->req_virt->start_txq;
1739 params.queue_id = vf->vf_queues[req->tx_qid].fw_tx_qid;
1740 params.vport_id = vf->vport_id;
1741 params.sb = req->hw_sb;
1742 params.sb_idx = req->sb_index;
1744 rc = qed_sp_eth_txq_start_ramrod(p_hwfn,
1746 vf->vf_queues[req->tx_qid].fw_cid,
1748 vf->abs_vf_id + 0x10,
1750 req->pbl_size, &pq_params);
1753 status = PFVF_STATUS_FAILURE;
1755 vf->vf_queues[req->tx_qid].txq_active = true;
1757 qed_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_START_TXQ,
1761 static int qed_iov_vf_stop_rxqs(struct qed_hwfn *p_hwfn,
1762 struct qed_vf_info *vf,
1763 u16 rxq_id, u8 num_rxqs, bool cqe_completion)
1768 if (rxq_id + num_rxqs > ARRAY_SIZE(vf->vf_queues))
1771 for (qid = rxq_id; qid < rxq_id + num_rxqs; qid++) {
1772 if (vf->vf_queues[qid].rxq_active) {
1773 rc = qed_sp_eth_rx_queue_stop(p_hwfn,
1781 vf->vf_queues[qid].rxq_active = false;
1782 vf->num_active_rxqs--;
1788 static int qed_iov_vf_stop_txqs(struct qed_hwfn *p_hwfn,
1789 struct qed_vf_info *vf, u16 txq_id, u8 num_txqs)
1794 if (txq_id + num_txqs > ARRAY_SIZE(vf->vf_queues))
1797 for (qid = txq_id; qid < txq_id + num_txqs; qid++) {
1798 if (vf->vf_queues[qid].txq_active) {
1799 rc = qed_sp_eth_tx_queue_stop(p_hwfn,
1806 vf->vf_queues[qid].txq_active = false;
1811 static void qed_iov_vf_mbx_stop_rxqs(struct qed_hwfn *p_hwfn,
1812 struct qed_ptt *p_ptt,
1813 struct qed_vf_info *vf)
1815 u16 length = sizeof(struct pfvf_def_resp_tlv);
1816 struct qed_iov_vf_mbx *mbx = &vf->vf_mbx;
1817 u8 status = PFVF_STATUS_SUCCESS;
1818 struct vfpf_stop_rxqs_tlv *req;
1821 /* We give the option of starting from qid != 0, in this case we
1822 * need to make sure that qid + num_qs doesn't exceed the actual
1823 * amount of queues that exist.
1825 req = &mbx->req_virt->stop_rxqs;
1826 rc = qed_iov_vf_stop_rxqs(p_hwfn, vf, req->rx_qid,
1827 req->num_rxqs, req->cqe_completion);
1829 status = PFVF_STATUS_FAILURE;
1831 qed_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_STOP_RXQS,
1835 static void qed_iov_vf_mbx_stop_txqs(struct qed_hwfn *p_hwfn,
1836 struct qed_ptt *p_ptt,
1837 struct qed_vf_info *vf)
1839 u16 length = sizeof(struct pfvf_def_resp_tlv);
1840 struct qed_iov_vf_mbx *mbx = &vf->vf_mbx;
1841 u8 status = PFVF_STATUS_SUCCESS;
1842 struct vfpf_stop_txqs_tlv *req;
1845 /* We give the option of starting from qid != 0, in this case we
1846 * need to make sure that qid + num_qs doesn't exceed the actual
1847 * amount of queues that exist.
1849 req = &mbx->req_virt->stop_txqs;
1850 rc = qed_iov_vf_stop_txqs(p_hwfn, vf, req->tx_qid, req->num_txqs);
1852 status = PFVF_STATUS_FAILURE;
1854 qed_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_STOP_TXQS,
1858 static void qed_iov_vf_mbx_update_rxqs(struct qed_hwfn *p_hwfn,
1859 struct qed_ptt *p_ptt,
1860 struct qed_vf_info *vf)
1862 u16 length = sizeof(struct pfvf_def_resp_tlv);
1863 struct qed_iov_vf_mbx *mbx = &vf->vf_mbx;
1864 struct vfpf_update_rxq_tlv *req;
1865 u8 status = PFVF_STATUS_SUCCESS;
1866 u8 complete_event_flg;
1867 u8 complete_cqe_flg;
1872 req = &mbx->req_virt->update_rxq;
1873 complete_cqe_flg = !!(req->flags & VFPF_RXQ_UPD_COMPLETE_CQE_FLAG);
1874 complete_event_flg = !!(req->flags & VFPF_RXQ_UPD_COMPLETE_EVENT_FLAG);
1876 for (i = 0; i < req->num_rxqs; i++) {
1877 qid = req->rx_qid + i;
1879 if (!vf->vf_queues[qid].rxq_active) {
1880 DP_NOTICE(p_hwfn, "VF rx_qid = %d isn`t active!\n",
1882 status = PFVF_STATUS_FAILURE;
1886 rc = qed_sp_eth_rx_queues_update(p_hwfn,
1887 vf->vf_queues[qid].fw_rx_qid,
1891 QED_SPQ_MODE_EBLOCK, NULL);
1894 status = PFVF_STATUS_FAILURE;
1899 qed_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_UPDATE_RXQ,
1903 void *qed_iov_search_list_tlvs(struct qed_hwfn *p_hwfn,
1904 void *p_tlvs_list, u16 req_type)
1906 struct channel_tlv *p_tlv = (struct channel_tlv *)p_tlvs_list;
1910 if (!p_tlv->length) {
1911 DP_NOTICE(p_hwfn, "Zero length TLV found\n");
1915 if (p_tlv->type == req_type) {
1916 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
1917 "Extended tlv type %d, length %d found\n",
1918 p_tlv->type, p_tlv->length);
1922 len += p_tlv->length;
1923 p_tlv = (struct channel_tlv *)((u8 *)p_tlv + p_tlv->length);
1925 if ((len + p_tlv->length) > TLV_BUFFER_SIZE) {
1926 DP_NOTICE(p_hwfn, "TLVs has overrun the buffer size\n");
1929 } while (p_tlv->type != CHANNEL_TLV_LIST_END);
1935 qed_iov_vp_update_act_param(struct qed_hwfn *p_hwfn,
1936 struct qed_sp_vport_update_params *p_data,
1937 struct qed_iov_vf_mbx *p_mbx, u16 *tlvs_mask)
1939 struct vfpf_vport_update_activate_tlv *p_act_tlv;
1940 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_ACTIVATE;
1942 p_act_tlv = (struct vfpf_vport_update_activate_tlv *)
1943 qed_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
1947 p_data->update_vport_active_rx_flg = p_act_tlv->update_rx;
1948 p_data->vport_active_rx_flg = p_act_tlv->active_rx;
1949 p_data->update_vport_active_tx_flg = p_act_tlv->update_tx;
1950 p_data->vport_active_tx_flg = p_act_tlv->active_tx;
1951 *tlvs_mask |= 1 << QED_IOV_VP_UPDATE_ACTIVATE;
1955 qed_iov_vp_update_vlan_param(struct qed_hwfn *p_hwfn,
1956 struct qed_sp_vport_update_params *p_data,
1957 struct qed_vf_info *p_vf,
1958 struct qed_iov_vf_mbx *p_mbx, u16 *tlvs_mask)
1960 struct vfpf_vport_update_vlan_strip_tlv *p_vlan_tlv;
1961 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_VLAN_STRIP;
1963 p_vlan_tlv = (struct vfpf_vport_update_vlan_strip_tlv *)
1964 qed_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
1968 p_vf->shadow_config.inner_vlan_removal = p_vlan_tlv->remove_vlan;
1970 /* Ignore the VF request if we're forcing a vlan */
1971 if (!(p_vf->configured_features & (1 << VLAN_ADDR_FORCED))) {
1972 p_data->update_inner_vlan_removal_flg = 1;
1973 p_data->inner_vlan_removal_flg = p_vlan_tlv->remove_vlan;
1976 *tlvs_mask |= 1 << QED_IOV_VP_UPDATE_VLAN_STRIP;
1980 qed_iov_vp_update_tx_switch(struct qed_hwfn *p_hwfn,
1981 struct qed_sp_vport_update_params *p_data,
1982 struct qed_iov_vf_mbx *p_mbx, u16 *tlvs_mask)
1984 struct vfpf_vport_update_tx_switch_tlv *p_tx_switch_tlv;
1985 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_TX_SWITCH;
1987 p_tx_switch_tlv = (struct vfpf_vport_update_tx_switch_tlv *)
1988 qed_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt,
1990 if (!p_tx_switch_tlv)
1993 p_data->update_tx_switching_flg = 1;
1994 p_data->tx_switching_flg = p_tx_switch_tlv->tx_switching;
1995 *tlvs_mask |= 1 << QED_IOV_VP_UPDATE_TX_SWITCH;
1999 qed_iov_vp_update_mcast_bin_param(struct qed_hwfn *p_hwfn,
2000 struct qed_sp_vport_update_params *p_data,
2001 struct qed_iov_vf_mbx *p_mbx, u16 *tlvs_mask)
2003 struct vfpf_vport_update_mcast_bin_tlv *p_mcast_tlv;
2004 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_MCAST;
2006 p_mcast_tlv = (struct vfpf_vport_update_mcast_bin_tlv *)
2007 qed_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
2011 p_data->update_approx_mcast_flg = 1;
2012 memcpy(p_data->bins, p_mcast_tlv->bins,
2013 sizeof(unsigned long) * ETH_MULTICAST_MAC_BINS_IN_REGS);
2014 *tlvs_mask |= 1 << QED_IOV_VP_UPDATE_MCAST;
2018 qed_iov_vp_update_accept_flag(struct qed_hwfn *p_hwfn,
2019 struct qed_sp_vport_update_params *p_data,
2020 struct qed_iov_vf_mbx *p_mbx, u16 *tlvs_mask)
2022 struct qed_filter_accept_flags *p_flags = &p_data->accept_flags;
2023 struct vfpf_vport_update_accept_param_tlv *p_accept_tlv;
2024 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_ACCEPT_PARAM;
2026 p_accept_tlv = (struct vfpf_vport_update_accept_param_tlv *)
2027 qed_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
2031 p_flags->update_rx_mode_config = p_accept_tlv->update_rx_mode;
2032 p_flags->rx_accept_filter = p_accept_tlv->rx_accept_filter;
2033 p_flags->update_tx_mode_config = p_accept_tlv->update_tx_mode;
2034 p_flags->tx_accept_filter = p_accept_tlv->tx_accept_filter;
2035 *tlvs_mask |= 1 << QED_IOV_VP_UPDATE_ACCEPT_PARAM;
2039 qed_iov_vp_update_accept_any_vlan(struct qed_hwfn *p_hwfn,
2040 struct qed_sp_vport_update_params *p_data,
2041 struct qed_iov_vf_mbx *p_mbx, u16 *tlvs_mask)
2043 struct vfpf_vport_update_accept_any_vlan_tlv *p_accept_any_vlan;
2044 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_ACCEPT_ANY_VLAN;
2046 p_accept_any_vlan = (struct vfpf_vport_update_accept_any_vlan_tlv *)
2047 qed_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt,
2049 if (!p_accept_any_vlan)
2052 p_data->accept_any_vlan = p_accept_any_vlan->accept_any_vlan;
2053 p_data->update_accept_any_vlan_flg =
2054 p_accept_any_vlan->update_accept_any_vlan_flg;
2055 *tlvs_mask |= 1 << QED_IOV_VP_UPDATE_ACCEPT_ANY_VLAN;
2059 qed_iov_vp_update_rss_param(struct qed_hwfn *p_hwfn,
2060 struct qed_vf_info *vf,
2061 struct qed_sp_vport_update_params *p_data,
2062 struct qed_rss_params *p_rss,
2063 struct qed_iov_vf_mbx *p_mbx, u16 *tlvs_mask)
2065 struct vfpf_vport_update_rss_tlv *p_rss_tlv;
2066 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_RSS;
2067 u16 i, q_idx, max_q_idx;
2070 p_rss_tlv = (struct vfpf_vport_update_rss_tlv *)
2071 qed_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
2073 p_data->rss_params = NULL;
2077 memset(p_rss, 0, sizeof(struct qed_rss_params));
2079 p_rss->update_rss_config = !!(p_rss_tlv->update_rss_flags &
2080 VFPF_UPDATE_RSS_CONFIG_FLAG);
2081 p_rss->update_rss_capabilities = !!(p_rss_tlv->update_rss_flags &
2082 VFPF_UPDATE_RSS_CAPS_FLAG);
2083 p_rss->update_rss_ind_table = !!(p_rss_tlv->update_rss_flags &
2084 VFPF_UPDATE_RSS_IND_TABLE_FLAG);
2085 p_rss->update_rss_key = !!(p_rss_tlv->update_rss_flags &
2086 VFPF_UPDATE_RSS_KEY_FLAG);
2088 p_rss->rss_enable = p_rss_tlv->rss_enable;
2089 p_rss->rss_eng_id = vf->relative_vf_id + 1;
2090 p_rss->rss_caps = p_rss_tlv->rss_caps;
2091 p_rss->rss_table_size_log = p_rss_tlv->rss_table_size_log;
2092 memcpy(p_rss->rss_ind_table, p_rss_tlv->rss_ind_table,
2093 sizeof(p_rss->rss_ind_table));
2094 memcpy(p_rss->rss_key, p_rss_tlv->rss_key, sizeof(p_rss->rss_key));
2096 table_size = min_t(u16, ARRAY_SIZE(p_rss->rss_ind_table),
2097 (1 << p_rss_tlv->rss_table_size_log));
2099 max_q_idx = ARRAY_SIZE(vf->vf_queues);
2101 for (i = 0; i < table_size; i++) {
2102 u16 index = vf->vf_queues[0].fw_rx_qid;
2104 q_idx = p_rss->rss_ind_table[i];
2105 if (q_idx >= max_q_idx)
2107 "rss_ind_table[%d] = %d, rxq is out of range\n",
2109 else if (!vf->vf_queues[q_idx].rxq_active)
2111 "rss_ind_table[%d] = %d, rxq is not active\n",
2114 index = vf->vf_queues[q_idx].fw_rx_qid;
2115 p_rss->rss_ind_table[i] = index;
2118 p_data->rss_params = p_rss;
2119 *tlvs_mask |= 1 << QED_IOV_VP_UPDATE_RSS;
2123 qed_iov_vp_update_sge_tpa_param(struct qed_hwfn *p_hwfn,
2124 struct qed_vf_info *vf,
2125 struct qed_sp_vport_update_params *p_data,
2126 struct qed_sge_tpa_params *p_sge_tpa,
2127 struct qed_iov_vf_mbx *p_mbx, u16 *tlvs_mask)
2129 struct vfpf_vport_update_sge_tpa_tlv *p_sge_tpa_tlv;
2130 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_SGE_TPA;
2132 p_sge_tpa_tlv = (struct vfpf_vport_update_sge_tpa_tlv *)
2133 qed_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
2135 if (!p_sge_tpa_tlv) {
2136 p_data->sge_tpa_params = NULL;
2140 memset(p_sge_tpa, 0, sizeof(struct qed_sge_tpa_params));
2142 p_sge_tpa->update_tpa_en_flg =
2143 !!(p_sge_tpa_tlv->update_sge_tpa_flags & VFPF_UPDATE_TPA_EN_FLAG);
2144 p_sge_tpa->update_tpa_param_flg =
2145 !!(p_sge_tpa_tlv->update_sge_tpa_flags &
2146 VFPF_UPDATE_TPA_PARAM_FLAG);
2148 p_sge_tpa->tpa_ipv4_en_flg =
2149 !!(p_sge_tpa_tlv->sge_tpa_flags & VFPF_TPA_IPV4_EN_FLAG);
2150 p_sge_tpa->tpa_ipv6_en_flg =
2151 !!(p_sge_tpa_tlv->sge_tpa_flags & VFPF_TPA_IPV6_EN_FLAG);
2152 p_sge_tpa->tpa_pkt_split_flg =
2153 !!(p_sge_tpa_tlv->sge_tpa_flags & VFPF_TPA_PKT_SPLIT_FLAG);
2154 p_sge_tpa->tpa_hdr_data_split_flg =
2155 !!(p_sge_tpa_tlv->sge_tpa_flags & VFPF_TPA_HDR_DATA_SPLIT_FLAG);
2156 p_sge_tpa->tpa_gro_consistent_flg =
2157 !!(p_sge_tpa_tlv->sge_tpa_flags & VFPF_TPA_GRO_CONSIST_FLAG);
2159 p_sge_tpa->tpa_max_aggs_num = p_sge_tpa_tlv->tpa_max_aggs_num;
2160 p_sge_tpa->tpa_max_size = p_sge_tpa_tlv->tpa_max_size;
2161 p_sge_tpa->tpa_min_size_to_start = p_sge_tpa_tlv->tpa_min_size_to_start;
2162 p_sge_tpa->tpa_min_size_to_cont = p_sge_tpa_tlv->tpa_min_size_to_cont;
2163 p_sge_tpa->max_buffers_per_cqe = p_sge_tpa_tlv->max_buffers_per_cqe;
2165 p_data->sge_tpa_params = p_sge_tpa;
2167 *tlvs_mask |= 1 << QED_IOV_VP_UPDATE_SGE_TPA;
2170 static void qed_iov_vf_mbx_vport_update(struct qed_hwfn *p_hwfn,
2171 struct qed_ptt *p_ptt,
2172 struct qed_vf_info *vf)
2174 struct qed_sp_vport_update_params params;
2175 struct qed_iov_vf_mbx *mbx = &vf->vf_mbx;
2176 struct qed_sge_tpa_params sge_tpa_params;
2177 struct qed_rss_params rss_params;
2178 u8 status = PFVF_STATUS_SUCCESS;
2183 memset(¶ms, 0, sizeof(params));
2184 params.opaque_fid = vf->opaque_fid;
2185 params.vport_id = vf->vport_id;
2186 params.rss_params = NULL;
2188 /* Search for extended tlvs list and update values
2189 * from VF in struct qed_sp_vport_update_params.
2191 qed_iov_vp_update_act_param(p_hwfn, ¶ms, mbx, &tlvs_mask);
2192 qed_iov_vp_update_vlan_param(p_hwfn, ¶ms, vf, mbx, &tlvs_mask);
2193 qed_iov_vp_update_tx_switch(p_hwfn, ¶ms, mbx, &tlvs_mask);
2194 qed_iov_vp_update_mcast_bin_param(p_hwfn, ¶ms, mbx, &tlvs_mask);
2195 qed_iov_vp_update_accept_flag(p_hwfn, ¶ms, mbx, &tlvs_mask);
2196 qed_iov_vp_update_rss_param(p_hwfn, vf, ¶ms, &rss_params,
2198 qed_iov_vp_update_accept_any_vlan(p_hwfn, ¶ms, mbx, &tlvs_mask);
2199 qed_iov_vp_update_sge_tpa_param(p_hwfn, vf, ¶ms,
2200 &sge_tpa_params, mbx, &tlvs_mask);
2202 /* Just log a message if there is no single extended tlv in buffer.
2203 * When all features of vport update ramrod would be requested by VF
2204 * as extended TLVs in buffer then an error can be returned in response
2205 * if there is no extended TLV present in buffer.
2209 "No feature tlvs found for vport update\n");
2210 status = PFVF_STATUS_NOT_SUPPORTED;
2214 rc = qed_sp_vport_update(p_hwfn, ¶ms, QED_SPQ_MODE_EBLOCK, NULL);
2217 status = PFVF_STATUS_FAILURE;
2220 length = qed_iov_prep_vp_update_resp_tlvs(p_hwfn, vf, mbx, status,
2221 tlvs_mask, tlvs_mask);
2222 qed_iov_send_response(p_hwfn, p_ptt, vf, length, status);
2225 static int qed_iov_vf_update_unicast_shadow(struct qed_hwfn *p_hwfn,
2226 struct qed_vf_info *p_vf,
2227 struct qed_filter_ucast *p_params)
2231 if (p_params->type == QED_FILTER_MAC)
2234 /* First remove entries and then add new ones */
2235 if (p_params->opcode == QED_FILTER_REMOVE) {
2236 for (i = 0; i < QED_ETH_VF_NUM_VLAN_FILTERS + 1; i++)
2237 if (p_vf->shadow_config.vlans[i].used &&
2238 p_vf->shadow_config.vlans[i].vid ==
2240 p_vf->shadow_config.vlans[i].used = false;
2243 if (i == QED_ETH_VF_NUM_VLAN_FILTERS + 1) {
2246 "VF [%d] - Tries to remove a non-existing vlan\n",
2247 p_vf->relative_vf_id);
2250 } else if (p_params->opcode == QED_FILTER_REPLACE ||
2251 p_params->opcode == QED_FILTER_FLUSH) {
2252 for (i = 0; i < QED_ETH_VF_NUM_VLAN_FILTERS + 1; i++)
2253 p_vf->shadow_config.vlans[i].used = false;
2256 /* In forced mode, we're willing to remove entries - but we don't add
2259 if (p_vf->bulletin.p_virt->valid_bitmap & (1 << VLAN_ADDR_FORCED))
2262 if (p_params->opcode == QED_FILTER_ADD ||
2263 p_params->opcode == QED_FILTER_REPLACE) {
2264 for (i = 0; i < QED_ETH_VF_NUM_VLAN_FILTERS + 1; i++) {
2265 if (p_vf->shadow_config.vlans[i].used)
2268 p_vf->shadow_config.vlans[i].used = true;
2269 p_vf->shadow_config.vlans[i].vid = p_params->vlan;
2273 if (i == QED_ETH_VF_NUM_VLAN_FILTERS + 1) {
2276 "VF [%d] - Tries to configure more than %d vlan filters\n",
2277 p_vf->relative_vf_id,
2278 QED_ETH_VF_NUM_VLAN_FILTERS + 1);
2286 int qed_iov_chk_ucast(struct qed_hwfn *hwfn,
2287 int vfid, struct qed_filter_ucast *params)
2289 struct qed_public_vf_info *vf;
2291 vf = qed_iov_get_public_vf_info(hwfn, vfid, true);
2295 /* No real decision to make; Store the configured MAC */
2296 if (params->type == QED_FILTER_MAC ||
2297 params->type == QED_FILTER_MAC_VLAN)
2298 ether_addr_copy(vf->mac, params->mac);
2303 static void qed_iov_vf_mbx_ucast_filter(struct qed_hwfn *p_hwfn,
2304 struct qed_ptt *p_ptt,
2305 struct qed_vf_info *vf)
2307 struct qed_bulletin_content *p_bulletin = vf->bulletin.p_virt;
2308 struct qed_iov_vf_mbx *mbx = &vf->vf_mbx;
2309 struct vfpf_ucast_filter_tlv *req;
2310 u8 status = PFVF_STATUS_SUCCESS;
2311 struct qed_filter_ucast params;
2314 /* Prepare the unicast filter params */
2315 memset(¶ms, 0, sizeof(struct qed_filter_ucast));
2316 req = &mbx->req_virt->ucast_filter;
2317 params.opcode = (enum qed_filter_opcode)req->opcode;
2318 params.type = (enum qed_filter_ucast_type)req->type;
2320 params.is_rx_filter = 1;
2321 params.is_tx_filter = 1;
2322 params.vport_to_remove_from = vf->vport_id;
2323 params.vport_to_add_to = vf->vport_id;
2324 memcpy(params.mac, req->mac, ETH_ALEN);
2325 params.vlan = req->vlan;
2329 "VF[%d]: opcode 0x%02x type 0x%02x [%s %s] [vport 0x%02x] MAC %02x:%02x:%02x:%02x:%02x:%02x, vlan 0x%04x\n",
2330 vf->abs_vf_id, params.opcode, params.type,
2331 params.is_rx_filter ? "RX" : "",
2332 params.is_tx_filter ? "TX" : "",
2333 params.vport_to_add_to,
2334 params.mac[0], params.mac[1],
2335 params.mac[2], params.mac[3],
2336 params.mac[4], params.mac[5], params.vlan);
2338 if (!vf->vport_instance) {
2341 "No VPORT instance available for VF[%d], failing ucast MAC configuration\n",
2343 status = PFVF_STATUS_FAILURE;
2347 /* Update shadow copy of the VF configuration */
2348 if (qed_iov_vf_update_unicast_shadow(p_hwfn, vf, ¶ms)) {
2349 status = PFVF_STATUS_FAILURE;
2353 /* Determine if the unicast filtering is acceptible by PF */
2354 if ((p_bulletin->valid_bitmap & (1 << VLAN_ADDR_FORCED)) &&
2355 (params.type == QED_FILTER_VLAN ||
2356 params.type == QED_FILTER_MAC_VLAN)) {
2357 /* Once VLAN is forced or PVID is set, do not allow
2358 * to add/replace any further VLANs.
2360 if (params.opcode == QED_FILTER_ADD ||
2361 params.opcode == QED_FILTER_REPLACE)
2362 status = PFVF_STATUS_FORCED;
2366 if ((p_bulletin->valid_bitmap & (1 << MAC_ADDR_FORCED)) &&
2367 (params.type == QED_FILTER_MAC ||
2368 params.type == QED_FILTER_MAC_VLAN)) {
2369 if (!ether_addr_equal(p_bulletin->mac, params.mac) ||
2370 (params.opcode != QED_FILTER_ADD &&
2371 params.opcode != QED_FILTER_REPLACE))
2372 status = PFVF_STATUS_FORCED;
2376 rc = qed_iov_chk_ucast(p_hwfn, vf->relative_vf_id, ¶ms);
2378 status = PFVF_STATUS_FAILURE;
2382 rc = qed_sp_eth_filter_ucast(p_hwfn, vf->opaque_fid, ¶ms,
2383 QED_SPQ_MODE_CB, NULL);
2385 status = PFVF_STATUS_FAILURE;
2388 qed_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_UCAST_FILTER,
2389 sizeof(struct pfvf_def_resp_tlv), status);
2392 static void qed_iov_vf_mbx_int_cleanup(struct qed_hwfn *p_hwfn,
2393 struct qed_ptt *p_ptt,
2394 struct qed_vf_info *vf)
2399 for (i = 0; i < vf->num_sbs; i++)
2400 qed_int_igu_init_pure_rt_single(p_hwfn, p_ptt,
2402 vf->opaque_fid, false);
2404 qed_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_INT_CLEANUP,
2405 sizeof(struct pfvf_def_resp_tlv),
2406 PFVF_STATUS_SUCCESS);
2409 static void qed_iov_vf_mbx_close(struct qed_hwfn *p_hwfn,
2410 struct qed_ptt *p_ptt, struct qed_vf_info *vf)
2412 u16 length = sizeof(struct pfvf_def_resp_tlv);
2413 u8 status = PFVF_STATUS_SUCCESS;
2415 /* Disable Interrupts for VF */
2416 qed_iov_vf_igu_set_int(p_hwfn, p_ptt, vf, 0);
2418 /* Reset Permission table */
2419 qed_iov_config_perm_table(p_hwfn, p_ptt, vf, 0);
2421 qed_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_CLOSE,
2425 static void qed_iov_vf_mbx_release(struct qed_hwfn *p_hwfn,
2426 struct qed_ptt *p_ptt,
2427 struct qed_vf_info *p_vf)
2429 u16 length = sizeof(struct pfvf_def_resp_tlv);
2430 u8 status = PFVF_STATUS_SUCCESS;
2433 qed_iov_vf_cleanup(p_hwfn, p_vf);
2435 if (p_vf->state != VF_STOPPED && p_vf->state != VF_FREE) {
2436 /* Stopping the VF */
2437 rc = qed_sp_vf_stop(p_hwfn, p_vf->concrete_fid,
2441 DP_ERR(p_hwfn, "qed_sp_vf_stop returned error %d\n",
2443 status = PFVF_STATUS_FAILURE;
2446 p_vf->state = VF_STOPPED;
2449 qed_iov_prepare_resp(p_hwfn, p_ptt, p_vf, CHANNEL_TLV_RELEASE,
2454 qed_iov_vf_flr_poll_dorq(struct qed_hwfn *p_hwfn,
2455 struct qed_vf_info *p_vf, struct qed_ptt *p_ptt)
2460 qed_fid_pretend(p_hwfn, p_ptt, (u16) p_vf->concrete_fid);
2462 for (cnt = 0; cnt < 50; cnt++) {
2463 val = qed_rd(p_hwfn, p_ptt, DORQ_REG_VF_USAGE_CNT);
2468 qed_fid_pretend(p_hwfn, p_ptt, (u16) p_hwfn->hw_info.concrete_fid);
2472 "VF[%d] - dorq failed to cleanup [usage 0x%08x]\n",
2473 p_vf->abs_vf_id, val);
2481 qed_iov_vf_flr_poll_pbf(struct qed_hwfn *p_hwfn,
2482 struct qed_vf_info *p_vf, struct qed_ptt *p_ptt)
2484 u32 cons[MAX_NUM_VOQS], distance[MAX_NUM_VOQS];
2487 /* Read initial consumers & producers */
2488 for (i = 0; i < MAX_NUM_VOQS; i++) {
2491 cons[i] = qed_rd(p_hwfn, p_ptt,
2492 PBF_REG_NUM_BLOCKS_ALLOCATED_CONS_VOQ0 +
2494 prod = qed_rd(p_hwfn, p_ptt,
2495 PBF_REG_NUM_BLOCKS_ALLOCATED_PROD_VOQ0 +
2497 distance[i] = prod - cons[i];
2500 /* Wait for consumers to pass the producers */
2502 for (cnt = 0; cnt < 50; cnt++) {
2503 for (; i < MAX_NUM_VOQS; i++) {
2506 tmp = qed_rd(p_hwfn, p_ptt,
2507 PBF_REG_NUM_BLOCKS_ALLOCATED_CONS_VOQ0 +
2509 if (distance[i] > tmp - cons[i])
2513 if (i == MAX_NUM_VOQS)
2520 DP_ERR(p_hwfn, "VF[%d] - pbf polling failed on VOQ %d\n",
2521 p_vf->abs_vf_id, i);
2528 static int qed_iov_vf_flr_poll(struct qed_hwfn *p_hwfn,
2529 struct qed_vf_info *p_vf, struct qed_ptt *p_ptt)
2533 rc = qed_iov_vf_flr_poll_dorq(p_hwfn, p_vf, p_ptt);
2537 rc = qed_iov_vf_flr_poll_pbf(p_hwfn, p_vf, p_ptt);
2545 qed_iov_execute_vf_flr_cleanup(struct qed_hwfn *p_hwfn,
2546 struct qed_ptt *p_ptt,
2547 u16 rel_vf_id, u32 *ack_vfs)
2549 struct qed_vf_info *p_vf;
2552 p_vf = qed_iov_get_vf_info(p_hwfn, rel_vf_id, false);
2556 if (p_hwfn->pf_iov_info->pending_flr[rel_vf_id / 64] &
2557 (1ULL << (rel_vf_id % 64))) {
2558 u16 vfid = p_vf->abs_vf_id;
2560 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
2561 "VF[%d] - Handling FLR\n", vfid);
2563 qed_iov_vf_cleanup(p_hwfn, p_vf);
2565 /* If VF isn't active, no need for anything but SW */
2569 rc = qed_iov_vf_flr_poll(p_hwfn, p_vf, p_ptt);
2573 rc = qed_final_cleanup(p_hwfn, p_ptt, vfid, true);
2575 DP_ERR(p_hwfn, "Failed handle FLR of VF[%d]\n", vfid);
2579 /* VF_STOPPED has to be set only after final cleanup
2580 * but prior to re-enabling the VF.
2582 p_vf->state = VF_STOPPED;
2584 rc = qed_iov_enable_vf_access(p_hwfn, p_ptt, p_vf);
2586 DP_ERR(p_hwfn, "Failed to re-enable VF[%d] acces\n",
2591 /* Mark VF for ack and clean pending state */
2592 if (p_vf->state == VF_RESET)
2593 p_vf->state = VF_STOPPED;
2594 ack_vfs[vfid / 32] |= (1 << (vfid % 32));
2595 p_hwfn->pf_iov_info->pending_flr[rel_vf_id / 64] &=
2596 ~(1ULL << (rel_vf_id % 64));
2597 p_hwfn->pf_iov_info->pending_events[rel_vf_id / 64] &=
2598 ~(1ULL << (rel_vf_id % 64));
2604 int qed_iov_vf_flr_cleanup(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
2606 u32 ack_vfs[VF_MAX_STATIC / 32];
2610 memset(ack_vfs, 0, sizeof(u32) * (VF_MAX_STATIC / 32));
2612 /* Since BRB <-> PRS interface can't be tested as part of the flr
2613 * polling due to HW limitations, simply sleep a bit. And since
2614 * there's no need to wait per-vf, do it before looping.
2618 for (i = 0; i < p_hwfn->cdev->p_iov_info->total_vfs; i++)
2619 qed_iov_execute_vf_flr_cleanup(p_hwfn, p_ptt, i, ack_vfs);
2621 rc = qed_mcp_ack_vf_flr(p_hwfn, p_ptt, ack_vfs);
2625 int qed_iov_mark_vf_flr(struct qed_hwfn *p_hwfn, u32 *p_disabled_vfs)
2629 DP_VERBOSE(p_hwfn, QED_MSG_IOV, "Marking FLR-ed VFs\n");
2630 for (i = 0; i < (VF_MAX_STATIC / 32); i++)
2631 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
2632 "[%08x,...,%08x]: %08x\n",
2633 i * 32, (i + 1) * 32 - 1, p_disabled_vfs[i]);
2635 if (!p_hwfn->cdev->p_iov_info) {
2636 DP_NOTICE(p_hwfn, "VF flr but no IOV\n");
2641 for (i = 0; i < p_hwfn->cdev->p_iov_info->total_vfs; i++) {
2642 struct qed_vf_info *p_vf;
2645 p_vf = qed_iov_get_vf_info(p_hwfn, i, false);
2649 vfid = p_vf->abs_vf_id;
2650 if ((1 << (vfid % 32)) & p_disabled_vfs[vfid / 32]) {
2651 u64 *p_flr = p_hwfn->pf_iov_info->pending_flr;
2652 u16 rel_vf_id = p_vf->relative_vf_id;
2654 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
2655 "VF[%d] [rel %d] got FLR-ed\n",
2658 p_vf->state = VF_RESET;
2660 /* No need to lock here, since pending_flr should
2661 * only change here and before ACKing MFw. Since
2662 * MFW will not trigger an additional attention for
2663 * VF flr until ACKs, we're safe.
2665 p_flr[rel_vf_id / 64] |= 1ULL << (rel_vf_id % 64);
2673 static void qed_iov_get_link(struct qed_hwfn *p_hwfn,
2675 struct qed_mcp_link_params *p_params,
2676 struct qed_mcp_link_state *p_link,
2677 struct qed_mcp_link_capabilities *p_caps)
2679 struct qed_vf_info *p_vf = qed_iov_get_vf_info(p_hwfn,
2682 struct qed_bulletin_content *p_bulletin;
2687 p_bulletin = p_vf->bulletin.p_virt;
2690 __qed_vf_get_link_params(p_hwfn, p_params, p_bulletin);
2692 __qed_vf_get_link_state(p_hwfn, p_link, p_bulletin);
2694 __qed_vf_get_link_caps(p_hwfn, p_caps, p_bulletin);
2697 static void qed_iov_process_mbx_req(struct qed_hwfn *p_hwfn,
2698 struct qed_ptt *p_ptt, int vfid)
2700 struct qed_iov_vf_mbx *mbx;
2701 struct qed_vf_info *p_vf;
2704 p_vf = qed_iov_get_vf_info(p_hwfn, (u16) vfid, true);
2708 mbx = &p_vf->vf_mbx;
2710 /* qed_iov_process_mbx_request */
2713 "qed_iov_process_mbx_req vfid %d\n", p_vf->abs_vf_id);
2715 mbx->first_tlv = mbx->req_virt->first_tlv;
2717 /* check if tlv type is known */
2718 if (qed_iov_tlv_supported(mbx->first_tlv.tl.type)) {
2719 switch (mbx->first_tlv.tl.type) {
2720 case CHANNEL_TLV_ACQUIRE:
2721 qed_iov_vf_mbx_acquire(p_hwfn, p_ptt, p_vf);
2723 case CHANNEL_TLV_VPORT_START:
2724 qed_iov_vf_mbx_start_vport(p_hwfn, p_ptt, p_vf);
2726 case CHANNEL_TLV_VPORT_TEARDOWN:
2727 qed_iov_vf_mbx_stop_vport(p_hwfn, p_ptt, p_vf);
2729 case CHANNEL_TLV_START_RXQ:
2730 qed_iov_vf_mbx_start_rxq(p_hwfn, p_ptt, p_vf);
2732 case CHANNEL_TLV_START_TXQ:
2733 qed_iov_vf_mbx_start_txq(p_hwfn, p_ptt, p_vf);
2735 case CHANNEL_TLV_STOP_RXQS:
2736 qed_iov_vf_mbx_stop_rxqs(p_hwfn, p_ptt, p_vf);
2738 case CHANNEL_TLV_STOP_TXQS:
2739 qed_iov_vf_mbx_stop_txqs(p_hwfn, p_ptt, p_vf);
2741 case CHANNEL_TLV_UPDATE_RXQ:
2742 qed_iov_vf_mbx_update_rxqs(p_hwfn, p_ptt, p_vf);
2744 case CHANNEL_TLV_VPORT_UPDATE:
2745 qed_iov_vf_mbx_vport_update(p_hwfn, p_ptt, p_vf);
2747 case CHANNEL_TLV_UCAST_FILTER:
2748 qed_iov_vf_mbx_ucast_filter(p_hwfn, p_ptt, p_vf);
2750 case CHANNEL_TLV_CLOSE:
2751 qed_iov_vf_mbx_close(p_hwfn, p_ptt, p_vf);
2753 case CHANNEL_TLV_INT_CLEANUP:
2754 qed_iov_vf_mbx_int_cleanup(p_hwfn, p_ptt, p_vf);
2756 case CHANNEL_TLV_RELEASE:
2757 qed_iov_vf_mbx_release(p_hwfn, p_ptt, p_vf);
2761 /* unknown TLV - this may belong to a VF driver from the future
2762 * - a version written after this PF driver was written, which
2763 * supports features unknown as of yet. Too bad since we don't
2764 * support them. Or this may be because someone wrote a crappy
2765 * VF driver and is sending garbage over the channel.
2768 "unknown TLV. type %d length %d. first 20 bytes of mailbox buffer:\n",
2769 mbx->first_tlv.tl.type, mbx->first_tlv.tl.length);
2771 for (i = 0; i < 20; i++) {
2775 mbx->req_virt->tlv_buf_size.tlv_buffer[i]);
2780 void qed_iov_pf_add_pending_events(struct qed_hwfn *p_hwfn, u8 vfid)
2782 u64 add_bit = 1ULL << (vfid % 64);
2784 p_hwfn->pf_iov_info->pending_events[vfid / 64] |= add_bit;
2787 static void qed_iov_pf_get_and_clear_pending_events(struct qed_hwfn *p_hwfn,
2790 u64 *p_pending_events = p_hwfn->pf_iov_info->pending_events;
2792 memcpy(events, p_pending_events, sizeof(u64) * QED_VF_ARRAY_LENGTH);
2793 memset(p_pending_events, 0, sizeof(u64) * QED_VF_ARRAY_LENGTH);
2796 static int qed_sriov_vfpf_msg(struct qed_hwfn *p_hwfn,
2797 u16 abs_vfid, struct regpair *vf_msg)
2799 u8 min = (u8)p_hwfn->cdev->p_iov_info->first_vf_in_pf;
2800 struct qed_vf_info *p_vf;
2802 if (!qed_iov_pf_sanity_check(p_hwfn, (int)abs_vfid - min)) {
2805 "Got a message from VF [abs 0x%08x] that cannot be handled by PF\n",
2809 p_vf = &p_hwfn->pf_iov_info->vfs_array[(u8)abs_vfid - min];
2811 /* List the physical address of the request so that handler
2812 * could later on copy the message from it.
2814 p_vf->vf_mbx.pending_req = (((u64)vf_msg->hi) << 32) | vf_msg->lo;
2816 /* Mark the event and schedule the workqueue */
2817 qed_iov_pf_add_pending_events(p_hwfn, p_vf->relative_vf_id);
2818 qed_schedule_iov(p_hwfn, QED_IOV_WQ_MSG_FLAG);
2823 int qed_sriov_eqe_event(struct qed_hwfn *p_hwfn,
2824 u8 opcode, __le16 echo, union event_ring_data *data)
2827 case COMMON_EVENT_VF_PF_CHANNEL:
2828 return qed_sriov_vfpf_msg(p_hwfn, le16_to_cpu(echo),
2829 &data->vf_pf_channel.msg_addr);
2831 DP_INFO(p_hwfn->cdev, "Unknown sriov eqe event 0x%02x\n",
2837 u16 qed_iov_get_next_active_vf(struct qed_hwfn *p_hwfn, u16 rel_vf_id)
2839 struct qed_hw_sriov_info *p_iov = p_hwfn->cdev->p_iov_info;
2845 for (i = rel_vf_id; i < p_iov->total_vfs; i++)
2846 if (qed_iov_is_valid_vfid(p_hwfn, rel_vf_id, true))
2853 static int qed_iov_copy_vf_msg(struct qed_hwfn *p_hwfn, struct qed_ptt *ptt,
2856 struct qed_dmae_params params;
2857 struct qed_vf_info *vf_info;
2859 vf_info = qed_iov_get_vf_info(p_hwfn, (u16) vfid, true);
2863 memset(¶ms, 0, sizeof(struct qed_dmae_params));
2864 params.flags = QED_DMAE_FLAG_VF_SRC | QED_DMAE_FLAG_COMPLETION_DST;
2865 params.src_vfid = vf_info->abs_vf_id;
2867 if (qed_dmae_host2host(p_hwfn, ptt,
2868 vf_info->vf_mbx.pending_req,
2869 vf_info->vf_mbx.req_phys,
2870 sizeof(union vfpf_tlvs) / 4, ¶ms)) {
2871 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
2872 "Failed to copy message from VF 0x%02x\n", vfid);
2880 static void qed_iov_bulletin_set_forced_mac(struct qed_hwfn *p_hwfn,
2883 struct qed_vf_info *vf_info;
2886 vf_info = qed_iov_get_vf_info(p_hwfn, (u16)vfid, true);
2888 DP_NOTICE(p_hwfn->cdev,
2889 "Can not set forced MAC, invalid vfid [%d]\n", vfid);
2893 feature = 1 << MAC_ADDR_FORCED;
2894 memcpy(vf_info->bulletin.p_virt->mac, mac, ETH_ALEN);
2896 vf_info->bulletin.p_virt->valid_bitmap |= feature;
2897 /* Forced MAC will disable MAC_ADDR */
2898 vf_info->bulletin.p_virt->valid_bitmap &=
2899 ~(1 << VFPF_BULLETIN_MAC_ADDR);
2901 qed_iov_configure_vport_forced(p_hwfn, vf_info, feature);
2904 void qed_iov_bulletin_set_forced_vlan(struct qed_hwfn *p_hwfn,
2907 struct qed_vf_info *vf_info;
2910 vf_info = qed_iov_get_vf_info(p_hwfn, (u16) vfid, true);
2912 DP_NOTICE(p_hwfn->cdev,
2913 "Can not set forced MAC, invalid vfid [%d]\n", vfid);
2917 feature = 1 << VLAN_ADDR_FORCED;
2918 vf_info->bulletin.p_virt->pvid = pvid;
2920 vf_info->bulletin.p_virt->valid_bitmap |= feature;
2922 vf_info->bulletin.p_virt->valid_bitmap &= ~feature;
2924 qed_iov_configure_vport_forced(p_hwfn, vf_info, feature);
2927 static bool qed_iov_vf_has_vport_instance(struct qed_hwfn *p_hwfn, int vfid)
2929 struct qed_vf_info *p_vf_info;
2931 p_vf_info = qed_iov_get_vf_info(p_hwfn, (u16) vfid, true);
2935 return !!p_vf_info->vport_instance;
2938 bool qed_iov_is_vf_stopped(struct qed_hwfn *p_hwfn, int vfid)
2940 struct qed_vf_info *p_vf_info;
2942 p_vf_info = qed_iov_get_vf_info(p_hwfn, (u16) vfid, true);
2946 return p_vf_info->state == VF_STOPPED;
2949 static bool qed_iov_spoofchk_get(struct qed_hwfn *p_hwfn, int vfid)
2951 struct qed_vf_info *vf_info;
2953 vf_info = qed_iov_get_vf_info(p_hwfn, (u16) vfid, true);
2957 return vf_info->spoof_chk;
2960 int qed_iov_spoofchk_set(struct qed_hwfn *p_hwfn, int vfid, bool val)
2962 struct qed_vf_info *vf;
2965 if (!qed_iov_pf_sanity_check(p_hwfn, vfid)) {
2967 "SR-IOV sanity check failed, can't set spoofchk\n");
2971 vf = qed_iov_get_vf_info(p_hwfn, (u16) vfid, true);
2975 if (!qed_iov_vf_has_vport_instance(p_hwfn, vfid)) {
2976 /* After VF VPORT start PF will configure spoof check */
2977 vf->req_spoofchk_val = val;
2982 rc = __qed_iov_spoofchk_set(p_hwfn, vf, val);
2988 static u8 *qed_iov_bulletin_get_forced_mac(struct qed_hwfn *p_hwfn,
2991 struct qed_vf_info *p_vf;
2993 p_vf = qed_iov_get_vf_info(p_hwfn, rel_vf_id, true);
2994 if (!p_vf || !p_vf->bulletin.p_virt)
2997 if (!(p_vf->bulletin.p_virt->valid_bitmap & (1 << MAC_ADDR_FORCED)))
3000 return p_vf->bulletin.p_virt->mac;
3003 u16 qed_iov_bulletin_get_forced_vlan(struct qed_hwfn *p_hwfn, u16 rel_vf_id)
3005 struct qed_vf_info *p_vf;
3007 p_vf = qed_iov_get_vf_info(p_hwfn, rel_vf_id, true);
3008 if (!p_vf || !p_vf->bulletin.p_virt)
3011 if (!(p_vf->bulletin.p_virt->valid_bitmap & (1 << VLAN_ADDR_FORCED)))
3014 return p_vf->bulletin.p_virt->pvid;
3017 static int qed_iov_configure_tx_rate(struct qed_hwfn *p_hwfn,
3018 struct qed_ptt *p_ptt, int vfid, int val)
3020 struct qed_vf_info *vf;
3024 vf = qed_iov_get_vf_info(p_hwfn, (u16)vfid, true);
3028 rc = qed_fw_vport(p_hwfn, vf->vport_id, &abs_vp_id);
3032 return qed_init_vport_rl(p_hwfn, p_ptt, abs_vp_id, (u32)val);
3035 int qed_iov_configure_min_tx_rate(struct qed_dev *cdev, int vfid, u32 rate)
3037 struct qed_vf_info *vf;
3041 for_each_hwfn(cdev, i) {
3042 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
3044 if (!qed_iov_pf_sanity_check(p_hwfn, vfid)) {
3046 "SR-IOV sanity check failed, can't set min rate\n");
3051 vf = qed_iov_get_vf_info(QED_LEADING_HWFN(cdev), (u16)vfid, true);
3052 vport_id = vf->vport_id;
3054 return qed_configure_vport_wfq(cdev, vport_id, rate);
3057 static int qed_iov_get_vf_min_rate(struct qed_hwfn *p_hwfn, int vfid)
3059 struct qed_wfq_data *vf_vp_wfq;
3060 struct qed_vf_info *vf_info;
3062 vf_info = qed_iov_get_vf_info(p_hwfn, (u16) vfid, true);
3066 vf_vp_wfq = &p_hwfn->qm_info.wfq_data[vf_info->vport_id];
3068 if (vf_vp_wfq->configured)
3069 return vf_vp_wfq->min_speed;
3075 * qed_schedule_iov - schedules IOV task for VF and PF
3076 * @hwfn: hardware function pointer
3077 * @flag: IOV flag for VF/PF
3079 void qed_schedule_iov(struct qed_hwfn *hwfn, enum qed_iov_wq_flag flag)
3081 smp_mb__before_atomic();
3082 set_bit(flag, &hwfn->iov_task_flags);
3083 smp_mb__after_atomic();
3084 DP_VERBOSE(hwfn, QED_MSG_IOV, "Scheduling iov task [Flag: %d]\n", flag);
3085 queue_delayed_work(hwfn->iov_wq, &hwfn->iov_task, 0);
3088 void qed_vf_start_iov_wq(struct qed_dev *cdev)
3092 for_each_hwfn(cdev, i)
3093 queue_delayed_work(cdev->hwfns[i].iov_wq,
3094 &cdev->hwfns[i].iov_task, 0);
3097 int qed_sriov_disable(struct qed_dev *cdev, bool pci_enabled)
3101 for_each_hwfn(cdev, i)
3102 if (cdev->hwfns[i].iov_wq)
3103 flush_workqueue(cdev->hwfns[i].iov_wq);
3105 /* Mark VFs for disablement */
3106 qed_iov_set_vfs_to_disable(cdev, true);
3108 if (cdev->p_iov_info && cdev->p_iov_info->num_vfs && pci_enabled)
3109 pci_disable_sriov(cdev->pdev);
3111 for_each_hwfn(cdev, i) {
3112 struct qed_hwfn *hwfn = &cdev->hwfns[i];
3113 struct qed_ptt *ptt = qed_ptt_acquire(hwfn);
3115 /* Failure to acquire the ptt in 100g creates an odd error
3116 * where the first engine has already relased IOV.
3119 DP_ERR(hwfn, "Failed to acquire ptt\n");
3123 /* Clean WFQ db and configure equal weight for all vports */
3124 qed_clean_wfq_db(hwfn, ptt);
3126 qed_for_each_vf(hwfn, j) {
3129 if (!qed_iov_is_valid_vfid(hwfn, j, true))
3132 /* Wait until VF is disabled before releasing */
3133 for (k = 0; k < 100; k++) {
3134 if (!qed_iov_is_vf_stopped(hwfn, j))
3141 qed_iov_release_hw_for_vf(&cdev->hwfns[i],
3145 "Timeout waiting for VF's FLR to end\n");
3148 qed_ptt_release(hwfn, ptt);
3151 qed_iov_set_vfs_to_disable(cdev, false);
3156 static int qed_sriov_enable(struct qed_dev *cdev, int num)
3158 struct qed_sb_cnt_info sb_cnt_info;
3161 if (num >= RESC_NUM(&cdev->hwfns[0], QED_VPORT)) {
3162 DP_NOTICE(cdev, "Can start at most %d VFs\n",
3163 RESC_NUM(&cdev->hwfns[0], QED_VPORT) - 1);
3167 /* Initialize HW for VF access */
3168 for_each_hwfn(cdev, j) {
3169 struct qed_hwfn *hwfn = &cdev->hwfns[j];
3170 struct qed_ptt *ptt = qed_ptt_acquire(hwfn);
3171 int num_sbs = 0, limit = 16;
3174 DP_ERR(hwfn, "Failed to acquire ptt\n");
3179 if (IS_MF_DEFAULT(hwfn))
3180 limit = MAX_NUM_VFS_BB / hwfn->num_funcs_on_engine;
3182 memset(&sb_cnt_info, 0, sizeof(sb_cnt_info));
3183 qed_int_get_num_sbs(hwfn, &sb_cnt_info);
3184 num_sbs = min_t(int, sb_cnt_info.sb_free_blk, limit);
3186 for (i = 0; i < num; i++) {
3187 if (!qed_iov_is_valid_vfid(hwfn, i, false))
3190 rc = qed_iov_init_hw_for_vf(hwfn,
3191 ptt, i, num_sbs / num);
3193 DP_ERR(cdev, "Failed to enable VF[%d]\n", i);
3194 qed_ptt_release(hwfn, ptt);
3199 qed_ptt_release(hwfn, ptt);
3202 /* Enable SRIOV PCIe functions */
3203 rc = pci_enable_sriov(cdev->pdev, num);
3205 DP_ERR(cdev, "Failed to enable sriov [%d]\n", rc);
3212 qed_sriov_disable(cdev, false);
3216 static int qed_sriov_configure(struct qed_dev *cdev, int num_vfs_param)
3218 if (!IS_QED_SRIOV(cdev)) {
3219 DP_VERBOSE(cdev, QED_MSG_IOV, "SR-IOV is not supported\n");
3224 return qed_sriov_enable(cdev, num_vfs_param);
3226 return qed_sriov_disable(cdev, true);
3229 static int qed_sriov_pf_set_mac(struct qed_dev *cdev, u8 *mac, int vfid)
3233 if (!IS_QED_SRIOV(cdev) || !IS_PF_SRIOV_ALLOC(&cdev->hwfns[0])) {
3234 DP_VERBOSE(cdev, QED_MSG_IOV,
3235 "Cannot set a VF MAC; Sriov is not enabled\n");
3239 if (!qed_iov_is_valid_vfid(&cdev->hwfns[0], vfid, true)) {
3240 DP_VERBOSE(cdev, QED_MSG_IOV,
3241 "Cannot set VF[%d] MAC (VF is not active)\n", vfid);
3245 for_each_hwfn(cdev, i) {
3246 struct qed_hwfn *hwfn = &cdev->hwfns[i];
3247 struct qed_public_vf_info *vf_info;
3249 vf_info = qed_iov_get_public_vf_info(hwfn, vfid, true);
3253 /* Set the forced MAC, and schedule the IOV task */
3254 ether_addr_copy(vf_info->forced_mac, mac);
3255 qed_schedule_iov(hwfn, QED_IOV_WQ_SET_UNICAST_FILTER_FLAG);
3261 static int qed_sriov_pf_set_vlan(struct qed_dev *cdev, u16 vid, int vfid)
3265 if (!IS_QED_SRIOV(cdev) || !IS_PF_SRIOV_ALLOC(&cdev->hwfns[0])) {
3266 DP_VERBOSE(cdev, QED_MSG_IOV,
3267 "Cannot set a VF MAC; Sriov is not enabled\n");
3271 if (!qed_iov_is_valid_vfid(&cdev->hwfns[0], vfid, true)) {
3272 DP_VERBOSE(cdev, QED_MSG_IOV,
3273 "Cannot set VF[%d] MAC (VF is not active)\n", vfid);
3277 for_each_hwfn(cdev, i) {
3278 struct qed_hwfn *hwfn = &cdev->hwfns[i];
3279 struct qed_public_vf_info *vf_info;
3281 vf_info = qed_iov_get_public_vf_info(hwfn, vfid, true);
3285 /* Set the forced vlan, and schedule the IOV task */
3286 vf_info->forced_vlan = vid;
3287 qed_schedule_iov(hwfn, QED_IOV_WQ_SET_UNICAST_FILTER_FLAG);
3293 static int qed_get_vf_config(struct qed_dev *cdev,
3294 int vf_id, struct ifla_vf_info *ivi)
3296 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
3297 struct qed_public_vf_info *vf_info;
3298 struct qed_mcp_link_state link;
3301 /* Sanitize request */
3305 if (!qed_iov_is_valid_vfid(&cdev->hwfns[0], vf_id, true)) {
3306 DP_VERBOSE(cdev, QED_MSG_IOV,
3307 "VF index [%d] isn't active\n", vf_id);
3311 vf_info = qed_iov_get_public_vf_info(hwfn, vf_id, true);
3313 qed_iov_get_link(hwfn, vf_id, NULL, &link, NULL);
3315 /* Fill information about VF */
3318 if (is_valid_ether_addr(vf_info->forced_mac))
3319 ether_addr_copy(ivi->mac, vf_info->forced_mac);
3321 ether_addr_copy(ivi->mac, vf_info->mac);
3323 ivi->vlan = vf_info->forced_vlan;
3324 ivi->spoofchk = qed_iov_spoofchk_get(hwfn, vf_id);
3325 ivi->linkstate = vf_info->link_state;
3326 tx_rate = vf_info->tx_rate;
3327 ivi->max_tx_rate = tx_rate ? tx_rate : link.speed;
3328 ivi->min_tx_rate = qed_iov_get_vf_min_rate(hwfn, vf_id);
3333 void qed_inform_vf_link_state(struct qed_hwfn *hwfn)
3335 struct qed_mcp_link_capabilities caps;
3336 struct qed_mcp_link_params params;
3337 struct qed_mcp_link_state link;
3340 if (!hwfn->pf_iov_info)
3343 /* Update bulletin of all future possible VFs with link configuration */
3344 for (i = 0; i < hwfn->cdev->p_iov_info->total_vfs; i++) {
3345 struct qed_public_vf_info *vf_info;
3347 vf_info = qed_iov_get_public_vf_info(hwfn, i, false);
3351 memcpy(¶ms, qed_mcp_get_link_params(hwfn), sizeof(params));
3352 memcpy(&link, qed_mcp_get_link_state(hwfn), sizeof(link));
3353 memcpy(&caps, qed_mcp_get_link_capabilities(hwfn),
3356 /* Modify link according to the VF's configured link state */
3357 switch (vf_info->link_state) {
3358 case IFLA_VF_LINK_STATE_DISABLE:
3359 link.link_up = false;
3361 case IFLA_VF_LINK_STATE_ENABLE:
3362 link.link_up = true;
3363 /* Set speed according to maximum supported by HW.
3364 * that is 40G for regular devices and 100G for CMT
3367 link.speed = (hwfn->cdev->num_hwfns > 1) ?
3370 /* In auto mode pass PF link image to VF */
3374 if (link.link_up && vf_info->tx_rate) {
3375 struct qed_ptt *ptt;
3378 rate = min_t(int, vf_info->tx_rate, link.speed);
3380 ptt = qed_ptt_acquire(hwfn);
3382 DP_NOTICE(hwfn, "Failed to acquire PTT\n");
3386 if (!qed_iov_configure_tx_rate(hwfn, ptt, i, rate)) {
3387 vf_info->tx_rate = rate;
3391 qed_ptt_release(hwfn, ptt);
3394 qed_iov_set_link(hwfn, i, ¶ms, &link, &caps);
3397 qed_schedule_iov(hwfn, QED_IOV_WQ_BULLETIN_UPDATE_FLAG);
3400 static int qed_set_vf_link_state(struct qed_dev *cdev,
3401 int vf_id, int link_state)
3405 /* Sanitize request */
3409 if (!qed_iov_is_valid_vfid(&cdev->hwfns[0], vf_id, true)) {
3410 DP_VERBOSE(cdev, QED_MSG_IOV,
3411 "VF index [%d] isn't active\n", vf_id);
3415 /* Handle configuration of link state */
3416 for_each_hwfn(cdev, i) {
3417 struct qed_hwfn *hwfn = &cdev->hwfns[i];
3418 struct qed_public_vf_info *vf;
3420 vf = qed_iov_get_public_vf_info(hwfn, vf_id, true);
3424 if (vf->link_state == link_state)
3427 vf->link_state = link_state;
3428 qed_inform_vf_link_state(&cdev->hwfns[i]);
3434 static int qed_spoof_configure(struct qed_dev *cdev, int vfid, bool val)
3436 int i, rc = -EINVAL;
3438 for_each_hwfn(cdev, i) {
3439 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
3441 rc = qed_iov_spoofchk_set(p_hwfn, vfid, val);
3449 static int qed_configure_max_vf_rate(struct qed_dev *cdev, int vfid, int rate)
3453 for_each_hwfn(cdev, i) {
3454 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
3455 struct qed_public_vf_info *vf;
3457 if (!qed_iov_pf_sanity_check(p_hwfn, vfid)) {
3459 "SR-IOV sanity check failed, can't set tx rate\n");
3463 vf = qed_iov_get_public_vf_info(p_hwfn, vfid, true);
3467 qed_inform_vf_link_state(p_hwfn);
3473 static int qed_set_vf_rate(struct qed_dev *cdev,
3474 int vfid, u32 min_rate, u32 max_rate)
3476 int rc_min = 0, rc_max = 0;
3479 rc_max = qed_configure_max_vf_rate(cdev, vfid, max_rate);
3482 rc_min = qed_iov_configure_min_tx_rate(cdev, vfid, min_rate);
3484 if (rc_max | rc_min)
3490 static void qed_handle_vf_msg(struct qed_hwfn *hwfn)
3492 u64 events[QED_VF_ARRAY_LENGTH];
3493 struct qed_ptt *ptt;
3496 ptt = qed_ptt_acquire(hwfn);
3498 DP_VERBOSE(hwfn, QED_MSG_IOV,
3499 "Can't acquire PTT; re-scheduling\n");
3500 qed_schedule_iov(hwfn, QED_IOV_WQ_MSG_FLAG);
3504 qed_iov_pf_get_and_clear_pending_events(hwfn, events);
3506 DP_VERBOSE(hwfn, QED_MSG_IOV,
3507 "Event mask of VF events: 0x%llx 0x%llx 0x%llx\n",
3508 events[0], events[1], events[2]);
3510 qed_for_each_vf(hwfn, i) {
3511 /* Skip VFs with no pending messages */
3512 if (!(events[i / 64] & (1ULL << (i % 64))))
3515 DP_VERBOSE(hwfn, QED_MSG_IOV,
3516 "Handling VF message from VF 0x%02x [Abs 0x%02x]\n",
3517 i, hwfn->cdev->p_iov_info->first_vf_in_pf + i);
3519 /* Copy VF's message to PF's request buffer for that VF */
3520 if (qed_iov_copy_vf_msg(hwfn, ptt, i))
3523 qed_iov_process_mbx_req(hwfn, ptt, i);
3526 qed_ptt_release(hwfn, ptt);
3529 static void qed_handle_pf_set_vf_unicast(struct qed_hwfn *hwfn)
3533 qed_for_each_vf(hwfn, i) {
3534 struct qed_public_vf_info *info;
3535 bool update = false;
3538 info = qed_iov_get_public_vf_info(hwfn, i, true);
3542 /* Update data on bulletin board */
3543 mac = qed_iov_bulletin_get_forced_mac(hwfn, i);
3544 if (is_valid_ether_addr(info->forced_mac) &&
3545 (!mac || !ether_addr_equal(mac, info->forced_mac))) {
3548 "Handling PF setting of VF MAC to VF 0x%02x [Abs 0x%02x]\n",
3550 hwfn->cdev->p_iov_info->first_vf_in_pf + i);
3552 /* Update bulletin board with forced MAC */
3553 qed_iov_bulletin_set_forced_mac(hwfn,
3554 info->forced_mac, i);
3558 if (qed_iov_bulletin_get_forced_vlan(hwfn, i) ^
3559 info->forced_vlan) {
3562 "Handling PF setting of pvid [0x%04x] to VF 0x%02x [Abs 0x%02x]\n",
3565 hwfn->cdev->p_iov_info->first_vf_in_pf + i);
3566 qed_iov_bulletin_set_forced_vlan(hwfn,
3567 info->forced_vlan, i);
3572 qed_schedule_iov(hwfn, QED_IOV_WQ_BULLETIN_UPDATE_FLAG);
3576 static void qed_handle_bulletin_post(struct qed_hwfn *hwfn)
3578 struct qed_ptt *ptt;
3581 ptt = qed_ptt_acquire(hwfn);
3583 DP_NOTICE(hwfn, "Failed allocating a ptt entry\n");
3584 qed_schedule_iov(hwfn, QED_IOV_WQ_BULLETIN_UPDATE_FLAG);
3588 qed_for_each_vf(hwfn, i)
3589 qed_iov_post_vf_bulletin(hwfn, i, ptt);
3591 qed_ptt_release(hwfn, ptt);
3594 void qed_iov_pf_task(struct work_struct *work)
3596 struct qed_hwfn *hwfn = container_of(work, struct qed_hwfn,
3600 if (test_and_clear_bit(QED_IOV_WQ_STOP_WQ_FLAG, &hwfn->iov_task_flags))
3603 if (test_and_clear_bit(QED_IOV_WQ_FLR_FLAG, &hwfn->iov_task_flags)) {
3604 struct qed_ptt *ptt = qed_ptt_acquire(hwfn);
3607 qed_schedule_iov(hwfn, QED_IOV_WQ_FLR_FLAG);
3611 rc = qed_iov_vf_flr_cleanup(hwfn, ptt);
3613 qed_schedule_iov(hwfn, QED_IOV_WQ_FLR_FLAG);
3615 qed_ptt_release(hwfn, ptt);
3618 if (test_and_clear_bit(QED_IOV_WQ_MSG_FLAG, &hwfn->iov_task_flags))
3619 qed_handle_vf_msg(hwfn);
3621 if (test_and_clear_bit(QED_IOV_WQ_SET_UNICAST_FILTER_FLAG,
3622 &hwfn->iov_task_flags))
3623 qed_handle_pf_set_vf_unicast(hwfn);
3625 if (test_and_clear_bit(QED_IOV_WQ_BULLETIN_UPDATE_FLAG,
3626 &hwfn->iov_task_flags))
3627 qed_handle_bulletin_post(hwfn);
3630 void qed_iov_wq_stop(struct qed_dev *cdev, bool schedule_first)
3634 for_each_hwfn(cdev, i) {
3635 if (!cdev->hwfns[i].iov_wq)
3638 if (schedule_first) {
3639 qed_schedule_iov(&cdev->hwfns[i],
3640 QED_IOV_WQ_STOP_WQ_FLAG);
3641 cancel_delayed_work_sync(&cdev->hwfns[i].iov_task);
3644 flush_workqueue(cdev->hwfns[i].iov_wq);
3645 destroy_workqueue(cdev->hwfns[i].iov_wq);
3649 int qed_iov_wq_start(struct qed_dev *cdev)
3651 char name[NAME_SIZE];
3654 for_each_hwfn(cdev, i) {
3655 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
3657 /* PFs needs a dedicated workqueue only if they support IOV.
3658 * VFs always require one.
3660 if (IS_PF(p_hwfn->cdev) && !IS_PF_SRIOV(p_hwfn))
3663 snprintf(name, NAME_SIZE, "iov-%02x:%02x.%02x",
3664 cdev->pdev->bus->number,
3665 PCI_SLOT(cdev->pdev->devfn), p_hwfn->abs_pf_id);
3667 p_hwfn->iov_wq = create_singlethread_workqueue(name);
3668 if (!p_hwfn->iov_wq) {
3669 DP_NOTICE(p_hwfn, "Cannot create iov workqueue\n");
3674 INIT_DELAYED_WORK(&p_hwfn->iov_task, qed_iov_pf_task);
3676 INIT_DELAYED_WORK(&p_hwfn->iov_task, qed_iov_vf_task);
3682 const struct qed_iov_hv_ops qed_iov_ops_pass = {
3683 .configure = &qed_sriov_configure,
3684 .set_mac = &qed_sriov_pf_set_mac,
3685 .set_vlan = &qed_sriov_pf_set_vlan,
3686 .get_config = &qed_get_vf_config,
3687 .set_link_state = &qed_set_vf_link_state,
3688 .set_spoof = &qed_spoof_configure,
3689 .set_rate = &qed_set_vf_rate,