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