1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright (c) 2016 - 2018 Cavium Inc.
10 #include "ecore_sriov.h"
11 #include "ecore_status.h"
13 #include "ecore_hw_defs.h"
14 #include "ecore_int.h"
15 #include "ecore_hsi_eth.h"
17 #include "ecore_vfpf_if.h"
18 #include "ecore_rt_defs.h"
19 #include "ecore_init_ops.h"
20 #include "ecore_gtt_reg_addr.h"
21 #include "ecore_iro.h"
22 #include "ecore_mcp.h"
23 #include "ecore_cxt.h"
25 #include "ecore_init_fw_funcs.h"
26 #include "ecore_sp_commands.h"
28 static enum _ecore_status_t ecore_sriov_eqe_event(struct ecore_hwfn *p_hwfn,
31 union event_ring_data *data,
34 const char *ecore_channel_tlvs_string[] = {
35 "CHANNEL_TLV_NONE", /* ends tlv sequence */
36 "CHANNEL_TLV_ACQUIRE",
37 "CHANNEL_TLV_VPORT_START",
38 "CHANNEL_TLV_VPORT_UPDATE",
39 "CHANNEL_TLV_VPORT_TEARDOWN",
40 "CHANNEL_TLV_START_RXQ",
41 "CHANNEL_TLV_START_TXQ",
42 "CHANNEL_TLV_STOP_RXQ",
43 "CHANNEL_TLV_STOP_TXQ",
44 "CHANNEL_TLV_UPDATE_RXQ",
45 "CHANNEL_TLV_INT_CLEANUP",
47 "CHANNEL_TLV_RELEASE",
48 "CHANNEL_TLV_LIST_END",
49 "CHANNEL_TLV_UCAST_FILTER",
50 "CHANNEL_TLV_VPORT_UPDATE_ACTIVATE",
51 "CHANNEL_TLV_VPORT_UPDATE_TX_SWITCH",
52 "CHANNEL_TLV_VPORT_UPDATE_VLAN_STRIP",
53 "CHANNEL_TLV_VPORT_UPDATE_MCAST",
54 "CHANNEL_TLV_VPORT_UPDATE_ACCEPT_PARAM",
55 "CHANNEL_TLV_VPORT_UPDATE_RSS",
56 "CHANNEL_TLV_VPORT_UPDATE_ACCEPT_ANY_VLAN",
57 "CHANNEL_TLV_VPORT_UPDATE_SGE_TPA",
58 "CHANNEL_TLV_UPDATE_TUNN_PARAM",
59 "CHANNEL_TLV_COALESCE_UPDATE",
61 "CHANNEL_TLV_COALESCE_READ",
62 "CHANNEL_TLV_BULLETIN_UPDATE_MAC",
63 "CHANNEL_TLV_UPDATE_MTU",
67 static u8 ecore_vf_calculate_legacy(struct ecore_vf_info *p_vf)
71 if (p_vf->acquire.vfdev_info.eth_fp_hsi_minor ==
72 ETH_HSI_VER_NO_PKT_LEN_TUNN)
73 legacy |= ECORE_QCID_LEGACY_VF_RX_PROD;
75 if (!(p_vf->acquire.vfdev_info.capabilities &
76 VFPF_ACQUIRE_CAP_QUEUE_QIDS))
77 legacy |= ECORE_QCID_LEGACY_VF_CID;
83 static enum _ecore_status_t ecore_sp_vf_start(struct ecore_hwfn *p_hwfn,
84 struct ecore_vf_info *p_vf)
86 struct vf_start_ramrod_data *p_ramrod = OSAL_NULL;
87 struct ecore_spq_entry *p_ent = OSAL_NULL;
88 struct ecore_sp_init_data init_data;
89 enum _ecore_status_t rc = ECORE_NOTIMPL;
93 OSAL_MEMSET(&init_data, 0, sizeof(init_data));
94 init_data.cid = ecore_spq_get_cid(p_hwfn);
95 init_data.opaque_fid = p_vf->opaque_fid;
96 init_data.comp_mode = ECORE_SPQ_MODE_EBLOCK;
98 rc = ecore_sp_init_request(p_hwfn, &p_ent,
99 COMMON_RAMROD_VF_START,
100 PROTOCOLID_COMMON, &init_data);
101 if (rc != ECORE_SUCCESS)
104 p_ramrod = &p_ent->ramrod.vf_start;
106 p_ramrod->vf_id = GET_FIELD(p_vf->concrete_fid, PXP_CONCRETE_FID_VFID);
107 p_ramrod->opaque_fid = OSAL_CPU_TO_LE16(p_vf->opaque_fid);
109 switch (p_hwfn->hw_info.personality) {
111 p_ramrod->personality = PERSONALITY_ETH;
113 case ECORE_PCI_ETH_ROCE:
114 case ECORE_PCI_ETH_IWARP:
115 p_ramrod->personality = PERSONALITY_RDMA_AND_ETH;
118 DP_NOTICE(p_hwfn, true, "Unknown VF personality %d\n",
119 p_hwfn->hw_info.personality);
123 fp_minor = p_vf->acquire.vfdev_info.eth_fp_hsi_minor;
124 if (fp_minor > ETH_HSI_VER_MINOR &&
125 fp_minor != ETH_HSI_VER_NO_PKT_LEN_TUNN) {
126 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
127 "VF [%d] - Requested fp hsi %02x.%02x which is"
128 " slightly newer than PF's %02x.%02x; Configuring"
131 ETH_HSI_VER_MAJOR, fp_minor,
132 ETH_HSI_VER_MAJOR, ETH_HSI_VER_MINOR);
133 fp_minor = ETH_HSI_VER_MINOR;
136 p_ramrod->hsi_fp_ver.major_ver_arr[ETH_VER_KEY] = ETH_HSI_VER_MAJOR;
137 p_ramrod->hsi_fp_ver.minor_ver_arr[ETH_VER_KEY] = fp_minor;
139 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
140 "VF[%d] - Starting using HSI %02x.%02x\n",
141 p_vf->abs_vf_id, ETH_HSI_VER_MAJOR, fp_minor);
143 return ecore_spq_post(p_hwfn, p_ent, OSAL_NULL);
146 static enum _ecore_status_t ecore_sp_vf_stop(struct ecore_hwfn *p_hwfn,
150 struct vf_stop_ramrod_data *p_ramrod = OSAL_NULL;
151 struct ecore_spq_entry *p_ent = OSAL_NULL;
152 struct ecore_sp_init_data init_data;
153 enum _ecore_status_t rc = ECORE_NOTIMPL;
156 OSAL_MEMSET(&init_data, 0, sizeof(init_data));
157 init_data.cid = ecore_spq_get_cid(p_hwfn);
158 init_data.opaque_fid = opaque_vfid;
159 init_data.comp_mode = ECORE_SPQ_MODE_EBLOCK;
161 rc = ecore_sp_init_request(p_hwfn, &p_ent,
162 COMMON_RAMROD_VF_STOP,
163 PROTOCOLID_COMMON, &init_data);
164 if (rc != ECORE_SUCCESS)
167 p_ramrod = &p_ent->ramrod.vf_stop;
169 p_ramrod->vf_id = GET_FIELD(concrete_vfid, PXP_CONCRETE_FID_VFID);
171 return ecore_spq_post(p_hwfn, p_ent, OSAL_NULL);
174 bool ecore_iov_is_valid_vfid(struct ecore_hwfn *p_hwfn, int rel_vf_id,
175 bool b_enabled_only, bool b_non_malicious)
177 if (!p_hwfn->pf_iov_info) {
178 DP_NOTICE(p_hwfn->p_dev, true, "No iov info\n");
182 if ((rel_vf_id >= p_hwfn->p_dev->p_iov_info->total_vfs) ||
186 if ((!p_hwfn->pf_iov_info->vfs_array[rel_vf_id].b_init) &&
190 if ((p_hwfn->pf_iov_info->vfs_array[rel_vf_id].b_malicious) &&
197 struct ecore_vf_info *ecore_iov_get_vf_info(struct ecore_hwfn *p_hwfn,
201 struct ecore_vf_info *vf = OSAL_NULL;
203 if (!p_hwfn->pf_iov_info) {
204 DP_NOTICE(p_hwfn->p_dev, true, "No iov info\n");
208 if (ecore_iov_is_valid_vfid(p_hwfn, relative_vf_id,
209 b_enabled_only, false))
210 vf = &p_hwfn->pf_iov_info->vfs_array[relative_vf_id];
212 DP_ERR(p_hwfn, "ecore_iov_get_vf_info: VF[%d] is not enabled\n",
218 static struct ecore_queue_cid *
219 ecore_iov_get_vf_rx_queue_cid(struct ecore_vf_queue *p_queue)
223 for (i = 0; i < MAX_QUEUES_PER_QZONE; i++) {
224 if (p_queue->cids[i].p_cid &&
225 !p_queue->cids[i].b_is_tx)
226 return p_queue->cids[i].p_cid;
232 enum ecore_iov_validate_q_mode {
233 ECORE_IOV_VALIDATE_Q_NA,
234 ECORE_IOV_VALIDATE_Q_ENABLE,
235 ECORE_IOV_VALIDATE_Q_DISABLE,
238 static bool ecore_iov_validate_queue_mode(struct ecore_vf_info *p_vf,
240 enum ecore_iov_validate_q_mode mode,
245 if (mode == ECORE_IOV_VALIDATE_Q_NA)
248 for (i = 0; i < MAX_QUEUES_PER_QZONE; i++) {
249 struct ecore_vf_queue_cid *p_qcid;
251 p_qcid = &p_vf->vf_queues[qid].cids[i];
253 if (p_qcid->p_cid == OSAL_NULL)
256 if (p_qcid->b_is_tx != b_is_tx)
259 /* Found. It's enabled. */
260 return (mode == ECORE_IOV_VALIDATE_Q_ENABLE);
263 /* In case we haven't found any valid cid, then its disabled */
264 return (mode == ECORE_IOV_VALIDATE_Q_DISABLE);
267 static bool ecore_iov_validate_rxq(struct ecore_hwfn *p_hwfn,
268 struct ecore_vf_info *p_vf,
270 enum ecore_iov_validate_q_mode mode)
272 if (rx_qid >= p_vf->num_rxqs) {
273 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
274 "VF[0x%02x] - can't touch Rx queue[%04x];"
275 " Only 0x%04x are allocated\n",
276 p_vf->abs_vf_id, rx_qid, p_vf->num_rxqs);
280 return ecore_iov_validate_queue_mode(p_vf, rx_qid, mode, false);
283 static bool ecore_iov_validate_txq(struct ecore_hwfn *p_hwfn,
284 struct ecore_vf_info *p_vf,
286 enum ecore_iov_validate_q_mode mode)
288 if (tx_qid >= p_vf->num_txqs) {
289 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
290 "VF[0x%02x] - can't touch Tx queue[%04x];"
291 " Only 0x%04x are allocated\n",
292 p_vf->abs_vf_id, tx_qid, p_vf->num_txqs);
296 return ecore_iov_validate_queue_mode(p_vf, tx_qid, mode, true);
299 static bool ecore_iov_validate_sb(struct ecore_hwfn *p_hwfn,
300 struct ecore_vf_info *p_vf,
305 for (i = 0; i < p_vf->num_sbs; i++)
306 if (p_vf->igu_sbs[i] == sb_idx)
309 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
310 "VF[0%02x] - tried using sb_idx %04x which doesn't exist as"
311 " one of its 0x%02x SBs\n",
312 p_vf->abs_vf_id, sb_idx, p_vf->num_sbs);
317 /* Is there at least 1 queue open? */
318 static bool ecore_iov_validate_active_rxq(struct ecore_vf_info *p_vf)
322 for (i = 0; i < p_vf->num_rxqs; i++)
323 if (ecore_iov_validate_queue_mode(p_vf, i,
324 ECORE_IOV_VALIDATE_Q_ENABLE,
331 static bool ecore_iov_validate_active_txq(struct ecore_vf_info *p_vf)
335 for (i = 0; i < p_vf->num_txqs; i++)
336 if (ecore_iov_validate_queue_mode(p_vf, i,
337 ECORE_IOV_VALIDATE_Q_ENABLE,
344 enum _ecore_status_t ecore_iov_post_vf_bulletin(struct ecore_hwfn *p_hwfn,
346 struct ecore_ptt *p_ptt)
348 struct ecore_bulletin_content *p_bulletin;
349 int crc_size = sizeof(p_bulletin->crc);
350 struct ecore_dmae_params params;
351 struct ecore_vf_info *p_vf;
353 p_vf = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
357 /* TODO - check VF is in a state where it can accept message */
358 if (!p_vf->vf_bulletin)
361 p_bulletin = p_vf->bulletin.p_virt;
363 /* Increment bulletin board version and compute crc */
364 p_bulletin->version++;
365 p_bulletin->crc = OSAL_CRC32(0, (u8 *)p_bulletin + crc_size,
366 p_vf->bulletin.size - crc_size);
368 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
369 "Posting Bulletin 0x%08x to VF[%d] (CRC 0x%08x)\n",
370 p_bulletin->version, p_vf->relative_vf_id, p_bulletin->crc);
372 /* propagate bulletin board via dmae to vm memory */
373 OSAL_MEMSET(¶ms, 0, sizeof(params));
374 params.flags = ECORE_DMAE_FLAG_VF_DST;
375 params.dst_vfid = p_vf->abs_vf_id;
376 return ecore_dmae_host2host(p_hwfn, p_ptt, p_vf->bulletin.phys,
377 p_vf->vf_bulletin, p_vf->bulletin.size / 4,
381 static enum _ecore_status_t ecore_iov_pci_cfg_info(struct ecore_dev *p_dev)
383 struct ecore_hw_sriov_info *iov = p_dev->p_iov_info;
386 DP_VERBOSE(p_dev, ECORE_MSG_IOV, "sriov ext pos %d\n", pos);
387 OSAL_PCI_READ_CONFIG_WORD(p_dev, pos + PCI_SRIOV_CTRL, &iov->ctrl);
389 OSAL_PCI_READ_CONFIG_WORD(p_dev,
390 pos + PCI_SRIOV_TOTAL_VF, &iov->total_vfs);
391 OSAL_PCI_READ_CONFIG_WORD(p_dev,
392 pos + PCI_SRIOV_INITIAL_VF,
395 OSAL_PCI_READ_CONFIG_WORD(p_dev, pos + PCI_SRIOV_NUM_VF, &iov->num_vfs);
397 /* @@@TODO - in future we might want to add an OSAL here to
398 * allow each OS to decide on its own how to act.
400 DP_VERBOSE(p_dev, ECORE_MSG_IOV,
401 "Number of VFs are already set to non-zero value."
402 " Ignoring PCI configuration value\n");
406 OSAL_PCI_READ_CONFIG_WORD(p_dev,
407 pos + PCI_SRIOV_VF_OFFSET, &iov->offset);
409 OSAL_PCI_READ_CONFIG_WORD(p_dev,
410 pos + PCI_SRIOV_VF_STRIDE, &iov->stride);
412 OSAL_PCI_READ_CONFIG_WORD(p_dev,
413 pos + PCI_SRIOV_VF_DID, &iov->vf_device_id);
415 OSAL_PCI_READ_CONFIG_DWORD(p_dev,
416 pos + PCI_SRIOV_SUP_PGSIZE, &iov->pgsz);
418 OSAL_PCI_READ_CONFIG_DWORD(p_dev, pos + PCI_SRIOV_CAP, &iov->cap);
420 OSAL_PCI_READ_CONFIG_BYTE(p_dev, pos + PCI_SRIOV_FUNC_LINK, &iov->link);
422 DP_VERBOSE(p_dev, ECORE_MSG_IOV, "IOV info: nres %d, cap 0x%x,"
423 "ctrl 0x%x, total %d, initial %d, num vfs %d, offset %d,"
424 " stride %d, page size 0x%x\n",
425 iov->nres, iov->cap, iov->ctrl,
426 iov->total_vfs, iov->initial_vfs, iov->nr_virtfn,
427 iov->offset, iov->stride, iov->pgsz);
429 /* Some sanity checks */
430 if (iov->num_vfs > NUM_OF_VFS(p_dev) ||
431 iov->total_vfs > NUM_OF_VFS(p_dev)) {
432 /* This can happen only due to a bug. In this case we set
433 * num_vfs to zero to avoid memory corruption in the code that
434 * assumes max number of vfs
436 DP_NOTICE(p_dev, false,
437 "IOV: Unexpected number of vfs set: %d"
438 " setting num_vf to zero\n",
445 return ECORE_SUCCESS;
448 static void ecore_iov_setup_vfdb(struct ecore_hwfn *p_hwfn)
450 struct ecore_hw_sriov_info *p_iov = p_hwfn->p_dev->p_iov_info;
451 struct ecore_pf_iov *p_iov_info = p_hwfn->pf_iov_info;
452 struct ecore_bulletin_content *p_bulletin_virt;
453 dma_addr_t req_p, rply_p, bulletin_p;
454 union pfvf_tlvs *p_reply_virt_addr;
455 union vfpf_tlvs *p_req_virt_addr;
458 OSAL_MEMSET(p_iov_info->vfs_array, 0, sizeof(p_iov_info->vfs_array));
460 p_req_virt_addr = p_iov_info->mbx_msg_virt_addr;
461 req_p = p_iov_info->mbx_msg_phys_addr;
462 p_reply_virt_addr = p_iov_info->mbx_reply_virt_addr;
463 rply_p = p_iov_info->mbx_reply_phys_addr;
464 p_bulletin_virt = p_iov_info->p_bulletins;
465 bulletin_p = p_iov_info->bulletins_phys;
466 if (!p_req_virt_addr || !p_reply_virt_addr || !p_bulletin_virt) {
468 "ecore_iov_setup_vfdb called without alloc mem first\n");
472 for (idx = 0; idx < p_iov->total_vfs; idx++) {
473 struct ecore_vf_info *vf = &p_iov_info->vfs_array[idx];
476 vf->vf_mbx.req_virt = p_req_virt_addr + idx;
477 vf->vf_mbx.req_phys = req_p + idx * sizeof(union vfpf_tlvs);
478 vf->vf_mbx.reply_virt = p_reply_virt_addr + idx;
479 vf->vf_mbx.reply_phys = rply_p + idx * sizeof(union pfvf_tlvs);
481 #ifdef CONFIG_ECORE_SW_CHANNEL
482 vf->vf_mbx.sw_mbx.request_size = sizeof(union vfpf_tlvs);
483 vf->vf_mbx.sw_mbx.mbx_state = VF_PF_WAIT_FOR_START_REQUEST;
485 vf->state = VF_STOPPED;
488 vf->bulletin.phys = idx *
489 sizeof(struct ecore_bulletin_content) + bulletin_p;
490 vf->bulletin.p_virt = p_bulletin_virt + idx;
491 vf->bulletin.size = sizeof(struct ecore_bulletin_content);
493 vf->relative_vf_id = idx;
494 vf->abs_vf_id = idx + p_iov->first_vf_in_pf;
495 concrete = ecore_vfid_to_concrete(p_hwfn, vf->abs_vf_id);
496 vf->concrete_fid = concrete;
497 /* TODO - need to devise a better way of getting opaque */
498 vf->opaque_fid = (p_hwfn->hw_info.opaque_fid & 0xff) |
499 (vf->abs_vf_id << 8);
501 vf->num_mac_filters = ECORE_ETH_VF_NUM_MAC_FILTERS;
502 vf->num_vlan_filters = ECORE_ETH_VF_NUM_VLAN_FILTERS;
506 static enum _ecore_status_t ecore_iov_allocate_vfdb(struct ecore_hwfn *p_hwfn)
508 struct ecore_pf_iov *p_iov_info = p_hwfn->pf_iov_info;
512 num_vfs = p_hwfn->p_dev->p_iov_info->total_vfs;
514 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
515 "ecore_iov_allocate_vfdb for %d VFs\n", num_vfs);
517 /* Allocate PF Mailbox buffer (per-VF) */
518 p_iov_info->mbx_msg_size = sizeof(union vfpf_tlvs) * num_vfs;
519 p_v_addr = &p_iov_info->mbx_msg_virt_addr;
520 *p_v_addr = OSAL_DMA_ALLOC_COHERENT(p_hwfn->p_dev,
521 &p_iov_info->mbx_msg_phys_addr,
522 p_iov_info->mbx_msg_size);
526 /* Allocate PF Mailbox Reply buffer (per-VF) */
527 p_iov_info->mbx_reply_size = sizeof(union pfvf_tlvs) * num_vfs;
528 p_v_addr = &p_iov_info->mbx_reply_virt_addr;
529 *p_v_addr = OSAL_DMA_ALLOC_COHERENT(p_hwfn->p_dev,
530 &p_iov_info->mbx_reply_phys_addr,
531 p_iov_info->mbx_reply_size);
535 p_iov_info->bulletins_size = sizeof(struct ecore_bulletin_content) *
537 p_v_addr = &p_iov_info->p_bulletins;
538 *p_v_addr = OSAL_DMA_ALLOC_COHERENT(p_hwfn->p_dev,
539 &p_iov_info->bulletins_phys,
540 p_iov_info->bulletins_size);
544 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
545 "PF's Requests mailbox [%p virt 0x%lx phys], "
546 "Response mailbox [%p virt 0x%lx phys] Bulletinsi"
547 " [%p virt 0x%lx phys]\n",
548 p_iov_info->mbx_msg_virt_addr,
549 (unsigned long)p_iov_info->mbx_msg_phys_addr,
550 p_iov_info->mbx_reply_virt_addr,
551 (unsigned long)p_iov_info->mbx_reply_phys_addr,
552 p_iov_info->p_bulletins,
553 (unsigned long)p_iov_info->bulletins_phys);
555 return ECORE_SUCCESS;
558 static void ecore_iov_free_vfdb(struct ecore_hwfn *p_hwfn)
560 struct ecore_pf_iov *p_iov_info = p_hwfn->pf_iov_info;
562 if (p_hwfn->pf_iov_info->mbx_msg_virt_addr)
563 OSAL_DMA_FREE_COHERENT(p_hwfn->p_dev,
564 p_iov_info->mbx_msg_virt_addr,
565 p_iov_info->mbx_msg_phys_addr,
566 p_iov_info->mbx_msg_size);
568 if (p_hwfn->pf_iov_info->mbx_reply_virt_addr)
569 OSAL_DMA_FREE_COHERENT(p_hwfn->p_dev,
570 p_iov_info->mbx_reply_virt_addr,
571 p_iov_info->mbx_reply_phys_addr,
572 p_iov_info->mbx_reply_size);
574 if (p_iov_info->p_bulletins)
575 OSAL_DMA_FREE_COHERENT(p_hwfn->p_dev,
576 p_iov_info->p_bulletins,
577 p_iov_info->bulletins_phys,
578 p_iov_info->bulletins_size);
581 enum _ecore_status_t ecore_iov_alloc(struct ecore_hwfn *p_hwfn)
583 struct ecore_pf_iov *p_sriov;
585 if (!IS_PF_SRIOV(p_hwfn)) {
586 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
587 "No SR-IOV - no need for IOV db\n");
588 return ECORE_SUCCESS;
591 p_sriov = OSAL_ZALLOC(p_hwfn->p_dev, GFP_KERNEL, sizeof(*p_sriov));
593 DP_NOTICE(p_hwfn, false, "Failed to allocate `struct ecore_sriov'\n");
597 p_hwfn->pf_iov_info = p_sriov;
599 ecore_spq_register_async_cb(p_hwfn, PROTOCOLID_COMMON,
600 ecore_sriov_eqe_event);
602 return ecore_iov_allocate_vfdb(p_hwfn);
605 void ecore_iov_setup(struct ecore_hwfn *p_hwfn)
607 if (!IS_PF_SRIOV(p_hwfn) || !IS_PF_SRIOV_ALLOC(p_hwfn))
610 ecore_iov_setup_vfdb(p_hwfn);
613 void ecore_iov_free(struct ecore_hwfn *p_hwfn)
615 ecore_spq_unregister_async_cb(p_hwfn, PROTOCOLID_COMMON);
617 if (IS_PF_SRIOV_ALLOC(p_hwfn)) {
618 ecore_iov_free_vfdb(p_hwfn);
619 OSAL_FREE(p_hwfn->p_dev, p_hwfn->pf_iov_info);
623 void ecore_iov_free_hw_info(struct ecore_dev *p_dev)
625 OSAL_FREE(p_dev, p_dev->p_iov_info);
628 enum _ecore_status_t ecore_iov_hw_info(struct ecore_hwfn *p_hwfn)
630 struct ecore_dev *p_dev = p_hwfn->p_dev;
632 enum _ecore_status_t rc;
634 if (IS_VF(p_hwfn->p_dev))
635 return ECORE_SUCCESS;
637 /* Learn the PCI configuration */
638 pos = OSAL_PCI_FIND_EXT_CAPABILITY(p_hwfn->p_dev,
639 PCI_EXT_CAP_ID_SRIOV);
641 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV, "No PCIe IOV support\n");
642 return ECORE_SUCCESS;
645 /* Allocate a new struct for IOV information */
646 /* TODO - can change to VALLOC when its available */
647 p_dev->p_iov_info = OSAL_ZALLOC(p_dev, GFP_KERNEL,
648 sizeof(*p_dev->p_iov_info));
649 if (!p_dev->p_iov_info) {
650 DP_NOTICE(p_hwfn, false,
651 "Can't support IOV due to lack of memory\n");
654 p_dev->p_iov_info->pos = pos;
656 rc = ecore_iov_pci_cfg_info(p_dev);
660 /* We want PF IOV to be synonemous with the existence of p_iov_info;
661 * In case the capability is published but there are no VFs, simply
662 * de-allocate the struct.
664 if (!p_dev->p_iov_info->total_vfs) {
665 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
666 "IOV capabilities, but no VFs are published\n");
667 OSAL_FREE(p_dev, p_dev->p_iov_info);
668 return ECORE_SUCCESS;
671 /* First VF index based on offset is tricky:
672 * - If ARI is supported [likely], offset - (16 - pf_id) would
673 * provide the number for eng0. 2nd engine Vfs would begin
674 * after the first engine's VFs.
675 * - If !ARI, VFs would start on next device.
676 * so offset - (256 - pf_id) would provide the number.
677 * Utilize the fact that (256 - pf_id) is achieved only be later
678 * to diffrentiate between the two.
681 if (p_hwfn->p_dev->p_iov_info->offset < (256 - p_hwfn->abs_pf_id)) {
682 u32 first = p_hwfn->p_dev->p_iov_info->offset +
683 p_hwfn->abs_pf_id - 16;
685 p_dev->p_iov_info->first_vf_in_pf = first;
687 if (ECORE_PATH_ID(p_hwfn))
688 p_dev->p_iov_info->first_vf_in_pf -= MAX_NUM_VFS_BB;
690 u32 first = p_hwfn->p_dev->p_iov_info->offset +
691 p_hwfn->abs_pf_id - 256;
693 p_dev->p_iov_info->first_vf_in_pf = first;
696 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
697 "First VF in hwfn 0x%08x\n",
698 p_dev->p_iov_info->first_vf_in_pf);
700 return ECORE_SUCCESS;
703 static bool _ecore_iov_pf_sanity_check(struct ecore_hwfn *p_hwfn, int vfid,
704 bool b_fail_malicious)
706 /* Check PF supports sriov */
707 if (IS_VF(p_hwfn->p_dev) || !IS_ECORE_SRIOV(p_hwfn->p_dev) ||
708 !IS_PF_SRIOV_ALLOC(p_hwfn))
711 /* Check VF validity */
712 if (!ecore_iov_is_valid_vfid(p_hwfn, vfid, true, b_fail_malicious))
718 bool ecore_iov_pf_sanity_check(struct ecore_hwfn *p_hwfn, int vfid)
720 return _ecore_iov_pf_sanity_check(p_hwfn, vfid, true);
723 void ecore_iov_set_vf_to_disable(struct ecore_dev *p_dev,
724 u16 rel_vf_id, u8 to_disable)
726 struct ecore_vf_info *vf;
729 for_each_hwfn(p_dev, i) {
730 struct ecore_hwfn *p_hwfn = &p_dev->hwfns[i];
732 vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, false);
736 vf->to_disable = to_disable;
740 void ecore_iov_set_vfs_to_disable(struct ecore_dev *p_dev,
745 if (!IS_ECORE_SRIOV(p_dev))
748 for (i = 0; i < p_dev->p_iov_info->total_vfs; i++)
749 ecore_iov_set_vf_to_disable(p_dev, i, to_disable);
753 /* @@@TBD Consider taking outside of ecore... */
754 enum _ecore_status_t ecore_iov_set_vf_ctx(struct ecore_hwfn *p_hwfn,
758 enum _ecore_status_t rc = ECORE_SUCCESS;
759 struct ecore_vf_info *vf = ecore_iov_get_vf_info(p_hwfn, vf_id, true);
761 if (vf != OSAL_NULL) {
763 #ifdef CONFIG_ECORE_SW_CHANNEL
764 vf->vf_mbx.sw_mbx.mbx_state = VF_PF_WAIT_FOR_START_REQUEST;
767 rc = ECORE_UNKNOWN_ERROR;
773 static void ecore_iov_vf_pglue_clear_err(struct ecore_hwfn *p_hwfn,
774 struct ecore_ptt *p_ptt,
777 ecore_wr(p_hwfn, p_ptt,
778 PGLUE_B_REG_WAS_ERROR_VF_31_0_CLR + (abs_vfid >> 5) * 4,
779 1 << (abs_vfid & 0x1f));
782 static void ecore_iov_vf_igu_reset(struct ecore_hwfn *p_hwfn,
783 struct ecore_ptt *p_ptt,
784 struct ecore_vf_info *vf)
788 /* Set VF masks and configuration - pretend */
789 ecore_fid_pretend(p_hwfn, p_ptt, (u16)vf->concrete_fid);
791 ecore_wr(p_hwfn, p_ptt, IGU_REG_STATISTIC_NUM_VF_MSG_SENT, 0);
794 ecore_fid_pretend(p_hwfn, p_ptt, (u16)p_hwfn->hw_info.concrete_fid);
796 /* iterate over all queues, clear sb consumer */
797 for (i = 0; i < vf->num_sbs; i++)
798 ecore_int_igu_init_pure_rt_single(p_hwfn, p_ptt,
800 vf->opaque_fid, true);
803 static void ecore_iov_vf_igu_set_int(struct ecore_hwfn *p_hwfn,
804 struct ecore_ptt *p_ptt,
805 struct ecore_vf_info *vf, bool enable)
809 ecore_fid_pretend(p_hwfn, p_ptt, (u16)vf->concrete_fid);
811 igu_vf_conf = ecore_rd(p_hwfn, p_ptt, IGU_REG_VF_CONFIGURATION);
814 igu_vf_conf |= IGU_VF_CONF_MSI_MSIX_EN;
816 igu_vf_conf &= ~IGU_VF_CONF_MSI_MSIX_EN;
818 ecore_wr(p_hwfn, p_ptt, IGU_REG_VF_CONFIGURATION, igu_vf_conf);
821 ecore_fid_pretend(p_hwfn, p_ptt, (u16)p_hwfn->hw_info.concrete_fid);
824 static enum _ecore_status_t
825 ecore_iov_enable_vf_access_msix(struct ecore_hwfn *p_hwfn,
826 struct ecore_ptt *p_ptt,
833 /* If client overrides this, don't do anything */
834 if (p_hwfn->p_dev->b_dont_override_vf_msix)
835 return ECORE_SUCCESS;
837 /* For AH onward, configuration is per-PF. Find maximum of all
838 * the currently enabled child VFs, and set the number to be that.
840 if (!ECORE_IS_BB(p_hwfn->p_dev)) {
841 ecore_for_each_vf(p_hwfn, i) {
842 struct ecore_vf_info *p_vf;
844 p_vf = ecore_iov_get_vf_info(p_hwfn, (u16)i, true);
848 current_max = OSAL_MAX_T(u8, current_max,
853 if (num_sbs > current_max)
854 return ecore_mcp_config_vf_msix(p_hwfn, p_ptt,
857 return ECORE_SUCCESS;
860 static enum _ecore_status_t
861 ecore_iov_enable_vf_access(struct ecore_hwfn *p_hwfn,
862 struct ecore_ptt *p_ptt, struct ecore_vf_info *vf)
864 u32 igu_vf_conf = IGU_VF_CONF_FUNC_EN;
865 enum _ecore_status_t rc = ECORE_SUCCESS;
867 /* It's possible VF was previously considered malicious -
868 * clear the indication even if we're only going to disable VF.
870 vf->b_malicious = false;
873 return ECORE_SUCCESS;
875 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
876 "Enable internal access for vf %x [abs %x]\n", vf->abs_vf_id,
877 ECORE_VF_ABS_ID(p_hwfn, vf));
879 ecore_iov_vf_pglue_clear_err(p_hwfn, p_ptt,
880 ECORE_VF_ABS_ID(p_hwfn, vf));
882 ecore_iov_vf_igu_reset(p_hwfn, p_ptt, vf);
884 rc = ecore_iov_enable_vf_access_msix(p_hwfn, p_ptt,
885 vf->abs_vf_id, vf->num_sbs);
886 if (rc != ECORE_SUCCESS)
889 ecore_fid_pretend(p_hwfn, p_ptt, (u16)vf->concrete_fid);
891 SET_FIELD(igu_vf_conf, IGU_VF_CONF_PARENT, p_hwfn->rel_pf_id);
892 STORE_RT_REG(p_hwfn, IGU_REG_VF_CONFIGURATION_RT_OFFSET, igu_vf_conf);
894 ecore_init_run(p_hwfn, p_ptt, PHASE_VF, vf->abs_vf_id,
895 p_hwfn->hw_info.hw_mode);
898 ecore_fid_pretend(p_hwfn, p_ptt, (u16)p_hwfn->hw_info.concrete_fid);
907 * @brief ecore_iov_config_perm_table - configure the permission
909 * In E4, queue zone permission table size is 320x9. There
910 * are 320 VF queues for single engine device (256 for dual
911 * engine device), and each entry has the following format:
918 static void ecore_iov_config_perm_table(struct ecore_hwfn *p_hwfn,
919 struct ecore_ptt *p_ptt,
920 struct ecore_vf_info *vf, u8 enable)
926 for (qid = 0; qid < vf->num_rxqs; qid++) {
927 ecore_fw_l2_queue(p_hwfn, vf->vf_queues[qid].fw_rx_qid,
930 reg_addr = PSWHST_REG_ZONE_PERMISSION_TABLE + qzone_id * 4;
931 val = enable ? (vf->abs_vf_id | (1 << 8)) : 0;
932 ecore_wr(p_hwfn, p_ptt, reg_addr, val);
936 static void ecore_iov_enable_vf_traffic(struct ecore_hwfn *p_hwfn,
937 struct ecore_ptt *p_ptt,
938 struct ecore_vf_info *vf)
940 /* Reset vf in IGU - interrupts are still disabled */
941 ecore_iov_vf_igu_reset(p_hwfn, p_ptt, vf);
943 ecore_iov_vf_igu_set_int(p_hwfn, p_ptt, vf, 1);
945 /* Permission Table */
946 ecore_iov_config_perm_table(p_hwfn, p_ptt, vf, true);
949 static u8 ecore_iov_alloc_vf_igu_sbs(struct ecore_hwfn *p_hwfn,
950 struct ecore_ptt *p_ptt,
951 struct ecore_vf_info *vf,
954 struct ecore_igu_block *p_block;
955 struct cau_sb_entry sb_entry;
959 if (num_rx_queues > p_hwfn->hw_info.p_igu_info->usage.free_cnt_iov)
961 (u16)p_hwfn->hw_info.p_igu_info->usage.free_cnt_iov;
962 p_hwfn->hw_info.p_igu_info->usage.free_cnt_iov -= num_rx_queues;
964 SET_FIELD(val, IGU_MAPPING_LINE_FUNCTION_NUMBER, vf->abs_vf_id);
965 SET_FIELD(val, IGU_MAPPING_LINE_VALID, 1);
966 SET_FIELD(val, IGU_MAPPING_LINE_PF_VALID, 0);
968 for (qid = 0; qid < num_rx_queues; qid++) {
969 p_block = ecore_get_igu_free_sb(p_hwfn, false);
970 vf->igu_sbs[qid] = p_block->igu_sb_id;
971 p_block->status &= ~ECORE_IGU_STATUS_FREE;
972 SET_FIELD(val, IGU_MAPPING_LINE_VECTOR_NUMBER, qid);
974 ecore_wr(p_hwfn, p_ptt,
975 IGU_REG_MAPPING_MEMORY +
976 sizeof(u32) * p_block->igu_sb_id, val);
978 /* Configure igu sb in CAU which were marked valid */
979 ecore_init_cau_sb_entry(p_hwfn, &sb_entry,
982 ecore_dmae_host2grc(p_hwfn, p_ptt,
983 (u64)(osal_uintptr_t)&sb_entry,
984 CAU_REG_SB_VAR_MEMORY +
985 p_block->igu_sb_id * sizeof(u64), 2, 0);
988 vf->num_sbs = (u8)num_rx_queues;
995 * @brief The function invalidates all the VF entries,
996 * technically this isn't required, but added for
997 * cleaness and ease of debugging incase a VF attempts to
998 * produce an interrupt after it has been taken down.
1004 static void ecore_iov_free_vf_igu_sbs(struct ecore_hwfn *p_hwfn,
1005 struct ecore_ptt *p_ptt,
1006 struct ecore_vf_info *vf)
1008 struct ecore_igu_info *p_info = p_hwfn->hw_info.p_igu_info;
1012 /* Invalidate igu CAM lines and mark them as free */
1013 for (idx = 0; idx < vf->num_sbs; idx++) {
1014 igu_id = vf->igu_sbs[idx];
1015 addr = IGU_REG_MAPPING_MEMORY + sizeof(u32) * igu_id;
1017 val = ecore_rd(p_hwfn, p_ptt, addr);
1018 SET_FIELD(val, IGU_MAPPING_LINE_VALID, 0);
1019 ecore_wr(p_hwfn, p_ptt, addr, val);
1021 p_info->entry[igu_id].status |= ECORE_IGU_STATUS_FREE;
1022 p_hwfn->hw_info.p_igu_info->usage.free_cnt_iov++;
1028 void ecore_iov_set_link(struct ecore_hwfn *p_hwfn,
1030 struct ecore_mcp_link_params *params,
1031 struct ecore_mcp_link_state *link,
1032 struct ecore_mcp_link_capabilities *p_caps)
1034 struct ecore_vf_info *p_vf = ecore_iov_get_vf_info(p_hwfn, vfid, false);
1035 struct ecore_bulletin_content *p_bulletin;
1040 p_bulletin = p_vf->bulletin.p_virt;
1041 p_bulletin->req_autoneg = params->speed.autoneg;
1042 p_bulletin->req_adv_speed = params->speed.advertised_speeds;
1043 p_bulletin->req_forced_speed = params->speed.forced_speed;
1044 p_bulletin->req_autoneg_pause = params->pause.autoneg;
1045 p_bulletin->req_forced_rx = params->pause.forced_rx;
1046 p_bulletin->req_forced_tx = params->pause.forced_tx;
1047 p_bulletin->req_loopback = params->loopback_mode;
1049 p_bulletin->link_up = link->link_up;
1050 p_bulletin->speed = link->speed;
1051 p_bulletin->full_duplex = link->full_duplex;
1052 p_bulletin->autoneg = link->an;
1053 p_bulletin->autoneg_complete = link->an_complete;
1054 p_bulletin->parallel_detection = link->parallel_detection;
1055 p_bulletin->pfc_enabled = link->pfc_enabled;
1056 p_bulletin->partner_adv_speed = link->partner_adv_speed;
1057 p_bulletin->partner_tx_flow_ctrl_en = link->partner_tx_flow_ctrl_en;
1058 p_bulletin->partner_rx_flow_ctrl_en = link->partner_rx_flow_ctrl_en;
1059 p_bulletin->partner_adv_pause = link->partner_adv_pause;
1060 p_bulletin->sfp_tx_fault = link->sfp_tx_fault;
1062 p_bulletin->capability_speed = p_caps->speed_capabilities;
1065 enum _ecore_status_t
1066 ecore_iov_init_hw_for_vf(struct ecore_hwfn *p_hwfn,
1067 struct ecore_ptt *p_ptt,
1068 struct ecore_iov_vf_init_params *p_params)
1070 struct ecore_mcp_link_capabilities link_caps;
1071 struct ecore_mcp_link_params link_params;
1072 struct ecore_mcp_link_state link_state;
1073 u8 num_of_vf_available_chains = 0;
1074 struct ecore_vf_info *vf = OSAL_NULL;
1076 enum _ecore_status_t rc = ECORE_SUCCESS;
1080 vf = ecore_iov_get_vf_info(p_hwfn, p_params->rel_vf_id, false);
1082 DP_ERR(p_hwfn, "ecore_iov_init_hw_for_vf : vf is OSAL_NULL\n");
1083 return ECORE_UNKNOWN_ERROR;
1087 DP_NOTICE(p_hwfn, true, "VF[%d] is already active.\n",
1088 p_params->rel_vf_id);
1092 /* Perform sanity checking on the requested vport/rss */
1093 if (p_params->vport_id >= RESC_NUM(p_hwfn, ECORE_VPORT)) {
1094 DP_NOTICE(p_hwfn, true, "VF[%d] - can't use VPORT %02x\n",
1095 p_params->rel_vf_id, p_params->vport_id);
1099 if ((p_params->num_queues > 1) &&
1100 (p_params->rss_eng_id >= RESC_NUM(p_hwfn, ECORE_RSS_ENG))) {
1101 DP_NOTICE(p_hwfn, true, "VF[%d] - can't use RSS_ENG %02x\n",
1102 p_params->rel_vf_id, p_params->rss_eng_id);
1106 /* TODO - remove this once we get confidence of change */
1107 if (!p_params->vport_id) {
1108 DP_NOTICE(p_hwfn, false,
1109 "VF[%d] - Unlikely that VF uses vport0. Forgotten?\n",
1110 p_params->rel_vf_id);
1112 if ((!p_params->rss_eng_id) && (p_params->num_queues > 1)) {
1113 DP_NOTICE(p_hwfn, false,
1114 "VF[%d] - Unlikely that VF uses RSS_eng0. Forgotten?\n",
1115 p_params->rel_vf_id);
1117 vf->vport_id = p_params->vport_id;
1118 vf->rss_eng_id = p_params->rss_eng_id;
1120 /* Since it's possible to relocate SBs, it's a bit difficult to check
1121 * things here. Simply check whether the index falls in the range
1122 * belonging to the PF.
1124 for (i = 0; i < p_params->num_queues; i++) {
1125 qid = p_params->req_rx_queue[i];
1126 if (qid > (u16)RESC_NUM(p_hwfn, ECORE_L2_QUEUE)) {
1127 DP_NOTICE(p_hwfn, true,
1128 "Can't enable Rx qid [%04x] for VF[%d]: qids [0,,...,0x%04x] available\n",
1129 qid, p_params->rel_vf_id,
1130 (u16)RESC_NUM(p_hwfn, ECORE_L2_QUEUE));
1134 qid = p_params->req_tx_queue[i];
1135 if (qid > (u16)RESC_NUM(p_hwfn, ECORE_L2_QUEUE)) {
1136 DP_NOTICE(p_hwfn, true,
1137 "Can't enable Tx qid [%04x] for VF[%d]: qids [0,,...,0x%04x] available\n",
1138 qid, p_params->rel_vf_id,
1139 (u16)RESC_NUM(p_hwfn, ECORE_L2_QUEUE));
1144 /* Limit number of queues according to number of CIDs */
1145 ecore_cxt_get_proto_cid_count(p_hwfn, PROTOCOLID_ETH, &cids);
1146 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1147 "VF[%d] - requesting to initialize for 0x%04x queues"
1148 " [0x%04x CIDs available]\n",
1149 vf->relative_vf_id, p_params->num_queues, (u16)cids);
1150 num_irqs = OSAL_MIN_T(u16, p_params->num_queues, ((u16)cids));
1152 num_of_vf_available_chains = ecore_iov_alloc_vf_igu_sbs(p_hwfn,
1156 if (num_of_vf_available_chains == 0) {
1157 DP_ERR(p_hwfn, "no available igu sbs\n");
1161 /* Choose queue number and index ranges */
1162 vf->num_rxqs = num_of_vf_available_chains;
1163 vf->num_txqs = num_of_vf_available_chains;
1165 for (i = 0; i < vf->num_rxqs; i++) {
1166 struct ecore_vf_queue *p_queue = &vf->vf_queues[i];
1168 p_queue->fw_rx_qid = p_params->req_rx_queue[i];
1169 p_queue->fw_tx_qid = p_params->req_tx_queue[i];
1171 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1172 "VF[%d] - Q[%d] SB %04x, qid [Rx %04x Tx %04x]\n",
1173 vf->relative_vf_id, i, vf->igu_sbs[i],
1174 p_queue->fw_rx_qid, p_queue->fw_tx_qid);
1177 /* Update the link configuration in bulletin.
1179 OSAL_MEMCPY(&link_params, ecore_mcp_get_link_params(p_hwfn),
1180 sizeof(link_params));
1181 OSAL_MEMCPY(&link_state, ecore_mcp_get_link_state(p_hwfn),
1182 sizeof(link_state));
1183 OSAL_MEMCPY(&link_caps, ecore_mcp_get_link_capabilities(p_hwfn),
1185 ecore_iov_set_link(p_hwfn, p_params->rel_vf_id,
1186 &link_params, &link_state, &link_caps);
1188 rc = ecore_iov_enable_vf_access(p_hwfn, p_ptt, vf);
1190 if (rc == ECORE_SUCCESS) {
1192 p_hwfn->pf_iov_info->active_vfs[vf->relative_vf_id / 64] |=
1193 (1ULL << (vf->relative_vf_id % 64));
1195 if (IS_LEAD_HWFN(p_hwfn))
1196 p_hwfn->p_dev->p_iov_info->num_vfs++;
1202 enum _ecore_status_t ecore_iov_release_hw_for_vf(struct ecore_hwfn *p_hwfn,
1203 struct ecore_ptt *p_ptt,
1206 struct ecore_mcp_link_capabilities caps;
1207 struct ecore_mcp_link_params params;
1208 struct ecore_mcp_link_state link;
1209 struct ecore_vf_info *vf = OSAL_NULL;
1211 vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
1213 DP_ERR(p_hwfn, "ecore_iov_release_hw_for_vf : vf is NULL\n");
1214 return ECORE_UNKNOWN_ERROR;
1217 if (vf->bulletin.p_virt)
1218 OSAL_MEMSET(vf->bulletin.p_virt, 0,
1219 sizeof(*vf->bulletin.p_virt));
1221 OSAL_MEMSET(&vf->p_vf_info, 0, sizeof(vf->p_vf_info));
1223 /* Get the link configuration back in bulletin so
1224 * that when VFs are re-enabled they get the actual
1225 * link configuration.
1227 OSAL_MEMCPY(¶ms, ecore_mcp_get_link_params(p_hwfn), sizeof(params));
1228 OSAL_MEMCPY(&link, ecore_mcp_get_link_state(p_hwfn), sizeof(link));
1229 OSAL_MEMCPY(&caps, ecore_mcp_get_link_capabilities(p_hwfn),
1231 ecore_iov_set_link(p_hwfn, rel_vf_id, ¶ms, &link, &caps);
1233 /* Forget the VF's acquisition message */
1234 OSAL_MEMSET(&vf->acquire, 0, sizeof(vf->acquire));
1236 /* disablng interrupts and resetting permission table was done during
1237 * vf-close, however, we could get here without going through vf_close
1239 /* Disable Interrupts for VF */
1240 ecore_iov_vf_igu_set_int(p_hwfn, p_ptt, vf, 0);
1242 /* Reset Permission table */
1243 ecore_iov_config_perm_table(p_hwfn, p_ptt, vf, 0);
1247 ecore_iov_free_vf_igu_sbs(p_hwfn, p_ptt, vf);
1251 p_hwfn->pf_iov_info->active_vfs[vf->relative_vf_id / 64] &=
1252 ~(1ULL << (vf->relative_vf_id / 64));
1254 if (IS_LEAD_HWFN(p_hwfn))
1255 p_hwfn->p_dev->p_iov_info->num_vfs--;
1258 return ECORE_SUCCESS;
1261 static bool ecore_iov_tlv_supported(u16 tlvtype)
1263 return tlvtype > CHANNEL_TLV_NONE && tlvtype < CHANNEL_TLV_MAX;
1266 static void ecore_iov_lock_vf_pf_channel(struct ecore_hwfn *p_hwfn,
1267 struct ecore_vf_info *vf, u16 tlv)
1269 /* lock the channel */
1270 /* mutex_lock(&vf->op_mutex); @@@TBD MichalK - add lock... */
1272 /* record the locking op */
1273 /* vf->op_current = tlv; @@@TBD MichalK */
1276 if (ecore_iov_tlv_supported(tlv))
1279 "VF[%d]: vf pf channel locked by %s\n",
1281 ecore_channel_tlvs_string[tlv]);
1285 "VF[%d]: vf pf channel locked by %04x\n",
1286 vf->abs_vf_id, tlv);
1289 static void ecore_iov_unlock_vf_pf_channel(struct ecore_hwfn *p_hwfn,
1290 struct ecore_vf_info *vf,
1293 /* log the unlock */
1294 if (ecore_iov_tlv_supported(expected_tlv))
1297 "VF[%d]: vf pf channel unlocked by %s\n",
1299 ecore_channel_tlvs_string[expected_tlv]);
1303 "VF[%d]: vf pf channel unlocked by %04x\n",
1304 vf->abs_vf_id, expected_tlv);
1306 /* record the locking op */
1307 /* vf->op_current = CHANNEL_TLV_NONE; */
1310 /* place a given tlv on the tlv buffer, continuing current tlv list */
1311 void *ecore_add_tlv(u8 **offset, u16 type, u16 length)
1313 struct channel_tlv *tl = (struct channel_tlv *)*offset;
1316 tl->length = length;
1318 /* Offset should keep pointing to next TLV (the end of the last) */
1321 /* Return a pointer to the start of the added tlv */
1322 return *offset - length;
1325 /* list the types and lengths of the tlvs on the buffer */
1326 void ecore_dp_tlv_list(struct ecore_hwfn *p_hwfn, void *tlvs_list)
1328 u16 i = 1, total_length = 0;
1329 struct channel_tlv *tlv;
1332 /* cast current tlv list entry to channel tlv header */
1333 tlv = (struct channel_tlv *)((u8 *)tlvs_list + total_length);
1336 if (ecore_iov_tlv_supported(tlv->type))
1337 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1338 "TLV number %d: type %s, length %d\n",
1339 i, ecore_channel_tlvs_string[tlv->type],
1342 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1343 "TLV number %d: type %d, length %d\n",
1344 i, tlv->type, tlv->length);
1346 if (tlv->type == CHANNEL_TLV_LIST_END)
1349 /* Validate entry - protect against malicious VFs */
1351 DP_NOTICE(p_hwfn, false, "TLV of length 0 found\n");
1354 total_length += tlv->length;
1355 if (total_length >= sizeof(struct tlv_buffer_size)) {
1356 DP_NOTICE(p_hwfn, false, "TLV ==> Buffer overflow\n");
1364 static void ecore_iov_send_response(struct ecore_hwfn *p_hwfn,
1365 struct ecore_ptt *p_ptt,
1366 struct ecore_vf_info *p_vf,
1367 #ifdef CONFIG_ECORE_SW_CHANNEL
1370 u16 OSAL_UNUSED length,
1374 struct ecore_iov_vf_mbx *mbx = &p_vf->vf_mbx;
1375 struct ecore_dmae_params params;
1378 mbx->reply_virt->default_resp.hdr.status = status;
1380 ecore_dp_tlv_list(p_hwfn, mbx->reply_virt);
1382 #ifdef CONFIG_ECORE_SW_CHANNEL
1383 mbx->sw_mbx.response_size =
1384 length + sizeof(struct channel_list_end_tlv);
1386 if (!p_vf->b_hw_channel)
1390 eng_vf_id = p_vf->abs_vf_id;
1392 OSAL_MEMSET(¶ms, 0, sizeof(struct ecore_dmae_params));
1393 params.flags = ECORE_DMAE_FLAG_VF_DST;
1394 params.dst_vfid = eng_vf_id;
1396 ecore_dmae_host2host(p_hwfn, p_ptt, mbx->reply_phys + sizeof(u64),
1397 mbx->req_virt->first_tlv.reply_address +
1399 (sizeof(union pfvf_tlvs) - sizeof(u64)) / 4,
1402 /* Once PF copies the rc to the VF, the latter can continue and
1403 * and send an additional message. So we have to make sure the
1404 * channel would be re-set to ready prior to that.
1407 GTT_BAR0_MAP_REG_USDM_RAM +
1408 USTORM_VF_PF_CHANNEL_READY_OFFSET(eng_vf_id), 1);
1410 ecore_dmae_host2host(p_hwfn, p_ptt, mbx->reply_phys,
1411 mbx->req_virt->first_tlv.reply_address,
1412 sizeof(u64) / 4, ¶ms);
1414 OSAL_IOV_PF_RESP_TYPE(p_hwfn, p_vf->relative_vf_id, status);
1417 static u16 ecore_iov_vport_to_tlv(enum ecore_iov_vport_update_flag flag)
1420 case ECORE_IOV_VP_UPDATE_ACTIVATE:
1421 return CHANNEL_TLV_VPORT_UPDATE_ACTIVATE;
1422 case ECORE_IOV_VP_UPDATE_VLAN_STRIP:
1423 return CHANNEL_TLV_VPORT_UPDATE_VLAN_STRIP;
1424 case ECORE_IOV_VP_UPDATE_TX_SWITCH:
1425 return CHANNEL_TLV_VPORT_UPDATE_TX_SWITCH;
1426 case ECORE_IOV_VP_UPDATE_MCAST:
1427 return CHANNEL_TLV_VPORT_UPDATE_MCAST;
1428 case ECORE_IOV_VP_UPDATE_ACCEPT_PARAM:
1429 return CHANNEL_TLV_VPORT_UPDATE_ACCEPT_PARAM;
1430 case ECORE_IOV_VP_UPDATE_RSS:
1431 return CHANNEL_TLV_VPORT_UPDATE_RSS;
1432 case ECORE_IOV_VP_UPDATE_ACCEPT_ANY_VLAN:
1433 return CHANNEL_TLV_VPORT_UPDATE_ACCEPT_ANY_VLAN;
1434 case ECORE_IOV_VP_UPDATE_SGE_TPA:
1435 return CHANNEL_TLV_VPORT_UPDATE_SGE_TPA;
1441 static u16 ecore_iov_prep_vp_update_resp_tlvs(struct ecore_hwfn *p_hwfn,
1442 struct ecore_vf_info *p_vf,
1443 struct ecore_iov_vf_mbx *p_mbx,
1444 u8 status, u16 tlvs_mask,
1447 struct pfvf_def_resp_tlv *resp;
1448 u16 size, total_len, i;
1450 OSAL_MEMSET(p_mbx->reply_virt, 0, sizeof(union pfvf_tlvs));
1451 p_mbx->offset = (u8 *)p_mbx->reply_virt;
1452 size = sizeof(struct pfvf_def_resp_tlv);
1455 ecore_add_tlv(&p_mbx->offset, CHANNEL_TLV_VPORT_UPDATE, size);
1457 /* Prepare response for all extended tlvs if they are found by PF */
1458 for (i = 0; i < ECORE_IOV_VP_UPDATE_MAX; i++) {
1459 if (!(tlvs_mask & (1 << i)))
1462 resp = ecore_add_tlv(&p_mbx->offset, ecore_iov_vport_to_tlv(i),
1465 if (tlvs_accepted & (1 << i))
1466 resp->hdr.status = status;
1468 resp->hdr.status = PFVF_STATUS_NOT_SUPPORTED;
1470 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1471 "VF[%d] - vport_update resp: TLV %d, status %02x\n",
1472 p_vf->relative_vf_id,
1473 ecore_iov_vport_to_tlv(i),
1479 ecore_add_tlv(&p_mbx->offset, CHANNEL_TLV_LIST_END,
1480 sizeof(struct channel_list_end_tlv));
1485 static void ecore_iov_prepare_resp(struct ecore_hwfn *p_hwfn,
1486 struct ecore_ptt *p_ptt,
1487 struct ecore_vf_info *vf_info,
1488 u16 type, u16 length, u8 status)
1490 struct ecore_iov_vf_mbx *mbx = &vf_info->vf_mbx;
1492 mbx->offset = (u8 *)mbx->reply_virt;
1494 ecore_add_tlv(&mbx->offset, type, length);
1495 ecore_add_tlv(&mbx->offset, CHANNEL_TLV_LIST_END,
1496 sizeof(struct channel_list_end_tlv));
1498 ecore_iov_send_response(p_hwfn, p_ptt, vf_info, length, status);
1501 struct ecore_public_vf_info
1502 *ecore_iov_get_public_vf_info(struct ecore_hwfn *p_hwfn,
1504 bool b_enabled_only)
1506 struct ecore_vf_info *vf = OSAL_NULL;
1508 vf = ecore_iov_get_vf_info(p_hwfn, relative_vf_id, b_enabled_only);
1512 return &vf->p_vf_info;
1515 static void ecore_iov_vf_cleanup(struct ecore_hwfn *p_hwfn,
1516 struct ecore_vf_info *p_vf)
1519 p_vf->vf_bulletin = 0;
1520 p_vf->vport_instance = 0;
1521 p_vf->configured_features = 0;
1523 /* If VF previously requested less resources, go back to default */
1524 p_vf->num_rxqs = p_vf->num_sbs;
1525 p_vf->num_txqs = p_vf->num_sbs;
1527 p_vf->num_active_rxqs = 0;
1529 for (i = 0; i < ECORE_MAX_VF_CHAINS_PER_PF; i++) {
1530 struct ecore_vf_queue *p_queue = &p_vf->vf_queues[i];
1532 for (j = 0; j < MAX_QUEUES_PER_QZONE; j++) {
1533 if (!p_queue->cids[j].p_cid)
1536 ecore_eth_queue_cid_release(p_hwfn,
1537 p_queue->cids[j].p_cid);
1538 p_queue->cids[j].p_cid = OSAL_NULL;
1542 OSAL_MEMSET(&p_vf->shadow_config, 0, sizeof(p_vf->shadow_config));
1543 OSAL_MEMSET(&p_vf->acquire, 0, sizeof(p_vf->acquire));
1544 OSAL_IOV_VF_CLEANUP(p_hwfn, p_vf->relative_vf_id);
1547 /* Returns either 0, or log(size) */
1548 static u32 ecore_iov_vf_db_bar_size(struct ecore_hwfn *p_hwfn,
1549 struct ecore_ptt *p_ptt)
1551 u32 val = ecore_rd(p_hwfn, p_ptt, PGLUE_B_REG_VF_BAR1_SIZE);
1559 ecore_iov_vf_mbx_acquire_resc_cids(struct ecore_hwfn *p_hwfn,
1560 struct ecore_ptt *p_ptt,
1561 struct ecore_vf_info *p_vf,
1562 struct vf_pf_resc_request *p_req,
1563 struct pf_vf_resc *p_resp)
1565 u8 num_vf_cons = p_hwfn->pf_params.eth_pf_params.num_vf_cons;
1566 u8 db_size = DB_ADDR_VF(1, DQ_DEMS_LEGACY) -
1567 DB_ADDR_VF(0, DQ_DEMS_LEGACY);
1570 p_resp->num_cids = OSAL_MIN_T(u8, p_req->num_cids, num_vf_cons);
1572 /* If VF didn't bother asking for QIDs than don't bother limiting
1573 * number of CIDs. The VF doesn't care about the number, and this
1574 * has the likely result of causing an additional acquisition.
1576 if (!(p_vf->acquire.vfdev_info.capabilities &
1577 VFPF_ACQUIRE_CAP_QUEUE_QIDS))
1580 /* If doorbell bar was mapped by VF, limit the VF CIDs to an amount
1581 * that would make sure doorbells for all CIDs fall within the bar.
1582 * If it doesn't, make sure regview window is sufficient.
1584 if (p_vf->acquire.vfdev_info.capabilities &
1585 VFPF_ACQUIRE_CAP_PHYSICAL_BAR) {
1586 bar_size = ecore_iov_vf_db_bar_size(p_hwfn, p_ptt);
1588 bar_size = 1 << bar_size;
1590 if (ECORE_IS_CMT(p_hwfn->p_dev))
1593 bar_size = PXP_VF_BAR0_DQ_LENGTH;
1596 if (bar_size / db_size < 256)
1597 p_resp->num_cids = OSAL_MIN_T(u8, p_resp->num_cids,
1598 (u8)(bar_size / db_size));
1601 static u8 ecore_iov_vf_mbx_acquire_resc(struct ecore_hwfn *p_hwfn,
1602 struct ecore_ptt *p_ptt,
1603 struct ecore_vf_info *p_vf,
1604 struct vf_pf_resc_request *p_req,
1605 struct pf_vf_resc *p_resp)
1609 /* Queue related information */
1610 p_resp->num_rxqs = p_vf->num_rxqs;
1611 p_resp->num_txqs = p_vf->num_txqs;
1612 p_resp->num_sbs = p_vf->num_sbs;
1614 for (i = 0; i < p_resp->num_sbs; i++) {
1615 p_resp->hw_sbs[i].hw_sb_id = p_vf->igu_sbs[i];
1616 /* TODO - what's this sb_qid field? Is it deprecated?
1617 * or is there an ecore_client that looks at this?
1619 p_resp->hw_sbs[i].sb_qid = 0;
1622 /* These fields are filled for backward compatibility.
1623 * Unused by modern vfs.
1625 for (i = 0; i < p_resp->num_rxqs; i++) {
1626 ecore_fw_l2_queue(p_hwfn, p_vf->vf_queues[i].fw_rx_qid,
1627 (u16 *)&p_resp->hw_qid[i]);
1631 /* Filter related information */
1632 p_resp->num_mac_filters = OSAL_MIN_T(u8, p_vf->num_mac_filters,
1633 p_req->num_mac_filters);
1634 p_resp->num_vlan_filters = OSAL_MIN_T(u8, p_vf->num_vlan_filters,
1635 p_req->num_vlan_filters);
1637 ecore_iov_vf_mbx_acquire_resc_cids(p_hwfn, p_ptt, p_vf, p_req, p_resp);
1639 /* This isn't really needed/enforced, but some legacy VFs might depend
1640 * on the correct filling of this field.
1642 p_resp->num_mc_filters = ECORE_MAX_MC_ADDRS;
1644 /* Validate sufficient resources for VF */
1645 if (p_resp->num_rxqs < p_req->num_rxqs ||
1646 p_resp->num_txqs < p_req->num_txqs ||
1647 p_resp->num_sbs < p_req->num_sbs ||
1648 p_resp->num_mac_filters < p_req->num_mac_filters ||
1649 p_resp->num_vlan_filters < p_req->num_vlan_filters ||
1650 p_resp->num_mc_filters < p_req->num_mc_filters ||
1651 p_resp->num_cids < p_req->num_cids) {
1652 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1653 "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",
1655 p_req->num_rxqs, p_resp->num_rxqs,
1656 p_req->num_rxqs, p_resp->num_txqs,
1657 p_req->num_sbs, p_resp->num_sbs,
1658 p_req->num_mac_filters, p_resp->num_mac_filters,
1659 p_req->num_vlan_filters, p_resp->num_vlan_filters,
1660 p_req->num_mc_filters, p_resp->num_mc_filters,
1661 p_req->num_cids, p_resp->num_cids);
1663 /* Some legacy OSes are incapable of correctly handling this
1666 if ((p_vf->acquire.vfdev_info.eth_fp_hsi_minor ==
1667 ETH_HSI_VER_NO_PKT_LEN_TUNN) &&
1668 (p_vf->acquire.vfdev_info.os_type ==
1669 VFPF_ACQUIRE_OS_WINDOWS))
1670 return PFVF_STATUS_SUCCESS;
1672 return PFVF_STATUS_NO_RESOURCE;
1675 return PFVF_STATUS_SUCCESS;
1678 static void ecore_iov_vf_mbx_acquire_stats(struct pfvf_stats_info *p_stats)
1680 p_stats->mstats.address = PXP_VF_BAR0_START_MSDM_ZONE_B +
1681 OFFSETOF(struct mstorm_vf_zone,
1682 non_trigger.eth_queue_stat);
1683 p_stats->mstats.len = sizeof(struct eth_mstorm_per_queue_stat);
1684 p_stats->ustats.address = PXP_VF_BAR0_START_USDM_ZONE_B +
1685 OFFSETOF(struct ustorm_vf_zone,
1686 non_trigger.eth_queue_stat);
1687 p_stats->ustats.len = sizeof(struct eth_ustorm_per_queue_stat);
1688 p_stats->pstats.address = PXP_VF_BAR0_START_PSDM_ZONE_B +
1689 OFFSETOF(struct pstorm_vf_zone,
1690 non_trigger.eth_queue_stat);
1691 p_stats->pstats.len = sizeof(struct eth_pstorm_per_queue_stat);
1692 p_stats->tstats.address = 0;
1693 p_stats->tstats.len = 0;
1696 static void ecore_iov_vf_mbx_acquire(struct ecore_hwfn *p_hwfn,
1697 struct ecore_ptt *p_ptt,
1698 struct ecore_vf_info *vf)
1700 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
1701 struct pfvf_acquire_resp_tlv *resp = &mbx->reply_virt->acquire_resp;
1702 struct pf_vf_pfdev_info *pfdev_info = &resp->pfdev_info;
1703 struct vfpf_acquire_tlv *req = &mbx->req_virt->acquire;
1704 u8 vfpf_status = PFVF_STATUS_NOT_SUPPORTED;
1705 struct pf_vf_resc *resc = &resp->resc;
1706 enum _ecore_status_t rc;
1708 OSAL_MEMSET(resp, 0, sizeof(*resp));
1710 /* Write the PF version so that VF would know which version
1711 * is supported - might be later overridden. This guarantees that
1712 * VF could recognize legacy PF based on lack of versions in reply.
1714 pfdev_info->major_fp_hsi = ETH_HSI_VER_MAJOR;
1715 pfdev_info->minor_fp_hsi = ETH_HSI_VER_MINOR;
1717 /* TODO - not doing anything is bad since we'll assert, but this isn't
1718 * necessarily the right behavior - perhaps we should have allowed some
1721 if (vf->state != VF_FREE &&
1722 vf->state != VF_STOPPED) {
1723 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1724 "VF[%d] sent ACQUIRE but is already in state %d - fail request\n",
1725 vf->abs_vf_id, vf->state);
1729 /* Validate FW compatibility */
1730 if (req->vfdev_info.eth_fp_hsi_major != ETH_HSI_VER_MAJOR) {
1731 if (req->vfdev_info.capabilities &
1732 VFPF_ACQUIRE_CAP_PRE_FP_HSI) {
1733 struct vf_pf_vfdev_info *p_vfdev = &req->vfdev_info;
1735 /* This legacy support would need to be removed once
1736 * the major has changed.
1738 OSAL_BUILD_BUG_ON(ETH_HSI_VER_MAJOR != 3);
1740 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1741 "VF[%d] is pre-fastpath HSI\n",
1743 p_vfdev->eth_fp_hsi_major = ETH_HSI_VER_MAJOR;
1744 p_vfdev->eth_fp_hsi_minor = ETH_HSI_VER_NO_PKT_LEN_TUNN;
1747 "VF[%d] needs fastpath HSI %02x.%02x, which is"
1748 " incompatible with loaded FW's faspath"
1751 req->vfdev_info.eth_fp_hsi_major,
1752 req->vfdev_info.eth_fp_hsi_minor,
1753 ETH_HSI_VER_MAJOR, ETH_HSI_VER_MINOR);
1759 /* On 100g PFs, prevent old VFs from loading */
1760 if (ECORE_IS_CMT(p_hwfn->p_dev) &&
1761 !(req->vfdev_info.capabilities & VFPF_ACQUIRE_CAP_100G)) {
1763 "VF[%d] is running an old driver that doesn't support"
1769 #ifndef __EXTRACT__LINUX__
1770 if (OSAL_IOV_VF_ACQUIRE(p_hwfn, vf->relative_vf_id) != ECORE_SUCCESS) {
1771 vfpf_status = PFVF_STATUS_NOT_SUPPORTED;
1776 /* Store the acquire message */
1777 OSAL_MEMCPY(&vf->acquire, req, sizeof(vf->acquire));
1779 vf->opaque_fid = req->vfdev_info.opaque_fid;
1781 vf->vf_bulletin = req->bulletin_addr;
1782 vf->bulletin.size = (vf->bulletin.size < req->bulletin_size) ?
1783 vf->bulletin.size : req->bulletin_size;
1785 /* fill in pfdev info */
1786 pfdev_info->chip_num = p_hwfn->p_dev->chip_num;
1787 pfdev_info->db_size = 0; /* @@@ TBD MichalK Vf Doorbells */
1788 pfdev_info->indices_per_sb = PIS_PER_SB_E4;
1790 pfdev_info->capabilities = PFVF_ACQUIRE_CAP_DEFAULT_UNTAGGED |
1791 PFVF_ACQUIRE_CAP_POST_FW_OVERRIDE;
1792 if (ECORE_IS_CMT(p_hwfn->p_dev))
1793 pfdev_info->capabilities |= PFVF_ACQUIRE_CAP_100G;
1795 /* Share our ability to use multiple queue-ids only with VFs
1798 if (req->vfdev_info.capabilities & VFPF_ACQUIRE_CAP_QUEUE_QIDS)
1799 pfdev_info->capabilities |= PFVF_ACQUIRE_CAP_QUEUE_QIDS;
1801 /* Share the sizes of the bars with VF */
1802 resp->pfdev_info.bar_size = (u8)ecore_iov_vf_db_bar_size(p_hwfn,
1805 ecore_iov_vf_mbx_acquire_stats(&pfdev_info->stats_info);
1807 OSAL_MEMCPY(pfdev_info->port_mac, p_hwfn->hw_info.hw_mac_addr,
1810 pfdev_info->fw_major = FW_MAJOR_VERSION;
1811 pfdev_info->fw_minor = FW_MINOR_VERSION;
1812 pfdev_info->fw_rev = FW_REVISION_VERSION;
1813 pfdev_info->fw_eng = FW_ENGINEERING_VERSION;
1815 /* Incorrect when legacy, but doesn't matter as legacy isn't reading
1818 pfdev_info->minor_fp_hsi = OSAL_MIN_T(u8, ETH_HSI_VER_MINOR,
1819 req->vfdev_info.eth_fp_hsi_minor);
1820 pfdev_info->os_type = OSAL_IOV_GET_OS_TYPE();
1821 ecore_mcp_get_mfw_ver(p_hwfn, p_ptt, &pfdev_info->mfw_ver,
1824 pfdev_info->dev_type = p_hwfn->p_dev->type;
1825 pfdev_info->chip_rev = p_hwfn->p_dev->chip_rev;
1827 /* Fill resources available to VF; Make sure there are enough to
1828 * satisfy the VF's request.
1830 vfpf_status = ecore_iov_vf_mbx_acquire_resc(p_hwfn, p_ptt, vf,
1831 &req->resc_request, resc);
1832 if (vfpf_status != PFVF_STATUS_SUCCESS)
1835 /* Start the VF in FW */
1836 rc = ecore_sp_vf_start(p_hwfn, vf);
1837 if (rc != ECORE_SUCCESS) {
1838 DP_NOTICE(p_hwfn, true, "Failed to start VF[%02x]\n",
1840 vfpf_status = PFVF_STATUS_FAILURE;
1844 /* Fill agreed size of bulletin board in response, and post
1845 * an initial image to the bulletin board.
1847 resp->bulletin_size = vf->bulletin.size;
1848 ecore_iov_post_vf_bulletin(p_hwfn, vf->relative_vf_id, p_ptt);
1850 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1851 "VF[%d] ACQUIRE_RESPONSE: pfdev_info- chip_num=0x%x,"
1852 " db_size=%d, idx_per_sb=%d, pf_cap=0x%lx\n"
1853 "resources- n_rxq-%d, n_txq-%d, n_sbs-%d, n_macs-%d,"
1855 vf->abs_vf_id, resp->pfdev_info.chip_num,
1856 resp->pfdev_info.db_size, resp->pfdev_info.indices_per_sb,
1857 (unsigned long)resp->pfdev_info.capabilities, resc->num_rxqs,
1858 resc->num_txqs, resc->num_sbs, resc->num_mac_filters,
1859 resc->num_vlan_filters);
1861 vf->state = VF_ACQUIRED;
1864 /* Prepare Response */
1865 ecore_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_ACQUIRE,
1866 sizeof(struct pfvf_acquire_resp_tlv),
1870 static enum _ecore_status_t
1871 __ecore_iov_spoofchk_set(struct ecore_hwfn *p_hwfn,
1872 struct ecore_vf_info *p_vf, bool val)
1874 struct ecore_sp_vport_update_params params;
1875 enum _ecore_status_t rc;
1877 if (val == p_vf->spoof_chk) {
1878 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1879 "Spoofchk value[%d] is already configured\n", val);
1880 return ECORE_SUCCESS;
1883 OSAL_MEMSET(¶ms, 0, sizeof(struct ecore_sp_vport_update_params));
1884 params.opaque_fid = p_vf->opaque_fid;
1885 params.vport_id = p_vf->vport_id;
1886 params.update_anti_spoofing_en_flg = 1;
1887 params.anti_spoofing_en = val;
1889 rc = ecore_sp_vport_update(p_hwfn, ¶ms, ECORE_SPQ_MODE_EBLOCK,
1891 if (rc == ECORE_SUCCESS) {
1892 p_vf->spoof_chk = val;
1893 p_vf->req_spoofchk_val = p_vf->spoof_chk;
1894 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1895 "Spoofchk val[%d] configured\n", val);
1897 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1898 "Spoofchk configuration[val:%d] failed for VF[%d]\n",
1899 val, p_vf->relative_vf_id);
1905 static enum _ecore_status_t
1906 ecore_iov_reconfigure_unicast_vlan(struct ecore_hwfn *p_hwfn,
1907 struct ecore_vf_info *p_vf)
1909 struct ecore_filter_ucast filter;
1910 enum _ecore_status_t rc = ECORE_SUCCESS;
1913 OSAL_MEMSET(&filter, 0, sizeof(filter));
1914 filter.is_rx_filter = 1;
1915 filter.is_tx_filter = 1;
1916 filter.vport_to_add_to = p_vf->vport_id;
1917 filter.opcode = ECORE_FILTER_ADD;
1919 /* Reconfigure vlans */
1920 for (i = 0; i < ECORE_ETH_VF_NUM_VLAN_FILTERS + 1; i++) {
1921 if (!p_vf->shadow_config.vlans[i].used)
1924 filter.type = ECORE_FILTER_VLAN;
1925 filter.vlan = p_vf->shadow_config.vlans[i].vid;
1926 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1927 "Reconfiguring VLAN [0x%04x] for VF [%04x]\n",
1928 filter.vlan, p_vf->relative_vf_id);
1929 rc = ecore_sp_eth_filter_ucast(p_hwfn, p_vf->opaque_fid,
1930 &filter, ECORE_SPQ_MODE_CB,
1933 DP_NOTICE(p_hwfn, true,
1934 "Failed to configure VLAN [%04x]"
1936 filter.vlan, p_vf->relative_vf_id);
1944 static enum _ecore_status_t
1945 ecore_iov_reconfigure_unicast_shadow(struct ecore_hwfn *p_hwfn,
1946 struct ecore_vf_info *p_vf, u64 events)
1948 enum _ecore_status_t rc = ECORE_SUCCESS;
1950 /*TODO - what about MACs? */
1952 if ((events & (1 << VLAN_ADDR_FORCED)) &&
1953 !(p_vf->configured_features & (1 << VLAN_ADDR_FORCED)))
1954 rc = ecore_iov_reconfigure_unicast_vlan(p_hwfn, p_vf);
1959 static enum _ecore_status_t
1960 ecore_iov_configure_vport_forced(struct ecore_hwfn *p_hwfn,
1961 struct ecore_vf_info *p_vf,
1964 enum _ecore_status_t rc = ECORE_SUCCESS;
1965 struct ecore_filter_ucast filter;
1967 if (!p_vf->vport_instance)
1970 if ((events & (1 << MAC_ADDR_FORCED)) ||
1971 p_hwfn->pf_params.eth_pf_params.allow_vf_mac_change ||
1972 p_vf->p_vf_info.is_trusted_configured) {
1973 /* Since there's no way [currently] of removing the MAC,
1974 * we can always assume this means we need to force it.
1976 OSAL_MEMSET(&filter, 0, sizeof(filter));
1977 filter.type = ECORE_FILTER_MAC;
1978 filter.opcode = ECORE_FILTER_REPLACE;
1979 filter.is_rx_filter = 1;
1980 filter.is_tx_filter = 1;
1981 filter.vport_to_add_to = p_vf->vport_id;
1982 OSAL_MEMCPY(filter.mac, p_vf->bulletin.p_virt->mac, ETH_ALEN);
1984 rc = ecore_sp_eth_filter_ucast(p_hwfn, p_vf->opaque_fid,
1986 ECORE_SPQ_MODE_CB, OSAL_NULL);
1988 DP_NOTICE(p_hwfn, true,
1989 "PF failed to configure MAC for VF\n");
1993 if (p_hwfn->pf_params.eth_pf_params.allow_vf_mac_change ||
1994 p_vf->p_vf_info.is_trusted_configured)
1995 p_vf->configured_features |=
1996 1 << VFPF_BULLETIN_MAC_ADDR;
1998 p_vf->configured_features |= 1 << MAC_ADDR_FORCED;
2001 if (events & (1 << VLAN_ADDR_FORCED)) {
2002 struct ecore_sp_vport_update_params vport_update;
2006 OSAL_MEMSET(&filter, 0, sizeof(filter));
2007 filter.type = ECORE_FILTER_VLAN;
2008 filter.is_rx_filter = 1;
2009 filter.is_tx_filter = 1;
2010 filter.vport_to_add_to = p_vf->vport_id;
2011 filter.vlan = p_vf->bulletin.p_virt->pvid;
2012 filter.opcode = filter.vlan ? ECORE_FILTER_REPLACE :
2015 /* Send the ramrod */
2016 rc = ecore_sp_eth_filter_ucast(p_hwfn, p_vf->opaque_fid,
2018 ECORE_SPQ_MODE_CB, OSAL_NULL);
2020 DP_NOTICE(p_hwfn, true,
2021 "PF failed to configure VLAN for VF\n");
2025 /* Update the default-vlan & silent vlan stripping */
2026 OSAL_MEMSET(&vport_update, 0, sizeof(vport_update));
2027 vport_update.opaque_fid = p_vf->opaque_fid;
2028 vport_update.vport_id = p_vf->vport_id;
2029 vport_update.update_default_vlan_enable_flg = 1;
2030 vport_update.default_vlan_enable_flg = filter.vlan ? 1 : 0;
2031 vport_update.update_default_vlan_flg = 1;
2032 vport_update.default_vlan = filter.vlan;
2034 vport_update.update_inner_vlan_removal_flg = 1;
2035 removal = filter.vlan ?
2036 1 : p_vf->shadow_config.inner_vlan_removal;
2037 vport_update.inner_vlan_removal_flg = removal;
2038 vport_update.silent_vlan_removal_flg = filter.vlan ? 1 : 0;
2039 rc = ecore_sp_vport_update(p_hwfn, &vport_update,
2040 ECORE_SPQ_MODE_EBLOCK, OSAL_NULL);
2042 DP_NOTICE(p_hwfn, true,
2043 "PF failed to configure VF vport for vlan\n");
2047 /* Update all the Rx queues */
2048 for (i = 0; i < ECORE_MAX_VF_CHAINS_PER_PF; i++) {
2049 struct ecore_vf_queue *p_queue = &p_vf->vf_queues[i];
2050 struct ecore_queue_cid *p_cid = OSAL_NULL;
2052 /* There can be at most 1 Rx queue on qzone. Find it */
2053 p_cid = ecore_iov_get_vf_rx_queue_cid(p_queue);
2054 if (p_cid == OSAL_NULL)
2057 rc = ecore_sp_eth_rx_queues_update(p_hwfn,
2060 ECORE_SPQ_MODE_EBLOCK,
2063 DP_NOTICE(p_hwfn, true,
2064 "Failed to send Rx update"
2065 " fo queue[0x%04x]\n",
2066 p_cid->rel.queue_id);
2072 p_vf->configured_features |= 1 << VLAN_ADDR_FORCED;
2074 p_vf->configured_features &= ~(1 << VLAN_ADDR_FORCED);
2077 /* If forced features are terminated, we need to configure the shadow
2078 * configuration back again.
2081 ecore_iov_reconfigure_unicast_shadow(p_hwfn, p_vf, events);
2086 static void ecore_iov_vf_mbx_start_vport(struct ecore_hwfn *p_hwfn,
2087 struct ecore_ptt *p_ptt,
2088 struct ecore_vf_info *vf)
2090 struct ecore_sp_vport_start_params params = { 0 };
2091 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
2092 struct vfpf_vport_start_tlv *start;
2093 u8 status = PFVF_STATUS_SUCCESS;
2094 struct ecore_vf_info *vf_info;
2097 enum _ecore_status_t rc;
2099 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vf->relative_vf_id, true);
2101 DP_NOTICE(p_hwfn->p_dev, true,
2102 "Failed to get VF info, invalid vfid [%d]\n",
2103 vf->relative_vf_id);
2107 vf->state = VF_ENABLED;
2108 start = &mbx->req_virt->start_vport;
2110 ecore_iov_enable_vf_traffic(p_hwfn, p_ptt, vf);
2112 /* Initialize Status block in CAU */
2113 for (sb_id = 0; sb_id < vf->num_sbs; sb_id++) {
2114 if (!start->sb_addr[sb_id]) {
2115 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2116 "VF[%d] did not fill the address of SB %d\n",
2117 vf->relative_vf_id, sb_id);
2121 ecore_int_cau_conf_sb(p_hwfn, p_ptt,
2122 start->sb_addr[sb_id],
2127 vf->mtu = start->mtu;
2128 vf->shadow_config.inner_vlan_removal = start->inner_vlan_removal;
2130 /* Take into consideration configuration forced by hypervisor;
2131 * If none is configured, use the supplied VF values [for old
2132 * vfs that would still be fine, since they passed '0' as padding].
2134 p_bitmap = &vf_info->bulletin.p_virt->valid_bitmap;
2135 if (!(*p_bitmap & (1 << VFPF_BULLETIN_UNTAGGED_DEFAULT_FORCED))) {
2136 u8 vf_req = start->only_untagged;
2138 vf_info->bulletin.p_virt->default_only_untagged = vf_req;
2139 *p_bitmap |= 1 << VFPF_BULLETIN_UNTAGGED_DEFAULT;
2142 params.tpa_mode = start->tpa_mode;
2143 params.remove_inner_vlan = start->inner_vlan_removal;
2144 params.tx_switching = true;
2147 if (CHIP_REV_IS_FPGA(p_hwfn->p_dev)) {
2148 DP_NOTICE(p_hwfn, false,
2149 "FPGA: Don't config VF for Tx-switching [no pVFC]\n");
2150 params.tx_switching = false;
2154 params.only_untagged = vf_info->bulletin.p_virt->default_only_untagged;
2155 params.drop_ttl0 = false;
2156 params.concrete_fid = vf->concrete_fid;
2157 params.opaque_fid = vf->opaque_fid;
2158 params.vport_id = vf->vport_id;
2159 params.max_buffers_per_cqe = start->max_buffers_per_cqe;
2160 params.mtu = vf->mtu;
2162 /* Non trusted VFs should enable control frame filtering */
2163 params.check_mac = !vf->p_vf_info.is_trusted_configured;
2165 rc = ecore_sp_eth_vport_start(p_hwfn, ¶ms);
2166 if (rc != ECORE_SUCCESS) {
2168 "ecore_iov_vf_mbx_start_vport returned error %d\n", rc);
2169 status = PFVF_STATUS_FAILURE;
2171 vf->vport_instance++;
2173 /* Force configuration if needed on the newly opened vport */
2174 ecore_iov_configure_vport_forced(p_hwfn, vf, *p_bitmap);
2175 OSAL_IOV_POST_START_VPORT(p_hwfn, vf->relative_vf_id,
2176 vf->vport_id, vf->opaque_fid);
2177 __ecore_iov_spoofchk_set(p_hwfn, vf, vf->req_spoofchk_val);
2180 ecore_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_VPORT_START,
2181 sizeof(struct pfvf_def_resp_tlv), status);
2184 static void ecore_iov_vf_mbx_stop_vport(struct ecore_hwfn *p_hwfn,
2185 struct ecore_ptt *p_ptt,
2186 struct ecore_vf_info *vf)
2188 u8 status = PFVF_STATUS_SUCCESS;
2189 enum _ecore_status_t rc;
2191 OSAL_IOV_VF_VPORT_STOP(p_hwfn, vf);
2192 vf->vport_instance--;
2193 vf->spoof_chk = false;
2195 if ((ecore_iov_validate_active_rxq(vf)) ||
2196 (ecore_iov_validate_active_txq(vf))) {
2197 vf->b_malicious = true;
2198 DP_NOTICE(p_hwfn, false,
2199 "VF [%02x] - considered malicious;"
2200 " Unable to stop RX/TX queuess\n",
2202 status = PFVF_STATUS_MALICIOUS;
2206 rc = ecore_sp_vport_stop(p_hwfn, vf->opaque_fid, vf->vport_id);
2207 if (rc != ECORE_SUCCESS) {
2209 "ecore_iov_vf_mbx_stop_vport returned error %d\n", rc);
2210 status = PFVF_STATUS_FAILURE;
2213 /* Forget the configuration on the vport */
2214 vf->configured_features = 0;
2215 OSAL_MEMSET(&vf->shadow_config, 0, sizeof(vf->shadow_config));
2218 ecore_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_VPORT_TEARDOWN,
2219 sizeof(struct pfvf_def_resp_tlv), status);
2222 static void ecore_iov_vf_mbx_start_rxq_resp(struct ecore_hwfn *p_hwfn,
2223 struct ecore_ptt *p_ptt,
2224 struct ecore_vf_info *vf,
2225 u8 status, bool b_legacy)
2227 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
2228 struct pfvf_start_queue_resp_tlv *p_tlv;
2229 struct vfpf_start_rxq_tlv *req;
2232 mbx->offset = (u8 *)mbx->reply_virt;
2234 /* Taking a bigger struct instead of adding a TLV to list was a
2235 * mistake, but one which we're now stuck with, as some older
2236 * clients assume the size of the previous response.
2239 length = sizeof(*p_tlv);
2241 length = sizeof(struct pfvf_def_resp_tlv);
2243 p_tlv = ecore_add_tlv(&mbx->offset, CHANNEL_TLV_START_RXQ, length);
2244 ecore_add_tlv(&mbx->offset, CHANNEL_TLV_LIST_END,
2245 sizeof(struct channel_list_end_tlv));
2247 /* Update the TLV with the response */
2248 if ((status == PFVF_STATUS_SUCCESS) && !b_legacy) {
2249 req = &mbx->req_virt->start_rxq;
2250 p_tlv->offset = PXP_VF_BAR0_START_MSDM_ZONE_B +
2251 OFFSETOF(struct mstorm_vf_zone,
2252 non_trigger.eth_rx_queue_producers) +
2253 sizeof(struct eth_rx_prod_data) * req->rx_qid;
2256 ecore_iov_send_response(p_hwfn, p_ptt, vf, length, status);
2259 static u8 ecore_iov_vf_mbx_qid(struct ecore_hwfn *p_hwfn,
2260 struct ecore_vf_info *p_vf, bool b_is_tx)
2262 struct ecore_iov_vf_mbx *p_mbx = &p_vf->vf_mbx;
2263 struct vfpf_qid_tlv *p_qid_tlv;
2265 /* Search for the qid if the VF published if its going to provide it */
2266 if (!(p_vf->acquire.vfdev_info.capabilities &
2267 VFPF_ACQUIRE_CAP_QUEUE_QIDS)) {
2269 return ECORE_IOV_LEGACY_QID_TX;
2271 return ECORE_IOV_LEGACY_QID_RX;
2274 p_qid_tlv = (struct vfpf_qid_tlv *)
2275 ecore_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt,
2277 if (p_qid_tlv == OSAL_NULL) {
2278 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2279 "VF[%2x]: Failed to provide qid\n",
2280 p_vf->relative_vf_id);
2282 return ECORE_IOV_QID_INVALID;
2285 if (p_qid_tlv->qid >= MAX_QUEUES_PER_QZONE) {
2286 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2287 "VF[%02x]: Provided qid out-of-bounds %02x\n",
2288 p_vf->relative_vf_id, p_qid_tlv->qid);
2289 return ECORE_IOV_QID_INVALID;
2292 return p_qid_tlv->qid;
2295 static void ecore_iov_vf_mbx_start_rxq(struct ecore_hwfn *p_hwfn,
2296 struct ecore_ptt *p_ptt,
2297 struct ecore_vf_info *vf)
2299 struct ecore_queue_start_common_params params;
2300 struct ecore_queue_cid_vf_params vf_params;
2301 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
2302 u8 status = PFVF_STATUS_NO_RESOURCE;
2303 u8 qid_usage_idx, vf_legacy = 0;
2304 struct ecore_vf_queue *p_queue;
2305 struct vfpf_start_rxq_tlv *req;
2306 struct ecore_queue_cid *p_cid;
2307 struct ecore_sb_info sb_dummy;
2308 enum _ecore_status_t rc;
2310 req = &mbx->req_virt->start_rxq;
2312 if (!ecore_iov_validate_rxq(p_hwfn, vf, req->rx_qid,
2313 ECORE_IOV_VALIDATE_Q_DISABLE) ||
2314 !ecore_iov_validate_sb(p_hwfn, vf, req->hw_sb))
2317 qid_usage_idx = ecore_iov_vf_mbx_qid(p_hwfn, vf, false);
2318 if (qid_usage_idx == ECORE_IOV_QID_INVALID)
2321 p_queue = &vf->vf_queues[req->rx_qid];
2322 if (p_queue->cids[qid_usage_idx].p_cid)
2325 vf_legacy = ecore_vf_calculate_legacy(vf);
2327 /* Acquire a new queue-cid */
2328 OSAL_MEMSET(¶ms, 0, sizeof(params));
2329 params.queue_id = (u8)p_queue->fw_rx_qid;
2330 params.vport_id = vf->vport_id;
2331 params.stats_id = vf->abs_vf_id + 0x10;
2333 /* Since IGU index is passed via sb_info, construct a dummy one */
2334 OSAL_MEM_ZERO(&sb_dummy, sizeof(sb_dummy));
2335 sb_dummy.igu_sb_id = req->hw_sb;
2336 params.p_sb = &sb_dummy;
2337 params.sb_idx = req->sb_index;
2339 OSAL_MEM_ZERO(&vf_params, sizeof(vf_params));
2340 vf_params.vfid = vf->relative_vf_id;
2341 vf_params.vf_qid = (u8)req->rx_qid;
2342 vf_params.vf_legacy = vf_legacy;
2343 vf_params.qid_usage_idx = qid_usage_idx;
2345 p_cid = ecore_eth_queue_to_cid(p_hwfn, vf->opaque_fid,
2346 ¶ms, true, &vf_params);
2347 if (p_cid == OSAL_NULL)
2350 /* Legacy VFs have their Producers in a different location, which they
2351 * calculate on their own and clean the producer prior to this.
2353 if (!(vf_legacy & ECORE_QCID_LEGACY_VF_RX_PROD))
2355 GTT_BAR0_MAP_REG_MSDM_RAM +
2356 MSTORM_ETH_VF_PRODS_OFFSET(vf->abs_vf_id, req->rx_qid),
2359 rc = ecore_eth_rxq_start_ramrod(p_hwfn, p_cid,
2364 if (rc != ECORE_SUCCESS) {
2365 status = PFVF_STATUS_FAILURE;
2366 ecore_eth_queue_cid_release(p_hwfn, p_cid);
2368 p_queue->cids[qid_usage_idx].p_cid = p_cid;
2369 p_queue->cids[qid_usage_idx].b_is_tx = false;
2370 status = PFVF_STATUS_SUCCESS;
2371 vf->num_active_rxqs++;
2375 ecore_iov_vf_mbx_start_rxq_resp(p_hwfn, p_ptt, vf, status,
2377 ECORE_QCID_LEGACY_VF_RX_PROD));
2381 ecore_iov_pf_update_tun_response(struct pfvf_update_tunn_param_tlv *p_resp,
2382 struct ecore_tunnel_info *p_tun,
2383 u16 tunn_feature_mask)
2385 p_resp->tunn_feature_mask = tunn_feature_mask;
2386 p_resp->vxlan_mode = p_tun->vxlan.b_mode_enabled;
2387 p_resp->l2geneve_mode = p_tun->l2_geneve.b_mode_enabled;
2388 p_resp->ipgeneve_mode = p_tun->ip_geneve.b_mode_enabled;
2389 p_resp->l2gre_mode = p_tun->l2_gre.b_mode_enabled;
2390 p_resp->ipgre_mode = p_tun->l2_gre.b_mode_enabled;
2391 p_resp->vxlan_clss = p_tun->vxlan.tun_cls;
2392 p_resp->l2gre_clss = p_tun->l2_gre.tun_cls;
2393 p_resp->ipgre_clss = p_tun->ip_gre.tun_cls;
2394 p_resp->l2geneve_clss = p_tun->l2_geneve.tun_cls;
2395 p_resp->ipgeneve_clss = p_tun->ip_geneve.tun_cls;
2396 p_resp->geneve_udp_port = p_tun->geneve_port.port;
2397 p_resp->vxlan_udp_port = p_tun->vxlan_port.port;
2401 __ecore_iov_pf_update_tun_param(struct vfpf_update_tunn_param_tlv *p_req,
2402 struct ecore_tunn_update_type *p_tun,
2403 enum ecore_tunn_mode mask, u8 tun_cls)
2405 if (p_req->tun_mode_update_mask & (1 << mask)) {
2406 p_tun->b_update_mode = true;
2408 if (p_req->tunn_mode & (1 << mask))
2409 p_tun->b_mode_enabled = true;
2412 p_tun->tun_cls = tun_cls;
2416 ecore_iov_pf_update_tun_param(struct vfpf_update_tunn_param_tlv *p_req,
2417 struct ecore_tunn_update_type *p_tun,
2418 struct ecore_tunn_update_udp_port *p_port,
2419 enum ecore_tunn_mode mask,
2420 u8 tun_cls, u8 update_port, u16 port)
2423 p_port->b_update_port = true;
2424 p_port->port = port;
2427 __ecore_iov_pf_update_tun_param(p_req, p_tun, mask, tun_cls);
2431 ecore_iov_pf_validate_tunn_param(struct vfpf_update_tunn_param_tlv *p_req)
2433 bool b_update_requested = false;
2435 if (p_req->tun_mode_update_mask || p_req->update_tun_cls ||
2436 p_req->update_geneve_port || p_req->update_vxlan_port)
2437 b_update_requested = true;
2439 return b_update_requested;
2442 static void ecore_iov_vf_mbx_update_tunn_param(struct ecore_hwfn *p_hwfn,
2443 struct ecore_ptt *p_ptt,
2444 struct ecore_vf_info *p_vf)
2446 struct ecore_tunnel_info *p_tun = &p_hwfn->p_dev->tunnel;
2447 struct ecore_iov_vf_mbx *mbx = &p_vf->vf_mbx;
2448 struct pfvf_update_tunn_param_tlv *p_resp;
2449 struct vfpf_update_tunn_param_tlv *p_req;
2450 enum _ecore_status_t rc = ECORE_SUCCESS;
2451 u8 status = PFVF_STATUS_SUCCESS;
2452 bool b_update_required = false;
2453 struct ecore_tunnel_info tunn;
2454 u16 tunn_feature_mask = 0;
2457 mbx->offset = (u8 *)mbx->reply_virt;
2459 OSAL_MEM_ZERO(&tunn, sizeof(tunn));
2460 p_req = &mbx->req_virt->tunn_param_update;
2462 if (!ecore_iov_pf_validate_tunn_param(p_req)) {
2463 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2464 "No tunnel update requested by VF\n");
2465 status = PFVF_STATUS_FAILURE;
2469 tunn.b_update_rx_cls = p_req->update_tun_cls;
2470 tunn.b_update_tx_cls = p_req->update_tun_cls;
2472 ecore_iov_pf_update_tun_param(p_req, &tunn.vxlan, &tunn.vxlan_port,
2473 ECORE_MODE_VXLAN_TUNN, p_req->vxlan_clss,
2474 p_req->update_vxlan_port,
2476 ecore_iov_pf_update_tun_param(p_req, &tunn.l2_geneve, &tunn.geneve_port,
2477 ECORE_MODE_L2GENEVE_TUNN,
2478 p_req->l2geneve_clss,
2479 p_req->update_geneve_port,
2480 p_req->geneve_port);
2481 __ecore_iov_pf_update_tun_param(p_req, &tunn.ip_geneve,
2482 ECORE_MODE_IPGENEVE_TUNN,
2483 p_req->ipgeneve_clss);
2484 __ecore_iov_pf_update_tun_param(p_req, &tunn.l2_gre,
2485 ECORE_MODE_L2GRE_TUNN,
2487 __ecore_iov_pf_update_tun_param(p_req, &tunn.ip_gre,
2488 ECORE_MODE_IPGRE_TUNN,
2491 /* If PF modifies VF's req then it should
2492 * still return an error in case of partial configuration
2493 * or modified configuration as opposed to requested one.
2495 rc = OSAL_PF_VALIDATE_MODIFY_TUNN_CONFIG(p_hwfn, &tunn_feature_mask,
2496 &b_update_required, &tunn);
2498 if (rc != ECORE_SUCCESS)
2499 status = PFVF_STATUS_FAILURE;
2501 /* If ECORE client is willing to update anything ? */
2502 if (b_update_required) {
2505 rc = ecore_sp_pf_update_tunn_cfg(p_hwfn, p_ptt, &tunn,
2506 ECORE_SPQ_MODE_EBLOCK,
2508 if (rc != ECORE_SUCCESS)
2509 status = PFVF_STATUS_FAILURE;
2511 geneve_port = p_tun->geneve_port.port;
2512 ecore_for_each_vf(p_hwfn, i) {
2513 ecore_iov_bulletin_set_udp_ports(p_hwfn, i,
2514 p_tun->vxlan_port.port,
2520 p_resp = ecore_add_tlv(&mbx->offset,
2521 CHANNEL_TLV_UPDATE_TUNN_PARAM, sizeof(*p_resp));
2523 ecore_iov_pf_update_tun_response(p_resp, p_tun, tunn_feature_mask);
2524 ecore_add_tlv(&mbx->offset, CHANNEL_TLV_LIST_END,
2525 sizeof(struct channel_list_end_tlv));
2527 ecore_iov_send_response(p_hwfn, p_ptt, p_vf, sizeof(*p_resp), status);
2530 static void ecore_iov_vf_mbx_start_txq_resp(struct ecore_hwfn *p_hwfn,
2531 struct ecore_ptt *p_ptt,
2532 struct ecore_vf_info *p_vf,
2536 struct ecore_iov_vf_mbx *mbx = &p_vf->vf_mbx;
2537 struct pfvf_start_queue_resp_tlv *p_tlv;
2538 bool b_legacy = false;
2541 mbx->offset = (u8 *)mbx->reply_virt;
2543 /* Taking a bigger struct instead of adding a TLV to list was a
2544 * mistake, but one which we're now stuck with, as some older
2545 * clients assume the size of the previous response.
2547 if (p_vf->acquire.vfdev_info.eth_fp_hsi_minor ==
2548 ETH_HSI_VER_NO_PKT_LEN_TUNN)
2552 length = sizeof(*p_tlv);
2554 length = sizeof(struct pfvf_def_resp_tlv);
2556 p_tlv = ecore_add_tlv(&mbx->offset, CHANNEL_TLV_START_TXQ, length);
2557 ecore_add_tlv(&mbx->offset, CHANNEL_TLV_LIST_END,
2558 sizeof(struct channel_list_end_tlv));
2560 /* Update the TLV with the response */
2561 if ((status == PFVF_STATUS_SUCCESS) && !b_legacy)
2562 p_tlv->offset = DB_ADDR_VF(cid, DQ_DEMS_LEGACY);
2564 ecore_iov_send_response(p_hwfn, p_ptt, p_vf, length, status);
2567 static void ecore_iov_vf_mbx_start_txq(struct ecore_hwfn *p_hwfn,
2568 struct ecore_ptt *p_ptt,
2569 struct ecore_vf_info *vf)
2571 struct ecore_queue_start_common_params params;
2572 struct ecore_queue_cid_vf_params vf_params;
2573 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
2574 u8 status = PFVF_STATUS_NO_RESOURCE;
2575 struct ecore_vf_queue *p_queue;
2576 struct vfpf_start_txq_tlv *req;
2577 struct ecore_queue_cid *p_cid;
2578 struct ecore_sb_info sb_dummy;
2579 u8 qid_usage_idx, vf_legacy;
2581 enum _ecore_status_t rc;
2584 OSAL_MEMSET(¶ms, 0, sizeof(params));
2585 req = &mbx->req_virt->start_txq;
2587 if (!ecore_iov_validate_txq(p_hwfn, vf, req->tx_qid,
2588 ECORE_IOV_VALIDATE_Q_NA) ||
2589 !ecore_iov_validate_sb(p_hwfn, vf, req->hw_sb))
2592 qid_usage_idx = ecore_iov_vf_mbx_qid(p_hwfn, vf, true);
2593 if (qid_usage_idx == ECORE_IOV_QID_INVALID)
2596 p_queue = &vf->vf_queues[req->tx_qid];
2597 if (p_queue->cids[qid_usage_idx].p_cid)
2600 vf_legacy = ecore_vf_calculate_legacy(vf);
2602 /* Acquire a new queue-cid */
2603 params.queue_id = p_queue->fw_tx_qid;
2604 params.vport_id = vf->vport_id;
2605 params.stats_id = vf->abs_vf_id + 0x10;
2607 /* Since IGU index is passed via sb_info, construct a dummy one */
2608 OSAL_MEM_ZERO(&sb_dummy, sizeof(sb_dummy));
2609 sb_dummy.igu_sb_id = req->hw_sb;
2610 params.p_sb = &sb_dummy;
2611 params.sb_idx = req->sb_index;
2613 OSAL_MEM_ZERO(&vf_params, sizeof(vf_params));
2614 vf_params.vfid = vf->relative_vf_id;
2615 vf_params.vf_qid = (u8)req->tx_qid;
2616 vf_params.vf_legacy = vf_legacy;
2617 vf_params.qid_usage_idx = qid_usage_idx;
2619 p_cid = ecore_eth_queue_to_cid(p_hwfn, vf->opaque_fid,
2620 ¶ms, false, &vf_params);
2621 if (p_cid == OSAL_NULL)
2624 pq = ecore_get_cm_pq_idx_vf(p_hwfn,
2625 vf->relative_vf_id);
2626 rc = ecore_eth_txq_start_ramrod(p_hwfn, p_cid,
2627 req->pbl_addr, req->pbl_size, pq);
2628 if (rc != ECORE_SUCCESS) {
2629 status = PFVF_STATUS_FAILURE;
2630 ecore_eth_queue_cid_release(p_hwfn, p_cid);
2632 status = PFVF_STATUS_SUCCESS;
2633 p_queue->cids[qid_usage_idx].p_cid = p_cid;
2634 p_queue->cids[qid_usage_idx].b_is_tx = true;
2639 ecore_iov_vf_mbx_start_txq_resp(p_hwfn, p_ptt, vf,
2643 static enum _ecore_status_t ecore_iov_vf_stop_rxqs(struct ecore_hwfn *p_hwfn,
2644 struct ecore_vf_info *vf,
2647 bool cqe_completion)
2649 struct ecore_vf_queue *p_queue;
2650 enum _ecore_status_t rc = ECORE_SUCCESS;
2652 if (!ecore_iov_validate_rxq(p_hwfn, vf, rxq_id,
2653 ECORE_IOV_VALIDATE_Q_NA)) {
2654 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2655 "VF[%d] Tried Closing Rx 0x%04x.%02x which is inactive\n",
2656 vf->relative_vf_id, rxq_id, qid_usage_idx);
2660 p_queue = &vf->vf_queues[rxq_id];
2662 /* We've validated the index and the existence of the active RXQ -
2663 * now we need to make sure that it's using the correct qid.
2665 if (!p_queue->cids[qid_usage_idx].p_cid ||
2666 p_queue->cids[qid_usage_idx].b_is_tx) {
2667 struct ecore_queue_cid *p_cid;
2669 p_cid = ecore_iov_get_vf_rx_queue_cid(p_queue);
2670 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2671 "VF[%d] - Tried Closing Rx 0x%04x.%02x, but Rx is at %04x.%02x\n",
2672 vf->relative_vf_id, rxq_id, qid_usage_idx,
2673 rxq_id, p_cid->qid_usage_idx);
2677 /* Now that we know we have a valid Rx-queue - close it */
2678 rc = ecore_eth_rx_queue_stop(p_hwfn,
2679 p_queue->cids[qid_usage_idx].p_cid,
2680 false, cqe_completion);
2681 if (rc != ECORE_SUCCESS)
2684 p_queue->cids[qid_usage_idx].p_cid = OSAL_NULL;
2685 vf->num_active_rxqs--;
2687 return ECORE_SUCCESS;
2690 static enum _ecore_status_t ecore_iov_vf_stop_txqs(struct ecore_hwfn *p_hwfn,
2691 struct ecore_vf_info *vf,
2695 struct ecore_vf_queue *p_queue;
2696 enum _ecore_status_t rc = ECORE_SUCCESS;
2698 if (!ecore_iov_validate_txq(p_hwfn, vf, txq_id,
2699 ECORE_IOV_VALIDATE_Q_NA))
2702 p_queue = &vf->vf_queues[txq_id];
2703 if (!p_queue->cids[qid_usage_idx].p_cid ||
2704 !p_queue->cids[qid_usage_idx].b_is_tx)
2707 rc = ecore_eth_tx_queue_stop(p_hwfn,
2708 p_queue->cids[qid_usage_idx].p_cid);
2709 if (rc != ECORE_SUCCESS)
2712 p_queue->cids[qid_usage_idx].p_cid = OSAL_NULL;
2713 return ECORE_SUCCESS;
2716 static void ecore_iov_vf_mbx_stop_rxqs(struct ecore_hwfn *p_hwfn,
2717 struct ecore_ptt *p_ptt,
2718 struct ecore_vf_info *vf)
2720 u16 length = sizeof(struct pfvf_def_resp_tlv);
2721 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
2722 u8 status = PFVF_STATUS_FAILURE;
2723 struct vfpf_stop_rxqs_tlv *req;
2725 enum _ecore_status_t rc;
2727 /* Starting with CHANNEL_TLV_QID, it's assumed the 'num_rxqs'
2728 * would be one. Since no older ecore passed multiple queues
2729 * using this API, sanitize on the value.
2731 req = &mbx->req_virt->stop_rxqs;
2732 if (req->num_rxqs != 1) {
2733 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2734 "Odd; VF[%d] tried stopping multiple Rx queues\n",
2735 vf->relative_vf_id);
2736 status = PFVF_STATUS_NOT_SUPPORTED;
2740 /* Find which qid-index is associated with the queue */
2741 qid_usage_idx = ecore_iov_vf_mbx_qid(p_hwfn, vf, false);
2742 if (qid_usage_idx == ECORE_IOV_QID_INVALID)
2745 rc = ecore_iov_vf_stop_rxqs(p_hwfn, vf, req->rx_qid,
2746 qid_usage_idx, req->cqe_completion);
2747 if (rc == ECORE_SUCCESS)
2748 status = PFVF_STATUS_SUCCESS;
2750 ecore_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_STOP_RXQS,
2754 static void ecore_iov_vf_mbx_stop_txqs(struct ecore_hwfn *p_hwfn,
2755 struct ecore_ptt *p_ptt,
2756 struct ecore_vf_info *vf)
2758 u16 length = sizeof(struct pfvf_def_resp_tlv);
2759 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
2760 u8 status = PFVF_STATUS_FAILURE;
2761 struct vfpf_stop_txqs_tlv *req;
2763 enum _ecore_status_t rc;
2765 /* Starting with CHANNEL_TLV_QID, it's assumed the 'num_txqs'
2766 * would be one. Since no older ecore passed multiple queues
2767 * using this API, sanitize on the value.
2769 req = &mbx->req_virt->stop_txqs;
2770 if (req->num_txqs != 1) {
2771 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2772 "Odd; VF[%d] tried stopping multiple Tx queues\n",
2773 vf->relative_vf_id);
2774 status = PFVF_STATUS_NOT_SUPPORTED;
2778 /* Find which qid-index is associated with the queue */
2779 qid_usage_idx = ecore_iov_vf_mbx_qid(p_hwfn, vf, true);
2780 if (qid_usage_idx == ECORE_IOV_QID_INVALID)
2783 rc = ecore_iov_vf_stop_txqs(p_hwfn, vf, req->tx_qid,
2785 if (rc == ECORE_SUCCESS)
2786 status = PFVF_STATUS_SUCCESS;
2789 ecore_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_STOP_TXQS,
2793 static void ecore_iov_vf_mbx_update_rxqs(struct ecore_hwfn *p_hwfn,
2794 struct ecore_ptt *p_ptt,
2795 struct ecore_vf_info *vf)
2797 struct ecore_queue_cid *handlers[ECORE_MAX_VF_CHAINS_PER_PF];
2798 u16 length = sizeof(struct pfvf_def_resp_tlv);
2799 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
2800 struct vfpf_update_rxq_tlv *req;
2801 u8 status = PFVF_STATUS_FAILURE;
2802 u8 complete_event_flg;
2803 u8 complete_cqe_flg;
2805 enum _ecore_status_t rc;
2808 req = &mbx->req_virt->update_rxq;
2809 complete_cqe_flg = !!(req->flags & VFPF_RXQ_UPD_COMPLETE_CQE_FLAG);
2810 complete_event_flg = !!(req->flags & VFPF_RXQ_UPD_COMPLETE_EVENT_FLAG);
2812 qid_usage_idx = ecore_iov_vf_mbx_qid(p_hwfn, vf, false);
2813 if (qid_usage_idx == ECORE_IOV_QID_INVALID)
2816 /* Starting with the addition of CHANNEL_TLV_QID, this API started
2817 * expecting a single queue at a time. Validate this.
2819 if ((vf->acquire.vfdev_info.capabilities &
2820 VFPF_ACQUIRE_CAP_QUEUE_QIDS) &&
2821 req->num_rxqs != 1) {
2822 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2823 "VF[%d] supports QIDs but sends multiple queues\n",
2824 vf->relative_vf_id);
2828 /* Validate inputs - for the legacy case this is still true since
2829 * qid_usage_idx for each Rx queue would be LEGACY_QID_RX.
2831 for (i = req->rx_qid; i < req->rx_qid + req->num_rxqs; i++) {
2832 if (!ecore_iov_validate_rxq(p_hwfn, vf, i,
2833 ECORE_IOV_VALIDATE_Q_NA) ||
2834 !vf->vf_queues[i].cids[qid_usage_idx].p_cid ||
2835 vf->vf_queues[i].cids[qid_usage_idx].b_is_tx) {
2836 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2837 "VF[%d]: Incorrect Rxqs [%04x, %02x]\n",
2838 vf->relative_vf_id, req->rx_qid,
2844 for (i = 0; i < req->num_rxqs; i++) {
2845 u16 qid = req->rx_qid + i;
2847 handlers[i] = vf->vf_queues[qid].cids[qid_usage_idx].p_cid;
2850 rc = ecore_sp_eth_rx_queues_update(p_hwfn, (void **)&handlers,
2854 ECORE_SPQ_MODE_EBLOCK,
2856 if (rc != ECORE_SUCCESS)
2859 status = PFVF_STATUS_SUCCESS;
2861 ecore_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_UPDATE_RXQ,
2865 static enum _ecore_status_t
2866 ecore_iov_vf_pf_update_mtu(struct ecore_hwfn *p_hwfn,
2867 struct ecore_ptt *p_ptt,
2868 struct ecore_vf_info *p_vf)
2870 struct ecore_iov_vf_mbx *mbx = &p_vf->vf_mbx;
2871 struct ecore_sp_vport_update_params params;
2872 enum _ecore_status_t rc = ECORE_SUCCESS;
2873 struct vfpf_update_mtu_tlv *p_req;
2874 u8 status = PFVF_STATUS_SUCCESS;
2876 /* Valiate PF can send such a request */
2877 if (!p_vf->vport_instance) {
2878 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2879 "No VPORT instance available for VF[%d], failing MTU update\n",
2881 status = PFVF_STATUS_FAILURE;
2885 p_req = &mbx->req_virt->update_mtu;
2887 OSAL_MEMSET(¶ms, 0, sizeof(params));
2888 params.opaque_fid = p_vf->opaque_fid;
2889 params.vport_id = p_vf->vport_id;
2890 params.mtu = p_req->mtu;
2891 rc = ecore_sp_vport_update(p_hwfn, ¶ms, ECORE_SPQ_MODE_EBLOCK,
2895 status = PFVF_STATUS_FAILURE;
2897 ecore_iov_prepare_resp(p_hwfn, p_ptt, p_vf,
2898 CHANNEL_TLV_UPDATE_MTU,
2899 sizeof(struct pfvf_def_resp_tlv),
2904 void *ecore_iov_search_list_tlvs(struct ecore_hwfn *p_hwfn,
2905 void *p_tlvs_list, u16 req_type)
2907 struct channel_tlv *p_tlv = (struct channel_tlv *)p_tlvs_list;
2911 if (!p_tlv->length) {
2912 DP_NOTICE(p_hwfn, true, "Zero length TLV found\n");
2916 if (p_tlv->type == req_type) {
2917 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2918 "Extended tlv type %s, length %d found\n",
2919 ecore_channel_tlvs_string[p_tlv->type],
2924 len += p_tlv->length;
2925 p_tlv = (struct channel_tlv *)((u8 *)p_tlv + p_tlv->length);
2927 if ((len + p_tlv->length) > TLV_BUFFER_SIZE) {
2928 DP_NOTICE(p_hwfn, true,
2929 "TLVs has overrun the buffer size\n");
2932 } while (p_tlv->type != CHANNEL_TLV_LIST_END);
2938 ecore_iov_vp_update_act_param(struct ecore_hwfn *p_hwfn,
2939 struct ecore_sp_vport_update_params *p_data,
2940 struct ecore_iov_vf_mbx *p_mbx, u16 *tlvs_mask)
2942 struct vfpf_vport_update_activate_tlv *p_act_tlv;
2943 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_ACTIVATE;
2945 p_act_tlv = (struct vfpf_vport_update_activate_tlv *)
2946 ecore_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
2950 p_data->update_vport_active_rx_flg = p_act_tlv->update_rx;
2951 p_data->vport_active_rx_flg = p_act_tlv->active_rx;
2952 p_data->update_vport_active_tx_flg = p_act_tlv->update_tx;
2953 p_data->vport_active_tx_flg = p_act_tlv->active_tx;
2954 *tlvs_mask |= 1 << ECORE_IOV_VP_UPDATE_ACTIVATE;
2958 ecore_iov_vp_update_vlan_param(struct ecore_hwfn *p_hwfn,
2959 struct ecore_sp_vport_update_params *p_data,
2960 struct ecore_vf_info *p_vf,
2961 struct ecore_iov_vf_mbx *p_mbx, u16 *tlvs_mask)
2963 struct vfpf_vport_update_vlan_strip_tlv *p_vlan_tlv;
2964 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_VLAN_STRIP;
2966 p_vlan_tlv = (struct vfpf_vport_update_vlan_strip_tlv *)
2967 ecore_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
2971 p_vf->shadow_config.inner_vlan_removal = p_vlan_tlv->remove_vlan;
2973 /* Ignore the VF request if we're forcing a vlan */
2974 if (!(p_vf->configured_features & (1 << VLAN_ADDR_FORCED))) {
2975 p_data->update_inner_vlan_removal_flg = 1;
2976 p_data->inner_vlan_removal_flg = p_vlan_tlv->remove_vlan;
2979 *tlvs_mask |= 1 << ECORE_IOV_VP_UPDATE_VLAN_STRIP;
2983 ecore_iov_vp_update_tx_switch(struct ecore_hwfn *p_hwfn,
2984 struct ecore_sp_vport_update_params *p_data,
2985 struct ecore_iov_vf_mbx *p_mbx, u16 *tlvs_mask)
2987 struct vfpf_vport_update_tx_switch_tlv *p_tx_switch_tlv;
2988 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_TX_SWITCH;
2990 p_tx_switch_tlv = (struct vfpf_vport_update_tx_switch_tlv *)
2991 ecore_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
2992 if (!p_tx_switch_tlv)
2996 if (CHIP_REV_IS_FPGA(p_hwfn->p_dev)) {
2997 DP_NOTICE(p_hwfn, false,
2998 "FPGA: Ignore tx-switching configuration originating"
3004 p_data->update_tx_switching_flg = 1;
3005 p_data->tx_switching_flg = p_tx_switch_tlv->tx_switching;
3006 *tlvs_mask |= 1 << ECORE_IOV_VP_UPDATE_TX_SWITCH;
3010 ecore_iov_vp_update_mcast_bin_param(struct ecore_hwfn *p_hwfn,
3011 struct ecore_sp_vport_update_params *p_data,
3012 struct ecore_iov_vf_mbx *p_mbx,
3015 struct vfpf_vport_update_mcast_bin_tlv *p_mcast_tlv;
3016 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_MCAST;
3018 p_mcast_tlv = (struct vfpf_vport_update_mcast_bin_tlv *)
3019 ecore_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
3023 p_data->update_approx_mcast_flg = 1;
3024 OSAL_MEMCPY(p_data->bins, p_mcast_tlv->bins,
3025 sizeof(u32) * ETH_MULTICAST_MAC_BINS_IN_REGS);
3026 *tlvs_mask |= 1 << ECORE_IOV_VP_UPDATE_MCAST;
3030 ecore_iov_vp_update_accept_flag(struct ecore_hwfn *p_hwfn,
3031 struct ecore_sp_vport_update_params *p_data,
3032 struct ecore_iov_vf_mbx *p_mbx, u16 *tlvs_mask)
3034 struct ecore_filter_accept_flags *p_flags = &p_data->accept_flags;
3035 struct vfpf_vport_update_accept_param_tlv *p_accept_tlv;
3036 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_ACCEPT_PARAM;
3038 p_accept_tlv = (struct vfpf_vport_update_accept_param_tlv *)
3039 ecore_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
3043 p_flags->update_rx_mode_config = p_accept_tlv->update_rx_mode;
3044 p_flags->rx_accept_filter = p_accept_tlv->rx_accept_filter;
3045 p_flags->update_tx_mode_config = p_accept_tlv->update_tx_mode;
3046 p_flags->tx_accept_filter = p_accept_tlv->tx_accept_filter;
3047 *tlvs_mask |= 1 << ECORE_IOV_VP_UPDATE_ACCEPT_PARAM;
3051 ecore_iov_vp_update_accept_any_vlan(struct ecore_hwfn *p_hwfn,
3052 struct ecore_sp_vport_update_params *p_data,
3053 struct ecore_iov_vf_mbx *p_mbx,
3056 struct vfpf_vport_update_accept_any_vlan_tlv *p_accept_any_vlan;
3057 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_ACCEPT_ANY_VLAN;
3059 p_accept_any_vlan = (struct vfpf_vport_update_accept_any_vlan_tlv *)
3060 ecore_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
3061 if (!p_accept_any_vlan)
3064 p_data->accept_any_vlan = p_accept_any_vlan->accept_any_vlan;
3065 p_data->update_accept_any_vlan_flg =
3066 p_accept_any_vlan->update_accept_any_vlan_flg;
3067 *tlvs_mask |= 1 << ECORE_IOV_VP_UPDATE_ACCEPT_ANY_VLAN;
3071 ecore_iov_vp_update_rss_param(struct ecore_hwfn *p_hwfn,
3072 struct ecore_vf_info *vf,
3073 struct ecore_sp_vport_update_params *p_data,
3074 struct ecore_rss_params *p_rss,
3075 struct ecore_iov_vf_mbx *p_mbx,
3076 u16 *tlvs_mask, u16 *tlvs_accepted)
3078 struct vfpf_vport_update_rss_tlv *p_rss_tlv;
3079 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_RSS;
3080 bool b_reject = false;
3084 p_rss_tlv = (struct vfpf_vport_update_rss_tlv *)
3085 ecore_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
3087 p_data->rss_params = OSAL_NULL;
3091 OSAL_MEMSET(p_rss, 0, sizeof(struct ecore_rss_params));
3093 p_rss->update_rss_config =
3094 !!(p_rss_tlv->update_rss_flags &
3095 VFPF_UPDATE_RSS_CONFIG_FLAG);
3096 p_rss->update_rss_capabilities =
3097 !!(p_rss_tlv->update_rss_flags &
3098 VFPF_UPDATE_RSS_CAPS_FLAG);
3099 p_rss->update_rss_ind_table =
3100 !!(p_rss_tlv->update_rss_flags &
3101 VFPF_UPDATE_RSS_IND_TABLE_FLAG);
3102 p_rss->update_rss_key =
3103 !!(p_rss_tlv->update_rss_flags &
3104 VFPF_UPDATE_RSS_KEY_FLAG);
3106 p_rss->rss_enable = p_rss_tlv->rss_enable;
3107 p_rss->rss_eng_id = vf->rss_eng_id;
3108 p_rss->rss_caps = p_rss_tlv->rss_caps;
3109 p_rss->rss_table_size_log = p_rss_tlv->rss_table_size_log;
3110 OSAL_MEMCPY(p_rss->rss_key, p_rss_tlv->rss_key,
3111 sizeof(p_rss->rss_key));
3113 table_size = OSAL_MIN_T(u16, OSAL_ARRAY_SIZE(p_rss->rss_ind_table),
3114 (1 << p_rss_tlv->rss_table_size_log));
3116 for (i = 0; i < table_size; i++) {
3117 struct ecore_queue_cid *p_cid;
3119 q_idx = p_rss_tlv->rss_ind_table[i];
3120 if (!ecore_iov_validate_rxq(p_hwfn, vf, q_idx,
3121 ECORE_IOV_VALIDATE_Q_ENABLE)) {
3122 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3123 "VF[%d]: Omitting RSS due to wrong queue %04x\n",
3124 vf->relative_vf_id, q_idx);
3129 p_cid = ecore_iov_get_vf_rx_queue_cid(&vf->vf_queues[q_idx]);
3130 p_rss->rss_ind_table[i] = p_cid;
3133 p_data->rss_params = p_rss;
3135 *tlvs_mask |= 1 << ECORE_IOV_VP_UPDATE_RSS;
3137 *tlvs_accepted |= 1 << ECORE_IOV_VP_UPDATE_RSS;
3141 ecore_iov_vp_update_sge_tpa_param(struct ecore_hwfn *p_hwfn,
3142 struct ecore_sp_vport_update_params *p_data,
3143 struct ecore_sge_tpa_params *p_sge_tpa,
3144 struct ecore_iov_vf_mbx *p_mbx,
3147 struct vfpf_vport_update_sge_tpa_tlv *p_sge_tpa_tlv;
3148 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_SGE_TPA;
3150 p_sge_tpa_tlv = (struct vfpf_vport_update_sge_tpa_tlv *)
3151 ecore_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
3153 if (!p_sge_tpa_tlv) {
3154 p_data->sge_tpa_params = OSAL_NULL;
3158 OSAL_MEMSET(p_sge_tpa, 0, sizeof(struct ecore_sge_tpa_params));
3160 p_sge_tpa->update_tpa_en_flg =
3161 !!(p_sge_tpa_tlv->update_sge_tpa_flags & VFPF_UPDATE_TPA_EN_FLAG);
3162 p_sge_tpa->update_tpa_param_flg =
3163 !!(p_sge_tpa_tlv->update_sge_tpa_flags &
3164 VFPF_UPDATE_TPA_PARAM_FLAG);
3166 p_sge_tpa->tpa_ipv4_en_flg =
3167 !!(p_sge_tpa_tlv->sge_tpa_flags & VFPF_TPA_IPV4_EN_FLAG);
3168 p_sge_tpa->tpa_ipv6_en_flg =
3169 !!(p_sge_tpa_tlv->sge_tpa_flags & VFPF_TPA_IPV6_EN_FLAG);
3170 p_sge_tpa->tpa_pkt_split_flg =
3171 !!(p_sge_tpa_tlv->sge_tpa_flags & VFPF_TPA_PKT_SPLIT_FLAG);
3172 p_sge_tpa->tpa_hdr_data_split_flg =
3173 !!(p_sge_tpa_tlv->sge_tpa_flags & VFPF_TPA_HDR_DATA_SPLIT_FLAG);
3174 p_sge_tpa->tpa_gro_consistent_flg =
3175 !!(p_sge_tpa_tlv->sge_tpa_flags & VFPF_TPA_GRO_CONSIST_FLAG);
3177 p_sge_tpa->tpa_max_aggs_num = p_sge_tpa_tlv->tpa_max_aggs_num;
3178 p_sge_tpa->tpa_max_size = p_sge_tpa_tlv->tpa_max_size;
3179 p_sge_tpa->tpa_min_size_to_start = p_sge_tpa_tlv->tpa_min_size_to_start;
3180 p_sge_tpa->tpa_min_size_to_cont = p_sge_tpa_tlv->tpa_min_size_to_cont;
3181 p_sge_tpa->max_buffers_per_cqe = p_sge_tpa_tlv->max_buffers_per_cqe;
3183 p_data->sge_tpa_params = p_sge_tpa;
3185 *tlvs_mask |= 1 << ECORE_IOV_VP_UPDATE_SGE_TPA;
3188 static void ecore_iov_vf_mbx_vport_update(struct ecore_hwfn *p_hwfn,
3189 struct ecore_ptt *p_ptt,
3190 struct ecore_vf_info *vf)
3192 struct ecore_rss_params *p_rss_params = OSAL_NULL;
3193 struct ecore_sp_vport_update_params params;
3194 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
3195 struct ecore_sge_tpa_params sge_tpa_params;
3196 u16 tlvs_mask = 0, tlvs_accepted = 0;
3197 u8 status = PFVF_STATUS_SUCCESS;
3199 enum _ecore_status_t rc;
3201 /* Valiate PF can send such a request */
3202 if (!vf->vport_instance) {
3203 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3204 "No VPORT instance available for VF[%d],"
3205 " failing vport update\n",
3207 status = PFVF_STATUS_FAILURE;
3211 p_rss_params = OSAL_VZALLOC(p_hwfn->p_dev, sizeof(*p_rss_params));
3212 if (p_rss_params == OSAL_NULL) {
3213 status = PFVF_STATUS_FAILURE;
3217 OSAL_MEMSET(¶ms, 0, sizeof(params));
3218 params.opaque_fid = vf->opaque_fid;
3219 params.vport_id = vf->vport_id;
3220 params.rss_params = OSAL_NULL;
3222 /* Search for extended tlvs list and update values
3223 * from VF in struct ecore_sp_vport_update_params.
3225 ecore_iov_vp_update_act_param(p_hwfn, ¶ms, mbx, &tlvs_mask);
3226 ecore_iov_vp_update_vlan_param(p_hwfn, ¶ms, vf, mbx, &tlvs_mask);
3227 ecore_iov_vp_update_tx_switch(p_hwfn, ¶ms, mbx, &tlvs_mask);
3228 ecore_iov_vp_update_mcast_bin_param(p_hwfn, ¶ms, mbx, &tlvs_mask);
3229 ecore_iov_vp_update_accept_flag(p_hwfn, ¶ms, mbx, &tlvs_mask);
3230 ecore_iov_vp_update_accept_any_vlan(p_hwfn, ¶ms, mbx, &tlvs_mask);
3231 ecore_iov_vp_update_sge_tpa_param(p_hwfn, ¶ms,
3232 &sge_tpa_params, mbx, &tlvs_mask);
3234 tlvs_accepted = tlvs_mask;
3236 /* Some of the extended TLVs need to be validated first; In that case,
3237 * they can update the mask without updating the accepted [so that
3238 * PF could communicate to VF it has rejected request].
3240 ecore_iov_vp_update_rss_param(p_hwfn, vf, ¶ms, p_rss_params,
3241 mbx, &tlvs_mask, &tlvs_accepted);
3243 /* Just log a message if there is no single extended tlv in buffer.
3244 * When all features of vport update ramrod would be requested by VF
3245 * as extended TLVs in buffer then an error can be returned in response
3246 * if there is no extended TLV present in buffer.
3248 if (OSAL_IOV_VF_VPORT_UPDATE(p_hwfn, vf->relative_vf_id,
3249 ¶ms, &tlvs_accepted) !=
3252 status = PFVF_STATUS_NOT_SUPPORTED;
3256 if (!tlvs_accepted) {
3258 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3259 "Upper-layer prevents said VF"
3260 " configuration\n");
3262 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3263 "No feature tlvs found for vport update\n");
3264 status = PFVF_STATUS_NOT_SUPPORTED;
3268 rc = ecore_sp_vport_update(p_hwfn, ¶ms, ECORE_SPQ_MODE_EBLOCK,
3272 status = PFVF_STATUS_FAILURE;
3275 OSAL_VFREE(p_hwfn->p_dev, p_rss_params);
3276 length = ecore_iov_prep_vp_update_resp_tlvs(p_hwfn, vf, mbx, status,
3277 tlvs_mask, tlvs_accepted);
3278 ecore_iov_send_response(p_hwfn, p_ptt, vf, length, status);
3281 static enum _ecore_status_t
3282 ecore_iov_vf_update_vlan_shadow(struct ecore_hwfn *p_hwfn,
3283 struct ecore_vf_info *p_vf,
3284 struct ecore_filter_ucast *p_params)
3288 /* First remove entries and then add new ones */
3289 if (p_params->opcode == ECORE_FILTER_REMOVE) {
3290 for (i = 0; i < ECORE_ETH_VF_NUM_VLAN_FILTERS + 1; i++)
3291 if (p_vf->shadow_config.vlans[i].used &&
3292 p_vf->shadow_config.vlans[i].vid ==
3294 p_vf->shadow_config.vlans[i].used = false;
3297 if (i == ECORE_ETH_VF_NUM_VLAN_FILTERS + 1) {
3298 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3299 "VF [%d] - Tries to remove a non-existing"
3301 p_vf->relative_vf_id);
3304 } else if (p_params->opcode == ECORE_FILTER_REPLACE ||
3305 p_params->opcode == ECORE_FILTER_FLUSH) {
3306 for (i = 0; i < ECORE_ETH_VF_NUM_VLAN_FILTERS + 1; i++)
3307 p_vf->shadow_config.vlans[i].used = false;
3310 /* In forced mode, we're willing to remove entries - but we don't add
3313 if (p_vf->bulletin.p_virt->valid_bitmap & (1 << VLAN_ADDR_FORCED))
3314 return ECORE_SUCCESS;
3316 if (p_params->opcode == ECORE_FILTER_ADD ||
3317 p_params->opcode == ECORE_FILTER_REPLACE) {
3318 for (i = 0; i < ECORE_ETH_VF_NUM_VLAN_FILTERS + 1; i++) {
3319 if (p_vf->shadow_config.vlans[i].used)
3322 p_vf->shadow_config.vlans[i].used = true;
3323 p_vf->shadow_config.vlans[i].vid = p_params->vlan;
3327 if (i == ECORE_ETH_VF_NUM_VLAN_FILTERS + 1) {
3328 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3329 "VF [%d] - Tries to configure more than %d"
3331 p_vf->relative_vf_id,
3332 ECORE_ETH_VF_NUM_VLAN_FILTERS + 1);
3337 return ECORE_SUCCESS;
3340 static enum _ecore_status_t
3341 ecore_iov_vf_update_mac_shadow(struct ecore_hwfn *p_hwfn,
3342 struct ecore_vf_info *p_vf,
3343 struct ecore_filter_ucast *p_params)
3345 char empty_mac[ETH_ALEN];
3348 OSAL_MEM_ZERO(empty_mac, ETH_ALEN);
3350 /* If we're in forced-mode, we don't allow any change */
3351 /* TODO - this would change if we were ever to implement logic for
3352 * removing a forced MAC altogether [in which case, like for vlans,
3353 * we should be able to re-trace previous configuration.
3355 if (p_vf->bulletin.p_virt->valid_bitmap & (1 << MAC_ADDR_FORCED))
3356 return ECORE_SUCCESS;
3358 /* Since we don't have the implementation of the logic for removing
3359 * a forced MAC and restoring shadow MAC, let's not worry about
3360 * processing shadow copies of MAC as long as VF trust mode is ON,
3361 * to keep things simple.
3363 if (p_hwfn->pf_params.eth_pf_params.allow_vf_mac_change ||
3364 p_vf->p_vf_info.is_trusted_configured)
3365 return ECORE_SUCCESS;
3367 /* First remove entries and then add new ones */
3368 if (p_params->opcode == ECORE_FILTER_REMOVE) {
3369 for (i = 0; i < ECORE_ETH_VF_NUM_MAC_FILTERS; i++) {
3370 if (!OSAL_MEMCMP(p_vf->shadow_config.macs[i],
3371 p_params->mac, ETH_ALEN)) {
3372 OSAL_MEM_ZERO(p_vf->shadow_config.macs[i],
3378 if (i == ECORE_ETH_VF_NUM_MAC_FILTERS) {
3379 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3380 "MAC isn't configured\n");
3383 } else if (p_params->opcode == ECORE_FILTER_REPLACE ||
3384 p_params->opcode == ECORE_FILTER_FLUSH) {
3385 for (i = 0; i < ECORE_ETH_VF_NUM_MAC_FILTERS; i++)
3386 OSAL_MEM_ZERO(p_vf->shadow_config.macs[i], ETH_ALEN);
3389 /* List the new MAC address */
3390 if (p_params->opcode != ECORE_FILTER_ADD &&
3391 p_params->opcode != ECORE_FILTER_REPLACE)
3392 return ECORE_SUCCESS;
3394 for (i = 0; i < ECORE_ETH_VF_NUM_MAC_FILTERS; i++) {
3395 if (!OSAL_MEMCMP(p_vf->shadow_config.macs[i],
3396 empty_mac, ETH_ALEN)) {
3397 OSAL_MEMCPY(p_vf->shadow_config.macs[i],
3398 p_params->mac, ETH_ALEN);
3399 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3400 "Added MAC at %d entry in shadow\n", i);
3405 if (i == ECORE_ETH_VF_NUM_MAC_FILTERS) {
3406 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3407 "No available place for MAC\n");
3411 return ECORE_SUCCESS;
3414 static enum _ecore_status_t
3415 ecore_iov_vf_update_unicast_shadow(struct ecore_hwfn *p_hwfn,
3416 struct ecore_vf_info *p_vf,
3417 struct ecore_filter_ucast *p_params)
3419 enum _ecore_status_t rc = ECORE_SUCCESS;
3421 if (p_params->type == ECORE_FILTER_MAC) {
3422 rc = ecore_iov_vf_update_mac_shadow(p_hwfn, p_vf, p_params);
3423 if (rc != ECORE_SUCCESS)
3427 if (p_params->type == ECORE_FILTER_VLAN)
3428 rc = ecore_iov_vf_update_vlan_shadow(p_hwfn, p_vf, p_params);
3433 static void ecore_iov_vf_mbx_ucast_filter(struct ecore_hwfn *p_hwfn,
3434 struct ecore_ptt *p_ptt,
3435 struct ecore_vf_info *vf)
3437 struct ecore_bulletin_content *p_bulletin = vf->bulletin.p_virt;
3438 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
3439 struct vfpf_ucast_filter_tlv *req;
3440 u8 status = PFVF_STATUS_SUCCESS;
3441 struct ecore_filter_ucast params;
3442 enum _ecore_status_t rc;
3444 /* Prepare the unicast filter params */
3445 OSAL_MEMSET(¶ms, 0, sizeof(struct ecore_filter_ucast));
3446 req = &mbx->req_virt->ucast_filter;
3447 params.opcode = (enum ecore_filter_opcode)req->opcode;
3448 params.type = (enum ecore_filter_ucast_type)req->type;
3450 /* @@@TBD - We might need logic on HV side in determining this */
3451 params.is_rx_filter = 1;
3452 params.is_tx_filter = 1;
3453 params.vport_to_remove_from = vf->vport_id;
3454 params.vport_to_add_to = vf->vport_id;
3455 OSAL_MEMCPY(params.mac, req->mac, ETH_ALEN);
3456 params.vlan = req->vlan;
3458 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3459 "VF[%d]: opcode 0x%02x type 0x%02x [%s %s] [vport 0x%02x]"
3460 " MAC %02x:%02x:%02x:%02x:%02x:%02x, vlan 0x%04x\n",
3461 vf->abs_vf_id, params.opcode, params.type,
3462 params.is_rx_filter ? "RX" : "",
3463 params.is_tx_filter ? "TX" : "",
3464 params.vport_to_add_to,
3465 params.mac[0], params.mac[1], params.mac[2],
3466 params.mac[3], params.mac[4], params.mac[5], params.vlan);
3468 if (!vf->vport_instance) {
3469 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3470 "No VPORT instance available for VF[%d],"
3471 " failing ucast MAC configuration\n",
3473 status = PFVF_STATUS_FAILURE;
3477 /* Update shadow copy of the VF configuration. In case shadow indicates
3478 * the action should be blocked return success to VF to imitate the
3479 * firmware behaviour in such case.
3481 if (ecore_iov_vf_update_unicast_shadow(p_hwfn, vf, ¶ms) !=
3485 /* Determine if the unicast filtering is acceptible by PF */
3486 if ((p_bulletin->valid_bitmap & (1 << VLAN_ADDR_FORCED)) &&
3487 (params.type == ECORE_FILTER_VLAN ||
3488 params.type == ECORE_FILTER_MAC_VLAN)) {
3489 /* Once VLAN is forced or PVID is set, do not allow
3490 * to add/replace any further VLANs.
3492 if (params.opcode == ECORE_FILTER_ADD ||
3493 params.opcode == ECORE_FILTER_REPLACE)
3494 status = PFVF_STATUS_FORCED;
3498 if ((p_bulletin->valid_bitmap & (1 << MAC_ADDR_FORCED)) &&
3499 (params.type == ECORE_FILTER_MAC ||
3500 params.type == ECORE_FILTER_MAC_VLAN)) {
3501 if (OSAL_MEMCMP(p_bulletin->mac, params.mac, ETH_ALEN) ||
3502 (params.opcode != ECORE_FILTER_ADD &&
3503 params.opcode != ECORE_FILTER_REPLACE))
3504 status = PFVF_STATUS_FORCED;
3508 rc = OSAL_IOV_CHK_UCAST(p_hwfn, vf->relative_vf_id, ¶ms);
3509 if (rc == ECORE_EXISTS) {
3511 } else if (rc == ECORE_INVAL) {
3512 status = PFVF_STATUS_FAILURE;
3516 rc = ecore_sp_eth_filter_ucast(p_hwfn, vf->opaque_fid, ¶ms,
3517 ECORE_SPQ_MODE_CB, OSAL_NULL);
3519 status = PFVF_STATUS_FAILURE;
3522 ecore_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_UCAST_FILTER,
3523 sizeof(struct pfvf_def_resp_tlv), status);
3526 static void ecore_iov_vf_mbx_int_cleanup(struct ecore_hwfn *p_hwfn,
3527 struct ecore_ptt *p_ptt,
3528 struct ecore_vf_info *vf)
3533 for (i = 0; i < vf->num_sbs; i++)
3534 ecore_int_igu_init_pure_rt_single(p_hwfn, p_ptt,
3536 vf->opaque_fid, false);
3538 ecore_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_INT_CLEANUP,
3539 sizeof(struct pfvf_def_resp_tlv),
3540 PFVF_STATUS_SUCCESS);
3543 static void ecore_iov_vf_mbx_close(struct ecore_hwfn *p_hwfn,
3544 struct ecore_ptt *p_ptt,
3545 struct ecore_vf_info *vf)
3547 u16 length = sizeof(struct pfvf_def_resp_tlv);
3548 u8 status = PFVF_STATUS_SUCCESS;
3550 /* Disable Interrupts for VF */
3551 ecore_iov_vf_igu_set_int(p_hwfn, p_ptt, vf, 0);
3553 /* Reset Permission table */
3554 ecore_iov_config_perm_table(p_hwfn, p_ptt, vf, 0);
3556 ecore_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_CLOSE,
3560 static void ecore_iov_vf_mbx_release(struct ecore_hwfn *p_hwfn,
3561 struct ecore_ptt *p_ptt,
3562 struct ecore_vf_info *p_vf)
3564 u16 length = sizeof(struct pfvf_def_resp_tlv);
3565 u8 status = PFVF_STATUS_SUCCESS;
3566 enum _ecore_status_t rc = ECORE_SUCCESS;
3568 ecore_iov_vf_cleanup(p_hwfn, p_vf);
3570 if (p_vf->state != VF_STOPPED && p_vf->state != VF_FREE) {
3571 /* Stopping the VF */
3572 rc = ecore_sp_vf_stop(p_hwfn, p_vf->concrete_fid,
3575 if (rc != ECORE_SUCCESS) {
3576 DP_ERR(p_hwfn, "ecore_sp_vf_stop returned error %d\n",
3578 status = PFVF_STATUS_FAILURE;
3581 p_vf->state = VF_STOPPED;
3584 ecore_iov_prepare_resp(p_hwfn, p_ptt, p_vf, CHANNEL_TLV_RELEASE,
3588 static void ecore_iov_vf_pf_get_coalesce(struct ecore_hwfn *p_hwfn,
3589 struct ecore_ptt *p_ptt,
3590 struct ecore_vf_info *p_vf)
3592 struct ecore_iov_vf_mbx *mbx = &p_vf->vf_mbx;
3593 struct pfvf_read_coal_resp_tlv *p_resp;
3594 struct vfpf_read_coal_req_tlv *req;
3595 u8 status = PFVF_STATUS_FAILURE;
3596 struct ecore_vf_queue *p_queue;
3597 struct ecore_queue_cid *p_cid;
3598 enum _ecore_status_t rc = ECORE_SUCCESS;
3599 u16 coal = 0, qid, i;
3602 mbx->offset = (u8 *)mbx->reply_virt;
3603 req = &mbx->req_virt->read_coal_req;
3606 b_is_rx = req->is_rx ? true : false;
3609 if (!ecore_iov_validate_rxq(p_hwfn, p_vf, qid,
3610 ECORE_IOV_VALIDATE_Q_ENABLE)) {
3611 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3612 "VF[%d]: Invalid Rx queue_id = %d\n",
3613 p_vf->abs_vf_id, qid);
3617 p_cid = ecore_iov_get_vf_rx_queue_cid(&p_vf->vf_queues[qid]);
3618 rc = ecore_get_rxq_coalesce(p_hwfn, p_ptt, p_cid, &coal);
3619 if (rc != ECORE_SUCCESS)
3622 if (!ecore_iov_validate_txq(p_hwfn, p_vf, qid,
3623 ECORE_IOV_VALIDATE_Q_ENABLE)) {
3624 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3625 "VF[%d]: Invalid Tx queue_id = %d\n",
3626 p_vf->abs_vf_id, qid);
3629 for (i = 0; i < MAX_QUEUES_PER_QZONE; i++) {
3630 p_queue = &p_vf->vf_queues[qid];
3631 if ((p_queue->cids[i].p_cid == OSAL_NULL) ||
3632 (!p_queue->cids[i].b_is_tx))
3635 p_cid = p_queue->cids[i].p_cid;
3637 rc = ecore_get_txq_coalesce(p_hwfn, p_ptt,
3639 if (rc != ECORE_SUCCESS)
3645 status = PFVF_STATUS_SUCCESS;
3648 p_resp = ecore_add_tlv(&mbx->offset, CHANNEL_TLV_COALESCE_READ,
3650 p_resp->coal = coal;
3652 ecore_add_tlv(&mbx->offset, CHANNEL_TLV_LIST_END,
3653 sizeof(struct channel_list_end_tlv));
3655 ecore_iov_send_response(p_hwfn, p_ptt, p_vf, sizeof(*p_resp), status);
3658 static void ecore_iov_vf_pf_set_coalesce(struct ecore_hwfn *p_hwfn,
3659 struct ecore_ptt *p_ptt,
3660 struct ecore_vf_info *vf)
3662 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
3663 enum _ecore_status_t rc = ECORE_SUCCESS;
3664 struct vfpf_update_coalesce *req;
3665 u8 status = PFVF_STATUS_FAILURE;
3666 struct ecore_queue_cid *p_cid;
3667 u16 rx_coal, tx_coal;
3671 req = &mbx->req_virt->update_coalesce;
3673 rx_coal = req->rx_coal;
3674 tx_coal = req->tx_coal;
3677 if (!ecore_iov_validate_rxq(p_hwfn, vf, qid,
3678 ECORE_IOV_VALIDATE_Q_ENABLE) &&
3680 DP_ERR(p_hwfn, "VF[%d]: Invalid Rx queue_id = %d\n",
3681 vf->abs_vf_id, qid);
3685 if (!ecore_iov_validate_txq(p_hwfn, vf, qid,
3686 ECORE_IOV_VALIDATE_Q_ENABLE) &&
3688 DP_ERR(p_hwfn, "VF[%d]: Invalid Tx queue_id = %d\n",
3689 vf->abs_vf_id, qid);
3693 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3694 "VF[%d]: Setting coalesce for VF rx_coal = %d, tx_coal = %d at queue = %d\n",
3695 vf->abs_vf_id, rx_coal, tx_coal, qid);
3698 p_cid = ecore_iov_get_vf_rx_queue_cid(&vf->vf_queues[qid]);
3700 rc = ecore_set_rxq_coalesce(p_hwfn, p_ptt, rx_coal, p_cid);
3701 if (rc != ECORE_SUCCESS) {
3702 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3703 "VF[%d]: Unable to set rx queue = %d coalesce\n",
3704 vf->abs_vf_id, vf->vf_queues[qid].fw_rx_qid);
3707 vf->rx_coal = rx_coal;
3710 /* TODO - in future, it might be possible to pass this in a per-cid
3711 * granularity. For now, do this for all Tx queues.
3714 struct ecore_vf_queue *p_queue = &vf->vf_queues[qid];
3716 for (i = 0; i < MAX_QUEUES_PER_QZONE; i++) {
3717 if (p_queue->cids[i].p_cid == OSAL_NULL)
3720 if (!p_queue->cids[i].b_is_tx)
3723 rc = ecore_set_txq_coalesce(p_hwfn, p_ptt, tx_coal,
3724 p_queue->cids[i].p_cid);
3725 if (rc != ECORE_SUCCESS) {
3726 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3727 "VF[%d]: Unable to set tx queue coalesce\n",
3732 vf->tx_coal = tx_coal;
3735 status = PFVF_STATUS_SUCCESS;
3737 ecore_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_COALESCE_UPDATE,
3738 sizeof(struct pfvf_def_resp_tlv), status);
3741 enum _ecore_status_t
3742 ecore_iov_pf_configure_vf_queue_coalesce(struct ecore_hwfn *p_hwfn,
3743 u16 rx_coal, u16 tx_coal,
3746 struct ecore_queue_cid *p_cid;
3747 struct ecore_vf_info *vf;
3748 struct ecore_ptt *p_ptt;
3751 if (!ecore_iov_is_valid_vfid(p_hwfn, vf_id, true, true)) {
3752 DP_NOTICE(p_hwfn, true,
3753 "VF[%d] - Can not set coalescing: VF is not active\n",
3758 vf = &p_hwfn->pf_iov_info->vfs_array[vf_id];
3759 p_ptt = ecore_ptt_acquire(p_hwfn);
3763 if (!ecore_iov_validate_rxq(p_hwfn, vf, qid,
3764 ECORE_IOV_VALIDATE_Q_ENABLE) &&
3766 DP_ERR(p_hwfn, "VF[%d]: Invalid Rx queue_id = %d\n",
3767 vf->abs_vf_id, qid);
3771 if (!ecore_iov_validate_txq(p_hwfn, vf, qid,
3772 ECORE_IOV_VALIDATE_Q_ENABLE) &&
3774 DP_ERR(p_hwfn, "VF[%d]: Invalid Tx queue_id = %d\n",
3775 vf->abs_vf_id, qid);
3779 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3780 "VF[%d]: Setting coalesce for VF rx_coal = %d, tx_coal = %d at queue = %d\n",
3781 vf->abs_vf_id, rx_coal, tx_coal, qid);
3784 p_cid = ecore_iov_get_vf_rx_queue_cid(&vf->vf_queues[qid]);
3786 rc = ecore_set_rxq_coalesce(p_hwfn, p_ptt, rx_coal, p_cid);
3787 if (rc != ECORE_SUCCESS) {
3788 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3789 "VF[%d]: Unable to set rx queue = %d coalesce\n",
3790 vf->abs_vf_id, vf->vf_queues[qid].fw_rx_qid);
3793 vf->rx_coal = rx_coal;
3796 /* TODO - in future, it might be possible to pass this in a per-cid
3797 * granularity. For now, do this for all Tx queues.
3800 struct ecore_vf_queue *p_queue = &vf->vf_queues[qid];
3802 for (i = 0; i < MAX_QUEUES_PER_QZONE; i++) {
3803 if (p_queue->cids[i].p_cid == OSAL_NULL)
3806 if (!p_queue->cids[i].b_is_tx)
3809 rc = ecore_set_txq_coalesce(p_hwfn, p_ptt, tx_coal,
3810 p_queue->cids[i].p_cid);
3811 if (rc != ECORE_SUCCESS) {
3812 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3813 "VF[%d]: Unable to set tx queue coalesce\n",
3818 vf->tx_coal = tx_coal;
3822 ecore_ptt_release(p_hwfn, p_ptt);
3827 static enum _ecore_status_t
3828 ecore_iov_vf_flr_poll_dorq(struct ecore_hwfn *p_hwfn,
3829 struct ecore_vf_info *p_vf, struct ecore_ptt *p_ptt)
3834 ecore_fid_pretend(p_hwfn, p_ptt, (u16)p_vf->concrete_fid);
3836 for (cnt = 0; cnt < 50; cnt++) {
3837 val = ecore_rd(p_hwfn, p_ptt, DORQ_REG_VF_USAGE_CNT);
3842 ecore_fid_pretend(p_hwfn, p_ptt, (u16)p_hwfn->hw_info.concrete_fid);
3846 "VF[%d] - dorq failed to cleanup [usage 0x%08x]\n",
3847 p_vf->abs_vf_id, val);
3848 return ECORE_TIMEOUT;
3851 return ECORE_SUCCESS;
3854 static enum _ecore_status_t
3855 ecore_iov_vf_flr_poll_pbf(struct ecore_hwfn *p_hwfn,
3856 struct ecore_vf_info *p_vf, struct ecore_ptt *p_ptt)
3858 u32 cons[MAX_NUM_VOQS_E4], distance[MAX_NUM_VOQS_E4];
3861 /* Read initial consumers & producers */
3862 for (i = 0; i < MAX_NUM_VOQS_E4; i++) {
3865 cons[i] = ecore_rd(p_hwfn, p_ptt,
3866 PBF_REG_NUM_BLOCKS_ALLOCATED_CONS_VOQ0 +
3868 prod = ecore_rd(p_hwfn, p_ptt,
3869 PBF_REG_NUM_BLOCKS_ALLOCATED_PROD_VOQ0 +
3871 distance[i] = prod - cons[i];
3874 /* Wait for consumers to pass the producers */
3876 for (cnt = 0; cnt < 50; cnt++) {
3877 for (; i < MAX_NUM_VOQS_E4; i++) {
3880 tmp = ecore_rd(p_hwfn, p_ptt,
3881 PBF_REG_NUM_BLOCKS_ALLOCATED_CONS_VOQ0 +
3883 if (distance[i] > tmp - cons[i])
3887 if (i == MAX_NUM_VOQS_E4)
3894 DP_ERR(p_hwfn, "VF[%d] - pbf polling failed on VOQ %d\n",
3895 p_vf->abs_vf_id, i);
3896 return ECORE_TIMEOUT;
3899 return ECORE_SUCCESS;
3902 static enum _ecore_status_t ecore_iov_vf_flr_poll(struct ecore_hwfn *p_hwfn,
3903 struct ecore_vf_info *p_vf,
3904 struct ecore_ptt *p_ptt)
3906 enum _ecore_status_t rc;
3908 /* TODO - add SRC and TM polling once we add storage IOV */
3910 rc = ecore_iov_vf_flr_poll_dorq(p_hwfn, p_vf, p_ptt);
3914 rc = ecore_iov_vf_flr_poll_pbf(p_hwfn, p_vf, p_ptt);
3918 return ECORE_SUCCESS;
3921 static enum _ecore_status_t
3922 ecore_iov_execute_vf_flr_cleanup(struct ecore_hwfn *p_hwfn,
3923 struct ecore_ptt *p_ptt,
3924 u16 rel_vf_id, u32 *ack_vfs)
3926 struct ecore_vf_info *p_vf;
3927 enum _ecore_status_t rc = ECORE_SUCCESS;
3929 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, false);
3931 return ECORE_SUCCESS;
3933 if (p_hwfn->pf_iov_info->pending_flr[rel_vf_id / 64] &
3934 (1ULL << (rel_vf_id % 64))) {
3935 u16 vfid = p_vf->abs_vf_id;
3937 /* TODO - should we lock channel? */
3939 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3940 "VF[%d] - Handling FLR\n", vfid);
3942 ecore_iov_vf_cleanup(p_hwfn, p_vf);
3944 /* If VF isn't active, no need for anything but SW */
3948 /* TODO - what to do in case of failure? */
3949 rc = ecore_iov_vf_flr_poll(p_hwfn, p_vf, p_ptt);
3950 if (rc != ECORE_SUCCESS)
3953 rc = ecore_final_cleanup(p_hwfn, p_ptt, vfid, true);
3955 /* TODO - what's now? What a mess.... */
3956 DP_ERR(p_hwfn, "Failed handle FLR of VF[%d]\n", vfid);
3960 /* Workaround to make VF-PF channel ready, as FW
3961 * doesn't do that as a part of FLR.
3964 GTT_BAR0_MAP_REG_USDM_RAM +
3965 USTORM_VF_PF_CHANNEL_READY_OFFSET(vfid), 1);
3967 /* VF_STOPPED has to be set only after final cleanup
3968 * but prior to re-enabling the VF.
3970 p_vf->state = VF_STOPPED;
3972 rc = ecore_iov_enable_vf_access(p_hwfn, p_ptt, p_vf);
3974 /* TODO - again, a mess... */
3975 DP_ERR(p_hwfn, "Failed to re-enable VF[%d] acces\n",
3980 /* Mark VF for ack and clean pending state */
3981 if (p_vf->state == VF_RESET)
3982 p_vf->state = VF_STOPPED;
3983 ack_vfs[vfid / 32] |= (1 << (vfid % 32));
3984 p_hwfn->pf_iov_info->pending_flr[rel_vf_id / 64] &=
3985 ~(1ULL << (rel_vf_id % 64));
3986 p_vf->vf_mbx.b_pending_msg = false;
3992 enum _ecore_status_t ecore_iov_vf_flr_cleanup(struct ecore_hwfn *p_hwfn,
3993 struct ecore_ptt *p_ptt)
3995 u32 ack_vfs[VF_MAX_STATIC / 32];
3996 enum _ecore_status_t rc = ECORE_SUCCESS;
3999 OSAL_MEMSET(ack_vfs, 0, sizeof(u32) * (VF_MAX_STATIC / 32));
4001 /* Since BRB <-> PRS interface can't be tested as part of the flr
4002 * polling due to HW limitations, simply sleep a bit. And since
4003 * there's no need to wait per-vf, do it before looping.
4007 for (i = 0; i < p_hwfn->p_dev->p_iov_info->total_vfs; i++)
4008 ecore_iov_execute_vf_flr_cleanup(p_hwfn, p_ptt, i, ack_vfs);
4010 rc = ecore_mcp_ack_vf_flr(p_hwfn, p_ptt, ack_vfs);
4014 enum _ecore_status_t
4015 ecore_iov_single_vf_flr_cleanup(struct ecore_hwfn *p_hwfn,
4016 struct ecore_ptt *p_ptt, u16 rel_vf_id)
4018 u32 ack_vfs[VF_MAX_STATIC / 32];
4019 enum _ecore_status_t rc = ECORE_SUCCESS;
4021 OSAL_MEMSET(ack_vfs, 0, sizeof(u32) * (VF_MAX_STATIC / 32));
4023 /* Wait instead of polling the BRB <-> PRS interface */
4026 ecore_iov_execute_vf_flr_cleanup(p_hwfn, p_ptt, rel_vf_id, ack_vfs);
4028 rc = ecore_mcp_ack_vf_flr(p_hwfn, p_ptt, ack_vfs);
4032 bool ecore_iov_mark_vf_flr(struct ecore_hwfn *p_hwfn, u32 *p_disabled_vfs)
4037 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV, "Marking FLR-ed VFs\n");
4038 for (i = 0; i < (VF_MAX_STATIC / 32); i++)
4039 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
4040 "[%08x,...,%08x]: %08x\n",
4041 i * 32, (i + 1) * 32 - 1, p_disabled_vfs[i]);
4043 if (!p_hwfn->p_dev->p_iov_info) {
4044 DP_NOTICE(p_hwfn, true, "VF flr but no IOV\n");
4049 for (i = 0; i < p_hwfn->p_dev->p_iov_info->total_vfs; i++) {
4050 struct ecore_vf_info *p_vf;
4053 p_vf = ecore_iov_get_vf_info(p_hwfn, i, false);
4057 vfid = p_vf->abs_vf_id;
4058 if ((1 << (vfid % 32)) & p_disabled_vfs[vfid / 32]) {
4059 u64 *p_flr = p_hwfn->pf_iov_info->pending_flr;
4060 u16 rel_vf_id = p_vf->relative_vf_id;
4062 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
4063 "VF[%d] [rel %d] got FLR-ed\n",
4066 p_vf->state = VF_RESET;
4068 /* No need to lock here, since pending_flr should
4069 * only change here and before ACKing MFw. Since
4070 * MFW will not trigger an additional attention for
4071 * VF flr until ACKs, we're safe.
4073 p_flr[rel_vf_id / 64] |= 1ULL << (rel_vf_id % 64);
4081 void ecore_iov_get_link(struct ecore_hwfn *p_hwfn,
4083 struct ecore_mcp_link_params *p_params,
4084 struct ecore_mcp_link_state *p_link,
4085 struct ecore_mcp_link_capabilities *p_caps)
4087 struct ecore_vf_info *p_vf = ecore_iov_get_vf_info(p_hwfn, vfid, false);
4088 struct ecore_bulletin_content *p_bulletin;
4093 p_bulletin = p_vf->bulletin.p_virt;
4096 __ecore_vf_get_link_params(p_params, p_bulletin);
4098 __ecore_vf_get_link_state(p_link, p_bulletin);
4100 __ecore_vf_get_link_caps(p_caps, p_bulletin);
4103 void ecore_iov_process_mbx_req(struct ecore_hwfn *p_hwfn,
4104 struct ecore_ptt *p_ptt, int vfid)
4106 struct ecore_iov_vf_mbx *mbx;
4107 struct ecore_vf_info *p_vf;
4109 p_vf = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4113 mbx = &p_vf->vf_mbx;
4115 /* ecore_iov_process_mbx_request */
4116 #ifndef CONFIG_ECORE_SW_CHANNEL
4117 if (!mbx->b_pending_msg) {
4118 DP_NOTICE(p_hwfn, true,
4119 "VF[%02x]: Trying to process mailbox message when none is pending\n",
4123 mbx->b_pending_msg = false;
4126 mbx->first_tlv = mbx->req_virt->first_tlv;
4128 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
4129 "VF[%02x]: Processing mailbox message [type %04x]\n",
4130 p_vf->abs_vf_id, mbx->first_tlv.tl.type);
4132 OSAL_IOV_VF_MSG_TYPE(p_hwfn,
4133 p_vf->relative_vf_id,
4134 mbx->first_tlv.tl.type);
4136 /* Lock the per vf op mutex and note the locker's identity.
4137 * The unlock will take place in mbx response.
4139 ecore_iov_lock_vf_pf_channel(p_hwfn,
4140 p_vf, mbx->first_tlv.tl.type);
4142 /* check if tlv type is known */
4143 if (ecore_iov_tlv_supported(mbx->first_tlv.tl.type) &&
4144 !p_vf->b_malicious) {
4145 /* switch on the opcode */
4146 switch (mbx->first_tlv.tl.type) {
4147 case CHANNEL_TLV_ACQUIRE:
4148 ecore_iov_vf_mbx_acquire(p_hwfn, p_ptt, p_vf);
4150 case CHANNEL_TLV_VPORT_START:
4151 ecore_iov_vf_mbx_start_vport(p_hwfn, p_ptt, p_vf);
4153 case CHANNEL_TLV_VPORT_TEARDOWN:
4154 ecore_iov_vf_mbx_stop_vport(p_hwfn, p_ptt, p_vf);
4156 case CHANNEL_TLV_START_RXQ:
4157 ecore_iov_vf_mbx_start_rxq(p_hwfn, p_ptt, p_vf);
4159 case CHANNEL_TLV_START_TXQ:
4160 ecore_iov_vf_mbx_start_txq(p_hwfn, p_ptt, p_vf);
4162 case CHANNEL_TLV_STOP_RXQS:
4163 ecore_iov_vf_mbx_stop_rxqs(p_hwfn, p_ptt, p_vf);
4165 case CHANNEL_TLV_STOP_TXQS:
4166 ecore_iov_vf_mbx_stop_txqs(p_hwfn, p_ptt, p_vf);
4168 case CHANNEL_TLV_UPDATE_RXQ:
4169 ecore_iov_vf_mbx_update_rxqs(p_hwfn, p_ptt, p_vf);
4171 case CHANNEL_TLV_VPORT_UPDATE:
4172 ecore_iov_vf_mbx_vport_update(p_hwfn, p_ptt, p_vf);
4174 case CHANNEL_TLV_UCAST_FILTER:
4175 ecore_iov_vf_mbx_ucast_filter(p_hwfn, p_ptt, p_vf);
4177 case CHANNEL_TLV_CLOSE:
4178 ecore_iov_vf_mbx_close(p_hwfn, p_ptt, p_vf);
4180 case CHANNEL_TLV_INT_CLEANUP:
4181 ecore_iov_vf_mbx_int_cleanup(p_hwfn, p_ptt, p_vf);
4183 case CHANNEL_TLV_RELEASE:
4184 ecore_iov_vf_mbx_release(p_hwfn, p_ptt, p_vf);
4186 case CHANNEL_TLV_UPDATE_TUNN_PARAM:
4187 ecore_iov_vf_mbx_update_tunn_param(p_hwfn, p_ptt, p_vf);
4189 case CHANNEL_TLV_COALESCE_UPDATE:
4190 ecore_iov_vf_pf_set_coalesce(p_hwfn, p_ptt, p_vf);
4192 case CHANNEL_TLV_COALESCE_READ:
4193 ecore_iov_vf_pf_get_coalesce(p_hwfn, p_ptt, p_vf);
4195 case CHANNEL_TLV_UPDATE_MTU:
4196 ecore_iov_vf_pf_update_mtu(p_hwfn, p_ptt, p_vf);
4199 } else if (ecore_iov_tlv_supported(mbx->first_tlv.tl.type)) {
4200 /* If we've received a message from a VF we consider malicious
4201 * we ignore the messasge unless it's one for RELEASE, in which
4202 * case we'll let it have the benefit of doubt, allowing the
4203 * next loaded driver to start again.
4205 if (mbx->first_tlv.tl.type == CHANNEL_TLV_RELEASE) {
4206 /* TODO - initiate FLR, remove malicious indication */
4207 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
4208 "VF [%02x] - considered malicious, but wanted to RELEASE. TODO\n",
4211 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
4212 "VF [%02x] - considered malicious; Ignoring TLV [%04x]\n",
4213 p_vf->abs_vf_id, mbx->first_tlv.tl.type);
4216 ecore_iov_prepare_resp(p_hwfn, p_ptt, p_vf,
4217 mbx->first_tlv.tl.type,
4218 sizeof(struct pfvf_def_resp_tlv),
4219 PFVF_STATUS_MALICIOUS);
4221 /* unknown TLV - this may belong to a VF driver from the future
4222 * - a version written after this PF driver was written, which
4223 * supports features unknown as of yet. Too bad since we don't
4224 * support them. Or this may be because someone wrote a crappy
4225 * VF driver and is sending garbage over the channel.
4227 DP_NOTICE(p_hwfn, false,
4228 "VF[%02x]: unknown TLV. type %04x length %04x"
4229 " padding %08x reply address %lu\n",
4231 mbx->first_tlv.tl.type,
4232 mbx->first_tlv.tl.length,
4233 mbx->first_tlv.padding,
4234 (unsigned long)mbx->first_tlv.reply_address);
4236 /* Try replying in case reply address matches the acquisition's
4239 if (p_vf->acquire.first_tlv.reply_address &&
4240 (mbx->first_tlv.reply_address ==
4241 p_vf->acquire.first_tlv.reply_address))
4242 ecore_iov_prepare_resp(p_hwfn, p_ptt, p_vf,
4243 mbx->first_tlv.tl.type,
4244 sizeof(struct pfvf_def_resp_tlv),
4245 PFVF_STATUS_NOT_SUPPORTED);
4247 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
4248 "VF[%02x]: Can't respond to TLV -"
4249 " no valid reply address\n",
4253 ecore_iov_unlock_vf_pf_channel(p_hwfn, p_vf,
4254 mbx->first_tlv.tl.type);
4256 #ifdef CONFIG_ECORE_SW_CHANNEL
4257 mbx->sw_mbx.mbx_state = VF_PF_RESPONSE_READY;
4258 mbx->sw_mbx.response_offset = 0;
4262 void ecore_iov_pf_get_pending_events(struct ecore_hwfn *p_hwfn,
4267 OSAL_MEM_ZERO(events, sizeof(u64) * ECORE_VF_ARRAY_LENGTH);
4269 ecore_for_each_vf(p_hwfn, i) {
4270 struct ecore_vf_info *p_vf;
4272 p_vf = &p_hwfn->pf_iov_info->vfs_array[i];
4273 if (p_vf->vf_mbx.b_pending_msg)
4274 events[i / 64] |= 1ULL << (i % 64);
4278 static struct ecore_vf_info *
4279 ecore_sriov_get_vf_from_absid(struct ecore_hwfn *p_hwfn, u16 abs_vfid)
4281 u8 min = (u8)p_hwfn->p_dev->p_iov_info->first_vf_in_pf;
4283 if (!_ecore_iov_pf_sanity_check(p_hwfn, (int)abs_vfid - min, false)) {
4284 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
4285 "Got indication for VF [abs 0x%08x] that cannot be"
4291 return &p_hwfn->pf_iov_info->vfs_array[(u8)abs_vfid - min];
4294 static enum _ecore_status_t ecore_sriov_vfpf_msg(struct ecore_hwfn *p_hwfn,
4296 struct regpair *vf_msg)
4298 struct ecore_vf_info *p_vf = ecore_sriov_get_vf_from_absid(p_hwfn,
4302 return ECORE_SUCCESS;
4304 /* List the physical address of the request so that handler
4305 * could later on copy the message from it.
4307 p_vf->vf_mbx.pending_req = (((u64)vf_msg->hi) << 32) | vf_msg->lo;
4309 p_vf->vf_mbx.b_pending_msg = true;
4311 return OSAL_PF_VF_MSG(p_hwfn, p_vf->relative_vf_id);
4314 static void ecore_sriov_vfpf_malicious(struct ecore_hwfn *p_hwfn,
4315 struct malicious_vf_eqe_data *p_data)
4317 struct ecore_vf_info *p_vf;
4319 p_vf = ecore_sriov_get_vf_from_absid(p_hwfn, p_data->vf_id);
4324 if (!p_vf->b_malicious) {
4325 DP_NOTICE(p_hwfn, false,
4326 "VF [%d] - Malicious behavior [%02x]\n",
4327 p_vf->abs_vf_id, p_data->err_id);
4329 p_vf->b_malicious = true;
4332 "VF [%d] - Malicious behavior [%02x]\n",
4333 p_vf->abs_vf_id, p_data->err_id);
4336 OSAL_PF_VF_MALICIOUS(p_hwfn, p_vf->relative_vf_id);
4339 static enum _ecore_status_t ecore_sriov_eqe_event(struct ecore_hwfn *p_hwfn,
4342 union event_ring_data *data,
4343 u8 OSAL_UNUSED fw_return_code)
4346 case COMMON_EVENT_VF_PF_CHANNEL:
4347 return ecore_sriov_vfpf_msg(p_hwfn, OSAL_LE16_TO_CPU(echo),
4348 &data->vf_pf_channel.msg_addr);
4349 case COMMON_EVENT_VF_FLR:
4350 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
4351 "VF-FLR is still not supported\n");
4352 return ECORE_SUCCESS;
4353 case COMMON_EVENT_MALICIOUS_VF:
4354 ecore_sriov_vfpf_malicious(p_hwfn, &data->malicious_vf);
4355 return ECORE_SUCCESS;
4357 DP_INFO(p_hwfn->p_dev, "Unknown sriov eqe event 0x%02x\n",
4363 bool ecore_iov_is_vf_pending_flr(struct ecore_hwfn *p_hwfn, u16 rel_vf_id)
4365 return !!(p_hwfn->pf_iov_info->pending_flr[rel_vf_id / 64] &
4366 (1ULL << (rel_vf_id % 64)));
4369 u16 ecore_iov_get_next_active_vf(struct ecore_hwfn *p_hwfn, u16 rel_vf_id)
4371 struct ecore_hw_sriov_info *p_iov = p_hwfn->p_dev->p_iov_info;
4377 for (i = rel_vf_id; i < p_iov->total_vfs; i++)
4378 if (ecore_iov_is_valid_vfid(p_hwfn, rel_vf_id, true, false))
4382 return MAX_NUM_VFS_E4;
4385 enum _ecore_status_t ecore_iov_copy_vf_msg(struct ecore_hwfn *p_hwfn,
4386 struct ecore_ptt *ptt, int vfid)
4388 struct ecore_dmae_params params;
4389 struct ecore_vf_info *vf_info;
4391 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4395 OSAL_MEMSET(¶ms, 0, sizeof(struct ecore_dmae_params));
4396 params.flags = ECORE_DMAE_FLAG_VF_SRC | ECORE_DMAE_FLAG_COMPLETION_DST;
4397 params.src_vfid = vf_info->abs_vf_id;
4399 if (ecore_dmae_host2host(p_hwfn, ptt,
4400 vf_info->vf_mbx.pending_req,
4401 vf_info->vf_mbx.req_phys,
4402 sizeof(union vfpf_tlvs) / 4, ¶ms)) {
4403 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
4404 "Failed to copy message from VF 0x%02x\n", vfid);
4409 return ECORE_SUCCESS;
4412 void ecore_iov_bulletin_set_forced_mac(struct ecore_hwfn *p_hwfn,
4415 struct ecore_vf_info *vf_info;
4418 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4420 DP_NOTICE(p_hwfn->p_dev, true,
4421 "Can not set forced MAC, invalid vfid [%d]\n", vfid);
4424 if (vf_info->b_malicious) {
4425 DP_NOTICE(p_hwfn->p_dev, false,
4426 "Can't set forced MAC to malicious VF [%d]\n",
4431 if (p_hwfn->pf_params.eth_pf_params.allow_vf_mac_change ||
4432 vf_info->p_vf_info.is_trusted_configured) {
4433 feature = 1 << VFPF_BULLETIN_MAC_ADDR;
4434 /* Trust mode will disable Forced MAC */
4435 vf_info->bulletin.p_virt->valid_bitmap &=
4436 ~(1 << MAC_ADDR_FORCED);
4438 feature = 1 << MAC_ADDR_FORCED;
4439 /* Forced MAC will disable MAC_ADDR */
4440 vf_info->bulletin.p_virt->valid_bitmap &=
4441 ~(1 << VFPF_BULLETIN_MAC_ADDR);
4444 OSAL_MEMCPY(vf_info->bulletin.p_virt->mac,
4447 vf_info->bulletin.p_virt->valid_bitmap |= feature;
4449 ecore_iov_configure_vport_forced(p_hwfn, vf_info, feature);
4452 enum _ecore_status_t ecore_iov_bulletin_set_mac(struct ecore_hwfn *p_hwfn,
4455 struct ecore_vf_info *vf_info;
4458 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4460 DP_NOTICE(p_hwfn->p_dev, true,
4461 "Can not set MAC, invalid vfid [%d]\n", vfid);
4464 if (vf_info->b_malicious) {
4465 DP_NOTICE(p_hwfn->p_dev, false,
4466 "Can't set MAC to malicious VF [%d]\n",
4471 if (vf_info->bulletin.p_virt->valid_bitmap & (1 << MAC_ADDR_FORCED)) {
4472 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
4473 "Can not set MAC, Forced MAC is configured\n");
4477 feature = 1 << VFPF_BULLETIN_MAC_ADDR;
4478 OSAL_MEMCPY(vf_info->bulletin.p_virt->mac, mac, ETH_ALEN);
4480 vf_info->bulletin.p_virt->valid_bitmap |= feature;
4482 if (p_hwfn->pf_params.eth_pf_params.allow_vf_mac_change ||
4483 vf_info->p_vf_info.is_trusted_configured)
4484 ecore_iov_configure_vport_forced(p_hwfn, vf_info, feature);
4486 return ECORE_SUCCESS;
4489 #ifndef LINUX_REMOVE
4490 enum _ecore_status_t
4491 ecore_iov_bulletin_set_forced_untagged_default(struct ecore_hwfn *p_hwfn,
4492 bool b_untagged_only, int vfid)
4494 struct ecore_vf_info *vf_info;
4497 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4499 DP_NOTICE(p_hwfn->p_dev, true,
4500 "Can not set untagged default, invalid vfid [%d]\n",
4504 if (vf_info->b_malicious) {
4505 DP_NOTICE(p_hwfn->p_dev, false,
4506 "Can't set untagged default to malicious VF [%d]\n",
4511 /* Since this is configurable only during vport-start, don't take it
4512 * if we're past that point.
4514 if (vf_info->state == VF_ENABLED) {
4515 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
4516 "Can't support untagged change for vfid[%d] -"
4517 " VF is already active\n",
4522 /* Set configuration; This will later be taken into account during the
4523 * VF initialization.
4525 feature = (1 << VFPF_BULLETIN_UNTAGGED_DEFAULT) |
4526 (1 << VFPF_BULLETIN_UNTAGGED_DEFAULT_FORCED);
4527 vf_info->bulletin.p_virt->valid_bitmap |= feature;
4529 vf_info->bulletin.p_virt->default_only_untagged = b_untagged_only ? 1
4532 return ECORE_SUCCESS;
4535 void ecore_iov_get_vfs_opaque_fid(struct ecore_hwfn *p_hwfn, int vfid,
4538 struct ecore_vf_info *vf_info;
4540 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4544 *opaque_fid = vf_info->opaque_fid;
4548 void ecore_iov_bulletin_set_forced_vlan(struct ecore_hwfn *p_hwfn,
4551 struct ecore_vf_info *vf_info;
4554 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4556 DP_NOTICE(p_hwfn->p_dev, true,
4557 "Can not set forced MAC, invalid vfid [%d]\n",
4561 if (vf_info->b_malicious) {
4562 DP_NOTICE(p_hwfn->p_dev, false,
4563 "Can't set forced vlan to malicious VF [%d]\n",
4568 feature = 1 << VLAN_ADDR_FORCED;
4569 vf_info->bulletin.p_virt->pvid = pvid;
4571 vf_info->bulletin.p_virt->valid_bitmap |= feature;
4573 vf_info->bulletin.p_virt->valid_bitmap &= ~feature;
4575 ecore_iov_configure_vport_forced(p_hwfn, vf_info, feature);
4578 void ecore_iov_bulletin_set_udp_ports(struct ecore_hwfn *p_hwfn,
4579 int vfid, u16 vxlan_port, u16 geneve_port)
4581 struct ecore_vf_info *vf_info;
4583 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4585 DP_NOTICE(p_hwfn->p_dev, true,
4586 "Can not set udp ports, invalid vfid [%d]\n", vfid);
4590 if (vf_info->b_malicious) {
4591 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
4592 "Can not set udp ports to malicious VF [%d]\n",
4597 vf_info->bulletin.p_virt->vxlan_udp_port = vxlan_port;
4598 vf_info->bulletin.p_virt->geneve_udp_port = geneve_port;
4601 bool ecore_iov_vf_has_vport_instance(struct ecore_hwfn *p_hwfn, int vfid)
4603 struct ecore_vf_info *p_vf_info;
4605 p_vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4609 return !!p_vf_info->vport_instance;
4612 bool ecore_iov_is_vf_stopped(struct ecore_hwfn *p_hwfn, int vfid)
4614 struct ecore_vf_info *p_vf_info;
4616 p_vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4620 return p_vf_info->state == VF_STOPPED;
4623 bool ecore_iov_spoofchk_get(struct ecore_hwfn *p_hwfn, int vfid)
4625 struct ecore_vf_info *vf_info;
4627 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4631 return vf_info->spoof_chk;
4634 enum _ecore_status_t ecore_iov_spoofchk_set(struct ecore_hwfn *p_hwfn,
4637 struct ecore_vf_info *vf;
4638 enum _ecore_status_t rc = ECORE_INVAL;
4640 if (!ecore_iov_pf_sanity_check(p_hwfn, vfid)) {
4641 DP_NOTICE(p_hwfn, true,
4642 "SR-IOV sanity check failed, can't set spoofchk\n");
4646 vf = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4650 if (!ecore_iov_vf_has_vport_instance(p_hwfn, vfid)) {
4651 /* After VF VPORT start PF will configure spoof check */
4652 vf->req_spoofchk_val = val;
4657 rc = __ecore_iov_spoofchk_set(p_hwfn, vf, val);
4663 u8 ecore_iov_vf_chains_per_pf(struct ecore_hwfn *p_hwfn)
4665 u8 max_chains_per_vf = p_hwfn->hw_info.max_chains_per_vf;
4667 max_chains_per_vf = (max_chains_per_vf) ? max_chains_per_vf
4668 : ECORE_MAX_VF_CHAINS_PER_PF;
4670 return max_chains_per_vf;
4673 void ecore_iov_get_vf_req_virt_mbx_params(struct ecore_hwfn *p_hwfn,
4675 void **pp_req_virt_addr,
4676 u16 *p_req_virt_size)
4678 struct ecore_vf_info *vf_info =
4679 ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4684 if (pp_req_virt_addr)
4685 *pp_req_virt_addr = vf_info->vf_mbx.req_virt;
4687 if (p_req_virt_size)
4688 *p_req_virt_size = sizeof(*vf_info->vf_mbx.req_virt);
4691 void ecore_iov_get_vf_reply_virt_mbx_params(struct ecore_hwfn *p_hwfn,
4693 void **pp_reply_virt_addr,
4694 u16 *p_reply_virt_size)
4696 struct ecore_vf_info *vf_info =
4697 ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4702 if (pp_reply_virt_addr)
4703 *pp_reply_virt_addr = vf_info->vf_mbx.reply_virt;
4705 if (p_reply_virt_size)
4706 *p_reply_virt_size = sizeof(*vf_info->vf_mbx.reply_virt);
4709 #ifdef CONFIG_ECORE_SW_CHANNEL
4710 struct ecore_iov_sw_mbx *ecore_iov_get_vf_sw_mbx(struct ecore_hwfn *p_hwfn,
4713 struct ecore_vf_info *vf_info =
4714 ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4719 return &vf_info->vf_mbx.sw_mbx;
4723 bool ecore_iov_is_valid_vfpf_msg_length(u32 length)
4725 return (length >= sizeof(struct vfpf_first_tlv) &&
4726 (length <= sizeof(union vfpf_tlvs)));
4729 u32 ecore_iov_pfvf_msg_length(void)
4731 return sizeof(union pfvf_tlvs);
4734 u8 *ecore_iov_bulletin_get_mac(struct ecore_hwfn *p_hwfn,
4737 struct ecore_vf_info *p_vf;
4739 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4740 if (!p_vf || !p_vf->bulletin.p_virt)
4743 if (!(p_vf->bulletin.p_virt->valid_bitmap &
4744 (1 << VFPF_BULLETIN_MAC_ADDR)))
4747 return p_vf->bulletin.p_virt->mac;
4750 u8 *ecore_iov_bulletin_get_forced_mac(struct ecore_hwfn *p_hwfn, u16 rel_vf_id)
4752 struct ecore_vf_info *p_vf;
4754 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4755 if (!p_vf || !p_vf->bulletin.p_virt)
4758 if (!(p_vf->bulletin.p_virt->valid_bitmap & (1 << MAC_ADDR_FORCED)))
4761 return p_vf->bulletin.p_virt->mac;
4764 u16 ecore_iov_bulletin_get_forced_vlan(struct ecore_hwfn *p_hwfn,
4767 struct ecore_vf_info *p_vf;
4769 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4770 if (!p_vf || !p_vf->bulletin.p_virt)
4773 if (!(p_vf->bulletin.p_virt->valid_bitmap & (1 << VLAN_ADDR_FORCED)))
4776 return p_vf->bulletin.p_virt->pvid;
4779 enum _ecore_status_t ecore_iov_configure_tx_rate(struct ecore_hwfn *p_hwfn,
4780 struct ecore_ptt *p_ptt,
4783 struct ecore_mcp_link_state *p_link;
4784 struct ecore_vf_info *vf;
4786 enum _ecore_status_t rc;
4788 vf = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4793 rc = ecore_fw_vport(p_hwfn, vf->vport_id, &abs_vp_id);
4794 if (rc != ECORE_SUCCESS)
4797 p_link = &ECORE_LEADING_HWFN(p_hwfn->p_dev)->mcp_info->link_output;
4799 return ecore_init_vport_rl(p_hwfn, p_ptt, abs_vp_id, (u32)val,
4803 enum _ecore_status_t ecore_iov_configure_min_tx_rate(struct ecore_dev *p_dev,
4806 struct ecore_vf_info *vf;
4809 for_each_hwfn(p_dev, i) {
4810 struct ecore_hwfn *p_hwfn = &p_dev->hwfns[i];
4812 if (!ecore_iov_pf_sanity_check(p_hwfn, vfid)) {
4813 DP_NOTICE(p_hwfn, true,
4814 "SR-IOV sanity check failed, can't set min rate\n");
4819 vf = ecore_iov_get_vf_info(ECORE_LEADING_HWFN(p_dev), (u16)vfid, true);
4821 DP_NOTICE(p_dev, true,
4822 "Getting vf info failed, can't set min rate\n");
4826 return ecore_configure_vport_wfq(p_dev, vf->vport_id, rate);
4829 enum _ecore_status_t ecore_iov_get_vf_stats(struct ecore_hwfn *p_hwfn,
4830 struct ecore_ptt *p_ptt,
4832 struct ecore_eth_stats *p_stats)
4834 struct ecore_vf_info *vf;
4836 vf = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4840 if (vf->state != VF_ENABLED)
4843 __ecore_get_vport_stats(p_hwfn, p_ptt, p_stats,
4844 vf->abs_vf_id + 0x10, false);
4846 return ECORE_SUCCESS;
4849 u8 ecore_iov_get_vf_num_rxqs(struct ecore_hwfn *p_hwfn, u16 rel_vf_id)
4851 struct ecore_vf_info *p_vf;
4853 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4857 return p_vf->num_rxqs;
4860 u8 ecore_iov_get_vf_num_active_rxqs(struct ecore_hwfn *p_hwfn, u16 rel_vf_id)
4862 struct ecore_vf_info *p_vf;
4864 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4868 return p_vf->num_active_rxqs;
4871 void *ecore_iov_get_vf_ctx(struct ecore_hwfn *p_hwfn, u16 rel_vf_id)
4873 struct ecore_vf_info *p_vf;
4875 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4882 u8 ecore_iov_get_vf_num_sbs(struct ecore_hwfn *p_hwfn, u16 rel_vf_id)
4884 struct ecore_vf_info *p_vf;
4886 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4890 return p_vf->num_sbs;
4893 bool ecore_iov_is_vf_wait_for_acquire(struct ecore_hwfn *p_hwfn, u16 rel_vf_id)
4895 struct ecore_vf_info *p_vf;
4897 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4901 return (p_vf->state == VF_FREE);
4904 bool ecore_iov_is_vf_acquired_not_initialized(struct ecore_hwfn *p_hwfn,
4907 struct ecore_vf_info *p_vf;
4909 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4913 return (p_vf->state == VF_ACQUIRED);
4916 bool ecore_iov_is_vf_initialized(struct ecore_hwfn *p_hwfn, u16 rel_vf_id)
4918 struct ecore_vf_info *p_vf;
4920 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4924 return (p_vf->state == VF_ENABLED);
4927 bool ecore_iov_is_vf_started(struct ecore_hwfn *p_hwfn,
4930 struct ecore_vf_info *p_vf;
4932 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4936 return (p_vf->state != VF_FREE && p_vf->state != VF_STOPPED);
4940 ecore_iov_get_vf_min_rate(struct ecore_hwfn *p_hwfn, int vfid)
4942 struct ecore_wfq_data *vf_vp_wfq;
4943 struct ecore_vf_info *vf_info;
4945 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4949 vf_vp_wfq = &p_hwfn->qm_info.wfq_data[vf_info->vport_id];
4951 if (vf_vp_wfq->configured)
4952 return vf_vp_wfq->min_speed;
4957 #ifdef CONFIG_ECORE_SW_CHANNEL
4958 void ecore_iov_set_vf_hw_channel(struct ecore_hwfn *p_hwfn, int vfid,
4961 struct ecore_vf_info *vf_info;
4963 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4967 vf_info->b_hw_channel = b_is_hw;