Stop phy code from returning success to unknown ioctls.
[safe/jmp/linux-2.6] / drivers / net / typhoon.c
index 8ddea1d..94ac586 100644 (file)
@@ -117,6 +117,7 @@ static const int multicast_filter_limit = 32;
 #include <linux/netdevice.h>
 #include <linux/etherdevice.h>
 #include <linux/skbuff.h>
+#include <linux/mm.h>
 #include <linux/init.h>
 #include <linux/delay.h>
 #include <linux/ethtool.h>
@@ -283,6 +284,7 @@ struct typhoon {
        struct basic_ring       rxLoRing;
        struct pci_dev *        pdev;
        struct net_device *     dev;
+       struct napi_struct      napi;
        spinlock_t              state_lock;
        struct vlan_group *     vlgrp;
        struct basic_ring       rxHiRing;
@@ -298,9 +300,9 @@ struct typhoon {
        const char *            name;
        struct typhoon_shared * shared;
        dma_addr_t              shared_dma;
-       u16                     xcvr_select;
-       u16                     wol_events;
-       u32                     offload;
+       __le16                  xcvr_select;
+       __le16                  wol_events;
+       __le32                  offload;
 
        /* unused stuff (future use) */
        int                     capabilities;
@@ -638,7 +640,7 @@ typhoon_issue_command(struct typhoon *tp, int num_cmd, struct cmd_desc *cmd,
 
        typhoon_inc_cmd_index(&ring->lastWrite, num_cmd);
 
-       /* "I feel a presence... another warrior is on the the mesa."
+       /* "I feel a presence... another warrior is on the mesa."
         */
        wmb();
        iowrite32(ring->lastWrite, tp->ioaddr + TYPHOON_REG_CMD_READY);
@@ -740,16 +742,6 @@ typhoon_vlan_rx_register(struct net_device *dev, struct vlan_group *grp)
        spin_unlock_bh(&tp->state_lock);
 }
 
-static void
-typhoon_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
-{
-       struct typhoon *tp = netdev_priv(dev);
-       spin_lock_bh(&tp->state_lock);
-       if(tp->vlgrp)
-               tp->vlgrp->vlan_devices[vid] = NULL;
-       spin_unlock_bh(&tp->state_lock);
-}
-
 static inline void
 typhoon_tso_fill(struct sk_buff *skb, struct transmit_ring *txRing,
                        u32 ring_dma)
@@ -836,7 +828,7 @@ typhoon_start_tx(struct sk_buff *skb, struct net_device *dev)
                first_txd->processFlags |=
                    TYPHOON_TX_PF_INSERT_VLAN | TYPHOON_TX_PF_VLAN_PRIORITY;
                first_txd->processFlags |=
-                   cpu_to_le32(htons(vlan_tx_tag_get(skb)) <<
+                   cpu_to_le32(ntohs(vlan_tx_tag_get(skb)) <<
                                TYPHOON_TX_PF_VLAN_TAG_SHIFT);
        }
 
@@ -928,7 +920,7 @@ typhoon_set_rx_mode(struct net_device *dev)
        struct typhoon *tp = netdev_priv(dev);
        struct cmd_desc xp_cmd;
        u32 mc_filter[2];
-       u16 filter;
+       __le16 filter;
 
        filter = TYPHOON_RX_FILTER_DIRECTED | TYPHOON_RX_FILTER_BROADCAST;
        if(dev->flags & IFF_PROMISC) {
@@ -1139,7 +1131,7 @@ typhoon_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
 {
        struct typhoon *tp = netdev_priv(dev);
        struct cmd_desc xp_cmd;
-       int xcvr;
+       __le16 xcvr;
        int err;
 
        err = -EINVAL;
@@ -1244,11 +1236,8 @@ static const struct ethtool_ops typhoon_ethtool_ops = {
        .set_wol                = typhoon_set_wol,
        .get_link               = ethtool_op_get_link,
        .get_rx_csum            = typhoon_get_rx_csum,
-       .get_tx_csum            = ethtool_op_get_tx_csum,
        .set_tx_csum            = ethtool_op_set_tx_csum,
-       .get_sg                 = ethtool_op_get_sg,
        .set_sg                 = ethtool_op_set_sg,
-       .get_tso                = ethtool_op_get_tso,
        .set_tso                = ethtool_op_set_tso,
        .get_ringparam          = typhoon_get_ringparam,
 };
@@ -1547,7 +1536,7 @@ out_timeout:
 
 static u32
 typhoon_clean_tx(struct typhoon *tp, struct transmit_ring *txRing,
-                       volatile u32 * index)
+                       volatile __le32 * index)
 {
        u32 lastRead = txRing->lastRead;
        struct tx_desc *tx;
@@ -1583,7 +1572,7 @@ typhoon_clean_tx(struct typhoon *tp, struct transmit_ring *txRing,
 
 static void
 typhoon_tx_complete(struct typhoon *tp, struct transmit_ring *txRing,
-                       volatile u32 * index)
+                       volatile __le32 * index)
 {
        u32 lastRead;
        int numDesc = MAX_SKB_FRAGS + 1;
@@ -1673,8 +1662,8 @@ typhoon_alloc_rx_skb(struct typhoon *tp, u32 idx)
 }
 
 static int
-typhoon_rx(struct typhoon *tp, struct basic_ring *rxRing, volatile u32 * ready,
-          volatile u32 * cleared, int budget)
+typhoon_rx(struct typhoon *tp, struct basic_ring *rxRing, volatile __le32 * ready,
+          volatile __le32 * cleared, int budget)
 {
        struct rx_desc *rx;
        struct sk_buff *skb, *new_skb;
@@ -1684,7 +1673,7 @@ typhoon_rx(struct typhoon *tp, struct basic_ring *rxRing, volatile u32 * ready,
        u32 rxaddr;
        int pkt_len;
        u32 idx;
-       u32 csum_bits;
+       __le32 csum_bits;
        int received;
 
        received = 0;
@@ -1708,12 +1697,11 @@ typhoon_rx(struct typhoon *tp, struct basic_ring *rxRing, volatile u32 * ready,
 
                if(pkt_len < rx_copybreak &&
                   (new_skb = dev_alloc_skb(pkt_len + 2)) != NULL) {
-                       new_skb->dev = tp->dev;
                        skb_reserve(new_skb, 2);
                        pci_dma_sync_single_for_cpu(tp->pdev, dma_addr,
                                                    PKT_BUF_SZ,
                                                    PCI_DMA_FROMDEVICE);
-                       eth_copy_and_sum(new_skb, skb->data, pkt_len, 0);
+                       skb_copy_to_linear_data(new_skb, skb->data, pkt_len);
                        pci_dma_sync_single_for_device(tp->pdev, dma_addr,
                                                       PKT_BUF_SZ,
                                                       PCI_DMA_FROMDEVICE);
@@ -1769,12 +1757,12 @@ typhoon_fill_free_ring(struct typhoon *tp)
 }
 
 static int
-typhoon_poll(struct net_device *dev, int *total_budget)
+typhoon_poll(struct napi_struct *napi, int budget)
 {
-       struct typhoon *tp = netdev_priv(dev);
+       struct typhoon *tp = container_of(napi, struct typhoon, napi);
+       struct net_device *dev = tp->dev;
        struct typhoon_indexes *indexes = tp->indexes;
-       int orig_budget = *total_budget;
-       int budget, work_done, done;
+       int work_done;
 
        rmb();
        if(!tp->awaiting_resp && indexes->respReady != indexes->respCleared)
@@ -1783,30 +1771,16 @@ typhoon_poll(struct net_device *dev, int *total_budget)
        if(le32_to_cpu(indexes->txLoCleared) != tp->txLoRing.lastRead)
                typhoon_tx_complete(tp, &tp->txLoRing, &indexes->txLoCleared);
 
-       if(orig_budget > dev->quota)
-               orig_budget = dev->quota;
-
-       budget = orig_budget;
        work_done = 0;
-       done = 1;
 
        if(indexes->rxHiCleared != indexes->rxHiReady) {
-               work_done = typhoon_rx(tp, &tp->rxHiRing, &indexes->rxHiReady,
+               work_done += typhoon_rx(tp, &tp->rxHiRing, &indexes->rxHiReady,
                                        &indexes->rxHiCleared, budget);
-               budget -= work_done;
        }
 
        if(indexes->rxLoCleared != indexes->rxLoReady) {
                work_done += typhoon_rx(tp, &tp->rxLoRing, &indexes->rxLoReady,
-                                       &indexes->rxLoCleared, budget);
-       }
-
-       if(work_done) {
-               *total_budget -= work_done;
-               dev->quota -= work_done;
-
-               if(work_done >= orig_budget)
-                       done = 0;
+                                       &indexes->rxLoCleared, budget - work_done);
        }
 
        if(le32_to_cpu(indexes->rxBuffCleared) == tp->rxBuffRing.lastWrite) {
@@ -1814,20 +1788,20 @@ typhoon_poll(struct net_device *dev, int *total_budget)
                typhoon_fill_free_ring(tp);
        }
 
-       if(done) {
-               netif_rx_complete(dev);
+       if (work_done < budget) {
+               netif_rx_complete(dev, napi);
                iowrite32(TYPHOON_INTR_NONE,
                                tp->ioaddr + TYPHOON_REG_INTR_MASK);
                typhoon_post_pci_writes(tp->ioaddr);
        }
 
-       return (done ? 0 : 1);
+       return work_done;
 }
 
 static irqreturn_t
 typhoon_interrupt(int irq, void *dev_instance)
 {
-       struct net_device *dev = (struct net_device *) dev_instance;
+       struct net_device *dev = dev_instance;
        struct typhoon *tp = dev->priv;
        void __iomem *ioaddr = tp->ioaddr;
        u32 intr_status;
@@ -1838,10 +1812,10 @@ typhoon_interrupt(int irq, void *dev_instance)
 
        iowrite32(intr_status, ioaddr + TYPHOON_REG_INTR_STATUS);
 
-       if(netif_rx_schedule_prep(dev)) {
+       if (netif_rx_schedule_prep(dev, &tp->napi)) {
                iowrite32(TYPHOON_INTR_ALL, ioaddr + TYPHOON_REG_INTR_MASK);
                typhoon_post_pci_writes(ioaddr);
-               __netif_rx_schedule(dev);
+               __netif_rx_schedule(dev, &tp->napi);
        } else {
                printk(KERN_ERR "%s: Error, poll already scheduled\n",
                        dev->name);
@@ -1866,7 +1840,7 @@ typhoon_free_rx_rings(struct typhoon *tp)
 }
 
 static int
-typhoon_sleep(struct typhoon *tp, pci_power_t state, u16 events)
+typhoon_sleep(struct typhoon *tp, pci_power_t state, __le16 events)
 {
        struct pci_dev *pdev = tp->pdev;
        void __iomem *ioaddr = tp->ioaddr;
@@ -1954,8 +1928,8 @@ typhoon_start_runtime(struct typhoon *tp)
                goto error_out;
 
        INIT_COMMAND_NO_RESPONSE(&xp_cmd, TYPHOON_CMD_SET_MAC_ADDRESS);
-       xp_cmd.parm1 = cpu_to_le16(ntohs(*(u16 *)&dev->dev_addr[0]));
-       xp_cmd.parm2 = cpu_to_le32(ntohl(*(u32 *)&dev->dev_addr[2]));
+       xp_cmd.parm1 = cpu_to_le16(ntohs(*(__be16 *)&dev->dev_addr[0]));
+       xp_cmd.parm2 = cpu_to_le32(ntohl(*(__be32 *)&dev->dev_addr[2]));
        err = typhoon_issue_command(tp, 1, &xp_cmd, 0, NULL);
        if(err < 0)
                goto error_out;
@@ -2129,9 +2103,13 @@ typhoon_open(struct net_device *dev)
        if(err < 0)
                goto out_sleep;
 
+       napi_enable(&tp->napi);
+
        err = typhoon_start_runtime(tp);
-       if(err < 0)
+       if(err < 0) {
+               napi_disable(&tp->napi);
                goto out_irq;
+       }
 
        netif_start_queue(dev);
        return 0;
@@ -2160,6 +2138,7 @@ typhoon_close(struct net_device *dev)
        struct typhoon *tp = netdev_priv(dev);
 
        netif_stop_queue(dev);
+       napi_disable(&tp->napi);
 
        if(typhoon_stop_runtime(tp, WaitSleep) < 0)
                printk(KERN_ERR "%s: unable to stop runtime\n", dev->name);
@@ -2250,8 +2229,8 @@ typhoon_suspend(struct pci_dev *pdev, pm_message_t state)
        }
 
        INIT_COMMAND_NO_RESPONSE(&xp_cmd, TYPHOON_CMD_SET_MAC_ADDRESS);
-       xp_cmd.parm1 = cpu_to_le16(ntohs(*(u16 *)&dev->dev_addr[0]));
-       xp_cmd.parm2 = cpu_to_le32(ntohl(*(u32 *)&dev->dev_addr[2]));
+       xp_cmd.parm1 = cpu_to_le16(ntohs(*(__be16 *)&dev->dev_addr[0]));
+       xp_cmd.parm2 = cpu_to_le32(ntohl(*(__be32 *)&dev->dev_addr[2]));
        if(typhoon_issue_command(tp, 1, &xp_cmd, 0, NULL) < 0) {
                printk(KERN_ERR "%s: unable to set mac address in suspend\n",
                                dev->name);
@@ -2277,12 +2256,6 @@ need_resume:
        typhoon_resume(pdev);
        return -EBUSY;
 }
-
-static int
-typhoon_enable_wake(struct pci_dev *pdev, pci_power_t state, int enable)
-{
-       return pci_enable_wake(pdev, state, enable);
-}
 #endif
 
 static int __devinit
@@ -2343,8 +2316,8 @@ typhoon_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
        dma_addr_t shared_dma;
        struct cmd_desc xp_cmd;
        struct resp_desc xp_resp[3];
-       int i;
        int err = 0;
+       DECLARE_MAC_BUF(mac);
 
        if(!did_version++)
                printk(KERN_INFO "%s", version);
@@ -2356,7 +2329,6 @@ typhoon_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
                err = -ENOMEM;
                goto error_out;
        }
-       SET_MODULE_OWNER(dev);
        SET_NETDEV_DEV(dev, &pdev->dev);
 
        err = pci_enable_device(pdev);
@@ -2493,8 +2465,8 @@ typhoon_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
                goto error_out_reset;
        }
 
-       *(u16 *)&dev->dev_addr[0] = htons(le16_to_cpu(xp_resp[0].parm1));
-       *(u32 *)&dev->dev_addr[2] = htonl(le32_to_cpu(xp_resp[0].parm2));
+       *(__be16 *)&dev->dev_addr[0] = htons(le16_to_cpu(xp_resp[0].parm1));
+       *(__be32 *)&dev->dev_addr[2] = htonl(le32_to_cpu(xp_resp[0].parm2));
 
        if(!is_valid_ether_addr(dev->dev_addr)) {
                printk(ERR_PFX "%s: Could not obtain valid ethernet address, "
@@ -2537,13 +2509,12 @@ typhoon_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
        dev->stop               = typhoon_close;
        dev->set_multicast_list = typhoon_set_rx_mode;
        dev->tx_timeout         = typhoon_tx_timeout;
-       dev->poll               = typhoon_poll;
-       dev->weight             = 16;
+       netif_napi_add(dev, &tp->napi, typhoon_poll, 16);
        dev->watchdog_timeo     = TX_TIMEOUT;
        dev->get_stats          = typhoon_get_stats;
        dev->set_mac_address    = typhoon_set_mac_address;
        dev->vlan_rx_register   = typhoon_vlan_rx_register;
-       dev->vlan_rx_kill_vid   = typhoon_vlan_rx_kill_vid;
+
        SET_ETHTOOL_OPS(dev, &typhoon_ethtool_ops);
 
        /* We can handle scatter gather, up to 16 entries, and
@@ -2561,13 +2532,11 @@ typhoon_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 
        pci_set_drvdata(pdev, dev);
 
-       printk(KERN_INFO "%s: %s at %s 0x%llx, ",
+       printk(KERN_INFO "%s: %s at %s 0x%llx, %s\n",
               dev->name, typhoon_card_info[card_id].name,
               use_mmio ? "MMIO" : "IO",
-              (unsigned long long)pci_resource_start(pdev, use_mmio));
-       for(i = 0; i < 5; i++)
-               printk("%2.2x:", dev->dev_addr[i]);
-       printk("%2.2x\n", dev->dev_addr[i]);
+              (unsigned long long)pci_resource_start(pdev, use_mmio),
+              print_mac(mac, dev->dev_addr));
 
        /* xp_resp still contains the response to the READ_VERSIONS command.
         * For debugging, let the user know what version he has.
@@ -2646,7 +2615,6 @@ static struct pci_driver typhoon_driver = {
 #ifdef CONFIG_PM
        .suspend        = typhoon_suspend,
        .resume         = typhoon_resume,
-       .enable_wake    = typhoon_enable_wake,
 #endif
 };