/*****************************************************************************
 *
 *  @brief This function initializes the FW application
 *         code at level 1.
 *
 *  @param pAC      Pointer to adapter context
 *  @param IoC      IO context handle 
 *  @return         SK_TRUE or SK_FALSE
 */
int FwAppInit1(SK_AC *pAC, SK_IOC IoC)
{
	int RetCode = SK_ASF_PNMI_ERR_OK;

	SK_DBG_MSG(pAC, SK_DBGMOD_ASF, SK_DBGCAT_INIT,
		("%s: FwAppInit1 ==>\n", SK_DRV_NAME));

	/* Check chip ID and set appropriate flash offsets, */
	/* operational modes and chip modes depending on Chip ID. */
	switch (pAC->FwCommon.ChipID) {
	case CHIP_ID_YUKON_SUPR:
		pAC->FwApp.ChipMode        = SK_GEASF_CHIP_SU;
		pAC->FwApp.FlashSize       = ASF_FLASH_SU_SIZE;

		SK_STRNCPY(pAC->FwApp.DriverVersion, FW_API_VERSION, FW_API_VERSION_SIZE);

		SK_DBG_MSG(pAC, SK_DBGMOD_ASF, SK_DBGCAT_INIT,
			("%s: FwAppInit1: pAC->FwApp.DriverVersion: %s!\n",
			SK_DRV_NAME, pAC->FwApp.DriverVersion));

		break;

	default:
		/* Chip ID does not match! */
		pAC->FwApp.InitState = ASF_INIT_ERROR_CHIP_ID;
		printk("%s: FwAppInit1: Chip ID does not match!\n", SK_DRV_NAME);

		RetCode = SK_ASF_PNMI_ERR_GENERAL;
		break;
	}

	if (RetCode != SK_ASF_PNMI_ERR_OK) {
		pAC->FwApp.InitState = ASF_INIT_ERROR_CHIP_ID;

		SK_DBG_MSG(pAC, SK_DBGMOD_ASF, SK_DBGCAT_INIT,
			("%s: FwAppInit1 <==\n", SK_DRV_NAME));

		return RetCode;
	}

	SetRamAddr(pAC, SK_ST_FIFOTYPE, HOST_READ_QWORD, SK_ST_BUFADDR_HIGH);
	pAC->FwApp.OpMode = SK_GEASF_MODE_EMBEDDED_SDK;

	SK_DBG_MSG(pAC, SK_DBGMOD_ASF, SK_DBGCAT_INIT,
		("%s: FwAppInit1 <==\n", SK_DRV_NAME));

	return RetCode;

} /* FwAppInit1 */
/*****************************************************************************
*
* FwMainStateMachine - general ASF  timer
*
* Description:
*
* Returns:
*   Always 0
*/
void FwMainStateMachine(
SK_AC  *pAC,	/* Pointer to adapter context */
SK_IOC IoC)		/* IO context handle */
{
	SK_EVPARA EventParam;

	SK_DBG_MSG(pAC, SK_DBGMOD_ASF, SK_DBGCAT_INIT,
		("%s: FwMainStateMachine() called!\n", SK_DRV_NAME));

	if (pAC->FwApp.GlHciState == 0) { /* idle */

		SK_MEMSET((char *)&EventParam, 0, sizeof(EventParam));
		SkTimerStart(pAC, IoC, &pAC->FwApp.AsfTimer,
					1000000, SKGE_ASF, SK_ASF_EVT_TIMER_EXPIRED,
					EventParam);
	}
	else {
		SK_MEMSET((char *)&EventParam, 0, sizeof(EventParam));
		SkTimerStart(pAC, IoC, &pAC->FwApp.AsfTimer,
					30000, SKGE_ASF, SK_ASF_EVT_TIMER_EXPIRED,
					EventParam);
	}

	return;

} /* FwMainStateMachine */
/*****************************************************************************
 *
 *  @brief This function returns the full pathname
 *         of the FW image file.
 *
 *  @param pAC      Pointer to adapter context
 *  @return         Pointer to full FW file pathname
 */
char *FwAppGetImageName(SK_AC *pAC)
{
	SK_DBG_MSG(pAC, SK_DBGMOD_ASF, SK_DBGCAT_INIT,
		("%s: FwAppGetImageName: pAC->FwOs.pFilePathName: %s\n",
		SK_DRV_NAME, pAC->FwOs.pFilePathName));

	return pAC->FwOs.pFilePathName;

} /* FwAppGetImageName */
/*****************************************************************************
 *
 *  @brief This function initializes the FW application
 *         code at level 2.
 *
 *  @param pAC      Pointer to adapter context
 *  @param IoC      IO context handle 
 *  @return         SK_TRUE or SK_FALSE
 */
int FwAppInit2(SK_AC *pAC, SK_IOC IoC)
{
	int RetCode = SK_ASF_PNMI_ERR_OK;

	SK_DBG_MSG(pAC, SK_DBGMOD_ASF, SK_DBGCAT_INIT,
		("%s: FwAppInit2 ==>\n", SK_DRV_NAME));

	/* FW initialization ok */
	pAC->FwApp.InitState = ASF_INIT_OK;

	/* Check if CPU is running */
	if (FwCpuState(pAC, IoC) != ASF_CPU_STATE_RUNNING) {
		SK_DBG_PRINTF("%s: FwAppInit2: CPU is NOT running! Start CPU!\n", SK_DRV_NAME);

		/* If not, start CPU */
		FwStartCpu(pAC, IoC);
		pAC->FwApp.CpuAlive = 1;
	}

	SK_DBG_MSG(pAC, SK_DBGMOD_ASF, SK_DBGCAT_INIT,
		("%s: FwAppInit2: INIT OK pAC->FwApp.InitState: %d pAC->FwApp.OpMode: %d\n",
		SK_DRV_NAME, pAC->FwApp.InitState, pAC->FwApp.OpMode));

	/* Otherwise the transmitter and the receiver will be */
	/* deactivated if we shut down the network interface. */
	FwAsfEnable(pAC, IoC);

	SK_DBG_PRINTF("%s: Checking Driver <-> FW communication ...", DRV_NAME);
	if (FwHciSendCommand(pAC, IoC, YASF_HOSTCMD_CHECK_ALIVE, 0, 0, 0, ASF_HCI_WAIT, 0) != HCI_EN_CMD_READY) {
		SK_DBG_PRINTF(" FAILED!\n");
		pAC->FwState = SK_FALSE;
	} else {
		SK_DBG_PRINTF(" working!\n");
		pAC->FwState = SK_TRUE;
	}

	SK_DBG_MSG(pAC, SK_DBGMOD_ASF, SK_DBGCAT_INIT,("%s: FwAppInit2 <==\n", SK_DRV_NAME));

	return RetCode;

} /* FwAppInit2 */
/*****************************************************************************
 *
 *  @brief This function initializes the FW application
 *         code at level 0.
 *
 *  @param pAC      Pointer to adapter context
 *  @param IoC      IO context handle 
 *  @return         SK_TRUE or SK_FALSE
 */
int FwAppInit0(SK_AC *pAC, SK_IOC IoC)
{
	int RetCode = SK_ASF_PNMI_ERR_OK;

	SK_DBG_MSG(pAC, SK_DBGMOD_ASF, SK_DBGCAT_INIT,
		("%s: FwAppInit0 ==>\n", SK_DRV_NAME));

	/* Set structure to zero */
	SK_MEMSET((char *)&(pAC->FwApp), 0, sizeof(SK_FWAPP));

	pAC->FwApp.ActivePort   = 0;
	pAC->FwApp.DualMode     = SK_GEASF_Y2_SINGLEPORT;
	pAC->FwApp.OpMode       = SK_GEASF_MODE_UNKNOWN;
	pAC->FwApp.ChipMode     = SK_GEASF_CHIP_UNKNOWN;
	pAC->FwApp.InitState    = ASF_INIT_UNDEFINED;
	pAC->RamAddr = 0;
	pAC->RamSelect = 0;

	SK_DBG_MSG(pAC, SK_DBGMOD_ASF, SK_DBGCAT_INIT,
		("%s: FwAppInit0 <==\n", SK_DRV_NAME));

	return RetCode;

} /* FwAppInit0 */
/*****************************************************************************
 *
 *  @brief This function prepares the patches for the FW image.
 *
 *  @param pAC      Pointer to adapter context
 *  @param IoC      IO context handle 
 *  @return         SK_TRUE or SK_FALSE
 */
