2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2002-11-03 00:24:07 +00:00
|
|
|
/*
|
|
|
|
* (C) Copyright 2002 Wolfgang Grandegger, wg@denx.de.
|
|
|
|
*
|
|
|
|
* This driver for AMD PCnet network controllers is derived from the
|
|
|
|
* Linux driver pcnet32.c written 1996-1999 by Thomas Bogendoerfer.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2019-11-14 19:57:39 +00:00
|
|
|
#include <cpu_func.h>
|
2020-05-10 17:40:05 +00:00
|
|
|
#include <log.h>
|
2002-11-03 00:24:07 +00:00
|
|
|
#include <malloc.h>
|
|
|
|
#include <net.h>
|
2008-08-31 17:08:43 +00:00
|
|
|
#include <netdev.h>
|
2020-05-10 17:39:56 +00:00
|
|
|
#include <asm/cache.h>
|
2002-11-03 00:24:07 +00:00
|
|
|
#include <asm/io.h>
|
|
|
|
#include <pci.h>
|
2020-05-10 17:40:11 +00:00
|
|
|
#include <linux/delay.h>
|
2002-11-03 00:24:07 +00:00
|
|
|
|
2008-04-24 21:44:26 +00:00
|
|
|
#define PCNET_DEBUG_LEVEL 0 /* 0=off, 1=init, 2=rx/tx */
|
2002-11-03 00:24:07 +00:00
|
|
|
|
2011-11-05 05:12:58 +00:00
|
|
|
#define PCNET_DEBUG1(fmt,args...) \
|
|
|
|
debug_cond(PCNET_DEBUG_LEVEL > 0, fmt ,##args)
|
|
|
|
#define PCNET_DEBUG2(fmt,args...) \
|
|
|
|
debug_cond(PCNET_DEBUG_LEVEL > 1, fmt ,##args)
|
2002-11-03 00:24:07 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Set the number of Tx and Rx buffers, using Log_2(# buffers).
|
|
|
|
* Reasonable default values are 4 Tx buffers, and 16 Rx buffers.
|
|
|
|
* That translates to 2 (4 == 2^^2) and 4 (16 == 2^^4).
|
|
|
|
*/
|
|
|
|
#define PCNET_LOG_TX_BUFFERS 0
|
|
|
|
#define PCNET_LOG_RX_BUFFERS 2
|
|
|
|
|
|
|
|
#define TX_RING_SIZE (1 << (PCNET_LOG_TX_BUFFERS))
|
|
|
|
#define TX_RING_LEN_BITS ((PCNET_LOG_TX_BUFFERS) << 12)
|
|
|
|
|
|
|
|
#define RX_RING_SIZE (1 << (PCNET_LOG_RX_BUFFERS))
|
|
|
|
#define RX_RING_LEN_BITS ((PCNET_LOG_RX_BUFFERS) << 4)
|
|
|
|
|
|
|
|
#define PKT_BUF_SZ 1544
|
|
|
|
|
|
|
|
/* The PCNET Rx and Tx ring descriptors. */
|
|
|
|
struct pcnet_rx_head {
|
2008-04-24 21:44:26 +00:00
|
|
|
u32 base;
|
|
|
|
s16 buf_length;
|
|
|
|
s16 status;
|
|
|
|
u32 msg_length;
|
|
|
|
u32 reserved;
|
2002-11-03 00:24:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct pcnet_tx_head {
|
2008-04-24 21:44:26 +00:00
|
|
|
u32 base;
|
|
|
|
s16 length;
|
|
|
|
s16 status;
|
|
|
|
u32 misc;
|
|
|
|
u32 reserved;
|
2002-11-03 00:24:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* The PCNET 32-Bit initialization block, described in databook. */
|
|
|
|
struct pcnet_init_block {
|
2008-04-24 21:44:26 +00:00
|
|
|
u16 mode;
|
|
|
|
u16 tlen_rlen;
|
|
|
|
u8 phys_addr[6];
|
|
|
|
u16 reserved;
|
|
|
|
u32 filter[2];
|
|
|
|
/* Receive and transmit ring base, along with extra bits. */
|
|
|
|
u32 rx_ring;
|
|
|
|
u32 tx_ring;
|
|
|
|
u32 reserved2;
|
2002-11-03 00:24:07 +00:00
|
|
|
};
|
|
|
|
|
2014-04-07 15:41:46 +00:00
|
|
|
struct pcnet_uncached_priv {
|
2008-04-24 21:44:26 +00:00
|
|
|
struct pcnet_rx_head rx_ring[RX_RING_SIZE];
|
|
|
|
struct pcnet_tx_head tx_ring[TX_RING_SIZE];
|
|
|
|
struct pcnet_init_block init_block;
|
2014-04-07 15:41:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct pcnet_priv {
|
|
|
|
struct pcnet_uncached_priv *uc;
|
2008-04-24 21:44:26 +00:00
|
|
|
/* Receive Buffer space */
|
2014-04-07 15:41:47 +00:00
|
|
|
unsigned char (*rx_buf)[RX_RING_SIZE][PKT_BUF_SZ + 4];
|
2008-04-24 21:44:26 +00:00
|
|
|
int cur_rx;
|
|
|
|
int cur_tx;
|
2002-11-03 00:24:07 +00:00
|
|
|
} pcnet_priv_t;
|
|
|
|
|
|
|
|
static pcnet_priv_t *lp;
|
|
|
|
|
|
|
|
/* Offsets from base I/O address for WIO mode */
|
|
|
|
#define PCNET_RDP 0x10
|
|
|
|
#define PCNET_RAP 0x12
|
|
|
|
#define PCNET_RESET 0x14
|
|
|
|
#define PCNET_BDP 0x16
|
|
|
|
|
2013-11-08 11:18:43 +00:00
|
|
|
static u16 pcnet_read_csr(struct eth_device *dev, int index)
|
2002-11-03 00:24:07 +00:00
|
|
|
{
|
2020-05-03 17:43:32 +00:00
|
|
|
void __iomem *base = (void __iomem *)dev->iobase;
|
|
|
|
|
|
|
|
writew(index, base + PCNET_RAP);
|
|
|
|
return readw(base + PCNET_RDP);
|
2002-11-03 00:24:07 +00:00
|
|
|
}
|
|
|
|
|
2013-11-08 11:18:43 +00:00
|
|
|
static void pcnet_write_csr(struct eth_device *dev, int index, u16 val)
|
2002-11-03 00:24:07 +00:00
|
|
|
{
|
2020-05-03 17:43:32 +00:00
|
|
|
void __iomem *base = (void __iomem *)dev->iobase;
|
|
|
|
|
|
|
|
writew(index, base + PCNET_RAP);
|
|
|
|
writew(val, base + PCNET_RDP);
|
2002-11-03 00:24:07 +00:00
|
|
|
}
|
|
|
|
|
2013-11-08 11:18:43 +00:00
|
|
|
static u16 pcnet_read_bcr(struct eth_device *dev, int index)
|
2002-11-03 00:24:07 +00:00
|
|
|
{
|
2020-05-03 17:43:32 +00:00
|
|
|
void __iomem *base = (void __iomem *)dev->iobase;
|
|
|
|
|
|
|
|
writew(index, base + PCNET_RAP);
|
|
|
|
return readw(base + PCNET_BDP);
|
2002-11-03 00:24:07 +00:00
|
|
|
}
|
|
|
|
|
2013-11-08 11:18:43 +00:00
|
|
|
static void pcnet_write_bcr(struct eth_device *dev, int index, u16 val)
|
2002-11-03 00:24:07 +00:00
|
|
|
{
|
2020-05-03 17:43:32 +00:00
|
|
|
void __iomem *base = (void __iomem *)dev->iobase;
|
|
|
|
|
|
|
|
writew(index, base + PCNET_RAP);
|
|
|
|
writew(val, base + PCNET_BDP);
|
2002-11-03 00:24:07 +00:00
|
|
|
}
|
|
|
|
|
2013-11-08 11:18:43 +00:00
|
|
|
static void pcnet_reset(struct eth_device *dev)
|
2002-11-03 00:24:07 +00:00
|
|
|
{
|
2020-05-03 17:43:32 +00:00
|
|
|
void __iomem *base = (void __iomem *)dev->iobase;
|
|
|
|
|
|
|
|
readw(base + PCNET_RESET);
|
2002-11-03 00:24:07 +00:00
|
|
|
}
|
|
|
|
|
2013-11-08 11:18:43 +00:00
|
|
|
static int pcnet_check(struct eth_device *dev)
|
2002-11-03 00:24:07 +00:00
|
|
|
{
|
2020-05-03 17:43:32 +00:00
|
|
|
void __iomem *base = (void __iomem *)dev->iobase;
|
|
|
|
|
|
|
|
writew(88, base + PCNET_RAP);
|
|
|
|
return readw(base + PCNET_RAP) == 88;
|
2002-11-03 00:24:07 +00:00
|
|
|
}
|
|
|
|
|
2008-04-24 21:44:26 +00:00
|
|
|
static int pcnet_init (struct eth_device *dev, bd_t * bis);
|
2012-05-22 18:09:56 +00:00
|
|
|
static int pcnet_send(struct eth_device *dev, void *packet, int length);
|
2008-04-24 21:44:26 +00:00
|
|
|
static int pcnet_recv (struct eth_device *dev);
|
|
|
|
static void pcnet_halt (struct eth_device *dev);
|
|
|
|
static int pcnet_probe (struct eth_device *dev, bd_t * bis, int dev_num);
|
2002-11-03 00:24:07 +00:00
|
|
|
|
2016-01-12 20:48:24 +00:00
|
|
|
static inline pci_addr_t pcnet_virt_to_mem(const struct eth_device *dev,
|
2016-05-26 13:49:34 +00:00
|
|
|
void *addr)
|
2016-01-12 20:48:24 +00:00
|
|
|
{
|
2016-05-26 13:49:35 +00:00
|
|
|
pci_dev_t devbusfn = (pci_dev_t)(unsigned long)dev->priv;
|
2016-01-12 20:48:24 +00:00
|
|
|
void *virt_addr = addr;
|
|
|
|
|
|
|
|
return pci_virt_to_mem(devbusfn, virt_addr);
|
|
|
|
}
|
2002-11-03 00:24:07 +00:00
|
|
|
|
|
|
|
static struct pci_device_id supported[] = {
|
2008-04-24 21:44:26 +00:00
|
|
|
{PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_LANCE},
|
|
|
|
{}
|
2002-11-03 00:24:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-11-08 11:18:43 +00:00
|
|
|
int pcnet_initialize(bd_t *bis)
|
2002-11-03 00:24:07 +00:00
|
|
|
{
|
2008-04-24 21:44:26 +00:00
|
|
|
pci_dev_t devbusfn;
|
|
|
|
struct eth_device *dev;
|
|
|
|
u16 command, status;
|
|
|
|
int dev_nr = 0;
|
2016-05-26 16:32:29 +00:00
|
|
|
u32 bar;
|
2008-04-24 21:44:26 +00:00
|
|
|
|
2013-11-08 11:18:43 +00:00
|
|
|
PCNET_DEBUG1("\npcnet_initialize...\n");
|
2008-04-24 21:44:26 +00:00
|
|
|
|
|
|
|
for (dev_nr = 0;; dev_nr++) {
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Find the PCnet PCI device(s).
|
|
|
|
*/
|
2013-11-08 11:18:43 +00:00
|
|
|
devbusfn = pci_find_devices(supported, dev_nr);
|
|
|
|
if (devbusfn < 0)
|
2008-04-24 21:44:26 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate and pre-fill the device structure.
|
|
|
|
*/
|
2013-11-08 11:18:43 +00:00
|
|
|
dev = (struct eth_device *)malloc(sizeof(*dev));
|
2010-10-19 05:03:45 +00:00
|
|
|
if (!dev) {
|
|
|
|
printf("pcnet: Can not allocate memory\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
memset(dev, 0, sizeof(*dev));
|
2016-05-26 13:49:35 +00:00
|
|
|
dev->priv = (void *)(unsigned long)devbusfn;
|
2013-11-08 11:18:43 +00:00
|
|
|
sprintf(dev->name, "pcnet#%d", dev_nr);
|
2008-04-24 21:44:26 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Setup the PCI device.
|
|
|
|
*/
|
2020-04-18 03:11:05 +00:00
|
|
|
pci_read_config_dword(devbusfn, PCI_BASE_ADDRESS_1, &bar);
|
|
|
|
dev->iobase = pci_mem_to_phys(devbusfn, bar);
|
2008-04-24 21:44:26 +00:00
|
|
|
dev->iobase &= ~0xf;
|
|
|
|
|
2016-05-26 13:49:35 +00:00
|
|
|
PCNET_DEBUG1("%s: devbusfn=0x%x iobase=0x%lx: ",
|
|
|
|
dev->name, devbusfn, (unsigned long)dev->iobase);
|
2008-04-24 21:44:26 +00:00
|
|
|
|
2020-04-18 03:11:05 +00:00
|
|
|
command = PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER;
|
2013-11-08 11:18:43 +00:00
|
|
|
pci_write_config_word(devbusfn, PCI_COMMAND, command);
|
|
|
|
pci_read_config_word(devbusfn, PCI_COMMAND, &status);
|
2008-04-24 21:44:26 +00:00
|
|
|
if ((status & command) != command) {
|
2013-11-08 11:18:43 +00:00
|
|
|
printf("%s: Couldn't enable IO access or Bus Mastering\n",
|
|
|
|
dev->name);
|
|
|
|
free(dev);
|
2008-04-24 21:44:26 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2013-11-08 11:18:43 +00:00
|
|
|
pci_write_config_byte(devbusfn, PCI_LATENCY_TIMER, 0x40);
|
2008-04-24 21:44:26 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Probe the PCnet chip.
|
|
|
|
*/
|
2013-11-08 11:18:43 +00:00
|
|
|
if (pcnet_probe(dev, bis, dev_nr) < 0) {
|
|
|
|
free(dev);
|
2008-04-24 21:44:26 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Setup device structure and register the driver.
|
|
|
|
*/
|
|
|
|
dev->init = pcnet_init;
|
|
|
|
dev->halt = pcnet_halt;
|
|
|
|
dev->send = pcnet_send;
|
|
|
|
dev->recv = pcnet_recv;
|
|
|
|
|
2013-11-08 11:18:43 +00:00
|
|
|
eth_register(dev);
|
2002-11-03 00:24:07 +00:00
|
|
|
}
|
|
|
|
|
2013-11-08 11:18:43 +00:00
|
|
|
udelay(10 * 1000);
|
2002-11-03 00:24:07 +00:00
|
|
|
|
2008-04-24 21:44:26 +00:00
|
|
|
return dev_nr;
|
2002-11-03 00:24:07 +00:00
|
|
|
}
|
|
|
|
|
2013-11-08 11:18:43 +00:00
|
|
|
static int pcnet_probe(struct eth_device *dev, bd_t *bis, int dev_nr)
|
2002-11-03 00:24:07 +00:00
|
|
|
{
|
2008-04-24 21:44:26 +00:00
|
|
|
int chip_version;
|
|
|
|
char *chipname;
|
|
|
|
|
2002-11-03 00:24:07 +00:00
|
|
|
#ifdef PCNET_HAS_PROM
|
2008-04-24 21:44:26 +00:00
|
|
|
int i;
|
2002-11-03 00:24:07 +00:00
|
|
|
#endif
|
|
|
|
|
2008-04-24 21:44:26 +00:00
|
|
|
/* Reset the PCnet controller */
|
2013-11-08 11:18:43 +00:00
|
|
|
pcnet_reset(dev);
|
2008-04-24 21:44:26 +00:00
|
|
|
|
|
|
|
/* Check if register access is working */
|
2013-11-08 11:18:43 +00:00
|
|
|
if (pcnet_read_csr(dev, 0) != 4 || !pcnet_check(dev)) {
|
|
|
|
printf("%s: CSR register access check failed\n", dev->name);
|
2008-04-24 21:44:26 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Identify the chip */
|
|
|
|
chip_version =
|
2013-11-08 11:18:43 +00:00
|
|
|
pcnet_read_csr(dev, 88) | (pcnet_read_csr(dev, 89) << 16);
|
2008-04-24 21:44:26 +00:00
|
|
|
if ((chip_version & 0xfff) != 0x003)
|
|
|
|
return -1;
|
|
|
|
chip_version = (chip_version >> 12) & 0xffff;
|
|
|
|
switch (chip_version) {
|
|
|
|
case 0x2621:
|
|
|
|
chipname = "PCnet/PCI II 79C970A"; /* PCI */
|
|
|
|
break;
|
|
|
|
case 0x2625:
|
|
|
|
chipname = "PCnet/FAST III 79C973"; /* PCI */
|
|
|
|
break;
|
|
|
|
case 0x2627:
|
|
|
|
chipname = "PCnet/FAST III 79C975"; /* PCI */
|
|
|
|
break;
|
|
|
|
default:
|
2013-11-08 11:18:43 +00:00
|
|
|
printf("%s: PCnet version %#x not supported\n",
|
|
|
|
dev->name, chip_version);
|
2008-04-24 21:44:26 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2002-11-03 00:24:07 +00:00
|
|
|
|
2013-11-08 11:18:43 +00:00
|
|
|
PCNET_DEBUG1("AMD %s\n", chipname);
|
2002-11-03 00:24:07 +00:00
|
|
|
|
|
|
|
#ifdef PCNET_HAS_PROM
|
2008-04-24 21:44:26 +00:00
|
|
|
/*
|
|
|
|
* In most chips, after a chip reset, the ethernet address is read from
|
|
|
|
* the station address PROM at the base address and programmed into the
|
|
|
|
* "Physical Address Registers" CSR12-14.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < 3; i++) {
|
|
|
|
unsigned int val;
|
|
|
|
|
2013-11-08 11:18:43 +00:00
|
|
|
val = pcnet_read_csr(dev, i + 12) & 0x0ffff;
|
2008-04-24 21:44:26 +00:00
|
|
|
/* There may be endianness issues here. */
|
|
|
|
dev->enetaddr[2 * i] = val & 0x0ff;
|
|
|
|
dev->enetaddr[2 * i + 1] = (val >> 8) & 0x0ff;
|
|
|
|
}
|
2002-11-03 00:24:07 +00:00
|
|
|
#endif /* PCNET_HAS_PROM */
|
|
|
|
|
2008-04-24 21:44:26 +00:00
|
|
|
return 0;
|
2002-11-03 00:24:07 +00:00
|
|
|
}
|
|
|
|
|
2013-11-08 11:18:43 +00:00
|
|
|
static int pcnet_init(struct eth_device *dev, bd_t *bis)
|
2002-11-03 00:24:07 +00:00
|
|
|
{
|
2014-04-07 15:41:46 +00:00
|
|
|
struct pcnet_uncached_priv *uc;
|
2008-04-24 21:44:26 +00:00
|
|
|
int i, val;
|
2016-05-26 13:49:35 +00:00
|
|
|
unsigned long addr;
|
2002-11-03 00:24:07 +00:00
|
|
|
|
2013-11-08 11:18:43 +00:00
|
|
|
PCNET_DEBUG1("%s: pcnet_init...\n", dev->name);
|
2002-11-03 00:24:07 +00:00
|
|
|
|
2008-04-24 21:44:26 +00:00
|
|
|
/* Switch pcnet to 32bit mode */
|
2013-11-08 11:18:43 +00:00
|
|
|
pcnet_write_bcr(dev, 20, 2);
|
2002-11-03 00:24:07 +00:00
|
|
|
|
2008-04-24 21:44:26 +00:00
|
|
|
/* Set/reset autoselect bit */
|
2013-11-08 11:18:43 +00:00
|
|
|
val = pcnet_read_bcr(dev, 2) & ~2;
|
2008-04-24 21:44:26 +00:00
|
|
|
val |= 2;
|
2013-11-08 11:18:43 +00:00
|
|
|
pcnet_write_bcr(dev, 2, val);
|
2002-11-03 00:24:07 +00:00
|
|
|
|
2008-04-24 21:44:26 +00:00
|
|
|
/* Enable auto negotiate, setup, disable fd */
|
2013-11-08 11:18:43 +00:00
|
|
|
val = pcnet_read_bcr(dev, 32) & ~0x98;
|
2008-04-24 21:44:26 +00:00
|
|
|
val |= 0x20;
|
2013-11-08 11:18:43 +00:00
|
|
|
pcnet_write_bcr(dev, 32, val);
|
2002-11-03 00:24:07 +00:00
|
|
|
|
2013-11-08 11:18:46 +00:00
|
|
|
/*
|
|
|
|
* Enable NOUFLO on supported controllers, with the transmit
|
|
|
|
* start point set to the full packet. This will cause entire
|
|
|
|
* packets to be buffered by the ethernet controller before
|
|
|
|
* transmission, eliminating underflows which are common on
|
|
|
|
* slower devices. Controllers which do not support NOUFLO will
|
|
|
|
* simply be left with a larger transmit FIFO threshold.
|
|
|
|
*/
|
|
|
|
val = pcnet_read_bcr(dev, 18);
|
|
|
|
val |= 1 << 11;
|
|
|
|
pcnet_write_bcr(dev, 18, val);
|
|
|
|
val = pcnet_read_csr(dev, 80);
|
|
|
|
val |= 0x3 << 10;
|
|
|
|
pcnet_write_csr(dev, 80, val);
|
|
|
|
|
2008-04-24 21:44:26 +00:00
|
|
|
/*
|
|
|
|
* We only maintain one structure because the drivers will never
|
|
|
|
* be used concurrently. In 32bit mode the RX and TX ring entries
|
|
|
|
* must be aligned on 16-byte boundaries.
|
|
|
|
*/
|
|
|
|
if (lp == NULL) {
|
2016-05-26 13:49:35 +00:00
|
|
|
addr = (unsigned long)malloc(sizeof(pcnet_priv_t) + 0x10);
|
2008-04-24 21:44:26 +00:00
|
|
|
addr = (addr + 0xf) & ~0xf;
|
2013-11-08 11:18:43 +00:00
|
|
|
lp = (pcnet_priv_t *)addr;
|
2014-04-07 15:41:46 +00:00
|
|
|
|
2016-05-26 13:49:35 +00:00
|
|
|
addr = (unsigned long)memalign(ARCH_DMA_MINALIGN,
|
|
|
|
sizeof(*lp->uc));
|
2014-04-07 15:41:46 +00:00
|
|
|
flush_dcache_range(addr, addr + sizeof(*lp->uc));
|
2020-04-18 00:32:19 +00:00
|
|
|
addr = (unsigned long)map_physmem(addr,
|
|
|
|
roundup(sizeof(*lp->uc), ARCH_DMA_MINALIGN),
|
|
|
|
MAP_NOCACHE);
|
2014-04-07 15:41:46 +00:00
|
|
|
lp->uc = (struct pcnet_uncached_priv *)addr;
|
2014-04-07 15:41:47 +00:00
|
|
|
|
2016-05-26 13:49:35 +00:00
|
|
|
addr = (unsigned long)memalign(ARCH_DMA_MINALIGN,
|
|
|
|
sizeof(*lp->rx_buf));
|
2014-04-07 15:41:47 +00:00
|
|
|
flush_dcache_range(addr, addr + sizeof(*lp->rx_buf));
|
|
|
|
lp->rx_buf = (void *)addr;
|
2008-04-24 21:44:26 +00:00
|
|
|
}
|
2002-11-03 00:24:07 +00:00
|
|
|
|
2014-04-07 15:41:46 +00:00
|
|
|
uc = lp->uc;
|
|
|
|
|
|
|
|
uc->init_block.mode = cpu_to_le16(0x0000);
|
|
|
|
uc->init_block.filter[0] = 0x00000000;
|
|
|
|
uc->init_block.filter[1] = 0x00000000;
|
2008-04-24 21:44:26 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize the Rx ring.
|
|
|
|
*/
|
|
|
|
lp->cur_rx = 0;
|
|
|
|
for (i = 0; i < RX_RING_SIZE; i++) {
|
2016-05-26 13:49:34 +00:00
|
|
|
addr = pcnet_virt_to_mem(dev, (*lp->rx_buf)[i]);
|
2016-01-12 20:48:24 +00:00
|
|
|
uc->rx_ring[i].base = cpu_to_le32(addr);
|
2014-04-07 15:41:46 +00:00
|
|
|
uc->rx_ring[i].buf_length = cpu_to_le16(-PKT_BUF_SZ);
|
|
|
|
uc->rx_ring[i].status = cpu_to_le16(0x8000);
|
2008-04-24 21:44:26 +00:00
|
|
|
PCNET_DEBUG1
|
|
|
|
("Rx%d: base=0x%x buf_length=0x%hx status=0x%hx\n", i,
|
2014-04-07 15:41:46 +00:00
|
|
|
uc->rx_ring[i].base, uc->rx_ring[i].buf_length,
|
|
|
|
uc->rx_ring[i].status);
|
2008-04-24 21:44:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize the Tx ring. The Tx buffer address is filled in as
|
|
|
|
* needed, but we do need to clear the upper ownership bit.
|
|
|
|
*/
|
2002-11-03 00:24:07 +00:00
|
|
|
lp->cur_tx = 0;
|
2008-04-24 21:44:26 +00:00
|
|
|
for (i = 0; i < TX_RING_SIZE; i++) {
|
2014-04-07 15:41:46 +00:00
|
|
|
uc->tx_ring[i].base = 0;
|
|
|
|
uc->tx_ring[i].status = 0;
|
2008-04-24 21:44:26 +00:00
|
|
|
}
|
2002-11-03 00:24:07 +00:00
|
|
|
|
2008-04-24 21:44:26 +00:00
|
|
|
/*
|
|
|
|
* Setup Init Block.
|
|
|
|
*/
|
2014-04-07 15:41:46 +00:00
|
|
|
PCNET_DEBUG1("Init block at 0x%p: MAC", &lp->uc->init_block);
|
2002-11-03 00:24:07 +00:00
|
|
|
|
2008-04-24 21:44:26 +00:00
|
|
|
for (i = 0; i < 6; i++) {
|
2014-04-07 15:41:46 +00:00
|
|
|
lp->uc->init_block.phys_addr[i] = dev->enetaddr[i];
|
|
|
|
PCNET_DEBUG1(" %02x", lp->uc->init_block.phys_addr[i]);
|
2008-04-24 21:44:26 +00:00
|
|
|
}
|
|
|
|
|
2014-04-07 15:41:46 +00:00
|
|
|
uc->init_block.tlen_rlen = cpu_to_le16(TX_RING_LEN_BITS |
|
2013-11-08 11:18:43 +00:00
|
|
|
RX_RING_LEN_BITS);
|
2016-05-26 13:49:34 +00:00
|
|
|
addr = pcnet_virt_to_mem(dev, uc->rx_ring);
|
2016-01-12 20:48:24 +00:00
|
|
|
uc->init_block.rx_ring = cpu_to_le32(addr);
|
2016-05-26 13:49:34 +00:00
|
|
|
addr = pcnet_virt_to_mem(dev, uc->tx_ring);
|
2016-01-12 20:48:24 +00:00
|
|
|
uc->init_block.tx_ring = cpu_to_le32(addr);
|
2008-04-24 21:44:26 +00:00
|
|
|
|
2013-11-08 11:18:43 +00:00
|
|
|
PCNET_DEBUG1("\ntlen_rlen=0x%x rx_ring=0x%x tx_ring=0x%x\n",
|
2014-04-07 15:41:46 +00:00
|
|
|
uc->init_block.tlen_rlen,
|
|
|
|
uc->init_block.rx_ring, uc->init_block.tx_ring);
|
2002-11-03 00:24:07 +00:00
|
|
|
|
|
|
|
/*
|
2008-04-24 21:44:26 +00:00
|
|
|
* Tell the controller where the Init Block is located.
|
2002-11-03 00:24:07 +00:00
|
|
|
*/
|
2014-04-07 15:41:46 +00:00
|
|
|
barrier();
|
2016-05-26 13:49:34 +00:00
|
|
|
addr = pcnet_virt_to_mem(dev, &lp->uc->init_block);
|
2013-11-08 11:18:43 +00:00
|
|
|
pcnet_write_csr(dev, 1, addr & 0xffff);
|
|
|
|
pcnet_write_csr(dev, 2, (addr >> 16) & 0xffff);
|
2008-04-24 21:44:26 +00:00
|
|
|
|
2013-11-08 11:18:43 +00:00
|
|
|
pcnet_write_csr(dev, 4, 0x0915);
|
|
|
|
pcnet_write_csr(dev, 0, 0x0001); /* start */
|
2008-04-24 21:44:26 +00:00
|
|
|
|
|
|
|
/* Wait for Init Done bit */
|
|
|
|
for (i = 10000; i > 0; i--) {
|
2013-11-08 11:18:43 +00:00
|
|
|
if (pcnet_read_csr(dev, 0) & 0x0100)
|
2008-04-24 21:44:26 +00:00
|
|
|
break;
|
2013-11-08 11:18:43 +00:00
|
|
|
udelay(10);
|
2002-11-03 00:24:07 +00:00
|
|
|
}
|
2008-04-24 21:44:26 +00:00
|
|
|
if (i <= 0) {
|
2013-11-08 11:18:43 +00:00
|
|
|
printf("%s: TIMEOUT: controller init failed\n", dev->name);
|
|
|
|
pcnet_reset(dev);
|
2008-04-24 21:44:26 +00:00
|
|
|
return -1;
|
2002-11-03 00:24:07 +00:00
|
|
|
}
|
|
|
|
|
2008-04-24 21:44:26 +00:00
|
|
|
/*
|
|
|
|
* Finally start network controller operation.
|
|
|
|
*/
|
2013-11-08 11:18:43 +00:00
|
|
|
pcnet_write_csr(dev, 0, 0x0002);
|
2008-04-24 21:44:26 +00:00
|
|
|
|
|
|
|
return 0;
|
2002-11-03 00:24:07 +00:00
|
|
|
}
|
|
|
|
|
2012-05-22 18:09:56 +00:00
|
|
|
static int pcnet_send(struct eth_device *dev, void *packet, int pkt_len)
|
2002-11-03 00:24:07 +00:00
|
|
|
{
|
2008-04-24 21:44:26 +00:00
|
|
|
int i, status;
|
2016-01-12 20:48:24 +00:00
|
|
|
u32 addr;
|
2014-04-07 15:41:46 +00:00
|
|
|
struct pcnet_tx_head *entry = &lp->uc->tx_ring[lp->cur_tx];
|
2008-04-24 21:44:26 +00:00
|
|
|
|
2013-11-08 11:18:43 +00:00
|
|
|
PCNET_DEBUG2("Tx%d: %d bytes from 0x%p ", lp->cur_tx, pkt_len,
|
|
|
|
packet);
|
2008-04-24 21:44:26 +00:00
|
|
|
|
2013-11-08 11:18:45 +00:00
|
|
|
flush_dcache_range((unsigned long)packet,
|
|
|
|
(unsigned long)packet + pkt_len);
|
|
|
|
|
2008-04-24 21:44:26 +00:00
|
|
|
/* Wait for completion by testing the OWN bit */
|
|
|
|
for (i = 1000; i > 0; i--) {
|
2014-04-07 15:41:48 +00:00
|
|
|
status = readw(&entry->status);
|
2008-04-24 21:44:26 +00:00
|
|
|
if ((status & 0x8000) == 0)
|
|
|
|
break;
|
2013-11-08 11:18:43 +00:00
|
|
|
udelay(100);
|
|
|
|
PCNET_DEBUG2(".");
|
2008-04-24 21:44:26 +00:00
|
|
|
}
|
|
|
|
if (i <= 0) {
|
2013-11-08 11:18:43 +00:00
|
|
|
printf("%s: TIMEOUT: Tx%d failed (status = 0x%x)\n",
|
|
|
|
dev->name, lp->cur_tx, status);
|
2008-04-24 21:44:26 +00:00
|
|
|
pkt_len = 0;
|
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Setup Tx ring. Caution: the write order is important here,
|
|
|
|
* set the status with the "ownership" bits last.
|
|
|
|
*/
|
2016-05-26 13:49:34 +00:00
|
|
|
addr = pcnet_virt_to_mem(dev, packet);
|
2014-04-07 15:41:48 +00:00
|
|
|
writew(-pkt_len, &entry->length);
|
|
|
|
writel(0, &entry->misc);
|
2016-01-12 20:48:24 +00:00
|
|
|
writel(addr, &entry->base);
|
2014-04-07 15:41:48 +00:00
|
|
|
writew(0x8300, &entry->status);
|
2008-04-24 21:44:26 +00:00
|
|
|
|
|
|
|
/* Trigger an immediate send poll. */
|
2013-11-08 11:18:43 +00:00
|
|
|
pcnet_write_csr(dev, 0, 0x0008);
|
2008-04-24 21:44:26 +00:00
|
|
|
|
|
|
|
failure:
|
|
|
|
if (++lp->cur_tx >= TX_RING_SIZE)
|
|
|
|
lp->cur_tx = 0;
|
|
|
|
|
2013-11-08 11:18:43 +00:00
|
|
|
PCNET_DEBUG2("done\n");
|
2008-04-24 21:44:26 +00:00
|
|
|
return pkt_len;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int pcnet_recv (struct eth_device *dev)
|
|
|
|
{
|
|
|
|
struct pcnet_rx_head *entry;
|
2014-04-07 15:41:47 +00:00
|
|
|
unsigned char *buf;
|
2008-04-24 21:44:26 +00:00
|
|
|
int pkt_len = 0;
|
2014-04-07 15:41:48 +00:00
|
|
|
u16 status, err_status;
|
2008-04-24 21:44:26 +00:00
|
|
|
|
|
|
|
while (1) {
|
2014-04-07 15:41:46 +00:00
|
|
|
entry = &lp->uc->rx_ring[lp->cur_rx];
|
2008-04-24 21:44:26 +00:00
|
|
|
/*
|
|
|
|
* If we own the next entry, it's a new packet. Send it up.
|
|
|
|
*/
|
2014-04-07 15:41:48 +00:00
|
|
|
status = readw(&entry->status);
|
2013-11-08 11:18:43 +00:00
|
|
|
if ((status & 0x8000) != 0)
|
2008-04-24 21:44:26 +00:00
|
|
|
break;
|
2014-04-07 15:41:48 +00:00
|
|
|
err_status = status >> 8;
|
2008-04-24 21:44:26 +00:00
|
|
|
|
2014-04-07 15:41:48 +00:00
|
|
|
if (err_status != 0x03) { /* There was an error. */
|
2013-11-08 11:18:43 +00:00
|
|
|
printf("%s: Rx%d", dev->name, lp->cur_rx);
|
2014-04-07 15:41:48 +00:00
|
|
|
PCNET_DEBUG1(" (status=0x%x)", err_status);
|
|
|
|
if (err_status & 0x20)
|
2013-11-08 11:18:43 +00:00
|
|
|
printf(" Frame");
|
2014-04-07 15:41:48 +00:00
|
|
|
if (err_status & 0x10)
|
2013-11-08 11:18:43 +00:00
|
|
|
printf(" Overflow");
|
2014-04-07 15:41:48 +00:00
|
|
|
if (err_status & 0x08)
|
2013-11-08 11:18:43 +00:00
|
|
|
printf(" CRC");
|
2014-04-07 15:41:48 +00:00
|
|
|
if (err_status & 0x04)
|
2013-11-08 11:18:43 +00:00
|
|
|
printf(" Fifo");
|
|
|
|
printf(" Error\n");
|
2014-04-07 15:41:48 +00:00
|
|
|
status &= 0x03ff;
|
2008-04-24 21:44:26 +00:00
|
|
|
|
|
|
|
} else {
|
2014-04-07 15:41:48 +00:00
|
|
|
pkt_len = (readl(&entry->msg_length) & 0xfff) - 4;
|
2008-04-24 21:44:26 +00:00
|
|
|
if (pkt_len < 60) {
|
2013-11-08 11:18:43 +00:00
|
|
|
printf("%s: Rx%d: invalid packet length %d\n",
|
|
|
|
dev->name, lp->cur_rx, pkt_len);
|
2008-04-24 21:44:26 +00:00
|
|
|
} else {
|
2014-04-07 15:41:47 +00:00
|
|
|
buf = (*lp->rx_buf)[lp->cur_rx];
|
|
|
|
invalidate_dcache_range((unsigned long)buf,
|
|
|
|
(unsigned long)buf + pkt_len);
|
2015-04-08 06:41:06 +00:00
|
|
|
net_process_received_packet(buf, pkt_len);
|
2013-11-08 11:18:43 +00:00
|
|
|
PCNET_DEBUG2("Rx%d: %d bytes from 0x%p\n",
|
2014-04-07 15:41:47 +00:00
|
|
|
lp->cur_rx, pkt_len, buf);
|
2008-04-24 21:44:26 +00:00
|
|
|
}
|
|
|
|
}
|
2014-04-07 15:41:48 +00:00
|
|
|
|
|
|
|
status |= 0x8000;
|
|
|
|
writew(status, &entry->status);
|
2008-04-24 21:44:26 +00:00
|
|
|
|
|
|
|
if (++lp->cur_rx >= RX_RING_SIZE)
|
|
|
|
lp->cur_rx = 0;
|
|
|
|
}
|
|
|
|
return pkt_len;
|
2002-11-03 00:24:07 +00:00
|
|
|
}
|
|
|
|
|
2013-11-08 11:18:43 +00:00
|
|
|
static void pcnet_halt(struct eth_device *dev)
|
2008-04-24 21:44:26 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2013-11-08 11:18:43 +00:00
|
|
|
PCNET_DEBUG1("%s: pcnet_halt...\n", dev->name);
|
2008-04-24 21:44:26 +00:00
|
|
|
|
|
|
|
/* Reset the PCnet controller */
|
2013-11-08 11:18:43 +00:00
|
|
|
pcnet_reset(dev);
|
2008-04-24 21:44:26 +00:00
|
|
|
|
|
|
|
/* Wait for Stop bit */
|
|
|
|
for (i = 1000; i > 0; i--) {
|
2013-11-08 11:18:43 +00:00
|
|
|
if (pcnet_read_csr(dev, 0) & 0x4)
|
2008-04-24 21:44:26 +00:00
|
|
|
break;
|
2013-11-08 11:18:43 +00:00
|
|
|
udelay(10);
|
2008-04-24 21:44:26 +00:00
|
|
|
}
|
2013-11-08 11:18:43 +00:00
|
|
|
if (i <= 0)
|
|
|
|
printf("%s: TIMEOUT: controller reset failed\n", dev->name);
|
2008-04-24 21:44:26 +00:00
|
|
|
}
|