32 #define TRACE_LEVEL NIC_TRACE_LEVEL
36 #include "mpfs_hal/common/mss_plic.h"
37 #include "mpfs_hal/common/mss_sysreg.h"
38 #include "drivers/mss/mss_ethernet_mac/mss_ethernet_registers.h"
39 #include "drivers/mss/mss_ethernet_mac/mss_ethernet_mac_regs.h"
44 #if defined(USE_MPFS_ICICLE_KIT_ES)
78 static uint_t txBufferIndex;
80 static uint_t rxBufferIndex;
117 volatile uint32_t temp;
120 TRACE_INFO(
"Initializing MPFSxxx Ethernet MAC (MAC0)...\r\n");
123 nicDriverInterface = interface;
126 SYSREG->SUBBLK_CLOCK_CR |= 2U;
129 SYSREG->SOFT_RESET_CR |= 2U;
130 SYSREG->SOFT_RESET_CR &= ~2U;
133 MAC0->NETWORK_CONTROL = 0;
139 MAC0->NETWORK_CONFIG = GEM_SGMII_MODE_ENABLE | GEM_PCS_SELECT |
140 (1 << GEM_DATA_BUS_WIDTH_SHIFT) | (5 << GEM_MDC_CLOCK_DIVISOR_SHIFT);
143 MAC0->NETWORK_CONTROL |= GEM_MAN_PORT_EN;
146 if(interface->phyDriver != NULL)
149 error = interface->phyDriver->init(interface);
151 else if(interface->switchDriver != NULL)
154 error = interface->switchDriver->init(interface);
169 MAC0->SPEC_ADD1_BOTTOM = interface->macAddr.w[0] | (interface->macAddr.w[1] << 16);
170 MAC0->SPEC_ADD1_TOP = interface->macAddr.w[2];
173 MAC0->SPEC_ADD2_BOTTOM = 0;
174 MAC0->SPEC_ADD3_BOTTOM = 0;
175 MAC0->SPEC_ADD4_BOTTOM = 0;
178 MAC0->HASH_BOTTOM = 0;
182 MAC0->NETWORK_CONFIG |= GEM_RECEIVE_1536_BYTE_FRAMES | GEM_MULTICAST_HASH_ENABLE;
189 temp |= GEM_DMA_ADDR_BUS_WIDTH_1;
191 temp |= GEM_TX_BD_EXTENDED_MODE_EN | GEM_RX_BD_EXTENDED_MODE_EN;
193 temp |= GEM_TX_PBUF_SIZE | GEM_RX_PBUF_SIZE;
196 MAC0->DMA_CONFIG = temp;
205 MAC0->TRANSMIT_STATUS = GEM_TX_RESP_NOT_OK | GEM_STAT_TRANSMIT_UNDER_RUN |
206 GEM_STAT_TRANSMIT_COMPLETE | GEM_STAT_AMBA_ERROR | GEM_TRANSMIT_GO |
207 GEM_RETRY_LIMIT_EXCEEDED | GEM_COLLISION_OCCURRED | GEM_USED_BIT_READ;
210 MAC0->RECEIVE_STATUS = GEM_RX_RESP_NOT_OK | GEM_RECEIVE_OVERRUN |
211 GEM_FRAME_RECEIVED | GEM_BUFFER_NOT_AVAILABLE;
214 MAC0->INT_DISABLE = 0xFFFFFFFF;
215 MAC0->INT_Q1_DISABLE = 0xFFFFFFFF;
216 MAC0->INT_Q2_DISABLE = 0xFFFFFFFF;
217 MAC0->INT_Q3_DISABLE = 0xFFFFFFFF;
220 MAC0->INT_ENABLE = GEM_RESP_NOT_OK_INT |
221 GEM_RECEIVE_OVERRUN_INT | GEM_TRANSMIT_COMPLETE | GEM_AMBA_ERROR |
222 GEM_RETRY_LIMIT_EXCEEDED_OR_LATE_COLLISION | GEM_TRANSMIT_UNDER_RUN |
223 GEM_RX_USED_BIT_READ | GEM_RECEIVE_COMPLETE;
226 temp =
MAC0->INT_STATUS;
233 MAC0->NETWORK_CONTROL |= GEM_ENABLE_TRANSMIT | GEM_ENABLE_RECEIVE;
251 #if defined(USE_MPFS_ICICLE_KIT_ES)
253 SYSREG->SUBBLK_CLOCK_CR |= 4U;
256 MAC1->NETWORK_CONFIG = GEM_SGMII_MODE_ENABLE | GEM_PCS_SELECT |
257 (1 << GEM_DATA_BUS_WIDTH_SHIFT) | (5 << GEM_MDC_CLOCK_DIVISOR_SHIFT);
260 MAC1->NETWORK_CONTROL |= GEM_MAN_PORT_EN;
282 txBufferDesc[i].addrLow = (uint32_t)
address;
283 txBufferDesc[i].addrHigh = (uint32_t) (
address >> 32);
289 txBufferDesc[i].reserved = 0;
290 txBufferDesc[i].nanoSeconds = 0;
291 txBufferDesc[i].seconds = 0;
307 rxBufferDesc[i].addrHigh = (uint32_t) (
address >> 32);
310 rxBufferDesc[i].status = 0;
313 rxBufferDesc[i].reserved = 0;
314 rxBufferDesc[i].nanoSeconds = 0;
315 rxBufferDesc[i].seconds = 0;
327 address = (uint64_t) dummyTxBuffer[i];
330 dummyTxBufferDesc[i].addrLow = (uint32_t)
address;
331 dummyTxBufferDesc[i].addrHigh = (uint32_t) (
address >> 32);
337 dummyTxBufferDesc[i].reserved = 0;
338 dummyTxBufferDesc[i].nanoSeconds = 0;
339 dummyTxBufferDesc[i].seconds = 0;
349 address = (uint64_t) dummyRxBuffer[i];
353 dummyRxBufferDesc[i].addrHigh = (uint32_t) (
address >> 32);
356 dummyRxBufferDesc[i].status = 0;
359 dummyRxBufferDesc[i].reserved = 0;
360 dummyRxBufferDesc[i].nanoSeconds = 0;
361 dummyRxBufferDesc[i].seconds = 0;
368 MAC0->TRANSMIT_Q_PTR = (uint32_t) ((uint64_t) txBufferDesc);
369 MAC0->UPPER_TX_Q_BASE_ADDR = (uint32_t) ((uint64_t) txBufferDesc >> 32);
371 MAC0->TRANSMIT_Q1_PTR = (uint32_t) ((uint64_t) dummyTxBufferDesc) | 1;
372 MAC0->TRANSMIT_Q2_PTR = (uint32_t) ((uint64_t) dummyTxBufferDesc) | 1;
373 MAC0->TRANSMIT_Q3_PTR = (uint32_t) ((uint64_t) dummyTxBufferDesc) | 1;
376 MAC0->RECEIVE_Q_PTR = (uint32_t) ((uint64_t) rxBufferDesc);
377 MAC0->UPPER_RX_Q_BASE_ADDR = (uint32_t) ((uint64_t) rxBufferDesc >> 32);
379 MAC0->RECEIVE_Q1_PTR = (uint32_t) ((uint64_t) dummyRxBufferDesc) | 1;
380 MAC0->RECEIVE_Q2_PTR = (uint32_t) ((uint64_t) dummyRxBufferDesc) | 1;
381 MAC0->RECEIVE_Q3_PTR = (uint32_t) ((uint64_t) dummyRxBufferDesc) | 1;
397 if(interface->phyDriver != NULL)
400 interface->phyDriver->tick(interface);
402 else if(interface->switchDriver != NULL)
405 interface->switchDriver->tick(interface);
422 PLIC_EnableIRQ(MAC0_INT_PLIC);
425 if(interface->phyDriver != NULL)
428 interface->phyDriver->enableIrq(interface);
430 else if(interface->switchDriver != NULL)
433 interface->switchDriver->enableIrq(interface);
450 PLIC_DisableIRQ(MAC0_INT_PLIC);
453 if(interface->phyDriver != NULL)
456 interface->phyDriver->disableIrq(interface);
458 else if(interface->switchDriver != NULL)
461 interface->switchDriver->disableIrq(interface);
477 volatile uint32_t isr;
478 volatile uint32_t tsr;
479 volatile uint32_t rsr;
489 isr =
MAC0->INT_Q1_STATUS;
490 isr =
MAC0->INT_Q2_STATUS;
491 isr =
MAC0->INT_Q3_STATUS;
492 isr =
MAC0->INT_STATUS;
493 tsr =
MAC0->TRANSMIT_STATUS;
494 rsr =
MAC0->RECEIVE_STATUS;
497 MAC0->INT_STATUS = isr;
500 if((tsr & (GEM_TX_RESP_NOT_OK | GEM_STAT_TRANSMIT_UNDER_RUN |
501 GEM_STAT_TRANSMIT_COMPLETE | GEM_STAT_AMBA_ERROR | GEM_TRANSMIT_GO |
502 GEM_RETRY_LIMIT_EXCEEDED | GEM_COLLISION_OCCURRED | GEM_USED_BIT_READ)) != 0)
505 MAC0->TRANSMIT_STATUS = tsr;
508 if((txBufferDesc[txBufferIndex].status &
MAC_TX_USED) != 0)
516 if((rsr & (GEM_RX_RESP_NOT_OK | GEM_RECEIVE_OVERRUN | GEM_FRAME_RECEIVED |
517 GEM_BUFFER_NOT_AVAILABLE)) != 0)
520 nicDriverInterface->nicEvent =
TRUE;
529 return EXT_IRQ_KEEP_ENABLED;
544 rsr =
MAC0->RECEIVE_STATUS;
547 if((rsr & (GEM_RX_RESP_NOT_OK | GEM_RECEIVE_OVERRUN | GEM_FRAME_RECEIVED |
548 GEM_BUFFER_NOT_AVAILABLE)) != 0)
551 MAC0->RECEIVE_STATUS = rsr;
593 if((txBufferDesc[txBufferIndex].status &
MAC_TX_USED) == 0)
622 MAC0->NETWORK_CONTROL |= GEM_TRANSMIT_START;
625 if((txBufferDesc[txBufferIndex].status &
MAC_TX_USED) != 0)
663 j = rxBufferIndex + i;
679 if((rxBufferDesc[j].status &
MAC_RX_SOF) != 0)
686 if((rxBufferDesc[j].status &
MAC_RX_EOF) != 0 && sofIndex != UINT_MAX)
700 if(eofIndex != UINT_MAX)
704 else if(sofIndex != UINT_MAX)
717 for(i = 0; i < j; i++)
720 if(eofIndex != UINT_MAX && i >= sofIndex && i <= eofIndex)
780 uint32_t hashTable[2];
788 MAC0->SPEC_ADD1_BOTTOM = interface->macAddr.w[0] | (interface->macAddr.w[1] << 16);
789 MAC0->SPEC_ADD1_TOP = interface->macAddr.w[2];
805 entry = &interface->macAddrFilter[i];
817 k = (
p[0] >> 6) ^
p[0];
818 k ^= (
p[1] >> 4) ^ (
p[1] << 2);
819 k ^= (
p[2] >> 2) ^ (
p[2] << 4);
820 k ^= (
p[3] >> 6) ^
p[3];
821 k ^= (
p[4] >> 4) ^ (
p[4] << 2);
822 k ^= (
p[5] >> 2) ^ (
p[5] << 4);
828 hashTable[k / 32] |= (1 << (k % 32));
836 unicastMacAddr[j] = entry->
addr;
844 k = (
p[0] >> 6) ^
p[0];
845 k ^= (
p[1] >> 4) ^ (
p[1] << 2);
846 k ^= (
p[2] >> 2) ^ (
p[2] << 4);
847 k ^= (
p[3] >> 6) ^
p[3];
848 k ^= (
p[4] >> 4) ^ (
p[4] << 2);
849 k ^= (
p[5] >> 2) ^ (
p[5] << 4);
855 hashTable[k / 32] |= (1 << (k % 32));
868 MAC0->SPEC_ADD2_BOTTOM = unicastMacAddr[0].w[0] | (unicastMacAddr[0].w[1] << 16);
869 MAC0->SPEC_ADD2_TOP = unicastMacAddr[0].w[2];
874 MAC0->SPEC_ADD2_BOTTOM = 0;
881 MAC0->SPEC_ADD3_BOTTOM = unicastMacAddr[1].w[0] | (unicastMacAddr[1].w[1] << 16);
882 MAC0->SPEC_ADD3_TOP = unicastMacAddr[1].w[2];
887 MAC0->SPEC_ADD3_BOTTOM = 0;
894 MAC0->SPEC_ADD4_BOTTOM = unicastMacAddr[2].w[0] | (unicastMacAddr[2].w[1] << 16);
895 MAC0->SPEC_ADD4_TOP = unicastMacAddr[2].w[2];
900 MAC0->SPEC_ADD4_BOTTOM = 0;
906 MAC0->NETWORK_CONFIG |= GEM_UNICAST_HASH_ENABLE;
910 MAC0->NETWORK_CONFIG &= ~GEM_UNICAST_HASH_ENABLE;
914 MAC0->HASH_BOTTOM = hashTable[0];
915 MAC0->HASH_TOP = hashTable[1];
937 config =
MAC0->NETWORK_CONFIG;
942 config |= GEM_GIGABIT_MODE_ENABLE;
943 config &= ~GEM_SPEED;
948 config &= ~GEM_GIGABIT_MODE_ENABLE;
954 config &= ~GEM_GIGABIT_MODE_ENABLE;
955 config &= ~GEM_SPEED;
961 config |= GEM_FULL_DUPLEX;
965 config &= ~GEM_FULL_DUPLEX;
969 MAC0->NETWORK_CONFIG = config;
993 temp = GEM_WRITE1 | (GEM_PHY_OP_CL22_WRITE << GEM_OPERATION_SHIFT) |
994 (2 << GEM_WRITE10_SHIFT);
997 temp |= (phyAddr << GEM_PHY_ADDRESS_SHIFT) & GEM_PHY_ADDRESS;
999 temp |= (
regAddr << GEM_REGISTER_ADDRESS_SHIFT) & GEM_REGISTER_ADDRESS;
1004 MAC0->PHY_MANAGEMENT = temp;
1006 while((
MAC0->NETWORK_STATUS & GEM_MAN_DONE) == 0)
1035 temp = GEM_WRITE1 | (GEM_PHY_OP_CL22_READ << GEM_OPERATION_SHIFT) |
1036 (2 << GEM_WRITE10_SHIFT);
1039 temp |= (phyAddr << GEM_PHY_ADDRESS_SHIFT) & GEM_PHY_ADDRESS;
1041 temp |= (
regAddr << GEM_REGISTER_ADDRESS_SHIFT) & GEM_REGISTER_ADDRESS;
1044 MAC0->PHY_MANAGEMENT = temp;
1046 while((
MAC0->NETWORK_STATUS & GEM_MAN_DONE) == 0)
1051 data = (uint16_t)
MAC0->PHY_MANAGEMENT;