/*
 * Broadcom BCM570x Ethernet Driver for U-Boot.
 * Support 5701, 5702, 5703, and 5704. Single instance driver.
 * Copyright (C) 2002 James F. Dougherty (jfd@broadcom.com)
 */

#include <common.h>

#if ((CONFIG_COMMANDS & CFG_CMD_NET) || defined(CONFIG_CMD_NET)) \
	&& (!defined(CONFIG_NET_MULTI)) && defined(CONFIG_BCM570x)

#ifdef CONFIG_BMW
#include <mpc824x.h>
#endif
#include <net.h>
#include "bcm570x_mm.h"
#include "bcm570x_autoneg.h"
#include <pci.h>
#include <malloc.h>


/*
 * PCI Registers and definitions.
 */
#define PCI_CMD_MASK	0xffff0000	/* mask to save status bits */
#define PCI_ANY_ID (~0)

/*
 * PCI memory base for Ethernet device as well as device Interrupt.
 */
#define BCM570X_MBAR 	0x80100000
#define BCM570X_ILINE   1


#define SECOND_USEC	1000000
#define MAX_PACKET_SIZE 1600
#define MAX_UNITS       4

/* Globals to this module */
int initialized = 0;
unsigned int ioBase = 0;
volatile PLM_DEVICE_BLOCK    pDevice = NULL;        /* 570x softc */
volatile PUM_DEVICE_BLOCK    pUmDevice = NULL;

/* Used to pass the full-duplex flag, etc. */
int line_speed[MAX_UNITS] = {0,0,0,0};
static int full_duplex[MAX_UNITS] = {1,1,1,1};
static int rx_flow_control[MAX_UNITS] = {0,0,0,0};
static int tx_flow_control[MAX_UNITS] = {0,0,0,0};
static int auto_flow_control[MAX_UNITS] = {0,0,0,0};
static int tx_checksum[MAX_UNITS] = {1,1,1,1};
static int rx_checksum[MAX_UNITS] = {1,1,1,1};
static int auto_speed[MAX_UNITS] = {1,1,1,1};

#if JUMBO_FRAMES
/* Jumbo MTU for interfaces. */
static int mtu[MAX_UNITS] = {0,0,0,0};
#endif

/* Turn on Wake-on lan for a device unit */
static int enable_wol[MAX_UNITS] = {0,0,0,0};

#define TX_DESC_CNT DEFAULT_TX_PACKET_DESC_COUNT
static unsigned int tx_pkt_desc_cnt[MAX_UNITS] =
	{TX_DESC_CNT,TX_DESC_CNT,TX_DESC_CNT, TX_DESC_CNT};

#define RX_DESC_CNT DEFAULT_STD_RCV_DESC_COUNT
static unsigned int rx_std_desc_cnt[MAX_UNITS] =
	{RX_DESC_CNT,RX_DESC_CNT,RX_DESC_CNT,RX_DESC_CNT};

static unsigned int rx_adaptive_coalesce[MAX_UNITS] = {1,1,1,1};

#if T3_JUMBO_RCV_RCB_ENTRY_COUNT
#define JBO_DESC_CNT DEFAULT_JUMBO_RCV_DESC_COUNT
static unsigned int rx_jumbo_desc_cnt[MAX_UNITS] =
	{JBO_DESC_CNT, JBO_DESC_CNT, JBO_DESC_CNT, JBO_DESC_CNT};
#endif
#define RX_COAL_TK DEFAULT_RX_COALESCING_TICKS
static unsigned int rx_coalesce_ticks[MAX_UNITS] =
	{RX_COAL_TK, RX_COAL_TK, RX_COAL_TK, RX_COAL_TK};

#define RX_COAL_FM DEFAULT_RX_MAX_COALESCED_FRAMES
static unsigned int rx_max_coalesce_frames[MAX_UNITS] =
	{RX_COAL_FM, RX_COAL_FM, RX_COAL_FM, RX_COAL_FM};

#define TX_COAL_TK DEFAULT_TX_COALESCING_TICKS
static unsigned int tx_coalesce_ticks[MAX_UNITS] =
	{TX_COAL_TK, TX_COAL_TK, TX_COAL_TK, TX_COAL_TK};

#define TX_COAL_FM DEFAULT_TX_MAX_COALESCED_FRAMES
static unsigned int tx_max_coalesce_frames[MAX_UNITS] =
	{TX_COAL_FM, TX_COAL_FM, TX_COAL_FM, TX_COAL_FM};

#define ST_COAL_TK DEFAULT_STATS_COALESCING_TICKS
static unsigned int stats_coalesce_ticks[MAX_UNITS] =
	{ST_COAL_TK, ST_COAL_TK, ST_COAL_TK, ST_COAL_TK};


/*
 * Legitimate values for BCM570x device types
 */
typedef enum {
	BCM5700VIGIL = 0,
	BCM5700A6,
	BCM5700T6,
	BCM5700A9,
	BCM5700T9,
	BCM5700,
	BCM5701A5,
	BCM5701T1,
	BCM5701T8,
	BCM5701A7,
	BCM5701A10,
	BCM5701A12,
	BCM5701,
	BCM5702,
	BCM5703,
	BCM5703A31,
	TC996T,
	TC996ST,
	TC996SSX,
	TC996SX,
	TC996BT,
	TC997T,
	TC997SX,
	TC1000T,
	TC940BR01,
	TC942BR01,
	NC6770,
	NC7760,
	NC7770,
	NC7780
} board_t;

/* Chip-Rev names for each device-type */
static struct {
    char* name;
} chip_rev[] = {
       {"BCM5700VIGIL"},
       {"BCM5700A6"},
       {"BCM5700T6"},
       {"BCM5700A9"},
       {"BCM5700T9"},
       {"BCM5700"},
       {"BCM5701A5"},
       {"BCM5701T1"},
       {"BCM5701T8"},
       {"BCM5701A7"},
       {"BCM5701A10"},
       {"BCM5701A12"},
       {"BCM5701"},
       {"BCM5702"},
       {"BCM5703"},
       {"BCM5703A31"},
       {"TC996T"},
       {"TC996ST"},
       {"TC996SSX"},
       {"TC996SX"},
       {"TC996BT"},
       {"TC997T"},
       {"TC997SX"},
       {"TC1000T"},
       {"TC940BR01"},
       {"TC942BR01"},
       {"NC6770"},
       {"NC7760"},
       {"NC7770"},
       {"NC7780"},
       {0}
};


/* indexed by board_t, above */
static struct {
    char *name;
} board_info[] = {
	{ "Broadcom Vigil B5700 1000Base-T" },
	{ "Broadcom BCM5700 1000Base-T" },
	{ "Broadcom BCM5700 1000Base-SX" },
	{ "Broadcom BCM5700 1000Base-SX" },
	{ "Broadcom BCM5700 1000Base-T" },
	{ "Broadcom BCM5700" },
	{ "Broadcom BCM5701 1000Base-T" },
	{ "Broadcom BCM5701 1000Base-T" },
	{ "Broadcom BCM5701 1000Base-T" },
	{ "Broadcom BCM5701 1000Base-SX" },
	{ "Broadcom BCM5701 1000Base-T" },
	{ "Broadcom BCM5701 1000Base-T" },
	{ "Broadcom BCM5701" },
	{ "Broadcom BCM5702 1000Base-T" },
	{ "Broadcom BCM5703 1000Base-T" },
	{ "Broadcom BCM5703 1000Base-SX" },
	{ "3Com 3C996 10/100/1000 Server NIC" },
	{ "3Com 3C996 10/100/1000 Server NIC" },
	{ "3Com 3C996 Gigabit Fiber-SX Server NIC" },
	{ "3Com 3C996 Gigabit Fiber-SX Server NIC" },
	{ "3Com 3C996B Gigabit Server NIC" },
	{ "3Com 3C997 Gigabit Server NIC" },
	{ "3Com 3C997 Gigabit Fiber-SX Server NIC" },
	{ "3Com 3C1000 Gigabit NIC" },
	{ "3Com 3C940 Gigabit LOM (21X21)" },
	{ "3Com 3C942 Gigabit LOM (31X31)" },
	{ "Compaq NC6770 Gigabit Server Adapter" },
	{ "Compaq NC7760 Gigabit Server Adapter" },
	{ "Compaq NC7770 Gigabit Server Adapter" },
	{ "Compaq NC7780 Gigabit Server Adapter" },
	{ 0 },
};

