1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright (c) 2016 - 2018 Cavium Inc.
10 #include "ecore_sriov.h"
11 #include "ecore_status.h"
13 #include "ecore_hw_defs.h"
14 #include "ecore_int.h"
15 #include "ecore_hsi_eth.h"
17 #include "ecore_vfpf_if.h"
18 #include "ecore_rt_defs.h"
19 #include "ecore_init_ops.h"
20 #include "ecore_gtt_reg_addr.h"
21 #include "ecore_iro.h"
22 #include "ecore_mcp.h"
23 #include "ecore_cxt.h"
25 #include "ecore_init_fw_funcs.h"
26 #include "ecore_sp_commands.h"
28 static enum _ecore_status_t ecore_sriov_eqe_event(struct ecore_hwfn *p_hwfn,
31 union event_ring_data *data,
34 const char *ecore_channel_tlvs_string[] = {
35 "CHANNEL_TLV_NONE", /* ends tlv sequence */
36 "CHANNEL_TLV_ACQUIRE",
37 "CHANNEL_TLV_VPORT_START",
38 "CHANNEL_TLV_VPORT_UPDATE",
39 "CHANNEL_TLV_VPORT_TEARDOWN",
40 "CHANNEL_TLV_START_RXQ",
41 "CHANNEL_TLV_START_TXQ",
42 "CHANNEL_TLV_STOP_RXQ",
43 "CHANNEL_TLV_STOP_TXQ",
44 "CHANNEL_TLV_UPDATE_RXQ",
45 "CHANNEL_TLV_INT_CLEANUP",
47 "CHANNEL_TLV_RELEASE",
48 "CHANNEL_TLV_LIST_END",
49 "CHANNEL_TLV_UCAST_FILTER",
50 "CHANNEL_TLV_VPORT_UPDATE_ACTIVATE",
51 "CHANNEL_TLV_VPORT_UPDATE_TX_SWITCH",
52 "CHANNEL_TLV_VPORT_UPDATE_VLAN_STRIP",
53 "CHANNEL_TLV_VPORT_UPDATE_MCAST",
54 "CHANNEL_TLV_VPORT_UPDATE_ACCEPT_PARAM",
55 "CHANNEL_TLV_VPORT_UPDATE_RSS",
56 "CHANNEL_TLV_VPORT_UPDATE_ACCEPT_ANY_VLAN",
57 "CHANNEL_TLV_VPORT_UPDATE_SGE_TPA",
58 "CHANNEL_TLV_UPDATE_TUNN_PARAM",
59 "CHANNEL_TLV_COALESCE_UPDATE",
61 "CHANNEL_TLV_COALESCE_READ",
62 "CHANNEL_TLV_BULLETIN_UPDATE_MAC",
63 "CHANNEL_TLV_UPDATE_MTU",
67 static u8 ecore_vf_calculate_legacy(struct ecore_vf_info *p_vf)
71 if (p_vf->acquire.vfdev_info.eth_fp_hsi_minor ==
72 ETH_HSI_VER_NO_PKT_LEN_TUNN)
73 legacy |= ECORE_QCID_LEGACY_VF_RX_PROD;
75 if (!(p_vf->acquire.vfdev_info.capabilities &
76 VFPF_ACQUIRE_CAP_QUEUE_QIDS))
77 legacy |= ECORE_QCID_LEGACY_VF_CID;
83 static enum _ecore_status_t ecore_sp_vf_start(struct ecore_hwfn *p_hwfn,
84 struct ecore_vf_info *p_vf)
86 struct vf_start_ramrod_data *p_ramrod = OSAL_NULL;
87 struct ecore_spq_entry *p_ent = OSAL_NULL;
88 struct ecore_sp_init_data init_data;
89 enum _ecore_status_t rc = ECORE_NOTIMPL;
93 OSAL_MEMSET(&init_data, 0, sizeof(init_data));
94 init_data.cid = ecore_spq_get_cid(p_hwfn);
95 init_data.opaque_fid = p_vf->opaque_fid;
96 init_data.comp_mode = ECORE_SPQ_MODE_EBLOCK;
98 rc = ecore_sp_init_request(p_hwfn, &p_ent,
99 COMMON_RAMROD_VF_START,
100 PROTOCOLID_COMMON, &init_data);
101 if (rc != ECORE_SUCCESS)
104 p_ramrod = &p_ent->ramrod.vf_start;
106 p_ramrod->vf_id = GET_FIELD(p_vf->concrete_fid, PXP_CONCRETE_FID_VFID);
107 p_ramrod->opaque_fid = OSAL_CPU_TO_LE16(p_vf->opaque_fid);
109 switch (p_hwfn->hw_info.personality) {
111 p_ramrod->personality = PERSONALITY_ETH;
113 case ECORE_PCI_ETH_ROCE:
114 case ECORE_PCI_ETH_IWARP:
115 p_ramrod->personality = PERSONALITY_RDMA_AND_ETH;
118 DP_NOTICE(p_hwfn, true, "Unknown VF personality %d\n",
119 p_hwfn->hw_info.personality);
123 fp_minor = p_vf->acquire.vfdev_info.eth_fp_hsi_minor;
124 if (fp_minor > ETH_HSI_VER_MINOR &&
125 fp_minor != ETH_HSI_VER_NO_PKT_LEN_TUNN) {
126 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
127 "VF [%d] - Requested fp hsi %02x.%02x which is"
128 " slightly newer than PF's %02x.%02x; Configuring"
131 ETH_HSI_VER_MAJOR, fp_minor,
132 ETH_HSI_VER_MAJOR, ETH_HSI_VER_MINOR);
133 fp_minor = ETH_HSI_VER_MINOR;
136 p_ramrod->hsi_fp_ver.major_ver_arr[ETH_VER_KEY] = ETH_HSI_VER_MAJOR;
137 p_ramrod->hsi_fp_ver.minor_ver_arr[ETH_VER_KEY] = fp_minor;
139 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
140 "VF[%d] - Starting using HSI %02x.%02x\n",
141 p_vf->abs_vf_id, ETH_HSI_VER_MAJOR, fp_minor);
143 return ecore_spq_post(p_hwfn, p_ent, OSAL_NULL);
146 static enum _ecore_status_t ecore_sp_vf_stop(struct ecore_hwfn *p_hwfn,
150 struct vf_stop_ramrod_data *p_ramrod = OSAL_NULL;
151 struct ecore_spq_entry *p_ent = OSAL_NULL;
152 struct ecore_sp_init_data init_data;
153 enum _ecore_status_t rc = ECORE_NOTIMPL;
156 OSAL_MEMSET(&init_data, 0, sizeof(init_data));
157 init_data.cid = ecore_spq_get_cid(p_hwfn);
158 init_data.opaque_fid = opaque_vfid;
159 init_data.comp_mode = ECORE_SPQ_MODE_EBLOCK;
161 rc = ecore_sp_init_request(p_hwfn, &p_ent,
162 COMMON_RAMROD_VF_STOP,
163 PROTOCOLID_COMMON, &init_data);
164 if (rc != ECORE_SUCCESS)
167 p_ramrod = &p_ent->ramrod.vf_stop;
169 p_ramrod->vf_id = GET_FIELD(concrete_vfid, PXP_CONCRETE_FID_VFID);
171 return ecore_spq_post(p_hwfn, p_ent, OSAL_NULL);
174 bool ecore_iov_is_valid_vfid(struct ecore_hwfn *p_hwfn, int rel_vf_id,
175 bool b_enabled_only, bool b_non_malicious)
177 if (!p_hwfn->pf_iov_info) {
178 DP_NOTICE(p_hwfn->p_dev, true, "No iov info\n");
182 if ((rel_vf_id >= p_hwfn->p_dev->p_iov_info->total_vfs) ||
186 if ((!p_hwfn->pf_iov_info->vfs_array[rel_vf_id].b_init) &&
190 if ((p_hwfn->pf_iov_info->vfs_array[rel_vf_id].b_malicious) &&
197 struct ecore_vf_info *ecore_iov_get_vf_info(struct ecore_hwfn *p_hwfn,
201 struct ecore_vf_info *vf = OSAL_NULL;
203 if (!p_hwfn->pf_iov_info) {
204 DP_NOTICE(p_hwfn->p_dev, true, "No iov info\n");
208 if (ecore_iov_is_valid_vfid(p_hwfn, relative_vf_id,
209 b_enabled_only, false))
210 vf = &p_hwfn->pf_iov_info->vfs_array[relative_vf_id];
212 DP_ERR(p_hwfn, "ecore_iov_get_vf_info: VF[%d] is not enabled\n",
218 static struct ecore_queue_cid *
219 ecore_iov_get_vf_rx_queue_cid(struct ecore_vf_queue *p_queue)
223 for (i = 0; i < MAX_QUEUES_PER_QZONE; i++) {
224 if (p_queue->cids[i].p_cid &&
225 !p_queue->cids[i].b_is_tx)
226 return p_queue->cids[i].p_cid;
232 enum ecore_iov_validate_q_mode {
233 ECORE_IOV_VALIDATE_Q_NA,
234 ECORE_IOV_VALIDATE_Q_ENABLE,
235 ECORE_IOV_VALIDATE_Q_DISABLE,
238 static bool ecore_iov_validate_queue_mode(struct ecore_vf_info *p_vf,
240 enum ecore_iov_validate_q_mode mode,
245 if (mode == ECORE_IOV_VALIDATE_Q_NA)
248 for (i = 0; i < MAX_QUEUES_PER_QZONE; i++) {
249 struct ecore_vf_queue_cid *p_qcid;
251 p_qcid = &p_vf->vf_queues[qid].cids[i];
253 if (p_qcid->p_cid == OSAL_NULL)
256 if (p_qcid->b_is_tx != b_is_tx)
259 /* Found. It's enabled. */
260 return (mode == ECORE_IOV_VALIDATE_Q_ENABLE);
263 /* In case we haven't found any valid cid, then its disabled */
264 return (mode == ECORE_IOV_VALIDATE_Q_DISABLE);
267 static bool ecore_iov_validate_rxq(struct ecore_hwfn *p_hwfn,
268 struct ecore_vf_info *p_vf,
270 enum ecore_iov_validate_q_mode mode)
272 if (rx_qid >= p_vf->num_rxqs) {
273 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
274 "VF[0x%02x] - can't touch Rx queue[%04x];"
275 " Only 0x%04x are allocated\n",
276 p_vf->abs_vf_id, rx_qid, p_vf->num_rxqs);
280 return ecore_iov_validate_queue_mode(p_vf, rx_qid, mode, false);
283 static bool ecore_iov_validate_txq(struct ecore_hwfn *p_hwfn,
284 struct ecore_vf_info *p_vf,
286 enum ecore_iov_validate_q_mode mode)
288 if (tx_qid >= p_vf->num_txqs) {
289 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
290 "VF[0x%02x] - can't touch Tx queue[%04x];"
291 " Only 0x%04x are allocated\n",
292 p_vf->abs_vf_id, tx_qid, p_vf->num_txqs);
296 return ecore_iov_validate_queue_mode(p_vf, tx_qid, mode, true);
299 static bool ecore_iov_validate_sb(struct ecore_hwfn *p_hwfn,
300 struct ecore_vf_info *p_vf,
305 for (i = 0; i < p_vf->num_sbs; i++)
306 if (p_vf->igu_sbs[i] == sb_idx)
309 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
310 "VF[0%02x] - tried using sb_idx %04x which doesn't exist as"
311 " one of its 0x%02x SBs\n",
312 p_vf->abs_vf_id, sb_idx, p_vf->num_sbs);
317 /* Is there at least 1 queue open? */
318 static bool ecore_iov_validate_active_rxq(struct ecore_vf_info *p_vf)
322 for (i = 0; i < p_vf->num_rxqs; i++)
323 if (ecore_iov_validate_queue_mode(p_vf, i,
324 ECORE_IOV_VALIDATE_Q_ENABLE,
331 static bool ecore_iov_validate_active_txq(struct ecore_vf_info *p_vf)
335 for (i = 0; i < p_vf->num_txqs; i++)
336 if (ecore_iov_validate_queue_mode(p_vf, i,
337 ECORE_IOV_VALIDATE_Q_ENABLE,
344 enum _ecore_status_t ecore_iov_post_vf_bulletin(struct ecore_hwfn *p_hwfn,
346 struct ecore_ptt *p_ptt)
348 struct ecore_bulletin_content *p_bulletin;
349 int crc_size = sizeof(p_bulletin->crc);
350 struct ecore_dmae_params params;
351 struct ecore_vf_info *p_vf;
353 p_vf = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
357 /* TODO - check VF is in a state where it can accept message */
358 if (!p_vf->vf_bulletin)
361 p_bulletin = p_vf->bulletin.p_virt;
363 /* Increment bulletin board version and compute crc */
364 p_bulletin->version++;
365 p_bulletin->crc = OSAL_CRC32(0, (u8 *)p_bulletin + crc_size,
366 p_vf->bulletin.size - crc_size);
368 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
369 "Posting Bulletin 0x%08x to VF[%d] (CRC 0x%08x)\n",
370 p_bulletin->version, p_vf->relative_vf_id, p_bulletin->crc);
372 /* propagate bulletin board via dmae to vm memory */
373 OSAL_MEMSET(¶ms, 0, sizeof(params));
374 params.flags = ECORE_DMAE_FLAG_VF_DST;
375 params.dst_vfid = p_vf->abs_vf_id;
376 return ecore_dmae_host2host(p_hwfn, p_ptt, p_vf->bulletin.phys,
377 p_vf->vf_bulletin, p_vf->bulletin.size / 4,
381 static enum _ecore_status_t ecore_iov_pci_cfg_info(struct ecore_dev *p_dev)
383 struct ecore_hw_sriov_info *iov = p_dev->p_iov_info;
386 DP_VERBOSE(p_dev, ECORE_MSG_IOV, "sriov ext pos %d\n", pos);
387 OSAL_PCI_READ_CONFIG_WORD(p_dev, pos + PCI_SRIOV_CTRL, &iov->ctrl);
389 OSAL_PCI_READ_CONFIG_WORD(p_dev,
390 pos + PCI_SRIOV_TOTAL_VF, &iov->total_vfs);
391 OSAL_PCI_READ_CONFIG_WORD(p_dev,
392 pos + PCI_SRIOV_INITIAL_VF,
395 OSAL_PCI_READ_CONFIG_WORD(p_dev, pos + PCI_SRIOV_NUM_VF, &iov->num_vfs);
397 /* @@@TODO - in future we might want to add an OSAL here to
398 * allow each OS to decide on its own how to act.
400 DP_VERBOSE(p_dev, ECORE_MSG_IOV,
401 "Number of VFs are already set to non-zero value."
402 " Ignoring PCI configuration value\n");
406 OSAL_PCI_READ_CONFIG_WORD(p_dev,
407 pos + PCI_SRIOV_VF_OFFSET, &iov->offset);
409 OSAL_PCI_READ_CONFIG_WORD(p_dev,
410 pos + PCI_SRIOV_VF_STRIDE, &iov->stride);
412 OSAL_PCI_READ_CONFIG_WORD(p_dev,
413 pos + PCI_SRIOV_VF_DID, &iov->vf_device_id);
415 OSAL_PCI_READ_CONFIG_DWORD(p_dev,
416 pos + PCI_SRIOV_SUP_PGSIZE, &iov->pgsz);
418 OSAL_PCI_READ_CONFIG_DWORD(p_dev, pos + PCI_SRIOV_CAP, &iov->cap);
420 OSAL_PCI_READ_CONFIG_BYTE(p_dev, pos + PCI_SRIOV_FUNC_LINK, &iov->link);
422 DP_VERBOSE(p_dev, ECORE_MSG_IOV, "IOV info: nres %d, cap 0x%x,"
423 "ctrl 0x%x, total %d, initial %d, num vfs %d, offset %d,"
424 " stride %d, page size 0x%x\n",
425 iov->nres, iov->cap, iov->ctrl,
426 iov->total_vfs, iov->initial_vfs, iov->nr_virtfn,
427 iov->offset, iov->stride, iov->pgsz);
429 /* Some sanity checks */
430 if (iov->num_vfs > NUM_OF_VFS(p_dev) ||
431 iov->total_vfs > NUM_OF_VFS(p_dev)) {
432 /* This can happen only due to a bug. In this case we set
433 * num_vfs to zero to avoid memory corruption in the code that
434 * assumes max number of vfs
436 DP_NOTICE(p_dev, false,
437 "IOV: Unexpected number of vfs set: %d"
438 " setting num_vf to zero\n",
445 return ECORE_SUCCESS;
448 static void ecore_iov_setup_vfdb(struct ecore_hwfn *p_hwfn)
450 struct ecore_hw_sriov_info *p_iov = p_hwfn->p_dev->p_iov_info;
451 struct ecore_pf_iov *p_iov_info = p_hwfn->pf_iov_info;
452 struct ecore_bulletin_content *p_bulletin_virt;
453 dma_addr_t req_p, rply_p, bulletin_p;
454 union pfvf_tlvs *p_reply_virt_addr;
455 union vfpf_tlvs *p_req_virt_addr;
458 OSAL_MEMSET(p_iov_info->vfs_array, 0, sizeof(p_iov_info->vfs_array));
460 p_req_virt_addr = p_iov_info->mbx_msg_virt_addr;
461 req_p = p_iov_info->mbx_msg_phys_addr;
462 p_reply_virt_addr = p_iov_info->mbx_reply_virt_addr;
463 rply_p = p_iov_info->mbx_reply_phys_addr;
464 p_bulletin_virt = p_iov_info->p_bulletins;
465 bulletin_p = p_iov_info->bulletins_phys;
466 if (!p_req_virt_addr || !p_reply_virt_addr || !p_bulletin_virt) {
468 "ecore_iov_setup_vfdb called without alloc mem first\n");
472 for (idx = 0; idx < p_iov->total_vfs; idx++) {
473 struct ecore_vf_info *vf = &p_iov_info->vfs_array[idx];
476 vf->vf_mbx.req_virt = p_req_virt_addr + idx;
477 vf->vf_mbx.req_phys = req_p + idx * sizeof(union vfpf_tlvs);
478 vf->vf_mbx.reply_virt = p_reply_virt_addr + idx;
479 vf->vf_mbx.reply_phys = rply_p + idx * sizeof(union pfvf_tlvs);
481 #ifdef CONFIG_ECORE_SW_CHANNEL
482 vf->vf_mbx.sw_mbx.request_size = sizeof(union vfpf_tlvs);
483 vf->vf_mbx.sw_mbx.mbx_state = VF_PF_WAIT_FOR_START_REQUEST;
485 vf->state = VF_STOPPED;
488 vf->bulletin.phys = idx *
489 sizeof(struct ecore_bulletin_content) + bulletin_p;
490 vf->bulletin.p_virt = p_bulletin_virt + idx;
491 vf->bulletin.size = sizeof(struct ecore_bulletin_content);
493 vf->relative_vf_id = idx;
494 vf->abs_vf_id = idx + p_iov->first_vf_in_pf;
495 concrete = ecore_vfid_to_concrete(p_hwfn, vf->abs_vf_id);
496 vf->concrete_fid = concrete;
497 /* TODO - need to devise a better way of getting opaque */
498 vf->opaque_fid = (p_hwfn->hw_info.opaque_fid & 0xff) |
499 (vf->abs_vf_id << 8);
501 vf->num_mac_filters = ECORE_ETH_VF_NUM_MAC_FILTERS;
502 vf->num_vlan_filters = ECORE_ETH_VF_NUM_VLAN_FILTERS;
506 static enum _ecore_status_t ecore_iov_allocate_vfdb(struct ecore_hwfn *p_hwfn)
508 struct ecore_pf_iov *p_iov_info = p_hwfn->pf_iov_info;
512 num_vfs = p_hwfn->p_dev->p_iov_info->total_vfs;
514 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
515 "ecore_iov_allocate_vfdb for %d VFs\n", num_vfs);
517 /* Allocate PF Mailbox buffer (per-VF) */
518 p_iov_info->mbx_msg_size = sizeof(union vfpf_tlvs) * num_vfs;
519 p_v_addr = &p_iov_info->mbx_msg_virt_addr;
520 *p_v_addr = OSAL_DMA_ALLOC_COHERENT(p_hwfn->p_dev,
521 &p_iov_info->mbx_msg_phys_addr,
522 p_iov_info->mbx_msg_size);
526 /* Allocate PF Mailbox Reply buffer (per-VF) */
527 p_iov_info->mbx_reply_size = sizeof(union pfvf_tlvs) * num_vfs;
528 p_v_addr = &p_iov_info->mbx_reply_virt_addr;
529 *p_v_addr = OSAL_DMA_ALLOC_COHERENT(p_hwfn->p_dev,
530 &p_iov_info->mbx_reply_phys_addr,
531 p_iov_info->mbx_reply_size);
535 p_iov_info->bulletins_size = sizeof(struct ecore_bulletin_content) *
537 p_v_addr = &p_iov_info->p_bulletins;
538 *p_v_addr = OSAL_DMA_ALLOC_COHERENT(p_hwfn->p_dev,
539 &p_iov_info->bulletins_phys,
540 p_iov_info->bulletins_size);
544 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
545 "PF's Requests mailbox [%p virt 0x%lx phys], "
546 "Response mailbox [%p virt 0x%lx phys] Bulletinsi"
547 " [%p virt 0x%lx phys]\n",
548 p_iov_info->mbx_msg_virt_addr,
549 (unsigned long)p_iov_info->mbx_msg_phys_addr,
550 p_iov_info->mbx_reply_virt_addr,
551 (unsigned long)p_iov_info->mbx_reply_phys_addr,
552 p_iov_info->p_bulletins,
553 (unsigned long)p_iov_info->bulletins_phys);
555 return ECORE_SUCCESS;
558 static void ecore_iov_free_vfdb(struct ecore_hwfn *p_hwfn)
560 struct ecore_pf_iov *p_iov_info = p_hwfn->pf_iov_info;
562 if (p_hwfn->pf_iov_info->mbx_msg_virt_addr)
563 OSAL_DMA_FREE_COHERENT(p_hwfn->p_dev,
564 p_iov_info->mbx_msg_virt_addr,
565 p_iov_info->mbx_msg_phys_addr,
566 p_iov_info->mbx_msg_size);
568 if (p_hwfn->pf_iov_info->mbx_reply_virt_addr)
569 OSAL_DMA_FREE_COHERENT(p_hwfn->p_dev,
570 p_iov_info->mbx_reply_virt_addr,
571 p_iov_info->mbx_reply_phys_addr,
572 p_iov_info->mbx_reply_size);
574 if (p_iov_info->p_bulletins)
575 OSAL_DMA_FREE_COHERENT(p_hwfn->p_dev,
576 p_iov_info->p_bulletins,
577 p_iov_info->bulletins_phys,
578 p_iov_info->bulletins_size);
581 enum _ecore_status_t ecore_iov_alloc(struct ecore_hwfn *p_hwfn)
583 struct ecore_pf_iov *p_sriov;
585 if (!IS_PF_SRIOV(p_hwfn)) {
586 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
587 "No SR-IOV - no need for IOV db\n");
588 return ECORE_SUCCESS;
591 p_sriov = OSAL_ZALLOC(p_hwfn->p_dev, GFP_KERNEL, sizeof(*p_sriov));
593 DP_NOTICE(p_hwfn, false, "Failed to allocate `struct ecore_sriov'\n");
597 p_hwfn->pf_iov_info = p_sriov;
599 ecore_spq_register_async_cb(p_hwfn, PROTOCOLID_COMMON,
600 ecore_sriov_eqe_event);
602 return ecore_iov_allocate_vfdb(p_hwfn);
605 void ecore_iov_setup(struct ecore_hwfn *p_hwfn)
607 if (!IS_PF_SRIOV(p_hwfn) || !IS_PF_SRIOV_ALLOC(p_hwfn))
610 ecore_iov_setup_vfdb(p_hwfn);
613 void ecore_iov_free(struct ecore_hwfn *p_hwfn)
615 ecore_spq_unregister_async_cb(p_hwfn, PROTOCOLID_COMMON);
617 if (IS_PF_SRIOV_ALLOC(p_hwfn)) {
618 ecore_iov_free_vfdb(p_hwfn);
619 OSAL_FREE(p_hwfn->p_dev, p_hwfn->pf_iov_info);
623 void ecore_iov_free_hw_info(struct ecore_dev *p_dev)
625 OSAL_FREE(p_dev, p_dev->p_iov_info);
628 enum _ecore_status_t ecore_iov_hw_info(struct ecore_hwfn *p_hwfn)
630 struct ecore_dev *p_dev = p_hwfn->p_dev;
632 enum _ecore_status_t rc;
634 if (IS_VF(p_hwfn->p_dev))
635 return ECORE_SUCCESS;
637 /* Learn the PCI configuration */
638 pos = OSAL_PCI_FIND_EXT_CAPABILITY(p_hwfn->p_dev,
639 PCI_EXT_CAP_ID_SRIOV);
641 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV, "No PCIe IOV support\n");
642 return ECORE_SUCCESS;
645 /* Allocate a new struct for IOV information */
646 /* TODO - can change to VALLOC when its available */
647 p_dev->p_iov_info = OSAL_ZALLOC(p_dev, GFP_KERNEL,
648 sizeof(*p_dev->p_iov_info));
649 if (!p_dev->p_iov_info) {
650 DP_NOTICE(p_hwfn, false,
651 "Can't support IOV due to lack of memory\n");
654 p_dev->p_iov_info->pos = pos;
656 rc = ecore_iov_pci_cfg_info(p_dev);
660 /* We want PF IOV to be synonemous with the existence of p_iov_info;
661 * In case the capability is published but there are no VFs, simply
662 * de-allocate the struct.
664 if (!p_dev->p_iov_info->total_vfs) {
665 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
666 "IOV capabilities, but no VFs are published\n");
667 OSAL_FREE(p_dev, p_dev->p_iov_info);
668 return ECORE_SUCCESS;
671 /* First VF index based on offset is tricky:
672 * - If ARI is supported [likely], offset - (16 - pf_id) would
673 * provide the number for eng0. 2nd engine Vfs would begin
674 * after the first engine's VFs.
675 * - If !ARI, VFs would start on next device.
676 * so offset - (256 - pf_id) would provide the number.
677 * Utilize the fact that (256 - pf_id) is achieved only be later
678 * to diffrentiate between the two.
681 if (p_hwfn->p_dev->p_iov_info->offset < (256 - p_hwfn->abs_pf_id)) {
682 u32 first = p_hwfn->p_dev->p_iov_info->offset +
683 p_hwfn->abs_pf_id - 16;
685 p_dev->p_iov_info->first_vf_in_pf = first;
687 if (ECORE_PATH_ID(p_hwfn))
688 p_dev->p_iov_info->first_vf_in_pf -= MAX_NUM_VFS_BB;
690 u32 first = p_hwfn->p_dev->p_iov_info->offset +
691 p_hwfn->abs_pf_id - 256;
693 p_dev->p_iov_info->first_vf_in_pf = first;
696 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
697 "First VF in hwfn 0x%08x\n",
698 p_dev->p_iov_info->first_vf_in_pf);
700 return ECORE_SUCCESS;
703 static bool _ecore_iov_pf_sanity_check(struct ecore_hwfn *p_hwfn, int vfid,
704 bool b_fail_malicious)
706 /* Check PF supports sriov */
707 if (IS_VF(p_hwfn->p_dev) || !IS_ECORE_SRIOV(p_hwfn->p_dev) ||
708 !IS_PF_SRIOV_ALLOC(p_hwfn))
711 /* Check VF validity */
712 if (!ecore_iov_is_valid_vfid(p_hwfn, vfid, true, b_fail_malicious))
718 bool ecore_iov_pf_sanity_check(struct ecore_hwfn *p_hwfn, int vfid)
720 return _ecore_iov_pf_sanity_check(p_hwfn, vfid, true);
723 void ecore_iov_set_vf_to_disable(struct ecore_dev *p_dev,
724 u16 rel_vf_id, u8 to_disable)
726 struct ecore_vf_info *vf;
729 for_each_hwfn(p_dev, i) {
730 struct ecore_hwfn *p_hwfn = &p_dev->hwfns[i];
732 vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, false);
736 vf->to_disable = to_disable;
740 void ecore_iov_set_vfs_to_disable(struct ecore_dev *p_dev,
745 if (!IS_ECORE_SRIOV(p_dev))
748 for (i = 0; i < p_dev->p_iov_info->total_vfs; i++)
749 ecore_iov_set_vf_to_disable(p_dev, i, to_disable);
753 /* @@@TBD Consider taking outside of ecore... */
754 enum _ecore_status_t ecore_iov_set_vf_ctx(struct ecore_hwfn *p_hwfn,
758 enum _ecore_status_t rc = ECORE_SUCCESS;
759 struct ecore_vf_info *vf = ecore_iov_get_vf_info(p_hwfn, vf_id, true);
761 if (vf != OSAL_NULL) {
763 #ifdef CONFIG_ECORE_SW_CHANNEL
764 vf->vf_mbx.sw_mbx.mbx_state = VF_PF_WAIT_FOR_START_REQUEST;
767 rc = ECORE_UNKNOWN_ERROR;
773 static void ecore_iov_vf_pglue_clear_err(struct ecore_hwfn *p_hwfn,
774 struct ecore_ptt *p_ptt,
777 ecore_wr(p_hwfn, p_ptt,
778 PGLUE_B_REG_WAS_ERROR_VF_31_0_CLR + (abs_vfid >> 5) * 4,
779 1 << (abs_vfid & 0x1f));
782 static void ecore_iov_vf_igu_reset(struct ecore_hwfn *p_hwfn,
783 struct ecore_ptt *p_ptt,
784 struct ecore_vf_info *vf)
788 /* Set VF masks and configuration - pretend */
789 ecore_fid_pretend(p_hwfn, p_ptt, (u16)vf->concrete_fid);
791 ecore_wr(p_hwfn, p_ptt, IGU_REG_STATISTIC_NUM_VF_MSG_SENT, 0);
794 ecore_fid_pretend(p_hwfn, p_ptt, (u16)p_hwfn->hw_info.concrete_fid);
796 /* iterate over all queues, clear sb consumer */
797 for (i = 0; i < vf->num_sbs; i++)
798 ecore_int_igu_init_pure_rt_single(p_hwfn, p_ptt,
800 vf->opaque_fid, true);
803 static void ecore_iov_vf_igu_set_int(struct ecore_hwfn *p_hwfn,
804 struct ecore_ptt *p_ptt,
805 struct ecore_vf_info *vf, bool enable)
809 ecore_fid_pretend(p_hwfn, p_ptt, (u16)vf->concrete_fid);
811 igu_vf_conf = ecore_rd(p_hwfn, p_ptt, IGU_REG_VF_CONFIGURATION);
814 igu_vf_conf |= IGU_VF_CONF_MSI_MSIX_EN;
816 igu_vf_conf &= ~IGU_VF_CONF_MSI_MSIX_EN;
818 ecore_wr(p_hwfn, p_ptt, IGU_REG_VF_CONFIGURATION, igu_vf_conf);
821 ecore_fid_pretend(p_hwfn, p_ptt, (u16)p_hwfn->hw_info.concrete_fid);
824 static enum _ecore_status_t
825 ecore_iov_enable_vf_access_msix(struct ecore_hwfn *p_hwfn,
826 struct ecore_ptt *p_ptt,
833 /* If client overrides this, don't do anything */
834 if (p_hwfn->p_dev->b_dont_override_vf_msix)
835 return ECORE_SUCCESS;
837 /* For AH onward, configuration is per-PF. Find maximum of all
838 * the currently enabled child VFs, and set the number to be that.
840 if (!ECORE_IS_BB(p_hwfn->p_dev)) {
841 ecore_for_each_vf(p_hwfn, i) {
842 struct ecore_vf_info *p_vf;
844 p_vf = ecore_iov_get_vf_info(p_hwfn, (u16)i, true);
848 current_max = OSAL_MAX_T(u8, current_max,
853 if (num_sbs > current_max)
854 return ecore_mcp_config_vf_msix(p_hwfn, p_ptt,
857 return ECORE_SUCCESS;
860 static enum _ecore_status_t
861 ecore_iov_enable_vf_access(struct ecore_hwfn *p_hwfn,
862 struct ecore_ptt *p_ptt, struct ecore_vf_info *vf)
864 u32 igu_vf_conf = IGU_VF_CONF_FUNC_EN;
865 enum _ecore_status_t rc = ECORE_SUCCESS;
867 /* It's possible VF was previously considered malicious -
868 * clear the indication even if we're only going to disable VF.
870 vf->b_malicious = false;
873 return ECORE_SUCCESS;
875 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
876 "Enable internal access for vf %x [abs %x]\n", vf->abs_vf_id,
877 ECORE_VF_ABS_ID(p_hwfn, vf));
879 ecore_iov_vf_pglue_clear_err(p_hwfn, p_ptt,
880 ECORE_VF_ABS_ID(p_hwfn, vf));
882 ecore_iov_vf_igu_reset(p_hwfn, p_ptt, vf);
884 rc = ecore_iov_enable_vf_access_msix(p_hwfn, p_ptt,
885 vf->abs_vf_id, vf->num_sbs);
886 if (rc != ECORE_SUCCESS)
889 ecore_fid_pretend(p_hwfn, p_ptt, (u16)vf->concrete_fid);
891 SET_FIELD(igu_vf_conf, IGU_VF_CONF_PARENT, p_hwfn->rel_pf_id);
892 STORE_RT_REG(p_hwfn, IGU_REG_VF_CONFIGURATION_RT_OFFSET, igu_vf_conf);
894 ecore_init_run(p_hwfn, p_ptt, PHASE_VF, vf->abs_vf_id,
895 p_hwfn->hw_info.hw_mode);
898 ecore_fid_pretend(p_hwfn, p_ptt, (u16)p_hwfn->hw_info.concrete_fid);
907 * @brief ecore_iov_config_perm_table - configure the permission
909 * In E4, queue zone permission table size is 320x9. There
910 * are 320 VF queues for single engine device (256 for dual
911 * engine device), and each entry has the following format:
918 static void ecore_iov_config_perm_table(struct ecore_hwfn *p_hwfn,
919 struct ecore_ptt *p_ptt,
920 struct ecore_vf_info *vf, u8 enable)
926 for (qid = 0; qid < vf->num_rxqs; qid++) {
927 ecore_fw_l2_queue(p_hwfn, vf->vf_queues[qid].fw_rx_qid,
930 reg_addr = PSWHST_REG_ZONE_PERMISSION_TABLE + qzone_id * 4;
931 val = enable ? (vf->abs_vf_id | (1 << 8)) : 0;
932 ecore_wr(p_hwfn, p_ptt, reg_addr, val);
936 static void ecore_iov_enable_vf_traffic(struct ecore_hwfn *p_hwfn,
937 struct ecore_ptt *p_ptt,
938 struct ecore_vf_info *vf)
940 /* Reset vf in IGU - interrupts are still disabled */
941 ecore_iov_vf_igu_reset(p_hwfn, p_ptt, vf);
943 ecore_iov_vf_igu_set_int(p_hwfn, p_ptt, vf, 1);
945 /* Permission Table */
946 ecore_iov_config_perm_table(p_hwfn, p_ptt, vf, true);
949 static u8 ecore_iov_alloc_vf_igu_sbs(struct ecore_hwfn *p_hwfn,
950 struct ecore_ptt *p_ptt,
951 struct ecore_vf_info *vf,
954 struct ecore_igu_block *p_block;
955 struct cau_sb_entry sb_entry;
959 if (num_rx_queues > p_hwfn->hw_info.p_igu_info->usage.free_cnt_iov)
961 (u16)p_hwfn->hw_info.p_igu_info->usage.free_cnt_iov;
962 p_hwfn->hw_info.p_igu_info->usage.free_cnt_iov -= num_rx_queues;
964 SET_FIELD(val, IGU_MAPPING_LINE_FUNCTION_NUMBER, vf->abs_vf_id);
965 SET_FIELD(val, IGU_MAPPING_LINE_VALID, 1);
966 SET_FIELD(val, IGU_MAPPING_LINE_PF_VALID, 0);
968 for (qid = 0; qid < num_rx_queues; qid++) {
969 p_block = ecore_get_igu_free_sb(p_hwfn, false);
970 vf->igu_sbs[qid] = p_block->igu_sb_id;
971 p_block->status &= ~ECORE_IGU_STATUS_FREE;
972 SET_FIELD(val, IGU_MAPPING_LINE_VECTOR_NUMBER, qid);
974 ecore_wr(p_hwfn, p_ptt,
975 IGU_REG_MAPPING_MEMORY +
976 sizeof(u32) * p_block->igu_sb_id, val);
978 /* Configure igu sb in CAU which were marked valid */
979 ecore_init_cau_sb_entry(p_hwfn, &sb_entry,
983 ecore_dmae_host2grc(p_hwfn, p_ptt,
984 (u64)(osal_uintptr_t)&sb_entry,
985 CAU_REG_SB_VAR_MEMORY +
986 p_block->igu_sb_id * sizeof(u64), 2,
987 OSAL_NULL /* default parameters */);
990 vf->num_sbs = (u8)num_rx_queues;
997 * @brief The function invalidates all the VF entries,
998 * technically this isn't required, but added for
999 * cleaness and ease of debugging incase a VF attempts to
1000 * produce an interrupt after it has been taken down.
1006 static void ecore_iov_free_vf_igu_sbs(struct ecore_hwfn *p_hwfn,
1007 struct ecore_ptt *p_ptt,
1008 struct ecore_vf_info *vf)
1010 struct ecore_igu_info *p_info = p_hwfn->hw_info.p_igu_info;
1014 /* Invalidate igu CAM lines and mark them as free */
1015 for (idx = 0; idx < vf->num_sbs; idx++) {
1016 igu_id = vf->igu_sbs[idx];
1017 addr = IGU_REG_MAPPING_MEMORY + sizeof(u32) * igu_id;
1019 val = ecore_rd(p_hwfn, p_ptt, addr);
1020 SET_FIELD(val, IGU_MAPPING_LINE_VALID, 0);
1021 ecore_wr(p_hwfn, p_ptt, addr, val);
1023 p_info->entry[igu_id].status |= ECORE_IGU_STATUS_FREE;
1024 p_hwfn->hw_info.p_igu_info->usage.free_cnt_iov++;
1030 void ecore_iov_set_link(struct ecore_hwfn *p_hwfn,
1032 struct ecore_mcp_link_params *params,
1033 struct ecore_mcp_link_state *link,
1034 struct ecore_mcp_link_capabilities *p_caps)
1036 struct ecore_vf_info *p_vf = ecore_iov_get_vf_info(p_hwfn, vfid, false);
1037 struct ecore_bulletin_content *p_bulletin;
1042 p_bulletin = p_vf->bulletin.p_virt;
1043 p_bulletin->req_autoneg = params->speed.autoneg;
1044 p_bulletin->req_adv_speed = params->speed.advertised_speeds;
1045 p_bulletin->req_forced_speed = params->speed.forced_speed;
1046 p_bulletin->req_autoneg_pause = params->pause.autoneg;
1047 p_bulletin->req_forced_rx = params->pause.forced_rx;
1048 p_bulletin->req_forced_tx = params->pause.forced_tx;
1049 p_bulletin->req_loopback = params->loopback_mode;
1051 p_bulletin->link_up = link->link_up;
1052 p_bulletin->speed = link->speed;
1053 p_bulletin->full_duplex = link->full_duplex;
1054 p_bulletin->autoneg = link->an;
1055 p_bulletin->autoneg_complete = link->an_complete;
1056 p_bulletin->parallel_detection = link->parallel_detection;
1057 p_bulletin->pfc_enabled = link->pfc_enabled;
1058 p_bulletin->partner_adv_speed = link->partner_adv_speed;
1059 p_bulletin->partner_tx_flow_ctrl_en = link->partner_tx_flow_ctrl_en;
1060 p_bulletin->partner_rx_flow_ctrl_en = link->partner_rx_flow_ctrl_en;
1061 p_bulletin->partner_adv_pause = link->partner_adv_pause;
1062 p_bulletin->sfp_tx_fault = link->sfp_tx_fault;
1064 p_bulletin->capability_speed = p_caps->speed_capabilities;
1067 enum _ecore_status_t
1068 ecore_iov_init_hw_for_vf(struct ecore_hwfn *p_hwfn,
1069 struct ecore_ptt *p_ptt,
1070 struct ecore_iov_vf_init_params *p_params)
1072 struct ecore_mcp_link_capabilities link_caps;
1073 struct ecore_mcp_link_params link_params;
1074 struct ecore_mcp_link_state link_state;
1075 u8 num_of_vf_available_chains = 0;
1076 struct ecore_vf_info *vf = OSAL_NULL;
1078 enum _ecore_status_t rc = ECORE_SUCCESS;
1082 vf = ecore_iov_get_vf_info(p_hwfn, p_params->rel_vf_id, false);
1084 DP_ERR(p_hwfn, "ecore_iov_init_hw_for_vf : vf is OSAL_NULL\n");
1085 return ECORE_UNKNOWN_ERROR;
1089 DP_NOTICE(p_hwfn, true, "VF[%d] is already active.\n",
1090 p_params->rel_vf_id);
1094 /* Perform sanity checking on the requested vport/rss */
1095 if (p_params->vport_id >= RESC_NUM(p_hwfn, ECORE_VPORT)) {
1096 DP_NOTICE(p_hwfn, true, "VF[%d] - can't use VPORT %02x\n",
1097 p_params->rel_vf_id, p_params->vport_id);
1101 if ((p_params->num_queues > 1) &&
1102 (p_params->rss_eng_id >= RESC_NUM(p_hwfn, ECORE_RSS_ENG))) {
1103 DP_NOTICE(p_hwfn, true, "VF[%d] - can't use RSS_ENG %02x\n",
1104 p_params->rel_vf_id, p_params->rss_eng_id);
1108 /* TODO - remove this once we get confidence of change */
1109 if (!p_params->vport_id) {
1110 DP_NOTICE(p_hwfn, false,
1111 "VF[%d] - Unlikely that VF uses vport0. Forgotten?\n",
1112 p_params->rel_vf_id);
1114 if ((!p_params->rss_eng_id) && (p_params->num_queues > 1)) {
1115 DP_NOTICE(p_hwfn, false,
1116 "VF[%d] - Unlikely that VF uses RSS_eng0. Forgotten?\n",
1117 p_params->rel_vf_id);
1119 vf->vport_id = p_params->vport_id;
1120 vf->rss_eng_id = p_params->rss_eng_id;
1122 /* Since it's possible to relocate SBs, it's a bit difficult to check
1123 * things here. Simply check whether the index falls in the range
1124 * belonging to the PF.
1126 for (i = 0; i < p_params->num_queues; i++) {
1127 qid = p_params->req_rx_queue[i];
1128 if (qid > (u16)RESC_NUM(p_hwfn, ECORE_L2_QUEUE)) {
1129 DP_NOTICE(p_hwfn, true,
1130 "Can't enable Rx qid [%04x] for VF[%d]: qids [0,,...,0x%04x] available\n",
1131 qid, p_params->rel_vf_id,
1132 (u16)RESC_NUM(p_hwfn, ECORE_L2_QUEUE));
1136 qid = p_params->req_tx_queue[i];
1137 if (qid > (u16)RESC_NUM(p_hwfn, ECORE_L2_QUEUE)) {
1138 DP_NOTICE(p_hwfn, true,
1139 "Can't enable Tx qid [%04x] for VF[%d]: qids [0,,...,0x%04x] available\n",
1140 qid, p_params->rel_vf_id,
1141 (u16)RESC_NUM(p_hwfn, ECORE_L2_QUEUE));
1146 /* Limit number of queues according to number of CIDs */
1147 ecore_cxt_get_proto_cid_count(p_hwfn, PROTOCOLID_ETH, &cids);
1148 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1149 "VF[%d] - requesting to initialize for 0x%04x queues"
1150 " [0x%04x CIDs available]\n",
1151 vf->relative_vf_id, p_params->num_queues, (u16)cids);
1152 num_irqs = OSAL_MIN_T(u16, p_params->num_queues, ((u16)cids));
1154 num_of_vf_available_chains = ecore_iov_alloc_vf_igu_sbs(p_hwfn,
1158 if (num_of_vf_available_chains == 0) {
1159 DP_ERR(p_hwfn, "no available igu sbs\n");
1163 /* Choose queue number and index ranges */
1164 vf->num_rxqs = num_of_vf_available_chains;
1165 vf->num_txqs = num_of_vf_available_chains;
1167 for (i = 0; i < vf->num_rxqs; i++) {
1168 struct ecore_vf_queue *p_queue = &vf->vf_queues[i];
1170 p_queue->fw_rx_qid = p_params->req_rx_queue[i];
1171 p_queue->fw_tx_qid = p_params->req_tx_queue[i];
1173 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1174 "VF[%d] - Q[%d] SB %04x, qid [Rx %04x Tx %04x]\n",
1175 vf->relative_vf_id, i, vf->igu_sbs[i],
1176 p_queue->fw_rx_qid, p_queue->fw_tx_qid);
1179 /* Update the link configuration in bulletin.
1181 OSAL_MEMCPY(&link_params, ecore_mcp_get_link_params(p_hwfn),
1182 sizeof(link_params));
1183 OSAL_MEMCPY(&link_state, ecore_mcp_get_link_state(p_hwfn),
1184 sizeof(link_state));
1185 OSAL_MEMCPY(&link_caps, ecore_mcp_get_link_capabilities(p_hwfn),
1187 ecore_iov_set_link(p_hwfn, p_params->rel_vf_id,
1188 &link_params, &link_state, &link_caps);
1190 rc = ecore_iov_enable_vf_access(p_hwfn, p_ptt, vf);
1192 if (rc == ECORE_SUCCESS) {
1194 p_hwfn->pf_iov_info->active_vfs[vf->relative_vf_id / 64] |=
1195 (1ULL << (vf->relative_vf_id % 64));
1197 if (IS_LEAD_HWFN(p_hwfn))
1198 p_hwfn->p_dev->p_iov_info->num_vfs++;
1204 enum _ecore_status_t ecore_iov_release_hw_for_vf(struct ecore_hwfn *p_hwfn,
1205 struct ecore_ptt *p_ptt,
1208 struct ecore_mcp_link_capabilities caps;
1209 struct ecore_mcp_link_params params;
1210 struct ecore_mcp_link_state link;
1211 struct ecore_vf_info *vf = OSAL_NULL;
1213 vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
1215 DP_ERR(p_hwfn, "ecore_iov_release_hw_for_vf : vf is NULL\n");
1216 return ECORE_UNKNOWN_ERROR;
1219 if (vf->bulletin.p_virt)
1220 OSAL_MEMSET(vf->bulletin.p_virt, 0,
1221 sizeof(*vf->bulletin.p_virt));
1223 OSAL_MEMSET(&vf->p_vf_info, 0, sizeof(vf->p_vf_info));
1225 /* Get the link configuration back in bulletin so
1226 * that when VFs are re-enabled they get the actual
1227 * link configuration.
1229 OSAL_MEMCPY(¶ms, ecore_mcp_get_link_params(p_hwfn), sizeof(params));
1230 OSAL_MEMCPY(&link, ecore_mcp_get_link_state(p_hwfn), sizeof(link));
1231 OSAL_MEMCPY(&caps, ecore_mcp_get_link_capabilities(p_hwfn),
1233 ecore_iov_set_link(p_hwfn, rel_vf_id, ¶ms, &link, &caps);
1235 /* Forget the VF's acquisition message */
1236 OSAL_MEMSET(&vf->acquire, 0, sizeof(vf->acquire));
1238 /* disablng interrupts and resetting permission table was done during
1239 * vf-close, however, we could get here without going through vf_close
1241 /* Disable Interrupts for VF */
1242 ecore_iov_vf_igu_set_int(p_hwfn, p_ptt, vf, 0);
1244 /* Reset Permission table */
1245 ecore_iov_config_perm_table(p_hwfn, p_ptt, vf, 0);
1249 ecore_iov_free_vf_igu_sbs(p_hwfn, p_ptt, vf);
1253 p_hwfn->pf_iov_info->active_vfs[vf->relative_vf_id / 64] &=
1254 ~(1ULL << (vf->relative_vf_id / 64));
1256 if (IS_LEAD_HWFN(p_hwfn))
1257 p_hwfn->p_dev->p_iov_info->num_vfs--;
1260 return ECORE_SUCCESS;
1263 static bool ecore_iov_tlv_supported(u16 tlvtype)
1265 return tlvtype > CHANNEL_TLV_NONE && tlvtype < CHANNEL_TLV_MAX;
1268 static void ecore_iov_lock_vf_pf_channel(struct ecore_hwfn *p_hwfn,
1269 struct ecore_vf_info *vf, u16 tlv)
1271 /* lock the channel */
1272 /* mutex_lock(&vf->op_mutex); @@@TBD MichalK - add lock... */
1274 /* record the locking op */
1275 /* vf->op_current = tlv; @@@TBD MichalK */
1278 if (ecore_iov_tlv_supported(tlv))
1281 "VF[%d]: vf pf channel locked by %s\n",
1283 ecore_channel_tlvs_string[tlv]);
1287 "VF[%d]: vf pf channel locked by %04x\n",
1288 vf->abs_vf_id, tlv);
1291 static void ecore_iov_unlock_vf_pf_channel(struct ecore_hwfn *p_hwfn,
1292 struct ecore_vf_info *vf,
1295 /* log the unlock */
1296 if (ecore_iov_tlv_supported(expected_tlv))
1299 "VF[%d]: vf pf channel unlocked by %s\n",
1301 ecore_channel_tlvs_string[expected_tlv]);
1305 "VF[%d]: vf pf channel unlocked by %04x\n",
1306 vf->abs_vf_id, expected_tlv);
1308 /* record the locking op */
1309 /* vf->op_current = CHANNEL_TLV_NONE; */
1312 /* place a given tlv on the tlv buffer, continuing current tlv list */
1313 void *ecore_add_tlv(u8 **offset, u16 type, u16 length)
1315 struct channel_tlv *tl = (struct channel_tlv *)*offset;
1318 tl->length = length;
1320 /* Offset should keep pointing to next TLV (the end of the last) */
1323 /* Return a pointer to the start of the added tlv */
1324 return *offset - length;
1327 /* list the types and lengths of the tlvs on the buffer */
1328 void ecore_dp_tlv_list(struct ecore_hwfn *p_hwfn, void *tlvs_list)
1330 u16 i = 1, total_length = 0;
1331 struct channel_tlv *tlv;
1334 /* cast current tlv list entry to channel tlv header */
1335 tlv = (struct channel_tlv *)((u8 *)tlvs_list + total_length);
1338 if (ecore_iov_tlv_supported(tlv->type))
1339 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1340 "TLV number %d: type %s, length %d\n",
1341 i, ecore_channel_tlvs_string[tlv->type],
1344 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1345 "TLV number %d: type %d, length %d\n",
1346 i, tlv->type, tlv->length);
1348 if (tlv->type == CHANNEL_TLV_LIST_END)
1351 /* Validate entry - protect against malicious VFs */
1353 DP_NOTICE(p_hwfn, false, "TLV of length 0 found\n");
1356 total_length += tlv->length;
1357 if (total_length >= sizeof(struct tlv_buffer_size)) {
1358 DP_NOTICE(p_hwfn, false, "TLV ==> Buffer overflow\n");
1366 static void ecore_iov_send_response(struct ecore_hwfn *p_hwfn,
1367 struct ecore_ptt *p_ptt,
1368 struct ecore_vf_info *p_vf,
1369 #ifdef CONFIG_ECORE_SW_CHANNEL
1372 u16 OSAL_UNUSED length,
1376 struct ecore_iov_vf_mbx *mbx = &p_vf->vf_mbx;
1377 struct ecore_dmae_params params;
1380 mbx->reply_virt->default_resp.hdr.status = status;
1382 ecore_dp_tlv_list(p_hwfn, mbx->reply_virt);
1384 #ifdef CONFIG_ECORE_SW_CHANNEL
1385 mbx->sw_mbx.response_size =
1386 length + sizeof(struct channel_list_end_tlv);
1388 if (!p_vf->b_hw_channel)
1392 eng_vf_id = p_vf->abs_vf_id;
1394 OSAL_MEMSET(¶ms, 0, sizeof(struct ecore_dmae_params));
1395 params.flags = ECORE_DMAE_FLAG_VF_DST;
1396 params.dst_vfid = eng_vf_id;
1398 ecore_dmae_host2host(p_hwfn, p_ptt, mbx->reply_phys + sizeof(u64),
1399 mbx->req_virt->first_tlv.reply_address +
1401 (sizeof(union pfvf_tlvs) - sizeof(u64)) / 4,
1404 /* Once PF copies the rc to the VF, the latter can continue and
1405 * and send an additional message. So we have to make sure the
1406 * channel would be re-set to ready prior to that.
1409 GTT_BAR0_MAP_REG_USDM_RAM +
1410 USTORM_VF_PF_CHANNEL_READY_OFFSET(eng_vf_id), 1);
1412 ecore_dmae_host2host(p_hwfn, p_ptt, mbx->reply_phys,
1413 mbx->req_virt->first_tlv.reply_address,
1414 sizeof(u64) / 4, ¶ms);
1416 OSAL_IOV_PF_RESP_TYPE(p_hwfn, p_vf->relative_vf_id, status);
1419 static u16 ecore_iov_vport_to_tlv(enum ecore_iov_vport_update_flag flag)
1422 case ECORE_IOV_VP_UPDATE_ACTIVATE:
1423 return CHANNEL_TLV_VPORT_UPDATE_ACTIVATE;
1424 case ECORE_IOV_VP_UPDATE_VLAN_STRIP:
1425 return CHANNEL_TLV_VPORT_UPDATE_VLAN_STRIP;
1426 case ECORE_IOV_VP_UPDATE_TX_SWITCH:
1427 return CHANNEL_TLV_VPORT_UPDATE_TX_SWITCH;
1428 case ECORE_IOV_VP_UPDATE_MCAST:
1429 return CHANNEL_TLV_VPORT_UPDATE_MCAST;
1430 case ECORE_IOV_VP_UPDATE_ACCEPT_PARAM:
1431 return CHANNEL_TLV_VPORT_UPDATE_ACCEPT_PARAM;
1432 case ECORE_IOV_VP_UPDATE_RSS:
1433 return CHANNEL_TLV_VPORT_UPDATE_RSS;
1434 case ECORE_IOV_VP_UPDATE_ACCEPT_ANY_VLAN:
1435 return CHANNEL_TLV_VPORT_UPDATE_ACCEPT_ANY_VLAN;
1436 case ECORE_IOV_VP_UPDATE_SGE_TPA:
1437 return CHANNEL_TLV_VPORT_UPDATE_SGE_TPA;
1443 static u16 ecore_iov_prep_vp_update_resp_tlvs(struct ecore_hwfn *p_hwfn,
1444 struct ecore_vf_info *p_vf,
1445 struct ecore_iov_vf_mbx *p_mbx,
1446 u8 status, u16 tlvs_mask,
1449 struct pfvf_def_resp_tlv *resp;
1450 u16 size, total_len, i;
1452 OSAL_MEMSET(p_mbx->reply_virt, 0, sizeof(union pfvf_tlvs));
1453 p_mbx->offset = (u8 *)p_mbx->reply_virt;
1454 size = sizeof(struct pfvf_def_resp_tlv);
1457 ecore_add_tlv(&p_mbx->offset, CHANNEL_TLV_VPORT_UPDATE, size);
1459 /* Prepare response for all extended tlvs if they are found by PF */
1460 for (i = 0; i < ECORE_IOV_VP_UPDATE_MAX; i++) {
1461 if (!(tlvs_mask & (1 << i)))
1464 resp = ecore_add_tlv(&p_mbx->offset, ecore_iov_vport_to_tlv(i),
1467 if (tlvs_accepted & (1 << i))
1468 resp->hdr.status = status;
1470 resp->hdr.status = PFVF_STATUS_NOT_SUPPORTED;
1472 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1473 "VF[%d] - vport_update resp: TLV %d, status %02x\n",
1474 p_vf->relative_vf_id,
1475 ecore_iov_vport_to_tlv(i),
1481 ecore_add_tlv(&p_mbx->offset, CHANNEL_TLV_LIST_END,
1482 sizeof(struct channel_list_end_tlv));
1487 static void ecore_iov_prepare_resp(struct ecore_hwfn *p_hwfn,
1488 struct ecore_ptt *p_ptt,
1489 struct ecore_vf_info *vf_info,
1490 u16 type, u16 length, u8 status)
1492 struct ecore_iov_vf_mbx *mbx = &vf_info->vf_mbx;
1494 mbx->offset = (u8 *)mbx->reply_virt;
1496 ecore_add_tlv(&mbx->offset, type, length);
1497 ecore_add_tlv(&mbx->offset, CHANNEL_TLV_LIST_END,
1498 sizeof(struct channel_list_end_tlv));
1500 ecore_iov_send_response(p_hwfn, p_ptt, vf_info, length, status);
1503 struct ecore_public_vf_info
1504 *ecore_iov_get_public_vf_info(struct ecore_hwfn *p_hwfn,
1506 bool b_enabled_only)
1508 struct ecore_vf_info *vf = OSAL_NULL;
1510 vf = ecore_iov_get_vf_info(p_hwfn, relative_vf_id, b_enabled_only);
1514 return &vf->p_vf_info;
1517 static void ecore_iov_vf_cleanup(struct ecore_hwfn *p_hwfn,
1518 struct ecore_vf_info *p_vf)
1521 p_vf->vf_bulletin = 0;
1522 p_vf->vport_instance = 0;
1523 p_vf->configured_features = 0;
1525 /* If VF previously requested less resources, go back to default */
1526 p_vf->num_rxqs = p_vf->num_sbs;
1527 p_vf->num_txqs = p_vf->num_sbs;
1529 p_vf->num_active_rxqs = 0;
1531 for (i = 0; i < ECORE_MAX_VF_CHAINS_PER_PF; i++) {
1532 struct ecore_vf_queue *p_queue = &p_vf->vf_queues[i];
1534 for (j = 0; j < MAX_QUEUES_PER_QZONE; j++) {
1535 if (!p_queue->cids[j].p_cid)
1538 ecore_eth_queue_cid_release(p_hwfn,
1539 p_queue->cids[j].p_cid);
1540 p_queue->cids[j].p_cid = OSAL_NULL;
1544 OSAL_MEMSET(&p_vf->shadow_config, 0, sizeof(p_vf->shadow_config));
1545 OSAL_MEMSET(&p_vf->acquire, 0, sizeof(p_vf->acquire));
1546 OSAL_IOV_VF_CLEANUP(p_hwfn, p_vf->relative_vf_id);
1549 /* Returns either 0, or log(size) */
1550 static u32 ecore_iov_vf_db_bar_size(struct ecore_hwfn *p_hwfn,
1551 struct ecore_ptt *p_ptt)
1553 u32 val = ecore_rd(p_hwfn, p_ptt, PGLUE_B_REG_VF_BAR1_SIZE);
1561 ecore_iov_vf_mbx_acquire_resc_cids(struct ecore_hwfn *p_hwfn,
1562 struct ecore_ptt *p_ptt,
1563 struct ecore_vf_info *p_vf,
1564 struct vf_pf_resc_request *p_req,
1565 struct pf_vf_resc *p_resp)
1567 u8 num_vf_cons = p_hwfn->pf_params.eth_pf_params.num_vf_cons;
1568 u8 db_size = DB_ADDR_VF(1, DQ_DEMS_LEGACY) -
1569 DB_ADDR_VF(0, DQ_DEMS_LEGACY);
1572 p_resp->num_cids = OSAL_MIN_T(u8, p_req->num_cids, num_vf_cons);
1574 /* If VF didn't bother asking for QIDs than don't bother limiting
1575 * number of CIDs. The VF doesn't care about the number, and this
1576 * has the likely result of causing an additional acquisition.
1578 if (!(p_vf->acquire.vfdev_info.capabilities &
1579 VFPF_ACQUIRE_CAP_QUEUE_QIDS))
1582 /* If doorbell bar was mapped by VF, limit the VF CIDs to an amount
1583 * that would make sure doorbells for all CIDs fall within the bar.
1584 * If it doesn't, make sure regview window is sufficient.
1586 if (p_vf->acquire.vfdev_info.capabilities &
1587 VFPF_ACQUIRE_CAP_PHYSICAL_BAR) {
1588 bar_size = ecore_iov_vf_db_bar_size(p_hwfn, p_ptt);
1590 bar_size = 1 << bar_size;
1592 if (ECORE_IS_CMT(p_hwfn->p_dev))
1595 bar_size = PXP_VF_BAR0_DQ_LENGTH;
1598 if (bar_size / db_size < 256)
1599 p_resp->num_cids = OSAL_MIN_T(u8, p_resp->num_cids,
1600 (u8)(bar_size / db_size));
1603 static u8 ecore_iov_vf_mbx_acquire_resc(struct ecore_hwfn *p_hwfn,
1604 struct ecore_ptt *p_ptt,
1605 struct ecore_vf_info *p_vf,
1606 struct vf_pf_resc_request *p_req,
1607 struct pf_vf_resc *p_resp)
1611 /* Queue related information */
1612 p_resp->num_rxqs = p_vf->num_rxqs;
1613 p_resp->num_txqs = p_vf->num_txqs;
1614 p_resp->num_sbs = p_vf->num_sbs;
1616 for (i = 0; i < p_resp->num_sbs; i++) {
1617 p_resp->hw_sbs[i].hw_sb_id = p_vf->igu_sbs[i];
1618 /* TODO - what's this sb_qid field? Is it deprecated?
1619 * or is there an ecore_client that looks at this?
1621 p_resp->hw_sbs[i].sb_qid = 0;
1624 /* These fields are filled for backward compatibility.
1625 * Unused by modern vfs.
1627 for (i = 0; i < p_resp->num_rxqs; i++) {
1628 ecore_fw_l2_queue(p_hwfn, p_vf->vf_queues[i].fw_rx_qid,
1629 (u16 *)&p_resp->hw_qid[i]);
1633 /* Filter related information */
1634 p_resp->num_mac_filters = OSAL_MIN_T(u8, p_vf->num_mac_filters,
1635 p_req->num_mac_filters);
1636 p_resp->num_vlan_filters = OSAL_MIN_T(u8, p_vf->num_vlan_filters,
1637 p_req->num_vlan_filters);
1639 ecore_iov_vf_mbx_acquire_resc_cids(p_hwfn, p_ptt, p_vf, p_req, p_resp);
1641 /* This isn't really needed/enforced, but some legacy VFs might depend
1642 * on the correct filling of this field.
1644 p_resp->num_mc_filters = ECORE_MAX_MC_ADDRS;
1646 /* Validate sufficient resources for VF */
1647 if (p_resp->num_rxqs < p_req->num_rxqs ||
1648 p_resp->num_txqs < p_req->num_txqs ||
1649 p_resp->num_sbs < p_req->num_sbs ||
1650 p_resp->num_mac_filters < p_req->num_mac_filters ||
1651 p_resp->num_vlan_filters < p_req->num_vlan_filters ||
1652 p_resp->num_mc_filters < p_req->num_mc_filters ||
1653 p_resp->num_cids < p_req->num_cids) {
1654 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1655 "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",
1657 p_req->num_rxqs, p_resp->num_rxqs,
1658 p_req->num_rxqs, p_resp->num_txqs,
1659 p_req->num_sbs, p_resp->num_sbs,
1660 p_req->num_mac_filters, p_resp->num_mac_filters,
1661 p_req->num_vlan_filters, p_resp->num_vlan_filters,
1662 p_req->num_mc_filters, p_resp->num_mc_filters,
1663 p_req->num_cids, p_resp->num_cids);
1665 /* Some legacy OSes are incapable of correctly handling this
1668 if ((p_vf->acquire.vfdev_info.eth_fp_hsi_minor ==
1669 ETH_HSI_VER_NO_PKT_LEN_TUNN) &&
1670 (p_vf->acquire.vfdev_info.os_type ==
1671 VFPF_ACQUIRE_OS_WINDOWS))
1672 return PFVF_STATUS_SUCCESS;
1674 return PFVF_STATUS_NO_RESOURCE;
1677 return PFVF_STATUS_SUCCESS;
1680 static void ecore_iov_vf_mbx_acquire_stats(struct pfvf_stats_info *p_stats)
1682 p_stats->mstats.address = PXP_VF_BAR0_START_MSDM_ZONE_B +
1683 OFFSETOF(struct mstorm_vf_zone,
1684 non_trigger.eth_queue_stat);
1685 p_stats->mstats.len = sizeof(struct eth_mstorm_per_queue_stat);
1686 p_stats->ustats.address = PXP_VF_BAR0_START_USDM_ZONE_B +
1687 OFFSETOF(struct ustorm_vf_zone,
1688 non_trigger.eth_queue_stat);
1689 p_stats->ustats.len = sizeof(struct eth_ustorm_per_queue_stat);
1690 p_stats->pstats.address = PXP_VF_BAR0_START_PSDM_ZONE_B +
1691 OFFSETOF(struct pstorm_vf_zone,
1692 non_trigger.eth_queue_stat);
1693 p_stats->pstats.len = sizeof(struct eth_pstorm_per_queue_stat);
1694 p_stats->tstats.address = 0;
1695 p_stats->tstats.len = 0;
1698 static void ecore_iov_vf_mbx_acquire(struct ecore_hwfn *p_hwfn,
1699 struct ecore_ptt *p_ptt,
1700 struct ecore_vf_info *vf)
1702 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
1703 struct pfvf_acquire_resp_tlv *resp = &mbx->reply_virt->acquire_resp;
1704 struct pf_vf_pfdev_info *pfdev_info = &resp->pfdev_info;
1705 struct vfpf_acquire_tlv *req = &mbx->req_virt->acquire;
1706 u8 vfpf_status = PFVF_STATUS_NOT_SUPPORTED;
1707 struct pf_vf_resc *resc = &resp->resc;
1708 enum _ecore_status_t rc;
1710 OSAL_MEMSET(resp, 0, sizeof(*resp));
1712 /* Write the PF version so that VF would know which version
1713 * is supported - might be later overridden. This guarantees that
1714 * VF could recognize legacy PF based on lack of versions in reply.
1716 pfdev_info->major_fp_hsi = ETH_HSI_VER_MAJOR;
1717 pfdev_info->minor_fp_hsi = ETH_HSI_VER_MINOR;
1719 /* TODO - not doing anything is bad since we'll assert, but this isn't
1720 * necessarily the right behavior - perhaps we should have allowed some
1723 if (vf->state != VF_FREE &&
1724 vf->state != VF_STOPPED) {
1725 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1726 "VF[%d] sent ACQUIRE but is already in state %d - fail request\n",
1727 vf->abs_vf_id, vf->state);
1731 /* Validate FW compatibility */
1732 if (req->vfdev_info.eth_fp_hsi_major != ETH_HSI_VER_MAJOR) {
1733 if (req->vfdev_info.capabilities &
1734 VFPF_ACQUIRE_CAP_PRE_FP_HSI) {
1735 struct vf_pf_vfdev_info *p_vfdev = &req->vfdev_info;
1737 /* This legacy support would need to be removed once
1738 * the major has changed.
1740 OSAL_BUILD_BUG_ON(ETH_HSI_VER_MAJOR != 3);
1742 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1743 "VF[%d] is pre-fastpath HSI\n",
1745 p_vfdev->eth_fp_hsi_major = ETH_HSI_VER_MAJOR;
1746 p_vfdev->eth_fp_hsi_minor = ETH_HSI_VER_NO_PKT_LEN_TUNN;
1749 "VF[%d] needs fastpath HSI %02x.%02x, which is"
1750 " incompatible with loaded FW's faspath"
1753 req->vfdev_info.eth_fp_hsi_major,
1754 req->vfdev_info.eth_fp_hsi_minor,
1755 ETH_HSI_VER_MAJOR, ETH_HSI_VER_MINOR);
1761 /* On 100g PFs, prevent old VFs from loading */
1762 if (ECORE_IS_CMT(p_hwfn->p_dev) &&
1763 !(req->vfdev_info.capabilities & VFPF_ACQUIRE_CAP_100G)) {
1765 "VF[%d] is running an old driver that doesn't support"
1771 #ifndef __EXTRACT__LINUX__
1772 if (OSAL_IOV_VF_ACQUIRE(p_hwfn, vf->relative_vf_id) != ECORE_SUCCESS) {
1773 vfpf_status = PFVF_STATUS_NOT_SUPPORTED;
1778 /* Store the acquire message */
1779 OSAL_MEMCPY(&vf->acquire, req, sizeof(vf->acquire));
1781 vf->opaque_fid = req->vfdev_info.opaque_fid;
1783 vf->vf_bulletin = req->bulletin_addr;
1784 vf->bulletin.size = (vf->bulletin.size < req->bulletin_size) ?
1785 vf->bulletin.size : req->bulletin_size;
1787 /* fill in pfdev info */
1788 pfdev_info->chip_num = p_hwfn->p_dev->chip_num;
1789 pfdev_info->db_size = 0; /* @@@ TBD MichalK Vf Doorbells */
1790 pfdev_info->indices_per_sb = PIS_PER_SB_E4;
1792 pfdev_info->capabilities = PFVF_ACQUIRE_CAP_DEFAULT_UNTAGGED |
1793 PFVF_ACQUIRE_CAP_POST_FW_OVERRIDE;
1794 if (ECORE_IS_CMT(p_hwfn->p_dev))
1795 pfdev_info->capabilities |= PFVF_ACQUIRE_CAP_100G;
1797 /* Share our ability to use multiple queue-ids only with VFs
1800 if (req->vfdev_info.capabilities & VFPF_ACQUIRE_CAP_QUEUE_QIDS)
1801 pfdev_info->capabilities |= PFVF_ACQUIRE_CAP_QUEUE_QIDS;
1803 /* Share the sizes of the bars with VF */
1804 resp->pfdev_info.bar_size = (u8)ecore_iov_vf_db_bar_size(p_hwfn,
1807 ecore_iov_vf_mbx_acquire_stats(&pfdev_info->stats_info);
1809 OSAL_MEMCPY(pfdev_info->port_mac, p_hwfn->hw_info.hw_mac_addr,
1812 pfdev_info->fw_major = FW_MAJOR_VERSION;
1813 pfdev_info->fw_minor = FW_MINOR_VERSION;
1814 pfdev_info->fw_rev = FW_REVISION_VERSION;
1815 pfdev_info->fw_eng = FW_ENGINEERING_VERSION;
1817 /* Incorrect when legacy, but doesn't matter as legacy isn't reading
1820 pfdev_info->minor_fp_hsi = OSAL_MIN_T(u8, ETH_HSI_VER_MINOR,
1821 req->vfdev_info.eth_fp_hsi_minor);
1822 pfdev_info->os_type = OSAL_IOV_GET_OS_TYPE();
1823 ecore_mcp_get_mfw_ver(p_hwfn, p_ptt, &pfdev_info->mfw_ver,
1826 pfdev_info->dev_type = p_hwfn->p_dev->type;
1827 pfdev_info->chip_rev = p_hwfn->p_dev->chip_rev;
1829 /* Fill resources available to VF; Make sure there are enough to
1830 * satisfy the VF's request.
1832 vfpf_status = ecore_iov_vf_mbx_acquire_resc(p_hwfn, p_ptt, vf,
1833 &req->resc_request, resc);
1834 if (vfpf_status != PFVF_STATUS_SUCCESS)
1837 /* Start the VF in FW */
1838 rc = ecore_sp_vf_start(p_hwfn, vf);
1839 if (rc != ECORE_SUCCESS) {
1840 DP_NOTICE(p_hwfn, true, "Failed to start VF[%02x]\n",
1842 vfpf_status = PFVF_STATUS_FAILURE;
1846 /* Fill agreed size of bulletin board in response, and post
1847 * an initial image to the bulletin board.
1849 resp->bulletin_size = vf->bulletin.size;
1850 ecore_iov_post_vf_bulletin(p_hwfn, vf->relative_vf_id, p_ptt);
1852 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1853 "VF[%d] ACQUIRE_RESPONSE: pfdev_info- chip_num=0x%x,"
1854 " db_size=%d, idx_per_sb=%d, pf_cap=0x%lx\n"
1855 "resources- n_rxq-%d, n_txq-%d, n_sbs-%d, n_macs-%d,"
1857 vf->abs_vf_id, resp->pfdev_info.chip_num,
1858 resp->pfdev_info.db_size, resp->pfdev_info.indices_per_sb,
1859 (unsigned long)resp->pfdev_info.capabilities, resc->num_rxqs,
1860 resc->num_txqs, resc->num_sbs, resc->num_mac_filters,
1861 resc->num_vlan_filters);
1863 vf->state = VF_ACQUIRED;
1866 /* Prepare Response */
1867 ecore_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_ACQUIRE,
1868 sizeof(struct pfvf_acquire_resp_tlv),
1872 static enum _ecore_status_t
1873 __ecore_iov_spoofchk_set(struct ecore_hwfn *p_hwfn,
1874 struct ecore_vf_info *p_vf, bool val)
1876 struct ecore_sp_vport_update_params params;
1877 enum _ecore_status_t rc;
1879 if (val == p_vf->spoof_chk) {
1880 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1881 "Spoofchk value[%d] is already configured\n", val);
1882 return ECORE_SUCCESS;
1885 OSAL_MEMSET(¶ms, 0, sizeof(struct ecore_sp_vport_update_params));
1886 params.opaque_fid = p_vf->opaque_fid;
1887 params.vport_id = p_vf->vport_id;
1888 params.update_anti_spoofing_en_flg = 1;
1889 params.anti_spoofing_en = val;
1891 rc = ecore_sp_vport_update(p_hwfn, ¶ms, ECORE_SPQ_MODE_EBLOCK,
1893 if (rc == ECORE_SUCCESS) {
1894 p_vf->spoof_chk = val;
1895 p_vf->req_spoofchk_val = p_vf->spoof_chk;
1896 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1897 "Spoofchk val[%d] configured\n", val);
1899 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1900 "Spoofchk configuration[val:%d] failed for VF[%d]\n",
1901 val, p_vf->relative_vf_id);
1907 static enum _ecore_status_t
1908 ecore_iov_reconfigure_unicast_vlan(struct ecore_hwfn *p_hwfn,
1909 struct ecore_vf_info *p_vf)
1911 struct ecore_filter_ucast filter;
1912 enum _ecore_status_t rc = ECORE_SUCCESS;
1915 OSAL_MEMSET(&filter, 0, sizeof(filter));
1916 filter.is_rx_filter = 1;
1917 filter.is_tx_filter = 1;
1918 filter.vport_to_add_to = p_vf->vport_id;
1919 filter.opcode = ECORE_FILTER_ADD;
1921 /* Reconfigure vlans */
1922 for (i = 0; i < ECORE_ETH_VF_NUM_VLAN_FILTERS + 1; i++) {
1923 if (!p_vf->shadow_config.vlans[i].used)
1926 filter.type = ECORE_FILTER_VLAN;
1927 filter.vlan = p_vf->shadow_config.vlans[i].vid;
1928 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1929 "Reconfiguring VLAN [0x%04x] for VF [%04x]\n",
1930 filter.vlan, p_vf->relative_vf_id);
1931 rc = ecore_sp_eth_filter_ucast(p_hwfn, p_vf->opaque_fid,
1932 &filter, ECORE_SPQ_MODE_CB,
1935 DP_NOTICE(p_hwfn, true,
1936 "Failed to configure VLAN [%04x]"
1938 filter.vlan, p_vf->relative_vf_id);
1946 static enum _ecore_status_t
1947 ecore_iov_reconfigure_unicast_shadow(struct ecore_hwfn *p_hwfn,
1948 struct ecore_vf_info *p_vf, u64 events)
1950 enum _ecore_status_t rc = ECORE_SUCCESS;
1952 /*TODO - what about MACs? */
1954 if ((events & (1 << VLAN_ADDR_FORCED)) &&
1955 !(p_vf->configured_features & (1 << VLAN_ADDR_FORCED)))
1956 rc = ecore_iov_reconfigure_unicast_vlan(p_hwfn, p_vf);
1961 static enum _ecore_status_t
1962 ecore_iov_configure_vport_forced(struct ecore_hwfn *p_hwfn,
1963 struct ecore_vf_info *p_vf,
1966 enum _ecore_status_t rc = ECORE_SUCCESS;
1967 struct ecore_filter_ucast filter;
1969 if (!p_vf->vport_instance)
1972 if ((events & (1 << MAC_ADDR_FORCED)) ||
1973 p_hwfn->pf_params.eth_pf_params.allow_vf_mac_change ||
1974 p_vf->p_vf_info.is_trusted_configured) {
1975 /* Since there's no way [currently] of removing the MAC,
1976 * we can always assume this means we need to force it.
1978 OSAL_MEMSET(&filter, 0, sizeof(filter));
1979 filter.type = ECORE_FILTER_MAC;
1980 filter.opcode = ECORE_FILTER_REPLACE;
1981 filter.is_rx_filter = 1;
1982 filter.is_tx_filter = 1;
1983 filter.vport_to_add_to = p_vf->vport_id;
1984 OSAL_MEMCPY(filter.mac, p_vf->bulletin.p_virt->mac, ETH_ALEN);
1986 rc = ecore_sp_eth_filter_ucast(p_hwfn, p_vf->opaque_fid,
1988 ECORE_SPQ_MODE_CB, OSAL_NULL);
1990 DP_NOTICE(p_hwfn, true,
1991 "PF failed to configure MAC for VF\n");
1995 if (p_hwfn->pf_params.eth_pf_params.allow_vf_mac_change ||
1996 p_vf->p_vf_info.is_trusted_configured)
1997 p_vf->configured_features |=
1998 1 << VFPF_BULLETIN_MAC_ADDR;
2000 p_vf->configured_features |= 1 << MAC_ADDR_FORCED;
2003 if (events & (1 << VLAN_ADDR_FORCED)) {
2004 struct ecore_sp_vport_update_params vport_update;
2008 OSAL_MEMSET(&filter, 0, sizeof(filter));
2009 filter.type = ECORE_FILTER_VLAN;
2010 filter.is_rx_filter = 1;
2011 filter.is_tx_filter = 1;
2012 filter.vport_to_add_to = p_vf->vport_id;
2013 filter.vlan = p_vf->bulletin.p_virt->pvid;
2014 filter.opcode = filter.vlan ? ECORE_FILTER_REPLACE :
2017 /* Send the ramrod */
2018 rc = ecore_sp_eth_filter_ucast(p_hwfn, p_vf->opaque_fid,
2020 ECORE_SPQ_MODE_CB, OSAL_NULL);
2022 DP_NOTICE(p_hwfn, true,
2023 "PF failed to configure VLAN for VF\n");
2027 /* Update the default-vlan & silent vlan stripping */
2028 OSAL_MEMSET(&vport_update, 0, sizeof(vport_update));
2029 vport_update.opaque_fid = p_vf->opaque_fid;
2030 vport_update.vport_id = p_vf->vport_id;
2031 vport_update.update_default_vlan_enable_flg = 1;
2032 vport_update.default_vlan_enable_flg = filter.vlan ? 1 : 0;
2033 vport_update.update_default_vlan_flg = 1;
2034 vport_update.default_vlan = filter.vlan;
2036 vport_update.update_inner_vlan_removal_flg = 1;
2037 removal = filter.vlan ?
2038 1 : p_vf->shadow_config.inner_vlan_removal;
2039 vport_update.inner_vlan_removal_flg = removal;
2040 vport_update.silent_vlan_removal_flg = filter.vlan ? 1 : 0;
2041 rc = ecore_sp_vport_update(p_hwfn, &vport_update,
2042 ECORE_SPQ_MODE_EBLOCK, OSAL_NULL);
2044 DP_NOTICE(p_hwfn, true,
2045 "PF failed to configure VF vport for vlan\n");
2049 /* Update all the Rx queues */
2050 for (i = 0; i < ECORE_MAX_VF_CHAINS_PER_PF; i++) {
2051 struct ecore_vf_queue *p_queue = &p_vf->vf_queues[i];
2052 struct ecore_queue_cid *p_cid = OSAL_NULL;
2054 /* There can be at most 1 Rx queue on qzone. Find it */
2055 p_cid = ecore_iov_get_vf_rx_queue_cid(p_queue);
2056 if (p_cid == OSAL_NULL)
2059 rc = ecore_sp_eth_rx_queues_update(p_hwfn,
2062 ECORE_SPQ_MODE_EBLOCK,
2065 DP_NOTICE(p_hwfn, true,
2066 "Failed to send Rx update"
2067 " fo queue[0x%04x]\n",
2068 p_cid->rel.queue_id);
2074 p_vf->configured_features |= 1 << VLAN_ADDR_FORCED;
2076 p_vf->configured_features &= ~(1 << VLAN_ADDR_FORCED);
2079 /* If forced features are terminated, we need to configure the shadow
2080 * configuration back again.
2083 ecore_iov_reconfigure_unicast_shadow(p_hwfn, p_vf, events);
2088 static void ecore_iov_vf_mbx_start_vport(struct ecore_hwfn *p_hwfn,
2089 struct ecore_ptt *p_ptt,
2090 struct ecore_vf_info *vf)
2092 struct ecore_sp_vport_start_params params = { 0 };
2093 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
2094 struct vfpf_vport_start_tlv *start;
2095 u8 status = PFVF_STATUS_SUCCESS;
2096 struct ecore_vf_info *vf_info;
2099 enum _ecore_status_t rc;
2101 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vf->relative_vf_id, true);
2103 DP_NOTICE(p_hwfn->p_dev, true,
2104 "Failed to get VF info, invalid vfid [%d]\n",
2105 vf->relative_vf_id);
2109 vf->state = VF_ENABLED;
2110 start = &mbx->req_virt->start_vport;
2112 ecore_iov_enable_vf_traffic(p_hwfn, p_ptt, vf);
2114 /* Initialize Status block in CAU */
2115 for (sb_id = 0; sb_id < vf->num_sbs; sb_id++) {
2116 if (!start->sb_addr[sb_id]) {
2117 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2118 "VF[%d] did not fill the address of SB %d\n",
2119 vf->relative_vf_id, sb_id);
2123 ecore_int_cau_conf_sb(p_hwfn, p_ptt,
2124 start->sb_addr[sb_id],
2129 vf->mtu = start->mtu;
2130 vf->shadow_config.inner_vlan_removal = start->inner_vlan_removal;
2132 /* Take into consideration configuration forced by hypervisor;
2133 * If none is configured, use the supplied VF values [for old
2134 * vfs that would still be fine, since they passed '0' as padding].
2136 p_bitmap = &vf_info->bulletin.p_virt->valid_bitmap;
2137 if (!(*p_bitmap & (1 << VFPF_BULLETIN_UNTAGGED_DEFAULT_FORCED))) {
2138 u8 vf_req = start->only_untagged;
2140 vf_info->bulletin.p_virt->default_only_untagged = vf_req;
2141 *p_bitmap |= 1 << VFPF_BULLETIN_UNTAGGED_DEFAULT;
2144 params.tpa_mode = start->tpa_mode;
2145 params.remove_inner_vlan = start->inner_vlan_removal;
2146 params.tx_switching = true;
2149 if (CHIP_REV_IS_FPGA(p_hwfn->p_dev)) {
2150 DP_NOTICE(p_hwfn, false,
2151 "FPGA: Don't config VF for Tx-switching [no pVFC]\n");
2152 params.tx_switching = false;
2156 params.only_untagged = vf_info->bulletin.p_virt->default_only_untagged;
2157 params.drop_ttl0 = false;
2158 params.concrete_fid = vf->concrete_fid;
2159 params.opaque_fid = vf->opaque_fid;
2160 params.vport_id = vf->vport_id;
2161 params.max_buffers_per_cqe = start->max_buffers_per_cqe;
2162 params.mtu = vf->mtu;
2164 /* Non trusted VFs should enable control frame filtering */
2165 params.check_mac = !vf->p_vf_info.is_trusted_configured;
2167 rc = ecore_sp_eth_vport_start(p_hwfn, ¶ms);
2168 if (rc != ECORE_SUCCESS) {
2170 "ecore_iov_vf_mbx_start_vport returned error %d\n", rc);
2171 status = PFVF_STATUS_FAILURE;
2173 vf->vport_instance++;
2175 /* Force configuration if needed on the newly opened vport */
2176 ecore_iov_configure_vport_forced(p_hwfn, vf, *p_bitmap);
2177 OSAL_IOV_POST_START_VPORT(p_hwfn, vf->relative_vf_id,
2178 vf->vport_id, vf->opaque_fid);
2179 __ecore_iov_spoofchk_set(p_hwfn, vf, vf->req_spoofchk_val);
2182 ecore_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_VPORT_START,
2183 sizeof(struct pfvf_def_resp_tlv), status);
2186 static void ecore_iov_vf_mbx_stop_vport(struct ecore_hwfn *p_hwfn,
2187 struct ecore_ptt *p_ptt,
2188 struct ecore_vf_info *vf)
2190 u8 status = PFVF_STATUS_SUCCESS;
2191 enum _ecore_status_t rc;
2193 OSAL_IOV_VF_VPORT_STOP(p_hwfn, vf);
2194 vf->vport_instance--;
2195 vf->spoof_chk = false;
2197 if ((ecore_iov_validate_active_rxq(vf)) ||
2198 (ecore_iov_validate_active_txq(vf))) {
2199 vf->b_malicious = true;
2200 DP_NOTICE(p_hwfn, false,
2201 "VF [%02x] - considered malicious;"
2202 " Unable to stop RX/TX queuess\n",
2204 status = PFVF_STATUS_MALICIOUS;
2208 rc = ecore_sp_vport_stop(p_hwfn, vf->opaque_fid, vf->vport_id);
2209 if (rc != ECORE_SUCCESS) {
2211 "ecore_iov_vf_mbx_stop_vport returned error %d\n", rc);
2212 status = PFVF_STATUS_FAILURE;
2215 /* Forget the configuration on the vport */
2216 vf->configured_features = 0;
2217 OSAL_MEMSET(&vf->shadow_config, 0, sizeof(vf->shadow_config));
2220 ecore_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_VPORT_TEARDOWN,
2221 sizeof(struct pfvf_def_resp_tlv), status);
2224 static void ecore_iov_vf_mbx_start_rxq_resp(struct ecore_hwfn *p_hwfn,
2225 struct ecore_ptt *p_ptt,
2226 struct ecore_vf_info *vf,
2227 u8 status, bool b_legacy)
2229 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
2230 struct pfvf_start_queue_resp_tlv *p_tlv;
2231 struct vfpf_start_rxq_tlv *req;
2234 mbx->offset = (u8 *)mbx->reply_virt;
2236 /* Taking a bigger struct instead of adding a TLV to list was a
2237 * mistake, but one which we're now stuck with, as some older
2238 * clients assume the size of the previous response.
2241 length = sizeof(*p_tlv);
2243 length = sizeof(struct pfvf_def_resp_tlv);
2245 p_tlv = ecore_add_tlv(&mbx->offset, CHANNEL_TLV_START_RXQ, length);
2246 ecore_add_tlv(&mbx->offset, CHANNEL_TLV_LIST_END,
2247 sizeof(struct channel_list_end_tlv));
2249 /* Update the TLV with the response */
2250 if ((status == PFVF_STATUS_SUCCESS) && !b_legacy) {
2251 req = &mbx->req_virt->start_rxq;
2252 p_tlv->offset = PXP_VF_BAR0_START_MSDM_ZONE_B +
2253 OFFSETOF(struct mstorm_vf_zone,
2254 non_trigger.eth_rx_queue_producers) +
2255 sizeof(struct eth_rx_prod_data) * req->rx_qid;
2258 ecore_iov_send_response(p_hwfn, p_ptt, vf, length, status);
2261 static u8 ecore_iov_vf_mbx_qid(struct ecore_hwfn *p_hwfn,
2262 struct ecore_vf_info *p_vf, bool b_is_tx)
2264 struct ecore_iov_vf_mbx *p_mbx = &p_vf->vf_mbx;
2265 struct vfpf_qid_tlv *p_qid_tlv;
2267 /* Search for the qid if the VF published if its going to provide it */
2268 if (!(p_vf->acquire.vfdev_info.capabilities &
2269 VFPF_ACQUIRE_CAP_QUEUE_QIDS)) {
2271 return ECORE_IOV_LEGACY_QID_TX;
2273 return ECORE_IOV_LEGACY_QID_RX;
2276 p_qid_tlv = (struct vfpf_qid_tlv *)
2277 ecore_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt,
2279 if (p_qid_tlv == OSAL_NULL) {
2280 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2281 "VF[%2x]: Failed to provide qid\n",
2282 p_vf->relative_vf_id);
2284 return ECORE_IOV_QID_INVALID;
2287 if (p_qid_tlv->qid >= MAX_QUEUES_PER_QZONE) {
2288 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2289 "VF[%02x]: Provided qid out-of-bounds %02x\n",
2290 p_vf->relative_vf_id, p_qid_tlv->qid);
2291 return ECORE_IOV_QID_INVALID;
2294 return p_qid_tlv->qid;
2297 static void ecore_iov_vf_mbx_start_rxq(struct ecore_hwfn *p_hwfn,
2298 struct ecore_ptt *p_ptt,
2299 struct ecore_vf_info *vf)
2301 struct ecore_queue_start_common_params params;
2302 struct ecore_queue_cid_vf_params vf_params;
2303 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
2304 u8 status = PFVF_STATUS_NO_RESOURCE;
2305 u8 qid_usage_idx, vf_legacy = 0;
2306 struct ecore_vf_queue *p_queue;
2307 struct vfpf_start_rxq_tlv *req;
2308 struct ecore_queue_cid *p_cid;
2309 struct ecore_sb_info sb_dummy;
2310 enum _ecore_status_t rc;
2312 req = &mbx->req_virt->start_rxq;
2314 if (!ecore_iov_validate_rxq(p_hwfn, vf, req->rx_qid,
2315 ECORE_IOV_VALIDATE_Q_DISABLE) ||
2316 !ecore_iov_validate_sb(p_hwfn, vf, req->hw_sb))
2319 qid_usage_idx = ecore_iov_vf_mbx_qid(p_hwfn, vf, false);
2320 if (qid_usage_idx == ECORE_IOV_QID_INVALID)
2323 p_queue = &vf->vf_queues[req->rx_qid];
2324 if (p_queue->cids[qid_usage_idx].p_cid)
2327 vf_legacy = ecore_vf_calculate_legacy(vf);
2329 /* Acquire a new queue-cid */
2330 OSAL_MEMSET(¶ms, 0, sizeof(params));
2331 params.queue_id = (u8)p_queue->fw_rx_qid;
2332 params.vport_id = vf->vport_id;
2333 params.stats_id = vf->abs_vf_id + 0x10;
2335 /* Since IGU index is passed via sb_info, construct a dummy one */
2336 OSAL_MEM_ZERO(&sb_dummy, sizeof(sb_dummy));
2337 sb_dummy.igu_sb_id = req->hw_sb;
2338 params.p_sb = &sb_dummy;
2339 params.sb_idx = req->sb_index;
2341 OSAL_MEM_ZERO(&vf_params, sizeof(vf_params));
2342 vf_params.vfid = vf->relative_vf_id;
2343 vf_params.vf_qid = (u8)req->rx_qid;
2344 vf_params.vf_legacy = vf_legacy;
2345 vf_params.qid_usage_idx = qid_usage_idx;
2347 p_cid = ecore_eth_queue_to_cid(p_hwfn, vf->opaque_fid,
2348 ¶ms, true, &vf_params);
2349 if (p_cid == OSAL_NULL)
2352 /* Legacy VFs have their Producers in a different location, which they
2353 * calculate on their own and clean the producer prior to this.
2355 if (!(vf_legacy & ECORE_QCID_LEGACY_VF_RX_PROD))
2357 GTT_BAR0_MAP_REG_MSDM_RAM +
2358 MSTORM_ETH_VF_PRODS_OFFSET(vf->abs_vf_id, req->rx_qid),
2361 rc = ecore_eth_rxq_start_ramrod(p_hwfn, p_cid,
2366 if (rc != ECORE_SUCCESS) {
2367 status = PFVF_STATUS_FAILURE;
2368 ecore_eth_queue_cid_release(p_hwfn, p_cid);
2370 p_queue->cids[qid_usage_idx].p_cid = p_cid;
2371 p_queue->cids[qid_usage_idx].b_is_tx = false;
2372 status = PFVF_STATUS_SUCCESS;
2373 vf->num_active_rxqs++;
2377 ecore_iov_vf_mbx_start_rxq_resp(p_hwfn, p_ptt, vf, status,
2379 ECORE_QCID_LEGACY_VF_RX_PROD));
2383 ecore_iov_pf_update_tun_response(struct pfvf_update_tunn_param_tlv *p_resp,
2384 struct ecore_tunnel_info *p_tun,
2385 u16 tunn_feature_mask)
2387 p_resp->tunn_feature_mask = tunn_feature_mask;
2388 p_resp->vxlan_mode = p_tun->vxlan.b_mode_enabled;
2389 p_resp->l2geneve_mode = p_tun->l2_geneve.b_mode_enabled;
2390 p_resp->ipgeneve_mode = p_tun->ip_geneve.b_mode_enabled;
2391 p_resp->l2gre_mode = p_tun->l2_gre.b_mode_enabled;
2392 p_resp->ipgre_mode = p_tun->l2_gre.b_mode_enabled;
2393 p_resp->vxlan_clss = p_tun->vxlan.tun_cls;
2394 p_resp->l2gre_clss = p_tun->l2_gre.tun_cls;
2395 p_resp->ipgre_clss = p_tun->ip_gre.tun_cls;
2396 p_resp->l2geneve_clss = p_tun->l2_geneve.tun_cls;
2397 p_resp->ipgeneve_clss = p_tun->ip_geneve.tun_cls;
2398 p_resp->geneve_udp_port = p_tun->geneve_port.port;
2399 p_resp->vxlan_udp_port = p_tun->vxlan_port.port;
2403 __ecore_iov_pf_update_tun_param(struct vfpf_update_tunn_param_tlv *p_req,
2404 struct ecore_tunn_update_type *p_tun,
2405 enum ecore_tunn_mode mask, u8 tun_cls)
2407 if (p_req->tun_mode_update_mask & (1 << mask)) {
2408 p_tun->b_update_mode = true;
2410 if (p_req->tunn_mode & (1 << mask))
2411 p_tun->b_mode_enabled = true;
2414 p_tun->tun_cls = tun_cls;
2418 ecore_iov_pf_update_tun_param(struct vfpf_update_tunn_param_tlv *p_req,
2419 struct ecore_tunn_update_type *p_tun,
2420 struct ecore_tunn_update_udp_port *p_port,
2421 enum ecore_tunn_mode mask,
2422 u8 tun_cls, u8 update_port, u16 port)
2425 p_port->b_update_port = true;
2426 p_port->port = port;
2429 __ecore_iov_pf_update_tun_param(p_req, p_tun, mask, tun_cls);
2433 ecore_iov_pf_validate_tunn_param(struct vfpf_update_tunn_param_tlv *p_req)
2435 bool b_update_requested = false;
2437 if (p_req->tun_mode_update_mask || p_req->update_tun_cls ||
2438 p_req->update_geneve_port || p_req->update_vxlan_port)
2439 b_update_requested = true;
2441 return b_update_requested;
2444 static void ecore_iov_vf_mbx_update_tunn_param(struct ecore_hwfn *p_hwfn,
2445 struct ecore_ptt *p_ptt,
2446 struct ecore_vf_info *p_vf)
2448 struct ecore_tunnel_info *p_tun = &p_hwfn->p_dev->tunnel;
2449 struct ecore_iov_vf_mbx *mbx = &p_vf->vf_mbx;
2450 struct pfvf_update_tunn_param_tlv *p_resp;
2451 struct vfpf_update_tunn_param_tlv *p_req;
2452 enum _ecore_status_t rc = ECORE_SUCCESS;
2453 u8 status = PFVF_STATUS_SUCCESS;
2454 bool b_update_required = false;
2455 struct ecore_tunnel_info tunn;
2456 u16 tunn_feature_mask = 0;
2459 mbx->offset = (u8 *)mbx->reply_virt;
2461 OSAL_MEM_ZERO(&tunn, sizeof(tunn));
2462 p_req = &mbx->req_virt->tunn_param_update;
2464 if (!ecore_iov_pf_validate_tunn_param(p_req)) {
2465 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2466 "No tunnel update requested by VF\n");
2467 status = PFVF_STATUS_FAILURE;
2471 tunn.b_update_rx_cls = p_req->update_tun_cls;
2472 tunn.b_update_tx_cls = p_req->update_tun_cls;
2474 ecore_iov_pf_update_tun_param(p_req, &tunn.vxlan, &tunn.vxlan_port,
2475 ECORE_MODE_VXLAN_TUNN, p_req->vxlan_clss,
2476 p_req->update_vxlan_port,
2478 ecore_iov_pf_update_tun_param(p_req, &tunn.l2_geneve, &tunn.geneve_port,
2479 ECORE_MODE_L2GENEVE_TUNN,
2480 p_req->l2geneve_clss,
2481 p_req->update_geneve_port,
2482 p_req->geneve_port);
2483 __ecore_iov_pf_update_tun_param(p_req, &tunn.ip_geneve,
2484 ECORE_MODE_IPGENEVE_TUNN,
2485 p_req->ipgeneve_clss);
2486 __ecore_iov_pf_update_tun_param(p_req, &tunn.l2_gre,
2487 ECORE_MODE_L2GRE_TUNN,
2489 __ecore_iov_pf_update_tun_param(p_req, &tunn.ip_gre,
2490 ECORE_MODE_IPGRE_TUNN,
2493 /* If PF modifies VF's req then it should
2494 * still return an error in case of partial configuration
2495 * or modified configuration as opposed to requested one.
2497 rc = OSAL_PF_VALIDATE_MODIFY_TUNN_CONFIG(p_hwfn, &tunn_feature_mask,
2498 &b_update_required, &tunn);
2500 if (rc != ECORE_SUCCESS)
2501 status = PFVF_STATUS_FAILURE;
2503 /* If ECORE client is willing to update anything ? */
2504 if (b_update_required) {
2507 rc = ecore_sp_pf_update_tunn_cfg(p_hwfn, p_ptt, &tunn,
2508 ECORE_SPQ_MODE_EBLOCK,
2510 if (rc != ECORE_SUCCESS)
2511 status = PFVF_STATUS_FAILURE;
2513 geneve_port = p_tun->geneve_port.port;
2514 ecore_for_each_vf(p_hwfn, i) {
2515 ecore_iov_bulletin_set_udp_ports(p_hwfn, i,
2516 p_tun->vxlan_port.port,
2522 p_resp = ecore_add_tlv(&mbx->offset,
2523 CHANNEL_TLV_UPDATE_TUNN_PARAM, sizeof(*p_resp));
2525 ecore_iov_pf_update_tun_response(p_resp, p_tun, tunn_feature_mask);
2526 ecore_add_tlv(&mbx->offset, CHANNEL_TLV_LIST_END,
2527 sizeof(struct channel_list_end_tlv));
2529 ecore_iov_send_response(p_hwfn, p_ptt, p_vf, sizeof(*p_resp), status);
2532 static void ecore_iov_vf_mbx_start_txq_resp(struct ecore_hwfn *p_hwfn,
2533 struct ecore_ptt *p_ptt,
2534 struct ecore_vf_info *p_vf,
2538 struct ecore_iov_vf_mbx *mbx = &p_vf->vf_mbx;
2539 struct pfvf_start_queue_resp_tlv *p_tlv;
2540 bool b_legacy = false;
2543 mbx->offset = (u8 *)mbx->reply_virt;
2545 /* Taking a bigger struct instead of adding a TLV to list was a
2546 * mistake, but one which we're now stuck with, as some older
2547 * clients assume the size of the previous response.
2549 if (p_vf->acquire.vfdev_info.eth_fp_hsi_minor ==
2550 ETH_HSI_VER_NO_PKT_LEN_TUNN)
2554 length = sizeof(*p_tlv);
2556 length = sizeof(struct pfvf_def_resp_tlv);
2558 p_tlv = ecore_add_tlv(&mbx->offset, CHANNEL_TLV_START_TXQ, length);
2559 ecore_add_tlv(&mbx->offset, CHANNEL_TLV_LIST_END,
2560 sizeof(struct channel_list_end_tlv));
2562 /* Update the TLV with the response */
2563 if ((status == PFVF_STATUS_SUCCESS) && !b_legacy)
2564 p_tlv->offset = DB_ADDR_VF(cid, DQ_DEMS_LEGACY);
2566 ecore_iov_send_response(p_hwfn, p_ptt, p_vf, length, status);
2569 static void ecore_iov_vf_mbx_start_txq(struct ecore_hwfn *p_hwfn,
2570 struct ecore_ptt *p_ptt,
2571 struct ecore_vf_info *vf)
2573 struct ecore_queue_start_common_params params;
2574 struct ecore_queue_cid_vf_params vf_params;
2575 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
2576 u8 status = PFVF_STATUS_NO_RESOURCE;
2577 struct ecore_vf_queue *p_queue;
2578 struct vfpf_start_txq_tlv *req;
2579 struct ecore_queue_cid *p_cid;
2580 struct ecore_sb_info sb_dummy;
2581 u8 qid_usage_idx, vf_legacy;
2583 enum _ecore_status_t rc;
2586 OSAL_MEMSET(¶ms, 0, sizeof(params));
2587 req = &mbx->req_virt->start_txq;
2589 if (!ecore_iov_validate_txq(p_hwfn, vf, req->tx_qid,
2590 ECORE_IOV_VALIDATE_Q_NA) ||
2591 !ecore_iov_validate_sb(p_hwfn, vf, req->hw_sb))
2594 qid_usage_idx = ecore_iov_vf_mbx_qid(p_hwfn, vf, true);
2595 if (qid_usage_idx == ECORE_IOV_QID_INVALID)
2598 p_queue = &vf->vf_queues[req->tx_qid];
2599 if (p_queue->cids[qid_usage_idx].p_cid)
2602 vf_legacy = ecore_vf_calculate_legacy(vf);
2604 /* Acquire a new queue-cid */
2605 params.queue_id = p_queue->fw_tx_qid;
2606 params.vport_id = vf->vport_id;
2607 params.stats_id = vf->abs_vf_id + 0x10;
2609 /* Since IGU index is passed via sb_info, construct a dummy one */
2610 OSAL_MEM_ZERO(&sb_dummy, sizeof(sb_dummy));
2611 sb_dummy.igu_sb_id = req->hw_sb;
2612 params.p_sb = &sb_dummy;
2613 params.sb_idx = req->sb_index;
2615 OSAL_MEM_ZERO(&vf_params, sizeof(vf_params));
2616 vf_params.vfid = vf->relative_vf_id;
2617 vf_params.vf_qid = (u8)req->tx_qid;
2618 vf_params.vf_legacy = vf_legacy;
2619 vf_params.qid_usage_idx = qid_usage_idx;
2621 p_cid = ecore_eth_queue_to_cid(p_hwfn, vf->opaque_fid,
2622 ¶ms, false, &vf_params);
2623 if (p_cid == OSAL_NULL)
2626 pq = ecore_get_cm_pq_idx_vf(p_hwfn,
2627 vf->relative_vf_id);
2628 rc = ecore_eth_txq_start_ramrod(p_hwfn, p_cid,
2629 req->pbl_addr, req->pbl_size, pq);
2630 if (rc != ECORE_SUCCESS) {
2631 status = PFVF_STATUS_FAILURE;
2632 ecore_eth_queue_cid_release(p_hwfn, p_cid);
2634 status = PFVF_STATUS_SUCCESS;
2635 p_queue->cids[qid_usage_idx].p_cid = p_cid;
2636 p_queue->cids[qid_usage_idx].b_is_tx = true;
2641 ecore_iov_vf_mbx_start_txq_resp(p_hwfn, p_ptt, vf,
2645 static enum _ecore_status_t ecore_iov_vf_stop_rxqs(struct ecore_hwfn *p_hwfn,
2646 struct ecore_vf_info *vf,
2649 bool cqe_completion)
2651 struct ecore_vf_queue *p_queue;
2652 enum _ecore_status_t rc = ECORE_SUCCESS;
2654 if (!ecore_iov_validate_rxq(p_hwfn, vf, rxq_id,
2655 ECORE_IOV_VALIDATE_Q_NA)) {
2656 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2657 "VF[%d] Tried Closing Rx 0x%04x.%02x which is inactive\n",
2658 vf->relative_vf_id, rxq_id, qid_usage_idx);
2662 p_queue = &vf->vf_queues[rxq_id];
2664 /* We've validated the index and the existence of the active RXQ -
2665 * now we need to make sure that it's using the correct qid.
2667 if (!p_queue->cids[qid_usage_idx].p_cid ||
2668 p_queue->cids[qid_usage_idx].b_is_tx) {
2669 struct ecore_queue_cid *p_cid;
2671 p_cid = ecore_iov_get_vf_rx_queue_cid(p_queue);
2672 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2673 "VF[%d] - Tried Closing Rx 0x%04x.%02x, but Rx is at %04x.%02x\n",
2674 vf->relative_vf_id, rxq_id, qid_usage_idx,
2675 rxq_id, p_cid->qid_usage_idx);
2679 /* Now that we know we have a valid Rx-queue - close it */
2680 rc = ecore_eth_rx_queue_stop(p_hwfn,
2681 p_queue->cids[qid_usage_idx].p_cid,
2682 false, cqe_completion);
2683 if (rc != ECORE_SUCCESS)
2686 p_queue->cids[qid_usage_idx].p_cid = OSAL_NULL;
2687 vf->num_active_rxqs--;
2689 return ECORE_SUCCESS;
2692 static enum _ecore_status_t ecore_iov_vf_stop_txqs(struct ecore_hwfn *p_hwfn,
2693 struct ecore_vf_info *vf,
2697 struct ecore_vf_queue *p_queue;
2698 enum _ecore_status_t rc = ECORE_SUCCESS;
2700 if (!ecore_iov_validate_txq(p_hwfn, vf, txq_id,
2701 ECORE_IOV_VALIDATE_Q_NA))
2704 p_queue = &vf->vf_queues[txq_id];
2705 if (!p_queue->cids[qid_usage_idx].p_cid ||
2706 !p_queue->cids[qid_usage_idx].b_is_tx)
2709 rc = ecore_eth_tx_queue_stop(p_hwfn,
2710 p_queue->cids[qid_usage_idx].p_cid);
2711 if (rc != ECORE_SUCCESS)
2714 p_queue->cids[qid_usage_idx].p_cid = OSAL_NULL;
2715 return ECORE_SUCCESS;
2718 static void ecore_iov_vf_mbx_stop_rxqs(struct ecore_hwfn *p_hwfn,
2719 struct ecore_ptt *p_ptt,
2720 struct ecore_vf_info *vf)
2722 u16 length = sizeof(struct pfvf_def_resp_tlv);
2723 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
2724 u8 status = PFVF_STATUS_FAILURE;
2725 struct vfpf_stop_rxqs_tlv *req;
2727 enum _ecore_status_t rc;
2729 /* Starting with CHANNEL_TLV_QID, it's assumed the 'num_rxqs'
2730 * would be one. Since no older ecore passed multiple queues
2731 * using this API, sanitize on the value.
2733 req = &mbx->req_virt->stop_rxqs;
2734 if (req->num_rxqs != 1) {
2735 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2736 "Odd; VF[%d] tried stopping multiple Rx queues\n",
2737 vf->relative_vf_id);
2738 status = PFVF_STATUS_NOT_SUPPORTED;
2742 /* Find which qid-index is associated with the queue */
2743 qid_usage_idx = ecore_iov_vf_mbx_qid(p_hwfn, vf, false);
2744 if (qid_usage_idx == ECORE_IOV_QID_INVALID)
2747 rc = ecore_iov_vf_stop_rxqs(p_hwfn, vf, req->rx_qid,
2748 qid_usage_idx, req->cqe_completion);
2749 if (rc == ECORE_SUCCESS)
2750 status = PFVF_STATUS_SUCCESS;
2752 ecore_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_STOP_RXQS,
2756 static void ecore_iov_vf_mbx_stop_txqs(struct ecore_hwfn *p_hwfn,
2757 struct ecore_ptt *p_ptt,
2758 struct ecore_vf_info *vf)
2760 u16 length = sizeof(struct pfvf_def_resp_tlv);
2761 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
2762 u8 status = PFVF_STATUS_FAILURE;
2763 struct vfpf_stop_txqs_tlv *req;
2765 enum _ecore_status_t rc;
2767 /* Starting with CHANNEL_TLV_QID, it's assumed the 'num_txqs'
2768 * would be one. Since no older ecore passed multiple queues
2769 * using this API, sanitize on the value.
2771 req = &mbx->req_virt->stop_txqs;
2772 if (req->num_txqs != 1) {
2773 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2774 "Odd; VF[%d] tried stopping multiple Tx queues\n",
2775 vf->relative_vf_id);
2776 status = PFVF_STATUS_NOT_SUPPORTED;
2780 /* Find which qid-index is associated with the queue */
2781 qid_usage_idx = ecore_iov_vf_mbx_qid(p_hwfn, vf, true);
2782 if (qid_usage_idx == ECORE_IOV_QID_INVALID)
2785 rc = ecore_iov_vf_stop_txqs(p_hwfn, vf, req->tx_qid,
2787 if (rc == ECORE_SUCCESS)
2788 status = PFVF_STATUS_SUCCESS;
2791 ecore_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_STOP_TXQS,
2795 static void ecore_iov_vf_mbx_update_rxqs(struct ecore_hwfn *p_hwfn,
2796 struct ecore_ptt *p_ptt,
2797 struct ecore_vf_info *vf)
2799 struct ecore_queue_cid *handlers[ECORE_MAX_VF_CHAINS_PER_PF];
2800 u16 length = sizeof(struct pfvf_def_resp_tlv);
2801 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
2802 struct vfpf_update_rxq_tlv *req;
2803 u8 status = PFVF_STATUS_FAILURE;
2804 u8 complete_event_flg;
2805 u8 complete_cqe_flg;
2807 enum _ecore_status_t rc;
2810 req = &mbx->req_virt->update_rxq;
2811 complete_cqe_flg = !!(req->flags & VFPF_RXQ_UPD_COMPLETE_CQE_FLAG);
2812 complete_event_flg = !!(req->flags & VFPF_RXQ_UPD_COMPLETE_EVENT_FLAG);
2814 qid_usage_idx = ecore_iov_vf_mbx_qid(p_hwfn, vf, false);
2815 if (qid_usage_idx == ECORE_IOV_QID_INVALID)
2818 /* Starting with the addition of CHANNEL_TLV_QID, this API started
2819 * expecting a single queue at a time. Validate this.
2821 if ((vf->acquire.vfdev_info.capabilities &
2822 VFPF_ACQUIRE_CAP_QUEUE_QIDS) &&
2823 req->num_rxqs != 1) {
2824 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2825 "VF[%d] supports QIDs but sends multiple queues\n",
2826 vf->relative_vf_id);
2830 /* Validate inputs - for the legacy case this is still true since
2831 * qid_usage_idx for each Rx queue would be LEGACY_QID_RX.
2833 for (i = req->rx_qid; i < req->rx_qid + req->num_rxqs; i++) {
2834 if (!ecore_iov_validate_rxq(p_hwfn, vf, i,
2835 ECORE_IOV_VALIDATE_Q_NA) ||
2836 !vf->vf_queues[i].cids[qid_usage_idx].p_cid ||
2837 vf->vf_queues[i].cids[qid_usage_idx].b_is_tx) {
2838 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2839 "VF[%d]: Incorrect Rxqs [%04x, %02x]\n",
2840 vf->relative_vf_id, req->rx_qid,
2846 for (i = 0; i < req->num_rxqs; i++) {
2847 u16 qid = req->rx_qid + i;
2849 handlers[i] = vf->vf_queues[qid].cids[qid_usage_idx].p_cid;
2852 rc = ecore_sp_eth_rx_queues_update(p_hwfn, (void **)&handlers,
2856 ECORE_SPQ_MODE_EBLOCK,
2858 if (rc != ECORE_SUCCESS)
2861 status = PFVF_STATUS_SUCCESS;
2863 ecore_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_UPDATE_RXQ,
2867 static enum _ecore_status_t
2868 ecore_iov_vf_pf_update_mtu(struct ecore_hwfn *p_hwfn,
2869 struct ecore_ptt *p_ptt,
2870 struct ecore_vf_info *p_vf)
2872 struct ecore_iov_vf_mbx *mbx = &p_vf->vf_mbx;
2873 struct ecore_sp_vport_update_params params;
2874 enum _ecore_status_t rc = ECORE_SUCCESS;
2875 struct vfpf_update_mtu_tlv *p_req;
2876 u8 status = PFVF_STATUS_SUCCESS;
2878 /* Valiate PF can send such a request */
2879 if (!p_vf->vport_instance) {
2880 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2881 "No VPORT instance available for VF[%d], failing MTU update\n",
2883 status = PFVF_STATUS_FAILURE;
2887 p_req = &mbx->req_virt->update_mtu;
2889 OSAL_MEMSET(¶ms, 0, sizeof(params));
2890 params.opaque_fid = p_vf->opaque_fid;
2891 params.vport_id = p_vf->vport_id;
2892 params.mtu = p_req->mtu;
2893 rc = ecore_sp_vport_update(p_hwfn, ¶ms, ECORE_SPQ_MODE_EBLOCK,
2897 status = PFVF_STATUS_FAILURE;
2899 ecore_iov_prepare_resp(p_hwfn, p_ptt, p_vf,
2900 CHANNEL_TLV_UPDATE_MTU,
2901 sizeof(struct pfvf_def_resp_tlv),
2906 void *ecore_iov_search_list_tlvs(struct ecore_hwfn *p_hwfn,
2907 void *p_tlvs_list, u16 req_type)
2909 struct channel_tlv *p_tlv = (struct channel_tlv *)p_tlvs_list;
2913 if (!p_tlv->length) {
2914 DP_NOTICE(p_hwfn, true, "Zero length TLV found\n");
2918 if (p_tlv->type == req_type) {
2919 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2920 "Extended tlv type %s, length %d found\n",
2921 ecore_channel_tlvs_string[p_tlv->type],
2926 len += p_tlv->length;
2927 p_tlv = (struct channel_tlv *)((u8 *)p_tlv + p_tlv->length);
2929 if ((len + p_tlv->length) > TLV_BUFFER_SIZE) {
2930 DP_NOTICE(p_hwfn, true,
2931 "TLVs has overrun the buffer size\n");
2934 } while (p_tlv->type != CHANNEL_TLV_LIST_END);
2940 ecore_iov_vp_update_act_param(struct ecore_hwfn *p_hwfn,
2941 struct ecore_sp_vport_update_params *p_data,
2942 struct ecore_iov_vf_mbx *p_mbx, u16 *tlvs_mask)
2944 struct vfpf_vport_update_activate_tlv *p_act_tlv;
2945 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_ACTIVATE;
2947 p_act_tlv = (struct vfpf_vport_update_activate_tlv *)
2948 ecore_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
2952 p_data->update_vport_active_rx_flg = p_act_tlv->update_rx;
2953 p_data->vport_active_rx_flg = p_act_tlv->active_rx;
2954 p_data->update_vport_active_tx_flg = p_act_tlv->update_tx;
2955 p_data->vport_active_tx_flg = p_act_tlv->active_tx;
2956 *tlvs_mask |= 1 << ECORE_IOV_VP_UPDATE_ACTIVATE;
2960 ecore_iov_vp_update_vlan_param(struct ecore_hwfn *p_hwfn,
2961 struct ecore_sp_vport_update_params *p_data,
2962 struct ecore_vf_info *p_vf,
2963 struct ecore_iov_vf_mbx *p_mbx, u16 *tlvs_mask)
2965 struct vfpf_vport_update_vlan_strip_tlv *p_vlan_tlv;
2966 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_VLAN_STRIP;
2968 p_vlan_tlv = (struct vfpf_vport_update_vlan_strip_tlv *)
2969 ecore_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
2973 p_vf->shadow_config.inner_vlan_removal = p_vlan_tlv->remove_vlan;
2975 /* Ignore the VF request if we're forcing a vlan */
2976 if (!(p_vf->configured_features & (1 << VLAN_ADDR_FORCED))) {
2977 p_data->update_inner_vlan_removal_flg = 1;
2978 p_data->inner_vlan_removal_flg = p_vlan_tlv->remove_vlan;
2981 *tlvs_mask |= 1 << ECORE_IOV_VP_UPDATE_VLAN_STRIP;
2985 ecore_iov_vp_update_tx_switch(struct ecore_hwfn *p_hwfn,
2986 struct ecore_sp_vport_update_params *p_data,
2987 struct ecore_iov_vf_mbx *p_mbx, u16 *tlvs_mask)
2989 struct vfpf_vport_update_tx_switch_tlv *p_tx_switch_tlv;
2990 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_TX_SWITCH;
2992 p_tx_switch_tlv = (struct vfpf_vport_update_tx_switch_tlv *)
2993 ecore_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
2994 if (!p_tx_switch_tlv)
2998 if (CHIP_REV_IS_FPGA(p_hwfn->p_dev)) {
2999 DP_NOTICE(p_hwfn, false,
3000 "FPGA: Ignore tx-switching configuration originating"
3006 p_data->update_tx_switching_flg = 1;
3007 p_data->tx_switching_flg = p_tx_switch_tlv->tx_switching;
3008 *tlvs_mask |= 1 << ECORE_IOV_VP_UPDATE_TX_SWITCH;
3012 ecore_iov_vp_update_mcast_bin_param(struct ecore_hwfn *p_hwfn,
3013 struct ecore_sp_vport_update_params *p_data,
3014 struct ecore_iov_vf_mbx *p_mbx,
3017 struct vfpf_vport_update_mcast_bin_tlv *p_mcast_tlv;
3018 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_MCAST;
3020 p_mcast_tlv = (struct vfpf_vport_update_mcast_bin_tlv *)
3021 ecore_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
3025 p_data->update_approx_mcast_flg = 1;
3026 OSAL_MEMCPY(p_data->bins, p_mcast_tlv->bins,
3027 sizeof(u32) * ETH_MULTICAST_MAC_BINS_IN_REGS);
3028 *tlvs_mask |= 1 << ECORE_IOV_VP_UPDATE_MCAST;
3032 ecore_iov_vp_update_accept_flag(struct ecore_hwfn *p_hwfn,
3033 struct ecore_sp_vport_update_params *p_data,
3034 struct ecore_iov_vf_mbx *p_mbx, u16 *tlvs_mask)
3036 struct ecore_filter_accept_flags *p_flags = &p_data->accept_flags;
3037 struct vfpf_vport_update_accept_param_tlv *p_accept_tlv;
3038 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_ACCEPT_PARAM;
3040 p_accept_tlv = (struct vfpf_vport_update_accept_param_tlv *)
3041 ecore_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
3045 p_flags->update_rx_mode_config = p_accept_tlv->update_rx_mode;
3046 p_flags->rx_accept_filter = p_accept_tlv->rx_accept_filter;
3047 p_flags->update_tx_mode_config = p_accept_tlv->update_tx_mode;
3048 p_flags->tx_accept_filter = p_accept_tlv->tx_accept_filter;
3049 *tlvs_mask |= 1 << ECORE_IOV_VP_UPDATE_ACCEPT_PARAM;
3053 ecore_iov_vp_update_accept_any_vlan(struct ecore_hwfn *p_hwfn,
3054 struct ecore_sp_vport_update_params *p_data,
3055 struct ecore_iov_vf_mbx *p_mbx,
3058 struct vfpf_vport_update_accept_any_vlan_tlv *p_accept_any_vlan;
3059 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_ACCEPT_ANY_VLAN;
3061 p_accept_any_vlan = (struct vfpf_vport_update_accept_any_vlan_tlv *)
3062 ecore_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
3063 if (!p_accept_any_vlan)
3066 p_data->accept_any_vlan = p_accept_any_vlan->accept_any_vlan;
3067 p_data->update_accept_any_vlan_flg =
3068 p_accept_any_vlan->update_accept_any_vlan_flg;
3069 *tlvs_mask |= 1 << ECORE_IOV_VP_UPDATE_ACCEPT_ANY_VLAN;
3073 ecore_iov_vp_update_rss_param(struct ecore_hwfn *p_hwfn,
3074 struct ecore_vf_info *vf,
3075 struct ecore_sp_vport_update_params *p_data,
3076 struct ecore_rss_params *p_rss,
3077 struct ecore_iov_vf_mbx *p_mbx,
3078 u16 *tlvs_mask, u16 *tlvs_accepted)
3080 struct vfpf_vport_update_rss_tlv *p_rss_tlv;
3081 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_RSS;
3082 bool b_reject = false;
3086 p_rss_tlv = (struct vfpf_vport_update_rss_tlv *)
3087 ecore_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
3089 p_data->rss_params = OSAL_NULL;
3093 OSAL_MEMSET(p_rss, 0, sizeof(struct ecore_rss_params));
3095 p_rss->update_rss_config =
3096 !!(p_rss_tlv->update_rss_flags &
3097 VFPF_UPDATE_RSS_CONFIG_FLAG);
3098 p_rss->update_rss_capabilities =
3099 !!(p_rss_tlv->update_rss_flags &
3100 VFPF_UPDATE_RSS_CAPS_FLAG);
3101 p_rss->update_rss_ind_table =
3102 !!(p_rss_tlv->update_rss_flags &
3103 VFPF_UPDATE_RSS_IND_TABLE_FLAG);
3104 p_rss->update_rss_key =
3105 !!(p_rss_tlv->update_rss_flags &
3106 VFPF_UPDATE_RSS_KEY_FLAG);
3108 p_rss->rss_enable = p_rss_tlv->rss_enable;
3109 p_rss->rss_eng_id = vf->rss_eng_id;
3110 p_rss->rss_caps = p_rss_tlv->rss_caps;
3111 p_rss->rss_table_size_log = p_rss_tlv->rss_table_size_log;
3112 OSAL_MEMCPY(p_rss->rss_key, p_rss_tlv->rss_key,
3113 sizeof(p_rss->rss_key));
3115 table_size = OSAL_MIN_T(u16, OSAL_ARRAY_SIZE(p_rss->rss_ind_table),
3116 (1 << p_rss_tlv->rss_table_size_log));
3118 for (i = 0; i < table_size; i++) {
3119 struct ecore_queue_cid *p_cid;
3121 q_idx = p_rss_tlv->rss_ind_table[i];
3122 if (!ecore_iov_validate_rxq(p_hwfn, vf, q_idx,
3123 ECORE_IOV_VALIDATE_Q_ENABLE)) {
3124 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3125 "VF[%d]: Omitting RSS due to wrong queue %04x\n",
3126 vf->relative_vf_id, q_idx);
3131 p_cid = ecore_iov_get_vf_rx_queue_cid(&vf->vf_queues[q_idx]);
3132 p_rss->rss_ind_table[i] = p_cid;
3135 p_data->rss_params = p_rss;
3137 *tlvs_mask |= 1 << ECORE_IOV_VP_UPDATE_RSS;
3139 *tlvs_accepted |= 1 << ECORE_IOV_VP_UPDATE_RSS;
3143 ecore_iov_vp_update_sge_tpa_param(struct ecore_hwfn *p_hwfn,
3144 struct ecore_sp_vport_update_params *p_data,
3145 struct ecore_sge_tpa_params *p_sge_tpa,
3146 struct ecore_iov_vf_mbx *p_mbx,
3149 struct vfpf_vport_update_sge_tpa_tlv *p_sge_tpa_tlv;
3150 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_SGE_TPA;
3152 p_sge_tpa_tlv = (struct vfpf_vport_update_sge_tpa_tlv *)
3153 ecore_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
3155 if (!p_sge_tpa_tlv) {
3156 p_data->sge_tpa_params = OSAL_NULL;
3160 OSAL_MEMSET(p_sge_tpa, 0, sizeof(struct ecore_sge_tpa_params));
3162 p_sge_tpa->update_tpa_en_flg =
3163 !!(p_sge_tpa_tlv->update_sge_tpa_flags & VFPF_UPDATE_TPA_EN_FLAG);
3164 p_sge_tpa->update_tpa_param_flg =
3165 !!(p_sge_tpa_tlv->update_sge_tpa_flags &
3166 VFPF_UPDATE_TPA_PARAM_FLAG);
3168 p_sge_tpa->tpa_ipv4_en_flg =
3169 !!(p_sge_tpa_tlv->sge_tpa_flags & VFPF_TPA_IPV4_EN_FLAG);
3170 p_sge_tpa->tpa_ipv6_en_flg =
3171 !!(p_sge_tpa_tlv->sge_tpa_flags & VFPF_TPA_IPV6_EN_FLAG);
3172 p_sge_tpa->tpa_pkt_split_flg =
3173 !!(p_sge_tpa_tlv->sge_tpa_flags & VFPF_TPA_PKT_SPLIT_FLAG);
3174 p_sge_tpa->tpa_hdr_data_split_flg =
3175 !!(p_sge_tpa_tlv->sge_tpa_flags & VFPF_TPA_HDR_DATA_SPLIT_FLAG);
3176 p_sge_tpa->tpa_gro_consistent_flg =
3177 !!(p_sge_tpa_tlv->sge_tpa_flags & VFPF_TPA_GRO_CONSIST_FLAG);
3179 p_sge_tpa->tpa_max_aggs_num = p_sge_tpa_tlv->tpa_max_aggs_num;
3180 p_sge_tpa->tpa_max_size = p_sge_tpa_tlv->tpa_max_size;
3181 p_sge_tpa->tpa_min_size_to_start = p_sge_tpa_tlv->tpa_min_size_to_start;
3182 p_sge_tpa->tpa_min_size_to_cont = p_sge_tpa_tlv->tpa_min_size_to_cont;
3183 p_sge_tpa->max_buffers_per_cqe = p_sge_tpa_tlv->max_buffers_per_cqe;
3185 p_data->sge_tpa_params = p_sge_tpa;
3187 *tlvs_mask |= 1 << ECORE_IOV_VP_UPDATE_SGE_TPA;
3190 static void ecore_iov_vf_mbx_vport_update(struct ecore_hwfn *p_hwfn,
3191 struct ecore_ptt *p_ptt,
3192 struct ecore_vf_info *vf)
3194 struct ecore_rss_params *p_rss_params = OSAL_NULL;
3195 struct ecore_sp_vport_update_params params;
3196 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
3197 struct ecore_sge_tpa_params sge_tpa_params;
3198 u16 tlvs_mask = 0, tlvs_accepted = 0;
3199 u8 status = PFVF_STATUS_SUCCESS;
3201 enum _ecore_status_t rc;
3203 /* Valiate PF can send such a request */
3204 if (!vf->vport_instance) {
3205 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3206 "No VPORT instance available for VF[%d],"
3207 " failing vport update\n",
3209 status = PFVF_STATUS_FAILURE;
3213 p_rss_params = OSAL_VZALLOC(p_hwfn->p_dev, sizeof(*p_rss_params));
3214 if (p_rss_params == OSAL_NULL) {
3215 status = PFVF_STATUS_FAILURE;
3219 OSAL_MEMSET(¶ms, 0, sizeof(params));
3220 params.opaque_fid = vf->opaque_fid;
3221 params.vport_id = vf->vport_id;
3222 params.rss_params = OSAL_NULL;
3224 /* Search for extended tlvs list and update values
3225 * from VF in struct ecore_sp_vport_update_params.
3227 ecore_iov_vp_update_act_param(p_hwfn, ¶ms, mbx, &tlvs_mask);
3228 ecore_iov_vp_update_vlan_param(p_hwfn, ¶ms, vf, mbx, &tlvs_mask);
3229 ecore_iov_vp_update_tx_switch(p_hwfn, ¶ms, mbx, &tlvs_mask);
3230 ecore_iov_vp_update_mcast_bin_param(p_hwfn, ¶ms, mbx, &tlvs_mask);
3231 ecore_iov_vp_update_accept_flag(p_hwfn, ¶ms, mbx, &tlvs_mask);
3232 ecore_iov_vp_update_accept_any_vlan(p_hwfn, ¶ms, mbx, &tlvs_mask);
3233 ecore_iov_vp_update_sge_tpa_param(p_hwfn, ¶ms,
3234 &sge_tpa_params, mbx, &tlvs_mask);
3236 tlvs_accepted = tlvs_mask;
3238 /* Some of the extended TLVs need to be validated first; In that case,
3239 * they can update the mask without updating the accepted [so that
3240 * PF could communicate to VF it has rejected request].
3242 ecore_iov_vp_update_rss_param(p_hwfn, vf, ¶ms, p_rss_params,
3243 mbx, &tlvs_mask, &tlvs_accepted);
3245 /* Just log a message if there is no single extended tlv in buffer.
3246 * When all features of vport update ramrod would be requested by VF
3247 * as extended TLVs in buffer then an error can be returned in response
3248 * if there is no extended TLV present in buffer.
3250 if (OSAL_IOV_VF_VPORT_UPDATE(p_hwfn, vf->relative_vf_id,
3251 ¶ms, &tlvs_accepted) !=
3254 status = PFVF_STATUS_NOT_SUPPORTED;
3258 if (!tlvs_accepted) {
3260 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3261 "Upper-layer prevents said VF"
3262 " configuration\n");
3264 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3265 "No feature tlvs found for vport update\n");
3266 status = PFVF_STATUS_NOT_SUPPORTED;
3270 rc = ecore_sp_vport_update(p_hwfn, ¶ms, ECORE_SPQ_MODE_EBLOCK,
3274 status = PFVF_STATUS_FAILURE;
3277 OSAL_VFREE(p_hwfn->p_dev, p_rss_params);
3278 length = ecore_iov_prep_vp_update_resp_tlvs(p_hwfn, vf, mbx, status,
3279 tlvs_mask, tlvs_accepted);
3280 ecore_iov_send_response(p_hwfn, p_ptt, vf, length, status);
3283 static enum _ecore_status_t
3284 ecore_iov_vf_update_vlan_shadow(struct ecore_hwfn *p_hwfn,
3285 struct ecore_vf_info *p_vf,
3286 struct ecore_filter_ucast *p_params)
3290 /* First remove entries and then add new ones */
3291 if (p_params->opcode == ECORE_FILTER_REMOVE) {
3292 for (i = 0; i < ECORE_ETH_VF_NUM_VLAN_FILTERS + 1; i++)
3293 if (p_vf->shadow_config.vlans[i].used &&
3294 p_vf->shadow_config.vlans[i].vid ==
3296 p_vf->shadow_config.vlans[i].used = false;
3299 if (i == ECORE_ETH_VF_NUM_VLAN_FILTERS + 1) {
3300 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3301 "VF [%d] - Tries to remove a non-existing"
3303 p_vf->relative_vf_id);
3306 } else if (p_params->opcode == ECORE_FILTER_REPLACE ||
3307 p_params->opcode == ECORE_FILTER_FLUSH) {
3308 for (i = 0; i < ECORE_ETH_VF_NUM_VLAN_FILTERS + 1; i++)
3309 p_vf->shadow_config.vlans[i].used = false;
3312 /* In forced mode, we're willing to remove entries - but we don't add
3315 if (p_vf->bulletin.p_virt->valid_bitmap & (1 << VLAN_ADDR_FORCED))
3316 return ECORE_SUCCESS;
3318 if (p_params->opcode == ECORE_FILTER_ADD ||
3319 p_params->opcode == ECORE_FILTER_REPLACE) {
3320 for (i = 0; i < ECORE_ETH_VF_NUM_VLAN_FILTERS + 1; i++) {
3321 if (p_vf->shadow_config.vlans[i].used)
3324 p_vf->shadow_config.vlans[i].used = true;
3325 p_vf->shadow_config.vlans[i].vid = p_params->vlan;
3329 if (i == ECORE_ETH_VF_NUM_VLAN_FILTERS + 1) {
3330 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3331 "VF [%d] - Tries to configure more than %d"
3333 p_vf->relative_vf_id,
3334 ECORE_ETH_VF_NUM_VLAN_FILTERS + 1);
3339 return ECORE_SUCCESS;
3342 static enum _ecore_status_t
3343 ecore_iov_vf_update_mac_shadow(struct ecore_hwfn *p_hwfn,
3344 struct ecore_vf_info *p_vf,
3345 struct ecore_filter_ucast *p_params)
3347 char empty_mac[ETH_ALEN];
3350 OSAL_MEM_ZERO(empty_mac, ETH_ALEN);
3352 /* If we're in forced-mode, we don't allow any change */
3353 /* TODO - this would change if we were ever to implement logic for
3354 * removing a forced MAC altogether [in which case, like for vlans,
3355 * we should be able to re-trace previous configuration.
3357 if (p_vf->bulletin.p_virt->valid_bitmap & (1 << MAC_ADDR_FORCED))
3358 return ECORE_SUCCESS;
3360 /* Since we don't have the implementation of the logic for removing
3361 * a forced MAC and restoring shadow MAC, let's not worry about
3362 * processing shadow copies of MAC as long as VF trust mode is ON,
3363 * to keep things simple.
3365 if (p_hwfn->pf_params.eth_pf_params.allow_vf_mac_change ||
3366 p_vf->p_vf_info.is_trusted_configured)
3367 return ECORE_SUCCESS;
3369 /* First remove entries and then add new ones */
3370 if (p_params->opcode == ECORE_FILTER_REMOVE) {
3371 for (i = 0; i < ECORE_ETH_VF_NUM_MAC_FILTERS; i++) {
3372 if (!OSAL_MEMCMP(p_vf->shadow_config.macs[i],
3373 p_params->mac, ETH_ALEN)) {
3374 OSAL_MEM_ZERO(p_vf->shadow_config.macs[i],
3380 if (i == ECORE_ETH_VF_NUM_MAC_FILTERS) {
3381 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3382 "MAC isn't configured\n");
3385 } else if (p_params->opcode == ECORE_FILTER_REPLACE ||
3386 p_params->opcode == ECORE_FILTER_FLUSH) {
3387 for (i = 0; i < ECORE_ETH_VF_NUM_MAC_FILTERS; i++)
3388 OSAL_MEM_ZERO(p_vf->shadow_config.macs[i], ETH_ALEN);
3391 /* List the new MAC address */
3392 if (p_params->opcode != ECORE_FILTER_ADD &&
3393 p_params->opcode != ECORE_FILTER_REPLACE)
3394 return ECORE_SUCCESS;
3396 for (i = 0; i < ECORE_ETH_VF_NUM_MAC_FILTERS; i++) {
3397 if (!OSAL_MEMCMP(p_vf->shadow_config.macs[i],
3398 empty_mac, ETH_ALEN)) {
3399 OSAL_MEMCPY(p_vf->shadow_config.macs[i],
3400 p_params->mac, ETH_ALEN);
3401 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3402 "Added MAC at %d entry in shadow\n", i);
3407 if (i == ECORE_ETH_VF_NUM_MAC_FILTERS) {
3408 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3409 "No available place for MAC\n");
3413 return ECORE_SUCCESS;
3416 static enum _ecore_status_t
3417 ecore_iov_vf_update_unicast_shadow(struct ecore_hwfn *p_hwfn,
3418 struct ecore_vf_info *p_vf,
3419 struct ecore_filter_ucast *p_params)
3421 enum _ecore_status_t rc = ECORE_SUCCESS;
3423 if (p_params->type == ECORE_FILTER_MAC) {
3424 rc = ecore_iov_vf_update_mac_shadow(p_hwfn, p_vf, p_params);
3425 if (rc != ECORE_SUCCESS)
3429 if (p_params->type == ECORE_FILTER_VLAN)
3430 rc = ecore_iov_vf_update_vlan_shadow(p_hwfn, p_vf, p_params);
3435 static void ecore_iov_vf_mbx_ucast_filter(struct ecore_hwfn *p_hwfn,
3436 struct ecore_ptt *p_ptt,
3437 struct ecore_vf_info *vf)
3439 struct ecore_bulletin_content *p_bulletin = vf->bulletin.p_virt;
3440 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
3441 struct vfpf_ucast_filter_tlv *req;
3442 u8 status = PFVF_STATUS_SUCCESS;
3443 struct ecore_filter_ucast params;
3444 enum _ecore_status_t rc;
3446 /* Prepare the unicast filter params */
3447 OSAL_MEMSET(¶ms, 0, sizeof(struct ecore_filter_ucast));
3448 req = &mbx->req_virt->ucast_filter;
3449 params.opcode = (enum ecore_filter_opcode)req->opcode;
3450 params.type = (enum ecore_filter_ucast_type)req->type;
3452 /* @@@TBD - We might need logic on HV side in determining this */
3453 params.is_rx_filter = 1;
3454 params.is_tx_filter = 1;
3455 params.vport_to_remove_from = vf->vport_id;
3456 params.vport_to_add_to = vf->vport_id;
3457 OSAL_MEMCPY(params.mac, req->mac, ETH_ALEN);
3458 params.vlan = req->vlan;
3460 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3461 "VF[%d]: opcode 0x%02x type 0x%02x [%s %s] [vport 0x%02x]"
3462 " MAC %02x:%02x:%02x:%02x:%02x:%02x, vlan 0x%04x\n",
3463 vf->abs_vf_id, params.opcode, params.type,
3464 params.is_rx_filter ? "RX" : "",
3465 params.is_tx_filter ? "TX" : "",
3466 params.vport_to_add_to,
3467 params.mac[0], params.mac[1], params.mac[2],
3468 params.mac[3], params.mac[4], params.mac[5], params.vlan);
3470 if (!vf->vport_instance) {
3471 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3472 "No VPORT instance available for VF[%d],"
3473 " failing ucast MAC configuration\n",
3475 status = PFVF_STATUS_FAILURE;
3479 /* Update shadow copy of the VF configuration. In case shadow indicates
3480 * the action should be blocked return success to VF to imitate the
3481 * firmware behaviour in such case.
3483 if (ecore_iov_vf_update_unicast_shadow(p_hwfn, vf, ¶ms) !=
3487 /* Determine if the unicast filtering is acceptible by PF */
3488 if ((p_bulletin->valid_bitmap & (1 << VLAN_ADDR_FORCED)) &&
3489 (params.type == ECORE_FILTER_VLAN ||
3490 params.type == ECORE_FILTER_MAC_VLAN)) {
3491 /* Once VLAN is forced or PVID is set, do not allow
3492 * to add/replace any further VLANs.
3494 if (params.opcode == ECORE_FILTER_ADD ||
3495 params.opcode == ECORE_FILTER_REPLACE)
3496 status = PFVF_STATUS_FORCED;
3500 if ((p_bulletin->valid_bitmap & (1 << MAC_ADDR_FORCED)) &&
3501 (params.type == ECORE_FILTER_MAC ||
3502 params.type == ECORE_FILTER_MAC_VLAN)) {
3503 if (OSAL_MEMCMP(p_bulletin->mac, params.mac, ETH_ALEN) ||
3504 (params.opcode != ECORE_FILTER_ADD &&
3505 params.opcode != ECORE_FILTER_REPLACE))
3506 status = PFVF_STATUS_FORCED;
3510 rc = OSAL_IOV_CHK_UCAST(p_hwfn, vf->relative_vf_id, ¶ms);
3511 if (rc == ECORE_EXISTS) {
3513 } else if (rc == ECORE_INVAL) {
3514 status = PFVF_STATUS_FAILURE;
3518 rc = ecore_sp_eth_filter_ucast(p_hwfn, vf->opaque_fid, ¶ms,
3519 ECORE_SPQ_MODE_CB, OSAL_NULL);
3521 status = PFVF_STATUS_FAILURE;
3524 ecore_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_UCAST_FILTER,
3525 sizeof(struct pfvf_def_resp_tlv), status);
3528 static void ecore_iov_vf_mbx_int_cleanup(struct ecore_hwfn *p_hwfn,
3529 struct ecore_ptt *p_ptt,
3530 struct ecore_vf_info *vf)
3535 for (i = 0; i < vf->num_sbs; i++)
3536 ecore_int_igu_init_pure_rt_single(p_hwfn, p_ptt,
3538 vf->opaque_fid, false);
3540 ecore_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_INT_CLEANUP,
3541 sizeof(struct pfvf_def_resp_tlv),
3542 PFVF_STATUS_SUCCESS);
3545 static void ecore_iov_vf_mbx_close(struct ecore_hwfn *p_hwfn,
3546 struct ecore_ptt *p_ptt,
3547 struct ecore_vf_info *vf)
3549 u16 length = sizeof(struct pfvf_def_resp_tlv);
3550 u8 status = PFVF_STATUS_SUCCESS;
3552 /* Disable Interrupts for VF */
3553 ecore_iov_vf_igu_set_int(p_hwfn, p_ptt, vf, 0);
3555 /* Reset Permission table */
3556 ecore_iov_config_perm_table(p_hwfn, p_ptt, vf, 0);
3558 ecore_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_CLOSE,
3562 static void ecore_iov_vf_mbx_release(struct ecore_hwfn *p_hwfn,
3563 struct ecore_ptt *p_ptt,
3564 struct ecore_vf_info *p_vf)
3566 u16 length = sizeof(struct pfvf_def_resp_tlv);
3567 u8 status = PFVF_STATUS_SUCCESS;
3568 enum _ecore_status_t rc = ECORE_SUCCESS;
3570 ecore_iov_vf_cleanup(p_hwfn, p_vf);
3572 if (p_vf->state != VF_STOPPED && p_vf->state != VF_FREE) {
3573 /* Stopping the VF */
3574 rc = ecore_sp_vf_stop(p_hwfn, p_vf->concrete_fid,
3577 if (rc != ECORE_SUCCESS) {
3578 DP_ERR(p_hwfn, "ecore_sp_vf_stop returned error %d\n",
3580 status = PFVF_STATUS_FAILURE;
3583 p_vf->state = VF_STOPPED;
3586 ecore_iov_prepare_resp(p_hwfn, p_ptt, p_vf, CHANNEL_TLV_RELEASE,
3590 static void ecore_iov_vf_pf_get_coalesce(struct ecore_hwfn *p_hwfn,
3591 struct ecore_ptt *p_ptt,
3592 struct ecore_vf_info *p_vf)
3594 struct ecore_iov_vf_mbx *mbx = &p_vf->vf_mbx;
3595 struct pfvf_read_coal_resp_tlv *p_resp;
3596 struct vfpf_read_coal_req_tlv *req;
3597 u8 status = PFVF_STATUS_FAILURE;
3598 struct ecore_vf_queue *p_queue;
3599 struct ecore_queue_cid *p_cid;
3600 enum _ecore_status_t rc = ECORE_SUCCESS;
3601 u16 coal = 0, qid, i;
3604 mbx->offset = (u8 *)mbx->reply_virt;
3605 req = &mbx->req_virt->read_coal_req;
3608 b_is_rx = req->is_rx ? true : false;
3611 if (!ecore_iov_validate_rxq(p_hwfn, p_vf, qid,
3612 ECORE_IOV_VALIDATE_Q_ENABLE)) {
3613 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3614 "VF[%d]: Invalid Rx queue_id = %d\n",
3615 p_vf->abs_vf_id, qid);
3619 p_cid = ecore_iov_get_vf_rx_queue_cid(&p_vf->vf_queues[qid]);
3620 rc = ecore_get_rxq_coalesce(p_hwfn, p_ptt, p_cid, &coal);
3621 if (rc != ECORE_SUCCESS)
3624 if (!ecore_iov_validate_txq(p_hwfn, p_vf, qid,
3625 ECORE_IOV_VALIDATE_Q_ENABLE)) {
3626 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3627 "VF[%d]: Invalid Tx queue_id = %d\n",
3628 p_vf->abs_vf_id, qid);
3631 for (i = 0; i < MAX_QUEUES_PER_QZONE; i++) {
3632 p_queue = &p_vf->vf_queues[qid];
3633 if ((p_queue->cids[i].p_cid == OSAL_NULL) ||
3634 (!p_queue->cids[i].b_is_tx))
3637 p_cid = p_queue->cids[i].p_cid;
3639 rc = ecore_get_txq_coalesce(p_hwfn, p_ptt,
3641 if (rc != ECORE_SUCCESS)
3647 status = PFVF_STATUS_SUCCESS;
3650 p_resp = ecore_add_tlv(&mbx->offset, CHANNEL_TLV_COALESCE_READ,
3652 p_resp->coal = coal;
3654 ecore_add_tlv(&mbx->offset, CHANNEL_TLV_LIST_END,
3655 sizeof(struct channel_list_end_tlv));
3657 ecore_iov_send_response(p_hwfn, p_ptt, p_vf, sizeof(*p_resp), status);
3660 static void ecore_iov_vf_pf_set_coalesce(struct ecore_hwfn *p_hwfn,
3661 struct ecore_ptt *p_ptt,
3662 struct ecore_vf_info *vf)
3664 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
3665 enum _ecore_status_t rc = ECORE_SUCCESS;
3666 struct vfpf_update_coalesce *req;
3667 u8 status = PFVF_STATUS_FAILURE;
3668 struct ecore_queue_cid *p_cid;
3669 u16 rx_coal, tx_coal;
3673 req = &mbx->req_virt->update_coalesce;
3675 rx_coal = req->rx_coal;
3676 tx_coal = req->tx_coal;
3679 if (!ecore_iov_validate_rxq(p_hwfn, vf, qid,
3680 ECORE_IOV_VALIDATE_Q_ENABLE) &&
3682 DP_ERR(p_hwfn, "VF[%d]: Invalid Rx queue_id = %d\n",
3683 vf->abs_vf_id, qid);
3687 if (!ecore_iov_validate_txq(p_hwfn, vf, qid,
3688 ECORE_IOV_VALIDATE_Q_ENABLE) &&
3690 DP_ERR(p_hwfn, "VF[%d]: Invalid Tx queue_id = %d\n",
3691 vf->abs_vf_id, qid);
3695 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3696 "VF[%d]: Setting coalesce for VF rx_coal = %d, tx_coal = %d at queue = %d\n",
3697 vf->abs_vf_id, rx_coal, tx_coal, qid);
3700 p_cid = ecore_iov_get_vf_rx_queue_cid(&vf->vf_queues[qid]);
3702 rc = ecore_set_rxq_coalesce(p_hwfn, p_ptt, rx_coal, p_cid);
3703 if (rc != ECORE_SUCCESS) {
3704 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3705 "VF[%d]: Unable to set rx queue = %d coalesce\n",
3706 vf->abs_vf_id, vf->vf_queues[qid].fw_rx_qid);
3709 vf->rx_coal = rx_coal;
3712 /* TODO - in future, it might be possible to pass this in a per-cid
3713 * granularity. For now, do this for all Tx queues.
3716 struct ecore_vf_queue *p_queue = &vf->vf_queues[qid];
3718 for (i = 0; i < MAX_QUEUES_PER_QZONE; i++) {
3719 if (p_queue->cids[i].p_cid == OSAL_NULL)
3722 if (!p_queue->cids[i].b_is_tx)
3725 rc = ecore_set_txq_coalesce(p_hwfn, p_ptt, tx_coal,
3726 p_queue->cids[i].p_cid);
3727 if (rc != ECORE_SUCCESS) {
3728 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3729 "VF[%d]: Unable to set tx queue coalesce\n",
3734 vf->tx_coal = tx_coal;
3737 status = PFVF_STATUS_SUCCESS;
3739 ecore_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_COALESCE_UPDATE,
3740 sizeof(struct pfvf_def_resp_tlv), status);
3743 enum _ecore_status_t
3744 ecore_iov_pf_configure_vf_queue_coalesce(struct ecore_hwfn *p_hwfn,
3745 u16 rx_coal, u16 tx_coal,
3748 struct ecore_queue_cid *p_cid;
3749 struct ecore_vf_info *vf;
3750 struct ecore_ptt *p_ptt;
3753 if (!ecore_iov_is_valid_vfid(p_hwfn, vf_id, true, true)) {
3754 DP_NOTICE(p_hwfn, true,
3755 "VF[%d] - Can not set coalescing: VF is not active\n",
3760 vf = &p_hwfn->pf_iov_info->vfs_array[vf_id];
3761 p_ptt = ecore_ptt_acquire(p_hwfn);
3765 if (!ecore_iov_validate_rxq(p_hwfn, vf, qid,
3766 ECORE_IOV_VALIDATE_Q_ENABLE) &&
3768 DP_ERR(p_hwfn, "VF[%d]: Invalid Rx queue_id = %d\n",
3769 vf->abs_vf_id, qid);
3773 if (!ecore_iov_validate_txq(p_hwfn, vf, qid,
3774 ECORE_IOV_VALIDATE_Q_ENABLE) &&
3776 DP_ERR(p_hwfn, "VF[%d]: Invalid Tx queue_id = %d\n",
3777 vf->abs_vf_id, qid);
3781 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3782 "VF[%d]: Setting coalesce for VF rx_coal = %d, tx_coal = %d at queue = %d\n",
3783 vf->abs_vf_id, rx_coal, tx_coal, qid);
3786 p_cid = ecore_iov_get_vf_rx_queue_cid(&vf->vf_queues[qid]);
3788 rc = ecore_set_rxq_coalesce(p_hwfn, p_ptt, rx_coal, p_cid);
3789 if (rc != ECORE_SUCCESS) {
3790 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3791 "VF[%d]: Unable to set rx queue = %d coalesce\n",
3792 vf->abs_vf_id, vf->vf_queues[qid].fw_rx_qid);
3795 vf->rx_coal = rx_coal;
3798 /* TODO - in future, it might be possible to pass this in a per-cid
3799 * granularity. For now, do this for all Tx queues.
3802 struct ecore_vf_queue *p_queue = &vf->vf_queues[qid];
3804 for (i = 0; i < MAX_QUEUES_PER_QZONE; i++) {
3805 if (p_queue->cids[i].p_cid == OSAL_NULL)
3808 if (!p_queue->cids[i].b_is_tx)
3811 rc = ecore_set_txq_coalesce(p_hwfn, p_ptt, tx_coal,
3812 p_queue->cids[i].p_cid);
3813 if (rc != ECORE_SUCCESS) {
3814 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3815 "VF[%d]: Unable to set tx queue coalesce\n",
3820 vf->tx_coal = tx_coal;
3824 ecore_ptt_release(p_hwfn, p_ptt);
3829 static enum _ecore_status_t
3830 ecore_iov_vf_flr_poll_dorq(struct ecore_hwfn *p_hwfn,
3831 struct ecore_vf_info *p_vf, struct ecore_ptt *p_ptt)
3836 ecore_fid_pretend(p_hwfn, p_ptt, (u16)p_vf->concrete_fid);
3838 for (cnt = 0; cnt < 50; cnt++) {
3839 val = ecore_rd(p_hwfn, p_ptt, DORQ_REG_VF_USAGE_CNT);
3844 ecore_fid_pretend(p_hwfn, p_ptt, (u16)p_hwfn->hw_info.concrete_fid);
3848 "VF[%d] - dorq failed to cleanup [usage 0x%08x]\n",
3849 p_vf->abs_vf_id, val);
3850 return ECORE_TIMEOUT;
3853 return ECORE_SUCCESS;
3856 static enum _ecore_status_t
3857 ecore_iov_vf_flr_poll_pbf(struct ecore_hwfn *p_hwfn,
3858 struct ecore_vf_info *p_vf, struct ecore_ptt *p_ptt)
3860 u32 cons[MAX_NUM_VOQS_E4], distance[MAX_NUM_VOQS_E4];
3863 /* Read initial consumers & producers */
3864 for (i = 0; i < MAX_NUM_VOQS_E4; i++) {
3867 cons[i] = ecore_rd(p_hwfn, p_ptt,
3868 PBF_REG_NUM_BLOCKS_ALLOCATED_CONS_VOQ0 +
3870 prod = ecore_rd(p_hwfn, p_ptt,
3871 PBF_REG_NUM_BLOCKS_ALLOCATED_PROD_VOQ0 +
3873 distance[i] = prod - cons[i];
3876 /* Wait for consumers to pass the producers */
3878 for (cnt = 0; cnt < 50; cnt++) {
3879 for (; i < MAX_NUM_VOQS_E4; i++) {
3882 tmp = ecore_rd(p_hwfn, p_ptt,
3883 PBF_REG_NUM_BLOCKS_ALLOCATED_CONS_VOQ0 +
3885 if (distance[i] > tmp - cons[i])
3889 if (i == MAX_NUM_VOQS_E4)
3896 DP_ERR(p_hwfn, "VF[%d] - pbf polling failed on VOQ %d\n",
3897 p_vf->abs_vf_id, i);
3898 return ECORE_TIMEOUT;
3901 return ECORE_SUCCESS;
3904 static enum _ecore_status_t ecore_iov_vf_flr_poll(struct ecore_hwfn *p_hwfn,
3905 struct ecore_vf_info *p_vf,
3906 struct ecore_ptt *p_ptt)
3908 enum _ecore_status_t rc;
3910 /* TODO - add SRC and TM polling once we add storage IOV */
3912 rc = ecore_iov_vf_flr_poll_dorq(p_hwfn, p_vf, p_ptt);
3916 rc = ecore_iov_vf_flr_poll_pbf(p_hwfn, p_vf, p_ptt);
3920 return ECORE_SUCCESS;
3923 static enum _ecore_status_t
3924 ecore_iov_execute_vf_flr_cleanup(struct ecore_hwfn *p_hwfn,
3925 struct ecore_ptt *p_ptt,
3926 u16 rel_vf_id, u32 *ack_vfs)
3928 struct ecore_vf_info *p_vf;
3929 enum _ecore_status_t rc = ECORE_SUCCESS;
3931 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, false);
3933 return ECORE_SUCCESS;
3935 if (p_hwfn->pf_iov_info->pending_flr[rel_vf_id / 64] &
3936 (1ULL << (rel_vf_id % 64))) {
3937 u16 vfid = p_vf->abs_vf_id;
3939 /* TODO - should we lock channel? */
3941 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3942 "VF[%d] - Handling FLR\n", vfid);
3944 ecore_iov_vf_cleanup(p_hwfn, p_vf);
3946 /* If VF isn't active, no need for anything but SW */
3950 /* TODO - what to do in case of failure? */
3951 rc = ecore_iov_vf_flr_poll(p_hwfn, p_vf, p_ptt);
3952 if (rc != ECORE_SUCCESS)
3955 rc = ecore_final_cleanup(p_hwfn, p_ptt, vfid, true);
3957 /* TODO - what's now? What a mess.... */
3958 DP_ERR(p_hwfn, "Failed handle FLR of VF[%d]\n", vfid);
3962 /* Workaround to make VF-PF channel ready, as FW
3963 * doesn't do that as a part of FLR.
3966 GTT_BAR0_MAP_REG_USDM_RAM +
3967 USTORM_VF_PF_CHANNEL_READY_OFFSET(vfid), 1);
3969 /* VF_STOPPED has to be set only after final cleanup
3970 * but prior to re-enabling the VF.
3972 p_vf->state = VF_STOPPED;
3974 rc = ecore_iov_enable_vf_access(p_hwfn, p_ptt, p_vf);
3976 /* TODO - again, a mess... */
3977 DP_ERR(p_hwfn, "Failed to re-enable VF[%d] acces\n",
3982 /* Mark VF for ack and clean pending state */
3983 if (p_vf->state == VF_RESET)
3984 p_vf->state = VF_STOPPED;
3985 ack_vfs[vfid / 32] |= (1 << (vfid % 32));
3986 p_hwfn->pf_iov_info->pending_flr[rel_vf_id / 64] &=
3987 ~(1ULL << (rel_vf_id % 64));
3988 p_vf->vf_mbx.b_pending_msg = false;
3994 enum _ecore_status_t ecore_iov_vf_flr_cleanup(struct ecore_hwfn *p_hwfn,
3995 struct ecore_ptt *p_ptt)
3997 u32 ack_vfs[VF_MAX_STATIC / 32];
3998 enum _ecore_status_t rc = ECORE_SUCCESS;
4001 OSAL_MEMSET(ack_vfs, 0, sizeof(u32) * (VF_MAX_STATIC / 32));
4003 /* Since BRB <-> PRS interface can't be tested as part of the flr
4004 * polling due to HW limitations, simply sleep a bit. And since
4005 * there's no need to wait per-vf, do it before looping.
4009 for (i = 0; i < p_hwfn->p_dev->p_iov_info->total_vfs; i++)
4010 ecore_iov_execute_vf_flr_cleanup(p_hwfn, p_ptt, i, ack_vfs);
4012 rc = ecore_mcp_ack_vf_flr(p_hwfn, p_ptt, ack_vfs);
4016 enum _ecore_status_t
4017 ecore_iov_single_vf_flr_cleanup(struct ecore_hwfn *p_hwfn,
4018 struct ecore_ptt *p_ptt, u16 rel_vf_id)
4020 u32 ack_vfs[VF_MAX_STATIC / 32];
4021 enum _ecore_status_t rc = ECORE_SUCCESS;
4023 OSAL_MEMSET(ack_vfs, 0, sizeof(u32) * (VF_MAX_STATIC / 32));
4025 /* Wait instead of polling the BRB <-> PRS interface */
4028 ecore_iov_execute_vf_flr_cleanup(p_hwfn, p_ptt, rel_vf_id, ack_vfs);
4030 rc = ecore_mcp_ack_vf_flr(p_hwfn, p_ptt, ack_vfs);
4034 bool ecore_iov_mark_vf_flr(struct ecore_hwfn *p_hwfn, u32 *p_disabled_vfs)
4039 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV, "Marking FLR-ed VFs\n");
4040 for (i = 0; i < (VF_MAX_STATIC / 32); i++)
4041 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
4042 "[%08x,...,%08x]: %08x\n",
4043 i * 32, (i + 1) * 32 - 1, p_disabled_vfs[i]);
4045 if (!p_hwfn->p_dev->p_iov_info) {
4046 DP_NOTICE(p_hwfn, true, "VF flr but no IOV\n");
4051 for (i = 0; i < p_hwfn->p_dev->p_iov_info->total_vfs; i++) {
4052 struct ecore_vf_info *p_vf;
4055 p_vf = ecore_iov_get_vf_info(p_hwfn, i, false);
4059 vfid = p_vf->abs_vf_id;
4060 if ((1 << (vfid % 32)) & p_disabled_vfs[vfid / 32]) {
4061 u64 *p_flr = p_hwfn->pf_iov_info->pending_flr;
4062 u16 rel_vf_id = p_vf->relative_vf_id;
4064 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
4065 "VF[%d] [rel %d] got FLR-ed\n",
4068 p_vf->state = VF_RESET;
4070 /* No need to lock here, since pending_flr should
4071 * only change here and before ACKing MFw. Since
4072 * MFW will not trigger an additional attention for
4073 * VF flr until ACKs, we're safe.
4075 p_flr[rel_vf_id / 64] |= 1ULL << (rel_vf_id % 64);
4083 void ecore_iov_get_link(struct ecore_hwfn *p_hwfn,
4085 struct ecore_mcp_link_params *p_params,
4086 struct ecore_mcp_link_state *p_link,
4087 struct ecore_mcp_link_capabilities *p_caps)
4089 struct ecore_vf_info *p_vf = ecore_iov_get_vf_info(p_hwfn, vfid, false);
4090 struct ecore_bulletin_content *p_bulletin;
4095 p_bulletin = p_vf->bulletin.p_virt;
4098 __ecore_vf_get_link_params(p_params, p_bulletin);
4100 __ecore_vf_get_link_state(p_link, p_bulletin);
4102 __ecore_vf_get_link_caps(p_caps, p_bulletin);
4105 void ecore_iov_process_mbx_req(struct ecore_hwfn *p_hwfn,
4106 struct ecore_ptt *p_ptt, int vfid)
4108 struct ecore_iov_vf_mbx *mbx;
4109 struct ecore_vf_info *p_vf;
4111 p_vf = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4115 mbx = &p_vf->vf_mbx;
4117 /* ecore_iov_process_mbx_request */
4118 #ifndef CONFIG_ECORE_SW_CHANNEL
4119 if (!mbx->b_pending_msg) {
4120 DP_NOTICE(p_hwfn, true,
4121 "VF[%02x]: Trying to process mailbox message when none is pending\n",
4125 mbx->b_pending_msg = false;
4128 mbx->first_tlv = mbx->req_virt->first_tlv;
4130 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
4131 "VF[%02x]: Processing mailbox message [type %04x]\n",
4132 p_vf->abs_vf_id, mbx->first_tlv.tl.type);
4134 OSAL_IOV_VF_MSG_TYPE(p_hwfn,
4135 p_vf->relative_vf_id,
4136 mbx->first_tlv.tl.type);
4138 /* Lock the per vf op mutex and note the locker's identity.
4139 * The unlock will take place in mbx response.
4141 ecore_iov_lock_vf_pf_channel(p_hwfn,
4142 p_vf, mbx->first_tlv.tl.type);
4144 /* check if tlv type is known */
4145 if (ecore_iov_tlv_supported(mbx->first_tlv.tl.type) &&
4146 !p_vf->b_malicious) {
4147 /* switch on the opcode */
4148 switch (mbx->first_tlv.tl.type) {
4149 case CHANNEL_TLV_ACQUIRE:
4150 ecore_iov_vf_mbx_acquire(p_hwfn, p_ptt, p_vf);
4152 case CHANNEL_TLV_VPORT_START:
4153 ecore_iov_vf_mbx_start_vport(p_hwfn, p_ptt, p_vf);
4155 case CHANNEL_TLV_VPORT_TEARDOWN:
4156 ecore_iov_vf_mbx_stop_vport(p_hwfn, p_ptt, p_vf);
4158 case CHANNEL_TLV_START_RXQ:
4159 ecore_iov_vf_mbx_start_rxq(p_hwfn, p_ptt, p_vf);
4161 case CHANNEL_TLV_START_TXQ:
4162 ecore_iov_vf_mbx_start_txq(p_hwfn, p_ptt, p_vf);
4164 case CHANNEL_TLV_STOP_RXQS:
4165 ecore_iov_vf_mbx_stop_rxqs(p_hwfn, p_ptt, p_vf);
4167 case CHANNEL_TLV_STOP_TXQS:
4168 ecore_iov_vf_mbx_stop_txqs(p_hwfn, p_ptt, p_vf);
4170 case CHANNEL_TLV_UPDATE_RXQ:
4171 ecore_iov_vf_mbx_update_rxqs(p_hwfn, p_ptt, p_vf);
4173 case CHANNEL_TLV_VPORT_UPDATE:
4174 ecore_iov_vf_mbx_vport_update(p_hwfn, p_ptt, p_vf);
4176 case CHANNEL_TLV_UCAST_FILTER:
4177 ecore_iov_vf_mbx_ucast_filter(p_hwfn, p_ptt, p_vf);
4179 case CHANNEL_TLV_CLOSE:
4180 ecore_iov_vf_mbx_close(p_hwfn, p_ptt, p_vf);
4182 case CHANNEL_TLV_INT_CLEANUP:
4183 ecore_iov_vf_mbx_int_cleanup(p_hwfn, p_ptt, p_vf);
4185 case CHANNEL_TLV_RELEASE:
4186 ecore_iov_vf_mbx_release(p_hwfn, p_ptt, p_vf);
4188 case CHANNEL_TLV_UPDATE_TUNN_PARAM:
4189 ecore_iov_vf_mbx_update_tunn_param(p_hwfn, p_ptt, p_vf);
4191 case CHANNEL_TLV_COALESCE_UPDATE:
4192 ecore_iov_vf_pf_set_coalesce(p_hwfn, p_ptt, p_vf);
4194 case CHANNEL_TLV_COALESCE_READ:
4195 ecore_iov_vf_pf_get_coalesce(p_hwfn, p_ptt, p_vf);
4197 case CHANNEL_TLV_UPDATE_MTU:
4198 ecore_iov_vf_pf_update_mtu(p_hwfn, p_ptt, p_vf);
4201 } else if (ecore_iov_tlv_supported(mbx->first_tlv.tl.type)) {
4202 /* If we've received a message from a VF we consider malicious
4203 * we ignore the messasge unless it's one for RELEASE, in which
4204 * case we'll let it have the benefit of doubt, allowing the
4205 * next loaded driver to start again.
4207 if (mbx->first_tlv.tl.type == CHANNEL_TLV_RELEASE) {
4208 /* TODO - initiate FLR, remove malicious indication */
4209 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
4210 "VF [%02x] - considered malicious, but wanted to RELEASE. TODO\n",
4213 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
4214 "VF [%02x] - considered malicious; Ignoring TLV [%04x]\n",
4215 p_vf->abs_vf_id, mbx->first_tlv.tl.type);
4218 ecore_iov_prepare_resp(p_hwfn, p_ptt, p_vf,
4219 mbx->first_tlv.tl.type,
4220 sizeof(struct pfvf_def_resp_tlv),
4221 PFVF_STATUS_MALICIOUS);
4223 /* unknown TLV - this may belong to a VF driver from the future
4224 * - a version written after this PF driver was written, which
4225 * supports features unknown as of yet. Too bad since we don't
4226 * support them. Or this may be because someone wrote a crappy
4227 * VF driver and is sending garbage over the channel.
4229 DP_NOTICE(p_hwfn, false,
4230 "VF[%02x]: unknown TLV. type %04x length %04x"
4231 " padding %08x reply address %lu\n",
4233 mbx->first_tlv.tl.type,
4234 mbx->first_tlv.tl.length,
4235 mbx->first_tlv.padding,
4236 (unsigned long)mbx->first_tlv.reply_address);
4238 /* Try replying in case reply address matches the acquisition's
4241 if (p_vf->acquire.first_tlv.reply_address &&
4242 (mbx->first_tlv.reply_address ==
4243 p_vf->acquire.first_tlv.reply_address))
4244 ecore_iov_prepare_resp(p_hwfn, p_ptt, p_vf,
4245 mbx->first_tlv.tl.type,
4246 sizeof(struct pfvf_def_resp_tlv),
4247 PFVF_STATUS_NOT_SUPPORTED);
4249 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
4250 "VF[%02x]: Can't respond to TLV -"
4251 " no valid reply address\n",
4255 ecore_iov_unlock_vf_pf_channel(p_hwfn, p_vf,
4256 mbx->first_tlv.tl.type);
4258 #ifdef CONFIG_ECORE_SW_CHANNEL
4259 mbx->sw_mbx.mbx_state = VF_PF_RESPONSE_READY;
4260 mbx->sw_mbx.response_offset = 0;
4264 void ecore_iov_pf_get_pending_events(struct ecore_hwfn *p_hwfn,
4269 OSAL_MEM_ZERO(events, sizeof(u64) * ECORE_VF_ARRAY_LENGTH);
4271 ecore_for_each_vf(p_hwfn, i) {
4272 struct ecore_vf_info *p_vf;
4274 p_vf = &p_hwfn->pf_iov_info->vfs_array[i];
4275 if (p_vf->vf_mbx.b_pending_msg)
4276 events[i / 64] |= 1ULL << (i % 64);
4280 static struct ecore_vf_info *
4281 ecore_sriov_get_vf_from_absid(struct ecore_hwfn *p_hwfn, u16 abs_vfid)
4283 u8 min = (u8)p_hwfn->p_dev->p_iov_info->first_vf_in_pf;
4285 if (!_ecore_iov_pf_sanity_check(p_hwfn, (int)abs_vfid - min, false)) {
4286 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
4287 "Got indication for VF [abs 0x%08x] that cannot be"
4293 return &p_hwfn->pf_iov_info->vfs_array[(u8)abs_vfid - min];
4296 static enum _ecore_status_t ecore_sriov_vfpf_msg(struct ecore_hwfn *p_hwfn,
4298 struct regpair *vf_msg)
4300 struct ecore_vf_info *p_vf = ecore_sriov_get_vf_from_absid(p_hwfn,
4304 return ECORE_SUCCESS;
4306 /* List the physical address of the request so that handler
4307 * could later on copy the message from it.
4309 p_vf->vf_mbx.pending_req = (((u64)vf_msg->hi) << 32) | vf_msg->lo;
4311 p_vf->vf_mbx.b_pending_msg = true;
4313 return OSAL_PF_VF_MSG(p_hwfn, p_vf->relative_vf_id);
4316 static void ecore_sriov_vfpf_malicious(struct ecore_hwfn *p_hwfn,
4317 struct malicious_vf_eqe_data *p_data)
4319 struct ecore_vf_info *p_vf;
4321 p_vf = ecore_sriov_get_vf_from_absid(p_hwfn, p_data->vf_id);
4326 if (!p_vf->b_malicious) {
4327 DP_NOTICE(p_hwfn, false,
4328 "VF [%d] - Malicious behavior [%02x]\n",
4329 p_vf->abs_vf_id, p_data->err_id);
4331 p_vf->b_malicious = true;
4334 "VF [%d] - Malicious behavior [%02x]\n",
4335 p_vf->abs_vf_id, p_data->err_id);
4338 OSAL_PF_VF_MALICIOUS(p_hwfn, p_vf->relative_vf_id);
4341 static enum _ecore_status_t ecore_sriov_eqe_event(struct ecore_hwfn *p_hwfn,
4344 union event_ring_data *data,
4345 u8 OSAL_UNUSED fw_return_code)
4348 case COMMON_EVENT_VF_PF_CHANNEL:
4349 return ecore_sriov_vfpf_msg(p_hwfn, OSAL_LE16_TO_CPU(echo),
4350 &data->vf_pf_channel.msg_addr);
4351 case COMMON_EVENT_VF_FLR:
4352 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
4353 "VF-FLR is still not supported\n");
4354 return ECORE_SUCCESS;
4355 case COMMON_EVENT_MALICIOUS_VF:
4356 ecore_sriov_vfpf_malicious(p_hwfn, &data->malicious_vf);
4357 return ECORE_SUCCESS;
4359 DP_INFO(p_hwfn->p_dev, "Unknown sriov eqe event 0x%02x\n",
4365 bool ecore_iov_is_vf_pending_flr(struct ecore_hwfn *p_hwfn, u16 rel_vf_id)
4367 return !!(p_hwfn->pf_iov_info->pending_flr[rel_vf_id / 64] &
4368 (1ULL << (rel_vf_id % 64)));
4371 u16 ecore_iov_get_next_active_vf(struct ecore_hwfn *p_hwfn, u16 rel_vf_id)
4373 struct ecore_hw_sriov_info *p_iov = p_hwfn->p_dev->p_iov_info;
4379 for (i = rel_vf_id; i < p_iov->total_vfs; i++)
4380 if (ecore_iov_is_valid_vfid(p_hwfn, rel_vf_id, true, false))
4384 return MAX_NUM_VFS_E4;
4387 enum _ecore_status_t ecore_iov_copy_vf_msg(struct ecore_hwfn *p_hwfn,
4388 struct ecore_ptt *ptt, int vfid)
4390 struct ecore_dmae_params params;
4391 struct ecore_vf_info *vf_info;
4393 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4397 OSAL_MEMSET(¶ms, 0, sizeof(struct ecore_dmae_params));
4398 params.flags = ECORE_DMAE_FLAG_VF_SRC | ECORE_DMAE_FLAG_COMPLETION_DST;
4399 params.src_vfid = vf_info->abs_vf_id;
4401 if (ecore_dmae_host2host(p_hwfn, ptt,
4402 vf_info->vf_mbx.pending_req,
4403 vf_info->vf_mbx.req_phys,
4404 sizeof(union vfpf_tlvs) / 4, ¶ms)) {
4405 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
4406 "Failed to copy message from VF 0x%02x\n", vfid);
4411 return ECORE_SUCCESS;
4414 void ecore_iov_bulletin_set_forced_mac(struct ecore_hwfn *p_hwfn,
4417 struct ecore_vf_info *vf_info;
4420 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4422 DP_NOTICE(p_hwfn->p_dev, true,
4423 "Can not set forced MAC, invalid vfid [%d]\n", vfid);
4426 if (vf_info->b_malicious) {
4427 DP_NOTICE(p_hwfn->p_dev, false,
4428 "Can't set forced MAC to malicious VF [%d]\n",
4433 if (p_hwfn->pf_params.eth_pf_params.allow_vf_mac_change ||
4434 vf_info->p_vf_info.is_trusted_configured) {
4435 feature = 1 << VFPF_BULLETIN_MAC_ADDR;
4436 /* Trust mode will disable Forced MAC */
4437 vf_info->bulletin.p_virt->valid_bitmap &=
4438 ~(1 << MAC_ADDR_FORCED);
4440 feature = 1 << MAC_ADDR_FORCED;
4441 /* Forced MAC will disable MAC_ADDR */
4442 vf_info->bulletin.p_virt->valid_bitmap &=
4443 ~(1 << VFPF_BULLETIN_MAC_ADDR);
4446 OSAL_MEMCPY(vf_info->bulletin.p_virt->mac,
4449 vf_info->bulletin.p_virt->valid_bitmap |= feature;
4451 ecore_iov_configure_vport_forced(p_hwfn, vf_info, feature);
4454 enum _ecore_status_t ecore_iov_bulletin_set_mac(struct ecore_hwfn *p_hwfn,
4457 struct ecore_vf_info *vf_info;
4460 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4462 DP_NOTICE(p_hwfn->p_dev, true,
4463 "Can not set MAC, invalid vfid [%d]\n", vfid);
4466 if (vf_info->b_malicious) {
4467 DP_NOTICE(p_hwfn->p_dev, false,
4468 "Can't set MAC to malicious VF [%d]\n",
4473 if (vf_info->bulletin.p_virt->valid_bitmap & (1 << MAC_ADDR_FORCED)) {
4474 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
4475 "Can not set MAC, Forced MAC is configured\n");
4479 feature = 1 << VFPF_BULLETIN_MAC_ADDR;
4480 OSAL_MEMCPY(vf_info->bulletin.p_virt->mac, mac, ETH_ALEN);
4482 vf_info->bulletin.p_virt->valid_bitmap |= feature;
4484 if (p_hwfn->pf_params.eth_pf_params.allow_vf_mac_change ||
4485 vf_info->p_vf_info.is_trusted_configured)
4486 ecore_iov_configure_vport_forced(p_hwfn, vf_info, feature);
4488 return ECORE_SUCCESS;
4491 #ifndef LINUX_REMOVE
4492 enum _ecore_status_t
4493 ecore_iov_bulletin_set_forced_untagged_default(struct ecore_hwfn *p_hwfn,
4494 bool b_untagged_only, int vfid)
4496 struct ecore_vf_info *vf_info;
4499 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4501 DP_NOTICE(p_hwfn->p_dev, true,
4502 "Can not set untagged default, invalid vfid [%d]\n",
4506 if (vf_info->b_malicious) {
4507 DP_NOTICE(p_hwfn->p_dev, false,
4508 "Can't set untagged default to malicious VF [%d]\n",
4513 /* Since this is configurable only during vport-start, don't take it
4514 * if we're past that point.
4516 if (vf_info->state == VF_ENABLED) {
4517 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
4518 "Can't support untagged change for vfid[%d] -"
4519 " VF is already active\n",
4524 /* Set configuration; This will later be taken into account during the
4525 * VF initialization.
4527 feature = (1 << VFPF_BULLETIN_UNTAGGED_DEFAULT) |
4528 (1 << VFPF_BULLETIN_UNTAGGED_DEFAULT_FORCED);
4529 vf_info->bulletin.p_virt->valid_bitmap |= feature;
4531 vf_info->bulletin.p_virt->default_only_untagged = b_untagged_only ? 1
4534 return ECORE_SUCCESS;
4537 void ecore_iov_get_vfs_opaque_fid(struct ecore_hwfn *p_hwfn, int vfid,
4540 struct ecore_vf_info *vf_info;
4542 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4546 *opaque_fid = vf_info->opaque_fid;
4550 void ecore_iov_bulletin_set_forced_vlan(struct ecore_hwfn *p_hwfn,
4553 struct ecore_vf_info *vf_info;
4556 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4558 DP_NOTICE(p_hwfn->p_dev, true,
4559 "Can not set forced MAC, invalid vfid [%d]\n",
4563 if (vf_info->b_malicious) {
4564 DP_NOTICE(p_hwfn->p_dev, false,
4565 "Can't set forced vlan to malicious VF [%d]\n",
4570 feature = 1 << VLAN_ADDR_FORCED;
4571 vf_info->bulletin.p_virt->pvid = pvid;
4573 vf_info->bulletin.p_virt->valid_bitmap |= feature;
4575 vf_info->bulletin.p_virt->valid_bitmap &= ~feature;
4577 ecore_iov_configure_vport_forced(p_hwfn, vf_info, feature);
4580 void ecore_iov_bulletin_set_udp_ports(struct ecore_hwfn *p_hwfn,
4581 int vfid, u16 vxlan_port, u16 geneve_port)
4583 struct ecore_vf_info *vf_info;
4585 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4587 DP_NOTICE(p_hwfn->p_dev, true,
4588 "Can not set udp ports, invalid vfid [%d]\n", vfid);
4592 if (vf_info->b_malicious) {
4593 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
4594 "Can not set udp ports to malicious VF [%d]\n",
4599 vf_info->bulletin.p_virt->vxlan_udp_port = vxlan_port;
4600 vf_info->bulletin.p_virt->geneve_udp_port = geneve_port;
4603 bool ecore_iov_vf_has_vport_instance(struct ecore_hwfn *p_hwfn, int vfid)
4605 struct ecore_vf_info *p_vf_info;
4607 p_vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4611 return !!p_vf_info->vport_instance;
4614 bool ecore_iov_is_vf_stopped(struct ecore_hwfn *p_hwfn, int vfid)
4616 struct ecore_vf_info *p_vf_info;
4618 p_vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4622 return p_vf_info->state == VF_STOPPED;
4625 bool ecore_iov_spoofchk_get(struct ecore_hwfn *p_hwfn, int vfid)
4627 struct ecore_vf_info *vf_info;
4629 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4633 return vf_info->spoof_chk;
4636 enum _ecore_status_t ecore_iov_spoofchk_set(struct ecore_hwfn *p_hwfn,
4639 struct ecore_vf_info *vf;
4640 enum _ecore_status_t rc = ECORE_INVAL;
4642 if (!ecore_iov_pf_sanity_check(p_hwfn, vfid)) {
4643 DP_NOTICE(p_hwfn, true,
4644 "SR-IOV sanity check failed, can't set spoofchk\n");
4648 vf = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4652 if (!ecore_iov_vf_has_vport_instance(p_hwfn, vfid)) {
4653 /* After VF VPORT start PF will configure spoof check */
4654 vf->req_spoofchk_val = val;
4659 rc = __ecore_iov_spoofchk_set(p_hwfn, vf, val);
4665 u8 ecore_iov_vf_chains_per_pf(struct ecore_hwfn *p_hwfn)
4667 u8 max_chains_per_vf = p_hwfn->hw_info.max_chains_per_vf;
4669 max_chains_per_vf = (max_chains_per_vf) ? max_chains_per_vf
4670 : ECORE_MAX_VF_CHAINS_PER_PF;
4672 return max_chains_per_vf;
4675 void ecore_iov_get_vf_req_virt_mbx_params(struct ecore_hwfn *p_hwfn,
4677 void **pp_req_virt_addr,
4678 u16 *p_req_virt_size)
4680 struct ecore_vf_info *vf_info =
4681 ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4686 if (pp_req_virt_addr)
4687 *pp_req_virt_addr = vf_info->vf_mbx.req_virt;
4689 if (p_req_virt_size)
4690 *p_req_virt_size = sizeof(*vf_info->vf_mbx.req_virt);
4693 void ecore_iov_get_vf_reply_virt_mbx_params(struct ecore_hwfn *p_hwfn,
4695 void **pp_reply_virt_addr,
4696 u16 *p_reply_virt_size)
4698 struct ecore_vf_info *vf_info =
4699 ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4704 if (pp_reply_virt_addr)
4705 *pp_reply_virt_addr = vf_info->vf_mbx.reply_virt;
4707 if (p_reply_virt_size)
4708 *p_reply_virt_size = sizeof(*vf_info->vf_mbx.reply_virt);
4711 #ifdef CONFIG_ECORE_SW_CHANNEL
4712 struct ecore_iov_sw_mbx *ecore_iov_get_vf_sw_mbx(struct ecore_hwfn *p_hwfn,
4715 struct ecore_vf_info *vf_info =
4716 ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4721 return &vf_info->vf_mbx.sw_mbx;
4725 bool ecore_iov_is_valid_vfpf_msg_length(u32 length)
4727 return (length >= sizeof(struct vfpf_first_tlv) &&
4728 (length <= sizeof(union vfpf_tlvs)));
4731 u32 ecore_iov_pfvf_msg_length(void)
4733 return sizeof(union pfvf_tlvs);
4736 u8 *ecore_iov_bulletin_get_mac(struct ecore_hwfn *p_hwfn,
4739 struct ecore_vf_info *p_vf;
4741 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4742 if (!p_vf || !p_vf->bulletin.p_virt)
4745 if (!(p_vf->bulletin.p_virt->valid_bitmap &
4746 (1 << VFPF_BULLETIN_MAC_ADDR)))
4749 return p_vf->bulletin.p_virt->mac;
4752 u8 *ecore_iov_bulletin_get_forced_mac(struct ecore_hwfn *p_hwfn, u16 rel_vf_id)
4754 struct ecore_vf_info *p_vf;
4756 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4757 if (!p_vf || !p_vf->bulletin.p_virt)
4760 if (!(p_vf->bulletin.p_virt->valid_bitmap & (1 << MAC_ADDR_FORCED)))
4763 return p_vf->bulletin.p_virt->mac;
4766 u16 ecore_iov_bulletin_get_forced_vlan(struct ecore_hwfn *p_hwfn,
4769 struct ecore_vf_info *p_vf;
4771 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4772 if (!p_vf || !p_vf->bulletin.p_virt)
4775 if (!(p_vf->bulletin.p_virt->valid_bitmap & (1 << VLAN_ADDR_FORCED)))
4778 return p_vf->bulletin.p_virt->pvid;
4781 enum _ecore_status_t ecore_iov_configure_tx_rate(struct ecore_hwfn *p_hwfn,
4782 struct ecore_ptt *p_ptt,
4785 struct ecore_mcp_link_state *p_link;
4786 struct ecore_vf_info *vf;
4788 enum _ecore_status_t rc;
4790 vf = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4795 rc = ecore_fw_vport(p_hwfn, vf->vport_id, &abs_vp_id);
4796 if (rc != ECORE_SUCCESS)
4799 p_link = &ECORE_LEADING_HWFN(p_hwfn->p_dev)->mcp_info->link_output;
4801 return ecore_init_vport_rl(p_hwfn, p_ptt, abs_vp_id, (u32)val,
4805 enum _ecore_status_t ecore_iov_configure_min_tx_rate(struct ecore_dev *p_dev,
4808 struct ecore_vf_info *vf;
4811 for_each_hwfn(p_dev, i) {
4812 struct ecore_hwfn *p_hwfn = &p_dev->hwfns[i];
4814 if (!ecore_iov_pf_sanity_check(p_hwfn, vfid)) {
4815 DP_NOTICE(p_hwfn, true,
4816 "SR-IOV sanity check failed, can't set min rate\n");
4821 vf = ecore_iov_get_vf_info(ECORE_LEADING_HWFN(p_dev), (u16)vfid, true);
4823 DP_NOTICE(p_dev, true,
4824 "Getting vf info failed, can't set min rate\n");
4828 return ecore_configure_vport_wfq(p_dev, vf->vport_id, rate);
4831 enum _ecore_status_t ecore_iov_get_vf_stats(struct ecore_hwfn *p_hwfn,
4832 struct ecore_ptt *p_ptt,
4834 struct ecore_eth_stats *p_stats)
4836 struct ecore_vf_info *vf;
4838 vf = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4842 if (vf->state != VF_ENABLED)
4845 __ecore_get_vport_stats(p_hwfn, p_ptt, p_stats,
4846 vf->abs_vf_id + 0x10, false);
4848 return ECORE_SUCCESS;
4851 u8 ecore_iov_get_vf_num_rxqs(struct ecore_hwfn *p_hwfn, u16 rel_vf_id)
4853 struct ecore_vf_info *p_vf;
4855 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4859 return p_vf->num_rxqs;
4862 u8 ecore_iov_get_vf_num_active_rxqs(struct ecore_hwfn *p_hwfn, u16 rel_vf_id)
4864 struct ecore_vf_info *p_vf;
4866 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4870 return p_vf->num_active_rxqs;
4873 void *ecore_iov_get_vf_ctx(struct ecore_hwfn *p_hwfn, u16 rel_vf_id)
4875 struct ecore_vf_info *p_vf;
4877 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4884 u8 ecore_iov_get_vf_num_sbs(struct ecore_hwfn *p_hwfn, u16 rel_vf_id)
4886 struct ecore_vf_info *p_vf;
4888 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4892 return p_vf->num_sbs;
4895 bool ecore_iov_is_vf_wait_for_acquire(struct ecore_hwfn *p_hwfn, u16 rel_vf_id)
4897 struct ecore_vf_info *p_vf;
4899 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4903 return (p_vf->state == VF_FREE);
4906 bool ecore_iov_is_vf_acquired_not_initialized(struct ecore_hwfn *p_hwfn,
4909 struct ecore_vf_info *p_vf;
4911 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4915 return (p_vf->state == VF_ACQUIRED);
4918 bool ecore_iov_is_vf_initialized(struct ecore_hwfn *p_hwfn, u16 rel_vf_id)
4920 struct ecore_vf_info *p_vf;
4922 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4926 return (p_vf->state == VF_ENABLED);
4929 bool ecore_iov_is_vf_started(struct ecore_hwfn *p_hwfn,
4932 struct ecore_vf_info *p_vf;
4934 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4938 return (p_vf->state != VF_FREE && p_vf->state != VF_STOPPED);
4942 ecore_iov_get_vf_min_rate(struct ecore_hwfn *p_hwfn, int vfid)
4944 struct ecore_wfq_data *vf_vp_wfq;
4945 struct ecore_vf_info *vf_info;
4947 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4951 vf_vp_wfq = &p_hwfn->qm_info.wfq_data[vf_info->vport_id];
4953 if (vf_vp_wfq->configured)
4954 return vf_vp_wfq->min_speed;
4959 #ifdef CONFIG_ECORE_SW_CHANNEL
4960 void ecore_iov_set_vf_hw_channel(struct ecore_hwfn *p_hwfn, int vfid,
4963 struct ecore_vf_info *vf_info;
4965 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4969 vf_info->b_hw_channel = b_is_hw;