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 enum _ecore_status_t ecore_sp_vf_start(struct ecore_hwfn *p_hwfn,
61 struct ecore_vf_info *p_vf)
63 struct vf_start_ramrod_data *p_ramrod = OSAL_NULL;
64 struct ecore_spq_entry *p_ent = OSAL_NULL;
65 struct ecore_sp_init_data init_data;
66 enum _ecore_status_t rc = ECORE_NOTIMPL;
70 OSAL_MEMSET(&init_data, 0, sizeof(init_data));
71 init_data.cid = ecore_spq_get_cid(p_hwfn);
72 init_data.opaque_fid = p_vf->opaque_fid;
73 init_data.comp_mode = ECORE_SPQ_MODE_EBLOCK;
75 rc = ecore_sp_init_request(p_hwfn, &p_ent,
76 COMMON_RAMROD_VF_START,
77 PROTOCOLID_COMMON, &init_data);
78 if (rc != ECORE_SUCCESS)
81 p_ramrod = &p_ent->ramrod.vf_start;
83 p_ramrod->vf_id = GET_FIELD(p_vf->concrete_fid, PXP_CONCRETE_FID_VFID);
84 p_ramrod->opaque_fid = OSAL_CPU_TO_LE16(p_vf->opaque_fid);
86 switch (p_hwfn->hw_info.personality) {
88 p_ramrod->personality = PERSONALITY_ETH;
90 case ECORE_PCI_ETH_ROCE:
91 case ECORE_PCI_ETH_IWARP:
92 p_ramrod->personality = PERSONALITY_RDMA_AND_ETH;
95 DP_NOTICE(p_hwfn, true, "Unknown VF personality %d\n",
96 p_hwfn->hw_info.personality);
100 fp_minor = p_vf->acquire.vfdev_info.eth_fp_hsi_minor;
101 if (fp_minor > ETH_HSI_VER_MINOR &&
102 fp_minor != ETH_HSI_VER_NO_PKT_LEN_TUNN) {
103 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
104 "VF [%d] - Requested fp hsi %02x.%02x which is"
105 " slightly newer than PF's %02x.%02x; Configuring"
108 ETH_HSI_VER_MAJOR, fp_minor,
109 ETH_HSI_VER_MAJOR, ETH_HSI_VER_MINOR);
110 fp_minor = ETH_HSI_VER_MINOR;
113 p_ramrod->hsi_fp_ver.major_ver_arr[ETH_VER_KEY] = ETH_HSI_VER_MAJOR;
114 p_ramrod->hsi_fp_ver.minor_ver_arr[ETH_VER_KEY] = fp_minor;
116 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
117 "VF[%d] - Starting using HSI %02x.%02x\n",
118 p_vf->abs_vf_id, ETH_HSI_VER_MAJOR, fp_minor);
120 return ecore_spq_post(p_hwfn, p_ent, OSAL_NULL);
123 static enum _ecore_status_t ecore_sp_vf_stop(struct ecore_hwfn *p_hwfn,
127 struct vf_stop_ramrod_data *p_ramrod = OSAL_NULL;
128 struct ecore_spq_entry *p_ent = OSAL_NULL;
129 struct ecore_sp_init_data init_data;
130 enum _ecore_status_t rc = ECORE_NOTIMPL;
133 OSAL_MEMSET(&init_data, 0, sizeof(init_data));
134 init_data.cid = ecore_spq_get_cid(p_hwfn);
135 init_data.opaque_fid = opaque_vfid;
136 init_data.comp_mode = ECORE_SPQ_MODE_EBLOCK;
138 rc = ecore_sp_init_request(p_hwfn, &p_ent,
139 COMMON_RAMROD_VF_STOP,
140 PROTOCOLID_COMMON, &init_data);
141 if (rc != ECORE_SUCCESS)
144 p_ramrod = &p_ent->ramrod.vf_stop;
146 p_ramrod->vf_id = GET_FIELD(concrete_vfid, PXP_CONCRETE_FID_VFID);
148 return ecore_spq_post(p_hwfn, p_ent, OSAL_NULL);
151 bool ecore_iov_is_valid_vfid(struct ecore_hwfn *p_hwfn, int rel_vf_id,
152 bool b_enabled_only, bool b_non_malicious)
154 if (!p_hwfn->pf_iov_info) {
155 DP_NOTICE(p_hwfn->p_dev, true, "No iov info\n");
159 if ((rel_vf_id >= p_hwfn->p_dev->p_iov_info->total_vfs) ||
163 if ((!p_hwfn->pf_iov_info->vfs_array[rel_vf_id].b_init) &&
167 if ((p_hwfn->pf_iov_info->vfs_array[rel_vf_id].b_malicious) &&
174 struct ecore_vf_info *ecore_iov_get_vf_info(struct ecore_hwfn *p_hwfn,
178 struct ecore_vf_info *vf = OSAL_NULL;
180 if (!p_hwfn->pf_iov_info) {
181 DP_NOTICE(p_hwfn->p_dev, true, "No iov info\n");
185 if (ecore_iov_is_valid_vfid(p_hwfn, relative_vf_id,
186 b_enabled_only, false))
187 vf = &p_hwfn->pf_iov_info->vfs_array[relative_vf_id];
189 DP_ERR(p_hwfn, "ecore_iov_get_vf_info: VF[%d] is not enabled\n",
195 static struct ecore_queue_cid *
196 ecore_iov_get_vf_rx_queue_cid(struct ecore_hwfn *p_hwfn,
197 struct ecore_vf_info *p_vf,
198 struct ecore_vf_queue *p_queue)
202 for (i = 0; i < MAX_QUEUES_PER_QZONE; i++) {
203 if (p_queue->cids[i].p_cid &&
204 !p_queue->cids[i].b_is_tx)
205 return p_queue->cids[i].p_cid;
211 enum ecore_iov_validate_q_mode {
212 ECORE_IOV_VALIDATE_Q_NA,
213 ECORE_IOV_VALIDATE_Q_ENABLE,
214 ECORE_IOV_VALIDATE_Q_DISABLE,
217 static bool ecore_iov_validate_queue_mode(struct ecore_hwfn *p_hwfn,
218 struct ecore_vf_info *p_vf,
220 enum ecore_iov_validate_q_mode mode,
225 if (mode == ECORE_IOV_VALIDATE_Q_NA)
228 for (i = 0; i < MAX_QUEUES_PER_QZONE; i++) {
229 struct ecore_vf_queue_cid *p_qcid;
231 p_qcid = &p_vf->vf_queues[qid].cids[i];
233 if (p_qcid->p_cid == OSAL_NULL)
236 if (p_qcid->b_is_tx != b_is_tx)
239 /* Found. It's enabled. */
240 return (mode == ECORE_IOV_VALIDATE_Q_ENABLE);
243 /* In case we haven't found any valid cid, then its disabled */
244 return (mode == ECORE_IOV_VALIDATE_Q_DISABLE);
247 static bool ecore_iov_validate_rxq(struct ecore_hwfn *p_hwfn,
248 struct ecore_vf_info *p_vf,
250 enum ecore_iov_validate_q_mode mode)
252 if (rx_qid >= p_vf->num_rxqs) {
253 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
254 "VF[0x%02x] - can't touch Rx queue[%04x];"
255 " Only 0x%04x are allocated\n",
256 p_vf->abs_vf_id, rx_qid, p_vf->num_rxqs);
260 return ecore_iov_validate_queue_mode(p_hwfn, p_vf, rx_qid,
264 static bool ecore_iov_validate_txq(struct ecore_hwfn *p_hwfn,
265 struct ecore_vf_info *p_vf,
267 enum ecore_iov_validate_q_mode mode)
269 if (tx_qid >= p_vf->num_txqs) {
270 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
271 "VF[0x%02x] - can't touch Tx queue[%04x];"
272 " Only 0x%04x are allocated\n",
273 p_vf->abs_vf_id, tx_qid, p_vf->num_txqs);
277 return ecore_iov_validate_queue_mode(p_hwfn, p_vf, tx_qid,
281 static bool ecore_iov_validate_sb(struct ecore_hwfn *p_hwfn,
282 struct ecore_vf_info *p_vf,
287 for (i = 0; i < p_vf->num_sbs; i++)
288 if (p_vf->igu_sbs[i] == sb_idx)
291 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
292 "VF[0%02x] - tried using sb_idx %04x which doesn't exist as"
293 " one of its 0x%02x SBs\n",
294 p_vf->abs_vf_id, sb_idx, p_vf->num_sbs);
299 /* Is there at least 1 queue open? */
300 static bool ecore_iov_validate_active_rxq(struct ecore_hwfn *p_hwfn,
301 struct ecore_vf_info *p_vf)
305 for (i = 0; i < p_vf->num_rxqs; i++)
306 if (ecore_iov_validate_queue_mode(p_hwfn, p_vf, i,
307 ECORE_IOV_VALIDATE_Q_ENABLE,
314 static bool ecore_iov_validate_active_txq(struct ecore_hwfn *p_hwfn,
315 struct ecore_vf_info *p_vf)
319 for (i = 0; i < p_vf->num_txqs; i++)
320 if (ecore_iov_validate_queue_mode(p_hwfn, p_vf, i,
321 ECORE_IOV_VALIDATE_Q_ENABLE,
328 enum _ecore_status_t ecore_iov_post_vf_bulletin(struct ecore_hwfn *p_hwfn,
330 struct ecore_ptt *p_ptt)
332 struct ecore_bulletin_content *p_bulletin;
333 int crc_size = sizeof(p_bulletin->crc);
334 struct ecore_dmae_params params;
335 struct ecore_vf_info *p_vf;
337 p_vf = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
341 /* TODO - check VF is in a state where it can accept message */
342 if (!p_vf->vf_bulletin)
345 p_bulletin = p_vf->bulletin.p_virt;
347 /* Increment bulletin board version and compute crc */
348 p_bulletin->version++;
349 p_bulletin->crc = OSAL_CRC32(0, (u8 *)p_bulletin + crc_size,
350 p_vf->bulletin.size - crc_size);
352 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
353 "Posting Bulletin 0x%08x to VF[%d] (CRC 0x%08x)\n",
354 p_bulletin->version, p_vf->relative_vf_id, p_bulletin->crc);
356 /* propagate bulletin board via dmae to vm memory */
357 OSAL_MEMSET(¶ms, 0, sizeof(params));
358 params.flags = ECORE_DMAE_FLAG_VF_DST;
359 params.dst_vfid = p_vf->abs_vf_id;
360 return ecore_dmae_host2host(p_hwfn, p_ptt, p_vf->bulletin.phys,
361 p_vf->vf_bulletin, p_vf->bulletin.size / 4,
365 static enum _ecore_status_t ecore_iov_pci_cfg_info(struct ecore_dev *p_dev)
367 struct ecore_hw_sriov_info *iov = p_dev->p_iov_info;
370 DP_VERBOSE(p_dev, ECORE_MSG_IOV, "sriov ext pos %d\n", pos);
371 OSAL_PCI_READ_CONFIG_WORD(p_dev, pos + PCI_SRIOV_CTRL, &iov->ctrl);
373 OSAL_PCI_READ_CONFIG_WORD(p_dev,
374 pos + PCI_SRIOV_TOTAL_VF, &iov->total_vfs);
375 OSAL_PCI_READ_CONFIG_WORD(p_dev,
376 pos + PCI_SRIOV_INITIAL_VF,
379 OSAL_PCI_READ_CONFIG_WORD(p_dev, pos + PCI_SRIOV_NUM_VF, &iov->num_vfs);
381 /* @@@TODO - in future we might want to add an OSAL here to
382 * allow each OS to decide on its own how to act.
384 DP_VERBOSE(p_dev, ECORE_MSG_IOV,
385 "Number of VFs are already set to non-zero value."
386 " Ignoring PCI configuration value\n");
390 OSAL_PCI_READ_CONFIG_WORD(p_dev,
391 pos + PCI_SRIOV_VF_OFFSET, &iov->offset);
393 OSAL_PCI_READ_CONFIG_WORD(p_dev,
394 pos + PCI_SRIOV_VF_STRIDE, &iov->stride);
396 OSAL_PCI_READ_CONFIG_WORD(p_dev,
397 pos + PCI_SRIOV_VF_DID, &iov->vf_device_id);
399 OSAL_PCI_READ_CONFIG_DWORD(p_dev,
400 pos + PCI_SRIOV_SUP_PGSIZE, &iov->pgsz);
402 OSAL_PCI_READ_CONFIG_DWORD(p_dev, pos + PCI_SRIOV_CAP, &iov->cap);
404 OSAL_PCI_READ_CONFIG_BYTE(p_dev, pos + PCI_SRIOV_FUNC_LINK, &iov->link);
406 DP_VERBOSE(p_dev, ECORE_MSG_IOV, "IOV info: nres %d, cap 0x%x,"
407 "ctrl 0x%x, total %d, initial %d, num vfs %d, offset %d,"
408 " stride %d, page size 0x%x\n",
409 iov->nres, iov->cap, iov->ctrl,
410 iov->total_vfs, iov->initial_vfs, iov->nr_virtfn,
411 iov->offset, iov->stride, iov->pgsz);
413 /* Some sanity checks */
414 if (iov->num_vfs > NUM_OF_VFS(p_dev) ||
415 iov->total_vfs > NUM_OF_VFS(p_dev)) {
416 /* This can happen only due to a bug. In this case we set
417 * num_vfs to zero to avoid memory corruption in the code that
418 * assumes max number of vfs
420 DP_NOTICE(p_dev, false,
421 "IOV: Unexpected number of vfs set: %d"
422 " setting num_vf to zero\n",
429 return ECORE_SUCCESS;
432 static void ecore_iov_clear_vf_igu_blocks(struct ecore_hwfn *p_hwfn,
433 struct ecore_ptt *p_ptt)
435 struct ecore_igu_block *p_sb;
439 if (!p_hwfn->hw_info.p_igu_info) {
441 "ecore_iov_clear_vf_igu_blocks IGU Info not inited\n");
446 sb_id < ECORE_MAPPING_MEMORY_SIZE(p_hwfn->p_dev); sb_id++) {
447 p_sb = &p_hwfn->hw_info.p_igu_info->igu_map.igu_blocks[sb_id];
448 if ((p_sb->status & ECORE_IGU_STATUS_FREE) &&
449 !(p_sb->status & ECORE_IGU_STATUS_PF)) {
450 val = ecore_rd(p_hwfn, p_ptt,
451 IGU_REG_MAPPING_MEMORY + sb_id * 4);
452 SET_FIELD(val, IGU_MAPPING_LINE_VALID, 0);
453 ecore_wr(p_hwfn, p_ptt,
454 IGU_REG_MAPPING_MEMORY + 4 * sb_id, val);
459 static void ecore_iov_setup_vfdb(struct ecore_hwfn *p_hwfn)
461 struct ecore_hw_sriov_info *p_iov = p_hwfn->p_dev->p_iov_info;
462 struct ecore_pf_iov *p_iov_info = p_hwfn->pf_iov_info;
463 struct ecore_bulletin_content *p_bulletin_virt;
464 dma_addr_t req_p, rply_p, bulletin_p;
465 union pfvf_tlvs *p_reply_virt_addr;
466 union vfpf_tlvs *p_req_virt_addr;
469 OSAL_MEMSET(p_iov_info->vfs_array, 0, sizeof(p_iov_info->vfs_array));
471 p_req_virt_addr = p_iov_info->mbx_msg_virt_addr;
472 req_p = p_iov_info->mbx_msg_phys_addr;
473 p_reply_virt_addr = p_iov_info->mbx_reply_virt_addr;
474 rply_p = p_iov_info->mbx_reply_phys_addr;
475 p_bulletin_virt = p_iov_info->p_bulletins;
476 bulletin_p = p_iov_info->bulletins_phys;
477 if (!p_req_virt_addr || !p_reply_virt_addr || !p_bulletin_virt) {
479 "ecore_iov_setup_vfdb called without alloc mem first\n");
483 for (idx = 0; idx < p_iov->total_vfs; idx++) {
484 struct ecore_vf_info *vf = &p_iov_info->vfs_array[idx];
487 vf->vf_mbx.req_virt = p_req_virt_addr + idx;
488 vf->vf_mbx.req_phys = req_p + idx * sizeof(union vfpf_tlvs);
489 vf->vf_mbx.reply_virt = p_reply_virt_addr + idx;
490 vf->vf_mbx.reply_phys = rply_p + idx * sizeof(union pfvf_tlvs);
492 #ifdef CONFIG_ECORE_SW_CHANNEL
493 vf->vf_mbx.sw_mbx.request_size = sizeof(union vfpf_tlvs);
494 vf->vf_mbx.sw_mbx.mbx_state = VF_PF_WAIT_FOR_START_REQUEST;
496 vf->state = VF_STOPPED;
499 vf->bulletin.phys = idx *
500 sizeof(struct ecore_bulletin_content) + bulletin_p;
501 vf->bulletin.p_virt = p_bulletin_virt + idx;
502 vf->bulletin.size = sizeof(struct ecore_bulletin_content);
504 vf->relative_vf_id = idx;
505 vf->abs_vf_id = idx + p_iov->first_vf_in_pf;
506 concrete = ecore_vfid_to_concrete(p_hwfn, vf->abs_vf_id);
507 vf->concrete_fid = concrete;
508 /* TODO - need to devise a better way of getting opaque */
509 vf->opaque_fid = (p_hwfn->hw_info.opaque_fid & 0xff) |
510 (vf->abs_vf_id << 8);
512 vf->num_mac_filters = ECORE_ETH_VF_NUM_MAC_FILTERS;
513 vf->num_vlan_filters = ECORE_ETH_VF_NUM_VLAN_FILTERS;
517 static enum _ecore_status_t ecore_iov_allocate_vfdb(struct ecore_hwfn *p_hwfn)
519 struct ecore_pf_iov *p_iov_info = p_hwfn->pf_iov_info;
523 num_vfs = p_hwfn->p_dev->p_iov_info->total_vfs;
525 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
526 "ecore_iov_allocate_vfdb for %d VFs\n", num_vfs);
528 /* Allocate PF Mailbox buffer (per-VF) */
529 p_iov_info->mbx_msg_size = sizeof(union vfpf_tlvs) * num_vfs;
530 p_v_addr = &p_iov_info->mbx_msg_virt_addr;
531 *p_v_addr = OSAL_DMA_ALLOC_COHERENT(p_hwfn->p_dev,
532 &p_iov_info->mbx_msg_phys_addr,
533 p_iov_info->mbx_msg_size);
537 /* Allocate PF Mailbox Reply buffer (per-VF) */
538 p_iov_info->mbx_reply_size = sizeof(union pfvf_tlvs) * num_vfs;
539 p_v_addr = &p_iov_info->mbx_reply_virt_addr;
540 *p_v_addr = OSAL_DMA_ALLOC_COHERENT(p_hwfn->p_dev,
541 &p_iov_info->mbx_reply_phys_addr,
542 p_iov_info->mbx_reply_size);
546 p_iov_info->bulletins_size = sizeof(struct ecore_bulletin_content) *
548 p_v_addr = &p_iov_info->p_bulletins;
549 *p_v_addr = OSAL_DMA_ALLOC_COHERENT(p_hwfn->p_dev,
550 &p_iov_info->bulletins_phys,
551 p_iov_info->bulletins_size);
555 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
556 "PF's Requests mailbox [%p virt 0x%lx phys], "
557 "Response mailbox [%p virt 0x%lx phys] Bulletinsi"
558 " [%p virt 0x%lx phys]\n",
559 p_iov_info->mbx_msg_virt_addr,
560 (unsigned long)p_iov_info->mbx_msg_phys_addr,
561 p_iov_info->mbx_reply_virt_addr,
562 (unsigned long)p_iov_info->mbx_reply_phys_addr,
563 p_iov_info->p_bulletins,
564 (unsigned long)p_iov_info->bulletins_phys);
566 return ECORE_SUCCESS;
569 static void ecore_iov_free_vfdb(struct ecore_hwfn *p_hwfn)
571 struct ecore_pf_iov *p_iov_info = p_hwfn->pf_iov_info;
573 if (p_hwfn->pf_iov_info->mbx_msg_virt_addr)
574 OSAL_DMA_FREE_COHERENT(p_hwfn->p_dev,
575 p_iov_info->mbx_msg_virt_addr,
576 p_iov_info->mbx_msg_phys_addr,
577 p_iov_info->mbx_msg_size);
579 if (p_hwfn->pf_iov_info->mbx_reply_virt_addr)
580 OSAL_DMA_FREE_COHERENT(p_hwfn->p_dev,
581 p_iov_info->mbx_reply_virt_addr,
582 p_iov_info->mbx_reply_phys_addr,
583 p_iov_info->mbx_reply_size);
585 if (p_iov_info->p_bulletins)
586 OSAL_DMA_FREE_COHERENT(p_hwfn->p_dev,
587 p_iov_info->p_bulletins,
588 p_iov_info->bulletins_phys,
589 p_iov_info->bulletins_size);
592 enum _ecore_status_t ecore_iov_alloc(struct ecore_hwfn *p_hwfn)
594 struct ecore_pf_iov *p_sriov;
596 if (!IS_PF_SRIOV(p_hwfn)) {
597 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
598 "No SR-IOV - no need for IOV db\n");
599 return ECORE_SUCCESS;
602 p_sriov = OSAL_ZALLOC(p_hwfn->p_dev, GFP_KERNEL, sizeof(*p_sriov));
604 DP_NOTICE(p_hwfn, true,
605 "Failed to allocate `struct ecore_sriov'\n");
609 p_hwfn->pf_iov_info = p_sriov;
611 return ecore_iov_allocate_vfdb(p_hwfn);
614 void ecore_iov_setup(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt)
616 if (!IS_PF_SRIOV(p_hwfn) || !IS_PF_SRIOV_ALLOC(p_hwfn))
619 ecore_iov_setup_vfdb(p_hwfn);
620 ecore_iov_clear_vf_igu_blocks(p_hwfn, p_ptt);
623 void ecore_iov_free(struct ecore_hwfn *p_hwfn)
625 if (IS_PF_SRIOV_ALLOC(p_hwfn)) {
626 ecore_iov_free_vfdb(p_hwfn);
627 OSAL_FREE(p_hwfn->p_dev, p_hwfn->pf_iov_info);
631 void ecore_iov_free_hw_info(struct ecore_dev *p_dev)
633 OSAL_FREE(p_dev, p_dev->p_iov_info);
636 enum _ecore_status_t ecore_iov_hw_info(struct ecore_hwfn *p_hwfn)
638 struct ecore_dev *p_dev = p_hwfn->p_dev;
640 enum _ecore_status_t rc;
642 if (IS_VF(p_hwfn->p_dev))
643 return ECORE_SUCCESS;
645 /* Learn the PCI configuration */
646 pos = OSAL_PCI_FIND_EXT_CAPABILITY(p_hwfn->p_dev,
647 PCI_EXT_CAP_ID_SRIOV);
649 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV, "No PCIe IOV support\n");
650 return ECORE_SUCCESS;
653 /* Allocate a new struct for IOV information */
654 /* TODO - can change to VALLOC when its available */
655 p_dev->p_iov_info = OSAL_ZALLOC(p_dev, GFP_KERNEL,
656 sizeof(*p_dev->p_iov_info));
657 if (!p_dev->p_iov_info) {
658 DP_NOTICE(p_hwfn, true,
659 "Can't support IOV due to lack of memory\n");
662 p_dev->p_iov_info->pos = pos;
664 rc = ecore_iov_pci_cfg_info(p_dev);
668 /* We want PF IOV to be synonemous with the existence of p_iov_info;
669 * In case the capability is published but there are no VFs, simply
670 * de-allocate the struct.
672 if (!p_dev->p_iov_info->total_vfs) {
673 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
674 "IOV capabilities, but no VFs are published\n");
675 OSAL_FREE(p_dev, p_dev->p_iov_info);
676 return ECORE_SUCCESS;
679 /* First VF index based on offset is tricky:
680 * - If ARI is supported [likely], offset - (16 - pf_id) would
681 * provide the number for eng0. 2nd engine Vfs would begin
682 * after the first engine's VFs.
683 * - If !ARI, VFs would start on next device.
684 * so offset - (256 - pf_id) would provide the number.
685 * Utilize the fact that (256 - pf_id) is achieved only be later
686 * to diffrentiate between the two.
689 if (p_hwfn->p_dev->p_iov_info->offset < (256 - p_hwfn->abs_pf_id)) {
690 u32 first = p_hwfn->p_dev->p_iov_info->offset +
691 p_hwfn->abs_pf_id - 16;
693 p_dev->p_iov_info->first_vf_in_pf = first;
695 if (ECORE_PATH_ID(p_hwfn))
696 p_dev->p_iov_info->first_vf_in_pf -= MAX_NUM_VFS_BB;
698 u32 first = p_hwfn->p_dev->p_iov_info->offset +
699 p_hwfn->abs_pf_id - 256;
701 p_dev->p_iov_info->first_vf_in_pf = first;
704 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
705 "First VF in hwfn 0x%08x\n",
706 p_dev->p_iov_info->first_vf_in_pf);
708 return ECORE_SUCCESS;
711 static bool _ecore_iov_pf_sanity_check(struct ecore_hwfn *p_hwfn, int vfid,
712 bool b_fail_malicious)
714 /* Check PF supports sriov */
715 if (IS_VF(p_hwfn->p_dev) || !IS_ECORE_SRIOV(p_hwfn->p_dev) ||
716 !IS_PF_SRIOV_ALLOC(p_hwfn))
719 /* Check VF validity */
720 if (!ecore_iov_is_valid_vfid(p_hwfn, vfid, true, b_fail_malicious))
726 bool ecore_iov_pf_sanity_check(struct ecore_hwfn *p_hwfn, int vfid)
728 return _ecore_iov_pf_sanity_check(p_hwfn, vfid, true);
731 void ecore_iov_set_vf_to_disable(struct ecore_dev *p_dev,
732 u16 rel_vf_id, u8 to_disable)
734 struct ecore_vf_info *vf;
737 for_each_hwfn(p_dev, i) {
738 struct ecore_hwfn *p_hwfn = &p_dev->hwfns[i];
740 vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, false);
744 vf->to_disable = to_disable;
748 void ecore_iov_set_vfs_to_disable(struct ecore_dev *p_dev,
753 if (!IS_ECORE_SRIOV(p_dev))
756 for (i = 0; i < p_dev->p_iov_info->total_vfs; i++)
757 ecore_iov_set_vf_to_disable(p_dev, i, to_disable);
761 /* @@@TBD Consider taking outside of ecore... */
762 enum _ecore_status_t ecore_iov_set_vf_ctx(struct ecore_hwfn *p_hwfn,
766 enum _ecore_status_t rc = ECORE_SUCCESS;
767 struct ecore_vf_info *vf = ecore_iov_get_vf_info(p_hwfn, vf_id, true);
769 if (vf != OSAL_NULL) {
771 #ifdef CONFIG_ECORE_SW_CHANNEL
772 vf->vf_mbx.sw_mbx.mbx_state = VF_PF_WAIT_FOR_START_REQUEST;
775 rc = ECORE_UNKNOWN_ERROR;
781 static void ecore_iov_vf_pglue_clear_err(struct ecore_hwfn *p_hwfn,
782 struct ecore_ptt *p_ptt,
785 ecore_wr(p_hwfn, p_ptt,
786 PGLUE_B_REG_WAS_ERROR_VF_31_0_CLR + (abs_vfid >> 5) * 4,
787 1 << (abs_vfid & 0x1f));
790 static void ecore_iov_vf_igu_reset(struct ecore_hwfn *p_hwfn,
791 struct ecore_ptt *p_ptt,
792 struct ecore_vf_info *vf)
796 /* Set VF masks and configuration - pretend */
797 ecore_fid_pretend(p_hwfn, p_ptt, (u16)vf->concrete_fid);
799 ecore_wr(p_hwfn, p_ptt, IGU_REG_STATISTIC_NUM_VF_MSG_SENT, 0);
802 ecore_fid_pretend(p_hwfn, p_ptt, (u16)p_hwfn->hw_info.concrete_fid);
804 /* iterate over all queues, clear sb consumer */
805 for (i = 0; i < vf->num_sbs; i++)
806 ecore_int_igu_init_pure_rt_single(p_hwfn, p_ptt,
808 vf->opaque_fid, true);
811 static void ecore_iov_vf_igu_set_int(struct ecore_hwfn *p_hwfn,
812 struct ecore_ptt *p_ptt,
813 struct ecore_vf_info *vf, bool enable)
817 ecore_fid_pretend(p_hwfn, p_ptt, (u16)vf->concrete_fid);
819 igu_vf_conf = ecore_rd(p_hwfn, p_ptt, IGU_REG_VF_CONFIGURATION);
822 igu_vf_conf |= IGU_VF_CONF_MSI_MSIX_EN;
824 igu_vf_conf &= ~IGU_VF_CONF_MSI_MSIX_EN;
826 ecore_wr(p_hwfn, p_ptt, IGU_REG_VF_CONFIGURATION, igu_vf_conf);
829 ecore_fid_pretend(p_hwfn, p_ptt, (u16)p_hwfn->hw_info.concrete_fid);
832 static enum _ecore_status_t
833 ecore_iov_enable_vf_access(struct ecore_hwfn *p_hwfn,
834 struct ecore_ptt *p_ptt, struct ecore_vf_info *vf)
836 u32 igu_vf_conf = IGU_VF_CONF_FUNC_EN;
837 enum _ecore_status_t rc;
840 return ECORE_SUCCESS;
842 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
843 "Enable internal access for vf %x [abs %x]\n", vf->abs_vf_id,
844 ECORE_VF_ABS_ID(p_hwfn, vf));
846 ecore_iov_vf_pglue_clear_err(p_hwfn, p_ptt,
847 ECORE_VF_ABS_ID(p_hwfn, vf));
849 ecore_iov_vf_igu_reset(p_hwfn, p_ptt, vf);
851 /* It's possible VF was previously considered malicious */
852 vf->b_malicious = false;
854 rc = ecore_mcp_config_vf_msix(p_hwfn, p_ptt,
855 vf->abs_vf_id, vf->num_sbs);
856 if (rc != ECORE_SUCCESS)
859 ecore_fid_pretend(p_hwfn, p_ptt, (u16)vf->concrete_fid);
861 SET_FIELD(igu_vf_conf, IGU_VF_CONF_PARENT, p_hwfn->rel_pf_id);
862 STORE_RT_REG(p_hwfn, IGU_REG_VF_CONFIGURATION_RT_OFFSET, igu_vf_conf);
864 ecore_init_run(p_hwfn, p_ptt, PHASE_VF, vf->abs_vf_id,
865 p_hwfn->hw_info.hw_mode);
868 ecore_fid_pretend(p_hwfn, p_ptt, (u16)p_hwfn->hw_info.concrete_fid);
877 * @brief ecore_iov_config_perm_table - configure the permission
879 * In E4, queue zone permission table size is 320x9. There
880 * are 320 VF queues for single engine device (256 for dual
881 * engine device), and each entry has the following format:
888 static void ecore_iov_config_perm_table(struct ecore_hwfn *p_hwfn,
889 struct ecore_ptt *p_ptt,
890 struct ecore_vf_info *vf, u8 enable)
896 for (qid = 0; qid < vf->num_rxqs; qid++) {
897 ecore_fw_l2_queue(p_hwfn, vf->vf_queues[qid].fw_rx_qid,
900 reg_addr = PSWHST_REG_ZONE_PERMISSION_TABLE + qzone_id * 4;
901 val = enable ? (vf->abs_vf_id | (1 << 8)) : 0;
902 ecore_wr(p_hwfn, p_ptt, reg_addr, val);
906 static void ecore_iov_enable_vf_traffic(struct ecore_hwfn *p_hwfn,
907 struct ecore_ptt *p_ptt,
908 struct ecore_vf_info *vf)
910 /* Reset vf in IGU - interrupts are still disabled */
911 ecore_iov_vf_igu_reset(p_hwfn, p_ptt, vf);
913 ecore_iov_vf_igu_set_int(p_hwfn, p_ptt, vf, 1);
915 /* Permission Table */
916 ecore_iov_config_perm_table(p_hwfn, p_ptt, vf, true);
919 static u8 ecore_iov_alloc_vf_igu_sbs(struct ecore_hwfn *p_hwfn,
920 struct ecore_ptt *p_ptt,
921 struct ecore_vf_info *vf,
924 struct ecore_igu_block *igu_blocks;
925 int qid = 0, igu_id = 0;
928 igu_blocks = p_hwfn->hw_info.p_igu_info->igu_map.igu_blocks;
930 if (num_rx_queues > p_hwfn->hw_info.p_igu_info->free_blks)
931 num_rx_queues = p_hwfn->hw_info.p_igu_info->free_blks;
933 p_hwfn->hw_info.p_igu_info->free_blks -= num_rx_queues;
935 SET_FIELD(val, IGU_MAPPING_LINE_FUNCTION_NUMBER, vf->abs_vf_id);
936 SET_FIELD(val, IGU_MAPPING_LINE_VALID, 1);
937 SET_FIELD(val, IGU_MAPPING_LINE_PF_VALID, 0);
939 while ((qid < num_rx_queues) &&
940 (igu_id < ECORE_MAPPING_MEMORY_SIZE(p_hwfn->p_dev))) {
941 if (igu_blocks[igu_id].status & ECORE_IGU_STATUS_FREE) {
942 struct cau_sb_entry sb_entry;
944 vf->igu_sbs[qid] = (u16)igu_id;
945 igu_blocks[igu_id].status &= ~ECORE_IGU_STATUS_FREE;
947 SET_FIELD(val, IGU_MAPPING_LINE_VECTOR_NUMBER, qid);
949 ecore_wr(p_hwfn, p_ptt,
950 IGU_REG_MAPPING_MEMORY + sizeof(u32) * igu_id,
953 /* Configure igu sb in CAU which were marked valid */
954 ecore_init_cau_sb_entry(p_hwfn, &sb_entry,
957 ecore_dmae_host2grc(p_hwfn, p_ptt,
958 (u64)(osal_uintptr_t)&sb_entry,
959 CAU_REG_SB_VAR_MEMORY +
960 igu_id * sizeof(u64), 2, 0);
966 vf->num_sbs = (u8)num_rx_queues;
973 * @brief The function invalidates all the VF entries,
974 * technically this isn't required, but added for
975 * cleaness and ease of debugging incase a VF attempts to
976 * produce an interrupt after it has been taken down.
982 static void ecore_iov_free_vf_igu_sbs(struct ecore_hwfn *p_hwfn,
983 struct ecore_ptt *p_ptt,
984 struct ecore_vf_info *vf)
986 struct ecore_igu_info *p_info = p_hwfn->hw_info.p_igu_info;
990 /* Invalidate igu CAM lines and mark them as free */
991 for (idx = 0; idx < vf->num_sbs; idx++) {
992 igu_id = vf->igu_sbs[idx];
993 addr = IGU_REG_MAPPING_MEMORY + sizeof(u32) * igu_id;
995 val = ecore_rd(p_hwfn, p_ptt, addr);
996 SET_FIELD(val, IGU_MAPPING_LINE_VALID, 0);
997 ecore_wr(p_hwfn, p_ptt, addr, val);
999 p_info->igu_map.igu_blocks[igu_id].status |=
1000 ECORE_IGU_STATUS_FREE;
1002 p_hwfn->hw_info.p_igu_info->free_blks++;
1008 void ecore_iov_set_link(struct ecore_hwfn *p_hwfn,
1010 struct ecore_mcp_link_params *params,
1011 struct ecore_mcp_link_state *link,
1012 struct ecore_mcp_link_capabilities *p_caps)
1014 struct ecore_vf_info *p_vf = ecore_iov_get_vf_info(p_hwfn, vfid, false);
1015 struct ecore_bulletin_content *p_bulletin;
1020 p_bulletin = p_vf->bulletin.p_virt;
1021 p_bulletin->req_autoneg = params->speed.autoneg;
1022 p_bulletin->req_adv_speed = params->speed.advertised_speeds;
1023 p_bulletin->req_forced_speed = params->speed.forced_speed;
1024 p_bulletin->req_autoneg_pause = params->pause.autoneg;
1025 p_bulletin->req_forced_rx = params->pause.forced_rx;
1026 p_bulletin->req_forced_tx = params->pause.forced_tx;
1027 p_bulletin->req_loopback = params->loopback_mode;
1029 p_bulletin->link_up = link->link_up;
1030 p_bulletin->speed = link->speed;
1031 p_bulletin->full_duplex = link->full_duplex;
1032 p_bulletin->autoneg = link->an;
1033 p_bulletin->autoneg_complete = link->an_complete;
1034 p_bulletin->parallel_detection = link->parallel_detection;
1035 p_bulletin->pfc_enabled = link->pfc_enabled;
1036 p_bulletin->partner_adv_speed = link->partner_adv_speed;
1037 p_bulletin->partner_tx_flow_ctrl_en = link->partner_tx_flow_ctrl_en;
1038 p_bulletin->partner_rx_flow_ctrl_en = link->partner_rx_flow_ctrl_en;
1039 p_bulletin->partner_adv_pause = link->partner_adv_pause;
1040 p_bulletin->sfp_tx_fault = link->sfp_tx_fault;
1042 p_bulletin->capability_speed = p_caps->speed_capabilities;
1045 enum _ecore_status_t
1046 ecore_iov_init_hw_for_vf(struct ecore_hwfn *p_hwfn,
1047 struct ecore_ptt *p_ptt,
1048 struct ecore_iov_vf_init_params *p_params)
1050 struct ecore_mcp_link_capabilities link_caps;
1051 struct ecore_mcp_link_params link_params;
1052 struct ecore_mcp_link_state link_state;
1053 u8 num_of_vf_available_chains = 0;
1054 struct ecore_vf_info *vf = OSAL_NULL;
1056 enum _ecore_status_t rc = ECORE_SUCCESS;
1060 vf = ecore_iov_get_vf_info(p_hwfn, p_params->rel_vf_id, false);
1062 DP_ERR(p_hwfn, "ecore_iov_init_hw_for_vf : vf is OSAL_NULL\n");
1063 return ECORE_UNKNOWN_ERROR;
1067 DP_NOTICE(p_hwfn, true, "VF[%d] is already active.\n",
1068 p_params->rel_vf_id);
1072 /* Perform sanity checking on the requested vport/rss */
1073 if (p_params->vport_id >= RESC_NUM(p_hwfn, ECORE_VPORT)) {
1074 DP_NOTICE(p_hwfn, true, "VF[%d] - can't use VPORT %02x\n",
1075 p_params->rel_vf_id, p_params->vport_id);
1079 if ((p_params->num_queues > 1) &&
1080 (p_params->rss_eng_id >= RESC_NUM(p_hwfn, ECORE_RSS_ENG))) {
1081 DP_NOTICE(p_hwfn, true, "VF[%d] - can't use RSS_ENG %02x\n",
1082 p_params->rel_vf_id, p_params->rss_eng_id);
1086 /* TODO - remove this once we get confidence of change */
1087 if (!p_params->vport_id) {
1088 DP_NOTICE(p_hwfn, false,
1089 "VF[%d] - Unlikely that VF uses vport0. Forgotten?\n",
1090 p_params->rel_vf_id);
1092 if ((!p_params->rss_eng_id) && (p_params->num_queues > 1)) {
1093 DP_NOTICE(p_hwfn, false,
1094 "VF[%d] - Unlikely that VF uses RSS_eng0. Forgotten?\n",
1095 p_params->rel_vf_id);
1097 vf->vport_id = p_params->vport_id;
1098 vf->rss_eng_id = p_params->rss_eng_id;
1100 /* Perform sanity checking on the requested queue_id */
1101 for (i = 0; i < p_params->num_queues; i++) {
1102 u16 min_vf_qzone = (u16)FEAT_NUM(p_hwfn, ECORE_PF_L2_QUE);
1103 u16 max_vf_qzone = min_vf_qzone +
1104 FEAT_NUM(p_hwfn, ECORE_VF_L2_QUE) - 1;
1106 qid = p_params->req_rx_queue[i];
1107 if (qid < min_vf_qzone || qid > max_vf_qzone) {
1108 DP_NOTICE(p_hwfn, true,
1109 "Can't enable Rx qid [%04x] for VF[%d]: qids [0x%04x,...,0x%04x] available\n",
1110 qid, p_params->rel_vf_id,
1111 min_vf_qzone, max_vf_qzone);
1115 qid = p_params->req_tx_queue[i];
1116 if (qid > max_vf_qzone) {
1117 DP_NOTICE(p_hwfn, true,
1118 "Can't enable Tx qid [%04x] for VF[%d]: max qid 0x%04x\n",
1119 qid, p_params->rel_vf_id, max_vf_qzone);
1123 /* If client *really* wants, Tx qid can be shared with PF */
1124 if (qid < min_vf_qzone)
1125 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1126 "VF[%d] is using PF qid [0x%04x] for Txq[0x%02x]\n",
1127 p_params->rel_vf_id, qid, i);
1130 /* Limit number of queues according to number of CIDs */
1131 ecore_cxt_get_proto_cid_count(p_hwfn, PROTOCOLID_ETH, &cids);
1132 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1133 "VF[%d] - requesting to initialize for 0x%04x queues"
1134 " [0x%04x CIDs available]\n",
1135 vf->relative_vf_id, p_params->num_queues, (u16)cids);
1136 num_irqs = OSAL_MIN_T(u16, p_params->num_queues, ((u16)cids));
1138 num_of_vf_available_chains = ecore_iov_alloc_vf_igu_sbs(p_hwfn,
1142 if (num_of_vf_available_chains == 0) {
1143 DP_ERR(p_hwfn, "no available igu sbs\n");
1147 /* Choose queue number and index ranges */
1148 vf->num_rxqs = num_of_vf_available_chains;
1149 vf->num_txqs = num_of_vf_available_chains;
1151 for (i = 0; i < vf->num_rxqs; i++) {
1152 struct ecore_vf_queue *p_queue = &vf->vf_queues[i];
1154 p_queue->fw_rx_qid = p_params->req_rx_queue[i];
1155 p_queue->fw_tx_qid = p_params->req_tx_queue[i];
1157 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1158 "VF[%d] - Q[%d] SB %04x, qid [Rx %04x Tx %04x]\n",
1159 vf->relative_vf_id, i, vf->igu_sbs[i],
1160 p_queue->fw_rx_qid, p_queue->fw_tx_qid);
1163 /* Update the link configuration in bulletin.
1165 OSAL_MEMCPY(&link_params, ecore_mcp_get_link_params(p_hwfn),
1166 sizeof(link_params));
1167 OSAL_MEMCPY(&link_state, ecore_mcp_get_link_state(p_hwfn),
1168 sizeof(link_state));
1169 OSAL_MEMCPY(&link_caps, ecore_mcp_get_link_capabilities(p_hwfn),
1171 ecore_iov_set_link(p_hwfn, p_params->rel_vf_id,
1172 &link_params, &link_state, &link_caps);
1174 rc = ecore_iov_enable_vf_access(p_hwfn, p_ptt, vf);
1176 if (rc == ECORE_SUCCESS) {
1178 p_hwfn->pf_iov_info->active_vfs[vf->relative_vf_id / 64] |=
1179 (1ULL << (vf->relative_vf_id % 64));
1181 if (IS_LEAD_HWFN(p_hwfn))
1182 p_hwfn->p_dev->p_iov_info->num_vfs++;
1188 enum _ecore_status_t ecore_iov_release_hw_for_vf(struct ecore_hwfn *p_hwfn,
1189 struct ecore_ptt *p_ptt,
1192 struct ecore_mcp_link_capabilities caps;
1193 struct ecore_mcp_link_params params;
1194 struct ecore_mcp_link_state link;
1195 struct ecore_vf_info *vf = OSAL_NULL;
1197 vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
1199 DP_ERR(p_hwfn, "ecore_iov_release_hw_for_vf : vf is NULL\n");
1200 return ECORE_UNKNOWN_ERROR;
1203 if (vf->bulletin.p_virt)
1204 OSAL_MEMSET(vf->bulletin.p_virt, 0,
1205 sizeof(*vf->bulletin.p_virt));
1207 OSAL_MEMSET(&vf->p_vf_info, 0, sizeof(vf->p_vf_info));
1209 /* Get the link configuration back in bulletin so
1210 * that when VFs are re-enabled they get the actual
1211 * link configuration.
1213 OSAL_MEMCPY(¶ms, ecore_mcp_get_link_params(p_hwfn), sizeof(params));
1214 OSAL_MEMCPY(&link, ecore_mcp_get_link_state(p_hwfn), sizeof(link));
1215 OSAL_MEMCPY(&caps, ecore_mcp_get_link_capabilities(p_hwfn),
1217 ecore_iov_set_link(p_hwfn, rel_vf_id, ¶ms, &link, &caps);
1219 /* Forget the VF's acquisition message */
1220 OSAL_MEMSET(&vf->acquire, 0, sizeof(vf->acquire));
1222 /* disablng interrupts and resetting permission table was done during
1223 * vf-close, however, we could get here without going through vf_close
1225 /* Disable Interrupts for VF */
1226 ecore_iov_vf_igu_set_int(p_hwfn, p_ptt, vf, 0);
1228 /* Reset Permission table */
1229 ecore_iov_config_perm_table(p_hwfn, p_ptt, vf, 0);
1233 ecore_iov_free_vf_igu_sbs(p_hwfn, p_ptt, vf);
1237 p_hwfn->pf_iov_info->active_vfs[vf->relative_vf_id / 64] &=
1238 ~(1ULL << (vf->relative_vf_id / 64));
1240 if (IS_LEAD_HWFN(p_hwfn))
1241 p_hwfn->p_dev->p_iov_info->num_vfs--;
1244 return ECORE_SUCCESS;
1247 static bool ecore_iov_tlv_supported(u16 tlvtype)
1249 return tlvtype > CHANNEL_TLV_NONE && tlvtype < CHANNEL_TLV_MAX;
1252 static void ecore_iov_lock_vf_pf_channel(struct ecore_hwfn *p_hwfn,
1253 struct ecore_vf_info *vf, u16 tlv)
1255 /* lock the channel */
1256 /* mutex_lock(&vf->op_mutex); @@@TBD MichalK - add lock... */
1258 /* record the locking op */
1259 /* vf->op_current = tlv; @@@TBD MichalK */
1262 if (ecore_iov_tlv_supported(tlv))
1265 "VF[%d]: vf pf channel locked by %s\n",
1267 ecore_channel_tlvs_string[tlv]);
1271 "VF[%d]: vf pf channel locked by %04x\n",
1272 vf->abs_vf_id, tlv);
1275 static void ecore_iov_unlock_vf_pf_channel(struct ecore_hwfn *p_hwfn,
1276 struct ecore_vf_info *vf,
1279 /* log the unlock */
1280 if (ecore_iov_tlv_supported(expected_tlv))
1283 "VF[%d]: vf pf channel unlocked by %s\n",
1285 ecore_channel_tlvs_string[expected_tlv]);
1289 "VF[%d]: vf pf channel unlocked by %04x\n",
1290 vf->abs_vf_id, expected_tlv);
1292 /* record the locking op */
1293 /* vf->op_current = CHANNEL_TLV_NONE; */
1296 /* place a given tlv on the tlv buffer, continuing current tlv list */
1297 void *ecore_add_tlv(struct ecore_hwfn *p_hwfn,
1298 u8 **offset, u16 type, u16 length)
1300 struct channel_tlv *tl = (struct channel_tlv *)*offset;
1303 tl->length = length;
1305 /* Offset should keep pointing to next TLV (the end of the last) */
1308 /* Return a pointer to the start of the added tlv */
1309 return *offset - length;
1312 /* list the types and lengths of the tlvs on the buffer */
1313 void ecore_dp_tlv_list(struct ecore_hwfn *p_hwfn, void *tlvs_list)
1315 u16 i = 1, total_length = 0;
1316 struct channel_tlv *tlv;
1319 /* cast current tlv list entry to channel tlv header */
1320 tlv = (struct channel_tlv *)((u8 *)tlvs_list + total_length);
1323 if (ecore_iov_tlv_supported(tlv->type))
1324 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1325 "TLV number %d: type %s, length %d\n",
1326 i, ecore_channel_tlvs_string[tlv->type],
1329 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1330 "TLV number %d: type %d, length %d\n",
1331 i, tlv->type, tlv->length);
1333 if (tlv->type == CHANNEL_TLV_LIST_END)
1336 /* Validate entry - protect against malicious VFs */
1338 DP_NOTICE(p_hwfn, false, "TLV of length 0 found\n");
1341 total_length += tlv->length;
1342 if (total_length >= sizeof(struct tlv_buffer_size)) {
1343 DP_NOTICE(p_hwfn, false, "TLV ==> Buffer overflow\n");
1351 static void ecore_iov_send_response(struct ecore_hwfn *p_hwfn,
1352 struct ecore_ptt *p_ptt,
1353 struct ecore_vf_info *p_vf,
1354 u16 length, u8 status)
1356 struct ecore_iov_vf_mbx *mbx = &p_vf->vf_mbx;
1357 struct ecore_dmae_params params;
1360 mbx->reply_virt->default_resp.hdr.status = status;
1362 ecore_dp_tlv_list(p_hwfn, mbx->reply_virt);
1364 #ifdef CONFIG_ECORE_SW_CHANNEL
1365 mbx->sw_mbx.response_size =
1366 length + sizeof(struct channel_list_end_tlv);
1368 if (!p_hwfn->p_dev->b_hw_channel)
1372 eng_vf_id = p_vf->abs_vf_id;
1374 OSAL_MEMSET(¶ms, 0, sizeof(struct ecore_dmae_params));
1375 params.flags = ECORE_DMAE_FLAG_VF_DST;
1376 params.dst_vfid = eng_vf_id;
1378 ecore_dmae_host2host(p_hwfn, p_ptt, mbx->reply_phys + sizeof(u64),
1379 mbx->req_virt->first_tlv.reply_address +
1381 (sizeof(union pfvf_tlvs) - sizeof(u64)) / 4,
1384 ecore_dmae_host2host(p_hwfn, p_ptt, mbx->reply_phys,
1385 mbx->req_virt->first_tlv.reply_address,
1386 sizeof(u64) / 4, ¶ms);
1389 GTT_BAR0_MAP_REG_USDM_RAM +
1390 USTORM_VF_PF_CHANNEL_READY_OFFSET(eng_vf_id), 1);
1393 static u16 ecore_iov_vport_to_tlv(struct ecore_hwfn *p_hwfn,
1394 enum ecore_iov_vport_update_flag flag)
1397 case ECORE_IOV_VP_UPDATE_ACTIVATE:
1398 return CHANNEL_TLV_VPORT_UPDATE_ACTIVATE;
1399 case ECORE_IOV_VP_UPDATE_VLAN_STRIP:
1400 return CHANNEL_TLV_VPORT_UPDATE_VLAN_STRIP;
1401 case ECORE_IOV_VP_UPDATE_TX_SWITCH:
1402 return CHANNEL_TLV_VPORT_UPDATE_TX_SWITCH;
1403 case ECORE_IOV_VP_UPDATE_MCAST:
1404 return CHANNEL_TLV_VPORT_UPDATE_MCAST;
1405 case ECORE_IOV_VP_UPDATE_ACCEPT_PARAM:
1406 return CHANNEL_TLV_VPORT_UPDATE_ACCEPT_PARAM;
1407 case ECORE_IOV_VP_UPDATE_RSS:
1408 return CHANNEL_TLV_VPORT_UPDATE_RSS;
1409 case ECORE_IOV_VP_UPDATE_ACCEPT_ANY_VLAN:
1410 return CHANNEL_TLV_VPORT_UPDATE_ACCEPT_ANY_VLAN;
1411 case ECORE_IOV_VP_UPDATE_SGE_TPA:
1412 return CHANNEL_TLV_VPORT_UPDATE_SGE_TPA;
1418 static u16 ecore_iov_prep_vp_update_resp_tlvs(struct ecore_hwfn *p_hwfn,
1419 struct ecore_vf_info *p_vf,
1420 struct ecore_iov_vf_mbx *p_mbx,
1421 u8 status, u16 tlvs_mask,
1424 struct pfvf_def_resp_tlv *resp;
1425 u16 size, total_len, i;
1427 OSAL_MEMSET(p_mbx->reply_virt, 0, sizeof(union pfvf_tlvs));
1428 p_mbx->offset = (u8 *)p_mbx->reply_virt;
1429 size = sizeof(struct pfvf_def_resp_tlv);
1432 ecore_add_tlv(p_hwfn, &p_mbx->offset, CHANNEL_TLV_VPORT_UPDATE, size);
1434 /* Prepare response for all extended tlvs if they are found by PF */
1435 for (i = 0; i < ECORE_IOV_VP_UPDATE_MAX; i++) {
1436 if (!(tlvs_mask & (1 << i)))
1439 resp = ecore_add_tlv(p_hwfn, &p_mbx->offset,
1440 ecore_iov_vport_to_tlv(p_hwfn, i), size);
1442 if (tlvs_accepted & (1 << i))
1443 resp->hdr.status = status;
1445 resp->hdr.status = PFVF_STATUS_NOT_SUPPORTED;
1447 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1448 "VF[%d] - vport_update resp: TLV %d, status %02x\n",
1449 p_vf->relative_vf_id,
1450 ecore_iov_vport_to_tlv(p_hwfn, i), resp->hdr.status);
1455 ecore_add_tlv(p_hwfn, &p_mbx->offset, CHANNEL_TLV_LIST_END,
1456 sizeof(struct channel_list_end_tlv));
1461 static void ecore_iov_prepare_resp(struct ecore_hwfn *p_hwfn,
1462 struct ecore_ptt *p_ptt,
1463 struct ecore_vf_info *vf_info,
1464 u16 type, u16 length, u8 status)
1466 struct ecore_iov_vf_mbx *mbx = &vf_info->vf_mbx;
1468 mbx->offset = (u8 *)mbx->reply_virt;
1470 ecore_add_tlv(p_hwfn, &mbx->offset, type, length);
1471 ecore_add_tlv(p_hwfn, &mbx->offset, CHANNEL_TLV_LIST_END,
1472 sizeof(struct channel_list_end_tlv));
1474 ecore_iov_send_response(p_hwfn, p_ptt, vf_info, length, status);
1476 OSAL_IOV_PF_RESP_TYPE(p_hwfn, vf_info->relative_vf_id, status);
1479 struct ecore_public_vf_info
1480 *ecore_iov_get_public_vf_info(struct ecore_hwfn *p_hwfn,
1482 bool b_enabled_only)
1484 struct ecore_vf_info *vf = OSAL_NULL;
1486 vf = ecore_iov_get_vf_info(p_hwfn, relative_vf_id, b_enabled_only);
1490 return &vf->p_vf_info;
1493 static void ecore_iov_vf_cleanup(struct ecore_hwfn *p_hwfn,
1494 struct ecore_vf_info *p_vf)
1497 p_vf->vf_bulletin = 0;
1498 p_vf->vport_instance = 0;
1499 p_vf->configured_features = 0;
1501 /* If VF previously requested less resources, go back to default */
1502 p_vf->num_rxqs = p_vf->num_sbs;
1503 p_vf->num_txqs = p_vf->num_sbs;
1505 p_vf->num_active_rxqs = 0;
1507 for (i = 0; i < ECORE_MAX_VF_CHAINS_PER_PF; i++) {
1508 struct ecore_vf_queue *p_queue = &p_vf->vf_queues[i];
1510 for (j = 0; j < MAX_QUEUES_PER_QZONE; j++) {
1511 if (!p_queue->cids[j].p_cid)
1514 ecore_eth_queue_cid_release(p_hwfn,
1515 p_queue->cids[j].p_cid);
1516 p_queue->cids[j].p_cid = OSAL_NULL;
1520 OSAL_MEMSET(&p_vf->shadow_config, 0, sizeof(p_vf->shadow_config));
1521 OSAL_MEMSET(&p_vf->acquire, 0, sizeof(p_vf->acquire));
1522 OSAL_IOV_VF_CLEANUP(p_hwfn, p_vf->relative_vf_id);
1525 static u8 ecore_iov_vf_mbx_acquire_resc(struct ecore_hwfn *p_hwfn,
1526 struct ecore_ptt *p_ptt,
1527 struct ecore_vf_info *p_vf,
1528 struct vf_pf_resc_request *p_req,
1529 struct pf_vf_resc *p_resp)
1533 /* Queue related information */
1534 p_resp->num_rxqs = p_vf->num_rxqs;
1535 p_resp->num_txqs = p_vf->num_txqs;
1536 p_resp->num_sbs = p_vf->num_sbs;
1538 for (i = 0; i < p_resp->num_sbs; i++) {
1539 p_resp->hw_sbs[i].hw_sb_id = p_vf->igu_sbs[i];
1540 /* TODO - what's this sb_qid field? Is it deprecated?
1541 * or is there an ecore_client that looks at this?
1543 p_resp->hw_sbs[i].sb_qid = 0;
1546 /* These fields are filled for backward compatibility.
1547 * Unused by modern vfs.
1549 for (i = 0; i < p_resp->num_rxqs; i++) {
1550 ecore_fw_l2_queue(p_hwfn, p_vf->vf_queues[i].fw_rx_qid,
1551 (u16 *)&p_resp->hw_qid[i]);
1555 /* Filter related information */
1556 p_resp->num_mac_filters = OSAL_MIN_T(u8, p_vf->num_mac_filters,
1557 p_req->num_mac_filters);
1558 p_resp->num_vlan_filters = OSAL_MIN_T(u8, p_vf->num_vlan_filters,
1559 p_req->num_vlan_filters);
1561 /* This isn't really needed/enforced, but some legacy VFs might depend
1562 * on the correct filling of this field.
1564 p_resp->num_mc_filters = ECORE_MAX_MC_ADDRS;
1566 /* Validate sufficient resources for VF */
1567 if (p_resp->num_rxqs < p_req->num_rxqs ||
1568 p_resp->num_txqs < p_req->num_txqs ||
1569 p_resp->num_sbs < p_req->num_sbs ||
1570 p_resp->num_mac_filters < p_req->num_mac_filters ||
1571 p_resp->num_vlan_filters < p_req->num_vlan_filters ||
1572 p_resp->num_mc_filters < p_req->num_mc_filters) {
1573 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1574 "VF[%d] - Insufficient resources: rxq [%02x/%02x]"
1575 " txq [%02x/%02x] sbs [%02x/%02x] mac [%02x/%02x]"
1576 " vlan [%02x/%02x] mc [%02x/%02x]\n",
1578 p_req->num_rxqs, p_resp->num_rxqs,
1579 p_req->num_rxqs, p_resp->num_txqs,
1580 p_req->num_sbs, p_resp->num_sbs,
1581 p_req->num_mac_filters, p_resp->num_mac_filters,
1582 p_req->num_vlan_filters, p_resp->num_vlan_filters,
1583 p_req->num_mc_filters, p_resp->num_mc_filters);
1585 /* Some legacy OSes are incapable of correctly handling this
1588 if ((p_vf->acquire.vfdev_info.eth_fp_hsi_minor ==
1589 ETH_HSI_VER_NO_PKT_LEN_TUNN) &&
1590 (p_vf->acquire.vfdev_info.os_type ==
1591 VFPF_ACQUIRE_OS_WINDOWS))
1592 return PFVF_STATUS_SUCCESS;
1594 return PFVF_STATUS_NO_RESOURCE;
1597 return PFVF_STATUS_SUCCESS;
1600 static void ecore_iov_vf_mbx_acquire_stats(struct ecore_hwfn *p_hwfn,
1601 struct pfvf_stats_info *p_stats)
1603 p_stats->mstats.address = PXP_VF_BAR0_START_MSDM_ZONE_B +
1604 OFFSETOF(struct mstorm_vf_zone,
1605 non_trigger.eth_queue_stat);
1606 p_stats->mstats.len = sizeof(struct eth_mstorm_per_queue_stat);
1607 p_stats->ustats.address = PXP_VF_BAR0_START_USDM_ZONE_B +
1608 OFFSETOF(struct ustorm_vf_zone,
1609 non_trigger.eth_queue_stat);
1610 p_stats->ustats.len = sizeof(struct eth_ustorm_per_queue_stat);
1611 p_stats->pstats.address = PXP_VF_BAR0_START_PSDM_ZONE_B +
1612 OFFSETOF(struct pstorm_vf_zone,
1613 non_trigger.eth_queue_stat);
1614 p_stats->pstats.len = sizeof(struct eth_pstorm_per_queue_stat);
1615 p_stats->tstats.address = 0;
1616 p_stats->tstats.len = 0;
1619 static void ecore_iov_vf_mbx_acquire(struct ecore_hwfn *p_hwfn,
1620 struct ecore_ptt *p_ptt,
1621 struct ecore_vf_info *vf)
1623 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
1624 struct pfvf_acquire_resp_tlv *resp = &mbx->reply_virt->acquire_resp;
1625 struct pf_vf_pfdev_info *pfdev_info = &resp->pfdev_info;
1626 struct vfpf_acquire_tlv *req = &mbx->req_virt->acquire;
1627 u8 vfpf_status = PFVF_STATUS_NOT_SUPPORTED;
1628 struct pf_vf_resc *resc = &resp->resc;
1629 enum _ecore_status_t rc;
1631 OSAL_MEMSET(resp, 0, sizeof(*resp));
1633 /* Write the PF version so that VF would know which version
1634 * is supported - might be later overridden. This guarantees that
1635 * VF could recognize legacy PF based on lack of versions in reply.
1637 pfdev_info->major_fp_hsi = ETH_HSI_VER_MAJOR;
1638 pfdev_info->minor_fp_hsi = ETH_HSI_VER_MINOR;
1640 /* TODO - not doing anything is bad since we'll assert, but this isn't
1641 * necessarily the right behavior - perhaps we should have allowed some
1644 if (vf->state != VF_FREE &&
1645 vf->state != VF_STOPPED) {
1646 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1647 "VF[%d] sent ACQUIRE but is already in state %d - fail request\n",
1648 vf->abs_vf_id, vf->state);
1652 /* Validate FW compatibility */
1653 if (req->vfdev_info.eth_fp_hsi_major != ETH_HSI_VER_MAJOR) {
1654 if (req->vfdev_info.capabilities &
1655 VFPF_ACQUIRE_CAP_PRE_FP_HSI) {
1656 struct vf_pf_vfdev_info *p_vfdev = &req->vfdev_info;
1658 /* This legacy support would need to be removed once
1659 * the major has changed.
1661 OSAL_BUILD_BUG_ON(ETH_HSI_VER_MAJOR != 3);
1663 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1664 "VF[%d] is pre-fastpath HSI\n",
1666 p_vfdev->eth_fp_hsi_major = ETH_HSI_VER_MAJOR;
1667 p_vfdev->eth_fp_hsi_minor = ETH_HSI_VER_NO_PKT_LEN_TUNN;
1670 "VF[%d] needs fastpath HSI %02x.%02x, which is"
1671 " incompatible with loaded FW's faspath"
1674 req->vfdev_info.eth_fp_hsi_major,
1675 req->vfdev_info.eth_fp_hsi_minor,
1676 ETH_HSI_VER_MAJOR, ETH_HSI_VER_MINOR);
1682 /* On 100g PFs, prevent old VFs from loading */
1683 if ((p_hwfn->p_dev->num_hwfns > 1) &&
1684 !(req->vfdev_info.capabilities & VFPF_ACQUIRE_CAP_100G)) {
1686 "VF[%d] is running an old driver that doesn't support"
1692 #ifndef __EXTRACT__LINUX__
1693 if (OSAL_IOV_VF_ACQUIRE(p_hwfn, vf->relative_vf_id) != ECORE_SUCCESS) {
1694 vfpf_status = PFVF_STATUS_NOT_SUPPORTED;
1699 /* Store the acquire message */
1700 OSAL_MEMCPY(&vf->acquire, req, sizeof(vf->acquire));
1702 vf->opaque_fid = req->vfdev_info.opaque_fid;
1704 vf->vf_bulletin = req->bulletin_addr;
1705 vf->bulletin.size = (vf->bulletin.size < req->bulletin_size) ?
1706 vf->bulletin.size : req->bulletin_size;
1708 /* fill in pfdev info */
1709 pfdev_info->chip_num = p_hwfn->p_dev->chip_num;
1710 pfdev_info->db_size = 0; /* @@@ TBD MichalK Vf Doorbells */
1711 pfdev_info->indices_per_sb = PIS_PER_SB;
1713 pfdev_info->capabilities = PFVF_ACQUIRE_CAP_DEFAULT_UNTAGGED |
1714 PFVF_ACQUIRE_CAP_POST_FW_OVERRIDE;
1715 if (p_hwfn->p_dev->num_hwfns > 1)
1716 pfdev_info->capabilities |= PFVF_ACQUIRE_CAP_100G;
1718 ecore_iov_vf_mbx_acquire_stats(p_hwfn, &pfdev_info->stats_info);
1720 OSAL_MEMCPY(pfdev_info->port_mac, p_hwfn->hw_info.hw_mac_addr,
1723 pfdev_info->fw_major = FW_MAJOR_VERSION;
1724 pfdev_info->fw_minor = FW_MINOR_VERSION;
1725 pfdev_info->fw_rev = FW_REVISION_VERSION;
1726 pfdev_info->fw_eng = FW_ENGINEERING_VERSION;
1728 /* Incorrect when legacy, but doesn't matter as legacy isn't reading
1731 pfdev_info->minor_fp_hsi = OSAL_MIN_T(u8, ETH_HSI_VER_MINOR,
1732 req->vfdev_info.eth_fp_hsi_minor);
1733 pfdev_info->os_type = OSAL_IOV_GET_OS_TYPE();
1734 ecore_mcp_get_mfw_ver(p_hwfn, p_ptt, &pfdev_info->mfw_ver,
1737 pfdev_info->dev_type = p_hwfn->p_dev->type;
1738 pfdev_info->chip_rev = p_hwfn->p_dev->chip_rev;
1740 /* Fill resources available to VF; Make sure there are enough to
1741 * satisfy the VF's request.
1743 vfpf_status = ecore_iov_vf_mbx_acquire_resc(p_hwfn, p_ptt, vf,
1744 &req->resc_request, resc);
1745 if (vfpf_status != PFVF_STATUS_SUCCESS)
1748 /* Start the VF in FW */
1749 rc = ecore_sp_vf_start(p_hwfn, vf);
1750 if (rc != ECORE_SUCCESS) {
1751 DP_NOTICE(p_hwfn, true, "Failed to start VF[%02x]\n",
1753 vfpf_status = PFVF_STATUS_FAILURE;
1757 /* Fill agreed size of bulletin board in response, and post
1758 * an initial image to the bulletin board.
1760 resp->bulletin_size = vf->bulletin.size;
1761 ecore_iov_post_vf_bulletin(p_hwfn, vf->relative_vf_id, p_ptt);
1763 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1764 "VF[%d] ACQUIRE_RESPONSE: pfdev_info- chip_num=0x%x,"
1765 " db_size=%d, idx_per_sb=%d, pf_cap=0x%lx\n"
1766 "resources- n_rxq-%d, n_txq-%d, n_sbs-%d, n_macs-%d,"
1768 vf->abs_vf_id, resp->pfdev_info.chip_num,
1769 resp->pfdev_info.db_size, resp->pfdev_info.indices_per_sb,
1770 (unsigned long)resp->pfdev_info.capabilities, resc->num_rxqs,
1771 resc->num_txqs, resc->num_sbs, resc->num_mac_filters,
1772 resc->num_vlan_filters);
1774 vf->state = VF_ACQUIRED;
1777 /* Prepare Response */
1778 ecore_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_ACQUIRE,
1779 sizeof(struct pfvf_acquire_resp_tlv),
1783 static enum _ecore_status_t
1784 __ecore_iov_spoofchk_set(struct ecore_hwfn *p_hwfn,
1785 struct ecore_vf_info *p_vf, bool val)
1787 struct ecore_sp_vport_update_params params;
1788 enum _ecore_status_t rc;
1790 if (val == p_vf->spoof_chk) {
1791 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1792 "Spoofchk value[%d] is already configured\n", val);
1793 return ECORE_SUCCESS;
1796 OSAL_MEMSET(¶ms, 0, sizeof(struct ecore_sp_vport_update_params));
1797 params.opaque_fid = p_vf->opaque_fid;
1798 params.vport_id = p_vf->vport_id;
1799 params.update_anti_spoofing_en_flg = 1;
1800 params.anti_spoofing_en = val;
1802 rc = ecore_sp_vport_update(p_hwfn, ¶ms, ECORE_SPQ_MODE_EBLOCK,
1804 if (rc == ECORE_SUCCESS) {
1805 p_vf->spoof_chk = val;
1806 p_vf->req_spoofchk_val = p_vf->spoof_chk;
1807 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1808 "Spoofchk val[%d] configured\n", val);
1810 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1811 "Spoofchk configuration[val:%d] failed for VF[%d]\n",
1812 val, p_vf->relative_vf_id);
1818 static enum _ecore_status_t
1819 ecore_iov_reconfigure_unicast_vlan(struct ecore_hwfn *p_hwfn,
1820 struct ecore_vf_info *p_vf)
1822 struct ecore_filter_ucast filter;
1823 enum _ecore_status_t rc = ECORE_SUCCESS;
1826 OSAL_MEMSET(&filter, 0, sizeof(filter));
1827 filter.is_rx_filter = 1;
1828 filter.is_tx_filter = 1;
1829 filter.vport_to_add_to = p_vf->vport_id;
1830 filter.opcode = ECORE_FILTER_ADD;
1832 /* Reconfigure vlans */
1833 for (i = 0; i < ECORE_ETH_VF_NUM_VLAN_FILTERS + 1; i++) {
1834 if (!p_vf->shadow_config.vlans[i].used)
1837 filter.type = ECORE_FILTER_VLAN;
1838 filter.vlan = p_vf->shadow_config.vlans[i].vid;
1839 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1840 "Reconfiguring VLAN [0x%04x] for VF [%04x]\n",
1841 filter.vlan, p_vf->relative_vf_id);
1842 rc = ecore_sp_eth_filter_ucast(p_hwfn, p_vf->opaque_fid,
1843 &filter, ECORE_SPQ_MODE_CB,
1846 DP_NOTICE(p_hwfn, true,
1847 "Failed to configure VLAN [%04x]"
1849 filter.vlan, p_vf->relative_vf_id);
1857 static enum _ecore_status_t
1858 ecore_iov_reconfigure_unicast_shadow(struct ecore_hwfn *p_hwfn,
1859 struct ecore_vf_info *p_vf, u64 events)
1861 enum _ecore_status_t rc = ECORE_SUCCESS;
1863 /*TODO - what about MACs? */
1865 if ((events & (1 << VLAN_ADDR_FORCED)) &&
1866 !(p_vf->configured_features & (1 << VLAN_ADDR_FORCED)))
1867 rc = ecore_iov_reconfigure_unicast_vlan(p_hwfn, p_vf);
1872 static enum _ecore_status_t
1873 ecore_iov_configure_vport_forced(struct ecore_hwfn *p_hwfn,
1874 struct ecore_vf_info *p_vf,
1877 enum _ecore_status_t rc = ECORE_SUCCESS;
1878 struct ecore_filter_ucast filter;
1880 if (!p_vf->vport_instance)
1883 if (events & (1 << MAC_ADDR_FORCED)) {
1884 /* Since there's no way [currently] of removing the MAC,
1885 * we can always assume this means we need to force it.
1887 OSAL_MEMSET(&filter, 0, sizeof(filter));
1888 filter.type = ECORE_FILTER_MAC;
1889 filter.opcode = ECORE_FILTER_REPLACE;
1890 filter.is_rx_filter = 1;
1891 filter.is_tx_filter = 1;
1892 filter.vport_to_add_to = p_vf->vport_id;
1893 OSAL_MEMCPY(filter.mac, p_vf->bulletin.p_virt->mac, ETH_ALEN);
1895 rc = ecore_sp_eth_filter_ucast(p_hwfn, p_vf->opaque_fid,
1897 ECORE_SPQ_MODE_CB, OSAL_NULL);
1899 DP_NOTICE(p_hwfn, true,
1900 "PF failed to configure MAC for VF\n");
1904 p_vf->configured_features |= 1 << MAC_ADDR_FORCED;
1907 if (events & (1 << VLAN_ADDR_FORCED)) {
1908 struct ecore_sp_vport_update_params vport_update;
1912 OSAL_MEMSET(&filter, 0, sizeof(filter));
1913 filter.type = ECORE_FILTER_VLAN;
1914 filter.is_rx_filter = 1;
1915 filter.is_tx_filter = 1;
1916 filter.vport_to_add_to = p_vf->vport_id;
1917 filter.vlan = p_vf->bulletin.p_virt->pvid;
1918 filter.opcode = filter.vlan ? ECORE_FILTER_REPLACE :
1921 /* Send the ramrod */
1922 rc = ecore_sp_eth_filter_ucast(p_hwfn, p_vf->opaque_fid,
1924 ECORE_SPQ_MODE_CB, OSAL_NULL);
1926 DP_NOTICE(p_hwfn, true,
1927 "PF failed to configure VLAN for VF\n");
1931 /* Update the default-vlan & silent vlan stripping */
1932 OSAL_MEMSET(&vport_update, 0, sizeof(vport_update));
1933 vport_update.opaque_fid = p_vf->opaque_fid;
1934 vport_update.vport_id = p_vf->vport_id;
1935 vport_update.update_default_vlan_enable_flg = 1;
1936 vport_update.default_vlan_enable_flg = filter.vlan ? 1 : 0;
1937 vport_update.update_default_vlan_flg = 1;
1938 vport_update.default_vlan = filter.vlan;
1940 vport_update.update_inner_vlan_removal_flg = 1;
1941 removal = filter.vlan ?
1942 1 : p_vf->shadow_config.inner_vlan_removal;
1943 vport_update.inner_vlan_removal_flg = removal;
1944 vport_update.silent_vlan_removal_flg = filter.vlan ? 1 : 0;
1945 rc = ecore_sp_vport_update(p_hwfn, &vport_update,
1946 ECORE_SPQ_MODE_EBLOCK, OSAL_NULL);
1948 DP_NOTICE(p_hwfn, true,
1949 "PF failed to configure VF vport for vlan\n");
1953 /* Update all the Rx queues */
1954 for (i = 0; i < ECORE_MAX_VF_CHAINS_PER_PF; i++) {
1955 struct ecore_vf_queue *p_queue = &p_vf->vf_queues[i];
1956 struct ecore_queue_cid *p_cid = OSAL_NULL;
1958 /* There can be at most 1 Rx queue on qzone. Find it */
1959 p_cid = ecore_iov_get_vf_rx_queue_cid(p_hwfn, p_vf,
1961 if (p_cid == OSAL_NULL)
1964 rc = ecore_sp_eth_rx_queues_update(p_hwfn,
1967 ECORE_SPQ_MODE_EBLOCK,
1970 DP_NOTICE(p_hwfn, true,
1971 "Failed to send Rx update"
1972 " fo queue[0x%04x]\n",
1973 p_cid->rel.queue_id);
1979 p_vf->configured_features |= 1 << VLAN_ADDR_FORCED;
1981 p_vf->configured_features &= ~(1 << VLAN_ADDR_FORCED);
1984 /* If forced features are terminated, we need to configure the shadow
1985 * configuration back again.
1988 ecore_iov_reconfigure_unicast_shadow(p_hwfn, p_vf, events);
1993 static void ecore_iov_vf_mbx_start_vport(struct ecore_hwfn *p_hwfn,
1994 struct ecore_ptt *p_ptt,
1995 struct ecore_vf_info *vf)
1997 struct ecore_sp_vport_start_params params = { 0 };
1998 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
1999 struct vfpf_vport_start_tlv *start;
2000 u8 status = PFVF_STATUS_SUCCESS;
2001 struct ecore_vf_info *vf_info;
2004 enum _ecore_status_t rc;
2006 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vf->relative_vf_id, true);
2008 DP_NOTICE(p_hwfn->p_dev, true,
2009 "Failed to get VF info, invalid vfid [%d]\n",
2010 vf->relative_vf_id);
2014 vf->state = VF_ENABLED;
2015 start = &mbx->req_virt->start_vport;
2017 ecore_iov_enable_vf_traffic(p_hwfn, p_ptt, vf);
2019 /* Initialize Status block in CAU */
2020 for (sb_id = 0; sb_id < vf->num_sbs; sb_id++) {
2021 if (!start->sb_addr[sb_id]) {
2022 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2023 "VF[%d] did not fill the address of SB %d\n",
2024 vf->relative_vf_id, sb_id);
2028 ecore_int_cau_conf_sb(p_hwfn, p_ptt,
2029 start->sb_addr[sb_id],
2034 vf->mtu = start->mtu;
2035 vf->shadow_config.inner_vlan_removal = start->inner_vlan_removal;
2037 /* Take into consideration configuration forced by hypervisor;
2038 * If none is configured, use the supplied VF values [for old
2039 * vfs that would still be fine, since they passed '0' as padding].
2041 p_bitmap = &vf_info->bulletin.p_virt->valid_bitmap;
2042 if (!(*p_bitmap & (1 << VFPF_BULLETIN_UNTAGGED_DEFAULT_FORCED))) {
2043 u8 vf_req = start->only_untagged;
2045 vf_info->bulletin.p_virt->default_only_untagged = vf_req;
2046 *p_bitmap |= 1 << VFPF_BULLETIN_UNTAGGED_DEFAULT;
2049 params.tpa_mode = start->tpa_mode;
2050 params.remove_inner_vlan = start->inner_vlan_removal;
2051 params.tx_switching = true;
2054 if (CHIP_REV_IS_FPGA(p_hwfn->p_dev)) {
2055 DP_NOTICE(p_hwfn, false,
2056 "FPGA: Don't config VF for Tx-switching [no pVFC]\n");
2057 params.tx_switching = false;
2061 params.only_untagged = vf_info->bulletin.p_virt->default_only_untagged;
2062 params.drop_ttl0 = false;
2063 params.concrete_fid = vf->concrete_fid;
2064 params.opaque_fid = vf->opaque_fid;
2065 params.vport_id = vf->vport_id;
2066 params.max_buffers_per_cqe = start->max_buffers_per_cqe;
2067 params.mtu = vf->mtu;
2068 params.check_mac = true;
2070 rc = ecore_sp_eth_vport_start(p_hwfn, ¶ms);
2071 if (rc != ECORE_SUCCESS) {
2073 "ecore_iov_vf_mbx_start_vport returned error %d\n", rc);
2074 status = PFVF_STATUS_FAILURE;
2076 vf->vport_instance++;
2078 /* Force configuration if needed on the newly opened vport */
2079 ecore_iov_configure_vport_forced(p_hwfn, vf, *p_bitmap);
2080 OSAL_IOV_POST_START_VPORT(p_hwfn, vf->relative_vf_id,
2081 vf->vport_id, vf->opaque_fid);
2082 __ecore_iov_spoofchk_set(p_hwfn, vf, vf->req_spoofchk_val);
2085 ecore_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_VPORT_START,
2086 sizeof(struct pfvf_def_resp_tlv), status);
2089 static void ecore_iov_vf_mbx_stop_vport(struct ecore_hwfn *p_hwfn,
2090 struct ecore_ptt *p_ptt,
2091 struct ecore_vf_info *vf)
2093 u8 status = PFVF_STATUS_SUCCESS;
2094 enum _ecore_status_t rc;
2096 vf->vport_instance--;
2097 vf->spoof_chk = false;
2099 if ((ecore_iov_validate_active_rxq(p_hwfn, vf)) ||
2100 (ecore_iov_validate_active_txq(p_hwfn, vf))) {
2101 vf->b_malicious = true;
2102 DP_NOTICE(p_hwfn, false,
2103 "VF [%02x] - considered malicious;"
2104 " Unable to stop RX/TX queuess\n",
2108 rc = ecore_sp_vport_stop(p_hwfn, vf->opaque_fid, vf->vport_id);
2109 if (rc != ECORE_SUCCESS) {
2111 "ecore_iov_vf_mbx_stop_vport returned error %d\n", rc);
2112 status = PFVF_STATUS_FAILURE;
2115 /* Forget the configuration on the vport */
2116 vf->configured_features = 0;
2117 OSAL_MEMSET(&vf->shadow_config, 0, sizeof(vf->shadow_config));
2119 ecore_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_VPORT_TEARDOWN,
2120 sizeof(struct pfvf_def_resp_tlv), status);
2123 static void ecore_iov_vf_mbx_start_rxq_resp(struct ecore_hwfn *p_hwfn,
2124 struct ecore_ptt *p_ptt,
2125 struct ecore_vf_info *vf,
2126 u8 status, bool b_legacy)
2128 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
2129 struct pfvf_start_queue_resp_tlv *p_tlv;
2130 struct vfpf_start_rxq_tlv *req;
2133 mbx->offset = (u8 *)mbx->reply_virt;
2135 /* Taking a bigger struct instead of adding a TLV to list was a
2136 * mistake, but one which we're now stuck with, as some older
2137 * clients assume the size of the previous response.
2140 length = sizeof(*p_tlv);
2142 length = sizeof(struct pfvf_def_resp_tlv);
2144 p_tlv = ecore_add_tlv(p_hwfn, &mbx->offset, CHANNEL_TLV_START_RXQ,
2146 ecore_add_tlv(p_hwfn, &mbx->offset, CHANNEL_TLV_LIST_END,
2147 sizeof(struct channel_list_end_tlv));
2149 /* Update the TLV with the response */
2150 if ((status == PFVF_STATUS_SUCCESS) && !b_legacy) {
2151 req = &mbx->req_virt->start_rxq;
2152 p_tlv->offset = PXP_VF_BAR0_START_MSDM_ZONE_B +
2153 OFFSETOF(struct mstorm_vf_zone,
2154 non_trigger.eth_rx_queue_producers) +
2155 sizeof(struct eth_rx_prod_data) * req->rx_qid;
2158 ecore_iov_send_response(p_hwfn, p_ptt, vf, length, status);
2161 static void ecore_iov_vf_mbx_start_rxq(struct ecore_hwfn *p_hwfn,
2162 struct ecore_ptt *p_ptt,
2163 struct ecore_vf_info *vf)
2165 struct ecore_queue_start_common_params params;
2166 struct ecore_queue_cid_vf_params vf_params;
2167 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
2168 u8 status = PFVF_STATUS_NO_RESOURCE;
2169 struct ecore_vf_queue *p_queue;
2170 struct vfpf_start_rxq_tlv *req;
2171 struct ecore_queue_cid *p_cid;
2172 bool b_legacy_vf = false;
2174 enum _ecore_status_t rc;
2176 req = &mbx->req_virt->start_rxq;
2178 if (!ecore_iov_validate_rxq(p_hwfn, vf, req->rx_qid,
2179 ECORE_IOV_VALIDATE_Q_DISABLE) ||
2180 !ecore_iov_validate_sb(p_hwfn, vf, req->hw_sb))
2183 /* Legacy VFs made assumptions on the CID their queues connected to,
2184 * assuming queue X used CID X.
2185 * TODO - need to validate that there was no official release post
2186 * the current legacy scheme that still made that assumption.
2188 if (vf->acquire.vfdev_info.eth_fp_hsi_minor ==
2189 ETH_HSI_VER_NO_PKT_LEN_TUNN)
2192 /* Acquire a new queue-cid */
2193 p_queue = &vf->vf_queues[req->rx_qid];
2195 OSAL_MEMSET(¶ms, 0, sizeof(params));
2196 params.queue_id = (u8)p_queue->fw_rx_qid;
2197 params.vport_id = vf->vport_id;
2198 params.stats_id = vf->abs_vf_id + 0x10;
2199 params.sb = req->hw_sb;
2200 params.sb_idx = req->sb_index;
2202 /* TODO - set qid_usage_idx according to extended TLV. For now, use
2207 OSAL_MEM_ZERO(&vf_params, sizeof(vf_params));
2208 vf_params.vfid = vf->relative_vf_id;
2209 vf_params.vf_qid = (u8)req->rx_qid;
2210 vf_params.b_legacy = b_legacy_vf;
2211 vf_params.qid_usage_idx = qid_usage_idx;
2213 p_cid = ecore_eth_queue_to_cid(p_hwfn, vf->opaque_fid,
2214 ¶ms, &vf_params);
2215 if (p_cid == OSAL_NULL)
2218 /* Legacy VFs have their Producers in a different location, which they
2219 * calculate on their own and clean the producer prior to this.
2223 GTT_BAR0_MAP_REG_MSDM_RAM +
2224 MSTORM_ETH_VF_PRODS_OFFSET(vf->abs_vf_id, req->rx_qid),
2227 rc = ecore_eth_rxq_start_ramrod(p_hwfn, p_cid,
2232 if (rc != ECORE_SUCCESS) {
2233 status = PFVF_STATUS_FAILURE;
2234 ecore_eth_queue_cid_release(p_hwfn, p_cid);
2236 p_queue->cids[qid_usage_idx].p_cid = p_cid;
2237 p_queue->cids[qid_usage_idx].b_is_tx = false;
2238 status = PFVF_STATUS_SUCCESS;
2239 vf->num_active_rxqs++;
2243 ecore_iov_vf_mbx_start_rxq_resp(p_hwfn, p_ptt, vf, status,
2248 ecore_iov_pf_update_tun_response(struct pfvf_update_tunn_param_tlv *p_resp,
2249 struct ecore_tunnel_info *p_tun,
2250 u16 tunn_feature_mask)
2252 p_resp->tunn_feature_mask = tunn_feature_mask;
2253 p_resp->vxlan_mode = p_tun->vxlan.b_mode_enabled;
2254 p_resp->l2geneve_mode = p_tun->l2_geneve.b_mode_enabled;
2255 p_resp->ipgeneve_mode = p_tun->ip_geneve.b_mode_enabled;
2256 p_resp->l2gre_mode = p_tun->l2_gre.b_mode_enabled;
2257 p_resp->ipgre_mode = p_tun->l2_gre.b_mode_enabled;
2258 p_resp->vxlan_clss = p_tun->vxlan.tun_cls;
2259 p_resp->l2gre_clss = p_tun->l2_gre.tun_cls;
2260 p_resp->ipgre_clss = p_tun->ip_gre.tun_cls;
2261 p_resp->l2geneve_clss = p_tun->l2_geneve.tun_cls;
2262 p_resp->ipgeneve_clss = p_tun->ip_geneve.tun_cls;
2263 p_resp->geneve_udp_port = p_tun->geneve_port.port;
2264 p_resp->vxlan_udp_port = p_tun->vxlan_port.port;
2268 __ecore_iov_pf_update_tun_param(struct vfpf_update_tunn_param_tlv *p_req,
2269 struct ecore_tunn_update_type *p_tun,
2270 enum ecore_tunn_mode mask, u8 tun_cls)
2272 if (p_req->tun_mode_update_mask & (1 << mask)) {
2273 p_tun->b_update_mode = true;
2275 if (p_req->tunn_mode & (1 << mask))
2276 p_tun->b_mode_enabled = true;
2279 p_tun->tun_cls = tun_cls;
2283 ecore_iov_pf_update_tun_param(struct vfpf_update_tunn_param_tlv *p_req,
2284 struct ecore_tunn_update_type *p_tun,
2285 struct ecore_tunn_update_udp_port *p_port,
2286 enum ecore_tunn_mode mask,
2287 u8 tun_cls, u8 update_port, u16 port)
2290 p_port->b_update_port = true;
2291 p_port->port = port;
2294 __ecore_iov_pf_update_tun_param(p_req, p_tun, mask, tun_cls);
2298 ecore_iov_pf_validate_tunn_param(struct vfpf_update_tunn_param_tlv *p_req)
2300 bool b_update_requested = false;
2302 if (p_req->tun_mode_update_mask || p_req->update_tun_cls ||
2303 p_req->update_geneve_port || p_req->update_vxlan_port)
2304 b_update_requested = true;
2306 return b_update_requested;
2309 static void ecore_iov_vf_mbx_update_tunn_param(struct ecore_hwfn *p_hwfn,
2310 struct ecore_ptt *p_ptt,
2311 struct ecore_vf_info *p_vf)
2313 struct ecore_tunnel_info *p_tun = &p_hwfn->p_dev->tunnel;
2314 struct ecore_iov_vf_mbx *mbx = &p_vf->vf_mbx;
2315 struct pfvf_update_tunn_param_tlv *p_resp;
2316 struct vfpf_update_tunn_param_tlv *p_req;
2317 enum _ecore_status_t rc = ECORE_SUCCESS;
2318 u8 status = PFVF_STATUS_SUCCESS;
2319 bool b_update_required = false;
2320 struct ecore_tunnel_info tunn;
2321 u16 tunn_feature_mask = 0;
2324 mbx->offset = (u8 *)mbx->reply_virt;
2326 OSAL_MEM_ZERO(&tunn, sizeof(tunn));
2327 p_req = &mbx->req_virt->tunn_param_update;
2329 if (!ecore_iov_pf_validate_tunn_param(p_req)) {
2330 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2331 "No tunnel update requested by VF\n");
2332 status = PFVF_STATUS_FAILURE;
2336 tunn.b_update_rx_cls = p_req->update_tun_cls;
2337 tunn.b_update_tx_cls = p_req->update_tun_cls;
2339 ecore_iov_pf_update_tun_param(p_req, &tunn.vxlan, &tunn.vxlan_port,
2340 ECORE_MODE_VXLAN_TUNN, p_req->vxlan_clss,
2341 p_req->update_vxlan_port,
2343 ecore_iov_pf_update_tun_param(p_req, &tunn.l2_geneve, &tunn.geneve_port,
2344 ECORE_MODE_L2GENEVE_TUNN,
2345 p_req->l2geneve_clss,
2346 p_req->update_geneve_port,
2347 p_req->geneve_port);
2348 __ecore_iov_pf_update_tun_param(p_req, &tunn.ip_geneve,
2349 ECORE_MODE_IPGENEVE_TUNN,
2350 p_req->ipgeneve_clss);
2351 __ecore_iov_pf_update_tun_param(p_req, &tunn.l2_gre,
2352 ECORE_MODE_L2GRE_TUNN,
2354 __ecore_iov_pf_update_tun_param(p_req, &tunn.ip_gre,
2355 ECORE_MODE_IPGRE_TUNN,
2358 /* If PF modifies VF's req then it should
2359 * still return an error in case of partial configuration
2360 * or modified configuration as opposed to requested one.
2362 rc = OSAL_PF_VALIDATE_MODIFY_TUNN_CONFIG(p_hwfn, &tunn_feature_mask,
2363 &b_update_required, &tunn);
2365 if (rc != ECORE_SUCCESS)
2366 status = PFVF_STATUS_FAILURE;
2368 /* If ECORE client is willing to update anything ? */
2369 if (b_update_required) {
2372 rc = ecore_sp_pf_update_tunn_cfg(p_hwfn, &tunn,
2373 ECORE_SPQ_MODE_EBLOCK,
2375 if (rc != ECORE_SUCCESS)
2376 status = PFVF_STATUS_FAILURE;
2378 geneve_port = p_tun->geneve_port.port;
2379 ecore_for_each_vf(p_hwfn, i) {
2380 ecore_iov_bulletin_set_udp_ports(p_hwfn, i,
2381 p_tun->vxlan_port.port,
2387 p_resp = ecore_add_tlv(p_hwfn, &mbx->offset,
2388 CHANNEL_TLV_UPDATE_TUNN_PARAM, sizeof(*p_resp));
2390 ecore_iov_pf_update_tun_response(p_resp, p_tun, tunn_feature_mask);
2391 ecore_add_tlv(p_hwfn, &mbx->offset, CHANNEL_TLV_LIST_END,
2392 sizeof(struct channel_list_end_tlv));
2394 ecore_iov_send_response(p_hwfn, p_ptt, p_vf, sizeof(*p_resp), status);
2397 static void ecore_iov_vf_mbx_start_txq_resp(struct ecore_hwfn *p_hwfn,
2398 struct ecore_ptt *p_ptt,
2399 struct ecore_vf_info *p_vf,
2403 struct ecore_iov_vf_mbx *mbx = &p_vf->vf_mbx;
2404 struct pfvf_start_queue_resp_tlv *p_tlv;
2405 bool b_legacy = false;
2408 mbx->offset = (u8 *)mbx->reply_virt;
2410 /* Taking a bigger struct instead of adding a TLV to list was a
2411 * mistake, but one which we're now stuck with, as some older
2412 * clients assume the size of the previous response.
2414 if (p_vf->acquire.vfdev_info.eth_fp_hsi_minor ==
2415 ETH_HSI_VER_NO_PKT_LEN_TUNN)
2419 length = sizeof(*p_tlv);
2421 length = sizeof(struct pfvf_def_resp_tlv);
2423 p_tlv = ecore_add_tlv(p_hwfn, &mbx->offset, CHANNEL_TLV_START_TXQ,
2425 ecore_add_tlv(p_hwfn, &mbx->offset, CHANNEL_TLV_LIST_END,
2426 sizeof(struct channel_list_end_tlv));
2428 /* Update the TLV with the response */
2429 if ((status == PFVF_STATUS_SUCCESS) && !b_legacy)
2430 p_tlv->offset = DB_ADDR_VF(cid, DQ_DEMS_LEGACY);
2432 ecore_iov_send_response(p_hwfn, p_ptt, p_vf, length, status);
2435 static void ecore_iov_vf_mbx_start_txq(struct ecore_hwfn *p_hwfn,
2436 struct ecore_ptt *p_ptt,
2437 struct ecore_vf_info *vf)
2439 struct ecore_queue_start_common_params params;
2440 struct ecore_queue_cid_vf_params vf_params;
2441 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
2442 u8 status = PFVF_STATUS_NO_RESOURCE;
2443 struct ecore_vf_queue *p_queue;
2444 struct vfpf_start_txq_tlv *req;
2445 struct ecore_queue_cid *p_cid;
2446 bool b_legacy_vf = false;
2449 enum _ecore_status_t rc;
2452 OSAL_MEMSET(¶ms, 0, sizeof(params));
2453 req = &mbx->req_virt->start_txq;
2455 if (!ecore_iov_validate_txq(p_hwfn, vf, req->tx_qid,
2456 ECORE_IOV_VALIDATE_Q_NA) ||
2457 !ecore_iov_validate_sb(p_hwfn, vf, req->hw_sb))
2460 /* In case this is a legacy VF - need to know to use the right cids.
2461 * TODO - need to validate that there was no official release post
2462 * the current legacy scheme that still made that assumption.
2464 if (vf->acquire.vfdev_info.eth_fp_hsi_minor ==
2465 ETH_HSI_VER_NO_PKT_LEN_TUNN)
2468 /* Acquire a new queue-cid */
2469 p_queue = &vf->vf_queues[req->tx_qid];
2471 params.queue_id = p_queue->fw_tx_qid;
2472 params.vport_id = vf->vport_id;
2473 params.stats_id = vf->abs_vf_id + 0x10;
2474 params.sb = req->hw_sb;
2475 params.sb_idx = req->sb_index;
2477 /* TODO - set qid_usage_idx according to extended TLV. For now, use
2482 if (p_queue->cids[qid_usage_idx].p_cid)
2485 OSAL_MEM_ZERO(&vf_params, sizeof(vf_params));
2486 vf_params.vfid = vf->relative_vf_id;
2487 vf_params.vf_qid = (u8)req->tx_qid;
2488 vf_params.b_legacy = b_legacy_vf;
2489 vf_params.qid_usage_idx = qid_usage_idx;
2491 p_cid = ecore_eth_queue_to_cid(p_hwfn, vf->opaque_fid,
2492 ¶ms, &vf_params);
2493 if (p_cid == OSAL_NULL)
2496 pq = ecore_get_cm_pq_idx_vf(p_hwfn,
2497 vf->relative_vf_id);
2498 rc = ecore_eth_txq_start_ramrod(p_hwfn, p_cid,
2499 req->pbl_addr, req->pbl_size, pq);
2500 if (rc != ECORE_SUCCESS) {
2501 status = PFVF_STATUS_FAILURE;
2502 ecore_eth_queue_cid_release(p_hwfn, p_cid);
2504 status = PFVF_STATUS_SUCCESS;
2505 p_queue->cids[qid_usage_idx].p_cid = p_cid;
2506 p_queue->cids[qid_usage_idx].b_is_tx = true;
2511 ecore_iov_vf_mbx_start_txq_resp(p_hwfn, p_ptt, vf,
2515 static enum _ecore_status_t ecore_iov_vf_stop_rxqs(struct ecore_hwfn *p_hwfn,
2516 struct ecore_vf_info *vf,
2519 bool cqe_completion)
2521 enum _ecore_status_t rc = ECORE_SUCCESS;
2524 /* TODO - improve validation [wrap around] */
2525 if (rxq_id + num_rxqs > OSAL_ARRAY_SIZE(vf->vf_queues))
2528 for (qid = rxq_id; qid < rxq_id + num_rxqs; qid++) {
2529 struct ecore_vf_queue *p_queue = &vf->vf_queues[qid];
2530 struct ecore_queue_cid **pp_cid = OSAL_NULL;
2532 /* There can be at most a single Rx per qzone. Find it */
2533 for (i = 0; i < MAX_QUEUES_PER_QZONE; i++) {
2534 if (p_queue->cids[i].p_cid &&
2535 !p_queue->cids[i].b_is_tx) {
2536 pp_cid = &p_queue->cids[i].p_cid;
2540 if (pp_cid == OSAL_NULL) {
2541 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2542 "Ignoring VF[%02x] request of closing Rx queue %04x - closed\n",
2543 vf->relative_vf_id, qid);
2547 rc = ecore_eth_rx_queue_stop(p_hwfn, *pp_cid,
2548 false, cqe_completion);
2549 if (rc != ECORE_SUCCESS)
2552 *pp_cid = OSAL_NULL;
2553 vf->num_active_rxqs--;
2559 static enum _ecore_status_t ecore_iov_vf_stop_txqs(struct ecore_hwfn *p_hwfn,
2560 struct ecore_vf_info *vf,
2561 u16 txq_id, u8 num_txqs)
2563 enum _ecore_status_t rc = ECORE_SUCCESS;
2564 struct ecore_vf_queue *p_queue;
2567 if (!ecore_iov_validate_txq(p_hwfn, vf, txq_id,
2568 ECORE_IOV_VALIDATE_Q_NA) ||
2569 !ecore_iov_validate_txq(p_hwfn, vf, txq_id + num_txqs,
2570 ECORE_IOV_VALIDATE_Q_NA))
2573 for (qid = txq_id; qid < txq_id + num_txqs; qid++) {
2574 p_queue = &vf->vf_queues[qid];
2575 for (j = 0; j < MAX_QUEUES_PER_QZONE; j++) {
2576 if (p_queue->cids[j].p_cid == OSAL_NULL)
2579 if (!p_queue->cids[j].b_is_tx)
2582 rc = ecore_eth_tx_queue_stop(p_hwfn,
2583 p_queue->cids[j].p_cid);
2584 if (rc != ECORE_SUCCESS)
2587 p_queue->cids[j].p_cid = OSAL_NULL;
2594 static void ecore_iov_vf_mbx_stop_rxqs(struct ecore_hwfn *p_hwfn,
2595 struct ecore_ptt *p_ptt,
2596 struct ecore_vf_info *vf)
2598 u16 length = sizeof(struct pfvf_def_resp_tlv);
2599 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
2600 u8 status = PFVF_STATUS_SUCCESS;
2601 struct vfpf_stop_rxqs_tlv *req;
2602 enum _ecore_status_t rc;
2604 /* We give the option of starting from qid != 0, in this case we
2605 * need to make sure that qid + num_qs doesn't exceed the actual
2606 * amount of queues that exist.
2608 req = &mbx->req_virt->stop_rxqs;
2609 rc = ecore_iov_vf_stop_rxqs(p_hwfn, vf, req->rx_qid,
2610 req->num_rxqs, req->cqe_completion);
2612 status = PFVF_STATUS_FAILURE;
2614 ecore_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_STOP_RXQS,
2618 static void ecore_iov_vf_mbx_stop_txqs(struct ecore_hwfn *p_hwfn,
2619 struct ecore_ptt *p_ptt,
2620 struct ecore_vf_info *vf)
2622 u16 length = sizeof(struct pfvf_def_resp_tlv);
2623 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
2624 u8 status = PFVF_STATUS_SUCCESS;
2625 struct vfpf_stop_txqs_tlv *req;
2626 enum _ecore_status_t rc;
2628 /* We give the option of starting from qid != 0, in this case we
2629 * need to make sure that qid + num_qs doesn't exceed the actual
2630 * amount of queues that exist.
2632 req = &mbx->req_virt->stop_txqs;
2633 rc = ecore_iov_vf_stop_txqs(p_hwfn, vf, req->tx_qid, req->num_txqs);
2635 status = PFVF_STATUS_FAILURE;
2637 ecore_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_STOP_TXQS,
2641 static void ecore_iov_vf_mbx_update_rxqs(struct ecore_hwfn *p_hwfn,
2642 struct ecore_ptt *p_ptt,
2643 struct ecore_vf_info *vf)
2645 struct ecore_queue_cid *handlers[ECORE_MAX_VF_CHAINS_PER_PF];
2646 u16 length = sizeof(struct pfvf_def_resp_tlv);
2647 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
2648 struct vfpf_update_rxq_tlv *req;
2649 u8 status = PFVF_STATUS_FAILURE;
2650 u8 complete_event_flg;
2651 u8 complete_cqe_flg;
2652 enum _ecore_status_t rc;
2655 req = &mbx->req_virt->update_rxq;
2656 complete_cqe_flg = !!(req->flags & VFPF_RXQ_UPD_COMPLETE_CQE_FLAG);
2657 complete_event_flg = !!(req->flags & VFPF_RXQ_UPD_COMPLETE_EVENT_FLAG);
2659 /* Validate inputs */
2660 for (i = req->rx_qid; i < req->rx_qid + req->num_rxqs; i++) {
2661 if (!ecore_iov_validate_rxq(p_hwfn, vf, i,
2662 ECORE_IOV_VALIDATE_Q_ENABLE)) {
2663 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2664 "VF[%d]: Incorrect Rxqs [%04x, %02x]\n",
2665 vf->relative_vf_id, req->rx_qid,
2671 for (i = 0; i < req->num_rxqs; i++) {
2672 struct ecore_vf_queue *p_queue;
2673 u16 qid = req->rx_qid + i;
2675 p_queue = &vf->vf_queues[qid];
2676 handlers[i] = ecore_iov_get_vf_rx_queue_cid(p_hwfn, vf,
2680 rc = ecore_sp_eth_rx_queues_update(p_hwfn, (void **)&handlers,
2684 ECORE_SPQ_MODE_EBLOCK,
2689 status = PFVF_STATUS_SUCCESS;
2691 ecore_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_UPDATE_RXQ,
2695 void *ecore_iov_search_list_tlvs(struct ecore_hwfn *p_hwfn,
2696 void *p_tlvs_list, u16 req_type)
2698 struct channel_tlv *p_tlv = (struct channel_tlv *)p_tlvs_list;
2702 if (!p_tlv->length) {
2703 DP_NOTICE(p_hwfn, true, "Zero length TLV found\n");
2707 if (p_tlv->type == req_type) {
2708 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2709 "Extended tlv type %s, length %d found\n",
2710 ecore_channel_tlvs_string[p_tlv->type],
2715 len += p_tlv->length;
2716 p_tlv = (struct channel_tlv *)((u8 *)p_tlv + p_tlv->length);
2718 if ((len + p_tlv->length) > TLV_BUFFER_SIZE) {
2719 DP_NOTICE(p_hwfn, true,
2720 "TLVs has overrun the buffer size\n");
2723 } while (p_tlv->type != CHANNEL_TLV_LIST_END);
2729 ecore_iov_vp_update_act_param(struct ecore_hwfn *p_hwfn,
2730 struct ecore_sp_vport_update_params *p_data,
2731 struct ecore_iov_vf_mbx *p_mbx, u16 *tlvs_mask)
2733 struct vfpf_vport_update_activate_tlv *p_act_tlv;
2734 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_ACTIVATE;
2736 p_act_tlv = (struct vfpf_vport_update_activate_tlv *)
2737 ecore_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
2741 p_data->update_vport_active_rx_flg = p_act_tlv->update_rx;
2742 p_data->vport_active_rx_flg = p_act_tlv->active_rx;
2743 p_data->update_vport_active_tx_flg = p_act_tlv->update_tx;
2744 p_data->vport_active_tx_flg = p_act_tlv->active_tx;
2745 *tlvs_mask |= 1 << ECORE_IOV_VP_UPDATE_ACTIVATE;
2749 ecore_iov_vp_update_vlan_param(struct ecore_hwfn *p_hwfn,
2750 struct ecore_sp_vport_update_params *p_data,
2751 struct ecore_vf_info *p_vf,
2752 struct ecore_iov_vf_mbx *p_mbx, u16 *tlvs_mask)
2754 struct vfpf_vport_update_vlan_strip_tlv *p_vlan_tlv;
2755 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_VLAN_STRIP;
2757 p_vlan_tlv = (struct vfpf_vport_update_vlan_strip_tlv *)
2758 ecore_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
2762 p_vf->shadow_config.inner_vlan_removal = p_vlan_tlv->remove_vlan;
2764 /* Ignore the VF request if we're forcing a vlan */
2765 if (!(p_vf->configured_features & (1 << VLAN_ADDR_FORCED))) {
2766 p_data->update_inner_vlan_removal_flg = 1;
2767 p_data->inner_vlan_removal_flg = p_vlan_tlv->remove_vlan;
2770 *tlvs_mask |= 1 << ECORE_IOV_VP_UPDATE_VLAN_STRIP;
2774 ecore_iov_vp_update_tx_switch(struct ecore_hwfn *p_hwfn,
2775 struct ecore_sp_vport_update_params *p_data,
2776 struct ecore_iov_vf_mbx *p_mbx, u16 *tlvs_mask)
2778 struct vfpf_vport_update_tx_switch_tlv *p_tx_switch_tlv;
2779 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_TX_SWITCH;
2781 p_tx_switch_tlv = (struct vfpf_vport_update_tx_switch_tlv *)
2782 ecore_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
2783 if (!p_tx_switch_tlv)
2787 if (CHIP_REV_IS_FPGA(p_hwfn->p_dev)) {
2788 DP_NOTICE(p_hwfn, false,
2789 "FPGA: Ignore tx-switching configuration originating"
2795 p_data->update_tx_switching_flg = 1;
2796 p_data->tx_switching_flg = p_tx_switch_tlv->tx_switching;
2797 *tlvs_mask |= 1 << ECORE_IOV_VP_UPDATE_TX_SWITCH;
2801 ecore_iov_vp_update_mcast_bin_param(struct ecore_hwfn *p_hwfn,
2802 struct ecore_sp_vport_update_params *p_data,
2803 struct ecore_iov_vf_mbx *p_mbx,
2806 struct vfpf_vport_update_mcast_bin_tlv *p_mcast_tlv;
2807 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_MCAST;
2809 p_mcast_tlv = (struct vfpf_vport_update_mcast_bin_tlv *)
2810 ecore_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
2814 p_data->update_approx_mcast_flg = 1;
2815 OSAL_MEMCPY(p_data->bins, p_mcast_tlv->bins,
2816 sizeof(unsigned long) *
2817 ETH_MULTICAST_MAC_BINS_IN_REGS);
2818 *tlvs_mask |= 1 << ECORE_IOV_VP_UPDATE_MCAST;
2822 ecore_iov_vp_update_accept_flag(struct ecore_hwfn *p_hwfn,
2823 struct ecore_sp_vport_update_params *p_data,
2824 struct ecore_iov_vf_mbx *p_mbx, u16 *tlvs_mask)
2826 struct ecore_filter_accept_flags *p_flags = &p_data->accept_flags;
2827 struct vfpf_vport_update_accept_param_tlv *p_accept_tlv;
2828 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_ACCEPT_PARAM;
2830 p_accept_tlv = (struct vfpf_vport_update_accept_param_tlv *)
2831 ecore_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
2835 p_flags->update_rx_mode_config = p_accept_tlv->update_rx_mode;
2836 p_flags->rx_accept_filter = p_accept_tlv->rx_accept_filter;
2837 p_flags->update_tx_mode_config = p_accept_tlv->update_tx_mode;
2838 p_flags->tx_accept_filter = p_accept_tlv->tx_accept_filter;
2839 *tlvs_mask |= 1 << ECORE_IOV_VP_UPDATE_ACCEPT_PARAM;
2843 ecore_iov_vp_update_accept_any_vlan(struct ecore_hwfn *p_hwfn,
2844 struct ecore_sp_vport_update_params *p_data,
2845 struct ecore_iov_vf_mbx *p_mbx,
2848 struct vfpf_vport_update_accept_any_vlan_tlv *p_accept_any_vlan;
2849 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_ACCEPT_ANY_VLAN;
2851 p_accept_any_vlan = (struct vfpf_vport_update_accept_any_vlan_tlv *)
2852 ecore_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
2853 if (!p_accept_any_vlan)
2856 p_data->accept_any_vlan = p_accept_any_vlan->accept_any_vlan;
2857 p_data->update_accept_any_vlan_flg =
2858 p_accept_any_vlan->update_accept_any_vlan_flg;
2859 *tlvs_mask |= 1 << ECORE_IOV_VP_UPDATE_ACCEPT_ANY_VLAN;
2863 ecore_iov_vp_update_rss_param(struct ecore_hwfn *p_hwfn,
2864 struct ecore_vf_info *vf,
2865 struct ecore_sp_vport_update_params *p_data,
2866 struct ecore_rss_params *p_rss,
2867 struct ecore_iov_vf_mbx *p_mbx,
2868 u16 *tlvs_mask, u16 *tlvs_accepted)
2870 struct vfpf_vport_update_rss_tlv *p_rss_tlv;
2871 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_RSS;
2872 bool b_reject = false;
2876 p_rss_tlv = (struct vfpf_vport_update_rss_tlv *)
2877 ecore_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
2879 p_data->rss_params = OSAL_NULL;
2883 OSAL_MEMSET(p_rss, 0, sizeof(struct ecore_rss_params));
2885 p_rss->update_rss_config =
2886 !!(p_rss_tlv->update_rss_flags &
2887 VFPF_UPDATE_RSS_CONFIG_FLAG);
2888 p_rss->update_rss_capabilities =
2889 !!(p_rss_tlv->update_rss_flags &
2890 VFPF_UPDATE_RSS_CAPS_FLAG);
2891 p_rss->update_rss_ind_table =
2892 !!(p_rss_tlv->update_rss_flags &
2893 VFPF_UPDATE_RSS_IND_TABLE_FLAG);
2894 p_rss->update_rss_key =
2895 !!(p_rss_tlv->update_rss_flags &
2896 VFPF_UPDATE_RSS_KEY_FLAG);
2898 p_rss->rss_enable = p_rss_tlv->rss_enable;
2899 p_rss->rss_eng_id = vf->rss_eng_id;
2900 p_rss->rss_caps = p_rss_tlv->rss_caps;
2901 p_rss->rss_table_size_log = p_rss_tlv->rss_table_size_log;
2902 OSAL_MEMCPY(p_rss->rss_key, p_rss_tlv->rss_key,
2903 sizeof(p_rss->rss_key));
2905 table_size = OSAL_MIN_T(u16, OSAL_ARRAY_SIZE(p_rss->rss_ind_table),
2906 (1 << p_rss_tlv->rss_table_size_log));
2908 for (i = 0; i < table_size; i++) {
2909 struct ecore_queue_cid *p_cid;
2911 q_idx = p_rss_tlv->rss_ind_table[i];
2912 if (!ecore_iov_validate_rxq(p_hwfn, vf, q_idx,
2913 ECORE_IOV_VALIDATE_Q_ENABLE)) {
2914 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2915 "VF[%d]: Omitting RSS due to wrong queue %04x\n",
2916 vf->relative_vf_id, q_idx);
2921 p_cid = ecore_iov_get_vf_rx_queue_cid(p_hwfn, vf,
2922 &vf->vf_queues[q_idx]);
2923 p_rss->rss_ind_table[i] = p_cid;
2926 p_data->rss_params = p_rss;
2928 *tlvs_mask |= 1 << ECORE_IOV_VP_UPDATE_RSS;
2930 *tlvs_accepted |= 1 << ECORE_IOV_VP_UPDATE_RSS;
2934 ecore_iov_vp_update_sge_tpa_param(struct ecore_hwfn *p_hwfn,
2935 struct ecore_vf_info *vf,
2936 struct ecore_sp_vport_update_params *p_data,
2937 struct ecore_sge_tpa_params *p_sge_tpa,
2938 struct ecore_iov_vf_mbx *p_mbx,
2941 struct vfpf_vport_update_sge_tpa_tlv *p_sge_tpa_tlv;
2942 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_SGE_TPA;
2944 p_sge_tpa_tlv = (struct vfpf_vport_update_sge_tpa_tlv *)
2945 ecore_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
2947 if (!p_sge_tpa_tlv) {
2948 p_data->sge_tpa_params = OSAL_NULL;
2952 OSAL_MEMSET(p_sge_tpa, 0, sizeof(struct ecore_sge_tpa_params));
2954 p_sge_tpa->update_tpa_en_flg =
2955 !!(p_sge_tpa_tlv->update_sge_tpa_flags & VFPF_UPDATE_TPA_EN_FLAG);
2956 p_sge_tpa->update_tpa_param_flg =
2957 !!(p_sge_tpa_tlv->update_sge_tpa_flags &
2958 VFPF_UPDATE_TPA_PARAM_FLAG);
2960 p_sge_tpa->tpa_ipv4_en_flg =
2961 !!(p_sge_tpa_tlv->sge_tpa_flags & VFPF_TPA_IPV4_EN_FLAG);
2962 p_sge_tpa->tpa_ipv6_en_flg =
2963 !!(p_sge_tpa_tlv->sge_tpa_flags & VFPF_TPA_IPV6_EN_FLAG);
2964 p_sge_tpa->tpa_pkt_split_flg =
2965 !!(p_sge_tpa_tlv->sge_tpa_flags & VFPF_TPA_PKT_SPLIT_FLAG);
2966 p_sge_tpa->tpa_hdr_data_split_flg =
2967 !!(p_sge_tpa_tlv->sge_tpa_flags & VFPF_TPA_HDR_DATA_SPLIT_FLAG);
2968 p_sge_tpa->tpa_gro_consistent_flg =
2969 !!(p_sge_tpa_tlv->sge_tpa_flags & VFPF_TPA_GRO_CONSIST_FLAG);
2971 p_sge_tpa->tpa_max_aggs_num = p_sge_tpa_tlv->tpa_max_aggs_num;
2972 p_sge_tpa->tpa_max_size = p_sge_tpa_tlv->tpa_max_size;
2973 p_sge_tpa->tpa_min_size_to_start = p_sge_tpa_tlv->tpa_min_size_to_start;
2974 p_sge_tpa->tpa_min_size_to_cont = p_sge_tpa_tlv->tpa_min_size_to_cont;
2975 p_sge_tpa->max_buffers_per_cqe = p_sge_tpa_tlv->max_buffers_per_cqe;
2977 p_data->sge_tpa_params = p_sge_tpa;
2979 *tlvs_mask |= 1 << ECORE_IOV_VP_UPDATE_SGE_TPA;
2982 static void ecore_iov_vf_mbx_vport_update(struct ecore_hwfn *p_hwfn,
2983 struct ecore_ptt *p_ptt,
2984 struct ecore_vf_info *vf)
2986 struct ecore_rss_params *p_rss_params = OSAL_NULL;
2987 struct ecore_sp_vport_update_params params;
2988 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
2989 struct ecore_sge_tpa_params sge_tpa_params;
2990 u16 tlvs_mask = 0, tlvs_accepted = 0;
2991 u8 status = PFVF_STATUS_SUCCESS;
2993 enum _ecore_status_t rc;
2995 /* Valiate PF can send such a request */
2996 if (!vf->vport_instance) {
2997 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2998 "No VPORT instance available for VF[%d],"
2999 " failing vport update\n",
3001 status = PFVF_STATUS_FAILURE;
3005 p_rss_params = OSAL_VZALLOC(p_hwfn->p_dev, sizeof(*p_rss_params));
3006 if (p_rss_params == OSAL_NULL) {
3007 status = PFVF_STATUS_FAILURE;
3011 OSAL_MEMSET(¶ms, 0, sizeof(params));
3012 params.opaque_fid = vf->opaque_fid;
3013 params.vport_id = vf->vport_id;
3014 params.rss_params = OSAL_NULL;
3016 /* Search for extended tlvs list and update values
3017 * from VF in struct ecore_sp_vport_update_params.
3019 ecore_iov_vp_update_act_param(p_hwfn, ¶ms, mbx, &tlvs_mask);
3020 ecore_iov_vp_update_vlan_param(p_hwfn, ¶ms, vf, mbx, &tlvs_mask);
3021 ecore_iov_vp_update_tx_switch(p_hwfn, ¶ms, mbx, &tlvs_mask);
3022 ecore_iov_vp_update_mcast_bin_param(p_hwfn, ¶ms, mbx, &tlvs_mask);
3023 ecore_iov_vp_update_accept_flag(p_hwfn, ¶ms, mbx, &tlvs_mask);
3024 ecore_iov_vp_update_accept_any_vlan(p_hwfn, ¶ms, mbx, &tlvs_mask);
3025 ecore_iov_vp_update_sge_tpa_param(p_hwfn, vf, ¶ms,
3026 &sge_tpa_params, mbx, &tlvs_mask);
3028 tlvs_accepted = tlvs_mask;
3030 /* Some of the extended TLVs need to be validated first; In that case,
3031 * they can update the mask without updating the accepted [so that
3032 * PF could communicate to VF it has rejected request].
3034 ecore_iov_vp_update_rss_param(p_hwfn, vf, ¶ms, p_rss_params,
3035 mbx, &tlvs_mask, &tlvs_accepted);
3037 /* Just log a message if there is no single extended tlv in buffer.
3038 * When all features of vport update ramrod would be requested by VF
3039 * as extended TLVs in buffer then an error can be returned in response
3040 * if there is no extended TLV present in buffer.
3042 if (OSAL_IOV_VF_VPORT_UPDATE(p_hwfn, vf->relative_vf_id,
3043 ¶ms, &tlvs_accepted) !=
3046 status = PFVF_STATUS_NOT_SUPPORTED;
3050 if (!tlvs_accepted) {
3052 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3053 "Upper-layer prevents said VF"
3054 " configuration\n");
3056 DP_NOTICE(p_hwfn, true,
3057 "No feature tlvs found for vport update\n");
3058 status = PFVF_STATUS_NOT_SUPPORTED;
3062 rc = ecore_sp_vport_update(p_hwfn, ¶ms, ECORE_SPQ_MODE_EBLOCK,
3066 status = PFVF_STATUS_FAILURE;
3069 OSAL_VFREE(p_hwfn->p_dev, p_rss_params);
3070 length = ecore_iov_prep_vp_update_resp_tlvs(p_hwfn, vf, mbx, status,
3071 tlvs_mask, tlvs_accepted);
3072 ecore_iov_send_response(p_hwfn, p_ptt, vf, length, status);
3075 static enum _ecore_status_t
3076 ecore_iov_vf_update_vlan_shadow(struct ecore_hwfn *p_hwfn,
3077 struct ecore_vf_info *p_vf,
3078 struct ecore_filter_ucast *p_params)
3082 /* First remove entries and then add new ones */
3083 if (p_params->opcode == ECORE_FILTER_REMOVE) {
3084 for (i = 0; i < ECORE_ETH_VF_NUM_VLAN_FILTERS + 1; i++)
3085 if (p_vf->shadow_config.vlans[i].used &&
3086 p_vf->shadow_config.vlans[i].vid ==
3088 p_vf->shadow_config.vlans[i].used = false;
3091 if (i == ECORE_ETH_VF_NUM_VLAN_FILTERS + 1) {
3092 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3093 "VF [%d] - Tries to remove a non-existing"
3095 p_vf->relative_vf_id);
3098 } else if (p_params->opcode == ECORE_FILTER_REPLACE ||
3099 p_params->opcode == ECORE_FILTER_FLUSH) {
3100 for (i = 0; i < ECORE_ETH_VF_NUM_VLAN_FILTERS + 1; i++)
3101 p_vf->shadow_config.vlans[i].used = false;
3104 /* In forced mode, we're willing to remove entries - but we don't add
3107 if (p_vf->bulletin.p_virt->valid_bitmap & (1 << VLAN_ADDR_FORCED))
3108 return ECORE_SUCCESS;
3110 if (p_params->opcode == ECORE_FILTER_ADD ||
3111 p_params->opcode == ECORE_FILTER_REPLACE) {
3112 for (i = 0; i < ECORE_ETH_VF_NUM_VLAN_FILTERS + 1; i++) {
3113 if (p_vf->shadow_config.vlans[i].used)
3116 p_vf->shadow_config.vlans[i].used = true;
3117 p_vf->shadow_config.vlans[i].vid = p_params->vlan;
3121 if (i == ECORE_ETH_VF_NUM_VLAN_FILTERS + 1) {
3122 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3123 "VF [%d] - Tries to configure more than %d"
3125 p_vf->relative_vf_id,
3126 ECORE_ETH_VF_NUM_VLAN_FILTERS + 1);
3131 return ECORE_SUCCESS;
3134 static enum _ecore_status_t
3135 ecore_iov_vf_update_mac_shadow(struct ecore_hwfn *p_hwfn,
3136 struct ecore_vf_info *p_vf,
3137 struct ecore_filter_ucast *p_params)
3139 char empty_mac[ETH_ALEN];
3142 OSAL_MEM_ZERO(empty_mac, ETH_ALEN);
3144 /* If we're in forced-mode, we don't allow any change */
3145 /* TODO - this would change if we were ever to implement logic for
3146 * removing a forced MAC altogether [in which case, like for vlans,
3147 * we should be able to re-trace previous configuration.
3149 if (p_vf->bulletin.p_virt->valid_bitmap & (1 << MAC_ADDR_FORCED))
3150 return ECORE_SUCCESS;
3152 /* First remove entries and then add new ones */
3153 if (p_params->opcode == ECORE_FILTER_REMOVE) {
3154 for (i = 0; i < ECORE_ETH_VF_NUM_MAC_FILTERS; i++) {
3155 if (!OSAL_MEMCMP(p_vf->shadow_config.macs[i],
3156 p_params->mac, ETH_ALEN)) {
3157 OSAL_MEM_ZERO(p_vf->shadow_config.macs[i],
3163 if (i == ECORE_ETH_VF_NUM_MAC_FILTERS) {
3164 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3165 "MAC isn't configured\n");
3168 } else if (p_params->opcode == ECORE_FILTER_REPLACE ||
3169 p_params->opcode == ECORE_FILTER_FLUSH) {
3170 for (i = 0; i < ECORE_ETH_VF_NUM_MAC_FILTERS; i++)
3171 OSAL_MEM_ZERO(p_vf->shadow_config.macs[i], ETH_ALEN);
3174 /* List the new MAC address */
3175 if (p_params->opcode != ECORE_FILTER_ADD &&
3176 p_params->opcode != ECORE_FILTER_REPLACE)
3177 return ECORE_SUCCESS;
3179 for (i = 0; i < ECORE_ETH_VF_NUM_MAC_FILTERS; i++) {
3180 if (!OSAL_MEMCMP(p_vf->shadow_config.macs[i],
3181 empty_mac, ETH_ALEN)) {
3182 OSAL_MEMCPY(p_vf->shadow_config.macs[i],
3183 p_params->mac, ETH_ALEN);
3184 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3185 "Added MAC at %d entry in shadow\n", i);
3190 if (i == ECORE_ETH_VF_NUM_MAC_FILTERS) {
3191 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3192 "No available place for MAC\n");
3196 return ECORE_SUCCESS;
3199 static enum _ecore_status_t
3200 ecore_iov_vf_update_unicast_shadow(struct ecore_hwfn *p_hwfn,
3201 struct ecore_vf_info *p_vf,
3202 struct ecore_filter_ucast *p_params)
3204 enum _ecore_status_t rc = ECORE_SUCCESS;
3206 if (p_params->type == ECORE_FILTER_MAC) {
3207 rc = ecore_iov_vf_update_mac_shadow(p_hwfn, p_vf, p_params);
3208 if (rc != ECORE_SUCCESS)
3212 if (p_params->type == ECORE_FILTER_VLAN)
3213 rc = ecore_iov_vf_update_vlan_shadow(p_hwfn, p_vf, p_params);
3218 static void ecore_iov_vf_mbx_ucast_filter(struct ecore_hwfn *p_hwfn,
3219 struct ecore_ptt *p_ptt,
3220 struct ecore_vf_info *vf)
3222 struct ecore_bulletin_content *p_bulletin = vf->bulletin.p_virt;
3223 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
3224 struct vfpf_ucast_filter_tlv *req;
3225 u8 status = PFVF_STATUS_SUCCESS;
3226 struct ecore_filter_ucast params;
3227 enum _ecore_status_t rc;
3229 /* Prepare the unicast filter params */
3230 OSAL_MEMSET(¶ms, 0, sizeof(struct ecore_filter_ucast));
3231 req = &mbx->req_virt->ucast_filter;
3232 params.opcode = (enum ecore_filter_opcode)req->opcode;
3233 params.type = (enum ecore_filter_ucast_type)req->type;
3235 /* @@@TBD - We might need logic on HV side in determining this */
3236 params.is_rx_filter = 1;
3237 params.is_tx_filter = 1;
3238 params.vport_to_remove_from = vf->vport_id;
3239 params.vport_to_add_to = vf->vport_id;
3240 OSAL_MEMCPY(params.mac, req->mac, ETH_ALEN);
3241 params.vlan = req->vlan;
3243 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3244 "VF[%d]: opcode 0x%02x type 0x%02x [%s %s] [vport 0x%02x]"
3245 " MAC %02x:%02x:%02x:%02x:%02x:%02x, vlan 0x%04x\n",
3246 vf->abs_vf_id, params.opcode, params.type,
3247 params.is_rx_filter ? "RX" : "",
3248 params.is_tx_filter ? "TX" : "",
3249 params.vport_to_add_to,
3250 params.mac[0], params.mac[1], params.mac[2],
3251 params.mac[3], params.mac[4], params.mac[5], params.vlan);
3253 if (!vf->vport_instance) {
3254 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3255 "No VPORT instance available for VF[%d],"
3256 " failing ucast MAC configuration\n",
3258 status = PFVF_STATUS_FAILURE;
3262 /* Update shadow copy of the VF configuration */
3263 if (ecore_iov_vf_update_unicast_shadow(p_hwfn, vf, ¶ms) !=
3265 status = PFVF_STATUS_FAILURE;
3269 /* Determine if the unicast filtering is acceptible by PF */
3270 if ((p_bulletin->valid_bitmap & (1 << VLAN_ADDR_FORCED)) &&
3271 (params.type == ECORE_FILTER_VLAN ||
3272 params.type == ECORE_FILTER_MAC_VLAN)) {
3273 /* Once VLAN is forced or PVID is set, do not allow
3274 * to add/replace any further VLANs.
3276 if (params.opcode == ECORE_FILTER_ADD ||
3277 params.opcode == ECORE_FILTER_REPLACE)
3278 status = PFVF_STATUS_FORCED;
3282 if ((p_bulletin->valid_bitmap & (1 << MAC_ADDR_FORCED)) &&
3283 (params.type == ECORE_FILTER_MAC ||
3284 params.type == ECORE_FILTER_MAC_VLAN)) {
3285 if (OSAL_MEMCMP(p_bulletin->mac, params.mac, ETH_ALEN) ||
3286 (params.opcode != ECORE_FILTER_ADD &&
3287 params.opcode != ECORE_FILTER_REPLACE))
3288 status = PFVF_STATUS_FORCED;
3292 rc = OSAL_IOV_CHK_UCAST(p_hwfn, vf->relative_vf_id, ¶ms);
3293 if (rc == ECORE_EXISTS) {
3295 } else if (rc == ECORE_INVAL) {
3296 status = PFVF_STATUS_FAILURE;
3300 rc = ecore_sp_eth_filter_ucast(p_hwfn, vf->opaque_fid, ¶ms,
3301 ECORE_SPQ_MODE_CB, OSAL_NULL);
3303 status = PFVF_STATUS_FAILURE;
3306 ecore_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_UCAST_FILTER,
3307 sizeof(struct pfvf_def_resp_tlv), status);
3310 static void ecore_iov_vf_mbx_int_cleanup(struct ecore_hwfn *p_hwfn,
3311 struct ecore_ptt *p_ptt,
3312 struct ecore_vf_info *vf)
3317 for (i = 0; i < vf->num_sbs; i++)
3318 ecore_int_igu_init_pure_rt_single(p_hwfn, p_ptt,
3320 vf->opaque_fid, false);
3322 ecore_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_INT_CLEANUP,
3323 sizeof(struct pfvf_def_resp_tlv),
3324 PFVF_STATUS_SUCCESS);
3327 static void ecore_iov_vf_mbx_close(struct ecore_hwfn *p_hwfn,
3328 struct ecore_ptt *p_ptt,
3329 struct ecore_vf_info *vf)
3331 u16 length = sizeof(struct pfvf_def_resp_tlv);
3332 u8 status = PFVF_STATUS_SUCCESS;
3334 /* Disable Interrupts for VF */
3335 ecore_iov_vf_igu_set_int(p_hwfn, p_ptt, vf, 0);
3337 /* Reset Permission table */
3338 ecore_iov_config_perm_table(p_hwfn, p_ptt, vf, 0);
3340 ecore_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_CLOSE,
3344 static void ecore_iov_vf_mbx_release(struct ecore_hwfn *p_hwfn,
3345 struct ecore_ptt *p_ptt,
3346 struct ecore_vf_info *p_vf)
3348 u16 length = sizeof(struct pfvf_def_resp_tlv);
3349 u8 status = PFVF_STATUS_SUCCESS;
3350 enum _ecore_status_t rc = ECORE_SUCCESS;
3352 ecore_iov_vf_cleanup(p_hwfn, p_vf);
3354 if (p_vf->state != VF_STOPPED && p_vf->state != VF_FREE) {
3355 /* Stopping the VF */
3356 rc = ecore_sp_vf_stop(p_hwfn, p_vf->concrete_fid,
3359 if (rc != ECORE_SUCCESS) {
3360 DP_ERR(p_hwfn, "ecore_sp_vf_stop returned error %d\n",
3362 status = PFVF_STATUS_FAILURE;
3365 p_vf->state = VF_STOPPED;
3368 ecore_iov_prepare_resp(p_hwfn, p_ptt, p_vf, CHANNEL_TLV_RELEASE,
3372 static void ecore_iov_vf_pf_set_coalesce(struct ecore_hwfn *p_hwfn,
3373 struct ecore_ptt *p_ptt,
3374 struct ecore_vf_info *vf)
3376 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
3377 enum _ecore_status_t rc = ECORE_SUCCESS;
3378 struct vfpf_update_coalesce *req;
3379 u8 status = PFVF_STATUS_FAILURE;
3380 struct ecore_queue_cid *p_cid;
3381 u16 rx_coal, tx_coal;
3385 req = &mbx->req_virt->update_coalesce;
3387 rx_coal = req->rx_coal;
3388 tx_coal = req->tx_coal;
3391 if (!ecore_iov_validate_rxq(p_hwfn, vf, qid,
3392 ECORE_IOV_VALIDATE_Q_ENABLE) &&
3394 DP_ERR(p_hwfn, "VF[%d]: Invalid Rx queue_id = %d\n",
3395 vf->abs_vf_id, qid);
3399 if (!ecore_iov_validate_txq(p_hwfn, vf, qid,
3400 ECORE_IOV_VALIDATE_Q_ENABLE) &&
3402 DP_ERR(p_hwfn, "VF[%d]: Invalid Tx queue_id = %d\n",
3403 vf->abs_vf_id, qid);
3407 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3408 "VF[%d]: Setting coalesce for VF rx_coal = %d, tx_coal = %d at queue = %d\n",
3409 vf->abs_vf_id, rx_coal, tx_coal, qid);
3412 p_cid = ecore_iov_get_vf_rx_queue_cid(p_hwfn, vf,
3413 &vf->vf_queues[qid]);
3415 rc = ecore_set_rxq_coalesce(p_hwfn, p_ptt, rx_coal, p_cid);
3416 if (rc != ECORE_SUCCESS) {
3417 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3418 "VF[%d]: Unable to set rx queue = %d coalesce\n",
3419 vf->abs_vf_id, vf->vf_queues[qid].fw_rx_qid);
3424 /* TODO - in future, it might be possible to pass this in a per-cid
3425 * granularity. For now, do this for all Tx queues.
3428 struct ecore_vf_queue *p_queue = &vf->vf_queues[qid];
3430 for (i = 0; i < MAX_QUEUES_PER_QZONE; i++) {
3431 if (p_queue->cids[i].p_cid == OSAL_NULL)
3434 if (!p_queue->cids[i].b_is_tx)
3437 rc = ecore_set_txq_coalesce(p_hwfn, p_ptt, tx_coal,
3438 p_queue->cids[i].p_cid);
3439 if (rc != ECORE_SUCCESS) {
3440 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3441 "VF[%d]: Unable to set tx queue coalesce\n",
3448 status = PFVF_STATUS_SUCCESS;
3450 ecore_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_COALESCE_UPDATE,
3451 sizeof(struct pfvf_def_resp_tlv), status);
3454 static enum _ecore_status_t
3455 ecore_iov_vf_flr_poll_dorq(struct ecore_hwfn *p_hwfn,
3456 struct ecore_vf_info *p_vf, struct ecore_ptt *p_ptt)
3461 ecore_fid_pretend(p_hwfn, p_ptt, (u16)p_vf->concrete_fid);
3463 for (cnt = 0; cnt < 50; cnt++) {
3464 val = ecore_rd(p_hwfn, p_ptt, DORQ_REG_VF_USAGE_CNT);
3469 ecore_fid_pretend(p_hwfn, p_ptt, (u16)p_hwfn->hw_info.concrete_fid);
3473 "VF[%d] - dorq failed to cleanup [usage 0x%08x]\n",
3474 p_vf->abs_vf_id, val);
3475 return ECORE_TIMEOUT;
3478 return ECORE_SUCCESS;
3481 static enum _ecore_status_t
3482 ecore_iov_vf_flr_poll_pbf(struct ecore_hwfn *p_hwfn,
3483 struct ecore_vf_info *p_vf, struct ecore_ptt *p_ptt)
3485 u32 cons[MAX_NUM_VOQS], distance[MAX_NUM_VOQS];
3488 /* Read initial consumers & producers */
3489 for (i = 0; i < MAX_NUM_VOQS; i++) {
3492 cons[i] = ecore_rd(p_hwfn, p_ptt,
3493 PBF_REG_NUM_BLOCKS_ALLOCATED_CONS_VOQ0 +
3495 prod = ecore_rd(p_hwfn, p_ptt,
3496 PBF_REG_NUM_BLOCKS_ALLOCATED_PROD_VOQ0 +
3498 distance[i] = prod - cons[i];
3501 /* Wait for consumers to pass the producers */
3503 for (cnt = 0; cnt < 50; cnt++) {
3504 for (; i < MAX_NUM_VOQS; i++) {
3507 tmp = ecore_rd(p_hwfn, p_ptt,
3508 PBF_REG_NUM_BLOCKS_ALLOCATED_CONS_VOQ0 +
3510 if (distance[i] > tmp - cons[i])
3514 if (i == MAX_NUM_VOQS)
3521 DP_ERR(p_hwfn, "VF[%d] - pbf polling failed on VOQ %d\n",
3522 p_vf->abs_vf_id, i);
3523 return ECORE_TIMEOUT;
3526 return ECORE_SUCCESS;
3529 static enum _ecore_status_t ecore_iov_vf_flr_poll(struct ecore_hwfn *p_hwfn,
3530 struct ecore_vf_info *p_vf,
3531 struct ecore_ptt *p_ptt)
3533 enum _ecore_status_t rc;
3535 /* TODO - add SRC and TM polling once we add storage IOV */
3537 rc = ecore_iov_vf_flr_poll_dorq(p_hwfn, p_vf, p_ptt);
3541 rc = ecore_iov_vf_flr_poll_pbf(p_hwfn, p_vf, p_ptt);
3545 return ECORE_SUCCESS;
3548 static enum _ecore_status_t
3549 ecore_iov_execute_vf_flr_cleanup(struct ecore_hwfn *p_hwfn,
3550 struct ecore_ptt *p_ptt,
3551 u16 rel_vf_id, u32 *ack_vfs)
3553 struct ecore_vf_info *p_vf;
3554 enum _ecore_status_t rc = ECORE_SUCCESS;
3556 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, false);
3558 return ECORE_SUCCESS;
3560 if (p_hwfn->pf_iov_info->pending_flr[rel_vf_id / 64] &
3561 (1ULL << (rel_vf_id % 64))) {
3562 u16 vfid = p_vf->abs_vf_id;
3564 /* TODO - should we lock channel? */
3566 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3567 "VF[%d] - Handling FLR\n", vfid);
3569 ecore_iov_vf_cleanup(p_hwfn, p_vf);
3571 /* If VF isn't active, no need for anything but SW */
3575 /* TODO - what to do in case of failure? */
3576 rc = ecore_iov_vf_flr_poll(p_hwfn, p_vf, p_ptt);
3577 if (rc != ECORE_SUCCESS)
3580 rc = ecore_final_cleanup(p_hwfn, p_ptt, vfid, true);
3582 /* TODO - what's now? What a mess.... */
3583 DP_ERR(p_hwfn, "Failed handle FLR of VF[%d]\n", vfid);
3587 /* Workaround to make VF-PF channel ready, as FW
3588 * doesn't do that as a part of FLR.
3591 GTT_BAR0_MAP_REG_USDM_RAM +
3592 USTORM_VF_PF_CHANNEL_READY_OFFSET(vfid), 1);
3594 /* VF_STOPPED has to be set only after final cleanup
3595 * but prior to re-enabling the VF.
3597 p_vf->state = VF_STOPPED;
3599 rc = ecore_iov_enable_vf_access(p_hwfn, p_ptt, p_vf);
3601 /* TODO - again, a mess... */
3602 DP_ERR(p_hwfn, "Failed to re-enable VF[%d] acces\n",
3607 /* Mark VF for ack and clean pending state */
3608 if (p_vf->state == VF_RESET)
3609 p_vf->state = VF_STOPPED;
3610 ack_vfs[vfid / 32] |= (1 << (vfid % 32));
3611 p_hwfn->pf_iov_info->pending_flr[rel_vf_id / 64] &=
3612 ~(1ULL << (rel_vf_id % 64));
3613 p_hwfn->pf_iov_info->pending_events[rel_vf_id / 64] &=
3614 ~(1ULL << (rel_vf_id % 64));
3620 enum _ecore_status_t ecore_iov_vf_flr_cleanup(struct ecore_hwfn *p_hwfn,
3621 struct ecore_ptt *p_ptt)
3623 u32 ack_vfs[VF_MAX_STATIC / 32];
3624 enum _ecore_status_t rc = ECORE_SUCCESS;
3627 OSAL_MEMSET(ack_vfs, 0, sizeof(u32) * (VF_MAX_STATIC / 32));
3629 /* Since BRB <-> PRS interface can't be tested as part of the flr
3630 * polling due to HW limitations, simply sleep a bit. And since
3631 * there's no need to wait per-vf, do it before looping.
3635 for (i = 0; i < p_hwfn->p_dev->p_iov_info->total_vfs; i++)
3636 ecore_iov_execute_vf_flr_cleanup(p_hwfn, p_ptt, i, ack_vfs);
3638 rc = ecore_mcp_ack_vf_flr(p_hwfn, p_ptt, ack_vfs);
3642 enum _ecore_status_t
3643 ecore_iov_single_vf_flr_cleanup(struct ecore_hwfn *p_hwfn,
3644 struct ecore_ptt *p_ptt, u16 rel_vf_id)
3646 u32 ack_vfs[VF_MAX_STATIC / 32];
3647 enum _ecore_status_t rc = ECORE_SUCCESS;
3649 OSAL_MEMSET(ack_vfs, 0, sizeof(u32) * (VF_MAX_STATIC / 32));
3651 /* Wait instead of polling the BRB <-> PRS interface */
3654 ecore_iov_execute_vf_flr_cleanup(p_hwfn, p_ptt, rel_vf_id, ack_vfs);
3656 rc = ecore_mcp_ack_vf_flr(p_hwfn, p_ptt, ack_vfs);
3660 bool ecore_iov_mark_vf_flr(struct ecore_hwfn *p_hwfn, u32 *p_disabled_vfs)
3665 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV, "Marking FLR-ed VFs\n");
3666 for (i = 0; i < (VF_MAX_STATIC / 32); i++)
3667 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3668 "[%08x,...,%08x]: %08x\n",
3669 i * 32, (i + 1) * 32 - 1, p_disabled_vfs[i]);
3671 if (!p_hwfn->p_dev->p_iov_info) {
3672 DP_NOTICE(p_hwfn, true, "VF flr but no IOV\n");
3677 for (i = 0; i < p_hwfn->p_dev->p_iov_info->total_vfs; i++) {
3678 struct ecore_vf_info *p_vf;
3681 p_vf = ecore_iov_get_vf_info(p_hwfn, i, false);
3685 vfid = p_vf->abs_vf_id;
3686 if ((1 << (vfid % 32)) & p_disabled_vfs[vfid / 32]) {
3687 u64 *p_flr = p_hwfn->pf_iov_info->pending_flr;
3688 u16 rel_vf_id = p_vf->relative_vf_id;
3690 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3691 "VF[%d] [rel %d] got FLR-ed\n",
3694 p_vf->state = VF_RESET;
3696 /* No need to lock here, since pending_flr should
3697 * only change here and before ACKing MFw. Since
3698 * MFW will not trigger an additional attention for
3699 * VF flr until ACKs, we're safe.
3701 p_flr[rel_vf_id / 64] |= 1ULL << (rel_vf_id % 64);
3709 void ecore_iov_get_link(struct ecore_hwfn *p_hwfn,
3711 struct ecore_mcp_link_params *p_params,
3712 struct ecore_mcp_link_state *p_link,
3713 struct ecore_mcp_link_capabilities *p_caps)
3715 struct ecore_vf_info *p_vf = ecore_iov_get_vf_info(p_hwfn, vfid, false);
3716 struct ecore_bulletin_content *p_bulletin;
3721 p_bulletin = p_vf->bulletin.p_virt;
3724 __ecore_vf_get_link_params(p_hwfn, p_params, p_bulletin);
3726 __ecore_vf_get_link_state(p_hwfn, p_link, p_bulletin);
3728 __ecore_vf_get_link_caps(p_hwfn, p_caps, p_bulletin);
3731 void ecore_iov_process_mbx_req(struct ecore_hwfn *p_hwfn,
3732 struct ecore_ptt *p_ptt, int vfid)
3734 struct ecore_iov_vf_mbx *mbx;
3735 struct ecore_vf_info *p_vf;
3737 p_vf = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
3741 mbx = &p_vf->vf_mbx;
3743 /* ecore_iov_process_mbx_request */
3746 "VF[%02x]: Processing mailbox message\n", p_vf->abs_vf_id);
3748 mbx->first_tlv = mbx->req_virt->first_tlv;
3750 OSAL_IOV_VF_MSG_TYPE(p_hwfn,
3751 p_vf->relative_vf_id,
3752 mbx->first_tlv.tl.type);
3754 /* Lock the per vf op mutex and note the locker's identity.
3755 * The unlock will take place in mbx response.
3757 ecore_iov_lock_vf_pf_channel(p_hwfn,
3758 p_vf, mbx->first_tlv.tl.type);
3760 /* check if tlv type is known */
3761 if (ecore_iov_tlv_supported(mbx->first_tlv.tl.type) &&
3762 !p_vf->b_malicious) {
3763 /* switch on the opcode */
3764 switch (mbx->first_tlv.tl.type) {
3765 case CHANNEL_TLV_ACQUIRE:
3766 ecore_iov_vf_mbx_acquire(p_hwfn, p_ptt, p_vf);
3768 case CHANNEL_TLV_VPORT_START:
3769 ecore_iov_vf_mbx_start_vport(p_hwfn, p_ptt, p_vf);
3771 case CHANNEL_TLV_VPORT_TEARDOWN:
3772 ecore_iov_vf_mbx_stop_vport(p_hwfn, p_ptt, p_vf);
3774 case CHANNEL_TLV_START_RXQ:
3775 ecore_iov_vf_mbx_start_rxq(p_hwfn, p_ptt, p_vf);
3777 case CHANNEL_TLV_START_TXQ:
3778 ecore_iov_vf_mbx_start_txq(p_hwfn, p_ptt, p_vf);
3780 case CHANNEL_TLV_STOP_RXQS:
3781 ecore_iov_vf_mbx_stop_rxqs(p_hwfn, p_ptt, p_vf);
3783 case CHANNEL_TLV_STOP_TXQS:
3784 ecore_iov_vf_mbx_stop_txqs(p_hwfn, p_ptt, p_vf);
3786 case CHANNEL_TLV_UPDATE_RXQ:
3787 ecore_iov_vf_mbx_update_rxqs(p_hwfn, p_ptt, p_vf);
3789 case CHANNEL_TLV_VPORT_UPDATE:
3790 ecore_iov_vf_mbx_vport_update(p_hwfn, p_ptt, p_vf);
3792 case CHANNEL_TLV_UCAST_FILTER:
3793 ecore_iov_vf_mbx_ucast_filter(p_hwfn, p_ptt, p_vf);
3795 case CHANNEL_TLV_CLOSE:
3796 ecore_iov_vf_mbx_close(p_hwfn, p_ptt, p_vf);
3798 case CHANNEL_TLV_INT_CLEANUP:
3799 ecore_iov_vf_mbx_int_cleanup(p_hwfn, p_ptt, p_vf);
3801 case CHANNEL_TLV_RELEASE:
3802 ecore_iov_vf_mbx_release(p_hwfn, p_ptt, p_vf);
3804 case CHANNEL_TLV_UPDATE_TUNN_PARAM:
3805 ecore_iov_vf_mbx_update_tunn_param(p_hwfn, p_ptt, p_vf);
3807 case CHANNEL_TLV_COALESCE_UPDATE:
3808 ecore_iov_vf_pf_set_coalesce(p_hwfn, p_ptt, p_vf);
3811 } else if (ecore_iov_tlv_supported(mbx->first_tlv.tl.type)) {
3812 /* If we've received a message from a VF we consider malicious
3813 * we ignore the messasge unless it's one for RELEASE, in which
3814 * case we'll let it have the benefit of doubt, allowing the
3815 * next loaded driver to start again.
3817 if (mbx->first_tlv.tl.type == CHANNEL_TLV_RELEASE) {
3818 /* TODO - initiate FLR, remove malicious indication */
3819 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3820 "VF [%02x] - considered malicious, but wanted to RELEASE. TODO\n",
3823 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3824 "VF [%02x] - considered malicious; Ignoring TLV [%04x]\n",
3825 p_vf->abs_vf_id, mbx->first_tlv.tl.type);
3828 ecore_iov_prepare_resp(p_hwfn, p_ptt, p_vf,
3829 mbx->first_tlv.tl.type,
3830 sizeof(struct pfvf_def_resp_tlv),
3831 PFVF_STATUS_MALICIOUS);
3833 /* unknown TLV - this may belong to a VF driver from the future
3834 * - a version written after this PF driver was written, which
3835 * supports features unknown as of yet. Too bad since we don't
3836 * support them. Or this may be because someone wrote a crappy
3837 * VF driver and is sending garbage over the channel.
3839 DP_NOTICE(p_hwfn, false,
3840 "VF[%02x]: unknown TLV. type %04x length %04x"
3841 " padding %08x reply address %lu\n",
3843 mbx->first_tlv.tl.type,
3844 mbx->first_tlv.tl.length,
3845 mbx->first_tlv.padding,
3846 (unsigned long)mbx->first_tlv.reply_address);
3848 /* Try replying in case reply address matches the acquisition's
3851 if (p_vf->acquire.first_tlv.reply_address &&
3852 (mbx->first_tlv.reply_address ==
3853 p_vf->acquire.first_tlv.reply_address))
3854 ecore_iov_prepare_resp(p_hwfn, p_ptt, p_vf,
3855 mbx->first_tlv.tl.type,
3856 sizeof(struct pfvf_def_resp_tlv),
3857 PFVF_STATUS_NOT_SUPPORTED);
3859 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3860 "VF[%02x]: Can't respond to TLV -"
3861 " no valid reply address\n",
3865 ecore_iov_unlock_vf_pf_channel(p_hwfn, p_vf,
3866 mbx->first_tlv.tl.type);
3868 #ifdef CONFIG_ECORE_SW_CHANNEL
3869 mbx->sw_mbx.mbx_state = VF_PF_RESPONSE_READY;
3870 mbx->sw_mbx.response_offset = 0;
3874 void ecore_iov_pf_add_pending_events(struct ecore_hwfn *p_hwfn, u8 vfid)
3876 u64 add_bit = 1ULL << (vfid % 64);
3878 /* TODO - add locking mechanisms [no atomics in ecore, so we can't
3879 * add the lock inside the ecore_pf_iov struct].
3881 p_hwfn->pf_iov_info->pending_events[vfid / 64] |= add_bit;
3884 void ecore_iov_pf_get_and_clear_pending_events(struct ecore_hwfn *p_hwfn,
3887 u64 *p_pending_events = p_hwfn->pf_iov_info->pending_events;
3889 /* TODO - Take a lock */
3890 OSAL_MEMCPY(events, p_pending_events,
3891 sizeof(u64) * ECORE_VF_ARRAY_LENGTH);
3892 OSAL_MEMSET(p_pending_events, 0,
3893 sizeof(u64) * ECORE_VF_ARRAY_LENGTH);
3896 static struct ecore_vf_info *
3897 ecore_sriov_get_vf_from_absid(struct ecore_hwfn *p_hwfn, u16 abs_vfid)
3899 u8 min = (u8)p_hwfn->p_dev->p_iov_info->first_vf_in_pf;
3901 if (!_ecore_iov_pf_sanity_check(p_hwfn, (int)abs_vfid - min, false)) {
3902 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3903 "Got indication for VF [abs 0x%08x] that cannot be"
3909 return &p_hwfn->pf_iov_info->vfs_array[(u8)abs_vfid - min];
3912 static enum _ecore_status_t ecore_sriov_vfpf_msg(struct ecore_hwfn *p_hwfn,
3914 struct regpair *vf_msg)
3916 struct ecore_vf_info *p_vf = ecore_sriov_get_vf_from_absid(p_hwfn,
3920 return ECORE_SUCCESS;
3922 /* List the physical address of the request so that handler
3923 * could later on copy the message from it.
3925 p_vf->vf_mbx.pending_req = (((u64)vf_msg->hi) << 32) | vf_msg->lo;
3927 return OSAL_PF_VF_MSG(p_hwfn, p_vf->relative_vf_id);
3930 static void ecore_sriov_vfpf_malicious(struct ecore_hwfn *p_hwfn,
3931 struct malicious_vf_eqe_data *p_data)
3933 struct ecore_vf_info *p_vf;
3935 p_vf = ecore_sriov_get_vf_from_absid(p_hwfn, p_data->vfId);
3941 "VF [%d] - Malicious behavior [%02x]\n",
3942 p_vf->abs_vf_id, p_data->errId);
3944 p_vf->b_malicious = true;
3946 OSAL_PF_VF_MALICIOUS(p_hwfn, p_vf->relative_vf_id);
3949 enum _ecore_status_t ecore_sriov_eqe_event(struct ecore_hwfn *p_hwfn,
3952 union event_ring_data *data)
3955 case COMMON_EVENT_VF_PF_CHANNEL:
3956 return ecore_sriov_vfpf_msg(p_hwfn, OSAL_LE16_TO_CPU(echo),
3957 &data->vf_pf_channel.msg_addr);
3958 case COMMON_EVENT_VF_FLR:
3959 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3960 "VF-FLR is still not supported\n");
3961 return ECORE_SUCCESS;
3962 case COMMON_EVENT_MALICIOUS_VF:
3963 ecore_sriov_vfpf_malicious(p_hwfn, &data->malicious_vf);
3964 return ECORE_SUCCESS;
3966 DP_INFO(p_hwfn->p_dev, "Unknown sriov eqe event 0x%02x\n",
3972 bool ecore_iov_is_vf_pending_flr(struct ecore_hwfn *p_hwfn, u16 rel_vf_id)
3974 return !!(p_hwfn->pf_iov_info->pending_flr[rel_vf_id / 64] &
3975 (1ULL << (rel_vf_id % 64)));
3978 u16 ecore_iov_get_next_active_vf(struct ecore_hwfn *p_hwfn, u16 rel_vf_id)
3980 struct ecore_hw_sriov_info *p_iov = p_hwfn->p_dev->p_iov_info;
3986 for (i = rel_vf_id; i < p_iov->total_vfs; i++)
3987 if (ecore_iov_is_valid_vfid(p_hwfn, rel_vf_id, true, false))
3991 return E4_MAX_NUM_VFS;
3994 enum _ecore_status_t ecore_iov_copy_vf_msg(struct ecore_hwfn *p_hwfn,
3995 struct ecore_ptt *ptt, int vfid)
3997 struct ecore_dmae_params params;
3998 struct ecore_vf_info *vf_info;
4000 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4004 OSAL_MEMSET(¶ms, 0, sizeof(struct ecore_dmae_params));
4005 params.flags = ECORE_DMAE_FLAG_VF_SRC | ECORE_DMAE_FLAG_COMPLETION_DST;
4006 params.src_vfid = vf_info->abs_vf_id;
4008 if (ecore_dmae_host2host(p_hwfn, ptt,
4009 vf_info->vf_mbx.pending_req,
4010 vf_info->vf_mbx.req_phys,
4011 sizeof(union vfpf_tlvs) / 4, ¶ms)) {
4012 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
4013 "Failed to copy message from VF 0x%02x\n", vfid);
4018 return ECORE_SUCCESS;
4021 void ecore_iov_bulletin_set_forced_mac(struct ecore_hwfn *p_hwfn,
4024 struct ecore_vf_info *vf_info;
4027 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4029 DP_NOTICE(p_hwfn->p_dev, true,
4030 "Can not set forced MAC, invalid vfid [%d]\n", vfid);
4033 if (vf_info->b_malicious) {
4034 DP_NOTICE(p_hwfn->p_dev, false,
4035 "Can't set forced MAC to malicious VF [%d]\n",
4040 feature = 1 << MAC_ADDR_FORCED;
4041 OSAL_MEMCPY(vf_info->bulletin.p_virt->mac, mac, ETH_ALEN);
4043 vf_info->bulletin.p_virt->valid_bitmap |= feature;
4044 /* Forced MAC will disable MAC_ADDR */
4045 vf_info->bulletin.p_virt->valid_bitmap &=
4046 ~(1 << VFPF_BULLETIN_MAC_ADDR);
4048 ecore_iov_configure_vport_forced(p_hwfn, vf_info, feature);
4051 enum _ecore_status_t ecore_iov_bulletin_set_mac(struct ecore_hwfn *p_hwfn,
4054 struct ecore_vf_info *vf_info;
4057 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4059 DP_NOTICE(p_hwfn->p_dev, true,
4060 "Can not set MAC, invalid vfid [%d]\n", vfid);
4063 if (vf_info->b_malicious) {
4064 DP_NOTICE(p_hwfn->p_dev, false,
4065 "Can't set MAC to malicious VF [%d]\n",
4070 if (vf_info->bulletin.p_virt->valid_bitmap & (1 << MAC_ADDR_FORCED)) {
4071 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
4072 "Can not set MAC, Forced MAC is configured\n");
4076 feature = 1 << VFPF_BULLETIN_MAC_ADDR;
4077 OSAL_MEMCPY(vf_info->bulletin.p_virt->mac, mac, ETH_ALEN);
4079 vf_info->bulletin.p_virt->valid_bitmap |= feature;
4081 return ECORE_SUCCESS;
4084 enum _ecore_status_t
4085 ecore_iov_bulletin_set_forced_untagged_default(struct ecore_hwfn *p_hwfn,
4086 bool b_untagged_only, int vfid)
4088 struct ecore_vf_info *vf_info;
4091 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4093 DP_NOTICE(p_hwfn->p_dev, true,
4094 "Can not set untagged default, invalid vfid [%d]\n",
4098 if (vf_info->b_malicious) {
4099 DP_NOTICE(p_hwfn->p_dev, false,
4100 "Can't set untagged default to malicious VF [%d]\n",
4105 /* Since this is configurable only during vport-start, don't take it
4106 * if we're past that point.
4108 if (vf_info->state == VF_ENABLED) {
4109 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
4110 "Can't support untagged change for vfid[%d] -"
4111 " VF is already active\n",
4116 /* Set configuration; This will later be taken into account during the
4117 * VF initialization.
4119 feature = (1 << VFPF_BULLETIN_UNTAGGED_DEFAULT) |
4120 (1 << VFPF_BULLETIN_UNTAGGED_DEFAULT_FORCED);
4121 vf_info->bulletin.p_virt->valid_bitmap |= feature;
4123 vf_info->bulletin.p_virt->default_only_untagged = b_untagged_only ? 1
4126 return ECORE_SUCCESS;
4129 void ecore_iov_get_vfs_opaque_fid(struct ecore_hwfn *p_hwfn, int vfid,
4132 struct ecore_vf_info *vf_info;
4134 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4138 *opaque_fid = vf_info->opaque_fid;
4141 void ecore_iov_bulletin_set_forced_vlan(struct ecore_hwfn *p_hwfn,
4144 struct ecore_vf_info *vf_info;
4147 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4149 DP_NOTICE(p_hwfn->p_dev, true,
4150 "Can not set forced MAC, invalid vfid [%d]\n",
4154 if (vf_info->b_malicious) {
4155 DP_NOTICE(p_hwfn->p_dev, false,
4156 "Can't set forced vlan to malicious VF [%d]\n",
4161 feature = 1 << VLAN_ADDR_FORCED;
4162 vf_info->bulletin.p_virt->pvid = pvid;
4164 vf_info->bulletin.p_virt->valid_bitmap |= feature;
4166 vf_info->bulletin.p_virt->valid_bitmap &= ~feature;
4168 ecore_iov_configure_vport_forced(p_hwfn, vf_info, feature);
4171 void ecore_iov_bulletin_set_udp_ports(struct ecore_hwfn *p_hwfn,
4172 int vfid, u16 vxlan_port, u16 geneve_port)
4174 struct ecore_vf_info *vf_info;
4176 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4178 DP_NOTICE(p_hwfn->p_dev, true,
4179 "Can not set udp ports, invalid vfid [%d]\n", vfid);
4183 if (vf_info->b_malicious) {
4184 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
4185 "Can not set udp ports to malicious VF [%d]\n",
4190 vf_info->bulletin.p_virt->vxlan_udp_port = vxlan_port;
4191 vf_info->bulletin.p_virt->geneve_udp_port = geneve_port;
4194 bool ecore_iov_vf_has_vport_instance(struct ecore_hwfn *p_hwfn, int vfid)
4196 struct ecore_vf_info *p_vf_info;
4198 p_vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4202 return !!p_vf_info->vport_instance;
4205 bool ecore_iov_is_vf_stopped(struct ecore_hwfn *p_hwfn, int vfid)
4207 struct ecore_vf_info *p_vf_info;
4209 p_vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4213 return p_vf_info->state == VF_STOPPED;
4216 bool ecore_iov_spoofchk_get(struct ecore_hwfn *p_hwfn, int vfid)
4218 struct ecore_vf_info *vf_info;
4220 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4224 return vf_info->spoof_chk;
4227 enum _ecore_status_t ecore_iov_spoofchk_set(struct ecore_hwfn *p_hwfn,
4230 struct ecore_vf_info *vf;
4231 enum _ecore_status_t rc = ECORE_INVAL;
4233 if (!ecore_iov_pf_sanity_check(p_hwfn, vfid)) {
4234 DP_NOTICE(p_hwfn, true,
4235 "SR-IOV sanity check failed, can't set spoofchk\n");
4239 vf = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4243 if (!ecore_iov_vf_has_vport_instance(p_hwfn, vfid)) {
4244 /* After VF VPORT start PF will configure spoof check */
4245 vf->req_spoofchk_val = val;
4250 rc = __ecore_iov_spoofchk_set(p_hwfn, vf, val);
4256 u8 ecore_iov_vf_chains_per_pf(struct ecore_hwfn *p_hwfn)
4258 u8 max_chains_per_vf = p_hwfn->hw_info.max_chains_per_vf;
4260 max_chains_per_vf = (max_chains_per_vf) ? max_chains_per_vf
4261 : ECORE_MAX_VF_CHAINS_PER_PF;
4263 return max_chains_per_vf;
4266 void ecore_iov_get_vf_req_virt_mbx_params(struct ecore_hwfn *p_hwfn,
4268 void **pp_req_virt_addr,
4269 u16 *p_req_virt_size)
4271 struct ecore_vf_info *vf_info =
4272 ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4277 if (pp_req_virt_addr)
4278 *pp_req_virt_addr = vf_info->vf_mbx.req_virt;
4280 if (p_req_virt_size)
4281 *p_req_virt_size = sizeof(*vf_info->vf_mbx.req_virt);
4284 void ecore_iov_get_vf_reply_virt_mbx_params(struct ecore_hwfn *p_hwfn,
4286 void **pp_reply_virt_addr,
4287 u16 *p_reply_virt_size)
4289 struct ecore_vf_info *vf_info =
4290 ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4295 if (pp_reply_virt_addr)
4296 *pp_reply_virt_addr = vf_info->vf_mbx.reply_virt;
4298 if (p_reply_virt_size)
4299 *p_reply_virt_size = sizeof(*vf_info->vf_mbx.reply_virt);
4302 #ifdef CONFIG_ECORE_SW_CHANNEL
4303 struct ecore_iov_sw_mbx *ecore_iov_get_vf_sw_mbx(struct ecore_hwfn *p_hwfn,
4306 struct ecore_vf_info *vf_info =
4307 ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4312 return &vf_info->vf_mbx.sw_mbx;
4316 bool ecore_iov_is_valid_vfpf_msg_length(u32 length)
4318 return (length >= sizeof(struct vfpf_first_tlv) &&
4319 (length <= sizeof(union vfpf_tlvs)));
4322 u32 ecore_iov_pfvf_msg_length(void)
4324 return sizeof(union pfvf_tlvs);
4327 u8 *ecore_iov_bulletin_get_forced_mac(struct ecore_hwfn *p_hwfn, u16 rel_vf_id)
4329 struct ecore_vf_info *p_vf;
4331 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4332 if (!p_vf || !p_vf->bulletin.p_virt)
4335 if (!(p_vf->bulletin.p_virt->valid_bitmap & (1 << MAC_ADDR_FORCED)))
4338 return p_vf->bulletin.p_virt->mac;
4341 u16 ecore_iov_bulletin_get_forced_vlan(struct ecore_hwfn *p_hwfn,
4344 struct ecore_vf_info *p_vf;
4346 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4347 if (!p_vf || !p_vf->bulletin.p_virt)
4350 if (!(p_vf->bulletin.p_virt->valid_bitmap & (1 << VLAN_ADDR_FORCED)))
4353 return p_vf->bulletin.p_virt->pvid;
4356 enum _ecore_status_t ecore_iov_configure_tx_rate(struct ecore_hwfn *p_hwfn,
4357 struct ecore_ptt *p_ptt,
4360 struct ecore_vf_info *vf;
4362 enum _ecore_status_t rc;
4364 vf = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4369 rc = ecore_fw_vport(p_hwfn, vf->vport_id, &abs_vp_id);
4370 if (rc != ECORE_SUCCESS)
4373 return ecore_init_vport_rl(p_hwfn, p_ptt, abs_vp_id, (u32)val);
4376 enum _ecore_status_t ecore_iov_get_vf_stats(struct ecore_hwfn *p_hwfn,
4377 struct ecore_ptt *p_ptt,
4379 struct ecore_eth_stats *p_stats)
4381 struct ecore_vf_info *vf;
4383 vf = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4387 if (vf->state != VF_ENABLED)
4390 __ecore_get_vport_stats(p_hwfn, p_ptt, p_stats,
4391 vf->abs_vf_id + 0x10, false);
4393 return ECORE_SUCCESS;
4396 u8 ecore_iov_get_vf_num_rxqs(struct ecore_hwfn *p_hwfn, u16 rel_vf_id)
4398 struct ecore_vf_info *p_vf;
4400 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4404 return p_vf->num_rxqs;
4407 u8 ecore_iov_get_vf_num_active_rxqs(struct ecore_hwfn *p_hwfn, u16 rel_vf_id)
4409 struct ecore_vf_info *p_vf;
4411 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4415 return p_vf->num_active_rxqs;
4418 void *ecore_iov_get_vf_ctx(struct ecore_hwfn *p_hwfn, u16 rel_vf_id)
4420 struct ecore_vf_info *p_vf;
4422 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4429 u8 ecore_iov_get_vf_num_sbs(struct ecore_hwfn *p_hwfn, u16 rel_vf_id)
4431 struct ecore_vf_info *p_vf;
4433 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4437 return p_vf->num_sbs;
4440 bool ecore_iov_is_vf_wait_for_acquire(struct ecore_hwfn *p_hwfn, u16 rel_vf_id)
4442 struct ecore_vf_info *p_vf;
4444 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4448 return (p_vf->state == VF_FREE);
4451 bool ecore_iov_is_vf_acquired_not_initialized(struct ecore_hwfn *p_hwfn,
4454 struct ecore_vf_info *p_vf;
4456 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4460 return (p_vf->state == VF_ACQUIRED);
4463 bool ecore_iov_is_vf_initialized(struct ecore_hwfn *p_hwfn, u16 rel_vf_id)
4465 struct ecore_vf_info *p_vf;
4467 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4471 return (p_vf->state == VF_ENABLED);
4474 bool ecore_iov_is_vf_started(struct ecore_hwfn *p_hwfn,
4477 struct ecore_vf_info *p_vf;
4479 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4483 return (p_vf->state != VF_FREE && p_vf->state != VF_STOPPED);
4486 enum _ecore_status_t
4487 ecore_iov_get_vf_min_rate(struct ecore_hwfn *p_hwfn, int vfid)
4489 struct ecore_wfq_data *vf_vp_wfq;
4490 struct ecore_vf_info *vf_info;
4492 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4496 vf_vp_wfq = &p_hwfn->qm_info.wfq_data[vf_info->vport_id];
4498 if (vf_vp_wfq->configured)
4499 return vf_vp_wfq->min_speed;