summaryrefslogtreecommitdiffstats
path: root/src/drivers/net/mlx_ipoib/bit_ops.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/drivers/net/mlx_ipoib/bit_ops.h')
-rw-r--r--src/drivers/net/mlx_ipoib/bit_ops.h98
1 files changed, 98 insertions, 0 deletions
diff --git a/src/drivers/net/mlx_ipoib/bit_ops.h b/src/drivers/net/mlx_ipoib/bit_ops.h
index b67f92ce9..74823a608 100644
--- a/src/drivers/net/mlx_ipoib/bit_ops.h
+++ b/src/drivers/net/mlx_ipoib/bit_ops.h
@@ -133,4 +133,102 @@ struct addr_64_st {
field; \
})
+
+
+/* Remaining code Copyright Fen Systems Ltd. 2007 */
+
+/** Bit offset of a field within a pseudo_bit_t structure */
+#define MLX_BIT_OFFSET( _structure, _field ) \
+ offsetof ( struct _structure, _field )
+
+/** Bit width of a field within a pseudo_bit_t structure */
+#define MLX_BIT_WIDTH( _structure, _field ) \
+ sizeof ( ( ( struct _structure * ) NULL )->_field )
+
+/*
+ * Assemble native-endian dword from named fields and values
+ *
+ */
+
+#define MLX_ASSEMBLE_1( _structure, _index, _field, _value ) \
+ ( (_value) << \
+ ( MLX_BIT_OFFSET ( _structure, _field ) - ( 32 * (_index) ) ) )
+
+#define MLX_ASSEMBLE_2( _structure, _index, _field, _value, ... ) \
+ ( MLX_ASSEMBLE_1 ( _structure, _index, _field, _value ) | \
+ MLX_ASSEMBLE_1 ( _structure, _index, __VA_ARGS__ ) )
+
+#define MLX_ASSEMBLE_3( _structure, _index, _field, _value, ... ) \
+ ( MLX_ASSEMBLE_1 ( _structure, _index, _field, _value ) | \
+ MLX_ASSEMBLE_2 ( _structure, _index, __VA_ARGS__ ) )
+
+#define MLX_ASSEMBLE_4( _structure, _index, _field, _value, ... ) \
+ ( MLX_ASSEMBLE_1 ( _structure, _index, _field, _value ) | \
+ MLX_ASSEMBLE_3 ( _structure, _index, __VA_ARGS__ ) )
+
+/*
+ * Build native-endian (positive) dword bitmasks from named fields
+ *
+ */
+
+#define MLX_MASK_1( _structure, _index, _field ) \
+ MLX_ASSEMBLE_1 ( _structure, _index, _field, \
+ ( ( 1 << MLX_BIT_WIDTH ( _structure, \
+ _field ) ) - 1 ) )
+
+#define MLX_MASK_2( _structure, _index, _field, ... ) \
+ ( MLX_MASK_1 ( _structure, _index, _field ) | \
+ MLX_MASK_1 ( _structure, _index, __VA_ARGS__ ) )
+
+#define MLX_MASK_3( _structure, _index, _field, ... ) \
+ ( MLX_MASK_1 ( _structure, _index, _field ) | \
+ MLX_MASK_2 ( _structure, _index, __VA_ARGS__ ) )
+
+#define MLX_MASK_4( _structure, _index, _field, ... ) \
+ ( MLX_MASK_1 ( _structure, _index, _field ) | \
+ MLX_MASK_3 ( _structure, _index, __VA_ARGS__ ) )
+
+/*
+ * Populate big-endian dwords from named fields and values
+ *
+ */
+
+#define MLX_POPULATE( _base, _index, _assembled ) \
+ do { \
+ uint32_t *__ptr = ( ( (uint32_t *) (_base) ) + (_index) ); \
+ uint32_t __assembled = (_assembled); \
+ *__ptr = cpu_to_be32 ( __assembled ); \
+ } while ( 0 )
+
+#define MLX_POPULATE_1( _base, _structure, _index, ... ) \
+ MLX_POPULATE ( _base, _index, \
+ MLX_ASSEMBLE_1 ( _structure, _index, __VA_ARGS__ ) )
+
+#define MLX_POPULATE_2( _base, _structure, _index, ... ) \
+ MLX_POPULATE ( _base, _index, \
+ MLX_ASSEMBLE_2 ( _structure, _index, __VA_ARGS__ ) )
+
+#define MLX_POPULATE_3( _base, _structure, _index, ... ) \
+ MLX_POPULATE ( _base, _index, \
+ MLX_ASSEMBLE_3 ( _structure, _index, __VA_ARGS__ ) )
+
+#define MLX_POPULATE_4( _base, _structure, _index, ... ) \
+ MLX_POPULATE ( _base, _index, \
+ MLX_ASSEMBLE_4 ( _structure, _index, __VA_ARGS__ ) )
+
+/*
+ * Modify big-endian dword using named field and value
+ *
+ */
+
+#define MLX_MODIFY( _base, _structure, _index, _field, _value ) \
+ do { \
+ uint32_t *__ptr = ( ( (uint32_t *) (_base) ) + (_index) ); \
+ uint32_t __value = be32_to_cpu ( *__ptr ); \
+ __value &= ~( MLX_MASK_1 ( _structure, _index, _field ) ); \
+ __value |= MLX_ASSEMBLE_1 ( _structure, _index, \
+ _field, _value ); \
+ *__ptr = cpu_to_be32 ( __value ); \
+ } while ( 0 )
+
#endif /* __bit_ops_h__ */