2 * Copyright (c) 2016 QLogic Corporation.
6 * See LICENSE.qede_pmd for copyright and licensing details.
12 #include "ecore_sriov.h"
13 #include "ecore_status.h"
15 #include "ecore_hw_defs.h"
16 #include "ecore_int.h"
17 #include "ecore_hsi_eth.h"
19 #include "ecore_vfpf_if.h"
20 #include "ecore_rt_defs.h"
21 #include "ecore_init_ops.h"
22 #include "ecore_gtt_reg_addr.h"
23 #include "ecore_iro.h"
24 #include "ecore_mcp.h"
25 #include "ecore_cxt.h"
27 #include "ecore_init_fw_funcs.h"
28 #include "ecore_sp_commands.h"
30 const char *ecore_channel_tlvs_string[] = {
31 "CHANNEL_TLV_NONE", /* ends tlv sequence */
32 "CHANNEL_TLV_ACQUIRE",
33 "CHANNEL_TLV_VPORT_START",
34 "CHANNEL_TLV_VPORT_UPDATE",
35 "CHANNEL_TLV_VPORT_TEARDOWN",
36 "CHANNEL_TLV_START_RXQ",
37 "CHANNEL_TLV_START_TXQ",
38 "CHANNEL_TLV_STOP_RXQ",
39 "CHANNEL_TLV_STOP_TXQ",
40 "CHANNEL_TLV_UPDATE_RXQ",
41 "CHANNEL_TLV_INT_CLEANUP",
43 "CHANNEL_TLV_RELEASE",
44 "CHANNEL_TLV_LIST_END",
45 "CHANNEL_TLV_UCAST_FILTER",
46 "CHANNEL_TLV_VPORT_UPDATE_ACTIVATE",
47 "CHANNEL_TLV_VPORT_UPDATE_TX_SWITCH",
48 "CHANNEL_TLV_VPORT_UPDATE_VLAN_STRIP",
49 "CHANNEL_TLV_VPORT_UPDATE_MCAST",
50 "CHANNEL_TLV_VPORT_UPDATE_ACCEPT_PARAM",
51 "CHANNEL_TLV_VPORT_UPDATE_RSS",
52 "CHANNEL_TLV_VPORT_UPDATE_ACCEPT_ANY_VLAN",
53 "CHANNEL_TLV_VPORT_UPDATE_SGE_TPA",
54 "CHANNEL_TLV_UPDATE_TUNN_PARAM",
55 "CHANNEL_TLV_COALESCE_UPDATE",
60 static u8 ecore_vf_calculate_legacy(struct ecore_hwfn *p_hwfn,
61 struct ecore_vf_info *p_vf)
65 if (p_vf->acquire.vfdev_info.eth_fp_hsi_minor ==
66 ETH_HSI_VER_NO_PKT_LEN_TUNN)
67 legacy |= ECORE_QCID_LEGACY_VF_RX_PROD;
69 if (!(p_vf->acquire.vfdev_info.capabilities &
70 VFPF_ACQUIRE_CAP_QUEUE_QIDS))
71 legacy |= ECORE_QCID_LEGACY_VF_CID;
77 static enum _ecore_status_t ecore_sp_vf_start(struct ecore_hwfn *p_hwfn,
78 struct ecore_vf_info *p_vf)
80 struct vf_start_ramrod_data *p_ramrod = OSAL_NULL;
81 struct ecore_spq_entry *p_ent = OSAL_NULL;
82 struct ecore_sp_init_data init_data;
83 enum _ecore_status_t rc = ECORE_NOTIMPL;
87 OSAL_MEMSET(&init_data, 0, sizeof(init_data));
88 init_data.cid = ecore_spq_get_cid(p_hwfn);
89 init_data.opaque_fid = p_vf->opaque_fid;
90 init_data.comp_mode = ECORE_SPQ_MODE_EBLOCK;
92 rc = ecore_sp_init_request(p_hwfn, &p_ent,
93 COMMON_RAMROD_VF_START,
94 PROTOCOLID_COMMON, &init_data);
95 if (rc != ECORE_SUCCESS)
98 p_ramrod = &p_ent->ramrod.vf_start;
100 p_ramrod->vf_id = GET_FIELD(p_vf->concrete_fid, PXP_CONCRETE_FID_VFID);
101 p_ramrod->opaque_fid = OSAL_CPU_TO_LE16(p_vf->opaque_fid);
103 switch (p_hwfn->hw_info.personality) {
105 p_ramrod->personality = PERSONALITY_ETH;
107 case ECORE_PCI_ETH_ROCE:
108 case ECORE_PCI_ETH_IWARP:
109 p_ramrod->personality = PERSONALITY_RDMA_AND_ETH;
112 DP_NOTICE(p_hwfn, true, "Unknown VF personality %d\n",
113 p_hwfn->hw_info.personality);
117 fp_minor = p_vf->acquire.vfdev_info.eth_fp_hsi_minor;
118 if (fp_minor > ETH_HSI_VER_MINOR &&
119 fp_minor != ETH_HSI_VER_NO_PKT_LEN_TUNN) {
120 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
121 "VF [%d] - Requested fp hsi %02x.%02x which is"
122 " slightly newer than PF's %02x.%02x; Configuring"
125 ETH_HSI_VER_MAJOR, fp_minor,
126 ETH_HSI_VER_MAJOR, ETH_HSI_VER_MINOR);
127 fp_minor = ETH_HSI_VER_MINOR;
130 p_ramrod->hsi_fp_ver.major_ver_arr[ETH_VER_KEY] = ETH_HSI_VER_MAJOR;
131 p_ramrod->hsi_fp_ver.minor_ver_arr[ETH_VER_KEY] = fp_minor;
133 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
134 "VF[%d] - Starting using HSI %02x.%02x\n",
135 p_vf->abs_vf_id, ETH_HSI_VER_MAJOR, fp_minor);
137 return ecore_spq_post(p_hwfn, p_ent, OSAL_NULL);
140 static enum _ecore_status_t ecore_sp_vf_stop(struct ecore_hwfn *p_hwfn,
144 struct vf_stop_ramrod_data *p_ramrod = OSAL_NULL;
145 struct ecore_spq_entry *p_ent = OSAL_NULL;
146 struct ecore_sp_init_data init_data;
147 enum _ecore_status_t rc = ECORE_NOTIMPL;
150 OSAL_MEMSET(&init_data, 0, sizeof(init_data));
151 init_data.cid = ecore_spq_get_cid(p_hwfn);
152 init_data.opaque_fid = opaque_vfid;
153 init_data.comp_mode = ECORE_SPQ_MODE_EBLOCK;
155 rc = ecore_sp_init_request(p_hwfn, &p_ent,
156 COMMON_RAMROD_VF_STOP,
157 PROTOCOLID_COMMON, &init_data);
158 if (rc != ECORE_SUCCESS)
161 p_ramrod = &p_ent->ramrod.vf_stop;
163 p_ramrod->vf_id = GET_FIELD(concrete_vfid, PXP_CONCRETE_FID_VFID);
165 return ecore_spq_post(p_hwfn, p_ent, OSAL_NULL);
168 bool ecore_iov_is_valid_vfid(struct ecore_hwfn *p_hwfn, int rel_vf_id,
169 bool b_enabled_only, bool b_non_malicious)
171 if (!p_hwfn->pf_iov_info) {
172 DP_NOTICE(p_hwfn->p_dev, true, "No iov info\n");
176 if ((rel_vf_id >= p_hwfn->p_dev->p_iov_info->total_vfs) ||
180 if ((!p_hwfn->pf_iov_info->vfs_array[rel_vf_id].b_init) &&
184 if ((p_hwfn->pf_iov_info->vfs_array[rel_vf_id].b_malicious) &&
191 struct ecore_vf_info *ecore_iov_get_vf_info(struct ecore_hwfn *p_hwfn,
195 struct ecore_vf_info *vf = OSAL_NULL;
197 if (!p_hwfn->pf_iov_info) {
198 DP_NOTICE(p_hwfn->p_dev, true, "No iov info\n");
202 if (ecore_iov_is_valid_vfid(p_hwfn, relative_vf_id,
203 b_enabled_only, false))
204 vf = &p_hwfn->pf_iov_info->vfs_array[relative_vf_id];
206 DP_ERR(p_hwfn, "ecore_iov_get_vf_info: VF[%d] is not enabled\n",
212 static struct ecore_queue_cid *
213 ecore_iov_get_vf_rx_queue_cid(struct ecore_hwfn *p_hwfn,
214 struct ecore_vf_info *p_vf,
215 struct ecore_vf_queue *p_queue)
219 for (i = 0; i < MAX_QUEUES_PER_QZONE; i++) {
220 if (p_queue->cids[i].p_cid &&
221 !p_queue->cids[i].b_is_tx)
222 return p_queue->cids[i].p_cid;
228 enum ecore_iov_validate_q_mode {
229 ECORE_IOV_VALIDATE_Q_NA,
230 ECORE_IOV_VALIDATE_Q_ENABLE,
231 ECORE_IOV_VALIDATE_Q_DISABLE,
234 static bool ecore_iov_validate_queue_mode(struct ecore_hwfn *p_hwfn,
235 struct ecore_vf_info *p_vf,
237 enum ecore_iov_validate_q_mode mode,
242 if (mode == ECORE_IOV_VALIDATE_Q_NA)
245 for (i = 0; i < MAX_QUEUES_PER_QZONE; i++) {
246 struct ecore_vf_queue_cid *p_qcid;
248 p_qcid = &p_vf->vf_queues[qid].cids[i];
250 if (p_qcid->p_cid == OSAL_NULL)
253 if (p_qcid->b_is_tx != b_is_tx)
256 /* Found. It's enabled. */
257 return (mode == ECORE_IOV_VALIDATE_Q_ENABLE);
260 /* In case we haven't found any valid cid, then its disabled */
261 return (mode == ECORE_IOV_VALIDATE_Q_DISABLE);
264 static bool ecore_iov_validate_rxq(struct ecore_hwfn *p_hwfn,
265 struct ecore_vf_info *p_vf,
267 enum ecore_iov_validate_q_mode mode)
269 if (rx_qid >= p_vf->num_rxqs) {
270 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
271 "VF[0x%02x] - can't touch Rx queue[%04x];"
272 " Only 0x%04x are allocated\n",
273 p_vf->abs_vf_id, rx_qid, p_vf->num_rxqs);
277 return ecore_iov_validate_queue_mode(p_hwfn, p_vf, rx_qid,
281 static bool ecore_iov_validate_txq(struct ecore_hwfn *p_hwfn,
282 struct ecore_vf_info *p_vf,
284 enum ecore_iov_validate_q_mode mode)
286 if (tx_qid >= p_vf->num_txqs) {
287 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
288 "VF[0x%02x] - can't touch Tx queue[%04x];"
289 " Only 0x%04x are allocated\n",
290 p_vf->abs_vf_id, tx_qid, p_vf->num_txqs);
294 return ecore_iov_validate_queue_mode(p_hwfn, p_vf, tx_qid,
298 static bool ecore_iov_validate_sb(struct ecore_hwfn *p_hwfn,
299 struct ecore_vf_info *p_vf,
304 for (i = 0; i < p_vf->num_sbs; i++)
305 if (p_vf->igu_sbs[i] == sb_idx)
308 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
309 "VF[0%02x] - tried using sb_idx %04x which doesn't exist as"
310 " one of its 0x%02x SBs\n",
311 p_vf->abs_vf_id, sb_idx, p_vf->num_sbs);
316 /* Is there at least 1 queue open? */
317 static bool ecore_iov_validate_active_rxq(struct ecore_hwfn *p_hwfn,
318 struct ecore_vf_info *p_vf)
322 for (i = 0; i < p_vf->num_rxqs; i++)
323 if (ecore_iov_validate_queue_mode(p_hwfn, p_vf, i,
324 ECORE_IOV_VALIDATE_Q_ENABLE,
331 static bool ecore_iov_validate_active_txq(struct ecore_hwfn *p_hwfn,
332 struct ecore_vf_info *p_vf)
336 for (i = 0; i < p_vf->num_txqs; i++)
337 if (ecore_iov_validate_queue_mode(p_hwfn, p_vf, i,
338 ECORE_IOV_VALIDATE_Q_ENABLE,
345 enum _ecore_status_t ecore_iov_post_vf_bulletin(struct ecore_hwfn *p_hwfn,
347 struct ecore_ptt *p_ptt)
349 struct ecore_bulletin_content *p_bulletin;
350 int crc_size = sizeof(p_bulletin->crc);
351 struct ecore_dmae_params params;
352 struct ecore_vf_info *p_vf;
354 p_vf = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
358 /* TODO - check VF is in a state where it can accept message */
359 if (!p_vf->vf_bulletin)
362 p_bulletin = p_vf->bulletin.p_virt;
364 /* Increment bulletin board version and compute crc */
365 p_bulletin->version++;
366 p_bulletin->crc = OSAL_CRC32(0, (u8 *)p_bulletin + crc_size,
367 p_vf->bulletin.size - crc_size);
369 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
370 "Posting Bulletin 0x%08x to VF[%d] (CRC 0x%08x)\n",
371 p_bulletin->version, p_vf->relative_vf_id, p_bulletin->crc);
373 /* propagate bulletin board via dmae to vm memory */
374 OSAL_MEMSET(¶ms, 0, sizeof(params));
375 params.flags = ECORE_DMAE_FLAG_VF_DST;
376 params.dst_vfid = p_vf->abs_vf_id;
377 return ecore_dmae_host2host(p_hwfn, p_ptt, p_vf->bulletin.phys,
378 p_vf->vf_bulletin, p_vf->bulletin.size / 4,
382 static enum _ecore_status_t ecore_iov_pci_cfg_info(struct ecore_dev *p_dev)
384 struct ecore_hw_sriov_info *iov = p_dev->p_iov_info;
387 DP_VERBOSE(p_dev, ECORE_MSG_IOV, "sriov ext pos %d\n", pos);
388 OSAL_PCI_READ_CONFIG_WORD(p_dev, pos + PCI_SRIOV_CTRL, &iov->ctrl);
390 OSAL_PCI_READ_CONFIG_WORD(p_dev,
391 pos + PCI_SRIOV_TOTAL_VF, &iov->total_vfs);
392 OSAL_PCI_READ_CONFIG_WORD(p_dev,
393 pos + PCI_SRIOV_INITIAL_VF,
396 OSAL_PCI_READ_CONFIG_WORD(p_dev, pos + PCI_SRIOV_NUM_VF, &iov->num_vfs);
398 /* @@@TODO - in future we might want to add an OSAL here to
399 * allow each OS to decide on its own how to act.
401 DP_VERBOSE(p_dev, ECORE_MSG_IOV,
402 "Number of VFs are already set to non-zero value."
403 " Ignoring PCI configuration value\n");
407 OSAL_PCI_READ_CONFIG_WORD(p_dev,
408 pos + PCI_SRIOV_VF_OFFSET, &iov->offset);
410 OSAL_PCI_READ_CONFIG_WORD(p_dev,
411 pos + PCI_SRIOV_VF_STRIDE, &iov->stride);
413 OSAL_PCI_READ_CONFIG_WORD(p_dev,
414 pos + PCI_SRIOV_VF_DID, &iov->vf_device_id);
416 OSAL_PCI_READ_CONFIG_DWORD(p_dev,
417 pos + PCI_SRIOV_SUP_PGSIZE, &iov->pgsz);
419 OSAL_PCI_READ_CONFIG_DWORD(p_dev, pos + PCI_SRIOV_CAP, &iov->cap);
421 OSAL_PCI_READ_CONFIG_BYTE(p_dev, pos + PCI_SRIOV_FUNC_LINK, &iov->link);
423 DP_VERBOSE(p_dev, ECORE_MSG_IOV, "IOV info: nres %d, cap 0x%x,"
424 "ctrl 0x%x, total %d, initial %d, num vfs %d, offset %d,"
425 " stride %d, page size 0x%x\n",
426 iov->nres, iov->cap, iov->ctrl,
427 iov->total_vfs, iov->initial_vfs, iov->nr_virtfn,
428 iov->offset, iov->stride, iov->pgsz);
430 /* Some sanity checks */
431 if (iov->num_vfs > NUM_OF_VFS(p_dev) ||
432 iov->total_vfs > NUM_OF_VFS(p_dev)) {
433 /* This can happen only due to a bug. In this case we set
434 * num_vfs to zero to avoid memory corruption in the code that
435 * assumes max number of vfs
437 DP_NOTICE(p_dev, false,
438 "IOV: Unexpected number of vfs set: %d"
439 " setting num_vf to zero\n",
446 return ECORE_SUCCESS;
449 static void ecore_iov_setup_vfdb(struct ecore_hwfn *p_hwfn)
451 struct ecore_hw_sriov_info *p_iov = p_hwfn->p_dev->p_iov_info;
452 struct ecore_pf_iov *p_iov_info = p_hwfn->pf_iov_info;
453 struct ecore_bulletin_content *p_bulletin_virt;
454 dma_addr_t req_p, rply_p, bulletin_p;
455 union pfvf_tlvs *p_reply_virt_addr;
456 union vfpf_tlvs *p_req_virt_addr;
459 OSAL_MEMSET(p_iov_info->vfs_array, 0, sizeof(p_iov_info->vfs_array));
461 p_req_virt_addr = p_iov_info->mbx_msg_virt_addr;
462 req_p = p_iov_info->mbx_msg_phys_addr;
463 p_reply_virt_addr = p_iov_info->mbx_reply_virt_addr;
464 rply_p = p_iov_info->mbx_reply_phys_addr;
465 p_bulletin_virt = p_iov_info->p_bulletins;
466 bulletin_p = p_iov_info->bulletins_phys;
467 if (!p_req_virt_addr || !p_reply_virt_addr || !p_bulletin_virt) {
469 "ecore_iov_setup_vfdb called without alloc mem first\n");
473 for (idx = 0; idx < p_iov->total_vfs; idx++) {
474 struct ecore_vf_info *vf = &p_iov_info->vfs_array[idx];
477 vf->vf_mbx.req_virt = p_req_virt_addr + idx;
478 vf->vf_mbx.req_phys = req_p + idx * sizeof(union vfpf_tlvs);
479 vf->vf_mbx.reply_virt = p_reply_virt_addr + idx;
480 vf->vf_mbx.reply_phys = rply_p + idx * sizeof(union pfvf_tlvs);
482 #ifdef CONFIG_ECORE_SW_CHANNEL
483 vf->vf_mbx.sw_mbx.request_size = sizeof(union vfpf_tlvs);
484 vf->vf_mbx.sw_mbx.mbx_state = VF_PF_WAIT_FOR_START_REQUEST;
486 vf->state = VF_STOPPED;
489 vf->bulletin.phys = idx *
490 sizeof(struct ecore_bulletin_content) + bulletin_p;
491 vf->bulletin.p_virt = p_bulletin_virt + idx;
492 vf->bulletin.size = sizeof(struct ecore_bulletin_content);
494 vf->relative_vf_id = idx;
495 vf->abs_vf_id = idx + p_iov->first_vf_in_pf;
496 concrete = ecore_vfid_to_concrete(p_hwfn, vf->abs_vf_id);
497 vf->concrete_fid = concrete;
498 /* TODO - need to devise a better way of getting opaque */
499 vf->opaque_fid = (p_hwfn->hw_info.opaque_fid & 0xff) |
500 (vf->abs_vf_id << 8);
502 vf->num_mac_filters = ECORE_ETH_VF_NUM_MAC_FILTERS;
503 vf->num_vlan_filters = ECORE_ETH_VF_NUM_VLAN_FILTERS;
507 static enum _ecore_status_t ecore_iov_allocate_vfdb(struct ecore_hwfn *p_hwfn)
509 struct ecore_pf_iov *p_iov_info = p_hwfn->pf_iov_info;
513 num_vfs = p_hwfn->p_dev->p_iov_info->total_vfs;
515 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
516 "ecore_iov_allocate_vfdb for %d VFs\n", num_vfs);
518 /* Allocate PF Mailbox buffer (per-VF) */
519 p_iov_info->mbx_msg_size = sizeof(union vfpf_tlvs) * num_vfs;
520 p_v_addr = &p_iov_info->mbx_msg_virt_addr;
521 *p_v_addr = OSAL_DMA_ALLOC_COHERENT(p_hwfn->p_dev,
522 &p_iov_info->mbx_msg_phys_addr,
523 p_iov_info->mbx_msg_size);
527 /* Allocate PF Mailbox Reply buffer (per-VF) */
528 p_iov_info->mbx_reply_size = sizeof(union pfvf_tlvs) * num_vfs;
529 p_v_addr = &p_iov_info->mbx_reply_virt_addr;
530 *p_v_addr = OSAL_DMA_ALLOC_COHERENT(p_hwfn->p_dev,
531 &p_iov_info->mbx_reply_phys_addr,
532 p_iov_info->mbx_reply_size);
536 p_iov_info->bulletins_size = sizeof(struct ecore_bulletin_content) *
538 p_v_addr = &p_iov_info->p_bulletins;
539 *p_v_addr = OSAL_DMA_ALLOC_COHERENT(p_hwfn->p_dev,
540 &p_iov_info->bulletins_phys,
541 p_iov_info->bulletins_size);
545 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
546 "PF's Requests mailbox [%p virt 0x%lx phys], "
547 "Response mailbox [%p virt 0x%lx phys] Bulletinsi"
548 " [%p virt 0x%lx phys]\n",
549 p_iov_info->mbx_msg_virt_addr,
550 (unsigned long)p_iov_info->mbx_msg_phys_addr,
551 p_iov_info->mbx_reply_virt_addr,
552 (unsigned long)p_iov_info->mbx_reply_phys_addr,
553 p_iov_info->p_bulletins,
554 (unsigned long)p_iov_info->bulletins_phys);
556 return ECORE_SUCCESS;
559 static void ecore_iov_free_vfdb(struct ecore_hwfn *p_hwfn)
561 struct ecore_pf_iov *p_iov_info = p_hwfn->pf_iov_info;
563 if (p_hwfn->pf_iov_info->mbx_msg_virt_addr)
564 OSAL_DMA_FREE_COHERENT(p_hwfn->p_dev,
565 p_iov_info->mbx_msg_virt_addr,
566 p_iov_info->mbx_msg_phys_addr,
567 p_iov_info->mbx_msg_size);
569 if (p_hwfn->pf_iov_info->mbx_reply_virt_addr)
570 OSAL_DMA_FREE_COHERENT(p_hwfn->p_dev,
571 p_iov_info->mbx_reply_virt_addr,
572 p_iov_info->mbx_reply_phys_addr,
573 p_iov_info->mbx_reply_size);
575 if (p_iov_info->p_bulletins)
576 OSAL_DMA_FREE_COHERENT(p_hwfn->p_dev,
577 p_iov_info->p_bulletins,
578 p_iov_info->bulletins_phys,
579 p_iov_info->bulletins_size);
582 enum _ecore_status_t ecore_iov_alloc(struct ecore_hwfn *p_hwfn)
584 struct ecore_pf_iov *p_sriov;
586 if (!IS_PF_SRIOV(p_hwfn)) {
587 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
588 "No SR-IOV - no need for IOV db\n");
589 return ECORE_SUCCESS;
592 p_sriov = OSAL_ZALLOC(p_hwfn->p_dev, GFP_KERNEL, sizeof(*p_sriov));
594 DP_NOTICE(p_hwfn, true,
595 "Failed to allocate `struct ecore_sriov'\n");
599 p_hwfn->pf_iov_info = p_sriov;
601 return ecore_iov_allocate_vfdb(p_hwfn);
604 void ecore_iov_setup(struct ecore_hwfn *p_hwfn)
606 if (!IS_PF_SRIOV(p_hwfn) || !IS_PF_SRIOV_ALLOC(p_hwfn))
609 ecore_iov_setup_vfdb(p_hwfn);
612 void ecore_iov_free(struct ecore_hwfn *p_hwfn)
614 if (IS_PF_SRIOV_ALLOC(p_hwfn)) {
615 ecore_iov_free_vfdb(p_hwfn);
616 OSAL_FREE(p_hwfn->p_dev, p_hwfn->pf_iov_info);
620 void ecore_iov_free_hw_info(struct ecore_dev *p_dev)
622 OSAL_FREE(p_dev, p_dev->p_iov_info);
625 enum _ecore_status_t ecore_iov_hw_info(struct ecore_hwfn *p_hwfn)
627 struct ecore_dev *p_dev = p_hwfn->p_dev;
629 enum _ecore_status_t rc;
631 if (IS_VF(p_hwfn->p_dev))
632 return ECORE_SUCCESS;
634 /* Learn the PCI configuration */
635 pos = OSAL_PCI_FIND_EXT_CAPABILITY(p_hwfn->p_dev,
636 PCI_EXT_CAP_ID_SRIOV);
638 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV, "No PCIe IOV support\n");
639 return ECORE_SUCCESS;
642 /* Allocate a new struct for IOV information */
643 /* TODO - can change to VALLOC when its available */
644 p_dev->p_iov_info = OSAL_ZALLOC(p_dev, GFP_KERNEL,
645 sizeof(*p_dev->p_iov_info));
646 if (!p_dev->p_iov_info) {
647 DP_NOTICE(p_hwfn, true,
648 "Can't support IOV due to lack of memory\n");
651 p_dev->p_iov_info->pos = pos;
653 rc = ecore_iov_pci_cfg_info(p_dev);
657 /* We want PF IOV to be synonemous with the existence of p_iov_info;
658 * In case the capability is published but there are no VFs, simply
659 * de-allocate the struct.
661 if (!p_dev->p_iov_info->total_vfs) {
662 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
663 "IOV capabilities, but no VFs are published\n");
664 OSAL_FREE(p_dev, p_dev->p_iov_info);
665 return ECORE_SUCCESS;
668 /* First VF index based on offset is tricky:
669 * - If ARI is supported [likely], offset - (16 - pf_id) would
670 * provide the number for eng0. 2nd engine Vfs would begin
671 * after the first engine's VFs.
672 * - If !ARI, VFs would start on next device.
673 * so offset - (256 - pf_id) would provide the number.
674 * Utilize the fact that (256 - pf_id) is achieved only be later
675 * to diffrentiate between the two.
678 if (p_hwfn->p_dev->p_iov_info->offset < (256 - p_hwfn->abs_pf_id)) {
679 u32 first = p_hwfn->p_dev->p_iov_info->offset +
680 p_hwfn->abs_pf_id - 16;
682 p_dev->p_iov_info->first_vf_in_pf = first;
684 if (ECORE_PATH_ID(p_hwfn))
685 p_dev->p_iov_info->first_vf_in_pf -= MAX_NUM_VFS_BB;
687 u32 first = p_hwfn->p_dev->p_iov_info->offset +
688 p_hwfn->abs_pf_id - 256;
690 p_dev->p_iov_info->first_vf_in_pf = first;
693 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
694 "First VF in hwfn 0x%08x\n",
695 p_dev->p_iov_info->first_vf_in_pf);
697 return ECORE_SUCCESS;
700 static bool _ecore_iov_pf_sanity_check(struct ecore_hwfn *p_hwfn, int vfid,
701 bool b_fail_malicious)
703 /* Check PF supports sriov */
704 if (IS_VF(p_hwfn->p_dev) || !IS_ECORE_SRIOV(p_hwfn->p_dev) ||
705 !IS_PF_SRIOV_ALLOC(p_hwfn))
708 /* Check VF validity */
709 if (!ecore_iov_is_valid_vfid(p_hwfn, vfid, true, b_fail_malicious))
715 bool ecore_iov_pf_sanity_check(struct ecore_hwfn *p_hwfn, int vfid)
717 return _ecore_iov_pf_sanity_check(p_hwfn, vfid, true);
720 void ecore_iov_set_vf_to_disable(struct ecore_dev *p_dev,
721 u16 rel_vf_id, u8 to_disable)
723 struct ecore_vf_info *vf;
726 for_each_hwfn(p_dev, i) {
727 struct ecore_hwfn *p_hwfn = &p_dev->hwfns[i];
729 vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, false);
733 vf->to_disable = to_disable;
737 void ecore_iov_set_vfs_to_disable(struct ecore_dev *p_dev,
742 if (!IS_ECORE_SRIOV(p_dev))
745 for (i = 0; i < p_dev->p_iov_info->total_vfs; i++)
746 ecore_iov_set_vf_to_disable(p_dev, i, to_disable);
750 /* @@@TBD Consider taking outside of ecore... */
751 enum _ecore_status_t ecore_iov_set_vf_ctx(struct ecore_hwfn *p_hwfn,
755 enum _ecore_status_t rc = ECORE_SUCCESS;
756 struct ecore_vf_info *vf = ecore_iov_get_vf_info(p_hwfn, vf_id, true);
758 if (vf != OSAL_NULL) {
760 #ifdef CONFIG_ECORE_SW_CHANNEL
761 vf->vf_mbx.sw_mbx.mbx_state = VF_PF_WAIT_FOR_START_REQUEST;
764 rc = ECORE_UNKNOWN_ERROR;
770 static void ecore_iov_vf_pglue_clear_err(struct ecore_hwfn *p_hwfn,
771 struct ecore_ptt *p_ptt,
774 ecore_wr(p_hwfn, p_ptt,
775 PGLUE_B_REG_WAS_ERROR_VF_31_0_CLR + (abs_vfid >> 5) * 4,
776 1 << (abs_vfid & 0x1f));
779 static void ecore_iov_vf_igu_reset(struct ecore_hwfn *p_hwfn,
780 struct ecore_ptt *p_ptt,
781 struct ecore_vf_info *vf)
785 /* Set VF masks and configuration - pretend */
786 ecore_fid_pretend(p_hwfn, p_ptt, (u16)vf->concrete_fid);
788 ecore_wr(p_hwfn, p_ptt, IGU_REG_STATISTIC_NUM_VF_MSG_SENT, 0);
791 ecore_fid_pretend(p_hwfn, p_ptt, (u16)p_hwfn->hw_info.concrete_fid);
793 /* iterate over all queues, clear sb consumer */
794 for (i = 0; i < vf->num_sbs; i++)
795 ecore_int_igu_init_pure_rt_single(p_hwfn, p_ptt,
797 vf->opaque_fid, true);
800 static void ecore_iov_vf_igu_set_int(struct ecore_hwfn *p_hwfn,
801 struct ecore_ptt *p_ptt,
802 struct ecore_vf_info *vf, bool enable)
806 ecore_fid_pretend(p_hwfn, p_ptt, (u16)vf->concrete_fid);
808 igu_vf_conf = ecore_rd(p_hwfn, p_ptt, IGU_REG_VF_CONFIGURATION);
811 igu_vf_conf |= IGU_VF_CONF_MSI_MSIX_EN;
813 igu_vf_conf &= ~IGU_VF_CONF_MSI_MSIX_EN;
815 ecore_wr(p_hwfn, p_ptt, IGU_REG_VF_CONFIGURATION, igu_vf_conf);
818 ecore_fid_pretend(p_hwfn, p_ptt, (u16)p_hwfn->hw_info.concrete_fid);
821 static enum _ecore_status_t
822 ecore_iov_enable_vf_access_msix(struct ecore_hwfn *p_hwfn,
823 struct ecore_ptt *p_ptt,
830 /* If client overrides this, don't do anything */
831 if (p_hwfn->p_dev->b_dont_override_vf_msix)
832 return ECORE_SUCCESS;
834 /* For AH onward, configuration is per-PF. Find maximum of all
835 * the currently enabled child VFs, and set the number to be that.
837 if (!ECORE_IS_BB(p_hwfn->p_dev)) {
838 ecore_for_each_vf(p_hwfn, i) {
839 struct ecore_vf_info *p_vf;
841 p_vf = ecore_iov_get_vf_info(p_hwfn, (u16)i, true);
845 current_max = OSAL_MAX_T(u8, current_max,
850 if (num_sbs > current_max)
851 return ecore_mcp_config_vf_msix(p_hwfn, p_ptt,
854 return ECORE_SUCCESS;
857 static enum _ecore_status_t
858 ecore_iov_enable_vf_access(struct ecore_hwfn *p_hwfn,
859 struct ecore_ptt *p_ptt, struct ecore_vf_info *vf)
861 u32 igu_vf_conf = IGU_VF_CONF_FUNC_EN;
862 enum _ecore_status_t rc = ECORE_SUCCESS;
865 return ECORE_SUCCESS;
867 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
868 "Enable internal access for vf %x [abs %x]\n", vf->abs_vf_id,
869 ECORE_VF_ABS_ID(p_hwfn, vf));
871 ecore_iov_vf_pglue_clear_err(p_hwfn, p_ptt,
872 ECORE_VF_ABS_ID(p_hwfn, vf));
874 ecore_iov_vf_igu_reset(p_hwfn, p_ptt, vf);
876 /* It's possible VF was previously considered malicious */
877 vf->b_malicious = false;
878 rc = ecore_iov_enable_vf_access_msix(p_hwfn, p_ptt,
879 vf->abs_vf_id, vf->num_sbs);
880 if (rc != ECORE_SUCCESS)
883 ecore_fid_pretend(p_hwfn, p_ptt, (u16)vf->concrete_fid);
885 SET_FIELD(igu_vf_conf, IGU_VF_CONF_PARENT, p_hwfn->rel_pf_id);
886 STORE_RT_REG(p_hwfn, IGU_REG_VF_CONFIGURATION_RT_OFFSET, igu_vf_conf);
888 ecore_init_run(p_hwfn, p_ptt, PHASE_VF, vf->abs_vf_id,
889 p_hwfn->hw_info.hw_mode);
892 ecore_fid_pretend(p_hwfn, p_ptt, (u16)p_hwfn->hw_info.concrete_fid);
901 * @brief ecore_iov_config_perm_table - configure the permission
903 * In E4, queue zone permission table size is 320x9. There
904 * are 320 VF queues for single engine device (256 for dual
905 * engine device), and each entry has the following format:
912 static void ecore_iov_config_perm_table(struct ecore_hwfn *p_hwfn,
913 struct ecore_ptt *p_ptt,
914 struct ecore_vf_info *vf, u8 enable)
920 for (qid = 0; qid < vf->num_rxqs; qid++) {
921 ecore_fw_l2_queue(p_hwfn, vf->vf_queues[qid].fw_rx_qid,
924 reg_addr = PSWHST_REG_ZONE_PERMISSION_TABLE + qzone_id * 4;
925 val = enable ? (vf->abs_vf_id | (1 << 8)) : 0;
926 ecore_wr(p_hwfn, p_ptt, reg_addr, val);
930 static void ecore_iov_enable_vf_traffic(struct ecore_hwfn *p_hwfn,
931 struct ecore_ptt *p_ptt,
932 struct ecore_vf_info *vf)
934 /* Reset vf in IGU - interrupts are still disabled */
935 ecore_iov_vf_igu_reset(p_hwfn, p_ptt, vf);
937 ecore_iov_vf_igu_set_int(p_hwfn, p_ptt, vf, 1);
939 /* Permission Table */
940 ecore_iov_config_perm_table(p_hwfn, p_ptt, vf, true);
943 static u8 ecore_iov_alloc_vf_igu_sbs(struct ecore_hwfn *p_hwfn,
944 struct ecore_ptt *p_ptt,
945 struct ecore_vf_info *vf,
948 struct ecore_igu_block *p_block;
949 struct cau_sb_entry sb_entry;
953 if (num_rx_queues > p_hwfn->hw_info.p_igu_info->usage.free_cnt_iov)
955 (u16)p_hwfn->hw_info.p_igu_info->usage.free_cnt_iov;
956 p_hwfn->hw_info.p_igu_info->usage.free_cnt_iov -= num_rx_queues;
958 SET_FIELD(val, IGU_MAPPING_LINE_FUNCTION_NUMBER, vf->abs_vf_id);
959 SET_FIELD(val, IGU_MAPPING_LINE_VALID, 1);
960 SET_FIELD(val, IGU_MAPPING_LINE_PF_VALID, 0);
962 for (qid = 0; qid < num_rx_queues; qid++) {
963 p_block = ecore_get_igu_free_sb(p_hwfn, false);
964 vf->igu_sbs[qid] = p_block->igu_sb_id;
965 p_block->status &= ~ECORE_IGU_STATUS_FREE;
966 SET_FIELD(val, IGU_MAPPING_LINE_VECTOR_NUMBER, qid);
968 ecore_wr(p_hwfn, p_ptt,
969 IGU_REG_MAPPING_MEMORY +
970 sizeof(u32) * p_block->igu_sb_id, val);
972 /* Configure igu sb in CAU which were marked valid */
973 ecore_init_cau_sb_entry(p_hwfn, &sb_entry,
976 ecore_dmae_host2grc(p_hwfn, p_ptt,
977 (u64)(osal_uintptr_t)&sb_entry,
978 CAU_REG_SB_VAR_MEMORY +
979 p_block->igu_sb_id * sizeof(u64), 2, 0);
982 vf->num_sbs = (u8)num_rx_queues;
989 * @brief The function invalidates all the VF entries,
990 * technically this isn't required, but added for
991 * cleaness and ease of debugging incase a VF attempts to
992 * produce an interrupt after it has been taken down.
998 static void ecore_iov_free_vf_igu_sbs(struct ecore_hwfn *p_hwfn,
999 struct ecore_ptt *p_ptt,
1000 struct ecore_vf_info *vf)
1002 struct ecore_igu_info *p_info = p_hwfn->hw_info.p_igu_info;
1006 /* Invalidate igu CAM lines and mark them as free */
1007 for (idx = 0; idx < vf->num_sbs; idx++) {
1008 igu_id = vf->igu_sbs[idx];
1009 addr = IGU_REG_MAPPING_MEMORY + sizeof(u32) * igu_id;
1011 val = ecore_rd(p_hwfn, p_ptt, addr);
1012 SET_FIELD(val, IGU_MAPPING_LINE_VALID, 0);
1013 ecore_wr(p_hwfn, p_ptt, addr, val);
1015 p_info->entry[igu_id].status |= ECORE_IGU_STATUS_FREE;
1016 p_hwfn->hw_info.p_igu_info->usage.free_cnt_iov++;
1022 void ecore_iov_set_link(struct ecore_hwfn *p_hwfn,
1024 struct ecore_mcp_link_params *params,
1025 struct ecore_mcp_link_state *link,
1026 struct ecore_mcp_link_capabilities *p_caps)
1028 struct ecore_vf_info *p_vf = ecore_iov_get_vf_info(p_hwfn, vfid, false);
1029 struct ecore_bulletin_content *p_bulletin;
1034 p_bulletin = p_vf->bulletin.p_virt;
1035 p_bulletin->req_autoneg = params->speed.autoneg;
1036 p_bulletin->req_adv_speed = params->speed.advertised_speeds;
1037 p_bulletin->req_forced_speed = params->speed.forced_speed;
1038 p_bulletin->req_autoneg_pause = params->pause.autoneg;
1039 p_bulletin->req_forced_rx = params->pause.forced_rx;
1040 p_bulletin->req_forced_tx = params->pause.forced_tx;
1041 p_bulletin->req_loopback = params->loopback_mode;
1043 p_bulletin->link_up = link->link_up;
1044 p_bulletin->speed = link->speed;
1045 p_bulletin->full_duplex = link->full_duplex;
1046 p_bulletin->autoneg = link->an;
1047 p_bulletin->autoneg_complete = link->an_complete;
1048 p_bulletin->parallel_detection = link->parallel_detection;
1049 p_bulletin->pfc_enabled = link->pfc_enabled;
1050 p_bulletin->partner_adv_speed = link->partner_adv_speed;
1051 p_bulletin->partner_tx_flow_ctrl_en = link->partner_tx_flow_ctrl_en;
1052 p_bulletin->partner_rx_flow_ctrl_en = link->partner_rx_flow_ctrl_en;
1053 p_bulletin->partner_adv_pause = link->partner_adv_pause;
1054 p_bulletin->sfp_tx_fault = link->sfp_tx_fault;
1056 p_bulletin->capability_speed = p_caps->speed_capabilities;
1059 enum _ecore_status_t
1060 ecore_iov_init_hw_for_vf(struct ecore_hwfn *p_hwfn,
1061 struct ecore_ptt *p_ptt,
1062 struct ecore_iov_vf_init_params *p_params)
1064 struct ecore_mcp_link_capabilities link_caps;
1065 struct ecore_mcp_link_params link_params;
1066 struct ecore_mcp_link_state link_state;
1067 u8 num_of_vf_available_chains = 0;
1068 struct ecore_vf_info *vf = OSAL_NULL;
1070 enum _ecore_status_t rc = ECORE_SUCCESS;
1074 vf = ecore_iov_get_vf_info(p_hwfn, p_params->rel_vf_id, false);
1076 DP_ERR(p_hwfn, "ecore_iov_init_hw_for_vf : vf is OSAL_NULL\n");
1077 return ECORE_UNKNOWN_ERROR;
1081 DP_NOTICE(p_hwfn, true, "VF[%d] is already active.\n",
1082 p_params->rel_vf_id);
1086 /* Perform sanity checking on the requested vport/rss */
1087 if (p_params->vport_id >= RESC_NUM(p_hwfn, ECORE_VPORT)) {
1088 DP_NOTICE(p_hwfn, true, "VF[%d] - can't use VPORT %02x\n",
1089 p_params->rel_vf_id, p_params->vport_id);
1093 if ((p_params->num_queues > 1) &&
1094 (p_params->rss_eng_id >= RESC_NUM(p_hwfn, ECORE_RSS_ENG))) {
1095 DP_NOTICE(p_hwfn, true, "VF[%d] - can't use RSS_ENG %02x\n",
1096 p_params->rel_vf_id, p_params->rss_eng_id);
1100 /* TODO - remove this once we get confidence of change */
1101 if (!p_params->vport_id) {
1102 DP_NOTICE(p_hwfn, false,
1103 "VF[%d] - Unlikely that VF uses vport0. Forgotten?\n",
1104 p_params->rel_vf_id);
1106 if ((!p_params->rss_eng_id) && (p_params->num_queues > 1)) {
1107 DP_NOTICE(p_hwfn, false,
1108 "VF[%d] - Unlikely that VF uses RSS_eng0. Forgotten?\n",
1109 p_params->rel_vf_id);
1111 vf->vport_id = p_params->vport_id;
1112 vf->rss_eng_id = p_params->rss_eng_id;
1114 /* Since it's possible to relocate SBs, it's a bit difficult to check
1115 * things here. Simply check whether the index falls in the range
1116 * belonging to the PF.
1118 for (i = 0; i < p_params->num_queues; i++) {
1119 qid = p_params->req_rx_queue[i];
1120 if (qid > (u16)RESC_NUM(p_hwfn, ECORE_L2_QUEUE)) {
1121 DP_NOTICE(p_hwfn, true,
1122 "Can't enable Rx qid [%04x] for VF[%d]: qids [0,,...,0x%04x] available\n",
1123 qid, p_params->rel_vf_id,
1124 (u16)RESC_NUM(p_hwfn, ECORE_L2_QUEUE));
1128 qid = p_params->req_tx_queue[i];
1129 if (qid > (u16)RESC_NUM(p_hwfn, ECORE_L2_QUEUE)) {
1130 DP_NOTICE(p_hwfn, true,
1131 "Can't enable Tx qid [%04x] for VF[%d]: qids [0,,...,0x%04x] available\n",
1132 qid, p_params->rel_vf_id,
1133 (u16)RESC_NUM(p_hwfn, ECORE_L2_QUEUE));
1138 /* Limit number of queues according to number of CIDs */
1139 ecore_cxt_get_proto_cid_count(p_hwfn, PROTOCOLID_ETH, &cids);
1140 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1141 "VF[%d] - requesting to initialize for 0x%04x queues"
1142 " [0x%04x CIDs available]\n",
1143 vf->relative_vf_id, p_params->num_queues, (u16)cids);
1144 num_irqs = OSAL_MIN_T(u16, p_params->num_queues, ((u16)cids));
1146 num_of_vf_available_chains = ecore_iov_alloc_vf_igu_sbs(p_hwfn,
1150 if (num_of_vf_available_chains == 0) {
1151 DP_ERR(p_hwfn, "no available igu sbs\n");
1155 /* Choose queue number and index ranges */
1156 vf->num_rxqs = num_of_vf_available_chains;
1157 vf->num_txqs = num_of_vf_available_chains;
1159 for (i = 0; i < vf->num_rxqs; i++) {
1160 struct ecore_vf_queue *p_queue = &vf->vf_queues[i];
1162 p_queue->fw_rx_qid = p_params->req_rx_queue[i];
1163 p_queue->fw_tx_qid = p_params->req_tx_queue[i];
1165 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1166 "VF[%d] - Q[%d] SB %04x, qid [Rx %04x Tx %04x]\n",
1167 vf->relative_vf_id, i, vf->igu_sbs[i],
1168 p_queue->fw_rx_qid, p_queue->fw_tx_qid);
1171 /* Update the link configuration in bulletin.
1173 OSAL_MEMCPY(&link_params, ecore_mcp_get_link_params(p_hwfn),
1174 sizeof(link_params));
1175 OSAL_MEMCPY(&link_state, ecore_mcp_get_link_state(p_hwfn),
1176 sizeof(link_state));
1177 OSAL_MEMCPY(&link_caps, ecore_mcp_get_link_capabilities(p_hwfn),
1179 ecore_iov_set_link(p_hwfn, p_params->rel_vf_id,
1180 &link_params, &link_state, &link_caps);
1182 rc = ecore_iov_enable_vf_access(p_hwfn, p_ptt, vf);
1184 if (rc == ECORE_SUCCESS) {
1186 p_hwfn->pf_iov_info->active_vfs[vf->relative_vf_id / 64] |=
1187 (1ULL << (vf->relative_vf_id % 64));
1189 if (IS_LEAD_HWFN(p_hwfn))
1190 p_hwfn->p_dev->p_iov_info->num_vfs++;
1196 enum _ecore_status_t ecore_iov_release_hw_for_vf(struct ecore_hwfn *p_hwfn,
1197 struct ecore_ptt *p_ptt,
1200 struct ecore_mcp_link_capabilities caps;
1201 struct ecore_mcp_link_params params;
1202 struct ecore_mcp_link_state link;
1203 struct ecore_vf_info *vf = OSAL_NULL;
1205 vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
1207 DP_ERR(p_hwfn, "ecore_iov_release_hw_for_vf : vf is NULL\n");
1208 return ECORE_UNKNOWN_ERROR;
1211 if (vf->bulletin.p_virt)
1212 OSAL_MEMSET(vf->bulletin.p_virt, 0,
1213 sizeof(*vf->bulletin.p_virt));
1215 OSAL_MEMSET(&vf->p_vf_info, 0, sizeof(vf->p_vf_info));
1217 /* Get the link configuration back in bulletin so
1218 * that when VFs are re-enabled they get the actual
1219 * link configuration.
1221 OSAL_MEMCPY(¶ms, ecore_mcp_get_link_params(p_hwfn), sizeof(params));
1222 OSAL_MEMCPY(&link, ecore_mcp_get_link_state(p_hwfn), sizeof(link));
1223 OSAL_MEMCPY(&caps, ecore_mcp_get_link_capabilities(p_hwfn),
1225 ecore_iov_set_link(p_hwfn, rel_vf_id, ¶ms, &link, &caps);
1227 /* Forget the VF's acquisition message */
1228 OSAL_MEMSET(&vf->acquire, 0, sizeof(vf->acquire));
1230 /* disablng interrupts and resetting permission table was done during
1231 * vf-close, however, we could get here without going through vf_close
1233 /* Disable Interrupts for VF */
1234 ecore_iov_vf_igu_set_int(p_hwfn, p_ptt, vf, 0);
1236 /* Reset Permission table */
1237 ecore_iov_config_perm_table(p_hwfn, p_ptt, vf, 0);
1241 ecore_iov_free_vf_igu_sbs(p_hwfn, p_ptt, vf);
1245 p_hwfn->pf_iov_info->active_vfs[vf->relative_vf_id / 64] &=
1246 ~(1ULL << (vf->relative_vf_id / 64));
1248 if (IS_LEAD_HWFN(p_hwfn))
1249 p_hwfn->p_dev->p_iov_info->num_vfs--;
1252 return ECORE_SUCCESS;
1255 static bool ecore_iov_tlv_supported(u16 tlvtype)
1257 return tlvtype > CHANNEL_TLV_NONE && tlvtype < CHANNEL_TLV_MAX;
1260 static void ecore_iov_lock_vf_pf_channel(struct ecore_hwfn *p_hwfn,
1261 struct ecore_vf_info *vf, u16 tlv)
1263 /* lock the channel */
1264 /* mutex_lock(&vf->op_mutex); @@@TBD MichalK - add lock... */
1266 /* record the locking op */
1267 /* vf->op_current = tlv; @@@TBD MichalK */
1270 if (ecore_iov_tlv_supported(tlv))
1273 "VF[%d]: vf pf channel locked by %s\n",
1275 ecore_channel_tlvs_string[tlv]);
1279 "VF[%d]: vf pf channel locked by %04x\n",
1280 vf->abs_vf_id, tlv);
1283 static void ecore_iov_unlock_vf_pf_channel(struct ecore_hwfn *p_hwfn,
1284 struct ecore_vf_info *vf,
1287 /* log the unlock */
1288 if (ecore_iov_tlv_supported(expected_tlv))
1291 "VF[%d]: vf pf channel unlocked by %s\n",
1293 ecore_channel_tlvs_string[expected_tlv]);
1297 "VF[%d]: vf pf channel unlocked by %04x\n",
1298 vf->abs_vf_id, expected_tlv);
1300 /* record the locking op */
1301 /* vf->op_current = CHANNEL_TLV_NONE; */
1304 /* place a given tlv on the tlv buffer, continuing current tlv list */
1305 void *ecore_add_tlv(struct ecore_hwfn *p_hwfn,
1306 u8 **offset, u16 type, u16 length)
1308 struct channel_tlv *tl = (struct channel_tlv *)*offset;
1311 tl->length = length;
1313 /* Offset should keep pointing to next TLV (the end of the last) */
1316 /* Return a pointer to the start of the added tlv */
1317 return *offset - length;
1320 /* list the types and lengths of the tlvs on the buffer */
1321 void ecore_dp_tlv_list(struct ecore_hwfn *p_hwfn, void *tlvs_list)
1323 u16 i = 1, total_length = 0;
1324 struct channel_tlv *tlv;
1327 /* cast current tlv list entry to channel tlv header */
1328 tlv = (struct channel_tlv *)((u8 *)tlvs_list + total_length);
1331 if (ecore_iov_tlv_supported(tlv->type))
1332 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1333 "TLV number %d: type %s, length %d\n",
1334 i, ecore_channel_tlvs_string[tlv->type],
1337 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1338 "TLV number %d: type %d, length %d\n",
1339 i, tlv->type, tlv->length);
1341 if (tlv->type == CHANNEL_TLV_LIST_END)
1344 /* Validate entry - protect against malicious VFs */
1346 DP_NOTICE(p_hwfn, false, "TLV of length 0 found\n");
1349 total_length += tlv->length;
1350 if (total_length >= sizeof(struct tlv_buffer_size)) {
1351 DP_NOTICE(p_hwfn, false, "TLV ==> Buffer overflow\n");
1359 static void ecore_iov_send_response(struct ecore_hwfn *p_hwfn,
1360 struct ecore_ptt *p_ptt,
1361 struct ecore_vf_info *p_vf,
1362 u16 length, u8 status)
1364 struct ecore_iov_vf_mbx *mbx = &p_vf->vf_mbx;
1365 struct ecore_dmae_params params;
1368 mbx->reply_virt->default_resp.hdr.status = status;
1370 ecore_dp_tlv_list(p_hwfn, mbx->reply_virt);
1372 #ifdef CONFIG_ECORE_SW_CHANNEL
1373 mbx->sw_mbx.response_size =
1374 length + sizeof(struct channel_list_end_tlv);
1376 if (!p_hwfn->p_dev->b_hw_channel)
1380 eng_vf_id = p_vf->abs_vf_id;
1382 OSAL_MEMSET(¶ms, 0, sizeof(struct ecore_dmae_params));
1383 params.flags = ECORE_DMAE_FLAG_VF_DST;
1384 params.dst_vfid = eng_vf_id;
1386 ecore_dmae_host2host(p_hwfn, p_ptt, mbx->reply_phys + sizeof(u64),
1387 mbx->req_virt->first_tlv.reply_address +
1389 (sizeof(union pfvf_tlvs) - sizeof(u64)) / 4,
1392 ecore_dmae_host2host(p_hwfn, p_ptt, mbx->reply_phys,
1393 mbx->req_virt->first_tlv.reply_address,
1394 sizeof(u64) / 4, ¶ms);
1397 GTT_BAR0_MAP_REG_USDM_RAM +
1398 USTORM_VF_PF_CHANNEL_READY_OFFSET(eng_vf_id), 1);
1401 static u16 ecore_iov_vport_to_tlv(struct ecore_hwfn *p_hwfn,
1402 enum ecore_iov_vport_update_flag flag)
1405 case ECORE_IOV_VP_UPDATE_ACTIVATE:
1406 return CHANNEL_TLV_VPORT_UPDATE_ACTIVATE;
1407 case ECORE_IOV_VP_UPDATE_VLAN_STRIP:
1408 return CHANNEL_TLV_VPORT_UPDATE_VLAN_STRIP;
1409 case ECORE_IOV_VP_UPDATE_TX_SWITCH:
1410 return CHANNEL_TLV_VPORT_UPDATE_TX_SWITCH;
1411 case ECORE_IOV_VP_UPDATE_MCAST:
1412 return CHANNEL_TLV_VPORT_UPDATE_MCAST;
1413 case ECORE_IOV_VP_UPDATE_ACCEPT_PARAM:
1414 return CHANNEL_TLV_VPORT_UPDATE_ACCEPT_PARAM;
1415 case ECORE_IOV_VP_UPDATE_RSS:
1416 return CHANNEL_TLV_VPORT_UPDATE_RSS;
1417 case ECORE_IOV_VP_UPDATE_ACCEPT_ANY_VLAN:
1418 return CHANNEL_TLV_VPORT_UPDATE_ACCEPT_ANY_VLAN;
1419 case ECORE_IOV_VP_UPDATE_SGE_TPA:
1420 return CHANNEL_TLV_VPORT_UPDATE_SGE_TPA;
1426 static u16 ecore_iov_prep_vp_update_resp_tlvs(struct ecore_hwfn *p_hwfn,
1427 struct ecore_vf_info *p_vf,
1428 struct ecore_iov_vf_mbx *p_mbx,
1429 u8 status, u16 tlvs_mask,
1432 struct pfvf_def_resp_tlv *resp;
1433 u16 size, total_len, i;
1435 OSAL_MEMSET(p_mbx->reply_virt, 0, sizeof(union pfvf_tlvs));
1436 p_mbx->offset = (u8 *)p_mbx->reply_virt;
1437 size = sizeof(struct pfvf_def_resp_tlv);
1440 ecore_add_tlv(p_hwfn, &p_mbx->offset, CHANNEL_TLV_VPORT_UPDATE, size);
1442 /* Prepare response for all extended tlvs if they are found by PF */
1443 for (i = 0; i < ECORE_IOV_VP_UPDATE_MAX; i++) {
1444 if (!(tlvs_mask & (1 << i)))
1447 resp = ecore_add_tlv(p_hwfn, &p_mbx->offset,
1448 ecore_iov_vport_to_tlv(p_hwfn, i), size);
1450 if (tlvs_accepted & (1 << i))
1451 resp->hdr.status = status;
1453 resp->hdr.status = PFVF_STATUS_NOT_SUPPORTED;
1455 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1456 "VF[%d] - vport_update resp: TLV %d, status %02x\n",
1457 p_vf->relative_vf_id,
1458 ecore_iov_vport_to_tlv(p_hwfn, i), resp->hdr.status);
1463 ecore_add_tlv(p_hwfn, &p_mbx->offset, CHANNEL_TLV_LIST_END,
1464 sizeof(struct channel_list_end_tlv));
1469 static void ecore_iov_prepare_resp(struct ecore_hwfn *p_hwfn,
1470 struct ecore_ptt *p_ptt,
1471 struct ecore_vf_info *vf_info,
1472 u16 type, u16 length, u8 status)
1474 struct ecore_iov_vf_mbx *mbx = &vf_info->vf_mbx;
1476 mbx->offset = (u8 *)mbx->reply_virt;
1478 ecore_add_tlv(p_hwfn, &mbx->offset, type, length);
1479 ecore_add_tlv(p_hwfn, &mbx->offset, CHANNEL_TLV_LIST_END,
1480 sizeof(struct channel_list_end_tlv));
1482 ecore_iov_send_response(p_hwfn, p_ptt, vf_info, length, status);
1484 OSAL_IOV_PF_RESP_TYPE(p_hwfn, vf_info->relative_vf_id, status);
1487 struct ecore_public_vf_info
1488 *ecore_iov_get_public_vf_info(struct ecore_hwfn *p_hwfn,
1490 bool b_enabled_only)
1492 struct ecore_vf_info *vf = OSAL_NULL;
1494 vf = ecore_iov_get_vf_info(p_hwfn, relative_vf_id, b_enabled_only);
1498 return &vf->p_vf_info;
1501 static void ecore_iov_vf_cleanup(struct ecore_hwfn *p_hwfn,
1502 struct ecore_vf_info *p_vf)
1505 p_vf->vf_bulletin = 0;
1506 p_vf->vport_instance = 0;
1507 p_vf->configured_features = 0;
1509 /* If VF previously requested less resources, go back to default */
1510 p_vf->num_rxqs = p_vf->num_sbs;
1511 p_vf->num_txqs = p_vf->num_sbs;
1513 p_vf->num_active_rxqs = 0;
1515 for (i = 0; i < ECORE_MAX_VF_CHAINS_PER_PF; i++) {
1516 struct ecore_vf_queue *p_queue = &p_vf->vf_queues[i];
1518 for (j = 0; j < MAX_QUEUES_PER_QZONE; j++) {
1519 if (!p_queue->cids[j].p_cid)
1522 ecore_eth_queue_cid_release(p_hwfn,
1523 p_queue->cids[j].p_cid);
1524 p_queue->cids[j].p_cid = OSAL_NULL;
1528 OSAL_MEMSET(&p_vf->shadow_config, 0, sizeof(p_vf->shadow_config));
1529 OSAL_MEMSET(&p_vf->acquire, 0, sizeof(p_vf->acquire));
1530 OSAL_IOV_VF_CLEANUP(p_hwfn, p_vf->relative_vf_id);
1533 static u8 ecore_iov_vf_mbx_acquire_resc(struct ecore_hwfn *p_hwfn,
1534 struct ecore_ptt *p_ptt,
1535 struct ecore_vf_info *p_vf,
1536 struct vf_pf_resc_request *p_req,
1537 struct pf_vf_resc *p_resp)
1541 /* Queue related information */
1542 p_resp->num_rxqs = p_vf->num_rxqs;
1543 p_resp->num_txqs = p_vf->num_txqs;
1544 p_resp->num_sbs = p_vf->num_sbs;
1546 for (i = 0; i < p_resp->num_sbs; i++) {
1547 p_resp->hw_sbs[i].hw_sb_id = p_vf->igu_sbs[i];
1548 /* TODO - what's this sb_qid field? Is it deprecated?
1549 * or is there an ecore_client that looks at this?
1551 p_resp->hw_sbs[i].sb_qid = 0;
1554 /* These fields are filled for backward compatibility.
1555 * Unused by modern vfs.
1557 for (i = 0; i < p_resp->num_rxqs; i++) {
1558 ecore_fw_l2_queue(p_hwfn, p_vf->vf_queues[i].fw_rx_qid,
1559 (u16 *)&p_resp->hw_qid[i]);
1563 /* Filter related information */
1564 p_resp->num_mac_filters = OSAL_MIN_T(u8, p_vf->num_mac_filters,
1565 p_req->num_mac_filters);
1566 p_resp->num_vlan_filters = OSAL_MIN_T(u8, p_vf->num_vlan_filters,
1567 p_req->num_vlan_filters);
1570 OSAL_MIN_T(u8, p_req->num_cids,
1571 p_hwfn->pf_params.eth_pf_params.num_vf_cons);
1573 /* This isn't really needed/enforced, but some legacy VFs might depend
1574 * on the correct filling of this field.
1576 p_resp->num_mc_filters = ECORE_MAX_MC_ADDRS;
1578 /* Validate sufficient resources for VF */
1579 if (p_resp->num_rxqs < p_req->num_rxqs ||
1580 p_resp->num_txqs < p_req->num_txqs ||
1581 p_resp->num_sbs < p_req->num_sbs ||
1582 p_resp->num_mac_filters < p_req->num_mac_filters ||
1583 p_resp->num_vlan_filters < p_req->num_vlan_filters ||
1584 p_resp->num_mc_filters < p_req->num_mc_filters ||
1585 p_resp->num_cids < p_req->num_cids) {
1586 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1587 "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",
1589 p_req->num_rxqs, p_resp->num_rxqs,
1590 p_req->num_rxqs, p_resp->num_txqs,
1591 p_req->num_sbs, p_resp->num_sbs,
1592 p_req->num_mac_filters, p_resp->num_mac_filters,
1593 p_req->num_vlan_filters, p_resp->num_vlan_filters,
1594 p_req->num_mc_filters, p_resp->num_mc_filters,
1595 p_req->num_cids, p_resp->num_cids);
1597 /* Some legacy OSes are incapable of correctly handling this
1600 if ((p_vf->acquire.vfdev_info.eth_fp_hsi_minor ==
1601 ETH_HSI_VER_NO_PKT_LEN_TUNN) &&
1602 (p_vf->acquire.vfdev_info.os_type ==
1603 VFPF_ACQUIRE_OS_WINDOWS))
1604 return PFVF_STATUS_SUCCESS;
1606 return PFVF_STATUS_NO_RESOURCE;
1609 return PFVF_STATUS_SUCCESS;
1612 static void ecore_iov_vf_mbx_acquire_stats(struct ecore_hwfn *p_hwfn,
1613 struct pfvf_stats_info *p_stats)
1615 p_stats->mstats.address = PXP_VF_BAR0_START_MSDM_ZONE_B +
1616 OFFSETOF(struct mstorm_vf_zone,
1617 non_trigger.eth_queue_stat);
1618 p_stats->mstats.len = sizeof(struct eth_mstorm_per_queue_stat);
1619 p_stats->ustats.address = PXP_VF_BAR0_START_USDM_ZONE_B +
1620 OFFSETOF(struct ustorm_vf_zone,
1621 non_trigger.eth_queue_stat);
1622 p_stats->ustats.len = sizeof(struct eth_ustorm_per_queue_stat);
1623 p_stats->pstats.address = PXP_VF_BAR0_START_PSDM_ZONE_B +
1624 OFFSETOF(struct pstorm_vf_zone,
1625 non_trigger.eth_queue_stat);
1626 p_stats->pstats.len = sizeof(struct eth_pstorm_per_queue_stat);
1627 p_stats->tstats.address = 0;
1628 p_stats->tstats.len = 0;
1631 static void ecore_iov_vf_mbx_acquire(struct ecore_hwfn *p_hwfn,
1632 struct ecore_ptt *p_ptt,
1633 struct ecore_vf_info *vf)
1635 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
1636 struct pfvf_acquire_resp_tlv *resp = &mbx->reply_virt->acquire_resp;
1637 struct pf_vf_pfdev_info *pfdev_info = &resp->pfdev_info;
1638 struct vfpf_acquire_tlv *req = &mbx->req_virt->acquire;
1639 u8 vfpf_status = PFVF_STATUS_NOT_SUPPORTED;
1640 struct pf_vf_resc *resc = &resp->resc;
1641 enum _ecore_status_t rc;
1643 OSAL_MEMSET(resp, 0, sizeof(*resp));
1645 /* Write the PF version so that VF would know which version
1646 * is supported - might be later overridden. This guarantees that
1647 * VF could recognize legacy PF based on lack of versions in reply.
1649 pfdev_info->major_fp_hsi = ETH_HSI_VER_MAJOR;
1650 pfdev_info->minor_fp_hsi = ETH_HSI_VER_MINOR;
1652 /* TODO - not doing anything is bad since we'll assert, but this isn't
1653 * necessarily the right behavior - perhaps we should have allowed some
1656 if (vf->state != VF_FREE &&
1657 vf->state != VF_STOPPED) {
1658 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1659 "VF[%d] sent ACQUIRE but is already in state %d - fail request\n",
1660 vf->abs_vf_id, vf->state);
1664 /* Validate FW compatibility */
1665 if (req->vfdev_info.eth_fp_hsi_major != ETH_HSI_VER_MAJOR) {
1666 if (req->vfdev_info.capabilities &
1667 VFPF_ACQUIRE_CAP_PRE_FP_HSI) {
1668 struct vf_pf_vfdev_info *p_vfdev = &req->vfdev_info;
1670 /* This legacy support would need to be removed once
1671 * the major has changed.
1673 OSAL_BUILD_BUG_ON(ETH_HSI_VER_MAJOR != 3);
1675 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1676 "VF[%d] is pre-fastpath HSI\n",
1678 p_vfdev->eth_fp_hsi_major = ETH_HSI_VER_MAJOR;
1679 p_vfdev->eth_fp_hsi_minor = ETH_HSI_VER_NO_PKT_LEN_TUNN;
1682 "VF[%d] needs fastpath HSI %02x.%02x, which is"
1683 " incompatible with loaded FW's faspath"
1686 req->vfdev_info.eth_fp_hsi_major,
1687 req->vfdev_info.eth_fp_hsi_minor,
1688 ETH_HSI_VER_MAJOR, ETH_HSI_VER_MINOR);
1694 /* On 100g PFs, prevent old VFs from loading */
1695 if ((p_hwfn->p_dev->num_hwfns > 1) &&
1696 !(req->vfdev_info.capabilities & VFPF_ACQUIRE_CAP_100G)) {
1698 "VF[%d] is running an old driver that doesn't support"
1704 #ifndef __EXTRACT__LINUX__
1705 if (OSAL_IOV_VF_ACQUIRE(p_hwfn, vf->relative_vf_id) != ECORE_SUCCESS) {
1706 vfpf_status = PFVF_STATUS_NOT_SUPPORTED;
1711 /* Store the acquire message */
1712 OSAL_MEMCPY(&vf->acquire, req, sizeof(vf->acquire));
1714 vf->opaque_fid = req->vfdev_info.opaque_fid;
1716 vf->vf_bulletin = req->bulletin_addr;
1717 vf->bulletin.size = (vf->bulletin.size < req->bulletin_size) ?
1718 vf->bulletin.size : req->bulletin_size;
1720 /* fill in pfdev info */
1721 pfdev_info->chip_num = p_hwfn->p_dev->chip_num;
1722 pfdev_info->db_size = 0; /* @@@ TBD MichalK Vf Doorbells */
1723 pfdev_info->indices_per_sb = PIS_PER_SB;
1725 pfdev_info->capabilities = PFVF_ACQUIRE_CAP_DEFAULT_UNTAGGED |
1726 PFVF_ACQUIRE_CAP_POST_FW_OVERRIDE;
1727 if (p_hwfn->p_dev->num_hwfns > 1)
1728 pfdev_info->capabilities |= PFVF_ACQUIRE_CAP_100G;
1730 /* Share our ability to use multiple queue-ids only with VFs
1733 if (req->vfdev_info.capabilities & VFPF_ACQUIRE_CAP_QUEUE_QIDS)
1734 pfdev_info->capabilities |= PFVF_ACQUIRE_CAP_QUEUE_QIDS;
1736 ecore_iov_vf_mbx_acquire_stats(p_hwfn, &pfdev_info->stats_info);
1738 OSAL_MEMCPY(pfdev_info->port_mac, p_hwfn->hw_info.hw_mac_addr,
1741 pfdev_info->fw_major = FW_MAJOR_VERSION;
1742 pfdev_info->fw_minor = FW_MINOR_VERSION;
1743 pfdev_info->fw_rev = FW_REVISION_VERSION;
1744 pfdev_info->fw_eng = FW_ENGINEERING_VERSION;
1746 /* Incorrect when legacy, but doesn't matter as legacy isn't reading
1749 pfdev_info->minor_fp_hsi = OSAL_MIN_T(u8, ETH_HSI_VER_MINOR,
1750 req->vfdev_info.eth_fp_hsi_minor);
1751 pfdev_info->os_type = OSAL_IOV_GET_OS_TYPE();
1752 ecore_mcp_get_mfw_ver(p_hwfn, p_ptt, &pfdev_info->mfw_ver,
1755 pfdev_info->dev_type = p_hwfn->p_dev->type;
1756 pfdev_info->chip_rev = p_hwfn->p_dev->chip_rev;
1758 /* Fill resources available to VF; Make sure there are enough to
1759 * satisfy the VF's request.
1761 vfpf_status = ecore_iov_vf_mbx_acquire_resc(p_hwfn, p_ptt, vf,
1762 &req->resc_request, resc);
1763 if (vfpf_status != PFVF_STATUS_SUCCESS)
1766 /* Start the VF in FW */
1767 rc = ecore_sp_vf_start(p_hwfn, vf);
1768 if (rc != ECORE_SUCCESS) {
1769 DP_NOTICE(p_hwfn, true, "Failed to start VF[%02x]\n",
1771 vfpf_status = PFVF_STATUS_FAILURE;
1775 /* Fill agreed size of bulletin board in response, and post
1776 * an initial image to the bulletin board.
1778 resp->bulletin_size = vf->bulletin.size;
1779 ecore_iov_post_vf_bulletin(p_hwfn, vf->relative_vf_id, p_ptt);
1781 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1782 "VF[%d] ACQUIRE_RESPONSE: pfdev_info- chip_num=0x%x,"
1783 " db_size=%d, idx_per_sb=%d, pf_cap=0x%lx\n"
1784 "resources- n_rxq-%d, n_txq-%d, n_sbs-%d, n_macs-%d,"
1786 vf->abs_vf_id, resp->pfdev_info.chip_num,
1787 resp->pfdev_info.db_size, resp->pfdev_info.indices_per_sb,
1788 (unsigned long)resp->pfdev_info.capabilities, resc->num_rxqs,
1789 resc->num_txqs, resc->num_sbs, resc->num_mac_filters,
1790 resc->num_vlan_filters);
1792 vf->state = VF_ACQUIRED;
1795 /* Prepare Response */
1796 ecore_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_ACQUIRE,
1797 sizeof(struct pfvf_acquire_resp_tlv),
1801 static enum _ecore_status_t
1802 __ecore_iov_spoofchk_set(struct ecore_hwfn *p_hwfn,
1803 struct ecore_vf_info *p_vf, bool val)
1805 struct ecore_sp_vport_update_params params;
1806 enum _ecore_status_t rc;
1808 if (val == p_vf->spoof_chk) {
1809 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1810 "Spoofchk value[%d] is already configured\n", val);
1811 return ECORE_SUCCESS;
1814 OSAL_MEMSET(¶ms, 0, sizeof(struct ecore_sp_vport_update_params));
1815 params.opaque_fid = p_vf->opaque_fid;
1816 params.vport_id = p_vf->vport_id;
1817 params.update_anti_spoofing_en_flg = 1;
1818 params.anti_spoofing_en = val;
1820 rc = ecore_sp_vport_update(p_hwfn, ¶ms, ECORE_SPQ_MODE_EBLOCK,
1822 if (rc == ECORE_SUCCESS) {
1823 p_vf->spoof_chk = val;
1824 p_vf->req_spoofchk_val = p_vf->spoof_chk;
1825 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1826 "Spoofchk val[%d] configured\n", val);
1828 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1829 "Spoofchk configuration[val:%d] failed for VF[%d]\n",
1830 val, p_vf->relative_vf_id);
1836 static enum _ecore_status_t
1837 ecore_iov_reconfigure_unicast_vlan(struct ecore_hwfn *p_hwfn,
1838 struct ecore_vf_info *p_vf)
1840 struct ecore_filter_ucast filter;
1841 enum _ecore_status_t rc = ECORE_SUCCESS;
1844 OSAL_MEMSET(&filter, 0, sizeof(filter));
1845 filter.is_rx_filter = 1;
1846 filter.is_tx_filter = 1;
1847 filter.vport_to_add_to = p_vf->vport_id;
1848 filter.opcode = ECORE_FILTER_ADD;
1850 /* Reconfigure vlans */
1851 for (i = 0; i < ECORE_ETH_VF_NUM_VLAN_FILTERS + 1; i++) {
1852 if (!p_vf->shadow_config.vlans[i].used)
1855 filter.type = ECORE_FILTER_VLAN;
1856 filter.vlan = p_vf->shadow_config.vlans[i].vid;
1857 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1858 "Reconfiguring VLAN [0x%04x] for VF [%04x]\n",
1859 filter.vlan, p_vf->relative_vf_id);
1860 rc = ecore_sp_eth_filter_ucast(p_hwfn, p_vf->opaque_fid,
1861 &filter, ECORE_SPQ_MODE_CB,
1864 DP_NOTICE(p_hwfn, true,
1865 "Failed to configure VLAN [%04x]"
1867 filter.vlan, p_vf->relative_vf_id);
1875 static enum _ecore_status_t
1876 ecore_iov_reconfigure_unicast_shadow(struct ecore_hwfn *p_hwfn,
1877 struct ecore_vf_info *p_vf, u64 events)
1879 enum _ecore_status_t rc = ECORE_SUCCESS;
1881 /*TODO - what about MACs? */
1883 if ((events & (1 << VLAN_ADDR_FORCED)) &&
1884 !(p_vf->configured_features & (1 << VLAN_ADDR_FORCED)))
1885 rc = ecore_iov_reconfigure_unicast_vlan(p_hwfn, p_vf);
1890 static enum _ecore_status_t
1891 ecore_iov_configure_vport_forced(struct ecore_hwfn *p_hwfn,
1892 struct ecore_vf_info *p_vf,
1895 enum _ecore_status_t rc = ECORE_SUCCESS;
1896 struct ecore_filter_ucast filter;
1898 if (!p_vf->vport_instance)
1901 if (events & (1 << MAC_ADDR_FORCED)) {
1902 /* Since there's no way [currently] of removing the MAC,
1903 * we can always assume this means we need to force it.
1905 OSAL_MEMSET(&filter, 0, sizeof(filter));
1906 filter.type = ECORE_FILTER_MAC;
1907 filter.opcode = ECORE_FILTER_REPLACE;
1908 filter.is_rx_filter = 1;
1909 filter.is_tx_filter = 1;
1910 filter.vport_to_add_to = p_vf->vport_id;
1911 OSAL_MEMCPY(filter.mac, p_vf->bulletin.p_virt->mac, ETH_ALEN);
1913 rc = ecore_sp_eth_filter_ucast(p_hwfn, p_vf->opaque_fid,
1915 ECORE_SPQ_MODE_CB, OSAL_NULL);
1917 DP_NOTICE(p_hwfn, true,
1918 "PF failed to configure MAC for VF\n");
1922 p_vf->configured_features |= 1 << MAC_ADDR_FORCED;
1925 if (events & (1 << VLAN_ADDR_FORCED)) {
1926 struct ecore_sp_vport_update_params vport_update;
1930 OSAL_MEMSET(&filter, 0, sizeof(filter));
1931 filter.type = ECORE_FILTER_VLAN;
1932 filter.is_rx_filter = 1;
1933 filter.is_tx_filter = 1;
1934 filter.vport_to_add_to = p_vf->vport_id;
1935 filter.vlan = p_vf->bulletin.p_virt->pvid;
1936 filter.opcode = filter.vlan ? ECORE_FILTER_REPLACE :
1939 /* Send the ramrod */
1940 rc = ecore_sp_eth_filter_ucast(p_hwfn, p_vf->opaque_fid,
1942 ECORE_SPQ_MODE_CB, OSAL_NULL);
1944 DP_NOTICE(p_hwfn, true,
1945 "PF failed to configure VLAN for VF\n");
1949 /* Update the default-vlan & silent vlan stripping */
1950 OSAL_MEMSET(&vport_update, 0, sizeof(vport_update));
1951 vport_update.opaque_fid = p_vf->opaque_fid;
1952 vport_update.vport_id = p_vf->vport_id;
1953 vport_update.update_default_vlan_enable_flg = 1;
1954 vport_update.default_vlan_enable_flg = filter.vlan ? 1 : 0;
1955 vport_update.update_default_vlan_flg = 1;
1956 vport_update.default_vlan = filter.vlan;
1958 vport_update.update_inner_vlan_removal_flg = 1;
1959 removal = filter.vlan ?
1960 1 : p_vf->shadow_config.inner_vlan_removal;
1961 vport_update.inner_vlan_removal_flg = removal;
1962 vport_update.silent_vlan_removal_flg = filter.vlan ? 1 : 0;
1963 rc = ecore_sp_vport_update(p_hwfn, &vport_update,
1964 ECORE_SPQ_MODE_EBLOCK, OSAL_NULL);
1966 DP_NOTICE(p_hwfn, true,
1967 "PF failed to configure VF vport for vlan\n");
1971 /* Update all the Rx queues */
1972 for (i = 0; i < ECORE_MAX_VF_CHAINS_PER_PF; i++) {
1973 struct ecore_vf_queue *p_queue = &p_vf->vf_queues[i];
1974 struct ecore_queue_cid *p_cid = OSAL_NULL;
1976 /* There can be at most 1 Rx queue on qzone. Find it */
1977 p_cid = ecore_iov_get_vf_rx_queue_cid(p_hwfn, p_vf,
1979 if (p_cid == OSAL_NULL)
1982 rc = ecore_sp_eth_rx_queues_update(p_hwfn,
1985 ECORE_SPQ_MODE_EBLOCK,
1988 DP_NOTICE(p_hwfn, true,
1989 "Failed to send Rx update"
1990 " fo queue[0x%04x]\n",
1991 p_cid->rel.queue_id);
1997 p_vf->configured_features |= 1 << VLAN_ADDR_FORCED;
1999 p_vf->configured_features &= ~(1 << VLAN_ADDR_FORCED);
2002 /* If forced features are terminated, we need to configure the shadow
2003 * configuration back again.
2006 ecore_iov_reconfigure_unicast_shadow(p_hwfn, p_vf, events);
2011 static void ecore_iov_vf_mbx_start_vport(struct ecore_hwfn *p_hwfn,
2012 struct ecore_ptt *p_ptt,
2013 struct ecore_vf_info *vf)
2015 struct ecore_sp_vport_start_params params = { 0 };
2016 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
2017 struct vfpf_vport_start_tlv *start;
2018 u8 status = PFVF_STATUS_SUCCESS;
2019 struct ecore_vf_info *vf_info;
2022 enum _ecore_status_t rc;
2024 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vf->relative_vf_id, true);
2026 DP_NOTICE(p_hwfn->p_dev, true,
2027 "Failed to get VF info, invalid vfid [%d]\n",
2028 vf->relative_vf_id);
2032 vf->state = VF_ENABLED;
2033 start = &mbx->req_virt->start_vport;
2035 ecore_iov_enable_vf_traffic(p_hwfn, p_ptt, vf);
2037 /* Initialize Status block in CAU */
2038 for (sb_id = 0; sb_id < vf->num_sbs; sb_id++) {
2039 if (!start->sb_addr[sb_id]) {
2040 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2041 "VF[%d] did not fill the address of SB %d\n",
2042 vf->relative_vf_id, sb_id);
2046 ecore_int_cau_conf_sb(p_hwfn, p_ptt,
2047 start->sb_addr[sb_id],
2052 vf->mtu = start->mtu;
2053 vf->shadow_config.inner_vlan_removal = start->inner_vlan_removal;
2055 /* Take into consideration configuration forced by hypervisor;
2056 * If none is configured, use the supplied VF values [for old
2057 * vfs that would still be fine, since they passed '0' as padding].
2059 p_bitmap = &vf_info->bulletin.p_virt->valid_bitmap;
2060 if (!(*p_bitmap & (1 << VFPF_BULLETIN_UNTAGGED_DEFAULT_FORCED))) {
2061 u8 vf_req = start->only_untagged;
2063 vf_info->bulletin.p_virt->default_only_untagged = vf_req;
2064 *p_bitmap |= 1 << VFPF_BULLETIN_UNTAGGED_DEFAULT;
2067 params.tpa_mode = start->tpa_mode;
2068 params.remove_inner_vlan = start->inner_vlan_removal;
2069 params.tx_switching = true;
2072 if (CHIP_REV_IS_FPGA(p_hwfn->p_dev)) {
2073 DP_NOTICE(p_hwfn, false,
2074 "FPGA: Don't config VF for Tx-switching [no pVFC]\n");
2075 params.tx_switching = false;
2079 params.only_untagged = vf_info->bulletin.p_virt->default_only_untagged;
2080 params.drop_ttl0 = false;
2081 params.concrete_fid = vf->concrete_fid;
2082 params.opaque_fid = vf->opaque_fid;
2083 params.vport_id = vf->vport_id;
2084 params.max_buffers_per_cqe = start->max_buffers_per_cqe;
2085 params.mtu = vf->mtu;
2086 params.check_mac = true;
2088 rc = ecore_sp_eth_vport_start(p_hwfn, ¶ms);
2089 if (rc != ECORE_SUCCESS) {
2091 "ecore_iov_vf_mbx_start_vport returned error %d\n", rc);
2092 status = PFVF_STATUS_FAILURE;
2094 vf->vport_instance++;
2096 /* Force configuration if needed on the newly opened vport */
2097 ecore_iov_configure_vport_forced(p_hwfn, vf, *p_bitmap);
2098 OSAL_IOV_POST_START_VPORT(p_hwfn, vf->relative_vf_id,
2099 vf->vport_id, vf->opaque_fid);
2100 __ecore_iov_spoofchk_set(p_hwfn, vf, vf->req_spoofchk_val);
2103 ecore_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_VPORT_START,
2104 sizeof(struct pfvf_def_resp_tlv), status);
2107 static void ecore_iov_vf_mbx_stop_vport(struct ecore_hwfn *p_hwfn,
2108 struct ecore_ptt *p_ptt,
2109 struct ecore_vf_info *vf)
2111 u8 status = PFVF_STATUS_SUCCESS;
2112 enum _ecore_status_t rc;
2114 vf->vport_instance--;
2115 vf->spoof_chk = false;
2117 if ((ecore_iov_validate_active_rxq(p_hwfn, vf)) ||
2118 (ecore_iov_validate_active_txq(p_hwfn, vf))) {
2119 vf->b_malicious = true;
2120 DP_NOTICE(p_hwfn, false,
2121 "VF [%02x] - considered malicious;"
2122 " Unable to stop RX/TX queuess\n",
2126 rc = ecore_sp_vport_stop(p_hwfn, vf->opaque_fid, vf->vport_id);
2127 if (rc != ECORE_SUCCESS) {
2129 "ecore_iov_vf_mbx_stop_vport returned error %d\n", rc);
2130 status = PFVF_STATUS_FAILURE;
2133 /* Forget the configuration on the vport */
2134 vf->configured_features = 0;
2135 OSAL_MEMSET(&vf->shadow_config, 0, sizeof(vf->shadow_config));
2137 ecore_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_VPORT_TEARDOWN,
2138 sizeof(struct pfvf_def_resp_tlv), status);
2141 static void ecore_iov_vf_mbx_start_rxq_resp(struct ecore_hwfn *p_hwfn,
2142 struct ecore_ptt *p_ptt,
2143 struct ecore_vf_info *vf,
2144 u8 status, bool b_legacy)
2146 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
2147 struct pfvf_start_queue_resp_tlv *p_tlv;
2148 struct vfpf_start_rxq_tlv *req;
2151 mbx->offset = (u8 *)mbx->reply_virt;
2153 /* Taking a bigger struct instead of adding a TLV to list was a
2154 * mistake, but one which we're now stuck with, as some older
2155 * clients assume the size of the previous response.
2158 length = sizeof(*p_tlv);
2160 length = sizeof(struct pfvf_def_resp_tlv);
2162 p_tlv = ecore_add_tlv(p_hwfn, &mbx->offset, CHANNEL_TLV_START_RXQ,
2164 ecore_add_tlv(p_hwfn, &mbx->offset, CHANNEL_TLV_LIST_END,
2165 sizeof(struct channel_list_end_tlv));
2167 /* Update the TLV with the response */
2168 if ((status == PFVF_STATUS_SUCCESS) && !b_legacy) {
2169 req = &mbx->req_virt->start_rxq;
2170 p_tlv->offset = PXP_VF_BAR0_START_MSDM_ZONE_B +
2171 OFFSETOF(struct mstorm_vf_zone,
2172 non_trigger.eth_rx_queue_producers) +
2173 sizeof(struct eth_rx_prod_data) * req->rx_qid;
2176 ecore_iov_send_response(p_hwfn, p_ptt, vf, length, status);
2179 static u8 ecore_iov_vf_mbx_qid(struct ecore_hwfn *p_hwfn,
2180 struct ecore_vf_info *p_vf, bool b_is_tx)
2182 struct ecore_iov_vf_mbx *p_mbx = &p_vf->vf_mbx;
2183 struct vfpf_qid_tlv *p_qid_tlv;
2185 /* Search for the qid if the VF published if its going to provide it */
2186 if (!(p_vf->acquire.vfdev_info.capabilities &
2187 VFPF_ACQUIRE_CAP_QUEUE_QIDS)) {
2189 return ECORE_IOV_LEGACY_QID_TX;
2191 return ECORE_IOV_LEGACY_QID_RX;
2194 p_qid_tlv = (struct vfpf_qid_tlv *)
2195 ecore_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt,
2197 if (p_qid_tlv == OSAL_NULL) {
2198 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2199 "VF[%2x]: Failed to provide qid\n",
2200 p_vf->relative_vf_id);
2202 return ECORE_IOV_QID_INVALID;
2205 if (p_qid_tlv->qid >= MAX_QUEUES_PER_QZONE) {
2206 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2207 "VF[%02x]: Provided qid out-of-bounds %02x\n",
2208 p_vf->relative_vf_id, p_qid_tlv->qid);
2209 return ECORE_IOV_QID_INVALID;
2212 return p_qid_tlv->qid;
2215 static void ecore_iov_vf_mbx_start_rxq(struct ecore_hwfn *p_hwfn,
2216 struct ecore_ptt *p_ptt,
2217 struct ecore_vf_info *vf)
2219 struct ecore_queue_start_common_params params;
2220 struct ecore_queue_cid_vf_params vf_params;
2221 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
2222 u8 status = PFVF_STATUS_NO_RESOURCE;
2223 u8 qid_usage_idx, vf_legacy = 0;
2224 struct ecore_vf_queue *p_queue;
2225 struct vfpf_start_rxq_tlv *req;
2226 struct ecore_queue_cid *p_cid;
2227 struct ecore_sb_info sb_dummy;
2228 enum _ecore_status_t rc;
2230 req = &mbx->req_virt->start_rxq;
2232 if (!ecore_iov_validate_rxq(p_hwfn, vf, req->rx_qid,
2233 ECORE_IOV_VALIDATE_Q_DISABLE) ||
2234 !ecore_iov_validate_sb(p_hwfn, vf, req->hw_sb))
2237 qid_usage_idx = ecore_iov_vf_mbx_qid(p_hwfn, vf, false);
2238 if (qid_usage_idx == ECORE_IOV_QID_INVALID)
2241 p_queue = &vf->vf_queues[req->rx_qid];
2242 if (p_queue->cids[qid_usage_idx].p_cid)
2245 vf_legacy = ecore_vf_calculate_legacy(p_hwfn, vf);
2247 /* Acquire a new queue-cid */
2248 OSAL_MEMSET(¶ms, 0, sizeof(params));
2249 params.queue_id = (u8)p_queue->fw_rx_qid;
2250 params.vport_id = vf->vport_id;
2251 params.stats_id = vf->abs_vf_id + 0x10;
2253 /* Since IGU index is passed via sb_info, construct a dummy one */
2254 OSAL_MEM_ZERO(&sb_dummy, sizeof(sb_dummy));
2255 sb_dummy.igu_sb_id = req->hw_sb;
2256 params.p_sb = &sb_dummy;
2257 params.sb_idx = req->sb_index;
2259 OSAL_MEM_ZERO(&vf_params, sizeof(vf_params));
2260 vf_params.vfid = vf->relative_vf_id;
2261 vf_params.vf_qid = (u8)req->rx_qid;
2262 vf_params.vf_legacy = vf_legacy;
2263 vf_params.qid_usage_idx = qid_usage_idx;
2265 p_cid = ecore_eth_queue_to_cid(p_hwfn, vf->opaque_fid,
2266 ¶ms, &vf_params);
2267 if (p_cid == OSAL_NULL)
2270 /* Legacy VFs have their Producers in a different location, which they
2271 * calculate on their own and clean the producer prior to this.
2273 if (!(vf_legacy & ECORE_QCID_LEGACY_VF_RX_PROD))
2275 GTT_BAR0_MAP_REG_MSDM_RAM +
2276 MSTORM_ETH_VF_PRODS_OFFSET(vf->abs_vf_id, req->rx_qid),
2279 rc = ecore_eth_rxq_start_ramrod(p_hwfn, p_cid,
2284 if (rc != ECORE_SUCCESS) {
2285 status = PFVF_STATUS_FAILURE;
2286 ecore_eth_queue_cid_release(p_hwfn, p_cid);
2288 p_queue->cids[qid_usage_idx].p_cid = p_cid;
2289 p_queue->cids[qid_usage_idx].b_is_tx = false;
2290 status = PFVF_STATUS_SUCCESS;
2291 vf->num_active_rxqs++;
2295 ecore_iov_vf_mbx_start_rxq_resp(p_hwfn, p_ptt, vf, status,
2297 ECORE_QCID_LEGACY_VF_RX_PROD));
2301 ecore_iov_pf_update_tun_response(struct pfvf_update_tunn_param_tlv *p_resp,
2302 struct ecore_tunnel_info *p_tun,
2303 u16 tunn_feature_mask)
2305 p_resp->tunn_feature_mask = tunn_feature_mask;
2306 p_resp->vxlan_mode = p_tun->vxlan.b_mode_enabled;
2307 p_resp->l2geneve_mode = p_tun->l2_geneve.b_mode_enabled;
2308 p_resp->ipgeneve_mode = p_tun->ip_geneve.b_mode_enabled;
2309 p_resp->l2gre_mode = p_tun->l2_gre.b_mode_enabled;
2310 p_resp->ipgre_mode = p_tun->l2_gre.b_mode_enabled;
2311 p_resp->vxlan_clss = p_tun->vxlan.tun_cls;
2312 p_resp->l2gre_clss = p_tun->l2_gre.tun_cls;
2313 p_resp->ipgre_clss = p_tun->ip_gre.tun_cls;
2314 p_resp->l2geneve_clss = p_tun->l2_geneve.tun_cls;
2315 p_resp->ipgeneve_clss = p_tun->ip_geneve.tun_cls;
2316 p_resp->geneve_udp_port = p_tun->geneve_port.port;
2317 p_resp->vxlan_udp_port = p_tun->vxlan_port.port;
2321 __ecore_iov_pf_update_tun_param(struct vfpf_update_tunn_param_tlv *p_req,
2322 struct ecore_tunn_update_type *p_tun,
2323 enum ecore_tunn_mode mask, u8 tun_cls)
2325 if (p_req->tun_mode_update_mask & (1 << mask)) {
2326 p_tun->b_update_mode = true;
2328 if (p_req->tunn_mode & (1 << mask))
2329 p_tun->b_mode_enabled = true;
2332 p_tun->tun_cls = tun_cls;
2336 ecore_iov_pf_update_tun_param(struct vfpf_update_tunn_param_tlv *p_req,
2337 struct ecore_tunn_update_type *p_tun,
2338 struct ecore_tunn_update_udp_port *p_port,
2339 enum ecore_tunn_mode mask,
2340 u8 tun_cls, u8 update_port, u16 port)
2343 p_port->b_update_port = true;
2344 p_port->port = port;
2347 __ecore_iov_pf_update_tun_param(p_req, p_tun, mask, tun_cls);
2351 ecore_iov_pf_validate_tunn_param(struct vfpf_update_tunn_param_tlv *p_req)
2353 bool b_update_requested = false;
2355 if (p_req->tun_mode_update_mask || p_req->update_tun_cls ||
2356 p_req->update_geneve_port || p_req->update_vxlan_port)
2357 b_update_requested = true;
2359 return b_update_requested;
2362 static void ecore_iov_vf_mbx_update_tunn_param(struct ecore_hwfn *p_hwfn,
2363 struct ecore_ptt *p_ptt,
2364 struct ecore_vf_info *p_vf)
2366 struct ecore_tunnel_info *p_tun = &p_hwfn->p_dev->tunnel;
2367 struct ecore_iov_vf_mbx *mbx = &p_vf->vf_mbx;
2368 struct pfvf_update_tunn_param_tlv *p_resp;
2369 struct vfpf_update_tunn_param_tlv *p_req;
2370 enum _ecore_status_t rc = ECORE_SUCCESS;
2371 u8 status = PFVF_STATUS_SUCCESS;
2372 bool b_update_required = false;
2373 struct ecore_tunnel_info tunn;
2374 u16 tunn_feature_mask = 0;
2377 mbx->offset = (u8 *)mbx->reply_virt;
2379 OSAL_MEM_ZERO(&tunn, sizeof(tunn));
2380 p_req = &mbx->req_virt->tunn_param_update;
2382 if (!ecore_iov_pf_validate_tunn_param(p_req)) {
2383 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2384 "No tunnel update requested by VF\n");
2385 status = PFVF_STATUS_FAILURE;
2389 tunn.b_update_rx_cls = p_req->update_tun_cls;
2390 tunn.b_update_tx_cls = p_req->update_tun_cls;
2392 ecore_iov_pf_update_tun_param(p_req, &tunn.vxlan, &tunn.vxlan_port,
2393 ECORE_MODE_VXLAN_TUNN, p_req->vxlan_clss,
2394 p_req->update_vxlan_port,
2396 ecore_iov_pf_update_tun_param(p_req, &tunn.l2_geneve, &tunn.geneve_port,
2397 ECORE_MODE_L2GENEVE_TUNN,
2398 p_req->l2geneve_clss,
2399 p_req->update_geneve_port,
2400 p_req->geneve_port);
2401 __ecore_iov_pf_update_tun_param(p_req, &tunn.ip_geneve,
2402 ECORE_MODE_IPGENEVE_TUNN,
2403 p_req->ipgeneve_clss);
2404 __ecore_iov_pf_update_tun_param(p_req, &tunn.l2_gre,
2405 ECORE_MODE_L2GRE_TUNN,
2407 __ecore_iov_pf_update_tun_param(p_req, &tunn.ip_gre,
2408 ECORE_MODE_IPGRE_TUNN,
2411 /* If PF modifies VF's req then it should
2412 * still return an error in case of partial configuration
2413 * or modified configuration as opposed to requested one.
2415 rc = OSAL_PF_VALIDATE_MODIFY_TUNN_CONFIG(p_hwfn, &tunn_feature_mask,
2416 &b_update_required, &tunn);
2418 if (rc != ECORE_SUCCESS)
2419 status = PFVF_STATUS_FAILURE;
2421 /* If ECORE client is willing to update anything ? */
2422 if (b_update_required) {
2425 rc = ecore_sp_pf_update_tunn_cfg(p_hwfn, p_ptt, &tunn,
2426 ECORE_SPQ_MODE_EBLOCK,
2428 if (rc != ECORE_SUCCESS)
2429 status = PFVF_STATUS_FAILURE;
2431 geneve_port = p_tun->geneve_port.port;
2432 ecore_for_each_vf(p_hwfn, i) {
2433 ecore_iov_bulletin_set_udp_ports(p_hwfn, i,
2434 p_tun->vxlan_port.port,
2440 p_resp = ecore_add_tlv(p_hwfn, &mbx->offset,
2441 CHANNEL_TLV_UPDATE_TUNN_PARAM, sizeof(*p_resp));
2443 ecore_iov_pf_update_tun_response(p_resp, p_tun, tunn_feature_mask);
2444 ecore_add_tlv(p_hwfn, &mbx->offset, CHANNEL_TLV_LIST_END,
2445 sizeof(struct channel_list_end_tlv));
2447 ecore_iov_send_response(p_hwfn, p_ptt, p_vf, sizeof(*p_resp), status);
2450 static void ecore_iov_vf_mbx_start_txq_resp(struct ecore_hwfn *p_hwfn,
2451 struct ecore_ptt *p_ptt,
2452 struct ecore_vf_info *p_vf,
2456 struct ecore_iov_vf_mbx *mbx = &p_vf->vf_mbx;
2457 struct pfvf_start_queue_resp_tlv *p_tlv;
2458 bool b_legacy = false;
2461 mbx->offset = (u8 *)mbx->reply_virt;
2463 /* Taking a bigger struct instead of adding a TLV to list was a
2464 * mistake, but one which we're now stuck with, as some older
2465 * clients assume the size of the previous response.
2467 if (p_vf->acquire.vfdev_info.eth_fp_hsi_minor ==
2468 ETH_HSI_VER_NO_PKT_LEN_TUNN)
2472 length = sizeof(*p_tlv);
2474 length = sizeof(struct pfvf_def_resp_tlv);
2476 p_tlv = ecore_add_tlv(p_hwfn, &mbx->offset, CHANNEL_TLV_START_TXQ,
2478 ecore_add_tlv(p_hwfn, &mbx->offset, CHANNEL_TLV_LIST_END,
2479 sizeof(struct channel_list_end_tlv));
2481 /* Update the TLV with the response */
2482 if ((status == PFVF_STATUS_SUCCESS) && !b_legacy)
2483 p_tlv->offset = DB_ADDR_VF(cid, DQ_DEMS_LEGACY);
2485 ecore_iov_send_response(p_hwfn, p_ptt, p_vf, length, status);
2488 static void ecore_iov_vf_mbx_start_txq(struct ecore_hwfn *p_hwfn,
2489 struct ecore_ptt *p_ptt,
2490 struct ecore_vf_info *vf)
2492 struct ecore_queue_start_common_params params;
2493 struct ecore_queue_cid_vf_params vf_params;
2494 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
2495 u8 status = PFVF_STATUS_NO_RESOURCE;
2496 struct ecore_vf_queue *p_queue;
2497 struct vfpf_start_txq_tlv *req;
2498 struct ecore_queue_cid *p_cid;
2499 struct ecore_sb_info sb_dummy;
2500 u8 qid_usage_idx, vf_legacy;
2502 enum _ecore_status_t rc;
2505 OSAL_MEMSET(¶ms, 0, sizeof(params));
2506 req = &mbx->req_virt->start_txq;
2508 if (!ecore_iov_validate_txq(p_hwfn, vf, req->tx_qid,
2509 ECORE_IOV_VALIDATE_Q_NA) ||
2510 !ecore_iov_validate_sb(p_hwfn, vf, req->hw_sb))
2513 qid_usage_idx = ecore_iov_vf_mbx_qid(p_hwfn, vf, true);
2514 if (qid_usage_idx == ECORE_IOV_QID_INVALID)
2517 p_queue = &vf->vf_queues[req->tx_qid];
2518 if (p_queue->cids[qid_usage_idx].p_cid)
2521 vf_legacy = ecore_vf_calculate_legacy(p_hwfn, vf);
2523 /* Acquire a new queue-cid */
2524 params.queue_id = p_queue->fw_tx_qid;
2525 params.vport_id = vf->vport_id;
2526 params.stats_id = vf->abs_vf_id + 0x10;
2528 /* Since IGU index is passed via sb_info, construct a dummy one */
2529 OSAL_MEM_ZERO(&sb_dummy, sizeof(sb_dummy));
2530 sb_dummy.igu_sb_id = req->hw_sb;
2531 params.p_sb = &sb_dummy;
2532 params.sb_idx = req->sb_index;
2534 OSAL_MEM_ZERO(&vf_params, sizeof(vf_params));
2535 vf_params.vfid = vf->relative_vf_id;
2536 vf_params.vf_qid = (u8)req->tx_qid;
2537 vf_params.vf_legacy = vf_legacy;
2538 vf_params.qid_usage_idx = qid_usage_idx;
2540 p_cid = ecore_eth_queue_to_cid(p_hwfn, vf->opaque_fid,
2541 ¶ms, &vf_params);
2542 if (p_cid == OSAL_NULL)
2545 pq = ecore_get_cm_pq_idx_vf(p_hwfn,
2546 vf->relative_vf_id);
2547 rc = ecore_eth_txq_start_ramrod(p_hwfn, p_cid,
2548 req->pbl_addr, req->pbl_size, pq);
2549 if (rc != ECORE_SUCCESS) {
2550 status = PFVF_STATUS_FAILURE;
2551 ecore_eth_queue_cid_release(p_hwfn, p_cid);
2553 status = PFVF_STATUS_SUCCESS;
2554 p_queue->cids[qid_usage_idx].p_cid = p_cid;
2555 p_queue->cids[qid_usage_idx].b_is_tx = true;
2560 ecore_iov_vf_mbx_start_txq_resp(p_hwfn, p_ptt, vf,
2564 static enum _ecore_status_t ecore_iov_vf_stop_rxqs(struct ecore_hwfn *p_hwfn,
2565 struct ecore_vf_info *vf,
2568 bool cqe_completion)
2570 struct ecore_vf_queue *p_queue;
2571 enum _ecore_status_t rc = ECORE_SUCCESS;
2573 if (!ecore_iov_validate_rxq(p_hwfn, vf, rxq_id,
2574 ECORE_IOV_VALIDATE_Q_NA)) {
2575 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2576 "VF[%d] Tried Closing Rx 0x%04x.%02x which is inactive\n",
2577 vf->relative_vf_id, rxq_id, qid_usage_idx);
2581 p_queue = &vf->vf_queues[rxq_id];
2583 /* We've validated the index and the existence of the active RXQ -
2584 * now we need to make sure that it's using the correct qid.
2586 if (!p_queue->cids[qid_usage_idx].p_cid ||
2587 p_queue->cids[qid_usage_idx].b_is_tx) {
2588 struct ecore_queue_cid *p_cid;
2590 p_cid = ecore_iov_get_vf_rx_queue_cid(p_hwfn, vf, p_queue);
2591 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2592 "VF[%d] - Tried Closing Rx 0x%04x.%02x, but Rx is at %04x.%02x\n",
2593 vf->relative_vf_id, rxq_id, qid_usage_idx,
2594 rxq_id, p_cid->qid_usage_idx);
2598 /* Now that we know we have a valid Rx-queue - close it */
2599 rc = ecore_eth_rx_queue_stop(p_hwfn,
2600 p_queue->cids[qid_usage_idx].p_cid,
2601 false, cqe_completion);
2602 if (rc != ECORE_SUCCESS)
2605 p_queue->cids[qid_usage_idx].p_cid = OSAL_NULL;
2606 vf->num_active_rxqs--;
2608 return ECORE_SUCCESS;
2611 static enum _ecore_status_t ecore_iov_vf_stop_txqs(struct ecore_hwfn *p_hwfn,
2612 struct ecore_vf_info *vf,
2616 struct ecore_vf_queue *p_queue;
2617 enum _ecore_status_t rc = ECORE_SUCCESS;
2619 if (!ecore_iov_validate_txq(p_hwfn, vf, txq_id,
2620 ECORE_IOV_VALIDATE_Q_NA))
2623 p_queue = &vf->vf_queues[txq_id];
2624 if (!p_queue->cids[qid_usage_idx].p_cid ||
2625 !p_queue->cids[qid_usage_idx].b_is_tx)
2628 rc = ecore_eth_tx_queue_stop(p_hwfn,
2629 p_queue->cids[qid_usage_idx].p_cid);
2630 if (rc != ECORE_SUCCESS)
2633 p_queue->cids[qid_usage_idx].p_cid = OSAL_NULL;
2634 return ECORE_SUCCESS;
2637 static void ecore_iov_vf_mbx_stop_rxqs(struct ecore_hwfn *p_hwfn,
2638 struct ecore_ptt *p_ptt,
2639 struct ecore_vf_info *vf)
2641 u16 length = sizeof(struct pfvf_def_resp_tlv);
2642 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
2643 u8 status = PFVF_STATUS_FAILURE;
2644 struct vfpf_stop_rxqs_tlv *req;
2646 enum _ecore_status_t rc;
2648 /* Starting with CHANNEL_TLV_QID, it's assumed the 'num_rxqs'
2649 * would be one. Since no older ecore passed multiple queues
2650 * using this API, sanitize on the value.
2652 req = &mbx->req_virt->stop_rxqs;
2653 if (req->num_rxqs != 1) {
2654 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2655 "Odd; VF[%d] tried stopping multiple Rx queues\n",
2656 vf->relative_vf_id);
2657 status = PFVF_STATUS_NOT_SUPPORTED;
2661 /* Find which qid-index is associated with the queue */
2662 qid_usage_idx = ecore_iov_vf_mbx_qid(p_hwfn, vf, false);
2663 if (qid_usage_idx == ECORE_IOV_QID_INVALID)
2666 rc = ecore_iov_vf_stop_rxqs(p_hwfn, vf, req->rx_qid,
2667 qid_usage_idx, req->cqe_completion);
2668 if (rc == ECORE_SUCCESS)
2669 status = PFVF_STATUS_SUCCESS;
2671 ecore_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_STOP_RXQS,
2675 static void ecore_iov_vf_mbx_stop_txqs(struct ecore_hwfn *p_hwfn,
2676 struct ecore_ptt *p_ptt,
2677 struct ecore_vf_info *vf)
2679 u16 length = sizeof(struct pfvf_def_resp_tlv);
2680 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
2681 u8 status = PFVF_STATUS_FAILURE;
2682 struct vfpf_stop_txqs_tlv *req;
2684 enum _ecore_status_t rc;
2686 /* Starting with CHANNEL_TLV_QID, it's assumed the 'num_txqs'
2687 * would be one. Since no older ecore passed multiple queues
2688 * using this API, sanitize on the value.
2690 req = &mbx->req_virt->stop_txqs;
2691 if (req->num_txqs != 1) {
2692 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2693 "Odd; VF[%d] tried stopping multiple Tx queues\n",
2694 vf->relative_vf_id);
2695 status = PFVF_STATUS_NOT_SUPPORTED;
2699 /* Find which qid-index is associated with the queue */
2700 qid_usage_idx = ecore_iov_vf_mbx_qid(p_hwfn, vf, true);
2701 if (qid_usage_idx == ECORE_IOV_QID_INVALID)
2704 rc = ecore_iov_vf_stop_txqs(p_hwfn, vf, req->tx_qid,
2706 if (rc == ECORE_SUCCESS)
2707 status = PFVF_STATUS_SUCCESS;
2710 ecore_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_STOP_TXQS,
2714 static void ecore_iov_vf_mbx_update_rxqs(struct ecore_hwfn *p_hwfn,
2715 struct ecore_ptt *p_ptt,
2716 struct ecore_vf_info *vf)
2718 struct ecore_queue_cid *handlers[ECORE_MAX_VF_CHAINS_PER_PF];
2719 u16 length = sizeof(struct pfvf_def_resp_tlv);
2720 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
2721 struct vfpf_update_rxq_tlv *req;
2722 u8 status = PFVF_STATUS_FAILURE;
2723 u8 complete_event_flg;
2724 u8 complete_cqe_flg;
2726 enum _ecore_status_t rc;
2729 req = &mbx->req_virt->update_rxq;
2730 complete_cqe_flg = !!(req->flags & VFPF_RXQ_UPD_COMPLETE_CQE_FLAG);
2731 complete_event_flg = !!(req->flags & VFPF_RXQ_UPD_COMPLETE_EVENT_FLAG);
2733 qid_usage_idx = ecore_iov_vf_mbx_qid(p_hwfn, vf, false);
2734 if (qid_usage_idx == ECORE_IOV_QID_INVALID)
2737 /* Starting with the addition of CHANNEL_TLV_QID, this API started
2738 * expecting a single queue at a time. Validate this.
2740 if ((vf->acquire.vfdev_info.capabilities &
2741 VFPF_ACQUIRE_CAP_QUEUE_QIDS) &&
2742 req->num_rxqs != 1) {
2743 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2744 "VF[%d] supports QIDs but sends multiple queues\n",
2745 vf->relative_vf_id);
2749 /* Validate inputs - for the legacy case this is still true since
2750 * qid_usage_idx for each Rx queue would be LEGACY_QID_RX.
2752 for (i = req->rx_qid; i < req->rx_qid + req->num_rxqs; i++) {
2753 if (!ecore_iov_validate_rxq(p_hwfn, vf, i,
2754 ECORE_IOV_VALIDATE_Q_NA) ||
2755 !vf->vf_queues[i].cids[qid_usage_idx].p_cid ||
2756 vf->vf_queues[i].cids[qid_usage_idx].b_is_tx) {
2757 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2758 "VF[%d]: Incorrect Rxqs [%04x, %02x]\n",
2759 vf->relative_vf_id, req->rx_qid,
2765 for (i = 0; i < req->num_rxqs; i++) {
2766 u16 qid = req->rx_qid + i;
2768 handlers[i] = vf->vf_queues[qid].cids[qid_usage_idx].p_cid;
2771 rc = ecore_sp_eth_rx_queues_update(p_hwfn, (void **)&handlers,
2775 ECORE_SPQ_MODE_EBLOCK,
2777 if (rc != ECORE_SUCCESS)
2780 status = PFVF_STATUS_SUCCESS;
2782 ecore_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_UPDATE_RXQ,
2786 void *ecore_iov_search_list_tlvs(struct ecore_hwfn *p_hwfn,
2787 void *p_tlvs_list, u16 req_type)
2789 struct channel_tlv *p_tlv = (struct channel_tlv *)p_tlvs_list;
2793 if (!p_tlv->length) {
2794 DP_NOTICE(p_hwfn, true, "Zero length TLV found\n");
2798 if (p_tlv->type == req_type) {
2799 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2800 "Extended tlv type %s, length %d found\n",
2801 ecore_channel_tlvs_string[p_tlv->type],
2806 len += p_tlv->length;
2807 p_tlv = (struct channel_tlv *)((u8 *)p_tlv + p_tlv->length);
2809 if ((len + p_tlv->length) > TLV_BUFFER_SIZE) {
2810 DP_NOTICE(p_hwfn, true,
2811 "TLVs has overrun the buffer size\n");
2814 } while (p_tlv->type != CHANNEL_TLV_LIST_END);
2820 ecore_iov_vp_update_act_param(struct ecore_hwfn *p_hwfn,
2821 struct ecore_sp_vport_update_params *p_data,
2822 struct ecore_iov_vf_mbx *p_mbx, u16 *tlvs_mask)
2824 struct vfpf_vport_update_activate_tlv *p_act_tlv;
2825 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_ACTIVATE;
2827 p_act_tlv = (struct vfpf_vport_update_activate_tlv *)
2828 ecore_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
2832 p_data->update_vport_active_rx_flg = p_act_tlv->update_rx;
2833 p_data->vport_active_rx_flg = p_act_tlv->active_rx;
2834 p_data->update_vport_active_tx_flg = p_act_tlv->update_tx;
2835 p_data->vport_active_tx_flg = p_act_tlv->active_tx;
2836 *tlvs_mask |= 1 << ECORE_IOV_VP_UPDATE_ACTIVATE;
2840 ecore_iov_vp_update_vlan_param(struct ecore_hwfn *p_hwfn,
2841 struct ecore_sp_vport_update_params *p_data,
2842 struct ecore_vf_info *p_vf,
2843 struct ecore_iov_vf_mbx *p_mbx, u16 *tlvs_mask)
2845 struct vfpf_vport_update_vlan_strip_tlv *p_vlan_tlv;
2846 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_VLAN_STRIP;
2848 p_vlan_tlv = (struct vfpf_vport_update_vlan_strip_tlv *)
2849 ecore_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
2853 p_vf->shadow_config.inner_vlan_removal = p_vlan_tlv->remove_vlan;
2855 /* Ignore the VF request if we're forcing a vlan */
2856 if (!(p_vf->configured_features & (1 << VLAN_ADDR_FORCED))) {
2857 p_data->update_inner_vlan_removal_flg = 1;
2858 p_data->inner_vlan_removal_flg = p_vlan_tlv->remove_vlan;
2861 *tlvs_mask |= 1 << ECORE_IOV_VP_UPDATE_VLAN_STRIP;
2865 ecore_iov_vp_update_tx_switch(struct ecore_hwfn *p_hwfn,
2866 struct ecore_sp_vport_update_params *p_data,
2867 struct ecore_iov_vf_mbx *p_mbx, u16 *tlvs_mask)
2869 struct vfpf_vport_update_tx_switch_tlv *p_tx_switch_tlv;
2870 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_TX_SWITCH;
2872 p_tx_switch_tlv = (struct vfpf_vport_update_tx_switch_tlv *)
2873 ecore_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
2874 if (!p_tx_switch_tlv)
2878 if (CHIP_REV_IS_FPGA(p_hwfn->p_dev)) {
2879 DP_NOTICE(p_hwfn, false,
2880 "FPGA: Ignore tx-switching configuration originating"
2886 p_data->update_tx_switching_flg = 1;
2887 p_data->tx_switching_flg = p_tx_switch_tlv->tx_switching;
2888 *tlvs_mask |= 1 << ECORE_IOV_VP_UPDATE_TX_SWITCH;
2892 ecore_iov_vp_update_mcast_bin_param(struct ecore_hwfn *p_hwfn,
2893 struct ecore_sp_vport_update_params *p_data,
2894 struct ecore_iov_vf_mbx *p_mbx,
2897 struct vfpf_vport_update_mcast_bin_tlv *p_mcast_tlv;
2898 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_MCAST;
2900 p_mcast_tlv = (struct vfpf_vport_update_mcast_bin_tlv *)
2901 ecore_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
2905 p_data->update_approx_mcast_flg = 1;
2906 OSAL_MEMCPY(p_data->bins, p_mcast_tlv->bins,
2907 sizeof(unsigned long) *
2908 ETH_MULTICAST_MAC_BINS_IN_REGS);
2909 *tlvs_mask |= 1 << ECORE_IOV_VP_UPDATE_MCAST;
2913 ecore_iov_vp_update_accept_flag(struct ecore_hwfn *p_hwfn,
2914 struct ecore_sp_vport_update_params *p_data,
2915 struct ecore_iov_vf_mbx *p_mbx, u16 *tlvs_mask)
2917 struct ecore_filter_accept_flags *p_flags = &p_data->accept_flags;
2918 struct vfpf_vport_update_accept_param_tlv *p_accept_tlv;
2919 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_ACCEPT_PARAM;
2921 p_accept_tlv = (struct vfpf_vport_update_accept_param_tlv *)
2922 ecore_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
2926 p_flags->update_rx_mode_config = p_accept_tlv->update_rx_mode;
2927 p_flags->rx_accept_filter = p_accept_tlv->rx_accept_filter;
2928 p_flags->update_tx_mode_config = p_accept_tlv->update_tx_mode;
2929 p_flags->tx_accept_filter = p_accept_tlv->tx_accept_filter;
2930 *tlvs_mask |= 1 << ECORE_IOV_VP_UPDATE_ACCEPT_PARAM;
2934 ecore_iov_vp_update_accept_any_vlan(struct ecore_hwfn *p_hwfn,
2935 struct ecore_sp_vport_update_params *p_data,
2936 struct ecore_iov_vf_mbx *p_mbx,
2939 struct vfpf_vport_update_accept_any_vlan_tlv *p_accept_any_vlan;
2940 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_ACCEPT_ANY_VLAN;
2942 p_accept_any_vlan = (struct vfpf_vport_update_accept_any_vlan_tlv *)
2943 ecore_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
2944 if (!p_accept_any_vlan)
2947 p_data->accept_any_vlan = p_accept_any_vlan->accept_any_vlan;
2948 p_data->update_accept_any_vlan_flg =
2949 p_accept_any_vlan->update_accept_any_vlan_flg;
2950 *tlvs_mask |= 1 << ECORE_IOV_VP_UPDATE_ACCEPT_ANY_VLAN;
2954 ecore_iov_vp_update_rss_param(struct ecore_hwfn *p_hwfn,
2955 struct ecore_vf_info *vf,
2956 struct ecore_sp_vport_update_params *p_data,
2957 struct ecore_rss_params *p_rss,
2958 struct ecore_iov_vf_mbx *p_mbx,
2959 u16 *tlvs_mask, u16 *tlvs_accepted)
2961 struct vfpf_vport_update_rss_tlv *p_rss_tlv;
2962 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_RSS;
2963 bool b_reject = false;
2967 p_rss_tlv = (struct vfpf_vport_update_rss_tlv *)
2968 ecore_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
2970 p_data->rss_params = OSAL_NULL;
2974 OSAL_MEMSET(p_rss, 0, sizeof(struct ecore_rss_params));
2976 p_rss->update_rss_config =
2977 !!(p_rss_tlv->update_rss_flags &
2978 VFPF_UPDATE_RSS_CONFIG_FLAG);
2979 p_rss->update_rss_capabilities =
2980 !!(p_rss_tlv->update_rss_flags &
2981 VFPF_UPDATE_RSS_CAPS_FLAG);
2982 p_rss->update_rss_ind_table =
2983 !!(p_rss_tlv->update_rss_flags &
2984 VFPF_UPDATE_RSS_IND_TABLE_FLAG);
2985 p_rss->update_rss_key =
2986 !!(p_rss_tlv->update_rss_flags &
2987 VFPF_UPDATE_RSS_KEY_FLAG);
2989 p_rss->rss_enable = p_rss_tlv->rss_enable;
2990 p_rss->rss_eng_id = vf->rss_eng_id;
2991 p_rss->rss_caps = p_rss_tlv->rss_caps;
2992 p_rss->rss_table_size_log = p_rss_tlv->rss_table_size_log;
2993 OSAL_MEMCPY(p_rss->rss_key, p_rss_tlv->rss_key,
2994 sizeof(p_rss->rss_key));
2996 table_size = OSAL_MIN_T(u16, OSAL_ARRAY_SIZE(p_rss->rss_ind_table),
2997 (1 << p_rss_tlv->rss_table_size_log));
2999 for (i = 0; i < table_size; i++) {
3000 struct ecore_queue_cid *p_cid;
3002 q_idx = p_rss_tlv->rss_ind_table[i];
3003 if (!ecore_iov_validate_rxq(p_hwfn, vf, q_idx,
3004 ECORE_IOV_VALIDATE_Q_ENABLE)) {
3005 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3006 "VF[%d]: Omitting RSS due to wrong queue %04x\n",
3007 vf->relative_vf_id, q_idx);
3012 p_cid = ecore_iov_get_vf_rx_queue_cid(p_hwfn, vf,
3013 &vf->vf_queues[q_idx]);
3014 p_rss->rss_ind_table[i] = p_cid;
3017 p_data->rss_params = p_rss;
3019 *tlvs_mask |= 1 << ECORE_IOV_VP_UPDATE_RSS;
3021 *tlvs_accepted |= 1 << ECORE_IOV_VP_UPDATE_RSS;
3025 ecore_iov_vp_update_sge_tpa_param(struct ecore_hwfn *p_hwfn,
3026 struct ecore_vf_info *vf,
3027 struct ecore_sp_vport_update_params *p_data,
3028 struct ecore_sge_tpa_params *p_sge_tpa,
3029 struct ecore_iov_vf_mbx *p_mbx,
3032 struct vfpf_vport_update_sge_tpa_tlv *p_sge_tpa_tlv;
3033 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_SGE_TPA;
3035 p_sge_tpa_tlv = (struct vfpf_vport_update_sge_tpa_tlv *)
3036 ecore_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
3038 if (!p_sge_tpa_tlv) {
3039 p_data->sge_tpa_params = OSAL_NULL;
3043 OSAL_MEMSET(p_sge_tpa, 0, sizeof(struct ecore_sge_tpa_params));
3045 p_sge_tpa->update_tpa_en_flg =
3046 !!(p_sge_tpa_tlv->update_sge_tpa_flags & VFPF_UPDATE_TPA_EN_FLAG);
3047 p_sge_tpa->update_tpa_param_flg =
3048 !!(p_sge_tpa_tlv->update_sge_tpa_flags &
3049 VFPF_UPDATE_TPA_PARAM_FLAG);
3051 p_sge_tpa->tpa_ipv4_en_flg =
3052 !!(p_sge_tpa_tlv->sge_tpa_flags & VFPF_TPA_IPV4_EN_FLAG);
3053 p_sge_tpa->tpa_ipv6_en_flg =
3054 !!(p_sge_tpa_tlv->sge_tpa_flags & VFPF_TPA_IPV6_EN_FLAG);
3055 p_sge_tpa->tpa_pkt_split_flg =
3056 !!(p_sge_tpa_tlv->sge_tpa_flags & VFPF_TPA_PKT_SPLIT_FLAG);
3057 p_sge_tpa->tpa_hdr_data_split_flg =
3058 !!(p_sge_tpa_tlv->sge_tpa_flags & VFPF_TPA_HDR_DATA_SPLIT_FLAG);
3059 p_sge_tpa->tpa_gro_consistent_flg =
3060 !!(p_sge_tpa_tlv->sge_tpa_flags & VFPF_TPA_GRO_CONSIST_FLAG);
3062 p_sge_tpa->tpa_max_aggs_num = p_sge_tpa_tlv->tpa_max_aggs_num;
3063 p_sge_tpa->tpa_max_size = p_sge_tpa_tlv->tpa_max_size;
3064 p_sge_tpa->tpa_min_size_to_start = p_sge_tpa_tlv->tpa_min_size_to_start;
3065 p_sge_tpa->tpa_min_size_to_cont = p_sge_tpa_tlv->tpa_min_size_to_cont;
3066 p_sge_tpa->max_buffers_per_cqe = p_sge_tpa_tlv->max_buffers_per_cqe;
3068 p_data->sge_tpa_params = p_sge_tpa;
3070 *tlvs_mask |= 1 << ECORE_IOV_VP_UPDATE_SGE_TPA;
3073 static void ecore_iov_vf_mbx_vport_update(struct ecore_hwfn *p_hwfn,
3074 struct ecore_ptt *p_ptt,
3075 struct ecore_vf_info *vf)
3077 struct ecore_rss_params *p_rss_params = OSAL_NULL;
3078 struct ecore_sp_vport_update_params params;
3079 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
3080 struct ecore_sge_tpa_params sge_tpa_params;
3081 u16 tlvs_mask = 0, tlvs_accepted = 0;
3082 u8 status = PFVF_STATUS_SUCCESS;
3084 enum _ecore_status_t rc;
3086 /* Valiate PF can send such a request */
3087 if (!vf->vport_instance) {
3088 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3089 "No VPORT instance available for VF[%d],"
3090 " failing vport update\n",
3092 status = PFVF_STATUS_FAILURE;
3096 p_rss_params = OSAL_VZALLOC(p_hwfn->p_dev, sizeof(*p_rss_params));
3097 if (p_rss_params == OSAL_NULL) {
3098 status = PFVF_STATUS_FAILURE;
3102 OSAL_MEMSET(¶ms, 0, sizeof(params));
3103 params.opaque_fid = vf->opaque_fid;
3104 params.vport_id = vf->vport_id;
3105 params.rss_params = OSAL_NULL;
3107 /* Search for extended tlvs list and update values
3108 * from VF in struct ecore_sp_vport_update_params.
3110 ecore_iov_vp_update_act_param(p_hwfn, ¶ms, mbx, &tlvs_mask);
3111 ecore_iov_vp_update_vlan_param(p_hwfn, ¶ms, vf, mbx, &tlvs_mask);
3112 ecore_iov_vp_update_tx_switch(p_hwfn, ¶ms, mbx, &tlvs_mask);
3113 ecore_iov_vp_update_mcast_bin_param(p_hwfn, ¶ms, mbx, &tlvs_mask);
3114 ecore_iov_vp_update_accept_flag(p_hwfn, ¶ms, mbx, &tlvs_mask);
3115 ecore_iov_vp_update_accept_any_vlan(p_hwfn, ¶ms, mbx, &tlvs_mask);
3116 ecore_iov_vp_update_sge_tpa_param(p_hwfn, vf, ¶ms,
3117 &sge_tpa_params, mbx, &tlvs_mask);
3119 tlvs_accepted = tlvs_mask;
3121 /* Some of the extended TLVs need to be validated first; In that case,
3122 * they can update the mask without updating the accepted [so that
3123 * PF could communicate to VF it has rejected request].
3125 ecore_iov_vp_update_rss_param(p_hwfn, vf, ¶ms, p_rss_params,
3126 mbx, &tlvs_mask, &tlvs_accepted);
3128 /* Just log a message if there is no single extended tlv in buffer.
3129 * When all features of vport update ramrod would be requested by VF
3130 * as extended TLVs in buffer then an error can be returned in response
3131 * if there is no extended TLV present in buffer.
3133 if (OSAL_IOV_VF_VPORT_UPDATE(p_hwfn, vf->relative_vf_id,
3134 ¶ms, &tlvs_accepted) !=
3137 status = PFVF_STATUS_NOT_SUPPORTED;
3141 if (!tlvs_accepted) {
3143 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3144 "Upper-layer prevents said VF"
3145 " configuration\n");
3147 DP_NOTICE(p_hwfn, true,
3148 "No feature tlvs found for vport update\n");
3149 status = PFVF_STATUS_NOT_SUPPORTED;
3153 rc = ecore_sp_vport_update(p_hwfn, ¶ms, ECORE_SPQ_MODE_EBLOCK,
3157 status = PFVF_STATUS_FAILURE;
3160 OSAL_VFREE(p_hwfn->p_dev, p_rss_params);
3161 length = ecore_iov_prep_vp_update_resp_tlvs(p_hwfn, vf, mbx, status,
3162 tlvs_mask, tlvs_accepted);
3163 ecore_iov_send_response(p_hwfn, p_ptt, vf, length, status);
3166 static enum _ecore_status_t
3167 ecore_iov_vf_update_vlan_shadow(struct ecore_hwfn *p_hwfn,
3168 struct ecore_vf_info *p_vf,
3169 struct ecore_filter_ucast *p_params)
3173 /* First remove entries and then add new ones */
3174 if (p_params->opcode == ECORE_FILTER_REMOVE) {
3175 for (i = 0; i < ECORE_ETH_VF_NUM_VLAN_FILTERS + 1; i++)
3176 if (p_vf->shadow_config.vlans[i].used &&
3177 p_vf->shadow_config.vlans[i].vid ==
3179 p_vf->shadow_config.vlans[i].used = false;
3182 if (i == ECORE_ETH_VF_NUM_VLAN_FILTERS + 1) {
3183 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3184 "VF [%d] - Tries to remove a non-existing"
3186 p_vf->relative_vf_id);
3189 } else if (p_params->opcode == ECORE_FILTER_REPLACE ||
3190 p_params->opcode == ECORE_FILTER_FLUSH) {
3191 for (i = 0; i < ECORE_ETH_VF_NUM_VLAN_FILTERS + 1; i++)
3192 p_vf->shadow_config.vlans[i].used = false;
3195 /* In forced mode, we're willing to remove entries - but we don't add
3198 if (p_vf->bulletin.p_virt->valid_bitmap & (1 << VLAN_ADDR_FORCED))
3199 return ECORE_SUCCESS;
3201 if (p_params->opcode == ECORE_FILTER_ADD ||
3202 p_params->opcode == ECORE_FILTER_REPLACE) {
3203 for (i = 0; i < ECORE_ETH_VF_NUM_VLAN_FILTERS + 1; i++) {
3204 if (p_vf->shadow_config.vlans[i].used)
3207 p_vf->shadow_config.vlans[i].used = true;
3208 p_vf->shadow_config.vlans[i].vid = p_params->vlan;
3212 if (i == ECORE_ETH_VF_NUM_VLAN_FILTERS + 1) {
3213 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3214 "VF [%d] - Tries to configure more than %d"
3216 p_vf->relative_vf_id,
3217 ECORE_ETH_VF_NUM_VLAN_FILTERS + 1);
3222 return ECORE_SUCCESS;
3225 static enum _ecore_status_t
3226 ecore_iov_vf_update_mac_shadow(struct ecore_hwfn *p_hwfn,
3227 struct ecore_vf_info *p_vf,
3228 struct ecore_filter_ucast *p_params)
3230 char empty_mac[ETH_ALEN];
3233 OSAL_MEM_ZERO(empty_mac, ETH_ALEN);
3235 /* If we're in forced-mode, we don't allow any change */
3236 /* TODO - this would change if we were ever to implement logic for
3237 * removing a forced MAC altogether [in which case, like for vlans,
3238 * we should be able to re-trace previous configuration.
3240 if (p_vf->bulletin.p_virt->valid_bitmap & (1 << MAC_ADDR_FORCED))
3241 return ECORE_SUCCESS;
3243 /* First remove entries and then add new ones */
3244 if (p_params->opcode == ECORE_FILTER_REMOVE) {
3245 for (i = 0; i < ECORE_ETH_VF_NUM_MAC_FILTERS; i++) {
3246 if (!OSAL_MEMCMP(p_vf->shadow_config.macs[i],
3247 p_params->mac, ETH_ALEN)) {
3248 OSAL_MEM_ZERO(p_vf->shadow_config.macs[i],
3254 if (i == ECORE_ETH_VF_NUM_MAC_FILTERS) {
3255 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3256 "MAC isn't configured\n");
3259 } else if (p_params->opcode == ECORE_FILTER_REPLACE ||
3260 p_params->opcode == ECORE_FILTER_FLUSH) {
3261 for (i = 0; i < ECORE_ETH_VF_NUM_MAC_FILTERS; i++)
3262 OSAL_MEM_ZERO(p_vf->shadow_config.macs[i], ETH_ALEN);
3265 /* List the new MAC address */
3266 if (p_params->opcode != ECORE_FILTER_ADD &&
3267 p_params->opcode != ECORE_FILTER_REPLACE)
3268 return ECORE_SUCCESS;
3270 for (i = 0; i < ECORE_ETH_VF_NUM_MAC_FILTERS; i++) {
3271 if (!OSAL_MEMCMP(p_vf->shadow_config.macs[i],
3272 empty_mac, ETH_ALEN)) {
3273 OSAL_MEMCPY(p_vf->shadow_config.macs[i],
3274 p_params->mac, ETH_ALEN);
3275 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3276 "Added MAC at %d entry in shadow\n", i);
3281 if (i == ECORE_ETH_VF_NUM_MAC_FILTERS) {
3282 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3283 "No available place for MAC\n");
3287 return ECORE_SUCCESS;
3290 static enum _ecore_status_t
3291 ecore_iov_vf_update_unicast_shadow(struct ecore_hwfn *p_hwfn,
3292 struct ecore_vf_info *p_vf,
3293 struct ecore_filter_ucast *p_params)
3295 enum _ecore_status_t rc = ECORE_SUCCESS;
3297 if (p_params->type == ECORE_FILTER_MAC) {
3298 rc = ecore_iov_vf_update_mac_shadow(p_hwfn, p_vf, p_params);
3299 if (rc != ECORE_SUCCESS)
3303 if (p_params->type == ECORE_FILTER_VLAN)
3304 rc = ecore_iov_vf_update_vlan_shadow(p_hwfn, p_vf, p_params);
3309 static void ecore_iov_vf_mbx_ucast_filter(struct ecore_hwfn *p_hwfn,
3310 struct ecore_ptt *p_ptt,
3311 struct ecore_vf_info *vf)
3313 struct ecore_bulletin_content *p_bulletin = vf->bulletin.p_virt;
3314 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
3315 struct vfpf_ucast_filter_tlv *req;
3316 u8 status = PFVF_STATUS_SUCCESS;
3317 struct ecore_filter_ucast params;
3318 enum _ecore_status_t rc;
3320 /* Prepare the unicast filter params */
3321 OSAL_MEMSET(¶ms, 0, sizeof(struct ecore_filter_ucast));
3322 req = &mbx->req_virt->ucast_filter;
3323 params.opcode = (enum ecore_filter_opcode)req->opcode;
3324 params.type = (enum ecore_filter_ucast_type)req->type;
3326 /* @@@TBD - We might need logic on HV side in determining this */
3327 params.is_rx_filter = 1;
3328 params.is_tx_filter = 1;
3329 params.vport_to_remove_from = vf->vport_id;
3330 params.vport_to_add_to = vf->vport_id;
3331 OSAL_MEMCPY(params.mac, req->mac, ETH_ALEN);
3332 params.vlan = req->vlan;
3334 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3335 "VF[%d]: opcode 0x%02x type 0x%02x [%s %s] [vport 0x%02x]"
3336 " MAC %02x:%02x:%02x:%02x:%02x:%02x, vlan 0x%04x\n",
3337 vf->abs_vf_id, params.opcode, params.type,
3338 params.is_rx_filter ? "RX" : "",
3339 params.is_tx_filter ? "TX" : "",
3340 params.vport_to_add_to,
3341 params.mac[0], params.mac[1], params.mac[2],
3342 params.mac[3], params.mac[4], params.mac[5], params.vlan);
3344 if (!vf->vport_instance) {
3345 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3346 "No VPORT instance available for VF[%d],"
3347 " failing ucast MAC configuration\n",
3349 status = PFVF_STATUS_FAILURE;
3353 /* Update shadow copy of the VF configuration */
3354 if (ecore_iov_vf_update_unicast_shadow(p_hwfn, vf, ¶ms) !=
3356 status = PFVF_STATUS_FAILURE;
3360 /* Determine if the unicast filtering is acceptible by PF */
3361 if ((p_bulletin->valid_bitmap & (1 << VLAN_ADDR_FORCED)) &&
3362 (params.type == ECORE_FILTER_VLAN ||
3363 params.type == ECORE_FILTER_MAC_VLAN)) {
3364 /* Once VLAN is forced or PVID is set, do not allow
3365 * to add/replace any further VLANs.
3367 if (params.opcode == ECORE_FILTER_ADD ||
3368 params.opcode == ECORE_FILTER_REPLACE)
3369 status = PFVF_STATUS_FORCED;
3373 if ((p_bulletin->valid_bitmap & (1 << MAC_ADDR_FORCED)) &&
3374 (params.type == ECORE_FILTER_MAC ||
3375 params.type == ECORE_FILTER_MAC_VLAN)) {
3376 if (OSAL_MEMCMP(p_bulletin->mac, params.mac, ETH_ALEN) ||
3377 (params.opcode != ECORE_FILTER_ADD &&
3378 params.opcode != ECORE_FILTER_REPLACE))
3379 status = PFVF_STATUS_FORCED;
3383 rc = OSAL_IOV_CHK_UCAST(p_hwfn, vf->relative_vf_id, ¶ms);
3384 if (rc == ECORE_EXISTS) {
3386 } else if (rc == ECORE_INVAL) {
3387 status = PFVF_STATUS_FAILURE;
3391 rc = ecore_sp_eth_filter_ucast(p_hwfn, vf->opaque_fid, ¶ms,
3392 ECORE_SPQ_MODE_CB, OSAL_NULL);
3394 status = PFVF_STATUS_FAILURE;
3397 ecore_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_UCAST_FILTER,
3398 sizeof(struct pfvf_def_resp_tlv), status);
3401 static void ecore_iov_vf_mbx_int_cleanup(struct ecore_hwfn *p_hwfn,
3402 struct ecore_ptt *p_ptt,
3403 struct ecore_vf_info *vf)
3408 for (i = 0; i < vf->num_sbs; i++)
3409 ecore_int_igu_init_pure_rt_single(p_hwfn, p_ptt,
3411 vf->opaque_fid, false);
3413 ecore_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_INT_CLEANUP,
3414 sizeof(struct pfvf_def_resp_tlv),
3415 PFVF_STATUS_SUCCESS);
3418 static void ecore_iov_vf_mbx_close(struct ecore_hwfn *p_hwfn,
3419 struct ecore_ptt *p_ptt,
3420 struct ecore_vf_info *vf)
3422 u16 length = sizeof(struct pfvf_def_resp_tlv);
3423 u8 status = PFVF_STATUS_SUCCESS;
3425 /* Disable Interrupts for VF */
3426 ecore_iov_vf_igu_set_int(p_hwfn, p_ptt, vf, 0);
3428 /* Reset Permission table */
3429 ecore_iov_config_perm_table(p_hwfn, p_ptt, vf, 0);
3431 ecore_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_CLOSE,
3435 static void ecore_iov_vf_mbx_release(struct ecore_hwfn *p_hwfn,
3436 struct ecore_ptt *p_ptt,
3437 struct ecore_vf_info *p_vf)
3439 u16 length = sizeof(struct pfvf_def_resp_tlv);
3440 u8 status = PFVF_STATUS_SUCCESS;
3441 enum _ecore_status_t rc = ECORE_SUCCESS;
3443 ecore_iov_vf_cleanup(p_hwfn, p_vf);
3445 if (p_vf->state != VF_STOPPED && p_vf->state != VF_FREE) {
3446 /* Stopping the VF */
3447 rc = ecore_sp_vf_stop(p_hwfn, p_vf->concrete_fid,
3450 if (rc != ECORE_SUCCESS) {
3451 DP_ERR(p_hwfn, "ecore_sp_vf_stop returned error %d\n",
3453 status = PFVF_STATUS_FAILURE;
3456 p_vf->state = VF_STOPPED;
3459 ecore_iov_prepare_resp(p_hwfn, p_ptt, p_vf, CHANNEL_TLV_RELEASE,
3463 static void ecore_iov_vf_pf_set_coalesce(struct ecore_hwfn *p_hwfn,
3464 struct ecore_ptt *p_ptt,
3465 struct ecore_vf_info *vf)
3467 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
3468 enum _ecore_status_t rc = ECORE_SUCCESS;
3469 struct vfpf_update_coalesce *req;
3470 u8 status = PFVF_STATUS_FAILURE;
3471 struct ecore_queue_cid *p_cid;
3472 u16 rx_coal, tx_coal;
3476 req = &mbx->req_virt->update_coalesce;
3478 rx_coal = req->rx_coal;
3479 tx_coal = req->tx_coal;
3482 if (!ecore_iov_validate_rxq(p_hwfn, vf, qid,
3483 ECORE_IOV_VALIDATE_Q_ENABLE) &&
3485 DP_ERR(p_hwfn, "VF[%d]: Invalid Rx queue_id = %d\n",
3486 vf->abs_vf_id, qid);
3490 if (!ecore_iov_validate_txq(p_hwfn, vf, qid,
3491 ECORE_IOV_VALIDATE_Q_ENABLE) &&
3493 DP_ERR(p_hwfn, "VF[%d]: Invalid Tx queue_id = %d\n",
3494 vf->abs_vf_id, qid);
3498 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3499 "VF[%d]: Setting coalesce for VF rx_coal = %d, tx_coal = %d at queue = %d\n",
3500 vf->abs_vf_id, rx_coal, tx_coal, qid);
3503 p_cid = ecore_iov_get_vf_rx_queue_cid(p_hwfn, vf,
3504 &vf->vf_queues[qid]);
3506 rc = ecore_set_rxq_coalesce(p_hwfn, p_ptt, rx_coal, p_cid);
3507 if (rc != ECORE_SUCCESS) {
3508 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3509 "VF[%d]: Unable to set rx queue = %d coalesce\n",
3510 vf->abs_vf_id, vf->vf_queues[qid].fw_rx_qid);
3513 vf->rx_coal = rx_coal;
3516 /* TODO - in future, it might be possible to pass this in a per-cid
3517 * granularity. For now, do this for all Tx queues.
3520 struct ecore_vf_queue *p_queue = &vf->vf_queues[qid];
3522 for (i = 0; i < MAX_QUEUES_PER_QZONE; i++) {
3523 if (p_queue->cids[i].p_cid == OSAL_NULL)
3526 if (!p_queue->cids[i].b_is_tx)
3529 rc = ecore_set_txq_coalesce(p_hwfn, p_ptt, tx_coal,
3530 p_queue->cids[i].p_cid);
3531 if (rc != ECORE_SUCCESS) {
3532 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3533 "VF[%d]: Unable to set tx queue coalesce\n",
3538 vf->tx_coal = tx_coal;
3541 status = PFVF_STATUS_SUCCESS;
3543 ecore_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_COALESCE_UPDATE,
3544 sizeof(struct pfvf_def_resp_tlv), status);
3547 enum _ecore_status_t
3548 ecore_iov_pf_configure_vf_queue_coalesce(struct ecore_hwfn *p_hwfn,
3549 u16 rx_coal, u16 tx_coal,
3552 struct ecore_queue_cid *p_cid;
3553 struct ecore_vf_info *vf;
3554 struct ecore_ptt *p_ptt;
3557 if (!ecore_iov_is_valid_vfid(p_hwfn, vf_id, true, true)) {
3558 DP_NOTICE(p_hwfn, true,
3559 "VF[%d] - Can not set coalescing: VF is not active\n",
3564 vf = &p_hwfn->pf_iov_info->vfs_array[vf_id];
3565 p_ptt = ecore_ptt_acquire(p_hwfn);
3569 if (!ecore_iov_validate_rxq(p_hwfn, vf, qid,
3570 ECORE_IOV_VALIDATE_Q_ENABLE) &&
3572 DP_ERR(p_hwfn, "VF[%d]: Invalid Rx queue_id = %d\n",
3573 vf->abs_vf_id, qid);
3577 if (!ecore_iov_validate_txq(p_hwfn, vf, qid,
3578 ECORE_IOV_VALIDATE_Q_ENABLE) &&
3580 DP_ERR(p_hwfn, "VF[%d]: Invalid Tx queue_id = %d\n",
3581 vf->abs_vf_id, qid);
3585 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3586 "VF[%d]: Setting coalesce for VF rx_coal = %d, tx_coal = %d at queue = %d\n",
3587 vf->abs_vf_id, rx_coal, tx_coal, qid);
3590 p_cid = ecore_iov_get_vf_rx_queue_cid(p_hwfn, vf,
3591 &vf->vf_queues[qid]);
3593 rc = ecore_set_rxq_coalesce(p_hwfn, p_ptt, rx_coal, p_cid);
3594 if (rc != ECORE_SUCCESS) {
3595 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3596 "VF[%d]: Unable to set rx queue = %d coalesce\n",
3597 vf->abs_vf_id, vf->vf_queues[qid].fw_rx_qid);
3600 vf->rx_coal = rx_coal;
3603 /* TODO - in future, it might be possible to pass this in a per-cid
3604 * granularity. For now, do this for all Tx queues.
3607 struct ecore_vf_queue *p_queue = &vf->vf_queues[qid];
3609 for (i = 0; i < MAX_QUEUES_PER_QZONE; i++) {
3610 if (p_queue->cids[i].p_cid == OSAL_NULL)
3613 if (!p_queue->cids[i].b_is_tx)
3616 rc = ecore_set_txq_coalesce(p_hwfn, p_ptt, tx_coal,
3617 p_queue->cids[i].p_cid);
3618 if (rc != ECORE_SUCCESS) {
3619 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3620 "VF[%d]: Unable to set tx queue coalesce\n",
3625 vf->tx_coal = tx_coal;
3629 ecore_ptt_release(p_hwfn, p_ptt);
3634 static enum _ecore_status_t
3635 ecore_iov_vf_flr_poll_dorq(struct ecore_hwfn *p_hwfn,
3636 struct ecore_vf_info *p_vf, struct ecore_ptt *p_ptt)
3641 ecore_fid_pretend(p_hwfn, p_ptt, (u16)p_vf->concrete_fid);
3643 for (cnt = 0; cnt < 50; cnt++) {
3644 val = ecore_rd(p_hwfn, p_ptt, DORQ_REG_VF_USAGE_CNT);
3649 ecore_fid_pretend(p_hwfn, p_ptt, (u16)p_hwfn->hw_info.concrete_fid);
3653 "VF[%d] - dorq failed to cleanup [usage 0x%08x]\n",
3654 p_vf->abs_vf_id, val);
3655 return ECORE_TIMEOUT;
3658 return ECORE_SUCCESS;
3661 static enum _ecore_status_t
3662 ecore_iov_vf_flr_poll_pbf(struct ecore_hwfn *p_hwfn,
3663 struct ecore_vf_info *p_vf, struct ecore_ptt *p_ptt)
3665 u32 cons[MAX_NUM_VOQS], distance[MAX_NUM_VOQS];
3668 /* Read initial consumers & producers */
3669 for (i = 0; i < MAX_NUM_VOQS; i++) {
3672 cons[i] = ecore_rd(p_hwfn, p_ptt,
3673 PBF_REG_NUM_BLOCKS_ALLOCATED_CONS_VOQ0 +
3675 prod = ecore_rd(p_hwfn, p_ptt,
3676 PBF_REG_NUM_BLOCKS_ALLOCATED_PROD_VOQ0 +
3678 distance[i] = prod - cons[i];
3681 /* Wait for consumers to pass the producers */
3683 for (cnt = 0; cnt < 50; cnt++) {
3684 for (; i < MAX_NUM_VOQS; i++) {
3687 tmp = ecore_rd(p_hwfn, p_ptt,
3688 PBF_REG_NUM_BLOCKS_ALLOCATED_CONS_VOQ0 +
3690 if (distance[i] > tmp - cons[i])
3694 if (i == MAX_NUM_VOQS)
3701 DP_ERR(p_hwfn, "VF[%d] - pbf polling failed on VOQ %d\n",
3702 p_vf->abs_vf_id, i);
3703 return ECORE_TIMEOUT;
3706 return ECORE_SUCCESS;
3709 static enum _ecore_status_t ecore_iov_vf_flr_poll(struct ecore_hwfn *p_hwfn,
3710 struct ecore_vf_info *p_vf,
3711 struct ecore_ptt *p_ptt)
3713 enum _ecore_status_t rc;
3715 /* TODO - add SRC and TM polling once we add storage IOV */
3717 rc = ecore_iov_vf_flr_poll_dorq(p_hwfn, p_vf, p_ptt);
3721 rc = ecore_iov_vf_flr_poll_pbf(p_hwfn, p_vf, p_ptt);
3725 return ECORE_SUCCESS;
3728 static enum _ecore_status_t
3729 ecore_iov_execute_vf_flr_cleanup(struct ecore_hwfn *p_hwfn,
3730 struct ecore_ptt *p_ptt,
3731 u16 rel_vf_id, u32 *ack_vfs)
3733 struct ecore_vf_info *p_vf;
3734 enum _ecore_status_t rc = ECORE_SUCCESS;
3736 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, false);
3738 return ECORE_SUCCESS;
3740 if (p_hwfn->pf_iov_info->pending_flr[rel_vf_id / 64] &
3741 (1ULL << (rel_vf_id % 64))) {
3742 u16 vfid = p_vf->abs_vf_id;
3744 /* TODO - should we lock channel? */
3746 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3747 "VF[%d] - Handling FLR\n", vfid);
3749 ecore_iov_vf_cleanup(p_hwfn, p_vf);
3751 /* If VF isn't active, no need for anything but SW */
3755 /* TODO - what to do in case of failure? */
3756 rc = ecore_iov_vf_flr_poll(p_hwfn, p_vf, p_ptt);
3757 if (rc != ECORE_SUCCESS)
3760 rc = ecore_final_cleanup(p_hwfn, p_ptt, vfid, true);
3762 /* TODO - what's now? What a mess.... */
3763 DP_ERR(p_hwfn, "Failed handle FLR of VF[%d]\n", vfid);
3767 /* Workaround to make VF-PF channel ready, as FW
3768 * doesn't do that as a part of FLR.
3771 GTT_BAR0_MAP_REG_USDM_RAM +
3772 USTORM_VF_PF_CHANNEL_READY_OFFSET(vfid), 1);
3774 /* VF_STOPPED has to be set only after final cleanup
3775 * but prior to re-enabling the VF.
3777 p_vf->state = VF_STOPPED;
3779 rc = ecore_iov_enable_vf_access(p_hwfn, p_ptt, p_vf);
3781 /* TODO - again, a mess... */
3782 DP_ERR(p_hwfn, "Failed to re-enable VF[%d] acces\n",
3787 /* Mark VF for ack and clean pending state */
3788 if (p_vf->state == VF_RESET)
3789 p_vf->state = VF_STOPPED;
3790 ack_vfs[vfid / 32] |= (1 << (vfid % 32));
3791 p_hwfn->pf_iov_info->pending_flr[rel_vf_id / 64] &=
3792 ~(1ULL << (rel_vf_id % 64));
3793 p_vf->vf_mbx.b_pending_msg = false;
3799 enum _ecore_status_t ecore_iov_vf_flr_cleanup(struct ecore_hwfn *p_hwfn,
3800 struct ecore_ptt *p_ptt)
3802 u32 ack_vfs[VF_MAX_STATIC / 32];
3803 enum _ecore_status_t rc = ECORE_SUCCESS;
3806 OSAL_MEMSET(ack_vfs, 0, sizeof(u32) * (VF_MAX_STATIC / 32));
3808 /* Since BRB <-> PRS interface can't be tested as part of the flr
3809 * polling due to HW limitations, simply sleep a bit. And since
3810 * there's no need to wait per-vf, do it before looping.
3814 for (i = 0; i < p_hwfn->p_dev->p_iov_info->total_vfs; i++)
3815 ecore_iov_execute_vf_flr_cleanup(p_hwfn, p_ptt, i, ack_vfs);
3817 rc = ecore_mcp_ack_vf_flr(p_hwfn, p_ptt, ack_vfs);
3821 enum _ecore_status_t
3822 ecore_iov_single_vf_flr_cleanup(struct ecore_hwfn *p_hwfn,
3823 struct ecore_ptt *p_ptt, u16 rel_vf_id)
3825 u32 ack_vfs[VF_MAX_STATIC / 32];
3826 enum _ecore_status_t rc = ECORE_SUCCESS;
3828 OSAL_MEMSET(ack_vfs, 0, sizeof(u32) * (VF_MAX_STATIC / 32));
3830 /* Wait instead of polling the BRB <-> PRS interface */
3833 ecore_iov_execute_vf_flr_cleanup(p_hwfn, p_ptt, rel_vf_id, ack_vfs);
3835 rc = ecore_mcp_ack_vf_flr(p_hwfn, p_ptt, ack_vfs);
3839 bool ecore_iov_mark_vf_flr(struct ecore_hwfn *p_hwfn, u32 *p_disabled_vfs)
3844 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV, "Marking FLR-ed VFs\n");
3845 for (i = 0; i < (VF_MAX_STATIC / 32); i++)
3846 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3847 "[%08x,...,%08x]: %08x\n",
3848 i * 32, (i + 1) * 32 - 1, p_disabled_vfs[i]);
3850 if (!p_hwfn->p_dev->p_iov_info) {
3851 DP_NOTICE(p_hwfn, true, "VF flr but no IOV\n");
3856 for (i = 0; i < p_hwfn->p_dev->p_iov_info->total_vfs; i++) {
3857 struct ecore_vf_info *p_vf;
3860 p_vf = ecore_iov_get_vf_info(p_hwfn, i, false);
3864 vfid = p_vf->abs_vf_id;
3865 if ((1 << (vfid % 32)) & p_disabled_vfs[vfid / 32]) {
3866 u64 *p_flr = p_hwfn->pf_iov_info->pending_flr;
3867 u16 rel_vf_id = p_vf->relative_vf_id;
3869 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3870 "VF[%d] [rel %d] got FLR-ed\n",
3873 p_vf->state = VF_RESET;
3875 /* No need to lock here, since pending_flr should
3876 * only change here and before ACKing MFw. Since
3877 * MFW will not trigger an additional attention for
3878 * VF flr until ACKs, we're safe.
3880 p_flr[rel_vf_id / 64] |= 1ULL << (rel_vf_id % 64);
3888 void ecore_iov_get_link(struct ecore_hwfn *p_hwfn,
3890 struct ecore_mcp_link_params *p_params,
3891 struct ecore_mcp_link_state *p_link,
3892 struct ecore_mcp_link_capabilities *p_caps)
3894 struct ecore_vf_info *p_vf = ecore_iov_get_vf_info(p_hwfn, vfid, false);
3895 struct ecore_bulletin_content *p_bulletin;
3900 p_bulletin = p_vf->bulletin.p_virt;
3903 __ecore_vf_get_link_params(p_hwfn, p_params, p_bulletin);
3905 __ecore_vf_get_link_state(p_hwfn, p_link, p_bulletin);
3907 __ecore_vf_get_link_caps(p_hwfn, p_caps, p_bulletin);
3910 void ecore_iov_process_mbx_req(struct ecore_hwfn *p_hwfn,
3911 struct ecore_ptt *p_ptt, int vfid)
3913 struct ecore_iov_vf_mbx *mbx;
3914 struct ecore_vf_info *p_vf;
3916 p_vf = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
3920 mbx = &p_vf->vf_mbx;
3922 /* ecore_iov_process_mbx_request */
3923 #ifndef CONFIG_ECORE_SW_CHANNEL
3924 if (!mbx->b_pending_msg) {
3925 DP_NOTICE(p_hwfn, true,
3926 "VF[%02x]: Trying to process mailbox message when none is pending\n",
3930 mbx->b_pending_msg = false;
3933 mbx->first_tlv = mbx->req_virt->first_tlv;
3935 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3936 "VF[%02x]: Processing mailbox message [type %04x]\n",
3937 p_vf->abs_vf_id, mbx->first_tlv.tl.type);
3939 OSAL_IOV_VF_MSG_TYPE(p_hwfn,
3940 p_vf->relative_vf_id,
3941 mbx->first_tlv.tl.type);
3943 /* Lock the per vf op mutex and note the locker's identity.
3944 * The unlock will take place in mbx response.
3946 ecore_iov_lock_vf_pf_channel(p_hwfn,
3947 p_vf, mbx->first_tlv.tl.type);
3949 /* check if tlv type is known */
3950 if (ecore_iov_tlv_supported(mbx->first_tlv.tl.type) &&
3951 !p_vf->b_malicious) {
3952 /* switch on the opcode */
3953 switch (mbx->first_tlv.tl.type) {
3954 case CHANNEL_TLV_ACQUIRE:
3955 ecore_iov_vf_mbx_acquire(p_hwfn, p_ptt, p_vf);
3957 case CHANNEL_TLV_VPORT_START:
3958 ecore_iov_vf_mbx_start_vport(p_hwfn, p_ptt, p_vf);
3960 case CHANNEL_TLV_VPORT_TEARDOWN:
3961 ecore_iov_vf_mbx_stop_vport(p_hwfn, p_ptt, p_vf);
3963 case CHANNEL_TLV_START_RXQ:
3964 ecore_iov_vf_mbx_start_rxq(p_hwfn, p_ptt, p_vf);
3966 case CHANNEL_TLV_START_TXQ:
3967 ecore_iov_vf_mbx_start_txq(p_hwfn, p_ptt, p_vf);
3969 case CHANNEL_TLV_STOP_RXQS:
3970 ecore_iov_vf_mbx_stop_rxqs(p_hwfn, p_ptt, p_vf);
3972 case CHANNEL_TLV_STOP_TXQS:
3973 ecore_iov_vf_mbx_stop_txqs(p_hwfn, p_ptt, p_vf);
3975 case CHANNEL_TLV_UPDATE_RXQ:
3976 ecore_iov_vf_mbx_update_rxqs(p_hwfn, p_ptt, p_vf);
3978 case CHANNEL_TLV_VPORT_UPDATE:
3979 ecore_iov_vf_mbx_vport_update(p_hwfn, p_ptt, p_vf);
3981 case CHANNEL_TLV_UCAST_FILTER:
3982 ecore_iov_vf_mbx_ucast_filter(p_hwfn, p_ptt, p_vf);
3984 case CHANNEL_TLV_CLOSE:
3985 ecore_iov_vf_mbx_close(p_hwfn, p_ptt, p_vf);
3987 case CHANNEL_TLV_INT_CLEANUP:
3988 ecore_iov_vf_mbx_int_cleanup(p_hwfn, p_ptt, p_vf);
3990 case CHANNEL_TLV_RELEASE:
3991 ecore_iov_vf_mbx_release(p_hwfn, p_ptt, p_vf);
3993 case CHANNEL_TLV_UPDATE_TUNN_PARAM:
3994 ecore_iov_vf_mbx_update_tunn_param(p_hwfn, p_ptt, p_vf);
3996 case CHANNEL_TLV_COALESCE_UPDATE:
3997 ecore_iov_vf_pf_set_coalesce(p_hwfn, p_ptt, p_vf);
4000 } else if (ecore_iov_tlv_supported(mbx->first_tlv.tl.type)) {
4001 /* If we've received a message from a VF we consider malicious
4002 * we ignore the messasge unless it's one for RELEASE, in which
4003 * case we'll let it have the benefit of doubt, allowing the
4004 * next loaded driver to start again.
4006 if (mbx->first_tlv.tl.type == CHANNEL_TLV_RELEASE) {
4007 /* TODO - initiate FLR, remove malicious indication */
4008 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
4009 "VF [%02x] - considered malicious, but wanted to RELEASE. TODO\n",
4012 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
4013 "VF [%02x] - considered malicious; Ignoring TLV [%04x]\n",
4014 p_vf->abs_vf_id, mbx->first_tlv.tl.type);
4017 ecore_iov_prepare_resp(p_hwfn, p_ptt, p_vf,
4018 mbx->first_tlv.tl.type,
4019 sizeof(struct pfvf_def_resp_tlv),
4020 PFVF_STATUS_MALICIOUS);
4022 /* unknown TLV - this may belong to a VF driver from the future
4023 * - a version written after this PF driver was written, which
4024 * supports features unknown as of yet. Too bad since we don't
4025 * support them. Or this may be because someone wrote a crappy
4026 * VF driver and is sending garbage over the channel.
4028 DP_NOTICE(p_hwfn, false,
4029 "VF[%02x]: unknown TLV. type %04x length %04x"
4030 " padding %08x reply address %lu\n",
4032 mbx->first_tlv.tl.type,
4033 mbx->first_tlv.tl.length,
4034 mbx->first_tlv.padding,
4035 (unsigned long)mbx->first_tlv.reply_address);
4037 /* Try replying in case reply address matches the acquisition's
4040 if (p_vf->acquire.first_tlv.reply_address &&
4041 (mbx->first_tlv.reply_address ==
4042 p_vf->acquire.first_tlv.reply_address))
4043 ecore_iov_prepare_resp(p_hwfn, p_ptt, p_vf,
4044 mbx->first_tlv.tl.type,
4045 sizeof(struct pfvf_def_resp_tlv),
4046 PFVF_STATUS_NOT_SUPPORTED);
4048 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
4049 "VF[%02x]: Can't respond to TLV -"
4050 " no valid reply address\n",
4054 ecore_iov_unlock_vf_pf_channel(p_hwfn, p_vf,
4055 mbx->first_tlv.tl.type);
4057 #ifdef CONFIG_ECORE_SW_CHANNEL
4058 mbx->sw_mbx.mbx_state = VF_PF_RESPONSE_READY;
4059 mbx->sw_mbx.response_offset = 0;
4063 void ecore_iov_pf_get_pending_events(struct ecore_hwfn *p_hwfn,
4068 OSAL_MEM_ZERO(events, sizeof(u64) * ECORE_VF_ARRAY_LENGTH);
4070 ecore_for_each_vf(p_hwfn, i) {
4071 struct ecore_vf_info *p_vf;
4073 p_vf = &p_hwfn->pf_iov_info->vfs_array[i];
4074 if (p_vf->vf_mbx.b_pending_msg)
4075 events[i / 64] |= 1ULL << (i % 64);
4079 static struct ecore_vf_info *
4080 ecore_sriov_get_vf_from_absid(struct ecore_hwfn *p_hwfn, u16 abs_vfid)
4082 u8 min = (u8)p_hwfn->p_dev->p_iov_info->first_vf_in_pf;
4084 if (!_ecore_iov_pf_sanity_check(p_hwfn, (int)abs_vfid - min, false)) {
4085 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
4086 "Got indication for VF [abs 0x%08x] that cannot be"
4092 return &p_hwfn->pf_iov_info->vfs_array[(u8)abs_vfid - min];
4095 static enum _ecore_status_t ecore_sriov_vfpf_msg(struct ecore_hwfn *p_hwfn,
4097 struct regpair *vf_msg)
4099 struct ecore_vf_info *p_vf = ecore_sriov_get_vf_from_absid(p_hwfn,
4103 return ECORE_SUCCESS;
4105 /* List the physical address of the request so that handler
4106 * could later on copy the message from it.
4108 p_vf->vf_mbx.pending_req = (((u64)vf_msg->hi) << 32) | vf_msg->lo;
4110 p_vf->vf_mbx.b_pending_msg = true;
4112 return OSAL_PF_VF_MSG(p_hwfn, p_vf->relative_vf_id);
4115 static void ecore_sriov_vfpf_malicious(struct ecore_hwfn *p_hwfn,
4116 struct malicious_vf_eqe_data *p_data)
4118 struct ecore_vf_info *p_vf;
4120 p_vf = ecore_sriov_get_vf_from_absid(p_hwfn, p_data->vfId);
4126 "VF [%d] - Malicious behavior [%02x]\n",
4127 p_vf->abs_vf_id, p_data->errId);
4129 p_vf->b_malicious = true;
4131 OSAL_PF_VF_MALICIOUS(p_hwfn, p_vf->relative_vf_id);
4134 enum _ecore_status_t ecore_sriov_eqe_event(struct ecore_hwfn *p_hwfn,
4137 union event_ring_data *data)
4140 case COMMON_EVENT_VF_PF_CHANNEL:
4141 return ecore_sriov_vfpf_msg(p_hwfn, OSAL_LE16_TO_CPU(echo),
4142 &data->vf_pf_channel.msg_addr);
4143 case COMMON_EVENT_VF_FLR:
4144 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
4145 "VF-FLR is still not supported\n");
4146 return ECORE_SUCCESS;
4147 case COMMON_EVENT_MALICIOUS_VF:
4148 ecore_sriov_vfpf_malicious(p_hwfn, &data->malicious_vf);
4149 return ECORE_SUCCESS;
4151 DP_INFO(p_hwfn->p_dev, "Unknown sriov eqe event 0x%02x\n",
4157 bool ecore_iov_is_vf_pending_flr(struct ecore_hwfn *p_hwfn, u16 rel_vf_id)
4159 return !!(p_hwfn->pf_iov_info->pending_flr[rel_vf_id / 64] &
4160 (1ULL << (rel_vf_id % 64)));
4163 u16 ecore_iov_get_next_active_vf(struct ecore_hwfn *p_hwfn, u16 rel_vf_id)
4165 struct ecore_hw_sriov_info *p_iov = p_hwfn->p_dev->p_iov_info;
4171 for (i = rel_vf_id; i < p_iov->total_vfs; i++)
4172 if (ecore_iov_is_valid_vfid(p_hwfn, rel_vf_id, true, false))
4176 return E4_MAX_NUM_VFS;
4179 enum _ecore_status_t ecore_iov_copy_vf_msg(struct ecore_hwfn *p_hwfn,
4180 struct ecore_ptt *ptt, int vfid)
4182 struct ecore_dmae_params params;
4183 struct ecore_vf_info *vf_info;
4185 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4189 OSAL_MEMSET(¶ms, 0, sizeof(struct ecore_dmae_params));
4190 params.flags = ECORE_DMAE_FLAG_VF_SRC | ECORE_DMAE_FLAG_COMPLETION_DST;
4191 params.src_vfid = vf_info->abs_vf_id;
4193 if (ecore_dmae_host2host(p_hwfn, ptt,
4194 vf_info->vf_mbx.pending_req,
4195 vf_info->vf_mbx.req_phys,
4196 sizeof(union vfpf_tlvs) / 4, ¶ms)) {
4197 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
4198 "Failed to copy message from VF 0x%02x\n", vfid);
4203 return ECORE_SUCCESS;
4206 void ecore_iov_bulletin_set_forced_mac(struct ecore_hwfn *p_hwfn,
4209 struct ecore_vf_info *vf_info;
4212 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4214 DP_NOTICE(p_hwfn->p_dev, true,
4215 "Can not set forced MAC, invalid vfid [%d]\n", vfid);
4218 if (vf_info->b_malicious) {
4219 DP_NOTICE(p_hwfn->p_dev, false,
4220 "Can't set forced MAC to malicious VF [%d]\n",
4225 feature = 1 << MAC_ADDR_FORCED;
4226 OSAL_MEMCPY(vf_info->bulletin.p_virt->mac, mac, ETH_ALEN);
4228 vf_info->bulletin.p_virt->valid_bitmap |= feature;
4229 /* Forced MAC will disable MAC_ADDR */
4230 vf_info->bulletin.p_virt->valid_bitmap &=
4231 ~(1 << VFPF_BULLETIN_MAC_ADDR);
4233 ecore_iov_configure_vport_forced(p_hwfn, vf_info, feature);
4236 enum _ecore_status_t ecore_iov_bulletin_set_mac(struct ecore_hwfn *p_hwfn,
4239 struct ecore_vf_info *vf_info;
4242 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4244 DP_NOTICE(p_hwfn->p_dev, true,
4245 "Can not set MAC, invalid vfid [%d]\n", vfid);
4248 if (vf_info->b_malicious) {
4249 DP_NOTICE(p_hwfn->p_dev, false,
4250 "Can't set MAC to malicious VF [%d]\n",
4255 if (vf_info->bulletin.p_virt->valid_bitmap & (1 << MAC_ADDR_FORCED)) {
4256 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
4257 "Can not set MAC, Forced MAC is configured\n");
4261 feature = 1 << VFPF_BULLETIN_MAC_ADDR;
4262 OSAL_MEMCPY(vf_info->bulletin.p_virt->mac, mac, ETH_ALEN);
4264 vf_info->bulletin.p_virt->valid_bitmap |= feature;
4266 return ECORE_SUCCESS;
4269 enum _ecore_status_t
4270 ecore_iov_bulletin_set_forced_untagged_default(struct ecore_hwfn *p_hwfn,
4271 bool b_untagged_only, int vfid)
4273 struct ecore_vf_info *vf_info;
4276 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4278 DP_NOTICE(p_hwfn->p_dev, true,
4279 "Can not set untagged default, invalid vfid [%d]\n",
4283 if (vf_info->b_malicious) {
4284 DP_NOTICE(p_hwfn->p_dev, false,
4285 "Can't set untagged default to malicious VF [%d]\n",
4290 /* Since this is configurable only during vport-start, don't take it
4291 * if we're past that point.
4293 if (vf_info->state == VF_ENABLED) {
4294 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
4295 "Can't support untagged change for vfid[%d] -"
4296 " VF is already active\n",
4301 /* Set configuration; This will later be taken into account during the
4302 * VF initialization.
4304 feature = (1 << VFPF_BULLETIN_UNTAGGED_DEFAULT) |
4305 (1 << VFPF_BULLETIN_UNTAGGED_DEFAULT_FORCED);
4306 vf_info->bulletin.p_virt->valid_bitmap |= feature;
4308 vf_info->bulletin.p_virt->default_only_untagged = b_untagged_only ? 1
4311 return ECORE_SUCCESS;
4314 void ecore_iov_get_vfs_opaque_fid(struct ecore_hwfn *p_hwfn, int vfid,
4317 struct ecore_vf_info *vf_info;
4319 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4323 *opaque_fid = vf_info->opaque_fid;
4326 void ecore_iov_bulletin_set_forced_vlan(struct ecore_hwfn *p_hwfn,
4329 struct ecore_vf_info *vf_info;
4332 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4334 DP_NOTICE(p_hwfn->p_dev, true,
4335 "Can not set forced MAC, invalid vfid [%d]\n",
4339 if (vf_info->b_malicious) {
4340 DP_NOTICE(p_hwfn->p_dev, false,
4341 "Can't set forced vlan to malicious VF [%d]\n",
4346 feature = 1 << VLAN_ADDR_FORCED;
4347 vf_info->bulletin.p_virt->pvid = pvid;
4349 vf_info->bulletin.p_virt->valid_bitmap |= feature;
4351 vf_info->bulletin.p_virt->valid_bitmap &= ~feature;
4353 ecore_iov_configure_vport_forced(p_hwfn, vf_info, feature);
4356 void ecore_iov_bulletin_set_udp_ports(struct ecore_hwfn *p_hwfn,
4357 int vfid, u16 vxlan_port, u16 geneve_port)
4359 struct ecore_vf_info *vf_info;
4361 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4363 DP_NOTICE(p_hwfn->p_dev, true,
4364 "Can not set udp ports, invalid vfid [%d]\n", vfid);
4368 if (vf_info->b_malicious) {
4369 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
4370 "Can not set udp ports to malicious VF [%d]\n",
4375 vf_info->bulletin.p_virt->vxlan_udp_port = vxlan_port;
4376 vf_info->bulletin.p_virt->geneve_udp_port = geneve_port;
4379 bool ecore_iov_vf_has_vport_instance(struct ecore_hwfn *p_hwfn, int vfid)
4381 struct ecore_vf_info *p_vf_info;
4383 p_vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4387 return !!p_vf_info->vport_instance;
4390 bool ecore_iov_is_vf_stopped(struct ecore_hwfn *p_hwfn, int vfid)
4392 struct ecore_vf_info *p_vf_info;
4394 p_vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4398 return p_vf_info->state == VF_STOPPED;
4401 bool ecore_iov_spoofchk_get(struct ecore_hwfn *p_hwfn, int vfid)
4403 struct ecore_vf_info *vf_info;
4405 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4409 return vf_info->spoof_chk;
4412 enum _ecore_status_t ecore_iov_spoofchk_set(struct ecore_hwfn *p_hwfn,
4415 struct ecore_vf_info *vf;
4416 enum _ecore_status_t rc = ECORE_INVAL;
4418 if (!ecore_iov_pf_sanity_check(p_hwfn, vfid)) {
4419 DP_NOTICE(p_hwfn, true,
4420 "SR-IOV sanity check failed, can't set spoofchk\n");
4424 vf = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4428 if (!ecore_iov_vf_has_vport_instance(p_hwfn, vfid)) {
4429 /* After VF VPORT start PF will configure spoof check */
4430 vf->req_spoofchk_val = val;
4435 rc = __ecore_iov_spoofchk_set(p_hwfn, vf, val);
4441 u8 ecore_iov_vf_chains_per_pf(struct ecore_hwfn *p_hwfn)
4443 u8 max_chains_per_vf = p_hwfn->hw_info.max_chains_per_vf;
4445 max_chains_per_vf = (max_chains_per_vf) ? max_chains_per_vf
4446 : ECORE_MAX_VF_CHAINS_PER_PF;
4448 return max_chains_per_vf;
4451 void ecore_iov_get_vf_req_virt_mbx_params(struct ecore_hwfn *p_hwfn,
4453 void **pp_req_virt_addr,
4454 u16 *p_req_virt_size)
4456 struct ecore_vf_info *vf_info =
4457 ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4462 if (pp_req_virt_addr)
4463 *pp_req_virt_addr = vf_info->vf_mbx.req_virt;
4465 if (p_req_virt_size)
4466 *p_req_virt_size = sizeof(*vf_info->vf_mbx.req_virt);
4469 void ecore_iov_get_vf_reply_virt_mbx_params(struct ecore_hwfn *p_hwfn,
4471 void **pp_reply_virt_addr,
4472 u16 *p_reply_virt_size)
4474 struct ecore_vf_info *vf_info =
4475 ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4480 if (pp_reply_virt_addr)
4481 *pp_reply_virt_addr = vf_info->vf_mbx.reply_virt;
4483 if (p_reply_virt_size)
4484 *p_reply_virt_size = sizeof(*vf_info->vf_mbx.reply_virt);
4487 #ifdef CONFIG_ECORE_SW_CHANNEL
4488 struct ecore_iov_sw_mbx *ecore_iov_get_vf_sw_mbx(struct ecore_hwfn *p_hwfn,
4491 struct ecore_vf_info *vf_info =
4492 ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4497 return &vf_info->vf_mbx.sw_mbx;
4501 bool ecore_iov_is_valid_vfpf_msg_length(u32 length)
4503 return (length >= sizeof(struct vfpf_first_tlv) &&
4504 (length <= sizeof(union vfpf_tlvs)));
4507 u32 ecore_iov_pfvf_msg_length(void)
4509 return sizeof(union pfvf_tlvs);
4512 u8 *ecore_iov_bulletin_get_forced_mac(struct ecore_hwfn *p_hwfn, u16 rel_vf_id)
4514 struct ecore_vf_info *p_vf;
4516 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4517 if (!p_vf || !p_vf->bulletin.p_virt)
4520 if (!(p_vf->bulletin.p_virt->valid_bitmap & (1 << MAC_ADDR_FORCED)))
4523 return p_vf->bulletin.p_virt->mac;
4526 u16 ecore_iov_bulletin_get_forced_vlan(struct ecore_hwfn *p_hwfn,
4529 struct ecore_vf_info *p_vf;
4531 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4532 if (!p_vf || !p_vf->bulletin.p_virt)
4535 if (!(p_vf->bulletin.p_virt->valid_bitmap & (1 << VLAN_ADDR_FORCED)))
4538 return p_vf->bulletin.p_virt->pvid;
4541 enum _ecore_status_t ecore_iov_configure_tx_rate(struct ecore_hwfn *p_hwfn,
4542 struct ecore_ptt *p_ptt,
4545 struct ecore_vf_info *vf;
4547 enum _ecore_status_t rc;
4549 vf = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4554 rc = ecore_fw_vport(p_hwfn, vf->vport_id, &abs_vp_id);
4555 if (rc != ECORE_SUCCESS)
4558 return ecore_init_vport_rl(p_hwfn, p_ptt, abs_vp_id, (u32)val);
4561 enum _ecore_status_t ecore_iov_get_vf_stats(struct ecore_hwfn *p_hwfn,
4562 struct ecore_ptt *p_ptt,
4564 struct ecore_eth_stats *p_stats)
4566 struct ecore_vf_info *vf;
4568 vf = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4572 if (vf->state != VF_ENABLED)
4575 __ecore_get_vport_stats(p_hwfn, p_ptt, p_stats,
4576 vf->abs_vf_id + 0x10, false);
4578 return ECORE_SUCCESS;
4581 u8 ecore_iov_get_vf_num_rxqs(struct ecore_hwfn *p_hwfn, u16 rel_vf_id)
4583 struct ecore_vf_info *p_vf;
4585 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4589 return p_vf->num_rxqs;
4592 u8 ecore_iov_get_vf_num_active_rxqs(struct ecore_hwfn *p_hwfn, u16 rel_vf_id)
4594 struct ecore_vf_info *p_vf;
4596 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4600 return p_vf->num_active_rxqs;
4603 void *ecore_iov_get_vf_ctx(struct ecore_hwfn *p_hwfn, u16 rel_vf_id)
4605 struct ecore_vf_info *p_vf;
4607 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4614 u8 ecore_iov_get_vf_num_sbs(struct ecore_hwfn *p_hwfn, u16 rel_vf_id)
4616 struct ecore_vf_info *p_vf;
4618 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4622 return p_vf->num_sbs;
4625 bool ecore_iov_is_vf_wait_for_acquire(struct ecore_hwfn *p_hwfn, u16 rel_vf_id)
4627 struct ecore_vf_info *p_vf;
4629 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4633 return (p_vf->state == VF_FREE);
4636 bool ecore_iov_is_vf_acquired_not_initialized(struct ecore_hwfn *p_hwfn,
4639 struct ecore_vf_info *p_vf;
4641 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4645 return (p_vf->state == VF_ACQUIRED);
4648 bool ecore_iov_is_vf_initialized(struct ecore_hwfn *p_hwfn, u16 rel_vf_id)
4650 struct ecore_vf_info *p_vf;
4652 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4656 return (p_vf->state == VF_ENABLED);
4659 bool ecore_iov_is_vf_started(struct ecore_hwfn *p_hwfn,
4662 struct ecore_vf_info *p_vf;
4664 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4668 return (p_vf->state != VF_FREE && p_vf->state != VF_STOPPED);
4671 enum _ecore_status_t
4672 ecore_iov_get_vf_min_rate(struct ecore_hwfn *p_hwfn, int vfid)
4674 struct ecore_wfq_data *vf_vp_wfq;
4675 struct ecore_vf_info *vf_info;
4677 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4681 vf_vp_wfq = &p_hwfn->qm_info.wfq_data[vf_info->vport_id];
4683 if (vf_vp_wfq->configured)
4684 return vf_vp_wfq->min_speed;