X-Git-Url: https://git.rohieb.name/openwrt.git/blobdiff_plain/b37fa14eed52fb77f6d6a5cac2c72b8c7916a6af..032de762b44791de7f35c3716046e441c4f2b1a1:/target/linux/ar7/files/drivers/net/cpmac.c diff --git a/target/linux/ar7/files/drivers/net/cpmac.c b/target/linux/ar7/files/drivers/net/cpmac.c index cb2fb4097..45bd1eeb8 100644 --- a/target/linux/ar7/files/drivers/net/cpmac.c +++ b/target/linux/ar7/files/drivers/net/cpmac.c @@ -37,30 +37,32 @@ #include #include #include +#include -MODULE_AUTHOR("Eugene Konev"); +MODULE_AUTHOR("Eugene Konev "); MODULE_DESCRIPTION("TI AR7 ethernet driver (CPMAC)"); MODULE_LICENSE("GPL"); -static int rx_ring_size = 64; -static int disable_napi; static int debug_level = 8; static int dumb_switch; -module_param(rx_ring_size, int, 0644); -module_param(disable_napi, int, 0644); /* Next 2 are only used in cpmac_probe, so it's pointless to change them */ module_param(debug_level, int, 0444); module_param(dumb_switch, int, 0444); -MODULE_PARM_DESC(rx_ring_size, "Size of rx ring (in skbs)"); -MODULE_PARM_DESC(disable_napi, "Disable NAPI polling"); MODULE_PARM_DESC(debug_level, "Number of NETIF_MSG bits to enable"); MODULE_PARM_DESC(dumb_switch, "Assume switch is not connected to MDIO bus"); +#define CPMAC_VERSION "0.5.0" +/* stolen from net/ieee80211.h */ +#ifndef MAC_FMT +#define MAC_FMT "%02x:%02x:%02x:%02x:%02x:%02x" +#define MAC_ARG(x) ((u8*)(x))[0], ((u8*)(x))[1], ((u8*)(x))[2], \ + ((u8*)(x))[3], ((u8*)(x))[4], ((u8*)(x))[5] +#endif /* frame size + 802.1q tag */ #define CPMAC_SKB_SIZE (ETH_FRAME_LEN + 4) -#define CPMAC_TX_RING_SIZE 8 +#define CPMAC_QUEUES 8 /* Ethernet registers */ #define CPMAC_TX_CONTROL 0x0004 @@ -195,26 +197,27 @@ struct cpmac_desc { }; struct cpmac_priv { - struct net_device_stats stats; spinlock_t lock; + spinlock_t rx_lock; struct cpmac_desc *rx_head; - int tx_head, tx_tail; + int ring_size; struct cpmac_desc *desc_ring; dma_addr_t dma_ring; void __iomem *regs; struct mii_bus *mii_bus; struct phy_device *phy; char phy_name[BUS_ID_SIZE]; - struct plat_cpmac_data *config; int oldlink, oldspeed, oldduplex; u32 msg_enable; struct net_device *dev; - struct work_struct alloc_work; + struct work_struct reset_work; + struct platform_device *pdev; + atomic_t reset_pending; }; static irqreturn_t cpmac_irq(int, void *); -static void cpmac_reset(struct net_device *dev); -static void cpmac_hw_init(struct net_device *dev); +static void cpmac_hw_start(struct net_device *dev); +static void cpmac_hw_stop(struct net_device *dev); static int cpmac_stop(struct net_device *dev); static int cpmac_open(struct net_device *dev); @@ -313,18 +316,6 @@ static int cpmac_config(struct net_device *dev, struct ifmap *map) return 0; } -static int cpmac_set_mac_address(struct net_device *dev, void *addr) -{ - struct sockaddr *sa = addr; - - if (dev->flags & IFF_UP) - return -EBUSY; - - memcpy(dev->dev_addr, sa->sa_data, dev->addr_len); - - return 0; -} - static void cpmac_set_multicast_list(struct net_device *dev) { struct dev_mc_list *iter; @@ -377,7 +368,6 @@ static struct sk_buff *cpmac_rx_one(struct net_device *dev, struct cpmac_priv *priv, struct cpmac_desc *desc) { - unsigned long flags; struct sk_buff *skb, *result = NULL; if (unlikely(netif_msg_hw(priv))) @@ -391,14 +381,13 @@ static struct sk_buff *cpmac_rx_one(struct net_device *dev, } skb = netdev_alloc_skb(dev, CPMAC_SKB_SIZE); - spin_lock_irqsave(&priv->lock, flags); if (likely(skb)) { skb_reserve(skb, 2); skb_put(desc->skb, desc->datalen); desc->skb->protocol = eth_type_trans(desc->skb, dev); desc->skb->ip_summed = CHECKSUM_NONE; - priv->stats.rx_packets++; - priv->stats.rx_bytes += desc->datalen; + dev->stats.rx_packets++; + dev->stats.rx_bytes += desc->datalen; result = desc->skb; dma_unmap_single(&dev->dev, desc->data_mapping, CPMAC_SKB_SIZE, DMA_FROM_DEVICE); @@ -415,9 +404,8 @@ static struct sk_buff *cpmac_rx_one(struct net_device *dev, if (netif_msg_rx_err(priv) && net_ratelimit()) printk(KERN_WARNING "%s: low on skbs, dropping packet\n", dev->name); - priv->stats.rx_dropped++; + dev->stats.rx_dropped++; } - spin_unlock_irqrestore(&priv->lock, flags); desc->buflen = CPMAC_SKB_SIZE; desc->dataflags = CPMAC_OWN; @@ -425,32 +413,6 @@ static struct sk_buff *cpmac_rx_one(struct net_device *dev, return result; } -static void cpmac_rx(struct net_device *dev) -{ - struct sk_buff *skb; - struct cpmac_desc *desc; - struct cpmac_priv *priv = netdev_priv(dev); - - spin_lock(&priv->lock); - if (unlikely(!priv->rx_head)) { - spin_unlock(&priv->lock); - return; - } - - desc = priv->rx_head; - - while ((desc->dataflags & CPMAC_OWN) == 0) { - skb = cpmac_rx_one(dev, priv, desc); - if (likely(skb)) - netif_rx(skb); - desc = desc->next; - } - - priv->rx_head = desc; - cpmac_write(priv->regs, CPMAC_RX_PTR(0), (u32)desc->mapping); - spin_unlock(&priv->lock); -} - static int cpmac_poll(struct net_device *dev, int *budget) { struct sk_buff *skb; @@ -458,6 +420,7 @@ static int cpmac_poll(struct net_device *dev, int *budget) int received = 0, quota = min(dev->quota, *budget); struct cpmac_priv *priv = netdev_priv(dev); + spin_lock(&priv->rx_lock); if (unlikely(!priv->rx_head)) { if (netif_msg_rx_err(priv) && net_ratelimit()) printk(KERN_WARNING "%s: rx: polling, but no queue\n", @@ -467,7 +430,6 @@ static int cpmac_poll(struct net_device *dev, int *budget) } desc = priv->rx_head; - while ((received < quota) && ((desc->dataflags & CPMAC_OWN) == 0)) { skb = cpmac_rx_one(dev, priv, desc); if (likely(skb)) { @@ -478,6 +440,7 @@ static int cpmac_poll(struct net_device *dev, int *budget) } priv->rx_head = desc; + spin_unlock(&priv->rx_lock); *budget -= received; dev->quota -= received; if (unlikely(netif_msg_rx_status(priv))) @@ -495,41 +458,35 @@ static int cpmac_poll(struct net_device *dev, int *budget) static int cpmac_start_xmit(struct sk_buff *skb, struct net_device *dev) { - unsigned long flags; - int channel, len; + int queue, len; struct cpmac_desc *desc; struct cpmac_priv *priv = netdev_priv(dev); - if (unlikely(skb_padto(skb, ETH_ZLEN))) { - if (netif_msg_tx_err(priv) && net_ratelimit()) - printk(KERN_WARNING"%s: tx: padding failed, dropping\n", - dev->name); - spin_lock_irqsave(&priv->lock, flags); - priv->stats.tx_dropped++; - spin_unlock_irqrestore(&priv->lock, flags); - return -ENOMEM; - } + if (unlikely(atomic_read(&priv->reset_pending))) + return NETDEV_TX_BUSY; + + if (unlikely(skb_padto(skb, ETH_ZLEN))) + return NETDEV_TX_OK; len = max(skb->len, ETH_ZLEN); - spin_lock_irqsave(&priv->lock, flags); - channel = priv->tx_tail++; - priv->tx_tail %= CPMAC_TX_RING_SIZE; - if (priv->tx_tail == priv->tx_head) - netif_stop_queue(dev); + queue = skb->queue_mapping; +#ifdef CONFIG_NETDEVICES_MULTIQUEUE + netif_stop_subqueue(dev, queue); +#else + netif_stop_queue(dev); +#endif - desc = &priv->desc_ring[channel]; - if (desc->dataflags & CPMAC_OWN) { + desc = &priv->desc_ring[queue]; + if (unlikely(desc->dataflags & CPMAC_OWN)) { if (netif_msg_tx_err(priv) && net_ratelimit()) - printk(KERN_WARNING "%s: tx dma ring full, dropping\n", + printk(KERN_WARNING "%s: tx dma ring full\n", dev->name); - priv->stats.tx_dropped++; - spin_unlock_irqrestore(&priv->lock, flags); - dev_kfree_skb_any(skb); - return -ENOMEM; + return NETDEV_TX_BUSY; } + spin_lock(&priv->lock); dev->trans_start = jiffies; - spin_unlock_irqrestore(&priv->lock, flags); + spin_unlock(&priv->lock); desc->dataflags = CPMAC_SOP | CPMAC_EOP | CPMAC_OWN; desc->skb = skb; desc->data_mapping = dma_map_single(&dev->dev, skb->data, len, @@ -544,22 +501,23 @@ static int cpmac_start_xmit(struct sk_buff *skb, struct net_device *dev) cpmac_dump_desc(dev, desc); if (unlikely(netif_msg_pktdata(priv))) cpmac_dump_skb(dev, skb); - cpmac_write(priv->regs, CPMAC_TX_PTR(channel), (u32)desc->mapping); + cpmac_write(priv->regs, CPMAC_TX_PTR(queue), (u32)desc->mapping); - return 0; + return NETDEV_TX_OK; } -static void cpmac_end_xmit(struct net_device *dev, int channel) +static void cpmac_end_xmit(struct net_device *dev, int queue) { struct cpmac_desc *desc; struct cpmac_priv *priv = netdev_priv(dev); - spin_lock(&priv->lock); - desc = &priv->desc_ring[channel]; - cpmac_write(priv->regs, CPMAC_TX_ACK(channel), (u32)desc->mapping); + desc = &priv->desc_ring[queue]; + cpmac_write(priv->regs, CPMAC_TX_ACK(queue), (u32)desc->mapping); if (likely(desc->skb)) { - priv->stats.tx_packets++; - priv->stats.tx_bytes += desc->skb->len; + spin_lock(&priv->lock); + dev->stats.tx_packets++; + dev->stats.tx_bytes += desc->skb->len; + spin_unlock(&priv->lock); dma_unmap_single(&dev->dev, desc->data_mapping, desc->skb->len, DMA_TO_DEVICE); @@ -568,21 +526,35 @@ static void cpmac_end_xmit(struct net_device *dev, int channel) desc->skb, desc->skb->len); dev_kfree_skb_irq(desc->skb); + desc->skb = NULL; +#ifdef CONFIG_NETDEVICES_MULTIQUEUE + if (netif_subqueue_stopped(dev, queue)) + netif_wake_subqueue(dev, queue); +#else if (netif_queue_stopped(dev)) netif_wake_queue(dev); - } else +#endif + } else { if (netif_msg_tx_err(priv) && net_ratelimit()) printk(KERN_WARNING "%s: end_xmit: spurious interrupt\n", dev->name); - spin_unlock(&priv->lock); +#ifdef CONFIG_NETDEVICES_MULTIQUEUE + if (netif_subqueue_stopped(dev, queue)) + netif_wake_subqueue(dev, queue); +#else + if (netif_queue_stopped(dev)) + netif_wake_queue(dev); +#endif + } } -static void cpmac_reset(struct net_device *dev) +static void cpmac_hw_stop(struct net_device *dev) { int i; struct cpmac_priv *priv = netdev_priv(dev); + struct plat_cpmac_data *pdata = priv->pdev->dev.platform_data; - ar7_device_reset(priv->config->reset_bit); + ar7_device_reset(pdata->reset_bit); cpmac_write(priv->regs, CPMAC_RX_CONTROL, cpmac_read(priv->regs, CPMAC_RX_CONTROL) & ~1); cpmac_write(priv->regs, CPMAC_TX_CONTROL, @@ -591,23 +563,64 @@ static void cpmac_reset(struct net_device *dev) cpmac_write(priv->regs, CPMAC_TX_PTR(i), 0); cpmac_write(priv->regs, CPMAC_RX_PTR(i), 0); } + cpmac_write(priv->regs, CPMAC_UNICAST_CLEAR, 0xff); + cpmac_write(priv->regs, CPMAC_RX_INT_CLEAR, 0xff); + cpmac_write(priv->regs, CPMAC_TX_INT_CLEAR, 0xff); + cpmac_write(priv->regs, CPMAC_MAC_INT_CLEAR, 0xff); cpmac_write(priv->regs, CPMAC_MAC_CONTROL, cpmac_read(priv->regs, CPMAC_MAC_CONTROL) & ~MAC_MII); } -static inline void cpmac_free_rx_ring(struct net_device *dev) +static void cpmac_hw_start(struct net_device *dev) { - struct cpmac_desc *desc; int i; struct cpmac_priv *priv = netdev_priv(dev); + struct plat_cpmac_data *pdata = priv->pdev->dev.platform_data; + + ar7_device_reset(pdata->reset_bit); + for (i = 0; i < 8; i++) { + cpmac_write(priv->regs, CPMAC_TX_PTR(i), 0); + cpmac_write(priv->regs, CPMAC_RX_PTR(i), 0); + } + cpmac_write(priv->regs, CPMAC_RX_PTR(0), priv->rx_head->mapping); + + cpmac_write(priv->regs, CPMAC_MBP, MBP_RXSHORT | MBP_RXBCAST | + MBP_RXMCAST); + cpmac_write(priv->regs, CPMAC_BUFFER_OFFSET, 0); + for (i = 0; i < 8; i++) + cpmac_write(priv->regs, CPMAC_MAC_ADDR_LO(i), dev->dev_addr[5]); + cpmac_write(priv->regs, CPMAC_MAC_ADDR_MID, dev->dev_addr[4]); + cpmac_write(priv->regs, CPMAC_MAC_ADDR_HI, dev->dev_addr[0] | + (dev->dev_addr[1] << 8) | (dev->dev_addr[2] << 16) | + (dev->dev_addr[3] << 24)); + cpmac_write(priv->regs, CPMAC_MAX_LENGTH, CPMAC_SKB_SIZE); + cpmac_write(priv->regs, CPMAC_UNICAST_CLEAR, 0xff); + cpmac_write(priv->regs, CPMAC_RX_INT_CLEAR, 0xff); + cpmac_write(priv->regs, CPMAC_TX_INT_CLEAR, 0xff); + cpmac_write(priv->regs, CPMAC_MAC_INT_CLEAR, 0xff); + cpmac_write(priv->regs, CPMAC_UNICAST_ENABLE, 1); + cpmac_write(priv->regs, CPMAC_RX_INT_ENABLE, 1); + cpmac_write(priv->regs, CPMAC_TX_INT_ENABLE, 0xff); + cpmac_write(priv->regs, CPMAC_MAC_INT_ENABLE, 3); + cpmac_write(priv->regs, CPMAC_RX_CONTROL, + cpmac_read(priv->regs, CPMAC_RX_CONTROL) | 1); + cpmac_write(priv->regs, CPMAC_TX_CONTROL, + cpmac_read(priv->regs, CPMAC_TX_CONTROL) | 1); + cpmac_write(priv->regs, CPMAC_MAC_CONTROL, + cpmac_read(priv->regs, CPMAC_MAC_CONTROL) | MAC_MII | + MAC_FDX); +} + +static void cpmac_clear_rx(struct net_device *dev) +{ + struct cpmac_priv *priv = netdev_priv(dev); + struct cpmac_desc *desc; + int i; if (unlikely(!priv->rx_head)) return; - desc = priv->rx_head; - - for (i = 0; i < rx_ring_size; i++) { - desc->buflen = CPMAC_SKB_SIZE; + for (i = 0; i < priv->ring_size; i++) { if ((desc->dataflags & CPMAC_OWN) == 0) { if (netif_msg_rx_err(priv) && net_ratelimit()) printk(KERN_WARNING "%s: packet dropped\n", @@ -615,16 +628,84 @@ static inline void cpmac_free_rx_ring(struct net_device *dev) if (unlikely(netif_msg_hw(priv))) cpmac_dump_desc(dev, desc); desc->dataflags = CPMAC_OWN; - priv->stats.rx_dropped++; + dev->stats.rx_dropped++; } desc = desc->next; } } +static void cpmac_clear_tx(struct net_device *dev) +{ + struct cpmac_priv *priv = netdev_priv(dev); + int i; + if (unlikely(!priv->desc_ring)) + return; + for (i = 0; i < CPMAC_QUEUES; i++) { + priv->desc_ring[i].dataflags = 0; + if (priv->desc_ring[i].skb) { + dev_kfree_skb_any(priv->desc_ring[i].skb); + priv->desc_ring[i].skb = NULL; + } + } +} + +static void cpmac_hw_error(struct work_struct *work) +{ + int i; + struct cpmac_priv *priv = + container_of(work, struct cpmac_priv, reset_work); + + spin_lock(&priv->rx_lock); + cpmac_clear_rx(priv->dev); + spin_unlock(&priv->rx_lock); + cpmac_clear_tx(priv->dev); + cpmac_hw_start(priv->dev); + barrier(); + atomic_dec(&priv->reset_pending); + + for (i = 0; i < CPMAC_QUEUES; i++) { + netif_wake_subqueue(priv->dev, i); + } + netif_wake_queue(priv->dev); +} + +static void cpmac_check_status(struct net_device *dev) +{ + struct cpmac_priv *priv = netdev_priv(dev); + + u32 macstatus = cpmac_read(priv->regs, CPMAC_MAC_STATUS); + int rx_channel = (macstatus >> 8) & 7; + int rx_code = (macstatus >> 12) & 15; + int tx_channel = (macstatus >> 16) & 7; + int tx_code = (macstatus >> 20) & 15; + + if (rx_code || tx_code) { + if (netif_msg_drv(priv) && net_ratelimit()) { + /* Can't find any documentation on what these error codes actually are. + * So just log them and hope.. + */ + if (rx_code) + printk(KERN_WARNING "%s: host error %d on rx channel %d (macstatus %08x), resetting\n", + dev->name, rx_code, rx_channel, macstatus); + if (tx_code) + printk(KERN_WARNING "%s: host error %d on tx channel %d (macstatus %08x), resetting\n", + dev->name, tx_code, tx_channel, macstatus); + } + + netif_stop_queue(dev); + cpmac_hw_stop(dev); + if (schedule_work(&priv->reset_work)) + atomic_inc(&priv->reset_pending); + if (unlikely(netif_msg_hw(priv))) + cpmac_dump_regs(dev); + } +} + static irqreturn_t cpmac_irq(int irq, void *dev_id) { struct net_device *dev = dev_id; struct cpmac_priv *priv; + int queue; u32 status; if (!dev) @@ -642,46 +723,40 @@ static irqreturn_t cpmac_irq(int irq, void *dev_id) cpmac_end_xmit(dev, (status & 7)); if (status & MAC_INT_RX) { - if (disable_napi) - cpmac_rx(dev); - else { - cpmac_write(priv->regs, CPMAC_RX_INT_CLEAR, 1); - netif_rx_schedule(dev); - } + queue = (status >> 8) & 7; + netif_rx_schedule(dev); + cpmac_write(priv->regs, CPMAC_RX_INT_CLEAR, 1 << queue); } cpmac_write(priv->regs, CPMAC_MAC_EOI_VECTOR, 0); - if (unlikely(status & (MAC_INT_HOST | MAC_INT_STATUS))) { - if (netif_msg_drv(priv) && net_ratelimit()) - printk(KERN_ERR "%s: hw error, resetting...\n", - dev->name); - if (unlikely(netif_msg_hw(priv))) - cpmac_dump_regs(dev); - spin_lock(&priv->lock); - phy_stop(priv->phy); - cpmac_reset(dev); - cpmac_free_rx_ring(dev); - cpmac_hw_init(dev); - spin_unlock(&priv->lock); - } + if (unlikely(status & (MAC_INT_HOST | MAC_INT_STATUS))) + cpmac_check_status(dev); return IRQ_HANDLED; } static void cpmac_tx_timeout(struct net_device *dev) { + int i; struct cpmac_priv *priv = netdev_priv(dev); - struct cpmac_desc *desc; - priv->stats.tx_errors++; - desc = &priv->desc_ring[priv->tx_head++]; - priv->tx_head %= 8; + spin_lock(&priv->lock); + dev->stats.tx_errors++; + spin_unlock(&priv->lock); if (netif_msg_tx_err(priv) && net_ratelimit()) printk(KERN_WARNING "%s: transmit timeout\n", dev->name); - if (desc->skb) - dev_kfree_skb_any(desc->skb); - netif_wake_queue(dev); + + atomic_inc(&priv->reset_pending); + barrier(); + cpmac_clear_tx(dev); + barrier(); + atomic_dec(&priv->reset_pending); + + netif_wake_queue(priv->dev); + for (i = 0; i < CPMAC_QUEUES; i++) { + netif_wake_subqueue(dev, i); + } } static int cpmac_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) @@ -695,7 +770,7 @@ static int cpmac_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) (cmd == SIOCSMIIREG)) return phy_mii_ioctl(priv->phy, if_mii(ifr), cmd); - return -EINVAL; + return -EOPNOTSUPP; } static int cpmac_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) @@ -721,11 +796,36 @@ static int cpmac_set_settings(struct net_device *dev, struct ethtool_cmd *cmd) return -EINVAL; } +static void cpmac_get_ringparam(struct net_device *dev, struct ethtool_ringparam* ring) +{ + struct cpmac_priv *priv = netdev_priv(dev); + + ring->rx_max_pending = 1024; + ring->rx_mini_max_pending = 1; + ring->rx_jumbo_max_pending = 1; + ring->tx_max_pending = 1; + + ring->rx_pending = priv->ring_size; + ring->rx_mini_pending = 1; + ring->rx_jumbo_pending = 1; + ring->tx_pending = 1; +} + +static int cpmac_set_ringparam(struct net_device *dev, struct ethtool_ringparam* ring) +{ + struct cpmac_priv *priv = netdev_priv(dev); + + if (netif_running(dev)) + return -EBUSY; + priv->ring_size = ring->rx_pending; + return 0; +} + static void cpmac_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info) { strcpy(info->driver, "cpmac"); - strcpy(info->version, "0.0.3"); + strcpy(info->version, CPMAC_VERSION); info->fw_version[0] = '\0'; sprintf(info->bus_info, "%s", "cpmac"); info->regdump_len = 0; @@ -736,42 +836,18 @@ static const struct ethtool_ops cpmac_ethtool_ops = { .set_settings = cpmac_set_settings, .get_drvinfo = cpmac_get_drvinfo, .get_link = ethtool_op_get_link, + .get_ringparam = cpmac_get_ringparam, + .set_ringparam = cpmac_set_ringparam, }; -static struct net_device_stats *cpmac_stats(struct net_device *dev) -{ - struct cpmac_priv *priv = netdev_priv(dev); - - if (netif_device_present(dev)) - return &priv->stats; - - return NULL; -} - -static int cpmac_change_mtu(struct net_device *dev, int mtu) -{ - unsigned long flags; - struct cpmac_priv *priv = netdev_priv(dev); - spinlock_t *lock = &priv->lock; - - if ((mtu < 68) || (mtu > 1500)) - return -EINVAL; - - spin_lock_irqsave(lock, flags); - dev->mtu = mtu; - spin_unlock_irqrestore(lock, flags); - - return 0; -} - static void cpmac_adjust_link(struct net_device *dev) { struct cpmac_priv *priv = netdev_priv(dev); - unsigned long flags; int new_state = 0; - spin_lock_irqsave(&priv->lock, flags); + spin_lock(&priv->lock); if (priv->phy->link) { + netif_start_queue(dev); if (priv->phy->duplex != priv->oldduplex) { new_state = 1; priv->oldduplex = priv->phy->duplex; @@ -788,6 +864,7 @@ static void cpmac_adjust_link(struct net_device *dev) netif_schedule(dev); } } else if (priv->oldlink) { + netif_stop_queue(dev); new_state = 1; priv->oldlink = 0; priv->oldspeed = 0; @@ -797,55 +874,14 @@ static void cpmac_adjust_link(struct net_device *dev) if (new_state && netif_msg_link(priv) && net_ratelimit()) phy_print_status(priv->phy); - spin_unlock_irqrestore(&priv->lock, flags); -} - -static void cpmac_hw_init(struct net_device *dev) -{ - int i; - struct cpmac_priv *priv = netdev_priv(dev); - - for (i = 0; i < 8; i++) { - cpmac_write(priv->regs, CPMAC_TX_PTR(i), 0); - cpmac_write(priv->regs, CPMAC_RX_PTR(i), 0); - } - cpmac_write(priv->regs, CPMAC_RX_PTR(0), priv->rx_head->mapping); - - cpmac_write(priv->regs, CPMAC_MBP, MBP_RXSHORT | MBP_RXBCAST | - MBP_RXMCAST); - cpmac_write(priv->regs, CPMAC_UNICAST_ENABLE, 1); - cpmac_write(priv->regs, CPMAC_UNICAST_CLEAR, 0xfe); - cpmac_write(priv->regs, CPMAC_BUFFER_OFFSET, 0); - for (i = 0; i < 8; i++) - cpmac_write(priv->regs, CPMAC_MAC_ADDR_LO(i), dev->dev_addr[5]); - cpmac_write(priv->regs, CPMAC_MAC_ADDR_MID, dev->dev_addr[4]); - cpmac_write(priv->regs, CPMAC_MAC_ADDR_HI, dev->dev_addr[0] | - (dev->dev_addr[1] << 8) | (dev->dev_addr[2] << 16) | - (dev->dev_addr[3] << 24)); - cpmac_write(priv->regs, CPMAC_MAX_LENGTH, CPMAC_SKB_SIZE); - cpmac_write(priv->regs, CPMAC_RX_INT_CLEAR, 0xff); - cpmac_write(priv->regs, CPMAC_TX_INT_CLEAR, 0xff); - cpmac_write(priv->regs, CPMAC_MAC_INT_CLEAR, 0xff); - cpmac_write(priv->regs, CPMAC_RX_INT_ENABLE, 1); - cpmac_write(priv->regs, CPMAC_TX_INT_ENABLE, 0xff); - cpmac_write(priv->regs, CPMAC_MAC_INT_ENABLE, 3); - - cpmac_write(priv->regs, CPMAC_RX_CONTROL, - cpmac_read(priv->regs, CPMAC_RX_CONTROL) | 1); - cpmac_write(priv->regs, CPMAC_TX_CONTROL, - cpmac_read(priv->regs, CPMAC_TX_CONTROL) | 1); - cpmac_write(priv->regs, CPMAC_MAC_CONTROL, - cpmac_read(priv->regs, CPMAC_MAC_CONTROL) | MAC_MII | - MAC_FDX); - - priv->phy->state = PHY_CHANGELINK; - phy_start(priv->phy); + spin_unlock(&priv->lock); } static int cpmac_open(struct net_device *dev) { int i, size, res; struct cpmac_priv *priv = netdev_priv(dev); + struct resource *mem; struct cpmac_desc *desc; struct sk_buff *skb; @@ -858,8 +894,8 @@ static int cpmac_open(struct net_device *dev) return PTR_ERR(priv->phy); } - if (!request_mem_region(dev->mem_start, dev->mem_end - - dev->mem_start, dev->name)) { + mem = platform_get_resource_byname(priv->pdev, IORESOURCE_MEM, "regs"); + if (!request_mem_region(mem->start, mem->end - mem->start, dev->name)) { if (netif_msg_drv(priv)) printk(KERN_ERR "%s: failed to request registers\n", dev->name); @@ -867,8 +903,7 @@ static int cpmac_open(struct net_device *dev) goto fail_reserve; } - priv->regs = ioremap(dev->mem_start, dev->mem_end - - dev->mem_start); + priv->regs = ioremap(mem->start, mem->end - mem->start); if (!priv->regs) { if (netif_msg_drv(priv)) printk(KERN_ERR "%s: failed to remap registers\n", @@ -877,8 +912,7 @@ static int cpmac_open(struct net_device *dev) goto fail_remap; } - priv->rx_head = NULL; - size = rx_ring_size + CPMAC_TX_RING_SIZE; + size = priv->ring_size + CPMAC_QUEUES; priv->desc_ring = dma_alloc_coherent(&dev->dev, sizeof(struct cpmac_desc) * size, &priv->dma_ring, @@ -888,11 +922,11 @@ static int cpmac_open(struct net_device *dev) goto fail_alloc; } - priv->rx_head = &priv->desc_ring[CPMAC_TX_RING_SIZE]; for (i = 0; i < size; i++) priv->desc_ring[i].mapping = priv->dma_ring + sizeof(*desc) * i; - for (i = 0, desc = &priv->rx_head[i]; i < rx_ring_size; i++, desc++) { + priv->rx_head = &priv->desc_ring[CPMAC_QUEUES]; + for (i = 0, desc = priv->rx_head; i < priv->ring_size; i++, desc++) { skb = netdev_alloc_skb(dev, CPMAC_SKB_SIZE); if (unlikely(!skb)) { res = -ENOMEM; @@ -906,7 +940,7 @@ static int cpmac_open(struct net_device *dev) desc->hw_data = (u32)desc->data_mapping; desc->buflen = CPMAC_SKB_SIZE; desc->dataflags = CPMAC_OWN; - desc->next = &priv->rx_head[(i + 1) % rx_ring_size]; + desc->next = &priv->rx_head[(i + 1) % priv->ring_size]; desc->hw_next = (u32)desc->next->mapping; } @@ -918,21 +952,24 @@ static int cpmac_open(struct net_device *dev) goto fail_irq; } - cpmac_reset(dev); - cpmac_hw_init(dev); + atomic_set(&priv->reset_pending, 0); + INIT_WORK(&priv->reset_work, cpmac_hw_error); + cpmac_hw_start(dev); + + priv->phy->state = PHY_CHANGELINK; + phy_start(priv->phy); - netif_start_queue(dev); return 0; fail_irq: fail_desc: - for (i = 0; i < rx_ring_size; i++) { + for (i = 0; i < priv->ring_size; i++) { if (priv->rx_head[i].skb) { - kfree_skb(priv->rx_head[i].skb); dma_unmap_single(&dev->dev, priv->rx_head[i].data_mapping, CPMAC_SKB_SIZE, DMA_FROM_DEVICE); + kfree_skb(priv->rx_head[i].skb); } } fail_alloc: @@ -940,8 +977,7 @@ fail_alloc: iounmap(priv->regs); fail_remap: - release_mem_region(dev->mem_start, dev->mem_end - - dev->mem_start); + release_mem_region(mem->start, mem->end - mem->start); fail_reserve: phy_disconnect(priv->phy); @@ -953,14 +989,16 @@ static int cpmac_stop(struct net_device *dev) { int i; struct cpmac_priv *priv = netdev_priv(dev); + struct resource *mem; netif_stop_queue(dev); + cancel_work_sync(&priv->reset_work); phy_stop(priv->phy); phy_disconnect(priv->phy); priv->phy = NULL; - cpmac_reset(dev); + cpmac_hw_stop(dev); for (i = 0; i < 8; i++) cpmac_write(priv->regs, CPMAC_TX_PTR(i), 0); @@ -968,21 +1006,22 @@ static int cpmac_stop(struct net_device *dev) cpmac_write(priv->regs, CPMAC_MBP, 0); free_irq(dev->irq, dev); - release_mem_region(dev->mem_start, dev->mem_end - - dev->mem_start); - priv->rx_head = &priv->desc_ring[CPMAC_TX_RING_SIZE]; - for (i = 0; i < rx_ring_size; i++) { + iounmap(priv->regs); + mem = platform_get_resource_byname(priv->pdev, IORESOURCE_MEM, "regs"); + release_mem_region(mem->start, mem->end - mem->start); + priv->rx_head = &priv->desc_ring[CPMAC_QUEUES]; + for (i = 0; i < priv->ring_size; i++) { if (priv->rx_head[i].skb) { - kfree_skb(priv->rx_head[i].skb); dma_unmap_single(&dev->dev, priv->rx_head[i].data_mapping, CPMAC_SKB_SIZE, DMA_FROM_DEVICE); + kfree_skb(priv->rx_head[i].skb); } } dma_free_coherent(&dev->dev, sizeof(struct cpmac_desc) * - (CPMAC_TX_RING_SIZE + rx_ring_size), + (CPMAC_QUEUES + priv->ring_size), priv->desc_ring, priv->dma_ring); return 0; } @@ -991,8 +1030,8 @@ static int external_switch; static int __devinit cpmac_probe(struct platform_device *pdev) { - int i, rc, phy_id; - struct resource *res; + int rc, phy_id; + struct resource *mem; struct cpmac_priv *priv; struct net_device *dev; struct plat_cpmac_data *pdata; @@ -1016,7 +1055,7 @@ static int __devinit cpmac_probe(struct platform_device *pdev) } } - dev = alloc_etherdev(sizeof(struct cpmac_priv)); + dev = alloc_etherdev_mq(sizeof(*priv), CPMAC_QUEUES); if (!dev) { printk(KERN_ERR "cpmac: Unable to allocate net_device\n"); @@ -1026,14 +1065,13 @@ static int __devinit cpmac_probe(struct platform_device *pdev) platform_set_drvdata(pdev, dev); priv = netdev_priv(dev); - res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "regs"); - if (!res) { + priv->pdev = pdev; + mem = platform_get_resource_byname(pdev, IORESOURCE_MEM, "regs"); + if (!mem) { rc = -ENODEV; goto fail; } - dev->mem_start = res->start; - dev->mem_end = res->end; dev->irq = platform_get_irq_byname(pdev, "irq"); dev->open = cpmac_open; @@ -1041,27 +1079,22 @@ static int __devinit cpmac_probe(struct platform_device *pdev) dev->set_config = cpmac_config; dev->hard_start_xmit = cpmac_start_xmit; dev->do_ioctl = cpmac_ioctl; - dev->get_stats = cpmac_stats; - dev->change_mtu = cpmac_change_mtu; - dev->set_mac_address = cpmac_set_mac_address; dev->set_multicast_list = cpmac_set_multicast_list; dev->tx_timeout = cpmac_tx_timeout; dev->ethtool_ops = &cpmac_ethtool_ops; - if (!disable_napi) { - dev->poll = cpmac_poll; - dev->weight = min(rx_ring_size, 64); - } + dev->poll = cpmac_poll; + dev->weight = 64; + dev->features |= NETIF_F_MULTI_QUEUE; spin_lock_init(&priv->lock); - priv->msg_enable = netif_msg_init(debug_level, 0xff); - priv->config = pdata; + spin_lock_init(&priv->rx_lock); priv->dev = dev; - memcpy(dev->dev_addr, priv->config->dev_addr, sizeof(dev->dev_addr)); + priv->ring_size = 64; + priv->msg_enable = netif_msg_init(debug_level, 0xff); + memcpy(dev->dev_addr, pdata->dev_addr, sizeof(dev->dev_addr)); if (phy_id == 31) { snprintf(priv->phy_name, BUS_ID_SIZE, PHY_ID_FMT, cpmac_mii.id, phy_id); -/* cpmac_write(cpmac_mii.priv, CPMAC_MDIO_PHYSEL(0), PHYSEL_LINKSEL - | PHYSEL_LINKINT | phy_id);*/ } else snprintf(priv->phy_name, BUS_ID_SIZE, "fixed@%d:%d", 100, 1); @@ -1073,11 +1106,9 @@ static int __devinit cpmac_probe(struct platform_device *pdev) if (netif_msg_probe(priv)) { printk(KERN_INFO - "cpmac: device %s (regs: %p, irq: %d, phy: %s, mac: ", - dev->name, (u32 *)dev->mem_start, dev->irq, - priv->phy_name); - for (i = 0; i < 6; i++) - printk("%02x%s", dev->dev_addr[i], i < 5 ? ":" : ")\n"); + "cpmac: device %s (regs: %p, irq: %d, phy: %s, mac: " + MAC_FMT ")\n", dev->name, (void *)mem->start, dev->irq, + priv->phy_name, MAC_ARG(dev->dev_addr)); } return 0;