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"
74 static uint_t txBufferIndex;
76 static uint_t rxBufferIndex;
113 volatile uint32_t temp;
116 TRACE_INFO(
"Initializing MPFSxxx Ethernet MAC (MAC1)...\r\n");
119 nicDriverInterface = interface;
122 SYSREG->SUBBLK_CLOCK_CR |= 4U;
125 SYSREG->SOFT_RESET_CR |= 4U;
126 SYSREG->SOFT_RESET_CR &= ~4U;
129 MAC1->NETWORK_CONTROL = 0;
135 MAC1->NETWORK_CONFIG = GEM_SGMII_MODE_ENABLE | GEM_PCS_SELECT |
136 (1 << GEM_DATA_BUS_WIDTH_SHIFT) | (5 << GEM_MDC_CLOCK_DIVISOR_SHIFT);
139 MAC1->NETWORK_CONTROL |= GEM_MAN_PORT_EN;
142 if(interface->phyDriver != NULL)
145 error = interface->phyDriver->init(interface);
147 else if(interface->switchDriver != NULL)
150 error = interface->switchDriver->init(interface);
165 MAC1->SPEC_ADD1_BOTTOM = interface->macAddr.w[0] | (interface->macAddr.w[1] << 16);
166 MAC1->SPEC_ADD1_TOP = interface->macAddr.w[2];
169 MAC1->SPEC_ADD2_BOTTOM = 0;
170 MAC1->SPEC_ADD3_BOTTOM = 0;
171 MAC1->SPEC_ADD4_BOTTOM = 0;
174 MAC1->HASH_BOTTOM = 0;
178 MAC1->NETWORK_CONFIG |= GEM_RECEIVE_1536_BYTE_FRAMES | GEM_MULTICAST_HASH_ENABLE;
185 temp |= GEM_DMA_ADDR_BUS_WIDTH_1;
187 temp |= GEM_TX_BD_EXTENDED_MODE_EN | GEM_RX_BD_EXTENDED_MODE_EN;
189 temp |= GEM_TX_PBUF_SIZE | GEM_RX_PBUF_SIZE;
192 MAC1->DMA_CONFIG = temp;
201 MAC1->TRANSMIT_STATUS = GEM_TX_RESP_NOT_OK | GEM_STAT_TRANSMIT_UNDER_RUN |
202 GEM_STAT_TRANSMIT_COMPLETE | GEM_STAT_AMBA_ERROR | GEM_TRANSMIT_GO |
203 GEM_RETRY_LIMIT_EXCEEDED | GEM_COLLISION_OCCURRED | GEM_USED_BIT_READ;
206 MAC1->RECEIVE_STATUS = GEM_RX_RESP_NOT_OK | GEM_RECEIVE_OVERRUN |
207 GEM_FRAME_RECEIVED | GEM_BUFFER_NOT_AVAILABLE;
210 MAC1->INT_DISABLE = 0xFFFFFFFF;
211 MAC1->INT_Q1_DISABLE = 0xFFFFFFFF;
212 MAC1->INT_Q2_DISABLE = 0xFFFFFFFF;
213 MAC1->INT_Q3_DISABLE = 0xFFFFFFFF;
216 MAC1->INT_ENABLE = GEM_RESP_NOT_OK_INT |
217 GEM_RECEIVE_OVERRUN_INT | GEM_TRANSMIT_COMPLETE | GEM_AMBA_ERROR |
218 GEM_RETRY_LIMIT_EXCEEDED_OR_LATE_COLLISION | GEM_TRANSMIT_UNDER_RUN |
219 GEM_RX_USED_BIT_READ | GEM_RECEIVE_COMPLETE;
222 temp =
MAC1->INT_STATUS;
229 MAC1->NETWORK_CONTROL |= GEM_ENABLE_TRANSMIT | GEM_ENABLE_RECEIVE;
247 #if defined(USE_MPFS_ICICLE_KIT_ES)
269 txBufferDesc[i].addrLow = (uint32_t)
address;
270 txBufferDesc[i].addrHigh = (uint32_t) (
address >> 32);
276 txBufferDesc[i].reserved = 0;
277 txBufferDesc[i].nanoSeconds = 0;
278 txBufferDesc[i].seconds = 0;
294 rxBufferDesc[i].addrHigh = (uint32_t) (
address >> 32);
297 rxBufferDesc[i].status = 0;
300 rxBufferDesc[i].reserved = 0;
301 rxBufferDesc[i].nanoSeconds = 0;
302 rxBufferDesc[i].seconds = 0;
314 address = (uint64_t) dummyTxBuffer[i];
317 dummyTxBufferDesc[i].addrLow = (uint32_t)
address;
318 dummyTxBufferDesc[i].addrHigh = (uint32_t) (
address >> 32);
324 dummyTxBufferDesc[i].reserved = 0;
325 dummyTxBufferDesc[i].nanoSeconds = 0;
326 dummyTxBufferDesc[i].seconds = 0;
336 address = (uint64_t) dummyRxBuffer[i];
340 dummyRxBufferDesc[i].addrHigh = (uint32_t) (
address >> 32);
343 dummyRxBufferDesc[i].status = 0;
346 dummyRxBufferDesc[i].reserved = 0;
347 dummyRxBufferDesc[i].nanoSeconds = 0;
348 dummyRxBufferDesc[i].seconds = 0;
355 MAC1->TRANSMIT_Q_PTR = (uint32_t) ((uint64_t) txBufferDesc);
356 MAC1->UPPER_TX_Q_BASE_ADDR = (uint32_t) ((uint64_t) txBufferDesc >> 32);
358 MAC1->TRANSMIT_Q1_PTR = (uint32_t) ((uint64_t) dummyTxBufferDesc) | 1;
359 MAC1->TRANSMIT_Q2_PTR = (uint32_t) ((uint64_t) dummyTxBufferDesc) | 1;
360 MAC1->TRANSMIT_Q3_PTR = (uint32_t) ((uint64_t) dummyTxBufferDesc) | 1;
363 MAC1->RECEIVE_Q_PTR = (uint32_t) ((uint64_t) rxBufferDesc);
364 MAC1->UPPER_RX_Q_BASE_ADDR = (uint32_t) ((uint64_t) rxBufferDesc >> 32);
366 MAC1->RECEIVE_Q1_PTR = (uint32_t) ((uint64_t) dummyRxBufferDesc) | 1;
367 MAC1->RECEIVE_Q2_PTR = (uint32_t) ((uint64_t) dummyRxBufferDesc) | 1;
368 MAC1->RECEIVE_Q3_PTR = (uint32_t) ((uint64_t) dummyRxBufferDesc) | 1;
384 if(interface->phyDriver != NULL)
387 interface->phyDriver->tick(interface);
389 else if(interface->switchDriver != NULL)
392 interface->switchDriver->tick(interface);
409 PLIC_EnableIRQ(MAC1_INT_PLIC);
412 if(interface->phyDriver != NULL)
415 interface->phyDriver->enableIrq(interface);
417 else if(interface->switchDriver != NULL)
420 interface->switchDriver->enableIrq(interface);
437 PLIC_DisableIRQ(MAC1_INT_PLIC);
440 if(interface->phyDriver != NULL)
443 interface->phyDriver->disableIrq(interface);
445 else if(interface->switchDriver != NULL)
448 interface->switchDriver->disableIrq(interface);
464 volatile uint32_t isr;
465 volatile uint32_t tsr;
466 volatile uint32_t rsr;
476 isr =
MAC1->INT_Q1_STATUS;
477 isr =
MAC1->INT_Q2_STATUS;
478 isr =
MAC1->INT_Q3_STATUS;
479 isr =
MAC1->INT_STATUS;
480 tsr =
MAC1->TRANSMIT_STATUS;
481 rsr =
MAC1->RECEIVE_STATUS;
484 MAC1->INT_STATUS = isr;
487 if((tsr & (GEM_TX_RESP_NOT_OK | GEM_STAT_TRANSMIT_UNDER_RUN |
488 GEM_STAT_TRANSMIT_COMPLETE | GEM_STAT_AMBA_ERROR | GEM_TRANSMIT_GO |
489 GEM_RETRY_LIMIT_EXCEEDED | GEM_COLLISION_OCCURRED | GEM_USED_BIT_READ)) != 0)
492 MAC1->TRANSMIT_STATUS = tsr;
495 if((txBufferDesc[txBufferIndex].status &
MAC_TX_USED) != 0)
503 if((rsr & (GEM_RX_RESP_NOT_OK | GEM_RECEIVE_OVERRUN | GEM_FRAME_RECEIVED |
504 GEM_BUFFER_NOT_AVAILABLE)) != 0)
507 nicDriverInterface->nicEvent =
TRUE;
516 return EXT_IRQ_KEEP_ENABLED;
531 rsr =
MAC1->RECEIVE_STATUS;
534 if((rsr & (GEM_RX_RESP_NOT_OK | GEM_RECEIVE_OVERRUN | GEM_FRAME_RECEIVED |
535 GEM_BUFFER_NOT_AVAILABLE)) != 0)
538 MAC1->RECEIVE_STATUS = rsr;
580 if((txBufferDesc[txBufferIndex].status &
MAC_TX_USED) == 0)
609 MAC1->NETWORK_CONTROL |= GEM_TRANSMIT_START;
612 if((txBufferDesc[txBufferIndex].status &
MAC_TX_USED) != 0)
650 j = rxBufferIndex + i;
666 if((rxBufferDesc[j].status &
MAC_RX_SOF) != 0)
673 if((rxBufferDesc[j].status &
MAC_RX_EOF) != 0 && sofIndex != UINT_MAX)
687 if(eofIndex != UINT_MAX)
691 else if(sofIndex != UINT_MAX)
704 for(i = 0; i < j; i++)
707 if(eofIndex != UINT_MAX && i >= sofIndex && i <= eofIndex)
767 uint32_t hashTable[2];
775 MAC1->SPEC_ADD1_BOTTOM = interface->macAddr.w[0] | (interface->macAddr.w[1] << 16);
776 MAC1->SPEC_ADD1_TOP = interface->macAddr.w[2];
792 entry = &interface->macAddrFilter[i];
804 k = (
p[0] >> 6) ^
p[0];
805 k ^= (
p[1] >> 4) ^ (
p[1] << 2);
806 k ^= (
p[2] >> 2) ^ (
p[2] << 4);
807 k ^= (
p[3] >> 6) ^
p[3];
808 k ^= (
p[4] >> 4) ^ (
p[4] << 2);
809 k ^= (
p[5] >> 2) ^ (
p[5] << 4);
815 hashTable[k / 32] |= (1 << (k % 32));
823 unicastMacAddr[j] = entry->
addr;
831 k = (
p[0] >> 6) ^
p[0];
832 k ^= (
p[1] >> 4) ^ (
p[1] << 2);
833 k ^= (
p[2] >> 2) ^ (
p[2] << 4);
834 k ^= (
p[3] >> 6) ^
p[3];
835 k ^= (
p[4] >> 4) ^ (
p[4] << 2);
836 k ^= (
p[5] >> 2) ^ (
p[5] << 4);
842 hashTable[k / 32] |= (1 << (k % 32));
855 MAC1->SPEC_ADD2_BOTTOM = unicastMacAddr[0].w[0] | (unicastMacAddr[0].w[1] << 16);
856 MAC1->SPEC_ADD2_TOP = unicastMacAddr[0].w[2];
861 MAC1->SPEC_ADD2_BOTTOM = 0;
868 MAC1->SPEC_ADD3_BOTTOM = unicastMacAddr[1].w[0] | (unicastMacAddr[1].w[1] << 16);
869 MAC1->SPEC_ADD3_TOP = unicastMacAddr[1].w[2];
874 MAC1->SPEC_ADD3_BOTTOM = 0;
881 MAC1->SPEC_ADD4_BOTTOM = unicastMacAddr[2].w[0] | (unicastMacAddr[2].w[1] << 16);
882 MAC1->SPEC_ADD4_TOP = unicastMacAddr[2].w[2];
887 MAC1->SPEC_ADD4_BOTTOM = 0;
893 MAC1->NETWORK_CONFIG |= GEM_UNICAST_HASH_ENABLE;
897 MAC1->NETWORK_CONFIG &= ~GEM_UNICAST_HASH_ENABLE;
901 MAC1->HASH_BOTTOM = hashTable[0];
902 MAC1->HASH_TOP = hashTable[1];
924 config =
MAC1->NETWORK_CONFIG;
929 config |= GEM_GIGABIT_MODE_ENABLE;
930 config &= ~GEM_SPEED;
935 config &= ~GEM_GIGABIT_MODE_ENABLE;
941 config &= ~GEM_GIGABIT_MODE_ENABLE;
942 config &= ~GEM_SPEED;
948 config |= GEM_FULL_DUPLEX;
952 config &= ~GEM_FULL_DUPLEX;
956 MAC1->NETWORK_CONFIG = config;
980 temp = GEM_WRITE1 | (GEM_PHY_OP_CL22_WRITE << GEM_OPERATION_SHIFT) |
981 (2 << GEM_WRITE10_SHIFT);
984 temp |= (phyAddr << GEM_PHY_ADDRESS_SHIFT) & GEM_PHY_ADDRESS;
986 temp |= (
regAddr << GEM_REGISTER_ADDRESS_SHIFT) & GEM_REGISTER_ADDRESS;
991 MAC1->PHY_MANAGEMENT = temp;
993 while((
MAC1->NETWORK_STATUS & GEM_MAN_DONE) == 0)
1022 temp = GEM_WRITE1 | (GEM_PHY_OP_CL22_READ << GEM_OPERATION_SHIFT) |
1023 (2 << GEM_WRITE10_SHIFT);
1026 temp |= (phyAddr << GEM_PHY_ADDRESS_SHIFT) & GEM_PHY_ADDRESS;
1028 temp |= (
regAddr << GEM_REGISTER_ADDRESS_SHIFT) & GEM_REGISTER_ADDRESS;
1031 MAC1->PHY_MANAGEMENT = temp;
1033 while((
MAC1->NETWORK_STATUS & GEM_MAN_DONE) == 0)
1038 data = (uint16_t)
MAC1->PHY_MANAGEMENT;