/* All our allocations have been reset */
        efx_ef10_reset_mc_allocations(efx);
 
+       /* Driver-created vswitches and vports must be re-created */
+       nic_data->must_probe_vswitching = true;
+       nic_data->vport_id = EVB_PORT_ID_ASSIGNED;
+
        /* The datapath firmware might have been changed */
        nic_data->must_check_datapath_caps = true;
 
        .sriov_set_vf_vlan = efx_ef10_sriov_set_vf_vlan,
        .sriov_set_vf_spoofchk = efx_ef10_sriov_set_vf_spoofchk,
        .sriov_get_vf_config = efx_ef10_sriov_get_vf_config,
+       .vswitching_probe = efx_ef10_vswitching_probe,
+       .vswitching_restore = efx_ef10_vswitching_restore,
+       .vswitching_remove = efx_ef10_vswitching_remove,
 #endif
 
        .revision = EFX_REV_HUNT_A0,
 
        else
                return efx_ef10_pci_sriov_enable(efx, num_vfs);
 }
+
+static int efx_ef10_vswitch_alloc(struct efx_nic *efx, unsigned int port_id,
+                                 unsigned int vswitch_type)
+{
+       MCDI_DECLARE_BUF(inbuf, MC_CMD_VSWITCH_ALLOC_IN_LEN);
+
+       MCDI_SET_DWORD(inbuf, VSWITCH_ALLOC_IN_UPSTREAM_PORT_ID, port_id);
+       MCDI_SET_DWORD(inbuf, VSWITCH_ALLOC_IN_TYPE, vswitch_type);
+       MCDI_SET_DWORD(inbuf, VSWITCH_ALLOC_IN_NUM_VLAN_TAGS, 0);
+       MCDI_POPULATE_DWORD_1(inbuf, VSWITCH_ALLOC_IN_FLAGS,
+                             VSWITCH_ALLOC_IN_FLAG_AUTO_PORT, 0);
+
+       return efx_mcdi_rpc(efx, MC_CMD_VSWITCH_ALLOC, inbuf, sizeof(inbuf),
+                           NULL, 0, NULL);
+}
+
+static int efx_ef10_vswitch_free(struct efx_nic *efx, unsigned int port_id)
+{
+       MCDI_DECLARE_BUF(inbuf, MC_CMD_VSWITCH_FREE_IN_LEN);
+
+       MCDI_SET_DWORD(inbuf, VSWITCH_FREE_IN_UPSTREAM_PORT_ID, port_id);
+
+       return efx_mcdi_rpc(efx, MC_CMD_VSWITCH_FREE, inbuf, sizeof(inbuf),
+                           NULL, 0, NULL);
+}
+
+static int efx_ef10_vport_alloc(struct efx_nic *efx,
+                               unsigned int port_id_in,
+                               unsigned int vport_type,
+                               unsigned int *port_id_out)
+{
+       MCDI_DECLARE_BUF(inbuf, MC_CMD_VPORT_ALLOC_IN_LEN);
+       MCDI_DECLARE_BUF(outbuf, MC_CMD_VPORT_ALLOC_OUT_LEN);
+       size_t outlen;
+       int rc;
+
+       EFX_WARN_ON_PARANOID(!port_id_out);
+
+       MCDI_SET_DWORD(inbuf, VPORT_ALLOC_IN_UPSTREAM_PORT_ID, port_id_in);
+       MCDI_SET_DWORD(inbuf, VPORT_ALLOC_IN_TYPE, vport_type);
+       MCDI_SET_DWORD(inbuf, VPORT_ALLOC_IN_NUM_VLAN_TAGS, 0);
+       MCDI_POPULATE_DWORD_1(inbuf, VPORT_ALLOC_IN_FLAGS,
+                             VPORT_ALLOC_IN_FLAG_AUTO_PORT, 0);
+
+       rc = efx_mcdi_rpc(efx, MC_CMD_VPORT_ALLOC, inbuf, sizeof(inbuf),
+                         outbuf, sizeof(outbuf), &outlen);
+       if (rc)
+               return rc;
+       if (outlen < MC_CMD_VPORT_ALLOC_OUT_LEN)
+               return -EIO;
+
+       *port_id_out = MCDI_DWORD(outbuf, VPORT_ALLOC_OUT_VPORT_ID);
+       return 0;
+}
+
+static int efx_ef10_vport_free(struct efx_nic *efx, unsigned int port_id)
+{
+       MCDI_DECLARE_BUF(inbuf, MC_CMD_VPORT_FREE_IN_LEN);
+
+       MCDI_SET_DWORD(inbuf, VPORT_FREE_IN_VPORT_ID, port_id);
+
+       return efx_mcdi_rpc(efx, MC_CMD_VPORT_FREE, inbuf, sizeof(inbuf),
+                           NULL, 0, NULL);
+}
+
+/* On top of the default firmware vswitch setup, create a VEB vswitch and
+ * expansion vport for use by this function.
+ */
+int efx_ef10_vswitching_probe(struct efx_nic *efx)
+{
+       struct efx_ef10_nic_data *nic_data = efx->nic_data;
+       int rc;
+
+       if (pci_sriov_get_totalvfs(efx->pci_dev) <= 0)
+               return 0; /* vswitch not needed as we have no VFs */
+
+       rc = efx_ef10_vswitch_alloc(efx, EVB_PORT_ID_ASSIGNED,
+                                   MC_CMD_VSWITCH_ALLOC_IN_VSWITCH_TYPE_VEB);
+       if (rc)
+               goto fail1;
+
+       rc = efx_ef10_vport_alloc(efx, EVB_PORT_ID_ASSIGNED,
+                                 MC_CMD_VPORT_ALLOC_IN_VPORT_TYPE_NORMAL,
+                                 &nic_data->vport_id);
+       if (rc)
+               goto fail2;
+
+       return 0;
+fail2:
+       efx_ef10_vswitch_free(efx, EVB_PORT_ID_ASSIGNED);
+fail1:
+       return rc;
+}
+
+int efx_ef10_vswitching_restore(struct efx_nic *efx)
+{
+       struct efx_ef10_nic_data *nic_data = efx->nic_data;
+       int rc;
+
+       if (!nic_data->must_probe_vswitching)
+               return 0;
+
+       rc = efx_ef10_vswitching_probe(efx);
+
+       if (!rc)
+               nic_data->must_probe_vswitching = false;
+       return rc;
+}
+
+void efx_ef10_vswitching_remove(struct efx_nic *efx)
+{
+       struct efx_ef10_nic_data *nic_data = efx->nic_data;
+
+       if (nic_data->vport_id == EVB_PORT_ID_ASSIGNED)
+               return; /* No vswitch was ever created */
+
+       efx_ef10_vport_free(efx, nic_data->vport_id);
+       nic_data->vport_id = EVB_PORT_ID_ASSIGNED;
+
+       efx_ef10_vswitch_free(efx, nic_data->vport_id);
+}
 
        }
        efx->rxq_entries = efx->txq_entries = EFX_DEFAULT_DMAQ_SIZE;
 
