/***************************************************************************** * sampleAdmitOnlyTaggedFrame * * DESCRIPTION: * This routine will show how to configure a port to accept only vlan * tagged frames. * This routine assumes that 802.1Q has been enabled for the given port. * * INPUTS: * port - logical port to be configured. * * OUTPUTS: * None. * * RETURNS: * GT_OK - on success * GT_FAIL - on error * * COMMENTS: * Some device support Discard Untagged feature. If so, gprtSetDiscardUntagged * function will do the work. * *******************************************************************************/ GT_STATUS sampleAdmitOnlyTaggedFrame(GT_QD_DEV *dev,GT_LPORT port) { GT_STATUS status; GT_VTU_ENTRY vtuEntry; int i; /* * 0) If device support gprtSetDiscardUntagged, call the function. */ status = gprtSetDiscardUntagged(dev, port, GT_TRUE); switch (status) { case GT_OK: MSG_PRINT(("Done.\n")); return status; case GT_NOT_SUPPORTED: MSG_PRINT(("Try other method.\n")); break; default: MSG_PRINT(("Failure accessing device.\n")); return status; } /* * 1) Add VLAN ID 0xFFF with the given port as a member. */ gtMemSet(&vtuEntry,0,sizeof(GT_VTU_ENTRY)); vtuEntry.DBNum = 0; vtuEntry.vid = 0xFFF; for(i=0; i<dev->numOfPorts; i++) { vtuEntry.vtuData.memberTagP[i] = NOT_A_MEMBER; } vtuEntry.vtuData.memberTagP[port] = MEMBER_EGRESS_TAGGED; if((status = gvtuAddEntry(dev,&vtuEntry)) != GT_OK) { MSG_PRINT(("gvtuAddEntry returned fail.\n")); return status; } /* * 2) Configure the default vid for the given port with VID 0xFFF */ if((status = gvlnSetPortVid(dev,port,0xFFF)) != GT_OK) { MSG_PRINT(("gvlnSetPortVid returned fail.\n")); return status; } return GT_OK; }
/***************************************************************************** * sampleDisplayVIDTable * * DESCRIPTION: * This routine will show how to enumerate each vid entry in the VTU table * * INPUTS: * None. * * OUTPUTS: * None. * * RETURNS: * GT_OK - on success * GT_FAIL - on error * COMMENTS: * *******************************************************************************/ GT_STATUS sampleDisplayVIDTable(GT_QD_DEV *dev) { GT_STATUS status; GT_VTU_ENTRY vtuEntry; GT_LPORT port; int portIndex; gtMemSet(&vtuEntry,0,sizeof(GT_VTU_ENTRY)); vtuEntry.vid = 0xfff; if((status = gvtuGetEntryFirst(dev,&vtuEntry)) != GT_OK) { MSG_PRINT(("gvtuGetEntryCount returned fail.\n")); return status; } MSG_PRINT(("DBNum:%i, VID:%i \n",vtuEntry.DBNum,vtuEntry.vid)); for(portIndex=0; portIndex<dev->numOfPorts; portIndex++) { port = portIndex; MSG_PRINT(("Tag%i:%#x ",port,vtuEntry.vtuData.memberTagP[port])); } MSG_PRINT(("\n")); while(1) { if((status = gvtuGetEntryNext(dev,&vtuEntry)) != GT_OK) { break; } MSG_PRINT(("DBNum:%i, VID:%i \n",vtuEntry.DBNum,vtuEntry.vid)); for(portIndex=0; portIndex<dev->numOfPorts; portIndex++) { port = portIndex; MSG_PRINT(("Tag%i:%#x ",port,vtuEntry.vtuData.memberTagP[port])); } MSG_PRINT(("\n")); } return GT_OK; }
/******************************************************************************* * qdUnloadDriver * * DESCRIPTION: * This function unloads the QuaterDeck Driver. * * INPUTS: * None. * * OUTPUTS: * None. * * RETURNS: * GT_OK - on success * GT_FAIL - on error * * COMMENTS: * 1. This function should be called only after successful execution of * qdLoadDriver(). * *******************************************************************************/ GT_STATUS qdUnloadDriver ( IN GT_QD_DEV* dev ) { DBG_INFO(("qdUnloadDriver Called.\n")); /* Delete the MultiAddress mode reagister access semaphore. */ if(gtSemDelete(dev,dev->multiAddrSem) != GT_OK) { DBG_INFO(("Failed.\n")); return GT_FAIL; } /* Delete the ATU semaphore. */ if(gtSemDelete(dev,dev->atuRegsSem) != GT_OK) { DBG_INFO(("Failed.\n")); return GT_FAIL; } /* Delete the VTU semaphore. */ if(gtSemDelete(dev,dev->vtuRegsSem) != GT_OK) { DBG_INFO(("Failed.\n")); return GT_FAIL; } /* Delete the STATS semaphore. */ if(gtSemDelete(dev,dev->statsRegsSem) != GT_OK) { DBG_INFO(("Failed.\n")); return GT_FAIL; } gtMemSet(dev,0,sizeof(GT_QD_DEV)); return GT_OK; }
/***************************************************************************** * 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; }
static GT_STATUS stuGetSTUData ( IN GT_QD_DEV *dev, OUT GT_STU_ENTRY *entry ) { GT_STATUS retVal; /* Functions return value. */ GT_U16 data1,data2,data3; /* Data to be set into the */ GT_U16 nStuData = 0; data1 = data2 = data3 = 0; gtMemSet((void*)entry->portState,0,sizeof(entry->portState)); switch (dev->maxPorts) { case 11: case 10: case 9: nStuData = 3; break; case 8: case 7: case 6: case 5: nStuData = 2; break; case 4: case 3: case 2: case 1: nStuData = 1; break; default: return GT_FAIL; } switch(nStuData) { case 3: retVal = hwReadGlobalReg(dev,QD_REG_VTU_DATA3_REG,&data3); if(retVal != GT_OK) { return retVal; } /* pass through */ case 2: retVal = hwReadGlobalReg(dev,QD_REG_VTU_DATA2_REG,&data2); if(retVal != GT_OK) { return retVal; } /* pass through */ case 1: retVal = hwReadGlobalReg(dev,QD_REG_VTU_DATA1_REG,&data1); if(retVal != GT_OK) { return retVal; } break; default: return GT_FAIL; } switch (dev->maxPorts) { case 11: entry->portState[10] = (data3 >> 10) & 3 ; /* pass through */ case 10: entry->portState[9] = (data3 >> 6) & 3 ; /* pass through */ case 9: entry->portState[8] = (data3 >> 2) & 3 ; /* pass through */ case 8: entry->portState[7] = (data2 >> 14) & 3 ; /* pass through */ case 7: entry->portState[6] = (data2 >> 10) & 3 ; /* pass through */ case 6: entry->portState[5] = (data2 >> 6) & 3 ; /* pass through */ case 5: entry->portState[4] = (data2 >> 2) & 3 ; /* pass through */ case 4: entry->portState[3] = (data1 >> 14) & 3 ; /* pass through */ case 3: entry->portState[2] = (data1 >> 10) & 3 ; /* pass through */ case 2: entry->portState[1] = (data1 >> 6) & 3 ; /* pass through */ case 1: entry->portState[0] = (data1 >> 2) & 3 ; break; default: return GT_FAIL; } return GT_OK; }
/******************************************************************************* * qdUnloadDriver * * DESCRIPTION: * This function unloads the QuaterDeck Driver. * * INPUTS: * None. * * OUTPUTS: * None. * * RETURNS: * GT_OK - on success * GT_FAIL - on error * * COMMENTS: * 1. This function should be called only after successful execution of * qdLoadDriver(). * *******************************************************************************/ GT_STATUS qdUnloadDriver ( IN GT_QD_DEV* dev ) { DBG_INFO(("qdUnloadDriver Called.\n")); /* Delete the MultiAddress mode reagister access semaphore. */ if(gtSemDelete(dev,dev->multiAddrSem) != GT_OK) { DBG_INFO(("Failed.\n")); return GT_FAIL; } /* Delete the ATU semaphore. */ if(gtSemDelete(dev,dev->atuRegsSem) != GT_OK) { DBG_INFO(("Failed.\n")); return GT_FAIL; } /* Delete the VTU semaphore. */ if(gtSemDelete(dev,dev->vtuRegsSem) != GT_OK) { DBG_INFO(("Failed.\n")); return GT_FAIL; } /* Delete the STATS semaphore. */ if(gtSemDelete(dev,dev->statsRegsSem) != GT_OK) { DBG_INFO(("Failed.\n")); return GT_FAIL; } /* Delete the PIRL semaphore. */ if(gtSemDelete(dev,dev->pirlRegsSem) != GT_OK) { DBG_INFO(("Failed.\n")); return GT_FAIL; } /* Delete the PTP semaphore. */ if(gtSemDelete(dev,dev->ptpRegsSem) != GT_OK) { DBG_INFO(("Failed.\n")); return GT_FAIL; } /* Delete the Table semaphore. */ if(gtSemDelete(dev,dev->tblRegsSem) != GT_OK) { DBG_INFO(("Failed.\n")); return GT_FAIL; } /* Delete the EEPROM Configuration semaphore. */ if(gtSemDelete(dev,dev->eepromRegsSem) != GT_OK) { DBG_INFO(("Failed.\n")); return GT_FAIL; } /* Delete the PHY Device semaphore. */ if(gtSemDelete(dev,dev->phyRegsSem) != GT_OK) { DBG_INFO(("Failed.\n")); return GT_FAIL; } /* Delete the Remote management Register Access semaphore. */ if(gtSemDelete(dev,dev->hwAccessRegsSem) != GT_OK) { DBG_INFO(("Failed.\n")); return GT_FAIL; } gtMemSet(dev,0,sizeof(GT_QD_DEV)); return GT_OK; }