/** ============================================================================ * @n@b Switch_update_addr * * @b Description * @n This API add/delete entries in the Address Lookup Engine (ALE) in "Switch" mode. * * @param[in] * @n portNum Switch port number. * @param[in] * @n macAddress MAC address to configure on the switch. * * @param[in] * @n add 0:add; 1:delete. * * @return * @n None * * @Note It supports "add" operation only now. * ============================================================================= */ int Switch_update_addr (Uint32 portNum, UInt8 macAddress[6], Uint16 add) { Uint32 i; CSL_CPSW_3GF_ALE_PORTCONTROL alePortControlCfg; CSL_CPSW_3GF_ALE_UNICASTADDR_ENTRY ucastAddrCfg; /* Configure the address in "Learning"/"Forward" state */ alePortControlCfg.portState = ALE_PORTSTATE_FORWARD; alePortControlCfg.dropUntaggedEnable = 0; alePortControlCfg.vidIngressCheckEnable = 0; alePortControlCfg.noLearnModeEnable = 0; //(cpswLpbkMode != CPSW_LOOPBACK_NONE)?1:0; alePortControlCfg.mcastLimit = 0; alePortControlCfg.bcastLimit = 0; CSL_CPSW_3GF_setAlePortControlReg (portNum, &alePortControlCfg); //platform_write("Switch configuration done for Port %d\n",portNum); /* * The following code is required for device simulator only. * It is also served as an example of adding MAC address to the ALE table manually */ if (portNum==1||portNum==0) // if (0) { /* Program the ALE with the MAC address. * * The ALE entries determine the switch port to which any * matching received packet must be forwarded to. */ /* Get the next free ALE entry to program */ for (i = 0; i < CSL_CPSW_3GF_NUMALE_ENTRIES; i++) { if (CSL_CPSW_3GF_getALEEntryType (i) == ALE_ENTRYTYPE_FREE) { /* Found a free entry */ break; } } if (i == CSL_CPSW_3GF_NUMALE_ENTRIES) { /* No free ALE entry found. return error. */ return -1; } else { /* Found a free ALE entry to program our MAC address */ memcpy (ucastAddrCfg.macAddress, macAddress, 6); // Set the MAC address ucastAddrCfg.ucastType = ALE_UCASTTYPE_UCAST_AGETOUCH; // Add a permanent unicast address entryALE_UCASTTYPE_UCAST_NOAGE. ucastAddrCfg.secureEnable = FALSE; ucastAddrCfg.blockEnable = FALSE; ucastAddrCfg.portNumber = portNum; // Add the ALE entry for this port /* Setup the ALE entry for this port's MAC address */ CSL_CPSW_3GF_setAleUnicastAddrEntry (i, &ucastAddrCfg); } } /* Done with upading address */ return 0; }
/** ============================================================================ * @n@b Init_Switch * * @b Description * @n This API sets up the ethernet switch subsystem and its Address Lookup * Engine (ALE) in "Switch" mode. * * @param[in] * @n mtu Maximum Frame length to configure on the switch. * * @return * @n None * ============================================================================= */ void Init_Switch (uint32_t mtu) { CSL_CPSW_3GF_PORTSTAT portStatCfg; uint32_t rx_max_len = mtu + 14 + 4; /* 4 bytes of FCS */ CSL_CPSW_3GF_ALE_PORTCONTROL alePortControlCfg; /* Enable the CPPI port, i.e., port 0 that does all * the data streaming in/out of EMAC. */ CSL_CPSW_3GF_enablePort0 (); CSL_CPSW_3GF_disableVlanAware (); CSL_CPSW_3GF_setPort0VlanReg (0, 0, 0); CSL_CPSW_3GF_setPort0RxMaxLen (rx_max_len); /* Enable statistics on both the port groups: * * MAC Sliver ports - Port 1, Port 2 * CPPI Port - Port 0 */ portStatCfg.p0AStatEnable = 1; portStatCfg.p0BStatEnable = 1; portStatCfg.p1StatEnable = 1; portStatCfg.p2StatEnable = 1; CSL_CPSW_3GF_setPortStatsEnableReg (&portStatCfg); /* Setup the Address Lookup Engine (ALE) Configuration: * (1) Enable ALE. * (2) Clear stale ALE entries. * (3) Disable VLAN Aware lookups in ALE since * we are not using VLANs by default. * (4) No Flow control * (5) Configure the Unknown VLAN processing * properties for the switch, i.e., which * ports to send the packets to. */ CSL_CPSW_3GF_enableAle (); CSL_CPSW_3GF_clearAleTable (); CSL_CPSW_3GF_disableAleVlanAware (); CSL_CPSW_3GF_disableAleTxRateLimit (); /* Setting the Switch MTU Size to more than needed */ CSL_CPGMAC_SL_setRxMaxLen(0, rx_max_len); CSL_CPGMAC_SL_setRxMaxLen(1, rx_max_len); /* Configure the address in "Learning"/"Forward" state */ alePortControlCfg.portState = ALE_PORTSTATE_FORWARD; alePortControlCfg.dropUntaggedEnable = 0; alePortControlCfg.vidIngressCheckEnable = 0; alePortControlCfg.noLearnModeEnable = 0; alePortControlCfg.mcastLimit = 0; alePortControlCfg.bcastLimit = 0; CSL_CPSW_3GF_setAlePortControlReg (0, &alePortControlCfg); CSL_CPSW_3GF_setAlePortControlReg (1, &alePortControlCfg); CSL_CPSW_3GF_setAlePortControlReg (2, &alePortControlCfg); #ifdef SIMULATOR_SUPPORT CSL_CPSW_3GF_enableAleBypass(); #endif /* Done with switch configuration */ return; }