int FwAppPatchImage(SK_AC *pAC, SK_IOC IoC)
{
	int RetCode;

	/* Nothing to patch... */
	pAC->FwCommon.PatchNumber = 0;

	SK_DBG_MSG(pAC, SK_DBGMOD_ASF, SK_DBGCAT_INIT,
		("%s: FwAppPatchImage: pAC->FwCommon.PatchNumber: %d\n",
		SK_DRV_NAME, pAC->FwCommon.PatchNumber));

	RetCode = SK_TRUE;
	return RetCode;

} /* FwAppPatchImage */
/*****************************************************************************
 *
 *  @brief This function compares the required FW version
 *         with the version found in the FW image file.
 *
 *  @param pAC      Pointer to adapter context
 *  @return         SK_TRUE or SK_FALSE
 */
SK_BOOL FwAppIsVersionOk(SK_AC *pAC)
{
	SK_BOOL RetCode = SK_TRUE;
	int     i;

	/*
	 * Compare file firmware version with
	 * required firmware version.
	 */
	for (i = 0; i < FW_API_VERSION_SIZE; i++) {
		if (pAC->FwApp.DriverVersion[i] != pAC->FwCommon.FileVersion[i]) {
			RetCode = SK_FALSE;
		}
	}

	SK_DBG_MSG(pAC, SK_DBGMOD_ASF, SK_DBGCAT_INIT,
		("%s: FwAppIsVersionOk: RetCode: %d\n", SK_DRV_NAME, RetCode));

	return RetCode;

} /* FwAppIsVersionOk */
示例#8
0
文件: skcsum.c 项目: hugh712/Jollen
/******************************************************************************
 *
 *	SkCsGetReceiveInfo - verify checksum information for a received packet
 *
 * Description:
 *	Verify a received frame's checksum. The function returns a status code
 *	reflecting the result of the verification.
 *
 * Note:
 *	Before calling this function you have to verify that the frame is
 *	not padded and Checksum1 and Checksum2 are bigger than 1.
 *
 * Arguments:
 *	pAc - Pointer to adapter context struct.
 *
 *	pIpHeader - Pointer to IP header. Must be at least the length in bytes
 *	of the received IP header including any option fields. For UDP packets,
 *	8 additional bytes are needed to access the UDP checksum.
 *
 *	Note: The actual length of the IP header is stored in the lower four
 *	bits of the first octet of the IP header as the number of 4-byte words,
 *	so it must be multiplied by four to get the length in bytes. Thus, the
 *	maximum IP header length is 15 * 4 = 60 bytes.
 *
 *	Checksum1 - The first 16-bit Internet Checksum calculated by the
 *	hardware starting at the offset returned by SkCsSetReceiveFlags().
 *
 *	Checksum2 - The second 16-bit Internet Checksum calculated by the
 *	hardware starting at the offset returned by SkCsSetReceiveFlags().
 *
 * Returns:
 *	SKCS_STATUS_UNKNOWN_IP_VERSION - Not an IP v4 frame.
 *	SKCS_STATUS_IP_CSUM_ERROR - IP checksum error.
 *	SKCS_STATUS_IP_CSUM_ERROR_TCP - IP checksum error in TCP frame.
 *	SKCS_STATUS_IP_CSUM_ERROR_UDP - IP checksum error in UDP frame
 *	SKCS_STATUS_IP_FRAGMENT - IP fragment (IP checksum ok).
 *	SKCS_STATUS_IP_CSUM_OK - IP checksum ok (not a TCP or UDP frame).
 *	SKCS_STATUS_TCP_CSUM_ERROR - TCP checksum error (IP checksum ok).
 *	SKCS_STATUS_UDP_CSUM_ERROR - UDP checksum error (IP checksum ok).
 *	SKCS_STATUS_TCP_CSUM_OK - IP and TCP checksum ok.
 *	SKCS_STATUS_UDP_CSUM_OK - IP and UDP checksum ok.
 *	SKCS_STATUS_IP_CSUM_OK_NO_UDP - IP checksum OK and no UDP checksum.
 *
 *	Note: If SKCS_OVERWRITE_STATUS is defined, the SKCS_STATUS_XXX values
 *	returned here can be defined in some header file by the module using CSUM.
 *	In this way, the calling module can assign return values for its own needs,
 *	e.g. by assigning bit flags to the individual protocols.
 */
