Exemplo n.º 1
0
/*
 * Function definition: ixEthAccCodeletDBLearningRun()
 *
 * Run ethDB demo for all ports passed as parameters
 */
IX_STATUS 
ixEthAccCodeletDBLearningRun(BOOL validPorts[])
{
    IxEthAccPortId portId;
    IxEthDBPortId portPtr;

    IxEthDBMacAddr staticMacAddress[IX_ETHACC_CODELET_MAX_PORT] = 
	{{{0,1,2,3,4,5}}, {{6,7,8,9,0,1}}};

    IxEthDBMacAddr dynamMacAddress[IX_ETHACC_CODELET_MAX_PORT] = 
	{{{0xa,0xb,0xc,0xd,0xe,0xf}}, {{0x0,0xb,0x3,0xc,0x4,0xd}}};

    if (ixEthAccCodeletDBMaintenanceStart()
	!= IX_SUCCESS)
    {
	printf("DbLearning: Error spawning DB maintenance task\n");
	return (IX_FAIL);
    }

    /* configure all existing ports */
    for (portId = 0; portId < IX_ETHACC_CODELET_MAX_PORT; portId++)
    {
	if (validPorts[portId])
	{
	    /* Configure the port */
	    printf("Configuring the port...\n");

	    if (ixEthAccCodeletPortConfigure(portId,
					     ixEthAccCodeletMemPoolFreeRxCB,
					     (IxEthAccPortMultiBufferRxCallback) NULL,
					     ixEthAccCodeletMemPoolFreeTxCB,
					     portId) 
		!= IX_ETH_ACC_SUCCESS)
	    {
		printf("DbLearning: Failed to configure the port %u\n",
		       (UINT32)portId);
		return IX_FAIL;
	    }

	    /* Enable the port */
	    printf("Enabling the port...\n");

	    if(ixEthAccPortEnable(portId) != IX_ETH_ACC_SUCCESS)
	    {
		printf("DbLearning: Error enabling port %u\n", 
		       (UINT32)portId);
		return (IX_FAIL);
	    }
	    
	    /* Add some static entries */
	    printf("Adding static entries...\n");
	    
	    if (ixEthDBFilteringStaticEntryProvision(portId,
						     &staticMacAddress[portId])
		!= IX_ETH_DB_SUCCESS)
	    {
		printf("DbLearning: Failed to add static MAC to port %u\n", 
		       (UINT32)portId);
		return (IX_FAIL);
	    }

            ixOsalSleep(100);
	    
	    /* Verify that the address has successfully been added */
	    if (ixEthDBFilteringDatabaseSearch(&portPtr, 
					       &staticMacAddress[portId])
		== IX_ETH_DB_NO_SUCH_ADDR)
	    {
		printf("DbLearning: Static MAC address not found in Database\n");
		return (IX_FAIL);
	    }
	    
	    /* Add some dynamic entries */
	    printf("Adding dynamic entries...\n");
	    
	    if (ixEthDBFilteringDynamicEntryProvision(portId,
						      &dynamMacAddress[portId])
		!= IX_ETH_DB_SUCCESS)
	    {
		printf("DbLearning: Failed to add dynamic MAC to port %u\n", 
		       (UINT32)portId);
	    }
	    
	    printf("Enabling aging...\n");
	    
	    if (ixEthDBPortAgingEnable(portId) != IX_ETH_DB_SUCCESS)
	    {
		printf("DbLearning: Failed to enable aging for port %u\n", 
		       (UINT32)portId);
		return (IX_FAIL);
	    }
	}
    }
 
    ixEthDBFilteringDatabaseShowAll();

    /* Wait 4 minutes over aging time (for safety) and verify that the 
     * dynamic entries have been removed 
     */
    printf("Aging entries.\nWaiting for %d minutes...\n", 
	   IX_ETH_DB_LEARNING_ENTRY_AGE_TIME / 60 + 3);
    
    ixOsalSleep((IX_ETH_DB_LEARNING_ENTRY_AGE_TIME + 180) * 1000);
     
    ixEthDBFilteringDatabaseShowAll();
    
    for (portId = 0; portId < IX_ETHACC_CODELET_MAX_PORT; portId++)
    {
	if (validPorts[portId])
	{
	    if(ixEthDBFilteringEntryDelete(&staticMacAddress[portId])
	       != IX_ETH_DB_SUCCESS)
	    {
		printf("DbLearning: Failed to remove static MAC on port %u\n", 
		       (UINT32)portId);
	    }
	    
	    /* Disable ports */
	    if(ixEthAccPortDisable(portId) != IX_ETH_ACC_SUCCESS)
	    {
		printf("DbLearning: Error disabling port %u\n",
		       (UINT32)portId);
		return (IX_FAIL);
	    }
	}
    }

    /* wait for pending traffic to be completely received */
    if (ixEthAccCodeletRecoverBuffers() 
	!= IX_SUCCESS)
    {
	printf("Warning : Not all buffers are accounted for!\n");
    }    

    return (IX_SUCCESS);
}
Exemplo n.º 2
0
/*
 * Function definition: ixEthAccCodeletInit()
 *
 * See header file for documentation.
 */
