2 * Copyright (c) 2006 The DragonFly Project. All rights reserved.
4 * This code is derived from software contributed to The DragonFly Project
5 * by Sepherosa Ziehau <sepherosa@gmail.com>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * 3. Neither the name of The DragonFly Project nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific, prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
31 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * $DragonFly: src/sys/dev/netif/acx/if_acx.c,v 1.7 2006/09/05 00:55:39 dillon Exp $
38 * Copyright (c) 2003-2004 wlan.kewl.org Project
39 * All rights reserved.
41 * $Id: LICENSE,v 1.1.1.1 2004/07/01 12:20:39 darron Exp $
43 * Redistribution and use in source and binary forms, with or without
44 * modification, are permitted provided that the following conditions
47 * 1. Redistributions of source code must retain the above copyright
48 * notice, this list of conditions and the following disclaimer.
50 * 2. Redistributions in binary form must reproduce the above copyright
51 * notice, this list of conditions and the following disclaimer in the
52 * documentation and/or other materials provided with the distribution.
54 * 3. All advertising materials mentioning features or use of this software
55 * must display the following acknowledgement:
57 * This product includes software developed by the wlan.kewl.org Project.
59 * 4. Neither the name of the wlan.kewl.org Project nor the names of its
60 * contributors may be used to endorse or promote products derived from
61 * this software without specific prior written permission.
63 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
64 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
65 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
66 * THE wlan.kewl.org Project BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
67 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
68 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
69 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
70 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
71 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
72 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
75 #include <sys/param.h>
76 #include <sys/endian.h>
77 #include <sys/kernel.h>
79 #include <sys/malloc.h>
82 #include <sys/serialize.h>
83 #include <sys/socket.h>
84 #include <sys/sockio.h>
85 #include <sys/sysctl.h>
87 #include <machine/bus.h>
88 #include <machine/resource.h>
90 #include <net/ethernet.h>
93 #include <net/if_arp.h>
94 #include <net/if_dl.h>
95 #include <net/if_media.h>
96 #include <net/ifq_var.h>
98 #include <netproto/802_11/ieee80211_var.h>
100 #include <bus/pci/pcireg.h>
101 #include <bus/pci/pcivar.h>
102 #include <bus/pci/pcidevs.h>
106 #include "if_acxreg.h"
107 #include "if_acxvar.h"
110 #define ACX_ENABLE_TXCHAN(sc, chan) \
112 if (acx_enable_txchan((sc), (chan)) != 0) { \
113 if_printf(&(sc)->sc_ic.ic_if, \
114 "enable TX on channel %d failed\n", (chan)); \
118 #define ACX_ENABLE_RXCHAN(sc, chan) \
120 if (acx_enable_rxchan((sc), (chan)) != 0) { \
121 if_printf(&(sc)->sc_ic.ic_if, \
122 "enable RX on channel %d failed\n", (chan)); \
126 #define SIOCSLOADFW _IOW('i', 137, struct ifreq) /* load firmware */
127 #define SIOCGRADIO _IOW('i', 138, struct ifreq) /* get radio type */
128 #define SIOCGSTATS _IOW('i', 139, struct ifreq) /* get acx stats */
129 #define SIOCSKILLFW _IOW('i', 140, struct ifreq) /* free firmware */
130 #define SIOCGFWVER _IOW('i', 141, struct ifreq) /* get firmware ver */
131 #define SIOCGHWID _IOW('i', 142, struct ifreq) /* get hardware id */
133 static int acx_probe(device_t);
134 static int acx_attach(device_t);
135 static int acx_detach(device_t);
136 static int acx_shutdown(device_t);
138 static void acx_init(void *);
139 static int acx_stop(struct acx_softc *);
140 static void acx_init_info_reg(struct acx_softc *);
141 static int acx_config(struct acx_softc *);
142 static int acx_read_config(struct acx_softc *, struct acx_config *);
143 static int acx_write_config(struct acx_softc *, struct acx_config *);
144 static int acx_set_crypt_keys(struct acx_softc *);
146 static void acx_begin_scan(struct acx_softc *);
148 static void acx_next_scan(void *);
150 static void acx_start(struct ifnet *);
151 static void acx_watchdog(struct ifnet *);
153 static int acx_ioctl(struct ifnet *, u_long, caddr_t, struct ucred *);
155 static void acx_intr(void *);
156 static void acx_disable_intr(struct acx_softc *);
157 static void acx_enable_intr(struct acx_softc *);
158 static void acx_txeof(struct acx_softc *);
159 static void acx_txerr(struct acx_softc *, uint8_t);
160 static void acx_rxeof(struct acx_softc *);
162 static int acx_dma_alloc(struct acx_softc *);
163 static void acx_dma_free(struct acx_softc *);
164 static int acx_init_tx_ring(struct acx_softc *);
165 static int acx_init_rx_ring(struct acx_softc *);
166 static int acx_newbuf(struct acx_softc *, struct acx_rxbuf *, int);
167 static int acx_encap(struct acx_softc *, struct acx_txbuf *,
168 struct mbuf *, struct ieee80211_node *);
170 static int acx_reset(struct acx_softc *);
172 static int acx_set_null_tmplt(struct acx_softc *);
173 static int acx_set_probe_req_tmplt(struct acx_softc *, const char *, int);
174 static int acx_set_probe_resp_tmplt(struct acx_softc *,
175 struct ieee80211_node *);
176 static int acx_set_beacon_tmplt(struct acx_softc *,
177 struct ieee80211_node *);
179 static int acx_read_eeprom(struct acx_softc *, uint32_t, uint8_t *);
180 static int acx_read_phyreg(struct acx_softc *, uint32_t, uint8_t *);
182 static int acx_copyin_firmware(struct acx_softc *, struct ifreq *);
183 static void acx_free_firmware(struct acx_softc *);
184 static int acx_load_firmware(struct acx_softc *, uint32_t,
185 const uint8_t *, int);
186 static int acx_load_radio_firmware(struct acx_softc *, const uint8_t *,
188 static int acx_load_base_firmware(struct acx_softc *, const uint8_t *,
191 static int acx_newstate(struct ieee80211com *, enum ieee80211_state, int);
193 static int acx_sysctl_msdu_lifetime(SYSCTL_HANDLER_ARGS);
195 const struct ieee80211_rateset acx_rates_11b =
196 { 4, { 2, 4, 11, 22 } };
197 const struct ieee80211_rateset acx_rates_11g =
198 { 12, { 2, 4, 11, 22, 12, 18, 24, 36, 48, 72, 96, 108 } };
200 static int acx_chanscan_rate = 5; /* 5/second */
201 int acx_beacon_intvl = 100; /* 100 TU */
203 static const struct acx_device {
206 void (*set_param)(device_t);
209 { PCI_VENDOR_TI, PCI_PRODUCT_TI_ACX100A, acx100_set_param,
210 "Texas Instruments TNETW1100A Wireless Adapter" },
211 { PCI_VENDOR_TI, PCI_PRODUCT_TI_ACX100B, acx100_set_param,
212 "Texas Instruments TNETW1100B Wireless Adapter" },
213 { PCI_VENDOR_TI, PCI_PRODUCT_TI_ACX111, acx111_set_param,
214 "Texas Instruments TNETW1130 Wireless Adapter" },
218 static device_method_t acx_methods[] = {
219 DEVMETHOD(device_probe, acx_probe),
220 DEVMETHOD(device_attach, acx_attach),
221 DEVMETHOD(device_detach, acx_detach),
222 DEVMETHOD(device_shutdown, acx_shutdown),
224 DEVMETHOD(device_suspend, acx_suspend),
225 DEVMETHOD(device_resume, acx_resume),
230 static driver_t acx_driver = {
233 sizeof(struct acx_softc)
236 static devclass_t acx_devclass;
238 DRIVER_MODULE(acx, pci, acx_driver, acx_devclass, 0, 0);
239 DRIVER_MODULE(acx, cardbus, acx_driver, acx_devclass, 0, 0);
241 MODULE_DEPEND(acx, wlan, 1, 1, 1);
242 MODULE_DEPEND(acx, wlan_ratectl_onoe, 1, 1, 1);
243 MODULE_DEPEND(acx, wlan_ratectl_amrr, 1, 1, 1);
244 MODULE_DEPEND(acx, pci, 1, 1, 1);
245 MODULE_DEPEND(acx, cardbus, 1, 1, 1);
248 acx_probe(device_t dev)
250 const struct acx_device *a;
253 vid = pci_get_vendor(dev);
254 did = pci_get_device(dev);
255 for (a = acx_devices; a->desc != NULL; ++a) {
256 if (vid == a->vid && did == a->did) {
258 device_set_desc(dev, a->desc);
266 acx_attach(device_t dev)
268 struct acx_softc *sc;
270 struct ieee80211com *ic;
273 sc = device_get_softc(dev);
277 if_initname(ifp, device_get_name(dev), device_get_unit(dev));
280 if (pci_get_powerstate(dev) != PCI_POWERSTATE_D0) {
281 uint32_t mem1, mem2, irq;
283 mem1 = pci_read_config(dev, sc->chip_mem1_rid, 4);
284 mem2 = pci_read_config(dev, sc->chip_mem2_rid, 4);
285 irq = pci_read_config(dev, PCIR_INTLINE, 4);
287 device_printf(dev, "chip is in D%d power mode "
288 "-- setting to D0\n", pci_get_powerstate(dev));
290 pci_set_powerstate(dev, PCI_POWERSTATE_D0);
292 pci_write_config(dev, sc->chip_mem1_rid, mem1, 4);
293 pci_write_config(dev, sc->chip_mem2_rid, mem2, 4);
294 pci_write_config(dev, PCIR_INTLINE, irq, 4);
296 #endif /* !BURN_BRIDGE */
298 /* Enable bus mastering */
299 pci_enable_busmaster(dev);
301 /* Allocate IO memory 1 */
302 sc->sc_mem1_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY,
305 if (sc->sc_mem1_res == NULL) {
307 device_printf(dev, "can't allocate IO mem1\n");
310 sc->sc_mem1_bt = rman_get_bustag(sc->sc_mem1_res);
311 sc->sc_mem1_bh = rman_get_bushandle(sc->sc_mem1_res);
313 /* Allocate IO memory 2 */
314 sc->sc_mem2_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY,
317 if (sc->sc_mem2_res == NULL) {
319 device_printf(dev, "can't allocate IO mem2\n");
322 sc->sc_mem2_bt = rman_get_bustag(sc->sc_mem2_res);
323 sc->sc_mem2_bh = rman_get_bushandle(sc->sc_mem2_res);
326 sc->sc_irq_res = bus_alloc_resource_any(dev, SYS_RES_IRQ,
328 RF_SHAREABLE | RF_ACTIVE);
329 if (sc->sc_irq_res == NULL) {
331 device_printf(dev, "can't allocate intr\n");
335 /* Initilize channel scanning timer */
336 callout_init(&sc->sc_chanscan_timer);
338 /* Allocate busdma stuffs */
339 error = acx_dma_alloc(sc);
344 error = acx_reset(sc);
348 /* Disable interrupts before firmware is loaded */
349 acx_disable_intr(sc);
351 /* Get radio type and form factor */
352 #define EEINFO_RETRY_MAX 50
353 for (i = 0; i < EEINFO_RETRY_MAX; ++i) {
356 ee_info = CSR_READ_2(sc, ACXREG_EEPROM_INFO);
357 if (ACX_EEINFO_HAS_RADIO_TYPE(ee_info)) {
358 sc->sc_form_factor = ACX_EEINFO_FORM_FACTOR(ee_info);
359 sc->sc_radio_type = ACX_EEINFO_RADIO_TYPE(ee_info);
364 if (i == EEINFO_RETRY_MAX) {
368 #undef EEINFO_RETRY_MAX
370 DPRINTF((&sc->sc_ic.ic_if, "radio type %02x\n", sc->sc_radio_type));
373 for (i = 0; i < 0x40; ++i) {
376 error = acx_read_eeprom(sc, i, &val);
379 printf("%02x ", val);
382 #endif /* DUMP_EEPROM */
384 /* Get EEPROM version */
385 error = acx_read_eeprom(sc, ACX_EE_VERSION_OFS, &sc->sc_eeprom_ver);
388 DPRINTF((&sc->sc_ic.ic_if, "EEPROM version %u\n", sc->sc_eeprom_ver));
391 ifp->if_init = acx_init;
392 ifp->if_ioctl = acx_ioctl;
393 ifp->if_start = acx_start;
394 ifp->if_watchdog = acx_watchdog;
395 ifp->if_flags = IFF_SIMPLEX | IFF_BROADCAST | IFF_MULTICAST;
396 ifq_set_maxlen(&ifp->if_snd, IFQ_MAXLEN);
397 ifq_set_ready(&ifp->if_snd);
400 for (i = 1; i <= 14; ++i) {
401 ic->ic_channels[i].ic_freq =
402 ieee80211_ieee2mhz(i, IEEE80211_CHAN_2GHZ);
403 ic->ic_channels[i].ic_flags = sc->chip_chan_flags;
406 ic->ic_opmode = IEEE80211_M_STA;
407 ic->ic_state = IEEE80211_S_INIT;
408 ic->ic_bintval = acx_beacon_intvl;
411 * NOTE: Don't overwrite ic_caps set by chip specific code
413 ic->ic_caps |= IEEE80211_C_WEP | /* WEP */
414 IEEE80211_C_HOSTAP | /* Host AP modes */
415 IEEE80211_C_IBSS | /* IBSS modes */
416 IEEE80211_C_SHPREAMBLE; /* Short preamble */
419 for (i = 0; i < IEEE80211_ADDR_LEN; ++i) {
420 error = acx_read_eeprom(sc, sc->chip_ee_eaddr_ofs - i,
424 ieee80211_ifattach(ic);
426 /* Override newstate */
427 sc->sc_newstate = ic->ic_newstate;
428 ic->ic_newstate = acx_newstate;
430 ieee80211_media_init(ic, ieee80211_media_change, ieee80211_media_status);
432 sc->sc_long_retry_limit = 4;
433 sc->sc_msdu_lifetime = 4096;
435 sysctl_ctx_init(&sc->sc_sysctl_ctx);
436 sc->sc_sysctl_tree = SYSCTL_ADD_NODE(&sc->sc_sysctl_ctx,
437 SYSCTL_STATIC_CHILDREN(_hw),
439 device_get_nameunit(dev),
441 if (sc->sc_sysctl_tree == NULL) {
442 device_printf(dev, "can't add sysctl node\n");
447 SYSCTL_ADD_PROC(&sc->sc_sysctl_ctx,
448 SYSCTL_CHILDREN(sc->sc_sysctl_tree),
449 OID_AUTO, "msdu_lifetime",
450 CTLTYPE_INT | CTLFLAG_RW,
451 sc, 0, acx_sysctl_msdu_lifetime, "I",
454 error = bus_setup_intr(dev, sc->sc_irq_res, INTR_MPSAFE, acx_intr, sc,
455 &sc->sc_irq_handle, ifp->if_serializer);
457 device_printf(dev, "can't set up interrupt\n");
462 ieee80211_announce(ic);
466 ieee80211_ifdetach(ic);
473 acx_detach(device_t dev)
475 struct acx_softc *sc = device_get_softc(dev);
477 if (device_is_attached(dev)) {
478 struct ieee80211com *ic = &sc->sc_ic;
479 struct ifnet *ifp = &ic->ic_if;
481 lwkt_serialize_enter(ifp->if_serializer);
484 acx_free_firmware(sc);
485 bus_teardown_intr(dev, sc->sc_irq_res, sc->sc_irq_handle);
487 lwkt_serialize_exit(ifp->if_serializer);
489 ieee80211_ifdetach(ic);
492 if (sc->sc_sysctl_tree != NULL)
493 sysctl_ctx_free(&sc->sc_sysctl_ctx);
495 if (sc->sc_irq_res != NULL) {
496 bus_release_resource(dev, SYS_RES_IRQ, sc->sc_irq_rid,
499 if (sc->sc_mem1_res != NULL) {
500 bus_release_resource(dev, SYS_RES_MEMORY, sc->chip_mem1_rid,
503 if (sc->sc_mem2_res != NULL) {
504 bus_release_resource(dev, SYS_RES_MEMORY, sc->chip_mem2_rid,
513 acx_shutdown(device_t dev)
515 struct acx_softc *sc = device_get_softc(dev);
517 lwkt_serialize_enter(sc->sc_ic.ic_if.if_serializer);
519 lwkt_serialize_exit(sc->sc_ic.ic_if.if_serializer);
526 struct acx_softc *sc = arg;
527 struct ifnet *ifp = &sc->sc_ic.ic_if;
528 struct acx_firmware *fw = &sc->sc_firmware;
531 error = acx_stop(sc);
535 if (fw->base_fw == NULL) {
537 if_printf(ifp, "base firmware is not loaded yet\n");
541 error = acx_init_tx_ring(sc);
543 if_printf(ifp, "can't initialize TX ring\n");
547 error = acx_init_rx_ring(sc);
549 if_printf(ifp, "can't initialize RX ring\n");
553 error = acx_load_base_firmware(sc, fw->base_fw, fw->base_fw_len);
558 * Initialize command and information registers
559 * NOTE: This should be done after base firmware is loaded
561 acx_init_cmd_reg(sc);
562 acx_init_info_reg(sc);
564 sc->sc_flags |= ACX_FLAG_FW_LOADED;
567 if (sc->chip_post_basefw != NULL) {
568 error = sc->chip_post_basefw(sc);
574 if (fw->radio_fw != NULL) {
575 error = acx_load_radio_firmware(sc, fw->radio_fw,
581 error = sc->chip_init(sc);
585 /* Get and set device various configuration */
586 error = acx_config(sc);
590 /* Setup crypto stuffs */
591 if (sc->sc_ic.ic_flags & IEEE80211_F_PRIVACY) {
592 error = acx_set_crypt_keys(sc);
595 sc->sc_ic.ic_flags &= ~IEEE80211_F_DROPUNENC;
598 /* Turn on power led */
599 CSR_CLRB_2(sc, ACXREG_GPIO_OUT, sc->chip_gpio_pled);
603 ifp->if_flags |= IFF_RUNNING;
604 ifp->if_flags &= ~IFF_OACTIVE;
606 /* Begin background scanning */
610 ieee80211_new_state(&sc->sc_ic, IEEE80211_S_SCAN, -1);
619 acx_init_info_reg(struct acx_softc *sc)
621 sc->sc_info = CSR_READ_4(sc, ACXREG_INFO_REG_OFFSET);
622 sc->sc_info_param = sc->sc_info + ACX_INFO_REG_SIZE;
626 acx_set_crypt_keys(struct acx_softc *sc)
628 struct ieee80211com *ic = &sc->sc_ic;
629 struct acx_conf_wep_txkey wep_txkey;
630 int i, error, got_wk = 0;
632 for (i = 0; i < IEEE80211_WEP_NKID; ++i) {
633 struct ieee80211_key *wk = &ic->ic_nw_keys[i];
635 if (wk->wk_keylen == 0)
638 if (sc->chip_hw_crypt) {
639 error = sc->chip_set_wepkey(sc, wk, i);
643 } else if (wk->wk_flags & IEEE80211_KEY_XMIT) {
644 wk->wk_flags |= IEEE80211_KEY_SWCRYPT;
648 if (!got_wk || sc->chip_hw_crypt ||
649 ic->ic_def_txkey == IEEE80211_KEYIX_NONE)
652 /* Set current WEP key index */
653 wep_txkey.wep_txkey = ic->ic_def_txkey;
654 if (acx_set_wep_txkey_conf(sc, &wep_txkey) != 0) {
655 if_printf(&ic->ic_if, "set WEP txkey failed\n");
663 acx_begin_scan(struct acx_softc *sc)
665 struct ieee80211com *ic = &sc->sc_ic;
668 ieee80211_begin_scan(ic, 1);
670 chan = ieee80211_chan2ieee(ic, ic->ic_bss->ni_chan);
672 ACX_ENABLE_TXCHAN(sc, chan);
673 ACX_ENABLE_RXCHAN(sc, chan);
675 /* Start background scanning */
676 callout_reset(&sc->sc_chanscan_timer, hz / acx_chanscan_rate,
682 acx_next_scan(void *arg)
684 struct acx_softc *sc = arg;
685 struct ieee80211com *ic = &sc->sc_ic;
686 struct ifnet *ifp = &ic->ic_if;
688 lwkt_serialize_enter(ifp->if_serializer);
690 if (ic->ic_state == IEEE80211_S_SCAN) {
695 ieee80211_next_scan(ic);
698 chan = ieee80211_chan2ieee(ic, ic->ic_bss->ni_chan);
700 ACX_ENABLE_TXCHAN(sc, chan);
701 ACX_ENABLE_RXCHAN(sc, chan);
703 callout_reset(&sc->sc_chanscan_timer, hz / acx_chanscan_rate,
708 lwkt_serialize_exit(ifp->if_serializer);
712 acx_stop(struct acx_softc *sc)
714 struct ieee80211com *ic = &sc->sc_ic;
715 struct ifnet *ifp = &ic->ic_if;
716 struct acx_buf_data *bd = &sc->sc_buf_data;
717 struct acx_ring_data *rd = &sc->sc_ring_data;
720 ASSERT_SERIALIZED(ifp->if_serializer);
722 sc->sc_firmware_ver = 0;
723 sc->sc_hardware_id = 0;
726 error = acx_reset(sc);
730 /* Firmware no longer functions after hardware reset */
731 sc->sc_flags &= ~ACX_FLAG_FW_LOADED;
733 acx_disable_intr(sc);
735 /* Stop backgroud scanning */
736 callout_stop(&sc->sc_chanscan_timer);
738 /* Turn off power led */
739 CSR_SETB_2(sc, ACXREG_GPIO_OUT, sc->chip_gpio_pled);
742 for (i = 0; i < ACX_TX_DESC_CNT; ++i) {
743 struct acx_txbuf *buf;
745 buf = &bd->tx_buf[i];
747 if (buf->tb_mbuf != NULL) {
748 bus_dmamap_unload(bd->mbuf_dma_tag,
749 buf->tb_mbuf_dmamap);
750 m_freem(buf->tb_mbuf);
754 if (buf->tb_node != NULL)
755 ieee80211_free_node(buf->tb_node);
759 /* Clear TX host descriptors */
760 bzero(rd->tx_ring, ACX_TX_RING_SIZE);
763 for (i = 0; i < ACX_RX_DESC_CNT; ++i) {
764 if (bd->rx_buf[i].rb_mbuf != NULL) {
765 bus_dmamap_unload(bd->mbuf_dma_tag,
766 bd->rx_buf[i].rb_mbuf_dmamap);
767 m_freem(bd->rx_buf[i].rb_mbuf);
768 bd->rx_buf[i].rb_mbuf = NULL;
772 /* Clear RX host descriptors */
773 bzero(rd->rx_ring, ACX_RX_RING_SIZE);
776 ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE);
777 ieee80211_new_state(&sc->sc_ic, IEEE80211_S_INIT, -1);
783 acx_config(struct acx_softc *sc)
785 struct acx_config conf;
788 error = acx_read_config(sc, &conf);
792 error = acx_write_config(sc, &conf);
796 if (acx_set_probe_req_tmplt(sc, "", 0) != 0) {
797 if_printf(&sc->sc_ic.ic_if, "can't set probe req template "
803 if (acx_set_null_tmplt(sc) != 0) {
804 if_printf(&sc->sc_ic.ic_if, "can't set null data template\n");
811 acx_read_config(struct acx_softc *sc, struct acx_config *conf)
813 struct acx_conf_eaddr addr;
814 struct acx_conf_regdom reg_dom;
815 struct acx_conf_antenna ant;
816 struct acx_conf_fwrev fw_rev;
822 if (acx_get_eaddr_conf(sc, &addr) != 0) {
823 if_printf(&sc->sc_ic.ic_if, "can't get station id\n");
828 * Get and print station id in case that EEPROM station id's
829 * offset is not correct
831 for (i = 0; i < IEEE80211_ADDR_LEN; ++i)
832 conf->eaddr[IEEE80211_ADDR_LEN - 1 - i] = addr.eaddr[i];
833 if_printf(&sc->sc_ic.ic_if, "MAC address (from firmware): %6D\n",
836 /* Get region domain */
837 if (acx_get_regdom_conf(sc, ®_dom) != 0) {
838 if_printf(&sc->sc_ic.ic_if, "can't get region domain\n");
841 conf->regdom = reg_dom.regdom;
842 DPRINTF((&sc->sc_ic.ic_if, "regdom %02x\n", reg_dom.regdom));
845 if (acx_get_antenna_conf(sc, &ant) != 0) {
846 if_printf(&sc->sc_ic.ic_if, "can't get antenna\n");
849 conf->antenna = ant.antenna;
850 DPRINTF((&sc->sc_ic.ic_if, "antenna %02x\n", ant.antenna));
852 /* Get sensitivity XXX not used */
853 if (sc->sc_radio_type == ACX_RADIO_TYPE_MAXIM ||
854 sc->sc_radio_type == ACX_RADIO_TYPE_RFMD ||
855 sc->sc_radio_type == ACX_RADIO_TYPE_RALINK) {
856 error = acx_read_phyreg(sc, ACXRV_PHYREG_SENSITIVITY, &sen);
858 if_printf(&sc->sc_ic.ic_if, "can't get sensitivity\n");
864 DPRINTF((&sc->sc_ic.ic_if, "sensitivity %02x\n", sen));
866 /* Get firmware revision */
867 if (acx_get_fwrev_conf(sc, &fw_rev) != 0) {
868 if_printf(&sc->sc_ic.ic_if, "can't get firmware revision\n");
872 if (strncmp(fw_rev.fw_rev, "Rev ", 4) != 0) {
873 if_printf(&sc->sc_ic.ic_if, "strange revision string -- %s\n",
875 fw_rev_no = 0x01090407;
884 s = &fw_rev.fw_rev[4];
886 for (i = 0; i < 4; ++i) {
889 val = strtoul(s, &endp, 16);
890 fw_rev_no |= val << ((3 - i) * 8);
898 sc->sc_firmware_ver = fw_rev_no;
899 sc->sc_hardware_id = le32toh(fw_rev.hw_id);
900 DPRINTF((&sc->sc_ic.ic_if, "fw rev %08x, hw id %08x\n",
901 sc->sc_firmware_ver, sc->sc_hardware_id));
903 if (sc->chip_read_config != NULL) {
904 error = sc->chip_read_config(sc, conf);
912 acx_write_config(struct acx_softc *sc, struct acx_config *conf)
914 struct acx_conf_nretry_short sretry;
915 struct acx_conf_nretry_long lretry;
916 struct acx_conf_msdu_lifetime msdu_lifetime;
917 struct acx_conf_rate_fallback rate_fb;
918 struct acx_conf_antenna ant;
919 struct acx_conf_regdom reg_dom;
920 struct acx_conf_rxopt rx_opt;
923 /* Set number of long/short retry */
924 KKASSERT(sc->chip_short_retry_limit > 0);
925 sretry.nretry = sc->chip_short_retry_limit;
926 if (acx_set_nretry_short_conf(sc, &sretry) != 0) {
927 if_printf(&sc->sc_ic.ic_if, "can't set short retry limit\n");
931 lretry.nretry = sc->sc_long_retry_limit;
932 if (acx_set_nretry_long_conf(sc, &lretry) != 0) {
933 if_printf(&sc->sc_ic.ic_if, "can't set long retry limit\n");
937 /* Set MSDU lifetime */
938 msdu_lifetime.lifetime = htole32(sc->sc_msdu_lifetime);
939 if (acx_set_msdu_lifetime_conf(sc, &msdu_lifetime) != 0) {
940 if_printf(&sc->sc_ic.ic_if, "can't set MSDU lifetime\n");
944 /* Enable rate fallback */
945 rate_fb.ratefb_enable = 1;
946 if (acx_set_rate_fallback_conf(sc, &rate_fb) != 0) {
947 if_printf(&sc->sc_ic.ic_if, "can't enable rate fallback\n");
952 ant.antenna = conf->antenna;
953 if (acx_set_antenna_conf(sc, &ant) != 0) {
954 if_printf(&sc->sc_ic.ic_if, "can't set antenna\n");
958 /* Set region domain */
959 reg_dom.regdom = conf->regdom;
960 if (acx_set_regdom_conf(sc, ®_dom) != 0) {
961 if_printf(&sc->sc_ic.ic_if, "can't set region domain\n");
965 if (sc->chip_write_config != NULL) {
966 error = sc->chip_write_config(sc, conf);
971 /* What we want to receive and how to receive */
972 /* XXX may not belong here, acx_init() */
973 rx_opt.opt1 = RXOPT1_FILT_FDEST | RXOPT1_INCL_RXBUF_HDR;
974 rx_opt.opt2 = RXOPT2_RECV_ASSOC_REQ |
981 RXOPT2_RECV_PROBE_REQ |
982 RXOPT2_RECV_PROBE_RESP |
984 if (acx_set_rxopt_conf(sc, &rx_opt) != 0) {
985 if_printf(&sc->sc_ic.ic_if, "can't set RX option\n");
992 acx_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data, struct ucred *cr)
994 struct acx_softc *sc = ifp->if_softc;
999 req = (struct ifreq *)data;
1003 error = suser_cred(cr, NULL_CRED_OKAY);
1007 error = acx_copyin_firmware(sc, req);
1010 error = suser_cred(cr, NULL_CRED_OKAY);
1013 acx_free_firmware(sc);
1016 error = copyout(&sc->sc_radio_type, req->ifr_data,
1017 sizeof(sc->sc_radio_type));
1020 error = copyout(&sc->sc_firmware_ver, req->ifr_data,
1021 sizeof(sc->sc_firmware_ver));
1024 error = copyout(&sc->sc_hardware_id, req->ifr_data,
1025 sizeof(sc->sc_hardware_id));
1028 error = copyout(&sc->sc_stats, req->ifr_data,
1029 sizeof(sc->sc_stats));
1032 if (ifp->if_flags & IFF_UP) {
1033 if ((ifp->if_flags & IFF_RUNNING) == 0)
1036 if (ifp->if_flags & IFF_RUNNING)
1045 error = ieee80211_ioctl(&sc->sc_ic, cmd, data, cr);
1049 if (error == ENETRESET) {
1050 if ((ifp->if_flags & (IFF_RUNNING | IFF_UP)) ==
1051 (IFF_RUNNING | IFF_UP))
1059 acx_start(struct ifnet *ifp)
1061 struct acx_softc *sc = ifp->if_softc;
1062 struct ieee80211com *ic = &sc->sc_ic;
1063 struct acx_buf_data *bd = &sc->sc_buf_data;
1064 struct acx_txbuf *buf;
1067 ASSERT_SERIALIZED(ifp->if_serializer);
1069 if ((sc->sc_flags & ACX_FLAG_FW_LOADED) == 0 ||
1070 (ifp->if_flags & IFF_RUNNING) == 0 ||
1071 (ifp->if_flags & IFF_OACTIVE))
1076 * We can't start from a random position that TX descriptor
1077 * is free, since hardware will be confused by that.
1078 * We have to follow the order of the TX ring.
1080 idx = bd->tx_free_start;
1082 for (buf = &bd->tx_buf[idx]; buf->tb_mbuf == NULL;
1083 buf = &bd->tx_buf[idx]) {
1084 struct ieee80211_frame *f;
1085 struct ieee80211_node *ni = NULL;
1089 if (!IF_QEMPTY(&ic->ic_mgtq)) {
1090 IF_DEQUEUE(&ic->ic_mgtq, m);
1092 ni = (struct ieee80211_node *)m->m_pkthdr.rcvif;
1093 m->m_pkthdr.rcvif = NULL;
1096 } else if (!ifq_is_empty(&ifp->if_snd)) {
1097 struct ether_header *eh;
1099 if (ic->ic_state != IEEE80211_S_RUN) {
1100 if_printf(ifp, "data packet dropped due to "
1101 "not RUN. Current state %d\n",
1106 m = ifq_dequeue(&ifp->if_snd, NULL);
1110 if (m->m_len < sizeof(struct ether_header)) {
1111 m = m_pullup(m, sizeof(struct ether_header));
1117 eh = mtod(m, struct ether_header *);
1119 ni = ieee80211_find_txnode(ic, eh->ether_dhost);
1126 /* TODO power save */
1128 m = ieee80211_encap(ic, m, ni);
1130 ieee80211_free_node(ni);
1140 f = mtod(m, struct ieee80211_frame *);
1141 if ((f->i_fc[1] & IEEE80211_FC1_WEP) && !sc->chip_hw_crypt) {
1142 KASSERT(ni != NULL, ("TX node is NULL (WEP)\n"));
1143 if (ieee80211_crypto_encap(ic, ni, m) == NULL) {
1144 ieee80211_free_node(ni);
1151 if (ic->ic_rawbpf != NULL)
1152 bpf_mtap(ic->ic_rawbpf, m);
1155 * Since mgmt data are transmitted at fixed rate
1156 * they will not be used to do rate control.
1158 if (mgmt_pkt && ni != NULL) {
1159 ieee80211_free_node(ni);
1163 if (acx_encap(sc, buf, m, ni) != 0) {
1165 * NOTE: `m' will be freed in acx_encap()
1169 ieee80211_free_node(ni);
1176 * 1) `m' should not be touched after acx_encap()
1177 * 2) `node' will be used to do TX rate control during
1178 * acx_txeof(), so it is not freed here. acx_txeof()
1179 * will free it for us
1183 bd->tx_used_count++;
1184 idx = (idx + 1) % ACX_TX_DESC_CNT;
1186 bd->tx_free_start = idx;
1188 if (bd->tx_used_count == ACX_TX_DESC_CNT)
1189 ifp->if_flags |= IFF_OACTIVE;
1191 if (trans && ifp->if_timer == 0)
1196 acx_watchdog(struct ifnet *ifp)
1198 if_printf(ifp, "watchdog timeout\n");
1199 acx_txeof(ifp->if_softc);
1206 struct acx_softc *sc = arg;
1207 uint16_t intr_status;
1209 if ((sc->sc_flags & ACX_FLAG_FW_LOADED) == 0)
1212 intr_status = CSR_READ_2(sc, ACXREG_INTR_STATUS_CLR);
1213 if (intr_status == ACXRV_INTR_ALL) {
1214 /* not our interrupt */
1218 intr_status &= sc->chip_intr_enable;
1219 if (intr_status == 0) {
1220 /* not interrupts we care about */
1224 /* Acknowledge all interrupts */
1225 CSR_WRITE_2(sc, ACXREG_INTR_ACK, ACXRV_INTR_ALL);
1227 if (intr_status & ACXRV_INTR_TX_FINI)
1230 if (intr_status & ACXRV_INTR_RX_FINI)
1235 acx_disable_intr(struct acx_softc *sc)
1237 CSR_WRITE_2(sc, ACXREG_INTR_MASK, sc->chip_intr_disable);
1238 CSR_WRITE_2(sc, ACXREG_EVENT_MASK, 0);
1242 acx_enable_intr(struct acx_softc *sc)
1244 /* Mask out interrupts that are not in the enable set */
1245 CSR_WRITE_2(sc, ACXREG_INTR_MASK, ~sc->chip_intr_enable);
1246 CSR_WRITE_2(sc, ACXREG_EVENT_MASK, ACXRV_EVENT_DISABLE);
1250 acx_txeof(struct acx_softc *sc)
1252 struct acx_buf_data *bd;
1253 struct acx_txbuf *buf;
1257 ifp = &sc->sc_ic.ic_if;
1258 ASSERT_SERIALIZED(ifp->if_serializer);
1260 bd = &sc->sc_buf_data;
1261 idx = bd->tx_used_start;
1262 for (buf = &bd->tx_buf[idx]; buf->tb_mbuf != NULL;
1263 buf = &bd->tx_buf[idx]) {
1264 uint8_t ctrl, error;
1267 ctrl = FW_TXDESC_GETFIELD_1(sc, buf, f_tx_ctrl);
1268 if ((ctrl & (DESC_CTRL_HOSTOWN | DESC_CTRL_ACXDONE)) !=
1269 (DESC_CTRL_HOSTOWN | DESC_CTRL_ACXDONE))
1272 bus_dmamap_unload(bd->mbuf_dma_tag, buf->tb_mbuf_dmamap);
1273 frame_len = buf->tb_mbuf->m_pkthdr.len;
1274 m_freem(buf->tb_mbuf);
1275 buf->tb_mbuf = NULL;
1277 error = FW_TXDESC_GETFIELD_1(sc, buf, f_tx_error);
1279 acx_txerr(sc, error);
1285 if (buf->tb_node != NULL) {
1286 sc->chip_tx_complete(sc, buf, frame_len, error);
1287 ieee80211_free_node(buf->tb_node);
1288 buf->tb_node = NULL;
1291 FW_TXDESC_SETFIELD_1(sc, buf, f_tx_ctrl, DESC_CTRL_HOSTOWN);
1293 bd->tx_used_count--;
1295 idx = (idx + 1) % ACX_TX_DESC_CNT;
1297 bd->tx_used_start = idx;
1299 ifp->if_timer = bd->tx_used_count == 0 ? 0 : 5;
1301 if (bd->tx_used_count != ACX_TX_DESC_CNT) {
1302 ifp->if_flags &= ~IFF_OACTIVE;
1308 acx_txerr(struct acx_softc *sc, uint8_t err)
1310 struct ifnet *ifp = &sc->sc_ic.ic_if;
1311 struct acx_stats *stats = &sc->sc_stats;
1313 if (err == DESC_ERR_EXCESSIVE_RETRY) {
1315 * This a common error (see comment below),
1316 * so print it using DPRINTF()
1318 DPRINTF((ifp, "TX failed -- excessive retry\n"));
1320 if_printf(ifp, "TX failed -- ");
1324 * Although `err' looks like bitmask, it never
1325 * has multiple bits set.
1329 case DESC_ERR_OTHER_FRAG:
1330 /* XXX what's this */
1331 printf("error in other fragment\n");
1332 stats->err_oth_frag++;
1335 case DESC_ERR_ABORT:
1336 printf("aborted\n");
1339 case DESC_ERR_PARAM:
1340 printf("wrong paramters in descriptor\n");
1343 case DESC_ERR_NO_WEPKEY:
1344 printf("WEP key missing\n");
1345 stats->err_no_wepkey++;
1347 case DESC_ERR_MSDU_TIMEOUT:
1348 printf("MSDU life timeout\n");
1349 stats->err_msdu_timeout++;
1351 case DESC_ERR_EXCESSIVE_RETRY:
1354 * 1) Distance is too long
1355 * 2) Transmit failed (e.g. no MAC level ACK)
1356 * 3) Chip overheated (this should be rare)
1358 stats->err_ex_retry++;
1360 case DESC_ERR_BUF_OVERFLOW:
1361 printf("buffer overflow\n");
1362 stats->err_buf_oflow++;
1365 printf("DMA error\n");
1369 printf("unknown error %d\n", err);
1376 acx_rxeof(struct acx_softc *sc)
1378 struct ieee80211com *ic = &sc->sc_ic;
1379 struct acx_ring_data *rd = &sc->sc_ring_data;
1380 struct acx_buf_data *bd = &sc->sc_buf_data;
1381 struct ifnet *ifp = &ic->ic_if;
1384 ASSERT_SERIALIZED(ic->ic_if.if_serializer);
1386 bus_dmamap_sync(rd->rx_ring_dma_tag, rd->rx_ring_dmamap,
1387 BUS_DMASYNC_POSTREAD);
1390 * Locate first "ready" rx buffer,
1391 * start from last stopped position
1393 idx = bd->rx_scan_start;
1396 struct acx_rxbuf *buf;
1398 buf = &bd->rx_buf[idx];
1399 if ((buf->rb_desc->h_ctrl & htole16(DESC_CTRL_HOSTOWN)) &&
1400 (buf->rb_desc->h_status & htole32(DESC_STATUS_FULL))) {
1404 idx = (idx + 1) % ACX_RX_DESC_CNT;
1405 } while (idx != bd->rx_scan_start);
1411 * NOTE: don't mess up `idx' here, it will
1412 * be used in the following code
1416 struct acx_rxbuf_hdr *head;
1417 struct acx_rxbuf *buf;
1419 uint32_t desc_status;
1423 buf = &bd->rx_buf[idx];
1425 desc_ctrl = le16toh(buf->rb_desc->h_ctrl);
1426 desc_status = le32toh(buf->rb_desc->h_status);
1427 if (!(desc_ctrl & DESC_CTRL_HOSTOWN) ||
1428 !(desc_status & DESC_STATUS_FULL))
1431 bus_dmamap_sync(bd->mbuf_dma_tag, buf->rb_mbuf_dmamap,
1432 BUS_DMASYNC_POSTREAD);
1436 error = acx_newbuf(sc, buf, 0);
1442 head = mtod(m, struct acx_rxbuf_hdr *);
1444 len = le16toh(head->rbh_len) & ACX_RXBUF_LEN_MASK;
1445 if (len >= sizeof(struct ieee80211_frame_min) &&
1447 struct ieee80211_frame *f;
1448 struct ieee80211_node *ni;
1450 m_adj(m, sizeof(struct acx_rxbuf_hdr) +
1451 sc->chip_rxbuf_exhdr);
1452 f = mtod(m, struct ieee80211_frame *);
1454 if ((f->i_fc[1] & IEEE80211_FC1_WEP) &&
1455 sc->chip_hw_crypt) {
1456 /* Short circuit software WEP */
1457 f->i_fc[1] &= ~IEEE80211_FC1_WEP;
1459 /* Do chip specific RX buffer processing */
1460 if (sc->chip_proc_wep_rxbuf != NULL) {
1461 sc->chip_proc_wep_rxbuf(sc, m, &len);
1462 f = mtod(m, struct ieee80211_frame *);
1466 ni = ieee80211_find_rxnode(ic,
1467 (struct ieee80211_frame_min *)f);
1469 m->m_len = m->m_pkthdr.len = len;
1470 m->m_pkthdr.rcvif = &ic->ic_if;
1472 ieee80211_input(ic, m, ni, head->rbh_level,
1473 le32toh(head->rbh_time));
1475 ieee80211_free_node(ni);
1483 buf->rb_desc->h_ctrl = htole16(desc_ctrl & ~DESC_CTRL_HOSTOWN);
1484 buf->rb_desc->h_status = 0;
1485 bus_dmamap_sync(rd->rx_ring_dma_tag, rd->rx_ring_dmamap,
1486 BUS_DMASYNC_PREWRITE);
1488 idx = (idx + 1) % ACX_RX_DESC_CNT;
1489 } while (idx != bd->rx_scan_start);
1492 * Record the position so that next
1493 * time we can start from it
1495 bd->rx_scan_start = idx;
1499 acx_reset(struct acx_softc *sc)
1504 CSR_SETB_2(sc, ACXREG_ECPU_CTRL, ACXRV_ECPU_HALT);
1506 /* Software reset */
1507 reg = CSR_READ_2(sc, ACXREG_SOFT_RESET);
1508 CSR_WRITE_2(sc, ACXREG_SOFT_RESET, reg | ACXRV_SOFT_RESET);
1510 CSR_WRITE_2(sc, ACXREG_SOFT_RESET, reg);
1512 /* Initialize EEPROM */
1513 CSR_SETB_2(sc, ACXREG_EEPROM_INIT, ACXRV_EEPROM_INIT);
1516 /* Test whether ECPU is stopped */
1517 reg = CSR_READ_2(sc, ACXREG_ECPU_CTRL);
1518 if (!(reg & ACXRV_ECPU_HALT)) {
1519 if_printf(&sc->sc_ic.ic_if, "can't halt ECPU\n");
1526 acx_read_eeprom(struct acx_softc *sc, uint32_t offset, uint8_t *val)
1530 CSR_WRITE_4(sc, ACXREG_EEPROM_CONF, 0);
1531 CSR_WRITE_4(sc, ACXREG_EEPROM_ADDR, offset);
1532 CSR_WRITE_4(sc, ACXREG_EEPROM_CTRL, ACXRV_EEPROM_READ);
1534 #define EE_READ_RETRY_MAX 100
1535 for (i = 0; i < EE_READ_RETRY_MAX; ++i) {
1536 if (CSR_READ_2(sc, ACXREG_EEPROM_CTRL) == 0)
1540 if (i == EE_READ_RETRY_MAX) {
1541 if_printf(&sc->sc_ic.ic_if, "can't read EEPROM offset %x "
1542 "(timeout)\n", offset);
1545 #undef EE_READ_RETRY_MAX
1547 *val = CSR_READ_1(sc, ACXREG_EEPROM_DATA);
1552 acx_read_phyreg(struct acx_softc *sc, uint32_t reg, uint8_t *val)
1556 CSR_WRITE_4(sc, ACXREG_PHY_ADDR, reg);
1557 CSR_WRITE_4(sc, ACXREG_PHY_CTRL, ACXRV_PHY_READ);
1559 #define PHY_READ_RETRY_MAX 100
1560 for (i = 0; i < PHY_READ_RETRY_MAX; ++i) {
1561 if (CSR_READ_4(sc, ACXREG_PHY_CTRL) == 0)
1565 if (i == PHY_READ_RETRY_MAX) {
1566 if_printf(&sc->sc_ic.ic_if, "can't read phy reg %x (timeout)\n",
1570 #undef PHY_READ_RETRY_MAX
1572 *val = CSR_READ_1(sc, ACXREG_PHY_DATA);
1577 acx_write_phyreg(struct acx_softc *sc, uint32_t reg, uint8_t val)
1579 CSR_WRITE_4(sc, ACXREG_PHY_DATA, val);
1580 CSR_WRITE_4(sc, ACXREG_PHY_ADDR, reg);
1581 CSR_WRITE_4(sc, ACXREG_PHY_CTRL, ACXRV_PHY_WRITE);
1585 acx_copyin_firmware(struct acx_softc *sc, struct ifreq *req)
1587 struct acx_firmware ufw, *kfw;
1588 uint8_t *base_fw, *radio_fw;
1591 kfw = &sc->sc_firmware;
1595 error = copyin(req->ifr_data, &ufw, sizeof(ufw));
1600 * For combined base firmware, there is no radio firmware.
1601 * But base firmware must exist.
1603 if (ufw.base_fw_len <= 0 || ufw.radio_fw_len < 0)
1606 base_fw = kmalloc(ufw.base_fw_len, M_DEVBUF, M_INTWAIT);
1607 error = copyin(ufw.base_fw, base_fw, ufw.base_fw_len);
1611 if (ufw.radio_fw_len > 0) {
1612 radio_fw = kmalloc(ufw.radio_fw_len, M_DEVBUF, M_INTWAIT);
1613 error = copyin(ufw.radio_fw, radio_fw, ufw.radio_fw_len);
1618 kfw->base_fw_len = ufw.base_fw_len;
1619 if (kfw->base_fw != NULL)
1620 kfree(kfw->base_fw, M_DEVBUF);
1621 kfw->base_fw = base_fw;
1623 kfw->radio_fw_len = ufw.radio_fw_len;
1624 if (kfw->radio_fw != NULL)
1625 kfree(kfw->radio_fw, M_DEVBUF);
1626 kfw->radio_fw = radio_fw;
1630 if (base_fw != NULL)
1631 kfree(base_fw, M_DEVBUF);
1632 if (radio_fw != NULL)
1633 kfree(radio_fw, M_DEVBUF);
1638 acx_free_firmware(struct acx_softc *sc)
1640 struct acx_firmware *fw = &sc->sc_firmware;
1642 if (fw->base_fw != NULL) {
1643 kfree(fw->base_fw, M_DEVBUF);
1645 fw->base_fw_len = 0;
1647 if (fw->radio_fw != NULL) {
1648 kfree(fw->radio_fw, M_DEVBUF);
1649 fw->radio_fw = NULL;
1650 fw->radio_fw_len = 0;
1655 acx_load_base_firmware(struct acx_softc *sc, const uint8_t *base_fw,
1656 uint32_t base_fw_len)
1660 /* Load base firmware */
1661 error = acx_load_firmware(sc, 0, base_fw, base_fw_len);
1663 if_printf(&sc->sc_ic.ic_if, "can't load base firmware\n");
1666 DPRINTF((&sc->sc_ic.ic_if, "base firmware loaded\n"));
1669 CSR_WRITE_2(sc, ACXREG_ECPU_CTRL, ACXRV_ECPU_START);
1671 /* Wait for ECPU to be up */
1672 for (i = 0; i < 500; ++i) {
1675 reg = CSR_READ_2(sc, ACXREG_INTR_STATUS);
1676 if (reg & ACXRV_INTR_FCS_THRESH) {
1677 CSR_WRITE_2(sc, ACXREG_INTR_ACK, ACXRV_INTR_FCS_THRESH);
1683 if_printf(&sc->sc_ic.ic_if, "can't initialize ECPU (timeout)\n");
1688 acx_load_radio_firmware(struct acx_softc *sc, const uint8_t *radio_fw,
1689 uint32_t radio_fw_len)
1691 struct acx_conf_mmap mem_map;
1692 uint32_t radio_fw_ofs;
1696 * Get the position, where base firmware is loaded, so that
1697 * radio firmware can be loaded after it.
1699 if (acx_get_mmap_conf(sc, &mem_map) != 0)
1701 radio_fw_ofs = le32toh(mem_map.code_end);
1703 /* Put ECPU into sleeping state, before loading radio firmware */
1704 if (acx_sleep(sc) != 0)
1707 /* Load radio firmware */
1708 error = acx_load_firmware(sc, radio_fw_ofs, radio_fw, radio_fw_len);
1710 if_printf(&sc->sc_ic.ic_if, "can't load radio firmware\n");
1713 DPRINTF((&sc->sc_ic.ic_if, "radio firmware loaded\n"));
1715 /* Wake up sleeping ECPU, after radio firmware is loaded */
1716 if (acx_wakeup(sc) != 0)
1719 /* Initialize radio */
1720 if (acx_init_radio(sc, radio_fw_ofs, radio_fw_len) != 0)
1723 /* Verify radio firmware's loading position */
1724 if (acx_get_mmap_conf(sc, &mem_map) != 0)
1726 if (le32toh(mem_map.code_end) != radio_fw_ofs + radio_fw_len) {
1727 if_printf(&sc->sc_ic.ic_if, "loaded radio firmware position "
1732 DPRINTF((&sc->sc_ic.ic_if, "radio firmware initialized\n"));
1737 acx_load_firmware(struct acx_softc *sc, uint32_t offset, const uint8_t *data,
1743 fw = (const uint32_t *)data;
1744 fw_len = data_len / sizeof(uint32_t);
1747 * LOADFW_AUTO_INC only works with some older firmware:
1748 * 1) acx100's firmware
1749 * 2) acx111's firmware whose rev is 0x00010011
1753 CSR_WRITE_4(sc, ACXREG_FWMEM_START, ACXRV_FWMEM_START_OP);
1754 #ifndef LOADFW_AUTO_INC
1755 CSR_WRITE_4(sc, ACXREG_FWMEM_CTRL, 0);
1757 CSR_WRITE_4(sc, ACXREG_FWMEM_CTRL, ACXRV_FWMEM_ADDR_AUTOINC);
1758 CSR_WRITE_4(sc, ACXREG_FWMEM_ADDR, offset);
1761 for (i = 0; i < fw_len; ++i) {
1762 #ifndef LOADFW_AUTO_INC
1763 CSR_WRITE_4(sc, ACXREG_FWMEM_ADDR, offset + (i * 4));
1765 CSR_WRITE_4(sc, ACXREG_FWMEM_DATA, be32toh(fw[i]));
1768 /* Verify firmware */
1769 CSR_WRITE_4(sc, ACXREG_FWMEM_START, ACXRV_FWMEM_START_OP);
1770 #ifndef LOADFW_AUTO_INC
1771 CSR_WRITE_4(sc, ACXREG_FWMEM_CTRL, 0);
1773 CSR_WRITE_4(sc, ACXREG_FWMEM_CTRL, ACXRV_FWMEM_ADDR_AUTOINC);
1774 CSR_WRITE_4(sc, ACXREG_FWMEM_ADDR, offset);
1777 for (i = 0; i < fw_len; ++i) {
1780 #ifndef LOADFW_AUTO_INC
1781 CSR_WRITE_4(sc, ACXREG_FWMEM_ADDR, offset + (i * 4));
1783 val = CSR_READ_4(sc, ACXREG_FWMEM_DATA);
1784 if (be32toh(fw[i]) != val) {
1785 if_printf(&sc->sc_ic.ic_if, "fireware mismatch "
1786 "fw %08x loaded %08x\n", fw[i], val);
1794 acx_newstate(struct ieee80211com *ic, enum ieee80211_state nstate, int arg)
1796 struct acx_softc *sc = ic->ic_if.if_softc;
1797 int error = 0, mode = 0;
1799 ASSERT_SERIALIZED(ic->ic_if.if_serializer);
1801 ieee80211_ratectl_newstate(ic, nstate);
1804 case IEEE80211_S_SCAN:
1805 if (ic->ic_state != IEEE80211_S_INIT) {
1808 chan = ieee80211_chan2ieee(ic, ic->ic_curchan);
1809 ACX_ENABLE_TXCHAN(sc, chan);
1810 ACX_ENABLE_RXCHAN(sc, chan);
1812 callout_reset(&sc->sc_chanscan_timer,
1813 hz / acx_chanscan_rate,
1817 case IEEE80211_S_AUTH:
1818 if (ic->ic_opmode == IEEE80211_M_STA) {
1819 struct ieee80211_node *ni;
1826 if (acx_join_bss(sc, ACX_MODE_STA, ni) != 0) {
1827 if_printf(&ic->ic_if, "join BSS failed\n");
1832 DPRINTF((&ic->ic_if, "join BSS\n"));
1833 if (ic->ic_state == IEEE80211_S_ASSOC) {
1834 DPRINTF((&ic->ic_if,
1835 "change from assoc to run\n"));
1836 ic->ic_state = IEEE80211_S_RUN;
1840 if_printf(&ic->ic_if, "AP rates: ");
1841 for (i = 0; i < ni->ni_rates.rs_nrates; ++i)
1842 printf("%d ", ni->ni_rates.rs_rates[i]);
1843 ieee80211_print_essid(ni->ni_essid, ni->ni_esslen);
1844 printf(" %6D\n", ni->ni_bssid, ":");
1848 case IEEE80211_S_RUN:
1849 if (ic->ic_opmode == IEEE80211_M_IBSS ||
1850 ic->ic_opmode == IEEE80211_M_HOSTAP) {
1851 struct ieee80211_node *ni;
1855 chan = ieee80211_chan2ieee(ic, ni->ni_chan);
1859 if (acx_enable_txchan(sc, chan) != 0) {
1860 if_printf(&ic->ic_if,
1861 "enable TX on channel %d failed\n",
1866 if (acx_enable_rxchan(sc, chan) != 0) {
1867 if_printf(&ic->ic_if,
1868 "enable RX on channel %d failed\n",
1873 if (acx_set_beacon_tmplt(sc, ni) != 0) {
1874 if_printf(&ic->ic_if,
1875 "set bescon template failed\n");
1879 if (acx_set_probe_resp_tmplt(sc, ni) != 0) {
1880 if_printf(&ic->ic_if, "set probe response "
1881 "template failed\n");
1885 if (ic->ic_opmode == IEEE80211_M_IBSS)
1886 mode = ACX_MODE_ADHOC;
1890 if (acx_join_bss(sc, mode, ni) != 0) {
1891 if_printf(&ic->ic_if, "acx_join_ibss failed\n");
1895 DPRINTF((&ic->ic_if, "join IBSS\n"));
1906 nstate = IEEE80211_S_INIT;
1909 return sc->sc_newstate(ic, nstate, arg);
1913 acx_init_tmplt_ordered(struct acx_softc *sc)
1915 #define INIT_TMPLT(name) \
1917 if (acx_init_##name##_tmplt(sc) != 0) \
1923 * Order of templates initialization:
1929 * Above order is critical to get a correct memory map.
1931 INIT_TMPLT(probe_req);
1932 INIT_TMPLT(null_data);
1935 INIT_TMPLT(probe_resp);
1937 #undef CALL_SET_TMPLT
1942 acx_ring_dma_addr(void *arg, bus_dma_segment_t *seg, int nseg, int error)
1944 *((uint32_t *)arg) = seg->ds_addr;
1948 acx_dma_alloc(struct acx_softc *sc)
1950 struct acx_ring_data *rd = &sc->sc_ring_data;
1951 struct acx_buf_data *bd = &sc->sc_buf_data;
1954 /* Allocate DMA stuffs for RX descriptors */
1955 error = bus_dma_tag_create(NULL, PAGE_SIZE, 0,
1956 BUS_SPACE_MAXADDR_32BIT, BUS_SPACE_MAXADDR,
1958 ACX_RX_RING_SIZE, 1, ACX_RX_RING_SIZE,
1959 0, &rd->rx_ring_dma_tag);
1961 if_printf(&sc->sc_ic.ic_if, "can't create rx ring dma tag\n");
1965 error = bus_dmamem_alloc(rd->rx_ring_dma_tag, (void **)&rd->rx_ring,
1966 BUS_DMA_WAITOK | BUS_DMA_ZERO,
1967 &rd->rx_ring_dmamap);
1969 if_printf(&sc->sc_ic.ic_if,
1970 "can't allocate rx ring dma memory\n");
1971 bus_dma_tag_destroy(rd->rx_ring_dma_tag);
1972 rd->rx_ring_dma_tag = NULL;
1976 error = bus_dmamap_load(rd->rx_ring_dma_tag, rd->rx_ring_dmamap,
1977 rd->rx_ring, ACX_RX_RING_SIZE,
1978 acx_ring_dma_addr, &rd->rx_ring_paddr,
1981 if_printf(&sc->sc_ic.ic_if, "can't get rx ring dma address\n");
1982 bus_dmamem_free(rd->rx_ring_dma_tag, rd->rx_ring,
1983 rd->rx_ring_dmamap);
1984 bus_dma_tag_destroy(rd->rx_ring_dma_tag);
1985 rd->rx_ring_dma_tag = NULL;
1989 /* Allocate DMA stuffs for TX descriptors */
1990 error = bus_dma_tag_create(NULL, PAGE_SIZE, 0,
1991 BUS_SPACE_MAXADDR_32BIT, BUS_SPACE_MAXADDR,
1993 ACX_TX_RING_SIZE, 1, ACX_TX_RING_SIZE,
1994 0, &rd->tx_ring_dma_tag);
1996 if_printf(&sc->sc_ic.ic_if, "can't create tx ring dma tag\n");
2000 error = bus_dmamem_alloc(rd->tx_ring_dma_tag, (void **)&rd->tx_ring,
2001 BUS_DMA_WAITOK | BUS_DMA_ZERO,
2002 &rd->tx_ring_dmamap);
2004 if_printf(&sc->sc_ic.ic_if,
2005 "can't allocate tx ring dma memory\n");
2006 bus_dma_tag_destroy(rd->tx_ring_dma_tag);
2007 rd->tx_ring_dma_tag = NULL;
2011 error = bus_dmamap_load(rd->tx_ring_dma_tag, rd->tx_ring_dmamap,
2012 rd->tx_ring, ACX_TX_RING_SIZE,
2013 acx_ring_dma_addr, &rd->tx_ring_paddr,
2016 if_printf(&sc->sc_ic.ic_if, "can't get tx ring dma address\n");
2017 bus_dmamem_free(rd->tx_ring_dma_tag, rd->tx_ring,
2018 rd->tx_ring_dmamap);
2019 bus_dma_tag_destroy(rd->tx_ring_dma_tag);
2020 rd->tx_ring_dma_tag = NULL;
2024 /* Create DMA tag for RX/TX mbuf map */
2025 error = bus_dma_tag_create(NULL, 1, 0,
2026 BUS_SPACE_MAXADDR_32BIT, BUS_SPACE_MAXADDR,
2028 MCLBYTES, 1, MCLBYTES,
2029 0, &bd->mbuf_dma_tag);
2031 if_printf(&sc->sc_ic.ic_if, "can't create mbuf dma tag\n");
2035 /* Create a spare RX DMA map */
2036 error = bus_dmamap_create(bd->mbuf_dma_tag, 0, &bd->mbuf_tmp_dmamap);
2038 if_printf(&sc->sc_ic.ic_if, "can't create tmp mbuf dma map\n");
2039 bus_dma_tag_destroy(bd->mbuf_dma_tag);
2040 bd->mbuf_dma_tag = NULL;
2044 /* Create DMA map for RX mbufs */
2045 for (i = 0; i < ACX_RX_DESC_CNT; ++i) {
2046 error = bus_dmamap_create(bd->mbuf_dma_tag, 0,
2047 &bd->rx_buf[i].rb_mbuf_dmamap);
2049 if_printf(&sc->sc_ic.ic_if, "can't create rx mbuf "
2050 "dma map (%d)\n", i);
2053 bd->rx_buf[i].rb_desc = &rd->rx_ring[i];
2056 /* Create DMA map for TX mbufs */
2057 for (i = 0; i < ACX_TX_DESC_CNT; ++i) {
2058 error = bus_dmamap_create(bd->mbuf_dma_tag, 0,
2059 &bd->tx_buf[i].tb_mbuf_dmamap);
2061 if_printf(&sc->sc_ic.ic_if, "can't create tx mbuf "
2062 "dma map (%d)\n", i);
2065 bd->tx_buf[i].tb_desc1 = &rd->tx_ring[i * 2];
2066 bd->tx_buf[i].tb_desc2 = &rd->tx_ring[(i * 2) + 1];
2073 acx_dma_free(struct acx_softc *sc)
2075 struct acx_ring_data *rd = &sc->sc_ring_data;
2076 struct acx_buf_data *bd = &sc->sc_buf_data;
2079 if (rd->rx_ring_dma_tag != NULL) {
2080 bus_dmamap_unload(rd->rx_ring_dma_tag, rd->rx_ring_dmamap);
2081 bus_dmamem_free(rd->rx_ring_dma_tag, rd->rx_ring,
2082 rd->rx_ring_dmamap);
2083 bus_dma_tag_destroy(rd->rx_ring_dma_tag);
2086 if (rd->tx_ring_dma_tag != NULL) {
2087 bus_dmamap_unload(rd->tx_ring_dma_tag, rd->tx_ring_dmamap);
2088 bus_dmamem_free(rd->tx_ring_dma_tag, rd->tx_ring,
2089 rd->tx_ring_dmamap);
2090 bus_dma_tag_destroy(rd->tx_ring_dma_tag);
2093 for (i = 0; i < ACX_RX_DESC_CNT; ++i) {
2094 if (bd->rx_buf[i].rb_desc != NULL) {
2095 if (bd->rx_buf[i].rb_mbuf != NULL) {
2096 bus_dmamap_unload(bd->mbuf_dma_tag,
2097 bd->rx_buf[i].rb_mbuf_dmamap);
2098 m_freem(bd->rx_buf[i].rb_mbuf);
2100 bus_dmamap_destroy(bd->mbuf_dma_tag,
2101 bd->rx_buf[i].rb_mbuf_dmamap);
2105 for (i = 0; i < ACX_TX_DESC_CNT; ++i) {
2106 if (bd->tx_buf[i].tb_desc1 != NULL) {
2107 if (bd->tx_buf[i].tb_mbuf != NULL) {
2108 bus_dmamap_unload(bd->mbuf_dma_tag,
2109 bd->tx_buf[i].tb_mbuf_dmamap);
2110 m_freem(bd->tx_buf[i].tb_mbuf);
2112 bus_dmamap_destroy(bd->mbuf_dma_tag,
2113 bd->tx_buf[i].tb_mbuf_dmamap);
2117 if (bd->mbuf_dma_tag != NULL) {
2118 bus_dmamap_destroy(bd->mbuf_dma_tag, bd->mbuf_tmp_dmamap);
2119 bus_dma_tag_destroy(bd->mbuf_dma_tag);
2124 acx_init_tx_ring(struct acx_softc *sc)
2126 struct acx_ring_data *rd;
2127 struct acx_buf_data *bd;
2131 rd = &sc->sc_ring_data;
2132 paddr = rd->tx_ring_paddr;
2133 for (i = 0; i < (ACX_TX_DESC_CNT * 2) - 1; ++i) {
2134 paddr += sizeof(struct acx_host_desc);
2136 rd->tx_ring[i].h_ctrl = htole16(DESC_CTRL_HOSTOWN);
2138 if (i == (ACX_TX_DESC_CNT * 2) - 1)
2139 rd->tx_ring[i].h_next_desc = htole32(rd->tx_ring_paddr);
2141 rd->tx_ring[i].h_next_desc = htole32(paddr);
2144 bus_dmamap_sync(rd->tx_ring_dma_tag, rd->tx_ring_dmamap,
2145 BUS_DMASYNC_PREWRITE);
2147 bd = &sc->sc_buf_data;
2148 bd->tx_free_start = 0;
2149 bd->tx_used_start = 0;
2150 bd->tx_used_count = 0;
2156 acx_init_rx_ring(struct acx_softc *sc)
2158 struct acx_ring_data *rd;
2159 struct acx_buf_data *bd;
2163 bd = &sc->sc_buf_data;
2164 rd = &sc->sc_ring_data;
2165 paddr = rd->rx_ring_paddr;
2167 for (i = 0; i < ACX_RX_DESC_CNT; ++i) {
2170 paddr += sizeof(struct acx_host_desc);
2172 error = acx_newbuf(sc, &bd->rx_buf[i], 1);
2176 if (i == ACX_RX_DESC_CNT - 1)
2177 rd->rx_ring[i].h_next_desc = htole32(rd->rx_ring_paddr);
2179 rd->rx_ring[i].h_next_desc = htole32(paddr);
2182 bus_dmamap_sync(rd->rx_ring_dma_tag, rd->rx_ring_dmamap,
2183 BUS_DMASYNC_PREWRITE);
2185 bd->rx_scan_start = 0;
2190 acx_buf_dma_addr(void *arg, bus_dma_segment_t *seg, int nseg,
2191 bus_size_t mapsz, int error)
2197 KASSERT(nseg == 1, ("too many RX dma segments\n"));
2198 *((uint32_t *)arg) = seg->ds_addr;
2202 acx_newbuf(struct acx_softc *sc, struct acx_rxbuf *rb, int wait)
2204 struct acx_buf_data *bd;
2210 bd = &sc->sc_buf_data;
2212 m = m_getcl(wait ? MB_WAIT : MB_DONTWAIT, MT_DATA, M_PKTHDR);
2216 m->m_len = m->m_pkthdr.len = MCLBYTES;
2218 error = bus_dmamap_load_mbuf(bd->mbuf_dma_tag, bd->mbuf_tmp_dmamap,
2219 m, acx_buf_dma_addr, &paddr,
2220 wait ? BUS_DMA_WAITOK : BUS_DMA_NOWAIT);
2223 if_printf(&sc->sc_ic.ic_if, "can't map rx mbuf %d\n", error);
2227 /* Unload originally mapped mbuf */
2228 bus_dmamap_unload(bd->mbuf_dma_tag, rb->rb_mbuf_dmamap);
2230 /* Swap this dmamap with tmp dmamap */
2231 map = rb->rb_mbuf_dmamap;
2232 rb->rb_mbuf_dmamap = bd->mbuf_tmp_dmamap;
2233 bd->mbuf_tmp_dmamap = map;
2236 rb->rb_desc->h_data_paddr = htole32(paddr);
2237 rb->rb_desc->h_data_len = htole16(m->m_len);
2239 bus_dmamap_sync(bd->mbuf_dma_tag, rb->rb_mbuf_dmamap,
2240 BUS_DMASYNC_PREREAD);
2245 acx_encap(struct acx_softc *sc, struct acx_txbuf *txbuf, struct mbuf *m,
2246 struct ieee80211_node *ni)
2248 struct acx_buf_data *bd = &sc->sc_buf_data;
2249 struct acx_ring_data *rd = &sc->sc_ring_data;
2254 KASSERT(txbuf->tb_mbuf == NULL, ("free TX buf has mbuf installed\n"));
2257 if (m->m_pkthdr.len > MCLBYTES) {
2258 if_printf(&sc->sc_ic.ic_if, "mbuf too big\n");
2261 } else if (m->m_pkthdr.len < ACX_FRAME_HDRLEN) {
2262 if_printf(&sc->sc_ic.ic_if, "mbuf too small\n");
2267 error = bus_dmamap_load_mbuf(bd->mbuf_dma_tag, txbuf->tb_mbuf_dmamap,
2268 m, acx_buf_dma_addr, &paddr,
2270 if (error && error != EFBIG) {
2271 if_printf(&sc->sc_ic.ic_if, "can't map tx mbuf1 %d\n", error);
2275 if (error) { /* error == EFBIG */
2278 m_new = m_defrag(m, MB_DONTWAIT);
2279 if (m_new == NULL) {
2280 if_printf(&sc->sc_ic.ic_if, "can't defrag tx mbuf\n");
2287 error = bus_dmamap_load_mbuf(bd->mbuf_dma_tag,
2288 txbuf->tb_mbuf_dmamap, m,
2289 acx_buf_dma_addr, &paddr,
2292 if_printf(&sc->sc_ic.ic_if, "can't map tx mbuf2 %d\n",
2300 bus_dmamap_sync(bd->mbuf_dma_tag, txbuf->tb_mbuf_dmamap,
2301 BUS_DMASYNC_PREWRITE);
2304 txbuf->tb_node = ni;
2307 * TX buffers are accessed in following way:
2308 * acx_fw_txdesc -> acx_host_desc -> buffer
2310 * It is quite strange that acx also querys acx_host_desc next to
2311 * the one we have assigned to acx_fw_txdesc even if first one's
2312 * acx_host_desc.h_data_len == acx_fw_txdesc.f_tx_len
2314 * So we allocate two acx_host_desc for one acx_fw_txdesc and
2315 * assign the first acx_host_desc to acx_fw_txdesc
2318 * host_desc1.h_data_len = buffer_len
2319 * host_desc2.h_data_len = buffer_len - mac_header_len
2322 * host_desc1.h_data_len = mac_header_len
2323 * host_desc2.h_data_len = buffer_len - mac_header_len
2326 txbuf->tb_desc1->h_data_paddr = htole32(paddr);
2327 txbuf->tb_desc2->h_data_paddr = htole32(paddr + ACX_FRAME_HDRLEN);
2329 txbuf->tb_desc1->h_data_len =
2330 htole16(sc->chip_txdesc1_len ? sc->chip_txdesc1_len
2332 txbuf->tb_desc2->h_data_len =
2333 htole16(m->m_pkthdr.len - ACX_FRAME_HDRLEN);
2337 * We can't simply assign f_tx_ctrl, we will first read it back
2338 * and change it bit by bit
2340 ctrl = FW_TXDESC_GETFIELD_1(sc, txbuf, f_tx_ctrl);
2341 ctrl |= sc->chip_fw_txdesc_ctrl; /* extra chip specific flags */
2342 ctrl &= ~(DESC_CTRL_HOSTOWN | DESC_CTRL_ACXDONE);
2344 FW_TXDESC_SETFIELD_4(sc, txbuf, f_tx_len, m->m_pkthdr.len);
2345 FW_TXDESC_SETFIELD_1(sc, txbuf, f_tx_error, 0);
2346 FW_TXDESC_SETFIELD_1(sc, txbuf, f_tx_data_nretry, 0);
2347 FW_TXDESC_SETFIELD_1(sc, txbuf, f_tx_rts_nretry, 0);
2348 FW_TXDESC_SETFIELD_1(sc, txbuf, f_tx_rts_ok, 0);
2349 sc->chip_set_fw_txdesc_rate(sc, txbuf, ni, m->m_pkthdr.len);
2351 txbuf->tb_desc1->h_ctrl = 0;
2352 txbuf->tb_desc2->h_ctrl = 0;
2353 bus_dmamap_sync(rd->tx_ring_dma_tag, rd->tx_ring_dmamap,
2354 BUS_DMASYNC_PREWRITE);
2356 FW_TXDESC_SETFIELD_1(sc, txbuf, f_tx_ctrl2, 0);
2357 FW_TXDESC_SETFIELD_1(sc, txbuf, f_tx_ctrl, ctrl);
2359 /* Tell chip to inform us about TX completion */
2360 CSR_WRITE_2(sc, ACXREG_INTR_TRIG, ACXRV_TRIG_TX_FINI);
2368 acx_set_null_tmplt(struct acx_softc *sc)
2370 struct acx_tmplt_null_data n;
2371 struct ieee80211_frame *f;
2373 bzero(&n, sizeof(n));
2376 f->i_fc[0] = IEEE80211_FC0_SUBTYPE_NODATA | IEEE80211_FC0_TYPE_DATA;
2377 IEEE80211_ADDR_COPY(f->i_addr1, etherbroadcastaddr);
2378 IEEE80211_ADDR_COPY(f->i_addr2, IF_LLADDR(&sc->sc_ic.ic_if));
2379 IEEE80211_ADDR_COPY(f->i_addr3, etherbroadcastaddr);
2381 return _acx_set_null_data_tmplt(sc, &n, sizeof(n));
2385 acx_set_probe_req_tmplt(struct acx_softc *sc, const char *ssid, int ssid_len)
2387 struct acx_tmplt_probe_req req;
2388 struct ieee80211_frame *f;
2392 bzero(&req, sizeof(req));
2394 f = &req.data.u_data.f;
2395 f->i_fc[0] = IEEE80211_FC0_SUBTYPE_PROBE_REQ | IEEE80211_FC0_TYPE_MGT;
2396 IEEE80211_ADDR_COPY(f->i_addr1, etherbroadcastaddr);
2397 IEEE80211_ADDR_COPY(f->i_addr2, IF_LLADDR(&sc->sc_ic.ic_if));
2398 IEEE80211_ADDR_COPY(f->i_addr3, etherbroadcastaddr);
2400 v = req.data.u_data.var;
2401 v = ieee80211_add_ssid(v, ssid, ssid_len);
2402 v = ieee80211_add_rates(v, &sc->sc_ic.ic_sup_rates[sc->chip_phymode]);
2403 v = ieee80211_add_xrates(v, &sc->sc_ic.ic_sup_rates[sc->chip_phymode]);
2404 vlen = v - req.data.u_data.var;
2406 return _acx_set_probe_req_tmplt(sc, &req,
2407 ACX_TMPLT_PROBE_REQ_SIZ(vlen));
2411 acx_set_probe_resp_tmplt(struct acx_softc *sc, struct ieee80211_node *ni)
2413 struct ieee80211com *ic = &sc->sc_ic;
2414 struct acx_tmplt_probe_resp resp;
2415 struct ieee80211_beacon_offsets bo;
2419 bzero(&resp, sizeof(resp));
2421 bzero(&bo, sizeof(bo));
2422 m = ieee80211_beacon_alloc(ic, ni, &bo);
2423 DPRINTF((&ic->ic_if, "%s alloc beacon size %d\n", __func__,
2426 m_copydata(m, 0, m->m_pkthdr.len, (caddr_t)&resp.data);
2427 len = m->m_pkthdr.len + sizeof(resp.size);
2430 return _acx_set_probe_resp_tmplt(sc, &resp, len);
2434 acx_set_beacon_tmplt(struct acx_softc *sc, struct ieee80211_node *ni)
2436 struct ieee80211com *ic = &sc->sc_ic;
2437 struct acx_tmplt_beacon beacon;
2438 struct ieee80211_beacon_offsets bo;
2442 bzero(&beacon, sizeof(beacon));
2444 bzero(&bo, sizeof(bo));
2445 m = ieee80211_beacon_alloc(ic, ni, &bo);
2446 DPRINTF((&ic->ic_if, "%s alloc beacon size %d\n", __func__,
2449 m_copydata(m, 0, m->m_pkthdr.len, (caddr_t)&beacon.data);
2450 len = m->m_pkthdr.len + sizeof(beacon.size);
2453 return _acx_set_beacon_tmplt(sc, &beacon, len);
2457 acx_sysctl_msdu_lifetime(SYSCTL_HANDLER_ARGS)
2459 struct acx_softc *sc = arg1;
2460 struct ifnet *ifp = &sc->sc_ic.ic_if;
2463 lwkt_serialize_enter(ifp->if_serializer);
2465 v = sc->sc_msdu_lifetime;
2466 error = sysctl_handle_int(oidp, &v, 0, req);
2467 if (error || req->newptr == NULL)
2474 if (sc->sc_flags & ACX_FLAG_FW_LOADED) {
2475 struct acx_conf_msdu_lifetime msdu_lifetime;
2477 msdu_lifetime.lifetime = htole32(v);
2478 if (acx_set_msdu_lifetime_conf(sc, &msdu_lifetime) != 0) {
2479 if_printf(&sc->sc_ic.ic_if,
2480 "can't set MSDU lifetime\n");
2485 sc->sc_msdu_lifetime = v;
2487 lwkt_serialize_exit(ifp->if_serializer);