2022-06-08 23:46:35 +00:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
|
|
|
|
/* Copyright(c) 2007 - 2011 Realtek Corporation. */
|
|
|
|
|
2013-05-08 21:45:39 +00:00
|
|
|
#ifndef __BASIC_TYPES_H__
|
|
|
|
#define __BASIC_TYPES_H__
|
|
|
|
|
|
|
|
#define SUCCESS 0
|
|
|
|
#define FAIL (-1)
|
|
|
|
|
2013-05-26 03:02:10 +00:00
|
|
|
#include <linux/types.h>
|
|
|
|
#define NDIS_OID uint
|
2013-05-19 04:28:07 +00:00
|
|
|
|
2013-08-14 02:01:38 +00:00
|
|
|
typedef void (*proc_t)(void *);
|
2013-05-08 21:45:39 +00:00
|
|
|
|
2013-08-14 02:01:38 +00:00
|
|
|
#define FIELD_OFFSET(s, field) ((ssize_t)&((s *)(0))->field)
|
2013-05-08 21:45:39 +00:00
|
|
|
|
2013-08-14 02:01:38 +00:00
|
|
|
#define MEM_ALIGNMENT_OFFSET (sizeof(size_t))
|
2013-07-24 17:19:14 +00:00
|
|
|
#define MEM_ALIGNMENT_PADDING (sizeof(size_t) - 1)
|
2013-05-08 21:45:39 +00:00
|
|
|
|
2013-08-14 02:01:38 +00:00
|
|
|
/* port from fw */
|
|
|
|
/* TODO: Macros Below are Sync from SD7-Driver. It is necessary
|
|
|
|
* to check correctness */
|
2013-05-08 21:45:39 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Call endian free function when
|
|
|
|
* 1. Read/write packet content.
|
|
|
|
* 2. Before write integer to IO.
|
|
|
|
* 3. After read integer from IO.
|
|
|
|
*/
|
|
|
|
|
2013-07-09 22:40:50 +00:00
|
|
|
/* Convert little data endian to host ordering */
|
|
|
|
#define EF1BYTE(_val) \
|
|
|
|
((u8)(_val))
|
|
|
|
#define EF2BYTE(_val) \
|
|
|
|
(le16_to_cpu(_val))
|
|
|
|
#define EF4BYTE(_val) \
|
|
|
|
(le32_to_cpu(_val))
|
|
|
|
|
|
|
|
/* Read data from memory */
|
|
|
|
#define READEF1BYTE(_ptr) \
|
|
|
|
EF1BYTE(*((u8 *)(_ptr)))
|
|
|
|
/* Read le16 data from memory and convert to host ordering */
|
|
|
|
#define READEF2BYTE(_ptr) \
|
|
|
|
EF2BYTE(*(_ptr))
|
|
|
|
#define READEF4BYTE(_ptr) \
|
|
|
|
EF4BYTE(*(_ptr))
|
|
|
|
|
|
|
|
/* Write data to memory */
|
2013-08-14 02:01:38 +00:00
|
|
|
#define WRITEEF1BYTE(_ptr, _val) \
|
|
|
|
do { \
|
|
|
|
(*((u8 *)(_ptr))) = EF1BYTE(_val) \
|
|
|
|
} while (0)
|
2013-07-09 22:40:50 +00:00
|
|
|
/* Write le data to memory in host ordering */
|
2013-08-14 02:01:38 +00:00
|
|
|
#define WRITEEF2BYTE(_ptr, _val) \
|
|
|
|
do { \
|
|
|
|
(*((u16 *)(_ptr))) = EF2BYTE(_val) \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define WRITEEF4BYTE(_ptr, _val) \
|
|
|
|
do { \
|
|
|
|
(*((u32 *)(_ptr))) = EF2BYTE(_val) \
|
|
|
|
} while (0)
|
2013-07-09 22:40:50 +00:00
|
|
|
|
|
|
|
/* Create a bit mask
|
|
|
|
* Examples:
|
|
|
|
* BIT_LEN_MASK_32(0) => 0x00000000
|
|
|
|
* BIT_LEN_MASK_32(1) => 0x00000001
|
|
|
|
* BIT_LEN_MASK_32(2) => 0x00000003
|
|
|
|
* BIT_LEN_MASK_32(32) => 0xFFFFFFFF
|
|
|
|
*/
|
|
|
|
#define BIT_LEN_MASK_32(__bitlen) \
|
|
|
|
(0xFFFFFFFF >> (32 - (__bitlen)))
|
|
|
|
#define BIT_LEN_MASK_16(__bitlen) \
|
|
|
|
(0xFFFF >> (16 - (__bitlen)))
|
|
|
|
#define BIT_LEN_MASK_8(__bitlen) \
|
|
|
|
(0xFF >> (8 - (__bitlen)))
|
|
|
|
|
|
|
|
/* Create an offset bit mask
|
|
|
|
* Examples:
|
|
|
|
* BIT_OFFSET_LEN_MASK_32(0, 2) => 0x00000003
|
|
|
|
* BIT_OFFSET_LEN_MASK_32(16, 2) => 0x00030000
|
|
|
|
*/
|
|
|
|
#define BIT_OFFSET_LEN_MASK_32(__bitoffset, __bitlen) \
|
|
|
|
(BIT_LEN_MASK_32(__bitlen) << (__bitoffset))
|
|
|
|
#define BIT_OFFSET_LEN_MASK_16(__bitoffset, __bitlen) \
|
|
|
|
(BIT_LEN_MASK_16(__bitlen) << (__bitoffset))
|
|
|
|
#define BIT_OFFSET_LEN_MASK_8(__bitoffset, __bitlen) \
|
|
|
|
(BIT_LEN_MASK_8(__bitlen) << (__bitoffset))
|
|
|
|
|
|
|
|
/*Description:
|
|
|
|
* Return 4-byte value in host byte ordering from
|
|
|
|
* 4-byte pointer in little-endian system.
|
|
|
|
*/
|
|
|
|
#define LE_P4BYTE_TO_HOST_4BYTE(__pstart) \
|
|
|
|
(EF4BYTE(*((__le32 *)(__pstart))))
|
|
|
|
#define LE_P2BYTE_TO_HOST_2BYTE(__pstart) \
|
|
|
|
(EF2BYTE(*((__le16 *)(__pstart))))
|
|
|
|
#define LE_P1BYTE_TO_HOST_1BYTE(__pstart) \
|
|
|
|
(EF1BYTE(*((u8 *)(__pstart))))
|
|
|
|
|
|
|
|
/*Description:
|
|
|
|
Translate subfield (continuous bits in little-endian) of 4-byte
|
|
|
|
value to host byte ordering.*/
|
|
|
|
#define LE_BITS_TO_4BYTE(__pstart, __bitoffset, __bitlen) \
|
2013-05-08 21:45:39 +00:00
|
|
|
( \
|
2013-07-09 22:40:50 +00:00
|
|
|
(LE_P4BYTE_TO_HOST_4BYTE(__pstart) >> (__bitoffset)) & \
|
|
|
|
BIT_LEN_MASK_32(__bitlen) \
|
2013-05-08 21:45:39 +00:00
|
|
|
)
|
2013-07-09 22:40:50 +00:00
|
|
|
#define LE_BITS_TO_2BYTE(__pstart, __bitoffset, __bitlen) \
|
2013-05-08 21:45:39 +00:00
|
|
|
( \
|
2013-07-09 22:40:50 +00:00
|
|
|
(LE_P2BYTE_TO_HOST_2BYTE(__pstart) >> (__bitoffset)) & \
|
|
|
|
BIT_LEN_MASK_16(__bitlen) \
|
2013-05-08 21:45:39 +00:00
|
|
|
)
|
2013-07-09 22:40:50 +00:00
|
|
|
#define LE_BITS_TO_1BYTE(__pstart, __bitoffset, __bitlen) \
|
2013-05-08 21:45:39 +00:00
|
|
|
( \
|
2013-07-09 22:40:50 +00:00
|
|
|
(LE_P1BYTE_TO_HOST_1BYTE(__pstart) >> (__bitoffset)) & \
|
|
|
|
BIT_LEN_MASK_8(__bitlen) \
|
2013-05-08 21:45:39 +00:00
|
|
|
)
|
2013-05-19 04:28:07 +00:00
|
|
|
|
2013-07-09 22:40:50 +00:00
|
|
|
#define N_BYTE_ALIGMENT(__value, __aligment) ((__aligment == 1) ? \
|
|
|
|
(__value) : (((__value + __aligment - 1) / __aligment) * __aligment))
|
2013-05-08 21:45:39 +00:00
|
|
|
|
2013-08-12 04:36:23 +00:00
|
|
|
#endif /* __BASIC_TYPES_H__ */
|