IX_STATUS ixEthAccCodeletInit(IxEthAccCodeletOperation operationType,
                    IxEthAccPortId inPort,
                    IxEthAccPortId outPort)
{  
    IxEthAccPortId portId;

    IxOsalThread statsPollThread;
    IxOsalThreadAttr threadAttr;

    threadAttr.name      = "Codelet Stats";
    threadAttr.stackSize = 32 * 1024; /* 32kbytes */
    threadAttr.priority  = 128;


#ifdef __ixp46X
    /* Set the expansion bus fuse register to enable MUX for NPEA MII */
    {
        UINT32 expbusCtrlReg;
        expbusCtrlReg = ixFeatureCtrlRead ();
        expbusCtrlReg |= ((unsigned long)1<<8);
        ixFeatureCtrlWrite (expbusCtrlReg);
    }
#endif

    /* check the component is already initialized */
    if(ixEthAccCodeletInitialised) 
    {
	printf("CodeletMain: Ethernet codelet already initialised\n");
	return(IX_SUCCESS);
    }

#ifdef __vxworks
    /* When the ixe drivers are running, the codelets
    * cannot run.
    */
    for (portId = 0; portId < IX_ETHACC_CODELET_MAX_PORT; portId++)
    {
        if (endFindByName ("ixe", portId) != NULL)
        {
            printf("CodeletMain: FAIL: Driver ixe%d detected\n",portId);
            return IX_FAIL;
        }
    }
#endif

    /* Initialize NPE IMAGE ID here again to prevent confusion in multiple 
     * ixEthAccCodeletMain() calls with different operationType.
     */   
    ETH_NPEA_IMAGEID = IX_NPEDL_NPEIMAGE_NPEA_ETH_MACFILTERLEARN_HSSCHAN_COEXIST;
    ETH_NPEB_IMAGEID = IX_NPEDL_NPEIMAGE_NPEB_ETH_LEARN_FILTER_SPAN_MASK_FIREWALL_VLAN_QOS_EXTMIB;
    ETH_NPEC_IMAGEID = IX_NPEDL_NPEIMAGE_NPEC_ETH_LEARN_FILTER_SPAN_MASK_FIREWALL_VLAN_QOS_EXTMIB;

    /* Create mutexes for thread control */
    ixEthAccCodeletStatsPollTaskStop = TRUE;
    ixOsalMutexInit (&ixEthAccCodeletStatsPollTaskRunning);

    /* Initialise MBUF pool */
    if(ixEthAccCodeletMemPoolInit() != IX_SUCCESS)
    {
	printf("CodeletMain: Error initialising mBuf pool\n");
	return (IX_FAIL);
    }

    /* Check Silicon stepping */
    printf("Checking Silicon stepping...\n");

    if (ixFeatureCtrlDeviceRead() == IX_FEATURE_CTRL_DEVICE_TYPE_IXP42X)
    {

        if ((ixFeatureCtrlProductIdRead() & IX_FEATURE_CTRL_SILICON_STEPPING_MASK) == 
           IX_FEATURE_CTRL_SILICON_TYPE_B0)
        {
            /*
             * If it is B0 Silicon, we only enable port when its corresponding  
             * Eth Coprocessor is available.
             */
            if (ixFeatureCtrlComponentCheck(IX_FEATURECTRL_ETH0) == 
                IX_FEATURE_CTRL_COMPONENT_ENABLED)
            {
                ixEthAccCodeletHardwareExists[IX_ETH_PORT_1] = TRUE;
            }

            if (ixFeatureCtrlComponentCheck(IX_FEATURECTRL_ETH1) == 
               IX_FEATURE_CTRL_COMPONENT_ENABLED)
            {
                ixEthAccCodeletHardwareExists[IX_ETH_PORT_2] = TRUE;
            }
        }
        else if ((ixFeatureCtrlProductIdRead() & IX_FEATURE_CTRL_SILICON_STEPPING_MASK) == 
                  IX_FEATURE_CTRL_SILICON_TYPE_A0) 
        {
            /*
             * If it is A0 Silicon, we enable both as both Eth Coprocessors 
             * are available. 
             */ 
            ixEthAccCodeletHardwareExists[IX_ETH_PORT_1] = TRUE;
            ixEthAccCodeletHardwareExists[IX_ETH_PORT_2] = TRUE;
        }
        else
        {
            printf("CodeletMain: Error. Operation for other silicon stepping is undefined!.\n");
            return (IX_FAIL);
        }
    }
    else if (ixFeatureCtrlDeviceRead() == IX_FEATURE_CTRL_DEVICE_TYPE_IXP46X)
    {
        ixEthAccCodeletHardwareExists[IX_ETH_PORT_1] = TRUE;
        ixEthAccCodeletHardwareExists[IX_ETH_PORT_2] = TRUE;
#ifdef __ixp46X
        ixEthAccCodeletHardwareExists[IX_ETH_PORT_3] = TRUE;
#endif
    }

    /***********************************************************************
     *
     * System initialisation done. Now initialise Access components. 
     *
     ***********************************************************************/

    /* Initialise Queue Manager */
    printf("Initialising Queue Manager...\n");
    if (ixQMgrInit() != IX_SUCCESS)
    {
	printf("CodeletMain: Error initialising queue manager!\n");
	return (IX_FAIL);
    }

    /* Start the Queue Manager dispatcher */   
    if(ixEthAccCodeletDispatcherStart(IX_ETH_CODELET_QMGR_DISPATCH_MODE) 
       != IX_SUCCESS)
    {
	printf("CodeletMain: Error starting queue manager dispatch loop!\n");
	return (IX_FAIL);
    }

    /* Initialise NPE Message handler */
    printf("\nStarting NPE message handler...\n");
    if(ixNpeMhInitialize(IX_NPEMH_NPEINTERRUPTS_YES) != IX_SUCCESS)
    {
	printf("CodeletMain: Error initialising NPE Message handler!\n");
	return (IX_FAIL);
    }

    /* Initialise NPEs firmware */
    printf ("Initialising NPEs...\n");
    if (ixEthAccCodeletHardwareExists[IX_ETH_PORT_1])
    {
        if ((operationType == IX_ETHACC_CODELET_BRIDGE_WIFI) && (inPort == IX_ETH_PORT_1))
        {
            printf("CodeletMain: the 802.3 <=> 802.11 header conversion image is loaded on NPE B\n");
            ETH_NPEB_IMAGEID = IX_NPEDL_NPEIMAGE_NPEB_ETH_SPAN_VLAN_QOS_HDR_CONV_EXTMIB;
        }

	if (IX_SUCCESS != ixNpeDlNpeInitAndStart(ETH_NPEB_IMAGEID))
        {
	    printf ("CodeletMain: Error initialising and starting NPE B!\n");
	    return (IX_FAIL);
	}
    }

    if (ixEthAccCodeletHardwareExists[IX_ETH_PORT_2])
    {
        if ((operationType == IX_ETHACC_CODELET_BRIDGE_WIFI) && (inPort == IX_ETH_PORT_2))
        {
            printf("CodeletMain: the 802.3 <=> 802.11 header conversion image is loaded on NPE C\n");
            ETH_NPEC_IMAGEID = IX_NPEDL_NPEIMAGE_NPEC_ETH_SPAN_VLAN_QOS_HDR_CONV_EXTMIB;
        }

	if (IX_SUCCESS != ixNpeDlNpeInitAndStart(ETH_NPEC_IMAGEID))
        {
	    printf ("CodeletMain: Error initialising and starting NPE C!\n");
	    return (IX_FAIL);
	}
    }
#ifdef __ixp46X
    if (ixEthAccCodeletHardwareExists[IX_ETH_PORT_3])
    {
        if ((operationType == IX_ETHACC_CODELET_BRIDGE_WIFI) && (inPort == IX_ETH_PORT_3))
        {
            printf("CodeletMain: the 802.3 <=> 802.11 header conversion image is loaded on NPE A\n");
            ETH_NPEA_IMAGEID = IX_NPEDL_NPEIMAGE_NPEA_ETH_SPAN_VLAN_QOS_HDR_CONV_EXTMIB;
        }

	if (IX_SUCCESS != ixNpeDlNpeInitAndStart(ETH_NPEA_IMAGEID))
        {
	    printf ("CodeletMain: Error initialising and starting NPE A!\n");
	    return (IX_FAIL);
	}
    }
#endif

    printf ("Initialising Access Layers\n");

    /* Enable QoS on ethDB. This has to be done before ethAcc initialisation */
    if (operationType == IX_ETHACC_CODELET_BRIDGE_QOS)
    {
	printf("Enabling QoS\n");
        if (IX_ETH_DB_SUCCESS != ixEthDBInit())
	{
	    printf ("CodeletMain: Error initialising EthDB\n");
	    return (IX_FAIL);
	}

	(void)ixEthDBPortInit(inPort);

        if (IX_ETH_DB_SUCCESS != ixEthDBFeatureEnable(inPort, 
						      IX_ETH_DB_VLAN_QOS, 
						      TRUE))
	{
            printf("CodeletMain: Error enabling QoS on port %d\n",inPort);
	    return (IX_FAIL);
        }
    }

    /* initialise ethAcc : QoS, if needed is already configured */
    if (ixEthAccInit() != IX_ETH_ACC_SUCCESS)
    {
	printf("CodeletMain: Error initialising Ethernet access driver!\n");
	return (IX_FAIL);
    }

    /***********************************************************************
     *
     * Access components initialisation done. Now initialize the ports
     *
     ***********************************************************************/

    /* Configure all available ports */
    for (portId = 0; portId < IX_ETHACC_CODELET_MAX_PORT; portId++)
    {
	if (ixEthAccCodeletHardwareExists[portId])
	{
	    if(ixEthAccCodeletPortInit(portId) != IX_ETH_ACC_SUCCESS)
            {
   	        printf("CodeletMain: Error setup port %u\n",
		       portId);
	        return (IX_FAIL);
            }
        }
    }

    /* Find and initialise all available PHYs */
    printf ("Discover and reset the PHYs...\n");
    if(ixEthAccCodeletPhyInit() != IX_SUCCESS)
    {
	printf("CodeletMain: Error initialising Ethernet phy(s)!\n");
	return (IX_FAIL);
    }

    /***********************************************************************
     *
     * PortInitialization done. Now start the codelet features
     *
     ***********************************************************************/

    /* starts ethDB maintenance running from a different task */
    if (ixEthAccCodeletDBMaintenanceStart()
	!= IX_SUCCESS)
    {
	printf("CodeletMain: Error spawning DB maintenance task\n");
	return (IX_FAIL);
    }

    /* Starts the traffic display (in a different task) this is initially
     * set to FALSE in order to allow the traffic stats to start only
     * once traffic is started to be received 
     */
    ixEthAccCodeletTrafficPollEnabled = FALSE;

    if (ixOsalThreadCreate(&statsPollThread,
			   &threadAttr,
			   (IxOsalVoidFnVoidPtr) ixEthAccCodeletStatsPollTask,
			   NULL)	
	!= IX_SUCCESS)
    {
	printf("CodeletMain: Error spawning stats task\n");
	return (IX_FAIL);
    }

     /* Start the thread */
    if (ixOsalThreadStart(&statsPollThread) != IX_SUCCESS)
    {
	printf("CodeletMain: Error failed to start the stats thread\n");
        return IX_FAIL;
    }
    ixEthAccCodeletInitialised = TRUE;
    return (IX_SUCCESS);
}