iPXE
Macros | Typedefs | Functions
mlx_bitops.h File Reference

Mellanox bit operations. More...

Go to the source code of this file.

Macros

#define MLX_DECLARE_STRUCT(_structure)
 Wrapper structure for pseudo_bit_t structures. More...
 
#define MLX_PSEUDO_STRUCT(_ptr)   typeof ( *((_ptr)->u.dummy[0]) )
 Get pseudo_bit_t structure type from wrapper structure pointer. More...
 
#define MLX_BIT_OFFSET(_structure_st, _field)   offsetof ( _structure_st, _field )
 Bit offset of a field within a pseudo_bit_t structure. More...
 
#define MLX_DWORD_OFFSET(_structure_st, _field)   ( MLX_BIT_OFFSET ( _structure_st, _field ) / 32 )
 Dword offset of a field within a pseudo_bit_t structure. More...
 
#define MLX_DWORD_BIT_OFFSET(_structure_st, _index, _field)   ( MLX_BIT_OFFSET ( _structure_st, _field ) - ( 32 * (_index) ) )
 Dword bit offset of a field within a pseudo_bit_t structure. More...
 
#define MLX_BIT_WIDTH(_structure_st, _field)   sizeof ( ( ( _structure_st * ) NULL )->_field )
 Bit width of a field within a pseudo_bit_t structure. More...
 
#define MLX_BIT_MASK(_structure_st, _field)
 Bit mask for a field within a pseudo_bit_t structure. More...
 
#define MLX_ASSEMBLE_1(_structure_st, _index, _field, _value)   ( (_value) << MLX_DWORD_BIT_OFFSET ( _structure_st, _index, _field ) )
 
#define MLX_ASSEMBLE_2(_structure_st, _index, _field, _value, ...)
 
#define MLX_ASSEMBLE_3(_structure_st, _index, _field, _value, ...)
 
#define MLX_ASSEMBLE_4(_structure_st, _index, _field, _value, ...)
 
#define MLX_ASSEMBLE_5(_structure_st, _index, _field, _value, ...)
 
#define MLX_ASSEMBLE_6(_structure_st, _index, _field, _value, ...)
 
#define MLX_ASSEMBLE_7(_structure_st, _index, _field, _value, ...)
 
#define MLX_ASSEMBLE_8(_structure_st, _index, _field, _value, ...)
 
#define MLX_MASK_1(_structure_st, _index, _field)
 
#define MLX_MASK_2(_structure_st, _index, _field, ...)
 
#define MLX_MASK_3(_structure_st, _index, _field, ...)
 
#define MLX_MASK_4(_structure_st, _index, _field, ...)
 
#define MLX_MASK_5(_structure_st, _index, _field, ...)
 
#define MLX_MASK_6(_structure_st, _index, _field, ...)
 
#define MLX_MASK_7(_structure_st, _index, _field, ...)
 
#define MLX_MASK_8(_structure_st, _index, _field, ...)
 
#define MLX_FILL(_ptr, _index, _assembled)
 
#define MLX_FILL_1(_ptr, _index, ...)
 
#define MLX_FILL_2(_ptr, _index, ...)
 
#define MLX_FILL_3(_ptr, _index, ...)
 
#define MLX_FILL_4(_ptr, _index, ...)
 
#define MLX_FILL_5(_ptr, _index, ...)
 
#define MLX_FILL_6(_ptr, _index, ...)
 
#define MLX_FILL_7(_ptr, _index, ...)
 
#define MLX_FILL_8(_ptr, _index, ...)
 
#define MLX_SET(_ptr, _field, _value)
 
#define MLX_GET(_ptr, _field)
 
#define MLX_FILL_H(_structure_st, _index, _field, _address)
 

Typedefs

typedef unsigned char pseudo_bit_t
 

Functions

 FILE_LICENCE (GPL2_OR_LATER)
 

Detailed Description

Mellanox bit operations.

Definition in file mlx_bitops.h.

Macro Definition Documentation

◆ MLX_DECLARE_STRUCT

