netdevice: safe convert to netdev_priv() #part-1
[linux-2.6.git] / drivers / net / 3c505.c
index acede30..6124605 100644 (file)
@@ -130,12 +130,12 @@ static const char filename[] = __FILE__;
 
 static const char timeout_msg[] = "*** timeout at %s:%s (line %d) ***\n";
 #define TIMEOUT_MSG(lineno) \
-       printk(timeout_msg, filename,__FUNCTION__,(lineno))
+       printk(timeout_msg, filename,__func__,(lineno))
 
 static const char invalid_pcb_msg[] =
 "*** invalid pcb length %d at %s:%s (line %d) ***\n";
 #define INVALID_PCB_MSG(len) \
-       printk(invalid_pcb_msg, (len),filename,__FUNCTION__,__LINE__)
+       printk(invalid_pcb_msg, (len),filename,__func__,__LINE__)
 
 static char search_msg[] __initdata = KERN_INFO "%s: Looking for 3c505 adapter at address %#x...";
 
@@ -203,10 +203,10 @@ static inline int inb_command(unsigned int base_addr)
 static inline void outb_control(unsigned char val, struct net_device *dev)
 {
        outb(val, dev->base_addr + PORT_CONTROL);
-       ((elp_device *)(dev->priv))->hcr_val = val;
+       ((elp_device *)(netdev_priv(dev)))->hcr_val = val;
 }
 