SKCS_STATUS SkCsGetReceiveInfo(
SK_AC		*pAc,		/* Adapter context struct. */
void		*pIpHeader,	/* IP header. */
unsigned	Checksum1,	/* Hardware checksum 1. */
unsigned	Checksum2,	/* Hardware checksum 2. */
int			NetNumber)	/* Net number */
{
	/* Internet Header Version found in IP header. */
	unsigned InternetHeaderVersion;

	/* Length of the IP header as found in IP header. */
	unsigned IpHeaderLength;

	/* Length of IP data portion. */
	unsigned IpDataLength;

	/* IP header checksum. */
	unsigned IpHeaderChecksum;

	/* IP header options checksum, if any. */
	unsigned IpOptionsChecksum;

	/* IP data checksum, i.e. TCP/UDP checksum. */
	unsigned IpDataChecksum;

	/* Next level protocol identifier found in IP header. */
	unsigned NextLevelProtocol;

	/* The checksum of the "next level protocol", i.e. TCP or UDP. */
	unsigned long NextLevelProtocolChecksum;

	/* Pointer to next level protocol statistics structure. */
	SKCS_PROTO_STATS *NextLevelProtoStats;

	/* Temporary variable. */
	unsigned Tmp;

	Tmp = *(SK_U8 *)
		SKCS_IDX(pIpHeader, SKCS_OFS_IP_HEADER_VERSION_AND_LENGTH);

	/* Get the Internet Header Version (IHV). */
	/* Note: The IHV is stored in the upper four bits. */

	InternetHeaderVersion = Tmp >> 4;

	/* Check the Internet Header Version. */
	/* Note: We currently only support IP version 4. */

	if (InternetHeaderVersion != 4) {	/* IPv4? */
		SK_DBG_MSG(pAc, SK_DBGMOD_CSUM, SK_DBGCAT_ERR | SK_DBGCAT_RX,
			("Rx: Unknown Internet Header Version %u.\n",
			InternetHeaderVersion));
		pAc->Csum.ProtoStats[NetNumber][SKCS_PROTO_STATS_IP].RxUnableCts++;
		return (SKCS_STATUS_UNKNOWN_IP_VERSION);
	}

	/* Get the IP header length (IHL). */
	/*
	 * Note: The IHL is stored in the lower four bits as the number of
	 * 4-byte words.
	 */

	IpHeaderLength = (Tmp & 0xf) * 4;

	/* Check the IP header length. */

	/* 04-Aug-1998 sw - Really check the IHL? Necessary? */

	if (IpHeaderLength < 5*4) {
		SK_DBG_MSG(pAc, SK_DBGMOD_CSUM, SK_DBGCAT_ERR | SK_DBGCAT_RX,
			("Rx: Invalid IP Header Length %u.\n", IpHeaderLength));
		pAc->Csum.ProtoStats[NetNumber][SKCS_PROTO_STATS_IP].RxErrCts++;
		return (SKCS_STATUS_IP_CSUM_ERROR);
	}

	/* This is an IPv4 frame with a header of valid length. */

	/* Get the IP header and data checksum. */

	IpDataChecksum = Checksum2;

	/*
	 * The IP header checksum is calculated as follows:
	 *
	 *	IpHeaderChecksum = Checksum1 - Checksum2
	 */

	SKCS_OC_SUB(IpHeaderChecksum, Checksum1, Checksum2);

	/* Check if any IP header options. */

	if (IpHeaderLength > SKCS_IP_HEADER_SIZE) {

		/* Get the IP options checksum. */

		IpOptionsChecksum = SkCsCalculateChecksum(
			SKCS_IDX(pIpHeader, SKCS_IP_HEADER_SIZE),
			IpHeaderLength - SKCS_IP_HEADER_SIZE);

		/* Adjust the IP header and IP data checksums. */

		SKCS_OC_ADD(IpHeaderChecksum, IpHeaderChecksum, IpOptionsChecksum);

		SKCS_OC_SUB(IpDataChecksum, IpDataChecksum, IpOptionsChecksum);
	}

	/*
	 * Check if the IP header checksum is ok.
	 *
	 * NOTE: We must check the IP header checksum even if the caller just wants
	 * us to check upper-layer checksums, because we cannot do any further
	 * processing of the packet without a valid IP checksum.
	 */
	
	/* Get the next level protocol identifier. */
	
	NextLevelProtocol = *(SK_U8 *)
		SKCS_IDX(pIpHeader, SKCS_OFS_IP_NEXT_LEVEL_PROTOCOL);

	if (IpHeaderChecksum != 0xFFFF) {
		pAc->Csum.ProtoStats[NetNumber][SKCS_PROTO_STATS_IP].RxErrCts++;
		/* the NDIS tester wants to know the upper level protocol too */
		if (NextLevelProtocol == SKCS_PROTO_ID_TCP) {
			return(SKCS_STATUS_IP_CSUM_ERROR_TCP);
		}
		else if (NextLevelProtocol == SKCS_PROTO_ID_UDP) {
			return(SKCS_STATUS_IP_CSUM_ERROR_UDP);
		}
		return (SKCS_STATUS_IP_CSUM_ERROR);
	}

	/*
	 * Check if this is a TCP or UDP frame and if we should calculate the
	 * TCP/UDP pseudo header checksum.
	 *
	 * Also clear all protocol bit flags of protocols not present in the
	 * frame.
	 */

	if ((pAc->Csum.ReceiveFlags[NetNumber] & SKCS_PROTO_TCP) != 0 &&
		NextLevelProtocol == SKCS_PROTO_ID_TCP) {
		/* TCP/IP frame. */
		NextLevelProtoStats =
			&pAc->Csum.ProtoStats[NetNumber][SKCS_PROTO_STATS_TCP];
	}
	else if ((pAc->Csum.ReceiveFlags[NetNumber] & SKCS_PROTO_UDP) != 0 &&
		NextLevelProtocol == SKCS_PROTO_ID_UDP) {
		/* UDP/IP frame. */
		NextLevelProtoStats =
			&pAc->Csum.ProtoStats[NetNumber][SKCS_PROTO_STATS_UDP];
	}
	else {
		/*
		 * Either not a TCP or UDP frame and/or TCP/UDP processing not
		 * specified.
		 */
		return (SKCS_STATUS_IP_CSUM_OK);
	}

	/* Check if this is an IP fragment. */

	/*
	 * Note: An IP fragment has a non-zero "Fragment Offset" field and/or
	 * the "More Fragments" bit set. Thus, if both the "Fragment Offset"
	 * and the "More Fragments" are zero, it is *not* a fragment. We can
	 * easily check both at the same time since they are in the same 16-bit
	 * word.
	 */

	if ((*(SK_U16 *)
		SKCS_IDX(pIpHeader, SKCS_OFS_IP_FLAGS_AND_FRAGMENT_OFFSET) &
		~SKCS_IP_DONT_FRAGMENT) != 0) {
		/* IP fragment; ignore all other protocols. */
		NextLevelProtoStats->RxUnableCts++;
		return (SKCS_STATUS_IP_FRAGMENT);
	}

	/*
	 * 08-May-2000 ra
	 *
	 * From RFC 768 (UDP)
	 * If the computed checksum is zero, it is transmitted as all ones (the
	 * equivalent in one's complement arithmetic).  An all zero transmitted
	 * checksum value means that the transmitter generated no checksum (for
	 * debugging or for higher level protocols that don't care).
	 */

	if (NextLevelProtocol == SKCS_PROTO_ID_UDP &&
		*(SK_U16*)SKCS_IDX(pIpHeader, IpHeaderLength + 6) == 0x0000) {

		NextLevelProtoStats->RxOkCts++;
		
		return (SKCS_STATUS_IP_CSUM_OK_NO_UDP);
	}

	/*
	 * Calculate the TCP/UDP checksum.
	 */

	/* Get total length of IP header and data. */

	IpDataLength =
		*(SK_U16 *) SKCS_IDX(pIpHeader, SKCS_OFS_IP_TOTAL_LENGTH);

	/* Get length of IP data portion. */

	IpDataLength = SKCS_NTOH16(IpDataLength) - IpHeaderLength;

	NextLevelProtocolChecksum =

		/* Calculate the pseudo header checksum. */

		(unsigned long) *(SK_U16 *) SKCS_IDX(pIpHeader,
			SKCS_OFS_IP_SOURCE_ADDRESS + 0) +
		(unsigned long) *(SK_U16 *) SKCS_IDX(pIpHeader,
			SKCS_OFS_IP_SOURCE_ADDRESS + 2) +
		(unsigned long) *(SK_U16 *) SKCS_IDX(pIpHeader,
			SKCS_OFS_IP_DESTINATION_ADDRESS + 0) +
		(unsigned long) *(SK_U16 *) SKCS_IDX(pIpHeader,
			SKCS_OFS_IP_DESTINATION_ADDRESS + 2) +
		(unsigned long) SKCS_HTON16(NextLevelProtocol) +
		(unsigned long) SKCS_HTON16(IpDataLength) +

		/* Add the TCP/UDP header checksum. */

		(unsigned long) IpDataChecksum;

	/* Add-in any carries. */

	SKCS_OC_ADD(NextLevelProtocolChecksum, NextLevelProtocolChecksum, 0);

	/* Add-in any new carry. */

	SKCS_OC_ADD(NextLevelProtocolChecksum, NextLevelProtocolChecksum, 0);

	/* Check if the TCP/UDP checksum is ok. */

	if ((unsigned) NextLevelProtocolChecksum == 0xFFFF) {

		/* TCP/UDP checksum ok. */

		NextLevelProtoStats->RxOkCts++;

		return (NextLevelProtocol == SKCS_PROTO_ID_TCP ?
			SKCS_STATUS_TCP_CSUM_OK : SKCS_STATUS_UDP_CSUM_OK);
	}
	
	/* TCP/UDP checksum error. */

	NextLevelProtoStats->RxErrCts++;

	return (NextLevelProtocol == SKCS_PROTO_ID_TCP ?
		SKCS_STATUS_TCP_CSUM_ERROR : SKCS_STATUS_UDP_CSUM_ERROR);
}	/* SkCsGetReceiveInfo */
示例#9
0
文件: skcsum.c 项目: hugh712/Jollen
/******************************************************************************
 *
 *	SkCsGetSendInfo - get checksum information for a send packet
 *
 * Description:
 *	Get all checksum information necessary to send a TCP or UDP packet. The
 *	function checks the IP header passed to it. If the high-level protocol
 *	is either TCP or UDP the pseudo header checksum is calculated and
 *	returned.
 *
 *	The function returns the total length of the IP header (including any
 *	IP option fields), which is the same as the start offset of the IP data
 *	which in turn is the start offset of the TCP or UDP header.
 *
 *	The function also returns the TCP or UDP pseudo header checksum, which
 *	should be used as the start value for the hardware checksum calculation.
 *	(Note that any actual pseudo header checksum can never calculate to
 *	zero.)
 *
 * Note:
 *	There is a bug in the ASIC whic may lead to wrong checksums.
 *
 * Arguments:
 *	pAc - A pointer to the adapter context struct.
 *
 *	pIpHeader - Pointer to IP header. Must be at least the IP header *not*
 *	including any option fields, i.e. at least 20 bytes.
 *
 *	Note: This pointer will be used to address 8-, 16-, and 32-bit
 *	variables with the respective alignment offsets relative to the pointer.
 *	Thus, the pointer should point to a 32-bit aligned address. If the
 *	target system cannot address 32-bit variables on non 32-bit aligned
 *	addresses, then the pointer *must* point to a 32-bit aligned address.
 *
 *	pPacketInfo - A pointer to the packet information structure for this
 *	packet. Before calling this SkCsGetSendInfo(), the following field must
 *	be initialized:
 *
 *		ProtocolFlags - Initialize with any combination of
 *		SKCS_PROTO_XXX bit flags. SkCsGetSendInfo() will only work on
 *		the protocols specified here. Any protocol(s) not specified
 *		here will be ignored.
 *
 *		Note: Only one checksum can be calculated in hardware. Thus, if
 *		SKCS_PROTO_IP is specified in the 'ProtocolFlags',
 *		SkCsGetSendInfo() must calculate the IP header checksum in
 *		software. It might be a better idea to have the calling
 *		protocol stack calculate the IP header checksum.
 *
 * Returns: N/A
 *	On return, the following fields in 'pPacketInfo' may or may not have
 *	been filled with information, depending on the protocol(s) found in the
 *	packet:
 *
 *	ProtocolFlags - Returns the SKCS_PROTO_XXX bit flags of the protocol(s)
 *	that were both requested by the caller and actually found in the packet.
 *	Protocol(s) not specified by the caller and/or not found in the packet
 *	will have their respective SKCS_PROTO_XXX bit flags reset.
 *
 *	Note: For IP fragments, TCP and UDP packet information is ignored.
 *
 *	IpHeaderLength - The total length in bytes of the complete IP header
 *	including any option fields is returned here. This is the start offset
 *	of the IP data, i.e. the TCP or UDP header if present.
 *
 *	IpHeaderChecksum - If IP has been specified in the 'ProtocolFlags', the
 *	16-bit Internet Checksum of the IP header is returned here. This value
 *	is to be stored into the packet's 'IP Header Checksum' field.
 *
 *	PseudoHeaderChecksum - If this is a TCP or UDP packet and if TCP or UDP
 *	has been specified in the 'ProtocolFlags', the 16-bit Internet Checksum
 *	of the TCP or UDP pseudo header is returned here.
 */
