X-Git-Url: http://ftp.safe.ca/?a=blobdiff_plain;f=drivers%2Fnet%2Fpcmcia%2F3c574_cs.c;h=10ee106a161778d6a510adc9c065123a6784964c;hb=d7636e0b0769e0f4f437ff33168d723f86e7c080;hp=71fd41122c911f785ded502f1dcd41978ec3699c;hpb=44670d2b50efd2443c3810239d6ea3fd02f8ef64;p=safe%2Fjmp%2Flinux-2.6 diff --git a/drivers/net/pcmcia/3c574_cs.c b/drivers/net/pcmcia/3c574_cs.c index 71fd411..10ee106 100644 --- a/drivers/net/pcmcia/3c574_cs.c +++ b/drivers/net/pcmcia/3c574_cs.c @@ -85,6 +85,7 @@ earlier 3Com products. #include #include #include +#include #include #include @@ -92,7 +93,6 @@ earlier 3Com products. #include #include #include -#include #include #include @@ -117,14 +117,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 /*====================================================================*/ @@ -187,14 +179,16 @@ enum Window1 { enum Window3 { /* Window 3: MAC/config bits. */ Wn3_Config=0, Wn3_MAC_Ctrl=6, Wn3_Options=8, }; -union wn3_config { - int i; - struct w3_config_fields { - unsigned int ram_size:3, ram_width:1, ram_speed:2, rom_size:2; - int pad8:8; - unsigned int ram_split:2, pad18:2, xcvr:3, pad21:1, autoselect:1; - int pad24:7; - } u; +enum wn3_config { + Ram_size = 7, + Ram_width = 8, + Ram_speed = 0x30, + Rom_size = 0xc0, + Ram_split_shift = 16, + Ram_split = 3 << Ram_split_shift, + Xcvr_shift = 20, + Xcvr = 7 << Xcvr_shift, + Autoselect = 0x1000000, }; enum Window4 { /* Window 4: Xcvr/media bits. */ @@ -204,9 +198,7 @@ enum Window4 { /* Window 4: Xcvr/media bits. */ #define MEDIA_TP 0x00C0 /* Enable link beat and jabber for 10baseT. */ struct el3_private { - dev_link_t link; - dev_node_t node; - struct net_device_stats stats; + struct pcmcia_device *p_dev; u16 advertising, partner; /* NWay media advertisement */ unsigned char phys; /* MII device address */ unsigned int autoselect:1, default_media:3; /* Read from the EEPROM/Wn3_Config. */ @@ -225,102 +217,79 @@ static char mii_preamble_required = 0; /* Index of functions. */ -static void tc574_config(dev_link_t *link); -static void tc574_release(dev_link_t *link); -static int tc574_event(event_t event, int priority, - event_callback_args_t *args); +static int tc574_config(struct pcmcia_device *link); +static void tc574_release(struct pcmcia_device *link); -static void mdio_sync(kio_addr_t ioaddr, int bits); -static int mdio_read(kio_addr_t ioaddr, int phy_id, int location); -static void mdio_write(kio_addr_t ioaddr, int phy_id, int location, int value); -static unsigned short read_eeprom(kio_addr_t ioaddr, int index); +static void mdio_sync(unsigned int ioaddr, int bits); +static int mdio_read(unsigned int ioaddr, int phy_id, int location); +static void mdio_write(unsigned int ioaddr, int phy_id, int location, + int value); +static unsigned short read_eeprom(unsigned int ioaddr, int index); static void tc574_wait_for_completion(struct net_device *dev, int cmd); static void tc574_reset(struct net_device *dev); static void media_check(unsigned long arg); static int el3_open(struct net_device *dev); -static int el3_start_xmit(struct sk_buff *skb, struct net_device *dev); -static irqreturn_t el3_interrupt(int irq, void *dev_id, struct pt_regs *regs); +static netdev_tx_t el3_start_xmit(struct sk_buff *skb, + struct net_device *dev); +static irqreturn_t el3_interrupt(int irq, void *dev_id); static void update_stats(struct net_device *dev); static struct net_device_stats *el3_get_stats(struct net_device *dev); static int el3_rx(struct net_device *dev, int worklimit); static int el3_close(struct net_device *dev); static void el3_tx_timeout(struct net_device *dev); static int el3_ioctl(struct net_device *dev, struct ifreq *rq, int cmd); -static struct ethtool_ops netdev_ethtool_ops; +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 dev_info_t dev_info = "3c574_cs"; - -static dev_link_t *tc574_attach(void); -static void tc574_detach(dev_link_t *); - -static dev_link_t *dev_list; +static void tc574_detach(struct pcmcia_device *p_dev); /* tc574_attach() creates an "instance" of the driver, allocating local data structures for one device. The device is registered with Card Services. */ +static const struct net_device_ops el3_netdev_ops = { + .ndo_open = el3_open, + .ndo_stop = el3_close, + .ndo_start_xmit = el3_start_xmit, + .ndo_tx_timeout = el3_tx_timeout, + .ndo_get_stats = el3_get_stats, + .ndo_do_ioctl = el3_ioctl, + .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, +}; -static dev_link_t *tc574_attach(void) +static int tc574_probe(struct pcmcia_device *link) { struct el3_private *lp; - client_reg_t client_reg; - dev_link_t *link; struct net_device *dev; - int ret; - 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)); if (!dev) - return NULL; + return -ENOMEM; lp = netdev_priv(dev); - link = &lp->link; link->priv = dev; + lp->p_dev = link; spin_lock_init(&lp->window_lock); link->io.NumPorts1 = 32; link->io.Attributes1 = IO_DATA_PATH_WIDTH_16; - link->irq.Attributes = IRQ_TYPE_EXCLUSIVE | IRQ_HANDLE_PRESENT; - link->irq.IRQInfo1 = IRQ_LEVEL_ID; - link->irq.Handler = &el3_interrupt; - link->irq.Instance = dev; link->conf.Attributes = CONF_ENABLE_IRQ; - link->conf.Vcc = 50; link->conf.IntType = INT_MEMORY_AND_IO; link->conf.ConfigIndex = 1; - link->conf.Present = PRESENT_OPTION; - /* The EL3-specific entries in the device structure. */ - dev->hard_start_xmit = &el3_start_xmit; - dev->get_stats = &el3_get_stats; - dev->do_ioctl = &el3_ioctl; + dev->netdev_ops = &el3_netdev_ops; SET_ETHTOOL_OPS(dev, &netdev_ethtool_ops); - dev->set_multicast_list = &set_rx_mode; - dev->open = &el3_open; - dev->stop = &el3_close; -#ifdef HAVE_TX_TIMEOUT - dev->tx_timeout = el3_tx_timeout; dev->watchdog_timeo = TX_TIMEOUT; -#endif - - /* Register with Card Services */ - link->next = dev_list; - dev_list = link; - client_reg.dev_info = &dev_info; - client_reg.Version = 0x0210; - client_reg.event_callback_args.client_data = link; - ret = pcmcia_register_client(&link->handle, &client_reg); - if (ret != 0) { - cs_error(link->handle, RegisterClient, ret); - tc574_detach(link); - return NULL; - } - return link; + return tc574_config(link); } /* tc574_attach */ /* @@ -332,30 +301,16 @@ static dev_link_t *tc574_attach(void) */ -static void tc574_detach(dev_link_t *link) +static void tc574_detach(struct pcmcia_device *link) { struct net_device *dev = link->priv; - dev_link_t **linkp; - - DEBUG(0, "3c574_detach(0x%p)\n", link); - - /* Locate device structure */ - for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next) - if (*linkp == link) break; - if (*linkp == NULL) - return; - if (link->dev) - unregister_netdev(dev); + dev_dbg(&link->dev, "3c574_detach()\n"); - if (link->state & DEV_CONFIG) - tc574_release(link); + unregister_netdev(dev); - if (link->handle) - pcmcia_deregister_client(link->handle); + tc574_release(link); - /* Unlink device structure, free bits */ - *linkp = link->next; free_netdev(dev); } /* tc574_detach */ @@ -365,57 +320,43 @@ static void tc574_detach(dev_link_t *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 char *ram_split[] = {"5:3", "3:1", "1:1", "3:5"}; +static const char *ram_split[] = {"5:3", "3:1", "1:1", "3:5"}; -static void tc574_config(dev_link_t *link) +static int tc574_config(struct pcmcia_device *link) { - client_handle_t handle = link->handle; struct net_device *dev = link->priv; struct el3_private *lp = netdev_priv(dev); - tuple_t tuple; - cisparse_t parse; - unsigned short buf[32]; - int last_fn, last_ret, i, j; - kio_addr_t ioaddr; - u16 *phys_addr; + int ret, i, j; + unsigned int ioaddr; + __be16 *phys_addr; char *cardname; - union wn3_config config; - - phys_addr = (u16 *)dev->dev_addr; - - DEBUG(0, "3c574_config(0x%p)\n", link); + __u32 config; + u8 *buf; + size_t len; - tuple.Attributes = 0; - tuple.DesiredTuple = CISTPL_CONFIG; - CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); - tuple.TupleData = (cisdata_t *)buf; - tuple.TupleDataMax = 64; - tuple.TupleOffset = 0; - CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple)); - CS_CHECK(ParseTuple, pcmcia_parse_tuple(handle, &tuple, &parse)); - link->conf.ConfigBase = parse.config.base; - link->conf.Present = parse.config.rmask[0]; + phys_addr = (__be16 *)dev->dev_addr; - /* Configure card */ - link->state |= DEV_CONFIG; + dev_dbg(&link->dev, "3c574_config()\n"); link->io.IOAddrLines = 16; for (i = j = 0; j < 0x400; j += 0x20) { link->io.BasePort1 = j ^ 0x300; - i = pcmcia_request_io(link->handle, &link->io); - if (i == CS_SUCCESS) break; + i = pcmcia_request_io(link, &link->io); + if (i == 0) + break; } - if (i != CS_SUCCESS) { - cs_error(link->handle, RequestIO, i); + if (i != 0) goto failed; - } - CS_CHECK(RequestIRQ, pcmcia_request_irq(link->handle, &link->irq)); - CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link->handle, &link->conf)); - dev->irq = link->irq.AssignedIRQ; + ret = pcmcia_request_irq(link, el3_interrupt); + if (ret) + goto failed; + + ret = pcmcia_request_configuration(link, &link->conf); + if (ret) + goto failed; + + dev->irq = link->irq; dev->base_addr = link->io.BasePort1; ioaddr = dev->base_addr; @@ -423,27 +364,26 @@ static void tc574_config(dev_link_t *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.DesiredTuple = 0x88; - if (pcmcia_get_first_tuple(handle, &tuple) == CS_SUCCESS) { - pcmcia_get_tuple_data(handle, &tuple); + + len = pcmcia_get_tuple(link, 0x88, &buf); + if (buf && len >= 6) { for (i = 0; i < 3; i++) - phys_addr[i] = htons(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)); - if (phys_addr[0] == 0x6060) { + if (phys_addr[0] == htons(0x6060)) { printk(KERN_NOTICE "3c574_cs: IO port conflict at 0x%03lx" "-0x%03lx\n", dev->base_addr, dev->base_addr+15); goto failed; } } - tuple.DesiredTuple = CISTPL_VERS_1; - if (pcmcia_get_first_tuple(handle, &tuple) == CS_SUCCESS && - pcmcia_get_tuple_data(handle, &tuple) == CS_SUCCESS && - pcmcia_parse_tuple(handle, &tuple, &parse) == CS_SUCCESS) { - cardname = parse.version_1.str + parse.version_1.ofs[1]; - } else + if (link->prod_id[1]) + cardname = link->prod_id[1]; + else cardname = "3Com 3c574"; { @@ -453,9 +393,9 @@ static void tc574_config(dev_link_t *link) outw(0<<11, ioaddr + RunnerRdCtrl); printk(KERN_INFO " ASIC rev %d,", mcr>>3); EL3WINDOW(3); - config.i = inl(ioaddr + Wn3_Config); - lp->default_media = config.u.xcvr; - lp->autoselect = config.u.autoselect; + config = inl(ioaddr + Wn3_Config); + lp->default_media = (config & Xcvr) >> Xcvr_shift; + lp->autoselect = config & Autoselect ? 1 : 0; } init_timer(&lp->media); @@ -479,7 +419,8 @@ static void tc574_config(dev_link_t *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; @@ -500,33 +441,27 @@ static void tc574_config(dev_link_t *link) } } - link->state &= ~DEV_CONFIG_PENDING; - link->dev = &lp->node; - SET_NETDEV_DEV(dev, &handle_to_dev(handle)); + SET_NETDEV_DEV(dev, &link->dev); if (register_netdev(dev) != 0) { printk(KERN_NOTICE "3c574_cs: register_netdev() failed\n"); - link->dev = NULL; goto failed; } - strcpy(lp->node.dev_name, dev->name); - - printk(KERN_INFO "%s: %s at io %#3lx, irq %d, hw_addr ", - dev->name, cardname, dev->base_addr, dev->irq); - for (i = 0; i < 6; i++) - printk("%02X%s", dev->dev_addr[i], ((i<5) ? ":" : ".\n")); + printk(KERN_INFO "%s: %s at io %#3lx, irq %d, " + "hw_addr %pM.\n", + dev->name, cardname, dev->base_addr, dev->irq, + dev->dev_addr); printk(" %dK FIFO split %s Rx:Tx, %sMII interface.\n", - 8 << config.u.ram_size, ram_split[config.u.ram_split], - config.u.autoselect ? "autoselect " : ""); + 8 << config & Ram_size, + ram_split[(config & Ram_split) >> Ram_split_shift], + config & Autoselect ? "autoselect " : ""); - return; + return 0; -cs_failed: - cs_error(link->handle, last_fn, last_ret); failed: tc574_release(link); - return; + return -ENODEV; } /* tc574_config */ @@ -536,71 +471,36 @@ failed: still open, this will be postponed until it is closed. */ -static void tc574_release(dev_link_t *link) +static void tc574_release(struct pcmcia_device *link) { - DEBUG(0, "3c574_release(0x%p)\n", link); + pcmcia_disable_device(link); +} - pcmcia_release_configuration(link->handle); - pcmcia_release_io(link->handle, &link->io); - pcmcia_release_irq(link->handle, &link->irq); +static int tc574_suspend(struct pcmcia_device *link) +{ + struct net_device *dev = link->priv; - link->state &= ~DEV_CONFIG; -} + if (link->open) + netif_device_detach(dev); -/* - The card status event handler. Mostly, this schedules other - stuff to run after an event is received. A CARD_REMOVAL event - also sets some flags to discourage the net drivers from trying - to talk to the card any more. -*/ + return 0; +} -static int tc574_event(event_t event, int priority, - event_callback_args_t *args) +static int tc574_resume(struct pcmcia_device *link) { - dev_link_t *link = args->client_data; struct net_device *dev = link->priv; - DEBUG(1, "3c574_event(0x%06x)\n", event); - - switch (event) { - case CS_EVENT_CARD_REMOVAL: - link->state &= ~DEV_PRESENT; - if (link->state & DEV_CONFIG) - netif_device_detach(dev); - break; - case CS_EVENT_CARD_INSERTION: - link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; - tc574_config(link); - break; - case CS_EVENT_PM_SUSPEND: - link->state |= DEV_SUSPEND; - /* Fall through... */ - case CS_EVENT_RESET_PHYSICAL: - if (link->state & DEV_CONFIG) { - if (link->open) - netif_device_detach(dev); - pcmcia_release_configuration(link->handle); - } - break; - case CS_EVENT_PM_RESUME: - link->state &= ~DEV_SUSPEND; - /* Fall through... */ - case CS_EVENT_CARD_RESET: - if (link->state & DEV_CONFIG) { - pcmcia_request_configuration(link->handle, &link->conf); - if (link->open) { - tc574_reset(dev); - netif_device_attach(dev); - } - } - break; + if (link->open) { + tc574_reset(dev); + netif_device_attach(dev); } + return 0; -} /* tc574_event */ +} static void dump_status(struct net_device *dev) { - kio_addr_t ioaddr = dev->base_addr; + unsigned int ioaddr = dev->base_addr; EL3WINDOW(1); printk(KERN_INFO " irq status %04x, rx status %04x, tx status " "%02x, tx free %04x\n", inw(ioaddr+EL3_STATUS), @@ -629,7 +529,7 @@ static void tc574_wait_for_completion(struct net_device *dev, int cmd) /* Read a word from the EEPROM using the regular EEPROM access register. Assume that we are in register window zero. */ -static unsigned short read_eeprom(kio_addr_t ioaddr, int index) +static unsigned short read_eeprom(unsigned int ioaddr, int index) { int timer; outw(EEPROM_Read + index, ioaddr + Wn0EepromCmd); @@ -657,9 +557,9 @@ static unsigned short read_eeprom(kio_addr_t ioaddr, int index) /* Generate the preamble required for initial synchronization and a few older transceivers. */ -static void mdio_sync(kio_addr_t ioaddr, int bits) +static void mdio_sync(unsigned int ioaddr, int bits) { - kio_addr_t mdio_addr = ioaddr + Wn4_PhysicalMgmt; + unsigned int mdio_addr = ioaddr + Wn4_PhysicalMgmt; /* Establish sync by sending at least 32 logic ones. */ while (-- bits >= 0) { @@ -668,12 +568,12 @@ static void mdio_sync(kio_addr_t ioaddr, int bits) } } -static int mdio_read(kio_addr_t ioaddr, int phy_id, int location) +static int mdio_read(unsigned int ioaddr, int phy_id, int location) { int i; int read_cmd = (0xf6 << 10) | (phy_id << 5) | location; unsigned int retval = 0; - kio_addr_t mdio_addr = ioaddr + Wn4_PhysicalMgmt; + unsigned int mdio_addr = ioaddr + Wn4_PhysicalMgmt; if (mii_preamble_required) mdio_sync(ioaddr, 32); @@ -693,10 +593,10 @@ static int mdio_read(kio_addr_t ioaddr, int phy_id, int location) return (retval>>1) & 0xffff; } -static void mdio_write(kio_addr_t ioaddr, int phy_id, int location, int value) +static void mdio_write(unsigned int ioaddr, int phy_id, int location, int value) { int write_cmd = 0x50020000 | (phy_id << 23) | (location << 18) | value; - kio_addr_t mdio_addr = ioaddr + Wn4_PhysicalMgmt; + unsigned int mdio_addr = ioaddr + Wn4_PhysicalMgmt; int i; if (mii_preamble_required) @@ -713,8 +613,6 @@ static void mdio_write(kio_addr_t ioaddr, int phy_id, int location, int value) outw(MDIO_ENB_IN, mdio_addr); outw(MDIO_ENB_IN | MDIO_SHIFT_CLK, mdio_addr); } - - return; } /* Reset and restore all of the 3c574 registers. */ @@ -722,7 +620,7 @@ static void tc574_reset(struct net_device *dev) { struct el3_private *lp = netdev_priv(dev); int i; - kio_addr_t ioaddr = dev->base_addr; + unsigned int ioaddr = dev->base_addr; unsigned long flags; tc574_wait_for_completion(dev, TotalReset|0x10); @@ -780,7 +678,7 @@ static void tc574_reset(struct net_device *dev) mdio_write(ioaddr, lp->phys, 4, lp->advertising); if (!auto_polarity) { /* works for TDK 78Q2120 series MII's */ - int i = mdio_read(ioaddr, lp->phys, 16) | 0x20; + i = mdio_read(ioaddr, lp->phys, 16) | 0x20; mdio_write(ioaddr, lp->phys, 16, i); } @@ -803,9 +701,9 @@ static void tc574_reset(struct net_device *dev) static int el3_open(struct net_device *dev) { struct el3_private *lp = netdev_priv(dev); - dev_link_t *link = &lp->link; + struct pcmcia_device *link = lp->p_dev; - if (!DEV_OK(link)) + if (!pcmcia_dev_present(link)) return -ENODEV; link->open++; @@ -817,7 +715,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; @@ -825,13 +723,12 @@ static int el3_open(struct net_device *dev) static void el3_tx_timeout(struct net_device *dev) { - struct el3_private *lp = netdev_priv(dev); - kio_addr_t ioaddr = dev->base_addr; + unsigned int ioaddr = dev->base_addr; printk(KERN_NOTICE "%s: Transmit timed out!\n", dev->name); dump_status(dev); - lp->stats.tx_errors++; - dev->trans_start = jiffies; + dev->stats.tx_errors++; + dev->trans_start = jiffies; /* prevent tx timeout */ /* Issue TX_RESET and TX_START commands. */ tc574_wait_for_completion(dev, TxReset); outw(TxEnable, ioaddr + EL3_CMD); @@ -840,8 +737,7 @@ static void el3_tx_timeout(struct net_device *dev) static void pop_tx_status(struct net_device *dev) { - struct el3_private *lp = netdev_priv(dev); - kio_addr_t ioaddr = dev->base_addr; + unsigned int ioaddr = dev->base_addr; int i; /* Clear the Tx status stack. */ @@ -853,32 +749,36 @@ 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); - lp->stats.tx_aborted_errors++; + dev->stats.tx_aborted_errors++; } outb(0x00, ioaddr + TxStatus); /* Pop the status stack. */ } } -static int el3_start_xmit(struct sk_buff *skb, struct net_device *dev) +static netdev_tx_t el3_start_xmit(struct sk_buff *skb, + struct net_device *dev) { - kio_addr_t ioaddr = dev->base_addr; + unsigned int ioaddr = dev->base_addr; 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)); spin_lock_irqsave(&lp->window_lock, flags); + + dev->stats.tx_bytes += skb->len; + + /* Put out the doubleword header... */ outw(skb->len, ioaddr + TX_FIFO); outw(0, ioaddr + TX_FIFO); + /* ... and the packet rounded to a doubleword. */ outsl(ioaddr + TX_FIFO, skb->data, (skb->len+3)>>2); - dev->trans_start = jiffies; - /* TxFree appears only in Window 1, not offset 0x1c. */ if (inw(ioaddr + TxFree) <= 1536) { netif_stop_queue(dev); @@ -890,15 +790,15 @@ static int el3_start_xmit(struct sk_buff *skb, struct net_device *dev) pop_tx_status(dev); spin_unlock_irqrestore(&lp->window_lock, flags); dev_kfree_skb(skb); - return 0; + return NETDEV_TX_OK; } /* The EL3 interrupt handler. */ -static irqreturn_t el3_interrupt(int irq, void *dev_id, struct pt_regs *regs) +static irqreturn_t el3_interrupt(int irq, void *dev_id) { struct net_device *dev = (struct net_device *) dev_id; struct el3_private *lp = netdev_priv(dev); - kio_addr_t ioaddr; + unsigned int ioaddr; unsigned status; int work_budget = max_interrupt_work; int handled = 0; @@ -907,7 +807,7 @@ static irqreturn_t el3_interrupt(int irq, void *dev_id, struct pt_regs *regs) 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); @@ -916,7 +816,7 @@ static irqreturn_t el3_interrupt(int irq, void *dev_id, struct pt_regs *regs) (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; } @@ -926,7 +826,7 @@ static irqreturn_t el3_interrupt(int irq, void *dev_id, struct pt_regs *regs) 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); @@ -966,7 +866,7 @@ static irqreturn_t el3_interrupt(int irq, void *dev_id, struct pt_regs *regs) } 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); @@ -976,7 +876,7 @@ static irqreturn_t el3_interrupt(int irq, void *dev_id, struct pt_regs *regs) 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); @@ -992,7 +892,7 @@ static void media_check(unsigned long arg) { struct net_device *dev = (struct net_device *) arg; struct el3_private *lp = netdev_priv(dev); - kio_addr_t ioaddr = dev->base_addr; + unsigned int ioaddr = dev->base_addr; unsigned long flags; unsigned short /* cable, */ media, partner; @@ -1004,7 +904,11 @@ static void media_check(unsigned long arg) if ((inw(ioaddr + EL3_STATUS) & IntLatch) && (inb(ioaddr + Timer) == 0xff)) { if (!lp->fast_poll) printk(KERN_INFO "%s: interrupt(s) dropped!\n", dev->name); - el3_interrupt(dev->irq, lp, NULL); + + local_irq_save(flags); + el3_interrupt(dev->irq, dev); + local_irq_restore(flags); + lp->fast_poll = HZ; } if (lp->fast_poll) { @@ -1071,7 +975,7 @@ static struct net_device_stats *el3_get_stats(struct net_device *dev) update_stats(dev); spin_unlock_irqrestore(&lp->window_lock, flags); } - return &lp->stats; + return &dev->stats; } /* Update statistics. @@ -1080,11 +984,10 @@ static struct net_device_stats *el3_get_stats(struct net_device *dev) */ static void update_stats(struct net_device *dev) { - struct el3_private *lp = netdev_priv(dev); - kio_addr_t ioaddr = dev->base_addr; + 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; @@ -1092,15 +995,15 @@ static void update_stats(struct net_device *dev) /* Unlike the 3c509 we need not turn off stats updates while reading. */ /* Switch to the stats window, and read everything. */ EL3WINDOW(6); - lp->stats.tx_carrier_errors += inb(ioaddr + 0); - lp->stats.tx_heartbeat_errors += inb(ioaddr + 1); + dev->stats.tx_carrier_errors += inb(ioaddr + 0); + dev->stats.tx_heartbeat_errors += inb(ioaddr + 1); /* Multiple collisions. */ inb(ioaddr + 2); - lp->stats.collisions += inb(ioaddr + 3); - lp->stats.tx_window_errors += inb(ioaddr + 4); - lp->stats.rx_fifo_errors += inb(ioaddr + 5); - lp->stats.tx_packets += inb(ioaddr + 6); + dev->stats.collisions += inb(ioaddr + 3); + dev->stats.tx_window_errors += inb(ioaddr + 4); + dev->stats.rx_fifo_errors += inb(ioaddr + 5); + dev->stats.tx_packets += inb(ioaddr + 6); up = inb(ioaddr + 9); - lp->stats.tx_packets += (up&0x30) << 4; + dev->stats.tx_packets += (up&0x30) << 4; /* Rx packets */ inb(ioaddr + 7); /* Tx deferrals */ inb(ioaddr + 8); rx = inw(ioaddr + 10); @@ -1110,31 +1013,29 @@ static void update_stats(struct net_device *dev) /* BadSSD */ inb(ioaddr + 12); up = inb(ioaddr + 13); - lp->stats.tx_bytes += tx + ((up & 0xf0) << 12); - EL3WINDOW(1); } static int el3_rx(struct net_device *dev, int worklimit) { - struct el3_private *lp = netdev_priv(dev); - kio_addr_t ioaddr = dev->base_addr; + 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)) { + worklimit > 0) { + worklimit--; if (rx_status & 0x4000) { /* Error, update stats. */ short error = rx_status & 0x3800; - lp->stats.rx_errors++; + dev->stats.rx_errors++; switch (error) { - case 0x0000: lp->stats.rx_over_errors++; break; - case 0x0800: lp->stats.rx_length_errors++; break; - case 0x1000: lp->stats.rx_frame_errors++; break; - case 0x1800: lp->stats.rx_length_errors++; break; - case 0x2000: lp->stats.rx_frame_errors++; break; - case 0x2800: lp->stats.rx_crc_errors++; break; + case 0x0000: dev->stats.rx_over_errors++; break; + case 0x0800: dev->stats.rx_length_errors++; break; + case 0x1000: dev->stats.rx_frame_errors++; break; + case 0x1800: dev->stats.rx_length_errors++; break; + case 0x2000: dev->stats.rx_frame_errors++; break; + case 0x2800: dev->stats.rx_crc_errors++; break; } } else { short pkt_len = rx_status & 0x7ff; @@ -1142,22 +1043,20 @@ 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->dev = dev; skb_reserve(skb, 2); insl(ioaddr+RX_FIFO, skb_put(skb, pkt_len), ((pkt_len+3)>>2)); skb->protocol = eth_type_trans(skb, dev); netif_rx(skb); - dev->last_rx = jiffies; - lp->stats.rx_packets++; - lp->stats.rx_bytes += pkt_len; + 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); - lp->stats.rx_dropped++; + dev->stats.rx_dropped++; } } tc574_wait_for_completion(dev, RxDiscard); @@ -1172,7 +1071,7 @@ static void netdev_get_drvinfo(struct net_device *dev, strcpy(info->driver, "3c574_cs"); } -static struct ethtool_ops netdev_ethtool_ops = { +static const struct ethtool_ops netdev_ethtool_ops = { .get_drvinfo = netdev_get_drvinfo, }; @@ -1180,17 +1079,17 @@ static struct ethtool_ops netdev_ethtool_ops = { static int el3_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) { struct el3_private *lp = netdev_priv(dev); - kio_addr_t ioaddr = dev->base_addr; - u16 *data = (u16 *)&rq->ifr_ifru; + unsigned int ioaddr = dev->base_addr; + 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; @@ -1199,7 +1098,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; @@ -1209,12 +1109,11 @@ static int el3_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) int saved_window; unsigned long flags; - if (!capable(CAP_NET_ADMIN)) - return -EPERM; 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; @@ -1234,26 +1133,36 @@ static int el3_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) static void set_rx_mode(struct net_device *dev) { - kio_addr_t ioaddr = dev->base_addr; + unsigned int ioaddr = dev->base_addr; if (dev->flags & IFF_PROMISC) outw(SetRxFilter | RxStation | RxMulticast | RxBroadcast | RxProm, ioaddr + EL3_CMD); - else if (dev->mc_count || (dev->flags & IFF_ALLMULTI)) + else if (!netdev_mc_empty(dev) || (dev->flags & IFF_ALLMULTI)) outw(SetRxFilter|RxStation|RxMulticast|RxBroadcast, ioaddr + EL3_CMD); else 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) { - kio_addr_t ioaddr = dev->base_addr; + unsigned int ioaddr = dev->base_addr; struct el3_private *lp = netdev_priv(dev); - dev_link_t *link = &lp->link; + 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 (DEV_OK(link)) { + if (pcmcia_dev_present(link)) { unsigned long flags; /* Turn off statistics ASAP. We update lp->stats below. */ @@ -1282,7 +1191,7 @@ static int el3_close(struct net_device *dev) static struct pcmcia_device_id tc574_ids[] = { PCMCIA_DEVICE_MANF_CARD(0x0101, 0x0574), - PCMCIA_MFC_DEVICE_CIS_MANF_CARD(0, 0x0101, 0x0556, "3CCFEM556.cis"), + PCMCIA_MFC_DEVICE_CIS_MANF_CARD(0, 0x0101, 0x0556, "cis/3CCFEM556.cis"), PCMCIA_DEVICE_NULL, }; MODULE_DEVICE_TABLE(pcmcia, tc574_ids); @@ -1292,10 +1201,11 @@ static struct pcmcia_driver tc574_driver = { .drv = { .name = "3c574_cs", }, - .attach = tc574_attach, - .event = tc574_event, - .detach = tc574_detach, + .probe = tc574_probe, + .remove = tc574_detach, .id_table = tc574_ids, + .suspend = tc574_suspend, + .resume = tc574_resume, }; static int __init init_tc574(void) @@ -1306,7 +1216,6 @@ static int __init init_tc574(void) static void __exit exit_tc574(void) { pcmcia_unregister_driver(&tc574_driver); - BUG_ON(dev_list != NULL); } module_init(init_tc574);