b43: N-PHY: partly implement SPUR workaround
[safe/jmp/linux-2.6] / drivers / net / pcmcia / 3c574_cs.c
index d836af1..17a2722 100644 (file)
@@ -85,6 +85,7 @@ earlier 3Com products.
 #include <linux/ioport.h>
 #include <linux/ethtool.h>
 #include <linux/bitops.h>
+#include <linux/mii.h>
 
 #include <pcmcia/cs_types.h>
 #include <pcmcia/cs.h>
@@ -117,14 +118,6 @@ INT_MODULE_PARM(full_duplex, 0);
 /* Autodetect link polarity reversal? */
 INT_MODULE_PARM(auto_polarity, 1);
 
-#ifdef PCMCIA_DEBUG
-INT_MODULE_PARM(pc_debug, PCMCIA_DEBUG);
-#define DEBUG(n, args...) if (pc_debug>(n)) printk(KERN_DEBUG args)
-static char *version =
-"3c574_cs.c 1.65ac1 2003/04/07 Donald Becker/David Hinds, becker@scyld.com.\n";
-#else
-#define DEBUG(n, args...)
-#endif
 
 /*====================================================================*/
 
@@ -250,6 +243,7 @@ static void el3_tx_timeout(struct net_device *dev);
 static int el3_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
 static const struct ethtool_ops netdev_ethtool_ops;
 static void set_rx_mode(struct net_device *dev);
+static void set_multicast_list(struct net_device *dev);
 
 static void tc574_detach(struct pcmcia_device *p_dev);
 
@@ -265,7 +259,7 @@ static const struct net_device_ops el3_netdev_ops = {
        .ndo_tx_timeout         = el3_tx_timeout,
        .ndo_get_stats          = el3_get_stats,
        .ndo_do_ioctl           = el3_ioctl,
-       .ndo_set_multicast_list = set_rx_mode,
+       .ndo_set_multicast_list = set_multicast_list,
        .ndo_change_mtu         = eth_change_mtu,
        .ndo_set_mac_address    = eth_mac_addr,
        .ndo_validate_addr      = eth_validate_addr,
@@ -276,7 +270,7 @@ static int tc574_probe(struct pcmcia_device *link)
        struct el3_private *lp;
        struct net_device *dev;
 
-       DEBUG(0, "3c574_attach()\n");
+       dev_dbg(&link->dev, "3c574_attach()\n");
 
        /* Create the PC card device object. */
        dev = alloc_etherdev(sizeof(struct el3_private));
@@ -289,10 +283,8 @@ static int tc574_probe(struct pcmcia_device *link)
        spin_lock_init(&lp->window_lock);
        link->io.NumPorts1 = 32;
        link->io.Attributes1 = IO_DATA_PATH_WIDTH_16;
-       link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING|IRQ_HANDLE_PRESENT;
-       link->irq.IRQInfo1 = IRQ_LEVEL_ID;
+       link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING;
        link->irq.Handler = &el3_interrupt;
-       link->irq.Instance = dev;
        link->conf.Attributes = CONF_ENABLE_IRQ;
        link->conf.IntType = INT_MEMORY_AND_IO;
        link->conf.ConfigIndex = 1;
@@ -317,7 +309,7 @@ static void tc574_detach(struct pcmcia_device *link)
 {
        struct net_device *dev = link->priv;
 
-       DEBUG(0, "3c574_detach(0x%p)\n", link);
+       dev_dbg(&link->dev, "3c574_detach()\n");
 
        if (link->dev_node)
                unregister_netdev(dev);
@@ -333,26 +325,23 @@ static void tc574_detach(struct pcmcia_device *link)
        ethernet device available to the system.
 */
 
-#define CS_CHECK(fn, ret) \
-  do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
-
 static const char *ram_split[] = {"5:3", "3:1", "1:1", "3:5"};
 
 static int tc574_config(struct pcmcia_device *link)
 {
        struct net_device *dev = link->priv;
        struct el3_private *lp = netdev_priv(dev);
-       tuple_t tuple;
-       __le16 buf[32];
-       int last_fn, last_ret, i, j;
+       int ret, i, j;
        unsigned int ioaddr;
        __be16 *phys_addr;
        char *cardname;
        __u32 config;
+       u8 *buf;
+       size_t len;
 
        phys_addr = (__be16 *)dev->dev_addr;
 
-       DEBUG(0, "3c574_config(0x%p)\n", link);
+       dev_dbg(&link->dev, "3c574_config()\n");
 
        link->io.IOAddrLines = 16;
        for (i = j = 0; j < 0x400; j += 0x20) {
@@ -361,12 +350,16 @@ static int tc574_config(struct pcmcia_device *link)
                if (i == 0)
                        break;
        }
-       if (i != 0) {
-               cs_error(link, RequestIO, i);
+       if (i != 0)
+               goto failed;
+
+       ret = pcmcia_request_irq(link, &link->irq);
+       if (ret)
+               goto failed;
+
+       ret = pcmcia_request_configuration(link, &link->conf);
+       if (ret)
                goto failed;
-       }
-       CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq));
-       CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf));
 
        dev->irq = link->irq.AssignedIRQ;
        dev->base_addr = link->io.BasePort1;
