cleaned up

This commit is contained in:
Markus Fröschle
2014-01-02 06:35:15 +00:00
parent 225c53cf57
commit 2a4cd2de88

View File

@@ -201,7 +201,7 @@ void fec_mii_init(uint8_t ch, uint32_t sys_clk)
*/ */
void fec_mib_init(uint8_t ch) void fec_mib_init(uint8_t ch)
{ {
//To do //To do
} }
/********************************************************************/ /********************************************************************/
@@ -212,7 +212,7 @@ void fec_mib_init(uint8_t ch)
*/ */
void fec_mib_dump(uint8_t ch) void fec_mib_dump(uint8_t ch)
{ {
//To do //To do
} }
/********************************************************************/ /********************************************************************/
@@ -344,7 +344,7 @@ uint8_t fec_hash_address(const uint8_t *addr)
byte = addr[i]; byte = addr[i];
for (j = 0; j < 8; ++j) for (j = 0; j < 8; ++j)
{ {
if ((byte & 0x01)^(crc & 0x01)) if ((byte & 0x01) ^ (crc & 0x01))
{ {
crc >>= 1; crc >>= 1;
crc = crc ^ 0xEDB88320; crc = crc ^ 0xEDB88320;
@@ -366,15 +366,15 @@ uint8_t fec_hash_address(const uint8_t *addr)
* ch FEC channel * ch FEC channel
* pa Physical (Hardware) Address for the selected FEC * pa Physical (Hardware) Address for the selected FEC
*/ */
void fec_set_address (uint8_t ch, const uint8_t *pa) void fec_set_address(uint8_t ch, const uint8_t *pa)
{ {
uint8_t crc; uint8_t crc;
/* /*
* Set the Physical Address * Set the Physical Address
*/ */
MCF_FEC_PALR(ch) = (uint32_t)((pa[0] << 24) | (pa[1] << 16) | (pa[2] << 8) | pa[3]); MCF_FEC_PALR(ch) = (uint32_t) ((pa[0] << 24) | (pa[1] << 16) | (pa[2] << 8) | pa[3]);
MCF_FEC_PAHR(ch) = (uint32_t)((pa[4] << 24) | (pa[5] << 16)); MCF_FEC_PAHR(ch) = (uint32_t) ((pa[4] << 24) | (pa[5] << 16));
/* /*
* Calculate and set the hash for given Physical Address * Calculate and set the hash for given Physical Address
@@ -382,9 +382,9 @@ void fec_set_address (uint8_t ch, const uint8_t *pa)
*/ */
crc = fec_hash_address(pa); crc = fec_hash_address(pa);
if(crc >= 32) if(crc >= 32)
MCF_FEC_IAUR(ch) |= (uint32_t)(1 << (crc - 32)); MCF_FEC_IAUR(ch) |= (uint32_t) (1 << (crc - 32));
else else
MCF_FEC_IALR(ch) |= (uint32_t)(1 << crc); MCF_FEC_IALR(ch) |= (uint32_t) (1 << crc);
} }
/********************************************************************/ /********************************************************************/
@@ -489,9 +489,9 @@ void fec_init(uint8_t ch, uint8_t mode, const uint8_t *pa)
*/ */
MCF_FEC_RCR(ch) = 0 MCF_FEC_RCR(ch) = 0
| MCF_FEC_RCR_MAX_FL(ETH_MAX_FRM) | MCF_FEC_RCR_MAX_FL(ETH_MAX_FRM)
#ifdef FEC_PROMISCUOUS #ifdef FEC_PROMISCUOUS
| MCF_FEC_RCR_PROM | MCF_FEC_RCR_PROM
#endif #endif
| MCF_FEC_RCR_FCE; | MCF_FEC_RCR_FCE;
if (mode == FEC_MODE_MII) if (mode == FEC_MODE_MII)
@@ -543,7 +543,10 @@ void fec_init(uint8_t ch, uint8_t mode, const uint8_t *pa)
void fec_rx_start(uint8_t ch, int8_t *rxbd) void fec_rx_start(uint8_t ch, int8_t *rxbd)
{ {
uint32_t initiator; uint32_t initiator;
int channel, result; int channel;
int result;
(void) result; /* to avoid compiler warning */
/* /*
* Make the initiator assignment * Make the initiator assignment
@@ -608,6 +611,7 @@ void fec_rx_continue(uint8_t ch)
* selected FEC * selected FEC
*/ */
channel = dma_get_channel(DMA_FEC_RX(ch)); channel = dma_get_channel(DMA_FEC_RX(ch));
/* /*
* Continue/restart the DMA task * Continue/restart the DMA task
*/ */
@@ -637,6 +641,7 @@ void fec_rx_stop (uint8_t ch)
* selected FEC * selected FEC
*/ */
channel = dma_get_channel(DMA_FEC_RX(ch)); channel = dma_get_channel(DMA_FEC_RX(ch));
/* Kill the FEC Rx DMA task */ /* Kill the FEC Rx DMA task */
MCD_killDma(channel); MCD_killDma(channel);
@@ -730,9 +735,7 @@ void fec_rx_frame(uint8_t ch, NIF *nif)
new_nbuf = nbuf_alloc(); new_nbuf = nbuf_alloc();
if (new_nbuf == NULL) if (new_nbuf == NULL)
{ {
#ifdef DEBUG_PRINT dbg("%s: nbuf_alloc() failed\n", __FUNCTION__);
dbg("nbuf_alloc() failed\n");
#endif
/* /*
* Can't allocate a new network buffer, so we * Can't allocate a new network buffer, so we
@@ -745,6 +748,7 @@ void fec_rx_frame(uint8_t ch, NIF *nif)
pRxBD->status |= RX_BD_E; pRxBD->status |= RX_BD_E;
nbuf_add(NBUF_RX_RING, cur_nbuf); nbuf_add(NBUF_RX_RING, cur_nbuf);
fec_rx_continue(ch); fec_rx_continue(ch);
continue; continue;
} }
@@ -773,18 +777,21 @@ void fec_rx_frame(uint8_t ch, NIF *nif)
/* /*
* Get pointer to the frame data inside the network buffer * Get pointer to the frame data inside the network buffer
*/ */
eth_hdr = (ETH_HDR *)cur_nbuf->data; eth_hdr = (ETH_HDR *) cur_nbuf->data;
/* /*
* Pass the received packet up the network stack if the * Pass the received packet up the network stack if the
* protocol is supported in our network interface (NIF) * protocol is supported in our network interface (NIF)
*/ */
if (nif_protocol_exist(nif,eth_hdr->type)) if (nif_protocol_exist(nif, eth_hdr->type))
{ {
nif_protocol_handler(nif, eth_hdr->type, cur_nbuf); nif_protocol_handler(nif, eth_hdr->type, cur_nbuf);
} }
else else
{
nbuf_free(cur_nbuf); nbuf_free(cur_nbuf);
dbg("%s: got unsupported packet %d, trashed it\r\n", __FUNCTION__, eth_hdr->type);
}
} }
else else
{ {
@@ -838,10 +845,14 @@ void fec1_rx_frame(void)
void fec_tx_start(uint8_t ch, int8_t *txbd) void fec_tx_start(uint8_t ch, int8_t *txbd)
{ {
uint32_t initiator; uint32_t initiator;
int channel, result; int channel;
int result;
void fec0_tx_frame(void); void fec0_tx_frame(void);
void fec1_tx_frame(void); void fec1_tx_frame(void);
(void) result; /* to avoid compiler warning */
/* FIXME: code assumes that there are always free initiator slots */
/* /*
* Make the initiator assignment * Make the initiator assignment
*/ */
@@ -938,7 +949,7 @@ void fec_tx_stop (uint8_t ch)
MCF_FEC_TCR(ch) |= MCF_FEC_TCR_GTS; MCF_FEC_TCR(ch) |= MCF_FEC_TCR_GTS;
/* Wait for the Graceful Stop Complete interrupt */ /* Wait for the Graceful Stop Complete interrupt */
while(!(MCF_FEC_EIR(ch) & MCF_FEC_EIR_GRA)) while (!(MCF_FEC_EIR(ch) & MCF_FEC_EIR_GRA))
{ {
if (!(MCF_FEC_ECR(ch) & MCF_FEC_ECR_ETHER_EN)) if (!(MCF_FEC_ECR(ch) & MCF_FEC_ECR_ETHER_EN))
break; break;
@@ -1173,10 +1184,8 @@ static void fec_irq_handler(uint8_t ch)
eir = MCF_FEC_EIR(ch); eir = MCF_FEC_EIR(ch);
event = eir & MCF_FEC_EIMR(ch); event = eir & MCF_FEC_EIMR(ch);
#ifdef DEBUG
if (event != eir) if (event != eir)
dbg("Pending but not enabled: 0x%08X\n", (event ^ eir)); dbg("%s: pending but not enabled: 0x%08x\r\n", __FUNCTION__, (event ^ eir));
#endif
/* /*
* Clear the event(s) in the EIR immediately * Clear the event(s) in the EIR immediately
@@ -1187,80 +1196,74 @@ static void fec_irq_handler(uint8_t ch)
{ {
fec_log[ch].total++; fec_log[ch].total++;
fec_log[ch].rferr++; fec_log[ch].rferr++;
#ifdef DEBUG dbg("%s: RFERR\r\n", __FUNCTION__);
dbg("RFERR\n"); dbg("%s: FECRFSR%d = 0x%08x\r\n", __FUNCTION__, ch, MCF_FEC_FECRFSR(ch));
dbg("FECRFSR%d = 0x%08x\n", ch, MCF_FEC_FECRFSR(ch));
fec_eth_stop(ch); fec_eth_stop(ch);
#endif
} }
if (event & MCF_FEC_EIR_XFERR) if (event & MCF_FEC_EIR_XFERR)
{ {
fec_log[ch].total++; fec_log[ch].total++;
fec_log[ch].xferr++; fec_log[ch].xferr++;
#ifdef DEBUG dbg("%s: XFERR\r\n", __FUNCTION__);
dbg("XFERR\n");
#endif
} }
if (event & MCF_FEC_EIR_XFUN) if (event & MCF_FEC_EIR_XFUN)
{ {
fec_log[ch].total++; fec_log[ch].total++;
fec_log[ch].xfun++; fec_log[ch].xfun++;
#ifdef DEBUG dbg("%s: XFUN\r\n", __FUNCTION__);
dbg("XFUN\n");
fec_eth_stop(ch); fec_eth_stop(ch);
#endif
} }
if (event & MCF_FEC_EIR_RL) if (event & MCF_FEC_EIR_RL)
{ {
fec_log[ch].total++; fec_log[ch].total++;
fec_log[ch].rl++; fec_log[ch].rl++;
#ifdef DEBUG dbg("%s: RL\r\n", __FUNCTION__);
dbg("RL\n");
#endif
} }
if (event & MCF_FEC_EIR_LC) if (event & MCF_FEC_EIR_LC)
{ {
fec_log[ch].total++; fec_log[ch].total++;
fec_log[ch].lc++; fec_log[ch].lc++;
#ifdef DEBUG dbg("%s: LC\r\n", __FUNCTION__);
dbg("LC\n");
#endif
} }
if (event & MCF_FEC_EIR_MII) if (event & MCF_FEC_EIR_MII)
{ {
fec_log[ch].mii++; fec_log[ch].mii++;
} }
if (event & MCF_FEC_EIR_TXF) if (event & MCF_FEC_EIR_TXF)
{ {
fec_log[ch].txf++; fec_log[ch].txf++;
} }
if (event & MCF_FEC_EIR_GRA) if (event & MCF_FEC_EIR_GRA)
{ {
fec_log[ch].gra++; fec_log[ch].gra++;
} }
if (event & MCF_FEC_EIR_BABT) if (event & MCF_FEC_EIR_BABT)
{ {
fec_log[ch].total++; fec_log[ch].total++;
fec_log[ch].babt++; fec_log[ch].babt++;
#ifdef DEBUG dbg("%s: BABT\r\n", __FUNCTION__);
dbg("BABT\n");
#endif
} }
if (event & MCF_FEC_EIR_BABR) if (event & MCF_FEC_EIR_BABR)
{ {
fec_log[ch].total++; fec_log[ch].total++;
fec_log[ch].babr++; fec_log[ch].babr++;
#ifdef DEBUG dbg("%s: BABR\r\n", __FUNCTION__);
dbg("BABR\n");
#endif
} }
if (event & MCF_FEC_EIR_HBERR) if (event & MCF_FEC_EIR_HBERR)
{ {
fec_log[ch].total++; fec_log[ch].total++;
fec_log[ch].hberr++; fec_log[ch].hberr++;
#ifdef DEBUG dbg("%s: HBERR\r\n", __FUNCTION__);
dbg("HBERR\n");
#endif
} }
} }
@@ -1268,7 +1271,9 @@ int fec0_interrupt_handler(void* arg1, void* arg2)
{ {
(void) arg1; (void) arg1;
(void) arg2; (void) arg2;
fec_irq_handler(0); fec_irq_handler(0);
return 1; return 1;
} }
@@ -1276,7 +1281,9 @@ int fec1_interrupt_handler(void* arg1, void* arg2)
{ {
(void) arg1; (void) arg1;
(void) arg2; (void) arg2;
fec_irq_handler(1); fec_irq_handler(1);
return 1; return 1;
} }
@@ -1384,10 +1391,10 @@ void fec_eth_stop(uint8_t ch)
*/ */
MCF_FEC_ECR(ch) &= ~MCF_FEC_ECR_ETHER_EN; MCF_FEC_ECR(ch) &= ~MCF_FEC_ECR_ETHER_EN;
#ifdef DEBUG_PRINT #ifdef DBG_FEC
nbuf_debug_dump(); nbuf_debug_dump();
fec_log_dump(ch); fec_log_dump(ch);
#endif #endif
/* /*
* Flush the network buffers * Flush the network buffers