linux/drivers/net/ethernet/sfc/falcon/bitfield.h

/* SPDX-License-Identifier: GPL-2.0-only */
/****************************************************************************
 * Driver for Solarflare network controllers and boards
 * Copyright 2005-2006 Fen Systems Ltd.
 * Copyright 2006-2013 Solarflare Communications Inc.
 */

#ifndef EF4_BITFIELD_H
#define EF4_BITFIELD_H

/*
 * Efx bitfield access
 *
 * Efx NICs make extensive use of bitfields up to 128 bits
 * wide.  Since there is no native 128-bit datatype on most systems,
 * and since 64-bit datatypes are inefficient on 32-bit systems and
 * vice versa, we wrap accesses in a way that uses the most efficient
 * datatype.
 *
 * The NICs are PCI devices and therefore little-endian.  Since most
 * of the quantities that we deal with are DMAed to/from host memory,
 * we define our datatypes (ef4_oword_t, ef4_qword_t and
 * ef4_dword_t) to be little-endian.
 */

/* Lowest bit numbers and widths */
#define EF4_DUMMY_FIELD_LBN
#define EF4_DUMMY_FIELD_WIDTH
#define EF4_WORD_0_LBN
#define EF4_WORD_0_WIDTH
#define EF4_WORD_1_LBN
#define EF4_WORD_1_WIDTH
#define EF4_DWORD_0_LBN
#define EF4_DWORD_0_WIDTH
#define EF4_DWORD_1_LBN
#define EF4_DWORD_1_WIDTH
#define EF4_DWORD_2_LBN
#define EF4_DWORD_2_WIDTH
#define EF4_DWORD_3_LBN
#define EF4_DWORD_3_WIDTH
#define EF4_QWORD_0_LBN
#define EF4_QWORD_0_WIDTH

/* Specified attribute (e.g. LBN) of the specified field */
#define EF4_VAL(field, attribute)
/* Low bit number of the specified field */
#define EF4_LOW_BIT(field)
/* Bit width of the specified field */
#define EF4_WIDTH(field)
/* High bit number of the specified field */
#define EF4_HIGH_BIT(field)
/* Mask equal in width to the specified field.
 *
 * For example, a field with width 5 would have a mask of 0x1f.
 *
 * The maximum width mask that can be generated is 64 bits.
 */
#define EF4_MASK64(width)

/* Mask equal in width to the specified field.
 *
 * For example, a field with width 5 would have a mask of 0x1f.
 *
 * The maximum width mask that can be generated is 32 bits.  Use
 * EF4_MASK64 for higher width fields.
 */
#define EF4_MASK32(width)

/* A doubleword (i.e. 4 byte) datatype - little-endian in HW */
ef4_dword_t;

/* A quadword (i.e. 8 byte) datatype - little-endian in HW */
ef4_qword_t;

/* An octword (eight-word, i.e. 16 byte) datatype - little-endian in HW */
ef4_oword_t;

/* Format string and value expanders for printk */
#define EF4_DWORD_FMT
#define EF4_QWORD_FMT
#define EF4_OWORD_FMT
#define EF4_DWORD_VAL(dword)
#define EF4_QWORD_VAL(qword)
#define EF4_OWORD_VAL(oword)

/*
 * Extract bit field portion [low,high) from the native-endian element
 * which contains bits [min,max).
 *
 * For example, suppose "element" represents the high 32 bits of a
 * 64-bit value, and we wish to extract the bits belonging to the bit
 * field occupying bits 28-45 of this 64-bit value.
 *
 * Then EF4_EXTRACT ( element, 32, 63, 28, 45 ) would give
 *
 *   ( element ) << 4
 *
 * The result will contain the relevant bits filled in the range
 * [0,high-low), with garbage in bits [high-low+1,...).
 */
#define EF4_EXTRACT_NATIVE(native_element, min, max, low, high)

/*
 * Extract bit field portion [low,high) from the 64-bit little-endian
 * element which contains bits [min,max)
 */
