2 * ar2313.c: Linux driver for the Atheros AR2313 Ethernet device.
4 * Copyright 2004 by Sameer Dekate, <sdekate@arubanetworks.com>.
5 * Copyright (C) 2006 Imre Kaloz <kaloz@openwrt.org>
7 * Thanks to Atheros for providing hardware and documentation
8 * enabling me to write this driver.
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
16 * This code is taken from John Taylor's Sibyte driver and then
17 * modified for the AR2313.
20 #include <linux/autoconf.h>
21 #include <linux/module.h>
22 #include <linux/version.h>
23 #include <linux/types.h>
24 #include <linux/errno.h>
25 #include <linux/ioport.h>
26 #include <linux/pci.h>
27 #include <linux/netdevice.h>
28 #include <linux/etherdevice.h>
29 #include <linux/skbuff.h>
30 #include <linux/init.h>
31 #include <linux/delay.h>
33 #include <linux/highmem.h>
34 #include <linux/sockios.h>
35 #include <linux/pkt_sched.h>
36 #include <linux/compile.h>
37 #include <linux/mii.h>
38 #include <linux/ethtool.h>
39 #include <linux/ctype.h>
44 #include <asm/system.h>
47 #include <asm/byteorder.h>
48 #include <asm/uaccess.h>
49 #include <asm/bootinfo.h>
51 extern char *getenv(char *e
);
67 #define min(a,b) (((a)<(b))?(a):(b))
70 #ifndef SMP_CACHE_BYTES
71 #define SMP_CACHE_BYTES L1_CACHE_BYTES
74 #ifndef SET_MODULE_OWNER
75 #define SET_MODULE_OWNER(dev) {do{} while(0);}
76 #define AR2313_MOD_INC_USE_COUNT MOD_INC_USE_COUNT
77 #define AR2313_MOD_DEC_USE_COUNT MOD_DEC_USE_COUNT
79 #define AR2313_MOD_INC_USE_COUNT {do{} while(0);}
80 #define AR2313_MOD_DEC_USE_COUNT {do{} while(0);}
83 #define PHYSADDR(a) ((_ACAST32_ (a)) & 0x1fffffff)
85 static char ethaddr
[18] = "00:00:00:00:00:00";
86 static char ifname
[5] = "bond";
88 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,52)
89 module_param_string(ethaddr
, ethaddr
, 18, 0);
90 module_param_string(ifname
, ifname
, 5, 0);
92 MODULE_PARM(ethaddr
, "c18");
93 MODULE_PARM(ifname
, "c5");
96 #define AR2313_MBOX_SET_BIT 0x8
98 #define BOARD_IDX_STATIC 0
99 #define BOARD_IDX_OVERFLOW -1
101 /* margot includes */
102 #include <asm/idt-boards/rc32434/rc32434.h>
104 #include "ar2313_msg.h"
105 #include "platform.h"
110 * New interrupt handler strategy:
112 * An old interrupt handler worked using the traditional method of
113 * replacing an skbuff with a new one when a packet arrives. However
114 * the rx rings do not need to contain a static number of buffer
115 * descriptors, thus it makes sense to move the memory allocation out
116 * of the main interrupt handler and do it in a bottom half handler
117 * and only allocate new buffers when the number of buffers in the
118 * ring is below a certain threshold. In order to avoid starving the
119 * NIC under heavy load it is however necessary to force allocation
120 * when hitting a minimum threshold. The strategy for alloction is as
123 * RX_LOW_BUF_THRES - allocate buffers in the bottom half
124 * RX_PANIC_LOW_THRES - we are very low on buffers, allocate
125 * the buffers in the interrupt handler
126 * RX_RING_THRES - maximum number of buffers in the rx ring
128 * One advantagous side effect of this allocation approach is that the
129 * entire rx processing can be done without holding any spin lock
130 * since the rx rings and registers are totally independent of the tx
131 * ring and its registers. This of course includes the kmalloc's of
132 * new skb's. Thus start_xmit can run in parallel with rx processing
133 * and the memory allocation on SMP systems.
135 * Note that running the skb reallocation in a bottom half opens up
136 * another can of races which needs to be handled properly. In
137 * particular it can happen that the interrupt handler tries to run
138 * the reallocation while the bottom half is either running on another
139 * CPU or was interrupted on the same CPU. To get around this the
140 * driver uses bitops to prevent the reallocation routines from being
143 * TX handling can also be done without holding any spin lock, wheee
144 * this is fun! since tx_csm is only written to by the interrupt
149 * Threshold values for RX buffer allocation - the low water marks for
150 * when to start refilling the rings are set to 75% of the ring
151 * sizes. It seems to make sense to refill the rings entirely from the
152 * intrrupt handler once it gets below the panic threshold, that way
153 * we don't risk that the refilling is moved to another CPU when the
154 * one running the interrupt handler just got the slab code hot in its
157 #define RX_RING_SIZE AR2313_DESCR_ENTRIES
158 #define RX_PANIC_THRES (RX_RING_SIZE/4)
159 #define RX_LOW_THRES ((3*RX_RING_SIZE)/4)
163 #define AR2313_BUFSIZE (AR2313_MTU + ETH_HLEN + CRC_LEN + RX_OFFSET)
166 MODULE_AUTHOR("Sameer Dekate<sdekate@arubanetworks.com>");
167 MODULE_DESCRIPTION("AR2313 Ethernet driver");
171 static char version
[] __initdata
=
172 "ar2313.c: v0.02 2006/06/19 sdekate@arubanetworks.com\n";
175 #define virt_to_phys(x) ((u32)(x) & 0x1fffffff)
178 static short armiiread(short phy
, short reg
);
179 static void armiiwrite(short phy
, short reg
, short data
);
181 static void ar2313_tx_timeout(struct net_device
*dev
);
183 static void ar2313_halt(struct net_device
*dev
);
184 static void rx_tasklet_func(unsigned long data
);
185 static void ar2313_multicast_list(struct net_device
*dev
);
187 static struct net_device
*root_dev
;
188 static int probed __initdata
= 0;
189 static unsigned long ar_eth_base
;
190 static unsigned long ar_dma_base
;
191 static unsigned long ar_int_base
;
192 static unsigned long ar_int_mac_mask
;
193 static unsigned long ar_int_phy_mask
;
196 #define ERR(fmt, args...) printk("%s: " fmt, __func__, ##args)
199 static int parse_mac_addr(struct net_device
*dev
, char* macstr
){
201 unsigned char result
, value
;
203 for (i
=0; i
<6; i
++) {
205 if (i
!= 5 && *(macstr
+2) != ':') {
206 ERR("invalid mac address format: %d %c\n",
210 for (j
=0; j
<2; j
++) {
211 if (isxdigit(*macstr
) && (value
= isdigit(*macstr
) ? *macstr
-'0' :
212 toupper(*macstr
)-'A'+10) < 16)
214 result
= result
*16 + value
;
218 ERR("invalid mac address "
219 "character: %c\n", *macstr
);
225 dev
->dev_addr
[i
] = result
;
232 int __init
ar2313_probe(void)
234 struct net_device
*dev
;
235 struct ar2313_private
*sp
;
244 sprintf(name
, "%s%%d", ifname
) ;
245 dev
= alloc_etherdev(sizeof(struct ar2313_private
));
248 printk(KERN_ERR
"ar2313: Unable to allocate net_device structure!\n");
252 SET_MODULE_OWNER(dev
);
257 switch (mips_machtype
) {
258 case MACH_ARUBA_AP60
:
259 ar_eth_base
= 0xb8100000;
260 ar_dma_base
= ar_eth_base
+ 0x1000;
261 ar_int_base
= 0x1C003020;
262 ar_int_mac_mask
= RESET_ENET0
|RESET_ENET1
;
263 ar_int_phy_mask
= RESET_EPHY0
|RESET_EPHY1
;
269 case MACH_ARUBA_AP40
:
270 ar_eth_base
= 0xb0500000;
271 ar_dma_base
= ar_eth_base
+ 0x1000;
272 ar_int_base
= 0x11000004;
273 ar_int_mac_mask
= 0x800;
274 ar_int_phy_mask
= 0x400;
280 case MACH_ARUBA_AP65
:
281 ar_eth_base
= 0xb8100000;
282 ar_dma_base
= ar_eth_base
+ 0x1000;
283 ar_int_base
= 0x1C003020;
284 ar_int_mac_mask
= RESET_ENET0
|RESET_ENET1
;
285 ar_int_phy_mask
= RESET_EPHY0
|RESET_EPHY1
;
288 // commented out, for now
290 if (mips_machtype
== MACH_ARUBA_SAMSUNG
) {
302 printk("%s: unsupported mips_machtype=0x%lx\n",
303 __FUNCTION__
, mips_machtype
) ;
307 spin_lock_init(&sp
->lock
);
309 /* initialize func pointers */
310 dev
->open
= &ar2313_open
;
311 dev
->stop
= &ar2313_close
;
312 dev
->hard_start_xmit
= &ar2313_start_xmit
;
314 dev
->get_stats
= &ar2313_get_stats
;
315 dev
->set_multicast_list
= &ar2313_multicast_list
;
317 dev
->tx_timeout
= ar2313_tx_timeout
;
318 dev
->watchdog_timeo
= AR2313_TX_TIMEOUT
;
320 dev
->do_ioctl
= &ar2313_ioctl
;
322 // SAMEER: do we need this?
323 dev
->features
|= NETIF_F_SG
| NETIF_F_HIGHDMA
;
325 tasklet_init(&sp
->rx_tasklet
, rx_tasklet_func
, (unsigned long) dev
);
326 tasklet_disable(&sp
->rx_tasklet
);
328 /* display version info if adapter is found */
330 /* set display flag to TRUE so that */
331 /* we only display this string ONCE */
338 request_region(PHYSADDR(ETHERNET_BASE
), ETHERNET_SIZE
*ETHERNET_MACS
,
341 sp
->eth_regs
= ioremap_nocache(PHYSADDR(ETHERNET_BASE
+ ETHERNET_SIZE
*sp
->mac
),
342 sizeof(*sp
->eth_regs
));
344 printk("Can't remap eth registers\n");
348 sp
->dma_regs
= ioremap_nocache(PHYSADDR(DMA_BASE
+ DMA_SIZE
*sp
->mac
),
349 sizeof(*sp
->dma_regs
));
350 dev
->base_addr
= (unsigned int) sp
->dma_regs
;
352 printk("Can't remap DMA registers\n");
356 sp
->int_regs
= ioremap_nocache(PHYSADDR(INTERRUPT_BASE
),
357 sizeof(*sp
->int_regs
));
359 printk("Can't remap INTERRUPT registers\n");
363 strncpy(sp
->name
, "Atheros AR2313", sizeof (sp
->name
) - 1);
364 sp
->name
[sizeof (sp
->name
) - 1] = '\0';
368 extern char *getenv(char *e
);
369 unsigned char def_mac
[6] = {0, 0x0b, 0x86, 0xba, 0xdb, 0xad};
371 memcpy(mac
, getenv("ethaddr"), 17);
372 if (parse_mac_addr(dev
, mac
)){
373 printk("%s: MAC address not found, using default\n", __func__
);
374 memcpy(dev
->dev_addr
, def_mac
, 6);
378 sp
->board_idx
= BOARD_IDX_STATIC
;
380 if (ar2313_init(dev
)) {
382 * ar2313_init() calls ar2313_init_cleanup() on error.
388 if (register_netdev(dev
)){
389 printk("%s: register_netdev failed\n", __func__
);
393 printk("%s: %s: %02x:%02x:%02x:%02x:%02x:%02x, irq %d\n",
395 dev
->dev_addr
[0], dev
->dev_addr
[1], dev
->dev_addr
[2],
396 dev
->dev_addr
[3], dev
->dev_addr
[4], dev
->dev_addr
[5],
399 /* start link poll timer */
400 ar2313_setup_timer(dev
);
403 * Register the device
411 static void ar2313_dump_regs(struct net_device
*dev
)
413 unsigned int *ptr
, i
;
414 struct ar2313_private
*sp
= (struct ar2313_private
*)dev
->priv
;
416 ptr
= (unsigned int *)sp
->eth_regs
;
417 for(i
=0; i
< (sizeof(ETHERNET_STRUCT
)/ sizeof(unsigned int)); i
++, ptr
++) {
418 printk("ENET: %08x = %08x\n", (int)ptr
, *ptr
);
421 ptr
= (unsigned int *)sp
->dma_regs
;
422 for(i
=0; i
< (sizeof(DMA
)/ sizeof(unsigned int)); i
++, ptr
++) {
423 printk("DMA: %08x = %08x\n", (int)ptr
, *ptr
);
426 ptr
= (unsigned int *)sp
->int_regs
;
427 for(i
=0; i
< (sizeof(INTERRUPT
)/ sizeof(unsigned int)); i
++, ptr
++){
428 printk("INT: %08x = %08x\n", (int)ptr
, *ptr
);
431 for (i
= 0; i
< AR2313_DESCR_ENTRIES
; i
++) {
432 ar2313_descr_t
*td
= &sp
->tx_ring
[i
];
433 printk("Tx desc %2d: %08x %08x %08x %08x\n", i
,
434 td
->status
, td
->devcs
, td
->addr
, td
->descr
);
441 ar2313_tx_timeout(struct net_device
*dev
)
443 struct ar2313_private
*sp
= (struct ar2313_private
*)dev
->priv
;
447 printk("Tx timeout\n");
449 spin_lock_irqsave(&sp
->lock
, flags
);
451 spin_unlock_irqrestore(&sp
->lock
, flags
);
457 printMcList(struct net_device
*dev
)
459 struct dev_mc_list
*list
= dev
->mc_list
;
462 printk("%d MC ADDR ", num
);
463 for(i
=0;i
<list
->dmi_addrlen
;i
++) {
464 printk(":%02x", list
->dmi_addr
[i
]);
473 * Set or clear the multicast filter for this adaptor.
474 * THIS IS ABSOLUTE CRAP, disabled
477 ar2313_multicast_list(struct net_device
*dev
)
480 * Always listen to broadcasts and
481 * treat IFF bits independently
483 struct ar2313_private
*sp
= (struct ar2313_private
*)dev
->priv
;
484 unsigned int recognise
;
486 recognise
= sp
->eth_regs
->mac_control
;
488 if (dev
->flags
& IFF_PROMISC
) { /* set promiscuous mode */
489 recognise
|= MAC_CONTROL_PR
;
491 recognise
&= ~MAC_CONTROL_PR
;
494 if ((dev
->flags
& IFF_ALLMULTI
) || (dev
->mc_count
> 15)) {
497 printk("%s: all MULTICAST mc_count %d\n", __FUNCTION__
, dev
->mc_count
);
499 recognise
|= MAC_CONTROL_PM
;/* all multicast */
500 } else if (dev
->mc_count
> 0) {
503 printk("%s: mc_count %d\n", __FUNCTION__
, dev
->mc_count
);
505 recognise
|= MAC_CONTROL_PM
; /* for the time being */
508 printk("%s: setting %08x to %08x\n", __FUNCTION__
, (int)sp
->eth_regs
, recognise
);
511 sp
->eth_regs
->mac_control
= recognise
;
514 static void rx_tasklet_cleanup(struct net_device
*dev
)
516 struct ar2313_private
*sp
= dev
->priv
;
519 * Tasklet may be scheduled. Need to get it removed from the list
520 * since we're about to free the struct.
524 tasklet_enable(&sp
->rx_tasklet
);
525 tasklet_kill(&sp
->rx_tasklet
);
528 static void __exit
ar2313_module_cleanup(void)
530 rx_tasklet_cleanup(root_dev
);
531 ar2313_init_cleanup(root_dev
);
532 unregister_netdev(root_dev
);
534 release_region(PHYSADDR(ETHERNET_BASE
), ETHERNET_SIZE
*ETHERNET_MACS
);
539 * Restart the AR2313 ethernet controller.
541 static int ar2313_restart(struct net_device
*dev
)
543 /* disable interrupts */
544 disable_irq(dev
->irq
);
552 /* enable interrupts */
553 enable_irq(dev
->irq
);
558 extern unsigned long mips_machtype
;
560 int __init
ar2313_module_init(void)
563 switch (mips_machtype
){
564 case MACH_ARUBA_AP60
:
565 case MACH_ARUBA_AP65
:
566 case MACH_ARUBA_AP40
:
568 status
= ar2313_probe();
575 module_init(ar2313_module_init
);
576 module_exit(ar2313_module_cleanup
);
579 static void ar2313_free_descriptors(struct net_device
*dev
)
581 struct ar2313_private
*sp
= dev
->priv
;
582 if (sp
->rx_ring
!= NULL
) {
583 kfree((void*)KSEG0ADDR(sp
->rx_ring
));
590 static int ar2313_allocate_descriptors(struct net_device
*dev
)
592 struct ar2313_private
*sp
= dev
->priv
;
595 ar2313_descr_t
*space
;
597 if(sp
->rx_ring
!= NULL
){
598 printk("%s: already done.\n", __FUNCTION__
);
602 size
= (sizeof(ar2313_descr_t
) * (AR2313_DESCR_ENTRIES
* AR2313_QUEUES
));
603 space
= kmalloc(size
, GFP_KERNEL
);
607 /* invalidate caches */
608 dma_cache_inv((unsigned int)space
, size
);
610 /* now convert pointer to KSEG1 */
611 space
= (ar2313_descr_t
*)KSEG1ADDR(space
);
613 memset((void *)space
, 0, size
);
616 space
+= AR2313_DESCR_ENTRIES
;
619 space
+= AR2313_DESCR_ENTRIES
;
621 /* Initialize the transmit Descriptors */
622 for (j
= 0; j
< AR2313_DESCR_ENTRIES
; j
++) {
623 ar2313_descr_t
*td
= &sp
->tx_ring
[j
];
625 td
->devcs
= DMA_TX1_CHAINED
;
627 td
->descr
= K1_TO_PHYS(&sp
->tx_ring
[(j
+1) & (AR2313_DESCR_ENTRIES
-1)]);
635 * Generic cleanup handling data allocated during init. Used when the
636 * module is unloaded or if an error occurs during initialization
638 static void ar2313_init_cleanup(struct net_device
*dev
)
640 struct ar2313_private
*sp
= dev
->priv
;
644 ar2313_free_descriptors(dev
);
646 if (sp
->eth_regs
) iounmap((void*)sp
->eth_regs
);
647 if (sp
->dma_regs
) iounmap((void*)sp
->dma_regs
);
650 for (j
= 0; j
< AR2313_DESCR_ENTRIES
; j
++) {
653 sp
->rx_skb
[j
] = NULL
;
662 for (j
= 0; j
< AR2313_DESCR_ENTRIES
; j
++) {
665 sp
->tx_skb
[j
] = NULL
;
674 static int ar2313_setup_timer(struct net_device
*dev
)
676 struct ar2313_private
*sp
= dev
->priv
;
678 init_timer(&sp
->link_timer
);
680 sp
->link_timer
.function
= ar2313_link_timer_fn
;
681 sp
->link_timer
.data
= (int) dev
;
682 sp
->link_timer
.expires
= jiffies
+ HZ
;
684 add_timer(&sp
->link_timer
);
689 static void ar2313_link_timer_fn(unsigned long data
)
691 struct net_device
*dev
= (struct net_device
*) data
;
692 struct ar2313_private
*sp
= dev
->priv
;
694 // see if the link status changed
695 // This was needed to make sure we set the PHY to the
696 // autonegotiated value of half or full duplex.
697 ar2313_check_link(dev
);
699 // Loop faster when we don't have link.
700 // This was needed to speed up the AP bootstrap time.
702 mod_timer(&sp
->link_timer
, jiffies
+ HZ
/2);
704 mod_timer(&sp
->link_timer
, jiffies
+ LINK_TIMER
);
708 static void ar2313_check_link(struct net_device
*dev
)
710 struct ar2313_private
*sp
= dev
->priv
;
713 phyData
= armiiread(sp
->phy
, MII_BMSR
);
714 if (sp
->phyData
!= phyData
) {
715 if (phyData
& BMSR_LSTATUS
) {
716 /* link is present, ready link partner ability to deterine duplexity */
721 reg
= armiiread(sp
->phy
, MII_BMCR
);
722 if (reg
& BMCR_ANENABLE
) {
723 /* auto neg enabled */
724 reg
= armiiread(sp
->phy
, MII_LPA
);
725 duplex
= (reg
& (LPA_100FULL
|LPA_10FULL
))? 1:0;
727 /* no auto neg, just read duplex config */
728 duplex
= (reg
& BMCR_FULLDPLX
)? 1:0;
731 printk(KERN_INFO
"%s: Configuring MAC for %s duplex\n", dev
->name
,
732 (duplex
)? "full":"half");
736 sp
->eth_regs
->mac_control
= ((sp
->eth_regs
->mac_control
| MAC_CONTROL_F
) &
740 sp
->eth_regs
->mac_control
= ((sp
->eth_regs
->mac_control
| MAC_CONTROL_DRO
) &
747 sp
->phyData
= phyData
;
752 ar2313_reset_reg(struct net_device
*dev
)
754 struct ar2313_private
*sp
= (struct ar2313_private
*)dev
->priv
;
755 unsigned int ethsal
, ethsah
;
758 *sp
->int_regs
|= ar_int_mac_mask
;
760 *sp
->int_regs
&= ~ar_int_mac_mask
;
762 *sp
->int_regs
|= ar_int_phy_mask
;
764 *sp
->int_regs
&= ~ar_int_phy_mask
;
767 sp
->dma_regs
->bus_mode
= (DMA_BUS_MODE_SWR
);
769 sp
->dma_regs
->bus_mode
= ((32 << DMA_BUS_MODE_PBL_SHIFT
) | DMA_BUS_MODE_BLE
);
771 /* enable interrupts */
772 sp
->dma_regs
->intr_ena
= (DMA_STATUS_AIS
|
777 sp
->dma_regs
->xmt_base
= K1_TO_PHYS(sp
->tx_ring
);
778 sp
->dma_regs
->rcv_base
= K1_TO_PHYS(sp
->rx_ring
);
779 sp
->dma_regs
->control
= (DMA_CONTROL_SR
| DMA_CONTROL_ST
| DMA_CONTROL_SF
);
781 sp
->eth_regs
->flow_control
= (FLOW_CONTROL_FCE
);
782 sp
->eth_regs
->vlan_tag
= (0x8100);
784 /* Enable Ethernet Interface */
785 flags
= (MAC_CONTROL_TE
| /* transmit enable */
786 MAC_CONTROL_PM
| /* pass mcast */
787 MAC_CONTROL_F
| /* full duplex */
788 MAC_CONTROL_HBD
); /* heart beat disabled */
790 if (dev
->flags
& IFF_PROMISC
) { /* set promiscuous mode */
791 flags
|= MAC_CONTROL_PR
;
793 sp
->eth_regs
->mac_control
= flags
;
795 /* Set all Ethernet station address registers to their initial values */
796 ethsah
= ((((u_int
)(dev
->dev_addr
[5]) << 8) & (u_int
)0x0000FF00) |
797 (((u_int
)(dev
->dev_addr
[4]) << 0) & (u_int
)0x000000FF));
799 ethsal
= ((((u_int
)(dev
->dev_addr
[3]) << 24) & (u_int
)0xFF000000) |
800 (((u_int
)(dev
->dev_addr
[2]) << 16) & (u_int
)0x00FF0000) |
801 (((u_int
)(dev
->dev_addr
[1]) << 8) & (u_int
)0x0000FF00) |
802 (((u_int
)(dev
->dev_addr
[0]) << 0) & (u_int
)0x000000FF) );
804 sp
->eth_regs
->mac_addr
[0] = ethsah
;
805 sp
->eth_regs
->mac_addr
[1] = ethsal
;
813 static int ar2313_init(struct net_device
*dev
)
815 struct ar2313_private
*sp
= dev
->priv
;
819 * Allocate descriptors
821 if (ar2313_allocate_descriptors(dev
)) {
822 printk("%s: %s: ar2313_allocate_descriptors failed\n",
823 dev
->name
, __FUNCTION__
);
829 * Get the memory for the skb rings.
831 if(sp
->rx_skb
== NULL
) {
832 sp
->rx_skb
= kmalloc(sizeof(struct sk_buff
*) * AR2313_DESCR_ENTRIES
, GFP_KERNEL
);
834 printk("%s: %s: rx_skb kmalloc failed\n",
835 dev
->name
, __FUNCTION__
);
840 memset(sp
->rx_skb
, 0, sizeof(struct sk_buff
*) * AR2313_DESCR_ENTRIES
);
842 if(sp
->tx_skb
== NULL
) {
843 sp
->tx_skb
= kmalloc(sizeof(struct sk_buff
*) * AR2313_DESCR_ENTRIES
, GFP_KERNEL
);
845 printk("%s: %s: tx_skb kmalloc failed\n",
846 dev
->name
, __FUNCTION__
);
851 memset(sp
->tx_skb
, 0, sizeof(struct sk_buff
*) * AR2313_DESCR_ENTRIES
);
854 * Set tx_csm before we start receiving interrupts, otherwise
855 * the interrupt handler might think it is supposed to process
856 * tx ints before we are up and running, which may cause a null
857 * pointer access in the int handler.
865 * Zero the stats before starting the interface
867 memset(&sp
->stats
, 0, sizeof(sp
->stats
));
870 * We load the ring here as there seem to be no way to tell the
871 * firmware to wipe the ring without re-initializing it.
873 ar2313_load_rx_ring(dev
, RX_RING_SIZE
);
878 ar2313_reset_reg(dev
);
883 ecode
= request_irq(dev
->irq
, &ar2313_interrupt
, SA_SHIRQ
| SA_INTERRUPT
, dev
->name
, dev
);
885 printk(KERN_WARNING
"%s: %s: Requested IRQ %d is busy\n",
886 dev
->name
, __FUNCTION__
, dev
->irq
);
891 // commented out, for now
893 if(mips_machtype
== MACH_ARUBA_SAMSUNG
) {
895 /* configure Marvell 88E6060 */
897 armiiwrite(0x1f, 0xa, 0xa130);
900 i
= armiiread(sp
->phy
, 0xa);
901 } while (i
& 0x8000);
903 /* configure MAC address */
904 armiiwrite(sp
->phy
, 0x1, dev
->dev_addr
[0] << 8 | dev
->dev_addr
[1]);
905 armiiwrite(sp
->phy
, 0x2, dev
->dev_addr
[2] << 8 | dev
->dev_addr
[3]);
906 armiiwrite(sp
->phy
, 0x3, dev
->dev_addr
[4] << 8 | dev
->dev_addr
[5]);
908 /* set ports to forwarding */
909 armiiwrite(0x18, 0x4, 0x3);
910 armiiwrite(0x1c, 0x4, 0x3);
911 armiiwrite(0x1d, 0x4, 0x3);
915 tasklet_enable(&sp
->rx_tasklet
);
920 ar2313_init_cleanup(dev
);
927 * Loading rings is safe without holding the spin lock since this is
928 * done only before the device is enabled, thus no interrupts are
929 * generated and by the interrupt handler/tasklet handler.
931 static void ar2313_load_rx_ring(struct net_device
*dev
, int nr_bufs
)
934 struct ar2313_private
*sp
= ((struct net_device
*)dev
)->priv
;
939 for (i
= 0; i
< nr_bufs
; i
++) {
943 if (sp
->rx_skb
[idx
]) {
945 printk(KERN_INFO
"ar2313 rx refill full\n");
950 // partha: create additional room for the second GRE fragment
951 skb
= alloc_skb(AR2313_BUFSIZE
+128, GFP_ATOMIC
);
953 printk("\n\n\n\n %s: No memory in system\n\n\n\n", __FUNCTION__
);
956 // partha: create additional room in the front for tx pkt capture
957 skb_reserve(skb
, 32);
960 * Make sure IP header starts on a fresh cache line.
963 skb_reserve(skb
, RX_OFFSET
);
964 sp
->rx_skb
[idx
] = skb
;
966 rd
= (ar2313_descr_t
*) &sp
->rx_ring
[idx
];
968 /* initialize dma descriptor */
969 rd
->devcs
= ((AR2313_BUFSIZE
<< DMA_RX1_BSIZE_SHIFT
) |
971 rd
->addr
= virt_to_phys(skb
->data
);
972 rd
->descr
= virt_to_phys(&sp
->rx_ring
[(idx
+1) & (AR2313_DESCR_ENTRIES
-1)]);
973 rd
->status
= DMA_RX_OWN
;
980 printk(KERN_INFO
"Out of memory when allocating standard receive buffers\n");
989 #define AR2313_MAX_PKTS_PER_CALL 64
991 static int ar2313_rx_int(struct net_device
*dev
)
993 struct ar2313_private
*sp
= dev
->priv
;
994 struct sk_buff
*skb
, *skb_new
;
995 ar2313_descr_t
*rxdesc
;
1003 /* process at most the entire ring and then wait for another interrupt */
1006 rxdesc
= &sp
->rx_ring
[idx
];
1007 status
= rxdesc
->status
;
1008 if (status
& DMA_RX_OWN
) {
1009 /* SiByte owns descriptor or descr not yet filled in */
1014 if (++pkts
> AR2313_MAX_PKTS_PER_CALL
) {
1020 printk("index %d\n", idx
);
1021 printk("RX status %08x\n", rxdesc
->status
);
1022 printk("RX devcs %08x\n", rxdesc
->devcs
);
1023 printk("RX addr %08x\n", rxdesc
->addr
);
1024 printk("RX descr %08x\n", rxdesc
->descr
);
1027 if ((status
& (DMA_RX_ERROR
|DMA_RX_ERR_LENGTH
)) &&
1028 (!(status
& DMA_RX_LONG
))){
1030 printk("%s: rx ERROR %08x\n", __FUNCTION__
, status
);
1032 sp
->stats
.rx_errors
++;
1033 sp
->stats
.rx_dropped
++;
1035 /* add statistics counters */
1036 if (status
& DMA_RX_ERR_CRC
) sp
->stats
.rx_crc_errors
++;
1037 if (status
& DMA_RX_ERR_COL
) sp
->stats
.rx_over_errors
++;
1038 if (status
& DMA_RX_ERR_LENGTH
)
1039 sp
->stats
.rx_length_errors
++;
1040 if (status
& DMA_RX_ERR_RUNT
) sp
->stats
.rx_over_errors
++;
1041 if (status
& DMA_RX_ERR_DESC
) sp
->stats
.rx_over_errors
++;
1044 /* alloc new buffer. */
1045 skb_new
= dev_alloc_skb(AR2313_BUFSIZE
+ RX_OFFSET
+ 128);
1046 if (skb_new
!= NULL
) {
1048 skb
= sp
->rx_skb
[idx
];
1050 skb_put(skb
, ((status
>> DMA_RX_LEN_SHIFT
) & 0x3fff) - CRC_LEN
);
1052 #ifdef CONFIG_MERLOT
1053 if ((dev
->am_pkt_handler
== NULL
) ||
1054 (dev
->am_pkt_handler(skb
, dev
) == 0)) {
1056 sp
->stats
.rx_bytes
+= skb
->len
;
1057 skb
->protocol
= eth_type_trans(skb
, dev
);
1058 /* pass the packet to upper layers */
1060 #ifdef CONFIG_MERLOT
1061 if (dev
->asap_netif_rx
)
1062 dev
->asap_netif_rx(skb
);
1066 #ifdef CONFIG_MERLOT
1071 skb_reserve(skb_new
, RX_OFFSET
+32);
1072 /* reset descriptor's curr_addr */
1073 rxdesc
->addr
= virt_to_phys(skb_new
->data
);
1075 sp
->stats
.rx_packets
++;
1076 sp
->rx_skb
[idx
] = skb_new
;
1079 sp
->stats
.rx_dropped
++;
1083 rxdesc
->devcs
= ((AR2313_BUFSIZE
<< DMA_RX1_BSIZE_SHIFT
) |
1085 rxdesc
->status
= DMA_RX_OWN
;
1087 idx
= DSC_NEXT(idx
);
1096 static void ar2313_tx_int(struct net_device
*dev
)
1098 struct ar2313_private
*sp
= dev
->priv
;
1100 struct sk_buff
*skb
;
1101 ar2313_descr_t
*txdesc
;
1102 unsigned int status
=0;
1106 while (idx
!= sp
->tx_prd
) {
1108 txdesc
= &sp
->tx_ring
[idx
];
1111 printk("%s: TXINT: csm=%d idx=%d prd=%d status=%x devcs=%x addr=%08x descr=%x\n",
1112 dev
->name
, sp
->tx_csm
, idx
, sp
->tx_prd
,
1113 txdesc
->status
, txdesc
->devcs
, txdesc
->addr
, txdesc
->descr
);
1116 if ((status
= txdesc
->status
) & DMA_TX_OWN
) {
1117 /* ar2313 dma still owns descr */
1120 /* done with this descriptor */
1123 if (status
& DMA_TX_ERROR
){
1124 sp
->stats
.tx_errors
++;
1125 sp
->stats
.tx_dropped
++;
1126 if(status
& DMA_TX_ERR_UNDER
)
1127 sp
->stats
.tx_fifo_errors
++;
1128 if(status
& DMA_TX_ERR_HB
)
1129 sp
->stats
.tx_heartbeat_errors
++;
1130 if(status
& (DMA_TX_ERR_LOSS
|
1132 sp
->stats
.tx_carrier_errors
++;
1133 if (status
& (DMA_TX_ERR_LATE
|
1137 sp
->stats
.tx_aborted_errors
++;
1140 sp
->stats
.tx_packets
++;
1143 skb
= sp
->tx_skb
[idx
];
1144 sp
->tx_skb
[idx
] = NULL
;
1145 idx
= DSC_NEXT(idx
);
1146 sp
->stats
.tx_bytes
+= skb
->len
;
1147 dev_kfree_skb_irq(skb
);
1157 rx_tasklet_func(unsigned long data
)
1159 struct net_device
*dev
= (struct net_device
*) data
;
1160 struct ar2313_private
*sp
= dev
->priv
;
1162 if (sp
->unloading
) {
1166 if (ar2313_rx_int(dev
)) {
1167 tasklet_hi_schedule(&sp
->rx_tasklet
);
1170 unsigned long flags
;
1171 spin_lock_irqsave(&sp
->lock
, flags
);
1172 sp
->dma_regs
->intr_ena
|= DMA_STATUS_RI
;
1173 spin_unlock_irqrestore(&sp
->lock
, flags
);
1178 rx_schedule(struct net_device
*dev
)
1180 struct ar2313_private
*sp
= dev
->priv
;
1182 sp
->dma_regs
->intr_ena
&= ~DMA_STATUS_RI
;
1184 tasklet_hi_schedule(&sp
->rx_tasklet
);
1187 static irqreturn_t
ar2313_interrupt(int irq
, void *dev_id
)
1189 struct net_device
*dev
= (struct net_device
*)dev_id
;
1190 struct ar2313_private
*sp
= dev
->priv
;
1191 unsigned int status
, enabled
;
1193 /* clear interrupt */
1195 * Don't clear RI bit if currently disabled.
1197 status
= sp
->dma_regs
->status
;
1198 enabled
= sp
->dma_regs
->intr_ena
;
1199 sp
->dma_regs
->status
= status
& enabled
;
1201 if (status
& DMA_STATUS_NIS
) {
1204 * Don't schedule rx processing if interrupt
1205 * is already disabled.
1207 if (status
& enabled
& DMA_STATUS_RI
) {
1208 /* receive interrupt */
1211 if (status
& DMA_STATUS_TI
) {
1212 /* transmit interrupt */
1217 if (status
& DMA_STATUS_AIS
) {
1219 printk("%s: AIS set %08x & %x\n", __FUNCTION__
,
1220 status
, (DMA_STATUS_FBE
| DMA_STATUS_TPS
));
1222 /* abnormal status */
1223 if (status
& (DMA_STATUS_FBE
| DMA_STATUS_TPS
)) {
1224 ar2313_restart(dev
);
1231 static int ar2313_open(struct net_device
*dev
)
1233 struct ar2313_private
*sp
;
1238 netif_start_queue(dev
);
1240 sp
->eth_regs
->mac_control
|= MAC_CONTROL_RE
;
1242 AR2313_MOD_INC_USE_COUNT
;
1247 static void ar2313_halt(struct net_device
*dev
)
1249 struct ar2313_private
*sp
= dev
->priv
;
1252 tasklet_disable(&sp
->rx_tasklet
);
1255 sp
->eth_regs
->mac_control
&= ~(MAC_CONTROL_RE
| /* disable Receives */
1256 MAC_CONTROL_TE
); /* disable Transmits */
1258 sp
->dma_regs
->control
= 0;
1259 sp
->dma_regs
->bus_mode
= DMA_BUS_MODE_SWR
;
1261 /* place phy and MAC in reset */
1262 *sp
->int_regs
|= (ar_int_mac_mask
| ar_int_phy_mask
);
1264 /* free buffers on tx ring */
1265 for (j
= 0; j
< AR2313_DESCR_ENTRIES
; j
++) {
1266 struct sk_buff
*skb
;
1267 ar2313_descr_t
*txdesc
;
1269 txdesc
= &sp
->tx_ring
[j
];
1272 skb
= sp
->tx_skb
[j
];
1275 sp
->tx_skb
[j
] = NULL
;
1281 * close should do nothing. Here's why. It's called when
1282 * 'ifconfig bond0 down' is run. If it calls free_irq then
1283 * the irq is gone forever ! When bond0 is made 'up' again,
1284 * the ar2313_open () does not call request_irq (). Worse,
1285 * the call to ar2313_halt() generates a WDOG reset due to
1286 * the write to 'sp->int_regs' and the box reboots.
1287 * Commenting this out is good since it allows the
1288 * system to resume when bond0 is made up again.
1290 static int ar2313_close(struct net_device
*dev
)
1294 * Disable interrupts
1296 disable_irq(dev
->irq
);
1299 * Without (or before) releasing irq and stopping hardware, this
1300 * is an absolute non-sense, by the way. It will be reset instantly
1303 netif_stop_queue(dev
);
1305 /* stop the MAC and DMA engines */
1308 /* release the interrupt */
1309 free_irq(dev
->irq
, dev
);
1312 AR2313_MOD_DEC_USE_COUNT
;
1316 static int ar2313_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
1318 struct ar2313_private
*sp
= dev
->priv
;
1323 td
= &sp
->tx_ring
[idx
];
1325 if (td
->status
& DMA_TX_OWN
) {
1327 printk("%s: No space left to Tx\n", __FUNCTION__
);
1329 /* free skbuf and lie to the caller that we sent it out */
1330 sp
->stats
.tx_dropped
++;
1333 /* restart transmitter in case locked */
1334 sp
->dma_regs
->xmt_poll
= 0;
1338 /* Setup the transmit descriptor. */
1339 td
->devcs
= ((skb
->len
<< DMA_TX1_BSIZE_SHIFT
) |
1340 (DMA_TX1_LS
|DMA_TX1_IC
|DMA_TX1_CHAINED
));
1341 td
->addr
= virt_to_phys(skb
->data
);
1342 td
->status
= DMA_TX_OWN
;
1344 /* kick transmitter last */
1345 sp
->dma_regs
->xmt_poll
= 0;
1348 printk("index %d\n", idx
);
1349 printk("TX status %08x\n", td
->status
);
1350 printk("TX devcs %08x\n", td
->devcs
);
1351 printk("TX addr %08x\n", td
->addr
);
1352 printk("TX descr %08x\n", td
->descr
);
1355 sp
->tx_skb
[idx
] = skb
;
1356 idx
= DSC_NEXT(idx
);
1359 //dev->trans_start = jiffies;
1364 static int netdev_get_ecmd(struct net_device
*dev
, struct ethtool_cmd
*ecmd
)
1366 struct ar2313_private
*np
= dev
->priv
;
1370 (SUPPORTED_10baseT_Half
| SUPPORTED_10baseT_Full
|
1371 SUPPORTED_100baseT_Half
| SUPPORTED_100baseT_Full
|
1372 SUPPORTED_Autoneg
| SUPPORTED_TP
| SUPPORTED_MII
);
1374 ecmd
->port
= PORT_TP
;
1375 /* only supports internal transceiver */
1376 ecmd
->transceiver
= XCVR_INTERNAL
;
1377 /* not sure what this is for */
1378 ecmd
->phy_address
= 1;
1380 ecmd
->advertising
= ADVERTISED_MII
;
1381 tmp
= armiiread(np
->phy
, MII_ADVERTISE
);
1382 if (tmp
& ADVERTISE_10HALF
)
1383 ecmd
->advertising
|= ADVERTISED_10baseT_Half
;
1384 if (tmp
& ADVERTISE_10FULL
)
1385 ecmd
->advertising
|= ADVERTISED_10baseT_Full
;
1386 if (tmp
& ADVERTISE_100HALF
)
1387 ecmd
->advertising
|= ADVERTISED_100baseT_Half
;
1388 if (tmp
& ADVERTISE_100FULL
)
1389 ecmd
->advertising
|= ADVERTISED_100baseT_Full
;
1391 tmp
= armiiread(np
->phy
, MII_BMCR
);
1392 if (tmp
& BMCR_ANENABLE
) {
1393 ecmd
->advertising
|= ADVERTISED_Autoneg
;
1394 ecmd
->autoneg
= AUTONEG_ENABLE
;
1396 ecmd
->autoneg
= AUTONEG_DISABLE
;
1399 if (ecmd
->autoneg
== AUTONEG_ENABLE
) {
1400 tmp
= armiiread(np
->phy
, MII_LPA
);
1401 if (tmp
& (LPA_100FULL
|LPA_10FULL
)) {
1402 ecmd
->duplex
= DUPLEX_FULL
;
1404 ecmd
->duplex
= DUPLEX_HALF
;
1406 if (tmp
& (LPA_100FULL
|LPA_100HALF
)) {
1407 ecmd
->speed
= SPEED_100
;
1409 ecmd
->speed
= SPEED_10
;
1412 if (tmp
& BMCR_FULLDPLX
) {
1413 ecmd
->duplex
= DUPLEX_FULL
;
1415 ecmd
->duplex
= DUPLEX_HALF
;
1417 if (tmp
& BMCR_SPEED100
) {
1418 ecmd
->speed
= SPEED_100
;
1420 ecmd
->speed
= SPEED_10
;
1424 /* ignore maxtxpkt, maxrxpkt for now */
1429 static int netdev_set_ecmd(struct net_device
*dev
, struct ethtool_cmd
*ecmd
)
1431 struct ar2313_private
*np
= dev
->priv
;
1434 if (ecmd
->speed
!= SPEED_10
&& ecmd
->speed
!= SPEED_100
)
1436 if (ecmd
->duplex
!= DUPLEX_HALF
&& ecmd
->duplex
!= DUPLEX_FULL
)
1438 if (ecmd
->port
!= PORT_TP
)
1440 if (ecmd
->transceiver
!= XCVR_INTERNAL
)
1442 if (ecmd
->autoneg
!= AUTONEG_DISABLE
&& ecmd
->autoneg
!= AUTONEG_ENABLE
)
1444 /* ignore phy_address, maxtxpkt, maxrxpkt for now */
1446 /* WHEW! now lets bang some bits */
1448 tmp
= armiiread(np
->phy
, MII_BMCR
);
1449 if (ecmd
->autoneg
== AUTONEG_ENABLE
) {
1450 /* turn on autonegotiation */
1451 tmp
|= BMCR_ANENABLE
;
1452 printk("%s: Enabling auto-neg\n", dev
->name
);
1454 /* turn off auto negotiation, set speed and duplexity */
1455 tmp
&= ~(BMCR_ANENABLE
| BMCR_SPEED100
| BMCR_FULLDPLX
);
1456 if (ecmd
->speed
== SPEED_100
)
1457 tmp
|= BMCR_SPEED100
;
1458 if (ecmd
->duplex
== DUPLEX_FULL
)
1459 tmp
|= BMCR_FULLDPLX
;
1460 printk("%s: Hard coding %d/%s\n", dev
->name
,
1461 (ecmd
->speed
== SPEED_100
)? 100:10,
1462 (ecmd
->duplex
== DUPLEX_FULL
)? "full":"half");
1464 armiiwrite(np
->phy
, MII_BMCR
, tmp
);
1469 static int netdev_ethtool_ioctl(struct net_device
*dev
, void *useraddr
)
1471 struct ar2313_private
*np
= dev
->priv
;
1474 if (get_user(cmd
, (u32
*)useraddr
))
1479 case ETHTOOL_GSET
: {
1480 struct ethtool_cmd ecmd
= { ETHTOOL_GSET
};
1481 spin_lock_irq(&np
->lock
);
1482 netdev_get_ecmd(dev
, &ecmd
);
1483 spin_unlock_irq(&np
->lock
);
1484 if (copy_to_user(useraddr
, &ecmd
, sizeof(ecmd
)))
1489 case ETHTOOL_SSET
: {
1490 struct ethtool_cmd ecmd
;
1492 if (copy_from_user(&ecmd
, useraddr
, sizeof(ecmd
)))
1494 spin_lock_irq(&np
->lock
);
1495 r
= netdev_set_ecmd(dev
, &ecmd
);
1496 spin_unlock_irq(&np
->lock
);
1499 /* restart autonegotiation */
1500 case ETHTOOL_NWAY_RST
: {
1503 /* if autoneg is off, it's an error */
1504 tmp
= armiiread(np
->phy
, MII_BMCR
);
1505 if (tmp
& BMCR_ANENABLE
) {
1506 tmp
|= (BMCR_ANRESTART
);
1507 armiiwrite(np
->phy
, MII_BMCR
, tmp
);
1512 /* get link status */
1513 case ETHTOOL_GLINK
: {
1514 struct ethtool_value edata
= {ETHTOOL_GLINK
};
1515 edata
.data
= (armiiread(np
->phy
, MII_BMSR
)&BMSR_LSTATUS
) ? 1:0;
1516 if (copy_to_user(useraddr
, &edata
, sizeof(edata
)))
1525 static int ar2313_ioctl(struct net_device
*dev
, struct ifreq
*ifr
, int cmd
)
1527 struct mii_ioctl_data
*data
= (struct mii_ioctl_data
*)&ifr
->ifr_data
;
1530 case SIOCDEVPRIVATE
: {
1531 struct ar2313_cmd scmd
;
1533 if (copy_from_user(&scmd
, ifr
->ifr_data
, sizeof(scmd
)))
1537 printk("%s: ioctl devprivate c=%d a=%x l=%d m=%d d=%x,%x\n",
1538 dev
->name
, scmd
.cmd
,
1539 scmd
.address
, scmd
.length
,
1540 scmd
.mailbox
, scmd
.data
[0], scmd
.data
[1]);
1544 case AR2313_READ_DATA
:
1546 scmd
.data
[0] = *((u32
*)scmd
.address
);
1547 } else if(scmd
.length
==2) {
1548 scmd
.data
[0] = *((u16
*)scmd
.address
);
1549 } else if (scmd
.length
==1) {
1550 scmd
.data
[0] = *((u8
*)scmd
.address
);
1554 if(copy_to_user(ifr
->ifr_data
, &scmd
, sizeof(scmd
)))
1558 case AR2313_WRITE_DATA
:
1560 *((u32
*)scmd
.address
) = scmd
.data
[0];
1561 } else if(scmd
.length
==2) {
1562 *((u16
*)scmd
.address
) = scmd
.data
[0];
1563 } else if (scmd
.length
==1) {
1564 *((u8
*)scmd
.address
) = scmd
.data
[0];
1570 case AR2313_GET_VERSION
:
1571 // SAMEER: sprintf((char*) &scmd, "%s", ARUBA_VERSION);
1572 if(copy_to_user(ifr
->ifr_data
, &scmd
, sizeof(scmd
)))
1583 return netdev_ethtool_ioctl(dev
, (void *) ifr
->ifr_data
);
1585 case SIOCGMIIPHY
: /* Get address of MII PHY in use. */
1589 case SIOCGMIIREG
: /* Read MII PHY register. */
1590 case SIOCDEVPRIVATE
+1: /* for binary compat, remove in 2.5 */
1591 data
->val_out
= armiiread(data
->phy_id
& 0x1f,
1592 data
->reg_num
& 0x1f);
1594 case SIOCSMIIREG
: /* Write MII PHY register. */
1595 case SIOCDEVPRIVATE
+2: /* for binary compat, remove in 2.5 */
1596 if (!capable(CAP_NET_ADMIN
))
1598 armiiwrite(data
->phy_id
& 0x1f,
1599 data
->reg_num
& 0x1f, data
->val_in
);
1603 if (copy_from_user(dev
->dev_addr
, ifr
->ifr_data
, sizeof(dev
->dev_addr
)))
1608 if (copy_to_user(ifr
->ifr_data
, dev
->dev_addr
, sizeof(dev
->dev_addr
)))
1619 static struct net_device_stats
*ar2313_get_stats(struct net_device
*dev
)
1621 struct ar2313_private
*sp
= dev
->priv
;
1626 armiiread(short phy
, short reg
)
1628 volatile ETHERNET_STRUCT
* ethernet
;
1630 ethernet
= (volatile ETHERNET_STRUCT
*)ETHERNET_BASE
; /* always MAC 0 */
1631 ethernet
->mii_addr
= ((reg
<< MII_ADDR_REG_SHIFT
) |
1632 (phy
<< MII_ADDR_PHY_SHIFT
));
1633 while (ethernet
->mii_addr
& MII_ADDR_BUSY
);
1634 return (ethernet
->mii_data
>> MII_DATA_SHIFT
);
1638 armiiwrite(short phy
, short reg
, short data
)
1640 volatile ETHERNET_STRUCT
* ethernet
;
1642 ethernet
= (volatile ETHERNET_STRUCT
*)ETHERNET_BASE
; /* always MAC 0 */
1643 while (ethernet
->mii_addr
& MII_ADDR_BUSY
);
1644 ethernet
->mii_data
= data
<< MII_DATA_SHIFT
;
1645 ethernet
->mii_addr
= ((reg
<< MII_ADDR_REG_SHIFT
) |
1646 (phy
<< MII_ADDR_PHY_SHIFT
) |
This page took 0.139231 seconds and 5 git commands to generate.