#define MLX_DECLARE_STRUCT (   _structure)
Value:
_structure { \
union { \
uint8_t bytes[ sizeof ( struct _structure ## _st ) / 8 ]; \
uint32_t dwords[ sizeof ( struct _structure ## _st ) / 32 ]; \
struct _structure ## _st *dummy[0]; \
} __attribute__ (( packed )) u; \
} __attribute__ (( packed ))
#define __attribute__(x)
Definition: compiler.h:10
union @16 u
uint8_t bytes[64]
Definition: ib_mad.h:16

Wrapper structure for pseudo_bit_t structures.

This structure provides a wrapper around the autogenerated pseudo_bit_t structures. It has the correct size, and also encapsulates type information about the underlying pseudo_bit_t structure, which allows the MLX_FILL etc. macros to work without requiring explicit type information.

Definition at line 44 of file mlx_bitops.h.

◆ MLX_PSEUDO_STRUCT

#define MLX_PSEUDO_STRUCT (   _ptr)    typeof ( *((_ptr)->u.dummy[0]) )

Get pseudo_bit_t structure type from wrapper structure pointer.

Definition at line 54 of file mlx_bitops.h.

◆ MLX_BIT_OFFSET

#define MLX_BIT_OFFSET (   _structure_st,
  _field 
)    offsetof ( _structure_st, _field )

Bit offset of a field within a pseudo_bit_t structure.

Definition at line 58 of file mlx_bitops.h.

◆ MLX_DWORD_OFFSET

#define MLX_DWORD_OFFSET (   _structure_st,
  _field 
)    ( MLX_BIT_OFFSET ( _structure_st, _field ) / 32 )

Dword offset of a field within a pseudo_bit_t structure.

Definition at line 62 of file mlx_bitops.h.

◆ MLX_DWORD_BIT_OFFSET

#define MLX_DWORD_BIT_OFFSET (   _structure_st,
  _index,
  _field 
)    ( MLX_BIT_OFFSET ( _structure_st, _field ) - ( 32 * (_index) ) )

Dword bit offset of a field within a pseudo_bit_t structure.

Yes, using mod-32 would work, but would lose the check for the error of specifying a mismatched field name and dword index.

Definition at line 70 of file mlx_bitops.h.

◆ MLX_BIT_WIDTH

#define MLX_BIT_WIDTH (   _structure_st,
  _field 
)    sizeof ( ( ( _structure_st * ) NULL )->_field )

Bit width of a field within a pseudo_bit_t structure.

Definition at line 74 of file mlx_bitops.h.

◆ MLX_BIT_MASK

#define MLX_BIT_MASK (   _structure_st,
  _field 
)
Value:
( ( ~( ( uint32_t ) 0 ) ) >> \
( 32 - MLX_BIT_WIDTH ( _structure_st, _field ) ) )
unsigned int uint32_t
Definition: stdint.h:12
#define MLX_BIT_WIDTH(_structure_st, _field)
Bit width of a field within a pseudo_bit_t structure.
Definition: mlx_bitops.h:74

Bit mask for a field within a pseudo_bit_t structure.

Definition at line 78 of file mlx_bitops.h.

◆ MLX_ASSEMBLE_1

#define MLX_ASSEMBLE_1 (   _structure_st,
  _index,
  _field,
  _value 
)    ( (_value) << MLX_DWORD_BIT_OFFSET ( _structure_st, _index, _field ) )

Definition at line 87 of file mlx_bitops.h.

◆ MLX_ASSEMBLE_2

#define MLX_ASSEMBLE_2 (   _structure_st,
  _index,
  _field,
  _value,
  ... 
)
Value:
( MLX_ASSEMBLE_1 ( _structure_st, _index, _field, _value ) | \
MLX_ASSEMBLE_1 ( _structure_st, _index, __VA_ARGS__ ) )
#define MLX_ASSEMBLE_1(_structure_st, _index, _field, _value)
Definition: mlx_bitops.h:87

Definition at line 90 of file mlx_bitops.h.

◆ MLX_ASSEMBLE_3

#define MLX_ASSEMBLE_3 (   _structure_st,
  _index,
  _field,
  _value,
  ... 
)
Value:
( MLX_ASSEMBLE_1 ( _structure_st, _index, _field, _value ) | \
MLX_ASSEMBLE_2 ( _structure_st, _index, __VA_ARGS__ ) )
#define MLX_ASSEMBLE_1(_structure_st, _index, _field, _value)
Definition: mlx_bitops.h:87

