xref: /freebsd/sys/dev/rtwn/if_rtwnreg.h (revision b9f654b163bce26de79705e77b872427c9f2afa1)
1 /*-
2  * Copyright (c) 2010 Damien Bergamini <damien.bergamini@free.fr>
3  * Copyright (c) 2016 Andriy Voskoboinyk <avos@FreeBSD.org>
4  *
5  * Permission to use, copy, modify, and distribute this software for any
6  * purpose with or without fee is hereby granted, provided that the above
7  * copyright notice and this permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16  *
17  * $OpenBSD: if_urtwnreg.h,v 1.3 2010/11/16 18:02:59 damien Exp $
18  * $FreeBSD$
19  */
20 
21 #ifndef IF_RTWNREG_H
22 #define IF_RTWNREG_H
23 
24 #define R92C_MIN_TX_PWR		0x00
25 #define R92C_MAX_TX_PWR		0x3f
26 
27 #define R92C_H2C_NBOX		4
28 
29 
30 /* Common part of Tx descriptor (named only!). */
31 struct rtwn_tx_desc_common {
32 	uint16_t	pktlen;
33 	uint8_t		offset;
34 	uint8_t		flags0;
35 #define RTWN_FLAGS0_OWN	0x80
36 
37 	uint32_t	txdw1;
38 /* NB: qsel is shared too; however, it looks better at the lower level */
39 #define RTWN_TXDW1_CIPHER_M	0x00c00000
40 #define RTWN_TXDW1_CIPHER_S	22
41 #define RTWN_TXDW1_CIPHER_NONE	0
42 #define RTWN_TXDW1_CIPHER_RC4	1
43 #define RTWN_TXDW1_CIPHER_SM4	2
44 #define RTWN_TXDW1_CIPHER_AES	3
45 
46 	uint32_t	reserved[5];
47 
48 	union txdw7_shared {
49 		uint16_t	usb_checksum;
50 		uint16_t	pci_txbufsize;
51 	} txdw7;
52 } __packed __attribute__((aligned(4)));
53 
54 /* Common part of Rx descriptor. */
55 struct rtwn_rx_stat_common {
56 	uint32_t	rxdw0;
57 #define RTWN_RXDW0_PKTLEN_M	0x00003fff
58 #define RTWN_RXDW0_PKTLEN_S	0
59 #define RTWN_RXDW0_CRCERR	0x00004000
60 #define RTWN_RXDW0_ICVERR	0x00008000
61 #define RTWN_RXDW0_INFOSZ_M	0x000f0000
62 #define RTWN_RXDW0_INFOSZ_S	16
63 #define RTWN_RXDW0_CIPHER_M	0x00700000
64 #define RTWN_RXDW0_CIPHER_S	20
65 #define RTWN_RXDW0_QOS		0x00800000
66 #define RTWN_RXDW0_SHIFT_M	0x03000000
67 #define RTWN_RXDW0_SHIFT_S	24
68 #define RTWN_RXDW0_PHYST	0x04000000
69 #define RTWN_RXDW0_SWDEC	0x08000000
70 #define RTWN_RXDW0_LS		0x10000000
71 #define RTWN_RXDW0_FS		0x20000000
72 #define RTWN_RXDW0_EOR		0x40000000
73 #define RTWN_RXDW0_OWN		0x80000000
74 
75 	uint32_t	rxdw1;
76 #define RTWN_RXDW1_AMSDU	0x00002000
77 #define RTWN_RXDW1_MC		0x40000000
78 #define RTWN_RXDW1_BC		0x80000000
79 
80 	uint32_t	rxdw2;
81 	uint32_t	rxdw3;
82 #define RTWN_RXDW3_HTC		0x00000400
83 #define RTWN_RXDW3_BSSID01_FIT_M 0x00003000
84 #define RTWN_RXDW3_BSSID01_FIT_S 12
85 
86 	uint32_t	rxdw4;
87 	uint32_t	tsf_low;
88 } __packed __attribute__((aligned(4)));
89 
90 /* Rx descriptor for PCIe devices. */
91 struct rtwn_rx_stat_pci {
92 	uint32_t	rxdw0;
93 	uint32_t	rxdw1;
94 	uint32_t	rxdw2;
95 	uint32_t	rxdw3;
96 	uint32_t	rxdw4;
97 	uint32_t	tsf_low;
98 
99 	uint32_t	rxbufaddr;
100 	uint32_t	rxbufaddr64;
101 } __packed __attribute__((aligned(4)));
102 
103 /*
104  * Macros to access subfields in registers.
105  */
106 /* Mask and Shift (getter). */
107 #define MS(val, field)							\
108 	(((val) & field##_M) >> field##_S)
109 
110 /* Shift and Mask (setter). */
111 #define SM(field, val)							\
112 	(((val) << field##_S) & field##_M)
113 
114 /* Rewrite. */
115 #define RW(var, field, val)						\
116 	(((var) & ~field##_M) | SM(field, val))
117 
118 
119 #define RTWN_MAX_CONDITIONS	3
120 
121 /*
122  * Structure for MAC initialization values.
123  */
124 struct rtwn_mac_prog {
125 	uint16_t	reg;
126 	uint8_t		val;
127 };
128 
129 /*
130  * Structure for baseband initialization values.
131  */
132 struct rtwn_bb_prog {
133 	int		count;
134 	const uint16_t	*reg;
135 	const uint32_t	*val;
136 	const uint8_t	cond[RTWN_MAX_CONDITIONS];
137 	const struct rtwn_bb_prog *next;
138 };
139 
140 struct rtwn_agc_prog {
141 	int		count;
142 	const uint32_t	*val;
143 	const uint8_t	cond[RTWN_MAX_CONDITIONS];
144 	const struct rtwn_agc_prog *next;
145 };
146 
147 /*
148  * Structure for RF initialization values.
149  */
150 struct rtwn_rf_prog {
151 	int		count;
152 	const uint8_t	*reg;
153 	const uint32_t	*val;
154 	const uint8_t	cond[RTWN_MAX_CONDITIONS];
155 	const struct rtwn_rf_prog *next;
156 };
157 
158 
159 /* XXX move to net80211. */
160 static __inline int
161 rtwn_chan2centieee(const struct ieee80211_channel *c)
162 {
163 	int chan;
164 
165 	chan = c->ic_ieee;
166 	if (c->ic_extieee != 0)
167 		chan = (chan + c->ic_extieee) / 2;
168 
169 	return (chan);
170 }
171 
172 #endif	/* IF_RTWNREG_H */
173