x86/mm/pat: Don't report PAT on CPUs that don't support it
[linux/fpc-iii.git] / drivers / net / ethernet / qlogic / qed / qed_sriov.c
blob253c2bbe1e4e1a705e52054b4d3faa199fd2ca93
1 /* QLogic qed NIC Driver
2 * Copyright (c) 2015-2017 QLogic Corporation
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and /or other materials
21 * provided with the distribution.
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE.
33 #include <linux/etherdevice.h>
34 #include <linux/crc32.h>
35 #include <linux/vmalloc.h>
36 #include <linux/qed/qed_iov_if.h>
37 #include "qed_cxt.h"
38 #include "qed_hsi.h"
39 #include "qed_hw.h"
40 #include "qed_init_ops.h"
41 #include "qed_int.h"
42 #include "qed_mcp.h"
43 #include "qed_reg_addr.h"
44 #include "qed_sp.h"
45 #include "qed_sriov.h"
46 #include "qed_vf.h"
48 /* IOV ramrods */
49 static int qed_sp_vf_start(struct qed_hwfn *p_hwfn, struct qed_vf_info *p_vf)
51 struct vf_start_ramrod_data *p_ramrod = NULL;
52 struct qed_spq_entry *p_ent = NULL;
53 struct qed_sp_init_data init_data;
54 int rc = -EINVAL;
55 u8 fp_minor;
57 /* Get SPQ entry */
58 memset(&init_data, 0, sizeof(init_data));
59 init_data.cid = qed_spq_get_cid(p_hwfn);
60 init_data.opaque_fid = p_vf->opaque_fid;
61 init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
63 rc = qed_sp_init_request(p_hwfn, &p_ent,
64 COMMON_RAMROD_VF_START,
65 PROTOCOLID_COMMON, &init_data);
66 if (rc)
67 return rc;
69 p_ramrod = &p_ent->ramrod.vf_start;
71 p_ramrod->vf_id = GET_FIELD(p_vf->concrete_fid, PXP_CONCRETE_FID_VFID);
72 p_ramrod->opaque_fid = cpu_to_le16(p_vf->opaque_fid);
74 switch (p_hwfn->hw_info.personality) {
75 case QED_PCI_ETH:
76 p_ramrod->personality = PERSONALITY_ETH;
77 break;
78 case QED_PCI_ETH_ROCE:
79 p_ramrod->personality = PERSONALITY_RDMA_AND_ETH;
80 break;
81 default:
82 DP_NOTICE(p_hwfn, "Unknown VF personality %d\n",
83 p_hwfn->hw_info.personality);
84 return -EINVAL;
87 fp_minor = p_vf->acquire.vfdev_info.eth_fp_hsi_minor;
88 if (fp_minor > ETH_HSI_VER_MINOR &&
89 fp_minor != ETH_HSI_VER_NO_PKT_LEN_TUNN) {
90 DP_VERBOSE(p_hwfn,
91 QED_MSG_IOV,
92 "VF [%d] - Requested fp hsi %02x.%02x which is slightly newer than PF's %02x.%02x; Configuring PFs version\n",
93 p_vf->abs_vf_id,
94 ETH_HSI_VER_MAJOR,
95 fp_minor, ETH_HSI_VER_MAJOR, ETH_HSI_VER_MINOR);
96 fp_minor = ETH_HSI_VER_MINOR;
99 p_ramrod->hsi_fp_ver.major_ver_arr[ETH_VER_KEY] = ETH_HSI_VER_MAJOR;
100 p_ramrod->hsi_fp_ver.minor_ver_arr[ETH_VER_KEY] = fp_minor;
102 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
103 "VF[%d] - Starting using HSI %02x.%02x\n",
104 p_vf->abs_vf_id, ETH_HSI_VER_MAJOR, fp_minor);
106 return qed_spq_post(p_hwfn, p_ent, NULL);
109 static int qed_sp_vf_stop(struct qed_hwfn *p_hwfn,
110 u32 concrete_vfid, u16 opaque_vfid)
112 struct vf_stop_ramrod_data *p_ramrod = NULL;
113 struct qed_spq_entry *p_ent = NULL;
114 struct qed_sp_init_data init_data;
115 int rc = -EINVAL;
117 /* Get SPQ entry */
118 memset(&init_data, 0, sizeof(init_data));
119 init_data.cid = qed_spq_get_cid(p_hwfn);
120 init_data.opaque_fid = opaque_vfid;
121 init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
123 rc = qed_sp_init_request(p_hwfn, &p_ent,
124 COMMON_RAMROD_VF_STOP,
125 PROTOCOLID_COMMON, &init_data);
126 if (rc)
127 return rc;
129 p_ramrod = &p_ent->ramrod.vf_stop;
131 p_ramrod->vf_id = GET_FIELD(concrete_vfid, PXP_CONCRETE_FID_VFID);
133 return qed_spq_post(p_hwfn, p_ent, NULL);
136 static bool qed_iov_is_valid_vfid(struct qed_hwfn *p_hwfn,
137 int rel_vf_id,
138 bool b_enabled_only, bool b_non_malicious)
140 if (!p_hwfn->pf_iov_info) {
141 DP_NOTICE(p_hwfn->cdev, "No iov info\n");
142 return false;
145 if ((rel_vf_id >= p_hwfn->cdev->p_iov_info->total_vfs) ||
146 (rel_vf_id < 0))
147 return false;
149 if ((!p_hwfn->pf_iov_info->vfs_array[rel_vf_id].b_init) &&
150 b_enabled_only)
151 return false;
153 if ((p_hwfn->pf_iov_info->vfs_array[rel_vf_id].b_malicious) &&
154 b_non_malicious)
155 return false;
157 return true;
160 static struct qed_vf_info *qed_iov_get_vf_info(struct qed_hwfn *p_hwfn,
161 u16 relative_vf_id,
162 bool b_enabled_only)
164 struct qed_vf_info *vf = NULL;
166 if (!p_hwfn->pf_iov_info) {
167 DP_NOTICE(p_hwfn->cdev, "No iov info\n");
168 return NULL;
171 if (qed_iov_is_valid_vfid(p_hwfn, relative_vf_id,
172 b_enabled_only, false))
173 vf = &p_hwfn->pf_iov_info->vfs_array[relative_vf_id];
174 else
175 DP_ERR(p_hwfn, "qed_iov_get_vf_info: VF[%d] is not enabled\n",
176 relative_vf_id);
178 return vf;
181 static bool qed_iov_validate_rxq(struct qed_hwfn *p_hwfn,
182 struct qed_vf_info *p_vf, u16 rx_qid)
184 if (rx_qid >= p_vf->num_rxqs)
185 DP_VERBOSE(p_hwfn,
186 QED_MSG_IOV,
187 "VF[0x%02x] - can't touch Rx queue[%04x]; Only 0x%04x are allocated\n",
188 p_vf->abs_vf_id, rx_qid, p_vf->num_rxqs);
189 return rx_qid < p_vf->num_rxqs;
192 static bool qed_iov_validate_txq(struct qed_hwfn *p_hwfn,
193 struct qed_vf_info *p_vf, u16 tx_qid)
195 if (tx_qid >= p_vf->num_txqs)
196 DP_VERBOSE(p_hwfn,
197 QED_MSG_IOV,
198 "VF[0x%02x] - can't touch Tx queue[%04x]; Only 0x%04x are allocated\n",
199 p_vf->abs_vf_id, tx_qid, p_vf->num_txqs);
200 return tx_qid < p_vf->num_txqs;
203 static bool qed_iov_validate_sb(struct qed_hwfn *p_hwfn,
204 struct qed_vf_info *p_vf, u16 sb_idx)
206 int i;
208 for (i = 0; i < p_vf->num_sbs; i++)
209 if (p_vf->igu_sbs[i] == sb_idx)
210 return true;
212 DP_VERBOSE(p_hwfn,
213 QED_MSG_IOV,
214 "VF[0%02x] - tried using sb_idx %04x which doesn't exist as one of its 0x%02x SBs\n",
215 p_vf->abs_vf_id, sb_idx, p_vf->num_sbs);
217 return false;
220 static int qed_iov_post_vf_bulletin(struct qed_hwfn *p_hwfn,
221 int vfid, struct qed_ptt *p_ptt)
223 struct qed_bulletin_content *p_bulletin;
224 int crc_size = sizeof(p_bulletin->crc);
225 struct qed_dmae_params params;
226 struct qed_vf_info *p_vf;
228 p_vf = qed_iov_get_vf_info(p_hwfn, (u16) vfid, true);
229 if (!p_vf)
230 return -EINVAL;
232 if (!p_vf->vf_bulletin)
233 return -EINVAL;
235 p_bulletin = p_vf->bulletin.p_virt;
237 /* Increment bulletin board version and compute crc */
238 p_bulletin->version++;
239 p_bulletin->crc = crc32(0, (u8 *)p_bulletin + crc_size,
240 p_vf->bulletin.size - crc_size);
242 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
243 "Posting Bulletin 0x%08x to VF[%d] (CRC 0x%08x)\n",
244 p_bulletin->version, p_vf->relative_vf_id, p_bulletin->crc);
246 /* propagate bulletin board via dmae to vm memory */
247 memset(&params, 0, sizeof(params));
248 params.flags = QED_DMAE_FLAG_VF_DST;
249 params.dst_vfid = p_vf->abs_vf_id;
250 return qed_dmae_host2host(p_hwfn, p_ptt, p_vf->bulletin.phys,
251 p_vf->vf_bulletin, p_vf->bulletin.size / 4,
252 &params);
255 static int qed_iov_pci_cfg_info(struct qed_dev *cdev)
257 struct qed_hw_sriov_info *iov = cdev->p_iov_info;
258 int pos = iov->pos;
260 DP_VERBOSE(cdev, QED_MSG_IOV, "sriov ext pos %d\n", pos);
261 pci_read_config_word(cdev->pdev, pos + PCI_SRIOV_CTRL, &iov->ctrl);
263 pci_read_config_word(cdev->pdev,
264 pos + PCI_SRIOV_TOTAL_VF, &iov->total_vfs);
265 pci_read_config_word(cdev->pdev,
266 pos + PCI_SRIOV_INITIAL_VF, &iov->initial_vfs);
268 pci_read_config_word(cdev->pdev, pos + PCI_SRIOV_NUM_VF, &iov->num_vfs);
269 if (iov->num_vfs) {
270 DP_VERBOSE(cdev,
271 QED_MSG_IOV,
272 "Number of VFs are already set to non-zero value. Ignoring PCI configuration value\n");
273 iov->num_vfs = 0;
276 pci_read_config_word(cdev->pdev,
277 pos + PCI_SRIOV_VF_OFFSET, &iov->offset);
279 pci_read_config_word(cdev->pdev,
280 pos + PCI_SRIOV_VF_STRIDE, &iov->stride);
282 pci_read_config_word(cdev->pdev,
283 pos + PCI_SRIOV_VF_DID, &iov->vf_device_id);
285 pci_read_config_dword(cdev->pdev,
286 pos + PCI_SRIOV_SUP_PGSIZE, &iov->pgsz);
288 pci_read_config_dword(cdev->pdev, pos + PCI_SRIOV_CAP, &iov->cap);
290 pci_read_config_byte(cdev->pdev, pos + PCI_SRIOV_FUNC_LINK, &iov->link);
292 DP_VERBOSE(cdev,
293 QED_MSG_IOV,
294 "IOV info: nres %d, cap 0x%x, ctrl 0x%x, total %d, initial %d, num vfs %d, offset %d, stride %d, page size 0x%x\n",
295 iov->nres,
296 iov->cap,
297 iov->ctrl,
298 iov->total_vfs,
299 iov->initial_vfs,
300 iov->nr_virtfn, iov->offset, iov->stride, iov->pgsz);
302 /* Some sanity checks */
303 if (iov->num_vfs > NUM_OF_VFS(cdev) ||
304 iov->total_vfs > NUM_OF_VFS(cdev)) {
305 /* This can happen only due to a bug. In this case we set
306 * num_vfs to zero to avoid memory corruption in the code that
307 * assumes max number of vfs
309 DP_NOTICE(cdev,
310 "IOV: Unexpected number of vfs set: %d setting num_vf to zero\n",
311 iov->num_vfs);
313 iov->num_vfs = 0;
314 iov->total_vfs = 0;
317 return 0;
320 static void qed_iov_clear_vf_igu_blocks(struct qed_hwfn *p_hwfn,
321 struct qed_ptt *p_ptt)
323 struct qed_igu_block *p_sb;
324 u16 sb_id;
325 u32 val;
327 if (!p_hwfn->hw_info.p_igu_info) {
328 DP_ERR(p_hwfn,
329 "qed_iov_clear_vf_igu_blocks IGU Info not initialized\n");
330 return;
333 for (sb_id = 0; sb_id < QED_MAPPING_MEMORY_SIZE(p_hwfn->cdev);
334 sb_id++) {
335 p_sb = &p_hwfn->hw_info.p_igu_info->igu_map.igu_blocks[sb_id];
336 if ((p_sb->status & QED_IGU_STATUS_FREE) &&
337 !(p_sb->status & QED_IGU_STATUS_PF)) {
338 val = qed_rd(p_hwfn, p_ptt,
339 IGU_REG_MAPPING_MEMORY + sb_id * 4);
340 SET_FIELD(val, IGU_MAPPING_LINE_VALID, 0);
341 qed_wr(p_hwfn, p_ptt,
342 IGU_REG_MAPPING_MEMORY + 4 * sb_id, val);
347 static void qed_iov_setup_vfdb(struct qed_hwfn *p_hwfn)
349 struct qed_hw_sriov_info *p_iov = p_hwfn->cdev->p_iov_info;
350 struct qed_pf_iov *p_iov_info = p_hwfn->pf_iov_info;
351 struct qed_bulletin_content *p_bulletin_virt;
352 dma_addr_t req_p, rply_p, bulletin_p;
353 union pfvf_tlvs *p_reply_virt_addr;
354 union vfpf_tlvs *p_req_virt_addr;
355 u8 idx = 0;
357 memset(p_iov_info->vfs_array, 0, sizeof(p_iov_info->vfs_array));
359 p_req_virt_addr = p_iov_info->mbx_msg_virt_addr;
360 req_p = p_iov_info->mbx_msg_phys_addr;
361 p_reply_virt_addr = p_iov_info->mbx_reply_virt_addr;
362 rply_p = p_iov_info->mbx_reply_phys_addr;
363 p_bulletin_virt = p_iov_info->p_bulletins;
364 bulletin_p = p_iov_info->bulletins_phys;
365 if (!p_req_virt_addr || !p_reply_virt_addr || !p_bulletin_virt) {
366 DP_ERR(p_hwfn,
367 "qed_iov_setup_vfdb called without allocating mem first\n");
368 return;
371 for (idx = 0; idx < p_iov->total_vfs; idx++) {
372 struct qed_vf_info *vf = &p_iov_info->vfs_array[idx];
373 u32 concrete;
375 vf->vf_mbx.req_virt = p_req_virt_addr + idx;
376 vf->vf_mbx.req_phys = req_p + idx * sizeof(union vfpf_tlvs);
377 vf->vf_mbx.reply_virt = p_reply_virt_addr + idx;
378 vf->vf_mbx.reply_phys = rply_p + idx * sizeof(union pfvf_tlvs);
380 vf->state = VF_STOPPED;
381 vf->b_init = false;
383 vf->bulletin.phys = idx *
384 sizeof(struct qed_bulletin_content) +
385 bulletin_p;
386 vf->bulletin.p_virt = p_bulletin_virt + idx;
387 vf->bulletin.size = sizeof(struct qed_bulletin_content);
389 vf->relative_vf_id = idx;
390 vf->abs_vf_id = idx + p_iov->first_vf_in_pf;
391 concrete = qed_vfid_to_concrete(p_hwfn, vf->abs_vf_id);
392 vf->concrete_fid = concrete;
393 vf->opaque_fid = (p_hwfn->hw_info.opaque_fid & 0xff) |
394 (vf->abs_vf_id << 8);
395 vf->vport_id = idx + 1;
397 vf->num_mac_filters = QED_ETH_VF_NUM_MAC_FILTERS;
398 vf->num_vlan_filters = QED_ETH_VF_NUM_VLAN_FILTERS;
402 static int qed_iov_allocate_vfdb(struct qed_hwfn *p_hwfn)
404 struct qed_pf_iov *p_iov_info = p_hwfn->pf_iov_info;
405 void **p_v_addr;
406 u16 num_vfs = 0;
408 num_vfs = p_hwfn->cdev->p_iov_info->total_vfs;
410 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
411 "qed_iov_allocate_vfdb for %d VFs\n", num_vfs);
413 /* Allocate PF Mailbox buffer (per-VF) */
414 p_iov_info->mbx_msg_size = sizeof(union vfpf_tlvs) * num_vfs;
415 p_v_addr = &p_iov_info->mbx_msg_virt_addr;
416 *p_v_addr = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev,
417 p_iov_info->mbx_msg_size,
418 &p_iov_info->mbx_msg_phys_addr,
419 GFP_KERNEL);
420 if (!*p_v_addr)
421 return -ENOMEM;
423 /* Allocate PF Mailbox Reply buffer (per-VF) */
424 p_iov_info->mbx_reply_size = sizeof(union pfvf_tlvs) * num_vfs;
425 p_v_addr = &p_iov_info->mbx_reply_virt_addr;
426 *p_v_addr = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev,
427 p_iov_info->mbx_reply_size,
428 &p_iov_info->mbx_reply_phys_addr,
429 GFP_KERNEL);
430 if (!*p_v_addr)
431 return -ENOMEM;
433 p_iov_info->bulletins_size = sizeof(struct qed_bulletin_content) *
434 num_vfs;
435 p_v_addr = &p_iov_info->p_bulletins;
436 *p_v_addr = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev,
437 p_iov_info->bulletins_size,
438 &p_iov_info->bulletins_phys,
439 GFP_KERNEL);
440 if (!*p_v_addr)
441 return -ENOMEM;
443 DP_VERBOSE(p_hwfn,
444 QED_MSG_IOV,
445 "PF's Requests mailbox [%p virt 0x%llx phys], Response mailbox [%p virt 0x%llx phys] Bulletins [%p virt 0x%llx phys]\n",
446 p_iov_info->mbx_msg_virt_addr,
447 (u64) p_iov_info->mbx_msg_phys_addr,
448 p_iov_info->mbx_reply_virt_addr,
449 (u64) p_iov_info->mbx_reply_phys_addr,
450 p_iov_info->p_bulletins, (u64) p_iov_info->bulletins_phys);
452 return 0;
455 static void qed_iov_free_vfdb(struct qed_hwfn *p_hwfn)
457 struct qed_pf_iov *p_iov_info = p_hwfn->pf_iov_info;
459 if (p_hwfn->pf_iov_info->mbx_msg_virt_addr)
460 dma_free_coherent(&p_hwfn->cdev->pdev->dev,
461 p_iov_info->mbx_msg_size,
462 p_iov_info->mbx_msg_virt_addr,
463 p_iov_info->mbx_msg_phys_addr);
465 if (p_hwfn->pf_iov_info->mbx_reply_virt_addr)
466 dma_free_coherent(&p_hwfn->cdev->pdev->dev,
467 p_iov_info->mbx_reply_size,
468 p_iov_info->mbx_reply_virt_addr,
469 p_iov_info->mbx_reply_phys_addr);
471 if (p_iov_info->p_bulletins)
472 dma_free_coherent(&p_hwfn->cdev->pdev->dev,
473 p_iov_info->bulletins_size,
474 p_iov_info->p_bulletins,
475 p_iov_info->bulletins_phys);
478 int qed_iov_alloc(struct qed_hwfn *p_hwfn)
480 struct qed_pf_iov *p_sriov;
482 if (!IS_PF_SRIOV(p_hwfn)) {
483 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
484 "No SR-IOV - no need for IOV db\n");
485 return 0;
488 p_sriov = kzalloc(sizeof(*p_sriov), GFP_KERNEL);
489 if (!p_sriov)
490 return -ENOMEM;
492 p_hwfn->pf_iov_info = p_sriov;
494 return qed_iov_allocate_vfdb(p_hwfn);
497 void qed_iov_setup(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
499 if (!IS_PF_SRIOV(p_hwfn) || !IS_PF_SRIOV_ALLOC(p_hwfn))
500 return;
502 qed_iov_setup_vfdb(p_hwfn);
503 qed_iov_clear_vf_igu_blocks(p_hwfn, p_ptt);
506 void qed_iov_free(struct qed_hwfn *p_hwfn)
508 if (IS_PF_SRIOV_ALLOC(p_hwfn)) {
509 qed_iov_free_vfdb(p_hwfn);
510 kfree(p_hwfn->pf_iov_info);
514 void qed_iov_free_hw_info(struct qed_dev *cdev)
516 kfree(cdev->p_iov_info);
517 cdev->p_iov_info = NULL;
520 int qed_iov_hw_info(struct qed_hwfn *p_hwfn)
522 struct qed_dev *cdev = p_hwfn->cdev;
523 int pos;
524 int rc;
526 if (IS_VF(p_hwfn->cdev))
527 return 0;
529 /* Learn the PCI configuration */
530 pos = pci_find_ext_capability(p_hwfn->cdev->pdev,
531 PCI_EXT_CAP_ID_SRIOV);
532 if (!pos) {
533 DP_VERBOSE(p_hwfn, QED_MSG_IOV, "No PCIe IOV support\n");
534 return 0;
537 /* Allocate a new struct for IOV information */
538 cdev->p_iov_info = kzalloc(sizeof(*cdev->p_iov_info), GFP_KERNEL);
539 if (!cdev->p_iov_info)
540 return -ENOMEM;
542 cdev->p_iov_info->pos = pos;
544 rc = qed_iov_pci_cfg_info(cdev);
545 if (rc)
546 return rc;
548 /* We want PF IOV to be synonemous with the existance of p_iov_info;
549 * In case the capability is published but there are no VFs, simply
550 * de-allocate the struct.
552 if (!cdev->p_iov_info->total_vfs) {
553 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
554 "IOV capabilities, but no VFs are published\n");
555 kfree(cdev->p_iov_info);
556 cdev->p_iov_info = NULL;
557 return 0;
560 /* Calculate the first VF index - this is a bit tricky; Basically,
561 * VFs start at offset 16 relative to PF0, and 2nd engine VFs begin
562 * after the first engine's VFs.
564 cdev->p_iov_info->first_vf_in_pf = p_hwfn->cdev->p_iov_info->offset +
565 p_hwfn->abs_pf_id - 16;
566 if (QED_PATH_ID(p_hwfn))
567 cdev->p_iov_info->first_vf_in_pf -= MAX_NUM_VFS_BB;
569 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
570 "First VF in hwfn 0x%08x\n",
571 cdev->p_iov_info->first_vf_in_pf);
573 return 0;
576 bool _qed_iov_pf_sanity_check(struct qed_hwfn *p_hwfn,
577 int vfid, bool b_fail_malicious)
579 /* Check PF supports sriov */
580 if (IS_VF(p_hwfn->cdev) || !IS_QED_SRIOV(p_hwfn->cdev) ||
581 !IS_PF_SRIOV_ALLOC(p_hwfn))
582 return false;
584 /* Check VF validity */
585 if (!qed_iov_is_valid_vfid(p_hwfn, vfid, true, b_fail_malicious))
586 return false;
588 return true;
591 bool qed_iov_pf_sanity_check(struct qed_hwfn *p_hwfn, int vfid)
593 return _qed_iov_pf_sanity_check(p_hwfn, vfid, true);
596 static void qed_iov_set_vf_to_disable(struct qed_dev *cdev,
597 u16 rel_vf_id, u8 to_disable)
599 struct qed_vf_info *vf;
600 int i;
602 for_each_hwfn(cdev, i) {
603 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
605 vf = qed_iov_get_vf_info(p_hwfn, rel_vf_id, false);
606 if (!vf)
607 continue;
609 vf->to_disable = to_disable;
613 static void qed_iov_set_vfs_to_disable(struct qed_dev *cdev, u8 to_disable)
615 u16 i;
617 if (!IS_QED_SRIOV(cdev))
618 return;
620 for (i = 0; i < cdev->p_iov_info->total_vfs; i++)
621 qed_iov_set_vf_to_disable(cdev, i, to_disable);
624 static void qed_iov_vf_pglue_clear_err(struct qed_hwfn *p_hwfn,
625 struct qed_ptt *p_ptt, u8 abs_vfid)
627 qed_wr(p_hwfn, p_ptt,
628 PGLUE_B_REG_WAS_ERROR_VF_31_0_CLR + (abs_vfid >> 5) * 4,
629 1 << (abs_vfid & 0x1f));
632 static void qed_iov_vf_igu_reset(struct qed_hwfn *p_hwfn,
633 struct qed_ptt *p_ptt, struct qed_vf_info *vf)
635 int i;
637 /* Set VF masks and configuration - pretend */
638 qed_fid_pretend(p_hwfn, p_ptt, (u16) vf->concrete_fid);
640 qed_wr(p_hwfn, p_ptt, IGU_REG_STATISTIC_NUM_VF_MSG_SENT, 0);
642 /* unpretend */
643 qed_fid_pretend(p_hwfn, p_ptt, (u16) p_hwfn->hw_info.concrete_fid);
645 /* iterate over all queues, clear sb consumer */
646 for (i = 0; i < vf->num_sbs; i++)
647 qed_int_igu_init_pure_rt_single(p_hwfn, p_ptt,
648 vf->igu_sbs[i],
649 vf->opaque_fid, true);
652 static void qed_iov_vf_igu_set_int(struct qed_hwfn *p_hwfn,
653 struct qed_ptt *p_ptt,
654 struct qed_vf_info *vf, bool enable)
656 u32 igu_vf_conf;
658 qed_fid_pretend(p_hwfn, p_ptt, (u16) vf->concrete_fid);
660 igu_vf_conf = qed_rd(p_hwfn, p_ptt, IGU_REG_VF_CONFIGURATION);
662 if (enable)
663 igu_vf_conf |= IGU_VF_CONF_MSI_MSIX_EN;
664 else
665 igu_vf_conf &= ~IGU_VF_CONF_MSI_MSIX_EN;
667 qed_wr(p_hwfn, p_ptt, IGU_REG_VF_CONFIGURATION, igu_vf_conf);
669 /* unpretend */
670 qed_fid_pretend(p_hwfn, p_ptt, (u16) p_hwfn->hw_info.concrete_fid);
673 static int qed_iov_enable_vf_access(struct qed_hwfn *p_hwfn,
674 struct qed_ptt *p_ptt,
675 struct qed_vf_info *vf)
677 u32 igu_vf_conf = IGU_VF_CONF_FUNC_EN;
678 int rc;
680 if (vf->to_disable)
681 return 0;
683 DP_VERBOSE(p_hwfn,
684 QED_MSG_IOV,
685 "Enable internal access for vf %x [abs %x]\n",
686 vf->abs_vf_id, QED_VF_ABS_ID(p_hwfn, vf));
688 qed_iov_vf_pglue_clear_err(p_hwfn, p_ptt, QED_VF_ABS_ID(p_hwfn, vf));
690 qed_iov_vf_igu_reset(p_hwfn, p_ptt, vf);
692 /* It's possible VF was previously considered malicious */
693 vf->b_malicious = false;
695 rc = qed_mcp_config_vf_msix(p_hwfn, p_ptt, vf->abs_vf_id, vf->num_sbs);
696 if (rc)
697 return rc;
699 qed_fid_pretend(p_hwfn, p_ptt, (u16) vf->concrete_fid);
701 SET_FIELD(igu_vf_conf, IGU_VF_CONF_PARENT, p_hwfn->rel_pf_id);
702 STORE_RT_REG(p_hwfn, IGU_REG_VF_CONFIGURATION_RT_OFFSET, igu_vf_conf);
704 qed_init_run(p_hwfn, p_ptt, PHASE_VF, vf->abs_vf_id,
705 p_hwfn->hw_info.hw_mode);
707 /* unpretend */
708 qed_fid_pretend(p_hwfn, p_ptt, (u16) p_hwfn->hw_info.concrete_fid);
710 vf->state = VF_FREE;
712 return rc;
716 * @brief qed_iov_config_perm_table - configure the permission
717 * zone table.
718 * In E4, queue zone permission table size is 320x9. There
719 * are 320 VF queues for single engine device (256 for dual
720 * engine device), and each entry has the following format:
721 * {Valid, VF[7:0]}
722 * @param p_hwfn
723 * @param p_ptt
724 * @param vf
725 * @param enable
727 static void qed_iov_config_perm_table(struct qed_hwfn *p_hwfn,
728 struct qed_ptt *p_ptt,
729 struct qed_vf_info *vf, u8 enable)
731 u32 reg_addr, val;
732 u16 qzone_id = 0;
733 int qid;
735 for (qid = 0; qid < vf->num_rxqs; qid++) {
736 qed_fw_l2_queue(p_hwfn, vf->vf_queues[qid].fw_rx_qid,
737 &qzone_id);
739 reg_addr = PSWHST_REG_ZONE_PERMISSION_TABLE + qzone_id * 4;
740 val = enable ? (vf->abs_vf_id | BIT(8)) : 0;
741 qed_wr(p_hwfn, p_ptt, reg_addr, val);
745 static void qed_iov_enable_vf_traffic(struct qed_hwfn *p_hwfn,
746 struct qed_ptt *p_ptt,
747 struct qed_vf_info *vf)
749 /* Reset vf in IGU - interrupts are still disabled */
750 qed_iov_vf_igu_reset(p_hwfn, p_ptt, vf);
752 qed_iov_vf_igu_set_int(p_hwfn, p_ptt, vf, 1);
754 /* Permission Table */
755 qed_iov_config_perm_table(p_hwfn, p_ptt, vf, true);
758 static u8 qed_iov_alloc_vf_igu_sbs(struct qed_hwfn *p_hwfn,
759 struct qed_ptt *p_ptt,
760 struct qed_vf_info *vf, u16 num_rx_queues)
762 struct qed_igu_block *igu_blocks;
763 int qid = 0, igu_id = 0;
764 u32 val = 0;
766 igu_blocks = p_hwfn->hw_info.p_igu_info->igu_map.igu_blocks;
768 if (num_rx_queues > p_hwfn->hw_info.p_igu_info->free_blks)
769 num_rx_queues = p_hwfn->hw_info.p_igu_info->free_blks;
770 p_hwfn->hw_info.p_igu_info->free_blks -= num_rx_queues;
772 SET_FIELD(val, IGU_MAPPING_LINE_FUNCTION_NUMBER, vf->abs_vf_id);
773 SET_FIELD(val, IGU_MAPPING_LINE_VALID, 1);
774 SET_FIELD(val, IGU_MAPPING_LINE_PF_VALID, 0);
776 while ((qid < num_rx_queues) &&
777 (igu_id < QED_MAPPING_MEMORY_SIZE(p_hwfn->cdev))) {
778 if (igu_blocks[igu_id].status & QED_IGU_STATUS_FREE) {
779 struct cau_sb_entry sb_entry;
781 vf->igu_sbs[qid] = (u16)igu_id;
782 igu_blocks[igu_id].status &= ~QED_IGU_STATUS_FREE;
784 SET_FIELD(val, IGU_MAPPING_LINE_VECTOR_NUMBER, qid);
786 qed_wr(p_hwfn, p_ptt,
787 IGU_REG_MAPPING_MEMORY + sizeof(u32) * igu_id,
788 val);
790 /* Configure igu sb in CAU which were marked valid */
791 qed_init_cau_sb_entry(p_hwfn, &sb_entry,
792 p_hwfn->rel_pf_id,
793 vf->abs_vf_id, 1);
794 qed_dmae_host2grc(p_hwfn, p_ptt,
795 (u64)(uintptr_t)&sb_entry,
796 CAU_REG_SB_VAR_MEMORY +
797 igu_id * sizeof(u64), 2, 0);
798 qid++;
800 igu_id++;
803 vf->num_sbs = (u8) num_rx_queues;
805 return vf->num_sbs;
808 static void qed_iov_free_vf_igu_sbs(struct qed_hwfn *p_hwfn,
809 struct qed_ptt *p_ptt,
810 struct qed_vf_info *vf)
812 struct qed_igu_info *p_info = p_hwfn->hw_info.p_igu_info;
813 int idx, igu_id;
814 u32 addr, val;
816 /* Invalidate igu CAM lines and mark them as free */
817 for (idx = 0; idx < vf->num_sbs; idx++) {
818 igu_id = vf->igu_sbs[idx];
819 addr = IGU_REG_MAPPING_MEMORY + sizeof(u32) * igu_id;
821 val = qed_rd(p_hwfn, p_ptt, addr);
822 SET_FIELD(val, IGU_MAPPING_LINE_VALID, 0);
823 qed_wr(p_hwfn, p_ptt, addr, val);
825 p_info->igu_map.igu_blocks[igu_id].status |=
826 QED_IGU_STATUS_FREE;
828 p_hwfn->hw_info.p_igu_info->free_blks++;
831 vf->num_sbs = 0;
834 static void qed_iov_set_link(struct qed_hwfn *p_hwfn,
835 u16 vfid,
836 struct qed_mcp_link_params *params,
837 struct qed_mcp_link_state *link,
838 struct qed_mcp_link_capabilities *p_caps)
840 struct qed_vf_info *p_vf = qed_iov_get_vf_info(p_hwfn,
841 vfid,
842 false);
843 struct qed_bulletin_content *p_bulletin;
845 if (!p_vf)
846 return;
848 p_bulletin = p_vf->bulletin.p_virt;
849 p_bulletin->req_autoneg = params->speed.autoneg;
850 p_bulletin->req_adv_speed = params->speed.advertised_speeds;
851 p_bulletin->req_forced_speed = params->speed.forced_speed;
852 p_bulletin->req_autoneg_pause = params->pause.autoneg;
853 p_bulletin->req_forced_rx = params->pause.forced_rx;
854 p_bulletin->req_forced_tx = params->pause.forced_tx;
855 p_bulletin->req_loopback = params->loopback_mode;
857 p_bulletin->link_up = link->link_up;
858 p_bulletin->speed = link->speed;
859 p_bulletin->full_duplex = link->full_duplex;
860 p_bulletin->autoneg = link->an;
861 p_bulletin->autoneg_complete = link->an_complete;
862 p_bulletin->parallel_detection = link->parallel_detection;
863 p_bulletin->pfc_enabled = link->pfc_enabled;
864 p_bulletin->partner_adv_speed = link->partner_adv_speed;
865 p_bulletin->partner_tx_flow_ctrl_en = link->partner_tx_flow_ctrl_en;
866 p_bulletin->partner_rx_flow_ctrl_en = link->partner_rx_flow_ctrl_en;
867 p_bulletin->partner_adv_pause = link->partner_adv_pause;
868 p_bulletin->sfp_tx_fault = link->sfp_tx_fault;
870 p_bulletin->capability_speed = p_caps->speed_capabilities;
873 static int qed_iov_init_hw_for_vf(struct qed_hwfn *p_hwfn,
874 struct qed_ptt *p_ptt,
875 struct qed_iov_vf_init_params *p_params)
877 struct qed_mcp_link_capabilities link_caps;
878 struct qed_mcp_link_params link_params;
879 struct qed_mcp_link_state link_state;
880 u8 num_of_vf_avaiable_chains = 0;
881 struct qed_vf_info *vf = NULL;
882 u16 qid, num_irqs;
883 int rc = 0;
884 u32 cids;
885 u8 i;
887 vf = qed_iov_get_vf_info(p_hwfn, p_params->rel_vf_id, false);
888 if (!vf) {
889 DP_ERR(p_hwfn, "qed_iov_init_hw_for_vf : vf is NULL\n");
890 return -EINVAL;
893 if (vf->b_init) {
894 DP_NOTICE(p_hwfn, "VF[%d] is already active.\n",
895 p_params->rel_vf_id);
896 return -EINVAL;
899 /* Perform sanity checking on the requested queue_id */
900 for (i = 0; i < p_params->num_queues; i++) {
901 u16 min_vf_qzone = FEAT_NUM(p_hwfn, QED_PF_L2_QUE);
902 u16 max_vf_qzone = min_vf_qzone +
903 FEAT_NUM(p_hwfn, QED_VF_L2_QUE) - 1;
905 qid = p_params->req_rx_queue[i];
906 if (qid < min_vf_qzone || qid > max_vf_qzone) {
907 DP_NOTICE(p_hwfn,
908 "Can't enable Rx qid [%04x] for VF[%d]: qids [0x%04x,...,0x%04x] available\n",
909 qid,
910 p_params->rel_vf_id,
911 min_vf_qzone, max_vf_qzone);
912 return -EINVAL;
915 qid = p_params->req_tx_queue[i];
916 if (qid > max_vf_qzone) {
917 DP_NOTICE(p_hwfn,
918 "Can't enable Tx qid [%04x] for VF[%d]: max qid 0x%04x\n",
919 qid, p_params->rel_vf_id, max_vf_qzone);
920 return -EINVAL;
923 /* If client *really* wants, Tx qid can be shared with PF */
924 if (qid < min_vf_qzone)
925 DP_VERBOSE(p_hwfn,
926 QED_MSG_IOV,
927 "VF[%d] is using PF qid [0x%04x] for Txq[0x%02x]\n",
928 p_params->rel_vf_id, qid, i);
931 /* Limit number of queues according to number of CIDs */
932 qed_cxt_get_proto_cid_count(p_hwfn, PROTOCOLID_ETH, &cids);
933 DP_VERBOSE(p_hwfn,
934 QED_MSG_IOV,
935 "VF[%d] - requesting to initialize for 0x%04x queues [0x%04x CIDs available]\n",
936 vf->relative_vf_id, p_params->num_queues, (u16)cids);
937 num_irqs = min_t(u16, p_params->num_queues, ((u16)cids));
939 num_of_vf_avaiable_chains = qed_iov_alloc_vf_igu_sbs(p_hwfn,
940 p_ptt,
941 vf, num_irqs);
942 if (!num_of_vf_avaiable_chains) {
943 DP_ERR(p_hwfn, "no available igu sbs\n");
944 return -ENOMEM;
947 /* Choose queue number and index ranges */
948 vf->num_rxqs = num_of_vf_avaiable_chains;
949 vf->num_txqs = num_of_vf_avaiable_chains;
951 for (i = 0; i < vf->num_rxqs; i++) {
952 struct qed_vf_q_info *p_queue = &vf->vf_queues[i];
954 p_queue->fw_rx_qid = p_params->req_rx_queue[i];
955 p_queue->fw_tx_qid = p_params->req_tx_queue[i];
957 /* CIDs are per-VF, so no problem having them 0-based. */
958 p_queue->fw_cid = i;
960 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
961 "VF[%d] - Q[%d] SB %04x, qid [Rx %04x Tx %04x] CID %04x\n",
962 vf->relative_vf_id,
963 i, vf->igu_sbs[i],
964 p_queue->fw_rx_qid,
965 p_queue->fw_tx_qid, p_queue->fw_cid);
968 /* Update the link configuration in bulletin */
969 memcpy(&link_params, qed_mcp_get_link_params(p_hwfn),
970 sizeof(link_params));
971 memcpy(&link_state, qed_mcp_get_link_state(p_hwfn), sizeof(link_state));
972 memcpy(&link_caps, qed_mcp_get_link_capabilities(p_hwfn),
973 sizeof(link_caps));
974 qed_iov_set_link(p_hwfn, p_params->rel_vf_id,
975 &link_params, &link_state, &link_caps);
977 rc = qed_iov_enable_vf_access(p_hwfn, p_ptt, vf);
978 if (!rc) {
979 vf->b_init = true;
981 if (IS_LEAD_HWFN(p_hwfn))
982 p_hwfn->cdev->p_iov_info->num_vfs++;
985 return rc;
988 static int qed_iov_release_hw_for_vf(struct qed_hwfn *p_hwfn,
989 struct qed_ptt *p_ptt, u16 rel_vf_id)
991 struct qed_mcp_link_capabilities caps;
992 struct qed_mcp_link_params params;
993 struct qed_mcp_link_state link;
994 struct qed_vf_info *vf = NULL;
996 vf = qed_iov_get_vf_info(p_hwfn, rel_vf_id, true);
997 if (!vf) {
998 DP_ERR(p_hwfn, "qed_iov_release_hw_for_vf : vf is NULL\n");
999 return -EINVAL;
1002 if (vf->bulletin.p_virt)
1003 memset(vf->bulletin.p_virt, 0, sizeof(*vf->bulletin.p_virt));
1005 memset(&vf->p_vf_info, 0, sizeof(vf->p_vf_info));
1007 /* Get the link configuration back in bulletin so
1008 * that when VFs are re-enabled they get the actual
1009 * link configuration.
1011 memcpy(&params, qed_mcp_get_link_params(p_hwfn), sizeof(params));
1012 memcpy(&link, qed_mcp_get_link_state(p_hwfn), sizeof(link));
1013 memcpy(&caps, qed_mcp_get_link_capabilities(p_hwfn), sizeof(caps));
1014 qed_iov_set_link(p_hwfn, rel_vf_id, &params, &link, &caps);
1016 /* Forget the VF's acquisition message */
1017 memset(&vf->acquire, 0, sizeof(vf->acquire));
1019 /* disablng interrupts and resetting permission table was done during
1020 * vf-close, however, we could get here without going through vf_close
1022 /* Disable Interrupts for VF */
1023 qed_iov_vf_igu_set_int(p_hwfn, p_ptt, vf, 0);
1025 /* Reset Permission table */
1026 qed_iov_config_perm_table(p_hwfn, p_ptt, vf, 0);
1028 vf->num_rxqs = 0;
1029 vf->num_txqs = 0;
1030 qed_iov_free_vf_igu_sbs(p_hwfn, p_ptt, vf);
1032 if (vf->b_init) {
1033 vf->b_init = false;
1035 if (IS_LEAD_HWFN(p_hwfn))
1036 p_hwfn->cdev->p_iov_info->num_vfs--;
1039 return 0;
1042 static bool qed_iov_tlv_supported(u16 tlvtype)
1044 return CHANNEL_TLV_NONE < tlvtype && tlvtype < CHANNEL_TLV_MAX;
1047 /* place a given tlv on the tlv buffer, continuing current tlv list */
1048 void *qed_add_tlv(struct qed_hwfn *p_hwfn, u8 **offset, u16 type, u16 length)
1050 struct channel_tlv *tl = (struct channel_tlv *)*offset;
1052 tl->type = type;
1053 tl->length = length;
1055 /* Offset should keep pointing to next TLV (the end of the last) */
1056 *offset += length;
1058 /* Return a pointer to the start of the added tlv */
1059 return *offset - length;
1062 /* list the types and lengths of the tlvs on the buffer */
1063 void qed_dp_tlv_list(struct qed_hwfn *p_hwfn, void *tlvs_list)
1065 u16 i = 1, total_length = 0;
1066 struct channel_tlv *tlv;
1068 do {
1069 tlv = (struct channel_tlv *)((u8 *)tlvs_list + total_length);
1071 /* output tlv */
1072 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
1073 "TLV number %d: type %d, length %d\n",
1074 i, tlv->type, tlv->length);
1076 if (tlv->type == CHANNEL_TLV_LIST_END)
1077 return;
1079 /* Validate entry - protect against malicious VFs */
1080 if (!tlv->length) {
1081 DP_NOTICE(p_hwfn, "TLV of length 0 found\n");
1082 return;
1085 total_length += tlv->length;
1087 if (total_length >= sizeof(struct tlv_buffer_size)) {
1088 DP_NOTICE(p_hwfn, "TLV ==> Buffer overflow\n");
1089 return;
1092 i++;
1093 } while (1);
1096 static void qed_iov_send_response(struct qed_hwfn *p_hwfn,
1097 struct qed_ptt *p_ptt,
1098 struct qed_vf_info *p_vf,
1099 u16 length, u8 status)
1101 struct qed_iov_vf_mbx *mbx = &p_vf->vf_mbx;
1102 struct qed_dmae_params params;
1103 u8 eng_vf_id;
1105 mbx->reply_virt->default_resp.hdr.status = status;
1107 qed_dp_tlv_list(p_hwfn, mbx->reply_virt);
1109 eng_vf_id = p_vf->abs_vf_id;
1111 memset(&params, 0, sizeof(struct qed_dmae_params));
1112 params.flags = QED_DMAE_FLAG_VF_DST;
1113 params.dst_vfid = eng_vf_id;
1115 qed_dmae_host2host(p_hwfn, p_ptt, mbx->reply_phys + sizeof(u64),
1116 mbx->req_virt->first_tlv.reply_address +
1117 sizeof(u64),
1118 (sizeof(union pfvf_tlvs) - sizeof(u64)) / 4,
1119 &params);
1121 qed_dmae_host2host(p_hwfn, p_ptt, mbx->reply_phys,
1122 mbx->req_virt->first_tlv.reply_address,
1123 sizeof(u64) / 4, &params);
1125 REG_WR(p_hwfn,
1126 GTT_BAR0_MAP_REG_USDM_RAM +
1127 USTORM_VF_PF_CHANNEL_READY_OFFSET(eng_vf_id), 1);
1130 static u16 qed_iov_vport_to_tlv(struct qed_hwfn *p_hwfn,
1131 enum qed_iov_vport_update_flag flag)
1133 switch (flag) {
1134 case QED_IOV_VP_UPDATE_ACTIVATE:
1135 return CHANNEL_TLV_VPORT_UPDATE_ACTIVATE;
1136 case QED_IOV_VP_UPDATE_VLAN_STRIP:
1137 return CHANNEL_TLV_VPORT_UPDATE_VLAN_STRIP;
1138 case QED_IOV_VP_UPDATE_TX_SWITCH:
1139 return CHANNEL_TLV_VPORT_UPDATE_TX_SWITCH;
1140 case QED_IOV_VP_UPDATE_MCAST:
1141 return CHANNEL_TLV_VPORT_UPDATE_MCAST;
1142 case QED_IOV_VP_UPDATE_ACCEPT_PARAM:
1143 return CHANNEL_TLV_VPORT_UPDATE_ACCEPT_PARAM;
1144 case QED_IOV_VP_UPDATE_RSS:
1145 return CHANNEL_TLV_VPORT_UPDATE_RSS;
1146 case QED_IOV_VP_UPDATE_ACCEPT_ANY_VLAN:
1147 return CHANNEL_TLV_VPORT_UPDATE_ACCEPT_ANY_VLAN;
1148 case QED_IOV_VP_UPDATE_SGE_TPA:
1149 return CHANNEL_TLV_VPORT_UPDATE_SGE_TPA;
1150 default:
1151 return 0;
1155 static u16 qed_iov_prep_vp_update_resp_tlvs(struct qed_hwfn *p_hwfn,
1156 struct qed_vf_info *p_vf,
1157 struct qed_iov_vf_mbx *p_mbx,
1158 u8 status,
1159 u16 tlvs_mask, u16 tlvs_accepted)
1161 struct pfvf_def_resp_tlv *resp;
1162 u16 size, total_len, i;
1164 memset(p_mbx->reply_virt, 0, sizeof(union pfvf_tlvs));
1165 p_mbx->offset = (u8 *)p_mbx->reply_virt;
1166 size = sizeof(struct pfvf_def_resp_tlv);
1167 total_len = size;
1169 qed_add_tlv(p_hwfn, &p_mbx->offset, CHANNEL_TLV_VPORT_UPDATE, size);
1171 /* Prepare response for all extended tlvs if they are found by PF */
1172 for (i = 0; i < QED_IOV_VP_UPDATE_MAX; i++) {
1173 if (!(tlvs_mask & BIT(i)))
1174 continue;
1176 resp = qed_add_tlv(p_hwfn, &p_mbx->offset,
1177 qed_iov_vport_to_tlv(p_hwfn, i), size);
1179 if (tlvs_accepted & BIT(i))
1180 resp->hdr.status = status;
1181 else
1182 resp->hdr.status = PFVF_STATUS_NOT_SUPPORTED;
1184 DP_VERBOSE(p_hwfn,
1185 QED_MSG_IOV,
1186 "VF[%d] - vport_update response: TLV %d, status %02x\n",
1187 p_vf->relative_vf_id,
1188 qed_iov_vport_to_tlv(p_hwfn, i), resp->hdr.status);
1190 total_len += size;
1193 qed_add_tlv(p_hwfn, &p_mbx->offset, CHANNEL_TLV_LIST_END,
1194 sizeof(struct channel_list_end_tlv));
1196 return total_len;
1199 static void qed_iov_prepare_resp(struct qed_hwfn *p_hwfn,
1200 struct qed_ptt *p_ptt,
1201 struct qed_vf_info *vf_info,
1202 u16 type, u16 length, u8 status)
1204 struct qed_iov_vf_mbx *mbx = &vf_info->vf_mbx;
1206 mbx->offset = (u8 *)mbx->reply_virt;
1208 qed_add_tlv(p_hwfn, &mbx->offset, type, length);
1209 qed_add_tlv(p_hwfn, &mbx->offset, CHANNEL_TLV_LIST_END,
1210 sizeof(struct channel_list_end_tlv));
1212 qed_iov_send_response(p_hwfn, p_ptt, vf_info, length, status);
1215 static struct
1216 qed_public_vf_info *qed_iov_get_public_vf_info(struct qed_hwfn *p_hwfn,
1217 u16 relative_vf_id,
1218 bool b_enabled_only)
1220 struct qed_vf_info *vf = NULL;
1222 vf = qed_iov_get_vf_info(p_hwfn, relative_vf_id, b_enabled_only);
1223 if (!vf)
1224 return NULL;
1226 return &vf->p_vf_info;
1229 static void qed_iov_clean_vf(struct qed_hwfn *p_hwfn, u8 vfid)
1231 struct qed_public_vf_info *vf_info;
1233 vf_info = qed_iov_get_public_vf_info(p_hwfn, vfid, false);
1235 if (!vf_info)
1236 return;
1238 /* Clear the VF mac */
1239 eth_zero_addr(vf_info->mac);
1241 vf_info->rx_accept_mode = 0;
1242 vf_info->tx_accept_mode = 0;
1245 static void qed_iov_vf_cleanup(struct qed_hwfn *p_hwfn,
1246 struct qed_vf_info *p_vf)
1248 u32 i;
1250 p_vf->vf_bulletin = 0;
1251 p_vf->vport_instance = 0;
1252 p_vf->configured_features = 0;
1254 /* If VF previously requested less resources, go back to default */
1255 p_vf->num_rxqs = p_vf->num_sbs;
1256 p_vf->num_txqs = p_vf->num_sbs;
1258 p_vf->num_active_rxqs = 0;
1260 for (i = 0; i < QED_MAX_VF_CHAINS_PER_PF; i++) {
1261 struct qed_vf_q_info *p_queue = &p_vf->vf_queues[i];
1263 if (p_queue->p_rx_cid) {
1264 qed_eth_queue_cid_release(p_hwfn, p_queue->p_rx_cid);
1265 p_queue->p_rx_cid = NULL;
1268 if (p_queue->p_tx_cid) {
1269 qed_eth_queue_cid_release(p_hwfn, p_queue->p_tx_cid);
1270 p_queue->p_tx_cid = NULL;
1274 memset(&p_vf->shadow_config, 0, sizeof(p_vf->shadow_config));
1275 memset(&p_vf->acquire, 0, sizeof(p_vf->acquire));
1276 qed_iov_clean_vf(p_hwfn, p_vf->relative_vf_id);
1279 static u8 qed_iov_vf_mbx_acquire_resc(struct qed_hwfn *p_hwfn,
1280 struct qed_ptt *p_ptt,
1281 struct qed_vf_info *p_vf,
1282 struct vf_pf_resc_request *p_req,
1283 struct pf_vf_resc *p_resp)
1285 int i;
1287 /* Queue related information */
1288 p_resp->num_rxqs = p_vf->num_rxqs;
1289 p_resp->num_txqs = p_vf->num_txqs;
1290 p_resp->num_sbs = p_vf->num_sbs;
1292 for (i = 0; i < p_resp->num_sbs; i++) {
1293 p_resp->hw_sbs[i].hw_sb_id = p_vf->igu_sbs[i];
1294 p_resp->hw_sbs[i].sb_qid = 0;
1297 /* These fields are filled for backward compatibility.
1298 * Unused by modern vfs.
1300 for (i = 0; i < p_resp->num_rxqs; i++) {
1301 qed_fw_l2_queue(p_hwfn, p_vf->vf_queues[i].fw_rx_qid,
1302 (u16 *)&p_resp->hw_qid[i]);
1303 p_resp->cid[i] = p_vf->vf_queues[i].fw_cid;
1306 /* Filter related information */
1307 p_resp->num_mac_filters = min_t(u8, p_vf->num_mac_filters,
1308 p_req->num_mac_filters);
1309 p_resp->num_vlan_filters = min_t(u8, p_vf->num_vlan_filters,
1310 p_req->num_vlan_filters);
1312 /* This isn't really needed/enforced, but some legacy VFs might depend
1313 * on the correct filling of this field.
1315 p_resp->num_mc_filters = QED_MAX_MC_ADDRS;
1317 /* Validate sufficient resources for VF */
1318 if (p_resp->num_rxqs < p_req->num_rxqs ||
1319 p_resp->num_txqs < p_req->num_txqs ||
1320 p_resp->num_sbs < p_req->num_sbs ||
1321 p_resp->num_mac_filters < p_req->num_mac_filters ||
1322 p_resp->num_vlan_filters < p_req->num_vlan_filters ||
1323 p_resp->num_mc_filters < p_req->num_mc_filters) {
1324 DP_VERBOSE(p_hwfn,
1325 QED_MSG_IOV,
1326 "VF[%d] - Insufficient resources: rxq [%02x/%02x] txq [%02x/%02x] sbs [%02x/%02x] mac [%02x/%02x] vlan [%02x/%02x] mc [%02x/%02x]\n",
1327 p_vf->abs_vf_id,
1328 p_req->num_rxqs,
1329 p_resp->num_rxqs,
1330 p_req->num_rxqs,
1331 p_resp->num_txqs,
1332 p_req->num_sbs,
1333 p_resp->num_sbs,
1334 p_req->num_mac_filters,
1335 p_resp->num_mac_filters,
1336 p_req->num_vlan_filters,
1337 p_resp->num_vlan_filters,
1338 p_req->num_mc_filters, p_resp->num_mc_filters);
1340 /* Some legacy OSes are incapable of correctly handling this
1341 * failure.
1343 if ((p_vf->acquire.vfdev_info.eth_fp_hsi_minor ==
1344 ETH_HSI_VER_NO_PKT_LEN_TUNN) &&
1345 (p_vf->acquire.vfdev_info.os_type ==
1346 VFPF_ACQUIRE_OS_WINDOWS))
1347 return PFVF_STATUS_SUCCESS;
1349 return PFVF_STATUS_NO_RESOURCE;
1352 return PFVF_STATUS_SUCCESS;
1355 static void qed_iov_vf_mbx_acquire_stats(struct qed_hwfn *p_hwfn,
1356 struct pfvf_stats_info *p_stats)
1358 p_stats->mstats.address = PXP_VF_BAR0_START_MSDM_ZONE_B +
1359 offsetof(struct mstorm_vf_zone,
1360 non_trigger.eth_queue_stat);
1361 p_stats->mstats.len = sizeof(struct eth_mstorm_per_queue_stat);
1362 p_stats->ustats.address = PXP_VF_BAR0_START_USDM_ZONE_B +
1363 offsetof(struct ustorm_vf_zone,
1364 non_trigger.eth_queue_stat);
1365 p_stats->ustats.len = sizeof(struct eth_ustorm_per_queue_stat);
1366 p_stats->pstats.address = PXP_VF_BAR0_START_PSDM_ZONE_B +
1367 offsetof(struct pstorm_vf_zone,
1368 non_trigger.eth_queue_stat);
1369 p_stats->pstats.len = sizeof(struct eth_pstorm_per_queue_stat);
1370 p_stats->tstats.address = 0;
1371 p_stats->tstats.len = 0;
1374 static void qed_iov_vf_mbx_acquire(struct qed_hwfn *p_hwfn,
1375 struct qed_ptt *p_ptt,
1376 struct qed_vf_info *vf)
1378 struct qed_iov_vf_mbx *mbx = &vf->vf_mbx;
1379 struct pfvf_acquire_resp_tlv *resp = &mbx->reply_virt->acquire_resp;
1380 struct pf_vf_pfdev_info *pfdev_info = &resp->pfdev_info;
1381 struct vfpf_acquire_tlv *req = &mbx->req_virt->acquire;
1382 u8 vfpf_status = PFVF_STATUS_NOT_SUPPORTED;
1383 struct pf_vf_resc *resc = &resp->resc;
1384 int rc;
1386 memset(resp, 0, sizeof(*resp));
1388 /* Write the PF version so that VF would know which version
1389 * is supported - might be later overriden. This guarantees that
1390 * VF could recognize legacy PF based on lack of versions in reply.
1392 pfdev_info->major_fp_hsi = ETH_HSI_VER_MAJOR;
1393 pfdev_info->minor_fp_hsi = ETH_HSI_VER_MINOR;
1395 if (vf->state != VF_FREE && vf->state != VF_STOPPED) {
1396 DP_VERBOSE(p_hwfn,
1397 QED_MSG_IOV,
1398 "VF[%d] sent ACQUIRE but is already in state %d - fail request\n",
1399 vf->abs_vf_id, vf->state);
1400 goto out;
1403 /* Validate FW compatibility */
1404 if (req->vfdev_info.eth_fp_hsi_major != ETH_HSI_VER_MAJOR) {
1405 if (req->vfdev_info.capabilities &
1406 VFPF_ACQUIRE_CAP_PRE_FP_HSI) {
1407 struct vf_pf_vfdev_info *p_vfdev = &req->vfdev_info;
1409 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
1410 "VF[%d] is pre-fastpath HSI\n",
1411 vf->abs_vf_id);
1412 p_vfdev->eth_fp_hsi_major = ETH_HSI_VER_MAJOR;
1413 p_vfdev->eth_fp_hsi_minor = ETH_HSI_VER_NO_PKT_LEN_TUNN;
1414 } else {
1415 DP_INFO(p_hwfn,
1416 "VF[%d] needs fastpath HSI %02x.%02x, which is incompatible with loaded FW's faspath HSI %02x.%02x\n",
1417 vf->abs_vf_id,
1418 req->vfdev_info.eth_fp_hsi_major,
1419 req->vfdev_info.eth_fp_hsi_minor,
1420 ETH_HSI_VER_MAJOR, ETH_HSI_VER_MINOR);
1422 goto out;
1426 /* On 100g PFs, prevent old VFs from loading */
1427 if ((p_hwfn->cdev->num_hwfns > 1) &&
1428 !(req->vfdev_info.capabilities & VFPF_ACQUIRE_CAP_100G)) {
1429 DP_INFO(p_hwfn,
1430 "VF[%d] is running an old driver that doesn't support 100g\n",
1431 vf->abs_vf_id);
1432 goto out;
1435 /* Store the acquire message */
1436 memcpy(&vf->acquire, req, sizeof(vf->acquire));
1438 vf->opaque_fid = req->vfdev_info.opaque_fid;
1440 vf->vf_bulletin = req->bulletin_addr;
1441 vf->bulletin.size = (vf->bulletin.size < req->bulletin_size) ?
1442 vf->bulletin.size : req->bulletin_size;
1444 /* fill in pfdev info */
1445 pfdev_info->chip_num = p_hwfn->cdev->chip_num;
1446 pfdev_info->db_size = 0;
1447 pfdev_info->indices_per_sb = PIS_PER_SB;
1449 pfdev_info->capabilities = PFVF_ACQUIRE_CAP_DEFAULT_UNTAGGED |
1450 PFVF_ACQUIRE_CAP_POST_FW_OVERRIDE;
1451 if (p_hwfn->cdev->num_hwfns > 1)
1452 pfdev_info->capabilities |= PFVF_ACQUIRE_CAP_100G;
1454 qed_iov_vf_mbx_acquire_stats(p_hwfn, &pfdev_info->stats_info);
1456 memcpy(pfdev_info->port_mac, p_hwfn->hw_info.hw_mac_addr, ETH_ALEN);
1458 pfdev_info->fw_major = FW_MAJOR_VERSION;
1459 pfdev_info->fw_minor = FW_MINOR_VERSION;
1460 pfdev_info->fw_rev = FW_REVISION_VERSION;
1461 pfdev_info->fw_eng = FW_ENGINEERING_VERSION;
1463 /* Incorrect when legacy, but doesn't matter as legacy isn't reading
1464 * this field.
1466 pfdev_info->minor_fp_hsi = min_t(u8, ETH_HSI_VER_MINOR,
1467 req->vfdev_info.eth_fp_hsi_minor);
1468 pfdev_info->os_type = VFPF_ACQUIRE_OS_LINUX;
1469 qed_mcp_get_mfw_ver(p_hwfn, p_ptt, &pfdev_info->mfw_ver, NULL);
1471 pfdev_info->dev_type = p_hwfn->cdev->type;
1472 pfdev_info->chip_rev = p_hwfn->cdev->chip_rev;
1474 /* Fill resources available to VF; Make sure there are enough to
1475 * satisfy the VF's request.
1477 vfpf_status = qed_iov_vf_mbx_acquire_resc(p_hwfn, p_ptt, vf,
1478 &req->resc_request, resc);
1479 if (vfpf_status != PFVF_STATUS_SUCCESS)
1480 goto out;
1482 /* Start the VF in FW */
1483 rc = qed_sp_vf_start(p_hwfn, vf);
1484 if (rc) {
1485 DP_NOTICE(p_hwfn, "Failed to start VF[%02x]\n", vf->abs_vf_id);
1486 vfpf_status = PFVF_STATUS_FAILURE;
1487 goto out;
1490 /* Fill agreed size of bulletin board in response */
1491 resp->bulletin_size = vf->bulletin.size;
1492 qed_iov_post_vf_bulletin(p_hwfn, vf->relative_vf_id, p_ptt);
1494 DP_VERBOSE(p_hwfn,
1495 QED_MSG_IOV,
1496 "VF[%d] ACQUIRE_RESPONSE: pfdev_info- chip_num=0x%x, db_size=%d, idx_per_sb=%d, pf_cap=0x%llx\n"
1497 "resources- n_rxq-%d, n_txq-%d, n_sbs-%d, n_macs-%d, n_vlans-%d\n",
1498 vf->abs_vf_id,
1499 resp->pfdev_info.chip_num,
1500 resp->pfdev_info.db_size,
1501 resp->pfdev_info.indices_per_sb,
1502 resp->pfdev_info.capabilities,
1503 resc->num_rxqs,
1504 resc->num_txqs,
1505 resc->num_sbs,
1506 resc->num_mac_filters,
1507 resc->num_vlan_filters);
1508 vf->state = VF_ACQUIRED;
1510 /* Prepare Response */
1511 out:
1512 qed_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_ACQUIRE,
1513 sizeof(struct pfvf_acquire_resp_tlv), vfpf_status);
1516 static int __qed_iov_spoofchk_set(struct qed_hwfn *p_hwfn,
1517 struct qed_vf_info *p_vf, bool val)
1519 struct qed_sp_vport_update_params params;
1520 int rc;
1522 if (val == p_vf->spoof_chk) {
1523 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
1524 "Spoofchk value[%d] is already configured\n", val);
1525 return 0;
1528 memset(&params, 0, sizeof(struct qed_sp_vport_update_params));
1529 params.opaque_fid = p_vf->opaque_fid;
1530 params.vport_id = p_vf->vport_id;
1531 params.update_anti_spoofing_en_flg = 1;
1532 params.anti_spoofing_en = val;
1534 rc = qed_sp_vport_update(p_hwfn, &params, QED_SPQ_MODE_EBLOCK, NULL);
1535 if (!rc) {
1536 p_vf->spoof_chk = val;
1537 p_vf->req_spoofchk_val = p_vf->spoof_chk;
1538 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
1539 "Spoofchk val[%d] configured\n", val);
1540 } else {
1541 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
1542 "Spoofchk configuration[val:%d] failed for VF[%d]\n",
1543 val, p_vf->relative_vf_id);
1546 return rc;
1549 static int qed_iov_reconfigure_unicast_vlan(struct qed_hwfn *p_hwfn,
1550 struct qed_vf_info *p_vf)
1552 struct qed_filter_ucast filter;
1553 int rc = 0;
1554 int i;
1556 memset(&filter, 0, sizeof(filter));
1557 filter.is_rx_filter = 1;
1558 filter.is_tx_filter = 1;
1559 filter.vport_to_add_to = p_vf->vport_id;
1560 filter.opcode = QED_FILTER_ADD;
1562 /* Reconfigure vlans */
1563 for (i = 0; i < QED_ETH_VF_NUM_VLAN_FILTERS + 1; i++) {
1564 if (!p_vf->shadow_config.vlans[i].used)
1565 continue;
1567 filter.type = QED_FILTER_VLAN;
1568 filter.vlan = p_vf->shadow_config.vlans[i].vid;
1569 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
1570 "Reconfiguring VLAN [0x%04x] for VF [%04x]\n",
1571 filter.vlan, p_vf->relative_vf_id);
1572 rc = qed_sp_eth_filter_ucast(p_hwfn, p_vf->opaque_fid,
1573 &filter, QED_SPQ_MODE_CB, NULL);
1574 if (rc) {
1575 DP_NOTICE(p_hwfn,
1576 "Failed to configure VLAN [%04x] to VF [%04x]\n",
1577 filter.vlan, p_vf->relative_vf_id);
1578 break;
1582 return rc;
1585 static int
1586 qed_iov_reconfigure_unicast_shadow(struct qed_hwfn *p_hwfn,
1587 struct qed_vf_info *p_vf, u64 events)
1589 int rc = 0;
1591 if ((events & BIT(VLAN_ADDR_FORCED)) &&
1592 !(p_vf->configured_features & (1 << VLAN_ADDR_FORCED)))
1593 rc = qed_iov_reconfigure_unicast_vlan(p_hwfn, p_vf);
1595 return rc;
1598 static int qed_iov_configure_vport_forced(struct qed_hwfn *p_hwfn,
1599 struct qed_vf_info *p_vf, u64 events)
1601 int rc = 0;
1602 struct qed_filter_ucast filter;
1604 if (!p_vf->vport_instance)
1605 return -EINVAL;
1607 if (events & BIT(MAC_ADDR_FORCED)) {
1608 /* Since there's no way [currently] of removing the MAC,
1609 * we can always assume this means we need to force it.
1611 memset(&filter, 0, sizeof(filter));
1612 filter.type = QED_FILTER_MAC;
1613 filter.opcode = QED_FILTER_REPLACE;
1614 filter.is_rx_filter = 1;
1615 filter.is_tx_filter = 1;
1616 filter.vport_to_add_to = p_vf->vport_id;
1617 ether_addr_copy(filter.mac, p_vf->bulletin.p_virt->mac);
1619 rc = qed_sp_eth_filter_ucast(p_hwfn, p_vf->opaque_fid,
1620 &filter, QED_SPQ_MODE_CB, NULL);
1621 if (rc) {
1622 DP_NOTICE(p_hwfn,
1623 "PF failed to configure MAC for VF\n");
1624 return rc;
1627 p_vf->configured_features |= 1 << MAC_ADDR_FORCED;
1630 if (events & BIT(VLAN_ADDR_FORCED)) {
1631 struct qed_sp_vport_update_params vport_update;
1632 u8 removal;
1633 int i;
1635 memset(&filter, 0, sizeof(filter));
1636 filter.type = QED_FILTER_VLAN;
1637 filter.is_rx_filter = 1;
1638 filter.is_tx_filter = 1;
1639 filter.vport_to_add_to = p_vf->vport_id;
1640 filter.vlan = p_vf->bulletin.p_virt->pvid;
1641 filter.opcode = filter.vlan ? QED_FILTER_REPLACE :
1642 QED_FILTER_FLUSH;
1644 /* Send the ramrod */
1645 rc = qed_sp_eth_filter_ucast(p_hwfn, p_vf->opaque_fid,
1646 &filter, QED_SPQ_MODE_CB, NULL);
1647 if (rc) {
1648 DP_NOTICE(p_hwfn,
1649 "PF failed to configure VLAN for VF\n");
1650 return rc;
1653 /* Update the default-vlan & silent vlan stripping */
1654 memset(&vport_update, 0, sizeof(vport_update));
1655 vport_update.opaque_fid = p_vf->opaque_fid;
1656 vport_update.vport_id = p_vf->vport_id;
1657 vport_update.update_default_vlan_enable_flg = 1;
1658 vport_update.default_vlan_enable_flg = filter.vlan ? 1 : 0;
1659 vport_update.update_default_vlan_flg = 1;
1660 vport_update.default_vlan = filter.vlan;
1662 vport_update.update_inner_vlan_removal_flg = 1;
1663 removal = filter.vlan ? 1
1664 : p_vf->shadow_config.inner_vlan_removal;
1665 vport_update.inner_vlan_removal_flg = removal;
1666 vport_update.silent_vlan_removal_flg = filter.vlan ? 1 : 0;
1667 rc = qed_sp_vport_update(p_hwfn,
1668 &vport_update,
1669 QED_SPQ_MODE_EBLOCK, NULL);
1670 if (rc) {
1671 DP_NOTICE(p_hwfn,
1672 "PF failed to configure VF vport for vlan\n");
1673 return rc;
1676 /* Update all the Rx queues */
1677 for (i = 0; i < QED_MAX_VF_CHAINS_PER_PF; i++) {
1678 struct qed_queue_cid *p_cid;
1680 p_cid = p_vf->vf_queues[i].p_rx_cid;
1681 if (!p_cid)
1682 continue;
1684 rc = qed_sp_eth_rx_queues_update(p_hwfn,
1685 (void **)&p_cid,
1686 1, 0, 1,
1687 QED_SPQ_MODE_EBLOCK,
1688 NULL);
1689 if (rc) {
1690 DP_NOTICE(p_hwfn,
1691 "Failed to send Rx update fo queue[0x%04x]\n",
1692 p_cid->rel.queue_id);
1693 return rc;
1697 if (filter.vlan)
1698 p_vf->configured_features |= 1 << VLAN_ADDR_FORCED;
1699 else
1700 p_vf->configured_features &= ~BIT(VLAN_ADDR_FORCED);
1703 /* If forced features are terminated, we need to configure the shadow
1704 * configuration back again.
1706 if (events)
1707 qed_iov_reconfigure_unicast_shadow(p_hwfn, p_vf, events);
1709 return rc;
1712 static void qed_iov_vf_mbx_start_vport(struct qed_hwfn *p_hwfn,
1713 struct qed_ptt *p_ptt,
1714 struct qed_vf_info *vf)
1716 struct qed_sp_vport_start_params params = { 0 };
1717 struct qed_iov_vf_mbx *mbx = &vf->vf_mbx;
1718 struct vfpf_vport_start_tlv *start;
1719 u8 status = PFVF_STATUS_SUCCESS;
1720 struct qed_vf_info *vf_info;
1721 u64 *p_bitmap;
1722 int sb_id;
1723 int rc;
1725 vf_info = qed_iov_get_vf_info(p_hwfn, (u16) vf->relative_vf_id, true);
1726 if (!vf_info) {
1727 DP_NOTICE(p_hwfn->cdev,
1728 "Failed to get VF info, invalid vfid [%d]\n",
1729 vf->relative_vf_id);
1730 return;
1733 vf->state = VF_ENABLED;
1734 start = &mbx->req_virt->start_vport;
1736 /* Initialize Status block in CAU */
1737 for (sb_id = 0; sb_id < vf->num_sbs; sb_id++) {
1738 if (!start->sb_addr[sb_id]) {
1739 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
1740 "VF[%d] did not fill the address of SB %d\n",
1741 vf->relative_vf_id, sb_id);
1742 break;
1745 qed_int_cau_conf_sb(p_hwfn, p_ptt,
1746 start->sb_addr[sb_id],
1747 vf->igu_sbs[sb_id], vf->abs_vf_id, 1);
1749 qed_iov_enable_vf_traffic(p_hwfn, p_ptt, vf);
1751 vf->mtu = start->mtu;
1752 vf->shadow_config.inner_vlan_removal = start->inner_vlan_removal;
1754 /* Take into consideration configuration forced by hypervisor;
1755 * If none is configured, use the supplied VF values [for old
1756 * vfs that would still be fine, since they passed '0' as padding].
1758 p_bitmap = &vf_info->bulletin.p_virt->valid_bitmap;
1759 if (!(*p_bitmap & BIT(VFPF_BULLETIN_UNTAGGED_DEFAULT_FORCED))) {
1760 u8 vf_req = start->only_untagged;
1762 vf_info->bulletin.p_virt->default_only_untagged = vf_req;
1763 *p_bitmap |= 1 << VFPF_BULLETIN_UNTAGGED_DEFAULT;
1766 params.tpa_mode = start->tpa_mode;
1767 params.remove_inner_vlan = start->inner_vlan_removal;
1768 params.tx_switching = true;
1770 params.only_untagged = vf_info->bulletin.p_virt->default_only_untagged;
1771 params.drop_ttl0 = false;
1772 params.concrete_fid = vf->concrete_fid;
1773 params.opaque_fid = vf->opaque_fid;
1774 params.vport_id = vf->vport_id;
1775 params.max_buffers_per_cqe = start->max_buffers_per_cqe;
1776 params.mtu = vf->mtu;
1777 params.check_mac = true;
1779 rc = qed_sp_eth_vport_start(p_hwfn, &params);
1780 if (rc) {
1781 DP_ERR(p_hwfn,
1782 "qed_iov_vf_mbx_start_vport returned error %d\n", rc);
1783 status = PFVF_STATUS_FAILURE;
1784 } else {
1785 vf->vport_instance++;
1787 /* Force configuration if needed on the newly opened vport */
1788 qed_iov_configure_vport_forced(p_hwfn, vf, *p_bitmap);
1790 __qed_iov_spoofchk_set(p_hwfn, vf, vf->req_spoofchk_val);
1792 qed_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_VPORT_START,
1793 sizeof(struct pfvf_def_resp_tlv), status);
1796 static void qed_iov_vf_mbx_stop_vport(struct qed_hwfn *p_hwfn,
1797 struct qed_ptt *p_ptt,
1798 struct qed_vf_info *vf)
1800 u8 status = PFVF_STATUS_SUCCESS;
1801 int rc;
1803 vf->vport_instance--;
1804 vf->spoof_chk = false;
1806 rc = qed_sp_vport_stop(p_hwfn, vf->opaque_fid, vf->vport_id);
1807 if (rc) {
1808 DP_ERR(p_hwfn, "qed_iov_vf_mbx_stop_vport returned error %d\n",
1809 rc);
1810 status = PFVF_STATUS_FAILURE;
1813 /* Forget the configuration on the vport */
1814 vf->configured_features = 0;
1815 memset(&vf->shadow_config, 0, sizeof(vf->shadow_config));
1817 qed_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_VPORT_TEARDOWN,
1818 sizeof(struct pfvf_def_resp_tlv), status);
1821 static void qed_iov_vf_mbx_start_rxq_resp(struct qed_hwfn *p_hwfn,
1822 struct qed_ptt *p_ptt,
1823 struct qed_vf_info *vf,
1824 u8 status, bool b_legacy)
1826 struct qed_iov_vf_mbx *mbx = &vf->vf_mbx;
1827 struct pfvf_start_queue_resp_tlv *p_tlv;
1828 struct vfpf_start_rxq_tlv *req;
1829 u16 length;
1831 mbx->offset = (u8 *)mbx->reply_virt;
1833 /* Taking a bigger struct instead of adding a TLV to list was a
1834 * mistake, but one which we're now stuck with, as some older
1835 * clients assume the size of the previous response.
1837 if (!b_legacy)
1838 length = sizeof(*p_tlv);
1839 else
1840 length = sizeof(struct pfvf_def_resp_tlv);
1842 p_tlv = qed_add_tlv(p_hwfn, &mbx->offset, CHANNEL_TLV_START_RXQ,
1843 length);
1844 qed_add_tlv(p_hwfn, &mbx->offset, CHANNEL_TLV_LIST_END,
1845 sizeof(struct channel_list_end_tlv));
1847 /* Update the TLV with the response */
1848 if ((status == PFVF_STATUS_SUCCESS) && !b_legacy) {
1849 req = &mbx->req_virt->start_rxq;
1850 p_tlv->offset = PXP_VF_BAR0_START_MSDM_ZONE_B +
1851 offsetof(struct mstorm_vf_zone,
1852 non_trigger.eth_rx_queue_producers) +
1853 sizeof(struct eth_rx_prod_data) * req->rx_qid;
1856 qed_iov_send_response(p_hwfn, p_ptt, vf, length, status);
1859 static void qed_iov_vf_mbx_start_rxq(struct qed_hwfn *p_hwfn,
1860 struct qed_ptt *p_ptt,
1861 struct qed_vf_info *vf)
1863 struct qed_queue_start_common_params params;
1864 struct qed_iov_vf_mbx *mbx = &vf->vf_mbx;
1865 u8 status = PFVF_STATUS_NO_RESOURCE;
1866 struct qed_vf_q_info *p_queue;
1867 struct vfpf_start_rxq_tlv *req;
1868 bool b_legacy_vf = false;
1869 int rc;
1871 req = &mbx->req_virt->start_rxq;
1873 if (!qed_iov_validate_rxq(p_hwfn, vf, req->rx_qid) ||
1874 !qed_iov_validate_sb(p_hwfn, vf, req->hw_sb))
1875 goto out;
1877 /* Acquire a new queue-cid */
1878 p_queue = &vf->vf_queues[req->rx_qid];
1880 memset(&params, 0, sizeof(params));
1881 params.queue_id = p_queue->fw_rx_qid;
1882 params.vport_id = vf->vport_id;
1883 params.stats_id = vf->abs_vf_id + 0x10;
1884 params.sb = req->hw_sb;
1885 params.sb_idx = req->sb_index;
1887 p_queue->p_rx_cid = _qed_eth_queue_to_cid(p_hwfn,
1888 vf->opaque_fid,
1889 p_queue->fw_cid,
1890 req->rx_qid, &params);
1891 if (!p_queue->p_rx_cid)
1892 goto out;
1894 /* Legacy VFs have their Producers in a different location, which they
1895 * calculate on their own and clean the producer prior to this.
1897 if (vf->acquire.vfdev_info.eth_fp_hsi_minor ==
1898 ETH_HSI_VER_NO_PKT_LEN_TUNN) {
1899 b_legacy_vf = true;
1900 } else {
1901 REG_WR(p_hwfn,
1902 GTT_BAR0_MAP_REG_MSDM_RAM +
1903 MSTORM_ETH_VF_PRODS_OFFSET(vf->abs_vf_id, req->rx_qid),
1906 p_queue->p_rx_cid->b_legacy_vf = b_legacy_vf;
1908 rc = qed_eth_rxq_start_ramrod(p_hwfn,
1909 p_queue->p_rx_cid,
1910 req->bd_max_bytes,
1911 req->rxq_addr,
1912 req->cqe_pbl_addr, req->cqe_pbl_size);
1913 if (rc) {
1914 status = PFVF_STATUS_FAILURE;
1915 qed_eth_queue_cid_release(p_hwfn, p_queue->p_rx_cid);
1916 p_queue->p_rx_cid = NULL;
1917 } else {
1918 status = PFVF_STATUS_SUCCESS;
1919 vf->num_active_rxqs++;
1922 out:
1923 qed_iov_vf_mbx_start_rxq_resp(p_hwfn, p_ptt, vf, status, b_legacy_vf);
1926 static void qed_iov_vf_mbx_start_txq_resp(struct qed_hwfn *p_hwfn,
1927 struct qed_ptt *p_ptt,
1928 struct qed_vf_info *p_vf, u8 status)
1930 struct qed_iov_vf_mbx *mbx = &p_vf->vf_mbx;
1931 struct pfvf_start_queue_resp_tlv *p_tlv;
1932 bool b_legacy = false;
1933 u16 length;
1935 mbx->offset = (u8 *)mbx->reply_virt;
1937 /* Taking a bigger struct instead of adding a TLV to list was a
1938 * mistake, but one which we're now stuck with, as some older
1939 * clients assume the size of the previous response.
1941 if (p_vf->acquire.vfdev_info.eth_fp_hsi_minor ==
1942 ETH_HSI_VER_NO_PKT_LEN_TUNN)
1943 b_legacy = true;
1945 if (!b_legacy)
1946 length = sizeof(*p_tlv);
1947 else
1948 length = sizeof(struct pfvf_def_resp_tlv);
1950 p_tlv = qed_add_tlv(p_hwfn, &mbx->offset, CHANNEL_TLV_START_TXQ,
1951 length);
1952 qed_add_tlv(p_hwfn, &mbx->offset, CHANNEL_TLV_LIST_END,
1953 sizeof(struct channel_list_end_tlv));
1955 /* Update the TLV with the response */
1956 if ((status == PFVF_STATUS_SUCCESS) && !b_legacy) {
1957 u16 qid = mbx->req_virt->start_txq.tx_qid;
1959 p_tlv->offset = qed_db_addr_vf(p_vf->vf_queues[qid].fw_cid,
1960 DQ_DEMS_LEGACY);
1963 qed_iov_send_response(p_hwfn, p_ptt, p_vf, length, status);
1966 static void qed_iov_vf_mbx_start_txq(struct qed_hwfn *p_hwfn,
1967 struct qed_ptt *p_ptt,
1968 struct qed_vf_info *vf)
1970 struct qed_queue_start_common_params params;
1971 struct qed_iov_vf_mbx *mbx = &vf->vf_mbx;
1972 u8 status = PFVF_STATUS_NO_RESOURCE;
1973 union qed_qm_pq_params pq_params;
1974 struct vfpf_start_txq_tlv *req;
1975 struct qed_vf_q_info *p_queue;
1976 int rc;
1977 u16 pq;
1979 /* Prepare the parameters which would choose the right PQ */
1980 memset(&pq_params, 0, sizeof(pq_params));
1981 pq_params.eth.is_vf = 1;
1982 pq_params.eth.vf_id = vf->relative_vf_id;
1984 memset(&params, 0, sizeof(params));
1985 req = &mbx->req_virt->start_txq;
1987 if (!qed_iov_validate_txq(p_hwfn, vf, req->tx_qid) ||
1988 !qed_iov_validate_sb(p_hwfn, vf, req->hw_sb))
1989 goto out;
1991 /* Acquire a new queue-cid */
1992 p_queue = &vf->vf_queues[req->tx_qid];
1994 params.queue_id = p_queue->fw_tx_qid;
1995 params.vport_id = vf->vport_id;
1996 params.stats_id = vf->abs_vf_id + 0x10;
1997 params.sb = req->hw_sb;
1998 params.sb_idx = req->sb_index;
2000 p_queue->p_tx_cid = _qed_eth_queue_to_cid(p_hwfn,
2001 vf->opaque_fid,
2002 p_queue->fw_cid,
2003 req->tx_qid, &params);
2004 if (!p_queue->p_tx_cid)
2005 goto out;
2007 pq = qed_get_qm_pq(p_hwfn, PROTOCOLID_ETH, &pq_params);
2008 rc = qed_eth_txq_start_ramrod(p_hwfn, p_queue->p_tx_cid,
2009 req->pbl_addr, req->pbl_size, pq);
2010 if (rc) {
2011 status = PFVF_STATUS_FAILURE;
2012 qed_eth_queue_cid_release(p_hwfn, p_queue->p_tx_cid);
2013 p_queue->p_tx_cid = NULL;
2014 } else {
2015 status = PFVF_STATUS_SUCCESS;
2018 out:
2019 qed_iov_vf_mbx_start_txq_resp(p_hwfn, p_ptt, vf, status);
2022 static int qed_iov_vf_stop_rxqs(struct qed_hwfn *p_hwfn,
2023 struct qed_vf_info *vf,
2024 u16 rxq_id, u8 num_rxqs, bool cqe_completion)
2026 struct qed_vf_q_info *p_queue;
2027 int rc = 0;
2028 int qid;
2030 if (rxq_id + num_rxqs > ARRAY_SIZE(vf->vf_queues))
2031 return -EINVAL;
2033 for (qid = rxq_id; qid < rxq_id + num_rxqs; qid++) {
2034 p_queue = &vf->vf_queues[qid];
2036 if (!p_queue->p_rx_cid)
2037 continue;
2039 rc = qed_eth_rx_queue_stop(p_hwfn,
2040 p_queue->p_rx_cid,
2041 false, cqe_completion);
2042 if (rc)
2043 return rc;
2045 vf->vf_queues[qid].p_rx_cid = NULL;
2046 vf->num_active_rxqs--;
2049 return rc;
2052 static int qed_iov_vf_stop_txqs(struct qed_hwfn *p_hwfn,
2053 struct qed_vf_info *vf, u16 txq_id, u8 num_txqs)
2055 int rc = 0;
2056 struct qed_vf_q_info *p_queue;
2057 int qid;
2059 if (txq_id + num_txqs > ARRAY_SIZE(vf->vf_queues))
2060 return -EINVAL;
2062 for (qid = txq_id; qid < txq_id + num_txqs; qid++) {
2063 p_queue = &vf->vf_queues[qid];
2064 if (!p_queue->p_tx_cid)
2065 continue;
2067 rc = qed_eth_tx_queue_stop(p_hwfn, p_queue->p_tx_cid);
2068 if (rc)
2069 return rc;
2071 p_queue->p_tx_cid = NULL;
2074 return rc;
2077 static void qed_iov_vf_mbx_stop_rxqs(struct qed_hwfn *p_hwfn,
2078 struct qed_ptt *p_ptt,
2079 struct qed_vf_info *vf)
2081 u16 length = sizeof(struct pfvf_def_resp_tlv);
2082 struct qed_iov_vf_mbx *mbx = &vf->vf_mbx;
2083 u8 status = PFVF_STATUS_SUCCESS;
2084 struct vfpf_stop_rxqs_tlv *req;
2085 int rc;
2087 /* We give the option of starting from qid != 0, in this case we
2088 * need to make sure that qid + num_qs doesn't exceed the actual
2089 * amount of queues that exist.
2091 req = &mbx->req_virt->stop_rxqs;
2092 rc = qed_iov_vf_stop_rxqs(p_hwfn, vf, req->rx_qid,
2093 req->num_rxqs, req->cqe_completion);
2094 if (rc)
2095 status = PFVF_STATUS_FAILURE;
2097 qed_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_STOP_RXQS,
2098 length, status);
2101 static void qed_iov_vf_mbx_stop_txqs(struct qed_hwfn *p_hwfn,
2102 struct qed_ptt *p_ptt,
2103 struct qed_vf_info *vf)
2105 u16 length = sizeof(struct pfvf_def_resp_tlv);
2106 struct qed_iov_vf_mbx *mbx = &vf->vf_mbx;
2107 u8 status = PFVF_STATUS_SUCCESS;
2108 struct vfpf_stop_txqs_tlv *req;
2109 int rc;
2111 /* We give the option of starting from qid != 0, in this case we
2112 * need to make sure that qid + num_qs doesn't exceed the actual
2113 * amount of queues that exist.
2115 req = &mbx->req_virt->stop_txqs;
2116 rc = qed_iov_vf_stop_txqs(p_hwfn, vf, req->tx_qid, req->num_txqs);
2117 if (rc)
2118 status = PFVF_STATUS_FAILURE;
2120 qed_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_STOP_TXQS,
2121 length, status);
2124 static void qed_iov_vf_mbx_update_rxqs(struct qed_hwfn *p_hwfn,
2125 struct qed_ptt *p_ptt,
2126 struct qed_vf_info *vf)
2128 struct qed_queue_cid *handlers[QED_MAX_VF_CHAINS_PER_PF];
2129 u16 length = sizeof(struct pfvf_def_resp_tlv);
2130 struct qed_iov_vf_mbx *mbx = &vf->vf_mbx;
2131 struct vfpf_update_rxq_tlv *req;
2132 u8 status = PFVF_STATUS_FAILURE;
2133 u8 complete_event_flg;
2134 u8 complete_cqe_flg;
2135 u16 qid;
2136 int rc;
2137 u8 i;
2139 req = &mbx->req_virt->update_rxq;
2140 complete_cqe_flg = !!(req->flags & VFPF_RXQ_UPD_COMPLETE_CQE_FLAG);
2141 complete_event_flg = !!(req->flags & VFPF_RXQ_UPD_COMPLETE_EVENT_FLAG);
2143 /* Validate inputs */
2144 if (req->num_rxqs + req->rx_qid > QED_MAX_VF_CHAINS_PER_PF ||
2145 !qed_iov_validate_rxq(p_hwfn, vf, req->rx_qid)) {
2146 DP_INFO(p_hwfn, "VF[%d]: Incorrect Rxqs [%04x, %02x]\n",
2147 vf->relative_vf_id, req->rx_qid, req->num_rxqs);
2148 goto out;
2151 for (i = 0; i < req->num_rxqs; i++) {
2152 qid = req->rx_qid + i;
2153 if (!vf->vf_queues[qid].p_rx_cid) {
2154 DP_INFO(p_hwfn,
2155 "VF[%d] rx_qid = %d isn`t active!\n",
2156 vf->relative_vf_id, qid);
2157 goto out;
2160 handlers[i] = vf->vf_queues[qid].p_rx_cid;
2163 rc = qed_sp_eth_rx_queues_update(p_hwfn, (void **)&handlers,
2164 req->num_rxqs,
2165 complete_cqe_flg,
2166 complete_event_flg,
2167 QED_SPQ_MODE_EBLOCK, NULL);
2168 if (rc)
2169 goto out;
2171 status = PFVF_STATUS_SUCCESS;
2172 out:
2173 qed_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_UPDATE_RXQ,
2174 length, status);
2177 void *qed_iov_search_list_tlvs(struct qed_hwfn *p_hwfn,
2178 void *p_tlvs_list, u16 req_type)
2180 struct channel_tlv *p_tlv = (struct channel_tlv *)p_tlvs_list;
2181 int len = 0;
2183 do {
2184 if (!p_tlv->length) {
2185 DP_NOTICE(p_hwfn, "Zero length TLV found\n");
2186 return NULL;
2189 if (p_tlv->type == req_type) {
2190 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
2191 "Extended tlv type %d, length %d found\n",
2192 p_tlv->type, p_tlv->length);
2193 return p_tlv;
2196 len += p_tlv->length;
2197 p_tlv = (struct channel_tlv *)((u8 *)p_tlv + p_tlv->length);
2199 if ((len + p_tlv->length) > TLV_BUFFER_SIZE) {
2200 DP_NOTICE(p_hwfn, "TLVs has overrun the buffer size\n");
2201 return NULL;
2203 } while (p_tlv->type != CHANNEL_TLV_LIST_END);
2205 return NULL;
2208 static void
2209 qed_iov_vp_update_act_param(struct qed_hwfn *p_hwfn,
2210 struct qed_sp_vport_update_params *p_data,
2211 struct qed_iov_vf_mbx *p_mbx, u16 *tlvs_mask)
2213 struct vfpf_vport_update_activate_tlv *p_act_tlv;
2214 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_ACTIVATE;
2216 p_act_tlv = (struct vfpf_vport_update_activate_tlv *)
2217 qed_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
2218 if (!p_act_tlv)
2219 return;
2221 p_data->update_vport_active_rx_flg = p_act_tlv->update_rx;
2222 p_data->vport_active_rx_flg = p_act_tlv->active_rx;
2223 p_data->update_vport_active_tx_flg = p_act_tlv->update_tx;
2224 p_data->vport_active_tx_flg = p_act_tlv->active_tx;
2225 *tlvs_mask |= 1 << QED_IOV_VP_UPDATE_ACTIVATE;
2228 static void
2229 qed_iov_vp_update_vlan_param(struct qed_hwfn *p_hwfn,
2230 struct qed_sp_vport_update_params *p_data,
2231 struct qed_vf_info *p_vf,
2232 struct qed_iov_vf_mbx *p_mbx, u16 *tlvs_mask)
2234 struct vfpf_vport_update_vlan_strip_tlv *p_vlan_tlv;
2235 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_VLAN_STRIP;
2237 p_vlan_tlv = (struct vfpf_vport_update_vlan_strip_tlv *)
2238 qed_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
2239 if (!p_vlan_tlv)
2240 return;
2242 p_vf->shadow_config.inner_vlan_removal = p_vlan_tlv->remove_vlan;
2244 /* Ignore the VF request if we're forcing a vlan */
2245 if (!(p_vf->configured_features & BIT(VLAN_ADDR_FORCED))) {
2246 p_data->update_inner_vlan_removal_flg = 1;
2247 p_data->inner_vlan_removal_flg = p_vlan_tlv->remove_vlan;
2250 *tlvs_mask |= 1 << QED_IOV_VP_UPDATE_VLAN_STRIP;
2253 static void
2254 qed_iov_vp_update_tx_switch(struct qed_hwfn *p_hwfn,
2255 struct qed_sp_vport_update_params *p_data,
2256 struct qed_iov_vf_mbx *p_mbx, u16 *tlvs_mask)
2258 struct vfpf_vport_update_tx_switch_tlv *p_tx_switch_tlv;
2259 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_TX_SWITCH;
2261 p_tx_switch_tlv = (struct vfpf_vport_update_tx_switch_tlv *)
2262 qed_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt,
2263 tlv);
2264 if (!p_tx_switch_tlv)
2265 return;
2267 p_data->update_tx_switching_flg = 1;
2268 p_data->tx_switching_flg = p_tx_switch_tlv->tx_switching;
2269 *tlvs_mask |= 1 << QED_IOV_VP_UPDATE_TX_SWITCH;
2272 static void
2273 qed_iov_vp_update_mcast_bin_param(struct qed_hwfn *p_hwfn,
2274 struct qed_sp_vport_update_params *p_data,
2275 struct qed_iov_vf_mbx *p_mbx, u16 *tlvs_mask)
2277 struct vfpf_vport_update_mcast_bin_tlv *p_mcast_tlv;
2278 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_MCAST;
2280 p_mcast_tlv = (struct vfpf_vport_update_mcast_bin_tlv *)
2281 qed_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
2282 if (!p_mcast_tlv)
2283 return;
2285 p_data->update_approx_mcast_flg = 1;
2286 memcpy(p_data->bins, p_mcast_tlv->bins,
2287 sizeof(unsigned long) * ETH_MULTICAST_MAC_BINS_IN_REGS);
2288 *tlvs_mask |= 1 << QED_IOV_VP_UPDATE_MCAST;
2291 static void
2292 qed_iov_vp_update_accept_flag(struct qed_hwfn *p_hwfn,
2293 struct qed_sp_vport_update_params *p_data,
2294 struct qed_iov_vf_mbx *p_mbx, u16 *tlvs_mask)
2296 struct qed_filter_accept_flags *p_flags = &p_data->accept_flags;
2297 struct vfpf_vport_update_accept_param_tlv *p_accept_tlv;
2298 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_ACCEPT_PARAM;
2300 p_accept_tlv = (struct vfpf_vport_update_accept_param_tlv *)
2301 qed_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
2302 if (!p_accept_tlv)
2303 return;
2305 p_flags->update_rx_mode_config = p_accept_tlv->update_rx_mode;
2306 p_flags->rx_accept_filter = p_accept_tlv->rx_accept_filter;
2307 p_flags->update_tx_mode_config = p_accept_tlv->update_tx_mode;
2308 p_flags->tx_accept_filter = p_accept_tlv->tx_accept_filter;
2309 *tlvs_mask |= 1 << QED_IOV_VP_UPDATE_ACCEPT_PARAM;
2312 static void
2313 qed_iov_vp_update_accept_any_vlan(struct qed_hwfn *p_hwfn,
2314 struct qed_sp_vport_update_params *p_data,
2315 struct qed_iov_vf_mbx *p_mbx, u16 *tlvs_mask)
2317 struct vfpf_vport_update_accept_any_vlan_tlv *p_accept_any_vlan;
2318 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_ACCEPT_ANY_VLAN;
2320 p_accept_any_vlan = (struct vfpf_vport_update_accept_any_vlan_tlv *)
2321 qed_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt,
2322 tlv);
2323 if (!p_accept_any_vlan)
2324 return;
2326 p_data->accept_any_vlan = p_accept_any_vlan->accept_any_vlan;
2327 p_data->update_accept_any_vlan_flg =
2328 p_accept_any_vlan->update_accept_any_vlan_flg;
2329 *tlvs_mask |= 1 << QED_IOV_VP_UPDATE_ACCEPT_ANY_VLAN;
2332 static void
2333 qed_iov_vp_update_rss_param(struct qed_hwfn *p_hwfn,
2334 struct qed_vf_info *vf,
2335 struct qed_sp_vport_update_params *p_data,
2336 struct qed_rss_params *p_rss,
2337 struct qed_iov_vf_mbx *p_mbx,
2338 u16 *tlvs_mask, u16 *tlvs_accepted)
2340 struct vfpf_vport_update_rss_tlv *p_rss_tlv;
2341 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_RSS;
2342 bool b_reject = false;
2343 u16 table_size;
2344 u16 i, q_idx;
2346 p_rss_tlv = (struct vfpf_vport_update_rss_tlv *)
2347 qed_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
2348 if (!p_rss_tlv) {
2349 p_data->rss_params = NULL;
2350 return;
2353 memset(p_rss, 0, sizeof(struct qed_rss_params));
2355 p_rss->update_rss_config = !!(p_rss_tlv->update_rss_flags &
2356 VFPF_UPDATE_RSS_CONFIG_FLAG);
2357 p_rss->update_rss_capabilities = !!(p_rss_tlv->update_rss_flags &
2358 VFPF_UPDATE_RSS_CAPS_FLAG);
2359 p_rss->update_rss_ind_table = !!(p_rss_tlv->update_rss_flags &
2360 VFPF_UPDATE_RSS_IND_TABLE_FLAG);
2361 p_rss->update_rss_key = !!(p_rss_tlv->update_rss_flags &
2362 VFPF_UPDATE_RSS_KEY_FLAG);
2364 p_rss->rss_enable = p_rss_tlv->rss_enable;
2365 p_rss->rss_eng_id = vf->relative_vf_id + 1;
2366 p_rss->rss_caps = p_rss_tlv->rss_caps;
2367 p_rss->rss_table_size_log = p_rss_tlv->rss_table_size_log;
2368 memcpy(p_rss->rss_key, p_rss_tlv->rss_key, sizeof(p_rss->rss_key));
2370 table_size = min_t(u16, ARRAY_SIZE(p_rss->rss_ind_table),
2371 (1 << p_rss_tlv->rss_table_size_log));
2373 for (i = 0; i < table_size; i++) {
2374 q_idx = p_rss_tlv->rss_ind_table[i];
2375 if (!qed_iov_validate_rxq(p_hwfn, vf, q_idx)) {
2376 DP_VERBOSE(p_hwfn,
2377 QED_MSG_IOV,
2378 "VF[%d]: Omitting RSS due to wrong queue %04x\n",
2379 vf->relative_vf_id, q_idx);
2380 b_reject = true;
2381 goto out;
2384 if (!vf->vf_queues[q_idx].p_rx_cid) {
2385 DP_VERBOSE(p_hwfn,
2386 QED_MSG_IOV,
2387 "VF[%d]: Omitting RSS due to inactive queue %08x\n",
2388 vf->relative_vf_id, q_idx);
2389 b_reject = true;
2390 goto out;
2393 p_rss->rss_ind_table[i] = vf->vf_queues[q_idx].p_rx_cid;
2396 p_data->rss_params = p_rss;
2397 out:
2398 *tlvs_mask |= 1 << QED_IOV_VP_UPDATE_RSS;
2399 if (!b_reject)
2400 *tlvs_accepted |= 1 << QED_IOV_VP_UPDATE_RSS;
2403 static void
2404 qed_iov_vp_update_sge_tpa_param(struct qed_hwfn *p_hwfn,
2405 struct qed_vf_info *vf,
2406 struct qed_sp_vport_update_params *p_data,
2407 struct qed_sge_tpa_params *p_sge_tpa,
2408 struct qed_iov_vf_mbx *p_mbx, u16 *tlvs_mask)
2410 struct vfpf_vport_update_sge_tpa_tlv *p_sge_tpa_tlv;
2411 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_SGE_TPA;
2413 p_sge_tpa_tlv = (struct vfpf_vport_update_sge_tpa_tlv *)
2414 qed_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
2416 if (!p_sge_tpa_tlv) {
2417 p_data->sge_tpa_params = NULL;
2418 return;
2421 memset(p_sge_tpa, 0, sizeof(struct qed_sge_tpa_params));
2423 p_sge_tpa->update_tpa_en_flg =
2424 !!(p_sge_tpa_tlv->update_sge_tpa_flags & VFPF_UPDATE_TPA_EN_FLAG);
2425 p_sge_tpa->update_tpa_param_flg =
2426 !!(p_sge_tpa_tlv->update_sge_tpa_flags &
2427 VFPF_UPDATE_TPA_PARAM_FLAG);
2429 p_sge_tpa->tpa_ipv4_en_flg =
2430 !!(p_sge_tpa_tlv->sge_tpa_flags & VFPF_TPA_IPV4_EN_FLAG);
2431 p_sge_tpa->tpa_ipv6_en_flg =
2432 !!(p_sge_tpa_tlv->sge_tpa_flags & VFPF_TPA_IPV6_EN_FLAG);
2433 p_sge_tpa->tpa_pkt_split_flg =
2434 !!(p_sge_tpa_tlv->sge_tpa_flags & VFPF_TPA_PKT_SPLIT_FLAG);
2435 p_sge_tpa->tpa_hdr_data_split_flg =
2436 !!(p_sge_tpa_tlv->sge_tpa_flags & VFPF_TPA_HDR_DATA_SPLIT_FLAG);
2437 p_sge_tpa->tpa_gro_consistent_flg =
2438 !!(p_sge_tpa_tlv->sge_tpa_flags & VFPF_TPA_GRO_CONSIST_FLAG);
2440 p_sge_tpa->tpa_max_aggs_num = p_sge_tpa_tlv->tpa_max_aggs_num;
2441 p_sge_tpa->tpa_max_size = p_sge_tpa_tlv->tpa_max_size;
2442 p_sge_tpa->tpa_min_size_to_start = p_sge_tpa_tlv->tpa_min_size_to_start;
2443 p_sge_tpa->tpa_min_size_to_cont = p_sge_tpa_tlv->tpa_min_size_to_cont;
2444 p_sge_tpa->max_buffers_per_cqe = p_sge_tpa_tlv->max_buffers_per_cqe;
2446 p_data->sge_tpa_params = p_sge_tpa;
2448 *tlvs_mask |= 1 << QED_IOV_VP_UPDATE_SGE_TPA;
2451 static int qed_iov_pre_update_vport(struct qed_hwfn *hwfn,
2452 u8 vfid,
2453 struct qed_sp_vport_update_params *params,
2454 u16 *tlvs)
2456 u8 mask = QED_ACCEPT_UCAST_UNMATCHED | QED_ACCEPT_MCAST_UNMATCHED;
2457 struct qed_filter_accept_flags *flags = &params->accept_flags;
2458 struct qed_public_vf_info *vf_info;
2460 /* Untrusted VFs can't even be trusted to know that fact.
2461 * Simply indicate everything is configured fine, and trace
2462 * configuration 'behind their back'.
2464 if (!(*tlvs & BIT(QED_IOV_VP_UPDATE_ACCEPT_PARAM)))
2465 return 0;
2467 vf_info = qed_iov_get_public_vf_info(hwfn, vfid, true);
2469 if (flags->update_rx_mode_config) {
2470 vf_info->rx_accept_mode = flags->rx_accept_filter;
2471 if (!vf_info->is_trusted_configured)
2472 flags->rx_accept_filter &= ~mask;
2475 if (flags->update_tx_mode_config) {
2476 vf_info->tx_accept_mode = flags->tx_accept_filter;
2477 if (!vf_info->is_trusted_configured)
2478 flags->tx_accept_filter &= ~mask;
2481 return 0;
2484 static void qed_iov_vf_mbx_vport_update(struct qed_hwfn *p_hwfn,
2485 struct qed_ptt *p_ptt,
2486 struct qed_vf_info *vf)
2488 struct qed_rss_params *p_rss_params = NULL;
2489 struct qed_sp_vport_update_params params;
2490 struct qed_iov_vf_mbx *mbx = &vf->vf_mbx;
2491 struct qed_sge_tpa_params sge_tpa_params;
2492 u16 tlvs_mask = 0, tlvs_accepted = 0;
2493 u8 status = PFVF_STATUS_SUCCESS;
2494 u16 length;
2495 int rc;
2497 /* Valiate PF can send such a request */
2498 if (!vf->vport_instance) {
2499 DP_VERBOSE(p_hwfn,
2500 QED_MSG_IOV,
2501 "No VPORT instance available for VF[%d], failing vport update\n",
2502 vf->abs_vf_id);
2503 status = PFVF_STATUS_FAILURE;
2504 goto out;
2506 p_rss_params = vzalloc(sizeof(*p_rss_params));
2507 if (p_rss_params == NULL) {
2508 status = PFVF_STATUS_FAILURE;
2509 goto out;
2512 memset(&params, 0, sizeof(params));
2513 params.opaque_fid = vf->opaque_fid;
2514 params.vport_id = vf->vport_id;
2515 params.rss_params = NULL;
2517 /* Search for extended tlvs list and update values
2518 * from VF in struct qed_sp_vport_update_params.
2520 qed_iov_vp_update_act_param(p_hwfn, &params, mbx, &tlvs_mask);
2521 qed_iov_vp_update_vlan_param(p_hwfn, &params, vf, mbx, &tlvs_mask);
2522 qed_iov_vp_update_tx_switch(p_hwfn, &params, mbx, &tlvs_mask);
2523 qed_iov_vp_update_mcast_bin_param(p_hwfn, &params, mbx, &tlvs_mask);
2524 qed_iov_vp_update_accept_flag(p_hwfn, &params, mbx, &tlvs_mask);
2525 qed_iov_vp_update_accept_any_vlan(p_hwfn, &params, mbx, &tlvs_mask);
2526 qed_iov_vp_update_sge_tpa_param(p_hwfn, vf, &params,
2527 &sge_tpa_params, mbx, &tlvs_mask);
2529 tlvs_accepted = tlvs_mask;
2531 /* Some of the extended TLVs need to be validated first; In that case,
2532 * they can update the mask without updating the accepted [so that
2533 * PF could communicate to VF it has rejected request].
2535 qed_iov_vp_update_rss_param(p_hwfn, vf, &params, p_rss_params,
2536 mbx, &tlvs_mask, &tlvs_accepted);
2538 if (qed_iov_pre_update_vport(p_hwfn, vf->relative_vf_id,
2539 &params, &tlvs_accepted)) {
2540 tlvs_accepted = 0;
2541 status = PFVF_STATUS_NOT_SUPPORTED;
2542 goto out;
2545 if (!tlvs_accepted) {
2546 if (tlvs_mask)
2547 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
2548 "Upper-layer prevents VF vport configuration\n");
2549 else
2550 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
2551 "No feature tlvs found for vport update\n");
2552 status = PFVF_STATUS_NOT_SUPPORTED;
2553 goto out;
2556 rc = qed_sp_vport_update(p_hwfn, &params, QED_SPQ_MODE_EBLOCK, NULL);
2558 if (rc)
2559 status = PFVF_STATUS_FAILURE;
2561 out:
2562 vfree(p_rss_params);
2563 length = qed_iov_prep_vp_update_resp_tlvs(p_hwfn, vf, mbx, status,
2564 tlvs_mask, tlvs_accepted);
2565 qed_iov_send_response(p_hwfn, p_ptt, vf, length, status);
2568 static int qed_iov_vf_update_vlan_shadow(struct qed_hwfn *p_hwfn,
2569 struct qed_vf_info *p_vf,
2570 struct qed_filter_ucast *p_params)
2572 int i;
2574 /* First remove entries and then add new ones */
2575 if (p_params->opcode == QED_FILTER_REMOVE) {
2576 for (i = 0; i < QED_ETH_VF_NUM_VLAN_FILTERS + 1; i++)
2577 if (p_vf->shadow_config.vlans[i].used &&
2578 p_vf->shadow_config.vlans[i].vid ==
2579 p_params->vlan) {
2580 p_vf->shadow_config.vlans[i].used = false;
2581 break;
2583 if (i == QED_ETH_VF_NUM_VLAN_FILTERS + 1) {
2584 DP_VERBOSE(p_hwfn,
2585 QED_MSG_IOV,
2586 "VF [%d] - Tries to remove a non-existing vlan\n",
2587 p_vf->relative_vf_id);
2588 return -EINVAL;
2590 } else if (p_params->opcode == QED_FILTER_REPLACE ||
2591 p_params->opcode == QED_FILTER_FLUSH) {
2592 for (i = 0; i < QED_ETH_VF_NUM_VLAN_FILTERS + 1; i++)
2593 p_vf->shadow_config.vlans[i].used = false;
2596 /* In forced mode, we're willing to remove entries - but we don't add
2597 * new ones.
2599 if (p_vf->bulletin.p_virt->valid_bitmap & BIT(VLAN_ADDR_FORCED))
2600 return 0;
2602 if (p_params->opcode == QED_FILTER_ADD ||
2603 p_params->opcode == QED_FILTER_REPLACE) {
2604 for (i = 0; i < QED_ETH_VF_NUM_VLAN_FILTERS + 1; i++) {
2605 if (p_vf->shadow_config.vlans[i].used)
2606 continue;
2608 p_vf->shadow_config.vlans[i].used = true;
2609 p_vf->shadow_config.vlans[i].vid = p_params->vlan;
2610 break;
2613 if (i == QED_ETH_VF_NUM_VLAN_FILTERS + 1) {
2614 DP_VERBOSE(p_hwfn,
2615 QED_MSG_IOV,
2616 "VF [%d] - Tries to configure more than %d vlan filters\n",
2617 p_vf->relative_vf_id,
2618 QED_ETH_VF_NUM_VLAN_FILTERS + 1);
2619 return -EINVAL;
2623 return 0;
2626 static int qed_iov_vf_update_mac_shadow(struct qed_hwfn *p_hwfn,
2627 struct qed_vf_info *p_vf,
2628 struct qed_filter_ucast *p_params)
2630 int i;
2632 /* If we're in forced-mode, we don't allow any change */
2633 if (p_vf->bulletin.p_virt->valid_bitmap & BIT(MAC_ADDR_FORCED))
2634 return 0;
2636 /* First remove entries and then add new ones */
2637 if (p_params->opcode == QED_FILTER_REMOVE) {
2638 for (i = 0; i < QED_ETH_VF_NUM_MAC_FILTERS; i++) {
2639 if (ether_addr_equal(p_vf->shadow_config.macs[i],
2640 p_params->mac)) {
2641 eth_zero_addr(p_vf->shadow_config.macs[i]);
2642 break;
2646 if (i == QED_ETH_VF_NUM_MAC_FILTERS) {
2647 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
2648 "MAC isn't configured\n");
2649 return -EINVAL;
2651 } else if (p_params->opcode == QED_FILTER_REPLACE ||
2652 p_params->opcode == QED_FILTER_FLUSH) {
2653 for (i = 0; i < QED_ETH_VF_NUM_MAC_FILTERS; i++)
2654 eth_zero_addr(p_vf->shadow_config.macs[i]);
2657 /* List the new MAC address */
2658 if (p_params->opcode != QED_FILTER_ADD &&
2659 p_params->opcode != QED_FILTER_REPLACE)
2660 return 0;
2662 for (i = 0; i < QED_ETH_VF_NUM_MAC_FILTERS; i++) {
2663 if (is_zero_ether_addr(p_vf->shadow_config.macs[i])) {
2664 ether_addr_copy(p_vf->shadow_config.macs[i],
2665 p_params->mac);
2666 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
2667 "Added MAC at %d entry in shadow\n", i);
2668 break;
2672 if (i == QED_ETH_VF_NUM_MAC_FILTERS) {
2673 DP_VERBOSE(p_hwfn, QED_MSG_IOV, "No available place for MAC\n");
2674 return -EINVAL;
2677 return 0;
2680 static int
2681 qed_iov_vf_update_unicast_shadow(struct qed_hwfn *p_hwfn,
2682 struct qed_vf_info *p_vf,
2683 struct qed_filter_ucast *p_params)
2685 int rc = 0;
2687 if (p_params->type == QED_FILTER_MAC) {
2688 rc = qed_iov_vf_update_mac_shadow(p_hwfn, p_vf, p_params);
2689 if (rc)
2690 return rc;
2693 if (p_params->type == QED_FILTER_VLAN)
2694 rc = qed_iov_vf_update_vlan_shadow(p_hwfn, p_vf, p_params);
2696 return rc;
2699 static int qed_iov_chk_ucast(struct qed_hwfn *hwfn,
2700 int vfid, struct qed_filter_ucast *params)
2702 struct qed_public_vf_info *vf;
2704 vf = qed_iov_get_public_vf_info(hwfn, vfid, true);
2705 if (!vf)
2706 return -EINVAL;
2708 /* No real decision to make; Store the configured MAC */
2709 if (params->type == QED_FILTER_MAC ||
2710 params->type == QED_FILTER_MAC_VLAN)
2711 ether_addr_copy(vf->mac, params->mac);
2713 return 0;
2716 static void qed_iov_vf_mbx_ucast_filter(struct qed_hwfn *p_hwfn,
2717 struct qed_ptt *p_ptt,
2718 struct qed_vf_info *vf)
2720 struct qed_bulletin_content *p_bulletin = vf->bulletin.p_virt;
2721 struct qed_iov_vf_mbx *mbx = &vf->vf_mbx;
2722 struct vfpf_ucast_filter_tlv *req;
2723 u8 status = PFVF_STATUS_SUCCESS;
2724 struct qed_filter_ucast params;
2725 int rc;
2727 /* Prepare the unicast filter params */
2728 memset(&params, 0, sizeof(struct qed_filter_ucast));
2729 req = &mbx->req_virt->ucast_filter;
2730 params.opcode = (enum qed_filter_opcode)req->opcode;
2731 params.type = (enum qed_filter_ucast_type)req->type;
2733 params.is_rx_filter = 1;
2734 params.is_tx_filter = 1;
2735 params.vport_to_remove_from = vf->vport_id;
2736 params.vport_to_add_to = vf->vport_id;
2737 memcpy(params.mac, req->mac, ETH_ALEN);
2738 params.vlan = req->vlan;
2740 DP_VERBOSE(p_hwfn,
2741 QED_MSG_IOV,
2742 "VF[%d]: opcode 0x%02x type 0x%02x [%s %s] [vport 0x%02x] MAC %02x:%02x:%02x:%02x:%02x:%02x, vlan 0x%04x\n",
2743 vf->abs_vf_id, params.opcode, params.type,
2744 params.is_rx_filter ? "RX" : "",
2745 params.is_tx_filter ? "TX" : "",
2746 params.vport_to_add_to,
2747 params.mac[0], params.mac[1],
2748 params.mac[2], params.mac[3],
2749 params.mac[4], params.mac[5], params.vlan);
2751 if (!vf->vport_instance) {
2752 DP_VERBOSE(p_hwfn,
2753 QED_MSG_IOV,
2754 "No VPORT instance available for VF[%d], failing ucast MAC configuration\n",
2755 vf->abs_vf_id);
2756 status = PFVF_STATUS_FAILURE;
2757 goto out;
2760 /* Update shadow copy of the VF configuration */
2761 if (qed_iov_vf_update_unicast_shadow(p_hwfn, vf, &params)) {
2762 status = PFVF_STATUS_FAILURE;
2763 goto out;
2766 /* Determine if the unicast filtering is acceptible by PF */
2767 if ((p_bulletin->valid_bitmap & BIT(VLAN_ADDR_FORCED)) &&
2768 (params.type == QED_FILTER_VLAN ||
2769 params.type == QED_FILTER_MAC_VLAN)) {
2770 /* Once VLAN is forced or PVID is set, do not allow
2771 * to add/replace any further VLANs.
2773 if (params.opcode == QED_FILTER_ADD ||
2774 params.opcode == QED_FILTER_REPLACE)
2775 status = PFVF_STATUS_FORCED;
2776 goto out;
2779 if ((p_bulletin->valid_bitmap & BIT(MAC_ADDR_FORCED)) &&
2780 (params.type == QED_FILTER_MAC ||
2781 params.type == QED_FILTER_MAC_VLAN)) {
2782 if (!ether_addr_equal(p_bulletin->mac, params.mac) ||
2783 (params.opcode != QED_FILTER_ADD &&
2784 params.opcode != QED_FILTER_REPLACE))
2785 status = PFVF_STATUS_FORCED;
2786 goto out;
2789 rc = qed_iov_chk_ucast(p_hwfn, vf->relative_vf_id, &params);
2790 if (rc) {
2791 status = PFVF_STATUS_FAILURE;
2792 goto out;
2795 rc = qed_sp_eth_filter_ucast(p_hwfn, vf->opaque_fid, &params,
2796 QED_SPQ_MODE_CB, NULL);
2797 if (rc)
2798 status = PFVF_STATUS_FAILURE;
2800 out:
2801 qed_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_UCAST_FILTER,
2802 sizeof(struct pfvf_def_resp_tlv), status);
2805 static void qed_iov_vf_mbx_int_cleanup(struct qed_hwfn *p_hwfn,
2806 struct qed_ptt *p_ptt,
2807 struct qed_vf_info *vf)
2809 int i;
2811 /* Reset the SBs */
2812 for (i = 0; i < vf->num_sbs; i++)
2813 qed_int_igu_init_pure_rt_single(p_hwfn, p_ptt,
2814 vf->igu_sbs[i],
2815 vf->opaque_fid, false);
2817 qed_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_INT_CLEANUP,
2818 sizeof(struct pfvf_def_resp_tlv),
2819 PFVF_STATUS_SUCCESS);
2822 static void qed_iov_vf_mbx_close(struct qed_hwfn *p_hwfn,
2823 struct qed_ptt *p_ptt, struct qed_vf_info *vf)
2825 u16 length = sizeof(struct pfvf_def_resp_tlv);
2826 u8 status = PFVF_STATUS_SUCCESS;
2828 /* Disable Interrupts for VF */
2829 qed_iov_vf_igu_set_int(p_hwfn, p_ptt, vf, 0);
2831 /* Reset Permission table */
2832 qed_iov_config_perm_table(p_hwfn, p_ptt, vf, 0);
2834 qed_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_CLOSE,
2835 length, status);
2838 static void qed_iov_vf_mbx_release(struct qed_hwfn *p_hwfn,
2839 struct qed_ptt *p_ptt,
2840 struct qed_vf_info *p_vf)
2842 u16 length = sizeof(struct pfvf_def_resp_tlv);
2843 u8 status = PFVF_STATUS_SUCCESS;
2844 int rc = 0;
2846 qed_iov_vf_cleanup(p_hwfn, p_vf);
2848 if (p_vf->state != VF_STOPPED && p_vf->state != VF_FREE) {
2849 /* Stopping the VF */
2850 rc = qed_sp_vf_stop(p_hwfn, p_vf->concrete_fid,
2851 p_vf->opaque_fid);
2853 if (rc) {
2854 DP_ERR(p_hwfn, "qed_sp_vf_stop returned error %d\n",
2855 rc);
2856 status = PFVF_STATUS_FAILURE;
2859 p_vf->state = VF_STOPPED;
2862 qed_iov_prepare_resp(p_hwfn, p_ptt, p_vf, CHANNEL_TLV_RELEASE,
2863 length, status);
2866 static int
2867 qed_iov_vf_flr_poll_dorq(struct qed_hwfn *p_hwfn,
2868 struct qed_vf_info *p_vf, struct qed_ptt *p_ptt)
2870 int cnt;
2871 u32 val;
2873 qed_fid_pretend(p_hwfn, p_ptt, (u16) p_vf->concrete_fid);
2875 for (cnt = 0; cnt < 50; cnt++) {
2876 val = qed_rd(p_hwfn, p_ptt, DORQ_REG_VF_USAGE_CNT);
2877 if (!val)
2878 break;
2879 msleep(20);
2881 qed_fid_pretend(p_hwfn, p_ptt, (u16) p_hwfn->hw_info.concrete_fid);
2883 if (cnt == 50) {
2884 DP_ERR(p_hwfn,
2885 "VF[%d] - dorq failed to cleanup [usage 0x%08x]\n",
2886 p_vf->abs_vf_id, val);
2887 return -EBUSY;
2890 return 0;
2893 static int
2894 qed_iov_vf_flr_poll_pbf(struct qed_hwfn *p_hwfn,
2895 struct qed_vf_info *p_vf, struct qed_ptt *p_ptt)
2897 u32 cons[MAX_NUM_VOQS], distance[MAX_NUM_VOQS];
2898 int i, cnt;
2900 /* Read initial consumers & producers */
2901 for (i = 0; i < MAX_NUM_VOQS; i++) {
2902 u32 prod;
2904 cons[i] = qed_rd(p_hwfn, p_ptt,
2905 PBF_REG_NUM_BLOCKS_ALLOCATED_CONS_VOQ0 +
2906 i * 0x40);
2907 prod = qed_rd(p_hwfn, p_ptt,
2908 PBF_REG_NUM_BLOCKS_ALLOCATED_PROD_VOQ0 +
2909 i * 0x40);
2910 distance[i] = prod - cons[i];
2913 /* Wait for consumers to pass the producers */
2914 i = 0;
2915 for (cnt = 0; cnt < 50; cnt++) {
2916 for (; i < MAX_NUM_VOQS; i++) {
2917 u32 tmp;
2919 tmp = qed_rd(p_hwfn, p_ptt,
2920 PBF_REG_NUM_BLOCKS_ALLOCATED_CONS_VOQ0 +
2921 i * 0x40);
2922 if (distance[i] > tmp - cons[i])
2923 break;
2926 if (i == MAX_NUM_VOQS)
2927 break;
2929 msleep(20);
2932 if (cnt == 50) {
2933 DP_ERR(p_hwfn, "VF[%d] - pbf polling failed on VOQ %d\n",
2934 p_vf->abs_vf_id, i);
2935 return -EBUSY;
2938 return 0;
2941 static int qed_iov_vf_flr_poll(struct qed_hwfn *p_hwfn,
2942 struct qed_vf_info *p_vf, struct qed_ptt *p_ptt)
2944 int rc;
2946 rc = qed_iov_vf_flr_poll_dorq(p_hwfn, p_vf, p_ptt);
2947 if (rc)
2948 return rc;
2950 rc = qed_iov_vf_flr_poll_pbf(p_hwfn, p_vf, p_ptt);
2951 if (rc)
2952 return rc;
2954 return 0;
2957 static int
2958 qed_iov_execute_vf_flr_cleanup(struct qed_hwfn *p_hwfn,
2959 struct qed_ptt *p_ptt,
2960 u16 rel_vf_id, u32 *ack_vfs)
2962 struct qed_vf_info *p_vf;
2963 int rc = 0;
2965 p_vf = qed_iov_get_vf_info(p_hwfn, rel_vf_id, false);
2966 if (!p_vf)
2967 return 0;
2969 if (p_hwfn->pf_iov_info->pending_flr[rel_vf_id / 64] &
2970 (1ULL << (rel_vf_id % 64))) {
2971 u16 vfid = p_vf->abs_vf_id;
2973 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
2974 "VF[%d] - Handling FLR\n", vfid);
2976 qed_iov_vf_cleanup(p_hwfn, p_vf);
2978 /* If VF isn't active, no need for anything but SW */
2979 if (!p_vf->b_init)
2980 goto cleanup;
2982 rc = qed_iov_vf_flr_poll(p_hwfn, p_vf, p_ptt);
2983 if (rc)
2984 goto cleanup;
2986 rc = qed_final_cleanup(p_hwfn, p_ptt, vfid, true);
2987 if (rc) {
2988 DP_ERR(p_hwfn, "Failed handle FLR of VF[%d]\n", vfid);
2989 return rc;
2992 /* Workaround to make VF-PF channel ready, as FW
2993 * doesn't do that as a part of FLR.
2995 REG_WR(p_hwfn,
2996 GTT_BAR0_MAP_REG_USDM_RAM +
2997 USTORM_VF_PF_CHANNEL_READY_OFFSET(vfid), 1);
2999 /* VF_STOPPED has to be set only after final cleanup
3000 * but prior to re-enabling the VF.
3002 p_vf->state = VF_STOPPED;
3004 rc = qed_iov_enable_vf_access(p_hwfn, p_ptt, p_vf);
3005 if (rc) {
3006 DP_ERR(p_hwfn, "Failed to re-enable VF[%d] acces\n",
3007 vfid);
3008 return rc;
3010 cleanup:
3011 /* Mark VF for ack and clean pending state */
3012 if (p_vf->state == VF_RESET)
3013 p_vf->state = VF_STOPPED;
3014 ack_vfs[vfid / 32] |= BIT((vfid % 32));
3015 p_hwfn->pf_iov_info->pending_flr[rel_vf_id / 64] &=
3016 ~(1ULL << (rel_vf_id % 64));
3017 p_vf->vf_mbx.b_pending_msg = false;
3020 return rc;
3023 static int
3024 qed_iov_vf_flr_cleanup(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
3026 u32 ack_vfs[VF_MAX_STATIC / 32];
3027 int rc = 0;
3028 u16 i;
3030 memset(ack_vfs, 0, sizeof(u32) * (VF_MAX_STATIC / 32));
3032 /* Since BRB <-> PRS interface can't be tested as part of the flr
3033 * polling due to HW limitations, simply sleep a bit. And since
3034 * there's no need to wait per-vf, do it before looping.
3036 msleep(100);
3038 for (i = 0; i < p_hwfn->cdev->p_iov_info->total_vfs; i++)
3039 qed_iov_execute_vf_flr_cleanup(p_hwfn, p_ptt, i, ack_vfs);
3041 rc = qed_mcp_ack_vf_flr(p_hwfn, p_ptt, ack_vfs);
3042 return rc;
3045 int qed_iov_mark_vf_flr(struct qed_hwfn *p_hwfn, u32 *p_disabled_vfs)
3047 u16 i, found = 0;
3049 DP_VERBOSE(p_hwfn, QED_MSG_IOV, "Marking FLR-ed VFs\n");
3050 for (i = 0; i < (VF_MAX_STATIC / 32); i++)
3051 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
3052 "[%08x,...,%08x]: %08x\n",
3053 i * 32, (i + 1) * 32 - 1, p_disabled_vfs[i]);
3055 if (!p_hwfn->cdev->p_iov_info) {
3056 DP_NOTICE(p_hwfn, "VF flr but no IOV\n");
3057 return 0;
3060 /* Mark VFs */
3061 for (i = 0; i < p_hwfn->cdev->p_iov_info->total_vfs; i++) {
3062 struct qed_vf_info *p_vf;
3063 u8 vfid;
3065 p_vf = qed_iov_get_vf_info(p_hwfn, i, false);
3066 if (!p_vf)
3067 continue;
3069 vfid = p_vf->abs_vf_id;
3070 if (BIT((vfid % 32)) & p_disabled_vfs[vfid / 32]) {
3071 u64 *p_flr = p_hwfn->pf_iov_info->pending_flr;
3072 u16 rel_vf_id = p_vf->relative_vf_id;
3074 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
3075 "VF[%d] [rel %d] got FLR-ed\n",
3076 vfid, rel_vf_id);
3078 p_vf->state = VF_RESET;
3080 /* No need to lock here, since pending_flr should
3081 * only change here and before ACKing MFw. Since
3082 * MFW will not trigger an additional attention for
3083 * VF flr until ACKs, we're safe.
3085 p_flr[rel_vf_id / 64] |= 1ULL << (rel_vf_id % 64);
3086 found = 1;
3090 return found;
3093 static void qed_iov_get_link(struct qed_hwfn *p_hwfn,
3094 u16 vfid,
3095 struct qed_mcp_link_params *p_params,
3096 struct qed_mcp_link_state *p_link,
3097 struct qed_mcp_link_capabilities *p_caps)
3099 struct qed_vf_info *p_vf = qed_iov_get_vf_info(p_hwfn,
3100 vfid,
3101 false);
3102 struct qed_bulletin_content *p_bulletin;
3104 if (!p_vf)
3105 return;
3107 p_bulletin = p_vf->bulletin.p_virt;
3109 if (p_params)
3110 __qed_vf_get_link_params(p_hwfn, p_params, p_bulletin);
3111 if (p_link)
3112 __qed_vf_get_link_state(p_hwfn, p_link, p_bulletin);
3113 if (p_caps)
3114 __qed_vf_get_link_caps(p_hwfn, p_caps, p_bulletin);
3117 static void qed_iov_process_mbx_req(struct qed_hwfn *p_hwfn,
3118 struct qed_ptt *p_ptt, int vfid)
3120 struct qed_iov_vf_mbx *mbx;
3121 struct qed_vf_info *p_vf;
3123 p_vf = qed_iov_get_vf_info(p_hwfn, (u16) vfid, true);
3124 if (!p_vf)
3125 return;
3127 mbx = &p_vf->vf_mbx;
3129 /* qed_iov_process_mbx_request */
3130 if (!mbx->b_pending_msg) {
3131 DP_NOTICE(p_hwfn,
3132 "VF[%02x]: Trying to process mailbox message when none is pending\n",
3133 p_vf->abs_vf_id);
3134 return;
3136 mbx->b_pending_msg = false;
3138 mbx->first_tlv = mbx->req_virt->first_tlv;
3140 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
3141 "VF[%02x]: Processing mailbox message [type %04x]\n",
3142 p_vf->abs_vf_id, mbx->first_tlv.tl.type);
3144 /* check if tlv type is known */
3145 if (qed_iov_tlv_supported(mbx->first_tlv.tl.type) &&
3146 !p_vf->b_malicious) {
3147 switch (mbx->first_tlv.tl.type) {
3148 case CHANNEL_TLV_ACQUIRE:
3149 qed_iov_vf_mbx_acquire(p_hwfn, p_ptt, p_vf);
3150 break;
3151 case CHANNEL_TLV_VPORT_START:
3152 qed_iov_vf_mbx_start_vport(p_hwfn, p_ptt, p_vf);
3153 break;
3154 case CHANNEL_TLV_VPORT_TEARDOWN:
3155 qed_iov_vf_mbx_stop_vport(p_hwfn, p_ptt, p_vf);
3156 break;
3157 case CHANNEL_TLV_START_RXQ:
3158 qed_iov_vf_mbx_start_rxq(p_hwfn, p_ptt, p_vf);
3159 break;
3160 case CHANNEL_TLV_START_TXQ:
3161 qed_iov_vf_mbx_start_txq(p_hwfn, p_ptt, p_vf);
3162 break;
3163 case CHANNEL_TLV_STOP_RXQS:
3164 qed_iov_vf_mbx_stop_rxqs(p_hwfn, p_ptt, p_vf);
3165 break;
3166 case CHANNEL_TLV_STOP_TXQS:
3167 qed_iov_vf_mbx_stop_txqs(p_hwfn, p_ptt, p_vf);
3168 break;
3169 case CHANNEL_TLV_UPDATE_RXQ:
3170 qed_iov_vf_mbx_update_rxqs(p_hwfn, p_ptt, p_vf);
3171 break;
3172 case CHANNEL_TLV_VPORT_UPDATE:
3173 qed_iov_vf_mbx_vport_update(p_hwfn, p_ptt, p_vf);
3174 break;
3175 case CHANNEL_TLV_UCAST_FILTER:
3176 qed_iov_vf_mbx_ucast_filter(p_hwfn, p_ptt, p_vf);
3177 break;
3178 case CHANNEL_TLV_CLOSE:
3179 qed_iov_vf_mbx_close(p_hwfn, p_ptt, p_vf);
3180 break;
3181 case CHANNEL_TLV_INT_CLEANUP:
3182 qed_iov_vf_mbx_int_cleanup(p_hwfn, p_ptt, p_vf);
3183 break;
3184 case CHANNEL_TLV_RELEASE:
3185 qed_iov_vf_mbx_release(p_hwfn, p_ptt, p_vf);
3186 break;
3188 } else if (qed_iov_tlv_supported(mbx->first_tlv.tl.type)) {
3189 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
3190 "VF [%02x] - considered malicious; Ignoring TLV [%04x]\n",
3191 p_vf->abs_vf_id, mbx->first_tlv.tl.type);
3193 qed_iov_prepare_resp(p_hwfn, p_ptt, p_vf,
3194 mbx->first_tlv.tl.type,
3195 sizeof(struct pfvf_def_resp_tlv),
3196 PFVF_STATUS_MALICIOUS);
3197 } else {
3198 /* unknown TLV - this may belong to a VF driver from the future
3199 * - a version written after this PF driver was written, which
3200 * supports features unknown as of yet. Too bad since we don't
3201 * support them. Or this may be because someone wrote a crappy
3202 * VF driver and is sending garbage over the channel.
3204 DP_NOTICE(p_hwfn,
3205 "VF[%02x]: unknown TLV. type %04x length %04x padding %08x reply address %llu\n",
3206 p_vf->abs_vf_id,
3207 mbx->first_tlv.tl.type,
3208 mbx->first_tlv.tl.length,
3209 mbx->first_tlv.padding, mbx->first_tlv.reply_address);
3211 /* Try replying in case reply address matches the acquisition's
3212 * posted address.
3214 if (p_vf->acquire.first_tlv.reply_address &&
3215 (mbx->first_tlv.reply_address ==
3216 p_vf->acquire.first_tlv.reply_address)) {
3217 qed_iov_prepare_resp(p_hwfn, p_ptt, p_vf,
3218 mbx->first_tlv.tl.type,
3219 sizeof(struct pfvf_def_resp_tlv),
3220 PFVF_STATUS_NOT_SUPPORTED);
3221 } else {
3222 DP_VERBOSE(p_hwfn,
3223 QED_MSG_IOV,
3224 "VF[%02x]: Can't respond to TLV - no valid reply address\n",
3225 p_vf->abs_vf_id);
3230 void qed_iov_pf_get_pending_events(struct qed_hwfn *p_hwfn, u64 *events)
3232 int i;
3234 memset(events, 0, sizeof(u64) * QED_VF_ARRAY_LENGTH);
3236 qed_for_each_vf(p_hwfn, i) {
3237 struct qed_vf_info *p_vf;
3239 p_vf = &p_hwfn->pf_iov_info->vfs_array[i];
3240 if (p_vf->vf_mbx.b_pending_msg)
3241 events[i / 64] |= 1ULL << (i % 64);
3245 static struct qed_vf_info *qed_sriov_get_vf_from_absid(struct qed_hwfn *p_hwfn,
3246 u16 abs_vfid)
3248 u8 min = (u8) p_hwfn->cdev->p_iov_info->first_vf_in_pf;
3250 if (!_qed_iov_pf_sanity_check(p_hwfn, (int)abs_vfid - min, false)) {
3251 DP_VERBOSE(p_hwfn,
3252 QED_MSG_IOV,
3253 "Got indication for VF [abs 0x%08x] that cannot be handled by PF\n",
3254 abs_vfid);
3255 return NULL;
3258 return &p_hwfn->pf_iov_info->vfs_array[(u8) abs_vfid - min];
3261 static int qed_sriov_vfpf_msg(struct qed_hwfn *p_hwfn,
3262 u16 abs_vfid, struct regpair *vf_msg)
3264 struct qed_vf_info *p_vf = qed_sriov_get_vf_from_absid(p_hwfn,
3265 abs_vfid);
3267 if (!p_vf)
3268 return 0;
3270 /* List the physical address of the request so that handler
3271 * could later on copy the message from it.
3273 p_vf->vf_mbx.pending_req = (((u64)vf_msg->hi) << 32) | vf_msg->lo;
3275 /* Mark the event and schedule the workqueue */
3276 p_vf->vf_mbx.b_pending_msg = true;
3277 qed_schedule_iov(p_hwfn, QED_IOV_WQ_MSG_FLAG);
3279 return 0;
3282 static void qed_sriov_vfpf_malicious(struct qed_hwfn *p_hwfn,
3283 struct malicious_vf_eqe_data *p_data)
3285 struct qed_vf_info *p_vf;
3287 p_vf = qed_sriov_get_vf_from_absid(p_hwfn, p_data->vf_id);
3289 if (!p_vf)
3290 return;
3292 DP_INFO(p_hwfn,
3293 "VF [%d] - Malicious behavior [%02x]\n",
3294 p_vf->abs_vf_id, p_data->err_id);
3296 p_vf->b_malicious = true;
3299 int qed_sriov_eqe_event(struct qed_hwfn *p_hwfn,
3300 u8 opcode, __le16 echo, union event_ring_data *data)
3302 switch (opcode) {
3303 case COMMON_EVENT_VF_PF_CHANNEL:
3304 return qed_sriov_vfpf_msg(p_hwfn, le16_to_cpu(echo),
3305 &data->vf_pf_channel.msg_addr);
3306 case COMMON_EVENT_MALICIOUS_VF:
3307 qed_sriov_vfpf_malicious(p_hwfn, &data->malicious_vf);
3308 return 0;
3309 default:
3310 DP_INFO(p_hwfn->cdev, "Unknown sriov eqe event 0x%02x\n",
3311 opcode);
3312 return -EINVAL;
3316 u16 qed_iov_get_next_active_vf(struct qed_hwfn *p_hwfn, u16 rel_vf_id)
3318 struct qed_hw_sriov_info *p_iov = p_hwfn->cdev->p_iov_info;
3319 u16 i;
3321 if (!p_iov)
3322 goto out;
3324 for (i = rel_vf_id; i < p_iov->total_vfs; i++)
3325 if (qed_iov_is_valid_vfid(p_hwfn, rel_vf_id, true, false))
3326 return i;
3328 out:
3329 return MAX_NUM_VFS;
3332 static int qed_iov_copy_vf_msg(struct qed_hwfn *p_hwfn, struct qed_ptt *ptt,
3333 int vfid)
3335 struct qed_dmae_params params;
3336 struct qed_vf_info *vf_info;
3338 vf_info = qed_iov_get_vf_info(p_hwfn, (u16) vfid, true);
3339 if (!vf_info)
3340 return -EINVAL;
3342 memset(&params, 0, sizeof(struct qed_dmae_params));
3343 params.flags = QED_DMAE_FLAG_VF_SRC | QED_DMAE_FLAG_COMPLETION_DST;
3344 params.src_vfid = vf_info->abs_vf_id;
3346 if (qed_dmae_host2host(p_hwfn, ptt,
3347 vf_info->vf_mbx.pending_req,
3348 vf_info->vf_mbx.req_phys,
3349 sizeof(union vfpf_tlvs) / 4, &params)) {
3350 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
3351 "Failed to copy message from VF 0x%02x\n", vfid);
3353 return -EIO;
3356 return 0;
3359 static void qed_iov_bulletin_set_forced_mac(struct qed_hwfn *p_hwfn,
3360 u8 *mac, int vfid)
3362 struct qed_vf_info *vf_info;
3363 u64 feature;
3365 vf_info = qed_iov_get_vf_info(p_hwfn, (u16)vfid, true);
3366 if (!vf_info) {
3367 DP_NOTICE(p_hwfn->cdev,
3368 "Can not set forced MAC, invalid vfid [%d]\n", vfid);
3369 return;
3372 if (vf_info->b_malicious) {
3373 DP_NOTICE(p_hwfn->cdev,
3374 "Can't set forced MAC to malicious VF [%d]\n", vfid);
3375 return;
3378 feature = 1 << MAC_ADDR_FORCED;
3379 memcpy(vf_info->bulletin.p_virt->mac, mac, ETH_ALEN);
3381 vf_info->bulletin.p_virt->valid_bitmap |= feature;
3382 /* Forced MAC will disable MAC_ADDR */
3383 vf_info->bulletin.p_virt->valid_bitmap &= ~BIT(VFPF_BULLETIN_MAC_ADDR);
3385 qed_iov_configure_vport_forced(p_hwfn, vf_info, feature);
3388 static void qed_iov_bulletin_set_forced_vlan(struct qed_hwfn *p_hwfn,
3389 u16 pvid, int vfid)
3391 struct qed_vf_info *vf_info;
3392 u64 feature;
3394 vf_info = qed_iov_get_vf_info(p_hwfn, (u16) vfid, true);
3395 if (!vf_info) {
3396 DP_NOTICE(p_hwfn->cdev,
3397 "Can not set forced MAC, invalid vfid [%d]\n", vfid);
3398 return;
3401 if (vf_info->b_malicious) {
3402 DP_NOTICE(p_hwfn->cdev,
3403 "Can't set forced vlan to malicious VF [%d]\n", vfid);
3404 return;
3407 feature = 1 << VLAN_ADDR_FORCED;
3408 vf_info->bulletin.p_virt->pvid = pvid;
3409 if (pvid)
3410 vf_info->bulletin.p_virt->valid_bitmap |= feature;
3411 else
3412 vf_info->bulletin.p_virt->valid_bitmap &= ~feature;
3414 qed_iov_configure_vport_forced(p_hwfn, vf_info, feature);
3417 static bool qed_iov_vf_has_vport_instance(struct qed_hwfn *p_hwfn, int vfid)
3419 struct qed_vf_info *p_vf_info;
3421 p_vf_info = qed_iov_get_vf_info(p_hwfn, (u16) vfid, true);
3422 if (!p_vf_info)
3423 return false;
3425 return !!p_vf_info->vport_instance;
3428 static bool qed_iov_is_vf_stopped(struct qed_hwfn *p_hwfn, int vfid)
3430 struct qed_vf_info *p_vf_info;
3432 p_vf_info = qed_iov_get_vf_info(p_hwfn, (u16) vfid, true);
3433 if (!p_vf_info)
3434 return true;
3436 return p_vf_info->state == VF_STOPPED;
3439 static bool qed_iov_spoofchk_get(struct qed_hwfn *p_hwfn, int vfid)
3441 struct qed_vf_info *vf_info;
3443 vf_info = qed_iov_get_vf_info(p_hwfn, (u16) vfid, true);
3444 if (!vf_info)
3445 return false;
3447 return vf_info->spoof_chk;
3450 static int qed_iov_spoofchk_set(struct qed_hwfn *p_hwfn, int vfid, bool val)
3452 struct qed_vf_info *vf;
3453 int rc = -EINVAL;
3455 if (!qed_iov_pf_sanity_check(p_hwfn, vfid)) {
3456 DP_NOTICE(p_hwfn,
3457 "SR-IOV sanity check failed, can't set spoofchk\n");
3458 goto out;
3461 vf = qed_iov_get_vf_info(p_hwfn, (u16) vfid, true);
3462 if (!vf)
3463 goto out;
3465 if (!qed_iov_vf_has_vport_instance(p_hwfn, vfid)) {
3466 /* After VF VPORT start PF will configure spoof check */
3467 vf->req_spoofchk_val = val;
3468 rc = 0;
3469 goto out;
3472 rc = __qed_iov_spoofchk_set(p_hwfn, vf, val);
3474 out:
3475 return rc;
3478 static u8 *qed_iov_bulletin_get_forced_mac(struct qed_hwfn *p_hwfn,
3479 u16 rel_vf_id)
3481 struct qed_vf_info *p_vf;
3483 p_vf = qed_iov_get_vf_info(p_hwfn, rel_vf_id, true);
3484 if (!p_vf || !p_vf->bulletin.p_virt)
3485 return NULL;
3487 if (!(p_vf->bulletin.p_virt->valid_bitmap & BIT(MAC_ADDR_FORCED)))
3488 return NULL;
3490 return p_vf->bulletin.p_virt->mac;
3493 static u16
3494 qed_iov_bulletin_get_forced_vlan(struct qed_hwfn *p_hwfn, u16 rel_vf_id)
3496 struct qed_vf_info *p_vf;
3498 p_vf = qed_iov_get_vf_info(p_hwfn, rel_vf_id, true);
3499 if (!p_vf || !p_vf->bulletin.p_virt)
3500 return 0;
3502 if (!(p_vf->bulletin.p_virt->valid_bitmap & BIT(VLAN_ADDR_FORCED)))
3503 return 0;
3505 return p_vf->bulletin.p_virt->pvid;
3508 static int qed_iov_configure_tx_rate(struct qed_hwfn *p_hwfn,
3509 struct qed_ptt *p_ptt, int vfid, int val)
3511 struct qed_vf_info *vf;
3512 u8 abs_vp_id = 0;
3513 int rc;
3515 vf = qed_iov_get_vf_info(p_hwfn, (u16)vfid, true);
3516 if (!vf)
3517 return -EINVAL;
3519 rc = qed_fw_vport(p_hwfn, vf->vport_id, &abs_vp_id);
3520 if (rc)
3521 return rc;
3523 return qed_init_vport_rl(p_hwfn, p_ptt, abs_vp_id, (u32)val);
3526 static int
3527 qed_iov_configure_min_tx_rate(struct qed_dev *cdev, int vfid, u32 rate)
3529 struct qed_vf_info *vf;
3530 u8 vport_id;
3531 int i;
3533 for_each_hwfn(cdev, i) {
3534 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
3536 if (!qed_iov_pf_sanity_check(p_hwfn, vfid)) {
3537 DP_NOTICE(p_hwfn,
3538 "SR-IOV sanity check failed, can't set min rate\n");
3539 return -EINVAL;
3543 vf = qed_iov_get_vf_info(QED_LEADING_HWFN(cdev), (u16)vfid, true);
3544 vport_id = vf->vport_id;
3546 return qed_configure_vport_wfq(cdev, vport_id, rate);
3549 static int qed_iov_get_vf_min_rate(struct qed_hwfn *p_hwfn, int vfid)
3551 struct qed_wfq_data *vf_vp_wfq;
3552 struct qed_vf_info *vf_info;
3554 vf_info = qed_iov_get_vf_info(p_hwfn, (u16) vfid, true);
3555 if (!vf_info)
3556 return 0;
3558 vf_vp_wfq = &p_hwfn->qm_info.wfq_data[vf_info->vport_id];
3560 if (vf_vp_wfq->configured)
3561 return vf_vp_wfq->min_speed;
3562 else
3563 return 0;
3567 * qed_schedule_iov - schedules IOV task for VF and PF
3568 * @hwfn: hardware function pointer
3569 * @flag: IOV flag for VF/PF
3571 void qed_schedule_iov(struct qed_hwfn *hwfn, enum qed_iov_wq_flag flag)
3573 smp_mb__before_atomic();
3574 set_bit(flag, &hwfn->iov_task_flags);
3575 smp_mb__after_atomic();
3576 DP_VERBOSE(hwfn, QED_MSG_IOV, "Scheduling iov task [Flag: %d]\n", flag);
3577 queue_delayed_work(hwfn->iov_wq, &hwfn->iov_task, 0);
3580 void qed_vf_start_iov_wq(struct qed_dev *cdev)
3582 int i;
3584 for_each_hwfn(cdev, i)
3585 queue_delayed_work(cdev->hwfns[i].iov_wq,
3586 &cdev->hwfns[i].iov_task, 0);
3589 int qed_sriov_disable(struct qed_dev *cdev, bool pci_enabled)
3591 int i, j;
3593 for_each_hwfn(cdev, i)
3594 if (cdev->hwfns[i].iov_wq)
3595 flush_workqueue(cdev->hwfns[i].iov_wq);
3597 /* Mark VFs for disablement */
3598 qed_iov_set_vfs_to_disable(cdev, true);
3600 if (cdev->p_iov_info && cdev->p_iov_info->num_vfs && pci_enabled)
3601 pci_disable_sriov(cdev->pdev);
3603 for_each_hwfn(cdev, i) {
3604 struct qed_hwfn *hwfn = &cdev->hwfns[i];
3605 struct qed_ptt *ptt = qed_ptt_acquire(hwfn);
3607 /* Failure to acquire the ptt in 100g creates an odd error
3608 * where the first engine has already relased IOV.
3610 if (!ptt) {
3611 DP_ERR(hwfn, "Failed to acquire ptt\n");
3612 return -EBUSY;
3615 /* Clean WFQ db and configure equal weight for all vports */
3616 qed_clean_wfq_db(hwfn, ptt);
3618 qed_for_each_vf(hwfn, j) {
3619 int k;
3621 if (!qed_iov_is_valid_vfid(hwfn, j, true, false))
3622 continue;
3624 /* Wait until VF is disabled before releasing */
3625 for (k = 0; k < 100; k++) {
3626 if (!qed_iov_is_vf_stopped(hwfn, j))
3627 msleep(20);
3628 else
3629 break;
3632 if (k < 100)
3633 qed_iov_release_hw_for_vf(&cdev->hwfns[i],
3634 ptt, j);
3635 else
3636 DP_ERR(hwfn,
3637 "Timeout waiting for VF's FLR to end\n");
3640 qed_ptt_release(hwfn, ptt);
3643 qed_iov_set_vfs_to_disable(cdev, false);
3645 return 0;
3648 static void qed_sriov_enable_qid_config(struct qed_hwfn *hwfn,
3649 u16 vfid,
3650 struct qed_iov_vf_init_params *params)
3652 u16 base, i;
3654 /* Since we have an equal resource distribution per-VF, and we assume
3655 * PF has acquired the QED_PF_L2_QUE first queues, we start setting
3656 * sequentially from there.
3658 base = FEAT_NUM(hwfn, QED_PF_L2_QUE) + vfid * params->num_queues;
3660 params->rel_vf_id = vfid;
3661 for (i = 0; i < params->num_queues; i++) {
3662 params->req_rx_queue[i] = base + i;
3663 params->req_tx_queue[i] = base + i;
3667 static int qed_sriov_enable(struct qed_dev *cdev, int num)
3669 struct qed_iov_vf_init_params params;
3670 int i, j, rc;
3672 if (num >= RESC_NUM(&cdev->hwfns[0], QED_VPORT)) {
3673 DP_NOTICE(cdev, "Can start at most %d VFs\n",
3674 RESC_NUM(&cdev->hwfns[0], QED_VPORT) - 1);
3675 return -EINVAL;
3678 memset(&params, 0, sizeof(params));
3680 /* Initialize HW for VF access */
3681 for_each_hwfn(cdev, j) {
3682 struct qed_hwfn *hwfn = &cdev->hwfns[j];
3683 struct qed_ptt *ptt = qed_ptt_acquire(hwfn);
3685 /* Make sure not to use more than 16 queues per VF */
3686 params.num_queues = min_t(int,
3687 FEAT_NUM(hwfn, QED_VF_L2_QUE) / num,
3688 16);
3690 if (!ptt) {
3691 DP_ERR(hwfn, "Failed to acquire ptt\n");
3692 rc = -EBUSY;
3693 goto err;
3696 for (i = 0; i < num; i++) {
3697 if (!qed_iov_is_valid_vfid(hwfn, i, false, true))
3698 continue;
3700 qed_sriov_enable_qid_config(hwfn, i, &params);
3701 rc = qed_iov_init_hw_for_vf(hwfn, ptt, &params);
3702 if (rc) {
3703 DP_ERR(cdev, "Failed to enable VF[%d]\n", i);
3704 qed_ptt_release(hwfn, ptt);
3705 goto err;
3709 qed_ptt_release(hwfn, ptt);
3712 /* Enable SRIOV PCIe functions */
3713 rc = pci_enable_sriov(cdev->pdev, num);
3714 if (rc) {
3715 DP_ERR(cdev, "Failed to enable sriov [%d]\n", rc);
3716 goto err;
3719 return num;
3721 err:
3722 qed_sriov_disable(cdev, false);
3723 return rc;
3726 static int qed_sriov_configure(struct qed_dev *cdev, int num_vfs_param)
3728 if (!IS_QED_SRIOV(cdev)) {
3729 DP_VERBOSE(cdev, QED_MSG_IOV, "SR-IOV is not supported\n");
3730 return -EOPNOTSUPP;
3733 if (num_vfs_param)
3734 return qed_sriov_enable(cdev, num_vfs_param);
3735 else
3736 return qed_sriov_disable(cdev, true);
3739 static int qed_sriov_pf_set_mac(struct qed_dev *cdev, u8 *mac, int vfid)
3741 int i;
3743 if (!IS_QED_SRIOV(cdev) || !IS_PF_SRIOV_ALLOC(&cdev->hwfns[0])) {
3744 DP_VERBOSE(cdev, QED_MSG_IOV,
3745 "Cannot set a VF MAC; Sriov is not enabled\n");
3746 return -EINVAL;
3749 if (!qed_iov_is_valid_vfid(&cdev->hwfns[0], vfid, true, true)) {
3750 DP_VERBOSE(cdev, QED_MSG_IOV,
3751 "Cannot set VF[%d] MAC (VF is not active)\n", vfid);
3752 return -EINVAL;
3755 for_each_hwfn(cdev, i) {
3756 struct qed_hwfn *hwfn = &cdev->hwfns[i];
3757 struct qed_public_vf_info *vf_info;
3759 vf_info = qed_iov_get_public_vf_info(hwfn, vfid, true);
3760 if (!vf_info)
3761 continue;
3763 /* Set the forced MAC, and schedule the IOV task */
3764 ether_addr_copy(vf_info->forced_mac, mac);
3765 qed_schedule_iov(hwfn, QED_IOV_WQ_SET_UNICAST_FILTER_FLAG);
3768 return 0;
3771 static int qed_sriov_pf_set_vlan(struct qed_dev *cdev, u16 vid, int vfid)
3773 int i;
3775 if (!IS_QED_SRIOV(cdev) || !IS_PF_SRIOV_ALLOC(&cdev->hwfns[0])) {
3776 DP_VERBOSE(cdev, QED_MSG_IOV,
3777 "Cannot set a VF MAC; Sriov is not enabled\n");
3778 return -EINVAL;
3781 if (!qed_iov_is_valid_vfid(&cdev->hwfns[0], vfid, true, true)) {
3782 DP_VERBOSE(cdev, QED_MSG_IOV,
3783 "Cannot set VF[%d] MAC (VF is not active)\n", vfid);
3784 return -EINVAL;
3787 for_each_hwfn(cdev, i) {
3788 struct qed_hwfn *hwfn = &cdev->hwfns[i];
3789 struct qed_public_vf_info *vf_info;
3791 vf_info = qed_iov_get_public_vf_info(hwfn, vfid, true);
3792 if (!vf_info)
3793 continue;
3795 /* Set the forced vlan, and schedule the IOV task */
3796 vf_info->forced_vlan = vid;
3797 qed_schedule_iov(hwfn, QED_IOV_WQ_SET_UNICAST_FILTER_FLAG);
3800 return 0;
3803 static int qed_get_vf_config(struct qed_dev *cdev,
3804 int vf_id, struct ifla_vf_info *ivi)
3806 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
3807 struct qed_public_vf_info *vf_info;
3808 struct qed_mcp_link_state link;
3809 u32 tx_rate;
3811 /* Sanitize request */
3812 if (IS_VF(cdev))
3813 return -EINVAL;
3815 if (!qed_iov_is_valid_vfid(&cdev->hwfns[0], vf_id, true, false)) {
3816 DP_VERBOSE(cdev, QED_MSG_IOV,
3817 "VF index [%d] isn't active\n", vf_id);
3818 return -EINVAL;
3821 vf_info = qed_iov_get_public_vf_info(hwfn, vf_id, true);
3823 qed_iov_get_link(hwfn, vf_id, NULL, &link, NULL);
3825 /* Fill information about VF */
3826 ivi->vf = vf_id;
3828 if (is_valid_ether_addr(vf_info->forced_mac))
3829 ether_addr_copy(ivi->mac, vf_info->forced_mac);
3830 else
3831 ether_addr_copy(ivi->mac, vf_info->mac);
3833 ivi->vlan = vf_info->forced_vlan;
3834 ivi->spoofchk = qed_iov_spoofchk_get(hwfn, vf_id);
3835 ivi->linkstate = vf_info->link_state;
3836 tx_rate = vf_info->tx_rate;
3837 ivi->max_tx_rate = tx_rate ? tx_rate : link.speed;
3838 ivi->min_tx_rate = qed_iov_get_vf_min_rate(hwfn, vf_id);
3840 return 0;
3843 void qed_inform_vf_link_state(struct qed_hwfn *hwfn)
3845 struct qed_mcp_link_capabilities caps;
3846 struct qed_mcp_link_params params;
3847 struct qed_mcp_link_state link;
3848 int i;
3850 if (!hwfn->pf_iov_info)
3851 return;
3853 /* Update bulletin of all future possible VFs with link configuration */
3854 for (i = 0; i < hwfn->cdev->p_iov_info->total_vfs; i++) {
3855 struct qed_public_vf_info *vf_info;
3857 vf_info = qed_iov_get_public_vf_info(hwfn, i, false);
3858 if (!vf_info)
3859 continue;
3861 memcpy(&params, qed_mcp_get_link_params(hwfn), sizeof(params));
3862 memcpy(&link, qed_mcp_get_link_state(hwfn), sizeof(link));
3863 memcpy(&caps, qed_mcp_get_link_capabilities(hwfn),
3864 sizeof(caps));
3866 /* Modify link according to the VF's configured link state */
3867 switch (vf_info->link_state) {
3868 case IFLA_VF_LINK_STATE_DISABLE:
3869 link.link_up = false;
3870 break;
3871 case IFLA_VF_LINK_STATE_ENABLE:
3872 link.link_up = true;
3873 /* Set speed according to maximum supported by HW.
3874 * that is 40G for regular devices and 100G for CMT
3875 * mode devices.
3877 link.speed = (hwfn->cdev->num_hwfns > 1) ?
3878 100000 : 40000;
3879 default:
3880 /* In auto mode pass PF link image to VF */
3881 break;
3884 if (link.link_up && vf_info->tx_rate) {
3885 struct qed_ptt *ptt;
3886 int rate;
3888 rate = min_t(int, vf_info->tx_rate, link.speed);
3890 ptt = qed_ptt_acquire(hwfn);
3891 if (!ptt) {
3892 DP_NOTICE(hwfn, "Failed to acquire PTT\n");
3893 return;
3896 if (!qed_iov_configure_tx_rate(hwfn, ptt, i, rate)) {
3897 vf_info->tx_rate = rate;
3898 link.speed = rate;
3901 qed_ptt_release(hwfn, ptt);
3904 qed_iov_set_link(hwfn, i, &params, &link, &caps);
3907 qed_schedule_iov(hwfn, QED_IOV_WQ_BULLETIN_UPDATE_FLAG);
3910 static int qed_set_vf_link_state(struct qed_dev *cdev,
3911 int vf_id, int link_state)
3913 int i;
3915 /* Sanitize request */
3916 if (IS_VF(cdev))
3917 return -EINVAL;
3919 if (!qed_iov_is_valid_vfid(&cdev->hwfns[0], vf_id, true, true)) {
3920 DP_VERBOSE(cdev, QED_MSG_IOV,
3921 "VF index [%d] isn't active\n", vf_id);
3922 return -EINVAL;
3925 /* Handle configuration of link state */
3926 for_each_hwfn(cdev, i) {
3927 struct qed_hwfn *hwfn = &cdev->hwfns[i];
3928 struct qed_public_vf_info *vf;
3930 vf = qed_iov_get_public_vf_info(hwfn, vf_id, true);
3931 if (!vf)
3932 continue;
3934 if (vf->link_state == link_state)
3935 continue;
3937 vf->link_state = link_state;
3938 qed_inform_vf_link_state(&cdev->hwfns[i]);
3941 return 0;
3944 static int qed_spoof_configure(struct qed_dev *cdev, int vfid, bool val)
3946 int i, rc = -EINVAL;
3948 for_each_hwfn(cdev, i) {
3949 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
3951 rc = qed_iov_spoofchk_set(p_hwfn, vfid, val);
3952 if (rc)
3953 break;
3956 return rc;
3959 static int qed_configure_max_vf_rate(struct qed_dev *cdev, int vfid, int rate)
3961 int i;
3963 for_each_hwfn(cdev, i) {
3964 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
3965 struct qed_public_vf_info *vf;
3967 if (!qed_iov_pf_sanity_check(p_hwfn, vfid)) {
3968 DP_NOTICE(p_hwfn,
3969 "SR-IOV sanity check failed, can't set tx rate\n");
3970 return -EINVAL;
3973 vf = qed_iov_get_public_vf_info(p_hwfn, vfid, true);
3975 vf->tx_rate = rate;
3977 qed_inform_vf_link_state(p_hwfn);
3980 return 0;
3983 static int qed_set_vf_rate(struct qed_dev *cdev,
3984 int vfid, u32 min_rate, u32 max_rate)
3986 int rc_min = 0, rc_max = 0;
3988 if (max_rate)
3989 rc_max = qed_configure_max_vf_rate(cdev, vfid, max_rate);
3991 if (min_rate)
3992 rc_min = qed_iov_configure_min_tx_rate(cdev, vfid, min_rate);
3994 if (rc_max | rc_min)
3995 return -EINVAL;
3997 return 0;
4000 static int qed_set_vf_trust(struct qed_dev *cdev, int vfid, bool trust)
4002 int i;
4004 for_each_hwfn(cdev, i) {
4005 struct qed_hwfn *hwfn = &cdev->hwfns[i];
4006 struct qed_public_vf_info *vf;
4008 if (!qed_iov_pf_sanity_check(hwfn, vfid)) {
4009 DP_NOTICE(hwfn,
4010 "SR-IOV sanity check failed, can't set trust\n");
4011 return -EINVAL;
4014 vf = qed_iov_get_public_vf_info(hwfn, vfid, true);
4016 if (vf->is_trusted_request == trust)
4017 return 0;
4018 vf->is_trusted_request = trust;
4020 qed_schedule_iov(hwfn, QED_IOV_WQ_TRUST_FLAG);
4023 return 0;
4026 static void qed_handle_vf_msg(struct qed_hwfn *hwfn)
4028 u64 events[QED_VF_ARRAY_LENGTH];
4029 struct qed_ptt *ptt;
4030 int i;
4032 ptt = qed_ptt_acquire(hwfn);
4033 if (!ptt) {
4034 DP_VERBOSE(hwfn, QED_MSG_IOV,
4035 "Can't acquire PTT; re-scheduling\n");
4036 qed_schedule_iov(hwfn, QED_IOV_WQ_MSG_FLAG);
4037 return;
4040 qed_iov_pf_get_pending_events(hwfn, events);
4042 DP_VERBOSE(hwfn, QED_MSG_IOV,
4043 "Event mask of VF events: 0x%llx 0x%llx 0x%llx\n",
4044 events[0], events[1], events[2]);
4046 qed_for_each_vf(hwfn, i) {
4047 /* Skip VFs with no pending messages */
4048 if (!(events[i / 64] & (1ULL << (i % 64))))
4049 continue;
4051 DP_VERBOSE(hwfn, QED_MSG_IOV,
4052 "Handling VF message from VF 0x%02x [Abs 0x%02x]\n",
4053 i, hwfn->cdev->p_iov_info->first_vf_in_pf + i);
4055 /* Copy VF's message to PF's request buffer for that VF */
4056 if (qed_iov_copy_vf_msg(hwfn, ptt, i))
4057 continue;
4059 qed_iov_process_mbx_req(hwfn, ptt, i);
4062 qed_ptt_release(hwfn, ptt);
4065 static void qed_handle_pf_set_vf_unicast(struct qed_hwfn *hwfn)
4067 int i;
4069 qed_for_each_vf(hwfn, i) {
4070 struct qed_public_vf_info *info;
4071 bool update = false;
4072 u8 *mac;
4074 info = qed_iov_get_public_vf_info(hwfn, i, true);
4075 if (!info)
4076 continue;
4078 /* Update data on bulletin board */
4079 mac = qed_iov_bulletin_get_forced_mac(hwfn, i);
4080 if (is_valid_ether_addr(info->forced_mac) &&
4081 (!mac || !ether_addr_equal(mac, info->forced_mac))) {
4082 DP_VERBOSE(hwfn,
4083 QED_MSG_IOV,
4084 "Handling PF setting of VF MAC to VF 0x%02x [Abs 0x%02x]\n",
4086 hwfn->cdev->p_iov_info->first_vf_in_pf + i);
4088 /* Update bulletin board with forced MAC */
4089 qed_iov_bulletin_set_forced_mac(hwfn,
4090 info->forced_mac, i);
4091 update = true;
4094 if (qed_iov_bulletin_get_forced_vlan(hwfn, i) ^
4095 info->forced_vlan) {
4096 DP_VERBOSE(hwfn,
4097 QED_MSG_IOV,
4098 "Handling PF setting of pvid [0x%04x] to VF 0x%02x [Abs 0x%02x]\n",
4099 info->forced_vlan,
4101 hwfn->cdev->p_iov_info->first_vf_in_pf + i);
4102 qed_iov_bulletin_set_forced_vlan(hwfn,
4103 info->forced_vlan, i);
4104 update = true;
4107 if (update)
4108 qed_schedule_iov(hwfn, QED_IOV_WQ_BULLETIN_UPDATE_FLAG);
4112 static void qed_handle_bulletin_post(struct qed_hwfn *hwfn)
4114 struct qed_ptt *ptt;
4115 int i;
4117 ptt = qed_ptt_acquire(hwfn);
4118 if (!ptt) {
4119 DP_NOTICE(hwfn, "Failed allocating a ptt entry\n");
4120 qed_schedule_iov(hwfn, QED_IOV_WQ_BULLETIN_UPDATE_FLAG);
4121 return;
4124 qed_for_each_vf(hwfn, i)
4125 qed_iov_post_vf_bulletin(hwfn, i, ptt);
4127 qed_ptt_release(hwfn, ptt);
4130 static void qed_iov_handle_trust_change(struct qed_hwfn *hwfn)
4132 struct qed_sp_vport_update_params params;
4133 struct qed_filter_accept_flags *flags;
4134 struct qed_public_vf_info *vf_info;
4135 struct qed_vf_info *vf;
4136 u8 mask;
4137 int i;
4139 mask = QED_ACCEPT_UCAST_UNMATCHED | QED_ACCEPT_MCAST_UNMATCHED;
4140 flags = &params.accept_flags;
4142 qed_for_each_vf(hwfn, i) {
4143 /* Need to make sure current requested configuration didn't
4144 * flip so that we'll end up configuring something that's not
4145 * needed.
4147 vf_info = qed_iov_get_public_vf_info(hwfn, i, true);
4148 if (vf_info->is_trusted_configured ==
4149 vf_info->is_trusted_request)
4150 continue;
4151 vf_info->is_trusted_configured = vf_info->is_trusted_request;
4153 /* Validate that the VF has a configured vport */
4154 vf = qed_iov_get_vf_info(hwfn, i, true);
4155 if (!vf->vport_instance)
4156 continue;
4158 memset(&params, 0, sizeof(params));
4159 params.opaque_fid = vf->opaque_fid;
4160 params.vport_id = vf->vport_id;
4162 if (vf_info->rx_accept_mode & mask) {
4163 flags->update_rx_mode_config = 1;
4164 flags->rx_accept_filter = vf_info->rx_accept_mode;
4167 if (vf_info->tx_accept_mode & mask) {
4168 flags->update_tx_mode_config = 1;
4169 flags->tx_accept_filter = vf_info->tx_accept_mode;
4172 /* Remove if needed; Otherwise this would set the mask */
4173 if (!vf_info->is_trusted_configured) {
4174 flags->rx_accept_filter &= ~mask;
4175 flags->tx_accept_filter &= ~mask;
4178 if (flags->update_rx_mode_config ||
4179 flags->update_tx_mode_config)
4180 qed_sp_vport_update(hwfn, &params,
4181 QED_SPQ_MODE_EBLOCK, NULL);
4185 static void qed_iov_pf_task(struct work_struct *work)
4188 struct qed_hwfn *hwfn = container_of(work, struct qed_hwfn,
4189 iov_task.work);
4190 int rc;
4192 if (test_and_clear_bit(QED_IOV_WQ_STOP_WQ_FLAG, &hwfn->iov_task_flags))
4193 return;
4195 if (test_and_clear_bit(QED_IOV_WQ_FLR_FLAG, &hwfn->iov_task_flags)) {
4196 struct qed_ptt *ptt = qed_ptt_acquire(hwfn);
4198 if (!ptt) {
4199 qed_schedule_iov(hwfn, QED_IOV_WQ_FLR_FLAG);
4200 return;
4203 rc = qed_iov_vf_flr_cleanup(hwfn, ptt);
4204 if (rc)
4205 qed_schedule_iov(hwfn, QED_IOV_WQ_FLR_FLAG);
4207 qed_ptt_release(hwfn, ptt);
4210 if (test_and_clear_bit(QED_IOV_WQ_MSG_FLAG, &hwfn->iov_task_flags))
4211 qed_handle_vf_msg(hwfn);
4213 if (test_and_clear_bit(QED_IOV_WQ_SET_UNICAST_FILTER_FLAG,
4214 &hwfn->iov_task_flags))
4215 qed_handle_pf_set_vf_unicast(hwfn);
4217 if (test_and_clear_bit(QED_IOV_WQ_BULLETIN_UPDATE_FLAG,
4218 &hwfn->iov_task_flags))
4219 qed_handle_bulletin_post(hwfn);
4221 if (test_and_clear_bit(QED_IOV_WQ_TRUST_FLAG, &hwfn->iov_task_flags))
4222 qed_iov_handle_trust_change(hwfn);
4225 void qed_iov_wq_stop(struct qed_dev *cdev, bool schedule_first)
4227 int i;
4229 for_each_hwfn(cdev, i) {
4230 if (!cdev->hwfns[i].iov_wq)
4231 continue;
4233 if (schedule_first) {
4234 qed_schedule_iov(&cdev->hwfns[i],
4235 QED_IOV_WQ_STOP_WQ_FLAG);
4236 cancel_delayed_work_sync(&cdev->hwfns[i].iov_task);
4239 flush_workqueue(cdev->hwfns[i].iov_wq);
4240 destroy_workqueue(cdev->hwfns[i].iov_wq);
4244 int qed_iov_wq_start(struct qed_dev *cdev)
4246 char name[NAME_SIZE];
4247 int i;
4249 for_each_hwfn(cdev, i) {
4250 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
4252 /* PFs needs a dedicated workqueue only if they support IOV.
4253 * VFs always require one.
4255 if (IS_PF(p_hwfn->cdev) && !IS_PF_SRIOV(p_hwfn))
4256 continue;
4258 snprintf(name, NAME_SIZE, "iov-%02x:%02x.%02x",
4259 cdev->pdev->bus->number,
4260 PCI_SLOT(cdev->pdev->devfn), p_hwfn->abs_pf_id);
4262 p_hwfn->iov_wq = create_singlethread_workqueue(name);
4263 if (!p_hwfn->iov_wq) {
4264 DP_NOTICE(p_hwfn, "Cannot create iov workqueue\n");
4265 return -ENOMEM;
4268 if (IS_PF(cdev))
4269 INIT_DELAYED_WORK(&p_hwfn->iov_task, qed_iov_pf_task);
4270 else
4271 INIT_DELAYED_WORK(&p_hwfn->iov_task, qed_iov_vf_task);
4274 return 0;
4277 const struct qed_iov_hv_ops qed_iov_ops_pass = {
4278 .configure = &qed_sriov_configure,
4279 .set_mac = &qed_sriov_pf_set_mac,
4280 .set_vlan = &qed_sriov_pf_set_vlan,
4281 .get_config = &qed_get_vf_config,
4282 .set_link_state = &qed_set_vf_link_state,
4283 .set_spoof = &qed_spoof_configure,
4284 .set_rate = &qed_set_vf_rate,
4285 .set_trust = &qed_set_vf_trust,