aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/enic
diff options
context:
space:
mode:
authorScott Feldman <scofeldm@cisco.com>2009-09-03 13:02:45 -0400
committerDavid S. Miller <davem@davemloft.net>2009-09-03 23:19:25 -0400
commit6fdfa97073a2bcbb60d900654c612b2ff09b9cb7 (patch)
tree3297813813e0a1a82664e13b52cbc79ecb36ae92 /drivers/net/enic
parent491598a44f12fe8b862ab4123de1a1ffe9b86832 (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')
-rw-r--r--drivers/net/enic/enic_main.c145
-rw-r--r--drivers/net/enic/vnic_rq.c27
-rw-r--r--drivers/net/enic/vnic_rq.h12
-rw-r--r--drivers/net/enic/vnic_wq.c20
-rw-r--r--drivers/net/enic/vnic_wq.h4
5 files changed, 133 insertions, 75 deletions
diff --git a/drivers/net/enic/enic_main.c b/drivers/net/enic/enic_main.c
index f800218c659..d69d52ed772 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
1744void 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
1751int 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
1819err_out_free_vnic_resources:
1820 enic_clear_intr_mode(enic);
1821 enic_free_vnic_resources(enic);
1822
1823 return err;
1824}
1825
1744static void enic_iounmap(struct enic *enic) 1826static 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
2003err_out_free_vnic_resources: 2038err_out_dev_deinit:
2004 enic_free_vnic_resources(enic); 2039 enic_dev_deinit(enic);
2005err_out_dev_close: 2040err_out_dev_close:
2006 vnic_dev_close(enic->vdev); 2041 vnic_dev_close(enic->vdev);
2007err_out_vnic_unregister: 2042err_out_vnic_unregister:
2008 enic_clear_intr_mode(enic);
2009 vnic_dev_unregister(enic->vdev); 2043 vnic_dev_unregister(enic->vdev);
2010err_out_iounmap: 2044err_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);
diff --git a/drivers/net/enic/vnic_rq.c b/drivers/net/enic/vnic_rq.c
index 9365e63e821..75583978a5e 100644
--- a/drivers/net/enic/vnic_rq.c
+++ b/drivers/net/enic/vnic_rq.c
@@ -62,7 +62,6 @@ static int vnic_rq_alloc_bufs(struct vnic_rq *rq)
62 } 62 }
63 63
64 rq->to_use = rq->to_clean = rq->bufs[0]; 64 rq->to_use = rq->to_clean = rq->bufs[0];
65 rq->buf_index = 0;
66 65
67 return 0; 66 return 0;
68} 67}
@@ -113,12 +112,12 @@ int vnic_rq_alloc(struct vnic_dev *vdev, struct vnic_rq *rq, unsigned int index,
113 return 0; 112 return 0;
114} 113}
115 114
116void vnic_rq_init(struct vnic_rq *rq, unsigned int cq_index, 115void vnic_rq_init_start(struct vnic_rq *rq, unsigned int cq_index,
116 unsigned int fetch_index, unsigned int posted_index,
117 unsigned int error_interrupt_enable, 117 unsigned int error_interrupt_enable,
118 unsigned int error_interrupt_offset) 118 unsigned int error_interrupt_offset)
119{ 119{
120 u64 paddr; 120 u64 paddr;
121 u32 fetch_index;
122 121
123 paddr = (u64)rq->ring.base_addr | VNIC_PADDR_TARGET; 122 paddr = (u64)rq->ring.base_addr | VNIC_PADDR_TARGET;
124 writeq(paddr, &rq->ctrl->ring_base); 123 writeq(paddr, &rq->ctrl->ring_base);
@@ -128,15 +127,27 @@ void vnic_rq_init(struct vnic_rq *rq, unsigned int cq_index,
128 iowrite32(error_interrupt_offset, &rq->ctrl->error_interrupt_offset); 127 iowrite32(error_interrupt_offset, &rq->ctrl->error_interrupt_offset);
129 iowrite32(0, &rq->ctrl->dropped_packet_count); 128 iowrite32(0, &rq->ctrl->dropped_packet_count);
130 iowrite32(0, &rq->ctrl->error_status); 129 iowrite32(0, &rq->ctrl->error_status);
130 iowrite32(fetch_index, &rq->ctrl->fetch_index);
131 iowrite32(posted_index, &rq->ctrl->posted_index);
131 132
132 /* Use current fetch_index as the ring starting point */
133 fetch_index = ioread32(&rq->ctrl->fetch_index);
134 rq->to_use = rq->to_clean = 133 rq->to_use = rq->to_clean =
135 &rq->bufs[fetch_index / VNIC_RQ_BUF_BLK_ENTRIES] 134 &rq->bufs[fetch_index / VNIC_RQ_BUF_BLK_ENTRIES]
136 [fetch_index % VNIC_RQ_BUF_BLK_ENTRIES]; 135 [fetch_index % VNIC_RQ_BUF_BLK_ENTRIES];
137 iowrite32(fetch_index, &rq->ctrl->posted_index); 136}
137
138void vnic_rq_init(struct vnic_rq *rq, unsigned int cq_index,
139 unsigned int error_interrupt_enable,
140 unsigned int error_interrupt_offset)
141{
142 u32 fetch_index;
138 143
139 rq->buf_index = 0; 144 /* Use current fetch_index as the ring starting point */
145 fetch_index = ioread32(&rq->ctrl->fetch_index);
146
147 vnic_rq_init_start(rq, cq_index,
148 fetch_index, fetch_index,
149 error_interrupt_enable,
150 error_interrupt_offset);
140} 151}
141 152
142unsigned int vnic_rq_error_status(struct vnic_rq *rq) 153unsigned int vnic_rq_error_status(struct vnic_rq *rq)
@@ -192,8 +203,6 @@ void vnic_rq_clean(struct vnic_rq *rq,
192 [fetch_index % VNIC_RQ_BUF_BLK_ENTRIES]; 203 [fetch_index % VNIC_RQ_BUF_BLK_ENTRIES];
193 iowrite32(fetch_index, &rq->ctrl->posted_index); 204 iowrite32(fetch_index, &rq->ctrl->posted_index);
194 205
195 rq->buf_index = 0;
196
197 vnic_dev_clear_desc_ring(&rq->ring); 206 vnic_dev_clear_desc_ring(&rq->ring);
198} 207}
199 208
diff --git a/drivers/net/enic/vnic_rq.h b/drivers/net/enic/vnic_rq.h
index f7b5730cb74..35e736cc2d8 100644
--- a/drivers/net/enic/vnic_rq.h
+++ b/drivers/net/enic/vnic_rq.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright 2008 Cisco Systems, Inc. All rights reserved. 2 * Copyright 2008, 2009 Cisco Systems, Inc. All rights reserved.
3 * Copyright 2007 Nuova Systems, Inc. All rights reserved. 3 * Copyright 2007 Nuova Systems, Inc. All rights reserved.
4 * 4 *
5 * This program is free software; you may redistribute it and/or modify 5 * This program is free software; you may redistribute it and/or modify
@@ -79,7 +79,6 @@ struct vnic_rq {
79 struct vnic_rq_buf *to_use; 79 struct vnic_rq_buf *to_use;
80 struct vnic_rq_buf *to_clean; 80 struct vnic_rq_buf *to_clean;
81 void *os_buf_head; 81 void *os_buf_head;
82 unsigned int buf_index;
83 unsigned int pkts_outstanding; 82 unsigned int pkts_outstanding;
84}; 83};
85 84
@@ -105,11 +104,6 @@ static inline unsigned int vnic_rq_next_index(struct vnic_rq *rq)
105 return rq->to_use->index; 104 return rq->to_use->index;
106} 105}
107 106
108static inline unsigned int vnic_rq_next_buf_index(struct vnic_rq *rq)
109{
110 return rq->buf_index++;
111}
112
113static inline void vnic_rq_post(struct vnic_rq *rq, 107static inline void vnic_rq_post(struct vnic_rq *rq,
114 void *os_buf, unsigned int os_buf_index, 108 void *os_buf, unsigned int os_buf_index,
115 dma_addr_t dma_addr, unsigned int len) 109 dma_addr_t dma_addr, unsigned int len)
@@ -204,6 +198,10 @@ static inline int vnic_rq_fill(struct vnic_rq *rq,
204void vnic_rq_free(struct vnic_rq *rq); 198void vnic_rq_free(struct vnic_rq *rq);
205int vnic_rq_alloc(struct vnic_dev *vdev, struct vnic_rq *rq, unsigned int index, 199int vnic_rq_alloc(struct vnic_dev *vdev, struct vnic_rq *rq, unsigned int index,
206 unsigned int desc_count, unsigned int desc_size); 200 unsigned int desc_count, unsigned int desc_size);
201void vnic_rq_init_start(struct vnic_rq *rq, unsigned int cq_index,
202 unsigned int fetch_index, unsigned int posted_index,
203 unsigned int error_interrupt_enable,
204 unsigned int error_interrupt_offset);
207void vnic_rq_init(struct vnic_rq *rq, unsigned int cq_index, 205void vnic_rq_init(struct vnic_rq *rq, unsigned int cq_index,
208 unsigned int error_interrupt_enable, 206 unsigned int error_interrupt_enable,
209 unsigned int error_interrupt_offset); 207 unsigned int error_interrupt_offset);
diff --git a/drivers/net/enic/vnic_wq.c b/drivers/net/enic/vnic_wq.c
index a576d04708e..d2e00e51b7b 100644
--- a/drivers/net/enic/vnic_wq.c
+++ b/drivers/net/enic/vnic_wq.c
@@ -112,7 +112,8 @@ int vnic_wq_alloc(struct vnic_dev *vdev, struct vnic_wq *wq, unsigned int index,
112 return 0; 112 return 0;
113} 113}
114 114
115void vnic_wq_init(struct vnic_wq *wq, unsigned int cq_index, 115void vnic_wq_init_start(struct vnic_wq *wq, unsigned int cq_index,
116 unsigned int fetch_index, unsigned int posted_index,
116 unsigned int error_interrupt_enable, 117 unsigned int error_interrupt_enable,
117 unsigned int error_interrupt_offset) 118 unsigned int error_interrupt_offset)
118{ 119{
@@ -121,12 +122,25 @@ void vnic_wq_init(struct vnic_wq *wq, unsigned int cq_index,
121 paddr = (u64)wq->ring.base_addr | VNIC_PADDR_TARGET; 122 paddr = (u64)wq->ring.base_addr | VNIC_PADDR_TARGET;
122 writeq(paddr, &wq->ctrl->ring_base); 123 writeq(paddr, &wq->ctrl->ring_base);
123 iowrite32(wq->ring.desc_count, &wq->ctrl->ring_size); 124 iowrite32(wq->ring.desc_count, &wq->ctrl->ring_size);
124 iowrite32(0, &wq->ctrl->fetch_index); 125 iowrite32(fetch_index, &wq->ctrl->fetch_index);
125 iowrite32(0, &wq->ctrl->posted_index); 126 iowrite32(posted_index, &wq->ctrl->posted_index);
126 iowrite32(cq_index, &wq->ctrl->cq_index); 127 iowrite32(cq_index, &wq->ctrl->cq_index);
127 iowrite32(error_interrupt_enable, &wq->ctrl->error_interrupt_enable); 128 iowrite32(error_interrupt_enable, &wq->ctrl->error_interrupt_enable);
128 iowrite32(error_interrupt_offset, &wq->ctrl->error_interrupt_offset); 129 iowrite32(error_interrupt_offset, &wq->ctrl->error_interrupt_offset);
129 iowrite32(0, &wq->ctrl->error_status); 130 iowrite32(0, &wq->ctrl->error_status);
131
132 wq->to_use = wq->to_clean =
133 &wq->bufs[fetch_index / VNIC_WQ_BUF_BLK_ENTRIES]
134 [fetch_index % VNIC_WQ_BUF_BLK_ENTRIES];
135}
136
137void vnic_wq_init(struct vnic_wq *wq, unsigned int cq_index,
138 unsigned int error_interrupt_enable,
139 unsigned int error_interrupt_offset)
140{
141 vnic_wq_init_start(wq, cq_index, 0, 0,
142 error_interrupt_enable,
143 error_interrupt_offset);
130} 144}
131 145
132unsigned int vnic_wq_error_status(struct vnic_wq *wq) 146unsigned int vnic_wq_error_status(struct vnic_wq *wq)
diff --git a/drivers/net/enic/vnic_wq.h b/drivers/net/enic/vnic_wq.h
index c826137dc65..9c34d41a887 100644
--- a/drivers/net/enic/vnic_wq.h
+++ b/drivers/net/enic/vnic_wq.h
@@ -149,6 +149,10 @@ static inline void vnic_wq_service(struct vnic_wq *wq,
149void vnic_wq_free(struct vnic_wq *wq); 149void vnic_wq_free(struct vnic_wq *wq);
150int vnic_wq_alloc(struct vnic_dev *vdev, struct vnic_wq *wq, unsigned int index, 150int vnic_wq_alloc(struct vnic_dev *vdev, struct vnic_wq *wq, unsigned int index,
151 unsigned int desc_count, unsigned int desc_size); 151 unsigned int desc_count, unsigned int desc_size);
152void 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);
152void vnic_wq_init(struct vnic_wq *wq, unsigned int cq_index, 156void vnic_wq_init(struct vnic_wq *wq, unsigned int cq_index,
153 unsigned int error_interrupt_enable, 157 unsigned int error_interrupt_enable,
154 unsigned int error_interrupt_offset); 158 unsigned int error_interrupt_offset);