1 // SPDX-License-Identifier: GPL-2.0-only 2 /**************************************************************************** 3 * Driver for Solarflare network controllers and boards 4 * Copyright 2019 Solarflare Communications Inc. 5 * Copyright 2020-2022 Xilinx Inc. 6 * 7 * This program is free software; you can redistribute it and/or modify it 8 * under the terms of the GNU General Public License version 2 as published 9 * by the Free Software Foundation, incorporated herein by reference. 10 */ 11 12 #include "ef100_sriov.h" 13 #include "ef100_nic.h" 14 15 static int efx_ef100_pci_sriov_enable(struct efx_nic *efx, int num_vfs) 16 { 17 struct pci_dev *dev = efx->pci_dev; 18 int rc; 19 20 efx->vf_count = num_vfs; 21 rc = pci_enable_sriov(dev, num_vfs); 22 if (rc) 23 goto fail; 24 25 return 0; 26 27 fail: 28 netif_err(efx, probe, efx->net_dev, "Failed to enable SRIOV VFs\n"); 29 efx->vf_count = 0; 30 return rc; 31 } 32 33 int efx_ef100_pci_sriov_disable(struct efx_nic *efx) 34 { 35 struct pci_dev *dev = efx->pci_dev; 36 unsigned int vfs_assigned; 37 38 vfs_assigned = pci_vfs_assigned(dev); 39 if (vfs_assigned) { 40 netif_info(efx, drv, efx->net_dev, "VFs are assigned to guests; " 41 "please detach them before disabling SR-IOV\n"); 42 return -EBUSY; 43 } 44 45 pci_disable_sriov(dev); 46 47 return 0; 48 } 49 50 int efx_ef100_sriov_configure(struct efx_nic *efx, int num_vfs) 51 { 52 if (num_vfs == 0) 53 return efx_ef100_pci_sriov_disable(efx); 54 else 55 return efx_ef100_pci_sriov_enable(efx, num_vfs); 56 } 57