/* PCI Devices which use the 570x chipset */
struct pci_device_table {
    unsigned short vendor_id, device_id; /* Vendor/DeviceID */
    unsigned short subvendor, subdevice; /* Subsystem ID's or PCI_ANY_ID */
    unsigned int class, class_mask; /* (class,subclass,prog-if) triplet */
    unsigned long board_id;	    /* Data private to the driver */
    int io_size, min_latency;
} bcm570xDevices[] = {
	{0x14e4, 0x1644, 0x1014, 0x0277, 0, 0, BCM5700VIGIL ,128,32},
	{0x14e4, 0x1644, 0x14e4, 0x1644, 0, 0, BCM5700A6 ,128,32},
	{0x14e4, 0x1644, 0x14e4, 0x2, 0, 0, BCM5700T6 ,128,32},
	{0x14e4, 0x1644, 0x14e4, 0x3, 0, 0, BCM5700A9 ,128,32},
	{0x14e4, 0x1644, 0x14e4, 0x4, 0, 0, BCM5700T9 ,128,32},
	{0x14e4, 0x1644, 0x1028, 0xd1, 0, 0, BCM5700 ,128,32},
	{0x14e4, 0x1644, 0x1028, 0x0106, 0, 0, BCM5700 ,128,32},
	{0x14e4, 0x1644, 0x1028, 0x0109, 0, 0, BCM5700 ,128,32},
	{0x14e4, 0x1644, 0x1028, 0x010a, 0, 0, BCM5700 ,128,32},
	{0x14e4, 0x1644, 0x10b7, 0x1000, 0, 0, TC996T ,128,32},
	{0x14e4, 0x1644, 0x10b7, 0x1001, 0, 0, TC996ST ,128,32},
	{0x14e4, 0x1644, 0x10b7, 0x1002, 0, 0, TC996SSX ,128,32},
	{0x14e4, 0x1644, 0x10b7, 0x1003, 0, 0, TC997T ,128,32},
	{0x14e4, 0x1644, 0x10b7, 0x1005, 0, 0, TC997SX ,128,32},
	{0x14e4, 0x1644, 0x10b7, 0x1008, 0, 0, TC942BR01 ,128,32},
	{0x14e4, 0x1644, PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5700 ,128,32},
	{0x14e4, 0x1645, 0x14e4, 1, 0, 0, BCM5701A5 ,128,32},
	{0x14e4, 0x1645, 0x14e4, 5, 0, 0, BCM5701T1 ,128,32},
	{0x14e4, 0x1645, 0x14e4, 6, 0, 0, BCM5701T8 ,128,32},
	{0x14e4, 0x1645, 0x14e4, 7, 0, 0, BCM5701A7 ,128,32},
	{0x14e4, 0x1645, 0x14e4, 8, 0, 0, BCM5701A10 ,128,32},
	{0x14e4, 0x1645, 0x14e4, 0x8008, 0, 0, BCM5701A12 ,128,32},
	{0x14e4, 0x1645, 0x0e11, 0xc1, 0, 0, NC6770 ,128,32},
	{0x14e4, 0x1645, 0x0e11, 0x7c, 0, 0, NC7770 ,128,32},
	{0x14e4, 0x1645, 0x0e11, 0x85, 0, 0, NC7780 ,128,32},
	{0x14e4, 0x1645, 0x1028, 0x0121, 0, 0, BCM5701 ,128,32},
	{0x14e4, 0x1645, 0x10b7, 0x1004, 0, 0, TC996SX ,128,32},
	{0x14e4, 0x1645, 0x10b7, 0x1006, 0, 0, TC996BT ,128,32},
	{0x14e4, 0x1645, 0x10b7, 0x1007, 0, 0, TC1000T ,128,32},
	{0x14e4, 0x1645, 0x10b7, 0x1008, 0, 0, TC940BR01 ,128,32},
	{0x14e4, 0x1645, PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5701 ,128,32},
	{0x14e4, 0x1646, 0x14e4, 0x8009, 0, 0, BCM5702 ,128,32},
	{0x14e4, 0x1646, 0x0e11, 0xbb, 0, 0, NC7760 ,128,32},
	{0x14e4, 0x1646, PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5702 ,128,32},
	{0x14e4, 0x16a6, 0x14e4, 0x8009, 0, 0, BCM5702 ,128,32},
	{0x14e4, 0x16a6, 0x0e11, 0xbb, 0, 0, NC7760 ,128,32},
	{0x14e4, 0x16a6, PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5702 ,128,32},
	{0x14e4, 0x1647, 0x14e4, 0x0009, 0, 0, BCM5703 ,128,32},
	{0x14e4, 0x1647, 0x14e4, 0x000a, 0, 0, BCM5703A31 ,128,32},
	{0x14e4, 0x1647, 0x14e4, 0x000b, 0, 0, BCM5703 ,128,32},
	{0x14e4, 0x1647, 0x14e4, 0x800a, 0, 0, BCM5703 ,128,32},
	{0x14e4, 0x1647, 0x0e11, 0x9a, 0, 0, NC7770 ,128,32},
	{0x14e4, 0x1647, 0x0e11, 0x99, 0, 0, NC7780 ,128,32},
	{0x14e4, 0x1647, PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5703 ,128,32},
	{0x14e4, 0x16a7, 0x14e4, 0x0009, 0, 0, BCM5703 ,128,32},
	{0x14e4, 0x16a7, 0x14e4, 0x000a, 0, 0, BCM5703A31 ,128,32},
	{0x14e4, 0x16a7, 0x14e4, 0x000b, 0, 0, BCM5703 ,128,32},
	{0x14e4, 0x16a7, 0x14e4, 0x800a, 0, 0, BCM5703 ,128,32},
	{0x14e4, 0x16a7, 0x0e11, 0x9a, 0, 0, NC7770 ,128,32},
	{0x14e4, 0x16a7, 0x0e11, 0x99, 0, 0, NC7780 ,128,32},
	{0x14e4, 0x16a7, PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5703 ,128,32}
};

#define n570xDevices   (sizeof(bcm570xDevices)/sizeof(bcm570xDevices[0]))


/*
 * Allocate a packet buffer from the bcm570x packet pool.
 */
void *
bcm570xPktAlloc(int u, int pksize)
{
    return malloc(pksize);
}

/*
 * Free a packet previously allocated from the bcm570x packet
 * buffer pool.
 */
void
bcm570xPktFree(int u, void *p)
{
    free(p);
}

int
bcm570xReplenishRxBuffers(PUM_DEVICE_BLOCK pUmDevice)
{
    PLM_PACKET pPacket;
    PUM_PACKET pUmPacket;
    void *skb;
    int queue_rx = 0;
    int ret = 0;

    while ((pUmPacket = (PUM_PACKET)
	    QQ_PopHead(&pUmDevice->rx_out_of_buf_q.Container)) != 0) {

	pPacket = (PLM_PACKET) pUmPacket;

	/* reuse an old skb */
	if (pUmPacket->skbuff) {
	    QQ_PushTail(&pDevice->RxPacketFreeQ.Container, pPacket);
	    queue_rx = 1;
	    continue;
	}
	if ( ( skb = bcm570xPktAlloc(pUmDevice->index,
				     pPacket->u.Rx.RxBufferSize + 2)) == 0) {
	    QQ_PushHead(&pUmDevice->rx_out_of_buf_q.Container,pPacket);
	    printf("NOTICE: Out of RX memory.\n");
	    ret = 1;
	    break;
	}

	pUmPacket->skbuff = skb;
	QQ_PushTail(&pDevice->RxPacketFreeQ.Container, pPacket);
	queue_rx = 1;
    }

    if (queue_rx) {
	LM_QueueRxPackets(pDevice);
    }

    return ret;
}

