xref: /freebsd/sys/dev/ral/rt2661reg.h (revision 71625ec9ad2a9bc8c09784fbd23b759830e0ee5f)
19c6307b1SDamien Bergamini 
29c6307b1SDamien Bergamini /*-
39c6307b1SDamien Bergamini  * Copyright (c) 2006
49c6307b1SDamien Bergamini  *	Damien Bergamini <damien.bergamini@free.fr>
59c6307b1SDamien Bergamini  *
69c6307b1SDamien Bergamini  * Permission to use, copy, modify, and distribute this software for any
79c6307b1SDamien Bergamini  * purpose with or without fee is hereby granted, provided that the above
89c6307b1SDamien Bergamini  * copyright notice and this permission notice appear in all copies.
99c6307b1SDamien Bergamini  *
109c6307b1SDamien Bergamini  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
119c6307b1SDamien Bergamini  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
129c6307b1SDamien Bergamini  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
139c6307b1SDamien Bergamini  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
149c6307b1SDamien Bergamini  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
159c6307b1SDamien Bergamini  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
169c6307b1SDamien Bergamini  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
179c6307b1SDamien Bergamini  */
189c6307b1SDamien Bergamini 
1968e8e04eSSam Leffler #define RT2661_NOISE_FLOOR	-95
2068e8e04eSSam Leffler 
219c6307b1SDamien Bergamini #define RT2661_TX_RING_COUNT	32
229c6307b1SDamien Bergamini #define RT2661_MGT_RING_COUNT	32
239c6307b1SDamien Bergamini #define RT2661_RX_RING_COUNT	64
249c6307b1SDamien Bergamini 
259c6307b1SDamien Bergamini #define RT2661_TX_DESC_SIZE	(sizeof (struct rt2661_tx_desc))
269c6307b1SDamien Bergamini #define RT2661_TX_DESC_WSIZE	(RT2661_TX_DESC_SIZE / 4)
279c6307b1SDamien Bergamini #define RT2661_RX_DESC_SIZE	(sizeof (struct rt2661_rx_desc))
289c6307b1SDamien Bergamini #define RT2661_RX_DESC_WSIZE	(RT2661_RX_DESC_SIZE / 4)
299c6307b1SDamien Bergamini 
309c6307b1SDamien Bergamini #define RT2661_MAX_SCATTER	5
319c6307b1SDamien Bergamini 
329c6307b1SDamien Bergamini /*
339c6307b1SDamien Bergamini  * Control and status registers.
349c6307b1SDamien Bergamini  */
359c6307b1SDamien Bergamini #define RT2661_HOST_CMD_CSR		0x0008
369c6307b1SDamien Bergamini #define RT2661_MCU_CNTL_CSR		0x000c
379c6307b1SDamien Bergamini #define RT2661_SOFT_RESET_CSR		0x0010
389c6307b1SDamien Bergamini #define RT2661_MCU_INT_SOURCE_CSR	0x0014
399c6307b1SDamien Bergamini #define RT2661_MCU_INT_MASK_CSR		0x0018
409c6307b1SDamien Bergamini #define RT2661_PCI_USEC_CSR		0x001c
419c6307b1SDamien Bergamini #define RT2661_H2M_MAILBOX_CSR		0x2100
429c6307b1SDamien Bergamini #define RT2661_M2H_CMD_DONE_CSR		0x2104
439c6307b1SDamien Bergamini #define RT2661_HW_BEACON_BASE0		0x2c00
449c6307b1SDamien Bergamini #define RT2661_MAC_CSR0			0x3000
459c6307b1SDamien Bergamini #define RT2661_MAC_CSR1			0x3004
469c6307b1SDamien Bergamini #define RT2661_MAC_CSR2			0x3008
479c6307b1SDamien Bergamini #define RT2661_MAC_CSR3			0x300c
489c6307b1SDamien Bergamini #define RT2661_MAC_CSR4			0x3010
499c6307b1SDamien Bergamini #define RT2661_MAC_CSR5			0x3014
509c6307b1SDamien Bergamini #define RT2661_MAC_CSR6			0x3018
519c6307b1SDamien Bergamini #define RT2661_MAC_CSR7			0x301c
529c6307b1SDamien Bergamini #define RT2661_MAC_CSR8			0x3020
539c6307b1SDamien Bergamini #define RT2661_MAC_CSR9			0x3024
549c6307b1SDamien Bergamini #define RT2661_MAC_CSR10		0x3028
559c6307b1SDamien Bergamini #define RT2661_MAC_CSR11		0x302c
569c6307b1SDamien Bergamini #define RT2661_MAC_CSR12		0x3030
579c6307b1SDamien Bergamini #define RT2661_MAC_CSR13		0x3034
589c6307b1SDamien Bergamini #define RT2661_MAC_CSR14		0x3038
599c6307b1SDamien Bergamini #define RT2661_MAC_CSR15		0x303c
609c6307b1SDamien Bergamini #define RT2661_TXRX_CSR0		0x3040
619c6307b1SDamien Bergamini #define RT2661_TXRX_CSR1		0x3044
629c6307b1SDamien Bergamini #define RT2661_TXRX_CSR2		0x3048
639c6307b1SDamien Bergamini #define RT2661_TXRX_CSR3		0x304c
649c6307b1SDamien Bergamini #define RT2661_TXRX_CSR4		0x3050
659c6307b1SDamien Bergamini #define RT2661_TXRX_CSR5		0x3054
669c6307b1SDamien Bergamini #define RT2661_TXRX_CSR6		0x3058
679c6307b1SDamien Bergamini #define RT2661_TXRX_CSR7		0x305c
689c6307b1SDamien Bergamini #define RT2661_TXRX_CSR8		0x3060
699c6307b1SDamien Bergamini #define RT2661_TXRX_CSR9		0x3064
709c6307b1SDamien Bergamini #define RT2661_TXRX_CSR10		0x3068
719c6307b1SDamien Bergamini #define RT2661_TXRX_CSR11		0x306c
729c6307b1SDamien Bergamini #define RT2661_TXRX_CSR12		0x3070
739c6307b1SDamien Bergamini #define RT2661_TXRX_CSR13		0x3074
749c6307b1SDamien Bergamini #define RT2661_TXRX_CSR14		0x3078
759c6307b1SDamien Bergamini #define RT2661_TXRX_CSR15		0x307c
769c6307b1SDamien Bergamini #define RT2661_PHY_CSR0			0x3080
779c6307b1SDamien Bergamini #define RT2661_PHY_CSR1			0x3084
789c6307b1SDamien Bergamini #define RT2661_PHY_CSR2			0x3088
799c6307b1SDamien Bergamini #define RT2661_PHY_CSR3			0x308c
809c6307b1SDamien Bergamini #define RT2661_PHY_CSR4			0x3090
819c6307b1SDamien Bergamini #define RT2661_PHY_CSR5			0x3094
829c6307b1SDamien Bergamini #define RT2661_PHY_CSR6			0x3098
839c6307b1SDamien Bergamini #define RT2661_PHY_CSR7			0x309c
849c6307b1SDamien Bergamini #define RT2661_SEC_CSR0			0x30a0
859c6307b1SDamien Bergamini #define RT2661_SEC_CSR1			0x30a4
869c6307b1SDamien Bergamini #define RT2661_SEC_CSR2			0x30a8
879c6307b1SDamien Bergamini #define RT2661_SEC_CSR3			0x30ac
889c6307b1SDamien Bergamini #define RT2661_SEC_CSR4			0x30b0
899c6307b1SDamien Bergamini #define RT2661_SEC_CSR5			0x30b4
909c6307b1SDamien Bergamini #define RT2661_STA_CSR0			0x30c0
919c6307b1SDamien Bergamini #define RT2661_STA_CSR1			0x30c4
929c6307b1SDamien Bergamini #define RT2661_STA_CSR2			0x30c8
939c6307b1SDamien Bergamini #define RT2661_STA_CSR3			0x30cc
949c6307b1SDamien Bergamini #define RT2661_STA_CSR4			0x30d0
959c6307b1SDamien Bergamini #define RT2661_AC0_BASE_CSR		0x3400
969c6307b1SDamien Bergamini #define RT2661_AC1_BASE_CSR		0x3404
979c6307b1SDamien Bergamini #define RT2661_AC2_BASE_CSR		0x3408
989c6307b1SDamien Bergamini #define RT2661_AC3_BASE_CSR		0x340c
999c6307b1SDamien Bergamini #define RT2661_MGT_BASE_CSR		0x3410
1009c6307b1SDamien Bergamini #define RT2661_TX_RING_CSR0		0x3418
1019c6307b1SDamien Bergamini #define RT2661_TX_RING_CSR1		0x341c
1029c6307b1SDamien Bergamini #define RT2661_AIFSN_CSR		0x3420
1039c6307b1SDamien Bergamini #define RT2661_CWMIN_CSR		0x3424
1049c6307b1SDamien Bergamini #define RT2661_CWMAX_CSR		0x3428
1059c6307b1SDamien Bergamini #define RT2661_TX_DMA_DST_CSR		0x342c
1069c6307b1SDamien Bergamini #define RT2661_TX_CNTL_CSR		0x3430
1079c6307b1SDamien Bergamini #define RT2661_LOAD_TX_RING_CSR		0x3434
1089c6307b1SDamien Bergamini #define RT2661_RX_BASE_CSR		0x3450
1099c6307b1SDamien Bergamini #define RT2661_RX_RING_CSR		0x3454
1109c6307b1SDamien Bergamini #define RT2661_RX_CNTL_CSR		0x3458
1119c6307b1SDamien Bergamini #define RT2661_PCI_CFG_CSR		0x3460
1129c6307b1SDamien Bergamini #define RT2661_INT_SOURCE_CSR		0x3468
1139c6307b1SDamien Bergamini #define RT2661_INT_MASK_CSR		0x346c
1149c6307b1SDamien Bergamini #define RT2661_E2PROM_CSR		0x3470
1159c6307b1SDamien Bergamini #define RT2661_AC_TXOP_CSR0		0x3474
1169c6307b1SDamien Bergamini #define RT2661_AC_TXOP_CSR1		0x3478
1179c6307b1SDamien Bergamini #define RT2661_TEST_MODE_CSR		0x3484
1189c6307b1SDamien Bergamini #define RT2661_IO_CNTL_CSR		0x3498
1199c6307b1SDamien Bergamini #define RT2661_MCU_CODE_BASE		0x4000
1209c6307b1SDamien Bergamini 
1219c6307b1SDamien Bergamini /* possible flags for register HOST_CMD_CSR */
1229c6307b1SDamien Bergamini #define RT2661_KICK_CMD		(1 << 7)
1239c6307b1SDamien Bergamini /* Host to MCU (8051) command identifiers */
1249c6307b1SDamien Bergamini #define RT2661_MCU_CMD_SLEEP	0x30
1259c6307b1SDamien Bergamini #define RT2661_MCU_CMD_WAKEUP	0x31
1269c6307b1SDamien Bergamini #define RT2661_MCU_SET_LED	0x50
1279c6307b1SDamien Bergamini #define RT2661_MCU_SET_RSSI_LED	0x52
1289c6307b1SDamien Bergamini 
1299c6307b1SDamien Bergamini /* possible flags for register MCU_CNTL_CSR */
1309c6307b1SDamien Bergamini #define RT2661_MCU_SEL		(1 << 0)
1319c6307b1SDamien Bergamini #define RT2661_MCU_RESET	(1 << 1)
1329c6307b1SDamien Bergamini #define RT2661_MCU_READY	(1 << 2)
1339c6307b1SDamien Bergamini 
1349c6307b1SDamien Bergamini /* possible flags for register MCU_INT_SOURCE_CSR */
1359c6307b1SDamien Bergamini #define RT2661_MCU_CMD_DONE		0xff
1369c6307b1SDamien Bergamini #define RT2661_MCU_WAKEUP		(1 << 8)
1379c6307b1SDamien Bergamini #define RT2661_MCU_BEACON_EXPIRE	(1 << 9)
1389c6307b1SDamien Bergamini 
1399c6307b1SDamien Bergamini /* possible flags for register H2M_MAILBOX_CSR */
1409c6307b1SDamien Bergamini #define RT2661_H2M_BUSY		(1 << 24)
1419c6307b1SDamien Bergamini #define RT2661_TOKEN_NO_INTR	0xff
1429c6307b1SDamien Bergamini 
1439c6307b1SDamien Bergamini /* possible flags for register MAC_CSR5 */
1449c6307b1SDamien Bergamini #define RT2661_ONE_BSSID	3
1459c6307b1SDamien Bergamini 
1469c6307b1SDamien Bergamini /* possible flags for register TXRX_CSR0 */
1479c6307b1SDamien Bergamini /* Tx filter flags are in the low 16 bits */
1489c6307b1SDamien Bergamini #define RT2661_AUTO_TX_SEQ	(1 << 15)
1499c6307b1SDamien Bergamini /* Rx filter flags are in the high 16 bits */
1509c6307b1SDamien Bergamini #define RT2661_DISABLE_RX	(1 << 16)
1519c6307b1SDamien Bergamini #define RT2661_DROP_CRC_ERROR	(1 << 17)
1529c6307b1SDamien Bergamini #define RT2661_DROP_PHY_ERROR	(1 << 18)
1539c6307b1SDamien Bergamini #define RT2661_DROP_CTL		(1 << 19)
1549c6307b1SDamien Bergamini #define RT2661_DROP_NOT_TO_ME	(1 << 20)
1559c6307b1SDamien Bergamini #define RT2661_DROP_TODS	(1 << 21)
1569c6307b1SDamien Bergamini #define RT2661_DROP_VER_ERROR	(1 << 22)
1579c6307b1SDamien Bergamini #define RT2661_DROP_MULTICAST	(1 << 23)
1589c6307b1SDamien Bergamini #define RT2661_DROP_BROADCAST	(1 << 24)
1599c6307b1SDamien Bergamini #define RT2661_DROP_ACKCTS	(1 << 25)
1609c6307b1SDamien Bergamini 
1619c6307b1SDamien Bergamini /* possible flags for register TXRX_CSR4 */
1629c6307b1SDamien Bergamini #define RT2661_SHORT_PREAMBLE	(1 << 19)
1639c6307b1SDamien Bergamini #define RT2661_MRR_ENABLED	(1 << 20)
1649c6307b1SDamien Bergamini #define RT2661_MRR_CCK_FALLBACK	(1 << 23)
1659c6307b1SDamien Bergamini 
1669c6307b1SDamien Bergamini /* possible flags for register TXRX_CSR9 */
1679c6307b1SDamien Bergamini #define RT2661_TSF_TICKING	(1 << 16)
1689c6307b1SDamien Bergamini #define RT2661_TSF_MODE(x)	(((x) & 0x3) << 17)
1699c6307b1SDamien Bergamini /* TBTT stands for Target Beacon Transmission Time */
1709c6307b1SDamien Bergamini #define RT2661_ENABLE_TBTT	(1 << 19)
1719c6307b1SDamien Bergamini #define RT2661_GENERATE_BEACON	(1 << 20)
1729c6307b1SDamien Bergamini 
1739c6307b1SDamien Bergamini /* possible flags for register PHY_CSR0 */
1749c6307b1SDamien Bergamini #define RT2661_PA_PE_2GHZ	(1 << 16)
1759c6307b1SDamien Bergamini #define RT2661_PA_PE_5GHZ	(1 << 17)
1769c6307b1SDamien Bergamini 
1779c6307b1SDamien Bergamini /* possible flags for register PHY_CSR3 */
1789c6307b1SDamien Bergamini #define RT2661_BBP_READ	(1 << 15)
1799c6307b1SDamien Bergamini #define RT2661_BBP_BUSY	(1 << 16)
1809c6307b1SDamien Bergamini 
1819c6307b1SDamien Bergamini /* possible flags for register PHY_CSR4 */
1829c6307b1SDamien Bergamini #define RT2661_RF_21BIT	(21 << 24)
183*7a22215cSEitan Adler #define RT2661_RF_BUSY	(1U << 31)
1849c6307b1SDamien Bergamini 
1859c6307b1SDamien Bergamini /* possible values for register STA_CSR4 */
1869c6307b1SDamien Bergamini #define RT2661_TX_STAT_VALID	(1 << 0)
1879c6307b1SDamien Bergamini #define RT2661_TX_RESULT(v)	(((v) >> 1) & 0x7)
1889c6307b1SDamien Bergamini #define RT2661_TX_RETRYCNT(v)	(((v) >> 4) & 0xf)
1899c6307b1SDamien Bergamini #define RT2661_TX_QID(v)	(((v) >> 8) & 0xf)
1909c6307b1SDamien Bergamini #define RT2661_TX_SUCCESS	0
1919c6307b1SDamien Bergamini #define RT2661_TX_RETRY_FAIL	6
1929c6307b1SDamien Bergamini 
1939c6307b1SDamien Bergamini /* possible flags for register TX_CNTL_CSR */
1949c6307b1SDamien Bergamini #define RT2661_KICK_MGT	(1 << 4)
1959c6307b1SDamien Bergamini 
1969c6307b1SDamien Bergamini /* possible flags for register INT_SOURCE_CSR */
1979c6307b1SDamien Bergamini #define RT2661_TX_DONE		(1 << 0)
1989c6307b1SDamien Bergamini #define RT2661_RX_DONE		(1 << 1)
1999c6307b1SDamien Bergamini #define RT2661_TX0_DMA_DONE	(1 << 16)
2009c6307b1SDamien Bergamini #define RT2661_TX1_DMA_DONE	(1 << 17)
2019c6307b1SDamien Bergamini #define RT2661_TX2_DMA_DONE	(1 << 18)
2029c6307b1SDamien Bergamini #define RT2661_TX3_DMA_DONE	(1 << 19)
2039c6307b1SDamien Bergamini #define RT2661_MGT_DONE		(1 << 20)
2049c6307b1SDamien Bergamini 
2059c6307b1SDamien Bergamini /* possible flags for register E2PROM_CSR */
2069c6307b1SDamien Bergamini #define RT2661_C	(1 << 1)
2079c6307b1SDamien Bergamini #define RT2661_S	(1 << 2)
2089c6307b1SDamien Bergamini #define RT2661_D	(1 << 3)
2099c6307b1SDamien Bergamini #define RT2661_Q	(1 << 4)
2109c6307b1SDamien Bergamini #define RT2661_93C46	(1 << 5)
2119c6307b1SDamien Bergamini 
2129c6307b1SDamien Bergamini /* Tx descriptor */
2139c6307b1SDamien Bergamini struct rt2661_tx_desc {
2149c6307b1SDamien Bergamini 	uint32_t	flags;
2159c6307b1SDamien Bergamini #define RT2661_TX_BUSY		(1 << 0)
2169c6307b1SDamien Bergamini #define RT2661_TX_VALID		(1 << 1)
2179c6307b1SDamien Bergamini #define RT2661_TX_MORE_FRAG	(1 << 2)
2189c6307b1SDamien Bergamini #define RT2661_TX_NEED_ACK	(1 << 3)
2199c6307b1SDamien Bergamini #define RT2661_TX_TIMESTAMP	(1 << 4)
2209c6307b1SDamien Bergamini #define RT2661_TX_OFDM		(1 << 5)
2219c6307b1SDamien Bergamini #define RT2661_TX_IFS		(1 << 6)
2229c6307b1SDamien Bergamini #define RT2661_TX_LONG_RETRY	(1 << 7)
2239c6307b1SDamien Bergamini #define RT2661_TX_BURST		(1 << 28)
2249c6307b1SDamien Bergamini 
2259c6307b1SDamien Bergamini 	uint16_t	wme;
2269c6307b1SDamien Bergamini #define RT2661_QID(v)		(v)
2279c6307b1SDamien Bergamini #define RT2661_AIFSN(v)		((v) << 4)
2289c6307b1SDamien Bergamini #define RT2661_LOGCWMIN(v)	((v) << 8)
2299c6307b1SDamien Bergamini #define RT2661_LOGCWMAX(v)	((v) << 12)
2309c6307b1SDamien Bergamini 
2319c6307b1SDamien Bergamini 	uint16_t	xflags;
2329c6307b1SDamien Bergamini #define RT2661_TX_HWSEQ		(1 << 12)
2339c6307b1SDamien Bergamini 
2349c6307b1SDamien Bergamini 	uint8_t		plcp_signal;
2359c6307b1SDamien Bergamini 	uint8_t		plcp_service;
2369c6307b1SDamien Bergamini #define RT2661_PLCP_LENGEXT	0x80
2379c6307b1SDamien Bergamini 
2389c6307b1SDamien Bergamini 	uint8_t		plcp_length_lo;
2399c6307b1SDamien Bergamini 	uint8_t		plcp_length_hi;
2409c6307b1SDamien Bergamini 
2419c6307b1SDamien Bergamini 	uint32_t	iv;
2429c6307b1SDamien Bergamini 	uint32_t	eiv;
2439c6307b1SDamien Bergamini 
2449c6307b1SDamien Bergamini 	uint8_t		offset;
2459c6307b1SDamien Bergamini 	uint8_t		qid;
2469c6307b1SDamien Bergamini #define RT2661_QID_MGT	13
2479c6307b1SDamien Bergamini 
2489c6307b1SDamien Bergamini 	uint8_t		txpower;
2499c6307b1SDamien Bergamini #define RT2661_DEFAULT_TXPOWER	0
2509c6307b1SDamien Bergamini 
2519c6307b1SDamien Bergamini 	uint8_t		reserved1;
2529c6307b1SDamien Bergamini 
2539c6307b1SDamien Bergamini 	uint32_t	addr[RT2661_MAX_SCATTER];
2549c6307b1SDamien Bergamini 	uint16_t	len[RT2661_MAX_SCATTER];
2559c6307b1SDamien Bergamini 
2569c6307b1SDamien Bergamini 	uint16_t	reserved2;
2579c6307b1SDamien Bergamini } __packed;
2589c6307b1SDamien Bergamini 
2599c6307b1SDamien Bergamini /* Rx descriptor */
2609c6307b1SDamien Bergamini struct rt2661_rx_desc {
2619c6307b1SDamien Bergamini 	uint32_t	flags;
2629c6307b1SDamien Bergamini #define RT2661_RX_BUSY		(1 << 0)
2639c6307b1SDamien Bergamini #define RT2661_RX_DROP		(1 << 1)
2649c6307b1SDamien Bergamini #define RT2661_RX_CRC_ERROR	(1 << 6)
2659c6307b1SDamien Bergamini #define RT2661_RX_OFDM		(1 << 7)
2669c6307b1SDamien Bergamini #define RT2661_RX_PHY_ERROR	(1 << 8)
2679c6307b1SDamien Bergamini #define RT2661_RX_CIPHER_MASK	0x00000600
2689c6307b1SDamien Bergamini 
2699c6307b1SDamien Bergamini 	uint8_t		rate;
2709c6307b1SDamien Bergamini 	uint8_t		rssi;
2719c6307b1SDamien Bergamini 	uint8_t		reserved1;
2729c6307b1SDamien Bergamini 	uint8_t		offset;
2739c6307b1SDamien Bergamini 	uint32_t	iv;
2749c6307b1SDamien Bergamini 	uint32_t	eiv;
2759c6307b1SDamien Bergamini 	uint32_t	reserved2;
2769c6307b1SDamien Bergamini 	uint32_t	physaddr;
2779c6307b1SDamien Bergamini 	uint32_t	reserved3[10];
2789c6307b1SDamien Bergamini } __packed;
2799c6307b1SDamien Bergamini 
2809c6307b1SDamien Bergamini #define RAL_RF1	0
2819c6307b1SDamien Bergamini #define RAL_RF2	2
2829c6307b1SDamien Bergamini #define RAL_RF3	1
2839c6307b1SDamien Bergamini #define RAL_RF4	3
2849c6307b1SDamien Bergamini 
2859c6307b1SDamien Bergamini /* dual-band RF */
2869c6307b1SDamien Bergamini #define RT2661_RF_5225	1
2879c6307b1SDamien Bergamini #define RT2661_RF_5325	2
2889c6307b1SDamien Bergamini /* single-band RF */
2899c6307b1SDamien Bergamini #define RT2661_RF_2527	3
2909c6307b1SDamien Bergamini #define RT2661_RF_2529	4
2919c6307b1SDamien Bergamini 
2929c6307b1SDamien Bergamini #define RT2661_RX_DESC_BACK	4
2939c6307b1SDamien Bergamini 
2949c6307b1SDamien Bergamini #define RT2661_SMART_MODE	(1 << 0)
2959c6307b1SDamien Bergamini 
2969c6307b1SDamien Bergamini #define RT2661_BBPR94_DEFAULT	6
2979c6307b1SDamien Bergamini 
2989c6307b1SDamien Bergamini #define RT2661_SHIFT_D	3
2999c6307b1SDamien Bergamini #define RT2661_SHIFT_Q	4
3009c6307b1SDamien Bergamini 
3019c6307b1SDamien Bergamini #define RT2661_EEPROM_MAC01		0x02
3029c6307b1SDamien Bergamini #define RT2661_EEPROM_MAC23		0x03
3039c6307b1SDamien Bergamini #define RT2661_EEPROM_MAC45		0x04
3049c6307b1SDamien Bergamini #define RT2661_EEPROM_ANTENNA		0x10
3059c6307b1SDamien Bergamini #define RT2661_EEPROM_CONFIG2		0x11
3069c6307b1SDamien Bergamini #define RT2661_EEPROM_BBP_BASE		0x13
3079c6307b1SDamien Bergamini #define RT2661_EEPROM_TXPOWER		0x23
3089c6307b1SDamien Bergamini #define RT2661_EEPROM_FREQ_OFFSET	0x2f
3099c6307b1SDamien Bergamini #define RT2661_EEPROM_RSSI_2GHZ_OFFSET	0x4d
3109c6307b1SDamien Bergamini #define RT2661_EEPROM_RSSI_5GHZ_OFFSET	0x4e
3119c6307b1SDamien Bergamini 
3129c6307b1SDamien Bergamini #define RT2661_EEPROM_DELAY	1	/* minimum hold time (microsecond) */
3139c6307b1SDamien Bergamini 
3149c6307b1SDamien Bergamini /*
3159c6307b1SDamien Bergamini  * control and status registers access macros
3169c6307b1SDamien Bergamini  */
3179c6307b1SDamien Bergamini #define RAL_READ(sc, reg)						\
3189c6307b1SDamien Bergamini 	bus_space_read_4((sc)->sc_st, (sc)->sc_sh, (reg))
3199c6307b1SDamien Bergamini 
3209c6307b1SDamien Bergamini #define RAL_READ_REGION_4(sc, offset, datap, count)			\
3219c6307b1SDamien Bergamini 	bus_space_read_region_4((sc)->sc_st, (sc)->sc_sh, (offset),	\
3229c6307b1SDamien Bergamini 	    (datap), (count))
3239c6307b1SDamien Bergamini 
3249c6307b1SDamien Bergamini #define RAL_WRITE(sc, reg, val)						\
3259c6307b1SDamien Bergamini 	bus_space_write_4((sc)->sc_st, (sc)->sc_sh, (reg), (val))
3269c6307b1SDamien Bergamini 
3279c6307b1SDamien Bergamini #define RAL_WRITE_REGION_1(sc, offset, datap, count)			\
3289c6307b1SDamien Bergamini 	bus_space_write_region_1((sc)->sc_st, (sc)->sc_sh, (offset),	\
3299c6307b1SDamien Bergamini 	    (datap), (count))
3309c6307b1SDamien Bergamini 
3319c6307b1SDamien Bergamini /*
3329c6307b1SDamien Bergamini  * EEPROM access macro
3339c6307b1SDamien Bergamini  */
3349c6307b1SDamien Bergamini #define RT2661_EEPROM_CTL(sc, val) do {					\
3359c6307b1SDamien Bergamini 	RAL_WRITE((sc), RT2661_E2PROM_CSR, (val));			\
3369c6307b1SDamien Bergamini 	DELAY(RT2661_EEPROM_DELAY);					\
3379c6307b1SDamien Bergamini } while (/* CONSTCOND */0)
3389c6307b1SDamien Bergamini 
3399c6307b1SDamien Bergamini /*
3409c6307b1SDamien Bergamini  * Default values for MAC registers; values taken from the reference driver.
3419c6307b1SDamien Bergamini  */
3429c6307b1SDamien Bergamini #define RT2661_DEF_MAC					\
3439c6307b1SDamien Bergamini 	{ RT2661_TXRX_CSR0,        0x0000b032 },	\
3449c6307b1SDamien Bergamini 	{ RT2661_TXRX_CSR1,        0x9eb39eb3 },	\
3459c6307b1SDamien Bergamini 	{ RT2661_TXRX_CSR2,        0x8a8b8c8d },	\
3469c6307b1SDamien Bergamini 	{ RT2661_TXRX_CSR3,        0x00858687 },	\
3479c6307b1SDamien Bergamini 	{ RT2661_TXRX_CSR7,        0x2e31353b },	\
3489c6307b1SDamien Bergamini 	{ RT2661_TXRX_CSR8,        0x2a2a2a2c },	\
3499c6307b1SDamien Bergamini 	{ RT2661_TXRX_CSR15,       0x0000000f },	\
3509c6307b1SDamien Bergamini 	{ RT2661_MAC_CSR6,         0x00000fff },	\
3519c6307b1SDamien Bergamini 	{ RT2661_MAC_CSR8,         0x016c030a },	\
3529c6307b1SDamien Bergamini 	{ RT2661_MAC_CSR10,        0x00000718 },	\
3539c6307b1SDamien Bergamini 	{ RT2661_MAC_CSR12,        0x00000004 },	\
3549c6307b1SDamien Bergamini 	{ RT2661_MAC_CSR13,        0x0000e000 },	\
3559c6307b1SDamien Bergamini 	{ RT2661_SEC_CSR0,         0x00000000 },	\
3569c6307b1SDamien Bergamini 	{ RT2661_SEC_CSR1,         0x00000000 },	\
3579c6307b1SDamien Bergamini 	{ RT2661_SEC_CSR5,         0x00000000 },	\
3589c6307b1SDamien Bergamini 	{ RT2661_PHY_CSR1,         0x000023b0 },	\
3599c6307b1SDamien Bergamini 	{ RT2661_PHY_CSR5,         0x060a100c },	\
3609c6307b1SDamien Bergamini 	{ RT2661_PHY_CSR6,         0x00080606 },	\
3619c6307b1SDamien Bergamini 	{ RT2661_PHY_CSR7,         0x00000a08 },	\
3629c6307b1SDamien Bergamini 	{ RT2661_PCI_CFG_CSR,      0x3cca4808 },	\
3639c6307b1SDamien Bergamini 	{ RT2661_AIFSN_CSR,        0x00002273 },	\
3649c6307b1SDamien Bergamini 	{ RT2661_CWMIN_CSR,        0x00002344 },	\
3659c6307b1SDamien Bergamini 	{ RT2661_CWMAX_CSR,        0x000034aa },	\
3669c6307b1SDamien Bergamini 	{ RT2661_TEST_MODE_CSR,    0x00000200 },	\
3679c6307b1SDamien Bergamini 	{ RT2661_M2H_CMD_DONE_CSR, 0xffffffff }
3689c6307b1SDamien Bergamini 
3699c6307b1SDamien Bergamini /*
3709c6307b1SDamien Bergamini  * Default values for BBP registers; values taken from the reference driver.
3719c6307b1SDamien Bergamini  */
3729c6307b1SDamien Bergamini #define RT2661_DEF_BBP	\
3739c6307b1SDamien Bergamini 	{   3, 0x00 },	\
3749c6307b1SDamien Bergamini 	{  15, 0x30 },	\
3759c6307b1SDamien Bergamini 	{  17, 0x20 },	\
3769c6307b1SDamien Bergamini 	{  21, 0xc8 },	\
3779c6307b1SDamien Bergamini 	{  22, 0x38 },	\
3789c6307b1SDamien Bergamini 	{  23, 0x06 },	\
3799c6307b1SDamien Bergamini 	{  24, 0xfe },	\
3809c6307b1SDamien Bergamini 	{  25, 0x0a },	\
3819c6307b1SDamien Bergamini 	{  26, 0x0d },	\
3829c6307b1SDamien Bergamini 	{  34, 0x12 },	\
3839c6307b1SDamien Bergamini 	{  37, 0x07 },	\
3849c6307b1SDamien Bergamini 	{  39, 0xf8 },	\
3859c6307b1SDamien Bergamini 	{  41, 0x60 },	\
3869c6307b1SDamien Bergamini 	{  53, 0x10 },	\
3879c6307b1SDamien Bergamini 	{  54, 0x18 },	\
3889c6307b1SDamien Bergamini 	{  60, 0x10 },	\
3899c6307b1SDamien Bergamini 	{  61, 0x04 },	\
3909c6307b1SDamien Bergamini 	{  62, 0x04 },	\
3919c6307b1SDamien Bergamini 	{  75, 0xfe },	\
3929c6307b1SDamien Bergamini 	{  86, 0xfe },	\
3939c6307b1SDamien Bergamini 	{  88, 0xfe },	\
3949c6307b1SDamien Bergamini 	{  90, 0x0f },	\
3959c6307b1SDamien Bergamini 	{  99, 0x00 },	\
3969c6307b1SDamien Bergamini 	{ 102, 0x16 },	\
3979c6307b1SDamien Bergamini 	{ 107, 0x04 }
3989c6307b1SDamien Bergamini 
3999c6307b1SDamien Bergamini /*
4009c6307b1SDamien Bergamini  * Default settings for RF registers; values taken from the reference driver.
4019c6307b1SDamien Bergamini  */
4029c6307b1SDamien Bergamini #define RT2661_RF5225_1					\
4039c6307b1SDamien Bergamini 	{   1, 0x00b33, 0x011e1, 0x1a014, 0x30282 },	\
4049c6307b1SDamien Bergamini 	{   2, 0x00b33, 0x011e1, 0x1a014, 0x30287 },	\
4059c6307b1SDamien Bergamini 	{   3, 0x00b33, 0x011e2, 0x1a014, 0x30282 },	\
4069c6307b1SDamien Bergamini 	{   4, 0x00b33, 0x011e2, 0x1a014, 0x30287 },	\
4079c6307b1SDamien Bergamini 	{   5, 0x00b33, 0x011e3, 0x1a014, 0x30282 },	\
4089c6307b1SDamien Bergamini 	{   6, 0x00b33, 0x011e3, 0x1a014, 0x30287 },	\
4099c6307b1SDamien Bergamini 	{   7, 0x00b33, 0x011e4, 0x1a014, 0x30282 },	\
4109c6307b1SDamien Bergamini 	{   8, 0x00b33, 0x011e4, 0x1a014, 0x30287 },	\
4119c6307b1SDamien Bergamini 	{   9, 0x00b33, 0x011e5, 0x1a014, 0x30282 },	\
4129c6307b1SDamien Bergamini 	{  10, 0x00b33, 0x011e5, 0x1a014, 0x30287 },	\
4139c6307b1SDamien Bergamini 	{  11, 0x00b33, 0x011e6, 0x1a014, 0x30282 },	\
4149c6307b1SDamien Bergamini 	{  12, 0x00b33, 0x011e6, 0x1a014, 0x30287 },	\
4159c6307b1SDamien Bergamini 	{  13, 0x00b33, 0x011e7, 0x1a014, 0x30282 },	\
4169c6307b1SDamien Bergamini 	{  14, 0x00b33, 0x011e8, 0x1a014, 0x30284 },	\
4179c6307b1SDamien Bergamini 							\
4189c6307b1SDamien Bergamini 	{  36, 0x00b33, 0x01266, 0x26014, 0x30288 },	\
4199c6307b1SDamien Bergamini 	{  40, 0x00b33, 0x01268, 0x26014, 0x30280 },	\
4209c6307b1SDamien Bergamini 	{  44, 0x00b33, 0x01269, 0x26014, 0x30282 },	\
4219c6307b1SDamien Bergamini 	{  48, 0x00b33, 0x0126a, 0x26014, 0x30284 },	\
4229c6307b1SDamien Bergamini 	{  52, 0x00b33, 0x0126b, 0x26014, 0x30286 },	\
4239c6307b1SDamien Bergamini 	{  56, 0x00b33, 0x0126c, 0x26014, 0x30288 },	\
4249c6307b1SDamien Bergamini 	{  60, 0x00b33, 0x0126e, 0x26014, 0x30280 },	\
4259c6307b1SDamien Bergamini 	{  64, 0x00b33, 0x0126f, 0x26014, 0x30282 },	\
4269c6307b1SDamien Bergamini 							\
4279c6307b1SDamien Bergamini 	{ 100, 0x00b33, 0x0128a, 0x2e014, 0x30280 },	\
4289c6307b1SDamien Bergamini 	{ 104, 0x00b33, 0x0128b, 0x2e014, 0x30282 },	\
4299c6307b1SDamien Bergamini 	{ 108, 0x00b33, 0x0128c, 0x2e014, 0x30284 },	\
4309c6307b1SDamien Bergamini 	{ 112, 0x00b33, 0x0128d, 0x2e014, 0x30286 },	\
4319c6307b1SDamien Bergamini 	{ 116, 0x00b33, 0x0128e, 0x2e014, 0x30288 },	\
4329c6307b1SDamien Bergamini 	{ 120, 0x00b33, 0x012a0, 0x2e014, 0x30280 },	\
4339c6307b1SDamien Bergamini 	{ 124, 0x00b33, 0x012a1, 0x2e014, 0x30282 },	\
4349c6307b1SDamien Bergamini 	{ 128, 0x00b33, 0x012a2, 0x2e014, 0x30284 },	\
4359c6307b1SDamien Bergamini 	{ 132, 0x00b33, 0x012a3, 0x2e014, 0x30286 },	\
4369c6307b1SDamien Bergamini 	{ 136, 0x00b33, 0x012a4, 0x2e014, 0x30288 },	\
4379c6307b1SDamien Bergamini 	{ 140, 0x00b33, 0x012a6, 0x2e014, 0x30280 },	\
4389c6307b1SDamien Bergamini 							\
4399c6307b1SDamien Bergamini 	{ 149, 0x00b33, 0x012a8, 0x2e014, 0x30287 },	\
4409c6307b1SDamien Bergamini 	{ 153, 0x00b33, 0x012a9, 0x2e014, 0x30289 },	\
4419c6307b1SDamien Bergamini 	{ 157, 0x00b33, 0x012ab, 0x2e014, 0x30281 },	\
4429c6307b1SDamien Bergamini 	{ 161, 0x00b33, 0x012ac, 0x2e014, 0x30283 },	\
4439c6307b1SDamien Bergamini 	{ 165, 0x00b33, 0x012ad, 0x2e014, 0x30285 }
4449c6307b1SDamien Bergamini 
4459c6307b1SDamien Bergamini #define RT2661_RF5225_2					\
4469c6307b1SDamien Bergamini 	{   1, 0x00b33, 0x011e1, 0x1a014, 0x30282 },	\
4479c6307b1SDamien Bergamini 	{   2, 0x00b33, 0x011e1, 0x1a014, 0x30287 },	\
4489c6307b1SDamien Bergamini 	{   3, 0x00b33, 0x011e2, 0x1a014, 0x30282 },	\
4499c6307b1SDamien Bergamini 	{   4, 0x00b33, 0x011e2, 0x1a014, 0x30287 },	\
4509c6307b1SDamien Bergamini 	{   5, 0x00b33, 0x011e3, 0x1a014, 0x30282 },	\
4519c6307b1SDamien Bergamini 	{   6, 0x00b33, 0x011e3, 0x1a014, 0x30287 },	\
4529c6307b1SDamien Bergamini 	{   7, 0x00b33, 0x011e4, 0x1a014, 0x30282 },	\
4539c6307b1SDamien Bergamini 	{   8, 0x00b33, 0x011e4, 0x1a014, 0x30287 },	\
4549c6307b1SDamien Bergamini 	{   9, 0x00b33, 0x011e5, 0x1a014, 0x30282 },	\
4559c6307b1SDamien Bergamini 	{  10, 0x00b33, 0x011e5, 0x1a014, 0x30287 },	\
4569c6307b1SDamien Bergamini 	{  11, 0x00b33, 0x011e6, 0x1a014, 0x30282 },	\
4579c6307b1SDamien Bergamini 	{  12, 0x00b33, 0x011e6, 0x1a014, 0x30287 },	\
4589c6307b1SDamien Bergamini 	{  13, 0x00b33, 0x011e7, 0x1a014, 0x30282 },	\
4599c6307b1SDamien Bergamini 	{  14, 0x00b33, 0x011e8, 0x1a014, 0x30284 },	\
4609c6307b1SDamien Bergamini 							\
4619c6307b1SDamien Bergamini 	{  36, 0x00b35, 0x11206, 0x26014, 0x30280 },	\
4629c6307b1SDamien Bergamini 	{  40, 0x00b34, 0x111a0, 0x26014, 0x30280 },	\
4639c6307b1SDamien Bergamini 	{  44, 0x00b34, 0x111a1, 0x26014, 0x30286 },	\
4649c6307b1SDamien Bergamini 	{  48, 0x00b34, 0x111a3, 0x26014, 0x30282 },	\
4659c6307b1SDamien Bergamini 	{  52, 0x00b34, 0x111a4, 0x26014, 0x30288 },	\
4669c6307b1SDamien Bergamini 	{  56, 0x00b34, 0x111a6, 0x26014, 0x30284 },	\
4679c6307b1SDamien Bergamini 	{  60, 0x00b34, 0x111a8, 0x26014, 0x30280 },	\
4689c6307b1SDamien Bergamini 	{  64, 0x00b34, 0x111a9, 0x26014, 0x30286 },	\
4699c6307b1SDamien Bergamini 							\
4709c6307b1SDamien Bergamini 	{ 100, 0x00b35, 0x11226, 0x2e014, 0x30280 },	\
4719c6307b1SDamien Bergamini 	{ 104, 0x00b35, 0x11228, 0x2e014, 0x30280 },	\
4729c6307b1SDamien Bergamini 	{ 108, 0x00b35, 0x1122a, 0x2e014, 0x30280 },	\
4739c6307b1SDamien Bergamini 	{ 112, 0x00b35, 0x1122c, 0x2e014, 0x30280 },	\
4749c6307b1SDamien Bergamini 	{ 116, 0x00b35, 0x1122e, 0x2e014, 0x30280 },	\
4759c6307b1SDamien Bergamini 	{ 120, 0x00b34, 0x111c0, 0x2e014, 0x30280 },	\
4769c6307b1SDamien Bergamini 	{ 124, 0x00b34, 0x111c1, 0x2e014, 0x30286 },	\
4779c6307b1SDamien Bergamini 	{ 128, 0x00b34, 0x111c3, 0x2e014, 0x30282 },	\
4789c6307b1SDamien Bergamini 	{ 132, 0x00b34, 0x111c4, 0x2e014, 0x30288 },	\
4799c6307b1SDamien Bergamini 	{ 136, 0x00b34, 0x111c6, 0x2e014, 0x30284 },	\
4809c6307b1SDamien Bergamini 	{ 140, 0x00b34, 0x111c8, 0x2e014, 0x30280 },	\
4819c6307b1SDamien Bergamini 							\
4829c6307b1SDamien Bergamini 	{ 149, 0x00b34, 0x111cb, 0x2e014, 0x30286 },	\
4839c6307b1SDamien Bergamini 	{ 153, 0x00b34, 0x111cd, 0x2e014, 0x30282 },	\
4849c6307b1SDamien Bergamini 	{ 157, 0x00b35, 0x11242, 0x2e014, 0x30285 },	\
4859c6307b1SDamien Bergamini 	{ 161, 0x00b35, 0x11244, 0x2e014, 0x30285 },	\
4869c6307b1SDamien Bergamini 	{ 165, 0x00b35, 0x11246, 0x2e014, 0x30285 }
487