arn5008.c revision 1.2 1 1.2 christos /* $NetBSD: arn5008.c,v 1.2 2013/04/03 14:20:02 christos Exp $ */
2 1.1 christos /* $OpenBSD: ar5008.c,v 1.21 2012/08/25 12:14:31 kettenis Exp $ */
3 1.1 christos
4 1.1 christos /*-
5 1.1 christos * Copyright (c) 2009 Damien Bergamini <damien.bergamini (at) free.fr>
6 1.1 christos * Copyright (c) 2008-2009 Atheros Communications Inc.
7 1.1 christos *
8 1.1 christos * Permission to use, copy, modify, and/or distribute this software for any
9 1.1 christos * purpose with or without fee is hereby granted, provided that the above
10 1.1 christos * copyright notice and this permission notice appear in all copies.
11 1.1 christos *
12 1.1 christos * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13 1.1 christos * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14 1.1 christos * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15 1.1 christos * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16 1.1 christos * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17 1.1 christos * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18 1.1 christos * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 1.1 christos */
20 1.1 christos
21 1.1 christos /*
22 1.1 christos * Driver for Atheros 802.11a/g/n chipsets.
23 1.1 christos * Routines common to AR5008, AR9001 and AR9002 families.
24 1.1 christos */
25 1.1 christos
26 1.1 christos #include <sys/cdefs.h>
27 1.2 christos __KERNEL_RCSID(0, "$NetBSD: arn5008.c,v 1.2 2013/04/03 14:20:02 christos Exp $");
28 1.1 christos
29 1.1 christos #include <sys/param.h>
30 1.1 christos #include <sys/sockio.h>
31 1.1 christos #include <sys/mbuf.h>
32 1.1 christos #include <sys/kernel.h>
33 1.1 christos #include <sys/socket.h>
34 1.1 christos #include <sys/systm.h>
35 1.1 christos #include <sys/malloc.h>
36 1.1 christos #include <sys/queue.h>
37 1.1 christos #include <sys/conf.h>
38 1.1 christos #include <sys/device.h>
39 1.1 christos
40 1.1 christos #include <sys/bus.h>
41 1.1 christos #include <sys/endian.h>
42 1.1 christos #include <sys/intr.h>
43 1.1 christos
44 1.1 christos #include <net/bpf.h>
45 1.1 christos #include <net/if.h>
46 1.1 christos #include <net/if_arp.h>
47 1.1 christos #include <net/if_dl.h>
48 1.2 christos #include <net/if_ether.h>
49 1.1 christos #include <net/if_media.h>
50 1.1 christos #include <net/if_types.h>
51 1.1 christos
52 1.1 christos #include <netinet/in.h>
53 1.1 christos #include <netinet/in_systm.h>
54 1.1 christos #include <netinet/in_var.h>
55 1.1 christos #include <netinet/ip.h>
56 1.1 christos
57 1.1 christos #include <net80211/ieee80211_var.h>
58 1.1 christos #include <net80211/ieee80211_amrr.h>
59 1.1 christos #include <net80211/ieee80211_radiotap.h>
60 1.1 christos
61 1.1 christos #include <dev/ic/athnreg.h>
62 1.1 christos #include <dev/ic/athnvar.h>
63 1.1 christos
64 1.1 christos #include <dev/ic/arn5008reg.h>
65 1.1 christos #include <dev/ic/arn5008.h>
66 1.1 christos #include <dev/ic/arn5416.h>
67 1.1 christos #include <dev/ic/arn9280.h>
68 1.1 christos
69 1.1 christos #define Static static
70 1.1 christos
71 1.1 christos Static void ar5008_calib_adc_dc_off(struct athn_softc *);
72 1.1 christos Static void ar5008_calib_adc_gain(struct athn_softc *);
73 1.1 christos Static void ar5008_calib_iq(struct athn_softc *);
74 1.1 christos Static void ar5008_disable_ofdm_weak_signal(struct athn_softc *);
75 1.1 christos Static void ar5008_disable_phy(struct athn_softc *);
76 1.1 christos Static int ar5008_dma_alloc(struct athn_softc *);
77 1.1 christos Static void ar5008_dma_free(struct athn_softc *);
78 1.1 christos Static void ar5008_do_calib(struct athn_softc *);
79 1.1 christos Static void ar5008_do_noisefloor_calib(struct athn_softc *);
80 1.1 christos Static void ar5008_enable_antenna_diversity(struct athn_softc *);
81 1.1 christos Static void ar5008_enable_ofdm_weak_signal(struct athn_softc *);
82 1.1 christos Static uint8_t ar5008_get_vpd(uint8_t, const uint8_t *, const uint8_t *, int);
83 1.1 christos Static void ar5008_gpio_config_input(struct athn_softc *, int);
84 1.1 christos Static void ar5008_gpio_config_output(struct athn_softc *, int, int);
85 1.1 christos Static int ar5008_gpio_read(struct athn_softc *, int);
86 1.1 christos Static void ar5008_gpio_write(struct athn_softc *, int, int);
87 1.1 christos Static void ar5008_hw_init(struct athn_softc *, struct ieee80211_channel *,
88 1.1 christos struct ieee80211_channel *);
89 1.1 christos Static void ar5008_init_baseband(struct athn_softc *);
90 1.1 christos Static void ar5008_init_chains(struct athn_softc *);
91 1.1 christos Static int ar5008_intr(struct athn_softc *);
92 1.1 christos Static void ar5008_next_calib(struct athn_softc *);
93 1.1 christos Static int ar5008_read_eep_word(struct athn_softc *, uint32_t,
94 1.1 christos uint16_t *);
95 1.1 christos Static int ar5008_read_rom(struct athn_softc *);
96 1.1 christos Static void ar5008_rf_bus_release(struct athn_softc *);
97 1.1 christos Static int ar5008_rf_bus_request(struct athn_softc *);
98 1.1 christos Static void ar5008_rfsilent_init(struct athn_softc *);
99 1.1 christos Static int ar5008_rx_alloc(struct athn_softc *);
100 1.1 christos Static void ar5008_rx_enable(struct athn_softc *);
101 1.1 christos Static void ar5008_rx_free(struct athn_softc *);
102 1.1 christos Static void ar5008_rx_intr(struct athn_softc *);
103 1.1 christos Static void ar5008_rx_radiotap(struct athn_softc *, struct mbuf *,
104 1.1 christos struct ar_rx_desc *);
105 1.1 christos Static void ar5008_set_cck_weak_signal(struct athn_softc *, int);
106 1.1 christos Static void ar5008_set_delta_slope(struct athn_softc *,
107 1.1 christos struct ieee80211_channel *, struct ieee80211_channel *);
108 1.1 christos Static void ar5008_set_firstep_level(struct athn_softc *, int);
109 1.1 christos Static void ar5008_set_noise_immunity_level(struct athn_softc *, int);
110 1.1 christos Static void ar5008_set_phy(struct athn_softc *, struct ieee80211_channel *,
111 1.1 christos struct ieee80211_channel *);
112 1.1 christos Static void ar5008_set_rf_mode(struct athn_softc *,
113 1.1 christos struct ieee80211_channel *);
114 1.1 christos Static void ar5008_set_rxchains(struct athn_softc *);
115 1.1 christos Static void ar5008_set_spur_immunity_level(struct athn_softc *, int);
116 1.1 christos Static void ar5008_swap_rom(struct athn_softc *);
117 1.1 christos Static int ar5008_swba_intr(struct athn_softc *);
118 1.1 christos Static int ar5008_tx(struct athn_softc *, struct mbuf *,
119 1.1 christos struct ieee80211_node *, int);
120 1.1 christos Static int ar5008_tx_alloc(struct athn_softc *);
121 1.1 christos Static void ar5008_tx_free(struct athn_softc *);
122 1.1 christos Static void ar5008_tx_intr(struct athn_softc *);
123 1.1 christos Static int ar5008_tx_process(struct athn_softc *, int);
124 1.1 christos
125 1.1 christos #ifdef notused
126 1.1 christos Static void ar5008_bb_load_noisefloor(struct athn_softc *);
127 1.1 christos Static void ar5008_get_noisefloor(struct athn_softc *,
128 1.1 christos struct ieee80211_channel *);
129 1.1 christos Static void ar5008_noisefloor_calib(struct athn_softc *);
130 1.1 christos Static void ar5008_read_noisefloor(struct athn_softc *, int16_t *,
131 1.1 christos int16_t *);
132 1.1 christos Static void ar5008_write_noisefloor(struct athn_softc *, int16_t *,
133 1.1 christos int16_t *);
134 1.1 christos #endif /* notused */
135 1.1 christos
136 1.1 christos // bf->bf_m = MCLGETI(NULL, M_DONTWAIT, NULL, ATHN_RXBUFSZ);
137 1.1 christos
138 1.1 christos /*
139 1.1 christos * XXX: see if_iwn.c:MCLGETIalt() for a better solution.
140 1.1 christos */
141 1.1 christos static struct mbuf *
142 1.1 christos MCLGETI(struct athn_softc *sc __unused, int how,
143 1.1 christos struct ifnet *ifp __unused, u_int size)
144 1.1 christos {
145 1.1 christos struct mbuf *m;
146 1.1 christos
147 1.1 christos MGETHDR(m, how, MT_DATA);
148 1.1 christos if (m == NULL)
149 1.1 christos return NULL;
150 1.1 christos
151 1.1 christos MEXTMALLOC(m, size, how);
152 1.1 christos if ((m->m_flags & M_EXT) == 0) {
153 1.1 christos m_freem(m);
154 1.1 christos return NULL;
155 1.1 christos }
156 1.1 christos return m;
157 1.1 christos }
158 1.1 christos
159 1.1 christos PUBLIC int
160 1.1 christos ar5008_attach(struct athn_softc *sc)
161 1.1 christos {
162 1.1 christos struct athn_ops *ops = &sc->sc_ops;
163 1.1 christos struct ieee80211com *ic = &sc->sc_ic;
164 1.1 christos struct ar_base_eep_header *base;
165 1.1 christos uint8_t eep_ver, kc_entries_log;
166 1.1 christos int error;
167 1.1 christos
168 1.1 christos /* Set callbacks for AR5008, AR9001 and AR9002 families. */
169 1.1 christos ops->gpio_read = ar5008_gpio_read;
170 1.1 christos ops->gpio_write = ar5008_gpio_write;
171 1.1 christos ops->gpio_config_input = ar5008_gpio_config_input;
172 1.1 christos ops->gpio_config_output = ar5008_gpio_config_output;
173 1.1 christos ops->rfsilent_init = ar5008_rfsilent_init;
174 1.1 christos
175 1.1 christos ops->dma_alloc = ar5008_dma_alloc;
176 1.1 christos ops->dma_free = ar5008_dma_free;
177 1.1 christos ops->rx_enable = ar5008_rx_enable;
178 1.1 christos ops->intr = ar5008_intr;
179 1.1 christos ops->tx = ar5008_tx;
180 1.1 christos
181 1.1 christos ops->set_rf_mode = ar5008_set_rf_mode;
182 1.1 christos ops->rf_bus_request = ar5008_rf_bus_request;
183 1.1 christos ops->rf_bus_release = ar5008_rf_bus_release;
184 1.1 christos ops->set_phy = ar5008_set_phy;
185 1.1 christos ops->set_delta_slope = ar5008_set_delta_slope;
186 1.1 christos ops->enable_antenna_diversity = ar5008_enable_antenna_diversity;
187 1.1 christos ops->init_baseband = ar5008_init_baseband;
188 1.1 christos ops->disable_phy = ar5008_disable_phy;
189 1.1 christos ops->set_rxchains = ar5008_set_rxchains;
190 1.1 christos ops->noisefloor_calib = ar5008_do_noisefloor_calib;
191 1.1 christos ops->do_calib = ar5008_do_calib;
192 1.1 christos ops->next_calib = ar5008_next_calib;
193 1.1 christos ops->hw_init = ar5008_hw_init;
194 1.1 christos
195 1.1 christos ops->set_noise_immunity_level = ar5008_set_noise_immunity_level;
196 1.1 christos ops->enable_ofdm_weak_signal = ar5008_enable_ofdm_weak_signal;
197 1.1 christos ops->disable_ofdm_weak_signal = ar5008_disable_ofdm_weak_signal;
198 1.1 christos ops->set_cck_weak_signal = ar5008_set_cck_weak_signal;
199 1.1 christos ops->set_firstep_level = ar5008_set_firstep_level;
200 1.1 christos ops->set_spur_immunity_level = ar5008_set_spur_immunity_level;
201 1.1 christos
202 1.1 christos /* Set MAC registers offsets. */
203 1.1 christos sc->sc_obs_off = AR_OBS;
204 1.1 christos sc->sc_gpio_input_en_off = AR_GPIO_INPUT_EN_VAL;
205 1.1 christos
206 1.1 christos if (!(sc->sc_flags & ATHN_FLAG_PCIE))
207 1.1 christos athn_config_nonpcie(sc);
208 1.1 christos else
209 1.1 christos athn_config_pcie(sc);
210 1.1 christos
211 1.1 christos /* Read entire ROM content in memory. */
212 1.1 christos if ((error = ar5008_read_rom(sc)) != 0) {
213 1.1 christos printf("%s: could not read ROM\n", device_xname(sc->sc_dev));
214 1.1 christos return error;
215 1.1 christos }
216 1.1 christos
217 1.1 christos /* Get RF revision. */
218 1.1 christos sc->sc_rf_rev = ar5416_get_rf_rev(sc);
219 1.1 christos
220 1.1 christos base = sc->sc_eep;
221 1.1 christos eep_ver = (base->version >> 12) & 0xf;
222 1.1 christos sc->sc_eep_rev = (base->version & 0xfff);
223 1.1 christos if (eep_ver != AR_EEP_VER || sc->sc_eep_rev == 0) {
224 1.1 christos printf("%s: unsupported ROM version %d.%d\n",
225 1.1 christos device_xname(sc->sc_dev), eep_ver, sc->sc_eep_rev);
226 1.1 christos return EINVAL;
227 1.1 christos }
228 1.1 christos
229 1.1 christos if (base->opCapFlags & AR_OPFLAGS_11A)
230 1.1 christos sc->sc_flags |= ATHN_FLAG_11A;
231 1.1 christos if (base->opCapFlags & AR_OPFLAGS_11G)
232 1.1 christos sc->sc_flags |= ATHN_FLAG_11G;
233 1.1 christos if (base->opCapFlags & AR_OPFLAGS_11N)
234 1.1 christos sc->sc_flags |= ATHN_FLAG_11N;
235 1.1 christos
236 1.1 christos IEEE80211_ADDR_COPY(ic->ic_myaddr, base->macAddr);
237 1.1 christos
238 1.1 christos /* Check if we have a hardware radio switch. */
239 1.1 christos if (base->rfSilent & AR_EEP_RFSILENT_ENABLED) {
240 1.1 christos sc->sc_flags |= ATHN_FLAG_RFSILENT;
241 1.1 christos /* Get GPIO pin used by hardware radio switch. */
242 1.1 christos sc->sc_rfsilent_pin = MS(base->rfSilent,
243 1.1 christos AR_EEP_RFSILENT_GPIO_SEL);
244 1.1 christos /* Get polarity of hardware radio switch. */
245 1.1 christos if (base->rfSilent & AR_EEP_RFSILENT_POLARITY)
246 1.1 christos sc->sc_flags |= ATHN_FLAG_RFSILENT_REVERSED;
247 1.1 christos }
248 1.1 christos
249 1.1 christos /* Get the number of HW key cache entries. */
250 1.1 christos kc_entries_log = MS(base->deviceCap, AR_EEP_DEVCAP_KC_ENTRIES);
251 1.1 christos sc->sc_kc_entries = kc_entries_log != 0 ?
252 1.1 christos 1 << kc_entries_log : AR_KEYTABLE_SIZE;
253 1.1 christos
254 1.1 christos sc->sc_txchainmask = base->txMask;
255 1.1 christos if (sc->sc_mac_ver == AR_SREV_VERSION_5416_PCI &&
256 1.1 christos !(base->opCapFlags & AR_OPFLAGS_11A)) {
257 1.1 christos /* For single-band AR5416 PCI, use GPIO pin 0. */
258 1.1 christos sc->sc_rxchainmask = ar5008_gpio_read(sc, 0) ? 0x5 : 0x7;
259 1.1 christos }
260 1.1 christos else
261 1.1 christos sc->sc_rxchainmask = base->rxMask;
262 1.1 christos
263 1.1 christos ops->setup(sc);
264 1.1 christos return 0;
265 1.1 christos }
266 1.1 christos
267 1.1 christos /*
268 1.1 christos * Read 16-bit word from ROM.
269 1.1 christos */
270 1.1 christos Static int
271 1.1 christos ar5008_read_eep_word(struct athn_softc *sc, uint32_t addr, uint16_t *val)
272 1.1 christos {
273 1.1 christos uint32_t reg;
274 1.1 christos int ntries;
275 1.1 christos
276 1.1 christos reg = AR_READ(sc, AR_EEPROM_OFFSET(addr));
277 1.1 christos for (ntries = 0; ntries < 1000; ntries++) {
278 1.1 christos reg = AR_READ(sc, AR_EEPROM_STATUS_DATA);
279 1.1 christos if (!(reg & (AR_EEPROM_STATUS_DATA_BUSY |
280 1.1 christos AR_EEPROM_STATUS_DATA_PROT_ACCESS))) {
281 1.1 christos *val = MS(reg, AR_EEPROM_STATUS_DATA_VAL);
282 1.1 christos return 0;
283 1.1 christos }
284 1.1 christos DELAY(10);
285 1.1 christos }
286 1.1 christos *val = 0xffff;
287 1.1 christos return ETIMEDOUT;
288 1.1 christos }
289 1.1 christos
290 1.1 christos Static int
291 1.1 christos ar5008_read_rom(struct athn_softc *sc)
292 1.1 christos {
293 1.1 christos uint32_t addr, end;
294 1.1 christos uint16_t magic, sum, *eep;
295 1.1 christos int need_swap = 0;
296 1.1 christos int error;
297 1.1 christos
298 1.1 christos /* Determine ROM endianness. */
299 1.1 christos error = ar5008_read_eep_word(sc, AR_EEPROM_MAGIC_OFFSET, &magic);
300 1.1 christos if (error != 0)
301 1.1 christos return error;
302 1.1 christos if (magic != AR_EEPROM_MAGIC) {
303 1.1 christos if (magic != bswap16(AR_EEPROM_MAGIC)) {
304 1.1 christos DPRINTFN(DBG_INIT, sc,
305 1.1 christos "invalid ROM magic 0x%x != 0x%x\n",
306 1.1 christos magic, AR_EEPROM_MAGIC);
307 1.1 christos return EIO;
308 1.1 christos }
309 1.1 christos DPRINTFN(DBG_INIT, sc, "non-native ROM endianness\n");
310 1.1 christos need_swap = 1;
311 1.1 christos }
312 1.1 christos
313 1.1 christos /* Allocate space to store ROM in host memory. */
314 1.1 christos sc->sc_eep = malloc(sc->sc_eep_size, M_DEVBUF, M_NOWAIT);
315 1.1 christos if (sc->sc_eep == NULL)
316 1.1 christos return ENOMEM;
317 1.1 christos
318 1.1 christos /* Read entire ROM and compute checksum. */
319 1.1 christos sum = 0;
320 1.1 christos eep = sc->sc_eep;
321 1.1 christos end = sc->sc_eep_base + sc->sc_eep_size / sizeof(uint16_t);
322 1.1 christos for (addr = sc->sc_eep_base; addr < end; addr++, eep++) {
323 1.1 christos if ((error = ar5008_read_eep_word(sc, addr, eep)) != 0) {
324 1.1 christos DPRINTFN(DBG_INIT, sc,
325 1.1 christos "could not read ROM at 0x%x\n", addr);
326 1.1 christos return error;
327 1.1 christos }
328 1.1 christos if (need_swap)
329 1.1 christos *eep = bswap16(*eep);
330 1.1 christos sum ^= *eep;
331 1.1 christos }
332 1.1 christos if (sum != 0xffff) {
333 1.1 christos printf("%s: bad ROM checksum 0x%04x\n",
334 1.1 christos device_xname(sc->sc_dev), sum);
335 1.1 christos return EIO;
336 1.1 christos }
337 1.1 christos if (need_swap)
338 1.1 christos ar5008_swap_rom(sc);
339 1.1 christos
340 1.1 christos return 0;
341 1.1 christos }
342 1.1 christos
343 1.1 christos Static void
344 1.1 christos ar5008_swap_rom(struct athn_softc *sc)
345 1.1 christos {
346 1.1 christos struct ar_base_eep_header *base = sc->sc_eep;
347 1.1 christos
348 1.1 christos /* Swap common fields first. */
349 1.1 christos base->length = bswap16(base->length);
350 1.1 christos base->version = bswap16(base->version);
351 1.1 christos base->regDmn[0] = bswap16(base->regDmn[0]);
352 1.1 christos base->regDmn[1] = bswap16(base->regDmn[1]);
353 1.1 christos base->rfSilent = bswap16(base->rfSilent);
354 1.1 christos base->blueToothOptions = bswap16(base->blueToothOptions);
355 1.1 christos base->deviceCap = bswap16(base->deviceCap);
356 1.1 christos
357 1.1 christos /* Swap device-dependent fields. */
358 1.1 christos sc->sc_ops.swap_rom(sc);
359 1.1 christos }
360 1.1 christos
361 1.1 christos /*
362 1.1 christos * Access to General Purpose Input/Output ports.
363 1.1 christos */
364 1.1 christos Static int
365 1.1 christos ar5008_gpio_read(struct athn_softc *sc, int pin)
366 1.1 christos {
367 1.1 christos
368 1.1 christos KASSERT(pin < sc->sc_ngpiopins);
369 1.1 christos if ((sc->sc_flags & ATHN_FLAG_USB) && !AR_SREV_9271(sc))
370 1.1 christos return !((AR_READ(sc, AR7010_GPIO_IN) >> pin) & 1);
371 1.1 christos return (AR_READ(sc, AR_GPIO_IN_OUT) >> (sc->sc_ngpiopins + pin)) & 1;
372 1.1 christos }
373 1.1 christos
374 1.1 christos Static void
375 1.1 christos ar5008_gpio_write(struct athn_softc *sc, int pin, int set)
376 1.1 christos {
377 1.1 christos uint32_t reg;
378 1.1 christos
379 1.1 christos KASSERT(pin < sc->sc_ngpiopins);
380 1.1 christos
381 1.1 christos if (sc->sc_flags & ATHN_FLAG_USB)
382 1.1 christos set = !set; /* AR9271/AR7010 is reversed. */
383 1.1 christos
384 1.1 christos if ((sc->sc_flags & ATHN_FLAG_USB) && !AR_SREV_9271(sc)) {
385 1.1 christos /* Special case for AR7010. */
386 1.1 christos reg = AR_READ(sc, AR7010_GPIO_OUT);
387 1.1 christos if (set)
388 1.1 christos reg |= 1 << pin;
389 1.1 christos else
390 1.1 christos reg &= ~(1 << pin);
391 1.1 christos AR_WRITE(sc, AR7010_GPIO_OUT, reg);
392 1.1 christos }
393 1.1 christos else {
394 1.1 christos reg = AR_READ(sc, AR_GPIO_IN_OUT);
395 1.1 christos if (set)
396 1.1 christos reg |= 1 << pin;
397 1.1 christos else
398 1.1 christos reg &= ~(1 << pin);
399 1.1 christos AR_WRITE(sc, AR_GPIO_IN_OUT, reg);
400 1.1 christos }
401 1.1 christos AR_WRITE_BARRIER(sc);
402 1.1 christos }
403 1.1 christos
404 1.1 christos Static void
405 1.1 christos ar5008_gpio_config_input(struct athn_softc *sc, int pin)
406 1.1 christos {
407 1.1 christos uint32_t reg;
408 1.1 christos
409 1.1 christos if ((sc->sc_flags & ATHN_FLAG_USB) && !AR_SREV_9271(sc)) {
410 1.1 christos /* Special case for AR7010. */
411 1.1 christos AR_SETBITS(sc, AR7010_GPIO_OE, 1 << pin);
412 1.1 christos }
413 1.1 christos else {
414 1.1 christos reg = AR_READ(sc, AR_GPIO_OE_OUT);
415 1.1 christos reg &= ~(AR_GPIO_OE_OUT_DRV_M << (pin * 2));
416 1.1 christos reg |= AR_GPIO_OE_OUT_DRV_NO << (pin * 2);
417 1.1 christos AR_WRITE(sc, AR_GPIO_OE_OUT, reg);
418 1.1 christos }
419 1.1 christos AR_WRITE_BARRIER(sc);
420 1.1 christos }
421 1.1 christos
422 1.1 christos Static void
423 1.1 christos ar5008_gpio_config_output(struct athn_softc *sc, int pin, int type)
424 1.1 christos {
425 1.1 christos uint32_t reg;
426 1.1 christos int mux, off;
427 1.1 christos
428 1.1 christos if ((sc->sc_flags & ATHN_FLAG_USB) && !AR_SREV_9271(sc)) {
429 1.1 christos /* Special case for AR7010. */
430 1.1 christos AR_CLRBITS(sc, AR7010_GPIO_OE, 1 << pin);
431 1.1 christos AR_WRITE_BARRIER(sc);
432 1.1 christos return;
433 1.1 christos }
434 1.1 christos mux = pin / 6;
435 1.1 christos off = pin % 6;
436 1.1 christos
437 1.1 christos reg = AR_READ(sc, AR_GPIO_OUTPUT_MUX(mux));
438 1.1 christos if (!AR_SREV_9280_20_OR_LATER(sc) && mux == 0)
439 1.1 christos reg = (reg & ~0x1f0) | (reg & 0x1f0) << 1;
440 1.1 christos reg &= ~(0x1f << (off * 5));
441 1.1 christos reg |= (type & 0x1f) << (off * 5);
442 1.1 christos AR_WRITE(sc, AR_GPIO_OUTPUT_MUX(mux), reg);
443 1.1 christos
444 1.1 christos reg = AR_READ(sc, AR_GPIO_OE_OUT);
445 1.1 christos reg &= ~(AR_GPIO_OE_OUT_DRV_M << (pin * 2));
446 1.1 christos reg |= AR_GPIO_OE_OUT_DRV_ALL << (pin * 2);
447 1.1 christos AR_WRITE(sc, AR_GPIO_OE_OUT, reg);
448 1.1 christos AR_WRITE_BARRIER(sc);
449 1.1 christos }
450 1.1 christos
451 1.1 christos Static void
452 1.1 christos ar5008_rfsilent_init(struct athn_softc *sc)
453 1.1 christos {
454 1.1 christos uint32_t reg;
455 1.1 christos
456 1.1 christos /* Configure hardware radio switch. */
457 1.1 christos AR_SETBITS(sc, AR_GPIO_INPUT_EN_VAL, AR_GPIO_INPUT_EN_VAL_RFSILENT_BB);
458 1.1 christos reg = AR_READ(sc, AR_GPIO_INPUT_MUX2);
459 1.1 christos reg = RW(reg, AR_GPIO_INPUT_MUX2_RFSILENT, 0);
460 1.1 christos AR_WRITE(sc, AR_GPIO_INPUT_MUX2, reg);
461 1.1 christos ar5008_gpio_config_input(sc, sc->sc_rfsilent_pin);
462 1.1 christos AR_SETBITS(sc, AR_PHY_TEST, AR_PHY_TEST_RFSILENT_BB);
463 1.1 christos if (!(sc->sc_flags & ATHN_FLAG_RFSILENT_REVERSED)) {
464 1.1 christos AR_SETBITS(sc, AR_GPIO_INTR_POL,
465 1.1 christos AR_GPIO_INTR_POL_PIN(sc->sc_rfsilent_pin));
466 1.1 christos }
467 1.1 christos AR_WRITE_BARRIER(sc);
468 1.1 christos }
469 1.1 christos
470 1.1 christos Static int
471 1.1 christos ar5008_dma_alloc(struct athn_softc *sc)
472 1.1 christos {
473 1.1 christos int error;
474 1.1 christos
475 1.1 christos error = ar5008_tx_alloc(sc);
476 1.1 christos if (error != 0)
477 1.1 christos return error;
478 1.1 christos
479 1.1 christos error = ar5008_rx_alloc(sc);
480 1.1 christos if (error != 0)
481 1.1 christos return error;
482 1.1 christos
483 1.1 christos return 0;
484 1.1 christos }
485 1.1 christos
486 1.1 christos Static void
487 1.1 christos ar5008_dma_free(struct athn_softc *sc)
488 1.1 christos {
489 1.1 christos
490 1.1 christos ar5008_tx_free(sc);
491 1.1 christos ar5008_rx_free(sc);
492 1.1 christos }
493 1.1 christos
494 1.1 christos Static int
495 1.1 christos ar5008_tx_alloc(struct athn_softc *sc)
496 1.1 christos {
497 1.1 christos struct athn_tx_buf *bf;
498 1.1 christos bus_size_t size;
499 1.1 christos int error, nsegs, i;
500 1.1 christos
501 1.1 christos /*
502 1.1 christos * Allocate a pool of Tx descriptors shared between all Tx queues.
503 1.1 christos */
504 1.1 christos size = ATHN_NTXBUFS * AR5008_MAX_SCATTER * sizeof(struct ar_tx_desc);
505 1.1 christos
506 1.1 christos error = bus_dmamap_create(sc->sc_dmat, size, 1, size, 0,
507 1.1 christos BUS_DMA_NOWAIT, &sc->sc_map);
508 1.1 christos if (error != 0)
509 1.1 christos goto fail;
510 1.1 christos
511 1.1 christos error = bus_dmamem_alloc(sc->sc_dmat, size, 4, 0, &sc->sc_seg, 1,
512 1.1 christos // XXX &nsegs, BUS_DMA_NOWAIT | BUS_DMA_ZERO);
513 1.1 christos &nsegs, BUS_DMA_NOWAIT);
514 1.1 christos if (error != 0)
515 1.1 christos goto fail;
516 1.1 christos
517 1.1 christos error = bus_dmamem_map(sc->sc_dmat, &sc->sc_seg, 1, size,
518 1.1 christos (void **)&sc->sc_descs, BUS_DMA_NOWAIT | BUS_DMA_COHERENT);
519 1.1 christos if (error != 0)
520 1.1 christos goto fail;
521 1.1 christos
522 1.1 christos error = bus_dmamap_load_raw(sc->sc_dmat, sc->sc_map, &sc->sc_seg, 1, size,
523 1.1 christos BUS_DMA_NOWAIT);
524 1.1 christos if (error != 0)
525 1.1 christos goto fail;
526 1.1 christos
527 1.1 christos SIMPLEQ_INIT(&sc->sc_txbufs);
528 1.1 christos for (i = 0; i < ATHN_NTXBUFS; i++) {
529 1.1 christos bf = &sc->sc_txpool[i];
530 1.1 christos
531 1.1 christos error = bus_dmamap_create(sc->sc_dmat, ATHN_TXBUFSZ,
532 1.1 christos AR5008_MAX_SCATTER, ATHN_TXBUFSZ, 0, BUS_DMA_NOWAIT,
533 1.1 christos &bf->bf_map);
534 1.1 christos if (error != 0) {
535 1.1 christos printf("%s: could not create Tx buf DMA map\n",
536 1.1 christos device_xname(sc->sc_dev));
537 1.1 christos goto fail;
538 1.1 christos }
539 1.1 christos
540 1.1 christos bf->bf_descs =
541 1.1 christos &((struct ar_tx_desc *)sc->sc_descs)[i * AR5008_MAX_SCATTER];
542 1.1 christos bf->bf_daddr = sc->sc_map->dm_segs[0].ds_addr +
543 1.1 christos i * AR5008_MAX_SCATTER * sizeof(struct ar_tx_desc);
544 1.1 christos
545 1.1 christos SIMPLEQ_INSERT_TAIL(&sc->sc_txbufs, bf, bf_list);
546 1.1 christos }
547 1.1 christos return 0;
548 1.1 christos fail:
549 1.1 christos ar5008_tx_free(sc);
550 1.1 christos return error;
551 1.1 christos }
552 1.1 christos
553 1.1 christos Static void
554 1.1 christos ar5008_tx_free(struct athn_softc *sc)
555 1.1 christos {
556 1.1 christos struct athn_tx_buf *bf;
557 1.1 christos int i;
558 1.1 christos
559 1.1 christos for (i = 0; i < ATHN_NTXBUFS; i++) {
560 1.1 christos bf = &sc->sc_txpool[i];
561 1.1 christos
562 1.1 christos if (bf->bf_map != NULL)
563 1.1 christos bus_dmamap_destroy(sc->sc_dmat, bf->bf_map);
564 1.1 christos }
565 1.1 christos /* Free Tx descriptors. */
566 1.1 christos if (sc->sc_map != NULL) {
567 1.1 christos if (sc->sc_descs != NULL) {
568 1.1 christos bus_dmamap_unload(sc->sc_dmat, sc->sc_map);
569 1.1 christos bus_dmamem_unmap(sc->sc_dmat, (void *)sc->sc_descs,
570 1.1 christos ATHN_NTXBUFS * AR5008_MAX_SCATTER *
571 1.1 christos sizeof(struct ar_tx_desc));
572 1.1 christos bus_dmamem_free(sc->sc_dmat, &sc->sc_seg, 1);
573 1.1 christos }
574 1.1 christos bus_dmamap_destroy(sc->sc_dmat, sc->sc_map);
575 1.1 christos }
576 1.1 christos }
577 1.1 christos
578 1.1 christos Static int
579 1.1 christos ar5008_rx_alloc(struct athn_softc *sc)
580 1.1 christos {
581 1.1 christos struct athn_rxq *rxq = &sc->sc_rxq[0];
582 1.1 christos struct athn_rx_buf *bf;
583 1.1 christos struct ar_rx_desc *ds;
584 1.1 christos bus_size_t size;
585 1.1 christos int error, nsegs, i;
586 1.1 christos
587 1.1 christos rxq->bf = malloc(ATHN_NRXBUFS * sizeof(*bf), M_DEVBUF,
588 1.1 christos M_NOWAIT | M_ZERO);
589 1.1 christos if (rxq->bf == NULL)
590 1.1 christos return ENOMEM;
591 1.1 christos
592 1.1 christos size = ATHN_NRXBUFS * sizeof(struct ar_rx_desc);
593 1.1 christos
594 1.1 christos error = bus_dmamap_create(sc->sc_dmat, size, 1, size, 0,
595 1.1 christos BUS_DMA_NOWAIT, &rxq->map);
596 1.1 christos if (error != 0)
597 1.1 christos goto fail;
598 1.1 christos
599 1.1 christos error = bus_dmamem_alloc(sc->sc_dmat, size, 0, 0, &rxq->seg, 1,
600 1.1 christos // &nsegs, BUS_DMA_NOWAIT | BUS_DMA_ZERO);
601 1.1 christos &nsegs, BUS_DMA_NOWAIT);
602 1.1 christos if (error != 0)
603 1.1 christos goto fail;
604 1.1 christos
605 1.1 christos error = bus_dmamem_map(sc->sc_dmat, &rxq->seg, 1, size,
606 1.1 christos (void **)&rxq->descs, BUS_DMA_NOWAIT | BUS_DMA_COHERENT);
607 1.1 christos if (error != 0)
608 1.1 christos goto fail;
609 1.1 christos
610 1.1 christos error = bus_dmamap_load_raw(sc->sc_dmat, rxq->map, &rxq->seg, 1,
611 1.1 christos size, BUS_DMA_NOWAIT);
612 1.1 christos if (error != 0)
613 1.1 christos goto fail;
614 1.1 christos
615 1.1 christos for (i = 0; i < ATHN_NRXBUFS; i++) {
616 1.1 christos bf = &rxq->bf[i];
617 1.1 christos ds = &((struct ar_rx_desc *)rxq->descs)[i];
618 1.1 christos
619 1.1 christos error = bus_dmamap_create(sc->sc_dmat, ATHN_RXBUFSZ, 1,
620 1.1 christos ATHN_RXBUFSZ, 0, BUS_DMA_NOWAIT | BUS_DMA_ALLOCNOW,
621 1.1 christos &bf->bf_map);
622 1.1 christos if (error != 0) {
623 1.1 christos printf("%s: could not create Rx buf DMA map\n",
624 1.1 christos device_xname(sc->sc_dev));
625 1.1 christos goto fail;
626 1.1 christos }
627 1.1 christos /*
628 1.1 christos * Assumes MCLGETI returns cache-line-size aligned buffers.
629 1.1 christos * XXX: does ours?
630 1.1 christos */
631 1.1 christos bf->bf_m = MCLGETI(NULL, M_DONTWAIT, NULL, ATHN_RXBUFSZ);
632 1.1 christos if (bf->bf_m == NULL) {
633 1.1 christos printf("%s: could not allocate Rx mbuf\n",
634 1.1 christos device_xname(sc->sc_dev));
635 1.1 christos error = ENOBUFS;
636 1.1 christos goto fail;
637 1.1 christos }
638 1.1 christos
639 1.1 christos error = bus_dmamap_load(sc->sc_dmat, bf->bf_map,
640 1.1 christos mtod(bf->bf_m, void *), ATHN_RXBUFSZ, NULL,
641 1.1 christos BUS_DMA_NOWAIT | BUS_DMA_READ);
642 1.1 christos if (error != 0) {
643 1.1 christos printf("%s: could not DMA map Rx buffer\n",
644 1.1 christos device_xname(sc->sc_dev));
645 1.1 christos goto fail;
646 1.1 christos }
647 1.1 christos
648 1.1 christos bus_dmamap_sync(sc->sc_dmat, bf->bf_map, 0, ATHN_RXBUFSZ,
649 1.1 christos BUS_DMASYNC_PREREAD);
650 1.1 christos
651 1.1 christos bf->bf_desc = ds;
652 1.1 christos bf->bf_daddr = rxq->map->dm_segs[0].ds_addr +
653 1.1 christos i * sizeof(struct ar_rx_desc);
654 1.1 christos }
655 1.1 christos return 0;
656 1.1 christos fail:
657 1.1 christos ar5008_rx_free(sc);
658 1.1 christos return error;
659 1.1 christos }
660 1.1 christos
661 1.1 christos Static void
662 1.1 christos ar5008_rx_free(struct athn_softc *sc)
663 1.1 christos {
664 1.1 christos struct athn_rxq *rxq = &sc->sc_rxq[0];
665 1.1 christos struct athn_rx_buf *bf;
666 1.1 christos int i;
667 1.1 christos
668 1.1 christos if (rxq->bf == NULL)
669 1.1 christos return;
670 1.1 christos for (i = 0; i < ATHN_NRXBUFS; i++) {
671 1.1 christos bf = &rxq->bf[i];
672 1.1 christos
673 1.1 christos if (bf->bf_map != NULL)
674 1.1 christos bus_dmamap_destroy(sc->sc_dmat, bf->bf_map);
675 1.1 christos if (bf->bf_m != NULL)
676 1.1 christos m_freem(bf->bf_m);
677 1.1 christos }
678 1.1 christos free(rxq->bf, M_DEVBUF);
679 1.1 christos
680 1.1 christos /* Free Rx descriptors. */
681 1.1 christos if (rxq->map != NULL) {
682 1.1 christos if (rxq->descs != NULL) {
683 1.1 christos bus_dmamap_unload(sc->sc_dmat, rxq->map);
684 1.1 christos bus_dmamem_unmap(sc->sc_dmat, (void *)rxq->descs,
685 1.1 christos ATHN_NRXBUFS * sizeof(struct ar_rx_desc));
686 1.1 christos bus_dmamem_free(sc->sc_dmat, &rxq->seg, 1);
687 1.1 christos }
688 1.1 christos bus_dmamap_destroy(sc->sc_dmat, rxq->map);
689 1.1 christos }
690 1.1 christos }
691 1.1 christos
692 1.1 christos Static void
693 1.1 christos ar5008_rx_enable(struct athn_softc *sc)
694 1.1 christos {
695 1.1 christos struct athn_rxq *rxq = &sc->sc_rxq[0];
696 1.1 christos struct athn_rx_buf *bf;
697 1.1 christos struct ar_rx_desc *ds;
698 1.1 christos int i;
699 1.1 christos
700 1.1 christos /* Setup and link Rx descriptors. */
701 1.1 christos SIMPLEQ_INIT(&rxq->head);
702 1.1 christos rxq->lastds = NULL;
703 1.1 christos for (i = 0; i < ATHN_NRXBUFS; i++) {
704 1.1 christos bf = &rxq->bf[i];
705 1.1 christos ds = bf->bf_desc;
706 1.1 christos
707 1.1 christos memset(ds, 0, sizeof(*ds));
708 1.1 christos ds->ds_data = bf->bf_map->dm_segs[0].ds_addr;
709 1.1 christos ds->ds_ctl1 = SM(AR_RXC1_BUF_LEN, ATHN_RXBUFSZ);
710 1.1 christos
711 1.1 christos if (rxq->lastds != NULL) {
712 1.1 christos ((struct ar_rx_desc *)rxq->lastds)->ds_link =
713 1.1 christos bf->bf_daddr;
714 1.1 christos }
715 1.1 christos SIMPLEQ_INSERT_TAIL(&rxq->head, bf, bf_list);
716 1.1 christos rxq->lastds = ds;
717 1.1 christos }
718 1.1 christos bus_dmamap_sync(sc->sc_dmat, rxq->map, 0, rxq->map->dm_mapsize,
719 1.1 christos BUS_DMASYNC_PREREAD);
720 1.1 christos
721 1.1 christos /* Enable Rx. */
722 1.1 christos AR_WRITE(sc, AR_RXDP, SIMPLEQ_FIRST(&rxq->head)->bf_daddr);
723 1.1 christos AR_WRITE(sc, AR_CR, AR_CR_RXE);
724 1.1 christos AR_WRITE_BARRIER(sc);
725 1.1 christos }
726 1.1 christos
727 1.1 christos Static void
728 1.1 christos ar5008_rx_radiotap(struct athn_softc *sc, struct mbuf *m,
729 1.1 christos struct ar_rx_desc *ds)
730 1.1 christos {
731 1.1 christos struct athn_rx_radiotap_header *tap = &sc->sc_rxtap;
732 1.1 christos struct ieee80211com *ic = &sc->sc_ic;
733 1.1 christos uint64_t tsf;
734 1.1 christos uint32_t tstamp;
735 1.1 christos uint8_t rate;
736 1.1 christos
737 1.1 christos /* Extend the 15-bit timestamp from Rx descriptor to 64-bit TSF. */
738 1.1 christos tstamp = ds->ds_status2;
739 1.1 christos tsf = AR_READ(sc, AR_TSF_U32);
740 1.1 christos tsf = tsf << 32 | AR_READ(sc, AR_TSF_L32);
741 1.1 christos if ((tsf & 0x7fff) < tstamp)
742 1.1 christos tsf -= 0x8000;
743 1.1 christos tsf = (tsf & ~0x7fff) | tstamp;
744 1.1 christos
745 1.1 christos tap->wr_flags = IEEE80211_RADIOTAP_F_FCS;
746 1.1 christos tap->wr_tsft = htole64(tsf);
747 1.1 christos tap->wr_chan_freq = htole16(ic->ic_curchan->ic_freq);
748 1.1 christos tap->wr_chan_flags = htole16(ic->ic_curchan->ic_flags);
749 1.1 christos tap->wr_dbm_antsignal = MS(ds->ds_status4, AR_RXS4_RSSI_COMBINED);
750 1.1 christos /* XXX noise. */
751 1.1 christos tap->wr_antenna = MS(ds->ds_status3, AR_RXS3_ANTENNA);
752 1.1 christos tap->wr_rate = 0; /* In case it can't be found below. */
753 1.1 christos if (AR_SREV_5416_20_OR_LATER(sc))
754 1.1 christos rate = MS(ds->ds_status0, AR_RXS0_RATE);
755 1.1 christos else
756 1.1 christos rate = MS(ds->ds_status3, AR_RXS3_RATE);
757 1.1 christos if (rate & 0x80) { /* HT. */
758 1.1 christos /* Bit 7 set means HT MCS instead of rate. */
759 1.1 christos tap->wr_rate = rate;
760 1.1 christos if (!(ds->ds_status3 & AR_RXS3_GI))
761 1.1 christos tap->wr_flags |= IEEE80211_RADIOTAP_F_SHORTGI;
762 1.1 christos
763 1.1 christos }
764 1.1 christos else if (rate & 0x10) { /* CCK. */
765 1.1 christos if (rate & 0x04)
766 1.1 christos tap->wr_flags |= IEEE80211_RADIOTAP_F_SHORTPRE;
767 1.1 christos switch (rate & ~0x14) {
768 1.1 christos case 0xb: tap->wr_rate = 2; break;
769 1.1 christos case 0xa: tap->wr_rate = 4; break;
770 1.1 christos case 0x9: tap->wr_rate = 11; break;
771 1.1 christos case 0x8: tap->wr_rate = 22; break;
772 1.1 christos }
773 1.1 christos }
774 1.1 christos else { /* OFDM. */
775 1.1 christos switch (rate) {
776 1.1 christos case 0xb: tap->wr_rate = 12; break;
777 1.1 christos case 0xf: tap->wr_rate = 18; break;
778 1.1 christos case 0xa: tap->wr_rate = 24; break;
779 1.1 christos case 0xe: tap->wr_rate = 36; break;
780 1.1 christos case 0x9: tap->wr_rate = 48; break;
781 1.1 christos case 0xd: tap->wr_rate = 72; break;
782 1.1 christos case 0x8: tap->wr_rate = 96; break;
783 1.1 christos case 0xc: tap->wr_rate = 108; break;
784 1.1 christos }
785 1.1 christos }
786 1.1 christos bpf_mtap2(sc->sc_drvbpf, tap, sc->sc_rxtap_len, m);
787 1.1 christos }
788 1.1 christos
789 1.1 christos static __inline int
790 1.1 christos ar5008_rx_process(struct athn_softc *sc)
791 1.1 christos {
792 1.1 christos struct ieee80211com *ic = &sc->sc_ic;
793 1.1 christos struct ifnet *ifp = &sc->sc_if;
794 1.1 christos struct athn_rxq *rxq = &sc->sc_rxq[0];
795 1.1 christos struct athn_rx_buf *bf, *nbf;
796 1.1 christos struct ar_rx_desc *ds;
797 1.1 christos struct ieee80211_frame *wh;
798 1.1 christos struct ieee80211_node *ni;
799 1.1 christos struct mbuf *m, *m1;
800 1.1 christos u_int32_t rstamp;
801 1.1 christos int error, len, rssi;
802 1.1 christos
803 1.1 christos bf = SIMPLEQ_FIRST(&rxq->head);
804 1.1 christos if (__predict_false(bf == NULL)) { /* Should not happen. */
805 1.1 christos printf("%s: Rx queue is empty!\n", device_xname(sc->sc_dev));
806 1.1 christos return ENOENT;
807 1.1 christos }
808 1.1 christos ds = bf->bf_desc;
809 1.1 christos
810 1.1 christos if (!(ds->ds_status8 & AR_RXS8_DONE)) {
811 1.1 christos /*
812 1.1 christos * On some parts, the status words can get corrupted
813 1.1 christos * (including the "done" bit), so we check the next
814 1.1 christos * descriptor "done" bit. If it is set, it is a good
815 1.1 christos * indication that the status words are corrupted, so
816 1.1 christos * we skip this descriptor and drop the frame.
817 1.1 christos */
818 1.1 christos nbf = SIMPLEQ_NEXT(bf, bf_list);
819 1.1 christos if (nbf != NULL &&
820 1.1 christos (((struct ar_rx_desc *)nbf->bf_desc)->ds_status8 &
821 1.1 christos AR_RXS8_DONE)) {
822 1.1 christos DPRINTFN(DBG_RX, sc,
823 1.1 christos "corrupted descriptor status=0x%x\n",
824 1.1 christos ds->ds_status8);
825 1.1 christos /* HW will not "move" RXDP in this case, so do it. */
826 1.1 christos AR_WRITE(sc, AR_RXDP, nbf->bf_daddr);
827 1.1 christos AR_WRITE_BARRIER(sc);
828 1.1 christos ifp->if_ierrors++;
829 1.1 christos goto skip;
830 1.1 christos }
831 1.1 christos return EBUSY;
832 1.1 christos }
833 1.1 christos
834 1.1 christos if (__predict_false(ds->ds_status1 & AR_RXS1_MORE)) {
835 1.1 christos /* Drop frames that span multiple Rx descriptors. */
836 1.1 christos DPRINTFN(DBG_RX, sc, "dropping split frame\n");
837 1.1 christos ifp->if_ierrors++;
838 1.1 christos goto skip;
839 1.1 christos }
840 1.1 christos if (!(ds->ds_status8 & AR_RXS8_FRAME_OK)) {
841 1.1 christos if (ds->ds_status8 & AR_RXS8_CRC_ERR)
842 1.1 christos DPRINTFN(DBG_RX, sc, "CRC error\n");
843 1.1 christos else if (ds->ds_status8 & AR_RXS8_PHY_ERR)
844 1.1 christos DPRINTFN(DBG_RX, sc, "PHY error=0x%x\n",
845 1.1 christos MS(ds->ds_status8, AR_RXS8_PHY_ERR_CODE));
846 1.1 christos else if (ds->ds_status8 & AR_RXS8_DECRYPT_CRC_ERR)
847 1.1 christos DPRINTFN(DBG_RX, sc, "Decryption CRC error\n");
848 1.1 christos else if (ds->ds_status8 & AR_RXS8_MICHAEL_ERR) {
849 1.1 christos DPRINTFN(DBG_RX, sc, "Michael MIC failure\n");
850 1.1 christos
851 1.1 christos len = MS(ds->ds_status1, AR_RXS1_DATA_LEN);
852 1.1 christos m = bf->bf_m;
853 1.1 christos m->m_pkthdr.rcvif = ifp;
854 1.1 christos m->m_pkthdr.len = m->m_len = len;
855 1.1 christos wh = mtod(m, struct ieee80211_frame *);
856 1.1 christos
857 1.1 christos /* Report Michael MIC failures to net80211. */
858 1.1 christos ieee80211_notify_michael_failure(ic, wh, 0 /* XXX: keyix */);
859 1.1 christos }
860 1.1 christos ifp->if_ierrors++;
861 1.1 christos goto skip;
862 1.1 christos }
863 1.1 christos
864 1.1 christos len = MS(ds->ds_status1, AR_RXS1_DATA_LEN);
865 1.1 christos if (__predict_false(len < (int)IEEE80211_MIN_LEN || len > ATHN_RXBUFSZ)) {
866 1.1 christos DPRINTFN(DBG_RX, sc, "corrupted descriptor length=%d\n", len);
867 1.1 christos ifp->if_ierrors++;
868 1.1 christos goto skip;
869 1.1 christos }
870 1.1 christos
871 1.1 christos /* Allocate a new Rx buffer. */
872 1.1 christos m1 = MCLGETI(NULL, M_DONTWAIT, NULL, ATHN_RXBUFSZ);
873 1.1 christos if (__predict_false(m1 == NULL)) {
874 1.1 christos ic->ic_stats.is_rx_nobuf++;
875 1.1 christos ifp->if_ierrors++;
876 1.1 christos goto skip;
877 1.1 christos }
878 1.1 christos
879 1.1 christos /* Sync and unmap the old Rx buffer. */
880 1.1 christos bus_dmamap_sync(sc->sc_dmat, bf->bf_map, 0, ATHN_RXBUFSZ,
881 1.1 christos BUS_DMASYNC_POSTREAD);
882 1.1 christos bus_dmamap_unload(sc->sc_dmat, bf->bf_map);
883 1.1 christos
884 1.1 christos /* Map the new Rx buffer. */
885 1.1 christos error = bus_dmamap_load(sc->sc_dmat, bf->bf_map, mtod(m1, void *),
886 1.1 christos ATHN_RXBUFSZ, NULL, BUS_DMA_NOWAIT | BUS_DMA_READ);
887 1.1 christos if (__predict_false(error != 0)) {
888 1.1 christos m_freem(m1);
889 1.1 christos
890 1.1 christos /* Remap the old Rx buffer or panic. */
891 1.1 christos error = bus_dmamap_load(sc->sc_dmat, bf->bf_map,
892 1.1 christos mtod(bf->bf_m, void *), ATHN_RXBUFSZ, NULL,
893 1.1 christos BUS_DMA_NOWAIT | BUS_DMA_READ);
894 1.1 christos KASSERT(error != 0);
895 1.1 christos ifp->if_ierrors++;
896 1.1 christos goto skip;
897 1.1 christos }
898 1.1 christos
899 1.1 christos bus_dmamap_sync(sc->sc_dmat, bf->bf_map, 0, ATHN_RXBUFSZ,
900 1.1 christos BUS_DMASYNC_PREREAD);
901 1.1 christos
902 1.1 christos /* Write physical address of new Rx buffer. */
903 1.1 christos ds->ds_data = bf->bf_map->dm_segs[0].ds_addr;
904 1.1 christos
905 1.1 christos m = bf->bf_m;
906 1.1 christos bf->bf_m = m1;
907 1.1 christos
908 1.1 christos /* Finalize mbuf. */
909 1.1 christos m->m_pkthdr.rcvif = ifp;
910 1.1 christos m->m_pkthdr.len = m->m_len = len;
911 1.1 christos
912 1.1 christos /* Grab a reference to the source node. */
913 1.1 christos wh = mtod(m, struct ieee80211_frame *);
914 1.1 christos ni = ieee80211_find_rxnode(ic, (struct ieee80211_frame_min *)wh);
915 1.1 christos
916 1.1 christos /* Remove any HW padding after the 802.11 header. */
917 1.1 christos if (!(wh->i_fc[0] & IEEE80211_FC0_TYPE_CTL)) {
918 1.1 christos u_int hdrlen = ieee80211_anyhdrsize(wh);
919 1.1 christos if (hdrlen & 3) {
920 1.1 christos ovbcopy(wh, (uint8_t *)wh + 2, hdrlen);
921 1.1 christos m_adj(m, 2);
922 1.1 christos }
923 1.1 christos }
924 1.1 christos if (__predict_false(sc->sc_drvbpf != NULL))
925 1.1 christos ar5008_rx_radiotap(sc, m, ds);
926 1.1 christos
927 1.1 christos /* Trim 802.11 FCS after radiotap. */
928 1.1 christos m_adj(m, -IEEE80211_CRC_LEN);
929 1.1 christos
930 1.1 christos /* Send the frame to the 802.11 layer. */
931 1.1 christos rssi = MS(ds->ds_status4, AR_RXS4_RSSI_COMBINED);
932 1.1 christos rstamp = ds->ds_status2;
933 1.1 christos ieee80211_input(ic, m, ni, rssi, rstamp);
934 1.1 christos
935 1.1 christos /* Node is no longer needed. */
936 1.1 christos ieee80211_free_node(ni);
937 1.1 christos
938 1.1 christos skip:
939 1.1 christos /* Unlink this descriptor from head. */
940 1.1 christos SIMPLEQ_REMOVE_HEAD(&rxq->head, bf_list);
941 1.1 christos memset(&ds->ds_status0, 0, 36); /* XXX Really needed? */
942 1.1 christos ds->ds_status8 &= ~AR_RXS8_DONE;
943 1.1 christos ds->ds_link = 0;
944 1.1 christos
945 1.1 christos /* Re-use this descriptor and link it to tail. */
946 1.1 christos if (__predict_true(!SIMPLEQ_EMPTY(&rxq->head)))
947 1.1 christos ((struct ar_rx_desc *)rxq->lastds)->ds_link = bf->bf_daddr;
948 1.1 christos else
949 1.1 christos AR_WRITE(sc, AR_RXDP, bf->bf_daddr);
950 1.1 christos SIMPLEQ_INSERT_TAIL(&rxq->head, bf, bf_list);
951 1.1 christos rxq->lastds = ds;
952 1.1 christos
953 1.1 christos /* Re-enable Rx. */
954 1.1 christos AR_WRITE(sc, AR_CR, AR_CR_RXE);
955 1.1 christos AR_WRITE_BARRIER(sc);
956 1.1 christos return 0;
957 1.1 christos }
958 1.1 christos
959 1.1 christos Static void
960 1.1 christos ar5008_rx_intr(struct athn_softc *sc)
961 1.1 christos {
962 1.1 christos
963 1.1 christos while (ar5008_rx_process(sc) == 0)
964 1.1 christos continue;
965 1.1 christos }
966 1.1 christos
967 1.1 christos Static int
968 1.1 christos ar5008_tx_process(struct athn_softc *sc, int qid)
969 1.1 christos {
970 1.1 christos struct ifnet *ifp = &sc->sc_if;
971 1.1 christos struct athn_txq *txq = &sc->sc_txq[qid];
972 1.1 christos struct athn_node *an;
973 1.1 christos struct athn_tx_buf *bf;
974 1.1 christos struct ar_tx_desc *ds;
975 1.1 christos uint8_t failcnt;
976 1.1 christos
977 1.1 christos bf = SIMPLEQ_FIRST(&txq->head);
978 1.1 christos if (bf == NULL)
979 1.1 christos return ENOENT;
980 1.1 christos /* Get descriptor of last DMA segment. */
981 1.1 christos ds = &((struct ar_tx_desc *)bf->bf_descs)[bf->bf_map->dm_nsegs - 1];
982 1.1 christos
983 1.1 christos if (!(ds->ds_status9 & AR_TXS9_DONE))
984 1.1 christos return EBUSY;
985 1.1 christos
986 1.1 christos SIMPLEQ_REMOVE_HEAD(&txq->head, bf_list);
987 1.1 christos ifp->if_opackets++;
988 1.1 christos
989 1.1 christos sc->sc_tx_timer = 0;
990 1.1 christos
991 1.1 christos if (ds->ds_status1 & AR_TXS1_EXCESSIVE_RETRIES)
992 1.1 christos ifp->if_oerrors++;
993 1.1 christos
994 1.1 christos if (ds->ds_status1 & AR_TXS1_UNDERRUN)
995 1.1 christos athn_inc_tx_trigger_level(sc);
996 1.1 christos
997 1.1 christos an = (struct athn_node *)bf->bf_ni;
998 1.1 christos /*
999 1.1 christos * NB: the data fail count contains the number of un-acked tries
1000 1.1 christos * for the final series used. We must add the number of tries for
1001 1.1 christos * each series that was fully processed.
1002 1.1 christos */
1003 1.1 christos failcnt = MS(ds->ds_status1, AR_TXS1_DATA_FAIL_CNT);
1004 1.1 christos /* NB: Assume two tries per series. */
1005 1.1 christos failcnt += MS(ds->ds_status9, AR_TXS9_FINAL_IDX) * 2;
1006 1.1 christos
1007 1.1 christos /* Update rate control statistics. */
1008 1.1 christos an->amn.amn_txcnt++;
1009 1.1 christos if (failcnt > 0)
1010 1.1 christos an->amn.amn_retrycnt++;
1011 1.1 christos
1012 1.1 christos DPRINTFN(DBG_TX, sc, "Tx done qid=%d status1=%d fail count=%d\n",
1013 1.1 christos qid, ds->ds_status1, failcnt);
1014 1.1 christos
1015 1.1 christos bus_dmamap_sync(sc->sc_dmat, bf->bf_map, 0, bf->bf_map->dm_mapsize,
1016 1.1 christos BUS_DMASYNC_POSTWRITE);
1017 1.1 christos bus_dmamap_unload(sc->sc_dmat, bf->bf_map);
1018 1.1 christos
1019 1.1 christos m_freem(bf->bf_m);
1020 1.1 christos bf->bf_m = NULL;
1021 1.1 christos ieee80211_free_node(bf->bf_ni);
1022 1.1 christos bf->bf_ni = NULL;
1023 1.1 christos
1024 1.1 christos /* Link Tx buffer back to global free list. */
1025 1.1 christos SIMPLEQ_INSERT_TAIL(&sc->sc_txbufs, bf, bf_list);
1026 1.1 christos return 0;
1027 1.1 christos }
1028 1.1 christos
1029 1.1 christos Static void
1030 1.1 christos ar5008_tx_intr(struct athn_softc *sc)
1031 1.1 christos {
1032 1.1 christos struct ifnet *ifp = &sc->sc_if;
1033 1.1 christos uint16_t mask = 0;
1034 1.1 christos uint32_t reg;
1035 1.1 christos int qid;
1036 1.1 christos
1037 1.1 christos reg = AR_READ(sc, AR_ISR_S0_S);
1038 1.1 christos mask |= MS(reg, AR_ISR_S0_QCU_TXOK);
1039 1.1 christos mask |= MS(reg, AR_ISR_S0_QCU_TXDESC);
1040 1.1 christos
1041 1.1 christos reg = AR_READ(sc, AR_ISR_S1_S);
1042 1.1 christos mask |= MS(reg, AR_ISR_S1_QCU_TXERR);
1043 1.1 christos mask |= MS(reg, AR_ISR_S1_QCU_TXEOL);
1044 1.1 christos
1045 1.1 christos DPRINTFN(DBG_TX, sc, "Tx interrupt mask=0x%x\n", mask);
1046 1.1 christos for (qid = 0; mask != 0; mask >>= 1, qid++) {
1047 1.1 christos if (mask & 1)
1048 1.1 christos while (ar5008_tx_process(sc, qid) == 0);
1049 1.1 christos }
1050 1.1 christos if (!SIMPLEQ_EMPTY(&sc->sc_txbufs)) {
1051 1.1 christos ifp->if_flags &= ~IFF_OACTIVE;
1052 1.1 christos ifp->if_start(ifp);
1053 1.1 christos }
1054 1.1 christos }
1055 1.1 christos
1056 1.1 christos #ifndef IEEE80211_STA_ONLY
1057 1.1 christos /*
1058 1.1 christos * Process Software Beacon Alert interrupts.
1059 1.1 christos */
1060 1.1 christos Static int
1061 1.1 christos ar5008_swba_intr(struct athn_softc *sc)
1062 1.1 christos {
1063 1.1 christos struct ieee80211com *ic = &sc->sc_ic;
1064 1.1 christos struct ifnet *ifp = &sc->sc_if;
1065 1.1 christos struct ieee80211_node *ni = ic->ic_bss;
1066 1.1 christos struct athn_tx_buf *bf = sc->sc_bcnbuf;
1067 1.1 christos struct ieee80211_frame *wh;
1068 1.1 christos struct ieee80211_beacon_offsets bo;
1069 1.1 christos struct ar_tx_desc *ds;
1070 1.1 christos struct mbuf *m;
1071 1.1 christos uint8_t ridx, hwrate;
1072 1.1 christos int error, totlen;
1073 1.1 christos
1074 1.1 christos #if notyet
1075 1.1 christos if (ic->ic_tim_mcast_pending &&
1076 1.1 christos IF_IS_EMPTY(&ni->ni_savedq) &&
1077 1.1 christos SIMPLEQ_EMPTY(&sc->sc_txq[ATHN_QID_CAB].head))
1078 1.1 christos ic->ic_tim_mcast_pending = 0;
1079 1.1 christos #endif
1080 1.1 christos if (ic->ic_dtim_count == 0)
1081 1.1 christos ic->ic_dtim_count = ic->ic_dtim_period - 1;
1082 1.1 christos else
1083 1.1 christos ic->ic_dtim_count--;
1084 1.1 christos
1085 1.1 christos /* Make sure previous beacon has been sent. */
1086 1.1 christos if (athn_tx_pending(sc, ATHN_QID_BEACON)) {
1087 1.1 christos DPRINTFN(DBG_INTR, sc, "beacon stuck\n");
1088 1.1 christos return EBUSY;
1089 1.1 christos }
1090 1.1 christos /* Get new beacon. */
1091 1.1 christos m = ieee80211_beacon_alloc(ic, ic->ic_bss, &bo);
1092 1.1 christos if (__predict_false(m == NULL))
1093 1.1 christos return ENOBUFS;
1094 1.1 christos /* Assign sequence number. */
1095 1.1 christos /* XXX: use non-QoS tid? */
1096 1.1 christos wh = mtod(m, struct ieee80211_frame *);
1097 1.1 christos *(uint16_t *)&wh->i_seq[0] =
1098 1.1 christos htole16(ic->ic_bss->ni_txseqs[0] << IEEE80211_SEQ_SEQ_SHIFT);
1099 1.1 christos ic->ic_bss->ni_txseqs[0]++;
1100 1.1 christos
1101 1.1 christos /* Unmap and free old beacon if any. */
1102 1.1 christos if (__predict_true(bf->bf_m != NULL)) {
1103 1.1 christos bus_dmamap_sync(sc->sc_dmat, bf->bf_map, 0,
1104 1.1 christos bf->bf_map->dm_mapsize, BUS_DMASYNC_POSTWRITE);
1105 1.1 christos bus_dmamap_unload(sc->sc_dmat, bf->bf_map);
1106 1.1 christos m_freem(bf->bf_m);
1107 1.1 christos bf->bf_m = NULL;
1108 1.1 christos }
1109 1.1 christos /* DMA map new beacon. */
1110 1.1 christos error = bus_dmamap_load_mbuf(sc->sc_dmat, bf->bf_map, m,
1111 1.1 christos BUS_DMA_NOWAIT | BUS_DMA_WRITE);
1112 1.1 christos if (__predict_false(error != 0)) {
1113 1.1 christos m_freem(m);
1114 1.1 christos return error;
1115 1.1 christos }
1116 1.1 christos bf->bf_m = m;
1117 1.1 christos
1118 1.1 christos /* Setup Tx descriptor (simplified ar5008_tx()). */
1119 1.1 christos ds = bf->bf_descs;
1120 1.1 christos memset(ds, 0, sizeof(*ds));
1121 1.1 christos
1122 1.1 christos totlen = m->m_pkthdr.len + IEEE80211_CRC_LEN;
1123 1.1 christos ds->ds_ctl0 = SM(AR_TXC0_FRAME_LEN, totlen);
1124 1.1 christos ds->ds_ctl0 |= SM(AR_TXC0_XMIT_POWER, AR_MAX_RATE_POWER);
1125 1.1 christos ds->ds_ctl1 = SM(AR_TXC1_FRAME_TYPE, AR_FRAME_TYPE_BEACON);
1126 1.1 christos ds->ds_ctl1 |= AR_TXC1_NO_ACK;
1127 1.1 christos ds->ds_ctl6 = SM(AR_TXC6_ENCR_TYPE, AR_ENCR_TYPE_CLEAR);
1128 1.1 christos
1129 1.1 christos /* Write number of tries. */
1130 1.1 christos ds->ds_ctl2 = SM(AR_TXC2_XMIT_DATA_TRIES0, 1);
1131 1.1 christos
1132 1.1 christos /* Write Tx rate. */
1133 1.1 christos ridx = (ic->ic_curmode == IEEE80211_MODE_11A) ?
1134 1.1 christos ATHN_RIDX_OFDM6 : ATHN_RIDX_CCK1;
1135 1.1 christos hwrate = athn_rates[ridx].hwrate;
1136 1.1 christos ds->ds_ctl3 = SM(AR_TXC3_XMIT_RATE0, hwrate);
1137 1.1 christos
1138 1.1 christos /* Write Tx chains. */
1139 1.1 christos ds->ds_ctl7 = SM(AR_TXC7_CHAIN_SEL0, sc->sc_txchainmask);
1140 1.1 christos
1141 1.1 christos ds->ds_data = bf->bf_map->dm_segs[0].ds_addr;
1142 1.1 christos /* Segment length must be a multiple of 4. */
1143 1.1 christos ds->ds_ctl1 |= SM(AR_TXC1_BUF_LEN,
1144 1.1 christos (bf->bf_map->dm_segs[0].ds_len + 3) & ~3);
1145 1.1 christos
1146 1.1 christos bus_dmamap_sync(sc->sc_dmat, bf->bf_map, 0, bf->bf_map->dm_mapsize,
1147 1.1 christos BUS_DMASYNC_PREWRITE);
1148 1.1 christos
1149 1.1 christos /* Stop Tx DMA before putting the new beacon on the queue. */
1150 1.1 christos athn_stop_tx_dma(sc, ATHN_QID_BEACON);
1151 1.1 christos
1152 1.1 christos AR_WRITE(sc, AR_QTXDP(ATHN_QID_BEACON), bf->bf_daddr);
1153 1.1 christos
1154 1.1 christos for(;;) {
1155 1.1 christos if (SIMPLEQ_EMPTY(&sc->sc_txbufs))
1156 1.1 christos break;
1157 1.1 christos
1158 1.1 christos IF_DEQUEUE(&ni->ni_savedq, m);
1159 1.1 christos if (m == NULL)
1160 1.1 christos break;
1161 1.1 christos if (!IF_IS_EMPTY(&ni->ni_savedq)) {
1162 1.1 christos /* more queued frames, set the more data bit */
1163 1.1 christos wh = mtod(m, struct ieee80211_frame *);
1164 1.1 christos wh->i_fc[1] |= IEEE80211_FC1_MORE_DATA;
1165 1.1 christos }
1166 1.1 christos
1167 1.1 christos if (sc->sc_ops.tx(sc, m, ni, ATHN_TXFLAG_CAB) != 0) {
1168 1.1 christos ieee80211_free_node(ni);
1169 1.1 christos ifp->if_oerrors++;
1170 1.1 christos break;
1171 1.1 christos }
1172 1.1 christos }
1173 1.1 christos
1174 1.1 christos /* Kick Tx. */
1175 1.1 christos AR_WRITE(sc, AR_Q_TXE, 1 << ATHN_QID_BEACON);
1176 1.1 christos AR_WRITE_BARRIER(sc);
1177 1.1 christos return 0;
1178 1.1 christos }
1179 1.1 christos #endif
1180 1.1 christos
1181 1.1 christos Static int
1182 1.1 christos ar5008_intr(struct athn_softc *sc)
1183 1.1 christos {
1184 1.1 christos uint32_t intr, intr2, intr5, sync;
1185 1.1 christos
1186 1.1 christos /* Get pending interrupts. */
1187 1.1 christos intr = AR_READ(sc, AR_INTR_ASYNC_CAUSE);
1188 1.1 christos if (!(intr & AR_INTR_MAC_IRQ) || intr == AR_INTR_SPURIOUS) {
1189 1.1 christos intr = AR_READ(sc, AR_INTR_SYNC_CAUSE);
1190 1.1 christos if (intr == AR_INTR_SPURIOUS || (intr & sc->sc_isync) == 0)
1191 1.1 christos return 0; /* Not for us. */
1192 1.1 christos }
1193 1.1 christos
1194 1.1 christos if ((AR_READ(sc, AR_INTR_ASYNC_CAUSE) & AR_INTR_MAC_IRQ) &&
1195 1.1 christos (AR_READ(sc, AR_RTC_STATUS) & AR_RTC_STATUS_M) == AR_RTC_STATUS_ON)
1196 1.1 christos intr = AR_READ(sc, AR_ISR);
1197 1.1 christos else
1198 1.1 christos intr = 0;
1199 1.1 christos sync = AR_READ(sc, AR_INTR_SYNC_CAUSE) & sc->sc_isync;
1200 1.1 christos if (intr == 0 && sync == 0)
1201 1.1 christos return 0; /* Not for us. */
1202 1.1 christos
1203 1.1 christos if (intr != 0) {
1204 1.1 christos if (intr & AR_ISR_BCNMISC) {
1205 1.1 christos intr2 = AR_READ(sc, AR_ISR_S2);
1206 1.1 christos #if notyet
1207 1.1 christos if (intr2 & AR_ISR_S2_TIM)
1208 1.1 christos /* TBD */;
1209 1.1 christos if (intr2 & AR_ISR_S2_TSFOOR)
1210 1.1 christos /* TBD */;
1211 1.1 christos #endif
1212 1.1 christos }
1213 1.1 christos intr = AR_READ(sc, AR_ISR_RAC);
1214 1.1 christos if (intr == AR_INTR_SPURIOUS)
1215 1.1 christos return 1;
1216 1.1 christos
1217 1.1 christos #ifndef IEEE80211_STA_ONLY
1218 1.1 christos if (intr & AR_ISR_SWBA)
1219 1.1 christos ar5008_swba_intr(sc);
1220 1.1 christos #endif
1221 1.1 christos if (intr & (AR_ISR_RXMINTR | AR_ISR_RXINTM))
1222 1.1 christos ar5008_rx_intr(sc);
1223 1.1 christos if (intr & (AR_ISR_RXOK | AR_ISR_RXERR | AR_ISR_RXORN))
1224 1.1 christos ar5008_rx_intr(sc);
1225 1.1 christos
1226 1.1 christos if (intr & (AR_ISR_TXOK | AR_ISR_TXDESC |
1227 1.1 christos AR_ISR_TXERR | AR_ISR_TXEOL))
1228 1.1 christos ar5008_tx_intr(sc);
1229 1.1 christos
1230 1.1 christos intr5 = AR_READ(sc, AR_ISR_S5_S);
1231 1.1 christos if (intr & AR_ISR_GENTMR) {
1232 1.1 christos if (intr5 & AR_ISR_GENTMR) {
1233 1.1 christos DPRINTFN(DBG_INTR, sc,
1234 1.1 christos "GENTMR trigger=%d thresh=%d\n",
1235 1.1 christos MS(intr5, AR_ISR_S5_GENTIMER_TRIG),
1236 1.1 christos MS(intr5, AR_ISR_S5_GENTIMER_THRESH));
1237 1.1 christos }
1238 1.1 christos }
1239 1.1 christos #if notyet
1240 1.1 christos if (intr5 & AR_ISR_S5_TIM_TIMER) {
1241 1.1 christos /* TBD */;
1242 1.1 christos }
1243 1.1 christos #endif
1244 1.1 christos }
1245 1.1 christos if (sync != 0) {
1246 1.1 christos #if notyet
1247 1.1 christos if (sync &
1248 1.1 christos (AR_INTR_SYNC_HOST1_FATAL | AR_INTR_SYNC_HOST1_PERR)) {
1249 1.1 christos /* TBD */;
1250 1.1 christos }
1251 1.1 christos #endif
1252 1.1 christos if (sync & AR_INTR_SYNC_RADM_CPL_TIMEOUT) {
1253 1.1 christos AR_WRITE(sc, AR_RC, AR_RC_HOSTIF);
1254 1.1 christos AR_WRITE(sc, AR_RC, 0);
1255 1.1 christos }
1256 1.1 christos
1257 1.1 christos if ((sc->sc_flags & ATHN_FLAG_RFSILENT) &&
1258 1.1 christos (sync & AR_INTR_SYNC_GPIO_PIN(sc->sc_rfsilent_pin))) {
1259 1.1 christos struct ifnet *ifp = &sc->sc_if;
1260 1.1 christos
1261 1.1 christos printf("%s: radio switch turned off\n",
1262 1.1 christos device_xname(sc->sc_dev));
1263 1.1 christos /* Turn the interface down. */
1264 1.1 christos ifp->if_flags &= ~IFF_UP;
1265 1.1 christos athn_stop(ifp, 1);
1266 1.1 christos return 1;
1267 1.1 christos }
1268 1.1 christos
1269 1.1 christos AR_WRITE(sc, AR_INTR_SYNC_CAUSE, sync);
1270 1.1 christos (void)AR_READ(sc, AR_INTR_SYNC_CAUSE);
1271 1.1 christos }
1272 1.1 christos return 1;
1273 1.1 christos }
1274 1.1 christos
1275 1.1 christos Static int
1276 1.1 christos ar5008_tx(struct athn_softc *sc, struct mbuf *m, struct ieee80211_node *ni,
1277 1.1 christos int txflags)
1278 1.1 christos {
1279 1.1 christos struct ieee80211com *ic = &sc->sc_ic;
1280 1.1 christos struct ieee80211_key *k = NULL;
1281 1.1 christos struct ieee80211_frame *wh;
1282 1.1 christos struct athn_series series[4];
1283 1.1 christos struct ar_tx_desc *ds, *lastds;
1284 1.1 christos struct athn_txq *txq;
1285 1.1 christos struct athn_tx_buf *bf;
1286 1.1 christos struct athn_node *an = (void *)ni;
1287 1.1 christos struct mbuf *m1;
1288 1.1 christos uint16_t qos;
1289 1.1 christos uint8_t txpower, type, encrtype, ridx[4];
1290 1.1 christos int i, error, totlen, hasqos, qid;
1291 1.1 christos
1292 1.1 christos /* Grab a Tx buffer from our global free list. */
1293 1.1 christos bf = SIMPLEQ_FIRST(&sc->sc_txbufs);
1294 1.1 christos KASSERT(bf != NULL);
1295 1.1 christos
1296 1.1 christos /* Map 802.11 frame type to hardware frame type. */
1297 1.1 christos wh = mtod(m, struct ieee80211_frame *);
1298 1.1 christos if ((wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK) ==
1299 1.1 christos IEEE80211_FC0_TYPE_MGT) {
1300 1.1 christos /* NB: Beacons do not use ar5008_tx(). */
1301 1.1 christos if ((wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK) ==
1302 1.1 christos IEEE80211_FC0_SUBTYPE_PROBE_RESP)
1303 1.1 christos type = AR_FRAME_TYPE_PROBE_RESP;
1304 1.1 christos else if ((wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK) ==
1305 1.1 christos IEEE80211_FC0_SUBTYPE_ATIM)
1306 1.1 christos type = AR_FRAME_TYPE_ATIM;
1307 1.1 christos else
1308 1.1 christos type = AR_FRAME_TYPE_NORMAL;
1309 1.1 christos }
1310 1.1 christos else if ((wh->i_fc[0] &
1311 1.1 christos (IEEE80211_FC0_TYPE_MASK | IEEE80211_FC0_SUBTYPE_MASK)) ==
1312 1.1 christos (IEEE80211_FC0_TYPE_CTL | IEEE80211_FC0_SUBTYPE_PS_POLL)) {
1313 1.1 christos type = AR_FRAME_TYPE_PSPOLL;
1314 1.1 christos }
1315 1.1 christos else
1316 1.1 christos type = AR_FRAME_TYPE_NORMAL;
1317 1.1 christos
1318 1.1 christos if (wh->i_fc[1] & IEEE80211_FC1_PROTECTED) {
1319 1.1 christos k = ieee80211_crypto_encap(ic, ni, m);
1320 1.1 christos if (k == NULL)
1321 1.1 christos return ENOBUFS;
1322 1.1 christos
1323 1.1 christos /* packet header may have moved, reset our local pointer */
1324 1.1 christos wh = mtod(m, struct ieee80211_frame *);
1325 1.1 christos }
1326 1.1 christos
1327 1.1 christos /* XXX 2-byte padding for QoS and 4-addr headers. */
1328 1.1 christos
1329 1.1 christos /* Select the HW Tx queue to use for this frame. */
1330 1.1 christos if ((hasqos = ieee80211_has_qos(wh))) {
1331 1.1 christos #ifdef notyet_edca
1332 1.1 christos uint8_t tid;
1333 1.1 christos
1334 1.1 christos qos = ieee80211_get_qos(wh);
1335 1.1 christos tid = qos & IEEE80211_QOS_TID;
1336 1.1 christos qid = athn_ac2qid[ieee80211_up_to_ac(ic, tid)];
1337 1.1 christos #else
1338 1.1 christos qos = ieee80211_get_qos(wh);
1339 1.1 christos qid = ATHN_QID_AC_BE;
1340 1.1 christos #endif /* notyet_edca */
1341 1.1 christos }
1342 1.1 christos else if (type == AR_FRAME_TYPE_PSPOLL) {
1343 1.1 christos qos = 0;
1344 1.1 christos qid = ATHN_QID_PSPOLL;
1345 1.1 christos }
1346 1.1 christos else if (txflags & ATHN_TXFLAG_CAB) {
1347 1.1 christos qos = 0;
1348 1.1 christos qid = ATHN_QID_CAB;
1349 1.1 christos }
1350 1.1 christos else {
1351 1.1 christos qos = 0;
1352 1.1 christos qid = ATHN_QID_AC_BE;
1353 1.1 christos }
1354 1.1 christos txq = &sc->sc_txq[qid];
1355 1.1 christos
1356 1.1 christos /* Select the transmit rates to use for this frame. */
1357 1.1 christos if (IEEE80211_IS_MULTICAST(wh->i_addr1) ||
1358 1.1 christos (wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK) !=
1359 1.1 christos IEEE80211_FC0_TYPE_DATA) {
1360 1.1 christos /* Use lowest rate for all tries. */
1361 1.1 christos ridx[0] = ridx[1] = ridx[2] = ridx[3] =
1362 1.1 christos (ic->ic_curmode == IEEE80211_MODE_11A) ?
1363 1.1 christos ATHN_RIDX_OFDM6 : ATHN_RIDX_CCK1;
1364 1.1 christos }
1365 1.1 christos else if (ic->ic_fixed_rate != -1) {
1366 1.1 christos /* Use same fixed rate for all tries. */
1367 1.1 christos ridx[0] = ridx[1] = ridx[2] = ridx[3] =
1368 1.1 christos sc->sc_fixed_ridx;
1369 1.1 christos }
1370 1.1 christos else {
1371 1.1 christos int txrate = ni->ni_txrate;
1372 1.1 christos /* Use fallback table of the node. */
1373 1.1 christos for (i = 0; i < 4; i++) {
1374 1.1 christos ridx[i] = an->ridx[txrate];
1375 1.1 christos txrate = an->fallback[txrate];
1376 1.1 christos }
1377 1.1 christos }
1378 1.1 christos
1379 1.1 christos if (__predict_false(sc->sc_drvbpf != NULL)) {
1380 1.1 christos struct athn_tx_radiotap_header *tap = &sc->sc_txtap;
1381 1.1 christos
1382 1.1 christos tap->wt_flags = 0;
1383 1.1 christos /* Use initial transmit rate. */
1384 1.1 christos tap->wt_rate = athn_rates[ridx[0]].rate;
1385 1.1 christos tap->wt_chan_freq = htole16(ic->ic_curchan->ic_freq);
1386 1.1 christos tap->wt_chan_flags = htole16(ic->ic_curchan->ic_flags);
1387 1.1 christos // XXX tap->wt_hwqueue = qid;
1388 1.1 christos if (ridx[0] != ATHN_RIDX_CCK1 &&
1389 1.1 christos (ic->ic_flags & IEEE80211_F_SHPREAMBLE))
1390 1.1 christos tap->wt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE;
1391 1.1 christos
1392 1.1 christos bpf_mtap2(sc->sc_drvbpf, tap, sc->sc_txtap_len, m);
1393 1.1 christos }
1394 1.1 christos
1395 1.1 christos /* DMA map mbuf. */
1396 1.1 christos error = bus_dmamap_load_mbuf(sc->sc_dmat, bf->bf_map, m,
1397 1.1 christos BUS_DMA_NOWAIT | BUS_DMA_WRITE);
1398 1.1 christos if (__predict_false(error != 0)) {
1399 1.1 christos if (error != EFBIG) {
1400 1.1 christos printf("%s: can't map mbuf (error %d)\n",
1401 1.1 christos device_xname(sc->sc_dev), error);
1402 1.1 christos m_freem(m);
1403 1.1 christos return error;
1404 1.1 christos }
1405 1.1 christos /*
1406 1.1 christos * DMA mapping requires too many DMA segments; linearize
1407 1.1 christos * mbuf in kernel virtual address space and retry.
1408 1.1 christos */
1409 1.1 christos MGETHDR(m1, M_DONTWAIT, MT_DATA);
1410 1.1 christos if (m1 == NULL) {
1411 1.1 christos m_freem(m);
1412 1.1 christos return ENOBUFS;
1413 1.1 christos }
1414 1.1 christos if (m->m_pkthdr.len > (int)MHLEN) {
1415 1.1 christos MCLGET(m1, M_DONTWAIT);
1416 1.1 christos if (!(m1->m_flags & M_EXT)) {
1417 1.1 christos m_freem(m);
1418 1.1 christos m_freem(m1);
1419 1.1 christos return ENOBUFS;
1420 1.1 christos }
1421 1.1 christos }
1422 1.1 christos m_copydata(m, 0, m->m_pkthdr.len, mtod(m1, void *));
1423 1.1 christos m1->m_pkthdr.len = m1->m_len = m->m_pkthdr.len;
1424 1.1 christos m_freem(m);
1425 1.1 christos m = m1;
1426 1.1 christos
1427 1.1 christos error = bus_dmamap_load_mbuf(sc->sc_dmat, bf->bf_map, m,
1428 1.1 christos BUS_DMA_NOWAIT | BUS_DMA_WRITE);
1429 1.1 christos if (error != 0) {
1430 1.1 christos printf("%s: can't map mbuf (error %d)\n",
1431 1.1 christos device_xname(sc->sc_dev), error);
1432 1.1 christos m_freem(m);
1433 1.1 christos return error;
1434 1.1 christos }
1435 1.1 christos }
1436 1.1 christos bf->bf_m = m;
1437 1.1 christos bf->bf_ni = ni;
1438 1.1 christos bf->bf_txflags = txflags;
1439 1.1 christos
1440 1.1 christos wh = mtod(m, struct ieee80211_frame *);
1441 1.1 christos
1442 1.1 christos totlen = m->m_pkthdr.len + IEEE80211_CRC_LEN;
1443 1.1 christos
1444 1.1 christos /* Clear all Tx descriptors that we will use. */
1445 1.1 christos memset(bf->bf_descs, 0, bf->bf_map->dm_nsegs * sizeof(*ds));
1446 1.1 christos
1447 1.1 christos /* Setup first Tx descriptor. */
1448 1.1 christos ds = bf->bf_descs;
1449 1.1 christos
1450 1.1 christos ds->ds_ctl0 = AR_TXC0_INTR_REQ | AR_TXC0_CLR_DEST_MASK;
1451 1.1 christos txpower = AR_MAX_RATE_POWER; /* Get from per-rate registers. */
1452 1.1 christos ds->ds_ctl0 |= SM(AR_TXC0_XMIT_POWER, txpower);
1453 1.1 christos
1454 1.1 christos ds->ds_ctl1 = SM(AR_TXC1_FRAME_TYPE, type);
1455 1.1 christos
1456 1.1 christos if (IEEE80211_IS_MULTICAST(wh->i_addr1) ||
1457 1.1 christos (hasqos && (qos & IEEE80211_QOS_ACKPOLICY_MASK) ==
1458 1.1 christos IEEE80211_QOS_ACKPOLICY_NOACK))
1459 1.1 christos ds->ds_ctl1 |= AR_TXC1_NO_ACK;
1460 1.1 christos #if notyet
1461 1.1 christos if (0 && k != NULL) {
1462 1.1 christos uintptr_t entry;
1463 1.1 christos
1464 1.1 christos /*
1465 1.1 christos * Map 802.11 cipher to hardware encryption type and
1466 1.1 christos * compute MIC+ICV overhead.
1467 1.1 christos */
1468 1.1 christos totlen += k->wk_keylen;
1469 1.1 christos switch (k->wk_cipher->ic_cipher) {
1470 1.1 christos case IEEE80211_CIPHER_WEP:
1471 1.1 christos encrtype = AR_ENCR_TYPE_WEP;
1472 1.1 christos break;
1473 1.1 christos case IEEE80211_CIPHER_TKIP:
1474 1.1 christos encrtype = AR_ENCR_TYPE_TKIP;
1475 1.1 christos break;
1476 1.1 christos case IEEE80211_CIPHER_AES_OCB:
1477 1.1 christos case IEEE80211_CIPHER_AES_CCM:
1478 1.1 christos encrtype = AR_ENCR_TYPE_AES;
1479 1.1 christos break;
1480 1.1 christos default:
1481 1.1 christos panic("unsupported cipher");
1482 1.1 christos }
1483 1.1 christos /*
1484 1.1 christos * NB: The key cache entry index is stored in the key
1485 1.1 christos * private field when the key is installed.
1486 1.1 christos */
1487 1.1 christos entry = (uintptr_t)k->k_priv;
1488 1.1 christos ds->ds_ctl1 |= SM(AR_TXC1_DEST_IDX, entry);
1489 1.1 christos ds->ds_ctl0 |= AR_TXC0_DEST_IDX_VALID;
1490 1.1 christos }
1491 1.1 christos else
1492 1.1 christos #endif
1493 1.1 christos encrtype = AR_ENCR_TYPE_CLEAR;
1494 1.1 christos ds->ds_ctl6 = SM(AR_TXC6_ENCR_TYPE, encrtype);
1495 1.1 christos
1496 1.1 christos /* Check if frame must be protected using RTS/CTS or CTS-to-self. */
1497 1.1 christos if (!IEEE80211_IS_MULTICAST(wh->i_addr1)) {
1498 1.1 christos /* NB: Group frames are sent using CCK in 802.11b/g. */
1499 1.1 christos if (totlen > ic->ic_rtsthreshold) {
1500 1.1 christos ds->ds_ctl0 |= AR_TXC0_RTS_ENABLE;
1501 1.1 christos }
1502 1.1 christos else if ((ic->ic_flags & IEEE80211_F_USEPROT) &&
1503 1.1 christos athn_rates[ridx[0]].phy == IEEE80211_T_OFDM) {
1504 1.1 christos if (ic->ic_protmode == IEEE80211_PROT_RTSCTS)
1505 1.1 christos ds->ds_ctl0 |= AR_TXC0_RTS_ENABLE;
1506 1.1 christos else if (ic->ic_protmode == IEEE80211_PROT_CTSONLY)
1507 1.1 christos ds->ds_ctl0 |= AR_TXC0_CTS_ENABLE;
1508 1.1 christos }
1509 1.1 christos }
1510 1.1 christos if (ds->ds_ctl0 & (AR_TXC0_RTS_ENABLE | AR_TXC0_CTS_ENABLE)) {
1511 1.1 christos /* Disable multi-rate retries when protection is used. */
1512 1.1 christos ridx[1] = ridx[2] = ridx[3] = ridx[0];
1513 1.1 christos }
1514 1.1 christos /* Setup multi-rate retries. */
1515 1.1 christos for (i = 0; i < 4; i++) {
1516 1.1 christos series[i].hwrate = athn_rates[ridx[i]].hwrate;
1517 1.1 christos if (athn_rates[ridx[i]].phy == IEEE80211_T_DS &&
1518 1.1 christos ridx[i] != ATHN_RIDX_CCK1 &&
1519 1.1 christos (ic->ic_flags & IEEE80211_F_SHPREAMBLE))
1520 1.1 christos series[i].hwrate |= 0x04;
1521 1.1 christos series[i].dur = 0;
1522 1.1 christos }
1523 1.1 christos if (!(ds->ds_ctl1 & AR_TXC1_NO_ACK)) {
1524 1.1 christos /* Compute duration for each series. */
1525 1.1 christos for (i = 0; i < 4; i++) {
1526 1.1 christos series[i].dur = athn_txtime(sc, IEEE80211_ACK_LEN,
1527 1.1 christos athn_rates[ridx[i]].rspridx, ic->ic_flags);
1528 1.1 christos }
1529 1.1 christos }
1530 1.1 christos
1531 1.1 christos /* Write number of tries for each series. */
1532 1.1 christos ds->ds_ctl2 =
1533 1.1 christos SM(AR_TXC2_XMIT_DATA_TRIES0, 2) |
1534 1.1 christos SM(AR_TXC2_XMIT_DATA_TRIES1, 2) |
1535 1.1 christos SM(AR_TXC2_XMIT_DATA_TRIES2, 2) |
1536 1.1 christos SM(AR_TXC2_XMIT_DATA_TRIES3, 4);
1537 1.1 christos
1538 1.1 christos /* Tell HW to update duration field in 802.11 header. */
1539 1.1 christos if (type != AR_FRAME_TYPE_PSPOLL)
1540 1.1 christos ds->ds_ctl2 |= AR_TXC2_DUR_UPDATE_ENA;
1541 1.1 christos
1542 1.1 christos /* Write Tx rate for each series. */
1543 1.1 christos ds->ds_ctl3 =
1544 1.1 christos SM(AR_TXC3_XMIT_RATE0, series[0].hwrate) |
1545 1.1 christos SM(AR_TXC3_XMIT_RATE1, series[1].hwrate) |
1546 1.1 christos SM(AR_TXC3_XMIT_RATE2, series[2].hwrate) |
1547 1.1 christos SM(AR_TXC3_XMIT_RATE3, series[3].hwrate);
1548 1.1 christos
1549 1.1 christos /* Write duration for each series. */
1550 1.1 christos ds->ds_ctl4 =
1551 1.1 christos SM(AR_TXC4_PACKET_DUR0, series[0].dur) |
1552 1.1 christos SM(AR_TXC4_PACKET_DUR1, series[1].dur);
1553 1.1 christos ds->ds_ctl5 =
1554 1.1 christos SM(AR_TXC5_PACKET_DUR2, series[2].dur) |
1555 1.1 christos SM(AR_TXC5_PACKET_DUR3, series[3].dur);
1556 1.1 christos
1557 1.1 christos /* Use the same Tx chains for all tries. */
1558 1.1 christos ds->ds_ctl7 =
1559 1.1 christos SM(AR_TXC7_CHAIN_SEL0, sc->sc_txchainmask) |
1560 1.1 christos SM(AR_TXC7_CHAIN_SEL1, sc->sc_txchainmask) |
1561 1.1 christos SM(AR_TXC7_CHAIN_SEL2, sc->sc_txchainmask) |
1562 1.1 christos SM(AR_TXC7_CHAIN_SEL3, sc->sc_txchainmask);
1563 1.1 christos #ifdef notyet
1564 1.1 christos #ifndef IEEE80211_NO_HT
1565 1.1 christos /* Use the same short GI setting for all tries. */
1566 1.1 christos if (ic->ic_flags & IEEE80211_F_SHGI)
1567 1.1 christos ds->ds_ctl7 |= AR_TXC7_GI0123;
1568 1.1 christos /* Use the same channel width for all tries. */
1569 1.1 christos if (ic->ic_flags & IEEE80211_F_CBW40)
1570 1.1 christos ds->ds_ctl7 |= AR_TXC7_2040_0123;
1571 1.1 christos #endif
1572 1.1 christos #endif
1573 1.1 christos
1574 1.1 christos if (ds->ds_ctl0 & (AR_TXC0_RTS_ENABLE | AR_TXC0_CTS_ENABLE)) {
1575 1.1 christos uint8_t protridx, hwrate;
1576 1.1 christos uint16_t dur = 0;
1577 1.1 christos
1578 1.1 christos /* Use the same protection mode for all tries. */
1579 1.1 christos if (ds->ds_ctl0 & AR_TXC0_RTS_ENABLE) {
1580 1.1 christos ds->ds_ctl4 |= AR_TXC4_RTSCTS_QUAL01;
1581 1.1 christos ds->ds_ctl5 |= AR_TXC5_RTSCTS_QUAL23;
1582 1.1 christos }
1583 1.1 christos /* Select protection rate (suboptimal but ok). */
1584 1.1 christos protridx = (ic->ic_curmode == IEEE80211_MODE_11A) ?
1585 1.1 christos ATHN_RIDX_OFDM6 : ATHN_RIDX_CCK2;
1586 1.1 christos if (ds->ds_ctl0 & AR_TXC0_RTS_ENABLE) {
1587 1.1 christos /* Account for CTS duration. */
1588 1.1 christos dur += athn_txtime(sc, IEEE80211_ACK_LEN,
1589 1.1 christos athn_rates[protridx].rspridx, ic->ic_flags);
1590 1.1 christos }
1591 1.1 christos dur += athn_txtime(sc, totlen, ridx[0], ic->ic_flags);
1592 1.1 christos if (!(ds->ds_ctl1 & AR_TXC1_NO_ACK)) {
1593 1.1 christos /* Account for ACK duration. */
1594 1.1 christos dur += athn_txtime(sc, IEEE80211_ACK_LEN,
1595 1.1 christos athn_rates[ridx[0]].rspridx, ic->ic_flags);
1596 1.1 christos }
1597 1.1 christos /* Write protection frame duration and rate. */
1598 1.1 christos ds->ds_ctl2 |= SM(AR_TXC2_BURST_DUR, dur);
1599 1.1 christos hwrate = athn_rates[protridx].hwrate;
1600 1.1 christos if (protridx == ATHN_RIDX_CCK2 &&
1601 1.1 christos (ic->ic_flags & IEEE80211_F_SHPREAMBLE))
1602 1.1 christos hwrate |= 0x04;
1603 1.1 christos ds->ds_ctl7 |= SM(AR_TXC7_RTSCTS_RATE, hwrate);
1604 1.1 christos }
1605 1.1 christos
1606 1.1 christos /* Finalize first Tx descriptor and fill others (if any). */
1607 1.1 christos ds->ds_ctl0 |= SM(AR_TXC0_FRAME_LEN, totlen);
1608 1.1 christos
1609 1.1 christos lastds = NULL; /* XXX: gcc */
1610 1.1 christos for (i = 0; i < bf->bf_map->dm_nsegs; i++, ds++) {
1611 1.1 christos ds->ds_data = bf->bf_map->dm_segs[i].ds_addr;
1612 1.1 christos ds->ds_ctl1 |= SM(AR_TXC1_BUF_LEN,
1613 1.1 christos bf->bf_map->dm_segs[i].ds_len);
1614 1.1 christos
1615 1.1 christos if (i != bf->bf_map->dm_nsegs - 1)
1616 1.1 christos ds->ds_ctl1 |= AR_TXC1_MORE;
1617 1.1 christos ds->ds_link = 0;
1618 1.1 christos
1619 1.1 christos /* Chain Tx descriptor. */
1620 1.1 christos if (i != 0)
1621 1.1 christos lastds->ds_link = bf->bf_daddr + i * sizeof(*ds);
1622 1.1 christos lastds = ds;
1623 1.1 christos }
1624 1.1 christos bus_dmamap_sync(sc->sc_dmat, bf->bf_map, 0, bf->bf_map->dm_mapsize,
1625 1.1 christos BUS_DMASYNC_PREWRITE);
1626 1.1 christos
1627 1.1 christos if (!SIMPLEQ_EMPTY(&txq->head))
1628 1.1 christos ((struct ar_tx_desc *)txq->lastds)->ds_link = bf->bf_daddr;
1629 1.1 christos else
1630 1.1 christos AR_WRITE(sc, AR_QTXDP(qid), bf->bf_daddr);
1631 1.1 christos txq->lastds = lastds;
1632 1.1 christos SIMPLEQ_REMOVE_HEAD(&sc->sc_txbufs, bf_list);
1633 1.1 christos SIMPLEQ_INSERT_TAIL(&txq->head, bf, bf_list);
1634 1.1 christos
1635 1.1 christos ds = bf->bf_descs;
1636 1.1 christos DPRINTFN(DBG_TX, sc,
1637 1.1 christos "Tx qid=%d nsegs=%d ctl0=0x%x ctl1=0x%x ctl3=0x%x\n",
1638 1.1 christos qid, bf->bf_map->dm_nsegs, ds->ds_ctl0, ds->ds_ctl1, ds->ds_ctl3);
1639 1.1 christos
1640 1.1 christos /* Kick Tx. */
1641 1.1 christos AR_WRITE(sc, AR_Q_TXE, 1 << qid);
1642 1.1 christos AR_WRITE_BARRIER(sc);
1643 1.1 christos return 0;
1644 1.1 christos }
1645 1.1 christos
1646 1.1 christos Static void
1647 1.1 christos ar5008_set_rf_mode(struct athn_softc *sc, struct ieee80211_channel *c)
1648 1.1 christos {
1649 1.1 christos uint32_t reg;
1650 1.1 christos
1651 1.1 christos reg = IEEE80211_IS_CHAN_2GHZ(c) ?
1652 1.1 christos AR_PHY_MODE_DYNAMIC : AR_PHY_MODE_OFDM;
1653 1.1 christos if (!AR_SREV_9280_10_OR_LATER(sc)) {
1654 1.1 christos reg |= IEEE80211_IS_CHAN_2GHZ(c) ?
1655 1.1 christos AR_PHY_MODE_RF2GHZ : AR_PHY_MODE_RF5GHZ;
1656 1.1 christos }
1657 1.1 christos else if (IEEE80211_IS_CHAN_5GHZ(c) &&
1658 1.1 christos (sc->sc_flags & ATHN_FLAG_FAST_PLL_CLOCK)) {
1659 1.1 christos reg |= AR_PHY_MODE_DYNAMIC | AR_PHY_MODE_DYN_CCK_DISABLE;
1660 1.1 christos }
1661 1.1 christos AR_WRITE(sc, AR_PHY_MODE, reg);
1662 1.1 christos AR_WRITE_BARRIER(sc);
1663 1.1 christos }
1664 1.1 christos
1665 1.1 christos static __inline uint32_t
1666 1.1 christos ar5008_synth_delay(struct athn_softc *sc)
1667 1.1 christos {
1668 1.1 christos uint32_t delay;
1669 1.1 christos
1670 1.1 christos delay = MS(AR_READ(sc, AR_PHY_RX_DELAY), AR_PHY_RX_DELAY_DELAY);
1671 1.1 christos if (sc->sc_ic.ic_curmode == IEEE80211_MODE_11B)
1672 1.1 christos delay = (delay * 4) / 22;
1673 1.1 christos else
1674 1.1 christos delay = delay / 10; /* in 100ns steps */
1675 1.1 christos return delay;
1676 1.1 christos }
1677 1.1 christos
1678 1.1 christos Static int
1679 1.1 christos ar5008_rf_bus_request(struct athn_softc *sc)
1680 1.1 christos {
1681 1.1 christos int ntries;
1682 1.1 christos
1683 1.1 christos /* Request RF Bus grant. */
1684 1.1 christos AR_WRITE(sc, AR_PHY_RFBUS_REQ, AR_PHY_RFBUS_REQ_EN);
1685 1.1 christos for (ntries = 0; ntries < 10000; ntries++) {
1686 1.1 christos if (AR_READ(sc, AR_PHY_RFBUS_GRANT) & AR_PHY_RFBUS_GRANT_EN)
1687 1.1 christos return 0;
1688 1.1 christos DELAY(10);
1689 1.1 christos }
1690 1.1 christos DPRINTFN(DBG_RF, sc, "could not kill baseband Rx");
1691 1.1 christos return ETIMEDOUT;
1692 1.1 christos }
1693 1.1 christos
1694 1.1 christos Static void
1695 1.1 christos ar5008_rf_bus_release(struct athn_softc *sc)
1696 1.1 christos {
1697 1.1 christos
1698 1.1 christos /* Wait for the synthesizer to settle. */
1699 1.1 christos DELAY(AR_BASE_PHY_ACTIVE_DELAY + ar5008_synth_delay(sc));
1700 1.1 christos
1701 1.1 christos /* Release the RF Bus grant. */
1702 1.1 christos AR_WRITE(sc, AR_PHY_RFBUS_REQ, 0);
1703 1.1 christos AR_WRITE_BARRIER(sc);
1704 1.1 christos }
1705 1.1 christos
1706 1.1 christos Static void
1707 1.1 christos ar5008_set_phy(struct athn_softc *sc, struct ieee80211_channel *c,
1708 1.1 christos struct ieee80211_channel *extc)
1709 1.1 christos {
1710 1.1 christos uint32_t phy;
1711 1.1 christos
1712 1.1 christos if (AR_SREV_9285_10_OR_LATER(sc))
1713 1.1 christos phy = AR_READ(sc, AR_PHY_TURBO) & AR_PHY_FC_ENABLE_DAC_FIFO;
1714 1.1 christos else
1715 1.1 christos phy = 0;
1716 1.1 christos phy |= AR_PHY_FC_HT_EN | AR_PHY_FC_SHORT_GI_40 |
1717 1.1 christos AR_PHY_FC_SINGLE_HT_LTF1 | AR_PHY_FC_WALSH;
1718 1.1 christos #ifndef IEEE80211_NO_HT
1719 1.1 christos if (extc != NULL) {
1720 1.1 christos phy |= AR_PHY_FC_DYN2040_EN;
1721 1.1 christos if (extc > c) /* XXX */
1722 1.1 christos phy |= AR_PHY_FC_DYN2040_PRI_CH;
1723 1.1 christos }
1724 1.1 christos #endif
1725 1.1 christos AR_WRITE(sc, AR_PHY_TURBO, phy);
1726 1.1 christos
1727 1.1 christos AR_WRITE(sc, AR_2040_MODE,
1728 1.1 christos (extc != NULL) ? AR_2040_JOINED_RX_CLEAR : 0);
1729 1.1 christos
1730 1.1 christos /* Set global transmit timeout. */
1731 1.1 christos AR_WRITE(sc, AR_GTXTO, SM(AR_GTXTO_TIMEOUT_LIMIT, 25));
1732 1.1 christos /* Set carrier sense timeout. */
1733 1.1 christos AR_WRITE(sc, AR_CST, SM(AR_CST_TIMEOUT_LIMIT, 15));
1734 1.1 christos AR_WRITE_BARRIER(sc);
1735 1.1 christos }
1736 1.1 christos
1737 1.1 christos Static void
1738 1.1 christos ar5008_set_delta_slope(struct athn_softc *sc, struct ieee80211_channel *c,
1739 1.1 christos struct ieee80211_channel *extc)
1740 1.1 christos {
1741 1.1 christos uint32_t coeff, exp, man, reg;
1742 1.1 christos
1743 1.1 christos /* Set Delta Slope (exponent and mantissa). */
1744 1.1 christos coeff = (100 << 24) / c->ic_freq;
1745 1.1 christos athn_get_delta_slope(coeff, &exp, &man);
1746 1.1 christos DPRINTFN(DBG_RX, sc, "delta slope coeff exp=%u man=%u\n", exp, man);
1747 1.1 christos
1748 1.1 christos reg = AR_READ(sc, AR_PHY_TIMING3);
1749 1.1 christos reg = RW(reg, AR_PHY_TIMING3_DSC_EXP, exp);
1750 1.1 christos reg = RW(reg, AR_PHY_TIMING3_DSC_MAN, man);
1751 1.1 christos AR_WRITE(sc, AR_PHY_TIMING3, reg);
1752 1.1 christos
1753 1.1 christos /* For Short GI, coeff is 9/10 that of normal coeff. */
1754 1.1 christos coeff = (9 * coeff) / 10;
1755 1.1 christos athn_get_delta_slope(coeff, &exp, &man);
1756 1.1 christos DPRINTFN(DBG_RX, sc, "delta slope coeff exp=%u man=%u\n", exp, man);
1757 1.1 christos
1758 1.1 christos reg = AR_READ(sc, AR_PHY_HALFGI);
1759 1.1 christos reg = RW(reg, AR_PHY_HALFGI_DSC_EXP, exp);
1760 1.1 christos reg = RW(reg, AR_PHY_HALFGI_DSC_MAN, man);
1761 1.1 christos AR_WRITE(sc, AR_PHY_HALFGI, reg);
1762 1.1 christos AR_WRITE_BARRIER(sc);
1763 1.1 christos }
1764 1.1 christos
1765 1.1 christos Static void
1766 1.1 christos ar5008_enable_antenna_diversity(struct athn_softc *sc)
1767 1.1 christos {
1768 1.1 christos
1769 1.1 christos AR_SETBITS(sc, AR_PHY_CCK_DETECT,
1770 1.1 christos AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV);
1771 1.1 christos AR_WRITE_BARRIER(sc);
1772 1.1 christos }
1773 1.1 christos
1774 1.1 christos Static void
1775 1.1 christos ar5008_init_baseband(struct athn_softc *sc)
1776 1.1 christos {
1777 1.1 christos uint32_t synth_delay;
1778 1.1 christos
1779 1.1 christos synth_delay = ar5008_synth_delay(sc);
1780 1.1 christos /* Activate the PHY (includes baseband activate and synthesizer on). */
1781 1.1 christos AR_WRITE(sc, AR_PHY_ACTIVE, AR_PHY_ACTIVE_EN);
1782 1.1 christos AR_WRITE_BARRIER(sc);
1783 1.1 christos DELAY(AR_BASE_PHY_ACTIVE_DELAY + synth_delay);
1784 1.1 christos }
1785 1.1 christos
1786 1.1 christos Static void
1787 1.1 christos ar5008_disable_phy(struct athn_softc *sc)
1788 1.1 christos {
1789 1.1 christos
1790 1.1 christos AR_WRITE(sc, AR_PHY_ACTIVE, AR_PHY_ACTIVE_DIS);
1791 1.1 christos AR_WRITE_BARRIER(sc);
1792 1.1 christos }
1793 1.1 christos
1794 1.1 christos Static void
1795 1.1 christos ar5008_init_chains(struct athn_softc *sc)
1796 1.1 christos {
1797 1.1 christos
1798 1.1 christos if (sc->sc_rxchainmask == 0x5 || sc->sc_txchainmask == 0x5)
1799 1.1 christos AR_SETBITS(sc, AR_PHY_ANALOG_SWAP, AR_PHY_SWAP_ALT_CHAIN);
1800 1.1 christos
1801 1.1 christos /* Setup chain masks. */
1802 1.1 christos if (sc->sc_mac_ver <= AR_SREV_VERSION_9160 &&
1803 1.1 christos (sc->sc_rxchainmask == 0x3 || sc->sc_rxchainmask == 0x5)) {
1804 1.1 christos AR_WRITE(sc, AR_PHY_RX_CHAINMASK, 0x7);
1805 1.1 christos AR_WRITE(sc, AR_PHY_CAL_CHAINMASK, 0x7);
1806 1.1 christos }
1807 1.1 christos else {
1808 1.1 christos AR_WRITE(sc, AR_PHY_RX_CHAINMASK, sc->sc_rxchainmask);
1809 1.1 christos AR_WRITE(sc, AR_PHY_CAL_CHAINMASK, sc->sc_rxchainmask);
1810 1.1 christos }
1811 1.1 christos AR_WRITE(sc, AR_SELFGEN_MASK, sc->sc_txchainmask);
1812 1.1 christos AR_WRITE_BARRIER(sc);
1813 1.1 christos }
1814 1.1 christos
1815 1.1 christos Static void
1816 1.1 christos ar5008_set_rxchains(struct athn_softc *sc)
1817 1.1 christos {
1818 1.1 christos
1819 1.1 christos if (sc->sc_rxchainmask == 0x3 || sc->sc_rxchainmask == 0x5) {
1820 1.1 christos AR_WRITE(sc, AR_PHY_RX_CHAINMASK, sc->sc_rxchainmask);
1821 1.1 christos AR_WRITE(sc, AR_PHY_CAL_CHAINMASK, sc->sc_rxchainmask);
1822 1.1 christos AR_WRITE_BARRIER(sc);
1823 1.1 christos }
1824 1.1 christos }
1825 1.1 christos
1826 1.1 christos #ifdef notused
1827 1.1 christos Static void
1828 1.1 christos ar5008_read_noisefloor(struct athn_softc *sc, int16_t *nf, int16_t *nf_ext)
1829 1.1 christos {
1830 1.1 christos /* Sign-extends 9-bit value (assumes upper bits are zeroes). */
1831 1.1 christos #define SIGN_EXT(v) (((v) ^ 0x100) - 0x100)
1832 1.1 christos uint32_t reg;
1833 1.1 christos int i;
1834 1.1 christos
1835 1.1 christos for (i = 0; i < sc->sc_nrxchains; i++) {
1836 1.1 christos reg = AR_READ(sc, AR_PHY_CCA(i));
1837 1.1 christos if (AR_SREV_9280_10_OR_LATER(sc))
1838 1.1 christos nf[i] = MS(reg, AR9280_PHY_MINCCA_PWR);
1839 1.1 christos else
1840 1.1 christos nf[i] = MS(reg, AR_PHY_MINCCA_PWR);
1841 1.1 christos nf[i] = SIGN_EXT(nf[i]);
1842 1.1 christos
1843 1.1 christos reg = AR_READ(sc, AR_PHY_EXT_CCA(i));
1844 1.1 christos if (AR_SREV_9280_10_OR_LATER(sc))
1845 1.1 christos nf_ext[i] = MS(reg, AR9280_PHY_EXT_MINCCA_PWR);
1846 1.1 christos else
1847 1.1 christos nf_ext[i] = MS(reg, AR_PHY_EXT_MINCCA_PWR);
1848 1.1 christos nf_ext[i] = SIGN_EXT(nf_ext[i]);
1849 1.1 christos }
1850 1.1 christos #undef SIGN_EXT
1851 1.1 christos }
1852 1.1 christos #endif /* notused */
1853 1.1 christos
1854 1.1 christos #ifdef notused
1855 1.1 christos Static void
1856 1.1 christos ar5008_write_noisefloor(struct athn_softc *sc, int16_t *nf, int16_t *nf_ext)
1857 1.1 christos {
1858 1.1 christos uint32_t reg;
1859 1.1 christos int i;
1860 1.1 christos
1861 1.1 christos for (i = 0; i < sc->sc_nrxchains; i++) {
1862 1.1 christos reg = AR_READ(sc, AR_PHY_CCA(i));
1863 1.1 christos reg = RW(reg, AR_PHY_MAXCCA_PWR, nf[i]);
1864 1.1 christos AR_WRITE(sc, AR_PHY_CCA(i), reg);
1865 1.1 christos
1866 1.1 christos reg = AR_READ(sc, AR_PHY_EXT_CCA(i));
1867 1.1 christos reg = RW(reg, AR_PHY_EXT_MAXCCA_PWR, nf_ext[i]);
1868 1.1 christos AR_WRITE(sc, AR_PHY_EXT_CCA(i), reg);
1869 1.1 christos }
1870 1.1 christos AR_WRITE_BARRIER(sc);
1871 1.1 christos }
1872 1.1 christos #endif /* notused */
1873 1.1 christos
1874 1.1 christos #ifdef notused
1875 1.1 christos Static void
1876 1.1 christos ar5008_get_noisefloor(struct athn_softc *sc, struct ieee80211_channel *c)
1877 1.1 christos {
1878 1.1 christos int16_t nf[AR_MAX_CHAINS], nf_ext[AR_MAX_CHAINS];
1879 1.1 christos int i;
1880 1.1 christos
1881 1.1 christos if (AR_READ(sc, AR_PHY_AGC_CONTROL) & AR_PHY_AGC_CONTROL_NF) {
1882 1.1 christos /* Noisefloor calibration not finished. */
1883 1.1 christos return;
1884 1.1 christos }
1885 1.1 christos /* Noisefloor calibration is finished. */
1886 1.1 christos ar5008_read_noisefloor(sc, nf, nf_ext);
1887 1.1 christos
1888 1.1 christos /* Update noisefloor history. */
1889 1.1 christos for (i = 0; i < sc->sc_nrxchains; i++) {
1890 1.1 christos sc->sc_nf_hist[sc->sc_nf_hist_cur].nf[i] = nf[i];
1891 1.1 christos sc->sc_nf_hist[sc->sc_nf_hist_cur].nf_ext[i] = nf_ext[i];
1892 1.1 christos }
1893 1.1 christos if (++sc->sc_nf_hist_cur >= ATHN_NF_CAL_HIST_MAX)
1894 1.1 christos sc->sc_nf_hist_cur = 0;
1895 1.1 christos }
1896 1.1 christos #endif /* notused */
1897 1.1 christos
1898 1.1 christos #ifdef notused
1899 1.1 christos Static void
1900 1.1 christos ar5008_bb_load_noisefloor(struct athn_softc *sc)
1901 1.1 christos {
1902 1.1 christos int16_t nf[AR_MAX_CHAINS], nf_ext[AR_MAX_CHAINS];
1903 1.1 christos int i, ntries;
1904 1.1 christos
1905 1.1 christos /* Write filtered noisefloor values. */
1906 1.1 christos for (i = 0; i < sc->sc_nrxchains; i++) {
1907 1.1 christos nf[i] = sc->sc_nf_priv[i] * 2;
1908 1.1 christos nf_ext[i] = sc->sc_nf_ext_priv[i] * 2;
1909 1.1 christos }
1910 1.1 christos ar5008_write_noisefloor(sc, nf, nf_ext);
1911 1.1 christos
1912 1.1 christos /* Load filtered noisefloor values into baseband. */
1913 1.1 christos AR_CLRBITS(sc, AR_PHY_AGC_CONTROL, AR_PHY_AGC_CONTROL_ENABLE_NF);
1914 1.1 christos AR_CLRBITS(sc, AR_PHY_AGC_CONTROL, AR_PHY_AGC_CONTROL_NO_UPDATE_NF);
1915 1.1 christos AR_SETBITS(sc, AR_PHY_AGC_CONTROL, AR_PHY_AGC_CONTROL_NF);
1916 1.1 christos /* Wait for load to complete. */
1917 1.1 christos for (ntries = 0; ntries < 1000; ntries++) {
1918 1.1 christos if (!(AR_READ(sc, AR_PHY_AGC_CONTROL) & AR_PHY_AGC_CONTROL_NF))
1919 1.1 christos break;
1920 1.1 christos DELAY(50);
1921 1.1 christos }
1922 1.1 christos if (ntries == 1000) {
1923 1.1 christos DPRINTFN(DBG_RF, sc, "failed to load noisefloor values\n");
1924 1.1 christos return;
1925 1.1 christos }
1926 1.1 christos
1927 1.1 christos /* Restore noisefloor values to initial (max) values. */
1928 1.1 christos for (i = 0; i < AR_MAX_CHAINS; i++)
1929 1.1 christos nf[i] = nf_ext[i] = -50 * 2;
1930 1.1 christos ar5008_write_noisefloor(sc, nf, nf_ext);
1931 1.1 christos }
1932 1.1 christos #endif /* notused */
1933 1.1 christos
1934 1.1 christos #ifdef notused
1935 1.1 christos Static void
1936 1.1 christos ar5008_noisefloor_calib(struct athn_softc *sc)
1937 1.1 christos {
1938 1.1 christos
1939 1.1 christos AR_SETBITS(sc, AR_PHY_AGC_CONTROL, AR_PHY_AGC_CONTROL_ENABLE_NF);
1940 1.1 christos AR_SETBITS(sc, AR_PHY_AGC_CONTROL, AR_PHY_AGC_CONTROL_NO_UPDATE_NF);
1941 1.1 christos AR_SETBITS(sc, AR_PHY_AGC_CONTROL, AR_PHY_AGC_CONTROL_NF);
1942 1.1 christos AR_WRITE_BARRIER(sc);
1943 1.1 christos }
1944 1.1 christos #endif /* notused */
1945 1.1 christos
1946 1.1 christos Static void
1947 1.1 christos ar5008_do_noisefloor_calib(struct athn_softc *sc)
1948 1.1 christos {
1949 1.1 christos
1950 1.1 christos AR_SETBITS(sc, AR_PHY_AGC_CONTROL, AR_PHY_AGC_CONTROL_NF);
1951 1.1 christos AR_WRITE_BARRIER(sc);
1952 1.1 christos }
1953 1.1 christos
1954 1.1 christos Static void
1955 1.1 christos ar5008_do_calib(struct athn_softc *sc)
1956 1.1 christos {
1957 1.1 christos uint32_t mode, reg;
1958 1.1 christos int log;
1959 1.1 christos
1960 1.1 christos reg = AR_READ(sc, AR_PHY_TIMING_CTRL4_0);
1961 1.1 christos log = AR_SREV_9280_10_OR_LATER(sc) ? 10 : 2;
1962 1.1 christos reg = RW(reg, AR_PHY_TIMING_CTRL4_IQCAL_LOG_COUNT_MAX, log);
1963 1.1 christos AR_WRITE(sc, AR_PHY_TIMING_CTRL4_0, reg);
1964 1.1 christos
1965 1.1 christos if (sc->sc_cur_calib_mask & ATHN_CAL_ADC_GAIN)
1966 1.1 christos mode = AR_PHY_CALMODE_ADC_GAIN;
1967 1.1 christos else if (sc->sc_cur_calib_mask & ATHN_CAL_ADC_DC)
1968 1.1 christos mode = AR_PHY_CALMODE_ADC_DC_PER;
1969 1.1 christos else /* ATHN_CAL_IQ */
1970 1.1 christos mode = AR_PHY_CALMODE_IQ;
1971 1.1 christos AR_WRITE(sc, AR_PHY_CALMODE, mode);
1972 1.1 christos
1973 1.1 christos DPRINTFN(DBG_RF, sc, "starting calibration mode=0x%x\n", mode);
1974 1.1 christos AR_SETBITS(sc, AR_PHY_TIMING_CTRL4_0, AR_PHY_TIMING_CTRL4_DO_CAL);
1975 1.1 christos AR_WRITE_BARRIER(sc);
1976 1.1 christos }
1977 1.1 christos
1978 1.1 christos Static void
1979 1.1 christos ar5008_next_calib(struct athn_softc *sc)
1980 1.1 christos {
1981 1.1 christos
1982 1.1 christos /* Check if we have any calibration in progress. */
1983 1.1 christos if (sc->sc_cur_calib_mask != 0) {
1984 1.1 christos if (!(AR_READ(sc, AR_PHY_TIMING_CTRL4_0) &
1985 1.1 christos AR_PHY_TIMING_CTRL4_DO_CAL)) {
1986 1.1 christos /* Calibration completed for current sample. */
1987 1.1 christos if (sc->sc_cur_calib_mask & ATHN_CAL_ADC_GAIN)
1988 1.1 christos ar5008_calib_adc_gain(sc);
1989 1.1 christos else if (sc->sc_cur_calib_mask & ATHN_CAL_ADC_DC)
1990 1.1 christos ar5008_calib_adc_dc_off(sc);
1991 1.1 christos else /* ATHN_CAL_IQ */
1992 1.1 christos ar5008_calib_iq(sc);
1993 1.1 christos }
1994 1.1 christos }
1995 1.1 christos }
1996 1.1 christos
1997 1.1 christos Static void
1998 1.1 christos ar5008_calib_iq(struct athn_softc *sc)
1999 1.1 christos {
2000 1.1 christos struct athn_iq_cal *cal;
2001 1.1 christos uint32_t reg, i_coff_denom, q_coff_denom;
2002 1.1 christos int32_t i_coff, q_coff;
2003 1.1 christos int i, iq_corr_neg;
2004 1.1 christos
2005 1.1 christos for (i = 0; i < AR_MAX_CHAINS; i++) {
2006 1.1 christos cal = &sc->sc_calib.iq[i];
2007 1.1 christos
2008 1.1 christos /* Accumulate IQ calibration measures (clear on read). */
2009 1.1 christos cal->pwr_meas_i += AR_READ(sc, AR_PHY_CAL_MEAS_0(i));
2010 1.1 christos cal->pwr_meas_q += AR_READ(sc, AR_PHY_CAL_MEAS_1(i));
2011 1.1 christos cal->iq_corr_meas +=
2012 1.1 christos (int32_t)AR_READ(sc, AR_PHY_CAL_MEAS_2(i));
2013 1.1 christos }
2014 1.1 christos if (!AR_SREV_9280_10_OR_LATER(sc) &&
2015 1.1 christos ++sc->sc_calib.nsamples < AR_CAL_SAMPLES) {
2016 1.1 christos /* Not enough samples accumulated, continue. */
2017 1.1 christos ar5008_do_calib(sc);
2018 1.1 christos return;
2019 1.1 christos }
2020 1.1 christos
2021 1.1 christos for (i = 0; i < sc->sc_nrxchains; i++) {
2022 1.1 christos cal = &sc->sc_calib.iq[i];
2023 1.1 christos
2024 1.1 christos if (cal->pwr_meas_q == 0)
2025 1.1 christos continue;
2026 1.1 christos
2027 1.1 christos if ((iq_corr_neg = cal->iq_corr_meas < 0))
2028 1.1 christos cal->iq_corr_meas = -cal->iq_corr_meas;
2029 1.1 christos
2030 1.1 christos i_coff_denom =
2031 1.1 christos (cal->pwr_meas_i / 2 + cal->pwr_meas_q / 2) / 128;
2032 1.1 christos q_coff_denom = cal->pwr_meas_q / 64;
2033 1.1 christos
2034 1.1 christos if (i_coff_denom == 0 || q_coff_denom == 0)
2035 1.1 christos continue; /* Prevents division by zero. */
2036 1.1 christos
2037 1.1 christos i_coff = cal->iq_corr_meas / i_coff_denom;
2038 1.1 christos q_coff = (cal->pwr_meas_i / q_coff_denom) - 64;
2039 1.1 christos
2040 1.1 christos /* Negate i_coff if iq_corr_meas is positive. */
2041 1.1 christos if (!iq_corr_neg)
2042 1.1 christos i_coff = 0x40 - (i_coff & 0x3f);
2043 1.1 christos if (q_coff > 15)
2044 1.1 christos q_coff = 15;
2045 1.1 christos else if (q_coff <= -16)
2046 1.1 christos q_coff = -16; /* XXX Linux has a bug here? */
2047 1.1 christos
2048 1.1 christos DPRINTFN(DBG_RF, sc, "IQ calibration for chain %d\n", i);
2049 1.1 christos reg = AR_READ(sc, AR_PHY_TIMING_CTRL4(i));
2050 1.1 christos reg = RW(reg, AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF, i_coff);
2051 1.1 christos reg = RW(reg, AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF, q_coff);
2052 1.1 christos AR_WRITE(sc, AR_PHY_TIMING_CTRL4(i), reg);
2053 1.1 christos }
2054 1.1 christos
2055 1.1 christos /* Apply new settings. */
2056 1.1 christos AR_SETBITS(sc, AR_PHY_TIMING_CTRL4_0,
2057 1.1 christos AR_PHY_TIMING_CTRL4_IQCORR_ENABLE);
2058 1.1 christos AR_WRITE_BARRIER(sc);
2059 1.1 christos
2060 1.1 christos /* IQ calibration done. */
2061 1.1 christos sc->sc_cur_calib_mask &= ~ATHN_CAL_IQ;
2062 1.1 christos memset(&sc->sc_calib, 0, sizeof(sc->sc_calib));
2063 1.1 christos }
2064 1.1 christos
2065 1.1 christos Static void
2066 1.1 christos ar5008_calib_adc_gain(struct athn_softc *sc)
2067 1.1 christos {
2068 1.1 christos struct athn_adc_cal *cal;
2069 1.1 christos uint32_t reg, gain_mismatch_i, gain_mismatch_q;
2070 1.1 christos int i;
2071 1.1 christos
2072 1.1 christos for (i = 0; i < AR_MAX_CHAINS; i++) {
2073 1.1 christos cal = &sc->sc_calib.adc_gain[i];
2074 1.1 christos
2075 1.1 christos /* Accumulate ADC gain measures (clear on read). */
2076 1.1 christos cal->pwr_meas_odd_i += AR_READ(sc, AR_PHY_CAL_MEAS_0(i));
2077 1.1 christos cal->pwr_meas_even_i += AR_READ(sc, AR_PHY_CAL_MEAS_1(i));
2078 1.1 christos cal->pwr_meas_odd_q += AR_READ(sc, AR_PHY_CAL_MEAS_2(i));
2079 1.1 christos cal->pwr_meas_even_q += AR_READ(sc, AR_PHY_CAL_MEAS_3(i));
2080 1.1 christos }
2081 1.1 christos if (!AR_SREV_9280_10_OR_LATER(sc) &&
2082 1.1 christos ++sc->sc_calib.nsamples < AR_CAL_SAMPLES) {
2083 1.1 christos /* Not enough samples accumulated, continue. */
2084 1.1 christos ar5008_do_calib(sc);
2085 1.1 christos return;
2086 1.1 christos }
2087 1.1 christos
2088 1.1 christos for (i = 0; i < sc->sc_nrxchains; i++) {
2089 1.1 christos cal = &sc->sc_calib.adc_gain[i];
2090 1.1 christos
2091 1.1 christos if (cal->pwr_meas_odd_i == 0 || cal->pwr_meas_even_q == 0)
2092 1.1 christos continue; /* Prevents division by zero. */
2093 1.1 christos
2094 1.1 christos gain_mismatch_i =
2095 1.1 christos (cal->pwr_meas_even_i * 32) / cal->pwr_meas_odd_i;
2096 1.1 christos gain_mismatch_q =
2097 1.1 christos (cal->pwr_meas_odd_q * 32) / cal->pwr_meas_even_q;
2098 1.1 christos
2099 1.1 christos DPRINTFN(DBG_RF, sc, "ADC gain calibration for chain %d\n", i);
2100 1.1 christos reg = AR_READ(sc, AR_PHY_NEW_ADC_DC_GAIN_CORR(i));
2101 1.1 christos reg = RW(reg, AR_PHY_NEW_ADC_DC_GAIN_IGAIN, gain_mismatch_i);
2102 1.1 christos reg = RW(reg, AR_PHY_NEW_ADC_DC_GAIN_QGAIN, gain_mismatch_q);
2103 1.1 christos AR_WRITE(sc, AR_PHY_NEW_ADC_DC_GAIN_CORR(i), reg);
2104 1.1 christos }
2105 1.1 christos
2106 1.1 christos /* Apply new settings. */
2107 1.1 christos AR_SETBITS(sc, AR_PHY_NEW_ADC_DC_GAIN_CORR(0),
2108 1.1 christos AR_PHY_NEW_ADC_GAIN_CORR_ENABLE);
2109 1.1 christos AR_WRITE_BARRIER(sc);
2110 1.1 christos
2111 1.1 christos /* ADC gain calibration done. */
2112 1.1 christos sc->sc_cur_calib_mask &= ~ATHN_CAL_ADC_GAIN;
2113 1.1 christos memset(&sc->sc_calib, 0, sizeof(sc->sc_calib));
2114 1.1 christos }
2115 1.1 christos
2116 1.1 christos Static void
2117 1.1 christos ar5008_calib_adc_dc_off(struct athn_softc *sc)
2118 1.1 christos {
2119 1.1 christos struct athn_adc_cal *cal;
2120 1.1 christos int32_t dc_offset_mismatch_i, dc_offset_mismatch_q;
2121 1.1 christos uint32_t reg;
2122 1.1 christos int count, i;
2123 1.1 christos
2124 1.1 christos for (i = 0; i < AR_MAX_CHAINS; i++) {
2125 1.1 christos cal = &sc->sc_calib.adc_dc_offset[i];
2126 1.1 christos
2127 1.1 christos /* Accumulate ADC DC offset measures (clear on read). */
2128 1.1 christos cal->pwr_meas_odd_i += AR_READ(sc, AR_PHY_CAL_MEAS_0(i));
2129 1.1 christos cal->pwr_meas_even_i += AR_READ(sc, AR_PHY_CAL_MEAS_1(i));
2130 1.1 christos cal->pwr_meas_odd_q += AR_READ(sc, AR_PHY_CAL_MEAS_2(i));
2131 1.1 christos cal->pwr_meas_even_q += AR_READ(sc, AR_PHY_CAL_MEAS_3(i));
2132 1.1 christos }
2133 1.1 christos if (!AR_SREV_9280_10_OR_LATER(sc) &&
2134 1.1 christos ++sc->sc_calib.nsamples < AR_CAL_SAMPLES) {
2135 1.1 christos /* Not enough samples accumulated, continue. */
2136 1.1 christos ar5008_do_calib(sc);
2137 1.1 christos return;
2138 1.1 christos }
2139 1.1 christos
2140 1.1 christos if (AR_SREV_9280_10_OR_LATER(sc))
2141 1.1 christos count = (1 << (10 + 5));
2142 1.1 christos else
2143 1.1 christos count = (1 << ( 2 + 5)) * AR_CAL_SAMPLES;
2144 1.1 christos for (i = 0; i < sc->sc_nrxchains; i++) {
2145 1.1 christos cal = &sc->sc_calib.adc_dc_offset[i];
2146 1.1 christos
2147 1.1 christos dc_offset_mismatch_i =
2148 1.1 christos (cal->pwr_meas_even_i - cal->pwr_meas_odd_i * 2) / count;
2149 1.1 christos dc_offset_mismatch_q =
2150 1.1 christos (cal->pwr_meas_odd_q - cal->pwr_meas_even_q * 2) / count;
2151 1.1 christos
2152 1.1 christos DPRINTFN(DBG_RF, sc, "ADC DC offset calibration for chain %d\n", i);
2153 1.1 christos reg = AR_READ(sc, AR_PHY_NEW_ADC_DC_GAIN_CORR(i));
2154 1.1 christos reg = RW(reg, AR_PHY_NEW_ADC_DC_GAIN_QDC,
2155 1.1 christos dc_offset_mismatch_q);
2156 1.1 christos reg = RW(reg, AR_PHY_NEW_ADC_DC_GAIN_IDC,
2157 1.1 christos dc_offset_mismatch_i);
2158 1.1 christos AR_WRITE(sc, AR_PHY_NEW_ADC_DC_GAIN_CORR(i), reg);
2159 1.1 christos }
2160 1.1 christos
2161 1.1 christos /* Apply new settings. */
2162 1.1 christos AR_SETBITS(sc, AR_PHY_NEW_ADC_DC_GAIN_CORR(0),
2163 1.1 christos AR_PHY_NEW_ADC_DC_OFFSET_CORR_ENABLE);
2164 1.1 christos AR_WRITE_BARRIER(sc);
2165 1.1 christos
2166 1.1 christos /* ADC DC offset calibration done. */
2167 1.1 christos sc->sc_cur_calib_mask &= ~ATHN_CAL_ADC_DC;
2168 1.1 christos memset(&sc->sc_calib, 0, sizeof(sc->sc_calib));
2169 1.1 christos }
2170 1.1 christos
2171 1.1 christos PUBLIC void
2172 1.1 christos ar5008_write_txpower(struct athn_softc *sc, int16_t power[ATHN_POWER_COUNT])
2173 1.1 christos {
2174 1.1 christos
2175 1.1 christos AR_WRITE(sc, AR_PHY_POWER_TX_RATE1,
2176 1.1 christos (power[ATHN_POWER_OFDM18 ] & 0x3f) << 24 |
2177 1.1 christos (power[ATHN_POWER_OFDM12 ] & 0x3f) << 16 |
2178 1.1 christos (power[ATHN_POWER_OFDM9 ] & 0x3f) << 8 |
2179 1.1 christos (power[ATHN_POWER_OFDM6 ] & 0x3f));
2180 1.1 christos AR_WRITE(sc, AR_PHY_POWER_TX_RATE2,
2181 1.1 christos (power[ATHN_POWER_OFDM54 ] & 0x3f) << 24 |
2182 1.1 christos (power[ATHN_POWER_OFDM48 ] & 0x3f) << 16 |
2183 1.1 christos (power[ATHN_POWER_OFDM36 ] & 0x3f) << 8 |
2184 1.1 christos (power[ATHN_POWER_OFDM24 ] & 0x3f));
2185 1.1 christos AR_WRITE(sc, AR_PHY_POWER_TX_RATE3,
2186 1.1 christos (power[ATHN_POWER_CCK2_SP ] & 0x3f) << 24 |
2187 1.1 christos (power[ATHN_POWER_CCK2_LP ] & 0x3f) << 16 |
2188 1.1 christos (power[ATHN_POWER_XR ] & 0x3f) << 8 |
2189 1.1 christos (power[ATHN_POWER_CCK1_LP ] & 0x3f));
2190 1.1 christos AR_WRITE(sc, AR_PHY_POWER_TX_RATE4,
2191 1.1 christos (power[ATHN_POWER_CCK11_SP] & 0x3f) << 24 |
2192 1.1 christos (power[ATHN_POWER_CCK11_LP] & 0x3f) << 16 |
2193 1.1 christos (power[ATHN_POWER_CCK55_SP] & 0x3f) << 8 |
2194 1.1 christos (power[ATHN_POWER_CCK55_LP] & 0x3f));
2195 1.1 christos #ifndef IEEE80211_NO_HT
2196 1.1 christos AR_WRITE(sc, AR_PHY_POWER_TX_RATE5,
2197 1.1 christos (power[ATHN_POWER_HT20(3) ] & 0x3f) << 24 |
2198 1.1 christos (power[ATHN_POWER_HT20(2) ] & 0x3f) << 16 |
2199 1.1 christos (power[ATHN_POWER_HT20(1) ] & 0x3f) << 8 |
2200 1.1 christos (power[ATHN_POWER_HT20(0) ] & 0x3f));
2201 1.1 christos AR_WRITE(sc, AR_PHY_POWER_TX_RATE6,
2202 1.1 christos (power[ATHN_POWER_HT20(7) ] & 0x3f) << 24 |
2203 1.1 christos (power[ATHN_POWER_HT20(6) ] & 0x3f) << 16 |
2204 1.1 christos (power[ATHN_POWER_HT20(5) ] & 0x3f) << 8 |
2205 1.1 christos (power[ATHN_POWER_HT20(4) ] & 0x3f));
2206 1.1 christos AR_WRITE(sc, AR_PHY_POWER_TX_RATE7,
2207 1.1 christos (power[ATHN_POWER_HT40(3) ] & 0x3f) << 24 |
2208 1.1 christos (power[ATHN_POWER_HT40(2) ] & 0x3f) << 16 |
2209 1.1 christos (power[ATHN_POWER_HT40(1) ] & 0x3f) << 8 |
2210 1.1 christos (power[ATHN_POWER_HT40(0) ] & 0x3f));
2211 1.1 christos AR_WRITE(sc, AR_PHY_POWER_TX_RATE8,
2212 1.1 christos (power[ATHN_POWER_HT40(7) ] & 0x3f) << 24 |
2213 1.1 christos (power[ATHN_POWER_HT40(6) ] & 0x3f) << 16 |
2214 1.1 christos (power[ATHN_POWER_HT40(5) ] & 0x3f) << 8 |
2215 1.1 christos (power[ATHN_POWER_HT40(4) ] & 0x3f));
2216 1.1 christos AR_WRITE(sc, AR_PHY_POWER_TX_RATE9,
2217 1.1 christos (power[ATHN_POWER_OFDM_EXT] & 0x3f) << 24 |
2218 1.1 christos (power[ATHN_POWER_CCK_EXT ] & 0x3f) << 16 |
2219 1.1 christos (power[ATHN_POWER_OFDM_DUP] & 0x3f) << 8 |
2220 1.1 christos (power[ATHN_POWER_CCK_DUP ] & 0x3f));
2221 1.1 christos #endif
2222 1.1 christos AR_WRITE_BARRIER(sc);
2223 1.1 christos }
2224 1.1 christos
2225 1.1 christos PUBLIC void
2226 1.1 christos ar5008_set_viterbi_mask(struct athn_softc *sc, int bin)
2227 1.1 christos {
2228 1.1 christos uint32_t mask[4], reg;
2229 1.1 christos uint8_t m[62], p[62]; /* XXX use bit arrays? */
2230 1.1 christos int i, bit, cur;
2231 1.1 christos
2232 1.1 christos /* Compute pilot mask. */
2233 1.1 christos cur = -6000;
2234 1.1 christos for (i = 0; i < 4; i++) {
2235 1.1 christos mask[i] = 0;
2236 1.1 christos for (bit = 0; bit < 30; bit++) {
2237 1.1 christos if (abs(cur - bin) < 100)
2238 1.1 christos mask[i] |= 1 << bit;
2239 1.1 christos cur += 100;
2240 1.1 christos }
2241 1.1 christos if (cur == 0) /* Skip entry "0". */
2242 1.1 christos cur = 100;
2243 1.1 christos }
2244 1.1 christos /* Write entries from -6000 to -3100. */
2245 1.1 christos AR_WRITE(sc, AR_PHY_TIMING7, mask[0]);
2246 1.1 christos AR_WRITE(sc, AR_PHY_TIMING9, mask[0]);
2247 1.1 christos /* Write entries from -3000 to -100. */
2248 1.1 christos AR_WRITE(sc, AR_PHY_TIMING8, mask[1]);
2249 1.1 christos AR_WRITE(sc, AR_PHY_TIMING10, mask[1]);
2250 1.1 christos /* Write entries from 100 to 3000. */
2251 1.1 christos AR_WRITE(sc, AR_PHY_PILOT_MASK_01_30, mask[2]);
2252 1.1 christos AR_WRITE(sc, AR_PHY_CHANNEL_MASK_01_30, mask[2]);
2253 1.1 christos /* Write entries from 3100 to 6000. */
2254 1.1 christos AR_WRITE(sc, AR_PHY_PILOT_MASK_31_60, mask[3]);
2255 1.1 christos AR_WRITE(sc, AR_PHY_CHANNEL_MASK_31_60, mask[3]);
2256 1.1 christos
2257 1.1 christos /* Compute viterbi mask. */
2258 1.1 christos for (cur = 6100; cur >= 0; cur -= 100)
2259 1.1 christos p[+cur / 100] = abs(cur - bin) < 75;
2260 1.1 christos for (cur = -100; cur >= -6100; cur -= 100)
2261 1.1 christos m[-cur / 100] = abs(cur - bin) < 75;
2262 1.1 christos
2263 1.1 christos /* Write viterbi mask (XXX needs to be reworked). */
2264 1.1 christos reg =
2265 1.1 christos m[46] << 30 | m[47] << 28 | m[48] << 26 | m[49] << 24 |
2266 1.1 christos m[50] << 22 | m[51] << 20 | m[52] << 18 | m[53] << 16 |
2267 1.1 christos m[54] << 14 | m[55] << 12 | m[56] << 10 | m[57] << 8 |
2268 1.1 christos m[58] << 6 | m[59] << 4 | m[60] << 2 | m[61] << 0;
2269 1.1 christos AR_WRITE(sc, AR_PHY_BIN_MASK_1, reg);
2270 1.1 christos AR_WRITE(sc, AR_PHY_VIT_MASK2_M_46_61, reg);
2271 1.1 christos
2272 1.1 christos /* XXX m[48] should be m[38] ? */
2273 1.1 christos reg = m[31] << 28 | m[32] << 26 | m[33] << 24 |
2274 1.1 christos m[34] << 22 | m[35] << 20 | m[36] << 18 | m[37] << 16 |
2275 1.1 christos m[48] << 14 | m[39] << 12 | m[40] << 10 | m[41] << 8 |
2276 1.1 christos m[42] << 6 | m[43] << 4 | m[44] << 2 | m[45] << 0;
2277 1.1 christos AR_WRITE(sc, AR_PHY_BIN_MASK_2, reg);
2278 1.1 christos AR_WRITE(sc, AR_PHY_VIT_MASK2_M_31_45, reg);
2279 1.1 christos
2280 1.1 christos /* XXX This one is weird too. */
2281 1.1 christos reg =
2282 1.1 christos m[16] << 30 | m[16] << 28 | m[18] << 26 | m[18] << 24 |
2283 1.1 christos m[20] << 22 | m[20] << 20 | m[22] << 18 | m[22] << 16 |
2284 1.1 christos m[24] << 14 | m[24] << 12 | m[25] << 10 | m[26] << 8 |
2285 1.1 christos m[27] << 6 | m[28] << 4 | m[29] << 2 | m[30] << 0;
2286 1.1 christos AR_WRITE(sc, AR_PHY_BIN_MASK_3, reg);
2287 1.1 christos AR_WRITE(sc, AR_PHY_VIT_MASK2_M_16_30, reg);
2288 1.1 christos
2289 1.1 christos reg =
2290 1.1 christos m[ 0] << 30 | m[ 1] << 28 | m[ 2] << 26 | m[ 3] << 24 |
2291 1.1 christos m[ 4] << 22 | m[ 5] << 20 | m[ 6] << 18 | m[ 7] << 16 |
2292 1.1 christos m[ 8] << 14 | m[ 9] << 12 | m[10] << 10 | m[11] << 8 |
2293 1.1 christos m[12] << 6 | m[13] << 4 | m[14] << 2 | m[15] << 0;
2294 1.1 christos AR_WRITE(sc, AR_PHY_MASK_CTL, reg);
2295 1.1 christos AR_WRITE(sc, AR_PHY_VIT_MASK2_M_00_15, reg);
2296 1.1 christos
2297 1.1 christos reg = p[15] << 28 | p[14] << 26 | p[13] << 24 |
2298 1.1 christos p[12] << 22 | p[11] << 20 | p[10] << 18 | p[ 9] << 16 |
2299 1.1 christos p[ 8] << 14 | p[ 7] << 12 | p[ 6] << 10 | p[ 5] << 8 |
2300 1.1 christos p[ 4] << 6 | p[ 3] << 4 | p[ 2] << 2 | p[ 1] << 0;
2301 1.1 christos AR_WRITE(sc, AR_PHY_BIN_MASK2_1, reg);
2302 1.1 christos AR_WRITE(sc, AR_PHY_VIT_MASK2_P_15_01, reg);
2303 1.1 christos
2304 1.1 christos reg = p[30] << 28 | p[29] << 26 | p[28] << 24 |
2305 1.1 christos p[27] << 22 | p[26] << 20 | p[25] << 18 | p[24] << 16 |
2306 1.1 christos p[23] << 14 | p[22] << 12 | p[21] << 10 | p[20] << 8 |
2307 1.1 christos p[19] << 6 | p[18] << 4 | p[17] << 2 | p[16] << 0;
2308 1.1 christos AR_WRITE(sc, AR_PHY_BIN_MASK2_2, reg);
2309 1.1 christos AR_WRITE(sc, AR_PHY_VIT_MASK2_P_30_16, reg);
2310 1.1 christos
2311 1.1 christos reg = p[45] << 28 | p[44] << 26 | p[43] << 24 |
2312 1.1 christos p[42] << 22 | p[41] << 20 | p[40] << 18 | p[39] << 16 |
2313 1.1 christos p[38] << 14 | p[37] << 12 | p[36] << 10 | p[35] << 8 |
2314 1.1 christos p[34] << 6 | p[33] << 4 | p[32] << 2 | p[31] << 0;
2315 1.1 christos AR_WRITE(sc, AR_PHY_BIN_MASK2_3, reg);
2316 1.1 christos AR_WRITE(sc, AR_PHY_VIT_MASK2_P_45_31, reg);
2317 1.1 christos
2318 1.1 christos reg =
2319 1.1 christos p[61] << 30 | p[60] << 28 | p[59] << 26 | p[58] << 24 |
2320 1.1 christos p[57] << 22 | p[56] << 20 | p[55] << 18 | p[54] << 16 |
2321 1.1 christos p[53] << 14 | p[52] << 12 | p[51] << 10 | p[50] << 8 |
2322 1.1 christos p[49] << 6 | p[48] << 4 | p[47] << 2 | p[46] << 0;
2323 1.1 christos AR_WRITE(sc, AR_PHY_BIN_MASK2_4, reg);
2324 1.1 christos AR_WRITE(sc, AR_PHY_VIT_MASK2_P_61_46, reg);
2325 1.1 christos AR_WRITE_BARRIER(sc);
2326 1.1 christos }
2327 1.1 christos
2328 1.1 christos Static void
2329 1.1 christos ar5008_hw_init(struct athn_softc *sc, struct ieee80211_channel *c,
2330 1.1 christos struct ieee80211_channel *extc)
2331 1.1 christos {
2332 1.1 christos struct athn_ops *ops = &sc->sc_ops;
2333 1.1 christos const struct athn_ini *ini = sc->sc_ini;
2334 1.1 christos const uint32_t *pvals;
2335 1.1 christos uint32_t reg;
2336 1.1 christos int i;
2337 1.1 christos
2338 1.1 christos AR_WRITE(sc, AR_PHY(0), 0x00000007);
2339 1.1 christos AR_WRITE(sc, AR_PHY_ADC_SERIAL_CTL, AR_PHY_SEL_EXTERNAL_RADIO);
2340 1.1 christos
2341 1.1 christos if (!AR_SINGLE_CHIP(sc))
2342 1.1 christos ar5416_reset_addac(sc, c);
2343 1.1 christos
2344 1.1 christos AR_WRITE(sc, AR_PHY_ADC_SERIAL_CTL, AR_PHY_SEL_INTERNAL_ADDAC);
2345 1.1 christos
2346 1.1 christos /* First initialization step (depends on channel band/bandwidth). */
2347 1.1 christos #ifndef IEEE80211_NO_HT
2348 1.1 christos if (extc != NULL) {
2349 1.1 christos if (IEEE80211_IS_CHAN_2GHZ(c))
2350 1.1 christos pvals = ini->vals_2g40;
2351 1.1 christos else
2352 1.1 christos pvals = ini->vals_5g40;
2353 1.1 christos }
2354 1.1 christos else
2355 1.1 christos #endif
2356 1.1 christos {
2357 1.1 christos if (IEEE80211_IS_CHAN_2GHZ(c))
2358 1.1 christos pvals = ini->vals_2g20;
2359 1.1 christos else
2360 1.1 christos pvals = ini->vals_5g20;
2361 1.1 christos }
2362 1.1 christos DPRINTFN(DBG_INIT, sc, "writing modal init vals\n");
2363 1.1 christos for (i = 0; i < ini->nregs; i++) {
2364 1.1 christos uint32_t val = pvals[i];
2365 1.1 christos
2366 1.1 christos /* Fix AR_AN_TOP2 initialization value if required. */
2367 1.1 christos if (ini->regs[i] == AR_AN_TOP2 &&
2368 1.1 christos (sc->sc_flags & ATHN_FLAG_AN_TOP2_FIXUP))
2369 1.1 christos val &= ~AR_AN_TOP2_PWDCLKIND;
2370 1.1 christos AR_WRITE(sc, ini->regs[i], val);
2371 1.1 christos if (AR_IS_ANALOG_REG(ini->regs[i])) {
2372 1.1 christos AR_WRITE_BARRIER(sc);
2373 1.1 christos DELAY(100);
2374 1.1 christos }
2375 1.1 christos if ((i & 0x1f) == 0)
2376 1.1 christos DELAY(1);
2377 1.1 christos }
2378 1.1 christos AR_WRITE_BARRIER(sc);
2379 1.1 christos
2380 1.1 christos if (sc->sc_rx_gain != NULL)
2381 1.1 christos ar9280_reset_rx_gain(sc, c);
2382 1.1 christos if (sc->sc_tx_gain != NULL)
2383 1.1 christos ar9280_reset_tx_gain(sc, c);
2384 1.1 christos
2385 1.1 christos if (AR_SREV_9271_10(sc)) {
2386 1.1 christos AR_WRITE(sc, AR_PHY(68), 0x30002311);
2387 1.1 christos AR_WRITE(sc, AR_PHY_RF_CTL3, 0x0a020001);
2388 1.1 christos }
2389 1.1 christos AR_WRITE_BARRIER(sc);
2390 1.1 christos
2391 1.1 christos /* Second initialization step (common to all channels). */
2392 1.1 christos DPRINTFN(DBG_INIT, sc, "writing common init vals\n");
2393 1.1 christos for (i = 0; i < ini->ncmregs; i++) {
2394 1.1 christos AR_WRITE(sc, ini->cmregs[i], ini->cmvals[i]);
2395 1.1 christos if (AR_IS_ANALOG_REG(ini->cmregs[i])) {
2396 1.1 christos AR_WRITE_BARRIER(sc);
2397 1.1 christos DELAY(100);
2398 1.1 christos }
2399 1.1 christos if ((i & 0x1f) == 0)
2400 1.1 christos DELAY(1);
2401 1.1 christos }
2402 1.1 christos AR_WRITE_BARRIER(sc);
2403 1.1 christos
2404 1.1 christos if (!AR_SINGLE_CHIP(sc))
2405 1.1 christos ar5416_reset_bb_gain(sc, c);
2406 1.1 christos
2407 1.1 christos if (IEEE80211_IS_CHAN_5GHZ(c) &&
2408 1.1 christos (sc->sc_flags & ATHN_FLAG_FAST_PLL_CLOCK)) {
2409 1.1 christos /* Update modal values for fast PLL clock. */
2410 1.1 christos #ifndef IEEE80211_NO_HT
2411 1.1 christos if (extc != NULL)
2412 1.1 christos pvals = ini->fastvals_5g40;
2413 1.1 christos else
2414 1.1 christos #endif
2415 1.1 christos pvals = ini->fastvals_5g20;
2416 1.1 christos DPRINTFN(DBG_INIT, sc, "writing fast pll clock init vals\n");
2417 1.1 christos for (i = 0; i < ini->nfastregs; i++) {
2418 1.1 christos AR_WRITE(sc, ini->fastregs[i], pvals[i]);
2419 1.1 christos if (AR_IS_ANALOG_REG(ini->fastregs[i])) {
2420 1.1 christos AR_WRITE_BARRIER(sc);
2421 1.1 christos DELAY(100);
2422 1.1 christos }
2423 1.1 christos if ((i & 0x1f) == 0)
2424 1.1 christos DELAY(1);
2425 1.1 christos }
2426 1.1 christos }
2427 1.1 christos
2428 1.1 christos /*
2429 1.1 christos * Set the RX_ABORT and RX_DIS bits to prevent frames with corrupted
2430 1.1 christos * descriptor status.
2431 1.1 christos */
2432 1.1 christos AR_SETBITS(sc, AR_DIAG_SW, AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT);
2433 1.1 christos
2434 1.1 christos /* Hardware workarounds for occasional Rx data corruption. */
2435 1.1 christos if (AR_SREV_9280_10_OR_LATER(sc)) {
2436 1.1 christos reg = AR_READ(sc, AR_PCU_MISC_MODE2);
2437 1.1 christos if (!AR_SREV_9271(sc))
2438 1.1 christos reg &= ~AR_PCU_MISC_MODE2_HWWAR1;
2439 1.1 christos if (AR_SREV_9287_10_OR_LATER(sc))
2440 1.1 christos reg &= ~AR_PCU_MISC_MODE2_HWWAR2;
2441 1.1 christos AR_WRITE(sc, AR_PCU_MISC_MODE2, reg);
2442 1.1 christos
2443 1.1 christos }
2444 1.1 christos else if (AR_SREV_5416_20_OR_LATER(sc)) {
2445 1.1 christos /* Disable baseband clock gating. */
2446 1.1 christos AR_WRITE(sc, AR_PHY(651), 0x11);
2447 1.1 christos
2448 1.1 christos if (AR_SREV_9160(sc)) {
2449 1.1 christos /* Disable RIFS search to fix baseband hang. */
2450 1.1 christos AR_CLRBITS(sc, AR_PHY_HEAVY_CLIP_FACTOR_RIFS,
2451 1.1 christos AR_PHY_RIFS_INIT_DELAY_M);
2452 1.1 christos }
2453 1.1 christos }
2454 1.1 christos AR_WRITE_BARRIER(sc);
2455 1.1 christos
2456 1.1 christos ar5008_set_phy(sc, c, extc);
2457 1.1 christos ar5008_init_chains(sc);
2458 1.1 christos
2459 1.1 christos if (sc->sc_flags & ATHN_FLAG_OLPC) {
2460 1.1 christos extern int ticks;
2461 1.1 christos sc->sc_olpc_ticks = ticks;
2462 1.1 christos ops->olpc_init(sc);
2463 1.1 christos }
2464 1.1 christos
2465 1.1 christos ops->set_txpower(sc, c, extc);
2466 1.1 christos
2467 1.1 christos if (!AR_SINGLE_CHIP(sc))
2468 1.1 christos ar5416_rf_reset(sc, c);
2469 1.1 christos }
2470 1.1 christos
2471 1.1 christos Static uint8_t
2472 1.1 christos ar5008_get_vpd(uint8_t pwr, const uint8_t *pwrPdg, const uint8_t *vpdPdg,
2473 1.1 christos int nicepts)
2474 1.1 christos {
2475 1.1 christos uint8_t vpd;
2476 1.1 christos int i, lo, hi;
2477 1.1 christos
2478 1.1 christos for (i = 0; i < nicepts; i++)
2479 1.1 christos if (pwrPdg[i] > pwr)
2480 1.1 christos break;
2481 1.1 christos hi = i;
2482 1.1 christos lo = hi - 1;
2483 1.1 christos if (lo == -1)
2484 1.1 christos lo = hi;
2485 1.1 christos else if (hi == nicepts)
2486 1.1 christos hi = lo;
2487 1.1 christos
2488 1.1 christos vpd = athn_interpolate(pwr, pwrPdg[lo], vpdPdg[lo],
2489 1.1 christos pwrPdg[hi], vpdPdg[hi]);
2490 1.1 christos return vpd;
2491 1.1 christos }
2492 1.1 christos
2493 1.1 christos PUBLIC void
2494 1.1 christos ar5008_get_pdadcs(struct athn_softc *sc, uint8_t fbin,
2495 1.1 christos struct athn_pier *lopier, struct athn_pier *hipier, int nxpdgains,
2496 1.1 christos int nicepts, uint8_t overlap, uint8_t *boundaries, uint8_t *pdadcs)
2497 1.1 christos {
2498 1.1 christos #define DB(x) ((x) / 2) /* Convert half dB to dB. */
2499 1.1 christos uint8_t minpwr[AR_PD_GAINS_IN_MASK], maxpwr[AR_PD_GAINS_IN_MASK];
2500 1.1 christos uint8_t vpd[AR_MAX_PWR_RANGE_IN_HALF_DB], pwr;
2501 1.1 christos uint8_t lovpd, hivpd, boundary;
2502 1.1 christos int16_t ss, delta, vpdstep, val;
2503 1.1 christos int i, j, npdadcs, nvpds, maxidx, tgtidx;
2504 1.1 christos
2505 1.1 christos /* Compute min and max power in half dB for each pdGain. */
2506 1.1 christos for (i = 0; i < nxpdgains; i++) {
2507 1.1 christos minpwr[i] = MAX(lopier->pwr[i][0], hipier->pwr[i][0]);
2508 1.1 christos maxpwr[i] = MIN(lopier->pwr[i][nicepts - 1],
2509 1.1 christos hipier->pwr[i][nicepts - 1]);
2510 1.1 christos }
2511 1.1 christos
2512 1.1 christos /* Fill phase domain analog-to-digital converter (PDADC) table. */
2513 1.1 christos npdadcs = 0;
2514 1.1 christos for (i = 0; i < nxpdgains; i++) {
2515 1.1 christos if (i != nxpdgains - 1)
2516 1.1 christos boundaries[i] = DB(maxpwr[i] + minpwr[i + 1]) / 2;
2517 1.1 christos else
2518 1.1 christos boundaries[i] = DB(maxpwr[i]);
2519 1.1 christos if (boundaries[i] > AR_MAX_RATE_POWER)
2520 1.1 christos boundaries[i] = AR_MAX_RATE_POWER;
2521 1.1 christos
2522 1.1 christos if (i == 0 && !AR_SREV_5416_20_OR_LATER(sc)) {
2523 1.1 christos /* Fix the gain delta (AR5416 1.0 only). */
2524 1.1 christos delta = boundaries[0] - 23;
2525 1.1 christos boundaries[0] = 23;
2526 1.1 christos }
2527 1.1 christos else
2528 1.1 christos delta = 0;
2529 1.1 christos
2530 1.1 christos /* Find starting index for this pdGain. */
2531 1.1 christos if (i != 0) {
2532 1.1 christos ss = boundaries[i - 1] - DB(minpwr[i]) -
2533 1.1 christos overlap + 1 + delta;
2534 1.1 christos }
2535 1.1 christos else if (AR_SREV_9280_10_OR_LATER(sc))
2536 1.1 christos ss = -DB(minpwr[i]);
2537 1.1 christos else
2538 1.1 christos ss = 0;
2539 1.1 christos
2540 1.1 christos /* Compute Vpd table for this pdGain. */
2541 1.1 christos nvpds = DB(maxpwr[i] - minpwr[i]) + 1;
2542 1.1 christos memset(vpd, 0, sizeof(vpd));
2543 1.1 christos pwr = minpwr[i];
2544 1.1 christos for (j = 0; j < nvpds; j++) {
2545 1.1 christos /* Get lower and higher Vpd. */
2546 1.1 christos lovpd = ar5008_get_vpd(pwr, lopier->pwr[i],
2547 1.1 christos lopier->vpd[i], nicepts);
2548 1.1 christos hivpd = ar5008_get_vpd(pwr, hipier->pwr[i],
2549 1.1 christos hipier->vpd[i], nicepts);
2550 1.1 christos
2551 1.1 christos /* Interpolate the final Vpd. */
2552 1.1 christos vpd[j] = athn_interpolate(fbin,
2553 1.1 christos lopier->fbin, lovpd, hipier->fbin, hivpd);
2554 1.1 christos
2555 1.1 christos pwr += 2; /* In half dB. */
2556 1.1 christos }
2557 1.1 christos
2558 1.1 christos /* Extrapolate data for ss < 0. */
2559 1.1 christos if (vpd[1] > vpd[0])
2560 1.1 christos vpdstep = vpd[1] - vpd[0];
2561 1.1 christos else
2562 1.1 christos vpdstep = 1;
2563 1.1 christos while (ss < 0 && npdadcs < AR_NUM_PDADC_VALUES - 1) {
2564 1.1 christos val = vpd[0] + ss * vpdstep;
2565 1.1 christos pdadcs[npdadcs++] = MAX(val, 0);
2566 1.1 christos ss++;
2567 1.1 christos }
2568 1.1 christos
2569 1.1 christos tgtidx = boundaries[i] + overlap - DB(minpwr[i]);
2570 1.1 christos maxidx = MIN(tgtidx, nvpds);
2571 1.1 christos while (ss < maxidx && npdadcs < AR_NUM_PDADC_VALUES - 1)
2572 1.1 christos pdadcs[npdadcs++] = vpd[ss++];
2573 1.1 christos
2574 1.1 christos if (tgtidx < maxidx)
2575 1.1 christos continue;
2576 1.1 christos
2577 1.1 christos /* Extrapolate data for maxidx <= ss <= tgtidx. */
2578 1.1 christos if (vpd[nvpds - 1] > vpd[nvpds - 2])
2579 1.1 christos vpdstep = vpd[nvpds - 1] - vpd[nvpds - 2];
2580 1.1 christos else
2581 1.1 christos vpdstep = 1;
2582 1.1 christos while (ss <= tgtidx && npdadcs < AR_NUM_PDADC_VALUES - 1) {
2583 1.1 christos val = vpd[nvpds - 1] + (ss - maxidx + 1) * vpdstep;
2584 1.1 christos pdadcs[npdadcs++] = MIN(val, 255);
2585 1.1 christos ss++;
2586 1.1 christos }
2587 1.1 christos }
2588 1.1 christos
2589 1.1 christos /* Fill remaining PDADC and boundaries entries. */
2590 1.1 christos if (AR_SREV_9285(sc))
2591 1.1 christos boundary = AR9285_PD_GAIN_BOUNDARY_DEFAULT;
2592 1.1 christos else /* Fill with latest. */
2593 1.1 christos boundary = boundaries[nxpdgains - 1];
2594 1.1 christos
2595 1.1 christos for (; nxpdgains < AR_PD_GAINS_IN_MASK; nxpdgains++)
2596 1.1 christos boundaries[nxpdgains] = boundary;
2597 1.1 christos
2598 1.1 christos for (; npdadcs < AR_NUM_PDADC_VALUES; npdadcs++)
2599 1.1 christos pdadcs[npdadcs] = pdadcs[npdadcs - 1];
2600 1.1 christos #undef DB
2601 1.1 christos }
2602 1.1 christos
2603 1.1 christos PUBLIC void
2604 1.1 christos ar5008_get_lg_tpow(struct athn_softc *sc, struct ieee80211_channel *c,
2605 1.1 christos uint8_t ctl, const struct ar_cal_target_power_leg *tgt, int nchans,
2606 1.1 christos uint8_t tpow[4])
2607 1.1 christos {
2608 1.1 christos uint8_t fbin;
2609 1.1 christos int i, lo, hi;
2610 1.1 christos
2611 1.1 christos /* Find interval (lower and upper indices). */
2612 1.1 christos fbin = athn_chan2fbin(c);
2613 1.1 christos for (i = 0; i < nchans; i++) {
2614 1.1 christos if (tgt[i].bChannel == AR_BCHAN_UNUSED ||
2615 1.1 christos tgt[i].bChannel > fbin)
2616 1.1 christos break;
2617 1.1 christos }
2618 1.1 christos hi = i;
2619 1.1 christos lo = hi - 1;
2620 1.1 christos if (lo == -1)
2621 1.1 christos lo = hi;
2622 1.1 christos else if (hi == nchans || tgt[hi].bChannel == AR_BCHAN_UNUSED)
2623 1.1 christos hi = lo;
2624 1.1 christos
2625 1.1 christos /* Interpolate values. */
2626 1.1 christos for (i = 0; i < 4; i++) {
2627 1.1 christos tpow[i] = athn_interpolate(fbin,
2628 1.1 christos tgt[lo].bChannel, tgt[lo].tPow2x[i],
2629 1.1 christos tgt[hi].bChannel, tgt[hi].tPow2x[i]);
2630 1.1 christos }
2631 1.1 christos /* XXX Apply conformance testing limit. */
2632 1.1 christos }
2633 1.1 christos
2634 1.1 christos #ifndef IEEE80211_NO_HT
2635 1.1 christos PUBLIC void
2636 1.1 christos ar5008_get_ht_tpow(struct athn_softc *sc, struct ieee80211_channel *c,
2637 1.1 christos uint8_t ctl, const struct ar_cal_target_power_ht *tgt, int nchans,
2638 1.1 christos uint8_t tpow[8])
2639 1.1 christos {
2640 1.1 christos uint8_t fbin;
2641 1.1 christos int i, lo, hi;
2642 1.1 christos
2643 1.1 christos /* Find interval (lower and upper indices). */
2644 1.1 christos fbin = athn_chan2fbin(c);
2645 1.1 christos for (i = 0; i < nchans; i++) {
2646 1.1 christos if (tgt[i].bChannel == AR_BCHAN_UNUSED ||
2647 1.1 christos tgt[i].bChannel > fbin)
2648 1.1 christos break;
2649 1.1 christos }
2650 1.1 christos hi = i;
2651 1.1 christos lo = hi - 1;
2652 1.1 christos if (lo == -1)
2653 1.1 christos lo = hi;
2654 1.1 christos else if (hi == nchans || tgt[hi].bChannel == AR_BCHAN_UNUSED)
2655 1.1 christos hi = lo;
2656 1.1 christos
2657 1.1 christos /* Interpolate values. */
2658 1.1 christos for (i = 0; i < 8; i++) {
2659 1.1 christos tpow[i] = athn_interpolate(fbin,
2660 1.1 christos tgt[lo].bChannel, tgt[lo].tPow2x[i],
2661 1.1 christos tgt[hi].bChannel, tgt[hi].tPow2x[i]);
2662 1.1 christos }
2663 1.1 christos /* XXX Apply conformance testing limit. */
2664 1.1 christos }
2665 1.1 christos #endif
2666 1.1 christos
2667 1.1 christos /*
2668 1.1 christos * Adaptive noise immunity.
2669 1.1 christos */
2670 1.1 christos Static void
2671 1.1 christos ar5008_set_noise_immunity_level(struct athn_softc *sc, int level)
2672 1.1 christos {
2673 1.1 christos int high = level == 4;
2674 1.1 christos uint32_t reg;
2675 1.1 christos
2676 1.1 christos reg = AR_READ(sc, AR_PHY_DESIRED_SZ);
2677 1.1 christos reg = RW(reg, AR_PHY_DESIRED_SZ_TOT_DES, high ? -62 : -55);
2678 1.1 christos AR_WRITE(sc, AR_PHY_DESIRED_SZ, reg);
2679 1.1 christos
2680 1.1 christos reg = AR_READ(sc, AR_PHY_AGC_CTL1);
2681 1.1 christos reg = RW(reg, AR_PHY_AGC_CTL1_COARSE_LOW, high ? -70 : -64);
2682 1.1 christos reg = RW(reg, AR_PHY_AGC_CTL1_COARSE_HIGH, high ? -12 : -14);
2683 1.1 christos AR_WRITE(sc, AR_PHY_AGC_CTL1, reg);
2684 1.1 christos
2685 1.1 christos reg = AR_READ(sc, AR_PHY_FIND_SIG);
2686 1.1 christos reg = RW(reg, AR_PHY_FIND_SIG_FIRPWR, high ? -80 : -78);
2687 1.1 christos AR_WRITE(sc, AR_PHY_FIND_SIG, reg);
2688 1.1 christos
2689 1.1 christos AR_WRITE_BARRIER(sc);
2690 1.1 christos }
2691 1.1 christos
2692 1.1 christos Static void
2693 1.1 christos ar5008_enable_ofdm_weak_signal(struct athn_softc *sc)
2694 1.1 christos {
2695 1.1 christos uint32_t reg;
2696 1.1 christos
2697 1.1 christos reg = AR_READ(sc, AR_PHY_SFCORR_LOW);
2698 1.1 christos reg = RW(reg, AR_PHY_SFCORR_LOW_M1_THRESH_LOW, 50);
2699 1.1 christos reg = RW(reg, AR_PHY_SFCORR_LOW_M2_THRESH_LOW, 40);
2700 1.1 christos reg = RW(reg, AR_PHY_SFCORR_LOW_M2COUNT_THR_LOW, 48);
2701 1.1 christos AR_WRITE(sc, AR_PHY_SFCORR_LOW, reg);
2702 1.1 christos
2703 1.1 christos reg = AR_READ(sc, AR_PHY_SFCORR);
2704 1.1 christos reg = RW(reg, AR_PHY_SFCORR_M1_THRESH, 77);
2705 1.1 christos reg = RW(reg, AR_PHY_SFCORR_M2_THRESH, 64);
2706 1.1 christos reg = RW(reg, AR_PHY_SFCORR_M2COUNT_THR, 16);
2707 1.1 christos AR_WRITE(sc, AR_PHY_SFCORR, reg);
2708 1.1 christos
2709 1.1 christos reg = AR_READ(sc, AR_PHY_SFCORR_EXT);
2710 1.1 christos reg = RW(reg, AR_PHY_SFCORR_EXT_M1_THRESH_LOW, 50);
2711 1.1 christos reg = RW(reg, AR_PHY_SFCORR_EXT_M2_THRESH_LOW, 40);
2712 1.1 christos reg = RW(reg, AR_PHY_SFCORR_EXT_M1_THRESH, 77);
2713 1.1 christos reg = RW(reg, AR_PHY_SFCORR_EXT_M2_THRESH, 64);
2714 1.1 christos AR_WRITE(sc, AR_PHY_SFCORR_EXT, reg);
2715 1.1 christos
2716 1.1 christos AR_SETBITS(sc, AR_PHY_SFCORR_LOW,
2717 1.1 christos AR_PHY_SFCORR_LOW_USE_SELF_CORR_LOW);
2718 1.1 christos AR_WRITE_BARRIER(sc);
2719 1.1 christos }
2720 1.1 christos
2721 1.1 christos Static void
2722 1.1 christos ar5008_disable_ofdm_weak_signal(struct athn_softc *sc)
2723 1.1 christos {
2724 1.1 christos uint32_t reg;
2725 1.1 christos
2726 1.1 christos reg = AR_READ(sc, AR_PHY_SFCORR_LOW);
2727 1.1 christos reg = RW(reg, AR_PHY_SFCORR_LOW_M1_THRESH_LOW, 127);
2728 1.1 christos reg = RW(reg, AR_PHY_SFCORR_LOW_M2_THRESH_LOW, 127);
2729 1.1 christos reg = RW(reg, AR_PHY_SFCORR_LOW_M2COUNT_THR_LOW, 63);
2730 1.1 christos AR_WRITE(sc, AR_PHY_SFCORR_LOW, reg);
2731 1.1 christos
2732 1.1 christos reg = AR_READ(sc, AR_PHY_SFCORR);
2733 1.1 christos reg = RW(reg, AR_PHY_SFCORR_M1_THRESH, 127);
2734 1.1 christos reg = RW(reg, AR_PHY_SFCORR_M2_THRESH, 127);
2735 1.1 christos reg = RW(reg, AR_PHY_SFCORR_M2COUNT_THR, 31);
2736 1.1 christos AR_WRITE(sc, AR_PHY_SFCORR, reg);
2737 1.1 christos
2738 1.1 christos reg = AR_READ(sc, AR_PHY_SFCORR_EXT);
2739 1.1 christos reg = RW(reg, AR_PHY_SFCORR_EXT_M1_THRESH_LOW, 127);
2740 1.1 christos reg = RW(reg, AR_PHY_SFCORR_EXT_M2_THRESH_LOW, 127);
2741 1.1 christos reg = RW(reg, AR_PHY_SFCORR_EXT_M1_THRESH, 127);
2742 1.1 christos reg = RW(reg, AR_PHY_SFCORR_EXT_M2_THRESH, 127);
2743 1.1 christos AR_WRITE(sc, AR_PHY_SFCORR_EXT, reg);
2744 1.1 christos
2745 1.1 christos AR_CLRBITS(sc, AR_PHY_SFCORR_LOW,
2746 1.1 christos AR_PHY_SFCORR_LOW_USE_SELF_CORR_LOW);
2747 1.1 christos AR_WRITE_BARRIER(sc);
2748 1.1 christos }
2749 1.1 christos
2750 1.1 christos Static void
2751 1.1 christos ar5008_set_cck_weak_signal(struct athn_softc *sc, int high)
2752 1.1 christos {
2753 1.1 christos uint32_t reg;
2754 1.1 christos
2755 1.1 christos reg = AR_READ(sc, AR_PHY_CCK_DETECT);
2756 1.1 christos reg = RW(reg, AR_PHY_CCK_DETECT_WEAK_SIG_THR_CCK, high ? 6 : 8);
2757 1.1 christos AR_WRITE(sc, AR_PHY_CCK_DETECT, reg);
2758 1.1 christos AR_WRITE_BARRIER(sc);
2759 1.1 christos }
2760 1.1 christos
2761 1.1 christos Static void
2762 1.1 christos ar5008_set_firstep_level(struct athn_softc *sc, int level)
2763 1.1 christos {
2764 1.1 christos uint32_t reg;
2765 1.1 christos
2766 1.1 christos reg = AR_READ(sc, AR_PHY_FIND_SIG);
2767 1.1 christos reg = RW(reg, AR_PHY_FIND_SIG_FIRSTEP, level * 4);
2768 1.1 christos AR_WRITE(sc, AR_PHY_FIND_SIG, reg);
2769 1.1 christos AR_WRITE_BARRIER(sc);
2770 1.1 christos }
2771 1.1 christos
2772 1.1 christos Static void
2773 1.1 christos ar5008_set_spur_immunity_level(struct athn_softc *sc, int level)
2774 1.1 christos {
2775 1.1 christos uint32_t reg;
2776 1.1 christos
2777 1.1 christos reg = AR_READ(sc, AR_PHY_TIMING5);
2778 1.1 christos reg = RW(reg, AR_PHY_TIMING5_CYCPWR_THR1, (level + 1) * 2);
2779 1.1 christos AR_WRITE(sc, AR_PHY_TIMING5, reg);
2780 1.1 christos AR_WRITE_BARRIER(sc);
2781 1.1 christos }
2782