Definition at line 94 of file mlx_bitops.h.

◆ MLX_ASSEMBLE_4

#define MLX_ASSEMBLE_4 (   _structure_st,
  _index,
  _field,
  _value,
  ... 
)
Value:
( MLX_ASSEMBLE_1 ( _structure_st, _index, _field, _value ) | \
MLX_ASSEMBLE_3 ( _structure_st, _index, __VA_ARGS__ ) )
#define MLX_ASSEMBLE_1(_structure_st, _index, _field, _value)
Definition: mlx_bitops.h:87

Definition at line 98 of file mlx_bitops.h.

◆ MLX_ASSEMBLE_5

#define MLX_ASSEMBLE_5 (   _structure_st,
  _index,
  _field,
  _value,
  ... 
)
Value:
( MLX_ASSEMBLE_1 ( _structure_st, _index, _field, _value ) | \
MLX_ASSEMBLE_4 ( _structure_st, _index, __VA_ARGS__ ) )
#define MLX_ASSEMBLE_1(_structure_st, _index, _field, _value)
Definition: mlx_bitops.h:87

Definition at line 102 of file mlx_bitops.h.

◆ MLX_ASSEMBLE_6

#define MLX_ASSEMBLE_6 (   _structure_st,
  _index,
  _field,
  _value,
  ... 
)
Value:
( MLX_ASSEMBLE_1 ( _structure_st, _index, _field, _value ) | \
MLX_ASSEMBLE_5 ( _structure_st, _index, __VA_ARGS__ ) )
#define MLX_ASSEMBLE_1(_structure_st, _index, _field, _value)
Definition: mlx_bitops.h:87

Definition at line 106 of file mlx_bitops.h.

◆ MLX_ASSEMBLE_7

#define MLX_ASSEMBLE_7 (   _structure_st,
  _index,
  _field,
  _value,
  ... 
)
Value:
( MLX_ASSEMBLE_1 ( _structure_st, _index, _field, _value ) | \
MLX_ASSEMBLE_6 ( _structure_st, _index, __VA_ARGS__ ) )
#define MLX_ASSEMBLE_1(_structure_st, _index, _field, _value)
Definition: mlx_bitops.h:87

Definition at line 110 of file mlx_bitops.h.

◆ MLX_ASSEMBLE_8

#define MLX_ASSEMBLE_8 (   _structure_st,
  _index,
  _field,
  _value,
  ... 
)
Value:
( MLX_ASSEMBLE_1 ( _structure_st, _index, _field, _value ) | \
MLX_ASSEMBLE_7 ( _structure_st, _index, __VA_ARGS__ ) )
#define MLX_ASSEMBLE_1(_structure_st, _index, _field, _value)
Definition: mlx_bitops.h:87

Definition at line 114 of file mlx_bitops.h.

◆ MLX_MASK_1

#define MLX_MASK_1 (   _structure_st,
  _index,
  _field 
)
Value:
( MLX_BIT_MASK ( _structure_st, _field ) << \
MLX_DWORD_BIT_OFFSET ( _structure_st, _index, _field ) )
#define MLX_BIT_MASK(_structure_st, _field)
Bit mask for a field within a pseudo_bit_t structure.
Definition: mlx_bitops.h:78

Definition at line 123 of file mlx_bitops.h.

◆ MLX_MASK_2

#define MLX_MASK_2 (   _structure_st,
  _index,
  _field,
  ... 
)
Value:
( MLX_MASK_1 ( _structure_st, _index, _field ) | \
MLX_MASK_1 ( _structure_st, _index, __VA_ARGS__ ) )
#define MLX_MASK_1(_structure_st, _index, _field)
Definition: mlx_bitops.h:123

Definition at line 127 of file mlx_bitops.h.

◆ MLX_MASK_3

