1 diff -urN linux-2.4.32.new/arch/mips/ar531x/ae531xlnx.c linux-2.4.32.new-eth/arch/mips/ar531x/ae531xlnx.c
2 --- linux-2.4.32.new/arch/mips/ar531x/ae531xlnx.c 1970-01-01 01:00:00.000000000 +0100
3 +++ linux-2.4.32.new-eth/arch/mips/ar531x/ae531xlnx.c 2005-12-25 11:54:20.756273952 +0000
6 + * This file is subject to the terms and conditions of the GNU General Public
7 + * License. See the file "COPYING" in the main directory of this archive
10 + * Copyright © 2003 Atheros Communications, Inc., All Rights Reserved.
14 + * Ethernet driver for Atheros' ae531x ethernet MAC.
15 + * This is a fairly generic driver, but it's intended
16 + * for use in typical Atheros products.
19 +#include <linux/config.h>
20 +#include <linux/types.h>
21 +#include <linux/delay.h>
22 +#include <linux/netdevice.h>
23 +#include <linux/etherdevice.h>
24 +#include <linux/init.h>
25 +#include <linux/skbuff.h>
28 +#include "ar531xlnx.h"
29 +#include "ae531xreg.h"
30 +#include "ae531xmac.h"
33 + * A word about CONFIG_VENETDEV: It's intended to support two
34 + * "virtualized ethernet devices" that share a single underlying MAC.
35 + * To upper layers, it appears that the hardware supports two MACs,
36 + * with enet0 used for LAN ports and enet1 used for a WAN port. This
37 + * is useful, for instance, when building a 5-port router on hardware
38 + * that uses only one of the AR5312's ethernet MACs.
40 + * Virtualization is accomplished through trickery at the ethernet
41 + * PHY layer. We use PHY hardware to determine which port a packet
42 + * was received on, and in order to direct a packet to a particular
43 + * port or set of ports.
45 + * The code is mostly written to be generalized to more than two
46 + * virtual devices; but it's intended for one multi-port LAN enet
47 + * device and one single-port WAN enet device.
50 +#define AE531X_LAN_PORT 0
51 +#ifdef CONFIG_VENETDEV
52 +#define AE531X_DEV_PER_MAC 2
53 +#define AE531X_WAN_PORT 1
55 +#define AE531X_DEV_PER_MAC 1
60 + * ae531x_MAC_state contains driver-specific linux-specific per-MAC information.
61 + * The OSinfo member of ae531x_MAC_t points to one of these.
63 +typedef struct ae531x_MAC_state {
65 + struct tq_struct restart_task;
66 + struct net_device_stats stats;
67 + struct ae531x_dev_sw_state *dev_sw_state[AE531X_DEV_PER_MAC];
69 + ae531x_MAC_t MACInfo; /* hardware state */
70 +} ae531x_MAC_state_t;
73 + * ae531x_dev_sw_state contains driver-specific linux-specific per-device
74 + * information. The net_device priv member points to one of these, and
75 + * this structure contains a pointer to the associated MAC information.
76 + * In the case of CONFIG_VENETDEV, each virtual device has its own
77 + * ae531x_dev_sw_state, and virtual devices that share a physical MAC
78 + * point to the same ae531x_MAC_state.
80 +typedef struct ae531x_dev_sw_state {
81 + int enetUnit; /* system unit number "eth%d" */
82 + int unit_on_MAC; /* MAC-relative unit number */
83 + struct net_device *dev;
84 + ae531x_MAC_state_t *MAC_state; /* underlying MAC hw/sw state */
85 +#ifdef CONFIG_VENETDEV
86 + BOOL isLAN; /* 0-->WAN; 1-->LAN */
88 +} ae531x_dev_sw_state_t;
91 + * Driver-independent linux-specific per-ethernet device software information.
92 + * Regarding CONFIG_VENETDEV: If a system has 2 physical MACs, and each
93 + * physical MAC has 2 virtual ethernet devices (one for LAN and one for WAN),
94 + * then there are a total of 4 ethernet devices.
96 +static struct net_device *ae531x_MAC_dev[AR531X_NUM_ENET_MAC * AE531X_DEV_PER_MAC];
98 +/* Driver-dependent per-MAC information */
99 +static ae531x_MAC_state_t per_MAC_info[AR531X_NUM_ENET_MAC];
102 + * Receive buffers need enough room to hold the following:
103 + * 1) a max MTU-sized packet.
104 + * 2) space for an ethernet header
105 + * 3) room at the beginning of the receive buffer in order
106 + * to facilitate cooperating drivers that need to PREpend
108 + * 4) Depending on configuration, we may need some additional
109 + * room at the END of the rx buffer for phy-supplied
110 + * trailers (if any). (c.f. CONFIG_VENETDEV)
112 + * The DMA engine insists on 32-bit aligned RX buffers.
113 + * TBDXXX: With current code, the IP stack ends up looking
114 + * at misaligned headers with word operations. The misaligned
115 + * reads are software-emulated via handle_adel_int. We'd
116 + * rather align the buffers on a 16-bit boundary, but the
117 + * DMA engine doesn't permit it???
120 +#ifdef CONFIG_VLAN_8021Q
121 +#define ETH_MAX_MTU 1522
124 +#define ETH_MAX_MTU 1518
125 +#define HLEN ETH_HLEN
128 +#define AE531X_RX_BUF_SIZE \
129 + (((2 + RXBUFF_RESERVE + HLEN + ETH_MAX_MTU + PHY_TRAILER_SIZE) + 3) & ~3)
131 +/* Forward references to local functions */
132 +static void ae531x_TxReap(ae531x_MAC_state_t *MAC_state);
133 +static int ae531x_phy_poll(void *data);
134 +static int ae531x_MAC_stop(struct net_device *dev);
135 +static int ae531x_MAC_open(struct net_device *dev);
137 +/* Global to track number of MACs */
139 +int ar531x_num_enet_macs;
141 +#undef DEBUG_VENETDEV
144 +#if defined(CONFIG_VENETDEV) && defined(DEBUG_VENETDEV)
145 +static int cloned_counter;
146 +static int expand_counter;
147 +static int both_counter;
151 +/*******************************************************************************
152 +* ae531x_MAC_poll checks for received packets, and sends data
156 +ae531x_MAC_poll(struct net_device *dev, int *budget)
158 + struct sk_buff *skb;
159 + struct sk_buff *newskb;
164 + ae531x_dev_sw_state_t *dev_sw_state;
165 + ae531x_MAC_state_t *MAC_state;
166 + ae531x_MAC_t *MACInfo;
171 + struct net_device *rxdev;
174 +#ifdef CONFIG_VENETDEV
180 + dev_sw_state = (ae531x_dev_sw_state_t *)dev->priv;
181 + MAC_state = dev_sw_state->MAC_state;
182 + MACInfo = &MAC_state->MACInfo;
183 + rx_limit = MAC_state->dev_sw_state[MAC_state->primary_dev]->dev->quota;
186 +#ifdef CONFIG_VENETDEV
188 + * Non-primary devs don't explicitly get polled by the upper layers;
189 + * rather, they rely on primary_dev polling to feed packets. But in
190 + * order to keep netif_receive_skb happy, we need to temporarily put the
191 + * net_devices into "polling mode". We pull them back out before
192 + * leaving this function.
194 + for (i=0; i<AE531X_DEV_PER_MAC; i++) {
195 + if ((MAC_state->dev_sw_state[i]->dev) &&
196 + (MAC_state->dev_sw_state[i]->unit_on_MAC != MAC_state->primary_dev)) {
197 + netif_rx_schedule(MAC_state->dev_sw_state[i]->dev);
206 + // ae531x_AckIntr(MACInfo, (DmaIntRxCompleted | DmaIntRxNoBuffer));
208 + rxDesc = MACInfo->rxQueue.curDescAddr;
209 + cmdsts = AE531X_DESC_STATUS_GET(KSEG1ADDR(rxDesc));
211 + AE531X_PRINT(AE531X_DEBUG_RX,
212 + ("examine rxDesc %p with cmdsts=0x%x\n",
213 + (void *)rxDesc, cmdsts));
215 + if (cmdsts & DescOwnByDma) {
216 + /* There's nothing left to process in the RX ring */
222 + AE531X_CONSUME_DESC((&MACInfo->rxQueue));
224 + // A_DATA_CACHE_INVAL(rxDesc, AE531X_DESC_SIZE);
226 + /* Process a packet */
227 + length = AE531X_DESC_STATUS_RX_SIZE(cmdsts) - ETH_CRC_LEN;
228 + if ( (cmdsts & (DescRxFirst |DescRxLast | DescRxErrors)) ==
229 + (DescRxFirst | DescRxLast) ) {
230 + /* Descriptor status indicates "NO errors" */
231 + skb = AE531X_DESC_SWPTR_GET(rxDesc);
234 + * Allocate a replacement skb.
235 + * We want to get another buffer ready for Rx ASAP.
237 + newskb = (struct sk_buff *)ae531x_rxbuf_alloc(MACInfo, &rxBufp, &unused_length);
238 + if(newskb == NULL ) {
240 + * Give this descriptor back to the DMA engine,
241 + * and drop the received packet.
243 + MAC_state->stats.rx_dropped++;
244 + AE531X_PRINT(AE531X_DEBUG_ERROR,
245 + ("Can't allocate new skb\n"));
247 + AE531X_DESC_BUFPTR_SET(rxDesc, rxBufp);
248 + AE531X_DESC_SWPTR_SET(rxDesc, newskb);
251 + AE531X_DESC_STATUS_SET(rxDesc, DescOwnByDma);
252 + A_DATA_CACHE_FLUSH_INVAL(rxDesc, AE531X_DESC_SIZE);
253 + // rxDesc = NULL; /* sanity -- cannot use rxDesc now */
256 + if (newskb == NULL) {
260 + /* Sync data cache w.r.t. DMA */
261 + // A_DATA_CACHE_INVAL(skb->data, length);
263 +#ifdef CONFIG_VENETDEV
264 + /* Determine which associated device owns this rx buffer */
268 + fromLAN = phyDetermineSource(skb->data, length);
270 + if (fromLAN == -1) {
272 + * Could not determine source, so drop the packet
274 + dev_kfree_skb(skb);
278 + length -= PHY_TRAILER_SIZE;
280 + dev_sw_state = MAC_state->dev_sw_state[AE531X_LAN_PORT];
282 + dev_sw_state = MAC_state->dev_sw_state[AE531X_WAN_PORT];
286 + rxdev = dev_sw_state->dev;
288 + if (rxdev == NULL) {
290 + * We received a packet for a virtual enet device
291 + * that is no longer up. Ignore it.
293 + dev_kfree_skb(skb);
297 + /* Advance data pointer to show that there's data here */
298 + skb_put(skb, length);
299 + skb->protocol = eth_type_trans(skb, rxdev);
301 + rxdev->last_rx = jiffies;
304 + if (rx_limit-- < 0) {
306 + /* We've done enough for now -- more later */
307 + AE531X_PRINT(AE531X_DEBUG_RX_STOP,
308 + ("Enet%d RX early stop. Quota=%d rxDescCount=%d budget=%d\n",
309 + MACInfo->unit, dev->quota, rxDescCount, *budget));
313 + /* Send the data up the stack */
314 + AE531X_PRINT(AE531X_DEBUG_RX,
315 + ("Send data up stack: skb=%p data=%p length=%d\n",
316 + (void *)skb, (void *)skb->data, length));
318 + netif_receive_skb(skb);
320 + MAC_state->stats.rx_packets++;
321 + MAC_state->stats.rx_bytes += length;
324 + /* Descriptor status indicates ERRORS */
325 + MAC_state->stats.rx_errors++;
327 + if (cmdsts & (DescRxRunt | DescRxLateColl)) {
328 + AE531X_PRINT(AE531X_DEBUG_ERROR,
329 + ("Runt | RX Late Collision Error\n"));
330 + MAC_state->stats.collisions++;
333 + if (cmdsts & DescRxLengthError) {
334 + AE531X_PRINT(AE531X_DEBUG_ERROR,
335 + ("RX Length Error\n"));
336 + MAC_state->stats.rx_length_errors++;
339 + if (cmdsts & DescRxCrc) {
340 + AE531X_PRINT(AE531X_DEBUG_ERROR,
341 + ("RX CRC Error\n"));
342 + MAC_state->stats.rx_crc_errors++;
345 + if (cmdsts & DescRxDribbling) {
346 + AE531X_PRINT(AE531X_DEBUG_ERROR,
347 + ("Dribbling Error\n"));
348 + MAC_state->stats.rx_frame_errors++;
351 + AE531X_PRINT(AE531X_DEBUG_ERROR,
352 + ("Bad receive. rxDesc=%p cmdsts=0x%8.8x\n",
353 + (void *)rxDesc, cmdsts));
355 + /* Give this one back */
356 + AE531X_DESC_STATUS_SET(rxDesc, DescOwnByDma);
357 + A_DATA_CACHE_FLUSH_INVAL(rxDesc, AE531X_DESC_SIZE);
361 + } while ((!early_stop) &&
362 + ae531x_ReadDmaReg(MACInfo, DmaStatus) & DmaIntRxCompleted);
365 + AE531X_PRINT(AE531X_DEBUG_RX,
366 + ("rx done (%d)\n", rxDescCount));
367 + *budget -= rxDescCount;
370 + netif_rx_complete(dev);
372 + ae531x_SetDmaReg(MACInfo, DmaIntrEnb,
373 + DmaIeRxCompleted | DmaIeRxNoBuffer);
374 + ae531x_WriteDmaReg(MACInfo, DmaRxPollDemand, 0);
377 + retval = early_stop;
381 +#ifdef CONFIG_VENETDEV
382 + for (i=0; i<AE531X_DEV_PER_MAC; i++) {
383 + if ((MAC_state->dev_sw_state[i]->dev) &&
384 + (MAC_state->dev_sw_state[i]->unit_on_MAC !=
385 + MAC_state->primary_dev)) {
386 + netif_rx_complete(MAC_state->dev_sw_state[i]->dev);
397 +/*******************************************************************************
398 +* ae531x_MAC_recv checks for received packets, and sends data
402 +ae531x_MAC_recv(struct net_device *dev)
404 + struct sk_buff *skb;
405 + struct sk_buff *newskb;
410 + ae531x_dev_sw_state_t *dev_sw_state;
411 + ae531x_MAC_state_t *MAC_state;
412 + ae531x_MAC_t *MACInfo;
416 + struct net_device *rxdev;
421 + dev_sw_state = (ae531x_dev_sw_state_t *)dev->priv;
422 + MAC_state = dev_sw_state->MAC_state;
423 + MACInfo = &MAC_state->MACInfo;
424 + rx_limit = MAC_state->dev_sw_state[MAC_state->primary_dev]->dev->quota;
428 + rxDesc = MACInfo->rxQueue.curDescAddr;
429 + cmdsts = AE531X_DESC_STATUS_GET(KSEG1ADDR(rxDesc));
431 + AE531X_PRINT(AE531X_DEBUG_RX,
432 + ("examine rxDesc %p with cmdsts=0x%x\n",
433 + (void *)rxDesc, cmdsts));
435 + if (cmdsts & DescOwnByDma) {
436 + /* There's nothing left to process in the RX ring */
440 + AE531X_CONSUME_DESC((&MACInfo->rxQueue));
442 + // A_DATA_CACHE_INVAL(rxDesc, AE531X_DESC_SIZE);
444 + /* Process a packet */
445 + length = AE531X_DESC_STATUS_RX_SIZE(cmdsts) - ETH_CRC_LEN;
446 + if ( (cmdsts & (DescRxFirst |DescRxLast | DescRxErrors)) ==
447 + (DescRxFirst | DescRxLast) ) {
448 + /* Descriptor status indicates "NO errors" */
449 + skb = AE531X_DESC_SWPTR_GET(rxDesc);
452 + * Allocate a replacement skb.
453 + * We want to get another buffer ready for Rx ASAP.
455 + newskb = (struct sk_buff *)ae531x_rxbuf_alloc(MACInfo,
458 + if(newskb == NULL ) {
460 + * Give this descriptor back to the DMA engine,
461 + * and drop the received packet.
463 + MAC_state->stats.rx_dropped++;
464 + AE531X_PRINT(AE531X_DEBUG_ERROR,
465 + ("Can't allocate new skb\n"));
467 + AE531X_DESC_BUFPTR_SET(rxDesc, rxBufp);
468 + AE531X_DESC_SWPTR_SET(rxDesc, newskb);
471 + AE531X_DESC_STATUS_SET(rxDesc, DescOwnByDma);
472 + A_DATA_CACHE_FLUSH_INVAL(rxDesc, AE531X_DESC_SIZE);
475 + if (newskb == NULL) {
478 +#ifdef CONFIG_VENETDEV
479 + /* Determine which associated device owns this rx buffer */
483 + fromLAN = phyDetermineSource(skb->data, length);
485 + if (fromLAN == -1) {
487 + * Could not determine source, so drop the packet
489 + dev_kfree_skb(skb);
493 + length -= PHY_TRAILER_SIZE;
496 + MAC_state->dev_sw_state[AE531X_LAN_PORT];
499 + MAC_state->dev_sw_state[AE531X_WAN_PORT];
503 + rxdev = dev_sw_state->dev;
505 + if (rxdev == NULL) {
507 + * We received a packet for a virtual enet device
508 + * that is no longer up. Ignore it.
510 + dev_kfree_skb(skb);
514 + /* Advance data pointer to show that there's data here */
515 + skb_put(skb, length);
516 + skb->protocol = eth_type_trans(skb, rxdev);
518 + rxdev->last_rx = jiffies;
523 + /* Send the data up the stack */
524 + AE531X_PRINT(AE531X_DEBUG_RX,
525 + ("Send data up stack: skb=%p data=%p length=%d\n",
526 + (void *)skb, (void *)skb->data, length));
530 + MAC_state->stats.rx_packets++;
531 + MAC_state->stats.rx_bytes += length;
534 + /* Descriptor status indicates ERRORS */
535 + MAC_state->stats.rx_errors++;
537 + if (cmdsts & (DescRxRunt | DescRxLateColl)) {
538 + MAC_state->stats.collisions++;
541 + if (cmdsts & DescRxLengthError) {
542 + MAC_state->stats.rx_length_errors++;
545 + if (cmdsts & DescRxCrc) {
546 + MAC_state->stats.rx_crc_errors++;
549 + if (cmdsts & DescRxDribbling) {
550 + MAC_state->stats.rx_frame_errors++;
553 + AE531X_PRINT(AE531X_DEBUG_ERROR,
554 + ("Bad receive. rxDesc=%p cmdsts=0x%8.8x\n",
555 + (void *)rxDesc, cmdsts));
564 +/*******************************************************************************
565 +* ae531x_restart stops all ethernet devices associated with a physical MAC,
566 +* then shuts down the MAC. Then it re-opens all devices that were in use.
567 +* TBDXXX: needs testing!
570 +ae531x_restart(void *data)
572 + ae531x_MAC_t *MACInfo = (ae531x_MAC_t *)data;
573 + ae531x_MAC_state_t *MAC_state = (ae531x_MAC_state_t *)MACInfo->OSinfo;
574 + struct net_device *saved_dev[AE531X_DEV_PER_MAC];
577 + for (i=0; i<AE531X_DEV_PER_MAC; i++) {
578 + if ((saved_dev[i] = MAC_state->dev_sw_state[i]->dev) != NULL) {
579 + ae531x_MAC_stop(saved_dev[i]);
583 + for (i=0; i<AE531X_DEV_PER_MAC; i++) {
585 + ae531x_MAC_open(saved_dev[i]);
589 +/*******************************************************************************
590 +* ae531x_MAC_intr handle interrupts from an ethernet MAC.
591 +* It checks MAC status registers, and dispatches as appropriate.
594 +ae531x_MAC_intr(int cpl, void *dev_id, struct pt_regs *regs)
596 + ae531x_MAC_state_t *MAC_state;
597 + ae531x_MAC_t *MACInfo;
601 + struct net_device * primary_dev;
605 + MACInfo = (ae531x_MAC_t *)dev_id;
606 + MAC_state = (ae531x_MAC_state_t *)MACInfo->OSinfo;
607 + primary_dev = MAC_state->dev_sw_state[MAC_state->primary_dev]->dev;
610 + /* Clear any unhandled intr causes. */
611 + ae531x_WriteDmaReg(MACInfo, DmaStatus, UnhandledIntrMask);
613 + regIsr = ae531x_ReadDmaReg(MACInfo, DmaStatus);
615 + regImr = ae531x_ReadDmaReg(MACInfo, DmaIntrEnb);
616 + pendIntrs = regIsr & regImr;
618 + AE531X_PRINT(AE531X_DEBUG_INT,
619 + ("ethmac%d: intIsr=0x%8.8x intImr=0x%8.8x\n",
620 + MACInfo->unit, regIsr, regImr));
622 + if ((pendIntrs & DmaAllIntCauseMask) == 0)
625 + if ((pendIntrs & DmaIntRxCompleted) ||
626 + (pendIntrs & DmaIntRxNoBuffer)) {
628 + if (netif_rx_schedule_prep(primary_dev)) {
629 + ae531x_ClearDmaReg(MACInfo,
631 + DmaIeRxCompleted | DmaIeRxNoBuffer);
632 + ae531x_AckIntr(MACInfo,
633 + DmaIntRxCompleted | DmaIntRxNoBuffer);
634 + (void)ae531x_ReadDmaReg(MACInfo, DmaIntrEnb);
635 + __netif_rx_schedule(primary_dev);
637 + AE531X_PRINT(AE531X_DEBUG_ERROR,
638 + ("%s: Interrupt (0x%8.8x/0x%8.8x) while in poll. regs@%p, pc=%p, ra=%p\n",
641 + ae531x_ReadDmaReg(MACInfo, DmaIntrEnb),
643 + (void *)regs->cp0_epc,
644 + (void *)regs->regs[31]));
645 + ae531x_ClearDmaReg(MACInfo,
647 + DmaIeRxCompleted | DmaIeRxNoBuffer);
648 + ae531x_AckIntr(MACInfo,
649 + DmaIntRxCompleted | DmaIntRxNoBuffer);
652 + ae531x_MAC_recv(primary_dev);
653 + ae531x_AckIntr(MACInfo,
654 + DmaIntRxCompleted | DmaIntRxNoBuffer);
659 + (DmaIntTxStopped | DmaIntTxJabber | DmaIntTxUnderflow)) {
660 + AE531X_PRINT(AE531X_DEBUG_ERROR,
661 + ("ethmac%d: TX Error Intr (0x%x)\n",
662 + MACInfo->unit, pendIntrs));
663 + ae531x_AckIntr(MACInfo,
664 + (DmaIntTxStopped | DmaIntTxJabber | DmaIntTxUnderflow));
667 + if (pendIntrs & DmaIntBusError) {
668 + AE531X_PRINT(AE531X_DEBUG_ERROR,
669 + ("ethmac%d: DMA Bus Error Intr (0x%x)\n",
670 + MACInfo->unit, pendIntrs));
671 + ae531x_AckIntr(MACInfo, DmaIntBusError);
672 + /* Reset the chip, if it's not already being done */
673 + if (ae531x_IsInResetMode(MACInfo)) {
676 + ae531x_BeginResetMode(MACInfo);
677 + schedule_task(&MAC_state->restart_task);
680 + if (pendIntrs & DmaIntRxStopped) {
681 + AE531X_PRINT(AE531X_DEBUG_ERROR,
682 + ("ethmac%d: RX Stopped Intr (0x%x)\n",
683 + MACInfo->unit, pendIntrs));
684 + ae531x_AckIntr(MACInfo, DmaIntRxStopped);
688 + ae531x_DmaIntEnable(MACInfo);
694 +/*******************************************************************************
695 +* ae531x_MAC_get_stats returns statistics for a specified device
697 +static struct net_device_stats*
698 +ae531x_MAC_get_stats(struct net_device *dev)
700 + ae531x_dev_sw_state_t *dev_sw_state;
701 + ae531x_MAC_state_t *MAC_state;
704 + dev_sw_state = (ae531x_dev_sw_state_t *)dev->priv;
705 + MAC_state = dev_sw_state->MAC_state;
708 + return &MAC_state->stats;
711 +#define AE531X_PHY_POLL_SECONDS 2
713 +/*******************************************************************************
714 +* ae531x_phy_poll periodically checks for changes in phy status
715 +* (e.g. dropped link).
718 +ae531x_phy_poll(void *data)
720 + ae531x_dev_sw_state_t *dev_sw_state = (ae531x_dev_sw_state_t *)data;
721 + ae531x_MAC_t *MACInfo = &dev_sw_state->MAC_state->MACInfo;
722 + int unit = dev_sw_state->enetUnit;
724 +#if defined(CONFIG_VENETDEV) && defined(DEBUG_VENETDEV)
725 + int previous_cloned = 0;
726 + int previous_expand = 0;
727 + int previous_both = 0;
731 + reparent_to_init();
732 + spin_lock_irq(¤t->sigmask_lock);
733 + sigemptyset(¤t->blocked);
734 + recalc_sigpending(current);
735 + spin_unlock_irq(¤t->sigmask_lock);
737 + snprintf(current->comm, sizeof(current->comm), "%s",
738 + dev_sw_state->dev->name);
741 + if (MACInfo->port_is_up) {
742 + phyCheckStatusChange(unit);
745 +#if defined(CONFIG_VENETDEV) && defined(DEBUG_VENETDEV)
746 + if (cloned_counter != previous_cloned) {
747 + printk("Cloned Counter: %d (delta %d)\n",
748 + cloned_counter, cloned_counter - previous_cloned);
749 + previous_cloned = cloned_counter;
751 + if (expand_counter != previous_expand) {
752 + printk("Expand Counter: %d (delta %d)\n",
753 + expand_counter, expand_counter - previous_expand);
754 + previous_expand = expand_counter;
756 + if (both_counter != previous_both) {
757 + printk("Expand & Cloned Counter: %d (delta %d)\n",
758 + both_counter, both_counter - previous_both);
759 + previous_both = both_counter;
763 + set_current_state(TASK_UNINTERRUPTIBLE);
764 + schedule_timeout(AE531X_PHY_POLL_SECONDS * HZ);
771 +/*******************************************************************************
772 +* ae531x_MAC_set_rx_mode is used to set the RX mode options, such as
773 +* promiscuous or multicast.
776 +ae531x_MAC_set_rx_mode(struct net_device *dev)
778 + ae531x_dev_sw_state_t *dev_sw_state = (ae531x_dev_sw_state_t *)dev->priv;
779 + ae531x_MAC_state_t *MAC_state=dev_sw_state->MAC_state;
780 + ae531x_MAC_t *MACInfo = &MAC_state->MACInfo;
782 + if (dev->flags & IFF_PROMISC) {
783 + ae531x_SetMacReg(MACInfo, MacControl, MacPromiscuousModeOn);
785 + ae531x_ClearMacReg(MACInfo, MacControl, MacPromiscuousModeOn);
788 + if (dev->flags & IFF_MULTICAST) {
789 + ae531x_SetMacReg(MACInfo, MacControl, MacMulticastFilterOff);
791 + ae531x_ClearMacReg(MACInfo, MacControl, MacMulticastFilterOff);
795 +/*******************************************************************************
796 +* ae531x_MAC_open is the standard Linux open function. It puts
797 +* hardware into a known good state, allocates queues, starts
798 +* the phy polling task, and arranges for interrupts to be handled.
801 +ae531x_MAC_open(struct net_device *dev)
803 + ae531x_dev_sw_state_t *dev_sw_state;
804 + ae531x_MAC_state_t *MAC_state;
805 + ae531x_MAC_t *MACInfo;
807 + struct tq_struct *restart_task;
808 + pid_t phy_poll_pid;
812 + dev_sw_state = (ae531x_dev_sw_state_t *)dev->priv;
813 + dev_sw_state->dev = dev;
814 + MAC_state = dev_sw_state->MAC_state;
815 + MACInfo = &MAC_state->MACInfo;
817 + restart_task = &MAC_state->restart_task;
818 + restart_task->routine = ae531x_restart;
819 + restart_task->data = (void *)MACInfo;
821 + AE531X_PRINT(AE531X_DEBUG_RESET,
822 + ("ae531x_MAC_open eth%d ethmac%d macBase=0x%x dmaBase=0x%x irq=0x%x\n",
823 + dev_sw_state->enetUnit,
829 + if (!MACInfo->port_is_up) {
830 + /* Bring MAC and PHY out of reset */
831 + ae531x_reset(MACInfo);
833 + /* Attach interrupt handler */
834 + rv = request_irq(MAC_state->irq, ae531x_MAC_intr, SA_INTERRUPT,
835 + "ae531x_MAC_intr", (void *)MACInfo);
837 + AE531X_PRINT(AE531X_DEBUG_ERROR,
838 + ("request_irq(0x%x) failed (%d)\n",
839 + MAC_state->irq, rv));
843 + /* Initialize PHY */
844 + phySetup(MACInfo->unit, MACInfo->phyBase);
846 + /* Start thread to poll for phy link status changes */
847 + phy_poll_pid = kernel_thread(ae531x_phy_poll,
849 + CLONE_FS | CLONE_FILES);
850 + if (phy_poll_pid < 0) {
851 + AE531X_PRINT(AE531X_DEBUG_ERROR,
852 + ("ethmac%d unable to start Phy Poll thread\n",
856 + /* Allocate RX/TX Queues */
857 + if (ae531x_AllocateQueues(MACInfo) < 0) {
858 + AE531X_PRINT(AE531X_DEBUG_RESET, ("Queue allocation failed"));
859 + free_irq(MAC_state->irq, (void *)MACInfo);
863 + /* Initialize DMA and descriptors */
864 + ae531x_DmaReset(MACInfo);
866 + /* Initialize MAC */
867 + ae531x_MACReset(MACInfo);
870 + ae531x_MAC_set_rx_mode(dev);
872 + /* Enable Receive/Transmit */
873 + ae531x_EnableComm(MACInfo);
875 + MAC_state->primary_dev = dev_sw_state->unit_on_MAC;
876 + MACInfo->port_is_up = TRUE;
879 + dev->trans_start = jiffies;
890 + * Shut down MAC hardware.
893 +ae531x_MAC_shutdown(ae531x_MAC_state_t *MAC_state)
895 + ae531x_MAC_t *MACInfo;
897 + MACInfo = &MAC_state->MACInfo;
898 + MACInfo->port_is_up = FALSE;
900 + /* Disable Receive/Transmit */
901 + ae531x_DisableComm(MACInfo);
903 + /* Disable Interrupts */
904 + ae531x_DmaIntDisable(MACInfo);
906 + free_irq(MAC_state->irq, (void *)MACInfo);
908 + /* Free Transmit & Receive skb's/descriptors */
909 + ae531x_TxReap(MAC_state); /* one last time */
910 + ae531x_FreeQueues(MACInfo);
913 +/*******************************************************************************
914 +* ae531x_MAC_stop is the standard Linux stop function. It undoes
915 +* everything set up by ae531x_MAC_open.
918 +ae531x_MAC_stop(struct net_device *dev)
920 + ae531x_dev_sw_state_t *dev_sw_state;
921 + ae531x_MAC_state_t *MAC_state;
922 + ae531x_MAC_t *MACInfo;
927 + dev_sw_state = (ae531x_dev_sw_state_t *)dev->priv;
928 + MAC_state = dev_sw_state->MAC_state;
929 + MACInfo = &MAC_state->MACInfo;
931 + for (i=0; i<AE531X_DEV_PER_MAC; i++) {
932 + if ((MAC_state->dev_sw_state[i]->dev) &&
933 + (MAC_state->dev_sw_state[i]->dev != dev_sw_state->dev)) {
938 + if (i < AE531X_DEV_PER_MAC) {
939 + /* Physical MAC is still in use */
940 + if (MAC_state->primary_dev == dev_sw_state->unit_on_MAC) {
942 + * If the primary_dev is being stopped
943 + * then we need to assign a new one.
945 + MAC_state->primary_dev = i;
948 + /* Physical MAC is no longer in use */
949 + ae531x_MAC_shutdown(MAC_state);
952 + dev_sw_state->dev = NULL;
958 +/*******************************************************************************
959 +* ae531x_rxbuf_alloc - Allocate an skb to be associated with an RX descriptor.
961 +* RETURNS: A pointer to the skb. Also returns a pointer to the underlying
962 +* buffer and the size of that buffer.
965 +ae531x_rxbuf_alloc(ae531x_MAC_t *MACInfo, char **rxBuffp, int *rxBuffSizep)
967 + struct sk_buff *skb;
971 + skb = dev_alloc_skb(AE531X_RX_BUF_SIZE);
973 + /* Add 2 to align the IP header on a DWORD boundary */
974 + skb_reserve(skb, RXBUFF_RESERVE + 2);
976 + rxBuffSize = skb_tailroom(skb);
977 + rxBuff = skb->tail;
980 + *rxBuffSizep = rxBuffSize;
982 + A_DATA_CACHE_INVAL(rxBuff, rxBuffSize);
988 +/*******************************************************************************
989 +* ae531x_swptr_free - Free the skb, if any, associated with a descriptor.
992 +ae531x_swptr_free(VIRT_ADDR desc)
994 + struct sk_buff *skb;
996 + skb = (struct sk_buff *)AE531X_DESC_SWPTR_GET(desc);
998 + AE531X_DESC_SWPTR_SET(desc, NULL);
1003 +/*******************************************************************************
1005 +* ae531x_TxReap - the driver Tx completion routine.
1007 +* This routine reaps sk_buffs which have already been transmitted.
1011 +ae531x_TxReap(ae531x_MAC_state_t *MAC_state)
1013 + AE531X_QUEUE *txq;
1016 + struct sk_buff *skb;
1018 + ae531x_MAC_t *MACInfo;
1019 + static int aeUselessReap = 0;
1023 + MACInfo = &MAC_state->MACInfo;
1024 + txq = &MACInfo->txQueue;
1028 + txDesc = AE531X_QUEUE_ELE_NEXT_GET(txq, txq->reapDescAddr);
1029 + if (txDesc == txq->curDescAddr) {
1033 + cmdsts = AE531X_DESC_STATUS_GET(KSEG1ADDR(txDesc));
1034 + if (cmdsts & DescOwnByDma) {
1038 + /* Release sk_buff associated with completed transmit */
1039 + skb = (struct sk_buff *)AE531X_DESC_SWPTR_GET(txDesc);
1043 + AE531X_DESC_SWPTR_SET(txDesc, NULL);
1046 + /* Update statistics according to completed transmit desc */
1047 + if (cmdsts & DescTxErrors) {
1048 + AE531X_PRINT(AE531X_DEBUG_ERROR,
1049 + ("enetmac%d Tx prior error: 0x%8.8x <0x%8.8x> 0x%8.8x\n",
1054 + MAC_state->stats.tx_errors++;
1055 + if (cmdsts & (DescTxLateCollision | DescTxExcCollisions)) {
1056 + MAC_state->stats.tx_aborted_errors++;
1058 + if (cmdsts & (DescTxLostCarrier | DescTxNoCarrier)) {
1059 + MAC_state->stats.tx_carrier_errors++;
1062 + MAC_state->stats.tx_bytes += AE531X_DESC_STATUS_RX_SIZE(cmdsts);
1063 + MAC_state->stats.tx_packets++;
1066 + MAC_state->stats.collisions +=
1067 + ((cmdsts & DescTxCollMask) >> DescTxCollShift);
1069 + txq->reapDescAddr = txDesc;
1076 + AE531X_PRINT(AE531X_DEBUG_TX_REAP,
1077 + ("reaped %d\n", reaped));
1080 + * Re-start transmit queues for all ethernet devices
1081 + * associated with this MAC.
1083 + for (i=0; i<AE531X_DEV_PER_MAC; i++) {
1084 + if (MAC_state->dev_sw_state[i]->dev)
1085 + netif_start_queue(MAC_state->dev_sw_state[i]->dev);
1094 +/*******************************************************************************
1095 +* ae531x_MAC_start_xmit sends a packet.
1098 +ae531x_MAC_start_xmit(struct sk_buff *skb, struct net_device *dev)
1100 + ae531x_dev_sw_state_t *dev_sw_state;
1101 + ae531x_MAC_state_t *MAC_state;
1102 + ae531x_MAC_t *MACInfo;
1112 + dev_sw_state = (ae531x_dev_sw_state_t *)dev->priv;
1113 + MAC_state = dev_sw_state->MAC_state;
1114 + MACInfo = &MAC_state->MACInfo;
1116 + length = skb->len;
1118 + /* Check if this port is up, else toss packet */
1119 + if (!MACInfo->port_is_up) {
1120 + buf = virt_to_bus(skb->data);
1121 + AE531X_PRINT(AE531X_DEBUG_ERROR,
1122 + ("eth%d Tx Down, dropping buf=0x%8.8x, length=0x%8.8x, skb=%p\n",
1123 + dev_sw_state->enetUnit, buf, length, (void *)skb));
1125 + MAC_state->stats.tx_dropped++;
1126 + MAC_state->stats.tx_carrier_errors++;
1130 + if (ae531x_IsInResetMode(MACInfo)) {
1131 + AE531X_PRINT(AE531X_DEBUG_ERROR,
1132 + ("eth%d Tx: In Chip reset - drop frame\n",
1133 + dev_sw_state->enetUnit));
1135 + MAC_state->stats.tx_dropped++;
1136 + MAC_state->stats.tx_aborted_errors++;
1140 + /* Check if we can transport this packet */
1141 + length = max((u32)60, length); /* total length */
1143 + max_buf_size = mtu + HLEN;
1144 + if (length > max_buf_size) {
1145 + AE531X_PRINT(AE531X_DEBUG_ERROR,
1146 + ("eth%d Tx: length %d too long. mtu=%d, trailer=%d\n",
1147 + dev_sw_state->enetUnit, length, mtu, PHY_TRAILER_SIZE));
1149 + MAC_state->stats.tx_errors++;
1150 + MAC_state->stats.tx_aborted_errors++;
1155 + /* Reap any old, completed Tx descriptors */
1156 + ae531x_TxReap(MAC_state);
1158 + txDesc = MACInfo->txQueue.curDescAddr;
1159 + if (txDesc == MACInfo->txQueue.reapDescAddr) {
1162 + AE531X_PRINT(AE531X_DEBUG_ERROR,
1163 + ("eth%d Tx: cannot get txDesc\n",
1164 + dev_sw_state->enetUnit));
1166 + MAC_state->stats.tx_dropped++;
1167 + MAC_state->stats.tx_fifo_errors++;
1170 + * Stop transmit queues for any ethernet devices
1171 + * associated with this MAC.
1173 + for (i=0; i<AE531X_DEV_PER_MAC; i++) {
1174 + if (MAC_state->dev_sw_state[i]->dev)
1175 + netif_stop_queue(MAC_state->dev_sw_state[i]->dev);
1180 +#ifdef CONFIG_VENETDEV
1182 + struct sk_buff *newskb;
1184 + if (skb_cloned(skb) || (skb_tailroom(skb) < PHY_TRAILER_SIZE)) {
1185 +#ifdef DEBUG_VENETDEV
1186 + if (skb_cloned(skb)) {
1188 + if (skb_tailroom(skb) < PHY_TRAILER_SIZE) {
1195 + newskb = skb_copy_expand(skb, 0, PHY_TRAILER_SIZE, GFP_ATOMIC);
1196 + if (newskb == NULL) {
1200 + dev_kfree_skb(skb);
1204 + phySetDestinationPort(skb->data, length, dev_sw_state->isLAN);
1205 + skb_put(skb, PHY_TRAILER_SIZE);
1206 + length += PHY_TRAILER_SIZE;
1210 + /* We won't fail now; so consume this descriptor */
1211 + AE531X_CONSUME_DESC((&MACInfo->txQueue));
1213 + /* Update the descriptor */
1214 + buf = virt_to_bus(skb->data);
1215 + A_DATA_CACHE_FLUSH(skb->data, skb->len);
1216 + AE531X_DESC_BUFPTR_SET(txDesc, buf);
1217 + AE531X_DESC_SWPTR_SET(txDesc, skb);
1218 + ctrlen = AE531X_DESC_CTRLEN_GET(txDesc);
1219 + ctrlen = (ctrlen & (DescEndOfRing)) |
1224 + ctrlen |= ((length << DescSize1Shift) & DescSize1Mask);
1226 + AE531X_DESC_CTRLEN_SET(txDesc, ctrlen);
1227 + AE531X_DESC_STATUS_SET(txDesc, DescOwnByDma);
1229 + AE531X_PRINT(AE531X_DEBUG_TX,
1230 + ("eth%d Tx: Desc=0x%8.8x, L=0x%8.8x, D=0x%8.8x, d=0x%8.8x, length=0x%8.8x\n",
1231 + dev_sw_state->enetUnit,
1233 + AE531X_DESC_CTRLEN_GET(txDesc),
1235 + AE531X_DESC_LNKBUF_GET(txDesc),
1238 + /* Must not use txDesc after this point */
1239 + A_DATA_CACHE_FLUSH_INVAL(txDesc, AE531X_DESC_SIZE);
1241 + /* Alert DMA engine to resume Tx */
1242 + ae531x_WriteDmaReg(MACInfo, DmaTxPollDemand, 0);
1245 + MAC_state->stats.tx_packets++;
1246 + MAC_state->stats.tx_bytes += length;
1248 + /* Tell upper layers to keep it coming */
1249 + dev->trans_start = jiffies;
1255 + dev_kfree_skb(skb);
1262 +/*******************************************************************************
1263 +* ae531x_MAC_tx_timeout handles transmit timeouts
1266 +ae531x_MAC_tx_timeout(struct net_device *dev)
1268 + ae531x_dev_sw_state_t *dev_sw_state;
1269 + ae531x_MAC_state_t *MAC_state;
1270 + ae531x_MAC_t *MACInfo;
1274 + dev_sw_state = (ae531x_dev_sw_state_t *)dev->priv;
1275 + MAC_state = dev_sw_state->MAC_state;
1276 + MACInfo = &MAC_state->MACInfo;
1278 + AE531X_PRINT(AE531X_DEBUG_ERROR,
1279 + ("enet%d: Tx timeout\n", dev_sw_state->enetUnit));
1281 + ae531x_restart(MACInfo);
1287 +/*******************************************************************************
1288 +* ae531x_MAC_do_ioctl is a placeholder for future ioctls.
1291 +ae531x_MAC_do_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
1294 + ae531x_MAC_t *MACInfo;
1295 + struct ioctl_data {
1300 + ae531x_dev_sw_state_t *dev_sw_state;
1301 + ae531x_MAC_state_t *MAC_state;
1305 + dev_sw_state = (ae531x_dev_sw_state_t *)dev->priv;
1306 + MAC_state = dev_sw_state->MAC_state;
1307 + MACInfo = &MAC_state->MACInfo;
1309 + req = (struct ioctl_data *)ifr->ifr_data;
1313 + AE531X_PRINT(AE531X_DEBUG_ERROR,
1314 + ("Unsupported ioctl: 0x%x\n", cmd));
1322 +/*******************************************************************************
1323 +* ae531x_MAC_set_mac_address sets a new hardware address for the device
1326 +ae531x_MAC_set_mac_address(struct net_device *dev, void *addr)
1328 + struct sockaddr *saddr = (struct sockaddr *)addr;
1330 + /* update dev struct */
1331 + memcpy(dev->dev_addr, &saddr->sa_data[0], dev->addr_len);
1336 +/******************************************************************************
1337 +* macAddrGet - Given a MACInfo pointer, return a pointer to an
1338 +* array of chars that holds the corresponding MAC address.
1340 +char *macAddrGet(ae531x_MAC_t *MACInfo)
1342 + // return enet_mac_address_get(MACInfo->unit);
1343 + return ae531x_MAC_dev[MACInfo->unit]->dev_addr;
1347 +ae531x_MAC_setup_fntable(struct net_device *dev)
1349 + /* Set a default (should be overridden by software) */
1350 + u8 default_MAC_address[] = { 0x00, 0x03, 0x7f, 0xe0, 0x02, 0xbF };
1354 + dev->get_stats = ae531x_MAC_get_stats;
1355 + dev->open = ae531x_MAC_open;
1356 + dev->stop = ae531x_MAC_stop;
1357 + dev->hard_start_xmit = ae531x_MAC_start_xmit;
1358 + dev->do_ioctl = ae531x_MAC_do_ioctl;
1360 + dev->poll = ae531x_MAC_poll;
1363 + dev->tx_timeout = ae531x_MAC_tx_timeout;
1364 + dev->features = NETIF_F_HW_CSUM |\
1366 + dev->set_mac_address = ae531x_MAC_set_mac_address;
1367 + dev->set_multicast_list = ae531x_MAC_set_rx_mode;
1369 + /* Copy default MAC address into device descriptor */
1370 + memcpy(dev->dev_addr, default_MAC_address, dev->addr_len );
1376 + * ae531x_twisted_enet() returns 1 for chips where there is only one usable
1377 + * MAC, and that MAC is 1.
1380 +ae531x_twisted_enet(void)
1382 + int wisoc_revision;
1383 + int flash_bus_width;
1385 + wisoc_revision = (sysRegRead(AR531X_REV) & AR531X_REV_MAJ) >>
1387 + if (wisoc_revision == AR531X_REV_MAJ_AR2313)
1390 + flash_bus_width = sysRegRead(AR531X_FLASHCTL0) & FLASHCTL_MWx16;
1392 + if (flash_bus_width == 0) {
1393 + printk("Found AR2312-01\n");
1394 + return TRUE; /* AR2312-01 has 8 bit flash bus */
1396 + printk("Found AR2312-00\n");
1402 +ae531x_MAC_setup(void)
1407 + struct net_device *dev;
1408 + ae531x_dev_sw_state_t *dev_sw_state;
1409 + ae531x_MAC_state_t *MAC_state;
1410 + ae531x_MAC_t *MACInfo;
1416 + * This does not work since the AR2312 and AR5312 both have the same
1417 + * revision information in the CPU :-(
1419 + rev = (sysRegRead(AR531X_REV) & AR531X_REV_CHIP);
1421 + if ((rev & AR531X_REV_MIN) == AR5312_REV_MIN_SINGLE_ENET) {
1422 + ar531x_num_enet_macs = 1;
1424 + ar531x_num_enet_macs = 2;
1428 + * Need to select the number of ethernet MACs based on the config
1429 + * information (sadly)
1431 +#ifdef CONFIG_AR5312
1432 + ar531x_num_enet_macs = 2;
1434 + ar531x_num_enet_macs = 1;
1439 + for (i=0; i<ar531x_num_enet_macs; i++) {
1441 + dev = ae531x_MAC_dev[next_dev] =
1442 + init_etherdev(NULL, sizeof(ae531x_dev_sw_state_t));
1444 + if (dev == NULL) {
1449 + ae531x_MAC_setup_fntable(dev);
1451 + dev_sw_state = (ae531x_dev_sw_state_t *)dev->priv;
1452 + dev_sw_state->enetUnit = next_dev;
1453 + dev_sw_state->unit_on_MAC = 0;
1454 + MAC_state = &per_MAC_info[i];
1455 + dev_sw_state->MAC_state = MAC_state;
1456 + MAC_state->dev_sw_state[AE531X_LAN_PORT] = dev_sw_state;
1457 + MAC_state->primary_dev = -1;
1461 +#ifdef CONFIG_VENETDEV
1463 + ae531x_dev_sw_state_t *lan_dev_sw_state;
1465 + lan_dev_sw_state = dev_sw_state;
1467 + dev = ae531x_MAC_dev[next_dev] =
1468 + init_etherdev(NULL, sizeof(ae531x_dev_sw_state_t));
1470 + if (dev == NULL) {
1475 + ae531x_MAC_setup_fntable(dev);
1477 + dev_sw_state = (ae531x_dev_sw_state_t *)dev->priv;
1478 + dev_sw_state->enetUnit = next_dev;
1479 + dev_sw_state->unit_on_MAC = 1;
1480 + dev_sw_state->MAC_state = MAC_state;
1481 + MAC_state->dev_sw_state[AE531X_WAN_PORT] = dev_sw_state;
1482 + lan_dev_sw_state->isLAN = TRUE; /* enet0 is LAN */
1483 + dev_sw_state->isLAN = FALSE ; /* enet1 is WAN */
1489 + /* Initialize per-MAC information */
1490 + MACInfo = &MAC_state->MACInfo;
1491 + MACInfo->unit = i;
1493 + if (ar531x_num_enet_macs == 1) {
1494 + if (ae531x_twisted_enet()) {
1495 + MACInfo->macBase =
1496 + (u32)(PHYS_TO_K1(AR531X_ENET1)+AE531X_MAC_OFFSET);
1497 + MACInfo->dmaBase =
1498 + (u32)(PHYS_TO_K1(AR531X_ENET1)+AE531X_DMA_OFFSET);
1499 + MACInfo->phyBase =
1500 + (u32)(PHYS_TO_K1(AR531X_ENET0)+AE531X_PHY_OFFSET);
1501 + MAC_state->irq = AR531X_IRQ_ENET1_INTRS;
1503 + MACInfo->macBase =
1504 + (u32)(PHYS_TO_K1(AR531X_ENET0)+AE531X_MAC_OFFSET);
1505 + MACInfo->dmaBase =
1506 + (u32)(PHYS_TO_K1(AR531X_ENET0)+AE531X_DMA_OFFSET);
1507 + MACInfo->phyBase =
1508 + (u32)(PHYS_TO_K1(AR531X_ENET0)+AE531X_PHY_OFFSET);
1509 + MAC_state->irq = AR531X_IRQ_ENET0_INTRS;
1512 + if (MACInfo->unit == 0) {
1513 + MACInfo->macBase =
1514 + (u32)(PHYS_TO_K1(AR531X_ENET0)+AE531X_MAC_OFFSET);
1515 + MACInfo->dmaBase =
1516 + (u32)(PHYS_TO_K1(AR531X_ENET0)+AE531X_DMA_OFFSET);
1517 + MACInfo->phyBase =
1518 + (u32)(PHYS_TO_K1(AR531X_ENET0)+AE531X_PHY_OFFSET);
1519 + MAC_state->irq = AR531X_IRQ_ENET0_INTRS;
1521 + MACInfo->macBase =
1522 + (u32)(PHYS_TO_K1(AR531X_ENET1)+AE531X_MAC_OFFSET);
1523 + MACInfo->dmaBase =
1524 + (u32)(PHYS_TO_K1(AR531X_ENET1)+AE531X_DMA_OFFSET);
1525 + MACInfo->phyBase =
1526 + (u32)(PHYS_TO_K1(AR531X_ENET1)+AE531X_PHY_OFFSET);
1527 + MAC_state->irq = AR531X_IRQ_ENET1_INTRS;
1530 + MACInfo->OSinfo = (void *)MAC_state;
1537 +module_init(ae531x_MAC_setup);
1539 diff -urN linux-2.4.32.new/arch/mips/ar531x/ae531xmac.c linux-2.4.32.new-eth/arch/mips/ar531x/ae531xmac.c
1540 --- linux-2.4.32.new/arch/mips/ar531x/ae531xmac.c 1970-01-01 01:00:00.000000000 +0100
1541 +++ linux-2.4.32.new-eth/arch/mips/ar531x/ae531xmac.c 2005-12-25 11:54:20.771271672 +0000
1544 + * This file is subject to the terms and conditions of the GNU General Public
1545 + * License. See the file "COPYING" in the main directory of this archive
1546 + * for more details.
1548 + * Copyright © 2003 Atheros Communications, Inc., All Rights Reserved.
1553 + * Ethernet driver for Atheros' ae531x ethernet MAC.
1557 +#include <linux/config.h>
1558 +#include <linux/types.h>
1559 +#include <linux/delay.h>
1560 +#include <linux/netdevice.h>
1561 +#include <linux/etherdevice.h>
1562 +#include <linux/init.h>
1563 +#include <asm/io.h>
1565 +#include "ar531xlnx.h"
1568 +#include "ae531xreg.h"
1569 +#include "ae531xmac.h"
1571 +int ae531x_MAC_debug = AE531X_DEBUG_ERROR;
1574 + * These externs are for functions that this layer relies on
1575 + * that have OS-dependent implementations.
1577 +extern UINT8 *macAddrGet(ae531x_MAC_t *MACInfo);
1579 +/* Forward references to local functions */
1580 +static void ae531x_QueueDestroy(AE531X_QUEUE *q);
1583 +/******************************************************************************
1585 +* ae531x_ReadMacReg - read AE MAC register
1587 +* RETURNS: register value
1590 +ae531x_ReadMacReg(ae531x_MAC_t *MACInfo, UINT32 reg)
1592 + UINT32 addr = MACInfo->macBase+reg;
1595 + data = RegRead(addr);
1600 +/******************************************************************************
1602 +* ae531x_WriteMacReg - write AE MAC register
1607 +ae531x_WriteMacReg(ae531x_MAC_t *MACInfo, UINT32 reg, UINT32 data)
1609 + UINT32 addr = MACInfo->macBase+reg;
1611 + RegWrite(data, addr);
1615 +/******************************************************************************
1617 +* ae531x_SetMacReg - set bits in AE MAC register
1622 +ae531x_SetMacReg(ae531x_MAC_t *MACInfo, UINT32 reg, UINT32 val)
1624 + UINT32 addr = MACInfo->macBase+reg;
1625 + UINT32 data = RegRead(addr);
1628 + RegWrite(data, addr);
1632 +/******************************************************************************
1634 +* ae531x_ClearMacReg - clear bits in AE MAC register
1639 +ae531x_ClearMacReg(ae531x_MAC_t *MACInfo, UINT32 reg, UINT32 val)
1641 + UINT32 addr = MACInfo->macBase+reg;
1642 + UINT32 data = RegRead(addr);
1645 + RegWrite(data, addr);
1649 +/******************************************************************************
1651 +* ae531x_ReadDmaReg - read AE DMA register
1653 +* RETURNS: register value
1656 +ae531x_ReadDmaReg(ae531x_MAC_t *MACInfo, UINT32 reg)
1658 + UINT32 addr = MACInfo->dmaBase+reg;
1659 + UINT32 data = RegRead(addr);
1665 +/******************************************************************************
1667 +* ae531x_WriteDmaReg - write AE DMA register
1672 +ae531x_WriteDmaReg(ae531x_MAC_t *MACInfo, UINT32 reg, UINT32 data)
1674 + UINT32 addr = MACInfo->dmaBase+reg;
1676 + RegWrite(data, addr);
1680 +/******************************************************************************
1682 + * ae531x_AckIntr - clear interrupt bits in the status register.
1683 + * Note: Interrupt bits are *cleared* by writing a 1.
1686 +ae531x_AckIntr(ae531x_MAC_t *MACInfo, UINT32 data)
1688 + ae531x_WriteDmaReg(MACInfo, DmaStatus, data);
1692 +/******************************************************************************
1694 +* ae531x_SetDmaReg - set bits in an AE DMA register
1699 +ae531x_SetDmaReg(ae531x_MAC_t *MACInfo, UINT32 reg, UINT32 val)
1701 + UINT32 addr = MACInfo->dmaBase+reg;
1702 + UINT32 data = RegRead(addr);
1705 + RegWrite(data, addr);
1709 +/******************************************************************************
1711 +* ae531x_ClearDmaReg - clear bits in an AE DMA register
1716 +ae531x_ClearDmaReg(ae531x_MAC_t *MACInfo, UINT32 reg, UINT32 val)
1718 + UINT32 addr = MACInfo->dmaBase+reg;
1719 + UINT32 data = RegRead(addr);
1722 + RegWrite(data, addr);
1726 +/******************************************************************************
1728 +* ae531x_ReadMiiReg - read PHY registers via AE MAC Mii addr/data registers
1730 +* RETURNS: register value
1733 +ae531x_ReadMiiReg(UINT32 phyBase, UINT32 reg)
1736 + UINT32 addr = phyBase+reg;
1738 + data = RegRead(addr);
1743 +/******************************************************************************
1745 +* ae531x_WriteMiiReg - write PHY registers via AE MAC Mii addr/data registers
1750 +ae531x_WriteMiiReg(UINT32 phyBase, UINT32 reg, UINT32 data)
1752 + UINT32 addr = phyBase+reg;
1754 + RegWrite(data, addr);
1758 +/******************************************************************************
1760 +* ae531x_MiiRead - read AE Mii register
1762 +* RETURNS: register value
1765 +ae531x_MiiRead(UINT32 phyBase, UINT32 phyAddr, UINT8 reg)
1770 + addr = ((phyAddr << MiiDevShift) & MiiDevMask) | ((reg << MiiRegShift) & MiiRegMask);
1772 + ae531x_WriteMiiReg(phyBase, MacMiiAddr, addr );
1775 + } while ((ae531x_ReadMiiReg(phyBase, MacMiiAddr ) & MiiBusy) == MiiBusy);
1777 + data = ae531x_ReadMiiReg(phyBase, MacMiiData) & 0xFFFF;
1783 +/******************************************************************************
1785 +* ae531x_MiiWrite - write AE Mii register
1790 +ae531x_MiiWrite(UINT32 phyBase, UINT32 phyAddr, UINT8 reg, UINT16 data)
1794 + ae531x_WriteMiiReg(phyBase, MacMiiData, data );
1796 + addr = ((phyAddr << MiiDevShift) & MiiDevMask) |
1797 + ((reg << MiiRegShift) & MiiRegMask) | MiiWrite;
1798 + ae531x_WriteMiiReg(phyBase, MacMiiAddr, addr );
1802 + } while ((ae531x_ReadMiiReg(phyBase, MacMiiAddr ) & MiiBusy) == MiiBusy);
1806 +/*******************************************************************************
1807 +* ae531x_BeginResetMode - enter a special "reset mode" in which
1808 +* -no interrupts are expected from the device
1809 +* -the device will not transmit nor receive
1810 +* -attempts to send or receive will return with an error and
1811 +* -the device will be reset at the next convenient opportunity.
1814 +ae531x_BeginResetMode(ae531x_MAC_t *MACInfo)
1816 + /* Set the reset flag */
1817 + MACInfo->aeProcessRst = 1;
1821 +/*******************************************************************************
1822 +* ae531x_EndResetMode - exit the special "reset mode" entered
1823 +* earlier via a call to ae531x_BeginResetMode.
1826 +ae531x_EndResetMode(ae531x_MAC_t *MACInfo)
1828 + MACInfo->aeProcessRst = 0;
1832 +/*******************************************************************************
1833 +* ae531x_IsInResetMode - determine whether or not the device is
1834 +* currently in "reset mode" (i.e. that a device reset is pending)
1837 +ae531x_IsInResetMode(ae531x_MAC_t *MACInfo)
1839 + return MACInfo->aeProcessRst;
1843 +/******************************************************************************
1845 +* ae531x_DmaRxStart - Start Rx
1850 +ae531x_DmaRxStart(ae531x_MAC_t *MACInfo)
1852 + ae531x_SetDmaReg(MACInfo, DmaControl, DmaRxStart);
1857 +/******************************************************************************
1859 +* ae531x_DmaRxStop - Stop Rx
1864 +ae531x_DmaRxStop(ae531x_MAC_t *MACInfo)
1866 + ae531x_ClearDmaReg(MACInfo, DmaControl, DmaRxStart);
1871 +/******************************************************************************
1873 +* ae531x_DmaTxStart - Start Tx
1878 +ae531x_DmaTxStart(ae531x_MAC_t *MACInfo)
1880 + ae531x_SetDmaReg(MACInfo, DmaControl, DmaTxStart);
1885 +/******************************************************************************
1887 +* ae531x_DmaTxStop - Stop Tx
1892 +ae531x_DmaTxStop(ae531x_MAC_t *MACInfo)
1894 + ae531x_ClearDmaReg(MACInfo, DmaControl, DmaTxStart);
1899 +/******************************************************************************
1901 +* ae531x_DmaIntEnable - Enable DMA interrupts
1906 +ae531x_DmaIntEnable(ae531x_MAC_t *MACInfo)
1908 + ae531x_WriteDmaReg(MACInfo, DmaIntrEnb, DmaIntEnable);
1912 +/******************************************************************************
1914 +* ae531x_DmaIntDisable - Disable DMA interrupts
1919 +ae531x_DmaIntDisable(ae531x_MAC_t *MACInfo)
1921 + ae531x_WriteDmaReg(MACInfo, DmaIntrEnb, DmaIntDisable);
1925 +/******************************************************************************
1927 +* ae531x_DmaIntClear - Clear DMA interrupts
1932 +ae531x_DmaIntClear(ae531x_MAC_t *MACInfo)
1934 + /* clear all interrupt requests */
1935 + ae531x_WriteDmaReg(MACInfo, DmaStatus,
1936 + ae531x_ReadDmaReg(MACInfo, DmaStatus));
1940 +/******************************************************************************
1941 +* Initialize generic queue data
1944 +ae531x_QueueInit(AE531X_QUEUE *q, char *pMem, int count)
1947 + q->firstDescAddr = pMem;
1948 + q->lastDescAddr = (VIRT_ADDR)((UINT32)q->firstDescAddr +
1949 + (count - 1) * AE531X_QUEUE_ELE_SIZE);
1950 + q->curDescAddr = q->firstDescAddr;
1956 +/******************************************************************************
1957 +* ae531x_TxQueueCreate - create a circular queue of descriptors for Transmit
1960 +ae531x_TxQueueCreate(ae531x_MAC_t *MACInfo,
1966 + VIRT_ADDR descAddr;
1970 + ae531x_QueueInit(q, pMem, count);
1971 + q->reapDescAddr = q->lastDescAddr;
1973 + /* Initialize Tx buffer descriptors. */
1974 + for (i=0, descAddr=q->firstDescAddr;
1976 + i++, descAddr=(VIRT_ADDR)((UINT32)descAddr + AE531X_QUEUE_ELE_SIZE))
1978 + /* Update the size, BUFPTR, and SWPTR fields */
1980 + AE531X_DESC_STATUS_SET(descAddr, 0);
1981 + AE531X_DESC_CTRLEN_SET(descAddr, 0);
1983 + AE531X_DESC_BUFPTR_SET(descAddr, (UINT32)0);
1984 + AE531X_DESC_LNKBUF_SET(descAddr, (UINT32)0);
1985 + AE531X_DESC_SWPTR_SET(descAddr, (void *)0);
1986 + } /* for each desc */
1988 + /* Make the queue circular */
1989 + AE531X_DESC_CTRLEN_SET(q->lastDescAddr,
1990 + DescEndOfRing|AE531X_DESC_CTRLEN_GET(q->lastDescAddr));
1992 + AE531X_PRINT(AE531X_DEBUG_RESET,
1993 + ("ethmac%d Txbuf begin = %x, end = %x\n",
1995 + (UINT32)q->firstDescAddr,
1996 + (UINT32)q->lastDescAddr));
2003 +/******************************************************************************
2004 +* ae531x_RxQueueCreate - create a circular queue of Rx descriptors
2007 +ae531x_RxQueueCreate(ae531x_MAC_t *MACInfo,
2013 + VIRT_ADDR descAddr;
2017 + ae531x_QueueInit(q, pMem, count);
2018 + q->reapDescAddr = NULL;
2021 + /* Initialize Rx buffer descriptors */
2022 + for (i=0, descAddr=q->firstDescAddr;
2024 + i++, descAddr=(VIRT_ADDR)((UINT32)descAddr + AE531X_QUEUE_ELE_SIZE))
2030 + swptr = ae531x_rxbuf_alloc(MACInfo, &rxBuffer, &rxBufferSize);
2031 + if (swptr == NULL) {
2032 + AE531X_PRINT(AE531X_DEBUG_RESET,
2033 + ("ethmac%d RX queue: ae531x_rxbuf_alloc failed\n",
2035 + ae531x_QueueDestroy(q);
2038 + AE531X_DESC_SWPTR_SET(descAddr, swptr);
2040 + AE531X_DESC_STATUS_SET(descAddr, DescOwnByDma);
2041 + AE531X_DESC_CTRLEN_SET(descAddr, rxBufferSize);
2042 + AE531X_DESC_BUFPTR_SET(descAddr, virt_to_bus(rxBuffer));
2043 + AE531X_DESC_LNKBUF_SET(descAddr, (UINT32)0);
2044 + } /* for each desc */
2046 + /* Make the queue circular */
2047 + AE531X_DESC_CTRLEN_SET(q->lastDescAddr,
2048 + DescEndOfRing|AE531X_DESC_CTRLEN_GET(q->lastDescAddr));
2050 + AE531X_PRINT(AE531X_DEBUG_RESET,
2051 + ("ethmac%d Rxbuf begin = %x, end = %x\n",
2053 + (UINT32)q->firstDescAddr,
2054 + (UINT32)q->lastDescAddr));
2061 +/******************************************************************************
2062 +* ae531x_QueueDestroy -- Free all buffers and descriptors associated
2066 +ae531x_QueueDestroy(AE531X_QUEUE *q)
2070 + VIRT_ADDR descAddr;
2076 + for (i=0, descAddr=q->firstDescAddr;
2078 + i++, descAddr=(VIRT_ADDR)((UINT32)descAddr + AE531X_QUEUE_ELE_SIZE)) {
2080 + AE531X_DESC_STATUS_SET(descAddr, 0);
2081 + AE531X_DESC_CTRLEN_SET(descAddr, 0);
2082 + AE531X_DESC_BUFPTR_SET(descAddr, (UINT32)0);
2083 + AE531X_DESC_LNKBUF_SET(descAddr, (UINT32)0);
2085 + ae531x_swptr_free(descAddr); /* Free OS-specific software pointer */
2092 +ae531x_TxQueueDestroy(ae531x_MAC_t *MACInfo)
2094 + ae531x_QueueDestroy(&MACInfo->txQueue);
2098 +ae531x_RxQueueDestroy(ae531x_MAC_t *MACInfo)
2100 + ae531x_QueueDestroy(&MACInfo->rxQueue);
2104 +/******************************************************************************
2105 +* ae531x_AllocateQueues - Allocate receive and transmit queues
2108 +ae531x_AllocateQueues(ae531x_MAC_t *MACInfo)
2111 + char *pTxBuf = NULL;
2112 + char *pRxBuf = NULL;
2116 + MACInfo->txDescCount = AE531X_TX_DESC_COUNT_DEFAULT;
2117 + QMemSize = AE531X_QUEUE_ELE_SIZE * MACInfo->txDescCount;
2118 + pTxBuf = MALLOC(QMemSize);
2119 + if (pTxBuf == NULL) {
2120 + AE531X_PRINT(AE531X_DEBUG_RESET,
2121 + ("ethmac%d Failed to allocate TX queue\n", MACInfo->unit));
2125 + if (ae531x_TxQueueCreate(MACInfo, &MACInfo->txQueue, pTxBuf,
2126 + MACInfo->txDescCount) < 0)
2128 + AE531X_PRINT(AE531X_DEBUG_RESET,
2129 + ("ethmac%d Failed to create TX queue\n", MACInfo->unit));
2133 + MACInfo->rxDescCount = AE531X_RX_DESC_COUNT_DEFAULT;
2134 + QMemSize = AE531X_QUEUE_ELE_SIZE * MACInfo->rxDescCount;
2135 + pRxBuf = MALLOC(QMemSize);
2136 + if (pRxBuf == NULL) {
2137 + AE531X_PRINT(AE531X_DEBUG_RESET,
2138 + ("ethmac%d Failed to allocate RX queue\n", MACInfo->unit));
2142 + if (ae531x_RxQueueCreate(MACInfo, &MACInfo->rxQueue, pRxBuf,
2143 + MACInfo->rxDescCount) < 0)
2145 + AE531X_PRINT(AE531X_DEBUG_RESET,
2146 + ("ethmac%d Failed to create RX queue\n", MACInfo->unit));
2150 + AE531X_PRINT(AE531X_DEBUG_RESET,
2151 + ("ethmac%d Memory setup complete.\n", MACInfo->unit));
2157 + MACInfo->txDescCount = 0; /* sanity */
2158 + MACInfo->rxDescCount = 0; /* sanity */
2172 +/******************************************************************************
2174 +* ae531x_FreeQueues - Free Transmit & Receive queues
2177 +ae531x_FreeQueues(ae531x_MAC_t *MACInfo)
2179 + ae531x_TxQueueDestroy(MACInfo);
2180 + FREE(MACInfo->txQueue.firstDescAddr);
2182 + ae531x_RxQueueDestroy(MACInfo);
2183 + FREE(MACInfo->rxQueue.firstDescAddr);
2186 +/******************************************************************************
2188 +* ae531x_DmaReset - Reset DMA and TLI controllers
2193 +ae531x_DmaReset(ae531x_MAC_t *MACInfo)
2200 + /* Disable device interrupts prior to any errors during stop */
2201 + intDisable(MACInfo->ilevel);
2203 + /* Disable MAC rx and tx */
2204 + ae531x_ClearMacReg(MACInfo, MacControl, (MacRxEnable | MacTxEnable));
2206 + /* Reset dma controller */
2207 + ae531x_WriteDmaReg(MACInfo, DmaBusMode, DmaResetOn);
2209 + /* Delay 2 usec */
2212 + /* Flush the rx queue */
2213 + descAddr = (UINT32)MACInfo->rxQueue.firstDescAddr;
2214 + MACInfo->rxQueue.curDescAddr = MACInfo->rxQueue.firstDescAddr;
2216 + i<(MACInfo->rxDescCount);
2217 + i++, descAddr += AE531X_QUEUE_ELE_SIZE) {
2218 + AE531X_DESC_STATUS_SET(descAddr, DescOwnByDma);
2221 + /* Flush the tx queue */
2222 + descAddr = (UINT32)MACInfo->txQueue.firstDescAddr;
2223 + MACInfo->txQueue.curDescAddr = MACInfo->txQueue.firstDescAddr;
2224 + MACInfo->txQueue.reapDescAddr = MACInfo->txQueue.lastDescAddr;
2226 + i<(MACInfo->txDescCount);
2227 + i++, descAddr += AE531X_QUEUE_ELE_SIZE) {
2228 + AE531X_DESC_STATUS_SET (descAddr, 0);
2231 + /* Set init register values */
2232 + ae531x_WriteDmaReg(MACInfo, DmaBusMode, DmaBusModeInit);
2234 + /* Install the first Tx and Rx queues on the device */
2235 + ae531x_WriteDmaReg(MACInfo, DmaRxBaseAddr,
2236 + (UINT32)MACInfo->rxQueue.firstDescAddr);
2237 + ae531x_WriteDmaReg(MACInfo, DmaTxBaseAddr,
2238 + (UINT32)MACInfo->txQueue.firstDescAddr);
2240 + ae531x_WriteDmaReg(MACInfo, DmaControl, DmaStoreAndForward);
2242 + ae531x_WriteDmaReg(MACInfo, DmaIntrEnb, DmaIntDisable);
2244 + AE531X_PRINT(AE531X_DEBUG_RESET,
2245 + ("ethmac%d: DMA RESET!\n", MACInfo->unit));
2247 + /* Turn on device interrupts -- enable most errors */
2248 + ae531x_DmaIntClear(MACInfo); /* clear interrupt requests */
2249 + ae531x_DmaIntEnable(MACInfo); /* enable interrupts */
2250 + /* Enable receive interrupts separately (they are not part
2251 + * of the main group since they are enabled & disabled by
2252 + * the polling routine.
2254 + ae531x_SetDmaReg(MACInfo, DmaIntrEnb,
2255 + (DmaIntRxNoBuffer | DmaIntRxCompleted));
2257 + ae531x_EndResetMode(MACInfo);
2259 + intEnable(MACInfo->ilevel);
2265 +/******************************************************************************
2267 +* ae531x_MACAddressSet - Set the ethernet address
2269 +* Sets the ethernet address according to settings in flash.
2274 +ae531x_MACAddressSet(ae531x_MAC_t *MACInfo)
2276 + unsigned int data;
2281 + macAddr = macAddrGet(MACInfo);
2283 + /* set our MAC address */
2284 + data = (macAddr[5]<<8) | macAddr[4];
2285 + ae531x_WriteMacReg(MACInfo, MacAddrHigh, data );
2287 + data = (macAddr[3]<<24) | (macAddr[2]<<16) | (macAddr[1]<<8) | macAddr[0];
2288 + ae531x_WriteMacReg(MACInfo, MacAddrLow, data );
2290 + AE531X_PRINT(AE531X_DEBUG_RESET,
2291 + ("ethmac%d Verify MAC address %8.8X %8.8X \n",
2293 + ae531x_ReadMacReg(MACInfo, MacAddrLow),
2294 + ae531x_ReadMacReg(MACInfo, MacAddrHigh)));
2296 + AE531X_PRINT(AE531X_DEBUG_RESET,
2297 + (" sb = %2.2X %2.2X %2.2X %2.2X %2.2X %2.2X\n",
2303 + 0xff&macAddr[5]));
2308 +/******************************************************************************
2310 +* ae_SetMACFromPhy - read Phy settings and update Mac
2311 +* with current duplex and speed.
2316 +ae531x_SetMACFromPhy(ae531x_MAC_t *MACInfo)
2323 + /* Get duplex mode from Phy */
2324 + fullDuplex = phyIsFullDuplex(MACInfo->unit);
2326 + /* Flag is set for full duplex mode, else cleared */
2327 + macCtl = ae531x_ReadMacReg(MACInfo, MacControl);
2330 + /* set values of control registers */
2331 + macCtl &= ~MacDisableRxOwn;
2332 + macCtl |= MacFullDuplex;
2333 + ae531x_WriteMacReg(MACInfo, MacControl, macCtl);
2334 + ae531x_WriteMacReg(MACInfo, MacFlowControl, MacFlowControlInitFdx);
2336 + printk ("[Full Duplex] CTRL=%#x FLOW=%#x\n", macCtl,
2337 + MacFlowControlInitFdx);
2340 + /* set values of control registers */
2341 + ae531x_WriteMacReg(MACInfo, MacFlowControl, MacFlowControlInitHdx);
2342 + macCtl |= MacDisableRxOwn;
2343 + macCtl &= ~MacFullDuplex;
2344 + ae531x_WriteMacReg(MACInfo, MacControl, macCtl);
2346 + printk ("[Half Duplex] CTRL=%#x FLOW=%#x\n", macCtl,
2347 + MacFlowControlInitHdx);
2355 +/******************************************************************************
2356 +* ae531x_MACReset -- sets MAC address and duplex.
2359 +ae531x_MACReset(ae531x_MAC_t *MACInfo)
2361 + ae531x_MACAddressSet(MACInfo);
2363 + ae531x_SetMACFromPhy(MACInfo);
2367 +/******************************************************************************
2368 +* ae531x_EnableComm -- enable Transmit and Receive
2371 +ae531x_EnableComm(ae531x_MAC_t *MACInfo)
2373 + ae531x_SetMacReg(MACInfo, MacControl, (MacRxEnable | MacTxEnable));
2374 + ae531x_DmaRxStart(MACInfo); /* start receiver */
2375 + ae531x_DmaTxStart(MACInfo); /* start transmitter */
2379 +/******************************************************************************
2380 +* ae531x_DisableComm -- disable Transmit and Receive
2383 +ae531x_DisableComm(ae531x_MAC_t *MACInfo)
2385 + ae531x_ClearMacReg(MACInfo, MacControl, (MacRxEnable | MacTxEnable));
2389 +/******************************************************************************
2390 +* ae531x_reset -- Cold reset ethernet interface
2393 +ae531x_reset(ae531x_MAC_t *MACInfo)
2398 + if (ar531x_num_enet_macs == 2) {
2399 + if (MACInfo->unit == 0) {
2400 + mask = AR531X_RESET_ENET0 | AR531X_RESET_EPHY0;
2402 + mask = AR531X_RESET_ENET1 | AR531X_RESET_EPHY1;
2405 + mask = AR531X_RESET_ENET0 | AR531X_RESET_EPHY0 |
2406 + AR531X_RESET_ENET1 | AR531X_RESET_EPHY1;
2409 + /* Put into reset */
2410 + regtmp = sysRegRead(AR531X_RESET);
2411 + sysRegWrite(AR531X_RESET, regtmp | mask);
2414 + /* Pull out of reset */
2415 + regtmp = sysRegRead(AR531X_RESET);
2416 + sysRegWrite(AR531X_RESET, regtmp & ~mask);
2420 + if (ar531x_num_enet_macs == 2) {
2421 + if (MACInfo->unit == 0) {
2422 + mask = AR531X_ENABLE_ENET0;
2424 + mask = AR531X_ENABLE_ENET1;
2427 + mask = AR531X_ENABLE_ENET0 | AR531X_ENABLE_ENET1;
2429 + regtmp = sysRegRead(AR531X_ENABLE);
2430 + sysRegWrite(AR531X_ENABLE, regtmp | mask);
2434 +/******************************************************************************
2435 +* ae531x_unitLinkLost -- Called from PHY layer to notify the MAC layer
2436 +* that there are no longer any live links associated with a MAC.
2439 +ae531x_unitLinkLost(int ethUnit)
2441 + AE531X_PRINT(AE531X_DEBUG_LINK_CHANGE,
2442 + ("enetmac%d link down\n", ethUnit));
2446 +/******************************************************************************
2447 +* ae531x_unitLinkGained -- Called from PHY layer to notify the MAC layer
2448 +* that there are 1 or more live links associated with a MAC.
2451 +ae531x_unitLinkGained(int ethUnit)
2453 + AE531X_PRINT(AE531X_DEBUG_LINK_CHANGE,
2454 + ("enet%d link up\n", ethUnit));
2457 +/******************************************************************************
2458 +* ae531x_ethMacDefault -- Called from PHY layer to determine the default
2459 +* ethernet MAC. On some "twisted" platforms, the only usable MAC is 1,
2460 +* while on others the usable MAC is 0. Future boards may allow both MACs
2461 +* to be used; in this case, return -1 to indicate that there IS NO default
2464 +* Note: one some AR2312 platforms the PHY needs to be accessed through
2465 +* MAC 0, even though the MAC itself is addressed through MAC 1. Since this
2466 +* function is used by the PHY layer to determine which MAC it should use,
2467 +* the twisted case is limited to the one where the PHY is actually addressed
2468 +* through MAC 1 rather than MAC 0.
2471 +ae531x_ethMacDefault(void)
2474 + * Where there are two MACs, there is no real default
2476 + if (ar531x_num_enet_macs == 2)
2480 + * All single MAC platforms seem to address the PHY through MAC 0,
2481 + * even when they use MAC 1 for the actual MAC functions.
2485 diff -urN linux-2.4.32.new/arch/mips/ar531x/ae531xmac.h linux-2.4.32.new-eth/arch/mips/ar531x/ae531xmac.h
2486 --- linux-2.4.32.new/arch/mips/ar531x/ae531xmac.h 1970-01-01 01:00:00.000000000 +0100
2487 +++ linux-2.4.32.new-eth/arch/mips/ar531x/ae531xmac.h 2005-12-25 11:54:20.819264376 +0000
2490 + * This file is subject to the terms and conditions of the GNU General Public
2491 + * License. See the file "COPYING" in the main directory of this archive
2492 + * for more details.
2494 + * Copyright © 2003 Atheros Communications, Inc., All Rights Reserved.
2498 + * See README to understand the decomposition of the ethernet driver.
2500 + * This file contains OS-independent pure software definitions for
2501 + * ethernet support on the AR531X platform.
2504 +#ifndef _AE531XMAC_H_
2505 +#define _AE531XMAC_H_
2508 + * DEBUG switches to control verbosity.
2509 + * Just modify the value of ae531x_MAC_debug.
2511 +#define AE531X_DEBUG_ALL 0xffffffff
2512 +#define AE531X_DEBUG_ERROR 0x00000001 /* Unusual conditions and Errors */
2513 +#define AE531X_DEBUG_ARRIVE 0x00000002 /* Arrive into a function */
2514 +#define AE531X_DEBUG_LEAVE 0x00000004 /* Leave a function */
2515 +#define AE531X_DEBUG_RESET 0x00000008 /* Reset */
2516 +#define AE531X_DEBUG_TX 0x00000010 /* Transmit */
2517 +#define AE531X_DEBUG_TX_REAP 0x00000020 /* Transmit Descriptor Reaping */
2518 +#define AE531X_DEBUG_RX 0x00000040 /* Receive */
2519 +#define AE531X_DEBUG_RX_STOP 0x00000080 /* Receive Early Stop */
2520 +#define AE531X_DEBUG_INT 0x00000100 /* Interrupts */
2521 +#define AE531X_DEBUG_LINK_CHANGE 0x00000200 /* PHY Link status changed */
2523 +extern int ae531x_MAC_debug;
2525 +extern int ar531x_num_enet_macs;
2527 +#define AE531X_PRINT(FLG, X) \
2529 + if (ae531x_MAC_debug & (FLG)) { \
2530 + DEBUG_PRINTF("%s#%d:%s ", \
2538 +#define ARRIVE() AE531X_PRINT(AE531X_DEBUG_ARRIVE, ("Arrive{\n"))
2539 +#define LEAVE() AE531X_PRINT(AE531X_DEBUG_LEAVE, ("}Leave\n"))
2541 +#define RegRead(addr) \
2542 + (*(volatile unsigned int *)(addr))
2544 +#define RegWrite(val,addr) \
2545 + ((*(volatile unsigned int *)(addr)) = (val))
2547 +/*****************************************************************
2548 + * Phy code is broken out into a separate layer, so that different
2549 + * PHY hardware can easily be supported.
2551 + * These functions are provided by the PHY layer for use by the MAC layer.
2552 + * phySetup -- Set phy hardware appropriately for a MAC unit
2554 + * phyCheckStatusChange -- Look for dropped/initiated links on any
2555 + * phy port associated with a MAC unit
2557 + * phyIsSpeed100 -- Determines whether or not a PHY is up and
2558 + * running at 100Mbit
2560 + * phyIsFullDuplex -- Determines whether or not a PHY is up and
2561 + * running in Full Duplex mode
2564 +#ifdef CONFIG_MARVELL_ENET_PHY
2566 + * Mapping of generic phy APIs to Marvell Ethernet Switch phy functions.
2569 +#define phySetup(ethUnit, phyBase) mv_phySetup((ethUnit), (phyBase))
2570 +#define phyCheckStatusChange(ethUnit) mv_phyCheckStatusChange(ethUnit)
2571 +#define phyIsSpeed100(ethUnit) mv_phyIsSpeed100(ethUnit)
2572 +#define phyIsFullDuplex(ethUnit) mv_phyIsFullDuplex(ethUnit)
2574 +#ifdef CONFIG_VENETDEV
2575 +#define PHY_TRAILER_SIZE MV_PHY_TRAILER_SIZE
2576 +extern int mv_phyDetermineSource(char *data, int len);
2577 +extern void mv_phySetDestinationPort(char *data, int len, int fromLAN);
2578 +#define phyDetermineSource(data, len) mv_phyDetermineSource((data), (len))
2579 +#define phySetDestinationPort(data, len, fromLAN) mv_phySetDestinationPort((data), (len), (fromLAN))
2581 +#define PHY_TRAILER_SIZE 0
2583 +#endif /* CONFIG_MARVELL_ENET_PHY */
2585 +#if defined(CONFIG_KENDIN_ENET_PHY) || defined(CONFIG_REALTEK_ENET_PHY)
2587 + * Mapping of generic phy APIs to Kendin KS8721B and RealTek RTL8201BL phys.
2590 +#define phySetup(ethUnit, phyBase) rt_phySetup((ethUnit), (phyBase))
2591 +#define phyCheckStatusChange(ethUnit) rt_phyCheckStatusChange(ethUnit)
2592 +#define phyIsSpeed100(ethUnit) rt_phyIsSpeed100(ethUnit)
2593 +#define phyIsFullDuplex(ethUnit) rt_phyIsFullDuplex(ethUnit)
2596 +#if !defined(PHY_TRAILER_SIZE)
2597 +#define PHY_TRAILER_SIZE 0
2600 +/*****************************************************************
2601 + * MAC-independent interface to be used by PHY code
2603 + * These functions are provided by the MAC layer for use by the PHY layer.
2605 +#define phyRegRead ae531x_MiiRead
2606 +#define phyRegWrite ae531x_MiiWrite
2607 +#define phyLinkLost(ethUnit) ae531x_unitLinkLost(ethUnit)
2608 +#define phyLinkGained(ethUnit) ae531x_unitLinkGained(ethUnit)
2609 +#define phyEthMacDefault() ae531x_ethMacDefault()
2611 +void ae531x_unitLinkLost(int unit);
2612 +void ae531x_unitLinkGained(int unit);
2613 +int ae531x_ethMacDefault(void);
2616 +/* RXBUFF_RESERVE enables building header on WLAN-side in place */
2617 +#define RXBUFF_RESERVE 96
2618 +#define ETH_CRC_LEN 4
2620 +/*****************************************************************
2621 + * Descriptor queue
2623 +typedef struct ae531x_queue {
2624 + VIRT_ADDR firstDescAddr; /* descriptor array address */
2625 + VIRT_ADDR lastDescAddr; /* last descriptor address */
2626 + VIRT_ADDR curDescAddr; /* current descriptor address */
2627 + VIRT_ADDR reapDescAddr; /* current tail of tx descriptors reaped */
2628 + UINT16 count; /* number of elements */
2631 +/* Given a descriptor, return the next one in a circular list */
2632 +#define AE531X_QUEUE_ELE_NEXT_GET(q, descAddr) \
2633 + ((descAddr) == (q)->lastDescAddr) ? (q)->firstDescAddr : \
2634 + (VIRT_ADDR)((UINT32)(descAddr) + AE531X_QUEUE_ELE_SIZE)
2636 +/* Move the "current descriptor" forward to the next one */
2637 +#define AE531X_CONSUME_DESC(q) \
2638 + q->curDescAddr = AE531X_QUEUE_ELE_NEXT_GET(q, q->curDescAddr)
2640 +/*****************************************************************
2641 + * Per-ethernet-MAC OS-independent information
2643 +typedef struct ae531x_MAC_s {
2644 + u32 unit; /* MAC unit ID */
2645 + u32 macBase; /* MAC base address */
2646 + u32 dmaBase; /* DMA base address */
2647 + u32 phyBase; /* PHY base address */
2648 + AE531X_QUEUE txQueue; /* Transmit descriptor queue */
2649 + AE531X_QUEUE rxQueue; /* Receive descriptor queue */
2650 + UINT16 txDescCount; /* Transmit descriptor count */
2651 + UINT16 rxDescCount; /* Receive descriptor count */
2652 + BOOL aeProcessRst; /* flag to indicate reset in progress */
2653 + BOOL port_is_up; /* flag to indicate port is up */
2654 + void *OSinfo; /* OS-dependent data */
2657 +#define AE531X_TX_DESC_COUNT_DEFAULT 64 /* Transmit descriptors */
2658 +#define AE531X_RX_DESC_COUNT_DEFAULT 64 /* Receive descriptors */
2661 +/*****************************************************************
2662 + * Interfaces exported by the OS-independent MAC layer
2664 +void ae531x_BeginResetMode(ae531x_MAC_t *MACInfo);
2665 +void ae531x_EndResetMode(ae531x_MAC_t *MACInfo);
2666 +BOOL ae531x_IsInResetMode(ae531x_MAC_t *MACInfo);
2667 +int ae531x_RxQueueCreate(ae531x_MAC_t *MACInfo, AE531X_QUEUE *q,
2668 + char *pMem, int count);
2669 +int ae531x_QueueDelete(struct ae531x_queue *q);
2670 +void ae531x_DmaReset(ae531x_MAC_t *MACInfo);
2671 +void ae531x_MACReset(ae531x_MAC_t *MACInfo);
2672 +void ae531x_EnableComm(ae531x_MAC_t *MACInfo);
2673 +void ae531x_DisableComm(ae531x_MAC_t *MACInfo);
2674 +void ae531x_reset(ae531x_MAC_t *MACInfo);
2675 +int ae531x_AllocateQueues(ae531x_MAC_t *MACInfo);
2676 +void ae531x_FreeQueues(ae531x_MAC_t *MACInfo);
2677 +void ae531x_QueueInit(AE531X_QUEUE *q, char *pMem, int count);
2678 +UINT32 ae531x_ReadMacReg(ae531x_MAC_t *MACInfo, UINT32 reg);
2679 +void ae531x_WriteMacReg(ae531x_MAC_t *MACInfo, UINT32 reg, UINT32 data);
2680 +void ae531x_SetMacReg(ae531x_MAC_t *MACInfo, UINT32 reg, UINT32 val);
2681 +void ae531x_ClearMacReg(ae531x_MAC_t *MACInfo, UINT32 reg, UINT32 val);
2682 +void ae531x_SetDmaReg(ae531x_MAC_t *MACInfo, UINT32 reg, UINT32 val);
2683 +void ae531x_ClearDmaReg(ae531x_MAC_t *MACInfo, UINT32 reg, UINT32 val);
2684 +UINT32 ae531x_ReadDmaReg(ae531x_MAC_t *MACInfo, UINT32 reg);
2685 +void ae531x_WriteDmaReg(ae531x_MAC_t *MACInfo, UINT32 reg, UINT32 data);
2686 +UINT32 ae531x_ReadMiiReg(UINT32 phyBase, UINT32 reg);
2687 +void ae531x_WriteMiiReg(UINT32 phyBase, UINT32 reg, UINT32 data);
2688 +UINT16 ae531x_MiiRead(UINT32 phyBase, UINT32 phyAddr, UINT8 reg);
2689 +void ae531x_MiiWrite(UINT32 phyBase, UINT32 phyAddr, UINT8 reg, UINT16 data);
2690 +void ae531x_DmaIntEnable(ae531x_MAC_t *MACInfo);
2691 +void ae531x_DmaIntDisable(ae531x_MAC_t *MACInfo);
2692 +void ae531x_AckIntr(ae531x_MAC_t *MACInfo, UINT32 val);
2693 +void *ae531x_rxbuf_alloc(ae531x_MAC_t *MACInfo, char **rxBptr, int *rxBSize);
2694 +void ae531x_swptr_free(VIRT_ADDR txDesc);
2696 +#endif /* _AE531XMAC_H_ */
2697 diff -urN linux-2.4.32.new/arch/mips/ar531x/ae531xreg.h linux-2.4.32.new-eth/arch/mips/ar531x/ae531xreg.h
2698 --- linux-2.4.32.new/arch/mips/ar531x/ae531xreg.h 1970-01-01 01:00:00.000000000 +0100
2699 +++ linux-2.4.32.new-eth/arch/mips/ar531x/ae531xreg.h 2005-12-25 11:54:20.834262096 +0000
2702 + * This file is subject to the terms and conditions of the GNU General Public
2703 + * License. See the file "COPYING" in the main directory of this archive
2704 + * for more details.
2706 + * Copyright © 2003 Atheros Communications, Inc., All Rights Reserved.
2710 + * See README to understand the decomposition of the ethernet driver.
2712 + * Register definitions for Atheros AR531X Ethernet MAC.
2715 +#ifndef _AE531XREG_H_
2716 +#define _AE531XREG_H_
2718 +#define AE531X_MAC_OFFSET 0x0000
2719 +#define AE531X_PHY_OFFSET 0x0000 /* Same as MAC offset */
2720 +#define AE531X_DMA_OFFSET 0x1000
2722 +/***********************************************************/
2723 +/* MAC110 registers, base address is BAR+AE531X_MAC_OFFSET */
2724 +/***********************************************************/
2725 +#define MacControl 0x00 /* control */
2726 +#define MacAddrHigh 0x04 /* address high */
2727 +#define MacAddrLow 0x08 /* address low */
2728 +#define MacMultiHashHigh 0x0C /* multicast hash table high */
2729 +#define MacMultiHashLow 0x10 /* multicast hash table low */
2730 +#define MacMiiAddr 0x14 /* MII address */
2731 +#define MacMiiData 0x18 /* MII data */
2732 +#define MacFlowControl 0x1C /* Flow control */
2733 +#define MacVlan1Tag 0x4C /* VLAN1 tag */
2734 +#define MacVlan2Tag 0x50 /* VLAN2 tag */
2737 +/***************************************************************/
2738 +/* DMA engine registers, base address is BAR+AE531X_DMA_OFFSET */
2739 +/***************************************************************/
2740 +#define DmaBusMode 0x00 /* CSR0 - Bus Mode */
2741 +#define DmaTxPollDemand 0x04 /* CSR1 - Transmit Poll Demand */
2742 +#define DmaRxPollDemand 0x08 /* CSR2 - Receive Poll Demand */
2743 +#define DmaRxBaseAddr 0x0C /* CSR3 - Receive list base address */
2744 +#define DmaTxBaseAddr 0x10 /* CSR4 - Transmit list base address */
2745 +#define DmaStatus 0x14 /* CSR5 - Dma status */
2746 +#define DmaControl 0x18 /* CSR6 - Dma control */
2747 +#define DmaIntrEnb 0x1C /* CSR7 - Interrupt enable */
2748 +#define DmaOverflowCnt 0x20 /* CSR8 - Missed Frame and Buff Overflow counter */
2749 +#define DmaTxCurrAddr 0x50 /* CSR20 - Current host transmit buffer address */
2750 +#define DmaRxCurrAddr 0x54 /* CSR21 - Current host receive buffer address */
2752 +/**********************************************************/
2753 +/* MAC Control register layout */
2754 +/**********************************************************/
2755 +#define MacFilterOff 0x80000000 /* Receive all incoming packets RW */
2756 +#define MacFilterOn 0 /* Receive filtered packets only 0 */
2757 +#define MacBigEndian 0x40000000 /* Big endian mode RW */
2758 +#define MacLittleEndian 0 /* Little endian 0 */
2759 +#define MacHeartBeatOff 0x10000000 /* Heartbeat signal qual disable RW*/
2760 +#define MacHeartBeatOn 0 /* Heartbeat signal qual enable 0 */
2761 +#define MacSelectSrl 0x08000000 /* Select SRL port RW */
2762 +#define MacSelectMii 0 /* Select MII port 0 */
2763 +#define MacDisableRxOwn 0x00800000 /* Disable receive own packets RW */
2764 +#define MacEnableRxOwn 0 /* Enable receive own packets 0 */
2765 +#define MacLoopbackExt 0x00400000 /* External loopback RW */
2766 +#define MacLoopbackInt 0x00200000 /* Internal loopback */
2767 +#define MacLoopbackOff 0 /* Normal mode 00 */
2768 +#define MacFullDuplex 0x00100000 /* Full duplex mode RW */
2769 +#define MacHalfDuplex 0 /* Half duplex mode 0 */
2770 +#define MacMulticastFilterOff 0x00080000 /* Pass all multicast packets RW */
2771 +#define MacMulticastFilterOn 0 /* Pass filtered mcast packets 0 */
2772 +#define MacPromiscuousModeOn 0x00040000 /* Receive all valid packets RW 1 */
2773 +#define MacPromiscuousModeOff 0 /* Receive filtered packets only */
2774 +#define MacFilterInverse 0x00020000 /* Inverse filtering RW */
2775 +#define MacFilterNormal 0 /* Normal filtering 0 */
2776 +#define MacBadFramesEnable 0x00010000 /* Pass bad frames RW */
2777 +#define MacBadFramesDisable 0 /* Do not pass bad frames 0 */
2778 +#define MacPerfectFilterOff 0x00008000 /* Hash filtering only RW */
2779 +#define MacPerfectFilterOn 0 /* Both perfect and hash filtering 0 */
2780 +#define MacHashFilterOn 0x00002000 /* perform hash filtering RW */
2781 +#define MacHashFilterOff 0 /* perfect filtering only 0 */
2782 +#define MacLateCollisionOn 0x00001000 /* Enable late collision control RW */
2783 +#define MacLateCollisionOff 0 /* Disable late collision control 0 */
2784 +#define MacBroadcastDisable 0x00000800 /* Disable reception of bcast frames RW */
2785 +#define MacBroadcastEnable 0 /* Enable broadcast frames 0 */
2786 +#define MacRetryDisable 0x00000400 /* Disable retransmission RW */
2787 +#define MacRetryEnable 0 /* Enable retransmission 0 */
2788 +#define MacPadStripEnable 0x00000100 /* Pad stripping enable RW */
2789 +#define MacPadStripDisable 0 /* Pad stripping disable 0 */
2790 +#define MacBackoff 0 /* Backoff Limit RW 00 */
2791 +#define MacDeferralCheckEnable 0x00000020 /* Deferral check enable RW */
2792 +#define MacDeferralCheckDisable 0 /* Deferral check disable 0 */
2793 +#define MacTxEnable 0x00000008 /* Transmitter enable RW */
2794 +#define MacTxDisable 0 /* Transmitter disable 0 */
2795 +#define MacRxEnable 0x00000004 /* Receiver enable RW */
2796 +#define MacRxDisable 0 /* Receiver disable 0 */
2799 +/**********************************************************/
2800 +/* MII address register layout */
2801 +/**********************************************************/
2802 +#define MiiDevMask 0x0000F800 /* MII device address */
2803 +#define MiiDevShift 11
2804 +#define MiiRegMask 0x000007C0 /* MII register */
2805 +#define MiiRegShift 6
2806 +#define MiiWrite 0x00000002 /* Write to register */
2807 +#define MiiRead 0 /* Read from register */
2808 +#define MiiBusy 0x00000001 /* MII interface is busy */
2810 +/**********************************************************/
2811 +/* MII Data register layout */
2812 +/**********************************************************/
2813 +#define MiiDataMask 0x0000FFFF /* MII Data */
2815 +/**********************************************************/
2816 +/* MAC flow control register layout */
2817 +/**********************************************************/
2818 +#define MacPauseTimeMask 0xFFFF0000 /* PAUSE TIME field in ctrl frame */
2819 +#define MacPauseTimeShift 15
2820 +#define MacControlFrameEnable 0x00000004 /* Enable pass ctrl frames to host */
2821 +#define MacControlFrameDisable 0 /* Do not pass ctrl frames to host */
2822 +#define MacFlowControlEnable 0x00000002 /* Enable flow control */
2823 +#define MacFlowControlDisable 0 /* Disable flow control */
2824 +#define MacSendPauseFrame 0x00000001 /* send pause frame */
2826 +/**********************************************************/
2827 +/* DMA bus mode register layout */
2828 +/**********************************************************/
2829 +#define DmaRxAlign16 0x01000000 /* Force all rx buffers to align on odd hw bndry */
2830 +#define DmaBigEndianDes 0x00100000 /* Big endian data buffer descriptors RW */
2831 +#define DmaLittleEndianDesc 0 /* Little endian data descriptors */
2832 +#define DmaBurstLength32 0x00002000 /* Dma burst length 32 RW */
2833 +#define DmaBurstLength16 0x00001000 /* Dma burst length 16 */
2834 +#define DmaBurstLength8 0x00000800 /* Dma burst length 8 */
2835 +#define DmaBurstLength4 0x00000400 /* Dma burst length 4 */
2836 +#define DmaBurstLength2 0x00000200 /* Dma burst length 2 */
2837 +#define DmaBurstLength1 0x00000100 /* Dma burst length 1 */
2838 +#define DmaBurstLength0 0x00000000 /* Dma burst length 0 */
2839 +#define DmaBigEndianData 0x00000080 /* Big endian data buffers RW */
2840 +#define DmaLittleEndianData 0 /* Little endian data buffers 0 */
2841 +#define DmaDescriptorSkip16 0x00000040 /* number of dwords to skip RW */
2842 +#define DmaDescriptorSkip8 0x00000020 /* between two unchained descriptors */
2843 +#define DmaDescriptorSkip4 0x00000010
2844 +#define DmaDescriptorSkip2 0x00000008
2845 +#define DmaDescriptorSkip1 0x00000004
2846 +#define DmaDescriptorSkip0 0
2847 +#define DmaReceivePriorityOff 0x00000002 /* equal rx and tx priorities RW */
2848 +#define DmaReceivePriorityOn 0 /* Rx has prioryty over Tx 0 */
2849 +#define DmaResetOn 0x00000001 /* Reset DMA engine RW */
2850 +#define DmaResetOff 0
2852 +/**********************************************************/
2853 +/* DMA Status register layout */
2854 +/**********************************************************/
2855 +#define DmaRxAbort 0x01000000 /* receiver bus abort R 0 */
2856 +#define DmaTxAbort 0x00800000 /* transmitter bus abort R 0 */
2857 +#define DmaTxState 0x00700000 /* Transmit process state R 000 */
2858 +#define DmaTxStopped 0x00000000 /* Stopped */
2859 +#define DmaTxFetching 0x00100000 /* Running - fetching the descriptor */
2860 +#define DmaTxWaiting 0x00200000 /* Running - waiting for end of transmission */
2861 +#define DmaTxReading 0x00300000 /* Running - reading the data from memory */
2862 +#define DmaTxSuspended 0x00600000 /* Suspended */
2863 +#define DmaTxClosing 0x00700000 /* Running - closing descriptor */
2864 +#define DmaRxState 0x000E0000 /* Receive process state 000 */
2865 +#define DmaRxStopped 0x00000000 /* Stopped */
2866 +#define DmaRxFetching 0x00020000 /* Running - fetching the descriptor */
2867 +#define DmaRxChecking 0x00040000 /* Running - checking for end of packet */
2868 +#define DmaRxWaiting 0x00060000 /* Running - waiting for packet */
2869 +#define DmaRxSuspended 0x00080000 /* Suspended */
2870 +#define DmaRxClosing 0x000A0000 /* Running - closing descriptor */
2871 +#define DmaRxFlushing 0x000C0000 /* Running - flushing the current frame */
2872 +#define DmaRxQueuing 0x000E0000 /* Running - queuing the recieve frame into host memory */
2873 +#define DmaIntNormal 0x00010000 /* Normal interrupt summary RW 0 */
2874 +#define DmaIntAbnormal 0x00008000 /* Abnormal interrupt summary RW 0 */
2875 +#define DmaIntEarlyRx 0x00004000 /* Early receive interrupt (Normal) RW 0 */
2876 +#define DmaIntBusError 0x00002000 /* Fatal bus error (Abnormal) RW 0 */
2877 +#define DmaIntEarlyTx 0x00000400 /* Early transmit interrupt RW 0 */
2878 +#define DmaIntRxStopped 0x00000100 /* Receive process stopped (Abnormal) RW 0 */
2879 +#define DmaIntRxNoBuffer 0x00000080 /* Receive buffer unavailable (Abnormal) RW 0*/
2880 +#define DmaIntRxCompleted 0x00000040 /* Completion of frame reception(Normal) RW 0*/
2881 +#define DmaIntTxUnderflow 0x00000020 /* Transmit underflow (Abnormal) RW 0 */
2882 +#define DmaIntTxJabber 0x00000008 /* Transmit Jabber Timeout (Abnormal) RW 0 */
2883 +#define DmaIntTxNoBuffer 0x00000004 /* Transmit buffer unavailable (Normal) RW 0*/
2884 +#define DmaIntTxStopped 0x00000002 /* Transmit process stopped (Abnormal) RW 0 */
2885 +#define DmaIntTxCompleted 0x00000001 /* Transmit completed (Normal) RW 0 */
2887 +/**********************************************************/
2888 +/* DMA control register layout */
2889 +/**********************************************************/
2890 +#define DmaStoreAndForward 0x00200000 /* Store and forward RW 0 */
2891 +#define DmaTxThreshCtl256 0x0000c000 /* Non-SF threshold is 256 words */
2892 +#define DmaTxThreshCtl128 0x00008000 /* Non-SF threshold is 128 words */
2893 +#define DmaTxThreshCtl064 0x00004000 /* Non-SF threshold is 64 words */
2894 +#define DmaTxThreshCtl032 0x00000000 /* Non-SF threshold is 32 words */
2895 +#define DmaTxStart 0x00002000 /* Start/Stop transmission RW 0 */
2896 +#define DmaTxSecondFrame 0x00000004 /* Operate on second frame RW 0 */
2897 +#define DmaRxStart 0x00000002 /* Start/Stop reception RW 0 */
2899 +/**********************************************************/
2900 +/* DMA interrupt enable register layout */
2901 +/**********************************************************/
2902 +#define DmaIeNormal DmaIntNormal /* Normal interrupt enable RW 0 */
2903 +#define DmaIeAbnormal DmaIntAbnormal /* Abnormal interrupt enable RW 0 */
2904 +#define DmaIeEarlyRx DmaIntEarlyRx /* Early receive interrupt enable RW 0 */
2905 +#define DmaIeBusError DmaIntBusError /* Fatal bus error enable RW 0 */
2906 +#define DmaIeEarlyTx DmaIntEarlyTx /* Early transmit interrupt enable RW 0 */
2907 +#define DmaIeRxStopped DmaIntRxStopped /* Receive process stopped enable RW 0 */
2908 +#define DmaIeRxNoBuffer DmaIntRxNoBuffer /* Receive buffer unavailable enable RW 0 */
2909 +#define DmaIeRxCompleted DmaIntRxCompleted /* Completion of frame reception enable RW 0 */
2910 +#define DmaIeTxUnderflow DmaIntTxUnderflow /* Transmit underflow enable RW 0 */
2911 +#define DmaIeTxJabber DmaIntTxJabber /* Transmit jabber timeout RW 0 */
2912 +#define DmaIeTxNoBuffer DmaIntTxNoBuffer /* Transmit buffer unavailable enable RW 0 */
2913 +#define DmaIeTxStopped DmaIntTxStopped /* Transmit process stopped enable RW 0 */
2914 +#define DmaIeTxCompleted DmaIntTxCompleted /* Transmit completed enable RW 0 */
2916 +/****************************************************************/
2917 +/* DMA Missed Frame and Buffer Overflow Counter register layout */
2918 +/****************************************************************/
2919 +#define DmaRxBufferMissedFrame 0xffff0000 /* cleared on read */
2920 +#define DmaMissedFrameShift 16
2921 +#define DmaRxBufferOverflowCnt 0x0000ffff /* cleared on read */
2922 +#define DmaMissedFrameCountMask 0x0000ffff
2924 +/**********************************************************/
2925 +/* DMA Engine descriptor layout */
2926 +/**********************************************************/
2927 +/* status word of DMA descriptor */
2928 +#define DescOwnByDma 0x80000000 /* Descriptor is owned by DMA engine */
2929 +#define DescFrameLengthMask 0x3FFF0000 /* Receive descriptor frame length */
2930 +#define DescFrameLengthShift 16
2931 +#define DescError 0x00008000 /* Error summary bit OR of following bits */
2932 +#define DescRxTruncated 0x00004000 /* Rx - no more descs for receive frame */
2933 +#define DescRxLengthError 0x00001000 /* Rx - frame size not matching with length field */
2934 +#define DescRxRunt 0x00000800 /* Rx - runt frame, damaged by a
2935 + collision or term before 64 bytes */
2936 +#define DescRxMulticast 0x00000400 /* Rx - received frame is multicast */
2937 +#define DescRxFirst 0x00000200 /* Rx - first descriptor of the frame */
2938 +#define DescRxLast 0x00000100 /* Rx - last descriptor of the frame */
2939 +#define DescRxLongFrame 0x00000080 /* Rx - frame is longer than 1518 bytes */
2940 +#define DescRxLateColl 0x00000040 /* Rx - frame was damaged by a late collision */
2941 +#define DescRxFrameEther 0x00000020 /* Rx - Frame type Ethernet 802.3*/
2942 +#define DescRxMiiError 0x00000008 /* Rx - error reported by MII interface */
2943 +#define DescRxDribbling 0x00000004 /* Rx - frame contains noninteger multiple of 8 bits */
2944 +#define DescRxCrc 0x00000002 /* Rx - CRC error */
2945 +#define DescTxTimeout 0x00004000 /* Tx - Transmit jabber timeout */
2946 +#define DescTxLostCarrier 0x00000800 /* Tx - carrier lost during tramsmission */
2947 +#define DescTxNoCarrier 0x00000400 /* Tx - no carrier signal from tranceiver */
2948 +#define DescTxLateCollision 0x00000200 /* Tx - transmission aborted due to collision */
2949 +#define DescTxExcCollisions 0x00000100 /* Tx - transmission aborted after 16 collisions */
2950 +#define DescTxHeartbeatFail 0x00000080 /* Tx - heartbeat collision check failure */
2951 +#define DescTxCollMask 0x00000078 /* Tx - Collision count */
2952 +#define DescTxCollShift 3
2953 +#define DescTxExcDeferral 0x00000004 /* Tx - excessive deferral */
2954 +#define DescTxUnderflow 0x00000002 /* Tx - late data arrival from memory */
2955 +#define DescTxDeferred 0x00000001 /* Tx - frame transmision deferred */
2957 +/* length word of DMA descriptor */
2958 +#define DescTxIntEnable 0x80000000 /* Tx - interrupt on completion */
2959 +#define DescTxLast 0x40000000 /* Tx - Last segment of the frame */
2960 +#define DescTxFirst 0x20000000 /* Tx - First segment of the frame */
2961 +#define DescTxDisableCrc 0x04000000 /* Tx - Add CRC disabled (first segment only) */
2962 +#define DescEndOfRing 0x02000000 /* End of descriptors ring */
2963 +#define DescChain 0x01000000 /* Second buffer address is chain address */
2964 +#define DescTxDisablePadd 0x00800000 /* disable padding */
2965 +#define DescSize2Mask 0x003FF800 /* Buffer 2 size */
2966 +#define DescSize2Shift 11
2967 +#define DescSize1Mask 0x000007FF /* Buffer 1 size */
2968 +#define DescSize1Shift 0
2970 +/**********************************************************/
2971 +/* Initial register values */
2972 +/**********************************************************/
2973 +/* Full-duplex mode with perfect filter on */
2974 +#define MacControlInitFdx \
2976 + | MacLittleEndian \
2977 + | MacHeartBeatOn \
2979 + | MacEnableRxOwn \
2980 + | MacLoopbackOff \
2982 + | MacMulticastFilterOn \
2983 + | MacPromiscuousModeOff \
2984 + | MacFilterNormal \
2985 + | MacBadFramesDisable \
2986 + | MacPerfectFilterOn \
2987 + | MacHashFilterOff \
2988 + | MacLateCollisionOff \
2989 + | MacBroadcastEnable \
2990 + | MacRetryEnable \
2991 + | MacPadStripDisable \
2992 + | MacDeferralCheckDisable \
2996 +/* Full-duplex mode */
2997 +#define MacFlowControlInitFdx \
2998 + ( MacControlFrameDisable \
2999 + | MacFlowControlEnable)
3001 +/* Half-duplex mode with perfect filter on */
3002 +#define MacControlInitHdx \
3004 + | MacLittleEndian \
3005 + | MacHeartBeatOn \
3007 + | MacDisableRxOwn \
3008 + | MacLoopbackOff \
3010 + | MacMulticastFilterOn \
3011 + | MacPromiscuousModeOff \
3012 + | MacFilterNormal \
3013 + | MacBadFramesDisable \
3014 + | MacPerfectFilterOn \
3015 + | MacHashFilterOff \
3016 + | MacLateCollisionOff \
3017 + | MacBroadcastEnable \
3018 + | MacRetryEnable \
3019 + | MacPadStripDisable \
3020 + | MacDeferralCheckDisable \
3024 +/* Half-duplex mode */
3025 +#define MacFlowControlInitHdx \
3026 + ( MacControlFrameDisable \
3027 + | MacFlowControlDisable)
3029 +/* Bus Mode Rx odd half word align */
3030 +#define DmaBusModeInit \
3031 + ( DmaLittleEndianDesc \
3033 + | DmaBurstLength4 \
3034 + | DmaBigEndianData \
3035 + | DmaDescriptorSkip1 \
3036 + | DmaReceivePriorityOn \
3039 +#define DmaControlInit (DmaStoreAndForward)
3041 +/* Interrupt groups */
3042 +#define DmaIntEnable \
3045 + | DmaIntBusError \
3046 + | DmaIntRxStopped \
3047 + | DmaIntTxUnderflow \
3048 + | DmaIntTxStopped)
3050 +#define DmaIntDisable 0
3052 +#define DmaAllIntCauseMask \
3056 + | DmaIntBusError \
3058 + | DmaIntRxStopped \
3059 + | DmaIntRxNoBuffer \
3060 + | DmaIntRxCompleted \
3061 + | DmaIntTxUnderflow \
3062 + | DmaIntTxJabber \
3063 + | DmaIntTxNoBuffer \
3064 + | DmaIntTxStopped \
3065 + | DmaIntTxCompleted)
3067 +#define UnhandledIntrMask \
3068 + (DmaAllIntCauseMask \
3069 + & ~(DmaIntRxNoBuffer \
3070 + | DmaIntTxStopped \
3071 + | DmaIntTxJabber \
3072 + | DmaIntTxUnderflow \
3073 + | DmaIntBusError \
3074 + | DmaIntRxCompleted ))
3076 +#define DescRxErrors \
3077 + (DescRxTruncated \
3079 + | DescRxLateColl \
3080 + | DescRxMiiError \
3083 +#define DescTxErrors \
3085 + | DescTxLateCollision \
3086 + | DescTxExcCollisions \
3087 + | DescTxExcDeferral \
3088 + | DescTxUnderflow)
3090 +/**********************************************************/
3091 +/* Descriptor Layout */
3092 +/**********************************************************/
3093 +#define AE531X_DESC_STATUS 0x00 /* Status offset */
3094 +#define AE531X_DESC_CTRLEN 0x04 /* Control and Length offset */
3095 +#define AE531X_DESC_BUFPTR 0x08 /* Buffer pointer offset */
3096 +#define AE531X_DESC_LNKBUF 0x0c /* Link field offset, or ptr to 2nd buf */
3097 +#define AE531X_DESC_SWPTR 0x10 /* OS-Dependent software pointer */
3099 +#define AE531X_DESC_SIZE 0x10 /* 4 words, 16 bytes */
3100 +#define AE531X_QUEUE_ELE_SIZE 0x14 /* with software pointer extension */
3102 +/* Accessors to the dma descriptor fields */
3103 +#define AE531X_DESC_STATUS_GET(ptr) \
3104 + *(volatile UINT32 *)((UINT32)(ptr) + AE531X_DESC_STATUS)
3106 +#define AE531X_DESC_STATUS_SET(ptr, val) \
3107 + AE531X_DESC_STATUS_GET(ptr) = (val)
3109 +#define AE531X_DESC_CTRLEN_GET(ptr) \
3110 + *(volatile UINT32 *)((UINT32)ptr + AE531X_DESC_CTRLEN)
3112 +#define AE531X_DESC_CTRLEN_SET(ptr, val) \
3113 + AE531X_DESC_CTRLEN_GET(ptr) = (val)
3115 +#define AE531X_DESC_BUFPTR_GET(ptr) \
3116 + *(volatile UINT32 *)((UINT32)ptr + AE531X_DESC_BUFPTR)
3118 +#define AE531X_DESC_BUFPTR_SET(ptr,val) \
3119 + AE531X_DESC_BUFPTR_GET(ptr) = (UINT32)(val)
3121 +#define AE531X_DESC_LNKBUF_GET(ptr) \
3122 + *(volatile UINT32 *)((UINT32)ptr + AE531X_DESC_LNKBUF)
3124 +#define AE531X_DESC_LNKBUF_SET(ptr, val) \
3125 + AE531X_DESC_LNKBUF_GET(ptr) = (val)
3127 +#define AE531X_DESC_SWPTR_GET(ptr) \
3128 + (void *)(*(volatile UINT32 *) ((UINT32)ptr + AE531X_DESC_SWPTR))
3130 +#define AE531X_DESC_SWPTR_SET(ptr,val) \
3131 + AE531X_DESC_SWPTR_GET(ptr) = (void *)(val)
3133 +/* Get size of Rx data from desc, in bytes */
3134 +#define AE531X_DESC_STATUS_RX_SIZE(x) \
3135 + (((x) & DescFrameLengthMask) >> DescFrameLengthShift)
3137 +#endif /* _AE531XREG_H_ */
3138 diff -urN linux-2.4.32.new/arch/mips/ar531x/Makefile linux-2.4.32.new-eth/arch/mips/ar531x/Makefile
3139 --- linux-2.4.32.new/arch/mips/ar531x/Makefile 2005-12-24 20:29:42.010325312 +0000
3140 +++ linux-2.4.32.new-eth/arch/mips/ar531x/Makefile 2005-12-25 12:03:16.213872024 +0000
3150 include $(TOPDIR)/Rules.make
3151 +obj-$(CONFIG_MARVELL_ENET_PHY) += mvPhy.o
3152 +obj-$(CONFIG_KENDIN_ENET_PHY)) += rtPhy.o
3153 +obj-$(CONFIG_REALTEK_ENET_PHY) += rtPhy.o
3156 diff -urN linux-2.4.32.new/arch/mips/ar531x/mvPhy.c linux-2.4.32.new-eth/arch/mips/ar531x/mvPhy.c
3157 --- linux-2.4.32.new/arch/mips/ar531x/mvPhy.c 1970-01-01 01:00:00.000000000 +0100
3158 +++ linux-2.4.32.new-eth/arch/mips/ar531x/mvPhy.c 2005-12-25 11:54:39.730389448 +0000
3161 + * This file is subject to the terms and conditions of the GNU General Public
3162 + * License. See the file "COPYING" in the main directory of this archive
3163 + * for more details.
3165 + * Copyright © 2003 Atheros Communications, Inc., All Rights Reserved.
3169 +* Manage the ethernet PHY switch, Marvell 88E6060.
3171 +* This module is intended to be largely OS and platform-independent.
3175 +#include <linux/config.h>
3176 +#include <linux/types.h>
3177 +#include <linux/netdevice.h>
3178 +#include <linux/etherdevice.h>
3179 +#include <linux/delay.h>
3181 +#include "ar531xlnx.h"
3184 +#if defined(__ECOS)
3185 +#include "ae531xecos.h"
3189 +#include "ae531xmac.h"
3190 +#include "ae531xreg.h"
3194 +#define MV_DEBUG_ERROR 0x00000001
3195 +#define MV_DEBUG_PHYSETUP 0x00000002
3196 +#define MV_DEBUG_PHYCHANGE 0x00000004
3198 +int mvPhyDebug = MV_DEBUG_ERROR;
3200 +#define MV_PRINT(FLG, X) \
3202 + if (mvPhyDebug & (FLG)) { \
3207 +#define MV_PRINT(FLG, X)
3210 +#ifdef CONFIG_VENETDEV
3212 + * On AR5312 with CONFIG_VENETDEV==1,
3213 + * ports 0..3 are LAN ports (accessed through ae0)
3214 + * port 4 is the WAN port. (accessed through ae1)
3216 + * The phy switch settings in the mvPhyInfo table are set accordingly.
3218 +#define MV_WAN_PORT 4
3219 +#define MV_IS_LAN_PORT(port) ((port) < MV_WAN_PORT)
3220 +#define MV_IS_WAN_PORT(port) ((port) == MV_WAN_PORT)
3224 + * Track per-PHY port information.
3227 + BOOL isEnetPort; /* normal enet port */
3228 + BOOL isPhyAlive; /* last known state of link */
3229 + int ethUnit; /* MAC associated with this phy port */
3231 + UINT32 phyAddr; /* PHY registers associated with this phy port */
3232 + UINT32 switchPortAddr; /* switch port regs assoc'ed with this phy port */
3233 + UINT32 VLANTableSetting; /* Value to be written to VLAN table */
3236 +/******************************************************************************
3237 + * Per-PHY information, indexed by PHY unit number.
3239 + * This table is board-dependent. It includes information
3240 + * about which enet MAC controls which PHY port.
3242 +mvPhyInfo_t mvPhyInfo[] = {
3244 + * On AP30/AR5312, all PHYs are associated with MAC0.
3245 + * AP30/AR5312's MAC1 isn't used for anything.
3246 + * CONFIG_VENETDEV==1 (router) configuration:
3247 + * Ports 0,1,2, and 3 are "LAN ports"
3248 + * Port 4 is a WAN port
3249 + * Port 5 connects to MAC0 in the AR5312
3250 + * CONFIG_VENETDEV==0 (bridge) configuration:
3251 + * Ports 0,1,2,3,4 are "LAN ports"
3252 + * Port 5 connects to the MAC0 in the AR5312
3254 + {isEnetPort: TRUE, /* phy port 0 -- LAN port 0 */
3255 + isPhyAlive: FALSE,
3259 + switchPortAddr: 0x18,
3260 +#ifdef CONFIG_VENETDEV
3261 + VLANTableSetting: 0x2e
3263 + VLANTableSetting: 0x3e
3267 + {isEnetPort: TRUE, /* phy port 1 -- LAN port 1 */
3268 + isPhyAlive: FALSE,
3272 + switchPortAddr: 0x19,
3273 +#ifdef CONFIG_VENETDEV
3274 + VLANTableSetting: 0x2d
3276 + VLANTableSetting: 0x3d
3280 + {isEnetPort: TRUE, /* phy port 2 -- LAN port 2 */
3281 + isPhyAlive: FALSE,
3285 + switchPortAddr: 0x1a,
3286 +#ifdef CONFIG_VENETDEV
3287 + VLANTableSetting: 0x2b
3289 + VLANTableSetting: 0x3b
3293 + {isEnetPort: TRUE, /* phy port 3 -- LAN port 3 */
3294 + isPhyAlive: FALSE,
3298 + switchPortAddr: 0x1b,
3299 +#ifdef CONFIG_VENETDEV
3300 + VLANTableSetting: 0x27
3302 + VLANTableSetting: 0x37
3306 + {isEnetPort: TRUE, /* phy port 4 -- WAN port or LAN port 4 */
3307 + isPhyAlive: FALSE,
3311 + switchPortAddr: 0x1c,
3312 +#ifdef CONFIG_VENETDEV
3313 + VLANTableSetting: 0x1020 /* WAN port */
3315 + VLANTableSetting: 0x2f /* LAN port 4 */
3319 + {isEnetPort: FALSE, /* phy port 5 -- CPU port (no RJ45 connector) */
3324 + switchPortAddr: 0x1d,
3325 +#ifdef CONFIG_VENETDEV
3326 + VLANTableSetting: 0x0f /* Send only to LAN ports */
3328 + VLANTableSetting: 0x1f /* Send to all ports */
3333 +#define MV_PHY_MAX (sizeof(mvPhyInfo) / sizeof(mvPhyInfo[0]))
3335 +/* Range of valid PHY IDs is [MIN..MAX] */
3336 +#define MV_ID_MIN 0
3337 +#define MV_ID_MAX (MV_PHY_MAX-1)
3339 +/* Convenience macros to access myPhyInfo */
3340 +#define MV_IS_ENET_PORT(phyUnit) (mvPhyInfo[phyUnit].isEnetPort)
3341 +#define MV_IS_PHY_ALIVE(phyUnit) (mvPhyInfo[phyUnit].isPhyAlive)
3342 +#define MV_ETHUNIT(phyUnit) (mvPhyInfo[phyUnit].ethUnit)
3343 +#define MV_PHYBASE(phyUnit) (mvPhyInfo[phyUnit].phyBase)
3344 +#define MV_PHYADDR(phyUnit) (mvPhyInfo[phyUnit].phyAddr)
3345 +#define MV_SWITCH_PORT_ADDR(phyUnit) (mvPhyInfo[phyUnit].switchPortAddr)
3346 +#define MV_VLAN_TABLE_SETTING(phyUnit) (mvPhyInfo[phyUnit].VLANTableSetting)
3348 +#define MV_IS_ETHUNIT(phyUnit, ethUnit) \
3349 + (MV_IS_ENET_PORT(phyUnit) && \
3350 + MV_ETHUNIT(phyUnit) == (ethUnit))
3353 +/* Forward references */
3354 +BOOL mv_phyIsLinkAlive(int phyUnit);
3355 +LOCAL void mv_VLANInit(int ethUnit);
3356 +LOCAL void mv_enableConfiguredPorts(int ethUnit);
3357 +LOCAL void mv_verifyReady(int ethUnit);
3358 +BOOL mv_phySetup(int ethUnit, UINT32 phyBase);
3359 +BOOL mv_phyIsFullDuplex(int ethUnit);
3360 +BOOL mv_phyIsSpeed100(int phyUnit);
3361 +LOCAL BOOL mv_validPhyId(int phyUnit);
3362 +void mv_flushATUDB(int phyUnit);
3363 +void mv_phyCheckStatusChange(int ethUnit);
3365 +void mv_phyShow(int phyUnit);
3366 +void mv_phySet(int phyUnit, UINT32 regnum, UINT32 value);
3367 +void mv_switchPortSet(int phyUnit, UINT32 regnum, UINT32 value);
3368 +void mv_switchGlobalSet(int phyUnit, UINT32 regnum, UINT32 value);
3369 +void mv_showATUDB(int phyUnit);
3370 +void mv_countGoodFrames(int phyUnit);
3371 +void mv_countBadFrames(int phyUnit);
3372 +void mv_showFrameCounts(int phyUnit);
3376 +/******************************************************************************
3378 +* mv_phyIsLinkAlive - test to see if the specified link is alive
3381 +* TRUE --> link is alive
3382 +* FALSE --> link is down
3385 +mv_phyIsLinkAlive(int phyUnit)
3387 + UINT16 phyHwStatus;
3391 + phyBase = MV_PHYBASE(phyUnit);
3392 + phyAddr = MV_PHYADDR(phyUnit);
3394 + phyHwStatus = phyRegRead(phyBase, phyAddr, MV_PHY_SPECIFIC_STATUS);
3396 + if (phyHwStatus & MV_STATUS_REAL_TIME_LINK_UP) {
3403 +/******************************************************************************
3405 +* mv_VLANInit - initialize "port-based VLANs" for the specified enet unit.
3408 +mv_VLANInit(int ethUnit)
3412 + UINT32 switchPortAddr;
3414 + for (phyUnit=0; phyUnit < MV_PHY_MAX; phyUnit++) {
3415 + if (MV_ETHUNIT(phyUnit) != ethUnit) {
3419 + phyBase = MV_PHYBASE(phyUnit);
3420 + switchPortAddr = MV_SWITCH_PORT_ADDR(phyUnit);
3422 + phyRegWrite(phyBase, switchPortAddr, MV_PORT_BASED_VLAN_MAP,
3423 + MV_VLAN_TABLE_SETTING(phyUnit));
3427 +#define phyPortConfigured(phyUnit) TRUE /* TBDFREEDOM2 */
3429 +/******************************************************************************
3431 +* mv_enableConfiguredPorts - enable whichever PHY ports are supposed
3432 +* to be enabled according to administrative configuration.
3435 +mv_enableConfiguredPorts(int ethUnit)
3439 + UINT32 switchPortAddr;
3440 + UINT16 portControl;
3441 + UINT16 portAssociationVector;
3443 + for (phyUnit=0; phyUnit < MV_PHY_MAX; phyUnit++) {
3444 + if (MV_ETHUNIT(phyUnit) != ethUnit) {
3448 + phyBase = MV_PHYBASE(phyUnit);
3449 + switchPortAddr = MV_SWITCH_PORT_ADDR(phyUnit);
3451 + if (phyPortConfigured(phyUnit)) {
3453 + portControl = MV_PORT_CONTROL_PORT_STATE_FORWARDING;
3454 +#ifdef CONFIG_VENETDEV
3455 + if (!MV_IS_ENET_PORT(phyUnit)) { /* CPU port */
3456 + portControl |= MV_PORT_CONTROL_INGRESS_TRAILER
3457 + | MV_PORT_CONTROL_EGRESS_MODE;
3460 + phyRegWrite(phyBase, switchPortAddr, MV_PORT_CONTROL, portControl);
3462 + if (MV_IS_ENET_PORT(phyUnit)) {
3463 + portAssociationVector = 1 << phyUnit;
3465 + /* Disable learning on the CPU port */
3466 + portAssociationVector = 0;
3468 + phyRegWrite(phyBase, switchPortAddr,
3469 + MV_PORT_ASSOCIATION_VECTOR, portAssociationVector);
3474 +/******************************************************************************
3476 +* mv_verifyReady - validates that we're dealing with the device
3477 +* we think we're dealing with, and that it's ready.
3480 +mv_verifyReady(int ethUnit)
3483 + UINT16 globalStatus;
3484 + UINT32 phyBase = 0;
3486 + UINT32 switchPortAddr;
3492 + * The first read to the Phy port registers always fails and
3493 + * returns 0. So get things started with a bogus read.
3495 + for (phyUnit=0; phyUnit < MV_PHY_MAX; phyUnit++) {
3496 + if (!MV_IS_ETHUNIT(phyUnit, ethUnit)) {
3499 + phyBase = MV_PHYBASE(phyUnit);
3500 + phyAddr = MV_PHYADDR(phyUnit);
3502 + (void)phyRegRead(phyBase, phyAddr, MV_PHY_ID1); /* returns 0 */
3506 + for (phyUnit=0; phyUnit < MV_PHY_MAX; phyUnit++) {
3507 + if (!MV_IS_ETHUNIT(phyUnit, ethUnit)) {
3511 + /*******************/
3512 + /* Verify phy port */
3513 + /*******************/
3514 + phyBase = MV_PHYBASE(phyUnit);
3515 + phyAddr = MV_PHYADDR(phyUnit);
3517 + phyID1 = phyRegRead(phyBase, phyAddr, MV_PHY_ID1);
3518 + if (phyID1 != MV_PHY_ID1_EXPECTATION) {
3519 + MV_PRINT(MV_DEBUG_PHYSETUP,
3520 + ("Invalid PHY ID1 for ethmac%d port%d. Expected 0x%04x, read 0x%04x\n",
3523 + MV_PHY_ID1_EXPECTATION,
3528 + phyID2 = phyRegRead(phyBase, phyAddr, MV_PHY_ID2);
3529 + if ((phyID2 & MV_OUI_LSB_MASK) != MV_OUI_LSB_EXPECTATION) {
3530 + MV_PRINT(MV_DEBUG_PHYSETUP,
3531 + ("Invalid PHY ID2 for ethmac%d port %d. Expected 0x%04x, read 0x%04x\n",
3534 + MV_OUI_LSB_EXPECTATION,
3539 + MV_PRINT(MV_DEBUG_PHYSETUP,
3540 + ("Found PHY ethmac%d port%d: model 0x%x revision 0x%x\n",
3543 + (phyID2 & MV_MODEL_NUM_MASK) >> MV_MODEL_NUM_SHIFT,
3544 + (phyID2 & MV_REV_NUM_MASK) >> MV_REV_NUM_SHIFT));
3547 + /**********************/
3548 + /* Verify switch port */
3549 + /**********************/
3550 + switchPortAddr = MV_SWITCH_PORT_ADDR(phyUnit);
3552 + switchID = phyRegRead(phyBase, switchPortAddr, MV_SWITCH_ID);
3553 + if ((switchID & MV_SWITCH_ID_DEV_MASK) !=
3554 + MV_SWITCH_ID_DEV_EXPECTATION) {
3556 + MV_PRINT(MV_DEBUG_PHYSETUP,
3557 + ("Invalid switch ID for ethmac%d port %d. Expected 0x%04x, read 0x%04x\n",
3560 + MV_SWITCH_ID_DEV_EXPECTATION,
3565 + MV_PRINT(MV_DEBUG_PHYSETUP,
3566 + ("Found PHY switch for enet %d port %d deviceID 0x%x revision 0x%x\n",
3569 + (switchID & MV_SWITCH_ID_DEV_MASK) >> MV_SWITCH_ID_DEV_SHIFT,
3570 + (switchID & MV_SWITCH_ID_REV_MASK) >> MV_SWITCH_ID_REV_SHIFT))
3573 + /*******************************/
3574 + /* Verify that switch is ready */
3575 + /*******************************/
3577 + globalStatus = phyRegRead(phyBase, MV_SWITCH_GLOBAL_ADDR,
3578 + MV_SWITCH_GLOBAL_STATUS);
3580 + if (!(globalStatus & MV_SWITCH_STATUS_READY_MASK)) {
3581 + MV_PRINT(MV_DEBUG_PHYSETUP,
3582 + ("PHY switch for ethmac%d NOT ready!\n",
3586 + MV_PRINT(MV_DEBUG_PHYSETUP,
3587 + ("No ports configured for ethmac%d\n", ethUnit));
3591 +/******************************************************************************
3593 +* mv_phySetup - reset and setup the PHY switch.
3595 +* Resets each PHY port.
3598 +* TRUE --> at least 1 PHY with LINK
3599 +* FALSE --> no LINKs on this ethernet unit
3602 +mv_phySetup(int ethUnit, UINT32 phyBase)
3605 + int liveLinks = 0;
3606 + BOOL foundPhy = FALSE;
3608 + UINT16 atuControl;
3611 + * Allow platform-specific code to determine the default Ethernet MAC
3612 + * at run-time. If phyEthMacDefault returns a negative value, use the
3613 + * static mvPhyInfo table "as is". But if phyEthMacDefault returns a
3614 + * non-negative value, use it as the default ethernet unit.
3617 + int ethMacDefault = phyEthMacDefault();
3619 + if (ethMacDefault >= 0) {
3620 + for (phyUnit=0; phyUnit < MV_PHY_MAX; phyUnit++) {
3621 + MV_ETHUNIT(phyUnit)=ethMacDefault;
3627 + * See if there's any configuration data for this enet,
3628 + * and set up phyBase in table.
3630 + for (phyUnit=0; phyUnit < MV_PHY_MAX; phyUnit++) {
3631 + if (MV_ETHUNIT(phyUnit) != ethUnit) {
3635 + MV_PHYBASE(phyUnit) = phyBase;
3640 + return FALSE; /* No PHY's configured for this ethUnit */
3643 + /* Verify that the switch is what we think it is, and that it's ready */
3644 + mv_verifyReady(ethUnit);
3646 + /* Initialize global switch settings */
3647 + atuControl = MV_ATUCTRL_AGE_TIME_DEFAULT << MV_ATUCTRL_AGE_TIME_SHIFT;
3648 + atuControl |= MV_ATUCTRL_ATU_SIZE_DEFAULT << MV_ATUCTRL_ATU_SIZE_SHIFT;
3649 + // atuControl |= MV_ATUCTRL_ATU_LEARNDIS;
3650 + phyRegWrite(phyBase, MV_SWITCH_GLOBAL_ADDR, MV_ATU_CONTROL, atuControl);
3652 + /* Reset PHYs and start autonegoation on each. */
3653 + for (phyUnit=0; phyUnit < MV_PHY_MAX; phyUnit++) {
3654 + if (MV_ETHUNIT(phyUnit) != ethUnit) {
3658 + phyBase = MV_PHYBASE(phyUnit);
3659 + phyAddr = MV_PHYADDR(phyUnit);
3661 + phyRegWrite(phyBase, phyAddr, MV_PHY_CONTROL,
3662 + MV_CTRL_SOFTWARE_RESET | MV_CTRL_AUTONEGOTIATION_ENABLE);
3667 + UINT16 phyHwStatus;
3670 + * Wait 5 seconds for ALL associated PHYs to finish autonegotiation.
3673 + for (phyUnit=0; (phyUnit < MV_PHY_MAX) && (timeout > 0); phyUnit++) {
3674 + if (!MV_IS_ETHUNIT(phyUnit, ethUnit)) {
3678 + phyBase = MV_PHYBASE(phyUnit);
3679 + phyAddr = MV_PHYADDR(phyUnit);
3681 + phyHwStatus = phyRegRead(phyBase, phyAddr, MV_PHY_SPECIFIC_STATUS);
3683 + if (MV_AUTONEG_DONE(phyHwStatus)) {
3687 + if (--timeout == 0) {
3697 + * All PHYs have had adequate time to autonegotiate.
3698 + * Now initialize software status.
3700 + * It's possible that some ports may take a bit longer
3701 + * to autonegotiate; but we can't wait forever. They'll
3702 + * get noticed by mv_phyCheckStatusChange during regular
3703 + * polling activities.
3705 + for (phyUnit=0; phyUnit < MV_PHY_MAX; phyUnit++) {
3706 + if (!MV_IS_ETHUNIT(phyUnit, ethUnit)) {
3710 + if (mv_phyIsLinkAlive(phyUnit)) {
3712 + MV_IS_PHY_ALIVE(phyUnit) = TRUE;
3714 + mv_phyShow(phyUnit);
3717 + MV_IS_PHY_ALIVE(phyUnit) = FALSE;
3720 + MV_PRINT(MV_DEBUG_PHYSETUP,
3721 + ("ethmac%d: Phy Status=%4.4x\n",
3723 + phyRegRead(MV_PHYBASE(phyUnit),
3724 + MV_PHYADDR(phyUnit),
3725 + MV_PHY_SPECIFIC_STATUS)));
3730 + /* PHY 5 is the connection to the CPU */
3734 + mv_VLANInit(ethUnit);
3736 + mv_enableConfiguredPorts(ethUnit);
3738 + return (liveLinks > 0);
3742 +/******************************************************************************
3744 +* mv_phyIsDuplexFull - Determines whether the phy ports associated with the
3745 +* specified device are FULL or HALF duplex.
3748 +* TRUE --> at least one associated PHY in FULL DUPLEX
3749 +* FALSE --> all half duplex, or no links
3752 +mv_phyIsFullDuplex(int ethUnit)
3757 + UINT16 phyHwStatus;
3759 + for (phyUnit=0; phyUnit < MV_PHY_MAX; phyUnit++) {
3761 + if (!MV_IS_ETHUNIT(phyUnit, ethUnit)) {
3765 + if (mv_phyIsLinkAlive(phyUnit)) {
3767 + phyBase = MV_PHYBASE(phyUnit);
3768 + phyAddr = MV_PHYADDR(phyUnit);
3770 + phyHwStatus = phyRegRead(phyBase, phyAddr, MV_PHY_SPECIFIC_STATUS);
3772 + if (phyHwStatus & MV_STATUS_RESOLVED_DUPLEX_FULL) {
3781 +/******************************************************************************
3783 +* mv_phyIsSpeed100 - Determines the speed of a phy port
3786 +* TRUE --> PHY operating at 100 Mbit
3787 +* FALSE --> link down, or not operating at 100 Mbit
3790 +mv_phyIsSpeed100(int phyUnit)
3792 + UINT16 phyHwStatus;
3796 + if (MV_IS_ENET_PORT(phyUnit)) {
3797 + if (mv_phyIsLinkAlive(phyUnit)) {
3799 + phyBase = MV_PHYBASE(phyUnit);
3800 + phyAddr = MV_PHYADDR(phyUnit);
3802 + phyHwStatus = phyRegRead(phyBase, phyAddr, MV_PHY_SPECIFIC_STATUS);
3804 + if (phyHwStatus & MV_STATUS_RESOLVED_SPEED_100) {
3813 +#ifdef CONFIG_VENETDEV
3814 +/******************************************************************************
3816 +* mv_phyDetermineSource - Examine a received frame's Egress Trailer
3817 +* to determine whether it came from a LAN or WAN port.
3820 +* Returns 1-->LAN, 0-->WAN, -1-->ERROR
3823 +mv_phyDetermineSource(char *data, int len)
3825 + unsigned char *phyTrailer;
3826 + unsigned char incomingPort;
3828 + phyTrailer = &data[len - MV_PHY_TRAILER_SIZE];
3830 + /* ASSERT(phyTrailer[0] == MV_EGRESS_TRAILER_VALID); */
3831 + if (phyTrailer[0] != MV_EGRESS_TRAILER_VALID) {
3832 + printk(KERN_ERR "PHY trailer invalid; got %#02x, expected %#02x\n",
3833 + phyTrailer[0], MV_EGRESS_TRAILER_VALID);
3837 + incomingPort = phyTrailer[1];
3838 + if (MV_IS_LAN_PORT(incomingPort)) {
3841 + /* ASSERT(MV_IS_WAN_PORT(incomingPort)); */
3842 + if (!MV_IS_WAN_PORT(incomingPort)) {
3843 + printk(KERN_ERR "incoming port was %d; expected 0-4\n", incomingPort);
3851 +/******************************************************************************
3853 +* mv_phySetDestinationPort - Set the Ingress Trailer to force the
3854 +* frame to be sent to LAN or WAN, as specified.
3858 +mv_phySetDestinationPort(char *data, int len, int fromLAN)
3862 + phyTrailer = &data[len];
3864 + /* LAN ports: Use default settings, as per mvPhyInfo */
3865 + phyTrailer[0] = 0x00;
3866 + phyTrailer[1] = 0x00;
3868 + /* WAN port: Direct to WAN port */
3869 + phyTrailer[0] = MV_INGRESS_TRAILER_OVERRIDE;
3870 + phyTrailer[1] = 1 << MV_WAN_PORT;
3872 + phyTrailer[2] = 0x00;
3873 + phyTrailer[3] = 0x00;
3878 +/*****************************************************************************
3880 +* Validate that the specified PHY unit number is a valid PHY ID.
3881 +* Print a message if it is invalid.
3884 +* FALSE --> invalid
3887 +mv_validPhyId(int phyUnit)
3889 + if ((phyUnit >= MV_ID_MIN) && (phyUnit <= MV_ID_MAX)) {
3892 + PRINTF("PHY unit number must be in the range [%d..%d]\n",
3893 + MV_ID_MIN, MV_ID_MAX);
3899 +/*****************************************************************************
3901 +* mv_waitWhileATUBusy - spins until the ATU completes
3902 +* its previous operation.
3905 +mv_waitWhileATUBusy(UINT32 phyBase)
3908 + UINT16 ATUOperation;
3912 + ATUOperation = phyRegRead(phyBase, MV_SWITCH_GLOBAL_ADDR,
3913 + MV_ATU_OPERATION);
3915 + isBusy = (ATUOperation & MV_ATU_BUSY_MASK) == MV_ATU_IS_BUSY;
3920 +/*****************************************************************************
3922 +* mv_flushATUDB - flushes ALL entries in the Address Translation Unit
3923 +* DataBase associated with phyUnit. [Since we use a single DB for
3924 +* all PHYs, this flushes the entire shared DataBase.]
3926 +* The current implementation flushes even more than absolutely needed --
3927 +* it flushes all entries for all phyUnits on the same ethernet as the
3928 +* specified phyUnit.
3930 +* It is called only when a link failure is detected on a port that was
3931 +* previously working. In other words, when the cable is unplugged.
3934 +mv_flushATUDB(int phyUnit)
3938 + if (!mv_validPhyId(phyUnit)) {
3939 + PRINTF("Invalid port number: %d\n", phyUnit);
3943 + phyBase = MV_PHYBASE(phyUnit);
3945 + /* Wait for previous operation (if any) to complete */
3946 + mv_waitWhileATUBusy(phyBase);
3948 + /* Tell hardware to flush all entries */
3949 + phyRegWrite(phyBase, MV_SWITCH_GLOBAL_ADDR, MV_ATU_OPERATION,
3950 + MV_ATU_OP_FLUSH_ALL | MV_ATU_IS_BUSY);
3952 + mv_waitWhileATUBusy(phyBase);
3955 +/*****************************************************************************
3957 +* mv_phyCheckStatusChange -- checks for significant changes in PHY state.
3959 +* A "significant change" is:
3960 +* dropped link (e.g. ethernet cable unplugged) OR
3961 +* autonegotiation completed + link (e.g. ethernet cable plugged in)
3964 +mv_phyCheckStatusChange(int ethUnit)
3967 + UINT16 phyHwStatus;
3968 + mvPhyInfo_t *lastStatus;
3969 + int linkCount = 0;
3970 + int lostLinks = 0;
3971 + int gainedLinks = 0;
3975 + for (phyUnit=0; phyUnit < MV_PHY_MAX; phyUnit++) {
3976 + if (!MV_IS_ETHUNIT(phyUnit, ethUnit)) {
3980 + phyBase = MV_PHYBASE(phyUnit);
3981 + phyAddr = MV_PHYADDR(phyUnit);
3983 + lastStatus = &mvPhyInfo[phyUnit];
3984 + phyHwStatus = phyRegRead(phyBase, phyAddr, MV_PHY_SPECIFIC_STATUS);
3986 + if (lastStatus->isPhyAlive) { /* last known link status was ALIVE */
3987 + /* See if we've lost link */
3988 + if (phyHwStatus & MV_STATUS_REAL_TIME_LINK_UP) {
3992 + mv_flushATUDB(phyUnit);
3993 + MV_PRINT(MV_DEBUG_PHYCHANGE,("\nethmac%d port%d down\n",
3994 + ethUnit, phyUnit));
3995 + lastStatus->isPhyAlive = FALSE;
3997 + } else { /* last known link status was DEAD */
3998 + /* Check for AutoNegotiation complete */
3999 + if (MV_AUTONEG_DONE(phyHwStatus)) {
4002 + MV_PRINT(MV_DEBUG_PHYCHANGE,("\nethmac%d port%d up\n",
4003 + ethUnit, phyUnit));
4004 + lastStatus->isPhyAlive = TRUE;
4009 + if (linkCount == 0) {
4011 + /* We just lost the last link for this MAC */
4012 + phyLinkLost(ethUnit);
4015 + if (gainedLinks == linkCount) {
4016 + /* We just gained our first link(s) for this MAC */
4017 + phyLinkGained(ethUnit);
4024 +/* Define the registers of interest for a phyShow command */
4025 +typedef struct mvRegisterTableEntry_s {
4027 + char *regIdString;
4028 +} mvRegisterTableEntry_t;
4030 +mvRegisterTableEntry_t mvPhyRegisterTable[] = {
4031 + {MV_PHY_CONTROL, "PHY Control "},
4032 + {MV_PHY_STATUS, "PHY Status "},
4033 + {MV_PHY_ID1, "PHY Identifier 1 "},
4034 + {MV_PHY_ID2, "PHY Identifier 2 "},
4035 + {MV_AUTONEG_ADVERT, "Auto-Negotiation Advertisement "},
4036 + {MV_LINK_PARTNER_ABILITY, "Link Partner Ability "},
4037 + {MV_AUTONEG_EXPANSION, "Auto-Negotiation Expansion "},
4038 + {MV_NEXT_PAGE_TRANSMIT, "Next Page Transmit "},
4039 + {MV_LINK_PARTNER_NEXT_PAGE, "Link Partner Next Page "},
4040 + {MV_PHY_SPECIFIC_CONTROL_1, "PHY-Specific Control Register 1 "},
4041 + {MV_PHY_SPECIFIC_STATUS, "PHY-Specific Status "},
4042 + {MV_PHY_INTERRUPT_ENABLE, "PHY Interrupt Enable "},
4043 + {MV_PHY_INTERRUPT_STATUS, "PHY Interrupt Status "},
4044 + {MV_PHY_INTERRUPT_PORT_SUMMARY, "PHY Interrupt Port Summary "},
4045 + {MV_RECEIVE_ERROR_COUNTER, "Receive Error Counter "},
4046 + {MV_LED_PARALLEL_SELECT, "LED Parallel Select "},
4047 + {MV_LED_STREAM_SELECT_LEDS, "LED Stream Select "},
4048 + {MV_PHY_LED_CONTROL, "PHY LED Control "},
4049 + {MV_PHY_MANUAL_LED_OVERRIDE, "PHY Manual LED Override "},
4050 + {MV_VCT_CONTROL, "VCT Control "},
4051 + {MV_VCT_STATUS, "VCT Status "},
4052 + {MV_PHY_SPECIFIC_CONTROL_2, "PHY-Specific Control Register 2 "},
4054 +int mvPhyNumRegs = sizeof(mvPhyRegisterTable) / sizeof(mvPhyRegisterTable[0]);
4057 +mvRegisterTableEntry_t mvSwitchPortRegisterTable[] = {
4058 + {MV_PORT_STATUS, "Port Status "},
4059 + {MV_SWITCH_ID, "Switch ID "},
4060 + {MV_PORT_CONTROL, "Port Control "},
4061 + {MV_PORT_BASED_VLAN_MAP, "Port-Based VLAN Map "},
4062 + {MV_PORT_ASSOCIATION_VECTOR, "Port Association Vector "},
4063 + {MV_RX_COUNTER, "RX Counter "},
4064 + {MV_TX_COUNTER, "TX Counter "},
4066 +int mvSwitchPortNumRegs =
4067 + sizeof(mvSwitchPortRegisterTable) / sizeof(mvSwitchPortRegisterTable[0]);
4070 +mvRegisterTableEntry_t mvSwitchGlobalRegisterTable[] = {
4071 + {MV_SWITCH_GLOBAL_STATUS, "Switch Global Status "},
4072 + {MV_SWITCH_MAC_ADDR0, "Switch MAC Addr 0 & 1 "},
4073 + {MV_SWITCH_MAC_ADDR2, "Switch MAC Addr 2 & 3 "},
4074 + {MV_SWITCH_MAC_ADDR4, "Switch MAC Addr 4 & 5 "},
4075 + {MV_SWITCH_GLOBAL_CONTROL, "Switch Global Control "},
4076 + {MV_ATU_CONTROL, "ATU Control "},
4077 + {MV_ATU_OPERATION, "ATU Operation "},
4078 + {MV_ATU_DATA, "ATU Data "},
4079 + {MV_ATU_MAC_ADDR0, "ATU MAC Addr 0 & 1 "},
4080 + {MV_ATU_MAC_ADDR2, "ATU MAC Addr 2 & 3 "},
4081 + {MV_ATU_MAC_ADDR4, "ATU MAC Addr 4 & 5 "},
4083 +int mvSwitchGlobalNumRegs =
4084 + sizeof(mvSwitchGlobalRegisterTable) / sizeof(mvSwitchGlobalRegisterTable[0]);
4087 +/*****************************************************************************
4089 +* mv_phyShow - Dump the state of a PHY.
4090 +* There are two sets of registers for each phy port:
4091 +* "phy registers" and
4092 +* "switch port registers"
4093 +* We dump 'em all, plus the switch global registers.
4096 +mv_phyShow(int phyUnit)
4102 + UINT32 switchPortAddr;
4104 + if (!mv_validPhyId(phyUnit)) {
4108 + phyBase = MV_PHYBASE(phyUnit);
4109 + phyAddr = MV_PHYADDR(phyUnit);
4110 + switchPortAddr = MV_SWITCH_PORT_ADDR(phyUnit);
4112 + PRINTF("PHY state for PHY%d (ethmac%d, phyBase 0x%8x, phyAddr 0x%x, switchAddr 0x%x)\n",
4114 + MV_ETHUNIT(phyUnit),
4115 + MV_PHYBASE(phyUnit),
4116 + MV_PHYADDR(phyUnit),
4117 + MV_SWITCH_PORT_ADDR(phyUnit));
4119 + PRINTF("PHY Registers:\n");
4120 + for (i=0; i < mvPhyNumRegs; i++) {
4122 + value = phyRegRead(phyBase, phyAddr, mvPhyRegisterTable[i].regNum);
4124 + PRINTF("Reg %02d (0x%02x) %s = 0x%08x\n",
4125 + mvPhyRegisterTable[i].regNum,
4126 + mvPhyRegisterTable[i].regNum,
4127 + mvPhyRegisterTable[i].regIdString,
4131 + PRINTF("Switch Port Registers:\n");
4132 + for (i=0; i < mvSwitchPortNumRegs; i++) {
4134 + value = phyRegRead(phyBase, switchPortAddr,
4135 + mvSwitchPortRegisterTable[i].regNum);
4137 + PRINTF("Reg %02d (0x%02x) %s = 0x%08x\n",
4138 + mvSwitchPortRegisterTable[i].regNum,
4139 + mvSwitchPortRegisterTable[i].regNum,
4140 + mvSwitchPortRegisterTable[i].regIdString,
4144 + PRINTF("Switch Global Registers:\n");
4145 + for (i=0; i < mvSwitchGlobalNumRegs; i++) {
4147 + value = phyRegRead(phyBase, MV_SWITCH_GLOBAL_ADDR,
4148 + mvSwitchGlobalRegisterTable[i].regNum);
4150 + PRINTF("Reg %02d (0x%02x) %s = 0x%08x\n",
4151 + mvSwitchGlobalRegisterTable[i].regNum,
4152 + mvSwitchGlobalRegisterTable[i].regNum,
4153 + mvSwitchGlobalRegisterTable[i].regIdString,
4158 +/*****************************************************************************
4160 +* mv_phySet - Modify the value of a PHY register (debug only).
4163 +mv_phySet(int phyUnit, UINT32 regnum, UINT32 value)
4168 + if (mv_validPhyId(phyUnit)) {
4170 + phyBase = MV_PHYBASE(phyUnit);
4171 + phyAddr = MV_PHYADDR(phyUnit);
4173 + phyRegWrite(phyBase, phyAddr, regnum, value);
4178 +/*****************************************************************************
4180 +* mv_switchPortSet - Modify the value of a switch port register (debug only).
4183 +mv_switchPortSet(int phyUnit, UINT32 regnum, UINT32 value)
4186 + UINT32 switchPortAddr;
4188 + if (mv_validPhyId(phyUnit)) {
4190 + phyBase = MV_PHYBASE(phyUnit);
4191 + switchPortAddr = MV_SWITCH_PORT_ADDR(phyUnit);
4193 + phyRegWrite(phyBase, switchPortAddr, regnum, value);
4197 +/*****************************************************************************
4199 +* mv_switchGlobalSet - Modify the value of a switch global register
4203 +mv_switchGlobalSet(int phyUnit, UINT32 regnum, UINT32 value)
4207 + if (mv_validPhyId(phyUnit)) {
4209 + phyBase = MV_PHYBASE(phyUnit);
4211 + phyRegWrite(phyBase, MV_SWITCH_GLOBAL_ADDR, regnum, value);
4215 +/*****************************************************************************
4217 +* mv_showATUDB - Dump the contents of the Address Translation Unit DataBase
4218 +* for the PHY switch associated with the specified phy.
4221 +mv_showATUDB(int phyUnit)
4231 + if (!mv_validPhyId(phyUnit)) {
4232 + PRINTF("Invalid port number: %d\n", phyUnit);
4236 + phyBase = MV_PHYBASE(phyUnit);
4238 + /* Wait for previous operation (if any) to complete */
4239 + mv_waitWhileATUBusy(phyBase);
4241 + /* Initialize ATU MAC to all 1's */
4242 + phyRegWrite(phyBase, MV_SWITCH_GLOBAL_ADDR, MV_ATU_MAC_ADDR0, 0xffff);
4243 + phyRegWrite(phyBase, MV_SWITCH_GLOBAL_ADDR, MV_ATU_MAC_ADDR2, 0xffff);
4244 + phyRegWrite(phyBase, MV_SWITCH_GLOBAL_ADDR, MV_ATU_MAC_ADDR4, 0xffff);
4246 + PRINTF(" MAC ADDRESS EntryState PortVector\n");
4249 + /* Tell hardware to get next MAC info */
4250 + phyRegWrite(phyBase, MV_SWITCH_GLOBAL_ADDR, MV_ATU_OPERATION,
4251 + MV_ATU_OP_GET_NEXT | MV_ATU_IS_BUSY);
4253 + mv_waitWhileATUBusy(phyBase);
4255 + ATUData = phyRegRead(phyBase, MV_SWITCH_GLOBAL_ADDR, MV_ATU_DATA);
4256 + entryState = (ATUData & MV_ENTRYSTATE_MASK) >> MV_ENTRYSTATE_SHIFT;
4258 + if (entryState == 0) {
4259 + /* We've hit the end of the list */
4263 + ATUMac0 = phyRegRead(phyBase, MV_SWITCH_GLOBAL_ADDR, MV_ATU_MAC_ADDR0);
4264 + ATUMac2 = phyRegRead(phyBase, MV_SWITCH_GLOBAL_ADDR, MV_ATU_MAC_ADDR2);
4265 + ATUMac4 = phyRegRead(phyBase, MV_SWITCH_GLOBAL_ADDR, MV_ATU_MAC_ADDR4);
4267 + portVec = (ATUData & MV_PORTVEC_MASK) >> MV_PORTVEC_SHIFT;
4269 + PRINTF("%02x:%02x:%02x:%02x:%02x:%02x 0x%02x 0x%02x\n",
4270 + ATUMac0 >> 8, /* MAC byte 0 */
4271 + ATUMac0 & 0xff, /* MAC byte 1 */
4272 + ATUMac2 >> 8, /* MAC byte 2 */
4273 + ATUMac2 & 0xff, /* MAC byte 3 */
4274 + ATUMac4 >> 8, /* MAC byte 4 */
4275 + ATUMac4 & 0xff, /* MAC byte 5 */
4281 +LOCAL BOOL countingGoodFrames;
4283 +/*****************************************************************************
4285 +* mv_countGoodFrames - starts counting GOOD RX/TX frames per port
4288 +mv_countGoodFrames(int phyUnit)
4291 + UINT16 globalControl;
4293 + if (mv_validPhyId(phyUnit)) {
4295 + * Guarantee that counters are cleared by
4296 + * forcing CtrMode to toggle and end on GOODFRAMES.
4299 + phyBase = MV_PHYBASE(phyUnit);
4301 + /* Read current Switch Global Control Register */
4302 + globalControl = phyRegRead(phyBase, MV_SWITCH_GLOBAL_ADDR,
4303 + MV_SWITCH_GLOBAL_CONTROL);
4305 + /* Set CtrMode to count BAD frames */
4306 + globalControl = ((globalControl & ~MV_CTRMODE_MASK) |
4307 + MV_CTRMODE_BADFRAMES);
4309 + /* Push new value out to hardware */
4310 + phyRegWrite(phyBase, MV_SWITCH_GLOBAL_ADDR,
4311 + MV_SWITCH_GLOBAL_CONTROL, globalControl);
4313 + /* Now toggle CtrMode to count GOOD frames */
4314 + globalControl = ((globalControl & ~MV_CTRMODE_MASK) |
4315 + MV_CTRMODE_GOODFRAMES);
4317 + /* Push new value out to hardware */
4318 + phyRegWrite(phyBase, MV_SWITCH_GLOBAL_ADDR,
4319 + MV_SWITCH_GLOBAL_CONTROL, globalControl);
4321 + countingGoodFrames = TRUE;
4325 +/*****************************************************************************
4327 +* mv_countBadFrames - starts counting BAD RX/TX frames per port
4330 +mv_countBadFrames(int phyUnit)
4333 + UINT16 globalControl;
4335 + if (mv_validPhyId(phyUnit)) {
4337 + * Guarantee that counters are cleared by
4338 + * forcing CtrMode to toggle and end on BADFRAMES.
4341 + phyBase = MV_PHYBASE(phyUnit);
4343 + /* Read current Switch Global Control Register */
4344 + globalControl = phyRegRead(phyBase, MV_SWITCH_GLOBAL_ADDR,
4345 + MV_SWITCH_GLOBAL_CONTROL);
4347 + /* Set CtrMode to count GOOD frames */
4348 + globalControl = ((globalControl & ~MV_CTRMODE_MASK) |
4349 + MV_CTRMODE_GOODFRAMES);
4351 + /* Push new value out to hardware */
4352 + phyRegWrite(phyBase, MV_SWITCH_GLOBAL_ADDR,
4353 + MV_SWITCH_GLOBAL_CONTROL, globalControl);
4355 + /* Now toggle CtrMode to count BAD frames */
4356 + globalControl = ((globalControl & ~MV_CTRMODE_MASK) |
4357 + MV_CTRMODE_BADFRAMES);
4359 + /* Push new value out to hardware */
4360 + phyRegWrite(phyBase, MV_SWITCH_GLOBAL_ADDR,
4361 + MV_SWITCH_GLOBAL_CONTROL, globalControl);
4363 + countingGoodFrames = FALSE;
4367 +/*****************************************************************************
4369 +* mv_showFrameCounts - shows current GOOD/BAD Frame counts
4372 +mv_showFrameCounts(int phyUnit)
4377 + UINT32 switchPortAddr;
4379 + if (!mv_validPhyId(phyUnit)) {
4383 + phyBase = MV_PHYBASE(phyUnit);
4384 + switchPortAddr = MV_SWITCH_PORT_ADDR(phyUnit);
4386 + rxCounter = phyRegRead(phyBase, switchPortAddr, MV_RX_COUNTER);
4388 + txCounter = phyRegRead(phyBase, switchPortAddr, MV_TX_COUNTER);
4390 + PRINTF("port%d %s frames: receive: %05d transmit: %05d\n",
4392 + (countingGoodFrames ? "good" : "error"),
4397 diff -urN linux-2.4.32.new/arch/mips/ar531x/mvPhy.h linux-2.4.32.new-eth/arch/mips/ar531x/mvPhy.h
4398 --- linux-2.4.32.new/arch/mips/ar531x/mvPhy.h 1970-01-01 01:00:00.000000000 +0100
4399 +++ linux-2.4.32.new-eth/arch/mips/ar531x/mvPhy.h 2005-12-25 11:54:39.775382608 +0000
4402 + * This file is subject to the terms and conditions of the GNU General Public
4403 + * License. See the file "COPYING" in the main directory of this archive
4404 + * for more details.
4406 + * Copyright © 2003 Atheros Communications, Inc., All Rights Reserved.
4410 + * mvPhy.h - definitions for the ethernet PHY -- Marvell 88E6060
4411 + * All definitions in this file are operating system independent!
4417 +/*****************/
4418 +/* PHY Registers */
4419 +/*****************/
4420 +#define MV_PHY_CONTROL 0
4421 +#define MV_PHY_STATUS 1
4422 +#define MV_PHY_ID1 2
4423 +#define MV_PHY_ID2 3
4424 +#define MV_AUTONEG_ADVERT 4
4425 +#define MV_LINK_PARTNER_ABILITY 5
4426 +#define MV_AUTONEG_EXPANSION 6
4427 +#define MV_NEXT_PAGE_TRANSMIT 7
4428 +#define MV_LINK_PARTNER_NEXT_PAGE 8
4429 +#define MV_PHY_SPECIFIC_CONTROL_1 16
4430 +#define MV_PHY_SPECIFIC_STATUS 17
4431 +#define MV_PHY_INTERRUPT_ENABLE 18
4432 +#define MV_PHY_INTERRUPT_STATUS 19
4433 +#define MV_PHY_INTERRUPT_PORT_SUMMARY 20
4434 +#define MV_RECEIVE_ERROR_COUNTER 21
4435 +#define MV_LED_PARALLEL_SELECT 22
4436 +#define MV_LED_STREAM_SELECT_LEDS 23
4437 +#define MV_PHY_LED_CONTROL 24
4438 +#define MV_PHY_MANUAL_LED_OVERRIDE 25
4439 +#define MV_VCT_CONTROL 26
4440 +#define MV_VCT_STATUS 27
4441 +#define MV_PHY_SPECIFIC_CONTROL_2 28
4443 +/* MV_PHY_CONTROL fields */
4444 +#define MV_CTRL_SOFTWARE_RESET 0x8000
4445 +#define MV_CTRL_AUTONEGOTIATION_ENABLE 0x1000
4447 +/* MV_PHY_ID1 fields */
4448 +#define MV_PHY_ID1_EXPECTATION 0x0141 /* OUI >> 6 */
4450 +/* MV_PHY_ID2 fields */
4451 +#define MV_OUI_LSB_MASK 0xfc00
4452 +#define MV_OUI_LSB_EXPECTATION 0x0c00
4453 +#define MV_OUI_LSB_SHIFT 10
4454 +#define MV_MODEL_NUM_MASK 0x03f0
4455 +#define MV_MODEL_NUM_SHIFT 4
4456 +#define MV_REV_NUM_MASK 0x000f
4457 +#define MV_REV_NUM_SHIFT 0
4459 +/* MV_PHY_SPECIFIC_STATUS fields */
4460 +#define MV_STATUS_RESOLVED_SPEED_100 0x4000
4461 +#define MV_STATUS_RESOLVED_DUPLEX_FULL 0x2000
4462 +#define MV_STATUS_RESOLVED 0x0800
4463 +#define MV_STATUS_REAL_TIME_LINK_UP 0x0400
4465 +/* Check if autonegotiation is complete and link is up */
4466 +#define MV_AUTONEG_DONE(mv_phy_specific_status) \
4467 + (((mv_phy_specific_status) & \
4468 + (MV_STATUS_RESOLVED | MV_STATUS_REAL_TIME_LINK_UP)) == \
4469 + (MV_STATUS_RESOLVED | MV_STATUS_REAL_TIME_LINK_UP))
4472 +/*************************/
4473 +/* Switch Port Registers */
4474 +/*************************/
4475 +#define MV_PORT_STATUS 0
4476 +#define MV_SWITCH_ID 3
4477 +#define MV_PORT_CONTROL 4
4478 +#define MV_PORT_BASED_VLAN_MAP 6
4479 +#define MV_PORT_ASSOCIATION_VECTOR 11
4480 +#define MV_RX_COUNTER 16
4481 +#define MV_TX_COUNTER 17
4483 +/* MV_SWITCH_ID fields */
4484 +#define MV_SWITCH_ID_DEV_MASK 0xfff0
4485 +#define MV_SWITCH_ID_DEV_EXPECTATION 0x0600
4486 +#define MV_SWITCH_ID_DEV_SHIFT 4
4487 +#define MV_SWITCH_ID_REV_MASK 0x000f
4488 +#define MV_SWITCH_ID_REV_SHIFT 0
4490 +/* MV_PORT_CONTROL fields */
4491 +#define MV_PORT_CONTROL_PORT_STATE_MASK 0x0003
4492 +#define MV_PORT_CONTROL_PORT_STATE_DISABLED 0x0000
4493 +#define MV_PORT_CONTROL_PORT_STATE_FORWARDING 0x0003
4495 +#define MV_PORT_CONTROL_EGRESS_MODE 0x0100 /* Receive */
4496 +#define MV_PORT_CONTROL_INGRESS_TRAILER 0x4000 /* Transmit */
4498 +#define MV_EGRESS_TRAILER_VALID 0x80
4499 +#define MV_INGRESS_TRAILER_OVERRIDE 0x80
4501 +#define MV_PHY_TRAILER_SIZE 4
4504 +/***************************/
4505 +/* Switch Global Registers */
4506 +/***************************/
4507 +#define MV_SWITCH_GLOBAL_STATUS 0
4508 +#define MV_SWITCH_MAC_ADDR0 1
4509 +#define MV_SWITCH_MAC_ADDR2 2
4510 +#define MV_SWITCH_MAC_ADDR4 3
4511 +#define MV_SWITCH_GLOBAL_CONTROL 4
4512 +#define MV_ATU_CONTROL 10
4513 +#define MV_ATU_OPERATION 11
4514 +#define MV_ATU_DATA 12
4515 +#define MV_ATU_MAC_ADDR0 13
4516 +#define MV_ATU_MAC_ADDR2 14
4517 +#define MV_ATU_MAC_ADDR4 15
4519 +/* MV_SWITCH_GLOBAL_STATUS fields */
4520 +#define MV_SWITCH_STATUS_READY_MASK 0x0800
4522 +/* MV_SWITCH_GLOBAL_CONTROL fields */
4523 +#define MV_CTRMODE_MASK 0x0100
4524 +#define MV_CTRMODE_GOODFRAMES 0x0000
4525 +#define MV_CTRMODE_BADFRAMES 0x0100
4527 +/* MV_ATU_CONTROL fields */
4528 +#define MV_ATUCTRL_ATU_LEARNDIS 0x4000
4529 +#define MV_ATUCTRL_ATU_SIZE_MASK 0x3000
4530 +#define MV_ATUCTRL_ATU_SIZE_SHIFT 12
4531 +#define MV_ATUCTRL_ATU_SIZE_DEFAULT 2 /* 1024 entry database */
4532 +#define MV_ATUCTRL_AGE_TIME_MASK 0x0ff0
4533 +#define MV_ATUCTRL_AGE_TIME_SHIFT 4
4534 +#define MV_ATUCTRL_AGE_TIME_DEFAULT 19 /* 19 * 16 = 304 seconds */
4536 +/* MV_ATU_OPERATION fields */
4537 +#define MV_ATU_BUSY_MASK 0x8000
4538 +#define MV_ATU_IS_BUSY 0x8000
4539 +#define MV_ATU_IS_FREE 0x0000
4540 +#define MV_ATU_OP_MASK 0x7000
4541 +#define MV_ATU_OP_FLUSH_ALL 0x1000
4542 +#define MV_ATU_OP_GET_NEXT 0x4000
4544 +/* MV_ATU_DATA fields */
4545 +#define MV_ENTRYPRI_MASK 0xc000
4546 +#define MV_ENTRYPRI_SHIFT 14
4547 +#define MV_PORTVEC_MASK 0x03f0
4548 +#define MV_PORTVEC_SHIFT 4
4549 +#define MV_ENTRYSTATE_MASK 0x000f
4550 +#define MV_ENTRYSTATE_SHIFT 0
4552 +/* PHY Address for the switch itself */
4553 +#define MV_SWITCH_GLOBAL_ADDR 0x1f
4555 +BOOL mv_phySetup(int ethUnit, UINT32 phyBase);
4556 +void mv_phyCheckStatusChange(int ethUnit);
4557 +BOOL mv_phyIsSpeed100(int ethUnit);
4558 +BOOL mv_phyIsFullDuplex(int ethUnit);
4560 +#endif /* MVPHY_H */
4561 diff -urN linux-2.4.32.new/arch/mips/ar531x/rtPhy.c linux-2.4.32.new-eth/arch/mips/ar531x/rtPhy.c
4562 --- linux-2.4.32.new/arch/mips/ar531x/rtPhy.c 1970-01-01 01:00:00.000000000 +0100
4563 +++ linux-2.4.32.new-eth/arch/mips/ar531x/rtPhy.c 2005-12-25 11:54:46.086423184 +0000
4566 + * This file is subject to the terms and conditions of the GNU General Public
4567 + * License. See the file "COPYING" in the main directory of this archive
4568 + * for more details.
4570 + * Copyright © 2003 Atheros Communications, Inc., All Rights Reserved.
4574 + * Manage the ethernet PHY.
4575 + * This code supports a simple 1-port ethernet phy, Realtek RTL8201BL,
4576 + * and compatible PHYs, such as the Kendin KS8721B.
4577 + * All definitions in this file are operating system independent!
4581 +#include <linux/config.h>
4582 +#include <linux/types.h>
4583 +#include <linux/netdevice.h>
4584 +#include <linux/etherdevice.h>
4585 +#include <linux/delay.h>
4587 +#include "ar531xlnx.h"
4590 +#if defined(__ECOS)
4591 +#include "ae531xecos.h"
4595 +#include "ae531xmac.h"
4596 +#include "ae531xreg.h"
4600 +#define RT_DEBUG_ERROR 0x00000001
4601 +#define RT_DEBUG_PHYSETUP 0x00000002
4602 +#define RT_DEBUG_PHYCHANGE 0x00000004
4604 +int rtPhyDebug = RT_DEBUG_ERROR;
4606 +#define RT_PRINT(FLG, X) \
4608 + if (rtPhyDebug & (FLG)) { \
4613 +#define RT_PRINT(FLG, X)
4617 + * Track per-PHY port information.
4620 + BOOL phyAlive; /* last known state of link */
4625 +#define ETH_PHY_ADDR 1
4628 + * This table defines the mapping from phy units to
4629 + * per-PHY information.
4631 + * This table is somewhat board-dependent.
4633 +rtPhyInfo_t rtPhyInfo[] = {
4634 + {phyAlive: FALSE, /* PHY 0 */
4635 + phyBase: 0, /* filled in by rt_phySetup */
4636 + phyAddr: ETH_PHY_ADDR},
4638 + {phyAlive: FALSE, /* PHY 1 */
4639 + phyBase: 0, /* filled in by rt_phySetup */
4640 + phyAddr: ETH_PHY_ADDR}
4643 +/* Convert from phy unit# to (phyBase, phyAddr) pair */
4644 +#define RT_PHYBASE(phyUnit) (rtPhyInfo[phyUnit].phyBase)
4645 +#define RT_PHYADDR(phyUnit) (rtPhyInfo[phyUnit].phyAddr)
4648 +/******************************************************************************
4650 +* rt_phySetup - reset and setup the PHY associated with
4651 +* the specified MAC unit number.
4653 +* Resets the associated PHY port.
4656 +* TRUE --> associated PHY is alive
4657 +* FALSE --> no LINKs on this ethernet unit
4661 +rt_phySetup(int ethUnit, UINT32 phyBase)
4663 + BOOL linkAlive = FALSE;
4666 + RT_PHYBASE(ethUnit) = phyBase;
4668 + phyAddr = RT_PHYADDR(ethUnit);
4671 + phyRegWrite(phyBase, phyAddr, GEN_ctl, PHY_SW_RST | AUTONEGENA);
4678 +/******************************************************************************
4680 +* rt_phyIsDuplexFull - Determines whether the phy ports associated with the
4681 +* specified device are FULL or HALF duplex.
4688 +rt_phyIsFullDuplex(int ethUnit)
4694 + phyBase = RT_PHYBASE(ethUnit);
4695 + phyAddr = RT_PHYADDR(ethUnit);
4697 + phyCtl = phyRegRead(phyBase, phyAddr, GEN_ctl);
4699 + if (phyCtl & DUPLEX) {
4706 +/******************************************************************************
4708 +* rt_phyIsSpeed100 - Determines the speed of phy ports associated with the
4709 +* specified device.
4716 +rt_phyIsSpeed100(int phyUnit)
4722 + phyBase = RT_PHYBASE(phyUnit);
4723 + phyAddr = RT_PHYADDR(phyUnit);
4725 + phyLpa = phyRegRead(phyBase, phyAddr, AN_lpa);
4727 + if (phyLpa & (LPA_TXFD | LPA_TX)) {
4734 +/*****************************************************************************
4736 +* rt_phyCheckStatusChange -- checks for significant changes in PHY state.
4738 +* A "significant change" is:
4739 +* dropped link (e.g. ethernet cable unplugged) OR
4740 +* autonegotiation completed + link (e.g. ethernet cable plugged in)
4742 +* On AR5311, there is a 1-to-1 mapping of ethernet units to PHYs.
4743 +* When a PHY is plugged in, phyLinkGained is called.
4744 +* When a PHY is unplugged, phyLinkLost is called.
4747 +rt_phyCheckStatusChange(int ethUnit)
4749 + UINT16 phyHwStatus;
4750 + rtPhyInfo_t *lastStatus = &rtPhyInfo[ethUnit];
4754 + phyBase = RT_PHYBASE(ethUnit);
4755 + phyAddr = RT_PHYADDR(ethUnit);
4757 + phyHwStatus = phyRegRead(phyBase, phyAddr, GEN_sts);
4759 + if (lastStatus->phyAlive) { /* last known status was ALIVE */
4760 + /* See if we've lost link */
4761 + if (!(phyHwStatus & LINK)) {
4762 + RT_PRINT(RT_DEBUG_PHYCHANGE,("\nethmac%d link down\n", ethUnit));
4763 + lastStatus->phyAlive = FALSE;
4764 + phyLinkLost(ethUnit);
4766 + } else { /* last known status was DEAD */
4767 + /* Check for AN complete */
4768 + if ((phyHwStatus & (AUTOCMPLT | LINK)) == (AUTOCMPLT | LINK)) {
4769 + RT_PRINT(RT_DEBUG_PHYCHANGE,("\nethmac%d link up\n", ethUnit));
4770 + lastStatus->phyAlive = TRUE;
4771 + phyLinkGained(ethUnit);
4778 +/* Define the PHY registers of interest for a phyShow command */
4779 +struct rtRegisterTable_s {
4781 + char *regIdString;
4782 +} rtRegisterTable[] =
4784 + {GEN_ctl, "Basic Mode Control (GEN_ctl) "},
4785 + {GEN_sts, "Basic Mode Status (GEN_sts) "},
4786 + {GEN_id_hi, "PHY Identifier 1 (GET_id_hi) "},
4787 + {GEN_id_lo, "PHY Identifier 2 (GET_id_lo) "},
4788 + {AN_adv, "Auto-Neg Advertisement (AN_adv) "},
4789 + {AN_lpa, "Auto-Neg Link Partner Ability "},
4790 + {AN_exp, "Auto-Neg Expansion "},
4793 +int rtNumRegs = sizeof(rtRegisterTable) / sizeof(rtRegisterTable[0]);
4796 + * Dump the state of a PHY.
4799 +rt_phyShow(int phyUnit)
4806 + phyBase = RT_PHYBASE(phyUnit);
4807 + phyAddr = RT_PHYADDR(phyUnit);
4809 + printf("PHY state for ethphy%d\n", phyUnit);
4811 + for (i=0; i<rtNumRegs; i++) {
4813 + value = phyRegRead(phyBase, phyAddr, rtRegisterTable[i].regNum);
4815 + printf("Reg %02d (0x%02x) %s = 0x%08x\n",
4816 + rtRegisterTable[i].regNum, rtRegisterTable[i].regNum,
4817 + rtRegisterTable[i].regIdString, value);
4822 + * Modify the value of a PHY register.
4823 + * This makes it a bit easier to modify PHY values during debug.
4826 +rt_phySet(int phyUnit, UINT32 regnum, UINT32 value)
4831 + phyBase = RT_PHYBASE(phyUnit);
4832 + phyAddr = RT_PHYADDR(phyUnit);
4834 + phyRegWrite(phyBase, phyAddr, regnum, value);
4837 diff -urN linux-2.4.32.new/arch/mips/ar531x/rtPhy.h linux-2.4.32.new-eth/arch/mips/ar531x/rtPhy.h
4838 --- linux-2.4.32.new/arch/mips/ar531x/rtPhy.h 1970-01-01 01:00:00.000000000 +0100
4839 +++ linux-2.4.32.new-eth/arch/mips/ar531x/rtPhy.h 2005-12-25 11:54:46.089422728 +0000
4842 + * This file is subject to the terms and conditions of the GNU General Public
4843 + * License. See the file "COPYING" in the main directory of this archive
4844 + * for more details.
4846 + * Copyright © 2003 Atheros Communications, Inc., All Rights Reserved.
4850 + * rtPhy.h - definitions for the ethernet PHY.
4851 + * This code supports a simple 1-port ethernet phy, Realtek RTL8201BL,
4852 + * and compatible PHYs, such as the Kendin KS8721B.
4853 + * All definitions in this file are operating system independent!
4859 +/* MII Registers */
4863 +#define GEN_id_hi 02
4864 +#define GEN_id_lo 03
4870 +#define PHY_SW_RST 0x8000
4871 +#define LOOPBACK 0x4000
4872 +#define SPEED 0x2000 /* 100 Mbit/s */
4873 +#define AUTONEGENA 0x1000
4874 +#define DUPLEX 0x0100 /* Duplex mode */
4878 +#define AUTOCMPLT 0x0020 /* Autonegotiation completed */
4879 +#define LINK 0x0004 /* Link status */
4882 +#define RT_PHY_ID1_EXPECTATION 0x22
4885 +#define LPA_TXFD 0x0100 /* Link partner supports 100 TX Full Duplex */
4886 +#define LPA_TX 0x0080 /* Link partner supports 100 TX Half Duplex */
4887 +#define LPA_10FD 0x0040 /* Link partner supports 10 BT Full Duplex */
4888 +#define LPA_10 0x0020 /* Link partner supports 10 BT Half Duplex */
4890 +#endif /* RTPHY_H */