CAN: add controller hardware name for Softing cards
[linux-2.6.git] / drivers / net / spider_net.c
index edc736e..cb6bcca 100644 (file)
@@ -31,6 +31,7 @@
 #include <linux/if_vlan.h>
 #include <linux/in.h>
 #include <linux/init.h>
+#include <linux/gfp.h>
 #include <linux/ioport.h>
 #include <linux/ip.h>
 #include <linux/kernel.h>
 #include <linux/device.h>
 #include <linux/pci.h>
 #include <linux/skbuff.h>
-#include <linux/slab.h>
 #include <linux/tcp.h>
 #include <linux/types.h>
 #include <linux/vmalloc.h>
 #include <linux/wait.h>
 #include <linux/workqueue.h>
-#include <asm/bitops.h>
+#include <linux/bitops.h>
 #include <asm/pci-bridge.h>
 #include <net/checksum.h>
 
@@ -57,6 +57,7 @@ MODULE_AUTHOR("Utz Bacher <utz.bacher@de.ibm.com> and Jens Osterkamp " \
 MODULE_DESCRIPTION("Spider Southbridge Gigabit Ethernet driver");
 MODULE_LICENSE("GPL");
 MODULE_VERSION(VERSION);
+MODULE_FIRMWARE(SPIDER_NET_FIRMWARE_NAME);
 
 static int rx_descriptors = SPIDER_NET_RX_DESCRIPTORS_DEFAULT;
 static int tx_descriptors = SPIDER_NET_TX_DESCRIPTORS_DEFAULT;
@@ -71,7 +72,7 @@ MODULE_PARM_DESC(tx_descriptors, "number of descriptors used " \
 
 char spider_net_driver_name[] = "spidernet";
 
-static struct pci_device_id spider_net_pci_tbl[] = {
+static DEFINE_PCI_DEVICE_TABLE(spider_net_pci_tbl) = {
        { PCI_VENDOR_ID_TOSHIBA_2, PCI_DEVICE_ID_TOSHIBA_SPIDER_NET,
          PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
        { 0, }
@@ -409,7 +410,7 @@ spider_net_free_rx_chain_contents(struct spider_net_card *card)
  * @card: card structure
  * @descr: descriptor to re-init
  *
- * Return 0 on succes, <0 on failure.
+ * Return 0 on success, <0 on failure.
  *
  * Allocates a new rx skb, iommu-maps it and attaches it to the
  * descriptor. Mark the descriptor as activated, ready-to-use.
@@ -452,7 +453,7 @@ spider_net_prepare_rx_descr(struct spider_net_card *card,
        /* iommu-map the skb */
        buf = pci_map_single(card->pdev, descr->skb->data,
                        SPIDER_NET_MAX_FRAME, PCI_DMA_FROMDEVICE);
-       if (pci_dma_mapping_error(buf)) {
+       if (pci_dma_mapping_error(card->pdev, buf)) {
                dev_kfree_skb_any(descr->skb);
                descr->skb = NULL;
                if (netif_msg_rx_err(card) && net_ratelimit())
@@ -473,7 +474,7 @@ spider_net_prepare_rx_descr(struct spider_net_card *card,
  * spider_net_enable_rxchtails - sets RX dmac chain tail addresses
  * @card: card structure
  *
- * spider_net_enable_rxchtails sets the RX DMAC chain tail adresses in the
+ * spider_net_enable_rxchtails sets the RX DMAC chain tail addresses in the
  * chip by writing to the appropriate register. DMA is enabled in
  * spider_net_enable_rxdmac.
  */
@@ -624,7 +625,7 @@ spider_net_get_multicast_hash(struct net_device *netdev, __u8 *addr)
 static void
 spider_net_set_multi(struct net_device *netdev)
 {
-       struct dev_mc_list *mc;
+       struct netdev_hw_addr *ha;
        u8 hash;
        int i;
        u32 reg;
@@ -645,8 +646,8 @@ spider_net_set_multi(struct net_device *netdev)
        hash = spider_net_get_multicast_hash(netdev, netdev->broadcast); */
        set_bit(0xfd, bitmask);
 
-       for (mc = netdev->mc_list; mc; mc = mc->next) {
-               hash = spider_net_get_multicast_hash(netdev, mc->dmi_addr);
+       netdev_for_each_mc_addr(ha, netdev) {
+               hash = spider_net_get_multicast_hash(netdev, ha->addr);
                set_bit(hash, bitmask);
        }
 
@@ -672,7 +673,6 @@ write_hash:
 /**
  * spider_net_prepare_tx_descr - fill tx descriptor with skb data
  * @card: card structure
- * @descr: descriptor structure to fill out
  * @skb: packet to use
  *
  * returns 0 on success, <0 on failure.
@@ -691,7 +691,7 @@ spider_net_prepare_tx_descr(struct spider_net_card *card,
        unsigned long flags;
 
        buf = pci_map_single(card->pdev, skb->data, skb->len, PCI_DMA_TODEVICE);
-       if (pci_dma_mapping_error(buf)) {
+       if (pci_dma_mapping_error(card->pdev, buf)) {
                if (netif_msg_tx_err(card) && net_ratelimit())
                        dev_err(&card->netdev->dev, "could not iommu-map packet (%p, %i). "
                                  "Dropping packet\n", skb->data, skb->len);
@@ -790,11 +790,12 @@ spider_net_set_low_watermark(struct spider_net_card *card)
  * spider_net_release_tx_chain releases the tx descriptors that spider has
  * finished with (if non-brutal) or simply release tx descriptors (if brutal).
  * If some other context is calling this function, we return 1 so that we're
- * scheduled again (if we were scheduled) and will not loose initiative.
+ * scheduled again (if we were scheduled) and will not lose initiative.
  */
 static int
 spider_net_release_tx_chain(struct spider_net_card *card, int brutal)
 {
+       struct net_device *dev = card->netdev;
        struct spider_net_descr_chain *chain = &card->tx_chain;
        struct spider_net_descr *descr;
        struct spider_net_hw_descr *hwdescr;
@@ -815,8 +816,8 @@ spider_net_release_tx_chain(struct spider_net_card *card, int brutal)
                status = spider_net_get_descr_status(hwdescr);
                switch (status) {
                case SPIDER_NET_DESCR_COMPLETE:
-                       card->netdev_stats.tx_packets++;
-                       card->netdev_stats.tx_bytes += descr->skb->len;
+                       dev->stats.tx_packets++;
+                       dev->stats.tx_bytes += descr->skb->len;
                        break;
 
                case SPIDER_NET_DESCR_CARDOWNED:
@@ -835,11 +836,11 @@ spider_net_release_tx_chain(struct spider_net_card *card, int brutal)
                        if (netif_msg_tx_err(card))
                                dev_err(&card->netdev->dev, "forcing end of tx descriptor "
                                       "with status x%02x\n", status);
-                       card->netdev_stats.tx_errors++;
+                       dev->stats.tx_errors++;
                        break;
 
                default:
-                       card->netdev_stats.tx_dropped++;
+                       dev->stats.tx_dropped++;
                        if (!brutal) {
                                spin_unlock_irqrestore(&chain->lock, flags);
                                return 1;
@@ -866,7 +867,6 @@ spider_net_release_tx_chain(struct spider_net_card *card, int brutal)
 /**
  * spider_net_kick_tx_dma - enables TX DMA processing
  * @card: card structure
- * @descr: descriptor address to enable TX processing at
  *
  * This routine will start the transmit DMA running if
  * it is not already running. This routine ned only be
@@ -919,7 +919,7 @@ spider_net_xmit(struct sk_buff *skb, struct net_device *netdev)
        spider_net_release_tx_chain(card, 0);
 
        if (spider_net_prepare_tx_descr(card, skb) != 0) {
-               card->netdev_stats.tx_dropped++;
+               netdev->stats.tx_dropped++;
                netif_stop_queue(netdev);
                return NETDEV_TX_BUSY;
        }
@@ -979,16 +979,12 @@ static void
 spider_net_pass_skb_up(struct spider_net_descr *descr,
                       struct spider_net_card *card)
 {
-       struct spider_net_hw_descr *hwdescr= descr->hwdescr;
-       struct sk_buff *skb;
-       struct net_device *netdev;
-       u32 data_status, data_error;
-
-       data_status = hwdescr->data_status;
-       data_error = hwdescr->data_error;
-       netdev = card->netdev;
+       struct spider_net_hw_descr *hwdescr = descr->hwdescr;
+       struct sk_buff *skb = descr->skb;
+       struct net_device *netdev = card->netdev;
+       u32 data_status = hwdescr->data_status;
+       u32 data_error = hwdescr->data_error;
 
-       skb = descr->skb;
        skb_put(skb, hwdescr->valid_size);
 
        /* the card seems to add 2 bytes of junk in front
@@ -1004,9 +1000,9 @@ spider_net_pass_skb_up(struct spider_net_descr *descr,
                     !(data_error & SPIDER_NET_DATA_ERR_CKSUM_MASK))
                        skb->ip_summed = CHECKSUM_UNNECESSARY;
                else
-                       skb->ip_summed = CHECKSUM_NONE;
+                       skb_checksum_none_assert(skb);
        } else
-               skb->ip_summed = CHECKSUM_NONE;
+               skb_checksum_none_assert(skb);
 
        if (data_status & SPIDER_NET_VLAN_PACKET) {
                /* further enhancements: HW-accel VLAN
@@ -1015,8 +1011,8 @@ spider_net_pass_skb_up(struct spider_net_descr *descr,
        }
 
        /* update netdevice statistics */
-       card->netdev_stats.rx_packets++;
-       card->netdev_stats.rx_bytes += skb->len;
+       netdev->stats.rx_packets++;
+       netdev->stats.rx_bytes += skb->len;
 
        /* pass skb up to stack */
        netif_receive_skb(skb);
@@ -1184,6 +1180,7 @@ static int spider_net_resync_tail_ptr(struct spider_net_card *card)
 static int
 spider_net_decode_one_descr(struct spider_net_card *card)
 {
+       struct net_device *dev = card->netdev;
        struct spider_net_descr_chain *chain = &card->rx_chain;
        struct spider_net_descr *descr = chain->tail;
        struct spider_net_hw_descr *hwdescr = descr->hwdescr;
@@ -1210,9 +1207,9 @@ spider_net_decode_one_descr(struct spider_net_card *card)
             (status == SPIDER_NET_DESCR_PROTECTION_ERROR) ||
             (status == SPIDER_NET_DESCR_FORCE_END) ) {
                if (netif_msg_rx_err(card))
-                       dev_err(&card->netdev->dev,
+                       dev_err(&dev->dev,
                               "dropping RX descriptor with state %d\n", status);
-               card->netdev_stats.rx_dropped++;
+               dev->stats.rx_dropped++;
                goto bad_desc;
        }
 
@@ -1281,7 +1278,6 @@ bad_desc:
 static int spider_net_poll(struct napi_struct *napi, int budget)
 {
        struct spider_net_card *card = container_of(napi, struct spider_net_card, napi);
-       struct net_device *netdev = card->netdev;
        int packets_done = 0;
 
        while (packets_done < budget) {
@@ -1306,7 +1302,7 @@ static int spider_net_poll(struct napi_struct *napi, int budget)
        /* if all packets are in the stack, enable interrupts and return 0 */
        /* if not, return 1 */
        if (packets_done < budget) {
-               netif_rx_complete(netdev, napi);
+               napi_complete(napi);
                spider_net_rx_irq_on(card);
                card->ignore_rx_ramfull = 0;
        }
@@ -1315,20 +1311,6 @@ static int spider_net_poll(struct napi_struct *napi, int budget)
 }
 
 /**
- * spider_net_get_stats - get interface statistics
- * @netdev: interface device structure
- *
- * returns the interface statistics residing in the spider_net_card struct
- */
-static struct net_device_stats *
-spider_net_get_stats(struct net_device *netdev)
-{
-       struct spider_net_card *card = netdev_priv(netdev);
-       struct net_device_stats *stats = &card->netdev_stats;
-       return stats;
-}
-
-/**
  * spider_net_change_mtu - changes the MTU of an interface
  * @netdev: interface device structure
  * @new_mtu: new MTU value
@@ -1415,6 +1397,8 @@ spider_net_link_reset(struct net_device *netdev)
        spider_net_write_reg(card, SPIDER_NET_GMACINTEN, 0);
 
        /* reset phy and setup aneg */
+       card->aneg_count = 0;
+       card->medium = BCM54XX_COPPER;
        spider_net_setup_aneg(card);
        mod_timer(&card->aneg_timer, jiffies + SPIDER_NET_ANEG_TIMER);
 
@@ -1429,18 +1413,12 @@ spider_net_link_reset(struct net_device *netdev)
  * found when an interrupt is presented
  */
 static void
-spider_net_handle_error_irq(struct spider_net_card *card, u32 status_reg)
+spider_net_handle_error_irq(struct spider_net_card *card, u32 status_reg,
+                           u32 error_reg1, u32 error_reg2)
 {
-       u32 error_reg1, error_reg2;
        u32 i;
        int show_error = 1;
 
-       error_reg1 = spider_net_read_reg(card, SPIDER_NET_GHIINT1STS);
-       error_reg2 = spider_net_read_reg(card, SPIDER_NET_GHIINT2STS);
-
-       error_reg1 &= SPIDER_NET_INT1_MASK_VALUE;
-       error_reg2 &= SPIDER_NET_INT2_MASK_VALUE;
-
        /* check GHIINT0STS ************************************/
        if (status_reg)
                for (i = 0; i < 32; i++)
@@ -1551,8 +1529,7 @@ spider_net_handle_error_irq(struct spider_net_card *card, u32 status_reg)
                        spider_net_refill_rx_chain(card);
                        spider_net_enable_rxdmac(card);
                        card->num_rx_ints ++;
-                       netif_rx_schedule(card->netdev,
-                                         &card->napi);
+                       napi_schedule(&card->napi);
                }
                show_error = 0;
                break;
@@ -1572,8 +1549,7 @@ spider_net_handle_error_irq(struct spider_net_card *card, u32 status_reg)
                spider_net_refill_rx_chain(card);
                spider_net_enable_rxdmac(card);
                card->num_rx_ints ++;
-               netif_rx_schedule(card->netdev,
-                                 &card->napi);
+               napi_schedule(&card->napi);
                show_error = 0;
                break;
 
@@ -1587,8 +1563,7 @@ spider_net_handle_error_irq(struct spider_net_card *card, u32 status_reg)
                spider_net_refill_rx_chain(card);
                spider_net_enable_rxdmac(card);
                card->num_rx_ints ++;
-               netif_rx_schedule(card->netdev,
-                                 &card->napi);
+               napi_schedule(&card->napi);
                show_error = 0;
                break;
 
@@ -1655,9 +1630,8 @@ spider_net_handle_error_irq(struct spider_net_card *card, u32 status_reg)
 
 /**
  * spider_net_interrupt - interrupt handler for spider_net
- * @irq: interupt number
+ * @irq: interrupt number
  * @ptr: pointer to net_device
- * @regs: PU registers
  *
  * returns IRQ_HANDLED, if interrupt was for driver, or IRQ_NONE, if no
  * interrupt found raised by card.
@@ -1670,27 +1644,31 @@ spider_net_interrupt(int irq, void *ptr)
 {
        struct net_device *netdev = ptr;
        struct spider_net_card *card = netdev_priv(netdev);
-       u32 status_reg;
+       u32 status_reg, error_reg1, error_reg2;
 
        status_reg = spider_net_read_reg(card, SPIDER_NET_GHIINT0STS);
-       status_reg &= SPIDER_NET_INT0_MASK_VALUE;
+       error_reg1 = spider_net_read_reg(card, SPIDER_NET_GHIINT1STS);
+       error_reg2 = spider_net_read_reg(card, SPIDER_NET_GHIINT2STS);
 
-       if (!status_reg)
+       if (!(status_reg & SPIDER_NET_INT0_MASK_VALUE) &&
+           !(error_reg1 & SPIDER_NET_INT1_MASK_VALUE) &&
+           !(error_reg2 & SPIDER_NET_INT2_MASK_VALUE))
                return IRQ_NONE;
 
        if (status_reg & SPIDER_NET_RXINT ) {
                spider_net_rx_irq_off(card);
-               netif_rx_schedule(netdev, &card->napi);
+               napi_schedule(&card->napi);
                card->num_rx_ints ++;
        }
        if (status_reg & SPIDER_NET_TXINT)
-               netif_rx_schedule(netdev, &card->napi);
+               napi_schedule(&card->napi);
 
        if (status_reg & SPIDER_NET_LINKINT)
                spider_net_link_reset(netdev);
 
        if (status_reg & SPIDER_NET_ERRINT )
-               spider_net_handle_error_irq(card, status_reg);
+               spider_net_handle_error_irq(card, status_reg,
+                                           error_reg1, error_reg2);
 
        /* clear interrupt sources */
        spider_net_write_reg(card, SPIDER_NET_GHIINT0STS, status_reg);
@@ -1720,7 +1698,7 @@ spider_net_poll_controller(struct net_device *netdev)
  *
  * spider_net_enable_interrupt enables several interrupts
  */
-static void 
+static void
 spider_net_enable_interrupts(struct spider_net_card *card)
 {
        spider_net_write_reg(card, SPIDER_NET_GHIINT0MSK,
@@ -1737,7 +1715,7 @@ spider_net_enable_interrupts(struct spider_net_card *card)
  *
  * spider_net_disable_interrupts disables all the interrupts
  */
-static void 
+static void
 spider_net_disable_interrupts(struct spider_net_card *card)
 {
        spider_net_write_reg(card, SPIDER_NET_GHIINT0MSK, 0);
@@ -1842,7 +1820,7 @@ spider_net_enable_card(struct spider_net_card *card)
 
        spider_net_write_reg(card, SPIDER_NET_ECMODE, SPIDER_NET_ECMODE_VALUE);
 
-       /* set chain tail adress for RX chains and
+       /* set chain tail address for RX chains and
         * enable DMA */
        spider_net_enable_rxchtails(card);
        spider_net_enable_rxdmac(card);
@@ -1998,6 +1976,8 @@ spider_net_open(struct net_device *netdev)
                goto init_firmware_failed;
 
        /* start probing with copper */
+       card->aneg_count = 0;
+       card->medium = BCM54XX_COPPER;
        spider_net_setup_aneg(card);
        if (card->phy.def->phy_id)
                mod_timer(&card->aneg_timer, jiffies + SPIDER_NET_ANEG_TIMER);
@@ -2059,7 +2039,8 @@ static void spider_net_link_phy(unsigned long data)
        /* if link didn't come up after SPIDER_NET_ANEG_TIMEOUT tries, setup phy again */
        if (card->aneg_count > SPIDER_NET_ANEG_TIMEOUT) {
 
-               pr_info("%s: link is down trying to bring it up\n", card->netdev->name);
+               pr_debug("%s: link is down trying to bring it up\n",
+                        card->netdev->name);
 
                switch (card->medium) {
                case BCM54XX_COPPER:
@@ -2110,11 +2091,10 @@ static void spider_net_link_phy(unsigned long data)
 
        card->aneg_count = 0;
 
-       pr_debug("Found %s with %i Mbps, %s-duplex %sautoneg.\n",
-               phy->def->name, phy->speed, phy->duplex==1 ? "Full" : "Half",
-               phy->autoneg==1 ? "" : "no ");
-
-       return;
+       pr_info("%s: link up, %i Mbps, %s-duplex %sautoneg.\n",
+               card->netdev->name, phy->speed,
+               phy->duplex == 1 ? "Full" : "Half",
+               phy->autoneg == 1 ? "" : "no ");
 }
 
 /**
@@ -2278,6 +2258,23 @@ spider_net_tx_timeout(struct net_device *netdev)
        card->spider_stats.tx_timeouts++;
 }
 
+static const struct net_device_ops spider_net_ops = {
+       .ndo_open               = spider_net_open,
+       .ndo_stop               = spider_net_stop,
+       .ndo_start_xmit         = spider_net_xmit,
+       .ndo_set_multicast_list = spider_net_set_multi,
+       .ndo_set_mac_address    = spider_net_set_mac,
+       .ndo_change_mtu         = spider_net_change_mtu,
+       .ndo_do_ioctl           = spider_net_do_ioctl,
+       .ndo_tx_timeout         = spider_net_tx_timeout,
+       .ndo_validate_addr      = eth_validate_addr,
+       /* HW VLAN */
+#ifdef CONFIG_NET_POLL_CONTROLLER
+       /* poll controller */
+       .ndo_poll_controller    = spider_net_poll_controller,
+#endif /* CONFIG_NET_POLL_CONTROLLER */
+};
+
 /**
  * spider_net_setup_netdev_ops - initialization of net_device operations
  * @netdev: net_device structure
@@ -2287,22 +2284,8 @@ spider_net_tx_timeout(struct net_device *netdev)
 static void
 spider_net_setup_netdev_ops(struct net_device *netdev)
 {
-       netdev->open = &spider_net_open;
-       netdev->stop = &spider_net_stop;
-       netdev->hard_start_xmit = &spider_net_xmit;
-       netdev->get_stats = &spider_net_get_stats;
-       netdev->set_multicast_list = &spider_net_set_multi;
-       netdev->set_mac_address = &spider_net_set_mac;
-       netdev->change_mtu = &spider_net_change_mtu;
-       netdev->do_ioctl = &spider_net_do_ioctl;
-       /* tx watchdog */
-       netdev->tx_timeout = &spider_net_tx_timeout;
+       netdev->netdev_ops = &spider_net_ops;
        netdev->watchdog_timeo = SPIDER_NET_WATCHDOG_TIMEOUT;
-       /* HW VLAN */
-#ifdef CONFIG_NET_POLL_CONTROLLER
-       /* poll controller */
-       netdev->poll_controller = &spider_net_poll_controller;
-#endif /* CONFIG_NET_POLL_CONTROLLER */
        /* ethtool ops */
        netdev->ethtool_ops = &spider_net_ethtool_ops;
 }
@@ -2432,7 +2415,6 @@ spider_net_undo_pci_setup(struct spider_net_card *card)
 
 /**
  * spider_net_setup_pci_dev - sets up the device in terms of PCI operations
- * @card: card structure
  * @pdev: PCI device
  *
  * Returns the card structure or NULL if any errors occur