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 */
19
20 #ifndef IF_RTWNREG_H
21 #define IF_RTWNREG_H
22
23 #define R92C_MIN_TX_PWR 0x00
24 #define R92C_MAX_TX_PWR 0x3f
25
26 #define R92C_H2C_NBOX 4
27
28 /* Common part of Tx descriptor (named only!). */
29 struct rtwn_tx_desc_common {
30 uint16_t pktlen;
31 uint8_t offset;
32 uint8_t flags0;
33 #define RTWN_FLAGS0_OWN 0x80
34
35 uint32_t txdw1;
36 /* NB: qsel is shared too; however, it looks better at the lower level */
37 #define RTWN_TXDW1_CIPHER_M 0x00c00000
38 #define RTWN_TXDW1_CIPHER_S 22
39 #define RTWN_TXDW1_CIPHER_NONE 0
40 #define RTWN_TXDW1_CIPHER_RC4 1
41 #define RTWN_TXDW1_CIPHER_SM4 2
42 #define RTWN_TXDW1_CIPHER_AES 3
43
44 uint32_t reserved[5];
45
46 union txdw7_shared {
47 uint16_t usb_checksum;
48 uint16_t pci_txbufsize;
49 } txdw7;
50 } __packed __attribute__((aligned(4)));
51
52 /* Common part of Rx descriptor. */
53 struct rtwn_rx_stat_common {
54 uint32_t rxdw0;
55 #define RTWN_RXDW0_PKTLEN_M 0x00003fff
56 #define RTWN_RXDW0_PKTLEN_S 0
57 #define RTWN_RXDW0_CRCERR 0x00004000
58 #define RTWN_RXDW0_ICVERR 0x00008000
59 #define RTWN_RXDW0_INFOSZ_M 0x000f0000
60 #define RTWN_RXDW0_INFOSZ_S 16
61 #define RTWN_RXDW0_CIPHER_M 0x00700000
62 #define RTWN_RXDW0_CIPHER_S 20
63 #define RTWN_RXDW0_QOS 0x00800000
64 #define RTWN_RXDW0_SHIFT_M 0x03000000
65 #define RTWN_RXDW0_SHIFT_S 24
66 #define RTWN_RXDW0_PHYST 0x04000000
67 #define RTWN_RXDW0_SWDEC 0x08000000
68 #define RTWN_RXDW0_LS 0x10000000
69 #define RTWN_RXDW0_FS 0x20000000
70 #define RTWN_RXDW0_EOR 0x40000000
71 #define RTWN_RXDW0_OWN 0x80000000
72
73 uint32_t rxdw1;
74 #define RTWN_RXDW1_AMSDU 0x00002000
75 #define RTWN_RXDW1_MC 0x40000000
76 #define RTWN_RXDW1_BC 0x80000000
77
78 uint32_t rxdw2;
79 uint32_t rxdw3;
80 #define RTWN_RXDW3_HTC 0x00000400
81 #define RTWN_RXDW3_BSSID01_FIT_M 0x00003000
82 #define RTWN_RXDW3_BSSID01_FIT_S 12
83
84 uint32_t rxdw4;
85 uint32_t tsf_low;
86 } __packed __attribute__((aligned(4)));
87
88 /* Rx descriptor for PCIe devices. */
89 struct rtwn_rx_stat_pci {
90 uint32_t rxdw0;
91 uint32_t rxdw1;
92 uint32_t rxdw2;
93 uint32_t rxdw3;
94 uint32_t rxdw4;
95 uint32_t tsf_low;
96
97 uint32_t rxbufaddr;
98 uint32_t rxbufaddr64;
99 } __packed __attribute__((aligned(4)));
100
101 /*
102 * Macros to access subfields in registers.
103 */
104 /* Mask and Shift (getter). */
105 #define MS(val, field) \
106 (((val) & field##_M) >> field##_S)
107
108 /* Shift and Mask (setter). */
109 #define SM(field, val) \
110 (((val) << field##_S) & field##_M)
111
112 /* Rewrite. */
113 #define RW(var, field, val) \
114 (((var) & ~field##_M) | SM(field, val))
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 /* XXX move to net80211. */
156 static __inline int
rtwn_chan2centieee(const struct ieee80211_channel * c)157 rtwn_chan2centieee(const struct ieee80211_channel *c)
158 {
159 int chan;
160
161 chan = c->ic_ieee;
162 if (c->ic_extieee != 0)
163 chan = (chan + c->ic_extieee) / 2;
164
165 return (chan);
166 }
167
168 #endif /* IF_RTWNREG_H */
169