-#define HCR_VAL(x)   (((elp_device *)((x)->priv))->hcr_val)
+#define HCR_VAL(x)   (((elp_device *)(netdev_priv(x)))->hcr_val)
 
 static inline void outb_command(unsigned char val, unsigned int base_addr)
 {
@@ -247,7 +247,7 @@ static inline int get_status(unsigned int base_addr)
 
 static inline void set_hsf(struct net_device *dev, int hsf)
 {
-       elp_device *adapter = dev->priv;
+       elp_device *adapter = netdev_priv(dev);
        unsigned long flags;
 
        spin_lock_irqsave(&adapter->lock, flags);
@@ -260,7 +260,7 @@ static bool start_receive(struct net_device *, pcb_struct *);
 static inline void adapter_reset(struct net_device *dev)
 {
        unsigned long timeout;
-       elp_device *adapter = dev->priv;
+       elp_device *adapter = netdev_priv(dev);
        unsigned char orig_hcr = adapter->hcr_val;
 
        outb_control(0, dev);
@@ -293,7 +293,7 @@ static inline void adapter_reset(struct net_device *dev)
  */
 static inline void check_3c505_dma(struct net_device *dev)
 {
-       elp_device *adapter = dev->priv;
+       elp_device *adapter = netdev_priv(dev);
        if (adapter->dmaing && time_after(jiffies, adapter->current_dma.start_time + 10)) {
                unsigned long flags, f;
                printk(KERN_ERR "%s: DMA %s timed out, %d bytes left\n", dev->name, adapter->current_dma.direction ? "download" : "upload", get_dma_residue(dev->dma));
@@ -340,7 +340,7 @@ static inline bool send_pcb_fast(unsigned int base_addr, unsigned char byte)
 /* Check to see if the receiver needs restarting, and kick it if so */
 static inline void prime_rx(struct net_device *dev)
 {
-       elp_device *adapter = dev->priv;
+       elp_device *adapter = netdev_priv(dev);
        while (adapter->rx_active < ELP_RX_PCBS && netif_running(dev)) {
                if (!start_receive(dev, &adapter->itx_pcb))
                        break;
@@ -375,7 +375,7 @@ static bool send_pcb(struct net_device *dev, pcb_struct * pcb)
 {
        int i;
        unsigned long timeout;
-       elp_device *adapter = dev->priv;
+       elp_device *adapter = netdev_priv(dev);
        unsigned long flags;
 
        check_3c505_dma(dev);
@@ -463,7 +463,7 @@ static bool receive_pcb(struct net_device *dev, pcb_struct * pcb)
        unsigned long timeout;
        unsigned long flags;
 
-       elp_device *adapter = dev->priv;
+       elp_device *adapter = netdev_priv(dev);
 
        set_hsf(dev, 0);
 
@@ -543,7 +543,7 @@ static bool receive_pcb(struct net_device *dev, pcb_struct * pcb)
 static bool start_receive(struct net_device *dev, pcb_struct * tx_pcb)
 {
        bool status;
-       elp_device *adapter = dev->priv;
+       elp_device *adapter = netdev_priv(dev);
 
        if (elp_debug >= 3)
                printk(KERN_DEBUG "%s: restarting receiver\n", dev->name);
@@ -571,7 +571,7 @@ static bool start_receive(struct net_device *dev, pcb_struct * tx_pcb)
 static void receive_packet(struct net_device *dev, int len)
 {
        int rlen;
-       elp_device *adapter = dev->priv;
+       elp_device *adapter = netdev_priv(dev);
        void *target;
        struct sk_buff *skb;
        unsigned long flags;
@@ -638,13 +638,10 @@ static irqreturn_t elp_interrupt(int irq, void *dev_id)
        int len;
        int dlen;
        int icount = 0;
-       struct net_device *dev;
-       elp_device *adapter;
+       struct net_device *dev = dev_id;
+       elp_device *adapter = netdev_priv(dev);
        unsigned long timeout;
 
-       dev = dev_id;
-       adapter = (elp_device *) dev->priv;
-
        spin_lock(&adapter->lock);
 
        do {
@@ -670,9 +667,8 @@ static irqreturn_t elp_interrupt(int irq, void *dev_id)
                                        memcpy(adapter->current_dma.target, adapter->dma_buffer, adapter->current_dma.length);
                                        }
                                        skb->protocol = eth_type_trans(skb,dev);
-                                       adapter->stats.rx_bytes += skb->len;
+                                       dev->stats.rx_bytes += skb->len;
                                        netif_rx(skb);
-                                       dev->last_rx = jiffies;
                                }
                        }
                        adapter->dmaing = 0;
@@ -773,12 +769,12 @@ static irqreturn_t elp_interrupt(int irq, void *dev_id)
                                         * received board statistics
                                         */
                                case CMD_NETWORK_STATISTICS_RESPONSE:
-                                       adapter->stats.rx_packets += adapter->irx_pcb.data.netstat.tot_recv;
-                                       adapter->stats.tx_packets += adapter->irx_pcb.data.netstat.tot_xmit;
-                                       adapter->stats.rx_crc_errors += adapter->irx_pcb.data.netstat.err_CRC;
-                                       adapter->stats.rx_frame_errors += adapter->irx_pcb.data.netstat.err_align;
-                                       adapter->stats.rx_fifo_errors += adapter->irx_pcb.data.netstat.err_ovrrun;
-                                       adapter->stats.rx_over_errors += adapter->irx_pcb.data.netstat.err_res;
+                                       dev->stats.rx_packets += adapter->irx_pcb.data.netstat.tot_recv;
+                                       dev->stats.tx_packets += adapter->irx_pcb.data.netstat.tot_xmit;
+                                       dev->stats.rx_crc_errors += adapter->irx_pcb.data.netstat.err_CRC;
+                                       dev->stats.rx_frame_errors += adapter->irx_pcb.data.netstat.err_align;
+                                       dev->stats.rx_fifo_errors += adapter->irx_pcb.data.netstat.err_ovrrun;
+                                       dev->stats.rx_over_errors += adapter->irx_pcb.data.netstat.err_res;
                                        adapter->got[CMD_NETWORK_STATISTICS] = 1;
                                        if (elp_debug >= 3)
                                                printk(KERN_DEBUG "%s: interrupt - statistics response received\n", dev->name);
@@ -794,11 +790,11 @@ static irqreturn_t elp_interrupt(int irq, void *dev_id)
                                                break;
                                        switch (adapter->irx_pcb.data.xmit_resp.c_stat) {
                                        case 0xffff:
-                                               adapter->stats.tx_aborted_errors++;
+                                               dev->stats.tx_aborted_errors++;
                                                printk(KERN_INFO "%s: transmit timed out, network cable problem?\n", dev->name);
                                                break;
                                        case 0xfffe:
-                                               adapter->stats.tx_fifo_errors++;
+                                               dev->stats.tx_fifo_errors++;
                                                printk(KERN_INFO "%s: transmit timed out, FIFO underrun\n", dev->name);
                                                break;
                                        }
@@ -838,11 +834,9 @@ static irqreturn_t elp_interrupt(int irq, void *dev_id)
 
 static int elp_open(struct net_device *dev)
 {
-       elp_device *adapter;
+       elp_device *adapter = netdev_priv(dev);
        int retval;
 
-       adapter = dev->priv;
-
        if (elp_debug >= 3)
                printk(KERN_DEBUG "%s: request to open device\n", dev->name);
 
@@ -971,7 +965,7 @@ static int elp_open(struct net_device *dev)
 
 static bool send_packet(struct net_device *dev, struct sk_buff *skb)
 {
-       elp_device *adapter = dev->priv;
+       elp_device *adapter = netdev_priv(dev);
        unsigned long target;
        unsigned long flags;
 
@@ -986,7 +980,7 @@ static bool send_packet(struct net_device *dev, struct sk_buff *skb)
                return false;
        }
 
-       adapter->stats.tx_bytes += nlen;
+       dev->stats.tx_bytes += nlen;
 
        /*
         * send the adapter a transmit packet command. Ignore segment and offset
@@ -1041,7 +1035,6 @@ static bool send_packet(struct net_device *dev, struct sk_buff *skb)
 
 static void elp_timeout(struct net_device *dev)
 {
-       elp_device *adapter = dev->priv;
        int stat;
 
        stat = inb_status(dev->base_addr);
@@ -1049,7 +1042,7 @@ static void elp_timeout(struct net_device *dev)
        if (elp_debug >= 1)
                printk(KERN_DEBUG "%s: status %#02x\n", dev->name, stat);
        dev->trans_start = jiffies;
-       adapter->stats.tx_dropped++;
+       dev->stats.tx_dropped++;
        netif_wake_queue(dev);
 }
 
@@ -1063,7 +1056,7 @@ static void elp_timeout(struct net_device *dev)
 static int elp_start_xmit(struct sk_buff *skb, struct net_device *dev)
 {
        unsigned long flags;
-       elp_device *adapter = dev->priv;
+       elp_device *adapter = netdev_priv(dev);
 
        spin_lock_irqsave(&adapter->lock, flags);
        check_3c505_dma(dev);
@@ -1105,7 +1098,7 @@ static int elp_start_xmit(struct sk_buff *skb, struct net_device *dev)
 
 static struct net_device_stats *elp_get_stats(struct net_device *dev)
 {
-       elp_device *adapter = (elp_device *) dev->priv;
+       elp_device *adapter = netdev_priv(dev);
 
        if (elp_debug >= 3)
                printk(KERN_DEBUG "%s: request for stats\n", dev->name);
@@ -1113,7 +1106,7 @@ static struct net_device_stats *elp_get_stats(struct net_device *dev)
        /* If the device is closed, just return the latest stats we have,
           - we cannot ask from the adapter without interrupts */
        if (!netif_running(dev))
-               return &adapter->stats;
+               return &dev->stats;
 
        /* send a get statistics command to the board */
        adapter->tx_pcb.command = CMD_NETWORK_STATISTICS;
@@ -1126,12 +1119,12 @@ static struct net_device_stats *elp_get_stats(struct net_device *dev)
                while (adapter->got[CMD_NETWORK_STATISTICS] == 0 && time_before(jiffies, timeout));
                if (time_after_eq(jiffies, timeout)) {
                        TIMEOUT_MSG(__LINE__);
-                       return &adapter->stats;
+                       return &dev->stats;
                }
        }
 
        /* statistics are now up to date */
-       return &adapter->stats;
+       return &dev->stats;
 }
 
 
@@ -1167,9 +1160,7 @@ static const struct ethtool_ops netdev_ethtool_ops = {
 
 static int elp_close(struct net_device *dev)
 {
-       elp_device *adapter;
-
-       adapter = dev->priv;
+       elp_device *adapter = netdev_priv(dev);
 
        if (elp_debug >= 3)
                printk(KERN_DEBUG "%s: request to close device\n", dev->name);
@@ -1210,7 +1201,7 @@ static int elp_close(struct net_device *dev)
 
 static void elp_set_mc_list(struct net_device *dev)
 {
-       elp_device *adapter = (elp_device *) dev->priv;
+       elp_device *adapter = netdev_priv(dev);
        struct dev_mc_list *dmi = dev->mc_list;
        int i;
        unsigned long flags;
@@ -1381,14 +1372,12 @@ static int __init elp_autodetect(struct net_device *dev)
 
 static int __init elplus_setup(struct net_device *dev)
 {
-       elp_device *adapter = dev->priv;
+       elp_device *adapter = netdev_priv(dev);
        int i, tries, tries1, okay;
        unsigned long timeout;
        unsigned long cookie = 0;
        int err = -ENODEV;
 
-       SET_MODULE_OWNER(dev);
-
        /*
         *  setup adapter structure
         */
@@ -1523,11 +1512,10 @@ static int __init elplus_setup(struct net_device *dev)
        /*
         * print remainder of startup message
         */
-       printk(KERN_INFO "%s: 3c505 at %#lx, irq %d, dma %d, ",
-              dev->name, dev->base_addr, dev->irq, dev->dma);
-       printk("addr %02x:%02x:%02x:%02x:%02x:%02x, ",
-              dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2],
-              dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5]);
+       printk(KERN_INFO "%s: 3c505 at %#lx, irq %d, dma %d, "
+              "addr %pM, ",
+              dev->name, dev->base_addr, dev->irq, dev->dma,
+              dev->dev_addr);
 
        /*
         * read more information from the adapter
@@ -1573,7 +1561,6 @@ static int __init elplus_setup(struct net_device *dev)
        dev->set_multicast_list = elp_set_mc_list;      /* local */
        dev->ethtool_ops = &netdev_ethtool_ops;         /* local */
 
-       memset(&(adapter->stats), 0, sizeof(struct net_device_stats));
        dev->mem_start = dev->mem_end = 0;
 
        err = register_netdev(dev);