vserver 1.9.5.x5
[linux-2.6.git] / drivers / net / acenic.c
index cc56ca3..6eea3a8 100644 (file)
@@ -427,14 +427,13 @@ MODULE_AUTHOR("Jes Sorensen <jes@trained-monkey.org>");
 MODULE_LICENSE("GPL");
 MODULE_DESCRIPTION("AceNIC/3C985/GA620 Gigabit Ethernet driver");
 
-static int num_params;
-module_param_array(link, int, num_params, 0);
-module_param_array(trace, int, num_params, 0);
-module_param_array(tx_coal_tick, int, num_params, 0);
-module_param_array(max_tx_desc, int, num_params, 0);
-module_param_array(rx_coal_tick, int, num_params, 0);
-module_param_array(max_rx_desc, int, num_params, 0);
-module_param_array(tx_ratio, int, num_params, 0);
+module_param_array(link, int, NULL, 0);
+module_param_array(trace, int, NULL, 0);
+module_param_array(tx_coal_tick, int, NULL, 0);
+module_param_array(max_tx_desc, int, NULL, 0);
+module_param_array(rx_coal_tick, int, NULL, 0);
+module_param_array(max_rx_desc, int, NULL, 0);
+module_param_array(tx_ratio, int, NULL, 0);
 MODULE_PARM_DESC(link, "AceNIC/3C985/NetGear link state");
 MODULE_PARM_DESC(trace, "AceNIC/3C985/NetGear firmware trace level");
 MODULE_PARM_DESC(tx_coal_tick, "AceNIC/3C985/GA620 max clock ticks to wait from first tx descriptor arrives");
