niu: Refinements to kernel logging.
[safe/jmp/linux-2.6] / drivers / net / hamachi.c
index 77f2b29..c70b147 100644 (file)
@@ -145,6 +145,7 @@ static int tx_params[MAX_UNITS] = {-1, -1, -1, -1, -1, -1, -1, -1};
 /* Time in jiffies before concluding the transmitter is hung. */
 #define TX_TIMEOUT  (5*HZ)
 
+#include <linux/capability.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/string.h>
@@ -171,10 +172,10 @@ static int tx_params[MAX_UNITS] = {-1, -1, -1, -1, -1, -1, -1, -1};
 #include <asm/unaligned.h>
 #include <asm/cache.h>
 
-static char version[] __devinitdata =
+static const char version[] __devinitconst =
 KERN_INFO DRV_NAME ".c:v" DRV_VERSION " " DRV_RELDATE "  Written by Donald Becker\n"
-KERN_INFO "   Some modifications by Eric kasten <kasten@nscl.msu.edu>\n"
-KERN_INFO "   Further modifications by Keith Underwood <keithu@parl.clemson.edu>\n";
+"   Some modifications by Eric kasten <kasten@nscl.msu.edu>\n"
+"   Further modifications by Keith Underwood <keithu@parl.clemson.edu>\n";
 
 
 /* IP_MF appears to be only defined in <netinet/ip.h>, however,
@@ -406,10 +407,9 @@ that case.
 /* A few values that may be tweaked. */
 /* Size of each temporary Rx buffer, calculated as:
  * 1518 bytes (ethernet packet) + 2 bytes (to get 8 byte alignment for
- * the card) + 8 bytes of status info + 8 bytes for the Rx Checksum +
- * 2 more because we use skb_reserve.
+ * the card) + 8 bytes of status info + 8 bytes for the Rx Checksum
  */
-#define PKT_BUF_SZ             1538
+#define PKT_BUF_SZ             1536
 
 /* For now, this is going to be set to the maximum size of an ethernet
  * packet.  Eventually, we may want to make it a variable that is
@@ -557,7 +557,8 @@ static int netdev_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
 static void hamachi_timer(unsigned long data);
 static void hamachi_tx_timeout(struct net_device *dev);
 static void hamachi_init_ring(struct net_device *dev);
-static int hamachi_start_xmit(struct sk_buff *skb, struct net_device *dev);
+static netdev_tx_t hamachi_start_xmit(struct sk_buff *skb,
+                                     struct net_device *dev);
 static irqreturn_t hamachi_interrupt(int irq, void *dev_instance);
 static int hamachi_rx(struct net_device *dev);
 static inline int hamachi_tx(struct net_device *dev);
@@ -568,6 +569,20 @@ static void set_rx_mode(struct net_device *dev);
 static const struct ethtool_ops ethtool_ops;
 static const struct ethtool_ops ethtool_ops_no_mii;
 
+static const struct net_device_ops hamachi_netdev_ops = {
+       .ndo_open               = hamachi_open,
+       .ndo_stop               = hamachi_close,
+       .ndo_start_xmit         = hamachi_start_xmit,
+       .ndo_get_stats          = hamachi_get_stats,
+       .ndo_set_multicast_list = set_rx_mode,
+       .ndo_change_mtu         = eth_change_mtu,
+       .ndo_validate_addr      = eth_validate_addr,
+       .ndo_set_mac_address    = eth_mac_addr,
+       .ndo_tx_timeout         = hamachi_tx_timeout,
+       .ndo_do_ioctl           = netdev_ioctl,
+};
+
+
 static int __devinit hamachi_init_one (struct pci_dev *pdev,
                                    const struct pci_device_id *ent)
 {
@@ -722,17 +737,11 @@ static int __devinit hamachi_init_one (struct pci_dev *pdev,
 
 
        /* The Hamachi-specific entries in the device structure. */
