ata_piix: Add HP Compaq nc6000 to the broken poweroff list
[safe/jmp/linux-2.6] / drivers / net / 3c505.c
index ab8230a..2de1c9c 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...";
 
@@ -169,21 +169,6 @@ static int elp_debug;
 
 /*****************************************************************
  *
- * useful macros
- *
- *****************************************************************/
-
-#ifndef        TRUE
-#define        TRUE    1
-#endif
-
-#ifndef        FALSE
-#define        FALSE   0
-#endif
-
-
-/*****************************************************************
- *
  * List of I/O-addresses we try to auto-sense
  * Last element MUST BE 0!
  *****************************************************************/
@@ -218,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)
 {
@@ -262,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);
@@ -270,12 +255,12 @@ static inline void set_hsf(struct net_device *dev, int hsf)
        spin_unlock_irqrestore(&adapter->lock, flags);
 }
 
-static int start_receive(struct net_device *, pcb_struct *);
+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);
@@ -308,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));
@@ -328,34 +313,34 @@ static inline void check_3c505_dma(struct net_device *dev)
 }
 
 /* Primitive functions used by send_pcb() */
-static inline unsigned int send_pcb_slow(unsigned int base_addr, unsigned char byte)
+static inline bool send_pcb_slow(unsigned int base_addr, unsigned char byte)
 {
        unsigned long timeout;
        outb_command(byte, base_addr);
        for (timeout = jiffies + 5*HZ/100; time_before(jiffies, timeout);) {
                if (inb_status(base_addr) & HCRE)
-                       return FALSE;
+                       return false;
        }
        printk(KERN_WARNING "3c505: send_pcb_slow timed out\n");
-       return TRUE;
+       return true;
 }
 
-static inline unsigned int send_pcb_fast(unsigned int base_addr, unsigned char byte)
+static inline bool send_pcb_fast(unsigned int base_addr, unsigned char byte)
 {
        unsigned int timeout;
        outb_command(byte, base_addr);
        for (timeout = 0; timeout < 40000; timeout++) {
                if (inb_status(base_addr) & HCRE)
-                       return FALSE;
+                       return false;
        }
        printk(KERN_WARNING "3c505: send_pcb_fast timed out\n");
-       return TRUE;
+       return true;
 }
 
 /* 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;
@@ -386,24 +371,24 @@ static inline void prime_rx(struct net_device *dev)
  * timeout is reduced to 500us).
  */
 
-static int send_pcb(struct net_device *dev, pcb_struct * pcb)
+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);
 
        if (adapter->dmaing && adapter->current_dma.direction == 0)
-               return FALSE;
+               return false;
 
        /* Avoid contention */
        if (test_and_set_bit(1, &adapter->send_pcb_semaphore)) {
                if (elp_debug >= 3) {
                        printk(KERN_DEBUG "%s: send_pcb entered while threaded\n", dev->name);
                }
-               return FALSE;
+               return false;
        }
        /*
         * load each byte into the command register and
@@ -435,7 +420,7 @@ static int send_pcb(struct net_device *dev, pcb_struct * pcb)
                switch (GET_ASF(dev->base_addr)) {
                case ASF_PCB_ACK:
                        adapter->send_pcb_semaphore = 0;
-                       return TRUE;
+                       return true;
 
                case ASF_PCB_NAK:
 #ifdef ELP_DEBUG
@@ -453,7 +438,7 @@ static int send_pcb(struct net_device *dev, pcb_struct * pcb)
        spin_unlock_irqrestore(&adapter->lock, flags);
       abort:
        adapter->send_pcb_semaphore = 0;
-       return FALSE;
+       return false;
 }
 
 
@@ -470,7 +455,7 @@ static int send_pcb(struct net_device *dev, pcb_struct * pcb)
  *
  *****************************************************************/
 
-static int receive_pcb(struct net_device *dev, pcb_struct * pcb)
+static bool receive_pcb(struct net_device *dev, pcb_struct * pcb)
 {
        int i, j;
        int total_length;
@@ -478,7 +463,7 @@ static int 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);
 
@@ -487,7 +472,7 @@ static int receive_pcb(struct net_device *dev, pcb_struct * pcb)
        while (((stat = get_status(dev->base_addr)) & ACRF) == 0 && time_before(jiffies, timeout));
        if (time_after_eq(jiffies, timeout)) {
                TIMEOUT_MSG(__LINE__);
-               return FALSE;
+               return false;
        }
        pcb->command = inb_command(dev->base_addr);
 
