xref: /freebsd/sys/dev/rtwn/if_rtwnreg.h (revision 683b025adebfc2bb0d488c1d8d89e14379045ccc)
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 #define R92C_MIN_TX_PWR		0x00
22 #define R92C_MAX_TX_PWR		0x3f
23 
24 #define R92C_H2C_NBOX		4
25 
26 
27 /* Common part of Tx descriptor (named only!). */
28 struct rtwn_tx_desc_common {
29 	uint16_t	pktlen;
30 	uint8_t		offset;
31 	uint8_t		flags0;
32 #define RTWN_FLAGS0_OWN	0x80
33 
34 	uint32_t	txdw1;
35 /* NB: qsel is shared too; however, it looks better at the lower level */
36 #define RTWN_TXDW1_CIPHER_M	0x00c00000
37 #define RTWN_TXDW1_CIPHER_S	22
38 #define RTWN_TXDW1_CIPHER_NONE	0
39 #define RTWN_TXDW1_CIPHER_RC4	1
40 #define RTWN_TXDW1_CIPHER_SM4	2
41 #define RTWN_TXDW1_CIPHER_AES	3
42 
43 	uint32_t	reserved[5];
44 
45 	union txdw7_shared {
46 		uint16_t	usb_checksum;
47 		uint16_t	pci_txbufsize;
48 	} txdw7;
49 } __packed __attribute__((aligned(4)));
50 
51 /* Common part of Rx descriptor. */
52 struct rtwn_rx_stat_common {
53 	uint32_t	rxdw0;
54 #define RTWN_RXDW0_PKTLEN_M	0x00003fff
55 #define RTWN_RXDW0_PKTLEN_S	0
56 #define RTWN_RXDW0_CRCERR	0x00004000
57 #define RTWN_RXDW0_ICVERR	0x00008000
58 #define RTWN_RXDW0_INFOSZ_M	0x000f0000
59 #define RTWN_RXDW0_INFOSZ_S	16
60 #define RTWN_RXDW0_CIPHER_M	0x00700000
61 #define RTWN_RXDW0_CIPHER_S	20
62 #define RTWN_RXDW0_QOS		0x00800000
63 #define RTWN_RXDW0_SHIFT_M	0x03000000
64 #define RTWN_RXDW0_SHIFT_S	24
65 #define RTWN_RXDW0_PHYST	0x04000000
66 #define RTWN_RXDW0_SWDEC	0x08000000
67 #define RTWN_RXDW0_LS		0x10000000
68 #define RTWN_RXDW0_FS		0x20000000
69 #define RTWN_RXDW0_EOR		0x40000000
70 #define RTWN_RXDW0_OWN		0x80000000
71 
72 	uint32_t	rxdw1;
73 #define RTWN_RXDW1_AMSDU	0x00002000
74 #define RTWN_RXDW1_MC		0x40000000
75 #define RTWN_RXDW1_BC		0x80000000
76 
77 	uint32_t	rxdw2;
78 	uint32_t	rxdw3;
79 #define RTWN_RXDW3_HTC		0x00000400
80 #define RTWN_RXDW3_BSSID01_FIT_M 0x00003000
81 #define RTWN_RXDW3_BSSID01_FIT_S 12
82 
83 	uint32_t	rxdw4;
84 	uint32_t	tsf_low;
85 } __packed __attribute__((aligned(4)));
86 
87 /* Rx descriptor for PCIe devices. */
88 struct rtwn_rx_stat_pci {
89 	uint32_t	rxdw0;
90 	uint32_t	rxdw1;
91 	uint32_t	rxdw2;
92 	uint32_t	rxdw3;
93 	uint32_t	rxdw4;
94 	uint32_t	tsf_low;
95 
96 	uint32_t	rxbufaddr;
97 	uint32_t	rxbufaddr64;
98 } __packed __attribute__((aligned(4)));
99 
100 /*
101  * Macros to access subfields in registers.
102  */
103 /* Mask and Shift (getter). */
104 #define MS(val, field)							\
105 	(((val) & field##_M) >> field##_S)
106 
107 /* Shift and Mask (setter). */
108 #define SM(field, val)							\
109 	(((val) << field##_S) & field##_M)
110 
111 /* Rewrite. */
112 #define RW(var, field, val)						\
113 	(((var) & ~field##_M) | SM(field, val))
114 
115 
116 #define RTWN_MAX_CONDITIONS	3
117 
118 /*
119  * Structure for MAC initialization values.
120  */
121 struct rtwn_mac_prog {
122 	uint16_t	reg;
123 	uint8_t		val;
124 };
125 
126 /*
127  * Structure for baseband initialization values.
128  */
129 struct rtwn_bb_prog {
130 	int		count;
131 	const uint16_t	*reg;
132 	const uint32_t	*val;
133 	const uint8_t	cond[RTWN_MAX_CONDITIONS];
134 	const struct rtwn_bb_prog *next;
135 };
136 
137 struct rtwn_agc_prog {
138 	int		count;
139 	const uint32_t	*val;
140 	const uint8_t	cond[RTWN_MAX_CONDITIONS];
141 	const struct rtwn_agc_prog *next;
142 };
143 
144 /*
145  * Structure for RF initialization values.
146  */
147 struct rtwn_rf_prog {
148 	int		count;
149 	const uint8_t	*reg;
150 	const uint32_t	*val;
151 	const uint8_t	cond[RTWN_MAX_CONDITIONS];
152 	const struct rtwn_rf_prog *next;
153 };
154 
155 
156 /* XXX move to net80211. */
157 static __inline int
158 rtwn_chan2centieee(const struct ieee80211_channel *c)
159 {
160 	int chan;
161 
162 	chan = c->ic_ieee;
163 	if (c->ic_extieee != 0)
164 		chan = (chan + c->ic_extieee) / 2;
165 
166 	return (chan);
167 }
168