/*
 * Probe, Map, and Init 570x device.
 */
int eth_init(bd_t *bis)
{
    int i, rv, devFound = FALSE;
    pci_dev_t  devbusfn;
    unsigned short status;

    /* Find PCI device, if it exists, configure ...  */
    for( i = 0; i < n570xDevices; i++){
	devbusfn = pci_find_device(bcm570xDevices[i].vendor_id,
				   bcm570xDevices[i].device_id, 0);
	if(devbusfn == -1) {
	    continue; /* No device of that vendor/device ID */
	} else {

	    /* Set ILINE */
	    pci_write_config_byte(devbusfn,
				  PCI_INTERRUPT_LINE, BCM570X_ILINE);

	    /*
	     * 0x10 - 0x14 define one 64-bit MBAR.
	     * 0x14 is the higher-order address bits of the BAR.
	     */
	    pci_write_config_dword(devbusfn,
				   PCI_BASE_ADDRESS_1, 0);

	    ioBase = BCM570X_MBAR;

	    pci_write_config_dword(devbusfn,
				   PCI_BASE_ADDRESS_0, ioBase);

	    /*
	     * Enable PCI memory, IO, and Master -- don't
	     * reset any status bits in doing so.
	     */
	    pci_read_config_word(devbusfn,
				 PCI_COMMAND, &status);

	    status |= PCI_COMMAND_MEMORY|PCI_COMMAND_MASTER;

	    pci_write_config_word(devbusfn,
				  PCI_COMMAND, status);

	    printf("\n%s: bus %d, device %d, function %d: MBAR=0x%x\n",
		   board_info[bcm570xDevices[i].board_id].name,
		   PCI_BUS(devbusfn),
		   PCI_DEV(devbusfn),
		   PCI_FUNC(devbusfn),
		   ioBase);

	    /* Allocate once, but always clear on init */
	    if (!pDevice) {
		pDevice = malloc(sizeof(UM_DEVICE_BLOCK));
		pUmDevice = (PUM_DEVICE_BLOCK)pDevice;
		memset(pDevice, 0x0, sizeof(UM_DEVICE_BLOCK));
	    }

	    /* Configure pci dev structure */
	    pUmDevice->pdev = devbusfn;
	    pUmDevice->index = 0;
	    pUmDevice->tx_pkt = 0;
	    pUmDevice->rx_pkt = 0;
	    devFound = TRUE;
	    break;
	}
    }

    if(!devFound){
	printf("eth_init: FAILURE: no BCM570x Ethernet devices found.\n");
	return -1;
    }

    /* Setup defaults for chip */
    pDevice->TaskToOffload = LM_TASK_OFFLOAD_NONE;

    if (pDevice->ChipRevId == T3_CHIP_ID_5700_B0) {
	pDevice->TaskToOffload = LM_TASK_OFFLOAD_NONE;
    } else {

	if (rx_checksum[i]) {
	    pDevice->TaskToOffload |=
		LM_TASK_OFFLOAD_RX_TCP_CHECKSUM |
		LM_TASK_OFFLOAD_RX_UDP_CHECKSUM;
	}

	if (tx_checksum[i]) {
	    pDevice->TaskToOffload |=
		LM_TASK_OFFLOAD_TX_TCP_CHECKSUM |
		LM_TASK_OFFLOAD_TX_UDP_CHECKSUM;
	    pDevice->NoTxPseudoHdrChksum = TRUE;
	}
    }

    /* Set Device PCI Memory base address */
    pDevice->pMappedMemBase = (PLM_UINT8) ioBase;

    /* Pull down adapter info */
    if ((rv = LM_GetAdapterInfo(pDevice)) != LM_STATUS_SUCCESS) {
	printf("bcm570xEnd: LM_GetAdapterInfo failed: rv=%d!\n", rv );
	return -2;
    }

    /* Lock not needed */
    pUmDevice->do_global_lock = 0;

    if (T3_ASIC_REV(pUmDevice->lm_dev.ChipRevId) == T3_ASIC_REV_5700) {
	/* The 5700 chip works best without interleaved register */
	/* accesses on certain machines. */
	pUmDevice->do_global_lock = 1;
    }

    /* Setup timer delays */
    if (T3_ASIC_REV(pDevice->ChipRevId) == T3_ASIC_REV_5701) {
	pDevice->UseTaggedStatus = TRUE;
	pUmDevice->timer_interval = CFG_HZ;
    }
    else {
	pUmDevice->timer_interval = CFG_HZ / 50;
    }

    /* Grab name .... */
    pUmDevice->name =
	(char*)malloc(strlen(board_info[bcm570xDevices[i].board_id].name)+1);
    strcpy(pUmDevice->name,board_info[bcm570xDevices[i].board_id].name);

    memcpy(pDevice->NodeAddress, bis->bi_enetaddr, 6);
    LM_SetMacAddress(pDevice, bis->bi_enetaddr);
    /* Init queues  .. */
    QQ_InitQueue(&pUmDevice->rx_out_of_buf_q.Container,
		 MAX_RX_PACKET_DESC_COUNT);
    pUmDevice->rx_last_cnt = pUmDevice->tx_last_cnt = 0;

    /* delay for 4 seconds */
    pUmDevice->delayed_link_ind =
	(4 * CFG_HZ) / pUmDevice->timer_interval;

    pUmDevice->adaptive_expiry =
	CFG_HZ / pUmDevice->timer_interval;

    /* Sometimes we get spurious ints. after reset when link is down. */
    /* This field tells the isr to service the int. even if there is */
    /* no status block update. */
    pUmDevice->adapter_just_inited =
	(3 * CFG_HZ) / pUmDevice->timer_interval;

    /* Initialize 570x */
    if (LM_InitializeAdapter(pDevice) != LM_STATUS_SUCCESS) {
	printf("ERROR: Adapter initialization failed.\n");
	return ERROR;
    }

    /* Enable chip ISR */
    LM_EnableInterrupt(pDevice);

    /* Clear MC table */
    LM_MulticastClear(pDevice);

    /* Enable Multicast */
    LM_SetReceiveMask(pDevice,
		      pDevice->ReceiveMask | LM_ACCEPT_ALL_MULTICAST);

    pUmDevice->opened = 1;
    pUmDevice->tx_full = 0;
    pUmDevice->tx_pkt = 0;
    pUmDevice->rx_pkt = 0;
    printf("eth%d: %s @0x%lx,",
	   pDevice->index, pUmDevice->name, (unsigned long)ioBase);
    printf(	"node addr ");
    for (i = 0; i < 6; i++) {
	printf("%2.2x", pDevice->NodeAddress[i]);
    }
    printf("\n");

    printf("eth%d: ", pDevice->index);
    printf("%s with ",
	   chip_rev[bcm570xDevices[i].board_id].name);

    if ((pDevice->PhyId & PHY_ID_MASK) == PHY_BCM5400_PHY_ID)
	printf("Broadcom BCM5400 Copper ");
    else if ((pDevice->PhyId & PHY_ID_MASK) == PHY_BCM5401_PHY_ID)
	printf("Broadcom BCM5401 Copper ");
    else if ((pDevice->PhyId & PHY_ID_MASK) == PHY_BCM5411_PHY_ID)
	printf("Broadcom BCM5411 Copper ");
    else if ((pDevice->PhyId & PHY_ID_MASK) == PHY_BCM5701_PHY_ID)
	printf("Broadcom BCM5701 Integrated Copper ");
    else if ((pDevice->PhyId & PHY_ID_MASK) == PHY_BCM5703_PHY_ID)
	printf("Broadcom BCM5703 Integrated Copper ");
    else if ((pDevice->PhyId & PHY_ID_MASK) == PHY_BCM8002_PHY_ID)
	printf("Broadcom BCM8002 SerDes ");
    else if (pDevice->EnableTbi)
	printf("Agilent HDMP-1636 SerDes ");
    else
	printf("Unknown ");
    printf("transceiver found\n");

    printf("eth%d: %s, MTU: %d,",
	   pDevice->index, pDevice->BusSpeedStr, 1500);

    if ((pDevice->ChipRevId != T3_CHIP_ID_5700_B0) &&
	rx_checksum[i])
	printf("Rx Checksum ON\n");
    else
	printf("Rx Checksum OFF\n");
    initialized++;

    return 0;
}

