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 29*01ad088fSEdward Cree #define EFX_BYTE_0_LBN 0 30*01ad088fSEdward Cree #define EFX_BYTE_0_WIDTH 8 318127d661SBen Hutchings #define EFX_WORD_0_LBN 0 328127d661SBen Hutchings #define EFX_WORD_0_WIDTH 16 338127d661SBen Hutchings #define EFX_WORD_1_LBN 16 348127d661SBen Hutchings #define EFX_WORD_1_WIDTH 16 35874aeea5SJeff Kirsher #define EFX_DWORD_0_LBN 0 36874aeea5SJeff Kirsher #define EFX_DWORD_0_WIDTH 32 37874aeea5SJeff Kirsher #define EFX_DWORD_1_LBN 32 38874aeea5SJeff Kirsher #define EFX_DWORD_1_WIDTH 32 39874aeea5SJeff Kirsher #define EFX_DWORD_2_LBN 64 40874aeea5SJeff Kirsher #define EFX_DWORD_2_WIDTH 32 41874aeea5SJeff Kirsher #define EFX_DWORD_3_LBN 96 42874aeea5SJeff Kirsher #define EFX_DWORD_3_WIDTH 32 43874aeea5SJeff Kirsher #define EFX_QWORD_0_LBN 0 44874aeea5SJeff Kirsher #define EFX_QWORD_0_WIDTH 64 45874aeea5SJeff Kirsher 46874aeea5SJeff Kirsher /* Specified attribute (e.g. LBN) of the specified field */ 47874aeea5SJeff Kirsher #define EFX_VAL(field, attribute) field ## _ ## attribute 48874aeea5SJeff Kirsher /* Low bit number of the specified field */ 49874aeea5SJeff Kirsher #define EFX_LOW_BIT(field) EFX_VAL(field, LBN) 50874aeea5SJeff Kirsher /* Bit width of the specified field */ 51874aeea5SJeff Kirsher #define EFX_WIDTH(field) EFX_VAL(field, WIDTH) 52874aeea5SJeff Kirsher /* High bit number of the specified field */ 53874aeea5SJeff Kirsher #define EFX_HIGH_BIT(field) (EFX_LOW_BIT(field) + EFX_WIDTH(field) - 1) 54874aeea5SJeff Kirsher /* Mask equal in width to the specified field. 55874aeea5SJeff Kirsher * 56874aeea5SJeff Kirsher * For example, a field with width 5 would have a mask of 0x1f. 57874aeea5SJeff Kirsher * 58874aeea5SJeff Kirsher * The maximum width mask that can be generated is 64 bits. 59874aeea5SJeff Kirsher */ 60874aeea5SJeff Kirsher #define EFX_MASK64(width) \ 61874aeea5SJeff Kirsher ((width) == 64 ? ~((u64) 0) : \ 62874aeea5SJeff Kirsher (((((u64) 1) << (width))) - 1)) 63874aeea5SJeff Kirsher 64874aeea5SJeff Kirsher /* Mask equal in width to the specified field. 65874aeea5SJeff Kirsher * 66874aeea5SJeff Kirsher * For example, a field with width 5 would have a mask of 0x1f. 67874aeea5SJeff Kirsher * 68874aeea5SJeff Kirsher * The maximum width mask that can be generated is 32 bits. Use 69874aeea5SJeff Kirsher * EFX_MASK64 for higher width fields. 70874aeea5SJeff Kirsher */ 71874aeea5SJeff Kirsher #define EFX_MASK32(width) \ 72874aeea5SJeff Kirsher ((width) == 32 ? ~((u32) 0) : \ 73874aeea5SJeff Kirsher (((((u32) 1) << (width))) - 1)) 74874aeea5SJeff Kirsher 75874aeea5SJeff Kirsher /* A doubleword (i.e. 4 byte) datatype - little-endian in HW */ 76874aeea5SJeff Kirsher typedef union efx_dword { 77874aeea5SJeff Kirsher __le32 u32[1]; 78874aeea5SJeff Kirsher } efx_dword_t; 79874aeea5SJeff Kirsher 80874aeea5SJeff Kirsher /* A quadword (i.e. 8 byte) datatype - little-endian in HW */ 81874aeea5SJeff Kirsher typedef union efx_qword { 82874aeea5SJeff Kirsher __le64 u64[1]; 83874aeea5SJeff Kirsher __le32 u32[2]; 84874aeea5SJeff Kirsher efx_dword_t dword[2]; 85874aeea5SJeff Kirsher } efx_qword_t; 86874aeea5SJeff Kirsher 87874aeea5SJeff Kirsher /* An octword (eight-word, i.e. 16 byte) datatype - little-endian in HW */ 88874aeea5SJeff Kirsher typedef union efx_oword { 89874aeea5SJeff Kirsher __le64 u64[2]; 90874aeea5SJeff Kirsher efx_qword_t qword[2]; 91874aeea5SJeff Kirsher __le32 u32[4]; 92874aeea5SJeff Kirsher efx_dword_t dword[4]; 93874aeea5SJeff Kirsher } efx_oword_t; 94874aeea5SJeff Kirsher 95874aeea5SJeff Kirsher /* Format string and value expanders for printk */ 96874aeea5SJeff Kirsher #define EFX_DWORD_FMT "%08x" 97874aeea5SJeff Kirsher #define EFX_QWORD_FMT "%08x:%08x" 98874aeea5SJeff Kirsher #define EFX_OWORD_FMT "%08x:%08x:%08x:%08x" 99874aeea5SJeff Kirsher #define EFX_DWORD_VAL(dword) \ 100874aeea5SJeff Kirsher ((unsigned int) le32_to_cpu((dword).u32[0])) 101874aeea5SJeff Kirsher #define EFX_QWORD_VAL(qword) \ 102874aeea5SJeff Kirsher ((unsigned int) le32_to_cpu((qword).u32[1])), \ 103874aeea5SJeff Kirsher ((unsigned int) le32_to_cpu((qword).u32[0])) 104874aeea5SJeff Kirsher #define EFX_OWORD_VAL(oword) \ 105874aeea5SJeff Kirsher ((unsigned int) le32_to_cpu((oword).u32[3])), \ 106874aeea5SJeff Kirsher ((unsigned int) le32_to_cpu((oword).u32[2])), \ 107874aeea5SJeff Kirsher ((unsigned int) le32_to_cpu((oword).u32[1])), \ 108874aeea5SJeff Kirsher ((unsigned int) le32_to_cpu((oword).u32[0])) 109874aeea5SJeff Kirsher 110874aeea5SJeff Kirsher /* 111874aeea5SJeff Kirsher * Extract bit field portion [low,high) from the native-endian element 112874aeea5SJeff Kirsher * which contains bits [min,max). 113874aeea5SJeff Kirsher * 114874aeea5SJeff Kirsher * For example, suppose "element" represents the high 32 bits of a 115874aeea5SJeff Kirsher * 64-bit value, and we wish to extract the bits belonging to the bit 116874aeea5SJeff Kirsher * field occupying bits 28-45 of this 64-bit value. 117874aeea5SJeff Kirsher * 118874aeea5SJeff Kirsher * Then EFX_EXTRACT ( element, 32, 63, 28, 45 ) would give 119874aeea5SJeff Kirsher * 120874aeea5SJeff Kirsher * ( element ) << 4 121874aeea5SJeff Kirsher * 122874aeea5SJeff Kirsher * The result will contain the relevant bits filled in in the range 123874aeea5SJeff Kirsher * [0,high-low), with garbage in bits [high-low+1,...). 124874aeea5SJeff Kirsher */ 125874aeea5SJeff Kirsher #define EFX_EXTRACT_NATIVE(native_element, min, max, low, high) \ 1269724a850SBen Hutchings ((low) > (max) || (high) < (min) ? 0 : \ 1279724a850SBen Hutchings (low) > (min) ? \ 1289724a850SBen Hutchings (native_element) >> ((low) - (min)) : \ 1299724a850SBen Hutchings (native_element) << ((min) - (low))) 130874aeea5SJeff Kirsher 131874aeea5SJeff Kirsher /* 132874aeea5SJeff Kirsher * Extract bit field portion [low,high) from the 64-bit little-endian 133874aeea5SJeff Kirsher * element which contains bits [min,max) 134874aeea5SJeff Kirsher */ 135874aeea5SJeff Kirsher #define EFX_EXTRACT64(element, min, max, low, high) \ 136874aeea5SJeff Kirsher EFX_EXTRACT_NATIVE(le64_to_cpu(element), min, max, low, high) 137874aeea5SJeff Kirsher 138874aeea5SJeff Kirsher /* 139874aeea5SJeff Kirsher * Extract bit field portion [low,high) from the 32-bit little-endian 140874aeea5SJeff Kirsher * element which contains bits [min,max) 141874aeea5SJeff Kirsher */ 142874aeea5SJeff Kirsher #define EFX_EXTRACT32(element, min, max, low, high) \ 143874aeea5SJeff Kirsher EFX_EXTRACT_NATIVE(le32_to_cpu(element), min, max, low, high) 144874aeea5SJeff Kirsher 145874aeea5SJeff Kirsher #define EFX_EXTRACT_OWORD64(oword, low, high) \ 146874aeea5SJeff Kirsher ((EFX_EXTRACT64((oword).u64[0], 0, 63, low, high) | \ 147874aeea5SJeff Kirsher EFX_EXTRACT64((oword).u64[1], 64, 127, low, high)) & \ 1489724a850SBen Hutchings EFX_MASK64((high) + 1 - (low))) 149874aeea5SJeff Kirsher 150874aeea5SJeff Kirsher #define EFX_EXTRACT_QWORD64(qword, low, high) \ 151874aeea5SJeff Kirsher (EFX_EXTRACT64((qword).u64[0], 0, 63, low, high) & \ 1529724a850SBen Hutchings EFX_MASK64((high) + 1 - (low))) 153874aeea5SJeff Kirsher 154874aeea5SJeff Kirsher #define EFX_EXTRACT_OWORD32(oword, low, high) \ 155874aeea5SJeff Kirsher ((EFX_EXTRACT32((oword).u32[0], 0, 31, low, high) | \ 156874aeea5SJeff Kirsher EFX_EXTRACT32((oword).u32[1], 32, 63, low, high) | \ 157874aeea5SJeff Kirsher EFX_EXTRACT32((oword).u32[2], 64, 95, low, high) | \ 158874aeea5SJeff Kirsher EFX_EXTRACT32((oword).u32[3], 96, 127, low, high)) & \ 1599724a850SBen Hutchings EFX_MASK32((high) + 1 - (low))) 160874aeea5SJeff Kirsher 161874aeea5SJeff Kirsher #define EFX_EXTRACT_QWORD32(qword, low, high) \ 162874aeea5SJeff Kirsher ((EFX_EXTRACT32((qword).u32[0], 0, 31, low, high) | \ 163874aeea5SJeff Kirsher EFX_EXTRACT32((qword).u32[1], 32, 63, low, high)) & \ 1649724a850SBen Hutchings EFX_MASK32((high) + 1 - (low))) 165874aeea5SJeff Kirsher 166874aeea5SJeff Kirsher #define EFX_EXTRACT_DWORD(dword, low, high) \ 167874aeea5SJeff Kirsher (EFX_EXTRACT32((dword).u32[0], 0, 31, low, high) & \ 1689724a850SBen Hutchings EFX_MASK32((high) + 1 - (low))) 169874aeea5SJeff Kirsher 170874aeea5SJeff Kirsher #define EFX_OWORD_FIELD64(oword, field) \ 171874aeea5SJeff Kirsher EFX_EXTRACT_OWORD64(oword, EFX_LOW_BIT(field), \ 172874aeea5SJeff Kirsher EFX_HIGH_BIT(field)) 173874aeea5SJeff Kirsher 174874aeea5SJeff Kirsher #define EFX_QWORD_FIELD64(qword, field) \ 175874aeea5SJeff Kirsher EFX_EXTRACT_QWORD64(qword, EFX_LOW_BIT(field), \ 176874aeea5SJeff Kirsher EFX_HIGH_BIT(field)) 177874aeea5SJeff Kirsher 178874aeea5SJeff Kirsher #define EFX_OWORD_FIELD32(oword, field) \ 179874aeea5SJeff Kirsher EFX_EXTRACT_OWORD32(oword, EFX_LOW_BIT(field), \ 180874aeea5SJeff Kirsher EFX_HIGH_BIT(field)) 181874aeea5SJeff Kirsher 182874aeea5SJeff Kirsher #define EFX_QWORD_FIELD32(qword, field) \ 183874aeea5SJeff Kirsher EFX_EXTRACT_QWORD32(qword, EFX_LOW_BIT(field), \ 184874aeea5SJeff Kirsher EFX_HIGH_BIT(field)) 185874aeea5SJeff Kirsher 186874aeea5SJeff Kirsher #define EFX_DWORD_FIELD(dword, field) \ 187874aeea5SJeff Kirsher EFX_EXTRACT_DWORD(dword, EFX_LOW_BIT(field), \ 188874aeea5SJeff Kirsher EFX_HIGH_BIT(field)) 189874aeea5SJeff Kirsher 190874aeea5SJeff Kirsher #define EFX_OWORD_IS_ZERO64(oword) \ 191874aeea5SJeff Kirsher (((oword).u64[0] | (oword).u64[1]) == (__force __le64) 0) 192874aeea5SJeff Kirsher 193874aeea5SJeff Kirsher #define EFX_QWORD_IS_ZERO64(qword) \ 194874aeea5SJeff Kirsher (((qword).u64[0]) == (__force __le64) 0) 195874aeea5SJeff Kirsher 196874aeea5SJeff Kirsher #define EFX_OWORD_IS_ZERO32(oword) \ 197874aeea5SJeff Kirsher (((oword).u32[0] | (oword).u32[1] | (oword).u32[2] | (oword).u32[3]) \ 198874aeea5SJeff Kirsher == (__force __le32) 0) 199874aeea5SJeff Kirsher 200874aeea5SJeff Kirsher #define EFX_QWORD_IS_ZERO32(qword) \ 201874aeea5SJeff Kirsher (((qword).u32[0] | (qword).u32[1]) == (__force __le32) 0) 202874aeea5SJeff Kirsher 203874aeea5SJeff Kirsher #define EFX_DWORD_IS_ZERO(dword) \ 204874aeea5SJeff Kirsher (((dword).u32[0]) == (__force __le32) 0) 205874aeea5SJeff Kirsher 206874aeea5SJeff Kirsher #define EFX_OWORD_IS_ALL_ONES64(oword) \ 207874aeea5SJeff Kirsher (((oword).u64[0] & (oword).u64[1]) == ~((__force __le64) 0)) 208874aeea5SJeff Kirsher 209874aeea5SJeff Kirsher #define EFX_QWORD_IS_ALL_ONES64(qword) \ 210874aeea5SJeff Kirsher ((qword).u64[0] == ~((__force __le64) 0)) 211874aeea5SJeff Kirsher 212874aeea5SJeff Kirsher #define EFX_OWORD_IS_ALL_ONES32(oword) \ 213874aeea5SJeff Kirsher (((oword).u32[0] & (oword).u32[1] & (oword).u32[2] & (oword).u32[3]) \ 214874aeea5SJeff Kirsher == ~((__force __le32) 0)) 215874aeea5SJeff Kirsher 216874aeea5SJeff Kirsher #define EFX_QWORD_IS_ALL_ONES32(qword) \ 217874aeea5SJeff Kirsher (((qword).u32[0] & (qword).u32[1]) == ~((__force __le32) 0)) 218874aeea5SJeff Kirsher 219874aeea5SJeff Kirsher #define EFX_DWORD_IS_ALL_ONES(dword) \ 220874aeea5SJeff Kirsher ((dword).u32[0] == ~((__force __le32) 0)) 221874aeea5SJeff Kirsher 222874aeea5SJeff Kirsher #if BITS_PER_LONG == 64 223874aeea5SJeff Kirsher #define EFX_OWORD_FIELD EFX_OWORD_FIELD64 224874aeea5SJeff Kirsher #define EFX_QWORD_FIELD EFX_QWORD_FIELD64 225874aeea5SJeff Kirsher #define EFX_OWORD_IS_ZERO EFX_OWORD_IS_ZERO64 226874aeea5SJeff Kirsher #define EFX_QWORD_IS_ZERO EFX_QWORD_IS_ZERO64 227874aeea5SJeff Kirsher #define EFX_OWORD_IS_ALL_ONES EFX_OWORD_IS_ALL_ONES64 228874aeea5SJeff Kirsher #define EFX_QWORD_IS_ALL_ONES EFX_QWORD_IS_ALL_ONES64 229874aeea5SJeff Kirsher #else 230874aeea5SJeff Kirsher #define EFX_OWORD_FIELD EFX_OWORD_FIELD32 231874aeea5SJeff Kirsher #define EFX_QWORD_FIELD EFX_QWORD_FIELD32 232874aeea5SJeff Kirsher #define EFX_OWORD_IS_ZERO EFX_OWORD_IS_ZERO32 233874aeea5SJeff Kirsher #define EFX_QWORD_IS_ZERO EFX_QWORD_IS_ZERO32 234874aeea5SJeff Kirsher #define EFX_OWORD_IS_ALL_ONES EFX_OWORD_IS_ALL_ONES32 235874aeea5SJeff Kirsher #define EFX_QWORD_IS_ALL_ONES EFX_QWORD_IS_ALL_ONES32 236874aeea5SJeff Kirsher #endif 237874aeea5SJeff Kirsher 238874aeea5SJeff Kirsher /* 239874aeea5SJeff Kirsher * Construct bit field portion 240874aeea5SJeff Kirsher * 241874aeea5SJeff Kirsher * Creates the portion of the bit field [low,high) that lies within 242874aeea5SJeff Kirsher * the range [min,max). 243874aeea5SJeff Kirsher */ 244874aeea5SJeff Kirsher #define EFX_INSERT_NATIVE64(min, max, low, high, value) \ 245874aeea5SJeff Kirsher (((low > max) || (high < min)) ? 0 : \ 246874aeea5SJeff Kirsher ((low > min) ? \ 247874aeea5SJeff Kirsher (((u64) (value)) << (low - min)) : \ 248874aeea5SJeff Kirsher (((u64) (value)) >> (min - low)))) 249874aeea5SJeff Kirsher 250874aeea5SJeff Kirsher #define EFX_INSERT_NATIVE32(min, max, low, high, value) \ 251874aeea5SJeff Kirsher (((low > max) || (high < min)) ? 0 : \ 252874aeea5SJeff Kirsher ((low > min) ? \ 253874aeea5SJeff Kirsher (((u32) (value)) << (low - min)) : \ 254874aeea5SJeff Kirsher (((u32) (value)) >> (min - low)))) 255874aeea5SJeff Kirsher 256874aeea5SJeff Kirsher #define EFX_INSERT_NATIVE(min, max, low, high, value) \ 257874aeea5SJeff Kirsher ((((max - min) >= 32) || ((high - low) >= 32)) ? \ 258874aeea5SJeff Kirsher EFX_INSERT_NATIVE64(min, max, low, high, value) : \ 259874aeea5SJeff Kirsher EFX_INSERT_NATIVE32(min, max, low, high, value)) 260874aeea5SJeff Kirsher 261874aeea5SJeff Kirsher /* 262874aeea5SJeff Kirsher * Construct bit field portion 263874aeea5SJeff Kirsher * 264874aeea5SJeff Kirsher * Creates the portion of the named bit field that lies within the 265874aeea5SJeff Kirsher * range [min,max). 266874aeea5SJeff Kirsher */ 267874aeea5SJeff Kirsher #define EFX_INSERT_FIELD_NATIVE(min, max, field, value) \ 268874aeea5SJeff Kirsher EFX_INSERT_NATIVE(min, max, EFX_LOW_BIT(field), \ 269874aeea5SJeff Kirsher EFX_HIGH_BIT(field), value) 270874aeea5SJeff Kirsher 271874aeea5SJeff Kirsher /* 272874aeea5SJeff Kirsher * Construct bit field 273874aeea5SJeff Kirsher * 274874aeea5SJeff Kirsher * Creates the portion of the named bit fields that lie within the 275874aeea5SJeff Kirsher * range [min,max). 276874aeea5SJeff Kirsher */ 277874aeea5SJeff Kirsher #define EFX_INSERT_FIELDS_NATIVE(min, max, \ 278874aeea5SJeff Kirsher field1, value1, \ 279874aeea5SJeff Kirsher field2, value2, \ 280874aeea5SJeff Kirsher field3, value3, \ 281874aeea5SJeff Kirsher field4, value4, \ 282874aeea5SJeff Kirsher field5, value5, \ 283874aeea5SJeff Kirsher field6, value6, \ 284874aeea5SJeff Kirsher field7, value7, \ 285874aeea5SJeff Kirsher field8, value8, \ 286874aeea5SJeff Kirsher field9, value9, \ 28708f9912eSEdward Cree field10, value10, \ 28808f9912eSEdward Cree field11, value11, \ 28908f9912eSEdward Cree field12, value12, \ 290a7a375caSEdward Cree field13, value13, \ 291a7a375caSEdward Cree field14, value14, \ 292a7a375caSEdward Cree field15, value15, \ 293a7a375caSEdward Cree field16, value16, \ 294dc8d2512SEdward Cree field17, value17, \ 295dc8d2512SEdward Cree field18, value18, \ 296dc8d2512SEdward Cree field19, value19) \ 297874aeea5SJeff Kirsher (EFX_INSERT_FIELD_NATIVE((min), (max), field1, (value1)) | \ 298874aeea5SJeff Kirsher EFX_INSERT_FIELD_NATIVE((min), (max), field2, (value2)) | \ 299874aeea5SJeff Kirsher EFX_INSERT_FIELD_NATIVE((min), (max), field3, (value3)) | \ 300874aeea5SJeff Kirsher EFX_INSERT_FIELD_NATIVE((min), (max), field4, (value4)) | \ 301874aeea5SJeff Kirsher EFX_INSERT_FIELD_NATIVE((min), (max), field5, (value5)) | \ 302874aeea5SJeff Kirsher EFX_INSERT_FIELD_NATIVE((min), (max), field6, (value6)) | \ 303874aeea5SJeff Kirsher EFX_INSERT_FIELD_NATIVE((min), (max), field7, (value7)) | \ 304874aeea5SJeff Kirsher EFX_INSERT_FIELD_NATIVE((min), (max), field8, (value8)) | \ 305874aeea5SJeff Kirsher EFX_INSERT_FIELD_NATIVE((min), (max), field9, (value9)) | \ 30608f9912eSEdward Cree EFX_INSERT_FIELD_NATIVE((min), (max), field10, (value10)) | \ 30708f9912eSEdward Cree EFX_INSERT_FIELD_NATIVE((min), (max), field11, (value11)) | \ 30808f9912eSEdward Cree EFX_INSERT_FIELD_NATIVE((min), (max), field12, (value12)) | \ 309a7a375caSEdward Cree EFX_INSERT_FIELD_NATIVE((min), (max), field13, (value13)) | \ 310a7a375caSEdward Cree EFX_INSERT_FIELD_NATIVE((min), (max), field14, (value14)) | \ 311a7a375caSEdward Cree EFX_INSERT_FIELD_NATIVE((min), (max), field15, (value15)) | \ 312a7a375caSEdward Cree EFX_INSERT_FIELD_NATIVE((min), (max), field16, (value16)) | \ 313dc8d2512SEdward Cree EFX_INSERT_FIELD_NATIVE((min), (max), field17, (value17)) | \ 314dc8d2512SEdward Cree EFX_INSERT_FIELD_NATIVE((min), (max), field18, (value18)) | \ 315dc8d2512SEdward Cree EFX_INSERT_FIELD_NATIVE((min), (max), field19, (value19))) 316874aeea5SJeff Kirsher 317874aeea5SJeff Kirsher #define EFX_INSERT_FIELDS64(...) \ 318874aeea5SJeff Kirsher cpu_to_le64(EFX_INSERT_FIELDS_NATIVE(__VA_ARGS__)) 319874aeea5SJeff Kirsher 320874aeea5SJeff Kirsher #define EFX_INSERT_FIELDS32(...) \ 321874aeea5SJeff Kirsher cpu_to_le32(EFX_INSERT_FIELDS_NATIVE(__VA_ARGS__)) 322874aeea5SJeff Kirsher 323874aeea5SJeff Kirsher #define EFX_POPULATE_OWORD64(oword, ...) do { \ 324874aeea5SJeff Kirsher (oword).u64[0] = EFX_INSERT_FIELDS64(0, 63, __VA_ARGS__); \ 325874aeea5SJeff Kirsher (oword).u64[1] = EFX_INSERT_FIELDS64(64, 127, __VA_ARGS__); \ 326874aeea5SJeff Kirsher } while (0) 327874aeea5SJeff Kirsher 328874aeea5SJeff Kirsher #define EFX_POPULATE_QWORD64(qword, ...) do { \ 329874aeea5SJeff Kirsher (qword).u64[0] = EFX_INSERT_FIELDS64(0, 63, __VA_ARGS__); \ 330874aeea5SJeff Kirsher } while (0) 331874aeea5SJeff Kirsher 332874aeea5SJeff Kirsher #define EFX_POPULATE_OWORD32(oword, ...) do { \ 333874aeea5SJeff Kirsher (oword).u32[0] = EFX_INSERT_FIELDS32(0, 31, __VA_ARGS__); \ 334874aeea5SJeff Kirsher (oword).u32[1] = EFX_INSERT_FIELDS32(32, 63, __VA_ARGS__); \ 335874aeea5SJeff Kirsher (oword).u32[2] = EFX_INSERT_FIELDS32(64, 95, __VA_ARGS__); \ 336874aeea5SJeff Kirsher (oword).u32[3] = EFX_INSERT_FIELDS32(96, 127, __VA_ARGS__); \ 337874aeea5SJeff Kirsher } while (0) 338874aeea5SJeff Kirsher 339874aeea5SJeff Kirsher #define EFX_POPULATE_QWORD32(qword, ...) do { \ 340874aeea5SJeff Kirsher (qword).u32[0] = EFX_INSERT_FIELDS32(0, 31, __VA_ARGS__); \ 341874aeea5SJeff Kirsher (qword).u32[1] = EFX_INSERT_FIELDS32(32, 63, __VA_ARGS__); \ 342874aeea5SJeff Kirsher } while (0) 343874aeea5SJeff Kirsher 344874aeea5SJeff Kirsher #define EFX_POPULATE_DWORD(dword, ...) do { \ 345874aeea5SJeff Kirsher (dword).u32[0] = EFX_INSERT_FIELDS32(0, 31, __VA_ARGS__); \ 346874aeea5SJeff Kirsher } while (0) 347874aeea5SJeff Kirsher 348874aeea5SJeff Kirsher #if BITS_PER_LONG == 64 349874aeea5SJeff Kirsher #define EFX_POPULATE_OWORD EFX_POPULATE_OWORD64 350874aeea5SJeff Kirsher #define EFX_POPULATE_QWORD EFX_POPULATE_QWORD64 351874aeea5SJeff Kirsher #else 352874aeea5SJeff Kirsher #define EFX_POPULATE_OWORD EFX_POPULATE_OWORD32 353874aeea5SJeff Kirsher #define EFX_POPULATE_QWORD EFX_POPULATE_QWORD32 354874aeea5SJeff Kirsher #endif 355874aeea5SJeff Kirsher 356874aeea5SJeff Kirsher /* Populate an octword field with various numbers of arguments */ 357dc8d2512SEdward Cree #define EFX_POPULATE_OWORD_19 EFX_POPULATE_OWORD 358dc8d2512SEdward Cree #define EFX_POPULATE_OWORD_18(oword, ...) \ 359dc8d2512SEdward Cree EFX_POPULATE_OWORD_19(oword, EFX_DUMMY_FIELD, 0, __VA_ARGS__) 360dc8d2512SEdward Cree #define EFX_POPULATE_OWORD_17(oword, ...) \ 361dc8d2512SEdward Cree EFX_POPULATE_OWORD_18(oword, EFX_DUMMY_FIELD, 0, __VA_ARGS__) 362a7a375caSEdward Cree #define EFX_POPULATE_OWORD_16(oword, ...) \ 363a7a375caSEdward Cree EFX_POPULATE_OWORD_17(oword, EFX_DUMMY_FIELD, 0, __VA_ARGS__) 364a7a375caSEdward Cree #define EFX_POPULATE_OWORD_15(oword, ...) \ 365a7a375caSEdward Cree EFX_POPULATE_OWORD_16(oword, EFX_DUMMY_FIELD, 0, __VA_ARGS__) 366a7a375caSEdward Cree #define EFX_POPULATE_OWORD_14(oword, ...) \ 367a7a375caSEdward Cree EFX_POPULATE_OWORD_15(oword, EFX_DUMMY_FIELD, 0, __VA_ARGS__) 368a7a375caSEdward Cree #define EFX_POPULATE_OWORD_13(oword, ...) \ 369a7a375caSEdward Cree EFX_POPULATE_OWORD_14(oword, EFX_DUMMY_FIELD, 0, __VA_ARGS__) 37008f9912eSEdward Cree #define EFX_POPULATE_OWORD_12(oword, ...) \ 37108f9912eSEdward Cree EFX_POPULATE_OWORD_13(oword, EFX_DUMMY_FIELD, 0, __VA_ARGS__) 37208f9912eSEdward Cree #define EFX_POPULATE_OWORD_11(oword, ...) \ 37308f9912eSEdward Cree EFX_POPULATE_OWORD_12(oword, EFX_DUMMY_FIELD, 0, __VA_ARGS__) 37408f9912eSEdward Cree #define EFX_POPULATE_OWORD_10(oword, ...) \ 37508f9912eSEdward Cree EFX_POPULATE_OWORD_11(oword, EFX_DUMMY_FIELD, 0, __VA_ARGS__) 376874aeea5SJeff Kirsher #define EFX_POPULATE_OWORD_9(oword, ...) \ 377874aeea5SJeff Kirsher EFX_POPULATE_OWORD_10(oword, EFX_DUMMY_FIELD, 0, __VA_ARGS__) 378874aeea5SJeff Kirsher #define EFX_POPULATE_OWORD_8(oword, ...) \ 379874aeea5SJeff Kirsher EFX_POPULATE_OWORD_9(oword, EFX_DUMMY_FIELD, 0, __VA_ARGS__) 380874aeea5SJeff Kirsher #define EFX_POPULATE_OWORD_7(oword, ...) \ 381874aeea5SJeff Kirsher EFX_POPULATE_OWORD_8(oword, EFX_DUMMY_FIELD, 0, __VA_ARGS__) 382874aeea5SJeff Kirsher #define EFX_POPULATE_OWORD_6(oword, ...) \ 383874aeea5SJeff Kirsher EFX_POPULATE_OWORD_7(oword, EFX_DUMMY_FIELD, 0, __VA_ARGS__) 384874aeea5SJeff Kirsher #define EFX_POPULATE_OWORD_5(oword, ...) \ 385874aeea5SJeff Kirsher EFX_POPULATE_OWORD_6(oword, EFX_DUMMY_FIELD, 0, __VA_ARGS__) 386874aeea5SJeff Kirsher #define EFX_POPULATE_OWORD_4(oword, ...) \ 387874aeea5SJeff Kirsher EFX_POPULATE_OWORD_5(oword, EFX_DUMMY_FIELD, 0, __VA_ARGS__) 388874aeea5SJeff Kirsher #define EFX_POPULATE_OWORD_3(oword, ...) \ 389874aeea5SJeff Kirsher EFX_POPULATE_OWORD_4(oword, EFX_DUMMY_FIELD, 0, __VA_ARGS__) 390874aeea5SJeff Kirsher #define EFX_POPULATE_OWORD_2(oword, ...) \ 391874aeea5SJeff Kirsher EFX_POPULATE_OWORD_3(oword, EFX_DUMMY_FIELD, 0, __VA_ARGS__) 392874aeea5SJeff Kirsher #define EFX_POPULATE_OWORD_1(oword, ...) \ 393874aeea5SJeff Kirsher EFX_POPULATE_OWORD_2(oword, EFX_DUMMY_FIELD, 0, __VA_ARGS__) 394874aeea5SJeff Kirsher #define EFX_ZERO_OWORD(oword) \ 395874aeea5SJeff Kirsher EFX_POPULATE_OWORD_1(oword, EFX_DUMMY_FIELD, 0) 396874aeea5SJeff Kirsher #define EFX_SET_OWORD(oword) \ 397874aeea5SJeff Kirsher EFX_POPULATE_OWORD_4(oword, \ 398874aeea5SJeff Kirsher EFX_DWORD_0, 0xffffffff, \ 399874aeea5SJeff Kirsher EFX_DWORD_1, 0xffffffff, \ 400874aeea5SJeff Kirsher EFX_DWORD_2, 0xffffffff, \ 401874aeea5SJeff Kirsher EFX_DWORD_3, 0xffffffff) 402874aeea5SJeff Kirsher 403874aeea5SJeff Kirsher /* Populate a quadword field with various numbers of arguments */ 404dc8d2512SEdward Cree #define EFX_POPULATE_QWORD_19 EFX_POPULATE_QWORD 405dc8d2512SEdward Cree #define EFX_POPULATE_QWORD_18(qword, ...) \ 406dc8d2512SEdward Cree EFX_POPULATE_QWORD_19(qword, EFX_DUMMY_FIELD, 0, __VA_ARGS__) 407dc8d2512SEdward Cree #define EFX_POPULATE_QWORD_17(qword, ...) \ 408dc8d2512SEdward Cree EFX_POPULATE_QWORD_18(qword, EFX_DUMMY_FIELD, 0, __VA_ARGS__) 409a7a375caSEdward Cree #define EFX_POPULATE_QWORD_16(qword, ...) \ 410a7a375caSEdward Cree EFX_POPULATE_QWORD_17(qword, EFX_DUMMY_FIELD, 0, __VA_ARGS__) 411a7a375caSEdward Cree #define EFX_POPULATE_QWORD_15(qword, ...) \ 412a7a375caSEdward Cree EFX_POPULATE_QWORD_16(qword, EFX_DUMMY_FIELD, 0, __VA_ARGS__) 413a7a375caSEdward Cree #define EFX_POPULATE_QWORD_14(qword, ...) \ 414a7a375caSEdward Cree EFX_POPULATE_QWORD_15(qword, EFX_DUMMY_FIELD, 0, __VA_ARGS__) 415a7a375caSEdward Cree #define EFX_POPULATE_QWORD_13(qword, ...) \ 416a7a375caSEdward Cree EFX_POPULATE_QWORD_14(qword, EFX_DUMMY_FIELD, 0, __VA_ARGS__) 41708f9912eSEdward Cree #define EFX_POPULATE_QWORD_12(qword, ...) \ 41808f9912eSEdward Cree EFX_POPULATE_QWORD_13(qword, EFX_DUMMY_FIELD, 0, __VA_ARGS__) 41908f9912eSEdward Cree #define EFX_POPULATE_QWORD_11(qword, ...) \ 42008f9912eSEdward Cree EFX_POPULATE_QWORD_12(qword, EFX_DUMMY_FIELD, 0, __VA_ARGS__) 42108f9912eSEdward Cree #define EFX_POPULATE_QWORD_10(qword, ...) \ 42208f9912eSEdward Cree EFX_POPULATE_QWORD_11(qword, EFX_DUMMY_FIELD, 0, __VA_ARGS__) 423874aeea5SJeff Kirsher #define EFX_POPULATE_QWORD_9(qword, ...) \ 424874aeea5SJeff Kirsher EFX_POPULATE_QWORD_10(qword, EFX_DUMMY_FIELD, 0, __VA_ARGS__) 425874aeea5SJeff Kirsher #define EFX_POPULATE_QWORD_8(qword, ...) \ 426874aeea5SJeff Kirsher EFX_POPULATE_QWORD_9(qword, EFX_DUMMY_FIELD, 0, __VA_ARGS__) 427874aeea5SJeff Kirsher #define EFX_POPULATE_QWORD_7(qword, ...) \ 428874aeea5SJeff Kirsher EFX_POPULATE_QWORD_8(qword, EFX_DUMMY_FIELD, 0, __VA_ARGS__) 429874aeea5SJeff Kirsher #define EFX_POPULATE_QWORD_6(qword, ...) \ 430874aeea5SJeff Kirsher EFX_POPULATE_QWORD_7(qword, EFX_DUMMY_FIELD, 0, __VA_ARGS__) 431874aeea5SJeff Kirsher #define EFX_POPULATE_QWORD_5(qword, ...) \ 432874aeea5SJeff Kirsher EFX_POPULATE_QWORD_6(qword, EFX_DUMMY_FIELD, 0, __VA_ARGS__) 433874aeea5SJeff Kirsher #define EFX_POPULATE_QWORD_4(qword, ...) \ 434874aeea5SJeff Kirsher EFX_POPULATE_QWORD_5(qword, EFX_DUMMY_FIELD, 0, __VA_ARGS__) 435874aeea5SJeff Kirsher #define EFX_POPULATE_QWORD_3(qword, ...) \ 436874aeea5SJeff Kirsher EFX_POPULATE_QWORD_4(qword, EFX_DUMMY_FIELD, 0, __VA_ARGS__) 437874aeea5SJeff Kirsher #define EFX_POPULATE_QWORD_2(qword, ...) \ 438874aeea5SJeff Kirsher EFX_POPULATE_QWORD_3(qword, EFX_DUMMY_FIELD, 0, __VA_ARGS__) 439874aeea5SJeff Kirsher #define EFX_POPULATE_QWORD_1(qword, ...) \ 440874aeea5SJeff Kirsher EFX_POPULATE_QWORD_2(qword, EFX_DUMMY_FIELD, 0, __VA_ARGS__) 441874aeea5SJeff Kirsher #define EFX_ZERO_QWORD(qword) \ 442874aeea5SJeff Kirsher EFX_POPULATE_QWORD_1(qword, EFX_DUMMY_FIELD, 0) 443874aeea5SJeff Kirsher #define EFX_SET_QWORD(qword) \ 444874aeea5SJeff Kirsher EFX_POPULATE_QWORD_2(qword, \ 445874aeea5SJeff Kirsher EFX_DWORD_0, 0xffffffff, \ 446874aeea5SJeff Kirsher EFX_DWORD_1, 0xffffffff) 447874aeea5SJeff Kirsher 448874aeea5SJeff Kirsher /* Populate a dword field with various numbers of arguments */ 449dc8d2512SEdward Cree #define EFX_POPULATE_DWORD_19 EFX_POPULATE_DWORD 450dc8d2512SEdward Cree #define EFX_POPULATE_DWORD_18(dword, ...) \ 451dc8d2512SEdward Cree EFX_POPULATE_DWORD_19(dword, EFX_DUMMY_FIELD, 0, __VA_ARGS__) 452dc8d2512SEdward Cree #define EFX_POPULATE_DWORD_17(dword, ...) \ 453dc8d2512SEdward Cree EFX_POPULATE_DWORD_18(dword, EFX_DUMMY_FIELD, 0, __VA_ARGS__) 454a7a375caSEdward Cree #define EFX_POPULATE_DWORD_16(dword, ...) \ 455a7a375caSEdward Cree EFX_POPULATE_DWORD_17(dword, EFX_DUMMY_FIELD, 0, __VA_ARGS__) 456a7a375caSEdward Cree #define EFX_POPULATE_DWORD_15(dword, ...) \ 457a7a375caSEdward Cree EFX_POPULATE_DWORD_16(dword, EFX_DUMMY_FIELD, 0, __VA_ARGS__) 458a7a375caSEdward Cree #define EFX_POPULATE_DWORD_14(dword, ...) \ 459a7a375caSEdward Cree EFX_POPULATE_DWORD_15(dword, EFX_DUMMY_FIELD, 0, __VA_ARGS__) 460a7a375caSEdward Cree #define EFX_POPULATE_DWORD_13(dword, ...) \ 461a7a375caSEdward Cree EFX_POPULATE_DWORD_14(dword, EFX_DUMMY_FIELD, 0, __VA_ARGS__) 46208f9912eSEdward Cree #define EFX_POPULATE_DWORD_12(dword, ...) \ 46308f9912eSEdward Cree EFX_POPULATE_DWORD_13(dword, EFX_DUMMY_FIELD, 0, __VA_ARGS__) 46408f9912eSEdward Cree #define EFX_POPULATE_DWORD_11(dword, ...) \ 46508f9912eSEdward Cree EFX_POPULATE_DWORD_12(dword, EFX_DUMMY_FIELD, 0, __VA_ARGS__) 46608f9912eSEdward Cree #define EFX_POPULATE_DWORD_10(dword, ...) \ 46708f9912eSEdward Cree EFX_POPULATE_DWORD_11(dword, EFX_DUMMY_FIELD, 0, __VA_ARGS__) 468874aeea5SJeff Kirsher #define EFX_POPULATE_DWORD_9(dword, ...) \ 469874aeea5SJeff Kirsher EFX_POPULATE_DWORD_10(dword, EFX_DUMMY_FIELD, 0, __VA_ARGS__) 470874aeea5SJeff Kirsher #define EFX_POPULATE_DWORD_8(dword, ...) \ 471874aeea5SJeff Kirsher EFX_POPULATE_DWORD_9(dword, EFX_DUMMY_FIELD, 0, __VA_ARGS__) 472874aeea5SJeff Kirsher #define EFX_POPULATE_DWORD_7(dword, ...) \ 473874aeea5SJeff Kirsher EFX_POPULATE_DWORD_8(dword, EFX_DUMMY_FIELD, 0, __VA_ARGS__) 474874aeea5SJeff Kirsher #define EFX_POPULATE_DWORD_6(dword, ...) \ 475874aeea5SJeff Kirsher EFX_POPULATE_DWORD_7(dword, EFX_DUMMY_FIELD, 0, __VA_ARGS__) 476874aeea5SJeff Kirsher #define EFX_POPULATE_DWORD_5(dword, ...) \ 477874aeea5SJeff Kirsher EFX_POPULATE_DWORD_6(dword, EFX_DUMMY_FIELD, 0, __VA_ARGS__) 478874aeea5SJeff Kirsher #define EFX_POPULATE_DWORD_4(dword, ...) \ 479874aeea5SJeff Kirsher EFX_POPULATE_DWORD_5(dword, EFX_DUMMY_FIELD, 0, __VA_ARGS__) 480874aeea5SJeff Kirsher #define EFX_POPULATE_DWORD_3(dword, ...) \ 481874aeea5SJeff Kirsher EFX_POPULATE_DWORD_4(dword, EFX_DUMMY_FIELD, 0, __VA_ARGS__) 482874aeea5SJeff Kirsher #define EFX_POPULATE_DWORD_2(dword, ...) \ 483874aeea5SJeff Kirsher EFX_POPULATE_DWORD_3(dword, EFX_DUMMY_FIELD, 0, __VA_ARGS__) 484874aeea5SJeff Kirsher #define EFX_POPULATE_DWORD_1(dword, ...) \ 485874aeea5SJeff Kirsher EFX_POPULATE_DWORD_2(dword, EFX_DUMMY_FIELD, 0, __VA_ARGS__) 486874aeea5SJeff Kirsher #define EFX_ZERO_DWORD(dword) \ 487874aeea5SJeff Kirsher EFX_POPULATE_DWORD_1(dword, EFX_DUMMY_FIELD, 0) 488874aeea5SJeff Kirsher #define EFX_SET_DWORD(dword) \ 489874aeea5SJeff Kirsher EFX_POPULATE_DWORD_1(dword, EFX_DWORD_0, 0xffffffff) 490874aeea5SJeff Kirsher 491874aeea5SJeff Kirsher /* 492874aeea5SJeff Kirsher * Modify a named field within an already-populated structure. Used 493874aeea5SJeff Kirsher * for read-modify-write operations. 494874aeea5SJeff Kirsher * 495874aeea5SJeff Kirsher */ 496874aeea5SJeff Kirsher #define EFX_INVERT_OWORD(oword) do { \ 497874aeea5SJeff Kirsher (oword).u64[0] = ~((oword).u64[0]); \ 498874aeea5SJeff Kirsher (oword).u64[1] = ~((oword).u64[1]); \ 499874aeea5SJeff Kirsher } while (0) 500874aeea5SJeff Kirsher 501874aeea5SJeff Kirsher #define EFX_AND_OWORD(oword, from, mask) \ 502874aeea5SJeff Kirsher do { \ 503874aeea5SJeff Kirsher (oword).u64[0] = (from).u64[0] & (mask).u64[0]; \ 504874aeea5SJeff Kirsher (oword).u64[1] = (from).u64[1] & (mask).u64[1]; \ 505874aeea5SJeff Kirsher } while (0) 506874aeea5SJeff Kirsher 507a0ee3541SJon Cooper #define EFX_AND_QWORD(qword, from, mask) \ 508a0ee3541SJon Cooper (qword).u64[0] = (from).u64[0] & (mask).u64[0] 509a0ee3541SJon Cooper 510874aeea5SJeff Kirsher #define EFX_OR_OWORD(oword, from, mask) \ 511874aeea5SJeff Kirsher do { \ 512874aeea5SJeff Kirsher (oword).u64[0] = (from).u64[0] | (mask).u64[0]; \ 513874aeea5SJeff Kirsher (oword).u64[1] = (from).u64[1] | (mask).u64[1]; \ 514874aeea5SJeff Kirsher } while (0) 515874aeea5SJeff Kirsher 516874aeea5SJeff Kirsher #define EFX_INSERT64(min, max, low, high, value) \ 517874aeea5SJeff Kirsher cpu_to_le64(EFX_INSERT_NATIVE(min, max, low, high, value)) 518874aeea5SJeff Kirsher 519874aeea5SJeff Kirsher #define EFX_INSERT32(min, max, low, high, value) \ 520874aeea5SJeff Kirsher cpu_to_le32(EFX_INSERT_NATIVE(min, max, low, high, value)) 521874aeea5SJeff Kirsher 522874aeea5SJeff Kirsher #define EFX_INPLACE_MASK64(min, max, low, high) \ 5239724a850SBen Hutchings EFX_INSERT64(min, max, low, high, EFX_MASK64((high) + 1 - (low))) 524874aeea5SJeff Kirsher 525874aeea5SJeff Kirsher #define EFX_INPLACE_MASK32(min, max, low, high) \ 5269724a850SBen Hutchings EFX_INSERT32(min, max, low, high, EFX_MASK32((high) + 1 - (low))) 527874aeea5SJeff Kirsher 528874aeea5SJeff Kirsher #define EFX_SET_OWORD64(oword, low, high, value) do { \ 529874aeea5SJeff Kirsher (oword).u64[0] = (((oword).u64[0] \ 530874aeea5SJeff Kirsher & ~EFX_INPLACE_MASK64(0, 63, low, high)) \ 531874aeea5SJeff Kirsher | EFX_INSERT64(0, 63, low, high, value)); \ 532874aeea5SJeff Kirsher (oword).u64[1] = (((oword).u64[1] \ 533874aeea5SJeff Kirsher & ~EFX_INPLACE_MASK64(64, 127, low, high)) \ 534874aeea5SJeff Kirsher | EFX_INSERT64(64, 127, low, high, value)); \ 535874aeea5SJeff Kirsher } while (0) 536874aeea5SJeff Kirsher 537874aeea5SJeff Kirsher #define EFX_SET_QWORD64(qword, low, high, value) do { \ 538874aeea5SJeff Kirsher (qword).u64[0] = (((qword).u64[0] \ 539874aeea5SJeff Kirsher & ~EFX_INPLACE_MASK64(0, 63, low, high)) \ 540874aeea5SJeff Kirsher | EFX_INSERT64(0, 63, low, high, value)); \ 541874aeea5SJeff Kirsher } while (0) 542874aeea5SJeff Kirsher 543874aeea5SJeff Kirsher #define EFX_SET_OWORD32(oword, low, high, value) do { \ 544874aeea5SJeff Kirsher (oword).u32[0] = (((oword).u32[0] \ 545874aeea5SJeff Kirsher & ~EFX_INPLACE_MASK32(0, 31, low, high)) \ 546874aeea5SJeff Kirsher | EFX_INSERT32(0, 31, low, high, value)); \ 547874aeea5SJeff Kirsher (oword).u32[1] = (((oword).u32[1] \ 548874aeea5SJeff Kirsher & ~EFX_INPLACE_MASK32(32, 63, low, high)) \ 549874aeea5SJeff Kirsher | EFX_INSERT32(32, 63, low, high, value)); \ 550874aeea5SJeff Kirsher (oword).u32[2] = (((oword).u32[2] \ 551874aeea5SJeff Kirsher & ~EFX_INPLACE_MASK32(64, 95, low, high)) \ 552874aeea5SJeff Kirsher | EFX_INSERT32(64, 95, low, high, value)); \ 553874aeea5SJeff Kirsher (oword).u32[3] = (((oword).u32[3] \ 554874aeea5SJeff Kirsher & ~EFX_INPLACE_MASK32(96, 127, low, high)) \ 555874aeea5SJeff Kirsher | EFX_INSERT32(96, 127, low, high, value)); \ 556874aeea5SJeff Kirsher } while (0) 557874aeea5SJeff Kirsher 558874aeea5SJeff Kirsher #define EFX_SET_QWORD32(qword, low, high, value) do { \ 559874aeea5SJeff Kirsher (qword).u32[0] = (((qword).u32[0] \ 560874aeea5SJeff Kirsher & ~EFX_INPLACE_MASK32(0, 31, low, high)) \ 561874aeea5SJeff Kirsher | EFX_INSERT32(0, 31, low, high, value)); \ 562874aeea5SJeff Kirsher (qword).u32[1] = (((qword).u32[1] \ 563874aeea5SJeff Kirsher & ~EFX_INPLACE_MASK32(32, 63, low, high)) \ 564874aeea5SJeff Kirsher | EFX_INSERT32(32, 63, low, high, value)); \ 565874aeea5SJeff Kirsher } while (0) 566874aeea5SJeff Kirsher 567874aeea5SJeff Kirsher #define EFX_SET_DWORD32(dword, low, high, value) do { \ 568874aeea5SJeff Kirsher (dword).u32[0] = (((dword).u32[0] \ 569874aeea5SJeff Kirsher & ~EFX_INPLACE_MASK32(0, 31, low, high)) \ 570874aeea5SJeff Kirsher | EFX_INSERT32(0, 31, low, high, value)); \ 571874aeea5SJeff Kirsher } while (0) 572874aeea5SJeff Kirsher 573874aeea5SJeff Kirsher #define EFX_SET_OWORD_FIELD64(oword, field, value) \ 574874aeea5SJeff Kirsher EFX_SET_OWORD64(oword, EFX_LOW_BIT(field), \ 575874aeea5SJeff Kirsher EFX_HIGH_BIT(field), value) 576874aeea5SJeff Kirsher 577874aeea5SJeff Kirsher #define EFX_SET_QWORD_FIELD64(qword, field, value) \ 578874aeea5SJeff Kirsher EFX_SET_QWORD64(qword, EFX_LOW_BIT(field), \ 579874aeea5SJeff Kirsher EFX_HIGH_BIT(field), value) 580874aeea5SJeff Kirsher 581874aeea5SJeff Kirsher #define EFX_SET_OWORD_FIELD32(oword, field, value) \ 582874aeea5SJeff Kirsher EFX_SET_OWORD32(oword, EFX_LOW_BIT(field), \ 583874aeea5SJeff Kirsher EFX_HIGH_BIT(field), value) 584874aeea5SJeff Kirsher 585874aeea5SJeff Kirsher #define EFX_SET_QWORD_FIELD32(qword, field, value) \ 586874aeea5SJeff Kirsher EFX_SET_QWORD32(qword, EFX_LOW_BIT(field), \ 587874aeea5SJeff Kirsher EFX_HIGH_BIT(field), value) 588874aeea5SJeff Kirsher 589874aeea5SJeff Kirsher #define EFX_SET_DWORD_FIELD(dword, field, value) \ 590874aeea5SJeff Kirsher EFX_SET_DWORD32(dword, EFX_LOW_BIT(field), \ 591874aeea5SJeff Kirsher EFX_HIGH_BIT(field), value) 592874aeea5SJeff Kirsher 593874aeea5SJeff Kirsher 594874aeea5SJeff Kirsher 595874aeea5SJeff Kirsher #if BITS_PER_LONG == 64 596874aeea5SJeff Kirsher #define EFX_SET_OWORD_FIELD EFX_SET_OWORD_FIELD64 597874aeea5SJeff Kirsher #define EFX_SET_QWORD_FIELD EFX_SET_QWORD_FIELD64 598874aeea5SJeff Kirsher #else 599874aeea5SJeff Kirsher #define EFX_SET_OWORD_FIELD EFX_SET_OWORD_FIELD32 600874aeea5SJeff Kirsher #define EFX_SET_QWORD_FIELD EFX_SET_QWORD_FIELD32 601874aeea5SJeff Kirsher #endif 602874aeea5SJeff Kirsher 603874aeea5SJeff Kirsher /* Used to avoid compiler warnings about shift range exceeding width 604874aeea5SJeff Kirsher * of the data types when dma_addr_t is only 32 bits wide. 605874aeea5SJeff Kirsher */ 606874aeea5SJeff Kirsher #define DMA_ADDR_T_WIDTH (8 * sizeof(dma_addr_t)) 607874aeea5SJeff Kirsher #define EFX_DMA_TYPE_WIDTH(width) \ 608874aeea5SJeff Kirsher (((width) < DMA_ADDR_T_WIDTH) ? (width) : DMA_ADDR_T_WIDTH) 609874aeea5SJeff Kirsher 610874aeea5SJeff Kirsher 611874aeea5SJeff Kirsher /* Static initialiser */ 612874aeea5SJeff Kirsher #define EFX_OWORD32(a, b, c, d) \ 613874aeea5SJeff Kirsher { .u32 = { cpu_to_le32(a), cpu_to_le32(b), \ 614874aeea5SJeff Kirsher cpu_to_le32(c), cpu_to_le32(d) } } 615874aeea5SJeff Kirsher 616874aeea5SJeff Kirsher #endif /* EFX_BITFIELD_H */ 617