]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/net/e100.c
[ZD1211RD]: add USB id for Telegent TG54USB WLAN adapter
[linux-2.6-omap-h63xx.git] / drivers / net / e100.c
index 61696637a21edcc0b646e1c8894c3b89f632dadd..7bd9604026873f89d7211838dc37388b211ca97e 100644 (file)
 
 #define DRV_NAME               "e100"
 #define DRV_EXT                        "-NAPI"
-#define DRV_VERSION            "3.5.17-k4"DRV_EXT
+#define DRV_VERSION            "3.5.23-k4"DRV_EXT
 #define DRV_DESCRIPTION                "Intel(R) PRO/100 Network Driver"
 #define DRV_COPYRIGHT          "Copyright(c) 1999-2006 Intel Corporation"
 #define PFX                    DRV_NAME ": "
@@ -285,6 +285,12 @@ enum scb_status {
        rus_mask         = 0x3C,
 };
 
+enum ru_state  {
+       RU_SUSPENDED = 0,
+       RU_RUNNING       = 1,
+       RU_UNINITIALIZED = -1,
+};
+
 enum scb_stat_ack {
        stat_ack_not_ours    = 0x00,
        stat_ack_sw_gen      = 0x04,
@@ -526,12 +532,14 @@ struct nic {
        struct rx *rx_to_use;
        struct rx *rx_to_clean;
        struct rfd blank_rfd;
+       enum ru_state ru_running;
 
        spinlock_t cb_lock                      ____cacheline_aligned;
        spinlock_t cmd_lock;
        struct csr __iomem *csr;
        enum scb_cmd_lo cuc_cmd;
        unsigned int cbs_avail;
+       struct napi_struct napi;
        struct cb *cbs;
        struct cb *cb_to_use;
        struct cb *cb_to_send;
@@ -550,7 +558,6 @@ struct nic {
        enum mac mac;
        enum phy phy;
        struct params params;
-       struct net_device_stats net_stats;
        struct timer_list watchdog;
        struct timer_list blink_timer;
        struct mii_if_info mii;
@@ -576,7 +583,6 @@ struct nic {
        u32 rx_tco_frames;
        u32 rx_over_length_errors;
 
-       u8 rev_id;
        u16 leds;
        u16 eeprom_wc;
        u16 eeprom[256];
@@ -930,9 +936,8 @@ static void e100_get_defaults(struct nic *nic)
        struct param_range rfds = { .min = 16, .max = 256, .count = 256 };
        struct param_range cbs  = { .min = 64, .max = 256, .count = 128 };
 
-       pci_read_config_byte(nic->pdev, PCI_REVISION_ID, &nic->rev_id);
        /* MAC type is encoded as rev ID; exception: ICH is treated as 82559 */
-       nic->mac = (nic->flags & ich) ? mac_82559_D101M : nic->rev_id;
+       nic->mac = (nic->flags & ich) ? mac_82559_D101M : nic->pdev->revision;
        if(nic->mac == mac_unknown)
                nic->mac = mac_82557_D100_A;
 
@@ -947,7 +952,7 @@ static void e100_get_defaults(struct nic *nic)
                ((nic->mac >= mac_82558_D101_A4) ? cb_cid : cb_i));
 
        /* Template for a freshly allocated RFD */
-       nic->blank_rfd.command = cpu_to_le16(cb_el & cb_s);
+       nic->blank_rfd.command = cpu_to_le16(cb_el);
        nic->blank_rfd.rbd = 0xFFFFFFFF;
        nic->blank_rfd.size = cpu_to_le16(VLAN_ETH_FRAME_LEN);
 
@@ -1017,10 +1022,16 @@ static void e100_configure(struct nic *nic, struct cb *cb, struct sk_buff *skb)
                config->mwi_enable = 0x1;       /* 1=enable, 0=disable */
                config->standard_tcb = 0x0;     /* 1=standard, 0=extended */
                config->rx_long_ok = 0x1;       /* 1=VLANs ok, 0=standard */
-               if(nic->mac >= mac_82559_D101M)
+               if (nic->mac >= mac_82559_D101M) {
                        config->tno_intr = 0x1;         /* TCO stats enable */
-               else
+                       /* Enable TCO in extended config */
+                       if (nic->mac >= mac_82551_10) {
+                               config->byte_count = 0x20; /* extended bytes */
+                               config->rx_d102_mode = 0x1; /* GMRC for TCO */
+                       }
+               } else {
                        config->standard_stat_counter = 0x0;
+               }
        }
 
        DPRINTK(HW, DEBUG, "[00-07]=%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X\n",
@@ -1266,7 +1277,7 @@ static void e100_setup_ucode(struct nic *nic, struct cb *cb, struct sk_buff *skb
        if (nic->flags & ich)
                goto noloaducode;
 
-       /* Search for ucode match against h/w rev_id */
+       /* Search for ucode match against h/w revision */
        for (opts = ucode_opts; opts->mac; opts++) {
                int i;
                u32 *ucode = opts->ucode;
@@ -1471,7 +1482,8 @@ static void e100_set_multicast_list(struct net_device *netdev)
 
 static void e100_update_stats(struct nic *nic)
 {
-       struct net_device_stats *ns = &nic->net_stats;
+       struct net_device *dev = nic->netdev;
+       struct net_device_stats *ns = &dev->stats;
        struct stats *s = &nic->mem->stats;
        u32 *complete = (nic->mac < mac_82558_D101_A4) ? &s->fc_xmt_pause :
                (nic->mac < mac_82559_D101M) ? (u32 *)&s->xmt_tco_frames :
@@ -1593,7 +1605,8 @@ static void e100_watchdog(unsigned long data)
        else
                nic->flags &= ~ich_10h_workaround;
 
-       mod_timer(&nic->watchdog, jiffies + E100_WATCHDOG_PERIOD);
+       mod_timer(&nic->watchdog,
+                 round_jiffies(jiffies + E100_WATCHDOG_PERIOD));
 }
 
 static void e100_xmit_prepare(struct nic *nic, struct cb *cb,
@@ -1648,6 +1661,7 @@ static int e100_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
 
 static int e100_tx_clean(struct nic *nic)
 {
+       struct net_device *dev = nic->netdev;
        struct cb *cb;
        int tx_cleaned = 0;
 
@@ -1662,8 +1676,8 @@ static int e100_tx_clean(struct nic *nic)
                        cb->status);
 
                if(likely(cb->skb != NULL)) {
-                       nic->net_stats.tx_packets++;
-                       nic->net_stats.tx_bytes += cb->skb->len;
+                       dev->stats.tx_packets++;
+                       dev->stats.tx_bytes += cb->skb->len;
 
                        pci_unmap_single(nic->pdev,
                                le32_to_cpu(cb->u.tcb.tbd.buf_addr),
@@ -1742,11 +1756,19 @@ static int e100_alloc_cbs(struct nic *nic)
        return 0;
 }
 
-static inline void e100_start_receiver(struct nic *nic)
+static inline void e100_start_receiver(struct nic *nic, struct rx *rx)
 {
-       /* Start if RFA is non-NULL */
-       if(nic->rx_to_clean->skb)
-               e100_exec_cmd(nic, ruc_start, nic->rx_to_clean->dma_addr);
+       if(!nic->rxs) return;
+       if(RU_SUSPENDED != nic->ru_running) return;
+
+       /* handle init time starts */
+       if(!rx) rx = nic->rxs;
+
+       /* (Re)start RU if suspended or idle and RFA is non-NULL */
+       if(rx->skb) {
+               e100_exec_cmd(nic, ruc_start, rx->dma_addr);
+               nic->ru_running = RU_RUNNING;
+       }
 }
 
 #define RFD_BUF_LEN (sizeof(struct rfd) + VLAN_ETH_FRAME_LEN)
@@ -1775,7 +1797,7 @@ static int e100_rx_alloc_skb(struct nic *nic, struct rx *rx)
                put_unaligned(cpu_to_le32(rx->dma_addr),
                        (u32 *)&prev_rfd->link);
                wmb();
-               prev_rfd->command &= ~cpu_to_le16(cb_el & cb_s);
+               prev_rfd->command &= ~cpu_to_le16(cb_el);
                pci_dma_sync_single_for_device(nic->pdev, rx->prev->dma_addr,
                        sizeof(struct rfd), PCI_DMA_TODEVICE);
        }
@@ -1786,6 +1808,7 @@ static int e100_rx_alloc_skb(struct nic *nic, struct rx *rx)
 static int e100_rx_indicate(struct nic *nic, struct rx *rx,
        unsigned int *work_done, unsigned int work_to_do)
 {
+       struct net_device *dev = nic->netdev;
        struct sk_buff *skb = rx->skb;
        struct rfd *rfd = (struct rfd *)skb->data;
        u16 rfd_status, actual_size;
@@ -1813,6 +1836,10 @@ static int e100_rx_indicate(struct nic *nic, struct rx *rx,
        pci_unmap_single(nic->pdev, rx->dma_addr,
                RFD_BUF_LEN, PCI_DMA_FROMDEVICE);
 
+       /* this allows for a fast restart without re-enabling interrupts */
+       if(le16_to_cpu(rfd->command) & cb_el)
+               nic->ru_running = RU_SUSPENDED;
+
        /* Pull off the RFD and put the actual data (minus eth hdr) */
        skb_reserve(skb, sizeof(struct rfd));
        skb_put(skb, actual_size);
@@ -1826,8 +1853,8 @@ static int e100_rx_indicate(struct nic *nic, struct rx *rx,
                nic->rx_over_length_errors++;
                dev_kfree_skb_any(skb);
        } else {
-               nic->net_stats.rx_packets++;
-               nic->net_stats.rx_bytes += actual_size;
+               dev->stats.rx_packets++;
+               dev->stats.rx_bytes += actual_size;
                nic->netdev->last_rx = jiffies;
                netif_receive_skb(skb);
                if(work_done)
@@ -1843,18 +1870,45 @@ static void e100_rx_clean(struct nic *nic, unsigned int *work_done,
        unsigned int work_to_do)
 {
        struct rx *rx;
+       int restart_required = 0;
+       struct rx *rx_to_start = NULL;
+
+       /* are we already rnr? then pay attention!!! this ensures that
+        * the state machine progression never allows a start with a
+        * partially cleaned list, avoiding a race between hardware
+        * and rx_to_clean when in NAPI mode */
+       if(RU_SUSPENDED == nic->ru_running)
+               restart_required = 1;
 
        /* Indicate newly arrived packets */
        for(rx = nic->rx_to_clean; rx->skb; rx = nic->rx_to_clean = rx->next) {
-               if(e100_rx_indicate(nic, rx, work_done, work_to_do))
+               int err = e100_rx_indicate(nic, rx, work_done, work_to_do);
+               if(-EAGAIN == err) {
+                       /* hit quota so have more work to do, restart once
+                        * cleanup is complete */
+                       restart_required = 0;
+                       break;
+               } else if(-ENODATA == err)
                        break; /* No more to clean */
        }
 
+       /* save our starting point as the place we'll restart the receiver */
+       if(restart_required)
+               rx_to_start = nic->rx_to_clean;
+
        /* Alloc new skbs to refill list */
        for(rx = nic->rx_to_use; !rx->skb; rx = nic->rx_to_use = rx->next) {
                if(unlikely(e100_rx_alloc_skb(nic, rx)))
                        break; /* Better luck next time (see watchdog) */
        }
+
+       if(restart_required) {
+               // ack the rnr?
+               writeb(stat_ack_rnr, &nic->csr->scb.stat_ack);
+               e100_start_receiver(nic, rx_to_start);
+               if(work_done)
+                       (*work_done)++;
+       }
 }
 
 static void e100_rx_clean_list(struct nic *nic)
@@ -1862,6 +1916,8 @@ static void e100_rx_clean_list(struct nic *nic)
        struct rx *rx;
        unsigned int i, count = nic->params.rfds.count;
 
+       nic->ru_running = RU_UNINITIALIZED;
+
        if(nic->rxs) {
                for(rx = nic->rxs, i = 0; i < count; rx++, i++) {
                        if(rx->skb) {
@@ -1883,6 +1939,7 @@ static int e100_rx_alloc_list(struct nic *nic)
        unsigned int i, count = nic->params.rfds.count;
 
        nic->rx_to_use = nic->rx_to_clean = NULL;
+       nic->ru_running = RU_UNINITIALIZED;
 
        if(!(nic->rxs = kcalloc(count, sizeof(struct rx), GFP_ATOMIC)))
                return -ENOMEM;
@@ -1897,6 +1954,7 @@ static int e100_rx_alloc_list(struct nic *nic)
        }
 
        nic->rx_to_use = nic->rx_to_clean = nic->rxs;
+       nic->ru_running = RU_SUSPENDED;
 
        return 0;
 }
@@ -1916,35 +1974,35 @@ static irqreturn_t e100_intr(int irq, void *dev_id)
        /* Ack interrupt(s) */
        iowrite8(stat_ack, &nic->csr->scb.stat_ack);
 
-       if(likely(netif_rx_schedule_prep(netdev))) {
+       /* We hit Receive No Resource (RNR); restart RU after cleaning */
+       if(stat_ack & stat_ack_rnr)
+               nic->ru_running = RU_SUSPENDED;
+
+       if(likely(netif_rx_schedule_prep(netdev, &nic->napi))) {
                e100_disable_irq(nic);
-               __netif_rx_schedule(netdev);
+               __netif_rx_schedule(netdev, &nic->napi);
        }
 
        return IRQ_HANDLED;
 }
 
-static int e100_poll(struct net_device *netdev, int *budget)
+static int e100_poll(struct napi_struct *napi, int budget)
 {
-       struct nic *nic = netdev_priv(netdev);
-       unsigned int work_to_do = min(netdev->quota, *budget);
-       unsigned int work_done = 0;
+       struct nic *nic = container_of(napi, struct nic, napi);
+       struct net_device *netdev = nic->netdev;
+       int work_done = 0;
        int tx_cleaned;
 
-       e100_rx_clean(nic, &work_done, work_to_do);
+       e100_rx_clean(nic, &work_done, budget);
        tx_cleaned = e100_tx_clean(nic);
 
        /* If no Rx and Tx cleanup work was done, exit polling mode. */
        if((!tx_cleaned && (work_done == 0)) || !netif_running(netdev)) {
-               netif_rx_complete(netdev);
+               netif_rx_complete(netdev, napi);
                e100_enable_irq(nic);
-               return 0;
        }
 
-       *budget -= work_done;
-       netdev->quota -= work_done;
-
-       return 1;
+       return work_done;
 }
 
 #ifdef CONFIG_NET_POLL_CONTROLLER
@@ -1959,12 +2017,6 @@ static void e100_netpoll(struct net_device *netdev)
 }
 #endif
 
-static struct net_device_stats *e100_get_stats(struct net_device *netdev)
-{
-       struct nic *nic = netdev_priv(netdev);
-       return &nic->net_stats;
-}
-
 static int e100_set_mac_address(struct net_device *netdev, void *p)
 {
        struct nic *nic = netdev_priv(netdev);
@@ -2007,13 +2059,13 @@ static int e100_up(struct nic *nic)
        if((err = e100_hw_init(nic)))
                goto err_clean_cbs;
        e100_set_multicast_list(nic->netdev);
-       e100_start_receiver(nic);
+       e100_start_receiver(nic, NULL);
        mod_timer(&nic->watchdog, jiffies);
        if((err = request_irq(nic->pdev->irq, e100_intr, IRQF_SHARED,
                nic->netdev->name, nic->netdev)))
                goto err_no_irq;
        netif_wake_queue(nic->netdev);
-       netif_poll_enable(nic->netdev);
+       napi_enable(&nic->napi);
        /* enable ints _after_ enabling poll, preventing a race between
         * disable ints+schedule */
        e100_enable_irq(nic);
@@ -2031,7 +2083,7 @@ err_rx_clean_list:
 static void e100_down(struct nic *nic)
 {
        /* wait here for poll to complete */
-       netif_poll_disable(nic->netdev);
+       napi_disable(&nic->napi);
        netif_stop_queue(nic->netdev);
        e100_hw_reset(nic);
        free_irq(nic->pdev->irq, nic->netdev);
@@ -2088,7 +2140,7 @@ static int e100_loopback_test(struct nic *nic, enum loopback loopback_mode)
                mdio_write(nic->netdev, nic->mii.phy_id, MII_BMCR,
                        BMCR_LOOPBACK);
 
-       e100_start_receiver(nic);
+       e100_start_receiver(nic, NULL);
 
        if(!(skb = netdev_alloc_skb(nic->netdev, ETH_DATA_LEN))) {
                err = -ENOMEM;
@@ -2178,7 +2230,7 @@ static void e100_get_regs(struct net_device *netdev,
        u32 *buff = p;
        int i;
 
-       regs->version = (1 << 24) | nic->rev_id;
+       regs->version = (1 << 24) | nic->pdev->revision;
        buff[0] = ioread8(&nic->csr->scb.cmd_hi) << 24 |
                ioread8(&nic->csr->scb.cmd_lo) << 16 |
                ioread16(&nic->csr->scb.status);
@@ -2322,11 +2374,6 @@ static const char e100_gstrings_test[][ETH_GSTRING_LEN] = {
 };
 #define E100_TEST_LEN  sizeof(e100_gstrings_test) / ETH_GSTRING_LEN
 
-static int e100_diag_test_count(struct net_device *netdev)
-{
-       return E100_TEST_LEN;
-}
-
 static void e100_diag_test(struct net_device *netdev,
        struct ethtool_test *test, u64 *data)
 {
@@ -2389,9 +2436,16 @@ static const char e100_gstrings_stats[][ETH_GSTRING_LEN] = {
 #define E100_NET_STATS_LEN     21
 #define E100_STATS_LEN sizeof(e100_gstrings_stats) / ETH_GSTRING_LEN
 
-static int e100_get_stats_count(struct net_device *netdev)
+static int e100_get_sset_count(struct net_device *netdev, int sset)
 {
-       return E100_STATS_LEN;
+       switch (sset) {
+       case ETH_SS_TEST:
+               return E100_TEST_LEN;
+       case ETH_SS_STATS:
+               return E100_STATS_LEN;
+       default:
+               return -EOPNOTSUPP;
+       }
 }
 
 static void e100_get_ethtool_stats(struct net_device *netdev,
@@ -2401,7 +2455,7 @@ static void e100_get_ethtool_stats(struct net_device *netdev,
        int i;
 
        for(i = 0; i < E100_NET_STATS_LEN; i++)
-               data[i] = ((unsigned long *)&nic->net_stats)[i];
+               data[i] = ((unsigned long *)&netdev->stats)[i];
 
        data[i++] = nic->tx_deferred;
        data[i++] = nic->tx_single_collisions;
@@ -2442,13 +2496,11 @@ static const struct ethtool_ops e100_ethtool_ops = {
        .set_eeprom             = e100_set_eeprom,
        .get_ringparam          = e100_get_ringparam,
        .set_ringparam          = e100_set_ringparam,
-       .self_test_count        = e100_diag_test_count,
        .self_test              = e100_diag_test,
        .get_strings            = e100_get_strings,
        .phys_id                = e100_phys_id,
-       .get_stats_count        = e100_get_stats_count,
        .get_ethtool_stats      = e100_get_ethtool_stats,
-       .get_perm_addr          = ethtool_op_get_perm_addr,
+       .get_sset_count         = e100_get_sset_count,
 };
 
 static int e100_do_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
@@ -2497,6 +2549,7 @@ static int __devinit e100_probe(struct pci_dev *pdev,
        struct net_device *netdev;
        struct nic *nic;
        int err;
+       DECLARE_MAC_BUF(mac);
 
        if(!(netdev = alloc_etherdev(sizeof(struct nic)))) {
                if(((1 << debug) - 1) & NETIF_MSG_PROBE)
@@ -2507,7 +2560,6 @@ static int __devinit e100_probe(struct pci_dev *pdev,
        netdev->open = e100_open;
        netdev->stop = e100_close;
        netdev->hard_start_xmit = e100_xmit_frame;
-       netdev->get_stats = e100_get_stats;
        netdev->set_multicast_list = e100_set_multicast_list;
        netdev->set_mac_address = e100_set_mac_address;
        netdev->change_mtu = e100_change_mtu;
@@ -2515,14 +2567,13 @@ static int __devinit e100_probe(struct pci_dev *pdev,
        SET_ETHTOOL_OPS(netdev, &e100_ethtool_ops);
        netdev->tx_timeout = e100_tx_timeout;
        netdev->watchdog_timeo = E100_WATCHDOG_PERIOD;
-       netdev->poll = e100_poll;
-       netdev->weight = E100_NAPI_WEIGHT;
 #ifdef CONFIG_NET_POLL_CONTROLLER
        netdev->poll_controller = e100_netpoll;
 #endif
        strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
 
        nic = netdev_priv(netdev);
+       netif_napi_add(netdev, &nic->napi, e100_poll, E100_NAPI_WEIGHT);
        nic->netdev = netdev;
        nic->pdev = pdev;
        nic->msg_enable = (1 << debug) - 1;
@@ -2550,7 +2601,6 @@ static int __devinit e100_probe(struct pci_dev *pdev,
                goto err_out_free_res;
        }
 
-       SET_MODULE_OWNER(netdev);
        SET_NETDEV_DEV(netdev, &pdev->dev);
 
        if (use_io)
@@ -2631,11 +2681,9 @@ static int __devinit e100_probe(struct pci_dev *pdev,
                goto err_out_free;
        }
 
-       DPRINTK(PROBE, INFO, "addr 0x%llx, irq %d, "
-               "MAC addr %02X:%02X:%02X:%02X:%02X:%02X\n",
-               (unsigned long long)pci_resource_start(pdev, use_io ? 1 : 0), pdev->irq,
-               netdev->dev_addr[0], netdev->dev_addr[1], netdev->dev_addr[2],
-               netdev->dev_addr[3], netdev->dev_addr[4], netdev->dev_addr[5]);
+       DPRINTK(PROBE, INFO, "addr 0x%llx, irq %d, MAC addr %s\n",
+               (unsigned long long)pci_resource_start(pdev, use_io ? 1 : 0),
+               pdev->irq, print_mac(mac, netdev->dev_addr));
 
        return 0;
 
@@ -2676,7 +2724,7 @@ static int e100_suspend(struct pci_dev *pdev, pm_message_t state)
        struct nic *nic = netdev_priv(netdev);
 
        if (netif_running(netdev))
-               netif_poll_disable(nic->netdev);
+               napi_disable(&nic->napi);
        del_timer_sync(&nic->watchdog);
        netif_carrier_off(nic->netdev);
        netif_device_detach(netdev);
@@ -2722,7 +2770,7 @@ static void e100_shutdown(struct pci_dev *pdev)
        struct nic *nic = netdev_priv(netdev);
 
        if (netif_running(netdev))
-               netif_poll_disable(nic->netdev);
+               napi_disable(&nic->napi);
        del_timer_sync(&nic->watchdog);
        netif_carrier_off(nic->netdev);
 
@@ -2747,12 +2795,13 @@ static void e100_shutdown(struct pci_dev *pdev)
 static pci_ers_result_t e100_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
 {
        struct net_device *netdev = pci_get_drvdata(pdev);
+       struct nic *nic = netdev_priv(netdev);
 
        /* Similar to calling e100_down(), but avoids adpater I/O. */
        netdev->stop(netdev);
 
        /* Detach; put netif into state similar to hotplug unplug. */
-       netif_poll_enable(netdev);
+       napi_enable(&nic->napi);
        netif_device_detach(netdev);
        pci_disable_device(pdev);