File: fletcher.h

package info (click to toggle)
ndctl 81-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 3,436 kB
  • sloc: ansic: 41,432; sh: 3,931; makefile: 28
file content (26 lines) | stat: -rw-r--r-- 539 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#ifndef _NDCTL_FLETCHER_H_
#define _NDCTL_FLETCHER_H_

#include <stdbool.h>
#include <ccan/endian/endian.h>
#include <ccan/short_types/short_types.h>

/*
 * Note, fletcher64() is copied from drivers/nvdimm/label.c in the Linux kernel
 */
static inline u64 fletcher64(void *addr, size_t len, bool le)
{
	u32 *buf = addr;
	u32 lo32 = 0;
	u64 hi32 = 0;
	size_t i;

	for (i = 0; i < len / sizeof(u32); i++) {
		lo32 += le ? le32_to_cpu((le32) buf[i]) : buf[i];
		hi32 += lo32;
	}

	return hi32 << 32 | lo32;
}

#endif /* _NDCTL_FLETCHER_H_ */