/* Ethernet Interrupt service routine */
void
eth_isr(void)
{
    LM_UINT32 oldtag, newtag;
    int i;

    pUmDevice->interrupt = 1;

    if (pDevice->UseTaggedStatus) {
	if ((pDevice->pStatusBlkVirt->Status & STATUS_BLOCK_UPDATED) ||
	    pUmDevice->adapter_just_inited) {
	    MB_REG_WR(pDevice, Mailbox.Interrupt[0].Low, 1);
	    oldtag = pDevice->pStatusBlkVirt->StatusTag;

	    for (i = 0; ; i++) {
		pDevice->pStatusBlkVirt->Status &= ~STATUS_BLOCK_UPDATED;
		LM_ServiceInterrupts(pDevice);
		newtag = pDevice->pStatusBlkVirt->StatusTag;
		if ((newtag == oldtag) || (i > 50)) {
		    MB_REG_WR(pDevice, Mailbox.Interrupt[0].Low, newtag << 24);
		    if (pDevice->UndiFix) {
			REG_WR(pDevice, Grc.LocalCtrl,
			       pDevice->GrcLocalCtrl | 0x2);
		    }
		    break;
		 }
		oldtag = newtag;
	    }
	}
    }
    else {
	while (pDevice->pStatusBlkVirt->Status & STATUS_BLOCK_UPDATED) {
	    unsigned int dummy;

	    pDevice->pMemView->Mailbox.Interrupt[0].Low = 1;
	    pDevice->pStatusBlkVirt->Status &= ~STATUS_BLOCK_UPDATED;
	    LM_ServiceInterrupts(pDevice);
	    pDevice->pMemView->Mailbox.Interrupt[0].Low = 0;
	    dummy = pDevice->pMemView->Mailbox.Interrupt[0].Low;
	}
    }

    /* Allocate new RX buffers */
    if (QQ_GetEntryCnt(&pUmDevice->rx_out_of_buf_q.Container)) {
	bcm570xReplenishRxBuffers(pUmDevice);
    }

    /* Queue packets */
    if (QQ_GetEntryCnt(&pDevice->RxPacketFreeQ.Container)) {
	LM_QueueRxPackets(pDevice);
    }

    if (pUmDevice->tx_queued) {
	pUmDevice->tx_queued = 0;
    }

    if(pUmDevice->tx_full){
	if(pDevice->LinkStatus != LM_STATUS_LINK_DOWN){
	    printf("NOTICE: tx was previously blocked, restarting MUX\n");
	    pUmDevice->tx_full = 0;
	}
    }

    pUmDevice->interrupt = 0;

}

int
eth_send(volatile void *packet, int length)
{
    int status = 0;
#if ET_DEBUG
    unsigned char* ptr = (unsigned char*)packet;
#endif
    PLM_PACKET pPacket;
    PUM_PACKET pUmPacket;

    /* Link down, return */
    while(pDevice->LinkStatus == LM_STATUS_LINK_DOWN) {
#if 0
	printf("eth%d: link down - check cable or link partner.\n",
	       pUmDevice->index);
#endif
	eth_isr();

	/* Wait to see link for one-half a second before sending ... */
	udelay(1500000);

    }

    /* Clear sent flag */
    pUmDevice->tx_pkt = 0;

    /* Previously blocked */
    if(pUmDevice->tx_full){
	printf("eth%d: tx blocked.\n", pUmDevice->index);
	return 0;
    }

    pPacket = (PLM_PACKET)
	QQ_PopHead(&pDevice->TxPacketFreeQ.Container);

    if (pPacket == 0) {
	pUmDevice->tx_full = 1;
	printf("bcm570xEndSend: TX full!\n");
	return 0;
    }

    if (pDevice->SendBdLeft.counter == 0) {
	pUmDevice->tx_full = 1;
	printf("bcm570xEndSend: no more TX descriptors!\n");
	QQ_PushHead(&pDevice->TxPacketFreeQ.Container, pPacket);
	return 0;
    }

    if (length <= 0){
	printf("eth: bad packet size: %d\n", length);
	goto out;
    }

    /* Get packet buffers and fragment list */
    pUmPacket = (PUM_PACKET) pPacket;
    /* Single DMA Descriptor transmit.
     * Fragments may be provided, but one DMA descriptor max is
     * used to send the packet.
     */
    if (MM_CoalesceTxBuffer (pDevice, pPacket) != LM_STATUS_SUCCESS) {
	if (pUmPacket->skbuff == NULL){
	    /* Packet was discarded */
	    printf("TX: failed (1)\n");
	    status = 1;
	} else{
	    printf("TX: failed (2)\n");
	    status = 2;
	}
	QQ_PushHead (&pDevice->TxPacketFreeQ.Container, pPacket);
	return status;
    }

    /* Copy packet to DMA buffer */
    memset(pUmPacket->skbuff, 0x0, MAX_PACKET_SIZE);
    memcpy((void*)pUmPacket->skbuff, (void*)packet, length);
    pPacket->PacketSize = length;
    pPacket->Flags |= SND_BD_FLAG_END|SND_BD_FLAG_COAL_NOW;
    pPacket->u.Tx.FragCount = 1;
    /* We've already provided a frame ready for transmission */
    pPacket->Flags &= ~SND_BD_FLAG_TCP_UDP_CKSUM;

    if ( LM_SendPacket(pDevice, pPacket) == LM_STATUS_FAILURE){
	/*
	 *  A lower level send failure will push the packet descriptor back
	 *  in the free queue, so just deal with the VxWorks clusters.
	 */
	if (pUmPacket->skbuff == NULL){
	    printf("TX failed (1)!\n");
	    /* Packet was discarded */
	    status = 3;
	} else {
	    /* A resource problem ... */
	    printf("TX failed (2)!\n");
	    status = 4;
	}

	if (QQ_GetEntryCnt(&pDevice->TxPacketFreeQ.Container) == 0) {
	    printf("TX: emptyQ!\n");
	    pUmDevice->tx_full = 1;
	}
    }

    while(pUmDevice->tx_pkt == 0){
	/* Service TX */
	eth_isr();
    }
#if ET_DEBUG
    printf("eth_send: 0x%x, %d bytes\n"
	   "[%x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x] ...\n",
	   (int)pPacket, length,
	   ptr[0],ptr[1],ptr[2],ptr[3],ptr[4],ptr[5],
	   ptr[6],ptr[7],ptr[8],ptr[9],ptr[10],ptr[11],ptr[12],
	   ptr[13],ptr[14],ptr[15]);
#endif
    pUmDevice->tx_pkt = 0;
    QQ_PushHead(&pDevice->TxPacketFreeQ.Container, pPacket);

    /* Done with send */
 out:
    return status;
}


