ar7: cpmac: use fixed-size ringbuffers for rx/tx descriptors, use single channel rx, move skb allocation out of interrupt, general cleanup

SVN-Revision: 6724
This commit is contained in:
Eugene Konev 2007-03-27 15:19:08 +00:00
parent 34fd376368
commit 6f48cd2114

View File

@ -28,6 +28,7 @@
#include <linux/errno.h> #include <linux/errno.h>
#include <linux/types.h> #include <linux/types.h>
#include <linux/delay.h> #include <linux/delay.h>
#include <linux/version.h>
#include <linux/netdevice.h> #include <linux/netdevice.h>
#include <linux/etherdevice.h> #include <linux/etherdevice.h>
@ -194,23 +195,29 @@ struct cpmac_desc {
struct cpmac_priv { struct cpmac_priv {
struct net_device_stats stats; struct net_device_stats stats;
spinlock_t lock; spinlock_t lock;
int free_tx_channels; struct sk_buff *skb_pool;
struct cpmac_desc *tx_pool; int free_skbs;
struct cpmac_desc *rx_channels[8]; struct cpmac_desc *rx_head;
struct cpmac_desc *tx_channels[8]; int tx_head, tx_tail;
struct cpmac_desc *desc_ring;
struct cpmac_regs *regs; struct cpmac_regs *regs;
struct mii_bus *mii_bus; struct mii_bus *mii_bus;
struct phy_device *phy; struct phy_device *phy;
char phy_name[BUS_ID_SIZE]; char phy_name[BUS_ID_SIZE];
unsigned long pages;
int order;
struct plat_cpmac_data *config; struct plat_cpmac_data *config;
int oldlink, oldspeed, oldduplex; int oldlink, oldspeed, oldduplex;
u32 msg_enable; u32 msg_enable;
struct net_device *dev;
struct work_struct alloc_work;
}; };
static irqreturn_t cpmac_irq(int, void *); static irqreturn_t cpmac_irq(int, void *);
void cpmac_exit(void);
#define CPMAC_LOW_THRESH 8
#define CPMAC_ALLOC_SIZE 32
#define CPMAC_SKB_SIZE 1536
#define CPMAC_TX_RING_SIZE 8
#define CPMAC_RX_RING_SIZE 16
#ifdef CPMAC_DEBUG #ifdef CPMAC_DEBUG
static void cpmac_dump_regs(u32 *base, int count) static void cpmac_dump_regs(u32 *base, int count)
@ -263,7 +270,7 @@ static int cpmac_mdio_reset(struct mii_bus *bus)
static int mii_irqs[PHY_MAX_ADDR] = { PHY_POLL, }; static int mii_irqs[PHY_MAX_ADDR] = { PHY_POLL, };
struct mii_bus cpmac_mii = { static struct mii_bus cpmac_mii = {
.name = "cpmac-mii", .name = "cpmac-mii",
.read = cpmac_mdio_read, .read = cpmac_mdio_read,
.write = cpmac_mdio_write, .write = cpmac_mdio_write,
@ -271,7 +278,7 @@ struct mii_bus cpmac_mii = {
.irq = mii_irqs, .irq = mii_irqs,
}; };
int cpmac_config(struct net_device *dev, struct ifmap *map) static int cpmac_config(struct net_device *dev, struct ifmap *map)
{ {
if (dev->flags & IFF_UP) if (dev->flags & IFF_UP)
return -EBUSY; return -EBUSY;
@ -284,7 +291,7 @@ int cpmac_config(struct net_device *dev, struct ifmap *map)
return 0; return 0;
} }
int cpmac_set_mac_address(struct net_device *dev, void *addr) static int cpmac_set_mac_address(struct net_device *dev, void *addr)
{ {
struct sockaddr *sa = addr; struct sockaddr *sa = addr;
@ -296,7 +303,7 @@ int cpmac_set_mac_address(struct net_device *dev, void *addr)
return 0; return 0;
} }
void cpmac_set_multicast_list(struct net_device *dev) static void cpmac_set_multicast_list(struct net_device *dev)
{ {
struct dev_mc_list *iter; struct dev_mc_list *iter;
int i; int i;
@ -343,95 +350,132 @@ void cpmac_set_multicast_list(struct net_device *dev)
} }
} }
static struct sk_buff *cpmac_get_skb(struct net_device *dev)
{
struct sk_buff *skb;
struct cpmac_priv *priv = netdev_priv(dev);
skb = priv->skb_pool;
if (likely(skb))
priv->skb_pool = skb->next;
if (likely(priv->free_skbs))
priv->free_skbs--;
if (priv->free_skbs < CPMAC_LOW_THRESH)
schedule_work(&priv->alloc_work);
return skb;
}
static void cpmac_rx(struct net_device *dev, int channel) static void cpmac_rx(struct net_device *dev, int channel)
{ {
struct cpmac_desc *pkt;
struct sk_buff *skb;
char *data; char *data;
struct sk_buff *skb;
struct cpmac_desc *desc;
struct cpmac_priv *priv = netdev_priv(dev); struct cpmac_priv *priv = netdev_priv(dev);
spin_lock(&priv->lock); spin_lock(&priv->lock);
pkt = priv->rx_channels[channel]; if (unlikely(!priv->rx_head))
if (!pkt) {
if (printk_ratelimit())
printk(KERN_NOTICE "%s: rx: spurious interrupt\n",
dev->name);
priv->stats.rx_errors++;
return; return;
}
priv->regs->rx_ack[channel] = virt_to_phys(pkt); desc = priv->rx_head;
dma_cache_inv((u32)pkt, 16); dma_cache_inv((u32)desc, 16);
if (!pkt->datalen) {
if (printk_ratelimit()) while((desc->dataflags & CPMAC_OWN) == 0) {
printk(KERN_NOTICE "%s: rx: spurious interrupt\n", priv->regs->rx_ack[0] = virt_to_phys(desc);
dev->name); if (unlikely(!desc->datalen)) {
priv->stats.rx_errors++; if (printk_ratelimit())
return; printk(KERN_NOTICE "%s: rx: spurious interrupt\n",
} dev->name);
skb = dev_alloc_skb(1536); priv->stats.rx_errors++;
if (!skb) { goto out;
if (printk_ratelimit()) }
printk(KERN_NOTICE "%s: rx: low on mem - packet dropped\n",
dev->name); skb = cpmac_get_skb(dev);
priv->stats.rx_dropped++; if (likely(skb)) {
} else { data = (char *)phys_to_virt(desc->hw_data);
data = (char *)phys_to_virt(pkt->hw_data); dma_cache_inv((u32)data, desc->datalen);
dma_cache_inv((u32)data, pkt->datalen); skb_put(desc->skb, desc->datalen);
skb_put(pkt->skb, pkt->datalen); desc->skb->protocol = eth_type_trans(desc->skb, dev);
pkt->skb->protocol = eth_type_trans(pkt->skb, dev); desc->skb->ip_summed = CHECKSUM_NONE;
pkt->skb->ip_summed = CHECKSUM_NONE; priv->stats.rx_packets++;
priv->stats.rx_packets++; priv->stats.rx_bytes += desc->datalen;
priv->stats.rx_bytes += pkt->datalen; netif_rx(desc->skb);
netif_rx(pkt->skb); desc->skb = skb;
skb_reserve(skb, 2); } else {
skb->dev = dev; if (printk_ratelimit())
pkt->skb = skb; printk(KERN_NOTICE "%s: rx: no free skbs, dropping packet\n",
pkt->hw_data = virt_to_phys(skb->data); dev->name);
priv->stats.rx_dropped++;
}
desc->hw_data = virt_to_phys(desc->skb->data);
desc->buflen = CPMAC_SKB_SIZE;
desc->dataflags = CPMAC_OWN;
dma_cache_wback((u32)desc, 16);
desc = desc->next;
dma_cache_inv((u32)desc, 16);
} }
out:
priv->rx_head = desc;
spin_unlock(&priv->lock); spin_unlock(&priv->lock);
pkt->buflen = 1500 + ETH_HLEN + 4; priv->regs->rx_ptr[0] = virt_to_phys(priv->rx_head);
pkt->datalen = 0;
pkt->dataflags = CPMAC_OWN;
dma_cache_wback_inv((u32)pkt, 16);
priv->regs->rx_ptr[channel] = virt_to_phys(pkt);
} }
struct cpmac_desc *cpmac_get_desc(struct net_device *dev) #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 20)
static void
cpmac_alloc_skbs(struct work_struct *work)
{ {
struct cpmac_desc *pkt; struct cpmac_priv *priv = container_of(work, struct cpmac_priv,
struct cpmac_priv *priv = netdev_priv(dev); alloc_work);
pkt = priv->tx_pool; #else
priv->tx_pool = pkt->next; static void
pkt->next = NULL; cpmac_alloc_skbs(void *data)
if (priv->tx_pool == NULL)
netif_stop_queue(dev);
return pkt;
}
void cpmac_release_desc(struct net_device *dev, struct cpmac_desc *pkt)
{ {
struct net_device *dev = (struct net_device*)data;
struct cpmac_priv *priv = netdev_priv(dev); struct cpmac_priv *priv = netdev_priv(dev);
struct cpmac_desc *p; #endif
p = pkt; unsigned long flags;
while (p->next) p = p->next; int i, num_skbs = 0;
p->next = priv->tx_pool; struct sk_buff *skb, *skbs = NULL;
priv->tx_pool = pkt;
for (i = 0; i < CPMAC_ALLOC_SIZE; i++) {
skb = alloc_skb(CPMAC_SKB_SIZE + 2, GFP_KERNEL);
if (!skb)
break;
skb->next = skbs;
skb_reserve(skb, 2);
skb->dev = priv->dev;
num_skbs++;
skbs = skb;
}
if (skbs) {
spin_lock_irqsave(&priv->lock, flags);
for (skb = priv->skb_pool; skb && skb->next; skb = skb->next);
if (!skb) {
priv->skb_pool = skbs;
} else {
skb->next = skbs;
}
priv->free_skbs += num_skbs;
spin_unlock_irqrestore(&priv->lock, flags);
#ifdef CPMAC_DEBUG
printk("%s: allocated %d skbs\n", priv->dev->name, num_skbs);
#endif
}
} }
int cpmac_start_xmit(struct sk_buff *skb, struct net_device *dev) static int cpmac_start_xmit(struct sk_buff *skb, struct net_device *dev)
{ {
unsigned long flags; unsigned long flags;
int i, len, frag; int len, chan;
skb_frag_t *this_frag; struct cpmac_desc *desc;
void *data;
struct cpmac_desc *head, *tail, *curr;
struct cpmac_priv *priv = netdev_priv(dev); struct cpmac_priv *priv = netdev_priv(dev);
BUG_ON(priv->free_tx_channels < 1);
len = skb->len; len = skb->len;
if (len < ETH_ZLEN) { if (unlikely(len < ETH_ZLEN)) {
if (skb_padto(skb, ETH_ZLEN)) { if (unlikely(skb_padto(skb, ETH_ZLEN))) {
if (printk_ratelimit()) if (printk_ratelimit())
printk(KERN_NOTICE "%s: padding failed, dropping\n", printk(KERN_NOTICE "%s: padding failed, dropping\n",
dev->name); dev->name);
@ -443,66 +487,51 @@ int cpmac_start_xmit(struct sk_buff *skb, struct net_device *dev)
len = ETH_ZLEN; len = ETH_ZLEN;
} }
spin_lock_irqsave(&priv->lock, flags); spin_lock_irqsave(&priv->lock, flags);
dev->trans_start = jiffies; chan = priv->tx_tail++;
for (i = 0; i < 8; i++) priv->tx_tail %= 8;
if (!priv->tx_channels[i]) if (priv->tx_tail == priv->tx_head)
break;
BUG_ON(i == 8);
head = cpmac_get_desc(dev);
priv->tx_channels[i] = head;
head->jiffies = dev->trans_start;
if (!(--priv->free_tx_channels))
netif_stop_queue(dev); netif_stop_queue(dev);
desc = &priv->desc_ring[chan];
dev->trans_start = jiffies;
desc->jiffies = dev->trans_start;
spin_unlock_irqrestore(&priv->lock, flags); spin_unlock_irqrestore(&priv->lock, flags);
head->dataflags = CPMAC_SOP | CPMAC_OWN; desc->dataflags = CPMAC_SOP | CPMAC_EOP | CPMAC_OWN;
head->skb = skb; desc->skb = skb;
head->hw_data = virt_to_phys(skb->data); desc->hw_data = virt_to_phys(skb->data);
dma_cache_wback_inv((u32)skb->data, len); dma_cache_wback((u32)skb->data, len);
head->buflen = len; desc->buflen = len;
head->datalen = len; desc->datalen = len;
tail = head; desc->hw_next = 0;
for (frag = 0; frag < skb_shinfo(skb)->nr_frags; frag++) { dma_cache_wback((u32)desc, 16);
dma_cache_wback_inv((u32)tail, 16); priv->regs->tx_ptr[chan] = virt_to_phys(desc);
this_frag = &skb_shinfo(skb)->frags[frag];
curr = cpmac_get_desc(dev);
data = page_address(this_frag->page) +
this_frag->page_offset;
curr->hw_data = virt_to_phys(data);
curr->buflen = this_frag->size;
curr->datalen = this_frag->size;
curr->dataflags = CPMAC_OWN;
dma_cache_wback_inv((u32)data, len);
tail->hw_next = virt_to_phys(curr);
tail->next = curr;
tail = curr;
}
tail->hw_next = 0;
tail->dataflags |= CPMAC_EOP;
dma_cache_wback_inv((u32)tail, 16);
priv->regs->tx_ptr[i] = virt_to_phys(head);
return 0; return 0;
} }
void cpmac_end_xmit(struct net_device *dev, int channel) static void cpmac_end_xmit(struct net_device *dev, int channel)
{ {
struct cpmac_desc *pkt; struct cpmac_desc *desc;
struct cpmac_priv *priv = netdev_priv(dev); struct cpmac_priv *priv = netdev_priv(dev);
spin_lock(&priv->lock); spin_lock(&priv->lock);
pkt = priv->tx_channels[channel]; desc = &priv->desc_ring[channel];
priv->tx_channels[channel] = NULL; priv->regs->tx_ack[channel] = virt_to_phys(desc);
priv->free_tx_channels++; if (likely(desc->skb)) {
priv->regs->tx_ack[channel] = virt_to_phys(pkt);
if (pkt) {
priv->stats.tx_packets++; priv->stats.tx_packets++;
priv->stats.tx_bytes += pkt->skb->len; priv->stats.tx_bytes += desc->skb->len;
dev_kfree_skb_irq(pkt->skb); dev_kfree_skb_irq(desc->skb);
cpmac_release_desc(dev, pkt); if (priv->tx_head == channel) {
if (netif_queue_stopped(dev)) while ((desc->dataflags & CPMAC_OWN) == 0) {
netif_wake_queue(dev); priv->tx_head++;
priv->tx_head %= 8;
if (priv->tx_head == priv->tx_tail)
break;
desc = &priv->desc_ring[priv->tx_head];
}
if (netif_queue_stopped(dev))
netif_wake_queue(dev);
}
} else { } else {
if (printk_ratelimit()) if (printk_ratelimit())
printk(KERN_NOTICE "%s: end_xmit: spurious interrupt\n", printk(KERN_NOTICE "%s: end_xmit: spurious interrupt\n",
@ -530,46 +559,37 @@ static irqreturn_t cpmac_irq(int irq, void *dev_id)
cpmac_rx(dev, (status >> 8) & 7); cpmac_rx(dev, (status >> 8) & 7);
} }
if (status & INTST_HOST) { /* host interrupt ??? */ if (unlikely(status & INTST_HOST)) { /* host interrupt ??? */
printk("%s: host int, something bad happened...\n", dev->name); printk("%s: host int, something bad happened...\n", dev->name);
printk("%s: mac status: 0x%08x\n", dev->name, printk("%s: mac status: 0x%08x\n", dev->name,
priv->regs->mac_status); priv->regs->mac_status);
} }
if (status & INTST_STATUS) { /* status interrupt ??? */ if (unlikely(status & INTST_STATUS)) { /* status interrupt ??? */
printk("%s: status int, what are we gonna do?\n", dev->name); printk("%s: status int, what are we gonna do?\n", dev->name);
} }
priv->regs->mac_eoi_vector = 0; priv->regs->mac_eoi_vector = 0;
return IRQ_HANDLED; return IRQ_HANDLED;
} }
void cpmac_tx_timeout(struct net_device *dev) static void cpmac_tx_timeout(struct net_device *dev)
{ {
int i;
struct cpmac_priv *priv = netdev_priv(dev); struct cpmac_priv *priv = netdev_priv(dev);
struct cpmac_desc *pkt = NULL, *tmp; struct cpmac_desc *desc;
priv->stats.tx_errors++; priv->stats.tx_errors++;
for (i = 0; i < 8; i++) { desc = &priv->desc_ring[priv->tx_head++];
tmp = priv->tx_channels[i]; priv->tx_head %= 8;
if (tmp && (!pkt || (pkt->jiffies > tmp->jiffies))) printk("Transmit timeout at %ld, latency %ld\n", jiffies,
pkt = tmp; jiffies - desc->jiffies);
} if (desc->skb)
if (pkt) { dev_kfree_skb(desc->skb);
printk("Transmit timeout at %ld, latency %ld\n", jiffies, netif_wake_queue(dev);
jiffies - pkt->jiffies);
for (i = 0; i < 8; i++)
if (priv->tx_channels[i] == pkt)
priv->tx_channels[i] = NULL;
dev_kfree_skb(pkt->skb);
cpmac_release_desc(dev, pkt);
priv->free_tx_channels++;
netif_wake_queue(dev);
}
} }
int cpmac_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) static int cpmac_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
{ {
struct cpmac_priv *priv = netdev_priv(dev); struct cpmac_priv *priv = netdev_priv(dev);
if (!(netif_running(dev))) if (!(netif_running(dev)))
@ -696,16 +716,19 @@ static void cpmac_adjust_link(struct net_device *dev)
spin_unlock_irqrestore(&priv->lock, flags); spin_unlock_irqrestore(&priv->lock, flags);
} }
int cpmac_open(struct net_device *dev) static int cpmac_open(struct net_device *dev)
{ {
int i, j, res; int i, size, res;
struct cpmac_priv *priv = netdev_priv(dev); struct cpmac_priv *priv = netdev_priv(dev);
struct cpmac_desc *pkt; struct cpmac_desc *desc;
struct sk_buff *skb; struct sk_buff *skb;
/* priv->phy = phy_connect(dev, priv->phy_name, &cpmac_adjust_link, #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 20)
0, PHY_INTERFACE_MODE_MII);*/ priv->phy = phy_connect(dev, priv->phy_name, &cpmac_adjust_link,
0, PHY_INTERFACE_MODE_MII);
#else
priv->phy = phy_connect(dev, priv->phy_name, &cpmac_adjust_link, 0); priv->phy = phy_connect(dev, priv->phy_name, &cpmac_adjust_link, 0);
#endif
if (IS_ERR(priv->phy)) { if (IS_ERR(priv->phy)) {
printk(KERN_ERR "%s: Could not attach to PHY\n", dev->name); printk(KERN_ERR "%s: Could not attach to PHY\n", dev->name);
return PTR_ERR(priv->phy); return PTR_ERR(priv->phy);
@ -727,65 +750,65 @@ int cpmac_open(struct net_device *dev)
goto fail_remap; goto fail_remap;
} }
priv->order = get_order(4096); priv->rx_head = NULL;
priv->pages = __get_dma_pages(GFP_KERNEL, priv->order); size = sizeof(struct cpmac_desc) * (CPMAC_RX_RING_SIZE +
if (!priv->pages) { CPMAC_TX_RING_SIZE);
priv->desc_ring = (struct cpmac_desc *)kmalloc(size, GFP_KERNEL);
if (!priv->desc_ring) {
res = -ENOMEM; res = -ENOMEM;
goto fail_alloc; goto fail_alloc;
} }
memset((char *)priv->pages, 0, 4096);
priv->tx_pool = NULL; memset((char *)priv->desc_ring, 0, size);
for (i = 0; i < 4096 / sizeof(struct cpmac_desc); i++) { priv->skb_pool = NULL;
pkt = (struct cpmac_desc *) priv->free_skbs = 0;
(priv->pages + i * sizeof(struct cpmac_desc)); priv->rx_head = &priv->desc_ring[CPMAC_TX_RING_SIZE];
memset(pkt, sizeof(struct cpmac_desc), 0);
if (i < 8) { #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 20)
skb = alloc_skb(1500 + ETH_HLEN + 6, GFP_KERNEL); INIT_WORK(&priv->alloc_work, cpmac_alloc_skbs);
if (!skb) { #else
for(j = 0; j < i - 1; j++) INIT_WORK(&priv->alloc_work, cpmac_alloc_skbs, dev);
kfree_skb(priv->rx_channels[j]->skb); #endif
free_pages(priv->pages, priv->order); schedule_work(&priv->alloc_work);
res = -ENOMEM; flush_scheduled_work();
goto fail_alloc;
} for (i = 0; i < CPMAC_RX_RING_SIZE; i++) {
skb_reserve(skb, 2); desc = &priv->rx_head[i];
skb->dev = dev; skb = cpmac_get_skb(dev);
pkt->skb = skb; if (!skb) {
pkt->hw_data = virt_to_phys(skb->data); res = -ENOMEM;
pkt->buflen = 1500 + ETH_HLEN + 4; goto fail_desc;
pkt->dataflags = CPMAC_OWN;
dma_cache_wback_inv((u32)pkt, 16);
priv->rx_channels[i] = pkt;
priv->tx_channels[i] = NULL;
} else {
pkt->next = priv->tx_pool;
priv->tx_pool = pkt;
} }
desc->skb = skb;
desc->hw_data = virt_to_phys(skb->data);
desc->buflen = CPMAC_SKB_SIZE;
desc->dataflags = CPMAC_OWN;
desc->next = &priv->rx_head[i + 1];
desc->hw_next = virt_to_phys(desc->next);
dma_cache_wback((u32)desc, 16);
} }
priv->rx_head[CPMAC_RX_RING_SIZE - 1].next = priv->rx_head;
priv->rx_head[CPMAC_RX_RING_SIZE - 1].hw_next =
virt_to_phys(priv->rx_head);
cpmac_reset(dev); cpmac_reset(dev);
priv->free_tx_channels = 8; for (i = 0; i < 8; i++)
for (i = 0; i < 8; i++) {
priv->regs->tx_ptr[i] = 0; priv->regs->tx_ptr[i] = 0;
priv->regs->rx_ptr[i] = virt_to_phys(priv->rx_channels[i]); priv->regs->rx_ptr[0] = virt_to_phys(priv->rx_head);
}
priv->regs->mbp = MBP_RXNOCHAIN | MBP_RXSHORT | MBP_RXBCAST | priv->regs->mbp = MBP_RXSHORT | MBP_RXBCAST | MBP_RXMCAST;
MBP_RXMCAST; priv->regs->unicast_enable = 0x1;
priv->regs->unicast_enable = 0xff; priv->regs->unicast_clear = 0xfe;
priv->regs->unicast_clear = 0;
priv->regs->buffer_offset = 0; priv->regs->buffer_offset = 0;
for (i = 0; i < 8; i++) for (i = 0; i < 8; i++)
priv->regs->mac_addr_low[i] = dev->dev_addr[5]; priv->regs->mac_addr_low[i] = dev->dev_addr[5];
priv->regs->mac_addr_mid = dev->dev_addr[4]; priv->regs->mac_addr_mid = dev->dev_addr[4];
priv->regs->mac_addr_high = dev->dev_addr[0] | (dev->dev_addr[1] << 8) priv->regs->mac_addr_high = dev->dev_addr[0] | (dev->dev_addr[1] << 8)
| (dev->dev_addr[2] << 16) | (dev->dev_addr[3] << 24); | (dev->dev_addr[2] << 16) | (dev->dev_addr[3] << 24);
priv->regs->max_len = 1536; priv->regs->max_len = CPMAC_SKB_SIZE;
priv->regs->rx_int.enable = 0xff; priv->regs->rx_int.enable = 0x1;
priv->regs->rx_int.clear = 0; priv->regs->rx_int.clear = 0xfe;
priv->regs->tx_int.enable = 0xff; priv->regs->tx_int.enable = 0xff;
priv->regs->tx_int.clear = 0; priv->regs->tx_int.clear = 0;
priv->regs->mac_int_enable = 3; priv->regs->mac_int_enable = 3;
@ -809,12 +832,18 @@ int cpmac_open(struct net_device *dev)
return 0; return 0;
fail_irq: fail_irq:
for(i = 0; i < 8; i++) fail_desc:
if (priv->rx_channels[i]->skb) for (i = 0; i < CPMAC_RX_RING_SIZE; i++)
kfree_skb(priv->rx_channels[i]->skb); if (priv->rx_head[i].skb)
free_pages(priv->pages, priv->order); kfree_skb(priv->rx_head[i].skb);
fail_alloc: fail_alloc:
kfree(priv->desc_ring);
for (skb = priv->skb_pool; skb; skb = priv->skb_pool) {
priv->skb_pool = skb->next;
kfree_skb(skb);
}
iounmap(priv->regs); iounmap(priv->regs);
fail_remap: fail_remap:
@ -827,9 +856,10 @@ fail_reserve:
return res; return res;
} }
int cpmac_stop(struct net_device *dev) static int cpmac_stop(struct net_device *dev)
{ {
int i; int i;
struct sk_buff *skb;
struct cpmac_priv *priv = netdev_priv(dev); struct cpmac_priv *priv = netdev_priv(dev);
netif_stop_queue(dev); netif_stop_queue(dev);
@ -850,18 +880,27 @@ int cpmac_stop(struct net_device *dev)
release_mem_region(dev->mem_start, dev->mem_end - release_mem_region(dev->mem_start, dev->mem_end -
dev->mem_start); dev->mem_start);
for(i = 0; i < 8; i++) cancel_delayed_work(&priv->alloc_work);
if (priv->rx_channels[i]->skb) flush_scheduled_work();
kfree_skb(priv->rx_channels[i]->skb);
if (priv->pages) priv->rx_head = &priv->desc_ring[CPMAC_TX_RING_SIZE];
free_pages(priv->pages, priv->order); for (i = 0; i < CPMAC_RX_RING_SIZE; i++)
if (priv->rx_head[i].skb)
kfree_skb(priv->rx_head[i].skb);
kfree(priv->desc_ring);
for (skb = priv->skb_pool; skb; skb = priv->skb_pool) {
priv->skb_pool = skb->next;
kfree_skb(skb);
}
return 0; return 0;
} }
static int external_switch = 0; static int external_switch = 0;
int __devinit cpmac_probe(struct platform_device *pdev) static int __devinit cpmac_probe(struct platform_device *pdev)
{ {
int i, rc, phy_id; int i, rc, phy_id;
struct resource *res; struct resource *res;
@ -929,6 +968,7 @@ int __devinit cpmac_probe(struct platform_device *pdev)
spin_lock_init(&priv->lock); spin_lock_init(&priv->lock);
priv->msg_enable = netif_msg_init(NETIF_MSG_WOL, 0x3fff); priv->msg_enable = netif_msg_init(NETIF_MSG_WOL, 0x3fff);
priv->config = pdata; priv->config = pdata;
priv->dev = dev;
memcpy(dev->dev_addr, priv->config->dev_addr, sizeof(dev->dev_addr)); memcpy(dev->dev_addr, priv->config->dev_addr, sizeof(dev->dev_addr));
if (phy_id == 31) { if (phy_id == 31) {
snprintf(priv->phy_name, BUS_ID_SIZE, PHY_ID_FMT, snprintf(priv->phy_name, BUS_ID_SIZE, PHY_ID_FMT,
@ -988,9 +1028,9 @@ int __devinit cpmac_init(void)
#warning FIXME: unhardcode gpio&reset bits #warning FIXME: unhardcode gpio&reset bits
ar7_gpio_disable(26); ar7_gpio_disable(26);
ar7_gpio_disable(27); ar7_gpio_disable(27);
/* ar7_device_reset(17); ar7_device_reset(17);
ar7_device_reset(21); ar7_device_reset(21);
ar7_device_reset(26);*/ ar7_device_reset(26);
cpmac_mii.reset(&cpmac_mii); cpmac_mii.reset(&cpmac_mii);