Esempio n. 1
0
/*****************************************************************************
* sample802_1qSetup
*
* DESCRIPTION:
*        This routine will show how to configure the switch device so that it 
*        can be a Home Gateway. This example assumes that all the frames are not 
*        VLAN-Tagged.
*        1) to clear VLAN ID Table,
*         2) to enable 802.1Q in SECURE mode for each port except CPU port,
*        3) to enable 802.1Q in FALL BACK mode for the CPU port. 
*        4) to add VLAN ID 1 with member port 0 and CPU port 
*        (untagged egress),
*        5) to add VLAN ID 2 with member the rest of the ports and CPU port 
*        (untagged egress), 
*        6) to configure the default vid of each port:
*        Port 0 have PVID 1, CPU port has PVID 3, and the rest ports have PVID 2.
*        Note: CPU port's PVID should be unknown VID, so that QuarterDeck can use 
*        VlanTable (header info) for TX.
*
*
* INPUTS:
*       None.
*
* OUTPUTS:
*       None.
*
* RETURNS:
*       GT_OK               - on success
*       GT_FAIL             - on error
*
* COMMENTS: 
*        WARNING!!
*        If you create just two VLAN for this setup, Trailer mode or Header mode 
*        for the CPU port has to be enabled and Ethernet driver which connects to
*        CPU port should understand VLAN-TAGGING, Trailer mode, or Header mode.
*
*******************************************************************************/
GT_STATUS sample802_1qSetup(GT_QD_DEV *dev)
{
    GT_STATUS status;
    GT_DOT1Q_MODE mode;
        GT_VTU_ENTRY vtuEntry;
    GT_U16 vid;
    GT_LPORT port;
    int i;

    /*
     *    1) Clear VLAN ID Table
    */
    if((status = gvtuFlush(dev)) != GT_OK)
    {
        MSG_PRINT(("gvtuFlush returned fail.\n"));
        return status;
    }

    /*
     *    2) Enable 802.1Q for each port as GT_SECURE mode except CPU port.
    */
    mode = GT_SECURE;
    for(i=0; i<dev->numOfPorts; i++)
    {
        port = i;
        if (port == dev->cpuPortNum)
            continue;

        if((status = gvlnSetPortVlanDot1qMode(dev,port, mode)) != GT_OK)
        {
            MSG_PRINT(("gvlnSetPortVlanDot1qMode return Failed\n"));
            return status;
        }
    }

    /*
     *    3) Enable 802.1Q for CPU port as GT_FALLBACK mode
    */
    if((status = gvlnSetPortVlanDot1qMode(dev, dev->cpuPortNum, GT_FALLBACK)) != GT_OK)
    {
        MSG_PRINT(("gvlnSetPortVlanDot1qMode return Failed\n"));
        return status;
    }

    /*
     *    4) Add VLAN ID 1 with Port 0 and CPU Port as members of the Vlan.
    */
    gtMemSet(&vtuEntry,0,sizeof(GT_VTU_ENTRY));
    vtuEntry.DBNum = 0;
    vtuEntry.vid = 1;
    for(i=0; i<dev->numOfPorts; i++)
    {
        port = i;
        if((i==0) || (port == dev->cpuPortNum))
            vtuEntry.vtuData.memberTagP[port] = MEMBER_EGRESS_UNTAGGED;
        else
            vtuEntry.vtuData.memberTagP[port] = NOT_A_MEMBER;
    }

    if((status = gvtuAddEntry(dev,&vtuEntry)) != GT_OK)
    {
        MSG_PRINT(("gvtuAddEntry returned fail.\n"));
        return status;
    }

    /*
     *    5) Add VLAN ID 2 with the rest of the Ports and CPU Port as members of 
     *    the Vlan.
    */
    gtMemSet(&vtuEntry,0,sizeof(GT_VTU_ENTRY));
    vtuEntry.DBNum = 0;
    vtuEntry.vid = 2;
    for(i=0; i<dev->numOfPorts; i++)
    {
        port = i;
        if(i == 0)
            vtuEntry.vtuData.memberTagP[port] = NOT_A_MEMBER;
        else
            vtuEntry.vtuData.memberTagP[port] = MEMBER_EGRESS_UNTAGGED;
    }

    if((status = gvtuAddEntry(dev,&vtuEntry)) != GT_OK)
    {
        MSG_PRINT(("gvtuAddEntry returned fail.\n"));
        return status;
    }


    /*
     *    6) Configure the default vid for each port.
     *    Port 0 has PVID 1, CPU port has PVID 3, and the rest ports have PVID 2.
    */
    for(i=0; i<dev->numOfPorts; i++)
    {
        port = i;
        if(i==0)
            vid = 1;
        else if(port == dev->cpuPortNum)
            vid = 3;
        else
            vid = 2;

        if((status = gvlnSetPortVid(dev,port,vid)) != GT_OK)
        {
            MSG_PRINT(("gvlnSetPortVid returned fail.\n"));
            return status;
        }
    }

    return GT_OK;

}
Esempio n. 2
0
int mv_switch_unload(unsigned int switch_ports_mask)
{
	int i;

	printk(KERN_ERR "  o Unloading Switch QuarterDeck driver\n");

	if (qd_dev == NULL) {
		printk(KERN_ERR "    o %s: Already un-initialized\n", __func__);
		return 0;
	}

	/* Flush all addresses from the MAC address table */
	/* this also happens in mv_switch_init() but we call it here to clean-up nicely */
	/* Note: per DB address flush (gfdbFlushInDB) happens when doing ifconfig down on a Switch interface */
	if (gfdbFlush(qd_dev, GT_FLUSH_ALL) != GT_OK)
		printk(KERN_ERR "gfdbFlush failed\n");

	/* Reset VLAN tunnel mode */
	for (i = 0; i < qd_dev->numOfPorts; i++) {
		if (MV_BIT_CHECK(switch_ports_mask, i) && (i != qd_cpu_port))
			if (gprtSetVlanTunnel(qd_dev, i, GT_FALSE) != GT_OK)
				printk(KERN_ERR "gprtSetVlanTunnel failed (port %d)\n", i);
	}

	/* restore port's default private vlan id and database number to their default values after reset: */
	for (i = 0; i < qd_dev->numOfPorts; i++) {
		if (gvlnSetPortVid(qd_dev, i, 0x0001) != GT_OK) { /* that's the default according to the spec */
			printk(KERN_ERR "gvlnSetPortVid failed\n");
			return -1;
		}
		if (gvlnSetPortVlanDBNum(qd_dev, i, 0) != GT_OK) {
			printk(KERN_ERR "gvlnSetPortVlanDBNum failed\n");
			return -1;
		}
	}

	/* Port based VLAN */
	if (mv_switch_port_based_vlan_set(switch_ports_mask, 1))
		printk(KERN_ERR "mv_switch_port_based_vlan_set failed\n");

	/* Remove all entries from the VTU table */
	if (gvtuFlush(qd_dev) != GT_OK)
		printk(KERN_ERR "gvtuFlush failed\n");

	/* unload switch sw package */
	if (qdUnloadDriver(qd_dev) != GT_OK) {
		printk(KERN_ERR "qdUnloadDriver failed\n");
		return -1;
	}
	qd_dev = NULL;
	qd_cpu_port = -1;
	qsgmii_module = 0;
	gephy_on_port = -1;
	rgmiia_on_port = -1;

#ifdef CONFIG_MV_ETH_SWITCH_LINK
	switch_irq = -1;
	switch_link_poll = 0;
	del_timer(&switch_link_timer);
#endif /* CONFIG_MV_ETH_SWITCH_LINK */

	return 0;
}