#ifndef _XFS_CKSUM_H
#define _XFS_CKSUM_H 1

#define XFS_CRC_SEED	(~(__uint32_t)0)

/*
 * Calculate the intermediate checksum for a buffer that has the CRC field
 * inside it.  The offset of the 32bit crc fields is passed as the
 * cksum_offset parameter. We do not modify the buffer during verification,
 * hence we have to split the CRC calculation across the cksum_offset.
 */
static inline __uint32_t
xfs_start_cksum_safe(char *buffer, size_t length, unsigned long cksum_offset)
{
	__uint32_t zero = 0;
	__uint32_t crc;

	/* Calculate CRC up to the checksum. */
	crc = crc32c(XFS_CRC_SEED, buffer, cksum_offset);

	/* Skip checksum field */
	crc = crc32c(crc, &zero, sizeof(__u32));

	/* Calculate the rest of the CRC. */
	return crc32c(crc, &buffer[cksum_offset + sizeof(__be32)],
		      length - (cksum_offset + sizeof(__be32)));
}

/*
 * Fast CRC method where the buffer is modified. Callers must have exclusive
 * access to the buffer while the calculation takes place.
 */
static inline __uint32_t
xfs_start_cksum_update(char *buffer, size_t length, unsigned long cksum_offset)
{
	/* zero the CRC field */
	*(__le32 *)(buffer + cksum_offset) = 0;

	/* single pass CRC calculation for the entire buffer */
	return crc32c(XFS_CRC_SEED, buffer, length);
}

/*
 * Convert the intermediate checksum to the final ondisk format.
 *
 * The CRC32c calculation uses LE format even on BE machines, but returns the
 * result in host endian format. Hence we need to byte swap it back to LE format
 * so that it is consistent on disk.
 */
static inline __le32
xfs_end_cksum(__uint32_t crc)
{
	return ~cpu_to_le32(crc);
}

/*
 * Helper to generate the checksum for a buffer.
 *
 * This modifies the buffer temporarily - callers must have exclusive
 * access to the buffer while the calculation takes place.
 */
static inline void
xfs_update_cksum(char *buffer, size_t length, unsigned long cksum_offset)
{
	__uint32_t crc = xfs_start_cksum_update(buffer, length, cksum_offset);

	*(__le32 *)(buffer + cksum_offset) = xfs_end_cksum(crc);
}

/*
 * Helper to verify the checksum for a buffer.
 */
static inline int
xfs_verify_cksum(char *buffer, size_t length, unsigned long cksum_offset)
{
	__uint32_t crc = xfs_start_cksum_safe(buffer, length, cksum_offset);

	return *(__le32 *)(buffer + cksum_offset) == xfs_end_cksum(crc);
}

#endif /* _XFS_CKSUM_H */
'>committer</option>
<option value='range'>range</option>
</select>
<input class='txt' type='search' size='10' name='q' value=''/>
<input type='submit' value='search'/>
</form>
</td></tr></table>
<div class='path'>path: <a href='/cgit.cgi/linux/net-next.git/diff/?id=396bf4cd835e62d70fad4a03a8963e61f19021f2'>root</a>/<a href='/cgit.cgi/linux/net-next.git/diff/net?id=396bf4cd835e62d70fad4a03a8963e61f19021f2'>net</a>/<a href='/cgit.cgi/linux/net-next.git/diff/net/core?id=396bf4cd835e62d70fad4a03a8963e61f19021f2'>core</a>/<a href='/cgit.cgi/linux/net-next.git/diff/net/core/tso.c?id=396bf4cd835e62d70fad4a03a8963e61f19021f2'>tso.c</a></div><div class='content'><div class='cgit-panel'><b>diff options</b><form method='get'><input type='hidden' name='id' value='396bf4cd835e62d70fad4a03a8963e61f19021f2'/><table><tr><td colspan='2'/></tr><tr><td class='label'>context:</td><td class='ctrl'><select name='context' onchange='this.form.submit();'><option value='1'>1</option><option value='2'>2</option><option value='3' selected='selected'>3</option><option value='4'>4</option><option value='5'>5</option><option value='6'>6</option><option value='7'>7</option><option value='8'>8</option><option value='9'>9</option><option value='10'>10</option><option value='15'>15</option><option value='20'>20</option><option value='25'>25</option><option value='30'>30</option><option value='35'>35</option><option value='40'>40</option></select></td></tr><tr><td class='label'>space:</td><td class='ctrl'><select name='ignorews' onchange='this.form.submit();'><option value='0' selected='selected'>include</option><option value='1'>ignore</option></select></td></tr><tr><td class='label'>mode:</td><td class='ctrl'><select name='dt' onchange='this.form.submit();'><option value='0' selected='selected'>unified</option><option value='1'>ssdiff</option><option value='2'>stat only</option></select></td></tr><tr><td/><td class='ctrl'><noscript><input type='submit' value='reload'/></noscript></td></tr></table></form></div><div class='diffstat-header'><a href='/cgit.cgi/linux/net-next.git/diff/?id=396bf4cd835e62d70fad4a03a8963e61f19021f2'>Diffstat</a> (limited to 'net/core/tso.c')</div><table summary='diffstat' class='diffstat'>