Пример #1
0
void view_ale_table(void)
{
	int i;
	CSL_CPSW_3GF_ALE_UNICASTADDR_ENTRY  ucastAddrCfg;
	
	for (i = 0; i < CSL_CPSW_3GF_NUMALE_ENTRIES; i++) {
		if (CSL_CPSW_3GF_getALEEntryType(i) != ALE_ENTRYTYPE_FREE) {	/* Found a free entry */
			CSL_CPSW_3GF_getAleUnicastAddrEntry (i, &ucastAddrCfg);
			printf("Port = %d, ", ucastAddrCfg.portNumber);
			printf("MAC address = %02x:%02x:%02x:%02x:%02x:%02x, ",
				ucastAddrCfg.macAddress[0],
				ucastAddrCfg.macAddress[1],
				ucastAddrCfg.macAddress[2],
				ucastAddrCfg.macAddress[3],
				ucastAddrCfg.macAddress[4],
				ucastAddrCfg.macAddress[5]);
			printf("unicast_type = %d\n", ucastAddrCfg.ucastType);
		}
	}
}
/** ============================================================================
 *   @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;
}