@@ -497,39 +482,45 @@ static int receive_pcb(struct net_device *dev, pcb_struct * pcb)
        if (time_after_eq(jiffies, timeout)) {
                TIMEOUT_MSG(__LINE__);
                printk(KERN_INFO "%s: status %02x\n", dev->name, stat);
-               return FALSE;
+               return false;
        }
        pcb->length = inb_command(dev->base_addr);
 
        if (pcb->length > MAX_PCB_DATA) {
                INVALID_PCB_MSG(pcb->length);
                adapter_reset(dev);
-               return FALSE;
+               return false;
        }
        /* read the data */
        spin_lock_irqsave(&adapter->lock, flags);
-       i = 0;
-       do {
-               j = 0;
-               while (((stat = get_status(dev->base_addr)) & ACRF) == 0 && j++ < 20000);
-               pcb->data.raw[i++] = inb_command(dev->base_addr);
-               if (i > MAX_PCB_DATA)
-                       INVALID_PCB_MSG(i);
-       } while ((stat & ASF_PCB_MASK) != ASF_PCB_END && j < 20000);
+       for (i = 0; i < MAX_PCB_DATA; i++) {
+               for (j = 0; j < 20000; j++) {
+                       stat = get_status(dev->base_addr);
+                       if (stat & ACRF)
+                               break;
+               }
+               pcb->data.raw[i] = inb_command(dev->base_addr);
+               if ((stat & ASF_PCB_MASK) == ASF_PCB_END || j >= 20000)
+                       break;
+       }
        spin_unlock_irqrestore(&adapter->lock, flags);
+       if (i >= MAX_PCB_DATA) {
+               INVALID_PCB_MSG(i);
+               return false;
+       }
        if (j >= 20000) {
                TIMEOUT_MSG(__LINE__);
-               return FALSE;
+               return false;
        }
-       /* woops, the last "data" byte was really the length! */
-       total_length = pcb->data.raw[--i];
+       /* the last "data" byte was really the length! */
+       total_length = pcb->data.raw[i];
 
        /* safety check total length vs data length */
        if (total_length != (pcb->length + 2)) {
                if (elp_debug >= 2)
                        printk(KERN_WARNING "%s: mangled PCB received\n", dev->name);
                set_hsf(dev, HSF_PCB_NAK);
-               return FALSE;
+               return false;
        }
 
        if (pcb->command == CMD_RECEIVE_PACKET_COMPLETE) {
@@ -538,14 +529,14 @@ static int receive_pcb(struct net_device *dev, pcb_struct * pcb)
                                set_hsf(dev, HSF_PCB_NAK);
                                printk(KERN_WARNING "%s: PCB rejected, transfer in progress and backlog full\n", dev->name);
                                pcb->command = 0;
-                               return TRUE;
+                               return true;
                        } else {
                                pcb->command = 0xff;
                        }
                }
        }
        set_hsf(dev, HSF_PCB_ACK);
-       return TRUE;
+       return true;
 }
 
 /******************************************************
@@ -555,10 +546,10 @@ static int receive_pcb(struct net_device *dev, pcb_struct * pcb)
  *
  ******************************************************/
 
-static int start_receive(struct net_device *dev, pcb_struct * tx_pcb)
+static bool start_receive(struct net_device *dev, pcb_struct * tx_pcb)
 {
-       int status;
-       elp_device *adapter = dev->priv;
+       bool status;
+       elp_device *adapter = netdev_priv(dev);
 
        if (elp_debug >= 3)
                printk(KERN_DEBUG "%s: restarting receiver\n", dev->name);
@@ -586,7 +577,7 @@ static int 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;
@@ -615,7 +606,6 @@ static void receive_packet(struct net_device *dev, int len)
        if (test_and_set_bit(0, (void *) &adapter->dmaing))
                printk(KERN_ERR "%s: rx blocked, DMA in progress, dir %d\n", dev->name, adapter->current_dma.direction);
 
-       skb->dev = dev;
        adapter->current_dma.direction = 0;
        adapter->current_dma.length = rlen;
        adapter->current_dma.skb = skb;
@@ -649,18 +639,15 @@ static void receive_packet(struct net_device *dev, int len)
  *
  ******************************************************/
 
-static irqreturn_t elp_interrupt(int irq, void *dev_id, struct pt_regs *reg_ptr)
+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 {
@@ -686,9 +673,8 @@ static irqreturn_t elp_interrupt(int irq, void *dev_id, struct pt_regs *reg_ptr)
                                        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;
@@ -789,12 +775,12 @@ static irqreturn_t elp_interrupt(int irq, void *dev_id, struct pt_regs *reg_ptr)
                                         * 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);
@@ -810,11 +796,11 @@ static irqreturn_t elp_interrupt(int irq, void *dev_id, struct pt_regs *reg_ptr)
                                                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;
                                        }