/* Ethernet receive */
int
eth_rx(void)
{
    PLM_PACKET          pPacket = NULL;
    PUM_PACKET          pUmPacket = NULL;
    void *skb;
    int size=0;

    while(TRUE) {

    bcm570x_service_isr:
	/* Pull down packet if it is there */
	eth_isr();

	/* Indicate RX packets called */
	if(pUmDevice->rx_pkt){
	    /* printf("eth_rx: got a packet...\n"); */
	    pUmDevice->rx_pkt = 0;
	} else {
	    /* printf("eth_rx: waiting for packet...\n"); */
	    goto bcm570x_service_isr;
	}

	pPacket = (PLM_PACKET)
	    QQ_PopHead(&pDevice->RxPacketReceivedQ.Container);

	if (pPacket == 0){
	    printf("eth_rx: empty packet!\n");
	    goto bcm570x_service_isr;
	}

	pUmPacket = (PUM_PACKET) pPacket;
#if ET_DEBUG
	printf("eth_rx: packet @0x%x\n",
	       (int)pPacket);
#endif
	/* If the packet generated an error, reuse buffer */
	if ((pPacket->PacketStatus != LM_STATUS_SUCCESS) ||
	    ((size = pPacket->PacketSize) > pDevice->RxMtu)) {

	    /* reuse skb */
	    QQ_PushTail(&pDevice->RxPacketFreeQ.Container, pPacket);
	    printf("eth_rx: error in packet dma!\n");
	    goto bcm570x_service_isr;
	}

	/* Set size and address */
	skb = pUmPacket->skbuff;
	size = pPacket->PacketSize;

	/* Pass the packet up to the protocol
	 * layers.
	 */
	NetReceive(skb, size);

	/* Free packet buffer */
	bcm570xPktFree (pUmDevice->index, skb);
	pUmPacket->skbuff = NULL;

	/* Reuse SKB */
	QQ_PushTail(&pDevice->RxPacketFreeQ.Container, pPacket);

	return 0; /* Got a packet, bail ... */
    }
    return size;
}


/* Shut down device */
void
eth_halt(void)
{
    int i;
    if ( initialized)
    if (pDevice && pUmDevice && pUmDevice->opened){
	printf("\neth%d:%s,", pUmDevice->index, pUmDevice->name);
	printf("HALT,");
	/* stop device */
	LM_Halt(pDevice);
	printf("POWER DOWN,");
	LM_SetPowerState(pDevice, LM_POWER_STATE_D3);

	/* Free the memory allocated by the device in tigon3 */
	for (i = 0; i < pUmDevice->mem_list_num; i++)  {
	    if (pUmDevice->mem_list[i])  {
		/* sanity check */
		if (pUmDevice->dma_list[i]) {  /* cache-safe memory */
		    free(pUmDevice->mem_list[i]);
		} else {
		    free(pUmDevice->mem_list[i]);  /* normal memory   */
		}
	    }
	}
	pUmDevice->opened = 0;
	free(pDevice);
	pDevice = NULL;
	pUmDevice = NULL;
	initialized = 0;
	printf("done - offline.\n");
    }
}


/*
 *
 * Middle Module: Interface between the HW driver (tigon3 modules) and
 * the native (SENS) driver.  These routines implement the system
 * interface for tigon3 on VxWorks.
 */

/* Middle module dependency - size of a packet descriptor */
int MM_Packet_Desc_Size = sizeof(UM_PACKET);


LM_STATUS
MM_ReadConfig32(PLM_DEVICE_BLOCK pDevice,
		LM_UINT32 Offset,
		LM_UINT32 *pValue32)
{
    UM_DEVICE_BLOCK *pUmDevice;
    pUmDevice = (UM_DEVICE_BLOCK *) pDevice;
    pci_read_config_dword(pUmDevice->pdev,
			  Offset, (u32 *) pValue32);
    return LM_STATUS_SUCCESS;
}


LM_STATUS
MM_WriteConfig32(PLM_DEVICE_BLOCK pDevice,
		 LM_UINT32 Offset,
		 LM_UINT32 Value32)
{
    UM_DEVICE_BLOCK *pUmDevice;
    pUmDevice = (UM_DEVICE_BLOCK *) pDevice;
    pci_write_config_dword(pUmDevice->pdev,
			   Offset, Value32);
    return LM_STATUS_SUCCESS;
}


LM_STATUS
MM_ReadConfig16(PLM_DEVICE_BLOCK pDevice,
		LM_UINT32 Offset,
		LM_UINT16 *pValue16)
{
    UM_DEVICE_BLOCK *pUmDevice;
    pUmDevice = (UM_DEVICE_BLOCK *) pDevice;
    pci_read_config_word(pUmDevice->pdev,
			 Offset, (u16*) pValue16);
    return LM_STATUS_SUCCESS;
}

LM_STATUS
MM_WriteConfig16(PLM_DEVICE_BLOCK pDevice,
		 LM_UINT32 Offset,
		 LM_UINT16 Value16)
{
    UM_DEVICE_BLOCK *pUmDevice;
    pUmDevice = (UM_DEVICE_BLOCK *) pDevice;
    pci_write_config_word(pUmDevice->pdev,
			  Offset, Value16);
    return LM_STATUS_SUCCESS;
}


LM_STATUS
MM_AllocateSharedMemory(PLM_DEVICE_BLOCK pDevice, LM_UINT32 BlockSize,
			PLM_VOID *pMemoryBlockVirt,
			PLM_PHYSICAL_ADDRESS pMemoryBlockPhy,
			LM_BOOL Cached)
{
    PLM_VOID pvirt;
    PUM_DEVICE_BLOCK pUmDevice = (PUM_DEVICE_BLOCK) pDevice;
    dma_addr_t mapping;

    pvirt = malloc(BlockSize);
    mapping = (dma_addr_t)(pvirt);
    if (!pvirt)
	return LM_STATUS_FAILURE;

    pUmDevice->mem_list[pUmDevice->mem_list_num] = pvirt;
    pUmDevice->dma_list[pUmDevice->mem_list_num] = mapping;
    pUmDevice->mem_size_list[pUmDevice->mem_list_num++] = BlockSize;
    memset(pvirt, 0, BlockSize);

    *pMemoryBlockVirt = (PLM_VOID) pvirt;
    MM_SetAddr (pMemoryBlockPhy, (dma_addr_t) mapping);

    return LM_STATUS_SUCCESS;
}


LM_STATUS
MM_AllocateMemory(PLM_DEVICE_BLOCK pDevice, LM_UINT32 BlockSize,
	PLM_VOID *pMemoryBlockVirt)
{
    PLM_VOID pvirt;
    PUM_DEVICE_BLOCK pUmDevice = (PUM_DEVICE_BLOCK) pDevice;

    pvirt = malloc(BlockSize);

    if (!pvirt)
	return LM_STATUS_FAILURE;

    pUmDevice->mem_list[pUmDevice->mem_list_num] = pvirt;
    pUmDevice->dma_list[pUmDevice->mem_list_num] = 0;
    pUmDevice->mem_size_list[pUmDevice->mem_list_num++] = BlockSize;
    memset(pvirt, 0, BlockSize);
    *pMemoryBlockVirt = pvirt;

    return LM_STATUS_SUCCESS;
}

LM_STATUS
MM_MapMemBase(PLM_DEVICE_BLOCK pDevice)
{
    printf("BCM570x PCI Memory base address @0x%x\n",
	   (unsigned int)pDevice->pMappedMemBase);
    return LM_STATUS_SUCCESS;
}

LM_STATUS
MM_InitializeUmPackets(PLM_DEVICE_BLOCK pDevice)
{
    int i;
    void* skb;
    PUM_DEVICE_BLOCK pUmDevice = (PUM_DEVICE_BLOCK) pDevice;
    PUM_PACKET pUmPacket = NULL;
    PLM_PACKET pPacket = NULL;

    for (i = 0; i < pDevice->RxPacketDescCnt; i++) {
	pPacket = QQ_PopHead(&pDevice->RxPacketFreeQ.Container);
	pUmPacket = (PUM_PACKET) pPacket;

	if (pPacket == 0) {
	    printf("MM_InitializeUmPackets: Bad RxPacketFreeQ\n");
	}

	skb = bcm570xPktAlloc(pUmDevice->index,
			      pPacket->u.Rx.RxBufferSize + 2);

	if (skb == 0) {
	    pUmPacket->skbuff = 0;
	    QQ_PushTail(&pUmDevice->rx_out_of_buf_q.Container, pPacket);
	    printf("MM_InitializeUmPackets: out of buffer.\n");
	    continue;
	}

	pUmPacket->skbuff = skb;
	QQ_PushTail(&pDevice->RxPacketFreeQ.Container, pPacket);
    }

    pUmDevice->rx_low_buf_thresh = pDevice->RxPacketDescCnt / 8;

    return LM_STATUS_SUCCESS;
}