#define MLX_MASK_3 (   _structure_st,
  _index,
  _field,
  ... 
)
Value:
( MLX_MASK_1 ( _structure_st, _index, _field ) | \
MLX_MASK_2 ( _structure_st, _index, __VA_ARGS__ ) )
#define MLX_MASK_1(_structure_st, _index, _field)
Definition: mlx_bitops.h:123

Definition at line 131 of file mlx_bitops.h.

◆ MLX_MASK_4

#define MLX_MASK_4 (   _structure_st,
  _index,
  _field,
  ... 
)
Value:
( MLX_MASK_1 ( _structure_st, _index, _field ) | \
MLX_MASK_3 ( _structure_st, _index, __VA_ARGS__ ) )
#define MLX_MASK_1(_structure_st, _index, _field)
Definition: mlx_bitops.h:123

Definition at line 135 of file mlx_bitops.h.

◆ MLX_MASK_5

#define MLX_MASK_5 (   _structure_st,
  _index,
  _field,
  ... 
)
Value:
( MLX_MASK_1 ( _structure_st, _index, _field ) | \
MLX_MASK_4 ( _structure_st, _index, __VA_ARGS__ ) )
#define MLX_MASK_1(_structure_st, _index, _field)
Definition: mlx_bitops.h:123

Definition at line 139 of file mlx_bitops.h.

◆ MLX_MASK_6

#define MLX_MASK_6 (   _structure_st,
  _index,
  _field,
  ... 
)
Value:
( MLX_MASK_1 ( _structure_st, _index, _field ) | \
MLX_MASK_5 ( _structure_st, _index, __VA_ARGS__ ) )
#define MLX_MASK_1(_structure_st, _index, _field)
Definition: mlx_bitops.h:123

Definition at line 143 of file mlx_bitops.h.

◆ MLX_MASK_7

#define MLX_MASK_7 (   _structure_st,
  _index,
  _field,
  ... 
)
Value:
( MLX_MASK_1 ( _structure_st, _index, _field ) | \
MLX_MASK_6 ( _structure_st, _index, __VA_ARGS__ ) )
#define MLX_MASK_1(_structure_st, _index, _field)
Definition: mlx_bitops.h:123

Definition at line 147 of file mlx_bitops.h.

◆ MLX_MASK_8

#define MLX_MASK_8 (   _structure_st,
  _index,
  _field,
  ... 
)
Value:
( MLX_MASK_1 ( _structure_st, _index, _field ) | \
MLX_MASK_7 ( _structure_st, _index, __VA_ARGS__ ) )
#define MLX_MASK_1(_structure_st, _index, _field)
Definition: mlx_bitops.h:123

Definition at line 151 of file mlx_bitops.h.

◆ MLX_FILL

#define MLX_FILL (   _ptr,
  _index,
  _assembled 
)
Value:
do { \
uint32_t *__ptr = &(_ptr)->u.dwords[(_index)]; \
uint32_t __assembled = (_assembled); \
*__ptr = cpu_to_be32 ( __assembled ); \
} while ( 0 )
#define cpu_to_be32(value)
Definition: byteswap.h:110
union @16 u

Definition at line 160 of file mlx_bitops.h.

◆ MLX_FILL_1

#define MLX_FILL_1 (   _ptr,
  _index,
  ... 
)
Value:
MLX_FILL ( _ptr, _index, MLX_ASSEMBLE_1 ( MLX_PSEUDO_STRUCT ( _ptr ),\
_index, __VA_ARGS__ ) )
#define MLX_PSEUDO_STRUCT(_ptr)
Get pseudo_bit_t structure type from wrapper structure pointer.
Definition: mlx_bitops.h:54
#define MLX_FILL(_ptr, _index, _assembled)
Definition: mlx_bitops.h:160
#define MLX_ASSEMBLE_1(_structure_st, _index, _field, _value)
Definition: mlx_bitops.h:87

Definition at line 167 of file mlx_bitops.h.

◆ MLX_FILL_2

