aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/e1000
diff options
context:
space:
mode:
authorStephen Hemminger <shemminger@linux-foundation.org>2007-10-03 19:41:36 -0400
committerDavid S. Miller <davem@sunset.davemloft.net>2007-10-10 19:47:45 -0400
commitbea3348eef27e6044b6161fd04c3152215f96411 (patch)
treef0990b263e5ce42505d290a4c346fe990bcd4c33 /drivers/net/e1000
parentdde4e47e8fe333a5649a3fa0e7db1fa7c08d6158 (diff)
[NET]: Make NAPI polling independent of struct net_device objects.
Several devices have multiple independant RX queues per net device, and some have a single interrupt doorbell for several queues. In either case, it's easier to support layouts like that if the structure representing the poll is independant from the net device itself. The signature of the ->poll() call back goes from: int foo_poll(struct net_device *dev, int *budget) to int foo_poll(struct napi_struct *napi, int budget) The caller is returned the number of RX packets processed (or the number of "NAPI credits" consumed if you want to get abstract). The callee no longer messes around bumping dev->quota, *budget, etc. because that is all handled in the caller upon return. The napi_struct is to be embedded in the device driver private data structures. Furthermore, it is the driver's responsibility to disable all NAPI instances in it's ->stop() device close handler. Since the napi_struct is privatized into the driver's private data structures, only the driver knows how to get at all of the napi_struct instances it may have per-device. With lots of help and suggestions from Rusty Russell, Roland Dreier, Michael Chan, Jeff Garzik, and Jamal Hadi Salim. Bug fixes from Thomas Graf, Roland Dreier, Peter Zijlstra, Joseph Fannin, Scott Wood, Hans J. Koch, and Michael Chan. [ Ported to current tree and all drivers converted. Integrated Stephen's follow-on kerneldoc additions, and restored poll_list handling to the old style to fix mutual exclusion issues. -DaveM ] Signed-off-by: Stephen Hemminger <shemminger@linux-foundation.org> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/e1000')
-rw-r--r--drivers/net/e1000/e1000.h1
-rw-r--r--drivers/net/e1000/e1000_main.c45
2 files changed, 19 insertions, 27 deletions
diff --git a/drivers/net/e1000/e1000.h b/drivers/net/e1000/e1000.h
index 16a6edfeba41..781ed9968489 100644
--- a/drivers/net/e1000/e1000.h
+++ b/drivers/net/e1000/e1000.h
@@ -300,6 +300,7 @@ struct e1000_adapter {
300 int cleaned_count); 300 int cleaned_count);
301 struct e1000_rx_ring *rx_ring; /* One per active queue */ 301 struct e1000_rx_ring *rx_ring; /* One per active queue */
302#ifdef CONFIG_E1000_NAPI 302#ifdef CONFIG_E1000_NAPI
303 struct napi_struct napi;
303 struct net_device *polling_netdev; /* One per active queue */ 304 struct net_device *polling_netdev; /* One per active queue */
304#endif 305#endif
305 int num_tx_queues; 306 int num_tx_queues;
diff --git a/drivers/net/e1000/e1000_main.c b/drivers/net/e1000/e1000_main.c
index e7c8951f47fa..723568d6e44a 100644
--- a/drivers/net/e1000/e1000_main.c
+++ b/drivers/net/e1000/e1000_main.c
@@ -166,7 +166,7 @@ static irqreturn_t e1000_intr_msi(int irq, void *data);
166static boolean_t e1000_clean_tx_irq(struct e1000_adapter *adapter, 166static boolean_t e1000_clean_tx_irq(struct e1000_adapter *adapter,
167 struct e1000_tx_ring *tx_ring); 167 struct e1000_tx_ring *tx_ring);
168#ifdef CONFIG_E1000_NAPI 168#ifdef CONFIG_E1000_NAPI
169static int e1000_clean(struct net_device *poll_dev, int *budget); 169static int e1000_clean(struct napi_struct *napi, int budget);
170static boolean_t e1000_clean_rx_irq(struct e1000_adapter *adapter, 170static boolean_t e1000_clean_rx_irq(struct e1000_adapter *adapter,
171 struct e1000_rx_ring *rx_ring, 171 struct e1000_rx_ring *rx_ring,
172 int *work_done, int work_to_do); 172 int *work_done, int work_to_do);
@@ -545,7 +545,7 @@ int e1000_up(struct e1000_adapter *adapter)
545 clear_bit(__E1000_DOWN, &adapter->flags); 545 clear_bit(__E1000_DOWN, &adapter->flags);
546 546
547#ifdef CONFIG_E1000_NAPI 547#ifdef CONFIG_E1000_NAPI
548 netif_poll_enable(adapter->netdev); 548 napi_enable(&adapter->napi);
549#endif 549#endif
550 e1000_irq_enable(adapter); 550 e1000_irq_enable(adapter);
551 551
@@ -634,7 +634,7 @@ e1000_down(struct e1000_adapter *adapter)
634 set_bit(__E1000_DOWN, &adapter->flags); 634 set_bit(__E1000_DOWN, &adapter->flags);
635 635
636#ifdef CONFIG_E1000_NAPI 636#ifdef CONFIG_E1000_NAPI
637 netif_poll_disable(netdev); 637 napi_disable(&adapter->napi);
638#endif 638#endif
639 e1000_irq_disable(adapter); 639 e1000_irq_disable(adapter);
640 640
@@ -936,8 +936,7 @@ e1000_probe(struct pci_dev *pdev,
936 netdev->tx_timeout = &e1000_tx_timeout; 936 netdev->tx_timeout = &e1000_tx_timeout;
937 netdev->watchdog_timeo = 5 * HZ; 937 netdev->watchdog_timeo = 5 * HZ;
938#ifdef CONFIG_E1000_NAPI 938#ifdef CONFIG_E1000_NAPI
939 netdev->poll = &e1000_clean; 939 netif_napi_add(netdev, &adapter->napi, e1000_clean, 64);
940 netdev->weight = 64;
941#endif 940#endif
942 netdev->vlan_rx_register = e1000_vlan_rx_register; 941 netdev->vlan_rx_register = e1000_vlan_rx_register;
943 netdev->vlan_rx_add_vid = e1000_vlan_rx_add_vid; 942 netdev->vlan_rx_add_vid = e1000_vlan_rx_add_vid;
@@ -1151,9 +1150,6 @@ e1000_probe(struct pci_dev *pdev,
1151 /* tell the stack to leave us alone until e1000_open() is called */ 1150 /* tell the stack to leave us alone until e1000_open() is called */
1152 netif_carrier_off(netdev); 1151 netif_carrier_off(netdev);
1153 netif_stop_queue(netdev); 1152 netif_stop_queue(netdev);
1154#ifdef CONFIG_E1000_NAPI
1155 netif_poll_disable(netdev);
1156#endif
1157 1153
1158 strcpy(netdev->name, "eth%d"); 1154 strcpy(netdev->name, "eth%d");
1159 if ((err = register_netdev(netdev))) 1155 if ((err = register_netdev(netdev)))
@@ -1222,12 +1218,13 @@ e1000_remove(struct pci_dev *pdev)
1222 * would have already happened in close and is redundant. */ 1218 * would have already happened in close and is redundant. */
1223 e1000_release_hw_control(adapter); 1219 e1000_release_hw_control(adapter);
1224 1220
1225 unregister_netdev(netdev);
1226#ifdef CONFIG_E1000_NAPI 1221#ifdef CONFIG_E1000_NAPI
1227 for (i = 0; i < adapter->num_rx_queues; i++) 1222 for (i = 0; i < adapter->num_rx_queues; i++)
1228 dev_put(&adapter->polling_netdev[i]); 1223 dev_put(&adapter->polling_netdev[i]);
1229#endif 1224#endif
1230 1225
1226 unregister_netdev(netdev);
1227
1231 if (!e1000_check_phy_reset_block(&adapter->hw)) 1228 if (!e1000_check_phy_reset_block(&adapter->hw))
1232 e1000_phy_hw_reset(&adapter->hw); 1229 e1000_phy_hw_reset(&adapter->hw);
1233 1230
@@ -1325,8 +1322,6 @@ e1000_sw_init(struct e1000_adapter *adapter)
1325#ifdef CONFIG_E1000_NAPI 1322#ifdef CONFIG_E1000_NAPI
1326 for (i = 0; i < adapter->num_rx_queues; i++) { 1323 for (i = 0; i < adapter->num_rx_queues; i++) {
1327 adapter->polling_netdev[i].priv = adapter; 1324 adapter->polling_netdev[i].priv = adapter;
1328 adapter->polling_netdev[i].poll = &e1000_clean;
1329 adapter->polling_netdev[i].weight = 64;
1330 dev_hold(&adapter->polling_netdev[i]); 1325 dev_hold(&adapter->polling_netdev[i]);
1331 set_bit(__LINK_STATE_START, &adapter->polling_netdev[i].state); 1326 set_bit(__LINK_STATE_START, &adapter->polling_netdev[i].state);
1332 } 1327 }
@@ -1443,7 +1438,7 @@ e1000_open(struct net_device *netdev)
1443 clear_bit(__E1000_DOWN, &adapter->flags); 1438 clear_bit(__E1000_DOWN, &adapter->flags);
1444 1439
1445#ifdef CONFIG_E1000_NAPI 1440#ifdef CONFIG_E1000_NAPI
1446 netif_poll_enable(netdev); 1441 napi_enable(&adapter->napi);
1447#endif 1442#endif
1448 1443
1449 e1000_irq_enable(adapter); 1444 e1000_irq_enable(adapter);
@@ -3786,12 +3781,12 @@ e1000_intr_msi(int irq, void *data)
3786 } 3781 }
3787 3782
3788#ifdef CONFIG_E1000_NAPI 3783#ifdef CONFIG_E1000_NAPI
3789 if (likely(netif_rx_schedule_prep(netdev))) { 3784 if (likely(netif_rx_schedule_prep(netdev, &adapter->napi))) {
3790 adapter->total_tx_bytes = 0; 3785 adapter->total_tx_bytes = 0;
3791 adapter->total_tx_packets = 0; 3786 adapter->total_tx_packets = 0;
3792 adapter->total_rx_bytes = 0; 3787 adapter->total_rx_bytes = 0;
3793 adapter->total_rx_packets = 0; 3788 adapter->total_rx_packets = 0;
3794 __netif_rx_schedule(netdev); 3789 __netif_rx_schedule(netdev, &adapter->napi);
3795 } else 3790 } else
3796 e1000_irq_enable(adapter); 3791 e1000_irq_enable(adapter);
3797#else 3792#else
@@ -3871,12 +3866,12 @@ e1000_intr(int irq, void *data)
3871 E1000_WRITE_REG(hw, IMC, ~0); 3866 E1000_WRITE_REG(hw, IMC, ~0);
3872 E1000_WRITE_FLUSH(hw); 3867 E1000_WRITE_FLUSH(hw);
3873 } 3868 }
3874 if (likely(netif_rx_schedule_prep(netdev))) { 3869 if (likely(netif_rx_schedule_prep(netdev, &adapter->napi))) {
3875 adapter->total_tx_bytes = 0; 3870 adapter->total_tx_bytes = 0;
3876 adapter->total_tx_packets = 0; 3871 adapter->total_tx_packets = 0;
3877 adapter->total_rx_bytes = 0; 3872 adapter->total_rx_bytes = 0;
3878 adapter->total_rx_packets = 0; 3873 adapter->total_rx_packets = 0;
3879 __netif_rx_schedule(netdev); 3874 __netif_rx_schedule(netdev, &adapter->napi);
3880 } else 3875 } else
3881 /* this really should not happen! if it does it is basically a 3876 /* this really should not happen! if it does it is basically a
3882 * bug, but not a hard error, so enable ints and continue */ 3877 * bug, but not a hard error, so enable ints and continue */
@@ -3924,10 +3919,10 @@ e1000_intr(int irq, void *data)
3924 **/ 3919 **/
3925 3920
3926static int 3921static int
3927e1000_clean(struct net_device *poll_dev, int *budget) 3922e1000_clean(struct napi_struct *napi, int budget)
3928{ 3923{
3929 struct e1000_adapter *adapter; 3924 struct e1000_adapter *adapter = container_of(napi, struct e1000_adapter, napi);
3930 int work_to_do = min(*budget, poll_dev->quota); 3925 struct net_device *poll_dev = adapter->netdev;
3931 int tx_cleaned = 0, work_done = 0; 3926 int tx_cleaned = 0, work_done = 0;
3932 3927
3933 /* Must NOT use netdev_priv macro here. */ 3928 /* Must NOT use netdev_priv macro here. */
@@ -3948,23 +3943,19 @@ e1000_clean(struct net_device *poll_dev, int *budget)
3948 } 3943 }
3949 3944
3950 adapter->clean_rx(adapter, &adapter->rx_ring[0], 3945 adapter->clean_rx(adapter, &adapter->rx_ring[0],
3951 &work_done, work_to_do); 3946 &work_done, budget);
3952
3953 *budget -= work_done;
3954 poll_dev->quota -= work_done;
3955 3947
3956 /* If no Tx and not enough Rx work done, exit the polling mode */ 3948 /* If no Tx and not enough Rx work done, exit the polling mode */
3957 if ((!tx_cleaned && (work_done == 0)) || 3949 if ((!tx_cleaned && (work_done < budget)) ||
3958 !netif_running(poll_dev)) { 3950 !netif_running(poll_dev)) {
3959quit_polling: 3951quit_polling:
3960 if (likely(adapter->itr_setting & 3)) 3952 if (likely(adapter->itr_setting & 3))
3961 e1000_set_itr(adapter); 3953 e1000_set_itr(adapter);
3962 netif_rx_complete(poll_dev); 3954 netif_rx_complete(poll_dev, napi);
3963 e1000_irq_enable(adapter); 3955 e1000_irq_enable(adapter);
3964 return 0;
3965 } 3956 }
3966 3957
3967 return 1; 3958 return work_done;
3968} 3959}
3969 3960
3970#endif 3961#endif