2 * Copyright (c) 2016 QLogic Corporation.
6 * See LICENSE.qede_pmd for copyright and licensing details.
12 #include "ecore_sriov.h"
13 #include "ecore_status.h"
15 #include "ecore_hw_defs.h"
16 #include "ecore_int.h"
17 #include "ecore_hsi_eth.h"
19 #include "ecore_vfpf_if.h"
20 #include "ecore_rt_defs.h"
21 #include "ecore_init_ops.h"
22 #include "ecore_gtt_reg_addr.h"
23 #include "ecore_iro.h"
24 #include "ecore_mcp.h"
25 #include "ecore_cxt.h"
27 #include "ecore_init_fw_funcs.h"
28 #include "ecore_sp_commands.h"
30 const char *ecore_channel_tlvs_string[] = {
31 "CHANNEL_TLV_NONE", /* ends tlv sequence */
32 "CHANNEL_TLV_ACQUIRE",
33 "CHANNEL_TLV_VPORT_START",
34 "CHANNEL_TLV_VPORT_UPDATE",
35 "CHANNEL_TLV_VPORT_TEARDOWN",
36 "CHANNEL_TLV_START_RXQ",
37 "CHANNEL_TLV_START_TXQ",
38 "CHANNEL_TLV_STOP_RXQ",
39 "CHANNEL_TLV_STOP_TXQ",
40 "CHANNEL_TLV_UPDATE_RXQ",
41 "CHANNEL_TLV_INT_CLEANUP",
43 "CHANNEL_TLV_RELEASE",
44 "CHANNEL_TLV_LIST_END",
45 "CHANNEL_TLV_UCAST_FILTER",
46 "CHANNEL_TLV_VPORT_UPDATE_ACTIVATE",
47 "CHANNEL_TLV_VPORT_UPDATE_TX_SWITCH",
48 "CHANNEL_TLV_VPORT_UPDATE_VLAN_STRIP",
49 "CHANNEL_TLV_VPORT_UPDATE_MCAST",
50 "CHANNEL_TLV_VPORT_UPDATE_ACCEPT_PARAM",
51 "CHANNEL_TLV_VPORT_UPDATE_RSS",
52 "CHANNEL_TLV_VPORT_UPDATE_ACCEPT_ANY_VLAN",
53 "CHANNEL_TLV_VPORT_UPDATE_SGE_TPA",
54 "CHANNEL_TLV_UPDATE_TUNN_PARAM",
55 "CHANNEL_TLV_COALESCE_UPDATE",
60 static u8 ecore_vf_calculate_legacy(struct ecore_vf_info *p_vf)
64 if (p_vf->acquire.vfdev_info.eth_fp_hsi_minor ==
65 ETH_HSI_VER_NO_PKT_LEN_TUNN)
66 legacy |= ECORE_QCID_LEGACY_VF_RX_PROD;
68 if (!(p_vf->acquire.vfdev_info.capabilities &
69 VFPF_ACQUIRE_CAP_QUEUE_QIDS))
70 legacy |= ECORE_QCID_LEGACY_VF_CID;
76 static enum _ecore_status_t ecore_sp_vf_start(struct ecore_hwfn *p_hwfn,
77 struct ecore_vf_info *p_vf)
79 struct vf_start_ramrod_data *p_ramrod = OSAL_NULL;
80 struct ecore_spq_entry *p_ent = OSAL_NULL;
81 struct ecore_sp_init_data init_data;
82 enum _ecore_status_t rc = ECORE_NOTIMPL;
86 OSAL_MEMSET(&init_data, 0, sizeof(init_data));
87 init_data.cid = ecore_spq_get_cid(p_hwfn);
88 init_data.opaque_fid = p_vf->opaque_fid;
89 init_data.comp_mode = ECORE_SPQ_MODE_EBLOCK;
91 rc = ecore_sp_init_request(p_hwfn, &p_ent,
92 COMMON_RAMROD_VF_START,
93 PROTOCOLID_COMMON, &init_data);
94 if (rc != ECORE_SUCCESS)
97 p_ramrod = &p_ent->ramrod.vf_start;
99 p_ramrod->vf_id = GET_FIELD(p_vf->concrete_fid, PXP_CONCRETE_FID_VFID);
100 p_ramrod->opaque_fid = OSAL_CPU_TO_LE16(p_vf->opaque_fid);
102 switch (p_hwfn->hw_info.personality) {
104 p_ramrod->personality = PERSONALITY_ETH;
106 case ECORE_PCI_ETH_ROCE:
107 case ECORE_PCI_ETH_IWARP:
108 p_ramrod->personality = PERSONALITY_RDMA_AND_ETH;
111 DP_NOTICE(p_hwfn, true, "Unknown VF personality %d\n",
112 p_hwfn->hw_info.personality);
116 fp_minor = p_vf->acquire.vfdev_info.eth_fp_hsi_minor;
117 if (fp_minor > ETH_HSI_VER_MINOR &&
118 fp_minor != ETH_HSI_VER_NO_PKT_LEN_TUNN) {
119 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
120 "VF [%d] - Requested fp hsi %02x.%02x which is"
121 " slightly newer than PF's %02x.%02x; Configuring"
124 ETH_HSI_VER_MAJOR, fp_minor,
125 ETH_HSI_VER_MAJOR, ETH_HSI_VER_MINOR);
126 fp_minor = ETH_HSI_VER_MINOR;
129 p_ramrod->hsi_fp_ver.major_ver_arr[ETH_VER_KEY] = ETH_HSI_VER_MAJOR;
130 p_ramrod->hsi_fp_ver.minor_ver_arr[ETH_VER_KEY] = fp_minor;
132 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
133 "VF[%d] - Starting using HSI %02x.%02x\n",
134 p_vf->abs_vf_id, ETH_HSI_VER_MAJOR, fp_minor);
136 return ecore_spq_post(p_hwfn, p_ent, OSAL_NULL);
139 static enum _ecore_status_t ecore_sp_vf_stop(struct ecore_hwfn *p_hwfn,
143 struct vf_stop_ramrod_data *p_ramrod = OSAL_NULL;
144 struct ecore_spq_entry *p_ent = OSAL_NULL;
145 struct ecore_sp_init_data init_data;
146 enum _ecore_status_t rc = ECORE_NOTIMPL;
149 OSAL_MEMSET(&init_data, 0, sizeof(init_data));
150 init_data.cid = ecore_spq_get_cid(p_hwfn);
151 init_data.opaque_fid = opaque_vfid;
152 init_data.comp_mode = ECORE_SPQ_MODE_EBLOCK;
154 rc = ecore_sp_init_request(p_hwfn, &p_ent,
155 COMMON_RAMROD_VF_STOP,
156 PROTOCOLID_COMMON, &init_data);
157 if (rc != ECORE_SUCCESS)
160 p_ramrod = &p_ent->ramrod.vf_stop;
162 p_ramrod->vf_id = GET_FIELD(concrete_vfid, PXP_CONCRETE_FID_VFID);
164 return ecore_spq_post(p_hwfn, p_ent, OSAL_NULL);
167 bool ecore_iov_is_valid_vfid(struct ecore_hwfn *p_hwfn, int rel_vf_id,
168 bool b_enabled_only, bool b_non_malicious)
170 if (!p_hwfn->pf_iov_info) {
171 DP_NOTICE(p_hwfn->p_dev, true, "No iov info\n");
175 if ((rel_vf_id >= p_hwfn->p_dev->p_iov_info->total_vfs) ||
179 if ((!p_hwfn->pf_iov_info->vfs_array[rel_vf_id].b_init) &&
183 if ((p_hwfn->pf_iov_info->vfs_array[rel_vf_id].b_malicious) &&
190 struct ecore_vf_info *ecore_iov_get_vf_info(struct ecore_hwfn *p_hwfn,
194 struct ecore_vf_info *vf = OSAL_NULL;
196 if (!p_hwfn->pf_iov_info) {
197 DP_NOTICE(p_hwfn->p_dev, true, "No iov info\n");
201 if (ecore_iov_is_valid_vfid(p_hwfn, relative_vf_id,
202 b_enabled_only, false))
203 vf = &p_hwfn->pf_iov_info->vfs_array[relative_vf_id];
205 DP_ERR(p_hwfn, "ecore_iov_get_vf_info: VF[%d] is not enabled\n",
211 static struct ecore_queue_cid *
212 ecore_iov_get_vf_rx_queue_cid(struct ecore_vf_queue *p_queue)
216 for (i = 0; i < MAX_QUEUES_PER_QZONE; i++) {
217 if (p_queue->cids[i].p_cid &&
218 !p_queue->cids[i].b_is_tx)
219 return p_queue->cids[i].p_cid;
225 enum ecore_iov_validate_q_mode {
226 ECORE_IOV_VALIDATE_Q_NA,
227 ECORE_IOV_VALIDATE_Q_ENABLE,
228 ECORE_IOV_VALIDATE_Q_DISABLE,
231 static bool ecore_iov_validate_queue_mode(struct ecore_vf_info *p_vf,
233 enum ecore_iov_validate_q_mode mode,
238 if (mode == ECORE_IOV_VALIDATE_Q_NA)
241 for (i = 0; i < MAX_QUEUES_PER_QZONE; i++) {
242 struct ecore_vf_queue_cid *p_qcid;
244 p_qcid = &p_vf->vf_queues[qid].cids[i];
246 if (p_qcid->p_cid == OSAL_NULL)
249 if (p_qcid->b_is_tx != b_is_tx)
252 /* Found. It's enabled. */
253 return (mode == ECORE_IOV_VALIDATE_Q_ENABLE);
256 /* In case we haven't found any valid cid, then its disabled */
257 return (mode == ECORE_IOV_VALIDATE_Q_DISABLE);
260 static bool ecore_iov_validate_rxq(struct ecore_hwfn *p_hwfn,
261 struct ecore_vf_info *p_vf,
263 enum ecore_iov_validate_q_mode mode)
265 if (rx_qid >= p_vf->num_rxqs) {
266 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
267 "VF[0x%02x] - can't touch Rx queue[%04x];"
268 " Only 0x%04x are allocated\n",
269 p_vf->abs_vf_id, rx_qid, p_vf->num_rxqs);
273 return ecore_iov_validate_queue_mode(p_vf, rx_qid, mode, false);
276 static bool ecore_iov_validate_txq(struct ecore_hwfn *p_hwfn,
277 struct ecore_vf_info *p_vf,
279 enum ecore_iov_validate_q_mode mode)
281 if (tx_qid >= p_vf->num_txqs) {
282 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
283 "VF[0x%02x] - can't touch Tx queue[%04x];"
284 " Only 0x%04x are allocated\n",
285 p_vf->abs_vf_id, tx_qid, p_vf->num_txqs);
289 return ecore_iov_validate_queue_mode(p_vf, tx_qid, mode, true);
292 static bool ecore_iov_validate_sb(struct ecore_hwfn *p_hwfn,
293 struct ecore_vf_info *p_vf,
298 for (i = 0; i < p_vf->num_sbs; i++)
299 if (p_vf->igu_sbs[i] == sb_idx)
302 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
303 "VF[0%02x] - tried using sb_idx %04x which doesn't exist as"
304 " one of its 0x%02x SBs\n",
305 p_vf->abs_vf_id, sb_idx, p_vf->num_sbs);
310 /* Is there at least 1 queue open? */
311 static bool ecore_iov_validate_active_rxq(struct ecore_vf_info *p_vf)
315 for (i = 0; i < p_vf->num_rxqs; i++)
316 if (ecore_iov_validate_queue_mode(p_vf, i,
317 ECORE_IOV_VALIDATE_Q_ENABLE,
324 static bool ecore_iov_validate_active_txq(struct ecore_vf_info *p_vf)
328 for (i = 0; i < p_vf->num_txqs; i++)
329 if (ecore_iov_validate_queue_mode(p_vf, i,
330 ECORE_IOV_VALIDATE_Q_ENABLE,
337 enum _ecore_status_t ecore_iov_post_vf_bulletin(struct ecore_hwfn *p_hwfn,
339 struct ecore_ptt *p_ptt)
341 struct ecore_bulletin_content *p_bulletin;
342 int crc_size = sizeof(p_bulletin->crc);
343 struct ecore_dmae_params params;
344 struct ecore_vf_info *p_vf;
346 p_vf = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
350 /* TODO - check VF is in a state where it can accept message */
351 if (!p_vf->vf_bulletin)
354 p_bulletin = p_vf->bulletin.p_virt;
356 /* Increment bulletin board version and compute crc */
357 p_bulletin->version++;
358 p_bulletin->crc = OSAL_CRC32(0, (u8 *)p_bulletin + crc_size,
359 p_vf->bulletin.size - crc_size);
361 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
362 "Posting Bulletin 0x%08x to VF[%d] (CRC 0x%08x)\n",
363 p_bulletin->version, p_vf->relative_vf_id, p_bulletin->crc);
365 /* propagate bulletin board via dmae to vm memory */
366 OSAL_MEMSET(¶ms, 0, sizeof(params));
367 params.flags = ECORE_DMAE_FLAG_VF_DST;
368 params.dst_vfid = p_vf->abs_vf_id;
369 return ecore_dmae_host2host(p_hwfn, p_ptt, p_vf->bulletin.phys,
370 p_vf->vf_bulletin, p_vf->bulletin.size / 4,
374 static enum _ecore_status_t ecore_iov_pci_cfg_info(struct ecore_dev *p_dev)
376 struct ecore_hw_sriov_info *iov = p_dev->p_iov_info;
379 DP_VERBOSE(p_dev, ECORE_MSG_IOV, "sriov ext pos %d\n", pos);
380 OSAL_PCI_READ_CONFIG_WORD(p_dev, pos + PCI_SRIOV_CTRL, &iov->ctrl);
382 OSAL_PCI_READ_CONFIG_WORD(p_dev,
383 pos + PCI_SRIOV_TOTAL_VF, &iov->total_vfs);
384 OSAL_PCI_READ_CONFIG_WORD(p_dev,
385 pos + PCI_SRIOV_INITIAL_VF,
388 OSAL_PCI_READ_CONFIG_WORD(p_dev, pos + PCI_SRIOV_NUM_VF, &iov->num_vfs);
390 /* @@@TODO - in future we might want to add an OSAL here to
391 * allow each OS to decide on its own how to act.
393 DP_VERBOSE(p_dev, ECORE_MSG_IOV,
394 "Number of VFs are already set to non-zero value."
395 " Ignoring PCI configuration value\n");
399 OSAL_PCI_READ_CONFIG_WORD(p_dev,
400 pos + PCI_SRIOV_VF_OFFSET, &iov->offset);
402 OSAL_PCI_READ_CONFIG_WORD(p_dev,
403 pos + PCI_SRIOV_VF_STRIDE, &iov->stride);
405 OSAL_PCI_READ_CONFIG_WORD(p_dev,
406 pos + PCI_SRIOV_VF_DID, &iov->vf_device_id);
408 OSAL_PCI_READ_CONFIG_DWORD(p_dev,
409 pos + PCI_SRIOV_SUP_PGSIZE, &iov->pgsz);
411 OSAL_PCI_READ_CONFIG_DWORD(p_dev, pos + PCI_SRIOV_CAP, &iov->cap);
413 OSAL_PCI_READ_CONFIG_BYTE(p_dev, pos + PCI_SRIOV_FUNC_LINK, &iov->link);
415 DP_VERBOSE(p_dev, ECORE_MSG_IOV, "IOV info: nres %d, cap 0x%x,"
416 "ctrl 0x%x, total %d, initial %d, num vfs %d, offset %d,"
417 " stride %d, page size 0x%x\n",
418 iov->nres, iov->cap, iov->ctrl,
419 iov->total_vfs, iov->initial_vfs, iov->nr_virtfn,
420 iov->offset, iov->stride, iov->pgsz);
422 /* Some sanity checks */
423 if (iov->num_vfs > NUM_OF_VFS(p_dev) ||
424 iov->total_vfs > NUM_OF_VFS(p_dev)) {
425 /* This can happen only due to a bug. In this case we set
426 * num_vfs to zero to avoid memory corruption in the code that
427 * assumes max number of vfs
429 DP_NOTICE(p_dev, false,
430 "IOV: Unexpected number of vfs set: %d"
431 " setting num_vf to zero\n",
438 return ECORE_SUCCESS;
441 static void ecore_iov_setup_vfdb(struct ecore_hwfn *p_hwfn)
443 struct ecore_hw_sriov_info *p_iov = p_hwfn->p_dev->p_iov_info;
444 struct ecore_pf_iov *p_iov_info = p_hwfn->pf_iov_info;
445 struct ecore_bulletin_content *p_bulletin_virt;
446 dma_addr_t req_p, rply_p, bulletin_p;
447 union pfvf_tlvs *p_reply_virt_addr;
448 union vfpf_tlvs *p_req_virt_addr;
451 OSAL_MEMSET(p_iov_info->vfs_array, 0, sizeof(p_iov_info->vfs_array));
453 p_req_virt_addr = p_iov_info->mbx_msg_virt_addr;
454 req_p = p_iov_info->mbx_msg_phys_addr;
455 p_reply_virt_addr = p_iov_info->mbx_reply_virt_addr;
456 rply_p = p_iov_info->mbx_reply_phys_addr;
457 p_bulletin_virt = p_iov_info->p_bulletins;
458 bulletin_p = p_iov_info->bulletins_phys;
459 if (!p_req_virt_addr || !p_reply_virt_addr || !p_bulletin_virt) {
461 "ecore_iov_setup_vfdb called without alloc mem first\n");
465 for (idx = 0; idx < p_iov->total_vfs; idx++) {
466 struct ecore_vf_info *vf = &p_iov_info->vfs_array[idx];
469 vf->vf_mbx.req_virt = p_req_virt_addr + idx;
470 vf->vf_mbx.req_phys = req_p + idx * sizeof(union vfpf_tlvs);
471 vf->vf_mbx.reply_virt = p_reply_virt_addr + idx;
472 vf->vf_mbx.reply_phys = rply_p + idx * sizeof(union pfvf_tlvs);
474 #ifdef CONFIG_ECORE_SW_CHANNEL
475 vf->vf_mbx.sw_mbx.request_size = sizeof(union vfpf_tlvs);
476 vf->vf_mbx.sw_mbx.mbx_state = VF_PF_WAIT_FOR_START_REQUEST;
478 vf->state = VF_STOPPED;
481 vf->bulletin.phys = idx *
482 sizeof(struct ecore_bulletin_content) + bulletin_p;
483 vf->bulletin.p_virt = p_bulletin_virt + idx;
484 vf->bulletin.size = sizeof(struct ecore_bulletin_content);
486 vf->relative_vf_id = idx;
487 vf->abs_vf_id = idx + p_iov->first_vf_in_pf;
488 concrete = ecore_vfid_to_concrete(p_hwfn, vf->abs_vf_id);
489 vf->concrete_fid = concrete;
490 /* TODO - need to devise a better way of getting opaque */
491 vf->opaque_fid = (p_hwfn->hw_info.opaque_fid & 0xff) |
492 (vf->abs_vf_id << 8);
494 vf->num_mac_filters = ECORE_ETH_VF_NUM_MAC_FILTERS;
495 vf->num_vlan_filters = ECORE_ETH_VF_NUM_VLAN_FILTERS;
499 static enum _ecore_status_t ecore_iov_allocate_vfdb(struct ecore_hwfn *p_hwfn)
501 struct ecore_pf_iov *p_iov_info = p_hwfn->pf_iov_info;
505 num_vfs = p_hwfn->p_dev->p_iov_info->total_vfs;
507 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
508 "ecore_iov_allocate_vfdb for %d VFs\n", num_vfs);
510 /* Allocate PF Mailbox buffer (per-VF) */
511 p_iov_info->mbx_msg_size = sizeof(union vfpf_tlvs) * num_vfs;
512 p_v_addr = &p_iov_info->mbx_msg_virt_addr;
513 *p_v_addr = OSAL_DMA_ALLOC_COHERENT(p_hwfn->p_dev,
514 &p_iov_info->mbx_msg_phys_addr,
515 p_iov_info->mbx_msg_size);
519 /* Allocate PF Mailbox Reply buffer (per-VF) */
520 p_iov_info->mbx_reply_size = sizeof(union pfvf_tlvs) * num_vfs;
521 p_v_addr = &p_iov_info->mbx_reply_virt_addr;
522 *p_v_addr = OSAL_DMA_ALLOC_COHERENT(p_hwfn->p_dev,
523 &p_iov_info->mbx_reply_phys_addr,
524 p_iov_info->mbx_reply_size);
528 p_iov_info->bulletins_size = sizeof(struct ecore_bulletin_content) *
530 p_v_addr = &p_iov_info->p_bulletins;
531 *p_v_addr = OSAL_DMA_ALLOC_COHERENT(p_hwfn->p_dev,
532 &p_iov_info->bulletins_phys,
533 p_iov_info->bulletins_size);
537 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
538 "PF's Requests mailbox [%p virt 0x%lx phys], "
539 "Response mailbox [%p virt 0x%lx phys] Bulletinsi"
540 " [%p virt 0x%lx phys]\n",
541 p_iov_info->mbx_msg_virt_addr,
542 (unsigned long)p_iov_info->mbx_msg_phys_addr,
543 p_iov_info->mbx_reply_virt_addr,
544 (unsigned long)p_iov_info->mbx_reply_phys_addr,
545 p_iov_info->p_bulletins,
546 (unsigned long)p_iov_info->bulletins_phys);
548 return ECORE_SUCCESS;
551 static void ecore_iov_free_vfdb(struct ecore_hwfn *p_hwfn)
553 struct ecore_pf_iov *p_iov_info = p_hwfn->pf_iov_info;
555 if (p_hwfn->pf_iov_info->mbx_msg_virt_addr)
556 OSAL_DMA_FREE_COHERENT(p_hwfn->p_dev,
557 p_iov_info->mbx_msg_virt_addr,
558 p_iov_info->mbx_msg_phys_addr,
559 p_iov_info->mbx_msg_size);
561 if (p_hwfn->pf_iov_info->mbx_reply_virt_addr)
562 OSAL_DMA_FREE_COHERENT(p_hwfn->p_dev,
563 p_iov_info->mbx_reply_virt_addr,
564 p_iov_info->mbx_reply_phys_addr,
565 p_iov_info->mbx_reply_size);
567 if (p_iov_info->p_bulletins)
568 OSAL_DMA_FREE_COHERENT(p_hwfn->p_dev,
569 p_iov_info->p_bulletins,
570 p_iov_info->bulletins_phys,
571 p_iov_info->bulletins_size);
574 enum _ecore_status_t ecore_iov_alloc(struct ecore_hwfn *p_hwfn)
576 struct ecore_pf_iov *p_sriov;
578 if (!IS_PF_SRIOV(p_hwfn)) {
579 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
580 "No SR-IOV - no need for IOV db\n");
581 return ECORE_SUCCESS;
584 p_sriov = OSAL_ZALLOC(p_hwfn->p_dev, GFP_KERNEL, sizeof(*p_sriov));
586 DP_NOTICE(p_hwfn, true,
587 "Failed to allocate `struct ecore_sriov'\n");
591 p_hwfn->pf_iov_info = p_sriov;
593 return ecore_iov_allocate_vfdb(p_hwfn);
596 void ecore_iov_setup(struct ecore_hwfn *p_hwfn)
598 if (!IS_PF_SRIOV(p_hwfn) || !IS_PF_SRIOV_ALLOC(p_hwfn))
601 ecore_iov_setup_vfdb(p_hwfn);
604 void ecore_iov_free(struct ecore_hwfn *p_hwfn)
606 if (IS_PF_SRIOV_ALLOC(p_hwfn)) {
607 ecore_iov_free_vfdb(p_hwfn);
608 OSAL_FREE(p_hwfn->p_dev, p_hwfn->pf_iov_info);
612 void ecore_iov_free_hw_info(struct ecore_dev *p_dev)
614 OSAL_FREE(p_dev, p_dev->p_iov_info);
617 enum _ecore_status_t ecore_iov_hw_info(struct ecore_hwfn *p_hwfn)
619 struct ecore_dev *p_dev = p_hwfn->p_dev;
621 enum _ecore_status_t rc;
623 if (IS_VF(p_hwfn->p_dev))
624 return ECORE_SUCCESS;
626 /* Learn the PCI configuration */
627 pos = OSAL_PCI_FIND_EXT_CAPABILITY(p_hwfn->p_dev,
628 PCI_EXT_CAP_ID_SRIOV);
630 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV, "No PCIe IOV support\n");
631 return ECORE_SUCCESS;
634 /* Allocate a new struct for IOV information */
635 /* TODO - can change to VALLOC when its available */
636 p_dev->p_iov_info = OSAL_ZALLOC(p_dev, GFP_KERNEL,
637 sizeof(*p_dev->p_iov_info));
638 if (!p_dev->p_iov_info) {
639 DP_NOTICE(p_hwfn, true,
640 "Can't support IOV due to lack of memory\n");
643 p_dev->p_iov_info->pos = pos;
645 rc = ecore_iov_pci_cfg_info(p_dev);
649 /* We want PF IOV to be synonemous with the existence of p_iov_info;
650 * In case the capability is published but there are no VFs, simply
651 * de-allocate the struct.
653 if (!p_dev->p_iov_info->total_vfs) {
654 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
655 "IOV capabilities, but no VFs are published\n");
656 OSAL_FREE(p_dev, p_dev->p_iov_info);
657 return ECORE_SUCCESS;
660 /* First VF index based on offset is tricky:
661 * - If ARI is supported [likely], offset - (16 - pf_id) would
662 * provide the number for eng0. 2nd engine Vfs would begin
663 * after the first engine's VFs.
664 * - If !ARI, VFs would start on next device.
665 * so offset - (256 - pf_id) would provide the number.
666 * Utilize the fact that (256 - pf_id) is achieved only be later
667 * to diffrentiate between the two.
670 if (p_hwfn->p_dev->p_iov_info->offset < (256 - p_hwfn->abs_pf_id)) {
671 u32 first = p_hwfn->p_dev->p_iov_info->offset +
672 p_hwfn->abs_pf_id - 16;
674 p_dev->p_iov_info->first_vf_in_pf = first;
676 if (ECORE_PATH_ID(p_hwfn))
677 p_dev->p_iov_info->first_vf_in_pf -= MAX_NUM_VFS_BB;
679 u32 first = p_hwfn->p_dev->p_iov_info->offset +
680 p_hwfn->abs_pf_id - 256;
682 p_dev->p_iov_info->first_vf_in_pf = first;
685 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
686 "First VF in hwfn 0x%08x\n",
687 p_dev->p_iov_info->first_vf_in_pf);
689 return ECORE_SUCCESS;
692 static bool _ecore_iov_pf_sanity_check(struct ecore_hwfn *p_hwfn, int vfid,
693 bool b_fail_malicious)
695 /* Check PF supports sriov */
696 if (IS_VF(p_hwfn->p_dev) || !IS_ECORE_SRIOV(p_hwfn->p_dev) ||
697 !IS_PF_SRIOV_ALLOC(p_hwfn))
700 /* Check VF validity */
701 if (!ecore_iov_is_valid_vfid(p_hwfn, vfid, true, b_fail_malicious))
707 bool ecore_iov_pf_sanity_check(struct ecore_hwfn *p_hwfn, int vfid)
709 return _ecore_iov_pf_sanity_check(p_hwfn, vfid, true);
712 void ecore_iov_set_vf_to_disable(struct ecore_dev *p_dev,
713 u16 rel_vf_id, u8 to_disable)
715 struct ecore_vf_info *vf;
718 for_each_hwfn(p_dev, i) {
719 struct ecore_hwfn *p_hwfn = &p_dev->hwfns[i];
721 vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, false);
725 vf->to_disable = to_disable;
729 void ecore_iov_set_vfs_to_disable(struct ecore_dev *p_dev,
734 if (!IS_ECORE_SRIOV(p_dev))
737 for (i = 0; i < p_dev->p_iov_info->total_vfs; i++)
738 ecore_iov_set_vf_to_disable(p_dev, i, to_disable);
742 /* @@@TBD Consider taking outside of ecore... */
743 enum _ecore_status_t ecore_iov_set_vf_ctx(struct ecore_hwfn *p_hwfn,
747 enum _ecore_status_t rc = ECORE_SUCCESS;
748 struct ecore_vf_info *vf = ecore_iov_get_vf_info(p_hwfn, vf_id, true);
750 if (vf != OSAL_NULL) {
752 #ifdef CONFIG_ECORE_SW_CHANNEL
753 vf->vf_mbx.sw_mbx.mbx_state = VF_PF_WAIT_FOR_START_REQUEST;
756 rc = ECORE_UNKNOWN_ERROR;
762 static void ecore_iov_vf_pglue_clear_err(struct ecore_hwfn *p_hwfn,
763 struct ecore_ptt *p_ptt,
766 ecore_wr(p_hwfn, p_ptt,
767 PGLUE_B_REG_WAS_ERROR_VF_31_0_CLR + (abs_vfid >> 5) * 4,
768 1 << (abs_vfid & 0x1f));
771 static void ecore_iov_vf_igu_reset(struct ecore_hwfn *p_hwfn,
772 struct ecore_ptt *p_ptt,
773 struct ecore_vf_info *vf)
777 /* Set VF masks and configuration - pretend */
778 ecore_fid_pretend(p_hwfn, p_ptt, (u16)vf->concrete_fid);
780 ecore_wr(p_hwfn, p_ptt, IGU_REG_STATISTIC_NUM_VF_MSG_SENT, 0);
783 ecore_fid_pretend(p_hwfn, p_ptt, (u16)p_hwfn->hw_info.concrete_fid);
785 /* iterate over all queues, clear sb consumer */
786 for (i = 0; i < vf->num_sbs; i++)
787 ecore_int_igu_init_pure_rt_single(p_hwfn, p_ptt,
789 vf->opaque_fid, true);
792 static void ecore_iov_vf_igu_set_int(struct ecore_hwfn *p_hwfn,
793 struct ecore_ptt *p_ptt,
794 struct ecore_vf_info *vf, bool enable)
798 ecore_fid_pretend(p_hwfn, p_ptt, (u16)vf->concrete_fid);
800 igu_vf_conf = ecore_rd(p_hwfn, p_ptt, IGU_REG_VF_CONFIGURATION);
803 igu_vf_conf |= IGU_VF_CONF_MSI_MSIX_EN;
805 igu_vf_conf &= ~IGU_VF_CONF_MSI_MSIX_EN;
807 ecore_wr(p_hwfn, p_ptt, IGU_REG_VF_CONFIGURATION, igu_vf_conf);
810 ecore_fid_pretend(p_hwfn, p_ptt, (u16)p_hwfn->hw_info.concrete_fid);
813 static enum _ecore_status_t
814 ecore_iov_enable_vf_access_msix(struct ecore_hwfn *p_hwfn,
815 struct ecore_ptt *p_ptt,
822 /* If client overrides this, don't do anything */
823 if (p_hwfn->p_dev->b_dont_override_vf_msix)
824 return ECORE_SUCCESS;
826 /* For AH onward, configuration is per-PF. Find maximum of all
827 * the currently enabled child VFs, and set the number to be that.
829 if (!ECORE_IS_BB(p_hwfn->p_dev)) {
830 ecore_for_each_vf(p_hwfn, i) {
831 struct ecore_vf_info *p_vf;
833 p_vf = ecore_iov_get_vf_info(p_hwfn, (u16)i, true);
837 current_max = OSAL_MAX_T(u8, current_max,
842 if (num_sbs > current_max)
843 return ecore_mcp_config_vf_msix(p_hwfn, p_ptt,
846 return ECORE_SUCCESS;
849 static enum _ecore_status_t
850 ecore_iov_enable_vf_access(struct ecore_hwfn *p_hwfn,
851 struct ecore_ptt *p_ptt, struct ecore_vf_info *vf)
853 u32 igu_vf_conf = IGU_VF_CONF_FUNC_EN;
854 enum _ecore_status_t rc = ECORE_SUCCESS;
857 return ECORE_SUCCESS;
859 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
860 "Enable internal access for vf %x [abs %x]\n", vf->abs_vf_id,
861 ECORE_VF_ABS_ID(p_hwfn, vf));
863 ecore_iov_vf_pglue_clear_err(p_hwfn, p_ptt,
864 ECORE_VF_ABS_ID(p_hwfn, vf));
866 ecore_iov_vf_igu_reset(p_hwfn, p_ptt, vf);
868 /* It's possible VF was previously considered malicious */
869 vf->b_malicious = false;
870 rc = ecore_iov_enable_vf_access_msix(p_hwfn, p_ptt,
871 vf->abs_vf_id, vf->num_sbs);
872 if (rc != ECORE_SUCCESS)
875 ecore_fid_pretend(p_hwfn, p_ptt, (u16)vf->concrete_fid);
877 SET_FIELD(igu_vf_conf, IGU_VF_CONF_PARENT, p_hwfn->rel_pf_id);
878 STORE_RT_REG(p_hwfn, IGU_REG_VF_CONFIGURATION_RT_OFFSET, igu_vf_conf);
880 ecore_init_run(p_hwfn, p_ptt, PHASE_VF, vf->abs_vf_id,
881 p_hwfn->hw_info.hw_mode);
884 ecore_fid_pretend(p_hwfn, p_ptt, (u16)p_hwfn->hw_info.concrete_fid);
893 * @brief ecore_iov_config_perm_table - configure the permission
895 * In E4, queue zone permission table size is 320x9. There
896 * are 320 VF queues for single engine device (256 for dual
897 * engine device), and each entry has the following format:
904 static void ecore_iov_config_perm_table(struct ecore_hwfn *p_hwfn,
905 struct ecore_ptt *p_ptt,
906 struct ecore_vf_info *vf, u8 enable)
912 for (qid = 0; qid < vf->num_rxqs; qid++) {
913 ecore_fw_l2_queue(p_hwfn, vf->vf_queues[qid].fw_rx_qid,
916 reg_addr = PSWHST_REG_ZONE_PERMISSION_TABLE + qzone_id * 4;
917 val = enable ? (vf->abs_vf_id | (1 << 8)) : 0;
918 ecore_wr(p_hwfn, p_ptt, reg_addr, val);
922 static void ecore_iov_enable_vf_traffic(struct ecore_hwfn *p_hwfn,
923 struct ecore_ptt *p_ptt,
924 struct ecore_vf_info *vf)
926 /* Reset vf in IGU - interrupts are still disabled */
927 ecore_iov_vf_igu_reset(p_hwfn, p_ptt, vf);
929 ecore_iov_vf_igu_set_int(p_hwfn, p_ptt, vf, 1);
931 /* Permission Table */
932 ecore_iov_config_perm_table(p_hwfn, p_ptt, vf, true);
935 static u8 ecore_iov_alloc_vf_igu_sbs(struct ecore_hwfn *p_hwfn,
936 struct ecore_ptt *p_ptt,
937 struct ecore_vf_info *vf,
940 struct ecore_igu_block *p_block;
941 struct cau_sb_entry sb_entry;
945 if (num_rx_queues > p_hwfn->hw_info.p_igu_info->usage.free_cnt_iov)
947 (u16)p_hwfn->hw_info.p_igu_info->usage.free_cnt_iov;
948 p_hwfn->hw_info.p_igu_info->usage.free_cnt_iov -= num_rx_queues;
950 SET_FIELD(val, IGU_MAPPING_LINE_FUNCTION_NUMBER, vf->abs_vf_id);
951 SET_FIELD(val, IGU_MAPPING_LINE_VALID, 1);
952 SET_FIELD(val, IGU_MAPPING_LINE_PF_VALID, 0);
954 for (qid = 0; qid < num_rx_queues; qid++) {
955 p_block = ecore_get_igu_free_sb(p_hwfn, false);
956 vf->igu_sbs[qid] = p_block->igu_sb_id;
957 p_block->status &= ~ECORE_IGU_STATUS_FREE;
958 SET_FIELD(val, IGU_MAPPING_LINE_VECTOR_NUMBER, qid);
960 ecore_wr(p_hwfn, p_ptt,
961 IGU_REG_MAPPING_MEMORY +
962 sizeof(u32) * p_block->igu_sb_id, val);
964 /* Configure igu sb in CAU which were marked valid */
965 ecore_init_cau_sb_entry(p_hwfn, &sb_entry,
968 ecore_dmae_host2grc(p_hwfn, p_ptt,
969 (u64)(osal_uintptr_t)&sb_entry,
970 CAU_REG_SB_VAR_MEMORY +
971 p_block->igu_sb_id * sizeof(u64), 2, 0);
974 vf->num_sbs = (u8)num_rx_queues;
981 * @brief The function invalidates all the VF entries,
982 * technically this isn't required, but added for
983 * cleaness and ease of debugging incase a VF attempts to
984 * produce an interrupt after it has been taken down.
990 static void ecore_iov_free_vf_igu_sbs(struct ecore_hwfn *p_hwfn,
991 struct ecore_ptt *p_ptt,
992 struct ecore_vf_info *vf)
994 struct ecore_igu_info *p_info = p_hwfn->hw_info.p_igu_info;
998 /* Invalidate igu CAM lines and mark them as free */
999 for (idx = 0; idx < vf->num_sbs; idx++) {
1000 igu_id = vf->igu_sbs[idx];
1001 addr = IGU_REG_MAPPING_MEMORY + sizeof(u32) * igu_id;
1003 val = ecore_rd(p_hwfn, p_ptt, addr);
1004 SET_FIELD(val, IGU_MAPPING_LINE_VALID, 0);
1005 ecore_wr(p_hwfn, p_ptt, addr, val);
1007 p_info->entry[igu_id].status |= ECORE_IGU_STATUS_FREE;
1008 p_hwfn->hw_info.p_igu_info->usage.free_cnt_iov++;
1014 void ecore_iov_set_link(struct ecore_hwfn *p_hwfn,
1016 struct ecore_mcp_link_params *params,
1017 struct ecore_mcp_link_state *link,
1018 struct ecore_mcp_link_capabilities *p_caps)
1020 struct ecore_vf_info *p_vf = ecore_iov_get_vf_info(p_hwfn, vfid, false);
1021 struct ecore_bulletin_content *p_bulletin;
1026 p_bulletin = p_vf->bulletin.p_virt;
1027 p_bulletin->req_autoneg = params->speed.autoneg;
1028 p_bulletin->req_adv_speed = params->speed.advertised_speeds;
1029 p_bulletin->req_forced_speed = params->speed.forced_speed;
1030 p_bulletin->req_autoneg_pause = params->pause.autoneg;
1031 p_bulletin->req_forced_rx = params->pause.forced_rx;
1032 p_bulletin->req_forced_tx = params->pause.forced_tx;
1033 p_bulletin->req_loopback = params->loopback_mode;
1035 p_bulletin->link_up = link->link_up;
1036 p_bulletin->speed = link->speed;
1037 p_bulletin->full_duplex = link->full_duplex;
1038 p_bulletin->autoneg = link->an;
1039 p_bulletin->autoneg_complete = link->an_complete;
1040 p_bulletin->parallel_detection = link->parallel_detection;
1041 p_bulletin->pfc_enabled = link->pfc_enabled;
1042 p_bulletin->partner_adv_speed = link->partner_adv_speed;
1043 p_bulletin->partner_tx_flow_ctrl_en = link->partner_tx_flow_ctrl_en;
1044 p_bulletin->partner_rx_flow_ctrl_en = link->partner_rx_flow_ctrl_en;
1045 p_bulletin->partner_adv_pause = link->partner_adv_pause;
1046 p_bulletin->sfp_tx_fault = link->sfp_tx_fault;
1048 p_bulletin->capability_speed = p_caps->speed_capabilities;
1051 enum _ecore_status_t
1052 ecore_iov_init_hw_for_vf(struct ecore_hwfn *p_hwfn,
1053 struct ecore_ptt *p_ptt,
1054 struct ecore_iov_vf_init_params *p_params)
1056 struct ecore_mcp_link_capabilities link_caps;
1057 struct ecore_mcp_link_params link_params;
1058 struct ecore_mcp_link_state link_state;
1059 u8 num_of_vf_available_chains = 0;
1060 struct ecore_vf_info *vf = OSAL_NULL;
1062 enum _ecore_status_t rc = ECORE_SUCCESS;
1066 vf = ecore_iov_get_vf_info(p_hwfn, p_params->rel_vf_id, false);
1068 DP_ERR(p_hwfn, "ecore_iov_init_hw_for_vf : vf is OSAL_NULL\n");
1069 return ECORE_UNKNOWN_ERROR;
1073 DP_NOTICE(p_hwfn, true, "VF[%d] is already active.\n",
1074 p_params->rel_vf_id);
1078 /* Perform sanity checking on the requested vport/rss */
1079 if (p_params->vport_id >= RESC_NUM(p_hwfn, ECORE_VPORT)) {
1080 DP_NOTICE(p_hwfn, true, "VF[%d] - can't use VPORT %02x\n",
1081 p_params->rel_vf_id, p_params->vport_id);
1085 if ((p_params->num_queues > 1) &&
1086 (p_params->rss_eng_id >= RESC_NUM(p_hwfn, ECORE_RSS_ENG))) {
1087 DP_NOTICE(p_hwfn, true, "VF[%d] - can't use RSS_ENG %02x\n",
1088 p_params->rel_vf_id, p_params->rss_eng_id);
1092 /* TODO - remove this once we get confidence of change */
1093 if (!p_params->vport_id) {
1094 DP_NOTICE(p_hwfn, false,
1095 "VF[%d] - Unlikely that VF uses vport0. Forgotten?\n",
1096 p_params->rel_vf_id);
1098 if ((!p_params->rss_eng_id) && (p_params->num_queues > 1)) {
1099 DP_NOTICE(p_hwfn, false,
1100 "VF[%d] - Unlikely that VF uses RSS_eng0. Forgotten?\n",
1101 p_params->rel_vf_id);
1103 vf->vport_id = p_params->vport_id;
1104 vf->rss_eng_id = p_params->rss_eng_id;
1106 /* Since it's possible to relocate SBs, it's a bit difficult to check
1107 * things here. Simply check whether the index falls in the range
1108 * belonging to the PF.
1110 for (i = 0; i < p_params->num_queues; i++) {
1111 qid = p_params->req_rx_queue[i];
1112 if (qid > (u16)RESC_NUM(p_hwfn, ECORE_L2_QUEUE)) {
1113 DP_NOTICE(p_hwfn, true,
1114 "Can't enable Rx qid [%04x] for VF[%d]: qids [0,,...,0x%04x] available\n",
1115 qid, p_params->rel_vf_id,
1116 (u16)RESC_NUM(p_hwfn, ECORE_L2_QUEUE));
1120 qid = p_params->req_tx_queue[i];
1121 if (qid > (u16)RESC_NUM(p_hwfn, ECORE_L2_QUEUE)) {
1122 DP_NOTICE(p_hwfn, true,
1123 "Can't enable Tx qid [%04x] for VF[%d]: qids [0,,...,0x%04x] available\n",
1124 qid, p_params->rel_vf_id,
1125 (u16)RESC_NUM(p_hwfn, ECORE_L2_QUEUE));
1130 /* Limit number of queues according to number of CIDs */
1131 ecore_cxt_get_proto_cid_count(p_hwfn, PROTOCOLID_ETH, &cids);
1132 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1133 "VF[%d] - requesting to initialize for 0x%04x queues"
1134 " [0x%04x CIDs available]\n",
1135 vf->relative_vf_id, p_params->num_queues, (u16)cids);
1136 num_irqs = OSAL_MIN_T(u16, p_params->num_queues, ((u16)cids));
1138 num_of_vf_available_chains = ecore_iov_alloc_vf_igu_sbs(p_hwfn,
1142 if (num_of_vf_available_chains == 0) {
1143 DP_ERR(p_hwfn, "no available igu sbs\n");
1147 /* Choose queue number and index ranges */
1148 vf->num_rxqs = num_of_vf_available_chains;
1149 vf->num_txqs = num_of_vf_available_chains;
1151 for (i = 0; i < vf->num_rxqs; i++) {
1152 struct ecore_vf_queue *p_queue = &vf->vf_queues[i];
1154 p_queue->fw_rx_qid = p_params->req_rx_queue[i];
1155 p_queue->fw_tx_qid = p_params->req_tx_queue[i];
1157 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1158 "VF[%d] - Q[%d] SB %04x, qid [Rx %04x Tx %04x]\n",
1159 vf->relative_vf_id, i, vf->igu_sbs[i],
1160 p_queue->fw_rx_qid, p_queue->fw_tx_qid);
1163 /* Update the link configuration in bulletin.
1165 OSAL_MEMCPY(&link_params, ecore_mcp_get_link_params(p_hwfn),
1166 sizeof(link_params));
1167 OSAL_MEMCPY(&link_state, ecore_mcp_get_link_state(p_hwfn),
1168 sizeof(link_state));
1169 OSAL_MEMCPY(&link_caps, ecore_mcp_get_link_capabilities(p_hwfn),
1171 ecore_iov_set_link(p_hwfn, p_params->rel_vf_id,
1172 &link_params, &link_state, &link_caps);
1174 rc = ecore_iov_enable_vf_access(p_hwfn, p_ptt, vf);
1176 if (rc == ECORE_SUCCESS) {
1178 p_hwfn->pf_iov_info->active_vfs[vf->relative_vf_id / 64] |=
1179 (1ULL << (vf->relative_vf_id % 64));
1181 if (IS_LEAD_HWFN(p_hwfn))
1182 p_hwfn->p_dev->p_iov_info->num_vfs++;
1188 enum _ecore_status_t ecore_iov_release_hw_for_vf(struct ecore_hwfn *p_hwfn,
1189 struct ecore_ptt *p_ptt,
1192 struct ecore_mcp_link_capabilities caps;
1193 struct ecore_mcp_link_params params;
1194 struct ecore_mcp_link_state link;
1195 struct ecore_vf_info *vf = OSAL_NULL;
1197 vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
1199 DP_ERR(p_hwfn, "ecore_iov_release_hw_for_vf : vf is NULL\n");
1200 return ECORE_UNKNOWN_ERROR;
1203 if (vf->bulletin.p_virt)
1204 OSAL_MEMSET(vf->bulletin.p_virt, 0,
1205 sizeof(*vf->bulletin.p_virt));
1207 OSAL_MEMSET(&vf->p_vf_info, 0, sizeof(vf->p_vf_info));
1209 /* Get the link configuration back in bulletin so
1210 * that when VFs are re-enabled they get the actual
1211 * link configuration.
1213 OSAL_MEMCPY(¶ms, ecore_mcp_get_link_params(p_hwfn), sizeof(params));
1214 OSAL_MEMCPY(&link, ecore_mcp_get_link_state(p_hwfn), sizeof(link));
1215 OSAL_MEMCPY(&caps, ecore_mcp_get_link_capabilities(p_hwfn),
1217 ecore_iov_set_link(p_hwfn, rel_vf_id, ¶ms, &link, &caps);
1219 /* Forget the VF's acquisition message */
1220 OSAL_MEMSET(&vf->acquire, 0, sizeof(vf->acquire));
1222 /* disablng interrupts and resetting permission table was done during
1223 * vf-close, however, we could get here without going through vf_close
1225 /* Disable Interrupts for VF */
1226 ecore_iov_vf_igu_set_int(p_hwfn, p_ptt, vf, 0);
1228 /* Reset Permission table */
1229 ecore_iov_config_perm_table(p_hwfn, p_ptt, vf, 0);
1233 ecore_iov_free_vf_igu_sbs(p_hwfn, p_ptt, vf);
1237 p_hwfn->pf_iov_info->active_vfs[vf->relative_vf_id / 64] &=
1238 ~(1ULL << (vf->relative_vf_id / 64));
1240 if (IS_LEAD_HWFN(p_hwfn))
1241 p_hwfn->p_dev->p_iov_info->num_vfs--;
1244 return ECORE_SUCCESS;
1247 static bool ecore_iov_tlv_supported(u16 tlvtype)
1249 return tlvtype > CHANNEL_TLV_NONE && tlvtype < CHANNEL_TLV_MAX;
1252 static void ecore_iov_lock_vf_pf_channel(struct ecore_hwfn *p_hwfn,
1253 struct ecore_vf_info *vf, u16 tlv)
1255 /* lock the channel */
1256 /* mutex_lock(&vf->op_mutex); @@@TBD MichalK - add lock... */
1258 /* record the locking op */
1259 /* vf->op_current = tlv; @@@TBD MichalK */
1262 if (ecore_iov_tlv_supported(tlv))
1265 "VF[%d]: vf pf channel locked by %s\n",
1267 ecore_channel_tlvs_string[tlv]);
1271 "VF[%d]: vf pf channel locked by %04x\n",
1272 vf->abs_vf_id, tlv);
1275 static void ecore_iov_unlock_vf_pf_channel(struct ecore_hwfn *p_hwfn,
1276 struct ecore_vf_info *vf,
1279 /* log the unlock */
1280 if (ecore_iov_tlv_supported(expected_tlv))
1283 "VF[%d]: vf pf channel unlocked by %s\n",
1285 ecore_channel_tlvs_string[expected_tlv]);
1289 "VF[%d]: vf pf channel unlocked by %04x\n",
1290 vf->abs_vf_id, expected_tlv);
1292 /* record the locking op */
1293 /* vf->op_current = CHANNEL_TLV_NONE; */
1296 /* place a given tlv on the tlv buffer, continuing current tlv list */
1297 void *ecore_add_tlv(u8 **offset, u16 type, u16 length)
1299 struct channel_tlv *tl = (struct channel_tlv *)*offset;
1302 tl->length = length;
1304 /* Offset should keep pointing to next TLV (the end of the last) */
1307 /* Return a pointer to the start of the added tlv */
1308 return *offset - length;
1311 /* list the types and lengths of the tlvs on the buffer */
1312 void ecore_dp_tlv_list(struct ecore_hwfn *p_hwfn, void *tlvs_list)
1314 u16 i = 1, total_length = 0;
1315 struct channel_tlv *tlv;
1318 /* cast current tlv list entry to channel tlv header */
1319 tlv = (struct channel_tlv *)((u8 *)tlvs_list + total_length);
1322 if (ecore_iov_tlv_supported(tlv->type))
1323 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1324 "TLV number %d: type %s, length %d\n",
1325 i, ecore_channel_tlvs_string[tlv->type],
1328 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1329 "TLV number %d: type %d, length %d\n",
1330 i, tlv->type, tlv->length);
1332 if (tlv->type == CHANNEL_TLV_LIST_END)
1335 /* Validate entry - protect against malicious VFs */
1337 DP_NOTICE(p_hwfn, false, "TLV of length 0 found\n");
1340 total_length += tlv->length;
1341 if (total_length >= sizeof(struct tlv_buffer_size)) {
1342 DP_NOTICE(p_hwfn, false, "TLV ==> Buffer overflow\n");
1350 static void ecore_iov_send_response(struct ecore_hwfn *p_hwfn,
1351 struct ecore_ptt *p_ptt,
1352 struct ecore_vf_info *p_vf,
1353 #ifdef CONFIG_ECORE_SW_CHANNEL
1356 u16 OSAL_UNUSED length,
1360 struct ecore_iov_vf_mbx *mbx = &p_vf->vf_mbx;
1361 struct ecore_dmae_params params;
1364 mbx->reply_virt->default_resp.hdr.status = status;
1366 ecore_dp_tlv_list(p_hwfn, mbx->reply_virt);
1368 #ifdef CONFIG_ECORE_SW_CHANNEL
1369 mbx->sw_mbx.response_size =
1370 length + sizeof(struct channel_list_end_tlv);
1372 if (!p_hwfn->p_dev->b_hw_channel)
1376 eng_vf_id = p_vf->abs_vf_id;
1378 OSAL_MEMSET(¶ms, 0, sizeof(struct ecore_dmae_params));
1379 params.flags = ECORE_DMAE_FLAG_VF_DST;
1380 params.dst_vfid = eng_vf_id;
1382 ecore_dmae_host2host(p_hwfn, p_ptt, mbx->reply_phys + sizeof(u64),
1383 mbx->req_virt->first_tlv.reply_address +
1385 (sizeof(union pfvf_tlvs) - sizeof(u64)) / 4,
1388 ecore_dmae_host2host(p_hwfn, p_ptt, mbx->reply_phys,
1389 mbx->req_virt->first_tlv.reply_address,
1390 sizeof(u64) / 4, ¶ms);
1393 GTT_BAR0_MAP_REG_USDM_RAM +
1394 USTORM_VF_PF_CHANNEL_READY_OFFSET(eng_vf_id), 1);
1397 static u16 ecore_iov_vport_to_tlv(enum ecore_iov_vport_update_flag flag)
1400 case ECORE_IOV_VP_UPDATE_ACTIVATE:
1401 return CHANNEL_TLV_VPORT_UPDATE_ACTIVATE;
1402 case ECORE_IOV_VP_UPDATE_VLAN_STRIP:
1403 return CHANNEL_TLV_VPORT_UPDATE_VLAN_STRIP;
1404 case ECORE_IOV_VP_UPDATE_TX_SWITCH:
1405 return CHANNEL_TLV_VPORT_UPDATE_TX_SWITCH;
1406 case ECORE_IOV_VP_UPDATE_MCAST:
1407 return CHANNEL_TLV_VPORT_UPDATE_MCAST;
1408 case ECORE_IOV_VP_UPDATE_ACCEPT_PARAM:
1409 return CHANNEL_TLV_VPORT_UPDATE_ACCEPT_PARAM;
1410 case ECORE_IOV_VP_UPDATE_RSS:
1411 return CHANNEL_TLV_VPORT_UPDATE_RSS;
1412 case ECORE_IOV_VP_UPDATE_ACCEPT_ANY_VLAN:
1413 return CHANNEL_TLV_VPORT_UPDATE_ACCEPT_ANY_VLAN;
1414 case ECORE_IOV_VP_UPDATE_SGE_TPA:
1415 return CHANNEL_TLV_VPORT_UPDATE_SGE_TPA;
1421 static u16 ecore_iov_prep_vp_update_resp_tlvs(struct ecore_hwfn *p_hwfn,
1422 struct ecore_vf_info *p_vf,
1423 struct ecore_iov_vf_mbx *p_mbx,
1424 u8 status, u16 tlvs_mask,
1427 struct pfvf_def_resp_tlv *resp;
1428 u16 size, total_len, i;
1430 OSAL_MEMSET(p_mbx->reply_virt, 0, sizeof(union pfvf_tlvs));
1431 p_mbx->offset = (u8 *)p_mbx->reply_virt;
1432 size = sizeof(struct pfvf_def_resp_tlv);
1435 ecore_add_tlv(&p_mbx->offset, CHANNEL_TLV_VPORT_UPDATE, size);
1437 /* Prepare response for all extended tlvs if they are found by PF */
1438 for (i = 0; i < ECORE_IOV_VP_UPDATE_MAX; i++) {
1439 if (!(tlvs_mask & (1 << i)))
1442 resp = ecore_add_tlv(&p_mbx->offset, ecore_iov_vport_to_tlv(i),
1445 if (tlvs_accepted & (1 << i))
1446 resp->hdr.status = status;
1448 resp->hdr.status = PFVF_STATUS_NOT_SUPPORTED;
1450 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1451 "VF[%d] - vport_update resp: TLV %d, status %02x\n",
1452 p_vf->relative_vf_id,
1453 ecore_iov_vport_to_tlv(i),
1459 ecore_add_tlv(&p_mbx->offset, CHANNEL_TLV_LIST_END,
1460 sizeof(struct channel_list_end_tlv));
1465 static void ecore_iov_prepare_resp(struct ecore_hwfn *p_hwfn,
1466 struct ecore_ptt *p_ptt,
1467 struct ecore_vf_info *vf_info,
1468 u16 type, u16 length, u8 status)
1470 struct ecore_iov_vf_mbx *mbx = &vf_info->vf_mbx;
1472 mbx->offset = (u8 *)mbx->reply_virt;
1474 ecore_add_tlv(&mbx->offset, type, length);
1475 ecore_add_tlv(&mbx->offset, CHANNEL_TLV_LIST_END,
1476 sizeof(struct channel_list_end_tlv));
1478 ecore_iov_send_response(p_hwfn, p_ptt, vf_info, length, status);
1480 OSAL_IOV_PF_RESP_TYPE(p_hwfn, vf_info->relative_vf_id, status);
1483 struct ecore_public_vf_info
1484 *ecore_iov_get_public_vf_info(struct ecore_hwfn *p_hwfn,
1486 bool b_enabled_only)
1488 struct ecore_vf_info *vf = OSAL_NULL;
1490 vf = ecore_iov_get_vf_info(p_hwfn, relative_vf_id, b_enabled_only);
1494 return &vf->p_vf_info;
1497 static void ecore_iov_vf_cleanup(struct ecore_hwfn *p_hwfn,
1498 struct ecore_vf_info *p_vf)
1501 p_vf->vf_bulletin = 0;
1502 p_vf->vport_instance = 0;
1503 p_vf->configured_features = 0;
1505 /* If VF previously requested less resources, go back to default */
1506 p_vf->num_rxqs = p_vf->num_sbs;
1507 p_vf->num_txqs = p_vf->num_sbs;
1509 p_vf->num_active_rxqs = 0;
1511 for (i = 0; i < ECORE_MAX_VF_CHAINS_PER_PF; i++) {
1512 struct ecore_vf_queue *p_queue = &p_vf->vf_queues[i];
1514 for (j = 0; j < MAX_QUEUES_PER_QZONE; j++) {
1515 if (!p_queue->cids[j].p_cid)
1518 ecore_eth_queue_cid_release(p_hwfn,
1519 p_queue->cids[j].p_cid);
1520 p_queue->cids[j].p_cid = OSAL_NULL;
1524 OSAL_MEMSET(&p_vf->shadow_config, 0, sizeof(p_vf->shadow_config));
1525 OSAL_MEMSET(&p_vf->acquire, 0, sizeof(p_vf->acquire));
1526 OSAL_IOV_VF_CLEANUP(p_hwfn, p_vf->relative_vf_id);
1529 static u8 ecore_iov_vf_mbx_acquire_resc(struct ecore_hwfn *p_hwfn,
1530 struct ecore_vf_info *p_vf,
1531 struct vf_pf_resc_request *p_req,
1532 struct pf_vf_resc *p_resp)
1536 /* Queue related information */
1537 p_resp->num_rxqs = p_vf->num_rxqs;
1538 p_resp->num_txqs = p_vf->num_txqs;
1539 p_resp->num_sbs = p_vf->num_sbs;
1541 for (i = 0; i < p_resp->num_sbs; i++) {
1542 p_resp->hw_sbs[i].hw_sb_id = p_vf->igu_sbs[i];
1543 /* TODO - what's this sb_qid field? Is it deprecated?
1544 * or is there an ecore_client that looks at this?
1546 p_resp->hw_sbs[i].sb_qid = 0;
1549 /* These fields are filled for backward compatibility.
1550 * Unused by modern vfs.
1552 for (i = 0; i < p_resp->num_rxqs; i++) {
1553 ecore_fw_l2_queue(p_hwfn, p_vf->vf_queues[i].fw_rx_qid,
1554 (u16 *)&p_resp->hw_qid[i]);
1558 /* Filter related information */
1559 p_resp->num_mac_filters = OSAL_MIN_T(u8, p_vf->num_mac_filters,
1560 p_req->num_mac_filters);
1561 p_resp->num_vlan_filters = OSAL_MIN_T(u8, p_vf->num_vlan_filters,
1562 p_req->num_vlan_filters);
1565 OSAL_MIN_T(u8, p_req->num_cids,
1566 p_hwfn->pf_params.eth_pf_params.num_vf_cons);
1568 /* This isn't really needed/enforced, but some legacy VFs might depend
1569 * on the correct filling of this field.
1571 p_resp->num_mc_filters = ECORE_MAX_MC_ADDRS;
1573 /* Validate sufficient resources for VF */
1574 if (p_resp->num_rxqs < p_req->num_rxqs ||
1575 p_resp->num_txqs < p_req->num_txqs ||
1576 p_resp->num_sbs < p_req->num_sbs ||
1577 p_resp->num_mac_filters < p_req->num_mac_filters ||
1578 p_resp->num_vlan_filters < p_req->num_vlan_filters ||
1579 p_resp->num_mc_filters < p_req->num_mc_filters ||
1580 p_resp->num_cids < p_req->num_cids) {
1581 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1582 "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",
1584 p_req->num_rxqs, p_resp->num_rxqs,
1585 p_req->num_rxqs, p_resp->num_txqs,
1586 p_req->num_sbs, p_resp->num_sbs,
1587 p_req->num_mac_filters, p_resp->num_mac_filters,
1588 p_req->num_vlan_filters, p_resp->num_vlan_filters,
1589 p_req->num_mc_filters, p_resp->num_mc_filters,
1590 p_req->num_cids, p_resp->num_cids);
1592 /* Some legacy OSes are incapable of correctly handling this
1595 if ((p_vf->acquire.vfdev_info.eth_fp_hsi_minor ==
1596 ETH_HSI_VER_NO_PKT_LEN_TUNN) &&
1597 (p_vf->acquire.vfdev_info.os_type ==
1598 VFPF_ACQUIRE_OS_WINDOWS))
1599 return PFVF_STATUS_SUCCESS;
1601 return PFVF_STATUS_NO_RESOURCE;
1604 return PFVF_STATUS_SUCCESS;
1607 static void ecore_iov_vf_mbx_acquire_stats(struct pfvf_stats_info *p_stats)
1609 p_stats->mstats.address = PXP_VF_BAR0_START_MSDM_ZONE_B +
1610 OFFSETOF(struct mstorm_vf_zone,
1611 non_trigger.eth_queue_stat);
1612 p_stats->mstats.len = sizeof(struct eth_mstorm_per_queue_stat);
1613 p_stats->ustats.address = PXP_VF_BAR0_START_USDM_ZONE_B +
1614 OFFSETOF(struct ustorm_vf_zone,
1615 non_trigger.eth_queue_stat);
1616 p_stats->ustats.len = sizeof(struct eth_ustorm_per_queue_stat);
1617 p_stats->pstats.address = PXP_VF_BAR0_START_PSDM_ZONE_B +
1618 OFFSETOF(struct pstorm_vf_zone,
1619 non_trigger.eth_queue_stat);
1620 p_stats->pstats.len = sizeof(struct eth_pstorm_per_queue_stat);
1621 p_stats->tstats.address = 0;
1622 p_stats->tstats.len = 0;
1625 static void ecore_iov_vf_mbx_acquire(struct ecore_hwfn *p_hwfn,
1626 struct ecore_ptt *p_ptt,
1627 struct ecore_vf_info *vf)
1629 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
1630 struct pfvf_acquire_resp_tlv *resp = &mbx->reply_virt->acquire_resp;
1631 struct pf_vf_pfdev_info *pfdev_info = &resp->pfdev_info;
1632 struct vfpf_acquire_tlv *req = &mbx->req_virt->acquire;
1633 u8 vfpf_status = PFVF_STATUS_NOT_SUPPORTED;
1634 struct pf_vf_resc *resc = &resp->resc;
1635 enum _ecore_status_t rc;
1637 OSAL_MEMSET(resp, 0, sizeof(*resp));
1639 /* Write the PF version so that VF would know which version
1640 * is supported - might be later overridden. This guarantees that
1641 * VF could recognize legacy PF based on lack of versions in reply.
1643 pfdev_info->major_fp_hsi = ETH_HSI_VER_MAJOR;
1644 pfdev_info->minor_fp_hsi = ETH_HSI_VER_MINOR;
1646 /* TODO - not doing anything is bad since we'll assert, but this isn't
1647 * necessarily the right behavior - perhaps we should have allowed some
1650 if (vf->state != VF_FREE &&
1651 vf->state != VF_STOPPED) {
1652 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1653 "VF[%d] sent ACQUIRE but is already in state %d - fail request\n",
1654 vf->abs_vf_id, vf->state);
1658 /* Validate FW compatibility */
1659 if (req->vfdev_info.eth_fp_hsi_major != ETH_HSI_VER_MAJOR) {
1660 if (req->vfdev_info.capabilities &
1661 VFPF_ACQUIRE_CAP_PRE_FP_HSI) {
1662 struct vf_pf_vfdev_info *p_vfdev = &req->vfdev_info;
1664 /* This legacy support would need to be removed once
1665 * the major has changed.
1667 OSAL_BUILD_BUG_ON(ETH_HSI_VER_MAJOR != 3);
1669 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1670 "VF[%d] is pre-fastpath HSI\n",
1672 p_vfdev->eth_fp_hsi_major = ETH_HSI_VER_MAJOR;
1673 p_vfdev->eth_fp_hsi_minor = ETH_HSI_VER_NO_PKT_LEN_TUNN;
1676 "VF[%d] needs fastpath HSI %02x.%02x, which is"
1677 " incompatible with loaded FW's faspath"
1680 req->vfdev_info.eth_fp_hsi_major,
1681 req->vfdev_info.eth_fp_hsi_minor,
1682 ETH_HSI_VER_MAJOR, ETH_HSI_VER_MINOR);
1688 /* On 100g PFs, prevent old VFs from loading */
1689 if ((p_hwfn->p_dev->num_hwfns > 1) &&
1690 !(req->vfdev_info.capabilities & VFPF_ACQUIRE_CAP_100G)) {
1692 "VF[%d] is running an old driver that doesn't support"
1698 #ifndef __EXTRACT__LINUX__
1699 if (OSAL_IOV_VF_ACQUIRE(p_hwfn, vf->relative_vf_id) != ECORE_SUCCESS) {
1700 vfpf_status = PFVF_STATUS_NOT_SUPPORTED;
1705 /* Store the acquire message */
1706 OSAL_MEMCPY(&vf->acquire, req, sizeof(vf->acquire));
1708 vf->opaque_fid = req->vfdev_info.opaque_fid;
1710 vf->vf_bulletin = req->bulletin_addr;
1711 vf->bulletin.size = (vf->bulletin.size < req->bulletin_size) ?
1712 vf->bulletin.size : req->bulletin_size;
1714 /* fill in pfdev info */
1715 pfdev_info->chip_num = p_hwfn->p_dev->chip_num;
1716 pfdev_info->db_size = 0; /* @@@ TBD MichalK Vf Doorbells */
1717 pfdev_info->indices_per_sb = PIS_PER_SB;
1719 pfdev_info->capabilities = PFVF_ACQUIRE_CAP_DEFAULT_UNTAGGED |
1720 PFVF_ACQUIRE_CAP_POST_FW_OVERRIDE;
1721 if (p_hwfn->p_dev->num_hwfns > 1)
1722 pfdev_info->capabilities |= PFVF_ACQUIRE_CAP_100G;
1724 /* Share our ability to use multiple queue-ids only with VFs
1727 if (req->vfdev_info.capabilities & VFPF_ACQUIRE_CAP_QUEUE_QIDS)
1728 pfdev_info->capabilities |= PFVF_ACQUIRE_CAP_QUEUE_QIDS;
1730 ecore_iov_vf_mbx_acquire_stats(&pfdev_info->stats_info);
1732 OSAL_MEMCPY(pfdev_info->port_mac, p_hwfn->hw_info.hw_mac_addr,
1735 pfdev_info->fw_major = FW_MAJOR_VERSION;
1736 pfdev_info->fw_minor = FW_MINOR_VERSION;
1737 pfdev_info->fw_rev = FW_REVISION_VERSION;
1738 pfdev_info->fw_eng = FW_ENGINEERING_VERSION;
1740 /* Incorrect when legacy, but doesn't matter as legacy isn't reading
1743 pfdev_info->minor_fp_hsi = OSAL_MIN_T(u8, ETH_HSI_VER_MINOR,
1744 req->vfdev_info.eth_fp_hsi_minor);
1745 pfdev_info->os_type = OSAL_IOV_GET_OS_TYPE();
1746 ecore_mcp_get_mfw_ver(p_hwfn, p_ptt, &pfdev_info->mfw_ver,
1749 pfdev_info->dev_type = p_hwfn->p_dev->type;
1750 pfdev_info->chip_rev = p_hwfn->p_dev->chip_rev;
1752 /* Fill resources available to VF; Make sure there are enough to
1753 * satisfy the VF's request.
1755 vfpf_status = ecore_iov_vf_mbx_acquire_resc(p_hwfn, vf,
1756 &req->resc_request, resc);
1757 if (vfpf_status != PFVF_STATUS_SUCCESS)
1760 /* Start the VF in FW */
1761 rc = ecore_sp_vf_start(p_hwfn, vf);
1762 if (rc != ECORE_SUCCESS) {
1763 DP_NOTICE(p_hwfn, true, "Failed to start VF[%02x]\n",
1765 vfpf_status = PFVF_STATUS_FAILURE;
1769 /* Fill agreed size of bulletin board in response, and post
1770 * an initial image to the bulletin board.
1772 resp->bulletin_size = vf->bulletin.size;
1773 ecore_iov_post_vf_bulletin(p_hwfn, vf->relative_vf_id, p_ptt);
1775 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1776 "VF[%d] ACQUIRE_RESPONSE: pfdev_info- chip_num=0x%x,"
1777 " db_size=%d, idx_per_sb=%d, pf_cap=0x%lx\n"
1778 "resources- n_rxq-%d, n_txq-%d, n_sbs-%d, n_macs-%d,"
1780 vf->abs_vf_id, resp->pfdev_info.chip_num,
1781 resp->pfdev_info.db_size, resp->pfdev_info.indices_per_sb,
1782 (unsigned long)resp->pfdev_info.capabilities, resc->num_rxqs,
1783 resc->num_txqs, resc->num_sbs, resc->num_mac_filters,
1784 resc->num_vlan_filters);
1786 vf->state = VF_ACQUIRED;
1789 /* Prepare Response */
1790 ecore_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_ACQUIRE,
1791 sizeof(struct pfvf_acquire_resp_tlv),
1795 static enum _ecore_status_t
1796 __ecore_iov_spoofchk_set(struct ecore_hwfn *p_hwfn,
1797 struct ecore_vf_info *p_vf, bool val)
1799 struct ecore_sp_vport_update_params params;
1800 enum _ecore_status_t rc;
1802 if (val == p_vf->spoof_chk) {
1803 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1804 "Spoofchk value[%d] is already configured\n", val);
1805 return ECORE_SUCCESS;
1808 OSAL_MEMSET(¶ms, 0, sizeof(struct ecore_sp_vport_update_params));
1809 params.opaque_fid = p_vf->opaque_fid;
1810 params.vport_id = p_vf->vport_id;
1811 params.update_anti_spoofing_en_flg = 1;
1812 params.anti_spoofing_en = val;
1814 rc = ecore_sp_vport_update(p_hwfn, ¶ms, ECORE_SPQ_MODE_EBLOCK,
1816 if (rc == ECORE_SUCCESS) {
1817 p_vf->spoof_chk = val;
1818 p_vf->req_spoofchk_val = p_vf->spoof_chk;
1819 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1820 "Spoofchk val[%d] configured\n", val);
1822 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1823 "Spoofchk configuration[val:%d] failed for VF[%d]\n",
1824 val, p_vf->relative_vf_id);
1830 static enum _ecore_status_t
1831 ecore_iov_reconfigure_unicast_vlan(struct ecore_hwfn *p_hwfn,
1832 struct ecore_vf_info *p_vf)
1834 struct ecore_filter_ucast filter;
1835 enum _ecore_status_t rc = ECORE_SUCCESS;
1838 OSAL_MEMSET(&filter, 0, sizeof(filter));
1839 filter.is_rx_filter = 1;
1840 filter.is_tx_filter = 1;
1841 filter.vport_to_add_to = p_vf->vport_id;
1842 filter.opcode = ECORE_FILTER_ADD;
1844 /* Reconfigure vlans */
1845 for (i = 0; i < ECORE_ETH_VF_NUM_VLAN_FILTERS + 1; i++) {
1846 if (!p_vf->shadow_config.vlans[i].used)
1849 filter.type = ECORE_FILTER_VLAN;
1850 filter.vlan = p_vf->shadow_config.vlans[i].vid;
1851 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1852 "Reconfiguring VLAN [0x%04x] for VF [%04x]\n",
1853 filter.vlan, p_vf->relative_vf_id);
1854 rc = ecore_sp_eth_filter_ucast(p_hwfn, p_vf->opaque_fid,
1855 &filter, ECORE_SPQ_MODE_CB,
1858 DP_NOTICE(p_hwfn, true,
1859 "Failed to configure VLAN [%04x]"
1861 filter.vlan, p_vf->relative_vf_id);
1869 static enum _ecore_status_t
1870 ecore_iov_reconfigure_unicast_shadow(struct ecore_hwfn *p_hwfn,
1871 struct ecore_vf_info *p_vf, u64 events)
1873 enum _ecore_status_t rc = ECORE_SUCCESS;
1875 /*TODO - what about MACs? */
1877 if ((events & (1 << VLAN_ADDR_FORCED)) &&
1878 !(p_vf->configured_features & (1 << VLAN_ADDR_FORCED)))
1879 rc = ecore_iov_reconfigure_unicast_vlan(p_hwfn, p_vf);
1884 static enum _ecore_status_t
1885 ecore_iov_configure_vport_forced(struct ecore_hwfn *p_hwfn,
1886 struct ecore_vf_info *p_vf,
1889 enum _ecore_status_t rc = ECORE_SUCCESS;
1890 struct ecore_filter_ucast filter;
1892 if (!p_vf->vport_instance)
1895 if (events & (1 << MAC_ADDR_FORCED)) {
1896 /* Since there's no way [currently] of removing the MAC,
1897 * we can always assume this means we need to force it.
1899 OSAL_MEMSET(&filter, 0, sizeof(filter));
1900 filter.type = ECORE_FILTER_MAC;
1901 filter.opcode = ECORE_FILTER_REPLACE;
1902 filter.is_rx_filter = 1;
1903 filter.is_tx_filter = 1;
1904 filter.vport_to_add_to = p_vf->vport_id;
1905 OSAL_MEMCPY(filter.mac, p_vf->bulletin.p_virt->mac, ETH_ALEN);
1907 rc = ecore_sp_eth_filter_ucast(p_hwfn, p_vf->opaque_fid,
1909 ECORE_SPQ_MODE_CB, OSAL_NULL);
1911 DP_NOTICE(p_hwfn, true,
1912 "PF failed to configure MAC for VF\n");
1916 p_vf->configured_features |= 1 << MAC_ADDR_FORCED;
1919 if (events & (1 << VLAN_ADDR_FORCED)) {
1920 struct ecore_sp_vport_update_params vport_update;
1924 OSAL_MEMSET(&filter, 0, sizeof(filter));
1925 filter.type = ECORE_FILTER_VLAN;
1926 filter.is_rx_filter = 1;
1927 filter.is_tx_filter = 1;
1928 filter.vport_to_add_to = p_vf->vport_id;
1929 filter.vlan = p_vf->bulletin.p_virt->pvid;
1930 filter.opcode = filter.vlan ? ECORE_FILTER_REPLACE :
1933 /* Send the ramrod */
1934 rc = ecore_sp_eth_filter_ucast(p_hwfn, p_vf->opaque_fid,
1936 ECORE_SPQ_MODE_CB, OSAL_NULL);
1938 DP_NOTICE(p_hwfn, true,
1939 "PF failed to configure VLAN for VF\n");
1943 /* Update the default-vlan & silent vlan stripping */
1944 OSAL_MEMSET(&vport_update, 0, sizeof(vport_update));
1945 vport_update.opaque_fid = p_vf->opaque_fid;
1946 vport_update.vport_id = p_vf->vport_id;
1947 vport_update.update_default_vlan_enable_flg = 1;
1948 vport_update.default_vlan_enable_flg = filter.vlan ? 1 : 0;
1949 vport_update.update_default_vlan_flg = 1;
1950 vport_update.default_vlan = filter.vlan;
1952 vport_update.update_inner_vlan_removal_flg = 1;
1953 removal = filter.vlan ?
1954 1 : p_vf->shadow_config.inner_vlan_removal;
1955 vport_update.inner_vlan_removal_flg = removal;
1956 vport_update.silent_vlan_removal_flg = filter.vlan ? 1 : 0;
1957 rc = ecore_sp_vport_update(p_hwfn, &vport_update,
1958 ECORE_SPQ_MODE_EBLOCK, OSAL_NULL);
1960 DP_NOTICE(p_hwfn, true,
1961 "PF failed to configure VF vport for vlan\n");
1965 /* Update all the Rx queues */
1966 for (i = 0; i < ECORE_MAX_VF_CHAINS_PER_PF; i++) {
1967 struct ecore_vf_queue *p_queue = &p_vf->vf_queues[i];
1968 struct ecore_queue_cid *p_cid = OSAL_NULL;
1970 /* There can be at most 1 Rx queue on qzone. Find it */
1971 p_cid = ecore_iov_get_vf_rx_queue_cid(p_queue);
1972 if (p_cid == OSAL_NULL)
1975 rc = ecore_sp_eth_rx_queues_update(p_hwfn,
1978 ECORE_SPQ_MODE_EBLOCK,
1981 DP_NOTICE(p_hwfn, true,
1982 "Failed to send Rx update"
1983 " fo queue[0x%04x]\n",
1984 p_cid->rel.queue_id);
1990 p_vf->configured_features |= 1 << VLAN_ADDR_FORCED;
1992 p_vf->configured_features &= ~(1 << VLAN_ADDR_FORCED);
1995 /* If forced features are terminated, we need to configure the shadow
1996 * configuration back again.
1999 ecore_iov_reconfigure_unicast_shadow(p_hwfn, p_vf, events);
2004 static void ecore_iov_vf_mbx_start_vport(struct ecore_hwfn *p_hwfn,
2005 struct ecore_ptt *p_ptt,
2006 struct ecore_vf_info *vf)
2008 struct ecore_sp_vport_start_params params = { 0 };
2009 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
2010 struct vfpf_vport_start_tlv *start;
2011 u8 status = PFVF_STATUS_SUCCESS;
2012 struct ecore_vf_info *vf_info;
2015 enum _ecore_status_t rc;
2017 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vf->relative_vf_id, true);
2019 DP_NOTICE(p_hwfn->p_dev, true,
2020 "Failed to get VF info, invalid vfid [%d]\n",
2021 vf->relative_vf_id);
2025 vf->state = VF_ENABLED;
2026 start = &mbx->req_virt->start_vport;
2028 ecore_iov_enable_vf_traffic(p_hwfn, p_ptt, vf);
2030 /* Initialize Status block in CAU */
2031 for (sb_id = 0; sb_id < vf->num_sbs; sb_id++) {
2032 if (!start->sb_addr[sb_id]) {
2033 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2034 "VF[%d] did not fill the address of SB %d\n",
2035 vf->relative_vf_id, sb_id);
2039 ecore_int_cau_conf_sb(p_hwfn, p_ptt,
2040 start->sb_addr[sb_id],
2045 vf->mtu = start->mtu;
2046 vf->shadow_config.inner_vlan_removal = start->inner_vlan_removal;
2048 /* Take into consideration configuration forced by hypervisor;
2049 * If none is configured, use the supplied VF values [for old
2050 * vfs that would still be fine, since they passed '0' as padding].
2052 p_bitmap = &vf_info->bulletin.p_virt->valid_bitmap;
2053 if (!(*p_bitmap & (1 << VFPF_BULLETIN_UNTAGGED_DEFAULT_FORCED))) {
2054 u8 vf_req = start->only_untagged;
2056 vf_info->bulletin.p_virt->default_only_untagged = vf_req;
2057 *p_bitmap |= 1 << VFPF_BULLETIN_UNTAGGED_DEFAULT;
2060 params.tpa_mode = start->tpa_mode;
2061 params.remove_inner_vlan = start->inner_vlan_removal;
2062 params.tx_switching = true;
2065 if (CHIP_REV_IS_FPGA(p_hwfn->p_dev)) {
2066 DP_NOTICE(p_hwfn, false,
2067 "FPGA: Don't config VF for Tx-switching [no pVFC]\n");
2068 params.tx_switching = false;
2072 params.only_untagged = vf_info->bulletin.p_virt->default_only_untagged;
2073 params.drop_ttl0 = false;
2074 params.concrete_fid = vf->concrete_fid;
2075 params.opaque_fid = vf->opaque_fid;
2076 params.vport_id = vf->vport_id;
2077 params.max_buffers_per_cqe = start->max_buffers_per_cqe;
2078 params.mtu = vf->mtu;
2079 params.check_mac = true;
2081 rc = ecore_sp_eth_vport_start(p_hwfn, ¶ms);
2082 if (rc != ECORE_SUCCESS) {
2084 "ecore_iov_vf_mbx_start_vport returned error %d\n", rc);
2085 status = PFVF_STATUS_FAILURE;
2087 vf->vport_instance++;
2089 /* Force configuration if needed on the newly opened vport */
2090 ecore_iov_configure_vport_forced(p_hwfn, vf, *p_bitmap);
2091 OSAL_IOV_POST_START_VPORT(p_hwfn, vf->relative_vf_id,
2092 vf->vport_id, vf->opaque_fid);
2093 __ecore_iov_spoofchk_set(p_hwfn, vf, vf->req_spoofchk_val);
2096 ecore_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_VPORT_START,
2097 sizeof(struct pfvf_def_resp_tlv), status);
2100 static void ecore_iov_vf_mbx_stop_vport(struct ecore_hwfn *p_hwfn,
2101 struct ecore_ptt *p_ptt,
2102 struct ecore_vf_info *vf)
2104 u8 status = PFVF_STATUS_SUCCESS;
2105 enum _ecore_status_t rc;
2107 vf->vport_instance--;
2108 vf->spoof_chk = false;
2110 if ((ecore_iov_validate_active_rxq(vf)) ||
2111 (ecore_iov_validate_active_txq(vf))) {
2112 vf->b_malicious = true;
2113 DP_NOTICE(p_hwfn, false,
2114 "VF [%02x] - considered malicious;"
2115 " Unable to stop RX/TX queuess\n",
2117 status = PFVF_STATUS_MALICIOUS;
2121 rc = ecore_sp_vport_stop(p_hwfn, vf->opaque_fid, vf->vport_id);
2122 if (rc != ECORE_SUCCESS) {
2124 "ecore_iov_vf_mbx_stop_vport returned error %d\n", rc);
2125 status = PFVF_STATUS_FAILURE;
2128 /* Forget the configuration on the vport */
2129 vf->configured_features = 0;
2130 OSAL_MEMSET(&vf->shadow_config, 0, sizeof(vf->shadow_config));
2133 ecore_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_VPORT_TEARDOWN,
2134 sizeof(struct pfvf_def_resp_tlv), status);
2137 static void ecore_iov_vf_mbx_start_rxq_resp(struct ecore_hwfn *p_hwfn,
2138 struct ecore_ptt *p_ptt,
2139 struct ecore_vf_info *vf,
2140 u8 status, bool b_legacy)
2142 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
2143 struct pfvf_start_queue_resp_tlv *p_tlv;
2144 struct vfpf_start_rxq_tlv *req;
2147 mbx->offset = (u8 *)mbx->reply_virt;
2149 /* Taking a bigger struct instead of adding a TLV to list was a
2150 * mistake, but one which we're now stuck with, as some older
2151 * clients assume the size of the previous response.
2154 length = sizeof(*p_tlv);
2156 length = sizeof(struct pfvf_def_resp_tlv);
2158 p_tlv = ecore_add_tlv(&mbx->offset, CHANNEL_TLV_START_RXQ, length);
2159 ecore_add_tlv(&mbx->offset, CHANNEL_TLV_LIST_END,
2160 sizeof(struct channel_list_end_tlv));
2162 /* Update the TLV with the response */
2163 if ((status == PFVF_STATUS_SUCCESS) && !b_legacy) {
2164 req = &mbx->req_virt->start_rxq;
2165 p_tlv->offset = PXP_VF_BAR0_START_MSDM_ZONE_B +
2166 OFFSETOF(struct mstorm_vf_zone,
2167 non_trigger.eth_rx_queue_producers) +
2168 sizeof(struct eth_rx_prod_data) * req->rx_qid;
2171 ecore_iov_send_response(p_hwfn, p_ptt, vf, length, status);
2174 static u8 ecore_iov_vf_mbx_qid(struct ecore_hwfn *p_hwfn,
2175 struct ecore_vf_info *p_vf, bool b_is_tx)
2177 struct ecore_iov_vf_mbx *p_mbx = &p_vf->vf_mbx;
2178 struct vfpf_qid_tlv *p_qid_tlv;
2180 /* Search for the qid if the VF published if its going to provide it */
2181 if (!(p_vf->acquire.vfdev_info.capabilities &
2182 VFPF_ACQUIRE_CAP_QUEUE_QIDS)) {
2184 return ECORE_IOV_LEGACY_QID_TX;
2186 return ECORE_IOV_LEGACY_QID_RX;
2189 p_qid_tlv = (struct vfpf_qid_tlv *)
2190 ecore_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt,
2192 if (p_qid_tlv == OSAL_NULL) {
2193 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2194 "VF[%2x]: Failed to provide qid\n",
2195 p_vf->relative_vf_id);
2197 return ECORE_IOV_QID_INVALID;
2200 if (p_qid_tlv->qid >= MAX_QUEUES_PER_QZONE) {
2201 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2202 "VF[%02x]: Provided qid out-of-bounds %02x\n",
2203 p_vf->relative_vf_id, p_qid_tlv->qid);
2204 return ECORE_IOV_QID_INVALID;
2207 return p_qid_tlv->qid;
2210 static void ecore_iov_vf_mbx_start_rxq(struct ecore_hwfn *p_hwfn,
2211 struct ecore_ptt *p_ptt,
2212 struct ecore_vf_info *vf)
2214 struct ecore_queue_start_common_params params;
2215 struct ecore_queue_cid_vf_params vf_params;
2216 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
2217 u8 status = PFVF_STATUS_NO_RESOURCE;
2218 u8 qid_usage_idx, vf_legacy = 0;
2219 struct ecore_vf_queue *p_queue;
2220 struct vfpf_start_rxq_tlv *req;
2221 struct ecore_queue_cid *p_cid;
2222 struct ecore_sb_info sb_dummy;
2223 enum _ecore_status_t rc;
2225 req = &mbx->req_virt->start_rxq;
2227 if (!ecore_iov_validate_rxq(p_hwfn, vf, req->rx_qid,
2228 ECORE_IOV_VALIDATE_Q_DISABLE) ||
2229 !ecore_iov_validate_sb(p_hwfn, vf, req->hw_sb))
2232 qid_usage_idx = ecore_iov_vf_mbx_qid(p_hwfn, vf, false);
2233 if (qid_usage_idx == ECORE_IOV_QID_INVALID)
2236 p_queue = &vf->vf_queues[req->rx_qid];
2237 if (p_queue->cids[qid_usage_idx].p_cid)
2240 vf_legacy = ecore_vf_calculate_legacy(vf);
2242 /* Acquire a new queue-cid */
2243 OSAL_MEMSET(¶ms, 0, sizeof(params));
2244 params.queue_id = (u8)p_queue->fw_rx_qid;
2245 params.vport_id = vf->vport_id;
2246 params.stats_id = vf->abs_vf_id + 0x10;
2248 /* Since IGU index is passed via sb_info, construct a dummy one */
2249 OSAL_MEM_ZERO(&sb_dummy, sizeof(sb_dummy));
2250 sb_dummy.igu_sb_id = req->hw_sb;
2251 params.p_sb = &sb_dummy;
2252 params.sb_idx = req->sb_index;
2254 OSAL_MEM_ZERO(&vf_params, sizeof(vf_params));
2255 vf_params.vfid = vf->relative_vf_id;
2256 vf_params.vf_qid = (u8)req->rx_qid;
2257 vf_params.vf_legacy = vf_legacy;
2258 vf_params.qid_usage_idx = qid_usage_idx;
2260 p_cid = ecore_eth_queue_to_cid(p_hwfn, vf->opaque_fid,
2261 ¶ms, &vf_params);
2262 if (p_cid == OSAL_NULL)
2265 /* Legacy VFs have their Producers in a different location, which they
2266 * calculate on their own and clean the producer prior to this.
2268 if (!(vf_legacy & ECORE_QCID_LEGACY_VF_RX_PROD))
2270 GTT_BAR0_MAP_REG_MSDM_RAM +
2271 MSTORM_ETH_VF_PRODS_OFFSET(vf->abs_vf_id, req->rx_qid),
2274 rc = ecore_eth_rxq_start_ramrod(p_hwfn, p_cid,
2279 if (rc != ECORE_SUCCESS) {
2280 status = PFVF_STATUS_FAILURE;
2281 ecore_eth_queue_cid_release(p_hwfn, p_cid);
2283 p_queue->cids[qid_usage_idx].p_cid = p_cid;
2284 p_queue->cids[qid_usage_idx].b_is_tx = false;
2285 status = PFVF_STATUS_SUCCESS;
2286 vf->num_active_rxqs++;
2290 ecore_iov_vf_mbx_start_rxq_resp(p_hwfn, p_ptt, vf, status,
2292 ECORE_QCID_LEGACY_VF_RX_PROD));
2296 ecore_iov_pf_update_tun_response(struct pfvf_update_tunn_param_tlv *p_resp,
2297 struct ecore_tunnel_info *p_tun,
2298 u16 tunn_feature_mask)
2300 p_resp->tunn_feature_mask = tunn_feature_mask;
2301 p_resp->vxlan_mode = p_tun->vxlan.b_mode_enabled;
2302 p_resp->l2geneve_mode = p_tun->l2_geneve.b_mode_enabled;
2303 p_resp->ipgeneve_mode = p_tun->ip_geneve.b_mode_enabled;
2304 p_resp->l2gre_mode = p_tun->l2_gre.b_mode_enabled;
2305 p_resp->ipgre_mode = p_tun->l2_gre.b_mode_enabled;
2306 p_resp->vxlan_clss = p_tun->vxlan.tun_cls;
2307 p_resp->l2gre_clss = p_tun->l2_gre.tun_cls;
2308 p_resp->ipgre_clss = p_tun->ip_gre.tun_cls;
2309 p_resp->l2geneve_clss = p_tun->l2_geneve.tun_cls;
2310 p_resp->ipgeneve_clss = p_tun->ip_geneve.tun_cls;
2311 p_resp->geneve_udp_port = p_tun->geneve_port.port;
2312 p_resp->vxlan_udp_port = p_tun->vxlan_port.port;
2316 __ecore_iov_pf_update_tun_param(struct vfpf_update_tunn_param_tlv *p_req,
2317 struct ecore_tunn_update_type *p_tun,
2318 enum ecore_tunn_mode mask, u8 tun_cls)
2320 if (p_req->tun_mode_update_mask & (1 << mask)) {
2321 p_tun->b_update_mode = true;
2323 if (p_req->tunn_mode & (1 << mask))
2324 p_tun->b_mode_enabled = true;
2327 p_tun->tun_cls = tun_cls;
2331 ecore_iov_pf_update_tun_param(struct vfpf_update_tunn_param_tlv *p_req,
2332 struct ecore_tunn_update_type *p_tun,
2333 struct ecore_tunn_update_udp_port *p_port,
2334 enum ecore_tunn_mode mask,
2335 u8 tun_cls, u8 update_port, u16 port)
2338 p_port->b_update_port = true;
2339 p_port->port = port;
2342 __ecore_iov_pf_update_tun_param(p_req, p_tun, mask, tun_cls);
2346 ecore_iov_pf_validate_tunn_param(struct vfpf_update_tunn_param_tlv *p_req)
2348 bool b_update_requested = false;
2350 if (p_req->tun_mode_update_mask || p_req->update_tun_cls ||
2351 p_req->update_geneve_port || p_req->update_vxlan_port)
2352 b_update_requested = true;
2354 return b_update_requested;
2357 static void ecore_iov_vf_mbx_update_tunn_param(struct ecore_hwfn *p_hwfn,
2358 struct ecore_ptt *p_ptt,
2359 struct ecore_vf_info *p_vf)
2361 struct ecore_tunnel_info *p_tun = &p_hwfn->p_dev->tunnel;
2362 struct ecore_iov_vf_mbx *mbx = &p_vf->vf_mbx;
2363 struct pfvf_update_tunn_param_tlv *p_resp;
2364 struct vfpf_update_tunn_param_tlv *p_req;
2365 enum _ecore_status_t rc = ECORE_SUCCESS;
2366 u8 status = PFVF_STATUS_SUCCESS;
2367 bool b_update_required = false;
2368 struct ecore_tunnel_info tunn;
2369 u16 tunn_feature_mask = 0;
2372 mbx->offset = (u8 *)mbx->reply_virt;
2374 OSAL_MEM_ZERO(&tunn, sizeof(tunn));
2375 p_req = &mbx->req_virt->tunn_param_update;
2377 if (!ecore_iov_pf_validate_tunn_param(p_req)) {
2378 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2379 "No tunnel update requested by VF\n");
2380 status = PFVF_STATUS_FAILURE;
2384 tunn.b_update_rx_cls = p_req->update_tun_cls;
2385 tunn.b_update_tx_cls = p_req->update_tun_cls;
2387 ecore_iov_pf_update_tun_param(p_req, &tunn.vxlan, &tunn.vxlan_port,
2388 ECORE_MODE_VXLAN_TUNN, p_req->vxlan_clss,
2389 p_req->update_vxlan_port,
2391 ecore_iov_pf_update_tun_param(p_req, &tunn.l2_geneve, &tunn.geneve_port,
2392 ECORE_MODE_L2GENEVE_TUNN,
2393 p_req->l2geneve_clss,
2394 p_req->update_geneve_port,
2395 p_req->geneve_port);
2396 __ecore_iov_pf_update_tun_param(p_req, &tunn.ip_geneve,
2397 ECORE_MODE_IPGENEVE_TUNN,
2398 p_req->ipgeneve_clss);
2399 __ecore_iov_pf_update_tun_param(p_req, &tunn.l2_gre,
2400 ECORE_MODE_L2GRE_TUNN,
2402 __ecore_iov_pf_update_tun_param(p_req, &tunn.ip_gre,
2403 ECORE_MODE_IPGRE_TUNN,
2406 /* If PF modifies VF's req then it should
2407 * still return an error in case of partial configuration
2408 * or modified configuration as opposed to requested one.
2410 rc = OSAL_PF_VALIDATE_MODIFY_TUNN_CONFIG(p_hwfn, &tunn_feature_mask,
2411 &b_update_required, &tunn);
2413 if (rc != ECORE_SUCCESS)
2414 status = PFVF_STATUS_FAILURE;
2416 /* If ECORE client is willing to update anything ? */
2417 if (b_update_required) {
2420 rc = ecore_sp_pf_update_tunn_cfg(p_hwfn, p_ptt, &tunn,
2421 ECORE_SPQ_MODE_EBLOCK,
2423 if (rc != ECORE_SUCCESS)
2424 status = PFVF_STATUS_FAILURE;
2426 geneve_port = p_tun->geneve_port.port;
2427 ecore_for_each_vf(p_hwfn, i) {
2428 ecore_iov_bulletin_set_udp_ports(p_hwfn, i,
2429 p_tun->vxlan_port.port,
2435 p_resp = ecore_add_tlv(&mbx->offset,
2436 CHANNEL_TLV_UPDATE_TUNN_PARAM, sizeof(*p_resp));
2438 ecore_iov_pf_update_tun_response(p_resp, p_tun, tunn_feature_mask);
2439 ecore_add_tlv(&mbx->offset, CHANNEL_TLV_LIST_END,
2440 sizeof(struct channel_list_end_tlv));
2442 ecore_iov_send_response(p_hwfn, p_ptt, p_vf, sizeof(*p_resp), status);
2445 static void ecore_iov_vf_mbx_start_txq_resp(struct ecore_hwfn *p_hwfn,
2446 struct ecore_ptt *p_ptt,
2447 struct ecore_vf_info *p_vf,
2451 struct ecore_iov_vf_mbx *mbx = &p_vf->vf_mbx;
2452 struct pfvf_start_queue_resp_tlv *p_tlv;
2453 bool b_legacy = false;
2456 mbx->offset = (u8 *)mbx->reply_virt;
2458 /* Taking a bigger struct instead of adding a TLV to list was a
2459 * mistake, but one which we're now stuck with, as some older
2460 * clients assume the size of the previous response.
2462 if (p_vf->acquire.vfdev_info.eth_fp_hsi_minor ==
2463 ETH_HSI_VER_NO_PKT_LEN_TUNN)
2467 length = sizeof(*p_tlv);
2469 length = sizeof(struct pfvf_def_resp_tlv);
2471 p_tlv = ecore_add_tlv(&mbx->offset, CHANNEL_TLV_START_TXQ, length);
2472 ecore_add_tlv(&mbx->offset, CHANNEL_TLV_LIST_END,
2473 sizeof(struct channel_list_end_tlv));
2475 /* Update the TLV with the response */
2476 if ((status == PFVF_STATUS_SUCCESS) && !b_legacy)
2477 p_tlv->offset = DB_ADDR_VF(cid, DQ_DEMS_LEGACY);
2479 ecore_iov_send_response(p_hwfn, p_ptt, p_vf, length, status);
2482 static void ecore_iov_vf_mbx_start_txq(struct ecore_hwfn *p_hwfn,
2483 struct ecore_ptt *p_ptt,
2484 struct ecore_vf_info *vf)
2486 struct ecore_queue_start_common_params params;
2487 struct ecore_queue_cid_vf_params vf_params;
2488 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
2489 u8 status = PFVF_STATUS_NO_RESOURCE;
2490 struct ecore_vf_queue *p_queue;
2491 struct vfpf_start_txq_tlv *req;
2492 struct ecore_queue_cid *p_cid;
2493 struct ecore_sb_info sb_dummy;
2494 u8 qid_usage_idx, vf_legacy;
2496 enum _ecore_status_t rc;
2499 OSAL_MEMSET(¶ms, 0, sizeof(params));
2500 req = &mbx->req_virt->start_txq;
2502 if (!ecore_iov_validate_txq(p_hwfn, vf, req->tx_qid,
2503 ECORE_IOV_VALIDATE_Q_NA) ||
2504 !ecore_iov_validate_sb(p_hwfn, vf, req->hw_sb))
2507 qid_usage_idx = ecore_iov_vf_mbx_qid(p_hwfn, vf, true);
2508 if (qid_usage_idx == ECORE_IOV_QID_INVALID)
2511 p_queue = &vf->vf_queues[req->tx_qid];
2512 if (p_queue->cids[qid_usage_idx].p_cid)
2515 vf_legacy = ecore_vf_calculate_legacy(vf);
2517 /* Acquire a new queue-cid */
2518 params.queue_id = p_queue->fw_tx_qid;
2519 params.vport_id = vf->vport_id;
2520 params.stats_id = vf->abs_vf_id + 0x10;
2522 /* Since IGU index is passed via sb_info, construct a dummy one */
2523 OSAL_MEM_ZERO(&sb_dummy, sizeof(sb_dummy));
2524 sb_dummy.igu_sb_id = req->hw_sb;
2525 params.p_sb = &sb_dummy;
2526 params.sb_idx = req->sb_index;
2528 OSAL_MEM_ZERO(&vf_params, sizeof(vf_params));
2529 vf_params.vfid = vf->relative_vf_id;
2530 vf_params.vf_qid = (u8)req->tx_qid;
2531 vf_params.vf_legacy = vf_legacy;
2532 vf_params.qid_usage_idx = qid_usage_idx;
2534 p_cid = ecore_eth_queue_to_cid(p_hwfn, vf->opaque_fid,
2535 ¶ms, &vf_params);
2536 if (p_cid == OSAL_NULL)
2539 pq = ecore_get_cm_pq_idx_vf(p_hwfn,
2540 vf->relative_vf_id);
2541 rc = ecore_eth_txq_start_ramrod(p_hwfn, p_cid,
2542 req->pbl_addr, req->pbl_size, pq);
2543 if (rc != ECORE_SUCCESS) {
2544 status = PFVF_STATUS_FAILURE;
2545 ecore_eth_queue_cid_release(p_hwfn, p_cid);
2547 status = PFVF_STATUS_SUCCESS;
2548 p_queue->cids[qid_usage_idx].p_cid = p_cid;
2549 p_queue->cids[qid_usage_idx].b_is_tx = true;
2554 ecore_iov_vf_mbx_start_txq_resp(p_hwfn, p_ptt, vf,
2558 static enum _ecore_status_t ecore_iov_vf_stop_rxqs(struct ecore_hwfn *p_hwfn,
2559 struct ecore_vf_info *vf,
2562 bool cqe_completion)
2564 struct ecore_vf_queue *p_queue;
2565 enum _ecore_status_t rc = ECORE_SUCCESS;
2567 if (!ecore_iov_validate_rxq(p_hwfn, vf, rxq_id,
2568 ECORE_IOV_VALIDATE_Q_NA)) {
2569 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2570 "VF[%d] Tried Closing Rx 0x%04x.%02x which is inactive\n",
2571 vf->relative_vf_id, rxq_id, qid_usage_idx);
2575 p_queue = &vf->vf_queues[rxq_id];
2577 /* We've validated the index and the existence of the active RXQ -
2578 * now we need to make sure that it's using the correct qid.
2580 if (!p_queue->cids[qid_usage_idx].p_cid ||
2581 p_queue->cids[qid_usage_idx].b_is_tx) {
2582 struct ecore_queue_cid *p_cid;
2584 p_cid = ecore_iov_get_vf_rx_queue_cid(p_queue);
2585 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2586 "VF[%d] - Tried Closing Rx 0x%04x.%02x, but Rx is at %04x.%02x\n",
2587 vf->relative_vf_id, rxq_id, qid_usage_idx,
2588 rxq_id, p_cid->qid_usage_idx);
2592 /* Now that we know we have a valid Rx-queue - close it */
2593 rc = ecore_eth_rx_queue_stop(p_hwfn,
2594 p_queue->cids[qid_usage_idx].p_cid,
2595 false, cqe_completion);
2596 if (rc != ECORE_SUCCESS)
2599 p_queue->cids[qid_usage_idx].p_cid = OSAL_NULL;
2600 vf->num_active_rxqs--;
2602 return ECORE_SUCCESS;
2605 static enum _ecore_status_t ecore_iov_vf_stop_txqs(struct ecore_hwfn *p_hwfn,
2606 struct ecore_vf_info *vf,
2610 struct ecore_vf_queue *p_queue;
2611 enum _ecore_status_t rc = ECORE_SUCCESS;
2613 if (!ecore_iov_validate_txq(p_hwfn, vf, txq_id,
2614 ECORE_IOV_VALIDATE_Q_NA))
2617 p_queue = &vf->vf_queues[txq_id];
2618 if (!p_queue->cids[qid_usage_idx].p_cid ||
2619 !p_queue->cids[qid_usage_idx].b_is_tx)
2622 rc = ecore_eth_tx_queue_stop(p_hwfn,
2623 p_queue->cids[qid_usage_idx].p_cid);
2624 if (rc != ECORE_SUCCESS)
2627 p_queue->cids[qid_usage_idx].p_cid = OSAL_NULL;
2628 return ECORE_SUCCESS;
2631 static void ecore_iov_vf_mbx_stop_rxqs(struct ecore_hwfn *p_hwfn,
2632 struct ecore_ptt *p_ptt,
2633 struct ecore_vf_info *vf)
2635 u16 length = sizeof(struct pfvf_def_resp_tlv);
2636 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
2637 u8 status = PFVF_STATUS_FAILURE;
2638 struct vfpf_stop_rxqs_tlv *req;
2640 enum _ecore_status_t rc;
2642 /* Starting with CHANNEL_TLV_QID, it's assumed the 'num_rxqs'
2643 * would be one. Since no older ecore passed multiple queues
2644 * using this API, sanitize on the value.
2646 req = &mbx->req_virt->stop_rxqs;
2647 if (req->num_rxqs != 1) {
2648 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2649 "Odd; VF[%d] tried stopping multiple Rx queues\n",
2650 vf->relative_vf_id);
2651 status = PFVF_STATUS_NOT_SUPPORTED;
2655 /* Find which qid-index is associated with the queue */
2656 qid_usage_idx = ecore_iov_vf_mbx_qid(p_hwfn, vf, false);
2657 if (qid_usage_idx == ECORE_IOV_QID_INVALID)
2660 rc = ecore_iov_vf_stop_rxqs(p_hwfn, vf, req->rx_qid,
2661 qid_usage_idx, req->cqe_completion);
2662 if (rc == ECORE_SUCCESS)
2663 status = PFVF_STATUS_SUCCESS;
2665 ecore_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_STOP_RXQS,
2669 static void ecore_iov_vf_mbx_stop_txqs(struct ecore_hwfn *p_hwfn,
2670 struct ecore_ptt *p_ptt,
2671 struct ecore_vf_info *vf)
2673 u16 length = sizeof(struct pfvf_def_resp_tlv);
2674 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
2675 u8 status = PFVF_STATUS_FAILURE;
2676 struct vfpf_stop_txqs_tlv *req;
2678 enum _ecore_status_t rc;
2680 /* Starting with CHANNEL_TLV_QID, it's assumed the 'num_txqs'
2681 * would be one. Since no older ecore passed multiple queues
2682 * using this API, sanitize on the value.
2684 req = &mbx->req_virt->stop_txqs;
2685 if (req->num_txqs != 1) {
2686 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2687 "Odd; VF[%d] tried stopping multiple Tx queues\n",
2688 vf->relative_vf_id);
2689 status = PFVF_STATUS_NOT_SUPPORTED;
2693 /* Find which qid-index is associated with the queue */
2694 qid_usage_idx = ecore_iov_vf_mbx_qid(p_hwfn, vf, true);
2695 if (qid_usage_idx == ECORE_IOV_QID_INVALID)
2698 rc = ecore_iov_vf_stop_txqs(p_hwfn, vf, req->tx_qid,
2700 if (rc == ECORE_SUCCESS)
2701 status = PFVF_STATUS_SUCCESS;
2704 ecore_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_STOP_TXQS,
2708 static void ecore_iov_vf_mbx_update_rxqs(struct ecore_hwfn *p_hwfn,
2709 struct ecore_ptt *p_ptt,
2710 struct ecore_vf_info *vf)
2712 struct ecore_queue_cid *handlers[ECORE_MAX_VF_CHAINS_PER_PF];
2713 u16 length = sizeof(struct pfvf_def_resp_tlv);
2714 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
2715 struct vfpf_update_rxq_tlv *req;
2716 u8 status = PFVF_STATUS_FAILURE;
2717 u8 complete_event_flg;
2718 u8 complete_cqe_flg;
2720 enum _ecore_status_t rc;
2723 req = &mbx->req_virt->update_rxq;
2724 complete_cqe_flg = !!(req->flags & VFPF_RXQ_UPD_COMPLETE_CQE_FLAG);
2725 complete_event_flg = !!(req->flags & VFPF_RXQ_UPD_COMPLETE_EVENT_FLAG);
2727 qid_usage_idx = ecore_iov_vf_mbx_qid(p_hwfn, vf, false);
2728 if (qid_usage_idx == ECORE_IOV_QID_INVALID)
2731 /* Starting with the addition of CHANNEL_TLV_QID, this API started
2732 * expecting a single queue at a time. Validate this.
2734 if ((vf->acquire.vfdev_info.capabilities &
2735 VFPF_ACQUIRE_CAP_QUEUE_QIDS) &&
2736 req->num_rxqs != 1) {
2737 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2738 "VF[%d] supports QIDs but sends multiple queues\n",
2739 vf->relative_vf_id);
2743 /* Validate inputs - for the legacy case this is still true since
2744 * qid_usage_idx for each Rx queue would be LEGACY_QID_RX.
2746 for (i = req->rx_qid; i < req->rx_qid + req->num_rxqs; i++) {
2747 if (!ecore_iov_validate_rxq(p_hwfn, vf, i,
2748 ECORE_IOV_VALIDATE_Q_NA) ||
2749 !vf->vf_queues[i].cids[qid_usage_idx].p_cid ||
2750 vf->vf_queues[i].cids[qid_usage_idx].b_is_tx) {
2751 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2752 "VF[%d]: Incorrect Rxqs [%04x, %02x]\n",
2753 vf->relative_vf_id, req->rx_qid,
2759 for (i = 0; i < req->num_rxqs; i++) {
2760 u16 qid = req->rx_qid + i;
2762 handlers[i] = vf->vf_queues[qid].cids[qid_usage_idx].p_cid;
2765 rc = ecore_sp_eth_rx_queues_update(p_hwfn, (void **)&handlers,
2769 ECORE_SPQ_MODE_EBLOCK,
2771 if (rc != ECORE_SUCCESS)
2774 status = PFVF_STATUS_SUCCESS;
2776 ecore_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_UPDATE_RXQ,
2780 void *ecore_iov_search_list_tlvs(struct ecore_hwfn *p_hwfn,
2781 void *p_tlvs_list, u16 req_type)
2783 struct channel_tlv *p_tlv = (struct channel_tlv *)p_tlvs_list;
2787 if (!p_tlv->length) {
2788 DP_NOTICE(p_hwfn, true, "Zero length TLV found\n");
2792 if (p_tlv->type == req_type) {
2793 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2794 "Extended tlv type %s, length %d found\n",
2795 ecore_channel_tlvs_string[p_tlv->type],
2800 len += p_tlv->length;
2801 p_tlv = (struct channel_tlv *)((u8 *)p_tlv + p_tlv->length);
2803 if ((len + p_tlv->length) > TLV_BUFFER_SIZE) {
2804 DP_NOTICE(p_hwfn, true,
2805 "TLVs has overrun the buffer size\n");
2808 } while (p_tlv->type != CHANNEL_TLV_LIST_END);
2814 ecore_iov_vp_update_act_param(struct ecore_hwfn *p_hwfn,
2815 struct ecore_sp_vport_update_params *p_data,
2816 struct ecore_iov_vf_mbx *p_mbx, u16 *tlvs_mask)
2818 struct vfpf_vport_update_activate_tlv *p_act_tlv;
2819 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_ACTIVATE;
2821 p_act_tlv = (struct vfpf_vport_update_activate_tlv *)
2822 ecore_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
2826 p_data->update_vport_active_rx_flg = p_act_tlv->update_rx;
2827 p_data->vport_active_rx_flg = p_act_tlv->active_rx;
2828 p_data->update_vport_active_tx_flg = p_act_tlv->update_tx;
2829 p_data->vport_active_tx_flg = p_act_tlv->active_tx;
2830 *tlvs_mask |= 1 << ECORE_IOV_VP_UPDATE_ACTIVATE;
2834 ecore_iov_vp_update_vlan_param(struct ecore_hwfn *p_hwfn,
2835 struct ecore_sp_vport_update_params *p_data,
2836 struct ecore_vf_info *p_vf,
2837 struct ecore_iov_vf_mbx *p_mbx, u16 *tlvs_mask)
2839 struct vfpf_vport_update_vlan_strip_tlv *p_vlan_tlv;
2840 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_VLAN_STRIP;
2842 p_vlan_tlv = (struct vfpf_vport_update_vlan_strip_tlv *)
2843 ecore_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
2847 p_vf->shadow_config.inner_vlan_removal = p_vlan_tlv->remove_vlan;
2849 /* Ignore the VF request if we're forcing a vlan */
2850 if (!(p_vf->configured_features & (1 << VLAN_ADDR_FORCED))) {
2851 p_data->update_inner_vlan_removal_flg = 1;
2852 p_data->inner_vlan_removal_flg = p_vlan_tlv->remove_vlan;
2855 *tlvs_mask |= 1 << ECORE_IOV_VP_UPDATE_VLAN_STRIP;
2859 ecore_iov_vp_update_tx_switch(struct ecore_hwfn *p_hwfn,
2860 struct ecore_sp_vport_update_params *p_data,
2861 struct ecore_iov_vf_mbx *p_mbx, u16 *tlvs_mask)
2863 struct vfpf_vport_update_tx_switch_tlv *p_tx_switch_tlv;
2864 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_TX_SWITCH;
2866 p_tx_switch_tlv = (struct vfpf_vport_update_tx_switch_tlv *)
2867 ecore_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
2868 if (!p_tx_switch_tlv)
2872 if (CHIP_REV_IS_FPGA(p_hwfn->p_dev)) {
2873 DP_NOTICE(p_hwfn, false,
2874 "FPGA: Ignore tx-switching configuration originating"
2880 p_data->update_tx_switching_flg = 1;
2881 p_data->tx_switching_flg = p_tx_switch_tlv->tx_switching;
2882 *tlvs_mask |= 1 << ECORE_IOV_VP_UPDATE_TX_SWITCH;
2886 ecore_iov_vp_update_mcast_bin_param(struct ecore_hwfn *p_hwfn,
2887 struct ecore_sp_vport_update_params *p_data,
2888 struct ecore_iov_vf_mbx *p_mbx,
2891 struct vfpf_vport_update_mcast_bin_tlv *p_mcast_tlv;
2892 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_MCAST;
2894 p_mcast_tlv = (struct vfpf_vport_update_mcast_bin_tlv *)
2895 ecore_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
2899 p_data->update_approx_mcast_flg = 1;
2900 OSAL_MEMCPY(p_data->bins, p_mcast_tlv->bins,
2901 sizeof(unsigned long) *
2902 ETH_MULTICAST_MAC_BINS_IN_REGS);
2903 *tlvs_mask |= 1 << ECORE_IOV_VP_UPDATE_MCAST;
2907 ecore_iov_vp_update_accept_flag(struct ecore_hwfn *p_hwfn,
2908 struct ecore_sp_vport_update_params *p_data,
2909 struct ecore_iov_vf_mbx *p_mbx, u16 *tlvs_mask)
2911 struct ecore_filter_accept_flags *p_flags = &p_data->accept_flags;
2912 struct vfpf_vport_update_accept_param_tlv *p_accept_tlv;
2913 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_ACCEPT_PARAM;
2915 p_accept_tlv = (struct vfpf_vport_update_accept_param_tlv *)
2916 ecore_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
2920 p_flags->update_rx_mode_config = p_accept_tlv->update_rx_mode;
2921 p_flags->rx_accept_filter = p_accept_tlv->rx_accept_filter;
2922 p_flags->update_tx_mode_config = p_accept_tlv->update_tx_mode;
2923 p_flags->tx_accept_filter = p_accept_tlv->tx_accept_filter;
2924 *tlvs_mask |= 1 << ECORE_IOV_VP_UPDATE_ACCEPT_PARAM;
2928 ecore_iov_vp_update_accept_any_vlan(struct ecore_hwfn *p_hwfn,
2929 struct ecore_sp_vport_update_params *p_data,
2930 struct ecore_iov_vf_mbx *p_mbx,
2933 struct vfpf_vport_update_accept_any_vlan_tlv *p_accept_any_vlan;
2934 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_ACCEPT_ANY_VLAN;
2936 p_accept_any_vlan = (struct vfpf_vport_update_accept_any_vlan_tlv *)
2937 ecore_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
2938 if (!p_accept_any_vlan)
2941 p_data->accept_any_vlan = p_accept_any_vlan->accept_any_vlan;
2942 p_data->update_accept_any_vlan_flg =
2943 p_accept_any_vlan->update_accept_any_vlan_flg;
2944 *tlvs_mask |= 1 << ECORE_IOV_VP_UPDATE_ACCEPT_ANY_VLAN;
2948 ecore_iov_vp_update_rss_param(struct ecore_hwfn *p_hwfn,
2949 struct ecore_vf_info *vf,
2950 struct ecore_sp_vport_update_params *p_data,
2951 struct ecore_rss_params *p_rss,
2952 struct ecore_iov_vf_mbx *p_mbx,
2953 u16 *tlvs_mask, u16 *tlvs_accepted)
2955 struct vfpf_vport_update_rss_tlv *p_rss_tlv;
2956 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_RSS;
2957 bool b_reject = false;
2961 p_rss_tlv = (struct vfpf_vport_update_rss_tlv *)
2962 ecore_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
2964 p_data->rss_params = OSAL_NULL;
2968 OSAL_MEMSET(p_rss, 0, sizeof(struct ecore_rss_params));
2970 p_rss->update_rss_config =
2971 !!(p_rss_tlv->update_rss_flags &
2972 VFPF_UPDATE_RSS_CONFIG_FLAG);
2973 p_rss->update_rss_capabilities =
2974 !!(p_rss_tlv->update_rss_flags &
2975 VFPF_UPDATE_RSS_CAPS_FLAG);
2976 p_rss->update_rss_ind_table =
2977 !!(p_rss_tlv->update_rss_flags &
2978 VFPF_UPDATE_RSS_IND_TABLE_FLAG);
2979 p_rss->update_rss_key =
2980 !!(p_rss_tlv->update_rss_flags &
2981 VFPF_UPDATE_RSS_KEY_FLAG);
2983 p_rss->rss_enable = p_rss_tlv->rss_enable;
2984 p_rss->rss_eng_id = vf->rss_eng_id;
2985 p_rss->rss_caps = p_rss_tlv->rss_caps;
2986 p_rss->rss_table_size_log = p_rss_tlv->rss_table_size_log;
2987 OSAL_MEMCPY(p_rss->rss_key, p_rss_tlv->rss_key,
2988 sizeof(p_rss->rss_key));
2990 table_size = OSAL_MIN_T(u16, OSAL_ARRAY_SIZE(p_rss->rss_ind_table),
2991 (1 << p_rss_tlv->rss_table_size_log));
2993 for (i = 0; i < table_size; i++) {
2994 struct ecore_queue_cid *p_cid;
2996 q_idx = p_rss_tlv->rss_ind_table[i];
2997 if (!ecore_iov_validate_rxq(p_hwfn, vf, q_idx,
2998 ECORE_IOV_VALIDATE_Q_ENABLE)) {
2999 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3000 "VF[%d]: Omitting RSS due to wrong queue %04x\n",
3001 vf->relative_vf_id, q_idx);
3006 p_cid = ecore_iov_get_vf_rx_queue_cid(&vf->vf_queues[q_idx]);
3007 p_rss->rss_ind_table[i] = p_cid;
3010 p_data->rss_params = p_rss;
3012 *tlvs_mask |= 1 << ECORE_IOV_VP_UPDATE_RSS;
3014 *tlvs_accepted |= 1 << ECORE_IOV_VP_UPDATE_RSS;
3018 ecore_iov_vp_update_sge_tpa_param(struct ecore_hwfn *p_hwfn,
3019 struct ecore_sp_vport_update_params *p_data,
3020 struct ecore_sge_tpa_params *p_sge_tpa,
3021 struct ecore_iov_vf_mbx *p_mbx,
3024 struct vfpf_vport_update_sge_tpa_tlv *p_sge_tpa_tlv;
3025 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_SGE_TPA;
3027 p_sge_tpa_tlv = (struct vfpf_vport_update_sge_tpa_tlv *)
3028 ecore_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
3030 if (!p_sge_tpa_tlv) {
3031 p_data->sge_tpa_params = OSAL_NULL;
3035 OSAL_MEMSET(p_sge_tpa, 0, sizeof(struct ecore_sge_tpa_params));
3037 p_sge_tpa->update_tpa_en_flg =
3038 !!(p_sge_tpa_tlv->update_sge_tpa_flags & VFPF_UPDATE_TPA_EN_FLAG);
3039 p_sge_tpa->update_tpa_param_flg =
3040 !!(p_sge_tpa_tlv->update_sge_tpa_flags &
3041 VFPF_UPDATE_TPA_PARAM_FLAG);
3043 p_sge_tpa->tpa_ipv4_en_flg =
3044 !!(p_sge_tpa_tlv->sge_tpa_flags & VFPF_TPA_IPV4_EN_FLAG);
3045 p_sge_tpa->tpa_ipv6_en_flg =
3046 !!(p_sge_tpa_tlv->sge_tpa_flags & VFPF_TPA_IPV6_EN_FLAG);
3047 p_sge_tpa->tpa_pkt_split_flg =
3048 !!(p_sge_tpa_tlv->sge_tpa_flags & VFPF_TPA_PKT_SPLIT_FLAG);
3049 p_sge_tpa->tpa_hdr_data_split_flg =
3050 !!(p_sge_tpa_tlv->sge_tpa_flags & VFPF_TPA_HDR_DATA_SPLIT_FLAG);
3051 p_sge_tpa->tpa_gro_consistent_flg =
3052 !!(p_sge_tpa_tlv->sge_tpa_flags & VFPF_TPA_GRO_CONSIST_FLAG);
3054 p_sge_tpa->tpa_max_aggs_num = p_sge_tpa_tlv->tpa_max_aggs_num;
3055 p_sge_tpa->tpa_max_size = p_sge_tpa_tlv->tpa_max_size;
3056 p_sge_tpa->tpa_min_size_to_start = p_sge_tpa_tlv->tpa_min_size_to_start;
3057 p_sge_tpa->tpa_min_size_to_cont = p_sge_tpa_tlv->tpa_min_size_to_cont;
3058 p_sge_tpa->max_buffers_per_cqe = p_sge_tpa_tlv->max_buffers_per_cqe;
3060 p_data->sge_tpa_params = p_sge_tpa;
3062 *tlvs_mask |= 1 << ECORE_IOV_VP_UPDATE_SGE_TPA;
3065 static void ecore_iov_vf_mbx_vport_update(struct ecore_hwfn *p_hwfn,
3066 struct ecore_ptt *p_ptt,
3067 struct ecore_vf_info *vf)
3069 struct ecore_rss_params *p_rss_params = OSAL_NULL;
3070 struct ecore_sp_vport_update_params params;
3071 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
3072 struct ecore_sge_tpa_params sge_tpa_params;
3073 u16 tlvs_mask = 0, tlvs_accepted = 0;
3074 u8 status = PFVF_STATUS_SUCCESS;
3076 enum _ecore_status_t rc;
3078 /* Valiate PF can send such a request */
3079 if (!vf->vport_instance) {
3080 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3081 "No VPORT instance available for VF[%d],"
3082 " failing vport update\n",
3084 status = PFVF_STATUS_FAILURE;
3088 p_rss_params = OSAL_VZALLOC(p_hwfn->p_dev, sizeof(*p_rss_params));
3089 if (p_rss_params == OSAL_NULL) {
3090 status = PFVF_STATUS_FAILURE;
3094 OSAL_MEMSET(¶ms, 0, sizeof(params));
3095 params.opaque_fid = vf->opaque_fid;
3096 params.vport_id = vf->vport_id;
3097 params.rss_params = OSAL_NULL;
3099 /* Search for extended tlvs list and update values
3100 * from VF in struct ecore_sp_vport_update_params.
3102 ecore_iov_vp_update_act_param(p_hwfn, ¶ms, mbx, &tlvs_mask);
3103 ecore_iov_vp_update_vlan_param(p_hwfn, ¶ms, vf, mbx, &tlvs_mask);
3104 ecore_iov_vp_update_tx_switch(p_hwfn, ¶ms, mbx, &tlvs_mask);
3105 ecore_iov_vp_update_mcast_bin_param(p_hwfn, ¶ms, mbx, &tlvs_mask);
3106 ecore_iov_vp_update_accept_flag(p_hwfn, ¶ms, mbx, &tlvs_mask);
3107 ecore_iov_vp_update_accept_any_vlan(p_hwfn, ¶ms, mbx, &tlvs_mask);
3108 ecore_iov_vp_update_sge_tpa_param(p_hwfn, ¶ms,
3109 &sge_tpa_params, mbx, &tlvs_mask);
3111 tlvs_accepted = tlvs_mask;
3113 /* Some of the extended TLVs need to be validated first; In that case,
3114 * they can update the mask without updating the accepted [so that
3115 * PF could communicate to VF it has rejected request].
3117 ecore_iov_vp_update_rss_param(p_hwfn, vf, ¶ms, p_rss_params,
3118 mbx, &tlvs_mask, &tlvs_accepted);
3120 /* Just log a message if there is no single extended tlv in buffer.
3121 * When all features of vport update ramrod would be requested by VF
3122 * as extended TLVs in buffer then an error can be returned in response
3123 * if there is no extended TLV present in buffer.
3125 if (OSAL_IOV_VF_VPORT_UPDATE(p_hwfn, vf->relative_vf_id,
3126 ¶ms, &tlvs_accepted) !=
3129 status = PFVF_STATUS_NOT_SUPPORTED;
3133 if (!tlvs_accepted) {
3135 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3136 "Upper-layer prevents said VF"
3137 " configuration\n");
3139 DP_NOTICE(p_hwfn, true,
3140 "No feature tlvs found for vport update\n");
3141 status = PFVF_STATUS_NOT_SUPPORTED;
3145 rc = ecore_sp_vport_update(p_hwfn, ¶ms, ECORE_SPQ_MODE_EBLOCK,
3149 status = PFVF_STATUS_FAILURE;
3152 OSAL_VFREE(p_hwfn->p_dev, p_rss_params);
3153 length = ecore_iov_prep_vp_update_resp_tlvs(p_hwfn, vf, mbx, status,
3154 tlvs_mask, tlvs_accepted);
3155 ecore_iov_send_response(p_hwfn, p_ptt, vf, length, status);
3158 static enum _ecore_status_t
3159 ecore_iov_vf_update_vlan_shadow(struct ecore_hwfn *p_hwfn,
3160 struct ecore_vf_info *p_vf,
3161 struct ecore_filter_ucast *p_params)
3165 /* First remove entries and then add new ones */
3166 if (p_params->opcode == ECORE_FILTER_REMOVE) {
3167 for (i = 0; i < ECORE_ETH_VF_NUM_VLAN_FILTERS + 1; i++)
3168 if (p_vf->shadow_config.vlans[i].used &&
3169 p_vf->shadow_config.vlans[i].vid ==
3171 p_vf->shadow_config.vlans[i].used = false;
3174 if (i == ECORE_ETH_VF_NUM_VLAN_FILTERS + 1) {
3175 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3176 "VF [%d] - Tries to remove a non-existing"
3178 p_vf->relative_vf_id);
3181 } else if (p_params->opcode == ECORE_FILTER_REPLACE ||
3182 p_params->opcode == ECORE_FILTER_FLUSH) {
3183 for (i = 0; i < ECORE_ETH_VF_NUM_VLAN_FILTERS + 1; i++)
3184 p_vf->shadow_config.vlans[i].used = false;
3187 /* In forced mode, we're willing to remove entries - but we don't add
3190 if (p_vf->bulletin.p_virt->valid_bitmap & (1 << VLAN_ADDR_FORCED))
3191 return ECORE_SUCCESS;
3193 if (p_params->opcode == ECORE_FILTER_ADD ||
3194 p_params->opcode == ECORE_FILTER_REPLACE) {
3195 for (i = 0; i < ECORE_ETH_VF_NUM_VLAN_FILTERS + 1; i++) {
3196 if (p_vf->shadow_config.vlans[i].used)
3199 p_vf->shadow_config.vlans[i].used = true;
3200 p_vf->shadow_config.vlans[i].vid = p_params->vlan;
3204 if (i == ECORE_ETH_VF_NUM_VLAN_FILTERS + 1) {
3205 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3206 "VF [%d] - Tries to configure more than %d"
3208 p_vf->relative_vf_id,
3209 ECORE_ETH_VF_NUM_VLAN_FILTERS + 1);
3214 return ECORE_SUCCESS;
3217 static enum _ecore_status_t
3218 ecore_iov_vf_update_mac_shadow(struct ecore_hwfn *p_hwfn,
3219 struct ecore_vf_info *p_vf,
3220 struct ecore_filter_ucast *p_params)
3222 char empty_mac[ETH_ALEN];
3225 OSAL_MEM_ZERO(empty_mac, ETH_ALEN);
3227 /* If we're in forced-mode, we don't allow any change */
3228 /* TODO - this would change if we were ever to implement logic for
3229 * removing a forced MAC altogether [in which case, like for vlans,
3230 * we should be able to re-trace previous configuration.
3232 if (p_vf->bulletin.p_virt->valid_bitmap & (1 << MAC_ADDR_FORCED))
3233 return ECORE_SUCCESS;
3235 /* First remove entries and then add new ones */
3236 if (p_params->opcode == ECORE_FILTER_REMOVE) {
3237 for (i = 0; i < ECORE_ETH_VF_NUM_MAC_FILTERS; i++) {
3238 if (!OSAL_MEMCMP(p_vf->shadow_config.macs[i],
3239 p_params->mac, ETH_ALEN)) {
3240 OSAL_MEM_ZERO(p_vf->shadow_config.macs[i],
3246 if (i == ECORE_ETH_VF_NUM_MAC_FILTERS) {
3247 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3248 "MAC isn't configured\n");
3251 } else if (p_params->opcode == ECORE_FILTER_REPLACE ||
3252 p_params->opcode == ECORE_FILTER_FLUSH) {
3253 for (i = 0; i < ECORE_ETH_VF_NUM_MAC_FILTERS; i++)
3254 OSAL_MEM_ZERO(p_vf->shadow_config.macs[i], ETH_ALEN);
3257 /* List the new MAC address */
3258 if (p_params->opcode != ECORE_FILTER_ADD &&
3259 p_params->opcode != ECORE_FILTER_REPLACE)
3260 return ECORE_SUCCESS;
3262 for (i = 0; i < ECORE_ETH_VF_NUM_MAC_FILTERS; i++) {
3263 if (!OSAL_MEMCMP(p_vf->shadow_config.macs[i],
3264 empty_mac, ETH_ALEN)) {
3265 OSAL_MEMCPY(p_vf->shadow_config.macs[i],
3266 p_params->mac, ETH_ALEN);
3267 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3268 "Added MAC at %d entry in shadow\n", i);
3273 if (i == ECORE_ETH_VF_NUM_MAC_FILTERS) {
3274 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3275 "No available place for MAC\n");
3279 return ECORE_SUCCESS;
3282 static enum _ecore_status_t
3283 ecore_iov_vf_update_unicast_shadow(struct ecore_hwfn *p_hwfn,
3284 struct ecore_vf_info *p_vf,
3285 struct ecore_filter_ucast *p_params)
3287 enum _ecore_status_t rc = ECORE_SUCCESS;
3289 if (p_params->type == ECORE_FILTER_MAC) {
3290 rc = ecore_iov_vf_update_mac_shadow(p_hwfn, p_vf, p_params);
3291 if (rc != ECORE_SUCCESS)
3295 if (p_params->type == ECORE_FILTER_VLAN)
3296 rc = ecore_iov_vf_update_vlan_shadow(p_hwfn, p_vf, p_params);
3301 static void ecore_iov_vf_mbx_ucast_filter(struct ecore_hwfn *p_hwfn,
3302 struct ecore_ptt *p_ptt,
3303 struct ecore_vf_info *vf)
3305 struct ecore_bulletin_content *p_bulletin = vf->bulletin.p_virt;
3306 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
3307 struct vfpf_ucast_filter_tlv *req;
3308 u8 status = PFVF_STATUS_SUCCESS;
3309 struct ecore_filter_ucast params;
3310 enum _ecore_status_t rc;
3312 /* Prepare the unicast filter params */
3313 OSAL_MEMSET(¶ms, 0, sizeof(struct ecore_filter_ucast));
3314 req = &mbx->req_virt->ucast_filter;
3315 params.opcode = (enum ecore_filter_opcode)req->opcode;
3316 params.type = (enum ecore_filter_ucast_type)req->type;
3318 /* @@@TBD - We might need logic on HV side in determining this */
3319 params.is_rx_filter = 1;
3320 params.is_tx_filter = 1;
3321 params.vport_to_remove_from = vf->vport_id;
3322 params.vport_to_add_to = vf->vport_id;
3323 OSAL_MEMCPY(params.mac, req->mac, ETH_ALEN);
3324 params.vlan = req->vlan;
3326 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3327 "VF[%d]: opcode 0x%02x type 0x%02x [%s %s] [vport 0x%02x]"
3328 " MAC %02x:%02x:%02x:%02x:%02x:%02x, vlan 0x%04x\n",
3329 vf->abs_vf_id, params.opcode, params.type,
3330 params.is_rx_filter ? "RX" : "",
3331 params.is_tx_filter ? "TX" : "",
3332 params.vport_to_add_to,
3333 params.mac[0], params.mac[1], params.mac[2],
3334 params.mac[3], params.mac[4], params.mac[5], params.vlan);
3336 if (!vf->vport_instance) {
3337 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3338 "No VPORT instance available for VF[%d],"
3339 " failing ucast MAC configuration\n",
3341 status = PFVF_STATUS_FAILURE;
3345 /* Update shadow copy of the VF configuration */
3346 if (ecore_iov_vf_update_unicast_shadow(p_hwfn, vf, ¶ms) !=
3348 status = PFVF_STATUS_FAILURE;
3352 /* Determine if the unicast filtering is acceptible by PF */
3353 if ((p_bulletin->valid_bitmap & (1 << VLAN_ADDR_FORCED)) &&
3354 (params.type == ECORE_FILTER_VLAN ||
3355 params.type == ECORE_FILTER_MAC_VLAN)) {
3356 /* Once VLAN is forced or PVID is set, do not allow
3357 * to add/replace any further VLANs.
3359 if (params.opcode == ECORE_FILTER_ADD ||
3360 params.opcode == ECORE_FILTER_REPLACE)
3361 status = PFVF_STATUS_FORCED;
3365 if ((p_bulletin->valid_bitmap & (1 << MAC_ADDR_FORCED)) &&
3366 (params.type == ECORE_FILTER_MAC ||
3367 params.type == ECORE_FILTER_MAC_VLAN)) {
3368 if (OSAL_MEMCMP(p_bulletin->mac, params.mac, ETH_ALEN) ||
3369 (params.opcode != ECORE_FILTER_ADD &&
3370 params.opcode != ECORE_FILTER_REPLACE))
3371 status = PFVF_STATUS_FORCED;
3375 rc = OSAL_IOV_CHK_UCAST(p_hwfn, vf->relative_vf_id, ¶ms);
3376 if (rc == ECORE_EXISTS) {
3378 } else if (rc == ECORE_INVAL) {
3379 status = PFVF_STATUS_FAILURE;
3383 rc = ecore_sp_eth_filter_ucast(p_hwfn, vf->opaque_fid, ¶ms,
3384 ECORE_SPQ_MODE_CB, OSAL_NULL);
3386 status = PFVF_STATUS_FAILURE;
3389 ecore_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_UCAST_FILTER,
3390 sizeof(struct pfvf_def_resp_tlv), status);
3393 static void ecore_iov_vf_mbx_int_cleanup(struct ecore_hwfn *p_hwfn,
3394 struct ecore_ptt *p_ptt,
3395 struct ecore_vf_info *vf)
3400 for (i = 0; i < vf->num_sbs; i++)
3401 ecore_int_igu_init_pure_rt_single(p_hwfn, p_ptt,
3403 vf->opaque_fid, false);
3405 ecore_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_INT_CLEANUP,
3406 sizeof(struct pfvf_def_resp_tlv),
3407 PFVF_STATUS_SUCCESS);
3410 static void ecore_iov_vf_mbx_close(struct ecore_hwfn *p_hwfn,
3411 struct ecore_ptt *p_ptt,
3412 struct ecore_vf_info *vf)
3414 u16 length = sizeof(struct pfvf_def_resp_tlv);
3415 u8 status = PFVF_STATUS_SUCCESS;
3417 /* Disable Interrupts for VF */
3418 ecore_iov_vf_igu_set_int(p_hwfn, p_ptt, vf, 0);
3420 /* Reset Permission table */
3421 ecore_iov_config_perm_table(p_hwfn, p_ptt, vf, 0);
3423 ecore_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_CLOSE,
3427 static void ecore_iov_vf_mbx_release(struct ecore_hwfn *p_hwfn,
3428 struct ecore_ptt *p_ptt,
3429 struct ecore_vf_info *p_vf)
3431 u16 length = sizeof(struct pfvf_def_resp_tlv);
3432 u8 status = PFVF_STATUS_SUCCESS;
3433 enum _ecore_status_t rc = ECORE_SUCCESS;
3435 ecore_iov_vf_cleanup(p_hwfn, p_vf);
3437 if (p_vf->state != VF_STOPPED && p_vf->state != VF_FREE) {
3438 /* Stopping the VF */
3439 rc = ecore_sp_vf_stop(p_hwfn, p_vf->concrete_fid,
3442 if (rc != ECORE_SUCCESS) {
3443 DP_ERR(p_hwfn, "ecore_sp_vf_stop returned error %d\n",
3445 status = PFVF_STATUS_FAILURE;
3448 p_vf->state = VF_STOPPED;
3451 ecore_iov_prepare_resp(p_hwfn, p_ptt, p_vf, CHANNEL_TLV_RELEASE,
3455 static void ecore_iov_vf_pf_set_coalesce(struct ecore_hwfn *p_hwfn,
3456 struct ecore_ptt *p_ptt,
3457 struct ecore_vf_info *vf)
3459 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
3460 enum _ecore_status_t rc = ECORE_SUCCESS;
3461 struct vfpf_update_coalesce *req;
3462 u8 status = PFVF_STATUS_FAILURE;
3463 struct ecore_queue_cid *p_cid;
3464 u16 rx_coal, tx_coal;
3468 req = &mbx->req_virt->update_coalesce;
3470 rx_coal = req->rx_coal;
3471 tx_coal = req->tx_coal;
3474 if (!ecore_iov_validate_rxq(p_hwfn, vf, qid,
3475 ECORE_IOV_VALIDATE_Q_ENABLE) &&
3477 DP_ERR(p_hwfn, "VF[%d]: Invalid Rx queue_id = %d\n",
3478 vf->abs_vf_id, qid);
3482 if (!ecore_iov_validate_txq(p_hwfn, vf, qid,
3483 ECORE_IOV_VALIDATE_Q_ENABLE) &&
3485 DP_ERR(p_hwfn, "VF[%d]: Invalid Tx queue_id = %d\n",
3486 vf->abs_vf_id, qid);
3490 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3491 "VF[%d]: Setting coalesce for VF rx_coal = %d, tx_coal = %d at queue = %d\n",
3492 vf->abs_vf_id, rx_coal, tx_coal, qid);
3495 p_cid = ecore_iov_get_vf_rx_queue_cid(&vf->vf_queues[qid]);
3497 rc = ecore_set_rxq_coalesce(p_hwfn, p_ptt, rx_coal, p_cid);
3498 if (rc != ECORE_SUCCESS) {
3499 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3500 "VF[%d]: Unable to set rx queue = %d coalesce\n",
3501 vf->abs_vf_id, vf->vf_queues[qid].fw_rx_qid);
3504 vf->rx_coal = rx_coal;
3507 /* TODO - in future, it might be possible to pass this in a per-cid
3508 * granularity. For now, do this for all Tx queues.
3511 struct ecore_vf_queue *p_queue = &vf->vf_queues[qid];
3513 for (i = 0; i < MAX_QUEUES_PER_QZONE; i++) {
3514 if (p_queue->cids[i].p_cid == OSAL_NULL)
3517 if (!p_queue->cids[i].b_is_tx)
3520 rc = ecore_set_txq_coalesce(p_hwfn, p_ptt, tx_coal,
3521 p_queue->cids[i].p_cid);
3522 if (rc != ECORE_SUCCESS) {
3523 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3524 "VF[%d]: Unable to set tx queue coalesce\n",
3529 vf->tx_coal = tx_coal;
3532 status = PFVF_STATUS_SUCCESS;
3534 ecore_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_COALESCE_UPDATE,
3535 sizeof(struct pfvf_def_resp_tlv), status);
3538 enum _ecore_status_t
3539 ecore_iov_pf_configure_vf_queue_coalesce(struct ecore_hwfn *p_hwfn,
3540 u16 rx_coal, u16 tx_coal,
3543 struct ecore_queue_cid *p_cid;
3544 struct ecore_vf_info *vf;
3545 struct ecore_ptt *p_ptt;
3548 if (!ecore_iov_is_valid_vfid(p_hwfn, vf_id, true, true)) {
3549 DP_NOTICE(p_hwfn, true,
3550 "VF[%d] - Can not set coalescing: VF is not active\n",
3555 vf = &p_hwfn->pf_iov_info->vfs_array[vf_id];
3556 p_ptt = ecore_ptt_acquire(p_hwfn);
3560 if (!ecore_iov_validate_rxq(p_hwfn, vf, qid,
3561 ECORE_IOV_VALIDATE_Q_ENABLE) &&
3563 DP_ERR(p_hwfn, "VF[%d]: Invalid Rx queue_id = %d\n",
3564 vf->abs_vf_id, qid);
3568 if (!ecore_iov_validate_txq(p_hwfn, vf, qid,
3569 ECORE_IOV_VALIDATE_Q_ENABLE) &&
3571 DP_ERR(p_hwfn, "VF[%d]: Invalid Tx queue_id = %d\n",
3572 vf->abs_vf_id, qid);
3576 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3577 "VF[%d]: Setting coalesce for VF rx_coal = %d, tx_coal = %d at queue = %d\n",
3578 vf->abs_vf_id, rx_coal, tx_coal, qid);
3581 p_cid = ecore_iov_get_vf_rx_queue_cid(&vf->vf_queues[qid]);
3583 rc = ecore_set_rxq_coalesce(p_hwfn, p_ptt, rx_coal, p_cid);
3584 if (rc != ECORE_SUCCESS) {
3585 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3586 "VF[%d]: Unable to set rx queue = %d coalesce\n",
3587 vf->abs_vf_id, vf->vf_queues[qid].fw_rx_qid);
3590 vf->rx_coal = rx_coal;
3593 /* TODO - in future, it might be possible to pass this in a per-cid
3594 * granularity. For now, do this for all Tx queues.
3597 struct ecore_vf_queue *p_queue = &vf->vf_queues[qid];
3599 for (i = 0; i < MAX_QUEUES_PER_QZONE; i++) {
3600 if (p_queue->cids[i].p_cid == OSAL_NULL)
3603 if (!p_queue->cids[i].b_is_tx)
3606 rc = ecore_set_txq_coalesce(p_hwfn, p_ptt, tx_coal,
3607 p_queue->cids[i].p_cid);
3608 if (rc != ECORE_SUCCESS) {
3609 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3610 "VF[%d]: Unable to set tx queue coalesce\n",
3615 vf->tx_coal = tx_coal;
3619 ecore_ptt_release(p_hwfn, p_ptt);
3624 static enum _ecore_status_t
3625 ecore_iov_vf_flr_poll_dorq(struct ecore_hwfn *p_hwfn,
3626 struct ecore_vf_info *p_vf, struct ecore_ptt *p_ptt)
3631 ecore_fid_pretend(p_hwfn, p_ptt, (u16)p_vf->concrete_fid);
3633 for (cnt = 0; cnt < 50; cnt++) {
3634 val = ecore_rd(p_hwfn, p_ptt, DORQ_REG_VF_USAGE_CNT);
3639 ecore_fid_pretend(p_hwfn, p_ptt, (u16)p_hwfn->hw_info.concrete_fid);
3643 "VF[%d] - dorq failed to cleanup [usage 0x%08x]\n",
3644 p_vf->abs_vf_id, val);
3645 return ECORE_TIMEOUT;
3648 return ECORE_SUCCESS;
3651 static enum _ecore_status_t
3652 ecore_iov_vf_flr_poll_pbf(struct ecore_hwfn *p_hwfn,
3653 struct ecore_vf_info *p_vf, struct ecore_ptt *p_ptt)
3655 u32 cons[MAX_NUM_VOQS], distance[MAX_NUM_VOQS];
3658 /* Read initial consumers & producers */
3659 for (i = 0; i < MAX_NUM_VOQS; i++) {
3662 cons[i] = ecore_rd(p_hwfn, p_ptt,
3663 PBF_REG_NUM_BLOCKS_ALLOCATED_CONS_VOQ0 +
3665 prod = ecore_rd(p_hwfn, p_ptt,
3666 PBF_REG_NUM_BLOCKS_ALLOCATED_PROD_VOQ0 +
3668 distance[i] = prod - cons[i];
3671 /* Wait for consumers to pass the producers */
3673 for (cnt = 0; cnt < 50; cnt++) {
3674 for (; i < MAX_NUM_VOQS; i++) {
3677 tmp = ecore_rd(p_hwfn, p_ptt,
3678 PBF_REG_NUM_BLOCKS_ALLOCATED_CONS_VOQ0 +
3680 if (distance[i] > tmp - cons[i])
3684 if (i == MAX_NUM_VOQS)
3691 DP_ERR(p_hwfn, "VF[%d] - pbf polling failed on VOQ %d\n",
3692 p_vf->abs_vf_id, i);
3693 return ECORE_TIMEOUT;
3696 return ECORE_SUCCESS;
3699 static enum _ecore_status_t ecore_iov_vf_flr_poll(struct ecore_hwfn *p_hwfn,
3700 struct ecore_vf_info *p_vf,
3701 struct ecore_ptt *p_ptt)
3703 enum _ecore_status_t rc;
3705 /* TODO - add SRC and TM polling once we add storage IOV */
3707 rc = ecore_iov_vf_flr_poll_dorq(p_hwfn, p_vf, p_ptt);
3711 rc = ecore_iov_vf_flr_poll_pbf(p_hwfn, p_vf, p_ptt);
3715 return ECORE_SUCCESS;
3718 static enum _ecore_status_t
3719 ecore_iov_execute_vf_flr_cleanup(struct ecore_hwfn *p_hwfn,
3720 struct ecore_ptt *p_ptt,
3721 u16 rel_vf_id, u32 *ack_vfs)
3723 struct ecore_vf_info *p_vf;
3724 enum _ecore_status_t rc = ECORE_SUCCESS;
3726 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, false);
3728 return ECORE_SUCCESS;
3730 if (p_hwfn->pf_iov_info->pending_flr[rel_vf_id / 64] &
3731 (1ULL << (rel_vf_id % 64))) {
3732 u16 vfid = p_vf->abs_vf_id;
3734 /* TODO - should we lock channel? */
3736 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3737 "VF[%d] - Handling FLR\n", vfid);
3739 ecore_iov_vf_cleanup(p_hwfn, p_vf);
3741 /* If VF isn't active, no need for anything but SW */
3745 /* TODO - what to do in case of failure? */
3746 rc = ecore_iov_vf_flr_poll(p_hwfn, p_vf, p_ptt);
3747 if (rc != ECORE_SUCCESS)
3750 rc = ecore_final_cleanup(p_hwfn, p_ptt, vfid, true);
3752 /* TODO - what's now? What a mess.... */
3753 DP_ERR(p_hwfn, "Failed handle FLR of VF[%d]\n", vfid);
3757 /* Workaround to make VF-PF channel ready, as FW
3758 * doesn't do that as a part of FLR.
3761 GTT_BAR0_MAP_REG_USDM_RAM +
3762 USTORM_VF_PF_CHANNEL_READY_OFFSET(vfid), 1);
3764 /* VF_STOPPED has to be set only after final cleanup
3765 * but prior to re-enabling the VF.
3767 p_vf->state = VF_STOPPED;
3769 rc = ecore_iov_enable_vf_access(p_hwfn, p_ptt, p_vf);
3771 /* TODO - again, a mess... */
3772 DP_ERR(p_hwfn, "Failed to re-enable VF[%d] acces\n",
3777 /* Mark VF for ack and clean pending state */
3778 if (p_vf->state == VF_RESET)
3779 p_vf->state = VF_STOPPED;
3780 ack_vfs[vfid / 32] |= (1 << (vfid % 32));
3781 p_hwfn->pf_iov_info->pending_flr[rel_vf_id / 64] &=
3782 ~(1ULL << (rel_vf_id % 64));
3783 p_vf->vf_mbx.b_pending_msg = false;
3789 enum _ecore_status_t ecore_iov_vf_flr_cleanup(struct ecore_hwfn *p_hwfn,
3790 struct ecore_ptt *p_ptt)
3792 u32 ack_vfs[VF_MAX_STATIC / 32];
3793 enum _ecore_status_t rc = ECORE_SUCCESS;
3796 OSAL_MEMSET(ack_vfs, 0, sizeof(u32) * (VF_MAX_STATIC / 32));
3798 /* Since BRB <-> PRS interface can't be tested as part of the flr
3799 * polling due to HW limitations, simply sleep a bit. And since
3800 * there's no need to wait per-vf, do it before looping.
3804 for (i = 0; i < p_hwfn->p_dev->p_iov_info->total_vfs; i++)
3805 ecore_iov_execute_vf_flr_cleanup(p_hwfn, p_ptt, i, ack_vfs);
3807 rc = ecore_mcp_ack_vf_flr(p_hwfn, p_ptt, ack_vfs);
3811 enum _ecore_status_t
3812 ecore_iov_single_vf_flr_cleanup(struct ecore_hwfn *p_hwfn,
3813 struct ecore_ptt *p_ptt, u16 rel_vf_id)
3815 u32 ack_vfs[VF_MAX_STATIC / 32];
3816 enum _ecore_status_t rc = ECORE_SUCCESS;
3818 OSAL_MEMSET(ack_vfs, 0, sizeof(u32) * (VF_MAX_STATIC / 32));
3820 /* Wait instead of polling the BRB <-> PRS interface */
3823 ecore_iov_execute_vf_flr_cleanup(p_hwfn, p_ptt, rel_vf_id, ack_vfs);
3825 rc = ecore_mcp_ack_vf_flr(p_hwfn, p_ptt, ack_vfs);
3829 bool ecore_iov_mark_vf_flr(struct ecore_hwfn *p_hwfn, u32 *p_disabled_vfs)
3834 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV, "Marking FLR-ed VFs\n");
3835 for (i = 0; i < (VF_MAX_STATIC / 32); i++)
3836 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3837 "[%08x,...,%08x]: %08x\n",
3838 i * 32, (i + 1) * 32 - 1, p_disabled_vfs[i]);
3840 if (!p_hwfn->p_dev->p_iov_info) {
3841 DP_NOTICE(p_hwfn, true, "VF flr but no IOV\n");
3846 for (i = 0; i < p_hwfn->p_dev->p_iov_info->total_vfs; i++) {
3847 struct ecore_vf_info *p_vf;
3850 p_vf = ecore_iov_get_vf_info(p_hwfn, i, false);
3854 vfid = p_vf->abs_vf_id;
3855 if ((1 << (vfid % 32)) & p_disabled_vfs[vfid / 32]) {
3856 u64 *p_flr = p_hwfn->pf_iov_info->pending_flr;
3857 u16 rel_vf_id = p_vf->relative_vf_id;
3859 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3860 "VF[%d] [rel %d] got FLR-ed\n",
3863 p_vf->state = VF_RESET;
3865 /* No need to lock here, since pending_flr should
3866 * only change here and before ACKing MFw. Since
3867 * MFW will not trigger an additional attention for
3868 * VF flr until ACKs, we're safe.
3870 p_flr[rel_vf_id / 64] |= 1ULL << (rel_vf_id % 64);
3878 void ecore_iov_get_link(struct ecore_hwfn *p_hwfn,
3880 struct ecore_mcp_link_params *p_params,
3881 struct ecore_mcp_link_state *p_link,
3882 struct ecore_mcp_link_capabilities *p_caps)
3884 struct ecore_vf_info *p_vf = ecore_iov_get_vf_info(p_hwfn, vfid, false);
3885 struct ecore_bulletin_content *p_bulletin;
3890 p_bulletin = p_vf->bulletin.p_virt;
3893 __ecore_vf_get_link_params(p_params, p_bulletin);
3895 __ecore_vf_get_link_state(p_link, p_bulletin);
3897 __ecore_vf_get_link_caps(p_caps, p_bulletin);
3900 void ecore_iov_process_mbx_req(struct ecore_hwfn *p_hwfn,
3901 struct ecore_ptt *p_ptt, int vfid)
3903 struct ecore_iov_vf_mbx *mbx;
3904 struct ecore_vf_info *p_vf;
3906 p_vf = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
3910 mbx = &p_vf->vf_mbx;
3912 /* ecore_iov_process_mbx_request */
3913 #ifndef CONFIG_ECORE_SW_CHANNEL
3914 if (!mbx->b_pending_msg) {
3915 DP_NOTICE(p_hwfn, true,
3916 "VF[%02x]: Trying to process mailbox message when none is pending\n",
3920 mbx->b_pending_msg = false;
3923 mbx->first_tlv = mbx->req_virt->first_tlv;
3925 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3926 "VF[%02x]: Processing mailbox message [type %04x]\n",
3927 p_vf->abs_vf_id, mbx->first_tlv.tl.type);
3929 OSAL_IOV_VF_MSG_TYPE(p_hwfn,
3930 p_vf->relative_vf_id,
3931 mbx->first_tlv.tl.type);
3933 /* Lock the per vf op mutex and note the locker's identity.
3934 * The unlock will take place in mbx response.
3936 ecore_iov_lock_vf_pf_channel(p_hwfn,
3937 p_vf, mbx->first_tlv.tl.type);
3939 /* check if tlv type is known */
3940 if (ecore_iov_tlv_supported(mbx->first_tlv.tl.type) &&
3941 !p_vf->b_malicious) {
3942 /* switch on the opcode */
3943 switch (mbx->first_tlv.tl.type) {
3944 case CHANNEL_TLV_ACQUIRE:
3945 ecore_iov_vf_mbx_acquire(p_hwfn, p_ptt, p_vf);
3947 case CHANNEL_TLV_VPORT_START:
3948 ecore_iov_vf_mbx_start_vport(p_hwfn, p_ptt, p_vf);
3950 case CHANNEL_TLV_VPORT_TEARDOWN:
3951 ecore_iov_vf_mbx_stop_vport(p_hwfn, p_ptt, p_vf);
3953 case CHANNEL_TLV_START_RXQ:
3954 ecore_iov_vf_mbx_start_rxq(p_hwfn, p_ptt, p_vf);
3956 case CHANNEL_TLV_START_TXQ:
3957 ecore_iov_vf_mbx_start_txq(p_hwfn, p_ptt, p_vf);
3959 case CHANNEL_TLV_STOP_RXQS:
3960 ecore_iov_vf_mbx_stop_rxqs(p_hwfn, p_ptt, p_vf);
3962 case CHANNEL_TLV_STOP_TXQS:
3963 ecore_iov_vf_mbx_stop_txqs(p_hwfn, p_ptt, p_vf);
3965 case CHANNEL_TLV_UPDATE_RXQ:
3966 ecore_iov_vf_mbx_update_rxqs(p_hwfn, p_ptt, p_vf);
3968 case CHANNEL_TLV_VPORT_UPDATE:
3969 ecore_iov_vf_mbx_vport_update(p_hwfn, p_ptt, p_vf);
3971 case CHANNEL_TLV_UCAST_FILTER:
3972 ecore_iov_vf_mbx_ucast_filter(p_hwfn, p_ptt, p_vf);
3974 case CHANNEL_TLV_CLOSE:
3975 ecore_iov_vf_mbx_close(p_hwfn, p_ptt, p_vf);
3977 case CHANNEL_TLV_INT_CLEANUP:
3978 ecore_iov_vf_mbx_int_cleanup(p_hwfn, p_ptt, p_vf);
3980 case CHANNEL_TLV_RELEASE:
3981 ecore_iov_vf_mbx_release(p_hwfn, p_ptt, p_vf);
3983 case CHANNEL_TLV_UPDATE_TUNN_PARAM:
3984 ecore_iov_vf_mbx_update_tunn_param(p_hwfn, p_ptt, p_vf);
3986 case CHANNEL_TLV_COALESCE_UPDATE:
3987 ecore_iov_vf_pf_set_coalesce(p_hwfn, p_ptt, p_vf);
3990 } else if (ecore_iov_tlv_supported(mbx->first_tlv.tl.type)) {
3991 /* If we've received a message from a VF we consider malicious
3992 * we ignore the messasge unless it's one for RELEASE, in which
3993 * case we'll let it have the benefit of doubt, allowing the
3994 * next loaded driver to start again.
3996 if (mbx->first_tlv.tl.type == CHANNEL_TLV_RELEASE) {
3997 /* TODO - initiate FLR, remove malicious indication */
3998 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3999 "VF [%02x] - considered malicious, but wanted to RELEASE. TODO\n",
4002 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
4003 "VF [%02x] - considered malicious; Ignoring TLV [%04x]\n",
4004 p_vf->abs_vf_id, mbx->first_tlv.tl.type);
4007 ecore_iov_prepare_resp(p_hwfn, p_ptt, p_vf,
4008 mbx->first_tlv.tl.type,
4009 sizeof(struct pfvf_def_resp_tlv),
4010 PFVF_STATUS_MALICIOUS);
4012 /* unknown TLV - this may belong to a VF driver from the future
4013 * - a version written after this PF driver was written, which
4014 * supports features unknown as of yet. Too bad since we don't
4015 * support them. Or this may be because someone wrote a crappy
4016 * VF driver and is sending garbage over the channel.
4018 DP_NOTICE(p_hwfn, false,
4019 "VF[%02x]: unknown TLV. type %04x length %04x"
4020 " padding %08x reply address %lu\n",
4022 mbx->first_tlv.tl.type,
4023 mbx->first_tlv.tl.length,
4024 mbx->first_tlv.padding,
4025 (unsigned long)mbx->first_tlv.reply_address);
4027 /* Try replying in case reply address matches the acquisition's
4030 if (p_vf->acquire.first_tlv.reply_address &&
4031 (mbx->first_tlv.reply_address ==
4032 p_vf->acquire.first_tlv.reply_address))
4033 ecore_iov_prepare_resp(p_hwfn, p_ptt, p_vf,
4034 mbx->first_tlv.tl.type,
4035 sizeof(struct pfvf_def_resp_tlv),
4036 PFVF_STATUS_NOT_SUPPORTED);
4038 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
4039 "VF[%02x]: Can't respond to TLV -"
4040 " no valid reply address\n",
4044 ecore_iov_unlock_vf_pf_channel(p_hwfn, p_vf,
4045 mbx->first_tlv.tl.type);
4047 #ifdef CONFIG_ECORE_SW_CHANNEL
4048 mbx->sw_mbx.mbx_state = VF_PF_RESPONSE_READY;
4049 mbx->sw_mbx.response_offset = 0;
4053 void ecore_iov_pf_get_pending_events(struct ecore_hwfn *p_hwfn,
4058 OSAL_MEM_ZERO(events, sizeof(u64) * ECORE_VF_ARRAY_LENGTH);
4060 ecore_for_each_vf(p_hwfn, i) {
4061 struct ecore_vf_info *p_vf;
4063 p_vf = &p_hwfn->pf_iov_info->vfs_array[i];
4064 if (p_vf->vf_mbx.b_pending_msg)
4065 events[i / 64] |= 1ULL << (i % 64);
4069 static struct ecore_vf_info *
4070 ecore_sriov_get_vf_from_absid(struct ecore_hwfn *p_hwfn, u16 abs_vfid)
4072 u8 min = (u8)p_hwfn->p_dev->p_iov_info->first_vf_in_pf;
4074 if (!_ecore_iov_pf_sanity_check(p_hwfn, (int)abs_vfid - min, false)) {
4075 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
4076 "Got indication for VF [abs 0x%08x] that cannot be"
4082 return &p_hwfn->pf_iov_info->vfs_array[(u8)abs_vfid - min];
4085 static enum _ecore_status_t ecore_sriov_vfpf_msg(struct ecore_hwfn *p_hwfn,
4087 struct regpair *vf_msg)
4089 struct ecore_vf_info *p_vf = ecore_sriov_get_vf_from_absid(p_hwfn,
4093 return ECORE_SUCCESS;
4095 /* List the physical address of the request so that handler
4096 * could later on copy the message from it.
4098 p_vf->vf_mbx.pending_req = (((u64)vf_msg->hi) << 32) | vf_msg->lo;
4100 p_vf->vf_mbx.b_pending_msg = true;
4102 return OSAL_PF_VF_MSG(p_hwfn, p_vf->relative_vf_id);
4105 static void ecore_sriov_vfpf_malicious(struct ecore_hwfn *p_hwfn,
4106 struct malicious_vf_eqe_data *p_data)
4108 struct ecore_vf_info *p_vf;
4110 p_vf = ecore_sriov_get_vf_from_absid(p_hwfn, p_data->vfId);
4116 "VF [%d] - Malicious behavior [%02x]\n",
4117 p_vf->abs_vf_id, p_data->errId);
4119 p_vf->b_malicious = true;
4121 OSAL_PF_VF_MALICIOUS(p_hwfn, p_vf->relative_vf_id);
4124 enum _ecore_status_t ecore_sriov_eqe_event(struct ecore_hwfn *p_hwfn,
4127 union event_ring_data *data)
4130 case COMMON_EVENT_VF_PF_CHANNEL:
4131 return ecore_sriov_vfpf_msg(p_hwfn, OSAL_LE16_TO_CPU(echo),
4132 &data->vf_pf_channel.msg_addr);
4133 case COMMON_EVENT_VF_FLR:
4134 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
4135 "VF-FLR is still not supported\n");
4136 return ECORE_SUCCESS;
4137 case COMMON_EVENT_MALICIOUS_VF:
4138 ecore_sriov_vfpf_malicious(p_hwfn, &data->malicious_vf);
4139 return ECORE_SUCCESS;
4141 DP_INFO(p_hwfn->p_dev, "Unknown sriov eqe event 0x%02x\n",
4147 bool ecore_iov_is_vf_pending_flr(struct ecore_hwfn *p_hwfn, u16 rel_vf_id)
4149 return !!(p_hwfn->pf_iov_info->pending_flr[rel_vf_id / 64] &
4150 (1ULL << (rel_vf_id % 64)));
4153 u16 ecore_iov_get_next_active_vf(struct ecore_hwfn *p_hwfn, u16 rel_vf_id)
4155 struct ecore_hw_sriov_info *p_iov = p_hwfn->p_dev->p_iov_info;
4161 for (i = rel_vf_id; i < p_iov->total_vfs; i++)
4162 if (ecore_iov_is_valid_vfid(p_hwfn, rel_vf_id, true, false))
4166 return E4_MAX_NUM_VFS;
4169 enum _ecore_status_t ecore_iov_copy_vf_msg(struct ecore_hwfn *p_hwfn,
4170 struct ecore_ptt *ptt, int vfid)
4172 struct ecore_dmae_params params;
4173 struct ecore_vf_info *vf_info;
4175 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4179 OSAL_MEMSET(¶ms, 0, sizeof(struct ecore_dmae_params));
4180 params.flags = ECORE_DMAE_FLAG_VF_SRC | ECORE_DMAE_FLAG_COMPLETION_DST;
4181 params.src_vfid = vf_info->abs_vf_id;
4183 if (ecore_dmae_host2host(p_hwfn, ptt,
4184 vf_info->vf_mbx.pending_req,
4185 vf_info->vf_mbx.req_phys,
4186 sizeof(union vfpf_tlvs) / 4, ¶ms)) {
4187 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
4188 "Failed to copy message from VF 0x%02x\n", vfid);
4193 return ECORE_SUCCESS;
4196 void ecore_iov_bulletin_set_forced_mac(struct ecore_hwfn *p_hwfn,
4199 struct ecore_vf_info *vf_info;
4202 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4204 DP_NOTICE(p_hwfn->p_dev, true,
4205 "Can not set forced MAC, invalid vfid [%d]\n", vfid);
4208 if (vf_info->b_malicious) {
4209 DP_NOTICE(p_hwfn->p_dev, false,
4210 "Can't set forced MAC to malicious VF [%d]\n",
4215 feature = 1 << MAC_ADDR_FORCED;
4216 OSAL_MEMCPY(vf_info->bulletin.p_virt->mac, mac, ETH_ALEN);
4218 vf_info->bulletin.p_virt->valid_bitmap |= feature;
4219 /* Forced MAC will disable MAC_ADDR */
4220 vf_info->bulletin.p_virt->valid_bitmap &=
4221 ~(1 << VFPF_BULLETIN_MAC_ADDR);
4223 ecore_iov_configure_vport_forced(p_hwfn, vf_info, feature);
4226 enum _ecore_status_t ecore_iov_bulletin_set_mac(struct ecore_hwfn *p_hwfn,
4229 struct ecore_vf_info *vf_info;
4232 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4234 DP_NOTICE(p_hwfn->p_dev, true,
4235 "Can not set MAC, invalid vfid [%d]\n", vfid);
4238 if (vf_info->b_malicious) {
4239 DP_NOTICE(p_hwfn->p_dev, false,
4240 "Can't set MAC to malicious VF [%d]\n",
4245 if (vf_info->bulletin.p_virt->valid_bitmap & (1 << MAC_ADDR_FORCED)) {
4246 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
4247 "Can not set MAC, Forced MAC is configured\n");
4251 feature = 1 << VFPF_BULLETIN_MAC_ADDR;
4252 OSAL_MEMCPY(vf_info->bulletin.p_virt->mac, mac, ETH_ALEN);
4254 vf_info->bulletin.p_virt->valid_bitmap |= feature;
4256 return ECORE_SUCCESS;
4259 enum _ecore_status_t
4260 ecore_iov_bulletin_set_forced_untagged_default(struct ecore_hwfn *p_hwfn,
4261 bool b_untagged_only, int vfid)
4263 struct ecore_vf_info *vf_info;
4266 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4268 DP_NOTICE(p_hwfn->p_dev, true,
4269 "Can not set untagged default, invalid vfid [%d]\n",
4273 if (vf_info->b_malicious) {
4274 DP_NOTICE(p_hwfn->p_dev, false,
4275 "Can't set untagged default to malicious VF [%d]\n",
4280 /* Since this is configurable only during vport-start, don't take it
4281 * if we're past that point.
4283 if (vf_info->state == VF_ENABLED) {
4284 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
4285 "Can't support untagged change for vfid[%d] -"
4286 " VF is already active\n",
4291 /* Set configuration; This will later be taken into account during the
4292 * VF initialization.
4294 feature = (1 << VFPF_BULLETIN_UNTAGGED_DEFAULT) |
4295 (1 << VFPF_BULLETIN_UNTAGGED_DEFAULT_FORCED);
4296 vf_info->bulletin.p_virt->valid_bitmap |= feature;
4298 vf_info->bulletin.p_virt->default_only_untagged = b_untagged_only ? 1
4301 return ECORE_SUCCESS;
4304 void ecore_iov_get_vfs_opaque_fid(struct ecore_hwfn *p_hwfn, int vfid,
4307 struct ecore_vf_info *vf_info;
4309 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4313 *opaque_fid = vf_info->opaque_fid;
4316 void ecore_iov_bulletin_set_forced_vlan(struct ecore_hwfn *p_hwfn,
4319 struct ecore_vf_info *vf_info;
4322 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4324 DP_NOTICE(p_hwfn->p_dev, true,
4325 "Can not set forced MAC, invalid vfid [%d]\n",
4329 if (vf_info->b_malicious) {
4330 DP_NOTICE(p_hwfn->p_dev, false,
4331 "Can't set forced vlan to malicious VF [%d]\n",
4336 feature = 1 << VLAN_ADDR_FORCED;
4337 vf_info->bulletin.p_virt->pvid = pvid;
4339 vf_info->bulletin.p_virt->valid_bitmap |= feature;
4341 vf_info->bulletin.p_virt->valid_bitmap &= ~feature;
4343 ecore_iov_configure_vport_forced(p_hwfn, vf_info, feature);
4346 void ecore_iov_bulletin_set_udp_ports(struct ecore_hwfn *p_hwfn,
4347 int vfid, u16 vxlan_port, u16 geneve_port)
4349 struct ecore_vf_info *vf_info;
4351 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4353 DP_NOTICE(p_hwfn->p_dev, true,
4354 "Can not set udp ports, invalid vfid [%d]\n", vfid);
4358 if (vf_info->b_malicious) {
4359 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
4360 "Can not set udp ports to malicious VF [%d]\n",
4365 vf_info->bulletin.p_virt->vxlan_udp_port = vxlan_port;
4366 vf_info->bulletin.p_virt->geneve_udp_port = geneve_port;
4369 bool ecore_iov_vf_has_vport_instance(struct ecore_hwfn *p_hwfn, int vfid)
4371 struct ecore_vf_info *p_vf_info;
4373 p_vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4377 return !!p_vf_info->vport_instance;
4380 bool ecore_iov_is_vf_stopped(struct ecore_hwfn *p_hwfn, int vfid)
4382 struct ecore_vf_info *p_vf_info;
4384 p_vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4388 return p_vf_info->state == VF_STOPPED;
4391 bool ecore_iov_spoofchk_get(struct ecore_hwfn *p_hwfn, int vfid)
4393 struct ecore_vf_info *vf_info;
4395 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4399 return vf_info->spoof_chk;
4402 enum _ecore_status_t ecore_iov_spoofchk_set(struct ecore_hwfn *p_hwfn,
4405 struct ecore_vf_info *vf;
4406 enum _ecore_status_t rc = ECORE_INVAL;
4408 if (!ecore_iov_pf_sanity_check(p_hwfn, vfid)) {
4409 DP_NOTICE(p_hwfn, true,
4410 "SR-IOV sanity check failed, can't set spoofchk\n");
4414 vf = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4418 if (!ecore_iov_vf_has_vport_instance(p_hwfn, vfid)) {
4419 /* After VF VPORT start PF will configure spoof check */
4420 vf->req_spoofchk_val = val;
4425 rc = __ecore_iov_spoofchk_set(p_hwfn, vf, val);
4431 u8 ecore_iov_vf_chains_per_pf(struct ecore_hwfn *p_hwfn)
4433 u8 max_chains_per_vf = p_hwfn->hw_info.max_chains_per_vf;
4435 max_chains_per_vf = (max_chains_per_vf) ? max_chains_per_vf
4436 : ECORE_MAX_VF_CHAINS_PER_PF;
4438 return max_chains_per_vf;
4441 void ecore_iov_get_vf_req_virt_mbx_params(struct ecore_hwfn *p_hwfn,
4443 void **pp_req_virt_addr,
4444 u16 *p_req_virt_size)
4446 struct ecore_vf_info *vf_info =
4447 ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4452 if (pp_req_virt_addr)
4453 *pp_req_virt_addr = vf_info->vf_mbx.req_virt;
4455 if (p_req_virt_size)
4456 *p_req_virt_size = sizeof(*vf_info->vf_mbx.req_virt);
4459 void ecore_iov_get_vf_reply_virt_mbx_params(struct ecore_hwfn *p_hwfn,
4461 void **pp_reply_virt_addr,
4462 u16 *p_reply_virt_size)
4464 struct ecore_vf_info *vf_info =
4465 ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4470 if (pp_reply_virt_addr)
4471 *pp_reply_virt_addr = vf_info->vf_mbx.reply_virt;
4473 if (p_reply_virt_size)
4474 *p_reply_virt_size = sizeof(*vf_info->vf_mbx.reply_virt);
4477 #ifdef CONFIG_ECORE_SW_CHANNEL
4478 struct ecore_iov_sw_mbx *ecore_iov_get_vf_sw_mbx(struct ecore_hwfn *p_hwfn,
4481 struct ecore_vf_info *vf_info =
4482 ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4487 return &vf_info->vf_mbx.sw_mbx;
4491 bool ecore_iov_is_valid_vfpf_msg_length(u32 length)
4493 return (length >= sizeof(struct vfpf_first_tlv) &&
4494 (length <= sizeof(union vfpf_tlvs)));
4497 u32 ecore_iov_pfvf_msg_length(void)
4499 return sizeof(union pfvf_tlvs);
4502 u8 *ecore_iov_bulletin_get_forced_mac(struct ecore_hwfn *p_hwfn, u16 rel_vf_id)
4504 struct ecore_vf_info *p_vf;
4506 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4507 if (!p_vf || !p_vf->bulletin.p_virt)
4510 if (!(p_vf->bulletin.p_virt->valid_bitmap & (1 << MAC_ADDR_FORCED)))
4513 return p_vf->bulletin.p_virt->mac;
4516 u16 ecore_iov_bulletin_get_forced_vlan(struct ecore_hwfn *p_hwfn,
4519 struct ecore_vf_info *p_vf;
4521 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4522 if (!p_vf || !p_vf->bulletin.p_virt)
4525 if (!(p_vf->bulletin.p_virt->valid_bitmap & (1 << VLAN_ADDR_FORCED)))
4528 return p_vf->bulletin.p_virt->pvid;
4531 enum _ecore_status_t ecore_iov_configure_tx_rate(struct ecore_hwfn *p_hwfn,
4532 struct ecore_ptt *p_ptt,
4535 struct ecore_vf_info *vf;
4537 enum _ecore_status_t rc;
4539 vf = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4544 rc = ecore_fw_vport(p_hwfn, vf->vport_id, &abs_vp_id);
4545 if (rc != ECORE_SUCCESS)
4548 return ecore_init_vport_rl(p_hwfn, p_ptt, abs_vp_id, (u32)val);
4551 enum _ecore_status_t ecore_iov_get_vf_stats(struct ecore_hwfn *p_hwfn,
4552 struct ecore_ptt *p_ptt,
4554 struct ecore_eth_stats *p_stats)
4556 struct ecore_vf_info *vf;
4558 vf = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4562 if (vf->state != VF_ENABLED)
4565 __ecore_get_vport_stats(p_hwfn, p_ptt, p_stats,
4566 vf->abs_vf_id + 0x10, false);
4568 return ECORE_SUCCESS;
4571 u8 ecore_iov_get_vf_num_rxqs(struct ecore_hwfn *p_hwfn, u16 rel_vf_id)
4573 struct ecore_vf_info *p_vf;
4575 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4579 return p_vf->num_rxqs;
4582 u8 ecore_iov_get_vf_num_active_rxqs(struct ecore_hwfn *p_hwfn, u16 rel_vf_id)
4584 struct ecore_vf_info *p_vf;
4586 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4590 return p_vf->num_active_rxqs;
4593 void *ecore_iov_get_vf_ctx(struct ecore_hwfn *p_hwfn, u16 rel_vf_id)
4595 struct ecore_vf_info *p_vf;
4597 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4604 u8 ecore_iov_get_vf_num_sbs(struct ecore_hwfn *p_hwfn, u16 rel_vf_id)
4606 struct ecore_vf_info *p_vf;
4608 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4612 return p_vf->num_sbs;
4615 bool ecore_iov_is_vf_wait_for_acquire(struct ecore_hwfn *p_hwfn, u16 rel_vf_id)
4617 struct ecore_vf_info *p_vf;
4619 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4623 return (p_vf->state == VF_FREE);
4626 bool ecore_iov_is_vf_acquired_not_initialized(struct ecore_hwfn *p_hwfn,
4629 struct ecore_vf_info *p_vf;
4631 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4635 return (p_vf->state == VF_ACQUIRED);
4638 bool ecore_iov_is_vf_initialized(struct ecore_hwfn *p_hwfn, u16 rel_vf_id)
4640 struct ecore_vf_info *p_vf;
4642 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4646 return (p_vf->state == VF_ENABLED);
4649 bool ecore_iov_is_vf_started(struct ecore_hwfn *p_hwfn,
4652 struct ecore_vf_info *p_vf;
4654 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4658 return (p_vf->state != VF_FREE && p_vf->state != VF_STOPPED);
4661 enum _ecore_status_t
4662 ecore_iov_get_vf_min_rate(struct ecore_hwfn *p_hwfn, int vfid)
4664 struct ecore_wfq_data *vf_vp_wfq;
4665 struct ecore_vf_info *vf_info;
4667 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4671 vf_vp_wfq = &p_hwfn->qm_info.wfq_data[vf_info->vport_id];
4673 if (vf_vp_wfq->configured)
4674 return vf_vp_wfq->min_speed;