Vendor Unique iSCSI CRC32C
258 T10000: Interface Reference Manual August 2016
/* End Linux ONLY */
/*************************/
#endif
void add_crc32c(char *buf, int len);
uint32_t calc_crc32c_sw(char *buf, int len, uint32_t crc);
uint32_t calc_crc32c_sparc(char *buf, int len, uint32_t crc);
uint32_t calc_crc32c_intel(char *buf, int len, uint32_t crc);
int main(int argc, char **argv)
{
char *buf;
const int blksz = 2097152;
int i;
/* allocate 2MB block plus 4 bytes for crc */
buf = (char *)malloc(blksz + 4);
for (i = 0; i < blksz; i++) {
buf[i] = 1;
}
/* calculate data crc and insert crc at end of data */
add_crc32c(buf, blksz);
printf("crc32c: %02x%02x%02x%02x\n",
(uchar_t)buf[blksz],
(uchar_t)buf[blksz+1],
(uchar_t)buf[blksz+2],
(uchar_t)buf[blksz+3]);
}
void add_crc32c(char *buf, int len)
{
/* Where buf is the user data buffer address. Buffer must
contain extra 4 bytes for CRC.*/
/* Where len is the length of the user data in bytes. */
uint32_t crc;
#if defined(__sun__) || defined(__SunOS)
/********************/
/* Solaris ONLY */
/********************/
uint_t ui = 0;
(void) getisax(&ui, 1);
#ifdef __sparc
if (ui & AV_SPARC_CRC32C) {
/* use sparc crc instruction */
crc = calc_crc32c_sparc(buf, len, CRC32C_INIT);
#else
if (ui & AV_386_SSE4_2) {
/* use intel crc instruction */