/**
 * \file hal.c
 * \brief File to define HAL related functions
 *
 * \copyright Copyright (c) 2012 Texas Instruments Incorporated ALL RIGHTS RESERVED
 *
*/

/* ========================================================================== */
/*                             Include Files                                  */
/* ========================================================================== */
#include <ti/ndk/inc/stkmain.h>
#include "eip_main.h"
#include "hal.h"
#include "osdrv_spiflash.h"
#ifdef USE_CPSW_DRIVER
#include "cpsw_ioctl.h"
#else
#include "icss_ioctl.h"
#include "icss_iSwitchDrv.h"
#include "icss_ethdriver.h"
#endif

/* ========================================================================== */
/*                            Global Variables                                */
/* ========================================================================== */

/**Structure to store Ethernet INterface control parameters*/
ST_ETH_CONTROL          gstEthControl[2];
/**Structure to store Configuration control parameters*/
ST_TCPIP_CONTROL        gstTcpIpControl;
/**Structure to store Interface Configuration  parameters*/
ST_TCPIP_CONFIGURATION  gstTcpIpConfiguration;
extern ST_TCPIP_CONFIGURATION  eipDevTcpIpConfiguration;
DWORD ifConnfigACDStat=0;

/**Host Name of the Device*/
EIP_CHAR gszHostName[65];


/* ========================================================================== */
/*                          Function Definitions                              */
/* ========================================================================== */


/**
 *  \name HAL_GetCapability
 *  \brief The function informs about the capability of Ethernetip Implementation
 *  \param pstCapability variable where capabilities need to be stored
 *  \return EIP_TRUE on Success
 *
 */
EIP_BOOL HAL_GetCapability(ST_CAPABILITY * pstCapability)
{
	pstCapability->wInternalETHInstance = 1;
	pstCapability->bF6RequiresReset = EIP_TRUE;
	pstCapability->wF5IfConfigurationStatus                   = F5_ATTR1_OBTAINED_BOOTP_DHCP_STOREDVALUE;
	pstCapability->stF5ConfCapability.bBootpClient            = EIP_FALSE;
	pstCapability->stF5ConfCapability.bDnsClient              = EIP_FALSE;
	pstCapability->stF5ConfCapability.bDhcpClient             = EIP_TRUE;
	pstCapability->stF5ConfCapability.bDhcpDnsUpdate          = EIP_FALSE;
	pstCapability->stF5ConfCapability.bConfigurationSettable  = EIP_TRUE;
	pstCapability->stF5ConfCapability.bHostNameSettable       = EIP_TRUE;
	pstCapability->stF5ConfCapability.bHardwareConfigurable   = EIP_FALSE;
	pstCapability->stF5ConfCapability.bMcastAndTtlSettable    = EIP_FALSE;
	pstCapability->stF5ConfCapability.bIfConfRequiresReset    = EIP_TRUE;
	pstCapability->stF5ConfCapability.bAcdCapable             = EIP_TRUE; // EIP_GetCapability(EIP_CAPABILITY_BIT_ACD);

	return EIP_TRUE;
}


/*---------------------------------------------------------------------------*/
/* ----------------------------- [ TCP/IP ] -------------------------------- */
/*---------------------------------------------------------------------------*/

/**
 *  \name HAL_GetConfigurationControl
 *  \brief The function returns the Configuration control attribute of TCP/IP object
 *  \param pstF5ConfigurationControl  structure where configuration need to be filled
 *  \return EIP_TRUE on Success
 *
 */
EIP_BOOL HAL_GetConfigurationControl(ST_TCPIP_CONTROL * pstF5ConfigurationControl)
{
	*pstF5ConfigurationControl = gstTcpIpControl;
  
	return EIP_TRUE;
}

/**
 *  \name HAL_SetConfigurationControl
 *  \brief The function is called to set Configuration control attribute of TCP/IP object
 *  \param pstF5ConfigurationControl structure which specifies attribute values
 *  \return EIP_TRUE on Success
 *
 */
