32 #define TRACE_LEVEL NIC_TRACE_LEVEL
53 static uint_t txBufferIndex;
55 static uint_t rxBufferIndex;
96 TRACE_INFO(
"Initializing MCF5225x Ethernet MAC...\r\n");
99 nicDriverInterface = interface;
105 MCF_FEC_ECR = MCF_FEC_ECR_RESET;
107 while((MCF_FEC_ECR & MCF_FEC_ECR_RESET) != 0)
113 MCF_FEC_RCR_MII_MODE;
118 MCF_FEC_MSCR = MCF_FEC_MSCR_MII_SPEED(19);
121 if(interface->phyDriver != NULL)
124 error = interface->phyDriver->init(interface);
126 else if(interface->switchDriver != NULL)
129 error = interface->switchDriver->init(interface);
144 value = interface->macAddr.b[5];
145 value |= (interface->macAddr.b[4] << 8);
146 MCF_FEC_PAUR = MCF_FEC_PAUR_PADDR2(
value) | MCF_FEC_PAUR_TYPE(0x8808);
149 value = interface->macAddr.b[3];
150 value |= (interface->macAddr.b[2] << 8);
151 value |= (interface->macAddr.b[1] << 16);
152 value |= (interface->macAddr.b[0] << 24);
153 MCF_FEC_PALR = MCF_FEC_PALR_PADDR1(
value);
166 MCF_FEC_EIR = MCF_FEC_EIR_CLEAR_ALL;
169 MCF_FEC_EIMR = MCF_FEC_EIMR_TXF | MCF_FEC_EIMR_TXB |
170 MCF_FEC_EIMR_RXF | MCF_FEC_EIMR_RXB | MCF_FEC_EIMR_EBERR;
173 for(i = 23; i <= 35; i++)
180 MCF_FEC_ECR |= MCF_FEC_ECR_ETHER_EN;
182 MCF_FEC_RDAR = MCF_FEC_RDAR_R_DES_ACTIVE;
200 #if defined(USE_TWR_MCF5225X)
205 MCF_GPIO_PTIPAR |= MCF_GPIO_PTIPAR_FEC_COL_FEC_COL | MCF_GPIO_PTIPAR_FEC_CRS_FEC_CRS |
206 MCF_GPIO_PTIPAR_FEC_RXCLK_FEC_RXCLK | MCF_GPIO_PTIPAR_FEC_RXD0_FEC_RXD0 |
207 MCF_GPIO_PTIPAR_FEC_RXD1_FEC_RXD1 | MCF_GPIO_PTIPAR_FEC_RXD2_FEC_RXD2 |
208 MCF_GPIO_PTIPAR_FEC_RXD3_FEC_RXD3 | MCF_GPIO_PTIPAR_FEC_RXDV_FEC_RXDV;
212 MCF_GPIO_PTJPAR |= MCF_GPIO_PTJPAR_FEC_RXER_FEC_RXER | MCF_GPIO_PTJPAR_FEC_TXCLK_FEC_TXCLK |
213 MCF_GPIO_PTJPAR_FEC_TXD0_FEC_TXD0 | MCF_GPIO_PTJPAR_FEC_TXD1_FEC_TXD1 |
214 MCF_GPIO_PTJPAR_FEC_TXD2_FEC_TXD2 | MCF_GPIO_PTJPAR_FEC_TXD3_FEC_TXD3 |
215 MCF_GPIO_PTJPAR_FEC_TXEN_FEC_TXEN | MCF_GPIO_PTJPAR_FEC_TXER_FEC_TXER;
218 temp = MCF_GPIO_PNQPAR & ~MCF_GPIO_PNQPAR_PNQPAR3(3);
219 MCF_GPIO_PNQPAR = temp | MCF_GPIO_PNQPAR_IRQ3_FEC_MDIO;
222 temp = MCF_GPIO_PNQPAR & ~MCF_GPIO_PNQPAR_PNQPAR5(3);
223 MCF_GPIO_PNQPAR = temp | MCF_GPIO_PNQPAR_IRQ5_FEC_MDC;
226 MCF_RCM_RCR |= MCF_RCM_RCR_FRCRSTOUT;
228 MCF_RCM_RCR &= ~MCF_RCM_RCR_FRCRSTOUT;
247 txBufferDesc[i].
status = 0;
249 txBufferDesc[i].
length = 0;
265 rxBufferDesc[i].
length = 0;
276 MCF_FEC_ETSDR = (uint32_t) txBufferDesc;
278 MCF_FEC_ERDSR = (uint32_t) rxBufferDesc;
296 if(interface->phyDriver != NULL)
299 interface->phyDriver->tick(interface);
301 else if(interface->switchDriver != NULL)
304 interface->switchDriver->tick(interface);
321 MCF_INTC0_IMRL &= ~(MCF_INTC_IMRL_INT_MASK23 |
322 MCF_INTC_IMRL_INT_MASK24 | MCF_INTC_IMRL_INT_MASK25 |
323 MCF_INTC_IMRL_INT_MASK26 | MCF_INTC_IMRL_INT_MASK27 |
324 MCF_INTC_IMRL_INT_MASK28 | MCF_INTC_IMRL_INT_MASK29 |
325 MCF_INTC_IMRL_INT_MASK30 | MCF_INTC_IMRL_INT_MASK31);
327 MCF_INTC0_IMRH &= ~(MCF_INTC_IMRH_INT_MASK33 |
328 MCF_INTC_IMRH_INT_MASK34 | MCF_INTC_IMRH_INT_MASK35);
331 if(interface->phyDriver != NULL)
334 interface->phyDriver->enableIrq(interface);
336 else if(interface->switchDriver != NULL)
339 interface->switchDriver->enableIrq(interface);
356 MCF_INTC0_IMRL |= MCF_INTC_IMRL_INT_MASK23 |
357 MCF_INTC_IMRL_INT_MASK24 | MCF_INTC_IMRL_INT_MASK25 |
358 MCF_INTC_IMRL_INT_MASK26 | MCF_INTC_IMRL_INT_MASK27 |
359 MCF_INTC_IMRL_INT_MASK28 | MCF_INTC_IMRL_INT_MASK29 |
360 MCF_INTC_IMRL_INT_MASK30 | MCF_INTC_IMRL_INT_MASK31;
362 MCF_INTC0_IMRH |= MCF_INTC_IMRH_INT_MASK33 |
363 MCF_INTC_IMRH_INT_MASK34 | MCF_INTC_IMRH_INT_MASK35;
366 if(interface->phyDriver != NULL)
369 interface->phyDriver->disableIrq(interface);
371 else if(interface->switchDriver != NULL)
374 interface->switchDriver->disableIrq(interface);
398 events = MCF_FEC_EIR;
401 if((events & (MCF_FEC_EIR_TXF | MCF_FEC_EIR_TXB)) != 0)
404 MCF_FEC_EIR = MCF_FEC_EIR_TXF | MCF_FEC_EIR_TXB;
407 if((txBufferDesc[txBufferIndex].status &
FEC_TX_BD_R) == 0)
414 MCF_FEC_TDAR = MCF_FEC_TDAR_X_DES_ACTIVE;
418 if((events & (MCF_FEC_EIR_RXF | MCF_FEC_EIR_RXB)) != 0)
421 MCF_FEC_EIMR &= ~(MCF_FEC_EIMR_RXF | MCF_FEC_EIMR_RXB);
424 nicDriverInterface->nicEvent =
TRUE;
430 if((events & MCF_FEC_EIR_EBERR) != 0)
433 MCF_FEC_EIMR &= ~MCF_FEC_EIMR_EBERR;
436 nicDriverInterface->nicEvent =
TRUE;
442 if((events & (MCF_FEC_EIR_HBERR | MCF_FEC_EIR_BABR | MCF_FEC_EIR_BABT |
443 MCF_FEC_EIR_GRA | MCF_FEC_EIR_MII | MCF_FEC_EIR_LC | MCF_FEC_EIR_RL |
444 MCF_FEC_EIR_UN)) != 0)
447 MCF_FEC_EIR = MCF_FEC_EIR_HBERR | MCF_FEC_EIR_BABR | MCF_FEC_EIR_BABT |
448 MCF_FEC_EIR_GRA | MCF_FEC_EIR_MII | MCF_FEC_EIR_LC | MCF_FEC_EIR_RL |
468 status = MCF_FEC_EIR;
471 if((status & (MCF_FEC_EIR_RXF | MCF_FEC_EIR_RXB)) != 0)
474 MCF_FEC_EIR = MCF_FEC_EIR_RXF | MCF_FEC_EIR_RXB;
487 if((status & MCF_FEC_EIR_EBERR) != 0)
490 MCF_FEC_EIR = MCF_FEC_EIR_EBERR;
493 MCF_FEC_ECR &= ~MCF_FEC_ECR_ETHER_EN;
497 MCF_FEC_ECR |= MCF_FEC_ECR_ETHER_EN;
499 MCF_FEC_RDAR = MCF_FEC_RDAR_R_DES_ACTIVE;
503 MCF_FEC_EIMR = MCF_FEC_EIMR_TXF | MCF_FEC_EIMR_TXB |
504 MCF_FEC_EIMR_RXF | MCF_FEC_EIMR_RXB | MCF_FEC_EIMR_EBERR;
536 if((txBufferDesc[txBufferIndex].status &
FEC_TX_BD_R) != 0)
568 MCF_FEC_TDAR = MCF_FEC_TDAR_X_DES_ACTIVE;
571 if((txBufferDesc[txBufferIndex].status &
FEC_TX_BD_R) == 0)
595 if((rxBufferDesc[rxBufferIndex].status &
FEC_RX_BD_E) == 0)
598 if((rxBufferDesc[rxBufferIndex].status &
FEC_RX_BD_L) != 0)
601 if((rxBufferDesc[rxBufferIndex].status & (
FEC_RX_BD_LG |
605 n = rxBufferDesc[rxBufferIndex].
length;
648 MCF_FEC_RDAR = MCF_FEC_RDAR_R_DES_ACTIVE;
673 uint32_t unicastHashTable[2];
674 uint32_t multicastHashTable[2];
681 value = interface->macAddr.b[5];
682 value |= (interface->macAddr.b[4] << 8);
683 MCF_FEC_PAUR = MCF_FEC_PAUR_PADDR2(
value) | MCF_FEC_PAUR_TYPE(0x8808);
686 value = interface->macAddr.b[3];
687 value |= (interface->macAddr.b[2] << 8);
688 value |= (interface->macAddr.b[1] << 16);
689 value |= (interface->macAddr.b[0] << 24);
690 MCF_FEC_PALR = MCF_FEC_PALR_PADDR1(
value);
693 unicastHashTable[0] = 0;
694 unicastHashTable[1] = 0;
697 multicastHashTable[0] = 0;
698 multicastHashTable[1] = 0;
705 entry = &interface->macAddrFilter[i];
715 k = (crc >> 26) & 0x3F;
721 multicastHashTable[k / 32] |= (1 << (k % 32));
726 unicastHashTable[k / 32] |= (1 << (k % 32));
732 MCF_FEC_IALR = unicastHashTable[0];
733 MCF_FEC_IAUR = unicastHashTable[1];
736 MCF_FEC_GALR = multicastHashTable[0];
737 MCF_FEC_GAUR = multicastHashTable[1];
740 TRACE_DEBUG(
" IALR = %08" PRIX32
"\r\n", MCF_FEC_IALR);
741 TRACE_DEBUG(
" IAUR = %08" PRIX32
"\r\n", MCF_FEC_IAUR);
742 TRACE_DEBUG(
" GALR = %08" PRIX32
"\r\n", MCF_FEC_GALR);
743 TRACE_DEBUG(
" GAUR = %08" PRIX32
"\r\n", MCF_FEC_GAUR);
759 MCF_FEC_ECR &= ~MCF_FEC_ECR_ETHER_EN;
765 MCF_FEC_TCR |= MCF_FEC_TCR_FDEN;
767 MCF_FEC_RCR &= ~MCF_FEC_RCR_DRT;
772 MCF_FEC_TCR &= ~MCF_FEC_TCR_FDEN;
774 MCF_FEC_RCR |= MCF_FEC_RCR_DRT;
781 MCF_FEC_ECR |= MCF_FEC_ECR_ETHER_EN;
783 MCF_FEC_RDAR = MCF_FEC_RDAR_R_DES_ACTIVE;
807 temp = MCF_FEC_MMFR_ST(1) | MCF_FEC_MMFR_OP(1) | MCF_FEC_MMFR_TA(2);
809 temp |= MCF_FEC_MMFR_PA(phyAddr);
811 temp |= MCF_FEC_MMFR_RA(
regAddr);
813 temp |= MCF_FEC_MMFR_DATA(
data);
816 MCF_FEC_EIR = MCF_FEC_EIR_MII;
821 while((MCF_FEC_EIR & MCF_FEC_EIR_MII) == 0)
850 temp = MCF_FEC_MMFR_ST(1) | MCF_FEC_MMFR_OP(2) | MCF_FEC_MMFR_TA(2);
852 temp |= MCF_FEC_MMFR_PA(phyAddr);
854 temp |= MCF_FEC_MMFR_RA(
regAddr);
857 MCF_FEC_EIR = MCF_FEC_EIR_MII;
862 while((MCF_FEC_EIR & MCF_FEC_EIR_MII) == 0)
895 p = (uint8_t *)
data;
900 for(i = 0; i <
length; i++)
906 for(j = 0; j < 8; j++)
908 if((crc & 0x01) != 0)
910 crc = (crc >> 1) ^ 0xEDB88320;