diff options
author | Auke Kok <auke-jan.h.kok@intel.com> | 2006-06-27 12:06:28 -0400 |
---|---|---|
committer | Auke Kok <juke-jan.h.kok@intel.com> | 2006-06-27 12:06:28 -0400 |
commit | 2db10a081c5c1082d58809a1bcf1a6073f4db160 (patch) | |
tree | f54772ef60f2c5bf5f8d602a83d6dc508158a0e0 /drivers/net/e1000/e1000_main.c | |
parent | acfbc9fde2ec7f304398f6ad7644002e07bf84bc (diff) |
e1000: rework driver hardware reset locking
After studying the driver mac reset code it was found that there
were multiple race conditions possible to reset the unit twice or
bring it e1000_up() double. This fixes all occurences where the
driver needs to reset the mac.
We also remove irq requesting/releasing into _open and _close so
that while the device is _up we will never touch the irq's. This fixes
the double free irq bug that people saw.
To make sure that the watchdog task doesn't cause another race we let
it run as a non-scheduled task.
Signed-off-by: Jesse Brandeburg <jesse.brandeburg@intel.com>
Signed-off-by: Auke Kok <auke-jan.h.kok@intel.com>
Diffstat (limited to 'drivers/net/e1000/e1000_main.c')
-rw-r--r-- | drivers/net/e1000/e1000_main.c | 126 |
1 files changed, 73 insertions, 53 deletions
diff --git a/drivers/net/e1000/e1000_main.c b/drivers/net/e1000/e1000_main.c index a373ccb308d8..52d698bb2595 100644 --- a/drivers/net/e1000/e1000_main.c +++ b/drivers/net/e1000/e1000_main.c | |||
@@ -133,7 +133,6 @@ static void e1000_clean_rx_ring(struct e1000_adapter *adapter, | |||
133 | static void e1000_set_multi(struct net_device *netdev); | 133 | static void e1000_set_multi(struct net_device *netdev); |
134 | static void e1000_update_phy_info(unsigned long data); | 134 | static void e1000_update_phy_info(unsigned long data); |
135 | static void e1000_watchdog(unsigned long data); | 135 | static void e1000_watchdog(unsigned long data); |
136 | static void e1000_watchdog_task(struct e1000_adapter *adapter); | ||
137 | static void e1000_82547_tx_fifo_stall(unsigned long data); | 136 | static void e1000_82547_tx_fifo_stall(unsigned long data); |
138 | static int e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev); | 137 | static int e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev); |
139 | static struct net_device_stats * e1000_get_stats(struct net_device *netdev); | 138 | static struct net_device_stats * e1000_get_stats(struct net_device *netdev); |
@@ -261,6 +260,44 @@ e1000_exit_module(void) | |||
261 | 260 | ||
262 | module_exit(e1000_exit_module); | 261 | module_exit(e1000_exit_module); |
263 | 262 | ||
263 | static int e1000_request_irq(struct e1000_adapter *adapter) | ||
264 | { | ||
265 | struct net_device *netdev = adapter->netdev; | ||
266 | int flags, err = 0; | ||
267 | |||
268 | flags = SA_SHIRQ | SA_SAMPLE_RANDOM; | ||
269 | #ifdef CONFIG_PCI_MSI | ||
270 | if (adapter->hw.mac_type > e1000_82547_rev_2) { | ||
271 | adapter->have_msi = TRUE; | ||
272 | if ((err = pci_enable_msi(adapter->pdev))) { | ||
273 | DPRINTK(PROBE, ERR, | ||
274 | "Unable to allocate MSI interrupt Error: %d\n", err); | ||
275 | adapter->have_msi = FALSE; | ||
276 | } | ||
277 | } | ||
278 | if (adapter->have_msi) | ||
279 | flags &= ~SA_SHIRQ; | ||
280 | #endif | ||
281 | if ((err = request_irq(adapter->pdev->irq, &e1000_intr, flags, | ||
282 | netdev->name, netdev))) | ||
283 | DPRINTK(PROBE, ERR, | ||
284 | "Unable to allocate interrupt Error: %d\n", err); | ||
285 | |||
286 | return err; | ||
287 | } | ||
288 | |||
289 | static void e1000_free_irq(struct e1000_adapter *adapter) | ||
290 | { | ||
291 | struct net_device *netdev = adapter->netdev; | ||
292 | |||
293 | free_irq(adapter->pdev->irq, netdev); | ||
294 | |||
295 | #ifdef CONFIG_PCI_MSI | ||
296 | if (adapter->have_msi) | ||
297 | pci_disable_msi(adapter->pdev); | ||
298 | #endif | ||
299 | } | ||
300 | |||
264 | /** | 301 | /** |
265 | * e1000_irq_disable - Mask off interrupt generation on the NIC | 302 | * e1000_irq_disable - Mask off interrupt generation on the NIC |
266 | * @adapter: board private structure | 303 | * @adapter: board private structure |
@@ -387,7 +424,7 @@ int | |||
387 | e1000_up(struct e1000_adapter *adapter) | 424 | e1000_up(struct e1000_adapter *adapter) |
388 | { | 425 | { |
389 | struct net_device *netdev = adapter->netdev; | 426 | struct net_device *netdev = adapter->netdev; |
390 | int i, err; | 427 | int i; |
391 | 428 | ||
392 | /* hardware has been reset, we need to reload some things */ | 429 | /* hardware has been reset, we need to reload some things */ |
393 | 430 | ||
@@ -415,24 +452,6 @@ e1000_up(struct e1000_adapter *adapter) | |||
415 | E1000_DESC_UNUSED(ring)); | 452 | E1000_DESC_UNUSED(ring)); |
416 | } | 453 | } |
417 | 454 | ||
418 | #ifdef CONFIG_PCI_MSI | ||
419 | if (adapter->hw.mac_type > e1000_82547_rev_2) { | ||
420 | adapter->have_msi = TRUE; | ||
421 | if ((err = pci_enable_msi(adapter->pdev))) { | ||
422 | DPRINTK(PROBE, ERR, | ||
423 | "Unable to allocate MSI interrupt Error: %d\n", err); | ||
424 | adapter->have_msi = FALSE; | ||
425 | } | ||
426 | } | ||
427 | #endif | ||
428 | if ((err = request_irq(adapter->pdev->irq, &e1000_intr, | ||
429 | SA_SHIRQ | SA_SAMPLE_RANDOM, | ||
430 | netdev->name, netdev))) { | ||
431 | DPRINTK(PROBE, ERR, | ||
432 | "Unable to allocate interrupt Error: %d\n", err); | ||
433 | return err; | ||
434 | } | ||
435 | |||
436 | adapter->tx_queue_len = netdev->tx_queue_len; | 455 | adapter->tx_queue_len = netdev->tx_queue_len; |
437 | 456 | ||
438 | mod_timer(&adapter->watchdog_timer, jiffies); | 457 | mod_timer(&adapter->watchdog_timer, jiffies); |
@@ -450,16 +469,10 @@ e1000_down(struct e1000_adapter *adapter) | |||
450 | { | 469 | { |
451 | struct net_device *netdev = adapter->netdev; | 470 | struct net_device *netdev = adapter->netdev; |
452 | boolean_t mng_mode_enabled = (adapter->hw.mac_type >= e1000_82571) && | 471 | boolean_t mng_mode_enabled = (adapter->hw.mac_type >= e1000_82571) && |
453 | e1000_check_mng_mode(&adapter->hw); | 472 | e1000_check_mng_mode(&adapter->hw); |
454 | 473 | ||
455 | e1000_irq_disable(adapter); | 474 | e1000_irq_disable(adapter); |
456 | 475 | ||
457 | free_irq(adapter->pdev->irq, netdev); | ||
458 | #ifdef CONFIG_PCI_MSI | ||
459 | if (adapter->hw.mac_type > e1000_82547_rev_2 && | ||
460 | adapter->have_msi == TRUE) | ||
461 | pci_disable_msi(adapter->pdev); | ||
462 | #endif | ||
463 | del_timer_sync(&adapter->tx_fifo_stall_timer); | 476 | del_timer_sync(&adapter->tx_fifo_stall_timer); |
464 | del_timer_sync(&adapter->watchdog_timer); | 477 | del_timer_sync(&adapter->watchdog_timer); |
465 | del_timer_sync(&adapter->phy_info_timer); | 478 | del_timer_sync(&adapter->phy_info_timer); |
@@ -496,6 +509,17 @@ e1000_down(struct e1000_adapter *adapter) | |||
496 | } | 509 | } |
497 | 510 | ||
498 | void | 511 | void |
512 | e1000_reinit_locked(struct e1000_adapter *adapter) | ||
513 | { | ||
514 | WARN_ON(in_interrupt()); | ||
515 | while (test_and_set_bit(__E1000_RESETTING, &adapter->flags)) | ||
516 | msleep(1); | ||
517 | e1000_down(adapter); | ||
518 | e1000_up(adapter); | ||
519 | clear_bit(__E1000_RESETTING, &adapter->flags); | ||
520 | } | ||
521 | |||
522 | void | ||
499 | e1000_reset(struct e1000_adapter *adapter) | 523 | e1000_reset(struct e1000_adapter *adapter) |
500 | { | 524 | { |
501 | uint32_t pba, manc; | 525 | uint32_t pba, manc; |
@@ -758,9 +782,6 @@ e1000_probe(struct pci_dev *pdev, | |||
758 | adapter->watchdog_timer.function = &e1000_watchdog; | 782 | adapter->watchdog_timer.function = &e1000_watchdog; |
759 | adapter->watchdog_timer.data = (unsigned long) adapter; | 783 | adapter->watchdog_timer.data = (unsigned long) adapter; |
760 | 784 | ||
761 | INIT_WORK(&adapter->watchdog_task, | ||
762 | (void (*)(void *))e1000_watchdog_task, adapter); | ||
763 | |||
764 | init_timer(&adapter->phy_info_timer); | 785 | init_timer(&adapter->phy_info_timer); |
765 | adapter->phy_info_timer.function = &e1000_update_phy_info; | 786 | adapter->phy_info_timer.function = &e1000_update_phy_info; |
766 | adapter->phy_info_timer.data = (unsigned long) adapter; | 787 | adapter->phy_info_timer.data = (unsigned long) adapter; |
@@ -1078,6 +1099,10 @@ e1000_open(struct net_device *netdev) | |||
1078 | struct e1000_adapter *adapter = netdev_priv(netdev); | 1099 | struct e1000_adapter *adapter = netdev_priv(netdev); |
1079 | int err; | 1100 | int err; |
1080 | 1101 | ||
1102 | /* disallow open during test */ | ||
1103 | if (test_bit(__E1000_DRIVER_TESTING, &adapter->flags)) | ||
1104 | return -EBUSY; | ||
1105 | |||
1081 | /* allocate transmit descriptors */ | 1106 | /* allocate transmit descriptors */ |
1082 | 1107 | ||
1083 | if ((err = e1000_setup_all_tx_resources(adapter))) | 1108 | if ((err = e1000_setup_all_tx_resources(adapter))) |
@@ -1088,6 +1113,10 @@ e1000_open(struct net_device *netdev) | |||
1088 | if ((err = e1000_setup_all_rx_resources(adapter))) | 1113 | if ((err = e1000_setup_all_rx_resources(adapter))) |
1089 | goto err_setup_rx; | 1114 | goto err_setup_rx; |
1090 | 1115 | ||
1116 | err = e1000_request_irq(adapter); | ||
1117 | if (err) | ||
1118 | goto err_up; | ||
1119 | |||
1091 | if ((err = e1000_up(adapter))) | 1120 | if ((err = e1000_up(adapter))) |
1092 | goto err_up; | 1121 | goto err_up; |
1093 | adapter->mng_vlan_id = E1000_MNG_VLAN_NONE; | 1122 | adapter->mng_vlan_id = E1000_MNG_VLAN_NONE; |
@@ -1131,7 +1160,9 @@ e1000_close(struct net_device *netdev) | |||
1131 | { | 1160 | { |
1132 | struct e1000_adapter *adapter = netdev_priv(netdev); | 1161 | struct e1000_adapter *adapter = netdev_priv(netdev); |
1133 | 1162 | ||
1163 | WARN_ON(test_bit(__E1000_RESETTING, &adapter->flags)); | ||
1134 | e1000_down(adapter); | 1164 | e1000_down(adapter); |
1165 | e1000_free_irq(adapter); | ||
1135 | 1166 | ||
1136 | e1000_free_all_tx_resources(adapter); | 1167 | e1000_free_all_tx_resources(adapter); |
1137 | e1000_free_all_rx_resources(adapter); | 1168 | e1000_free_all_rx_resources(adapter); |
@@ -2201,14 +2232,6 @@ static void | |||
2201 | e1000_watchdog(unsigned long data) | 2232 | e1000_watchdog(unsigned long data) |
2202 | { | 2233 | { |
2203 | struct e1000_adapter *adapter = (struct e1000_adapter *) data; | 2234 | struct e1000_adapter *adapter = (struct e1000_adapter *) data; |
2204 | |||
2205 | /* Do the rest outside of interrupt context */ | ||
2206 | schedule_work(&adapter->watchdog_task); | ||
2207 | } | ||
2208 | |||
2209 | static void | ||
2210 | e1000_watchdog_task(struct e1000_adapter *adapter) | ||
2211 | { | ||
2212 | struct net_device *netdev = adapter->netdev; | 2235 | struct net_device *netdev = adapter->netdev; |
2213 | struct e1000_tx_ring *txdr = adapter->tx_ring; | 2236 | struct e1000_tx_ring *txdr = adapter->tx_ring; |
2214 | uint32_t link, tctl; | 2237 | uint32_t link, tctl; |
@@ -2919,8 +2942,7 @@ e1000_reset_task(struct net_device *netdev) | |||
2919 | { | 2942 | { |
2920 | struct e1000_adapter *adapter = netdev_priv(netdev); | 2943 | struct e1000_adapter *adapter = netdev_priv(netdev); |
2921 | 2944 | ||
2922 | e1000_down(adapter); | 2945 | e1000_reinit_locked(adapter); |
2923 | e1000_up(adapter); | ||
2924 | } | 2946 | } |
2925 | 2947 | ||
2926 | /** | 2948 | /** |
@@ -3026,10 +3048,8 @@ e1000_change_mtu(struct net_device *netdev, int new_mtu) | |||
3026 | 3048 | ||
3027 | netdev->mtu = new_mtu; | 3049 | netdev->mtu = new_mtu; |
3028 | 3050 | ||
3029 | if (netif_running(netdev)) { | 3051 | if (netif_running(netdev)) |
3030 | e1000_down(adapter); | 3052 | e1000_reinit_locked(adapter); |
3031 | e1000_up(adapter); | ||
3032 | } | ||
3033 | 3053 | ||
3034 | adapter->hw.max_frame_size = max_frame; | 3054 | adapter->hw.max_frame_size = max_frame; |
3035 | 3055 | ||
@@ -4180,10 +4200,9 @@ e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd) | |||
4180 | return retval; | 4200 | return retval; |
4181 | } | 4201 | } |
4182 | } | 4202 | } |
4183 | if (netif_running(adapter->netdev)) { | 4203 | if (netif_running(adapter->netdev)) |
4184 | e1000_down(adapter); | 4204 | e1000_reinit_locked(adapter); |
4185 | e1000_up(adapter); | 4205 | else |
4186 | } else | ||
4187 | e1000_reset(adapter); | 4206 | e1000_reset(adapter); |
4188 | break; | 4207 | break; |
4189 | case M88E1000_PHY_SPEC_CTRL: | 4208 | case M88E1000_PHY_SPEC_CTRL: |
@@ -4200,10 +4219,9 @@ e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd) | |||
4200 | case PHY_CTRL: | 4219 | case PHY_CTRL: |
4201 | if (mii_reg & MII_CR_POWER_DOWN) | 4220 | if (mii_reg & MII_CR_POWER_DOWN) |
4202 | break; | 4221 | break; |
4203 | if (netif_running(adapter->netdev)) { | 4222 | if (netif_running(adapter->netdev)) |
4204 | e1000_down(adapter); | 4223 | e1000_reinit_locked(adapter); |
4205 | e1000_up(adapter); | 4224 | else |
4206 | } else | ||
4207 | e1000_reset(adapter); | 4225 | e1000_reset(adapter); |
4208 | break; | 4226 | break; |
4209 | } | 4227 | } |
@@ -4462,8 +4480,10 @@ e1000_suspend(struct pci_dev *pdev, pm_message_t state) | |||
4462 | 4480 | ||
4463 | netif_device_detach(netdev); | 4481 | netif_device_detach(netdev); |
4464 | 4482 | ||
4465 | if (netif_running(netdev)) | 4483 | if (netif_running(netdev)) { |
4484 | WARN_ON(test_bit(__E1000_RESETTING, &adapter->flags)); | ||
4466 | e1000_down(adapter); | 4485 | e1000_down(adapter); |
4486 | } | ||
4467 | 4487 | ||
4468 | #ifdef CONFIG_PM | 4488 | #ifdef CONFIG_PM |
4469 | /* Implement our own version of pci_save_state(pdev) because pci- | 4489 | /* Implement our own version of pci_save_state(pdev) because pci- |