EIP_BOOL HAL_SetConfigurationControl(ST_TCPIP_CONTROL * pstF5ConfigurationControl)
{
	EPROM_TCPIP tempTCPIPConfig;
	gstTcpIpControl = *pstF5ConfigurationControl;

	tempTCPIPConfig.deviceIP = gstTcpIpConfiguration.IP_Address;
	tempTCPIPConfig.gatewayAddress = gstTcpIpConfiguration.Gateway_Address;
	tempTCPIPConfig.networkMask = gstTcpIpConfiguration.Network_Mask;
	tempTCPIPConfig.serverName =gstTcpIpConfiguration.Name_Server;

	switch(gstTcpIpControl.wStartupConfiguration)
	{
		case 2:
			tempTCPIPConfig.startupType =EIP_STARTUP_DHCP;
			WritePermanentMemory((EIP_BYTE*)&tempTCPIPConfig,sizeof(EPROM_TCPIP),SPI_EEPROM_DEVICEIP_OFFSET);
			break;
		case 0:
			tempTCPIPConfig.startupType =EIP_STARTUP_STATICIP;
			WritePermanentMemory((EIP_BYTE*)&tempTCPIPConfig,sizeof(EPROM_TCPIP),SPI_EEPROM_DEVICEIP_OFFSET);
			break;
		default:
			break;
	}
	return EIP_TRUE;
}

/**
 *  \name HAL_GetInterfaceConfiguration
 *  \brief The function returns the Interface configuration attribute of TCP/IP object
 *  \param pTcpIpConfiguration  structure where Interface configuration will be filled
 *  \return EIP_TRUE on Success
 *
 */
EIP_BOOL HAL_GetInterfaceConfiguration(ST_TCPIP_CONFIGURATION * pTcpIpConfiguration)
{
	*pTcpIpConfiguration = gstTcpIpConfiguration;
	return EIP_TRUE;
}

/**
 *  \name HAL_SetConfigurationControl
 *  \brief The function is called to set Interface configuration attribute of TCP/IP object
 *  \param pTcpIpConfiguration structure which specifies attribute values
 *  \return EIP_TRUE on Success
 *
 */
EIP_BOOL HAL_SetInterfaceConfiguration(ST_TCPIP_CONFIGURATION * pTcpIpConfiguration)
{
	EPROM_TCPIP tempTCPIPConfig;

	tempTCPIPConfig.startupType = EIP_STARTUP_STATICIP;
	tempTCPIPConfig.deviceIP = pTcpIpConfiguration->IP_Address;
	tempTCPIPConfig.gatewayAddress = pTcpIpConfiguration->Gateway_Address;
	tempTCPIPConfig.networkMask = pTcpIpConfiguration->Network_Mask;
	tempTCPIPConfig.serverName =pTcpIpConfiguration->Name_Server;

	WritePermanentMemory((EIP_BYTE*)&tempTCPIPConfig,sizeof(EPROM_TCPIP),SPI_EEPROM_DEVICEIP_OFFSET);
	gstTcpIpConfiguration = *pTcpIpConfiguration;
	return EIP_TRUE;
}

/**
 *  \name HAL_GetHostName
 *  \brief The function is called to obtain the Host Name
 *  \param pBuffer variable where hostname need to be copyied
 *  \param pwBufferSize size of hostname
 *  \return EIP_TRUE on Success
 *
 */
EIP_BOOL HAL_GetHostName(EIP_CHAR * pBuffer, EIP_WORD *pwBufferSize)
{
  
	strncpy(pBuffer,gszHostName,*pwBufferSize);
	*pwBufferSize = (EIP_WORD)strlen(gszHostName);

	return EIP_TRUE;
}

/**
 *  \name HAL_SetHostName
 *  \brief Function to set the Host Name
 *  \param pBuffer hostname to be set
 *  \param pwBufferSize size of hostname
 *  \return EIP_TRUE on Success
 *
 */
EIP_BOOL HAL_SetHostName(EIP_CHAR * pBuffer, EIP_WORD wBufferSize)
{
	strncpy(gszHostName,pBuffer,wBufferSize);
	pBuffer[wBufferSize] = 0;

	return EIP_TRUE;
}

