#include <linux/platform_device.h>
#include <linux/dma-mapping.h>
#include <asm/gpio.h>
+#include <asm/atomic.h>
-MODULE_AUTHOR("Eugene Konev");
+MODULE_AUTHOR("Eugene Konev <ejka@imfi.kspu.ru>");
MODULE_DESCRIPTION("TI AR7 ethernet driver (CPMAC)");
MODULE_LICENSE("GPL");
-static int disable_napi;
static int debug_level = 8;
static int dumb_switch;
-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(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"
#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
#define CPMAC_EOQ 0x1000
struct sk_buff *skb;
struct cpmac_desc *next;
+ struct cpmac_desc *prev;
dma_addr_t mapping;
dma_addr_t data_mapping;
};
struct cpmac_priv {
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;
char phy_name[BUS_ID_SIZE];
int oldlink, oldspeed, oldduplex;
u32 msg_enable;
+ struct net_device *dev;
+ 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);
printk("\n");
}
+static void cpmac_dump_all_desc(struct net_device *dev)
+{
+ struct cpmac_priv *priv = netdev_priv(dev);
+ struct cpmac_desc *dump = priv->rx_head;
+ do {
+ cpmac_dump_desc(dev, dump);
+ dump = dump->next;
+ } while (dump != priv->rx_head);
+}
+
static void cpmac_dump_skb(struct net_device *dev, struct sk_buff *skb)
{
int i;
struct cpmac_priv *priv,
struct cpmac_desc *desc)
{
- unsigned long flags;
struct sk_buff *skb, *result = NULL;
if (unlikely(netif_msg_hw(priv)))
}
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);
"%s: low on skbs, dropping packet\n", dev->name);
dev->stats.rx_dropped++;
}
- spin_unlock_irqrestore(&priv->lock, flags);
desc->buflen = CPMAC_SKB_SIZE;
desc->dataflags = CPMAC_OWN;
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;
- struct cpmac_desc *desc;
- int received = 0, quota = min(dev->quota, *budget);
+ struct cpmac_desc *desc, *restart;
+ int received = 0, processed = 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",
dev->name);
+ spin_unlock(&priv->rx_lock);
netif_rx_complete(dev);
return 0;
}
desc = priv->rx_head;
-
+ restart = NULL;
while ((received < quota) && ((desc->dataflags & CPMAC_OWN) == 0)) {
+ processed++;
+
+ if ((desc->dataflags & CPMAC_EOQ) != 0) {
+ /* The last update to eoq->hw_next didn't happen soon enough, and the
+ * receiver stopped here. Remember this descriptor so we can restart
+ * the receiver after freeing some space.
+ */
+ if (unlikely(restart)) {
+ if (netif_msg_rx_err(priv))
+ printk(KERN_ERR "%s: poll found a duplicate EOQ: %p and %p\n",
+ dev->name, restart, desc);
+ goto fatal_error;
+ }
+
+ restart = desc->next;
+ }
+
skb = cpmac_rx_one(dev, priv, desc);
if (likely(skb)) {
netif_receive_skb(skb);
}
desc = desc->next;
}
+
+ if (desc != priv->rx_head) {
+ /* We freed some buffers, but not the whole ring, add what we did free to the rx list */
+ desc->prev->hw_next = (u32)0;
+ priv->rx_head->prev->hw_next = priv->rx_head->mapping;
+ }
+
+ /* Optimization: If we did not actually process an EOQ (perhaps because of
+ * quota limits), check to see if the tail of the queue has EOQ set. We
+ * should immediately restart in that case so that the receiver can restart
+ * and run in parallel with more packet processing. This lets us handle slightly
+ * larger bursts before running out of ring space (assuming dev->weight < ring_size)
+ */
+ if (!restart &&
+ (priv->rx_head->prev->dataflags & (CPMAC_OWN|CPMAC_EOQ)) == CPMAC_EOQ &&
+ (priv->rx_head->dataflags & CPMAC_OWN) != 0) {
+ /* reset EOQ so the poll loop (above) doesn't try to restart this when it
+ * eventually gets to this descriptor.
+ */
+ priv->rx_head->prev->dataflags &= ~CPMAC_EOQ;
+ restart = priv->rx_head;
+ }
+
+ if (restart) {
+ dev->stats.rx_errors++;
+ dev->stats.rx_fifo_errors++;
+ if (netif_msg_rx_err(priv) && net_ratelimit())
+ printk(KERN_WARNING "%s: rx dma ring overrun\n", dev->name);
+
+ if (unlikely((restart->dataflags & CPMAC_OWN) == 0)) {
+ if (netif_msg_drv(priv))
+ printk(KERN_ERR "%s: cpmac_poll is trying to restart rx from a descriptor that's not free: %p\n",
+ dev->name, restart);
+ goto fatal_error;
+ }
+
+ cpmac_write(priv->regs, CPMAC_RX_PTR(0), restart->mapping);
+ }
priv->rx_head = desc;
+ spin_unlock(&priv->rx_lock);
*budget -= received;
dev->quota -= received;
if (unlikely(netif_msg_rx_status(priv)))
printk(KERN_DEBUG "%s: poll processed %d packets\n", dev->name,
received);
- if (desc->dataflags & CPMAC_OWN) {
+
+ if (processed == 0) {
+ /* we ran out of packets to read, revert to interrupt-driven mode */
netif_rx_complete(dev);
- cpmac_write(priv->regs, CPMAC_RX_PTR(0), (u32)desc->mapping);
cpmac_write(priv->regs, CPMAC_RX_INT_ENABLE, 1);
return 0;
}
return 1;
+
+fatal_error:
+ /* Something went horribly wrong. Reset hardware to try to recover rather than wedging. */
+
+ if (netif_msg_drv(priv)) {
+ printk(KERN_ERR "%s: cpmac_poll is confused. Resetting hardware\n", dev->name);
+ cpmac_dump_all_desc(dev);
+ printk(KERN_DEBUG "%s: RX_PTR(0)=0x%08x RX_ACK(0)=0x%08x\n",
+ dev->name,
+ cpmac_read(priv->regs, CPMAC_RX_PTR(0)),
+ cpmac_read(priv->regs, CPMAC_RX_ACK(0)));
+ }
+
+ spin_unlock(&priv->rx_lock);
+ netif_rx_complete(dev);
+ netif_stop_queue(dev);
+
+ atomic_inc(&priv->reset_pending);
+ cpmac_hw_stop(dev);
+ if (!schedule_work(&priv->reset_work))
+ atomic_dec(&priv->reset_pending);
+ return 0;
}
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);
- dev->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);
- dev->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,
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)) {
+ 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);
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);
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 < priv->ring_size; i++) {
- desc->buflen = CPMAC_SKB_SIZE;
if ((desc->dataflags & CPMAC_OWN) == 0) {
if (netif_msg_rx_err(priv) && net_ratelimit())
printk(KERN_WARNING "%s: packet dropped\n",
desc->dataflags = CPMAC_OWN;
dev->stats.rx_dropped++;
}
+ desc->hw_next = desc->next->mapping;
desc = desc->next;
}
+
+ priv->rx_head->prev->hw_next = 0;
+}
+
+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)
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;
+ spin_lock(&priv->lock);
dev->stats.tx_errors++;
- desc = &priv->desc_ring[priv->tx_head++];
- priv->tx_head %= 8;
+ 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)
(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)
{
struct cpmac_priv *priv = netdev_priv(dev);
- if (dev->flags && IFF_UP)
+ if (netif_running(dev))
return -EBUSY;
priv->ring_size = ring->rx_pending;
return 0;
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;
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;
netif_schedule(dev);
}
} else if (priv->oldlink) {
+ netif_stop_queue(dev);
new_state = 1;
priv->oldlink = 0;
priv->oldspeed = 0;
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)
goto fail_remap;
}
- priv->rx_head = NULL;
- size = priv->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,
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 < priv->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;
desc->buflen = CPMAC_SKB_SIZE;
desc->dataflags = CPMAC_OWN;
desc->next = &priv->rx_head[(i + 1) % priv->ring_size];
+ desc->next->prev = desc;
desc->hw_next = (u32)desc->next->mapping;
}
+ priv->rx_head->prev->hw_next = (u32)0;
+
if ((res = request_irq(dev->irq, cpmac_irq, IRQF_SHARED,
dev->name, dev))) {
if (netif_msg_drv(priv))
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 < 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:
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);
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_TX_RING_SIZE];
+ 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 + priv->ring_size),
+ (CPMAC_QUEUES + priv->ring_size),
priv->desc_ring, priv->dma_ring);
return 0;
}
}
}
- 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");
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 = 64;
- }
+ dev->poll = cpmac_poll;
+ dev->features |= NETIF_F_MULTI_QUEUE;
spin_lock_init(&priv->lock);
- priv->msg_enable = netif_msg_init(debug_level, 0xff);
+ spin_lock_init(&priv->rx_lock);
+ priv->dev = dev;
priv->ring_size = 64;
+ dev->weight = max(4, priv->ring_size/4);
+ 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);