Merge master.kernel.org:/home/rmk/linux-2.6-arm
[safe/jmp/linux-2.6] / drivers / net / e1000 / e1000_main.c
index 4d6677e..bcd192c 100644 (file)
@@ -1098,6 +1098,11 @@ static void __devexit e1000_remove(struct pci_dev *pdev)
        struct e1000_adapter *adapter = netdev_priv(netdev);
        struct e1000_hw *hw = &adapter->hw;
 
+       set_bit(__E1000_DOWN, &adapter->flags);
+       del_timer_sync(&adapter->tx_fifo_stall_timer);
+       del_timer_sync(&adapter->watchdog_timer);
+       del_timer_sync(&adapter->phy_info_timer);
+
        cancel_work_sync(&adapter->reset_task);
 
        e1000_release_manageability(adapter);
@@ -2240,12 +2245,46 @@ static void e1000_82547_tx_fifo_stall(unsigned long data)
                        adapter->tx_fifo_head = 0;
                        atomic_set(&adapter->tx_fifo_stall, 0);
                        netif_wake_queue(netdev);
-               } else {
+               } else if (!test_bit(__E1000_DOWN, &adapter->flags)) {
                        mod_timer(&adapter->tx_fifo_stall_timer, jiffies + 1);
                }
        }
 }
 
+static bool e1000_has_link(struct e1000_adapter *adapter)
+{
+       struct e1000_hw *hw = &adapter->hw;
+       bool link_active = false;
+
+       /* get_link_status is set on LSC (link status) interrupt or
+        * rx sequence error interrupt.  get_link_status will stay
+        * false until the e1000_check_for_link establishes link
+        * for copper adapters ONLY
+        */
+       switch (hw->media_type) {
+       case e1000_media_type_copper:
+               if (hw->get_link_status) {
+                       e1000_check_for_link(hw);
+                       link_active = !hw->get_link_status;
+               } else {
+                       link_active = true;
+               }
+               break;
+       case e1000_media_type_fiber:
+               e1000_check_for_link(hw);
+               link_active = !!(er32(STATUS) & E1000_STATUS_LU);
+               break;
+       case e1000_media_type_internal_serdes:
+               e1000_check_for_link(hw);
+               link_active = hw->serdes_has_link;
+               break;
+       default:
+               break;
+       }
+
+       return link_active;
+}
+
 /**
  * e1000_watchdog - Timer Call-back
  * @data: pointer to adapter cast into an unsigned long
@@ -2258,18 +2297,15 @@ static void e1000_watchdog(unsigned long data)
        struct e1000_tx_ring *txdr = adapter->tx_ring;
        u32 link, tctl;
 
-       e1000_check_for_link(hw);
-
-       if ((hw->media_type == e1000_media_type_internal_serdes) &&
-          !(er32(TXCW) & E1000_TXCW_ANE))
-               link = !hw->serdes_link_down;
-       else
-               link = er32(STATUS) & E1000_STATUS_LU;
+       link = e1000_has_link(adapter);
+       if ((netif_carrier_ok(netdev)) && link)
+               goto link_up;
 
        if (link) {
                if (!netif_carrier_ok(netdev)) {
                        u32 ctrl;
                        bool txb2b = true;
+                       /* update snapshot of PHY registers on LSC */
                        e1000_get_speed_and_duplex(hw,
                                                   &adapter->link_speed,
                                                   &adapter->link_duplex);
@@ -2294,7 +2330,7 @@ static void e1000_watchdog(unsigned long data)
                        case SPEED_10:
                                txb2b = false;
                                netdev->tx_queue_len = 10;
-                               adapter->tx_timeout_factor = 8;
+                               adapter->tx_timeout_factor = 16;
                                break;
                        case SPEED_100:
                                txb2b = false;
@@ -2309,8 +2345,9 @@ static void e1000_watchdog(unsigned long data)
                        ew32(TCTL, tctl);
 
                        netif_carrier_on(netdev);
-                       mod_timer(&adapter->phy_info_timer,
-                                 round_jiffies(jiffies + 2 * HZ));
+                       if (!test_bit(__E1000_DOWN, &adapter->flags))
+                               mod_timer(&adapter->phy_info_timer,
+                                         round_jiffies(jiffies + 2 * HZ));
                        adapter->smartspeed = 0;
                }
        } else {
@@ -2320,13 +2357,16 @@ static void e1000_watchdog(unsigned long data)
                        printk(KERN_INFO "e1000: %s NIC Link is Down\n",
                               netdev->name);
                        netif_carrier_off(netdev);
-                       mod_timer(&adapter->phy_info_timer,
-                                 round_jiffies(jiffies + 2 * HZ));
+
+                       if (!test_bit(__E1000_DOWN, &adapter->flags))
+                               mod_timer(&adapter->phy_info_timer,
+                                         round_jiffies(jiffies + 2 * HZ));
                }
 
                e1000_smartspeed(adapter);
        }
 