void SkCsGetSendInfo(
SK_AC				*pAc,			/* Adapter context struct. */
void				*pIpHeader,		/* IP header. */
SKCS_PACKET_INFO	*pPacketInfo,	/* Packet information struct. */
int					NetNumber)		/* Net number */
{
	/* Internet Header Version found in IP header. */
	unsigned InternetHeaderVersion;

	/* Length of the IP header as found in IP header. */
	unsigned IpHeaderLength;

	/* Bit field specifiying the desired/found protocols. */
	unsigned ProtocolFlags;

	/* Next level protocol identifier found in IP header. */
	unsigned NextLevelProtocol;

	/* Length of IP data portion. */
	unsigned IpDataLength;

	/* TCP/UDP pseudo header checksum. */
	unsigned long PseudoHeaderChecksum;

	/* Pointer to next level protocol statistics structure. */
	SKCS_PROTO_STATS *NextLevelProtoStats;

	/* Temporary variable. */
	unsigned Tmp;

	Tmp = *(SK_U8 *)
		SKCS_IDX(pIpHeader, SKCS_OFS_IP_HEADER_VERSION_AND_LENGTH);

	/* Get the Internet Header Version (IHV). */
	/* Note: The IHV is stored in the upper four bits. */

	InternetHeaderVersion = Tmp >> 4;

	/* Check the Internet Header Version. */
	/* Note: We currently only support IP version 4. */

	if (InternetHeaderVersion != 4) {	/* IPv4? */
		SK_DBG_MSG(pAc, SK_DBGMOD_CSUM, SK_DBGCAT_ERR | SK_DBGCAT_TX,
			("Tx: Unknown Internet Header Version %u.\n",
			InternetHeaderVersion));
		pPacketInfo->ProtocolFlags = 0;
		pAc->Csum.ProtoStats[NetNumber][SKCS_PROTO_STATS_IP].TxUnableCts++;
		return;
	}

	/* Get the IP header length (IHL). */
	/*
	 * Note: The IHL is stored in the lower four bits as the number of
	 * 4-byte words.
	 */

	IpHeaderLength = (Tmp & 0xf) * 4;
	pPacketInfo->IpHeaderLength = IpHeaderLength;

	/* Check the IP header length. */

	/* 04-Aug-1998 sw - Really check the IHL? Necessary? */

	if (IpHeaderLength < 5*4) {
		SK_DBG_MSG(pAc, SK_DBGMOD_CSUM, SK_DBGCAT_ERR | SK_DBGCAT_TX,
			("Tx: Invalid IP Header Length %u.\n", IpHeaderLength));
		pPacketInfo->ProtocolFlags = 0;
		pAc->Csum.ProtoStats[NetNumber][SKCS_PROTO_STATS_IP].TxUnableCts++;
		return;
	}

	/* This is an IPv4 frame with a header of valid length. */

	pAc->Csum.ProtoStats[NetNumber][SKCS_PROTO_STATS_IP].TxOkCts++;

	/* Check if we should calculate the IP header checksum. */

	ProtocolFlags = pPacketInfo->ProtocolFlags;

	if (ProtocolFlags & SKCS_PROTO_IP) {
		pPacketInfo->IpHeaderChecksum =
			SkCsCalculateChecksum(pIpHeader, IpHeaderLength);
	}

	/* Get the next level protocol identifier. */

	NextLevelProtocol =
		*(SK_U8 *) SKCS_IDX(pIpHeader, SKCS_OFS_IP_NEXT_LEVEL_PROTOCOL);

	/*
	 * Check if this is a TCP or UDP frame and if we should calculate the
	 * TCP/UDP pseudo header checksum.
	 *
	 * Also clear all protocol bit flags of protocols not present in the
	 * frame.
	 */

	if ((ProtocolFlags & SKCS_PROTO_TCP) != 0 &&
		NextLevelProtocol == SKCS_PROTO_ID_TCP) {
		/* TCP/IP frame. */
		ProtocolFlags &= SKCS_PROTO_TCP | SKCS_PROTO_IP;
		NextLevelProtoStats =
			&pAc->Csum.ProtoStats[NetNumber][SKCS_PROTO_STATS_TCP];
	}
	else if ((ProtocolFlags & SKCS_PROTO_UDP) != 0 &&
		NextLevelProtocol == SKCS_PROTO_ID_UDP) {
		/* UDP/IP frame. */
		ProtocolFlags &= SKCS_PROTO_UDP | SKCS_PROTO_IP;
		NextLevelProtoStats =
			&pAc->Csum.ProtoStats[NetNumber][SKCS_PROTO_STATS_UDP];
	}
	else {
		/*
		 * Either not a TCP or UDP frame and/or TCP/UDP processing not
		 * specified.
		 */
		pPacketInfo->ProtocolFlags = ProtocolFlags & SKCS_PROTO_IP;
		return;
	}

	/* Check if this is an IP fragment. */

	/*
	 * Note: An IP fragment has a non-zero "Fragment Offset" field and/or
	 * the "More Fragments" bit set. Thus, if both the "Fragment Offset"
	 * and the "More Fragments" are zero, it is *not* a fragment. We can
	 * easily check both at the same time since they are in the same 16-bit
	 * word.
	 */

	if ((*(SK_U16 *)
		SKCS_IDX(pIpHeader, SKCS_OFS_IP_FLAGS_AND_FRAGMENT_OFFSET) &
		~SKCS_IP_DONT_FRAGMENT) != 0) {
		/* IP fragment; ignore all other protocols. */
		pPacketInfo->ProtocolFlags = ProtocolFlags & SKCS_PROTO_IP;
		NextLevelProtoStats->TxUnableCts++;
		return;
	}

	/*
	 * Calculate the TCP/UDP pseudo header checksum.
	 */

	/* Get total length of IP header and data. */

	IpDataLength =
		*(SK_U16 *) SKCS_IDX(pIpHeader, SKCS_OFS_IP_TOTAL_LENGTH);

	/* Get length of IP data portion. */

	IpDataLength = SKCS_NTOH16(IpDataLength) - IpHeaderLength;

	/* Calculate the sum of all pseudo header fields (16-bit). */

	PseudoHeaderChecksum =
		(unsigned long) *(SK_U16 *) SKCS_IDX(pIpHeader,
			SKCS_OFS_IP_SOURCE_ADDRESS + 0) +
		(unsigned long) *(SK_U16 *) SKCS_IDX(pIpHeader,
			SKCS_OFS_IP_SOURCE_ADDRESS + 2) +
		(unsigned long) *(SK_U16 *) SKCS_IDX(pIpHeader,
			SKCS_OFS_IP_DESTINATION_ADDRESS + 0) +
		(unsigned long) *(SK_U16 *) SKCS_IDX(pIpHeader,
			SKCS_OFS_IP_DESTINATION_ADDRESS + 2) +
		(unsigned long) (NextLevelProtocol << 8) +
		(unsigned long) SKCS_HTON16(IpDataLength);

	/* Add-in any carries. */

	SKCS_OC_ADD(PseudoHeaderChecksum, PseudoHeaderChecksum, 0);

	/* Add-in any new carry. */

	SKCS_OC_ADD(pPacketInfo->PseudoHeaderChecksum, PseudoHeaderChecksum, 0);

	NextLevelProtoStats->TxOkCts++;	/* Success. */
}	/* SkCsGetSendInfo */
/*****************************************************************************
 *
 *	SkGeSetPauseParam - configures the pause parameters of an adapter
 *
 * Description:
 *	This function sets the Rx or Tx pause parameters 
 *
 * Returns:
 *	==0:	everything fine, no error
 *	!=0:	the return value is the error code of the failure 
 */
