usb: cdc_ether: Add new product id for the 5AE profile
[linux-2.6.git] / drivers / net / rrunner.c
index 3a4fce3..e68c941 100644 (file)
@@ -40,6 +40,7 @@
 #include <linux/init.h>
 #include <linux/delay.h>
 #include <linux/mm.h>
+#include <linux/slab.h>
 #include <net/sock.h>
 
 #include <asm/system.h>
@@ -63,6 +64,16 @@ MODULE_LICENSE("GPL");
 
 static char version[] __devinitdata = "rrunner.c: v0.50 11/11/2002  Jes Sorensen (jes@wildopensource.com)\n";
 
+
+static const struct net_device_ops rr_netdev_ops = {
+       .ndo_open               = rr_open,
+       .ndo_stop               = rr_close,
+       .ndo_do_ioctl           = rr_ioctl,
+       .ndo_start_xmit         = rr_start_xmit,
+       .ndo_change_mtu         = hippi_change_mtu,
+       .ndo_set_mac_address    = hippi_mac_addr,
+};
+
 /*
  * Implementation notes:
  *
@@ -78,14 +89,6 @@ static char version[] __devinitdata = "rrunner.c: v0.50 11/11/2002  Jes Sorensen
  * stack will need to know about I/O vectors or something similar.
  */
 
