| 1 |
/* |
|---|
| 2 |
* ar2313.c: Linux driver for the Atheros AR231x Ethernet device. |
|---|
| 3 |
* |
|---|
| 4 |
* Copyright (C) 2004 by Sameer Dekate <sdekate@arubanetworks.com> |
|---|
| 5 |
* Copyright (C) 2006 Imre Kaloz <kaloz@openwrt.org> |
|---|
| 6 |
* Copyright (C) 2006-2007 Felix Fietkau <nbd@openwrt.org> |
|---|
| 7 |
* |
|---|
| 8 |
* Thanks to Atheros for providing hardware and documentation |
|---|
| 9 |
* enabling me to write this driver. |
|---|
| 10 |
* |
|---|
| 11 |
* This program is free software; you can redistribute it and/or modify |
|---|
| 12 |
* it under the terms of the GNU General Public License as published by |
|---|
| 13 |
* the Free Software Foundation; either version 2 of the License, or |
|---|
| 14 |
* (at your option) any later version. |
|---|
| 15 |
* |
|---|
| 16 |
* Additional credits: |
|---|
| 17 |
* This code is taken from John Taylor's Sibyte driver and then |
|---|
| 18 |
* modified for the AR2313. |
|---|
| 19 |
*/ |
|---|
| 20 |
|
|---|
| 21 |
#include <linux/autoconf.h> |
|---|
| 22 |
#include <linux/module.h> |
|---|
| 23 |
#include <linux/version.h> |
|---|
| 24 |
#include <linux/types.h> |
|---|
| 25 |
#include <linux/errno.h> |
|---|
| 26 |
#include <linux/ioport.h> |
|---|
| 27 |
#include <linux/pci.h> |
|---|
| 28 |
#include <linux/netdevice.h> |
|---|
| 29 |
#include <linux/etherdevice.h> |
|---|
| 30 |
#include <linux/skbuff.h> |
|---|
| 31 |
#include <linux/init.h> |
|---|
| 32 |
#include <linux/delay.h> |
|---|
| 33 |
#include <linux/mm.h> |
|---|
| 34 |
#include <linux/highmem.h> |
|---|
| 35 |
#include <linux/sockios.h> |
|---|
| 36 |
#include <linux/pkt_sched.h> |
|---|
| 37 |
#include <linux/compile.h> |
|---|
| 38 |
#include <linux/mii.h> |
|---|
| 39 |
#include <linux/phy.h> |
|---|
| 40 |
#include <linux/ethtool.h> |
|---|
| 41 |
#include <linux/ctype.h> |
|---|
| 42 |
#include <linux/platform_device.h> |
|---|
| 43 |
|
|---|
| 44 |
#include <net/sock.h> |
|---|
| 45 |
#include <net/ip.h> |
|---|
| 46 |
|
|---|
| 47 |
#include <asm/system.h> |
|---|
| 48 |
#include <asm/io.h> |
|---|
| 49 |
#include <asm/irq.h> |
|---|
| 50 |
#include <asm/byteorder.h> |
|---|
| 51 |
#include <asm/uaccess.h> |
|---|
| 52 |
#include <asm/bootinfo.h> |
|---|
| 53 |
|
|---|
| 54 |
#define AR2313_MTU 1518 |
|---|
| 55 |
#define AR2313_PRIOS 1 |
|---|
| 56 |
#define AR2313_QUEUES (2*AR2313_PRIOS) |
|---|
| 57 |
#define AR2313_DESCR_ENTRIES 64 |
|---|
| 58 |
|
|---|
| 59 |
#undef INDEX_DEBUG |
|---|
| 60 |
#define DEBUG 0 |
|---|
| 61 |
#define DEBUG_TX 0 |
|---|
| 62 |
#define DEBUG_RX 0 |
|---|
| 63 |
#define DEBUG_INT 0 |
|---|
| 64 |
#define DEBUG_MC 0 |
|---|
| 65 |
#define DEBUG_ERR 1 |
|---|
| 66 |
|
|---|
| 67 |
#ifndef min |
|---|
| 68 |
#define min(a,b) (((a)<(b))?(a):(b)) |
|---|
| 69 |
#endif |
|---|
| 70 |
|
|---|
| 71 |
#ifndef SMP_CACHE_BYTES |
|---|
| 72 |
#define SMP_CACHE_BYTES L1_CACHE_BYTES |
|---|
| 73 |
#endif |
|---|
| 74 |
|
|---|
| 75 |
#define AR2313_MBOX_SET_BIT 0x8 |
|---|
| 76 |
|
|---|
| 77 |
#define BOARD_IDX_STATIC 0 |
|---|
| 78 |
#define BOARD_IDX_OVERFLOW -1 |
|---|
| 79 |
|
|---|
| 80 |
#include "dma.h" |
|---|
| 81 |
#include "ar2313.h" |
|---|
| 82 |
|
|---|
| 83 |
/* |
|---|
| 84 |
* New interrupt handler strategy: |
|---|
| 85 |
* |
|---|
| 86 |
* An old interrupt handler worked using the traditional method of |
|---|
| 87 |
* replacing an skbuff with a new one when a packet arrives. However |
|---|
| 88 |
* the rx rings do not need to contain a static number of buffer |
|---|
| 89 |
* descriptors, thus it makes sense to move the memory allocation out |
|---|
| 90 |
* of the main interrupt handler and do it in a bottom half handler |
|---|
| 91 |
* and only allocate new buffers when the number of buffers in the |
|---|
| 92 |
* ring is below a certain threshold. In order to avoid starving the |
|---|
| 93 |
* NIC under heavy load it is however necessary to force allocation |
|---|
| 94 |
* when hitting a minimum threshold. The strategy for alloction is as |
|---|
| 95 |
* follows: |
|---|
| 96 |
* |
|---|
| 97 |
* RX_LOW_BUF_THRES - allocate buffers in the bottom half |
|---|
| 98 |
* RX_PANIC_LOW_THRES - we are very low on buffers, allocate |
|---|
| 99 |
* the buffers in the interrupt handler |
|---|
| 100 |
* RX_RING_THRES - maximum number of buffers in the rx ring |
|---|
| 101 |
* |
|---|
| 102 |
* One advantagous side effect of this allocation approach is that the |
|---|
| 103 |
* entire rx processing can be done without holding any spin lock |
|---|
| 104 |
* since the rx rings and registers are totally independent of the tx |
|---|
| 105 |
* ring and its registers. This of course includes the kmalloc's of |
|---|
| 106 |
* new skb's. Thus start_xmit can run in parallel with rx processing |
|---|
| 107 |
* and the memory allocation on SMP systems. |
|---|
| 108 |
* |
|---|
| 109 |
* Note that running the skb reallocation in a bottom half opens up |
|---|
| 110 |
* another can of races which needs to be handled properly. In |
|---|
| 111 |
* particular it can happen that the interrupt handler tries to run |
|---|
| 112 |
* the reallocation while the bottom half is either running on another |
|---|
| 113 |
* CPU or was interrupted on the same CPU. To get around this the |
|---|
| 114 |
* driver uses bitops to prevent the reallocation routines from being |
|---|
| 115 |
* reentered. |
|---|
| 116 |
* |
|---|
| 117 |
* TX handling can also be done without holding any spin lock, wheee |
|---|
| 118 |
* this is fun! since tx_csm is only written to by the interrupt |
|---|
| 119 |
* handler. |
|---|
| 120 |
*/ |
|---|
| 121 |
|
|---|
| 122 |
/* |
|---|
| 123 |
* Threshold values for RX buffer allocation - the low water marks for |
|---|
| 124 |
* when to start refilling the rings are set to 75% of the ring |
|---|
| 125 |
* sizes. It seems to make sense to refill the rings entirely from the |
|---|
| 126 |
* intrrupt handler once it gets below the panic threshold, that way |
|---|
| 127 |
* we don't risk that the refilling is moved to another CPU when the |
|---|
| 128 |
* one running the interrupt handler just got the slab code hot in its |
|---|
| 129 |
* cache. |
|---|
| 130 |
*/ |
|---|
| 131 |
#define RX_RING_SIZE AR2313_DESCR_ENTRIES |
|---|
| 132 |
#define RX_PANIC_THRES (RX_RING_SIZE/4) |
|---|
| 133 |
#define RX_LOW_THRES ((3*RX_RING_SIZE)/4) |
|---|
| 134 |
#define CRC_LEN 4 |
|---|
| 135 |
#define RX_OFFSET 2 |
|---|
| 136 |
|
|---|
| 137 |
#if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE) |
|---|
| 138 |
#define VLAN_HDR 4 |
|---|
| 139 |
#else |
|---|
| 140 |
#define VLAN_HDR 0 |
|---|
| 141 |
#endif |
|---|
| 142 |
|
|---|
| 143 |
#define RXBUFF_RESERVE 96 |
|---|
| 144 |
|
|---|
| 145 |
//#define AR2313_BUFSIZE (((RXBUFF_RESERVE + ETH_HLEN + AR2313_MTU + VLAN_HDR + 4) + 3) & ~3) |
|---|
| 146 |
|
|---|
| 147 |
#define AR2313_BUFSIZE (AR2313_MTU + VLAN_HDR + ETH_HLEN + CRC_LEN + RX_OFFSET) |
|---|
| 148 |
|
|---|
| 149 |
#ifdef MODULE |
|---|
| 150 |
MODULE_LICENSE("GPL"); |
|---|
| 151 |
MODULE_AUTHOR("Sameer Dekate <sdekate@arubanetworks.com>, Imre Kaloz <kaloz@openwrt.org>, Felix Fietkau <nbd@openwrt.org>"); |
|---|
| 152 |
MODULE_DESCRIPTION("AR2313 Ethernet driver"); |
|---|
| 153 |
#endif |
|---|
| 154 |
|
|---|
| 155 |
#define virt_to_phys(x) ((u32)(x) & 0x1fffffff) |
|---|
| 156 |
|
|---|
| 157 |
// prototypes |
|---|
| 158 |
#ifdef TX_TIMEOUT |
|---|
| 159 |
static void ar2313_tx_timeout(struct net_device *dev); |
|---|
| 160 |
#endif |
|---|
| 161 |
static void ar2313_halt(struct net_device *dev); |
|---|
| 162 |
static void rx_tasklet_func(unsigned long data); |
|---|
| 163 |
static void rx_tasklet_cleanup(struct net_device *dev); |
|---|
| 164 |
static void ar2313_multicast_list(struct net_device *dev); |
|---|
| 165 |
|
|---|
| 166 |
static int mdiobus_read(struct mii_bus *bus, int phy_addr, int regnum); |
|---|
| 167 |
static int mdiobus_write(struct mii_bus *bus, int phy_addr, int regnum, u16 value); |
|---|
| 168 |
static int mdiobus_reset(struct mii_bus *bus); |
|---|
| 169 |
static int mdiobus_probe (struct net_device *dev); |
|---|
| 170 |
static void ar2313_adjust_link(struct net_device *dev); |
|---|
| 171 |
|
|---|
| 172 |
#ifndef ERR |
|---|
| 173 |
#define ERR(fmt, args...) printk("%s: " fmt, __func__, ##args) |
|---|
| 174 |
#endif |
|---|
| 175 |
|
|---|
| 176 |
|
|---|
| 177 |
int __init ar2313_probe(struct platform_device *pdev) |
|---|
| 178 |
{ |
|---|
| 179 |
struct net_device *dev; |
|---|
| 180 |
struct ar2313_private *sp; |
|---|
| 181 |
struct resource *res; |
|---|
| 182 |
unsigned long ar_eth_base; |
|---|
| 183 |
char buf[64]; |
|---|
| 184 |
|
|---|
| 185 |
dev = alloc_etherdev(sizeof(struct ar2313_private)); |
|---|
| 186 |
|
|---|
| 187 |
if (dev == NULL) { |
|---|
| 188 |
printk(KERN_ERR |
|---|
| 189 |
"ar2313: Unable to allocate net_device structure!\n"); |
|---|
| 190 |
return -ENOMEM; |
|---|
| 191 |
} |
|---|
| 192 |
|
|---|
| 193 |
platform_set_drvdata(pdev, dev); |
|---|
| 194 |
|
|---|
| 195 |
sp = netdev_priv(dev); |
|---|
| 196 |
sp->dev = dev; |
|---|
| 197 |
sp->cfg = pdev->dev.platform_data; |
|---|
| 198 |
|
|---|
| 199 |
sprintf(buf, "eth%d_membase", pdev->id); |
|---|
| 200 |
res = platform_get_resource_byname(pdev, IORESOURCE_MEM, buf); |
|---|
| 201 |
if (!res) |
|---|
| 202 |
return -ENODEV; |
|---|
| 203 |
|
|---|
| 204 |
sp->link = 0; |
|---|
| 205 |
ar_eth_base = res->start; |
|---|
| 206 |
sp->phy = sp->cfg->phy; |
|---|
| 207 |
|
|---|
| 208 |
sprintf(buf, "eth%d_irq", pdev->id); |
|---|
| 209 |
dev->irq = platform_get_irq_byname(pdev, buf); |
|---|
| 210 |
|
|---|
| 211 |
spin_lock_init(&sp->lock); |
|---|
| 212 |
|
|---|
| 213 |
/* initialize func pointers */ |
|---|
| 214 |
dev->open = &ar2313_open; |
|---|
| 215 |
dev->stop = &ar2313_close; |
|---|
| 216 |
dev->hard_start_xmit = &ar2313_start_xmit; |
|---|
| 217 |
|
|---|
| 218 |
dev->set_multicast_list = &ar2313_multicast_list; |
|---|
| 219 |
#ifdef TX_TIMEOUT |
|---|
| 220 |
dev->tx_timeout = ar2313_tx_timeout; |
|---|
| 221 |
dev->watchdog_timeo = AR2313_TX_TIMEOUT; |
|---|
| 222 |
#endif |
|---|
| 223 |
dev->do_ioctl = &ar2313_ioctl; |
|---|
| 224 |
|
|---|
| 225 |
// SAMEER: do we need this? |
|---|
| 226 |
// dev->features |= NETIF_F_SG | NETIF_F_HIGHDMA; |
|---|
| 227 |
dev->features |= NETIF_F_HIGHDMA; |
|---|
| 228 |
// dev->features |= NETIF_F_HIGHDMA | NETIF_F_HW_CSUM; |
|---|
| 229 |
|
|---|
| 230 |
tasklet_init(&sp->rx_tasklet, rx_tasklet_func, (unsigned long) dev); |
|---|
| 231 |
tasklet_disable(&sp->rx_tasklet); |
|---|
| 232 |
|
|---|
| 233 |
sp->eth_regs = |
|---|
| 234 |
ioremap_nocache(virt_to_phys(ar_eth_base), sizeof(*sp->eth_regs)); |
|---|
| 235 |
if (!sp->eth_regs) { |
|---|
| 236 |
printk("Can't remap eth registers\n"); |
|---|
| 237 |
return (-ENXIO); |
|---|
| 238 |
} |
|---|
| 239 |
|
|---|
| 240 |
/* |
|---|
| 241 |
* When there's only one MAC, PHY regs are typically on ENET0, |
|---|
| 242 |
* even though the MAC might be on ENET1. |
|---|
| 243 |
* Needto remap PHY regs separately in this case |
|---|
| 244 |
*/ |
|---|
| 245 |
if (virt_to_phys(ar_eth_base) == virt_to_phys(sp->phy_regs)) |
|---|
| 246 |
sp->phy_regs = sp->eth_regs; |
|---|
| 247 |
else { |
|---|
| 248 |
sp->phy_regs = |
|---|
| 249 |
ioremap_nocache(virt_to_phys(sp->cfg->phy_base), |
|---|
| 250 |
sizeof(*sp->phy_regs)); |
|---|
| 251 |
if (!sp->phy_regs) { |
|---|
| 252 |
printk("Can't remap phy registers\n"); |
|---|
| 253 |
return (-ENXIO); |
|---|
| 254 |
} |
|---|
| 255 |
} |
|---|
| 256 |
|
|---|
| 257 |
sp->dma_regs = |
|---|
| 258 |
ioremap_nocache(virt_to_phys(ar_eth_base + 0x1000), |
|---|
| 259 |
sizeof(*sp->dma_regs)); |
|---|
| 260 |
dev->base_addr = (unsigned int) sp->dma_regs; |
|---|
| 261 |
if (!sp->dma_regs) { |
|---|
| 262 |
printk("Can't remap DMA registers\n"); |
|---|
| 263 |
return (-ENXIO); |
|---|
| 264 |
} |
|---|
| 265 |
|
|---|
| 266 |
sp->int_regs = ioremap_nocache(virt_to_phys(sp->cfg->reset_base), 4); |
|---|
| 267 |
if (!sp->int_regs) { |
|---|
| 268 |
printk("Can't remap INTERRUPT registers\n"); |
|---|
| 269 |
return (-ENXIO); |
|---|
| 270 |
} |
|---|
| 271 |
|
|---|
| 272 |
strncpy(sp->name, "Atheros AR231x", sizeof(sp->name) - 1); |
|---|
| 273 |
sp->name[sizeof(sp->name) - 1] = '\0'; |
|---|
| 274 |
memcpy(dev->dev_addr, sp->cfg->macaddr, 6); |
|---|
| 275 |
sp->board_idx = BOARD_IDX_STATIC; |
|---|
| 276 |
|
|---|
| 277 |
if (ar2313_init(dev)) { |
|---|
| 278 |
/* |
|---|
| 279 |
* ar2313_init() calls ar2313_init_cleanup() on error. |
|---|
| 280 |
*/ |
|---|
| 281 |
kfree(dev); |
|---|
| 282 |
return -ENODEV; |
|---|
| 283 |
} |
|---|
| 284 |
|
|---|
| 285 |
if (register_netdev(dev)) { |
|---|
| 286 |
printk("%s: register_netdev failed\n", __func__); |
|---|
| 287 |
return -1; |
|---|
| 288 |
} |
|---|
| 289 |
|
|---|
| 290 |
printk("%s: %s: %02x:%02x:%02x:%02x:%02x:%02x, irq %d\n", |
|---|
| 291 |
dev->name, sp->name, |
|---|
| 292 |
dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2], |
|---|
| 293 |
dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5], dev->irq); |
|---|
| 294 |
|
|---|
| 295 |
sp->mii_bus.priv = dev; |
|---|
| 296 |
sp->mii_bus.read = mdiobus_read; |
|---|
| 297 |
sp->mii_bus.write = mdiobus_write; |
|---|
| 298 |
sp->mii_bus.reset = mdiobus_reset; |
|---|
| 299 |
sp->mii_bus.name = "ar2313_eth_mii"; |
|---|
| 300 |
sp->mii_bus.id = pdev->id; |
|---|
| 301 |
sp->mii_bus.irq = kmalloc(sizeof(int), GFP_KERNEL); |
|---|
| 302 |
*sp->mii_bus.irq = PHY_POLL; |
|---|
| 303 |
|
|---|
| 304 |
mdiobus_register(&sp->mii_bus); |
|---|
| 305 |
|
|---|
| 306 |
if (mdiobus_probe(dev) != 0) { |
|---|
| 307 |
printk(KERN_ERR "ar2313: mdiobus_probe failed"); |
|---|
| 308 |
rx_tasklet_cleanup(dev); |
|---|
| 309 |
ar2313_init_cleanup(dev); |
|---|
| 310 |
unregister_netdev(dev); |
|---|
| 311 |
kfree(dev); |
|---|
| 312 |
} else { |
|---|
| 313 |
/* start link poll timer */ |
|---|
| 314 |
ar2313_setup_timer(dev); |
|---|
| 315 |
} |
|---|
| 316 |
|
|---|
| 317 |
return 0; |
|---|
| 318 |
} |
|---|
| 319 |
|
|---|
| 320 |
#if 0 |
|---|
| 321 |
static void ar2313_dump_regs(struct net_device *dev) |
|---|
| 322 |
{ |
|---|
| 323 |
unsigned int *ptr, i; |
|---|
| 324 |
struct ar2313_private *sp = netdev_priv(dev); |
|---|
| 325 |
|
|---|
| 326 |
ptr = (unsigned int *) sp->eth_regs; |
|---|
| 327 |
for (i = 0; i < (sizeof(ETHERNET_STRUCT) / sizeof(unsigned int)); |
|---|
| 328 |
i++, ptr++) { |
|---|
| 329 |
printk("ENET: %08x = %08x\n", (int) ptr, *ptr); |
|---|
| 330 |
} |
|---|
| 331 |
|
|---|
| 332 |
ptr = (unsigned int *) sp->dma_regs; |
|---|
| 333 |
for (i = 0; i < (sizeof(DMA) / sizeof(unsigned int)); i++, ptr++) { |
|---|
| 334 |
printk("DMA: %08x = %08x\n", (int) ptr, *ptr); |
|---|
| 335 |
} |
|---|
| 336 |
|
|---|
| 337 |
ptr = (unsigned int *) sp->int_regs; |
|---|
| 338 |
for (i = 0; i < (sizeof(INTERRUPT) / sizeof(unsigned int)); i++, ptr++) { |
|---|
| 339 |
printk("INT: %08x = %08x\n", (int) ptr, *ptr); |
|---|
| 340 |
} |
|---|
| 341 |
|
|---|
| 342 |
for (i = 0; i < AR2313_DESCR_ENTRIES; i++) { |
|---|
| 343 |
ar2313_descr_t *td = &sp->tx_ring[i]; |
|---|
| 344 |
printk("Tx desc %2d: %08x %08x %08x %08x\n", i, |
|---|
| 345 |
td->status, td->devcs, td->addr, td->descr); |
|---|
| 346 |
} |
|---|
| 347 |
} |
|---|
| 348 |
#endif |
|---|
| 349 |
|
|---|
| 350 |
#ifdef TX_TIMEOUT |
|---|
| 351 |
static void ar2313_tx_timeout(struct net_device *dev) |
|---|
| 352 |
{ |
|---|
| 353 |
struct ar2313_private *sp = netdev_priv(dev); |
|---|
| 354 |
unsigned long flags; |
|---|
| 355 |
|
|---|
| 356 |
#if DEBUG_TX |
|---|
| 357 |
printk("Tx timeout\n"); |
|---|
| 358 |
#endif |
|---|
| 359 |
spin_lock_irqsave(&sp->lock, flags); |
|---|
| 360 |
ar2313_restart(dev); |
|---|
| 361 |
spin_unlock_irqrestore(&sp->lock, flags); |
|---|
| 362 |
} |
|---|
| 363 |
#endif |
|---|
| 364 |
|
|---|
| 365 |
#if DEBUG_MC |
|---|
| 366 |
static void printMcList(struct net_device *dev) |
|---|
| 367 |
{ |
|---|
| 368 |
struct dev_mc_list *list = dev->mc_list; |
|---|
| 369 |
int num = 0, i; |
|---|
| 370 |
while (list) { |
|---|
| 371 |
printk("%d MC ADDR ", num); |
|---|
| 372 |
for (i = 0; i < list->dmi_addrlen; i++) { |
|---|
| 373 |
printk(":%02x", list->dmi_addr[i]); |
|---|
| 374 |
} |
|---|
| 375 |
list = list->next; |
|---|
| 376 |
printk("\n"); |
|---|
| 377 |
} |
|---|
| 378 |
} |
|---|
| 379 |
#endif |
|---|
| 380 |
|
|---|
| 381 |
/* |
|---|
| 382 |
* Set or clear the multicast filter for this adaptor. |
|---|
| 383 |
* THIS IS ABSOLUTE CRAP, disabled |
|---|
| 384 |
*/ |
|---|
| 385 |
static void ar2313_multicast_list(struct net_device *dev) |
|---|
| 386 |
{ |
|---|
| 387 |
/* |
|---|
| 388 |
* Always listen to broadcasts and |
|---|
| 389 |
* treat IFF bits independently |
|---|
| 390 |
*/ |
|---|
| 391 |
struct ar2313_private *sp = netdev_priv(dev); |
|---|
| 392 |
unsigned int recognise; |
|---|
| 393 |
|
|---|
| 394 |
recognise = sp->eth_regs->mac_control; |
|---|
| 395 |
|
|---|
| 396 |
if (dev->flags & IFF_PROMISC) { /* set promiscuous mode */ |
|---|
| 397 |
recognise |= MAC_CONTROL_PR; |
|---|
| 398 |
} else { |
|---|
| 399 |
recognise &= ~MAC_CONTROL_PR; |
|---|
| 400 |
} |
|---|
| 401 |
|
|---|
| 402 |
if ((dev->flags & IFF_ALLMULTI) || (dev->mc_count > 15)) { |
|---|
| 403 |
#if DEBUG_MC |
|---|
| 404 |
printMcList(dev); |
|---|
| 405 |
printk("%s: all MULTICAST mc_count %d\n", __FUNCTION__, |
|---|
| 406 |
dev->mc_count); |
|---|
| 407 |
#endif |
|---|
| 408 |
recognise |= MAC_CONTROL_PM; /* all multicast */ |
|---|
| 409 |
} else if (dev->mc_count > 0) { |
|---|
| 410 |
#if DEBUG_MC |
|---|
| 411 |
printMcList(dev); |
|---|
| 412 |
printk("%s: mc_count %d\n", __FUNCTION__, dev->mc_count); |
|---|
| 413 |
#endif |
|---|
| 414 |
recognise |= MAC_CONTROL_PM; /* for the time being */ |
|---|
| 415 |
} |
|---|
| 416 |
#if DEBUG_MC |
|---|
| 417 |
printk("%s: setting %08x to %08x\n", __FUNCTION__, (int) sp->eth_regs, |
|---|
| 418 |
recognise); |
|---|
| 419 |
#endif |
|---|
| 420 |
|
|---|
| 421 |
sp->eth_regs->mac_control = recognise; |
|---|
| 422 |
} |
|---|
| 423 |
|
|---|
| 424 |
static void rx_tasklet_cleanup(struct net_device *dev) |
|---|
| 425 |
{ |
|---|
| 426 |
struct ar2313_private *sp = netdev_priv(dev); |
|---|
| 427 |
|
|---|
| 428 |
/* |
|---|
| 429 |
* Tasklet may be scheduled. Need to get it removed from the list |
|---|
| 430 |
* since we're about to free the struct. |
|---|
| 431 |
*/ |
|---|
| 432 |
|
|---|
| 433 |
sp->unloading = 1; |
|---|
| 434 |
tasklet_enable(&sp->rx_tasklet); |
|---|
| 435 |
tasklet_kill(&sp->rx_tasklet); |
|---|
| 436 |
} |
|---|
| 437 |
|
|---|
| 438 |
static int __exit ar2313_remove(struct platform_device *pdev) |
|---|
| 439 |
{ |
|---|
| 440 |
struct net_device *dev = platform_get_drvdata(pdev); |
|---|
| 441 |
rx_tasklet_cleanup(dev); |
|---|
| 442 |
ar2313_init_cleanup(dev); |
|---|
| 443 |
unregister_netdev(dev); |
|---|
| 444 |
kfree(dev); |
|---|
| 445 |
return 0; |
|---|
| 446 |
} |
|---|
| 447 |
|
|---|
| 448 |
|
|---|
| 449 |
/* |
|---|
| 450 |
* Restart the AR2313 ethernet controller. |
|---|
| 451 |
*/ |
|---|
| 452 |
static int ar2313_restart(struct net_device *dev) |
|---|
| 453 |
{ |
|---|
| 454 |
/* disable interrupts */ |
|---|
| 455 |
disable_irq(dev->irq); |
|---|
| 456 |
|
|---|
| 457 |
/* stop mac */ |
|---|
| 458 |
ar2313_halt(dev); |
|---|
| 459 |
|
|---|
| 460 |
/* initialize */ |
|---|
| 461 |
ar2313_init(dev); |
|---|
| 462 |
|
|---|
| 463 |
/* enable interrupts */ |
|---|
| 464 |
enable_irq(dev->irq); |
|---|
| 465 |
|
|---|
| 466 |
return 0; |
|---|
| 467 |
} |
|---|
| 468 |
|
|---|
| 469 |
static struct platform_driver ar2313_driver = { |
|---|
| 470 |
.driver.name = "ar531x-eth", |
|---|
| 471 |
.probe = ar2313_probe, |
|---|
| 472 |
.remove = ar2313_remove, |
|---|
| 473 |
}; |
|---|
| 474 |
|
|---|
| 475 |
int __init ar2313_module_init(void) |
|---|
| 476 |
{ |
|---|
| 477 |
return platform_driver_register(&ar2313_driver); |
|---|
| 478 |
} |
|---|
| 479 |
|
|---|
| 480 |
void __exit ar2313_module_cleanup(void) |
|---|
| 481 |
{ |
|---|
| 482 |
platform_driver_unregister(&ar2313_driver); |
|---|
| 483 |
} |
|---|
| 484 |
|
|---|
| 485 |
module_init(ar2313_module_init); |
|---|
| 486 |
module_exit(ar2313_module_cleanup); |
|---|
| 487 |
|
|---|
| 488 |
|
|---|
| 489 |
static void ar2313_free_descriptors(struct net_device *dev) |
|---|
| 490 |
{ |
|---|
| 491 |
struct ar2313_private *sp = netdev_priv(dev); |
|---|
| 492 |
if (sp->rx_ring != NULL) { |
|---|
| 493 |
kfree((void *) KSEG0ADDR(sp->rx_ring)); |
|---|
| 494 |
sp->rx_ring = NULL; |
|---|
| 495 |
sp->tx_ring = NULL; |
|---|
| 496 |
} |
|---|
| 497 |
} |
|---|
| 498 |
|
|---|
| 499 |
|
|---|
| 500 |
static int ar2313_allocate_descriptors(struct net_device *dev) |
|---|
| 501 |
{ |
|---|
| 502 |
struct ar2313_private *sp = netdev_priv(dev); |
|---|
| 503 |
int size; |
|---|
| 504 |
int j; |
|---|
| 505 |
ar2313_descr_t *space; |
|---|
| 506 |
|
|---|
| 507 |
if (sp->rx_ring != NULL) { |
|---|
| 508 |
printk("%s: already done.\n", __FUNCTION__); |
|---|
| 509 |
return 0; |
|---|
| 510 |
} |
|---|
| 511 |
|
|---|
| 512 |
size = |
|---|
| 513 |
(sizeof(ar2313_descr_t) * (AR2313_DESCR_ENTRIES * AR2313_QUEUES)); |
|---|
| 514 |
space = kmalloc(size, GFP_KERNEL); |
|---|
| 515 |
if (space == NULL) |
|---|
| 516 |
return 1; |
|---|
| 517 |
|
|---|
| 518 |
/* invalidate caches */ |
|---|
| 519 |
dma_cache_inv((unsigned int) space, size); |
|---|
| 520 |
|
|---|
| 521 |
/* now convert pointer to KSEG1 */ |
|---|
| 522 |
space = (ar2313_descr_t *) KSEG1ADDR(space); |
|---|
| 523 |
|
|---|
| 524 |
memset((void *) space, 0, size); |
|---|
| 525 |
|
|---|
| 526 |
sp->rx_ring = space; |
|---|
| 527 |
space += AR2313_DESCR_ENTRIES; |
|---|
| 528 |
|
|---|
| 529 |
sp->tx_ring = space; |
|---|
| 530 |
space += AR2313_DESCR_ENTRIES; |
|---|
| 531 |
|
|---|
| 532 |
/* Initialize the transmit Descriptors */ |
|---|
| 533 |
for (j = 0; j < AR2313_DESCR_ENTRIES; j++) { |
|---|
| 534 |
ar2313_descr_t *td = &sp->tx_ring[j]; |
|---|
| 535 |
td->status = 0; |
|---|
| 536 |
td->devcs = DMA_TX1_CHAINED; |
|---|
| 537 |
td->addr = 0; |
|---|
| 538 |
td->descr = |
|---|
| 539 |
virt_to_phys(&sp-> |
|---|
| 540 |
tx_ring[(j + 1) & (AR2313_DESCR_ENTRIES - 1)]); |
|---|
| 541 |
} |
|---|
| 542 |
|
|---|
| 543 |
return 0; |
|---|
| 544 |
} |
|---|
| 545 |
|
|---|
| 546 |
|
|---|
| 547 |
/* |
|---|
| 548 |
* Generic cleanup handling data allocated during init. Used when the |
|---|
| 549 |
* module is unloaded or if an error occurs during initialization |
|---|
| 550 |
*/ |
|---|
| 551 |
static void ar2313_init_cleanup(struct net_device *dev) |
|---|
| 552 |
{ |
|---|
| 553 |
struct ar2313_private *sp = netdev_priv(dev); |
|---|
| 554 |
struct sk_buff *skb; |
|---|
| 555 |
int j; |
|---|
| 556 |
|
|---|
| 557 |
ar2313_free_descriptors(dev); |
|---|
| 558 |
|
|---|
| 559 |
if (sp->eth_regs) |
|---|
| 560 |
iounmap((void *) sp->eth_regs); |
|---|
| 561 |
if (sp->dma_regs) |
|---|
| 562 |
iounmap((void *) sp->dma_regs); |
|---|
| 563 |
|
|---|
| 564 |
if (sp->rx_skb) { |
|---|
| 565 |
for (j = 0; j < AR2313_DESCR_ENTRIES; j++) { |
|---|
| 566 |
skb = sp->rx_skb[j]; |
|---|
| 567 |
if (skb) { |
|---|
| 568 |
sp->rx_skb[j] = NULL; |
|---|
| 569 |
dev_kfree_skb(skb); |
|---|
| 570 |
} |
|---|
| 571 |
} |
|---|
| 572 |
kfree(sp->rx_skb); |
|---|
| 573 |
sp->rx_skb = NULL; |
|---|
| 574 |
} |
|---|
| 575 |
|
|---|
| 576 |
if (sp->tx_skb) { |
|---|
| 577 |
for (j = 0; j < AR2313_DESCR_ENTRIES; j++) { |
|---|
| 578 |
skb = sp->tx_skb[j]; |
|---|
| 579 |
if (skb) { |
|---|
| 580 |
sp->tx_skb[j] = NULL; |
|---|
| 581 |
dev_kfree_skb(skb); |
|---|
| 582 |
} |
|---|
| 583 |
} |
|---|
| 584 |
kfree(sp->tx_skb); |
|---|
| 585 |
sp->tx_skb = NULL; |
|---|
| 586 |
} |
|---|
| 587 |
} |
|---|
| 588 |
|
|---|
| 589 |
static int ar2313_setup_timer(struct net_device *dev) |
|---|
| 590 |
{ |
|---|
| 591 |
struct ar2313_private *sp = netdev_priv(dev); |
|---|
| 592 |
|
|---|
| 593 |
init_timer(&sp->link_timer); |
|---|
| 594 |
|
|---|
| 595 |
sp->link_timer.function = ar2313_link_timer_fn; |
|---|
| 596 |
sp->link_timer.data = (int) dev; |
|---|
| 597 |
sp->link_timer.expires = jiffies + HZ; |
|---|
| 598 |
|
|---|
| 599 |
add_timer(&sp->link_timer); |
|---|
| 600 |
return 0; |
|---|
| 601 |
|
|---|
| 602 |
} |
|---|
| 603 |
|
|---|
| 604 |
static void ar2313_link_timer_fn(unsigned long data) |
|---|
| 605 |
{ |
|---|
| 606 |
struct net_device *dev = (struct net_device *) data; |
|---|
| 607 |
struct ar2313_private *sp = netdev_priv(dev); |
|---|
| 608 |
|
|---|
| 609 |
// see if the link status changed |
|---|
| 610 |
// This was needed to make sure we set the PHY to the |
|---|
| 611 |
// autonegotiated value of half or full duplex. |
|---|
| 612 |
ar2313_check_link(dev); |
|---|
| 613 |
|
|---|
| 614 |
// Loop faster when we don't have link. |
|---|
| 615 |
// This was needed to speed up the AP bootstrap time. |
|---|
| 616 |
if (sp->link == 0) { |
|---|
| 617 |
mod_timer(&sp->link_timer, jiffies + HZ / 2); |
|---|
| 618 |
} else { |
|---|
| 619 |
mod_timer(&sp->link_timer, jiffies + LINK_TIMER); |
|---|
| 620 |
} |
|---|
| 621 |
} |
|---|
| 622 |
|
|---|
| 623 |
static void ar2313_check_link(struct net_device *dev) |
|---|
| 624 |
{ |
|---|
| 625 |
struct ar2313_private *sp = netdev_priv(dev); |
|---|
| 626 |
u16 phyData; |
|---|
| 627 |
|
|---|
| 628 |
phyData = mdiobus_read(&sp->mii_bus, sp->phy, MII_BMSR); |
|---|
| 629 |
if (sp->phyData != phyData) { |
|---|
| 630 |
if (phyData & BMSR_LSTATUS) { |
|---|
| 631 |
/* link is present, ready link partner ability to deterine |
|---|
| 632 |
duplexity */ |
|---|
| 633 |
int duplex = 0; |
|---|
| 634 |
u16 reg; |
|---|
| 635 |
|
|---|
| 636 |
sp->link = 1; |
|---|
| 637 |
reg = mdiobus_read(&sp->mii_bus, sp->phy, MII_BMCR); |
|---|
| 638 |
if (reg & BMCR_ANENABLE) { |
|---|
| 639 |
/* auto neg enabled */ |
|---|
| 640 |
reg = mdiobus_read(&sp->mii_bus, sp->phy, MII_LPA); |
|---|
| 641 |
duplex = (reg & (LPA_100FULL | LPA_10FULL)) ? 1 : 0; |
|---|
| 642 |
} else { |
|---|
| 643 |
/* no auto neg, just read duplex config */ |
|---|
| 644 |
duplex = (reg & BMCR_FULLDPLX) ? 1 : 0; |
|---|
| 645 |
} |
|---|
| 646 |
|
|---|
| 647 |
printk(KERN_INFO "%s: Configuring MAC for %s duplex\n", |
|---|
| 648 |
dev->name, (duplex) ? "full" : "half"); |
|---|
| 649 |
|
|---|
| 650 |
if (duplex) { |
|---|
| 651 |
/* full duplex */ |
|---|
| 652 |
sp->eth_regs->mac_control = |
|---|
| 653 |
((sp->eth_regs-> |
|---|
| 654 |
mac_control | MAC_CONTROL_F) & ~MAC_CONTROL_DRO); |
|---|
| 655 |
} else { |
|---|
| 656 |
/* half duplex */ |
|---|
| 657 |
sp->eth_regs->mac_control = |
|---|
| 658 |
((sp->eth_regs-> |
|---|
| 659 |
mac_control | MAC_CONTROL_DRO) & ~MAC_CONTROL_F); |
|---|
| 660 |
} |
|---|
| 661 |
} else { |
|---|
| 662 |
/* no link */ |
|---|
| 663 |
sp->link = 0; |
|---|
| 664 |
} |
|---|
| 665 |
sp->phyData = phyData; |
|---|
| 666 |
} |
|---|
| 667 |
} |
|---|
| 668 |
|
|---|
| 669 |
static int ar2313_reset_reg(struct net_device *dev) |
|---|
| 670 |
{ |
|---|
| 671 |
struct ar2313_private *sp = netdev_priv(dev); |
|---|
| 672 |
unsigned int ethsal, ethsah; |
|---|
| 673 |
unsigned int flags; |
|---|
| 674 |
|
|---|
| 675 |
*sp->int_regs |= sp->cfg->reset_mac; |
|---|
| 676 |
mdelay(10); |
|---|
| 677 |
*sp->int_regs &= ~sp->cfg->reset_mac; |
|---|
| 678 |
mdelay(10); |
|---|
| 679 |
*sp->int_regs |= sp->cfg->reset_phy; |
|---|
| 680 |
mdelay(10); |
|---|
| 681 |
*sp->int_regs &= ~sp->cfg->reset_phy; |
|---|
| 682 |
mdelay(10); |
|---|
| 683 |
|
|---|
| 684 |
sp->dma_regs->bus_mode = (DMA_BUS_MODE_SWR); |
|---|
| 685 |
mdelay(10); |
|---|
| 686 |
sp->dma_regs->bus_mode = |
|---|
| 687 |
((32 << DMA_BUS_MODE_PBL_SHIFT) | DMA_BUS_MODE_BLE); |
|---|
| 688 |
|
|---|
| 689 |
/* enable interrupts */ |
|---|
| 690 |
sp->dma_regs->intr_ena = (DMA_STATUS_AIS | |
|---|
| 691 |
DMA_STATUS_NIS | |
|---|
| 692 |
DMA_STATUS_RI | |
|---|
| 693 |
DMA_STATUS_TI | DMA_STATUS_FBE); |
|---|
| 694 |
sp->dma_regs->xmt_base = virt_to_phys(sp->tx_ring); |
|---|
| 695 |
sp->dma_regs->rcv_base = virt_to_phys(sp->rx_ring); |
|---|
| 696 |
sp->dma_regs->control = |
|---|
| 697 |
(DMA_CONTROL_SR | DMA_CONTROL_ST | DMA_CONTROL_SF); |
|---|
| 698 |
|
|---|
| 699 |
sp->eth_regs->flow_control = (FLOW_CONTROL_FCE); |
|---|
| 700 |
sp->eth_regs->vlan_tag = (0x8100); |
|---|
| 701 |
|
|---|
| 702 |
/* Enable Ethernet Interface */ |
|---|
| 703 |
flags = (MAC_CONTROL_TE | /* transmit enable */ |
|---|
| 704 |
MAC_CONTROL_PM | /* pass mcast */ |
|---|
| 705 |
MAC_CONTROL_F | /* full duplex */ |
|---|
| 706 |
MAC_CONTROL_HBD); /* heart beat disabled */ |
|---|
| 707 |
|
|---|
| 708 |
if (dev->flags & IFF_PROMISC) { /* set promiscuous mode */ |
|---|
| 709 |
flags |= MAC_CONTROL_PR; |
|---|
| 710 |
} |
|---|
| 711 |
sp->eth_regs->mac_control = flags; |
|---|
| 712 |
|
|---|
| 713 |
/* Set all Ethernet station address registers to their initial values */ |
|---|
| 714 |
ethsah = ((((u_int) (dev->dev_addr[5]) << 8) & (u_int) 0x0000FF00) | |
|---|
| 715 |
(((u_int) (dev->dev_addr[4]) << 0) & (u_int) 0x000000FF)); |
|---|
| 716 |
|
|---|
| 717 |
ethsal = ((((u_int) (dev->dev_addr[3]) << 24) & (u_int) 0xFF000000) | |
|---|
| 718 |
(((u_int) (dev->dev_addr[2]) << 16) & (u_int) 0x00FF0000) | |
|---|
| 719 |
(((u_int) (dev->dev_addr[1]) << 8) & (u_int) 0x0000FF00) | |
|---|
| 720 |
(((u_int) (dev->dev_addr[0]) << 0) & (u_int) 0x000000FF)); |
|---|
| 721 |
|
|---|
| 722 |
sp->eth_regs->mac_addr[0] = ethsah; |
|---|
| 723 |
sp->eth_regs->mac_addr[1] = ethsal; |
|---|
| 724 |
|
|---|
| 725 |
mdelay(10); |
|---|
| 726 |
|
|---|
| 727 |
return (0); |
|---|
| 728 |
} |
|---|
| 729 |
|
|---|
| 730 |
|
|---|
| 731 |
static int ar2313_init(struct net_device *dev) |
|---|
| 732 |
{ |
|---|
| 733 |
struct ar2313_private *sp = netdev_priv(dev); |
|---|
| 734 |
int ecode = 0; |
|---|
| 735 |
|
|---|
| 736 |
/* |
|---|
| 737 |
* Allocate descriptors |
|---|
| 738 |
*/ |
|---|
| 739 |
if (ar2313_allocate_descriptors(dev)) { |
|---|
| 740 |
printk("%s: %s: ar2313_allocate_descriptors failed\n", |
|---|
| 741 |
dev->name, __FUNCTION__); |
|---|
| 742 |
ecode = -EAGAIN; |
|---|
| 743 |
goto init_error; |
|---|
| 744 |
} |
|---|
| 745 |
|
|---|
| 746 |
/* |
|---|
| 747 |
* Get the memory for the skb rings. |
|---|
| 748 |
*/ |
|---|
| 749 |
if (sp->rx_skb == NULL) { |
|---|
| 750 |
sp->rx_skb = |
|---|
| 751 |
kmalloc(sizeof(struct sk_buff *) * AR2313_DESCR_ENTRIES, |
|---|
| 752 |
GFP_KERNEL); |
|---|
| 753 |
if (!(sp->rx_skb)) { |
|---|
| 754 |
printk("%s: %s: rx_skb kmalloc failed\n", |
|---|
| 755 |
dev->name, __FUNCTION__); |
|---|
| 756 |
ecode = -EAGAIN; |
|---|
| 757 |
goto init_error; |
|---|
| 758 |
} |
|---|
| 759 |
} |
|---|
| 760 |
memset(sp->rx_skb, 0, sizeof(struct sk_buff *) * AR2313_DESCR_ENTRIES); |
|---|
| 761 |
|
|---|
| 762 |
if (sp->tx_skb == NULL) { |
|---|
| 763 |
sp->tx_skb = |
|---|
| 764 |
kmalloc(sizeof(struct sk_buff *) * AR2313_DESCR_ENTRIES, |
|---|
| 765 |
GFP_KERNEL); |
|---|
| 766 |
if (!(sp->tx_skb)) { |
|---|
| 767 |
printk("%s: %s: tx_skb kmalloc failed\n", |
|---|
| 768 |
dev->name, __FUNCTION__); |
|---|
| 769 |
ecode = -EAGAIN; |
|---|
| 770 |
goto init_error; |
|---|
| 771 |
} |
|---|
| 772 |
} |
|---|
| 773 |
memset(sp->tx_skb, 0, sizeof(struct sk_buff *) * AR2313_DESCR_ENTRIES); |
|---|
| 774 |
|
|---|
| 775 |
/* |
|---|
| 776 |
* Set tx_csm before we start receiving interrupts, otherwise |
|---|
| 777 |
* the interrupt handler might think it is supposed to process |
|---|
| 778 |
* tx ints before we are up and running, which may cause a null |
|---|
| 779 |
* pointer access in the int handler. |
|---|
| 780 |
*/ |
|---|
| 781 |
sp->rx_skbprd = 0; |
|---|
| 782 |
sp->cur_rx = 0; |
|---|
| 783 |
sp->tx_prd = 0; |
|---|
| 784 |
sp->tx_csm = 0; |
|---|
| 785 |
|
|---|
| 786 |
/* |
|---|
| 787 |
* Zero the stats before starting the interface |
|---|
| 788 |
*/ |
|---|
| 789 |
memset(&dev->stats, 0, sizeof(dev->stats)); |
|---|
| 790 |
|
|---|
| 791 |
/* |
|---|
| 792 |
* We load the ring here as there seem to be no way to tell the |
|---|
| 793 |
* firmware to wipe the ring without re-initializing it. |
|---|
| 794 |
*/ |
|---|
| 795 |
ar2313_load_rx_ring(dev, RX_RING_SIZE); |
|---|
| 796 |
|
|---|
| 797 |
/* |
|---|
| 798 |
* Init hardware |
|---|
| 799 |
*/ |
|---|
| 800 |
ar2313_reset_reg(dev); |
|---|
| 801 |
|
|---|
| 802 |
/* |
|---|
| 803 |
* Get the IRQ |
|---|
| 804 |
*/ |
|---|
| 805 |
ecode = |
|---|
| 806 |
request_irq(dev->irq, &ar2313_interrupt, |
|---|
| 807 |
IRQF_SHARED | IRQF_DISABLED | IRQF_SAMPLE_RANDOM, |
|---|
| 808 |
dev->name, dev); |
|---|
| 809 |
if (ecode) { |
|---|
| 810 |
printk(KERN_WARNING "%s: %s: Requested IRQ %d is busy\n", |
|---|
| 811 |
dev->name, __FUNCTION__, dev->irq); |
|---|
| 812 |
goto init_error; |
|---|
| 813 |
} |
|---|
| 814 |
|
|---|
| 815 |
|
|---|
| 816 |
tasklet_enable(&sp->rx_tasklet); |
|---|
| 817 |
|
|---|
| 818 |
return 0; |
|---|
| 819 |
|
|---|
| 820 |
init_error: |
|---|
| 821 |
ar2313_init_cleanup(dev); |
|---|
| 822 |
return ecode; |
|---|
| 823 |
} |
|---|
| 824 |
|
|---|
| 825 |
/* |
|---|
| 826 |
* Load the rx ring. |
|---|
| 827 |
* |
|---|
| 828 |
* Loading rings is safe without holding the spin lock since this is |
|---|
| 829 |
* done only before the device is enabled, thus no interrupts are |
|---|
| 830 |
* generated and by the interrupt handler/tasklet handler. |
|---|
| 831 |
*/ |
|---|
| 832 |
static void ar2313_load_rx_ring(struct net_device *dev, int nr_bufs) |
|---|
| 833 |
{ |
|---|
| 834 |
|
|---|
| 835 |
struct ar2313_private *sp = netdev_priv(dev); |
|---|
| 836 |
short i, idx; |
|---|
| 837 |
|
|---|
| 838 |
idx = sp->rx_skbprd; |
|---|
| 839 |
|
|---|
| 840 |
for (i = 0; i < nr_bufs; i++) { |
|---|
| 841 |
struct sk_buff *skb; |
|---|
| 842 |
ar2313_descr_t *rd; |
|---|
| 843 |
int offset = RX_OFFSET; |
|---|
| 844 |
|
|---|
| 845 |
if (sp->rx_skb[idx]) { |
|---|
| 846 |
#if DEBUG_RX |
|---|
| 847 |
printk(KERN_INFO "ar2313 rx refill full\n"); |
|---|
| 848 |
#endif /* DEBUG */ |
|---|
| 849 |
break; |
|---|
| 850 |
} |
|---|
| 851 |
// partha: create additional room for the second GRE fragment |
|---|
| 852 |
skb = alloc_skb(AR2313_BUFSIZE + 128, GFP_ATOMIC); |
|---|
| 853 |
if (!skb) { |
|---|
| 854 |
printk("\n\n\n\n %s: No memory in system\n\n\n\n", |
|---|
| 855 |
__FUNCTION__); |
|---|
| 856 |
break; |
|---|
| 857 |
} |
|---|
| 858 |
// partha: create additional room in the front for tx pkt capture |
|---|
| 859 |
skb_reserve(skb, 32); |
|---|
| 860 |
|
|---|
| 861 |
/* |
|---|
| 862 |
* Make sure IP header starts on a fresh cache line. |
|---|
| 863 |
*/ |
|---|
| 864 |
skb->dev = dev; |
|---|
| 865 |
if (sp->phy_dev) |
|---|
| 866 |
offset += sp->phy_dev->pkt_align; |
|---|
| 867 |
skb_reserve(skb, offset); |
|---|
| 868 |
sp->rx_skb[idx] = skb; |
|---|
| 869 |
|
|---|
| 870 |
rd = (ar2313_descr_t *) & sp->rx_ring[idx]; |
|---|
| 871 |
|
|---|
| 872 |
/* initialize dma descriptor */ |
|---|
| 873 |
rd->devcs = ((AR2313_BUFSIZE << DMA_RX1_BSIZE_SHIFT) | |
|---|
| 874 |
DMA_RX1_CHAINED); |
|---|
| 875 |
rd->addr = virt_to_phys(skb->data); |
|---|
| 876 |
rd->descr = |
|---|
| 877 |
virt_to_phys(&sp-> |
|---|
| 878 |
rx_ring[(idx + 1) & (AR2313_DESCR_ENTRIES - 1)]); |
|---|
| 879 |
rd->status = DMA_RX_OWN; |
|---|
| 880 |
|
|---|
| 881 |
idx = DSC_NEXT(idx); |
|---|
| 882 |
} |
|---|
| 883 |
|
|---|
| 884 |
if (!i) { |
|---|
| 885 |
#if DEBUG_ERR |
|---|
| 886 |
printk(KERN_INFO |
|---|
| 887 |
"Out of memory when allocating standard receive buffers\n"); |
|---|
| 888 |
#endif /* DEBUG */ |
|---|
| 889 |
} else { |
|---|
| 890 |
sp->rx_skbprd = idx; |
|---|
| 891 |
} |
|---|
| 892 |
|
|---|
| 893 |
return; |
|---|
| 894 |
} |
|---|
| 895 |
|
|---|
| 896 |
#define AR2313_MAX_PKTS_PER_CALL 64 |
|---|
| 897 |
|
|---|
| 898 |
static int ar2313_rx_int(struct net_device *dev) |
|---|
| 899 |
{ |
|---|
| 900 |
struct ar2313_private *sp = netdev_priv(dev); |
|---|
| 901 |
struct sk_buff *skb, *skb_new; |
|---|
| 902 |
ar2313_descr_t *rxdesc; |
|---|
| 903 |
unsigned int status; |
|---|
| 904 |
u32 idx; |
|---|
| 905 |
int pkts = 0; |
|---|
| 906 |
int rval; |
|---|
| 907 |
|
|---|
| 908 |
idx = sp->cur_rx; |
|---|
| 909 |
|
|---|
| 910 |
/* process at most the entire ring and then wait for another interrupt |
|---|
| 911 |
*/ |
|---|
| 912 |
while (1) { |
|---|
| 913 |
|
|---|
| 914 |
rxdesc = &sp->rx_ring[idx]; |
|---|
| 915 |
status = rxdesc->status; |
|---|
| 916 |
if (status & DMA_RX_OWN) { |
|---|
| 917 |
/* SiByte owns descriptor or descr not yet filled in */ |
|---|
| 918 |
rval = 0; |
|---|
| 919 |
break; |
|---|
| 920 |
} |
|---|
| 921 |
|
|---|
| 922 |
if (++pkts > AR2313_MAX_PKTS_PER_CALL) { |
|---|
| 923 |
rval = 1; |
|---|
| 924 |
break; |
|---|
| 925 |
} |
|---|
| 926 |
#if DEBUG_RX |
|---|
| 927 |
printk("index %d\n", idx); |
|---|
| 928 |
printk("RX status %08x\n", rxdesc->status); |
|---|
| 929 |
printk("RX devcs %08x\n", rxdesc->devcs); |
|---|
| 930 |
printk("RX addr %08x\n", rxdesc->addr); |
|---|
| 931 |
printk("RX descr %08x\n", rxdesc->descr); |
|---|
| 932 |
#endif |
|---|
| 933 |
|
|---|
| 934 |
if ((status & DMA_RX_ERROR) && |
|---|
| 935 |
(!(status & DMA_RX_LONG))) { |
|---|
| 936 |
#if DEBUG_RX |
|---|
| 937 |
printk("%s: rx ERROR %08x\n", __FUNCTION__, status); |
|---|
| 938 |
#endif |
|---|
| 939 |
dev->stats.rx_errors++; |
|---|
| 940 |
dev->stats.rx_dropped++; |
|---|
| 941 |
|
|---|
| 942 |
/* add statistics counters */ |
|---|
| 943 |
if (status & DMA_RX_ERR_CRC) |
|---|
| 944 |
dev->stats.rx_crc_errors++; |
|---|
| 945 |
if (status & DMA_RX_ERR_COL) |
|---|
| 946 |
dev->stats.rx_over_errors++; |
|---|
| 947 |
if (status & DMA_RX_ERR_LENGTH) |
|---|
| 948 |
dev->stats.rx_length_errors++; |
|---|
| 949 |
if (status & DMA_RX_ERR_RUNT) |
|---|
| 950 |
dev->stats.rx_over_errors++; |
|---|
| 951 |
if (status & DMA_RX_ERR_DESC) |
|---|
| 952 |
dev->stats.rx_over_errors++; |
|---|
| 953 |
|
|---|
| 954 |
} else { |
|---|
| 955 |
/* alloc new buffer. */ |
|---|
| 956 |
skb_new = dev_alloc_skb(AR2313_BUFSIZE + RX_OFFSET + 128); |
|---|
| 957 |
if (skb_new != NULL) { |
|---|
| 958 |
int offset; |
|---|
| 959 |
|
|---|
| 960 |
skb = sp->rx_skb[idx]; |
|---|
| 961 |
/* set skb */ |
|---|
| 962 |
skb_put(skb, |
|---|
| 963 |
((status >> DMA_RX_LEN_SHIFT) & 0x3fff) - CRC_LEN); |
|---|
| 964 |
|
|---|
| 965 |
dev->stats.rx_bytes += skb->len; |
|---|
| 966 |
|
|---|
| 967 |
/* pass the packet to upper layers */ |
|---|
| 968 |
sp->rx(skb); |
|---|
| 969 |
|
|---|
| 970 |
skb_new->dev = dev; |
|---|
| 971 |
/* 16 bit align */ |
|---|
| 972 |
offset = RX_OFFSET + 32; |
|---|
| 973 |
if (sp->phy_dev) |
|---|
| 974 |
offset += sp->phy_dev->pkt_align; |
|---|
| 975 |
skb_reserve(skb_new, offset); |
|---|
| 976 |
/* reset descriptor's curr_addr */ |
|---|
| 977 |
rxdesc->addr = virt_to_phys(skb_new->data); |
|---|
| 978 |
|
|---|
| 979 |
dev->stats.rx_packets++; |
|---|
| 980 |
sp->rx_skb[idx] = skb_new; |
|---|
| 981 |
} else { |
|---|
| 982 |
dev->stats.rx_dropped++; |
|---|
| 983 |
} |
|---|
| 984 |
} |
|---|
| 985 |
|
|---|
| 986 |
rxdesc->devcs = ((AR2313_BUFSIZE << DMA_RX1_BSIZE_SHIFT) | |
|---|
| 987 |
DMA_RX1_CHAINED); |
|---|
| 988 |
rxdesc->status = DMA_RX_OWN; |
|---|
| 989 |
|
|---|
| 990 |
idx = DSC_NEXT(idx); |
|---|
| 991 |
} |
|---|
| 992 |
|
|---|
| 993 |
sp->cur_rx = idx; |
|---|
| 994 |
|
|---|
| 995 |
return rval; |
|---|
| 996 |
} |
|---|
| 997 |
|
|---|
| 998 |
|
|---|
| 999 |
static void ar2313_tx_int(struct net_device *dev) |
|---|
| 1000 |
{ |
|---|
| 1001 |
struct ar2313_private *sp = netdev_priv(dev); |
|---|
| 1002 |
u32 idx; |
|---|
| 1003 |
struct sk_buff *skb; |
|---|
| 1004 |
ar2313_descr_t *txdesc; |
|---|
| 1005 |
unsigned int status = 0; |
|---|
| 1006 |
|
|---|
| 1007 |
idx = sp->tx_csm; |
|---|
| 1008 |
|
|---|
| 1009 |
while (idx != sp->tx_prd) { |
|---|
| 1010 |
|
|---|
| 1011 |
txdesc = &sp->tx_ring[idx]; |
|---|
| 1012 |
|
|---|
| 1013 |
#if DEBUG_TX |
|---|
| 1014 |
printk |
|---|
| 1015 |
("%s: TXINT: csm=%d idx=%d prd=%d status=%x devcs=%x addr=%08x descr=%x\n", |
|---|
| 1016 |
dev->name, sp->tx_csm, idx, sp->tx_prd, txdesc->status, |
|---|
| 1017 |
txdesc->devcs, txdesc->addr, txdesc->descr); |
|---|
| 1018 |
#endif /* DEBUG */ |
|---|
| 1019 |
|
|---|
| 1020 |
if ((status = txdesc->status) & DMA_TX_OWN) { |
|---|
| 1021 |
/* ar2313 dma still owns descr */ |
|---|
| 1022 |
break; |
|---|
| 1023 |
} |
|---|
| 1024 |
/* done with this descriptor */ |
|---|
| 1025 |
dma_unmap_single(NULL, txdesc->addr, |
|---|
| 1026 |
txdesc->devcs & DMA_TX1_BSIZE_MASK, |
|---|
| 1027 |
DMA_TO_DEVICE); |
|---|
| 1028 |
txdesc->status = 0; |
|---|
| 1029 |
|
|---|
| 1030 |
if (status & DMA_TX_ERROR) { |
|---|
| 1031 |
dev->stats.tx_errors++; |
|---|
| 1032 |
dev->stats.tx_dropped++; |
|---|
| 1033 |
if (status & DMA_TX_ERR_UNDER) |
|---|
| 1034 |
dev->stats.tx_fifo_errors++; |
|---|
| 1035 |
if (status & DMA_TX_ERR_HB) |
|---|
| 1036 |
dev->stats.tx_heartbeat_errors++; |
|---|
| 1037 |
if (status & (DMA_TX_ERR_LOSS | DMA_TX_ERR_LINK)) |
|---|
| 1038 |
dev->stats.tx_carrier_errors++; |
|---|
| 1039 |
if (status & (DMA_TX_ERR_LATE | |
|---|
| 1040 |
DMA_TX_ERR_COL | |
|---|
| 1041 |
DMA_TX_ERR_JABBER | DMA_TX_ERR_DEFER)) |
|---|
| 1042 |
dev->stats.tx_aborted_errors++; |
|---|
| 1043 |
} else { |
|---|
| 1044 |
/* transmit OK */ |
|---|
| 1045 |
dev->stats.tx_packets++; |
|---|
| 1046 |
} |
|---|
| 1047 |
|
|---|
| 1048 |
skb = sp->tx_skb[idx]; |
|---|
| 1049 |
sp->tx_skb[idx] = NULL; |
|---|
| 1050 |
idx = DSC_NEXT(idx); |
|---|
| 1051 |
dev->stats.tx_bytes += skb->len; |
|---|
| 1052 |
dev_kfree_skb_irq(skb); |
|---|
| 1053 |
} |
|---|
| 1054 |
|
|---|
| 1055 |
sp->tx_csm = idx; |
|---|
| 1056 |
|
|---|
| 1057 |
return; |
|---|
| 1058 |
} |
|---|
| 1059 |
|
|---|
| 1060 |
|
|---|
| 1061 |
static void rx_tasklet_func(unsigned long data) |
|---|
| 1062 |
{ |
|---|
| 1063 |
struct net_device *dev = (struct net_device *) data; |
|---|
| 1064 |
struct ar2313_private *sp = netdev_priv(dev); |
|---|
| 1065 |
|
|---|
| 1066 |
if (sp->unloading) { |
|---|
| 1067 |
return; |
|---|
| 1068 |
} |
|---|
| 1069 |
|
|---|
| 1070 |
if (ar2313_rx_int(dev)) { |
|---|
| 1071 |
tasklet_hi_schedule(&sp->rx_tasklet); |
|---|
| 1072 |
} else { |
|---|
| 1073 |
unsigned long flags; |
|---|
| 1074 |
spin_lock_irqsave(&sp->lock, flags); |
|---|
| 1075 |
sp->dma_regs->intr_ena |= DMA_STATUS_RI; |
|---|
| 1076 |
spin_unlock_irqrestore(&sp->lock, flags); |
|---|
| 1077 |
} |
|---|
| 1078 |
} |
|---|
| 1079 |
|
|---|
| 1080 |
static void rx_schedule(struct net_device *dev) |
|---|
| 1081 |
{ |
|---|
| 1082 |
struct ar2313_private *sp = netdev_priv(dev); |
|---|
| 1083 |
|
|---|
| 1084 |
sp->dma_regs->intr_ena &= ~DMA_STATUS_RI; |
|---|
| 1085 |
|
|---|
| 1086 |
tasklet_hi_schedule(&sp->rx_tasklet); |
|---|
| 1087 |
} |
|---|
| 1088 |
|
|---|
| 1089 |
static irqreturn_t ar2313_interrupt(int irq, void *dev_id) |
|---|
| 1090 |
{ |
|---|
| 1091 |
struct net_device *dev = (struct net_device *) dev_id; |
|---|
| 1092 |
struct ar2313_private *sp = netdev_priv(dev); |
|---|
| 1093 |
unsigned int status, enabled; |
|---|
| 1094 |
|
|---|
| 1095 |
/* clear interrupt */ |
|---|
| 1096 |
/* |
|---|
| 1097 |
* Don't clear RI bit if currently disabled. |
|---|
| 1098 |
*/ |
|---|
| 1099 |
status = sp->dma_regs->status; |
|---|
| 1100 |
enabled = sp->dma_regs->intr_ena; |
|---|
| 1101 |
sp->dma_regs->status = status & enabled; |
|---|
| 1102 |
|
|---|
| 1103 |
if (status & DMA_STATUS_NIS) { |
|---|
| 1104 |
/* normal status */ |
|---|
| 1105 |
/* |
|---|
| 1106 |
* Don't schedule rx processing if interrupt |
|---|
| 1107 |
* is already disabled. |
|---|
| 1108 |
*/ |
|---|
| 1109 |
if (status & enabled & DMA_STATUS_RI) { |
|---|
| 1110 |
/* receive interrupt */ |
|---|
| 1111 |
rx_schedule(dev); |
|---|
| 1112 |
} |
|---|
| 1113 |
if (status & DMA_STATUS_TI) { |
|---|
| 1114 |
/* transmit interrupt */ |
|---|
| 1115 |
ar2313_tx_int(dev); |
|---|
| 1116 |
} |
|---|
| 1117 |
} |
|---|
| 1118 |
|
|---|
| 1119 |
if (status & DMA_STATUS_AIS) { |
|---|
| 1120 |
#if DEBUG_INT |
|---|
| 1121 |
printk("%s: AIS set %08x & %x\n", __FUNCTION__, |
|---|
| 1122 |
status, (DMA_STATUS_FBE | DMA_STATUS_TPS)); |
|---|
| 1123 |
#endif |
|---|
| 1124 |
/* abnormal status */ |
|---|
| 1125 |
if (status & (DMA_STATUS_FBE | DMA_STATUS_TPS)) { |
|---|
| 1126 |
ar2313_restart(dev); |
|---|
| 1127 |
} |
|---|
| 1128 |
} |
|---|
| 1129 |
return IRQ_HANDLED; |
|---|
| 1130 |
} |
|---|
| 1131 |
|
|---|
| 1132 |
|
|---|
| 1133 |
static int ar2313_open(struct net_device *dev) |
|---|
| 1134 |
{ |
|---|
| 1135 |
struct ar2313_private *sp = netdev_priv(dev); |
|---|
| 1136 |
unsigned int ethsal, ethsah; |
|---|
| 1137 |
|
|---|
| 1138 |
/* reset the hardware, in case the MAC address changed */ |
|---|
| 1139 |
ethsah = ((((u_int) (dev->dev_addr[5]) << 8) & (u_int) 0x0000FF00) | |
|---|
| 1140 |
(((u_int) (dev->dev_addr[4]) << 0) & (u_int) 0x000000FF)); |
|---|
| 1141 |
|
|---|
| 1142 |
ethsal = ((((u_int) (dev->dev_addr[3]) << 24) & (u_int) 0xFF000000) | |
|---|
| 1143 |
(((u_int) (dev->dev_addr[2]) << 16) & (u_int) 0x00FF0000) | |
|---|
| 1144 |
(((u_int) (dev->dev_addr[1]) << 8) & (u_int) 0x0000FF00) | |
|---|
| 1145 |
(((u_int) (dev->dev_addr[0]) << 0) & (u_int) 0x000000FF)); |
|---|
| 1146 |
|
|---|
| 1147 |
sp->eth_regs->mac_addr[0] = ethsah; |
|---|
| 1148 |
sp->eth_regs->mac_addr[1] = ethsal; |
|---|
| 1149 |
|
|---|
| 1150 |
mdelay(10); |
|---|
| 1151 |
|
|---|
| 1152 |
dev->mtu = 1500; |
|---|
| 1153 |
netif_start_queue(dev); |
|---|
| 1154 |
|
|---|
| 1155 |
sp->eth_regs->mac_control |= MAC_CONTROL_RE; |
|---|
| 1156 |
|
|---|
| 1157 |
return 0; |
|---|
| 1158 |
} |
|---|
| 1159 |
|
|---|
| 1160 |
static void ar2313_halt(struct net_device *dev) |
|---|
| 1161 |
{ |
|---|
| 1162 |
struct ar2313_private *sp = netdev_priv(dev); |
|---|
| 1163 |
int j; |
|---|
| 1164 |
|
|---|
| 1165 |
tasklet_disable(&sp->rx_tasklet); |
|---|
| 1166 |
|
|---|
| 1167 |
/* kill the MAC */ |
|---|
| 1168 |
sp->eth_regs->mac_control &= ~(MAC_CONTROL_RE | /* disable Receives */ |
|---|
| 1169 |
MAC_CONTROL_TE); /* disable Transmits */ |
|---|
| 1170 |
/* stop dma */ |
|---|
| 1171 |
sp->dma_regs->control = 0; |
|---|
| 1172 |
sp->dma_regs->bus_mode = DMA_BUS_MODE_SWR; |
|---|
| 1173 |
|
|---|
| 1174 |
/* place phy and MAC in reset */ |
|---|
| 1175 |
*sp->int_regs |= (sp->cfg->reset_mac | sp->cfg->reset_phy); |
|---|
| 1176 |
|
|---|
| 1177 |
/* free buffers on tx ring */ |
|---|
| 1178 |
for (j = 0; j < AR2313_DESCR_ENTRIES; j++) { |
|---|
| 1179 |
struct sk_buff *skb; |
|---|
| 1180 |
ar2313_descr_t *txdesc; |
|---|
| 1181 |
|
|---|
| 1182 |
txdesc = &sp->tx_ring[j]; |
|---|
| 1183 |
txdesc->descr = 0; |
|---|
| 1184 |
|
|---|
| 1185 |
skb = sp->tx_skb[j]; |
|---|
| 1186 |
if (skb) { |
|---|
| 1187 |
dev_kfree_skb(skb); |
|---|
| 1188 |
sp->tx_skb[j] = NULL; |
|---|
| 1189 |
} |
|---|
| 1190 |
} |
|---|
| 1191 |
} |
|---|
| 1192 |
|
|---|
| 1193 |
/* |
|---|
| 1194 |
* close should do nothing. Here's why. It's called when |
|---|
| 1195 |
* 'ifconfig bond0 down' is run. If it calls free_irq then |
|---|
| 1196 |
* the irq is gone forever ! When bond0 is made 'up' again, |
|---|
| 1197 |
* the ar2313_open () does not call request_irq (). Worse, |
|---|
| 1198 |
* the call to ar2313_halt() generates a WDOG reset due to |
|---|
| 1199 |
* the write to 'sp->int_regs' and the box reboots. |
|---|
| 1200 |
* Commenting this out is good since it allows the |
|---|
| 1201 |
* system to resume when bond0 is made up again. |
|---|
| 1202 |
*/ |
|---|
| 1203 |
static int ar2313_close(struct net_device *dev) |
|---|
| 1204 |
{ |
|---|
| 1205 |
#if 0 |
|---|
| 1206 |
/* |
|---|
| 1207 |
* Disable interrupts |
|---|
| 1208 |
*/ |
|---|
| 1209 |
disable_irq(dev->irq); |
|---|
| 1210 |
|
|---|
| 1211 |
/* |
|---|
| 1212 |
* Without (or before) releasing irq and stopping hardware, this |
|---|
| 1213 |
* is an absolute non-sense, by the way. It will be reset instantly |
|---|
| 1214 |
* by the first irq. |
|---|
| 1215 |
*/ |
|---|
| 1216 |
netif_stop_queue(dev); |
|---|
| 1217 |
|
|---|
| 1218 |
/* stop the MAC and DMA engines */ |
|---|
| 1219 |
ar2313_halt(dev); |
|---|
| 1220 |
|
|---|
| 1221 |
/* release the interrupt */ |
|---|
| 1222 |
free_irq(dev->irq, dev); |
|---|
| 1223 |
|
|---|
| 1224 |
#endif |
|---|
| 1225 |
return 0; |
|---|
| 1226 |
} |
|---|
| 1227 |
|
|---|
| 1228 |
static int ar2313_start_xmit(struct sk_buff *skb, struct net_device *dev) |
|---|
| 1229 |
{ |
|---|
| 1230 |
struct ar2313_private *sp = netdev_priv(dev); |
|---|
| 1231 |
ar2313_descr_t *td; |
|---|
| 1232 |
u32 idx; |
|---|
| 1233 |
|
|---|
| 1234 |
idx = sp->tx_prd; |
|---|
| 1235 |
td = &sp->tx_ring[idx]; |
|---|
| 1236 |
|
|---|
| 1237 |
if (td->status & DMA_TX_OWN) { |
|---|
| 1238 |
#if DEBUG_TX |
|---|
| 1239 |
printk("%s: No space left to Tx\n", __FUNCTION__); |
|---|
| 1240 |
#endif |
|---|
| 1241 |
/* free skbuf and lie to the caller that we sent it out */ |
|---|
| 1242 |
dev->stats.tx_dropped++; |
|---|
| 1243 |
dev_kfree_skb(skb); |
|---|
| 1244 |
|
|---|
| 1245 |
/* restart transmitter in case locked */ |
|---|
| 1246 |
sp->dma_regs->xmt_poll = 0; |
|---|
| 1247 |
return 0; |
|---|
| 1248 |
} |
|---|
| 1249 |
|
|---|
| 1250 |
/* Setup the transmit descriptor. */ |
|---|
| 1251 |
td->devcs = ((skb->len << DMA_TX1_BSIZE_SHIFT) | |
|---|
| 1252 |
(DMA_TX1_LS | DMA_TX1_IC | DMA_TX1_CHAINED)); |
|---|
| 1253 |
td->addr = dma_map_single(NULL, skb->data, skb->len, DMA_TO_DEVICE); |
|---|
| 1254 |
td->status = DMA_TX_OWN; |
|---|
| 1255 |
|
|---|
| 1256 |
/* kick transmitter last */ |
|---|
| 1257 |
sp->dma_regs->xmt_poll = 0; |
|---|
| 1258 |
|
|---|
| 1259 |
#if DEBUG_TX |
|---|
| 1260 |
printk("index %d\n", idx); |
|---|
| 1261 |
printk("TX status %08x\n", td->status); |
|---|
| 1262 |
printk("TX devcs %08x\n", td->devcs); |
|---|
| 1263 |
printk("TX addr %08x\n", td->addr); |
|---|
| 1264 |
printk("TX descr %08x\n", td->descr); |
|---|
| 1265 |
#endif |
|---|
| 1266 |
|
|---|
| 1267 |
sp->tx_skb[idx] = skb; |
|---|
| 1268 |
idx = DSC_NEXT(idx); |
|---|
| 1269 |
sp->tx_prd = idx; |
|---|
| 1270 |
|
|---|
| 1271 |
return 0; |
|---|
| 1272 |
} |
|---|
| 1273 |
static short armiiread (struct net_device *dev, short phy, short reg); |
|---|
| 1274 |
static void armiiwrite (struct net_device *dev, short phy, short reg, |
|---|
| 1275 |
short data); |
|---|
| 1276 |
|
|---|
| 1277 |
static int ar2313_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) |
|---|
| 1278 |
{ |
|---|
| 1279 |
struct mii_ioctl_data *data = (struct mii_ioctl_data *) &ifr->ifr_data; |
|---|
| 1280 |
struct ar2313_private *sp = netdev_priv(dev); |
|---|
| 1281 |
int ret; |
|---|
| 1282 |
|
|---|
| 1283 |
switch (cmd) { |
|---|
| 1284 |
|
|---|
| 1285 |
case SIOCETHTOOL: |
|---|
| 1286 |
spin_lock_irq(&sp->lock); |
|---|
| 1287 |
ret = phy_ethtool_ioctl(sp->phy_dev, (void *) ifr->ifr_data); |
|---|
| 1288 |
spin_unlock_irq(&sp->lock); |
|---|
| 1289 |
return ret; |
|---|
| 1290 |
|
|---|
| 1291 |
case SIOCSIFHWADDR: |
|---|
| 1292 |
if (copy_from_user |
|---|
| 1293 |
(dev->dev_addr, ifr->ifr_data, sizeof(dev->dev_addr))) |
|---|
| 1294 |
return -EFAULT; |
|---|
| 1295 |
return 0; |
|---|
| 1296 |
|
|---|
| 1297 |
case SIOCGIFHWADDR: |
|---|
| 1298 |
if (copy_to_user |
|---|
| 1299 |
(ifr->ifr_data, dev->dev_addr, sizeof(dev->dev_addr))) |
|---|
| 1300 |
return -EFAULT; |
|---|
| 1301 |
return 0; |
|---|
| 1302 |
|
|---|
| 1303 |
case SIOCGMIIPHY: /* Get address of MII PHY in use. */ |
|---|
| 1304 |
data->phy_id = 1; |
|---|
| 1305 |
/* Fall Through */ |
|---|
| 1306 |
|
|---|
| 1307 |
case SIOCGMIIREG: /* Read MII PHY register. */ |
|---|
| 1308 |
data->val_out = armiiread (dev, data->phy_id & 0x1f, |
|---|
| 1309 |
data->reg_num & 0x1f); |
|---|
| 1310 |
return 0; |
|---|
| 1311 |
case SIOCSMIIREG: /* Write MII PHY register. */ |
|---|
| 1312 |
if (!capable (CAP_NET_ADMIN)) |
|---|
| 1313 |
return -EPERM; |
|---|
| 1314 |
armiiwrite (dev, data->phy_id & 0x1f, |
|---|
| 1315 |
data->reg_num & 0x1f, data->val_in); |
|---|
| 1316 |
return 0; |
|---|
| 1317 |
|
|---|
| 1318 |
default: |
|---|
| 1319 |
break; |
|---|
| 1320 |
} |
|---|
| 1321 |
|
|---|
| 1322 |
return -EOPNOTSUPP; |
|---|
| 1323 |
} |
|---|
| 1324 |
|
|---|
| 1325 |
static void ar2313_adjust_link(struct net_device *dev) |
|---|
| 1326 |
{ |
|---|
| 1327 |
struct ar2313_private *sp = netdev_priv(dev); |
|---|
| 1328 |
unsigned int mc; |
|---|
| 1329 |
|
|---|
| 1330 |
if (!sp->phy_dev->link) |
|---|
| 1331 |
return; |
|---|
| 1332 |
|
|---|
| 1333 |
if (sp->phy_dev->duplex != sp->oldduplex) { |
|---|
| 1334 |
mc = readl(&sp->eth_regs->mac_control); |
|---|
| 1335 |
mc &= ~(MAC_CONTROL_F | MAC_CONTROL_DRO); |
|---|
| 1336 |
if (sp->phy_dev->duplex) |
|---|
| 1337 |
mc |= MAC_CONTROL_F; |
|---|
| 1338 |
else |
|---|
| 1339 |
mc |= MAC_CONTROL_DRO; |
|---|
| 1340 |
writel(mc, &sp->eth_regs->mac_control); |
|---|
| 1341 |
sp->oldduplex = sp->phy_dev->duplex; |
|---|
| 1342 |
} |
|---|
| 1343 |
} |
|---|
| 1344 |
|
|---|
| 1345 |
#define MII_ADDR(phy, reg) \ |
|---|
| 1346 |
((reg << MII_ADDR_REG_SHIFT) | (phy << MII_ADDR_PHY_SHIFT)) |
|---|
| 1347 |
|
|---|
| 1348 |
|
|---|
| 1349 |
|
|---|
| 1350 |
|
|---|
| 1351 |
static short |
|---|
| 1352 |
armiiread (struct net_device *dev, short phy, short reg) |
|---|
| 1353 |
{ |
|---|
| 1354 |
|
|---|
| 1355 |
short outp; |
|---|
| 1356 |
|
|---|
| 1357 |
struct ar2313_private *sp = (struct ar2313_private *) dev->priv; |
|---|
| 1358 |
volatile ETHERNET_STRUCT *ethernet = sp->phy_regs; |
|---|
| 1359 |
ethernet->mii_addr = MII_ADDR (phy, reg); |
|---|
| 1360 |
while (ethernet->mii_addr & MII_ADDR_BUSY); |
|---|
| 1361 |
outp = ethernet->mii_data >> MII_DATA_SHIFT; |
|---|
| 1362 |
return (outp); |
|---|
| 1363 |
} |
|---|
| 1364 |
|
|---|
| 1365 |
static void |
|---|
| 1366 |
armiiwrite (struct net_device *dev, short phy, short reg, short data) |
|---|
| 1367 |
{ |
|---|
| 1368 |
struct ar2313_private *sp = (struct ar2313_private *) dev->priv; |
|---|
| 1369 |
volatile ETHERNET_STRUCT *ethernet = sp->phy_regs; |
|---|
| 1370 |
while (ethernet->mii_addr & MII_ADDR_BUSY); |
|---|
| 1371 |
ethernet->mii_data = data << MII_DATA_SHIFT; |
|---|
| 1372 |
ethernet->mii_addr = MII_ADDR (phy, reg) | MII_ADDR_WRITE; |
|---|
| 1373 |
} |
|---|
| 1374 |
|
|---|
| 1375 |
static int |
|---|
| 1376 |
mdiobus_read(struct mii_bus *bus, int phy_addr, int regnum) |
|---|
| 1377 |
{ |
|---|
| 1378 |
struct net_device *const dev = bus->priv; |
|---|
| 1379 |
struct ar2313_private *sp = netdev_priv(dev); |
|---|
| 1380 |
volatile ETHERNET_STRUCT *ethernet = sp->phy_regs; |
|---|
| 1381 |
|
|---|
| 1382 |
ethernet->mii_addr = MII_ADDR(phy_addr, regnum); |
|---|
| 1383 |
while (ethernet->mii_addr & MII_ADDR_BUSY); |
|---|
| 1384 |
return (ethernet->mii_data >> MII_DATA_SHIFT); |
|---|
| 1385 |
} |
|---|
| 1386 |
|
|---|
| 1387 |
static int |
|---|
| 1388 |
mdiobus_write(struct mii_bus *bus, int phy_addr, int regnum, |
|---|
| 1389 |
u16 value) |
|---|
| 1390 |
{ |
|---|
| 1391 |
struct net_device *const dev = bus->priv; |
|---|
| 1392 |
struct ar2313_private *sp = netdev_priv(dev); |
|---|
| 1393 |
volatile ETHERNET_STRUCT *ethernet = sp->phy_regs; |
|---|
| 1394 |
|
|---|
| 1395 |
while (ethernet->mii_addr & MII_ADDR_BUSY); |
|---|
| 1396 |
ethernet->mii_data = value << MII_DATA_SHIFT; |
|---|
| 1397 |
ethernet->mii_addr = MII_ADDR(phy_addr, regnum) | MII_ADDR_WRITE; |
|---|
| 1398 |
|
|---|
| 1399 |
return 0; |
|---|
| 1400 |
} |
|---|
| 1401 |
|
|---|
| 1402 |
static int mdiobus_reset(struct mii_bus *bus) |
|---|
| 1403 |
{ |
|---|
| 1404 |
struct net_device *const dev = bus->priv; |
|---|
| 1405 |
|
|---|
| 1406 |
ar2313_reset_reg(dev); |
|---|
| 1407 |
|
|---|
| 1408 |
return 0; |
|---|
| 1409 |
} |
|---|
| 1410 |
|
|---|
| 1411 |
static int mdiobus_probe (struct net_device *dev) |
|---|
| 1412 |
{ |
|---|
| 1413 |
struct ar2313_private *const sp = netdev_priv(dev); |
|---|
| 1414 |
struct phy_device *phydev = NULL; |
|---|
| 1415 |
int phy_addr; |
|---|
| 1416 |
|
|---|
| 1417 |
/* find the first (lowest address) PHY on the current MAC's MII bus */ |
|---|
| 1418 |
for (phy_addr = 0; phy_addr < PHY_MAX_ADDR; phy_addr++) |
|---|
| 1419 |
if (sp->mii_bus.phy_map[phy_addr]) { |
|---|
| 1420 |
phydev = sp->mii_bus.phy_map[phy_addr]; |
|---|
| 1421 |
break; /* break out with first one found */ |
|---|
| 1422 |
} |
|---|
| 1423 |
|
|---|
| 1424 |
if (!phydev) { |
|---|
| 1425 |
printk (KERN_ERR "ar2313:%s: no PHY found\n", dev->name); |
|---|
| 1426 |
return -1; |
|---|
| 1427 |
} |
|---|
| 1428 |
|
|---|
| 1429 |
/* now we are supposed to have a proper phydev, to attach to... */ |
|---|
| 1430 |
BUG_ON(!phydev); |
|---|
| 1431 |
BUG_ON(phydev->attached_dev); |
|---|
| 1432 |
|
|---|
| 1433 |
phydev = phy_connect(dev, phydev->dev.bus_id, &ar2313_adjust_link, 0, |
|---|
| 1434 |
PHY_INTERFACE_MODE_MII); |
|---|
| 1435 |
|
|---|
| 1436 |
if (IS_ERR(phydev)) { |
|---|
| 1437 |
printk(KERN_ERR "%s: Could not attach to PHY\n", dev->name); |
|---|
| 1438 |
return PTR_ERR(phydev); |
|---|
| 1439 |
} |
|---|
| 1440 |
|
|---|
| 1441 |
sp->rx = phydev->netif_rx; |
|---|
| 1442 |
|
|---|
| 1443 |
/* mask with MAC supported features */ |
|---|
| 1444 |
phydev->supported &= (SUPPORTED_10baseT_Half |
|---|
| 1445 |
| SUPPORTED_10baseT_Full |
|---|
| 1446 |
| SUPPORTED_100baseT_Half |
|---|
| 1447 |
| SUPPORTED_100baseT_Full |
|---|
| 1448 |
| SUPPORTED_Autoneg |
|---|
| 1449 |
/* | SUPPORTED_Pause | SUPPORTED_Asym_Pause */ |
|---|
| 1450 |
| SUPPORTED_MII |
|---|
| 1451 |
| SUPPORTED_TP); |
|---|
| 1452 |
|
|---|
| 1453 |
phydev->advertising = phydev->supported; |
|---|
| 1454 |
|
|---|
| 1455 |
sp->oldduplex = -1; |
|---|
| 1456 |
sp->phy_dev = phydev; |
|---|
| 1457 |
|
|---|
| 1458 |
printk(KERN_INFO "%s: attached PHY driver [%s] " |
|---|
| 1459 |
"(mii_bus:phy_addr=%s)\n", |
|---|
| 1460 |
dev->name, phydev->drv->name, phydev->dev.bus_id); |
|---|
| 1461 |
|
|---|
| 1462 |
return 0; |
|---|
| 1463 |
} |
|---|
| 1464 |
|
|---|