@@ -854,11 +840,9 @@ static irqreturn_t elp_interrupt(int irq, void *dev_id, struct pt_regs *reg_ptr)
 
 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);
 
@@ -985,9 +969,9 @@ static int elp_open(struct net_device *dev)
  *
  ******************************************************/
 
-static int send_packet(struct net_device *dev, struct sk_buff *skb)
+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;
 
@@ -999,10 +983,10 @@ static int send_packet(struct net_device *dev, struct sk_buff *skb)
        if (test_and_set_bit(0, (void *) &adapter->busy)) {
                if (elp_debug >= 2)
                        printk(KERN_DEBUG "%s: transmit blocked\n", dev->name);
-               return FALSE;
+               return false;
        }
 
-       adapter->stats.tx_bytes += nlen;
+       dev->stats.tx_bytes += nlen;
 
        /*
         * send the adapter a transmit packet command. Ignore segment and offset
@@ -1016,7 +1000,7 @@ static int send_packet(struct net_device *dev, struct sk_buff *skb)
 
        if (!send_pcb(dev, &adapter->tx_pcb)) {
                adapter->busy = 0;
-               return FALSE;
+               return false;
        }
        /* if this happens, we die */
        if (test_and_set_bit(0, (void *) &adapter->dmaing))
@@ -1026,7 +1010,7 @@ static int send_packet(struct net_device *dev, struct sk_buff *skb)
        adapter->current_dma.start_time = jiffies;
 
        if ((unsigned long)(skb->data + nlen) >= MAX_DMA_ADDRESS || nlen != skb->len) {
-               memcpy(adapter->dma_buffer, skb->data, nlen);
+               skb_copy_from_linear_data(skb, adapter->dma_buffer, nlen);
                memset(adapter->dma_buffer+skb->len, 0, nlen-skb->len);
                target = isa_virt_to_bus(adapter->dma_buffer);
        }
@@ -1048,7 +1032,7 @@ static int send_packet(struct net_device *dev, struct sk_buff *skb)
        if (elp_debug >= 3)
                printk(KERN_DEBUG "%s: DMA transfer started\n", dev->name);
 
-       return TRUE;
+       return true;
 }
 
 /*
@@ -1057,7 +1041,6 @@ static int 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);
@@ -1065,7 +1048,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);
 }
 
@@ -1079,7 +1062,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);
@@ -1121,7 +1104,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);
@@ -1129,7 +1112,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;
@@ -1142,12 +1125,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;
 }
 
 
@@ -1183,9 +1166,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);
@@ -1226,7 +1207,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;
@@ -1373,6 +1354,17 @@ static int __init elp_autodetect(struct net_device *dev)
        return 0;               /* Because of this, the layer above will return -ENODEV */
 }
 
+static const struct net_device_ops elp_netdev_ops = {
+       .ndo_open               = elp_open,
+       .ndo_stop               = elp_close,
+       .ndo_get_stats          = elp_get_stats,
+       .ndo_start_xmit         = elp_start_xmit,
+       .ndo_tx_timeout         = elp_timeout,
+       .ndo_set_multicast_list = elp_set_mc_list,
+       .ndo_change_mtu         = eth_change_mtu,
+       .ndo_set_mac_address    = eth_mac_addr,
+       .ndo_validate_addr      = eth_validate_addr,
+};
 
 /******************************************************
  *
@@ -1397,14 +1389,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
         */
@@ -1539,11 +1529,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
@@ -1580,16 +1569,10 @@ static int __init elplus_setup(struct net_device *dev)
                printk(KERN_ERR "%s: adapter configuration failed\n", dev->name);
        }
 
-       dev->open = elp_open;                           /* local */
-       dev->stop = elp_close;                          /* local */
-       dev->get_stats = elp_get_stats;                 /* local */
-       dev->hard_start_xmit = elp_start_xmit;          /* local */
-       dev->tx_timeout = elp_timeout;                  /* local */
+       dev->netdev_ops = &elp_netdev_ops;
        dev->watchdog_timeo = 10*HZ;
-       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);
@@ -1670,7 +1653,7 @@ int __init init_module(void)
        return 0;
 }
 
-void cleanup_module(void)
+void __exit cleanup_module(void)
 {
        int this_dev;