-/*
- * These are checked at init time to see if they are at least 256KB
- * and increased to 256KB if they are not. This is done to avoid ending
- * up with socket buffers smaller than the MTU size,
- */
-extern __u32 sysctl_wmem_max;
-extern __u32 sysctl_rmem_max;
-
 static int __devinit rr_init_one(struct pci_dev *pdev,
        const struct pci_device_id *ent)
 {
@@ -109,7 +112,6 @@ static int __devinit rr_init_one(struct pci_dev *pdev,
 
        rrpriv = netdev_priv(dev);
 
-       SET_MODULE_OWNER(dev);
        SET_NETDEV_DEV(dev, &pdev->dev);
 
        if (pci_request_regions(pdev, "rrunner")) {
@@ -124,11 +126,7 @@ static int __devinit rr_init_one(struct pci_dev *pdev,
        spin_lock_init(&rrpriv->lock);
 
        dev->irq = pdev->irq;
-       dev->open = &rr_open;
-       dev->hard_start_xmit = &rr_start_xmit;
-       dev->stop = &rr_close;
-       dev->get_stats = &rr_get_stats;
-       dev->do_ioctl = &rr_ioctl;
+       dev->netdev_ops = &rr_netdev_ops;
 
        dev->base_addr = pci_resource_start(pdev, 0);
 
@@ -304,7 +302,6 @@ static int rr_reset(struct net_device *dev)
 {
        struct rr_private *rrpriv;
        struct rr_regs __iomem *regs;
-       struct eeprom *hw = NULL;
        u32 start_pc;
        int i;
 
@@ -391,7 +388,8 @@ static int rr_reset(struct net_device *dev)
        writel(RBURST_64|WBURST_64, &regs->PciState);
        wmb();
 
-       start_pc = rr_read_eeprom_word(rrpriv, &hw->rncd_info.FwStart);
+       start_pc = rr_read_eeprom_word(rrpriv,
+                       offsetof(struct eeprom, rncd_info.FwStart));
 
 #if (DEBUG > 1)
        printk("%s: Executing firmware at address 0x%06x\n",
@@ -448,12 +446,12 @@ static unsigned int rr_read_eeprom(struct rr_private *rrpriv,
  * it to our CPU byte-order.
  */
 static u32 rr_read_eeprom_word(struct rr_private *rrpriv,
-                           void * offset)
+                           size_t offset)
 {
-       u32 word;
+       __be32 word;
 
-       if ((rr_read_eeprom(rrpriv, (unsigned long)offset,
-                           (char *)&word, 4) == 4))
+       if ((rr_read_eeprom(rrpriv, offset,
+                           (unsigned char *)&word, 4) == 4))
                return be32_to_cpu(word);
        return 0;
 }
@@ -516,13 +514,11 @@ static unsigned int write_eeprom(struct rr_private *rrpriv,
 }
 
 
-static int __init rr_init(struct net_device *dev)
+static int __devinit rr_init(struct net_device *dev)
 {
        struct rr_private *rrpriv;
        struct rr_regs __iomem *regs;
-       struct eeprom *hw = NULL;
        u32 sram_size, rev;
-       int i;
 
        rrpriv = netdev_priv(dev);
        regs = rrpriv->regs;
@@ -555,32 +551,16 @@ static int __init rr_init(struct net_device *dev)
         * other method I've seen.  -VAL
         */
 
-       *(u16 *)(dev->dev_addr) =
-         htons(rr_read_eeprom_word(rrpriv, &hw->manf.BoardULA));
-       *(u32 *)(dev->dev_addr+2) =
-         htonl(rr_read_eeprom_word(rrpriv, &hw->manf.BoardULA[4]));
-
-       printk("  MAC: ");
+       *(__be16 *)(dev->dev_addr) =
+         htons(rr_read_eeprom_word(rrpriv, offsetof(struct eeprom, manf.BoardULA)));
+       *(__be32 *)(dev->dev_addr+2) =
+         htonl(rr_read_eeprom_word(rrpriv, offsetof(struct eeprom, manf.BoardULA[4])));
 
-       for (i = 0; i < 5; i++)
-               printk("%2.2x:", dev->dev_addr[i]);
-       printk("%2.2x\n", dev->dev_addr[i]);
+       printk("  MAC: %pM\n", dev->dev_addr);
 
-       sram_size = rr_read_eeprom_word(rrpriv, (void *)8);
+       sram_size = rr_read_eeprom_word(rrpriv, 8);
        printk("  SRAM size 0x%06x\n", sram_size);
 
-       if (sysctl_rmem_max < 262144){
-               printk("  Receive socket buffer limit too low (%i), "
-                      "setting to 262144\n", sysctl_rmem_max);
-               sysctl_rmem_max = 262144;
-       }
-
-       if (sysctl_wmem_max < 262144){
-               printk("  Transmit socket buffer limit too low (%i), "
-                      "setting to 262144\n", sysctl_wmem_max);
-               sysctl_wmem_max = 262144;
-       }
-
        return 0;
 }
 
@@ -809,7 +789,7 @@ static u32 rr_handle_event(struct net_device *dev, u32 prodidx, u32 eidx)
                case E_CON_REJ:
                        printk(KERN_WARNING "%s: Connection rejected\n",
                               dev->name);
-                       rrpriv->stats.tx_aborted_errors++;
+                       dev->stats.tx_aborted_errors++;
                        break;
                case E_CON_TMOUT:
                        printk(KERN_WARNING "%s: Connection timeout\n",
@@ -818,7 +798,7 @@ static u32 rr_handle_event(struct net_device *dev, u32 prodidx, u32 eidx)
                case E_DISC_ERR:
                        printk(KERN_WARNING "%s: HIPPI disconnect error\n",
                               dev->name);
-                       rrpriv->stats.tx_aborted_errors++;
+                       dev->stats.tx_aborted_errors++;
                        break;
                case E_INT_PRTY:
                        printk(KERN_ERR "%s: HIPPI Internal Parity error\n",
@@ -834,7 +814,7 @@ static u32 rr_handle_event(struct net_device *dev, u32 prodidx, u32 eidx)
                case E_TX_LINK_DROP:
                        printk(KERN_WARNING "%s: Link lost during transmit\n",
                               dev->name);
-                       rrpriv->stats.tx_aborted_errors++;
+                       dev->stats.tx_aborted_errors++;
                        writel(readl(&regs->HostCtrl)|HALT_NIC|RR_CLEAR_INT,
                               &regs->HostCtrl);
                        wmb();
@@ -904,7 +884,7 @@ static u32 rr_handle_event(struct net_device *dev, u32 prodidx, u32 eidx)
                               dev->name);
                        goto drop;
                case E_FLG_SYN_ERR:
-                       printk(KERN_WARNING "%s: Flag sync. lost during"
+                       printk(KERN_WARNING "%s: Flag sync. lost during "
                               "packet\n", dev->name);
                        goto drop;
                case E_RX_INV_BUF:
@@ -974,7 +954,7 @@ static void rx_int(struct net_device *dev, u32 rxlimit, u32 index)
                printk("len %x, mode %x\n", pkt_len, desc->mode);
 #endif
                if ( (rrpriv->rx_ring[index].mode & PACKET_BAD) == PACKET_BAD){
-                       rrpriv->stats.rx_dropped++;
+                       dev->stats.rx_dropped++;
                        goto defer;
                }
 
@@ -987,7 +967,7 @@ static void rx_int(struct net_device *dev, u32 rxlimit, u32 index)
                                skb = alloc_skb(pkt_len, GFP_ATOMIC);
                                if (skb == NULL){
                                        printk(KERN_WARNING "%s: Unable to allocate skb (%i bytes), deferring packet\n", dev->name, pkt_len);
-                                       rrpriv->stats.rx_dropped++;
+                                       dev->stats.rx_dropped++;
                                        goto defer;
                                } else {
                                        pci_dma_sync_single_for_cpu(rrpriv->pci_dev,
@@ -1025,7 +1005,7 @@ static void rx_int(struct net_device *dev, u32 rxlimit, u32 index)
                                } else {
                                        printk("%s: Out of memory, deferring "
                                               "packet\n", dev->name);
-                                       rrpriv->stats.rx_dropped++;
+                                       dev->stats.rx_dropped++;
                                        goto defer;
                                }
                        }
@@ -1033,9 +1013,8 @@ static void rx_int(struct net_device *dev, u32 rxlimit, u32 index)
 
                        netif_rx(skb);          /* send it up */
 
-                       dev->last_rx = jiffies;
-                       rrpriv->stats.rx_packets++;
-                       rrpriv->stats.rx_bytes += pkt_len;
+                       dev->stats.rx_packets++;
+                       dev->stats.rx_bytes += pkt_len;
                }
        defer:
                desc->mode = 0;
@@ -1103,8 +1082,8 @@ static irqreturn_t rr_interrupt(int irq, void *dev_id)
                                desc = &(rrpriv->tx_ring[txcon]);
                                skb = rrpriv->tx_skbuff[txcon];
 
-                               rrpriv->stats.tx_packets++;
-                               rrpriv->stats.tx_bytes += skb->len;
+                               dev->stats.tx_packets++;
+                               dev->stats.tx_bytes += skb->len;
 
                                pci_unmap_single(rrpriv->pci_dev,
                                                 desc->addr.addrlo, skb->len,
@@ -1266,7 +1245,7 @@ static int rr_open(struct net_device *dev)
        init_timer(&rrpriv->timer);
        rrpriv->timer.expires = RUN_AT(5*HZ);           /* 5 sec. watchdog */
        rrpriv->timer.data = (unsigned long)dev;
-       rrpriv->timer.function = &rr_timer;               /* timer handler */
+       rrpriv->timer.function = rr_timer;               /* timer handler */
        add_timer(&rrpriv->timer);
 
        netif_start_queue(dev);
@@ -1315,7 +1294,7 @@ static void rr_dump(struct net_device *dev)
 
        printk("Error code 0x%x\n", readl(&regs->Fail1));
 
-       index = (((readl(&regs->EvtPrd) >> 8) & 0xff ) - 1) % EVT_RING_ENTRIES;
+       index = (((readl(&regs->EvtPrd) >> 8) & 0xff) - 1) % TX_RING_ENTRIES;
        cons = rrpriv->dirty_tx;
        printk("TX ring index %i, TX consumer %i\n",
               index, cons);
@@ -1423,7 +1402,8 @@ static int rr_close(struct net_device *dev)
 }
 
 
-static int rr_start_xmit(struct sk_buff *skb, struct net_device *dev)
+static netdev_tx_t rr_start_xmit(struct sk_buff *skb,
+                                struct net_device *dev)
 {
        struct rr_private *rrpriv = netdev_priv(dev);
        struct rr_regs __iomem *regs = rrpriv->regs;
@@ -1447,11 +1427,11 @@ static int rr_start_xmit(struct sk_buff *skb, struct net_device *dev)
                if (!(new_skb = dev_alloc_skb(len + 8))) {
                        dev_kfree_skb(skb);
                        netif_wake_queue(dev);
-                       return -EBUSY;
+                       return NETDEV_TX_OK;
                }
                skb_reserve(new_skb, 8);
                skb_put(new_skb, len);
-               memcpy(new_skb->data, skb->data, len);
+               skb_copy_from_linear_data(skb, new_skb->data, len);
                dev_kfree_skb(skb);
                skb = new_skb;
        }
@@ -1487,18 +1467,7 @@ static int rr_start_xmit(struct sk_buff *skb, struct net_device *dev)
 
        spin_unlock_irqrestore(&rrpriv->lock, flags);
 
-       dev->trans_start = jiffies;
-       return 0;
-}
-
-
-static struct net_device_stats *rr_get_stats(struct net_device *dev)
-{
-       struct rr_private *rrpriv;
-
-       rrpriv = netdev_priv(dev);
-
-       return(&rrpriv->stats);
+       return NETDEV_TX_OK;
 }
 
 
@@ -1513,11 +1482,10 @@ static int rr_load_firmware(struct net_device *dev)
 {
        struct rr_private *rrpriv;
        struct rr_regs __iomem *regs;
-       unsigned long eptr, segptr;
+       size_t eptr, segptr;
        int i, j;
        u32 localctrl, sptr, len, tmp;
        u32 p2len, p2size, nr_seg, revision, io, sram_size;
-       struct eeprom *hw = NULL;
 
        rrpriv = netdev_priv(dev);
        regs = rrpriv->regs;
@@ -1545,7 +1513,7 @@ static int rr_load_firmware(struct net_device *dev)
         */
        io = readl(&regs->ExtIo);
        writel(0, &regs->ExtIo);
-       sram_size = rr_read_eeprom_word(rrpriv, (void *)8);
+       sram_size = rr_read_eeprom_word(rrpriv, 8);
 
        for (i = 200; i < sram_size / 4; i++){
                writel(i * 4, &regs->WinBase);
@@ -1556,13 +1524,13 @@ static int rr_load_firmware(struct net_device *dev)
        writel(io, &regs->ExtIo);
        mb();
 
-       eptr = (unsigned long)rr_read_eeprom_word(rrpriv,
-                                              &hw->rncd_info.AddrRunCodeSegs);
+       eptr = rr_read_eeprom_word(rrpriv,
+                      offsetof(struct eeprom, rncd_info.AddrRunCodeSegs));
        eptr = ((eptr & 0x1fffff) >> 3);
 
-       p2len = rr_read_eeprom_word(rrpriv, (void *)(0x83*4));
+       p2len = rr_read_eeprom_word(rrpriv, 0x83*4);
        p2len = (p2len << 2);
-       p2size = rr_read_eeprom_word(rrpriv, (void *)(0x84*4));
+       p2size = rr_read_eeprom_word(rrpriv, 0x84*4);
        p2size = ((p2size & 0x1fffff) >> 3);
 
        if ((eptr < p2size) || (eptr > (p2size + p2len))){
@@ -1570,7 +1538,8 @@ static int rr_load_firmware(struct net_device *dev)
                goto out;
        }
 
-       revision = rr_read_eeprom_word(rrpriv, &hw->manf.HeaderFmt);
+       revision = rr_read_eeprom_word(rrpriv,
+                       offsetof(struct eeprom, manf.HeaderFmt));
 
        if (revision != 1){
                printk("%s: invalid firmware format (%i)\n",
@@ -1578,18 +1547,18 @@ static int rr_load_firmware(struct net_device *dev)
                goto out;
        }
 
-       nr_seg = rr_read_eeprom_word(rrpriv, (void *)eptr);
+       nr_seg = rr_read_eeprom_word(rrpriv, eptr);
        eptr +=4;
 #if (DEBUG > 1)
        printk("%s: nr_seg %i\n", dev->name, nr_seg);
 #endif
 
        for (i = 0; i < nr_seg; i++){
-               sptr = rr_read_eeprom_word(rrpriv, (void *)eptr);
+               sptr = rr_read_eeprom_word(rrpriv, eptr);
                eptr += 4;
-               len = rr_read_eeprom_word(rrpriv, (void *)eptr);
+               len = rr_read_eeprom_word(rrpriv, eptr);
                eptr += 4;
-               segptr = (unsigned long)rr_read_eeprom_word(rrpriv, (void *)eptr);
+               segptr = rr_read_eeprom_word(rrpriv, eptr);
                segptr = ((segptr & 0x1fffff) >> 3);
                eptr += 4;
 #if (DEBUG > 1)
@@ -1597,7 +1566,7 @@ static int rr_load_firmware(struct net_device *dev)
                       dev->name, i, sptr, len, segptr);
 #endif
                for (j = 0; j < len; j++){
-                       tmp = rr_read_eeprom_word(rrpriv, (void *)segptr);
+                       tmp = rr_read_eeprom_word(rrpriv, segptr);
                        writel(sptr, &regs->WinBase);
                        mb();
                        writel(tmp, &regs->WinData);
@@ -1719,7 +1688,7 @@ static int rr_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
        }
 }
 
-static struct pci_device_id rr_pci_tbl[] = {
+static DEFINE_PCI_DEVICE_TABLE(rr_pci_tbl) = {
        { PCI_VENDOR_ID_ESSENTIAL, PCI_DEVICE_ID_ESSENTIAL_ROADRUNNER,
                PCI_ANY_ID, PCI_ANY_ID, },
        { 0,}
@@ -1745,9 +1714,3 @@ static void __exit rr_cleanup_module(void)
 
 module_init(rr_init_module);
 module_exit(rr_cleanup_module);
-
-/*
- * Local variables:
- * compile-command: "gcc -D__KERNEL__ -I../../include -Wall -Wstrict-prototypes -O2 -pipe -fomit-frame-pointer -fno-strength-reduce -m486 -malign-loops=2 -malign-jumps=2 -malign-functions=2 -DMODULE -DMODVERSIONS -include ../../include/linux/modversions.h -c rrunner.c"
- * End:
- */