LM_STATUS
MM_GetConfig(PLM_DEVICE_BLOCK pDevice)
{
    PUM_DEVICE_BLOCK pUmDevice = (PUM_DEVICE_BLOCK) pDevice;
    int index = pDevice->index;

    if (auto_speed[index] == 0)
	pDevice->DisableAutoNeg = TRUE;
    else
	pDevice->DisableAutoNeg = FALSE;

    if (line_speed[index] == 0) {
	pDevice->RequestedMediaType =
	    LM_REQUESTED_MEDIA_TYPE_AUTO;
	pDevice->DisableAutoNeg = FALSE;
    }
    else {
	if (line_speed[index] == 1000) {
	    if (pDevice->EnableTbi) {
		pDevice->RequestedMediaType =
		    LM_REQUESTED_MEDIA_TYPE_FIBER_1000MBPS_FULL_DUPLEX;
	    }
	    else if (full_duplex[index]) {
		pDevice->RequestedMediaType =
		    LM_REQUESTED_MEDIA_TYPE_UTP_1000MBPS_FULL_DUPLEX;
	    }
	    else {
		pDevice->RequestedMediaType =
		    LM_REQUESTED_MEDIA_TYPE_UTP_1000MBPS;
	    }
	    if (!pDevice->EnableTbi)
		pDevice->DisableAutoNeg = FALSE;
	}
	else if (line_speed[index] == 100) {
	    if (full_duplex[index]) {
		pDevice->RequestedMediaType =
		    LM_REQUESTED_MEDIA_TYPE_UTP_100MBPS_FULL_DUPLEX;
	    }
	    else {
		pDevice->RequestedMediaType =
		    LM_REQUESTED_MEDIA_TYPE_UTP_100MBPS;
	    }
	}
	else if (line_speed[index] == 10) {
	    if (full_duplex[index]) {
		pDevice->RequestedMediaType =
		    LM_REQUESTED_MEDIA_TYPE_UTP_10MBPS_FULL_DUPLEX;
	    }
	    else {
		pDevice->RequestedMediaType =
		    LM_REQUESTED_MEDIA_TYPE_UTP_10MBPS;
	    }
	}
	else {
	    pDevice->RequestedMediaType =
		LM_REQUESTED_MEDIA_TYPE_AUTO;
	    pDevice->DisableAutoNeg = FALSE;
	}

    }
    pDevice->FlowControlCap = 0;
    if (rx_flow_control[index] != 0) {
	pDevice->FlowControlCap |= LM_FLOW_CONTROL_RECEIVE_PAUSE;
    }
    if (tx_flow_control[index] != 0) {
	pDevice->FlowControlCap |= LM_FLOW_CONTROL_TRANSMIT_PAUSE;
    }
    if ((auto_flow_control[index] != 0) &&
	(pDevice->DisableAutoNeg == FALSE)) {

	pDevice->FlowControlCap |= LM_FLOW_CONTROL_AUTO_PAUSE;
	if ((tx_flow_control[index] == 0) &&
	    (rx_flow_control[index] == 0)) {
	    pDevice->FlowControlCap |=
		LM_FLOW_CONTROL_TRANSMIT_PAUSE |
		LM_FLOW_CONTROL_RECEIVE_PAUSE;
	}
    }

    /* Default MTU for now */
    pUmDevice->mtu = 1500;

#if T3_JUMBO_RCV_RCB_ENTRY_COUNT
    if (pUmDevice->mtu > 1500) {
	pDevice->RxMtu = pUmDevice->mtu;
	pDevice->RxJumboDescCnt = DEFAULT_JUMBO_RCV_DESC_COUNT;
    }
    else {
	pDevice->RxJumboDescCnt = 0;
    }
    pDevice->RxJumboDescCnt = rx_jumbo_desc_cnt[index];
#else
    pDevice->RxMtu = pUmDevice->mtu;
#endif

    if (T3_ASIC_REV(pDevice->ChipRevId) == T3_ASIC_REV_5701) {
	pDevice->UseTaggedStatus = TRUE;
	pUmDevice->timer_interval = CFG_HZ;
    }
    else {
	pUmDevice->timer_interval = CFG_HZ/50;
    }

    pDevice->TxPacketDescCnt = tx_pkt_desc_cnt[index];
    pDevice->RxStdDescCnt = rx_std_desc_cnt[index];
    /* Note:  adaptive coalescence really isn't adaptive in this driver */
    pUmDevice->rx_adaptive_coalesce = rx_adaptive_coalesce[index];
    if (!pUmDevice->rx_adaptive_coalesce) {
	pDevice->RxCoalescingTicks = rx_coalesce_ticks[index];
	if (pDevice->RxCoalescingTicks > MAX_RX_COALESCING_TICKS)
	    pDevice->RxCoalescingTicks = MAX_RX_COALESCING_TICKS;
	pUmDevice->rx_curr_coalesce_ticks =pDevice->RxCoalescingTicks;

	pDevice->RxMaxCoalescedFrames = rx_max_coalesce_frames[index];
	if (pDevice->RxMaxCoalescedFrames>MAX_RX_MAX_COALESCED_FRAMES)
	    pDevice->RxMaxCoalescedFrames =
				MAX_RX_MAX_COALESCED_FRAMES;
	pUmDevice->rx_curr_coalesce_frames =
	    pDevice->RxMaxCoalescedFrames;
	pDevice->StatsCoalescingTicks = stats_coalesce_ticks[index];
	if (pDevice->StatsCoalescingTicks>MAX_STATS_COALESCING_TICKS)
	    pDevice->StatsCoalescingTicks=
		MAX_STATS_COALESCING_TICKS;
	}
	else {
	    pUmDevice->rx_curr_coalesce_frames =
		DEFAULT_RX_MAX_COALESCED_FRAMES;
	    pUmDevice->rx_curr_coalesce_ticks =
		DEFAULT_RX_COALESCING_TICKS;
	}
    pDevice->TxCoalescingTicks = tx_coalesce_ticks[index];
    if (pDevice->TxCoalescingTicks > MAX_TX_COALESCING_TICKS)
	pDevice->TxCoalescingTicks = MAX_TX_COALESCING_TICKS;
    pDevice->TxMaxCoalescedFrames = tx_max_coalesce_frames[index];
    if (pDevice->TxMaxCoalescedFrames > MAX_TX_MAX_COALESCED_FRAMES)
	pDevice->TxMaxCoalescedFrames = MAX_TX_MAX_COALESCED_FRAMES;

    if (enable_wol[index]) {
	pDevice->WakeUpModeCap = LM_WAKE_UP_MODE_MAGIC_PACKET;
	pDevice->WakeUpMode = LM_WAKE_UP_MODE_MAGIC_PACKET;
    }
    pDevice->NicSendBd = TRUE;

    /* Don't update status blocks during interrupt */
    pDevice->RxCoalescingTicksDuringInt = 0;
    pDevice->TxCoalescingTicksDuringInt = 0;

    return LM_STATUS_SUCCESS;

}


LM_STATUS
MM_StartTxDma(PLM_DEVICE_BLOCK pDevice, PLM_PACKET pPacket)
{
    PUM_DEVICE_BLOCK pUmDevice = (PUM_DEVICE_BLOCK) pDevice;
    printf("Start TX DMA: dev=%d packet @0x%x\n",
	   (int)pUmDevice->index, (unsigned int)pPacket);

    return LM_STATUS_SUCCESS;
}

LM_STATUS
MM_CompleteTxDma(PLM_DEVICE_BLOCK pDevice, PLM_PACKET pPacket)
{
    PUM_DEVICE_BLOCK pUmDevice = (PUM_DEVICE_BLOCK) pDevice;
    printf("Complete TX DMA: dev=%d packet @0x%x\n",
	   (int)pUmDevice->index, (unsigned int)pPacket);
    return LM_STATUS_SUCCESS;
}