/**
 *  \name HAL_GetSafetyNetworkNumber
 *  \brief Function to get the SafetyNetwork Number (Not IMplemented)
 *  \param pSafetyNetworkNumber safety network number
 *  \return EIP_TRUE on Success
 *
 */
EIP_BOOL HAL_GetSafetyNetworkNumber(EIP_BYTE * pSafetyNetworkNumber)
{
	pSafetyNetworkNumber[0] = 1;
	pSafetyNetworkNumber[1] = 2;
	pSafetyNetworkNumber[2] = 3;
	pSafetyNetworkNumber[3] = 4;
	pSafetyNetworkNumber[4] = 5;
	pSafetyNetworkNumber[5] = 6;
  
	return EIP_TRUE;
}

/*---------------------------------------------------------------------------*/
/* ----------------------------- [ ETHERNET ] ------------------------------ */
/*---------------------------------------------------------------------------*/

/**
 *  \name HAL_GetInterfaceSpeed
 *  \brief Function to get the Interface speed
 *  \param wInstance Ethernet instance
 *  \param pdwIfSpeed speed of the interface
 *  \return EIP_TRUE on Success
 *
 */
EIP_BOOL HAL_GetInterfaceSpeed(EIP_WORD wInstance, EIP_DWORD * pdwIfSpeed)
{

#ifdef USE_CPSW_DRIVER
		NIMU_IF_REQ device;
		device.index = 1;
		device.name[0] = 0;

		SwitchConsCmd cmd;
		cmd.opcode =CPSW3G_IOCTL_GET_PORT_CONFIG;
		cmd.PortCmd.port = wInstance-1;
		NIMUIoctl(CPSW3G_IOCTL_SWITCH_CMD,&device,&cmd,sizeof(cmd));

		if(cmd.PortCmd.linkStat)
		{
			gstEthControl[wInstance-1].wForceInterfaceSpeed = cmd.PortCmd.value/1000000;
			*pdwIfSpeed = gstEthControl[wInstance-1].wForceInterfaceSpeed;
		}
		else
			*pdwIfSpeed =0;


#else

	if(GetLinkStatus(wInstance))
	{
		 NIMU_IF_REQ device;
		device.index = 1;
		device.name[0] = 0;

		SwitchConsCmd cmd;

		cmd.opcode =ICSS_IOCTL_GET_PORT_CONFIG;
		cmd.CmdType.PortCmd.port = wInstance;
		NIMUIoctl(ICSS_IOCTL_SWITCH_CMD,&device,&cmd,sizeof(cmd));
		gstEthControl[wInstance-1].wForceInterfaceSpeed = cmd.CmdType.PortCmd.value/1000000;
		*pdwIfSpeed = gstEthControl[wInstance-1].wForceInterfaceSpeed;
	}
	else
	{
		*pdwIfSpeed =0;
	}
#endif
	return EIP_TRUE;
}

/**
 *  \name HAL_GetInterfaceFlags
 *  \brief Function to get the Interface properites
 *  \param wInstance Ethernet instance
 *  \param pstF6InterfaceFlags structure where details will be returned
 *  \return EIP_TRUE on Success
 *
 */
