1 /****************************************************************************
2 * Driver for Solarflare network controllers and boards
3 * Copyright 2005-2006 Fen Systems Ltd.
4 * Copyright 2006-2013 Solarflare Communications Inc.
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published
8 * by the Free Software Foundation, incorporated herein by reference.
11 #ifndef EFX_BITFIELD_H
12 #define EFX_BITFIELD_H
17 * Efx NICs make extensive use of bitfields up to 128 bits
18 * wide. Since there is no native 128-bit datatype on most systems,
19 * and since 64-bit datatypes are inefficient on 32-bit systems and
20 * vice versa, we wrap accesses in a way that uses the most efficient
23 * The NICs are PCI devices and therefore little-endian. Since most
24 * of the quantities that we deal with are DMAed to/from host memory,
25 * we define our datatypes (efx_oword_t, efx_qword_t and
26 * efx_dword_t) to be little-endian.
29 /* Lowest bit numbers and widths */
30 #define EFX_DUMMY_FIELD_LBN 0
31 #define EFX_DUMMY_FIELD_WIDTH 0
32 #define EFX_WORD_0_LBN 0
33 #define EFX_WORD_0_WIDTH 16
34 #define EFX_WORD_1_LBN 16
35 #define EFX_WORD_1_WIDTH 16
36 #define EFX_DWORD_0_LBN 0
37 #define EFX_DWORD_0_WIDTH 32
38 #define EFX_DWORD_1_LBN 32
39 #define EFX_DWORD_1_WIDTH 32
40 #define EFX_DWORD_2_LBN 64
41 #define EFX_DWORD_2_WIDTH 32
42 #define EFX_DWORD_3_LBN 96
43 #define EFX_DWORD_3_WIDTH 32
44 #define EFX_QWORD_0_LBN 0
45 #define EFX_QWORD_0_WIDTH 64
47 /* Specified attribute (e.g. LBN) of the specified field */
48 #define EFX_VAL(field, attribute) field ## _ ## attribute
49 /* Low bit number of the specified field */
50 #define EFX_LOW_BIT(field) EFX_VAL(field, LBN)
51 /* Bit width of the specified field */
52 #define EFX_WIDTH(field) EFX_VAL(field, WIDTH)
53 /* High bit number of the specified field */
54 #define EFX_HIGH_BIT(field) (EFX_LOW_BIT(field) + EFX_WIDTH(field) - 1)
55 /* Mask equal in width to the specified field.
57 * For example, a field with width 5 would have a mask of 0x1f.
59 * The maximum width mask that can be generated is 64 bits.
61 #define EFX_MASK64(width) \
62 ((width) == 64 ? ~((u64) 0) : \
63 (((((u64) 1) << (width))) - 1))
65 /* Mask equal in width to the specified field.
67 * For example, a field with width 5 would have a mask of 0x1f.
69 * The maximum width mask that can be generated is 32 bits. Use
70 * EFX_MASK64 for higher width fields.
72 #define EFX_MASK32(width) \
73 ((width) == 32 ? ~((u32) 0) : \
74 (((((u32) 1) << (width))) - 1))
76 /* A doubleword (i.e. 4 byte) datatype - little-endian in HW */
77 typedef union efx_dword
{
81 /* A quadword (i.e. 8 byte) datatype - little-endian in HW */
82 typedef union efx_qword
{
88 /* An octword (eight-word, i.e. 16 byte) datatype - little-endian in HW */
89 typedef union efx_oword
{
96 /* Format string and value expanders for printk */
97 #define EFX_DWORD_FMT "%08x"
98 #define EFX_QWORD_FMT "%08x:%08x"
99 #define EFX_OWORD_FMT "%08x:%08x:%08x:%08x"
100 #define EFX_DWORD_VAL(dword) \
101 ((unsigned int) le32_to_cpu((dword).u32[0]))
102 #define EFX_QWORD_VAL(qword) \
103 ((unsigned int) le32_to_cpu((qword).u32[1])), \
104 ((unsigned int) le32_to_cpu((qword).u32[0]))
105 #define EFX_OWORD_VAL(oword) \
106 ((unsigned int) le32_to_cpu((oword).u32[3])), \
107 ((unsigned int) le32_to_cpu((oword).u32[2])), \
108 ((unsigned int) le32_to_cpu((oword).u32[1])), \
109 ((unsigned int) le32_to_cpu((oword).u32[0]))
112 * Extract bit field portion [low,high) from the native-endian element
113 * which contains bits [min,max).
115 * For example, suppose "element" represents the high 32 bits of a
116 * 64-bit value, and we wish to extract the bits belonging to the bit
117 * field occupying bits 28-45 of this 64-bit value.
119 * Then EFX_EXTRACT ( element, 32, 63, 28, 45 ) would give
123 * The result will contain the relevant bits filled in in the range
124 * [0,high-low), with garbage in bits [high-low+1,...).
126 #define EFX_EXTRACT_NATIVE(native_element, min, max, low, high) \
127 ((low) > (max) || (high) < (min) ? 0 : \
129 (native_element) >> ((low) - (min)) : \
130 (native_element) << ((min) - (low)))
133 * Extract bit field portion [low,high) from the 64-bit little-endian
134 * element which contains bits [min,max)
136 #define EFX_EXTRACT64(element, min, max, low, high) \
137 EFX_EXTRACT_NATIVE(le64_to_cpu(element), min, max, low, high)
140 * Extract bit field portion [low,high) from the 32-bit little-endian
141 * element which contains bits [min,max)
143 #define EFX_EXTRACT32(element, min, max, low, high) \
144 EFX_EXTRACT_NATIVE(le32_to_cpu(element), min, max, low, high)
146 #define EFX_EXTRACT_OWORD64(oword, low, high) \
147 ((EFX_EXTRACT64((oword).u64[0], 0, 63, low, high) | \
148 EFX_EXTRACT64((oword).u64[1], 64, 127, low, high)) & \
149 EFX_MASK64((high) + 1 - (low)))
151 #define EFX_EXTRACT_QWORD64(qword, low, high) \
152 (EFX_EXTRACT64((qword).u64[0], 0, 63, low, high) & \
153 EFX_MASK64((high) + 1 - (low)))
155 #define EFX_EXTRACT_OWORD32(oword, low, high) \
156 ((EFX_EXTRACT32((oword).u32[0], 0, 31, low, high) | \
157 EFX_EXTRACT32((oword).u32[1], 32, 63, low, high) | \
158 EFX_EXTRACT32((oword).u32[2], 64, 95, low, high) | \
159 EFX_EXTRACT32((oword).u32[3], 96, 127, low, high)) & \
160 EFX_MASK32((high) + 1 - (low)))
162 #define EFX_EXTRACT_QWORD32(qword, low, high) \
163 ((EFX_EXTRACT32((qword).u32[0], 0, 31, low, high) | \
164 EFX_EXTRACT32((qword).u32[1], 32, 63, low, high)) & \
165 EFX_MASK32((high) + 1 - (low)))
167 #define EFX_EXTRACT_DWORD(dword, low, high) \
168 (EFX_EXTRACT32((dword).u32[0], 0, 31, low, high) & \
169 EFX_MASK32((high) + 1 - (low)))
171 #define EFX_OWORD_FIELD64(oword, field) \
172 EFX_EXTRACT_OWORD64(oword, EFX_LOW_BIT(field), \
175 #define EFX_QWORD_FIELD64(qword, field) \
176 EFX_EXTRACT_QWORD64(qword, EFX_LOW_BIT(field), \
179 #define EFX_OWORD_FIELD32(oword, field) \
180 EFX_EXTRACT_OWORD32(oword, EFX_LOW_BIT(field), \
183 #define EFX_QWORD_FIELD32(qword, field) \
184 EFX_EXTRACT_QWORD32(qword, EFX_LOW_BIT(field), \
187 #define EFX_DWORD_FIELD(dword, field) \
188 EFX_EXTRACT_DWORD(dword, EFX_LOW_BIT(field), \
191 #define EFX_OWORD_IS_ZERO64(oword) \
192 (((oword).u64[0] | (oword).u64[1]) == (__force __le64) 0)
194 #define EFX_QWORD_IS_ZERO64(qword) \
195 (((qword).u64[0]) == (__force __le64) 0)
197 #define EFX_OWORD_IS_ZERO32(oword) \
198 (((oword).u32[0] | (oword).u32[1] | (oword).u32[2] | (oword).u32[3]) \
199 == (__force __le32) 0)
201 #define EFX_QWORD_IS_ZERO32(qword) \
202 (((qword).u32[0] | (qword).u32[1]) == (__force __le32) 0)
204 #define EFX_DWORD_IS_ZERO(dword) \
205 (((dword).u32[0]) == (__force __le32) 0)
207 #define EFX_OWORD_IS_ALL_ONES64(oword) \
208 (((oword).u64[0] & (oword).u64[1]) == ~((__force __le64) 0))
210 #define EFX_QWORD_IS_ALL_ONES64(qword) \
211 ((qword).u64[0] == ~((__force __le64) 0))
213 #define EFX_OWORD_IS_ALL_ONES32(oword) \
214 (((oword).u32[0] & (oword).u32[1] & (oword).u32[2] & (oword).u32[3]) \
215 == ~((__force __le32) 0))
217 #define EFX_QWORD_IS_ALL_ONES32(qword) \
218 (((qword).u32[0] & (qword).u32[1]) == ~((__force __le32) 0))
220 #define EFX_DWORD_IS_ALL_ONES(dword) \
221 ((dword).u32[0] == ~((__force __le32) 0))
223 #if BITS_PER_LONG == 64
224 #define EFX_OWORD_FIELD EFX_OWORD_FIELD64
225 #define EFX_QWORD_FIELD EFX_QWORD_FIELD64
226 #define EFX_OWORD_IS_ZERO EFX_OWORD_IS_ZERO64
227 #define EFX_QWORD_IS_ZERO EFX_QWORD_IS_ZERO64
228 #define EFX_OWORD_IS_ALL_ONES EFX_OWORD_IS_ALL_ONES64
229 #define EFX_QWORD_IS_ALL_ONES EFX_QWORD_IS_ALL_ONES64
231 #define EFX_OWORD_FIELD EFX_OWORD_FIELD32
232 #define EFX_QWORD_FIELD EFX_QWORD_FIELD32
233 #define EFX_OWORD_IS_ZERO EFX_OWORD_IS_ZERO32
234 #define EFX_QWORD_IS_ZERO EFX_QWORD_IS_ZERO32
235 #define EFX_OWORD_IS_ALL_ONES EFX_OWORD_IS_ALL_ONES32
236 #define EFX_QWORD_IS_ALL_ONES EFX_QWORD_IS_ALL_ONES32
240 * Construct bit field portion
242 * Creates the portion of the bit field [low,high) that lies within
243 * the range [min,max).
245 #define EFX_INSERT_NATIVE64(min, max, low, high, value) \
246 (((low > max) || (high < min)) ? 0 : \
248 (((u64) (value)) << (low - min)) : \
249 (((u64) (value)) >> (min - low))))
251 #define EFX_INSERT_NATIVE32(min, max, low, high, value) \
252 (((low > max) || (high < min)) ? 0 : \
254 (((u32) (value)) << (low - min)) : \
255 (((u32) (value)) >> (min - low))))
257 #define EFX_INSERT_NATIVE(min, max, low, high, value) \
258 ((((max - min) >= 32) || ((high - low) >= 32)) ? \
259 EFX_INSERT_NATIVE64(min, max, low, high, value) : \
260 EFX_INSERT_NATIVE32(min, max, low, high, value))
263 * Construct bit field portion
265 * Creates the portion of the named bit field that lies within the
268 #define EFX_INSERT_FIELD_NATIVE(min, max, field, value) \
269 EFX_INSERT_NATIVE(min, max, EFX_LOW_BIT(field), \
270 EFX_HIGH_BIT(field), value)
273 * Construct bit field
275 * Creates the portion of the named bit fields that lie within the
278 #define EFX_INSERT_FIELDS_NATIVE(min, max, \
289 (EFX_INSERT_FIELD_NATIVE((min), (max), field1, (value1)) | \
290 EFX_INSERT_FIELD_NATIVE((min), (max), field2, (value2)) | \
291 EFX_INSERT_FIELD_NATIVE((min), (max), field3, (value3)) | \
292 EFX_INSERT_FIELD_NATIVE((min), (max), field4, (value4)) | \
293 EFX_INSERT_FIELD_NATIVE((min), (max), field5, (value5)) | \
294 EFX_INSERT_FIELD_NATIVE((min), (max), field6, (value6)) | \
295 EFX_INSERT_FIELD_NATIVE((min), (max), field7, (value7)) | \
296 EFX_INSERT_FIELD_NATIVE((min), (max), field8, (value8)) | \
297 EFX_INSERT_FIELD_NATIVE((min), (max), field9, (value9)) | \
298 EFX_INSERT_FIELD_NATIVE((min), (max), field10, (value10)))
300 #define EFX_INSERT_FIELDS64(...) \
301 cpu_to_le64(EFX_INSERT_FIELDS_NATIVE(__VA_ARGS__))
303 #define EFX_INSERT_FIELDS32(...) \
304 cpu_to_le32(EFX_INSERT_FIELDS_NATIVE(__VA_ARGS__))
306 #define EFX_POPULATE_OWORD64(oword, ...) do { \
307 (oword).u64[0] = EFX_INSERT_FIELDS64(0, 63, __VA_ARGS__); \
308 (oword).u64[1] = EFX_INSERT_FIELDS64(64, 127, __VA_ARGS__); \
311 #define EFX_POPULATE_QWORD64(qword, ...) do { \
312 (qword).u64[0] = EFX_INSERT_FIELDS64(0, 63, __VA_ARGS__); \
315 #define EFX_POPULATE_OWORD32(oword, ...) do { \
316 (oword).u32[0] = EFX_INSERT_FIELDS32(0, 31, __VA_ARGS__); \
317 (oword).u32[1] = EFX_INSERT_FIELDS32(32, 63, __VA_ARGS__); \
318 (oword).u32[2] = EFX_INSERT_FIELDS32(64, 95, __VA_ARGS__); \
319 (oword).u32[3] = EFX_INSERT_FIELDS32(96, 127, __VA_ARGS__); \
322 #define EFX_POPULATE_QWORD32(qword, ...) do { \
323 (qword).u32[0] = EFX_INSERT_FIELDS32(0, 31, __VA_ARGS__); \
324 (qword).u32[1] = EFX_INSERT_FIELDS32(32, 63, __VA_ARGS__); \
327 #define EFX_POPULATE_DWORD(dword, ...) do { \
328 (dword).u32[0] = EFX_INSERT_FIELDS32(0, 31, __VA_ARGS__); \
331 #if BITS_PER_LONG == 64
332 #define EFX_POPULATE_OWORD EFX_POPULATE_OWORD64
333 #define EFX_POPULATE_QWORD EFX_POPULATE_QWORD64
335 #define EFX_POPULATE_OWORD EFX_POPULATE_OWORD32
336 #define EFX_POPULATE_QWORD EFX_POPULATE_QWORD32
339 /* Populate an octword field with various numbers of arguments */
340 #define EFX_POPULATE_OWORD_10 EFX_POPULATE_OWORD
341 #define EFX_POPULATE_OWORD_9(oword, ...) \
342 EFX_POPULATE_OWORD_10(oword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
343 #define EFX_POPULATE_OWORD_8(oword, ...) \
344 EFX_POPULATE_OWORD_9(oword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
345 #define EFX_POPULATE_OWORD_7(oword, ...) \
346 EFX_POPULATE_OWORD_8(oword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
347 #define EFX_POPULATE_OWORD_6(oword, ...) \
348 EFX_POPULATE_OWORD_7(oword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
349 #define EFX_POPULATE_OWORD_5(oword, ...) \
350 EFX_POPULATE_OWORD_6(oword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
351 #define EFX_POPULATE_OWORD_4(oword, ...) \
352 EFX_POPULATE_OWORD_5(oword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
353 #define EFX_POPULATE_OWORD_3(oword, ...) \
354 EFX_POPULATE_OWORD_4(oword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
355 #define EFX_POPULATE_OWORD_2(oword, ...) \
356 EFX_POPULATE_OWORD_3(oword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
357 #define EFX_POPULATE_OWORD_1(oword, ...) \
358 EFX_POPULATE_OWORD_2(oword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
359 #define EFX_ZERO_OWORD(oword) \
360 EFX_POPULATE_OWORD_1(oword, EFX_DUMMY_FIELD, 0)
361 #define EFX_SET_OWORD(oword) \
362 EFX_POPULATE_OWORD_4(oword, \
363 EFX_DWORD_0, 0xffffffff, \
364 EFX_DWORD_1, 0xffffffff, \
365 EFX_DWORD_2, 0xffffffff, \
366 EFX_DWORD_3, 0xffffffff)
368 /* Populate a quadword field with various numbers of arguments */
369 #define EFX_POPULATE_QWORD_10 EFX_POPULATE_QWORD
370 #define EFX_POPULATE_QWORD_9(qword, ...) \
371 EFX_POPULATE_QWORD_10(qword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
372 #define EFX_POPULATE_QWORD_8(qword, ...) \
373 EFX_POPULATE_QWORD_9(qword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
374 #define EFX_POPULATE_QWORD_7(qword, ...) \
375 EFX_POPULATE_QWORD_8(qword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
376 #define EFX_POPULATE_QWORD_6(qword, ...) \
377 EFX_POPULATE_QWORD_7(qword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
378 #define EFX_POPULATE_QWORD_5(qword, ...) \
379 EFX_POPULATE_QWORD_6(qword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
380 #define EFX_POPULATE_QWORD_4(qword, ...) \
381 EFX_POPULATE_QWORD_5(qword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
382 #define EFX_POPULATE_QWORD_3(qword, ...) \
383 EFX_POPULATE_QWORD_4(qword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
384 #define EFX_POPULATE_QWORD_2(qword, ...) \
385 EFX_POPULATE_QWORD_3(qword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
386 #define EFX_POPULATE_QWORD_1(qword, ...) \
387 EFX_POPULATE_QWORD_2(qword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
388 #define EFX_ZERO_QWORD(qword) \
389 EFX_POPULATE_QWORD_1(qword, EFX_DUMMY_FIELD, 0)
390 #define EFX_SET_QWORD(qword) \
391 EFX_POPULATE_QWORD_2(qword, \
392 EFX_DWORD_0, 0xffffffff, \
393 EFX_DWORD_1, 0xffffffff)
395 /* Populate a dword field with various numbers of arguments */
396 #define EFX_POPULATE_DWORD_10 EFX_POPULATE_DWORD
397 #define EFX_POPULATE_DWORD_9(dword, ...) \
398 EFX_POPULATE_DWORD_10(dword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
399 #define EFX_POPULATE_DWORD_8(dword, ...) \
400 EFX_POPULATE_DWORD_9(dword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
401 #define EFX_POPULATE_DWORD_7(dword, ...) \
402 EFX_POPULATE_DWORD_8(dword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
403 #define EFX_POPULATE_DWORD_6(dword, ...) \
404 EFX_POPULATE_DWORD_7(dword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
405 #define EFX_POPULATE_DWORD_5(dword, ...) \
406 EFX_POPULATE_DWORD_6(dword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
407 #define EFX_POPULATE_DWORD_4(dword, ...) \
408 EFX_POPULATE_DWORD_5(dword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
409 #define EFX_POPULATE_DWORD_3(dword, ...) \
410 EFX_POPULATE_DWORD_4(dword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
411 #define EFX_POPULATE_DWORD_2(dword, ...) \
412 EFX_POPULATE_DWORD_3(dword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
413 #define EFX_POPULATE_DWORD_1(dword, ...) \
414 EFX_POPULATE_DWORD_2(dword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
415 #define EFX_ZERO_DWORD(dword) \
416 EFX_POPULATE_DWORD_1(dword, EFX_DUMMY_FIELD, 0)
417 #define EFX_SET_DWORD(dword) \
418 EFX_POPULATE_DWORD_1(dword, EFX_DWORD_0, 0xffffffff)
421 * Modify a named field within an already-populated structure. Used
422 * for read-modify-write operations.
425 #define EFX_INVERT_OWORD(oword) do { \
426 (oword).u64[0] = ~((oword).u64[0]); \
427 (oword).u64[1] = ~((oword).u64[1]); \
430 #define EFX_AND_OWORD(oword, from, mask) \
432 (oword).u64[0] = (from).u64[0] & (mask).u64[0]; \
433 (oword).u64[1] = (from).u64[1] & (mask).u64[1]; \
436 #define EFX_AND_QWORD(qword, from, mask) \
437 (qword).u64[0] = (from).u64[0] & (mask).u64[0]
439 #define EFX_OR_OWORD(oword, from, mask) \
441 (oword).u64[0] = (from).u64[0] | (mask).u64[0]; \
442 (oword).u64[1] = (from).u64[1] | (mask).u64[1]; \
445 #define EFX_INSERT64(min, max, low, high, value) \
446 cpu_to_le64(EFX_INSERT_NATIVE(min, max, low, high, value))
448 #define EFX_INSERT32(min, max, low, high, value) \
449 cpu_to_le32(EFX_INSERT_NATIVE(min, max, low, high, value))
451 #define EFX_INPLACE_MASK64(min, max, low, high) \
452 EFX_INSERT64(min, max, low, high, EFX_MASK64((high) + 1 - (low)))
454 #define EFX_INPLACE_MASK32(min, max, low, high) \
455 EFX_INSERT32(min, max, low, high, EFX_MASK32((high) + 1 - (low)))
457 #define EFX_SET_OWORD64(oword, low, high, value) do { \
458 (oword).u64[0] = (((oword).u64[0] \
459 & ~EFX_INPLACE_MASK64(0, 63, low, high)) \
460 | EFX_INSERT64(0, 63, low, high, value)); \
461 (oword).u64[1] = (((oword).u64[1] \
462 & ~EFX_INPLACE_MASK64(64, 127, low, high)) \
463 | EFX_INSERT64(64, 127, low, high, value)); \
466 #define EFX_SET_QWORD64(qword, low, high, value) do { \
467 (qword).u64[0] = (((qword).u64[0] \
468 & ~EFX_INPLACE_MASK64(0, 63, low, high)) \
469 | EFX_INSERT64(0, 63, low, high, value)); \
472 #define EFX_SET_OWORD32(oword, low, high, value) do { \
473 (oword).u32[0] = (((oword).u32[0] \
474 & ~EFX_INPLACE_MASK32(0, 31, low, high)) \
475 | EFX_INSERT32(0, 31, low, high, value)); \
476 (oword).u32[1] = (((oword).u32[1] \
477 & ~EFX_INPLACE_MASK32(32, 63, low, high)) \
478 | EFX_INSERT32(32, 63, low, high, value)); \
479 (oword).u32[2] = (((oword).u32[2] \
480 & ~EFX_INPLACE_MASK32(64, 95, low, high)) \
481 | EFX_INSERT32(64, 95, low, high, value)); \
482 (oword).u32[3] = (((oword).u32[3] \
483 & ~EFX_INPLACE_MASK32(96, 127, low, high)) \
484 | EFX_INSERT32(96, 127, low, high, value)); \
487 #define EFX_SET_QWORD32(qword, low, high, value) do { \
488 (qword).u32[0] = (((qword).u32[0] \
489 & ~EFX_INPLACE_MASK32(0, 31, low, high)) \
490 | EFX_INSERT32(0, 31, low, high, value)); \
491 (qword).u32[1] = (((qword).u32[1] \
492 & ~EFX_INPLACE_MASK32(32, 63, low, high)) \
493 | EFX_INSERT32(32, 63, low, high, value)); \
496 #define EFX_SET_DWORD32(dword, low, high, value) do { \
497 (dword).u32[0] = (((dword).u32[0] \
498 & ~EFX_INPLACE_MASK32(0, 31, low, high)) \
499 | EFX_INSERT32(0, 31, low, high, value)); \
502 #define EFX_SET_OWORD_FIELD64(oword, field, value) \
503 EFX_SET_OWORD64(oword, EFX_LOW_BIT(field), \
504 EFX_HIGH_BIT(field), value)
506 #define EFX_SET_QWORD_FIELD64(qword, field, value) \
507 EFX_SET_QWORD64(qword, EFX_LOW_BIT(field), \
508 EFX_HIGH_BIT(field), value)
510 #define EFX_SET_OWORD_FIELD32(oword, field, value) \
511 EFX_SET_OWORD32(oword, EFX_LOW_BIT(field), \
512 EFX_HIGH_BIT(field), value)
514 #define EFX_SET_QWORD_FIELD32(qword, field, value) \
515 EFX_SET_QWORD32(qword, EFX_LOW_BIT(field), \
516 EFX_HIGH_BIT(field), value)
518 #define EFX_SET_DWORD_FIELD(dword, field, value) \
519 EFX_SET_DWORD32(dword, EFX_LOW_BIT(field), \
520 EFX_HIGH_BIT(field), value)
524 #if BITS_PER_LONG == 64
525 #define EFX_SET_OWORD_FIELD EFX_SET_OWORD_FIELD64
526 #define EFX_SET_QWORD_FIELD EFX_SET_QWORD_FIELD64
528 #define EFX_SET_OWORD_FIELD EFX_SET_OWORD_FIELD32
529 #define EFX_SET_QWORD_FIELD EFX_SET_QWORD_FIELD32
532 /* Used to avoid compiler warnings about shift range exceeding width
533 * of the data types when dma_addr_t is only 32 bits wide.
535 #define DMA_ADDR_T_WIDTH (8 * sizeof(dma_addr_t))
536 #define EFX_DMA_TYPE_WIDTH(width) \
537 (((width) < DMA_ADDR_T_WIDTH) ? (width) : DMA_ADDR_T_WIDTH)
540 /* Static initialiser */
541 #define EFX_OWORD32(a, b, c, d) \
542 { .u32 = { cpu_to_le32(a), cpu_to_le32(b), \
543 cpu_to_le32(c), cpu_to_le32(d) } }
545 #endif /* EFX_BITFIELD_H */