LM_STATUS
MM_IndicateStatus(PLM_DEVICE_BLOCK pDevice, LM_STATUS Status)
{
    char buf[128];
    char lcd[4];
    PUM_DEVICE_BLOCK pUmDevice = (PUM_DEVICE_BLOCK) pDevice;
    LM_FLOW_CONTROL flow_control;

    pUmDevice->delayed_link_ind = 0;
    memset(lcd, 0x0, 4);

    if (Status == LM_STATUS_LINK_DOWN) {
	sprintf(buf,"eth%d: %s: NIC Link is down\n",
		pUmDevice->index,pUmDevice->name);
	lcd[0] = 'L';lcd[1]='N';lcd[2]='K';lcd[3] = '?';
    } else if (Status == LM_STATUS_LINK_ACTIVE) {
	sprintf(buf,"eth%d:%s: ", pUmDevice->index, pUmDevice->name);

	if (pDevice->LineSpeed == LM_LINE_SPEED_1000MBPS){
	    strcat(buf,"1000 Mbps ");
	    lcd[0] = '1';lcd[1]='G';lcd[2]='B';
	} else if (pDevice->LineSpeed == LM_LINE_SPEED_100MBPS){
	    strcat(buf,"100 Mbps ");
	    lcd[0] = '1';lcd[1]='0';lcd[2]='0';
	} else if (pDevice->LineSpeed == LM_LINE_SPEED_10MBPS){
	    strcat(buf,"10 Mbps ");
	    lcd[0] = '1';lcd[1]='0';lcd[2]=' ';
	}
	if (pDevice->DuplexMode == LM_DUPLEX_MODE_FULL){
	    strcat(buf, "full duplex");
	    lcd[3] = 'F';
	} else {
	    strcat(buf, "half duplex");
	    lcd[3] = 'H';
	}
	strcat(buf, " link up");

	flow_control = pDevice->FlowControl &
	    (LM_FLOW_CONTROL_RECEIVE_PAUSE |
	     LM_FLOW_CONTROL_TRANSMIT_PAUSE);

	if (flow_control) {
	    if (flow_control & LM_FLOW_CONTROL_RECEIVE_PAUSE) {
		strcat(buf,", receive ");
		if (flow_control & LM_FLOW_CONTROL_TRANSMIT_PAUSE)
		    strcat(buf," & transmit ");
	    }
	    else {
		strcat(buf,", transmit ");
	    }
	    strcat(buf,"flow control ON");
	} else {
	    strcat(buf, ", flow control OFF");
	}
	strcat(buf,"\n");
	printf("%s",buf);
    }
#if 0
    sysLedDsply(lcd[0],lcd[1],lcd[2],lcd[3]);
#endif
    return LM_STATUS_SUCCESS;
}

LM_STATUS
MM_FreeRxBuffer(PLM_DEVICE_BLOCK pDevice, PLM_PACKET pPacket)
{

    PUM_DEVICE_BLOCK pUmDevice = (PUM_DEVICE_BLOCK) pDevice;
    PUM_PACKET pUmPacket;
    void *skb;

    pUmPacket = (PUM_PACKET) pPacket;

    if ((skb = pUmPacket->skbuff))
	bcm570xPktFree(pUmDevice->index, skb);

    pUmPacket->skbuff = 0;

    return LM_STATUS_SUCCESS;
}

unsigned long
MM_AnGetCurrentTime_us(PAN_STATE_INFO pAnInfo)
{
    return get_timer(0);
}

/*
 *   Transform an MBUF chain into a single MBUF.
 *   This routine will fail if the amount of data in the
 *   chain overflows a transmit buffer.  In that case,
 *   the incoming MBUF chain will be freed.  This routine can
 *   also fail by not being able to allocate a new MBUF (including
 *   cluster and mbuf headers).  In that case the failure is
 *   non-fatal.  The incoming cluster chain is not freed, giving
 *   the caller the choice of whether to try a retransmit later.
 */
LM_STATUS
MM_CoalesceTxBuffer(PLM_DEVICE_BLOCK pDevice, PLM_PACKET pPacket)
{
    PUM_PACKET pUmPacket = (PUM_PACKET) pPacket;
    PUM_DEVICE_BLOCK pUmDevice = (PUM_DEVICE_BLOCK) pDevice;
    void *skbnew;
    int len = 0;

    if (len == 0)
	return (LM_STATUS_SUCCESS);

    if (len > MAX_PACKET_SIZE){
	printf ("eth%d: xmit frame discarded, too big!, size = %d\n",
		pUmDevice->index, len);
	return (LM_STATUS_FAILURE);
    }

    skbnew = bcm570xPktAlloc(pUmDevice->index, MAX_PACKET_SIZE);

    if (skbnew == NULL) {
	pUmDevice->tx_full = 1;
	printf ("eth%d: out of transmit buffers", pUmDevice->index);
	return (LM_STATUS_FAILURE);
    }

    /* New packet values */
    pUmPacket->skbuff = skbnew;
    pUmPacket->lm_packet.u.Tx.FragCount = 1;

    return (LM_STATUS_SUCCESS);
}


LM_STATUS
MM_IndicateRxPackets(PLM_DEVICE_BLOCK pDevice)
{
    PUM_DEVICE_BLOCK pUmDevice = (PUM_DEVICE_BLOCK) pDevice;
    pUmDevice->rx_pkt = 1;
    return LM_STATUS_SUCCESS;
}

LM_STATUS
MM_IndicateTxPackets(PLM_DEVICE_BLOCK pDevice)
{
    PUM_DEVICE_BLOCK pUmDevice = (PUM_DEVICE_BLOCK) pDevice;
    PLM_PACKET pPacket;
    PUM_PACKET pUmPacket;
    void *skb;
    while ( TRUE ) {

	pPacket = (PLM_PACKET)
	    QQ_PopHead(&pDevice->TxPacketXmittedQ.Container);

	if (pPacket == 0)
	    break;

	pUmPacket = (PUM_PACKET) pPacket;
	skb = (void*)pUmPacket->skbuff;

	/*
	* Free MBLK if we transmitted a fragmented packet or a
	* non-fragmented packet straight from the VxWorks
	* buffer pool. If packet was copied to a local transmit
	* buffer, then there's no MBUF to free, just free
	* the transmit buffer back to the cluster pool.
	*/

	if (skb)
	    bcm570xPktFree (pUmDevice->index, skb);

	pUmPacket->skbuff = 0;
	QQ_PushTail(&pDevice->TxPacketFreeQ.Container, pPacket);
	pUmDevice->tx_pkt = 1;
    }
    if (pUmDevice->tx_full) {
	if (QQ_GetEntryCnt(&pDevice->TxPacketFreeQ.Container) >=
	    (QQ_GetSize(&pDevice->TxPacketFreeQ.Container) >> 1))
	    pUmDevice->tx_full = 0;
    }
    return LM_STATUS_SUCCESS;
}

/*
 *  Scan an MBUF chain until we reach fragment number "frag"
 *  Return its length and physical address.
 */
void MM_MapTxDma
    (
    PLM_DEVICE_BLOCK pDevice,
    struct _LM_PACKET *pPacket,
    T3_64BIT_HOST_ADDR *paddr,
    LM_UINT32 *len,
    int frag)
{
    PUM_PACKET pUmPacket = (PUM_PACKET) pPacket;
    *len = pPacket->PacketSize;
    MM_SetT3Addr(paddr, (dma_addr_t) pUmPacket->skbuff);
}

/*
 *  Convert an mbuf address, a CPU local virtual address,
 *  to a physical address as seen from a PCI device.  Store the
 *  result at paddr.
 */
void MM_MapRxDma(
		 PLM_DEVICE_BLOCK pDevice,
		 struct _LM_PACKET *pPacket,
		 T3_64BIT_HOST_ADDR *paddr)
{
    PUM_PACKET pUmPacket = (PUM_PACKET) pPacket;
    MM_SetT3Addr(paddr, (dma_addr_t) pUmPacket->skbuff);
}

