1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /****************************************************************************
3 * Driver for Solarflare network controllers and boards
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
17 * vice versa, we wrap accesses in a way that uses the most efficient
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,
22 * we define our datatypes (efx_oword_t, efx_qword_t and
23 * efx_dword_t) to be little-endian.
26 /* Lowest bit numbers and widths */
27 #define EFX_DUMMY_FIELD_LBN 0
28 #define EFX_DUMMY_FIELD_WIDTH 0
29 #define EFX_BYTE_0_LBN 0
30 #define EFX_BYTE_0_WIDTH 8
31 #define EFX_WORD_0_LBN 0
32 #define EFX_WORD_0_WIDTH 16
33 #define EFX_WORD_1_LBN 16
34 #define EFX_WORD_1_WIDTH 16
35 #define EFX_DWORD_0_LBN 0
36 #define EFX_DWORD_0_WIDTH 32
37 #define EFX_DWORD_1_LBN 32
38 #define EFX_DWORD_1_WIDTH 32
39 #define EFX_DWORD_2_LBN 64
40 #define EFX_DWORD_2_WIDTH 32
41 #define EFX_DWORD_3_LBN 96
42 #define EFX_DWORD_3_WIDTH 32
43 #define EFX_QWORD_0_LBN 0
44 #define EFX_QWORD_0_WIDTH 64
46 /* Specified attribute (e.g. LBN) of the specified field */
47 #define EFX_VAL(field, attribute) field ## _ ## attribute
48 /* Low bit number of the specified field */
49 #define EFX_LOW_BIT(field) EFX_VAL(field, LBN)
50 /* Bit width of the specified field */
51 #define EFX_WIDTH(field) EFX_VAL(field, WIDTH)
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.
56 * For example, a field with width 5 would have a mask of 0x1f.
58 * The maximum width mask that can be generated is 64 bits.
60 #define EFX_MASK64(width) \
61 ((width) == 64 ? ~((u64) 0) : \
62 (((((u64) 1) << (width))) - 1))
64 /* Mask equal in width to the specified field.
66 * For example, a field with width 5 would have a mask of 0x1f.
68 * The maximum width mask that can be generated is 32 bits. Use
69 * EFX_MASK64 for higher width fields.
71 #define EFX_MASK32(width) \
72 ((width) == 32 ? ~((u32) 0) : \
73 (((((u32) 1) << (width))) - 1))
75 /* A doubleword (i.e. 4 byte) datatype - little-endian in HW */
76 typedef union efx_dword
{
80 /* A quadword (i.e. 8 byte) datatype - little-endian in HW */
81 typedef union efx_qword
{
87 /* An octword (eight-word, i.e. 16 byte) datatype - little-endian in HW */
88 typedef union efx_oword
{
95 /* Format string and value expanders for printk */
96 #define EFX_DWORD_FMT "%08x"
97 #define EFX_QWORD_FMT "%08x:%08x"
98 #define EFX_OWORD_FMT "%08x:%08x:%08x:%08x"
99 #define EFX_DWORD_VAL(dword) \
100 ((unsigned int) le32_to_cpu((dword).u32[0]))
101 #define EFX_QWORD_VAL(qword) \
102 ((unsigned int) le32_to_cpu((qword).u32[1])), \
103 ((unsigned int) le32_to_cpu((qword).u32[0]))
104 #define EFX_OWORD_VAL(oword) \
105 ((unsigned int) le32_to_cpu((oword).u32[3])), \
106 ((unsigned int) le32_to_cpu((oword).u32[2])), \
107 ((unsigned int) le32_to_cpu((oword).u32[1])), \
108 ((unsigned int) le32_to_cpu((oword).u32[0]))
111 * Extract bit field portion [low,high) from the native-endian element
112 * which contains bits [min,max).
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.
118 * Then EFX_EXTRACT ( element, 32, 63, 28, 45 ) would give
122 * The result will contain the relevant bits filled in in the range
123 * [0,high-low), with garbage in bits [high-low+1,...).
125 #define EFX_EXTRACT_NATIVE(native_element, min, max, low, high) \
126 ((low) > (max) || (high) < (min) ? 0 : \
128 (native_element) >> ((low) - (min)) : \
129 (native_element) << ((min) - (low)))
132 * Extract bit field portion [low,high) from the 64-bit little-endian
133 * element which contains bits [min,max)
135 #define EFX_EXTRACT64(element, min, max, low, high) \
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
140 * element which contains bits [min,max)
142 #define EFX_EXTRACT32(element, min, max, low, high) \
143 EFX_EXTRACT_NATIVE(le32_to_cpu(element), min, max, low, high)
145 #define EFX_EXTRACT_OWORD64(oword, low, high) \
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) \
151 (EFX_EXTRACT64((qword).u64[0], 0, 63, low, high) & \
152 EFX_MASK64((high) + 1 - (low)))
154 #define EFX_EXTRACT_OWORD32(oword, low, high) \
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) \
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) \
167 (EFX_EXTRACT32((dword).u32[0], 0, 31, low, high) & \
168 EFX_MASK32((high) + 1 - (low)))
170 #define EFX_OWORD_FIELD64(oword, field) \
171 EFX_EXTRACT_OWORD64(oword, EFX_LOW_BIT(field), \
174 #define EFX_QWORD_FIELD64(qword, field) \
175 EFX_EXTRACT_QWORD64(qword, EFX_LOW_BIT(field), \
178 #define EFX_OWORD_FIELD32(oword, field) \
179 EFX_EXTRACT_OWORD32(oword, EFX_LOW_BIT(field), \
182 #define EFX_QWORD_FIELD32(qword, field) \
183 EFX_EXTRACT_QWORD32(qword, EFX_LOW_BIT(field), \
186 #define EFX_DWORD_FIELD(dword, field) \
187 EFX_EXTRACT_DWORD(dword, EFX_LOW_BIT(field), \
190 #define EFX_OWORD_IS_ZERO64(oword) \
191 (((oword).u64[0] | (oword).u64[1]) == (__force __le64) 0)
193 #define EFX_QWORD_IS_ZERO64(qword) \
194 (((qword).u64[0]) == (__force __le64) 0)
196 #define EFX_OWORD_IS_ZERO32(oword) \
197 (((oword).u32[0] | (oword).u32[1] | (oword).u32[2] | (oword).u32[3]) \
198 == (__force __le32) 0)
200 #define EFX_QWORD_IS_ZERO32(qword) \
201 (((qword).u32[0] | (qword).u32[1]) == (__force __le32) 0)
203 #define EFX_DWORD_IS_ZERO(dword) \
204 (((dword).u32[0]) == (__force __le32) 0)
206 #define EFX_OWORD_IS_ALL_ONES64(oword) \
207 (((oword).u64[0] & (oword).u64[1]) == ~((__force __le64) 0))
209 #define EFX_QWORD_IS_ALL_ONES64(qword) \
210 ((qword).u64[0] == ~((__force __le64) 0))
212 #define EFX_OWORD_IS_ALL_ONES32(oword) \
213 (((oword).u32[0] & (oword).u32[1] & (oword).u32[2] & (oword).u32[3]) \
214 == ~((__force __le32) 0))
216 #define EFX_QWORD_IS_ALL_ONES32(qword) \
217 (((qword).u32[0] & (qword).u32[1]) == ~((__force __le32) 0))
219 #define EFX_DWORD_IS_ALL_ONES(dword) \
220 ((dword).u32[0] == ~((__force __le32) 0))
222 #if BITS_PER_LONG == 64
223 #define EFX_OWORD_FIELD EFX_OWORD_FIELD64
224 #define EFX_QWORD_FIELD EFX_QWORD_FIELD64
225 #define EFX_OWORD_IS_ZERO EFX_OWORD_IS_ZERO64
226 #define EFX_QWORD_IS_ZERO EFX_QWORD_IS_ZERO64
227 #define EFX_OWORD_IS_ALL_ONES EFX_OWORD_IS_ALL_ONES64
228 #define EFX_QWORD_IS_ALL_ONES EFX_QWORD_IS_ALL_ONES64
230 #define EFX_OWORD_FIELD EFX_OWORD_FIELD32
231 #define EFX_QWORD_FIELD EFX_QWORD_FIELD32
232 #define EFX_OWORD_IS_ZERO EFX_OWORD_IS_ZERO32
233 #define EFX_QWORD_IS_ZERO EFX_QWORD_IS_ZERO32
234 #define EFX_OWORD_IS_ALL_ONES EFX_OWORD_IS_ALL_ONES32
235 #define EFX_QWORD_IS_ALL_ONES EFX_QWORD_IS_ALL_ONES32
239 * Construct bit field portion
241 * Creates the portion of the bit field [low,high) that lies within
242 * the range [min,max).
244 #define EFX_INSERT_NATIVE64(min, max, low, high, value) \
245 (((low > max) || (high < min)) ? 0 : \
247 (((u64) (value)) << (low - min)) : \
248 (((u64) (value)) >> (min - low))))
250 #define EFX_INSERT_NATIVE32(min, max, low, high, value) \
251 (((low > max) || (high < min)) ? 0 : \
253 (((u32) (value)) << (low - min)) : \
254 (((u32) (value)) >> (min - low))))
256 #define EFX_INSERT_NATIVE(min, max, low, high, value) \
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))
262 * Construct bit field portion
264 * Creates the portion of the named bit field that lies within the
267 #define EFX_INSERT_FIELD_NATIVE(min, max, field, value) \
268 EFX_INSERT_NATIVE(min, max, EFX_LOW_BIT(field), \
269 EFX_HIGH_BIT(field), value)
272 * Construct bit field
274 * Creates the portion of the named bit fields that lie within the
277 #define EFX_INSERT_FIELDS_NATIVE(min, max, \
297 (EFX_INSERT_FIELD_NATIVE((min), (max), field1, (value1)) | \
298 EFX_INSERT_FIELD_NATIVE((min), (max), field2, (value2)) | \
299 EFX_INSERT_FIELD_NATIVE((min), (max), field3, (value3)) | \
300 EFX_INSERT_FIELD_NATIVE((min), (max), field4, (value4)) | \
301 EFX_INSERT_FIELD_NATIVE((min), (max), field5, (value5)) | \
302 EFX_INSERT_FIELD_NATIVE((min), (max), field6, (value6)) | \
303 EFX_INSERT_FIELD_NATIVE((min), (max), field7, (value7)) | \
304 EFX_INSERT_FIELD_NATIVE((min), (max), field8, (value8)) | \
305 EFX_INSERT_FIELD_NATIVE((min), (max), field9, (value9)) | \
306 EFX_INSERT_FIELD_NATIVE((min), (max), field10, (value10)) | \
307 EFX_INSERT_FIELD_NATIVE((min), (max), field11, (value11)) | \
308 EFX_INSERT_FIELD_NATIVE((min), (max), field12, (value12)) | \
309 EFX_INSERT_FIELD_NATIVE((min), (max), field13, (value13)) | \
310 EFX_INSERT_FIELD_NATIVE((min), (max), field14, (value14)) | \
311 EFX_INSERT_FIELD_NATIVE((min), (max), field15, (value15)) | \
312 EFX_INSERT_FIELD_NATIVE((min), (max), field16, (value16)) | \
313 EFX_INSERT_FIELD_NATIVE((min), (max), field17, (value17)) | \
314 EFX_INSERT_FIELD_NATIVE((min), (max), field18, (value18)) | \
315 EFX_INSERT_FIELD_NATIVE((min), (max), field19, (value19)))
317 #define EFX_INSERT_FIELDS64(...) \
318 cpu_to_le64(EFX_INSERT_FIELDS_NATIVE(__VA_ARGS__))
320 #define EFX_INSERT_FIELDS32(...) \
321 cpu_to_le32(EFX_INSERT_FIELDS_NATIVE(__VA_ARGS__))
323 #define EFX_POPULATE_OWORD64(oword, ...) do { \
324 (oword).u64[0] = EFX_INSERT_FIELDS64(0, 63, __VA_ARGS__); \
325 (oword).u64[1] = EFX_INSERT_FIELDS64(64, 127, __VA_ARGS__); \
328 #define EFX_POPULATE_QWORD64(qword, ...) do { \
329 (qword).u64[0] = EFX_INSERT_FIELDS64(0, 63, __VA_ARGS__); \
332 #define EFX_POPULATE_OWORD32(oword, ...) do { \
333 (oword).u32[0] = EFX_INSERT_FIELDS32(0, 31, __VA_ARGS__); \
334 (oword).u32[1] = EFX_INSERT_FIELDS32(32, 63, __VA_ARGS__); \
335 (oword).u32[2] = EFX_INSERT_FIELDS32(64, 95, __VA_ARGS__); \
336 (oword).u32[3] = EFX_INSERT_FIELDS32(96, 127, __VA_ARGS__); \
339 #define EFX_POPULATE_QWORD32(qword, ...) do { \
340 (qword).u32[0] = EFX_INSERT_FIELDS32(0, 31, __VA_ARGS__); \
341 (qword).u32[1] = EFX_INSERT_FIELDS32(32, 63, __VA_ARGS__); \
344 #define EFX_POPULATE_DWORD(dword, ...) do { \
345 (dword).u32[0] = EFX_INSERT_FIELDS32(0, 31, __VA_ARGS__); \
348 #if BITS_PER_LONG == 64
349 #define EFX_POPULATE_OWORD EFX_POPULATE_OWORD64
350 #define EFX_POPULATE_QWORD EFX_POPULATE_QWORD64
352 #define EFX_POPULATE_OWORD EFX_POPULATE_OWORD32
353 #define EFX_POPULATE_QWORD EFX_POPULATE_QWORD32
356 /* Populate an octword field with various numbers of arguments */
357 #define EFX_POPULATE_OWORD_19 EFX_POPULATE_OWORD
358 #define EFX_POPULATE_OWORD_18(oword, ...) \
359 EFX_POPULATE_OWORD_19(oword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
360 #define EFX_POPULATE_OWORD_17(oword, ...) \
361 EFX_POPULATE_OWORD_18(oword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
362 #define EFX_POPULATE_OWORD_16(oword, ...) \
363 EFX_POPULATE_OWORD_17(oword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
364 #define EFX_POPULATE_OWORD_15(oword, ...) \
365 EFX_POPULATE_OWORD_16(oword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
366 #define EFX_POPULATE_OWORD_14(oword, ...) \
367 EFX_POPULATE_OWORD_15(oword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
368 #define EFX_POPULATE_OWORD_13(oword, ...) \
369 EFX_POPULATE_OWORD_14(oword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
370 #define EFX_POPULATE_OWORD_12(oword, ...) \
371 EFX_POPULATE_OWORD_13(oword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
372 #define EFX_POPULATE_OWORD_11(oword, ...) \
373 EFX_POPULATE_OWORD_12(oword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
374 #define EFX_POPULATE_OWORD_10(oword, ...) \
375 EFX_POPULATE_OWORD_11(oword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
376 #define EFX_POPULATE_OWORD_9(oword, ...) \
377 EFX_POPULATE_OWORD_10(oword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
378 #define EFX_POPULATE_OWORD_8(oword, ...) \
379 EFX_POPULATE_OWORD_9(oword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
380 #define EFX_POPULATE_OWORD_7(oword, ...) \
381 EFX_POPULATE_OWORD_8(oword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
382 #define EFX_POPULATE_OWORD_6(oword, ...) \
383 EFX_POPULATE_OWORD_7(oword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
384 #define EFX_POPULATE_OWORD_5(oword, ...) \
385 EFX_POPULATE_OWORD_6(oword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
386 #define EFX_POPULATE_OWORD_4(oword, ...) \
387 EFX_POPULATE_OWORD_5(oword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
388 #define EFX_POPULATE_OWORD_3(oword, ...) \
389 EFX_POPULATE_OWORD_4(oword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
390 #define EFX_POPULATE_OWORD_2(oword, ...) \
391 EFX_POPULATE_OWORD_3(oword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
392 #define EFX_POPULATE_OWORD_1(oword, ...) \
393 EFX_POPULATE_OWORD_2(oword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
394 #define EFX_ZERO_OWORD(oword) \
395 EFX_POPULATE_OWORD_1(oword, EFX_DUMMY_FIELD, 0)
396 #define EFX_SET_OWORD(oword) \
397 EFX_POPULATE_OWORD_4(oword, \
398 EFX_DWORD_0, 0xffffffff, \
399 EFX_DWORD_1, 0xffffffff, \
400 EFX_DWORD_2, 0xffffffff, \
401 EFX_DWORD_3, 0xffffffff)
403 /* Populate a quadword field with various numbers of arguments */
404 #define EFX_POPULATE_QWORD_19 EFX_POPULATE_QWORD
405 #define EFX_POPULATE_QWORD_18(qword, ...) \
406 EFX_POPULATE_QWORD_19(qword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
407 #define EFX_POPULATE_QWORD_17(qword, ...) \
408 EFX_POPULATE_QWORD_18(qword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
409 #define EFX_POPULATE_QWORD_16(qword, ...) \
410 EFX_POPULATE_QWORD_17(qword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
411 #define EFX_POPULATE_QWORD_15(qword, ...) \
412 EFX_POPULATE_QWORD_16(qword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
413 #define EFX_POPULATE_QWORD_14(qword, ...) \
414 EFX_POPULATE_QWORD_15(qword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
415 #define EFX_POPULATE_QWORD_13(qword, ...) \
416 EFX_POPULATE_QWORD_14(qword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
417 #define EFX_POPULATE_QWORD_12(qword, ...) \
418 EFX_POPULATE_QWORD_13(qword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
419 #define EFX_POPULATE_QWORD_11(qword, ...) \
420 EFX_POPULATE_QWORD_12(qword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
421 #define EFX_POPULATE_QWORD_10(qword, ...) \
422 EFX_POPULATE_QWORD_11(qword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
423 #define EFX_POPULATE_QWORD_9(qword, ...) \
424 EFX_POPULATE_QWORD_10(qword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
425 #define EFX_POPULATE_QWORD_8(qword, ...) \
426 EFX_POPULATE_QWORD_9(qword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
427 #define EFX_POPULATE_QWORD_7(qword, ...) \
428 EFX_POPULATE_QWORD_8(qword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
429 #define EFX_POPULATE_QWORD_6(qword, ...) \
430 EFX_POPULATE_QWORD_7(qword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
431 #define EFX_POPULATE_QWORD_5(qword, ...) \
432 EFX_POPULATE_QWORD_6(qword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
433 #define EFX_POPULATE_QWORD_4(qword, ...) \
434 EFX_POPULATE_QWORD_5(qword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
435 #define EFX_POPULATE_QWORD_3(qword, ...) \
436 EFX_POPULATE_QWORD_4(qword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
437 #define EFX_POPULATE_QWORD_2(qword, ...) \
438 EFX_POPULATE_QWORD_3(qword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
439 #define EFX_POPULATE_QWORD_1(qword, ...) \
440 EFX_POPULATE_QWORD_2(qword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
441 #define EFX_ZERO_QWORD(qword) \
442 EFX_POPULATE_QWORD_1(qword, EFX_DUMMY_FIELD, 0)
443 #define EFX_SET_QWORD(qword) \
444 EFX_POPULATE_QWORD_2(qword, \
445 EFX_DWORD_0, 0xffffffff, \
446 EFX_DWORD_1, 0xffffffff)
448 /* Populate a dword field with various numbers of arguments */
449 #define EFX_POPULATE_DWORD_19 EFX_POPULATE_DWORD
450 #define EFX_POPULATE_DWORD_18(dword, ...) \
451 EFX_POPULATE_DWORD_19(dword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
452 #define EFX_POPULATE_DWORD_17(dword, ...) \
453 EFX_POPULATE_DWORD_18(dword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
454 #define EFX_POPULATE_DWORD_16(dword, ...) \
455 EFX_POPULATE_DWORD_17(dword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
456 #define EFX_POPULATE_DWORD_15(dword, ...) \
457 EFX_POPULATE_DWORD_16(dword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
458 #define EFX_POPULATE_DWORD_14(dword, ...) \
459 EFX_POPULATE_DWORD_15(dword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
460 #define EFX_POPULATE_DWORD_13(dword, ...) \
461 EFX_POPULATE_DWORD_14(dword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
462 #define EFX_POPULATE_DWORD_12(dword, ...) \
463 EFX_POPULATE_DWORD_13(dword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
464 #define EFX_POPULATE_DWORD_11(dword, ...) \
465 EFX_POPULATE_DWORD_12(dword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
466 #define EFX_POPULATE_DWORD_10(dword, ...) \
467 EFX_POPULATE_DWORD_11(dword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
468 #define EFX_POPULATE_DWORD_9(dword, ...) \
469 EFX_POPULATE_DWORD_10(dword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
470 #define EFX_POPULATE_DWORD_8(dword, ...) \
471 EFX_POPULATE_DWORD_9(dword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
472 #define EFX_POPULATE_DWORD_7(dword, ...) \
473 EFX_POPULATE_DWORD_8(dword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
474 #define EFX_POPULATE_DWORD_6(dword, ...) \
475 EFX_POPULATE_DWORD_7(dword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
476 #define EFX_POPULATE_DWORD_5(dword, ...) \
477 EFX_POPULATE_DWORD_6(dword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
478 #define EFX_POPULATE_DWORD_4(dword, ...) \
479 EFX_POPULATE_DWORD_5(dword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
480 #define EFX_POPULATE_DWORD_3(dword, ...) \
481 EFX_POPULATE_DWORD_4(dword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
482 #define EFX_POPULATE_DWORD_2(dword, ...) \
483 EFX_POPULATE_DWORD_3(dword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
484 #define EFX_POPULATE_DWORD_1(dword, ...) \
485 EFX_POPULATE_DWORD_2(dword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
486 #define EFX_ZERO_DWORD(dword) \
487 EFX_POPULATE_DWORD_1(dword, EFX_DUMMY_FIELD, 0)
488 #define EFX_SET_DWORD(dword) \
489 EFX_POPULATE_DWORD_1(dword, EFX_DWORD_0, 0xffffffff)
492 * Modify a named field within an already-populated structure. Used
493 * for read-modify-write operations.
496 #define EFX_INVERT_OWORD(oword) do { \
497 (oword).u64[0] = ~((oword).u64[0]); \
498 (oword).u64[1] = ~((oword).u64[1]); \
501 #define EFX_AND_OWORD(oword, from, mask) \
503 (oword).u64[0] = (from).u64[0] & (mask).u64[0]; \
504 (oword).u64[1] = (from).u64[1] & (mask).u64[1]; \
507 #define EFX_AND_QWORD(qword, from, mask) \
508 (qword).u64[0] = (from).u64[0] & (mask).u64[0]
510 #define EFX_OR_OWORD(oword, from, mask) \
512 (oword).u64[0] = (from).u64[0] | (mask).u64[0]; \
513 (oword).u64[1] = (from).u64[1] | (mask).u64[1]; \
516 #define EFX_INSERT64(min, max, low, high, value) \
517 cpu_to_le64(EFX_INSERT_NATIVE(min, max, low, high, value))
519 #define EFX_INSERT32(min, max, low, high, value) \
520 cpu_to_le32(EFX_INSERT_NATIVE(min, max, low, high, value))
522 #define EFX_INPLACE_MASK64(min, max, low, high) \
523 EFX_INSERT64(min, max, low, high, EFX_MASK64((high) + 1 - (low)))
525 #define EFX_INPLACE_MASK32(min, max, low, high) \
526 EFX_INSERT32(min, max, low, high, EFX_MASK32((high) + 1 - (low)))
528 #define EFX_SET_OWORD64(oword, low, high, value) do { \
529 (oword).u64[0] = (((oword).u64[0] \
530 & ~EFX_INPLACE_MASK64(0, 63, low, high)) \
531 | EFX_INSERT64(0, 63, low, high, value)); \
532 (oword).u64[1] = (((oword).u64[1] \
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 { \
538 (qword).u64[0] = (((qword).u64[0] \
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 { \
544 (oword).u32[0] = (((oword).u32[0] \
545 & ~EFX_INPLACE_MASK32(0, 31, low, high)) \
546 | EFX_INSERT32(0, 31, low, high, value)); \
547 (oword).u32[1] = (((oword).u32[1] \
548 & ~EFX_INPLACE_MASK32(32, 63, low, high)) \
549 | EFX_INSERT32(32, 63, low, high, value)); \
550 (oword).u32[2] = (((oword).u32[2] \
551 & ~EFX_INPLACE_MASK32(64, 95, low, high)) \
552 | EFX_INSERT32(64, 95, low, high, value)); \
553 (oword).u32[3] = (((oword).u32[3] \
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 { \
559 (qword).u32[0] = (((qword).u32[0] \
560 & ~EFX_INPLACE_MASK32(0, 31, low, high)) \
561 | EFX_INSERT32(0, 31, low, high, value)); \
562 (qword).u32[1] = (((qword).u32[1] \
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 { \
568 (dword).u32[0] = (((dword).u32[0] \
569 & ~EFX_INPLACE_MASK32(0, 31, low, high)) \
570 | EFX_INSERT32(0, 31, low, high, value)); \
573 #define EFX_SET_OWORD_FIELD64(oword, field, value) \
574 EFX_SET_OWORD64(oword, EFX_LOW_BIT(field), \
575 EFX_HIGH_BIT(field), value)
577 #define EFX_SET_QWORD_FIELD64(qword, field, value) \
578 EFX_SET_QWORD64(qword, EFX_LOW_BIT(field), \
579 EFX_HIGH_BIT(field), value)
581 #define EFX_SET_OWORD_FIELD32(oword, field, value) \
582 EFX_SET_OWORD32(oword, EFX_LOW_BIT(field), \
583 EFX_HIGH_BIT(field), value)
585 #define EFX_SET_QWORD_FIELD32(qword, field, value) \
586 EFX_SET_QWORD32(qword, EFX_LOW_BIT(field), \
587 EFX_HIGH_BIT(field), value)
589 #define EFX_SET_DWORD_FIELD(dword, field, value) \
590 EFX_SET_DWORD32(dword, EFX_LOW_BIT(field), \
591 EFX_HIGH_BIT(field), value)
595 #if BITS_PER_LONG == 64
596 #define EFX_SET_OWORD_FIELD EFX_SET_OWORD_FIELD64
597 #define EFX_SET_QWORD_FIELD EFX_SET_QWORD_FIELD64
599 #define EFX_SET_OWORD_FIELD EFX_SET_OWORD_FIELD32
600 #define EFX_SET_QWORD_FIELD EFX_SET_QWORD_FIELD32
603 /* Used to avoid compiler warnings about shift range exceeding width
604 * of the data types when dma_addr_t is only 32 bits wide.
606 #define DMA_ADDR_T_WIDTH (8 * sizeof(dma_addr_t))
607 #define EFX_DMA_TYPE_WIDTH(width) \
608 (((width) < DMA_ADDR_T_WIDTH) ? (width) : DMA_ADDR_T_WIDTH)
611 /* Static initialiser */
612 #define EFX_OWORD32(a, b, c, d) \
613 { .u32 = { cpu_to_le32(a), cpu_to_le32(b), \
614 cpu_to_le32(c), cpu_to_le32(d) } }
616 #endif /* EFX_BITFIELD_H */