i2c: Document the message size limit
[safe/jmp/linux-2.6] / drivers / net / lib82596.c
index 5884f5b..b117f7f 100644 (file)
@@ -47,7 +47,7 @@
    TBD:
    * look at deferring rx frames rather than discarding (as per tulip)
    * handle tx ring full as per tulip
-   * performace test to tune rx_copybreak
+   * performance test to tune rx_copybreak
 
    Most of my modifications relate to the braindead big-endian
    implementation by Intel.  When the i596 is operating in
@@ -176,8 +176,8 @@ struct i596_reg {
 struct i596_tbd {
        unsigned short size;
        unsigned short pad;
-       dma_addr_t     next;
-       dma_addr_t     data;
+       u32            next;
+       u32            data;
        u32 cache_pad[5];               /* Total 32 bytes... */
 };
 
@@ -195,12 +195,12 @@ struct i596_cmd {
        struct i596_cmd *v_next;        /* Address from CPUs viewpoint */
        unsigned short status;
        unsigned short command;
-       dma_addr_t     b_next;  /* Address from i596 viewpoint */
+       u32            b_next;  /* Address from i596 viewpoint */
 };
 
 struct tx_cmd {
        struct i596_cmd cmd;
-       dma_addr_t     tbd;
+       u32            tbd;
        unsigned short size;
        unsigned short pad;
        struct sk_buff *skb;            /* So we can free it after tx */
@@ -237,8 +237,8 @@ struct cf_cmd {
 struct i596_rfd {
        unsigned short stat;
        unsigned short cmd;
-       dma_addr_t     b_next;  /* Address from i596 viewpoint */
-       dma_addr_t     rbd;
+       u32            b_next;  /* Address from i596 viewpoint */
+       u32            rbd;
        unsigned short count;
        unsigned short size;
        struct i596_rfd *v_next;        /* Address from CPUs viewpoint */
@@ -249,18 +249,18 @@ struct i596_rfd {
 };
 
 struct i596_rbd {
-    /* hardware data */
-    unsigned short count;
-    unsigned short zero1;
-    dma_addr_t     b_next;
-    dma_addr_t     b_data;             /* Address from i596 viewpoint */
-    unsigned short size;
-    unsigned short zero2;
-    /* driver data */
-    struct sk_buff *skb;
-    struct i596_rbd *v_next;
-    dma_addr_t     b_addr;             /* This rbd addr from i596 view */
-    unsigned char *v_data;             /* Address from CPUs viewpoint */
+       /* hardware data */
+       unsigned short count;
+       unsigned short zero1;
+       u32            b_next;
+       u32            b_data;          /* Address from i596 viewpoint */
+       unsigned short size;
+       unsigned short zero2;
+       /* driver data */
+       struct sk_buff *skb;
+       struct i596_rbd *v_next;
+       u32            b_addr;          /* This rbd addr from i596 view */
+       unsigned char *v_data;          /* Address from CPUs viewpoint */
                                        /* Total 32 bytes... */
 #ifdef __LP64__
     u32 cache_pad[4];
@@ -275,8 +275,8 @@ struct i596_rbd {
 struct i596_scb {
        unsigned short status;
        unsigned short command;
-       dma_addr_t    cmd;
-       dma_addr_t    rfd;
+       u32           cmd;
+       u32           rfd;
        u32           crc_err;
        u32           align_err;
        u32           resource_err;
@@ -288,14 +288,14 @@ struct i596_scb {
 };
 
 struct i596_iscp {
-       u32           stat;
-       dma_addr_t    scb;
+       u32 stat;
+       u32 scb;
 };
 
 struct i596_scp {
-       u32           sysbus;
-       u32           pad;
-       dma_addr_t    iscp;
+       u32 sysbus;
+       u32 pad;
+       u32 iscp;
 };
 
 struct i596_dma {
@@ -322,7 +322,6 @@ struct i596_private {
        struct i596_cmd *cmd_head;
        int cmd_backlog;
        u32    last_cmd;
-       struct net_device_stats stats;
        int next_tx_cmd;
        int options;
        spinlock_t lock;       /* serialize access to chip */
@@ -352,7 +351,6 @@ static int i596_open(struct net_device *dev);
 static int i596_start_xmit(struct sk_buff *skb, struct net_device *dev);
 static irqreturn_t i596_interrupt(int irq, void *dev_id);
 static int i596_close(struct net_device *dev);
-static struct net_device_stats *i596_get_stats(struct net_device *dev);
 static void i596_add_cmd(struct net_device *dev, struct i596_cmd *cmd);
 static void i596_tx_timeout (struct net_device *dev);
 static void print_eth(unsigned char *buf, char *str);
@@ -472,11 +470,11 @@ static inline int init_rx_bufs(struct net_device *dev)
 
        for (i = 0, rbd = dma->rbds; i < rx_ring_size; i++, rbd++) {
                dma_addr_t dma_addr;
-               struct sk_buff *skb = netdev_alloc_skb(dev, PKT_BUF_SZ + 4);
+               struct sk_buff *skb;
 
+               skb = netdev_alloc_skb_ip_align(dev, PKT_BUF_SZ);
                if (skb == NULL)
                        return -1;
-               skb_reserve(skb, 2);
                dma_addr = dma_map_single(dev->dev.parent, skb->data,
                                          PKT_BUF_SZ, DMA_FROM_DEVICE);
                rbd->v_next = rbd+1;
@@ -590,7 +588,7 @@ static int init_i596_mem(struct net_device *dev)
                             "%s: i82596 initialization successful\n",
                             dev->name));
 
-       if (request_irq(dev->irq, &i596_interrupt, 0, "i82596", dev)) {
+       if (request_irq(dev->irq, i596_interrupt, 0, "i82596", dev)) {
                printk(KERN_ERR "%s: IRQ %d not free\n", dev->name, dev->irq);
                goto failed;
        }
@@ -699,12 +697,12 @@ static inline int i596_rx(struct net_device *dev)
                                                 (dma_addr_t)SWAP32(rbd->b_data),
                                                 PKT_BUF_SZ, DMA_FROM_DEVICE);
                                /* Get fresh skbuff to replace filled one. */
-                               newskb = netdev_alloc_skb(dev, PKT_BUF_SZ + 4);
+                               newskb = netdev_alloc_skb_ip_align(dev,
+                                                                  PKT_BUF_SZ);
                                if (newskb == NULL) {
                                        skb = NULL;     /* drop pkt */
                                        goto memory_squeeze;
                                }
-                               skb_reserve(newskb, 2);
 
                                /* Pass up the skb already on the Rx ring. */
                                skb_put(skb, pkt_len);
@@ -718,21 +716,20 @@ static inline int i596_rx(struct net_device *dev)
                                rbd->b_data = SWAP32(dma_addr);
                                DMA_WBACK_INV(dev, rbd, sizeof(struct i596_rbd));
                        } else
-                               skb = netdev_alloc_skb(dev, pkt_len + 2);
+                               skb = netdev_alloc_skb_ip_align(dev, pkt_len);
 memory_squeeze:
                        if (skb == NULL) {
                                /* XXX tulip.c can defer packets here!! */
                                printk(KERN_ERR
                                       "%s: i596_rx Memory squeeze, dropping packet.\n",
                                       dev->name);
-                               lp->stats.rx_dropped++;
+                               dev->stats.rx_dropped++;
                        } else {
                                if (!rx_in_place) {
                                        /* 16 byte align the data fields */
                                        dma_sync_single_for_cpu(dev->dev.parent,
                                                                (dma_addr_t)SWAP32(rbd->b_data),
                                                                PKT_BUF_SZ, DMA_FROM_DEVICE);
-                                       skb_reserve(skb, 2);
                                        memcpy(skb_put(skb, pkt_len), rbd->v_data, pkt_len);
                                        dma_sync_single_for_device(dev->dev.parent,
                                                                   (dma_addr_t)SWAP32(rbd->b_data),
@@ -741,29 +738,28 @@ memory_squeeze:
                                skb->len = pkt_len;
                                skb->protocol = eth_type_trans(skb, dev);
                                netif_rx(skb);
-                               dev->last_rx = jiffies;
-                               lp->stats.rx_packets++;
-                               lp->stats.rx_bytes += pkt_len;
+                               dev->stats.rx_packets++;
+                               dev->stats.rx_bytes += pkt_len;
                        }
                } else {
                        DEB(DEB_ERRORS, printk(KERN_DEBUG
                                               "%s: Error, rfd.stat = 0x%04x\n",
                                               dev->name, rfd->stat));
-                       lp->stats.rx_errors++;
+                       dev->stats.rx_errors++;
                        if (rfd->stat & SWAP16(0x0100))
-                               lp->stats.collisions++;
+                               dev->stats.collisions++;
                        if (rfd->stat & SWAP16(0x8000))
-                               lp->stats.rx_length_errors++;
+                               dev->stats.rx_length_errors++;
                        if (rfd->stat & SWAP16(0x0001))
-                               lp->stats.rx_over_errors++;
+                               dev->stats.rx_over_errors++;
                        if (rfd->stat & SWAP16(0x0002))
-                               lp->stats.rx_fifo_errors++;
+                               dev->stats.rx_fifo_errors++;
                        if (rfd->stat & SWAP16(0x0004))
-                               lp->stats.rx_frame_errors++;
+                               dev->stats.rx_frame_errors++;
                        if (rfd->stat & SWAP16(0x0008))
-                               lp->stats.rx_crc_errors++;
+                               dev->stats.rx_crc_errors++;
                        if (rfd->stat & SWAP16(0x0010))
-                               lp->stats.rx_length_errors++;
+                               dev->stats.rx_length_errors++;
                }
 
                /* Clear the buffer descriptor count and EOF + F flags */
@@ -821,8 +817,8 @@ static inline void i596_cleanup_cmd(struct net_device *dev, struct i596_private
 
                                dev_kfree_skb(skb);
 
-                               lp->stats.tx_errors++;
-                               lp->stats.tx_aborted_errors++;
+                               dev->stats.tx_errors++;
+                               dev->stats.tx_aborted_errors++;
 
                                ptr->v_next = NULL;
                                ptr->b_next = I596_NULL;
@@ -951,10 +947,10 @@ static void i596_tx_timeout (struct net_device *dev)
                               "%s: transmit timed out, status resetting.\n",
                               dev->name));
 
-       lp->stats.tx_errors++;
+       dev->stats.tx_errors++;
 
        /* Try to restart the adaptor */
-       if (lp->last_restart == lp->stats.tx_packets) {
+       if (lp->last_restart == dev->stats.tx_packets) {
                DEB(DEB_ERRORS, printk(KERN_DEBUG "Resetting board.\n"));
                /* Shutdown and restart */
                i596_reset (dev, lp);
@@ -964,7 +960,7 @@ static void i596_tx_timeout (struct net_device *dev)
                lp->dma->scb.command = SWAP16(CUC_START | RX_START);
                DMA_WBACK_INV(dev, &(lp->dma->scb), sizeof(struct i596_scb));
                ca (dev);
-               lp->last_restart = lp->stats.tx_packets;
+               lp->last_restart = dev->stats.tx_packets;
        }
 
        dev->trans_start = jiffies;
@@ -986,7 +982,7 @@ static int i596_start_xmit(struct sk_buff *skb, struct net_device *dev)
 
        if (length < ETH_ZLEN) {
                if (skb_padto(skb, ETH_ZLEN))
-                       return 0;
+                       return NETDEV_TX_OK;
                length = ETH_ZLEN;
        }
 
@@ -999,7 +995,7 @@ static int i596_start_xmit(struct sk_buff *skb, struct net_device *dev)
                DEB(DEB_ERRORS, printk(KERN_DEBUG
                                       "%s: xmit ring full, dropping packet.\n",
                                       dev->name));
-               lp->stats.tx_dropped++;
+               dev->stats.tx_dropped++;
 
                dev_kfree_skb(skb);
        } else {
@@ -1025,27 +1021,33 @@ static int i596_start_xmit(struct sk_buff *skb, struct net_device *dev)
                DMA_WBACK_INV(dev, tbd, sizeof(struct i596_tbd));
                i596_add_cmd(dev, &tx_cmd->cmd);
 
-               lp->stats.tx_packets++;
-               lp->stats.tx_bytes += length;
+               dev->stats.tx_packets++;
+               dev->stats.tx_bytes += length;
        }
 
        netif_start_queue(dev);
 
-       return 0;
+       return NETDEV_TX_OK;
 }
 
 static void print_eth(unsigned char *add, char *str)
 {
-       int i;
-
-       printk(KERN_DEBUG "i596 0x%p, ", add);
-       for (i = 0; i < 6; i++)
-               printk(" %02X", add[i + 6]);
-       printk(" -->");
-       for (i = 0; i < 6; i++)
-               printk(" %02X", add[i]);
-       printk(" %02X%02X, %s\n", add[12], add[13], str);
+       printk(KERN_DEBUG "i596 0x%p, %pM --> %pM %02X%02X, %s\n",
+              add, add + 6, add, add[12], add[13], str);
 }
+static const struct net_device_ops i596_netdev_ops = {
+       .ndo_open               = i596_open,
+       .ndo_stop               = i596_close,
+       .ndo_start_xmit         = i596_start_xmit,
+       .ndo_set_multicast_list = set_multicast_list,
+       .ndo_tx_timeout         = i596_tx_timeout,
+       .ndo_change_mtu         = eth_change_mtu,
+       .ndo_validate_addr      = eth_validate_addr,
+       .ndo_set_mac_address    = eth_mac_addr,
+#ifdef CONFIG_NET_POLL_CONTROLLER
+       .ndo_poll_controller    = i596_poll_controller,
+#endif
+};
 
 static int __devinit i82596_probe(struct net_device *dev)
 {
@@ -1072,17 +1074,8 @@ static int __devinit i82596_probe(struct net_device *dev)
                return -ENOMEM;
        }
 
-       /* The 82596-specific entries in the device structure. */
-       dev->open = i596_open;
-       dev->stop = i596_close;
-       dev->hard_start_xmit = i596_start_xmit;
-       dev->get_stats = i596_get_stats;
-       dev->set_multicast_list = set_multicast_list;
-       dev->tx_timeout = i596_tx_timeout;
+       dev->netdev_ops = &i596_netdev_ops;
        dev->watchdog_timeo = TX_TIMEOUT;
-#ifdef CONFIG_NET_POLL_CONTROLLER
-       dev->poll_controller = i596_poll_controller;
-#endif
 
        memset(dma, 0, sizeof(struct i596_dma));
        lp->dma = dma;
@@ -1130,12 +1123,6 @@ static irqreturn_t i596_interrupt(int irq, void *dev_id)
        struct i596_dma *dma;
        unsigned short status, ack_cmd = 0;
 
-       if (dev == NULL) {
-               printk(KERN_WARNING "%s: irq %d for unknown device.\n",
-                      __FUNCTION__, irq);
-               return IRQ_NONE;
-       }
-
        lp = netdev_priv(dev);
        dma = lp->dma;
 
@@ -1146,7 +1133,7 @@ static irqreturn_t i596_interrupt(int irq, void *dev_id)
 
        DEB(DEB_INTS, printk(KERN_DEBUG
                             "%s: i596 interrupt, IRQ %d, status %4.4x.\n",
-                       dev->name, irq, status));
+                       dev->name, dev->irq, status));
 
        ack_cmd = status & 0xf000;
 
@@ -1197,17 +1184,17 @@ static irqreturn_t i596_interrupt(int irq, void *dev_id)
                                        DEB(DEB_TXADDR,
                                            print_eth(skb->data, "tx-done"));
                                } else {
-                                       lp->stats.tx_errors++;
+                                       dev->stats.tx_errors++;
                                        if (ptr->status & SWAP16(0x0020))
-                                               lp->stats.collisions++;
+                                               dev->stats.collisions++;
                                        if (!(ptr->status & SWAP16(0x0040)))
-                                               lp->stats.tx_heartbeat_errors++;
+                                               dev->stats.tx_heartbeat_errors++;
                                        if (ptr->status & SWAP16(0x0400))
-                                               lp->stats.tx_carrier_errors++;
+                                               dev->stats.tx_carrier_errors++;
                                        if (ptr->status & SWAP16(0x0800))
-                                               lp->stats.collisions++;
+                                               dev->stats.collisions++;
                                        if (ptr->status & SWAP16(0x1000))
-                                               lp->stats.tx_aborted_errors++;
+                                               dev->stats.tx_aborted_errors++;
                                }
                                dma_unmap_single(dev->dev.parent,
                                                 tx_cmd->dma_addr,
@@ -1292,8 +1279,8 @@ static irqreturn_t i596_interrupt(int irq, void *dev_id)
                                           "%s: i596 interrupt receive unit inactive, status 0x%x\n",
                                           dev->name, status));
                                ack_cmd |= RX_START;
-                               lp->stats.rx_errors++;
-                               lp->stats.rx_fifo_errors++;
+                               dev->stats.rx_errors++;
+                               dev->stats.rx_fifo_errors++;
                                rebuild_rx_bufs(dev);
                        }
                }
@@ -1346,13 +1333,6 @@ static int i596_close(struct net_device *dev)
        return 0;
 }
 
-static struct net_device_stats *i596_get_stats(struct net_device *dev)
-{
-       struct i596_private *lp = netdev_priv(dev);
-
-       return &lp->stats;
-}
-
 /*
  *    Set or clear the multicast filter for this adaptor.
  */
@@ -1425,8 +1405,8 @@ static void set_multicast_list(struct net_device *dev)
                        if (i596_debug > 1)
                                DEB(DEB_MULTI,
                                    printk(KERN_DEBUG
-                                          "%s: Adding address %02x:%02x:%02x:%02x:%02x:%02x\n",
-                                          dev->name, cp[0], cp[1], cp[2], cp[3], cp[4], cp[5]));
+                                          "%s: Adding address %pM\n",
+                                          dev->name, cp));
                }
                DMA_WBACK_INV(dev, &dma->mc_cmd, sizeof(struct mc_cmd));
                i596_add_cmd(dev, &cmd->cmd);