diff options
author | Scott Feldman <scofeldm@cisco.com> | 2009-09-03 13:02:45 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2009-09-03 23:19:25 -0400 |
commit | 6fdfa97073a2bcbb60d900654c612b2ff09b9cb7 (patch) | |
tree | 3297813813e0a1a82664e13b52cbc79ecb36ae92 /drivers/net/enic/enic_main.c | |
parent | 491598a44f12fe8b862ab4123de1a1ffe9b86832 (diff) |
enic: organize device initialization/deinit into separate functions
To unclutter probe() a little bit, put all device initialization code
in one spot and device deinit code in another spot. Also remove unused
rq->buf_index variable/func.
Signed-off-by: Scott Feldman <scofeldm@cisco.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/enic/enic_main.c')
-rw-r--r-- | drivers/net/enic/enic_main.c | 145 |
1 files changed, 89 insertions, 56 deletions
diff --git a/drivers/net/enic/enic_main.c b/drivers/net/enic/enic_main.c index f800218c6595..d69d52ed7726 100644 --- a/drivers/net/enic/enic_main.c +++ b/drivers/net/enic/enic_main.c | |||
@@ -1741,6 +1741,88 @@ static const struct net_device_ops enic_netdev_ops = { | |||
1741 | #endif | 1741 | #endif |
1742 | }; | 1742 | }; |
1743 | 1743 | ||
1744 | void enic_dev_deinit(struct enic *enic) | ||
1745 | { | ||
1746 | netif_napi_del(&enic->napi); | ||
1747 | enic_free_vnic_resources(enic); | ||
1748 | enic_clear_intr_mode(enic); | ||
1749 | } | ||
1750 | |||
1751 | int enic_dev_init(struct enic *enic) | ||
1752 | { | ||
1753 | struct net_device *netdev = enic->netdev; | ||
1754 | int err; | ||
1755 | |||
1756 | /* Get vNIC configuration | ||
1757 | */ | ||
1758 | |||
1759 | err = enic_get_vnic_config(enic); | ||
1760 | if (err) { | ||
1761 | printk(KERN_ERR PFX | ||
1762 | "Get vNIC configuration failed, aborting.\n"); | ||
1763 | return err; | ||
1764 | } | ||
1765 | |||
1766 | /* Get available resource counts | ||
1767 | */ | ||
1768 | |||
1769 | enic_get_res_counts(enic); | ||
1770 | |||
1771 | /* Set interrupt mode based on resource counts and system | ||
1772 | * capabilities | ||
1773 | */ | ||
1774 | |||
1775 | err = enic_set_intr_mode(enic); | ||
1776 | if (err) { | ||
1777 | printk(KERN_ERR PFX | ||
1778 | "Failed to set intr mode, aborting.\n"); | ||
1779 | return err; | ||
1780 | } | ||
1781 | |||
1782 | /* Allocate and configure vNIC resources | ||
1783 | */ | ||
1784 | |||
1785 | err = enic_alloc_vnic_resources(enic); | ||
1786 | if (err) { | ||
1787 | printk(KERN_ERR PFX | ||
1788 | "Failed to alloc vNIC resources, aborting.\n"); | ||
1789 | goto err_out_free_vnic_resources; | ||
1790 | } | ||
1791 | |||
1792 | enic_init_vnic_resources(enic); | ||
1793 | |||
1794 | err = enic_set_rq_alloc_buf(enic); | ||
1795 | if (err) { | ||
1796 | printk(KERN_ERR PFX | ||
1797 | "Failed to set RQ buffer allocator, aborting.\n"); | ||
1798 | goto err_out_free_vnic_resources; | ||
1799 | } | ||
1800 | |||
1801 | err = enic_set_niccfg(enic); | ||
1802 | if (err) { | ||
1803 | printk(KERN_ERR PFX | ||
1804 | "Failed to config nic, aborting.\n"); | ||
1805 | goto err_out_free_vnic_resources; | ||
1806 | } | ||
1807 | |||
1808 | switch (vnic_dev_get_intr_mode(enic->vdev)) { | ||
1809 | default: | ||
1810 | netif_napi_add(netdev, &enic->napi, enic_poll, 64); | ||
1811 | break; | ||
1812 | case VNIC_DEV_INTR_MODE_MSIX: | ||
1813 | netif_napi_add(netdev, &enic->napi, enic_poll_msix, 64); | ||
1814 | break; | ||
1815 | } | ||
1816 | |||
1817 | return 0; | ||
1818 | |||
1819 | err_out_free_vnic_resources: | ||
1820 | enic_clear_intr_mode(enic); | ||
1821 | enic_free_vnic_resources(enic); | ||
1822 | |||
1823 | return err; | ||
1824 | } | ||
1825 | |||
1744 | static void enic_iounmap(struct enic *enic) | 1826 | static void enic_iounmap(struct enic *enic) |
1745 | { | 1827 | { |
1746 | unsigned int i; | 1828 | unsigned int i; |
@@ -1883,51 +1965,13 @@ static int __devinit enic_probe(struct pci_dev *pdev, | |||
1883 | goto err_out_dev_close; | 1965 | goto err_out_dev_close; |
1884 | } | 1966 | } |
1885 | 1967 | ||
1886 | /* Get vNIC configuration | 1968 | err = enic_dev_init(enic); |
1887 | */ | ||
1888 | |||
1889 | err = enic_get_vnic_config(enic); | ||
1890 | if (err) { | 1969 | if (err) { |
1891 | printk(KERN_ERR PFX | 1970 | printk(KERN_ERR PFX |
1892 | "Get vNIC configuration failed, aborting.\n"); | 1971 | "Device initialization failed, aborting.\n"); |
1893 | goto err_out_dev_close; | 1972 | goto err_out_dev_close; |
1894 | } | 1973 | } |
1895 | 1974 | ||
1896 | /* Get available resource counts | ||
1897 | */ | ||
1898 | |||
1899 | enic_get_res_counts(enic); | ||
1900 | |||
1901 | /* Set interrupt mode based on resource counts and system | ||
1902 | * capabilities | ||
1903 | */ | ||
1904 | |||
1905 | err = enic_set_intr_mode(enic); | ||
1906 | if (err) { | ||
1907 | printk(KERN_ERR PFX | ||
1908 | "Failed to set intr mode, aborting.\n"); | ||
1909 | goto err_out_dev_close; | ||
1910 | } | ||
1911 | |||
1912 | /* Allocate and configure vNIC resources | ||
1913 | */ | ||
1914 | |||
1915 | err = enic_alloc_vnic_resources(enic); | ||
1916 | if (err) { | ||
1917 | printk(KERN_ERR PFX | ||
1918 | "Failed to alloc vNIC resources, aborting.\n"); | ||
1919 | goto err_out_free_vnic_resources; | ||
1920 | } | ||
1921 | |||
1922 | enic_init_vnic_resources(enic); | ||
1923 | |||
1924 | err = enic_set_niccfg(enic); | ||
1925 | if (err) { | ||
1926 | printk(KERN_ERR PFX | ||
1927 | "Failed to config nic, aborting.\n"); | ||
1928 | goto err_out_free_vnic_resources; | ||
1929 | } | ||
1930 | |||
1931 | /* Setup notification timer, HW reset task, and locks | 1975 | /* Setup notification timer, HW reset task, and locks |
1932 | */ | 1976 | */ |
1933 | 1977 | ||
@@ -1952,22 +1996,13 @@ static int __devinit enic_probe(struct pci_dev *pdev, | |||
1952 | if (err) { | 1996 | if (err) { |
1953 | printk(KERN_ERR PFX | 1997 | printk(KERN_ERR PFX |
1954 | "Invalid MAC address, aborting.\n"); | 1998 | "Invalid MAC address, aborting.\n"); |
1955 | goto err_out_free_vnic_resources; | 1999 | goto err_out_dev_deinit; |
1956 | } | 2000 | } |
1957 | 2001 | ||
1958 | netdev->netdev_ops = &enic_netdev_ops; | 2002 | netdev->netdev_ops = &enic_netdev_ops; |
1959 | netdev->watchdog_timeo = 2 * HZ; | 2003 | netdev->watchdog_timeo = 2 * HZ; |
1960 | netdev->ethtool_ops = &enic_ethtool_ops; | 2004 | netdev->ethtool_ops = &enic_ethtool_ops; |
1961 | 2005 | ||
1962 | switch (vnic_dev_get_intr_mode(enic->vdev)) { | ||
1963 | default: | ||
1964 | netif_napi_add(netdev, &enic->napi, enic_poll, 64); | ||
1965 | break; | ||
1966 | case VNIC_DEV_INTR_MODE_MSIX: | ||
1967 | netif_napi_add(netdev, &enic->napi, enic_poll_msix, 64); | ||
1968 | break; | ||
1969 | } | ||
1970 | |||
1971 | netdev->features |= NETIF_F_HW_VLAN_TX | | 2006 | netdev->features |= NETIF_F_HW_VLAN_TX | |
1972 | NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_FILTER; | 2007 | NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_FILTER; |
1973 | if (ENIC_SETTING(enic, TXCSUM)) | 2008 | if (ENIC_SETTING(enic, TXCSUM)) |
@@ -1995,17 +2030,16 @@ static int __devinit enic_probe(struct pci_dev *pdev, | |||
1995 | if (err) { | 2030 | if (err) { |
1996 | printk(KERN_ERR PFX | 2031 | printk(KERN_ERR PFX |
1997 | "Cannot register net device, aborting.\n"); | 2032 | "Cannot register net device, aborting.\n"); |
1998 | goto err_out_free_vnic_resources; | 2033 | goto err_out_dev_deinit; |
1999 | } | 2034 | } |
2000 | 2035 | ||
2001 | return 0; | 2036 | return 0; |
2002 | 2037 | ||
2003 | err_out_free_vnic_resources: | 2038 | err_out_dev_deinit: |
2004 | enic_free_vnic_resources(enic); | 2039 | enic_dev_deinit(enic); |
2005 | err_out_dev_close: | 2040 | err_out_dev_close: |
2006 | vnic_dev_close(enic->vdev); | 2041 | vnic_dev_close(enic->vdev); |
2007 | err_out_vnic_unregister: | 2042 | err_out_vnic_unregister: |
2008 | enic_clear_intr_mode(enic); | ||
2009 | vnic_dev_unregister(enic->vdev); | 2043 | vnic_dev_unregister(enic->vdev); |
2010 | err_out_iounmap: | 2044 | err_out_iounmap: |
2011 | enic_iounmap(enic); | 2045 | enic_iounmap(enic); |
@@ -2029,9 +2063,8 @@ static void __devexit enic_remove(struct pci_dev *pdev) | |||
2029 | 2063 | ||
2030 | flush_scheduled_work(); | 2064 | flush_scheduled_work(); |
2031 | unregister_netdev(netdev); | 2065 | unregister_netdev(netdev); |
2032 | enic_free_vnic_resources(enic); | 2066 | enic_dev_deinit(enic); |
2033 | vnic_dev_close(enic->vdev); | 2067 | vnic_dev_close(enic->vdev); |
2034 | enic_clear_intr_mode(enic); | ||
2035 | vnic_dev_unregister(enic->vdev); | 2068 | vnic_dev_unregister(enic->vdev); |
2036 | enic_iounmap(enic); | 2069 | enic_iounmap(enic); |
2037 | pci_release_regions(pdev); | 2070 | pci_release_regions(pdev); |