int SkGeSetPauseParam(struct net_device *dev,
			struct ethtool_pauseparam *ecmd)
{
	DEV_NET			*pNet        = PPRIV;
	SK_AC			*pAC         = pNet->pAC;
	int			port         = pNet->PortNr;
	SK_GEPORT		*pPort = &pAC->GIni.GP[port];
	int			PrevSpeedVal = pPort->PLinkSpeedUsed;
	SK_U32			Instance;
	char			Buf[4];
	int			Ret;
	SK_BOOL			prevAutonegValue = SK_TRUE;
	int			prevTxPause      = 0;
	int			prevRxPause      = 0;
	unsigned int		Len              = 1;


        if (port == 0) {
                Instance = (pAC->RlmtNets == 2) ? 1 : 2;
        } else {
                Instance = (pAC->RlmtNets == 2) ? 2 : 3;
        }

	/*
	** we have to determine the current settings to see if 
	** the operator requested any modification of the flow 
	** control parameters...
	*/
	if (pPort->PFlowCtrlMode == SK_FLOW_MODE_LOC_SEND) {
		prevTxPause = 1;
	} 
	if ((pPort->PFlowCtrlMode == SK_FLOW_MODE_SYMMETRIC) ||
	    (pPort->PFlowCtrlMode == SK_FLOW_MODE_SYM_OR_REM)) {
		prevTxPause = 1;
		prevRxPause = 1;
	}

	if ((prevRxPause == 0) && (prevTxPause == 0)) {
		prevAutonegValue = SK_FALSE;
	}


	/*
	** perform modifications regarding the changes 
	** requested by the operator
	*/
	if (ecmd->autoneg != prevAutonegValue) {
		if (ecmd->autoneg == AUTONEG_DISABLE) {
			*Buf = (char) SK_FLOW_MODE_NONE;
		} else {
			*Buf = (char) SK_FLOW_MODE_SYMMETRIC;
		}
	} else {
		if(ecmd->rx_pause && ecmd->tx_pause) {
			*Buf = (char) SK_FLOW_MODE_SYMMETRIC;
		} else if (ecmd->rx_pause && !ecmd->tx_pause) {
			*Buf = (char) SK_FLOW_MODE_SYM_OR_REM;
		} else if(!ecmd->rx_pause && ecmd->tx_pause) {
			*Buf = (char) SK_FLOW_MODE_LOC_SEND;
		} else {
			*Buf = (char) SK_FLOW_MODE_NONE;
		}
	}

	Ret = SkPnmiSetVar(pAC, pAC->IoBase, OID_SKGE_FLOWCTRL_MODE,
			&Buf, &Len, Instance, pNet->NetNr);

	if (Ret != SK_PNMI_ERR_OK) {
		SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_CTRL,
		("ethtool (sk98lin): error changing rx/tx pause (%i)\n", Ret));
	}  else {
		Len = 1; /* set buffer length to correct value */
	}

	/*
	** It may be that autoneg has been disabled! Therefore
	** set the speed to the previously used value...
	*/
	*Buf = (char) PrevSpeedVal;

	Ret = SkPnmiSetVar(pAC, pAC->IoBase, OID_SKGE_SPEED_MODE, 
			&Buf, &Len, Instance, pNet->NetNr);

	if (Ret != SK_PNMI_ERR_OK) {
		SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_CTRL,
		("ethtool (sk98lin): error setting speed (%i)\n", Ret));
	}
        return 0;
}
示例#11
0
/******************************************************************************
 *
 *	SkCsGetReceiveInfo - verify checksum information for a received packet
 *
 * Description:
 *	Verify a received frame's checksum. The function returns a status code
 *	reflecting the result of the verification.
 *
 * Note:
 *	Before calling this function you have to verify that the frame is
 *	not padded and Checksum1 and Checksum2 are bigger than 1.
 *
 * Arguments:
 *	pAc - Pointer to adapter context struct.
 *
 *	pIpHeader - Pointer to IP header. Must be at least the length in bytes
 *	of the received IP header including any option fields. For UDP packets,
 *	8 additional bytes are needed to access the UDP checksum.
 *
 *	Note: The actual length of the IP header is stored in the lower four
 *	bits of the first octet of the IP header as the number of 4-byte words,
 *	so it must be multiplied by four to get the length in bytes. Thus, the
 *	maximum IP header length is 15 * 4 = 60 bytes.
 *
 *	Checksum1 - The first 16-bit Internet Checksum calculated by the
 *	hardware starting at the offset returned by SkCsSetReceiveFlags().
 *
 *	Checksum2 - The second 16-bit Internet Checksum calculated by the
 *	hardware starting at the offset returned by SkCsSetReceiveFlags().
 *
 *  NetNumber - The net number.
 *
 *  Len - The packet length (without MAC header) - never access memory
 *	behind pIpHeader[Len].
 *
 * Returns:
 *	SKCS_STATUS_UNKNOWN_IP_VERSION - Not an IP v4 frame.
 *	SKCS_STATUS_IP_CSUM_ERROR - IP checksum error.
 *	SKCS_STATUS_IP_CSUM_ERROR_TCP - IP checksum error in TCP frame.
 *	SKCS_STATUS_IP_CSUM_ERROR_UDP - IP checksum error in UDP frame
 *	SKCS_STATUS_IP_FRAGMENT - IP fragment (IP checksum ok).
 *	SKCS_STATUS_IP_CSUM_OK - IP checksum ok (not a TCP or UDP frame).
 *	SKCS_STATUS_TCP_CSUM_ERROR - TCP checksum error (IP checksum ok).
 *	SKCS_STATUS_UDP_CSUM_ERROR - UDP checksum error (IP checksum ok).
 *	SKCS_STATUS_TCP_CSUM_OK - IP and TCP checksum ok.
 *	SKCS_STATUS_UDP_CSUM_OK - IP and UDP checksum ok.
 *	SKCS_STATUS_IP_CSUM_OK_NO_UDP - IP checksum OK and no UDP checksum.
 *	SKCS_STATUS_NO_CSUM_POSSIBLE - Checksum could not be built (various reasons).
 *
 *	Note: If SKCS_OVERWRITE_STATUS is defined, the SKCS_STATUS_XXX values
 *	returned here can be defined in some header file by the module using CSUM.
 *	In this way, the calling module can assign return values for its own needs,
 *	e.g. by assigning bit flags to the individual protocols.
 */