#define EF4_EXTRACT64(element, min, max, low, high)

/*
 * Extract bit field portion [low,high) from the 32-bit little-endian
 * element which contains bits [min,max)
 */
#define EF4_EXTRACT32(element, min, max, low, high)

#define EF4_EXTRACT_OWORD64(oword, low, high)

#define EF4_EXTRACT_QWORD64(qword, low, high)

#define EF4_EXTRACT_OWORD32(oword, low, high)

#define EF4_EXTRACT_QWORD32(qword, low, high)

#define EF4_EXTRACT_DWORD(dword, low, high)

#define EF4_OWORD_FIELD64(oword, field)

#define EF4_QWORD_FIELD64(qword, field)

#define EF4_OWORD_FIELD32(oword, field)

#define EF4_QWORD_FIELD32(qword, field)

#define EF4_DWORD_FIELD(dword, field)

#define EF4_OWORD_IS_ZERO64(oword)

#define EF4_QWORD_IS_ZERO64(qword)

#define EF4_OWORD_IS_ZERO32(oword)

#define EF4_QWORD_IS_ZERO32(qword)

#define EF4_DWORD_IS_ZERO(dword)

#define EF4_OWORD_IS_ALL_ONES64(oword)

#define EF4_QWORD_IS_ALL_ONES64(qword)

#define EF4_OWORD_IS_ALL_ONES32(oword)

#define EF4_QWORD_IS_ALL_ONES32(qword)

#define EF4_DWORD_IS_ALL_ONES(dword)

#if BITS_PER_LONG == 64
#define EF4_OWORD_FIELD
#define EF4_QWORD_FIELD
#define EF4_OWORD_IS_ZERO
#define EF4_QWORD_IS_ZERO
#define EF4_OWORD_IS_ALL_ONES
#define EF4_QWORD_IS_ALL_ONES
#else
#define EF4_OWORD_FIELD
#define EF4_QWORD_FIELD
#define EF4_OWORD_IS_ZERO
#define EF4_QWORD_IS_ZERO
#define EF4_OWORD_IS_ALL_ONES
#define EF4_QWORD_IS_ALL_ONES
#endif

/*
 * Construct bit field portion
 *
 * Creates the portion of the bit field [low,high) that lies within
 * the range [min,max).
 */
#define EF4_INSERT_NATIVE64(min, max, low, high, value)

#define EF4_INSERT_NATIVE32(min, max, low, high, value)

#define EF4_INSERT_NATIVE(min, max, low, high, value)

/*
 * Construct bit field portion
 *
 * Creates the portion of the named bit field that lies within the
 * range [min,max).
 */
#define EF4_INSERT_FIELD_NATIVE(min, max, field, value)

/*
 * Construct bit field
 *
 * Creates the portion of the named bit fields that lie within the
 * range [min,max).
 */
#define EF4_INSERT_FIELDS_NATIVE(min, max,				\
				 field1, value1,			\
				 field2, value2,			\
				 field3, value3,			\
				 field4, value4,			\
				 field5, value5,			\
				 field6, value6,			\
				 field7, value7,			\
				 field8, value8,			\
				 field9, value9,			\
				 field10, value10)

#define EF4_INSERT_FIELDS64(...)

#define EF4_INSERT_FIELDS32(...)

#define EF4_POPULATE_OWORD64(oword, ...)

#define EF4_POPULATE_QWORD64(qword, ...)

#define EF4_POPULATE_OWORD32(oword, ...)

#define EF4_POPULATE_QWORD32(qword, ...)

#define EF4_POPULATE_DWORD(dword, ...)

#if BITS_PER_LONG == 64
#define EF4_POPULATE_OWORD
#define EF4_POPULATE_QWORD
#else
#define EF4_POPULATE_OWORD
#define EF4_POPULATE_QWORD
#endif