EIP_BOOL HAL_GetInterfaceFlags(EIP_WORD wInstance, ST_F6_INTERFACE_FLAGS * pstF6InterfaceFlags)
{
	NIMU_IF_REQ device;
	device.index = 1;
	device.name[0] = 0;
	SwitchConsCmd cmd;

#ifndef USE_CPSW_DRIVER
	pstF6InterfaceFlags->bLinkStatus          = GetLinkStatus(wInstance);
	if(pstF6InterfaceFlags->bLinkStatus)
	{
		cmd.opcode =ICSS_IOCTL_GET_PORT_CONFIG;
		cmd.CmdType.PortCmd.port = wInstance;
		NIMUIoctl(ICSS_IOCTL_SWITCH_CMD,&device,&cmd,sizeof(cmd));

		if (gstEthControl[wInstance-1].bAutoNegotiate)
		{
			pstF6InterfaceFlags->wNegotiationStatus   = F6_ATTR2_AUTO_NEG_SUCCESS;
			pstF6InterfaceFlags->bFullDuplex          = cmd.CmdType.PortCmd.EnDis-1;
		}
		else
		{
			pstF6InterfaceFlags->wNegotiationStatus   = F6_ATTR2_AUTO_NEG_NOT_ATTEMPTED;
			pstF6InterfaceFlags->bFullDuplex          = cmd.CmdType.PortCmd.EnDis-1;
		}
	}
	else
	{
		pstF6InterfaceFlags->wNegotiationStatus = F6_ATTR2_AUTO_NEG_NOT_ATTEMPTED;
		pstF6InterfaceFlags->bFullDuplex = 0;

	}
#else
	cmd.opcode =CPSW3G_IOCTL_GET_PORT_CONFIG;
	cmd.PortCmd.port = wInstance-1;
	NIMUIoctl(CPSW3G_IOCTL_SWITCH_CMD,&device,&cmd,sizeof(cmd));
	pstF6InterfaceFlags->bLinkStatus          = cmd.PortCmd.linkStat;

	if(pstF6InterfaceFlags->bLinkStatus)
	{
		if (gstEthControl[wInstance-1].bAutoNegotiate)
		{
			pstF6InterfaceFlags->wNegotiationStatus   = F6_ATTR2_AUTO_NEG_SUCCESS;
			pstF6InterfaceFlags->bFullDuplex          = cmd.PortCmd.EnDis-1;
		}
		else
		{
			pstF6InterfaceFlags->wNegotiationStatus   = F6_ATTR2_AUTO_NEG_NOT_ATTEMPTED;
			pstF6InterfaceFlags->bFullDuplex          = cmd.PortCmd.EnDis-1;
		}
	}
	else
	{
		pstF6InterfaceFlags->wNegotiationStatus = F6_ATTR2_AUTO_NEG_NOT_ATTEMPTED;
		pstF6InterfaceFlags->bFullDuplex = 0;
	}
#endif

	pstF6InterfaceFlags->bLocalHardwareFault  = EIP_FALSE;
  
	return EIP_TRUE;
}


/**
 *  \name HAL_GetInterfaceCounters
 *  \brief Function to get the Port statistics
 *  \param wInstance Ethernet instance
 *  \param pIfCnt structure where statistics will be returned
 *  \param bClear specifies whether to clear statistics or not
 *  \return EIP_TRUE on Success,EIP_FALSE on failure
 *
 */
EIP_BOOL HAL_GetInterfaceCounters(EIP_WORD wInstance, CLASS_ETH_LINK_INTERFACE_COUNTERS * pIfCnt, EIP_BOOL bClear)
{
	static EIP_DWORD dwValue;
    NIMU_IF_REQ nimudevice;
    nimudevice.index = 1;
    nimudevice.name[0] = 0;

#ifdef USE_CPSW_DRIVER
    CpswStatsCmd statStr;
	statStr.opcode = CPSW3G_IOCTL_STAT_GET;

	NIMUIoctl(CPSW3G_IOCTL_STAT_CMD,&nimudevice,&statStr,sizeof(statStr));


	if (bClear)
	{
		dwValue = 0;
		statStr.opcode = CPSW3G_IOCTL_STAT_CLEAR;
		NIMUIoctl(CPSW3G_IOCTL_STAT_CMD,&nimudevice,&statStr,sizeof(statStr));
	}
	else
		dwValue++;

#else

	StatsCmd statStr;
	statStr.opcode = ICSS_IOCTL_STAT_GET;

	statStr.portNum = wInstance;

	NIMUIoctl(ICSS_IOCTL_STAT_CMD,&nimudevice,&statStr,sizeof(statStr));

	pIfCnt->In_Octets           = statStr.statsObj.rxNetOctets;
	pIfCnt->In_Ucast_Packets    = statStr.statsObj.rxUcast;
	pIfCnt->In_NUcast_Packets   = statStr.statsObj.rxBcast+ statStr.statsObj.rxMcast;
	//pIfCnt->In_Discards         = statStr.statsObj.droppedBCPackets+ statStr.statsObj.droppedMCPackets;
	pIfCnt->In_Errors           = 0; /*TODO Update accordingly *///statStr.statsObj.rxCRCFrames;
	pIfCnt->In_Unknown_Protos   = statStr.statsObj.rxUnknownProtocol;
	pIfCnt->Out_Octets          = statStr.statsObj.txNetOctets;
	pIfCnt->Out_Ucast_Packets   = statStr.statsObj.txUcast;
	pIfCnt->Out_NUcast_Packets  = statStr.statsObj.txBcast+ statStr.statsObj.txMcast;
	pIfCnt->Out_Discards        = 0;
	pIfCnt->Out_Errors          = 0;
	if (bClear)
	{
		dwValue = 0;
		statStr.opcode = ICSS_IOCTL_STAT_CLEAR;
		NIMUIoctl(ICSS_IOCTL_STAT_CMD,&nimudevice,&statStr,sizeof(statStr));
	}
	else
		dwValue++;
#endif

	return EIP_TRUE;
}


