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",
59 static enum _ecore_status_t ecore_sp_vf_start(struct ecore_hwfn *p_hwfn,
60 struct ecore_vf_info *p_vf)
62 struct vf_start_ramrod_data *p_ramrod = OSAL_NULL;
63 struct ecore_spq_entry *p_ent = OSAL_NULL;
64 struct ecore_sp_init_data init_data;
65 enum _ecore_status_t rc = ECORE_NOTIMPL;
69 OSAL_MEMSET(&init_data, 0, sizeof(init_data));
70 init_data.cid = ecore_spq_get_cid(p_hwfn);
71 init_data.opaque_fid = p_vf->opaque_fid;
72 init_data.comp_mode = ECORE_SPQ_MODE_EBLOCK;
74 rc = ecore_sp_init_request(p_hwfn, &p_ent,
75 COMMON_RAMROD_VF_START,
76 PROTOCOLID_COMMON, &init_data);
77 if (rc != ECORE_SUCCESS)
80 p_ramrod = &p_ent->ramrod.vf_start;
82 p_ramrod->vf_id = GET_FIELD(p_vf->concrete_fid, PXP_CONCRETE_FID_VFID);
83 p_ramrod->opaque_fid = OSAL_CPU_TO_LE16(p_vf->opaque_fid);
85 switch (p_hwfn->hw_info.personality) {
87 p_ramrod->personality = PERSONALITY_ETH;
89 case ECORE_PCI_ETH_ROCE:
90 case ECORE_PCI_ETH_IWARP:
91 p_ramrod->personality = PERSONALITY_RDMA_AND_ETH;
94 DP_NOTICE(p_hwfn, true, "Unknown VF personality %d\n",
95 p_hwfn->hw_info.personality);
99 fp_minor = p_vf->acquire.vfdev_info.eth_fp_hsi_minor;
100 if (fp_minor > ETH_HSI_VER_MINOR &&
101 fp_minor != ETH_HSI_VER_NO_PKT_LEN_TUNN) {
102 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
103 "VF [%d] - Requested fp hsi %02x.%02x which is"
104 " slightly newer than PF's %02x.%02x; Configuring"
107 ETH_HSI_VER_MAJOR, fp_minor,
108 ETH_HSI_VER_MAJOR, ETH_HSI_VER_MINOR);
109 fp_minor = ETH_HSI_VER_MINOR;
112 p_ramrod->hsi_fp_ver.major_ver_arr[ETH_VER_KEY] = ETH_HSI_VER_MAJOR;
113 p_ramrod->hsi_fp_ver.minor_ver_arr[ETH_VER_KEY] = fp_minor;
115 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
116 "VF[%d] - Starting using HSI %02x.%02x\n",
117 p_vf->abs_vf_id, ETH_HSI_VER_MAJOR, fp_minor);
119 return ecore_spq_post(p_hwfn, p_ent, OSAL_NULL);
122 static enum _ecore_status_t ecore_sp_vf_stop(struct ecore_hwfn *p_hwfn,
126 struct vf_stop_ramrod_data *p_ramrod = OSAL_NULL;
127 struct ecore_spq_entry *p_ent = OSAL_NULL;
128 struct ecore_sp_init_data init_data;
129 enum _ecore_status_t rc = ECORE_NOTIMPL;
132 OSAL_MEMSET(&init_data, 0, sizeof(init_data));
133 init_data.cid = ecore_spq_get_cid(p_hwfn);
134 init_data.opaque_fid = opaque_vfid;
135 init_data.comp_mode = ECORE_SPQ_MODE_EBLOCK;
137 rc = ecore_sp_init_request(p_hwfn, &p_ent,
138 COMMON_RAMROD_VF_STOP,
139 PROTOCOLID_COMMON, &init_data);
140 if (rc != ECORE_SUCCESS)
143 p_ramrod = &p_ent->ramrod.vf_stop;
145 p_ramrod->vf_id = GET_FIELD(concrete_vfid, PXP_CONCRETE_FID_VFID);
147 return ecore_spq_post(p_hwfn, p_ent, OSAL_NULL);
150 bool ecore_iov_is_valid_vfid(struct ecore_hwfn *p_hwfn, int rel_vf_id,
151 bool b_enabled_only, bool b_non_malicious)
153 if (!p_hwfn->pf_iov_info) {
154 DP_NOTICE(p_hwfn->p_dev, true, "No iov info\n");
158 if ((rel_vf_id >= p_hwfn->p_dev->p_iov_info->total_vfs) ||
162 if ((!p_hwfn->pf_iov_info->vfs_array[rel_vf_id].b_init) &&
166 if ((p_hwfn->pf_iov_info->vfs_array[rel_vf_id].b_malicious) &&
173 struct ecore_vf_info *ecore_iov_get_vf_info(struct ecore_hwfn *p_hwfn,
177 struct ecore_vf_info *vf = OSAL_NULL;
179 if (!p_hwfn->pf_iov_info) {
180 DP_NOTICE(p_hwfn->p_dev, true, "No iov info\n");
184 if (ecore_iov_is_valid_vfid(p_hwfn, relative_vf_id,
185 b_enabled_only, false))
186 vf = &p_hwfn->pf_iov_info->vfs_array[relative_vf_id];
188 DP_ERR(p_hwfn, "ecore_iov_get_vf_info: VF[%d] is not enabled\n",
194 static bool ecore_iov_validate_rxq(struct ecore_hwfn *p_hwfn,
195 struct ecore_vf_info *p_vf,
198 if (rx_qid >= p_vf->num_rxqs)
199 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
200 "VF[0x%02x] - can't touch Rx queue[%04x];"
201 " Only 0x%04x are allocated\n",
202 p_vf->abs_vf_id, rx_qid, p_vf->num_rxqs);
203 return rx_qid < p_vf->num_rxqs;
206 static bool ecore_iov_validate_txq(struct ecore_hwfn *p_hwfn,
207 struct ecore_vf_info *p_vf,
210 if (tx_qid >= p_vf->num_txqs)
211 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
212 "VF[0x%02x] - can't touch Tx queue[%04x];"
213 " Only 0x%04x are allocated\n",
214 p_vf->abs_vf_id, tx_qid, p_vf->num_txqs);
215 return tx_qid < p_vf->num_txqs;
218 static bool ecore_iov_validate_sb(struct ecore_hwfn *p_hwfn,
219 struct ecore_vf_info *p_vf,
224 for (i = 0; i < p_vf->num_sbs; i++)
225 if (p_vf->igu_sbs[i] == sb_idx)
228 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
229 "VF[0%02x] - tried using sb_idx %04x which doesn't exist as"
230 " one of its 0x%02x SBs\n",
231 p_vf->abs_vf_id, sb_idx, p_vf->num_sbs);
236 static bool ecore_iov_validate_active_rxq(struct ecore_hwfn *p_hwfn,
237 struct ecore_vf_info *p_vf)
241 for (i = 0; i < p_vf->num_rxqs; i++)
242 if (p_vf->vf_queues[i].p_rx_cid)
248 static bool ecore_iov_validate_active_txq(struct ecore_hwfn *p_hwfn,
249 struct ecore_vf_info *p_vf)
253 for (i = 0; i < p_vf->num_rxqs; i++)
254 if (p_vf->vf_queues[i].p_tx_cid)
260 /* TODO - this is linux crc32; Need a way to ifdef it out for linux */
261 u32 ecore_crc32(u32 crc, u8 *ptr, u32 length)
267 for (i = 0; i < 8; i++)
268 crc = (crc >> 1) ^ ((crc & 1) ? 0xedb88320 : 0);
273 enum _ecore_status_t ecore_iov_post_vf_bulletin(struct ecore_hwfn *p_hwfn,
275 struct ecore_ptt *p_ptt)
277 struct ecore_bulletin_content *p_bulletin;
278 int crc_size = sizeof(p_bulletin->crc);
279 struct ecore_dmae_params params;
280 struct ecore_vf_info *p_vf;
282 p_vf = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
286 /* TODO - check VF is in a state where it can accept message */
287 if (!p_vf->vf_bulletin)
290 p_bulletin = p_vf->bulletin.p_virt;
292 /* Increment bulletin board version and compute crc */
293 p_bulletin->version++;
294 p_bulletin->crc = ecore_crc32(0, (u8 *)p_bulletin + crc_size,
295 p_vf->bulletin.size - crc_size);
297 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
298 "Posting Bulletin 0x%08x to VF[%d] (CRC 0x%08x)\n",
299 p_bulletin->version, p_vf->relative_vf_id, p_bulletin->crc);
301 /* propagate bulletin board via dmae to vm memory */
302 OSAL_MEMSET(¶ms, 0, sizeof(params));
303 params.flags = ECORE_DMAE_FLAG_VF_DST;
304 params.dst_vfid = p_vf->abs_vf_id;
305 return ecore_dmae_host2host(p_hwfn, p_ptt, p_vf->bulletin.phys,
306 p_vf->vf_bulletin, p_vf->bulletin.size / 4,
310 static enum _ecore_status_t ecore_iov_pci_cfg_info(struct ecore_dev *p_dev)
312 struct ecore_hw_sriov_info *iov = p_dev->p_iov_info;
315 DP_VERBOSE(p_dev, ECORE_MSG_IOV, "sriov ext pos %d\n", pos);
316 OSAL_PCI_READ_CONFIG_WORD(p_dev, pos + PCI_SRIOV_CTRL, &iov->ctrl);
318 OSAL_PCI_READ_CONFIG_WORD(p_dev,
319 pos + PCI_SRIOV_TOTAL_VF, &iov->total_vfs);
320 OSAL_PCI_READ_CONFIG_WORD(p_dev,
321 pos + PCI_SRIOV_INITIAL_VF,
324 OSAL_PCI_READ_CONFIG_WORD(p_dev, pos + PCI_SRIOV_NUM_VF, &iov->num_vfs);
326 /* @@@TODO - in future we might want to add an OSAL here to
327 * allow each OS to decide on its own how to act.
329 DP_VERBOSE(p_dev, ECORE_MSG_IOV,
330 "Number of VFs are already set to non-zero value."
331 " Ignoring PCI configuration value\n");
335 OSAL_PCI_READ_CONFIG_WORD(p_dev,
336 pos + PCI_SRIOV_VF_OFFSET, &iov->offset);
338 OSAL_PCI_READ_CONFIG_WORD(p_dev,
339 pos + PCI_SRIOV_VF_STRIDE, &iov->stride);
341 OSAL_PCI_READ_CONFIG_WORD(p_dev,
342 pos + PCI_SRIOV_VF_DID, &iov->vf_device_id);
344 OSAL_PCI_READ_CONFIG_DWORD(p_dev,
345 pos + PCI_SRIOV_SUP_PGSIZE, &iov->pgsz);
347 OSAL_PCI_READ_CONFIG_DWORD(p_dev, pos + PCI_SRIOV_CAP, &iov->cap);
349 OSAL_PCI_READ_CONFIG_BYTE(p_dev, pos + PCI_SRIOV_FUNC_LINK, &iov->link);
351 DP_VERBOSE(p_dev, ECORE_MSG_IOV, "IOV info: nres %d, cap 0x%x,"
352 "ctrl 0x%x, total %d, initial %d, num vfs %d, offset %d,"
353 " stride %d, page size 0x%x\n",
354 iov->nres, iov->cap, iov->ctrl,
355 iov->total_vfs, iov->initial_vfs, iov->nr_virtfn,
356 iov->offset, iov->stride, iov->pgsz);
358 /* Some sanity checks */
359 if (iov->num_vfs > NUM_OF_VFS(p_dev) ||
360 iov->total_vfs > NUM_OF_VFS(p_dev)) {
361 /* This can happen only due to a bug. In this case we set
362 * num_vfs to zero to avoid memory corruption in the code that
363 * assumes max number of vfs
365 DP_NOTICE(p_dev, false,
366 "IOV: Unexpected number of vfs set: %d"
367 " setting num_vf to zero\n",
374 return ECORE_SUCCESS;
377 static void ecore_iov_clear_vf_igu_blocks(struct ecore_hwfn *p_hwfn,
378 struct ecore_ptt *p_ptt)
380 struct ecore_igu_block *p_sb;
384 if (!p_hwfn->hw_info.p_igu_info) {
386 "ecore_iov_clear_vf_igu_blocks IGU Info not inited\n");
391 sb_id < ECORE_MAPPING_MEMORY_SIZE(p_hwfn->p_dev); sb_id++) {
392 p_sb = &p_hwfn->hw_info.p_igu_info->igu_map.igu_blocks[sb_id];
393 if ((p_sb->status & ECORE_IGU_STATUS_FREE) &&
394 !(p_sb->status & ECORE_IGU_STATUS_PF)) {
395 val = ecore_rd(p_hwfn, p_ptt,
396 IGU_REG_MAPPING_MEMORY + sb_id * 4);
397 SET_FIELD(val, IGU_MAPPING_LINE_VALID, 0);
398 ecore_wr(p_hwfn, p_ptt,
399 IGU_REG_MAPPING_MEMORY + 4 * sb_id, val);
404 static void ecore_iov_setup_vfdb(struct ecore_hwfn *p_hwfn)
406 struct ecore_hw_sriov_info *p_iov = p_hwfn->p_dev->p_iov_info;
407 struct ecore_pf_iov *p_iov_info = p_hwfn->pf_iov_info;
408 struct ecore_bulletin_content *p_bulletin_virt;
409 dma_addr_t req_p, rply_p, bulletin_p;
410 union pfvf_tlvs *p_reply_virt_addr;
411 union vfpf_tlvs *p_req_virt_addr;
414 OSAL_MEMSET(p_iov_info->vfs_array, 0, sizeof(p_iov_info->vfs_array));
416 p_req_virt_addr = p_iov_info->mbx_msg_virt_addr;
417 req_p = p_iov_info->mbx_msg_phys_addr;
418 p_reply_virt_addr = p_iov_info->mbx_reply_virt_addr;
419 rply_p = p_iov_info->mbx_reply_phys_addr;
420 p_bulletin_virt = p_iov_info->p_bulletins;
421 bulletin_p = p_iov_info->bulletins_phys;
422 if (!p_req_virt_addr || !p_reply_virt_addr || !p_bulletin_virt) {
424 "ecore_iov_setup_vfdb called without alloc mem first\n");
428 p_iov_info->base_vport_id = 1; /* @@@TBD resource allocation */
430 for (idx = 0; idx < p_iov->total_vfs; idx++) {
431 struct ecore_vf_info *vf = &p_iov_info->vfs_array[idx];
434 vf->vf_mbx.req_virt = p_req_virt_addr + idx;
435 vf->vf_mbx.req_phys = req_p + idx * sizeof(union vfpf_tlvs);
436 vf->vf_mbx.reply_virt = p_reply_virt_addr + idx;
437 vf->vf_mbx.reply_phys = rply_p + idx * sizeof(union pfvf_tlvs);
439 #ifdef CONFIG_ECORE_SW_CHANNEL
440 vf->vf_mbx.sw_mbx.request_size = sizeof(union vfpf_tlvs);
441 vf->vf_mbx.sw_mbx.mbx_state = VF_PF_WAIT_FOR_START_REQUEST;
443 vf->state = VF_STOPPED;
446 vf->bulletin.phys = idx *
447 sizeof(struct ecore_bulletin_content) + bulletin_p;
448 vf->bulletin.p_virt = p_bulletin_virt + idx;
449 vf->bulletin.size = sizeof(struct ecore_bulletin_content);
451 vf->relative_vf_id = idx;
452 vf->abs_vf_id = idx + p_iov->first_vf_in_pf;
453 concrete = ecore_vfid_to_concrete(p_hwfn, vf->abs_vf_id);
454 vf->concrete_fid = concrete;
455 /* TODO - need to devise a better way of getting opaque */
456 vf->opaque_fid = (p_hwfn->hw_info.opaque_fid & 0xff) |
457 (vf->abs_vf_id << 8);
458 /* @@TBD MichalK - add base vport_id of VFs to equation */
459 vf->vport_id = p_iov_info->base_vport_id + idx;
461 vf->num_mac_filters = ECORE_ETH_VF_NUM_MAC_FILTERS;
462 vf->num_vlan_filters = ECORE_ETH_VF_NUM_VLAN_FILTERS;
466 static enum _ecore_status_t ecore_iov_allocate_vfdb(struct ecore_hwfn *p_hwfn)
468 struct ecore_pf_iov *p_iov_info = p_hwfn->pf_iov_info;
472 num_vfs = p_hwfn->p_dev->p_iov_info->total_vfs;
474 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
475 "ecore_iov_allocate_vfdb for %d VFs\n", num_vfs);
477 /* Allocate PF Mailbox buffer (per-VF) */
478 p_iov_info->mbx_msg_size = sizeof(union vfpf_tlvs) * num_vfs;
479 p_v_addr = &p_iov_info->mbx_msg_virt_addr;
480 *p_v_addr = OSAL_DMA_ALLOC_COHERENT(p_hwfn->p_dev,
481 &p_iov_info->mbx_msg_phys_addr,
482 p_iov_info->mbx_msg_size);
486 /* Allocate PF Mailbox Reply buffer (per-VF) */
487 p_iov_info->mbx_reply_size = sizeof(union pfvf_tlvs) * num_vfs;
488 p_v_addr = &p_iov_info->mbx_reply_virt_addr;
489 *p_v_addr = OSAL_DMA_ALLOC_COHERENT(p_hwfn->p_dev,
490 &p_iov_info->mbx_reply_phys_addr,
491 p_iov_info->mbx_reply_size);
495 p_iov_info->bulletins_size = sizeof(struct ecore_bulletin_content) *
497 p_v_addr = &p_iov_info->p_bulletins;
498 *p_v_addr = OSAL_DMA_ALLOC_COHERENT(p_hwfn->p_dev,
499 &p_iov_info->bulletins_phys,
500 p_iov_info->bulletins_size);
504 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
505 "PF's Requests mailbox [%p virt 0x%lx phys], "
506 "Response mailbox [%p virt 0x%lx phys] Bulletinsi"
507 " [%p virt 0x%lx phys]\n",
508 p_iov_info->mbx_msg_virt_addr,
509 (unsigned long)p_iov_info->mbx_msg_phys_addr,
510 p_iov_info->mbx_reply_virt_addr,
511 (unsigned long)p_iov_info->mbx_reply_phys_addr,
512 p_iov_info->p_bulletins,
513 (unsigned long)p_iov_info->bulletins_phys);
515 return ECORE_SUCCESS;
518 static void ecore_iov_free_vfdb(struct ecore_hwfn *p_hwfn)
520 struct ecore_pf_iov *p_iov_info = p_hwfn->pf_iov_info;
522 if (p_hwfn->pf_iov_info->mbx_msg_virt_addr)
523 OSAL_DMA_FREE_COHERENT(p_hwfn->p_dev,
524 p_iov_info->mbx_msg_virt_addr,
525 p_iov_info->mbx_msg_phys_addr,
526 p_iov_info->mbx_msg_size);
528 if (p_hwfn->pf_iov_info->mbx_reply_virt_addr)
529 OSAL_DMA_FREE_COHERENT(p_hwfn->p_dev,
530 p_iov_info->mbx_reply_virt_addr,
531 p_iov_info->mbx_reply_phys_addr,
532 p_iov_info->mbx_reply_size);
534 if (p_iov_info->p_bulletins)
535 OSAL_DMA_FREE_COHERENT(p_hwfn->p_dev,
536 p_iov_info->p_bulletins,
537 p_iov_info->bulletins_phys,
538 p_iov_info->bulletins_size);
541 enum _ecore_status_t ecore_iov_alloc(struct ecore_hwfn *p_hwfn)
543 struct ecore_pf_iov *p_sriov;
545 if (!IS_PF_SRIOV(p_hwfn)) {
546 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
547 "No SR-IOV - no need for IOV db\n");
548 return ECORE_SUCCESS;
551 p_sriov = OSAL_ZALLOC(p_hwfn->p_dev, GFP_KERNEL, sizeof(*p_sriov));
553 DP_NOTICE(p_hwfn, true,
554 "Failed to allocate `struct ecore_sriov'\n");
558 p_hwfn->pf_iov_info = p_sriov;
560 return ecore_iov_allocate_vfdb(p_hwfn);
563 void ecore_iov_setup(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt)
565 if (!IS_PF_SRIOV(p_hwfn) || !IS_PF_SRIOV_ALLOC(p_hwfn))
568 ecore_iov_setup_vfdb(p_hwfn);
569 ecore_iov_clear_vf_igu_blocks(p_hwfn, p_ptt);
572 void ecore_iov_free(struct ecore_hwfn *p_hwfn)
574 if (IS_PF_SRIOV_ALLOC(p_hwfn)) {
575 ecore_iov_free_vfdb(p_hwfn);
576 OSAL_FREE(p_hwfn->p_dev, p_hwfn->pf_iov_info);
580 void ecore_iov_free_hw_info(struct ecore_dev *p_dev)
582 OSAL_FREE(p_dev, p_dev->p_iov_info);
585 enum _ecore_status_t ecore_iov_hw_info(struct ecore_hwfn *p_hwfn)
587 struct ecore_dev *p_dev = p_hwfn->p_dev;
589 enum _ecore_status_t rc;
591 if (IS_VF(p_hwfn->p_dev))
592 return ECORE_SUCCESS;
594 /* Learn the PCI configuration */
595 pos = OSAL_PCI_FIND_EXT_CAPABILITY(p_hwfn->p_dev,
596 PCI_EXT_CAP_ID_SRIOV);
598 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV, "No PCIe IOV support\n");
599 return ECORE_SUCCESS;
602 /* Allocate a new struct for IOV information */
603 /* TODO - can change to VALLOC when its available */
604 p_dev->p_iov_info = OSAL_ZALLOC(p_dev, GFP_KERNEL,
605 sizeof(*p_dev->p_iov_info));
606 if (!p_dev->p_iov_info) {
607 DP_NOTICE(p_hwfn, true,
608 "Can't support IOV due to lack of memory\n");
611 p_dev->p_iov_info->pos = pos;
613 rc = ecore_iov_pci_cfg_info(p_dev);
617 /* We want PF IOV to be synonemous with the existence of p_iov_info;
618 * In case the capability is published but there are no VFs, simply
619 * de-allocate the struct.
621 if (!p_dev->p_iov_info->total_vfs) {
622 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
623 "IOV capabilities, but no VFs are published\n");
624 OSAL_FREE(p_dev, p_dev->p_iov_info);
625 return ECORE_SUCCESS;
628 /* First VF index based on offset is tricky:
629 * - If ARI is supported [likely], offset - (16 - pf_id) would
630 * provide the number for eng0. 2nd engine Vfs would begin
631 * after the first engine's VFs.
632 * - If !ARI, VFs would start on next device.
633 * so offset - (256 - pf_id) would provide the number.
634 * Utilize the fact that (256 - pf_id) is achieved only be later
635 * to diffrentiate between the two.
638 if (p_hwfn->p_dev->p_iov_info->offset < (256 - p_hwfn->abs_pf_id)) {
639 u32 first = p_hwfn->p_dev->p_iov_info->offset +
640 p_hwfn->abs_pf_id - 16;
642 p_dev->p_iov_info->first_vf_in_pf = first;
644 if (ECORE_PATH_ID(p_hwfn))
645 p_dev->p_iov_info->first_vf_in_pf -= MAX_NUM_VFS_BB;
647 u32 first = p_hwfn->p_dev->p_iov_info->offset +
648 p_hwfn->abs_pf_id - 256;
650 p_dev->p_iov_info->first_vf_in_pf = first;
653 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
654 "First VF in hwfn 0x%08x\n",
655 p_dev->p_iov_info->first_vf_in_pf);
657 return ECORE_SUCCESS;
660 static bool _ecore_iov_pf_sanity_check(struct ecore_hwfn *p_hwfn, int vfid,
661 bool b_fail_malicious)
663 /* Check PF supports sriov */
664 if (IS_VF(p_hwfn->p_dev) || !IS_ECORE_SRIOV(p_hwfn->p_dev) ||
665 !IS_PF_SRIOV_ALLOC(p_hwfn))
668 /* Check VF validity */
669 if (!ecore_iov_is_valid_vfid(p_hwfn, vfid, true, b_fail_malicious))
675 bool ecore_iov_pf_sanity_check(struct ecore_hwfn *p_hwfn, int vfid)
677 return _ecore_iov_pf_sanity_check(p_hwfn, vfid, true);
680 void ecore_iov_set_vf_to_disable(struct ecore_dev *p_dev,
681 u16 rel_vf_id, u8 to_disable)
683 struct ecore_vf_info *vf;
686 for_each_hwfn(p_dev, i) {
687 struct ecore_hwfn *p_hwfn = &p_dev->hwfns[i];
689 vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, false);
693 vf->to_disable = to_disable;
697 void ecore_iov_set_vfs_to_disable(struct ecore_dev *p_dev,
702 if (!IS_ECORE_SRIOV(p_dev))
705 for (i = 0; i < p_dev->p_iov_info->total_vfs; i++)
706 ecore_iov_set_vf_to_disable(p_dev, i, to_disable);
710 /* @@@TBD Consider taking outside of ecore... */
711 enum _ecore_status_t ecore_iov_set_vf_ctx(struct ecore_hwfn *p_hwfn,
715 enum _ecore_status_t rc = ECORE_SUCCESS;
716 struct ecore_vf_info *vf = ecore_iov_get_vf_info(p_hwfn, vf_id, true);
718 if (vf != OSAL_NULL) {
720 #ifdef CONFIG_ECORE_SW_CHANNEL
721 vf->vf_mbx.sw_mbx.mbx_state = VF_PF_WAIT_FOR_START_REQUEST;
724 rc = ECORE_UNKNOWN_ERROR;
730 static void ecore_iov_vf_pglue_clear_err(struct ecore_hwfn *p_hwfn,
731 struct ecore_ptt *p_ptt,
734 ecore_wr(p_hwfn, p_ptt,
735 PGLUE_B_REG_WAS_ERROR_VF_31_0_CLR + (abs_vfid >> 5) * 4,
736 1 << (abs_vfid & 0x1f));
739 static void ecore_iov_vf_igu_reset(struct ecore_hwfn *p_hwfn,
740 struct ecore_ptt *p_ptt,
741 struct ecore_vf_info *vf)
745 /* Set VF masks and configuration - pretend */
746 ecore_fid_pretend(p_hwfn, p_ptt, (u16)vf->concrete_fid);
748 ecore_wr(p_hwfn, p_ptt, IGU_REG_STATISTIC_NUM_VF_MSG_SENT, 0);
751 ecore_fid_pretend(p_hwfn, p_ptt, (u16)p_hwfn->hw_info.concrete_fid);
753 /* iterate over all queues, clear sb consumer */
754 for (i = 0; i < vf->num_sbs; i++)
755 ecore_int_igu_init_pure_rt_single(p_hwfn, p_ptt,
757 vf->opaque_fid, true);
760 static void ecore_iov_vf_igu_set_int(struct ecore_hwfn *p_hwfn,
761 struct ecore_ptt *p_ptt,
762 struct ecore_vf_info *vf, bool enable)
766 ecore_fid_pretend(p_hwfn, p_ptt, (u16)vf->concrete_fid);
768 igu_vf_conf = ecore_rd(p_hwfn, p_ptt, IGU_REG_VF_CONFIGURATION);
771 igu_vf_conf |= IGU_VF_CONF_MSI_MSIX_EN;
773 igu_vf_conf &= ~IGU_VF_CONF_MSI_MSIX_EN;
775 ecore_wr(p_hwfn, p_ptt, IGU_REG_VF_CONFIGURATION, igu_vf_conf);
778 ecore_fid_pretend(p_hwfn, p_ptt, (u16)p_hwfn->hw_info.concrete_fid);
781 static enum _ecore_status_t
782 ecore_iov_enable_vf_access(struct ecore_hwfn *p_hwfn,
783 struct ecore_ptt *p_ptt, struct ecore_vf_info *vf)
785 u32 igu_vf_conf = IGU_VF_CONF_FUNC_EN;
786 enum _ecore_status_t rc;
789 return ECORE_SUCCESS;
791 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
792 "Enable internal access for vf %x [abs %x]\n", vf->abs_vf_id,
793 ECORE_VF_ABS_ID(p_hwfn, vf));
795 ecore_iov_vf_pglue_clear_err(p_hwfn, p_ptt,
796 ECORE_VF_ABS_ID(p_hwfn, vf));
798 ecore_iov_vf_igu_reset(p_hwfn, p_ptt, vf);
800 /* It's possible VF was previously considered malicious */
801 vf->b_malicious = false;
803 rc = ecore_mcp_config_vf_msix(p_hwfn, p_ptt,
804 vf->abs_vf_id, vf->num_sbs);
805 if (rc != ECORE_SUCCESS)
808 ecore_fid_pretend(p_hwfn, p_ptt, (u16)vf->concrete_fid);
810 SET_FIELD(igu_vf_conf, IGU_VF_CONF_PARENT, p_hwfn->rel_pf_id);
811 STORE_RT_REG(p_hwfn, IGU_REG_VF_CONFIGURATION_RT_OFFSET, igu_vf_conf);
813 ecore_init_run(p_hwfn, p_ptt, PHASE_VF, vf->abs_vf_id,
814 p_hwfn->hw_info.hw_mode);
817 ecore_fid_pretend(p_hwfn, p_ptt, (u16)p_hwfn->hw_info.concrete_fid);
826 * @brief ecore_iov_config_perm_table - configure the permission
828 * In E4, queue zone permission table size is 320x9. There
829 * are 320 VF queues for single engine device (256 for dual
830 * engine device), and each entry has the following format:
837 static void ecore_iov_config_perm_table(struct ecore_hwfn *p_hwfn,
838 struct ecore_ptt *p_ptt,
839 struct ecore_vf_info *vf, u8 enable)
845 for (qid = 0; qid < vf->num_rxqs; qid++) {
846 ecore_fw_l2_queue(p_hwfn, vf->vf_queues[qid].fw_rx_qid,
849 reg_addr = PSWHST_REG_ZONE_PERMISSION_TABLE + qzone_id * 4;
850 val = enable ? (vf->abs_vf_id | (1 << 8)) : 0;
851 ecore_wr(p_hwfn, p_ptt, reg_addr, val);
855 static void ecore_iov_enable_vf_traffic(struct ecore_hwfn *p_hwfn,
856 struct ecore_ptt *p_ptt,
857 struct ecore_vf_info *vf)
859 /* Reset vf in IGU - interrupts are still disabled */
860 ecore_iov_vf_igu_reset(p_hwfn, p_ptt, vf);
862 ecore_iov_vf_igu_set_int(p_hwfn, p_ptt, vf, 1);
864 /* Permission Table */
865 ecore_iov_config_perm_table(p_hwfn, p_ptt, vf, true);
868 static u8 ecore_iov_alloc_vf_igu_sbs(struct ecore_hwfn *p_hwfn,
869 struct ecore_ptt *p_ptt,
870 struct ecore_vf_info *vf,
873 struct ecore_igu_block *igu_blocks;
874 int qid = 0, igu_id = 0;
877 igu_blocks = p_hwfn->hw_info.p_igu_info->igu_map.igu_blocks;
879 if (num_rx_queues > p_hwfn->hw_info.p_igu_info->free_blks)
880 num_rx_queues = p_hwfn->hw_info.p_igu_info->free_blks;
882 p_hwfn->hw_info.p_igu_info->free_blks -= num_rx_queues;
884 SET_FIELD(val, IGU_MAPPING_LINE_FUNCTION_NUMBER, vf->abs_vf_id);
885 SET_FIELD(val, IGU_MAPPING_LINE_VALID, 1);
886 SET_FIELD(val, IGU_MAPPING_LINE_PF_VALID, 0);
888 while ((qid < num_rx_queues) &&
889 (igu_id < ECORE_MAPPING_MEMORY_SIZE(p_hwfn->p_dev))) {
890 if (igu_blocks[igu_id].status & ECORE_IGU_STATUS_FREE) {
891 struct cau_sb_entry sb_entry;
893 vf->igu_sbs[qid] = (u16)igu_id;
894 igu_blocks[igu_id].status &= ~ECORE_IGU_STATUS_FREE;
896 SET_FIELD(val, IGU_MAPPING_LINE_VECTOR_NUMBER, qid);
898 ecore_wr(p_hwfn, p_ptt,
899 IGU_REG_MAPPING_MEMORY + sizeof(u32) * igu_id,
902 /* Configure igu sb in CAU which were marked valid */
903 ecore_init_cau_sb_entry(p_hwfn, &sb_entry,
906 ecore_dmae_host2grc(p_hwfn, p_ptt,
907 (u64)(osal_uintptr_t)&sb_entry,
908 CAU_REG_SB_VAR_MEMORY +
909 igu_id * sizeof(u64), 2, 0);
915 vf->num_sbs = (u8)num_rx_queues;
922 * @brief The function invalidates all the VF entries,
923 * technically this isn't required, but added for
924 * cleaness and ease of debugging incase a VF attempts to
925 * produce an interrupt after it has been taken down.
931 static void ecore_iov_free_vf_igu_sbs(struct ecore_hwfn *p_hwfn,
932 struct ecore_ptt *p_ptt,
933 struct ecore_vf_info *vf)
935 struct ecore_igu_info *p_info = p_hwfn->hw_info.p_igu_info;
939 /* Invalidate igu CAM lines and mark them as free */
940 for (idx = 0; idx < vf->num_sbs; idx++) {
941 igu_id = vf->igu_sbs[idx];
942 addr = IGU_REG_MAPPING_MEMORY + sizeof(u32) * igu_id;
944 val = ecore_rd(p_hwfn, p_ptt, addr);
945 SET_FIELD(val, IGU_MAPPING_LINE_VALID, 0);
946 ecore_wr(p_hwfn, p_ptt, addr, val);
948 p_info->igu_map.igu_blocks[igu_id].status |=
949 ECORE_IGU_STATUS_FREE;
951 p_hwfn->hw_info.p_igu_info->free_blks++;
958 ecore_iov_init_hw_for_vf(struct ecore_hwfn *p_hwfn,
959 struct ecore_ptt *p_ptt,
960 struct ecore_iov_vf_init_params *p_params)
962 u8 num_of_vf_available_chains = 0;
963 struct ecore_vf_info *vf = OSAL_NULL;
965 enum _ecore_status_t rc = ECORE_SUCCESS;
969 vf = ecore_iov_get_vf_info(p_hwfn, p_params->rel_vf_id, false);
971 DP_ERR(p_hwfn, "ecore_iov_init_hw_for_vf : vf is OSAL_NULL\n");
972 return ECORE_UNKNOWN_ERROR;
976 DP_NOTICE(p_hwfn, true, "VF[%d] is already active.\n",
977 p_params->rel_vf_id);
981 /* Perform sanity checking on the requested queue_id */
982 for (i = 0; i < p_params->num_queues; i++) {
983 u16 min_vf_qzone = (u16)FEAT_NUM(p_hwfn, ECORE_PF_L2_QUE);
984 u16 max_vf_qzone = min_vf_qzone +
985 FEAT_NUM(p_hwfn, ECORE_VF_L2_QUE) - 1;
987 qid = p_params->req_rx_queue[i];
988 if (qid < min_vf_qzone || qid > max_vf_qzone) {
989 DP_NOTICE(p_hwfn, true,
990 "Can't enable Rx qid [%04x] for VF[%d]: qids [0x%04x,...,0x%04x] available\n",
991 qid, p_params->rel_vf_id,
992 min_vf_qzone, max_vf_qzone);
996 qid = p_params->req_tx_queue[i];
997 if (qid > max_vf_qzone) {
998 DP_NOTICE(p_hwfn, true,
999 "Can't enable Tx qid [%04x] for VF[%d]: max qid 0x%04x\n",
1000 qid, p_params->rel_vf_id, max_vf_qzone);
1004 /* If client *really* wants, Tx qid can be shared with PF */
1005 if (qid < min_vf_qzone)
1006 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1007 "VF[%d] is using PF qid [0x%04x] for Txq[0x%02x]\n",
1008 p_params->rel_vf_id, qid, i);
1011 /* Limit number of queues according to number of CIDs */
1012 ecore_cxt_get_proto_cid_count(p_hwfn, PROTOCOLID_ETH, &cids);
1013 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1014 "VF[%d] - requesting to initialize for 0x%04x queues"
1015 " [0x%04x CIDs available]\n",
1016 vf->relative_vf_id, p_params->num_queues, (u16)cids);
1017 num_irqs = OSAL_MIN_T(u16, p_params->num_queues, ((u16)cids));
1019 num_of_vf_available_chains = ecore_iov_alloc_vf_igu_sbs(p_hwfn,
1023 if (num_of_vf_available_chains == 0) {
1024 DP_ERR(p_hwfn, "no available igu sbs\n");
1028 /* Choose queue number and index ranges */
1029 vf->num_rxqs = num_of_vf_available_chains;
1030 vf->num_txqs = num_of_vf_available_chains;
1032 for (i = 0; i < vf->num_rxqs; i++) {
1033 struct ecore_vf_q_info *p_queue = &vf->vf_queues[i];
1035 p_queue->fw_rx_qid = p_params->req_rx_queue[i];
1036 p_queue->fw_tx_qid = p_params->req_tx_queue[i];
1038 /* CIDs are per-VF, so no problem having them 0-based. */
1039 p_queue->fw_cid = i;
1041 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1042 "VF[%d] - Q[%d] SB %04x, qid [Rx %04x Tx %04x] CID %04x\n",
1043 vf->relative_vf_id, i, vf->igu_sbs[i],
1044 p_queue->fw_rx_qid, p_queue->fw_tx_qid,
1048 rc = ecore_iov_enable_vf_access(p_hwfn, p_ptt, vf);
1050 if (rc == ECORE_SUCCESS) {
1052 p_hwfn->pf_iov_info->active_vfs[vf->relative_vf_id / 64] |=
1053 (1ULL << (vf->relative_vf_id % 64));
1055 if (IS_LEAD_HWFN(p_hwfn))
1056 p_hwfn->p_dev->p_iov_info->num_vfs++;
1062 void ecore_iov_set_link(struct ecore_hwfn *p_hwfn,
1064 struct ecore_mcp_link_params *params,
1065 struct ecore_mcp_link_state *link,
1066 struct ecore_mcp_link_capabilities *p_caps)
1068 struct ecore_vf_info *p_vf = ecore_iov_get_vf_info(p_hwfn, vfid, false);
1069 struct ecore_bulletin_content *p_bulletin;
1074 p_bulletin = p_vf->bulletin.p_virt;
1075 p_bulletin->req_autoneg = params->speed.autoneg;
1076 p_bulletin->req_adv_speed = params->speed.advertised_speeds;
1077 p_bulletin->req_forced_speed = params->speed.forced_speed;
1078 p_bulletin->req_autoneg_pause = params->pause.autoneg;
1079 p_bulletin->req_forced_rx = params->pause.forced_rx;
1080 p_bulletin->req_forced_tx = params->pause.forced_tx;
1081 p_bulletin->req_loopback = params->loopback_mode;
1083 p_bulletin->link_up = link->link_up;
1084 p_bulletin->speed = link->speed;
1085 p_bulletin->full_duplex = link->full_duplex;
1086 p_bulletin->autoneg = link->an;
1087 p_bulletin->autoneg_complete = link->an_complete;
1088 p_bulletin->parallel_detection = link->parallel_detection;
1089 p_bulletin->pfc_enabled = link->pfc_enabled;
1090 p_bulletin->partner_adv_speed = link->partner_adv_speed;
1091 p_bulletin->partner_tx_flow_ctrl_en = link->partner_tx_flow_ctrl_en;
1092 p_bulletin->partner_rx_flow_ctrl_en = link->partner_rx_flow_ctrl_en;
1093 p_bulletin->partner_adv_pause = link->partner_adv_pause;
1094 p_bulletin->sfp_tx_fault = link->sfp_tx_fault;
1096 p_bulletin->capability_speed = p_caps->speed_capabilities;
1099 enum _ecore_status_t ecore_iov_release_hw_for_vf(struct ecore_hwfn *p_hwfn,
1100 struct ecore_ptt *p_ptt,
1103 struct ecore_mcp_link_capabilities caps;
1104 struct ecore_mcp_link_params params;
1105 struct ecore_mcp_link_state link;
1106 struct ecore_vf_info *vf = OSAL_NULL;
1108 vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
1110 DP_ERR(p_hwfn, "ecore_iov_release_hw_for_vf : vf is NULL\n");
1111 return ECORE_UNKNOWN_ERROR;
1114 if (vf->bulletin.p_virt)
1115 OSAL_MEMSET(vf->bulletin.p_virt, 0,
1116 sizeof(*vf->bulletin.p_virt));
1118 OSAL_MEMSET(&vf->p_vf_info, 0, sizeof(vf->p_vf_info));
1120 /* Get the link configuration back in bulletin so
1121 * that when VFs are re-enabled they get the actual
1122 * link configuration.
1124 OSAL_MEMCPY(¶ms, ecore_mcp_get_link_params(p_hwfn), sizeof(params));
1125 OSAL_MEMCPY(&link, ecore_mcp_get_link_state(p_hwfn), sizeof(link));
1126 OSAL_MEMCPY(&caps, ecore_mcp_get_link_capabilities(p_hwfn),
1128 ecore_iov_set_link(p_hwfn, rel_vf_id, ¶ms, &link, &caps);
1130 /* Forget the VF's acquisition message */
1131 OSAL_MEMSET(&vf->acquire, 0, sizeof(vf->acquire));
1133 /* disablng interrupts and resetting permission table was done during
1134 * vf-close, however, we could get here without going through vf_close
1136 /* Disable Interrupts for VF */
1137 ecore_iov_vf_igu_set_int(p_hwfn, p_ptt, vf, 0);
1139 /* Reset Permission table */
1140 ecore_iov_config_perm_table(p_hwfn, p_ptt, vf, 0);
1144 ecore_iov_free_vf_igu_sbs(p_hwfn, p_ptt, vf);
1148 p_hwfn->pf_iov_info->active_vfs[vf->relative_vf_id / 64] &=
1149 ~(1ULL << (vf->relative_vf_id / 64));
1151 if (IS_LEAD_HWFN(p_hwfn))
1152 p_hwfn->p_dev->p_iov_info->num_vfs--;
1155 return ECORE_SUCCESS;
1158 static bool ecore_iov_tlv_supported(u16 tlvtype)
1160 return tlvtype > CHANNEL_TLV_NONE && tlvtype < CHANNEL_TLV_MAX;
1163 static void ecore_iov_lock_vf_pf_channel(struct ecore_hwfn *p_hwfn,
1164 struct ecore_vf_info *vf, u16 tlv)
1166 /* lock the channel */
1167 /* mutex_lock(&vf->op_mutex); @@@TBD MichalK - add lock... */
1169 /* record the locking op */
1170 /* vf->op_current = tlv; @@@TBD MichalK */
1173 if (ecore_iov_tlv_supported(tlv))
1176 "VF[%d]: vf pf channel locked by %s\n",
1178 ecore_channel_tlvs_string[tlv]);
1182 "VF[%d]: vf pf channel locked by %04x\n",
1183 vf->abs_vf_id, tlv);
1186 static void ecore_iov_unlock_vf_pf_channel(struct ecore_hwfn *p_hwfn,
1187 struct ecore_vf_info *vf,
1190 /* log the unlock */
1191 if (ecore_iov_tlv_supported(expected_tlv))
1194 "VF[%d]: vf pf channel unlocked by %s\n",
1196 ecore_channel_tlvs_string[expected_tlv]);
1200 "VF[%d]: vf pf channel unlocked by %04x\n",
1201 vf->abs_vf_id, expected_tlv);
1203 /* record the locking op */
1204 /* vf->op_current = CHANNEL_TLV_NONE; */
1207 /* place a given tlv on the tlv buffer, continuing current tlv list */
1208 void *ecore_add_tlv(struct ecore_hwfn *p_hwfn,
1209 u8 **offset, u16 type, u16 length)
1211 struct channel_tlv *tl = (struct channel_tlv *)*offset;
1214 tl->length = length;
1216 /* Offset should keep pointing to next TLV (the end of the last) */
1219 /* Return a pointer to the start of the added tlv */
1220 return *offset - length;
1223 /* list the types and lengths of the tlvs on the buffer */
1224 void ecore_dp_tlv_list(struct ecore_hwfn *p_hwfn, void *tlvs_list)
1226 u16 i = 1, total_length = 0;
1227 struct channel_tlv *tlv;
1230 /* cast current tlv list entry to channel tlv header */
1231 tlv = (struct channel_tlv *)((u8 *)tlvs_list + total_length);
1234 if (ecore_iov_tlv_supported(tlv->type))
1235 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1236 "TLV number %d: type %s, length %d\n",
1237 i, ecore_channel_tlvs_string[tlv->type],
1240 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1241 "TLV number %d: type %d, length %d\n",
1242 i, tlv->type, tlv->length);
1244 if (tlv->type == CHANNEL_TLV_LIST_END)
1247 /* Validate entry - protect against malicious VFs */
1249 DP_NOTICE(p_hwfn, false, "TLV of length 0 found\n");
1252 total_length += tlv->length;
1253 if (total_length >= sizeof(struct tlv_buffer_size)) {
1254 DP_NOTICE(p_hwfn, false, "TLV ==> Buffer overflow\n");
1262 static void ecore_iov_send_response(struct ecore_hwfn *p_hwfn,
1263 struct ecore_ptt *p_ptt,
1264 struct ecore_vf_info *p_vf,
1265 u16 length, u8 status)
1267 struct ecore_iov_vf_mbx *mbx = &p_vf->vf_mbx;
1268 struct ecore_dmae_params params;
1271 mbx->reply_virt->default_resp.hdr.status = status;
1273 ecore_dp_tlv_list(p_hwfn, mbx->reply_virt);
1275 #ifdef CONFIG_ECORE_SW_CHANNEL
1276 mbx->sw_mbx.response_size =
1277 length + sizeof(struct channel_list_end_tlv);
1279 if (!p_hwfn->p_dev->b_hw_channel)
1283 eng_vf_id = p_vf->abs_vf_id;
1285 OSAL_MEMSET(¶ms, 0, sizeof(struct ecore_dmae_params));
1286 params.flags = ECORE_DMAE_FLAG_VF_DST;
1287 params.dst_vfid = eng_vf_id;
1289 ecore_dmae_host2host(p_hwfn, p_ptt, mbx->reply_phys + sizeof(u64),
1290 mbx->req_virt->first_tlv.reply_address +
1292 (sizeof(union pfvf_tlvs) - sizeof(u64)) / 4,
1295 ecore_dmae_host2host(p_hwfn, p_ptt, mbx->reply_phys,
1296 mbx->req_virt->first_tlv.reply_address,
1297 sizeof(u64) / 4, ¶ms);
1300 GTT_BAR0_MAP_REG_USDM_RAM +
1301 USTORM_VF_PF_CHANNEL_READY_OFFSET(eng_vf_id), 1);
1304 static u16 ecore_iov_vport_to_tlv(struct ecore_hwfn *p_hwfn,
1305 enum ecore_iov_vport_update_flag flag)
1308 case ECORE_IOV_VP_UPDATE_ACTIVATE:
1309 return CHANNEL_TLV_VPORT_UPDATE_ACTIVATE;
1310 case ECORE_IOV_VP_UPDATE_VLAN_STRIP:
1311 return CHANNEL_TLV_VPORT_UPDATE_VLAN_STRIP;
1312 case ECORE_IOV_VP_UPDATE_TX_SWITCH:
1313 return CHANNEL_TLV_VPORT_UPDATE_TX_SWITCH;
1314 case ECORE_IOV_VP_UPDATE_MCAST:
1315 return CHANNEL_TLV_VPORT_UPDATE_MCAST;
1316 case ECORE_IOV_VP_UPDATE_ACCEPT_PARAM:
1317 return CHANNEL_TLV_VPORT_UPDATE_ACCEPT_PARAM;
1318 case ECORE_IOV_VP_UPDATE_RSS:
1319 return CHANNEL_TLV_VPORT_UPDATE_RSS;
1320 case ECORE_IOV_VP_UPDATE_ACCEPT_ANY_VLAN:
1321 return CHANNEL_TLV_VPORT_UPDATE_ACCEPT_ANY_VLAN;
1322 case ECORE_IOV_VP_UPDATE_SGE_TPA:
1323 return CHANNEL_TLV_VPORT_UPDATE_SGE_TPA;
1329 static u16 ecore_iov_prep_vp_update_resp_tlvs(struct ecore_hwfn *p_hwfn,
1330 struct ecore_vf_info *p_vf,
1331 struct ecore_iov_vf_mbx *p_mbx,
1332 u8 status, u16 tlvs_mask,
1335 struct pfvf_def_resp_tlv *resp;
1336 u16 size, total_len, i;
1338 OSAL_MEMSET(p_mbx->reply_virt, 0, sizeof(union pfvf_tlvs));
1339 p_mbx->offset = (u8 *)p_mbx->reply_virt;
1340 size = sizeof(struct pfvf_def_resp_tlv);
1343 ecore_add_tlv(p_hwfn, &p_mbx->offset, CHANNEL_TLV_VPORT_UPDATE, size);
1345 /* Prepare response for all extended tlvs if they are found by PF */
1346 for (i = 0; i < ECORE_IOV_VP_UPDATE_MAX; i++) {
1347 if (!(tlvs_mask & (1 << i)))
1350 resp = ecore_add_tlv(p_hwfn, &p_mbx->offset,
1351 ecore_iov_vport_to_tlv(p_hwfn, i), size);
1353 if (tlvs_accepted & (1 << i))
1354 resp->hdr.status = status;
1356 resp->hdr.status = PFVF_STATUS_NOT_SUPPORTED;
1358 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1359 "VF[%d] - vport_update resp: TLV %d, status %02x\n",
1360 p_vf->relative_vf_id,
1361 ecore_iov_vport_to_tlv(p_hwfn, i), resp->hdr.status);
1366 ecore_add_tlv(p_hwfn, &p_mbx->offset, CHANNEL_TLV_LIST_END,
1367 sizeof(struct channel_list_end_tlv));
1372 static void ecore_iov_prepare_resp(struct ecore_hwfn *p_hwfn,
1373 struct ecore_ptt *p_ptt,
1374 struct ecore_vf_info *vf_info,
1375 u16 type, u16 length, u8 status)
1377 struct ecore_iov_vf_mbx *mbx = &vf_info->vf_mbx;
1379 mbx->offset = (u8 *)mbx->reply_virt;
1381 ecore_add_tlv(p_hwfn, &mbx->offset, type, length);
1382 ecore_add_tlv(p_hwfn, &mbx->offset, CHANNEL_TLV_LIST_END,
1383 sizeof(struct channel_list_end_tlv));
1385 ecore_iov_send_response(p_hwfn, p_ptt, vf_info, length, status);
1387 OSAL_IOV_PF_RESP_TYPE(p_hwfn, vf_info->relative_vf_id, status);
1390 struct ecore_public_vf_info
1391 *ecore_iov_get_public_vf_info(struct ecore_hwfn *p_hwfn,
1393 bool b_enabled_only)
1395 struct ecore_vf_info *vf = OSAL_NULL;
1397 vf = ecore_iov_get_vf_info(p_hwfn, relative_vf_id, b_enabled_only);
1401 return &vf->p_vf_info;
1404 static void ecore_iov_vf_cleanup(struct ecore_hwfn *p_hwfn,
1405 struct ecore_vf_info *p_vf)
1408 p_vf->vf_bulletin = 0;
1409 p_vf->vport_instance = 0;
1410 p_vf->configured_features = 0;
1412 /* If VF previously requested less resources, go back to default */
1413 p_vf->num_rxqs = p_vf->num_sbs;
1414 p_vf->num_txqs = p_vf->num_sbs;
1416 p_vf->num_active_rxqs = 0;
1418 for (i = 0; i < ECORE_MAX_VF_CHAINS_PER_PF; i++) {
1419 struct ecore_vf_q_info *p_queue = &p_vf->vf_queues[i];
1421 if (p_queue->p_rx_cid) {
1422 ecore_eth_queue_cid_release(p_hwfn,
1424 p_queue->p_rx_cid = OSAL_NULL;
1427 if (p_queue->p_tx_cid) {
1428 ecore_eth_queue_cid_release(p_hwfn,
1430 p_queue->p_tx_cid = OSAL_NULL;
1434 OSAL_MEMSET(&p_vf->shadow_config, 0, sizeof(p_vf->shadow_config));
1435 OSAL_MEMSET(&p_vf->acquire, 0, sizeof(p_vf->acquire));
1436 OSAL_IOV_VF_CLEANUP(p_hwfn, p_vf->relative_vf_id);
1439 static u8 ecore_iov_vf_mbx_acquire_resc(struct ecore_hwfn *p_hwfn,
1440 struct ecore_ptt *p_ptt,
1441 struct ecore_vf_info *p_vf,
1442 struct vf_pf_resc_request *p_req,
1443 struct pf_vf_resc *p_resp)
1447 /* Queue related information */
1448 p_resp->num_rxqs = p_vf->num_rxqs;
1449 p_resp->num_txqs = p_vf->num_txqs;
1450 p_resp->num_sbs = p_vf->num_sbs;
1452 for (i = 0; i < p_resp->num_sbs; i++) {
1453 p_resp->hw_sbs[i].hw_sb_id = p_vf->igu_sbs[i];
1454 /* TODO - what's this sb_qid field? Is it deprecated?
1455 * or is there an ecore_client that looks at this?
1457 p_resp->hw_sbs[i].sb_qid = 0;
1460 /* These fields are filled for backward compatibility.
1461 * Unused by modern vfs.
1463 for (i = 0; i < p_resp->num_rxqs; i++) {
1464 ecore_fw_l2_queue(p_hwfn, p_vf->vf_queues[i].fw_rx_qid,
1465 (u16 *)&p_resp->hw_qid[i]);
1466 p_resp->cid[i] = p_vf->vf_queues[i].fw_cid;
1469 /* Filter related information */
1470 p_resp->num_mac_filters = OSAL_MIN_T(u8, p_vf->num_mac_filters,
1471 p_req->num_mac_filters);
1472 p_resp->num_vlan_filters = OSAL_MIN_T(u8, p_vf->num_vlan_filters,
1473 p_req->num_vlan_filters);
1475 /* This isn't really needed/enforced, but some legacy VFs might depend
1476 * on the correct filling of this field.
1478 p_resp->num_mc_filters = ECORE_MAX_MC_ADDRS;
1480 /* Validate sufficient resources for VF */
1481 if (p_resp->num_rxqs < p_req->num_rxqs ||
1482 p_resp->num_txqs < p_req->num_txqs ||
1483 p_resp->num_sbs < p_req->num_sbs ||
1484 p_resp->num_mac_filters < p_req->num_mac_filters ||
1485 p_resp->num_vlan_filters < p_req->num_vlan_filters ||
1486 p_resp->num_mc_filters < p_req->num_mc_filters) {
1487 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1488 "VF[%d] - Insufficient resources: rxq [%02x/%02x]"
1489 " txq [%02x/%02x] sbs [%02x/%02x] mac [%02x/%02x]"
1490 " vlan [%02x/%02x] mc [%02x/%02x]\n",
1492 p_req->num_rxqs, p_resp->num_rxqs,
1493 p_req->num_rxqs, p_resp->num_txqs,
1494 p_req->num_sbs, p_resp->num_sbs,
1495 p_req->num_mac_filters, p_resp->num_mac_filters,
1496 p_req->num_vlan_filters, p_resp->num_vlan_filters,
1497 p_req->num_mc_filters, p_resp->num_mc_filters);
1499 /* Some legacy OSes are incapable of correctly handling this
1502 if ((p_vf->acquire.vfdev_info.eth_fp_hsi_minor ==
1503 ETH_HSI_VER_NO_PKT_LEN_TUNN) &&
1504 (p_vf->acquire.vfdev_info.os_type ==
1505 VFPF_ACQUIRE_OS_WINDOWS))
1506 return PFVF_STATUS_SUCCESS;
1508 return PFVF_STATUS_NO_RESOURCE;
1511 return PFVF_STATUS_SUCCESS;
1514 static void ecore_iov_vf_mbx_acquire_stats(struct ecore_hwfn *p_hwfn,
1515 struct pfvf_stats_info *p_stats)
1517 p_stats->mstats.address = PXP_VF_BAR0_START_MSDM_ZONE_B +
1518 OFFSETOF(struct mstorm_vf_zone,
1519 non_trigger.eth_queue_stat);
1520 p_stats->mstats.len = sizeof(struct eth_mstorm_per_queue_stat);
1521 p_stats->ustats.address = PXP_VF_BAR0_START_USDM_ZONE_B +
1522 OFFSETOF(struct ustorm_vf_zone,
1523 non_trigger.eth_queue_stat);
1524 p_stats->ustats.len = sizeof(struct eth_ustorm_per_queue_stat);
1525 p_stats->pstats.address = PXP_VF_BAR0_START_PSDM_ZONE_B +
1526 OFFSETOF(struct pstorm_vf_zone,
1527 non_trigger.eth_queue_stat);
1528 p_stats->pstats.len = sizeof(struct eth_pstorm_per_queue_stat);
1529 p_stats->tstats.address = 0;
1530 p_stats->tstats.len = 0;
1533 static void ecore_iov_vf_mbx_acquire(struct ecore_hwfn *p_hwfn,
1534 struct ecore_ptt *p_ptt,
1535 struct ecore_vf_info *vf)
1537 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
1538 struct pfvf_acquire_resp_tlv *resp = &mbx->reply_virt->acquire_resp;
1539 struct pf_vf_pfdev_info *pfdev_info = &resp->pfdev_info;
1540 struct vfpf_acquire_tlv *req = &mbx->req_virt->acquire;
1541 u8 vfpf_status = PFVF_STATUS_NOT_SUPPORTED;
1542 struct pf_vf_resc *resc = &resp->resc;
1543 enum _ecore_status_t rc;
1545 OSAL_MEMSET(resp, 0, sizeof(*resp));
1547 /* Write the PF version so that VF would know which version
1548 * is supported - might be later overridden. This guarantees that
1549 * VF could recognize legacy PF based on lack of versions in reply.
1551 pfdev_info->major_fp_hsi = ETH_HSI_VER_MAJOR;
1552 pfdev_info->minor_fp_hsi = ETH_HSI_VER_MINOR;
1554 /* TODO - not doing anything is bad since we'll assert, but this isn't
1555 * necessarily the right behavior - perhaps we should have allowed some
1558 if (vf->state != VF_FREE &&
1559 vf->state != VF_STOPPED) {
1560 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1561 "VF[%d] sent ACQUIRE but is already in state %d - fail request\n",
1562 vf->abs_vf_id, vf->state);
1566 /* Validate FW compatibility */
1567 if (req->vfdev_info.eth_fp_hsi_major != ETH_HSI_VER_MAJOR) {
1568 if (req->vfdev_info.capabilities &
1569 VFPF_ACQUIRE_CAP_PRE_FP_HSI) {
1570 struct vf_pf_vfdev_info *p_vfdev = &req->vfdev_info;
1572 /* This legacy support would need to be removed once
1573 * the major has changed.
1575 OSAL_BUILD_BUG_ON(ETH_HSI_VER_MAJOR != 3);
1577 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1578 "VF[%d] is pre-fastpath HSI\n",
1580 p_vfdev->eth_fp_hsi_major = ETH_HSI_VER_MAJOR;
1581 p_vfdev->eth_fp_hsi_minor = ETH_HSI_VER_NO_PKT_LEN_TUNN;
1584 "VF[%d] needs fastpath HSI %02x.%02x, which is"
1585 " incompatible with loaded FW's faspath"
1588 req->vfdev_info.eth_fp_hsi_major,
1589 req->vfdev_info.eth_fp_hsi_minor,
1590 ETH_HSI_VER_MAJOR, ETH_HSI_VER_MINOR);
1596 /* On 100g PFs, prevent old VFs from loading */
1597 if ((p_hwfn->p_dev->num_hwfns > 1) &&
1598 !(req->vfdev_info.capabilities & VFPF_ACQUIRE_CAP_100G)) {
1600 "VF[%d] is running an old driver that doesn't support"
1606 #ifndef __EXTRACT__LINUX__
1607 if (OSAL_IOV_VF_ACQUIRE(p_hwfn, vf->relative_vf_id) != ECORE_SUCCESS) {
1608 vfpf_status = PFVF_STATUS_NOT_SUPPORTED;
1613 /* Store the acquire message */
1614 OSAL_MEMCPY(&vf->acquire, req, sizeof(vf->acquire));
1616 vf->opaque_fid = req->vfdev_info.opaque_fid;
1618 vf->vf_bulletin = req->bulletin_addr;
1619 vf->bulletin.size = (vf->bulletin.size < req->bulletin_size) ?
1620 vf->bulletin.size : req->bulletin_size;
1622 /* fill in pfdev info */
1623 pfdev_info->chip_num = p_hwfn->p_dev->chip_num;
1624 pfdev_info->db_size = 0; /* @@@ TBD MichalK Vf Doorbells */
1625 pfdev_info->indices_per_sb = PIS_PER_SB;
1627 pfdev_info->capabilities = PFVF_ACQUIRE_CAP_DEFAULT_UNTAGGED |
1628 PFVF_ACQUIRE_CAP_POST_FW_OVERRIDE;
1629 if (p_hwfn->p_dev->num_hwfns > 1)
1630 pfdev_info->capabilities |= PFVF_ACQUIRE_CAP_100G;
1632 ecore_iov_vf_mbx_acquire_stats(p_hwfn, &pfdev_info->stats_info);
1634 OSAL_MEMCPY(pfdev_info->port_mac, p_hwfn->hw_info.hw_mac_addr,
1637 pfdev_info->fw_major = FW_MAJOR_VERSION;
1638 pfdev_info->fw_minor = FW_MINOR_VERSION;
1639 pfdev_info->fw_rev = FW_REVISION_VERSION;
1640 pfdev_info->fw_eng = FW_ENGINEERING_VERSION;
1642 /* Incorrect when legacy, but doesn't matter as legacy isn't reading
1645 pfdev_info->minor_fp_hsi = OSAL_MIN_T(u8, ETH_HSI_VER_MINOR,
1646 req->vfdev_info.eth_fp_hsi_minor);
1647 pfdev_info->os_type = OSAL_IOV_GET_OS_TYPE();
1648 ecore_mcp_get_mfw_ver(p_hwfn, p_ptt, &pfdev_info->mfw_ver,
1651 pfdev_info->dev_type = p_hwfn->p_dev->type;
1652 pfdev_info->chip_rev = p_hwfn->p_dev->chip_rev;
1654 /* Fill resources available to VF; Make sure there are enough to
1655 * satisfy the VF's request.
1657 vfpf_status = ecore_iov_vf_mbx_acquire_resc(p_hwfn, p_ptt, vf,
1658 &req->resc_request, resc);
1659 if (vfpf_status != PFVF_STATUS_SUCCESS)
1662 /* Start the VF in FW */
1663 rc = ecore_sp_vf_start(p_hwfn, vf);
1664 if (rc != ECORE_SUCCESS) {
1665 DP_NOTICE(p_hwfn, true, "Failed to start VF[%02x]\n",
1667 vfpf_status = PFVF_STATUS_FAILURE;
1671 /* Fill agreed size of bulletin board in response, and post
1672 * an initial image to the bulletin board.
1674 resp->bulletin_size = vf->bulletin.size;
1675 ecore_iov_post_vf_bulletin(p_hwfn, vf->relative_vf_id, p_ptt);
1677 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1678 "VF[%d] ACQUIRE_RESPONSE: pfdev_info- chip_num=0x%x,"
1679 " db_size=%d, idx_per_sb=%d, pf_cap=0x%lx\n"
1680 "resources- n_rxq-%d, n_txq-%d, n_sbs-%d, n_macs-%d,"
1682 vf->abs_vf_id, resp->pfdev_info.chip_num,
1683 resp->pfdev_info.db_size, resp->pfdev_info.indices_per_sb,
1684 (unsigned long)resp->pfdev_info.capabilities, resc->num_rxqs,
1685 resc->num_txqs, resc->num_sbs, resc->num_mac_filters,
1686 resc->num_vlan_filters);
1688 vf->state = VF_ACQUIRED;
1691 /* Prepare Response */
1692 ecore_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_ACQUIRE,
1693 sizeof(struct pfvf_acquire_resp_tlv),
1697 static enum _ecore_status_t
1698 __ecore_iov_spoofchk_set(struct ecore_hwfn *p_hwfn,
1699 struct ecore_vf_info *p_vf, bool val)
1701 struct ecore_sp_vport_update_params params;
1702 enum _ecore_status_t rc;
1704 if (val == p_vf->spoof_chk) {
1705 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1706 "Spoofchk value[%d] is already configured\n", val);
1707 return ECORE_SUCCESS;
1710 OSAL_MEMSET(¶ms, 0, sizeof(struct ecore_sp_vport_update_params));
1711 params.opaque_fid = p_vf->opaque_fid;
1712 params.vport_id = p_vf->vport_id;
1713 params.update_anti_spoofing_en_flg = 1;
1714 params.anti_spoofing_en = val;
1716 rc = ecore_sp_vport_update(p_hwfn, ¶ms, ECORE_SPQ_MODE_EBLOCK,
1718 if (rc == ECORE_SUCCESS) {
1719 p_vf->spoof_chk = val;
1720 p_vf->req_spoofchk_val = p_vf->spoof_chk;
1721 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1722 "Spoofchk val[%d] configured\n", val);
1724 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1725 "Spoofchk configuration[val:%d] failed for VF[%d]\n",
1726 val, p_vf->relative_vf_id);
1732 static enum _ecore_status_t
1733 ecore_iov_reconfigure_unicast_vlan(struct ecore_hwfn *p_hwfn,
1734 struct ecore_vf_info *p_vf)
1736 struct ecore_filter_ucast filter;
1737 enum _ecore_status_t rc = ECORE_SUCCESS;
1740 OSAL_MEMSET(&filter, 0, sizeof(filter));
1741 filter.is_rx_filter = 1;
1742 filter.is_tx_filter = 1;
1743 filter.vport_to_add_to = p_vf->vport_id;
1744 filter.opcode = ECORE_FILTER_ADD;
1746 /* Reconfigure vlans */
1747 for (i = 0; i < ECORE_ETH_VF_NUM_VLAN_FILTERS + 1; i++) {
1748 if (!p_vf->shadow_config.vlans[i].used)
1751 filter.type = ECORE_FILTER_VLAN;
1752 filter.vlan = p_vf->shadow_config.vlans[i].vid;
1753 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1754 "Reconfiguring VLAN [0x%04x] for VF [%04x]\n",
1755 filter.vlan, p_vf->relative_vf_id);
1756 rc = ecore_sp_eth_filter_ucast(p_hwfn, p_vf->opaque_fid,
1757 &filter, ECORE_SPQ_MODE_CB,
1760 DP_NOTICE(p_hwfn, true,
1761 "Failed to configure VLAN [%04x]"
1763 filter.vlan, p_vf->relative_vf_id);
1771 static enum _ecore_status_t
1772 ecore_iov_reconfigure_unicast_shadow(struct ecore_hwfn *p_hwfn,
1773 struct ecore_vf_info *p_vf, u64 events)
1775 enum _ecore_status_t rc = ECORE_SUCCESS;
1777 /*TODO - what about MACs? */
1779 if ((events & (1 << VLAN_ADDR_FORCED)) &&
1780 !(p_vf->configured_features & (1 << VLAN_ADDR_FORCED)))
1781 rc = ecore_iov_reconfigure_unicast_vlan(p_hwfn, p_vf);
1786 static enum _ecore_status_t
1787 ecore_iov_configure_vport_forced(struct ecore_hwfn *p_hwfn,
1788 struct ecore_vf_info *p_vf,
1791 enum _ecore_status_t rc = ECORE_SUCCESS;
1792 struct ecore_filter_ucast filter;
1794 if (!p_vf->vport_instance)
1797 if (events & (1 << MAC_ADDR_FORCED)) {
1798 /* Since there's no way [currently] of removing the MAC,
1799 * we can always assume this means we need to force it.
1801 OSAL_MEMSET(&filter, 0, sizeof(filter));
1802 filter.type = ECORE_FILTER_MAC;
1803 filter.opcode = ECORE_FILTER_REPLACE;
1804 filter.is_rx_filter = 1;
1805 filter.is_tx_filter = 1;
1806 filter.vport_to_add_to = p_vf->vport_id;
1807 OSAL_MEMCPY(filter.mac, p_vf->bulletin.p_virt->mac, ETH_ALEN);
1809 rc = ecore_sp_eth_filter_ucast(p_hwfn, p_vf->opaque_fid,
1811 ECORE_SPQ_MODE_CB, OSAL_NULL);
1813 DP_NOTICE(p_hwfn, true,
1814 "PF failed to configure MAC for VF\n");
1818 p_vf->configured_features |= 1 << MAC_ADDR_FORCED;
1821 if (events & (1 << VLAN_ADDR_FORCED)) {
1822 struct ecore_sp_vport_update_params vport_update;
1826 OSAL_MEMSET(&filter, 0, sizeof(filter));
1827 filter.type = ECORE_FILTER_VLAN;
1828 filter.is_rx_filter = 1;
1829 filter.is_tx_filter = 1;
1830 filter.vport_to_add_to = p_vf->vport_id;
1831 filter.vlan = p_vf->bulletin.p_virt->pvid;
1832 filter.opcode = filter.vlan ? ECORE_FILTER_REPLACE :
1835 /* Send the ramrod */
1836 rc = ecore_sp_eth_filter_ucast(p_hwfn, p_vf->opaque_fid,
1838 ECORE_SPQ_MODE_CB, OSAL_NULL);
1840 DP_NOTICE(p_hwfn, true,
1841 "PF failed to configure VLAN for VF\n");
1845 /* Update the default-vlan & silent vlan stripping */
1846 OSAL_MEMSET(&vport_update, 0, sizeof(vport_update));
1847 vport_update.opaque_fid = p_vf->opaque_fid;
1848 vport_update.vport_id = p_vf->vport_id;
1849 vport_update.update_default_vlan_enable_flg = 1;
1850 vport_update.default_vlan_enable_flg = filter.vlan ? 1 : 0;
1851 vport_update.update_default_vlan_flg = 1;
1852 vport_update.default_vlan = filter.vlan;
1854 vport_update.update_inner_vlan_removal_flg = 1;
1855 removal = filter.vlan ?
1856 1 : p_vf->shadow_config.inner_vlan_removal;
1857 vport_update.inner_vlan_removal_flg = removal;
1858 vport_update.silent_vlan_removal_flg = filter.vlan ? 1 : 0;
1859 rc = ecore_sp_vport_update(p_hwfn, &vport_update,
1860 ECORE_SPQ_MODE_EBLOCK, OSAL_NULL);
1862 DP_NOTICE(p_hwfn, true,
1863 "PF failed to configure VF vport for vlan\n");
1867 /* Update all the Rx queues */
1868 for (i = 0; i < ECORE_MAX_VF_CHAINS_PER_PF; i++) {
1869 struct ecore_queue_cid *p_cid;
1871 p_cid = p_vf->vf_queues[i].p_rx_cid;
1872 if (p_cid == OSAL_NULL)
1875 rc = ecore_sp_eth_rx_queues_update(p_hwfn,
1878 ECORE_SPQ_MODE_EBLOCK,
1881 DP_NOTICE(p_hwfn, true,
1882 "Failed to send Rx update"
1883 " fo queue[0x%04x]\n",
1884 p_cid->rel.queue_id);
1890 p_vf->configured_features |= 1 << VLAN_ADDR_FORCED;
1892 p_vf->configured_features &= ~(1 << VLAN_ADDR_FORCED);
1895 /* If forced features are terminated, we need to configure the shadow
1896 * configuration back again.
1899 ecore_iov_reconfigure_unicast_shadow(p_hwfn, p_vf, events);
1904 static void ecore_iov_vf_mbx_start_vport(struct ecore_hwfn *p_hwfn,
1905 struct ecore_ptt *p_ptt,
1906 struct ecore_vf_info *vf)
1908 struct ecore_sp_vport_start_params params = { 0 };
1909 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
1910 struct vfpf_vport_start_tlv *start;
1911 u8 status = PFVF_STATUS_SUCCESS;
1912 struct ecore_vf_info *vf_info;
1915 enum _ecore_status_t rc;
1917 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vf->relative_vf_id, true);
1919 DP_NOTICE(p_hwfn->p_dev, true,
1920 "Failed to get VF info, invalid vfid [%d]\n",
1921 vf->relative_vf_id);
1925 vf->state = VF_ENABLED;
1926 start = &mbx->req_virt->start_vport;
1928 /* Initialize Status block in CAU */
1929 for (sb_id = 0; sb_id < vf->num_sbs; sb_id++) {
1930 if (!start->sb_addr[sb_id]) {
1931 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1932 "VF[%d] did not fill the address of SB %d\n",
1933 vf->relative_vf_id, sb_id);
1937 ecore_int_cau_conf_sb(p_hwfn, p_ptt,
1938 start->sb_addr[sb_id],
1942 ecore_iov_enable_vf_traffic(p_hwfn, p_ptt, vf);
1944 vf->mtu = start->mtu;
1945 vf->shadow_config.inner_vlan_removal = start->inner_vlan_removal;
1947 /* Take into consideration configuration forced by hypervisor;
1948 * If none is configured, use the supplied VF values [for old
1949 * vfs that would still be fine, since they passed '0' as padding].
1951 p_bitmap = &vf_info->bulletin.p_virt->valid_bitmap;
1952 if (!(*p_bitmap & (1 << VFPF_BULLETIN_UNTAGGED_DEFAULT_FORCED))) {
1953 u8 vf_req = start->only_untagged;
1955 vf_info->bulletin.p_virt->default_only_untagged = vf_req;
1956 *p_bitmap |= 1 << VFPF_BULLETIN_UNTAGGED_DEFAULT;
1959 params.tpa_mode = start->tpa_mode;
1960 params.remove_inner_vlan = start->inner_vlan_removal;
1961 params.tx_switching = true;
1964 if (CHIP_REV_IS_FPGA(p_hwfn->p_dev)) {
1965 DP_NOTICE(p_hwfn, false,
1966 "FPGA: Don't config VF for Tx-switching [no pVFC]\n");
1967 params.tx_switching = false;
1971 params.only_untagged = vf_info->bulletin.p_virt->default_only_untagged;
1972 params.drop_ttl0 = false;
1973 params.concrete_fid = vf->concrete_fid;
1974 params.opaque_fid = vf->opaque_fid;
1975 params.vport_id = vf->vport_id;
1976 params.max_buffers_per_cqe = start->max_buffers_per_cqe;
1977 params.mtu = vf->mtu;
1978 params.check_mac = true;
1980 rc = ecore_sp_eth_vport_start(p_hwfn, ¶ms);
1981 if (rc != ECORE_SUCCESS) {
1983 "ecore_iov_vf_mbx_start_vport returned error %d\n", rc);
1984 status = PFVF_STATUS_FAILURE;
1986 vf->vport_instance++;
1988 /* Force configuration if needed on the newly opened vport */
1989 ecore_iov_configure_vport_forced(p_hwfn, vf, *p_bitmap);
1990 OSAL_IOV_POST_START_VPORT(p_hwfn, vf->relative_vf_id,
1991 vf->vport_id, vf->opaque_fid);
1992 __ecore_iov_spoofchk_set(p_hwfn, vf, vf->req_spoofchk_val);
1995 ecore_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_VPORT_START,
1996 sizeof(struct pfvf_def_resp_tlv), status);
1999 static void ecore_iov_vf_mbx_stop_vport(struct ecore_hwfn *p_hwfn,
2000 struct ecore_ptt *p_ptt,
2001 struct ecore_vf_info *vf)
2003 u8 status = PFVF_STATUS_SUCCESS;
2004 enum _ecore_status_t rc;
2006 vf->vport_instance--;
2007 vf->spoof_chk = false;
2009 if ((ecore_iov_validate_active_rxq(p_hwfn, vf)) ||
2010 (ecore_iov_validate_active_txq(p_hwfn, vf))) {
2011 vf->b_malicious = true;
2012 DP_NOTICE(p_hwfn, false,
2013 "VF [%02x] - considered malicious;"
2014 " Unable to stop RX/TX queuess\n",
2018 rc = ecore_sp_vport_stop(p_hwfn, vf->opaque_fid, vf->vport_id);
2019 if (rc != ECORE_SUCCESS) {
2021 "ecore_iov_vf_mbx_stop_vport returned error %d\n", rc);
2022 status = PFVF_STATUS_FAILURE;
2025 /* Forget the configuration on the vport */
2026 vf->configured_features = 0;
2027 OSAL_MEMSET(&vf->shadow_config, 0, sizeof(vf->shadow_config));
2029 ecore_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_VPORT_TEARDOWN,
2030 sizeof(struct pfvf_def_resp_tlv), status);
2033 static void ecore_iov_vf_mbx_start_rxq_resp(struct ecore_hwfn *p_hwfn,
2034 struct ecore_ptt *p_ptt,
2035 struct ecore_vf_info *vf,
2036 u8 status, bool b_legacy)
2038 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
2039 struct pfvf_start_queue_resp_tlv *p_tlv;
2040 struct vfpf_start_rxq_tlv *req;
2043 mbx->offset = (u8 *)mbx->reply_virt;
2045 /* Taking a bigger struct instead of adding a TLV to list was a
2046 * mistake, but one which we're now stuck with, as some older
2047 * clients assume the size of the previous response.
2050 length = sizeof(*p_tlv);
2052 length = sizeof(struct pfvf_def_resp_tlv);
2054 p_tlv = ecore_add_tlv(p_hwfn, &mbx->offset, CHANNEL_TLV_START_RXQ,
2056 ecore_add_tlv(p_hwfn, &mbx->offset, CHANNEL_TLV_LIST_END,
2057 sizeof(struct channel_list_end_tlv));
2059 /* Update the TLV with the response */
2060 if ((status == PFVF_STATUS_SUCCESS) && !b_legacy) {
2061 req = &mbx->req_virt->start_rxq;
2062 p_tlv->offset = PXP_VF_BAR0_START_MSDM_ZONE_B +
2063 OFFSETOF(struct mstorm_vf_zone,
2064 non_trigger.eth_rx_queue_producers) +
2065 sizeof(struct eth_rx_prod_data) * req->rx_qid;
2068 ecore_iov_send_response(p_hwfn, p_ptt, vf, length, status);
2071 static void ecore_iov_vf_mbx_start_rxq(struct ecore_hwfn *p_hwfn,
2072 struct ecore_ptt *p_ptt,
2073 struct ecore_vf_info *vf)
2075 struct ecore_queue_start_common_params params;
2076 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
2077 u8 status = PFVF_STATUS_NO_RESOURCE;
2078 struct ecore_vf_q_info *p_queue;
2079 struct vfpf_start_rxq_tlv *req;
2080 bool b_legacy_vf = false;
2081 enum _ecore_status_t rc;
2083 req = &mbx->req_virt->start_rxq;
2085 if (!ecore_iov_validate_rxq(p_hwfn, vf, req->rx_qid) ||
2086 !ecore_iov_validate_sb(p_hwfn, vf, req->hw_sb))
2089 /* Acquire a new queue-cid */
2090 p_queue = &vf->vf_queues[req->rx_qid];
2092 OSAL_MEMSET(¶ms, 0, sizeof(params));
2093 params.queue_id = (u8)p_queue->fw_rx_qid;
2094 params.vport_id = vf->vport_id;
2095 params.stats_id = vf->abs_vf_id + 0x10;
2096 params.sb = req->hw_sb;
2097 params.sb_idx = req->sb_index;
2099 p_queue->p_rx_cid = _ecore_eth_queue_to_cid(p_hwfn,
2104 if (p_queue->p_rx_cid == OSAL_NULL)
2107 /* Legacy VFs have their Producers in a different location, which they
2108 * calculate on their own and clean the producer prior to this.
2110 if (vf->acquire.vfdev_info.eth_fp_hsi_minor ==
2111 ETH_HSI_VER_NO_PKT_LEN_TUNN)
2115 GTT_BAR0_MAP_REG_MSDM_RAM +
2116 MSTORM_ETH_VF_PRODS_OFFSET(vf->abs_vf_id, req->rx_qid),
2118 p_queue->p_rx_cid->b_legacy_vf = b_legacy_vf;
2121 rc = ecore_eth_rxq_start_ramrod(p_hwfn,
2127 if (rc != ECORE_SUCCESS) {
2128 status = PFVF_STATUS_FAILURE;
2129 ecore_eth_queue_cid_release(p_hwfn, p_queue->p_rx_cid);
2130 p_queue->p_rx_cid = OSAL_NULL;
2132 status = PFVF_STATUS_SUCCESS;
2133 vf->num_active_rxqs++;
2137 ecore_iov_vf_mbx_start_rxq_resp(p_hwfn, p_ptt, vf, status,
2142 ecore_iov_pf_update_tun_response(struct pfvf_update_tunn_param_tlv *p_resp,
2143 struct ecore_tunnel_info *p_tun,
2144 u16 tunn_feature_mask)
2146 p_resp->tunn_feature_mask = tunn_feature_mask;
2147 p_resp->vxlan_mode = p_tun->vxlan.b_mode_enabled;
2148 p_resp->l2geneve_mode = p_tun->l2_geneve.b_mode_enabled;
2149 p_resp->ipgeneve_mode = p_tun->ip_geneve.b_mode_enabled;
2150 p_resp->l2gre_mode = p_tun->l2_gre.b_mode_enabled;
2151 p_resp->ipgre_mode = p_tun->l2_gre.b_mode_enabled;
2152 p_resp->vxlan_clss = p_tun->vxlan.tun_cls;
2153 p_resp->l2gre_clss = p_tun->l2_gre.tun_cls;
2154 p_resp->ipgre_clss = p_tun->ip_gre.tun_cls;
2155 p_resp->l2geneve_clss = p_tun->l2_geneve.tun_cls;
2156 p_resp->ipgeneve_clss = p_tun->ip_geneve.tun_cls;
2157 p_resp->geneve_udp_port = p_tun->geneve_port.port;
2158 p_resp->vxlan_udp_port = p_tun->vxlan_port.port;
2162 __ecore_iov_pf_update_tun_param(struct vfpf_update_tunn_param_tlv *p_req,
2163 struct ecore_tunn_update_type *p_tun,
2164 enum ecore_tunn_mode mask, u8 tun_cls)
2166 if (p_req->tun_mode_update_mask & (1 << mask)) {
2167 p_tun->b_update_mode = true;
2169 if (p_req->tunn_mode & (1 << mask))
2170 p_tun->b_mode_enabled = true;
2173 p_tun->tun_cls = tun_cls;
2177 ecore_iov_pf_update_tun_param(struct vfpf_update_tunn_param_tlv *p_req,
2178 struct ecore_tunn_update_type *p_tun,
2179 struct ecore_tunn_update_udp_port *p_port,
2180 enum ecore_tunn_mode mask,
2181 u8 tun_cls, u8 update_port, u16 port)
2184 p_port->b_update_port = true;
2185 p_port->port = port;
2188 __ecore_iov_pf_update_tun_param(p_req, p_tun, mask, tun_cls);
2192 ecore_iov_pf_validate_tunn_param(struct vfpf_update_tunn_param_tlv *p_req)
2194 bool b_update_requested = false;
2196 if (p_req->tun_mode_update_mask || p_req->update_tun_cls ||
2197 p_req->update_geneve_port || p_req->update_vxlan_port)
2198 b_update_requested = true;
2200 return b_update_requested;
2203 static void ecore_iov_vf_mbx_update_tunn_param(struct ecore_hwfn *p_hwfn,
2204 struct ecore_ptt *p_ptt,
2205 struct ecore_vf_info *p_vf)
2207 struct ecore_tunnel_info *p_tun = &p_hwfn->p_dev->tunnel;
2208 struct ecore_iov_vf_mbx *mbx = &p_vf->vf_mbx;
2209 struct pfvf_update_tunn_param_tlv *p_resp;
2210 struct vfpf_update_tunn_param_tlv *p_req;
2211 enum _ecore_status_t rc = ECORE_SUCCESS;
2212 u8 status = PFVF_STATUS_SUCCESS;
2213 bool b_update_required = false;
2214 struct ecore_tunnel_info tunn;
2215 u16 tunn_feature_mask = 0;
2217 mbx->offset = (u8 *)mbx->reply_virt;
2219 OSAL_MEM_ZERO(&tunn, sizeof(tunn));
2220 p_req = &mbx->req_virt->tunn_param_update;
2222 if (!ecore_iov_pf_validate_tunn_param(p_req)) {
2223 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2224 "No tunnel update requested by VF\n");
2225 status = PFVF_STATUS_FAILURE;
2229 tunn.b_update_rx_cls = p_req->update_tun_cls;
2230 tunn.b_update_tx_cls = p_req->update_tun_cls;
2232 ecore_iov_pf_update_tun_param(p_req, &tunn.vxlan, &tunn.vxlan_port,
2233 ECORE_MODE_VXLAN_TUNN, p_req->vxlan_clss,
2234 p_req->update_vxlan_port,
2236 ecore_iov_pf_update_tun_param(p_req, &tunn.l2_geneve, &tunn.geneve_port,
2237 ECORE_MODE_L2GENEVE_TUNN,
2238 p_req->l2geneve_clss,
2239 p_req->update_geneve_port,
2240 p_req->geneve_port);
2241 __ecore_iov_pf_update_tun_param(p_req, &tunn.ip_geneve,
2242 ECORE_MODE_IPGENEVE_TUNN,
2243 p_req->ipgeneve_clss);
2244 __ecore_iov_pf_update_tun_param(p_req, &tunn.l2_gre,
2245 ECORE_MODE_L2GRE_TUNN,
2247 __ecore_iov_pf_update_tun_param(p_req, &tunn.ip_gre,
2248 ECORE_MODE_IPGRE_TUNN,
2251 /* If PF modifies VF's req then it should
2252 * still return an error in case of partial configuration
2253 * or modified configuration as opposed to requested one.
2255 rc = OSAL_PF_VALIDATE_MODIFY_TUNN_CONFIG(p_hwfn, &tunn_feature_mask,
2256 &b_update_required, &tunn);
2258 if (rc != ECORE_SUCCESS)
2259 status = PFVF_STATUS_FAILURE;
2261 /* If ECORE client is willing to update anything ? */
2262 if (b_update_required) {
2263 rc = ecore_sp_pf_update_tunn_cfg(p_hwfn, &tunn,
2264 ECORE_SPQ_MODE_EBLOCK,
2266 if (rc != ECORE_SUCCESS)
2267 status = PFVF_STATUS_FAILURE;
2271 p_resp = ecore_add_tlv(p_hwfn, &mbx->offset,
2272 CHANNEL_TLV_UPDATE_TUNN_PARAM, sizeof(*p_resp));
2274 ecore_iov_pf_update_tun_response(p_resp, p_tun, tunn_feature_mask);
2275 ecore_add_tlv(p_hwfn, &mbx->offset, CHANNEL_TLV_LIST_END,
2276 sizeof(struct channel_list_end_tlv));
2278 ecore_iov_send_response(p_hwfn, p_ptt, p_vf, sizeof(*p_resp), status);
2281 static void ecore_iov_vf_mbx_start_txq_resp(struct ecore_hwfn *p_hwfn,
2282 struct ecore_ptt *p_ptt,
2283 struct ecore_vf_info *p_vf,
2286 struct ecore_iov_vf_mbx *mbx = &p_vf->vf_mbx;
2287 struct pfvf_start_queue_resp_tlv *p_tlv;
2288 bool b_legacy = false;
2291 mbx->offset = (u8 *)mbx->reply_virt;
2293 /* Taking a bigger struct instead of adding a TLV to list was a
2294 * mistake, but one which we're now stuck with, as some older
2295 * clients assume the size of the previous response.
2297 if (p_vf->acquire.vfdev_info.eth_fp_hsi_minor ==
2298 ETH_HSI_VER_NO_PKT_LEN_TUNN)
2302 length = sizeof(*p_tlv);
2304 length = sizeof(struct pfvf_def_resp_tlv);
2306 p_tlv = ecore_add_tlv(p_hwfn, &mbx->offset, CHANNEL_TLV_START_TXQ,
2308 ecore_add_tlv(p_hwfn, &mbx->offset, CHANNEL_TLV_LIST_END,
2309 sizeof(struct channel_list_end_tlv));
2311 /* Update the TLV with the response */
2312 if ((status == PFVF_STATUS_SUCCESS) && !b_legacy) {
2313 u16 qid = mbx->req_virt->start_txq.tx_qid;
2315 p_tlv->offset = DB_ADDR_VF(p_vf->vf_queues[qid].fw_cid,
2319 ecore_iov_send_response(p_hwfn, p_ptt, p_vf, length, status);
2322 static void ecore_iov_vf_mbx_start_txq(struct ecore_hwfn *p_hwfn,
2323 struct ecore_ptt *p_ptt,
2324 struct ecore_vf_info *vf)
2326 struct ecore_queue_start_common_params params;
2327 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
2328 u8 status = PFVF_STATUS_NO_RESOURCE;
2329 struct ecore_vf_q_info *p_queue;
2330 struct vfpf_start_txq_tlv *req;
2331 enum _ecore_status_t rc;
2334 OSAL_MEMSET(¶ms, 0, sizeof(params));
2335 req = &mbx->req_virt->start_txq;
2337 if (!ecore_iov_validate_txq(p_hwfn, vf, req->tx_qid) ||
2338 !ecore_iov_validate_sb(p_hwfn, vf, req->hw_sb))
2341 /* Acquire a new queue-cid */
2342 p_queue = &vf->vf_queues[req->tx_qid];
2344 params.queue_id = p_queue->fw_tx_qid;
2345 params.vport_id = vf->vport_id;
2346 params.stats_id = vf->abs_vf_id + 0x10;
2347 params.sb = req->hw_sb;
2348 params.sb_idx = req->sb_index;
2350 p_queue->p_tx_cid = _ecore_eth_queue_to_cid(p_hwfn,
2355 if (p_queue->p_tx_cid == OSAL_NULL)
2358 pq = ecore_get_cm_pq_idx_vf(p_hwfn,
2359 vf->relative_vf_id);
2360 rc = ecore_eth_txq_start_ramrod(p_hwfn, p_queue->p_tx_cid,
2361 req->pbl_addr, req->pbl_size, pq);
2362 if (rc != ECORE_SUCCESS) {
2363 status = PFVF_STATUS_FAILURE;
2364 ecore_eth_queue_cid_release(p_hwfn,
2366 p_queue->p_tx_cid = OSAL_NULL;
2368 status = PFVF_STATUS_SUCCESS;
2372 ecore_iov_vf_mbx_start_txq_resp(p_hwfn, p_ptt, vf, status);
2375 static enum _ecore_status_t ecore_iov_vf_stop_rxqs(struct ecore_hwfn *p_hwfn,
2376 struct ecore_vf_info *vf,
2379 bool cqe_completion)
2381 struct ecore_vf_q_info *p_queue;
2382 enum _ecore_status_t rc = ECORE_SUCCESS;
2385 if (rxq_id + num_rxqs > OSAL_ARRAY_SIZE(vf->vf_queues))
2388 for (qid = rxq_id; qid < rxq_id + num_rxqs; qid++) {
2389 p_queue = &vf->vf_queues[qid];
2391 if (!p_queue->p_rx_cid)
2394 rc = ecore_eth_rx_queue_stop(p_hwfn,
2396 false, cqe_completion);
2397 if (rc != ECORE_SUCCESS)
2400 vf->vf_queues[qid].p_rx_cid = OSAL_NULL;
2401 vf->num_active_rxqs--;
2407 static enum _ecore_status_t ecore_iov_vf_stop_txqs(struct ecore_hwfn *p_hwfn,
2408 struct ecore_vf_info *vf,
2409 u16 txq_id, u8 num_txqs)
2411 enum _ecore_status_t rc = ECORE_SUCCESS;
2412 struct ecore_vf_q_info *p_queue;
2415 if (txq_id + num_txqs > OSAL_ARRAY_SIZE(vf->vf_queues))
2418 for (qid = txq_id; qid < txq_id + num_txqs; qid++) {
2419 p_queue = &vf->vf_queues[qid];
2420 if (!p_queue->p_tx_cid)
2423 rc = ecore_eth_tx_queue_stop(p_hwfn,
2425 if (rc != ECORE_SUCCESS)
2428 p_queue->p_tx_cid = OSAL_NULL;
2433 static void ecore_iov_vf_mbx_stop_rxqs(struct ecore_hwfn *p_hwfn,
2434 struct ecore_ptt *p_ptt,
2435 struct ecore_vf_info *vf)
2437 u16 length = sizeof(struct pfvf_def_resp_tlv);
2438 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
2439 u8 status = PFVF_STATUS_SUCCESS;
2440 struct vfpf_stop_rxqs_tlv *req;
2441 enum _ecore_status_t rc;
2443 /* We give the option of starting from qid != 0, in this case we
2444 * need to make sure that qid + num_qs doesn't exceed the actual
2445 * amount of queues that exist.
2447 req = &mbx->req_virt->stop_rxqs;
2448 rc = ecore_iov_vf_stop_rxqs(p_hwfn, vf, req->rx_qid,
2449 req->num_rxqs, req->cqe_completion);
2451 status = PFVF_STATUS_FAILURE;
2453 ecore_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_STOP_RXQS,
2457 static void ecore_iov_vf_mbx_stop_txqs(struct ecore_hwfn *p_hwfn,
2458 struct ecore_ptt *p_ptt,
2459 struct ecore_vf_info *vf)
2461 u16 length = sizeof(struct pfvf_def_resp_tlv);
2462 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
2463 u8 status = PFVF_STATUS_SUCCESS;
2464 struct vfpf_stop_txqs_tlv *req;
2465 enum _ecore_status_t rc;
2467 /* We give the option of starting from qid != 0, in this case we
2468 * need to make sure that qid + num_qs doesn't exceed the actual
2469 * amount of queues that exist.
2471 req = &mbx->req_virt->stop_txqs;
2472 rc = ecore_iov_vf_stop_txqs(p_hwfn, vf, req->tx_qid, req->num_txqs);
2474 status = PFVF_STATUS_FAILURE;
2476 ecore_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_STOP_TXQS,
2480 static void ecore_iov_vf_mbx_update_rxqs(struct ecore_hwfn *p_hwfn,
2481 struct ecore_ptt *p_ptt,
2482 struct ecore_vf_info *vf)
2484 struct ecore_queue_cid *handlers[ECORE_MAX_VF_CHAINS_PER_PF];
2485 u16 length = sizeof(struct pfvf_def_resp_tlv);
2486 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
2487 struct vfpf_update_rxq_tlv *req;
2488 u8 status = PFVF_STATUS_FAILURE;
2489 u8 complete_event_flg;
2490 u8 complete_cqe_flg;
2492 enum _ecore_status_t rc;
2495 req = &mbx->req_virt->update_rxq;
2496 complete_cqe_flg = !!(req->flags & VFPF_RXQ_UPD_COMPLETE_CQE_FLAG);
2497 complete_event_flg = !!(req->flags & VFPF_RXQ_UPD_COMPLETE_EVENT_FLAG);
2499 /* Validaute inputs */
2500 if (req->num_rxqs + req->rx_qid > ECORE_MAX_VF_CHAINS_PER_PF ||
2501 !ecore_iov_validate_rxq(p_hwfn, vf, req->rx_qid)) {
2502 DP_INFO(p_hwfn, "VF[%d]: Incorrect Rxqs [%04x, %02x]\n",
2503 vf->relative_vf_id, req->rx_qid, req->num_rxqs);
2507 for (i = 0; i < req->num_rxqs; i++) {
2508 qid = req->rx_qid + i;
2510 if (!vf->vf_queues[qid].p_rx_cid) {
2512 "VF[%d] rx_qid = %d isn`t active!\n",
2513 vf->relative_vf_id, qid);
2517 handlers[i] = vf->vf_queues[qid].p_rx_cid;
2520 rc = ecore_sp_eth_rx_queues_update(p_hwfn, (void **)&handlers,
2524 ECORE_SPQ_MODE_EBLOCK,
2529 status = PFVF_STATUS_SUCCESS;
2531 ecore_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_UPDATE_RXQ,
2535 void *ecore_iov_search_list_tlvs(struct ecore_hwfn *p_hwfn,
2536 void *p_tlvs_list, u16 req_type)
2538 struct channel_tlv *p_tlv = (struct channel_tlv *)p_tlvs_list;
2542 if (!p_tlv->length) {
2543 DP_NOTICE(p_hwfn, true, "Zero length TLV found\n");
2547 if (p_tlv->type == req_type) {
2548 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2549 "Extended tlv type %s, length %d found\n",
2550 ecore_channel_tlvs_string[p_tlv->type],
2555 len += p_tlv->length;
2556 p_tlv = (struct channel_tlv *)((u8 *)p_tlv + p_tlv->length);
2558 if ((len + p_tlv->length) > TLV_BUFFER_SIZE) {
2559 DP_NOTICE(p_hwfn, true,
2560 "TLVs has overrun the buffer size\n");
2563 } while (p_tlv->type != CHANNEL_TLV_LIST_END);
2569 ecore_iov_vp_update_act_param(struct ecore_hwfn *p_hwfn,
2570 struct ecore_sp_vport_update_params *p_data,
2571 struct ecore_iov_vf_mbx *p_mbx, u16 *tlvs_mask)
2573 struct vfpf_vport_update_activate_tlv *p_act_tlv;
2574 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_ACTIVATE;
2576 p_act_tlv = (struct vfpf_vport_update_activate_tlv *)
2577 ecore_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
2581 p_data->update_vport_active_rx_flg = p_act_tlv->update_rx;
2582 p_data->vport_active_rx_flg = p_act_tlv->active_rx;
2583 p_data->update_vport_active_tx_flg = p_act_tlv->update_tx;
2584 p_data->vport_active_tx_flg = p_act_tlv->active_tx;
2585 *tlvs_mask |= 1 << ECORE_IOV_VP_UPDATE_ACTIVATE;
2589 ecore_iov_vp_update_vlan_param(struct ecore_hwfn *p_hwfn,
2590 struct ecore_sp_vport_update_params *p_data,
2591 struct ecore_vf_info *p_vf,
2592 struct ecore_iov_vf_mbx *p_mbx, u16 *tlvs_mask)
2594 struct vfpf_vport_update_vlan_strip_tlv *p_vlan_tlv;
2595 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_VLAN_STRIP;
2597 p_vlan_tlv = (struct vfpf_vport_update_vlan_strip_tlv *)
2598 ecore_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
2602 p_vf->shadow_config.inner_vlan_removal = p_vlan_tlv->remove_vlan;
2604 /* Ignore the VF request if we're forcing a vlan */
2605 if (!(p_vf->configured_features & (1 << VLAN_ADDR_FORCED))) {
2606 p_data->update_inner_vlan_removal_flg = 1;
2607 p_data->inner_vlan_removal_flg = p_vlan_tlv->remove_vlan;
2610 *tlvs_mask |= 1 << ECORE_IOV_VP_UPDATE_VLAN_STRIP;
2614 ecore_iov_vp_update_tx_switch(struct ecore_hwfn *p_hwfn,
2615 struct ecore_sp_vport_update_params *p_data,
2616 struct ecore_iov_vf_mbx *p_mbx, u16 *tlvs_mask)
2618 struct vfpf_vport_update_tx_switch_tlv *p_tx_switch_tlv;
2619 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_TX_SWITCH;
2621 p_tx_switch_tlv = (struct vfpf_vport_update_tx_switch_tlv *)
2622 ecore_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
2623 if (!p_tx_switch_tlv)
2627 if (CHIP_REV_IS_FPGA(p_hwfn->p_dev)) {
2628 DP_NOTICE(p_hwfn, false,
2629 "FPGA: Ignore tx-switching configuration originating"
2635 p_data->update_tx_switching_flg = 1;
2636 p_data->tx_switching_flg = p_tx_switch_tlv->tx_switching;
2637 *tlvs_mask |= 1 << ECORE_IOV_VP_UPDATE_TX_SWITCH;
2641 ecore_iov_vp_update_mcast_bin_param(struct ecore_hwfn *p_hwfn,
2642 struct ecore_sp_vport_update_params *p_data,
2643 struct ecore_iov_vf_mbx *p_mbx,
2646 struct vfpf_vport_update_mcast_bin_tlv *p_mcast_tlv;
2647 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_MCAST;
2649 p_mcast_tlv = (struct vfpf_vport_update_mcast_bin_tlv *)
2650 ecore_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
2654 p_data->update_approx_mcast_flg = 1;
2655 OSAL_MEMCPY(p_data->bins, p_mcast_tlv->bins,
2656 sizeof(unsigned long) *
2657 ETH_MULTICAST_MAC_BINS_IN_REGS);
2658 *tlvs_mask |= 1 << ECORE_IOV_VP_UPDATE_MCAST;
2662 ecore_iov_vp_update_accept_flag(struct ecore_hwfn *p_hwfn,
2663 struct ecore_sp_vport_update_params *p_data,
2664 struct ecore_iov_vf_mbx *p_mbx, u16 *tlvs_mask)
2666 struct ecore_filter_accept_flags *p_flags = &p_data->accept_flags;
2667 struct vfpf_vport_update_accept_param_tlv *p_accept_tlv;
2668 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_ACCEPT_PARAM;
2670 p_accept_tlv = (struct vfpf_vport_update_accept_param_tlv *)
2671 ecore_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
2675 p_flags->update_rx_mode_config = p_accept_tlv->update_rx_mode;
2676 p_flags->rx_accept_filter = p_accept_tlv->rx_accept_filter;
2677 p_flags->update_tx_mode_config = p_accept_tlv->update_tx_mode;
2678 p_flags->tx_accept_filter = p_accept_tlv->tx_accept_filter;
2679 *tlvs_mask |= 1 << ECORE_IOV_VP_UPDATE_ACCEPT_PARAM;
2683 ecore_iov_vp_update_accept_any_vlan(struct ecore_hwfn *p_hwfn,
2684 struct ecore_sp_vport_update_params *p_data,
2685 struct ecore_iov_vf_mbx *p_mbx,
2688 struct vfpf_vport_update_accept_any_vlan_tlv *p_accept_any_vlan;
2689 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_ACCEPT_ANY_VLAN;
2691 p_accept_any_vlan = (struct vfpf_vport_update_accept_any_vlan_tlv *)
2692 ecore_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
2693 if (!p_accept_any_vlan)
2696 p_data->accept_any_vlan = p_accept_any_vlan->accept_any_vlan;
2697 p_data->update_accept_any_vlan_flg =
2698 p_accept_any_vlan->update_accept_any_vlan_flg;
2699 *tlvs_mask |= 1 << ECORE_IOV_VP_UPDATE_ACCEPT_ANY_VLAN;
2703 ecore_iov_vp_update_rss_param(struct ecore_hwfn *p_hwfn,
2704 struct ecore_vf_info *vf,
2705 struct ecore_sp_vport_update_params *p_data,
2706 struct ecore_rss_params *p_rss,
2707 struct ecore_iov_vf_mbx *p_mbx,
2708 u16 *tlvs_mask, u16 *tlvs_accepted)
2710 struct vfpf_vport_update_rss_tlv *p_rss_tlv;
2711 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_RSS;
2712 bool b_reject = false;
2716 p_rss_tlv = (struct vfpf_vport_update_rss_tlv *)
2717 ecore_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
2719 p_data->rss_params = OSAL_NULL;
2723 OSAL_MEMSET(p_rss, 0, sizeof(struct ecore_rss_params));
2725 p_rss->update_rss_config =
2726 !!(p_rss_tlv->update_rss_flags &
2727 VFPF_UPDATE_RSS_CONFIG_FLAG);
2728 p_rss->update_rss_capabilities =
2729 !!(p_rss_tlv->update_rss_flags &
2730 VFPF_UPDATE_RSS_CAPS_FLAG);
2731 p_rss->update_rss_ind_table =
2732 !!(p_rss_tlv->update_rss_flags &
2733 VFPF_UPDATE_RSS_IND_TABLE_FLAG);
2734 p_rss->update_rss_key =
2735 !!(p_rss_tlv->update_rss_flags &
2736 VFPF_UPDATE_RSS_KEY_FLAG);
2738 p_rss->rss_enable = p_rss_tlv->rss_enable;
2739 p_rss->rss_eng_id = vf->relative_vf_id + 1;
2740 p_rss->rss_caps = p_rss_tlv->rss_caps;
2741 p_rss->rss_table_size_log = p_rss_tlv->rss_table_size_log;
2742 OSAL_MEMCPY(p_rss->rss_key, p_rss_tlv->rss_key,
2743 sizeof(p_rss->rss_key));
2745 table_size = OSAL_MIN_T(u16, OSAL_ARRAY_SIZE(p_rss->rss_ind_table),
2746 (1 << p_rss_tlv->rss_table_size_log));
2748 for (i = 0; i < table_size; i++) {
2749 q_idx = p_rss_tlv->rss_ind_table[i];
2750 if (!ecore_iov_validate_rxq(p_hwfn, vf, q_idx)) {
2751 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2752 "VF[%d]: Omitting RSS due to wrong queue %04x\n",
2753 vf->relative_vf_id, q_idx);
2758 if (!vf->vf_queues[q_idx].p_rx_cid) {
2759 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2760 "VF[%d]: Omitting RSS due to inactive queue %08x\n",
2761 vf->relative_vf_id, q_idx);
2766 p_rss->rss_ind_table[i] = vf->vf_queues[q_idx].p_rx_cid;
2769 p_data->rss_params = p_rss;
2771 *tlvs_mask |= 1 << ECORE_IOV_VP_UPDATE_RSS;
2773 *tlvs_accepted |= 1 << ECORE_IOV_VP_UPDATE_RSS;
2777 ecore_iov_vp_update_sge_tpa_param(struct ecore_hwfn *p_hwfn,
2778 struct ecore_vf_info *vf,
2779 struct ecore_sp_vport_update_params *p_data,
2780 struct ecore_sge_tpa_params *p_sge_tpa,
2781 struct ecore_iov_vf_mbx *p_mbx,
2784 struct vfpf_vport_update_sge_tpa_tlv *p_sge_tpa_tlv;
2785 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_SGE_TPA;
2787 p_sge_tpa_tlv = (struct vfpf_vport_update_sge_tpa_tlv *)
2788 ecore_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
2790 if (!p_sge_tpa_tlv) {
2791 p_data->sge_tpa_params = OSAL_NULL;
2795 OSAL_MEMSET(p_sge_tpa, 0, sizeof(struct ecore_sge_tpa_params));
2797 p_sge_tpa->update_tpa_en_flg =
2798 !!(p_sge_tpa_tlv->update_sge_tpa_flags & VFPF_UPDATE_TPA_EN_FLAG);
2799 p_sge_tpa->update_tpa_param_flg =
2800 !!(p_sge_tpa_tlv->update_sge_tpa_flags &
2801 VFPF_UPDATE_TPA_PARAM_FLAG);
2803 p_sge_tpa->tpa_ipv4_en_flg =
2804 !!(p_sge_tpa_tlv->sge_tpa_flags & VFPF_TPA_IPV4_EN_FLAG);
2805 p_sge_tpa->tpa_ipv6_en_flg =
2806 !!(p_sge_tpa_tlv->sge_tpa_flags & VFPF_TPA_IPV6_EN_FLAG);
2807 p_sge_tpa->tpa_pkt_split_flg =
2808 !!(p_sge_tpa_tlv->sge_tpa_flags & VFPF_TPA_PKT_SPLIT_FLAG);
2809 p_sge_tpa->tpa_hdr_data_split_flg =
2810 !!(p_sge_tpa_tlv->sge_tpa_flags & VFPF_TPA_HDR_DATA_SPLIT_FLAG);
2811 p_sge_tpa->tpa_gro_consistent_flg =
2812 !!(p_sge_tpa_tlv->sge_tpa_flags & VFPF_TPA_GRO_CONSIST_FLAG);
2814 p_sge_tpa->tpa_max_aggs_num = p_sge_tpa_tlv->tpa_max_aggs_num;
2815 p_sge_tpa->tpa_max_size = p_sge_tpa_tlv->tpa_max_size;
2816 p_sge_tpa->tpa_min_size_to_start = p_sge_tpa_tlv->tpa_min_size_to_start;
2817 p_sge_tpa->tpa_min_size_to_cont = p_sge_tpa_tlv->tpa_min_size_to_cont;
2818 p_sge_tpa->max_buffers_per_cqe = p_sge_tpa_tlv->max_buffers_per_cqe;
2820 p_data->sge_tpa_params = p_sge_tpa;
2822 *tlvs_mask |= 1 << ECORE_IOV_VP_UPDATE_SGE_TPA;
2825 static void ecore_iov_vf_mbx_vport_update(struct ecore_hwfn *p_hwfn,
2826 struct ecore_ptt *p_ptt,
2827 struct ecore_vf_info *vf)
2829 struct ecore_rss_params *p_rss_params = OSAL_NULL;
2830 struct ecore_sp_vport_update_params params;
2831 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
2832 struct ecore_sge_tpa_params sge_tpa_params;
2833 u16 tlvs_mask = 0, tlvs_accepted = 0;
2834 u8 status = PFVF_STATUS_SUCCESS;
2836 enum _ecore_status_t rc;
2838 /* Valiate PF can send such a request */
2839 if (!vf->vport_instance) {
2840 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2841 "No VPORT instance available for VF[%d],"
2842 " failing vport update\n",
2844 status = PFVF_STATUS_FAILURE;
2848 p_rss_params = OSAL_VZALLOC(p_hwfn->p_dev, sizeof(*p_rss_params));
2849 if (p_rss_params == OSAL_NULL) {
2850 status = PFVF_STATUS_FAILURE;
2854 OSAL_MEMSET(¶ms, 0, sizeof(params));
2855 params.opaque_fid = vf->opaque_fid;
2856 params.vport_id = vf->vport_id;
2857 params.rss_params = OSAL_NULL;
2859 /* Search for extended tlvs list and update values
2860 * from VF in struct ecore_sp_vport_update_params.
2862 ecore_iov_vp_update_act_param(p_hwfn, ¶ms, mbx, &tlvs_mask);
2863 ecore_iov_vp_update_vlan_param(p_hwfn, ¶ms, vf, mbx, &tlvs_mask);
2864 ecore_iov_vp_update_tx_switch(p_hwfn, ¶ms, mbx, &tlvs_mask);
2865 ecore_iov_vp_update_mcast_bin_param(p_hwfn, ¶ms, mbx, &tlvs_mask);
2866 ecore_iov_vp_update_accept_flag(p_hwfn, ¶ms, mbx, &tlvs_mask);
2867 ecore_iov_vp_update_accept_any_vlan(p_hwfn, ¶ms, mbx, &tlvs_mask);
2868 ecore_iov_vp_update_sge_tpa_param(p_hwfn, vf, ¶ms,
2869 &sge_tpa_params, mbx, &tlvs_mask);
2871 tlvs_accepted = tlvs_mask;
2873 /* Some of the extended TLVs need to be validated first; In that case,
2874 * they can update the mask without updating the accepted [so that
2875 * PF could communicate to VF it has rejected request].
2877 ecore_iov_vp_update_rss_param(p_hwfn, vf, ¶ms, p_rss_params,
2878 mbx, &tlvs_mask, &tlvs_accepted);
2880 /* Just log a message if there is no single extended tlv in buffer.
2881 * When all features of vport update ramrod would be requested by VF
2882 * as extended TLVs in buffer then an error can be returned in response
2883 * if there is no extended TLV present in buffer.
2885 if (OSAL_IOV_VF_VPORT_UPDATE(p_hwfn, vf->relative_vf_id,
2886 ¶ms, &tlvs_accepted) !=
2889 status = PFVF_STATUS_NOT_SUPPORTED;
2893 if (!tlvs_accepted) {
2895 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2896 "Upper-layer prevents said VF"
2897 " configuration\n");
2899 DP_NOTICE(p_hwfn, true,
2900 "No feature tlvs found for vport update\n");
2901 status = PFVF_STATUS_NOT_SUPPORTED;
2905 rc = ecore_sp_vport_update(p_hwfn, ¶ms, ECORE_SPQ_MODE_EBLOCK,
2909 status = PFVF_STATUS_FAILURE;
2912 OSAL_VFREE(p_hwfn->p_dev, p_rss_params);
2913 length = ecore_iov_prep_vp_update_resp_tlvs(p_hwfn, vf, mbx, status,
2914 tlvs_mask, tlvs_accepted);
2915 ecore_iov_send_response(p_hwfn, p_ptt, vf, length, status);
2918 static enum _ecore_status_t
2919 ecore_iov_vf_update_vlan_shadow(struct ecore_hwfn *p_hwfn,
2920 struct ecore_vf_info *p_vf,
2921 struct ecore_filter_ucast *p_params)
2925 /* First remove entries and then add new ones */
2926 if (p_params->opcode == ECORE_FILTER_REMOVE) {
2927 for (i = 0; i < ECORE_ETH_VF_NUM_VLAN_FILTERS + 1; i++)
2928 if (p_vf->shadow_config.vlans[i].used &&
2929 p_vf->shadow_config.vlans[i].vid ==
2931 p_vf->shadow_config.vlans[i].used = false;
2934 if (i == ECORE_ETH_VF_NUM_VLAN_FILTERS + 1) {
2935 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2936 "VF [%d] - Tries to remove a non-existing"
2938 p_vf->relative_vf_id);
2941 } else if (p_params->opcode == ECORE_FILTER_REPLACE ||
2942 p_params->opcode == ECORE_FILTER_FLUSH) {
2943 for (i = 0; i < ECORE_ETH_VF_NUM_VLAN_FILTERS + 1; i++)
2944 p_vf->shadow_config.vlans[i].used = false;
2947 /* In forced mode, we're willing to remove entries - but we don't add
2950 if (p_vf->bulletin.p_virt->valid_bitmap & (1 << VLAN_ADDR_FORCED))
2951 return ECORE_SUCCESS;
2953 if (p_params->opcode == ECORE_FILTER_ADD ||
2954 p_params->opcode == ECORE_FILTER_REPLACE) {
2955 for (i = 0; i < ECORE_ETH_VF_NUM_VLAN_FILTERS + 1; i++) {
2956 if (p_vf->shadow_config.vlans[i].used)
2959 p_vf->shadow_config.vlans[i].used = true;
2960 p_vf->shadow_config.vlans[i].vid = p_params->vlan;
2964 if (i == ECORE_ETH_VF_NUM_VLAN_FILTERS + 1) {
2965 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2966 "VF [%d] - Tries to configure more than %d"
2968 p_vf->relative_vf_id,
2969 ECORE_ETH_VF_NUM_VLAN_FILTERS + 1);
2974 return ECORE_SUCCESS;
2977 static enum _ecore_status_t
2978 ecore_iov_vf_update_mac_shadow(struct ecore_hwfn *p_hwfn,
2979 struct ecore_vf_info *p_vf,
2980 struct ecore_filter_ucast *p_params)
2982 char empty_mac[ETH_ALEN];
2985 OSAL_MEM_ZERO(empty_mac, ETH_ALEN);
2987 /* If we're in forced-mode, we don't allow any change */
2988 /* TODO - this would change if we were ever to implement logic for
2989 * removing a forced MAC altogether [in which case, like for vlans,
2990 * we should be able to re-trace previous configuration.
2992 if (p_vf->bulletin.p_virt->valid_bitmap & (1 << MAC_ADDR_FORCED))
2993 return ECORE_SUCCESS;
2995 /* First remove entries and then add new ones */
2996 if (p_params->opcode == ECORE_FILTER_REMOVE) {
2997 for (i = 0; i < ECORE_ETH_VF_NUM_MAC_FILTERS; i++) {
2998 if (!OSAL_MEMCMP(p_vf->shadow_config.macs[i],
2999 p_params->mac, ETH_ALEN)) {
3000 OSAL_MEM_ZERO(p_vf->shadow_config.macs[i],
3006 if (i == ECORE_ETH_VF_NUM_MAC_FILTERS) {
3007 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3008 "MAC isn't configured\n");
3011 } else if (p_params->opcode == ECORE_FILTER_REPLACE ||
3012 p_params->opcode == ECORE_FILTER_FLUSH) {
3013 for (i = 0; i < ECORE_ETH_VF_NUM_MAC_FILTERS; i++)
3014 OSAL_MEM_ZERO(p_vf->shadow_config.macs[i], ETH_ALEN);
3017 /* List the new MAC address */
3018 if (p_params->opcode != ECORE_FILTER_ADD &&
3019 p_params->opcode != ECORE_FILTER_REPLACE)
3020 return ECORE_SUCCESS;
3022 for (i = 0; i < ECORE_ETH_VF_NUM_MAC_FILTERS; i++) {
3023 if (!OSAL_MEMCMP(p_vf->shadow_config.macs[i],
3024 empty_mac, ETH_ALEN)) {
3025 OSAL_MEMCPY(p_vf->shadow_config.macs[i],
3026 p_params->mac, ETH_ALEN);
3027 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3028 "Added MAC at %d entry in shadow\n", i);
3033 if (i == ECORE_ETH_VF_NUM_MAC_FILTERS) {
3034 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3035 "No available place for MAC\n");
3039 return ECORE_SUCCESS;
3042 static enum _ecore_status_t
3043 ecore_iov_vf_update_unicast_shadow(struct ecore_hwfn *p_hwfn,
3044 struct ecore_vf_info *p_vf,
3045 struct ecore_filter_ucast *p_params)
3047 enum _ecore_status_t rc = ECORE_SUCCESS;
3049 if (p_params->type == ECORE_FILTER_MAC) {
3050 rc = ecore_iov_vf_update_mac_shadow(p_hwfn, p_vf, p_params);
3051 if (rc != ECORE_SUCCESS)
3055 if (p_params->type == ECORE_FILTER_VLAN)
3056 rc = ecore_iov_vf_update_vlan_shadow(p_hwfn, p_vf, p_params);
3061 static void ecore_iov_vf_mbx_ucast_filter(struct ecore_hwfn *p_hwfn,
3062 struct ecore_ptt *p_ptt,
3063 struct ecore_vf_info *vf)
3065 struct ecore_bulletin_content *p_bulletin = vf->bulletin.p_virt;
3066 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
3067 struct vfpf_ucast_filter_tlv *req;
3068 u8 status = PFVF_STATUS_SUCCESS;
3069 struct ecore_filter_ucast params;
3070 enum _ecore_status_t rc;
3072 /* Prepare the unicast filter params */
3073 OSAL_MEMSET(¶ms, 0, sizeof(struct ecore_filter_ucast));
3074 req = &mbx->req_virt->ucast_filter;
3075 params.opcode = (enum ecore_filter_opcode)req->opcode;
3076 params.type = (enum ecore_filter_ucast_type)req->type;
3078 /* @@@TBD - We might need logic on HV side in determining this */
3079 params.is_rx_filter = 1;
3080 params.is_tx_filter = 1;
3081 params.vport_to_remove_from = vf->vport_id;
3082 params.vport_to_add_to = vf->vport_id;
3083 OSAL_MEMCPY(params.mac, req->mac, ETH_ALEN);
3084 params.vlan = req->vlan;
3086 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3087 "VF[%d]: opcode 0x%02x type 0x%02x [%s %s] [vport 0x%02x]"
3088 " MAC %02x:%02x:%02x:%02x:%02x:%02x, vlan 0x%04x\n",
3089 vf->abs_vf_id, params.opcode, params.type,
3090 params.is_rx_filter ? "RX" : "",
3091 params.is_tx_filter ? "TX" : "",
3092 params.vport_to_add_to,
3093 params.mac[0], params.mac[1], params.mac[2],
3094 params.mac[3], params.mac[4], params.mac[5], params.vlan);
3096 if (!vf->vport_instance) {
3097 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3098 "No VPORT instance available for VF[%d],"
3099 " failing ucast MAC configuration\n",
3101 status = PFVF_STATUS_FAILURE;
3105 /* Update shadow copy of the VF configuration */
3106 if (ecore_iov_vf_update_unicast_shadow(p_hwfn, vf, ¶ms) !=
3108 status = PFVF_STATUS_FAILURE;
3112 /* Determine if the unicast filtering is acceptible by PF */
3113 if ((p_bulletin->valid_bitmap & (1 << VLAN_ADDR_FORCED)) &&
3114 (params.type == ECORE_FILTER_VLAN ||
3115 params.type == ECORE_FILTER_MAC_VLAN)) {
3116 /* Once VLAN is forced or PVID is set, do not allow
3117 * to add/replace any further VLANs.
3119 if (params.opcode == ECORE_FILTER_ADD ||
3120 params.opcode == ECORE_FILTER_REPLACE)
3121 status = PFVF_STATUS_FORCED;
3125 if ((p_bulletin->valid_bitmap & (1 << MAC_ADDR_FORCED)) &&
3126 (params.type == ECORE_FILTER_MAC ||
3127 params.type == ECORE_FILTER_MAC_VLAN)) {
3128 if (OSAL_MEMCMP(p_bulletin->mac, params.mac, ETH_ALEN) ||
3129 (params.opcode != ECORE_FILTER_ADD &&
3130 params.opcode != ECORE_FILTER_REPLACE))
3131 status = PFVF_STATUS_FORCED;
3135 rc = OSAL_IOV_CHK_UCAST(p_hwfn, vf->relative_vf_id, ¶ms);
3136 if (rc == ECORE_EXISTS) {
3138 } else if (rc == ECORE_INVAL) {
3139 status = PFVF_STATUS_FAILURE;
3143 rc = ecore_sp_eth_filter_ucast(p_hwfn, vf->opaque_fid, ¶ms,
3144 ECORE_SPQ_MODE_CB, OSAL_NULL);
3146 status = PFVF_STATUS_FAILURE;
3149 ecore_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_UCAST_FILTER,
3150 sizeof(struct pfvf_def_resp_tlv), status);
3153 static void ecore_iov_vf_mbx_int_cleanup(struct ecore_hwfn *p_hwfn,
3154 struct ecore_ptt *p_ptt,
3155 struct ecore_vf_info *vf)
3160 for (i = 0; i < vf->num_sbs; i++)
3161 ecore_int_igu_init_pure_rt_single(p_hwfn, p_ptt,
3163 vf->opaque_fid, false);
3165 ecore_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_INT_CLEANUP,
3166 sizeof(struct pfvf_def_resp_tlv),
3167 PFVF_STATUS_SUCCESS);
3170 static void ecore_iov_vf_mbx_close(struct ecore_hwfn *p_hwfn,
3171 struct ecore_ptt *p_ptt,
3172 struct ecore_vf_info *vf)
3174 u16 length = sizeof(struct pfvf_def_resp_tlv);
3175 u8 status = PFVF_STATUS_SUCCESS;
3177 /* Disable Interrupts for VF */
3178 ecore_iov_vf_igu_set_int(p_hwfn, p_ptt, vf, 0);
3180 /* Reset Permission table */
3181 ecore_iov_config_perm_table(p_hwfn, p_ptt, vf, 0);
3183 ecore_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_CLOSE,
3187 static void ecore_iov_vf_mbx_release(struct ecore_hwfn *p_hwfn,
3188 struct ecore_ptt *p_ptt,
3189 struct ecore_vf_info *p_vf)
3191 u16 length = sizeof(struct pfvf_def_resp_tlv);
3192 u8 status = PFVF_STATUS_SUCCESS;
3193 enum _ecore_status_t rc = ECORE_SUCCESS;
3195 ecore_iov_vf_cleanup(p_hwfn, p_vf);
3197 if (p_vf->state != VF_STOPPED && p_vf->state != VF_FREE) {
3198 /* Stopping the VF */
3199 rc = ecore_sp_vf_stop(p_hwfn, p_vf->concrete_fid,
3202 if (rc != ECORE_SUCCESS) {
3203 DP_ERR(p_hwfn, "ecore_sp_vf_stop returned error %d\n",
3205 status = PFVF_STATUS_FAILURE;
3208 p_vf->state = VF_STOPPED;
3211 ecore_iov_prepare_resp(p_hwfn, p_ptt, p_vf, CHANNEL_TLV_RELEASE,
3215 static enum _ecore_status_t
3216 ecore_iov_vf_flr_poll_dorq(struct ecore_hwfn *p_hwfn,
3217 struct ecore_vf_info *p_vf, struct ecore_ptt *p_ptt)
3222 ecore_fid_pretend(p_hwfn, p_ptt, (u16)p_vf->concrete_fid);
3224 for (cnt = 0; cnt < 50; cnt++) {
3225 val = ecore_rd(p_hwfn, p_ptt, DORQ_REG_VF_USAGE_CNT);
3230 ecore_fid_pretend(p_hwfn, p_ptt, (u16)p_hwfn->hw_info.concrete_fid);
3234 "VF[%d] - dorq failed to cleanup [usage 0x%08x]\n",
3235 p_vf->abs_vf_id, val);
3236 return ECORE_TIMEOUT;
3239 return ECORE_SUCCESS;
3242 static enum _ecore_status_t
3243 ecore_iov_vf_flr_poll_pbf(struct ecore_hwfn *p_hwfn,
3244 struct ecore_vf_info *p_vf, struct ecore_ptt *p_ptt)
3246 u32 cons[MAX_NUM_VOQS], distance[MAX_NUM_VOQS];
3249 /* Read initial consumers & producers */
3250 for (i = 0; i < MAX_NUM_VOQS; i++) {
3253 cons[i] = ecore_rd(p_hwfn, p_ptt,
3254 PBF_REG_NUM_BLOCKS_ALLOCATED_CONS_VOQ0 +
3256 prod = ecore_rd(p_hwfn, p_ptt,
3257 PBF_REG_NUM_BLOCKS_ALLOCATED_PROD_VOQ0 +
3259 distance[i] = prod - cons[i];
3262 /* Wait for consumers to pass the producers */
3264 for (cnt = 0; cnt < 50; cnt++) {
3265 for (; i < MAX_NUM_VOQS; i++) {
3268 tmp = ecore_rd(p_hwfn, p_ptt,
3269 PBF_REG_NUM_BLOCKS_ALLOCATED_CONS_VOQ0 +
3271 if (distance[i] > tmp - cons[i])
3275 if (i == MAX_NUM_VOQS)
3282 DP_ERR(p_hwfn, "VF[%d] - pbf polling failed on VOQ %d\n",
3283 p_vf->abs_vf_id, i);
3284 return ECORE_TIMEOUT;
3287 return ECORE_SUCCESS;
3290 static enum _ecore_status_t ecore_iov_vf_flr_poll(struct ecore_hwfn *p_hwfn,
3291 struct ecore_vf_info *p_vf,
3292 struct ecore_ptt *p_ptt)
3294 enum _ecore_status_t rc;
3296 /* TODO - add SRC and TM polling once we add storage IOV */
3298 rc = ecore_iov_vf_flr_poll_dorq(p_hwfn, p_vf, p_ptt);
3302 rc = ecore_iov_vf_flr_poll_pbf(p_hwfn, p_vf, p_ptt);
3306 return ECORE_SUCCESS;
3309 static enum _ecore_status_t
3310 ecore_iov_execute_vf_flr_cleanup(struct ecore_hwfn *p_hwfn,
3311 struct ecore_ptt *p_ptt,
3312 u16 rel_vf_id, u32 *ack_vfs)
3314 struct ecore_vf_info *p_vf;
3315 enum _ecore_status_t rc = ECORE_SUCCESS;
3317 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, false);
3319 return ECORE_SUCCESS;
3321 if (p_hwfn->pf_iov_info->pending_flr[rel_vf_id / 64] &
3322 (1ULL << (rel_vf_id % 64))) {
3323 u16 vfid = p_vf->abs_vf_id;
3325 /* TODO - should we lock channel? */
3327 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3328 "VF[%d] - Handling FLR\n", vfid);
3330 ecore_iov_vf_cleanup(p_hwfn, p_vf);
3332 /* If VF isn't active, no need for anything but SW */
3336 /* TODO - what to do in case of failure? */
3337 rc = ecore_iov_vf_flr_poll(p_hwfn, p_vf, p_ptt);
3338 if (rc != ECORE_SUCCESS)
3341 rc = ecore_final_cleanup(p_hwfn, p_ptt, vfid, true);
3343 /* TODO - what's now? What a mess.... */
3344 DP_ERR(p_hwfn, "Failed handle FLR of VF[%d]\n", vfid);
3348 /* Workaround to make VF-PF channel ready, as FW
3349 * doesn't do that as a part of FLR.
3352 GTT_BAR0_MAP_REG_USDM_RAM +
3353 USTORM_VF_PF_CHANNEL_READY_OFFSET(vfid), 1);
3355 /* VF_STOPPED has to be set only after final cleanup
3356 * but prior to re-enabling the VF.
3358 p_vf->state = VF_STOPPED;
3360 rc = ecore_iov_enable_vf_access(p_hwfn, p_ptt, p_vf);
3362 /* TODO - again, a mess... */
3363 DP_ERR(p_hwfn, "Failed to re-enable VF[%d] acces\n",
3368 /* Mark VF for ack and clean pending state */
3369 if (p_vf->state == VF_RESET)
3370 p_vf->state = VF_STOPPED;
3371 ack_vfs[vfid / 32] |= (1 << (vfid % 32));
3372 p_hwfn->pf_iov_info->pending_flr[rel_vf_id / 64] &=
3373 ~(1ULL << (rel_vf_id % 64));
3374 p_hwfn->pf_iov_info->pending_events[rel_vf_id / 64] &=
3375 ~(1ULL << (rel_vf_id % 64));
3381 enum _ecore_status_t ecore_iov_vf_flr_cleanup(struct ecore_hwfn *p_hwfn,
3382 struct ecore_ptt *p_ptt)
3384 u32 ack_vfs[VF_MAX_STATIC / 32];
3385 enum _ecore_status_t rc = ECORE_SUCCESS;
3388 OSAL_MEMSET(ack_vfs, 0, sizeof(u32) * (VF_MAX_STATIC / 32));
3390 /* Since BRB <-> PRS interface can't be tested as part of the flr
3391 * polling due to HW limitations, simply sleep a bit. And since
3392 * there's no need to wait per-vf, do it before looping.
3396 for (i = 0; i < p_hwfn->p_dev->p_iov_info->total_vfs; i++)
3397 ecore_iov_execute_vf_flr_cleanup(p_hwfn, p_ptt, i, ack_vfs);
3399 rc = ecore_mcp_ack_vf_flr(p_hwfn, p_ptt, ack_vfs);
3403 enum _ecore_status_t
3404 ecore_iov_single_vf_flr_cleanup(struct ecore_hwfn *p_hwfn,
3405 struct ecore_ptt *p_ptt, u16 rel_vf_id)
3407 u32 ack_vfs[VF_MAX_STATIC / 32];
3408 enum _ecore_status_t rc = ECORE_SUCCESS;
3410 OSAL_MEMSET(ack_vfs, 0, sizeof(u32) * (VF_MAX_STATIC / 32));
3412 /* Wait instead of polling the BRB <-> PRS interface */
3415 ecore_iov_execute_vf_flr_cleanup(p_hwfn, p_ptt, rel_vf_id, ack_vfs);
3417 rc = ecore_mcp_ack_vf_flr(p_hwfn, p_ptt, ack_vfs);
3421 bool ecore_iov_mark_vf_flr(struct ecore_hwfn *p_hwfn, u32 *p_disabled_vfs)
3426 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV, "Marking FLR-ed VFs\n");
3427 for (i = 0; i < (VF_MAX_STATIC / 32); i++)
3428 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3429 "[%08x,...,%08x]: %08x\n",
3430 i * 32, (i + 1) * 32 - 1, p_disabled_vfs[i]);
3432 if (!p_hwfn->p_dev->p_iov_info) {
3433 DP_NOTICE(p_hwfn, true, "VF flr but no IOV\n");
3438 for (i = 0; i < p_hwfn->p_dev->p_iov_info->total_vfs; i++) {
3439 struct ecore_vf_info *p_vf;
3442 p_vf = ecore_iov_get_vf_info(p_hwfn, i, false);
3446 vfid = p_vf->abs_vf_id;
3447 if ((1 << (vfid % 32)) & p_disabled_vfs[vfid / 32]) {
3448 u64 *p_flr = p_hwfn->pf_iov_info->pending_flr;
3449 u16 rel_vf_id = p_vf->relative_vf_id;
3451 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3452 "VF[%d] [rel %d] got FLR-ed\n",
3455 p_vf->state = VF_RESET;
3457 /* No need to lock here, since pending_flr should
3458 * only change here and before ACKing MFw. Since
3459 * MFW will not trigger an additional attention for
3460 * VF flr until ACKs, we're safe.
3462 p_flr[rel_vf_id / 64] |= 1ULL << (rel_vf_id % 64);
3470 void ecore_iov_get_link(struct ecore_hwfn *p_hwfn,
3472 struct ecore_mcp_link_params *p_params,
3473 struct ecore_mcp_link_state *p_link,
3474 struct ecore_mcp_link_capabilities *p_caps)
3476 struct ecore_vf_info *p_vf = ecore_iov_get_vf_info(p_hwfn, vfid, false);
3477 struct ecore_bulletin_content *p_bulletin;
3482 p_bulletin = p_vf->bulletin.p_virt;
3485 __ecore_vf_get_link_params(p_hwfn, p_params, p_bulletin);
3487 __ecore_vf_get_link_state(p_hwfn, p_link, p_bulletin);
3489 __ecore_vf_get_link_caps(p_hwfn, p_caps, p_bulletin);
3492 void ecore_iov_process_mbx_req(struct ecore_hwfn *p_hwfn,
3493 struct ecore_ptt *p_ptt, int vfid)
3495 struct ecore_iov_vf_mbx *mbx;
3496 struct ecore_vf_info *p_vf;
3498 p_vf = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
3502 mbx = &p_vf->vf_mbx;
3504 /* ecore_iov_process_mbx_request */
3507 "VF[%02x]: Processing mailbox message\n", p_vf->abs_vf_id);
3509 mbx->first_tlv = mbx->req_virt->first_tlv;
3511 OSAL_IOV_VF_MSG_TYPE(p_hwfn,
3512 p_vf->relative_vf_id,
3513 mbx->first_tlv.tl.type);
3515 /* Lock the per vf op mutex and note the locker's identity.
3516 * The unlock will take place in mbx response.
3518 ecore_iov_lock_vf_pf_channel(p_hwfn,
3519 p_vf, mbx->first_tlv.tl.type);
3521 /* check if tlv type is known */
3522 if (ecore_iov_tlv_supported(mbx->first_tlv.tl.type) &&
3523 !p_vf->b_malicious) {
3524 /* switch on the opcode */
3525 switch (mbx->first_tlv.tl.type) {
3526 case CHANNEL_TLV_ACQUIRE:
3527 ecore_iov_vf_mbx_acquire(p_hwfn, p_ptt, p_vf);
3529 case CHANNEL_TLV_VPORT_START:
3530 ecore_iov_vf_mbx_start_vport(p_hwfn, p_ptt, p_vf);
3532 case CHANNEL_TLV_VPORT_TEARDOWN:
3533 ecore_iov_vf_mbx_stop_vport(p_hwfn, p_ptt, p_vf);
3535 case CHANNEL_TLV_START_RXQ:
3536 ecore_iov_vf_mbx_start_rxq(p_hwfn, p_ptt, p_vf);
3538 case CHANNEL_TLV_START_TXQ:
3539 ecore_iov_vf_mbx_start_txq(p_hwfn, p_ptt, p_vf);
3541 case CHANNEL_TLV_STOP_RXQS:
3542 ecore_iov_vf_mbx_stop_rxqs(p_hwfn, p_ptt, p_vf);
3544 case CHANNEL_TLV_STOP_TXQS:
3545 ecore_iov_vf_mbx_stop_txqs(p_hwfn, p_ptt, p_vf);
3547 case CHANNEL_TLV_UPDATE_RXQ:
3548 ecore_iov_vf_mbx_update_rxqs(p_hwfn, p_ptt, p_vf);
3550 case CHANNEL_TLV_VPORT_UPDATE:
3551 ecore_iov_vf_mbx_vport_update(p_hwfn, p_ptt, p_vf);
3553 case CHANNEL_TLV_UCAST_FILTER:
3554 ecore_iov_vf_mbx_ucast_filter(p_hwfn, p_ptt, p_vf);
3556 case CHANNEL_TLV_CLOSE:
3557 ecore_iov_vf_mbx_close(p_hwfn, p_ptt, p_vf);
3559 case CHANNEL_TLV_INT_CLEANUP:
3560 ecore_iov_vf_mbx_int_cleanup(p_hwfn, p_ptt, p_vf);
3562 case CHANNEL_TLV_RELEASE:
3563 ecore_iov_vf_mbx_release(p_hwfn, p_ptt, p_vf);
3565 case CHANNEL_TLV_UPDATE_TUNN_PARAM:
3566 ecore_iov_vf_mbx_update_tunn_param(p_hwfn, p_ptt, p_vf);
3569 } else if (ecore_iov_tlv_supported(mbx->first_tlv.tl.type)) {
3570 /* If we've received a message from a VF we consider malicious
3571 * we ignore the messasge unless it's one for RELEASE, in which
3572 * case we'll let it have the benefit of doubt, allowing the
3573 * next loaded driver to start again.
3575 if (mbx->first_tlv.tl.type == CHANNEL_TLV_RELEASE) {
3576 /* TODO - initiate FLR, remove malicious indication */
3577 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3578 "VF [%02x] - considered malicious, but wanted to RELEASE. TODO\n",
3581 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3582 "VF [%02x] - considered malicious; Ignoring TLV [%04x]\n",
3583 p_vf->abs_vf_id, mbx->first_tlv.tl.type);
3586 ecore_iov_prepare_resp(p_hwfn, p_ptt, p_vf,
3587 mbx->first_tlv.tl.type,
3588 sizeof(struct pfvf_def_resp_tlv),
3589 PFVF_STATUS_MALICIOUS);
3591 /* unknown TLV - this may belong to a VF driver from the future
3592 * - a version written after this PF driver was written, which
3593 * supports features unknown as of yet. Too bad since we don't
3594 * support them. Or this may be because someone wrote a crappy
3595 * VF driver and is sending garbage over the channel.
3597 DP_NOTICE(p_hwfn, false,
3598 "VF[%02x]: unknown TLV. type %04x length %04x"
3599 " padding %08x reply address %lu\n",
3601 mbx->first_tlv.tl.type,
3602 mbx->first_tlv.tl.length,
3603 mbx->first_tlv.padding,
3604 (unsigned long)mbx->first_tlv.reply_address);
3606 /* Try replying in case reply address matches the acquisition's
3609 if (p_vf->acquire.first_tlv.reply_address &&
3610 (mbx->first_tlv.reply_address ==
3611 p_vf->acquire.first_tlv.reply_address))
3612 ecore_iov_prepare_resp(p_hwfn, p_ptt, p_vf,
3613 mbx->first_tlv.tl.type,
3614 sizeof(struct pfvf_def_resp_tlv),
3615 PFVF_STATUS_NOT_SUPPORTED);
3617 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3618 "VF[%02x]: Can't respond to TLV -"
3619 " no valid reply address\n",
3623 ecore_iov_unlock_vf_pf_channel(p_hwfn, p_vf,
3624 mbx->first_tlv.tl.type);
3626 #ifdef CONFIG_ECORE_SW_CHANNEL
3627 mbx->sw_mbx.mbx_state = VF_PF_RESPONSE_READY;
3628 mbx->sw_mbx.response_offset = 0;
3632 void ecore_iov_pf_add_pending_events(struct ecore_hwfn *p_hwfn, u8 vfid)
3634 u64 add_bit = 1ULL << (vfid % 64);
3636 /* TODO - add locking mechanisms [no atomics in ecore, so we can't
3637 * add the lock inside the ecore_pf_iov struct].
3639 p_hwfn->pf_iov_info->pending_events[vfid / 64] |= add_bit;
3642 void ecore_iov_pf_get_and_clear_pending_events(struct ecore_hwfn *p_hwfn,
3645 u64 *p_pending_events = p_hwfn->pf_iov_info->pending_events;
3647 /* TODO - Take a lock */
3648 OSAL_MEMCPY(events, p_pending_events,
3649 sizeof(u64) * ECORE_VF_ARRAY_LENGTH);
3650 OSAL_MEMSET(p_pending_events, 0,
3651 sizeof(u64) * ECORE_VF_ARRAY_LENGTH);
3654 static struct ecore_vf_info *
3655 ecore_sriov_get_vf_from_absid(struct ecore_hwfn *p_hwfn, u16 abs_vfid)
3657 u8 min = (u8)p_hwfn->p_dev->p_iov_info->first_vf_in_pf;
3659 if (!_ecore_iov_pf_sanity_check(p_hwfn, (int)abs_vfid - min, false)) {
3660 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3661 "Got indication for VF [abs 0x%08x] that cannot be"
3667 return &p_hwfn->pf_iov_info->vfs_array[(u8)abs_vfid - min];
3670 static enum _ecore_status_t ecore_sriov_vfpf_msg(struct ecore_hwfn *p_hwfn,
3672 struct regpair *vf_msg)
3674 struct ecore_vf_info *p_vf = ecore_sriov_get_vf_from_absid(p_hwfn,
3678 return ECORE_SUCCESS;
3680 /* List the physical address of the request so that handler
3681 * could later on copy the message from it.
3683 p_vf->vf_mbx.pending_req = (((u64)vf_msg->hi) << 32) | vf_msg->lo;
3685 return OSAL_PF_VF_MSG(p_hwfn, p_vf->relative_vf_id);
3688 static void ecore_sriov_vfpf_malicious(struct ecore_hwfn *p_hwfn,
3689 struct malicious_vf_eqe_data *p_data)
3691 struct ecore_vf_info *p_vf;
3693 p_vf = ecore_sriov_get_vf_from_absid(p_hwfn, p_data->vfId);
3699 "VF [%d] - Malicious behavior [%02x]\n",
3700 p_vf->abs_vf_id, p_data->errId);
3702 p_vf->b_malicious = true;
3704 OSAL_PF_VF_MALICIOUS(p_hwfn, p_vf->relative_vf_id);
3707 enum _ecore_status_t ecore_sriov_eqe_event(struct ecore_hwfn *p_hwfn,
3710 union event_ring_data *data)
3713 case COMMON_EVENT_VF_PF_CHANNEL:
3714 return ecore_sriov_vfpf_msg(p_hwfn, OSAL_LE16_TO_CPU(echo),
3715 &data->vf_pf_channel.msg_addr);
3716 case COMMON_EVENT_VF_FLR:
3717 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3718 "VF-FLR is still not supported\n");
3719 return ECORE_SUCCESS;
3720 case COMMON_EVENT_MALICIOUS_VF:
3721 ecore_sriov_vfpf_malicious(p_hwfn, &data->malicious_vf);
3722 return ECORE_SUCCESS;
3724 DP_INFO(p_hwfn->p_dev, "Unknown sriov eqe event 0x%02x\n",
3730 bool ecore_iov_is_vf_pending_flr(struct ecore_hwfn *p_hwfn, u16 rel_vf_id)
3732 return !!(p_hwfn->pf_iov_info->pending_flr[rel_vf_id / 64] &
3733 (1ULL << (rel_vf_id % 64)));
3736 u16 ecore_iov_get_next_active_vf(struct ecore_hwfn *p_hwfn, u16 rel_vf_id)
3738 struct ecore_hw_sriov_info *p_iov = p_hwfn->p_dev->p_iov_info;
3744 for (i = rel_vf_id; i < p_iov->total_vfs; i++)
3745 if (ecore_iov_is_valid_vfid(p_hwfn, rel_vf_id, true, false))
3749 return E4_MAX_NUM_VFS;
3752 enum _ecore_status_t ecore_iov_copy_vf_msg(struct ecore_hwfn *p_hwfn,
3753 struct ecore_ptt *ptt, int vfid)
3755 struct ecore_dmae_params params;
3756 struct ecore_vf_info *vf_info;
3758 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
3762 OSAL_MEMSET(¶ms, 0, sizeof(struct ecore_dmae_params));
3763 params.flags = ECORE_DMAE_FLAG_VF_SRC | ECORE_DMAE_FLAG_COMPLETION_DST;
3764 params.src_vfid = vf_info->abs_vf_id;
3766 if (ecore_dmae_host2host(p_hwfn, ptt,
3767 vf_info->vf_mbx.pending_req,
3768 vf_info->vf_mbx.req_phys,
3769 sizeof(union vfpf_tlvs) / 4, ¶ms)) {
3770 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3771 "Failed to copy message from VF 0x%02x\n", vfid);
3776 return ECORE_SUCCESS;
3779 void ecore_iov_bulletin_set_forced_mac(struct ecore_hwfn *p_hwfn,
3782 struct ecore_vf_info *vf_info;
3785 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
3787 DP_NOTICE(p_hwfn->p_dev, true,
3788 "Can not set forced MAC, invalid vfid [%d]\n", vfid);
3791 if (vf_info->b_malicious) {
3792 DP_NOTICE(p_hwfn->p_dev, false,
3793 "Can't set forced MAC to malicious VF [%d]\n",
3798 feature = 1 << MAC_ADDR_FORCED;
3799 OSAL_MEMCPY(vf_info->bulletin.p_virt->mac, mac, ETH_ALEN);
3801 vf_info->bulletin.p_virt->valid_bitmap |= feature;
3802 /* Forced MAC will disable MAC_ADDR */
3803 vf_info->bulletin.p_virt->valid_bitmap &=
3804 ~(1 << VFPF_BULLETIN_MAC_ADDR);
3806 ecore_iov_configure_vport_forced(p_hwfn, vf_info, feature);
3809 enum _ecore_status_t ecore_iov_bulletin_set_mac(struct ecore_hwfn *p_hwfn,
3812 struct ecore_vf_info *vf_info;
3815 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
3817 DP_NOTICE(p_hwfn->p_dev, true,
3818 "Can not set MAC, invalid vfid [%d]\n", vfid);
3821 if (vf_info->b_malicious) {
3822 DP_NOTICE(p_hwfn->p_dev, false,
3823 "Can't set MAC to malicious VF [%d]\n",
3828 if (vf_info->bulletin.p_virt->valid_bitmap & (1 << MAC_ADDR_FORCED)) {
3829 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3830 "Can not set MAC, Forced MAC is configured\n");
3834 feature = 1 << VFPF_BULLETIN_MAC_ADDR;
3835 OSAL_MEMCPY(vf_info->bulletin.p_virt->mac, mac, ETH_ALEN);
3837 vf_info->bulletin.p_virt->valid_bitmap |= feature;
3839 return ECORE_SUCCESS;
3842 enum _ecore_status_t
3843 ecore_iov_bulletin_set_forced_untagged_default(struct ecore_hwfn *p_hwfn,
3844 bool b_untagged_only, int vfid)
3846 struct ecore_vf_info *vf_info;
3849 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
3851 DP_NOTICE(p_hwfn->p_dev, true,
3852 "Can not set untagged default, invalid vfid [%d]\n",
3856 if (vf_info->b_malicious) {
3857 DP_NOTICE(p_hwfn->p_dev, false,
3858 "Can't set untagged default to malicious VF [%d]\n",
3863 /* Since this is configurable only during vport-start, don't take it
3864 * if we're past that point.
3866 if (vf_info->state == VF_ENABLED) {
3867 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3868 "Can't support untagged change for vfid[%d] -"
3869 " VF is already active\n",
3874 /* Set configuration; This will later be taken into account during the
3875 * VF initialization.
3877 feature = (1 << VFPF_BULLETIN_UNTAGGED_DEFAULT) |
3878 (1 << VFPF_BULLETIN_UNTAGGED_DEFAULT_FORCED);
3879 vf_info->bulletin.p_virt->valid_bitmap |= feature;
3881 vf_info->bulletin.p_virt->default_only_untagged = b_untagged_only ? 1
3884 return ECORE_SUCCESS;
3887 void ecore_iov_get_vfs_opaque_fid(struct ecore_hwfn *p_hwfn, int vfid,
3890 struct ecore_vf_info *vf_info;
3892 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
3896 *opaque_fid = vf_info->opaque_fid;
3899 void ecore_iov_get_vfs_vport_id(struct ecore_hwfn *p_hwfn, int vfid,
3902 struct ecore_vf_info *vf_info;
3904 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
3908 *p_vort_id = vf_info->vport_id;
3911 void ecore_iov_bulletin_set_forced_vlan(struct ecore_hwfn *p_hwfn,
3914 struct ecore_vf_info *vf_info;
3917 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
3919 DP_NOTICE(p_hwfn->p_dev, true,
3920 "Can not set forced MAC, invalid vfid [%d]\n",
3924 if (vf_info->b_malicious) {
3925 DP_NOTICE(p_hwfn->p_dev, false,
3926 "Can't set forced vlan to malicious VF [%d]\n",
3931 feature = 1 << VLAN_ADDR_FORCED;
3932 vf_info->bulletin.p_virt->pvid = pvid;
3934 vf_info->bulletin.p_virt->valid_bitmap |= feature;
3936 vf_info->bulletin.p_virt->valid_bitmap &= ~feature;
3938 ecore_iov_configure_vport_forced(p_hwfn, vf_info, feature);
3941 bool ecore_iov_vf_has_vport_instance(struct ecore_hwfn *p_hwfn, int vfid)
3943 struct ecore_vf_info *p_vf_info;
3945 p_vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
3949 return !!p_vf_info->vport_instance;
3952 bool ecore_iov_is_vf_stopped(struct ecore_hwfn *p_hwfn, int vfid)
3954 struct ecore_vf_info *p_vf_info;
3956 p_vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
3960 return p_vf_info->state == VF_STOPPED;
3963 bool ecore_iov_spoofchk_get(struct ecore_hwfn *p_hwfn, int vfid)
3965 struct ecore_vf_info *vf_info;
3967 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
3971 return vf_info->spoof_chk;
3974 enum _ecore_status_t ecore_iov_spoofchk_set(struct ecore_hwfn *p_hwfn,
3977 struct ecore_vf_info *vf;
3978 enum _ecore_status_t rc = ECORE_INVAL;
3980 if (!ecore_iov_pf_sanity_check(p_hwfn, vfid)) {
3981 DP_NOTICE(p_hwfn, true,
3982 "SR-IOV sanity check failed, can't set spoofchk\n");
3986 vf = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
3990 if (!ecore_iov_vf_has_vport_instance(p_hwfn, vfid)) {
3991 /* After VF VPORT start PF will configure spoof check */
3992 vf->req_spoofchk_val = val;
3997 rc = __ecore_iov_spoofchk_set(p_hwfn, vf, val);
4003 u8 ecore_iov_vf_chains_per_pf(struct ecore_hwfn *p_hwfn)
4005 u8 max_chains_per_vf = p_hwfn->hw_info.max_chains_per_vf;
4007 max_chains_per_vf = (max_chains_per_vf) ? max_chains_per_vf
4008 : ECORE_MAX_VF_CHAINS_PER_PF;
4010 return max_chains_per_vf;
4013 void ecore_iov_get_vf_req_virt_mbx_params(struct ecore_hwfn *p_hwfn,
4015 void **pp_req_virt_addr,
4016 u16 *p_req_virt_size)
4018 struct ecore_vf_info *vf_info =
4019 ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4024 if (pp_req_virt_addr)
4025 *pp_req_virt_addr = vf_info->vf_mbx.req_virt;
4027 if (p_req_virt_size)
4028 *p_req_virt_size = sizeof(*vf_info->vf_mbx.req_virt);
4031 void ecore_iov_get_vf_reply_virt_mbx_params(struct ecore_hwfn *p_hwfn,
4033 void **pp_reply_virt_addr,
4034 u16 *p_reply_virt_size)
4036 struct ecore_vf_info *vf_info =
4037 ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4042 if (pp_reply_virt_addr)
4043 *pp_reply_virt_addr = vf_info->vf_mbx.reply_virt;
4045 if (p_reply_virt_size)
4046 *p_reply_virt_size = sizeof(*vf_info->vf_mbx.reply_virt);
4049 #ifdef CONFIG_ECORE_SW_CHANNEL
4050 struct ecore_iov_sw_mbx *ecore_iov_get_vf_sw_mbx(struct ecore_hwfn *p_hwfn,
4053 struct ecore_vf_info *vf_info =
4054 ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4059 return &vf_info->vf_mbx.sw_mbx;
4063 bool ecore_iov_is_valid_vfpf_msg_length(u32 length)
4065 return (length >= sizeof(struct vfpf_first_tlv) &&
4066 (length <= sizeof(union vfpf_tlvs)));
4069 u32 ecore_iov_pfvf_msg_length(void)
4071 return sizeof(union pfvf_tlvs);
4074 u8 *ecore_iov_bulletin_get_forced_mac(struct ecore_hwfn *p_hwfn, u16 rel_vf_id)
4076 struct ecore_vf_info *p_vf;
4078 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4079 if (!p_vf || !p_vf->bulletin.p_virt)
4082 if (!(p_vf->bulletin.p_virt->valid_bitmap & (1 << MAC_ADDR_FORCED)))
4085 return p_vf->bulletin.p_virt->mac;
4088 u16 ecore_iov_bulletin_get_forced_vlan(struct ecore_hwfn *p_hwfn,
4091 struct ecore_vf_info *p_vf;
4093 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4094 if (!p_vf || !p_vf->bulletin.p_virt)
4097 if (!(p_vf->bulletin.p_virt->valid_bitmap & (1 << VLAN_ADDR_FORCED)))
4100 return p_vf->bulletin.p_virt->pvid;
4103 enum _ecore_status_t ecore_iov_configure_tx_rate(struct ecore_hwfn *p_hwfn,
4104 struct ecore_ptt *p_ptt,
4107 struct ecore_vf_info *vf;
4109 enum _ecore_status_t rc;
4111 vf = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4116 rc = ecore_fw_vport(p_hwfn, vf->vport_id, &abs_vp_id);
4117 if (rc != ECORE_SUCCESS)
4120 return ecore_init_vport_rl(p_hwfn, p_ptt, abs_vp_id, (u32)val);
4123 enum _ecore_status_t ecore_iov_configure_min_tx_rate(struct ecore_dev *p_dev,
4126 struct ecore_vf_info *vf;
4130 for_each_hwfn(p_dev, i) {
4131 struct ecore_hwfn *p_hwfn = &p_dev->hwfns[i];
4133 if (!ecore_iov_pf_sanity_check(p_hwfn, vfid)) {
4134 DP_NOTICE(p_hwfn, true,
4135 "SR-IOV sanity check failed,"
4136 " can't set min rate\n");
4141 vf = ecore_iov_get_vf_info(ECORE_LEADING_HWFN(p_dev), (u16)vfid, true);
4142 vport_id = vf->vport_id;
4144 return ecore_configure_vport_wfq(p_dev, vport_id, rate);
4147 enum _ecore_status_t ecore_iov_get_vf_stats(struct ecore_hwfn *p_hwfn,
4148 struct ecore_ptt *p_ptt,
4150 struct ecore_eth_stats *p_stats)
4152 struct ecore_vf_info *vf;
4154 vf = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4158 if (vf->state != VF_ENABLED)
4161 __ecore_get_vport_stats(p_hwfn, p_ptt, p_stats,
4162 vf->abs_vf_id + 0x10, false);
4164 return ECORE_SUCCESS;
4167 u8 ecore_iov_get_vf_num_rxqs(struct ecore_hwfn *p_hwfn, u16 rel_vf_id)
4169 struct ecore_vf_info *p_vf;
4171 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4175 return p_vf->num_rxqs;
4178 u8 ecore_iov_get_vf_num_active_rxqs(struct ecore_hwfn *p_hwfn, u16 rel_vf_id)
4180 struct ecore_vf_info *p_vf;
4182 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4186 return p_vf->num_active_rxqs;
4189 void *ecore_iov_get_vf_ctx(struct ecore_hwfn *p_hwfn, u16 rel_vf_id)
4191 struct ecore_vf_info *p_vf;
4193 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4200 u8 ecore_iov_get_vf_num_sbs(struct ecore_hwfn *p_hwfn, u16 rel_vf_id)
4202 struct ecore_vf_info *p_vf;
4204 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4208 return p_vf->num_sbs;
4211 bool ecore_iov_is_vf_wait_for_acquire(struct ecore_hwfn *p_hwfn, u16 rel_vf_id)
4213 struct ecore_vf_info *p_vf;
4215 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4219 return (p_vf->state == VF_FREE);
4222 bool ecore_iov_is_vf_acquired_not_initialized(struct ecore_hwfn *p_hwfn,
4225 struct ecore_vf_info *p_vf;
4227 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4231 return (p_vf->state == VF_ACQUIRED);
4234 bool ecore_iov_is_vf_initialized(struct ecore_hwfn *p_hwfn, u16 rel_vf_id)
4236 struct ecore_vf_info *p_vf;
4238 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4242 return (p_vf->state == VF_ENABLED);
4245 bool ecore_iov_is_vf_started(struct ecore_hwfn *p_hwfn,
4248 struct ecore_vf_info *p_vf;
4250 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4254 return (p_vf->state != VF_FREE && p_vf->state != VF_STOPPED);
4257 enum _ecore_status_t
4258 ecore_iov_get_vf_min_rate(struct ecore_hwfn *p_hwfn, int vfid)
4260 struct ecore_wfq_data *vf_vp_wfq;
4261 struct ecore_vf_info *vf_info;
4263 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4267 vf_vp_wfq = &p_hwfn->qm_info.wfq_data[vf_info->vport_id];
4269 if (vf_vp_wfq->configured)
4270 return vf_vp_wfq->min_speed;