Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Scott Feldman and committed by
David S. Miller
6fdfa970 491598a4

+133 -75
+89 -56
drivers/net/enic/enic_main.c
··· 1741 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 1826 static void enic_iounmap(struct enic *enic) 1745 1827 { 1746 1828 unsigned int i; ··· 1965 1883 goto err_out_dev_close; 1966 1884 } 1967 1885 1968 - /* Get vNIC configuration 1969 - */ 1970 - 1971 - err = enic_get_vnic_config(enic); 1886 + err = enic_dev_init(enic); 1972 1887 if (err) { 1973 1888 printk(KERN_ERR PFX 1974 - "Get vNIC configuration failed, aborting.\n"); 1889 + "Device initialization failed, aborting.\n"); 1975 1890 goto err_out_dev_close; 1976 - } 1977 - 1978 - /* Get available resource counts 1979 - */ 1980 - 1981 - enic_get_res_counts(enic); 1982 - 1983 - /* Set interrupt mode based on resource counts and system 1984 - * capabilities 1985 - */ 1986 - 1987 - err = enic_set_intr_mode(enic); 1988 - if (err) { 1989 - printk(KERN_ERR PFX 1990 - "Failed to set intr mode, aborting.\n"); 1991 - goto err_out_dev_close; 1992 - } 1993 - 1994 - /* Allocate and configure vNIC resources 1995 - */ 1996 - 1997 - err = enic_alloc_vnic_resources(enic); 1998 - if (err) { 1999 - printk(KERN_ERR PFX 2000 - "Failed to alloc vNIC resources, aborting.\n"); 2001 - goto err_out_free_vnic_resources; 2002 - } 2003 - 2004 - enic_init_vnic_resources(enic); 2005 - 2006 - err = enic_set_niccfg(enic); 2007 - if (err) { 2008 - printk(KERN_ERR PFX 2009 - "Failed to config nic, aborting.\n"); 2010 - goto err_out_free_vnic_resources; 2011 1891 } 2012 1892 2013 1893 /* Setup notification timer, HW reset task, and locks ··· 1996 1952 if (err) { 1997 1953 printk(KERN_ERR PFX 1998 1954 "Invalid MAC address, aborting.\n"); 1999 - goto err_out_free_vnic_resources; 1955 + goto err_out_dev_deinit; 2000 1956 } 2001 1957 2002 1958 netdev->netdev_ops = &enic_netdev_ops; 2003 1959 netdev->watchdog_timeo = 2 * HZ; 2004 1960 netdev->ethtool_ops = &enic_ethtool_ops; 2005 - 2006 - switch (vnic_dev_get_intr_mode(enic->vdev)) { 2007 - default: 2008 - netif_napi_add(netdev, &enic->napi, enic_poll, 64); 2009 - break; 2010 - case VNIC_DEV_INTR_MODE_MSIX: 2011 - netif_napi_add(netdev, &enic->napi, enic_poll_msix, 64); 2012 - break; 2013 - } 2014 1961 2015 1962 netdev->features |= NETIF_F_HW_VLAN_TX | 2016 1963 NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_FILTER; ··· 2030 1995 if (err) { 2031 1996 printk(KERN_ERR PFX 2032 1997 "Cannot register net device, aborting.\n"); 2033 - goto err_out_free_vnic_resources; 1998 + goto err_out_dev_deinit; 2034 1999 } 2035 2000 2036 2001 return 0; 2037 2002 2038 - err_out_free_vnic_resources: 2039 - enic_free_vnic_resources(enic); 2003 + err_out_dev_deinit: 2004 + enic_dev_deinit(enic); 2040 2005 err_out_dev_close: 2041 2006 vnic_dev_close(enic->vdev); 2042 2007 err_out_vnic_unregister: 2043 - enic_clear_intr_mode(enic); 2044 2008 vnic_dev_unregister(enic->vdev); 2045 2009 err_out_iounmap: 2046 2010 enic_iounmap(enic); ··· 2063 2029 2064 2030 flush_scheduled_work(); 2065 2031 unregister_netdev(netdev); 2066 - enic_free_vnic_resources(enic); 2032 + enic_dev_deinit(enic); 2067 2033 vnic_dev_close(enic->vdev); 2068 - enic_clear_intr_mode(enic); 2069 2034 vnic_dev_unregister(enic->vdev); 2070 2035 enic_iounmap(enic); 2071 2036 pci_release_regions(pdev);
+18 -9
drivers/net/enic/vnic_rq.c
··· 62 62 } 63 63 64 64 rq->to_use = rq->to_clean = rq->bufs[0]; 65 - rq->buf_index = 0; 66 65 67 66 return 0; 68 67 } ··· 112 113 return 0; 113 114 } 114 115 115 - void vnic_rq_init(struct vnic_rq *rq, unsigned int cq_index, 116 + void vnic_rq_init_start(struct vnic_rq *rq, unsigned int cq_index, 117 + unsigned int fetch_index, unsigned int posted_index, 116 118 unsigned int error_interrupt_enable, 117 119 unsigned int error_interrupt_offset) 118 120 { 119 121 u64 paddr; 120 - u32 fetch_index; 121 122 122 123 paddr = (u64)rq->ring.base_addr | VNIC_PADDR_TARGET; 123 124 writeq(paddr, &rq->ctrl->ring_base); ··· 127 128 iowrite32(error_interrupt_offset, &rq->ctrl->error_interrupt_offset); 128 129 iowrite32(0, &rq->ctrl->dropped_packet_count); 129 130 iowrite32(0, &rq->ctrl->error_status); 131 + iowrite32(fetch_index, &rq->ctrl->fetch_index); 132 + iowrite32(posted_index, &rq->ctrl->posted_index); 130 133 131 - /* Use current fetch_index as the ring starting point */ 132 - fetch_index = ioread32(&rq->ctrl->fetch_index); 133 134 rq->to_use = rq->to_clean = 134 135 &rq->bufs[fetch_index / VNIC_RQ_BUF_BLK_ENTRIES] 135 136 [fetch_index % VNIC_RQ_BUF_BLK_ENTRIES]; 136 - iowrite32(fetch_index, &rq->ctrl->posted_index); 137 + } 137 138 138 - rq->buf_index = 0; 139 + void vnic_rq_init(struct vnic_rq *rq, unsigned int cq_index, 140 + unsigned int error_interrupt_enable, 141 + unsigned int error_interrupt_offset) 142 + { 143 + u32 fetch_index; 144 + 145 + /* Use current fetch_index as the ring starting point */ 146 + fetch_index = ioread32(&rq->ctrl->fetch_index); 147 + 148 + vnic_rq_init_start(rq, cq_index, 149 + fetch_index, fetch_index, 150 + error_interrupt_enable, 151 + error_interrupt_offset); 139 152 } 140 153 141 154 unsigned int vnic_rq_error_status(struct vnic_rq *rq) ··· 202 191 &rq->bufs[fetch_index / VNIC_RQ_BUF_BLK_ENTRIES] 203 192 [fetch_index % VNIC_RQ_BUF_BLK_ENTRIES]; 204 193 iowrite32(fetch_index, &rq->ctrl->posted_index); 205 - 206 - rq->buf_index = 0; 207 194 208 195 vnic_dev_clear_desc_ring(&rq->ring); 209 196 }
+5 -7
drivers/net/enic/vnic_rq.h
··· 1 1 /* 2 - * Copyright 2008 Cisco Systems, Inc. All rights reserved. 2 + * Copyright 2008, 2009 Cisco Systems, Inc. All rights reserved. 3 3 * Copyright 2007 Nuova Systems, Inc. All rights reserved. 4 4 * 5 5 * This program is free software; you may redistribute it and/or modify ··· 79 79 struct vnic_rq_buf *to_use; 80 80 struct vnic_rq_buf *to_clean; 81 81 void *os_buf_head; 82 - unsigned int buf_index; 83 82 unsigned int pkts_outstanding; 84 83 }; 85 84 ··· 102 103 static inline unsigned int vnic_rq_next_index(struct vnic_rq *rq) 103 104 { 104 105 return rq->to_use->index; 105 - } 106 - 107 - static inline unsigned int vnic_rq_next_buf_index(struct vnic_rq *rq) 108 - { 109 - return rq->buf_index++; 110 106 } 111 107 112 108 static inline void vnic_rq_post(struct vnic_rq *rq, ··· 198 204 void vnic_rq_free(struct vnic_rq *rq); 199 205 int vnic_rq_alloc(struct vnic_dev *vdev, struct vnic_rq *rq, unsigned int index, 200 206 unsigned int desc_count, unsigned int desc_size); 207 + void vnic_rq_init_start(struct vnic_rq *rq, unsigned int cq_index, 208 + unsigned int fetch_index, unsigned int posted_index, 209 + unsigned int error_interrupt_enable, 210 + unsigned int error_interrupt_offset); 201 211 void vnic_rq_init(struct vnic_rq *rq, unsigned int cq_index, 202 212 unsigned int error_interrupt_enable, 203 213 unsigned int error_interrupt_offset);
+17 -3
drivers/net/enic/vnic_wq.c
··· 112 112 return 0; 113 113 } 114 114 115 - void vnic_wq_init(struct vnic_wq *wq, unsigned int cq_index, 115 + void vnic_wq_init_start(struct vnic_wq *wq, unsigned int cq_index, 116 + unsigned int fetch_index, unsigned int posted_index, 116 117 unsigned int error_interrupt_enable, 117 118 unsigned int error_interrupt_offset) 118 119 { ··· 122 121 paddr = (u64)wq->ring.base_addr | VNIC_PADDR_TARGET; 123 122 writeq(paddr, &wq->ctrl->ring_base); 124 123 iowrite32(wq->ring.desc_count, &wq->ctrl->ring_size); 125 - iowrite32(0, &wq->ctrl->fetch_index); 126 - iowrite32(0, &wq->ctrl->posted_index); 124 + iowrite32(fetch_index, &wq->ctrl->fetch_index); 125 + iowrite32(posted_index, &wq->ctrl->posted_index); 127 126 iowrite32(cq_index, &wq->ctrl->cq_index); 128 127 iowrite32(error_interrupt_enable, &wq->ctrl->error_interrupt_enable); 129 128 iowrite32(error_interrupt_offset, &wq->ctrl->error_interrupt_offset); 130 129 iowrite32(0, &wq->ctrl->error_status); 130 + 131 + wq->to_use = wq->to_clean = 132 + &wq->bufs[fetch_index / VNIC_WQ_BUF_BLK_ENTRIES] 133 + [fetch_index % VNIC_WQ_BUF_BLK_ENTRIES]; 134 + } 135 + 136 + void vnic_wq_init(struct vnic_wq *wq, unsigned int cq_index, 137 + unsigned int error_interrupt_enable, 138 + unsigned int error_interrupt_offset) 139 + { 140 + vnic_wq_init_start(wq, cq_index, 0, 0, 141 + error_interrupt_enable, 142 + error_interrupt_offset); 131 143 } 132 144 133 145 unsigned int vnic_wq_error_status(struct vnic_wq *wq)
+4
drivers/net/enic/vnic_wq.h
··· 149 149 void vnic_wq_free(struct vnic_wq *wq); 150 150 int vnic_wq_alloc(struct vnic_dev *vdev, struct vnic_wq *wq, unsigned int index, 151 151 unsigned int desc_count, unsigned int desc_size); 152 + void vnic_wq_init_start(struct vnic_wq *wq, unsigned int cq_index, 153 + unsigned int fetch_index, unsigned int posted_index, 154 + unsigned int error_interrupt_enable, 155 + unsigned int error_interrupt_offset); 152 156 void vnic_wq_init(struct vnic_wq *wq, unsigned int cq_index, 153 157 unsigned int error_interrupt_enable, 154 158 unsigned int error_interrupt_offset);