/* Populate an octword field with various numbers of arguments */
#define EF4_POPULATE_OWORD_10
#define EF4_POPULATE_OWORD_9(oword, ...)
#define EF4_POPULATE_OWORD_8(oword, ...)
#define EF4_POPULATE_OWORD_7(oword, ...)
#define EF4_POPULATE_OWORD_6(oword, ...)
#define EF4_POPULATE_OWORD_5(oword, ...)
#define EF4_POPULATE_OWORD_4(oword, ...)
#define EF4_POPULATE_OWORD_3(oword, ...)
#define EF4_POPULATE_OWORD_2(oword, ...)
#define EF4_POPULATE_OWORD_1(oword, ...)
#define EF4_ZERO_OWORD(oword)
#define EF4_SET_OWORD(oword)

/* Populate a quadword field with various numbers of arguments */
#define EF4_POPULATE_QWORD_10
#define EF4_POPULATE_QWORD_9(qword, ...)
#define EF4_POPULATE_QWORD_8(qword, ...)
#define EF4_POPULATE_QWORD_7(qword, ...)
#define EF4_POPULATE_QWORD_6(qword, ...)
#define EF4_POPULATE_QWORD_5(qword, ...)
#define EF4_POPULATE_QWORD_4(qword, ...)
#define EF4_POPULATE_QWORD_3(qword, ...)
#define EF4_POPULATE_QWORD_2(qword, ...)
#define EF4_POPULATE_QWORD_1(qword, ...)
#define EF4_ZERO_QWORD(qword)
#define EF4_SET_QWORD(qword)

/* Populate a dword field with various numbers of arguments */
#define EF4_POPULATE_DWORD_10
#define EF4_POPULATE_DWORD_9(dword, ...)
#define EF4_POPULATE_DWORD_8(dword, ...)
#define EF4_POPULATE_DWORD_7(dword, ...)
#define EF4_POPULATE_DWORD_6(dword, ...)
#define EF4_POPULATE_DWORD_5(dword, ...)
#define EF4_POPULATE_DWORD_4(dword, ...)
#define EF4_POPULATE_DWORD_3(dword, ...)
#define EF4_POPULATE_DWORD_2(dword, ...)
#define EF4_POPULATE_DWORD_1(dword, ...)
#define EF4_ZERO_DWORD(dword)
#define EF4_SET_DWORD(dword)

/*
 * Modify a named field within an already-populated structure.  Used
 * for read-modify-write operations.
 *
 */
#define EF4_INVERT_OWORD(oword)

#define EF4_AND_OWORD(oword, from, mask)

#define EF4_OR_OWORD(oword, from, mask)

#define EF4_INSERT64(min, max, low, high, value)

#define EF4_INSERT32(min, max, low, high, value)

#define EF4_INPLACE_MASK64(min, max, low, high)

#define EF4_INPLACE_MASK32(min, max, low, high)

#define EF4_SET_OWORD64(oword, low, high, value)

#define EF4_SET_QWORD64(qword, low, high, value)

#define EF4_SET_OWORD32(oword, low, high, value)

#define EF4_SET_QWORD32(qword, low, high, value)

#define EF4_SET_DWORD32(dword, low, high, value)

#define EF4_SET_OWORD_FIELD64(oword, field, value)

#define EF4_SET_QWORD_FIELD64(qword, field, value)

#define EF4_SET_OWORD_FIELD32(oword, field, value)

#define EF4_SET_QWORD_FIELD32(qword, field, value)

#define EF4_SET_DWORD_FIELD(dword, field, value)



#if BITS_PER_LONG == 64
#define EF4_SET_OWORD_FIELD
#define EF4_SET_QWORD_FIELD
#else
#define EF4_SET_OWORD_FIELD
#define EF4_SET_QWORD_FIELD
#endif

/* Used to avoid compiler warnings about shift range exceeding width
 * of the data types when dma_addr_t is only 32 bits wide.
 */
#define DMA_ADDR_T_WIDTH
#define EF4_DMA_TYPE_WIDTH(width)


/* Static initialiser */
#define EF4_OWORD32(a, b, c, d)

#endif /* EF4_BITFIELD_H */