#define MLX_FILL_2 (   _ptr,
  _index,
  ... 
)
Value:
MLX_FILL ( _ptr, _index, MLX_ASSEMBLE_2 ( MLX_PSEUDO_STRUCT ( _ptr ),\
_index, __VA_ARGS__ ) )
#define MLX_ASSEMBLE_2(_structure_st, _index, _field, _value,...)
Definition: mlx_bitops.h:90
#define MLX_PSEUDO_STRUCT(_ptr)
Get pseudo_bit_t structure type from wrapper structure pointer.
Definition: mlx_bitops.h:54
#define MLX_FILL(_ptr, _index, _assembled)
Definition: mlx_bitops.h:160

Definition at line 171 of file mlx_bitops.h.

◆ MLX_FILL_3

#define MLX_FILL_3 (   _ptr,
  _index,
  ... 
)
Value:
MLX_FILL ( _ptr, _index, MLX_ASSEMBLE_3 ( MLX_PSEUDO_STRUCT ( _ptr ),\
_index, __VA_ARGS__ ) )
#define MLX_ASSEMBLE_3(_structure_st, _index, _field, _value,...)
Definition: mlx_bitops.h:94
#define MLX_PSEUDO_STRUCT(_ptr)
Get pseudo_bit_t structure type from wrapper structure pointer.
Definition: mlx_bitops.h:54
#define MLX_FILL(_ptr, _index, _assembled)
Definition: mlx_bitops.h:160

Definition at line 175 of file mlx_bitops.h.

◆ MLX_FILL_4

#define MLX_FILL_4 (   _ptr,
  _index,
  ... 
)
Value:
MLX_FILL ( _ptr, _index, MLX_ASSEMBLE_4 ( MLX_PSEUDO_STRUCT ( _ptr ),\
_index, __VA_ARGS__ ) )
#define MLX_ASSEMBLE_4(_structure_st, _index, _field, _value,...)
Definition: mlx_bitops.h:98
#define MLX_PSEUDO_STRUCT(_ptr)
Get pseudo_bit_t structure type from wrapper structure pointer.
Definition: mlx_bitops.h:54
#define MLX_FILL(_ptr, _index, _assembled)
Definition: mlx_bitops.h:160

Definition at line 179 of file mlx_bitops.h.

◆ MLX_FILL_5

#define MLX_FILL_5 (   _ptr,
  _index,
  ... 
)
Value:
MLX_FILL ( _ptr, _index, MLX_ASSEMBLE_5 ( MLX_PSEUDO_STRUCT ( _ptr ),\
_index, __VA_ARGS__ ) )
#define MLX_PSEUDO_STRUCT(_ptr)
Get pseudo_bit_t structure type from wrapper structure pointer.
Definition: mlx_bitops.h:54
#define MLX_ASSEMBLE_5(_structure_st, _index, _field, _value,...)
Definition: mlx_bitops.h:102
#define MLX_FILL(_ptr, _index, _assembled)
Definition: mlx_bitops.h:160

Definition at line 183 of file mlx_bitops.h.

◆ MLX_FILL_6

#define MLX_FILL_6 (   _ptr,
  _index,
  ... 
)
Value:
MLX_FILL ( _ptr, _index, MLX_ASSEMBLE_6 ( MLX_PSEUDO_STRUCT ( _ptr ),\
_index, __VA_ARGS__ ) )
#define MLX_PSEUDO_STRUCT(_ptr)
Get pseudo_bit_t structure type from wrapper structure pointer.
Definition: mlx_bitops.h:54
#define MLX_ASSEMBLE_6(_structure_st, _index, _field, _value,...)
Definition: mlx_bitops.h:106
#define MLX_FILL(_ptr, _index, _assembled)
Definition: mlx_bitops.h:160

Definition at line 187 of file mlx_bitops.h.

◆ MLX_FILL_7

#define MLX_FILL_7 (   _ptr,
  _index,
  ... 
)
Value:
MLX_FILL ( _ptr, _index, MLX_ASSEMBLE_7 ( MLX_PSEUDO_STRUCT ( _ptr ),\
_index, __VA_ARGS__ ) )
#define MLX_ASSEMBLE_7(_structure_st, _index, _field, _value,...)
Definition: mlx_bitops.h:110
#define MLX_PSEUDO_STRUCT(_ptr)
Get pseudo_bit_t structure type from wrapper structure pointer.
Definition: mlx_bitops.h:54
#define MLX_FILL(_ptr, _index, _assembled)
Definition: mlx_bitops.h:160