SKCS_STATUS SkCsGetReceiveInfo(
SK_AC		*pAc,		/* Adapter context struct. */
void		*pIpHeader,	/* IP header. */
unsigned	Checksum1,	/* Hardware checksum 1. */
unsigned	Checksum2,	/* Hardware checksum 2. */
int			NetNumber,	/* Net number. */
unsigned	Len)		/* Packet length (without MAC header). */
{
	/* Internet Header Version found in IP header. */
	unsigned InternetHeaderVersion;

	/* Length of the IP header as found in IP header. */
	unsigned IpHeaderLength;

	/* Length of IP data portion. */
	unsigned IpDataLength;

	/* IP header checksum. */
	unsigned IpHeaderChecksum;

	/* IP header options checksum, if any. */
	unsigned IpOptionsChecksum;

	/* IP data checksum, i.e. TCP/UDP checksum. */
	unsigned IpDataChecksum;

	/* Next level protocol identifier found in IP header. */
	unsigned NextLevelProtocol;

	/* The checksum of the "next level protocol", i.e. TCP or UDP. */
	unsigned long NextLevelProtocolChecksum;

	/* Pointer to next level protocol statistics structure. */
	SKCS_PROTO_STATS *NextLevelProtoStats;

	/* Temporary variable. */
	unsigned Tmp;

#ifdef SK_IPV6_SUPPORT
	/* For parsing IPv6 packets */
	SK_U8	*pDst;
	SK_U32	ProtCsum;
	SK_U32	Pseudo;
	SK_U32	Pseudo2;
	SK_U16	Offset;
	SK_U16	NextHeaderOffset;
	SK_U16	OptSize;
	SK_U8	NextHeader;
#endif

	if (SKCS_IDX_CHECK(Len, SKCS_OFS_IP_HEADER_VERSION_AND_LENGTH)) {
		pAc->Csum.ProtoStats[NetNumber][SKCS_PROTO_STATS_IP].RxUnableCts++;
		return (SKCS_STATUS_NO_CSUM_POSSIBLE);
	}

	Tmp = *(SK_U8 *) SKCS_IDX(pIpHeader, SKCS_OFS_IP_HEADER_VERSION_AND_LENGTH);

	/* Get the Internet Header Version (IHV). */
	/* Note: The IHV is stored in the upper four bits. */

	InternetHeaderVersion = Tmp >> 4;

	/* Check the Internet Header Version. */

#ifdef SK_IPV6_SUPPORT
	if (InternetHeaderVersion == 6) {	/* IPv6? */

		if ((pAc->Csum.ReceiveFlags[NetNumber] &
			(SKCS_PROTO_TCPV6 | SKCS_PROTO_UDPV6)) == 0) {

			/* The OS/stack told us not to verify IPv6 checksum. */
			return (SKCS_STATUS_NO_CSUM_POSSIBLE);
		}

		/* Get the payload length. the payload starts immediately after the
		 * IPv6 header. This value includes all additional headers!
		 */
		 /* first test if the frame has at least the length of the IPv6 header */
		if (Len < SKCS_IP6_HEADER_SIZE) {
			pAc->Csum.ProtoStats[NetNumber][SKCS_PROTO_STATS_IP].RxUnableCts++;
			return (SKCS_STATUS_NO_CSUM_POSSIBLE);
		}
		IpDataLength = *(SK_U16 *)
			SKCS_IDX(pIpHeader, SKCS_OFS_IP6_PAYLOAD_LENGTH);
		IpDataLength = SKCS_NTOH16(IpDataLength);

		/* Before we can proceed we need to find the protocol frame that
		 * contains the checksum. We support TCP and UDP.
		 */

		Offset = SKCS_IP6_HEADER_SIZE;
		NextHeaderOffset = SKCS_OFS_IP6_NEXT_HEADER;
		/* this access has been secured by checking frame len against SKCS_IP6_HEADER_SIZE */
		NextHeader = *(SK_U8 *) SKCS_IDX(pIpHeader, NextHeaderOffset);

		pDst = (SK_U8 *) SKCS_IDX(pIpHeader, SKCS_OFS_IP6_DESTINATION_ADDRESS);

		do {
			if ((NextHeader == SKCS_PROTO_ID_TCP) ||
				(NextHeader == SKCS_PROTO_ID_UDP)) {

				/* We found the TCP/UDP header */
				break;
			}

			/* Check type of next header to find "Next Header" field */
			switch (NextHeader) {

			case 0:		/* hop-by-hop options header	*/
			case 60:	/* Destination options header	*/
				NextHeaderOffset = Offset;

				/*
				 * Calculate the size of the option header. The size is in
				 * units of 8-octets and does not contain the first 8 octets.
				 */
				if (SKCS_IDX_CHECK(Len, (unsigned) (NextHeaderOffset + 1))) {
					pAc->Csum.ProtoStats[NetNumber][SKCS_PROTO_STATS_IP].RxUnableCts++;
					return (SKCS_STATUS_NO_CSUM_POSSIBLE);
				}
				OptSize = *(SK_U8 *) SKCS_IDX(pIpHeader, NextHeaderOffset + 1);
				OptSize *= 8;
				Offset += OptSize + 8;
				break;

			case 43:	/* routing header				*/
				NextHeaderOffset = Offset;

				/*
				 * Calculate the size of the option header. The size is in
				 * units of 8-octets and does not contain the first 8 octets.
				 */
				if (SKCS_IDX_CHECK(Len, (unsigned) (NextHeaderOffset + 1))) {
					pAc->Csum.ProtoStats[NetNumber][SKCS_PROTO_STATS_IP].RxUnableCts++;
					return (SKCS_STATUS_NO_CSUM_POSSIBLE);
				}
				OptSize = *(SK_U8 *) SKCS_IDX(pIpHeader, NextHeaderOffset + 1);
				OptSize *= 8;
				Offset += OptSize + 8;

				/*
				 * If SegLeft != 0, use the last address in the routing header
				 * as IP dst in the pseudo header (for both, type 0 and type 2).
				 */
				if (*(SK_U8 *) SKCS_IDX(pIpHeader, NextHeaderOffset + 3) != 0) {
					SK_DBG_MSG(pAc, SK_DBGMOD_CSUM, SK_DBGCAT_ERR | SK_DBGCAT_RX,
						("Rx: IPv6 Routing Header with SegLeft != 0.\n"));
					pDst = (SK_U8 *) SKCS_IDX(pIpHeader, Offset - 16);
				}
				break;

			case 44:	/* fragment header */
				pAc->Csum.ProtoStats[NetNumber][SKCS_PROTO_STATS_IP].RxUnableCts++;
				return (SKCS_STATUS_IP_FRAGMENT);

			case 46:	/* resource ReSerVation protocol */
			case 41:	/* encapsulated IPv6 header */
			case 59:	/* No next header */
				SK_DBG_MSG(
					pAc,
					SK_DBGMOD_CSUM, SK_DBGCAT_ERR | SK_DBGCAT_RX,
					("Rx: Header in IPv6 packet can not be processed: %u.\n",
						NextHeader));
				pAc->Csum.ProtoStats[NetNumber][SKCS_PROTO_STATS_IP].RxUnableCts++;
				return (SKCS_STATUS_NO_CSUM_POSSIBLE);

			case 51:	/* authentication header, would have to use OptSize *= 4! */
			case 50:	/* encapsulating security payload */
			case 58:	/* ICMP v6 */
			default:
				pAc->Csum.ProtoStats[NetNumber][SKCS_PROTO_STATS_IP].RxUnableCts++;
				return (SKCS_STATUS_NO_CSUM_POSSIBLE);
			}

			/* Continue with the next header */
			if (SKCS_IDX_CHECK(Len, NextHeaderOffset)) {
				pAc->Csum.ProtoStats[NetNumber][SKCS_PROTO_STATS_IP].RxUnableCts++;
				return (SKCS_STATUS_NO_CSUM_POSSIBLE);
			}
			NextHeader = *(SK_U8 *) SKCS_IDX(pIpHeader, NextHeaderOffset);
		} while (Offset < (IpDataLength + SKCS_IP6_HEADER_SIZE));

		if (Offset >= (IpDataLength + SKCS_IP6_HEADER_SIZE)) {
			/* We passed the end of the packet without finding the payload. */
			SK_DBG_MSG(
				pAc,
				SK_DBGMOD_CSUM, SK_DBGCAT_ERR | SK_DBGCAT_RX,
				("Rx: malformed IPv6 packet.\n"));
				pAc->Csum.ProtoStats[NetNumber][SKCS_PROTO_STATS_IP].RxUnableCts++;
				return (SKCS_STATUS_NO_CSUM_POSSIBLE);
		}

		/* Before starting checksum calculating, check if we really need to. */
		if ((NextHeader == SKCS_PROTO_ID_TCP) &&
			(((pAc->Csum.ReceiveFlags[NetNumber] & SKCS_PROTO_TCPV6) == 0))) {

			/* Header is TCP but we shall not verify TCP checksum. */
			return (SKCS_STATUS_NO_CSUM_POSSIBLE);
		}
		if ((NextHeader == SKCS_PROTO_ID_UDP) &&
			(((pAc->Csum.ReceiveFlags[NetNumber] & SKCS_PROTO_UDPV6) == 0))) {

			/* Header is UDP but we shall not verify UDP checksum. */
			return (SKCS_STATUS_NO_CSUM_POSSIBLE);
		}

		if (IpDataLength + SKCS_IP6_HEADER_SIZE > Len) {
			pAc->Csum.ProtoStats[NetNumber][SKCS_PROTO_STATS_IP].RxUnableCts++;
			return (SKCS_STATUS_NO_CSUM_POSSIBLE);
		}
		ProtCsum = SkCsCalculateChecksum(
			SKCS_IDX(pIpHeader, Offset),
			IpDataLength + SKCS_IP6_HEADER_SIZE -Offset);

		/*
		 * Calculate the pseudo header checksum.
		 */

		/* Start with src and dest address */
		/* this access has been secured by checking frame len against SKCS_IP6_HEADER_SIZE */
		Pseudo = SkCsCalculateChecksum(
					SKCS_IDX(pIpHeader, SKCS_OFS_IP6_SOURCE_ADDRESS), 16);

		Pseudo2 = SkCsCalculateChecksum(pDst, 16);
		SKCS_OC_ADD(Pseudo, Pseudo, Pseudo2);
		SKCS_OC_ADD(Pseudo, Pseudo, 0);		/* Add-in any carries. */

		SKCS_OC_ADD(Pseudo, Pseudo,
			SKCS_HTON16(IpDataLength + SKCS_IP6_HEADER_SIZE -Offset));
		SKCS_OC_ADD(Pseudo, Pseudo, SKCS_HTON16(NextHeader));
		SKCS_OC_ADD(Pseudo, Pseudo, 0);		/* Add-in any carries. */

		/* Add to protocol part's checksum */
		SKCS_OC_ADD(ProtCsum, ProtCsum, Pseudo);
		SKCS_OC_ADD(ProtCsum, ProtCsum, 0);	/* Add-in any carries. */

		/*
		 * Check result. We can only process TCP or UDP.
		 */
		switch (NextHeader) {
		case SKCS_PROTO_ID_TCP:
			if (ProtCsum != 0xFFFF) {
				pAc->Csum.ProtoStats[NetNumber][SKCS_PROTO_STATS_TCP].RxErrCts++;
				return (SKCS_STATUS_TCP_CSUM_ERROR);
			}
			pAc->Csum.ProtoStats[NetNumber][SKCS_PROTO_STATS_TCP].RxOkCts++;
			return (SKCS_STATUS_TCP_CSUM_OK);

		case SKCS_PROTO_ID_UDP:

			if (ProtCsum != 0xFFFF) {
				pAc->Csum.ProtoStats[NetNumber][SKCS_PROTO_STATS_UDP].RxErrCts++;
				return (SKCS_STATUS_UDP_CSUM_ERROR);
			}
			pAc->Csum.ProtoStats[NetNumber][SKCS_PROTO_STATS_UDP].RxOkCts++;
			return (SKCS_STATUS_UDP_CSUM_OK);

		default:
			/* This case should already be eliminated because we only compute
			 * the checksum for TCP, UDP or ICMPv6
			 */
			return (SKCS_STATUS_NO_CSUM_POSSIBLE);
		}
	}
#endif	/* SK_IPV6_SUPPORT */

	if (InternetHeaderVersion != 4) {	/* IPv4? */
		SK_DBG_MSG(pAc, SK_DBGMOD_CSUM, SK_DBGCAT_ERR | SK_DBGCAT_RX,
			("Rx: Unknown Internet Header Version %u.\n",
			InternetHeaderVersion));
		pAc->Csum.ProtoStats[NetNumber][SKCS_PROTO_STATS_IP].RxUnableCts++;
		return (SKCS_STATUS_UNKNOWN_IP_VERSION);
	}

	/* Get the IP header length (IHL). */
	/*
	 * Note: The IHL is stored in the lower four bits as the number of
	 * 4-byte words.
	 */

	IpHeaderLength = (Tmp & 0xf) * 4;

	/* Check the IP header length. */

	/* 04-Aug-1998 sw - Really check the IHL? Necessary? */

	if (IpHeaderLength < 5*4) {
		SK_DBG_MSG(pAc, SK_DBGMOD_CSUM, SK_DBGCAT_ERR | SK_DBGCAT_RX,
			("Rx: Invalid IP Header Length %u.\n", IpHeaderLength));
		pAc->Csum.ProtoStats[NetNumber][SKCS_PROTO_STATS_IP].RxErrCts++;
		return (SKCS_STATUS_IP_CSUM_ERROR);
	}

	/* This is an IPv4 frame with a header of valid length. */

	/* First test if the frame has at least the length of the IP header. */
	if (Len < IpHeaderLength) {
		pAc->Csum.ProtoStats[NetNumber][SKCS_PROTO_STATS_IP].RxUnableCts++;
		return (SKCS_STATUS_NO_CSUM_POSSIBLE);
	}

	/* Get the IP header and data checksum. */
	IpDataChecksum = Checksum2;

	/* Get the next level protocol identifier. */
	/* this access has been secured by checking frame len against IpHeaderLength */
	NextLevelProtocol = *(SK_U8 *)
		SKCS_IDX(pIpHeader, SKCS_OFS_IP_NEXT_LEVEL_PROTOCOL);

	if ((pAc->Csum.ReceiveFlags[NetNumber] & SKCS_PROTO_IP) != 0) {

		/* IPv4 checksum verification is specified */

		/*
		 * The IP header checksum is calculated as follows:
		 *
		 *	IpHeaderChecksum = Checksum1 - Checksum2
		 */

		SKCS_OC_SUB(IpHeaderChecksum, Checksum1, Checksum2);

		/* Check if any IP header options. */

		if (IpHeaderLength > SKCS_IP_HEADER_SIZE) {

			/*
			 * Get the IP options checksum.
			 *
			 * This access has been secured by checking the frame length
			 * against IpHeaderLength.
			 */
			IpOptionsChecksum = SkCsCalculateChecksum(
				SKCS_IDX(pIpHeader, SKCS_IP_HEADER_SIZE),
				IpHeaderLength - SKCS_IP_HEADER_SIZE);

			/* Adjust the IP header and IP data checksums. */

			SKCS_OC_ADD(IpHeaderChecksum, IpHeaderChecksum, IpOptionsChecksum);

			SKCS_OC_SUB(IpDataChecksum, IpDataChecksum, IpOptionsChecksum);
		}

		/*
		 * Check if the IP header checksum is ok.
		 *
		 * NOTE: We must check the IP header checksum even if the caller
		 * just wants us to check upper-layer checksums, because we cannot do
		 * any further processing of the packet without a valid IP checksum.
		 */

		if (IpHeaderChecksum != 0xffff) {
			pAc->Csum.ProtoStats[NetNumber][SKCS_PROTO_STATS_IP].RxErrCts++;
			/* The NDIS tester wants to know the upper level protocol, too. */
			if (NextLevelProtocol == SKCS_PROTO_ID_TCP) {
				return(SKCS_STATUS_IP_CSUM_ERROR_TCP);
			}
			else if (NextLevelProtocol == SKCS_PROTO_ID_UDP) {
				return(SKCS_STATUS_IP_CSUM_ERROR_UDP);
			}
			return (SKCS_STATUS_IP_CSUM_ERROR);
		}
	}

	/*
	 * Check if this is a TCP or UDP frame and if we should calculate the
	 * TCP/UDP pseudo header checksum.
	 *
	 * Also clear all protocol bit flags of protocols not present in the
	 * frame.
	 */

	if ((pAc->Csum.ReceiveFlags[NetNumber] & SKCS_PROTO_TCP) != 0 &&
		NextLevelProtocol == SKCS_PROTO_ID_TCP) {
		/* TCP/IP frame. */
		NextLevelProtoStats =
			&pAc->Csum.ProtoStats[NetNumber][SKCS_PROTO_STATS_TCP];
	}
	else if ((pAc->Csum.ReceiveFlags[NetNumber] & SKCS_PROTO_UDP) != 0 &&
		NextLevelProtocol == SKCS_PROTO_ID_UDP) {
		/* UDP/IP frame. */
		NextLevelProtoStats =
			&pAc->Csum.ProtoStats[NetNumber][SKCS_PROTO_STATS_UDP];
	}
	else {
		/*
		 * Either not a TCP or UDP frame and/or TCP/UDP processing not
		 * specified.
		 */
		return (SKCS_STATUS_IP_CSUM_OK);
	}

	/* Check if this is an IP fragment. */

	/*
	 * Note: An IP fragment has a non-zero "Fragment Offset" field and/or
	 * the "More Fragments" bit set. Thus, if both the "Fragment Offset"
	 * and the "More Fragments" are zero, it is *not* a fragment. We can
	 * easily check both at the same time since they are in the same 16-bit
	 * word.
	 *
	 * This access has been secured by checking the frame length
	 * against IpHeaderLength.
	 */

	if ((*(SK_U16 *) SKCS_IDX(pIpHeader, SKCS_OFS_IP_FLAGS_AND_FRAGMENT_OFFSET) &
		~SKCS_IP_DONT_FRAGMENT) != 0) {
		/* IP fragment; ignore all other protocols. */
		NextLevelProtoStats->RxUnableCts++;
		return (SKCS_STATUS_IP_FRAGMENT);
	}

	if (SKCS_IDX_CHECK(Len, (IpHeaderLength + 6 + 1))) {
		pAc->Csum.ProtoStats[NetNumber][SKCS_PROTO_STATS_IP].RxUnableCts++;
		return (SKCS_STATUS_NO_CSUM_POSSIBLE);
	}

	/*
	 * A checksum value of 0 in UDP over IPv4 frames means that no checksum
	 * was inserted by the sender (RFC 768).
	 */

	if (NextLevelProtocol == SKCS_PROTO_ID_UDP &&
		*(SK_U16 *) SKCS_IDX(pIpHeader, IpHeaderLength + 6) == 0x0000) {

		NextLevelProtoStats->RxOkCts++;
		
		return (SKCS_STATUS_IP_CSUM_OK_NO_UDP);
	}

	/*
	 * Calculate the TCP/UDP checksum.
	 */

	/*
	 * Get total length of IP header and data.
	 *
	 * This access has been secured by checking the frame length
	 * against IpHeaderLength.
	 */

	IpDataLength =
		*(SK_U16 *) SKCS_IDX(pIpHeader, SKCS_OFS_IP_TOTAL_LENGTH);

	/* Get length of IP data portion. */

	IpDataLength = SKCS_NTOH16(IpDataLength) - IpHeaderLength;

	/*
	 * This access has been secured by checking the frame length
	 * against IpHeaderLength.
	 */

	NextLevelProtocolChecksum =

		/* Calculate the pseudo header checksum. */

		(unsigned long) *(SK_U16 *) SKCS_IDX(pIpHeader,
			SKCS_OFS_IP_SOURCE_ADDRESS + 0) +
		(unsigned long) *(SK_U16 *) SKCS_IDX(pIpHeader,
			SKCS_OFS_IP_SOURCE_ADDRESS + 2) +
		(unsigned long) *(SK_U16 *) SKCS_IDX(pIpHeader,
			SKCS_OFS_IP_DESTINATION_ADDRESS + 0) +
		(unsigned long) *(SK_U16 *) SKCS_IDX(pIpHeader,
			SKCS_OFS_IP_DESTINATION_ADDRESS + 2) +
		(unsigned long) SKCS_HTON16(NextLevelProtocol) +
		(unsigned long) SKCS_HTON16(IpDataLength) +

		/* Add the TCP/UDP header checksum. */

		(unsigned long) IpDataChecksum;

	/* Add-in any carries. */

	SKCS_OC_ADD(NextLevelProtocolChecksum, NextLevelProtocolChecksum, 0);

	/* Add-in any new carry. */

	SKCS_OC_ADD(NextLevelProtocolChecksum, NextLevelProtocolChecksum, 0);

	/* Check if the TCP/UDP checksum is ok. */

	if ((unsigned) NextLevelProtocolChecksum == 0xffff) {

		/* TCP/UDP checksum ok. */

		NextLevelProtoStats->RxOkCts++;

		return (NextLevelProtocol == SKCS_PROTO_ID_TCP ?
			SKCS_STATUS_TCP_CSUM_OK : SKCS_STATUS_UDP_CSUM_OK);
	}
	
	/* TCP/UDP checksum error. */

	NextLevelProtoStats->RxErrCts++;

	return (NextLevelProtocol == SKCS_PROTO_ID_TCP ?
		SKCS_STATUS_TCP_CSUM_ERROR : SKCS_STATUS_UDP_CSUM_ERROR);
}	/* SkCsGetReceiveInfo */