void
MM_SetAddr (LM_PHYSICAL_ADDRESS *paddr, dma_addr_t addr)
{
#if (BITS_PER_LONG == 64)
	paddr->High = ((unsigned long) addr) >> 32;
	paddr->Low = ((unsigned long) addr) & 0xffffffff;
#else
	paddr->High = 0;
	paddr->Low = (unsigned long) addr;
#endif
}

void
MM_SetT3Addr(T3_64BIT_HOST_ADDR *paddr, dma_addr_t addr)
{
	unsigned long baddr = (unsigned long) addr;
#if (BITS_PER_LONG == 64)
	set_64bit_addr(paddr, baddr & 0xffffffff, baddr >> 32);
#else
	set_64bit_addr(paddr, baddr, 0);
#endif
}

/*
 * This combination of `inline' and `extern' has almost the effect of a
 * macro.  The way to use it is to put a function definition in a header
 * file with these keywords, and put another copy of the definition
 * (lacking `inline' and `extern') in a library file.  The definition in
 * the header file will cause most calls to the function to be inlined.
 * If any uses of the function remain, they will refer to the single copy
 * in the library.
 */
void
atomic_set(atomic_t* entry, int val)
{
    entry->counter = val;
}
int
atomic_read(atomic_t* entry)
{
    return entry->counter;
}
void
atomic_inc(atomic_t* entry)
{
    if(entry)
	entry->counter++;
}

void
atomic_dec(atomic_t* entry)
{
    if(entry)
	entry->counter--;
}

void
atomic_sub(int a, atomic_t* entry)
{
    if(entry)
	entry->counter -= a;
}

void
atomic_add(int a, atomic_t* entry)
{
    if(entry)
	entry->counter += a;
}

/******************************************************************************/
/* Description:                                                               */
/*                                                                            */
/* Return:                                                                    */
/******************************************************************************/
void
QQ_InitQueue(
PQQ_CONTAINER pQueue,
unsigned int QueueSize) {
    pQueue->Head = 0;
    pQueue->Tail = 0;
    pQueue->Size = QueueSize+1;
    atomic_set(&pQueue->EntryCnt, 0);
} /* QQ_InitQueue */


/******************************************************************************/
/* Description:                                                               */
/*                                                                            */
/* Return:                                                                    */
/******************************************************************************/
char
QQ_Full(
PQQ_CONTAINER pQueue) {
    unsigned int NewHead;

    NewHead = (pQueue->Head + 1) % pQueue->Size;

    return(NewHead == pQueue->Tail);
} /* QQ_Full */


/******************************************************************************/
/* Description:                                                               */
/*                                                                            */
/* Return:                                                                    */
/******************************************************************************/
char
QQ_Empty(
PQQ_CONTAINER pQueue) {
    return(pQueue->Head == pQueue->Tail);
} /* QQ_Empty */


/******************************************************************************/
/* Description:                                                               */
/*                                                                            */
/* Return:                                                                    */
/******************************************************************************/
unsigned int
QQ_GetSize(
PQQ_CONTAINER pQueue) {
    return pQueue->Size;
} /* QQ_GetSize */


/******************************************************************************/
/* Description:                                                               */
/*                                                                            */
/* Return:                                                                    */
/******************************************************************************/
unsigned int
QQ_GetEntryCnt(
PQQ_CONTAINER pQueue) {
    return atomic_read(&pQueue->EntryCnt);
} /* QQ_GetEntryCnt */


/******************************************************************************/
/* Description:                                                               */
/*                                                                            */
/* Return:                                                                    */
/*    TRUE entry was added successfully.                                      */
/*    FALSE queue is full.                                                    */
/******************************************************************************/
char
QQ_PushHead(
PQQ_CONTAINER pQueue,
PQQ_ENTRY pEntry) {
    unsigned int Head;

    Head = (pQueue->Head + 1) % pQueue->Size;

#if !defined(QQ_NO_OVERFLOW_CHECK)
    if(Head == pQueue->Tail) {
	return 0;
    } /* if */
#endif /* QQ_NO_OVERFLOW_CHECK */

    pQueue->Array[pQueue->Head] = pEntry;
    wmb();
    pQueue->Head = Head;
    atomic_inc(&pQueue->EntryCnt);

    return -1;
} /* QQ_PushHead */


/******************************************************************************/
/* Description:                                                               */
/*                                                                            */
/* Return:                                                                    */
/*    TRUE entry was added successfully.                                      */
/*    FALSE queue is full.                                                    */
/******************************************************************************/
char
QQ_PushTail(
PQQ_CONTAINER pQueue,
PQQ_ENTRY pEntry) {
    unsigned int Tail;

    Tail = pQueue->Tail;
    if(Tail == 0) {
	Tail = pQueue->Size;
    } /* if */
    Tail--;

#if !defined(QQ_NO_OVERFLOW_CHECK)
    if(Tail == pQueue->Head) {
	return 0;
    } /* if */
#endif /* QQ_NO_OVERFLOW_CHECK */

    pQueue->Array[Tail] = pEntry;
    wmb();
    pQueue->Tail = Tail;
    atomic_inc(&pQueue->EntryCnt);

    return -1;
} /* QQ_PushTail */


/******************************************************************************/
/* Description:                                                               */
/*                                                                            */
/* Return:                                                                    */
/******************************************************************************/
PQQ_ENTRY
QQ_PopHead(
PQQ_CONTAINER pQueue) {
    unsigned int Head;
    PQQ_ENTRY Entry;

    Head = pQueue->Head;

#if !defined(QQ_NO_UNDERFLOW_CHECK)
    if(Head == pQueue->Tail) {
	return (PQQ_ENTRY) 0;
    } /* if */
#endif /* QQ_NO_UNDERFLOW_CHECK */

    if(Head == 0) {
	Head = pQueue->Size;
    } /* if */
    Head--;

    Entry = pQueue->Array[Head];
    membar();

    pQueue->Head = Head;
    atomic_dec(&pQueue->EntryCnt);

    return Entry;
} /* QQ_PopHead */


/******************************************************************************/
/* Description:                                                               */
/*                                                                            */
/* Return:                                                                    */
/******************************************************************************/
PQQ_ENTRY
QQ_PopTail(
PQQ_CONTAINER pQueue) {
    unsigned int Tail;
    PQQ_ENTRY Entry;

    Tail = pQueue->Tail;

#if !defined(QQ_NO_UNDERFLOW_CHECK)
    if(Tail == pQueue->Head) {
	return (PQQ_ENTRY) 0;
    } /* if */
#endif /* QQ_NO_UNDERFLOW_CHECK */

    Entry = pQueue->Array[Tail];
    membar();
    pQueue->Tail = (Tail + 1) % pQueue->Size;
    atomic_dec(&pQueue->EntryCnt);

    return Entry;
} /* QQ_PopTail */


/******************************************************************************/
/* Description:                                                               */
/*                                                                            */
/* Return:                                                                    */
/******************************************************************************/
PQQ_ENTRY
QQ_GetHead(
    PQQ_CONTAINER pQueue,
    unsigned int Idx)
{
    if(Idx >= atomic_read(&pQueue->EntryCnt))
    {
	return (PQQ_ENTRY) 0;
    }

    if(pQueue->Head > Idx)
    {
	Idx = pQueue->Head - Idx;
    }
    else
    {
	Idx = pQueue->Size - (Idx - pQueue->Head);
    }
    Idx--;

    return pQueue->Array[Idx];
}


/******************************************************************************/
/* Description:                                                               */
/*                                                                            */
/* Return:                                                                    */
/******************************************************************************/
PQQ_ENTRY
QQ_GetTail(
    PQQ_CONTAINER pQueue,
    unsigned int Idx)
{
    if(Idx >= atomic_read(&pQueue->EntryCnt))
    {
	return (PQQ_ENTRY) 0;
    }

    Idx += pQueue->Tail;
    if(Idx >= pQueue->Size)
    {
	Idx = Idx - pQueue->Size;
    }

    return pQueue->Array[Idx];
}

#endif	/* CFG_CMD_NET, !CONFIG_NET_MULTI, CONFIG_BCM570x */