-       dev->open = &hamachi_open;
-       dev->hard_start_xmit = &hamachi_start_xmit;
-       dev->stop = &hamachi_close;
-       dev->get_stats = &hamachi_get_stats;
-       dev->set_multicast_list = &set_rx_mode;
-       dev->do_ioctl = &netdev_ioctl;
+       dev->netdev_ops = &hamachi_netdev_ops;
        if (chip_tbl[hmp->chip_id].flags & CanHaveMII)
                SET_ETHTOOL_OPS(dev, &ethtool_ops);
        else
                SET_ETHTOOL_OPS(dev, &ethtool_ops_no_mii);
-       dev->tx_timeout = &hamachi_tx_timeout;
        dev->watchdog_timeo = TX_TIMEOUT;
        if (mtu)
                dev->mtu = mtu;
@@ -863,7 +872,7 @@ static int hamachi_open(struct net_device *dev)
        u32 rx_int_var, tx_int_var;
        u16 fifo_info;
 
-       i = request_irq(dev->irq, &hamachi_interrupt, IRQF_SHARED, dev->name, dev);
+       i = request_irq(dev->irq, hamachi_interrupt, IRQF_SHARED, dev->name, dev);
        if (i)
                return i;
 
@@ -1072,11 +1081,14 @@ static void hamachi_tx_timeout(struct net_device *dev)
        {
                printk(KERN_DEBUG "  Rx ring %p: ", hmp->rx_ring);
                for (i = 0; i < RX_RING_SIZE; i++)
-                       printk(" %8.8x", le32_to_cpu(hmp->rx_ring[i].status_n_length));
-               printk("\n"KERN_DEBUG"  Tx ring %p: ", hmp->tx_ring);
+                       printk(KERN_CONT " %8.8x",
+                              le32_to_cpu(hmp->rx_ring[i].status_n_length));
+               printk(KERN_CONT "\n");
+               printk(KERN_DEBUG"  Tx ring %p: ", hmp->tx_ring);
                for (i = 0; i < TX_RING_SIZE; i++)
-                       printk(" %4.4x", le32_to_cpu(hmp->tx_ring[i].status_n_length));
-               printk("\n");
+                       printk(KERN_CONT " %4.4x",
+                              le32_to_cpu(hmp->tx_ring[i].status_n_length));
+               printk(KERN_CONT "\n");
        }
 
        /* Reinit the hardware and make sure the Rx and Tx processes
@@ -1139,12 +1151,13 @@ static void hamachi_tx_timeout(struct net_device *dev)
        }
        /* Fill in the Rx buffers.  Handle allocation failure gracefully. */
        for (i = 0; i < RX_RING_SIZE; i++) {
-               struct sk_buff *skb = netdev_alloc_skb(dev, hmp->rx_buf_sz);
+               struct sk_buff *skb;
+
+               skb = netdev_alloc_skb_ip_align(dev, hmp->rx_buf_sz);
                hmp->rx_skbuff[i] = skb;
                if (skb == NULL)
                        break;
 
-               skb_reserve(skb, 2); /* 16 byte align the IP header. */
                 hmp->rx_ring[i].addr = cpu_to_leXX(pci_map_single(hmp->pci_dev,
                        skb->data, hmp->rx_buf_sz, PCI_DMA_FROMDEVICE));
                hmp->rx_ring[i].status_n_length = cpu_to_le32(DescOwn |
@@ -1155,7 +1168,7 @@ static void hamachi_tx_timeout(struct net_device *dev)
        hmp->rx_ring[RX_RING_SIZE-1].status_n_length |= cpu_to_le32(DescEndRing);
 
        /* Trigger an immediate transmit demand. */
-       dev->trans_start = jiffies;
+       dev->trans_start = jiffies; /* prevent tx timeout */
        hmp->stats.tx_errors++;
 
        /* Restart the chip's Tx/Rx processes . */
@@ -1183,7 +1196,7 @@ static void hamachi_init_ring(struct net_device *dev)
         * card.  -KDU
         */
        hmp->rx_buf_sz = (dev->mtu <= 1492 ? PKT_BUF_SZ :
-               (((dev->mtu+26+7) & ~7) + 2 + 16));
+               (((dev->mtu+26+7) & ~7) + 16));
 
        /* Initialize all Rx descriptors. */
        for (i = 0; i < RX_RING_SIZE; i++) {
@@ -1236,7 +1249,7 @@ do { \
     csum_add(sum, (ih)->saddr & 0xffff); \
     csum_add(sum, (ih)->daddr >> 16); \
     csum_add(sum, (ih)->daddr & 0xffff); \
-    csum_add(sum, __constant_htons(IPPROTO_UDP)); \
+    csum_add(sum, cpu_to_be16(IPPROTO_UDP)); \
     csum_add(sum, (uh)->len); \
 } while (0)
 
@@ -1247,12 +1260,13 @@ do { \
     csum_add(sum, (ih)->saddr & 0xffff); \
     csum_add(sum, (ih)->daddr >> 16); \
     csum_add(sum, (ih)->daddr & 0xffff); \
-    csum_add(sum, __constant_htons(IPPROTO_TCP)); \
+    csum_add(sum, cpu_to_be16(IPPROTO_TCP)); \
     csum_add(sum, htons(len)); \
 } while (0)
 #endif
 
-static int hamachi_start_xmit(struct sk_buff *skb, struct net_device *dev)
+static netdev_tx_t hamachi_start_xmit(struct sk_buff *skb,
+                                     struct net_device *dev)
 {
        struct hamachi_private *hmp = netdev_priv(dev);
        unsigned entry;
@@ -1272,7 +1286,7 @@ static int hamachi_start_xmit(struct sk_buff *skb, struct net_device *dev)
                status=readw(hmp->base + TxStatus);
                if( !(status & 0x0001) || (status & 0x0002))
                        writew(0x0001, hmp->base + TxCmd);
-               return 1;
+               return NETDEV_TX_BUSY;
        }
 
        /* Caution: the write order is important here, set the field
@@ -1288,7 +1302,7 @@ static int hamachi_start_xmit(struct sk_buff *skb, struct net_device *dev)
            /* tack on checksum tag */
            u32 tagval = 0;
            struct ethhdr *eh = (struct ethhdr *)skb->data;
-           if (eh->h_proto == __constant_htons(ETH_P_IP)) {
+           if (eh->h_proto == cpu_to_be16(ETH_P_IP)) {
                struct iphdr *ih = (struct iphdr *)((char *)eh + ETH_HLEN);
                if (ih->protocol == IPPROTO_UDP) {
                    struct udphdr *uh
@@ -1356,13 +1370,12 @@ static int hamachi_start_xmit(struct sk_buff *skb, struct net_device *dev)
                hmp->tx_full = 1;
                netif_stop_queue(dev);
        }
-       dev->trans_start = jiffies;
 
        if (hamachi_debug > 4) {
                printk(KERN_DEBUG "%s: Hamachi transmit frame #%d queued in slot %d.\n",
                           dev->name, hmp->cur_tx, entry);
        }
-       return 0;
+       return NETDEV_TX_OK;
 }
 
 /* The interrupt handler does all of the Rx thread work and cleans up
@@ -1553,8 +1566,8 @@ static int hamachi_rx(struct net_device *dev)
 #endif
                        /* Check if the packet is long enough to accept without copying
                           to a minimally-sized skbuff. */
-                       if (pkt_len < rx_copybreak
-                               && (skb = dev_alloc_skb(pkt_len + 2)) != NULL) {
+                       if (pkt_len < rx_copybreak &&
+                           (skb = dev_alloc_skb(pkt_len + 2)) != NULL) {
 #ifdef RX_CHECKSUM
                                printk(KERN_ERR "%s: rx_copybreak non-zero "
                                  "not good with RX_CHECKSUM\n", dev->name);
@@ -1597,7 +1610,7 @@ static int hamachi_rx(struct net_device *dev)
                                 */
                                if (ntohs(ih->tot_len) >= 46){
                                        /* don't worry about frags */
-                                       if (!(ih->frag_off & __constant_htons(IP_MF|IP_OFFSET))) {
+                                       if (!(ih->frag_off & cpu_to_be16(IP_MF|IP_OFFSET))) {
                                                u32 inv = *(u32 *) &buf_addr[data_size - 16];
                                                u32 *p = (u32 *) &buf_addr[data_size - 20];
                                                register u32 crc, p_r, p_r1;
@@ -1709,10 +1722,10 @@ static void hamachi_error(struct net_device *dev, int intr_status)
                readl(ioaddr + 0x370);
                readl(ioaddr + 0x3F0);
        }
-       if ((intr_status & ~(LinkChange|StatsMax|NegotiationChange|IntrRxDone|IntrTxDone))
-               && hamachi_debug)
+       if ((intr_status & ~(LinkChange|StatsMax|NegotiationChange|IntrRxDone|IntrTxDone)) &&
+           hamachi_debug)
                printk(KERN_ERR "%s: Something Wicked happened! %4.4x.\n",
-                          dev->name, intr_status);
+                      dev->name, intr_status);
        /* Hmmmmm, it's not clear how to recover from PCI faults. */
        if (intr_status & (IntrTxPCIErr | IntrTxPCIFault))
                hmp->stats.tx_fifo_errors++;
@@ -1746,13 +1759,13 @@ static int hamachi_close(struct net_device *dev)
 
 #ifdef __i386__
        if (hamachi_debug > 2) {
-               printk("\n"KERN_DEBUG"  Tx ring at %8.8x:\n",
+               printk(KERN_DEBUG "  Tx ring at %8.8x:\n",
                           (int)hmp->tx_ring_dma);
                for (i = 0; i < TX_RING_SIZE; i++)
-                       printk(" %c #%d desc. %8.8x %8.8x.\n",
+                       printk(KERN_DEBUG " %c #%d desc. %8.8x %8.8x.\n",
                                   readl(ioaddr + TxCurPtr) == (long)&hmp->tx_ring[i] ? '>' : ' ',
                                   i, hmp->tx_ring[i].status_n_length, hmp->tx_ring[i].addr);
-               printk("\n"KERN_DEBUG "  Rx ring %8.8x:\n",
+               printk(KERN_DEBUG "  Rx ring %8.8x:\n",
                           (int)hmp->rx_ring_dma);
                for (i = 0; i < RX_RING_SIZE; i++) {
                        printk(KERN_DEBUG " %c #%d desc. %4.4x %8.8x\n",
@@ -1763,7 +1776,7 @@ static int hamachi_close(struct net_device *dev)
                                        u16 *addr = (u16 *)
                                                hmp->rx_skbuff[i]->data;
                                        int j;
-
+                                       printk(KERN_DEBUG "Addr: ");
                                        for (j = 0; j < 0x50; j++)
                                                printk(" %4.4x", addr[j]);
                                        printk("\n");
@@ -1841,13 +1854,13 @@ static void set_rx_mode(struct net_device *dev)
 
        if (dev->flags & IFF_PROMISC) {                 /* Set promiscuous. */
                writew(0x000F, ioaddr + AddrMode);
-       } else if ((dev->mc_count > 63)  ||  (dev->flags & IFF_ALLMULTI)) {
+       } else if ((netdev_mc_count(dev) > 63) || (dev->flags & IFF_ALLMULTI)) {
                /* Too many to match, or accept all multicasts. */
                writew(0x000B, ioaddr + AddrMode);
-       } else if (dev->mc_count > 0) { /* Must use the CAM filter. */
+       } else if (!netdev_mc_empty(dev)) { /* Must use the CAM filter. */
                struct dev_mc_list *mclist;
                int i;
-               for (i = 0, mclist = dev->mc_list; mclist && i < dev->mc_count;
+               for (i = 0, mclist = dev->mc_list; mclist && i < netdev_mc_count(dev);
                         i++, mclist = mclist->next) {
                        writel(*(u32*)(mclist->dmi_addr), ioaddr + 0x100 + i*8);
                        writel(0x20000 | (*(u16*)&mclist->dmi_addr[4]),
@@ -1977,7 +1990,7 @@ static void __devexit hamachi_remove_one (struct pci_dev *pdev)
        }
 }
 
-static struct pci_device_id hamachi_pci_tbl[] = {
+static DEFINE_PCI_DEVICE_TABLE(hamachi_pci_tbl) = {
        { 0x1318, 0x0911, PCI_ANY_ID, PCI_ANY_ID, },
        { 0, }
 };