2 * Copyright (c) 2016 QLogic Corporation.
6 * See LICENSE.qede_pmd for copyright and licensing details.
12 #include "ecore_sriov.h"
13 #include "ecore_status.h"
15 #include "ecore_hw_defs.h"
16 #include "ecore_int.h"
17 #include "ecore_hsi_eth.h"
19 #include "ecore_vfpf_if.h"
20 #include "ecore_rt_defs.h"
21 #include "ecore_init_ops.h"
22 #include "ecore_gtt_reg_addr.h"
23 #include "ecore_iro.h"
24 #include "ecore_mcp.h"
25 #include "ecore_cxt.h"
27 #include "ecore_init_fw_funcs.h"
28 #include "ecore_sp_commands.h"
30 const char *ecore_channel_tlvs_string[] = {
31 "CHANNEL_TLV_NONE", /* ends tlv sequence */
32 "CHANNEL_TLV_ACQUIRE",
33 "CHANNEL_TLV_VPORT_START",
34 "CHANNEL_TLV_VPORT_UPDATE",
35 "CHANNEL_TLV_VPORT_TEARDOWN",
36 "CHANNEL_TLV_START_RXQ",
37 "CHANNEL_TLV_START_TXQ",
38 "CHANNEL_TLV_STOP_RXQ",
39 "CHANNEL_TLV_STOP_TXQ",
40 "CHANNEL_TLV_UPDATE_RXQ",
41 "CHANNEL_TLV_INT_CLEANUP",
43 "CHANNEL_TLV_RELEASE",
44 "CHANNEL_TLV_LIST_END",
45 "CHANNEL_TLV_UCAST_FILTER",
46 "CHANNEL_TLV_VPORT_UPDATE_ACTIVATE",
47 "CHANNEL_TLV_VPORT_UPDATE_TX_SWITCH",
48 "CHANNEL_TLV_VPORT_UPDATE_VLAN_STRIP",
49 "CHANNEL_TLV_VPORT_UPDATE_MCAST",
50 "CHANNEL_TLV_VPORT_UPDATE_ACCEPT_PARAM",
51 "CHANNEL_TLV_VPORT_UPDATE_RSS",
52 "CHANNEL_TLV_VPORT_UPDATE_ACCEPT_ANY_VLAN",
53 "CHANNEL_TLV_VPORT_UPDATE_SGE_TPA",
54 "CHANNEL_TLV_UPDATE_TUNN_PARAM",
55 "CHANNEL_TLV_COALESCE_UPDATE",
60 static enum _ecore_status_t ecore_sp_vf_start(struct ecore_hwfn *p_hwfn,
61 struct ecore_vf_info *p_vf)
63 struct vf_start_ramrod_data *p_ramrod = OSAL_NULL;
64 struct ecore_spq_entry *p_ent = OSAL_NULL;
65 struct ecore_sp_init_data init_data;
66 enum _ecore_status_t rc = ECORE_NOTIMPL;
70 OSAL_MEMSET(&init_data, 0, sizeof(init_data));
71 init_data.cid = ecore_spq_get_cid(p_hwfn);
72 init_data.opaque_fid = p_vf->opaque_fid;
73 init_data.comp_mode = ECORE_SPQ_MODE_EBLOCK;
75 rc = ecore_sp_init_request(p_hwfn, &p_ent,
76 COMMON_RAMROD_VF_START,
77 PROTOCOLID_COMMON, &init_data);
78 if (rc != ECORE_SUCCESS)
81 p_ramrod = &p_ent->ramrod.vf_start;
83 p_ramrod->vf_id = GET_FIELD(p_vf->concrete_fid, PXP_CONCRETE_FID_VFID);
84 p_ramrod->opaque_fid = OSAL_CPU_TO_LE16(p_vf->opaque_fid);
86 switch (p_hwfn->hw_info.personality) {
88 p_ramrod->personality = PERSONALITY_ETH;
90 case ECORE_PCI_ETH_ROCE:
91 case ECORE_PCI_ETH_IWARP:
92 p_ramrod->personality = PERSONALITY_RDMA_AND_ETH;
95 DP_NOTICE(p_hwfn, true, "Unknown VF personality %d\n",
96 p_hwfn->hw_info.personality);
100 fp_minor = p_vf->acquire.vfdev_info.eth_fp_hsi_minor;
101 if (fp_minor > ETH_HSI_VER_MINOR &&
102 fp_minor != ETH_HSI_VER_NO_PKT_LEN_TUNN) {
103 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
104 "VF [%d] - Requested fp hsi %02x.%02x which is"
105 " slightly newer than PF's %02x.%02x; Configuring"
108 ETH_HSI_VER_MAJOR, fp_minor,
109 ETH_HSI_VER_MAJOR, ETH_HSI_VER_MINOR);
110 fp_minor = ETH_HSI_VER_MINOR;
113 p_ramrod->hsi_fp_ver.major_ver_arr[ETH_VER_KEY] = ETH_HSI_VER_MAJOR;
114 p_ramrod->hsi_fp_ver.minor_ver_arr[ETH_VER_KEY] = fp_minor;
116 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
117 "VF[%d] - Starting using HSI %02x.%02x\n",
118 p_vf->abs_vf_id, ETH_HSI_VER_MAJOR, fp_minor);
120 return ecore_spq_post(p_hwfn, p_ent, OSAL_NULL);
123 static enum _ecore_status_t ecore_sp_vf_stop(struct ecore_hwfn *p_hwfn,
127 struct vf_stop_ramrod_data *p_ramrod = OSAL_NULL;
128 struct ecore_spq_entry *p_ent = OSAL_NULL;
129 struct ecore_sp_init_data init_data;
130 enum _ecore_status_t rc = ECORE_NOTIMPL;
133 OSAL_MEMSET(&init_data, 0, sizeof(init_data));
134 init_data.cid = ecore_spq_get_cid(p_hwfn);
135 init_data.opaque_fid = opaque_vfid;
136 init_data.comp_mode = ECORE_SPQ_MODE_EBLOCK;
138 rc = ecore_sp_init_request(p_hwfn, &p_ent,
139 COMMON_RAMROD_VF_STOP,
140 PROTOCOLID_COMMON, &init_data);
141 if (rc != ECORE_SUCCESS)
144 p_ramrod = &p_ent->ramrod.vf_stop;
146 p_ramrod->vf_id = GET_FIELD(concrete_vfid, PXP_CONCRETE_FID_VFID);
148 return ecore_spq_post(p_hwfn, p_ent, OSAL_NULL);
151 bool ecore_iov_is_valid_vfid(struct ecore_hwfn *p_hwfn, int rel_vf_id,
152 bool b_enabled_only, bool b_non_malicious)
154 if (!p_hwfn->pf_iov_info) {
155 DP_NOTICE(p_hwfn->p_dev, true, "No iov info\n");
159 if ((rel_vf_id >= p_hwfn->p_dev->p_iov_info->total_vfs) ||
163 if ((!p_hwfn->pf_iov_info->vfs_array[rel_vf_id].b_init) &&
167 if ((p_hwfn->pf_iov_info->vfs_array[rel_vf_id].b_malicious) &&
174 struct ecore_vf_info *ecore_iov_get_vf_info(struct ecore_hwfn *p_hwfn,
178 struct ecore_vf_info *vf = OSAL_NULL;
180 if (!p_hwfn->pf_iov_info) {
181 DP_NOTICE(p_hwfn->p_dev, true, "No iov info\n");
185 if (ecore_iov_is_valid_vfid(p_hwfn, relative_vf_id,
186 b_enabled_only, false))
187 vf = &p_hwfn->pf_iov_info->vfs_array[relative_vf_id];
189 DP_ERR(p_hwfn, "ecore_iov_get_vf_info: VF[%d] is not enabled\n",
195 static bool ecore_iov_validate_rxq(struct ecore_hwfn *p_hwfn,
196 struct ecore_vf_info *p_vf,
199 if (rx_qid >= p_vf->num_rxqs)
200 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
201 "VF[0x%02x] - can't touch Rx queue[%04x];"
202 " Only 0x%04x are allocated\n",
203 p_vf->abs_vf_id, rx_qid, p_vf->num_rxqs);
204 return rx_qid < p_vf->num_rxqs;
207 static bool ecore_iov_validate_txq(struct ecore_hwfn *p_hwfn,
208 struct ecore_vf_info *p_vf,
211 if (tx_qid >= p_vf->num_txqs)
212 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
213 "VF[0x%02x] - can't touch Tx queue[%04x];"
214 " Only 0x%04x are allocated\n",
215 p_vf->abs_vf_id, tx_qid, p_vf->num_txqs);
216 return tx_qid < p_vf->num_txqs;
219 static bool ecore_iov_validate_sb(struct ecore_hwfn *p_hwfn,
220 struct ecore_vf_info *p_vf,
225 for (i = 0; i < p_vf->num_sbs; i++)
226 if (p_vf->igu_sbs[i] == sb_idx)
229 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
230 "VF[0%02x] - tried using sb_idx %04x which doesn't exist as"
231 " one of its 0x%02x SBs\n",
232 p_vf->abs_vf_id, sb_idx, p_vf->num_sbs);
237 static bool ecore_iov_validate_active_rxq(struct ecore_hwfn *p_hwfn,
238 struct ecore_vf_info *p_vf)
242 for (i = 0; i < p_vf->num_rxqs; i++)
243 if (p_vf->vf_queues[i].p_rx_cid)
249 static bool ecore_iov_validate_active_txq(struct ecore_hwfn *p_hwfn,
250 struct ecore_vf_info *p_vf)
254 for (i = 0; i < p_vf->num_rxqs; i++)
255 if (p_vf->vf_queues[i].p_tx_cid)
261 /* TODO - this is linux crc32; Need a way to ifdef it out for linux */
262 u32 ecore_crc32(u32 crc, u8 *ptr, u32 length)
268 for (i = 0; i < 8; i++)
269 crc = (crc >> 1) ^ ((crc & 1) ? 0xedb88320 : 0);
274 enum _ecore_status_t ecore_iov_post_vf_bulletin(struct ecore_hwfn *p_hwfn,
276 struct ecore_ptt *p_ptt)
278 struct ecore_bulletin_content *p_bulletin;
279 int crc_size = sizeof(p_bulletin->crc);
280 struct ecore_dmae_params params;
281 struct ecore_vf_info *p_vf;
283 p_vf = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
287 /* TODO - check VF is in a state where it can accept message */
288 if (!p_vf->vf_bulletin)
291 p_bulletin = p_vf->bulletin.p_virt;
293 /* Increment bulletin board version and compute crc */
294 p_bulletin->version++;
295 p_bulletin->crc = ecore_crc32(0, (u8 *)p_bulletin + crc_size,
296 p_vf->bulletin.size - crc_size);
298 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
299 "Posting Bulletin 0x%08x to VF[%d] (CRC 0x%08x)\n",
300 p_bulletin->version, p_vf->relative_vf_id, p_bulletin->crc);
302 /* propagate bulletin board via dmae to vm memory */
303 OSAL_MEMSET(¶ms, 0, sizeof(params));
304 params.flags = ECORE_DMAE_FLAG_VF_DST;
305 params.dst_vfid = p_vf->abs_vf_id;
306 return ecore_dmae_host2host(p_hwfn, p_ptt, p_vf->bulletin.phys,
307 p_vf->vf_bulletin, p_vf->bulletin.size / 4,
311 static enum _ecore_status_t ecore_iov_pci_cfg_info(struct ecore_dev *p_dev)
313 struct ecore_hw_sriov_info *iov = p_dev->p_iov_info;
316 DP_VERBOSE(p_dev, ECORE_MSG_IOV, "sriov ext pos %d\n", pos);
317 OSAL_PCI_READ_CONFIG_WORD(p_dev, pos + PCI_SRIOV_CTRL, &iov->ctrl);
319 OSAL_PCI_READ_CONFIG_WORD(p_dev,
320 pos + PCI_SRIOV_TOTAL_VF, &iov->total_vfs);
321 OSAL_PCI_READ_CONFIG_WORD(p_dev,
322 pos + PCI_SRIOV_INITIAL_VF,
325 OSAL_PCI_READ_CONFIG_WORD(p_dev, pos + PCI_SRIOV_NUM_VF, &iov->num_vfs);
327 /* @@@TODO - in future we might want to add an OSAL here to
328 * allow each OS to decide on its own how to act.
330 DP_VERBOSE(p_dev, ECORE_MSG_IOV,
331 "Number of VFs are already set to non-zero value."
332 " Ignoring PCI configuration value\n");
336 OSAL_PCI_READ_CONFIG_WORD(p_dev,
337 pos + PCI_SRIOV_VF_OFFSET, &iov->offset);
339 OSAL_PCI_READ_CONFIG_WORD(p_dev,
340 pos + PCI_SRIOV_VF_STRIDE, &iov->stride);
342 OSAL_PCI_READ_CONFIG_WORD(p_dev,
343 pos + PCI_SRIOV_VF_DID, &iov->vf_device_id);
345 OSAL_PCI_READ_CONFIG_DWORD(p_dev,
346 pos + PCI_SRIOV_SUP_PGSIZE, &iov->pgsz);
348 OSAL_PCI_READ_CONFIG_DWORD(p_dev, pos + PCI_SRIOV_CAP, &iov->cap);
350 OSAL_PCI_READ_CONFIG_BYTE(p_dev, pos + PCI_SRIOV_FUNC_LINK, &iov->link);
352 DP_VERBOSE(p_dev, ECORE_MSG_IOV, "IOV info: nres %d, cap 0x%x,"
353 "ctrl 0x%x, total %d, initial %d, num vfs %d, offset %d,"
354 " stride %d, page size 0x%x\n",
355 iov->nres, iov->cap, iov->ctrl,
356 iov->total_vfs, iov->initial_vfs, iov->nr_virtfn,
357 iov->offset, iov->stride, iov->pgsz);
359 /* Some sanity checks */
360 if (iov->num_vfs > NUM_OF_VFS(p_dev) ||
361 iov->total_vfs > NUM_OF_VFS(p_dev)) {
362 /* This can happen only due to a bug. In this case we set
363 * num_vfs to zero to avoid memory corruption in the code that
364 * assumes max number of vfs
366 DP_NOTICE(p_dev, false,
367 "IOV: Unexpected number of vfs set: %d"
368 " setting num_vf to zero\n",
375 return ECORE_SUCCESS;
378 static void ecore_iov_clear_vf_igu_blocks(struct ecore_hwfn *p_hwfn,
379 struct ecore_ptt *p_ptt)
381 struct ecore_igu_block *p_sb;
385 if (!p_hwfn->hw_info.p_igu_info) {
387 "ecore_iov_clear_vf_igu_blocks IGU Info not inited\n");
392 sb_id < ECORE_MAPPING_MEMORY_SIZE(p_hwfn->p_dev); sb_id++) {
393 p_sb = &p_hwfn->hw_info.p_igu_info->igu_map.igu_blocks[sb_id];
394 if ((p_sb->status & ECORE_IGU_STATUS_FREE) &&
395 !(p_sb->status & ECORE_IGU_STATUS_PF)) {
396 val = ecore_rd(p_hwfn, p_ptt,
397 IGU_REG_MAPPING_MEMORY + sb_id * 4);
398 SET_FIELD(val, IGU_MAPPING_LINE_VALID, 0);
399 ecore_wr(p_hwfn, p_ptt,
400 IGU_REG_MAPPING_MEMORY + 4 * sb_id, val);
405 static void ecore_iov_setup_vfdb(struct ecore_hwfn *p_hwfn)
407 struct ecore_hw_sriov_info *p_iov = p_hwfn->p_dev->p_iov_info;
408 struct ecore_pf_iov *p_iov_info = p_hwfn->pf_iov_info;
409 struct ecore_bulletin_content *p_bulletin_virt;
410 dma_addr_t req_p, rply_p, bulletin_p;
411 union pfvf_tlvs *p_reply_virt_addr;
412 union vfpf_tlvs *p_req_virt_addr;
415 OSAL_MEMSET(p_iov_info->vfs_array, 0, sizeof(p_iov_info->vfs_array));
417 p_req_virt_addr = p_iov_info->mbx_msg_virt_addr;
418 req_p = p_iov_info->mbx_msg_phys_addr;
419 p_reply_virt_addr = p_iov_info->mbx_reply_virt_addr;
420 rply_p = p_iov_info->mbx_reply_phys_addr;
421 p_bulletin_virt = p_iov_info->p_bulletins;
422 bulletin_p = p_iov_info->bulletins_phys;
423 if (!p_req_virt_addr || !p_reply_virt_addr || !p_bulletin_virt) {
425 "ecore_iov_setup_vfdb called without alloc mem first\n");
429 p_iov_info->base_vport_id = 1; /* @@@TBD resource allocation */
431 for (idx = 0; idx < p_iov->total_vfs; idx++) {
432 struct ecore_vf_info *vf = &p_iov_info->vfs_array[idx];
435 vf->vf_mbx.req_virt = p_req_virt_addr + idx;
436 vf->vf_mbx.req_phys = req_p + idx * sizeof(union vfpf_tlvs);
437 vf->vf_mbx.reply_virt = p_reply_virt_addr + idx;
438 vf->vf_mbx.reply_phys = rply_p + idx * sizeof(union pfvf_tlvs);
440 #ifdef CONFIG_ECORE_SW_CHANNEL
441 vf->vf_mbx.sw_mbx.request_size = sizeof(union vfpf_tlvs);
442 vf->vf_mbx.sw_mbx.mbx_state = VF_PF_WAIT_FOR_START_REQUEST;
444 vf->state = VF_STOPPED;
447 vf->bulletin.phys = idx *
448 sizeof(struct ecore_bulletin_content) + bulletin_p;
449 vf->bulletin.p_virt = p_bulletin_virt + idx;
450 vf->bulletin.size = sizeof(struct ecore_bulletin_content);
452 vf->relative_vf_id = idx;
453 vf->abs_vf_id = idx + p_iov->first_vf_in_pf;
454 concrete = ecore_vfid_to_concrete(p_hwfn, vf->abs_vf_id);
455 vf->concrete_fid = concrete;
456 /* TODO - need to devise a better way of getting opaque */
457 vf->opaque_fid = (p_hwfn->hw_info.opaque_fid & 0xff) |
458 (vf->abs_vf_id << 8);
459 /* @@TBD MichalK - add base vport_id of VFs to equation */
460 vf->vport_id = p_iov_info->base_vport_id + idx;
462 vf->num_mac_filters = ECORE_ETH_VF_NUM_MAC_FILTERS;
463 vf->num_vlan_filters = ECORE_ETH_VF_NUM_VLAN_FILTERS;
467 static enum _ecore_status_t ecore_iov_allocate_vfdb(struct ecore_hwfn *p_hwfn)
469 struct ecore_pf_iov *p_iov_info = p_hwfn->pf_iov_info;
473 num_vfs = p_hwfn->p_dev->p_iov_info->total_vfs;
475 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
476 "ecore_iov_allocate_vfdb for %d VFs\n", num_vfs);
478 /* Allocate PF Mailbox buffer (per-VF) */
479 p_iov_info->mbx_msg_size = sizeof(union vfpf_tlvs) * num_vfs;
480 p_v_addr = &p_iov_info->mbx_msg_virt_addr;
481 *p_v_addr = OSAL_DMA_ALLOC_COHERENT(p_hwfn->p_dev,
482 &p_iov_info->mbx_msg_phys_addr,
483 p_iov_info->mbx_msg_size);
487 /* Allocate PF Mailbox Reply buffer (per-VF) */
488 p_iov_info->mbx_reply_size = sizeof(union pfvf_tlvs) * num_vfs;
489 p_v_addr = &p_iov_info->mbx_reply_virt_addr;
490 *p_v_addr = OSAL_DMA_ALLOC_COHERENT(p_hwfn->p_dev,
491 &p_iov_info->mbx_reply_phys_addr,
492 p_iov_info->mbx_reply_size);
496 p_iov_info->bulletins_size = sizeof(struct ecore_bulletin_content) *
498 p_v_addr = &p_iov_info->p_bulletins;
499 *p_v_addr = OSAL_DMA_ALLOC_COHERENT(p_hwfn->p_dev,
500 &p_iov_info->bulletins_phys,
501 p_iov_info->bulletins_size);
505 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
506 "PF's Requests mailbox [%p virt 0x%lx phys], "
507 "Response mailbox [%p virt 0x%lx phys] Bulletinsi"
508 " [%p virt 0x%lx phys]\n",
509 p_iov_info->mbx_msg_virt_addr,
510 (unsigned long)p_iov_info->mbx_msg_phys_addr,
511 p_iov_info->mbx_reply_virt_addr,
512 (unsigned long)p_iov_info->mbx_reply_phys_addr,
513 p_iov_info->p_bulletins,
514 (unsigned long)p_iov_info->bulletins_phys);
516 return ECORE_SUCCESS;
519 static void ecore_iov_free_vfdb(struct ecore_hwfn *p_hwfn)
521 struct ecore_pf_iov *p_iov_info = p_hwfn->pf_iov_info;
523 if (p_hwfn->pf_iov_info->mbx_msg_virt_addr)
524 OSAL_DMA_FREE_COHERENT(p_hwfn->p_dev,
525 p_iov_info->mbx_msg_virt_addr,
526 p_iov_info->mbx_msg_phys_addr,
527 p_iov_info->mbx_msg_size);
529 if (p_hwfn->pf_iov_info->mbx_reply_virt_addr)
530 OSAL_DMA_FREE_COHERENT(p_hwfn->p_dev,
531 p_iov_info->mbx_reply_virt_addr,
532 p_iov_info->mbx_reply_phys_addr,
533 p_iov_info->mbx_reply_size);
535 if (p_iov_info->p_bulletins)
536 OSAL_DMA_FREE_COHERENT(p_hwfn->p_dev,
537 p_iov_info->p_bulletins,
538 p_iov_info->bulletins_phys,
539 p_iov_info->bulletins_size);
542 enum _ecore_status_t ecore_iov_alloc(struct ecore_hwfn *p_hwfn)
544 struct ecore_pf_iov *p_sriov;
546 if (!IS_PF_SRIOV(p_hwfn)) {
547 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
548 "No SR-IOV - no need for IOV db\n");
549 return ECORE_SUCCESS;
552 p_sriov = OSAL_ZALLOC(p_hwfn->p_dev, GFP_KERNEL, sizeof(*p_sriov));
554 DP_NOTICE(p_hwfn, true,
555 "Failed to allocate `struct ecore_sriov'\n");
559 p_hwfn->pf_iov_info = p_sriov;
561 return ecore_iov_allocate_vfdb(p_hwfn);
564 void ecore_iov_setup(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt)
566 if (!IS_PF_SRIOV(p_hwfn) || !IS_PF_SRIOV_ALLOC(p_hwfn))
569 ecore_iov_setup_vfdb(p_hwfn);
570 ecore_iov_clear_vf_igu_blocks(p_hwfn, p_ptt);
573 void ecore_iov_free(struct ecore_hwfn *p_hwfn)
575 if (IS_PF_SRIOV_ALLOC(p_hwfn)) {
576 ecore_iov_free_vfdb(p_hwfn);
577 OSAL_FREE(p_hwfn->p_dev, p_hwfn->pf_iov_info);
581 void ecore_iov_free_hw_info(struct ecore_dev *p_dev)
583 OSAL_FREE(p_dev, p_dev->p_iov_info);
586 enum _ecore_status_t ecore_iov_hw_info(struct ecore_hwfn *p_hwfn)
588 struct ecore_dev *p_dev = p_hwfn->p_dev;
590 enum _ecore_status_t rc;
592 if (IS_VF(p_hwfn->p_dev))
593 return ECORE_SUCCESS;
595 /* Learn the PCI configuration */
596 pos = OSAL_PCI_FIND_EXT_CAPABILITY(p_hwfn->p_dev,
597 PCI_EXT_CAP_ID_SRIOV);
599 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV, "No PCIe IOV support\n");
600 return ECORE_SUCCESS;
603 /* Allocate a new struct for IOV information */
604 /* TODO - can change to VALLOC when its available */
605 p_dev->p_iov_info = OSAL_ZALLOC(p_dev, GFP_KERNEL,
606 sizeof(*p_dev->p_iov_info));
607 if (!p_dev->p_iov_info) {
608 DP_NOTICE(p_hwfn, true,
609 "Can't support IOV due to lack of memory\n");
612 p_dev->p_iov_info->pos = pos;
614 rc = ecore_iov_pci_cfg_info(p_dev);
618 /* We want PF IOV to be synonemous with the existence of p_iov_info;
619 * In case the capability is published but there are no VFs, simply
620 * de-allocate the struct.
622 if (!p_dev->p_iov_info->total_vfs) {
623 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
624 "IOV capabilities, but no VFs are published\n");
625 OSAL_FREE(p_dev, p_dev->p_iov_info);
626 return ECORE_SUCCESS;
629 /* First VF index based on offset is tricky:
630 * - If ARI is supported [likely], offset - (16 - pf_id) would
631 * provide the number for eng0. 2nd engine Vfs would begin
632 * after the first engine's VFs.
633 * - If !ARI, VFs would start on next device.
634 * so offset - (256 - pf_id) would provide the number.
635 * Utilize the fact that (256 - pf_id) is achieved only be later
636 * to diffrentiate between the two.
639 if (p_hwfn->p_dev->p_iov_info->offset < (256 - p_hwfn->abs_pf_id)) {
640 u32 first = p_hwfn->p_dev->p_iov_info->offset +
641 p_hwfn->abs_pf_id - 16;
643 p_dev->p_iov_info->first_vf_in_pf = first;
645 if (ECORE_PATH_ID(p_hwfn))
646 p_dev->p_iov_info->first_vf_in_pf -= MAX_NUM_VFS_BB;
648 u32 first = p_hwfn->p_dev->p_iov_info->offset +
649 p_hwfn->abs_pf_id - 256;
651 p_dev->p_iov_info->first_vf_in_pf = first;
654 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
655 "First VF in hwfn 0x%08x\n",
656 p_dev->p_iov_info->first_vf_in_pf);
658 return ECORE_SUCCESS;
661 static bool _ecore_iov_pf_sanity_check(struct ecore_hwfn *p_hwfn, int vfid,
662 bool b_fail_malicious)
664 /* Check PF supports sriov */
665 if (IS_VF(p_hwfn->p_dev) || !IS_ECORE_SRIOV(p_hwfn->p_dev) ||
666 !IS_PF_SRIOV_ALLOC(p_hwfn))
669 /* Check VF validity */
670 if (!ecore_iov_is_valid_vfid(p_hwfn, vfid, true, b_fail_malicious))
676 bool ecore_iov_pf_sanity_check(struct ecore_hwfn *p_hwfn, int vfid)
678 return _ecore_iov_pf_sanity_check(p_hwfn, vfid, true);
681 void ecore_iov_set_vf_to_disable(struct ecore_dev *p_dev,
682 u16 rel_vf_id, u8 to_disable)
684 struct ecore_vf_info *vf;
687 for_each_hwfn(p_dev, i) {
688 struct ecore_hwfn *p_hwfn = &p_dev->hwfns[i];
690 vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, false);
694 vf->to_disable = to_disable;
698 void ecore_iov_set_vfs_to_disable(struct ecore_dev *p_dev,
703 if (!IS_ECORE_SRIOV(p_dev))
706 for (i = 0; i < p_dev->p_iov_info->total_vfs; i++)
707 ecore_iov_set_vf_to_disable(p_dev, i, to_disable);
711 /* @@@TBD Consider taking outside of ecore... */
712 enum _ecore_status_t ecore_iov_set_vf_ctx(struct ecore_hwfn *p_hwfn,
716 enum _ecore_status_t rc = ECORE_SUCCESS;
717 struct ecore_vf_info *vf = ecore_iov_get_vf_info(p_hwfn, vf_id, true);
719 if (vf != OSAL_NULL) {
721 #ifdef CONFIG_ECORE_SW_CHANNEL
722 vf->vf_mbx.sw_mbx.mbx_state = VF_PF_WAIT_FOR_START_REQUEST;
725 rc = ECORE_UNKNOWN_ERROR;
731 static void ecore_iov_vf_pglue_clear_err(struct ecore_hwfn *p_hwfn,
732 struct ecore_ptt *p_ptt,
735 ecore_wr(p_hwfn, p_ptt,
736 PGLUE_B_REG_WAS_ERROR_VF_31_0_CLR + (abs_vfid >> 5) * 4,
737 1 << (abs_vfid & 0x1f));
740 static void ecore_iov_vf_igu_reset(struct ecore_hwfn *p_hwfn,
741 struct ecore_ptt *p_ptt,
742 struct ecore_vf_info *vf)
746 /* Set VF masks and configuration - pretend */
747 ecore_fid_pretend(p_hwfn, p_ptt, (u16)vf->concrete_fid);
749 ecore_wr(p_hwfn, p_ptt, IGU_REG_STATISTIC_NUM_VF_MSG_SENT, 0);
752 ecore_fid_pretend(p_hwfn, p_ptt, (u16)p_hwfn->hw_info.concrete_fid);
754 /* iterate over all queues, clear sb consumer */
755 for (i = 0; i < vf->num_sbs; i++)
756 ecore_int_igu_init_pure_rt_single(p_hwfn, p_ptt,
758 vf->opaque_fid, true);
761 static void ecore_iov_vf_igu_set_int(struct ecore_hwfn *p_hwfn,
762 struct ecore_ptt *p_ptt,
763 struct ecore_vf_info *vf, bool enable)
767 ecore_fid_pretend(p_hwfn, p_ptt, (u16)vf->concrete_fid);
769 igu_vf_conf = ecore_rd(p_hwfn, p_ptt, IGU_REG_VF_CONFIGURATION);
772 igu_vf_conf |= IGU_VF_CONF_MSI_MSIX_EN;
774 igu_vf_conf &= ~IGU_VF_CONF_MSI_MSIX_EN;
776 ecore_wr(p_hwfn, p_ptt, IGU_REG_VF_CONFIGURATION, igu_vf_conf);
779 ecore_fid_pretend(p_hwfn, p_ptt, (u16)p_hwfn->hw_info.concrete_fid);
782 static enum _ecore_status_t
783 ecore_iov_enable_vf_access(struct ecore_hwfn *p_hwfn,
784 struct ecore_ptt *p_ptt, struct ecore_vf_info *vf)
786 u32 igu_vf_conf = IGU_VF_CONF_FUNC_EN;
787 enum _ecore_status_t rc;
790 return ECORE_SUCCESS;
792 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
793 "Enable internal access for vf %x [abs %x]\n", vf->abs_vf_id,
794 ECORE_VF_ABS_ID(p_hwfn, vf));
796 ecore_iov_vf_pglue_clear_err(p_hwfn, p_ptt,
797 ECORE_VF_ABS_ID(p_hwfn, vf));
799 ecore_iov_vf_igu_reset(p_hwfn, p_ptt, vf);
801 /* It's possible VF was previously considered malicious */
802 vf->b_malicious = false;
804 rc = ecore_mcp_config_vf_msix(p_hwfn, p_ptt,
805 vf->abs_vf_id, vf->num_sbs);
806 if (rc != ECORE_SUCCESS)
809 ecore_fid_pretend(p_hwfn, p_ptt, (u16)vf->concrete_fid);
811 SET_FIELD(igu_vf_conf, IGU_VF_CONF_PARENT, p_hwfn->rel_pf_id);
812 STORE_RT_REG(p_hwfn, IGU_REG_VF_CONFIGURATION_RT_OFFSET, igu_vf_conf);
814 ecore_init_run(p_hwfn, p_ptt, PHASE_VF, vf->abs_vf_id,
815 p_hwfn->hw_info.hw_mode);
818 ecore_fid_pretend(p_hwfn, p_ptt, (u16)p_hwfn->hw_info.concrete_fid);
827 * @brief ecore_iov_config_perm_table - configure the permission
829 * In E4, queue zone permission table size is 320x9. There
830 * are 320 VF queues for single engine device (256 for dual
831 * engine device), and each entry has the following format:
838 static void ecore_iov_config_perm_table(struct ecore_hwfn *p_hwfn,
839 struct ecore_ptt *p_ptt,
840 struct ecore_vf_info *vf, u8 enable)
846 for (qid = 0; qid < vf->num_rxqs; qid++) {
847 ecore_fw_l2_queue(p_hwfn, vf->vf_queues[qid].fw_rx_qid,
850 reg_addr = PSWHST_REG_ZONE_PERMISSION_TABLE + qzone_id * 4;
851 val = enable ? (vf->abs_vf_id | (1 << 8)) : 0;
852 ecore_wr(p_hwfn, p_ptt, reg_addr, val);
856 static void ecore_iov_enable_vf_traffic(struct ecore_hwfn *p_hwfn,
857 struct ecore_ptt *p_ptt,
858 struct ecore_vf_info *vf)
860 /* Reset vf in IGU - interrupts are still disabled */
861 ecore_iov_vf_igu_reset(p_hwfn, p_ptt, vf);
863 ecore_iov_vf_igu_set_int(p_hwfn, p_ptt, vf, 1);
865 /* Permission Table */
866 ecore_iov_config_perm_table(p_hwfn, p_ptt, vf, true);
869 static u8 ecore_iov_alloc_vf_igu_sbs(struct ecore_hwfn *p_hwfn,
870 struct ecore_ptt *p_ptt,
871 struct ecore_vf_info *vf,
874 struct ecore_igu_block *igu_blocks;
875 int qid = 0, igu_id = 0;
878 igu_blocks = p_hwfn->hw_info.p_igu_info->igu_map.igu_blocks;
880 if (num_rx_queues > p_hwfn->hw_info.p_igu_info->free_blks)
881 num_rx_queues = p_hwfn->hw_info.p_igu_info->free_blks;
883 p_hwfn->hw_info.p_igu_info->free_blks -= num_rx_queues;
885 SET_FIELD(val, IGU_MAPPING_LINE_FUNCTION_NUMBER, vf->abs_vf_id);
886 SET_FIELD(val, IGU_MAPPING_LINE_VALID, 1);
887 SET_FIELD(val, IGU_MAPPING_LINE_PF_VALID, 0);
889 while ((qid < num_rx_queues) &&
890 (igu_id < ECORE_MAPPING_MEMORY_SIZE(p_hwfn->p_dev))) {
891 if (igu_blocks[igu_id].status & ECORE_IGU_STATUS_FREE) {
892 struct cau_sb_entry sb_entry;
894 vf->igu_sbs[qid] = (u16)igu_id;
895 igu_blocks[igu_id].status &= ~ECORE_IGU_STATUS_FREE;
897 SET_FIELD(val, IGU_MAPPING_LINE_VECTOR_NUMBER, qid);
899 ecore_wr(p_hwfn, p_ptt,
900 IGU_REG_MAPPING_MEMORY + sizeof(u32) * igu_id,
903 /* Configure igu sb in CAU which were marked valid */
904 ecore_init_cau_sb_entry(p_hwfn, &sb_entry,
907 ecore_dmae_host2grc(p_hwfn, p_ptt,
908 (u64)(osal_uintptr_t)&sb_entry,
909 CAU_REG_SB_VAR_MEMORY +
910 igu_id * sizeof(u64), 2, 0);
916 vf->num_sbs = (u8)num_rx_queues;
923 * @brief The function invalidates all the VF entries,
924 * technically this isn't required, but added for
925 * cleaness and ease of debugging incase a VF attempts to
926 * produce an interrupt after it has been taken down.
932 static void ecore_iov_free_vf_igu_sbs(struct ecore_hwfn *p_hwfn,
933 struct ecore_ptt *p_ptt,
934 struct ecore_vf_info *vf)
936 struct ecore_igu_info *p_info = p_hwfn->hw_info.p_igu_info;
940 /* Invalidate igu CAM lines and mark them as free */
941 for (idx = 0; idx < vf->num_sbs; idx++) {
942 igu_id = vf->igu_sbs[idx];
943 addr = IGU_REG_MAPPING_MEMORY + sizeof(u32) * igu_id;
945 val = ecore_rd(p_hwfn, p_ptt, addr);
946 SET_FIELD(val, IGU_MAPPING_LINE_VALID, 0);
947 ecore_wr(p_hwfn, p_ptt, addr, val);
949 p_info->igu_map.igu_blocks[igu_id].status |=
950 ECORE_IGU_STATUS_FREE;
952 p_hwfn->hw_info.p_igu_info->free_blks++;
958 void ecore_iov_set_link(struct ecore_hwfn *p_hwfn,
960 struct ecore_mcp_link_params *params,
961 struct ecore_mcp_link_state *link,
962 struct ecore_mcp_link_capabilities *p_caps)
964 struct ecore_vf_info *p_vf = ecore_iov_get_vf_info(p_hwfn, vfid, false);
965 struct ecore_bulletin_content *p_bulletin;
970 p_bulletin = p_vf->bulletin.p_virt;
971 p_bulletin->req_autoneg = params->speed.autoneg;
972 p_bulletin->req_adv_speed = params->speed.advertised_speeds;
973 p_bulletin->req_forced_speed = params->speed.forced_speed;
974 p_bulletin->req_autoneg_pause = params->pause.autoneg;
975 p_bulletin->req_forced_rx = params->pause.forced_rx;
976 p_bulletin->req_forced_tx = params->pause.forced_tx;
977 p_bulletin->req_loopback = params->loopback_mode;
979 p_bulletin->link_up = link->link_up;
980 p_bulletin->speed = link->speed;
981 p_bulletin->full_duplex = link->full_duplex;
982 p_bulletin->autoneg = link->an;
983 p_bulletin->autoneg_complete = link->an_complete;
984 p_bulletin->parallel_detection = link->parallel_detection;
985 p_bulletin->pfc_enabled = link->pfc_enabled;
986 p_bulletin->partner_adv_speed = link->partner_adv_speed;
987 p_bulletin->partner_tx_flow_ctrl_en = link->partner_tx_flow_ctrl_en;
988 p_bulletin->partner_rx_flow_ctrl_en = link->partner_rx_flow_ctrl_en;
989 p_bulletin->partner_adv_pause = link->partner_adv_pause;
990 p_bulletin->sfp_tx_fault = link->sfp_tx_fault;
992 p_bulletin->capability_speed = p_caps->speed_capabilities;
996 ecore_iov_init_hw_for_vf(struct ecore_hwfn *p_hwfn,
997 struct ecore_ptt *p_ptt,
998 struct ecore_iov_vf_init_params *p_params)
1000 struct ecore_mcp_link_capabilities link_caps;
1001 struct ecore_mcp_link_params link_params;
1002 struct ecore_mcp_link_state link_state;
1003 u8 num_of_vf_available_chains = 0;
1004 struct ecore_vf_info *vf = OSAL_NULL;
1006 enum _ecore_status_t rc = ECORE_SUCCESS;
1010 vf = ecore_iov_get_vf_info(p_hwfn, p_params->rel_vf_id, false);
1012 DP_ERR(p_hwfn, "ecore_iov_init_hw_for_vf : vf is OSAL_NULL\n");
1013 return ECORE_UNKNOWN_ERROR;
1017 DP_NOTICE(p_hwfn, true, "VF[%d] is already active.\n",
1018 p_params->rel_vf_id);
1022 /* Perform sanity checking on the requested queue_id */
1023 for (i = 0; i < p_params->num_queues; i++) {
1024 u16 min_vf_qzone = (u16)FEAT_NUM(p_hwfn, ECORE_PF_L2_QUE);
1025 u16 max_vf_qzone = min_vf_qzone +
1026 FEAT_NUM(p_hwfn, ECORE_VF_L2_QUE) - 1;
1028 qid = p_params->req_rx_queue[i];
1029 if (qid < min_vf_qzone || qid > max_vf_qzone) {
1030 DP_NOTICE(p_hwfn, true,
1031 "Can't enable Rx qid [%04x] for VF[%d]: qids [0x%04x,...,0x%04x] available\n",
1032 qid, p_params->rel_vf_id,
1033 min_vf_qzone, max_vf_qzone);
1037 qid = p_params->req_tx_queue[i];
1038 if (qid > max_vf_qzone) {
1039 DP_NOTICE(p_hwfn, true,
1040 "Can't enable Tx qid [%04x] for VF[%d]: max qid 0x%04x\n",
1041 qid, p_params->rel_vf_id, max_vf_qzone);
1045 /* If client *really* wants, Tx qid can be shared with PF */
1046 if (qid < min_vf_qzone)
1047 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1048 "VF[%d] is using PF qid [0x%04x] for Txq[0x%02x]\n",
1049 p_params->rel_vf_id, qid, i);
1052 /* Limit number of queues according to number of CIDs */
1053 ecore_cxt_get_proto_cid_count(p_hwfn, PROTOCOLID_ETH, &cids);
1054 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1055 "VF[%d] - requesting to initialize for 0x%04x queues"
1056 " [0x%04x CIDs available]\n",
1057 vf->relative_vf_id, p_params->num_queues, (u16)cids);
1058 num_irqs = OSAL_MIN_T(u16, p_params->num_queues, ((u16)cids));
1060 num_of_vf_available_chains = ecore_iov_alloc_vf_igu_sbs(p_hwfn,
1064 if (num_of_vf_available_chains == 0) {
1065 DP_ERR(p_hwfn, "no available igu sbs\n");
1069 /* Choose queue number and index ranges */
1070 vf->num_rxqs = num_of_vf_available_chains;
1071 vf->num_txqs = num_of_vf_available_chains;
1073 for (i = 0; i < vf->num_rxqs; i++) {
1074 struct ecore_vf_q_info *p_queue = &vf->vf_queues[i];
1076 p_queue->fw_rx_qid = p_params->req_rx_queue[i];
1077 p_queue->fw_tx_qid = p_params->req_tx_queue[i];
1079 /* CIDs are per-VF, so no problem having them 0-based. */
1080 p_queue->fw_cid = i;
1082 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1083 "VF[%d] - Q[%d] SB %04x, qid [Rx %04x Tx %04x] CID %04x\n",
1084 vf->relative_vf_id, i, vf->igu_sbs[i],
1085 p_queue->fw_rx_qid, p_queue->fw_tx_qid,
1089 /* Update the link configuration in bulletin.
1091 OSAL_MEMCPY(&link_params, ecore_mcp_get_link_params(p_hwfn),
1092 sizeof(link_params));
1093 OSAL_MEMCPY(&link_state, ecore_mcp_get_link_state(p_hwfn),
1094 sizeof(link_state));
1095 OSAL_MEMCPY(&link_caps, ecore_mcp_get_link_capabilities(p_hwfn),
1097 ecore_iov_set_link(p_hwfn, p_params->rel_vf_id,
1098 &link_params, &link_state, &link_caps);
1100 rc = ecore_iov_enable_vf_access(p_hwfn, p_ptt, vf);
1102 if (rc == ECORE_SUCCESS) {
1104 p_hwfn->pf_iov_info->active_vfs[vf->relative_vf_id / 64] |=
1105 (1ULL << (vf->relative_vf_id % 64));
1107 if (IS_LEAD_HWFN(p_hwfn))
1108 p_hwfn->p_dev->p_iov_info->num_vfs++;
1114 enum _ecore_status_t ecore_iov_release_hw_for_vf(struct ecore_hwfn *p_hwfn,
1115 struct ecore_ptt *p_ptt,
1118 struct ecore_mcp_link_capabilities caps;
1119 struct ecore_mcp_link_params params;
1120 struct ecore_mcp_link_state link;
1121 struct ecore_vf_info *vf = OSAL_NULL;
1123 vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
1125 DP_ERR(p_hwfn, "ecore_iov_release_hw_for_vf : vf is NULL\n");
1126 return ECORE_UNKNOWN_ERROR;
1129 if (vf->bulletin.p_virt)
1130 OSAL_MEMSET(vf->bulletin.p_virt, 0,
1131 sizeof(*vf->bulletin.p_virt));
1133 OSAL_MEMSET(&vf->p_vf_info, 0, sizeof(vf->p_vf_info));
1135 /* Get the link configuration back in bulletin so
1136 * that when VFs are re-enabled they get the actual
1137 * link configuration.
1139 OSAL_MEMCPY(¶ms, ecore_mcp_get_link_params(p_hwfn), sizeof(params));
1140 OSAL_MEMCPY(&link, ecore_mcp_get_link_state(p_hwfn), sizeof(link));
1141 OSAL_MEMCPY(&caps, ecore_mcp_get_link_capabilities(p_hwfn),
1143 ecore_iov_set_link(p_hwfn, rel_vf_id, ¶ms, &link, &caps);
1145 /* Forget the VF's acquisition message */
1146 OSAL_MEMSET(&vf->acquire, 0, sizeof(vf->acquire));
1148 /* disablng interrupts and resetting permission table was done during
1149 * vf-close, however, we could get here without going through vf_close
1151 /* Disable Interrupts for VF */
1152 ecore_iov_vf_igu_set_int(p_hwfn, p_ptt, vf, 0);
1154 /* Reset Permission table */
1155 ecore_iov_config_perm_table(p_hwfn, p_ptt, vf, 0);
1159 ecore_iov_free_vf_igu_sbs(p_hwfn, p_ptt, vf);
1163 p_hwfn->pf_iov_info->active_vfs[vf->relative_vf_id / 64] &=
1164 ~(1ULL << (vf->relative_vf_id / 64));
1166 if (IS_LEAD_HWFN(p_hwfn))
1167 p_hwfn->p_dev->p_iov_info->num_vfs--;
1170 return ECORE_SUCCESS;
1173 static bool ecore_iov_tlv_supported(u16 tlvtype)
1175 return tlvtype > CHANNEL_TLV_NONE && tlvtype < CHANNEL_TLV_MAX;
1178 static void ecore_iov_lock_vf_pf_channel(struct ecore_hwfn *p_hwfn,
1179 struct ecore_vf_info *vf, u16 tlv)
1181 /* lock the channel */
1182 /* mutex_lock(&vf->op_mutex); @@@TBD MichalK - add lock... */
1184 /* record the locking op */
1185 /* vf->op_current = tlv; @@@TBD MichalK */
1188 if (ecore_iov_tlv_supported(tlv))
1191 "VF[%d]: vf pf channel locked by %s\n",
1193 ecore_channel_tlvs_string[tlv]);
1197 "VF[%d]: vf pf channel locked by %04x\n",
1198 vf->abs_vf_id, tlv);
1201 static void ecore_iov_unlock_vf_pf_channel(struct ecore_hwfn *p_hwfn,
1202 struct ecore_vf_info *vf,
1205 /* log the unlock */
1206 if (ecore_iov_tlv_supported(expected_tlv))
1209 "VF[%d]: vf pf channel unlocked by %s\n",
1211 ecore_channel_tlvs_string[expected_tlv]);
1215 "VF[%d]: vf pf channel unlocked by %04x\n",
1216 vf->abs_vf_id, expected_tlv);
1218 /* record the locking op */
1219 /* vf->op_current = CHANNEL_TLV_NONE; */
1222 /* place a given tlv on the tlv buffer, continuing current tlv list */
1223 void *ecore_add_tlv(struct ecore_hwfn *p_hwfn,
1224 u8 **offset, u16 type, u16 length)
1226 struct channel_tlv *tl = (struct channel_tlv *)*offset;
1229 tl->length = length;
1231 /* Offset should keep pointing to next TLV (the end of the last) */
1234 /* Return a pointer to the start of the added tlv */
1235 return *offset - length;
1238 /* list the types and lengths of the tlvs on the buffer */
1239 void ecore_dp_tlv_list(struct ecore_hwfn *p_hwfn, void *tlvs_list)
1241 u16 i = 1, total_length = 0;
1242 struct channel_tlv *tlv;
1245 /* cast current tlv list entry to channel tlv header */
1246 tlv = (struct channel_tlv *)((u8 *)tlvs_list + total_length);
1249 if (ecore_iov_tlv_supported(tlv->type))
1250 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1251 "TLV number %d: type %s, length %d\n",
1252 i, ecore_channel_tlvs_string[tlv->type],
1255 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1256 "TLV number %d: type %d, length %d\n",
1257 i, tlv->type, tlv->length);
1259 if (tlv->type == CHANNEL_TLV_LIST_END)
1262 /* Validate entry - protect against malicious VFs */
1264 DP_NOTICE(p_hwfn, false, "TLV of length 0 found\n");
1267 total_length += tlv->length;
1268 if (total_length >= sizeof(struct tlv_buffer_size)) {
1269 DP_NOTICE(p_hwfn, false, "TLV ==> Buffer overflow\n");
1277 static void ecore_iov_send_response(struct ecore_hwfn *p_hwfn,
1278 struct ecore_ptt *p_ptt,
1279 struct ecore_vf_info *p_vf,
1280 u16 length, u8 status)
1282 struct ecore_iov_vf_mbx *mbx = &p_vf->vf_mbx;
1283 struct ecore_dmae_params params;
1286 mbx->reply_virt->default_resp.hdr.status = status;
1288 ecore_dp_tlv_list(p_hwfn, mbx->reply_virt);
1290 #ifdef CONFIG_ECORE_SW_CHANNEL
1291 mbx->sw_mbx.response_size =
1292 length + sizeof(struct channel_list_end_tlv);
1294 if (!p_hwfn->p_dev->b_hw_channel)
1298 eng_vf_id = p_vf->abs_vf_id;
1300 OSAL_MEMSET(¶ms, 0, sizeof(struct ecore_dmae_params));
1301 params.flags = ECORE_DMAE_FLAG_VF_DST;
1302 params.dst_vfid = eng_vf_id;
1304 ecore_dmae_host2host(p_hwfn, p_ptt, mbx->reply_phys + sizeof(u64),
1305 mbx->req_virt->first_tlv.reply_address +
1307 (sizeof(union pfvf_tlvs) - sizeof(u64)) / 4,
1310 ecore_dmae_host2host(p_hwfn, p_ptt, mbx->reply_phys,
1311 mbx->req_virt->first_tlv.reply_address,
1312 sizeof(u64) / 4, ¶ms);
1315 GTT_BAR0_MAP_REG_USDM_RAM +
1316 USTORM_VF_PF_CHANNEL_READY_OFFSET(eng_vf_id), 1);
1319 static u16 ecore_iov_vport_to_tlv(struct ecore_hwfn *p_hwfn,
1320 enum ecore_iov_vport_update_flag flag)
1323 case ECORE_IOV_VP_UPDATE_ACTIVATE:
1324 return CHANNEL_TLV_VPORT_UPDATE_ACTIVATE;
1325 case ECORE_IOV_VP_UPDATE_VLAN_STRIP:
1326 return CHANNEL_TLV_VPORT_UPDATE_VLAN_STRIP;
1327 case ECORE_IOV_VP_UPDATE_TX_SWITCH:
1328 return CHANNEL_TLV_VPORT_UPDATE_TX_SWITCH;
1329 case ECORE_IOV_VP_UPDATE_MCAST:
1330 return CHANNEL_TLV_VPORT_UPDATE_MCAST;
1331 case ECORE_IOV_VP_UPDATE_ACCEPT_PARAM:
1332 return CHANNEL_TLV_VPORT_UPDATE_ACCEPT_PARAM;
1333 case ECORE_IOV_VP_UPDATE_RSS:
1334 return CHANNEL_TLV_VPORT_UPDATE_RSS;
1335 case ECORE_IOV_VP_UPDATE_ACCEPT_ANY_VLAN:
1336 return CHANNEL_TLV_VPORT_UPDATE_ACCEPT_ANY_VLAN;
1337 case ECORE_IOV_VP_UPDATE_SGE_TPA:
1338 return CHANNEL_TLV_VPORT_UPDATE_SGE_TPA;
1344 static u16 ecore_iov_prep_vp_update_resp_tlvs(struct ecore_hwfn *p_hwfn,
1345 struct ecore_vf_info *p_vf,
1346 struct ecore_iov_vf_mbx *p_mbx,
1347 u8 status, u16 tlvs_mask,
1350 struct pfvf_def_resp_tlv *resp;
1351 u16 size, total_len, i;
1353 OSAL_MEMSET(p_mbx->reply_virt, 0, sizeof(union pfvf_tlvs));
1354 p_mbx->offset = (u8 *)p_mbx->reply_virt;
1355 size = sizeof(struct pfvf_def_resp_tlv);
1358 ecore_add_tlv(p_hwfn, &p_mbx->offset, CHANNEL_TLV_VPORT_UPDATE, size);
1360 /* Prepare response for all extended tlvs if they are found by PF */
1361 for (i = 0; i < ECORE_IOV_VP_UPDATE_MAX; i++) {
1362 if (!(tlvs_mask & (1 << i)))
1365 resp = ecore_add_tlv(p_hwfn, &p_mbx->offset,
1366 ecore_iov_vport_to_tlv(p_hwfn, i), size);
1368 if (tlvs_accepted & (1 << i))
1369 resp->hdr.status = status;
1371 resp->hdr.status = PFVF_STATUS_NOT_SUPPORTED;
1373 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1374 "VF[%d] - vport_update resp: TLV %d, status %02x\n",
1375 p_vf->relative_vf_id,
1376 ecore_iov_vport_to_tlv(p_hwfn, i), resp->hdr.status);
1381 ecore_add_tlv(p_hwfn, &p_mbx->offset, CHANNEL_TLV_LIST_END,
1382 sizeof(struct channel_list_end_tlv));
1387 static void ecore_iov_prepare_resp(struct ecore_hwfn *p_hwfn,
1388 struct ecore_ptt *p_ptt,
1389 struct ecore_vf_info *vf_info,
1390 u16 type, u16 length, u8 status)
1392 struct ecore_iov_vf_mbx *mbx = &vf_info->vf_mbx;
1394 mbx->offset = (u8 *)mbx->reply_virt;
1396 ecore_add_tlv(p_hwfn, &mbx->offset, type, length);
1397 ecore_add_tlv(p_hwfn, &mbx->offset, CHANNEL_TLV_LIST_END,
1398 sizeof(struct channel_list_end_tlv));
1400 ecore_iov_send_response(p_hwfn, p_ptt, vf_info, length, status);
1402 OSAL_IOV_PF_RESP_TYPE(p_hwfn, vf_info->relative_vf_id, status);
1405 struct ecore_public_vf_info
1406 *ecore_iov_get_public_vf_info(struct ecore_hwfn *p_hwfn,
1408 bool b_enabled_only)
1410 struct ecore_vf_info *vf = OSAL_NULL;
1412 vf = ecore_iov_get_vf_info(p_hwfn, relative_vf_id, b_enabled_only);
1416 return &vf->p_vf_info;
1419 static void ecore_iov_vf_cleanup(struct ecore_hwfn *p_hwfn,
1420 struct ecore_vf_info *p_vf)
1423 p_vf->vf_bulletin = 0;
1424 p_vf->vport_instance = 0;
1425 p_vf->configured_features = 0;
1427 /* If VF previously requested less resources, go back to default */
1428 p_vf->num_rxqs = p_vf->num_sbs;
1429 p_vf->num_txqs = p_vf->num_sbs;
1431 p_vf->num_active_rxqs = 0;
1433 for (i = 0; i < ECORE_MAX_VF_CHAINS_PER_PF; i++) {
1434 struct ecore_vf_q_info *p_queue = &p_vf->vf_queues[i];
1436 if (p_queue->p_rx_cid) {
1437 ecore_eth_queue_cid_release(p_hwfn,
1439 p_queue->p_rx_cid = OSAL_NULL;
1442 if (p_queue->p_tx_cid) {
1443 ecore_eth_queue_cid_release(p_hwfn,
1445 p_queue->p_tx_cid = OSAL_NULL;
1449 OSAL_MEMSET(&p_vf->shadow_config, 0, sizeof(p_vf->shadow_config));
1450 OSAL_MEMSET(&p_vf->acquire, 0, sizeof(p_vf->acquire));
1451 OSAL_IOV_VF_CLEANUP(p_hwfn, p_vf->relative_vf_id);
1454 static u8 ecore_iov_vf_mbx_acquire_resc(struct ecore_hwfn *p_hwfn,
1455 struct ecore_ptt *p_ptt,
1456 struct ecore_vf_info *p_vf,
1457 struct vf_pf_resc_request *p_req,
1458 struct pf_vf_resc *p_resp)
1462 /* Queue related information */
1463 p_resp->num_rxqs = p_vf->num_rxqs;
1464 p_resp->num_txqs = p_vf->num_txqs;
1465 p_resp->num_sbs = p_vf->num_sbs;
1467 for (i = 0; i < p_resp->num_sbs; i++) {
1468 p_resp->hw_sbs[i].hw_sb_id = p_vf->igu_sbs[i];
1469 /* TODO - what's this sb_qid field? Is it deprecated?
1470 * or is there an ecore_client that looks at this?
1472 p_resp->hw_sbs[i].sb_qid = 0;
1475 /* These fields are filled for backward compatibility.
1476 * Unused by modern vfs.
1478 for (i = 0; i < p_resp->num_rxqs; i++) {
1479 ecore_fw_l2_queue(p_hwfn, p_vf->vf_queues[i].fw_rx_qid,
1480 (u16 *)&p_resp->hw_qid[i]);
1481 p_resp->cid[i] = p_vf->vf_queues[i].fw_cid;
1484 /* Filter related information */
1485 p_resp->num_mac_filters = OSAL_MIN_T(u8, p_vf->num_mac_filters,
1486 p_req->num_mac_filters);
1487 p_resp->num_vlan_filters = OSAL_MIN_T(u8, p_vf->num_vlan_filters,
1488 p_req->num_vlan_filters);
1490 /* This isn't really needed/enforced, but some legacy VFs might depend
1491 * on the correct filling of this field.
1493 p_resp->num_mc_filters = ECORE_MAX_MC_ADDRS;
1495 /* Validate sufficient resources for VF */
1496 if (p_resp->num_rxqs < p_req->num_rxqs ||
1497 p_resp->num_txqs < p_req->num_txqs ||
1498 p_resp->num_sbs < p_req->num_sbs ||
1499 p_resp->num_mac_filters < p_req->num_mac_filters ||
1500 p_resp->num_vlan_filters < p_req->num_vlan_filters ||
1501 p_resp->num_mc_filters < p_req->num_mc_filters) {
1502 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1503 "VF[%d] - Insufficient resources: rxq [%02x/%02x]"
1504 " txq [%02x/%02x] sbs [%02x/%02x] mac [%02x/%02x]"
1505 " vlan [%02x/%02x] mc [%02x/%02x]\n",
1507 p_req->num_rxqs, p_resp->num_rxqs,
1508 p_req->num_rxqs, p_resp->num_txqs,
1509 p_req->num_sbs, p_resp->num_sbs,
1510 p_req->num_mac_filters, p_resp->num_mac_filters,
1511 p_req->num_vlan_filters, p_resp->num_vlan_filters,
1512 p_req->num_mc_filters, p_resp->num_mc_filters);
1514 /* Some legacy OSes are incapable of correctly handling this
1517 if ((p_vf->acquire.vfdev_info.eth_fp_hsi_minor ==
1518 ETH_HSI_VER_NO_PKT_LEN_TUNN) &&
1519 (p_vf->acquire.vfdev_info.os_type ==
1520 VFPF_ACQUIRE_OS_WINDOWS))
1521 return PFVF_STATUS_SUCCESS;
1523 return PFVF_STATUS_NO_RESOURCE;
1526 return PFVF_STATUS_SUCCESS;
1529 static void ecore_iov_vf_mbx_acquire_stats(struct ecore_hwfn *p_hwfn,
1530 struct pfvf_stats_info *p_stats)
1532 p_stats->mstats.address = PXP_VF_BAR0_START_MSDM_ZONE_B +
1533 OFFSETOF(struct mstorm_vf_zone,
1534 non_trigger.eth_queue_stat);
1535 p_stats->mstats.len = sizeof(struct eth_mstorm_per_queue_stat);
1536 p_stats->ustats.address = PXP_VF_BAR0_START_USDM_ZONE_B +
1537 OFFSETOF(struct ustorm_vf_zone,
1538 non_trigger.eth_queue_stat);
1539 p_stats->ustats.len = sizeof(struct eth_ustorm_per_queue_stat);
1540 p_stats->pstats.address = PXP_VF_BAR0_START_PSDM_ZONE_B +
1541 OFFSETOF(struct pstorm_vf_zone,
1542 non_trigger.eth_queue_stat);
1543 p_stats->pstats.len = sizeof(struct eth_pstorm_per_queue_stat);
1544 p_stats->tstats.address = 0;
1545 p_stats->tstats.len = 0;
1548 static void ecore_iov_vf_mbx_acquire(struct ecore_hwfn *p_hwfn,
1549 struct ecore_ptt *p_ptt,
1550 struct ecore_vf_info *vf)
1552 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
1553 struct pfvf_acquire_resp_tlv *resp = &mbx->reply_virt->acquire_resp;
1554 struct pf_vf_pfdev_info *pfdev_info = &resp->pfdev_info;
1555 struct vfpf_acquire_tlv *req = &mbx->req_virt->acquire;
1556 u8 vfpf_status = PFVF_STATUS_NOT_SUPPORTED;
1557 struct pf_vf_resc *resc = &resp->resc;
1558 enum _ecore_status_t rc;
1560 OSAL_MEMSET(resp, 0, sizeof(*resp));
1562 /* Write the PF version so that VF would know which version
1563 * is supported - might be later overridden. This guarantees that
1564 * VF could recognize legacy PF based on lack of versions in reply.
1566 pfdev_info->major_fp_hsi = ETH_HSI_VER_MAJOR;
1567 pfdev_info->minor_fp_hsi = ETH_HSI_VER_MINOR;
1569 /* TODO - not doing anything is bad since we'll assert, but this isn't
1570 * necessarily the right behavior - perhaps we should have allowed some
1573 if (vf->state != VF_FREE &&
1574 vf->state != VF_STOPPED) {
1575 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1576 "VF[%d] sent ACQUIRE but is already in state %d - fail request\n",
1577 vf->abs_vf_id, vf->state);
1581 /* Validate FW compatibility */
1582 if (req->vfdev_info.eth_fp_hsi_major != ETH_HSI_VER_MAJOR) {
1583 if (req->vfdev_info.capabilities &
1584 VFPF_ACQUIRE_CAP_PRE_FP_HSI) {
1585 struct vf_pf_vfdev_info *p_vfdev = &req->vfdev_info;
1587 /* This legacy support would need to be removed once
1588 * the major has changed.
1590 OSAL_BUILD_BUG_ON(ETH_HSI_VER_MAJOR != 3);
1592 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1593 "VF[%d] is pre-fastpath HSI\n",
1595 p_vfdev->eth_fp_hsi_major = ETH_HSI_VER_MAJOR;
1596 p_vfdev->eth_fp_hsi_minor = ETH_HSI_VER_NO_PKT_LEN_TUNN;
1599 "VF[%d] needs fastpath HSI %02x.%02x, which is"
1600 " incompatible with loaded FW's faspath"
1603 req->vfdev_info.eth_fp_hsi_major,
1604 req->vfdev_info.eth_fp_hsi_minor,
1605 ETH_HSI_VER_MAJOR, ETH_HSI_VER_MINOR);
1611 /* On 100g PFs, prevent old VFs from loading */
1612 if ((p_hwfn->p_dev->num_hwfns > 1) &&
1613 !(req->vfdev_info.capabilities & VFPF_ACQUIRE_CAP_100G)) {
1615 "VF[%d] is running an old driver that doesn't support"
1621 #ifndef __EXTRACT__LINUX__
1622 if (OSAL_IOV_VF_ACQUIRE(p_hwfn, vf->relative_vf_id) != ECORE_SUCCESS) {
1623 vfpf_status = PFVF_STATUS_NOT_SUPPORTED;
1628 /* Store the acquire message */
1629 OSAL_MEMCPY(&vf->acquire, req, sizeof(vf->acquire));
1631 vf->opaque_fid = req->vfdev_info.opaque_fid;
1633 vf->vf_bulletin = req->bulletin_addr;
1634 vf->bulletin.size = (vf->bulletin.size < req->bulletin_size) ?
1635 vf->bulletin.size : req->bulletin_size;
1637 /* fill in pfdev info */
1638 pfdev_info->chip_num = p_hwfn->p_dev->chip_num;
1639 pfdev_info->db_size = 0; /* @@@ TBD MichalK Vf Doorbells */
1640 pfdev_info->indices_per_sb = PIS_PER_SB;
1642 pfdev_info->capabilities = PFVF_ACQUIRE_CAP_DEFAULT_UNTAGGED |
1643 PFVF_ACQUIRE_CAP_POST_FW_OVERRIDE;
1644 if (p_hwfn->p_dev->num_hwfns > 1)
1645 pfdev_info->capabilities |= PFVF_ACQUIRE_CAP_100G;
1647 ecore_iov_vf_mbx_acquire_stats(p_hwfn, &pfdev_info->stats_info);
1649 OSAL_MEMCPY(pfdev_info->port_mac, p_hwfn->hw_info.hw_mac_addr,
1652 pfdev_info->fw_major = FW_MAJOR_VERSION;
1653 pfdev_info->fw_minor = FW_MINOR_VERSION;
1654 pfdev_info->fw_rev = FW_REVISION_VERSION;
1655 pfdev_info->fw_eng = FW_ENGINEERING_VERSION;
1657 /* Incorrect when legacy, but doesn't matter as legacy isn't reading
1660 pfdev_info->minor_fp_hsi = OSAL_MIN_T(u8, ETH_HSI_VER_MINOR,
1661 req->vfdev_info.eth_fp_hsi_minor);
1662 pfdev_info->os_type = OSAL_IOV_GET_OS_TYPE();
1663 ecore_mcp_get_mfw_ver(p_hwfn, p_ptt, &pfdev_info->mfw_ver,
1666 pfdev_info->dev_type = p_hwfn->p_dev->type;
1667 pfdev_info->chip_rev = p_hwfn->p_dev->chip_rev;
1669 /* Fill resources available to VF; Make sure there are enough to
1670 * satisfy the VF's request.
1672 vfpf_status = ecore_iov_vf_mbx_acquire_resc(p_hwfn, p_ptt, vf,
1673 &req->resc_request, resc);
1674 if (vfpf_status != PFVF_STATUS_SUCCESS)
1677 /* Start the VF in FW */
1678 rc = ecore_sp_vf_start(p_hwfn, vf);
1679 if (rc != ECORE_SUCCESS) {
1680 DP_NOTICE(p_hwfn, true, "Failed to start VF[%02x]\n",
1682 vfpf_status = PFVF_STATUS_FAILURE;
1686 /* Fill agreed size of bulletin board in response, and post
1687 * an initial image to the bulletin board.
1689 resp->bulletin_size = vf->bulletin.size;
1690 ecore_iov_post_vf_bulletin(p_hwfn, vf->relative_vf_id, p_ptt);
1692 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1693 "VF[%d] ACQUIRE_RESPONSE: pfdev_info- chip_num=0x%x,"
1694 " db_size=%d, idx_per_sb=%d, pf_cap=0x%lx\n"
1695 "resources- n_rxq-%d, n_txq-%d, n_sbs-%d, n_macs-%d,"
1697 vf->abs_vf_id, resp->pfdev_info.chip_num,
1698 resp->pfdev_info.db_size, resp->pfdev_info.indices_per_sb,
1699 (unsigned long)resp->pfdev_info.capabilities, resc->num_rxqs,
1700 resc->num_txqs, resc->num_sbs, resc->num_mac_filters,
1701 resc->num_vlan_filters);
1703 vf->state = VF_ACQUIRED;
1706 /* Prepare Response */
1707 ecore_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_ACQUIRE,
1708 sizeof(struct pfvf_acquire_resp_tlv),
1712 static enum _ecore_status_t
1713 __ecore_iov_spoofchk_set(struct ecore_hwfn *p_hwfn,
1714 struct ecore_vf_info *p_vf, bool val)
1716 struct ecore_sp_vport_update_params params;
1717 enum _ecore_status_t rc;
1719 if (val == p_vf->spoof_chk) {
1720 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1721 "Spoofchk value[%d] is already configured\n", val);
1722 return ECORE_SUCCESS;
1725 OSAL_MEMSET(¶ms, 0, sizeof(struct ecore_sp_vport_update_params));
1726 params.opaque_fid = p_vf->opaque_fid;
1727 params.vport_id = p_vf->vport_id;
1728 params.update_anti_spoofing_en_flg = 1;
1729 params.anti_spoofing_en = val;
1731 rc = ecore_sp_vport_update(p_hwfn, ¶ms, ECORE_SPQ_MODE_EBLOCK,
1733 if (rc == ECORE_SUCCESS) {
1734 p_vf->spoof_chk = val;
1735 p_vf->req_spoofchk_val = p_vf->spoof_chk;
1736 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1737 "Spoofchk val[%d] configured\n", val);
1739 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1740 "Spoofchk configuration[val:%d] failed for VF[%d]\n",
1741 val, p_vf->relative_vf_id);
1747 static enum _ecore_status_t
1748 ecore_iov_reconfigure_unicast_vlan(struct ecore_hwfn *p_hwfn,
1749 struct ecore_vf_info *p_vf)
1751 struct ecore_filter_ucast filter;
1752 enum _ecore_status_t rc = ECORE_SUCCESS;
1755 OSAL_MEMSET(&filter, 0, sizeof(filter));
1756 filter.is_rx_filter = 1;
1757 filter.is_tx_filter = 1;
1758 filter.vport_to_add_to = p_vf->vport_id;
1759 filter.opcode = ECORE_FILTER_ADD;
1761 /* Reconfigure vlans */
1762 for (i = 0; i < ECORE_ETH_VF_NUM_VLAN_FILTERS + 1; i++) {
1763 if (!p_vf->shadow_config.vlans[i].used)
1766 filter.type = ECORE_FILTER_VLAN;
1767 filter.vlan = p_vf->shadow_config.vlans[i].vid;
1768 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1769 "Reconfiguring VLAN [0x%04x] for VF [%04x]\n",
1770 filter.vlan, p_vf->relative_vf_id);
1771 rc = ecore_sp_eth_filter_ucast(p_hwfn, p_vf->opaque_fid,
1772 &filter, ECORE_SPQ_MODE_CB,
1775 DP_NOTICE(p_hwfn, true,
1776 "Failed to configure VLAN [%04x]"
1778 filter.vlan, p_vf->relative_vf_id);
1786 static enum _ecore_status_t
1787 ecore_iov_reconfigure_unicast_shadow(struct ecore_hwfn *p_hwfn,
1788 struct ecore_vf_info *p_vf, u64 events)
1790 enum _ecore_status_t rc = ECORE_SUCCESS;
1792 /*TODO - what about MACs? */
1794 if ((events & (1 << VLAN_ADDR_FORCED)) &&
1795 !(p_vf->configured_features & (1 << VLAN_ADDR_FORCED)))
1796 rc = ecore_iov_reconfigure_unicast_vlan(p_hwfn, p_vf);
1801 static enum _ecore_status_t
1802 ecore_iov_configure_vport_forced(struct ecore_hwfn *p_hwfn,
1803 struct ecore_vf_info *p_vf,
1806 enum _ecore_status_t rc = ECORE_SUCCESS;
1807 struct ecore_filter_ucast filter;
1809 if (!p_vf->vport_instance)
1812 if (events & (1 << MAC_ADDR_FORCED)) {
1813 /* Since there's no way [currently] of removing the MAC,
1814 * we can always assume this means we need to force it.
1816 OSAL_MEMSET(&filter, 0, sizeof(filter));
1817 filter.type = ECORE_FILTER_MAC;
1818 filter.opcode = ECORE_FILTER_REPLACE;
1819 filter.is_rx_filter = 1;
1820 filter.is_tx_filter = 1;
1821 filter.vport_to_add_to = p_vf->vport_id;
1822 OSAL_MEMCPY(filter.mac, p_vf->bulletin.p_virt->mac, ETH_ALEN);
1824 rc = ecore_sp_eth_filter_ucast(p_hwfn, p_vf->opaque_fid,
1826 ECORE_SPQ_MODE_CB, OSAL_NULL);
1828 DP_NOTICE(p_hwfn, true,
1829 "PF failed to configure MAC for VF\n");
1833 p_vf->configured_features |= 1 << MAC_ADDR_FORCED;
1836 if (events & (1 << VLAN_ADDR_FORCED)) {
1837 struct ecore_sp_vport_update_params vport_update;
1841 OSAL_MEMSET(&filter, 0, sizeof(filter));
1842 filter.type = ECORE_FILTER_VLAN;
1843 filter.is_rx_filter = 1;
1844 filter.is_tx_filter = 1;
1845 filter.vport_to_add_to = p_vf->vport_id;
1846 filter.vlan = p_vf->bulletin.p_virt->pvid;
1847 filter.opcode = filter.vlan ? ECORE_FILTER_REPLACE :
1850 /* Send the ramrod */
1851 rc = ecore_sp_eth_filter_ucast(p_hwfn, p_vf->opaque_fid,
1853 ECORE_SPQ_MODE_CB, OSAL_NULL);
1855 DP_NOTICE(p_hwfn, true,
1856 "PF failed to configure VLAN for VF\n");
1860 /* Update the default-vlan & silent vlan stripping */
1861 OSAL_MEMSET(&vport_update, 0, sizeof(vport_update));
1862 vport_update.opaque_fid = p_vf->opaque_fid;
1863 vport_update.vport_id = p_vf->vport_id;
1864 vport_update.update_default_vlan_enable_flg = 1;
1865 vport_update.default_vlan_enable_flg = filter.vlan ? 1 : 0;
1866 vport_update.update_default_vlan_flg = 1;
1867 vport_update.default_vlan = filter.vlan;
1869 vport_update.update_inner_vlan_removal_flg = 1;
1870 removal = filter.vlan ?
1871 1 : p_vf->shadow_config.inner_vlan_removal;
1872 vport_update.inner_vlan_removal_flg = removal;
1873 vport_update.silent_vlan_removal_flg = filter.vlan ? 1 : 0;
1874 rc = ecore_sp_vport_update(p_hwfn, &vport_update,
1875 ECORE_SPQ_MODE_EBLOCK, OSAL_NULL);
1877 DP_NOTICE(p_hwfn, true,
1878 "PF failed to configure VF vport for vlan\n");
1882 /* Update all the Rx queues */
1883 for (i = 0; i < ECORE_MAX_VF_CHAINS_PER_PF; i++) {
1884 struct ecore_queue_cid *p_cid;
1886 p_cid = p_vf->vf_queues[i].p_rx_cid;
1887 if (p_cid == OSAL_NULL)
1890 rc = ecore_sp_eth_rx_queues_update(p_hwfn,
1893 ECORE_SPQ_MODE_EBLOCK,
1896 DP_NOTICE(p_hwfn, true,
1897 "Failed to send Rx update"
1898 " fo queue[0x%04x]\n",
1899 p_cid->rel.queue_id);
1905 p_vf->configured_features |= 1 << VLAN_ADDR_FORCED;
1907 p_vf->configured_features &= ~(1 << VLAN_ADDR_FORCED);
1910 /* If forced features are terminated, we need to configure the shadow
1911 * configuration back again.
1914 ecore_iov_reconfigure_unicast_shadow(p_hwfn, p_vf, events);
1919 static void ecore_iov_vf_mbx_start_vport(struct ecore_hwfn *p_hwfn,
1920 struct ecore_ptt *p_ptt,
1921 struct ecore_vf_info *vf)
1923 struct ecore_sp_vport_start_params params = { 0 };
1924 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
1925 struct vfpf_vport_start_tlv *start;
1926 u8 status = PFVF_STATUS_SUCCESS;
1927 struct ecore_vf_info *vf_info;
1930 enum _ecore_status_t rc;
1932 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vf->relative_vf_id, true);
1934 DP_NOTICE(p_hwfn->p_dev, true,
1935 "Failed to get VF info, invalid vfid [%d]\n",
1936 vf->relative_vf_id);
1940 vf->state = VF_ENABLED;
1941 start = &mbx->req_virt->start_vport;
1943 ecore_iov_enable_vf_traffic(p_hwfn, p_ptt, vf);
1945 /* Initialize Status block in CAU */
1946 for (sb_id = 0; sb_id < vf->num_sbs; sb_id++) {
1947 if (!start->sb_addr[sb_id]) {
1948 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1949 "VF[%d] did not fill the address of SB %d\n",
1950 vf->relative_vf_id, sb_id);
1954 ecore_int_cau_conf_sb(p_hwfn, p_ptt,
1955 start->sb_addr[sb_id],
1960 vf->mtu = start->mtu;
1961 vf->shadow_config.inner_vlan_removal = start->inner_vlan_removal;
1963 /* Take into consideration configuration forced by hypervisor;
1964 * If none is configured, use the supplied VF values [for old
1965 * vfs that would still be fine, since they passed '0' as padding].
1967 p_bitmap = &vf_info->bulletin.p_virt->valid_bitmap;
1968 if (!(*p_bitmap & (1 << VFPF_BULLETIN_UNTAGGED_DEFAULT_FORCED))) {
1969 u8 vf_req = start->only_untagged;
1971 vf_info->bulletin.p_virt->default_only_untagged = vf_req;
1972 *p_bitmap |= 1 << VFPF_BULLETIN_UNTAGGED_DEFAULT;
1975 params.tpa_mode = start->tpa_mode;
1976 params.remove_inner_vlan = start->inner_vlan_removal;
1977 params.tx_switching = true;
1980 if (CHIP_REV_IS_FPGA(p_hwfn->p_dev)) {
1981 DP_NOTICE(p_hwfn, false,
1982 "FPGA: Don't config VF for Tx-switching [no pVFC]\n");
1983 params.tx_switching = false;
1987 params.only_untagged = vf_info->bulletin.p_virt->default_only_untagged;
1988 params.drop_ttl0 = false;
1989 params.concrete_fid = vf->concrete_fid;
1990 params.opaque_fid = vf->opaque_fid;
1991 params.vport_id = vf->vport_id;
1992 params.max_buffers_per_cqe = start->max_buffers_per_cqe;
1993 params.mtu = vf->mtu;
1994 params.check_mac = true;
1996 rc = ecore_sp_eth_vport_start(p_hwfn, ¶ms);
1997 if (rc != ECORE_SUCCESS) {
1999 "ecore_iov_vf_mbx_start_vport returned error %d\n", rc);
2000 status = PFVF_STATUS_FAILURE;
2002 vf->vport_instance++;
2004 /* Force configuration if needed on the newly opened vport */
2005 ecore_iov_configure_vport_forced(p_hwfn, vf, *p_bitmap);
2006 OSAL_IOV_POST_START_VPORT(p_hwfn, vf->relative_vf_id,
2007 vf->vport_id, vf->opaque_fid);
2008 __ecore_iov_spoofchk_set(p_hwfn, vf, vf->req_spoofchk_val);
2011 ecore_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_VPORT_START,
2012 sizeof(struct pfvf_def_resp_tlv), status);
2015 static void ecore_iov_vf_mbx_stop_vport(struct ecore_hwfn *p_hwfn,
2016 struct ecore_ptt *p_ptt,
2017 struct ecore_vf_info *vf)
2019 u8 status = PFVF_STATUS_SUCCESS;
2020 enum _ecore_status_t rc;
2022 vf->vport_instance--;
2023 vf->spoof_chk = false;
2025 if ((ecore_iov_validate_active_rxq(p_hwfn, vf)) ||
2026 (ecore_iov_validate_active_txq(p_hwfn, vf))) {
2027 vf->b_malicious = true;
2028 DP_NOTICE(p_hwfn, false,
2029 "VF [%02x] - considered malicious;"
2030 " Unable to stop RX/TX queuess\n",
2034 rc = ecore_sp_vport_stop(p_hwfn, vf->opaque_fid, vf->vport_id);
2035 if (rc != ECORE_SUCCESS) {
2037 "ecore_iov_vf_mbx_stop_vport returned error %d\n", rc);
2038 status = PFVF_STATUS_FAILURE;
2041 /* Forget the configuration on the vport */
2042 vf->configured_features = 0;
2043 OSAL_MEMSET(&vf->shadow_config, 0, sizeof(vf->shadow_config));
2045 ecore_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_VPORT_TEARDOWN,
2046 sizeof(struct pfvf_def_resp_tlv), status);
2049 static void ecore_iov_vf_mbx_start_rxq_resp(struct ecore_hwfn *p_hwfn,
2050 struct ecore_ptt *p_ptt,
2051 struct ecore_vf_info *vf,
2052 u8 status, bool b_legacy)
2054 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
2055 struct pfvf_start_queue_resp_tlv *p_tlv;
2056 struct vfpf_start_rxq_tlv *req;
2059 mbx->offset = (u8 *)mbx->reply_virt;
2061 /* Taking a bigger struct instead of adding a TLV to list was a
2062 * mistake, but one which we're now stuck with, as some older
2063 * clients assume the size of the previous response.
2066 length = sizeof(*p_tlv);
2068 length = sizeof(struct pfvf_def_resp_tlv);
2070 p_tlv = ecore_add_tlv(p_hwfn, &mbx->offset, CHANNEL_TLV_START_RXQ,
2072 ecore_add_tlv(p_hwfn, &mbx->offset, CHANNEL_TLV_LIST_END,
2073 sizeof(struct channel_list_end_tlv));
2075 /* Update the TLV with the response */
2076 if ((status == PFVF_STATUS_SUCCESS) && !b_legacy) {
2077 req = &mbx->req_virt->start_rxq;
2078 p_tlv->offset = PXP_VF_BAR0_START_MSDM_ZONE_B +
2079 OFFSETOF(struct mstorm_vf_zone,
2080 non_trigger.eth_rx_queue_producers) +
2081 sizeof(struct eth_rx_prod_data) * req->rx_qid;
2084 ecore_iov_send_response(p_hwfn, p_ptt, vf, length, status);
2087 static void ecore_iov_vf_mbx_start_rxq(struct ecore_hwfn *p_hwfn,
2088 struct ecore_ptt *p_ptt,
2089 struct ecore_vf_info *vf)
2091 struct ecore_queue_start_common_params params;
2092 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
2093 u8 status = PFVF_STATUS_NO_RESOURCE;
2094 struct ecore_vf_q_info *p_queue;
2095 struct vfpf_start_rxq_tlv *req;
2096 bool b_legacy_vf = false;
2097 enum _ecore_status_t rc;
2099 req = &mbx->req_virt->start_rxq;
2101 if (!ecore_iov_validate_rxq(p_hwfn, vf, req->rx_qid) ||
2102 !ecore_iov_validate_sb(p_hwfn, vf, req->hw_sb))
2105 /* Acquire a new queue-cid */
2106 p_queue = &vf->vf_queues[req->rx_qid];
2108 OSAL_MEMSET(¶ms, 0, sizeof(params));
2109 params.queue_id = (u8)p_queue->fw_rx_qid;
2110 params.vport_id = vf->vport_id;
2111 params.stats_id = vf->abs_vf_id + 0x10;
2112 params.sb = req->hw_sb;
2113 params.sb_idx = req->sb_index;
2115 p_queue->p_rx_cid = _ecore_eth_queue_to_cid(p_hwfn,
2120 if (p_queue->p_rx_cid == OSAL_NULL)
2123 /* Legacy VFs have their Producers in a different location, which they
2124 * calculate on their own and clean the producer prior to this.
2126 if (vf->acquire.vfdev_info.eth_fp_hsi_minor ==
2127 ETH_HSI_VER_NO_PKT_LEN_TUNN)
2131 GTT_BAR0_MAP_REG_MSDM_RAM +
2132 MSTORM_ETH_VF_PRODS_OFFSET(vf->abs_vf_id, req->rx_qid),
2134 p_queue->p_rx_cid->b_legacy_vf = b_legacy_vf;
2137 rc = ecore_eth_rxq_start_ramrod(p_hwfn,
2143 if (rc != ECORE_SUCCESS) {
2144 status = PFVF_STATUS_FAILURE;
2145 ecore_eth_queue_cid_release(p_hwfn, p_queue->p_rx_cid);
2146 p_queue->p_rx_cid = OSAL_NULL;
2148 status = PFVF_STATUS_SUCCESS;
2149 vf->num_active_rxqs++;
2153 ecore_iov_vf_mbx_start_rxq_resp(p_hwfn, p_ptt, vf, status,
2158 ecore_iov_pf_update_tun_response(struct pfvf_update_tunn_param_tlv *p_resp,
2159 struct ecore_tunnel_info *p_tun,
2160 u16 tunn_feature_mask)
2162 p_resp->tunn_feature_mask = tunn_feature_mask;
2163 p_resp->vxlan_mode = p_tun->vxlan.b_mode_enabled;
2164 p_resp->l2geneve_mode = p_tun->l2_geneve.b_mode_enabled;
2165 p_resp->ipgeneve_mode = p_tun->ip_geneve.b_mode_enabled;
2166 p_resp->l2gre_mode = p_tun->l2_gre.b_mode_enabled;
2167 p_resp->ipgre_mode = p_tun->l2_gre.b_mode_enabled;
2168 p_resp->vxlan_clss = p_tun->vxlan.tun_cls;
2169 p_resp->l2gre_clss = p_tun->l2_gre.tun_cls;
2170 p_resp->ipgre_clss = p_tun->ip_gre.tun_cls;
2171 p_resp->l2geneve_clss = p_tun->l2_geneve.tun_cls;
2172 p_resp->ipgeneve_clss = p_tun->ip_geneve.tun_cls;
2173 p_resp->geneve_udp_port = p_tun->geneve_port.port;
2174 p_resp->vxlan_udp_port = p_tun->vxlan_port.port;
2178 __ecore_iov_pf_update_tun_param(struct vfpf_update_tunn_param_tlv *p_req,
2179 struct ecore_tunn_update_type *p_tun,
2180 enum ecore_tunn_mode mask, u8 tun_cls)
2182 if (p_req->tun_mode_update_mask & (1 << mask)) {
2183 p_tun->b_update_mode = true;
2185 if (p_req->tunn_mode & (1 << mask))
2186 p_tun->b_mode_enabled = true;
2189 p_tun->tun_cls = tun_cls;
2193 ecore_iov_pf_update_tun_param(struct vfpf_update_tunn_param_tlv *p_req,
2194 struct ecore_tunn_update_type *p_tun,
2195 struct ecore_tunn_update_udp_port *p_port,
2196 enum ecore_tunn_mode mask,
2197 u8 tun_cls, u8 update_port, u16 port)
2200 p_port->b_update_port = true;
2201 p_port->port = port;
2204 __ecore_iov_pf_update_tun_param(p_req, p_tun, mask, tun_cls);
2208 ecore_iov_pf_validate_tunn_param(struct vfpf_update_tunn_param_tlv *p_req)
2210 bool b_update_requested = false;
2212 if (p_req->tun_mode_update_mask || p_req->update_tun_cls ||
2213 p_req->update_geneve_port || p_req->update_vxlan_port)
2214 b_update_requested = true;
2216 return b_update_requested;
2219 static void ecore_iov_vf_mbx_update_tunn_param(struct ecore_hwfn *p_hwfn,
2220 struct ecore_ptt *p_ptt,
2221 struct ecore_vf_info *p_vf)
2223 struct ecore_tunnel_info *p_tun = &p_hwfn->p_dev->tunnel;
2224 struct ecore_iov_vf_mbx *mbx = &p_vf->vf_mbx;
2225 struct pfvf_update_tunn_param_tlv *p_resp;
2226 struct vfpf_update_tunn_param_tlv *p_req;
2227 enum _ecore_status_t rc = ECORE_SUCCESS;
2228 u8 status = PFVF_STATUS_SUCCESS;
2229 bool b_update_required = false;
2230 struct ecore_tunnel_info tunn;
2231 u16 tunn_feature_mask = 0;
2233 mbx->offset = (u8 *)mbx->reply_virt;
2235 OSAL_MEM_ZERO(&tunn, sizeof(tunn));
2236 p_req = &mbx->req_virt->tunn_param_update;
2238 if (!ecore_iov_pf_validate_tunn_param(p_req)) {
2239 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2240 "No tunnel update requested by VF\n");
2241 status = PFVF_STATUS_FAILURE;
2245 tunn.b_update_rx_cls = p_req->update_tun_cls;
2246 tunn.b_update_tx_cls = p_req->update_tun_cls;
2248 ecore_iov_pf_update_tun_param(p_req, &tunn.vxlan, &tunn.vxlan_port,
2249 ECORE_MODE_VXLAN_TUNN, p_req->vxlan_clss,
2250 p_req->update_vxlan_port,
2252 ecore_iov_pf_update_tun_param(p_req, &tunn.l2_geneve, &tunn.geneve_port,
2253 ECORE_MODE_L2GENEVE_TUNN,
2254 p_req->l2geneve_clss,
2255 p_req->update_geneve_port,
2256 p_req->geneve_port);
2257 __ecore_iov_pf_update_tun_param(p_req, &tunn.ip_geneve,
2258 ECORE_MODE_IPGENEVE_TUNN,
2259 p_req->ipgeneve_clss);
2260 __ecore_iov_pf_update_tun_param(p_req, &tunn.l2_gre,
2261 ECORE_MODE_L2GRE_TUNN,
2263 __ecore_iov_pf_update_tun_param(p_req, &tunn.ip_gre,
2264 ECORE_MODE_IPGRE_TUNN,
2267 /* If PF modifies VF's req then it should
2268 * still return an error in case of partial configuration
2269 * or modified configuration as opposed to requested one.
2271 rc = OSAL_PF_VALIDATE_MODIFY_TUNN_CONFIG(p_hwfn, &tunn_feature_mask,
2272 &b_update_required, &tunn);
2274 if (rc != ECORE_SUCCESS)
2275 status = PFVF_STATUS_FAILURE;
2277 /* If ECORE client is willing to update anything ? */
2278 if (b_update_required) {
2279 rc = ecore_sp_pf_update_tunn_cfg(p_hwfn, &tunn,
2280 ECORE_SPQ_MODE_EBLOCK,
2282 if (rc != ECORE_SUCCESS)
2283 status = PFVF_STATUS_FAILURE;
2287 p_resp = ecore_add_tlv(p_hwfn, &mbx->offset,
2288 CHANNEL_TLV_UPDATE_TUNN_PARAM, sizeof(*p_resp));
2290 ecore_iov_pf_update_tun_response(p_resp, p_tun, tunn_feature_mask);
2291 ecore_add_tlv(p_hwfn, &mbx->offset, CHANNEL_TLV_LIST_END,
2292 sizeof(struct channel_list_end_tlv));
2294 ecore_iov_send_response(p_hwfn, p_ptt, p_vf, sizeof(*p_resp), status);
2297 static void ecore_iov_vf_mbx_start_txq_resp(struct ecore_hwfn *p_hwfn,
2298 struct ecore_ptt *p_ptt,
2299 struct ecore_vf_info *p_vf,
2302 struct ecore_iov_vf_mbx *mbx = &p_vf->vf_mbx;
2303 struct pfvf_start_queue_resp_tlv *p_tlv;
2304 bool b_legacy = false;
2307 mbx->offset = (u8 *)mbx->reply_virt;
2309 /* Taking a bigger struct instead of adding a TLV to list was a
2310 * mistake, but one which we're now stuck with, as some older
2311 * clients assume the size of the previous response.
2313 if (p_vf->acquire.vfdev_info.eth_fp_hsi_minor ==
2314 ETH_HSI_VER_NO_PKT_LEN_TUNN)
2318 length = sizeof(*p_tlv);
2320 length = sizeof(struct pfvf_def_resp_tlv);
2322 p_tlv = ecore_add_tlv(p_hwfn, &mbx->offset, CHANNEL_TLV_START_TXQ,
2324 ecore_add_tlv(p_hwfn, &mbx->offset, CHANNEL_TLV_LIST_END,
2325 sizeof(struct channel_list_end_tlv));
2327 /* Update the TLV with the response */
2328 if ((status == PFVF_STATUS_SUCCESS) && !b_legacy) {
2329 u16 qid = mbx->req_virt->start_txq.tx_qid;
2331 p_tlv->offset = DB_ADDR_VF(p_vf->vf_queues[qid].fw_cid,
2335 ecore_iov_send_response(p_hwfn, p_ptt, p_vf, length, status);
2338 static void ecore_iov_vf_mbx_start_txq(struct ecore_hwfn *p_hwfn,
2339 struct ecore_ptt *p_ptt,
2340 struct ecore_vf_info *vf)
2342 struct ecore_queue_start_common_params params;
2343 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
2344 u8 status = PFVF_STATUS_NO_RESOURCE;
2345 struct ecore_vf_q_info *p_queue;
2346 struct vfpf_start_txq_tlv *req;
2347 enum _ecore_status_t rc;
2350 OSAL_MEMSET(¶ms, 0, sizeof(params));
2351 req = &mbx->req_virt->start_txq;
2353 if (!ecore_iov_validate_txq(p_hwfn, vf, req->tx_qid) ||
2354 !ecore_iov_validate_sb(p_hwfn, vf, req->hw_sb))
2357 /* Acquire a new queue-cid */
2358 p_queue = &vf->vf_queues[req->tx_qid];
2360 params.queue_id = p_queue->fw_tx_qid;
2361 params.vport_id = vf->vport_id;
2362 params.stats_id = vf->abs_vf_id + 0x10;
2363 params.sb = req->hw_sb;
2364 params.sb_idx = req->sb_index;
2366 p_queue->p_tx_cid = _ecore_eth_queue_to_cid(p_hwfn,
2371 if (p_queue->p_tx_cid == OSAL_NULL)
2374 pq = ecore_get_cm_pq_idx_vf(p_hwfn,
2375 vf->relative_vf_id);
2376 rc = ecore_eth_txq_start_ramrod(p_hwfn, p_queue->p_tx_cid,
2377 req->pbl_addr, req->pbl_size, pq);
2378 if (rc != ECORE_SUCCESS) {
2379 status = PFVF_STATUS_FAILURE;
2380 ecore_eth_queue_cid_release(p_hwfn,
2382 p_queue->p_tx_cid = OSAL_NULL;
2384 status = PFVF_STATUS_SUCCESS;
2388 ecore_iov_vf_mbx_start_txq_resp(p_hwfn, p_ptt, vf, status);
2391 static enum _ecore_status_t ecore_iov_vf_stop_rxqs(struct ecore_hwfn *p_hwfn,
2392 struct ecore_vf_info *vf,
2395 bool cqe_completion)
2397 struct ecore_vf_q_info *p_queue;
2398 enum _ecore_status_t rc = ECORE_SUCCESS;
2401 if (rxq_id + num_rxqs > OSAL_ARRAY_SIZE(vf->vf_queues))
2404 for (qid = rxq_id; qid < rxq_id + num_rxqs; qid++) {
2405 p_queue = &vf->vf_queues[qid];
2407 if (!p_queue->p_rx_cid)
2410 rc = ecore_eth_rx_queue_stop(p_hwfn,
2412 false, cqe_completion);
2413 if (rc != ECORE_SUCCESS)
2416 vf->vf_queues[qid].p_rx_cid = OSAL_NULL;
2417 vf->num_active_rxqs--;
2423 static enum _ecore_status_t ecore_iov_vf_stop_txqs(struct ecore_hwfn *p_hwfn,
2424 struct ecore_vf_info *vf,
2425 u16 txq_id, u8 num_txqs)
2427 enum _ecore_status_t rc = ECORE_SUCCESS;
2428 struct ecore_vf_q_info *p_queue;
2431 if (txq_id + num_txqs > OSAL_ARRAY_SIZE(vf->vf_queues))
2434 for (qid = txq_id; qid < txq_id + num_txqs; qid++) {
2435 p_queue = &vf->vf_queues[qid];
2436 if (!p_queue->p_tx_cid)
2439 rc = ecore_eth_tx_queue_stop(p_hwfn,
2441 if (rc != ECORE_SUCCESS)
2444 p_queue->p_tx_cid = OSAL_NULL;
2449 static void ecore_iov_vf_mbx_stop_rxqs(struct ecore_hwfn *p_hwfn,
2450 struct ecore_ptt *p_ptt,
2451 struct ecore_vf_info *vf)
2453 u16 length = sizeof(struct pfvf_def_resp_tlv);
2454 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
2455 u8 status = PFVF_STATUS_SUCCESS;
2456 struct vfpf_stop_rxqs_tlv *req;
2457 enum _ecore_status_t rc;
2459 /* We give the option of starting from qid != 0, in this case we
2460 * need to make sure that qid + num_qs doesn't exceed the actual
2461 * amount of queues that exist.
2463 req = &mbx->req_virt->stop_rxqs;
2464 rc = ecore_iov_vf_stop_rxqs(p_hwfn, vf, req->rx_qid,
2465 req->num_rxqs, req->cqe_completion);
2467 status = PFVF_STATUS_FAILURE;
2469 ecore_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_STOP_RXQS,
2473 static void ecore_iov_vf_mbx_stop_txqs(struct ecore_hwfn *p_hwfn,
2474 struct ecore_ptt *p_ptt,
2475 struct ecore_vf_info *vf)
2477 u16 length = sizeof(struct pfvf_def_resp_tlv);
2478 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
2479 u8 status = PFVF_STATUS_SUCCESS;
2480 struct vfpf_stop_txqs_tlv *req;
2481 enum _ecore_status_t rc;
2483 /* We give the option of starting from qid != 0, in this case we
2484 * need to make sure that qid + num_qs doesn't exceed the actual
2485 * amount of queues that exist.
2487 req = &mbx->req_virt->stop_txqs;
2488 rc = ecore_iov_vf_stop_txqs(p_hwfn, vf, req->tx_qid, req->num_txqs);
2490 status = PFVF_STATUS_FAILURE;
2492 ecore_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_STOP_TXQS,
2496 static void ecore_iov_vf_mbx_update_rxqs(struct ecore_hwfn *p_hwfn,
2497 struct ecore_ptt *p_ptt,
2498 struct ecore_vf_info *vf)
2500 struct ecore_queue_cid *handlers[ECORE_MAX_VF_CHAINS_PER_PF];
2501 u16 length = sizeof(struct pfvf_def_resp_tlv);
2502 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
2503 struct vfpf_update_rxq_tlv *req;
2504 u8 status = PFVF_STATUS_FAILURE;
2505 u8 complete_event_flg;
2506 u8 complete_cqe_flg;
2508 enum _ecore_status_t rc;
2511 req = &mbx->req_virt->update_rxq;
2512 complete_cqe_flg = !!(req->flags & VFPF_RXQ_UPD_COMPLETE_CQE_FLAG);
2513 complete_event_flg = !!(req->flags & VFPF_RXQ_UPD_COMPLETE_EVENT_FLAG);
2515 /* Validaute inputs */
2516 if (req->num_rxqs + req->rx_qid > ECORE_MAX_VF_CHAINS_PER_PF ||
2517 !ecore_iov_validate_rxq(p_hwfn, vf, req->rx_qid)) {
2518 DP_INFO(p_hwfn, "VF[%d]: Incorrect Rxqs [%04x, %02x]\n",
2519 vf->relative_vf_id, req->rx_qid, req->num_rxqs);
2523 for (i = 0; i < req->num_rxqs; i++) {
2524 qid = req->rx_qid + i;
2526 if (!vf->vf_queues[qid].p_rx_cid) {
2528 "VF[%d] rx_qid = %d isn`t active!\n",
2529 vf->relative_vf_id, qid);
2533 handlers[i] = vf->vf_queues[qid].p_rx_cid;
2536 rc = ecore_sp_eth_rx_queues_update(p_hwfn, (void **)&handlers,
2540 ECORE_SPQ_MODE_EBLOCK,
2545 status = PFVF_STATUS_SUCCESS;
2547 ecore_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_UPDATE_RXQ,
2551 void *ecore_iov_search_list_tlvs(struct ecore_hwfn *p_hwfn,
2552 void *p_tlvs_list, u16 req_type)
2554 struct channel_tlv *p_tlv = (struct channel_tlv *)p_tlvs_list;
2558 if (!p_tlv->length) {
2559 DP_NOTICE(p_hwfn, true, "Zero length TLV found\n");
2563 if (p_tlv->type == req_type) {
2564 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2565 "Extended tlv type %s, length %d found\n",
2566 ecore_channel_tlvs_string[p_tlv->type],
2571 len += p_tlv->length;
2572 p_tlv = (struct channel_tlv *)((u8 *)p_tlv + p_tlv->length);
2574 if ((len + p_tlv->length) > TLV_BUFFER_SIZE) {
2575 DP_NOTICE(p_hwfn, true,
2576 "TLVs has overrun the buffer size\n");
2579 } while (p_tlv->type != CHANNEL_TLV_LIST_END);
2585 ecore_iov_vp_update_act_param(struct ecore_hwfn *p_hwfn,
2586 struct ecore_sp_vport_update_params *p_data,
2587 struct ecore_iov_vf_mbx *p_mbx, u16 *tlvs_mask)
2589 struct vfpf_vport_update_activate_tlv *p_act_tlv;
2590 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_ACTIVATE;
2592 p_act_tlv = (struct vfpf_vport_update_activate_tlv *)
2593 ecore_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
2597 p_data->update_vport_active_rx_flg = p_act_tlv->update_rx;
2598 p_data->vport_active_rx_flg = p_act_tlv->active_rx;
2599 p_data->update_vport_active_tx_flg = p_act_tlv->update_tx;
2600 p_data->vport_active_tx_flg = p_act_tlv->active_tx;
2601 *tlvs_mask |= 1 << ECORE_IOV_VP_UPDATE_ACTIVATE;
2605 ecore_iov_vp_update_vlan_param(struct ecore_hwfn *p_hwfn,
2606 struct ecore_sp_vport_update_params *p_data,
2607 struct ecore_vf_info *p_vf,
2608 struct ecore_iov_vf_mbx *p_mbx, u16 *tlvs_mask)
2610 struct vfpf_vport_update_vlan_strip_tlv *p_vlan_tlv;
2611 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_VLAN_STRIP;
2613 p_vlan_tlv = (struct vfpf_vport_update_vlan_strip_tlv *)
2614 ecore_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
2618 p_vf->shadow_config.inner_vlan_removal = p_vlan_tlv->remove_vlan;
2620 /* Ignore the VF request if we're forcing a vlan */
2621 if (!(p_vf->configured_features & (1 << VLAN_ADDR_FORCED))) {
2622 p_data->update_inner_vlan_removal_flg = 1;
2623 p_data->inner_vlan_removal_flg = p_vlan_tlv->remove_vlan;
2626 *tlvs_mask |= 1 << ECORE_IOV_VP_UPDATE_VLAN_STRIP;
2630 ecore_iov_vp_update_tx_switch(struct ecore_hwfn *p_hwfn,
2631 struct ecore_sp_vport_update_params *p_data,
2632 struct ecore_iov_vf_mbx *p_mbx, u16 *tlvs_mask)
2634 struct vfpf_vport_update_tx_switch_tlv *p_tx_switch_tlv;
2635 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_TX_SWITCH;
2637 p_tx_switch_tlv = (struct vfpf_vport_update_tx_switch_tlv *)
2638 ecore_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
2639 if (!p_tx_switch_tlv)
2643 if (CHIP_REV_IS_FPGA(p_hwfn->p_dev)) {
2644 DP_NOTICE(p_hwfn, false,
2645 "FPGA: Ignore tx-switching configuration originating"
2651 p_data->update_tx_switching_flg = 1;
2652 p_data->tx_switching_flg = p_tx_switch_tlv->tx_switching;
2653 *tlvs_mask |= 1 << ECORE_IOV_VP_UPDATE_TX_SWITCH;
2657 ecore_iov_vp_update_mcast_bin_param(struct ecore_hwfn *p_hwfn,
2658 struct ecore_sp_vport_update_params *p_data,
2659 struct ecore_iov_vf_mbx *p_mbx,
2662 struct vfpf_vport_update_mcast_bin_tlv *p_mcast_tlv;
2663 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_MCAST;
2665 p_mcast_tlv = (struct vfpf_vport_update_mcast_bin_tlv *)
2666 ecore_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
2670 p_data->update_approx_mcast_flg = 1;
2671 OSAL_MEMCPY(p_data->bins, p_mcast_tlv->bins,
2672 sizeof(unsigned long) *
2673 ETH_MULTICAST_MAC_BINS_IN_REGS);
2674 *tlvs_mask |= 1 << ECORE_IOV_VP_UPDATE_MCAST;
2678 ecore_iov_vp_update_accept_flag(struct ecore_hwfn *p_hwfn,
2679 struct ecore_sp_vport_update_params *p_data,
2680 struct ecore_iov_vf_mbx *p_mbx, u16 *tlvs_mask)
2682 struct ecore_filter_accept_flags *p_flags = &p_data->accept_flags;
2683 struct vfpf_vport_update_accept_param_tlv *p_accept_tlv;
2684 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_ACCEPT_PARAM;
2686 p_accept_tlv = (struct vfpf_vport_update_accept_param_tlv *)
2687 ecore_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
2691 p_flags->update_rx_mode_config = p_accept_tlv->update_rx_mode;
2692 p_flags->rx_accept_filter = p_accept_tlv->rx_accept_filter;
2693 p_flags->update_tx_mode_config = p_accept_tlv->update_tx_mode;
2694 p_flags->tx_accept_filter = p_accept_tlv->tx_accept_filter;
2695 *tlvs_mask |= 1 << ECORE_IOV_VP_UPDATE_ACCEPT_PARAM;
2699 ecore_iov_vp_update_accept_any_vlan(struct ecore_hwfn *p_hwfn,
2700 struct ecore_sp_vport_update_params *p_data,
2701 struct ecore_iov_vf_mbx *p_mbx,
2704 struct vfpf_vport_update_accept_any_vlan_tlv *p_accept_any_vlan;
2705 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_ACCEPT_ANY_VLAN;
2707 p_accept_any_vlan = (struct vfpf_vport_update_accept_any_vlan_tlv *)
2708 ecore_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
2709 if (!p_accept_any_vlan)
2712 p_data->accept_any_vlan = p_accept_any_vlan->accept_any_vlan;
2713 p_data->update_accept_any_vlan_flg =
2714 p_accept_any_vlan->update_accept_any_vlan_flg;
2715 *tlvs_mask |= 1 << ECORE_IOV_VP_UPDATE_ACCEPT_ANY_VLAN;
2719 ecore_iov_vp_update_rss_param(struct ecore_hwfn *p_hwfn,
2720 struct ecore_vf_info *vf,
2721 struct ecore_sp_vport_update_params *p_data,
2722 struct ecore_rss_params *p_rss,
2723 struct ecore_iov_vf_mbx *p_mbx,
2724 u16 *tlvs_mask, u16 *tlvs_accepted)
2726 struct vfpf_vport_update_rss_tlv *p_rss_tlv;
2727 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_RSS;
2728 bool b_reject = false;
2732 p_rss_tlv = (struct vfpf_vport_update_rss_tlv *)
2733 ecore_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
2735 p_data->rss_params = OSAL_NULL;
2739 OSAL_MEMSET(p_rss, 0, sizeof(struct ecore_rss_params));
2741 p_rss->update_rss_config =
2742 !!(p_rss_tlv->update_rss_flags &
2743 VFPF_UPDATE_RSS_CONFIG_FLAG);
2744 p_rss->update_rss_capabilities =
2745 !!(p_rss_tlv->update_rss_flags &
2746 VFPF_UPDATE_RSS_CAPS_FLAG);
2747 p_rss->update_rss_ind_table =
2748 !!(p_rss_tlv->update_rss_flags &
2749 VFPF_UPDATE_RSS_IND_TABLE_FLAG);
2750 p_rss->update_rss_key =
2751 !!(p_rss_tlv->update_rss_flags &
2752 VFPF_UPDATE_RSS_KEY_FLAG);
2754 p_rss->rss_enable = p_rss_tlv->rss_enable;
2755 p_rss->rss_eng_id = vf->relative_vf_id + 1;
2756 p_rss->rss_caps = p_rss_tlv->rss_caps;
2757 p_rss->rss_table_size_log = p_rss_tlv->rss_table_size_log;
2758 OSAL_MEMCPY(p_rss->rss_key, p_rss_tlv->rss_key,
2759 sizeof(p_rss->rss_key));
2761 table_size = OSAL_MIN_T(u16, OSAL_ARRAY_SIZE(p_rss->rss_ind_table),
2762 (1 << p_rss_tlv->rss_table_size_log));
2764 for (i = 0; i < table_size; i++) {
2765 q_idx = p_rss_tlv->rss_ind_table[i];
2766 if (!ecore_iov_validate_rxq(p_hwfn, vf, q_idx)) {
2767 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2768 "VF[%d]: Omitting RSS due to wrong queue %04x\n",
2769 vf->relative_vf_id, q_idx);
2774 if (!vf->vf_queues[q_idx].p_rx_cid) {
2775 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2776 "VF[%d]: Omitting RSS due to inactive queue %08x\n",
2777 vf->relative_vf_id, q_idx);
2782 p_rss->rss_ind_table[i] = vf->vf_queues[q_idx].p_rx_cid;
2785 p_data->rss_params = p_rss;
2787 *tlvs_mask |= 1 << ECORE_IOV_VP_UPDATE_RSS;
2789 *tlvs_accepted |= 1 << ECORE_IOV_VP_UPDATE_RSS;
2793 ecore_iov_vp_update_sge_tpa_param(struct ecore_hwfn *p_hwfn,
2794 struct ecore_vf_info *vf,
2795 struct ecore_sp_vport_update_params *p_data,
2796 struct ecore_sge_tpa_params *p_sge_tpa,
2797 struct ecore_iov_vf_mbx *p_mbx,
2800 struct vfpf_vport_update_sge_tpa_tlv *p_sge_tpa_tlv;
2801 u16 tlv = CHANNEL_TLV_VPORT_UPDATE_SGE_TPA;
2803 p_sge_tpa_tlv = (struct vfpf_vport_update_sge_tpa_tlv *)
2804 ecore_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
2806 if (!p_sge_tpa_tlv) {
2807 p_data->sge_tpa_params = OSAL_NULL;
2811 OSAL_MEMSET(p_sge_tpa, 0, sizeof(struct ecore_sge_tpa_params));
2813 p_sge_tpa->update_tpa_en_flg =
2814 !!(p_sge_tpa_tlv->update_sge_tpa_flags & VFPF_UPDATE_TPA_EN_FLAG);
2815 p_sge_tpa->update_tpa_param_flg =
2816 !!(p_sge_tpa_tlv->update_sge_tpa_flags &
2817 VFPF_UPDATE_TPA_PARAM_FLAG);
2819 p_sge_tpa->tpa_ipv4_en_flg =
2820 !!(p_sge_tpa_tlv->sge_tpa_flags & VFPF_TPA_IPV4_EN_FLAG);
2821 p_sge_tpa->tpa_ipv6_en_flg =
2822 !!(p_sge_tpa_tlv->sge_tpa_flags & VFPF_TPA_IPV6_EN_FLAG);
2823 p_sge_tpa->tpa_pkt_split_flg =
2824 !!(p_sge_tpa_tlv->sge_tpa_flags & VFPF_TPA_PKT_SPLIT_FLAG);
2825 p_sge_tpa->tpa_hdr_data_split_flg =
2826 !!(p_sge_tpa_tlv->sge_tpa_flags & VFPF_TPA_HDR_DATA_SPLIT_FLAG);
2827 p_sge_tpa->tpa_gro_consistent_flg =
2828 !!(p_sge_tpa_tlv->sge_tpa_flags & VFPF_TPA_GRO_CONSIST_FLAG);
2830 p_sge_tpa->tpa_max_aggs_num = p_sge_tpa_tlv->tpa_max_aggs_num;
2831 p_sge_tpa->tpa_max_size = p_sge_tpa_tlv->tpa_max_size;
2832 p_sge_tpa->tpa_min_size_to_start = p_sge_tpa_tlv->tpa_min_size_to_start;
2833 p_sge_tpa->tpa_min_size_to_cont = p_sge_tpa_tlv->tpa_min_size_to_cont;
2834 p_sge_tpa->max_buffers_per_cqe = p_sge_tpa_tlv->max_buffers_per_cqe;
2836 p_data->sge_tpa_params = p_sge_tpa;
2838 *tlvs_mask |= 1 << ECORE_IOV_VP_UPDATE_SGE_TPA;
2841 static void ecore_iov_vf_mbx_vport_update(struct ecore_hwfn *p_hwfn,
2842 struct ecore_ptt *p_ptt,
2843 struct ecore_vf_info *vf)
2845 struct ecore_rss_params *p_rss_params = OSAL_NULL;
2846 struct ecore_sp_vport_update_params params;
2847 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
2848 struct ecore_sge_tpa_params sge_tpa_params;
2849 u16 tlvs_mask = 0, tlvs_accepted = 0;
2850 u8 status = PFVF_STATUS_SUCCESS;
2852 enum _ecore_status_t rc;
2854 /* Valiate PF can send such a request */
2855 if (!vf->vport_instance) {
2856 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2857 "No VPORT instance available for VF[%d],"
2858 " failing vport update\n",
2860 status = PFVF_STATUS_FAILURE;
2864 p_rss_params = OSAL_VZALLOC(p_hwfn->p_dev, sizeof(*p_rss_params));
2865 if (p_rss_params == OSAL_NULL) {
2866 status = PFVF_STATUS_FAILURE;
2870 OSAL_MEMSET(¶ms, 0, sizeof(params));
2871 params.opaque_fid = vf->opaque_fid;
2872 params.vport_id = vf->vport_id;
2873 params.rss_params = OSAL_NULL;
2875 /* Search for extended tlvs list and update values
2876 * from VF in struct ecore_sp_vport_update_params.
2878 ecore_iov_vp_update_act_param(p_hwfn, ¶ms, mbx, &tlvs_mask);
2879 ecore_iov_vp_update_vlan_param(p_hwfn, ¶ms, vf, mbx, &tlvs_mask);
2880 ecore_iov_vp_update_tx_switch(p_hwfn, ¶ms, mbx, &tlvs_mask);
2881 ecore_iov_vp_update_mcast_bin_param(p_hwfn, ¶ms, mbx, &tlvs_mask);
2882 ecore_iov_vp_update_accept_flag(p_hwfn, ¶ms, mbx, &tlvs_mask);
2883 ecore_iov_vp_update_accept_any_vlan(p_hwfn, ¶ms, mbx, &tlvs_mask);
2884 ecore_iov_vp_update_sge_tpa_param(p_hwfn, vf, ¶ms,
2885 &sge_tpa_params, mbx, &tlvs_mask);
2887 tlvs_accepted = tlvs_mask;
2889 /* Some of the extended TLVs need to be validated first; In that case,
2890 * they can update the mask without updating the accepted [so that
2891 * PF could communicate to VF it has rejected request].
2893 ecore_iov_vp_update_rss_param(p_hwfn, vf, ¶ms, p_rss_params,
2894 mbx, &tlvs_mask, &tlvs_accepted);
2896 /* Just log a message if there is no single extended tlv in buffer.
2897 * When all features of vport update ramrod would be requested by VF
2898 * as extended TLVs in buffer then an error can be returned in response
2899 * if there is no extended TLV present in buffer.
2901 if (OSAL_IOV_VF_VPORT_UPDATE(p_hwfn, vf->relative_vf_id,
2902 ¶ms, &tlvs_accepted) !=
2905 status = PFVF_STATUS_NOT_SUPPORTED;
2909 if (!tlvs_accepted) {
2911 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2912 "Upper-layer prevents said VF"
2913 " configuration\n");
2915 DP_NOTICE(p_hwfn, true,
2916 "No feature tlvs found for vport update\n");
2917 status = PFVF_STATUS_NOT_SUPPORTED;
2921 rc = ecore_sp_vport_update(p_hwfn, ¶ms, ECORE_SPQ_MODE_EBLOCK,
2925 status = PFVF_STATUS_FAILURE;
2928 OSAL_VFREE(p_hwfn->p_dev, p_rss_params);
2929 length = ecore_iov_prep_vp_update_resp_tlvs(p_hwfn, vf, mbx, status,
2930 tlvs_mask, tlvs_accepted);
2931 ecore_iov_send_response(p_hwfn, p_ptt, vf, length, status);
2934 static enum _ecore_status_t
2935 ecore_iov_vf_update_vlan_shadow(struct ecore_hwfn *p_hwfn,
2936 struct ecore_vf_info *p_vf,
2937 struct ecore_filter_ucast *p_params)
2941 /* First remove entries and then add new ones */
2942 if (p_params->opcode == ECORE_FILTER_REMOVE) {
2943 for (i = 0; i < ECORE_ETH_VF_NUM_VLAN_FILTERS + 1; i++)
2944 if (p_vf->shadow_config.vlans[i].used &&
2945 p_vf->shadow_config.vlans[i].vid ==
2947 p_vf->shadow_config.vlans[i].used = false;
2950 if (i == ECORE_ETH_VF_NUM_VLAN_FILTERS + 1) {
2951 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2952 "VF [%d] - Tries to remove a non-existing"
2954 p_vf->relative_vf_id);
2957 } else if (p_params->opcode == ECORE_FILTER_REPLACE ||
2958 p_params->opcode == ECORE_FILTER_FLUSH) {
2959 for (i = 0; i < ECORE_ETH_VF_NUM_VLAN_FILTERS + 1; i++)
2960 p_vf->shadow_config.vlans[i].used = false;
2963 /* In forced mode, we're willing to remove entries - but we don't add
2966 if (p_vf->bulletin.p_virt->valid_bitmap & (1 << VLAN_ADDR_FORCED))
2967 return ECORE_SUCCESS;
2969 if (p_params->opcode == ECORE_FILTER_ADD ||
2970 p_params->opcode == ECORE_FILTER_REPLACE) {
2971 for (i = 0; i < ECORE_ETH_VF_NUM_VLAN_FILTERS + 1; i++) {
2972 if (p_vf->shadow_config.vlans[i].used)
2975 p_vf->shadow_config.vlans[i].used = true;
2976 p_vf->shadow_config.vlans[i].vid = p_params->vlan;
2980 if (i == ECORE_ETH_VF_NUM_VLAN_FILTERS + 1) {
2981 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2982 "VF [%d] - Tries to configure more than %d"
2984 p_vf->relative_vf_id,
2985 ECORE_ETH_VF_NUM_VLAN_FILTERS + 1);
2990 return ECORE_SUCCESS;
2993 static enum _ecore_status_t
2994 ecore_iov_vf_update_mac_shadow(struct ecore_hwfn *p_hwfn,
2995 struct ecore_vf_info *p_vf,
2996 struct ecore_filter_ucast *p_params)
2998 char empty_mac[ETH_ALEN];
3001 OSAL_MEM_ZERO(empty_mac, ETH_ALEN);
3003 /* If we're in forced-mode, we don't allow any change */
3004 /* TODO - this would change if we were ever to implement logic for
3005 * removing a forced MAC altogether [in which case, like for vlans,
3006 * we should be able to re-trace previous configuration.
3008 if (p_vf->bulletin.p_virt->valid_bitmap & (1 << MAC_ADDR_FORCED))
3009 return ECORE_SUCCESS;
3011 /* First remove entries and then add new ones */
3012 if (p_params->opcode == ECORE_FILTER_REMOVE) {
3013 for (i = 0; i < ECORE_ETH_VF_NUM_MAC_FILTERS; i++) {
3014 if (!OSAL_MEMCMP(p_vf->shadow_config.macs[i],
3015 p_params->mac, ETH_ALEN)) {
3016 OSAL_MEM_ZERO(p_vf->shadow_config.macs[i],
3022 if (i == ECORE_ETH_VF_NUM_MAC_FILTERS) {
3023 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3024 "MAC isn't configured\n");
3027 } else if (p_params->opcode == ECORE_FILTER_REPLACE ||
3028 p_params->opcode == ECORE_FILTER_FLUSH) {
3029 for (i = 0; i < ECORE_ETH_VF_NUM_MAC_FILTERS; i++)
3030 OSAL_MEM_ZERO(p_vf->shadow_config.macs[i], ETH_ALEN);
3033 /* List the new MAC address */
3034 if (p_params->opcode != ECORE_FILTER_ADD &&
3035 p_params->opcode != ECORE_FILTER_REPLACE)
3036 return ECORE_SUCCESS;
3038 for (i = 0; i < ECORE_ETH_VF_NUM_MAC_FILTERS; i++) {
3039 if (!OSAL_MEMCMP(p_vf->shadow_config.macs[i],
3040 empty_mac, ETH_ALEN)) {
3041 OSAL_MEMCPY(p_vf->shadow_config.macs[i],
3042 p_params->mac, ETH_ALEN);
3043 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3044 "Added MAC at %d entry in shadow\n", i);
3049 if (i == ECORE_ETH_VF_NUM_MAC_FILTERS) {
3050 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3051 "No available place for MAC\n");
3055 return ECORE_SUCCESS;
3058 static enum _ecore_status_t
3059 ecore_iov_vf_update_unicast_shadow(struct ecore_hwfn *p_hwfn,
3060 struct ecore_vf_info *p_vf,
3061 struct ecore_filter_ucast *p_params)
3063 enum _ecore_status_t rc = ECORE_SUCCESS;
3065 if (p_params->type == ECORE_FILTER_MAC) {
3066 rc = ecore_iov_vf_update_mac_shadow(p_hwfn, p_vf, p_params);
3067 if (rc != ECORE_SUCCESS)
3071 if (p_params->type == ECORE_FILTER_VLAN)
3072 rc = ecore_iov_vf_update_vlan_shadow(p_hwfn, p_vf, p_params);
3077 static void ecore_iov_vf_mbx_ucast_filter(struct ecore_hwfn *p_hwfn,
3078 struct ecore_ptt *p_ptt,
3079 struct ecore_vf_info *vf)
3081 struct ecore_bulletin_content *p_bulletin = vf->bulletin.p_virt;
3082 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
3083 struct vfpf_ucast_filter_tlv *req;
3084 u8 status = PFVF_STATUS_SUCCESS;
3085 struct ecore_filter_ucast params;
3086 enum _ecore_status_t rc;
3088 /* Prepare the unicast filter params */
3089 OSAL_MEMSET(¶ms, 0, sizeof(struct ecore_filter_ucast));
3090 req = &mbx->req_virt->ucast_filter;
3091 params.opcode = (enum ecore_filter_opcode)req->opcode;
3092 params.type = (enum ecore_filter_ucast_type)req->type;
3094 /* @@@TBD - We might need logic on HV side in determining this */
3095 params.is_rx_filter = 1;
3096 params.is_tx_filter = 1;
3097 params.vport_to_remove_from = vf->vport_id;
3098 params.vport_to_add_to = vf->vport_id;
3099 OSAL_MEMCPY(params.mac, req->mac, ETH_ALEN);
3100 params.vlan = req->vlan;
3102 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3103 "VF[%d]: opcode 0x%02x type 0x%02x [%s %s] [vport 0x%02x]"
3104 " MAC %02x:%02x:%02x:%02x:%02x:%02x, vlan 0x%04x\n",
3105 vf->abs_vf_id, params.opcode, params.type,
3106 params.is_rx_filter ? "RX" : "",
3107 params.is_tx_filter ? "TX" : "",
3108 params.vport_to_add_to,
3109 params.mac[0], params.mac[1], params.mac[2],
3110 params.mac[3], params.mac[4], params.mac[5], params.vlan);
3112 if (!vf->vport_instance) {
3113 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3114 "No VPORT instance available for VF[%d],"
3115 " failing ucast MAC configuration\n",
3117 status = PFVF_STATUS_FAILURE;
3121 /* Update shadow copy of the VF configuration */
3122 if (ecore_iov_vf_update_unicast_shadow(p_hwfn, vf, ¶ms) !=
3124 status = PFVF_STATUS_FAILURE;
3128 /* Determine if the unicast filtering is acceptible by PF */
3129 if ((p_bulletin->valid_bitmap & (1 << VLAN_ADDR_FORCED)) &&
3130 (params.type == ECORE_FILTER_VLAN ||
3131 params.type == ECORE_FILTER_MAC_VLAN)) {
3132 /* Once VLAN is forced or PVID is set, do not allow
3133 * to add/replace any further VLANs.
3135 if (params.opcode == ECORE_FILTER_ADD ||
3136 params.opcode == ECORE_FILTER_REPLACE)
3137 status = PFVF_STATUS_FORCED;
3141 if ((p_bulletin->valid_bitmap & (1 << MAC_ADDR_FORCED)) &&
3142 (params.type == ECORE_FILTER_MAC ||
3143 params.type == ECORE_FILTER_MAC_VLAN)) {
3144 if (OSAL_MEMCMP(p_bulletin->mac, params.mac, ETH_ALEN) ||
3145 (params.opcode != ECORE_FILTER_ADD &&
3146 params.opcode != ECORE_FILTER_REPLACE))
3147 status = PFVF_STATUS_FORCED;
3151 rc = OSAL_IOV_CHK_UCAST(p_hwfn, vf->relative_vf_id, ¶ms);
3152 if (rc == ECORE_EXISTS) {
3154 } else if (rc == ECORE_INVAL) {
3155 status = PFVF_STATUS_FAILURE;
3159 rc = ecore_sp_eth_filter_ucast(p_hwfn, vf->opaque_fid, ¶ms,
3160 ECORE_SPQ_MODE_CB, OSAL_NULL);
3162 status = PFVF_STATUS_FAILURE;
3165 ecore_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_UCAST_FILTER,
3166 sizeof(struct pfvf_def_resp_tlv), status);
3169 static void ecore_iov_vf_mbx_int_cleanup(struct ecore_hwfn *p_hwfn,
3170 struct ecore_ptt *p_ptt,
3171 struct ecore_vf_info *vf)
3176 for (i = 0; i < vf->num_sbs; i++)
3177 ecore_int_igu_init_pure_rt_single(p_hwfn, p_ptt,
3179 vf->opaque_fid, false);
3181 ecore_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_INT_CLEANUP,
3182 sizeof(struct pfvf_def_resp_tlv),
3183 PFVF_STATUS_SUCCESS);
3186 static void ecore_iov_vf_mbx_close(struct ecore_hwfn *p_hwfn,
3187 struct ecore_ptt *p_ptt,
3188 struct ecore_vf_info *vf)
3190 u16 length = sizeof(struct pfvf_def_resp_tlv);
3191 u8 status = PFVF_STATUS_SUCCESS;
3193 /* Disable Interrupts for VF */
3194 ecore_iov_vf_igu_set_int(p_hwfn, p_ptt, vf, 0);
3196 /* Reset Permission table */
3197 ecore_iov_config_perm_table(p_hwfn, p_ptt, vf, 0);
3199 ecore_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_CLOSE,
3203 static void ecore_iov_vf_mbx_release(struct ecore_hwfn *p_hwfn,
3204 struct ecore_ptt *p_ptt,
3205 struct ecore_vf_info *p_vf)
3207 u16 length = sizeof(struct pfvf_def_resp_tlv);
3208 u8 status = PFVF_STATUS_SUCCESS;
3209 enum _ecore_status_t rc = ECORE_SUCCESS;
3211 ecore_iov_vf_cleanup(p_hwfn, p_vf);
3213 if (p_vf->state != VF_STOPPED && p_vf->state != VF_FREE) {
3214 /* Stopping the VF */
3215 rc = ecore_sp_vf_stop(p_hwfn, p_vf->concrete_fid,
3218 if (rc != ECORE_SUCCESS) {
3219 DP_ERR(p_hwfn, "ecore_sp_vf_stop returned error %d\n",
3221 status = PFVF_STATUS_FAILURE;
3224 p_vf->state = VF_STOPPED;
3227 ecore_iov_prepare_resp(p_hwfn, p_ptt, p_vf, CHANNEL_TLV_RELEASE,
3231 static void ecore_iov_vf_pf_set_coalesce(struct ecore_hwfn *p_hwfn,
3232 struct ecore_ptt *p_ptt,
3233 struct ecore_vf_info *vf)
3235 struct ecore_iov_vf_mbx *mbx = &vf->vf_mbx;
3236 enum _ecore_status_t rc = ECORE_SUCCESS;
3237 struct vfpf_update_coalesce *req;
3238 u8 status = PFVF_STATUS_FAILURE;
3239 struct ecore_queue_cid *p_cid;
3240 u16 rx_coal, tx_coal;
3243 req = &mbx->req_virt->update_coalesce;
3245 rx_coal = req->rx_coal;
3246 tx_coal = req->tx_coal;
3248 p_cid = vf->vf_queues[qid].p_rx_cid;
3250 if (!ecore_iov_validate_rxq(p_hwfn, vf, qid)) {
3251 DP_ERR(p_hwfn, "VF[%d]: Invalid Rx queue_id = %d\n",
3252 vf->abs_vf_id, qid);
3256 if (!ecore_iov_validate_txq(p_hwfn, vf, qid)) {
3257 DP_ERR(p_hwfn, "VF[%d]: Invalid Tx queue_id = %d\n",
3258 vf->abs_vf_id, qid);
3262 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3263 "VF[%d]: Setting coalesce for VF rx_coal = %d, tx_coal = %d at queue = %d\n",
3264 vf->abs_vf_id, rx_coal, tx_coal, qid);
3266 rc = ecore_set_rxq_coalesce(p_hwfn, p_ptt, rx_coal, p_cid);
3267 if (rc != ECORE_SUCCESS) {
3268 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3269 "VF[%d]: Unable to set rx queue = %d coalesce\n",
3270 vf->abs_vf_id, vf->vf_queues[qid].fw_rx_qid);
3275 rc = ecore_set_txq_coalesce(p_hwfn, p_ptt, tx_coal, p_cid);
3276 if (rc != ECORE_SUCCESS) {
3277 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3278 "VF[%d]: Unable to set tx queue = %d coalesce\n",
3279 vf->abs_vf_id, vf->vf_queues[qid].fw_tx_qid);
3284 status = PFVF_STATUS_SUCCESS;
3286 ecore_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_COALESCE_UPDATE,
3287 sizeof(struct pfvf_def_resp_tlv), status);
3290 static enum _ecore_status_t
3291 ecore_iov_vf_flr_poll_dorq(struct ecore_hwfn *p_hwfn,
3292 struct ecore_vf_info *p_vf, struct ecore_ptt *p_ptt)
3297 ecore_fid_pretend(p_hwfn, p_ptt, (u16)p_vf->concrete_fid);
3299 for (cnt = 0; cnt < 50; cnt++) {
3300 val = ecore_rd(p_hwfn, p_ptt, DORQ_REG_VF_USAGE_CNT);
3305 ecore_fid_pretend(p_hwfn, p_ptt, (u16)p_hwfn->hw_info.concrete_fid);
3309 "VF[%d] - dorq failed to cleanup [usage 0x%08x]\n",
3310 p_vf->abs_vf_id, val);
3311 return ECORE_TIMEOUT;
3314 return ECORE_SUCCESS;
3317 static enum _ecore_status_t
3318 ecore_iov_vf_flr_poll_pbf(struct ecore_hwfn *p_hwfn,
3319 struct ecore_vf_info *p_vf, struct ecore_ptt *p_ptt)
3321 u32 cons[MAX_NUM_VOQS], distance[MAX_NUM_VOQS];
3324 /* Read initial consumers & producers */
3325 for (i = 0; i < MAX_NUM_VOQS; i++) {
3328 cons[i] = ecore_rd(p_hwfn, p_ptt,
3329 PBF_REG_NUM_BLOCKS_ALLOCATED_CONS_VOQ0 +
3331 prod = ecore_rd(p_hwfn, p_ptt,
3332 PBF_REG_NUM_BLOCKS_ALLOCATED_PROD_VOQ0 +
3334 distance[i] = prod - cons[i];
3337 /* Wait for consumers to pass the producers */
3339 for (cnt = 0; cnt < 50; cnt++) {
3340 for (; i < MAX_NUM_VOQS; i++) {
3343 tmp = ecore_rd(p_hwfn, p_ptt,
3344 PBF_REG_NUM_BLOCKS_ALLOCATED_CONS_VOQ0 +
3346 if (distance[i] > tmp - cons[i])
3350 if (i == MAX_NUM_VOQS)
3357 DP_ERR(p_hwfn, "VF[%d] - pbf polling failed on VOQ %d\n",
3358 p_vf->abs_vf_id, i);
3359 return ECORE_TIMEOUT;
3362 return ECORE_SUCCESS;
3365 static enum _ecore_status_t ecore_iov_vf_flr_poll(struct ecore_hwfn *p_hwfn,
3366 struct ecore_vf_info *p_vf,
3367 struct ecore_ptt *p_ptt)
3369 enum _ecore_status_t rc;
3371 /* TODO - add SRC and TM polling once we add storage IOV */
3373 rc = ecore_iov_vf_flr_poll_dorq(p_hwfn, p_vf, p_ptt);
3377 rc = ecore_iov_vf_flr_poll_pbf(p_hwfn, p_vf, p_ptt);
3381 return ECORE_SUCCESS;
3384 static enum _ecore_status_t
3385 ecore_iov_execute_vf_flr_cleanup(struct ecore_hwfn *p_hwfn,
3386 struct ecore_ptt *p_ptt,
3387 u16 rel_vf_id, u32 *ack_vfs)
3389 struct ecore_vf_info *p_vf;
3390 enum _ecore_status_t rc = ECORE_SUCCESS;
3392 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, false);
3394 return ECORE_SUCCESS;
3396 if (p_hwfn->pf_iov_info->pending_flr[rel_vf_id / 64] &
3397 (1ULL << (rel_vf_id % 64))) {
3398 u16 vfid = p_vf->abs_vf_id;
3400 /* TODO - should we lock channel? */
3402 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3403 "VF[%d] - Handling FLR\n", vfid);
3405 ecore_iov_vf_cleanup(p_hwfn, p_vf);
3407 /* If VF isn't active, no need for anything but SW */
3411 /* TODO - what to do in case of failure? */
3412 rc = ecore_iov_vf_flr_poll(p_hwfn, p_vf, p_ptt);
3413 if (rc != ECORE_SUCCESS)
3416 rc = ecore_final_cleanup(p_hwfn, p_ptt, vfid, true);
3418 /* TODO - what's now? What a mess.... */
3419 DP_ERR(p_hwfn, "Failed handle FLR of VF[%d]\n", vfid);
3423 /* Workaround to make VF-PF channel ready, as FW
3424 * doesn't do that as a part of FLR.
3427 GTT_BAR0_MAP_REG_USDM_RAM +
3428 USTORM_VF_PF_CHANNEL_READY_OFFSET(vfid), 1);
3430 /* VF_STOPPED has to be set only after final cleanup
3431 * but prior to re-enabling the VF.
3433 p_vf->state = VF_STOPPED;
3435 rc = ecore_iov_enable_vf_access(p_hwfn, p_ptt, p_vf);
3437 /* TODO - again, a mess... */
3438 DP_ERR(p_hwfn, "Failed to re-enable VF[%d] acces\n",
3443 /* Mark VF for ack and clean pending state */
3444 if (p_vf->state == VF_RESET)
3445 p_vf->state = VF_STOPPED;
3446 ack_vfs[vfid / 32] |= (1 << (vfid % 32));
3447 p_hwfn->pf_iov_info->pending_flr[rel_vf_id / 64] &=
3448 ~(1ULL << (rel_vf_id % 64));
3449 p_hwfn->pf_iov_info->pending_events[rel_vf_id / 64] &=
3450 ~(1ULL << (rel_vf_id % 64));
3456 enum _ecore_status_t ecore_iov_vf_flr_cleanup(struct ecore_hwfn *p_hwfn,
3457 struct ecore_ptt *p_ptt)
3459 u32 ack_vfs[VF_MAX_STATIC / 32];
3460 enum _ecore_status_t rc = ECORE_SUCCESS;
3463 OSAL_MEMSET(ack_vfs, 0, sizeof(u32) * (VF_MAX_STATIC / 32));
3465 /* Since BRB <-> PRS interface can't be tested as part of the flr
3466 * polling due to HW limitations, simply sleep a bit. And since
3467 * there's no need to wait per-vf, do it before looping.
3471 for (i = 0; i < p_hwfn->p_dev->p_iov_info->total_vfs; i++)
3472 ecore_iov_execute_vf_flr_cleanup(p_hwfn, p_ptt, i, ack_vfs);
3474 rc = ecore_mcp_ack_vf_flr(p_hwfn, p_ptt, ack_vfs);
3478 enum _ecore_status_t
3479 ecore_iov_single_vf_flr_cleanup(struct ecore_hwfn *p_hwfn,
3480 struct ecore_ptt *p_ptt, u16 rel_vf_id)
3482 u32 ack_vfs[VF_MAX_STATIC / 32];
3483 enum _ecore_status_t rc = ECORE_SUCCESS;
3485 OSAL_MEMSET(ack_vfs, 0, sizeof(u32) * (VF_MAX_STATIC / 32));
3487 /* Wait instead of polling the BRB <-> PRS interface */
3490 ecore_iov_execute_vf_flr_cleanup(p_hwfn, p_ptt, rel_vf_id, ack_vfs);
3492 rc = ecore_mcp_ack_vf_flr(p_hwfn, p_ptt, ack_vfs);
3496 bool ecore_iov_mark_vf_flr(struct ecore_hwfn *p_hwfn, u32 *p_disabled_vfs)
3501 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV, "Marking FLR-ed VFs\n");
3502 for (i = 0; i < (VF_MAX_STATIC / 32); i++)
3503 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3504 "[%08x,...,%08x]: %08x\n",
3505 i * 32, (i + 1) * 32 - 1, p_disabled_vfs[i]);
3507 if (!p_hwfn->p_dev->p_iov_info) {
3508 DP_NOTICE(p_hwfn, true, "VF flr but no IOV\n");
3513 for (i = 0; i < p_hwfn->p_dev->p_iov_info->total_vfs; i++) {
3514 struct ecore_vf_info *p_vf;
3517 p_vf = ecore_iov_get_vf_info(p_hwfn, i, false);
3521 vfid = p_vf->abs_vf_id;
3522 if ((1 << (vfid % 32)) & p_disabled_vfs[vfid / 32]) {
3523 u64 *p_flr = p_hwfn->pf_iov_info->pending_flr;
3524 u16 rel_vf_id = p_vf->relative_vf_id;
3526 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3527 "VF[%d] [rel %d] got FLR-ed\n",
3530 p_vf->state = VF_RESET;
3532 /* No need to lock here, since pending_flr should
3533 * only change here and before ACKing MFw. Since
3534 * MFW will not trigger an additional attention for
3535 * VF flr until ACKs, we're safe.
3537 p_flr[rel_vf_id / 64] |= 1ULL << (rel_vf_id % 64);
3545 void ecore_iov_get_link(struct ecore_hwfn *p_hwfn,
3547 struct ecore_mcp_link_params *p_params,
3548 struct ecore_mcp_link_state *p_link,
3549 struct ecore_mcp_link_capabilities *p_caps)
3551 struct ecore_vf_info *p_vf = ecore_iov_get_vf_info(p_hwfn, vfid, false);
3552 struct ecore_bulletin_content *p_bulletin;
3557 p_bulletin = p_vf->bulletin.p_virt;
3560 __ecore_vf_get_link_params(p_hwfn, p_params, p_bulletin);
3562 __ecore_vf_get_link_state(p_hwfn, p_link, p_bulletin);
3564 __ecore_vf_get_link_caps(p_hwfn, p_caps, p_bulletin);
3567 void ecore_iov_process_mbx_req(struct ecore_hwfn *p_hwfn,
3568 struct ecore_ptt *p_ptt, int vfid)
3570 struct ecore_iov_vf_mbx *mbx;
3571 struct ecore_vf_info *p_vf;
3573 p_vf = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
3577 mbx = &p_vf->vf_mbx;
3579 /* ecore_iov_process_mbx_request */
3582 "VF[%02x]: Processing mailbox message\n", p_vf->abs_vf_id);
3584 mbx->first_tlv = mbx->req_virt->first_tlv;
3586 OSAL_IOV_VF_MSG_TYPE(p_hwfn,
3587 p_vf->relative_vf_id,
3588 mbx->first_tlv.tl.type);
3590 /* Lock the per vf op mutex and note the locker's identity.
3591 * The unlock will take place in mbx response.
3593 ecore_iov_lock_vf_pf_channel(p_hwfn,
3594 p_vf, mbx->first_tlv.tl.type);
3596 /* check if tlv type is known */
3597 if (ecore_iov_tlv_supported(mbx->first_tlv.tl.type) &&
3598 !p_vf->b_malicious) {
3599 /* switch on the opcode */
3600 switch (mbx->first_tlv.tl.type) {
3601 case CHANNEL_TLV_ACQUIRE:
3602 ecore_iov_vf_mbx_acquire(p_hwfn, p_ptt, p_vf);
3604 case CHANNEL_TLV_VPORT_START:
3605 ecore_iov_vf_mbx_start_vport(p_hwfn, p_ptt, p_vf);
3607 case CHANNEL_TLV_VPORT_TEARDOWN:
3608 ecore_iov_vf_mbx_stop_vport(p_hwfn, p_ptt, p_vf);
3610 case CHANNEL_TLV_START_RXQ:
3611 ecore_iov_vf_mbx_start_rxq(p_hwfn, p_ptt, p_vf);
3613 case CHANNEL_TLV_START_TXQ:
3614 ecore_iov_vf_mbx_start_txq(p_hwfn, p_ptt, p_vf);
3616 case CHANNEL_TLV_STOP_RXQS:
3617 ecore_iov_vf_mbx_stop_rxqs(p_hwfn, p_ptt, p_vf);
3619 case CHANNEL_TLV_STOP_TXQS:
3620 ecore_iov_vf_mbx_stop_txqs(p_hwfn, p_ptt, p_vf);
3622 case CHANNEL_TLV_UPDATE_RXQ:
3623 ecore_iov_vf_mbx_update_rxqs(p_hwfn, p_ptt, p_vf);
3625 case CHANNEL_TLV_VPORT_UPDATE:
3626 ecore_iov_vf_mbx_vport_update(p_hwfn, p_ptt, p_vf);
3628 case CHANNEL_TLV_UCAST_FILTER:
3629 ecore_iov_vf_mbx_ucast_filter(p_hwfn, p_ptt, p_vf);
3631 case CHANNEL_TLV_CLOSE:
3632 ecore_iov_vf_mbx_close(p_hwfn, p_ptt, p_vf);
3634 case CHANNEL_TLV_INT_CLEANUP:
3635 ecore_iov_vf_mbx_int_cleanup(p_hwfn, p_ptt, p_vf);
3637 case CHANNEL_TLV_RELEASE:
3638 ecore_iov_vf_mbx_release(p_hwfn, p_ptt, p_vf);
3640 case CHANNEL_TLV_UPDATE_TUNN_PARAM:
3641 ecore_iov_vf_mbx_update_tunn_param(p_hwfn, p_ptt, p_vf);
3643 case CHANNEL_TLV_COALESCE_UPDATE:
3644 ecore_iov_vf_pf_set_coalesce(p_hwfn, p_ptt, p_vf);
3647 } else if (ecore_iov_tlv_supported(mbx->first_tlv.tl.type)) {
3648 /* If we've received a message from a VF we consider malicious
3649 * we ignore the messasge unless it's one for RELEASE, in which
3650 * case we'll let it have the benefit of doubt, allowing the
3651 * next loaded driver to start again.
3653 if (mbx->first_tlv.tl.type == CHANNEL_TLV_RELEASE) {
3654 /* TODO - initiate FLR, remove malicious indication */
3655 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3656 "VF [%02x] - considered malicious, but wanted to RELEASE. TODO\n",
3659 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3660 "VF [%02x] - considered malicious; Ignoring TLV [%04x]\n",
3661 p_vf->abs_vf_id, mbx->first_tlv.tl.type);
3664 ecore_iov_prepare_resp(p_hwfn, p_ptt, p_vf,
3665 mbx->first_tlv.tl.type,
3666 sizeof(struct pfvf_def_resp_tlv),
3667 PFVF_STATUS_MALICIOUS);
3669 /* unknown TLV - this may belong to a VF driver from the future
3670 * - a version written after this PF driver was written, which
3671 * supports features unknown as of yet. Too bad since we don't
3672 * support them. Or this may be because someone wrote a crappy
3673 * VF driver and is sending garbage over the channel.
3675 DP_NOTICE(p_hwfn, false,
3676 "VF[%02x]: unknown TLV. type %04x length %04x"
3677 " padding %08x reply address %lu\n",
3679 mbx->first_tlv.tl.type,
3680 mbx->first_tlv.tl.length,
3681 mbx->first_tlv.padding,
3682 (unsigned long)mbx->first_tlv.reply_address);
3684 /* Try replying in case reply address matches the acquisition's
3687 if (p_vf->acquire.first_tlv.reply_address &&
3688 (mbx->first_tlv.reply_address ==
3689 p_vf->acquire.first_tlv.reply_address))
3690 ecore_iov_prepare_resp(p_hwfn, p_ptt, p_vf,
3691 mbx->first_tlv.tl.type,
3692 sizeof(struct pfvf_def_resp_tlv),
3693 PFVF_STATUS_NOT_SUPPORTED);
3695 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3696 "VF[%02x]: Can't respond to TLV -"
3697 " no valid reply address\n",
3701 ecore_iov_unlock_vf_pf_channel(p_hwfn, p_vf,
3702 mbx->first_tlv.tl.type);
3704 #ifdef CONFIG_ECORE_SW_CHANNEL
3705 mbx->sw_mbx.mbx_state = VF_PF_RESPONSE_READY;
3706 mbx->sw_mbx.response_offset = 0;
3710 void ecore_iov_pf_add_pending_events(struct ecore_hwfn *p_hwfn, u8 vfid)
3712 u64 add_bit = 1ULL << (vfid % 64);
3714 /* TODO - add locking mechanisms [no atomics in ecore, so we can't
3715 * add the lock inside the ecore_pf_iov struct].
3717 p_hwfn->pf_iov_info->pending_events[vfid / 64] |= add_bit;
3720 void ecore_iov_pf_get_and_clear_pending_events(struct ecore_hwfn *p_hwfn,
3723 u64 *p_pending_events = p_hwfn->pf_iov_info->pending_events;
3725 /* TODO - Take a lock */
3726 OSAL_MEMCPY(events, p_pending_events,
3727 sizeof(u64) * ECORE_VF_ARRAY_LENGTH);
3728 OSAL_MEMSET(p_pending_events, 0,
3729 sizeof(u64) * ECORE_VF_ARRAY_LENGTH);
3732 static struct ecore_vf_info *
3733 ecore_sriov_get_vf_from_absid(struct ecore_hwfn *p_hwfn, u16 abs_vfid)
3735 u8 min = (u8)p_hwfn->p_dev->p_iov_info->first_vf_in_pf;
3737 if (!_ecore_iov_pf_sanity_check(p_hwfn, (int)abs_vfid - min, false)) {
3738 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3739 "Got indication for VF [abs 0x%08x] that cannot be"
3745 return &p_hwfn->pf_iov_info->vfs_array[(u8)abs_vfid - min];
3748 static enum _ecore_status_t ecore_sriov_vfpf_msg(struct ecore_hwfn *p_hwfn,
3750 struct regpair *vf_msg)
3752 struct ecore_vf_info *p_vf = ecore_sriov_get_vf_from_absid(p_hwfn,
3756 return ECORE_SUCCESS;
3758 /* List the physical address of the request so that handler
3759 * could later on copy the message from it.
3761 p_vf->vf_mbx.pending_req = (((u64)vf_msg->hi) << 32) | vf_msg->lo;
3763 return OSAL_PF_VF_MSG(p_hwfn, p_vf->relative_vf_id);
3766 static void ecore_sriov_vfpf_malicious(struct ecore_hwfn *p_hwfn,
3767 struct malicious_vf_eqe_data *p_data)
3769 struct ecore_vf_info *p_vf;
3771 p_vf = ecore_sriov_get_vf_from_absid(p_hwfn, p_data->vfId);
3777 "VF [%d] - Malicious behavior [%02x]\n",
3778 p_vf->abs_vf_id, p_data->errId);
3780 p_vf->b_malicious = true;
3782 OSAL_PF_VF_MALICIOUS(p_hwfn, p_vf->relative_vf_id);
3785 enum _ecore_status_t ecore_sriov_eqe_event(struct ecore_hwfn *p_hwfn,
3788 union event_ring_data *data)
3791 case COMMON_EVENT_VF_PF_CHANNEL:
3792 return ecore_sriov_vfpf_msg(p_hwfn, OSAL_LE16_TO_CPU(echo),
3793 &data->vf_pf_channel.msg_addr);
3794 case COMMON_EVENT_VF_FLR:
3795 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3796 "VF-FLR is still not supported\n");
3797 return ECORE_SUCCESS;
3798 case COMMON_EVENT_MALICIOUS_VF:
3799 ecore_sriov_vfpf_malicious(p_hwfn, &data->malicious_vf);
3800 return ECORE_SUCCESS;
3802 DP_INFO(p_hwfn->p_dev, "Unknown sriov eqe event 0x%02x\n",
3808 bool ecore_iov_is_vf_pending_flr(struct ecore_hwfn *p_hwfn, u16 rel_vf_id)
3810 return !!(p_hwfn->pf_iov_info->pending_flr[rel_vf_id / 64] &
3811 (1ULL << (rel_vf_id % 64)));
3814 u16 ecore_iov_get_next_active_vf(struct ecore_hwfn *p_hwfn, u16 rel_vf_id)
3816 struct ecore_hw_sriov_info *p_iov = p_hwfn->p_dev->p_iov_info;
3822 for (i = rel_vf_id; i < p_iov->total_vfs; i++)
3823 if (ecore_iov_is_valid_vfid(p_hwfn, rel_vf_id, true, false))
3827 return E4_MAX_NUM_VFS;
3830 enum _ecore_status_t ecore_iov_copy_vf_msg(struct ecore_hwfn *p_hwfn,
3831 struct ecore_ptt *ptt, int vfid)
3833 struct ecore_dmae_params params;
3834 struct ecore_vf_info *vf_info;
3836 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
3840 OSAL_MEMSET(¶ms, 0, sizeof(struct ecore_dmae_params));
3841 params.flags = ECORE_DMAE_FLAG_VF_SRC | ECORE_DMAE_FLAG_COMPLETION_DST;
3842 params.src_vfid = vf_info->abs_vf_id;
3844 if (ecore_dmae_host2host(p_hwfn, ptt,
3845 vf_info->vf_mbx.pending_req,
3846 vf_info->vf_mbx.req_phys,
3847 sizeof(union vfpf_tlvs) / 4, ¶ms)) {
3848 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3849 "Failed to copy message from VF 0x%02x\n", vfid);
3854 return ECORE_SUCCESS;
3857 void ecore_iov_bulletin_set_forced_mac(struct ecore_hwfn *p_hwfn,
3860 struct ecore_vf_info *vf_info;
3863 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
3865 DP_NOTICE(p_hwfn->p_dev, true,
3866 "Can not set forced MAC, invalid vfid [%d]\n", vfid);
3869 if (vf_info->b_malicious) {
3870 DP_NOTICE(p_hwfn->p_dev, false,
3871 "Can't set forced MAC to malicious VF [%d]\n",
3876 feature = 1 << MAC_ADDR_FORCED;
3877 OSAL_MEMCPY(vf_info->bulletin.p_virt->mac, mac, ETH_ALEN);
3879 vf_info->bulletin.p_virt->valid_bitmap |= feature;
3880 /* Forced MAC will disable MAC_ADDR */
3881 vf_info->bulletin.p_virt->valid_bitmap &=
3882 ~(1 << VFPF_BULLETIN_MAC_ADDR);
3884 ecore_iov_configure_vport_forced(p_hwfn, vf_info, feature);
3887 enum _ecore_status_t ecore_iov_bulletin_set_mac(struct ecore_hwfn *p_hwfn,
3890 struct ecore_vf_info *vf_info;
3893 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
3895 DP_NOTICE(p_hwfn->p_dev, true,
3896 "Can not set MAC, invalid vfid [%d]\n", vfid);
3899 if (vf_info->b_malicious) {
3900 DP_NOTICE(p_hwfn->p_dev, false,
3901 "Can't set MAC to malicious VF [%d]\n",
3906 if (vf_info->bulletin.p_virt->valid_bitmap & (1 << MAC_ADDR_FORCED)) {
3907 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3908 "Can not set MAC, Forced MAC is configured\n");
3912 feature = 1 << VFPF_BULLETIN_MAC_ADDR;
3913 OSAL_MEMCPY(vf_info->bulletin.p_virt->mac, mac, ETH_ALEN);
3915 vf_info->bulletin.p_virt->valid_bitmap |= feature;
3917 return ECORE_SUCCESS;
3920 enum _ecore_status_t
3921 ecore_iov_bulletin_set_forced_untagged_default(struct ecore_hwfn *p_hwfn,
3922 bool b_untagged_only, int vfid)
3924 struct ecore_vf_info *vf_info;
3927 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
3929 DP_NOTICE(p_hwfn->p_dev, true,
3930 "Can not set untagged default, invalid vfid [%d]\n",
3934 if (vf_info->b_malicious) {
3935 DP_NOTICE(p_hwfn->p_dev, false,
3936 "Can't set untagged default to malicious VF [%d]\n",
3941 /* Since this is configurable only during vport-start, don't take it
3942 * if we're past that point.
3944 if (vf_info->state == VF_ENABLED) {
3945 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
3946 "Can't support untagged change for vfid[%d] -"
3947 " VF is already active\n",
3952 /* Set configuration; This will later be taken into account during the
3953 * VF initialization.
3955 feature = (1 << VFPF_BULLETIN_UNTAGGED_DEFAULT) |
3956 (1 << VFPF_BULLETIN_UNTAGGED_DEFAULT_FORCED);
3957 vf_info->bulletin.p_virt->valid_bitmap |= feature;
3959 vf_info->bulletin.p_virt->default_only_untagged = b_untagged_only ? 1
3962 return ECORE_SUCCESS;
3965 void ecore_iov_get_vfs_opaque_fid(struct ecore_hwfn *p_hwfn, int vfid,
3968 struct ecore_vf_info *vf_info;
3970 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
3974 *opaque_fid = vf_info->opaque_fid;
3977 void ecore_iov_get_vfs_vport_id(struct ecore_hwfn *p_hwfn, int vfid,
3980 struct ecore_vf_info *vf_info;
3982 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
3986 *p_vort_id = vf_info->vport_id;
3989 void ecore_iov_bulletin_set_forced_vlan(struct ecore_hwfn *p_hwfn,
3992 struct ecore_vf_info *vf_info;
3995 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
3997 DP_NOTICE(p_hwfn->p_dev, true,
3998 "Can not set forced MAC, invalid vfid [%d]\n",
4002 if (vf_info->b_malicious) {
4003 DP_NOTICE(p_hwfn->p_dev, false,
4004 "Can't set forced vlan to malicious VF [%d]\n",
4009 feature = 1 << VLAN_ADDR_FORCED;
4010 vf_info->bulletin.p_virt->pvid = pvid;
4012 vf_info->bulletin.p_virt->valid_bitmap |= feature;
4014 vf_info->bulletin.p_virt->valid_bitmap &= ~feature;
4016 ecore_iov_configure_vport_forced(p_hwfn, vf_info, feature);
4019 bool ecore_iov_vf_has_vport_instance(struct ecore_hwfn *p_hwfn, int vfid)
4021 struct ecore_vf_info *p_vf_info;
4023 p_vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4027 return !!p_vf_info->vport_instance;
4030 bool ecore_iov_is_vf_stopped(struct ecore_hwfn *p_hwfn, int vfid)
4032 struct ecore_vf_info *p_vf_info;
4034 p_vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4038 return p_vf_info->state == VF_STOPPED;
4041 bool ecore_iov_spoofchk_get(struct ecore_hwfn *p_hwfn, int vfid)
4043 struct ecore_vf_info *vf_info;
4045 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4049 return vf_info->spoof_chk;
4052 enum _ecore_status_t ecore_iov_spoofchk_set(struct ecore_hwfn *p_hwfn,
4055 struct ecore_vf_info *vf;
4056 enum _ecore_status_t rc = ECORE_INVAL;
4058 if (!ecore_iov_pf_sanity_check(p_hwfn, vfid)) {
4059 DP_NOTICE(p_hwfn, true,
4060 "SR-IOV sanity check failed, can't set spoofchk\n");
4064 vf = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4068 if (!ecore_iov_vf_has_vport_instance(p_hwfn, vfid)) {
4069 /* After VF VPORT start PF will configure spoof check */
4070 vf->req_spoofchk_val = val;
4075 rc = __ecore_iov_spoofchk_set(p_hwfn, vf, val);
4081 u8 ecore_iov_vf_chains_per_pf(struct ecore_hwfn *p_hwfn)
4083 u8 max_chains_per_vf = p_hwfn->hw_info.max_chains_per_vf;
4085 max_chains_per_vf = (max_chains_per_vf) ? max_chains_per_vf
4086 : ECORE_MAX_VF_CHAINS_PER_PF;
4088 return max_chains_per_vf;
4091 void ecore_iov_get_vf_req_virt_mbx_params(struct ecore_hwfn *p_hwfn,
4093 void **pp_req_virt_addr,
4094 u16 *p_req_virt_size)
4096 struct ecore_vf_info *vf_info =
4097 ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4102 if (pp_req_virt_addr)
4103 *pp_req_virt_addr = vf_info->vf_mbx.req_virt;
4105 if (p_req_virt_size)
4106 *p_req_virt_size = sizeof(*vf_info->vf_mbx.req_virt);
4109 void ecore_iov_get_vf_reply_virt_mbx_params(struct ecore_hwfn *p_hwfn,
4111 void **pp_reply_virt_addr,
4112 u16 *p_reply_virt_size)
4114 struct ecore_vf_info *vf_info =
4115 ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4120 if (pp_reply_virt_addr)
4121 *pp_reply_virt_addr = vf_info->vf_mbx.reply_virt;
4123 if (p_reply_virt_size)
4124 *p_reply_virt_size = sizeof(*vf_info->vf_mbx.reply_virt);
4127 #ifdef CONFIG_ECORE_SW_CHANNEL
4128 struct ecore_iov_sw_mbx *ecore_iov_get_vf_sw_mbx(struct ecore_hwfn *p_hwfn,
4131 struct ecore_vf_info *vf_info =
4132 ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4137 return &vf_info->vf_mbx.sw_mbx;
4141 bool ecore_iov_is_valid_vfpf_msg_length(u32 length)
4143 return (length >= sizeof(struct vfpf_first_tlv) &&
4144 (length <= sizeof(union vfpf_tlvs)));
4147 u32 ecore_iov_pfvf_msg_length(void)
4149 return sizeof(union pfvf_tlvs);
4152 u8 *ecore_iov_bulletin_get_forced_mac(struct ecore_hwfn *p_hwfn, u16 rel_vf_id)
4154 struct ecore_vf_info *p_vf;
4156 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4157 if (!p_vf || !p_vf->bulletin.p_virt)
4160 if (!(p_vf->bulletin.p_virt->valid_bitmap & (1 << MAC_ADDR_FORCED)))
4163 return p_vf->bulletin.p_virt->mac;
4166 u16 ecore_iov_bulletin_get_forced_vlan(struct ecore_hwfn *p_hwfn,
4169 struct ecore_vf_info *p_vf;
4171 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4172 if (!p_vf || !p_vf->bulletin.p_virt)
4175 if (!(p_vf->bulletin.p_virt->valid_bitmap & (1 << VLAN_ADDR_FORCED)))
4178 return p_vf->bulletin.p_virt->pvid;
4181 enum _ecore_status_t ecore_iov_configure_tx_rate(struct ecore_hwfn *p_hwfn,
4182 struct ecore_ptt *p_ptt,
4185 struct ecore_vf_info *vf;
4187 enum _ecore_status_t rc;
4189 vf = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4194 rc = ecore_fw_vport(p_hwfn, vf->vport_id, &abs_vp_id);
4195 if (rc != ECORE_SUCCESS)
4198 return ecore_init_vport_rl(p_hwfn, p_ptt, abs_vp_id, (u32)val);
4201 enum _ecore_status_t ecore_iov_configure_min_tx_rate(struct ecore_dev *p_dev,
4204 struct ecore_vf_info *vf;
4208 for_each_hwfn(p_dev, i) {
4209 struct ecore_hwfn *p_hwfn = &p_dev->hwfns[i];
4211 if (!ecore_iov_pf_sanity_check(p_hwfn, vfid)) {
4212 DP_NOTICE(p_hwfn, true,
4213 "SR-IOV sanity check failed,"
4214 " can't set min rate\n");
4219 vf = ecore_iov_get_vf_info(ECORE_LEADING_HWFN(p_dev), (u16)vfid, true);
4220 vport_id = vf->vport_id;
4222 return ecore_configure_vport_wfq(p_dev, vport_id, rate);
4225 enum _ecore_status_t ecore_iov_get_vf_stats(struct ecore_hwfn *p_hwfn,
4226 struct ecore_ptt *p_ptt,
4228 struct ecore_eth_stats *p_stats)
4230 struct ecore_vf_info *vf;
4232 vf = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4236 if (vf->state != VF_ENABLED)
4239 __ecore_get_vport_stats(p_hwfn, p_ptt, p_stats,
4240 vf->abs_vf_id + 0x10, false);
4242 return ECORE_SUCCESS;
4245 u8 ecore_iov_get_vf_num_rxqs(struct ecore_hwfn *p_hwfn, u16 rel_vf_id)
4247 struct ecore_vf_info *p_vf;
4249 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4253 return p_vf->num_rxqs;
4256 u8 ecore_iov_get_vf_num_active_rxqs(struct ecore_hwfn *p_hwfn, u16 rel_vf_id)
4258 struct ecore_vf_info *p_vf;
4260 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4264 return p_vf->num_active_rxqs;
4267 void *ecore_iov_get_vf_ctx(struct ecore_hwfn *p_hwfn, u16 rel_vf_id)
4269 struct ecore_vf_info *p_vf;
4271 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4278 u8 ecore_iov_get_vf_num_sbs(struct ecore_hwfn *p_hwfn, u16 rel_vf_id)
4280 struct ecore_vf_info *p_vf;
4282 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4286 return p_vf->num_sbs;
4289 bool ecore_iov_is_vf_wait_for_acquire(struct ecore_hwfn *p_hwfn, u16 rel_vf_id)
4291 struct ecore_vf_info *p_vf;
4293 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4297 return (p_vf->state == VF_FREE);
4300 bool ecore_iov_is_vf_acquired_not_initialized(struct ecore_hwfn *p_hwfn,
4303 struct ecore_vf_info *p_vf;
4305 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4309 return (p_vf->state == VF_ACQUIRED);
4312 bool ecore_iov_is_vf_initialized(struct ecore_hwfn *p_hwfn, u16 rel_vf_id)
4314 struct ecore_vf_info *p_vf;
4316 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4320 return (p_vf->state == VF_ENABLED);
4323 bool ecore_iov_is_vf_started(struct ecore_hwfn *p_hwfn,
4326 struct ecore_vf_info *p_vf;
4328 p_vf = ecore_iov_get_vf_info(p_hwfn, rel_vf_id, true);
4332 return (p_vf->state != VF_FREE && p_vf->state != VF_STOPPED);
4335 enum _ecore_status_t
4336 ecore_iov_get_vf_min_rate(struct ecore_hwfn *p_hwfn, int vfid)
4338 struct ecore_wfq_data *vf_vp_wfq;
4339 struct ecore_vf_info *vf_info;
4341 vf_info = ecore_iov_get_vf_info(p_hwfn, (u16)vfid, true);
4345 vf_vp_wfq = &p_hwfn->qm_info.wfq_data[vf_info->vport_id];
4347 if (vf_vp_wfq->configured)
4348 return vf_vp_wfq->min_speed;