+link_up:
        e1000_update_stats(adapter);
 
        hw->tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
@@ -2361,7 +2401,9 @@ static void e1000_watchdog(unsigned long data)
        adapter->detect_tx_hung = true;
 
        /* Reset the timer */
-       mod_timer(&adapter->watchdog_timer, round_jiffies(jiffies + 2 * HZ));
+       if (!test_bit(__E1000_DOWN, &adapter->flags))
+               mod_timer(&adapter->watchdog_timer,
+                         round_jiffies(jiffies + 2 * HZ));
 }
 
 enum latency_range {
@@ -2373,6 +2415,11 @@ enum latency_range {
 
 /**
  * e1000_update_itr - update the dynamic ITR value based on statistics
+ * @adapter: pointer to adapter
+ * @itr_setting: current adapter->itr
+ * @packets: the number of packets during this measurement interval
+ * @bytes: the number of bytes during this measurement interval
+ *
  *      Stores a new ITR value based on packets and byte
  *      counts during the last interrupt.  The advantage of per interrupt
  *      computation is faster updates and more accurate ITR for the current
@@ -2382,10 +2429,6 @@ enum latency_range {
  *      while increasing bulk throughput.
  *      this functionality is controlled by the InterruptThrottleRate module
  *      parameter (see e1000_param.c)
- * @adapter: pointer to adapter
- * @itr_setting: current adapter->itr
- * @packets: the number of packets during this measurement interval
- * @bytes: the number of bytes during this measurement interval
  **/
 static unsigned int e1000_update_itr(struct e1000_adapter *adapter,
                                     u16 itr_setting, int packets, int bytes)
@@ -2690,8 +2733,9 @@ static int e1000_tx_map(struct e1000_adapter *adapter,
                        size -= 4;
 
                buffer_info->length = size;
-               buffer_info->dma = skb_shinfo(skb)->dma_head + offset;
+               /* set time_stamp *before* dma to help avoid a possible race */
                buffer_info->time_stamp = jiffies;
+               buffer_info->dma = skb_shinfo(skb)->dma_head + offset;
                buffer_info->next_to_watch = i;
 
                len -= size;
@@ -2726,13 +2770,14 @@ static int e1000_tx_map(struct e1000_adapter *adapter,
                         * Avoid terminating buffers within evenly-aligned
                         * dwords. */
                        if (unlikely(adapter->pcix_82544 &&
-                          !((unsigned long)(frag->page+offset+size-1) & 4) &&
-                          size > 4))
+                           !((unsigned long)(page_to_phys(frag->page) + offset
+                                             + size - 1) & 4) &&
+                           size > 4))
                                size -= 4;
 
                        buffer_info->length = size;
-                       buffer_info->dma = map[f] + offset;
                        buffer_info->time_stamp = jiffies;
+                       buffer_info->dma = map[f] + offset;
                        buffer_info->next_to_watch = i;
 
                        len -= size;
@@ -2977,7 +3022,9 @@ static netdev_tx_t e1000_xmit_frame(struct sk_buff *skb,
        if (unlikely(hw->mac_type == e1000_82547)) {
                if (unlikely(e1000_82547_fifo_workaround(adapter, skb))) {
                        netif_stop_queue(netdev);
-                       mod_timer(&adapter->tx_fifo_stall_timer, jiffies + 1);
+                       if (!test_bit(__E1000_DOWN, &adapter->flags))
+                               mod_timer(&adapter->tx_fifo_stall_timer,
+                                         jiffies + 1);
                        return NETDEV_TX_BUSY;
                }
        }
@@ -2996,7 +3043,8 @@ static netdev_tx_t e1000_xmit_frame(struct sk_buff *skb,
        }
 
        if (likely(tso)) {
-               tx_ring->last_tx_tso = 1;
+               if (likely(hw->mac_type != e1000_82544))
+                       tx_ring->last_tx_tso = 1;
                tx_flags |= E1000_TX_FLAGS_TSO;
        } else if (likely(e1000_tx_csum(adapter, tx_ring, skb)))
                tx_flags |= E1000_TX_FLAGS_CSUM;
@@ -3092,6 +3140,13 @@ static int e1000_change_mtu(struct net_device *netdev, int new_mtu)
                break;
        }
 
+       while (test_and_set_bit(__E1000_RESETTING, &adapter->flags))
+               msleep(1);
+       /* e1000_down has a dependency on max_frame_size */
+       hw->max_frame_size = max_frame;
+       if (netif_running(netdev))
+               e1000_down(adapter);
+
        /* NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
         * means we reserve 2 more, this pushes us to allocate from the next
         * larger slab size.
@@ -3120,11 +3175,16 @@ static int e1000_change_mtu(struct net_device *netdev, int new_mtu)
             (max_frame == MAXIMUM_ETHERNET_VLAN_SIZE)))
                adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE;
 
+       printk(KERN_INFO "e1000: %s changing MTU from %d to %d\n",
+              netdev->name, netdev->mtu, new_mtu);
        netdev->mtu = new_mtu;
-       hw->max_frame_size = max_frame;
 
        if (netif_running(netdev))
-               e1000_reinit_locked(adapter);
+               e1000_up(adapter);
+       else
+               e1000_reset(adapter);
+
+       clear_bit(__E1000_RESETTING, &adapter->flags);
 
        return 0;
 }
@@ -3333,17 +3393,13 @@ static irqreturn_t e1000_intr(int irq, void *data)
 static int e1000_clean(struct napi_struct *napi, int budget)
 {
        struct e1000_adapter *adapter = container_of(napi, struct e1000_adapter, napi);
-       struct net_device *poll_dev = adapter->netdev;
-       int tx_cleaned = 0, work_done = 0;
-
-       adapter = netdev_priv(poll_dev);
+       int tx_clean_complete = 0, work_done = 0;
 
-       tx_cleaned = e1000_clean_tx_irq(adapter, &adapter->tx_ring[0]);
+       tx_clean_complete = e1000_clean_tx_irq(adapter, &adapter->tx_ring[0]);
 
-       adapter->clean_rx(adapter, &adapter->rx_ring[0],
-                         &work_done, budget);
+       adapter->clean_rx(adapter, &adapter->rx_ring[0], &work_done, budget);
 
-       if (!tx_cleaned)
+       if (!tx_clean_complete)
                work_done = budget;
 
        /* If budget not fully consumed, exit the polling mode */
@@ -3414,7 +3470,9 @@ static bool e1000_clean_tx_irq(struct e1000_adapter *adapter,
                 * sees the new next_to_clean.
                 */
                smp_mb();
-               if (netif_queue_stopped(netdev)) {
+
+               if (netif_queue_stopped(netdev) &&
+                   !(test_bit(__E1000_DOWN, &adapter->flags))) {
                        netif_wake_queue(netdev);
                        ++adapter->restart_queue;
                }
@@ -3424,8 +3482,8 @@ static bool e1000_clean_tx_irq(struct e1000_adapter *adapter,
                /* Detect a transmit hang in hardware, this serializes the
                 * check with the clearing of time_stamp and movement of i */
                adapter->detect_tx_hung = false;
-               if (tx_ring->buffer_info[i].time_stamp &&
-                   time_after(jiffies, tx_ring->buffer_info[i].time_stamp +
+               if (tx_ring->buffer_info[eop].time_stamp &&
+                   time_after(jiffies, tx_ring->buffer_info[eop].time_stamp +
                               (adapter->tx_timeout_factor * HZ))
                    && !(er32(STATUS) & E1000_STATUS_TXOFF)) {
 
@@ -3447,7 +3505,7 @@ static bool e1000_clean_tx_irq(struct e1000_adapter *adapter,
                                readl(hw->hw_addr + tx_ring->tdt),
                                tx_ring->next_to_use,
                                tx_ring->next_to_clean,
-                               tx_ring->buffer_info[i].time_stamp,
+                               tx_ring->buffer_info[eop].time_stamp,
                                eop,
                                jiffies,
                                eop_desc->upper.fields.status);
@@ -4291,20 +4349,6 @@ void e1000_pcix_set_mmrbc(struct e1000_hw *hw, int mmrbc)
        pcix_set_mmrbc(adapter->pdev, mmrbc);
 }
 
-s32 e1000_read_pcie_cap_reg(struct e1000_hw *hw, u32 reg, u16 *value)
-{
-    struct e1000_adapter *adapter = hw->back;
-    u16 cap_offset;
-
-    cap_offset = pci_find_capability(adapter->pdev, PCI_CAP_ID_EXP);
-    if (!cap_offset)
-        return -E1000_ERR_CONFIG;
-
-    pci_read_config_word(adapter->pdev, cap_offset + reg, value);
-
-    return E1000_SUCCESS;
-}
-
 void e1000_io_write(struct e1000_hw *hw, unsigned long port, u32 value)
 {
        outl(value, port);
@@ -4346,8 +4390,7 @@ static void e1000_vlan_rx_register(struct net_device *netdev,
                ew32(RCTL, rctl);
 
                if (adapter->mng_vlan_id != (u16)E1000_MNG_VLAN_NONE) {
-                       e1000_vlan_rx_kill_vid(netdev,
-                                              adapter->mng_vlan_id);
+                       e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
                        adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
                }
        }
@@ -4620,7 +4663,7 @@ static void e1000_netpoll(struct net_device *netdev)
 /**
  * e1000_io_error_detected - called when PCI error is detected
  * @pdev: Pointer to PCI device
- * @state: The current pci conneection state
+ * @state: The current pci connection state
  *
  * This function is called after a PCI bus error affecting
  * this device has been detected.