/**
 *  \name HAL_GetMediaCounters
 *  \brief Function to get the Media Counters
 *  \param wInstance Ethernet instance
 *  \param pMediaCnt structure where data will be returned
 *  \param bClear specifies whether to clear statistics or not
 *  \return EIP_TRUE on Success
 *
 */
EIP_BOOL HAL_GetMediaCounters(EIP_WORD wInstance, CLASS_ETH_MEDIA_COUNTERS * pMediaCnt, EIP_BOOL bClear)
{
	static EIP_DWORD dwValue;
	pMediaCnt->Alignment_Errors       = dwValue;
	pMediaCnt->FCS_Errors             = dwValue;
	pMediaCnt->Single_Collisions      = dwValue;
	pMediaCnt->Multiple_Collisions    = dwValue;
	pMediaCnt->SQE_Test_Errors        = dwValue;
	pMediaCnt->Deferred_Transmissions = dwValue;
	pMediaCnt->Late_Collisions        = dwValue;
	pMediaCnt->Excessive_Collisions   = dwValue;
	pMediaCnt->MAC_Transmit_Errors    = dwValue;
	pMediaCnt->Carrier_Sense_Errors   = dwValue;
	pMediaCnt->Frame_Too_Long         = dwValue;
	pMediaCnt->MAC_Receive_Errors     = dwValue;

	if (bClear)
		dwValue = 0;
	return EIP_TRUE;
}

/**
 *  \name HAL_GetPhysicalAddress
 *  \brief Function to get the Mac address of the device
 *  \param wInstance Ethernet instance
 *  \param pMacAddress Mac Address
 *  \return EIP_TRUE on Success
 *
 */
EIP_BOOL HAL_GetPhysicalAddress(EIP_WORD wInstance, EIP_BYTE * pMacAddress)
{
    NIMU_IF_REQ device;
    device.index = 1;
    device.name[0] = 0;

    NIMUIoctl(NIMU_GET_DEVICE_MAC,&device,(Uint8*)pMacAddress, 6);

	return EIP_TRUE;
}

/**
 *  \name HAL_GetInterfaceControl
 *  \brief The function returns the Interface configuration attribute of TCP/IP object
 *  \param wInstance Ethernet instance
 *  \param pstEthControl Structure pointer to get the details
 *  \return EIP_TRUE on Success
 *
 */
