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;
868 /* It's possible VF was previously considered malicious -
869 * clear the indication even if we're only going to disable VF.
871 vf->b_malicious = false;
874 return ECORE_SUCCESS;
876 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
877 "Enable internal access for vf %x [abs %x]\n", vf->abs_vf_id,
878 ECORE_VF_ABS_ID(p_hwfn, vf));
880 ecore_iov_vf_pglue_clear_err(p_hwfn, p_ptt,
881 ECORE_VF_ABS_ID(p_hwfn, vf));
883 ecore_iov_vf_igu_reset(p_hwfn, p_ptt, vf);
885 rc = ecore_iov_enable_vf_access_msix(p_hwfn, p_ptt,
886 vf->abs_vf_id, vf->num_sbs);
887 if (rc != ECORE_SUCCESS)
890 ecore_fid_pretend(p_hwfn, p_ptt, (u16)vf->concrete_fid);
892 SET_FIELD(igu_vf_conf, IGU_VF_CONF_PARENT, p_hwfn->rel_pf_id);
893 STORE_RT_REG(p_hwfn, IGU_REG_VF_CONFIGURATION_RT_OFFSET, igu_vf_conf);
895 ecore_init_run(p_hwfn, p_ptt, PHASE_VF, vf->abs_vf_id,
896 p_hwfn->hw_info.hw_mode);
899 ecore_fid_pretend(p_hwfn, p_ptt, (u16)p_hwfn->hw_info.concrete_fid);
908 * @brief ecore_iov_config_perm_table - configure the permission
910 * In E4, queue zone permission table size is 320x9. There
911 * are 320 VF queues for single engine device (256 for dual
912 * engine device), and each entry has the following format:
919 static void ecore_iov_config_perm_table(struct ecore_hwfn *p_hwfn,
920 struct ecore_ptt *p_ptt,
921 struct ecore_vf_info *vf, u8 enable)
927 for (qid = 0; qid < vf->num_rxqs; qid++) {
928 ecore_fw_l2_queue(p_hwfn, vf->vf_queues[qid].fw_rx_qid,
931 reg_addr = PSWHST_REG_ZONE_PERMISSION_TABLE + qzone_id * 4;
932 val = enable ? (vf->abs_vf_id | (1 << 8)) : 0;
933 ecore_wr(p_hwfn, p_ptt, reg_addr, val);
937 static void ecore_iov_enable_vf_traffic(struct ecore_hwfn *p_hwfn,
938 struct ecore_ptt *p_ptt,
939 struct ecore_vf_info *vf)
941 /* Reset vf in IGU - interrupts are still disabled */
942 ecore_iov_vf_igu_reset(p_hwfn, p_ptt, vf);
944 ecore_iov_vf_igu_set_int(p_hwfn, p_ptt, vf, 1);
946 /* Permission Table */
947 ecore_iov_config_perm_table(p_hwfn, p_ptt, vf, true);
950 static u8 ecore_iov_alloc_vf_igu_sbs(struct ecore_hwfn *p_hwfn,
951 struct ecore_ptt *p_ptt,
952 struct ecore_vf_info *vf,
955 struct ecore_igu_block *p_block;
956 struct cau_sb_entry sb_entry;
960 if (num_rx_queues > p_hwfn->hw_info.p_igu_info->usage.free_cnt_iov)
962 (u16)p_hwfn->hw_info.p_igu_info->usage.free_cnt_iov;
963 p_hwfn->hw_info.p_igu_info->usage.free_cnt_iov -= num_rx_queues;
965 SET_FIELD(val, IGU_MAPPING_LINE_FUNCTION_NUMBER, vf->abs_vf_id);
966 SET_FIELD(val, IGU_MAPPING_LINE_VALID, 1);
967 SET_FIELD(val, IGU_MAPPING_LINE_PF_VALID, 0);
969 for (qid = 0; qid < num_rx_queues; qid++) {
970 p_block = ecore_get_igu_free_sb(p_hwfn, false);
971 vf->igu_sbs[qid] = p_block->igu_sb_id;
972 p_block->status &= ~ECORE_IGU_STATUS_FREE;
973 SET_FIELD(val, IGU_MAPPING_LINE_VECTOR_NUMBER, qid);
975 ecore_wr(p_hwfn, p_ptt,
976 IGU_REG_MAPPING_MEMORY +
977 sizeof(u32) * p_block->igu_sb_id, val);
979 /* Configure igu sb in CAU which were marked valid */
980 ecore_init_cau_sb_entry(p_hwfn, &sb_entry,
983 ecore_dmae_host2grc(p_hwfn, p_ptt,
984 (u64)(osal_uintptr_t)&sb_entry,
985 CAU_REG_SB_VAR_MEMORY +
986 p_block->igu_sb_id * sizeof(u64), 2, 0);
989 vf->num_sbs = (u8)num_rx_queues;
996 * @brief The function invalidates all the VF entries,
997 * technically this isn't required, but added for
998 * cleaness and ease of debugging incase a VF attempts to
999 * produce an interrupt after it has been taken down.
1005 static void ecore_iov_free_vf_igu_sbs(struct ecore_hwfn *p_hwfn,
1006 struct ecore_ptt *p_ptt,
1007 struct ecore_vf_info *vf)
1009 struct ecore_igu_info *p_info = p_hwfn->hw_info.p_igu_info;
1013 /* Invalidate igu CAM lines and mark them as free */
1014 for (idx = 0; idx < vf->num_sbs; idx++) {
1015 igu_id = vf->igu_sbs[idx];
1016 addr = IGU_REG_MAPPING_MEMORY + sizeof(u32) * igu_id;
1018 val = ecore_rd(p_hwfn, p_ptt, addr);
1019 SET_FIELD(val, IGU_MAPPING_LINE_VALID, 0);
1020 ecore_wr(p_hwfn, p_ptt, addr, val);
1022 p_info->entry[igu_id].status |= ECORE_IGU_STATUS_FREE;
1023 p_hwfn->hw_info.p_igu_info->usage.free_cnt_iov++;
1029 void ecore_iov_set_link(struct ecore_hwfn *p_hwfn,
1031 struct ecore_mcp_link_params *params,
1032 struct ecore_mcp_link_state *link,
1033 struct ecore_mcp_link_capabilities *p_caps)
1035 struct ecore_vf_info *p_vf = ecore_iov_get_vf_info(p_hwfn, vfid, false);
1036 struct ecore_bulletin_content *p_bulletin;
1041 p_bulletin = p_vf->bulletin.p_virt;
1042 p_bulletin->req_autoneg = params->speed.autoneg;
1043 p_bulletin->req_adv_speed = params->speed.advertised_speeds;
1044 p_bulletin->req_forced_speed = params->speed.forced_speed;
1045 p_bulletin->req_autoneg_pause = params->pause.autoneg;
1046 p_bulletin->req_forced_rx = params->pause.forced_rx;
1047 p_bulletin->req_forced_tx = params->pause.forced_tx;
1048 p_bulletin->req_loopback = params->loopback_mode;
1050 p_bulletin->link_up = link->link_up;
1051 p_bulletin->speed = link->speed;
1052 p_bulletin->full_duplex = link->full_duplex;
1053 p_bulletin->autoneg = link->an;
1054 p_bulletin->autoneg_complete = link->an_complete;
1055 p_bulletin->parallel_detection = link->parallel_detection;
1056 p_bulletin->pfc_enabled = link->pfc_enabled;
1057 p_bulletin->partner_adv_speed = link->partner_adv_speed;
1058 p_bulletin->partner_tx_flow_ctrl_en = link->partner_tx_flow_ctrl_en;
1059 p_bulletin->partner_rx_flow_ctrl_en = link->partner_rx_flow_ctrl_en;
1060 p_bulletin->partner_adv_pause = link->partner_adv_pause;
1061 p_bulletin->sfp_tx_fault = link->sfp_tx_fault;
1063 p_bulletin->capability_speed = p_caps->speed_capabilities;
1066 enum _ecore_status_t
1067 ecore_iov_init_hw_for_vf(struct ecore_hwfn *p_hwfn,
1068 struct ecore_ptt *p_ptt,
1069 struct ecore_iov_vf_init_params *p_params)
1071 struct ecore_mcp_link_capabilities link_caps;
1072 struct ecore_mcp_link_params link_params;
1073 struct ecore_mcp_link_state link_state;
1074 u8 num_of_vf_available_chains = 0;
1075 struct ecore_vf_info *vf = OSAL_NULL;
1077 enum _ecore_status_t rc = ECORE_SUCCESS;
1081 vf = ecore_iov_get_vf_info(p_hwfn, p_params->rel_vf_id, false);
1083 DP_ERR(p_hwfn, "ecore_iov_init_hw_for_vf : vf is OSAL_NULL\n");
1084 return ECORE_UNKNOWN_ERROR;
1088 DP_NOTICE(p_hwfn, true, "VF[%d] is already active.\n",
1089 p_params->rel_vf_id);
1093 /* Perform sanity checking on the requested vport/rss */
1094 if (p_params->vport_id >= RESC_NUM(p_hwfn, ECORE_VPORT)) {
1095 DP_NOTICE(p_hwfn, true, "VF[%d] - can't use VPORT %02x\n",
1096 p_params->rel_vf_id, p_params->vport_id);
1100 if ((p_params->num_queues > 1) &&
1101 (p_params->rss_eng_id >= RESC_NUM(p_hwfn, ECORE_RSS_ENG))) {
1102 DP_NOTICE(p_hwfn, true, "VF[%d] - can't use RSS_ENG %02x\n",
1103 p_params->rel_vf_id, p_params->rss_eng_id);
1107 /* TODO - remove this once we get confidence of change */
1108 if (!p_params->vport_id) {
1109 DP_NOTICE(p_hwfn, false,
1110 "VF[%d] - Unlikely that VF uses vport0. Forgotten?\n",
1111 p_params->rel_vf_id);
1113 if ((!p_params->rss_eng_id) && (p_params->num_queues > 1)) {
1114 DP_NOTICE(p_hwfn, false,
1115 "VF[%d] - Unlikely that VF uses RSS_eng0. Forgotten?\n",
1116 p_params->rel_vf_id);
1118 vf->vport_id = p_params->vport_id;
1119 vf->rss_eng_id = p_params->rss_eng_id;
1121 /* Since it's possible to relocate SBs, it's a bit difficult to check
1122 * things here. Simply check whether the index falls in the range
1123 * belonging to the PF.
1125 for (i = 0; i < p_params->num_queues; i++) {
1126 qid = p_params->req_rx_queue[i];
1127 if (qid > (u16)RESC_NUM(p_hwfn, ECORE_L2_QUEUE)) {
1128 DP_NOTICE(p_hwfn, true,
1129 "Can't enable Rx qid [%04x] for VF[%d]: qids [0,,...,0x%04x] available\n",
1130 qid, p_params->rel_vf_id,
1131 (u16)RESC_NUM(p_hwfn, ECORE_L2_QUEUE));
1135 qid = p_params->req_tx_queue[i];
1136 if (qid > (u16)RESC_NUM(p_hwfn, ECORE_L2_QUEUE)) {
1137 DP_NOTICE(p_hwfn, true,
1138 "Can't enable Tx qid [%04x] for VF[%d]: qids [0,,...,0x%04x] available\n",
1139 qid, p_params->rel_vf_id,
1140 (u16)RESC_NUM(p_hwfn, ECORE_L2_QUEUE));
1145 /* Limit number of queues according to number of CIDs */
1146 ecore_cxt_get_proto_cid_count(p_hwfn, PROTOCOLID_ETH, &cids);
1147 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1148 "VF[%d] - requesting to initialize for 0x%04x queues"
1149 " [0x%04x CIDs available]\n",
1150 vf->relative_vf_id, p_params->num_queues, (u16)cids);
1151 num_irqs = OSAL_MIN_T(u16, p_params->num_queues, ((u16)cids));
1153 num_of_vf_available_chains = ecore_iov_alloc_vf_igu_sbs(p_hwfn,
1157 if (num_of_vf_available_chains == 0) {
1158 DP_ERR(p_hwfn, "no available igu sbs\n");
1162 /* Choose queue number and index ranges */
1163 vf->num_rxqs = num_of_vf_available_chains;
1164 vf->num_txqs = num_of_vf_available_chains;
1166 for (i = 0; i < vf->num_rxqs; i++) {
1167 struct ecore_vf_queue *p_queue = &vf->vf_queues[i];
1169 p_queue->fw_rx_qid = p_params->req_rx_queue[i];
1170 p_queue->fw_tx_qid = p_params->req_tx_queue[i];
1172 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1173 "VF[%d] - Q[%d] SB %04x, qid [Rx %04x Tx %04x]\n",
1174 vf->relative_vf_id, i, vf->igu_sbs[i],
1175 p_queue->fw_rx_qid, p_queue->fw_tx_qid);
1178 /* Update the link configuration in bulletin.
1180 OSAL_MEMCPY(&link_params, ecore_mcp_get_link_params(p_hwfn),
1181 sizeof(link_params));
1182 OSAL_MEMCPY(&link_state, ecore_mcp_get_link_state(p_hwfn),
1183 sizeof(link_state));
1184 OSAL_MEMCPY(&link_caps, ecore_mcp_get_link_capabilities(p_hwfn),
1186 ecore_iov_set_link(p_hwfn, p_params->rel_vf_id,
1187 &link_params, &link_state, &link_caps);
1189 rc = ecore_iov_enable_vf_access(p_hwfn, p_ptt, vf);
1191 if (rc == ECORE_SUCCESS) {
1193 p_hwfn->pf_iov_info->active_vfs[vf->relative_vf_id / 64] |=
1194 (1ULL << (vf->relative_vf_id % 64));
1196 if (IS_LEAD_HWFN(p_hwfn))
1197 p_hwfn->p_dev->p_iov_info->num_vfs++;
1203 enum _ecore_status_t ecore_iov_release_hw_for_vf(struct ecore_hwfn *p_hwfn,
1204 struct ecore_ptt *p_ptt,
1207 struct ecore_mcp_link_capabilities caps;
1208 struct ecore_mcp_link_params params;
1209 struct ecore_mcp_link_state link;
1210 struct ecore_vf_info *vf = OSAL_NULL;
1212 vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
1214 DP_ERR(p_hwfn, "ecore_iov_release_hw_for_vf : vf is NULL\n");
1215 return ECORE_UNKNOWN_ERROR;
1218 if (vf->bulletin.p_virt)
1219 OSAL_MEMSET(vf->bulletin.p_virt, 0,
1220 sizeof(*vf->bulletin.p_virt));
1222 OSAL_MEMSET(&vf->p_vf_info, 0, sizeof(vf->p_vf_info));
1224 /* Get the link configuration back in bulletin so
1225 * that when VFs are re-enabled they get the actual
1226 * link configuration.
1228 OSAL_MEMCPY(¶ms, ecore_mcp_get_link_params(p_hwfn), sizeof(params));
1229 OSAL_MEMCPY(&link, ecore_mcp_get_link_state(p_hwfn), sizeof(link));
1230 OSAL_MEMCPY(&caps, ecore_mcp_get_link_capabilities(p_hwfn),
1232 ecore_iov_set_link(p_hwfn, rel_vf_id, ¶ms, &link, &caps);
1234 /* Forget the VF's acquisition message */
1235 OSAL_MEMSET(&vf->acquire, 0, sizeof(vf->acquire));
1237 /* disablng interrupts and resetting permission table was done during
1238 * vf-close, however, we could get here without going through vf_close
1240 /* Disable Interrupts for VF */
1241 ecore_iov_vf_igu_set_int(p_hwfn, p_ptt, vf, 0);
1243 /* Reset Permission table */
1244 ecore_iov_config_perm_table(p_hwfn, p_ptt, vf, 0);
1248 ecore_iov_free_vf_igu_sbs(p_hwfn, p_ptt, vf);
1252 p_hwfn->pf_iov_info->active_vfs[vf->relative_vf_id / 64] &=
1253 ~(1ULL << (vf->relative_vf_id / 64));
1255 if (IS_LEAD_HWFN(p_hwfn))
1256 p_hwfn->p_dev->p_iov_info->num_vfs--;
1259 return ECORE_SUCCESS;
1262 static bool ecore_iov_tlv_supported(u16 tlvtype)
1264 return tlvtype > CHANNEL_TLV_NONE && tlvtype < CHANNEL_TLV_MAX;
1267 static void ecore_iov_lock_vf_pf_channel(struct ecore_hwfn *p_hwfn,
1268 struct ecore_vf_info *vf, u16 tlv)
1270 /* lock the channel */
1271 /* mutex_lock(&vf->op_mutex); @@@TBD MichalK - add lock... */
1273 /* record the locking op */
1274 /* vf->op_current = tlv; @@@TBD MichalK */
1277 if (ecore_iov_tlv_supported(tlv))
1280 "VF[%d]: vf pf channel locked by %s\n",
1282 ecore_channel_tlvs_string[tlv]);
1286 "VF[%d]: vf pf channel locked by %04x\n",
1287 vf->abs_vf_id, tlv);
1290 static void ecore_iov_unlock_vf_pf_channel(struct ecore_hwfn *p_hwfn,
1291 struct ecore_vf_info *vf,
1294 /* log the unlock */
1295 if (ecore_iov_tlv_supported(expected_tlv))
1298 "VF[%d]: vf pf channel unlocked by %s\n",
1300 ecore_channel_tlvs_string[expected_tlv]);
1304 "VF[%d]: vf pf channel unlocked by %04x\n",
1305 vf->abs_vf_id, expected_tlv);
1307 /* record the locking op */
1308 /* vf->op_current = CHANNEL_TLV_NONE; */
1311 /* place a given tlv on the tlv buffer, continuing current tlv list */
1312 void *ecore_add_tlv(u8 **offset, u16 type, u16 length)
1314 struct channel_tlv *tl = (struct channel_tlv *)*offset;
1317 tl->length = length;
1319 /* Offset should keep pointing to next TLV (the end of the last) */
1322 /* Return a pointer to the start of the added tlv */
1323 return *offset - length;
1326 /* list the types and lengths of the tlvs on the buffer */
1327 void ecore_dp_tlv_list(struct ecore_hwfn *p_hwfn, void *tlvs_list)
1329 u16 i = 1, total_length = 0;
1330 struct channel_tlv *tlv;
1333 /* cast current tlv list entry to channel tlv header */
1334 tlv = (struct channel_tlv *)((u8 *)tlvs_list + total_length);
1337 if (ecore_iov_tlv_supported(tlv->type))
1338 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1339 "TLV number %d: type %s, length %d\n",
1340 i, ecore_channel_tlvs_string[tlv->type],
1343 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1344 "TLV number %d: type %d, length %d\n",
1345 i, tlv->type, tlv->length);
1347 if (tlv->type == CHANNEL_TLV_LIST_END)
1350 /* Validate entry - protect against malicious VFs */
1352 DP_NOTICE(p_hwfn, false, "TLV of length 0 found\n");
1355 total_length += tlv->length;
1356 if (total_length >= sizeof(struct tlv_buffer_size)) {
1357 DP_NOTICE(p_hwfn, false, "TLV ==> Buffer overflow\n");
1365 static void ecore_iov_send_response(struct ecore_hwfn *p_hwfn,
1366 struct ecore_ptt *p_ptt,
1367 struct ecore_vf_info *p_vf,
1368 #ifdef CONFIG_ECORE_SW_CHANNEL
1371 u16 OSAL_UNUSED length,
1375 struct ecore_iov_vf_mbx *mbx = &p_vf->vf_mbx;
1376 struct ecore_dmae_params params;
1379 mbx->reply_virt->default_resp.hdr.status = status;
1381 ecore_dp_tlv_list(p_hwfn, mbx->reply_virt);
1383 #ifdef CONFIG_ECORE_SW_CHANNEL
1384 mbx->sw_mbx.response_size =
1385 length + sizeof(struct channel_list_end_tlv);
1387 if (!p_vf->b_hw_channel)
1391 eng_vf_id = p_vf->abs_vf_id;
1393 OSAL_MEMSET(¶ms, 0, sizeof(struct ecore_dmae_params));
1394 params.flags = ECORE_DMAE_FLAG_VF_DST;
1395 params.dst_vfid = eng_vf_id;
1397 ecore_dmae_host2host(p_hwfn, p_ptt, mbx->reply_phys + sizeof(u64),
1398 mbx->req_virt->first_tlv.reply_address +
1400 (sizeof(union pfvf_tlvs) - sizeof(u64)) / 4,
1403 /* Once PF copies the rc to the VF, the latter can continue and
1404 * and send an additional message. So we have to make sure the
1405 * channel would be re-set to ready prior to that.
1408 GTT_BAR0_MAP_REG_USDM_RAM +
1409 USTORM_VF_PF_CHANNEL_READY_OFFSET(eng_vf_id), 1);
1411 ecore_dmae_host2host(p_hwfn, p_ptt, mbx->reply_phys,
1412 mbx->req_virt->first_tlv.reply_address,
1413 sizeof(u64) / 4, ¶ms);
1415 OSAL_IOV_PF_RESP_TYPE(p_hwfn, p_vf->relative_vf_id, status);
1418 static u16 ecore_iov_vport_to_tlv(enum ecore_iov_vport_update_flag flag)
1421 case ECORE_IOV_VP_UPDATE_ACTIVATE:
1422 return CHANNEL_TLV_VPORT_UPDATE_ACTIVATE;
1423 case ECORE_IOV_VP_UPDATE_VLAN_STRIP:
1424 return CHANNEL_TLV_VPORT_UPDATE_VLAN_STRIP;
1425 case ECORE_IOV_VP_UPDATE_TX_SWITCH:
1426 return CHANNEL_TLV_VPORT_UPDATE_TX_SWITCH;
1427 case ECORE_IOV_VP_UPDATE_MCAST:
1428 return CHANNEL_TLV_VPORT_UPDATE_MCAST;
1429 case ECORE_IOV_VP_UPDATE_ACCEPT_PARAM:
1430 return CHANNEL_TLV_VPORT_UPDATE_ACCEPT_PARAM;
1431 case ECORE_IOV_VP_UPDATE_RSS:
1432 return CHANNEL_TLV_VPORT_UPDATE_RSS;
1433 case ECORE_IOV_VP_UPDATE_ACCEPT_ANY_VLAN:
1434 return CHANNEL_TLV_VPORT_UPDATE_ACCEPT_ANY_VLAN;
1435 case ECORE_IOV_VP_UPDATE_SGE_TPA:
1436 return CHANNEL_TLV_VPORT_UPDATE_SGE_TPA;
1442 static u16 ecore_iov_prep_vp_update_resp_tlvs(struct ecore_hwfn *p_hwfn,
1443 struct ecore_vf_info *p_vf,
1444 struct ecore_iov_vf_mbx *p_mbx,
1445 u8 status, u16 tlvs_mask,
1448 struct pfvf_def_resp_tlv *resp;
1449 u16 size, total_len, i;
1451 OSAL_MEMSET(p_mbx->reply_virt, 0, sizeof(union pfvf_tlvs));
1452 p_mbx->offset = (u8 *)p_mbx->reply_virt;
1453 size = sizeof(struct pfvf_def_resp_tlv);
1456 ecore_add_tlv(&p_mbx->offset, CHANNEL_TLV_VPORT_UPDATE, size);
1458 /* Prepare response for all extended tlvs if they are found by PF */
1459 for (i = 0; i < ECORE_IOV_VP_UPDATE_MAX; i++) {
1460 if (!(tlvs_mask & (1 << i)))
1463 resp = ecore_add_tlv(&p_mbx->offset, ecore_iov_vport_to_tlv(i),
1466 if (tlvs_accepted & (1 << i))
1467 resp->hdr.status = status;
1469 resp->hdr.status = PFVF_STATUS_NOT_SUPPORTED;
1471 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1472 "VF[%d] - vport_update resp: TLV %d, status %02x\n",
1473 p_vf->relative_vf_id,
1474 ecore_iov_vport_to_tlv(i),
1480 ecore_add_tlv(&p_mbx->offset, CHANNEL_TLV_LIST_END,
1481 sizeof(struct channel_list_end_tlv));
1486 static void ecore_iov_prepare_resp(struct ecore_hwfn *p_hwfn,
1487 struct ecore_ptt *p_ptt,
1488 struct ecore_vf_info *vf_info,
1489 u16 type, u16 length, u8 status)
1491 struct ecore_iov_vf_mbx *mbx = &vf_info->vf_mbx;
1493 mbx->offset = (u8 *)mbx->reply_virt;
1495 ecore_add_tlv(&mbx->offset, type, length);
1496 ecore_add_tlv(&mbx->offset, CHANNEL_TLV_LIST_END,
1497 sizeof(struct channel_list_end_tlv));
1499 ecore_iov_send_response(p_hwfn, p_ptt, vf_info, length, status);
1502 struct ecore_public_vf_info
1503 *ecore_iov_get_public_vf_info(struct ecore_hwfn *p_hwfn,
1505 bool b_enabled_only)
1507 struct ecore_vf_info *vf = OSAL_NULL;
1509 vf = ecore_iov_get_vf_info(p_hwfn, relative_vf_id, b_enabled_only);
1513 return &vf->p_vf_info;
1516 static void ecore_iov_vf_cleanup(struct ecore_hwfn *p_hwfn,
1517 struct ecore_vf_info *p_vf)
1520 p_vf->vf_bulletin = 0;
1521 p_vf->vport_instance = 0;
1522 p_vf->configured_features = 0;
1524 /* If VF previously requested less resources, go back to default */
1525 p_vf->num_rxqs = p_vf->num_sbs;
1526 p_vf->num_txqs = p_vf->num_sbs;
1528 p_vf->num_active_rxqs = 0;
1530 for (i = 0; i < ECORE_MAX_VF_CHAINS_PER_PF; i++) {
1531 struct ecore_vf_queue *p_queue = &p_vf->vf_queues[i];
1533 for (j = 0; j < MAX_QUEUES_PER_QZONE; j++) {
1534 if (!p_queue->cids[j].p_cid)
1537 ecore_eth_queue_cid_release(p_hwfn,
1538 p_queue->cids[j].p_cid);
1539 p_queue->cids[j].p_cid = OSAL_NULL;
1543 OSAL_MEMSET(&p_vf->shadow_config, 0, sizeof(p_vf->shadow_config));
1544 OSAL_MEMSET(&p_vf->acquire, 0, sizeof(p_vf->acquire));
1545 OSAL_IOV_VF_CLEANUP(p_hwfn, p_vf->relative_vf_id);
1548 /* Returns either 0, or log(size) */
1549 static u32 ecore_iov_vf_db_bar_size(struct ecore_hwfn *p_hwfn,
1550 struct ecore_ptt *p_ptt)
1552 u32 val = ecore_rd(p_hwfn, p_ptt, PGLUE_B_REG_VF_BAR1_SIZE);
1560 ecore_iov_vf_mbx_acquire_resc_cids(struct ecore_hwfn *p_hwfn,
1561 struct ecore_ptt *p_ptt,
1562 struct ecore_vf_info *p_vf,
1563 struct vf_pf_resc_request *p_req,
1564 struct pf_vf_resc *p_resp)
1566 u8 num_vf_cons = p_hwfn->pf_params.eth_pf_params.num_vf_cons;
1567 u8 db_size = DB_ADDR_VF(1, DQ_DEMS_LEGACY) -
1568 DB_ADDR_VF(0, DQ_DEMS_LEGACY);
1571 p_resp->num_cids = OSAL_MIN_T(u8, p_req->num_cids, num_vf_cons);
1573 /* If VF didn't bother asking for QIDs than don't bother limiting
1574 * number of CIDs. The VF doesn't care about the number, and this
1575 * has the likely result of causing an additional acquisition.
1577 if (!(p_vf->acquire.vfdev_info.capabilities &
1578 VFPF_ACQUIRE_CAP_QUEUE_QIDS))
1581 /* If doorbell bar was mapped by VF, limit the VF CIDs to an amount
1582 * that would make sure doorbells for all CIDs fall within the bar.
1583 * If it doesn't, make sure regview window is sufficient.
1585 if (p_vf->acquire.vfdev_info.capabilities &
1586 VFPF_ACQUIRE_CAP_PHYSICAL_BAR) {
1587 bar_size = ecore_iov_vf_db_bar_size(p_hwfn, p_ptt);
1589 bar_size = 1 << bar_size;
1591 if (ECORE_IS_CMT(p_hwfn->p_dev))
1594 bar_size = PXP_VF_BAR0_DQ_LENGTH;
1597 if (bar_size / db_size < 256)
1598 p_resp->num_cids = OSAL_MIN_T(u8, p_resp->num_cids,
1599 (u8)(bar_size / db_size));
1602 static u8 ecore_iov_vf_mbx_acquire_resc(struct ecore_hwfn *p_hwfn,
1603 struct ecore_ptt *p_ptt,
1604 struct ecore_vf_info *p_vf,
1605 struct vf_pf_resc_request *p_req,
1606 struct pf_vf_resc *p_resp)
1610 /* Queue related information */
1611 p_resp->num_rxqs = p_vf->num_rxqs;
1612 p_resp->num_txqs = p_vf->num_txqs;
1613 p_resp->num_sbs = p_vf->num_sbs;
1615 for (i = 0; i < p_resp->num_sbs; i++) {
1616 p_resp->hw_sbs[i].hw_sb_id = p_vf->igu_sbs[i];
1617 /* TODO - what's this sb_qid field? Is it deprecated?
1618 * or is there an ecore_client that looks at this?
1620 p_resp->hw_sbs[i].sb_qid = 0;
1623 /* These fields are filled for backward compatibility.
1624 * Unused by modern vfs.
1626 for (i = 0; i < p_resp->num_rxqs; i++) {
1627 ecore_fw_l2_queue(p_hwfn, p_vf->vf_queues[i].fw_rx_qid,
1628 (u16 *)&p_resp->hw_qid[i]);
1632 /* Filter related information */
1633 p_resp->num_mac_filters = OSAL_MIN_T(u8, p_vf->num_mac_filters,
1634 p_req->num_mac_filters);
1635 p_resp->num_vlan_filters = OSAL_MIN_T(u8, p_vf->num_vlan_filters,
1636 p_req->num_vlan_filters);
1638 ecore_iov_vf_mbx_acquire_resc_cids(p_hwfn, p_ptt, p_vf, p_req, p_resp);
1640 /* This isn't really needed/enforced, but some legacy VFs might depend
1641 * on the correct filling of this field.
1643 p_resp->num_mc_filters = ECORE_MAX_MC_ADDRS;
1645 /* Validate sufficient resources for VF */
1646 if (p_resp->num_rxqs < p_req->num_rxqs ||
1647 p_resp->num_txqs < p_req->num_txqs ||
1648 p_resp->num_sbs < p_req->num_sbs ||
1649 p_resp->num_mac_filters < p_req->num_mac_filters ||
1650 p_resp->num_vlan_filters < p_req->num_vlan_filters ||
1651 p_resp->num_mc_filters < p_req->num_mc_filters ||
1652 p_resp->num_cids < p_req->num_cids) {
1653 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1654 "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",
1656 p_req->num_rxqs, p_resp->num_rxqs,
1657 p_req->num_rxqs, p_resp->num_txqs,
1658 p_req->num_sbs, p_resp->num_sbs,
1659 p_req->num_mac_filters, p_resp->num_mac_filters,
1660 p_req->num_vlan_filters, p_resp->num_vlan_filters,
1661 p_req->num_mc_filters, p_resp->num_mc_filters,
1662 p_req->num_cids, p_resp->num_cids);
1664 /* Some legacy OSes are incapable of correctly handling this
1667 if ((p_vf->acquire.vfdev_info.eth_fp_hsi_minor ==
1668 ETH_HSI_VER_NO_PKT_LEN_TUNN) &&
1669 (p_vf->acquire.vfdev_info.os_type ==
1670 VFPF_ACQUIRE_OS_WINDOWS))
1671 return PFVF_STATUS_SUCCESS;
1673 return PFVF_STATUS_NO_RESOURCE;
1676 return PFVF_STATUS_SUCCESS;
1679 static void ecore_iov_vf_mbx_acquire_stats(struct pfvf_stats_info *p_stats)
1681 p_stats->mstats.address = PXP_VF_BAR0_START_MSDM_ZONE_B +
1682 OFFSETOF(struct mstorm_vf_zone,
1683 non_trigger.eth_queue_stat);
1684 p_stats->mstats.len = sizeof(struct eth_mstorm_per_queue_stat);
1685 p_stats->ustats.address = PXP_VF_BAR0_START_USDM_ZONE_B +
1686 OFFSETOF(struct ustorm_vf_zone,
1687 non_trigger.eth_queue_stat);
1688 p_stats->ustats.len = sizeof(struct eth_ustorm_per_queue_stat);
1689 p_stats->pstats.address = PXP_VF_BAR0_START_PSDM_ZONE_B +
1690 OFFSETOF(struct pstorm_vf_zone,
1691 non_trigger.eth_queue_stat);
1692 p_stats->pstats.len = sizeof(struct eth_pstorm_per_queue_stat);
1693 p_stats->tstats.address = 0;
1694 p_stats->tstats.len = 0;
1697 static void ecore_iov_vf_mbx_acquire(struct ecore_hwfn *p_hwfn,
1698 struct ecore_ptt *p_ptt,
1699 struct ecore_vf_info *vf)
1701 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
1702 struct pfvf_acquire_resp_tlv *resp = &mbx->reply_virt->acquire_resp;
1703 struct pf_vf_pfdev_info *pfdev_info = &resp->pfdev_info;
1704 struct vfpf_acquire_tlv *req = &mbx->req_virt->acquire;
1705 u8 vfpf_status = PFVF_STATUS_NOT_SUPPORTED;
1706 struct pf_vf_resc *resc = &resp->resc;
1707 enum _ecore_status_t rc;
1709 OSAL_MEMSET(resp, 0, sizeof(*resp));
1711 /* Write the PF version so that VF would know which version
1712 * is supported - might be later overridden. This guarantees that
1713 * VF could recognize legacy PF based on lack of versions in reply.
1715 pfdev_info->major_fp_hsi = ETH_HSI_VER_MAJOR;
1716 pfdev_info->minor_fp_hsi = ETH_HSI_VER_MINOR;
1718 /* TODO - not doing anything is bad since we'll assert, but this isn't
1719 * necessarily the right behavior - perhaps we should have allowed some
1722 if (vf->state != VF_FREE &&
1723 vf->state != VF_STOPPED) {
1724 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1725 "VF[%d] sent ACQUIRE but is already in state %d - fail request\n",
1726 vf->abs_vf_id, vf->state);
1730 /* Validate FW compatibility */
1731 if (req->vfdev_info.eth_fp_hsi_major != ETH_HSI_VER_MAJOR) {
1732 if (req->vfdev_info.capabilities &
1733 VFPF_ACQUIRE_CAP_PRE_FP_HSI) {
1734 struct vf_pf_vfdev_info *p_vfdev = &req->vfdev_info;
1736 /* This legacy support would need to be removed once
1737 * the major has changed.
1739 OSAL_BUILD_BUG_ON(ETH_HSI_VER_MAJOR != 3);
1741 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1742 "VF[%d] is pre-fastpath HSI\n",
1744 p_vfdev->eth_fp_hsi_major = ETH_HSI_VER_MAJOR;
1745 p_vfdev->eth_fp_hsi_minor = ETH_HSI_VER_NO_PKT_LEN_TUNN;
1748 "VF[%d] needs fastpath HSI %02x.%02x, which is"
1749 " incompatible with loaded FW's faspath"
1752 req->vfdev_info.eth_fp_hsi_major,
1753 req->vfdev_info.eth_fp_hsi_minor,
1754 ETH_HSI_VER_MAJOR, ETH_HSI_VER_MINOR);
1760 /* On 100g PFs, prevent old VFs from loading */
1761 if (ECORE_IS_CMT(p_hwfn->p_dev) &&
1762 !(req->vfdev_info.capabilities & VFPF_ACQUIRE_CAP_100G)) {
1764 "VF[%d] is running an old driver that doesn't support"
1770 #ifndef __EXTRACT__LINUX__
1771 if (OSAL_IOV_VF_ACQUIRE(p_hwfn, vf->relative_vf_id) != ECORE_SUCCESS) {
1772 vfpf_status = PFVF_STATUS_NOT_SUPPORTED;
1777 /* Store the acquire message */
1778 OSAL_MEMCPY(&vf->acquire, req, sizeof(vf->acquire));
1780 vf->opaque_fid = req->vfdev_info.opaque_fid;
1782 vf->vf_bulletin = req->bulletin_addr;
1783 vf->bulletin.size = (vf->bulletin.size < req->bulletin_size) ?
1784 vf->bulletin.size : req->bulletin_size;
1786 /* fill in pfdev info */
1787 pfdev_info->chip_num = p_hwfn->p_dev->chip_num;
1788 pfdev_info->db_size = 0; /* @@@ TBD MichalK Vf Doorbells */
1789 pfdev_info->indices_per_sb = PIS_PER_SB_E4;
1791 pfdev_info->capabilities = PFVF_ACQUIRE_CAP_DEFAULT_UNTAGGED |
1792 PFVF_ACQUIRE_CAP_POST_FW_OVERRIDE;
1793 if (ECORE_IS_CMT(p_hwfn->p_dev))
1794 pfdev_info->capabilities |= PFVF_ACQUIRE_CAP_100G;
1796 /* Share our ability to use multiple queue-ids only with VFs
1799 if (req->vfdev_info.capabilities & VFPF_ACQUIRE_CAP_QUEUE_QIDS)
1800 pfdev_info->capabilities |= PFVF_ACQUIRE_CAP_QUEUE_QIDS;
1802 /* Share the sizes of the bars with VF */
1803 resp->pfdev_info.bar_size = (u8)ecore_iov_vf_db_bar_size(p_hwfn,
1806 ecore_iov_vf_mbx_acquire_stats(&pfdev_info->stats_info);
1808 OSAL_MEMCPY(pfdev_info->port_mac, p_hwfn->hw_info.hw_mac_addr,
1811 pfdev_info->fw_major = FW_MAJOR_VERSION;
1812 pfdev_info->fw_minor = FW_MINOR_VERSION;
1813 pfdev_info->fw_rev = FW_REVISION_VERSION;
1814 pfdev_info->fw_eng = FW_ENGINEERING_VERSION;
1816 /* Incorrect when legacy, but doesn't matter as legacy isn't reading
1819 pfdev_info->minor_fp_hsi = OSAL_MIN_T(u8, ETH_HSI_VER_MINOR,
1820 req->vfdev_info.eth_fp_hsi_minor);
1821 pfdev_info->os_type = OSAL_IOV_GET_OS_TYPE();
1822 ecore_mcp_get_mfw_ver(p_hwfn, p_ptt, &pfdev_info->mfw_ver,
1825 pfdev_info->dev_type = p_hwfn->p_dev->type;
1826 pfdev_info->chip_rev = p_hwfn->p_dev->chip_rev;
1828 /* Fill resources available to VF; Make sure there are enough to
1829 * satisfy the VF's request.
1831 vfpf_status = ecore_iov_vf_mbx_acquire_resc(p_hwfn, p_ptt, vf,
1832 &req->resc_request, resc);
1833 if (vfpf_status != PFVF_STATUS_SUCCESS)
1836 /* Start the VF in FW */
1837 rc = ecore_sp_vf_start(p_hwfn, vf);
1838 if (rc != ECORE_SUCCESS) {
1839 DP_NOTICE(p_hwfn, true, "Failed to start VF[%02x]\n",
1841 vfpf_status = PFVF_STATUS_FAILURE;
1845 /* Fill agreed size of bulletin board in response, and post
1846 * an initial image to the bulletin board.
1848 resp->bulletin_size = vf->bulletin.size;
1849 ecore_iov_post_vf_bulletin(p_hwfn, vf->relative_vf_id, p_ptt);
1851 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1852 "VF[%d] ACQUIRE_RESPONSE: pfdev_info- chip_num=0x%x,"
1853 " db_size=%d, idx_per_sb=%d, pf_cap=0x%lx\n"
1854 "resources- n_rxq-%d, n_txq-%d, n_sbs-%d, n_macs-%d,"
1856 vf->abs_vf_id, resp->pfdev_info.chip_num,
1857 resp->pfdev_info.db_size, resp->pfdev_info.indices_per_sb,
1858 (unsigned long)resp->pfdev_info.capabilities, resc->num_rxqs,
1859 resc->num_txqs, resc->num_sbs, resc->num_mac_filters,
1860 resc->num_vlan_filters);
1862 vf->state = VF_ACQUIRED;
1865 /* Prepare Response */
1866 ecore_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_ACQUIRE,
1867 sizeof(struct pfvf_acquire_resp_tlv),
1871 static enum _ecore_status_t
1872 __ecore_iov_spoofchk_set(struct ecore_hwfn *p_hwfn,
1873 struct ecore_vf_info *p_vf, bool val)
1875 struct ecore_sp_vport_update_params params;
1876 enum _ecore_status_t rc;
1878 if (val == p_vf->spoof_chk) {
1879 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1880 "Spoofchk value[%d] is already configured\n", val);
1881 return ECORE_SUCCESS;
1884 OSAL_MEMSET(¶ms, 0, sizeof(struct ecore_sp_vport_update_params));
1885 params.opaque_fid = p_vf->opaque_fid;
1886 params.vport_id = p_vf->vport_id;
1887 params.update_anti_spoofing_en_flg = 1;
1888 params.anti_spoofing_en = val;
1890 rc = ecore_sp_vport_update(p_hwfn, ¶ms, ECORE_SPQ_MODE_EBLOCK,
1892 if (rc == ECORE_SUCCESS) {
1893 p_vf->spoof_chk = val;
1894 p_vf->req_spoofchk_val = p_vf->spoof_chk;
1895 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1896 "Spoofchk val[%d] configured\n", val);
1898 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1899 "Spoofchk configuration[val:%d] failed for VF[%d]\n",
1900 val, p_vf->relative_vf_id);
1906 static enum _ecore_status_t
1907 ecore_iov_reconfigure_unicast_vlan(struct ecore_hwfn *p_hwfn,
1908 struct ecore_vf_info *p_vf)
1910 struct ecore_filter_ucast filter;
1911 enum _ecore_status_t rc = ECORE_SUCCESS;
1914 OSAL_MEMSET(&filter, 0, sizeof(filter));
1915 filter.is_rx_filter = 1;
1916 filter.is_tx_filter = 1;
1917 filter.vport_to_add_to = p_vf->vport_id;
1918 filter.opcode = ECORE_FILTER_ADD;
1920 /* Reconfigure vlans */
1921 for (i = 0; i < ECORE_ETH_VF_NUM_VLAN_FILTERS + 1; i++) {
1922 if (!p_vf->shadow_config.vlans[i].used)
1925 filter.type = ECORE_FILTER_VLAN;
1926 filter.vlan = p_vf->shadow_config.vlans[i].vid;
1927 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1928 "Reconfiguring VLAN [0x%04x] for VF [%04x]\n",
1929 filter.vlan, p_vf->relative_vf_id);
1930 rc = ecore_sp_eth_filter_ucast(p_hwfn, p_vf->opaque_fid,
1931 &filter, ECORE_SPQ_MODE_CB,
1934 DP_NOTICE(p_hwfn, true,
1935 "Failed to configure VLAN [%04x]"
1937 filter.vlan, p_vf->relative_vf_id);
1945 static enum _ecore_status_t
1946 ecore_iov_reconfigure_unicast_shadow(struct ecore_hwfn *p_hwfn,
1947 struct ecore_vf_info *p_vf, u64 events)
1949 enum _ecore_status_t rc = ECORE_SUCCESS;
1951 /*TODO - what about MACs? */
1953 if ((events & (1 << VLAN_ADDR_FORCED)) &&
1954 !(p_vf->configured_features & (1 << VLAN_ADDR_FORCED)))
1955 rc = ecore_iov_reconfigure_unicast_vlan(p_hwfn, p_vf);
1960 static enum _ecore_status_t
1961 ecore_iov_configure_vport_forced(struct ecore_hwfn *p_hwfn,
1962 struct ecore_vf_info *p_vf,
1965 enum _ecore_status_t rc = ECORE_SUCCESS;
1966 struct ecore_filter_ucast filter;
1968 if (!p_vf->vport_instance)
1971 if (events & (1 << MAC_ADDR_FORCED)) {
1972 /* Since there's no way [currently] of removing the MAC,
1973 * we can always assume this means we need to force it.
1975 OSAL_MEMSET(&filter, 0, sizeof(filter));
1976 filter.type = ECORE_FILTER_MAC;
1977 filter.opcode = ECORE_FILTER_REPLACE;
1978 filter.is_rx_filter = 1;
1979 filter.is_tx_filter = 1;
1980 filter.vport_to_add_to = p_vf->vport_id;
1981 OSAL_MEMCPY(filter.mac, p_vf->bulletin.p_virt->mac, ETH_ALEN);
1983 rc = ecore_sp_eth_filter_ucast(p_hwfn, p_vf->opaque_fid,
1985 ECORE_SPQ_MODE_CB, OSAL_NULL);
1987 DP_NOTICE(p_hwfn, true,
1988 "PF failed to configure MAC for VF\n");
1992 p_vf->configured_features |= 1 << MAC_ADDR_FORCED;
1995 if (events & (1 << VLAN_ADDR_FORCED)) {
1996 struct ecore_sp_vport_update_params vport_update;
2000 OSAL_MEMSET(&filter, 0, sizeof(filter));
2001 filter.type = ECORE_FILTER_VLAN;
2002 filter.is_rx_filter = 1;
2003 filter.is_tx_filter = 1;
2004 filter.vport_to_add_to = p_vf->vport_id;
2005 filter.vlan = p_vf->bulletin.p_virt->pvid;
2006 filter.opcode = filter.vlan ? ECORE_FILTER_REPLACE :
2009 /* Send the ramrod */
2010 rc = ecore_sp_eth_filter_ucast(p_hwfn, p_vf->opaque_fid,
2012 ECORE_SPQ_MODE_CB, OSAL_NULL);
2014 DP_NOTICE(p_hwfn, true,
2015 "PF failed to configure VLAN for VF\n");
2019 /* Update the default-vlan & silent vlan stripping */
2020 OSAL_MEMSET(&vport_update, 0, sizeof(vport_update));
2021 vport_update.opaque_fid = p_vf->opaque_fid;
2022 vport_update.vport_id = p_vf->vport_id;
2023 vport_update.update_default_vlan_enable_flg = 1;
2024 vport_update.default_vlan_enable_flg = filter.vlan ? 1 : 0;
2025 vport_update.update_default_vlan_flg = 1;
2026 vport_update.default_vlan = filter.vlan;
2028 vport_update.update_inner_vlan_removal_flg = 1;
2029 removal = filter.vlan ?
2030 1 : p_vf->shadow_config.inner_vlan_removal;
2031 vport_update.inner_vlan_removal_flg = removal;
2032 vport_update.silent_vlan_removal_flg = filter.vlan ? 1 : 0;
2033 rc = ecore_sp_vport_update(p_hwfn, &vport_update,
2034 ECORE_SPQ_MODE_EBLOCK, OSAL_NULL);
2036 DP_NOTICE(p_hwfn, true,
2037 "PF failed to configure VF vport for vlan\n");
2041 /* Update all the Rx queues */
2042 for (i = 0; i < ECORE_MAX_VF_CHAINS_PER_PF; i++) {
2043 struct ecore_vf_queue *p_queue = &p_vf->vf_queues[i];
2044 struct ecore_queue_cid *p_cid = OSAL_NULL;
2046 /* There can be at most 1 Rx queue on qzone. Find it */
2047 p_cid = ecore_iov_get_vf_rx_queue_cid(p_queue);
2048 if (p_cid == OSAL_NULL)
2051 rc = ecore_sp_eth_rx_queues_update(p_hwfn,
2054 ECORE_SPQ_MODE_EBLOCK,
2057 DP_NOTICE(p_hwfn, true,
2058 "Failed to send Rx update"
2059 " fo queue[0x%04x]\n",
2060 p_cid->rel.queue_id);
2066 p_vf->configured_features |= 1 << VLAN_ADDR_FORCED;
2068 p_vf->configured_features &= ~(1 << VLAN_ADDR_FORCED);
2071 /* If forced features are terminated, we need to configure the shadow
2072 * configuration back again.
2075 ecore_iov_reconfigure_unicast_shadow(p_hwfn, p_vf, events);
2080 static void ecore_iov_vf_mbx_start_vport(struct ecore_hwfn *p_hwfn,
2081 struct ecore_ptt *p_ptt,
2082 struct ecore_vf_info *vf)
2084 struct ecore_sp_vport_start_params params = { 0 };
2085 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
2086 struct vfpf_vport_start_tlv *start;
2087 u8 status = PFVF_STATUS_SUCCESS;
2088 struct ecore_vf_info *vf_info;
2091 enum _ecore_status_t rc;
2093 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vf->relative_vf_id, true);
2095 DP_NOTICE(p_hwfn->p_dev, true,
2096 "Failed to get VF info, invalid vfid [%d]\n",
2097 vf->relative_vf_id);
2101 vf->state = VF_ENABLED;
2102 start = &mbx->req_virt->start_vport;
2104 ecore_iov_enable_vf_traffic(p_hwfn, p_ptt, vf);
2106 /* Initialize Status block in CAU */
2107 for (sb_id = 0; sb_id < vf->num_sbs; sb_id++) {
2108 if (!start->sb_addr[sb_id]) {
2109 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2110 "VF[%d] did not fill the address of SB %d\n",
2111 vf->relative_vf_id, sb_id);
2115 ecore_int_cau_conf_sb(p_hwfn, p_ptt,
2116 start->sb_addr[sb_id],
2121 vf->mtu = start->mtu;
2122 vf->shadow_config.inner_vlan_removal = start->inner_vlan_removal;
2124 /* Take into consideration configuration forced by hypervisor;
2125 * If none is configured, use the supplied VF values [for old
2126 * vfs that would still be fine, since they passed '0' as padding].
2128 p_bitmap = &vf_info->bulletin.p_virt->valid_bitmap;
2129 if (!(*p_bitmap & (1 << VFPF_BULLETIN_UNTAGGED_DEFAULT_FORCED))) {
2130 u8 vf_req = start->only_untagged;
2132 vf_info->bulletin.p_virt->default_only_untagged = vf_req;
2133 *p_bitmap |= 1 << VFPF_BULLETIN_UNTAGGED_DEFAULT;
2136 params.tpa_mode = start->tpa_mode;
2137 params.remove_inner_vlan = start->inner_vlan_removal;
2138 params.tx_switching = true;
2141 if (CHIP_REV_IS_FPGA(p_hwfn->p_dev)) {
2142 DP_NOTICE(p_hwfn, false,
2143 "FPGA: Don't config VF for Tx-switching [no pVFC]\n");
2144 params.tx_switching = false;
2148 params.only_untagged = vf_info->bulletin.p_virt->default_only_untagged;
2149 params.drop_ttl0 = false;
2150 params.concrete_fid = vf->concrete_fid;
2151 params.opaque_fid = vf->opaque_fid;
2152 params.vport_id = vf->vport_id;
2153 params.max_buffers_per_cqe = start->max_buffers_per_cqe;
2154 params.mtu = vf->mtu;
2155 params.check_mac = true;
2157 rc = ecore_sp_eth_vport_start(p_hwfn, ¶ms);
2158 if (rc != ECORE_SUCCESS) {
2160 "ecore_iov_vf_mbx_start_vport returned error %d\n", rc);
2161 status = PFVF_STATUS_FAILURE;
2163 vf->vport_instance++;
2165 /* Force configuration if needed on the newly opened vport */
2166 ecore_iov_configure_vport_forced(p_hwfn, vf, *p_bitmap);
2167 OSAL_IOV_POST_START_VPORT(p_hwfn, vf->relative_vf_id,
2168 vf->vport_id, vf->opaque_fid);
2169 __ecore_iov_spoofchk_set(p_hwfn, vf, vf->req_spoofchk_val);
2172 ecore_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_VPORT_START,
2173 sizeof(struct pfvf_def_resp_tlv), status);
2176 static void ecore_iov_vf_mbx_stop_vport(struct ecore_hwfn *p_hwfn,
2177 struct ecore_ptt *p_ptt,
2178 struct ecore_vf_info *vf)
2180 u8 status = PFVF_STATUS_SUCCESS;
2181 enum _ecore_status_t rc;
2183 OSAL_IOV_VF_VPORT_STOP(p_hwfn, vf);
2184 vf->vport_instance--;
2185 vf->spoof_chk = false;
2187 if ((ecore_iov_validate_active_rxq(vf)) ||
2188 (ecore_iov_validate_active_txq(vf))) {
2189 vf->b_malicious = true;
2190 DP_NOTICE(p_hwfn, false,
2191 "VF [%02x] - considered malicious;"
2192 " Unable to stop RX/TX queuess\n",
2194 status = PFVF_STATUS_MALICIOUS;
2198 rc = ecore_sp_vport_stop(p_hwfn, vf->opaque_fid, vf->vport_id);
2199 if (rc != ECORE_SUCCESS) {
2201 "ecore_iov_vf_mbx_stop_vport returned error %d\n", rc);
2202 status = PFVF_STATUS_FAILURE;
2205 /* Forget the configuration on the vport */
2206 vf->configured_features = 0;
2207 OSAL_MEMSET(&vf->shadow_config, 0, sizeof(vf->shadow_config));
2210 ecore_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_VPORT_TEARDOWN,
2211 sizeof(struct pfvf_def_resp_tlv), status);
2214 static void ecore_iov_vf_mbx_start_rxq_resp(struct ecore_hwfn *p_hwfn,
2215 struct ecore_ptt *p_ptt,
2216 struct ecore_vf_info *vf,
2217 u8 status, bool b_legacy)
2219 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
2220 struct pfvf_start_queue_resp_tlv *p_tlv;
2221 struct vfpf_start_rxq_tlv *req;
2224 mbx->offset = (u8 *)mbx->reply_virt;
2226 /* Taking a bigger struct instead of adding a TLV to list was a
2227 * mistake, but one which we're now stuck with, as some older
2228 * clients assume the size of the previous response.
2231 length = sizeof(*p_tlv);
2233 length = sizeof(struct pfvf_def_resp_tlv);
2235 p_tlv = ecore_add_tlv(&mbx->offset, CHANNEL_TLV_START_RXQ, length);
2236 ecore_add_tlv(&mbx->offset, CHANNEL_TLV_LIST_END,
2237 sizeof(struct channel_list_end_tlv));
2239 /* Update the TLV with the response */
2240 if ((status == PFVF_STATUS_SUCCESS) && !b_legacy) {
2241 req = &mbx->req_virt->start_rxq;
2242 p_tlv->offset = PXP_VF_BAR0_START_MSDM_ZONE_B +
2243 OFFSETOF(struct mstorm_vf_zone,
2244 non_trigger.eth_rx_queue_producers) +
2245 sizeof(struct eth_rx_prod_data) * req->rx_qid;
2248 ecore_iov_send_response(p_hwfn, p_ptt, vf, length, status);
2251 static u8 ecore_iov_vf_mbx_qid(struct ecore_hwfn *p_hwfn,
2252 struct ecore_vf_info *p_vf, bool b_is_tx)
2254 struct ecore_iov_vf_mbx *p_mbx = &p_vf->vf_mbx;
2255 struct vfpf_qid_tlv *p_qid_tlv;
2257 /* Search for the qid if the VF published if its going to provide it */
2258 if (!(p_vf->acquire.vfdev_info.capabilities &
2259 VFPF_ACQUIRE_CAP_QUEUE_QIDS)) {
2261 return ECORE_IOV_LEGACY_QID_TX;
2263 return ECORE_IOV_LEGACY_QID_RX;
2266 p_qid_tlv = (struct vfpf_qid_tlv *)
2267 ecore_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt,
2269 if (p_qid_tlv == OSAL_NULL) {
2270 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2271 "VF[%2x]: Failed to provide qid\n",
2272 p_vf->relative_vf_id);
2274 return ECORE_IOV_QID_INVALID;
2277 if (p_qid_tlv->qid >= MAX_QUEUES_PER_QZONE) {
2278 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2279 "VF[%02x]: Provided qid out-of-bounds %02x\n",
2280 p_vf->relative_vf_id, p_qid_tlv->qid);
2281 return ECORE_IOV_QID_INVALID;
2284 return p_qid_tlv->qid;
2287 static void ecore_iov_vf_mbx_start_rxq(struct ecore_hwfn *p_hwfn,
2288 struct ecore_ptt *p_ptt,
2289 struct ecore_vf_info *vf)
2291 struct ecore_queue_start_common_params params;
2292 struct ecore_queue_cid_vf_params vf_params;
2293 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
2294 u8 status = PFVF_STATUS_NO_RESOURCE;
2295 u8 qid_usage_idx, vf_legacy = 0;
2296 struct ecore_vf_queue *p_queue;
2297 struct vfpf_start_rxq_tlv *req;
2298 struct ecore_queue_cid *p_cid;
2299 struct ecore_sb_info sb_dummy;
2300 enum _ecore_status_t rc;
2302 req = &mbx->req_virt->start_rxq;
2304 if (!ecore_iov_validate_rxq(p_hwfn, vf, req->rx_qid,
2305 ECORE_IOV_VALIDATE_Q_DISABLE) ||
2306 !ecore_iov_validate_sb(p_hwfn, vf, req->hw_sb))
2309 qid_usage_idx = ecore_iov_vf_mbx_qid(p_hwfn, vf, false);
2310 if (qid_usage_idx == ECORE_IOV_QID_INVALID)
2313 p_queue = &vf->vf_queues[req->rx_qid];
2314 if (p_queue->cids[qid_usage_idx].p_cid)
2317 vf_legacy = ecore_vf_calculate_legacy(vf);
2319 /* Acquire a new queue-cid */
2320 OSAL_MEMSET(¶ms, 0, sizeof(params));
2321 params.queue_id = (u8)p_queue->fw_rx_qid;
2322 params.vport_id = vf->vport_id;
2323 params.stats_id = vf->abs_vf_id + 0x10;
2325 /* Since IGU index is passed via sb_info, construct a dummy one */
2326 OSAL_MEM_ZERO(&sb_dummy, sizeof(sb_dummy));
2327 sb_dummy.igu_sb_id = req->hw_sb;
2328 params.p_sb = &sb_dummy;
2329 params.sb_idx = req->sb_index;
2331 OSAL_MEM_ZERO(&vf_params, sizeof(vf_params));
2332 vf_params.vfid = vf->relative_vf_id;
2333 vf_params.vf_qid = (u8)req->rx_qid;
2334 vf_params.vf_legacy = vf_legacy;
2335 vf_params.qid_usage_idx = qid_usage_idx;
2337 p_cid = ecore_eth_queue_to_cid(p_hwfn, vf->opaque_fid,
2338 ¶ms, true, &vf_params);
2339 if (p_cid == OSAL_NULL)
2342 /* Legacy VFs have their Producers in a different location, which they
2343 * calculate on their own and clean the producer prior to this.
2345 if (!(vf_legacy & ECORE_QCID_LEGACY_VF_RX_PROD))
2347 GTT_BAR0_MAP_REG_MSDM_RAM +
2348 MSTORM_ETH_VF_PRODS_OFFSET(vf->abs_vf_id, req->rx_qid),
2351 rc = ecore_eth_rxq_start_ramrod(p_hwfn, p_cid,
2356 if (rc != ECORE_SUCCESS) {
2357 status = PFVF_STATUS_FAILURE;
2358 ecore_eth_queue_cid_release(p_hwfn, p_cid);
2360 p_queue->cids[qid_usage_idx].p_cid = p_cid;
2361 p_queue->cids[qid_usage_idx].b_is_tx = false;
2362 status = PFVF_STATUS_SUCCESS;
2363 vf->num_active_rxqs++;
2367 ecore_iov_vf_mbx_start_rxq_resp(p_hwfn, p_ptt, vf, status,
2369 ECORE_QCID_LEGACY_VF_RX_PROD));
2373 ecore_iov_pf_update_tun_response(struct pfvf_update_tunn_param_tlv *p_resp,
2374 struct ecore_tunnel_info *p_tun,
2375 u16 tunn_feature_mask)
2377 p_resp->tunn_feature_mask = tunn_feature_mask;
2378 p_resp->vxlan_mode = p_tun->vxlan.b_mode_enabled;
2379 p_resp->l2geneve_mode = p_tun->l2_geneve.b_mode_enabled;
2380 p_resp->ipgeneve_mode = p_tun->ip_geneve.b_mode_enabled;
2381 p_resp->l2gre_mode = p_tun->l2_gre.b_mode_enabled;
2382 p_resp->ipgre_mode = p_tun->l2_gre.b_mode_enabled;
2383 p_resp->vxlan_clss = p_tun->vxlan.tun_cls;
2384 p_resp->l2gre_clss = p_tun->l2_gre.tun_cls;
2385 p_resp->ipgre_clss = p_tun->ip_gre.tun_cls;
2386 p_resp->l2geneve_clss = p_tun->l2_geneve.tun_cls;
2387 p_resp->ipgeneve_clss = p_tun->ip_geneve.tun_cls;
2388 p_resp->geneve_udp_port = p_tun->geneve_port.port;
2389 p_resp->vxlan_udp_port = p_tun->vxlan_port.port;
2393 __ecore_iov_pf_update_tun_param(struct vfpf_update_tunn_param_tlv *p_req,
2394 struct ecore_tunn_update_type *p_tun,
2395 enum ecore_tunn_mode mask, u8 tun_cls)
2397 if (p_req->tun_mode_update_mask & (1 << mask)) {
2398 p_tun->b_update_mode = true;
2400 if (p_req->tunn_mode & (1 << mask))
2401 p_tun->b_mode_enabled = true;
2404 p_tun->tun_cls = tun_cls;
2408 ecore_iov_pf_update_tun_param(struct vfpf_update_tunn_param_tlv *p_req,
2409 struct ecore_tunn_update_type *p_tun,
2410 struct ecore_tunn_update_udp_port *p_port,
2411 enum ecore_tunn_mode mask,
2412 u8 tun_cls, u8 update_port, u16 port)
2415 p_port->b_update_port = true;
2416 p_port->port = port;
2419 __ecore_iov_pf_update_tun_param(p_req, p_tun, mask, tun_cls);
2423 ecore_iov_pf_validate_tunn_param(struct vfpf_update_tunn_param_tlv *p_req)
2425 bool b_update_requested = false;
2427 if (p_req->tun_mode_update_mask || p_req->update_tun_cls ||
2428 p_req->update_geneve_port || p_req->update_vxlan_port)
2429 b_update_requested = true;
2431 return b_update_requested;
2434 static void ecore_iov_vf_mbx_update_tunn_param(struct ecore_hwfn *p_hwfn,
2435 struct ecore_ptt *p_ptt,
2436 struct ecore_vf_info *p_vf)
2438 struct ecore_tunnel_info *p_tun = &p_hwfn->p_dev->tunnel;
2439 struct ecore_iov_vf_mbx *mbx = &p_vf->vf_mbx;
2440 struct pfvf_update_tunn_param_tlv *p_resp;
2441 struct vfpf_update_tunn_param_tlv *p_req;
2442 enum _ecore_status_t rc = ECORE_SUCCESS;
2443 u8 status = PFVF_STATUS_SUCCESS;
2444 bool b_update_required = false;
2445 struct ecore_tunnel_info tunn;
2446 u16 tunn_feature_mask = 0;
2449 mbx->offset = (u8 *)mbx->reply_virt;
2451 OSAL_MEM_ZERO(&tunn, sizeof(tunn));
2452 p_req = &mbx->req_virt->tunn_param_update;
2454 if (!ecore_iov_pf_validate_tunn_param(p_req)) {
2455 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2456 "No tunnel update requested by VF\n");
2457 status = PFVF_STATUS_FAILURE;
2461 tunn.b_update_rx_cls = p_req->update_tun_cls;
2462 tunn.b_update_tx_cls = p_req->update_tun_cls;
2464 ecore_iov_pf_update_tun_param(p_req, &tunn.vxlan, &tunn.vxlan_port,
2465 ECORE_MODE_VXLAN_TUNN, p_req->vxlan_clss,
2466 p_req->update_vxlan_port,
2468 ecore_iov_pf_update_tun_param(p_req, &tunn.l2_geneve, &tunn.geneve_port,
2469 ECORE_MODE_L2GENEVE_TUNN,
2470 p_req->l2geneve_clss,
2471 p_req->update_geneve_port,
2472 p_req->geneve_port);
2473 __ecore_iov_pf_update_tun_param(p_req, &tunn.ip_geneve,
2474 ECORE_MODE_IPGENEVE_TUNN,
2475 p_req->ipgeneve_clss);
2476 __ecore_iov_pf_update_tun_param(p_req, &tunn.l2_gre,
2477 ECORE_MODE_L2GRE_TUNN,
2479 __ecore_iov_pf_update_tun_param(p_req, &tunn.ip_gre,
2480 ECORE_MODE_IPGRE_TUNN,
2483 /* If PF modifies VF's req then it should
2484 * still return an error in case of partial configuration
2485 * or modified configuration as opposed to requested one.
2487 rc = OSAL_PF_VALIDATE_MODIFY_TUNN_CONFIG(p_hwfn, &tunn_feature_mask,
2488 &b_update_required, &tunn);
2490 if (rc != ECORE_SUCCESS)
2491 status = PFVF_STATUS_FAILURE;
2493 /* If ECORE client is willing to update anything ? */
2494 if (b_update_required) {
2497 rc = ecore_sp_pf_update_tunn_cfg(p_hwfn, p_ptt, &tunn,
2498 ECORE_SPQ_MODE_EBLOCK,
2500 if (rc != ECORE_SUCCESS)
2501 status = PFVF_STATUS_FAILURE;
2503 geneve_port = p_tun->geneve_port.port;
2504 ecore_for_each_vf(p_hwfn, i) {
2505 ecore_iov_bulletin_set_udp_ports(p_hwfn, i,
2506 p_tun->vxlan_port.port,
2512 p_resp = ecore_add_tlv(&mbx->offset,
2513 CHANNEL_TLV_UPDATE_TUNN_PARAM, sizeof(*p_resp));
2515 ecore_iov_pf_update_tun_response(p_resp, p_tun, tunn_feature_mask);
2516 ecore_add_tlv(&mbx->offset, CHANNEL_TLV_LIST_END,
2517 sizeof(struct channel_list_end_tlv));
2519 ecore_iov_send_response(p_hwfn, p_ptt, p_vf, sizeof(*p_resp), status);
2522 static void ecore_iov_vf_mbx_start_txq_resp(struct ecore_hwfn *p_hwfn,
2523 struct ecore_ptt *p_ptt,
2524 struct ecore_vf_info *p_vf,
2528 struct ecore_iov_vf_mbx *mbx = &p_vf->vf_mbx;
2529 struct pfvf_start_queue_resp_tlv *p_tlv;
2530 bool b_legacy = false;
2533 mbx->offset = (u8 *)mbx->reply_virt;
2535 /* Taking a bigger struct instead of adding a TLV to list was a
2536 * mistake, but one which we're now stuck with, as some older
2537 * clients assume the size of the previous response.
2539 if (p_vf->acquire.vfdev_info.eth_fp_hsi_minor ==
2540 ETH_HSI_VER_NO_PKT_LEN_TUNN)
2544 length = sizeof(*p_tlv);
2546 length = sizeof(struct pfvf_def_resp_tlv);
2548 p_tlv = ecore_add_tlv(&mbx->offset, CHANNEL_TLV_START_TXQ, length);
2549 ecore_add_tlv(&mbx->offset, CHANNEL_TLV_LIST_END,
2550 sizeof(struct channel_list_end_tlv));
2552 /* Update the TLV with the response */
2553 if ((status == PFVF_STATUS_SUCCESS) && !b_legacy)
2554 p_tlv->offset = DB_ADDR_VF(cid, DQ_DEMS_LEGACY);
2556 ecore_iov_send_response(p_hwfn, p_ptt, p_vf, length, status);
2559 static void ecore_iov_vf_mbx_start_txq(struct ecore_hwfn *p_hwfn,
2560 struct ecore_ptt *p_ptt,
2561 struct ecore_vf_info *vf)
2563 struct ecore_queue_start_common_params params;
2564 struct ecore_queue_cid_vf_params vf_params;
2565 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
2566 u8 status = PFVF_STATUS_NO_RESOURCE;
2567 struct ecore_vf_queue *p_queue;
2568 struct vfpf_start_txq_tlv *req;
2569 struct ecore_queue_cid *p_cid;
2570 struct ecore_sb_info sb_dummy;
2571 u8 qid_usage_idx, vf_legacy;
2573 enum _ecore_status_t rc;
2576 OSAL_MEMSET(¶ms, 0, sizeof(params));
2577 req = &mbx->req_virt->start_txq;
2579 if (!ecore_iov_validate_txq(p_hwfn, vf, req->tx_qid,
2580 ECORE_IOV_VALIDATE_Q_NA) ||
2581 !ecore_iov_validate_sb(p_hwfn, vf, req->hw_sb))
2584 qid_usage_idx = ecore_iov_vf_mbx_qid(p_hwfn, vf, true);
2585 if (qid_usage_idx == ECORE_IOV_QID_INVALID)
2588 p_queue = &vf->vf_queues[req->tx_qid];
2589 if (p_queue->cids[qid_usage_idx].p_cid)
2592 vf_legacy = ecore_vf_calculate_legacy(vf);
2594 /* Acquire a new queue-cid */
2595 params.queue_id = p_queue->fw_tx_qid;
2596 params.vport_id = vf->vport_id;
2597 params.stats_id = vf->abs_vf_id + 0x10;
2599 /* Since IGU index is passed via sb_info, construct a dummy one */
2600 OSAL_MEM_ZERO(&sb_dummy, sizeof(sb_dummy));
2601 sb_dummy.igu_sb_id = req->hw_sb;
2602 params.p_sb = &sb_dummy;
2603 params.sb_idx = req->sb_index;
2605 OSAL_MEM_ZERO(&vf_params, sizeof(vf_params));
2606 vf_params.vfid = vf->relative_vf_id;
2607 vf_params.vf_qid = (u8)req->tx_qid;
2608 vf_params.vf_legacy = vf_legacy;
2609 vf_params.qid_usage_idx = qid_usage_idx;
2611 p_cid = ecore_eth_queue_to_cid(p_hwfn, vf->opaque_fid,
2612 ¶ms, false, &vf_params);
2613 if (p_cid == OSAL_NULL)
2616 pq = ecore_get_cm_pq_idx_vf(p_hwfn,
2617 vf->relative_vf_id);
2618 rc = ecore_eth_txq_start_ramrod(p_hwfn, p_cid,
2619 req->pbl_addr, req->pbl_size, pq);
2620 if (rc != ECORE_SUCCESS) {
2621 status = PFVF_STATUS_FAILURE;
2622 ecore_eth_queue_cid_release(p_hwfn, p_cid);
2624 status = PFVF_STATUS_SUCCESS;
2625 p_queue->cids[qid_usage_idx].p_cid = p_cid;
2626 p_queue->cids[qid_usage_idx].b_is_tx = true;
2631 ecore_iov_vf_mbx_start_txq_resp(p_hwfn, p_ptt, vf,
2635 static enum _ecore_status_t ecore_iov_vf_stop_rxqs(struct ecore_hwfn *p_hwfn,
2636 struct ecore_vf_info *vf,
2639 bool cqe_completion)
2641 struct ecore_vf_queue *p_queue;
2642 enum _ecore_status_t rc = ECORE_SUCCESS;
2644 if (!ecore_iov_validate_rxq(p_hwfn, vf, rxq_id,
2645 ECORE_IOV_VALIDATE_Q_NA)) {
2646 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2647 "VF[%d] Tried Closing Rx 0x%04x.%02x which is inactive\n",
2648 vf->relative_vf_id, rxq_id, qid_usage_idx);
2652 p_queue = &vf->vf_queues[rxq_id];
2654 /* We've validated the index and the existence of the active RXQ -
2655 * now we need to make sure that it's using the correct qid.
2657 if (!p_queue->cids[qid_usage_idx].p_cid ||
2658 p_queue->cids[qid_usage_idx].b_is_tx) {
2659 struct ecore_queue_cid *p_cid;
2661 p_cid = ecore_iov_get_vf_rx_queue_cid(p_queue);
2662 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2663 "VF[%d] - Tried Closing Rx 0x%04x.%02x, but Rx is at %04x.%02x\n",
2664 vf->relative_vf_id, rxq_id, qid_usage_idx,
2665 rxq_id, p_cid->qid_usage_idx);
2669 /* Now that we know we have a valid Rx-queue - close it */
2670 rc = ecore_eth_rx_queue_stop(p_hwfn,
2671 p_queue->cids[qid_usage_idx].p_cid,
2672 false, cqe_completion);
2673 if (rc != ECORE_SUCCESS)
2676 p_queue->cids[qid_usage_idx].p_cid = OSAL_NULL;
2677 vf->num_active_rxqs--;
2679 return ECORE_SUCCESS;
2682 static enum _ecore_status_t ecore_iov_vf_stop_txqs(struct ecore_hwfn *p_hwfn,
2683 struct ecore_vf_info *vf,
2687 struct ecore_vf_queue *p_queue;
2688 enum _ecore_status_t rc = ECORE_SUCCESS;
2690 if (!ecore_iov_validate_txq(p_hwfn, vf, txq_id,
2691 ECORE_IOV_VALIDATE_Q_NA))
2694 p_queue = &vf->vf_queues[txq_id];
2695 if (!p_queue->cids[qid_usage_idx].p_cid ||
2696 !p_queue->cids[qid_usage_idx].b_is_tx)
2699 rc = ecore_eth_tx_queue_stop(p_hwfn,
2700 p_queue->cids[qid_usage_idx].p_cid);
2701 if (rc != ECORE_SUCCESS)
2704 p_queue->cids[qid_usage_idx].p_cid = OSAL_NULL;
2705 return ECORE_SUCCESS;
2708 static void ecore_iov_vf_mbx_stop_rxqs(struct ecore_hwfn *p_hwfn,
2709 struct ecore_ptt *p_ptt,
2710 struct ecore_vf_info *vf)
2712 u16 length = sizeof(struct pfvf_def_resp_tlv);
2713 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
2714 u8 status = PFVF_STATUS_FAILURE;
2715 struct vfpf_stop_rxqs_tlv *req;
2717 enum _ecore_status_t rc;
2719 /* Starting with CHANNEL_TLV_QID, it's assumed the 'num_rxqs'
2720 * would be one. Since no older ecore passed multiple queues
2721 * using this API, sanitize on the value.
2723 req = &mbx->req_virt->stop_rxqs;
2724 if (req->num_rxqs != 1) {
2725 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2726 "Odd; VF[%d] tried stopping multiple Rx queues\n",
2727 vf->relative_vf_id);
2728 status = PFVF_STATUS_NOT_SUPPORTED;
2732 /* Find which qid-index is associated with the queue */
2733 qid_usage_idx = ecore_iov_vf_mbx_qid(p_hwfn, vf, false);
2734 if (qid_usage_idx == ECORE_IOV_QID_INVALID)
2737 rc = ecore_iov_vf_stop_rxqs(p_hwfn, vf, req->rx_qid,
2738 qid_usage_idx, req->cqe_completion);
2739 if (rc == ECORE_SUCCESS)
2740 status = PFVF_STATUS_SUCCESS;
2742 ecore_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_STOP_RXQS,
2746 static void ecore_iov_vf_mbx_stop_txqs(struct ecore_hwfn *p_hwfn,
2747 struct ecore_ptt *p_ptt,
2748 struct ecore_vf_info *vf)
2750 u16 length = sizeof(struct pfvf_def_resp_tlv);
2751 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
2752 u8 status = PFVF_STATUS_FAILURE;
2753 struct vfpf_stop_txqs_tlv *req;
2755 enum _ecore_status_t rc;
2757 /* Starting with CHANNEL_TLV_QID, it's assumed the 'num_txqs'
2758 * would be one. Since no older ecore passed multiple queues
2759 * using this API, sanitize on the value.
2761 req = &mbx->req_virt->stop_txqs;
2762 if (req->num_txqs != 1) {
2763 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2764 "Odd; VF[%d] tried stopping multiple Tx queues\n",
2765 vf->relative_vf_id);
2766 status = PFVF_STATUS_NOT_SUPPORTED;
2770 /* Find which qid-index is associated with the queue */
2771 qid_usage_idx = ecore_iov_vf_mbx_qid(p_hwfn, vf, true);
2772 if (qid_usage_idx == ECORE_IOV_QID_INVALID)
2775 rc = ecore_iov_vf_stop_txqs(p_hwfn, vf, req->tx_qid,
2777 if (rc == ECORE_SUCCESS)
2778 status = PFVF_STATUS_SUCCESS;
2781 ecore_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_STOP_TXQS,
2785 static void ecore_iov_vf_mbx_update_rxqs(struct ecore_hwfn *p_hwfn,
2786 struct ecore_ptt *p_ptt,
2787 struct ecore_vf_info *vf)
2789 struct ecore_queue_cid *handlers[ECORE_MAX_VF_CHAINS_PER_PF];
2790 u16 length = sizeof(struct pfvf_def_resp_tlv);
2791 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
2792 struct vfpf_update_rxq_tlv *req;
2793 u8 status = PFVF_STATUS_FAILURE;
2794 u8 complete_event_flg;
2795 u8 complete_cqe_flg;
2797 enum _ecore_status_t rc;
2800 req = &mbx->req_virt->update_rxq;
2801 complete_cqe_flg = !!(req->flags & VFPF_RXQ_UPD_COMPLETE_CQE_FLAG);
2802 complete_event_flg = !!(req->flags & VFPF_RXQ_UPD_COMPLETE_EVENT_FLAG);
2804 qid_usage_idx = ecore_iov_vf_mbx_qid(p_hwfn, vf, false);
2805 if (qid_usage_idx == ECORE_IOV_QID_INVALID)
2808 /* Starting with the addition of CHANNEL_TLV_QID, this API started
2809 * expecting a single queue at a time. Validate this.
2811 if ((vf->acquire.vfdev_info.capabilities &
2812 VFPF_ACQUIRE_CAP_QUEUE_QIDS) &&
2813 req->num_rxqs != 1) {
2814 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2815 "VF[%d] supports QIDs but sends multiple queues\n",
2816 vf->relative_vf_id);
2820 /* Validate inputs - for the legacy case this is still true since
2821 * qid_usage_idx for each Rx queue would be LEGACY_QID_RX.
2823 for (i = req->rx_qid; i < req->rx_qid + req->num_rxqs; i++) {
2824 if (!ecore_iov_validate_rxq(p_hwfn, vf, i,
2825 ECORE_IOV_VALIDATE_Q_NA) ||
2826 !vf->vf_queues[i].cids[qid_usage_idx].p_cid ||
2827 vf->vf_queues[i].cids[qid_usage_idx].b_is_tx) {
2828 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2829 "VF[%d]: Incorrect Rxqs [%04x, %02x]\n",
2830 vf->relative_vf_id, req->rx_qid,
2836 for (i = 0; i < req->num_rxqs; i++) {
2837 u16 qid = req->rx_qid + i;
2839 handlers[i] = vf->vf_queues[qid].cids[qid_usage_idx].p_cid;
2842 rc = ecore_sp_eth_rx_queues_update(p_hwfn, (void **)&handlers,
2846 ECORE_SPQ_MODE_EBLOCK,
2848 if (rc != ECORE_SUCCESS)
2851 status = PFVF_STATUS_SUCCESS;
2853 ecore_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_UPDATE_RXQ,
2857 void *ecore_iov_search_list_tlvs(struct ecore_hwfn *p_hwfn,
2858 void *p_tlvs_list, u16 req_type)
2860 struct channel_tlv *p_tlv = (struct channel_tlv *)p_tlvs_list;
2864 if (!p_tlv->length) {
2865 DP_NOTICE(p_hwfn, true, "Zero length TLV found\n");
2869 if (p_tlv->type == req_type) {
2870 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2871 "Extended tlv type %s, length %d found\n",
2872 ecore_channel_tlvs_string[p_tlv->type],
2877 len += p_tlv->length;
2878 p_tlv = (struct channel_tlv *)((u8 *)p_tlv + p_tlv->length);
2880 if ((len + p_tlv->length) > TLV_BUFFER_SIZE) {
2881 DP_NOTICE(p_hwfn, true,
2882 "TLVs has overrun the buffer size\n");
2885 } while (p_tlv->type != CHANNEL_TLV_LIST_END);
2891 ecore_iov_vp_update_act_param(struct ecore_hwfn *p_hwfn,
2892 struct ecore_sp_vport_update_params *p_data,
2893 struct ecore_iov_vf_mbx *p_mbx, u16 *tlvs_mask)
2895 struct vfpf_vport_update_activate_tlv *p_act_tlv;
2896 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_ACTIVATE;
2898 p_act_tlv = (struct vfpf_vport_update_activate_tlv *)
2899 ecore_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
2903 p_data->update_vport_active_rx_flg = p_act_tlv->update_rx;
2904 p_data->vport_active_rx_flg = p_act_tlv->active_rx;
2905 p_data->update_vport_active_tx_flg = p_act_tlv->update_tx;
2906 p_data->vport_active_tx_flg = p_act_tlv->active_tx;
2907 *tlvs_mask |= 1 << ECORE_IOV_VP_UPDATE_ACTIVATE;
2911 ecore_iov_vp_update_vlan_param(struct ecore_hwfn *p_hwfn,
2912 struct ecore_sp_vport_update_params *p_data,
2913 struct ecore_vf_info *p_vf,
2914 struct ecore_iov_vf_mbx *p_mbx, u16 *tlvs_mask)
2916 struct vfpf_vport_update_vlan_strip_tlv *p_vlan_tlv;
2917 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_VLAN_STRIP;
2919 p_vlan_tlv = (struct vfpf_vport_update_vlan_strip_tlv *)
2920 ecore_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
2924 p_vf->shadow_config.inner_vlan_removal = p_vlan_tlv->remove_vlan;
2926 /* Ignore the VF request if we're forcing a vlan */
2927 if (!(p_vf->configured_features & (1 << VLAN_ADDR_FORCED))) {
2928 p_data->update_inner_vlan_removal_flg = 1;
2929 p_data->inner_vlan_removal_flg = p_vlan_tlv->remove_vlan;
2932 *tlvs_mask |= 1 << ECORE_IOV_VP_UPDATE_VLAN_STRIP;
2936 ecore_iov_vp_update_tx_switch(struct ecore_hwfn *p_hwfn,
2937 struct ecore_sp_vport_update_params *p_data,
2938 struct ecore_iov_vf_mbx *p_mbx, u16 *tlvs_mask)
2940 struct vfpf_vport_update_tx_switch_tlv *p_tx_switch_tlv;
2941 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_TX_SWITCH;
2943 p_tx_switch_tlv = (struct vfpf_vport_update_tx_switch_tlv *)
2944 ecore_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
2945 if (!p_tx_switch_tlv)
2949 if (CHIP_REV_IS_FPGA(p_hwfn->p_dev)) {
2950 DP_NOTICE(p_hwfn, false,
2951 "FPGA: Ignore tx-switching configuration originating"
2957 p_data->update_tx_switching_flg = 1;
2958 p_data->tx_switching_flg = p_tx_switch_tlv->tx_switching;
2959 *tlvs_mask |= 1 << ECORE_IOV_VP_UPDATE_TX_SWITCH;
2963 ecore_iov_vp_update_mcast_bin_param(struct ecore_hwfn *p_hwfn,
2964 struct ecore_sp_vport_update_params *p_data,
2965 struct ecore_iov_vf_mbx *p_mbx,
2968 struct vfpf_vport_update_mcast_bin_tlv *p_mcast_tlv;
2969 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_MCAST;
2971 p_mcast_tlv = (struct vfpf_vport_update_mcast_bin_tlv *)
2972 ecore_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
2976 p_data->update_approx_mcast_flg = 1;
2977 OSAL_MEMCPY(p_data->bins, p_mcast_tlv->bins,
2978 sizeof(unsigned long) *
2979 ETH_MULTICAST_MAC_BINS_IN_REGS);
2980 *tlvs_mask |= 1 << ECORE_IOV_VP_UPDATE_MCAST;
2984 ecore_iov_vp_update_accept_flag(struct ecore_hwfn *p_hwfn,
2985 struct ecore_sp_vport_update_params *p_data,
2986 struct ecore_iov_vf_mbx *p_mbx, u16 *tlvs_mask)
2988 struct ecore_filter_accept_flags *p_flags = &p_data->accept_flags;
2989 struct vfpf_vport_update_accept_param_tlv *p_accept_tlv;
2990 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_ACCEPT_PARAM;
2992 p_accept_tlv = (struct vfpf_vport_update_accept_param_tlv *)
2993 ecore_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
2997 p_flags->update_rx_mode_config = p_accept_tlv->update_rx_mode;
2998 p_flags->rx_accept_filter = p_accept_tlv->rx_accept_filter;
2999 p_flags->update_tx_mode_config = p_accept_tlv->update_tx_mode;
3000 p_flags->tx_accept_filter = p_accept_tlv->tx_accept_filter;
3001 *tlvs_mask |= 1 << ECORE_IOV_VP_UPDATE_ACCEPT_PARAM;
3005 ecore_iov_vp_update_accept_any_vlan(struct ecore_hwfn *p_hwfn,
3006 struct ecore_sp_vport_update_params *p_data,
3007 struct ecore_iov_vf_mbx *p_mbx,
3010 struct vfpf_vport_update_accept_any_vlan_tlv *p_accept_any_vlan;
3011 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_ACCEPT_ANY_VLAN;
3013 p_accept_any_vlan = (struct vfpf_vport_update_accept_any_vlan_tlv *)
3014 ecore_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
3015 if (!p_accept_any_vlan)
3018 p_data->accept_any_vlan = p_accept_any_vlan->accept_any_vlan;
3019 p_data->update_accept_any_vlan_flg =
3020 p_accept_any_vlan->update_accept_any_vlan_flg;
3021 *tlvs_mask |= 1 << ECORE_IOV_VP_UPDATE_ACCEPT_ANY_VLAN;
3025 ecore_iov_vp_update_rss_param(struct ecore_hwfn *p_hwfn,
3026 struct ecore_vf_info *vf,
3027 struct ecore_sp_vport_update_params *p_data,
3028 struct ecore_rss_params *p_rss,
3029 struct ecore_iov_vf_mbx *p_mbx,
3030 u16 *tlvs_mask, u16 *tlvs_accepted)
3032 struct vfpf_vport_update_rss_tlv *p_rss_tlv;
3033 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_RSS;
3034 bool b_reject = false;
3038 p_rss_tlv = (struct vfpf_vport_update_rss_tlv *)
3039 ecore_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
3041 p_data->rss_params = OSAL_NULL;
3045 OSAL_MEMSET(p_rss, 0, sizeof(struct ecore_rss_params));
3047 p_rss->update_rss_config =
3048 !!(p_rss_tlv->update_rss_flags &
3049 VFPF_UPDATE_RSS_CONFIG_FLAG);
3050 p_rss->update_rss_capabilities =
3051 !!(p_rss_tlv->update_rss_flags &
3052 VFPF_UPDATE_RSS_CAPS_FLAG);
3053 p_rss->update_rss_ind_table =
3054 !!(p_rss_tlv->update_rss_flags &
3055 VFPF_UPDATE_RSS_IND_TABLE_FLAG);
3056 p_rss->update_rss_key =
3057 !!(p_rss_tlv->update_rss_flags &
3058 VFPF_UPDATE_RSS_KEY_FLAG);
3060 p_rss->rss_enable = p_rss_tlv->rss_enable;
3061 p_rss->rss_eng_id = vf->rss_eng_id;
3062 p_rss->rss_caps = p_rss_tlv->rss_caps;
3063 p_rss->rss_table_size_log = p_rss_tlv->rss_table_size_log;
3064 OSAL_MEMCPY(p_rss->rss_key, p_rss_tlv->rss_key,
3065 sizeof(p_rss->rss_key));
3067 table_size = OSAL_MIN_T(u16, OSAL_ARRAY_SIZE(p_rss->rss_ind_table),
3068 (1 << p_rss_tlv->rss_table_size_log));
3070 for (i = 0; i < table_size; i++) {
3071 struct ecore_queue_cid *p_cid;
3073 q_idx = p_rss_tlv->rss_ind_table[i];
3074 if (!ecore_iov_validate_rxq(p_hwfn, vf, q_idx,
3075 ECORE_IOV_VALIDATE_Q_ENABLE)) {
3076 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3077 "VF[%d]: Omitting RSS due to wrong queue %04x\n",
3078 vf->relative_vf_id, q_idx);
3083 p_cid = ecore_iov_get_vf_rx_queue_cid(&vf->vf_queues[q_idx]);
3084 p_rss->rss_ind_table[i] = p_cid;
3087 p_data->rss_params = p_rss;
3089 *tlvs_mask |= 1 << ECORE_IOV_VP_UPDATE_RSS;
3091 *tlvs_accepted |= 1 << ECORE_IOV_VP_UPDATE_RSS;
3095 ecore_iov_vp_update_sge_tpa_param(struct ecore_hwfn *p_hwfn,
3096 struct ecore_sp_vport_update_params *p_data,
3097 struct ecore_sge_tpa_params *p_sge_tpa,
3098 struct ecore_iov_vf_mbx *p_mbx,
3101 struct vfpf_vport_update_sge_tpa_tlv *p_sge_tpa_tlv;
3102 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_SGE_TPA;
3104 p_sge_tpa_tlv = (struct vfpf_vport_update_sge_tpa_tlv *)
3105 ecore_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
3107 if (!p_sge_tpa_tlv) {
3108 p_data->sge_tpa_params = OSAL_NULL;
3112 OSAL_MEMSET(p_sge_tpa, 0, sizeof(struct ecore_sge_tpa_params));
3114 p_sge_tpa->update_tpa_en_flg =
3115 !!(p_sge_tpa_tlv->update_sge_tpa_flags & VFPF_UPDATE_TPA_EN_FLAG);
3116 p_sge_tpa->update_tpa_param_flg =
3117 !!(p_sge_tpa_tlv->update_sge_tpa_flags &
3118 VFPF_UPDATE_TPA_PARAM_FLAG);
3120 p_sge_tpa->tpa_ipv4_en_flg =
3121 !!(p_sge_tpa_tlv->sge_tpa_flags & VFPF_TPA_IPV4_EN_FLAG);
3122 p_sge_tpa->tpa_ipv6_en_flg =
3123 !!(p_sge_tpa_tlv->sge_tpa_flags & VFPF_TPA_IPV6_EN_FLAG);
3124 p_sge_tpa->tpa_pkt_split_flg =
3125 !!(p_sge_tpa_tlv->sge_tpa_flags & VFPF_TPA_PKT_SPLIT_FLAG);
3126 p_sge_tpa->tpa_hdr_data_split_flg =
3127 !!(p_sge_tpa_tlv->sge_tpa_flags & VFPF_TPA_HDR_DATA_SPLIT_FLAG);
3128 p_sge_tpa->tpa_gro_consistent_flg =
3129 !!(p_sge_tpa_tlv->sge_tpa_flags & VFPF_TPA_GRO_CONSIST_FLAG);
3131 p_sge_tpa->tpa_max_aggs_num = p_sge_tpa_tlv->tpa_max_aggs_num;
3132 p_sge_tpa->tpa_max_size = p_sge_tpa_tlv->tpa_max_size;
3133 p_sge_tpa->tpa_min_size_to_start = p_sge_tpa_tlv->tpa_min_size_to_start;
3134 p_sge_tpa->tpa_min_size_to_cont = p_sge_tpa_tlv->tpa_min_size_to_cont;
3135 p_sge_tpa->max_buffers_per_cqe = p_sge_tpa_tlv->max_buffers_per_cqe;
3137 p_data->sge_tpa_params = p_sge_tpa;
3139 *tlvs_mask |= 1 << ECORE_IOV_VP_UPDATE_SGE_TPA;
3142 static void ecore_iov_vf_mbx_vport_update(struct ecore_hwfn *p_hwfn,
3143 struct ecore_ptt *p_ptt,
3144 struct ecore_vf_info *vf)
3146 struct ecore_rss_params *p_rss_params = OSAL_NULL;
3147 struct ecore_sp_vport_update_params params;
3148 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
3149 struct ecore_sge_tpa_params sge_tpa_params;
3150 u16 tlvs_mask = 0, tlvs_accepted = 0;
3151 u8 status = PFVF_STATUS_SUCCESS;
3153 enum _ecore_status_t rc;
3155 /* Valiate PF can send such a request */
3156 if (!vf->vport_instance) {
3157 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3158 "No VPORT instance available for VF[%d],"
3159 " failing vport update\n",
3161 status = PFVF_STATUS_FAILURE;
3165 p_rss_params = OSAL_VZALLOC(p_hwfn->p_dev, sizeof(*p_rss_params));
3166 if (p_rss_params == OSAL_NULL) {
3167 status = PFVF_STATUS_FAILURE;
3171 OSAL_MEMSET(¶ms, 0, sizeof(params));
3172 params.opaque_fid = vf->opaque_fid;
3173 params.vport_id = vf->vport_id;
3174 params.rss_params = OSAL_NULL;
3176 /* Search for extended tlvs list and update values
3177 * from VF in struct ecore_sp_vport_update_params.
3179 ecore_iov_vp_update_act_param(p_hwfn, ¶ms, mbx, &tlvs_mask);
3180 ecore_iov_vp_update_vlan_param(p_hwfn, ¶ms, vf, mbx, &tlvs_mask);
3181 ecore_iov_vp_update_tx_switch(p_hwfn, ¶ms, mbx, &tlvs_mask);
3182 ecore_iov_vp_update_mcast_bin_param(p_hwfn, ¶ms, mbx, &tlvs_mask);
3183 ecore_iov_vp_update_accept_flag(p_hwfn, ¶ms, mbx, &tlvs_mask);
3184 ecore_iov_vp_update_accept_any_vlan(p_hwfn, ¶ms, mbx, &tlvs_mask);
3185 ecore_iov_vp_update_sge_tpa_param(p_hwfn, ¶ms,
3186 &sge_tpa_params, mbx, &tlvs_mask);
3188 tlvs_accepted = tlvs_mask;
3190 /* Some of the extended TLVs need to be validated first; In that case,
3191 * they can update the mask without updating the accepted [so that
3192 * PF could communicate to VF it has rejected request].
3194 ecore_iov_vp_update_rss_param(p_hwfn, vf, ¶ms, p_rss_params,
3195 mbx, &tlvs_mask, &tlvs_accepted);
3197 /* Just log a message if there is no single extended tlv in buffer.
3198 * When all features of vport update ramrod would be requested by VF
3199 * as extended TLVs in buffer then an error can be returned in response
3200 * if there is no extended TLV present in buffer.
3202 if (OSAL_IOV_VF_VPORT_UPDATE(p_hwfn, vf->relative_vf_id,
3203 ¶ms, &tlvs_accepted) !=
3206 status = PFVF_STATUS_NOT_SUPPORTED;
3210 if (!tlvs_accepted) {
3212 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3213 "Upper-layer prevents said VF"
3214 " configuration\n");
3216 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3217 "No feature tlvs found for vport update\n");
3218 status = PFVF_STATUS_NOT_SUPPORTED;
3222 rc = ecore_sp_vport_update(p_hwfn, ¶ms, ECORE_SPQ_MODE_EBLOCK,
3226 status = PFVF_STATUS_FAILURE;
3229 OSAL_VFREE(p_hwfn->p_dev, p_rss_params);
3230 length = ecore_iov_prep_vp_update_resp_tlvs(p_hwfn, vf, mbx, status,
3231 tlvs_mask, tlvs_accepted);
3232 ecore_iov_send_response(p_hwfn, p_ptt, vf, length, status);
3235 static enum _ecore_status_t
3236 ecore_iov_vf_update_vlan_shadow(struct ecore_hwfn *p_hwfn,
3237 struct ecore_vf_info *p_vf,
3238 struct ecore_filter_ucast *p_params)
3242 /* First remove entries and then add new ones */
3243 if (p_params->opcode == ECORE_FILTER_REMOVE) {
3244 for (i = 0; i < ECORE_ETH_VF_NUM_VLAN_FILTERS + 1; i++)
3245 if (p_vf->shadow_config.vlans[i].used &&
3246 p_vf->shadow_config.vlans[i].vid ==
3248 p_vf->shadow_config.vlans[i].used = false;
3251 if (i == ECORE_ETH_VF_NUM_VLAN_FILTERS + 1) {
3252 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3253 "VF [%d] - Tries to remove a non-existing"
3255 p_vf->relative_vf_id);
3258 } else if (p_params->opcode == ECORE_FILTER_REPLACE ||
3259 p_params->opcode == ECORE_FILTER_FLUSH) {
3260 for (i = 0; i < ECORE_ETH_VF_NUM_VLAN_FILTERS + 1; i++)
3261 p_vf->shadow_config.vlans[i].used = false;
3264 /* In forced mode, we're willing to remove entries - but we don't add
3267 if (p_vf->bulletin.p_virt->valid_bitmap & (1 << VLAN_ADDR_FORCED))
3268 return ECORE_SUCCESS;
3270 if (p_params->opcode == ECORE_FILTER_ADD ||
3271 p_params->opcode == ECORE_FILTER_REPLACE) {
3272 for (i = 0; i < ECORE_ETH_VF_NUM_VLAN_FILTERS + 1; i++) {
3273 if (p_vf->shadow_config.vlans[i].used)
3276 p_vf->shadow_config.vlans[i].used = true;
3277 p_vf->shadow_config.vlans[i].vid = p_params->vlan;
3281 if (i == ECORE_ETH_VF_NUM_VLAN_FILTERS + 1) {
3282 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3283 "VF [%d] - Tries to configure more than %d"
3285 p_vf->relative_vf_id,
3286 ECORE_ETH_VF_NUM_VLAN_FILTERS + 1);
3291 return ECORE_SUCCESS;
3294 static enum _ecore_status_t
3295 ecore_iov_vf_update_mac_shadow(struct ecore_hwfn *p_hwfn,
3296 struct ecore_vf_info *p_vf,
3297 struct ecore_filter_ucast *p_params)
3299 char empty_mac[ETH_ALEN];
3302 OSAL_MEM_ZERO(empty_mac, ETH_ALEN);
3304 /* If we're in forced-mode, we don't allow any change */
3305 /* TODO - this would change if we were ever to implement logic for
3306 * removing a forced MAC altogether [in which case, like for vlans,
3307 * we should be able to re-trace previous configuration.
3309 if (p_vf->bulletin.p_virt->valid_bitmap & (1 << MAC_ADDR_FORCED))
3310 return ECORE_SUCCESS;
3312 /* First remove entries and then add new ones */
3313 if (p_params->opcode == ECORE_FILTER_REMOVE) {
3314 for (i = 0; i < ECORE_ETH_VF_NUM_MAC_FILTERS; i++) {
3315 if (!OSAL_MEMCMP(p_vf->shadow_config.macs[i],
3316 p_params->mac, ETH_ALEN)) {
3317 OSAL_MEM_ZERO(p_vf->shadow_config.macs[i],
3323 if (i == ECORE_ETH_VF_NUM_MAC_FILTERS) {
3324 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3325 "MAC isn't configured\n");
3328 } else if (p_params->opcode == ECORE_FILTER_REPLACE ||
3329 p_params->opcode == ECORE_FILTER_FLUSH) {
3330 for (i = 0; i < ECORE_ETH_VF_NUM_MAC_FILTERS; i++)
3331 OSAL_MEM_ZERO(p_vf->shadow_config.macs[i], ETH_ALEN);
3334 /* List the new MAC address */
3335 if (p_params->opcode != ECORE_FILTER_ADD &&
3336 p_params->opcode != ECORE_FILTER_REPLACE)
3337 return ECORE_SUCCESS;
3339 for (i = 0; i < ECORE_ETH_VF_NUM_MAC_FILTERS; i++) {
3340 if (!OSAL_MEMCMP(p_vf->shadow_config.macs[i],
3341 empty_mac, ETH_ALEN)) {
3342 OSAL_MEMCPY(p_vf->shadow_config.macs[i],
3343 p_params->mac, ETH_ALEN);
3344 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3345 "Added MAC at %d entry in shadow\n", i);
3350 if (i == ECORE_ETH_VF_NUM_MAC_FILTERS) {
3351 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3352 "No available place for MAC\n");
3356 return ECORE_SUCCESS;
3359 static enum _ecore_status_t
3360 ecore_iov_vf_update_unicast_shadow(struct ecore_hwfn *p_hwfn,
3361 struct ecore_vf_info *p_vf,
3362 struct ecore_filter_ucast *p_params)
3364 enum _ecore_status_t rc = ECORE_SUCCESS;
3366 if (p_params->type == ECORE_FILTER_MAC) {
3367 rc = ecore_iov_vf_update_mac_shadow(p_hwfn, p_vf, p_params);
3368 if (rc != ECORE_SUCCESS)
3372 if (p_params->type == ECORE_FILTER_VLAN)
3373 rc = ecore_iov_vf_update_vlan_shadow(p_hwfn, p_vf, p_params);
3378 static void ecore_iov_vf_mbx_ucast_filter(struct ecore_hwfn *p_hwfn,
3379 struct ecore_ptt *p_ptt,
3380 struct ecore_vf_info *vf)
3382 struct ecore_bulletin_content *p_bulletin = vf->bulletin.p_virt;
3383 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
3384 struct vfpf_ucast_filter_tlv *req;
3385 u8 status = PFVF_STATUS_SUCCESS;
3386 struct ecore_filter_ucast params;
3387 enum _ecore_status_t rc;
3389 /* Prepare the unicast filter params */
3390 OSAL_MEMSET(¶ms, 0, sizeof(struct ecore_filter_ucast));
3391 req = &mbx->req_virt->ucast_filter;
3392 params.opcode = (enum ecore_filter_opcode)req->opcode;
3393 params.type = (enum ecore_filter_ucast_type)req->type;
3395 /* @@@TBD - We might need logic on HV side in determining this */
3396 params.is_rx_filter = 1;
3397 params.is_tx_filter = 1;
3398 params.vport_to_remove_from = vf->vport_id;
3399 params.vport_to_add_to = vf->vport_id;
3400 OSAL_MEMCPY(params.mac, req->mac, ETH_ALEN);
3401 params.vlan = req->vlan;
3403 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3404 "VF[%d]: opcode 0x%02x type 0x%02x [%s %s] [vport 0x%02x]"
3405 " MAC %02x:%02x:%02x:%02x:%02x:%02x, vlan 0x%04x\n",
3406 vf->abs_vf_id, params.opcode, params.type,
3407 params.is_rx_filter ? "RX" : "",
3408 params.is_tx_filter ? "TX" : "",
3409 params.vport_to_add_to,
3410 params.mac[0], params.mac[1], params.mac[2],
3411 params.mac[3], params.mac[4], params.mac[5], params.vlan);
3413 if (!vf->vport_instance) {
3414 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3415 "No VPORT instance available for VF[%d],"
3416 " failing ucast MAC configuration\n",
3418 status = PFVF_STATUS_FAILURE;
3422 /* Update shadow copy of the VF configuration. In case shadow indicates
3423 * the action should be blocked return success to VF to imitate the
3424 * firmware behaviour in such case.
3426 if (ecore_iov_vf_update_unicast_shadow(p_hwfn, vf, ¶ms) !=
3430 /* Determine if the unicast filtering is acceptible by PF */
3431 if ((p_bulletin->valid_bitmap & (1 << VLAN_ADDR_FORCED)) &&
3432 (params.type == ECORE_FILTER_VLAN ||
3433 params.type == ECORE_FILTER_MAC_VLAN)) {
3434 /* Once VLAN is forced or PVID is set, do not allow
3435 * to add/replace any further VLANs.
3437 if (params.opcode == ECORE_FILTER_ADD ||
3438 params.opcode == ECORE_FILTER_REPLACE)
3439 status = PFVF_STATUS_FORCED;
3443 if ((p_bulletin->valid_bitmap & (1 << MAC_ADDR_FORCED)) &&
3444 (params.type == ECORE_FILTER_MAC ||
3445 params.type == ECORE_FILTER_MAC_VLAN)) {
3446 if (OSAL_MEMCMP(p_bulletin->mac, params.mac, ETH_ALEN) ||
3447 (params.opcode != ECORE_FILTER_ADD &&
3448 params.opcode != ECORE_FILTER_REPLACE))
3449 status = PFVF_STATUS_FORCED;
3453 rc = OSAL_IOV_CHK_UCAST(p_hwfn, vf->relative_vf_id, ¶ms);
3454 if (rc == ECORE_EXISTS) {
3456 } else if (rc == ECORE_INVAL) {
3457 status = PFVF_STATUS_FAILURE;
3461 rc = ecore_sp_eth_filter_ucast(p_hwfn, vf->opaque_fid, ¶ms,
3462 ECORE_SPQ_MODE_CB, OSAL_NULL);
3464 status = PFVF_STATUS_FAILURE;
3467 ecore_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_UCAST_FILTER,
3468 sizeof(struct pfvf_def_resp_tlv), status);
3471 static void ecore_iov_vf_mbx_int_cleanup(struct ecore_hwfn *p_hwfn,
3472 struct ecore_ptt *p_ptt,
3473 struct ecore_vf_info *vf)
3478 for (i = 0; i < vf->num_sbs; i++)
3479 ecore_int_igu_init_pure_rt_single(p_hwfn, p_ptt,
3481 vf->opaque_fid, false);
3483 ecore_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_INT_CLEANUP,
3484 sizeof(struct pfvf_def_resp_tlv),
3485 PFVF_STATUS_SUCCESS);
3488 static void ecore_iov_vf_mbx_close(struct ecore_hwfn *p_hwfn,
3489 struct ecore_ptt *p_ptt,
3490 struct ecore_vf_info *vf)
3492 u16 length = sizeof(struct pfvf_def_resp_tlv);
3493 u8 status = PFVF_STATUS_SUCCESS;
3495 /* Disable Interrupts for VF */
3496 ecore_iov_vf_igu_set_int(p_hwfn, p_ptt, vf, 0);
3498 /* Reset Permission table */
3499 ecore_iov_config_perm_table(p_hwfn, p_ptt, vf, 0);
3501 ecore_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_CLOSE,
3505 static void ecore_iov_vf_mbx_release(struct ecore_hwfn *p_hwfn,
3506 struct ecore_ptt *p_ptt,
3507 struct ecore_vf_info *p_vf)
3509 u16 length = sizeof(struct pfvf_def_resp_tlv);
3510 u8 status = PFVF_STATUS_SUCCESS;
3511 enum _ecore_status_t rc = ECORE_SUCCESS;
3513 ecore_iov_vf_cleanup(p_hwfn, p_vf);
3515 if (p_vf->state != VF_STOPPED && p_vf->state != VF_FREE) {
3516 /* Stopping the VF */
3517 rc = ecore_sp_vf_stop(p_hwfn, p_vf->concrete_fid,
3520 if (rc != ECORE_SUCCESS) {
3521 DP_ERR(p_hwfn, "ecore_sp_vf_stop returned error %d\n",
3523 status = PFVF_STATUS_FAILURE;
3526 p_vf->state = VF_STOPPED;
3529 ecore_iov_prepare_resp(p_hwfn, p_ptt, p_vf, CHANNEL_TLV_RELEASE,
3533 static void ecore_iov_vf_pf_get_coalesce(struct ecore_hwfn *p_hwfn,
3534 struct ecore_ptt *p_ptt,
3535 struct ecore_vf_info *p_vf)
3537 struct ecore_iov_vf_mbx *mbx = &p_vf->vf_mbx;
3538 struct pfvf_read_coal_resp_tlv *p_resp;
3539 struct vfpf_read_coal_req_tlv *req;
3540 u8 status = PFVF_STATUS_FAILURE;
3541 struct ecore_vf_queue *p_queue;
3542 struct ecore_queue_cid *p_cid;
3543 enum _ecore_status_t rc = ECORE_SUCCESS;
3544 u16 coal = 0, qid, i;
3547 mbx->offset = (u8 *)mbx->reply_virt;
3548 req = &mbx->req_virt->read_coal_req;
3551 b_is_rx = req->is_rx ? true : false;
3554 if (!ecore_iov_validate_rxq(p_hwfn, p_vf, qid,
3555 ECORE_IOV_VALIDATE_Q_ENABLE)) {
3556 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3557 "VF[%d]: Invalid Rx queue_id = %d\n",
3558 p_vf->abs_vf_id, qid);
3562 p_cid = ecore_iov_get_vf_rx_queue_cid(&p_vf->vf_queues[qid]);
3563 rc = ecore_get_rxq_coalesce(p_hwfn, p_ptt, p_cid, &coal);
3564 if (rc != ECORE_SUCCESS)
3567 if (!ecore_iov_validate_txq(p_hwfn, p_vf, qid,
3568 ECORE_IOV_VALIDATE_Q_ENABLE)) {
3569 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3570 "VF[%d]: Invalid Tx queue_id = %d\n",
3571 p_vf->abs_vf_id, qid);
3574 for (i = 0; i < MAX_QUEUES_PER_QZONE; i++) {
3575 p_queue = &p_vf->vf_queues[qid];
3576 if ((p_queue->cids[i].p_cid == OSAL_NULL) ||
3577 (!p_queue->cids[i].b_is_tx))
3580 p_cid = p_queue->cids[i].p_cid;
3582 rc = ecore_get_txq_coalesce(p_hwfn, p_ptt,
3584 if (rc != ECORE_SUCCESS)
3590 status = PFVF_STATUS_SUCCESS;
3593 p_resp = ecore_add_tlv(&mbx->offset, CHANNEL_TLV_COALESCE_READ,
3595 p_resp->coal = coal;
3597 ecore_add_tlv(&mbx->offset, CHANNEL_TLV_LIST_END,
3598 sizeof(struct channel_list_end_tlv));
3600 ecore_iov_send_response(p_hwfn, p_ptt, p_vf, sizeof(*p_resp), status);
3603 static void ecore_iov_vf_pf_set_coalesce(struct ecore_hwfn *p_hwfn,
3604 struct ecore_ptt *p_ptt,
3605 struct ecore_vf_info *vf)
3607 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
3608 enum _ecore_status_t rc = ECORE_SUCCESS;
3609 struct vfpf_update_coalesce *req;
3610 u8 status = PFVF_STATUS_FAILURE;
3611 struct ecore_queue_cid *p_cid;
3612 u16 rx_coal, tx_coal;
3616 req = &mbx->req_virt->update_coalesce;
3618 rx_coal = req->rx_coal;
3619 tx_coal = req->tx_coal;
3622 if (!ecore_iov_validate_rxq(p_hwfn, vf, qid,
3623 ECORE_IOV_VALIDATE_Q_ENABLE) &&
3625 DP_ERR(p_hwfn, "VF[%d]: Invalid Rx queue_id = %d\n",
3626 vf->abs_vf_id, qid);
3630 if (!ecore_iov_validate_txq(p_hwfn, vf, qid,
3631 ECORE_IOV_VALIDATE_Q_ENABLE) &&
3633 DP_ERR(p_hwfn, "VF[%d]: Invalid Tx queue_id = %d\n",
3634 vf->abs_vf_id, qid);
3638 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3639 "VF[%d]: Setting coalesce for VF rx_coal = %d, tx_coal = %d at queue = %d\n",
3640 vf->abs_vf_id, rx_coal, tx_coal, qid);
3643 p_cid = ecore_iov_get_vf_rx_queue_cid(&vf->vf_queues[qid]);
3645 rc = ecore_set_rxq_coalesce(p_hwfn, p_ptt, rx_coal, p_cid);
3646 if (rc != ECORE_SUCCESS) {
3647 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3648 "VF[%d]: Unable to set rx queue = %d coalesce\n",
3649 vf->abs_vf_id, vf->vf_queues[qid].fw_rx_qid);
3652 vf->rx_coal = rx_coal;
3655 /* TODO - in future, it might be possible to pass this in a per-cid
3656 * granularity. For now, do this for all Tx queues.
3659 struct ecore_vf_queue *p_queue = &vf->vf_queues[qid];
3661 for (i = 0; i < MAX_QUEUES_PER_QZONE; i++) {
3662 if (p_queue->cids[i].p_cid == OSAL_NULL)
3665 if (!p_queue->cids[i].b_is_tx)
3668 rc = ecore_set_txq_coalesce(p_hwfn, p_ptt, tx_coal,
3669 p_queue->cids[i].p_cid);
3670 if (rc != ECORE_SUCCESS) {
3671 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3672 "VF[%d]: Unable to set tx queue coalesce\n",
3677 vf->tx_coal = tx_coal;
3680 status = PFVF_STATUS_SUCCESS;
3682 ecore_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_COALESCE_UPDATE,
3683 sizeof(struct pfvf_def_resp_tlv), status);
3686 enum _ecore_status_t
3687 ecore_iov_pf_configure_vf_queue_coalesce(struct ecore_hwfn *p_hwfn,
3688 u16 rx_coal, u16 tx_coal,
3691 struct ecore_queue_cid *p_cid;
3692 struct ecore_vf_info *vf;
3693 struct ecore_ptt *p_ptt;
3696 if (!ecore_iov_is_valid_vfid(p_hwfn, vf_id, true, true)) {
3697 DP_NOTICE(p_hwfn, true,
3698 "VF[%d] - Can not set coalescing: VF is not active\n",
3703 vf = &p_hwfn->pf_iov_info->vfs_array[vf_id];
3704 p_ptt = ecore_ptt_acquire(p_hwfn);
3708 if (!ecore_iov_validate_rxq(p_hwfn, vf, qid,
3709 ECORE_IOV_VALIDATE_Q_ENABLE) &&
3711 DP_ERR(p_hwfn, "VF[%d]: Invalid Rx queue_id = %d\n",
3712 vf->abs_vf_id, qid);
3716 if (!ecore_iov_validate_txq(p_hwfn, vf, qid,
3717 ECORE_IOV_VALIDATE_Q_ENABLE) &&
3719 DP_ERR(p_hwfn, "VF[%d]: Invalid Tx queue_id = %d\n",
3720 vf->abs_vf_id, qid);
3724 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3725 "VF[%d]: Setting coalesce for VF rx_coal = %d, tx_coal = %d at queue = %d\n",
3726 vf->abs_vf_id, rx_coal, tx_coal, qid);
3729 p_cid = ecore_iov_get_vf_rx_queue_cid(&vf->vf_queues[qid]);
3731 rc = ecore_set_rxq_coalesce(p_hwfn, p_ptt, rx_coal, p_cid);
3732 if (rc != ECORE_SUCCESS) {
3733 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3734 "VF[%d]: Unable to set rx queue = %d coalesce\n",
3735 vf->abs_vf_id, vf->vf_queues[qid].fw_rx_qid);
3738 vf->rx_coal = rx_coal;
3741 /* TODO - in future, it might be possible to pass this in a per-cid
3742 * granularity. For now, do this for all Tx queues.
3745 struct ecore_vf_queue *p_queue = &vf->vf_queues[qid];
3747 for (i = 0; i < MAX_QUEUES_PER_QZONE; i++) {
3748 if (p_queue->cids[i].p_cid == OSAL_NULL)
3751 if (!p_queue->cids[i].b_is_tx)
3754 rc = ecore_set_txq_coalesce(p_hwfn, p_ptt, tx_coal,
3755 p_queue->cids[i].p_cid);
3756 if (rc != ECORE_SUCCESS) {
3757 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3758 "VF[%d]: Unable to set tx queue coalesce\n",
3763 vf->tx_coal = tx_coal;
3767 ecore_ptt_release(p_hwfn, p_ptt);
3772 static enum _ecore_status_t
3773 ecore_iov_vf_flr_poll_dorq(struct ecore_hwfn *p_hwfn,
3774 struct ecore_vf_info *p_vf, struct ecore_ptt *p_ptt)
3779 ecore_fid_pretend(p_hwfn, p_ptt, (u16)p_vf->concrete_fid);
3781 for (cnt = 0; cnt < 50; cnt++) {
3782 val = ecore_rd(p_hwfn, p_ptt, DORQ_REG_VF_USAGE_CNT);
3787 ecore_fid_pretend(p_hwfn, p_ptt, (u16)p_hwfn->hw_info.concrete_fid);
3791 "VF[%d] - dorq failed to cleanup [usage 0x%08x]\n",
3792 p_vf->abs_vf_id, val);
3793 return ECORE_TIMEOUT;
3796 return ECORE_SUCCESS;
3799 static enum _ecore_status_t
3800 ecore_iov_vf_flr_poll_pbf(struct ecore_hwfn *p_hwfn,
3801 struct ecore_vf_info *p_vf, struct ecore_ptt *p_ptt)
3803 u32 cons[MAX_NUM_VOQS_E4], distance[MAX_NUM_VOQS_E4];
3806 /* Read initial consumers & producers */
3807 for (i = 0; i < MAX_NUM_VOQS_E4; i++) {
3810 cons[i] = ecore_rd(p_hwfn, p_ptt,
3811 PBF_REG_NUM_BLOCKS_ALLOCATED_CONS_VOQ0 +
3813 prod = ecore_rd(p_hwfn, p_ptt,
3814 PBF_REG_NUM_BLOCKS_ALLOCATED_PROD_VOQ0 +
3816 distance[i] = prod - cons[i];
3819 /* Wait for consumers to pass the producers */
3821 for (cnt = 0; cnt < 50; cnt++) {
3822 for (; i < MAX_NUM_VOQS_E4; i++) {
3825 tmp = ecore_rd(p_hwfn, p_ptt,
3826 PBF_REG_NUM_BLOCKS_ALLOCATED_CONS_VOQ0 +
3828 if (distance[i] > tmp - cons[i])
3832 if (i == MAX_NUM_VOQS_E4)
3839 DP_ERR(p_hwfn, "VF[%d] - pbf polling failed on VOQ %d\n",
3840 p_vf->abs_vf_id, i);
3841 return ECORE_TIMEOUT;
3844 return ECORE_SUCCESS;
3847 static enum _ecore_status_t ecore_iov_vf_flr_poll(struct ecore_hwfn *p_hwfn,
3848 struct ecore_vf_info *p_vf,
3849 struct ecore_ptt *p_ptt)
3851 enum _ecore_status_t rc;
3853 /* TODO - add SRC and TM polling once we add storage IOV */
3855 rc = ecore_iov_vf_flr_poll_dorq(p_hwfn, p_vf, p_ptt);
3859 rc = ecore_iov_vf_flr_poll_pbf(p_hwfn, p_vf, p_ptt);
3863 return ECORE_SUCCESS;
3866 static enum _ecore_status_t
3867 ecore_iov_execute_vf_flr_cleanup(struct ecore_hwfn *p_hwfn,
3868 struct ecore_ptt *p_ptt,
3869 u16 rel_vf_id, u32 *ack_vfs)
3871 struct ecore_vf_info *p_vf;
3872 enum _ecore_status_t rc = ECORE_SUCCESS;
3874 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, false);
3876 return ECORE_SUCCESS;
3878 if (p_hwfn->pf_iov_info->pending_flr[rel_vf_id / 64] &
3879 (1ULL << (rel_vf_id % 64))) {
3880 u16 vfid = p_vf->abs_vf_id;
3882 /* TODO - should we lock channel? */
3884 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3885 "VF[%d] - Handling FLR\n", vfid);
3887 ecore_iov_vf_cleanup(p_hwfn, p_vf);
3889 /* If VF isn't active, no need for anything but SW */
3893 /* TODO - what to do in case of failure? */
3894 rc = ecore_iov_vf_flr_poll(p_hwfn, p_vf, p_ptt);
3895 if (rc != ECORE_SUCCESS)
3898 rc = ecore_final_cleanup(p_hwfn, p_ptt, vfid, true);
3900 /* TODO - what's now? What a mess.... */
3901 DP_ERR(p_hwfn, "Failed handle FLR of VF[%d]\n", vfid);
3905 /* Workaround to make VF-PF channel ready, as FW
3906 * doesn't do that as a part of FLR.
3909 GTT_BAR0_MAP_REG_USDM_RAM +
3910 USTORM_VF_PF_CHANNEL_READY_OFFSET(vfid), 1);
3912 /* VF_STOPPED has to be set only after final cleanup
3913 * but prior to re-enabling the VF.
3915 p_vf->state = VF_STOPPED;
3917 rc = ecore_iov_enable_vf_access(p_hwfn, p_ptt, p_vf);
3919 /* TODO - again, a mess... */
3920 DP_ERR(p_hwfn, "Failed to re-enable VF[%d] acces\n",
3925 /* Mark VF for ack and clean pending state */
3926 if (p_vf->state == VF_RESET)
3927 p_vf->state = VF_STOPPED;
3928 ack_vfs[vfid / 32] |= (1 << (vfid % 32));
3929 p_hwfn->pf_iov_info->pending_flr[rel_vf_id / 64] &=
3930 ~(1ULL << (rel_vf_id % 64));
3931 p_vf->vf_mbx.b_pending_msg = false;
3937 enum _ecore_status_t ecore_iov_vf_flr_cleanup(struct ecore_hwfn *p_hwfn,
3938 struct ecore_ptt *p_ptt)
3940 u32 ack_vfs[VF_MAX_STATIC / 32];
3941 enum _ecore_status_t rc = ECORE_SUCCESS;
3944 OSAL_MEMSET(ack_vfs, 0, sizeof(u32) * (VF_MAX_STATIC / 32));
3946 /* Since BRB <-> PRS interface can't be tested as part of the flr
3947 * polling due to HW limitations, simply sleep a bit. And since
3948 * there's no need to wait per-vf, do it before looping.
3952 for (i = 0; i < p_hwfn->p_dev->p_iov_info->total_vfs; i++)
3953 ecore_iov_execute_vf_flr_cleanup(p_hwfn, p_ptt, i, ack_vfs);
3955 rc = ecore_mcp_ack_vf_flr(p_hwfn, p_ptt, ack_vfs);
3959 enum _ecore_status_t
3960 ecore_iov_single_vf_flr_cleanup(struct ecore_hwfn *p_hwfn,
3961 struct ecore_ptt *p_ptt, u16 rel_vf_id)
3963 u32 ack_vfs[VF_MAX_STATIC / 32];
3964 enum _ecore_status_t rc = ECORE_SUCCESS;
3966 OSAL_MEMSET(ack_vfs, 0, sizeof(u32) * (VF_MAX_STATIC / 32));
3968 /* Wait instead of polling the BRB <-> PRS interface */
3971 ecore_iov_execute_vf_flr_cleanup(p_hwfn, p_ptt, rel_vf_id, ack_vfs);
3973 rc = ecore_mcp_ack_vf_flr(p_hwfn, p_ptt, ack_vfs);
3977 bool ecore_iov_mark_vf_flr(struct ecore_hwfn *p_hwfn, u32 *p_disabled_vfs)
3982 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV, "Marking FLR-ed VFs\n");
3983 for (i = 0; i < (VF_MAX_STATIC / 32); i++)
3984 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3985 "[%08x,...,%08x]: %08x\n",
3986 i * 32, (i + 1) * 32 - 1, p_disabled_vfs[i]);
3988 if (!p_hwfn->p_dev->p_iov_info) {
3989 DP_NOTICE(p_hwfn, true, "VF flr but no IOV\n");
3994 for (i = 0; i < p_hwfn->p_dev->p_iov_info->total_vfs; i++) {
3995 struct ecore_vf_info *p_vf;
3998 p_vf = ecore_iov_get_vf_info(p_hwfn, i, false);
4002 vfid = p_vf->abs_vf_id;
4003 if ((1 << (vfid % 32)) & p_disabled_vfs[vfid / 32]) {
4004 u64 *p_flr = p_hwfn->pf_iov_info->pending_flr;
4005 u16 rel_vf_id = p_vf->relative_vf_id;
4007 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
4008 "VF[%d] [rel %d] got FLR-ed\n",
4011 p_vf->state = VF_RESET;
4013 /* No need to lock here, since pending_flr should
4014 * only change here and before ACKing MFw. Since
4015 * MFW will not trigger an additional attention for
4016 * VF flr until ACKs, we're safe.
4018 p_flr[rel_vf_id / 64] |= 1ULL << (rel_vf_id % 64);
4026 void ecore_iov_get_link(struct ecore_hwfn *p_hwfn,
4028 struct ecore_mcp_link_params *p_params,
4029 struct ecore_mcp_link_state *p_link,
4030 struct ecore_mcp_link_capabilities *p_caps)
4032 struct ecore_vf_info *p_vf = ecore_iov_get_vf_info(p_hwfn, vfid, false);
4033 struct ecore_bulletin_content *p_bulletin;
4038 p_bulletin = p_vf->bulletin.p_virt;
4041 __ecore_vf_get_link_params(p_params, p_bulletin);
4043 __ecore_vf_get_link_state(p_link, p_bulletin);
4045 __ecore_vf_get_link_caps(p_caps, p_bulletin);
4048 void ecore_iov_process_mbx_req(struct ecore_hwfn *p_hwfn,
4049 struct ecore_ptt *p_ptt, int vfid)
4051 struct ecore_iov_vf_mbx *mbx;
4052 struct ecore_vf_info *p_vf;
4054 p_vf = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4058 mbx = &p_vf->vf_mbx;
4060 /* ecore_iov_process_mbx_request */
4061 #ifndef CONFIG_ECORE_SW_CHANNEL
4062 if (!mbx->b_pending_msg) {
4063 DP_NOTICE(p_hwfn, true,
4064 "VF[%02x]: Trying to process mailbox message when none is pending\n",
4068 mbx->b_pending_msg = false;
4071 mbx->first_tlv = mbx->req_virt->first_tlv;
4073 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
4074 "VF[%02x]: Processing mailbox message [type %04x]\n",
4075 p_vf->abs_vf_id, mbx->first_tlv.tl.type);
4077 OSAL_IOV_VF_MSG_TYPE(p_hwfn,
4078 p_vf->relative_vf_id,
4079 mbx->first_tlv.tl.type);
4081 /* Lock the per vf op mutex and note the locker's identity.
4082 * The unlock will take place in mbx response.
4084 ecore_iov_lock_vf_pf_channel(p_hwfn,
4085 p_vf, mbx->first_tlv.tl.type);
4087 /* check if tlv type is known */
4088 if (ecore_iov_tlv_supported(mbx->first_tlv.tl.type) &&
4089 !p_vf->b_malicious) {
4090 /* switch on the opcode */
4091 switch (mbx->first_tlv.tl.type) {
4092 case CHANNEL_TLV_ACQUIRE:
4093 ecore_iov_vf_mbx_acquire(p_hwfn, p_ptt, p_vf);
4095 case CHANNEL_TLV_VPORT_START:
4096 ecore_iov_vf_mbx_start_vport(p_hwfn, p_ptt, p_vf);
4098 case CHANNEL_TLV_VPORT_TEARDOWN:
4099 ecore_iov_vf_mbx_stop_vport(p_hwfn, p_ptt, p_vf);
4101 case CHANNEL_TLV_START_RXQ:
4102 ecore_iov_vf_mbx_start_rxq(p_hwfn, p_ptt, p_vf);
4104 case CHANNEL_TLV_START_TXQ:
4105 ecore_iov_vf_mbx_start_txq(p_hwfn, p_ptt, p_vf);
4107 case CHANNEL_TLV_STOP_RXQS:
4108 ecore_iov_vf_mbx_stop_rxqs(p_hwfn, p_ptt, p_vf);
4110 case CHANNEL_TLV_STOP_TXQS:
4111 ecore_iov_vf_mbx_stop_txqs(p_hwfn, p_ptt, p_vf);
4113 case CHANNEL_TLV_UPDATE_RXQ:
4114 ecore_iov_vf_mbx_update_rxqs(p_hwfn, p_ptt, p_vf);
4116 case CHANNEL_TLV_VPORT_UPDATE:
4117 ecore_iov_vf_mbx_vport_update(p_hwfn, p_ptt, p_vf);
4119 case CHANNEL_TLV_UCAST_FILTER:
4120 ecore_iov_vf_mbx_ucast_filter(p_hwfn, p_ptt, p_vf);
4122 case CHANNEL_TLV_CLOSE:
4123 ecore_iov_vf_mbx_close(p_hwfn, p_ptt, p_vf);
4125 case CHANNEL_TLV_INT_CLEANUP:
4126 ecore_iov_vf_mbx_int_cleanup(p_hwfn, p_ptt, p_vf);
4128 case CHANNEL_TLV_RELEASE:
4129 ecore_iov_vf_mbx_release(p_hwfn, p_ptt, p_vf);
4131 case CHANNEL_TLV_UPDATE_TUNN_PARAM:
4132 ecore_iov_vf_mbx_update_tunn_param(p_hwfn, p_ptt, p_vf);
4134 case CHANNEL_TLV_COALESCE_UPDATE:
4135 ecore_iov_vf_pf_set_coalesce(p_hwfn, p_ptt, p_vf);
4137 case CHANNEL_TLV_COALESCE_READ:
4138 ecore_iov_vf_pf_get_coalesce(p_hwfn, p_ptt, p_vf);
4141 } else if (ecore_iov_tlv_supported(mbx->first_tlv.tl.type)) {
4142 /* If we've received a message from a VF we consider malicious
4143 * we ignore the messasge unless it's one for RELEASE, in which
4144 * case we'll let it have the benefit of doubt, allowing the
4145 * next loaded driver to start again.
4147 if (mbx->first_tlv.tl.type == CHANNEL_TLV_RELEASE) {
4148 /* TODO - initiate FLR, remove malicious indication */
4149 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
4150 "VF [%02x] - considered malicious, but wanted to RELEASE. TODO\n",
4153 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
4154 "VF [%02x] - considered malicious; Ignoring TLV [%04x]\n",
4155 p_vf->abs_vf_id, mbx->first_tlv.tl.type);
4158 ecore_iov_prepare_resp(p_hwfn, p_ptt, p_vf,
4159 mbx->first_tlv.tl.type,
4160 sizeof(struct pfvf_def_resp_tlv),
4161 PFVF_STATUS_MALICIOUS);
4163 /* unknown TLV - this may belong to a VF driver from the future
4164 * - a version written after this PF driver was written, which
4165 * supports features unknown as of yet. Too bad since we don't
4166 * support them. Or this may be because someone wrote a crappy
4167 * VF driver and is sending garbage over the channel.
4169 DP_NOTICE(p_hwfn, false,
4170 "VF[%02x]: unknown TLV. type %04x length %04x"
4171 " padding %08x reply address %lu\n",
4173 mbx->first_tlv.tl.type,
4174 mbx->first_tlv.tl.length,
4175 mbx->first_tlv.padding,
4176 (unsigned long)mbx->first_tlv.reply_address);
4178 /* Try replying in case reply address matches the acquisition's
4181 if (p_vf->acquire.first_tlv.reply_address &&
4182 (mbx->first_tlv.reply_address ==
4183 p_vf->acquire.first_tlv.reply_address))
4184 ecore_iov_prepare_resp(p_hwfn, p_ptt, p_vf,
4185 mbx->first_tlv.tl.type,
4186 sizeof(struct pfvf_def_resp_tlv),
4187 PFVF_STATUS_NOT_SUPPORTED);
4189 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
4190 "VF[%02x]: Can't respond to TLV -"
4191 " no valid reply address\n",
4195 ecore_iov_unlock_vf_pf_channel(p_hwfn, p_vf,
4196 mbx->first_tlv.tl.type);
4198 #ifdef CONFIG_ECORE_SW_CHANNEL
4199 mbx->sw_mbx.mbx_state = VF_PF_RESPONSE_READY;
4200 mbx->sw_mbx.response_offset = 0;
4204 void ecore_iov_pf_get_pending_events(struct ecore_hwfn *p_hwfn,
4209 OSAL_MEM_ZERO(events, sizeof(u64) * ECORE_VF_ARRAY_LENGTH);
4211 ecore_for_each_vf(p_hwfn, i) {
4212 struct ecore_vf_info *p_vf;
4214 p_vf = &p_hwfn->pf_iov_info->vfs_array[i];
4215 if (p_vf->vf_mbx.b_pending_msg)
4216 events[i / 64] |= 1ULL << (i % 64);
4220 static struct ecore_vf_info *
4221 ecore_sriov_get_vf_from_absid(struct ecore_hwfn *p_hwfn, u16 abs_vfid)
4223 u8 min = (u8)p_hwfn->p_dev->p_iov_info->first_vf_in_pf;
4225 if (!_ecore_iov_pf_sanity_check(p_hwfn, (int)abs_vfid - min, false)) {
4226 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
4227 "Got indication for VF [abs 0x%08x] that cannot be"
4233 return &p_hwfn->pf_iov_info->vfs_array[(u8)abs_vfid - min];
4236 static enum _ecore_status_t ecore_sriov_vfpf_msg(struct ecore_hwfn *p_hwfn,
4238 struct regpair *vf_msg)
4240 struct ecore_vf_info *p_vf = ecore_sriov_get_vf_from_absid(p_hwfn,
4244 return ECORE_SUCCESS;
4246 /* List the physical address of the request so that handler
4247 * could later on copy the message from it.
4249 p_vf->vf_mbx.pending_req = (((u64)vf_msg->hi) << 32) | vf_msg->lo;
4251 p_vf->vf_mbx.b_pending_msg = true;
4253 return OSAL_PF_VF_MSG(p_hwfn, p_vf->relative_vf_id);
4256 static void ecore_sriov_vfpf_malicious(struct ecore_hwfn *p_hwfn,
4257 struct malicious_vf_eqe_data *p_data)
4259 struct ecore_vf_info *p_vf;
4261 p_vf = ecore_sriov_get_vf_from_absid(p_hwfn, p_data->vf_id);
4266 if (!p_vf->b_malicious) {
4267 DP_NOTICE(p_hwfn, false,
4268 "VF [%d] - Malicious behavior [%02x]\n",
4269 p_vf->abs_vf_id, p_data->err_id);
4271 p_vf->b_malicious = true;
4274 "VF [%d] - Malicious behavior [%02x]\n",
4275 p_vf->abs_vf_id, p_data->err_id);
4278 OSAL_PF_VF_MALICIOUS(p_hwfn, p_vf->relative_vf_id);
4281 static enum _ecore_status_t ecore_sriov_eqe_event(struct ecore_hwfn *p_hwfn,
4284 union event_ring_data *data,
4285 u8 OSAL_UNUSED fw_return_code)
4288 case COMMON_EVENT_VF_PF_CHANNEL:
4289 return ecore_sriov_vfpf_msg(p_hwfn, OSAL_LE16_TO_CPU(echo),
4290 &data->vf_pf_channel.msg_addr);
4291 case COMMON_EVENT_VF_FLR:
4292 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
4293 "VF-FLR is still not supported\n");
4294 return ECORE_SUCCESS;
4295 case COMMON_EVENT_MALICIOUS_VF:
4296 ecore_sriov_vfpf_malicious(p_hwfn, &data->malicious_vf);
4297 return ECORE_SUCCESS;
4299 DP_INFO(p_hwfn->p_dev, "Unknown sriov eqe event 0x%02x\n",
4305 bool ecore_iov_is_vf_pending_flr(struct ecore_hwfn *p_hwfn, u16 rel_vf_id)
4307 return !!(p_hwfn->pf_iov_info->pending_flr[rel_vf_id / 64] &
4308 (1ULL << (rel_vf_id % 64)));
4311 u16 ecore_iov_get_next_active_vf(struct ecore_hwfn *p_hwfn, u16 rel_vf_id)
4313 struct ecore_hw_sriov_info *p_iov = p_hwfn->p_dev->p_iov_info;
4319 for (i = rel_vf_id; i < p_iov->total_vfs; i++)
4320 if (ecore_iov_is_valid_vfid(p_hwfn, rel_vf_id, true, false))
4324 return MAX_NUM_VFS_E4;
4327 enum _ecore_status_t ecore_iov_copy_vf_msg(struct ecore_hwfn *p_hwfn,
4328 struct ecore_ptt *ptt, int vfid)
4330 struct ecore_dmae_params params;
4331 struct ecore_vf_info *vf_info;
4333 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4337 OSAL_MEMSET(¶ms, 0, sizeof(struct ecore_dmae_params));
4338 params.flags = ECORE_DMAE_FLAG_VF_SRC | ECORE_DMAE_FLAG_COMPLETION_DST;
4339 params.src_vfid = vf_info->abs_vf_id;
4341 if (ecore_dmae_host2host(p_hwfn, ptt,
4342 vf_info->vf_mbx.pending_req,
4343 vf_info->vf_mbx.req_phys,
4344 sizeof(union vfpf_tlvs) / 4, ¶ms)) {
4345 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
4346 "Failed to copy message from VF 0x%02x\n", vfid);
4351 return ECORE_SUCCESS;
4354 void ecore_iov_bulletin_set_forced_mac(struct ecore_hwfn *p_hwfn,
4357 struct ecore_vf_info *vf_info;
4360 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4362 DP_NOTICE(p_hwfn->p_dev, true,
4363 "Can not set forced MAC, invalid vfid [%d]\n", vfid);
4366 if (vf_info->b_malicious) {
4367 DP_NOTICE(p_hwfn->p_dev, false,
4368 "Can't set forced MAC to malicious VF [%d]\n",
4373 feature = 1 << MAC_ADDR_FORCED;
4374 OSAL_MEMCPY(vf_info->bulletin.p_virt->mac, mac, ETH_ALEN);
4376 vf_info->bulletin.p_virt->valid_bitmap |= feature;
4377 /* Forced MAC will disable MAC_ADDR */
4378 vf_info->bulletin.p_virt->valid_bitmap &=
4379 ~(1 << VFPF_BULLETIN_MAC_ADDR);
4381 ecore_iov_configure_vport_forced(p_hwfn, vf_info, feature);
4384 enum _ecore_status_t ecore_iov_bulletin_set_mac(struct ecore_hwfn *p_hwfn,
4387 struct ecore_vf_info *vf_info;
4390 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4392 DP_NOTICE(p_hwfn->p_dev, true,
4393 "Can not set MAC, invalid vfid [%d]\n", vfid);
4396 if (vf_info->b_malicious) {
4397 DP_NOTICE(p_hwfn->p_dev, false,
4398 "Can't set MAC to malicious VF [%d]\n",
4403 if (vf_info->bulletin.p_virt->valid_bitmap & (1 << MAC_ADDR_FORCED)) {
4404 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
4405 "Can not set MAC, Forced MAC is configured\n");
4409 feature = 1 << VFPF_BULLETIN_MAC_ADDR;
4410 OSAL_MEMCPY(vf_info->bulletin.p_virt->mac, mac, ETH_ALEN);
4412 vf_info->bulletin.p_virt->valid_bitmap |= feature;
4414 return ECORE_SUCCESS;
4417 enum _ecore_status_t
4418 ecore_iov_bulletin_set_forced_untagged_default(struct ecore_hwfn *p_hwfn,
4419 bool b_untagged_only, int vfid)
4421 struct ecore_vf_info *vf_info;
4424 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4426 DP_NOTICE(p_hwfn->p_dev, true,
4427 "Can not set untagged default, invalid vfid [%d]\n",
4431 if (vf_info->b_malicious) {
4432 DP_NOTICE(p_hwfn->p_dev, false,
4433 "Can't set untagged default to malicious VF [%d]\n",
4438 /* Since this is configurable only during vport-start, don't take it
4439 * if we're past that point.
4441 if (vf_info->state == VF_ENABLED) {
4442 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
4443 "Can't support untagged change for vfid[%d] -"
4444 " VF is already active\n",
4449 /* Set configuration; This will later be taken into account during the
4450 * VF initialization.
4452 feature = (1 << VFPF_BULLETIN_UNTAGGED_DEFAULT) |
4453 (1 << VFPF_BULLETIN_UNTAGGED_DEFAULT_FORCED);
4454 vf_info->bulletin.p_virt->valid_bitmap |= feature;
4456 vf_info->bulletin.p_virt->default_only_untagged = b_untagged_only ? 1
4459 return ECORE_SUCCESS;
4462 void ecore_iov_get_vfs_opaque_fid(struct ecore_hwfn *p_hwfn, int vfid,
4465 struct ecore_vf_info *vf_info;
4467 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4471 *opaque_fid = vf_info->opaque_fid;
4474 void ecore_iov_bulletin_set_forced_vlan(struct ecore_hwfn *p_hwfn,
4477 struct ecore_vf_info *vf_info;
4480 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4482 DP_NOTICE(p_hwfn->p_dev, true,
4483 "Can not set forced MAC, invalid vfid [%d]\n",
4487 if (vf_info->b_malicious) {
4488 DP_NOTICE(p_hwfn->p_dev, false,
4489 "Can't set forced vlan to malicious VF [%d]\n",
4494 feature = 1 << VLAN_ADDR_FORCED;
4495 vf_info->bulletin.p_virt->pvid = pvid;
4497 vf_info->bulletin.p_virt->valid_bitmap |= feature;
4499 vf_info->bulletin.p_virt->valid_bitmap &= ~feature;
4501 ecore_iov_configure_vport_forced(p_hwfn, vf_info, feature);
4504 void ecore_iov_bulletin_set_udp_ports(struct ecore_hwfn *p_hwfn,
4505 int vfid, u16 vxlan_port, u16 geneve_port)
4507 struct ecore_vf_info *vf_info;
4509 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4511 DP_NOTICE(p_hwfn->p_dev, true,
4512 "Can not set udp ports, invalid vfid [%d]\n", vfid);
4516 if (vf_info->b_malicious) {
4517 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
4518 "Can not set udp ports to malicious VF [%d]\n",
4523 vf_info->bulletin.p_virt->vxlan_udp_port = vxlan_port;
4524 vf_info->bulletin.p_virt->geneve_udp_port = geneve_port;
4527 bool ecore_iov_vf_has_vport_instance(struct ecore_hwfn *p_hwfn, int vfid)
4529 struct ecore_vf_info *p_vf_info;
4531 p_vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4535 return !!p_vf_info->vport_instance;
4538 bool ecore_iov_is_vf_stopped(struct ecore_hwfn *p_hwfn, int vfid)
4540 struct ecore_vf_info *p_vf_info;
4542 p_vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4546 return p_vf_info->state == VF_STOPPED;
4549 bool ecore_iov_spoofchk_get(struct ecore_hwfn *p_hwfn, int vfid)
4551 struct ecore_vf_info *vf_info;
4553 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4557 return vf_info->spoof_chk;
4560 enum _ecore_status_t ecore_iov_spoofchk_set(struct ecore_hwfn *p_hwfn,
4563 struct ecore_vf_info *vf;
4564 enum _ecore_status_t rc = ECORE_INVAL;
4566 if (!ecore_iov_pf_sanity_check(p_hwfn, vfid)) {
4567 DP_NOTICE(p_hwfn, true,
4568 "SR-IOV sanity check failed, can't set spoofchk\n");
4572 vf = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4576 if (!ecore_iov_vf_has_vport_instance(p_hwfn, vfid)) {
4577 /* After VF VPORT start PF will configure spoof check */
4578 vf->req_spoofchk_val = val;
4583 rc = __ecore_iov_spoofchk_set(p_hwfn, vf, val);
4589 u8 ecore_iov_vf_chains_per_pf(struct ecore_hwfn *p_hwfn)
4591 u8 max_chains_per_vf = p_hwfn->hw_info.max_chains_per_vf;
4593 max_chains_per_vf = (max_chains_per_vf) ? max_chains_per_vf
4594 : ECORE_MAX_VF_CHAINS_PER_PF;
4596 return max_chains_per_vf;
4599 void ecore_iov_get_vf_req_virt_mbx_params(struct ecore_hwfn *p_hwfn,
4601 void **pp_req_virt_addr,
4602 u16 *p_req_virt_size)
4604 struct ecore_vf_info *vf_info =
4605 ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4610 if (pp_req_virt_addr)
4611 *pp_req_virt_addr = vf_info->vf_mbx.req_virt;
4613 if (p_req_virt_size)
4614 *p_req_virt_size = sizeof(*vf_info->vf_mbx.req_virt);
4617 void ecore_iov_get_vf_reply_virt_mbx_params(struct ecore_hwfn *p_hwfn,
4619 void **pp_reply_virt_addr,
4620 u16 *p_reply_virt_size)
4622 struct ecore_vf_info *vf_info =
4623 ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4628 if (pp_reply_virt_addr)
4629 *pp_reply_virt_addr = vf_info->vf_mbx.reply_virt;
4631 if (p_reply_virt_size)
4632 *p_reply_virt_size = sizeof(*vf_info->vf_mbx.reply_virt);
4635 #ifdef CONFIG_ECORE_SW_CHANNEL
4636 struct ecore_iov_sw_mbx *ecore_iov_get_vf_sw_mbx(struct ecore_hwfn *p_hwfn,
4639 struct ecore_vf_info *vf_info =
4640 ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4645 return &vf_info->vf_mbx.sw_mbx;
4649 bool ecore_iov_is_valid_vfpf_msg_length(u32 length)
4651 return (length >= sizeof(struct vfpf_first_tlv) &&
4652 (length <= sizeof(union vfpf_tlvs)));
4655 u32 ecore_iov_pfvf_msg_length(void)
4657 return sizeof(union pfvf_tlvs);
4660 u8 *ecore_iov_bulletin_get_forced_mac(struct ecore_hwfn *p_hwfn, u16 rel_vf_id)
4662 struct ecore_vf_info *p_vf;
4664 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4665 if (!p_vf || !p_vf->bulletin.p_virt)
4668 if (!(p_vf->bulletin.p_virt->valid_bitmap & (1 << MAC_ADDR_FORCED)))
4671 return p_vf->bulletin.p_virt->mac;
4674 u16 ecore_iov_bulletin_get_forced_vlan(struct ecore_hwfn *p_hwfn,
4677 struct ecore_vf_info *p_vf;
4679 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4680 if (!p_vf || !p_vf->bulletin.p_virt)
4683 if (!(p_vf->bulletin.p_virt->valid_bitmap & (1 << VLAN_ADDR_FORCED)))
4686 return p_vf->bulletin.p_virt->pvid;
4689 enum _ecore_status_t ecore_iov_configure_tx_rate(struct ecore_hwfn *p_hwfn,
4690 struct ecore_ptt *p_ptt,
4693 struct ecore_mcp_link_state *p_link;
4694 struct ecore_vf_info *vf;
4696 enum _ecore_status_t rc;
4698 vf = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4703 rc = ecore_fw_vport(p_hwfn, vf->vport_id, &abs_vp_id);
4704 if (rc != ECORE_SUCCESS)
4707 p_link = &ECORE_LEADING_HWFN(p_hwfn->p_dev)->mcp_info->link_output;
4709 return ecore_init_vport_rl(p_hwfn, p_ptt, abs_vp_id, (u32)val,
4713 enum _ecore_status_t ecore_iov_get_vf_stats(struct ecore_hwfn *p_hwfn,
4714 struct ecore_ptt *p_ptt,
4716 struct ecore_eth_stats *p_stats)
4718 struct ecore_vf_info *vf;
4720 vf = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4724 if (vf->state != VF_ENABLED)
4727 __ecore_get_vport_stats(p_hwfn, p_ptt, p_stats,
4728 vf->abs_vf_id + 0x10, false);
4730 return ECORE_SUCCESS;
4733 u8 ecore_iov_get_vf_num_rxqs(struct ecore_hwfn *p_hwfn, u16 rel_vf_id)
4735 struct ecore_vf_info *p_vf;
4737 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4741 return p_vf->num_rxqs;
4744 u8 ecore_iov_get_vf_num_active_rxqs(struct ecore_hwfn *p_hwfn, u16 rel_vf_id)
4746 struct ecore_vf_info *p_vf;
4748 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4752 return p_vf->num_active_rxqs;
4755 void *ecore_iov_get_vf_ctx(struct ecore_hwfn *p_hwfn, u16 rel_vf_id)
4757 struct ecore_vf_info *p_vf;
4759 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4766 u8 ecore_iov_get_vf_num_sbs(struct ecore_hwfn *p_hwfn, u16 rel_vf_id)
4768 struct ecore_vf_info *p_vf;
4770 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4774 return p_vf->num_sbs;
4777 bool ecore_iov_is_vf_wait_for_acquire(struct ecore_hwfn *p_hwfn, u16 rel_vf_id)
4779 struct ecore_vf_info *p_vf;
4781 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4785 return (p_vf->state == VF_FREE);
4788 bool ecore_iov_is_vf_acquired_not_initialized(struct ecore_hwfn *p_hwfn,
4791 struct ecore_vf_info *p_vf;
4793 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4797 return (p_vf->state == VF_ACQUIRED);
4800 bool ecore_iov_is_vf_initialized(struct ecore_hwfn *p_hwfn, u16 rel_vf_id)
4802 struct ecore_vf_info *p_vf;
4804 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4808 return (p_vf->state == VF_ENABLED);
4811 bool ecore_iov_is_vf_started(struct ecore_hwfn *p_hwfn,
4814 struct ecore_vf_info *p_vf;
4816 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4820 return (p_vf->state != VF_FREE && p_vf->state != VF_STOPPED);
4823 enum _ecore_status_t
4824 ecore_iov_get_vf_min_rate(struct ecore_hwfn *p_hwfn, int vfid)
4826 struct ecore_wfq_data *vf_vp_wfq;
4827 struct ecore_vf_info *vf_info;
4829 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4833 vf_vp_wfq = &p_hwfn->qm_info.wfq_data[vf_info->vport_id];
4835 if (vf_vp_wfq->configured)
4836 return vf_vp_wfq->min_speed;
4841 #ifdef CONFIG_ECORE_SW_CHANNEL
4842 void ecore_iov_set_vf_hw_channel(struct ecore_hwfn *p_hwfn, int vfid,
4845 struct ecore_vf_info *vf_info;
4847 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4851 vf_info->b_hw_channel = b_is_hw;