1d2912cb1SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */ 2874aeea5SJeff Kirsher /**************************************************************************** 3f7a6d2c4SBen Hutchings * Driver for Solarflare network controllers and boards 4874aeea5SJeff Kirsher * Copyright 2005-2006 Fen Systems Ltd. 5f7a6d2c4SBen Hutchings * Copyright 2006-2013 Solarflare Communications Inc. 6874aeea5SJeff Kirsher */ 7874aeea5SJeff Kirsher 8874aeea5SJeff Kirsher #ifndef EFX_BITFIELD_H 9874aeea5SJeff Kirsher #define EFX_BITFIELD_H 10874aeea5SJeff Kirsher 11874aeea5SJeff Kirsher /* 12874aeea5SJeff Kirsher * Efx bitfield access 13874aeea5SJeff Kirsher * 14874aeea5SJeff Kirsher * Efx NICs make extensive use of bitfields up to 128 bits 15874aeea5SJeff Kirsher * wide. Since there is no native 128-bit datatype on most systems, 16874aeea5SJeff Kirsher * and since 64-bit datatypes are inefficient on 32-bit systems and 17874aeea5SJeff Kirsher * vice versa, we wrap accesses in a way that uses the most efficient 18874aeea5SJeff Kirsher * datatype. 19874aeea5SJeff Kirsher * 20874aeea5SJeff Kirsher * The NICs are PCI devices and therefore little-endian. Since most 21874aeea5SJeff Kirsher * of the quantities that we deal with are DMAed to/from host memory, 22874aeea5SJeff Kirsher * we define our datatypes (efx_oword_t, efx_qword_t and 23874aeea5SJeff Kirsher * efx_dword_t) to be little-endian. 24874aeea5SJeff Kirsher */ 25874aeea5SJeff Kirsher 26874aeea5SJeff Kirsher /* Lowest bit numbers and widths */ 27874aeea5SJeff Kirsher #define EFX_DUMMY_FIELD_LBN 0 28874aeea5SJeff Kirsher #define EFX_DUMMY_FIELD_WIDTH 0 298127d661SBen Hutchings #define EFX_WORD_0_LBN 0 308127d661SBen Hutchings #define EFX_WORD_0_WIDTH 16 318127d661SBen Hutchings #define EFX_WORD_1_LBN 16 328127d661SBen Hutchings #define EFX_WORD_1_WIDTH 16 33874aeea5SJeff Kirsher #define EFX_DWORD_0_LBN 0 34874aeea5SJeff Kirsher #define EFX_DWORD_0_WIDTH 32 35874aeea5SJeff Kirsher #define EFX_DWORD_1_LBN 32 36874aeea5SJeff Kirsher #define EFX_DWORD_1_WIDTH 32 37874aeea5SJeff Kirsher #define EFX_DWORD_2_LBN 64 38874aeea5SJeff Kirsher #define EFX_DWORD_2_WIDTH 32 39874aeea5SJeff Kirsher #define EFX_DWORD_3_LBN 96 40874aeea5SJeff Kirsher #define EFX_DWORD_3_WIDTH 32 41874aeea5SJeff Kirsher #define EFX_QWORD_0_LBN 0 42874aeea5SJeff Kirsher #define EFX_QWORD_0_WIDTH 64 43874aeea5SJeff Kirsher 44874aeea5SJeff Kirsher /* Specified attribute (e.g. LBN) of the specified field */ 45874aeea5SJeff Kirsher #define EFX_VAL(field, attribute) field ## _ ## attribute 46874aeea5SJeff Kirsher /* Low bit number of the specified field */ 47874aeea5SJeff Kirsher #define EFX_LOW_BIT(field) EFX_VAL(field, LBN) 48874aeea5SJeff Kirsher /* Bit width of the specified field */ 49874aeea5SJeff Kirsher #define EFX_WIDTH(field) EFX_VAL(field, WIDTH) 50874aeea5SJeff Kirsher /* High bit number of the specified field */ 51874aeea5SJeff Kirsher #define EFX_HIGH_BIT(field) (EFX_LOW_BIT(field) + EFX_WIDTH(field) - 1) 52874aeea5SJeff Kirsher /* Mask equal in width to the specified field. 53874aeea5SJeff Kirsher * 54874aeea5SJeff Kirsher * For example, a field with width 5 would have a mask of 0x1f. 55874aeea5SJeff Kirsher * 56874aeea5SJeff Kirsher * The maximum width mask that can be generated is 64 bits. 57874aeea5SJeff Kirsher */ 58874aeea5SJeff Kirsher #define EFX_MASK64(width) \ 59874aeea5SJeff Kirsher ((width) == 64 ? ~((u64) 0) : \ 60874aeea5SJeff Kirsher (((((u64) 1) << (width))) - 1)) 61874aeea5SJeff Kirsher 62874aeea5SJeff Kirsher /* Mask equal in width to the specified field. 63874aeea5SJeff Kirsher * 64874aeea5SJeff Kirsher * For example, a field with width 5 would have a mask of 0x1f. 65874aeea5SJeff Kirsher * 66874aeea5SJeff Kirsher * The maximum width mask that can be generated is 32 bits. Use 67874aeea5SJeff Kirsher * EFX_MASK64 for higher width fields. 68874aeea5SJeff Kirsher */ 69874aeea5SJeff Kirsher #define EFX_MASK32(width) \ 70874aeea5SJeff Kirsher ((width) == 32 ? ~((u32) 0) : \ 71874aeea5SJeff Kirsher (((((u32) 1) << (width))) - 1)) 72874aeea5SJeff Kirsher 73874aeea5SJeff Kirsher /* A doubleword (i.e. 4 byte) datatype - little-endian in HW */ 74874aeea5SJeff Kirsher typedef union efx_dword { 75874aeea5SJeff Kirsher __le32 u32[1]; 76874aeea5SJeff Kirsher } efx_dword_t; 77874aeea5SJeff Kirsher 78874aeea5SJeff Kirsher /* A quadword (i.e. 8 byte) datatype - little-endian in HW */ 79874aeea5SJeff Kirsher typedef union efx_qword { 80874aeea5SJeff Kirsher __le64 u64[1]; 81874aeea5SJeff Kirsher __le32 u32[2]; 82874aeea5SJeff Kirsher efx_dword_t dword[2]; 83874aeea5SJeff Kirsher } efx_qword_t; 84874aeea5SJeff Kirsher 85874aeea5SJeff Kirsher /* An octword (eight-word, i.e. 16 byte) datatype - little-endian in HW */ 86874aeea5SJeff Kirsher typedef union efx_oword { 87874aeea5SJeff Kirsher __le64 u64[2]; 88874aeea5SJeff Kirsher efx_qword_t qword[2]; 89874aeea5SJeff Kirsher __le32 u32[4]; 90874aeea5SJeff Kirsher efx_dword_t dword[4]; 91874aeea5SJeff Kirsher } efx_oword_t; 92874aeea5SJeff Kirsher 93874aeea5SJeff Kirsher /* Format string and value expanders for printk */ 94874aeea5SJeff Kirsher #define EFX_DWORD_FMT "%08x" 95874aeea5SJeff Kirsher #define EFX_QWORD_FMT "%08x:%08x" 96874aeea5SJeff Kirsher #define EFX_OWORD_FMT "%08x:%08x:%08x:%08x" 97874aeea5SJeff Kirsher #define EFX_DWORD_VAL(dword) \ 98874aeea5SJeff Kirsher ((unsigned int) le32_to_cpu((dword).u32[0])) 99874aeea5SJeff Kirsher #define EFX_QWORD_VAL(qword) \ 100874aeea5SJeff Kirsher ((unsigned int) le32_to_cpu((qword).u32[1])), \ 101874aeea5SJeff Kirsher ((unsigned int) le32_to_cpu((qword).u32[0])) 102874aeea5SJeff Kirsher #define EFX_OWORD_VAL(oword) \ 103874aeea5SJeff Kirsher ((unsigned int) le32_to_cpu((oword).u32[3])), \ 104874aeea5SJeff Kirsher ((unsigned int) le32_to_cpu((oword).u32[2])), \ 105874aeea5SJeff Kirsher ((unsigned int) le32_to_cpu((oword).u32[1])), \ 106874aeea5SJeff Kirsher ((unsigned int) le32_to_cpu((oword).u32[0])) 107874aeea5SJeff Kirsher 108874aeea5SJeff Kirsher /* 109874aeea5SJeff Kirsher * Extract bit field portion [low,high) from the native-endian element 110874aeea5SJeff Kirsher * which contains bits [min,max). 111874aeea5SJeff Kirsher * 112874aeea5SJeff Kirsher * For example, suppose "element" represents the high 32 bits of a 113874aeea5SJeff Kirsher * 64-bit value, and we wish to extract the bits belonging to the bit 114874aeea5SJeff Kirsher * field occupying bits 28-45 of this 64-bit value. 115874aeea5SJeff Kirsher * 116874aeea5SJeff Kirsher * Then EFX_EXTRACT ( element, 32, 63, 28, 45 ) would give 117874aeea5SJeff Kirsher * 118874aeea5SJeff Kirsher * ( element ) << 4 119874aeea5SJeff Kirsher * 120874aeea5SJeff Kirsher * The result will contain the relevant bits filled in in the range 121874aeea5SJeff Kirsher * [0,high-low), with garbage in bits [high-low+1,...). 122874aeea5SJeff Kirsher */ 123874aeea5SJeff Kirsher #define EFX_EXTRACT_NATIVE(native_element, min, max, low, high) \ 1249724a850SBen Hutchings ((low) > (max) || (high) < (min) ? 0 : \ 1259724a850SBen Hutchings (low) > (min) ? \ 1269724a850SBen Hutchings (native_element) >> ((low) - (min)) : \ 1279724a850SBen Hutchings (native_element) << ((min) - (low))) 128874aeea5SJeff Kirsher 129874aeea5SJeff Kirsher /* 130874aeea5SJeff Kirsher * Extract bit field portion [low,high) from the 64-bit little-endian 131874aeea5SJeff Kirsher * element which contains bits [min,max) 132874aeea5SJeff Kirsher */ 133874aeea5SJeff Kirsher #define EFX_EXTRACT64(element, min, max, low, high) \ 134874aeea5SJeff Kirsher EFX_EXTRACT_NATIVE(le64_to_cpu(element), min, max, low, high) 135874aeea5SJeff Kirsher 136874aeea5SJeff Kirsher /* 137874aeea5SJeff Kirsher * Extract bit field portion [low,high) from the 32-bit little-endian 138874aeea5SJeff Kirsher * element which contains bits [min,max) 139874aeea5SJeff Kirsher */ 140874aeea5SJeff Kirsher #define EFX_EXTRACT32(element, min, max, low, high) \ 141874aeea5SJeff Kirsher EFX_EXTRACT_NATIVE(le32_to_cpu(element), min, max, low, high) 142874aeea5SJeff Kirsher 143874aeea5SJeff Kirsher #define EFX_EXTRACT_OWORD64(oword, low, high) \ 144874aeea5SJeff Kirsher ((EFX_EXTRACT64((oword).u64[0], 0, 63, low, high) | \ 145874aeea5SJeff Kirsher EFX_EXTRACT64((oword).u64[1], 64, 127, low, high)) & \ 1469724a850SBen Hutchings EFX_MASK64((high) + 1 - (low))) 147874aeea5SJeff Kirsher 148874aeea5SJeff Kirsher #define EFX_EXTRACT_QWORD64(qword, low, high) \ 149874aeea5SJeff Kirsher (EFX_EXTRACT64((qword).u64[0], 0, 63, low, high) & \ 1509724a850SBen Hutchings EFX_MASK64((high) + 1 - (low))) 151874aeea5SJeff Kirsher 152874aeea5SJeff Kirsher #define EFX_EXTRACT_OWORD32(oword, low, high) \ 153874aeea5SJeff Kirsher ((EFX_EXTRACT32((oword).u32[0], 0, 31, low, high) | \ 154874aeea5SJeff Kirsher EFX_EXTRACT32((oword).u32[1], 32, 63, low, high) | \ 155874aeea5SJeff Kirsher EFX_EXTRACT32((oword).u32[2], 64, 95, low, high) | \ 156874aeea5SJeff Kirsher EFX_EXTRACT32((oword).u32[3], 96, 127, low, high)) & \ 1579724a850SBen Hutchings EFX_MASK32((high) + 1 - (low))) 158874aeea5SJeff Kirsher 159874aeea5SJeff Kirsher #define EFX_EXTRACT_QWORD32(qword, low, high) \ 160874aeea5SJeff Kirsher ((EFX_EXTRACT32((qword).u32[0], 0, 31, low, high) | \ 161874aeea5SJeff Kirsher EFX_EXTRACT32((qword).u32[1], 32, 63, low, high)) & \ 1629724a850SBen Hutchings EFX_MASK32((high) + 1 - (low))) 163874aeea5SJeff Kirsher 164874aeea5SJeff Kirsher #define EFX_EXTRACT_DWORD(dword, low, high) \ 165874aeea5SJeff Kirsher (EFX_EXTRACT32((dword).u32[0], 0, 31, low, high) & \ 1669724a850SBen Hutchings EFX_MASK32((high) + 1 - (low))) 167874aeea5SJeff Kirsher 168874aeea5SJeff Kirsher #define EFX_OWORD_FIELD64(oword, field) \ 169874aeea5SJeff Kirsher EFX_EXTRACT_OWORD64(oword, EFX_LOW_BIT(field), \ 170874aeea5SJeff Kirsher EFX_HIGH_BIT(field)) 171874aeea5SJeff Kirsher 172874aeea5SJeff Kirsher #define EFX_QWORD_FIELD64(qword, field) \ 173874aeea5SJeff Kirsher EFX_EXTRACT_QWORD64(qword, EFX_LOW_BIT(field), \ 174874aeea5SJeff Kirsher EFX_HIGH_BIT(field)) 175874aeea5SJeff Kirsher 176874aeea5SJeff Kirsher #define EFX_OWORD_FIELD32(oword, field) \ 177874aeea5SJeff Kirsher EFX_EXTRACT_OWORD32(oword, EFX_LOW_BIT(field), \ 178874aeea5SJeff Kirsher EFX_HIGH_BIT(field)) 179874aeea5SJeff Kirsher 180874aeea5SJeff Kirsher #define EFX_QWORD_FIELD32(qword, field) \ 181874aeea5SJeff Kirsher EFX_EXTRACT_QWORD32(qword, EFX_LOW_BIT(field), \ 182874aeea5SJeff Kirsher EFX_HIGH_BIT(field)) 183874aeea5SJeff Kirsher 184874aeea5SJeff Kirsher #define EFX_DWORD_FIELD(dword, field) \ 185874aeea5SJeff Kirsher EFX_EXTRACT_DWORD(dword, EFX_LOW_BIT(field), \ 186874aeea5SJeff Kirsher EFX_HIGH_BIT(field)) 187874aeea5SJeff Kirsher 188874aeea5SJeff Kirsher #define EFX_OWORD_IS_ZERO64(oword) \ 189874aeea5SJeff Kirsher (((oword).u64[0] | (oword).u64[1]) == (__force __le64) 0) 190874aeea5SJeff Kirsher 191874aeea5SJeff Kirsher #define EFX_QWORD_IS_ZERO64(qword) \ 192874aeea5SJeff Kirsher (((qword).u64[0]) == (__force __le64) 0) 193874aeea5SJeff Kirsher 194874aeea5SJeff Kirsher #define EFX_OWORD_IS_ZERO32(oword) \ 195874aeea5SJeff Kirsher (((oword).u32[0] | (oword).u32[1] | (oword).u32[2] | (oword).u32[3]) \ 196874aeea5SJeff Kirsher == (__force __le32) 0) 197874aeea5SJeff Kirsher 198874aeea5SJeff Kirsher #define EFX_QWORD_IS_ZERO32(qword) \ 199874aeea5SJeff Kirsher (((qword).u32[0] | (qword).u32[1]) == (__force __le32) 0) 200874aeea5SJeff Kirsher 201874aeea5SJeff Kirsher #define EFX_DWORD_IS_ZERO(dword) \ 202874aeea5SJeff Kirsher (((dword).u32[0]) == (__force __le32) 0) 203874aeea5SJeff Kirsher 204874aeea5SJeff Kirsher #define EFX_OWORD_IS_ALL_ONES64(oword) \ 205874aeea5SJeff Kirsher (((oword).u64[0] & (oword).u64[1]) == ~((__force __le64) 0)) 206874aeea5SJeff Kirsher 207874aeea5SJeff Kirsher #define EFX_QWORD_IS_ALL_ONES64(qword) \ 208874aeea5SJeff Kirsher ((qword).u64[0] == ~((__force __le64) 0)) 209874aeea5SJeff Kirsher 210874aeea5SJeff Kirsher #define EFX_OWORD_IS_ALL_ONES32(oword) \ 211874aeea5SJeff Kirsher (((oword).u32[0] & (oword).u32[1] & (oword).u32[2] & (oword).u32[3]) \ 212874aeea5SJeff Kirsher == ~((__force __le32) 0)) 213874aeea5SJeff Kirsher 214874aeea5SJeff Kirsher #define EFX_QWORD_IS_ALL_ONES32(qword) \ 215874aeea5SJeff Kirsher (((qword).u32[0] & (qword).u32[1]) == ~((__force __le32) 0)) 216874aeea5SJeff Kirsher 217874aeea5SJeff Kirsher #define EFX_DWORD_IS_ALL_ONES(dword) \ 218874aeea5SJeff Kirsher ((dword).u32[0] == ~((__force __le32) 0)) 219874aeea5SJeff Kirsher 220874aeea5SJeff Kirsher #if BITS_PER_LONG == 64 221874aeea5SJeff Kirsher #define EFX_OWORD_FIELD EFX_OWORD_FIELD64 222874aeea5SJeff Kirsher #define EFX_QWORD_FIELD EFX_QWORD_FIELD64 223874aeea5SJeff Kirsher #define EFX_OWORD_IS_ZERO EFX_OWORD_IS_ZERO64 224874aeea5SJeff Kirsher #define EFX_QWORD_IS_ZERO EFX_QWORD_IS_ZERO64 225874aeea5SJeff Kirsher #define EFX_OWORD_IS_ALL_ONES EFX_OWORD_IS_ALL_ONES64 226874aeea5SJeff Kirsher #define EFX_QWORD_IS_ALL_ONES EFX_QWORD_IS_ALL_ONES64 227874aeea5SJeff Kirsher #else 228874aeea5SJeff Kirsher #define EFX_OWORD_FIELD EFX_OWORD_FIELD32 229874aeea5SJeff Kirsher #define EFX_QWORD_FIELD EFX_QWORD_FIELD32 230874aeea5SJeff Kirsher #define EFX_OWORD_IS_ZERO EFX_OWORD_IS_ZERO32 231874aeea5SJeff Kirsher #define EFX_QWORD_IS_ZERO EFX_QWORD_IS_ZERO32 232874aeea5SJeff Kirsher #define EFX_OWORD_IS_ALL_ONES EFX_OWORD_IS_ALL_ONES32 233874aeea5SJeff Kirsher #define EFX_QWORD_IS_ALL_ONES EFX_QWORD_IS_ALL_ONES32 234874aeea5SJeff Kirsher #endif 235874aeea5SJeff Kirsher 236874aeea5SJeff Kirsher /* 237874aeea5SJeff Kirsher * Construct bit field portion 238874aeea5SJeff Kirsher * 239874aeea5SJeff Kirsher * Creates the portion of the bit field [low,high) that lies within 240874aeea5SJeff Kirsher * the range [min,max). 241874aeea5SJeff Kirsher */ 242874aeea5SJeff Kirsher #define EFX_INSERT_NATIVE64(min, max, low, high, value) \ 243874aeea5SJeff Kirsher (((low > max) || (high < min)) ? 0 : \ 244874aeea5SJeff Kirsher ((low > min) ? \ 245874aeea5SJeff Kirsher (((u64) (value)) << (low - min)) : \ 246874aeea5SJeff Kirsher (((u64) (value)) >> (min - low)))) 247874aeea5SJeff Kirsher 248874aeea5SJeff Kirsher #define EFX_INSERT_NATIVE32(min, max, low, high, value) \ 249874aeea5SJeff Kirsher (((low > max) || (high < min)) ? 0 : \ 250874aeea5SJeff Kirsher ((low > min) ? \ 251874aeea5SJeff Kirsher (((u32) (value)) << (low - min)) : \ 252874aeea5SJeff Kirsher (((u32) (value)) >> (min - low)))) 253874aeea5SJeff Kirsher 254874aeea5SJeff Kirsher #define EFX_INSERT_NATIVE(min, max, low, high, value) \ 255874aeea5SJeff Kirsher ((((max - min) >= 32) || ((high - low) >= 32)) ? \ 256874aeea5SJeff Kirsher EFX_INSERT_NATIVE64(min, max, low, high, value) : \ 257874aeea5SJeff Kirsher EFX_INSERT_NATIVE32(min, max, low, high, value)) 258874aeea5SJeff Kirsher 259874aeea5SJeff Kirsher /* 260874aeea5SJeff Kirsher * Construct bit field portion 261874aeea5SJeff Kirsher * 262874aeea5SJeff Kirsher * Creates the portion of the named bit field that lies within the 263874aeea5SJeff Kirsher * range [min,max). 264874aeea5SJeff Kirsher */ 265874aeea5SJeff Kirsher #define EFX_INSERT_FIELD_NATIVE(min, max, field, value) \ 266874aeea5SJeff Kirsher EFX_INSERT_NATIVE(min, max, EFX_LOW_BIT(field), \ 267874aeea5SJeff Kirsher EFX_HIGH_BIT(field), value) 268874aeea5SJeff Kirsher 269874aeea5SJeff Kirsher /* 270874aeea5SJeff Kirsher * Construct bit field 271874aeea5SJeff Kirsher * 272874aeea5SJeff Kirsher * Creates the portion of the named bit fields that lie within the 273874aeea5SJeff Kirsher * range [min,max). 274874aeea5SJeff Kirsher */ 275874aeea5SJeff Kirsher #define EFX_INSERT_FIELDS_NATIVE(min, max, \ 276874aeea5SJeff Kirsher field1, value1, \ 277874aeea5SJeff Kirsher field2, value2, \ 278874aeea5SJeff Kirsher field3, value3, \ 279874aeea5SJeff Kirsher field4, value4, \ 280874aeea5SJeff Kirsher field5, value5, \ 281874aeea5SJeff Kirsher field6, value6, \ 282874aeea5SJeff Kirsher field7, value7, \ 283874aeea5SJeff Kirsher field8, value8, \ 284874aeea5SJeff Kirsher field9, value9, \ 28508f9912eSEdward Cree field10, value10, \ 28608f9912eSEdward Cree field11, value11, \ 28708f9912eSEdward Cree field12, value12, \ 288*a7a375caSEdward Cree field13, value13, \ 289*a7a375caSEdward Cree field14, value14, \ 290*a7a375caSEdward Cree field15, value15, \ 291*a7a375caSEdward Cree field16, value16, \ 292*a7a375caSEdward Cree field17, value17) \ 293874aeea5SJeff Kirsher (EFX_INSERT_FIELD_NATIVE((min), (max), field1, (value1)) | \ 294874aeea5SJeff Kirsher EFX_INSERT_FIELD_NATIVE((min), (max), field2, (value2)) | \ 295874aeea5SJeff Kirsher EFX_INSERT_FIELD_NATIVE((min), (max), field3, (value3)) | \ 296874aeea5SJeff Kirsher EFX_INSERT_FIELD_NATIVE((min), (max), field4, (value4)) | \ 297874aeea5SJeff Kirsher EFX_INSERT_FIELD_NATIVE((min), (max), field5, (value5)) | \ 298874aeea5SJeff Kirsher EFX_INSERT_FIELD_NATIVE((min), (max), field6, (value6)) | \ 299874aeea5SJeff Kirsher EFX_INSERT_FIELD_NATIVE((min), (max), field7, (value7)) | \ 300874aeea5SJeff Kirsher EFX_INSERT_FIELD_NATIVE((min), (max), field8, (value8)) | \ 301874aeea5SJeff Kirsher EFX_INSERT_FIELD_NATIVE((min), (max), field9, (value9)) | \ 30208f9912eSEdward Cree EFX_INSERT_FIELD_NATIVE((min), (max), field10, (value10)) | \ 30308f9912eSEdward Cree EFX_INSERT_FIELD_NATIVE((min), (max), field11, (value11)) | \ 30408f9912eSEdward Cree EFX_INSERT_FIELD_NATIVE((min), (max), field12, (value12)) | \ 305*a7a375caSEdward Cree EFX_INSERT_FIELD_NATIVE((min), (max), field13, (value13)) | \ 306*a7a375caSEdward Cree EFX_INSERT_FIELD_NATIVE((min), (max), field14, (value14)) | \ 307*a7a375caSEdward Cree EFX_INSERT_FIELD_NATIVE((min), (max), field15, (value15)) | \ 308*a7a375caSEdward Cree EFX_INSERT_FIELD_NATIVE((min), (max), field16, (value16)) | \ 309*a7a375caSEdward Cree EFX_INSERT_FIELD_NATIVE((min), (max), field17, (value17))) 310874aeea5SJeff Kirsher 311874aeea5SJeff Kirsher #define EFX_INSERT_FIELDS64(...) \ 312874aeea5SJeff Kirsher cpu_to_le64(EFX_INSERT_FIELDS_NATIVE(__VA_ARGS__)) 313874aeea5SJeff Kirsher 314874aeea5SJeff Kirsher #define EFX_INSERT_FIELDS32(...) \ 315874aeea5SJeff Kirsher cpu_to_le32(EFX_INSERT_FIELDS_NATIVE(__VA_ARGS__)) 316874aeea5SJeff Kirsher 317874aeea5SJeff Kirsher #define EFX_POPULATE_OWORD64(oword, ...) do { \ 318874aeea5SJeff Kirsher (oword).u64[0] = EFX_INSERT_FIELDS64(0, 63, __VA_ARGS__); \ 319874aeea5SJeff Kirsher (oword).u64[1] = EFX_INSERT_FIELDS64(64, 127, __VA_ARGS__); \ 320874aeea5SJeff Kirsher } while (0) 321874aeea5SJeff Kirsher 322874aeea5SJeff Kirsher #define EFX_POPULATE_QWORD64(qword, ...) do { \ 323874aeea5SJeff Kirsher (qword).u64[0] = EFX_INSERT_FIELDS64(0, 63, __VA_ARGS__); \ 324874aeea5SJeff Kirsher } while (0) 325874aeea5SJeff Kirsher 326874aeea5SJeff Kirsher #define EFX_POPULATE_OWORD32(oword, ...) do { \ 327874aeea5SJeff Kirsher (oword).u32[0] = EFX_INSERT_FIELDS32(0, 31, __VA_ARGS__); \ 328874aeea5SJeff Kirsher (oword).u32[1] = EFX_INSERT_FIELDS32(32, 63, __VA_ARGS__); \ 329874aeea5SJeff Kirsher (oword).u32[2] = EFX_INSERT_FIELDS32(64, 95, __VA_ARGS__); \ 330874aeea5SJeff Kirsher (oword).u32[3] = EFX_INSERT_FIELDS32(96, 127, __VA_ARGS__); \ 331874aeea5SJeff Kirsher } while (0) 332874aeea5SJeff Kirsher 333874aeea5SJeff Kirsher #define EFX_POPULATE_QWORD32(qword, ...) do { \ 334874aeea5SJeff Kirsher (qword).u32[0] = EFX_INSERT_FIELDS32(0, 31, __VA_ARGS__); \ 335874aeea5SJeff Kirsher (qword).u32[1] = EFX_INSERT_FIELDS32(32, 63, __VA_ARGS__); \ 336874aeea5SJeff Kirsher } while (0) 337874aeea5SJeff Kirsher 338874aeea5SJeff Kirsher #define EFX_POPULATE_DWORD(dword, ...) do { \ 339874aeea5SJeff Kirsher (dword).u32[0] = EFX_INSERT_FIELDS32(0, 31, __VA_ARGS__); \ 340874aeea5SJeff Kirsher } while (0) 341874aeea5SJeff Kirsher 342874aeea5SJeff Kirsher #if BITS_PER_LONG == 64 343874aeea5SJeff Kirsher #define EFX_POPULATE_OWORD EFX_POPULATE_OWORD64 344874aeea5SJeff Kirsher #define EFX_POPULATE_QWORD EFX_POPULATE_QWORD64 345874aeea5SJeff Kirsher #else 346874aeea5SJeff Kirsher #define EFX_POPULATE_OWORD EFX_POPULATE_OWORD32 347874aeea5SJeff Kirsher #define EFX_POPULATE_QWORD EFX_POPULATE_QWORD32 348874aeea5SJeff Kirsher #endif 349874aeea5SJeff Kirsher 350874aeea5SJeff Kirsher /* Populate an octword field with various numbers of arguments */ 351*a7a375caSEdward Cree #define EFX_POPULATE_OWORD_17 EFX_POPULATE_OWORD 352*a7a375caSEdward Cree #define EFX_POPULATE_OWORD_16(oword, ...) \ 353*a7a375caSEdward Cree EFX_POPULATE_OWORD_17(oword, EFX_DUMMY_FIELD, 0, __VA_ARGS__) 354*a7a375caSEdward Cree #define EFX_POPULATE_OWORD_15(oword, ...) \ 355*a7a375caSEdward Cree EFX_POPULATE_OWORD_16(oword, EFX_DUMMY_FIELD, 0, __VA_ARGS__) 356*a7a375caSEdward Cree #define EFX_POPULATE_OWORD_14(oword, ...) \ 357*a7a375caSEdward Cree EFX_POPULATE_OWORD_15(oword, EFX_DUMMY_FIELD, 0, __VA_ARGS__) 358*a7a375caSEdward Cree #define EFX_POPULATE_OWORD_13(oword, ...) \ 359*a7a375caSEdward Cree EFX_POPULATE_OWORD_14(oword, EFX_DUMMY_FIELD, 0, __VA_ARGS__) 36008f9912eSEdward Cree #define EFX_POPULATE_OWORD_12(oword, ...) \ 36108f9912eSEdward Cree EFX_POPULATE_OWORD_13(oword, EFX_DUMMY_FIELD, 0, __VA_ARGS__) 36208f9912eSEdward Cree #define EFX_POPULATE_OWORD_11(oword, ...) \ 36308f9912eSEdward Cree EFX_POPULATE_OWORD_12(oword, EFX_DUMMY_FIELD, 0, __VA_ARGS__) 36408f9912eSEdward Cree #define EFX_POPULATE_OWORD_10(oword, ...) \ 36508f9912eSEdward Cree EFX_POPULATE_OWORD_11(oword, EFX_DUMMY_FIELD, 0, __VA_ARGS__) 366874aeea5SJeff Kirsher #define EFX_POPULATE_OWORD_9(oword, ...) \ 367874aeea5SJeff Kirsher EFX_POPULATE_OWORD_10(oword, EFX_DUMMY_FIELD, 0, __VA_ARGS__) 368874aeea5SJeff Kirsher #define EFX_POPULATE_OWORD_8(oword, ...) \ 369874aeea5SJeff Kirsher EFX_POPULATE_OWORD_9(oword, EFX_DUMMY_FIELD, 0, __VA_ARGS__) 370874aeea5SJeff Kirsher #define EFX_POPULATE_OWORD_7(oword, ...) \ 371874aeea5SJeff Kirsher EFX_POPULATE_OWORD_8(oword, EFX_DUMMY_FIELD, 0, __VA_ARGS__) 372874aeea5SJeff Kirsher #define EFX_POPULATE_OWORD_6(oword, ...) \ 373874aeea5SJeff Kirsher EFX_POPULATE_OWORD_7(oword, EFX_DUMMY_FIELD, 0, __VA_ARGS__) 374874aeea5SJeff Kirsher #define EFX_POPULATE_OWORD_5(oword, ...) \ 375874aeea5SJeff Kirsher EFX_POPULATE_OWORD_6(oword, EFX_DUMMY_FIELD, 0, __VA_ARGS__) 376874aeea5SJeff Kirsher #define EFX_POPULATE_OWORD_4(oword, ...) \ 377874aeea5SJeff Kirsher EFX_POPULATE_OWORD_5(oword, EFX_DUMMY_FIELD, 0, __VA_ARGS__) 378874aeea5SJeff Kirsher #define EFX_POPULATE_OWORD_3(oword, ...) \ 379874aeea5SJeff Kirsher EFX_POPULATE_OWORD_4(oword, EFX_DUMMY_FIELD, 0, __VA_ARGS__) 380874aeea5SJeff Kirsher #define EFX_POPULATE_OWORD_2(oword, ...) \ 381874aeea5SJeff Kirsher EFX_POPULATE_OWORD_3(oword, EFX_DUMMY_FIELD, 0, __VA_ARGS__) 382874aeea5SJeff Kirsher #define EFX_POPULATE_OWORD_1(oword, ...) \ 383874aeea5SJeff Kirsher EFX_POPULATE_OWORD_2(oword, EFX_DUMMY_FIELD, 0, __VA_ARGS__) 384874aeea5SJeff Kirsher #define EFX_ZERO_OWORD(oword) \ 385874aeea5SJeff Kirsher EFX_POPULATE_OWORD_1(oword, EFX_DUMMY_FIELD, 0) 386874aeea5SJeff Kirsher #define EFX_SET_OWORD(oword) \ 387874aeea5SJeff Kirsher EFX_POPULATE_OWORD_4(oword, \ 388874aeea5SJeff Kirsher EFX_DWORD_0, 0xffffffff, \ 389874aeea5SJeff Kirsher EFX_DWORD_1, 0xffffffff, \ 390874aeea5SJeff Kirsher EFX_DWORD_2, 0xffffffff, \ 391874aeea5SJeff Kirsher EFX_DWORD_3, 0xffffffff) 392874aeea5SJeff Kirsher 393874aeea5SJeff Kirsher /* Populate a quadword field with various numbers of arguments */ 394*a7a375caSEdward Cree #define EFX_POPULATE_QWORD_17 EFX_POPULATE_QWORD 395*a7a375caSEdward Cree #define EFX_POPULATE_QWORD_16(qword, ...) \ 396*a7a375caSEdward Cree EFX_POPULATE_QWORD_17(qword, EFX_DUMMY_FIELD, 0, __VA_ARGS__) 397*a7a375caSEdward Cree #define EFX_POPULATE_QWORD_15(qword, ...) \ 398*a7a375caSEdward Cree EFX_POPULATE_QWORD_16(qword, EFX_DUMMY_FIELD, 0, __VA_ARGS__) 399*a7a375caSEdward Cree #define EFX_POPULATE_QWORD_14(qword, ...) \ 400*a7a375caSEdward Cree EFX_POPULATE_QWORD_15(qword, EFX_DUMMY_FIELD, 0, __VA_ARGS__) 401*a7a375caSEdward Cree #define EFX_POPULATE_QWORD_13(qword, ...) \ 402*a7a375caSEdward Cree EFX_POPULATE_QWORD_14(qword, EFX_DUMMY_FIELD, 0, __VA_ARGS__) 40308f9912eSEdward Cree #define EFX_POPULATE_QWORD_12(qword, ...) \ 40408f9912eSEdward Cree EFX_POPULATE_QWORD_13(qword, EFX_DUMMY_FIELD, 0, __VA_ARGS__) 40508f9912eSEdward Cree #define EFX_POPULATE_QWORD_11(qword, ...) \ 40608f9912eSEdward Cree EFX_POPULATE_QWORD_12(qword, EFX_DUMMY_FIELD, 0, __VA_ARGS__) 40708f9912eSEdward Cree #define EFX_POPULATE_QWORD_10(qword, ...) \ 40808f9912eSEdward Cree EFX_POPULATE_QWORD_11(qword, EFX_DUMMY_FIELD, 0, __VA_ARGS__) 409874aeea5SJeff Kirsher #define EFX_POPULATE_QWORD_9(qword, ...) \ 410874aeea5SJeff Kirsher EFX_POPULATE_QWORD_10(qword, EFX_DUMMY_FIELD, 0, __VA_ARGS__) 411874aeea5SJeff Kirsher #define EFX_POPULATE_QWORD_8(qword, ...) \ 412874aeea5SJeff Kirsher EFX_POPULATE_QWORD_9(qword, EFX_DUMMY_FIELD, 0, __VA_ARGS__) 413874aeea5SJeff Kirsher #define EFX_POPULATE_QWORD_7(qword, ...) \ 414874aeea5SJeff Kirsher EFX_POPULATE_QWORD_8(qword, EFX_DUMMY_FIELD, 0, __VA_ARGS__) 415874aeea5SJeff Kirsher #define EFX_POPULATE_QWORD_6(qword, ...) \ 416874aeea5SJeff Kirsher EFX_POPULATE_QWORD_7(qword, EFX_DUMMY_FIELD, 0, __VA_ARGS__) 417874aeea5SJeff Kirsher #define EFX_POPULATE_QWORD_5(qword, ...) \ 418874aeea5SJeff Kirsher EFX_POPULATE_QWORD_6(qword, EFX_DUMMY_FIELD, 0, __VA_ARGS__) 419874aeea5SJeff Kirsher #define EFX_POPULATE_QWORD_4(qword, ...) \ 420874aeea5SJeff Kirsher EFX_POPULATE_QWORD_5(qword, EFX_DUMMY_FIELD, 0, __VA_ARGS__) 421874aeea5SJeff Kirsher #define EFX_POPULATE_QWORD_3(qword, ...) \ 422874aeea5SJeff Kirsher EFX_POPULATE_QWORD_4(qword, EFX_DUMMY_FIELD, 0, __VA_ARGS__) 423874aeea5SJeff Kirsher #define EFX_POPULATE_QWORD_2(qword, ...) \ 424874aeea5SJeff Kirsher EFX_POPULATE_QWORD_3(qword, EFX_DUMMY_FIELD, 0, __VA_ARGS__) 425874aeea5SJeff Kirsher #define EFX_POPULATE_QWORD_1(qword, ...) \ 426874aeea5SJeff Kirsher EFX_POPULATE_QWORD_2(qword, EFX_DUMMY_FIELD, 0, __VA_ARGS__) 427874aeea5SJeff Kirsher #define EFX_ZERO_QWORD(qword) \ 428874aeea5SJeff Kirsher EFX_POPULATE_QWORD_1(qword, EFX_DUMMY_FIELD, 0) 429874aeea5SJeff Kirsher #define EFX_SET_QWORD(qword) \ 430874aeea5SJeff Kirsher EFX_POPULATE_QWORD_2(qword, \ 431874aeea5SJeff Kirsher EFX_DWORD_0, 0xffffffff, \ 432874aeea5SJeff Kirsher EFX_DWORD_1, 0xffffffff) 433874aeea5SJeff Kirsher 434874aeea5SJeff Kirsher /* Populate a dword field with various numbers of arguments */ 435*a7a375caSEdward Cree #define EFX_POPULATE_DWORD_17 EFX_POPULATE_DWORD 436*a7a375caSEdward Cree #define EFX_POPULATE_DWORD_16(dword, ...) \ 437*a7a375caSEdward Cree EFX_POPULATE_DWORD_17(dword, EFX_DUMMY_FIELD, 0, __VA_ARGS__) 438*a7a375caSEdward Cree #define EFX_POPULATE_DWORD_15(dword, ...) \ 439*a7a375caSEdward Cree EFX_POPULATE_DWORD_16(dword, EFX_DUMMY_FIELD, 0, __VA_ARGS__) 440*a7a375caSEdward Cree #define EFX_POPULATE_DWORD_14(dword, ...) \ 441*a7a375caSEdward Cree EFX_POPULATE_DWORD_15(dword, EFX_DUMMY_FIELD, 0, __VA_ARGS__) 442*a7a375caSEdward Cree #define EFX_POPULATE_DWORD_13(dword, ...) \ 443*a7a375caSEdward Cree EFX_POPULATE_DWORD_14(dword, EFX_DUMMY_FIELD, 0, __VA_ARGS__) 44408f9912eSEdward Cree #define EFX_POPULATE_DWORD_12(dword, ...) \ 44508f9912eSEdward Cree EFX_POPULATE_DWORD_13(dword, EFX_DUMMY_FIELD, 0, __VA_ARGS__) 44608f9912eSEdward Cree #define EFX_POPULATE_DWORD_11(dword, ...) \ 44708f9912eSEdward Cree EFX_POPULATE_DWORD_12(dword, EFX_DUMMY_FIELD, 0, __VA_ARGS__) 44808f9912eSEdward Cree #define EFX_POPULATE_DWORD_10(dword, ...) \ 44908f9912eSEdward Cree EFX_POPULATE_DWORD_11(dword, EFX_DUMMY_FIELD, 0, __VA_ARGS__) 450874aeea5SJeff Kirsher #define EFX_POPULATE_DWORD_9(dword, ...) \ 451874aeea5SJeff Kirsher EFX_POPULATE_DWORD_10(dword, EFX_DUMMY_FIELD, 0, __VA_ARGS__) 452874aeea5SJeff Kirsher #define EFX_POPULATE_DWORD_8(dword, ...) \ 453874aeea5SJeff Kirsher EFX_POPULATE_DWORD_9(dword, EFX_DUMMY_FIELD, 0, __VA_ARGS__) 454874aeea5SJeff Kirsher #define EFX_POPULATE_DWORD_7(dword, ...) \ 455874aeea5SJeff Kirsher EFX_POPULATE_DWORD_8(dword, EFX_DUMMY_FIELD, 0, __VA_ARGS__) 456874aeea5SJeff Kirsher #define EFX_POPULATE_DWORD_6(dword, ...) \ 457874aeea5SJeff Kirsher EFX_POPULATE_DWORD_7(dword, EFX_DUMMY_FIELD, 0, __VA_ARGS__) 458874aeea5SJeff Kirsher #define EFX_POPULATE_DWORD_5(dword, ...) \ 459874aeea5SJeff Kirsher EFX_POPULATE_DWORD_6(dword, EFX_DUMMY_FIELD, 0, __VA_ARGS__) 460874aeea5SJeff Kirsher #define EFX_POPULATE_DWORD_4(dword, ...) \ 461874aeea5SJeff Kirsher EFX_POPULATE_DWORD_5(dword, EFX_DUMMY_FIELD, 0, __VA_ARGS__) 462874aeea5SJeff Kirsher #define EFX_POPULATE_DWORD_3(dword, ...) \ 463874aeea5SJeff Kirsher EFX_POPULATE_DWORD_4(dword, EFX_DUMMY_FIELD, 0, __VA_ARGS__) 464874aeea5SJeff Kirsher #define EFX_POPULATE_DWORD_2(dword, ...) \ 465874aeea5SJeff Kirsher EFX_POPULATE_DWORD_3(dword, EFX_DUMMY_FIELD, 0, __VA_ARGS__) 466874aeea5SJeff Kirsher #define EFX_POPULATE_DWORD_1(dword, ...) \ 467874aeea5SJeff Kirsher EFX_POPULATE_DWORD_2(dword, EFX_DUMMY_FIELD, 0, __VA_ARGS__) 468874aeea5SJeff Kirsher #define EFX_ZERO_DWORD(dword) \ 469874aeea5SJeff Kirsher EFX_POPULATE_DWORD_1(dword, EFX_DUMMY_FIELD, 0) 470874aeea5SJeff Kirsher #define EFX_SET_DWORD(dword) \ 471874aeea5SJeff Kirsher EFX_POPULATE_DWORD_1(dword, EFX_DWORD_0, 0xffffffff) 472874aeea5SJeff Kirsher 473874aeea5SJeff Kirsher /* 474874aeea5SJeff Kirsher * Modify a named field within an already-populated structure. Used 475874aeea5SJeff Kirsher * for read-modify-write operations. 476874aeea5SJeff Kirsher * 477874aeea5SJeff Kirsher */ 478874aeea5SJeff Kirsher #define EFX_INVERT_OWORD(oword) do { \ 479874aeea5SJeff Kirsher (oword).u64[0] = ~((oword).u64[0]); \ 480874aeea5SJeff Kirsher (oword).u64[1] = ~((oword).u64[1]); \ 481874aeea5SJeff Kirsher } while (0) 482874aeea5SJeff Kirsher 483874aeea5SJeff Kirsher #define EFX_AND_OWORD(oword, from, mask) \ 484874aeea5SJeff Kirsher do { \ 485874aeea5SJeff Kirsher (oword).u64[0] = (from).u64[0] & (mask).u64[0]; \ 486874aeea5SJeff Kirsher (oword).u64[1] = (from).u64[1] & (mask).u64[1]; \ 487874aeea5SJeff Kirsher } while (0) 488874aeea5SJeff Kirsher 489a0ee3541SJon Cooper #define EFX_AND_QWORD(qword, from, mask) \ 490a0ee3541SJon Cooper (qword).u64[0] = (from).u64[0] & (mask).u64[0] 491a0ee3541SJon Cooper 492874aeea5SJeff Kirsher #define EFX_OR_OWORD(oword, from, mask) \ 493874aeea5SJeff Kirsher do { \ 494874aeea5SJeff Kirsher (oword).u64[0] = (from).u64[0] | (mask).u64[0]; \ 495874aeea5SJeff Kirsher (oword).u64[1] = (from).u64[1] | (mask).u64[1]; \ 496874aeea5SJeff Kirsher } while (0) 497874aeea5SJeff Kirsher 498874aeea5SJeff Kirsher #define EFX_INSERT64(min, max, low, high, value) \ 499874aeea5SJeff Kirsher cpu_to_le64(EFX_INSERT_NATIVE(min, max, low, high, value)) 500874aeea5SJeff Kirsher 501874aeea5SJeff Kirsher #define EFX_INSERT32(min, max, low, high, value) \ 502874aeea5SJeff Kirsher cpu_to_le32(EFX_INSERT_NATIVE(min, max, low, high, value)) 503874aeea5SJeff Kirsher 504874aeea5SJeff Kirsher #define EFX_INPLACE_MASK64(min, max, low, high) \ 5059724a850SBen Hutchings EFX_INSERT64(min, max, low, high, EFX_MASK64((high) + 1 - (low))) 506874aeea5SJeff Kirsher 507874aeea5SJeff Kirsher #define EFX_INPLACE_MASK32(min, max, low, high) \ 5089724a850SBen Hutchings EFX_INSERT32(min, max, low, high, EFX_MASK32((high) + 1 - (low))) 509874aeea5SJeff Kirsher 510874aeea5SJeff Kirsher #define EFX_SET_OWORD64(oword, low, high, value) do { \ 511874aeea5SJeff Kirsher (oword).u64[0] = (((oword).u64[0] \ 512874aeea5SJeff Kirsher & ~EFX_INPLACE_MASK64(0, 63, low, high)) \ 513874aeea5SJeff Kirsher | EFX_INSERT64(0, 63, low, high, value)); \ 514874aeea5SJeff Kirsher (oword).u64[1] = (((oword).u64[1] \ 515874aeea5SJeff Kirsher & ~EFX_INPLACE_MASK64(64, 127, low, high)) \ 516874aeea5SJeff Kirsher | EFX_INSERT64(64, 127, low, high, value)); \ 517874aeea5SJeff Kirsher } while (0) 518874aeea5SJeff Kirsher 519874aeea5SJeff Kirsher #define EFX_SET_QWORD64(qword, low, high, value) do { \ 520874aeea5SJeff Kirsher (qword).u64[0] = (((qword).u64[0] \ 521874aeea5SJeff Kirsher & ~EFX_INPLACE_MASK64(0, 63, low, high)) \ 522874aeea5SJeff Kirsher | EFX_INSERT64(0, 63, low, high, value)); \ 523874aeea5SJeff Kirsher } while (0) 524874aeea5SJeff Kirsher 525874aeea5SJeff Kirsher #define EFX_SET_OWORD32(oword, low, high, value) do { \ 526874aeea5SJeff Kirsher (oword).u32[0] = (((oword).u32[0] \ 527874aeea5SJeff Kirsher & ~EFX_INPLACE_MASK32(0, 31, low, high)) \ 528874aeea5SJeff Kirsher | EFX_INSERT32(0, 31, low, high, value)); \ 529874aeea5SJeff Kirsher (oword).u32[1] = (((oword).u32[1] \ 530874aeea5SJeff Kirsher & ~EFX_INPLACE_MASK32(32, 63, low, high)) \ 531874aeea5SJeff Kirsher | EFX_INSERT32(32, 63, low, high, value)); \ 532874aeea5SJeff Kirsher (oword).u32[2] = (((oword).u32[2] \ 533874aeea5SJeff Kirsher & ~EFX_INPLACE_MASK32(64, 95, low, high)) \ 534874aeea5SJeff Kirsher | EFX_INSERT32(64, 95, low, high, value)); \ 535874aeea5SJeff Kirsher (oword).u32[3] = (((oword).u32[3] \ 536874aeea5SJeff Kirsher & ~EFX_INPLACE_MASK32(96, 127, low, high)) \ 537874aeea5SJeff Kirsher | EFX_INSERT32(96, 127, low, high, value)); \ 538874aeea5SJeff Kirsher } while (0) 539874aeea5SJeff Kirsher 540874aeea5SJeff Kirsher #define EFX_SET_QWORD32(qword, low, high, value) do { \ 541874aeea5SJeff Kirsher (qword).u32[0] = (((qword).u32[0] \ 542874aeea5SJeff Kirsher & ~EFX_INPLACE_MASK32(0, 31, low, high)) \ 543874aeea5SJeff Kirsher | EFX_INSERT32(0, 31, low, high, value)); \ 544874aeea5SJeff Kirsher (qword).u32[1] = (((qword).u32[1] \ 545874aeea5SJeff Kirsher & ~EFX_INPLACE_MASK32(32, 63, low, high)) \ 546874aeea5SJeff Kirsher | EFX_INSERT32(32, 63, low, high, value)); \ 547874aeea5SJeff Kirsher } while (0) 548874aeea5SJeff Kirsher 549874aeea5SJeff Kirsher #define EFX_SET_DWORD32(dword, low, high, value) do { \ 550874aeea5SJeff Kirsher (dword).u32[0] = (((dword).u32[0] \ 551874aeea5SJeff Kirsher & ~EFX_INPLACE_MASK32(0, 31, low, high)) \ 552874aeea5SJeff Kirsher | EFX_INSERT32(0, 31, low, high, value)); \ 553874aeea5SJeff Kirsher } while (0) 554874aeea5SJeff Kirsher 555874aeea5SJeff Kirsher #define EFX_SET_OWORD_FIELD64(oword, field, value) \ 556874aeea5SJeff Kirsher EFX_SET_OWORD64(oword, EFX_LOW_BIT(field), \ 557874aeea5SJeff Kirsher EFX_HIGH_BIT(field), value) 558874aeea5SJeff Kirsher 559874aeea5SJeff Kirsher #define EFX_SET_QWORD_FIELD64(qword, field, value) \ 560874aeea5SJeff Kirsher EFX_SET_QWORD64(qword, EFX_LOW_BIT(field), \ 561874aeea5SJeff Kirsher EFX_HIGH_BIT(field), value) 562874aeea5SJeff Kirsher 563874aeea5SJeff Kirsher #define EFX_SET_OWORD_FIELD32(oword, field, value) \ 564874aeea5SJeff Kirsher EFX_SET_OWORD32(oword, EFX_LOW_BIT(field), \ 565874aeea5SJeff Kirsher EFX_HIGH_BIT(field), value) 566874aeea5SJeff Kirsher 567874aeea5SJeff Kirsher #define EFX_SET_QWORD_FIELD32(qword, field, value) \ 568874aeea5SJeff Kirsher EFX_SET_QWORD32(qword, EFX_LOW_BIT(field), \ 569874aeea5SJeff Kirsher EFX_HIGH_BIT(field), value) 570874aeea5SJeff Kirsher 571874aeea5SJeff Kirsher #define EFX_SET_DWORD_FIELD(dword, field, value) \ 572874aeea5SJeff Kirsher EFX_SET_DWORD32(dword, EFX_LOW_BIT(field), \ 573874aeea5SJeff Kirsher EFX_HIGH_BIT(field), value) 574874aeea5SJeff Kirsher 575874aeea5SJeff Kirsher 576874aeea5SJeff Kirsher 577874aeea5SJeff Kirsher #if BITS_PER_LONG == 64 578874aeea5SJeff Kirsher #define EFX_SET_OWORD_FIELD EFX_SET_OWORD_FIELD64 579874aeea5SJeff Kirsher #define EFX_SET_QWORD_FIELD EFX_SET_QWORD_FIELD64 580874aeea5SJeff Kirsher #else 581874aeea5SJeff Kirsher #define EFX_SET_OWORD_FIELD EFX_SET_OWORD_FIELD32 582874aeea5SJeff Kirsher #define EFX_SET_QWORD_FIELD EFX_SET_QWORD_FIELD32 583874aeea5SJeff Kirsher #endif 584874aeea5SJeff Kirsher 585874aeea5SJeff Kirsher /* Used to avoid compiler warnings about shift range exceeding width 586874aeea5SJeff Kirsher * of the data types when dma_addr_t is only 32 bits wide. 587874aeea5SJeff Kirsher */ 588874aeea5SJeff Kirsher #define DMA_ADDR_T_WIDTH (8 * sizeof(dma_addr_t)) 589874aeea5SJeff Kirsher #define EFX_DMA_TYPE_WIDTH(width) \ 590874aeea5SJeff Kirsher (((width) < DMA_ADDR_T_WIDTH) ? (width) : DMA_ADDR_T_WIDTH) 591874aeea5SJeff Kirsher 592874aeea5SJeff Kirsher 593874aeea5SJeff Kirsher /* Static initialiser */ 594874aeea5SJeff Kirsher #define EFX_OWORD32(a, b, c, d) \ 595874aeea5SJeff Kirsher { .u32 = { cpu_to_le32(a), cpu_to_le32(b), \ 596874aeea5SJeff Kirsher cpu_to_le32(c), cpu_to_le32(d) } } 597874aeea5SJeff Kirsher 598874aeea5SJeff Kirsher #endif /* EFX_BITFIELD_H */ 599