2005-11-28 23:09:21 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
|
|
|
|
* University Research and Technology
|
|
|
|
* Corporation. All rights reserved.
|
2006-08-23 04:29:35 +04:00
|
|
|
* Copyright (c) 2004-2006 The University of Tennessee and The University
|
2005-11-28 23:09:21 +03:00
|
|
|
* of Tennessee Research Foundation. All rights
|
|
|
|
* reserved.
|
|
|
|
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
|
|
|
|
* University of Stuttgart. All rights reserved.
|
|
|
|
* Copyright (c) 2004-2005 The Regents of the University of California.
|
|
|
|
* All rights reserved.
|
2009-03-24 02:52:05 +03:00
|
|
|
* Copyright (c) 2009 IBM Corporation. All rights reserved.
|
|
|
|
* Copyright (c) 2009 Los Alamos National Security, LLC. All rights
|
2015-06-24 06:59:57 +03:00
|
|
|
* reserved.
|
2005-11-28 23:09:21 +03:00
|
|
|
* $COPYRIGHT$
|
|
|
|
*
|
|
|
|
* Additional copyrights may follow
|
|
|
|
*
|
|
|
|
* $HEADER$
|
|
|
|
*/
|
|
|
|
|
2005-11-28 20:20:21 +03:00
|
|
|
#ifndef _OPAL_CRC_H_
|
|
|
|
#define _OPAL_CRC_H_
|
|
|
|
|
2006-10-20 11:01:52 +04:00
|
|
|
#include "opal_config.h"
|
|
|
|
|
2006-10-18 02:06:51 +04:00
|
|
|
#include <stddef.h>
|
|
|
|
|
2009-08-20 15:42:18 +04:00
|
|
|
BEGIN_C_DECLS
|
2006-08-23 04:29:35 +04:00
|
|
|
|
2005-11-28 20:20:21 +03:00
|
|
|
#define CRC_POLYNOMIAL ((unsigned int)0x04c11db7)
|
|
|
|
#define CRC_INITIAL_REGISTER ((unsigned int)0xffffffff)
|
|
|
|
|
2006-03-17 21:46:48 +03:00
|
|
|
|
|
|
|
#define OPAL_CSUM( SRC, LEN ) opal_uicsum( SRC, LEN )
|
|
|
|
#define OPAL_CSUM_PARTIAL( SRC, LEN, UI1, UI2 ) \
|
|
|
|
opal_uicsum_partial( SRC, LEN, UI1, UI2 )
|
|
|
|
#define OPAL_CSUM_BCOPY_PARTIAL( SRC, DST, LEN1, LEN2, UI1, UI2 ) \
|
|
|
|
opal_bcopy_uicsum_partial( SRC, DST, LEN1, LEN2, UI1, UI2 )
|
|
|
|
#define OPAL_CSUM_ZERO 0
|
|
|
|
|
|
|
|
|
2006-08-23 04:29:35 +04:00
|
|
|
OPAL_DECLSPEC unsigned long
|
2005-11-28 20:20:21 +03:00
|
|
|
opal_bcopy_csum_partial(
|
|
|
|
const void * source,
|
|
|
|
void * destination,
|
2006-10-18 00:20:58 +04:00
|
|
|
size_t copylen,
|
|
|
|
size_t csumlen,
|
|
|
|
unsigned long* lastPartialLong,
|
|
|
|
size_t* lastPartialLength
|
2005-11-28 20:20:21 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
static inline unsigned long
|
|
|
|
opal_bcopy_csum (
|
|
|
|
const void * source,
|
|
|
|
void * destination,
|
2006-10-18 00:20:58 +04:00
|
|
|
size_t copylen,
|
|
|
|
size_t csumlen
|
2005-11-28 20:20:21 +03:00
|
|
|
)
|
|
|
|
{
|
|
|
|
unsigned long plong = 0;
|
2006-10-18 00:20:58 +04:00
|
|
|
size_t plength = 0;
|
2005-11-28 20:20:21 +03:00
|
|
|
return opal_bcopy_csum_partial(source, destination, copylen, csumlen, &plong, &plength);
|
|
|
|
}
|
2015-06-24 06:59:57 +03:00
|
|
|
|
|
|
|
OPAL_DECLSPEC unsigned int
|
2005-11-28 20:20:21 +03:00
|
|
|
opal_bcopy_uicsum_partial (
|
|
|
|
const void * source,
|
|
|
|
void * destination,
|
2006-10-18 00:20:58 +04:00
|
|
|
size_t copylen,
|
|
|
|
size_t csumlen,
|
|
|
|
unsigned int* lastPartialInt,
|
|
|
|
size_t* lastPartialLength
|
2005-11-28 20:20:21 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
static inline unsigned int
|
|
|
|
opal_bcopy_uicsum (
|
|
|
|
const void * source,
|
|
|
|
void * destination,
|
2006-10-18 00:20:58 +04:00
|
|
|
size_t copylen,
|
|
|
|
size_t csumlen
|
2005-11-28 20:20:21 +03:00
|
|
|
)
|
|
|
|
{
|
|
|
|
unsigned int pint = 0;
|
2006-10-18 00:20:58 +04:00
|
|
|
size_t plength = 0;
|
2005-11-28 20:20:21 +03:00
|
|
|
return opal_bcopy_uicsum_partial(source, destination, copylen, csumlen, &pint, &plength);
|
|
|
|
}
|
2015-06-24 06:59:57 +03:00
|
|
|
|
|
|
|
OPAL_DECLSPEC unsigned long
|
2005-11-28 20:20:21 +03:00
|
|
|
opal_csum_partial (
|
|
|
|
const void * source,
|
2006-10-18 00:20:58 +04:00
|
|
|
size_t csumlen,
|
|
|
|
unsigned long* lastPartialLong,
|
|
|
|
size_t* lastPartialLength
|
2005-11-28 20:20:21 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
|
2015-06-24 06:59:57 +03:00
|
|
|
static inline unsigned long
|
2006-10-18 00:20:58 +04:00
|
|
|
opal_csum(const void * source, size_t csumlen)
|
2005-11-28 20:20:21 +03:00
|
|
|
{
|
|
|
|
unsigned long lastPartialLong = 0;
|
2006-10-18 00:20:58 +04:00
|
|
|
size_t lastPartialLength = 0;
|
2005-11-28 20:20:21 +03:00
|
|
|
return opal_csum_partial(source, csumlen, &lastPartialLong, &lastPartialLength);
|
|
|
|
}
|
2009-04-09 15:04:38 +04:00
|
|
|
/*
|
|
|
|
* The buffer passed to this function is assumed to be 16-bit aligned
|
|
|
|
*/
|
2009-03-24 02:52:05 +03:00
|
|
|
static inline uint16_t
|
|
|
|
opal_csum16 (const void * source, size_t csumlen)
|
|
|
|
{
|
2009-04-09 15:04:38 +04:00
|
|
|
uint16_t *src = (uint16_t *) source;
|
|
|
|
register uint32_t csum = 0;
|
2009-03-24 02:52:05 +03:00
|
|
|
|
2009-04-09 15:04:38 +04:00
|
|
|
while (csumlen > 1) {
|
2009-03-24 02:52:05 +03:00
|
|
|
csum += *src++;
|
2009-04-09 15:04:38 +04:00
|
|
|
csumlen -= 2;
|
|
|
|
}
|
2015-06-24 06:59:57 +03:00
|
|
|
/* Add leftover byte, if any */
|
2009-04-09 15:04:38 +04:00
|
|
|
if(csumlen > 0)
|
|
|
|
csum += *((unsigned char*)src);
|
|
|
|
/* Fold 32-bit checksum to 16 bits */
|
|
|
|
while(csum >> 16) {
|
2015-06-24 06:59:57 +03:00
|
|
|
csum = (csum & 0xFFFF) + (csum >> 16);
|
|
|
|
}
|
2009-03-24 02:52:05 +03:00
|
|
|
return csum;
|
|
|
|
}
|
|
|
|
|
2006-08-23 04:29:35 +04:00
|
|
|
OPAL_DECLSPEC unsigned int
|
2005-11-28 20:20:21 +03:00
|
|
|
opal_uicsum_partial (
|
|
|
|
const void * source,
|
2006-10-18 00:20:58 +04:00
|
|
|
size_t csumlen,
|
2005-11-28 20:20:21 +03:00
|
|
|
unsigned int * lastPartialInt,
|
2006-10-18 00:20:58 +04:00
|
|
|
size_t* lastPartialLength
|
2005-11-28 20:20:21 +03:00
|
|
|
);
|
|
|
|
|
2015-06-24 06:59:57 +03:00
|
|
|
static inline unsigned int
|
2006-10-18 00:20:58 +04:00
|
|
|
opal_uicsum(const void * source, size_t csumlen)
|
2005-11-28 20:20:21 +03:00
|
|
|
{
|
|
|
|
unsigned int lastPartialInt = 0;
|
2006-10-18 00:20:58 +04:00
|
|
|
size_t lastPartialLength = 0;
|
2005-11-28 20:20:21 +03:00
|
|
|
return opal_uicsum_partial(source, csumlen, &lastPartialInt, &lastPartialLength);
|
|
|
|
}
|
2015-06-24 06:59:57 +03:00
|
|
|
|
2005-11-28 20:20:21 +03:00
|
|
|
/*
|
|
|
|
* CRC Support
|
|
|
|
*/
|
|
|
|
|
|
|
|
void opal_initialize_crc_table(void);
|
|
|
|
|
2015-06-24 06:59:57 +03:00
|
|
|
OPAL_DECLSPEC unsigned int
|
2005-11-28 20:20:21 +03:00
|
|
|
opal_bcopy_uicrc_partial(
|
|
|
|
const void * source,
|
|
|
|
void * destination,
|
2006-10-18 00:20:58 +04:00
|
|
|
size_t copylen,
|
|
|
|
size_t crclen,
|
2005-11-28 20:20:21 +03:00
|
|
|
unsigned int partial_crc);
|
|
|
|
|
2015-06-24 06:59:57 +03:00
|
|
|
static inline unsigned int
|
2005-11-28 20:20:21 +03:00
|
|
|
opal_bcopy_uicrc(
|
2015-06-24 06:59:57 +03:00
|
|
|
const void * source,
|
2005-11-28 20:20:21 +03:00
|
|
|
void * destination,
|
2015-06-24 06:59:57 +03:00
|
|
|
size_t copylen,
|
2006-10-18 00:20:58 +04:00
|
|
|
size_t crclen)
|
2005-11-28 20:20:21 +03:00
|
|
|
{
|
|
|
|
return opal_bcopy_uicrc_partial(source, destination, copylen, crclen, CRC_INITIAL_REGISTER);
|
|
|
|
}
|
|
|
|
|
2015-06-24 06:59:57 +03:00
|
|
|
OPAL_DECLSPEC unsigned int
|
2005-11-28 20:20:21 +03:00
|
|
|
opal_uicrc_partial(
|
2015-06-24 06:59:57 +03:00
|
|
|
const void * source,
|
|
|
|
size_t crclen,
|
2005-11-28 20:20:21 +03:00
|
|
|
unsigned int partial_crc);
|
|
|
|
|
|
|
|
|
2015-06-24 06:59:57 +03:00
|
|
|
static inline unsigned int
|
2006-10-18 00:20:58 +04:00
|
|
|
opal_uicrc(const void * source, size_t crclen)
|
2005-11-28 20:20:21 +03:00
|
|
|
{
|
|
|
|
return opal_uicrc_partial(source, crclen, CRC_INITIAL_REGISTER);
|
|
|
|
}
|
2015-06-24 06:59:57 +03:00
|
|
|
|
2009-08-20 15:42:18 +04:00
|
|
|
END_C_DECLS
|
2006-08-23 04:29:35 +04:00
|
|
|
|
2005-11-28 20:20:21 +03:00
|
|
|
#endif
|
|
|
|
|