@@ -444,7 +443,7 @@ MODULE_PARM_DESC(max_rx_desc, "AceNIC/3C985/GA620 max number of receive descript
 MODULE_PARM_DESC(tx_ratio, "AceNIC/3C985/GA620 ratio of NIC memory used for TX/RX descriptors (range 0-63)");
 
 
-static char version[] __initdata = 
+static char version[] __devinitdata = 
   "acenic.c: v0.92 08/05/2002  Jes Sorensen, linux-acenic@SunSITE.dk\n"
   "                            http://home.cern.ch/~jes/gige/acenic.html\n";
 
@@ -458,6 +457,8 @@ static struct ethtool_ops ace_ethtool_ops = {
        .get_drvinfo = ace_get_drvinfo,
 };
 
+static void ace_watchdog(struct net_device *dev);
+
 static int __devinit acenic_probe_one(struct pci_dev *pdev,
                const struct pci_device_id *id)
 {
@@ -486,7 +487,6 @@ static int __devinit acenic_probe_one(struct pci_dev *pdev,
        dev->vlan_rx_kill_vid = ace_vlan_rx_kill_vid;
 #endif
        if (1) {
-               static void ace_watchdog(struct net_device *dev);
                dev->tx_timeout = &ace_watchdog;
                dev->watchdog_timeo = 5*HZ;
        }
@@ -539,7 +539,7 @@ static int __devinit acenic_probe_one(struct pci_dev *pdev,
         * addresses but who gives a damn.
         */
        dev->base_addr = pci_resource_start(pdev, 0);
-       ap->regs = (struct ace_regs *)ioremap(dev->base_addr, 0x4000);
+       ap->regs = ioremap(dev->base_addr, 0x4000);
        if (!ap->regs) {
                printk(KERN_ERR "%s:  Unable to map I/O register, "
                       "AceNIC %i will be disabled.\n",
@@ -632,7 +632,7 @@ static void __devexit acenic_remove_one(struct pci_dev *pdev)
 {
        struct net_device *dev = pci_get_drvdata(pdev);
        struct ace_private *ap = netdev_priv(dev);
-       struct ace_regs *regs = ap->regs;
+       struct ace_regs __iomem *regs = ap->regs;
        short i;
 
        unregister_netdev(dev);
@@ -885,7 +885,7 @@ static void ace_init_cleanup(struct net_device *dev)
 /*
  * Commands are considered to be slow.
  */
-static inline void ace_issue_cmd(struct ace_regs *regs, struct cmd *cmd)
+static inline void ace_issue_cmd(struct ace_regs __iomem *regs, struct cmd *cmd)
 {
        u32 idx;
 
@@ -898,10 +898,10 @@ static inline void ace_issue_cmd(struct ace_regs *regs, struct cmd *cmd)
 }
 
 
-static int __init ace_init(struct net_device *dev)
+static int __devinit ace_init(struct net_device *dev)
 {
        struct ace_private *ap;
-       struct ace_regs *regs;
+       struct ace_regs __iomem *regs;
        struct ace_info *info = NULL;
        struct pci_dev *pdev;
        unsigned long myjif;
@@ -1319,11 +1319,10 @@ static int __init ace_init(struct net_device *dev)
        writel(TX_RING_BASE, &regs->WinBase);
 
        if (ACE_IS_TIGON_I(ap)) {
-               ap->tx_ring = (struct tx_desc *)regs->Window;
-               for (i = 0; i < (TIGON_I_TX_RING_ENTRIES * 
-                                sizeof(struct tx_desc) / 4); i++) {
-                       writel(0, (unsigned long)ap->tx_ring + i * 4);
-               }
+               ap->tx_ring = (struct tx_desc *) regs->Window;
+               for (i = 0; i < (TIGON_I_TX_RING_ENTRIES 
+                                * sizeof(struct tx_desc)) / sizeof(u32); i++)
+                       writel(0, (void __iomem *)ap->tx_ring  + i * 4);
 
                set_aceaddr(&info->tx_ctrl.rngptr, TX_RING_BASE);
        } else {
@@ -1550,14 +1549,9 @@ static int __init ace_init(struct net_device *dev)
 
 static void ace_set_rxtx_parms(struct net_device *dev, int jumbo)
 {
-       struct ace_private *ap;
-       struct ace_regs *regs;
-       int board_idx;
-
-       ap = netdev_priv(dev);
-       regs = ap->regs;
-
-       board_idx = ap->board_idx;
+       struct ace_private *ap = netdev_priv(dev);
+       struct ace_regs __iomem *regs = ap->regs;
+       int board_idx = ap->board_idx;
 
        if (board_idx >= 0) {
                if (!jumbo) {
@@ -1595,7 +1589,7 @@ static void ace_watchdog(struct net_device *data)
 {
        struct net_device *dev = data;
        struct ace_private *ap = netdev_priv(dev);
-       struct ace_regs *regs = ap->regs;
+       struct ace_regs __iomem *regs = ap->regs;
 
        /*
         * We haven't received a stats update event for more than 2.5
@@ -1618,7 +1612,7 @@ static void ace_watchdog(struct net_device *data)
 
 static void ace_tasklet(unsigned long dev)
 {
-       struct ace_private *ap = ((struct net_device *)dev)->priv;
+       struct ace_private *ap = netdev_priv((struct net_device *)dev);
        int cur_size;
 
        cur_size = atomic_read(&ap->cur_rx_bufs);
@@ -1676,10 +1670,9 @@ static void ace_dump_trace(struct ace_private *ap)
  */
 static void ace_load_std_rx_ring(struct ace_private *ap, int nr_bufs)
 {
-       struct ace_regs *regs;
+       struct ace_regs __iomem *regs = ap->regs;
        short i, idx;
-
-       regs = ap->regs;
+       
 
        prefetchw(&ap->cur_rx_bufs);
 
@@ -1740,11 +1733,9 @@ static void ace_load_std_rx_ring(struct ace_private *ap, int nr_bufs)
 
 static void ace_load_mini_rx_ring(struct ace_private *ap, int nr_bufs)
 {
-       struct ace_regs *regs;
+       struct ace_regs __iomem *regs = ap->regs;
        short i, idx;
 
-       regs = ap->regs;
-
        prefetchw(&ap->cur_mini_bufs);
 
        idx = ap->rx_mini_skbprd;
@@ -1799,11 +1790,9 @@ static void ace_load_mini_rx_ring(struct ace_private *ap, int nr_bufs)
  */
 static void ace_load_jumbo_rx_ring(struct ace_private *ap, int nr_bufs)
 {
-       struct ace_regs *regs;
+       struct ace_regs __iomem *regs = ap->regs;
        short i, idx;
 
-       regs = ap->regs;
-
        idx = ap->rx_jumbo_skbprd;
 
        for (i = 0; i < nr_bufs; i++) {
@@ -2083,8 +2072,7 @@ static void ace_rx_int(struct net_device *dev, u32 rxretprd, u32 rxretcsm)
         * the 12.3.x Firmware - my Tigon I NICs seem to disagree!
         */
        if (ACE_IS_TIGON_I(ap)) {
-               struct ace_regs *regs = ap->regs;
-               writel(idx, &regs->RxRetCsm);
+               writel(idx, &ap->regs->RxRetCsm);
        }
        ap->cur_rx = idx;
 
@@ -2164,16 +2152,13 @@ static inline void ace_tx_int(struct net_device *dev,
 
 static irqreturn_t ace_interrupt(int irq, void *dev_id, struct pt_regs *ptregs)
 {
-       struct ace_private *ap;
-       struct ace_regs *regs;
        struct net_device *dev = (struct net_device *)dev_id;
+       struct ace_private *ap = netdev_priv(dev);
+       struct ace_regs __iomem *regs = ap->regs;
        u32 idx;
        u32 txcsm, rxretcsm, rxretprd;
        u32 evtcsm, evtprd;
 
-       ap = netdev_priv(dev);
-       regs = ap->regs;
-
        /*
         * In case of PCI shared interrupts or spurious interrupts,
         * we want to make sure it is actually our interrupt before
@@ -2326,13 +2311,10 @@ static void ace_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
 
 static int ace_open(struct net_device *dev)
 {
-       struct ace_private *ap;
-       struct ace_regs *regs;
+       struct ace_private *ap = netdev_priv(dev);
+       struct ace_regs __iomem *regs = ap->regs;
        struct cmd cmd;
 
-       ap = netdev_priv(dev);
-       regs = ap->regs;
-
        if (!(ap->fw_running)) {
                printk(KERN_WARNING "%s: Firmware not running!\n", dev->name);
                return -EBUSY;
@@ -2384,8 +2366,8 @@ static int ace_open(struct net_device *dev)
 
 static int ace_close(struct net_device *dev)
 {
-       struct ace_private *ap;
-       struct ace_regs *regs;
+       struct ace_private *ap = netdev_priv(dev);
+       struct ace_regs __iomem *regs = ap->regs;
        struct cmd cmd;
        unsigned long flags;
        short i;
@@ -2397,9 +2379,7 @@ static int ace_close(struct net_device *dev)
         */
        netif_stop_queue(dev);
 
-       ap = netdev_priv(dev);
-       regs = ap->regs;
-
+       
        if (ap->promisc) {
                cmd.evt = C_SET_PROMISC_MODE;
                cmd.code = C_C_PROMISC_DISABLE;
@@ -2434,9 +2414,11 @@ static int ace_close(struct net_device *dev)
 
                if (mapping) {
                        if (ACE_IS_TIGON_I(ap)) {
-                               writel(0, &ap->tx_ring[i].addr.addrhi);
-                               writel(0, &ap->tx_ring[i].addr.addrlo);
-                               writel(0, &ap->tx_ring[i].flagsize);
+                               struct tx_desc __iomem *tx 
+                                       = (struct tx_desc __iomem *) &ap->tx_ring[i];
+                               writel(0, &tx->addr.addrhi);
+                               writel(0, &tx->addr.addrlo);
+                               writel(0, &tx->flagsize);
                        } else
                                memset(ap->tx_ring + i, 0,
                                       sizeof(struct tx_desc));
@@ -2493,11 +2475,12 @@ ace_load_tx_bd(struct ace_private *ap, struct tx_desc *desc, u64 addr,
 #endif
 
        if (ACE_IS_TIGON_I(ap)) {
-               writel(addr >> 32, &desc->addr.addrhi);
-               writel(addr & 0xffffffff, &desc->addr.addrlo);
-               writel(flagsize, &desc->flagsize);
+               struct tx_desc __iomem *io = (struct tx_desc __iomem *) desc;
+               writel(addr >> 32, &io->addr.addrhi);
+               writel(addr & 0xffffffff, &io->addr.addrlo);
+               writel(flagsize, &io->flagsize);
 #if ACENIC_DO_VLAN
-               writel(vlan_tag, &desc->vlanres);
+               writel(vlan_tag, &io->vlanres);
 #endif
        } else {
                desc->addr.addrhi = addr >> 32;
@@ -2513,9 +2496,10 @@ ace_load_tx_bd(struct ace_private *ap, struct tx_desc *desc, u64 addr,
 static int ace_start_xmit(struct sk_buff *skb, struct net_device *dev)
 {
        struct ace_private *ap = netdev_priv(dev);
-       struct ace_regs *regs = ap->regs;
+       struct ace_regs __iomem *regs = ap->regs;
        struct tx_desc *desc;
        u32 idx, flagsize;
+       unsigned long maxjiff = jiffies + 3*HZ;
 
 restart:
        idx = ap->tx_prd;
@@ -2523,10 +2507,7 @@ restart:
        if (tx_ring_full(ap, ap->tx_ret_csm, idx))
                goto overflow;
 
-#if MAX_SKB_FRAGS
-       if (!skb_shinfo(skb)->nr_frags)
-#endif
-       {
+       if (!skb_shinfo(skb)->nr_frags) {
                dma_addr_t mapping;
                u32 vlan_tag = 0;
 
@@ -2548,9 +2529,7 @@ restart:
                        flagsize |= BD_FLG_COAL_NOW;
 
                ace_load_tx_bd(ap, desc, mapping, flagsize, vlan_tag);
-       }
-#if MAX_SKB_FRAGS
-       else {
+       } else {
                dma_addr_t mapping;
                u32 vlan_tag = 0;
                int i, len = 0;
@@ -2605,7 +2584,6 @@ restart:
                        ace_load_tx_bd(ap, desc, mapping, flagsize, vlan_tag);
                }
        }
-#endif
 
        wmb();
        ap->tx_prd = idx;
@@ -2625,7 +2603,7 @@ restart:
        }
 
        dev->trans_start = jiffies;
-       return 0;
+       return NETDEV_TX_OK;
 
 overflow:
        /*
@@ -2644,15 +2622,22 @@ overflow:
         * Alternative is to return with 1 not throttling queue. In this
         * case loop becomes longer, no more useful effects.
         */
-       barrier();
-       goto restart;
+       if (time_before(jiffies, maxjiff)) {
+               barrier();
+               cpu_relax();
+               goto restart;
+       }
+       
+       /* The ring is stuck full. */
+       printk(KERN_WARNING "%s: Transmit ring stuck full\n", dev->name);
+       return NETDEV_TX_BUSY;
 }
 
 
 static int ace_change_mtu(struct net_device *dev, int new_mtu)
 {
        struct ace_private *ap = netdev_priv(dev);
-       struct ace_regs *regs = ap->regs;
+       struct ace_regs __iomem *regs = ap->regs;
 
        if (new_mtu > ACE_JUMBO_MTU)
                return -EINVAL;
@@ -2689,7 +2674,7 @@ static int ace_change_mtu(struct net_device *dev, int new_mtu)
 static int ace_get_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
 {
        struct ace_private *ap = netdev_priv(dev);
-       struct ace_regs *regs = ap->regs;
+       struct ace_regs __iomem *regs = ap->regs;
        u32 link;
 
        memset(ecmd, 0, sizeof(struct ethtool_cmd));
@@ -2742,7 +2727,7 @@ static int ace_get_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
 static int ace_set_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
 {
        struct ace_private *ap = netdev_priv(dev);
-       struct ace_regs *regs = ap->regs;
+       struct ace_regs __iomem *regs = ap->regs;
        u32 link, speed;
 
        link = readl(&regs->GigLnkState);
@@ -2822,8 +2807,9 @@ static void ace_get_drvinfo(struct net_device *dev,
  */
 static int ace_set_mac_addr(struct net_device *dev, void *p)
 {
+       struct ace_private *ap = netdev_priv(dev);
+       struct ace_regs __iomem *regs = ap->regs;
        struct sockaddr *addr=p;
-       struct ace_regs *regs;
        u8 *da;
        struct cmd cmd;
 
@@ -2834,7 +2820,6 @@ static int ace_set_mac_addr(struct net_device *dev, void *p)
 
        da = (u8 *)dev->dev_addr;
 
-       regs = ((struct ace_private *)netdev_priv(dev))->regs;
        writel(da[0] << 8 | da[1], &regs->MacAddrHi);
        writel((da[2] << 24) | (da[3] << 16) | (da[4] << 8) | da[5],
               &regs->MacAddrLo);
@@ -2851,7 +2836,7 @@ static int ace_set_mac_addr(struct net_device *dev, void *p)
 static void ace_set_multicast_list(struct net_device *dev)
 {
        struct ace_private *ap = netdev_priv(dev);
-       struct ace_regs *regs = ap->regs;
+       struct ace_regs __iomem *regs = ap->regs;
        struct cmd cmd;
 
        if ((dev->flags & IFF_ALLMULTI) && !(ap->mcast_all)) {
@@ -2905,8 +2890,8 @@ static void ace_set_multicast_list(struct net_device *dev)
 static struct net_device_stats *ace_get_stats(struct net_device *dev)
 {
        struct ace_private *ap = netdev_priv(dev);
-       struct ace_mac_stats *mac_stats =
-               (struct ace_mac_stats *)ap->regs->Stats;
+       struct ace_mac_stats __iomem *mac_stats =
+               (struct ace_mac_stats __iomem *)ap->regs->Stats;
 
        ap->stats.rx_missed_errors = readl(&mac_stats->drop_space);
        ap->stats.multicast = readl(&mac_stats->kept_mc);
@@ -2916,10 +2901,10 @@ static struct net_device_stats *ace_get_stats(struct net_device *dev)
 }
 
 
-static void __init ace_copy(struct ace_regs *regs, void *src,
+static void __devinit ace_copy(struct ace_regs __iomem *regs, void *src,
                            u32 dest, int size)
 {
-       unsigned long tdest;
+       void __iomem *tdest;
        u32 *wsrc;
        short tsize, i;
 
@@ -2929,7 +2914,7 @@ static void __init ace_copy(struct ace_regs *regs, void *src,
        while (size > 0) {
                tsize = min_t(u32, ((~dest & (ACE_WINDOW_SIZE - 1)) + 1),
                            min_t(u32, size, ACE_WINDOW_SIZE));
-               tdest = (unsigned long)&regs->Window +
+               tdest = (void __iomem *) &regs->Window + 
                        (dest & (ACE_WINDOW_SIZE - 1));
                writel(dest & ~(ACE_WINDOW_SIZE - 1), &regs->WinBase);
                /*
@@ -2949,9 +2934,9 @@ static void __init ace_copy(struct ace_regs *regs, void *src,
 }
 
 
-static void __init ace_clear(struct ace_regs *regs, u32 dest, int size)
+static void __devinit ace_clear(struct ace_regs __iomem *regs, u32 dest, int size)
 {
-       unsigned long tdest;
+       void __iomem *tdest;
        short tsize = 0, i;
 
        if (size <= 0)
@@ -2960,7 +2945,7 @@ static void __init ace_clear(struct ace_regs *regs, u32 dest, int size)
        while (size > 0) {
                tsize = min_t(u32, ((~dest & (ACE_WINDOW_SIZE - 1)) + 1),
                                min_t(u32, size, ACE_WINDOW_SIZE));
-               tdest = (unsigned long)&regs->Window +
+               tdest = (void __iomem *) &regs->Window + 
                        (dest & (ACE_WINDOW_SIZE - 1));
                writel(dest & ~(ACE_WINDOW_SIZE - 1), &regs->WinBase);
 
@@ -2982,13 +2967,10 @@ static void __init ace_clear(struct ace_regs *regs, u32 dest, int size)
  * This operation requires the NIC to be halted and is performed with
  * interrupts disabled and with the spinlock hold.
  */
-int __init ace_load_firmware(struct net_device *dev)
+int __devinit ace_load_firmware(struct net_device *dev)
 {
-       struct ace_private *ap;
-       struct ace_regs *regs;
-
-       ap = netdev_priv(dev);
-       regs = ap->regs;
+       struct ace_private *ap = netdev_priv(dev);
+       struct ace_regs __iomem *regs = ap->regs;
 
        if (!(readl(&regs->CpuCtrl) & CPU_HALTED)) {
                printk(KERN_ERR "%s: trying to download firmware while the "
@@ -3036,7 +3018,7 @@ int __init ace_load_firmware(struct net_device *dev)
  * Thanks to Stevarino Webinski for helping tracking down the bugs in the
  * code i2c readout code by beta testing all my hacks.
  */
-static void __init eeprom_start(struct ace_regs *regs)
+static void __devinit eeprom_start(struct ace_regs __iomem *regs)
 {
        u32 local;
 
@@ -3065,7 +3047,7 @@ static void __init eeprom_start(struct ace_regs *regs)
 }
 
 
-static void __init eeprom_prep(struct ace_regs *regs, u8 magic)
+static void __devinit eeprom_prep(struct ace_regs __iomem *regs, u8 magic)
 {
        short i;
        u32 local;
@@ -3102,7 +3084,7 @@ static void __init eeprom_prep(struct ace_regs *regs, u8 magic)
 }
 
 
-static int __init eeprom_check_ack(struct ace_regs *regs)
+static int __devinit eeprom_check_ack(struct ace_regs __iomem *regs)
 {
        int state;
        u32 local;
@@ -3130,7 +3112,7 @@ static int __init eeprom_check_ack(struct ace_regs *regs)
 }
 
 
-static void __init eeprom_stop(struct ace_regs *regs)
+static void __devinit eeprom_stop(struct ace_regs __iomem *regs)
 {
        u32 local;
 
@@ -3165,11 +3147,11 @@ static void __init eeprom_stop(struct ace_regs *regs)
 /*
  * Read a whole byte from the EEPROM.
  */
-static int __init read_eeprom_byte(struct net_device *dev,
+static int __devinit read_eeprom_byte(struct net_device *dev,
                                   unsigned long offset)
 {
-       struct ace_private *ap;
-       struct ace_regs *regs;
+       struct ace_private *ap = netdev_priv(dev);
+       struct ace_regs __iomem *regs = ap->regs;
        unsigned long flags;
        u32 local;
        int result = 0;
@@ -3181,9 +3163,6 @@ static int __init read_eeprom_byte(struct net_device *dev,
                goto out;
        }
 
-       ap = netdev_priv(dev);
-       regs = ap->regs;
-
        /*
         * Don't take interrupts on this CPU will bit banging
         * the %#%#@$ I2C device