Definition at line 191 of file mlx_bitops.h.

◆ MLX_FILL_8

#define MLX_FILL_8 (   _ptr,
  _index,
  ... 
)
Value:
MLX_FILL ( _ptr, _index, MLX_ASSEMBLE_8 ( MLX_PSEUDO_STRUCT ( _ptr ),\
_index, __VA_ARGS__ ) )
#define MLX_PSEUDO_STRUCT(_ptr)
Get pseudo_bit_t structure type from wrapper structure pointer.
Definition: mlx_bitops.h:54
#define MLX_FILL(_ptr, _index, _assembled)
Definition: mlx_bitops.h:160
#define MLX_ASSEMBLE_8(_structure_st, _index, _field, _value,...)
Definition: mlx_bitops.h:114

Definition at line 195 of file mlx_bitops.h.

◆ MLX_SET

#define MLX_SET (   _ptr,
  _field,
  _value 
)
Value:
do { \
unsigned int __index = \
MLX_DWORD_OFFSET ( MLX_PSEUDO_STRUCT ( _ptr ), _field ); \
uint32_t *__ptr = &(_ptr)->u.dwords[__index]; \
uint32_t __value = be32_to_cpu ( *__ptr ); \
__value &= ~( MLX_MASK_1 ( MLX_PSEUDO_STRUCT ( _ptr ), \
__index, _field ) ); \
__value |= MLX_ASSEMBLE_1 ( MLX_PSEUDO_STRUCT ( _ptr ), \
__index, _field, _value ); \
*__ptr = cpu_to_be32 ( __value ); \
} while ( 0 )
#define MLX_PSEUDO_STRUCT(_ptr)
Get pseudo_bit_t structure type from wrapper structure pointer.
Definition: mlx_bitops.h:54
#define be32_to_cpu(value)
Definition: byteswap.h:116
#define MLX_ASSEMBLE_1(_structure_st, _index, _field, _value)
Definition: mlx_bitops.h:87
unsigned int uint32_t
Definition: stdint.h:12
#define cpu_to_be32(value)
Definition: byteswap.h:110
#define MLX_MASK_1(_structure_st, _index, _field)
Definition: mlx_bitops.h:123
union @16 u

Definition at line 204 of file mlx_bitops.h.

◆ MLX_GET

#define MLX_GET (   _ptr,
  _field 
)
Value:
( { \
unsigned int __index = \
MLX_DWORD_OFFSET ( MLX_PSEUDO_STRUCT ( _ptr ), _field ); \
uint32_t *__ptr = &(_ptr)->u.dwords[__index]; \
uint32_t __value = be32_to_cpu ( *__ptr ); \
__value >>= \
MLX_DWORD_BIT_OFFSET ( MLX_PSEUDO_STRUCT ( _ptr ), \
__index, _field ); \
__value &= \
MLX_BIT_MASK ( MLX_PSEUDO_STRUCT ( _ptr ), _field ); \
__value; \
} )
#define MLX_PSEUDO_STRUCT(_ptr)
Get pseudo_bit_t structure type from wrapper structure pointer.
Definition: mlx_bitops.h:54
#define be32_to_cpu(value)
Definition: byteswap.h:116
unsigned int uint32_t
Definition: stdint.h:12
union @16 u

Definition at line 222 of file mlx_bitops.h.

◆ MLX_FILL_H

#define MLX_FILL_H (   _structure_st,
  _index,
  _field,
  _address 
)
Value:
do { \
if ( sizeof ( physaddr_t ) > sizeof ( uint32_t ) ) { \
MLX_FILL_1 ( _structure_st, _index, _field, \
( ( ( uint64_t ) (_address) ) >> 32 ) ); \
} } while ( 0 )
unsigned long long uint64_t
Definition: stdint.h:13
unsigned int uint32_t
Definition: stdint.h:12
unsigned long physaddr_t
Definition: stdint.h:20

Definition at line 240 of file mlx_bitops.h.

Typedef Documentation

◆ pseudo_bit_t

typedef unsigned char pseudo_bit_t

Definition at line 33 of file mlx_bitops.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER  )