mirror of
https://github.com/Fishwaldo/u-boot.git
synced 2025-03-28 01:51:33 +00:00
NE2000: coding style cleanup
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
This commit is contained in:
parent
b4aff1ffaf
commit
4acbc6c7f9
4 changed files with 344 additions and 315 deletions
|
@ -83,18 +83,20 @@ void uboot_push_packet_len(int len);
|
||||||
void uboot_push_tx_done(int key, int val);
|
void uboot_push_tx_done(int key, int val);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
------------------------------------------------------------------------
|
* Debugging details
|
||||||
Debugging details
|
*
|
||||||
|
* Set to perms of:
|
||||||
Set to perms of:
|
* 0 disables all debug output
|
||||||
0 disables all debug output
|
* 1 for process debug output
|
||||||
1 for process debug output
|
* 2 for added data IO output: get_reg, put_reg
|
||||||
2 for added data IO output: get_reg, put_reg
|
* 4 for packet allocation/free output
|
||||||
4 for packet allocation/free output
|
* 8 for only startup status, so we can tell we're installed OK
|
||||||
8 for only startup status, so we can tell we're installed OK
|
*/
|
||||||
*/
|
#if 0
|
||||||
/*#define DEBUG 0xf*/
|
#define DEBUG 0xf
|
||||||
|
#else
|
||||||
#define DEBUG 0
|
#define DEBUG 0
|
||||||
|
#endif
|
||||||
|
|
||||||
#if DEBUG & 1
|
#if DEBUG & 1
|
||||||
#define DEBUG_FUNCTION() do { printf("%s\n", __FUNCTION__); } while (0)
|
#define DEBUG_FUNCTION() do { printf("%s\n", __FUNCTION__); } while (0)
|
||||||
|
@ -128,7 +130,8 @@ dp83902a_init(void)
|
||||||
DEBUG_FUNCTION();
|
DEBUG_FUNCTION();
|
||||||
|
|
||||||
base = dp->base;
|
base = dp->base;
|
||||||
if (!base) return false; /* No device found */
|
if (!base)
|
||||||
|
return false; /* No device found */
|
||||||
|
|
||||||
DEBUG_LINE();
|
DEBUG_LINE();
|
||||||
|
|
||||||
|
@ -170,11 +173,11 @@ dp83902a_stop(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
This function is called to "start up" the interface. It may be called
|
* This function is called to "start up" the interface. It may be called
|
||||||
multiple times, even when the hardware is already running. It will be
|
* multiple times, even when the hardware is already running. It will be
|
||||||
called whenever something "hardware oriented" changes and should leave
|
* called whenever something "hardware oriented" changes and should leave
|
||||||
the hardware ready to send/receive packets.
|
* the hardware ready to send/receive packets.
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
dp83902a_start(u8 * enaddr)
|
dp83902a_start(u8 * enaddr)
|
||||||
{
|
{
|
||||||
|
@ -196,9 +199,9 @@ dp83902a_start(u8 * enaddr)
|
||||||
dp->tx_started = false;
|
dp->tx_started = false;
|
||||||
dp->running = true;
|
dp->running = true;
|
||||||
DP_OUT(base, DP_PSTART, dp->rx_buf_start); /* Receive ring start page */
|
DP_OUT(base, DP_PSTART, dp->rx_buf_start); /* Receive ring start page */
|
||||||
DP_OUT(base, DP_BNDRY, dp->rx_buf_end-1); /* Receive ring boundary */
|
DP_OUT(base, DP_BNDRY, dp->rx_buf_end - 1); /* Receive ring boundary */
|
||||||
DP_OUT(base, DP_PSTOP, dp->rx_buf_end); /* Receive ring end page */
|
DP_OUT(base, DP_PSTOP, dp->rx_buf_end); /* Receive ring end page */
|
||||||
dp->rx_next = dp->rx_buf_start-1;
|
dp->rx_next = dp->rx_buf_start - 1;
|
||||||
dp->running = true;
|
dp->running = true;
|
||||||
DP_OUT(base, DP_ISR, 0xFF); /* Clear any pending interrupts */
|
DP_OUT(base, DP_ISR, 0xFF); /* Clear any pending interrupts */
|
||||||
DP_OUT(base, DP_IMR, DP_IMR_All); /* Enable all interrupts */
|
DP_OUT(base, DP_IMR, DP_IMR_All); /* Enable all interrupts */
|
||||||
|
@ -219,10 +222,10 @@ dp83902a_start(u8 * enaddr)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
This routine is called to start the transmitter. It is split out from the
|
* This routine is called to start the transmitter. It is split out from the
|
||||||
data handling routine so it may be called either when data becomes first
|
* data handling routine so it may be called either when data becomes first
|
||||||
available or when an Tx interrupt occurs
|
* available or when an Tx interrupt occurs
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static void
|
static void
|
||||||
dp83902a_start_xmit(int start_page, int len)
|
dp83902a_start_xmit(int start_page, int len)
|
||||||
|
@ -249,9 +252,9 @@ dp83902a_start_xmit(int start_page, int len)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
This routine is called to send data to the hardware. It is known a-priori
|
* This routine is called to send data to the hardware. It is known a-priori
|
||||||
that there is free buffer space (dp->tx_next).
|
* that there is free buffer space (dp->tx_next).
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
dp83902a_send(u8 *data, int total_len, u32 key)
|
dp83902a_send(u8 *data, int total_len, u32 key)
|
||||||
{
|
{
|
||||||
|
@ -265,7 +268,8 @@ dp83902a_send(u8 *data, int total_len, u32 key)
|
||||||
DEBUG_FUNCTION();
|
DEBUG_FUNCTION();
|
||||||
|
|
||||||
len = pkt_len = total_len;
|
len = pkt_len = total_len;
|
||||||
if (pkt_len < IEEE_8023_MIN_FRAME) pkt_len = IEEE_8023_MIN_FRAME;
|
if (pkt_len < IEEE_8023_MIN_FRAME)
|
||||||
|
pkt_len = IEEE_8023_MIN_FRAME;
|
||||||
|
|
||||||
start_page = dp->tx_next;
|
start_page = dp->tx_next;
|
||||||
if (dp->tx_next == dp->tx_buf1) {
|
if (dp->tx_next == dp->tx_buf1) {
|
||||||
|
@ -286,15 +290,17 @@ dp83902a_send(u8 *data, int total_len, u32 key)
|
||||||
|
|
||||||
DP_OUT(base, DP_ISR, DP_ISR_RDC); /* Clear end of DMA */
|
DP_OUT(base, DP_ISR, DP_ISR_RDC); /* Clear end of DMA */
|
||||||
{
|
{
|
||||||
/* Dummy read. The manual sez something slightly different, */
|
/*
|
||||||
/* but the code is extended a bit to do what Hitachi's monitor */
|
* Dummy read. The manual sez something slightly different,
|
||||||
/* does (i.e., also read data). */
|
* but the code is extended a bit to do what Hitachi's monitor
|
||||||
|
* does (i.e., also read data).
|
||||||
|
*/
|
||||||
|
|
||||||
u16 tmp;
|
u16 tmp;
|
||||||
int len = 1;
|
int len = 1;
|
||||||
|
|
||||||
DP_OUT(base, DP_RSAL, 0x100-len);
|
DP_OUT(base, DP_RSAL, 0x100 - len);
|
||||||
DP_OUT(base, DP_RSAH, (start_page-1) & 0xff);
|
DP_OUT(base, DP_RSAH, (start_page - 1) & 0xff);
|
||||||
DP_OUT(base, DP_RBCL, len);
|
DP_OUT(base, DP_RBCL, len);
|
||||||
DP_OUT(base, DP_RBCH, 0);
|
DP_OUT(base, DP_RBCH, 0);
|
||||||
DP_OUT(base, DP_CR, DP_CR_PAGE0 | DP_CR_RDMA | DP_CR_START);
|
DP_OUT(base, DP_CR, DP_CR_PAGE0 | DP_CR_RDMA | DP_CR_START);
|
||||||
|
@ -302,8 +308,10 @@ dp83902a_send(u8 *data, int total_len, u32 key)
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CYGHWR_NS_DP83902A_PLF_BROKEN_TX_DMA
|
#ifdef CYGHWR_NS_DP83902A_PLF_BROKEN_TX_DMA
|
||||||
/* Stall for a bit before continuing to work around random data */
|
/*
|
||||||
/* corruption problems on some platforms. */
|
* Stall for a bit before continuing to work around random data
|
||||||
|
* corruption problems on some platforms.
|
||||||
|
*/
|
||||||
CYGACC_CALL_IF_DELAY_US(1);
|
CYGACC_CALL_IF_DELAY_US(1);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -343,9 +351,11 @@ dp83902a_send(u8 *data, int total_len, u32 key)
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CYGHWR_NS_DP83902A_PLF_BROKEN_TX_DMA
|
#ifdef CYGHWR_NS_DP83902A_PLF_BROKEN_TX_DMA
|
||||||
/* After last data write, delay for a bit before accessing the */
|
/*
|
||||||
/* device again, or we may get random data corruption in the last */
|
* After last data write, delay for a bit before accessing the
|
||||||
/* datum (on some platforms). */
|
* device again, or we may get random data corruption in the last
|
||||||
|
* datum (on some platforms).
|
||||||
|
*/
|
||||||
CYGACC_CALL_IF_DELAY_US(1);
|
CYGACC_CALL_IF_DELAY_US(1);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -369,12 +379,12 @@ dp83902a_send(u8 *data, int total_len, u32 key)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
This function is called when a packet has been received. It's job is
|
* This function is called when a packet has been received. It's job is
|
||||||
to prepare to unload the packet from the hardware. Once the length of
|
* to prepare to unload the packet from the hardware. Once the length of
|
||||||
the packet is known, the upper layer of the driver can be told. When
|
* the packet is known, the upper layer of the driver can be told. When
|
||||||
the upper layer is ready to unload the packet, the internal function
|
* the upper layer is ready to unload the packet, the internal function
|
||||||
'dp83902a_recv' will be called to actually fetch it from the hardware.
|
* 'dp83902a_recv' will be called to actually fetch it from the hardware.
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
dp83902a_RxEvent(void)
|
dp83902a_RxEvent(void)
|
||||||
{
|
{
|
||||||
|
@ -407,9 +417,9 @@ dp83902a_RxEvent(void)
|
||||||
DP_OUT(base, DP_RSAH, pkt);
|
DP_OUT(base, DP_RSAH, pkt);
|
||||||
if (dp->rx_next == pkt) {
|
if (dp->rx_next == pkt) {
|
||||||
if (cur == dp->rx_buf_start)
|
if (cur == dp->rx_buf_start)
|
||||||
DP_OUT(base, DP_BNDRY, dp->rx_buf_end-1);
|
DP_OUT(base, DP_BNDRY, dp->rx_buf_end - 1);
|
||||||
else
|
else
|
||||||
DP_OUT(base, DP_BNDRY, cur-1); /* Update pointer */
|
DP_OUT(base, DP_BNDRY, cur - 1); /* Update pointer */
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
dp->rx_next = pkt;
|
dp->rx_next = pkt;
|
||||||
|
@ -434,19 +444,19 @@ dp83902a_RxEvent(void)
|
||||||
uboot_push_packet_len(len);
|
uboot_push_packet_len(len);
|
||||||
|
|
||||||
if (rcv_hdr[1] == dp->rx_buf_start)
|
if (rcv_hdr[1] == dp->rx_buf_start)
|
||||||
DP_OUT(base, DP_BNDRY, dp->rx_buf_end-1);
|
DP_OUT(base, DP_BNDRY, dp->rx_buf_end - 1);
|
||||||
else
|
else
|
||||||
DP_OUT(base, DP_BNDRY, rcv_hdr[1]-1); /* Update pointer */
|
DP_OUT(base, DP_BNDRY, rcv_hdr[1] - 1); /* Update pointer */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
This function is called as a result of the "eth_drv_recv()" call above.
|
* This function is called as a result of the "eth_drv_recv()" call above.
|
||||||
It's job is to actually fetch data for a packet from the hardware once
|
* It's job is to actually fetch data for a packet from the hardware once
|
||||||
memory buffers have been allocated for the packet. Note that the buffers
|
* memory buffers have been allocated for the packet. Note that the buffers
|
||||||
may come in pieces, using a scatter-gather list. This allows for more
|
* may come in pieces, using a scatter-gather list. This allows for more
|
||||||
efficient processing in the upper layers of the stack.
|
* efficient processing in the upper layers of the stack.
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
dp83902a_recv(u8 *data, int len)
|
dp83902a_recv(u8 *data, int len)
|
||||||
{
|
{
|
||||||
|
@ -545,8 +555,10 @@ dp83902a_TxEvent(void)
|
||||||
uboot_push_tx_done(key, 0);
|
uboot_push_tx_done(key, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Read the tally counters to clear them. Called in response to a CNT */
|
/*
|
||||||
/* interrupt. */
|
* Read the tally counters to clear them. Called in response to a CNT
|
||||||
|
* interrupt.
|
||||||
|
*/
|
||||||
static void
|
static void
|
||||||
dp83902a_ClearCounters(void)
|
dp83902a_ClearCounters(void)
|
||||||
{
|
{
|
||||||
|
@ -560,8 +572,10 @@ dp83902a_ClearCounters(void)
|
||||||
DP_OUT(base, DP_ISR, DP_ISR_CNT);
|
DP_OUT(base, DP_ISR, DP_ISR_CNT);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Deal with an overflow condition. This code follows the procedure set */
|
/*
|
||||||
/* out in section 7.0 of the datasheet. */
|
* Deal with an overflow condition. This code follows the procedure set
|
||||||
|
* out in section 7.0 of the datasheet.
|
||||||
|
*/
|
||||||
static void
|
static void
|
||||||
dp83902a_Overflow(void)
|
dp83902a_Overflow(void)
|
||||||
{
|
{
|
||||||
|
@ -581,9 +595,11 @@ dp83902a_Overflow(void)
|
||||||
DP_OUT(base, DP_TCR, DP_TCR_LOCAL);
|
DP_OUT(base, DP_TCR, DP_TCR_LOCAL);
|
||||||
DP_OUT(base, DP_CR, DP_CR_START | DP_CR_NODMA);
|
DP_OUT(base, DP_CR, DP_CR_START | DP_CR_NODMA);
|
||||||
|
|
||||||
/* Read in as many packets as we can and acknowledge any and receive */
|
/*
|
||||||
/* interrupts. Since the buffer has overflowed, a receive event of */
|
* Read in as many packets as we can and acknowledge any and receive
|
||||||
/* some kind will have occured. */
|
* interrupts. Since the buffer has overflowed, a receive event of
|
||||||
|
* some kind will have occured.
|
||||||
|
*/
|
||||||
dp83902a_RxEvent();
|
dp83902a_RxEvent();
|
||||||
DP_OUT(base, DP_ISR, DP_ISR_RxP|DP_ISR_RxE);
|
DP_OUT(base, DP_ISR, DP_ISR_RxP|DP_ISR_RxE);
|
||||||
|
|
||||||
|
@ -591,8 +607,10 @@ dp83902a_Overflow(void)
|
||||||
DP_OUT(base, DP_ISR, DP_ISR_OFLW);
|
DP_OUT(base, DP_ISR, DP_ISR_OFLW);
|
||||||
DP_OUT(base, DP_TCR, DP_TCR_NORMAL);
|
DP_OUT(base, DP_TCR, DP_TCR_NORMAL);
|
||||||
|
|
||||||
/* If a transmit command was issued, but no transmit event has occured, */
|
/*
|
||||||
/* restart it here. */
|
* If a transmit command was issued, but no transmit event has occured,
|
||||||
|
* restart it here.
|
||||||
|
*/
|
||||||
DP_IN(base, DP_ISR, isr);
|
DP_IN(base, DP_ISR, isr);
|
||||||
if (dp->tx_started && !(isr & (DP_ISR_TxP|DP_ISR_TxE))) {
|
if (dp->tx_started && !(isr & (DP_ISR_TxP|DP_ISR_TxE))) {
|
||||||
DP_OUT(base, DP_CR, DP_CR_NODMA | DP_CR_TXPKT | DP_CR_START);
|
DP_OUT(base, DP_CR, DP_CR_NODMA | DP_CR_TXPKT | DP_CR_START);
|
||||||
|
@ -609,25 +627,33 @@ dp83902a_poll(void)
|
||||||
DP_OUT(base, DP_CR, DP_CR_NODMA | DP_CR_PAGE0 | DP_CR_START);
|
DP_OUT(base, DP_CR, DP_CR_NODMA | DP_CR_PAGE0 | DP_CR_START);
|
||||||
DP_IN(base, DP_ISR, isr);
|
DP_IN(base, DP_ISR, isr);
|
||||||
while (0 != isr) {
|
while (0 != isr) {
|
||||||
/* The CNT interrupt triggers when the MSB of one of the error */
|
/*
|
||||||
/* counters is set. We don't much care about these counters, but */
|
* The CNT interrupt triggers when the MSB of one of the error
|
||||||
/* we should read their values to reset them. */
|
* counters is set. We don't much care about these counters, but
|
||||||
|
* we should read their values to reset them.
|
||||||
|
*/
|
||||||
if (isr & DP_ISR_CNT) {
|
if (isr & DP_ISR_CNT) {
|
||||||
dp83902a_ClearCounters();
|
dp83902a_ClearCounters();
|
||||||
}
|
}
|
||||||
/* Check for overflow. It's a special case, since there's a */
|
/*
|
||||||
/* particular procedure that must be followed to get back into */
|
* Check for overflow. It's a special case, since there's a
|
||||||
/* a running state.a */
|
* particular procedure that must be followed to get back into
|
||||||
|
* a running state.a
|
||||||
|
*/
|
||||||
if (isr & DP_ISR_OFLW) {
|
if (isr & DP_ISR_OFLW) {
|
||||||
dp83902a_Overflow();
|
dp83902a_Overflow();
|
||||||
} else {
|
} else {
|
||||||
/* Other kinds of interrupts can be acknowledged simply by */
|
/*
|
||||||
/* clearing the relevant bits of the ISR. Do that now, then */
|
* Other kinds of interrupts can be acknowledged simply by
|
||||||
/* handle the interrupts we care about. */
|
* clearing the relevant bits of the ISR. Do that now, then
|
||||||
|
* handle the interrupts we care about.
|
||||||
|
*/
|
||||||
DP_OUT(base, DP_ISR, isr); /* Clear set bits */
|
DP_OUT(base, DP_ISR, isr); /* Clear set bits */
|
||||||
if (!dp->running) break; /* Is this necessary? */
|
if (!dp->running) break; /* Is this necessary? */
|
||||||
/* Check for tx_started on TX event since these may happen */
|
/*
|
||||||
/* spuriously it seems. */
|
* Check for tx_started on TX event since these may happen
|
||||||
|
* spuriously it seems.
|
||||||
|
*/
|
||||||
if (isr & (DP_ISR_TxP|DP_ISR_TxE) && dp->tx_started) {
|
if (isr & (DP_ISR_TxP|DP_ISR_TxE) && dp->tx_started) {
|
||||||
dp83902a_TxEvent();
|
dp83902a_TxEvent();
|
||||||
}
|
}
|
||||||
|
@ -744,11 +770,11 @@ u32 nic_base;
|
||||||
static u8 *pbuf = NULL;
|
static u8 *pbuf = NULL;
|
||||||
|
|
||||||
static int pkey = -1;
|
static int pkey = -1;
|
||||||
static int initialized=0;
|
static int initialized = 0;
|
||||||
|
|
||||||
void uboot_push_packet_len(int len) {
|
void uboot_push_packet_len(int len) {
|
||||||
PRINTK("pushed len = %d\n", len);
|
PRINTK("pushed len = %d\n", len);
|
||||||
if (len>=2000) {
|
if (len >= 2000) {
|
||||||
printf("NE2000: packet too big\n");
|
printf("NE2000: packet too big\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -811,7 +837,7 @@ int eth_init(bd_t *bd) {
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
dp83902a_start(dev_addr);
|
dp83902a_start(dev_addr);
|
||||||
initialized=1;
|
initialized = 1;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -821,7 +847,7 @@ void eth_halt() {
|
||||||
PRINTK("### eth_halt\n");
|
PRINTK("### eth_halt\n");
|
||||||
if(initialized)
|
if(initialized)
|
||||||
dp83902a_stop();
|
dp83902a_stop();
|
||||||
initialized=0;
|
initialized = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int eth_rx() {
|
int eth_rx() {
|
||||||
|
|
|
@ -76,6 +76,9 @@ are GPL, so this is, of course, GPL.
|
||||||
These can be overridden by the platform header
|
These can be overridden by the platform header
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifndef __NE2000_BASE_H__
|
||||||
|
#define __NE2000_BASE_H__
|
||||||
|
|
||||||
#define bool int
|
#define bool int
|
||||||
|
|
||||||
#define false 0
|
#define false 0
|
||||||
|
@ -117,9 +120,8 @@ typedef struct dp83902a_priv_data {
|
||||||
} dp83902a_priv_data_t;
|
} dp83902a_priv_data_t;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
------------------------------------------------------------------------
|
* Some forward declarations
|
||||||
Some forward declarations
|
*/
|
||||||
*/
|
|
||||||
int get_prom( u8* mac_addr);
|
int get_prom( u8* mac_addr);
|
||||||
static void dp83902a_poll(void);
|
static void dp83902a_poll(void);
|
||||||
|
|
||||||
|
@ -280,3 +282,4 @@ static void dp83902a_poll(void);
|
||||||
|
|
||||||
#define IEEE_8023_MAX_FRAME 1518 /* Largest possible ethernet frame */
|
#define IEEE_8023_MAX_FRAME 1518 /* Largest possible ethernet frame */
|
||||||
#define IEEE_8023_MIN_FRAME 64 /* Smallest possible ethernet frame */
|
#define IEEE_8023_MIN_FRAME 64 /* Smallest possible ethernet frame */
|
||||||
|
#endif /* __NE2000_BASE_H__ */
|
||||||
|
|
Loading…
Add table
Reference in a new issue