+#ifdef CONFIG_SFC_SRIOV
+       rc = efx->type->vswitching_probe(efx);
+       if (rc) /* not fatal; the PF will still work fine */
+               netif_warn(efx, probe, efx->net_dev,
+                          "failed to setup vswitching rc=%d;"
+                          " VFs may not function\n", rc);
+#endif
+
        rc = efx_probe_filters(efx);
        if (rc) {
                netif_err(efx, probe, efx->net_dev,
                          "failed to create filter tables\n");
-               goto fail3;
+               goto fail4;
        }
 
        rc = efx_probe_channels(efx);
        if (rc)
-               goto fail4;
+               goto fail5;
 
        return 0;
 
- fail4:
+ fail5:
        efx_remove_filters(efx);
+ fail4:
+#ifdef CONFIG_SFC_SRIOV
+       efx->type->vswitching_remove(efx);
+#endif
  fail3:
        efx_remove_port(efx);
  fail2:
 {
        efx_remove_channels(efx);
        efx_remove_filters(efx);
+#ifdef CONFIG_SFC_SRIOV
+       efx->type->vswitching_remove(efx);
+#endif
        efx_remove_port(efx);
        efx_remove_nic(efx);
 }
        rc = efx_enable_interrupts(efx);
        if (rc)
                goto fail;
+
+#ifdef CONFIG_SFC_SRIOV
+       rc = efx->type->vswitching_restore(efx);
+       if (rc) /* not fatal; the PF will still work fine */
+               netif_warn(efx, probe, efx->net_dev,
+                          "failed to restore vswitching rc=%d;"
+                          " VFs may not function\n", rc);
+#endif
+
        efx_restore_filters(efx);
        if (efx->type->sriov_reset)
                efx->type->sriov_reset(efx);