iPXE
efx_bitfield.h
Go to the documentation of this file.
00001 /****************************************************************************
00002  *
00003  * Driver for Solarflare network controllers and boards
00004  * Copyright 2005-2006 Fen Systems Ltd.
00005  * Copyright 2006-2017 Solarflare Communications Inc.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License as
00009  * published by the Free Software Foundation; either version 2 of the
00010  * License, or any later version.
00011  *
00012  * You can also choose to distribute this program under the terms of
00013  * the Unmodified Binary Distribution Licence (as given in the file
00014  * COPYING.UBDL), provided that you have satisfied its requirements.
00015  */
00016 
00017 #ifndef EFX_BITFIELD_H
00018 #define EFX_BITFIELD_H
00019 
00020 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
00021 
00022 #include <byteswap.h>
00023 
00024 /** \file efx_bitfield.h
00025  * Efx bitfield access
00026  *
00027  * Efx NICs make extensive use of bitfields up to 128 bits
00028  * wide.  Since there is no native 128-bit datatype on most systems,
00029  * and since 64-bit datatypes are inefficient on 32-bit systems and
00030  * vice versa, we wrap accesses in a way that uses the most efficient
00031  * datatype.
00032  *
00033  * The NICs are PCI devices and therefore little-endian.  Since most
00034  * of the quantities that we deal with are DMAed to/from host memory,
00035  * we define our datatypes (efx_oword_t, efx_qword_t and
00036  * efx_dword_t) to be little-endian.
00037  */
00038 
00039 /* Lowest bit numbers and widths */
00040 #define EFX_DUMMY_FIELD_LBN 0
00041 #define EFX_DUMMY_FIELD_WIDTH 0
00042 #define EFX_WORD_0_LBN 0
00043 #define EFX_WORD_0_WIDTH 16
00044 #define EFX_WORD_1_LBN 16
00045 #define EFX_WORD_1_WIDTH 16
00046 #define EFX_DWORD_0_LBN 0
00047 #define EFX_DWORD_0_WIDTH 32
00048 #define EFX_DWORD_1_LBN 32
00049 #define EFX_DWORD_1_WIDTH 32
00050 #define EFX_DWORD_2_LBN 64
00051 #define EFX_DWORD_2_WIDTH 32
00052 #define EFX_DWORD_3_LBN 96
00053 #define EFX_DWORD_3_WIDTH 32
00054 #define EFX_QWORD_0_LBN 0
00055 #define EFX_QWORD_0_WIDTH 64
00056 
00057 /* Specified attribute (e.g. LBN) of the specified field */
00058 #define EFX_VAL(field, attribute) field ## _ ## attribute
00059 /* Low bit number of the specified field */
00060 #define EFX_LOW_BIT(field) EFX_VAL(field, LBN)
00061 /* Bit width of the specified field */
00062 #define EFX_WIDTH(field) EFX_VAL(field, WIDTH)
00063 /* High bit number of the specified field */
00064 #define EFX_HIGH_BIT(field) (EFX_LOW_BIT(field) + EFX_WIDTH(field) - 1)
00065 /* Mask equal in width to the specified field.
00066  *
00067  * For example, a field with width 5 would have a mask of 0x1f.
00068  *
00069  * The maximum width mask that can be generated is 64 bits.
00070  */
00071 #define EFX_MASK64(width)                       \
00072         ((width) == 64 ? ~((u64) 0) :           \
00073          (((((u64) 1) << (width))) - 1))
00074 
00075 /* Mask equal in width to the specified field.
00076  *
00077  * For example, a field with width 5 would have a mask of 0x1f.
00078  *
00079  * The maximum width mask that can be generated is 32 bits.  Use
00080  * EFX_MASK64 for higher width fields.
00081  */
00082 #define EFX_MASK32(width)                       \
00083         ((width) == 32 ? ~((u32) 0) :           \
00084          (((((u32) 1) << (width))) - 1))
00085 
00086 /** A doubleword (4 byte) datatype - little-endian in HW */
00087 typedef union efx_dword {
00088         __le32 u32[1];
00089 } efx_dword_t;
00090 
00091 /** A quadword (8 byte) datatype - little-endian in HW */
00092 typedef union efx_qword {
00093         __le64 u64[1];
00094         __le32 u32[2];
00095         efx_dword_t dword[2];
00096 } efx_qword_t;
00097 
00098 /** An octword (eight-word, so 16 byte) datatype - little-endian in HW */
00099 typedef union efx_oword {
00100         __le64 u64[2];
00101         efx_qword_t qword[2];
00102         __le32 u32[4];
00103         efx_dword_t dword[4];
00104 } efx_oword_t;
00105 
00106 /* Format string and value expanders for printk */
00107 #define EFX_DWORD_FMT "%08x"
00108 #define EFX_QWORD_FMT "%08x:%08x"
00109 #define EFX_OWORD_FMT "%08x:%08x:%08x:%08x"
00110 #define EFX_DWORD_VAL(dword)                            \
00111         ((unsigned int) le32_to_cpu((dword).u32[0]))
00112 #define EFX_QWORD_VAL(qword)                            \
00113         ((unsigned int) le32_to_cpu((qword).u32[1])),   \
00114         ((unsigned int) le32_to_cpu((qword).u32[0]))
00115 #define EFX_OWORD_VAL(oword)                            \
00116         ((unsigned int) le32_to_cpu((oword).u32[3])),   \
00117         ((unsigned int) le32_to_cpu((oword).u32[2])),   \
00118         ((unsigned int) le32_to_cpu((oword).u32[1])),   \
00119         ((unsigned int) le32_to_cpu((oword).u32[0]))
00120 
00121 /*
00122  * Extract bit field portion [low,high) from the native-endian element
00123  * which contains bits [min,max).
00124  *
00125  * For example, suppose "element" represents the high 32 bits of a
00126  * 64-bit value, and we wish to extract the bits belonging to the bit
00127  * field occupying bits 28-45 of this 64-bit value.
00128  *
00129  * Then EFX_EXTRACT ( element, 32, 63, 28, 45 ) would give
00130  *
00131  *   ( element ) << 4
00132  *
00133  * The result will contain the relevant bits filled in in the range
00134  * [0,high-low), with garbage in bits [high-low+1,...).
00135  */
00136 #define EFX_EXTRACT_NATIVE(native_element, min, max, low, high)         \
00137         ((low) > (max) || (high) < (min) ? 0 :                          \
00138          (low) > (min) ?                                                \
00139          (native_element) >> ((low) - (min)) :                          \
00140          (native_element) << ((min) - (low)))
00141 
00142 /*
00143  * Extract bit field portion [low,high) from the 64-bit little-endian
00144  * element which contains bits [min,max)
00145  */
00146 #define EFX_EXTRACT64(element, min, max, low, high)                     \
00147         EFX_EXTRACT_NATIVE(le64_to_cpu(element), min, max, low, high)
00148 
00149 /*
00150  * Extract bit field portion [low,high) from the 32-bit little-endian
00151  * element which contains bits [min,max)
00152  */
00153 #define EFX_EXTRACT32(element, min, max, low, high)                     \
00154         EFX_EXTRACT_NATIVE(le32_to_cpu(element), min, max, low, high)
00155 
00156 #define EFX_EXTRACT_OWORD64(oword, low, high)                           \
00157         ((EFX_EXTRACT64((oword).u64[0], 0, 63, low, high) |             \
00158           EFX_EXTRACT64((oword).u64[1], 64, 127, low, high)) &          \
00159          EFX_MASK64((high) + 1 - (low)))
00160 
00161 #define EFX_EXTRACT_QWORD64(qword, low, high)                           \
00162         (EFX_EXTRACT64((qword).u64[0], 0, 63, low, high) &              \
00163          EFX_MASK64((high) + 1 - (low)))
00164 
00165 #define EFX_EXTRACT_OWORD32(oword, low, high)                           \
00166         ((EFX_EXTRACT32((oword).u32[0], 0, 31, low, high) |             \
00167           EFX_EXTRACT32((oword).u32[1], 32, 63, low, high) |            \
00168           EFX_EXTRACT32((oword).u32[2], 64, 95, low, high) |            \
00169           EFX_EXTRACT32((oword).u32[3], 96, 127, low, high)) &          \
00170          EFX_MASK32((high) + 1 - (low)))
00171 
00172 #define EFX_EXTRACT_QWORD32(qword, low, high)                           \
00173         ((EFX_EXTRACT32((qword).u32[0], 0, 31, low, high) |             \
00174           EFX_EXTRACT32((qword).u32[1], 32, 63, low, high)) &           \
00175          EFX_MASK32((high) + 1 - (low)))
00176 
00177 #define EFX_EXTRACT_DWORD(dword, low, high)                     \
00178         (EFX_EXTRACT32((dword).u32[0], 0, 31, low, high) &      \
00179          EFX_MASK32((high) + 1 - (low)))
00180 
00181 #define EFX_OWORD_FIELD64(oword, field)                         \
00182         EFX_EXTRACT_OWORD64(oword, EFX_LOW_BIT(field),          \
00183                             EFX_HIGH_BIT(field))
00184 
00185 #define EFX_QWORD_FIELD64(qword, field)                         \
00186         EFX_EXTRACT_QWORD64(qword, EFX_LOW_BIT(field),          \
00187                             EFX_HIGH_BIT(field))
00188 
00189 #define EFX_OWORD_FIELD32(oword, field)                         \
00190         EFX_EXTRACT_OWORD32(oword, EFX_LOW_BIT(field),          \
00191                             EFX_HIGH_BIT(field))
00192 
00193 #define EFX_QWORD_FIELD32(qword, field)                         \
00194         EFX_EXTRACT_QWORD32(qword, EFX_LOW_BIT(field),          \
00195                             EFX_HIGH_BIT(field))
00196 
00197 #define EFX_DWORD_FIELD(dword, field)                           \
00198         EFX_EXTRACT_DWORD(dword, EFX_LOW_BIT(field),            \
00199                           EFX_HIGH_BIT(field))
00200 
00201 #define EFX_OWORD_IS_ZERO64(oword)                                      \
00202         (((oword).u64[0] | (oword).u64[1]) == (__force __le64) 0)
00203 
00204 #define EFX_QWORD_IS_ZERO64(qword)                                      \
00205         (((qword).u64[0]) == (__force __le64) 0)
00206 
00207 #define EFX_OWORD_IS_ZERO32(oword)                                           \
00208         (((oword).u32[0] | (oword).u32[1] | (oword).u32[2] | (oword).u32[3]) \
00209          == (__force __le32) 0)
00210 
00211 #define EFX_QWORD_IS_ZERO32(qword)                                      \
00212         (((qword).u32[0] | (qword).u32[1]) == (__force __le32) 0)
00213 
00214 #define EFX_DWORD_IS_ZERO(dword)                                        \
00215         (((dword).u32[0]) == (__force __le32) 0)
00216 
00217 #define EFX_OWORD_IS_ALL_ONES64(oword)                                  \
00218         (((oword).u64[0] & (oword).u64[1]) == ~((__force __le64) 0))
00219 
00220 #define EFX_QWORD_IS_ALL_ONES64(qword)                                  \
00221         ((qword).u64[0] == ~((__force __le64) 0))
00222 
00223 #define EFX_OWORD_IS_ALL_ONES32(oword)                                  \
00224         (((oword).u32[0] & (oword).u32[1] & (oword).u32[2] & (oword).u32[3]) \
00225          == ~((__force __le32) 0))
00226 
00227 #define EFX_QWORD_IS_ALL_ONES32(qword)                                  \
00228         (((qword).u32[0] & (qword).u32[1]) == ~((__force __le32) 0))
00229 
00230 #define EFX_DWORD_IS_ALL_ONES(dword)                                    \
00231         ((dword).u32[0] == ~((__force __le32) 0))
00232 
00233 #if BITS_PER_LONG == 64
00234 #define EFX_OWORD_FIELD         EFX_OWORD_FIELD64
00235 #define EFX_QWORD_FIELD         EFX_QWORD_FIELD64
00236 #define EFX_OWORD_IS_ZERO       EFX_OWORD_IS_ZERO64
00237 #define EFX_QWORD_IS_ZERO       EFX_QWORD_IS_ZERO64
00238 #define EFX_OWORD_IS_ALL_ONES   EFX_OWORD_IS_ALL_ONES64
00239 #define EFX_QWORD_IS_ALL_ONES   EFX_QWORD_IS_ALL_ONES64
00240 #else
00241 #define EFX_OWORD_FIELD         EFX_OWORD_FIELD32
00242 #define EFX_QWORD_FIELD         EFX_QWORD_FIELD32
00243 #define EFX_OWORD_IS_ZERO       EFX_OWORD_IS_ZERO32
00244 #define EFX_QWORD_IS_ZERO       EFX_QWORD_IS_ZERO32
00245 #define EFX_OWORD_IS_ALL_ONES   EFX_OWORD_IS_ALL_ONES32
00246 #define EFX_QWORD_IS_ALL_ONES   EFX_QWORD_IS_ALL_ONES32
00247 #endif
00248 
00249 /*
00250  * Construct bit field portion
00251  *
00252  * Creates the portion of the bit field [low,high) that lies within
00253  * the range [min,max).
00254  */
00255 #define EFX_INSERT_NATIVE64(min, max, low, high, value)         \
00256         (((low > max) || (high < min)) ? 0 :                    \
00257          ((low > min) ?                                         \
00258           (((u64) (value)) << (low - min)) :            \
00259           (((u64) (value)) >> (min - low))))
00260 
00261 #define EFX_INSERT_NATIVE32(min, max, low, high, value)         \
00262         (((low > max) || (high < min)) ? 0 :                    \
00263          ((low > min) ?                                         \
00264           (((u32) (value)) << (low - min)) :            \
00265           (((u32) (value)) >> (min - low))))
00266 
00267 #define EFX_INSERT_NATIVE(min, max, low, high, value)           \
00268         ((((max - min) >= 32) || ((high - low) >= 32)) ?        \
00269          EFX_INSERT_NATIVE64(min, max, low, high, value) :      \
00270          EFX_INSERT_NATIVE32(min, max, low, high, value))
00271 
00272 /*
00273  * Construct bit field portion
00274  *
00275  * Creates the portion of the named bit field that lies within the
00276  * range [min,max).
00277  */
00278 #define EFX_INSERT_FIELD_NATIVE(min, max, field, value)         \
00279         EFX_INSERT_NATIVE(min, max, EFX_LOW_BIT(field),         \
00280                           EFX_HIGH_BIT(field), value)
00281 
00282 /*
00283  * Construct bit field
00284  *
00285  * Creates the portion of the named bit fields that lie within the
00286  * range [min,max).
00287  */
00288 #define EFX_INSERT_FIELDS_NATIVE(min, max,                              \
00289                                  field1, value1,                        \
00290                                  field2, value2,                        \
00291                                  field3, value3,                        \
00292                                  field4, value4,                        \
00293                                  field5, value5,                        \
00294                                  field6, value6,                        \
00295                                  field7, value7,                        \
00296                                  field8, value8,                        \
00297                                  field9, value9,                        \
00298                                  field10, value10)                      \
00299         (EFX_INSERT_FIELD_NATIVE((min), (max), field1, (value1)) |      \
00300          EFX_INSERT_FIELD_NATIVE((min), (max), field2, (value2)) |      \
00301          EFX_INSERT_FIELD_NATIVE((min), (max), field3, (value3)) |      \
00302          EFX_INSERT_FIELD_NATIVE((min), (max), field4, (value4)) |      \
00303          EFX_INSERT_FIELD_NATIVE((min), (max), field5, (value5)) |      \
00304          EFX_INSERT_FIELD_NATIVE((min), (max), field6, (value6)) |      \
00305          EFX_INSERT_FIELD_NATIVE((min), (max), field7, (value7)) |      \
00306          EFX_INSERT_FIELD_NATIVE((min), (max), field8, (value8)) |      \
00307          EFX_INSERT_FIELD_NATIVE((min), (max), field9, (value9)) |      \
00308          EFX_INSERT_FIELD_NATIVE((min), (max), field10, (value10)))
00309 
00310 #define EFX_INSERT_FIELDS64(...)                                \
00311         cpu_to_le64(EFX_INSERT_FIELDS_NATIVE(__VA_ARGS__))
00312 
00313 #define EFX_INSERT_FIELDS32(...)                                \
00314         cpu_to_le32(EFX_INSERT_FIELDS_NATIVE(__VA_ARGS__))
00315 
00316 #define EFX_POPULATE_OWORD64(oword, ...) do {                           \
00317         (oword).u64[0] = EFX_INSERT_FIELDS64(0, 63, __VA_ARGS__);       \
00318         (oword).u64[1] = EFX_INSERT_FIELDS64(64, 127, __VA_ARGS__);     \
00319         } while (0)
00320 
00321 #define EFX_POPULATE_QWORD64(qword, ...) do {                           \
00322         (qword).u64[0] = EFX_INSERT_FIELDS64(0, 63, __VA_ARGS__);       \
00323         } while (0)
00324 
00325 #define EFX_POPULATE_OWORD32(oword, ...) do {                           \
00326         (oword).u32[0] = EFX_INSERT_FIELDS32(0, 31, __VA_ARGS__);       \
00327         (oword).u32[1] = EFX_INSERT_FIELDS32(32, 63, __VA_ARGS__);      \
00328         (oword).u32[2] = EFX_INSERT_FIELDS32(64, 95, __VA_ARGS__);      \
00329         (oword).u32[3] = EFX_INSERT_FIELDS32(96, 127, __VA_ARGS__);     \
00330         } while (0)
00331 
00332 #define EFX_POPULATE_QWORD32(qword, ...) do {                           \
00333         (qword).u32[0] = EFX_INSERT_FIELDS32(0, 31, __VA_ARGS__);       \
00334         (qword).u32[1] = EFX_INSERT_FIELDS32(32, 63, __VA_ARGS__);      \
00335         } while (0)
00336 
00337 #define EFX_POPULATE_DWORD(dword, ...) do {                             \
00338         (dword).u32[0] = EFX_INSERT_FIELDS32(0, 31, __VA_ARGS__);       \
00339         } while (0)
00340 
00341 #if BITS_PER_LONG == 64
00342 #define EFX_POPULATE_OWORD EFX_POPULATE_OWORD64
00343 #define EFX_POPULATE_QWORD EFX_POPULATE_QWORD64
00344 #else
00345 #define EFX_POPULATE_OWORD EFX_POPULATE_OWORD32
00346 #define EFX_POPULATE_QWORD EFX_POPULATE_QWORD32
00347 #endif
00348 
00349 /* Populate an octword field with various numbers of arguments */
00350 #define EFX_POPULATE_OWORD_10 EFX_POPULATE_OWORD
00351 #define EFX_POPULATE_OWORD_9(oword, ...) \
00352         EFX_POPULATE_OWORD_10(oword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
00353 #define EFX_POPULATE_OWORD_8(oword, ...) \
00354         EFX_POPULATE_OWORD_9(oword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
00355 #define EFX_POPULATE_OWORD_7(oword, ...) \
00356         EFX_POPULATE_OWORD_8(oword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
00357 #define EFX_POPULATE_OWORD_6(oword, ...) \
00358         EFX_POPULATE_OWORD_7(oword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
00359 #define EFX_POPULATE_OWORD_5(oword, ...) \
00360         EFX_POPULATE_OWORD_6(oword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
00361 #define EFX_POPULATE_OWORD_4(oword, ...) \
00362         EFX_POPULATE_OWORD_5(oword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
00363 #define EFX_POPULATE_OWORD_3(oword, ...) \
00364         EFX_POPULATE_OWORD_4(oword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
00365 #define EFX_POPULATE_OWORD_2(oword, ...) \
00366         EFX_POPULATE_OWORD_3(oword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
00367 #define EFX_POPULATE_OWORD_1(oword, ...) \
00368         EFX_POPULATE_OWORD_2(oword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
00369 #define EFX_ZERO_OWORD(oword) \
00370         EFX_POPULATE_OWORD_1(oword, EFX_DUMMY_FIELD, 0)
00371 #define EFX_SET_OWORD(oword) \
00372         EFX_POPULATE_OWORD_4(oword, \
00373                              EFX_DWORD_0, 0xffffffff, \
00374                              EFX_DWORD_1, 0xffffffff, \
00375                              EFX_DWORD_2, 0xffffffff, \
00376                              EFX_DWORD_3, 0xffffffff)
00377 
00378 /* Populate a quadword field with various numbers of arguments */
00379 #define EFX_POPULATE_QWORD_10 EFX_POPULATE_QWORD
00380 #define EFX_POPULATE_QWORD_9(qword, ...) \
00381         EFX_POPULATE_QWORD_10(qword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
00382 #define EFX_POPULATE_QWORD_8(qword, ...) \
00383         EFX_POPULATE_QWORD_9(qword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
00384 #define EFX_POPULATE_QWORD_7(qword, ...) \
00385         EFX_POPULATE_QWORD_8(qword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
00386 #define EFX_POPULATE_QWORD_6(qword, ...) \
00387         EFX_POPULATE_QWORD_7(qword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
00388 #define EFX_POPULATE_QWORD_5(qword, ...) \
00389         EFX_POPULATE_QWORD_6(qword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
00390 #define EFX_POPULATE_QWORD_4(qword, ...) \
00391         EFX_POPULATE_QWORD_5(qword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
00392 #define EFX_POPULATE_QWORD_3(qword, ...) \
00393         EFX_POPULATE_QWORD_4(qword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
00394 #define EFX_POPULATE_QWORD_2(qword, ...) \
00395         EFX_POPULATE_QWORD_3(qword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
00396 #define EFX_POPULATE_QWORD_1(qword, ...) \
00397         EFX_POPULATE_QWORD_2(qword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
00398 #define EFX_ZERO_QWORD(qword) \
00399         EFX_POPULATE_QWORD_1(qword, EFX_DUMMY_FIELD, 0)
00400 #define EFX_SET_QWORD(qword) \
00401         EFX_POPULATE_QWORD_2(qword, \
00402                              EFX_DWORD_0, 0xffffffff, \
00403                              EFX_DWORD_1, 0xffffffff)
00404 
00405 /* Populate a dword field with various numbers of arguments */
00406 #define EFX_POPULATE_DWORD_10 EFX_POPULATE_DWORD
00407 #define EFX_POPULATE_DWORD_9(dword, ...) \
00408         EFX_POPULATE_DWORD_10(dword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
00409 #define EFX_POPULATE_DWORD_8(dword, ...) \
00410         EFX_POPULATE_DWORD_9(dword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
00411 #define EFX_POPULATE_DWORD_7(dword, ...) \
00412         EFX_POPULATE_DWORD_8(dword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
00413 #define EFX_POPULATE_DWORD_6(dword, ...) \
00414         EFX_POPULATE_DWORD_7(dword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
00415 #define EFX_POPULATE_DWORD_5(dword, ...) \
00416         EFX_POPULATE_DWORD_6(dword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
00417 #define EFX_POPULATE_DWORD_4(dword, ...) \
00418         EFX_POPULATE_DWORD_5(dword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
00419 #define EFX_POPULATE_DWORD_3(dword, ...) \
00420         EFX_POPULATE_DWORD_4(dword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
00421 #define EFX_POPULATE_DWORD_2(dword, ...) \
00422         EFX_POPULATE_DWORD_3(dword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
00423 #define EFX_POPULATE_DWORD_1(dword, ...) \
00424         EFX_POPULATE_DWORD_2(dword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
00425 #define EFX_ZERO_DWORD(dword) \
00426         EFX_POPULATE_DWORD_1(dword, EFX_DUMMY_FIELD, 0)
00427 #define EFX_SET_DWORD(dword) \
00428         EFX_POPULATE_DWORD_1(dword, EFX_DWORD_0, 0xffffffff)
00429 
00430 /*
00431  * Modify a named field within an already-populated structure.  Used
00432  * for read-modify-write operations.
00433  *
00434  */
00435 #define EFX_INVERT_OWORD(oword) do {            \
00436         (oword).u64[0] = ~((oword).u64[0]);     \
00437         (oword).u64[1] = ~((oword).u64[1]);     \
00438         } while (0)
00439 
00440 #define EFX_AND_OWORD(oword, from, mask)                        \
00441         do {                                                    \
00442                 (oword).u64[0] = (from).u64[0] & (mask).u64[0]; \
00443                 (oword).u64[1] = (from).u64[1] & (mask).u64[1]; \
00444         } while (0)
00445 
00446 #define EFX_AND_QWORD(qword, from, mask)                        \
00447                 (qword).u64[0] = (from).u64[0] & (mask).u64[0]
00448 
00449 #define EFX_OR_OWORD(oword, from, mask)                         \
00450         do {                                                    \
00451                 (oword).u64[0] = (from).u64[0] | (mask).u64[0]; \
00452                 (oword).u64[1] = (from).u64[1] | (mask).u64[1]; \
00453         } while (0)
00454 
00455 #define EFX_INSERT64(min, max, low, high, value)                        \
00456         cpu_to_le64(EFX_INSERT_NATIVE(min, max, low, high, value))
00457 
00458 #define EFX_INSERT32(min, max, low, high, value)                        \
00459         cpu_to_le32(EFX_INSERT_NATIVE(min, max, low, high, value))
00460 
00461 #define EFX_INPLACE_MASK64(min, max, low, high)                         \
00462         EFX_INSERT64(min, max, low, high, EFX_MASK64((high) + 1 - (low)))
00463 
00464 #define EFX_INPLACE_MASK32(min, max, low, high)                         \
00465         EFX_INSERT32(min, max, low, high, EFX_MASK32((high) + 1 - (low)))
00466 
00467 #define EFX_SET_OWORD64(oword, low, high, value) do {                   \
00468         (oword).u64[0] = (((oword).u64[0]                               \
00469                            & ~EFX_INPLACE_MASK64(0,  63, low, high))    \
00470                           | EFX_INSERT64(0,  63, low, high, value));    \
00471         (oword).u64[1] = (((oword).u64[1]                               \
00472                            & ~EFX_INPLACE_MASK64(64, 127, low, high))   \
00473                           | EFX_INSERT64(64, 127, low, high, value));   \
00474         } while (0)
00475 
00476 #define EFX_SET_QWORD64(qword, low, high, value) do {                   \
00477         (qword).u64[0] = (((qword).u64[0]                               \
00478                            & ~EFX_INPLACE_MASK64(0, 63, low, high))     \
00479                           | EFX_INSERT64(0, 63, low, high, value));     \
00480         } while (0)
00481 
00482 #define EFX_SET_OWORD32(oword, low, high, value) do {                   \
00483         (oword).u32[0] = (((oword).u32[0]                               \
00484                            & ~EFX_INPLACE_MASK32(0, 31, low, high))     \
00485                           | EFX_INSERT32(0, 31, low, high, value));     \
00486         (oword).u32[1] = (((oword).u32[1]                               \
00487                            & ~EFX_INPLACE_MASK32(32, 63, low, high))    \
00488                           | EFX_INSERT32(32, 63, low, high, value));    \
00489         (oword).u32[2] = (((oword).u32[2]                               \
00490                            & ~EFX_INPLACE_MASK32(64, 95, low, high))    \
00491                           | EFX_INSERT32(64, 95, low, high, value));    \
00492         (oword).u32[3] = (((oword).u32[3]                               \
00493                            & ~EFX_INPLACE_MASK32(96, 127, low, high))   \
00494                           | EFX_INSERT32(96, 127, low, high, value));   \
00495         } while (0)
00496 
00497 #define EFX_SET_QWORD32(qword, low, high, value) do {                   \
00498         (qword).u32[0] = (((qword).u32[0]                               \
00499                            & ~EFX_INPLACE_MASK32(0, 31, low, high))     \
00500                           | EFX_INSERT32(0, 31, low, high, value));     \
00501         (qword).u32[1] = (((qword).u32[1]                               \
00502                            & ~EFX_INPLACE_MASK32(32, 63, low, high))    \
00503                           | EFX_INSERT32(32, 63, low, high, value));    \
00504         } while (0)
00505 
00506 #define EFX_SET_DWORD32(dword, low, high, value) do {                   \
00507         (dword).u32[0] = (((dword).u32[0]                               \
00508                            & ~EFX_INPLACE_MASK32(0, 31, low, high))     \
00509                           | EFX_INSERT32(0, 31, low, high, value));     \
00510         } while (0)
00511 
00512 #define EFX_SET_OWORD_FIELD64(oword, field, value)                      \
00513         EFX_SET_OWORD64(oword, EFX_LOW_BIT(field),                      \
00514                          EFX_HIGH_BIT(field), value)
00515 
00516 #define EFX_SET_QWORD_FIELD64(qword, field, value)                      \
00517         EFX_SET_QWORD64(qword, EFX_LOW_BIT(field),                      \
00518                          EFX_HIGH_BIT(field), value)
00519 
00520 #define EFX_SET_OWORD_FIELD32(oword, field, value)                      \
00521         EFX_SET_OWORD32(oword, EFX_LOW_BIT(field),                      \
00522                          EFX_HIGH_BIT(field), value)
00523 
00524 #define EFX_SET_QWORD_FIELD32(qword, field, value)                      \
00525         EFX_SET_QWORD32(qword, EFX_LOW_BIT(field),                      \
00526                          EFX_HIGH_BIT(field), value)
00527 
00528 #define EFX_SET_DWORD_FIELD(dword, field, value)                        \
00529         EFX_SET_DWORD32(dword, EFX_LOW_BIT(field),                      \
00530                          EFX_HIGH_BIT(field), value)
00531 
00532 
00533 
00534 #if BITS_PER_LONG == 64
00535 #define EFX_SET_OWORD_FIELD EFX_SET_OWORD_FIELD64
00536 #define EFX_SET_QWORD_FIELD EFX_SET_QWORD_FIELD64
00537 #else
00538 #define EFX_SET_OWORD_FIELD EFX_SET_OWORD_FIELD32
00539 #define EFX_SET_QWORD_FIELD EFX_SET_QWORD_FIELD32
00540 #endif
00541 
00542 /* Used to avoid compiler warnings about shift range exceeding width
00543  * of the data types when dma_addr_t is only 32 bits wide.
00544  */
00545 #define DMA_ADDR_T_WIDTH        (8 * sizeof(dma_addr_t))
00546 #define EFX_DMA_TYPE_WIDTH(width) \
00547         (((width) < DMA_ADDR_T_WIDTH) ? (width) : DMA_ADDR_T_WIDTH)
00548 
00549 
00550 /* Static initialiser */
00551 #define EFX_OWORD32(a, b, c, d)                         \
00552         { .u32 = { cpu_to_le32(a), cpu_to_le32(b),      \
00553                    cpu_to_le32(c), cpu_to_le32(d) } }
00554 
00555 #endif /* EFX_BITFIELD_H */