@@ -376,16 +369,14 @@ static int tc574_config(struct pcmcia_device *link)
        /* The 3c574 normally uses an EEPROM for configuration info, including
           the hardware address.  The future products may include a modem chip
           and put the address in the CIS. */
-       tuple.Attributes = 0;
-       tuple.TupleData = (cisdata_t *)buf;
-       tuple.TupleDataMax = 64;
-       tuple.TupleOffset = 0;
-       tuple.DesiredTuple = 0x88;
-       if (pcmcia_get_first_tuple(link, &tuple) == 0) {
-               pcmcia_get_tuple_data(link, &tuple);
+
+       len = pcmcia_get_tuple(link, 0x88, &buf);
+       if (buf && len >= 6) {
                for (i = 0; i < 3; i++)
-                       phys_addr[i] = htons(le16_to_cpu(buf[i]));
+                       phys_addr[i] = htons(le16_to_cpu(buf[i * 2]));
+               kfree(buf);
        } else {
+               kfree(buf); /* 0 < len < 6 */
                EL3WINDOW(0);
                for (i = 0; i < 3; i++)
                        phys_addr[i] = htons(read_eeprom(ioaddr, i + 10));
@@ -433,7 +424,8 @@ static int tc574_config(struct pcmcia_device *link)
                        mii_status = mdio_read(ioaddr, phy & 0x1f, 1);
                        if (mii_status != 0xffff) {
                                lp->phys = phy & 0x1f;
-                               DEBUG(0, "  MII transceiver at index %d, status %x.\n",
+                               dev_dbg(&link->dev, "  MII transceiver at "
+                                       "index %d, status %x.\n",
                                          phy, mii_status);
                                if ((mii_status & 0x0040) == 0)
                                        mii_preamble_required = 1;
@@ -455,7 +447,7 @@ static int tc574_config(struct pcmcia_device *link)
        }
 
        link->dev_node = &lp->node;
-       SET_NETDEV_DEV(dev, &handle_to_dev(link));
+       SET_NETDEV_DEV(dev, &link->dev);
 
        if (register_netdev(dev) != 0) {
                printk(KERN_NOTICE "3c574_cs: register_netdev() failed\n");
@@ -476,8 +468,6 @@ static int tc574_config(struct pcmcia_device *link)
 
        return 0;
 
-cs_failed:
-       cs_error(link, last_fn, last_ret);
 failed:
        tc574_release(link);
        return -ENODEV;
@@ -736,7 +726,7 @@ static int el3_open(struct net_device *dev)
        lp->media.expires = jiffies + HZ;
        add_timer(&lp->media);
        
-       DEBUG(2, "%s: opened, status %4.4x.\n",
+       dev_dbg(&link->dev, "%s: opened, status %4.4x.\n",
                  dev->name, inw(dev->base_addr + EL3_STATUS));
        
        return 0;
@@ -770,7 +760,7 @@ static void pop_tx_status(struct net_device *dev)
                if (tx_status & 0x30)
                        tc574_wait_for_completion(dev, TxReset);
                if (tx_status & 0x38) {
-                       DEBUG(1, "%s: transmit error: status 0x%02x\n",
+                       pr_debug("%s: transmit error: status 0x%02x\n",
                                  dev->name, tx_status);
                        outw(TxEnable, ioaddr + EL3_CMD);
                        dev->stats.tx_aborted_errors++;
@@ -786,7 +776,7 @@ static netdev_tx_t el3_start_xmit(struct sk_buff *skb,
        struct el3_private *lp = netdev_priv(dev);
        unsigned long flags;
 
-       DEBUG(3, "%s: el3_start_xmit(length = %ld) called, "
+       pr_debug("%s: el3_start_xmit(length = %ld) called, "
                  "status %4.4x.\n", dev->name, (long)skb->len,
                  inw(ioaddr + EL3_STATUS));
 
@@ -825,7 +815,7 @@ static irqreturn_t el3_interrupt(int irq, void *dev_id)
                return IRQ_NONE;
        ioaddr = dev->base_addr;
 
-       DEBUG(3, "%s: interrupt, status %4.4x.\n",
+       pr_debug("%s: interrupt, status %4.4x.\n",
                  dev->name, inw(ioaddr + EL3_STATUS));
 
        spin_lock(&lp->window_lock);
@@ -834,7 +824,7 @@ static irqreturn_t el3_interrupt(int irq, void *dev_id)
                   (IntLatch | RxComplete | RxEarly | StatsFull)) {
                if (!netif_device_present(dev) ||
                        ((status & 0xe000) != 0x2000)) {
-                       DEBUG(1, "%s: Interrupt from dead card\n", dev->name);
+                       pr_debug("%s: Interrupt from dead card\n", dev->name);
                        break;
                }
 
@@ -844,7 +834,7 @@ static irqreturn_t el3_interrupt(int irq, void *dev_id)
                        work_budget = el3_rx(dev, work_budget);
 
                if (status & TxAvailable) {
-                       DEBUG(3, "  TX room bit was handled.\n");
+                       pr_debug("  TX room bit was handled.\n");
                        /* There's room in the FIFO for a full-sized packet. */
                        outw(AckIntr | TxAvailable, ioaddr + EL3_CMD);
                        netif_wake_queue(dev);
@@ -884,7 +874,7 @@ static irqreturn_t el3_interrupt(int irq, void *dev_id)
                }
 
                if (--work_budget < 0) {
-                       DEBUG(0, "%s: Too much work in interrupt, "
+                       pr_debug("%s: Too much work in interrupt, "
                                  "status %4.4x.\n", dev->name, status);
                        /* Clear all interrupts */
                        outw(AckIntr | 0xFF, ioaddr + EL3_CMD);
@@ -894,7 +884,7 @@ static irqreturn_t el3_interrupt(int irq, void *dev_id)
                outw(AckIntr | IntReq | IntLatch, ioaddr + EL3_CMD);
        }
 
-       DEBUG(3, "%s: exiting interrupt, status %4.4x.\n",
+       pr_debug("%s: exiting interrupt, status %4.4x.\n",
                  dev->name, inw(ioaddr + EL3_STATUS));
                  
        spin_unlock(&lp->window_lock);
@@ -1001,7 +991,7 @@ static void update_stats(struct net_device *dev)
        unsigned int ioaddr = dev->base_addr;
        u8 rx, tx, up;
 
-       DEBUG(2, "%s: updating the statistics.\n", dev->name);
+       pr_debug("%s: updating the statistics.\n", dev->name);
 
        if (inw(ioaddr+EL3_STATUS) == 0xffff) /* No card. */
                return;
@@ -1037,7 +1027,7 @@ static int el3_rx(struct net_device *dev, int worklimit)
        unsigned int ioaddr = dev->base_addr;
        short rx_status;
        
-       DEBUG(3, "%s: in rx_packet(), status %4.4x, rx_status %4.4x.\n",
+       pr_debug("%s: in rx_packet(), status %4.4x, rx_status %4.4x.\n",
                  dev->name, inw(ioaddr+EL3_STATUS), inw(ioaddr+RxStatus));
        while (!((rx_status = inw(ioaddr + RxStatus)) & 0x8000) &&
                        worklimit > 0) {
@@ -1059,7 +1049,7 @@ static int el3_rx(struct net_device *dev, int worklimit)
 
                        skb = dev_alloc_skb(pkt_len+5);
 
-                       DEBUG(3, "  Receiving packet size %d status %4.4x.\n",
+                       pr_debug("  Receiving packet size %d status %4.4x.\n",
                                  pkt_len, rx_status);
                        if (skb != NULL) {
                                skb_reserve(skb, 2);
@@ -1070,7 +1060,7 @@ static int el3_rx(struct net_device *dev, int worklimit)
                                dev->stats.rx_packets++;
                                dev->stats.rx_bytes += pkt_len;
                        } else {
-                               DEBUG(1, "%s: couldn't allocate a sk_buff of"
+                               pr_debug("%s: couldn't allocate a sk_buff of"
                                          " size %d.\n", dev->name, pkt_len);
                                dev->stats.rx_dropped++;
                        }
@@ -1096,16 +1086,16 @@ static int el3_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
 {
        struct el3_private *lp = netdev_priv(dev);
        unsigned int ioaddr = dev->base_addr;
-       u16 *data = (u16 *)&rq->ifr_ifru;
+       struct mii_ioctl_data *data = if_mii(rq);
        int phy = lp->phys & 0x1f;
 
-       DEBUG(2, "%s: In ioct(%-.6s, %#4.4x) %4.4x %4.4x %4.4x %4.4x.\n",
+       pr_debug("%s: In ioct(%-.6s, %#4.4x) %4.4x %4.4x %4.4x %4.4x.\n",
                  dev->name, rq->ifr_ifrn.ifrn_name, cmd,
-                 data[0], data[1], data[2], data[3]);
+                 data->phy_id, data->reg_num, data->val_in, data->val_out);
 
        switch(cmd) {
        case SIOCGMIIPHY:               /* Get the address of the PHY in use. */
-               data[0] = phy;
+               data->phy_id = phy;
        case SIOCGMIIREG:               /* Read the specified MII register. */
                {
                        int saved_window;
@@ -1114,7 +1104,8 @@ static int el3_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
                        spin_lock_irqsave(&lp->window_lock, flags);
                        saved_window = inw(ioaddr + EL3_CMD) >> 13;
                        EL3WINDOW(4);
-                       data[3] = mdio_read(ioaddr, data[0] & 0x1f, data[1] & 0x1f);
+                       data->val_out = mdio_read(ioaddr, data->phy_id & 0x1f,
+                                                 data->reg_num & 0x1f);
                        EL3WINDOW(saved_window);
                        spin_unlock_irqrestore(&lp->window_lock, flags);
                        return 0;
@@ -1127,7 +1118,8 @@ static int el3_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
                        spin_lock_irqsave(&lp->window_lock, flags);
                        saved_window = inw(ioaddr + EL3_CMD) >> 13;
                        EL3WINDOW(4);
-                       mdio_write(ioaddr, data[0] & 0x1f, data[1] & 0x1f, data[2]);
+                       mdio_write(ioaddr, data->phy_id & 0x1f,
+                                  data->reg_num & 0x1f, data->val_in);
                        EL3WINDOW(saved_window);
                        spin_unlock_irqrestore(&lp->window_lock, flags);
                        return 0;
@@ -1158,13 +1150,23 @@ static void set_rx_mode(struct net_device *dev)
                outw(SetRxFilter | RxStation | RxBroadcast, ioaddr + EL3_CMD);
 }
 
+static void set_multicast_list(struct net_device *dev)
+{
+       struct el3_private *lp = netdev_priv(dev);
+       unsigned long flags;
+
+       spin_lock_irqsave(&lp->window_lock, flags);
+       set_rx_mode(dev);
+       spin_unlock_irqrestore(&lp->window_lock, flags);
+}
+
 static int el3_close(struct net_device *dev)
 {
        unsigned int ioaddr = dev->base_addr;
        struct el3_private *lp = netdev_priv(dev);
        struct pcmcia_device *link = lp->p_dev;
 
-       DEBUG(2, "%s: shutting down ethercard.\n", dev->name);
+       dev_dbg(&link->dev, "%s: shutting down ethercard.\n", dev->name);
        
        if (pcmcia_dev_present(link)) {
                unsigned long flags;