EIP_BOOL HAL_GetInterfaceControl(EIP_WORD wInstance, ST_ETH_CONTROL * pstEthControl)
{
    NIMU_IF_REQ device;
    device.index = 1;
    device.name[0] = 0;

#ifdef USE_CPSW_DRIVER

	SwitchConsCmd cmd;
	cmd.opcode =CPSW3G_IOCTL_GET_PORT_CONFIG;
	cmd.PortCmd.port = wInstance-1;
	NIMUIoctl(CPSW3G_IOCTL_SWITCH_CMD,&device,&cmd,sizeof(cmd));
	if(cmd.PortCmd.linkStat)
	{
		if(gstEthControl[wInstance-1].bAutoNegotiate)
		{
			gstEthControl[wInstance-1].wForceInterfaceSpeed =0;
		}
		else
		{

			gstEthControl[wInstance-1].wForceInterfaceSpeed = cmd.PortCmd.value/1000000;
		}
	}
#else

	if(GetLinkStatus(wInstance))
	{
		if(gstEthControl[wInstance-1].bAutoNegotiate)
		{
			gstEthControl[wInstance-1].wForceInterfaceSpeed =0;
		}
		else
		{
			SwitchConsCmd cmd;
			cmd.opcode =ICSS_IOCTL_GET_PORT_CONFIG;
			cmd.CmdType.PortCmd.port = wInstance;
			NIMUIoctl(ICSS_IOCTL_SWITCH_CMD,&device,&cmd,sizeof(cmd));
			gstEthControl[wInstance-1].wForceInterfaceSpeed = cmd.CmdType.PortCmd.value/1000000;
		}
	}

#endif
	*pstEthControl = gstEthControl[wInstance-1];
	return EIP_TRUE;
}


/**
 *  \name HAL_SetInterfaceControl
 *  \brief The function sets the Interface configuration attribute of TCP/IP object
 *  \param wInstance Ethernet instance
 *  \param pstEthControl Structure pointer to get the attribute details
 *  \return EIP_TRUE on Success
 *
 */
EIP_BOOL HAL_SetInterfaceControl(EIP_WORD wInstance, ST_ETH_CONTROL * pstEthControl)
{

	WritePermanentMemory((EIP_BYTE*)pstEthControl,sizeof(ST_ETH_CONTROL),SPI_EEPROM_SPEED_OFFSET);

	gstEthControl[0] = *pstEthControl;
	gstEthControl[1] = *pstEthControl;

	return EIP_TRUE;
}


EIP_BOOL HAL_GetInterfaceStarupType()
{

	if(eipDevInitConfig.tcpipConfig.startupType == EIP_STARTUP_DHCP)
		return EIP_TRUE;
	else
		return EIP_FALSE;
}

EIP_VOID HAL_SetLastConflictDetails(CLASS_TCP_LAST_CONFLICT_DETECTED* lastconflictdetails)
{
	WritePermanentMemory((EIP_BYTE*)lastconflictdetails,sizeof(CLASS_TCP_LAST_CONFLICT_DETECTED),SPI_EEPROM_ACD_CONFLICT_OFFSET);
	eipDevInitConfig.acdConflictDetails = * lastconflictdetails; // CHECK whether this is required.
}


EIP_VOID HAL_GetLastConflictDetails(CLASS_TCP_LAST_CONFLICT_DETECTED* lastconflictdetails)
{
	* lastconflictdetails = eipDevInitConfig.acdConflictDetails;
}


EIP_VOID GetInterfaceConfigACDStatus(DWORD * acdStatus)
{
	*acdStatus |= ifConnfigACDStat;
}


EIP_VOID HAL_GetACDEnable(EIP_WORD * acdEnable)
{
	* acdEnable = eipDevInitConfig.acdEnable;
}

EIP_VOID HAL_SetACDEnable(EIP_WORD * acdEnable)
{
	WritePermanentMemory((EIP_BYTE*)acdEnable,sizeof(EIP_WORD),SPI_EEPROM_ACD_OFFSET);
}

EIP_BOOL HAL_SetQoSValues(CLASS_QOS* lpQosObj)
{
	WritePermanentMemory((EIP_BYTE*)lpQosObj,sizeof(CLASS_QOS),SPI_EEPROM_QOS_OFFSET);
	return EIP_TRUE;
}

EIP_BOOL HAL_GetQoSValues(CLASS_QOS * lpQosObj)
{
	ReadPermanentMemory((EIP_BYTE*)lpQosObj,sizeof(CLASS_QOS),SPI_EEPROM_QOS_OFFSET);
	return EIP_TRUE;
}


/**
 *  \name SetInterfaceSpeed
 *  \brief The function calls ndk driver ioctl to force the Interface properties
 *  \param pstEthControl structure having the Interface properties
 *  \return none
 *
 */
