Lines Matching +full:high +full:- +full:to +full:- +full:low

1 /* SPDX-License-Identifier: GPL-2.0-only */
4 * Copyright 2005-2006 Fen Systems Ltd.
5 * Copyright 2006-2013 Solarflare Communications Inc.
14 * Efx NICs make extensive use of bitfields up to 128 bits
15 * wide. Since there is no native 128-bit datatype on most systems,
16 * and since 64-bit datatypes are inefficient on 32-bit systems and
20 * The NICs are PCI devices and therefore little-endian. Since most
21 * of the quantities that we deal with are DMAed to/from host memory,
23 * efx_dword_t) to be little-endian.
48 /* Low bit number of the specified field */
52 /* High bit number of the specified field */
53 #define EFX_HIGH_BIT(field) (EFX_LOW_BIT(field) + EFX_WIDTH(field) - 1)
54 /* Mask equal in width to the specified field.
62 (((((u64) 1) << (width))) - 1))
64 /* Mask equal in width to the specified field.
73 (((((u32) 1) << (width))) - 1))
75 /* A doubleword (i.e. 4 byte) datatype - little-endian in HW */
80 /* A quadword (i.e. 8 byte) datatype - little-endian in HW */
87 /* An octword (eight-word, i.e. 16 byte) datatype - little-endian in HW */
111 * Extract bit field portion [low,high) from the native-endian element
114 * For example, suppose "element" represents the high 32 bits of a
115 * 64-bit value, and we wish to extract the bits belonging to the bit
116 * field occupying bits 28-45 of this 64-bit value.
123 * [0,high-low), with garbage in bits [high-low+1,...).
125 #define EFX_EXTRACT_NATIVE(native_element, min, max, low, high) \ argument
126 ((low) > (max) || (high) < (min) ? 0 : \
127 (low) > (min) ? \
128 (native_element) >> ((low) - (min)) : \
129 (native_element) << ((min) - (low)))
132 * Extract bit field portion [low,high) from the 64-bit little-endian
135 #define EFX_EXTRACT64(element, min, max, low, high) \ argument
136 EFX_EXTRACT_NATIVE(le64_to_cpu(element), min, max, low, high)
139 * Extract bit field portion [low,high) from the 32-bit little-endian
142 #define EFX_EXTRACT32(element, min, max, low, high) \ argument
143 EFX_EXTRACT_NATIVE(le32_to_cpu(element), min, max, low, high)
145 #define EFX_EXTRACT_OWORD64(oword, low, high) \ argument
146 ((EFX_EXTRACT64((oword).u64[0], 0, 63, low, high) | \
147 EFX_EXTRACT64((oword).u64[1], 64, 127, low, high)) & \
148 EFX_MASK64((high) + 1 - (low)))
150 #define EFX_EXTRACT_QWORD64(qword, low, high) \ argument
151 (EFX_EXTRACT64((qword).u64[0], 0, 63, low, high) & \
152 EFX_MASK64((high) + 1 - (low)))
154 #define EFX_EXTRACT_OWORD32(oword, low, high) \ argument
155 ((EFX_EXTRACT32((oword).u32[0], 0, 31, low, high) | \
156 EFX_EXTRACT32((oword).u32[1], 32, 63, low, high) | \
157 EFX_EXTRACT32((oword).u32[2], 64, 95, low, high) | \
158 EFX_EXTRACT32((oword).u32[3], 96, 127, low, high)) & \
159 EFX_MASK32((high) + 1 - (low)))
161 #define EFX_EXTRACT_QWORD32(qword, low, high) \ argument
162 ((EFX_EXTRACT32((qword).u32[0], 0, 31, low, high) | \
163 EFX_EXTRACT32((qword).u32[1], 32, 63, low, high)) & \
164 EFX_MASK32((high) + 1 - (low)))
166 #define EFX_EXTRACT_DWORD(dword, low, high) \ argument
167 (EFX_EXTRACT32((dword).u32[0], 0, 31, low, high) & \
168 EFX_MASK32((high) + 1 - (low)))
241 * Creates the portion of the bit field [low,high) that lies within
244 #define EFX_INSERT_NATIVE64(min, max, low, high, value) \ argument
245 (((low > max) || (high < min)) ? 0 : \
246 ((low > min) ? \
247 (((u64) (value)) << (low - min)) : \
248 (((u64) (value)) >> (min - low))))
250 #define EFX_INSERT_NATIVE32(min, max, low, high, value) \ argument
251 (((low > max) || (high < min)) ? 0 : \
252 ((low > min) ? \
253 (((u32) (value)) << (low - min)) : \
254 (((u32) (value)) >> (min - low))))
256 #define EFX_INSERT_NATIVE(min, max, low, high, value) \ argument
257 ((((max - min) >= 32) || ((high - low) >= 32)) ? \
258 EFX_INSERT_NATIVE64(min, max, low, high, value) : \
259 EFX_INSERT_NATIVE32(min, max, low, high, value))
492 * Modify a named field within an already-populated structure. Used
493 * for read-modify-write operations.
516 #define EFX_INSERT64(min, max, low, high, value) \ argument
517 cpu_to_le64(EFX_INSERT_NATIVE(min, max, low, high, value))
519 #define EFX_INSERT32(min, max, low, high, value) \ argument
520 cpu_to_le32(EFX_INSERT_NATIVE(min, max, low, high, value))
522 #define EFX_INPLACE_MASK64(min, max, low, high) \ argument
523 EFX_INSERT64(min, max, low, high, EFX_MASK64((high) + 1 - (low)))
525 #define EFX_INPLACE_MASK32(min, max, low, high) \ argument
526 EFX_INSERT32(min, max, low, high, EFX_MASK32((high) + 1 - (low)))
528 #define EFX_SET_OWORD64(oword, low, high, value) do { \ argument
530 & ~EFX_INPLACE_MASK64(0, 63, low, high)) \
531 | EFX_INSERT64(0, 63, low, high, value)); \
533 & ~EFX_INPLACE_MASK64(64, 127, low, high)) \
534 | EFX_INSERT64(64, 127, low, high, value)); \
537 #define EFX_SET_QWORD64(qword, low, high, value) do { \ argument
539 & ~EFX_INPLACE_MASK64(0, 63, low, high)) \
540 | EFX_INSERT64(0, 63, low, high, value)); \
543 #define EFX_SET_OWORD32(oword, low, high, value) do { \ argument
545 & ~EFX_INPLACE_MASK32(0, 31, low, high)) \
546 | EFX_INSERT32(0, 31, low, high, value)); \
548 & ~EFX_INPLACE_MASK32(32, 63, low, high)) \
549 | EFX_INSERT32(32, 63, low, high, value)); \
551 & ~EFX_INPLACE_MASK32(64, 95, low, high)) \
552 | EFX_INSERT32(64, 95, low, high, value)); \
554 & ~EFX_INPLACE_MASK32(96, 127, low, high)) \
555 | EFX_INSERT32(96, 127, low, high, value)); \
558 #define EFX_SET_QWORD32(qword, low, high, value) do { \ argument
560 & ~EFX_INPLACE_MASK32(0, 31, low, high)) \
561 | EFX_INSERT32(0, 31, low, high, value)); \
563 & ~EFX_INPLACE_MASK32(32, 63, low, high)) \
564 | EFX_INSERT32(32, 63, low, high, value)); \
567 #define EFX_SET_DWORD32(dword, low, high, value) do { \ argument
569 & ~EFX_INPLACE_MASK32(0, 31, low, high)) \
570 | EFX_INSERT32(0, 31, low, high, value)); \
603 /* Used to avoid compiler warnings about shift range exceeding width