|
@@ -63,14 +63,10 @@
|
|
/* Recv interrupt enable bit */
|
|
/* Recv interrupt enable bit */
|
|
#define XEL_RSR_RECV_IE_MASK 0x00000008UL
|
|
#define XEL_RSR_RECV_IE_MASK 0x00000008UL
|
|
|
|
|
|
-typedef struct {
|
|
|
|
- u32 baseaddress; /* Base address for device (IPIF) */
|
|
|
|
|
|
+struct xemaclite {
|
|
u32 nexttxbuffertouse; /* Next TX buffer to write to */
|
|
u32 nexttxbuffertouse; /* Next TX buffer to write to */
|
|
u32 nextrxbuffertouse; /* Next RX buffer to read from */
|
|
u32 nextrxbuffertouse; /* Next RX buffer to read from */
|
|
- uchar deviceid; /* Unique ID of device - for future */
|
|
|
|
-} xemaclite;
|
|
|
|
-
|
|
|
|
-static xemaclite emaclite;
|
|
|
|
|
|
+};
|
|
|
|
|
|
static u32 etherrxbuff[PKTSIZE_ALIGN/4]; /* Receive buffer */
|
|
static u32 etherrxbuff[PKTSIZE_ALIGN/4]; /* Receive buffer */
|
|
|
|
|
|
@@ -136,44 +132,44 @@ static void emaclite_halt(struct eth_device *dev)
|
|
static int emaclite_init(struct eth_device *dev, bd_t *bis)
|
|
static int emaclite_init(struct eth_device *dev, bd_t *bis)
|
|
{
|
|
{
|
|
debug ("EmacLite Initialization Started\n");
|
|
debug ("EmacLite Initialization Started\n");
|
|
- memset (&emaclite, 0, sizeof (xemaclite));
|
|
|
|
- emaclite.baseaddress = dev->iobase;
|
|
|
|
|
|
|
|
/*
|
|
/*
|
|
* TX - TX_PING & TX_PONG initialization
|
|
* TX - TX_PING & TX_PONG initialization
|
|
*/
|
|
*/
|
|
/* Restart PING TX */
|
|
/* Restart PING TX */
|
|
- out_be32 (emaclite.baseaddress + XEL_TSR_OFFSET, 0);
|
|
|
|
|
|
+ out_be32 (dev->iobase + XEL_TSR_OFFSET, 0);
|
|
/* Copy MAC address */
|
|
/* Copy MAC address */
|
|
xemaclite_alignedwrite (dev->enetaddr,
|
|
xemaclite_alignedwrite (dev->enetaddr,
|
|
- emaclite.baseaddress, ENET_ADDR_LENGTH);
|
|
|
|
|
|
+ dev->iobase, ENET_ADDR_LENGTH);
|
|
/* Set the length */
|
|
/* Set the length */
|
|
- out_be32 (emaclite.baseaddress + XEL_TPLR_OFFSET, ENET_ADDR_LENGTH);
|
|
|
|
|
|
+ out_be32 (dev->iobase + XEL_TPLR_OFFSET, ENET_ADDR_LENGTH);
|
|
/* Update the MAC address in the EMAC Lite */
|
|
/* Update the MAC address in the EMAC Lite */
|
|
- out_be32 (emaclite.baseaddress + XEL_TSR_OFFSET, XEL_TSR_PROG_MAC_ADDR);
|
|
|
|
|
|
+ out_be32 (dev->iobase + XEL_TSR_OFFSET, XEL_TSR_PROG_MAC_ADDR);
|
|
/* Wait for EMAC Lite to finish with the MAC address update */
|
|
/* Wait for EMAC Lite to finish with the MAC address update */
|
|
- while ((in_be32 (emaclite.baseaddress + XEL_TSR_OFFSET) &
|
|
|
|
- XEL_TSR_PROG_MAC_ADDR) != 0) ;
|
|
|
|
|
|
+ while ((in_be32 (dev->iobase + XEL_TSR_OFFSET) &
|
|
|
|
+ XEL_TSR_PROG_MAC_ADDR) != 0)
|
|
|
|
+ ;
|
|
|
|
|
|
#ifdef CONFIG_XILINX_EMACLITE_TX_PING_PONG
|
|
#ifdef CONFIG_XILINX_EMACLITE_TX_PING_PONG
|
|
/* The same operation with PONG TX */
|
|
/* The same operation with PONG TX */
|
|
- out_be32 (emaclite.baseaddress + XEL_TSR_OFFSET + XEL_BUFFER_OFFSET, 0);
|
|
|
|
- xemaclite_alignedwrite (dev->enetaddr, emaclite.baseaddress +
|
|
|
|
|
|
+ out_be32 (dev->iobase + XEL_TSR_OFFSET + XEL_BUFFER_OFFSET, 0);
|
|
|
|
+ xemaclite_alignedwrite(dev->enetaddr, dev->iobase +
|
|
XEL_BUFFER_OFFSET, ENET_ADDR_LENGTH);
|
|
XEL_BUFFER_OFFSET, ENET_ADDR_LENGTH);
|
|
- out_be32 (emaclite.baseaddress + XEL_TPLR_OFFSET, ENET_ADDR_LENGTH);
|
|
|
|
- out_be32 (emaclite.baseaddress + XEL_TSR_OFFSET + XEL_BUFFER_OFFSET,
|
|
|
|
|
|
+ out_be32 (dev->iobase + XEL_TPLR_OFFSET, ENET_ADDR_LENGTH);
|
|
|
|
+ out_be32 (dev->iobase + XEL_TSR_OFFSET + XEL_BUFFER_OFFSET,
|
|
XEL_TSR_PROG_MAC_ADDR);
|
|
XEL_TSR_PROG_MAC_ADDR);
|
|
- while ((in_be32 (emaclite.baseaddress + XEL_TSR_OFFSET +
|
|
|
|
- XEL_BUFFER_OFFSET) & XEL_TSR_PROG_MAC_ADDR) != 0) ;
|
|
|
|
|
|
+ while ((in_be32 (dev->iobase + XEL_TSR_OFFSET +
|
|
|
|
+ XEL_BUFFER_OFFSET) & XEL_TSR_PROG_MAC_ADDR) != 0)
|
|
|
|
+ ;
|
|
#endif
|
|
#endif
|
|
|
|
|
|
/*
|
|
/*
|
|
* RX - RX_PING & RX_PONG initialization
|
|
* RX - RX_PING & RX_PONG initialization
|
|
*/
|
|
*/
|
|
/* Write out the value to flush the RX buffer */
|
|
/* Write out the value to flush the RX buffer */
|
|
- out_be32 (emaclite.baseaddress + XEL_RSR_OFFSET, XEL_RSR_RECV_IE_MASK);
|
|
|
|
|
|
+ out_be32 (dev->iobase + XEL_RSR_OFFSET, XEL_RSR_RECV_IE_MASK);
|
|
#ifdef CONFIG_XILINX_EMACLITE_RX_PING_PONG
|
|
#ifdef CONFIG_XILINX_EMACLITE_RX_PING_PONG
|
|
- out_be32 (emaclite.baseaddress + XEL_RSR_OFFSET + XEL_BUFFER_OFFSET,
|
|
|
|
|
|
+ out_be32 (dev->iobase + XEL_RSR_OFFSET + XEL_BUFFER_OFFSET,
|
|
XEL_RSR_RECV_IE_MASK);
|
|
XEL_RSR_RECV_IE_MASK);
|
|
#endif
|
|
#endif
|
|
|
|
|
|
@@ -181,22 +177,24 @@ static int emaclite_init(struct eth_device *dev, bd_t *bis)
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
|
|
-static int xemaclite_txbufferavailable (xemaclite *instanceptr)
|
|
|
|
|
|
+static int xemaclite_txbufferavailable(struct eth_device *dev)
|
|
{
|
|
{
|
|
u32 reg;
|
|
u32 reg;
|
|
u32 txpingbusy;
|
|
u32 txpingbusy;
|
|
u32 txpongbusy;
|
|
u32 txpongbusy;
|
|
|
|
+ struct xemaclite *emaclite = dev->priv;
|
|
|
|
+
|
|
/*
|
|
/*
|
|
* Read the other buffer register
|
|
* Read the other buffer register
|
|
* and determine if the other buffer is available
|
|
* and determine if the other buffer is available
|
|
*/
|
|
*/
|
|
- reg = in_be32 (instanceptr->baseaddress +
|
|
|
|
- instanceptr->nexttxbuffertouse + 0);
|
|
|
|
|
|
+ reg = in_be32 (dev->iobase +
|
|
|
|
+ emaclite->nexttxbuffertouse + 0);
|
|
txpingbusy = ((reg & XEL_TSR_XMIT_BUSY_MASK) ==
|
|
txpingbusy = ((reg & XEL_TSR_XMIT_BUSY_MASK) ==
|
|
XEL_TSR_XMIT_BUSY_MASK);
|
|
XEL_TSR_XMIT_BUSY_MASK);
|
|
|
|
|
|
- reg = in_be32 (instanceptr->baseaddress +
|
|
|
|
- (instanceptr->nexttxbuffertouse ^ XEL_TSR_OFFSET) + 0);
|
|
|
|
|
|
+ reg = in_be32 (dev->iobase +
|
|
|
|
+ (emaclite->nexttxbuffertouse ^ XEL_TSR_OFFSET) + 0);
|
|
txpongbusy = ((reg & XEL_TSR_XMIT_BUSY_MASK) ==
|
|
txpongbusy = ((reg & XEL_TSR_XMIT_BUSY_MASK) ==
|
|
XEL_TSR_XMIT_BUSY_MASK);
|
|
XEL_TSR_XMIT_BUSY_MASK);
|
|
|
|
|
|
@@ -207,13 +205,14 @@ static int emaclite_send (struct eth_device *dev, volatile void *ptr, int len)
|
|
{
|
|
{
|
|
u32 reg;
|
|
u32 reg;
|
|
u32 baseaddress;
|
|
u32 baseaddress;
|
|
|
|
+ struct xemaclite *emaclite = dev->priv;
|
|
|
|
|
|
u32 maxtry = 1000;
|
|
u32 maxtry = 1000;
|
|
|
|
|
|
if (len > ENET_MAX_MTU)
|
|
if (len > ENET_MAX_MTU)
|
|
len = ENET_MAX_MTU;
|
|
len = ENET_MAX_MTU;
|
|
|
|
|
|
- while (!xemaclite_txbufferavailable (&emaclite) && maxtry) {
|
|
|
|
|
|
+ while (!xemaclite_txbufferavailable(dev) && maxtry) {
|
|
udelay (10);
|
|
udelay (10);
|
|
maxtry--;
|
|
maxtry--;
|
|
}
|
|
}
|
|
@@ -221,16 +220,16 @@ static int emaclite_send (struct eth_device *dev, volatile void *ptr, int len)
|
|
if (!maxtry) {
|
|
if (!maxtry) {
|
|
printf ("Error: Timeout waiting for ethernet TX buffer\n");
|
|
printf ("Error: Timeout waiting for ethernet TX buffer\n");
|
|
/* Restart PING TX */
|
|
/* Restart PING TX */
|
|
- out_be32 (emaclite.baseaddress + XEL_TSR_OFFSET, 0);
|
|
|
|
|
|
+ out_be32 (dev->iobase + XEL_TSR_OFFSET, 0);
|
|
#ifdef CONFIG_XILINX_EMACLITE_TX_PING_PONG
|
|
#ifdef CONFIG_XILINX_EMACLITE_TX_PING_PONG
|
|
- out_be32 (emaclite.baseaddress + XEL_TSR_OFFSET +
|
|
|
|
|
|
+ out_be32 (dev->iobase + XEL_TSR_OFFSET +
|
|
XEL_BUFFER_OFFSET, 0);
|
|
XEL_BUFFER_OFFSET, 0);
|
|
#endif
|
|
#endif
|
|
return -1;
|
|
return -1;
|
|
}
|
|
}
|
|
|
|
|
|
/* Determine the expected TX buffer address */
|
|
/* Determine the expected TX buffer address */
|
|
- baseaddress = (emaclite.baseaddress + emaclite.nexttxbuffertouse);
|
|
|
|
|
|
+ baseaddress = (dev->iobase + emaclite->nexttxbuffertouse);
|
|
|
|
|
|
/* Determine if the expected buffer address is empty */
|
|
/* Determine if the expected buffer address is empty */
|
|
reg = in_be32 (baseaddress + XEL_TSR_OFFSET);
|
|
reg = in_be32 (baseaddress + XEL_TSR_OFFSET);
|
|
@@ -239,7 +238,7 @@ static int emaclite_send (struct eth_device *dev, volatile void *ptr, int len)
|
|
& XEL_TSR_XMIT_ACTIVE_MASK) == 0)) {
|
|
& XEL_TSR_XMIT_ACTIVE_MASK) == 0)) {
|
|
|
|
|
|
#ifdef CONFIG_XILINX_EMACLITE_TX_PING_PONG
|
|
#ifdef CONFIG_XILINX_EMACLITE_TX_PING_PONG
|
|
- emaclite.nexttxbuffertouse ^= XEL_BUFFER_OFFSET;
|
|
|
|
|
|
+ emaclite->nexttxbuffertouse ^= XEL_BUFFER_OFFSET;
|
|
#endif
|
|
#endif
|
|
debug ("Send packet from 0x%x\n", baseaddress);
|
|
debug ("Send packet from 0x%x\n", baseaddress);
|
|
/* Write the frame to the buffer */
|
|
/* Write the frame to the buffer */
|
|
@@ -262,7 +261,7 @@ static int emaclite_send (struct eth_device *dev, volatile void *ptr, int len)
|
|
if (((reg & XEL_TSR_XMIT_BUSY_MASK) == 0)
|
|
if (((reg & XEL_TSR_XMIT_BUSY_MASK) == 0)
|
|
&& ((in_be32 ((baseaddress) + XEL_TSR_OFFSET)
|
|
&& ((in_be32 ((baseaddress) + XEL_TSR_OFFSET)
|
|
& XEL_TSR_XMIT_ACTIVE_MASK) == 0)) {
|
|
& XEL_TSR_XMIT_ACTIVE_MASK) == 0)) {
|
|
- debug ("Send packet from 0x%x\n", baseaddress);
|
|
|
|
|
|
+ debug("Send packet from 0x%x\n", baseaddress);
|
|
/* Write the frame to the buffer */
|
|
/* Write the frame to the buffer */
|
|
xemaclite_alignedwrite ((void *) ptr, baseaddress, len);
|
|
xemaclite_alignedwrite ((void *) ptr, baseaddress, len);
|
|
out_be32 (baseaddress + XEL_TPLR_OFFSET,(len &
|
|
out_be32 (baseaddress + XEL_TPLR_OFFSET,(len &
|
|
@@ -285,13 +284,14 @@ static int emaclite_recv(struct eth_device *dev)
|
|
u32 length;
|
|
u32 length;
|
|
u32 reg;
|
|
u32 reg;
|
|
u32 baseaddress;
|
|
u32 baseaddress;
|
|
|
|
+ struct xemaclite *emaclite = dev->priv;
|
|
|
|
|
|
- baseaddress = emaclite.baseaddress + emaclite.nextrxbuffertouse;
|
|
|
|
|
|
+ baseaddress = dev->iobase + emaclite->nextrxbuffertouse;
|
|
reg = in_be32 (baseaddress + XEL_RSR_OFFSET);
|
|
reg = in_be32 (baseaddress + XEL_RSR_OFFSET);
|
|
debug ("Testing data at address 0x%x\n", baseaddress);
|
|
debug ("Testing data at address 0x%x\n", baseaddress);
|
|
if ((reg & XEL_RSR_RECV_DONE_MASK) == XEL_RSR_RECV_DONE_MASK) {
|
|
if ((reg & XEL_RSR_RECV_DONE_MASK) == XEL_RSR_RECV_DONE_MASK) {
|
|
#ifdef CONFIG_XILINX_EMACLITE_RX_PING_PONG
|
|
#ifdef CONFIG_XILINX_EMACLITE_RX_PING_PONG
|
|
- emaclite.nextrxbuffertouse ^= XEL_BUFFER_OFFSET;
|
|
|
|
|
|
+ emaclite->nextrxbuffertouse ^= XEL_BUFFER_OFFSET;
|
|
#endif
|
|
#endif
|
|
} else {
|
|
} else {
|
|
#ifndef CONFIG_XILINX_EMACLITE_RX_PING_PONG
|
|
#ifndef CONFIG_XILINX_EMACLITE_RX_PING_PONG
|
|
@@ -344,16 +344,23 @@ static int emaclite_recv(struct eth_device *dev)
|
|
int xilinx_emaclite_initialize (bd_t *bis, int base_addr)
|
|
int xilinx_emaclite_initialize (bd_t *bis, int base_addr)
|
|
{
|
|
{
|
|
struct eth_device *dev;
|
|
struct eth_device *dev;
|
|
|
|
+ struct xemaclite *emaclite;
|
|
|
|
|
|
- dev = malloc(sizeof(*dev));
|
|
|
|
|
|
+ dev = calloc(1, sizeof(*dev));
|
|
if (dev == NULL)
|
|
if (dev == NULL)
|
|
return -1;
|
|
return -1;
|
|
|
|
|
|
- memset(dev, 0, sizeof(*dev));
|
|
|
|
- sprintf(dev->name, "Xilinx_Emaclite");
|
|
|
|
|
|
+ emaclite = calloc(1, sizeof(struct xemaclite));
|
|
|
|
+ if (emaclite == NULL) {
|
|
|
|
+ free(dev);
|
|
|
|
+ return -1;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ dev->priv = emaclite;
|
|
|
|
+
|
|
|
|
+ sprintf(dev->name, "Xelite.%x", base_addr);
|
|
|
|
|
|
dev->iobase = base_addr;
|
|
dev->iobase = base_addr;
|
|
- dev->priv = 0;
|
|
|
|
dev->init = emaclite_init;
|
|
dev->init = emaclite_init;
|
|
dev->halt = emaclite_halt;
|
|
dev->halt = emaclite_halt;
|
|
dev->send = emaclite_send;
|
|
dev->send = emaclite_send;
|