18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci	Copyright (C) 2004 - 2009 Ivo van Doorn <IvDoorn@gmail.com>
48c2ecf20Sopenharmony_ci	<http://rt2x00.serialmonkey.com>
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_ci */
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci/*
98c2ecf20Sopenharmony_ci	Module: rt2x00
108c2ecf20Sopenharmony_ci	Abstract: rt2x00 generic register information.
118c2ecf20Sopenharmony_ci */
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ci#ifndef RT2X00REG_H
148c2ecf20Sopenharmony_ci#define RT2X00REG_H
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_ci/*
178c2ecf20Sopenharmony_ci * RX crypto status
188c2ecf20Sopenharmony_ci */
198c2ecf20Sopenharmony_cienum rx_crypto {
208c2ecf20Sopenharmony_ci	RX_CRYPTO_SUCCESS = 0,
218c2ecf20Sopenharmony_ci	RX_CRYPTO_FAIL_ICV = 1,
228c2ecf20Sopenharmony_ci	RX_CRYPTO_FAIL_MIC = 2,
238c2ecf20Sopenharmony_ci	RX_CRYPTO_FAIL_KEY = 3,
248c2ecf20Sopenharmony_ci};
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci/*
278c2ecf20Sopenharmony_ci * Antenna values
288c2ecf20Sopenharmony_ci */
298c2ecf20Sopenharmony_cienum antenna {
308c2ecf20Sopenharmony_ci	ANTENNA_SW_DIVERSITY = 0,
318c2ecf20Sopenharmony_ci	ANTENNA_A = 1,
328c2ecf20Sopenharmony_ci	ANTENNA_B = 2,
338c2ecf20Sopenharmony_ci	ANTENNA_HW_DIVERSITY = 3,
348c2ecf20Sopenharmony_ci};
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ci/*
378c2ecf20Sopenharmony_ci * Led mode values.
388c2ecf20Sopenharmony_ci */
398c2ecf20Sopenharmony_cienum led_mode {
408c2ecf20Sopenharmony_ci	LED_MODE_DEFAULT = 0,
418c2ecf20Sopenharmony_ci	LED_MODE_TXRX_ACTIVITY = 1,
428c2ecf20Sopenharmony_ci	LED_MODE_SIGNAL_STRENGTH = 2,
438c2ecf20Sopenharmony_ci	LED_MODE_ASUS = 3,
448c2ecf20Sopenharmony_ci	LED_MODE_ALPHA = 4,
458c2ecf20Sopenharmony_ci};
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_ci/*
488c2ecf20Sopenharmony_ci * TSF sync values
498c2ecf20Sopenharmony_ci */
508c2ecf20Sopenharmony_cienum tsf_sync {
518c2ecf20Sopenharmony_ci	TSF_SYNC_NONE = 0,
528c2ecf20Sopenharmony_ci	TSF_SYNC_INFRA = 1,
538c2ecf20Sopenharmony_ci	TSF_SYNC_ADHOC = 2,
548c2ecf20Sopenharmony_ci	TSF_SYNC_AP_NONE = 3,
558c2ecf20Sopenharmony_ci};
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_ci/*
588c2ecf20Sopenharmony_ci * Device states
598c2ecf20Sopenharmony_ci */
608c2ecf20Sopenharmony_cienum dev_state {
618c2ecf20Sopenharmony_ci	STATE_DEEP_SLEEP = 0,
628c2ecf20Sopenharmony_ci	STATE_SLEEP = 1,
638c2ecf20Sopenharmony_ci	STATE_STANDBY = 2,
648c2ecf20Sopenharmony_ci	STATE_AWAKE = 3,
658c2ecf20Sopenharmony_ci
668c2ecf20Sopenharmony_ci/*
678c2ecf20Sopenharmony_ci * Additional device states, these values are
688c2ecf20Sopenharmony_ci * not strict since they are not directly passed
698c2ecf20Sopenharmony_ci * into the device.
708c2ecf20Sopenharmony_ci */
718c2ecf20Sopenharmony_ci	STATE_RADIO_ON,
728c2ecf20Sopenharmony_ci	STATE_RADIO_OFF,
738c2ecf20Sopenharmony_ci	STATE_RADIO_IRQ_ON,
748c2ecf20Sopenharmony_ci	STATE_RADIO_IRQ_OFF,
758c2ecf20Sopenharmony_ci};
768c2ecf20Sopenharmony_ci
778c2ecf20Sopenharmony_ci/*
788c2ecf20Sopenharmony_ci * IFS backoff values
798c2ecf20Sopenharmony_ci */
808c2ecf20Sopenharmony_cienum ifs {
818c2ecf20Sopenharmony_ci	IFS_BACKOFF = 0,
828c2ecf20Sopenharmony_ci	IFS_SIFS = 1,
838c2ecf20Sopenharmony_ci	IFS_NEW_BACKOFF = 2,
848c2ecf20Sopenharmony_ci	IFS_NONE = 3,
858c2ecf20Sopenharmony_ci};
868c2ecf20Sopenharmony_ci
878c2ecf20Sopenharmony_ci/*
888c2ecf20Sopenharmony_ci * IFS backoff values for HT devices
898c2ecf20Sopenharmony_ci */
908c2ecf20Sopenharmony_cienum txop {
918c2ecf20Sopenharmony_ci	TXOP_HTTXOP = 0,
928c2ecf20Sopenharmony_ci	TXOP_PIFS = 1,
938c2ecf20Sopenharmony_ci	TXOP_SIFS = 2,
948c2ecf20Sopenharmony_ci	TXOP_BACKOFF = 3,
958c2ecf20Sopenharmony_ci};
968c2ecf20Sopenharmony_ci
978c2ecf20Sopenharmony_ci/*
988c2ecf20Sopenharmony_ci * Cipher types for hardware encryption
998c2ecf20Sopenharmony_ci */
1008c2ecf20Sopenharmony_cienum cipher {
1018c2ecf20Sopenharmony_ci	CIPHER_NONE = 0,
1028c2ecf20Sopenharmony_ci	CIPHER_WEP64 = 1,
1038c2ecf20Sopenharmony_ci	CIPHER_WEP128 = 2,
1048c2ecf20Sopenharmony_ci	CIPHER_TKIP = 3,
1058c2ecf20Sopenharmony_ci	CIPHER_AES = 4,
1068c2ecf20Sopenharmony_ci/*
1078c2ecf20Sopenharmony_ci * The following fields were added by rt61pci and rt73usb.
1088c2ecf20Sopenharmony_ci */
1098c2ecf20Sopenharmony_ci	CIPHER_CKIP64 = 5,
1108c2ecf20Sopenharmony_ci	CIPHER_CKIP128 = 6,
1118c2ecf20Sopenharmony_ci	CIPHER_TKIP_NO_MIC = 7, /* Don't send to device */
1128c2ecf20Sopenharmony_ci
1138c2ecf20Sopenharmony_ci/*
1148c2ecf20Sopenharmony_ci * Max cipher type.
1158c2ecf20Sopenharmony_ci * Note that CIPHER_NONE isn't counted, and CKIP64 and CKIP128
1168c2ecf20Sopenharmony_ci * are excluded due to limitations in mac80211.
1178c2ecf20Sopenharmony_ci */
1188c2ecf20Sopenharmony_ci	CIPHER_MAX = 4,
1198c2ecf20Sopenharmony_ci};
1208c2ecf20Sopenharmony_ci
1218c2ecf20Sopenharmony_ci/*
1228c2ecf20Sopenharmony_ci * Rate modulations
1238c2ecf20Sopenharmony_ci */
1248c2ecf20Sopenharmony_cienum rate_modulation {
1258c2ecf20Sopenharmony_ci	RATE_MODE_CCK = 0,
1268c2ecf20Sopenharmony_ci	RATE_MODE_OFDM = 1,
1278c2ecf20Sopenharmony_ci	RATE_MODE_HT_MIX = 2,
1288c2ecf20Sopenharmony_ci	RATE_MODE_HT_GREENFIELD = 3,
1298c2ecf20Sopenharmony_ci};
1308c2ecf20Sopenharmony_ci
1318c2ecf20Sopenharmony_ci/*
1328c2ecf20Sopenharmony_ci * Firmware validation error codes
1338c2ecf20Sopenharmony_ci */
1348c2ecf20Sopenharmony_cienum firmware_errors {
1358c2ecf20Sopenharmony_ci	FW_OK,
1368c2ecf20Sopenharmony_ci	FW_BAD_CRC,
1378c2ecf20Sopenharmony_ci	FW_BAD_LENGTH,
1388c2ecf20Sopenharmony_ci	FW_BAD_VERSION,
1398c2ecf20Sopenharmony_ci};
1408c2ecf20Sopenharmony_ci
1418c2ecf20Sopenharmony_ci/*
1428c2ecf20Sopenharmony_ci * Register handlers.
1438c2ecf20Sopenharmony_ci * We store the position of a register field inside a field structure,
1448c2ecf20Sopenharmony_ci * This will simplify the process of setting and reading a certain field
1458c2ecf20Sopenharmony_ci * inside the register while making sure the process remains byte order safe.
1468c2ecf20Sopenharmony_ci */
1478c2ecf20Sopenharmony_cistruct rt2x00_field8 {
1488c2ecf20Sopenharmony_ci	u8 bit_offset;
1498c2ecf20Sopenharmony_ci	u8 bit_mask;
1508c2ecf20Sopenharmony_ci};
1518c2ecf20Sopenharmony_ci
1528c2ecf20Sopenharmony_cistruct rt2x00_field16 {
1538c2ecf20Sopenharmony_ci	u16 bit_offset;
1548c2ecf20Sopenharmony_ci	u16 bit_mask;
1558c2ecf20Sopenharmony_ci};
1568c2ecf20Sopenharmony_ci
1578c2ecf20Sopenharmony_cistruct rt2x00_field32 {
1588c2ecf20Sopenharmony_ci	u32 bit_offset;
1598c2ecf20Sopenharmony_ci	u32 bit_mask;
1608c2ecf20Sopenharmony_ci};
1618c2ecf20Sopenharmony_ci
1628c2ecf20Sopenharmony_ci/*
1638c2ecf20Sopenharmony_ci * Power of two check, this will check
1648c2ecf20Sopenharmony_ci * if the mask that has been given contains and contiguous set of bits.
1658c2ecf20Sopenharmony_ci * Note that we cannot use the is_power_of_2() function since this
1668c2ecf20Sopenharmony_ci * check must be done at compile-time.
1678c2ecf20Sopenharmony_ci */
1688c2ecf20Sopenharmony_ci#define is_power_of_two(x)	( !((x) & ((x)-1)) )
1698c2ecf20Sopenharmony_ci#define low_bit_mask(x)		( ((x)-1) & ~(x) )
1708c2ecf20Sopenharmony_ci#define is_valid_mask(x)	is_power_of_two(1LU + (x) + low_bit_mask(x))
1718c2ecf20Sopenharmony_ci
1728c2ecf20Sopenharmony_ci/*
1738c2ecf20Sopenharmony_ci * Macros to find first set bit in a variable.
1748c2ecf20Sopenharmony_ci * These macros behave the same as the __ffs() functions but
1758c2ecf20Sopenharmony_ci * the most important difference that this is done during
1768c2ecf20Sopenharmony_ci * compile-time rather then run-time.
1778c2ecf20Sopenharmony_ci */
1788c2ecf20Sopenharmony_ci#define compile_ffs2(__x) \
1798c2ecf20Sopenharmony_ci	__builtin_choose_expr(((__x) & 0x1), 0, 1)
1808c2ecf20Sopenharmony_ci
1818c2ecf20Sopenharmony_ci#define compile_ffs4(__x) \
1828c2ecf20Sopenharmony_ci	__builtin_choose_expr(((__x) & 0x3), \
1838c2ecf20Sopenharmony_ci			      (compile_ffs2((__x))), \
1848c2ecf20Sopenharmony_ci			      (compile_ffs2((__x) >> 2) + 2))
1858c2ecf20Sopenharmony_ci
1868c2ecf20Sopenharmony_ci#define compile_ffs8(__x) \
1878c2ecf20Sopenharmony_ci	__builtin_choose_expr(((__x) & 0xf), \
1888c2ecf20Sopenharmony_ci			      (compile_ffs4((__x))), \
1898c2ecf20Sopenharmony_ci			      (compile_ffs4((__x) >> 4) + 4))
1908c2ecf20Sopenharmony_ci
1918c2ecf20Sopenharmony_ci#define compile_ffs16(__x) \
1928c2ecf20Sopenharmony_ci	__builtin_choose_expr(((__x) & 0xff), \
1938c2ecf20Sopenharmony_ci			      (compile_ffs8((__x))), \
1948c2ecf20Sopenharmony_ci			      (compile_ffs8((__x) >> 8) + 8))
1958c2ecf20Sopenharmony_ci
1968c2ecf20Sopenharmony_ci#define compile_ffs32(__x) \
1978c2ecf20Sopenharmony_ci	__builtin_choose_expr(((__x) & 0xffff), \
1988c2ecf20Sopenharmony_ci			      (compile_ffs16((__x))), \
1998c2ecf20Sopenharmony_ci			      (compile_ffs16((__x) >> 16) + 16))
2008c2ecf20Sopenharmony_ci
2018c2ecf20Sopenharmony_ci/*
2028c2ecf20Sopenharmony_ci * This macro will check the requirements for the FIELD{8,16,32} macros
2038c2ecf20Sopenharmony_ci * The mask should be a constant non-zero contiguous set of bits which
2048c2ecf20Sopenharmony_ci * does not exceed the given typelimit.
2058c2ecf20Sopenharmony_ci */
2068c2ecf20Sopenharmony_ci#define FIELD_CHECK(__mask, __type)			\
2078c2ecf20Sopenharmony_ci	BUILD_BUG_ON(!(__mask) ||			\
2088c2ecf20Sopenharmony_ci		     !is_valid_mask(__mask) ||		\
2098c2ecf20Sopenharmony_ci		     (__mask) != (__type)(__mask))	\
2108c2ecf20Sopenharmony_ci
2118c2ecf20Sopenharmony_ci#define FIELD8(__mask)				\
2128c2ecf20Sopenharmony_ci({						\
2138c2ecf20Sopenharmony_ci	FIELD_CHECK(__mask, u8);		\
2148c2ecf20Sopenharmony_ci	(struct rt2x00_field8) {		\
2158c2ecf20Sopenharmony_ci		compile_ffs8(__mask), (__mask)	\
2168c2ecf20Sopenharmony_ci	};					\
2178c2ecf20Sopenharmony_ci})
2188c2ecf20Sopenharmony_ci
2198c2ecf20Sopenharmony_ci#define FIELD16(__mask)				\
2208c2ecf20Sopenharmony_ci({						\
2218c2ecf20Sopenharmony_ci	FIELD_CHECK(__mask, u16);		\
2228c2ecf20Sopenharmony_ci	(struct rt2x00_field16) {		\
2238c2ecf20Sopenharmony_ci		compile_ffs16(__mask), (__mask)	\
2248c2ecf20Sopenharmony_ci	};					\
2258c2ecf20Sopenharmony_ci})
2268c2ecf20Sopenharmony_ci
2278c2ecf20Sopenharmony_ci#define FIELD32(__mask)				\
2288c2ecf20Sopenharmony_ci({						\
2298c2ecf20Sopenharmony_ci	FIELD_CHECK(__mask, u32);		\
2308c2ecf20Sopenharmony_ci	(struct rt2x00_field32) {		\
2318c2ecf20Sopenharmony_ci		compile_ffs32(__mask), (__mask)	\
2328c2ecf20Sopenharmony_ci	};					\
2338c2ecf20Sopenharmony_ci})
2348c2ecf20Sopenharmony_ci
2358c2ecf20Sopenharmony_ci#define SET_FIELD(__reg, __type, __field, __value)\
2368c2ecf20Sopenharmony_ci({						\
2378c2ecf20Sopenharmony_ci	typecheck(__type, __field);		\
2388c2ecf20Sopenharmony_ci	*(__reg) &= ~((__field).bit_mask);	\
2398c2ecf20Sopenharmony_ci	*(__reg) |= ((__value) <<		\
2408c2ecf20Sopenharmony_ci	    ((__field).bit_offset)) &		\
2418c2ecf20Sopenharmony_ci	    ((__field).bit_mask);		\
2428c2ecf20Sopenharmony_ci})
2438c2ecf20Sopenharmony_ci
2448c2ecf20Sopenharmony_ci#define GET_FIELD(__reg, __type, __field)	\
2458c2ecf20Sopenharmony_ci({						\
2468c2ecf20Sopenharmony_ci	typecheck(__type, __field);		\
2478c2ecf20Sopenharmony_ci	((__reg) & ((__field).bit_mask)) >>	\
2488c2ecf20Sopenharmony_ci	    ((__field).bit_offset);		\
2498c2ecf20Sopenharmony_ci})
2508c2ecf20Sopenharmony_ci
2518c2ecf20Sopenharmony_ci#define rt2x00_set_field32(__reg, __field, __value) \
2528c2ecf20Sopenharmony_ci	SET_FIELD(__reg, struct rt2x00_field32, __field, __value)
2538c2ecf20Sopenharmony_ci#define rt2x00_get_field32(__reg, __field) \
2548c2ecf20Sopenharmony_ci	GET_FIELD(__reg, struct rt2x00_field32, __field)
2558c2ecf20Sopenharmony_ci
2568c2ecf20Sopenharmony_ci#define rt2x00_set_field16(__reg, __field, __value) \
2578c2ecf20Sopenharmony_ci	SET_FIELD(__reg, struct rt2x00_field16, __field, __value)
2588c2ecf20Sopenharmony_ci#define rt2x00_get_field16(__reg, __field) \
2598c2ecf20Sopenharmony_ci	GET_FIELD(__reg, struct rt2x00_field16, __field)
2608c2ecf20Sopenharmony_ci
2618c2ecf20Sopenharmony_ci#define rt2x00_set_field8(__reg, __field, __value) \
2628c2ecf20Sopenharmony_ci	SET_FIELD(__reg, struct rt2x00_field8, __field, __value)
2638c2ecf20Sopenharmony_ci#define rt2x00_get_field8(__reg, __field) \
2648c2ecf20Sopenharmony_ci	GET_FIELD(__reg, struct rt2x00_field8, __field)
2658c2ecf20Sopenharmony_ci
2668c2ecf20Sopenharmony_ci#endif /* RT2X00REG_H */
267