aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/igb
diff options
context:
space:
mode:
authorAlexander Duyck <alexander.h.duyck@intel.com>2009-10-27 19:47:53 -0400
committerDavid S. Miller <davem@davemloft.net>2009-10-28 06:25:42 -0400
commita6b623e0e5787ba5ffd2a3c4448ff6d1eaa904a9 (patch)
treeef526a59111600f157ae54062a2b39a40d1b052c /drivers/net/igb
parent51466239fb9f95343e88c14475a0f99fe4882c54 (diff)
igb: move vf init into a seperate function
This patch moves VF initialization into a seperate function to help improve the readability of igb_probe. Signed-off-by: Alexander Duyck <alexander.h.duyck@intel.com> Signed-off-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/igb')
-rw-r--r--drivers/net/igb/igb_main.c98
1 files changed, 56 insertions, 42 deletions
diff --git a/drivers/net/igb/igb_main.c b/drivers/net/igb/igb_main.c
index 91709272ae1f..54e8f02929d9 100644
--- a/drivers/net/igb/igb_main.c
+++ b/drivers/net/igb/igb_main.c
@@ -1409,46 +1409,6 @@ static int __devinit igb_probe(struct pci_dev *pdev,
1409 if (err) 1409 if (err)
1410 goto err_sw_init; 1410 goto err_sw_init;
1411 1411
1412#ifdef CONFIG_PCI_IOV
1413 /* since iov functionality isn't critical to base device function we
1414 * can accept failure. If it fails we don't allow iov to be enabled */
1415 if (hw->mac.type == e1000_82576) {
1416 /* 82576 supports a maximum of 7 VFs in addition to the PF */
1417 unsigned int num_vfs = (max_vfs > 7) ? 7 : max_vfs;
1418 int i;
1419 unsigned char mac_addr[ETH_ALEN];
1420
1421 if (num_vfs) {
1422 adapter->vf_data = kcalloc(num_vfs,
1423 sizeof(struct vf_data_storage),
1424 GFP_KERNEL);
1425 if (!adapter->vf_data) {
1426 dev_err(&pdev->dev,
1427 "Could not allocate VF private data - "
1428 "IOV enable failed\n");
1429 } else {
1430 err = pci_enable_sriov(pdev, num_vfs);
1431 if (!err) {
1432 adapter->vfs_allocated_count = num_vfs;
1433 dev_info(&pdev->dev,
1434 "%d vfs allocated\n",
1435 num_vfs);
1436 for (i = 0;
1437 i < adapter->vfs_allocated_count;
1438 i++) {
1439 random_ether_addr(mac_addr);
1440 igb_set_vf_mac(adapter, i,
1441 mac_addr);
1442 }
1443 } else {
1444 kfree(adapter->vf_data);
1445 adapter->vf_data = NULL;
1446 }
1447 }
1448 }
1449 }
1450
1451#endif
1452 /* setup the private structure */ 1412 /* setup the private structure */
1453 err = igb_sw_init(adapter); 1413 err = igb_sw_init(adapter);
1454 if (err) 1414 if (err)
@@ -1772,6 +1732,54 @@ static void __devexit igb_remove(struct pci_dev *pdev)
1772} 1732}
1773 1733
1774/** 1734/**
1735 * igb_probe_vfs - Initialize vf data storage and add VFs to pci config space
1736 * @adapter: board private structure to initialize
1737 *
1738 * This function initializes the vf specific data storage and then attempts to
1739 * allocate the VFs. The reason for ordering it this way is because it is much
1740 * mor expensive time wise to disable SR-IOV than it is to allocate and free
1741 * the memory for the VFs.
1742 **/
1743static void __devinit igb_probe_vfs(struct igb_adapter * adapter)
1744{
1745#ifdef CONFIG_PCI_IOV
1746 struct pci_dev *pdev = adapter->pdev;
1747
1748 if (adapter->vfs_allocated_count > 7)
1749 adapter->vfs_allocated_count = 7;
1750
1751 if (adapter->vfs_allocated_count) {
1752 adapter->vf_data = kcalloc(adapter->vfs_allocated_count,
1753 sizeof(struct vf_data_storage),
1754 GFP_KERNEL);
1755 /* if allocation failed then we do not support SR-IOV */
1756 if (!adapter->vf_data) {
1757 adapter->vfs_allocated_count = 0;
1758 dev_err(&pdev->dev, "Unable to allocate memory for VF "
1759 "Data Storage\n");
1760 }
1761 }
1762
1763 if (pci_enable_sriov(pdev, adapter->vfs_allocated_count)) {
1764 kfree(adapter->vf_data);
1765 adapter->vf_data = NULL;
1766#endif /* CONFIG_PCI_IOV */
1767 adapter->vfs_allocated_count = 0;
1768#ifdef CONFIG_PCI_IOV
1769 } else {
1770 unsigned char mac_addr[ETH_ALEN];
1771 int i;
1772 dev_info(&pdev->dev, "%d vfs allocated\n",
1773 adapter->vfs_allocated_count);
1774 for (i = 0; i < adapter->vfs_allocated_count; i++) {
1775 random_ether_addr(mac_addr);
1776 igb_set_vf_mac(adapter, i, mac_addr);
1777 }
1778 }
1779#endif /* CONFIG_PCI_IOV */
1780}
1781
1782/**
1775 * igb_sw_init - Initialize general software structures (struct igb_adapter) 1783 * igb_sw_init - Initialize general software structures (struct igb_adapter)
1776 * @adapter: board private structure to initialize 1784 * @adapter: board private structure to initialize
1777 * 1785 *
@@ -1795,13 +1803,19 @@ static int __devinit igb_sw_init(struct igb_adapter *adapter)
1795 adapter->max_frame_size = netdev->mtu + ETH_HLEN + ETH_FCS_LEN; 1803 adapter->max_frame_size = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
1796 adapter->min_frame_size = ETH_ZLEN + ETH_FCS_LEN; 1804 adapter->min_frame_size = ETH_ZLEN + ETH_FCS_LEN;
1797 1805
1798 /* This call may decrease the number of queues depending on 1806#ifdef CONFIG_PCI_IOV
1799 * interrupt mode. */ 1807 if (hw->mac.type == e1000_82576)
1808 adapter->vfs_allocated_count = max_vfs;
1809
1810#endif /* CONFIG_PCI_IOV */
1811 /* This call may decrease the number of queues */
1800 if (igb_init_interrupt_scheme(adapter)) { 1812 if (igb_init_interrupt_scheme(adapter)) {
1801 dev_err(&pdev->dev, "Unable to allocate memory for queues\n"); 1813 dev_err(&pdev->dev, "Unable to allocate memory for queues\n");
1802 return -ENOMEM; 1814 return -ENOMEM;
1803 } 1815 }
1804 1816
1817 igb_probe_vfs(adapter);
1818
1805 /* Explicitly disable IRQ since the NIC can be in any state. */ 1819 /* Explicitly disable IRQ since the NIC can be in any state. */
1806 igb_irq_disable(adapter); 1820 igb_irq_disable(adapter);
1807 1821