1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright (c) 2016 - 2018 Cavium Inc.
10 #include "ecore_sriov.h"
11 #include "ecore_status.h"
13 #include "ecore_hw_defs.h"
14 #include "ecore_int.h"
15 #include "ecore_hsi_eth.h"
17 #include "ecore_vfpf_if.h"
18 #include "ecore_rt_defs.h"
19 #include "ecore_init_ops.h"
20 #include "ecore_gtt_reg_addr.h"
21 #include "ecore_iro.h"
22 #include "ecore_mcp.h"
23 #include "ecore_cxt.h"
25 #include "ecore_init_fw_funcs.h"
26 #include "ecore_sp_commands.h"
28 static enum _ecore_status_t ecore_sriov_eqe_event(struct ecore_hwfn *p_hwfn,
31 union event_ring_data *data,
34 const char *qede_ecore_channel_tlvs_string[] = {
35 "CHANNEL_TLV_NONE", /* ends tlv sequence */
36 "CHANNEL_TLV_ACQUIRE",
37 "CHANNEL_TLV_VPORT_START",
38 "CHANNEL_TLV_VPORT_UPDATE",
39 "CHANNEL_TLV_VPORT_TEARDOWN",
40 "CHANNEL_TLV_START_RXQ",
41 "CHANNEL_TLV_START_TXQ",
42 "CHANNEL_TLV_STOP_RXQ",
43 "CHANNEL_TLV_STOP_TXQ",
44 "CHANNEL_TLV_UPDATE_RXQ",
45 "CHANNEL_TLV_INT_CLEANUP",
47 "CHANNEL_TLV_RELEASE",
48 "CHANNEL_TLV_LIST_END",
49 "CHANNEL_TLV_UCAST_FILTER",
50 "CHANNEL_TLV_VPORT_UPDATE_ACTIVATE",
51 "CHANNEL_TLV_VPORT_UPDATE_TX_SWITCH",
52 "CHANNEL_TLV_VPORT_UPDATE_VLAN_STRIP",
53 "CHANNEL_TLV_VPORT_UPDATE_MCAST",
54 "CHANNEL_TLV_VPORT_UPDATE_ACCEPT_PARAM",
55 "CHANNEL_TLV_VPORT_UPDATE_RSS",
56 "CHANNEL_TLV_VPORT_UPDATE_ACCEPT_ANY_VLAN",
57 "CHANNEL_TLV_VPORT_UPDATE_SGE_TPA",
58 "CHANNEL_TLV_UPDATE_TUNN_PARAM",
59 "CHANNEL_TLV_COALESCE_UPDATE",
61 "CHANNEL_TLV_COALESCE_READ",
62 "CHANNEL_TLV_BULLETIN_UPDATE_MAC",
63 "CHANNEL_TLV_UPDATE_MTU",
67 static u8 ecore_vf_calculate_legacy(struct ecore_vf_info *p_vf)
71 if (p_vf->acquire.vfdev_info.eth_fp_hsi_minor ==
72 ETH_HSI_VER_NO_PKT_LEN_TUNN)
73 legacy |= ECORE_QCID_LEGACY_VF_RX_PROD;
75 if (!(p_vf->acquire.vfdev_info.capabilities &
76 VFPF_ACQUIRE_CAP_QUEUE_QIDS))
77 legacy |= ECORE_QCID_LEGACY_VF_CID;
83 static enum _ecore_status_t ecore_sp_vf_start(struct ecore_hwfn *p_hwfn,
84 struct ecore_vf_info *p_vf)
86 struct vf_start_ramrod_data *p_ramrod = OSAL_NULL;
87 struct ecore_spq_entry *p_ent = OSAL_NULL;
88 struct ecore_sp_init_data init_data;
89 enum _ecore_status_t rc = ECORE_NOTIMPL;
93 OSAL_MEMSET(&init_data, 0, sizeof(init_data));
94 init_data.cid = ecore_spq_get_cid(p_hwfn);
95 init_data.opaque_fid = p_vf->opaque_fid;
96 init_data.comp_mode = ECORE_SPQ_MODE_EBLOCK;
98 rc = ecore_sp_init_request(p_hwfn, &p_ent,
99 COMMON_RAMROD_VF_START,
100 PROTOCOLID_COMMON, &init_data);
101 if (rc != ECORE_SUCCESS)
104 p_ramrod = &p_ent->ramrod.vf_start;
106 p_ramrod->vf_id = GET_FIELD(p_vf->concrete_fid, PXP_CONCRETE_FID_VFID);
107 p_ramrod->opaque_fid = OSAL_CPU_TO_LE16(p_vf->opaque_fid);
109 switch (p_hwfn->hw_info.personality) {
111 p_ramrod->personality = PERSONALITY_ETH;
113 case ECORE_PCI_ETH_ROCE:
114 case ECORE_PCI_ETH_IWARP:
115 p_ramrod->personality = PERSONALITY_RDMA_AND_ETH;
118 DP_NOTICE(p_hwfn, true, "Unknown VF personality %d\n",
119 p_hwfn->hw_info.personality);
123 fp_minor = p_vf->acquire.vfdev_info.eth_fp_hsi_minor;
124 if (fp_minor > ETH_HSI_VER_MINOR &&
125 fp_minor != ETH_HSI_VER_NO_PKT_LEN_TUNN) {
126 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
127 "VF [%d] - Requested fp hsi %02x.%02x which is"
128 " slightly newer than PF's %02x.%02x; Configuring"
131 ETH_HSI_VER_MAJOR, fp_minor,
132 ETH_HSI_VER_MAJOR, ETH_HSI_VER_MINOR);
133 fp_minor = ETH_HSI_VER_MINOR;
136 p_ramrod->hsi_fp_ver.major_ver_arr[ETH_VER_KEY] = ETH_HSI_VER_MAJOR;
137 p_ramrod->hsi_fp_ver.minor_ver_arr[ETH_VER_KEY] = fp_minor;
139 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
140 "VF[%d] - Starting using HSI %02x.%02x\n",
141 p_vf->abs_vf_id, ETH_HSI_VER_MAJOR, fp_minor);
143 return ecore_spq_post(p_hwfn, p_ent, OSAL_NULL);
146 static enum _ecore_status_t ecore_sp_vf_stop(struct ecore_hwfn *p_hwfn,
150 struct vf_stop_ramrod_data *p_ramrod = OSAL_NULL;
151 struct ecore_spq_entry *p_ent = OSAL_NULL;
152 struct ecore_sp_init_data init_data;
153 enum _ecore_status_t rc = ECORE_NOTIMPL;
156 OSAL_MEMSET(&init_data, 0, sizeof(init_data));
157 init_data.cid = ecore_spq_get_cid(p_hwfn);
158 init_data.opaque_fid = opaque_vfid;
159 init_data.comp_mode = ECORE_SPQ_MODE_EBLOCK;
161 rc = ecore_sp_init_request(p_hwfn, &p_ent,
162 COMMON_RAMROD_VF_STOP,
163 PROTOCOLID_COMMON, &init_data);
164 if (rc != ECORE_SUCCESS)
167 p_ramrod = &p_ent->ramrod.vf_stop;
169 p_ramrod->vf_id = GET_FIELD(concrete_vfid, PXP_CONCRETE_FID_VFID);
171 return ecore_spq_post(p_hwfn, p_ent, OSAL_NULL);
174 bool ecore_iov_is_valid_vfid(struct ecore_hwfn *p_hwfn, int rel_vf_id,
175 bool b_enabled_only, bool b_non_malicious)
177 if (!p_hwfn->pf_iov_info) {
178 DP_NOTICE(p_hwfn->p_dev, true, "No iov info\n");
182 if ((rel_vf_id >= p_hwfn->p_dev->p_iov_info->total_vfs) ||
186 if ((!p_hwfn->pf_iov_info->vfs_array[rel_vf_id].b_init) &&
190 if ((p_hwfn->pf_iov_info->vfs_array[rel_vf_id].b_malicious) &&
197 struct ecore_vf_info *ecore_iov_get_vf_info(struct ecore_hwfn *p_hwfn,
201 struct ecore_vf_info *vf = OSAL_NULL;
203 if (!p_hwfn->pf_iov_info) {
204 DP_NOTICE(p_hwfn->p_dev, true, "No iov info\n");
208 if (ecore_iov_is_valid_vfid(p_hwfn, relative_vf_id,
209 b_enabled_only, false))
210 vf = &p_hwfn->pf_iov_info->vfs_array[relative_vf_id];
212 DP_ERR(p_hwfn, "ecore_iov_get_vf_info: VF[%d] is not enabled\n",
218 static struct ecore_queue_cid *
219 ecore_iov_get_vf_rx_queue_cid(struct ecore_vf_queue *p_queue)
223 for (i = 0; i < MAX_QUEUES_PER_QZONE; i++) {
224 if (p_queue->cids[i].p_cid &&
225 !p_queue->cids[i].b_is_tx)
226 return p_queue->cids[i].p_cid;
232 enum ecore_iov_validate_q_mode {
233 ECORE_IOV_VALIDATE_Q_NA,
234 ECORE_IOV_VALIDATE_Q_ENABLE,
235 ECORE_IOV_VALIDATE_Q_DISABLE,
238 static bool ecore_iov_validate_queue_mode(struct ecore_vf_info *p_vf,
240 enum ecore_iov_validate_q_mode mode,
245 if (mode == ECORE_IOV_VALIDATE_Q_NA)
248 for (i = 0; i < MAX_QUEUES_PER_QZONE; i++) {
249 struct ecore_vf_queue_cid *p_qcid;
251 p_qcid = &p_vf->vf_queues[qid].cids[i];
253 if (p_qcid->p_cid == OSAL_NULL)
256 if (p_qcid->b_is_tx != b_is_tx)
259 /* Found. It's enabled. */
260 return (mode == ECORE_IOV_VALIDATE_Q_ENABLE);
263 /* In case we haven't found any valid cid, then its disabled */
264 return (mode == ECORE_IOV_VALIDATE_Q_DISABLE);
267 static bool ecore_iov_validate_rxq(struct ecore_hwfn *p_hwfn,
268 struct ecore_vf_info *p_vf,
270 enum ecore_iov_validate_q_mode mode)
272 if (rx_qid >= p_vf->num_rxqs) {
273 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
274 "VF[0x%02x] - can't touch Rx queue[%04x];"
275 " Only 0x%04x are allocated\n",
276 p_vf->abs_vf_id, rx_qid, p_vf->num_rxqs);
280 return ecore_iov_validate_queue_mode(p_vf, rx_qid, mode, false);
283 static bool ecore_iov_validate_txq(struct ecore_hwfn *p_hwfn,
284 struct ecore_vf_info *p_vf,
286 enum ecore_iov_validate_q_mode mode)
288 if (tx_qid >= p_vf->num_txqs) {
289 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
290 "VF[0x%02x] - can't touch Tx queue[%04x];"
291 " Only 0x%04x are allocated\n",
292 p_vf->abs_vf_id, tx_qid, p_vf->num_txqs);
296 return ecore_iov_validate_queue_mode(p_vf, tx_qid, mode, true);
299 static bool ecore_iov_validate_sb(struct ecore_hwfn *p_hwfn,
300 struct ecore_vf_info *p_vf,
305 for (i = 0; i < p_vf->num_sbs; i++)
306 if (p_vf->igu_sbs[i] == sb_idx)
309 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
310 "VF[0%02x] - tried using sb_idx %04x which doesn't exist as"
311 " one of its 0x%02x SBs\n",
312 p_vf->abs_vf_id, sb_idx, p_vf->num_sbs);
317 /* Is there at least 1 queue open? */
318 static bool ecore_iov_validate_active_rxq(struct ecore_vf_info *p_vf)
322 for (i = 0; i < p_vf->num_rxqs; i++)
323 if (ecore_iov_validate_queue_mode(p_vf, i,
324 ECORE_IOV_VALIDATE_Q_ENABLE,
331 static bool ecore_iov_validate_active_txq(struct ecore_vf_info *p_vf)
335 for (i = 0; i < p_vf->num_txqs; i++)
336 if (ecore_iov_validate_queue_mode(p_vf, i,
337 ECORE_IOV_VALIDATE_Q_ENABLE,
344 enum _ecore_status_t ecore_iov_post_vf_bulletin(struct ecore_hwfn *p_hwfn,
346 struct ecore_ptt *p_ptt)
348 struct ecore_bulletin_content *p_bulletin;
349 int crc_size = sizeof(p_bulletin->crc);
350 struct dmae_params params;
351 struct ecore_vf_info *p_vf;
353 p_vf = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
357 /* TODO - check VF is in a state where it can accept message */
358 if (!p_vf->vf_bulletin)
361 p_bulletin = p_vf->bulletin.p_virt;
363 /* Increment bulletin board version and compute crc */
364 p_bulletin->version++;
365 p_bulletin->crc = OSAL_CRC32(0, (u8 *)p_bulletin + crc_size,
366 p_vf->bulletin.size - crc_size);
368 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
369 "Posting Bulletin 0x%08x to VF[%d] (CRC 0x%08x)\n",
370 p_bulletin->version, p_vf->relative_vf_id, p_bulletin->crc);
372 /* propagate bulletin board via dmae to vm memory */
373 OSAL_MEMSET(¶ms, 0, sizeof(params));
374 SET_FIELD(params.flags, DMAE_PARAMS_DST_VF_VALID, 0x1);
375 params.dst_vf_id = p_vf->abs_vf_id;
376 return ecore_dmae_host2host(p_hwfn, p_ptt, p_vf->bulletin.phys,
377 p_vf->vf_bulletin, p_vf->bulletin.size / 4,
381 static enum _ecore_status_t ecore_iov_pci_cfg_info(struct ecore_dev *p_dev)
383 struct ecore_hw_sriov_info *iov = p_dev->p_iov_info;
386 DP_VERBOSE(p_dev, ECORE_MSG_IOV, "sriov ext pos %d\n", pos);
387 OSAL_PCI_READ_CONFIG_WORD(p_dev, pos + PCI_SRIOV_CTRL, &iov->ctrl);
389 OSAL_PCI_READ_CONFIG_WORD(p_dev,
390 pos + PCI_SRIOV_TOTAL_VF, &iov->total_vfs);
391 OSAL_PCI_READ_CONFIG_WORD(p_dev,
392 pos + PCI_SRIOV_INITIAL_VF,
395 OSAL_PCI_READ_CONFIG_WORD(p_dev, pos + PCI_SRIOV_NUM_VF, &iov->num_vfs);
397 /* @@@TODO - in future we might want to add an OSAL here to
398 * allow each OS to decide on its own how to act.
400 DP_VERBOSE(p_dev, ECORE_MSG_IOV,
401 "Number of VFs are already set to non-zero value."
402 " Ignoring PCI configuration value\n");
406 OSAL_PCI_READ_CONFIG_WORD(p_dev,
407 pos + PCI_SRIOV_VF_OFFSET, &iov->offset);
409 OSAL_PCI_READ_CONFIG_WORD(p_dev,
410 pos + PCI_SRIOV_VF_STRIDE, &iov->stride);
412 OSAL_PCI_READ_CONFIG_WORD(p_dev,
413 pos + PCI_SRIOV_VF_DID, &iov->vf_device_id);
415 OSAL_PCI_READ_CONFIG_DWORD(p_dev,
416 pos + PCI_SRIOV_SUP_PGSIZE, &iov->pgsz);
418 OSAL_PCI_READ_CONFIG_DWORD(p_dev, pos + PCI_SRIOV_CAP, &iov->cap);
420 OSAL_PCI_READ_CONFIG_BYTE(p_dev, pos + PCI_SRIOV_FUNC_LINK, &iov->link);
422 DP_VERBOSE(p_dev, ECORE_MSG_IOV, "IOV info: nres %d, cap 0x%x,"
423 "ctrl 0x%x, total %d, initial %d, num vfs %d, offset %d,"
424 " stride %d, page size 0x%x\n",
425 iov->nres, iov->cap, iov->ctrl,
426 iov->total_vfs, iov->initial_vfs, iov->nr_virtfn,
427 iov->offset, iov->stride, iov->pgsz);
429 /* Some sanity checks */
430 if (iov->num_vfs > NUM_OF_VFS(p_dev) ||
431 iov->total_vfs > NUM_OF_VFS(p_dev)) {
432 /* This can happen only due to a bug. In this case we set
433 * num_vfs to zero to avoid memory corruption in the code that
434 * assumes max number of vfs
436 DP_NOTICE(p_dev, false,
437 "IOV: Unexpected number of vfs set: %d"
438 " setting num_vf to zero\n",
445 return ECORE_SUCCESS;
448 static void ecore_iov_setup_vfdb(struct ecore_hwfn *p_hwfn)
450 struct ecore_hw_sriov_info *p_iov = p_hwfn->p_dev->p_iov_info;
451 struct ecore_pf_iov *p_iov_info = p_hwfn->pf_iov_info;
452 struct ecore_bulletin_content *p_bulletin_virt;
453 dma_addr_t req_p, rply_p, bulletin_p;
454 union pfvf_tlvs *p_reply_virt_addr;
455 union vfpf_tlvs *p_req_virt_addr;
458 OSAL_MEMSET(p_iov_info->vfs_array, 0, sizeof(p_iov_info->vfs_array));
460 p_req_virt_addr = p_iov_info->mbx_msg_virt_addr;
461 req_p = p_iov_info->mbx_msg_phys_addr;
462 p_reply_virt_addr = p_iov_info->mbx_reply_virt_addr;
463 rply_p = p_iov_info->mbx_reply_phys_addr;
464 p_bulletin_virt = p_iov_info->p_bulletins;
465 bulletin_p = p_iov_info->bulletins_phys;
466 if (!p_req_virt_addr || !p_reply_virt_addr || !p_bulletin_virt) {
468 "ecore_iov_setup_vfdb called without alloc mem first\n");
472 for (idx = 0; idx < p_iov->total_vfs; idx++) {
473 struct ecore_vf_info *vf = &p_iov_info->vfs_array[idx];
476 vf->vf_mbx.req_virt = p_req_virt_addr + idx;
477 vf->vf_mbx.req_phys = req_p + idx * sizeof(union vfpf_tlvs);
478 vf->vf_mbx.reply_virt = p_reply_virt_addr + idx;
479 vf->vf_mbx.reply_phys = rply_p + idx * sizeof(union pfvf_tlvs);
481 #ifdef CONFIG_ECORE_SW_CHANNEL
482 vf->vf_mbx.sw_mbx.request_size = sizeof(union vfpf_tlvs);
483 vf->vf_mbx.sw_mbx.mbx_state = VF_PF_WAIT_FOR_START_REQUEST;
485 vf->state = VF_STOPPED;
488 vf->bulletin.phys = idx *
489 sizeof(struct ecore_bulletin_content) + bulletin_p;
490 vf->bulletin.p_virt = p_bulletin_virt + idx;
491 vf->bulletin.size = sizeof(struct ecore_bulletin_content);
493 vf->relative_vf_id = idx;
494 vf->abs_vf_id = idx + p_iov->first_vf_in_pf;
495 concrete = ecore_vfid_to_concrete(p_hwfn, vf->abs_vf_id);
496 vf->concrete_fid = concrete;
497 /* TODO - need to devise a better way of getting opaque */
498 vf->opaque_fid = (p_hwfn->hw_info.opaque_fid & 0xff) |
499 (vf->abs_vf_id << 8);
501 vf->num_mac_filters = ECORE_ETH_VF_NUM_MAC_FILTERS;
502 vf->num_vlan_filters = ECORE_ETH_VF_NUM_VLAN_FILTERS;
506 static enum _ecore_status_t ecore_iov_allocate_vfdb(struct ecore_hwfn *p_hwfn)
508 struct ecore_pf_iov *p_iov_info = p_hwfn->pf_iov_info;
512 num_vfs = p_hwfn->p_dev->p_iov_info->total_vfs;
514 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
515 "ecore_iov_allocate_vfdb for %d VFs\n", num_vfs);
517 /* Allocate PF Mailbox buffer (per-VF) */
518 p_iov_info->mbx_msg_size = sizeof(union vfpf_tlvs) * num_vfs;
519 p_v_addr = &p_iov_info->mbx_msg_virt_addr;
520 *p_v_addr = OSAL_DMA_ALLOC_COHERENT(p_hwfn->p_dev,
521 &p_iov_info->mbx_msg_phys_addr,
522 p_iov_info->mbx_msg_size);
526 /* Allocate PF Mailbox Reply buffer (per-VF) */
527 p_iov_info->mbx_reply_size = sizeof(union pfvf_tlvs) * num_vfs;
528 p_v_addr = &p_iov_info->mbx_reply_virt_addr;
529 *p_v_addr = OSAL_DMA_ALLOC_COHERENT(p_hwfn->p_dev,
530 &p_iov_info->mbx_reply_phys_addr,
531 p_iov_info->mbx_reply_size);
535 p_iov_info->bulletins_size = sizeof(struct ecore_bulletin_content) *
537 p_v_addr = &p_iov_info->p_bulletins;
538 *p_v_addr = OSAL_DMA_ALLOC_COHERENT(p_hwfn->p_dev,
539 &p_iov_info->bulletins_phys,
540 p_iov_info->bulletins_size);
544 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
545 "PF's Requests mailbox [%p virt 0x%lx phys], "
546 "Response mailbox [%p virt 0x%lx phys] Bulletinsi"
547 " [%p virt 0x%lx phys]\n",
548 p_iov_info->mbx_msg_virt_addr,
549 (unsigned long)p_iov_info->mbx_msg_phys_addr,
550 p_iov_info->mbx_reply_virt_addr,
551 (unsigned long)p_iov_info->mbx_reply_phys_addr,
552 p_iov_info->p_bulletins,
553 (unsigned long)p_iov_info->bulletins_phys);
555 return ECORE_SUCCESS;
558 static void ecore_iov_free_vfdb(struct ecore_hwfn *p_hwfn)
560 struct ecore_pf_iov *p_iov_info = p_hwfn->pf_iov_info;
562 if (p_hwfn->pf_iov_info->mbx_msg_virt_addr)
563 OSAL_DMA_FREE_COHERENT(p_hwfn->p_dev,
564 p_iov_info->mbx_msg_virt_addr,
565 p_iov_info->mbx_msg_phys_addr,
566 p_iov_info->mbx_msg_size);
568 if (p_hwfn->pf_iov_info->mbx_reply_virt_addr)
569 OSAL_DMA_FREE_COHERENT(p_hwfn->p_dev,
570 p_iov_info->mbx_reply_virt_addr,
571 p_iov_info->mbx_reply_phys_addr,
572 p_iov_info->mbx_reply_size);
574 if (p_iov_info->p_bulletins)
575 OSAL_DMA_FREE_COHERENT(p_hwfn->p_dev,
576 p_iov_info->p_bulletins,
577 p_iov_info->bulletins_phys,
578 p_iov_info->bulletins_size);
581 enum _ecore_status_t ecore_iov_alloc(struct ecore_hwfn *p_hwfn)
583 struct ecore_pf_iov *p_sriov;
585 if (!IS_PF_SRIOV(p_hwfn)) {
586 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
587 "No SR-IOV - no need for IOV db\n");
588 return ECORE_SUCCESS;
591 p_sriov = OSAL_ZALLOC(p_hwfn->p_dev, GFP_KERNEL, sizeof(*p_sriov));
593 DP_NOTICE(p_hwfn, false, "Failed to allocate `struct ecore_sriov'\n");
597 p_hwfn->pf_iov_info = p_sriov;
599 ecore_spq_register_async_cb(p_hwfn, PROTOCOLID_COMMON,
600 ecore_sriov_eqe_event);
602 return ecore_iov_allocate_vfdb(p_hwfn);
605 void ecore_iov_setup(struct ecore_hwfn *p_hwfn)
607 if (!IS_PF_SRIOV(p_hwfn) || !IS_PF_SRIOV_ALLOC(p_hwfn))
610 ecore_iov_setup_vfdb(p_hwfn);
613 void ecore_iov_free(struct ecore_hwfn *p_hwfn)
615 ecore_spq_unregister_async_cb(p_hwfn, PROTOCOLID_COMMON);
617 if (IS_PF_SRIOV_ALLOC(p_hwfn)) {
618 ecore_iov_free_vfdb(p_hwfn);
619 OSAL_FREE(p_hwfn->p_dev, p_hwfn->pf_iov_info);
623 void ecore_iov_free_hw_info(struct ecore_dev *p_dev)
625 OSAL_FREE(p_dev, p_dev->p_iov_info);
628 enum _ecore_status_t ecore_iov_hw_info(struct ecore_hwfn *p_hwfn)
630 struct ecore_dev *p_dev = p_hwfn->p_dev;
632 enum _ecore_status_t rc;
634 if (IS_VF(p_hwfn->p_dev))
635 return ECORE_SUCCESS;
637 /* Learn the PCI configuration */
638 pos = OSAL_PCI_FIND_EXT_CAPABILITY(p_hwfn->p_dev,
639 PCI_EXT_CAP_ID_SRIOV);
641 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV, "No PCIe IOV support\n");
642 return ECORE_SUCCESS;
645 /* Allocate a new struct for IOV information */
646 /* TODO - can change to VALLOC when its available */
647 p_dev->p_iov_info = OSAL_ZALLOC(p_dev, GFP_KERNEL,
648 sizeof(*p_dev->p_iov_info));
649 if (!p_dev->p_iov_info) {
650 DP_NOTICE(p_hwfn, false,
651 "Can't support IOV due to lack of memory\n");
654 p_dev->p_iov_info->pos = pos;
656 rc = ecore_iov_pci_cfg_info(p_dev);
660 /* We want PF IOV to be synonemous with the existence of p_iov_info;
661 * In case the capability is published but there are no VFs, simply
662 * de-allocate the struct.
664 if (!p_dev->p_iov_info->total_vfs) {
665 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
666 "IOV capabilities, but no VFs are published\n");
667 OSAL_FREE(p_dev, p_dev->p_iov_info);
668 return ECORE_SUCCESS;
671 /* First VF index based on offset is tricky:
672 * - If ARI is supported [likely], offset - (16 - pf_id) would
673 * provide the number for eng0. 2nd engine Vfs would begin
674 * after the first engine's VFs.
675 * - If !ARI, VFs would start on next device.
676 * so offset - (256 - pf_id) would provide the number.
677 * Utilize the fact that (256 - pf_id) is achieved only be later
678 * to diffrentiate between the two.
681 if (p_hwfn->p_dev->p_iov_info->offset < (256 - p_hwfn->abs_pf_id)) {
682 u32 first = p_hwfn->p_dev->p_iov_info->offset +
683 p_hwfn->abs_pf_id - 16;
685 p_dev->p_iov_info->first_vf_in_pf = first;
687 if (ECORE_PATH_ID(p_hwfn))
688 p_dev->p_iov_info->first_vf_in_pf -= MAX_NUM_VFS_BB;
690 u32 first = p_hwfn->p_dev->p_iov_info->offset +
691 p_hwfn->abs_pf_id - 256;
693 p_dev->p_iov_info->first_vf_in_pf = first;
696 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
697 "First VF in hwfn 0x%08x\n",
698 p_dev->p_iov_info->first_vf_in_pf);
700 return ECORE_SUCCESS;
703 static bool _ecore_iov_pf_sanity_check(struct ecore_hwfn *p_hwfn, int vfid,
704 bool b_fail_malicious)
706 /* Check PF supports sriov */
707 if (IS_VF(p_hwfn->p_dev) || !IS_ECORE_SRIOV(p_hwfn->p_dev) ||
708 !IS_PF_SRIOV_ALLOC(p_hwfn))
711 /* Check VF validity */
712 if (!ecore_iov_is_valid_vfid(p_hwfn, vfid, true, b_fail_malicious))
718 bool ecore_iov_pf_sanity_check(struct ecore_hwfn *p_hwfn, int vfid)
720 return _ecore_iov_pf_sanity_check(p_hwfn, vfid, true);
723 void ecore_iov_set_vf_to_disable(struct ecore_dev *p_dev,
724 u16 rel_vf_id, u8 to_disable)
726 struct ecore_vf_info *vf;
729 for_each_hwfn(p_dev, i) {
730 struct ecore_hwfn *p_hwfn = &p_dev->hwfns[i];
732 vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, false);
736 vf->to_disable = to_disable;
740 void ecore_iov_set_vfs_to_disable(struct ecore_dev *p_dev,
745 if (!IS_ECORE_SRIOV(p_dev))
748 for (i = 0; i < p_dev->p_iov_info->total_vfs; i++)
749 ecore_iov_set_vf_to_disable(p_dev, i, to_disable);
753 /* @@@TBD Consider taking outside of ecore... */
754 enum _ecore_status_t ecore_iov_set_vf_ctx(struct ecore_hwfn *p_hwfn,
758 enum _ecore_status_t rc = ECORE_SUCCESS;
759 struct ecore_vf_info *vf = ecore_iov_get_vf_info(p_hwfn, vf_id, true);
761 if (vf != OSAL_NULL) {
763 #ifdef CONFIG_ECORE_SW_CHANNEL
764 vf->vf_mbx.sw_mbx.mbx_state = VF_PF_WAIT_FOR_START_REQUEST;
767 rc = ECORE_UNKNOWN_ERROR;
773 static void ecore_iov_vf_pglue_clear_err(struct ecore_hwfn *p_hwfn,
774 struct ecore_ptt *p_ptt,
777 ecore_wr(p_hwfn, p_ptt,
778 PGLUE_B_REG_WAS_ERROR_VF_31_0_CLR + (abs_vfid >> 5) * 4,
779 1 << (abs_vfid & 0x1f));
782 static void ecore_iov_vf_igu_reset(struct ecore_hwfn *p_hwfn,
783 struct ecore_ptt *p_ptt,
784 struct ecore_vf_info *vf)
788 /* Set VF masks and configuration - pretend */
789 ecore_fid_pretend(p_hwfn, p_ptt, (u16)vf->concrete_fid);
791 ecore_wr(p_hwfn, p_ptt, IGU_REG_STATISTIC_NUM_VF_MSG_SENT, 0);
794 ecore_fid_pretend(p_hwfn, p_ptt, (u16)p_hwfn->hw_info.concrete_fid);
796 /* iterate over all queues, clear sb consumer */
797 for (i = 0; i < vf->num_sbs; i++)
798 ecore_int_igu_init_pure_rt_single(p_hwfn, p_ptt,
800 vf->opaque_fid, true);
803 static void ecore_iov_vf_igu_set_int(struct ecore_hwfn *p_hwfn,
804 struct ecore_ptt *p_ptt,
805 struct ecore_vf_info *vf, bool enable)
809 ecore_fid_pretend(p_hwfn, p_ptt, (u16)vf->concrete_fid);
811 igu_vf_conf = ecore_rd(p_hwfn, p_ptt, IGU_REG_VF_CONFIGURATION);
814 igu_vf_conf |= IGU_VF_CONF_MSI_MSIX_EN;
816 igu_vf_conf &= ~IGU_VF_CONF_MSI_MSIX_EN;
818 ecore_wr(p_hwfn, p_ptt, IGU_REG_VF_CONFIGURATION, igu_vf_conf);
821 ecore_fid_pretend(p_hwfn, p_ptt, (u16)p_hwfn->hw_info.concrete_fid);
824 static enum _ecore_status_t
825 ecore_iov_enable_vf_access_msix(struct ecore_hwfn *p_hwfn,
826 struct ecore_ptt *p_ptt,
833 /* If client overrides this, don't do anything */
834 if (p_hwfn->p_dev->b_dont_override_vf_msix)
835 return ECORE_SUCCESS;
837 /* For AH onward, configuration is per-PF. Find maximum of all
838 * the currently enabled child VFs, and set the number to be that.
840 if (!ECORE_IS_BB(p_hwfn->p_dev)) {
841 ecore_for_each_vf(p_hwfn, i) {
842 struct ecore_vf_info *p_vf;
844 p_vf = ecore_iov_get_vf_info(p_hwfn, (u16)i, true);
848 current_max = OSAL_MAX_T(u8, current_max,
853 if (num_sbs > current_max)
854 return ecore_mcp_config_vf_msix(p_hwfn, p_ptt,
857 return ECORE_SUCCESS;
860 static enum _ecore_status_t
861 ecore_iov_enable_vf_access(struct ecore_hwfn *p_hwfn,
862 struct ecore_ptt *p_ptt, struct ecore_vf_info *vf)
864 u32 igu_vf_conf = IGU_VF_CONF_FUNC_EN;
865 enum _ecore_status_t rc = ECORE_SUCCESS;
867 /* It's possible VF was previously considered malicious -
868 * clear the indication even if we're only going to disable VF.
870 vf->b_malicious = false;
873 return ECORE_SUCCESS;
875 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
876 "Enable internal access for vf %x [abs %x]\n", vf->abs_vf_id,
877 ECORE_VF_ABS_ID(p_hwfn, vf));
879 ecore_iov_vf_pglue_clear_err(p_hwfn, p_ptt,
880 ECORE_VF_ABS_ID(p_hwfn, vf));
882 ecore_iov_vf_igu_reset(p_hwfn, p_ptt, vf);
884 rc = ecore_iov_enable_vf_access_msix(p_hwfn, p_ptt,
885 vf->abs_vf_id, vf->num_sbs);
886 if (rc != ECORE_SUCCESS)
889 ecore_fid_pretend(p_hwfn, p_ptt, (u16)vf->concrete_fid);
891 SET_FIELD(igu_vf_conf, IGU_VF_CONF_PARENT, p_hwfn->rel_pf_id);
892 STORE_RT_REG(p_hwfn, IGU_REG_VF_CONFIGURATION_RT_OFFSET, igu_vf_conf);
894 ecore_init_run(p_hwfn, p_ptt, PHASE_VF, vf->abs_vf_id,
895 p_hwfn->hw_info.hw_mode);
898 ecore_fid_pretend(p_hwfn, p_ptt, (u16)p_hwfn->hw_info.concrete_fid);
907 * @brief ecore_iov_config_perm_table - configure the permission
909 * The queue zone permission table size is 320x9. There
910 * are 320 VF queues for single engine device (256 for dual
911 * engine device), and each entry has the following format:
918 static void ecore_iov_config_perm_table(struct ecore_hwfn *p_hwfn,
919 struct ecore_ptt *p_ptt,
920 struct ecore_vf_info *vf, u8 enable)
926 for (qid = 0; qid < vf->num_rxqs; qid++) {
927 ecore_fw_l2_queue(p_hwfn, vf->vf_queues[qid].fw_rx_qid,
930 reg_addr = PSWHST_REG_ZONE_PERMISSION_TABLE + qzone_id * 4;
931 val = enable ? (vf->abs_vf_id | (1 << 8)) : 0;
932 ecore_wr(p_hwfn, p_ptt, reg_addr, val);
936 static void ecore_iov_enable_vf_traffic(struct ecore_hwfn *p_hwfn,
937 struct ecore_ptt *p_ptt,
938 struct ecore_vf_info *vf)
940 /* Reset vf in IGU - interrupts are still disabled */
941 ecore_iov_vf_igu_reset(p_hwfn, p_ptt, vf);
943 ecore_iov_vf_igu_set_int(p_hwfn, p_ptt, vf, 1);
945 /* Permission Table */
946 ecore_iov_config_perm_table(p_hwfn, p_ptt, vf, true);
949 static u8 ecore_iov_alloc_vf_igu_sbs(struct ecore_hwfn *p_hwfn,
950 struct ecore_ptt *p_ptt,
951 struct ecore_vf_info *vf,
954 struct ecore_igu_block *p_block;
955 struct cau_sb_entry sb_entry;
959 if (num_rx_queues > p_hwfn->hw_info.p_igu_info->usage.free_cnt_iov)
961 (u16)p_hwfn->hw_info.p_igu_info->usage.free_cnt_iov;
962 p_hwfn->hw_info.p_igu_info->usage.free_cnt_iov -= num_rx_queues;
964 SET_FIELD(val, IGU_MAPPING_LINE_FUNCTION_NUMBER, vf->abs_vf_id);
965 SET_FIELD(val, IGU_MAPPING_LINE_VALID, 1);
966 SET_FIELD(val, IGU_MAPPING_LINE_PF_VALID, 0);
968 for (qid = 0; qid < num_rx_queues; qid++) {
969 p_block = ecore_get_igu_free_sb(p_hwfn, false);
973 vf->igu_sbs[qid] = p_block->igu_sb_id;
974 p_block->status &= ~ECORE_IGU_STATUS_FREE;
975 SET_FIELD(val, IGU_MAPPING_LINE_VECTOR_NUMBER, qid);
977 ecore_wr(p_hwfn, p_ptt,
978 IGU_REG_MAPPING_MEMORY +
979 sizeof(u32) * p_block->igu_sb_id, val);
981 /* Configure igu sb in CAU which were marked valid */
982 ecore_init_cau_sb_entry(p_hwfn, &sb_entry,
986 ecore_dmae_host2grc(p_hwfn, p_ptt,
987 (u64)(osal_uintptr_t)&sb_entry,
988 CAU_REG_SB_VAR_MEMORY +
989 p_block->igu_sb_id * sizeof(u64), 2,
990 OSAL_NULL /* default parameters */);
993 vf->num_sbs = (u8)num_rx_queues;
1000 * @brief The function invalidates all the VF entries,
1001 * technically this isn't required, but added for
1002 * cleaness and ease of debugging incase a VF attempts to
1003 * produce an interrupt after it has been taken down.
1009 static void ecore_iov_free_vf_igu_sbs(struct ecore_hwfn *p_hwfn,
1010 struct ecore_ptt *p_ptt,
1011 struct ecore_vf_info *vf)
1013 struct ecore_igu_info *p_info = p_hwfn->hw_info.p_igu_info;
1017 /* Invalidate igu CAM lines and mark them as free */
1018 for (idx = 0; idx < vf->num_sbs; idx++) {
1019 igu_id = vf->igu_sbs[idx];
1020 addr = IGU_REG_MAPPING_MEMORY + sizeof(u32) * igu_id;
1022 val = ecore_rd(p_hwfn, p_ptt, addr);
1023 SET_FIELD(val, IGU_MAPPING_LINE_VALID, 0);
1024 ecore_wr(p_hwfn, p_ptt, addr, val);
1026 p_info->entry[igu_id].status |= ECORE_IGU_STATUS_FREE;
1027 p_hwfn->hw_info.p_igu_info->usage.free_cnt_iov++;
1033 void ecore_iov_set_link(struct ecore_hwfn *p_hwfn,
1035 struct ecore_mcp_link_params *params,
1036 struct ecore_mcp_link_state *link,
1037 struct ecore_mcp_link_capabilities *p_caps)
1039 struct ecore_vf_info *p_vf = ecore_iov_get_vf_info(p_hwfn, vfid, false);
1040 struct ecore_bulletin_content *p_bulletin;
1045 p_bulletin = p_vf->bulletin.p_virt;
1046 p_bulletin->req_autoneg = params->speed.autoneg;
1047 p_bulletin->req_adv_speed = params->speed.advertised_speeds;
1048 p_bulletin->req_forced_speed = params->speed.forced_speed;
1049 p_bulletin->req_autoneg_pause = params->pause.autoneg;
1050 p_bulletin->req_forced_rx = params->pause.forced_rx;
1051 p_bulletin->req_forced_tx = params->pause.forced_tx;
1052 p_bulletin->req_loopback = params->loopback_mode;
1054 p_bulletin->link_up = link->link_up;
1055 p_bulletin->speed = link->speed;
1056 p_bulletin->full_duplex = link->full_duplex;
1057 p_bulletin->autoneg = link->an;
1058 p_bulletin->autoneg_complete = link->an_complete;
1059 p_bulletin->parallel_detection = link->parallel_detection;
1060 p_bulletin->pfc_enabled = link->pfc_enabled;
1061 p_bulletin->partner_adv_speed = link->partner_adv_speed;
1062 p_bulletin->partner_tx_flow_ctrl_en = link->partner_tx_flow_ctrl_en;
1063 p_bulletin->partner_rx_flow_ctrl_en = link->partner_rx_flow_ctrl_en;
1064 p_bulletin->partner_adv_pause = link->partner_adv_pause;
1065 p_bulletin->sfp_tx_fault = link->sfp_tx_fault;
1067 p_bulletin->capability_speed = p_caps->speed_capabilities;
1071 static void ecore_emul_iov_init_hw_for_vf(struct ecore_hwfn *p_hwfn,
1072 struct ecore_ptt *p_ptt)
1074 /* Increase the maximum number of DORQ FIFO entries used by child VFs */
1075 ecore_wr(p_hwfn, p_ptt, DORQ_REG_VF_USAGE_CNT_LIM, 0x3ec);
1079 enum _ecore_status_t
1080 ecore_iov_init_hw_for_vf(struct ecore_hwfn *p_hwfn,
1081 struct ecore_ptt *p_ptt,
1082 struct ecore_iov_vf_init_params *p_params)
1084 struct ecore_mcp_link_capabilities link_caps;
1085 struct ecore_mcp_link_params link_params;
1086 struct ecore_mcp_link_state link_state;
1087 u8 num_of_vf_available_chains = 0;
1088 struct ecore_vf_info *vf = OSAL_NULL;
1090 enum _ecore_status_t rc = ECORE_SUCCESS;
1094 vf = ecore_iov_get_vf_info(p_hwfn, p_params->rel_vf_id, false);
1096 DP_ERR(p_hwfn, "ecore_iov_init_hw_for_vf : vf is OSAL_NULL\n");
1097 return ECORE_UNKNOWN_ERROR;
1101 DP_NOTICE(p_hwfn, true, "VF[%d] is already active.\n",
1102 p_params->rel_vf_id);
1106 /* Perform sanity checking on the requested vport/rss */
1107 if (p_params->vport_id >= RESC_NUM(p_hwfn, ECORE_VPORT)) {
1108 DP_NOTICE(p_hwfn, true, "VF[%d] - can't use VPORT %02x\n",
1109 p_params->rel_vf_id, p_params->vport_id);
1113 if ((p_params->num_queues > 1) &&
1114 (p_params->rss_eng_id >= RESC_NUM(p_hwfn, ECORE_RSS_ENG))) {
1115 DP_NOTICE(p_hwfn, true, "VF[%d] - can't use RSS_ENG %02x\n",
1116 p_params->rel_vf_id, p_params->rss_eng_id);
1120 /* TODO - remove this once we get confidence of change */
1121 if (!p_params->vport_id) {
1122 DP_NOTICE(p_hwfn, false,
1123 "VF[%d] - Unlikely that VF uses vport0. Forgotten?\n",
1124 p_params->rel_vf_id);
1126 if ((!p_params->rss_eng_id) && (p_params->num_queues > 1)) {
1127 DP_NOTICE(p_hwfn, false,
1128 "VF[%d] - Unlikely that VF uses RSS_eng0. Forgotten?\n",
1129 p_params->rel_vf_id);
1131 vf->vport_id = p_params->vport_id;
1132 vf->rss_eng_id = p_params->rss_eng_id;
1134 /* Since it's possible to relocate SBs, it's a bit difficult to check
1135 * things here. Simply check whether the index falls in the range
1136 * belonging to the PF.
1138 for (i = 0; i < p_params->num_queues; i++) {
1139 qid = p_params->req_rx_queue[i];
1140 if (qid > (u16)RESC_NUM(p_hwfn, ECORE_L2_QUEUE)) {
1141 DP_NOTICE(p_hwfn, true,
1142 "Can't enable Rx qid [%04x] for VF[%d]: qids [0,,...,0x%04x] available\n",
1143 qid, p_params->rel_vf_id,
1144 (u16)RESC_NUM(p_hwfn, ECORE_L2_QUEUE));
1148 qid = p_params->req_tx_queue[i];
1149 if (qid > (u16)RESC_NUM(p_hwfn, ECORE_L2_QUEUE)) {
1150 DP_NOTICE(p_hwfn, true,
1151 "Can't enable Tx qid [%04x] for VF[%d]: qids [0,,...,0x%04x] available\n",
1152 qid, p_params->rel_vf_id,
1153 (u16)RESC_NUM(p_hwfn, ECORE_L2_QUEUE));
1158 /* Limit number of queues according to number of CIDs */
1159 ecore_cxt_get_proto_cid_count(p_hwfn, PROTOCOLID_ETH, &cids);
1160 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1161 "VF[%d] - requesting to initialize for 0x%04x queues"
1162 " [0x%04x CIDs available]\n",
1163 vf->relative_vf_id, p_params->num_queues, (u16)cids);
1164 num_irqs = OSAL_MIN_T(u16, p_params->num_queues, ((u16)cids));
1166 num_of_vf_available_chains = ecore_iov_alloc_vf_igu_sbs(p_hwfn,
1170 if (num_of_vf_available_chains == 0) {
1171 DP_ERR(p_hwfn, "no available igu sbs\n");
1175 /* Choose queue number and index ranges */
1176 vf->num_rxqs = num_of_vf_available_chains;
1177 vf->num_txqs = num_of_vf_available_chains;
1179 for (i = 0; i < vf->num_rxqs; i++) {
1180 struct ecore_vf_queue *p_queue = &vf->vf_queues[i];
1182 p_queue->fw_rx_qid = p_params->req_rx_queue[i];
1183 p_queue->fw_tx_qid = p_params->req_tx_queue[i];
1185 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1186 "VF[%d] - Q[%d] SB %04x, qid [Rx %04x Tx %04x]\n",
1187 vf->relative_vf_id, i, vf->igu_sbs[i],
1188 p_queue->fw_rx_qid, p_queue->fw_tx_qid);
1191 /* Update the link configuration in bulletin.
1193 OSAL_MEMCPY(&link_params, ecore_mcp_get_link_params(p_hwfn),
1194 sizeof(link_params));
1195 OSAL_MEMCPY(&link_state, ecore_mcp_get_link_state(p_hwfn),
1196 sizeof(link_state));
1197 OSAL_MEMCPY(&link_caps, ecore_mcp_get_link_capabilities(p_hwfn),
1199 ecore_iov_set_link(p_hwfn, p_params->rel_vf_id,
1200 &link_params, &link_state, &link_caps);
1202 rc = ecore_iov_enable_vf_access(p_hwfn, p_ptt, vf);
1203 if (rc != ECORE_SUCCESS)
1208 p_hwfn->pf_iov_info->active_vfs[vf->relative_vf_id / 64] |=
1209 (1ULL << (vf->relative_vf_id % 64));
1212 if (IS_LEAD_HWFN(p_hwfn))
1213 p_hwfn->p_dev->p_iov_info->num_vfs++;
1216 if (CHIP_REV_IS_EMUL(p_hwfn->p_dev))
1217 ecore_emul_iov_init_hw_for_vf(p_hwfn, p_ptt);
1220 return ECORE_SUCCESS;
1224 static void ecore_emul_iov_release_hw_for_vf(struct ecore_hwfn *p_hwfn,
1225 struct ecore_ptt *p_ptt)
1227 if (!ecore_mcp_is_init(p_hwfn)) {
1228 u32 sriov_dis = ecore_rd(p_hwfn, p_ptt,
1229 PGLUE_B_REG_SR_IOV_DISABLED_REQUEST);
1231 ecore_wr(p_hwfn, p_ptt, PGLUE_B_REG_SR_IOV_DISABLED_REQUEST_CLR,
1237 enum _ecore_status_t ecore_iov_release_hw_for_vf(struct ecore_hwfn *p_hwfn,
1238 struct ecore_ptt *p_ptt,
1241 struct ecore_mcp_link_capabilities caps;
1242 struct ecore_mcp_link_params params;
1243 struct ecore_mcp_link_state link;
1244 struct ecore_vf_info *vf = OSAL_NULL;
1246 vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
1248 DP_ERR(p_hwfn, "ecore_iov_release_hw_for_vf : vf is NULL\n");
1249 return ECORE_UNKNOWN_ERROR;
1252 if (vf->bulletin.p_virt)
1253 OSAL_MEMSET(vf->bulletin.p_virt, 0,
1254 sizeof(*vf->bulletin.p_virt));
1256 OSAL_MEMSET(&vf->p_vf_info, 0, sizeof(vf->p_vf_info));
1258 /* Get the link configuration back in bulletin so
1259 * that when VFs are re-enabled they get the actual
1260 * link configuration.
1262 OSAL_MEMCPY(¶ms, ecore_mcp_get_link_params(p_hwfn), sizeof(params));
1263 OSAL_MEMCPY(&link, ecore_mcp_get_link_state(p_hwfn), sizeof(link));
1264 OSAL_MEMCPY(&caps, ecore_mcp_get_link_capabilities(p_hwfn),
1266 ecore_iov_set_link(p_hwfn, rel_vf_id, ¶ms, &link, &caps);
1268 /* Forget the VF's acquisition message */
1269 OSAL_MEMSET(&vf->acquire, 0, sizeof(vf->acquire));
1271 /* disablng interrupts and resetting permission table was done during
1272 * vf-close, however, we could get here without going through vf_close
1274 /* Disable Interrupts for VF */
1275 ecore_iov_vf_igu_set_int(p_hwfn, p_ptt, vf, 0);
1277 /* Reset Permission table */
1278 ecore_iov_config_perm_table(p_hwfn, p_ptt, vf, 0);
1282 ecore_iov_free_vf_igu_sbs(p_hwfn, p_ptt, vf);
1286 p_hwfn->pf_iov_info->active_vfs[vf->relative_vf_id / 64] &=
1287 ~(1ULL << (vf->relative_vf_id / 64));
1289 if (IS_LEAD_HWFN(p_hwfn))
1290 p_hwfn->p_dev->p_iov_info->num_vfs--;
1294 if (CHIP_REV_IS_EMUL(p_hwfn->p_dev))
1295 ecore_emul_iov_release_hw_for_vf(p_hwfn, p_ptt);
1298 return ECORE_SUCCESS;
1301 static bool ecore_iov_tlv_supported(u16 tlvtype)
1303 return tlvtype > CHANNEL_TLV_NONE && tlvtype < CHANNEL_TLV_MAX;
1306 static void ecore_iov_lock_vf_pf_channel(struct ecore_hwfn *p_hwfn,
1307 struct ecore_vf_info *vf, u16 tlv)
1309 /* lock the channel */
1310 /* mutex_lock(&vf->op_mutex); @@@TBD MichalK - add lock... */
1312 /* record the locking op */
1313 /* vf->op_current = tlv; @@@TBD MichalK */
1316 if (ecore_iov_tlv_supported(tlv))
1319 "VF[%d]: vf pf channel locked by %s\n",
1321 qede_ecore_channel_tlvs_string[tlv]);
1325 "VF[%d]: vf pf channel locked by %04x\n",
1326 vf->abs_vf_id, tlv);
1329 static void ecore_iov_unlock_vf_pf_channel(struct ecore_hwfn *p_hwfn,
1330 struct ecore_vf_info *vf,
1333 /* log the unlock */
1334 if (ecore_iov_tlv_supported(expected_tlv))
1337 "VF[%d]: vf pf channel unlocked by %s\n",
1339 qede_ecore_channel_tlvs_string[expected_tlv]);
1343 "VF[%d]: vf pf channel unlocked by %04x\n",
1344 vf->abs_vf_id, expected_tlv);
1346 /* record the locking op */
1347 /* vf->op_current = CHANNEL_TLV_NONE; */
1350 /* place a given tlv on the tlv buffer, continuing current tlv list */
1351 void *ecore_add_tlv(u8 **offset, u16 type, u16 length)
1353 struct channel_tlv *tl = (struct channel_tlv *)*offset;
1356 tl->length = length;
1358 /* Offset should keep pointing to next TLV (the end of the last) */
1361 /* Return a pointer to the start of the added tlv */
1362 return *offset - length;
1365 /* list the types and lengths of the tlvs on the buffer */
1366 void ecore_dp_tlv_list(struct ecore_hwfn *p_hwfn, void *tlvs_list)
1368 u16 i = 1, total_length = 0;
1369 struct channel_tlv *tlv;
1372 /* cast current tlv list entry to channel tlv header */
1373 tlv = (struct channel_tlv *)((u8 *)tlvs_list + total_length);
1376 if (ecore_iov_tlv_supported(tlv->type))
1377 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1378 "TLV number %d: type %s, length %d\n",
1379 i, qede_ecore_channel_tlvs_string[tlv->type],
1382 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1383 "TLV number %d: type %d, length %d\n",
1384 i, tlv->type, tlv->length);
1386 if (tlv->type == CHANNEL_TLV_LIST_END)
1389 /* Validate entry - protect against malicious VFs */
1391 DP_NOTICE(p_hwfn, false, "TLV of length 0 found\n");
1394 total_length += tlv->length;
1395 if (total_length >= sizeof(struct tlv_buffer_size)) {
1396 DP_NOTICE(p_hwfn, false, "TLV ==> Buffer overflow\n");
1404 static void ecore_iov_send_response(struct ecore_hwfn *p_hwfn,
1405 struct ecore_ptt *p_ptt,
1406 struct ecore_vf_info *p_vf,
1407 #ifdef CONFIG_ECORE_SW_CHANNEL
1410 u16 OSAL_UNUSED length,
1414 struct ecore_iov_vf_mbx *mbx = &p_vf->vf_mbx;
1415 struct dmae_params params;
1418 mbx->reply_virt->default_resp.hdr.status = status;
1420 ecore_dp_tlv_list(p_hwfn, mbx->reply_virt);
1422 #ifdef CONFIG_ECORE_SW_CHANNEL
1423 mbx->sw_mbx.response_size =
1424 length + sizeof(struct channel_list_end_tlv);
1426 if (!p_vf->b_hw_channel)
1430 eng_vf_id = p_vf->abs_vf_id;
1432 OSAL_MEMSET(¶ms, 0, sizeof(params));
1433 SET_FIELD(params.flags, DMAE_PARAMS_DST_VF_VALID, 0x1);
1434 params.dst_vf_id = eng_vf_id;
1436 ecore_dmae_host2host(p_hwfn, p_ptt, mbx->reply_phys + sizeof(u64),
1437 mbx->req_virt->first_tlv.reply_address +
1439 (sizeof(union pfvf_tlvs) - sizeof(u64)) / 4,
1442 /* Once PF copies the rc to the VF, the latter can continue and
1443 * and send an additional message. So we have to make sure the
1444 * channel would be re-set to ready prior to that.
1447 GTT_BAR0_MAP_REG_USDM_RAM +
1448 USTORM_VF_PF_CHANNEL_READY_OFFSET(eng_vf_id), 1);
1450 ecore_dmae_host2host(p_hwfn, p_ptt, mbx->reply_phys,
1451 mbx->req_virt->first_tlv.reply_address,
1452 sizeof(u64) / 4, ¶ms);
1454 OSAL_IOV_PF_RESP_TYPE(p_hwfn, p_vf->relative_vf_id, status);
1457 static u16 ecore_iov_vport_to_tlv(enum ecore_iov_vport_update_flag flag)
1460 case ECORE_IOV_VP_UPDATE_ACTIVATE:
1461 return CHANNEL_TLV_VPORT_UPDATE_ACTIVATE;
1462 case ECORE_IOV_VP_UPDATE_VLAN_STRIP:
1463 return CHANNEL_TLV_VPORT_UPDATE_VLAN_STRIP;
1464 case ECORE_IOV_VP_UPDATE_TX_SWITCH:
1465 return CHANNEL_TLV_VPORT_UPDATE_TX_SWITCH;
1466 case ECORE_IOV_VP_UPDATE_MCAST:
1467 return CHANNEL_TLV_VPORT_UPDATE_MCAST;
1468 case ECORE_IOV_VP_UPDATE_ACCEPT_PARAM:
1469 return CHANNEL_TLV_VPORT_UPDATE_ACCEPT_PARAM;
1470 case ECORE_IOV_VP_UPDATE_RSS:
1471 return CHANNEL_TLV_VPORT_UPDATE_RSS;
1472 case ECORE_IOV_VP_UPDATE_ACCEPT_ANY_VLAN:
1473 return CHANNEL_TLV_VPORT_UPDATE_ACCEPT_ANY_VLAN;
1474 case ECORE_IOV_VP_UPDATE_SGE_TPA:
1475 return CHANNEL_TLV_VPORT_UPDATE_SGE_TPA;
1481 static u16 ecore_iov_prep_vp_update_resp_tlvs(struct ecore_hwfn *p_hwfn,
1482 struct ecore_vf_info *p_vf,
1483 struct ecore_iov_vf_mbx *p_mbx,
1484 u8 status, u16 tlvs_mask,
1487 struct pfvf_def_resp_tlv *resp;
1488 u16 size, total_len, i;
1490 OSAL_MEMSET(p_mbx->reply_virt, 0, sizeof(union pfvf_tlvs));
1491 p_mbx->offset = (u8 *)p_mbx->reply_virt;
1492 size = sizeof(struct pfvf_def_resp_tlv);
1495 ecore_add_tlv(&p_mbx->offset, CHANNEL_TLV_VPORT_UPDATE, size);
1497 /* Prepare response for all extended tlvs if they are found by PF */
1498 for (i = 0; i < ECORE_IOV_VP_UPDATE_MAX; i++) {
1499 if (!(tlvs_mask & (1 << i)))
1502 resp = ecore_add_tlv(&p_mbx->offset, ecore_iov_vport_to_tlv(i),
1505 if (tlvs_accepted & (1 << i))
1506 resp->hdr.status = status;
1508 resp->hdr.status = PFVF_STATUS_NOT_SUPPORTED;
1510 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1511 "VF[%d] - vport_update resp: TLV %d, status %02x\n",
1512 p_vf->relative_vf_id,
1513 ecore_iov_vport_to_tlv(i),
1519 ecore_add_tlv(&p_mbx->offset, CHANNEL_TLV_LIST_END,
1520 sizeof(struct channel_list_end_tlv));
1525 static void ecore_iov_prepare_resp(struct ecore_hwfn *p_hwfn,
1526 struct ecore_ptt *p_ptt,
1527 struct ecore_vf_info *vf_info,
1528 u16 type, u16 length, u8 status)
1530 struct ecore_iov_vf_mbx *mbx = &vf_info->vf_mbx;
1532 mbx->offset = (u8 *)mbx->reply_virt;
1534 ecore_add_tlv(&mbx->offset, type, length);
1535 ecore_add_tlv(&mbx->offset, CHANNEL_TLV_LIST_END,
1536 sizeof(struct channel_list_end_tlv));
1538 ecore_iov_send_response(p_hwfn, p_ptt, vf_info, length, status);
1541 struct ecore_public_vf_info
1542 *ecore_iov_get_public_vf_info(struct ecore_hwfn *p_hwfn,
1544 bool b_enabled_only)
1546 struct ecore_vf_info *vf = OSAL_NULL;
1548 vf = ecore_iov_get_vf_info(p_hwfn, relative_vf_id, b_enabled_only);
1552 return &vf->p_vf_info;
1555 static void ecore_iov_vf_cleanup(struct ecore_hwfn *p_hwfn,
1556 struct ecore_vf_info *p_vf)
1559 p_vf->vf_bulletin = 0;
1560 p_vf->vport_instance = 0;
1561 p_vf->configured_features = 0;
1563 /* If VF previously requested less resources, go back to default */
1564 p_vf->num_rxqs = p_vf->num_sbs;
1565 p_vf->num_txqs = p_vf->num_sbs;
1567 p_vf->num_active_rxqs = 0;
1569 for (i = 0; i < ECORE_MAX_VF_CHAINS_PER_PF; i++) {
1570 struct ecore_vf_queue *p_queue = &p_vf->vf_queues[i];
1572 for (j = 0; j < MAX_QUEUES_PER_QZONE; j++) {
1573 if (!p_queue->cids[j].p_cid)
1576 ecore_eth_queue_cid_release(p_hwfn,
1577 p_queue->cids[j].p_cid);
1578 p_queue->cids[j].p_cid = OSAL_NULL;
1582 OSAL_MEMSET(&p_vf->shadow_config, 0, sizeof(p_vf->shadow_config));
1583 OSAL_MEMSET(&p_vf->acquire, 0, sizeof(p_vf->acquire));
1584 OSAL_IOV_VF_CLEANUP(p_hwfn, p_vf->relative_vf_id);
1587 /* Returns either 0, or log(size) */
1588 static u32 ecore_iov_vf_db_bar_size(struct ecore_hwfn *p_hwfn,
1589 struct ecore_ptt *p_ptt)
1591 u32 val = ecore_rd(p_hwfn, p_ptt, PGLUE_B_REG_VF_BAR1_SIZE);
1599 ecore_iov_vf_mbx_acquire_resc_cids(struct ecore_hwfn *p_hwfn,
1600 struct ecore_ptt *p_ptt,
1601 struct ecore_vf_info *p_vf,
1602 struct vf_pf_resc_request *p_req,
1603 struct pf_vf_resc *p_resp)
1605 u8 num_vf_cons = p_hwfn->pf_params.eth_pf_params.num_vf_cons;
1606 u8 db_size = DB_ADDR_VF(1, DQ_DEMS_LEGACY) -
1607 DB_ADDR_VF(0, DQ_DEMS_LEGACY);
1610 p_resp->num_cids = OSAL_MIN_T(u8, p_req->num_cids, num_vf_cons);
1612 /* If VF didn't bother asking for QIDs than don't bother limiting
1613 * number of CIDs. The VF doesn't care about the number, and this
1614 * has the likely result of causing an additional acquisition.
1616 if (!(p_vf->acquire.vfdev_info.capabilities &
1617 VFPF_ACQUIRE_CAP_QUEUE_QIDS))
1620 /* If doorbell bar was mapped by VF, limit the VF CIDs to an amount
1621 * that would make sure doorbells for all CIDs fall within the bar.
1622 * If it doesn't, make sure regview window is sufficient.
1624 if (p_vf->acquire.vfdev_info.capabilities &
1625 VFPF_ACQUIRE_CAP_PHYSICAL_BAR) {
1626 bar_size = ecore_iov_vf_db_bar_size(p_hwfn, p_ptt);
1628 bar_size = 1 << bar_size;
1630 if (ECORE_IS_CMT(p_hwfn->p_dev))
1633 bar_size = PXP_VF_BAR0_DQ_LENGTH;
1636 if (bar_size / db_size < 256)
1637 p_resp->num_cids = OSAL_MIN_T(u8, p_resp->num_cids,
1638 (u8)(bar_size / db_size));
1641 static u8 ecore_iov_vf_mbx_acquire_resc(struct ecore_hwfn *p_hwfn,
1642 struct ecore_ptt *p_ptt,
1643 struct ecore_vf_info *p_vf,
1644 struct vf_pf_resc_request *p_req,
1645 struct pf_vf_resc *p_resp)
1649 /* Queue related information */
1650 p_resp->num_rxqs = p_vf->num_rxqs;
1651 p_resp->num_txqs = p_vf->num_txqs;
1652 p_resp->num_sbs = p_vf->num_sbs;
1654 for (i = 0; i < p_resp->num_sbs; i++) {
1655 p_resp->hw_sbs[i].hw_sb_id = p_vf->igu_sbs[i];
1656 /* TODO - what's this sb_qid field? Is it deprecated?
1657 * or is there an ecore_client that looks at this?
1659 p_resp->hw_sbs[i].sb_qid = 0;
1662 /* These fields are filled for backward compatibility.
1663 * Unused by modern vfs.
1665 for (i = 0; i < p_resp->num_rxqs; i++) {
1666 ecore_fw_l2_queue(p_hwfn, p_vf->vf_queues[i].fw_rx_qid,
1667 (u16 *)&p_resp->hw_qid[i]);
1671 /* Filter related information */
1672 p_resp->num_mac_filters = OSAL_MIN_T(u8, p_vf->num_mac_filters,
1673 p_req->num_mac_filters);
1674 p_resp->num_vlan_filters = OSAL_MIN_T(u8, p_vf->num_vlan_filters,
1675 p_req->num_vlan_filters);
1677 ecore_iov_vf_mbx_acquire_resc_cids(p_hwfn, p_ptt, p_vf, p_req, p_resp);
1679 /* This isn't really needed/enforced, but some legacy VFs might depend
1680 * on the correct filling of this field.
1682 p_resp->num_mc_filters = ECORE_MAX_MC_ADDRS;
1684 /* Validate sufficient resources for VF */
1685 if (p_resp->num_rxqs < p_req->num_rxqs ||
1686 p_resp->num_txqs < p_req->num_txqs ||
1687 p_resp->num_sbs < p_req->num_sbs ||
1688 p_resp->num_mac_filters < p_req->num_mac_filters ||
1689 p_resp->num_vlan_filters < p_req->num_vlan_filters ||
1690 p_resp->num_mc_filters < p_req->num_mc_filters ||
1691 p_resp->num_cids < p_req->num_cids) {
1692 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1693 "VF[%d] - Insufficient resources: rxq [%02x/%02x] txq [%02x/%02x] sbs [%02x/%02x] mac [%02x/%02x] vlan [%02x/%02x] mc [%02x/%02x] cids [%02x/%02x]\n",
1695 p_req->num_rxqs, p_resp->num_rxqs,
1696 p_req->num_rxqs, p_resp->num_txqs,
1697 p_req->num_sbs, p_resp->num_sbs,
1698 p_req->num_mac_filters, p_resp->num_mac_filters,
1699 p_req->num_vlan_filters, p_resp->num_vlan_filters,
1700 p_req->num_mc_filters, p_resp->num_mc_filters,
1701 p_req->num_cids, p_resp->num_cids);
1703 /* Some legacy OSes are incapable of correctly handling this
1706 if ((p_vf->acquire.vfdev_info.eth_fp_hsi_minor ==
1707 ETH_HSI_VER_NO_PKT_LEN_TUNN) &&
1708 (p_vf->acquire.vfdev_info.os_type ==
1709 VFPF_ACQUIRE_OS_WINDOWS))
1710 return PFVF_STATUS_SUCCESS;
1712 return PFVF_STATUS_NO_RESOURCE;
1715 return PFVF_STATUS_SUCCESS;
1718 static void ecore_iov_vf_mbx_acquire_stats(struct pfvf_stats_info *p_stats)
1720 p_stats->mstats.address = PXP_VF_BAR0_START_MSDM_ZONE_B +
1721 OFFSETOF(struct mstorm_vf_zone,
1722 non_trigger.eth_queue_stat);
1723 p_stats->mstats.len = sizeof(struct eth_mstorm_per_queue_stat);
1724 p_stats->ustats.address = PXP_VF_BAR0_START_USDM_ZONE_B +
1725 OFFSETOF(struct ustorm_vf_zone,
1726 non_trigger.eth_queue_stat);
1727 p_stats->ustats.len = sizeof(struct eth_ustorm_per_queue_stat);
1728 p_stats->pstats.address = PXP_VF_BAR0_START_PSDM_ZONE_B +
1729 OFFSETOF(struct pstorm_vf_zone,
1730 non_trigger.eth_queue_stat);
1731 p_stats->pstats.len = sizeof(struct eth_pstorm_per_queue_stat);
1732 p_stats->tstats.address = 0;
1733 p_stats->tstats.len = 0;
1736 static void ecore_iov_vf_mbx_acquire(struct ecore_hwfn *p_hwfn,
1737 struct ecore_ptt *p_ptt,
1738 struct ecore_vf_info *vf)
1740 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
1741 struct pfvf_acquire_resp_tlv *resp = &mbx->reply_virt->acquire_resp;
1742 struct pf_vf_pfdev_info *pfdev_info = &resp->pfdev_info;
1743 struct vfpf_acquire_tlv *req = &mbx->req_virt->acquire;
1744 u8 vfpf_status = PFVF_STATUS_NOT_SUPPORTED;
1745 struct pf_vf_resc *resc = &resp->resc;
1746 enum _ecore_status_t rc;
1748 OSAL_MEMSET(resp, 0, sizeof(*resp));
1750 /* Write the PF version so that VF would know which version
1751 * is supported - might be later overridden. This guarantees that
1752 * VF could recognize legacy PF based on lack of versions in reply.
1754 pfdev_info->major_fp_hsi = ETH_HSI_VER_MAJOR;
1755 pfdev_info->minor_fp_hsi = ETH_HSI_VER_MINOR;
1757 /* TODO - not doing anything is bad since we'll assert, but this isn't
1758 * necessarily the right behavior - perhaps we should have allowed some
1761 if (vf->state != VF_FREE &&
1762 vf->state != VF_STOPPED) {
1763 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1764 "VF[%d] sent ACQUIRE but is already in state %d - fail request\n",
1765 vf->abs_vf_id, vf->state);
1769 /* Validate FW compatibility */
1770 if (req->vfdev_info.eth_fp_hsi_major != ETH_HSI_VER_MAJOR) {
1771 if (req->vfdev_info.capabilities &
1772 VFPF_ACQUIRE_CAP_PRE_FP_HSI) {
1773 struct vf_pf_vfdev_info *p_vfdev = &req->vfdev_info;
1775 /* This legacy support would need to be removed once
1776 * the major has changed.
1778 OSAL_BUILD_BUG_ON(ETH_HSI_VER_MAJOR != 3);
1780 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1781 "VF[%d] is pre-fastpath HSI\n",
1783 p_vfdev->eth_fp_hsi_major = ETH_HSI_VER_MAJOR;
1784 p_vfdev->eth_fp_hsi_minor = ETH_HSI_VER_NO_PKT_LEN_TUNN;
1787 "VF[%d] needs fastpath HSI %02x.%02x, which is"
1788 " incompatible with loaded FW's faspath"
1791 req->vfdev_info.eth_fp_hsi_major,
1792 req->vfdev_info.eth_fp_hsi_minor,
1793 ETH_HSI_VER_MAJOR, ETH_HSI_VER_MINOR);
1799 /* On 100g PFs, prevent old VFs from loading */
1800 if (ECORE_IS_CMT(p_hwfn->p_dev) &&
1801 !(req->vfdev_info.capabilities & VFPF_ACQUIRE_CAP_100G)) {
1803 "VF[%d] is running an old driver that doesn't support"
1809 #ifndef __EXTRACT__LINUX__
1810 if (OSAL_IOV_VF_ACQUIRE(p_hwfn, vf->relative_vf_id) != ECORE_SUCCESS) {
1811 vfpf_status = PFVF_STATUS_NOT_SUPPORTED;
1816 /* Store the acquire message */
1817 OSAL_MEMCPY(&vf->acquire, req, sizeof(vf->acquire));
1819 vf->opaque_fid = req->vfdev_info.opaque_fid;
1821 vf->vf_bulletin = req->bulletin_addr;
1822 vf->bulletin.size = (vf->bulletin.size < req->bulletin_size) ?
1823 vf->bulletin.size : req->bulletin_size;
1825 /* fill in pfdev info */
1826 pfdev_info->chip_num = p_hwfn->p_dev->chip_num;
1827 pfdev_info->db_size = 0; /* @@@ TBD MichalK Vf Doorbells */
1828 pfdev_info->indices_per_sb = PIS_PER_SB;
1830 pfdev_info->capabilities = PFVF_ACQUIRE_CAP_DEFAULT_UNTAGGED |
1831 PFVF_ACQUIRE_CAP_POST_FW_OVERRIDE;
1832 if (ECORE_IS_CMT(p_hwfn->p_dev))
1833 pfdev_info->capabilities |= PFVF_ACQUIRE_CAP_100G;
1835 /* Share our ability to use multiple queue-ids only with VFs
1838 if (req->vfdev_info.capabilities & VFPF_ACQUIRE_CAP_QUEUE_QIDS)
1839 pfdev_info->capabilities |= PFVF_ACQUIRE_CAP_QUEUE_QIDS;
1841 /* Share the sizes of the bars with VF */
1842 resp->pfdev_info.bar_size = (u8)ecore_iov_vf_db_bar_size(p_hwfn,
1845 ecore_iov_vf_mbx_acquire_stats(&pfdev_info->stats_info);
1847 OSAL_MEMCPY(pfdev_info->port_mac, p_hwfn->hw_info.hw_mac_addr,
1850 pfdev_info->fw_major = FW_MAJOR_VERSION;
1851 pfdev_info->fw_minor = FW_MINOR_VERSION;
1852 pfdev_info->fw_rev = FW_REVISION_VERSION;
1853 pfdev_info->fw_eng = FW_ENGINEERING_VERSION;
1855 /* Incorrect when legacy, but doesn't matter as legacy isn't reading
1858 pfdev_info->minor_fp_hsi = OSAL_MIN_T(u8, ETH_HSI_VER_MINOR,
1859 req->vfdev_info.eth_fp_hsi_minor);
1860 pfdev_info->os_type = OSAL_IOV_GET_OS_TYPE();
1861 ecore_mcp_get_mfw_ver(p_hwfn, p_ptt, &pfdev_info->mfw_ver,
1864 pfdev_info->dev_type = p_hwfn->p_dev->type;
1865 pfdev_info->chip_rev = p_hwfn->p_dev->chip_rev;
1867 /* Fill resources available to VF; Make sure there are enough to
1868 * satisfy the VF's request.
1870 vfpf_status = ecore_iov_vf_mbx_acquire_resc(p_hwfn, p_ptt, vf,
1871 &req->resc_request, resc);
1872 if (vfpf_status != PFVF_STATUS_SUCCESS)
1875 /* Start the VF in FW */
1876 rc = ecore_sp_vf_start(p_hwfn, vf);
1877 if (rc != ECORE_SUCCESS) {
1878 DP_NOTICE(p_hwfn, true, "Failed to start VF[%02x]\n",
1880 vfpf_status = PFVF_STATUS_FAILURE;
1884 /* Fill agreed size of bulletin board in response, and post
1885 * an initial image to the bulletin board.
1887 resp->bulletin_size = vf->bulletin.size;
1888 ecore_iov_post_vf_bulletin(p_hwfn, vf->relative_vf_id, p_ptt);
1890 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1891 "VF[%d] ACQUIRE_RESPONSE: pfdev_info- chip_num=0x%x,"
1892 " db_size=%d, idx_per_sb=%d, pf_cap=0x%lx\n"
1893 "resources- n_rxq-%d, n_txq-%d, n_sbs-%d, n_macs-%d,"
1895 vf->abs_vf_id, resp->pfdev_info.chip_num,
1896 resp->pfdev_info.db_size, resp->pfdev_info.indices_per_sb,
1897 (unsigned long)resp->pfdev_info.capabilities, resc->num_rxqs,
1898 resc->num_txqs, resc->num_sbs, resc->num_mac_filters,
1899 resc->num_vlan_filters);
1901 vf->state = VF_ACQUIRED;
1904 /* Prepare Response */
1905 ecore_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_ACQUIRE,
1906 sizeof(struct pfvf_acquire_resp_tlv),
1910 static enum _ecore_status_t
1911 __ecore_iov_spoofchk_set(struct ecore_hwfn *p_hwfn,
1912 struct ecore_vf_info *p_vf, bool val)
1914 struct ecore_sp_vport_update_params params;
1915 enum _ecore_status_t rc;
1917 if (val == p_vf->spoof_chk) {
1918 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1919 "Spoofchk value[%d] is already configured\n", val);
1920 return ECORE_SUCCESS;
1923 OSAL_MEMSET(¶ms, 0, sizeof(struct ecore_sp_vport_update_params));
1924 params.opaque_fid = p_vf->opaque_fid;
1925 params.vport_id = p_vf->vport_id;
1926 params.update_anti_spoofing_en_flg = 1;
1927 params.anti_spoofing_en = val;
1929 rc = ecore_sp_vport_update(p_hwfn, ¶ms, ECORE_SPQ_MODE_EBLOCK,
1931 if (rc == ECORE_SUCCESS) {
1932 p_vf->spoof_chk = val;
1933 p_vf->req_spoofchk_val = p_vf->spoof_chk;
1934 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1935 "Spoofchk val[%d] configured\n", val);
1937 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1938 "Spoofchk configuration[val:%d] failed for VF[%d]\n",
1939 val, p_vf->relative_vf_id);
1945 static enum _ecore_status_t
1946 ecore_iov_reconfigure_unicast_vlan(struct ecore_hwfn *p_hwfn,
1947 struct ecore_vf_info *p_vf)
1949 struct ecore_filter_ucast filter;
1950 enum _ecore_status_t rc = ECORE_SUCCESS;
1953 OSAL_MEMSET(&filter, 0, sizeof(filter));
1954 filter.is_rx_filter = 1;
1955 filter.is_tx_filter = 1;
1956 filter.vport_to_add_to = p_vf->vport_id;
1957 filter.opcode = ECORE_FILTER_ADD;
1959 /* Reconfigure vlans */
1960 for (i = 0; i < ECORE_ETH_VF_NUM_VLAN_FILTERS + 1; i++) {
1961 if (!p_vf->shadow_config.vlans[i].used)
1964 filter.type = ECORE_FILTER_VLAN;
1965 filter.vlan = p_vf->shadow_config.vlans[i].vid;
1966 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1967 "Reconfiguring VLAN [0x%04x] for VF [%04x]\n",
1968 filter.vlan, p_vf->relative_vf_id);
1969 rc = ecore_sp_eth_filter_ucast(p_hwfn, p_vf->opaque_fid,
1970 &filter, ECORE_SPQ_MODE_CB,
1973 DP_NOTICE(p_hwfn, true,
1974 "Failed to configure VLAN [%04x]"
1976 filter.vlan, p_vf->relative_vf_id);
1984 static enum _ecore_status_t
1985 ecore_iov_reconfigure_unicast_shadow(struct ecore_hwfn *p_hwfn,
1986 struct ecore_vf_info *p_vf, u64 events)
1988 enum _ecore_status_t rc = ECORE_SUCCESS;
1990 /*TODO - what about MACs? */
1992 if ((events & (1 << VLAN_ADDR_FORCED)) &&
1993 !(p_vf->configured_features & (1 << VLAN_ADDR_FORCED)))
1994 rc = ecore_iov_reconfigure_unicast_vlan(p_hwfn, p_vf);
1999 static enum _ecore_status_t
2000 ecore_iov_configure_vport_forced(struct ecore_hwfn *p_hwfn,
2001 struct ecore_vf_info *p_vf,
2004 enum _ecore_status_t rc = ECORE_SUCCESS;
2005 struct ecore_filter_ucast filter;
2007 if (!p_vf->vport_instance)
2010 if ((events & (1 << MAC_ADDR_FORCED)) ||
2011 p_hwfn->pf_params.eth_pf_params.allow_vf_mac_change ||
2012 p_vf->p_vf_info.is_trusted_configured) {
2013 /* Since there's no way [currently] of removing the MAC,
2014 * we can always assume this means we need to force it.
2016 OSAL_MEMSET(&filter, 0, sizeof(filter));
2017 filter.type = ECORE_FILTER_MAC;
2018 filter.opcode = ECORE_FILTER_REPLACE;
2019 filter.is_rx_filter = 1;
2020 filter.is_tx_filter = 1;
2021 filter.vport_to_add_to = p_vf->vport_id;
2022 OSAL_MEMCPY(filter.mac, p_vf->bulletin.p_virt->mac, ETH_ALEN);
2024 rc = ecore_sp_eth_filter_ucast(p_hwfn, p_vf->opaque_fid,
2026 ECORE_SPQ_MODE_CB, OSAL_NULL);
2028 DP_NOTICE(p_hwfn, true,
2029 "PF failed to configure MAC for VF\n");
2033 if (p_hwfn->pf_params.eth_pf_params.allow_vf_mac_change ||
2034 p_vf->p_vf_info.is_trusted_configured)
2035 p_vf->configured_features |=
2036 1 << VFPF_BULLETIN_MAC_ADDR;
2038 p_vf->configured_features |= 1 << MAC_ADDR_FORCED;
2041 if (events & (1 << VLAN_ADDR_FORCED)) {
2042 struct ecore_sp_vport_update_params vport_update;
2046 OSAL_MEMSET(&filter, 0, sizeof(filter));
2047 filter.type = ECORE_FILTER_VLAN;
2048 filter.is_rx_filter = 1;
2049 filter.is_tx_filter = 1;
2050 filter.vport_to_add_to = p_vf->vport_id;
2051 filter.vlan = p_vf->bulletin.p_virt->pvid;
2052 filter.opcode = filter.vlan ? ECORE_FILTER_REPLACE :
2055 /* Send the ramrod */
2056 rc = ecore_sp_eth_filter_ucast(p_hwfn, p_vf->opaque_fid,
2058 ECORE_SPQ_MODE_CB, OSAL_NULL);
2060 DP_NOTICE(p_hwfn, true,
2061 "PF failed to configure VLAN for VF\n");
2065 /* Update the default-vlan & silent vlan stripping */
2066 OSAL_MEMSET(&vport_update, 0, sizeof(vport_update));
2067 vport_update.opaque_fid = p_vf->opaque_fid;
2068 vport_update.vport_id = p_vf->vport_id;
2069 vport_update.update_default_vlan_enable_flg = 1;
2070 vport_update.default_vlan_enable_flg = filter.vlan ? 1 : 0;
2071 vport_update.update_default_vlan_flg = 1;
2072 vport_update.default_vlan = filter.vlan;
2074 vport_update.update_inner_vlan_removal_flg = 1;
2075 removal = filter.vlan ?
2076 1 : p_vf->shadow_config.inner_vlan_removal;
2077 vport_update.inner_vlan_removal_flg = removal;
2078 vport_update.silent_vlan_removal_flg = filter.vlan ? 1 : 0;
2079 rc = ecore_sp_vport_update(p_hwfn, &vport_update,
2080 ECORE_SPQ_MODE_EBLOCK, OSAL_NULL);
2082 DP_NOTICE(p_hwfn, true,
2083 "PF failed to configure VF vport for vlan\n");
2087 /* Update all the Rx queues */
2088 for (i = 0; i < ECORE_MAX_VF_CHAINS_PER_PF; i++) {
2089 struct ecore_vf_queue *p_queue = &p_vf->vf_queues[i];
2090 struct ecore_queue_cid *p_cid = OSAL_NULL;
2092 /* There can be at most 1 Rx queue on qzone. Find it */
2093 p_cid = ecore_iov_get_vf_rx_queue_cid(p_queue);
2094 if (p_cid == OSAL_NULL)
2097 rc = ecore_sp_eth_rx_queues_update(p_hwfn,
2100 ECORE_SPQ_MODE_EBLOCK,
2103 DP_NOTICE(p_hwfn, true,
2104 "Failed to send Rx update"
2105 " fo queue[0x%04x]\n",
2106 p_cid->rel.queue_id);
2112 p_vf->configured_features |= 1 << VLAN_ADDR_FORCED;
2114 p_vf->configured_features &= ~(1 << VLAN_ADDR_FORCED);
2117 /* If forced features are terminated, we need to configure the shadow
2118 * configuration back again.
2121 ecore_iov_reconfigure_unicast_shadow(p_hwfn, p_vf, events);
2126 static void ecore_iov_vf_mbx_start_vport(struct ecore_hwfn *p_hwfn,
2127 struct ecore_ptt *p_ptt,
2128 struct ecore_vf_info *vf)
2130 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
2131 struct ecore_sp_vport_start_params params;
2132 struct vfpf_vport_start_tlv *start;
2133 u8 status = PFVF_STATUS_SUCCESS;
2134 struct ecore_vf_info *vf_info;
2137 enum _ecore_status_t rc;
2139 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vf->relative_vf_id, true);
2141 DP_NOTICE(p_hwfn->p_dev, true,
2142 "Failed to get VF info, invalid vfid [%d]\n",
2143 vf->relative_vf_id);
2147 vf->state = VF_ENABLED;
2148 start = &mbx->req_virt->start_vport;
2150 ecore_iov_enable_vf_traffic(p_hwfn, p_ptt, vf);
2152 /* Initialize Status block in CAU */
2153 for (sb_id = 0; sb_id < vf->num_sbs; sb_id++) {
2154 if (!start->sb_addr[sb_id]) {
2155 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2156 "VF[%d] did not fill the address of SB %d\n",
2157 vf->relative_vf_id, sb_id);
2161 ecore_int_cau_conf_sb(p_hwfn, p_ptt,
2162 start->sb_addr[sb_id],
2167 vf->mtu = start->mtu;
2168 vf->shadow_config.inner_vlan_removal = start->inner_vlan_removal;
2170 /* Take into consideration configuration forced by hypervisor;
2171 * If none is configured, use the supplied VF values [for old
2172 * vfs that would still be fine, since they passed '0' as padding].
2174 p_bitmap = &vf_info->bulletin.p_virt->valid_bitmap;
2175 if (!(*p_bitmap & (1 << VFPF_BULLETIN_UNTAGGED_DEFAULT_FORCED))) {
2176 u8 vf_req = start->only_untagged;
2178 vf_info->bulletin.p_virt->default_only_untagged = vf_req;
2179 *p_bitmap |= 1 << VFPF_BULLETIN_UNTAGGED_DEFAULT;
2182 OSAL_MEMSET(¶ms, 0, sizeof(struct ecore_sp_vport_start_params));
2183 params.tpa_mode = start->tpa_mode;
2184 params.remove_inner_vlan = start->inner_vlan_removal;
2185 params.tx_switching = true;
2188 if (CHIP_REV_IS_FPGA(p_hwfn->p_dev)) {
2189 DP_NOTICE(p_hwfn, false,
2190 "FPGA: Don't config VF for Tx-switching [no pVFC]\n");
2191 params.tx_switching = false;
2195 params.only_untagged = vf_info->bulletin.p_virt->default_only_untagged;
2196 params.drop_ttl0 = false;
2197 params.concrete_fid = vf->concrete_fid;
2198 params.opaque_fid = vf->opaque_fid;
2199 params.vport_id = vf->vport_id;
2200 params.max_buffers_per_cqe = start->max_buffers_per_cqe;
2201 params.mtu = vf->mtu;
2203 /* Non trusted VFs should enable control frame filtering */
2204 params.check_mac = !vf->p_vf_info.is_trusted_configured;
2206 rc = ecore_sp_eth_vport_start(p_hwfn, ¶ms);
2207 if (rc != ECORE_SUCCESS) {
2209 "ecore_iov_vf_mbx_start_vport returned error %d\n", rc);
2210 status = PFVF_STATUS_FAILURE;
2212 vf->vport_instance++;
2214 /* Force configuration if needed on the newly opened vport */
2215 ecore_iov_configure_vport_forced(p_hwfn, vf, *p_bitmap);
2216 OSAL_IOV_POST_START_VPORT(p_hwfn, vf->relative_vf_id,
2217 vf->vport_id, vf->opaque_fid);
2218 __ecore_iov_spoofchk_set(p_hwfn, vf, vf->req_spoofchk_val);
2221 ecore_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_VPORT_START,
2222 sizeof(struct pfvf_def_resp_tlv), status);
2225 static void ecore_iov_vf_mbx_stop_vport(struct ecore_hwfn *p_hwfn,
2226 struct ecore_ptt *p_ptt,
2227 struct ecore_vf_info *vf)
2229 u8 status = PFVF_STATUS_SUCCESS;
2230 enum _ecore_status_t rc;
2232 OSAL_IOV_VF_VPORT_STOP(p_hwfn, vf);
2233 vf->vport_instance--;
2234 vf->spoof_chk = false;
2236 if ((ecore_iov_validate_active_rxq(vf)) ||
2237 (ecore_iov_validate_active_txq(vf))) {
2238 vf->b_malicious = true;
2239 DP_NOTICE(p_hwfn, false,
2240 "VF [%02x] - considered malicious;"
2241 " Unable to stop RX/TX queuess\n",
2243 status = PFVF_STATUS_MALICIOUS;
2247 rc = ecore_sp_vport_stop(p_hwfn, vf->opaque_fid, vf->vport_id);
2248 if (rc != ECORE_SUCCESS) {
2250 "ecore_iov_vf_mbx_stop_vport returned error %d\n", rc);
2251 status = PFVF_STATUS_FAILURE;
2254 /* Forget the configuration on the vport */
2255 vf->configured_features = 0;
2256 OSAL_MEMSET(&vf->shadow_config, 0, sizeof(vf->shadow_config));
2259 ecore_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_VPORT_TEARDOWN,
2260 sizeof(struct pfvf_def_resp_tlv), status);
2263 static void ecore_iov_vf_mbx_start_rxq_resp(struct ecore_hwfn *p_hwfn,
2264 struct ecore_ptt *p_ptt,
2265 struct ecore_vf_info *vf,
2266 u8 status, bool b_legacy)
2268 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
2269 struct pfvf_start_queue_resp_tlv *p_tlv;
2270 struct vfpf_start_rxq_tlv *req;
2273 mbx->offset = (u8 *)mbx->reply_virt;
2275 /* Taking a bigger struct instead of adding a TLV to list was a
2276 * mistake, but one which we're now stuck with, as some older
2277 * clients assume the size of the previous response.
2280 length = sizeof(*p_tlv);
2282 length = sizeof(struct pfvf_def_resp_tlv);
2284 p_tlv = ecore_add_tlv(&mbx->offset, CHANNEL_TLV_START_RXQ, length);
2285 ecore_add_tlv(&mbx->offset, CHANNEL_TLV_LIST_END,
2286 sizeof(struct channel_list_end_tlv));
2288 /* Update the TLV with the response.
2289 * The VF Rx producers are located in the vf zone.
2291 if ((status == PFVF_STATUS_SUCCESS) && !b_legacy) {
2292 req = &mbx->req_virt->start_rxq;
2295 PXP_VF_BAR0_START_MSDM_ZONE_B +
2296 OFFSETOF(struct mstorm_vf_zone,
2297 non_trigger.eth_rx_queue_producers) +
2298 sizeof(struct eth_rx_prod_data) * req->rx_qid;
2301 ecore_iov_send_response(p_hwfn, p_ptt, vf, length, status);
2304 static u8 ecore_iov_vf_mbx_qid(struct ecore_hwfn *p_hwfn,
2305 struct ecore_vf_info *p_vf, bool b_is_tx)
2307 struct ecore_iov_vf_mbx *p_mbx = &p_vf->vf_mbx;
2308 struct vfpf_qid_tlv *p_qid_tlv;
2310 /* Search for the qid if the VF published if its going to provide it */
2311 if (!(p_vf->acquire.vfdev_info.capabilities &
2312 VFPF_ACQUIRE_CAP_QUEUE_QIDS)) {
2314 return ECORE_IOV_LEGACY_QID_TX;
2316 return ECORE_IOV_LEGACY_QID_RX;
2319 p_qid_tlv = (struct vfpf_qid_tlv *)
2320 ecore_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt,
2322 if (p_qid_tlv == OSAL_NULL) {
2323 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2324 "VF[%2x]: Failed to provide qid\n",
2325 p_vf->relative_vf_id);
2327 return ECORE_IOV_QID_INVALID;
2330 if (p_qid_tlv->qid >= MAX_QUEUES_PER_QZONE) {
2331 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2332 "VF[%02x]: Provided qid out-of-bounds %02x\n",
2333 p_vf->relative_vf_id, p_qid_tlv->qid);
2334 return ECORE_IOV_QID_INVALID;
2337 return p_qid_tlv->qid;
2340 static void ecore_iov_vf_mbx_start_rxq(struct ecore_hwfn *p_hwfn,
2341 struct ecore_ptt *p_ptt,
2342 struct ecore_vf_info *vf)
2344 struct ecore_queue_start_common_params params;
2345 struct ecore_queue_cid_vf_params vf_params;
2346 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
2347 u8 status = PFVF_STATUS_NO_RESOURCE;
2348 u8 qid_usage_idx, vf_legacy = 0;
2349 struct ecore_vf_queue *p_queue;
2350 struct vfpf_start_rxq_tlv *req;
2351 struct ecore_queue_cid *p_cid;
2352 struct ecore_sb_info sb_dummy;
2353 enum _ecore_status_t rc;
2355 req = &mbx->req_virt->start_rxq;
2357 if (!ecore_iov_validate_rxq(p_hwfn, vf, req->rx_qid,
2358 ECORE_IOV_VALIDATE_Q_DISABLE) ||
2359 !ecore_iov_validate_sb(p_hwfn, vf, req->hw_sb))
2362 qid_usage_idx = ecore_iov_vf_mbx_qid(p_hwfn, vf, false);
2363 if (qid_usage_idx == ECORE_IOV_QID_INVALID)
2366 p_queue = &vf->vf_queues[req->rx_qid];
2367 if (p_queue->cids[qid_usage_idx].p_cid)
2370 vf_legacy = ecore_vf_calculate_legacy(vf);
2372 /* Acquire a new queue-cid */
2373 OSAL_MEMSET(¶ms, 0, sizeof(params));
2374 params.queue_id = (u8)p_queue->fw_rx_qid;
2375 params.vport_id = vf->vport_id;
2376 params.stats_id = vf->abs_vf_id + 0x10;
2378 /* Since IGU index is passed via sb_info, construct a dummy one */
2379 OSAL_MEM_ZERO(&sb_dummy, sizeof(sb_dummy));
2380 sb_dummy.igu_sb_id = req->hw_sb;
2381 params.p_sb = &sb_dummy;
2382 params.sb_idx = req->sb_index;
2384 OSAL_MEM_ZERO(&vf_params, sizeof(vf_params));
2385 vf_params.vfid = vf->relative_vf_id;
2386 vf_params.vf_qid = (u8)req->rx_qid;
2387 vf_params.vf_legacy = vf_legacy;
2388 vf_params.qid_usage_idx = qid_usage_idx;
2390 p_cid = ecore_eth_queue_to_cid(p_hwfn, vf->opaque_fid,
2391 ¶ms, true, &vf_params);
2392 if (p_cid == OSAL_NULL)
2395 /* The VF Rx producers are located in the vf zone.
2396 * Legacy VFs have their producers in the queue zone, but they
2397 * calculate the location by their own and clean them prior to this.
2399 if (!(vf_legacy & ECORE_QCID_LEGACY_VF_RX_PROD))
2401 GTT_BAR0_MAP_REG_MSDM_RAM +
2402 MSTORM_ETH_VF_PRODS_OFFSET(vf->abs_vf_id,
2406 rc = ecore_eth_rxq_start_ramrod(p_hwfn, p_cid,
2411 if (rc != ECORE_SUCCESS) {
2412 status = PFVF_STATUS_FAILURE;
2413 ecore_eth_queue_cid_release(p_hwfn, p_cid);
2415 p_queue->cids[qid_usage_idx].p_cid = p_cid;
2416 p_queue->cids[qid_usage_idx].b_is_tx = false;
2417 status = PFVF_STATUS_SUCCESS;
2418 vf->num_active_rxqs++;
2422 ecore_iov_vf_mbx_start_rxq_resp(p_hwfn, p_ptt, vf, status,
2424 ECORE_QCID_LEGACY_VF_RX_PROD));
2428 ecore_iov_pf_update_tun_response(struct pfvf_update_tunn_param_tlv *p_resp,
2429 struct ecore_tunnel_info *p_tun,
2430 u16 tunn_feature_mask)
2432 p_resp->tunn_feature_mask = tunn_feature_mask;
2433 p_resp->vxlan_mode = p_tun->vxlan.b_mode_enabled;
2434 p_resp->l2geneve_mode = p_tun->l2_geneve.b_mode_enabled;
2435 p_resp->ipgeneve_mode = p_tun->ip_geneve.b_mode_enabled;
2436 p_resp->l2gre_mode = p_tun->l2_gre.b_mode_enabled;
2437 p_resp->ipgre_mode = p_tun->l2_gre.b_mode_enabled;
2438 p_resp->vxlan_clss = p_tun->vxlan.tun_cls;
2439 p_resp->l2gre_clss = p_tun->l2_gre.tun_cls;
2440 p_resp->ipgre_clss = p_tun->ip_gre.tun_cls;
2441 p_resp->l2geneve_clss = p_tun->l2_geneve.tun_cls;
2442 p_resp->ipgeneve_clss = p_tun->ip_geneve.tun_cls;
2443 p_resp->geneve_udp_port = p_tun->geneve_port.port;
2444 p_resp->vxlan_udp_port = p_tun->vxlan_port.port;
2448 __ecore_iov_pf_update_tun_param(struct vfpf_update_tunn_param_tlv *p_req,
2449 struct ecore_tunn_update_type *p_tun,
2450 enum ecore_tunn_mode mask, u8 tun_cls)
2452 if (p_req->tun_mode_update_mask & (1 << mask)) {
2453 p_tun->b_update_mode = true;
2455 if (p_req->tunn_mode & (1 << mask))
2456 p_tun->b_mode_enabled = true;
2459 p_tun->tun_cls = tun_cls;
2463 ecore_iov_pf_update_tun_param(struct vfpf_update_tunn_param_tlv *p_req,
2464 struct ecore_tunn_update_type *p_tun,
2465 struct ecore_tunn_update_udp_port *p_port,
2466 enum ecore_tunn_mode mask,
2467 u8 tun_cls, u8 update_port, u16 port)
2470 p_port->b_update_port = true;
2471 p_port->port = port;
2474 __ecore_iov_pf_update_tun_param(p_req, p_tun, mask, tun_cls);
2478 ecore_iov_pf_validate_tunn_param(struct vfpf_update_tunn_param_tlv *p_req)
2480 bool b_update_requested = false;
2482 if (p_req->tun_mode_update_mask || p_req->update_tun_cls ||
2483 p_req->update_geneve_port || p_req->update_vxlan_port)
2484 b_update_requested = true;
2486 return b_update_requested;
2489 static void ecore_iov_vf_mbx_update_tunn_param(struct ecore_hwfn *p_hwfn,
2490 struct ecore_ptt *p_ptt,
2491 struct ecore_vf_info *p_vf)
2493 struct ecore_tunnel_info *p_tun = &p_hwfn->p_dev->tunnel;
2494 struct ecore_iov_vf_mbx *mbx = &p_vf->vf_mbx;
2495 struct pfvf_update_tunn_param_tlv *p_resp;
2496 struct vfpf_update_tunn_param_tlv *p_req;
2497 enum _ecore_status_t rc = ECORE_SUCCESS;
2498 u8 status = PFVF_STATUS_SUCCESS;
2499 bool b_update_required = false;
2500 struct ecore_tunnel_info tunn;
2501 u16 tunn_feature_mask = 0;
2504 mbx->offset = (u8 *)mbx->reply_virt;
2506 OSAL_MEM_ZERO(&tunn, sizeof(tunn));
2507 p_req = &mbx->req_virt->tunn_param_update;
2509 if (!ecore_iov_pf_validate_tunn_param(p_req)) {
2510 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2511 "No tunnel update requested by VF\n");
2512 status = PFVF_STATUS_FAILURE;
2516 tunn.b_update_rx_cls = p_req->update_tun_cls;
2517 tunn.b_update_tx_cls = p_req->update_tun_cls;
2519 ecore_iov_pf_update_tun_param(p_req, &tunn.vxlan, &tunn.vxlan_port,
2520 ECORE_MODE_VXLAN_TUNN, p_req->vxlan_clss,
2521 p_req->update_vxlan_port,
2523 ecore_iov_pf_update_tun_param(p_req, &tunn.l2_geneve, &tunn.geneve_port,
2524 ECORE_MODE_L2GENEVE_TUNN,
2525 p_req->l2geneve_clss,
2526 p_req->update_geneve_port,
2527 p_req->geneve_port);
2528 __ecore_iov_pf_update_tun_param(p_req, &tunn.ip_geneve,
2529 ECORE_MODE_IPGENEVE_TUNN,
2530 p_req->ipgeneve_clss);
2531 __ecore_iov_pf_update_tun_param(p_req, &tunn.l2_gre,
2532 ECORE_MODE_L2GRE_TUNN,
2534 __ecore_iov_pf_update_tun_param(p_req, &tunn.ip_gre,
2535 ECORE_MODE_IPGRE_TUNN,
2538 /* If PF modifies VF's req then it should
2539 * still return an error in case of partial configuration
2540 * or modified configuration as opposed to requested one.
2542 rc = OSAL_PF_VALIDATE_MODIFY_TUNN_CONFIG(p_hwfn, &tunn_feature_mask,
2543 &b_update_required, &tunn);
2545 if (rc != ECORE_SUCCESS)
2546 status = PFVF_STATUS_FAILURE;
2548 /* If ECORE client is willing to update anything ? */
2549 if (b_update_required) {
2552 rc = ecore_sp_pf_update_tunn_cfg(p_hwfn, p_ptt, &tunn,
2553 ECORE_SPQ_MODE_EBLOCK,
2555 if (rc != ECORE_SUCCESS)
2556 status = PFVF_STATUS_FAILURE;
2558 geneve_port = p_tun->geneve_port.port;
2559 ecore_for_each_vf(p_hwfn, i) {
2560 ecore_iov_bulletin_set_udp_ports(p_hwfn, i,
2561 p_tun->vxlan_port.port,
2567 p_resp = ecore_add_tlv(&mbx->offset,
2568 CHANNEL_TLV_UPDATE_TUNN_PARAM, sizeof(*p_resp));
2570 ecore_iov_pf_update_tun_response(p_resp, p_tun, tunn_feature_mask);
2571 ecore_add_tlv(&mbx->offset, CHANNEL_TLV_LIST_END,
2572 sizeof(struct channel_list_end_tlv));
2574 ecore_iov_send_response(p_hwfn, p_ptt, p_vf, sizeof(*p_resp), status);
2577 static void ecore_iov_vf_mbx_start_txq_resp(struct ecore_hwfn *p_hwfn,
2578 struct ecore_ptt *p_ptt,
2579 struct ecore_vf_info *p_vf,
2583 struct ecore_iov_vf_mbx *mbx = &p_vf->vf_mbx;
2584 struct pfvf_start_queue_resp_tlv *p_tlv;
2585 bool b_legacy = false;
2588 mbx->offset = (u8 *)mbx->reply_virt;
2590 /* Taking a bigger struct instead of adding a TLV to list was a
2591 * mistake, but one which we're now stuck with, as some older
2592 * clients assume the size of the previous response.
2594 if (p_vf->acquire.vfdev_info.eth_fp_hsi_minor ==
2595 ETH_HSI_VER_NO_PKT_LEN_TUNN)
2599 length = sizeof(*p_tlv);
2601 length = sizeof(struct pfvf_def_resp_tlv);
2603 p_tlv = ecore_add_tlv(&mbx->offset, CHANNEL_TLV_START_TXQ, length);
2604 ecore_add_tlv(&mbx->offset, CHANNEL_TLV_LIST_END,
2605 sizeof(struct channel_list_end_tlv));
2607 /* Update the TLV with the response */
2608 if ((status == PFVF_STATUS_SUCCESS) && !b_legacy)
2609 p_tlv->offset = DB_ADDR_VF(cid, DQ_DEMS_LEGACY);
2611 ecore_iov_send_response(p_hwfn, p_ptt, p_vf, length, status);
2614 static void ecore_iov_vf_mbx_start_txq(struct ecore_hwfn *p_hwfn,
2615 struct ecore_ptt *p_ptt,
2616 struct ecore_vf_info *vf)
2618 struct ecore_queue_start_common_params params;
2619 struct ecore_queue_cid_vf_params vf_params;
2620 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
2621 u8 status = PFVF_STATUS_NO_RESOURCE;
2622 struct ecore_vf_queue *p_queue;
2623 struct vfpf_start_txq_tlv *req;
2624 struct ecore_queue_cid *p_cid;
2625 struct ecore_sb_info sb_dummy;
2626 u8 qid_usage_idx, vf_legacy;
2628 enum _ecore_status_t rc;
2631 OSAL_MEMSET(¶ms, 0, sizeof(params));
2632 req = &mbx->req_virt->start_txq;
2634 if (!ecore_iov_validate_txq(p_hwfn, vf, req->tx_qid,
2635 ECORE_IOV_VALIDATE_Q_NA) ||
2636 !ecore_iov_validate_sb(p_hwfn, vf, req->hw_sb))
2639 qid_usage_idx = ecore_iov_vf_mbx_qid(p_hwfn, vf, true);
2640 if (qid_usage_idx == ECORE_IOV_QID_INVALID)
2643 p_queue = &vf->vf_queues[req->tx_qid];
2644 if (p_queue->cids[qid_usage_idx].p_cid)
2647 vf_legacy = ecore_vf_calculate_legacy(vf);
2649 /* Acquire a new queue-cid */
2650 params.queue_id = p_queue->fw_tx_qid;
2651 params.vport_id = vf->vport_id;
2652 params.stats_id = vf->abs_vf_id + 0x10;
2654 /* Since IGU index is passed via sb_info, construct a dummy one */
2655 OSAL_MEM_ZERO(&sb_dummy, sizeof(sb_dummy));
2656 sb_dummy.igu_sb_id = req->hw_sb;
2657 params.p_sb = &sb_dummy;
2658 params.sb_idx = req->sb_index;
2660 OSAL_MEM_ZERO(&vf_params, sizeof(vf_params));
2661 vf_params.vfid = vf->relative_vf_id;
2662 vf_params.vf_qid = (u8)req->tx_qid;
2663 vf_params.vf_legacy = vf_legacy;
2664 vf_params.qid_usage_idx = qid_usage_idx;
2666 p_cid = ecore_eth_queue_to_cid(p_hwfn, vf->opaque_fid,
2667 ¶ms, false, &vf_params);
2668 if (p_cid == OSAL_NULL)
2671 pq = ecore_get_cm_pq_idx_vf(p_hwfn,
2672 vf->relative_vf_id);
2673 rc = ecore_eth_txq_start_ramrod(p_hwfn, p_cid,
2674 req->pbl_addr, req->pbl_size, pq);
2675 if (rc != ECORE_SUCCESS) {
2676 status = PFVF_STATUS_FAILURE;
2677 ecore_eth_queue_cid_release(p_hwfn, p_cid);
2679 status = PFVF_STATUS_SUCCESS;
2680 p_queue->cids[qid_usage_idx].p_cid = p_cid;
2681 p_queue->cids[qid_usage_idx].b_is_tx = true;
2686 ecore_iov_vf_mbx_start_txq_resp(p_hwfn, p_ptt, vf,
2690 static enum _ecore_status_t ecore_iov_vf_stop_rxqs(struct ecore_hwfn *p_hwfn,
2691 struct ecore_vf_info *vf,
2694 bool cqe_completion)
2696 struct ecore_vf_queue *p_queue;
2697 enum _ecore_status_t rc = ECORE_SUCCESS;
2699 if (!ecore_iov_validate_rxq(p_hwfn, vf, rxq_id,
2700 ECORE_IOV_VALIDATE_Q_NA)) {
2701 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2702 "VF[%d] Tried Closing Rx 0x%04x.%02x which is inactive\n",
2703 vf->relative_vf_id, rxq_id, qid_usage_idx);
2707 p_queue = &vf->vf_queues[rxq_id];
2709 /* We've validated the index and the existence of the active RXQ -
2710 * now we need to make sure that it's using the correct qid.
2712 if (!p_queue->cids[qid_usage_idx].p_cid ||
2713 p_queue->cids[qid_usage_idx].b_is_tx) {
2714 struct ecore_queue_cid *p_cid;
2716 p_cid = ecore_iov_get_vf_rx_queue_cid(p_queue);
2717 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2718 "VF[%d] - Tried Closing Rx 0x%04x.%02x, but Rx is at %04x.%02x\n",
2719 vf->relative_vf_id, rxq_id, qid_usage_idx,
2720 rxq_id, p_cid->qid_usage_idx);
2724 /* Now that we know we have a valid Rx-queue - close it */
2725 rc = ecore_eth_rx_queue_stop(p_hwfn,
2726 p_queue->cids[qid_usage_idx].p_cid,
2727 false, cqe_completion);
2728 if (rc != ECORE_SUCCESS)
2731 p_queue->cids[qid_usage_idx].p_cid = OSAL_NULL;
2732 vf->num_active_rxqs--;
2734 return ECORE_SUCCESS;
2737 static enum _ecore_status_t ecore_iov_vf_stop_txqs(struct ecore_hwfn *p_hwfn,
2738 struct ecore_vf_info *vf,
2742 struct ecore_vf_queue *p_queue;
2743 enum _ecore_status_t rc = ECORE_SUCCESS;
2745 if (!ecore_iov_validate_txq(p_hwfn, vf, txq_id,
2746 ECORE_IOV_VALIDATE_Q_NA))
2749 p_queue = &vf->vf_queues[txq_id];
2750 if (!p_queue->cids[qid_usage_idx].p_cid ||
2751 !p_queue->cids[qid_usage_idx].b_is_tx)
2754 rc = ecore_eth_tx_queue_stop(p_hwfn,
2755 p_queue->cids[qid_usage_idx].p_cid);
2756 if (rc != ECORE_SUCCESS)
2759 p_queue->cids[qid_usage_idx].p_cid = OSAL_NULL;
2760 return ECORE_SUCCESS;
2763 static void ecore_iov_vf_mbx_stop_rxqs(struct ecore_hwfn *p_hwfn,
2764 struct ecore_ptt *p_ptt,
2765 struct ecore_vf_info *vf)
2767 u16 length = sizeof(struct pfvf_def_resp_tlv);
2768 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
2769 u8 status = PFVF_STATUS_FAILURE;
2770 struct vfpf_stop_rxqs_tlv *req;
2772 enum _ecore_status_t rc;
2774 /* Starting with CHANNEL_TLV_QID, it's assumed the 'num_rxqs'
2775 * would be one. Since no older ecore passed multiple queues
2776 * using this API, sanitize on the value.
2778 req = &mbx->req_virt->stop_rxqs;
2779 if (req->num_rxqs != 1) {
2780 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2781 "Odd; VF[%d] tried stopping multiple Rx queues\n",
2782 vf->relative_vf_id);
2783 status = PFVF_STATUS_NOT_SUPPORTED;
2787 /* Find which qid-index is associated with the queue */
2788 qid_usage_idx = ecore_iov_vf_mbx_qid(p_hwfn, vf, false);
2789 if (qid_usage_idx == ECORE_IOV_QID_INVALID)
2792 rc = ecore_iov_vf_stop_rxqs(p_hwfn, vf, req->rx_qid,
2793 qid_usage_idx, req->cqe_completion);
2794 if (rc == ECORE_SUCCESS)
2795 status = PFVF_STATUS_SUCCESS;
2797 ecore_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_STOP_RXQS,
2801 static void ecore_iov_vf_mbx_stop_txqs(struct ecore_hwfn *p_hwfn,
2802 struct ecore_ptt *p_ptt,
2803 struct ecore_vf_info *vf)
2805 u16 length = sizeof(struct pfvf_def_resp_tlv);
2806 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
2807 u8 status = PFVF_STATUS_FAILURE;
2808 struct vfpf_stop_txqs_tlv *req;
2810 enum _ecore_status_t rc;
2812 /* Starting with CHANNEL_TLV_QID, it's assumed the 'num_txqs'
2813 * would be one. Since no older ecore passed multiple queues
2814 * using this API, sanitize on the value.
2816 req = &mbx->req_virt->stop_txqs;
2817 if (req->num_txqs != 1) {
2818 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2819 "Odd; VF[%d] tried stopping multiple Tx queues\n",
2820 vf->relative_vf_id);
2821 status = PFVF_STATUS_NOT_SUPPORTED;
2825 /* Find which qid-index is associated with the queue */
2826 qid_usage_idx = ecore_iov_vf_mbx_qid(p_hwfn, vf, true);
2827 if (qid_usage_idx == ECORE_IOV_QID_INVALID)
2830 rc = ecore_iov_vf_stop_txqs(p_hwfn, vf, req->tx_qid,
2832 if (rc == ECORE_SUCCESS)
2833 status = PFVF_STATUS_SUCCESS;
2836 ecore_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_STOP_TXQS,
2840 static void ecore_iov_vf_mbx_update_rxqs(struct ecore_hwfn *p_hwfn,
2841 struct ecore_ptt *p_ptt,
2842 struct ecore_vf_info *vf)
2844 struct ecore_queue_cid *handlers[ECORE_MAX_VF_CHAINS_PER_PF];
2845 u16 length = sizeof(struct pfvf_def_resp_tlv);
2846 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
2847 struct vfpf_update_rxq_tlv *req;
2848 u8 status = PFVF_STATUS_FAILURE;
2849 u8 complete_event_flg;
2850 u8 complete_cqe_flg;
2852 enum _ecore_status_t rc;
2855 req = &mbx->req_virt->update_rxq;
2856 complete_cqe_flg = !!(req->flags & VFPF_RXQ_UPD_COMPLETE_CQE_FLAG);
2857 complete_event_flg = !!(req->flags & VFPF_RXQ_UPD_COMPLETE_EVENT_FLAG);
2859 qid_usage_idx = ecore_iov_vf_mbx_qid(p_hwfn, vf, false);
2860 if (qid_usage_idx == ECORE_IOV_QID_INVALID)
2863 /* Starting with the addition of CHANNEL_TLV_QID, this API started
2864 * expecting a single queue at a time. Validate this.
2866 if ((vf->acquire.vfdev_info.capabilities &
2867 VFPF_ACQUIRE_CAP_QUEUE_QIDS) &&
2868 req->num_rxqs != 1) {
2869 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2870 "VF[%d] supports QIDs but sends multiple queues\n",
2871 vf->relative_vf_id);
2875 /* Validate inputs - for the legacy case this is still true since
2876 * qid_usage_idx for each Rx queue would be LEGACY_QID_RX.
2878 for (i = req->rx_qid; i < req->rx_qid + req->num_rxqs; i++) {
2879 if (!ecore_iov_validate_rxq(p_hwfn, vf, i,
2880 ECORE_IOV_VALIDATE_Q_NA) ||
2881 !vf->vf_queues[i].cids[qid_usage_idx].p_cid ||
2882 vf->vf_queues[i].cids[qid_usage_idx].b_is_tx) {
2883 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2884 "VF[%d]: Incorrect Rxqs [%04x, %02x]\n",
2885 vf->relative_vf_id, req->rx_qid,
2891 for (i = 0; i < req->num_rxqs; i++) {
2892 u16 qid = req->rx_qid + i;
2894 handlers[i] = vf->vf_queues[qid].cids[qid_usage_idx].p_cid;
2897 rc = ecore_sp_eth_rx_queues_update(p_hwfn, (void **)&handlers,
2901 ECORE_SPQ_MODE_EBLOCK,
2903 if (rc != ECORE_SUCCESS)
2906 status = PFVF_STATUS_SUCCESS;
2908 ecore_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_UPDATE_RXQ,
2912 static enum _ecore_status_t
2913 ecore_iov_vf_pf_update_mtu(struct ecore_hwfn *p_hwfn,
2914 struct ecore_ptt *p_ptt,
2915 struct ecore_vf_info *p_vf)
2917 struct ecore_iov_vf_mbx *mbx = &p_vf->vf_mbx;
2918 struct ecore_sp_vport_update_params params;
2919 enum _ecore_status_t rc = ECORE_SUCCESS;
2920 struct vfpf_update_mtu_tlv *p_req;
2921 u8 status = PFVF_STATUS_SUCCESS;
2923 /* Valiate PF can send such a request */
2924 if (!p_vf->vport_instance) {
2925 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2926 "No VPORT instance available for VF[%d], failing MTU update\n",
2928 status = PFVF_STATUS_FAILURE;
2932 p_req = &mbx->req_virt->update_mtu;
2934 OSAL_MEMSET(¶ms, 0, sizeof(params));
2935 params.opaque_fid = p_vf->opaque_fid;
2936 params.vport_id = p_vf->vport_id;
2937 params.mtu = p_req->mtu;
2938 rc = ecore_sp_vport_update(p_hwfn, ¶ms, ECORE_SPQ_MODE_EBLOCK,
2942 status = PFVF_STATUS_FAILURE;
2944 ecore_iov_prepare_resp(p_hwfn, p_ptt, p_vf,
2945 CHANNEL_TLV_UPDATE_MTU,
2946 sizeof(struct pfvf_def_resp_tlv),
2951 void *ecore_iov_search_list_tlvs(struct ecore_hwfn *p_hwfn,
2952 void *p_tlvs_list, u16 req_type)
2954 struct channel_tlv *p_tlv = (struct channel_tlv *)p_tlvs_list;
2958 if (!p_tlv->length) {
2959 DP_NOTICE(p_hwfn, true, "Zero length TLV found\n");
2963 if (p_tlv->type == req_type) {
2964 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2965 "Extended tlv type %s, length %d found\n",
2966 qede_ecore_channel_tlvs_string[p_tlv->type],
2971 len += p_tlv->length;
2972 p_tlv = (struct channel_tlv *)((u8 *)p_tlv + p_tlv->length);
2974 if ((len + p_tlv->length) > TLV_BUFFER_SIZE) {
2975 DP_NOTICE(p_hwfn, true,
2976 "TLVs has overrun the buffer size\n");
2979 } while (p_tlv->type != CHANNEL_TLV_LIST_END);
2985 ecore_iov_vp_update_act_param(struct ecore_hwfn *p_hwfn,
2986 struct ecore_sp_vport_update_params *p_data,
2987 struct ecore_iov_vf_mbx *p_mbx, u16 *tlvs_mask)
2989 struct vfpf_vport_update_activate_tlv *p_act_tlv;
2990 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_ACTIVATE;
2992 p_act_tlv = (struct vfpf_vport_update_activate_tlv *)
2993 ecore_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
2997 p_data->update_vport_active_rx_flg = p_act_tlv->update_rx;
2998 p_data->vport_active_rx_flg = p_act_tlv->active_rx;
2999 p_data->update_vport_active_tx_flg = p_act_tlv->update_tx;
3000 p_data->vport_active_tx_flg = p_act_tlv->active_tx;
3001 *tlvs_mask |= 1 << ECORE_IOV_VP_UPDATE_ACTIVATE;
3005 ecore_iov_vp_update_vlan_param(struct ecore_hwfn *p_hwfn,
3006 struct ecore_sp_vport_update_params *p_data,
3007 struct ecore_vf_info *p_vf,
3008 struct ecore_iov_vf_mbx *p_mbx, u16 *tlvs_mask)
3010 struct vfpf_vport_update_vlan_strip_tlv *p_vlan_tlv;
3011 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_VLAN_STRIP;
3013 p_vlan_tlv = (struct vfpf_vport_update_vlan_strip_tlv *)
3014 ecore_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
3018 p_vf->shadow_config.inner_vlan_removal = p_vlan_tlv->remove_vlan;
3020 /* Ignore the VF request if we're forcing a vlan */
3021 if (!(p_vf->configured_features & (1 << VLAN_ADDR_FORCED))) {
3022 p_data->update_inner_vlan_removal_flg = 1;
3023 p_data->inner_vlan_removal_flg = p_vlan_tlv->remove_vlan;
3026 *tlvs_mask |= 1 << ECORE_IOV_VP_UPDATE_VLAN_STRIP;
3030 ecore_iov_vp_update_tx_switch(struct ecore_hwfn *p_hwfn,
3031 struct ecore_sp_vport_update_params *p_data,
3032 struct ecore_iov_vf_mbx *p_mbx, u16 *tlvs_mask)
3034 struct vfpf_vport_update_tx_switch_tlv *p_tx_switch_tlv;
3035 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_TX_SWITCH;
3037 p_tx_switch_tlv = (struct vfpf_vport_update_tx_switch_tlv *)
3038 ecore_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
3039 if (!p_tx_switch_tlv)
3043 if (CHIP_REV_IS_FPGA(p_hwfn->p_dev)) {
3044 DP_NOTICE(p_hwfn, false,
3045 "FPGA: Ignore tx-switching configuration originating"
3051 p_data->update_tx_switching_flg = 1;
3052 p_data->tx_switching_flg = p_tx_switch_tlv->tx_switching;
3053 *tlvs_mask |= 1 << ECORE_IOV_VP_UPDATE_TX_SWITCH;
3057 ecore_iov_vp_update_mcast_bin_param(struct ecore_hwfn *p_hwfn,
3058 struct ecore_sp_vport_update_params *p_data,
3059 struct ecore_iov_vf_mbx *p_mbx,
3062 struct vfpf_vport_update_mcast_bin_tlv *p_mcast_tlv;
3063 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_MCAST;
3065 p_mcast_tlv = (struct vfpf_vport_update_mcast_bin_tlv *)
3066 ecore_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
3070 p_data->update_approx_mcast_flg = 1;
3071 OSAL_MEMCPY(p_data->bins, p_mcast_tlv->bins,
3072 sizeof(u32) * ETH_MULTICAST_MAC_BINS_IN_REGS);
3073 *tlvs_mask |= 1 << ECORE_IOV_VP_UPDATE_MCAST;
3077 ecore_iov_vp_update_accept_flag(struct ecore_hwfn *p_hwfn,
3078 struct ecore_sp_vport_update_params *p_data,
3079 struct ecore_iov_vf_mbx *p_mbx, u16 *tlvs_mask)
3081 struct ecore_filter_accept_flags *p_flags = &p_data->accept_flags;
3082 struct vfpf_vport_update_accept_param_tlv *p_accept_tlv;
3083 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_ACCEPT_PARAM;
3085 p_accept_tlv = (struct vfpf_vport_update_accept_param_tlv *)
3086 ecore_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
3090 p_flags->update_rx_mode_config = p_accept_tlv->update_rx_mode;
3091 p_flags->rx_accept_filter = p_accept_tlv->rx_accept_filter;
3092 p_flags->update_tx_mode_config = p_accept_tlv->update_tx_mode;
3093 p_flags->tx_accept_filter = p_accept_tlv->tx_accept_filter;
3094 *tlvs_mask |= 1 << ECORE_IOV_VP_UPDATE_ACCEPT_PARAM;
3098 ecore_iov_vp_update_accept_any_vlan(struct ecore_hwfn *p_hwfn,
3099 struct ecore_sp_vport_update_params *p_data,
3100 struct ecore_iov_vf_mbx *p_mbx,
3103 struct vfpf_vport_update_accept_any_vlan_tlv *p_accept_any_vlan;
3104 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_ACCEPT_ANY_VLAN;
3106 p_accept_any_vlan = (struct vfpf_vport_update_accept_any_vlan_tlv *)
3107 ecore_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
3108 if (!p_accept_any_vlan)
3111 p_data->accept_any_vlan = p_accept_any_vlan->accept_any_vlan;
3112 p_data->update_accept_any_vlan_flg =
3113 p_accept_any_vlan->update_accept_any_vlan_flg;
3114 *tlvs_mask |= 1 << ECORE_IOV_VP_UPDATE_ACCEPT_ANY_VLAN;
3118 ecore_iov_vp_update_rss_param(struct ecore_hwfn *p_hwfn,
3119 struct ecore_vf_info *vf,
3120 struct ecore_sp_vport_update_params *p_data,
3121 struct ecore_rss_params *p_rss,
3122 struct ecore_iov_vf_mbx *p_mbx,
3123 u16 *tlvs_mask, u16 *tlvs_accepted)
3125 struct vfpf_vport_update_rss_tlv *p_rss_tlv;
3126 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_RSS;
3127 bool b_reject = false;
3131 p_rss_tlv = (struct vfpf_vport_update_rss_tlv *)
3132 ecore_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
3134 p_data->rss_params = OSAL_NULL;
3138 OSAL_MEMSET(p_rss, 0, sizeof(struct ecore_rss_params));
3140 p_rss->update_rss_config =
3141 !!(p_rss_tlv->update_rss_flags &
3142 VFPF_UPDATE_RSS_CONFIG_FLAG);
3143 p_rss->update_rss_capabilities =
3144 !!(p_rss_tlv->update_rss_flags &
3145 VFPF_UPDATE_RSS_CAPS_FLAG);
3146 p_rss->update_rss_ind_table =
3147 !!(p_rss_tlv->update_rss_flags &
3148 VFPF_UPDATE_RSS_IND_TABLE_FLAG);
3149 p_rss->update_rss_key =
3150 !!(p_rss_tlv->update_rss_flags &
3151 VFPF_UPDATE_RSS_KEY_FLAG);
3153 p_rss->rss_enable = p_rss_tlv->rss_enable;
3154 p_rss->rss_eng_id = vf->rss_eng_id;
3155 p_rss->rss_caps = p_rss_tlv->rss_caps;
3156 p_rss->rss_table_size_log = p_rss_tlv->rss_table_size_log;
3157 OSAL_MEMCPY(p_rss->rss_key, p_rss_tlv->rss_key,
3158 sizeof(p_rss->rss_key));
3160 table_size = OSAL_MIN_T(u16, OSAL_ARRAY_SIZE(p_rss->rss_ind_table),
3161 (1 << p_rss_tlv->rss_table_size_log));
3163 for (i = 0; i < table_size; i++) {
3164 struct ecore_queue_cid *p_cid;
3166 q_idx = p_rss_tlv->rss_ind_table[i];
3167 if (!ecore_iov_validate_rxq(p_hwfn, vf, q_idx,
3168 ECORE_IOV_VALIDATE_Q_ENABLE)) {
3169 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3170 "VF[%d]: Omitting RSS due to wrong queue %04x\n",
3171 vf->relative_vf_id, q_idx);
3176 p_cid = ecore_iov_get_vf_rx_queue_cid(&vf->vf_queues[q_idx]);
3177 p_rss->rss_ind_table[i] = p_cid;
3180 p_data->rss_params = p_rss;
3182 *tlvs_mask |= 1 << ECORE_IOV_VP_UPDATE_RSS;
3184 *tlvs_accepted |= 1 << ECORE_IOV_VP_UPDATE_RSS;
3188 ecore_iov_vp_update_sge_tpa_param(struct ecore_hwfn *p_hwfn,
3189 struct ecore_sp_vport_update_params *p_data,
3190 struct ecore_sge_tpa_params *p_sge_tpa,
3191 struct ecore_iov_vf_mbx *p_mbx,
3194 struct vfpf_vport_update_sge_tpa_tlv *p_sge_tpa_tlv;
3195 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_SGE_TPA;
3197 p_sge_tpa_tlv = (struct vfpf_vport_update_sge_tpa_tlv *)
3198 ecore_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
3200 if (!p_sge_tpa_tlv) {
3201 p_data->sge_tpa_params = OSAL_NULL;
3205 OSAL_MEMSET(p_sge_tpa, 0, sizeof(struct ecore_sge_tpa_params));
3207 p_sge_tpa->update_tpa_en_flg =
3208 !!(p_sge_tpa_tlv->update_sge_tpa_flags & VFPF_UPDATE_TPA_EN_FLAG);
3209 p_sge_tpa->update_tpa_param_flg =
3210 !!(p_sge_tpa_tlv->update_sge_tpa_flags &
3211 VFPF_UPDATE_TPA_PARAM_FLAG);
3213 p_sge_tpa->tpa_ipv4_en_flg =
3214 !!(p_sge_tpa_tlv->sge_tpa_flags & VFPF_TPA_IPV4_EN_FLAG);
3215 p_sge_tpa->tpa_ipv6_en_flg =
3216 !!(p_sge_tpa_tlv->sge_tpa_flags & VFPF_TPA_IPV6_EN_FLAG);
3217 p_sge_tpa->tpa_pkt_split_flg =
3218 !!(p_sge_tpa_tlv->sge_tpa_flags & VFPF_TPA_PKT_SPLIT_FLAG);
3219 p_sge_tpa->tpa_hdr_data_split_flg =
3220 !!(p_sge_tpa_tlv->sge_tpa_flags & VFPF_TPA_HDR_DATA_SPLIT_FLAG);
3221 p_sge_tpa->tpa_gro_consistent_flg =
3222 !!(p_sge_tpa_tlv->sge_tpa_flags & VFPF_TPA_GRO_CONSIST_FLAG);
3224 p_sge_tpa->tpa_max_aggs_num = p_sge_tpa_tlv->tpa_max_aggs_num;
3225 p_sge_tpa->tpa_max_size = p_sge_tpa_tlv->tpa_max_size;
3226 p_sge_tpa->tpa_min_size_to_start = p_sge_tpa_tlv->tpa_min_size_to_start;
3227 p_sge_tpa->tpa_min_size_to_cont = p_sge_tpa_tlv->tpa_min_size_to_cont;
3228 p_sge_tpa->max_buffers_per_cqe = p_sge_tpa_tlv->max_buffers_per_cqe;
3230 p_data->sge_tpa_params = p_sge_tpa;
3232 *tlvs_mask |= 1 << ECORE_IOV_VP_UPDATE_SGE_TPA;
3235 static void ecore_iov_vf_mbx_vport_update(struct ecore_hwfn *p_hwfn,
3236 struct ecore_ptt *p_ptt,
3237 struct ecore_vf_info *vf)
3239 struct ecore_rss_params *p_rss_params = OSAL_NULL;
3240 struct ecore_sp_vport_update_params params;
3241 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
3242 struct ecore_sge_tpa_params sge_tpa_params;
3243 u16 tlvs_mask = 0, tlvs_accepted = 0;
3244 u8 status = PFVF_STATUS_SUCCESS;
3246 enum _ecore_status_t rc;
3248 /* Valiate PF can send such a request */
3249 if (!vf->vport_instance) {
3250 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3251 "No VPORT instance available for VF[%d],"
3252 " failing vport update\n",
3254 status = PFVF_STATUS_FAILURE;
3258 p_rss_params = OSAL_VZALLOC(p_hwfn->p_dev, sizeof(*p_rss_params));
3259 if (p_rss_params == OSAL_NULL) {
3260 status = PFVF_STATUS_FAILURE;
3264 OSAL_MEMSET(¶ms, 0, sizeof(params));
3265 params.opaque_fid = vf->opaque_fid;
3266 params.vport_id = vf->vport_id;
3267 params.rss_params = OSAL_NULL;
3269 /* Search for extended tlvs list and update values
3270 * from VF in struct ecore_sp_vport_update_params.
3272 ecore_iov_vp_update_act_param(p_hwfn, ¶ms, mbx, &tlvs_mask);
3273 ecore_iov_vp_update_vlan_param(p_hwfn, ¶ms, vf, mbx, &tlvs_mask);
3274 ecore_iov_vp_update_tx_switch(p_hwfn, ¶ms, mbx, &tlvs_mask);
3275 ecore_iov_vp_update_mcast_bin_param(p_hwfn, ¶ms, mbx, &tlvs_mask);
3276 ecore_iov_vp_update_accept_flag(p_hwfn, ¶ms, mbx, &tlvs_mask);
3277 ecore_iov_vp_update_accept_any_vlan(p_hwfn, ¶ms, mbx, &tlvs_mask);
3278 ecore_iov_vp_update_sge_tpa_param(p_hwfn, ¶ms,
3279 &sge_tpa_params, mbx, &tlvs_mask);
3281 tlvs_accepted = tlvs_mask;
3283 /* Some of the extended TLVs need to be validated first; In that case,
3284 * they can update the mask without updating the accepted [so that
3285 * PF could communicate to VF it has rejected request].
3287 ecore_iov_vp_update_rss_param(p_hwfn, vf, ¶ms, p_rss_params,
3288 mbx, &tlvs_mask, &tlvs_accepted);
3290 /* Just log a message if there is no single extended tlv in buffer.
3291 * When all features of vport update ramrod would be requested by VF
3292 * as extended TLVs in buffer then an error can be returned in response
3293 * if there is no extended TLV present in buffer.
3295 if (OSAL_IOV_VF_VPORT_UPDATE(p_hwfn, vf->relative_vf_id,
3296 ¶ms, &tlvs_accepted) !=
3299 status = PFVF_STATUS_NOT_SUPPORTED;
3303 if (!tlvs_accepted) {
3305 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3306 "Upper-layer prevents said VF"
3307 " configuration\n");
3309 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3310 "No feature tlvs found for vport update\n");
3311 status = PFVF_STATUS_NOT_SUPPORTED;
3315 rc = ecore_sp_vport_update(p_hwfn, ¶ms, ECORE_SPQ_MODE_EBLOCK,
3319 status = PFVF_STATUS_FAILURE;
3322 OSAL_VFREE(p_hwfn->p_dev, p_rss_params);
3323 length = ecore_iov_prep_vp_update_resp_tlvs(p_hwfn, vf, mbx, status,
3324 tlvs_mask, tlvs_accepted);
3325 ecore_iov_send_response(p_hwfn, p_ptt, vf, length, status);
3328 static enum _ecore_status_t
3329 ecore_iov_vf_update_vlan_shadow(struct ecore_hwfn *p_hwfn,
3330 struct ecore_vf_info *p_vf,
3331 struct ecore_filter_ucast *p_params)
3335 /* First remove entries and then add new ones */
3336 if (p_params->opcode == ECORE_FILTER_REMOVE) {
3337 for (i = 0; i < ECORE_ETH_VF_NUM_VLAN_FILTERS + 1; i++)
3338 if (p_vf->shadow_config.vlans[i].used &&
3339 p_vf->shadow_config.vlans[i].vid ==
3341 p_vf->shadow_config.vlans[i].used = false;
3344 if (i == ECORE_ETH_VF_NUM_VLAN_FILTERS + 1) {
3345 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3346 "VF [%d] - Tries to remove a non-existing"
3348 p_vf->relative_vf_id);
3351 } else if (p_params->opcode == ECORE_FILTER_REPLACE ||
3352 p_params->opcode == ECORE_FILTER_FLUSH) {
3353 for (i = 0; i < ECORE_ETH_VF_NUM_VLAN_FILTERS + 1; i++)
3354 p_vf->shadow_config.vlans[i].used = false;
3357 /* In forced mode, we're willing to remove entries - but we don't add
3360 if (p_vf->bulletin.p_virt->valid_bitmap & (1 << VLAN_ADDR_FORCED))
3361 return ECORE_SUCCESS;
3363 if (p_params->opcode == ECORE_FILTER_ADD ||
3364 p_params->opcode == ECORE_FILTER_REPLACE) {
3365 for (i = 0; i < ECORE_ETH_VF_NUM_VLAN_FILTERS + 1; i++) {
3366 if (p_vf->shadow_config.vlans[i].used)
3369 p_vf->shadow_config.vlans[i].used = true;
3370 p_vf->shadow_config.vlans[i].vid = p_params->vlan;
3374 if (i == ECORE_ETH_VF_NUM_VLAN_FILTERS + 1) {
3375 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3376 "VF [%d] - Tries to configure more than %d"
3378 p_vf->relative_vf_id,
3379 ECORE_ETH_VF_NUM_VLAN_FILTERS + 1);
3384 return ECORE_SUCCESS;
3387 static enum _ecore_status_t
3388 ecore_iov_vf_update_mac_shadow(struct ecore_hwfn *p_hwfn,
3389 struct ecore_vf_info *p_vf,
3390 struct ecore_filter_ucast *p_params)
3392 char empty_mac[ETH_ALEN];
3395 OSAL_MEM_ZERO(empty_mac, ETH_ALEN);
3397 /* If we're in forced-mode, we don't allow any change */
3398 /* TODO - this would change if we were ever to implement logic for
3399 * removing a forced MAC altogether [in which case, like for vlans,
3400 * we should be able to re-trace previous configuration.
3402 if (p_vf->bulletin.p_virt->valid_bitmap & (1 << MAC_ADDR_FORCED))
3403 return ECORE_SUCCESS;
3405 /* Since we don't have the implementation of the logic for removing
3406 * a forced MAC and restoring shadow MAC, let's not worry about
3407 * processing shadow copies of MAC as long as VF trust mode is ON,
3408 * to keep things simple.
3410 if (p_hwfn->pf_params.eth_pf_params.allow_vf_mac_change ||
3411 p_vf->p_vf_info.is_trusted_configured)
3412 return ECORE_SUCCESS;
3414 /* First remove entries and then add new ones */
3415 if (p_params->opcode == ECORE_FILTER_REMOVE) {
3416 for (i = 0; i < ECORE_ETH_VF_NUM_MAC_FILTERS; i++) {
3417 if (!OSAL_MEMCMP(p_vf->shadow_config.macs[i],
3418 p_params->mac, ETH_ALEN)) {
3419 OSAL_MEM_ZERO(p_vf->shadow_config.macs[i],
3425 if (i == ECORE_ETH_VF_NUM_MAC_FILTERS) {
3426 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3427 "MAC isn't configured\n");
3430 } else if (p_params->opcode == ECORE_FILTER_REPLACE ||
3431 p_params->opcode == ECORE_FILTER_FLUSH) {
3432 for (i = 0; i < ECORE_ETH_VF_NUM_MAC_FILTERS; i++)
3433 OSAL_MEM_ZERO(p_vf->shadow_config.macs[i], ETH_ALEN);
3436 /* List the new MAC address */
3437 if (p_params->opcode != ECORE_FILTER_ADD &&
3438 p_params->opcode != ECORE_FILTER_REPLACE)
3439 return ECORE_SUCCESS;
3441 for (i = 0; i < ECORE_ETH_VF_NUM_MAC_FILTERS; i++) {
3442 if (!OSAL_MEMCMP(p_vf->shadow_config.macs[i],
3443 empty_mac, ETH_ALEN)) {
3444 OSAL_MEMCPY(p_vf->shadow_config.macs[i],
3445 p_params->mac, ETH_ALEN);
3446 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3447 "Added MAC at %d entry in shadow\n", i);
3452 if (i == ECORE_ETH_VF_NUM_MAC_FILTERS) {
3453 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3454 "No available place for MAC\n");
3458 return ECORE_SUCCESS;
3461 static enum _ecore_status_t
3462 ecore_iov_vf_update_unicast_shadow(struct ecore_hwfn *p_hwfn,
3463 struct ecore_vf_info *p_vf,
3464 struct ecore_filter_ucast *p_params)
3466 enum _ecore_status_t rc = ECORE_SUCCESS;
3468 if (p_params->type == ECORE_FILTER_MAC) {
3469 rc = ecore_iov_vf_update_mac_shadow(p_hwfn, p_vf, p_params);
3470 if (rc != ECORE_SUCCESS)
3474 if (p_params->type == ECORE_FILTER_VLAN)
3475 rc = ecore_iov_vf_update_vlan_shadow(p_hwfn, p_vf, p_params);
3480 static void ecore_iov_vf_mbx_ucast_filter(struct ecore_hwfn *p_hwfn,
3481 struct ecore_ptt *p_ptt,
3482 struct ecore_vf_info *vf)
3484 struct ecore_bulletin_content *p_bulletin = vf->bulletin.p_virt;
3485 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
3486 struct vfpf_ucast_filter_tlv *req;
3487 u8 status = PFVF_STATUS_SUCCESS;
3488 struct ecore_filter_ucast params;
3489 enum _ecore_status_t rc;
3491 /* Prepare the unicast filter params */
3492 OSAL_MEMSET(¶ms, 0, sizeof(struct ecore_filter_ucast));
3493 req = &mbx->req_virt->ucast_filter;
3494 params.opcode = (enum ecore_filter_opcode)req->opcode;
3495 params.type = (enum ecore_filter_ucast_type)req->type;
3497 /* @@@TBD - We might need logic on HV side in determining this */
3498 params.is_rx_filter = 1;
3499 params.is_tx_filter = 1;
3500 params.vport_to_remove_from = vf->vport_id;
3501 params.vport_to_add_to = vf->vport_id;
3502 OSAL_MEMCPY(params.mac, req->mac, ETH_ALEN);
3503 params.vlan = req->vlan;
3505 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3506 "VF[%d]: opcode 0x%02x type 0x%02x [%s %s] [vport 0x%02x]"
3507 " MAC %02x:%02x:%02x:%02x:%02x:%02x, vlan 0x%04x\n",
3508 vf->abs_vf_id, params.opcode, params.type,
3509 params.is_rx_filter ? "RX" : "",
3510 params.is_tx_filter ? "TX" : "",
3511 params.vport_to_add_to,
3512 params.mac[0], params.mac[1], params.mac[2],
3513 params.mac[3], params.mac[4], params.mac[5], params.vlan);
3515 if (!vf->vport_instance) {
3516 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3517 "No VPORT instance available for VF[%d],"
3518 " failing ucast MAC configuration\n",
3520 status = PFVF_STATUS_FAILURE;
3524 /* Update shadow copy of the VF configuration. In case shadow indicates
3525 * the action should be blocked return success to VF to imitate the
3526 * firmware behaviour in such case.
3528 if (ecore_iov_vf_update_unicast_shadow(p_hwfn, vf, ¶ms) !=
3532 /* Determine if the unicast filtering is acceptible by PF */
3533 if ((p_bulletin->valid_bitmap & (1 << VLAN_ADDR_FORCED)) &&
3534 (params.type == ECORE_FILTER_VLAN ||
3535 params.type == ECORE_FILTER_MAC_VLAN)) {
3536 /* Once VLAN is forced or PVID is set, do not allow
3537 * to add/replace any further VLANs.
3539 if (params.opcode == ECORE_FILTER_ADD ||
3540 params.opcode == ECORE_FILTER_REPLACE)
3541 status = PFVF_STATUS_FORCED;
3545 if ((p_bulletin->valid_bitmap & (1 << MAC_ADDR_FORCED)) &&
3546 (params.type == ECORE_FILTER_MAC ||
3547 params.type == ECORE_FILTER_MAC_VLAN)) {
3548 if (OSAL_MEMCMP(p_bulletin->mac, params.mac, ETH_ALEN) ||
3549 (params.opcode != ECORE_FILTER_ADD &&
3550 params.opcode != ECORE_FILTER_REPLACE))
3551 status = PFVF_STATUS_FORCED;
3555 rc = OSAL_IOV_CHK_UCAST(p_hwfn, vf->relative_vf_id, ¶ms);
3556 if (rc == ECORE_EXISTS) {
3558 } else if (rc == ECORE_INVAL) {
3559 status = PFVF_STATUS_FAILURE;
3563 rc = ecore_sp_eth_filter_ucast(p_hwfn, vf->opaque_fid, ¶ms,
3564 ECORE_SPQ_MODE_CB, OSAL_NULL);
3566 status = PFVF_STATUS_FAILURE;
3569 ecore_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_UCAST_FILTER,
3570 sizeof(struct pfvf_def_resp_tlv), status);
3573 static void ecore_iov_vf_mbx_int_cleanup(struct ecore_hwfn *p_hwfn,
3574 struct ecore_ptt *p_ptt,
3575 struct ecore_vf_info *vf)
3580 for (i = 0; i < vf->num_sbs; i++)
3581 ecore_int_igu_init_pure_rt_single(p_hwfn, p_ptt,
3583 vf->opaque_fid, false);
3585 ecore_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_INT_CLEANUP,
3586 sizeof(struct pfvf_def_resp_tlv),
3587 PFVF_STATUS_SUCCESS);
3590 static void ecore_iov_vf_mbx_close(struct ecore_hwfn *p_hwfn,
3591 struct ecore_ptt *p_ptt,
3592 struct ecore_vf_info *vf)
3594 u16 length = sizeof(struct pfvf_def_resp_tlv);
3595 u8 status = PFVF_STATUS_SUCCESS;
3597 /* Disable Interrupts for VF */
3598 ecore_iov_vf_igu_set_int(p_hwfn, p_ptt, vf, 0);
3600 /* Reset Permission table */
3601 ecore_iov_config_perm_table(p_hwfn, p_ptt, vf, 0);
3603 ecore_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_CLOSE,
3607 static void ecore_iov_vf_mbx_release(struct ecore_hwfn *p_hwfn,
3608 struct ecore_ptt *p_ptt,
3609 struct ecore_vf_info *p_vf)
3611 u16 length = sizeof(struct pfvf_def_resp_tlv);
3612 u8 status = PFVF_STATUS_SUCCESS;
3613 enum _ecore_status_t rc = ECORE_SUCCESS;
3615 ecore_iov_vf_cleanup(p_hwfn, p_vf);
3617 if (p_vf->state != VF_STOPPED && p_vf->state != VF_FREE) {
3618 /* Stopping the VF */
3619 rc = ecore_sp_vf_stop(p_hwfn, p_vf->concrete_fid,
3622 if (rc != ECORE_SUCCESS) {
3623 DP_ERR(p_hwfn, "ecore_sp_vf_stop returned error %d\n",
3625 status = PFVF_STATUS_FAILURE;
3628 p_vf->state = VF_STOPPED;
3631 ecore_iov_prepare_resp(p_hwfn, p_ptt, p_vf, CHANNEL_TLV_RELEASE,
3635 static void ecore_iov_vf_pf_get_coalesce(struct ecore_hwfn *p_hwfn,
3636 struct ecore_ptt *p_ptt,
3637 struct ecore_vf_info *p_vf)
3639 struct ecore_iov_vf_mbx *mbx = &p_vf->vf_mbx;
3640 struct pfvf_read_coal_resp_tlv *p_resp;
3641 struct vfpf_read_coal_req_tlv *req;
3642 u8 status = PFVF_STATUS_FAILURE;
3643 struct ecore_vf_queue *p_queue;
3644 struct ecore_queue_cid *p_cid;
3645 enum _ecore_status_t rc = ECORE_SUCCESS;
3646 u16 coal = 0, qid, i;
3649 mbx->offset = (u8 *)mbx->reply_virt;
3650 req = &mbx->req_virt->read_coal_req;
3653 b_is_rx = req->is_rx ? true : false;
3656 if (!ecore_iov_validate_rxq(p_hwfn, p_vf, qid,
3657 ECORE_IOV_VALIDATE_Q_ENABLE)) {
3658 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3659 "VF[%d]: Invalid Rx queue_id = %d\n",
3660 p_vf->abs_vf_id, qid);
3664 p_cid = ecore_iov_get_vf_rx_queue_cid(&p_vf->vf_queues[qid]);
3665 rc = ecore_get_rxq_coalesce(p_hwfn, p_ptt, p_cid, &coal);
3666 if (rc != ECORE_SUCCESS)
3669 if (!ecore_iov_validate_txq(p_hwfn, p_vf, qid,
3670 ECORE_IOV_VALIDATE_Q_ENABLE)) {
3671 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3672 "VF[%d]: Invalid Tx queue_id = %d\n",
3673 p_vf->abs_vf_id, qid);
3676 for (i = 0; i < MAX_QUEUES_PER_QZONE; i++) {
3677 p_queue = &p_vf->vf_queues[qid];
3678 if ((p_queue->cids[i].p_cid == OSAL_NULL) ||
3679 (!p_queue->cids[i].b_is_tx))
3682 p_cid = p_queue->cids[i].p_cid;
3684 rc = ecore_get_txq_coalesce(p_hwfn, p_ptt,
3686 if (rc != ECORE_SUCCESS)
3692 status = PFVF_STATUS_SUCCESS;
3695 p_resp = ecore_add_tlv(&mbx->offset, CHANNEL_TLV_COALESCE_READ,
3697 p_resp->coal = coal;
3699 ecore_add_tlv(&mbx->offset, CHANNEL_TLV_LIST_END,
3700 sizeof(struct channel_list_end_tlv));
3702 ecore_iov_send_response(p_hwfn, p_ptt, p_vf, sizeof(*p_resp), status);
3705 static void ecore_iov_vf_pf_set_coalesce(struct ecore_hwfn *p_hwfn,
3706 struct ecore_ptt *p_ptt,
3707 struct ecore_vf_info *vf)
3709 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
3710 enum _ecore_status_t rc = ECORE_SUCCESS;
3711 struct vfpf_update_coalesce *req;
3712 u8 status = PFVF_STATUS_FAILURE;
3713 struct ecore_queue_cid *p_cid;
3714 u16 rx_coal, tx_coal;
3718 req = &mbx->req_virt->update_coalesce;
3720 rx_coal = req->rx_coal;
3721 tx_coal = req->tx_coal;
3724 if (!ecore_iov_validate_rxq(p_hwfn, vf, qid,
3725 ECORE_IOV_VALIDATE_Q_ENABLE) &&
3727 DP_ERR(p_hwfn, "VF[%d]: Invalid Rx queue_id = %d\n",
3728 vf->abs_vf_id, qid);
3732 if (!ecore_iov_validate_txq(p_hwfn, vf, qid,
3733 ECORE_IOV_VALIDATE_Q_ENABLE) &&
3735 DP_ERR(p_hwfn, "VF[%d]: Invalid Tx queue_id = %d\n",
3736 vf->abs_vf_id, qid);
3740 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3741 "VF[%d]: Setting coalesce for VF rx_coal = %d, tx_coal = %d at queue = %d\n",
3742 vf->abs_vf_id, rx_coal, tx_coal, qid);
3745 p_cid = ecore_iov_get_vf_rx_queue_cid(&vf->vf_queues[qid]);
3747 rc = ecore_set_rxq_coalesce(p_hwfn, p_ptt, rx_coal, p_cid);
3748 if (rc != ECORE_SUCCESS) {
3749 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3750 "VF[%d]: Unable to set rx queue = %d coalesce\n",
3751 vf->abs_vf_id, vf->vf_queues[qid].fw_rx_qid);
3754 vf->rx_coal = rx_coal;
3757 /* TODO - in future, it might be possible to pass this in a per-cid
3758 * granularity. For now, do this for all Tx queues.
3761 struct ecore_vf_queue *p_queue = &vf->vf_queues[qid];
3763 for (i = 0; i < MAX_QUEUES_PER_QZONE; i++) {
3764 if (p_queue->cids[i].p_cid == OSAL_NULL)
3767 if (!p_queue->cids[i].b_is_tx)
3770 rc = ecore_set_txq_coalesce(p_hwfn, p_ptt, tx_coal,
3771 p_queue->cids[i].p_cid);
3772 if (rc != ECORE_SUCCESS) {
3773 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3774 "VF[%d]: Unable to set tx queue coalesce\n",
3779 vf->tx_coal = tx_coal;
3782 status = PFVF_STATUS_SUCCESS;
3784 ecore_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_COALESCE_UPDATE,
3785 sizeof(struct pfvf_def_resp_tlv), status);
3788 enum _ecore_status_t
3789 ecore_iov_pf_configure_vf_queue_coalesce(struct ecore_hwfn *p_hwfn,
3790 u16 rx_coal, u16 tx_coal,
3793 struct ecore_queue_cid *p_cid;
3794 struct ecore_vf_info *vf;
3795 struct ecore_ptt *p_ptt;
3799 if (!ecore_iov_is_valid_vfid(p_hwfn, vf_id, true, true)) {
3800 DP_NOTICE(p_hwfn, true,
3801 "VF[%d] - Can not set coalescing: VF is not active\n",
3806 vf = &p_hwfn->pf_iov_info->vfs_array[vf_id];
3807 p_ptt = ecore_ptt_acquire(p_hwfn);
3811 if (!ecore_iov_validate_rxq(p_hwfn, vf, qid,
3812 ECORE_IOV_VALIDATE_Q_ENABLE) &&
3814 DP_ERR(p_hwfn, "VF[%d]: Invalid Rx queue_id = %d\n",
3815 vf->abs_vf_id, qid);
3819 if (!ecore_iov_validate_txq(p_hwfn, vf, qid,
3820 ECORE_IOV_VALIDATE_Q_ENABLE) &&
3822 DP_ERR(p_hwfn, "VF[%d]: Invalid Tx queue_id = %d\n",
3823 vf->abs_vf_id, qid);
3827 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3828 "VF[%d]: Setting coalesce for VF rx_coal = %d, tx_coal = %d at queue = %d\n",
3829 vf->abs_vf_id, rx_coal, tx_coal, qid);
3832 p_cid = ecore_iov_get_vf_rx_queue_cid(&vf->vf_queues[qid]);
3834 rc = ecore_set_rxq_coalesce(p_hwfn, p_ptt, rx_coal, p_cid);
3835 if (rc != ECORE_SUCCESS) {
3836 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3837 "VF[%d]: Unable to set rx queue = %d coalesce\n",
3838 vf->abs_vf_id, vf->vf_queues[qid].fw_rx_qid);
3841 vf->rx_coal = rx_coal;
3844 /* TODO - in future, it might be possible to pass this in a per-cid
3845 * granularity. For now, do this for all Tx queues.
3848 struct ecore_vf_queue *p_queue = &vf->vf_queues[qid];
3850 for (i = 0; i < MAX_QUEUES_PER_QZONE; i++) {
3851 if (p_queue->cids[i].p_cid == OSAL_NULL)
3854 if (!p_queue->cids[i].b_is_tx)
3857 rc = ecore_set_txq_coalesce(p_hwfn, p_ptt, tx_coal,
3858 p_queue->cids[i].p_cid);
3859 if (rc != ECORE_SUCCESS) {
3860 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3861 "VF[%d]: Unable to set tx queue coalesce\n",
3866 vf->tx_coal = tx_coal;
3870 ecore_ptt_release(p_hwfn, p_ptt);
3875 static enum _ecore_status_t
3876 ecore_iov_vf_flr_poll_dorq(struct ecore_hwfn *p_hwfn,
3877 struct ecore_vf_info *p_vf, struct ecore_ptt *p_ptt)
3882 ecore_fid_pretend(p_hwfn, p_ptt, (u16)p_vf->concrete_fid);
3884 for (cnt = 0; cnt < 50; cnt++) {
3885 val = ecore_rd(p_hwfn, p_ptt, DORQ_REG_VF_USAGE_CNT);
3890 ecore_fid_pretend(p_hwfn, p_ptt, (u16)p_hwfn->hw_info.concrete_fid);
3894 "VF[%d] - dorq failed to cleanup [usage 0x%08x]\n",
3895 p_vf->abs_vf_id, val);
3896 return ECORE_TIMEOUT;
3899 return ECORE_SUCCESS;
3902 #define MAX_NUM_EXT_VOQS (MAX_NUM_PORTS * NUM_OF_TCS)
3904 static enum _ecore_status_t
3905 ecore_iov_vf_flr_poll_pbf(struct ecore_hwfn *p_hwfn,
3906 struct ecore_vf_info *p_vf, struct ecore_ptt *p_ptt)
3908 u32 prod, cons[MAX_NUM_EXT_VOQS], distance[MAX_NUM_EXT_VOQS], tmp;
3909 u8 max_phys_tcs_per_port = p_hwfn->qm_info.max_phys_tcs_per_port;
3910 u8 max_ports_per_engine = p_hwfn->p_dev->num_ports_in_engine;
3911 u32 prod_voq0_addr = PBF_REG_NUM_BLOCKS_ALLOCATED_PROD_VOQ0;
3912 u32 cons_voq0_addr = PBF_REG_NUM_BLOCKS_ALLOCATED_CONS_VOQ0;
3913 u8 port_id, tc, tc_id = 0, voq = 0;
3916 /* Read initial consumers & producers */
3917 for (port_id = 0; port_id < max_ports_per_engine; port_id++) {
3918 /* "max_phys_tcs_per_port" active TCs + 1 pure LB TC */
3919 for (tc = 0; tc < max_phys_tcs_per_port + 1; tc++) {
3920 tc_id = (tc < max_phys_tcs_per_port) ?
3923 voq = VOQ(port_id, tc_id, max_phys_tcs_per_port);
3924 cons[voq] = ecore_rd(p_hwfn, p_ptt,
3925 cons_voq0_addr + voq * 0x40);
3926 prod = ecore_rd(p_hwfn, p_ptt,
3927 prod_voq0_addr + voq * 0x40);
3928 distance[voq] = prod - cons[voq];
3932 /* Wait for consumers to pass the producers */
3935 for (cnt = 0; cnt < 50; cnt++) {
3936 for (; port_id < max_ports_per_engine; port_id++) {
3937 /* "max_phys_tcs_per_port" active TCs + 1 pure LB TC */
3938 for (; tc < max_phys_tcs_per_port + 1; tc++) {
3939 tc_id = (tc < max_phys_tcs_per_port) ?
3942 voq = VOQ(port_id, tc_id,
3943 max_phys_tcs_per_port);
3944 tmp = ecore_rd(p_hwfn, p_ptt,
3945 cons_voq0_addr + voq * 0x40);
3946 if (distance[voq] > tmp - cons[voq])
3950 if (tc == max_phys_tcs_per_port + 1)
3956 if (port_id == max_ports_per_engine)
3964 "VF[%d] - pbf polling failed on VOQ %d [port_id %d, tc_id %d]\n",
3965 p_vf->abs_vf_id, voq, port_id, tc_id);
3966 return ECORE_TIMEOUT;
3969 return ECORE_SUCCESS;
3972 static enum _ecore_status_t ecore_iov_vf_flr_poll(struct ecore_hwfn *p_hwfn,
3973 struct ecore_vf_info *p_vf,
3974 struct ecore_ptt *p_ptt)
3976 enum _ecore_status_t rc;
3978 /* TODO - add SRC and TM polling once we add storage IOV */
3980 rc = ecore_iov_vf_flr_poll_dorq(p_hwfn, p_vf, p_ptt);
3984 rc = ecore_iov_vf_flr_poll_pbf(p_hwfn, p_vf, p_ptt);
3988 return ECORE_SUCCESS;
3991 static enum _ecore_status_t
3992 ecore_iov_execute_vf_flr_cleanup(struct ecore_hwfn *p_hwfn,
3993 struct ecore_ptt *p_ptt,
3994 u16 rel_vf_id, u32 *ack_vfs)
3996 struct ecore_vf_info *p_vf;
3997 enum _ecore_status_t rc = ECORE_SUCCESS;
3999 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, false);
4001 return ECORE_SUCCESS;
4003 if (p_hwfn->pf_iov_info->pending_flr[rel_vf_id / 64] &
4004 (1ULL << (rel_vf_id % 64))) {
4005 u16 vfid = p_vf->abs_vf_id;
4007 /* TODO - should we lock channel? */
4009 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
4010 "VF[%d] - Handling FLR\n", vfid);
4012 ecore_iov_vf_cleanup(p_hwfn, p_vf);
4014 /* If VF isn't active, no need for anything but SW */
4018 /* TODO - what to do in case of failure? */
4019 rc = ecore_iov_vf_flr_poll(p_hwfn, p_vf, p_ptt);
4020 if (rc != ECORE_SUCCESS)
4023 rc = ecore_final_cleanup(p_hwfn, p_ptt, vfid, true);
4025 /* TODO - what's now? What a mess.... */
4026 DP_ERR(p_hwfn, "Failed handle FLR of VF[%d]\n", vfid);
4030 /* Workaround to make VF-PF channel ready, as FW
4031 * doesn't do that as a part of FLR.
4034 GTT_BAR0_MAP_REG_USDM_RAM +
4035 USTORM_VF_PF_CHANNEL_READY_OFFSET(vfid), 1);
4037 /* VF_STOPPED has to be set only after final cleanup
4038 * but prior to re-enabling the VF.
4040 p_vf->state = VF_STOPPED;
4042 rc = ecore_iov_enable_vf_access(p_hwfn, p_ptt, p_vf);
4044 /* TODO - again, a mess... */
4045 DP_ERR(p_hwfn, "Failed to re-enable VF[%d] acces\n",
4050 /* Mark VF for ack and clean pending state */
4051 if (p_vf->state == VF_RESET)
4052 p_vf->state = VF_STOPPED;
4053 ack_vfs[vfid / 32] |= (1 << (vfid % 32));
4054 p_hwfn->pf_iov_info->pending_flr[rel_vf_id / 64] &=
4055 ~(1ULL << (rel_vf_id % 64));
4056 p_vf->vf_mbx.b_pending_msg = false;
4062 enum _ecore_status_t ecore_iov_vf_flr_cleanup(struct ecore_hwfn *p_hwfn,
4063 struct ecore_ptt *p_ptt)
4065 u32 ack_vfs[EXT_VF_BITMAP_SIZE_IN_DWORDS];
4066 enum _ecore_status_t rc = ECORE_SUCCESS;
4069 OSAL_MEM_ZERO(ack_vfs, EXT_VF_BITMAP_SIZE_IN_BYTES);
4071 /* Since BRB <-> PRS interface can't be tested as part of the flr
4072 * polling due to HW limitations, simply sleep a bit. And since
4073 * there's no need to wait per-vf, do it before looping.
4077 for (i = 0; i < p_hwfn->p_dev->p_iov_info->total_vfs; i++)
4078 ecore_iov_execute_vf_flr_cleanup(p_hwfn, p_ptt, i, ack_vfs);
4080 rc = ecore_mcp_ack_vf_flr(p_hwfn, p_ptt, ack_vfs);
4084 enum _ecore_status_t
4085 ecore_iov_single_vf_flr_cleanup(struct ecore_hwfn *p_hwfn,
4086 struct ecore_ptt *p_ptt, u16 rel_vf_id)
4088 u32 ack_vfs[EXT_VF_BITMAP_SIZE_IN_DWORDS];
4089 enum _ecore_status_t rc = ECORE_SUCCESS;
4091 OSAL_MEM_ZERO(ack_vfs, EXT_VF_BITMAP_SIZE_IN_BYTES);
4093 /* Wait instead of polling the BRB <-> PRS interface */
4096 ecore_iov_execute_vf_flr_cleanup(p_hwfn, p_ptt, rel_vf_id, ack_vfs);
4098 rc = ecore_mcp_ack_vf_flr(p_hwfn, p_ptt, ack_vfs);
4102 bool ecore_iov_mark_vf_flr(struct ecore_hwfn *p_hwfn, u32 *p_disabled_vfs)
4107 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV, "Marking FLR-ed VFs\n");
4109 for (i = 0; i < VF_BITMAP_SIZE_IN_DWORDS; i++)
4110 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
4111 "[%08x,...,%08x]: %08x\n",
4112 i * 32, (i + 1) * 32 - 1, p_disabled_vfs[i]);
4114 if (!p_hwfn->p_dev->p_iov_info) {
4115 DP_NOTICE(p_hwfn, true, "VF flr but no IOV\n");
4120 for (i = 0; i < p_hwfn->p_dev->p_iov_info->total_vfs; i++) {
4121 struct ecore_vf_info *p_vf;
4124 p_vf = ecore_iov_get_vf_info(p_hwfn, i, false);
4128 vfid = p_vf->abs_vf_id;
4129 if ((1 << (vfid % 32)) & p_disabled_vfs[vfid / 32]) {
4130 u64 *p_flr = p_hwfn->pf_iov_info->pending_flr;
4131 u16 rel_vf_id = p_vf->relative_vf_id;
4133 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
4134 "VF[%d] [rel %d] got FLR-ed\n",
4137 p_vf->state = VF_RESET;
4139 /* No need to lock here, since pending_flr should
4140 * only change here and before ACKing MFw. Since
4141 * MFW will not trigger an additional attention for
4142 * VF flr until ACKs, we're safe.
4144 p_flr[rel_vf_id / 64] |= 1ULL << (rel_vf_id % 64);
4152 void ecore_iov_get_link(struct ecore_hwfn *p_hwfn,
4154 struct ecore_mcp_link_params *p_params,
4155 struct ecore_mcp_link_state *p_link,
4156 struct ecore_mcp_link_capabilities *p_caps)
4158 struct ecore_vf_info *p_vf = ecore_iov_get_vf_info(p_hwfn, vfid, false);
4159 struct ecore_bulletin_content *p_bulletin;
4164 p_bulletin = p_vf->bulletin.p_virt;
4167 __ecore_vf_get_link_params(p_params, p_bulletin);
4169 __ecore_vf_get_link_state(p_link, p_bulletin);
4171 __ecore_vf_get_link_caps(p_caps, p_bulletin);
4174 void ecore_iov_process_mbx_req(struct ecore_hwfn *p_hwfn,
4175 struct ecore_ptt *p_ptt, int vfid)
4177 struct ecore_iov_vf_mbx *mbx;
4178 struct ecore_vf_info *p_vf;
4180 p_vf = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4184 mbx = &p_vf->vf_mbx;
4186 /* ecore_iov_process_mbx_request */
4187 #ifndef CONFIG_ECORE_SW_CHANNEL
4188 if (!mbx->b_pending_msg) {
4189 DP_NOTICE(p_hwfn, true,
4190 "VF[%02x]: Trying to process mailbox message when none is pending\n",
4194 mbx->b_pending_msg = false;
4197 mbx->first_tlv = mbx->req_virt->first_tlv;
4199 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
4200 "VF[%02x]: Processing mailbox message [type %04x]\n",
4201 p_vf->abs_vf_id, mbx->first_tlv.tl.type);
4203 OSAL_IOV_VF_MSG_TYPE(p_hwfn,
4204 p_vf->relative_vf_id,
4205 mbx->first_tlv.tl.type);
4207 /* Lock the per vf op mutex and note the locker's identity.
4208 * The unlock will take place in mbx response.
4210 ecore_iov_lock_vf_pf_channel(p_hwfn,
4211 p_vf, mbx->first_tlv.tl.type);
4213 /* check if tlv type is known */
4214 if (ecore_iov_tlv_supported(mbx->first_tlv.tl.type) &&
4215 !p_vf->b_malicious) {
4216 /* switch on the opcode */
4217 switch (mbx->first_tlv.tl.type) {
4218 case CHANNEL_TLV_ACQUIRE:
4219 ecore_iov_vf_mbx_acquire(p_hwfn, p_ptt, p_vf);
4221 case CHANNEL_TLV_VPORT_START:
4222 ecore_iov_vf_mbx_start_vport(p_hwfn, p_ptt, p_vf);
4224 case CHANNEL_TLV_VPORT_TEARDOWN:
4225 ecore_iov_vf_mbx_stop_vport(p_hwfn, p_ptt, p_vf);
4227 case CHANNEL_TLV_START_RXQ:
4228 ecore_iov_vf_mbx_start_rxq(p_hwfn, p_ptt, p_vf);
4230 case CHANNEL_TLV_START_TXQ:
4231 ecore_iov_vf_mbx_start_txq(p_hwfn, p_ptt, p_vf);
4233 case CHANNEL_TLV_STOP_RXQS:
4234 ecore_iov_vf_mbx_stop_rxqs(p_hwfn, p_ptt, p_vf);
4236 case CHANNEL_TLV_STOP_TXQS:
4237 ecore_iov_vf_mbx_stop_txqs(p_hwfn, p_ptt, p_vf);
4239 case CHANNEL_TLV_UPDATE_RXQ:
4240 ecore_iov_vf_mbx_update_rxqs(p_hwfn, p_ptt, p_vf);
4242 case CHANNEL_TLV_VPORT_UPDATE:
4243 ecore_iov_vf_mbx_vport_update(p_hwfn, p_ptt, p_vf);
4245 case CHANNEL_TLV_UCAST_FILTER:
4246 ecore_iov_vf_mbx_ucast_filter(p_hwfn, p_ptt, p_vf);
4248 case CHANNEL_TLV_CLOSE:
4249 ecore_iov_vf_mbx_close(p_hwfn, p_ptt, p_vf);
4251 case CHANNEL_TLV_INT_CLEANUP:
4252 ecore_iov_vf_mbx_int_cleanup(p_hwfn, p_ptt, p_vf);
4254 case CHANNEL_TLV_RELEASE:
4255 ecore_iov_vf_mbx_release(p_hwfn, p_ptt, p_vf);
4257 case CHANNEL_TLV_UPDATE_TUNN_PARAM:
4258 ecore_iov_vf_mbx_update_tunn_param(p_hwfn, p_ptt, p_vf);
4260 case CHANNEL_TLV_COALESCE_UPDATE:
4261 ecore_iov_vf_pf_set_coalesce(p_hwfn, p_ptt, p_vf);
4263 case CHANNEL_TLV_COALESCE_READ:
4264 ecore_iov_vf_pf_get_coalesce(p_hwfn, p_ptt, p_vf);
4266 case CHANNEL_TLV_UPDATE_MTU:
4267 ecore_iov_vf_pf_update_mtu(p_hwfn, p_ptt, p_vf);
4270 } else if (ecore_iov_tlv_supported(mbx->first_tlv.tl.type)) {
4271 /* If we've received a message from a VF we consider malicious
4272 * we ignore the messasge unless it's one for RELEASE, in which
4273 * case we'll let it have the benefit of doubt, allowing the
4274 * next loaded driver to start again.
4276 if (mbx->first_tlv.tl.type == CHANNEL_TLV_RELEASE) {
4277 /* TODO - initiate FLR, remove malicious indication */
4278 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
4279 "VF [%02x] - considered malicious, but wanted to RELEASE. TODO\n",
4282 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
4283 "VF [%02x] - considered malicious; Ignoring TLV [%04x]\n",
4284 p_vf->abs_vf_id, mbx->first_tlv.tl.type);
4287 ecore_iov_prepare_resp(p_hwfn, p_ptt, p_vf,
4288 mbx->first_tlv.tl.type,
4289 sizeof(struct pfvf_def_resp_tlv),
4290 PFVF_STATUS_MALICIOUS);
4292 /* unknown TLV - this may belong to a VF driver from the future
4293 * - a version written after this PF driver was written, which
4294 * supports features unknown as of yet. Too bad since we don't
4295 * support them. Or this may be because someone wrote a crappy
4296 * VF driver and is sending garbage over the channel.
4298 DP_NOTICE(p_hwfn, false,
4299 "VF[%02x]: unknown TLV. type %04x length %04x"
4300 " padding %08x reply address %lu\n",
4302 mbx->first_tlv.tl.type,
4303 mbx->first_tlv.tl.length,
4304 mbx->first_tlv.padding,
4305 (unsigned long)mbx->first_tlv.reply_address);
4307 /* Try replying in case reply address matches the acquisition's
4310 if (p_vf->acquire.first_tlv.reply_address &&
4311 (mbx->first_tlv.reply_address ==
4312 p_vf->acquire.first_tlv.reply_address))
4313 ecore_iov_prepare_resp(p_hwfn, p_ptt, p_vf,
4314 mbx->first_tlv.tl.type,
4315 sizeof(struct pfvf_def_resp_tlv),
4316 PFVF_STATUS_NOT_SUPPORTED);
4318 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
4319 "VF[%02x]: Can't respond to TLV -"
4320 " no valid reply address\n",
4324 ecore_iov_unlock_vf_pf_channel(p_hwfn, p_vf,
4325 mbx->first_tlv.tl.type);
4327 #ifdef CONFIG_ECORE_SW_CHANNEL
4328 mbx->sw_mbx.mbx_state = VF_PF_RESPONSE_READY;
4329 mbx->sw_mbx.response_offset = 0;
4333 void ecore_iov_pf_get_pending_events(struct ecore_hwfn *p_hwfn,
4338 OSAL_MEM_ZERO(events, sizeof(u64) * ECORE_VF_ARRAY_LENGTH);
4340 ecore_for_each_vf(p_hwfn, i) {
4341 struct ecore_vf_info *p_vf;
4343 p_vf = &p_hwfn->pf_iov_info->vfs_array[i];
4344 if (p_vf->vf_mbx.b_pending_msg)
4345 events[i / 64] |= 1ULL << (i % 64);
4349 static struct ecore_vf_info *
4350 ecore_sriov_get_vf_from_absid(struct ecore_hwfn *p_hwfn, u16 abs_vfid)
4352 u8 min = (u8)p_hwfn->p_dev->p_iov_info->first_vf_in_pf;
4354 if (!_ecore_iov_pf_sanity_check(p_hwfn, (int)abs_vfid - min, false)) {
4355 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
4356 "Got indication for VF [abs 0x%08x] that cannot be"
4362 return &p_hwfn->pf_iov_info->vfs_array[(u8)abs_vfid - min];
4365 static enum _ecore_status_t ecore_sriov_vfpf_msg(struct ecore_hwfn *p_hwfn,
4367 struct regpair *vf_msg)
4369 struct ecore_vf_info *p_vf = ecore_sriov_get_vf_from_absid(p_hwfn,
4373 return ECORE_SUCCESS;
4375 /* List the physical address of the request so that handler
4376 * could later on copy the message from it.
4378 p_vf->vf_mbx.pending_req = (((u64)vf_msg->hi) << 32) | vf_msg->lo;
4380 p_vf->vf_mbx.b_pending_msg = true;
4382 return OSAL_PF_VF_MSG(p_hwfn, p_vf->relative_vf_id);
4385 static void ecore_sriov_vfpf_malicious(struct ecore_hwfn *p_hwfn,
4386 struct malicious_vf_eqe_data *p_data)
4388 struct ecore_vf_info *p_vf;
4390 p_vf = ecore_sriov_get_vf_from_absid(p_hwfn, p_data->vf_id);
4395 if (!p_vf->b_malicious) {
4396 DP_NOTICE(p_hwfn, false,
4397 "VF [%d] - Malicious behavior [%02x]\n",
4398 p_vf->abs_vf_id, p_data->err_id);
4400 p_vf->b_malicious = true;
4403 "VF [%d] - Malicious behavior [%02x]\n",
4404 p_vf->abs_vf_id, p_data->err_id);
4407 OSAL_PF_VF_MALICIOUS(p_hwfn, p_vf->relative_vf_id);
4410 static enum _ecore_status_t ecore_sriov_eqe_event(struct ecore_hwfn *p_hwfn,
4413 union event_ring_data *data,
4414 u8 OSAL_UNUSED fw_return_code)
4417 case COMMON_EVENT_VF_PF_CHANNEL:
4418 return ecore_sriov_vfpf_msg(p_hwfn, OSAL_LE16_TO_CPU(echo),
4419 &data->vf_pf_channel.msg_addr);
4420 case COMMON_EVENT_VF_FLR:
4421 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
4422 "VF-FLR is still not supported\n");
4423 return ECORE_SUCCESS;
4424 case COMMON_EVENT_MALICIOUS_VF:
4425 ecore_sriov_vfpf_malicious(p_hwfn, &data->malicious_vf);
4426 return ECORE_SUCCESS;
4428 DP_INFO(p_hwfn->p_dev, "Unknown sriov eqe event 0x%02x\n",
4434 bool ecore_iov_is_vf_pending_flr(struct ecore_hwfn *p_hwfn, u16 rel_vf_id)
4436 return !!(p_hwfn->pf_iov_info->pending_flr[rel_vf_id / 64] &
4437 (1ULL << (rel_vf_id % 64)));
4440 u16 ecore_iov_get_next_active_vf(struct ecore_hwfn *p_hwfn, u16 rel_vf_id)
4442 struct ecore_hw_sriov_info *p_iov = p_hwfn->p_dev->p_iov_info;
4448 for (i = rel_vf_id; i < p_iov->total_vfs; i++)
4449 if (ecore_iov_is_valid_vfid(p_hwfn, rel_vf_id, true, false))
4453 return MAX_NUM_VFS_K2;
4456 enum _ecore_status_t ecore_iov_copy_vf_msg(struct ecore_hwfn *p_hwfn,
4457 struct ecore_ptt *ptt, int vfid)
4459 struct dmae_params params;
4460 struct ecore_vf_info *vf_info;
4462 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4466 OSAL_MEMSET(¶ms, 0, sizeof(params));
4467 SET_FIELD(params.flags, DMAE_PARAMS_SRC_VF_VALID, 0x1);
4468 SET_FIELD(params.flags, DMAE_PARAMS_COMPLETION_DST, 0x1);
4469 params.src_vf_id = vf_info->abs_vf_id;
4471 if (ecore_dmae_host2host(p_hwfn, ptt,
4472 vf_info->vf_mbx.pending_req,
4473 vf_info->vf_mbx.req_phys,
4474 sizeof(union vfpf_tlvs) / 4, ¶ms)) {
4475 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
4476 "Failed to copy message from VF 0x%02x\n", vfid);
4481 return ECORE_SUCCESS;
4484 void ecore_iov_bulletin_set_forced_mac(struct ecore_hwfn *p_hwfn,
4487 struct ecore_vf_info *vf_info;
4490 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4492 DP_NOTICE(p_hwfn->p_dev, true,
4493 "Can not set forced MAC, invalid vfid [%d]\n", vfid);
4496 if (vf_info->b_malicious) {
4497 DP_NOTICE(p_hwfn->p_dev, false,
4498 "Can't set forced MAC to malicious VF [%d]\n",
4503 if (p_hwfn->pf_params.eth_pf_params.allow_vf_mac_change ||
4504 vf_info->p_vf_info.is_trusted_configured) {
4505 feature = 1 << VFPF_BULLETIN_MAC_ADDR;
4506 /* Trust mode will disable Forced MAC */
4507 vf_info->bulletin.p_virt->valid_bitmap &=
4508 ~(1 << MAC_ADDR_FORCED);
4510 feature = 1 << MAC_ADDR_FORCED;
4511 /* Forced MAC will disable MAC_ADDR */
4512 vf_info->bulletin.p_virt->valid_bitmap &=
4513 ~(1 << VFPF_BULLETIN_MAC_ADDR);
4516 OSAL_MEMCPY(vf_info->bulletin.p_virt->mac,
4519 vf_info->bulletin.p_virt->valid_bitmap |= feature;
4521 ecore_iov_configure_vport_forced(p_hwfn, vf_info, feature);
4524 enum _ecore_status_t ecore_iov_bulletin_set_mac(struct ecore_hwfn *p_hwfn,
4527 struct ecore_vf_info *vf_info;
4530 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4532 DP_NOTICE(p_hwfn->p_dev, true,
4533 "Can not set MAC, invalid vfid [%d]\n", vfid);
4536 if (vf_info->b_malicious) {
4537 DP_NOTICE(p_hwfn->p_dev, false,
4538 "Can't set MAC to malicious VF [%d]\n",
4543 if (vf_info->bulletin.p_virt->valid_bitmap & (1 << MAC_ADDR_FORCED)) {
4544 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
4545 "Can not set MAC, Forced MAC is configured\n");
4549 feature = 1 << VFPF_BULLETIN_MAC_ADDR;
4550 OSAL_MEMCPY(vf_info->bulletin.p_virt->mac, mac, ETH_ALEN);
4552 vf_info->bulletin.p_virt->valid_bitmap |= feature;
4554 if (p_hwfn->pf_params.eth_pf_params.allow_vf_mac_change ||
4555 vf_info->p_vf_info.is_trusted_configured)
4556 ecore_iov_configure_vport_forced(p_hwfn, vf_info, feature);
4558 return ECORE_SUCCESS;
4561 #ifndef LINUX_REMOVE
4562 enum _ecore_status_t
4563 ecore_iov_bulletin_set_forced_untagged_default(struct ecore_hwfn *p_hwfn,
4564 bool b_untagged_only, int vfid)
4566 struct ecore_vf_info *vf_info;
4569 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4571 DP_NOTICE(p_hwfn->p_dev, true,
4572 "Can not set untagged default, invalid vfid [%d]\n",
4576 if (vf_info->b_malicious) {
4577 DP_NOTICE(p_hwfn->p_dev, false,
4578 "Can't set untagged default to malicious VF [%d]\n",
4583 /* Since this is configurable only during vport-start, don't take it
4584 * if we're past that point.
4586 if (vf_info->state == VF_ENABLED) {
4587 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
4588 "Can't support untagged change for vfid[%d] -"
4589 " VF is already active\n",
4594 /* Set configuration; This will later be taken into account during the
4595 * VF initialization.
4597 feature = (1 << VFPF_BULLETIN_UNTAGGED_DEFAULT) |
4598 (1 << VFPF_BULLETIN_UNTAGGED_DEFAULT_FORCED);
4599 vf_info->bulletin.p_virt->valid_bitmap |= feature;
4601 vf_info->bulletin.p_virt->default_only_untagged = b_untagged_only ? 1
4604 return ECORE_SUCCESS;
4607 void ecore_iov_get_vfs_opaque_fid(struct ecore_hwfn *p_hwfn, int vfid,
4610 struct ecore_vf_info *vf_info;
4612 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4616 *opaque_fid = vf_info->opaque_fid;
4620 void ecore_iov_bulletin_set_forced_vlan(struct ecore_hwfn *p_hwfn,
4623 struct ecore_vf_info *vf_info;
4626 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4628 DP_NOTICE(p_hwfn->p_dev, true,
4629 "Can not set forced MAC, invalid vfid [%d]\n",
4633 if (vf_info->b_malicious) {
4634 DP_NOTICE(p_hwfn->p_dev, false,
4635 "Can't set forced vlan to malicious VF [%d]\n",
4640 feature = 1 << VLAN_ADDR_FORCED;
4641 vf_info->bulletin.p_virt->pvid = pvid;
4643 vf_info->bulletin.p_virt->valid_bitmap |= feature;
4645 vf_info->bulletin.p_virt->valid_bitmap &= ~feature;
4647 ecore_iov_configure_vport_forced(p_hwfn, vf_info, feature);
4650 void ecore_iov_bulletin_set_udp_ports(struct ecore_hwfn *p_hwfn,
4651 int vfid, u16 vxlan_port, u16 geneve_port)
4653 struct ecore_vf_info *vf_info;
4655 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4657 DP_NOTICE(p_hwfn->p_dev, true,
4658 "Can not set udp ports, invalid vfid [%d]\n", vfid);
4662 if (vf_info->b_malicious) {
4663 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
4664 "Can not set udp ports to malicious VF [%d]\n",
4669 vf_info->bulletin.p_virt->vxlan_udp_port = vxlan_port;
4670 vf_info->bulletin.p_virt->geneve_udp_port = geneve_port;
4673 bool ecore_iov_vf_has_vport_instance(struct ecore_hwfn *p_hwfn, int vfid)
4675 struct ecore_vf_info *p_vf_info;
4677 p_vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4681 return !!p_vf_info->vport_instance;
4684 bool ecore_iov_is_vf_stopped(struct ecore_hwfn *p_hwfn, int vfid)
4686 struct ecore_vf_info *p_vf_info;
4688 p_vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4692 return p_vf_info->state == VF_STOPPED;
4695 bool ecore_iov_spoofchk_get(struct ecore_hwfn *p_hwfn, int vfid)
4697 struct ecore_vf_info *vf_info;
4699 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4703 return vf_info->spoof_chk;
4706 enum _ecore_status_t ecore_iov_spoofchk_set(struct ecore_hwfn *p_hwfn,
4709 struct ecore_vf_info *vf;
4710 enum _ecore_status_t rc = ECORE_INVAL;
4712 if (!ecore_iov_pf_sanity_check(p_hwfn, vfid)) {
4713 DP_NOTICE(p_hwfn, true,
4714 "SR-IOV sanity check failed, can't set spoofchk\n");
4718 vf = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4722 if (!ecore_iov_vf_has_vport_instance(p_hwfn, vfid)) {
4723 /* After VF VPORT start PF will configure spoof check */
4724 vf->req_spoofchk_val = val;
4729 rc = __ecore_iov_spoofchk_set(p_hwfn, vf, val);
4735 u8 ecore_iov_vf_chains_per_pf(struct ecore_hwfn *p_hwfn)
4737 u8 max_chains_per_vf = p_hwfn->hw_info.max_chains_per_vf;
4739 max_chains_per_vf = (max_chains_per_vf) ? max_chains_per_vf
4740 : ECORE_MAX_VF_CHAINS_PER_PF;
4742 return max_chains_per_vf;
4745 void ecore_iov_get_vf_req_virt_mbx_params(struct ecore_hwfn *p_hwfn,
4747 void **pp_req_virt_addr,
4748 u16 *p_req_virt_size)
4750 struct ecore_vf_info *vf_info =
4751 ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4756 if (pp_req_virt_addr)
4757 *pp_req_virt_addr = vf_info->vf_mbx.req_virt;
4759 if (p_req_virt_size)
4760 *p_req_virt_size = sizeof(*vf_info->vf_mbx.req_virt);
4763 void ecore_iov_get_vf_reply_virt_mbx_params(struct ecore_hwfn *p_hwfn,
4765 void **pp_reply_virt_addr,
4766 u16 *p_reply_virt_size)
4768 struct ecore_vf_info *vf_info =
4769 ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4774 if (pp_reply_virt_addr)
4775 *pp_reply_virt_addr = vf_info->vf_mbx.reply_virt;
4777 if (p_reply_virt_size)
4778 *p_reply_virt_size = sizeof(*vf_info->vf_mbx.reply_virt);
4781 #ifdef CONFIG_ECORE_SW_CHANNEL
4782 struct ecore_iov_sw_mbx *ecore_iov_get_vf_sw_mbx(struct ecore_hwfn *p_hwfn,
4785 struct ecore_vf_info *vf_info =
4786 ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4791 return &vf_info->vf_mbx.sw_mbx;
4795 bool ecore_iov_is_valid_vfpf_msg_length(u32 length)
4797 return (length >= sizeof(struct vfpf_first_tlv) &&
4798 (length <= sizeof(union vfpf_tlvs)));
4801 u32 ecore_iov_pfvf_msg_length(void)
4803 return sizeof(union pfvf_tlvs);
4806 u8 *ecore_iov_bulletin_get_mac(struct ecore_hwfn *p_hwfn,
4809 struct ecore_vf_info *p_vf;
4811 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4812 if (!p_vf || !p_vf->bulletin.p_virt)
4815 if (!(p_vf->bulletin.p_virt->valid_bitmap &
4816 (1 << VFPF_BULLETIN_MAC_ADDR)))
4819 return p_vf->bulletin.p_virt->mac;
4822 u8 *ecore_iov_bulletin_get_forced_mac(struct ecore_hwfn *p_hwfn, u16 rel_vf_id)
4824 struct ecore_vf_info *p_vf;
4826 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4827 if (!p_vf || !p_vf->bulletin.p_virt)
4830 if (!(p_vf->bulletin.p_virt->valid_bitmap & (1 << MAC_ADDR_FORCED)))
4833 return p_vf->bulletin.p_virt->mac;
4836 u16 ecore_iov_bulletin_get_forced_vlan(struct ecore_hwfn *p_hwfn,
4839 struct ecore_vf_info *p_vf;
4841 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4842 if (!p_vf || !p_vf->bulletin.p_virt)
4845 if (!(p_vf->bulletin.p_virt->valid_bitmap & (1 << VLAN_ADDR_FORCED)))
4848 return p_vf->bulletin.p_virt->pvid;
4851 enum _ecore_status_t ecore_iov_configure_tx_rate(struct ecore_hwfn *p_hwfn,
4852 struct ecore_ptt *p_ptt,
4855 struct ecore_vf_info *vf;
4858 enum _ecore_status_t rc;
4860 vf = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4865 rc = ecore_fw_vport(p_hwfn, vf->vport_id, &abs_vp_id);
4866 if (rc != ECORE_SUCCESS)
4869 rl_id = abs_vp_id; /* The "rl_id" is set as the "vport_id" */
4870 return ecore_init_global_rl(p_hwfn, p_ptt, rl_id, (u32)val);
4873 enum _ecore_status_t ecore_iov_configure_min_tx_rate(struct ecore_dev *p_dev,
4876 struct ecore_vf_info *vf;
4879 for_each_hwfn(p_dev, i) {
4880 struct ecore_hwfn *p_hwfn = &p_dev->hwfns[i];
4882 if (!ecore_iov_pf_sanity_check(p_hwfn, vfid)) {
4883 DP_NOTICE(p_hwfn, true,
4884 "SR-IOV sanity check failed, can't set min rate\n");
4889 vf = ecore_iov_get_vf_info(ECORE_LEADING_HWFN(p_dev), (u16)vfid, true);
4891 DP_NOTICE(p_dev, true,
4892 "Getting vf info failed, can't set min rate\n");
4896 return ecore_configure_vport_wfq(p_dev, vf->vport_id, rate);
4899 enum _ecore_status_t ecore_iov_get_vf_stats(struct ecore_hwfn *p_hwfn,
4900 struct ecore_ptt *p_ptt,
4902 struct ecore_eth_stats *p_stats)
4904 struct ecore_vf_info *vf;
4906 vf = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4910 if (vf->state != VF_ENABLED)
4913 __ecore_get_vport_stats(p_hwfn, p_ptt, p_stats,
4914 vf->abs_vf_id + 0x10, false);
4916 return ECORE_SUCCESS;
4919 u8 ecore_iov_get_vf_num_rxqs(struct ecore_hwfn *p_hwfn, u16 rel_vf_id)
4921 struct ecore_vf_info *p_vf;
4923 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4927 return p_vf->num_rxqs;
4930 u8 ecore_iov_get_vf_num_active_rxqs(struct ecore_hwfn *p_hwfn, u16 rel_vf_id)
4932 struct ecore_vf_info *p_vf;
4934 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4938 return p_vf->num_active_rxqs;
4941 void *ecore_iov_get_vf_ctx(struct ecore_hwfn *p_hwfn, u16 rel_vf_id)
4943 struct ecore_vf_info *p_vf;
4945 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4952 u8 ecore_iov_get_vf_num_sbs(struct ecore_hwfn *p_hwfn, u16 rel_vf_id)
4954 struct ecore_vf_info *p_vf;
4956 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4960 return p_vf->num_sbs;
4963 bool ecore_iov_is_vf_wait_for_acquire(struct ecore_hwfn *p_hwfn, u16 rel_vf_id)
4965 struct ecore_vf_info *p_vf;
4967 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4971 return (p_vf->state == VF_FREE);
4974 bool ecore_iov_is_vf_acquired_not_initialized(struct ecore_hwfn *p_hwfn,
4977 struct ecore_vf_info *p_vf;
4979 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4983 return (p_vf->state == VF_ACQUIRED);
4986 bool ecore_iov_is_vf_initialized(struct ecore_hwfn *p_hwfn, u16 rel_vf_id)
4988 struct ecore_vf_info *p_vf;
4990 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4994 return (p_vf->state == VF_ENABLED);
4997 bool ecore_iov_is_vf_started(struct ecore_hwfn *p_hwfn,
5000 struct ecore_vf_info *p_vf;
5002 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
5006 return (p_vf->state != VF_FREE && p_vf->state != VF_STOPPED);
5010 ecore_iov_get_vf_min_rate(struct ecore_hwfn *p_hwfn, int vfid)
5012 struct ecore_wfq_data *vf_vp_wfq;
5013 struct ecore_vf_info *vf_info;
5015 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
5019 vf_vp_wfq = &p_hwfn->qm_info.wfq_data[vf_info->vport_id];
5021 if (vf_vp_wfq->configured)
5022 return vf_vp_wfq->min_speed;
5027 #ifdef CONFIG_ECORE_SW_CHANNEL
5028 void ecore_iov_set_vf_hw_channel(struct ecore_hwfn *p_hwfn, int vfid,
5031 struct ecore_vf_info *vf_info;
5033 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
5037 vf_info->b_hw_channel = b_is_hw;