EIP_VOID SetInterfaceSpeed(ST_ETH_CONTROL * pstEthControl)
{
	NIMU_IF_REQ nimudevice;
	nimudevice.index = 1;
	nimudevice.name[0] = 0;
	SwitchConsCmd cmd;

#ifdef USE_CPSW_DRIVER
	cmd.opcode =CPSW3G_IOCTL_SET_PORT_CONFIG;
	cmd.PortCmd.port = 0;
	if(0 == pstEthControl->bAutoNegotiate)
	{
		if(pstEthControl->wForceInterfaceSpeed == 10 ||pstEthControl->wForceInterfaceSpeed == 100)
			cmd.PortCmd.value = pstEthControl->wForceInterfaceSpeed;
		else
			cmd.PortCmd.value = 100;

		cmd.PortCmd.EnDis =pstEthControl->bForceFullDuplex;
	}
	else
	{
		// Making Sure that values are in correct format
		pstEthControl->bAutoNegotiate =1;
		pstEthControl->bForceFullDuplex =0;
		pstEthControl->wForceInterfaceSpeed = 0;
		cmd.PortCmd.EnDis = 0;
	}
	NIMUIoctl(CPSW3G_IOCTL_SWITCH_CMD,&nimudevice,&cmd,sizeof(cmd));

	if(board_Type != AM335X_BOARD_TYPE_IDK)/*Only one port for IDK*/
	{
		cmd.PortCmd.port = 1;
		NIMUIoctl(CPSW3G_IOCTL_SWITCH_CMD,&nimudevice,&cmd,sizeof(cmd));
	}
#else
	cmd.opcode =ICSS_IOCTL_SET_PORT_CONFIG;
	if(0 == pstEthControl->bAutoNegotiate)
	{
		if(pstEthControl->wForceInterfaceSpeed == 10 ||pstEthControl->wForceInterfaceSpeed == 100)
			cmd.CmdType.PortCmd.value = pstEthControl->wForceInterfaceSpeed;
		else
			cmd.CmdType.PortCmd.value = 100;
		cmd.CmdType.PortCmd.EnDis =pstEthControl->bForceFullDuplex;
	}
	else
	{
		// Making Sure that values are in correct format
		pstEthControl->bAutoNegotiate =1;
		pstEthControl->bForceFullDuplex =0;
		pstEthControl->wForceInterfaceSpeed = 0;
		cmd.CmdType.PortCmd.value = 0;
		cmd.CmdType.PortCmd.EnDis =0;
	}
	cmd.CmdType.PortCmd.port = 0;
	NIMUIoctl(ICSS_IOCTL_SWITCH_CMD,&nimudevice,&cmd,sizeof(cmd));
	cmd.CmdType.PortCmd.port = 1;
	NIMUIoctl(ICSS_IOCTL_SWITCH_CMD,&nimudevice,&cmd,sizeof(cmd));
#endif
}


EIP_BOOL SetEthernetLinkConfig()
{
//	ReadPermanentMemory((EIP_BYTE*)&gstEthControl[0],sizeof(ST_ETH_CONTROL),SPI_EEPROM_SPEED_OFFSET);
//	ReadPermanentMemory((EIP_BYTE*)&gstEthControl[1],sizeof(ST_ETH_CONTROL),SPI_EEPROM_SPEED_OFFSET);
//	EN
	gstEthControl[0].bAutoNegotiate = 1;
	gstEthControl[0].bForceFullDuplex = 0;
	gstEthControl[0].wForceInterfaceSpeed = 0;

	gstEthControl[1].bAutoNegotiate = 1;
	gstEthControl[1].bForceFullDuplex = 0;
	gstEthControl[1].wForceInterfaceSpeed = 0;


	SetInterfaceSpeed(&gstEthControl[0]);
	return EIP_TRUE;
}

EIP_BOOL SetTCPIPInitConfig()
{
	GetTCPIPConfigDetails(&eipDevTcpIpConfiguration);
	gstTcpIpControl.wStartupConfiguration = eipDevInitConfig.tcpipConfig.startupType;
	gstTcpIpConfiguration = eipDevTcpIpConfiguration;
	return EIP_TRUE;
}
