root/drivers/staging/rtl8188eu/include/basic_types.h

/* [<][>][^][v][top][bottom][index][help] */

INCLUDED FROM


   1 /* SPDX-License-Identifier: GPL-2.0 */
   2 /******************************************************************************
   3  *
   4  * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
   5  *
   6  ******************************************************************************/
   7 #ifndef __BASIC_TYPES_H__
   8 #define __BASIC_TYPES_H__
   9 
  10 #include <linux/types.h>
  11 #define NDIS_OID uint
  12 
  13 /* port from fw */
  14 /*  TODO: Macros Below are Sync from SD7-Driver. It is necessary
  15  * to check correctness
  16  */
  17 
  18 /*
  19  *      Call endian free function when
  20  *              1. Read/write packet content.
  21  *              2. Before write integer to IO.
  22  *              3. After read integer from IO.
  23  */
  24 
  25 /* Convert little data endian to host ordering */
  26 #define EF1BYTE(_val)           \
  27         ((u8)(_val))
  28 #define EF2BYTE(_val)           \
  29         (le16_to_cpu(_val))
  30 #define EF4BYTE(_val)           \
  31         (le32_to_cpu(_val))
  32 
  33 /* Create a bit mask
  34  * Examples:
  35  * BIT_LEN_MASK_32(0) => 0x00000000
  36  * BIT_LEN_MASK_32(1) => 0x00000001
  37  * BIT_LEN_MASK_32(2) => 0x00000003
  38  * BIT_LEN_MASK_32(32) => 0xFFFFFFFF
  39  */
  40 #define BIT_LEN_MASK_32(__bitlen)        \
  41         (0xFFFFFFFF >> (32 - (__bitlen)))
  42 #define BIT_LEN_MASK_16(__bitlen)        \
  43         (0xFFFF >> (16 - (__bitlen)))
  44 #define BIT_LEN_MASK_8(__bitlen) \
  45         (0xFF >> (8 - (__bitlen)))
  46 
  47 /* Create an offset bit mask
  48  * Examples:
  49  * BIT_OFFSET_LEN_MASK_32(0, 2) => 0x00000003
  50  * BIT_OFFSET_LEN_MASK_32(16, 2) => 0x00030000
  51  */
  52 #define BIT_OFFSET_LEN_MASK_32(__bitoffset, __bitlen) \
  53         (BIT_LEN_MASK_32(__bitlen) << (__bitoffset))
  54 #define BIT_OFFSET_LEN_MASK_16(__bitoffset, __bitlen) \
  55         (BIT_LEN_MASK_16(__bitlen) << (__bitoffset))
  56 #define BIT_OFFSET_LEN_MASK_8(__bitoffset, __bitlen) \
  57         (BIT_LEN_MASK_8(__bitlen) << (__bitoffset))
  58 
  59 /*Description:
  60  * Return 4-byte value in host byte ordering from
  61  * 4-byte pointer in little-endian system.
  62  */
  63 #define LE_P4BYTE_TO_HOST_4BYTE(__pstart) \
  64         (EF4BYTE(*((__le32 *)(__pstart))))
  65 #define LE_P2BYTE_TO_HOST_2BYTE(__pstart) \
  66         (EF2BYTE(*((__le16 *)(__pstart))))
  67 #define LE_P1BYTE_TO_HOST_1BYTE(__pstart) \
  68         (EF1BYTE(*((u8 *)(__pstart))))
  69 
  70 /* Description:
  71  * Translate subfield (continuous bits in little-endian) of 4-byte
  72  * value to host byte ordering.
  73  */
  74 #define LE_BITS_TO_4BYTE(__pstart, __bitoffset, __bitlen) \
  75         ( \
  76                 (LE_P4BYTE_TO_HOST_4BYTE(__pstart) >> (__bitoffset))  & \
  77                 BIT_LEN_MASK_32(__bitlen) \
  78         )
  79 #define LE_BITS_TO_2BYTE(__pstart, __bitoffset, __bitlen) \
  80         ( \
  81                 (LE_P2BYTE_TO_HOST_2BYTE(__pstart) >> (__bitoffset)) & \
  82                 BIT_LEN_MASK_16(__bitlen) \
  83         )
  84 #define LE_BITS_TO_1BYTE(__pstart, __bitoffset, __bitlen) \
  85         ( \
  86                 (LE_P1BYTE_TO_HOST_1BYTE(__pstart) >> (__bitoffset)) & \
  87                 BIT_LEN_MASK_8(__bitlen) \
  88         )
  89 
  90 /* Description:
  91  * Mask subfield (continuous bits in little-endian) of 4-byte value
  92  * and return the result in 4-byte value in host byte ordering.
  93  */
  94 #define LE_BITS_CLEARED_TO_4BYTE(__pstart, __bitoffset, __bitlen) \
  95         ( \
  96                 LE_P4BYTE_TO_HOST_4BYTE(__pstart)  & \
  97                 (~BIT_OFFSET_LEN_MASK_32(__bitoffset, __bitlen)) \
  98         )
  99 #define LE_BITS_CLEARED_TO_2BYTE(__pstart, __bitoffset, __bitlen) \
 100         ( \
 101                 LE_P2BYTE_TO_HOST_2BYTE(__pstart) & \
 102                 (~BIT_OFFSET_LEN_MASK_16(__bitoffset, __bitlen)) \
 103         )
 104 #define LE_BITS_CLEARED_TO_1BYTE(__pstart, __bitoffset, __bitlen) \
 105         ( \
 106                 LE_P1BYTE_TO_HOST_1BYTE(__pstart) & \
 107                 (~BIT_OFFSET_LEN_MASK_8(__bitoffset, __bitlen)) \
 108         )
 109 
 110 /* Description:
 111  * Set subfield of little-endian 4-byte value to specified value.
 112  */
 113 #define SET_BITS_TO_LE_4BYTE(__pstart, __bitoffset, __bitlen, __val) \
 114                 *((u32 *)(__pstart)) =                          \
 115                 (                                                       \
 116                 LE_BITS_CLEARED_TO_4BYTE(__pstart, __bitoffset, __bitlen) | \
 117                 ((((u32)__val) & BIT_LEN_MASK_32(__bitlen)) << (__bitoffset)) \
 118                 )
 119 
 120 #define SET_BITS_TO_LE_2BYTE(__pstart, __bitoffset, __bitlen, __val) \
 121                 *((u16 *)(__pstart)) =                          \
 122                 (                                               \
 123                 LE_BITS_CLEARED_TO_2BYTE(__pstart, __bitoffset, __bitlen) | \
 124                 ((((u16)__val) & BIT_LEN_MASK_16(__bitlen)) << (__bitoffset)) \
 125                 );
 126 
 127 #define SET_BITS_TO_LE_1BYTE(__pstart, __bitoffset, __bitlen, __val) \
 128                 *((u8 *)(__pstart)) = EF1BYTE                   \
 129                 (                                               \
 130                 LE_BITS_CLEARED_TO_1BYTE(__pstart, __bitoffset, __bitlen) | \
 131                 ((((u8)__val) & BIT_LEN_MASK_8(__bitlen)) << (__bitoffset)) \
 132                 )
 133 
 134 #endif /* __BASIC_TYPES_H__ */

/* [<][>][^][v][top][bottom][index][help] */