2 * Copyright (c) 2016 QLogic Corporation.
6 * See LICENSE.qede_pmd for copyright and licensing details.
12 #include "ecore_sriov.h"
13 #include "ecore_status.h"
15 #include "ecore_hw_defs.h"
16 #include "ecore_int.h"
17 #include "ecore_hsi_eth.h"
19 #include "ecore_vfpf_if.h"
20 #include "ecore_rt_defs.h"
21 #include "ecore_init_ops.h"
22 #include "ecore_gtt_reg_addr.h"
23 #include "ecore_iro.h"
24 #include "ecore_mcp.h"
25 #include "ecore_cxt.h"
27 #include "ecore_init_fw_funcs.h"
28 #include "ecore_sp_commands.h"
30 static enum _ecore_status_t ecore_sriov_eqe_event(struct ecore_hwfn *p_hwfn,
33 union event_ring_data *data,
36 const char *ecore_channel_tlvs_string[] = {
37 "CHANNEL_TLV_NONE", /* ends tlv sequence */
38 "CHANNEL_TLV_ACQUIRE",
39 "CHANNEL_TLV_VPORT_START",
40 "CHANNEL_TLV_VPORT_UPDATE",
41 "CHANNEL_TLV_VPORT_TEARDOWN",
42 "CHANNEL_TLV_START_RXQ",
43 "CHANNEL_TLV_START_TXQ",
44 "CHANNEL_TLV_STOP_RXQ",
45 "CHANNEL_TLV_STOP_TXQ",
46 "CHANNEL_TLV_UPDATE_RXQ",
47 "CHANNEL_TLV_INT_CLEANUP",
49 "CHANNEL_TLV_RELEASE",
50 "CHANNEL_TLV_LIST_END",
51 "CHANNEL_TLV_UCAST_FILTER",
52 "CHANNEL_TLV_VPORT_UPDATE_ACTIVATE",
53 "CHANNEL_TLV_VPORT_UPDATE_TX_SWITCH",
54 "CHANNEL_TLV_VPORT_UPDATE_VLAN_STRIP",
55 "CHANNEL_TLV_VPORT_UPDATE_MCAST",
56 "CHANNEL_TLV_VPORT_UPDATE_ACCEPT_PARAM",
57 "CHANNEL_TLV_VPORT_UPDATE_RSS",
58 "CHANNEL_TLV_VPORT_UPDATE_ACCEPT_ANY_VLAN",
59 "CHANNEL_TLV_VPORT_UPDATE_SGE_TPA",
60 "CHANNEL_TLV_UPDATE_TUNN_PARAM",
61 "CHANNEL_TLV_COALESCE_UPDATE",
63 "CHANNEL_TLV_COALESCE_READ",
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, true,
594 "Failed to allocate `struct ecore_sriov'\n");
598 p_hwfn->pf_iov_info = p_sriov;
600 ecore_spq_register_async_cb(p_hwfn, PROTOCOLID_COMMON,
601 ecore_sriov_eqe_event);
603 return ecore_iov_allocate_vfdb(p_hwfn);
606 void ecore_iov_setup(struct ecore_hwfn *p_hwfn)
608 if (!IS_PF_SRIOV(p_hwfn) || !IS_PF_SRIOV_ALLOC(p_hwfn))
611 ecore_iov_setup_vfdb(p_hwfn);
614 void ecore_iov_free(struct ecore_hwfn *p_hwfn)
616 ecore_spq_unregister_async_cb(p_hwfn, PROTOCOLID_COMMON);
618 if (IS_PF_SRIOV_ALLOC(p_hwfn)) {
619 ecore_iov_free_vfdb(p_hwfn);
620 OSAL_FREE(p_hwfn->p_dev, p_hwfn->pf_iov_info);
624 void ecore_iov_free_hw_info(struct ecore_dev *p_dev)
626 OSAL_FREE(p_dev, p_dev->p_iov_info);
629 enum _ecore_status_t ecore_iov_hw_info(struct ecore_hwfn *p_hwfn)
631 struct ecore_dev *p_dev = p_hwfn->p_dev;
633 enum _ecore_status_t rc;
635 if (IS_VF(p_hwfn->p_dev))
636 return ECORE_SUCCESS;
638 /* Learn the PCI configuration */
639 pos = OSAL_PCI_FIND_EXT_CAPABILITY(p_hwfn->p_dev,
640 PCI_EXT_CAP_ID_SRIOV);
642 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV, "No PCIe IOV support\n");
643 return ECORE_SUCCESS;
646 /* Allocate a new struct for IOV information */
647 /* TODO - can change to VALLOC when its available */
648 p_dev->p_iov_info = OSAL_ZALLOC(p_dev, GFP_KERNEL,
649 sizeof(*p_dev->p_iov_info));
650 if (!p_dev->p_iov_info) {
651 DP_NOTICE(p_hwfn, true,
652 "Can't support IOV due to lack of memory\n");
655 p_dev->p_iov_info->pos = pos;
657 rc = ecore_iov_pci_cfg_info(p_dev);
661 /* We want PF IOV to be synonemous with the existence of p_iov_info;
662 * In case the capability is published but there are no VFs, simply
663 * de-allocate the struct.
665 if (!p_dev->p_iov_info->total_vfs) {
666 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
667 "IOV capabilities, but no VFs are published\n");
668 OSAL_FREE(p_dev, p_dev->p_iov_info);
669 return ECORE_SUCCESS;
672 /* First VF index based on offset is tricky:
673 * - If ARI is supported [likely], offset - (16 - pf_id) would
674 * provide the number for eng0. 2nd engine Vfs would begin
675 * after the first engine's VFs.
676 * - If !ARI, VFs would start on next device.
677 * so offset - (256 - pf_id) would provide the number.
678 * Utilize the fact that (256 - pf_id) is achieved only be later
679 * to diffrentiate between the two.
682 if (p_hwfn->p_dev->p_iov_info->offset < (256 - p_hwfn->abs_pf_id)) {
683 u32 first = p_hwfn->p_dev->p_iov_info->offset +
684 p_hwfn->abs_pf_id - 16;
686 p_dev->p_iov_info->first_vf_in_pf = first;
688 if (ECORE_PATH_ID(p_hwfn))
689 p_dev->p_iov_info->first_vf_in_pf -= MAX_NUM_VFS_BB;
691 u32 first = p_hwfn->p_dev->p_iov_info->offset +
692 p_hwfn->abs_pf_id - 256;
694 p_dev->p_iov_info->first_vf_in_pf = first;
697 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
698 "First VF in hwfn 0x%08x\n",
699 p_dev->p_iov_info->first_vf_in_pf);
701 return ECORE_SUCCESS;
704 static bool _ecore_iov_pf_sanity_check(struct ecore_hwfn *p_hwfn, int vfid,
705 bool b_fail_malicious)
707 /* Check PF supports sriov */
708 if (IS_VF(p_hwfn->p_dev) || !IS_ECORE_SRIOV(p_hwfn->p_dev) ||
709 !IS_PF_SRIOV_ALLOC(p_hwfn))
712 /* Check VF validity */
713 if (!ecore_iov_is_valid_vfid(p_hwfn, vfid, true, b_fail_malicious))
719 bool ecore_iov_pf_sanity_check(struct ecore_hwfn *p_hwfn, int vfid)
721 return _ecore_iov_pf_sanity_check(p_hwfn, vfid, true);
724 void ecore_iov_set_vf_to_disable(struct ecore_dev *p_dev,
725 u16 rel_vf_id, u8 to_disable)
727 struct ecore_vf_info *vf;
730 for_each_hwfn(p_dev, i) {
731 struct ecore_hwfn *p_hwfn = &p_dev->hwfns[i];
733 vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, false);
737 vf->to_disable = to_disable;
741 void ecore_iov_set_vfs_to_disable(struct ecore_dev *p_dev,
746 if (!IS_ECORE_SRIOV(p_dev))
749 for (i = 0; i < p_dev->p_iov_info->total_vfs; i++)
750 ecore_iov_set_vf_to_disable(p_dev, i, to_disable);
754 /* @@@TBD Consider taking outside of ecore... */
755 enum _ecore_status_t ecore_iov_set_vf_ctx(struct ecore_hwfn *p_hwfn,
759 enum _ecore_status_t rc = ECORE_SUCCESS;
760 struct ecore_vf_info *vf = ecore_iov_get_vf_info(p_hwfn, vf_id, true);
762 if (vf != OSAL_NULL) {
764 #ifdef CONFIG_ECORE_SW_CHANNEL
765 vf->vf_mbx.sw_mbx.mbx_state = VF_PF_WAIT_FOR_START_REQUEST;
768 rc = ECORE_UNKNOWN_ERROR;
774 static void ecore_iov_vf_pglue_clear_err(struct ecore_hwfn *p_hwfn,
775 struct ecore_ptt *p_ptt,
778 ecore_wr(p_hwfn, p_ptt,
779 PGLUE_B_REG_WAS_ERROR_VF_31_0_CLR + (abs_vfid >> 5) * 4,
780 1 << (abs_vfid & 0x1f));
783 static void ecore_iov_vf_igu_reset(struct ecore_hwfn *p_hwfn,
784 struct ecore_ptt *p_ptt,
785 struct ecore_vf_info *vf)
789 /* Set VF masks and configuration - pretend */
790 ecore_fid_pretend(p_hwfn, p_ptt, (u16)vf->concrete_fid);
792 ecore_wr(p_hwfn, p_ptt, IGU_REG_STATISTIC_NUM_VF_MSG_SENT, 0);
795 ecore_fid_pretend(p_hwfn, p_ptt, (u16)p_hwfn->hw_info.concrete_fid);
797 /* iterate over all queues, clear sb consumer */
798 for (i = 0; i < vf->num_sbs; i++)
799 ecore_int_igu_init_pure_rt_single(p_hwfn, p_ptt,
801 vf->opaque_fid, true);
804 static void ecore_iov_vf_igu_set_int(struct ecore_hwfn *p_hwfn,
805 struct ecore_ptt *p_ptt,
806 struct ecore_vf_info *vf, bool enable)
810 ecore_fid_pretend(p_hwfn, p_ptt, (u16)vf->concrete_fid);
812 igu_vf_conf = ecore_rd(p_hwfn, p_ptt, IGU_REG_VF_CONFIGURATION);
815 igu_vf_conf |= IGU_VF_CONF_MSI_MSIX_EN;
817 igu_vf_conf &= ~IGU_VF_CONF_MSI_MSIX_EN;
819 ecore_wr(p_hwfn, p_ptt, IGU_REG_VF_CONFIGURATION, igu_vf_conf);
822 ecore_fid_pretend(p_hwfn, p_ptt, (u16)p_hwfn->hw_info.concrete_fid);
825 static enum _ecore_status_t
826 ecore_iov_enable_vf_access_msix(struct ecore_hwfn *p_hwfn,
827 struct ecore_ptt *p_ptt,
834 /* If client overrides this, don't do anything */
835 if (p_hwfn->p_dev->b_dont_override_vf_msix)
836 return ECORE_SUCCESS;
838 /* For AH onward, configuration is per-PF. Find maximum of all
839 * the currently enabled child VFs, and set the number to be that.
841 if (!ECORE_IS_BB(p_hwfn->p_dev)) {
842 ecore_for_each_vf(p_hwfn, i) {
843 struct ecore_vf_info *p_vf;
845 p_vf = ecore_iov_get_vf_info(p_hwfn, (u16)i, true);
849 current_max = OSAL_MAX_T(u8, current_max,
854 if (num_sbs > current_max)
855 return ecore_mcp_config_vf_msix(p_hwfn, p_ptt,
858 return ECORE_SUCCESS;
861 static enum _ecore_status_t
862 ecore_iov_enable_vf_access(struct ecore_hwfn *p_hwfn,
863 struct ecore_ptt *p_ptt, struct ecore_vf_info *vf)
865 u32 igu_vf_conf = IGU_VF_CONF_FUNC_EN;
866 enum _ecore_status_t rc = ECORE_SUCCESS;
869 return ECORE_SUCCESS;
871 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
872 "Enable internal access for vf %x [abs %x]\n", vf->abs_vf_id,
873 ECORE_VF_ABS_ID(p_hwfn, vf));
875 ecore_iov_vf_pglue_clear_err(p_hwfn, p_ptt,
876 ECORE_VF_ABS_ID(p_hwfn, vf));
878 ecore_iov_vf_igu_reset(p_hwfn, p_ptt, vf);
880 /* It's possible VF was previously considered malicious */
881 vf->b_malicious = false;
882 rc = ecore_iov_enable_vf_access_msix(p_hwfn, p_ptt,
883 vf->abs_vf_id, vf->num_sbs);
884 if (rc != ECORE_SUCCESS)
887 ecore_fid_pretend(p_hwfn, p_ptt, (u16)vf->concrete_fid);
889 SET_FIELD(igu_vf_conf, IGU_VF_CONF_PARENT, p_hwfn->rel_pf_id);
890 STORE_RT_REG(p_hwfn, IGU_REG_VF_CONFIGURATION_RT_OFFSET, igu_vf_conf);
892 ecore_init_run(p_hwfn, p_ptt, PHASE_VF, vf->abs_vf_id,
893 p_hwfn->hw_info.hw_mode);
896 ecore_fid_pretend(p_hwfn, p_ptt, (u16)p_hwfn->hw_info.concrete_fid);
905 * @brief ecore_iov_config_perm_table - configure the permission
907 * In E4, queue zone permission table size is 320x9. There
908 * are 320 VF queues for single engine device (256 for dual
909 * engine device), and each entry has the following format:
916 static void ecore_iov_config_perm_table(struct ecore_hwfn *p_hwfn,
917 struct ecore_ptt *p_ptt,
918 struct ecore_vf_info *vf, u8 enable)
924 for (qid = 0; qid < vf->num_rxqs; qid++) {
925 ecore_fw_l2_queue(p_hwfn, vf->vf_queues[qid].fw_rx_qid,
928 reg_addr = PSWHST_REG_ZONE_PERMISSION_TABLE + qzone_id * 4;
929 val = enable ? (vf->abs_vf_id | (1 << 8)) : 0;
930 ecore_wr(p_hwfn, p_ptt, reg_addr, val);
934 static void ecore_iov_enable_vf_traffic(struct ecore_hwfn *p_hwfn,
935 struct ecore_ptt *p_ptt,
936 struct ecore_vf_info *vf)
938 /* Reset vf in IGU - interrupts are still disabled */
939 ecore_iov_vf_igu_reset(p_hwfn, p_ptt, vf);
941 ecore_iov_vf_igu_set_int(p_hwfn, p_ptt, vf, 1);
943 /* Permission Table */
944 ecore_iov_config_perm_table(p_hwfn, p_ptt, vf, true);
947 static u8 ecore_iov_alloc_vf_igu_sbs(struct ecore_hwfn *p_hwfn,
948 struct ecore_ptt *p_ptt,
949 struct ecore_vf_info *vf,
952 struct ecore_igu_block *p_block;
953 struct cau_sb_entry sb_entry;
957 if (num_rx_queues > p_hwfn->hw_info.p_igu_info->usage.free_cnt_iov)
959 (u16)p_hwfn->hw_info.p_igu_info->usage.free_cnt_iov;
960 p_hwfn->hw_info.p_igu_info->usage.free_cnt_iov -= num_rx_queues;
962 SET_FIELD(val, IGU_MAPPING_LINE_FUNCTION_NUMBER, vf->abs_vf_id);
963 SET_FIELD(val, IGU_MAPPING_LINE_VALID, 1);
964 SET_FIELD(val, IGU_MAPPING_LINE_PF_VALID, 0);
966 for (qid = 0; qid < num_rx_queues; qid++) {
967 p_block = ecore_get_igu_free_sb(p_hwfn, false);
968 vf->igu_sbs[qid] = p_block->igu_sb_id;
969 p_block->status &= ~ECORE_IGU_STATUS_FREE;
970 SET_FIELD(val, IGU_MAPPING_LINE_VECTOR_NUMBER, qid);
972 ecore_wr(p_hwfn, p_ptt,
973 IGU_REG_MAPPING_MEMORY +
974 sizeof(u32) * p_block->igu_sb_id, val);
976 /* Configure igu sb in CAU which were marked valid */
977 ecore_init_cau_sb_entry(p_hwfn, &sb_entry,
980 ecore_dmae_host2grc(p_hwfn, p_ptt,
981 (u64)(osal_uintptr_t)&sb_entry,
982 CAU_REG_SB_VAR_MEMORY +
983 p_block->igu_sb_id * sizeof(u64), 2, 0);
986 vf->num_sbs = (u8)num_rx_queues;
993 * @brief The function invalidates all the VF entries,
994 * technically this isn't required, but added for
995 * cleaness and ease of debugging incase a VF attempts to
996 * produce an interrupt after it has been taken down.
1002 static void ecore_iov_free_vf_igu_sbs(struct ecore_hwfn *p_hwfn,
1003 struct ecore_ptt *p_ptt,
1004 struct ecore_vf_info *vf)
1006 struct ecore_igu_info *p_info = p_hwfn->hw_info.p_igu_info;
1010 /* Invalidate igu CAM lines and mark them as free */
1011 for (idx = 0; idx < vf->num_sbs; idx++) {
1012 igu_id = vf->igu_sbs[idx];
1013 addr = IGU_REG_MAPPING_MEMORY + sizeof(u32) * igu_id;
1015 val = ecore_rd(p_hwfn, p_ptt, addr);
1016 SET_FIELD(val, IGU_MAPPING_LINE_VALID, 0);
1017 ecore_wr(p_hwfn, p_ptt, addr, val);
1019 p_info->entry[igu_id].status |= ECORE_IGU_STATUS_FREE;
1020 p_hwfn->hw_info.p_igu_info->usage.free_cnt_iov++;
1026 void ecore_iov_set_link(struct ecore_hwfn *p_hwfn,
1028 struct ecore_mcp_link_params *params,
1029 struct ecore_mcp_link_state *link,
1030 struct ecore_mcp_link_capabilities *p_caps)
1032 struct ecore_vf_info *p_vf = ecore_iov_get_vf_info(p_hwfn, vfid, false);
1033 struct ecore_bulletin_content *p_bulletin;
1038 p_bulletin = p_vf->bulletin.p_virt;
1039 p_bulletin->req_autoneg = params->speed.autoneg;
1040 p_bulletin->req_adv_speed = params->speed.advertised_speeds;
1041 p_bulletin->req_forced_speed = params->speed.forced_speed;
1042 p_bulletin->req_autoneg_pause = params->pause.autoneg;
1043 p_bulletin->req_forced_rx = params->pause.forced_rx;
1044 p_bulletin->req_forced_tx = params->pause.forced_tx;
1045 p_bulletin->req_loopback = params->loopback_mode;
1047 p_bulletin->link_up = link->link_up;
1048 p_bulletin->speed = link->speed;
1049 p_bulletin->full_duplex = link->full_duplex;
1050 p_bulletin->autoneg = link->an;
1051 p_bulletin->autoneg_complete = link->an_complete;
1052 p_bulletin->parallel_detection = link->parallel_detection;
1053 p_bulletin->pfc_enabled = link->pfc_enabled;
1054 p_bulletin->partner_adv_speed = link->partner_adv_speed;
1055 p_bulletin->partner_tx_flow_ctrl_en = link->partner_tx_flow_ctrl_en;
1056 p_bulletin->partner_rx_flow_ctrl_en = link->partner_rx_flow_ctrl_en;
1057 p_bulletin->partner_adv_pause = link->partner_adv_pause;
1058 p_bulletin->sfp_tx_fault = link->sfp_tx_fault;
1060 p_bulletin->capability_speed = p_caps->speed_capabilities;
1063 enum _ecore_status_t
1064 ecore_iov_init_hw_for_vf(struct ecore_hwfn *p_hwfn,
1065 struct ecore_ptt *p_ptt,
1066 struct ecore_iov_vf_init_params *p_params)
1068 struct ecore_mcp_link_capabilities link_caps;
1069 struct ecore_mcp_link_params link_params;
1070 struct ecore_mcp_link_state link_state;
1071 u8 num_of_vf_available_chains = 0;
1072 struct ecore_vf_info *vf = OSAL_NULL;
1074 enum _ecore_status_t rc = ECORE_SUCCESS;
1078 vf = ecore_iov_get_vf_info(p_hwfn, p_params->rel_vf_id, false);
1080 DP_ERR(p_hwfn, "ecore_iov_init_hw_for_vf : vf is OSAL_NULL\n");
1081 return ECORE_UNKNOWN_ERROR;
1085 DP_NOTICE(p_hwfn, true, "VF[%d] is already active.\n",
1086 p_params->rel_vf_id);
1090 /* Perform sanity checking on the requested vport/rss */
1091 if (p_params->vport_id >= RESC_NUM(p_hwfn, ECORE_VPORT)) {
1092 DP_NOTICE(p_hwfn, true, "VF[%d] - can't use VPORT %02x\n",
1093 p_params->rel_vf_id, p_params->vport_id);
1097 if ((p_params->num_queues > 1) &&
1098 (p_params->rss_eng_id >= RESC_NUM(p_hwfn, ECORE_RSS_ENG))) {
1099 DP_NOTICE(p_hwfn, true, "VF[%d] - can't use RSS_ENG %02x\n",
1100 p_params->rel_vf_id, p_params->rss_eng_id);
1104 /* TODO - remove this once we get confidence of change */
1105 if (!p_params->vport_id) {
1106 DP_NOTICE(p_hwfn, false,
1107 "VF[%d] - Unlikely that VF uses vport0. Forgotten?\n",
1108 p_params->rel_vf_id);
1110 if ((!p_params->rss_eng_id) && (p_params->num_queues > 1)) {
1111 DP_NOTICE(p_hwfn, false,
1112 "VF[%d] - Unlikely that VF uses RSS_eng0. Forgotten?\n",
1113 p_params->rel_vf_id);
1115 vf->vport_id = p_params->vport_id;
1116 vf->rss_eng_id = p_params->rss_eng_id;
1118 /* Since it's possible to relocate SBs, it's a bit difficult to check
1119 * things here. Simply check whether the index falls in the range
1120 * belonging to the PF.
1122 for (i = 0; i < p_params->num_queues; i++) {
1123 qid = p_params->req_rx_queue[i];
1124 if (qid > (u16)RESC_NUM(p_hwfn, ECORE_L2_QUEUE)) {
1125 DP_NOTICE(p_hwfn, true,
1126 "Can't enable Rx qid [%04x] for VF[%d]: qids [0,,...,0x%04x] available\n",
1127 qid, p_params->rel_vf_id,
1128 (u16)RESC_NUM(p_hwfn, ECORE_L2_QUEUE));
1132 qid = p_params->req_tx_queue[i];
1133 if (qid > (u16)RESC_NUM(p_hwfn, ECORE_L2_QUEUE)) {
1134 DP_NOTICE(p_hwfn, true,
1135 "Can't enable Tx qid [%04x] for VF[%d]: qids [0,,...,0x%04x] available\n",
1136 qid, p_params->rel_vf_id,
1137 (u16)RESC_NUM(p_hwfn, ECORE_L2_QUEUE));
1142 /* Limit number of queues according to number of CIDs */
1143 ecore_cxt_get_proto_cid_count(p_hwfn, PROTOCOLID_ETH, &cids);
1144 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1145 "VF[%d] - requesting to initialize for 0x%04x queues"
1146 " [0x%04x CIDs available]\n",
1147 vf->relative_vf_id, p_params->num_queues, (u16)cids);
1148 num_irqs = OSAL_MIN_T(u16, p_params->num_queues, ((u16)cids));
1150 num_of_vf_available_chains = ecore_iov_alloc_vf_igu_sbs(p_hwfn,
1154 if (num_of_vf_available_chains == 0) {
1155 DP_ERR(p_hwfn, "no available igu sbs\n");
1159 /* Choose queue number and index ranges */
1160 vf->num_rxqs = num_of_vf_available_chains;
1161 vf->num_txqs = num_of_vf_available_chains;
1163 for (i = 0; i < vf->num_rxqs; i++) {
1164 struct ecore_vf_queue *p_queue = &vf->vf_queues[i];
1166 p_queue->fw_rx_qid = p_params->req_rx_queue[i];
1167 p_queue->fw_tx_qid = p_params->req_tx_queue[i];
1169 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1170 "VF[%d] - Q[%d] SB %04x, qid [Rx %04x Tx %04x]\n",
1171 vf->relative_vf_id, i, vf->igu_sbs[i],
1172 p_queue->fw_rx_qid, p_queue->fw_tx_qid);
1175 /* Update the link configuration in bulletin.
1177 OSAL_MEMCPY(&link_params, ecore_mcp_get_link_params(p_hwfn),
1178 sizeof(link_params));
1179 OSAL_MEMCPY(&link_state, ecore_mcp_get_link_state(p_hwfn),
1180 sizeof(link_state));
1181 OSAL_MEMCPY(&link_caps, ecore_mcp_get_link_capabilities(p_hwfn),
1183 ecore_iov_set_link(p_hwfn, p_params->rel_vf_id,
1184 &link_params, &link_state, &link_caps);
1186 rc = ecore_iov_enable_vf_access(p_hwfn, p_ptt, vf);
1188 if (rc == ECORE_SUCCESS) {
1190 p_hwfn->pf_iov_info->active_vfs[vf->relative_vf_id / 64] |=
1191 (1ULL << (vf->relative_vf_id % 64));
1193 if (IS_LEAD_HWFN(p_hwfn))
1194 p_hwfn->p_dev->p_iov_info->num_vfs++;
1200 enum _ecore_status_t ecore_iov_release_hw_for_vf(struct ecore_hwfn *p_hwfn,
1201 struct ecore_ptt *p_ptt,
1204 struct ecore_mcp_link_capabilities caps;
1205 struct ecore_mcp_link_params params;
1206 struct ecore_mcp_link_state link;
1207 struct ecore_vf_info *vf = OSAL_NULL;
1209 vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
1211 DP_ERR(p_hwfn, "ecore_iov_release_hw_for_vf : vf is NULL\n");
1212 return ECORE_UNKNOWN_ERROR;
1215 if (vf->bulletin.p_virt)
1216 OSAL_MEMSET(vf->bulletin.p_virt, 0,
1217 sizeof(*vf->bulletin.p_virt));
1219 OSAL_MEMSET(&vf->p_vf_info, 0, sizeof(vf->p_vf_info));
1221 /* Get the link configuration back in bulletin so
1222 * that when VFs are re-enabled they get the actual
1223 * link configuration.
1225 OSAL_MEMCPY(¶ms, ecore_mcp_get_link_params(p_hwfn), sizeof(params));
1226 OSAL_MEMCPY(&link, ecore_mcp_get_link_state(p_hwfn), sizeof(link));
1227 OSAL_MEMCPY(&caps, ecore_mcp_get_link_capabilities(p_hwfn),
1229 ecore_iov_set_link(p_hwfn, rel_vf_id, ¶ms, &link, &caps);
1231 /* Forget the VF's acquisition message */
1232 OSAL_MEMSET(&vf->acquire, 0, sizeof(vf->acquire));
1234 /* disablng interrupts and resetting permission table was done during
1235 * vf-close, however, we could get here without going through vf_close
1237 /* Disable Interrupts for VF */
1238 ecore_iov_vf_igu_set_int(p_hwfn, p_ptt, vf, 0);
1240 /* Reset Permission table */
1241 ecore_iov_config_perm_table(p_hwfn, p_ptt, vf, 0);
1245 ecore_iov_free_vf_igu_sbs(p_hwfn, p_ptt, vf);
1249 p_hwfn->pf_iov_info->active_vfs[vf->relative_vf_id / 64] &=
1250 ~(1ULL << (vf->relative_vf_id / 64));
1252 if (IS_LEAD_HWFN(p_hwfn))
1253 p_hwfn->p_dev->p_iov_info->num_vfs--;
1256 return ECORE_SUCCESS;
1259 static bool ecore_iov_tlv_supported(u16 tlvtype)
1261 return tlvtype > CHANNEL_TLV_NONE && tlvtype < CHANNEL_TLV_MAX;
1264 static void ecore_iov_lock_vf_pf_channel(struct ecore_hwfn *p_hwfn,
1265 struct ecore_vf_info *vf, u16 tlv)
1267 /* lock the channel */
1268 /* mutex_lock(&vf->op_mutex); @@@TBD MichalK - add lock... */
1270 /* record the locking op */
1271 /* vf->op_current = tlv; @@@TBD MichalK */
1274 if (ecore_iov_tlv_supported(tlv))
1277 "VF[%d]: vf pf channel locked by %s\n",
1279 ecore_channel_tlvs_string[tlv]);
1283 "VF[%d]: vf pf channel locked by %04x\n",
1284 vf->abs_vf_id, tlv);
1287 static void ecore_iov_unlock_vf_pf_channel(struct ecore_hwfn *p_hwfn,
1288 struct ecore_vf_info *vf,
1291 /* log the unlock */
1292 if (ecore_iov_tlv_supported(expected_tlv))
1295 "VF[%d]: vf pf channel unlocked by %s\n",
1297 ecore_channel_tlvs_string[expected_tlv]);
1301 "VF[%d]: vf pf channel unlocked by %04x\n",
1302 vf->abs_vf_id, expected_tlv);
1304 /* record the locking op */
1305 /* vf->op_current = CHANNEL_TLV_NONE; */
1308 /* place a given tlv on the tlv buffer, continuing current tlv list */
1309 void *ecore_add_tlv(u8 **offset, u16 type, u16 length)
1311 struct channel_tlv *tl = (struct channel_tlv *)*offset;
1314 tl->length = length;
1316 /* Offset should keep pointing to next TLV (the end of the last) */
1319 /* Return a pointer to the start of the added tlv */
1320 return *offset - length;
1323 /* list the types and lengths of the tlvs on the buffer */
1324 void ecore_dp_tlv_list(struct ecore_hwfn *p_hwfn, void *tlvs_list)
1326 u16 i = 1, total_length = 0;
1327 struct channel_tlv *tlv;
1330 /* cast current tlv list entry to channel tlv header */
1331 tlv = (struct channel_tlv *)((u8 *)tlvs_list + total_length);
1334 if (ecore_iov_tlv_supported(tlv->type))
1335 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1336 "TLV number %d: type %s, length %d\n",
1337 i, ecore_channel_tlvs_string[tlv->type],
1340 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1341 "TLV number %d: type %d, length %d\n",
1342 i, tlv->type, tlv->length);
1344 if (tlv->type == CHANNEL_TLV_LIST_END)
1347 /* Validate entry - protect against malicious VFs */
1349 DP_NOTICE(p_hwfn, false, "TLV of length 0 found\n");
1352 total_length += tlv->length;
1353 if (total_length >= sizeof(struct tlv_buffer_size)) {
1354 DP_NOTICE(p_hwfn, false, "TLV ==> Buffer overflow\n");
1362 static void ecore_iov_send_response(struct ecore_hwfn *p_hwfn,
1363 struct ecore_ptt *p_ptt,
1364 struct ecore_vf_info *p_vf,
1365 #ifdef CONFIG_ECORE_SW_CHANNEL
1368 u16 OSAL_UNUSED length,
1372 struct ecore_iov_vf_mbx *mbx = &p_vf->vf_mbx;
1373 struct ecore_dmae_params params;
1376 mbx->reply_virt->default_resp.hdr.status = status;
1378 ecore_dp_tlv_list(p_hwfn, mbx->reply_virt);
1380 #ifdef CONFIG_ECORE_SW_CHANNEL
1381 mbx->sw_mbx.response_size =
1382 length + sizeof(struct channel_list_end_tlv);
1384 if (!p_hwfn->p_dev->b_hw_channel)
1388 eng_vf_id = p_vf->abs_vf_id;
1390 OSAL_MEMSET(¶ms, 0, sizeof(struct ecore_dmae_params));
1391 params.flags = ECORE_DMAE_FLAG_VF_DST;
1392 params.dst_vfid = eng_vf_id;
1394 ecore_dmae_host2host(p_hwfn, p_ptt, mbx->reply_phys + sizeof(u64),
1395 mbx->req_virt->first_tlv.reply_address +
1397 (sizeof(union pfvf_tlvs) - sizeof(u64)) / 4,
1400 ecore_dmae_host2host(p_hwfn, p_ptt, mbx->reply_phys,
1401 mbx->req_virt->first_tlv.reply_address,
1402 sizeof(u64) / 4, ¶ms);
1405 GTT_BAR0_MAP_REG_USDM_RAM +
1406 USTORM_VF_PF_CHANNEL_READY_OFFSET(eng_vf_id), 1);
1408 OSAL_IOV_PF_RESP_TYPE(p_hwfn, p_vf->relative_vf_id, status);
1411 static u16 ecore_iov_vport_to_tlv(enum ecore_iov_vport_update_flag flag)
1414 case ECORE_IOV_VP_UPDATE_ACTIVATE:
1415 return CHANNEL_TLV_VPORT_UPDATE_ACTIVATE;
1416 case ECORE_IOV_VP_UPDATE_VLAN_STRIP:
1417 return CHANNEL_TLV_VPORT_UPDATE_VLAN_STRIP;
1418 case ECORE_IOV_VP_UPDATE_TX_SWITCH:
1419 return CHANNEL_TLV_VPORT_UPDATE_TX_SWITCH;
1420 case ECORE_IOV_VP_UPDATE_MCAST:
1421 return CHANNEL_TLV_VPORT_UPDATE_MCAST;
1422 case ECORE_IOV_VP_UPDATE_ACCEPT_PARAM:
1423 return CHANNEL_TLV_VPORT_UPDATE_ACCEPT_PARAM;
1424 case ECORE_IOV_VP_UPDATE_RSS:
1425 return CHANNEL_TLV_VPORT_UPDATE_RSS;
1426 case ECORE_IOV_VP_UPDATE_ACCEPT_ANY_VLAN:
1427 return CHANNEL_TLV_VPORT_UPDATE_ACCEPT_ANY_VLAN;
1428 case ECORE_IOV_VP_UPDATE_SGE_TPA:
1429 return CHANNEL_TLV_VPORT_UPDATE_SGE_TPA;
1435 static u16 ecore_iov_prep_vp_update_resp_tlvs(struct ecore_hwfn *p_hwfn,
1436 struct ecore_vf_info *p_vf,
1437 struct ecore_iov_vf_mbx *p_mbx,
1438 u8 status, u16 tlvs_mask,
1441 struct pfvf_def_resp_tlv *resp;
1442 u16 size, total_len, i;
1444 OSAL_MEMSET(p_mbx->reply_virt, 0, sizeof(union pfvf_tlvs));
1445 p_mbx->offset = (u8 *)p_mbx->reply_virt;
1446 size = sizeof(struct pfvf_def_resp_tlv);
1449 ecore_add_tlv(&p_mbx->offset, CHANNEL_TLV_VPORT_UPDATE, size);
1451 /* Prepare response for all extended tlvs if they are found by PF */
1452 for (i = 0; i < ECORE_IOV_VP_UPDATE_MAX; i++) {
1453 if (!(tlvs_mask & (1 << i)))
1456 resp = ecore_add_tlv(&p_mbx->offset, ecore_iov_vport_to_tlv(i),
1459 if (tlvs_accepted & (1 << i))
1460 resp->hdr.status = status;
1462 resp->hdr.status = PFVF_STATUS_NOT_SUPPORTED;
1464 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1465 "VF[%d] - vport_update resp: TLV %d, status %02x\n",
1466 p_vf->relative_vf_id,
1467 ecore_iov_vport_to_tlv(i),
1473 ecore_add_tlv(&p_mbx->offset, CHANNEL_TLV_LIST_END,
1474 sizeof(struct channel_list_end_tlv));
1479 static void ecore_iov_prepare_resp(struct ecore_hwfn *p_hwfn,
1480 struct ecore_ptt *p_ptt,
1481 struct ecore_vf_info *vf_info,
1482 u16 type, u16 length, u8 status)
1484 struct ecore_iov_vf_mbx *mbx = &vf_info->vf_mbx;
1486 mbx->offset = (u8 *)mbx->reply_virt;
1488 ecore_add_tlv(&mbx->offset, type, length);
1489 ecore_add_tlv(&mbx->offset, CHANNEL_TLV_LIST_END,
1490 sizeof(struct channel_list_end_tlv));
1492 ecore_iov_send_response(p_hwfn, p_ptt, vf_info, length, status);
1495 struct ecore_public_vf_info
1496 *ecore_iov_get_public_vf_info(struct ecore_hwfn *p_hwfn,
1498 bool b_enabled_only)
1500 struct ecore_vf_info *vf = OSAL_NULL;
1502 vf = ecore_iov_get_vf_info(p_hwfn, relative_vf_id, b_enabled_only);
1506 return &vf->p_vf_info;
1509 static void ecore_iov_vf_cleanup(struct ecore_hwfn *p_hwfn,
1510 struct ecore_vf_info *p_vf)
1513 p_vf->vf_bulletin = 0;
1514 p_vf->vport_instance = 0;
1515 p_vf->configured_features = 0;
1517 /* If VF previously requested less resources, go back to default */
1518 p_vf->num_rxqs = p_vf->num_sbs;
1519 p_vf->num_txqs = p_vf->num_sbs;
1521 p_vf->num_active_rxqs = 0;
1523 for (i = 0; i < ECORE_MAX_VF_CHAINS_PER_PF; i++) {
1524 struct ecore_vf_queue *p_queue = &p_vf->vf_queues[i];
1526 for (j = 0; j < MAX_QUEUES_PER_QZONE; j++) {
1527 if (!p_queue->cids[j].p_cid)
1530 ecore_eth_queue_cid_release(p_hwfn,
1531 p_queue->cids[j].p_cid);
1532 p_queue->cids[j].p_cid = OSAL_NULL;
1536 OSAL_MEMSET(&p_vf->shadow_config, 0, sizeof(p_vf->shadow_config));
1537 OSAL_MEMSET(&p_vf->acquire, 0, sizeof(p_vf->acquire));
1538 OSAL_IOV_VF_CLEANUP(p_hwfn, p_vf->relative_vf_id);
1541 /* Returns either 0, or log(size) */
1542 static u32 ecore_iov_vf_db_bar_size(struct ecore_hwfn *p_hwfn,
1543 struct ecore_ptt *p_ptt)
1545 u32 val = ecore_rd(p_hwfn, p_ptt, PGLUE_B_REG_VF_BAR1_SIZE);
1553 ecore_iov_vf_mbx_acquire_resc_cids(struct ecore_hwfn *p_hwfn,
1554 struct ecore_ptt *p_ptt,
1555 struct ecore_vf_info *p_vf,
1556 struct vf_pf_resc_request *p_req,
1557 struct pf_vf_resc *p_resp)
1559 u8 num_vf_cons = p_hwfn->pf_params.eth_pf_params.num_vf_cons;
1560 u8 db_size = DB_ADDR_VF(1, DQ_DEMS_LEGACY) -
1561 DB_ADDR_VF(0, DQ_DEMS_LEGACY);
1564 p_resp->num_cids = OSAL_MIN_T(u8, p_req->num_cids, num_vf_cons);
1566 /* If VF didn't bother asking for QIDs than don't bother limiting
1567 * number of CIDs. The VF doesn't care about the number, and this
1568 * has the likely result of causing an additional acquisition.
1570 if (!(p_vf->acquire.vfdev_info.capabilities &
1571 VFPF_ACQUIRE_CAP_QUEUE_QIDS))
1574 /* If doorbell bar was mapped by VF, limit the VF CIDs to an amount
1575 * that would make sure doorbells for all CIDs fall within the bar.
1576 * If it doesn't, make sure regview window is sufficient.
1578 if (p_vf->acquire.vfdev_info.capabilities &
1579 VFPF_ACQUIRE_CAP_PHYSICAL_BAR) {
1580 bar_size = ecore_iov_vf_db_bar_size(p_hwfn, p_ptt);
1582 bar_size = 1 << bar_size;
1584 if (ECORE_IS_CMT(p_hwfn->p_dev))
1587 bar_size = PXP_VF_BAR0_DQ_LENGTH;
1590 if (bar_size / db_size < 256)
1591 p_resp->num_cids = OSAL_MIN_T(u8, p_resp->num_cids,
1592 (u8)(bar_size / db_size));
1595 static u8 ecore_iov_vf_mbx_acquire_resc(struct ecore_hwfn *p_hwfn,
1596 struct ecore_ptt *p_ptt,
1597 struct ecore_vf_info *p_vf,
1598 struct vf_pf_resc_request *p_req,
1599 struct pf_vf_resc *p_resp)
1603 /* Queue related information */
1604 p_resp->num_rxqs = p_vf->num_rxqs;
1605 p_resp->num_txqs = p_vf->num_txqs;
1606 p_resp->num_sbs = p_vf->num_sbs;
1608 for (i = 0; i < p_resp->num_sbs; i++) {
1609 p_resp->hw_sbs[i].hw_sb_id = p_vf->igu_sbs[i];
1610 /* TODO - what's this sb_qid field? Is it deprecated?
1611 * or is there an ecore_client that looks at this?
1613 p_resp->hw_sbs[i].sb_qid = 0;
1616 /* These fields are filled for backward compatibility.
1617 * Unused by modern vfs.
1619 for (i = 0; i < p_resp->num_rxqs; i++) {
1620 ecore_fw_l2_queue(p_hwfn, p_vf->vf_queues[i].fw_rx_qid,
1621 (u16 *)&p_resp->hw_qid[i]);
1625 /* Filter related information */
1626 p_resp->num_mac_filters = OSAL_MIN_T(u8, p_vf->num_mac_filters,
1627 p_req->num_mac_filters);
1628 p_resp->num_vlan_filters = OSAL_MIN_T(u8, p_vf->num_vlan_filters,
1629 p_req->num_vlan_filters);
1631 ecore_iov_vf_mbx_acquire_resc_cids(p_hwfn, p_ptt, p_vf, p_req, p_resp);
1633 /* This isn't really needed/enforced, but some legacy VFs might depend
1634 * on the correct filling of this field.
1636 p_resp->num_mc_filters = ECORE_MAX_MC_ADDRS;
1638 /* Validate sufficient resources for VF */
1639 if (p_resp->num_rxqs < p_req->num_rxqs ||
1640 p_resp->num_txqs < p_req->num_txqs ||
1641 p_resp->num_sbs < p_req->num_sbs ||
1642 p_resp->num_mac_filters < p_req->num_mac_filters ||
1643 p_resp->num_vlan_filters < p_req->num_vlan_filters ||
1644 p_resp->num_mc_filters < p_req->num_mc_filters ||
1645 p_resp->num_cids < p_req->num_cids) {
1646 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1647 "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",
1649 p_req->num_rxqs, p_resp->num_rxqs,
1650 p_req->num_rxqs, p_resp->num_txqs,
1651 p_req->num_sbs, p_resp->num_sbs,
1652 p_req->num_mac_filters, p_resp->num_mac_filters,
1653 p_req->num_vlan_filters, p_resp->num_vlan_filters,
1654 p_req->num_mc_filters, p_resp->num_mc_filters,
1655 p_req->num_cids, p_resp->num_cids);
1657 /* Some legacy OSes are incapable of correctly handling this
1660 if ((p_vf->acquire.vfdev_info.eth_fp_hsi_minor ==
1661 ETH_HSI_VER_NO_PKT_LEN_TUNN) &&
1662 (p_vf->acquire.vfdev_info.os_type ==
1663 VFPF_ACQUIRE_OS_WINDOWS))
1664 return PFVF_STATUS_SUCCESS;
1666 return PFVF_STATUS_NO_RESOURCE;
1669 return PFVF_STATUS_SUCCESS;
1672 static void ecore_iov_vf_mbx_acquire_stats(struct pfvf_stats_info *p_stats)
1674 p_stats->mstats.address = PXP_VF_BAR0_START_MSDM_ZONE_B +
1675 OFFSETOF(struct mstorm_vf_zone,
1676 non_trigger.eth_queue_stat);
1677 p_stats->mstats.len = sizeof(struct eth_mstorm_per_queue_stat);
1678 p_stats->ustats.address = PXP_VF_BAR0_START_USDM_ZONE_B +
1679 OFFSETOF(struct ustorm_vf_zone,
1680 non_trigger.eth_queue_stat);
1681 p_stats->ustats.len = sizeof(struct eth_ustorm_per_queue_stat);
1682 p_stats->pstats.address = PXP_VF_BAR0_START_PSDM_ZONE_B +
1683 OFFSETOF(struct pstorm_vf_zone,
1684 non_trigger.eth_queue_stat);
1685 p_stats->pstats.len = sizeof(struct eth_pstorm_per_queue_stat);
1686 p_stats->tstats.address = 0;
1687 p_stats->tstats.len = 0;
1690 static void ecore_iov_vf_mbx_acquire(struct ecore_hwfn *p_hwfn,
1691 struct ecore_ptt *p_ptt,
1692 struct ecore_vf_info *vf)
1694 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
1695 struct pfvf_acquire_resp_tlv *resp = &mbx->reply_virt->acquire_resp;
1696 struct pf_vf_pfdev_info *pfdev_info = &resp->pfdev_info;
1697 struct vfpf_acquire_tlv *req = &mbx->req_virt->acquire;
1698 u8 vfpf_status = PFVF_STATUS_NOT_SUPPORTED;
1699 struct pf_vf_resc *resc = &resp->resc;
1700 enum _ecore_status_t rc;
1702 OSAL_MEMSET(resp, 0, sizeof(*resp));
1704 /* Write the PF version so that VF would know which version
1705 * is supported - might be later overridden. This guarantees that
1706 * VF could recognize legacy PF based on lack of versions in reply.
1708 pfdev_info->major_fp_hsi = ETH_HSI_VER_MAJOR;
1709 pfdev_info->minor_fp_hsi = ETH_HSI_VER_MINOR;
1711 /* TODO - not doing anything is bad since we'll assert, but this isn't
1712 * necessarily the right behavior - perhaps we should have allowed some
1715 if (vf->state != VF_FREE &&
1716 vf->state != VF_STOPPED) {
1717 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1718 "VF[%d] sent ACQUIRE but is already in state %d - fail request\n",
1719 vf->abs_vf_id, vf->state);
1723 /* Validate FW compatibility */
1724 if (req->vfdev_info.eth_fp_hsi_major != ETH_HSI_VER_MAJOR) {
1725 if (req->vfdev_info.capabilities &
1726 VFPF_ACQUIRE_CAP_PRE_FP_HSI) {
1727 struct vf_pf_vfdev_info *p_vfdev = &req->vfdev_info;
1729 /* This legacy support would need to be removed once
1730 * the major has changed.
1732 OSAL_BUILD_BUG_ON(ETH_HSI_VER_MAJOR != 3);
1734 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1735 "VF[%d] is pre-fastpath HSI\n",
1737 p_vfdev->eth_fp_hsi_major = ETH_HSI_VER_MAJOR;
1738 p_vfdev->eth_fp_hsi_minor = ETH_HSI_VER_NO_PKT_LEN_TUNN;
1741 "VF[%d] needs fastpath HSI %02x.%02x, which is"
1742 " incompatible with loaded FW's faspath"
1745 req->vfdev_info.eth_fp_hsi_major,
1746 req->vfdev_info.eth_fp_hsi_minor,
1747 ETH_HSI_VER_MAJOR, ETH_HSI_VER_MINOR);
1753 /* On 100g PFs, prevent old VFs from loading */
1754 if (ECORE_IS_CMT(p_hwfn->p_dev) &&
1755 !(req->vfdev_info.capabilities & VFPF_ACQUIRE_CAP_100G)) {
1757 "VF[%d] is running an old driver that doesn't support"
1763 #ifndef __EXTRACT__LINUX__
1764 if (OSAL_IOV_VF_ACQUIRE(p_hwfn, vf->relative_vf_id) != ECORE_SUCCESS) {
1765 vfpf_status = PFVF_STATUS_NOT_SUPPORTED;
1770 /* Store the acquire message */
1771 OSAL_MEMCPY(&vf->acquire, req, sizeof(vf->acquire));
1773 vf->opaque_fid = req->vfdev_info.opaque_fid;
1775 vf->vf_bulletin = req->bulletin_addr;
1776 vf->bulletin.size = (vf->bulletin.size < req->bulletin_size) ?
1777 vf->bulletin.size : req->bulletin_size;
1779 /* fill in pfdev info */
1780 pfdev_info->chip_num = p_hwfn->p_dev->chip_num;
1781 pfdev_info->db_size = 0; /* @@@ TBD MichalK Vf Doorbells */
1782 pfdev_info->indices_per_sb = PIS_PER_SB_E4;
1784 pfdev_info->capabilities = PFVF_ACQUIRE_CAP_DEFAULT_UNTAGGED |
1785 PFVF_ACQUIRE_CAP_POST_FW_OVERRIDE;
1786 if (ECORE_IS_CMT(p_hwfn->p_dev))
1787 pfdev_info->capabilities |= PFVF_ACQUIRE_CAP_100G;
1789 /* Share our ability to use multiple queue-ids only with VFs
1792 if (req->vfdev_info.capabilities & VFPF_ACQUIRE_CAP_QUEUE_QIDS)
1793 pfdev_info->capabilities |= PFVF_ACQUIRE_CAP_QUEUE_QIDS;
1795 /* Share the sizes of the bars with VF */
1796 resp->pfdev_info.bar_size = (u8)ecore_iov_vf_db_bar_size(p_hwfn,
1799 ecore_iov_vf_mbx_acquire_stats(&pfdev_info->stats_info);
1801 OSAL_MEMCPY(pfdev_info->port_mac, p_hwfn->hw_info.hw_mac_addr,
1804 pfdev_info->fw_major = FW_MAJOR_VERSION;
1805 pfdev_info->fw_minor = FW_MINOR_VERSION;
1806 pfdev_info->fw_rev = FW_REVISION_VERSION;
1807 pfdev_info->fw_eng = FW_ENGINEERING_VERSION;
1809 /* Incorrect when legacy, but doesn't matter as legacy isn't reading
1812 pfdev_info->minor_fp_hsi = OSAL_MIN_T(u8, ETH_HSI_VER_MINOR,
1813 req->vfdev_info.eth_fp_hsi_minor);
1814 pfdev_info->os_type = OSAL_IOV_GET_OS_TYPE();
1815 ecore_mcp_get_mfw_ver(p_hwfn, p_ptt, &pfdev_info->mfw_ver,
1818 pfdev_info->dev_type = p_hwfn->p_dev->type;
1819 pfdev_info->chip_rev = p_hwfn->p_dev->chip_rev;
1821 /* Fill resources available to VF; Make sure there are enough to
1822 * satisfy the VF's request.
1824 vfpf_status = ecore_iov_vf_mbx_acquire_resc(p_hwfn, p_ptt, vf,
1825 &req->resc_request, resc);
1826 if (vfpf_status != PFVF_STATUS_SUCCESS)
1829 /* Start the VF in FW */
1830 rc = ecore_sp_vf_start(p_hwfn, vf);
1831 if (rc != ECORE_SUCCESS) {
1832 DP_NOTICE(p_hwfn, true, "Failed to start VF[%02x]\n",
1834 vfpf_status = PFVF_STATUS_FAILURE;
1838 /* Fill agreed size of bulletin board in response, and post
1839 * an initial image to the bulletin board.
1841 resp->bulletin_size = vf->bulletin.size;
1842 ecore_iov_post_vf_bulletin(p_hwfn, vf->relative_vf_id, p_ptt);
1844 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1845 "VF[%d] ACQUIRE_RESPONSE: pfdev_info- chip_num=0x%x,"
1846 " db_size=%d, idx_per_sb=%d, pf_cap=0x%lx\n"
1847 "resources- n_rxq-%d, n_txq-%d, n_sbs-%d, n_macs-%d,"
1849 vf->abs_vf_id, resp->pfdev_info.chip_num,
1850 resp->pfdev_info.db_size, resp->pfdev_info.indices_per_sb,
1851 (unsigned long)resp->pfdev_info.capabilities, resc->num_rxqs,
1852 resc->num_txqs, resc->num_sbs, resc->num_mac_filters,
1853 resc->num_vlan_filters);
1855 vf->state = VF_ACQUIRED;
1858 /* Prepare Response */
1859 ecore_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_ACQUIRE,
1860 sizeof(struct pfvf_acquire_resp_tlv),
1864 static enum _ecore_status_t
1865 __ecore_iov_spoofchk_set(struct ecore_hwfn *p_hwfn,
1866 struct ecore_vf_info *p_vf, bool val)
1868 struct ecore_sp_vport_update_params params;
1869 enum _ecore_status_t rc;
1871 if (val == p_vf->spoof_chk) {
1872 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1873 "Spoofchk value[%d] is already configured\n", val);
1874 return ECORE_SUCCESS;
1877 OSAL_MEMSET(¶ms, 0, sizeof(struct ecore_sp_vport_update_params));
1878 params.opaque_fid = p_vf->opaque_fid;
1879 params.vport_id = p_vf->vport_id;
1880 params.update_anti_spoofing_en_flg = 1;
1881 params.anti_spoofing_en = val;
1883 rc = ecore_sp_vport_update(p_hwfn, ¶ms, ECORE_SPQ_MODE_EBLOCK,
1885 if (rc == ECORE_SUCCESS) {
1886 p_vf->spoof_chk = val;
1887 p_vf->req_spoofchk_val = p_vf->spoof_chk;
1888 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1889 "Spoofchk val[%d] configured\n", val);
1891 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1892 "Spoofchk configuration[val:%d] failed for VF[%d]\n",
1893 val, p_vf->relative_vf_id);
1899 static enum _ecore_status_t
1900 ecore_iov_reconfigure_unicast_vlan(struct ecore_hwfn *p_hwfn,
1901 struct ecore_vf_info *p_vf)
1903 struct ecore_filter_ucast filter;
1904 enum _ecore_status_t rc = ECORE_SUCCESS;
1907 OSAL_MEMSET(&filter, 0, sizeof(filter));
1908 filter.is_rx_filter = 1;
1909 filter.is_tx_filter = 1;
1910 filter.vport_to_add_to = p_vf->vport_id;
1911 filter.opcode = ECORE_FILTER_ADD;
1913 /* Reconfigure vlans */
1914 for (i = 0; i < ECORE_ETH_VF_NUM_VLAN_FILTERS + 1; i++) {
1915 if (!p_vf->shadow_config.vlans[i].used)
1918 filter.type = ECORE_FILTER_VLAN;
1919 filter.vlan = p_vf->shadow_config.vlans[i].vid;
1920 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1921 "Reconfiguring VLAN [0x%04x] for VF [%04x]\n",
1922 filter.vlan, p_vf->relative_vf_id);
1923 rc = ecore_sp_eth_filter_ucast(p_hwfn, p_vf->opaque_fid,
1924 &filter, ECORE_SPQ_MODE_CB,
1927 DP_NOTICE(p_hwfn, true,
1928 "Failed to configure VLAN [%04x]"
1930 filter.vlan, p_vf->relative_vf_id);
1938 static enum _ecore_status_t
1939 ecore_iov_reconfigure_unicast_shadow(struct ecore_hwfn *p_hwfn,
1940 struct ecore_vf_info *p_vf, u64 events)
1942 enum _ecore_status_t rc = ECORE_SUCCESS;
1944 /*TODO - what about MACs? */
1946 if ((events & (1 << VLAN_ADDR_FORCED)) &&
1947 !(p_vf->configured_features & (1 << VLAN_ADDR_FORCED)))
1948 rc = ecore_iov_reconfigure_unicast_vlan(p_hwfn, p_vf);
1953 static enum _ecore_status_t
1954 ecore_iov_configure_vport_forced(struct ecore_hwfn *p_hwfn,
1955 struct ecore_vf_info *p_vf,
1958 enum _ecore_status_t rc = ECORE_SUCCESS;
1959 struct ecore_filter_ucast filter;
1961 if (!p_vf->vport_instance)
1964 if (events & (1 << MAC_ADDR_FORCED)) {
1965 /* Since there's no way [currently] of removing the MAC,
1966 * we can always assume this means we need to force it.
1968 OSAL_MEMSET(&filter, 0, sizeof(filter));
1969 filter.type = ECORE_FILTER_MAC;
1970 filter.opcode = ECORE_FILTER_REPLACE;
1971 filter.is_rx_filter = 1;
1972 filter.is_tx_filter = 1;
1973 filter.vport_to_add_to = p_vf->vport_id;
1974 OSAL_MEMCPY(filter.mac, p_vf->bulletin.p_virt->mac, ETH_ALEN);
1976 rc = ecore_sp_eth_filter_ucast(p_hwfn, p_vf->opaque_fid,
1978 ECORE_SPQ_MODE_CB, OSAL_NULL);
1980 DP_NOTICE(p_hwfn, true,
1981 "PF failed to configure MAC for VF\n");
1985 p_vf->configured_features |= 1 << MAC_ADDR_FORCED;
1988 if (events & (1 << VLAN_ADDR_FORCED)) {
1989 struct ecore_sp_vport_update_params vport_update;
1993 OSAL_MEMSET(&filter, 0, sizeof(filter));
1994 filter.type = ECORE_FILTER_VLAN;
1995 filter.is_rx_filter = 1;
1996 filter.is_tx_filter = 1;
1997 filter.vport_to_add_to = p_vf->vport_id;
1998 filter.vlan = p_vf->bulletin.p_virt->pvid;
1999 filter.opcode = filter.vlan ? ECORE_FILTER_REPLACE :
2002 /* Send the ramrod */
2003 rc = ecore_sp_eth_filter_ucast(p_hwfn, p_vf->opaque_fid,
2005 ECORE_SPQ_MODE_CB, OSAL_NULL);
2007 DP_NOTICE(p_hwfn, true,
2008 "PF failed to configure VLAN for VF\n");
2012 /* Update the default-vlan & silent vlan stripping */
2013 OSAL_MEMSET(&vport_update, 0, sizeof(vport_update));
2014 vport_update.opaque_fid = p_vf->opaque_fid;
2015 vport_update.vport_id = p_vf->vport_id;
2016 vport_update.update_default_vlan_enable_flg = 1;
2017 vport_update.default_vlan_enable_flg = filter.vlan ? 1 : 0;
2018 vport_update.update_default_vlan_flg = 1;
2019 vport_update.default_vlan = filter.vlan;
2021 vport_update.update_inner_vlan_removal_flg = 1;
2022 removal = filter.vlan ?
2023 1 : p_vf->shadow_config.inner_vlan_removal;
2024 vport_update.inner_vlan_removal_flg = removal;
2025 vport_update.silent_vlan_removal_flg = filter.vlan ? 1 : 0;
2026 rc = ecore_sp_vport_update(p_hwfn, &vport_update,
2027 ECORE_SPQ_MODE_EBLOCK, OSAL_NULL);
2029 DP_NOTICE(p_hwfn, true,
2030 "PF failed to configure VF vport for vlan\n");
2034 /* Update all the Rx queues */
2035 for (i = 0; i < ECORE_MAX_VF_CHAINS_PER_PF; i++) {
2036 struct ecore_vf_queue *p_queue = &p_vf->vf_queues[i];
2037 struct ecore_queue_cid *p_cid = OSAL_NULL;
2039 /* There can be at most 1 Rx queue on qzone. Find it */
2040 p_cid = ecore_iov_get_vf_rx_queue_cid(p_queue);
2041 if (p_cid == OSAL_NULL)
2044 rc = ecore_sp_eth_rx_queues_update(p_hwfn,
2047 ECORE_SPQ_MODE_EBLOCK,
2050 DP_NOTICE(p_hwfn, true,
2051 "Failed to send Rx update"
2052 " fo queue[0x%04x]\n",
2053 p_cid->rel.queue_id);
2059 p_vf->configured_features |= 1 << VLAN_ADDR_FORCED;
2061 p_vf->configured_features &= ~(1 << VLAN_ADDR_FORCED);
2064 /* If forced features are terminated, we need to configure the shadow
2065 * configuration back again.
2068 ecore_iov_reconfigure_unicast_shadow(p_hwfn, p_vf, events);
2073 static void ecore_iov_vf_mbx_start_vport(struct ecore_hwfn *p_hwfn,
2074 struct ecore_ptt *p_ptt,
2075 struct ecore_vf_info *vf)
2077 struct ecore_sp_vport_start_params params = { 0 };
2078 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
2079 struct vfpf_vport_start_tlv *start;
2080 u8 status = PFVF_STATUS_SUCCESS;
2081 struct ecore_vf_info *vf_info;
2084 enum _ecore_status_t rc;
2086 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vf->relative_vf_id, true);
2088 DP_NOTICE(p_hwfn->p_dev, true,
2089 "Failed to get VF info, invalid vfid [%d]\n",
2090 vf->relative_vf_id);
2094 vf->state = VF_ENABLED;
2095 start = &mbx->req_virt->start_vport;
2097 ecore_iov_enable_vf_traffic(p_hwfn, p_ptt, vf);
2099 /* Initialize Status block in CAU */
2100 for (sb_id = 0; sb_id < vf->num_sbs; sb_id++) {
2101 if (!start->sb_addr[sb_id]) {
2102 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2103 "VF[%d] did not fill the address of SB %d\n",
2104 vf->relative_vf_id, sb_id);
2108 ecore_int_cau_conf_sb(p_hwfn, p_ptt,
2109 start->sb_addr[sb_id],
2114 vf->mtu = start->mtu;
2115 vf->shadow_config.inner_vlan_removal = start->inner_vlan_removal;
2117 /* Take into consideration configuration forced by hypervisor;
2118 * If none is configured, use the supplied VF values [for old
2119 * vfs that would still be fine, since they passed '0' as padding].
2121 p_bitmap = &vf_info->bulletin.p_virt->valid_bitmap;
2122 if (!(*p_bitmap & (1 << VFPF_BULLETIN_UNTAGGED_DEFAULT_FORCED))) {
2123 u8 vf_req = start->only_untagged;
2125 vf_info->bulletin.p_virt->default_only_untagged = vf_req;
2126 *p_bitmap |= 1 << VFPF_BULLETIN_UNTAGGED_DEFAULT;
2129 params.tpa_mode = start->tpa_mode;
2130 params.remove_inner_vlan = start->inner_vlan_removal;
2131 params.tx_switching = true;
2134 if (CHIP_REV_IS_FPGA(p_hwfn->p_dev)) {
2135 DP_NOTICE(p_hwfn, false,
2136 "FPGA: Don't config VF for Tx-switching [no pVFC]\n");
2137 params.tx_switching = false;
2141 params.only_untagged = vf_info->bulletin.p_virt->default_only_untagged;
2142 params.drop_ttl0 = false;
2143 params.concrete_fid = vf->concrete_fid;
2144 params.opaque_fid = vf->opaque_fid;
2145 params.vport_id = vf->vport_id;
2146 params.max_buffers_per_cqe = start->max_buffers_per_cqe;
2147 params.mtu = vf->mtu;
2148 params.check_mac = true;
2150 rc = ecore_sp_eth_vport_start(p_hwfn, ¶ms);
2151 if (rc != ECORE_SUCCESS) {
2153 "ecore_iov_vf_mbx_start_vport returned error %d\n", rc);
2154 status = PFVF_STATUS_FAILURE;
2156 vf->vport_instance++;
2158 /* Force configuration if needed on the newly opened vport */
2159 ecore_iov_configure_vport_forced(p_hwfn, vf, *p_bitmap);
2160 OSAL_IOV_POST_START_VPORT(p_hwfn, vf->relative_vf_id,
2161 vf->vport_id, vf->opaque_fid);
2162 __ecore_iov_spoofchk_set(p_hwfn, vf, vf->req_spoofchk_val);
2165 ecore_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_VPORT_START,
2166 sizeof(struct pfvf_def_resp_tlv), status);
2169 static void ecore_iov_vf_mbx_stop_vport(struct ecore_hwfn *p_hwfn,
2170 struct ecore_ptt *p_ptt,
2171 struct ecore_vf_info *vf)
2173 u8 status = PFVF_STATUS_SUCCESS;
2174 enum _ecore_status_t rc;
2176 vf->vport_instance--;
2177 vf->spoof_chk = false;
2179 if ((ecore_iov_validate_active_rxq(vf)) ||
2180 (ecore_iov_validate_active_txq(vf))) {
2181 vf->b_malicious = true;
2182 DP_NOTICE(p_hwfn, false,
2183 "VF [%02x] - considered malicious;"
2184 " Unable to stop RX/TX queuess\n",
2186 status = PFVF_STATUS_MALICIOUS;
2190 rc = ecore_sp_vport_stop(p_hwfn, vf->opaque_fid, vf->vport_id);
2191 if (rc != ECORE_SUCCESS) {
2193 "ecore_iov_vf_mbx_stop_vport returned error %d\n", rc);
2194 status = PFVF_STATUS_FAILURE;
2197 /* Forget the configuration on the vport */
2198 vf->configured_features = 0;
2199 OSAL_MEMSET(&vf->shadow_config, 0, sizeof(vf->shadow_config));
2202 ecore_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_VPORT_TEARDOWN,
2203 sizeof(struct pfvf_def_resp_tlv), status);
2206 static void ecore_iov_vf_mbx_start_rxq_resp(struct ecore_hwfn *p_hwfn,
2207 struct ecore_ptt *p_ptt,
2208 struct ecore_vf_info *vf,
2209 u8 status, bool b_legacy)
2211 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
2212 struct pfvf_start_queue_resp_tlv *p_tlv;
2213 struct vfpf_start_rxq_tlv *req;
2216 mbx->offset = (u8 *)mbx->reply_virt;
2218 /* Taking a bigger struct instead of adding a TLV to list was a
2219 * mistake, but one which we're now stuck with, as some older
2220 * clients assume the size of the previous response.
2223 length = sizeof(*p_tlv);
2225 length = sizeof(struct pfvf_def_resp_tlv);
2227 p_tlv = ecore_add_tlv(&mbx->offset, CHANNEL_TLV_START_RXQ, length);
2228 ecore_add_tlv(&mbx->offset, CHANNEL_TLV_LIST_END,
2229 sizeof(struct channel_list_end_tlv));
2231 /* Update the TLV with the response */
2232 if ((status == PFVF_STATUS_SUCCESS) && !b_legacy) {
2233 req = &mbx->req_virt->start_rxq;
2234 p_tlv->offset = PXP_VF_BAR0_START_MSDM_ZONE_B +
2235 OFFSETOF(struct mstorm_vf_zone,
2236 non_trigger.eth_rx_queue_producers) +
2237 sizeof(struct eth_rx_prod_data) * req->rx_qid;
2240 ecore_iov_send_response(p_hwfn, p_ptt, vf, length, status);
2243 static u8 ecore_iov_vf_mbx_qid(struct ecore_hwfn *p_hwfn,
2244 struct ecore_vf_info *p_vf, bool b_is_tx)
2246 struct ecore_iov_vf_mbx *p_mbx = &p_vf->vf_mbx;
2247 struct vfpf_qid_tlv *p_qid_tlv;
2249 /* Search for the qid if the VF published if its going to provide it */
2250 if (!(p_vf->acquire.vfdev_info.capabilities &
2251 VFPF_ACQUIRE_CAP_QUEUE_QIDS)) {
2253 return ECORE_IOV_LEGACY_QID_TX;
2255 return ECORE_IOV_LEGACY_QID_RX;
2258 p_qid_tlv = (struct vfpf_qid_tlv *)
2259 ecore_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt,
2261 if (p_qid_tlv == OSAL_NULL) {
2262 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2263 "VF[%2x]: Failed to provide qid\n",
2264 p_vf->relative_vf_id);
2266 return ECORE_IOV_QID_INVALID;
2269 if (p_qid_tlv->qid >= MAX_QUEUES_PER_QZONE) {
2270 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2271 "VF[%02x]: Provided qid out-of-bounds %02x\n",
2272 p_vf->relative_vf_id, p_qid_tlv->qid);
2273 return ECORE_IOV_QID_INVALID;
2276 return p_qid_tlv->qid;
2279 static void ecore_iov_vf_mbx_start_rxq(struct ecore_hwfn *p_hwfn,
2280 struct ecore_ptt *p_ptt,
2281 struct ecore_vf_info *vf)
2283 struct ecore_queue_start_common_params params;
2284 struct ecore_queue_cid_vf_params vf_params;
2285 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
2286 u8 status = PFVF_STATUS_NO_RESOURCE;
2287 u8 qid_usage_idx, vf_legacy = 0;
2288 struct ecore_vf_queue *p_queue;
2289 struct vfpf_start_rxq_tlv *req;
2290 struct ecore_queue_cid *p_cid;
2291 struct ecore_sb_info sb_dummy;
2292 enum _ecore_status_t rc;
2294 req = &mbx->req_virt->start_rxq;
2296 if (!ecore_iov_validate_rxq(p_hwfn, vf, req->rx_qid,
2297 ECORE_IOV_VALIDATE_Q_DISABLE) ||
2298 !ecore_iov_validate_sb(p_hwfn, vf, req->hw_sb))
2301 qid_usage_idx = ecore_iov_vf_mbx_qid(p_hwfn, vf, false);
2302 if (qid_usage_idx == ECORE_IOV_QID_INVALID)
2305 p_queue = &vf->vf_queues[req->rx_qid];
2306 if (p_queue->cids[qid_usage_idx].p_cid)
2309 vf_legacy = ecore_vf_calculate_legacy(vf);
2311 /* Acquire a new queue-cid */
2312 OSAL_MEMSET(¶ms, 0, sizeof(params));
2313 params.queue_id = (u8)p_queue->fw_rx_qid;
2314 params.vport_id = vf->vport_id;
2315 params.stats_id = vf->abs_vf_id + 0x10;
2317 /* Since IGU index is passed via sb_info, construct a dummy one */
2318 OSAL_MEM_ZERO(&sb_dummy, sizeof(sb_dummy));
2319 sb_dummy.igu_sb_id = req->hw_sb;
2320 params.p_sb = &sb_dummy;
2321 params.sb_idx = req->sb_index;
2323 OSAL_MEM_ZERO(&vf_params, sizeof(vf_params));
2324 vf_params.vfid = vf->relative_vf_id;
2325 vf_params.vf_qid = (u8)req->rx_qid;
2326 vf_params.vf_legacy = vf_legacy;
2327 vf_params.qid_usage_idx = qid_usage_idx;
2329 p_cid = ecore_eth_queue_to_cid(p_hwfn, vf->opaque_fid,
2330 ¶ms, true, &vf_params);
2331 if (p_cid == OSAL_NULL)
2334 /* Legacy VFs have their Producers in a different location, which they
2335 * calculate on their own and clean the producer prior to this.
2337 if (!(vf_legacy & ECORE_QCID_LEGACY_VF_RX_PROD))
2339 GTT_BAR0_MAP_REG_MSDM_RAM +
2340 MSTORM_ETH_VF_PRODS_OFFSET(vf->abs_vf_id, req->rx_qid),
2343 rc = ecore_eth_rxq_start_ramrod(p_hwfn, p_cid,
2348 if (rc != ECORE_SUCCESS) {
2349 status = PFVF_STATUS_FAILURE;
2350 ecore_eth_queue_cid_release(p_hwfn, p_cid);
2352 p_queue->cids[qid_usage_idx].p_cid = p_cid;
2353 p_queue->cids[qid_usage_idx].b_is_tx = false;
2354 status = PFVF_STATUS_SUCCESS;
2355 vf->num_active_rxqs++;
2359 ecore_iov_vf_mbx_start_rxq_resp(p_hwfn, p_ptt, vf, status,
2361 ECORE_QCID_LEGACY_VF_RX_PROD));
2365 ecore_iov_pf_update_tun_response(struct pfvf_update_tunn_param_tlv *p_resp,
2366 struct ecore_tunnel_info *p_tun,
2367 u16 tunn_feature_mask)
2369 p_resp->tunn_feature_mask = tunn_feature_mask;
2370 p_resp->vxlan_mode = p_tun->vxlan.b_mode_enabled;
2371 p_resp->l2geneve_mode = p_tun->l2_geneve.b_mode_enabled;
2372 p_resp->ipgeneve_mode = p_tun->ip_geneve.b_mode_enabled;
2373 p_resp->l2gre_mode = p_tun->l2_gre.b_mode_enabled;
2374 p_resp->ipgre_mode = p_tun->l2_gre.b_mode_enabled;
2375 p_resp->vxlan_clss = p_tun->vxlan.tun_cls;
2376 p_resp->l2gre_clss = p_tun->l2_gre.tun_cls;
2377 p_resp->ipgre_clss = p_tun->ip_gre.tun_cls;
2378 p_resp->l2geneve_clss = p_tun->l2_geneve.tun_cls;
2379 p_resp->ipgeneve_clss = p_tun->ip_geneve.tun_cls;
2380 p_resp->geneve_udp_port = p_tun->geneve_port.port;
2381 p_resp->vxlan_udp_port = p_tun->vxlan_port.port;
2385 __ecore_iov_pf_update_tun_param(struct vfpf_update_tunn_param_tlv *p_req,
2386 struct ecore_tunn_update_type *p_tun,
2387 enum ecore_tunn_mode mask, u8 tun_cls)
2389 if (p_req->tun_mode_update_mask & (1 << mask)) {
2390 p_tun->b_update_mode = true;
2392 if (p_req->tunn_mode & (1 << mask))
2393 p_tun->b_mode_enabled = true;
2396 p_tun->tun_cls = tun_cls;
2400 ecore_iov_pf_update_tun_param(struct vfpf_update_tunn_param_tlv *p_req,
2401 struct ecore_tunn_update_type *p_tun,
2402 struct ecore_tunn_update_udp_port *p_port,
2403 enum ecore_tunn_mode mask,
2404 u8 tun_cls, u8 update_port, u16 port)
2407 p_port->b_update_port = true;
2408 p_port->port = port;
2411 __ecore_iov_pf_update_tun_param(p_req, p_tun, mask, tun_cls);
2415 ecore_iov_pf_validate_tunn_param(struct vfpf_update_tunn_param_tlv *p_req)
2417 bool b_update_requested = false;
2419 if (p_req->tun_mode_update_mask || p_req->update_tun_cls ||
2420 p_req->update_geneve_port || p_req->update_vxlan_port)
2421 b_update_requested = true;
2423 return b_update_requested;
2426 static void ecore_iov_vf_mbx_update_tunn_param(struct ecore_hwfn *p_hwfn,
2427 struct ecore_ptt *p_ptt,
2428 struct ecore_vf_info *p_vf)
2430 struct ecore_tunnel_info *p_tun = &p_hwfn->p_dev->tunnel;
2431 struct ecore_iov_vf_mbx *mbx = &p_vf->vf_mbx;
2432 struct pfvf_update_tunn_param_tlv *p_resp;
2433 struct vfpf_update_tunn_param_tlv *p_req;
2434 enum _ecore_status_t rc = ECORE_SUCCESS;
2435 u8 status = PFVF_STATUS_SUCCESS;
2436 bool b_update_required = false;
2437 struct ecore_tunnel_info tunn;
2438 u16 tunn_feature_mask = 0;
2441 mbx->offset = (u8 *)mbx->reply_virt;
2443 OSAL_MEM_ZERO(&tunn, sizeof(tunn));
2444 p_req = &mbx->req_virt->tunn_param_update;
2446 if (!ecore_iov_pf_validate_tunn_param(p_req)) {
2447 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2448 "No tunnel update requested by VF\n");
2449 status = PFVF_STATUS_FAILURE;
2453 tunn.b_update_rx_cls = p_req->update_tun_cls;
2454 tunn.b_update_tx_cls = p_req->update_tun_cls;
2456 ecore_iov_pf_update_tun_param(p_req, &tunn.vxlan, &tunn.vxlan_port,
2457 ECORE_MODE_VXLAN_TUNN, p_req->vxlan_clss,
2458 p_req->update_vxlan_port,
2460 ecore_iov_pf_update_tun_param(p_req, &tunn.l2_geneve, &tunn.geneve_port,
2461 ECORE_MODE_L2GENEVE_TUNN,
2462 p_req->l2geneve_clss,
2463 p_req->update_geneve_port,
2464 p_req->geneve_port);
2465 __ecore_iov_pf_update_tun_param(p_req, &tunn.ip_geneve,
2466 ECORE_MODE_IPGENEVE_TUNN,
2467 p_req->ipgeneve_clss);
2468 __ecore_iov_pf_update_tun_param(p_req, &tunn.l2_gre,
2469 ECORE_MODE_L2GRE_TUNN,
2471 __ecore_iov_pf_update_tun_param(p_req, &tunn.ip_gre,
2472 ECORE_MODE_IPGRE_TUNN,
2475 /* If PF modifies VF's req then it should
2476 * still return an error in case of partial configuration
2477 * or modified configuration as opposed to requested one.
2479 rc = OSAL_PF_VALIDATE_MODIFY_TUNN_CONFIG(p_hwfn, &tunn_feature_mask,
2480 &b_update_required, &tunn);
2482 if (rc != ECORE_SUCCESS)
2483 status = PFVF_STATUS_FAILURE;
2485 /* If ECORE client is willing to update anything ? */
2486 if (b_update_required) {
2489 rc = ecore_sp_pf_update_tunn_cfg(p_hwfn, p_ptt, &tunn,
2490 ECORE_SPQ_MODE_EBLOCK,
2492 if (rc != ECORE_SUCCESS)
2493 status = PFVF_STATUS_FAILURE;
2495 geneve_port = p_tun->geneve_port.port;
2496 ecore_for_each_vf(p_hwfn, i) {
2497 ecore_iov_bulletin_set_udp_ports(p_hwfn, i,
2498 p_tun->vxlan_port.port,
2504 p_resp = ecore_add_tlv(&mbx->offset,
2505 CHANNEL_TLV_UPDATE_TUNN_PARAM, sizeof(*p_resp));
2507 ecore_iov_pf_update_tun_response(p_resp, p_tun, tunn_feature_mask);
2508 ecore_add_tlv(&mbx->offset, CHANNEL_TLV_LIST_END,
2509 sizeof(struct channel_list_end_tlv));
2511 ecore_iov_send_response(p_hwfn, p_ptt, p_vf, sizeof(*p_resp), status);
2514 static void ecore_iov_vf_mbx_start_txq_resp(struct ecore_hwfn *p_hwfn,
2515 struct ecore_ptt *p_ptt,
2516 struct ecore_vf_info *p_vf,
2520 struct ecore_iov_vf_mbx *mbx = &p_vf->vf_mbx;
2521 struct pfvf_start_queue_resp_tlv *p_tlv;
2522 bool b_legacy = false;
2525 mbx->offset = (u8 *)mbx->reply_virt;
2527 /* Taking a bigger struct instead of adding a TLV to list was a
2528 * mistake, but one which we're now stuck with, as some older
2529 * clients assume the size of the previous response.
2531 if (p_vf->acquire.vfdev_info.eth_fp_hsi_minor ==
2532 ETH_HSI_VER_NO_PKT_LEN_TUNN)
2536 length = sizeof(*p_tlv);
2538 length = sizeof(struct pfvf_def_resp_tlv);
2540 p_tlv = ecore_add_tlv(&mbx->offset, CHANNEL_TLV_START_TXQ, length);
2541 ecore_add_tlv(&mbx->offset, CHANNEL_TLV_LIST_END,
2542 sizeof(struct channel_list_end_tlv));
2544 /* Update the TLV with the response */
2545 if ((status == PFVF_STATUS_SUCCESS) && !b_legacy)
2546 p_tlv->offset = DB_ADDR_VF(cid, DQ_DEMS_LEGACY);
2548 ecore_iov_send_response(p_hwfn, p_ptt, p_vf, length, status);
2551 static void ecore_iov_vf_mbx_start_txq(struct ecore_hwfn *p_hwfn,
2552 struct ecore_ptt *p_ptt,
2553 struct ecore_vf_info *vf)
2555 struct ecore_queue_start_common_params params;
2556 struct ecore_queue_cid_vf_params vf_params;
2557 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
2558 u8 status = PFVF_STATUS_NO_RESOURCE;
2559 struct ecore_vf_queue *p_queue;
2560 struct vfpf_start_txq_tlv *req;
2561 struct ecore_queue_cid *p_cid;
2562 struct ecore_sb_info sb_dummy;
2563 u8 qid_usage_idx, vf_legacy;
2565 enum _ecore_status_t rc;
2568 OSAL_MEMSET(¶ms, 0, sizeof(params));
2569 req = &mbx->req_virt->start_txq;
2571 if (!ecore_iov_validate_txq(p_hwfn, vf, req->tx_qid,
2572 ECORE_IOV_VALIDATE_Q_NA) ||
2573 !ecore_iov_validate_sb(p_hwfn, vf, req->hw_sb))
2576 qid_usage_idx = ecore_iov_vf_mbx_qid(p_hwfn, vf, true);
2577 if (qid_usage_idx == ECORE_IOV_QID_INVALID)
2580 p_queue = &vf->vf_queues[req->tx_qid];
2581 if (p_queue->cids[qid_usage_idx].p_cid)
2584 vf_legacy = ecore_vf_calculate_legacy(vf);
2586 /* Acquire a new queue-cid */
2587 params.queue_id = p_queue->fw_tx_qid;
2588 params.vport_id = vf->vport_id;
2589 params.stats_id = vf->abs_vf_id + 0x10;
2591 /* Since IGU index is passed via sb_info, construct a dummy one */
2592 OSAL_MEM_ZERO(&sb_dummy, sizeof(sb_dummy));
2593 sb_dummy.igu_sb_id = req->hw_sb;
2594 params.p_sb = &sb_dummy;
2595 params.sb_idx = req->sb_index;
2597 OSAL_MEM_ZERO(&vf_params, sizeof(vf_params));
2598 vf_params.vfid = vf->relative_vf_id;
2599 vf_params.vf_qid = (u8)req->tx_qid;
2600 vf_params.vf_legacy = vf_legacy;
2601 vf_params.qid_usage_idx = qid_usage_idx;
2603 p_cid = ecore_eth_queue_to_cid(p_hwfn, vf->opaque_fid,
2604 ¶ms, false, &vf_params);
2605 if (p_cid == OSAL_NULL)
2608 pq = ecore_get_cm_pq_idx_vf(p_hwfn,
2609 vf->relative_vf_id);
2610 rc = ecore_eth_txq_start_ramrod(p_hwfn, p_cid,
2611 req->pbl_addr, req->pbl_size, pq);
2612 if (rc != ECORE_SUCCESS) {
2613 status = PFVF_STATUS_FAILURE;
2614 ecore_eth_queue_cid_release(p_hwfn, p_cid);
2616 status = PFVF_STATUS_SUCCESS;
2617 p_queue->cids[qid_usage_idx].p_cid = p_cid;
2618 p_queue->cids[qid_usage_idx].b_is_tx = true;
2623 ecore_iov_vf_mbx_start_txq_resp(p_hwfn, p_ptt, vf,
2627 static enum _ecore_status_t ecore_iov_vf_stop_rxqs(struct ecore_hwfn *p_hwfn,
2628 struct ecore_vf_info *vf,
2631 bool cqe_completion)
2633 struct ecore_vf_queue *p_queue;
2634 enum _ecore_status_t rc = ECORE_SUCCESS;
2636 if (!ecore_iov_validate_rxq(p_hwfn, vf, rxq_id,
2637 ECORE_IOV_VALIDATE_Q_NA)) {
2638 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2639 "VF[%d] Tried Closing Rx 0x%04x.%02x which is inactive\n",
2640 vf->relative_vf_id, rxq_id, qid_usage_idx);
2644 p_queue = &vf->vf_queues[rxq_id];
2646 /* We've validated the index and the existence of the active RXQ -
2647 * now we need to make sure that it's using the correct qid.
2649 if (!p_queue->cids[qid_usage_idx].p_cid ||
2650 p_queue->cids[qid_usage_idx].b_is_tx) {
2651 struct ecore_queue_cid *p_cid;
2653 p_cid = ecore_iov_get_vf_rx_queue_cid(p_queue);
2654 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2655 "VF[%d] - Tried Closing Rx 0x%04x.%02x, but Rx is at %04x.%02x\n",
2656 vf->relative_vf_id, rxq_id, qid_usage_idx,
2657 rxq_id, p_cid->qid_usage_idx);
2661 /* Now that we know we have a valid Rx-queue - close it */
2662 rc = ecore_eth_rx_queue_stop(p_hwfn,
2663 p_queue->cids[qid_usage_idx].p_cid,
2664 false, cqe_completion);
2665 if (rc != ECORE_SUCCESS)
2668 p_queue->cids[qid_usage_idx].p_cid = OSAL_NULL;
2669 vf->num_active_rxqs--;
2671 return ECORE_SUCCESS;
2674 static enum _ecore_status_t ecore_iov_vf_stop_txqs(struct ecore_hwfn *p_hwfn,
2675 struct ecore_vf_info *vf,
2679 struct ecore_vf_queue *p_queue;
2680 enum _ecore_status_t rc = ECORE_SUCCESS;
2682 if (!ecore_iov_validate_txq(p_hwfn, vf, txq_id,
2683 ECORE_IOV_VALIDATE_Q_NA))
2686 p_queue = &vf->vf_queues[txq_id];
2687 if (!p_queue->cids[qid_usage_idx].p_cid ||
2688 !p_queue->cids[qid_usage_idx].b_is_tx)
2691 rc = ecore_eth_tx_queue_stop(p_hwfn,
2692 p_queue->cids[qid_usage_idx].p_cid);
2693 if (rc != ECORE_SUCCESS)
2696 p_queue->cids[qid_usage_idx].p_cid = OSAL_NULL;
2697 return ECORE_SUCCESS;
2700 static void ecore_iov_vf_mbx_stop_rxqs(struct ecore_hwfn *p_hwfn,
2701 struct ecore_ptt *p_ptt,
2702 struct ecore_vf_info *vf)
2704 u16 length = sizeof(struct pfvf_def_resp_tlv);
2705 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
2706 u8 status = PFVF_STATUS_FAILURE;
2707 struct vfpf_stop_rxqs_tlv *req;
2709 enum _ecore_status_t rc;
2711 /* Starting with CHANNEL_TLV_QID, it's assumed the 'num_rxqs'
2712 * would be one. Since no older ecore passed multiple queues
2713 * using this API, sanitize on the value.
2715 req = &mbx->req_virt->stop_rxqs;
2716 if (req->num_rxqs != 1) {
2717 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2718 "Odd; VF[%d] tried stopping multiple Rx queues\n",
2719 vf->relative_vf_id);
2720 status = PFVF_STATUS_NOT_SUPPORTED;
2724 /* Find which qid-index is associated with the queue */
2725 qid_usage_idx = ecore_iov_vf_mbx_qid(p_hwfn, vf, false);
2726 if (qid_usage_idx == ECORE_IOV_QID_INVALID)
2729 rc = ecore_iov_vf_stop_rxqs(p_hwfn, vf, req->rx_qid,
2730 qid_usage_idx, req->cqe_completion);
2731 if (rc == ECORE_SUCCESS)
2732 status = PFVF_STATUS_SUCCESS;
2734 ecore_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_STOP_RXQS,
2738 static void ecore_iov_vf_mbx_stop_txqs(struct ecore_hwfn *p_hwfn,
2739 struct ecore_ptt *p_ptt,
2740 struct ecore_vf_info *vf)
2742 u16 length = sizeof(struct pfvf_def_resp_tlv);
2743 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
2744 u8 status = PFVF_STATUS_FAILURE;
2745 struct vfpf_stop_txqs_tlv *req;
2747 enum _ecore_status_t rc;
2749 /* Starting with CHANNEL_TLV_QID, it's assumed the 'num_txqs'
2750 * would be one. Since no older ecore passed multiple queues
2751 * using this API, sanitize on the value.
2753 req = &mbx->req_virt->stop_txqs;
2754 if (req->num_txqs != 1) {
2755 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2756 "Odd; VF[%d] tried stopping multiple Tx queues\n",
2757 vf->relative_vf_id);
2758 status = PFVF_STATUS_NOT_SUPPORTED;
2762 /* Find which qid-index is associated with the queue */
2763 qid_usage_idx = ecore_iov_vf_mbx_qid(p_hwfn, vf, true);
2764 if (qid_usage_idx == ECORE_IOV_QID_INVALID)
2767 rc = ecore_iov_vf_stop_txqs(p_hwfn, vf, req->tx_qid,
2769 if (rc == ECORE_SUCCESS)
2770 status = PFVF_STATUS_SUCCESS;
2773 ecore_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_STOP_TXQS,
2777 static void ecore_iov_vf_mbx_update_rxqs(struct ecore_hwfn *p_hwfn,
2778 struct ecore_ptt *p_ptt,
2779 struct ecore_vf_info *vf)
2781 struct ecore_queue_cid *handlers[ECORE_MAX_VF_CHAINS_PER_PF];
2782 u16 length = sizeof(struct pfvf_def_resp_tlv);
2783 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
2784 struct vfpf_update_rxq_tlv *req;
2785 u8 status = PFVF_STATUS_FAILURE;
2786 u8 complete_event_flg;
2787 u8 complete_cqe_flg;
2789 enum _ecore_status_t rc;
2792 req = &mbx->req_virt->update_rxq;
2793 complete_cqe_flg = !!(req->flags & VFPF_RXQ_UPD_COMPLETE_CQE_FLAG);
2794 complete_event_flg = !!(req->flags & VFPF_RXQ_UPD_COMPLETE_EVENT_FLAG);
2796 qid_usage_idx = ecore_iov_vf_mbx_qid(p_hwfn, vf, false);
2797 if (qid_usage_idx == ECORE_IOV_QID_INVALID)
2800 /* Starting with the addition of CHANNEL_TLV_QID, this API started
2801 * expecting a single queue at a time. Validate this.
2803 if ((vf->acquire.vfdev_info.capabilities &
2804 VFPF_ACQUIRE_CAP_QUEUE_QIDS) &&
2805 req->num_rxqs != 1) {
2806 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2807 "VF[%d] supports QIDs but sends multiple queues\n",
2808 vf->relative_vf_id);
2812 /* Validate inputs - for the legacy case this is still true since
2813 * qid_usage_idx for each Rx queue would be LEGACY_QID_RX.
2815 for (i = req->rx_qid; i < req->rx_qid + req->num_rxqs; i++) {
2816 if (!ecore_iov_validate_rxq(p_hwfn, vf, i,
2817 ECORE_IOV_VALIDATE_Q_NA) ||
2818 !vf->vf_queues[i].cids[qid_usage_idx].p_cid ||
2819 vf->vf_queues[i].cids[qid_usage_idx].b_is_tx) {
2820 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2821 "VF[%d]: Incorrect Rxqs [%04x, %02x]\n",
2822 vf->relative_vf_id, req->rx_qid,
2828 for (i = 0; i < req->num_rxqs; i++) {
2829 u16 qid = req->rx_qid + i;
2831 handlers[i] = vf->vf_queues[qid].cids[qid_usage_idx].p_cid;
2834 rc = ecore_sp_eth_rx_queues_update(p_hwfn, (void **)&handlers,
2838 ECORE_SPQ_MODE_EBLOCK,
2840 if (rc != ECORE_SUCCESS)
2843 status = PFVF_STATUS_SUCCESS;
2845 ecore_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_UPDATE_RXQ,
2849 void *ecore_iov_search_list_tlvs(struct ecore_hwfn *p_hwfn,
2850 void *p_tlvs_list, u16 req_type)
2852 struct channel_tlv *p_tlv = (struct channel_tlv *)p_tlvs_list;
2856 if (!p_tlv->length) {
2857 DP_NOTICE(p_hwfn, true, "Zero length TLV found\n");
2861 if (p_tlv->type == req_type) {
2862 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2863 "Extended tlv type %s, length %d found\n",
2864 ecore_channel_tlvs_string[p_tlv->type],
2869 len += p_tlv->length;
2870 p_tlv = (struct channel_tlv *)((u8 *)p_tlv + p_tlv->length);
2872 if ((len + p_tlv->length) > TLV_BUFFER_SIZE) {
2873 DP_NOTICE(p_hwfn, true,
2874 "TLVs has overrun the buffer size\n");
2877 } while (p_tlv->type != CHANNEL_TLV_LIST_END);
2883 ecore_iov_vp_update_act_param(struct ecore_hwfn *p_hwfn,
2884 struct ecore_sp_vport_update_params *p_data,
2885 struct ecore_iov_vf_mbx *p_mbx, u16 *tlvs_mask)
2887 struct vfpf_vport_update_activate_tlv *p_act_tlv;
2888 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_ACTIVATE;
2890 p_act_tlv = (struct vfpf_vport_update_activate_tlv *)
2891 ecore_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
2895 p_data->update_vport_active_rx_flg = p_act_tlv->update_rx;
2896 p_data->vport_active_rx_flg = p_act_tlv->active_rx;
2897 p_data->update_vport_active_tx_flg = p_act_tlv->update_tx;
2898 p_data->vport_active_tx_flg = p_act_tlv->active_tx;
2899 *tlvs_mask |= 1 << ECORE_IOV_VP_UPDATE_ACTIVATE;
2903 ecore_iov_vp_update_vlan_param(struct ecore_hwfn *p_hwfn,
2904 struct ecore_sp_vport_update_params *p_data,
2905 struct ecore_vf_info *p_vf,
2906 struct ecore_iov_vf_mbx *p_mbx, u16 *tlvs_mask)
2908 struct vfpf_vport_update_vlan_strip_tlv *p_vlan_tlv;
2909 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_VLAN_STRIP;
2911 p_vlan_tlv = (struct vfpf_vport_update_vlan_strip_tlv *)
2912 ecore_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
2916 p_vf->shadow_config.inner_vlan_removal = p_vlan_tlv->remove_vlan;
2918 /* Ignore the VF request if we're forcing a vlan */
2919 if (!(p_vf->configured_features & (1 << VLAN_ADDR_FORCED))) {
2920 p_data->update_inner_vlan_removal_flg = 1;
2921 p_data->inner_vlan_removal_flg = p_vlan_tlv->remove_vlan;
2924 *tlvs_mask |= 1 << ECORE_IOV_VP_UPDATE_VLAN_STRIP;
2928 ecore_iov_vp_update_tx_switch(struct ecore_hwfn *p_hwfn,
2929 struct ecore_sp_vport_update_params *p_data,
2930 struct ecore_iov_vf_mbx *p_mbx, u16 *tlvs_mask)
2932 struct vfpf_vport_update_tx_switch_tlv *p_tx_switch_tlv;
2933 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_TX_SWITCH;
2935 p_tx_switch_tlv = (struct vfpf_vport_update_tx_switch_tlv *)
2936 ecore_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
2937 if (!p_tx_switch_tlv)
2941 if (CHIP_REV_IS_FPGA(p_hwfn->p_dev)) {
2942 DP_NOTICE(p_hwfn, false,
2943 "FPGA: Ignore tx-switching configuration originating"
2949 p_data->update_tx_switching_flg = 1;
2950 p_data->tx_switching_flg = p_tx_switch_tlv->tx_switching;
2951 *tlvs_mask |= 1 << ECORE_IOV_VP_UPDATE_TX_SWITCH;
2955 ecore_iov_vp_update_mcast_bin_param(struct ecore_hwfn *p_hwfn,
2956 struct ecore_sp_vport_update_params *p_data,
2957 struct ecore_iov_vf_mbx *p_mbx,
2960 struct vfpf_vport_update_mcast_bin_tlv *p_mcast_tlv;
2961 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_MCAST;
2963 p_mcast_tlv = (struct vfpf_vport_update_mcast_bin_tlv *)
2964 ecore_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
2968 p_data->update_approx_mcast_flg = 1;
2969 OSAL_MEMCPY(p_data->bins, p_mcast_tlv->bins,
2970 sizeof(unsigned long) *
2971 ETH_MULTICAST_MAC_BINS_IN_REGS);
2972 *tlvs_mask |= 1 << ECORE_IOV_VP_UPDATE_MCAST;
2976 ecore_iov_vp_update_accept_flag(struct ecore_hwfn *p_hwfn,
2977 struct ecore_sp_vport_update_params *p_data,
2978 struct ecore_iov_vf_mbx *p_mbx, u16 *tlvs_mask)
2980 struct ecore_filter_accept_flags *p_flags = &p_data->accept_flags;
2981 struct vfpf_vport_update_accept_param_tlv *p_accept_tlv;
2982 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_ACCEPT_PARAM;
2984 p_accept_tlv = (struct vfpf_vport_update_accept_param_tlv *)
2985 ecore_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
2989 p_flags->update_rx_mode_config = p_accept_tlv->update_rx_mode;
2990 p_flags->rx_accept_filter = p_accept_tlv->rx_accept_filter;
2991 p_flags->update_tx_mode_config = p_accept_tlv->update_tx_mode;
2992 p_flags->tx_accept_filter = p_accept_tlv->tx_accept_filter;
2993 *tlvs_mask |= 1 << ECORE_IOV_VP_UPDATE_ACCEPT_PARAM;
2997 ecore_iov_vp_update_accept_any_vlan(struct ecore_hwfn *p_hwfn,
2998 struct ecore_sp_vport_update_params *p_data,
2999 struct ecore_iov_vf_mbx *p_mbx,
3002 struct vfpf_vport_update_accept_any_vlan_tlv *p_accept_any_vlan;
3003 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_ACCEPT_ANY_VLAN;
3005 p_accept_any_vlan = (struct vfpf_vport_update_accept_any_vlan_tlv *)
3006 ecore_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
3007 if (!p_accept_any_vlan)
3010 p_data->accept_any_vlan = p_accept_any_vlan->accept_any_vlan;
3011 p_data->update_accept_any_vlan_flg =
3012 p_accept_any_vlan->update_accept_any_vlan_flg;
3013 *tlvs_mask |= 1 << ECORE_IOV_VP_UPDATE_ACCEPT_ANY_VLAN;
3017 ecore_iov_vp_update_rss_param(struct ecore_hwfn *p_hwfn,
3018 struct ecore_vf_info *vf,
3019 struct ecore_sp_vport_update_params *p_data,
3020 struct ecore_rss_params *p_rss,
3021 struct ecore_iov_vf_mbx *p_mbx,
3022 u16 *tlvs_mask, u16 *tlvs_accepted)
3024 struct vfpf_vport_update_rss_tlv *p_rss_tlv;
3025 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_RSS;
3026 bool b_reject = false;
3030 p_rss_tlv = (struct vfpf_vport_update_rss_tlv *)
3031 ecore_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
3033 p_data->rss_params = OSAL_NULL;
3037 OSAL_MEMSET(p_rss, 0, sizeof(struct ecore_rss_params));
3039 p_rss->update_rss_config =
3040 !!(p_rss_tlv->update_rss_flags &
3041 VFPF_UPDATE_RSS_CONFIG_FLAG);
3042 p_rss->update_rss_capabilities =
3043 !!(p_rss_tlv->update_rss_flags &
3044 VFPF_UPDATE_RSS_CAPS_FLAG);
3045 p_rss->update_rss_ind_table =
3046 !!(p_rss_tlv->update_rss_flags &
3047 VFPF_UPDATE_RSS_IND_TABLE_FLAG);
3048 p_rss->update_rss_key =
3049 !!(p_rss_tlv->update_rss_flags &
3050 VFPF_UPDATE_RSS_KEY_FLAG);
3052 p_rss->rss_enable = p_rss_tlv->rss_enable;
3053 p_rss->rss_eng_id = vf->rss_eng_id;
3054 p_rss->rss_caps = p_rss_tlv->rss_caps;
3055 p_rss->rss_table_size_log = p_rss_tlv->rss_table_size_log;
3056 OSAL_MEMCPY(p_rss->rss_key, p_rss_tlv->rss_key,
3057 sizeof(p_rss->rss_key));
3059 table_size = OSAL_MIN_T(u16, OSAL_ARRAY_SIZE(p_rss->rss_ind_table),
3060 (1 << p_rss_tlv->rss_table_size_log));
3062 for (i = 0; i < table_size; i++) {
3063 struct ecore_queue_cid *p_cid;
3065 q_idx = p_rss_tlv->rss_ind_table[i];
3066 if (!ecore_iov_validate_rxq(p_hwfn, vf, q_idx,
3067 ECORE_IOV_VALIDATE_Q_ENABLE)) {
3068 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3069 "VF[%d]: Omitting RSS due to wrong queue %04x\n",
3070 vf->relative_vf_id, q_idx);
3075 p_cid = ecore_iov_get_vf_rx_queue_cid(&vf->vf_queues[q_idx]);
3076 p_rss->rss_ind_table[i] = p_cid;
3079 p_data->rss_params = p_rss;
3081 *tlvs_mask |= 1 << ECORE_IOV_VP_UPDATE_RSS;
3083 *tlvs_accepted |= 1 << ECORE_IOV_VP_UPDATE_RSS;
3087 ecore_iov_vp_update_sge_tpa_param(struct ecore_hwfn *p_hwfn,
3088 struct ecore_sp_vport_update_params *p_data,
3089 struct ecore_sge_tpa_params *p_sge_tpa,
3090 struct ecore_iov_vf_mbx *p_mbx,
3093 struct vfpf_vport_update_sge_tpa_tlv *p_sge_tpa_tlv;
3094 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_SGE_TPA;
3096 p_sge_tpa_tlv = (struct vfpf_vport_update_sge_tpa_tlv *)
3097 ecore_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
3099 if (!p_sge_tpa_tlv) {
3100 p_data->sge_tpa_params = OSAL_NULL;
3104 OSAL_MEMSET(p_sge_tpa, 0, sizeof(struct ecore_sge_tpa_params));
3106 p_sge_tpa->update_tpa_en_flg =
3107 !!(p_sge_tpa_tlv->update_sge_tpa_flags & VFPF_UPDATE_TPA_EN_FLAG);
3108 p_sge_tpa->update_tpa_param_flg =
3109 !!(p_sge_tpa_tlv->update_sge_tpa_flags &
3110 VFPF_UPDATE_TPA_PARAM_FLAG);
3112 p_sge_tpa->tpa_ipv4_en_flg =
3113 !!(p_sge_tpa_tlv->sge_tpa_flags & VFPF_TPA_IPV4_EN_FLAG);
3114 p_sge_tpa->tpa_ipv6_en_flg =
3115 !!(p_sge_tpa_tlv->sge_tpa_flags & VFPF_TPA_IPV6_EN_FLAG);
3116 p_sge_tpa->tpa_pkt_split_flg =
3117 !!(p_sge_tpa_tlv->sge_tpa_flags & VFPF_TPA_PKT_SPLIT_FLAG);
3118 p_sge_tpa->tpa_hdr_data_split_flg =
3119 !!(p_sge_tpa_tlv->sge_tpa_flags & VFPF_TPA_HDR_DATA_SPLIT_FLAG);
3120 p_sge_tpa->tpa_gro_consistent_flg =
3121 !!(p_sge_tpa_tlv->sge_tpa_flags & VFPF_TPA_GRO_CONSIST_FLAG);
3123 p_sge_tpa->tpa_max_aggs_num = p_sge_tpa_tlv->tpa_max_aggs_num;
3124 p_sge_tpa->tpa_max_size = p_sge_tpa_tlv->tpa_max_size;
3125 p_sge_tpa->tpa_min_size_to_start = p_sge_tpa_tlv->tpa_min_size_to_start;
3126 p_sge_tpa->tpa_min_size_to_cont = p_sge_tpa_tlv->tpa_min_size_to_cont;
3127 p_sge_tpa->max_buffers_per_cqe = p_sge_tpa_tlv->max_buffers_per_cqe;
3129 p_data->sge_tpa_params = p_sge_tpa;
3131 *tlvs_mask |= 1 << ECORE_IOV_VP_UPDATE_SGE_TPA;
3134 static void ecore_iov_vf_mbx_vport_update(struct ecore_hwfn *p_hwfn,
3135 struct ecore_ptt *p_ptt,
3136 struct ecore_vf_info *vf)
3138 struct ecore_rss_params *p_rss_params = OSAL_NULL;
3139 struct ecore_sp_vport_update_params params;
3140 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
3141 struct ecore_sge_tpa_params sge_tpa_params;
3142 u16 tlvs_mask = 0, tlvs_accepted = 0;
3143 u8 status = PFVF_STATUS_SUCCESS;
3145 enum _ecore_status_t rc;
3147 /* Valiate PF can send such a request */
3148 if (!vf->vport_instance) {
3149 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3150 "No VPORT instance available for VF[%d],"
3151 " failing vport update\n",
3153 status = PFVF_STATUS_FAILURE;
3157 p_rss_params = OSAL_VZALLOC(p_hwfn->p_dev, sizeof(*p_rss_params));
3158 if (p_rss_params == OSAL_NULL) {
3159 status = PFVF_STATUS_FAILURE;
3163 OSAL_MEMSET(¶ms, 0, sizeof(params));
3164 params.opaque_fid = vf->opaque_fid;
3165 params.vport_id = vf->vport_id;
3166 params.rss_params = OSAL_NULL;
3168 /* Search for extended tlvs list and update values
3169 * from VF in struct ecore_sp_vport_update_params.
3171 ecore_iov_vp_update_act_param(p_hwfn, ¶ms, mbx, &tlvs_mask);
3172 ecore_iov_vp_update_vlan_param(p_hwfn, ¶ms, vf, mbx, &tlvs_mask);
3173 ecore_iov_vp_update_tx_switch(p_hwfn, ¶ms, mbx, &tlvs_mask);
3174 ecore_iov_vp_update_mcast_bin_param(p_hwfn, ¶ms, mbx, &tlvs_mask);
3175 ecore_iov_vp_update_accept_flag(p_hwfn, ¶ms, mbx, &tlvs_mask);
3176 ecore_iov_vp_update_accept_any_vlan(p_hwfn, ¶ms, mbx, &tlvs_mask);
3177 ecore_iov_vp_update_sge_tpa_param(p_hwfn, ¶ms,
3178 &sge_tpa_params, mbx, &tlvs_mask);
3180 tlvs_accepted = tlvs_mask;
3182 /* Some of the extended TLVs need to be validated first; In that case,
3183 * they can update the mask without updating the accepted [so that
3184 * PF could communicate to VF it has rejected request].
3186 ecore_iov_vp_update_rss_param(p_hwfn, vf, ¶ms, p_rss_params,
3187 mbx, &tlvs_mask, &tlvs_accepted);
3189 /* Just log a message if there is no single extended tlv in buffer.
3190 * When all features of vport update ramrod would be requested by VF
3191 * as extended TLVs in buffer then an error can be returned in response
3192 * if there is no extended TLV present in buffer.
3194 if (OSAL_IOV_VF_VPORT_UPDATE(p_hwfn, vf->relative_vf_id,
3195 ¶ms, &tlvs_accepted) !=
3198 status = PFVF_STATUS_NOT_SUPPORTED;
3202 if (!tlvs_accepted) {
3204 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3205 "Upper-layer prevents said VF"
3206 " configuration\n");
3208 DP_NOTICE(p_hwfn, true,
3209 "No feature tlvs found for vport update\n");
3210 status = PFVF_STATUS_NOT_SUPPORTED;
3214 rc = ecore_sp_vport_update(p_hwfn, ¶ms, ECORE_SPQ_MODE_EBLOCK,
3218 status = PFVF_STATUS_FAILURE;
3221 OSAL_VFREE(p_hwfn->p_dev, p_rss_params);
3222 length = ecore_iov_prep_vp_update_resp_tlvs(p_hwfn, vf, mbx, status,
3223 tlvs_mask, tlvs_accepted);
3224 ecore_iov_send_response(p_hwfn, p_ptt, vf, length, status);
3227 static enum _ecore_status_t
3228 ecore_iov_vf_update_vlan_shadow(struct ecore_hwfn *p_hwfn,
3229 struct ecore_vf_info *p_vf,
3230 struct ecore_filter_ucast *p_params)
3234 /* First remove entries and then add new ones */
3235 if (p_params->opcode == ECORE_FILTER_REMOVE) {
3236 for (i = 0; i < ECORE_ETH_VF_NUM_VLAN_FILTERS + 1; i++)
3237 if (p_vf->shadow_config.vlans[i].used &&
3238 p_vf->shadow_config.vlans[i].vid ==
3240 p_vf->shadow_config.vlans[i].used = false;
3243 if (i == ECORE_ETH_VF_NUM_VLAN_FILTERS + 1) {
3244 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3245 "VF [%d] - Tries to remove a non-existing"
3247 p_vf->relative_vf_id);
3250 } else if (p_params->opcode == ECORE_FILTER_REPLACE ||
3251 p_params->opcode == ECORE_FILTER_FLUSH) {
3252 for (i = 0; i < ECORE_ETH_VF_NUM_VLAN_FILTERS + 1; i++)
3253 p_vf->shadow_config.vlans[i].used = false;
3256 /* In forced mode, we're willing to remove entries - but we don't add
3259 if (p_vf->bulletin.p_virt->valid_bitmap & (1 << VLAN_ADDR_FORCED))
3260 return ECORE_SUCCESS;
3262 if (p_params->opcode == ECORE_FILTER_ADD ||
3263 p_params->opcode == ECORE_FILTER_REPLACE) {
3264 for (i = 0; i < ECORE_ETH_VF_NUM_VLAN_FILTERS + 1; i++) {
3265 if (p_vf->shadow_config.vlans[i].used)
3268 p_vf->shadow_config.vlans[i].used = true;
3269 p_vf->shadow_config.vlans[i].vid = p_params->vlan;
3273 if (i == ECORE_ETH_VF_NUM_VLAN_FILTERS + 1) {
3274 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3275 "VF [%d] - Tries to configure more than %d"
3277 p_vf->relative_vf_id,
3278 ECORE_ETH_VF_NUM_VLAN_FILTERS + 1);
3283 return ECORE_SUCCESS;
3286 static enum _ecore_status_t
3287 ecore_iov_vf_update_mac_shadow(struct ecore_hwfn *p_hwfn,
3288 struct ecore_vf_info *p_vf,
3289 struct ecore_filter_ucast *p_params)
3291 char empty_mac[ETH_ALEN];
3294 OSAL_MEM_ZERO(empty_mac, ETH_ALEN);
3296 /* If we're in forced-mode, we don't allow any change */
3297 /* TODO - this would change if we were ever to implement logic for
3298 * removing a forced MAC altogether [in which case, like for vlans,
3299 * we should be able to re-trace previous configuration.
3301 if (p_vf->bulletin.p_virt->valid_bitmap & (1 << MAC_ADDR_FORCED))
3302 return ECORE_SUCCESS;
3304 /* First remove entries and then add new ones */
3305 if (p_params->opcode == ECORE_FILTER_REMOVE) {
3306 for (i = 0; i < ECORE_ETH_VF_NUM_MAC_FILTERS; i++) {
3307 if (!OSAL_MEMCMP(p_vf->shadow_config.macs[i],
3308 p_params->mac, ETH_ALEN)) {
3309 OSAL_MEM_ZERO(p_vf->shadow_config.macs[i],
3315 if (i == ECORE_ETH_VF_NUM_MAC_FILTERS) {
3316 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3317 "MAC isn't configured\n");
3320 } else if (p_params->opcode == ECORE_FILTER_REPLACE ||
3321 p_params->opcode == ECORE_FILTER_FLUSH) {
3322 for (i = 0; i < ECORE_ETH_VF_NUM_MAC_FILTERS; i++)
3323 OSAL_MEM_ZERO(p_vf->shadow_config.macs[i], ETH_ALEN);
3326 /* List the new MAC address */
3327 if (p_params->opcode != ECORE_FILTER_ADD &&
3328 p_params->opcode != ECORE_FILTER_REPLACE)
3329 return ECORE_SUCCESS;
3331 for (i = 0; i < ECORE_ETH_VF_NUM_MAC_FILTERS; i++) {
3332 if (!OSAL_MEMCMP(p_vf->shadow_config.macs[i],
3333 empty_mac, ETH_ALEN)) {
3334 OSAL_MEMCPY(p_vf->shadow_config.macs[i],
3335 p_params->mac, ETH_ALEN);
3336 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3337 "Added MAC at %d entry in shadow\n", i);
3342 if (i == ECORE_ETH_VF_NUM_MAC_FILTERS) {
3343 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3344 "No available place for MAC\n");
3348 return ECORE_SUCCESS;
3351 static enum _ecore_status_t
3352 ecore_iov_vf_update_unicast_shadow(struct ecore_hwfn *p_hwfn,
3353 struct ecore_vf_info *p_vf,
3354 struct ecore_filter_ucast *p_params)
3356 enum _ecore_status_t rc = ECORE_SUCCESS;
3358 if (p_params->type == ECORE_FILTER_MAC) {
3359 rc = ecore_iov_vf_update_mac_shadow(p_hwfn, p_vf, p_params);
3360 if (rc != ECORE_SUCCESS)
3364 if (p_params->type == ECORE_FILTER_VLAN)
3365 rc = ecore_iov_vf_update_vlan_shadow(p_hwfn, p_vf, p_params);
3370 static void ecore_iov_vf_mbx_ucast_filter(struct ecore_hwfn *p_hwfn,
3371 struct ecore_ptt *p_ptt,
3372 struct ecore_vf_info *vf)
3374 struct ecore_bulletin_content *p_bulletin = vf->bulletin.p_virt;
3375 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
3376 struct vfpf_ucast_filter_tlv *req;
3377 u8 status = PFVF_STATUS_SUCCESS;
3378 struct ecore_filter_ucast params;
3379 enum _ecore_status_t rc;
3381 /* Prepare the unicast filter params */
3382 OSAL_MEMSET(¶ms, 0, sizeof(struct ecore_filter_ucast));
3383 req = &mbx->req_virt->ucast_filter;
3384 params.opcode = (enum ecore_filter_opcode)req->opcode;
3385 params.type = (enum ecore_filter_ucast_type)req->type;
3387 /* @@@TBD - We might need logic on HV side in determining this */
3388 params.is_rx_filter = 1;
3389 params.is_tx_filter = 1;
3390 params.vport_to_remove_from = vf->vport_id;
3391 params.vport_to_add_to = vf->vport_id;
3392 OSAL_MEMCPY(params.mac, req->mac, ETH_ALEN);
3393 params.vlan = req->vlan;
3395 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3396 "VF[%d]: opcode 0x%02x type 0x%02x [%s %s] [vport 0x%02x]"
3397 " MAC %02x:%02x:%02x:%02x:%02x:%02x, vlan 0x%04x\n",
3398 vf->abs_vf_id, params.opcode, params.type,
3399 params.is_rx_filter ? "RX" : "",
3400 params.is_tx_filter ? "TX" : "",
3401 params.vport_to_add_to,
3402 params.mac[0], params.mac[1], params.mac[2],
3403 params.mac[3], params.mac[4], params.mac[5], params.vlan);
3405 if (!vf->vport_instance) {
3406 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3407 "No VPORT instance available for VF[%d],"
3408 " failing ucast MAC configuration\n",
3410 status = PFVF_STATUS_FAILURE;
3414 /* Update shadow copy of the VF configuration */
3415 if (ecore_iov_vf_update_unicast_shadow(p_hwfn, vf, ¶ms) !=
3417 status = PFVF_STATUS_FAILURE;
3421 /* Determine if the unicast filtering is acceptible by PF */
3422 if ((p_bulletin->valid_bitmap & (1 << VLAN_ADDR_FORCED)) &&
3423 (params.type == ECORE_FILTER_VLAN ||
3424 params.type == ECORE_FILTER_MAC_VLAN)) {
3425 /* Once VLAN is forced or PVID is set, do not allow
3426 * to add/replace any further VLANs.
3428 if (params.opcode == ECORE_FILTER_ADD ||
3429 params.opcode == ECORE_FILTER_REPLACE)
3430 status = PFVF_STATUS_FORCED;
3434 if ((p_bulletin->valid_bitmap & (1 << MAC_ADDR_FORCED)) &&
3435 (params.type == ECORE_FILTER_MAC ||
3436 params.type == ECORE_FILTER_MAC_VLAN)) {
3437 if (OSAL_MEMCMP(p_bulletin->mac, params.mac, ETH_ALEN) ||
3438 (params.opcode != ECORE_FILTER_ADD &&
3439 params.opcode != ECORE_FILTER_REPLACE))
3440 status = PFVF_STATUS_FORCED;
3444 rc = OSAL_IOV_CHK_UCAST(p_hwfn, vf->relative_vf_id, ¶ms);
3445 if (rc == ECORE_EXISTS) {
3447 } else if (rc == ECORE_INVAL) {
3448 status = PFVF_STATUS_FAILURE;
3452 rc = ecore_sp_eth_filter_ucast(p_hwfn, vf->opaque_fid, ¶ms,
3453 ECORE_SPQ_MODE_CB, OSAL_NULL);
3455 status = PFVF_STATUS_FAILURE;
3458 ecore_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_UCAST_FILTER,
3459 sizeof(struct pfvf_def_resp_tlv), status);
3462 static void ecore_iov_vf_mbx_int_cleanup(struct ecore_hwfn *p_hwfn,
3463 struct ecore_ptt *p_ptt,
3464 struct ecore_vf_info *vf)
3469 for (i = 0; i < vf->num_sbs; i++)
3470 ecore_int_igu_init_pure_rt_single(p_hwfn, p_ptt,
3472 vf->opaque_fid, false);
3474 ecore_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_INT_CLEANUP,
3475 sizeof(struct pfvf_def_resp_tlv),
3476 PFVF_STATUS_SUCCESS);
3479 static void ecore_iov_vf_mbx_close(struct ecore_hwfn *p_hwfn,
3480 struct ecore_ptt *p_ptt,
3481 struct ecore_vf_info *vf)
3483 u16 length = sizeof(struct pfvf_def_resp_tlv);
3484 u8 status = PFVF_STATUS_SUCCESS;
3486 /* Disable Interrupts for VF */
3487 ecore_iov_vf_igu_set_int(p_hwfn, p_ptt, vf, 0);
3489 /* Reset Permission table */
3490 ecore_iov_config_perm_table(p_hwfn, p_ptt, vf, 0);
3492 ecore_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_CLOSE,
3496 static void ecore_iov_vf_mbx_release(struct ecore_hwfn *p_hwfn,
3497 struct ecore_ptt *p_ptt,
3498 struct ecore_vf_info *p_vf)
3500 u16 length = sizeof(struct pfvf_def_resp_tlv);
3501 u8 status = PFVF_STATUS_SUCCESS;
3502 enum _ecore_status_t rc = ECORE_SUCCESS;
3504 ecore_iov_vf_cleanup(p_hwfn, p_vf);
3506 if (p_vf->state != VF_STOPPED && p_vf->state != VF_FREE) {
3507 /* Stopping the VF */
3508 rc = ecore_sp_vf_stop(p_hwfn, p_vf->concrete_fid,
3511 if (rc != ECORE_SUCCESS) {
3512 DP_ERR(p_hwfn, "ecore_sp_vf_stop returned error %d\n",
3514 status = PFVF_STATUS_FAILURE;
3517 p_vf->state = VF_STOPPED;
3520 ecore_iov_prepare_resp(p_hwfn, p_ptt, p_vf, CHANNEL_TLV_RELEASE,
3524 static void ecore_iov_vf_pf_get_coalesce(struct ecore_hwfn *p_hwfn,
3525 struct ecore_ptt *p_ptt,
3526 struct ecore_vf_info *p_vf)
3528 struct ecore_iov_vf_mbx *mbx = &p_vf->vf_mbx;
3529 struct pfvf_read_coal_resp_tlv *p_resp;
3530 struct vfpf_read_coal_req_tlv *req;
3531 u8 status = PFVF_STATUS_FAILURE;
3532 struct ecore_vf_queue *p_queue;
3533 struct ecore_queue_cid *p_cid;
3534 enum _ecore_status_t rc = ECORE_SUCCESS;
3535 u16 coal = 0, qid, i;
3538 mbx->offset = (u8 *)mbx->reply_virt;
3539 req = &mbx->req_virt->read_coal_req;
3542 b_is_rx = req->is_rx ? true : false;
3545 if (!ecore_iov_validate_rxq(p_hwfn, p_vf, qid,
3546 ECORE_IOV_VALIDATE_Q_ENABLE)) {
3547 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3548 "VF[%d]: Invalid Rx queue_id = %d\n",
3549 p_vf->abs_vf_id, qid);
3553 p_cid = ecore_iov_get_vf_rx_queue_cid(&p_vf->vf_queues[qid]);
3554 rc = ecore_get_rxq_coalesce(p_hwfn, p_ptt, p_cid, &coal);
3555 if (rc != ECORE_SUCCESS)
3558 if (!ecore_iov_validate_txq(p_hwfn, p_vf, qid,
3559 ECORE_IOV_VALIDATE_Q_ENABLE)) {
3560 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3561 "VF[%d]: Invalid Tx queue_id = %d\n",
3562 p_vf->abs_vf_id, qid);
3565 for (i = 0; i < MAX_QUEUES_PER_QZONE; i++) {
3566 p_queue = &p_vf->vf_queues[qid];
3567 if ((p_queue->cids[i].p_cid == OSAL_NULL) ||
3568 (!p_queue->cids[i].b_is_tx))
3571 p_cid = p_queue->cids[i].p_cid;
3573 rc = ecore_get_txq_coalesce(p_hwfn, p_ptt,
3575 if (rc != ECORE_SUCCESS)
3581 status = PFVF_STATUS_SUCCESS;
3584 p_resp = ecore_add_tlv(&mbx->offset, CHANNEL_TLV_COALESCE_READ,
3586 p_resp->coal = coal;
3588 ecore_add_tlv(&mbx->offset, CHANNEL_TLV_LIST_END,
3589 sizeof(struct channel_list_end_tlv));
3591 ecore_iov_send_response(p_hwfn, p_ptt, p_vf, sizeof(*p_resp), status);
3594 static void ecore_iov_vf_pf_set_coalesce(struct ecore_hwfn *p_hwfn,
3595 struct ecore_ptt *p_ptt,
3596 struct ecore_vf_info *vf)
3598 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
3599 enum _ecore_status_t rc = ECORE_SUCCESS;
3600 struct vfpf_update_coalesce *req;
3601 u8 status = PFVF_STATUS_FAILURE;
3602 struct ecore_queue_cid *p_cid;
3603 u16 rx_coal, tx_coal;
3607 req = &mbx->req_virt->update_coalesce;
3609 rx_coal = req->rx_coal;
3610 tx_coal = req->tx_coal;
3613 if (!ecore_iov_validate_rxq(p_hwfn, vf, qid,
3614 ECORE_IOV_VALIDATE_Q_ENABLE) &&
3616 DP_ERR(p_hwfn, "VF[%d]: Invalid Rx queue_id = %d\n",
3617 vf->abs_vf_id, qid);
3621 if (!ecore_iov_validate_txq(p_hwfn, vf, qid,
3622 ECORE_IOV_VALIDATE_Q_ENABLE) &&
3624 DP_ERR(p_hwfn, "VF[%d]: Invalid Tx queue_id = %d\n",
3625 vf->abs_vf_id, qid);
3629 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3630 "VF[%d]: Setting coalesce for VF rx_coal = %d, tx_coal = %d at queue = %d\n",
3631 vf->abs_vf_id, rx_coal, tx_coal, qid);
3634 p_cid = ecore_iov_get_vf_rx_queue_cid(&vf->vf_queues[qid]);
3636 rc = ecore_set_rxq_coalesce(p_hwfn, p_ptt, rx_coal, p_cid);
3637 if (rc != ECORE_SUCCESS) {
3638 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3639 "VF[%d]: Unable to set rx queue = %d coalesce\n",
3640 vf->abs_vf_id, vf->vf_queues[qid].fw_rx_qid);
3643 vf->rx_coal = rx_coal;
3646 /* TODO - in future, it might be possible to pass this in a per-cid
3647 * granularity. For now, do this for all Tx queues.
3650 struct ecore_vf_queue *p_queue = &vf->vf_queues[qid];
3652 for (i = 0; i < MAX_QUEUES_PER_QZONE; i++) {
3653 if (p_queue->cids[i].p_cid == OSAL_NULL)
3656 if (!p_queue->cids[i].b_is_tx)
3659 rc = ecore_set_txq_coalesce(p_hwfn, p_ptt, tx_coal,
3660 p_queue->cids[i].p_cid);
3661 if (rc != ECORE_SUCCESS) {
3662 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3663 "VF[%d]: Unable to set tx queue coalesce\n",
3668 vf->tx_coal = tx_coal;
3671 status = PFVF_STATUS_SUCCESS;
3673 ecore_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_COALESCE_UPDATE,
3674 sizeof(struct pfvf_def_resp_tlv), status);
3677 enum _ecore_status_t
3678 ecore_iov_pf_configure_vf_queue_coalesce(struct ecore_hwfn *p_hwfn,
3679 u16 rx_coal, u16 tx_coal,
3682 struct ecore_queue_cid *p_cid;
3683 struct ecore_vf_info *vf;
3684 struct ecore_ptt *p_ptt;
3687 if (!ecore_iov_is_valid_vfid(p_hwfn, vf_id, true, true)) {
3688 DP_NOTICE(p_hwfn, true,
3689 "VF[%d] - Can not set coalescing: VF is not active\n",
3694 vf = &p_hwfn->pf_iov_info->vfs_array[vf_id];
3695 p_ptt = ecore_ptt_acquire(p_hwfn);
3699 if (!ecore_iov_validate_rxq(p_hwfn, vf, qid,
3700 ECORE_IOV_VALIDATE_Q_ENABLE) &&
3702 DP_ERR(p_hwfn, "VF[%d]: Invalid Rx queue_id = %d\n",
3703 vf->abs_vf_id, qid);
3707 if (!ecore_iov_validate_txq(p_hwfn, vf, qid,
3708 ECORE_IOV_VALIDATE_Q_ENABLE) &&
3710 DP_ERR(p_hwfn, "VF[%d]: Invalid Tx queue_id = %d\n",
3711 vf->abs_vf_id, qid);
3715 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3716 "VF[%d]: Setting coalesce for VF rx_coal = %d, tx_coal = %d at queue = %d\n",
3717 vf->abs_vf_id, rx_coal, tx_coal, qid);
3720 p_cid = ecore_iov_get_vf_rx_queue_cid(&vf->vf_queues[qid]);
3722 rc = ecore_set_rxq_coalesce(p_hwfn, p_ptt, rx_coal, p_cid);
3723 if (rc != ECORE_SUCCESS) {
3724 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3725 "VF[%d]: Unable to set rx queue = %d coalesce\n",
3726 vf->abs_vf_id, vf->vf_queues[qid].fw_rx_qid);
3729 vf->rx_coal = rx_coal;
3732 /* TODO - in future, it might be possible to pass this in a per-cid
3733 * granularity. For now, do this for all Tx queues.
3736 struct ecore_vf_queue *p_queue = &vf->vf_queues[qid];
3738 for (i = 0; i < MAX_QUEUES_PER_QZONE; i++) {
3739 if (p_queue->cids[i].p_cid == OSAL_NULL)
3742 if (!p_queue->cids[i].b_is_tx)
3745 rc = ecore_set_txq_coalesce(p_hwfn, p_ptt, tx_coal,
3746 p_queue->cids[i].p_cid);
3747 if (rc != ECORE_SUCCESS) {
3748 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3749 "VF[%d]: Unable to set tx queue coalesce\n",
3754 vf->tx_coal = tx_coal;
3758 ecore_ptt_release(p_hwfn, p_ptt);
3763 static enum _ecore_status_t
3764 ecore_iov_vf_flr_poll_dorq(struct ecore_hwfn *p_hwfn,
3765 struct ecore_vf_info *p_vf, struct ecore_ptt *p_ptt)
3770 ecore_fid_pretend(p_hwfn, p_ptt, (u16)p_vf->concrete_fid);
3772 for (cnt = 0; cnt < 50; cnt++) {
3773 val = ecore_rd(p_hwfn, p_ptt, DORQ_REG_VF_USAGE_CNT);
3778 ecore_fid_pretend(p_hwfn, p_ptt, (u16)p_hwfn->hw_info.concrete_fid);
3782 "VF[%d] - dorq failed to cleanup [usage 0x%08x]\n",
3783 p_vf->abs_vf_id, val);
3784 return ECORE_TIMEOUT;
3787 return ECORE_SUCCESS;
3790 static enum _ecore_status_t
3791 ecore_iov_vf_flr_poll_pbf(struct ecore_hwfn *p_hwfn,
3792 struct ecore_vf_info *p_vf, struct ecore_ptt *p_ptt)
3794 u32 cons[MAX_NUM_VOQS_E4], distance[MAX_NUM_VOQS_E4];
3797 /* Read initial consumers & producers */
3798 for (i = 0; i < MAX_NUM_VOQS_E4; i++) {
3801 cons[i] = ecore_rd(p_hwfn, p_ptt,
3802 PBF_REG_NUM_BLOCKS_ALLOCATED_CONS_VOQ0 +
3804 prod = ecore_rd(p_hwfn, p_ptt,
3805 PBF_REG_NUM_BLOCKS_ALLOCATED_PROD_VOQ0 +
3807 distance[i] = prod - cons[i];
3810 /* Wait for consumers to pass the producers */
3812 for (cnt = 0; cnt < 50; cnt++) {
3813 for (; i < MAX_NUM_VOQS_E4; i++) {
3816 tmp = ecore_rd(p_hwfn, p_ptt,
3817 PBF_REG_NUM_BLOCKS_ALLOCATED_CONS_VOQ0 +
3819 if (distance[i] > tmp - cons[i])
3823 if (i == MAX_NUM_VOQS_E4)
3830 DP_ERR(p_hwfn, "VF[%d] - pbf polling failed on VOQ %d\n",
3831 p_vf->abs_vf_id, i);
3832 return ECORE_TIMEOUT;
3835 return ECORE_SUCCESS;
3838 static enum _ecore_status_t ecore_iov_vf_flr_poll(struct ecore_hwfn *p_hwfn,
3839 struct ecore_vf_info *p_vf,
3840 struct ecore_ptt *p_ptt)
3842 enum _ecore_status_t rc;
3844 /* TODO - add SRC and TM polling once we add storage IOV */
3846 rc = ecore_iov_vf_flr_poll_dorq(p_hwfn, p_vf, p_ptt);
3850 rc = ecore_iov_vf_flr_poll_pbf(p_hwfn, p_vf, p_ptt);
3854 return ECORE_SUCCESS;
3857 static enum _ecore_status_t
3858 ecore_iov_execute_vf_flr_cleanup(struct ecore_hwfn *p_hwfn,
3859 struct ecore_ptt *p_ptt,
3860 u16 rel_vf_id, u32 *ack_vfs)
3862 struct ecore_vf_info *p_vf;
3863 enum _ecore_status_t rc = ECORE_SUCCESS;
3865 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, false);
3867 return ECORE_SUCCESS;
3869 if (p_hwfn->pf_iov_info->pending_flr[rel_vf_id / 64] &
3870 (1ULL << (rel_vf_id % 64))) {
3871 u16 vfid = p_vf->abs_vf_id;
3873 /* TODO - should we lock channel? */
3875 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3876 "VF[%d] - Handling FLR\n", vfid);
3878 ecore_iov_vf_cleanup(p_hwfn, p_vf);
3880 /* If VF isn't active, no need for anything but SW */
3884 /* TODO - what to do in case of failure? */
3885 rc = ecore_iov_vf_flr_poll(p_hwfn, p_vf, p_ptt);
3886 if (rc != ECORE_SUCCESS)
3889 rc = ecore_final_cleanup(p_hwfn, p_ptt, vfid, true);
3891 /* TODO - what's now? What a mess.... */
3892 DP_ERR(p_hwfn, "Failed handle FLR of VF[%d]\n", vfid);
3896 /* Workaround to make VF-PF channel ready, as FW
3897 * doesn't do that as a part of FLR.
3900 GTT_BAR0_MAP_REG_USDM_RAM +
3901 USTORM_VF_PF_CHANNEL_READY_OFFSET(vfid), 1);
3903 /* VF_STOPPED has to be set only after final cleanup
3904 * but prior to re-enabling the VF.
3906 p_vf->state = VF_STOPPED;
3908 rc = ecore_iov_enable_vf_access(p_hwfn, p_ptt, p_vf);
3910 /* TODO - again, a mess... */
3911 DP_ERR(p_hwfn, "Failed to re-enable VF[%d] acces\n",
3916 /* Mark VF for ack and clean pending state */
3917 if (p_vf->state == VF_RESET)
3918 p_vf->state = VF_STOPPED;
3919 ack_vfs[vfid / 32] |= (1 << (vfid % 32));
3920 p_hwfn->pf_iov_info->pending_flr[rel_vf_id / 64] &=
3921 ~(1ULL << (rel_vf_id % 64));
3922 p_vf->vf_mbx.b_pending_msg = false;
3928 enum _ecore_status_t ecore_iov_vf_flr_cleanup(struct ecore_hwfn *p_hwfn,
3929 struct ecore_ptt *p_ptt)
3931 u32 ack_vfs[VF_MAX_STATIC / 32];
3932 enum _ecore_status_t rc = ECORE_SUCCESS;
3935 OSAL_MEMSET(ack_vfs, 0, sizeof(u32) * (VF_MAX_STATIC / 32));
3937 /* Since BRB <-> PRS interface can't be tested as part of the flr
3938 * polling due to HW limitations, simply sleep a bit. And since
3939 * there's no need to wait per-vf, do it before looping.
3943 for (i = 0; i < p_hwfn->p_dev->p_iov_info->total_vfs; i++)
3944 ecore_iov_execute_vf_flr_cleanup(p_hwfn, p_ptt, i, ack_vfs);
3946 rc = ecore_mcp_ack_vf_flr(p_hwfn, p_ptt, ack_vfs);
3950 enum _ecore_status_t
3951 ecore_iov_single_vf_flr_cleanup(struct ecore_hwfn *p_hwfn,
3952 struct ecore_ptt *p_ptt, u16 rel_vf_id)
3954 u32 ack_vfs[VF_MAX_STATIC / 32];
3955 enum _ecore_status_t rc = ECORE_SUCCESS;
3957 OSAL_MEMSET(ack_vfs, 0, sizeof(u32) * (VF_MAX_STATIC / 32));
3959 /* Wait instead of polling the BRB <-> PRS interface */
3962 ecore_iov_execute_vf_flr_cleanup(p_hwfn, p_ptt, rel_vf_id, ack_vfs);
3964 rc = ecore_mcp_ack_vf_flr(p_hwfn, p_ptt, ack_vfs);
3968 bool ecore_iov_mark_vf_flr(struct ecore_hwfn *p_hwfn, u32 *p_disabled_vfs)
3973 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV, "Marking FLR-ed VFs\n");
3974 for (i = 0; i < (VF_MAX_STATIC / 32); i++)
3975 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3976 "[%08x,...,%08x]: %08x\n",
3977 i * 32, (i + 1) * 32 - 1, p_disabled_vfs[i]);
3979 if (!p_hwfn->p_dev->p_iov_info) {
3980 DP_NOTICE(p_hwfn, true, "VF flr but no IOV\n");
3985 for (i = 0; i < p_hwfn->p_dev->p_iov_info->total_vfs; i++) {
3986 struct ecore_vf_info *p_vf;
3989 p_vf = ecore_iov_get_vf_info(p_hwfn, i, false);
3993 vfid = p_vf->abs_vf_id;
3994 if ((1 << (vfid % 32)) & p_disabled_vfs[vfid / 32]) {
3995 u64 *p_flr = p_hwfn->pf_iov_info->pending_flr;
3996 u16 rel_vf_id = p_vf->relative_vf_id;
3998 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3999 "VF[%d] [rel %d] got FLR-ed\n",
4002 p_vf->state = VF_RESET;
4004 /* No need to lock here, since pending_flr should
4005 * only change here and before ACKing MFw. Since
4006 * MFW will not trigger an additional attention for
4007 * VF flr until ACKs, we're safe.
4009 p_flr[rel_vf_id / 64] |= 1ULL << (rel_vf_id % 64);
4017 void ecore_iov_get_link(struct ecore_hwfn *p_hwfn,
4019 struct ecore_mcp_link_params *p_params,
4020 struct ecore_mcp_link_state *p_link,
4021 struct ecore_mcp_link_capabilities *p_caps)
4023 struct ecore_vf_info *p_vf = ecore_iov_get_vf_info(p_hwfn, vfid, false);
4024 struct ecore_bulletin_content *p_bulletin;
4029 p_bulletin = p_vf->bulletin.p_virt;
4032 __ecore_vf_get_link_params(p_params, p_bulletin);
4034 __ecore_vf_get_link_state(p_link, p_bulletin);
4036 __ecore_vf_get_link_caps(p_caps, p_bulletin);
4039 void ecore_iov_process_mbx_req(struct ecore_hwfn *p_hwfn,
4040 struct ecore_ptt *p_ptt, int vfid)
4042 struct ecore_iov_vf_mbx *mbx;
4043 struct ecore_vf_info *p_vf;
4045 p_vf = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4049 mbx = &p_vf->vf_mbx;
4051 /* ecore_iov_process_mbx_request */
4052 #ifndef CONFIG_ECORE_SW_CHANNEL
4053 if (!mbx->b_pending_msg) {
4054 DP_NOTICE(p_hwfn, true,
4055 "VF[%02x]: Trying to process mailbox message when none is pending\n",
4059 mbx->b_pending_msg = false;
4062 mbx->first_tlv = mbx->req_virt->first_tlv;
4064 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
4065 "VF[%02x]: Processing mailbox message [type %04x]\n",
4066 p_vf->abs_vf_id, mbx->first_tlv.tl.type);
4068 OSAL_IOV_VF_MSG_TYPE(p_hwfn,
4069 p_vf->relative_vf_id,
4070 mbx->first_tlv.tl.type);
4072 /* Lock the per vf op mutex and note the locker's identity.
4073 * The unlock will take place in mbx response.
4075 ecore_iov_lock_vf_pf_channel(p_hwfn,
4076 p_vf, mbx->first_tlv.tl.type);
4078 /* check if tlv type is known */
4079 if (ecore_iov_tlv_supported(mbx->first_tlv.tl.type) &&
4080 !p_vf->b_malicious) {
4081 /* switch on the opcode */
4082 switch (mbx->first_tlv.tl.type) {
4083 case CHANNEL_TLV_ACQUIRE:
4084 ecore_iov_vf_mbx_acquire(p_hwfn, p_ptt, p_vf);
4086 case CHANNEL_TLV_VPORT_START:
4087 ecore_iov_vf_mbx_start_vport(p_hwfn, p_ptt, p_vf);
4089 case CHANNEL_TLV_VPORT_TEARDOWN:
4090 ecore_iov_vf_mbx_stop_vport(p_hwfn, p_ptt, p_vf);
4092 case CHANNEL_TLV_START_RXQ:
4093 ecore_iov_vf_mbx_start_rxq(p_hwfn, p_ptt, p_vf);
4095 case CHANNEL_TLV_START_TXQ:
4096 ecore_iov_vf_mbx_start_txq(p_hwfn, p_ptt, p_vf);
4098 case CHANNEL_TLV_STOP_RXQS:
4099 ecore_iov_vf_mbx_stop_rxqs(p_hwfn, p_ptt, p_vf);
4101 case CHANNEL_TLV_STOP_TXQS:
4102 ecore_iov_vf_mbx_stop_txqs(p_hwfn, p_ptt, p_vf);
4104 case CHANNEL_TLV_UPDATE_RXQ:
4105 ecore_iov_vf_mbx_update_rxqs(p_hwfn, p_ptt, p_vf);
4107 case CHANNEL_TLV_VPORT_UPDATE:
4108 ecore_iov_vf_mbx_vport_update(p_hwfn, p_ptt, p_vf);
4110 case CHANNEL_TLV_UCAST_FILTER:
4111 ecore_iov_vf_mbx_ucast_filter(p_hwfn, p_ptt, p_vf);
4113 case CHANNEL_TLV_CLOSE:
4114 ecore_iov_vf_mbx_close(p_hwfn, p_ptt, p_vf);
4116 case CHANNEL_TLV_INT_CLEANUP:
4117 ecore_iov_vf_mbx_int_cleanup(p_hwfn, p_ptt, p_vf);
4119 case CHANNEL_TLV_RELEASE:
4120 ecore_iov_vf_mbx_release(p_hwfn, p_ptt, p_vf);
4122 case CHANNEL_TLV_UPDATE_TUNN_PARAM:
4123 ecore_iov_vf_mbx_update_tunn_param(p_hwfn, p_ptt, p_vf);
4125 case CHANNEL_TLV_COALESCE_UPDATE:
4126 ecore_iov_vf_pf_set_coalesce(p_hwfn, p_ptt, p_vf);
4128 case CHANNEL_TLV_COALESCE_READ:
4129 ecore_iov_vf_pf_get_coalesce(p_hwfn, p_ptt, p_vf);
4132 } else if (ecore_iov_tlv_supported(mbx->first_tlv.tl.type)) {
4133 /* If we've received a message from a VF we consider malicious
4134 * we ignore the messasge unless it's one for RELEASE, in which
4135 * case we'll let it have the benefit of doubt, allowing the
4136 * next loaded driver to start again.
4138 if (mbx->first_tlv.tl.type == CHANNEL_TLV_RELEASE) {
4139 /* TODO - initiate FLR, remove malicious indication */
4140 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
4141 "VF [%02x] - considered malicious, but wanted to RELEASE. TODO\n",
4144 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
4145 "VF [%02x] - considered malicious; Ignoring TLV [%04x]\n",
4146 p_vf->abs_vf_id, mbx->first_tlv.tl.type);
4149 ecore_iov_prepare_resp(p_hwfn, p_ptt, p_vf,
4150 mbx->first_tlv.tl.type,
4151 sizeof(struct pfvf_def_resp_tlv),
4152 PFVF_STATUS_MALICIOUS);
4154 /* unknown TLV - this may belong to a VF driver from the future
4155 * - a version written after this PF driver was written, which
4156 * supports features unknown as of yet. Too bad since we don't
4157 * support them. Or this may be because someone wrote a crappy
4158 * VF driver and is sending garbage over the channel.
4160 DP_NOTICE(p_hwfn, false,
4161 "VF[%02x]: unknown TLV. type %04x length %04x"
4162 " padding %08x reply address %lu\n",
4164 mbx->first_tlv.tl.type,
4165 mbx->first_tlv.tl.length,
4166 mbx->first_tlv.padding,
4167 (unsigned long)mbx->first_tlv.reply_address);
4169 /* Try replying in case reply address matches the acquisition's
4172 if (p_vf->acquire.first_tlv.reply_address &&
4173 (mbx->first_tlv.reply_address ==
4174 p_vf->acquire.first_tlv.reply_address))
4175 ecore_iov_prepare_resp(p_hwfn, p_ptt, p_vf,
4176 mbx->first_tlv.tl.type,
4177 sizeof(struct pfvf_def_resp_tlv),
4178 PFVF_STATUS_NOT_SUPPORTED);
4180 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
4181 "VF[%02x]: Can't respond to TLV -"
4182 " no valid reply address\n",
4186 ecore_iov_unlock_vf_pf_channel(p_hwfn, p_vf,
4187 mbx->first_tlv.tl.type);
4189 #ifdef CONFIG_ECORE_SW_CHANNEL
4190 mbx->sw_mbx.mbx_state = VF_PF_RESPONSE_READY;
4191 mbx->sw_mbx.response_offset = 0;
4195 void ecore_iov_pf_get_pending_events(struct ecore_hwfn *p_hwfn,
4200 OSAL_MEM_ZERO(events, sizeof(u64) * ECORE_VF_ARRAY_LENGTH);
4202 ecore_for_each_vf(p_hwfn, i) {
4203 struct ecore_vf_info *p_vf;
4205 p_vf = &p_hwfn->pf_iov_info->vfs_array[i];
4206 if (p_vf->vf_mbx.b_pending_msg)
4207 events[i / 64] |= 1ULL << (i % 64);
4211 static struct ecore_vf_info *
4212 ecore_sriov_get_vf_from_absid(struct ecore_hwfn *p_hwfn, u16 abs_vfid)
4214 u8 min = (u8)p_hwfn->p_dev->p_iov_info->first_vf_in_pf;
4216 if (!_ecore_iov_pf_sanity_check(p_hwfn, (int)abs_vfid - min, false)) {
4217 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
4218 "Got indication for VF [abs 0x%08x] that cannot be"
4224 return &p_hwfn->pf_iov_info->vfs_array[(u8)abs_vfid - min];
4227 static enum _ecore_status_t ecore_sriov_vfpf_msg(struct ecore_hwfn *p_hwfn,
4229 struct regpair *vf_msg)
4231 struct ecore_vf_info *p_vf = ecore_sriov_get_vf_from_absid(p_hwfn,
4235 return ECORE_SUCCESS;
4237 /* List the physical address of the request so that handler
4238 * could later on copy the message from it.
4240 p_vf->vf_mbx.pending_req = (((u64)vf_msg->hi) << 32) | vf_msg->lo;
4242 p_vf->vf_mbx.b_pending_msg = true;
4244 return OSAL_PF_VF_MSG(p_hwfn, p_vf->relative_vf_id);
4247 static void ecore_sriov_vfpf_malicious(struct ecore_hwfn *p_hwfn,
4248 struct malicious_vf_eqe_data *p_data)
4250 struct ecore_vf_info *p_vf;
4252 p_vf = ecore_sriov_get_vf_from_absid(p_hwfn, p_data->vf_id);
4257 if (!p_vf->b_malicious) {
4258 DP_NOTICE(p_hwfn, false,
4259 "VF [%d] - Malicious behavior [%02x]\n",
4260 p_vf->abs_vf_id, p_data->err_id);
4262 p_vf->b_malicious = true;
4265 "VF [%d] - Malicious behavior [%02x]\n",
4266 p_vf->abs_vf_id, p_data->err_id);
4269 OSAL_PF_VF_MALICIOUS(p_hwfn, p_vf->relative_vf_id);
4272 static enum _ecore_status_t ecore_sriov_eqe_event(struct ecore_hwfn *p_hwfn,
4275 union event_ring_data *data,
4276 u8 OSAL_UNUSED fw_return_code)
4279 case COMMON_EVENT_VF_PF_CHANNEL:
4280 return ecore_sriov_vfpf_msg(p_hwfn, OSAL_LE16_TO_CPU(echo),
4281 &data->vf_pf_channel.msg_addr);
4282 case COMMON_EVENT_VF_FLR:
4283 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
4284 "VF-FLR is still not supported\n");
4285 return ECORE_SUCCESS;
4286 case COMMON_EVENT_MALICIOUS_VF:
4287 ecore_sriov_vfpf_malicious(p_hwfn, &data->malicious_vf);
4288 return ECORE_SUCCESS;
4290 DP_INFO(p_hwfn->p_dev, "Unknown sriov eqe event 0x%02x\n",
4296 bool ecore_iov_is_vf_pending_flr(struct ecore_hwfn *p_hwfn, u16 rel_vf_id)
4298 return !!(p_hwfn->pf_iov_info->pending_flr[rel_vf_id / 64] &
4299 (1ULL << (rel_vf_id % 64)));
4302 u16 ecore_iov_get_next_active_vf(struct ecore_hwfn *p_hwfn, u16 rel_vf_id)
4304 struct ecore_hw_sriov_info *p_iov = p_hwfn->p_dev->p_iov_info;
4310 for (i = rel_vf_id; i < p_iov->total_vfs; i++)
4311 if (ecore_iov_is_valid_vfid(p_hwfn, rel_vf_id, true, false))
4315 return MAX_NUM_VFS_E4;
4318 enum _ecore_status_t ecore_iov_copy_vf_msg(struct ecore_hwfn *p_hwfn,
4319 struct ecore_ptt *ptt, int vfid)
4321 struct ecore_dmae_params params;
4322 struct ecore_vf_info *vf_info;
4324 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4328 OSAL_MEMSET(¶ms, 0, sizeof(struct ecore_dmae_params));
4329 params.flags = ECORE_DMAE_FLAG_VF_SRC | ECORE_DMAE_FLAG_COMPLETION_DST;
4330 params.src_vfid = vf_info->abs_vf_id;
4332 if (ecore_dmae_host2host(p_hwfn, ptt,
4333 vf_info->vf_mbx.pending_req,
4334 vf_info->vf_mbx.req_phys,
4335 sizeof(union vfpf_tlvs) / 4, ¶ms)) {
4336 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
4337 "Failed to copy message from VF 0x%02x\n", vfid);
4342 return ECORE_SUCCESS;
4345 void ecore_iov_bulletin_set_forced_mac(struct ecore_hwfn *p_hwfn,
4348 struct ecore_vf_info *vf_info;
4351 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4353 DP_NOTICE(p_hwfn->p_dev, true,
4354 "Can not set forced MAC, invalid vfid [%d]\n", vfid);
4357 if (vf_info->b_malicious) {
4358 DP_NOTICE(p_hwfn->p_dev, false,
4359 "Can't set forced MAC to malicious VF [%d]\n",
4364 feature = 1 << MAC_ADDR_FORCED;
4365 OSAL_MEMCPY(vf_info->bulletin.p_virt->mac, mac, ETH_ALEN);
4367 vf_info->bulletin.p_virt->valid_bitmap |= feature;
4368 /* Forced MAC will disable MAC_ADDR */
4369 vf_info->bulletin.p_virt->valid_bitmap &=
4370 ~(1 << VFPF_BULLETIN_MAC_ADDR);
4372 ecore_iov_configure_vport_forced(p_hwfn, vf_info, feature);
4375 enum _ecore_status_t ecore_iov_bulletin_set_mac(struct ecore_hwfn *p_hwfn,
4378 struct ecore_vf_info *vf_info;
4381 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4383 DP_NOTICE(p_hwfn->p_dev, true,
4384 "Can not set MAC, invalid vfid [%d]\n", vfid);
4387 if (vf_info->b_malicious) {
4388 DP_NOTICE(p_hwfn->p_dev, false,
4389 "Can't set MAC to malicious VF [%d]\n",
4394 if (vf_info->bulletin.p_virt->valid_bitmap & (1 << MAC_ADDR_FORCED)) {
4395 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
4396 "Can not set MAC, Forced MAC is configured\n");
4400 feature = 1 << VFPF_BULLETIN_MAC_ADDR;
4401 OSAL_MEMCPY(vf_info->bulletin.p_virt->mac, mac, ETH_ALEN);
4403 vf_info->bulletin.p_virt->valid_bitmap |= feature;
4405 return ECORE_SUCCESS;
4408 enum _ecore_status_t
4409 ecore_iov_bulletin_set_forced_untagged_default(struct ecore_hwfn *p_hwfn,
4410 bool b_untagged_only, int vfid)
4412 struct ecore_vf_info *vf_info;
4415 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4417 DP_NOTICE(p_hwfn->p_dev, true,
4418 "Can not set untagged default, invalid vfid [%d]\n",
4422 if (vf_info->b_malicious) {
4423 DP_NOTICE(p_hwfn->p_dev, false,
4424 "Can't set untagged default to malicious VF [%d]\n",
4429 /* Since this is configurable only during vport-start, don't take it
4430 * if we're past that point.
4432 if (vf_info->state == VF_ENABLED) {
4433 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
4434 "Can't support untagged change for vfid[%d] -"
4435 " VF is already active\n",
4440 /* Set configuration; This will later be taken into account during the
4441 * VF initialization.
4443 feature = (1 << VFPF_BULLETIN_UNTAGGED_DEFAULT) |
4444 (1 << VFPF_BULLETIN_UNTAGGED_DEFAULT_FORCED);
4445 vf_info->bulletin.p_virt->valid_bitmap |= feature;
4447 vf_info->bulletin.p_virt->default_only_untagged = b_untagged_only ? 1
4450 return ECORE_SUCCESS;
4453 void ecore_iov_get_vfs_opaque_fid(struct ecore_hwfn *p_hwfn, int vfid,
4456 struct ecore_vf_info *vf_info;
4458 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4462 *opaque_fid = vf_info->opaque_fid;
4465 void ecore_iov_bulletin_set_forced_vlan(struct ecore_hwfn *p_hwfn,
4468 struct ecore_vf_info *vf_info;
4471 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4473 DP_NOTICE(p_hwfn->p_dev, true,
4474 "Can not set forced MAC, invalid vfid [%d]\n",
4478 if (vf_info->b_malicious) {
4479 DP_NOTICE(p_hwfn->p_dev, false,
4480 "Can't set forced vlan to malicious VF [%d]\n",
4485 feature = 1 << VLAN_ADDR_FORCED;
4486 vf_info->bulletin.p_virt->pvid = pvid;
4488 vf_info->bulletin.p_virt->valid_bitmap |= feature;
4490 vf_info->bulletin.p_virt->valid_bitmap &= ~feature;
4492 ecore_iov_configure_vport_forced(p_hwfn, vf_info, feature);
4495 void ecore_iov_bulletin_set_udp_ports(struct ecore_hwfn *p_hwfn,
4496 int vfid, u16 vxlan_port, u16 geneve_port)
4498 struct ecore_vf_info *vf_info;
4500 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4502 DP_NOTICE(p_hwfn->p_dev, true,
4503 "Can not set udp ports, invalid vfid [%d]\n", vfid);
4507 if (vf_info->b_malicious) {
4508 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
4509 "Can not set udp ports to malicious VF [%d]\n",
4514 vf_info->bulletin.p_virt->vxlan_udp_port = vxlan_port;
4515 vf_info->bulletin.p_virt->geneve_udp_port = geneve_port;
4518 bool ecore_iov_vf_has_vport_instance(struct ecore_hwfn *p_hwfn, int vfid)
4520 struct ecore_vf_info *p_vf_info;
4522 p_vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4526 return !!p_vf_info->vport_instance;
4529 bool ecore_iov_is_vf_stopped(struct ecore_hwfn *p_hwfn, int vfid)
4531 struct ecore_vf_info *p_vf_info;
4533 p_vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4537 return p_vf_info->state == VF_STOPPED;
4540 bool ecore_iov_spoofchk_get(struct ecore_hwfn *p_hwfn, int vfid)
4542 struct ecore_vf_info *vf_info;
4544 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4548 return vf_info->spoof_chk;
4551 enum _ecore_status_t ecore_iov_spoofchk_set(struct ecore_hwfn *p_hwfn,
4554 struct ecore_vf_info *vf;
4555 enum _ecore_status_t rc = ECORE_INVAL;
4557 if (!ecore_iov_pf_sanity_check(p_hwfn, vfid)) {
4558 DP_NOTICE(p_hwfn, true,
4559 "SR-IOV sanity check failed, can't set spoofchk\n");
4563 vf = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4567 if (!ecore_iov_vf_has_vport_instance(p_hwfn, vfid)) {
4568 /* After VF VPORT start PF will configure spoof check */
4569 vf->req_spoofchk_val = val;
4574 rc = __ecore_iov_spoofchk_set(p_hwfn, vf, val);
4580 u8 ecore_iov_vf_chains_per_pf(struct ecore_hwfn *p_hwfn)
4582 u8 max_chains_per_vf = p_hwfn->hw_info.max_chains_per_vf;
4584 max_chains_per_vf = (max_chains_per_vf) ? max_chains_per_vf
4585 : ECORE_MAX_VF_CHAINS_PER_PF;
4587 return max_chains_per_vf;
4590 void ecore_iov_get_vf_req_virt_mbx_params(struct ecore_hwfn *p_hwfn,
4592 void **pp_req_virt_addr,
4593 u16 *p_req_virt_size)
4595 struct ecore_vf_info *vf_info =
4596 ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4601 if (pp_req_virt_addr)
4602 *pp_req_virt_addr = vf_info->vf_mbx.req_virt;
4604 if (p_req_virt_size)
4605 *p_req_virt_size = sizeof(*vf_info->vf_mbx.req_virt);
4608 void ecore_iov_get_vf_reply_virt_mbx_params(struct ecore_hwfn *p_hwfn,
4610 void **pp_reply_virt_addr,
4611 u16 *p_reply_virt_size)
4613 struct ecore_vf_info *vf_info =
4614 ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4619 if (pp_reply_virt_addr)
4620 *pp_reply_virt_addr = vf_info->vf_mbx.reply_virt;
4622 if (p_reply_virt_size)
4623 *p_reply_virt_size = sizeof(*vf_info->vf_mbx.reply_virt);
4626 #ifdef CONFIG_ECORE_SW_CHANNEL
4627 struct ecore_iov_sw_mbx *ecore_iov_get_vf_sw_mbx(struct ecore_hwfn *p_hwfn,
4630 struct ecore_vf_info *vf_info =
4631 ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4636 return &vf_info->vf_mbx.sw_mbx;
4640 bool ecore_iov_is_valid_vfpf_msg_length(u32 length)
4642 return (length >= sizeof(struct vfpf_first_tlv) &&
4643 (length <= sizeof(union vfpf_tlvs)));
4646 u32 ecore_iov_pfvf_msg_length(void)
4648 return sizeof(union pfvf_tlvs);
4651 u8 *ecore_iov_bulletin_get_forced_mac(struct ecore_hwfn *p_hwfn, u16 rel_vf_id)
4653 struct ecore_vf_info *p_vf;
4655 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4656 if (!p_vf || !p_vf->bulletin.p_virt)
4659 if (!(p_vf->bulletin.p_virt->valid_bitmap & (1 << MAC_ADDR_FORCED)))
4662 return p_vf->bulletin.p_virt->mac;
4665 u16 ecore_iov_bulletin_get_forced_vlan(struct ecore_hwfn *p_hwfn,
4668 struct ecore_vf_info *p_vf;
4670 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4671 if (!p_vf || !p_vf->bulletin.p_virt)
4674 if (!(p_vf->bulletin.p_virt->valid_bitmap & (1 << VLAN_ADDR_FORCED)))
4677 return p_vf->bulletin.p_virt->pvid;
4680 enum _ecore_status_t ecore_iov_configure_tx_rate(struct ecore_hwfn *p_hwfn,
4681 struct ecore_ptt *p_ptt,
4684 struct ecore_mcp_link_state *p_link;
4685 struct ecore_vf_info *vf;
4687 enum _ecore_status_t rc;
4689 vf = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4694 rc = ecore_fw_vport(p_hwfn, vf->vport_id, &abs_vp_id);
4695 if (rc != ECORE_SUCCESS)
4698 p_link = &ECORE_LEADING_HWFN(p_hwfn->p_dev)->mcp_info->link_output;
4700 return ecore_init_vport_rl(p_hwfn, p_ptt, abs_vp_id, (u32)val,
4704 enum _ecore_status_t ecore_iov_get_vf_stats(struct ecore_hwfn *p_hwfn,
4705 struct ecore_ptt *p_ptt,
4707 struct ecore_eth_stats *p_stats)
4709 struct ecore_vf_info *vf;
4711 vf = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4715 if (vf->state != VF_ENABLED)
4718 __ecore_get_vport_stats(p_hwfn, p_ptt, p_stats,
4719 vf->abs_vf_id + 0x10, false);
4721 return ECORE_SUCCESS;
4724 u8 ecore_iov_get_vf_num_rxqs(struct ecore_hwfn *p_hwfn, u16 rel_vf_id)
4726 struct ecore_vf_info *p_vf;
4728 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4732 return p_vf->num_rxqs;
4735 u8 ecore_iov_get_vf_num_active_rxqs(struct ecore_hwfn *p_hwfn, u16 rel_vf_id)
4737 struct ecore_vf_info *p_vf;
4739 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4743 return p_vf->num_active_rxqs;
4746 void *ecore_iov_get_vf_ctx(struct ecore_hwfn *p_hwfn, u16 rel_vf_id)
4748 struct ecore_vf_info *p_vf;
4750 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4757 u8 ecore_iov_get_vf_num_sbs(struct ecore_hwfn *p_hwfn, u16 rel_vf_id)
4759 struct ecore_vf_info *p_vf;
4761 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4765 return p_vf->num_sbs;
4768 bool ecore_iov_is_vf_wait_for_acquire(struct ecore_hwfn *p_hwfn, u16 rel_vf_id)
4770 struct ecore_vf_info *p_vf;
4772 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4776 return (p_vf->state == VF_FREE);
4779 bool ecore_iov_is_vf_acquired_not_initialized(struct ecore_hwfn *p_hwfn,
4782 struct ecore_vf_info *p_vf;
4784 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4788 return (p_vf->state == VF_ACQUIRED);
4791 bool ecore_iov_is_vf_initialized(struct ecore_hwfn *p_hwfn, u16 rel_vf_id)
4793 struct ecore_vf_info *p_vf;
4795 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4799 return (p_vf->state == VF_ENABLED);
4802 bool ecore_iov_is_vf_started(struct ecore_hwfn *p_hwfn,
4805 struct ecore_vf_info *p_vf;
4807 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4811 return (p_vf->state != VF_FREE && p_vf->state != VF_STOPPED);
4814 enum _ecore_status_t
4815 ecore_iov_get_vf_min_rate(struct ecore_hwfn *p_hwfn, int vfid)
4817 struct ecore_wfq_data *vf_vp_wfq;
4818 struct ecore_vf_info *vf_info;
4820 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4824 vf_vp_wfq = &p_hwfn->qm_info.wfq_data[vf_info->vport_id];
4826 if (vf_vp_wfq->configured)
4827 return vf_vp_wfq->min_speed;