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.18 2007/02/16 06:34:10 sephe 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 <net/ethernet.h>
90 #include <net/if_arp.h>
91 #include <net/if_dl.h>
92 #include <net/if_media.h>
93 #include <net/ifq_var.h>
95 #include <netproto/802_11/ieee80211_var.h>
97 #include <bus/pci/pcireg.h>
98 #include <bus/pci/pcivar.h>
99 #include <bus/pci/pcidevs.h>
103 #include "if_acxreg.h"
104 #include "if_acxvar.h"
107 #define SIOCSLOADFW _IOW('i', 137, struct ifreq) /* load firmware */
108 #define SIOCGRADIO _IOW('i', 138, struct ifreq) /* get radio type */
109 #define SIOCGSTATS _IOW('i', 139, struct ifreq) /* get acx stats */
110 #define SIOCSKILLFW _IOW('i', 140, struct ifreq) /* free firmware */
111 #define SIOCGFWVER _IOW('i', 141, struct ifreq) /* get firmware ver */
112 #define SIOCGHWID _IOW('i', 142, struct ifreq) /* get hardware id */
114 static int acx_probe(device_t);
115 static int acx_attach(device_t);
116 static int acx_detach(device_t);
117 static int acx_shutdown(device_t);
119 static void acx_init(void *);
120 static void acx_start(struct ifnet *);
121 static int acx_ioctl(struct ifnet *, u_long, caddr_t, struct ucred *);
122 static void acx_watchdog(struct ifnet *);
124 static void acx_intr(void *);
125 static void acx_txeof(struct acx_softc *);
126 static void acx_txerr(struct acx_softc *, uint8_t);
127 static void acx_rxeof(struct acx_softc *);
128 static void acx_disable_intr(struct acx_softc *);
129 static void acx_enable_intr(struct acx_softc *);
131 static int acx_reset(struct acx_softc *);
132 static int acx_stop(struct acx_softc *);
133 static void acx_init_info_reg(struct acx_softc *);
134 static int acx_config(struct acx_softc *);
135 static int acx_read_config(struct acx_softc *, struct acx_config *);
136 static int acx_write_config(struct acx_softc *, struct acx_config *);
137 static int acx_rx_config(struct acx_softc *, int);
138 static int acx_set_crypt_keys(struct acx_softc *);
140 static int acx_dma_alloc(struct acx_softc *);
141 static void acx_dma_free(struct acx_softc *);
142 static int acx_init_tx_ring(struct acx_softc *);
143 static int acx_init_rx_ring(struct acx_softc *);
144 static int acx_newbuf(struct acx_softc *, struct acx_rxbuf *, int);
145 static int acx_encap(struct acx_softc *, struct acx_txbuf *,
146 struct mbuf *, struct ieee80211_node *);
148 static int acx_set_null_tmplt(struct acx_softc *);
149 static int acx_set_probe_req_tmplt(struct acx_softc *, const char *, int);
150 static int acx_set_probe_resp_tmplt(struct acx_softc *,
151 struct ieee80211_node *);
152 static int acx_set_beacon_tmplt(struct acx_softc *,
153 struct ieee80211_node *);
155 static int acx_read_eeprom(struct acx_softc *, uint32_t, uint8_t *);
156 static int acx_read_phyreg(struct acx_softc *, uint32_t, uint8_t *);
158 static int acx_copyin_firmware(struct acx_softc *, struct ifreq *);
159 static void acx_free_firmware(struct acx_softc *);
160 static int acx_load_firmware(struct acx_softc *, uint32_t,
161 const uint8_t *, int);
162 static int acx_load_radio_firmware(struct acx_softc *, const uint8_t *,
164 static int acx_load_base_firmware(struct acx_softc *, const uint8_t *,
167 static void acx_next_scan(void *);
168 static int acx_set_chan(struct acx_softc *, struct ieee80211_channel *);
170 static int acx_media_change(struct ifnet *);
171 static int acx_newstate(struct ieee80211com *, enum ieee80211_state, int);
173 static int acx_sysctl_msdu_lifetime(SYSCTL_HANDLER_ARGS);
175 const struct ieee80211_rateset acx_rates_11b =
176 { 5, { 2, 4, 11, 22, 44 } };
177 const struct ieee80211_rateset acx_rates_11g =
178 { 13, { 2, 4, 11, 22, 44, 12, 18, 24, 36, 48, 72, 96, 108 } };
180 static const struct acx_device {
183 void (*set_param)(device_t);
186 { PCI_VENDOR_TI, PCI_PRODUCT_TI_ACX100A, acx100_set_param,
187 "Texas Instruments TNETW1100A Wireless Adapter" },
188 { PCI_VENDOR_TI, PCI_PRODUCT_TI_ACX100B, acx100_set_param,
189 "Texas Instruments TNETW1100B Wireless Adapter" },
190 { PCI_VENDOR_TI, PCI_PRODUCT_TI_ACX111, acx111_set_param,
191 "Texas Instruments TNETW1130 Wireless Adapter" },
195 static device_method_t acx_methods[] = {
196 DEVMETHOD(device_probe, acx_probe),
197 DEVMETHOD(device_attach, acx_attach),
198 DEVMETHOD(device_detach, acx_detach),
199 DEVMETHOD(device_shutdown, acx_shutdown),
201 DEVMETHOD(device_suspend, acx_suspend),
202 DEVMETHOD(device_resume, acx_resume),
207 static driver_t acx_driver = {
210 sizeof(struct acx_softc)
213 static devclass_t acx_devclass;
215 DRIVER_MODULE(acx, pci, acx_driver, acx_devclass, 0, 0);
216 DRIVER_MODULE(acx, cardbus, acx_driver, acx_devclass, 0, 0);
218 MODULE_DEPEND(acx, wlan, 1, 1, 1);
219 MODULE_DEPEND(acx, wlan_ratectl_onoe, 1, 1, 1);
220 MODULE_DEPEND(acx, wlan_ratectl_amrr, 1, 1, 1);
221 MODULE_DEPEND(acx, pci, 1, 1, 1);
222 MODULE_DEPEND(acx, cardbus, 1, 1, 1);
225 acx_get_rssi(struct acx_softc *sc, uint8_t raw)
229 rssi = ((sc->chip_rssi_corr / 2) + (raw * 5)) / sc->chip_rssi_corr;
230 return rssi > 100 ? 100 : rssi;
234 acx_probe(device_t dev)
236 const struct acx_device *a;
239 vid = pci_get_vendor(dev);
240 did = pci_get_device(dev);
241 for (a = acx_devices; a->desc != NULL; ++a) {
242 if (vid == a->vid && did == a->did) {
244 device_set_desc(dev, a->desc);
252 acx_attach(device_t dev)
254 struct acx_softc *sc;
256 struct ieee80211com *ic;
259 sc = device_get_softc(dev);
263 if_initname(ifp, device_get_name(dev), device_get_unit(dev));
266 if (pci_get_powerstate(dev) != PCI_POWERSTATE_D0) {
267 uint32_t mem1, mem2, irq;
269 mem1 = pci_read_config(dev, sc->chip_mem1_rid, 4);
270 mem2 = pci_read_config(dev, sc->chip_mem2_rid, 4);
271 irq = pci_read_config(dev, PCIR_INTLINE, 4);
273 device_printf(dev, "chip is in D%d power mode "
274 "-- setting to D0\n", pci_get_powerstate(dev));
276 pci_set_powerstate(dev, PCI_POWERSTATE_D0);
278 pci_write_config(dev, sc->chip_mem1_rid, mem1, 4);
279 pci_write_config(dev, sc->chip_mem2_rid, mem2, 4);
280 pci_write_config(dev, PCIR_INTLINE, irq, 4);
282 #endif /* !BURN_BRIDGE */
284 /* Enable bus mastering */
285 pci_enable_busmaster(dev);
287 /* Allocate IO memory 1 */
288 sc->sc_mem1_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY,
291 if (sc->sc_mem1_res == NULL) {
293 device_printf(dev, "can't allocate IO mem1\n");
296 sc->sc_mem1_bt = rman_get_bustag(sc->sc_mem1_res);
297 sc->sc_mem1_bh = rman_get_bushandle(sc->sc_mem1_res);
299 /* Allocate IO memory 2 */
300 sc->sc_mem2_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY,
303 if (sc->sc_mem2_res == NULL) {
305 device_printf(dev, "can't allocate IO mem2\n");
308 sc->sc_mem2_bt = rman_get_bustag(sc->sc_mem2_res);
309 sc->sc_mem2_bh = rman_get_bushandle(sc->sc_mem2_res);
312 sc->sc_irq_res = bus_alloc_resource_any(dev, SYS_RES_IRQ,
314 RF_SHAREABLE | RF_ACTIVE);
315 if (sc->sc_irq_res == NULL) {
317 device_printf(dev, "can't allocate intr\n");
321 /* Initilize channel scanning timer */
322 callout_init(&sc->sc_scan_timer);
324 /* Allocate busdma stuffs */
325 error = acx_dma_alloc(sc);
330 error = acx_reset(sc);
334 /* Disable interrupts before firmware is loaded */
335 acx_disable_intr(sc);
337 /* Get radio type and form factor */
338 #define EEINFO_RETRY_MAX 50
339 for (i = 0; i < EEINFO_RETRY_MAX; ++i) {
342 ee_info = CSR_READ_2(sc, ACXREG_EEPROM_INFO);
343 if (ACX_EEINFO_HAS_RADIO_TYPE(ee_info)) {
344 sc->sc_form_factor = ACX_EEINFO_FORM_FACTOR(ee_info);
345 sc->sc_radio_type = ACX_EEINFO_RADIO_TYPE(ee_info);
350 if (i == EEINFO_RETRY_MAX) {
354 #undef EEINFO_RETRY_MAX
356 DPRINTF((&sc->sc_ic.ic_if, "radio type %02x\n", sc->sc_radio_type));
359 for (i = 0; i < 0x40; ++i) {
362 error = acx_read_eeprom(sc, i, &val);
365 kprintf("%02x ", val);
368 #endif /* DUMP_EEPROM */
370 /* Get EEPROM version */
371 error = acx_read_eeprom(sc, ACX_EE_VERSION_OFS, &sc->sc_eeprom_ver);
374 DPRINTF((&sc->sc_ic.ic_if, "EEPROM version %u\n", sc->sc_eeprom_ver));
377 ifp->if_init = acx_init;
378 ifp->if_ioctl = acx_ioctl;
379 ifp->if_start = acx_start;
380 ifp->if_watchdog = acx_watchdog;
381 ifp->if_flags = IFF_SIMPLEX | IFF_BROADCAST | IFF_MULTICAST;
382 ifq_set_maxlen(&ifp->if_snd, IFQ_MAXLEN);
383 ifq_set_ready(&ifp->if_snd);
386 for (i = 1; i <= 14; ++i) {
387 ic->ic_channels[i].ic_freq =
388 ieee80211_ieee2mhz(i, IEEE80211_CHAN_2GHZ);
389 ic->ic_channels[i].ic_flags = sc->chip_chan_flags;
392 ic->ic_opmode = IEEE80211_M_STA;
393 ic->ic_state = IEEE80211_S_INIT;
396 * NOTE: Don't overwrite ic_caps set by chip specific code
398 ic->ic_caps |= IEEE80211_C_WEP | /* WEP */
399 IEEE80211_C_HOSTAP | /* HostAP mode */
400 IEEE80211_C_MONITOR | /* Monitor mode */
401 IEEE80211_C_IBSS | /* IBSS modes */
402 IEEE80211_C_SHPREAMBLE; /* Short preamble */
403 ic->ic_caps_ext = IEEE80211_CEXT_PBCC; /* PBCC modulation */
406 for (i = 0; i < IEEE80211_ADDR_LEN; ++i) {
407 error = acx_read_eeprom(sc, sc->chip_ee_eaddr_ofs - i,
411 ieee80211_ifattach(ic);
413 /* Enable software beacon missing */
414 ic->ic_flags_ext |= IEEE80211_FEXT_SWBMISS;
416 /* Override newstate */
417 sc->sc_newstate = ic->ic_newstate;
418 ic->ic_newstate = acx_newstate;
420 ieee80211_media_init(ic, acx_media_change, ieee80211_media_status);
422 sc->sc_long_retry_limit = 4;
423 sc->sc_msdu_lifetime = 4096;
424 sc->sc_scan_dwell = 200; /* 200 milliseconds */
426 sysctl_ctx_init(&sc->sc_sysctl_ctx);
427 sc->sc_sysctl_tree = SYSCTL_ADD_NODE(&sc->sc_sysctl_ctx,
428 SYSCTL_STATIC_CHILDREN(_hw),
430 device_get_nameunit(dev),
432 if (sc->sc_sysctl_tree == NULL) {
433 device_printf(dev, "can't add sysctl node\n");
438 SYSCTL_ADD_PROC(&sc->sc_sysctl_ctx,
439 SYSCTL_CHILDREN(sc->sc_sysctl_tree),
440 OID_AUTO, "msdu_lifetime",
441 CTLTYPE_INT | CTLFLAG_RW,
442 sc, 0, acx_sysctl_msdu_lifetime, "I",
445 error = bus_setup_intr(dev, sc->sc_irq_res, INTR_MPSAFE, acx_intr, sc,
446 &sc->sc_irq_handle, ifp->if_serializer);
448 device_printf(dev, "can't set up interrupt\n");
453 ieee80211_announce(ic);
457 ieee80211_ifdetach(ic);
464 acx_detach(device_t dev)
466 struct acx_softc *sc = device_get_softc(dev);
468 if (device_is_attached(dev)) {
469 struct ieee80211com *ic = &sc->sc_ic;
470 struct ifnet *ifp = &ic->ic_if;
472 lwkt_serialize_enter(ifp->if_serializer);
475 acx_free_firmware(sc);
476 bus_teardown_intr(dev, sc->sc_irq_res, sc->sc_irq_handle);
478 lwkt_serialize_exit(ifp->if_serializer);
480 ieee80211_ifdetach(ic);
483 if (sc->sc_sysctl_tree != NULL)
484 sysctl_ctx_free(&sc->sc_sysctl_ctx);
486 if (sc->sc_irq_res != NULL) {
487 bus_release_resource(dev, SYS_RES_IRQ, sc->sc_irq_rid,
490 if (sc->sc_mem1_res != NULL) {
491 bus_release_resource(dev, SYS_RES_MEMORY, sc->chip_mem1_rid,
494 if (sc->sc_mem2_res != NULL) {
495 bus_release_resource(dev, SYS_RES_MEMORY, sc->chip_mem2_rid,
504 acx_shutdown(device_t dev)
506 struct acx_softc *sc = device_get_softc(dev);
508 lwkt_serialize_enter(sc->sc_ic.ic_if.if_serializer);
510 lwkt_serialize_exit(sc->sc_ic.ic_if.if_serializer);
517 struct acx_softc *sc = arg;
518 struct ieee80211com *ic = &sc->sc_ic;
519 struct ifnet *ifp = &ic->ic_if;
520 struct acx_firmware *fw = &sc->sc_firmware;
523 error = acx_stop(sc);
527 if (fw->base_fw == NULL) {
529 if_printf(ifp, "base firmware is not loaded yet\n");
533 error = acx_init_tx_ring(sc);
535 if_printf(ifp, "can't initialize TX ring\n");
539 error = acx_init_rx_ring(sc);
541 if_printf(ifp, "can't initialize RX ring\n");
545 error = acx_load_base_firmware(sc, fw->base_fw, fw->base_fw_len);
550 * Initialize command and information registers
551 * NOTE: This should be done after base firmware is loaded
553 acx_init_cmd_reg(sc);
554 acx_init_info_reg(sc);
556 sc->sc_flags |= ACX_FLAG_FW_LOADED;
559 if (sc->chip_post_basefw != NULL) {
560 error = sc->chip_post_basefw(sc);
566 if (fw->radio_fw != NULL) {
567 error = acx_load_radio_firmware(sc, fw->radio_fw,
573 error = sc->chip_init(sc);
577 /* Get and set device various configuration */
578 error = acx_config(sc);
582 /* Setup crypto stuffs */
583 if (sc->sc_ic.ic_flags & IEEE80211_F_PRIVACY) {
584 error = acx_set_crypt_keys(sc);
587 sc->sc_ic.ic_flags &= ~IEEE80211_F_DROPUNENC;
590 /* Turn on power led */
591 CSR_CLRB_2(sc, ACXREG_GPIO_OUT, sc->chip_gpio_pled);
595 ifp->if_flags |= IFF_RUNNING;
596 ifp->if_flags &= ~IFF_OACTIVE;
598 if (ic->ic_opmode != IEEE80211_M_MONITOR) {
599 if (ic->ic_roaming != IEEE80211_ROAMING_MANUAL)
600 ieee80211_new_state(&sc->sc_ic, IEEE80211_S_SCAN, -1);
602 ieee80211_new_state(ic, IEEE80211_S_RUN, -1);
610 acx_init_info_reg(struct acx_softc *sc)
612 sc->sc_info = CSR_READ_4(sc, ACXREG_INFO_REG_OFFSET);
613 sc->sc_info_param = sc->sc_info + ACX_INFO_REG_SIZE;
617 acx_set_crypt_keys(struct acx_softc *sc)
619 struct ieee80211com *ic = &sc->sc_ic;
620 struct acx_conf_wep_txkey wep_txkey;
621 int i, error, got_wk = 0;
623 for (i = 0; i < IEEE80211_WEP_NKID; ++i) {
624 struct ieee80211_key *wk = &ic->ic_nw_keys[i];
626 if (wk->wk_keylen == 0)
629 if (sc->chip_hw_crypt) {
630 error = sc->chip_set_wepkey(sc, wk, i);
634 } else if (wk->wk_flags & IEEE80211_KEY_XMIT) {
635 wk->wk_flags |= IEEE80211_KEY_SWCRYPT;
639 if (!got_wk || sc->chip_hw_crypt ||
640 ic->ic_def_txkey == IEEE80211_KEYIX_NONE)
643 /* Set current WEP key index */
644 wep_txkey.wep_txkey = ic->ic_def_txkey;
645 if (acx_set_wep_txkey_conf(sc, &wep_txkey) != 0) {
646 if_printf(&ic->ic_if, "set WEP txkey failed\n");
653 acx_next_scan(void *arg)
655 struct acx_softc *sc = arg;
656 struct ieee80211com *ic = &sc->sc_ic;
657 struct ifnet *ifp = &ic->ic_if;
659 lwkt_serialize_enter(ifp->if_serializer);
661 if (ic->ic_state == IEEE80211_S_SCAN)
662 ieee80211_next_scan(ic);
664 lwkt_serialize_exit(ifp->if_serializer);
668 acx_stop(struct acx_softc *sc)
670 struct ieee80211com *ic = &sc->sc_ic;
671 struct ifnet *ifp = &ic->ic_if;
672 struct acx_buf_data *bd = &sc->sc_buf_data;
673 struct acx_ring_data *rd = &sc->sc_ring_data;
676 ASSERT_SERIALIZED(ifp->if_serializer);
678 ieee80211_new_state(&sc->sc_ic, IEEE80211_S_INIT, -1);
680 sc->sc_firmware_ver = 0;
681 sc->sc_hardware_id = 0;
684 error = acx_reset(sc);
688 /* Firmware no longer functions after hardware reset */
689 sc->sc_flags &= ~ACX_FLAG_FW_LOADED;
691 acx_disable_intr(sc);
693 /* Stop backgroud scanning */
694 callout_stop(&sc->sc_scan_timer);
696 /* Turn off power led */
697 CSR_SETB_2(sc, ACXREG_GPIO_OUT, sc->chip_gpio_pled);
700 for (i = 0; i < ACX_TX_DESC_CNT; ++i) {
701 struct acx_txbuf *buf;
703 buf = &bd->tx_buf[i];
705 if (buf->tb_mbuf != NULL) {
706 bus_dmamap_unload(bd->mbuf_dma_tag,
707 buf->tb_mbuf_dmamap);
708 m_freem(buf->tb_mbuf);
712 if (buf->tb_node != NULL)
713 ieee80211_free_node(buf->tb_node);
717 /* Clear TX host descriptors */
718 bzero(rd->tx_ring, ACX_TX_RING_SIZE);
721 for (i = 0; i < ACX_RX_DESC_CNT; ++i) {
722 if (bd->rx_buf[i].rb_mbuf != NULL) {
723 bus_dmamap_unload(bd->mbuf_dma_tag,
724 bd->rx_buf[i].rb_mbuf_dmamap);
725 m_freem(bd->rx_buf[i].rb_mbuf);
726 bd->rx_buf[i].rb_mbuf = NULL;
730 /* Clear RX host descriptors */
731 bzero(rd->rx_ring, ACX_RX_RING_SIZE);
735 ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE);
741 acx_config(struct acx_softc *sc)
743 struct acx_config conf;
746 error = acx_read_config(sc, &conf);
750 error = acx_write_config(sc, &conf);
754 error = acx_rx_config(sc, sc->sc_flags & ACX_FLAG_PROMISC);
758 if (acx_set_probe_req_tmplt(sc, "", 0) != 0) {
759 if_printf(&sc->sc_ic.ic_if, "can't set probe req template "
765 if (acx_set_null_tmplt(sc) != 0) {
766 if_printf(&sc->sc_ic.ic_if, "can't set null data template\n");
773 acx_read_config(struct acx_softc *sc, struct acx_config *conf)
775 struct acx_conf_eaddr addr;
776 struct acx_conf_regdom reg_dom;
777 struct acx_conf_antenna ant;
778 struct acx_conf_fwrev fw_rev;
784 if (acx_get_eaddr_conf(sc, &addr) != 0) {
785 if_printf(&sc->sc_ic.ic_if, "can't get station id\n");
790 * Get and print station id in case that EEPROM station id's
791 * offset is not correct
793 for (i = 0; i < IEEE80211_ADDR_LEN; ++i)
794 conf->eaddr[IEEE80211_ADDR_LEN - 1 - i] = addr.eaddr[i];
795 if_printf(&sc->sc_ic.ic_if, "MAC address (from firmware): %6D\n",
798 /* Get region domain */
799 if (acx_get_regdom_conf(sc, ®_dom) != 0) {
800 if_printf(&sc->sc_ic.ic_if, "can't get region domain\n");
803 conf->regdom = reg_dom.regdom;
804 DPRINTF((&sc->sc_ic.ic_if, "regdom %02x\n", reg_dom.regdom));
807 if (acx_get_antenna_conf(sc, &ant) != 0) {
808 if_printf(&sc->sc_ic.ic_if, "can't get antenna\n");
811 conf->antenna = ant.antenna;
812 DPRINTF((&sc->sc_ic.ic_if, "antenna %02x\n", ant.antenna));
814 /* Get sensitivity XXX not used */
815 if (sc->sc_radio_type == ACX_RADIO_TYPE_MAXIM ||
816 sc->sc_radio_type == ACX_RADIO_TYPE_RFMD ||
817 sc->sc_radio_type == ACX_RADIO_TYPE_RALINK) {
818 error = acx_read_phyreg(sc, ACXRV_PHYREG_SENSITIVITY, &sen);
820 if_printf(&sc->sc_ic.ic_if, "can't get sensitivity\n");
826 DPRINTF((&sc->sc_ic.ic_if, "sensitivity %02x\n", sen));
828 /* Get firmware revision */
829 if (acx_get_fwrev_conf(sc, &fw_rev) != 0) {
830 if_printf(&sc->sc_ic.ic_if, "can't get firmware revision\n");
834 if (strncmp(fw_rev.fw_rev, "Rev ", 4) != 0) {
835 if_printf(&sc->sc_ic.ic_if, "strange revision string -- %s\n",
837 fw_rev_no = 0x01090407;
846 s = &fw_rev.fw_rev[4];
848 for (i = 0; i < 4; ++i) {
851 val = strtoul(s, &endp, 16);
852 fw_rev_no |= val << ((3 - i) * 8);
860 sc->sc_firmware_ver = fw_rev_no;
861 sc->sc_hardware_id = le32toh(fw_rev.hw_id);
862 DPRINTF((&sc->sc_ic.ic_if, "fw rev %08x, hw id %08x\n",
863 sc->sc_firmware_ver, sc->sc_hardware_id));
865 if (sc->chip_read_config != NULL) {
866 error = sc->chip_read_config(sc, conf);
874 acx_write_config(struct acx_softc *sc, struct acx_config *conf)
876 struct acx_conf_nretry_short sretry;
877 struct acx_conf_nretry_long lretry;
878 struct acx_conf_msdu_lifetime msdu_lifetime;
879 struct acx_conf_rate_fallback rate_fb;
880 struct acx_conf_antenna ant;
881 struct acx_conf_regdom reg_dom;
884 /* Set number of long/short retry */
885 KKASSERT(sc->chip_short_retry_limit > 0);
886 sretry.nretry = sc->chip_short_retry_limit;
887 if (acx_set_nretry_short_conf(sc, &sretry) != 0) {
888 if_printf(&sc->sc_ic.ic_if, "can't set short retry limit\n");
892 lretry.nretry = sc->sc_long_retry_limit;
893 if (acx_set_nretry_long_conf(sc, &lretry) != 0) {
894 if_printf(&sc->sc_ic.ic_if, "can't set long retry limit\n");
898 /* Set MSDU lifetime */
899 msdu_lifetime.lifetime = htole32(sc->sc_msdu_lifetime);
900 if (acx_set_msdu_lifetime_conf(sc, &msdu_lifetime) != 0) {
901 if_printf(&sc->sc_ic.ic_if, "can't set MSDU lifetime\n");
905 /* Enable rate fallback */
906 rate_fb.ratefb_enable = 1;
907 if (acx_set_rate_fallback_conf(sc, &rate_fb) != 0) {
908 if_printf(&sc->sc_ic.ic_if, "can't enable rate fallback\n");
913 ant.antenna = conf->antenna;
914 if (acx_set_antenna_conf(sc, &ant) != 0) {
915 if_printf(&sc->sc_ic.ic_if, "can't set antenna\n");
919 /* Set region domain */
920 reg_dom.regdom = conf->regdom;
921 if (acx_set_regdom_conf(sc, ®_dom) != 0) {
922 if_printf(&sc->sc_ic.ic_if, "can't set region domain\n");
926 if (sc->chip_write_config != NULL) {
927 error = sc->chip_write_config(sc, conf);
936 acx_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data, struct ucred *cr)
938 struct acx_softc *sc = ifp->if_softc;
939 struct ieee80211com *ic = &sc->sc_ic;
944 req = (struct ifreq *)data;
948 error = suser_cred(cr, NULL_CRED_OKAY);
952 error = acx_copyin_firmware(sc, req);
955 error = suser_cred(cr, NULL_CRED_OKAY);
958 acx_free_firmware(sc);
961 error = copyout(&sc->sc_radio_type, req->ifr_data,
962 sizeof(sc->sc_radio_type));
965 error = copyout(&sc->sc_firmware_ver, req->ifr_data,
966 sizeof(sc->sc_firmware_ver));
969 error = copyout(&sc->sc_hardware_id, req->ifr_data,
970 sizeof(sc->sc_hardware_id));
973 error = copyout(&sc->sc_stats, req->ifr_data,
974 sizeof(sc->sc_stats));
977 if (ifp->if_flags & IFF_UP) {
978 if ((ifp->if_flags & IFF_RUNNING)) {
981 if ((ifp->if_flags & IFF_PROMISC) &&
982 (sc->sc_flags & ACX_FLAG_PROMISC) == 0)
984 else if ((ifp->if_flags & IFF_PROMISC) == 0 &&
985 (sc->sc_flags & ACX_FLAG_PROMISC))
989 * Promisc mode is always enabled when
990 * operation mode is Monitor.
992 if (ic->ic_opmode != IEEE80211_M_MONITOR &&
994 error = acx_rx_config(sc, promisc);
999 if (ifp->if_flags & IFF_RUNNING)
1003 if (ifp->if_flags & IFF_PROMISC)
1004 sc->sc_flags |= ACX_FLAG_PROMISC;
1006 sc->sc_flags &= ~ACX_FLAG_PROMISC;
1013 error = ieee80211_ioctl(ic, cmd, data, cr);
1017 if (error == ENETRESET) {
1018 if ((ifp->if_flags & (IFF_RUNNING | IFF_UP)) ==
1019 (IFF_RUNNING | IFF_UP))
1027 acx_start(struct ifnet *ifp)
1029 struct acx_softc *sc = ifp->if_softc;
1030 struct ieee80211com *ic = &sc->sc_ic;
1031 struct acx_buf_data *bd = &sc->sc_buf_data;
1032 struct acx_txbuf *buf;
1035 ASSERT_SERIALIZED(ifp->if_serializer);
1037 if ((sc->sc_flags & ACX_FLAG_FW_LOADED) == 0 ||
1038 (ifp->if_flags & IFF_RUNNING) == 0 ||
1039 (ifp->if_flags & IFF_OACTIVE))
1044 * We can't start from a random position that TX descriptor
1045 * is free, since hardware will be confused by that.
1046 * We have to follow the order of the TX ring.
1048 idx = bd->tx_free_start;
1050 for (buf = &bd->tx_buf[idx]; buf->tb_mbuf == NULL;
1051 buf = &bd->tx_buf[idx]) {
1052 struct ieee80211_frame *f;
1053 struct ieee80211_node *ni = NULL;
1057 if (!IF_QEMPTY(&ic->ic_mgtq)) {
1058 IF_DEQUEUE(&ic->ic_mgtq, m);
1060 ni = (struct ieee80211_node *)m->m_pkthdr.rcvif;
1061 m->m_pkthdr.rcvif = NULL;
1066 * Don't transmit probe response firmware will
1069 f = mtod(m, struct ieee80211_frame *);
1070 if ((f->i_fc[0] & IEEE80211_FC0_TYPE_MASK) ==
1071 IEEE80211_FC0_TYPE_MGT &&
1072 (f->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK) ==
1073 IEEE80211_FC0_SUBTYPE_PROBE_RESP) {
1075 ieee80211_free_node(ni);
1079 } else if (!ifq_is_empty(&ifp->if_snd)) {
1080 struct ether_header *eh;
1082 if (ic->ic_state != IEEE80211_S_RUN)
1085 m = ifq_dequeue(&ifp->if_snd, NULL);
1089 if (m->m_len < sizeof(struct ether_header)) {
1090 m = m_pullup(m, sizeof(struct ether_header));
1096 eh = mtod(m, struct ether_header *);
1098 ni = ieee80211_find_txnode(ic, eh->ether_dhost);
1105 /* TODO power save */
1109 m = ieee80211_encap(ic, m, ni);
1111 ieee80211_free_node(ni);
1119 if (ic->ic_rawbpf != NULL)
1120 bpf_mtap(ic->ic_rawbpf, m);
1122 f = mtod(m, struct ieee80211_frame *);
1123 if ((f->i_fc[1] & IEEE80211_FC1_WEP) && !sc->chip_hw_crypt) {
1124 KASSERT(ni != NULL, ("TX node is NULL (WEP)\n"));
1125 if (ieee80211_crypto_encap(ic, ni, m) == NULL) {
1126 ieee80211_free_node(ni);
1134 * Since mgmt data are transmitted at fixed rate
1135 * they will not be used to do rate control.
1137 if (mgmt_pkt && ni != NULL) {
1138 ieee80211_free_node(ni);
1142 if (acx_encap(sc, buf, m, ni) != 0) {
1144 * NOTE: `m' will be freed in acx_encap()
1148 ieee80211_free_node(ni);
1155 * 1) `m' should not be touched after acx_encap()
1156 * 2) `node' will be used to do TX rate control during
1157 * acx_txeof(), so it is not freed here. acx_txeof()
1158 * will free it for us
1162 bd->tx_used_count++;
1163 idx = (idx + 1) % ACX_TX_DESC_CNT;
1165 bd->tx_free_start = idx;
1167 if (bd->tx_used_count == ACX_TX_DESC_CNT)
1168 ifp->if_flags |= IFF_OACTIVE;
1170 if (trans && sc->sc_tx_timer == 0)
1171 sc->sc_tx_timer = 5;
1176 acx_watchdog(struct ifnet *ifp)
1178 struct acx_softc *sc = ifp->if_softc;
1182 if ((ifp->if_flags & IFF_RUNNING) == 0)
1185 if (sc->sc_tx_timer) {
1186 if (--sc->sc_tx_timer == 0) {
1187 if_printf(ifp, "watchdog timeout\n");
1189 acx_txeof(ifp->if_softc);
1194 ieee80211_watchdog(&sc->sc_ic);
1200 struct acx_softc *sc = arg;
1201 uint16_t intr_status;
1203 if ((sc->sc_flags & ACX_FLAG_FW_LOADED) == 0)
1206 intr_status = CSR_READ_2(sc, ACXREG_INTR_STATUS_CLR);
1207 if (intr_status == ACXRV_INTR_ALL) {
1208 /* not our interrupt */
1212 intr_status &= sc->chip_intr_enable;
1213 if (intr_status == 0) {
1214 /* not interrupts we care about */
1218 /* Acknowledge all interrupts */
1219 CSR_WRITE_2(sc, ACXREG_INTR_ACK, ACXRV_INTR_ALL);
1221 if (intr_status & ACXRV_INTR_TX_FINI)
1224 if (intr_status & ACXRV_INTR_RX_FINI)
1229 acx_disable_intr(struct acx_softc *sc)
1231 CSR_WRITE_2(sc, ACXREG_INTR_MASK, sc->chip_intr_disable);
1232 CSR_WRITE_2(sc, ACXREG_EVENT_MASK, 0);
1236 acx_enable_intr(struct acx_softc *sc)
1238 /* Mask out interrupts that are not in the enable set */
1239 CSR_WRITE_2(sc, ACXREG_INTR_MASK, ~sc->chip_intr_enable);
1240 CSR_WRITE_2(sc, ACXREG_EVENT_MASK, ACXRV_EVENT_DISABLE);
1244 acx_txeof(struct acx_softc *sc)
1246 struct acx_buf_data *bd;
1247 struct acx_txbuf *buf;
1251 ifp = &sc->sc_ic.ic_if;
1252 ASSERT_SERIALIZED(ifp->if_serializer);
1254 bd = &sc->sc_buf_data;
1255 idx = bd->tx_used_start;
1256 for (buf = &bd->tx_buf[idx]; buf->tb_mbuf != NULL;
1257 buf = &bd->tx_buf[idx]) {
1258 uint8_t ctrl, error;
1261 ctrl = FW_TXDESC_GETFIELD_1(sc, buf, f_tx_ctrl);
1262 if ((ctrl & (DESC_CTRL_HOSTOWN | DESC_CTRL_ACXDONE)) !=
1263 (DESC_CTRL_HOSTOWN | DESC_CTRL_ACXDONE))
1266 bus_dmamap_unload(bd->mbuf_dma_tag, buf->tb_mbuf_dmamap);
1267 frame_len = buf->tb_mbuf->m_pkthdr.len;
1268 m_freem(buf->tb_mbuf);
1269 buf->tb_mbuf = NULL;
1271 error = FW_TXDESC_GETFIELD_1(sc, buf, f_tx_error);
1273 acx_txerr(sc, error);
1279 if (buf->tb_node != NULL) {
1280 sc->chip_tx_complete(sc, buf, frame_len, error);
1281 ieee80211_free_node(buf->tb_node);
1282 buf->tb_node = NULL;
1285 FW_TXDESC_SETFIELD_1(sc, buf, f_tx_ctrl, DESC_CTRL_HOSTOWN);
1287 bd->tx_used_count--;
1289 idx = (idx + 1) % ACX_TX_DESC_CNT;
1291 bd->tx_used_start = idx;
1293 sc->sc_tx_timer = bd->tx_used_count == 0 ? 0 : 5;
1295 if (bd->tx_used_count != ACX_TX_DESC_CNT) {
1296 ifp->if_flags &= ~IFF_OACTIVE;
1302 acx_txerr(struct acx_softc *sc, uint8_t err)
1304 struct ifnet *ifp = &sc->sc_ic.ic_if;
1305 struct acx_stats *stats = &sc->sc_stats;
1307 if (err == DESC_ERR_EXCESSIVE_RETRY) {
1309 * This a common error (see comment below),
1310 * so print it using DPRINTF()
1312 DPRINTF((ifp, "TX failed -- excessive retry\n"));
1314 if_printf(ifp, "TX failed -- ");
1318 * Although `err' looks like bitmask, it never
1319 * has multiple bits set.
1323 case DESC_ERR_OTHER_FRAG:
1324 /* XXX what's this */
1325 kprintf("error in other fragment\n");
1326 stats->err_oth_frag++;
1329 case DESC_ERR_ABORT:
1330 kprintf("aborted\n");
1333 case DESC_ERR_PARAM:
1334 kprintf("wrong paramters in descriptor\n");
1337 case DESC_ERR_NO_WEPKEY:
1338 kprintf("WEP key missing\n");
1339 stats->err_no_wepkey++;
1341 case DESC_ERR_MSDU_TIMEOUT:
1342 kprintf("MSDU life timeout\n");
1343 stats->err_msdu_timeout++;
1345 case DESC_ERR_EXCESSIVE_RETRY:
1348 * 1) Distance is too long
1349 * 2) Transmit failed (e.g. no MAC level ACK)
1350 * 3) Chip overheated (this should be rare)
1352 stats->err_ex_retry++;
1354 case DESC_ERR_BUF_OVERFLOW:
1355 kprintf("buffer overflow\n");
1356 stats->err_buf_oflow++;
1359 kprintf("DMA error\n");
1363 kprintf("unknown error %d\n", err);
1370 acx_rxeof(struct acx_softc *sc)
1372 struct ieee80211com *ic = &sc->sc_ic;
1373 struct acx_ring_data *rd = &sc->sc_ring_data;
1374 struct acx_buf_data *bd = &sc->sc_buf_data;
1375 struct ifnet *ifp = &ic->ic_if;
1378 ASSERT_SERIALIZED(ic->ic_if.if_serializer);
1380 bus_dmamap_sync(rd->rx_ring_dma_tag, rd->rx_ring_dmamap,
1381 BUS_DMASYNC_POSTREAD);
1384 * Locate first "ready" rx buffer,
1385 * start from last stopped position
1387 idx = bd->rx_scan_start;
1390 struct acx_rxbuf *buf;
1392 buf = &bd->rx_buf[idx];
1393 if ((buf->rb_desc->h_ctrl & htole16(DESC_CTRL_HOSTOWN)) &&
1394 (buf->rb_desc->h_status & htole32(DESC_STATUS_FULL))) {
1398 idx = (idx + 1) % ACX_RX_DESC_CNT;
1399 } while (idx != bd->rx_scan_start);
1405 * NOTE: don't mess up `idx' here, it will
1406 * be used in the following code
1410 struct acx_rxbuf_hdr *head;
1411 struct acx_rxbuf *buf;
1413 uint32_t desc_status;
1417 buf = &bd->rx_buf[idx];
1419 desc_ctrl = le16toh(buf->rb_desc->h_ctrl);
1420 desc_status = le32toh(buf->rb_desc->h_status);
1421 if (!(desc_ctrl & DESC_CTRL_HOSTOWN) ||
1422 !(desc_status & DESC_STATUS_FULL))
1425 bus_dmamap_sync(bd->mbuf_dma_tag, buf->rb_mbuf_dmamap,
1426 BUS_DMASYNC_POSTREAD);
1430 error = acx_newbuf(sc, buf, 0);
1436 head = mtod(m, struct acx_rxbuf_hdr *);
1438 len = le16toh(head->rbh_len) & ACX_RXBUF_LEN_MASK;
1439 if (len >= sizeof(struct ieee80211_frame_min) &&
1441 struct ieee80211_frame_min *f;
1442 struct ieee80211_node *ni;
1445 m_adj(m, sizeof(struct acx_rxbuf_hdr) +
1446 sc->chip_rxbuf_exhdr);
1447 f = mtod(m, struct ieee80211_frame_min *);
1449 if ((f->i_fc[1] & IEEE80211_FC1_WEP) &&
1450 sc->chip_hw_crypt) {
1451 /* Short circuit software WEP */
1452 f->i_fc[1] &= ~IEEE80211_FC1_WEP;
1454 /* Do chip specific RX buffer processing */
1455 if (sc->chip_proc_wep_rxbuf != NULL) {
1456 sc->chip_proc_wep_rxbuf(sc, m, &len);
1458 struct ieee80211_frame_min *);
1462 rssi = acx_get_rssi(sc, head->rbh_level);
1464 ni = ieee80211_find_rxnode(ic, f);
1466 m->m_len = m->m_pkthdr.len = len;
1467 m->m_pkthdr.rcvif = &ic->ic_if;
1469 ieee80211_input(ic, m, ni, rssi,
1470 le32toh(head->rbh_time));
1472 ieee80211_free_node(ni);
1475 if (len < sizeof(struct ieee80211_frame_min)) {
1476 if (ic->ic_rawbpf != NULL &&
1477 len >= sizeof(struct ieee80211_frame_ack)) {
1478 m_adj(m, sizeof(struct acx_rxbuf_hdr) +
1479 sc->chip_rxbuf_exhdr);
1480 m->m_len = m->m_pkthdr.len = len;
1481 m->m_pkthdr.rcvif = &ic->ic_if;
1482 bpf_mtap(ic->ic_rawbpf, m);
1485 if (ic->ic_opmode != IEEE80211_M_MONITOR)
1486 ic->ic_stats.is_rx_tooshort++;
1492 buf->rb_desc->h_ctrl = htole16(desc_ctrl & ~DESC_CTRL_HOSTOWN);
1493 buf->rb_desc->h_status = 0;
1494 bus_dmamap_sync(rd->rx_ring_dma_tag, rd->rx_ring_dmamap,
1495 BUS_DMASYNC_PREWRITE);
1497 idx = (idx + 1) % ACX_RX_DESC_CNT;
1498 } while (idx != bd->rx_scan_start);
1501 * Record the position so that next
1502 * time we can start from it
1504 bd->rx_scan_start = idx;
1508 acx_reset(struct acx_softc *sc)
1513 CSR_SETB_2(sc, ACXREG_ECPU_CTRL, ACXRV_ECPU_HALT);
1515 /* Software reset */
1516 reg = CSR_READ_2(sc, ACXREG_SOFT_RESET);
1517 CSR_WRITE_2(sc, ACXREG_SOFT_RESET, reg | ACXRV_SOFT_RESET);
1519 CSR_WRITE_2(sc, ACXREG_SOFT_RESET, reg);
1521 /* Initialize EEPROM */
1522 CSR_SETB_2(sc, ACXREG_EEPROM_INIT, ACXRV_EEPROM_INIT);
1525 /* Test whether ECPU is stopped */
1526 reg = CSR_READ_2(sc, ACXREG_ECPU_CTRL);
1527 if (!(reg & ACXRV_ECPU_HALT)) {
1528 if_printf(&sc->sc_ic.ic_if, "can't halt ECPU\n");
1535 acx_read_eeprom(struct acx_softc *sc, uint32_t offset, uint8_t *val)
1539 CSR_WRITE_4(sc, ACXREG_EEPROM_CONF, 0);
1540 CSR_WRITE_4(sc, ACXREG_EEPROM_ADDR, offset);
1541 CSR_WRITE_4(sc, ACXREG_EEPROM_CTRL, ACXRV_EEPROM_READ);
1543 #define EE_READ_RETRY_MAX 100
1544 for (i = 0; i < EE_READ_RETRY_MAX; ++i) {
1545 if (CSR_READ_2(sc, ACXREG_EEPROM_CTRL) == 0)
1549 if (i == EE_READ_RETRY_MAX) {
1550 if_printf(&sc->sc_ic.ic_if, "can't read EEPROM offset %x "
1551 "(timeout)\n", offset);
1554 #undef EE_READ_RETRY_MAX
1556 *val = CSR_READ_1(sc, ACXREG_EEPROM_DATA);
1561 acx_read_phyreg(struct acx_softc *sc, uint32_t reg, uint8_t *val)
1565 CSR_WRITE_4(sc, ACXREG_PHY_ADDR, reg);
1566 CSR_WRITE_4(sc, ACXREG_PHY_CTRL, ACXRV_PHY_READ);
1568 #define PHY_READ_RETRY_MAX 100
1569 for (i = 0; i < PHY_READ_RETRY_MAX; ++i) {
1570 if (CSR_READ_4(sc, ACXREG_PHY_CTRL) == 0)
1574 if (i == PHY_READ_RETRY_MAX) {
1575 if_printf(&sc->sc_ic.ic_if, "can't read phy reg %x (timeout)\n",
1579 #undef PHY_READ_RETRY_MAX
1581 *val = CSR_READ_1(sc, ACXREG_PHY_DATA);
1586 acx_write_phyreg(struct acx_softc *sc, uint32_t reg, uint8_t val)
1588 CSR_WRITE_4(sc, ACXREG_PHY_DATA, val);
1589 CSR_WRITE_4(sc, ACXREG_PHY_ADDR, reg);
1590 CSR_WRITE_4(sc, ACXREG_PHY_CTRL, ACXRV_PHY_WRITE);
1594 acx_copyin_firmware(struct acx_softc *sc, struct ifreq *req)
1596 struct acx_firmware ufw, *kfw;
1597 uint8_t *base_fw, *radio_fw;
1600 kfw = &sc->sc_firmware;
1604 error = copyin(req->ifr_data, &ufw, sizeof(ufw));
1609 * For combined base firmware, there is no radio firmware.
1610 * But base firmware must exist.
1612 if (ufw.base_fw_len <= 0 || ufw.radio_fw_len < 0)
1615 base_fw = kmalloc(ufw.base_fw_len, M_DEVBUF, M_INTWAIT);
1616 error = copyin(ufw.base_fw, base_fw, ufw.base_fw_len);
1620 if (ufw.radio_fw_len > 0) {
1621 radio_fw = kmalloc(ufw.radio_fw_len, M_DEVBUF, M_INTWAIT);
1622 error = copyin(ufw.radio_fw, radio_fw, ufw.radio_fw_len);
1627 kfw->base_fw_len = ufw.base_fw_len;
1628 if (kfw->base_fw != NULL)
1629 kfree(kfw->base_fw, M_DEVBUF);
1630 kfw->base_fw = base_fw;
1632 kfw->radio_fw_len = ufw.radio_fw_len;
1633 if (kfw->radio_fw != NULL)
1634 kfree(kfw->radio_fw, M_DEVBUF);
1635 kfw->radio_fw = radio_fw;
1639 if (base_fw != NULL)
1640 kfree(base_fw, M_DEVBUF);
1641 if (radio_fw != NULL)
1642 kfree(radio_fw, M_DEVBUF);
1647 acx_free_firmware(struct acx_softc *sc)
1649 struct acx_firmware *fw = &sc->sc_firmware;
1651 if (fw->base_fw != NULL) {
1652 kfree(fw->base_fw, M_DEVBUF);
1654 fw->base_fw_len = 0;
1656 if (fw->radio_fw != NULL) {
1657 kfree(fw->radio_fw, M_DEVBUF);
1658 fw->radio_fw = NULL;
1659 fw->radio_fw_len = 0;
1664 acx_load_base_firmware(struct acx_softc *sc, const uint8_t *base_fw,
1665 uint32_t base_fw_len)
1669 /* Load base firmware */
1670 error = acx_load_firmware(sc, 0, base_fw, base_fw_len);
1672 if_printf(&sc->sc_ic.ic_if, "can't load base firmware\n");
1675 DPRINTF((&sc->sc_ic.ic_if, "base firmware loaded\n"));
1678 CSR_WRITE_2(sc, ACXREG_ECPU_CTRL, ACXRV_ECPU_START);
1680 /* Wait for ECPU to be up */
1681 for (i = 0; i < 500; ++i) {
1684 reg = CSR_READ_2(sc, ACXREG_INTR_STATUS);
1685 if (reg & ACXRV_INTR_FCS_THRESH) {
1686 CSR_WRITE_2(sc, ACXREG_INTR_ACK, ACXRV_INTR_FCS_THRESH);
1692 if_printf(&sc->sc_ic.ic_if, "can't initialize ECPU (timeout)\n");
1697 acx_load_radio_firmware(struct acx_softc *sc, const uint8_t *radio_fw,
1698 uint32_t radio_fw_len)
1700 struct acx_conf_mmap mem_map;
1701 uint32_t radio_fw_ofs;
1705 * Get the position, where base firmware is loaded, so that
1706 * radio firmware can be loaded after it.
1708 if (acx_get_mmap_conf(sc, &mem_map) != 0)
1710 radio_fw_ofs = le32toh(mem_map.code_end);
1712 /* Put ECPU into sleeping state, before loading radio firmware */
1713 if (acx_sleep(sc) != 0)
1716 /* Load radio firmware */
1717 error = acx_load_firmware(sc, radio_fw_ofs, radio_fw, radio_fw_len);
1719 if_printf(&sc->sc_ic.ic_if, "can't load radio firmware\n");
1722 DPRINTF((&sc->sc_ic.ic_if, "radio firmware loaded\n"));
1724 /* Wake up sleeping ECPU, after radio firmware is loaded */
1725 if (acx_wakeup(sc) != 0)
1728 /* Initialize radio */
1729 if (acx_init_radio(sc, radio_fw_ofs, radio_fw_len) != 0)
1732 /* Verify radio firmware's loading position */
1733 if (acx_get_mmap_conf(sc, &mem_map) != 0)
1735 if (le32toh(mem_map.code_end) != radio_fw_ofs + radio_fw_len) {
1736 if_printf(&sc->sc_ic.ic_if, "loaded radio firmware position "
1741 DPRINTF((&sc->sc_ic.ic_if, "radio firmware initialized\n"));
1746 acx_load_firmware(struct acx_softc *sc, uint32_t offset, const uint8_t *data,
1752 fw = (const uint32_t *)data;
1753 fw_len = data_len / sizeof(uint32_t);
1756 * LOADFW_AUTO_INC only works with some older firmware:
1757 * 1) acx100's firmware
1758 * 2) acx111's firmware whose rev is 0x00010011
1762 CSR_WRITE_4(sc, ACXREG_FWMEM_START, ACXRV_FWMEM_START_OP);
1763 #ifndef LOADFW_AUTO_INC
1764 CSR_WRITE_4(sc, ACXREG_FWMEM_CTRL, 0);
1766 CSR_WRITE_4(sc, ACXREG_FWMEM_CTRL, ACXRV_FWMEM_ADDR_AUTOINC);
1767 CSR_WRITE_4(sc, ACXREG_FWMEM_ADDR, offset);
1770 for (i = 0; i < fw_len; ++i) {
1771 #ifndef LOADFW_AUTO_INC
1772 CSR_WRITE_4(sc, ACXREG_FWMEM_ADDR, offset + (i * 4));
1774 CSR_WRITE_4(sc, ACXREG_FWMEM_DATA, be32toh(fw[i]));
1777 /* Verify firmware */
1778 CSR_WRITE_4(sc, ACXREG_FWMEM_START, ACXRV_FWMEM_START_OP);
1779 #ifndef LOADFW_AUTO_INC
1780 CSR_WRITE_4(sc, ACXREG_FWMEM_CTRL, 0);
1782 CSR_WRITE_4(sc, ACXREG_FWMEM_CTRL, ACXRV_FWMEM_ADDR_AUTOINC);
1783 CSR_WRITE_4(sc, ACXREG_FWMEM_ADDR, offset);
1786 for (i = 0; i < fw_len; ++i) {
1789 #ifndef LOADFW_AUTO_INC
1790 CSR_WRITE_4(sc, ACXREG_FWMEM_ADDR, offset + (i * 4));
1792 val = CSR_READ_4(sc, ACXREG_FWMEM_DATA);
1793 if (be32toh(fw[i]) != val) {
1794 if_printf(&sc->sc_ic.ic_if, "fireware mismatch "
1795 "fw %08x loaded %08x\n", fw[i], val);
1803 acx_newstate(struct ieee80211com *ic, enum ieee80211_state nstate, int arg)
1805 struct ifnet *ifp = &ic->ic_if;
1806 struct acx_softc *sc = ifp->if_softc;
1807 struct ieee80211_node *ni = NULL;
1808 struct ieee80211_channel *c = NULL;
1809 int error = 1, mode = 0;
1811 ASSERT_SERIALIZED(ifp->if_serializer);
1813 ieee80211_ratectl_newstate(ic, nstate);
1814 callout_stop(&sc->sc_scan_timer);
1817 case IEEE80211_S_SCAN:
1818 acx_set_chan(sc, ic->ic_curchan);
1819 callout_reset(&sc->sc_scan_timer,
1820 (hz * sc->sc_scan_dwell) / 1000,
1823 case IEEE80211_S_AUTH:
1824 if (ic->ic_opmode == IEEE80211_M_STA) {
1827 mode = ACX_MODE_STA;
1830 case IEEE80211_S_RUN:
1831 if (ic->ic_opmode == IEEE80211_M_IBSS ||
1832 ic->ic_opmode == IEEE80211_M_HOSTAP) {
1835 if (ic->ic_opmode == IEEE80211_M_IBSS)
1836 mode = ACX_MODE_ADHOC;
1840 if (acx_set_beacon_tmplt(sc, ni) != 0) {
1841 if_printf(ifp, "set bescon template failed\n");
1844 if (acx_set_probe_resp_tmplt(sc, ni) != 0) {
1845 if_printf(ifp, "set probe response template"
1849 } else if (ic->ic_opmode == IEEE80211_M_MONITOR) {
1852 mode = ACX_MODE_STA;
1860 KKASSERT(c != NULL);
1862 if (acx_set_chan(sc, c) != 0)
1865 if (acx_join_bss(sc, mode, ni, c) != 0) {
1866 if_printf(ifp, "join BSS failed\n");
1875 nstate = IEEE80211_S_INIT;
1878 return sc->sc_newstate(ic, nstate, arg);
1882 acx_init_tmplt_ordered(struct acx_softc *sc)
1884 struct acx_tmplt_tim tim;
1886 #define INIT_TMPLT(name) \
1888 if (acx_init_##name##_tmplt(sc) != 0) \
1894 * Order of templates initialization:
1900 * Above order is critical to get a correct memory map.
1902 INIT_TMPLT(probe_req);
1903 INIT_TMPLT(null_data);
1906 INIT_TMPLT(probe_resp);
1908 /* Setup TIM template */
1909 bzero(&tim, sizeof(tim));
1910 tim.tim_eid = IEEE80211_ELEMID_TIM;
1911 tim.tim_len = ACX_TIM_LEN(ACX_TIM_BITMAP_LEN);
1912 if (_acx_set_tim_tmplt(sc, &tim,
1913 ACX_TMPLT_TIM_SIZ(ACX_TIM_BITMAP_LEN)) != 0) {
1914 if_printf(&sc->sc_ic.ic_if, "%s can't set tim tmplt\n",
1924 acx_ring_dma_addr(void *arg, bus_dma_segment_t *seg, int nseg, int error)
1926 *((uint32_t *)arg) = seg->ds_addr;
1930 acx_dma_alloc(struct acx_softc *sc)
1932 struct acx_ring_data *rd = &sc->sc_ring_data;
1933 struct acx_buf_data *bd = &sc->sc_buf_data;
1936 /* Allocate DMA stuffs for RX descriptors */
1937 error = bus_dma_tag_create(NULL, PAGE_SIZE, 0,
1938 BUS_SPACE_MAXADDR_32BIT, BUS_SPACE_MAXADDR,
1940 ACX_RX_RING_SIZE, 1, ACX_RX_RING_SIZE,
1941 0, &rd->rx_ring_dma_tag);
1943 if_printf(&sc->sc_ic.ic_if, "can't create rx ring dma tag\n");
1947 error = bus_dmamem_alloc(rd->rx_ring_dma_tag, (void **)&rd->rx_ring,
1948 BUS_DMA_WAITOK | BUS_DMA_ZERO,
1949 &rd->rx_ring_dmamap);
1951 if_printf(&sc->sc_ic.ic_if,
1952 "can't allocate rx ring dma memory\n");
1953 bus_dma_tag_destroy(rd->rx_ring_dma_tag);
1954 rd->rx_ring_dma_tag = NULL;
1958 error = bus_dmamap_load(rd->rx_ring_dma_tag, rd->rx_ring_dmamap,
1959 rd->rx_ring, ACX_RX_RING_SIZE,
1960 acx_ring_dma_addr, &rd->rx_ring_paddr,
1963 if_printf(&sc->sc_ic.ic_if, "can't get rx ring dma address\n");
1964 bus_dmamem_free(rd->rx_ring_dma_tag, rd->rx_ring,
1965 rd->rx_ring_dmamap);
1966 bus_dma_tag_destroy(rd->rx_ring_dma_tag);
1967 rd->rx_ring_dma_tag = NULL;
1971 /* Allocate DMA stuffs for TX descriptors */
1972 error = bus_dma_tag_create(NULL, PAGE_SIZE, 0,
1973 BUS_SPACE_MAXADDR_32BIT, BUS_SPACE_MAXADDR,
1975 ACX_TX_RING_SIZE, 1, ACX_TX_RING_SIZE,
1976 0, &rd->tx_ring_dma_tag);
1978 if_printf(&sc->sc_ic.ic_if, "can't create tx ring dma tag\n");
1982 error = bus_dmamem_alloc(rd->tx_ring_dma_tag, (void **)&rd->tx_ring,
1983 BUS_DMA_WAITOK | BUS_DMA_ZERO,
1984 &rd->tx_ring_dmamap);
1986 if_printf(&sc->sc_ic.ic_if,
1987 "can't allocate tx ring dma memory\n");
1988 bus_dma_tag_destroy(rd->tx_ring_dma_tag);
1989 rd->tx_ring_dma_tag = NULL;
1993 error = bus_dmamap_load(rd->tx_ring_dma_tag, rd->tx_ring_dmamap,
1994 rd->tx_ring, ACX_TX_RING_SIZE,
1995 acx_ring_dma_addr, &rd->tx_ring_paddr,
1998 if_printf(&sc->sc_ic.ic_if, "can't get tx ring dma address\n");
1999 bus_dmamem_free(rd->tx_ring_dma_tag, rd->tx_ring,
2000 rd->tx_ring_dmamap);
2001 bus_dma_tag_destroy(rd->tx_ring_dma_tag);
2002 rd->tx_ring_dma_tag = NULL;
2006 /* Create DMA tag for RX/TX mbuf map */
2007 error = bus_dma_tag_create(NULL, 1, 0,
2008 BUS_SPACE_MAXADDR_32BIT, BUS_SPACE_MAXADDR,
2010 MCLBYTES, 1, MCLBYTES,
2011 0, &bd->mbuf_dma_tag);
2013 if_printf(&sc->sc_ic.ic_if, "can't create mbuf dma tag\n");
2017 /* Create a spare RX DMA map */
2018 error = bus_dmamap_create(bd->mbuf_dma_tag, 0, &bd->mbuf_tmp_dmamap);
2020 if_printf(&sc->sc_ic.ic_if, "can't create tmp mbuf dma map\n");
2021 bus_dma_tag_destroy(bd->mbuf_dma_tag);
2022 bd->mbuf_dma_tag = NULL;
2026 /* Create DMA map for RX mbufs */
2027 for (i = 0; i < ACX_RX_DESC_CNT; ++i) {
2028 error = bus_dmamap_create(bd->mbuf_dma_tag, 0,
2029 &bd->rx_buf[i].rb_mbuf_dmamap);
2031 if_printf(&sc->sc_ic.ic_if, "can't create rx mbuf "
2032 "dma map (%d)\n", i);
2035 bd->rx_buf[i].rb_desc = &rd->rx_ring[i];
2038 /* Create DMA map for TX mbufs */
2039 for (i = 0; i < ACX_TX_DESC_CNT; ++i) {
2040 error = bus_dmamap_create(bd->mbuf_dma_tag, 0,
2041 &bd->tx_buf[i].tb_mbuf_dmamap);
2043 if_printf(&sc->sc_ic.ic_if, "can't create tx mbuf "
2044 "dma map (%d)\n", i);
2047 bd->tx_buf[i].tb_desc1 = &rd->tx_ring[i * 2];
2048 bd->tx_buf[i].tb_desc2 = &rd->tx_ring[(i * 2) + 1];
2055 acx_dma_free(struct acx_softc *sc)
2057 struct acx_ring_data *rd = &sc->sc_ring_data;
2058 struct acx_buf_data *bd = &sc->sc_buf_data;
2061 if (rd->rx_ring_dma_tag != NULL) {
2062 bus_dmamap_unload(rd->rx_ring_dma_tag, rd->rx_ring_dmamap);
2063 bus_dmamem_free(rd->rx_ring_dma_tag, rd->rx_ring,
2064 rd->rx_ring_dmamap);
2065 bus_dma_tag_destroy(rd->rx_ring_dma_tag);
2068 if (rd->tx_ring_dma_tag != NULL) {
2069 bus_dmamap_unload(rd->tx_ring_dma_tag, rd->tx_ring_dmamap);
2070 bus_dmamem_free(rd->tx_ring_dma_tag, rd->tx_ring,
2071 rd->tx_ring_dmamap);
2072 bus_dma_tag_destroy(rd->tx_ring_dma_tag);
2075 for (i = 0; i < ACX_RX_DESC_CNT; ++i) {
2076 if (bd->rx_buf[i].rb_desc != NULL) {
2077 if (bd->rx_buf[i].rb_mbuf != NULL) {
2078 bus_dmamap_unload(bd->mbuf_dma_tag,
2079 bd->rx_buf[i].rb_mbuf_dmamap);
2080 m_freem(bd->rx_buf[i].rb_mbuf);
2082 bus_dmamap_destroy(bd->mbuf_dma_tag,
2083 bd->rx_buf[i].rb_mbuf_dmamap);
2087 for (i = 0; i < ACX_TX_DESC_CNT; ++i) {
2088 if (bd->tx_buf[i].tb_desc1 != NULL) {
2089 if (bd->tx_buf[i].tb_mbuf != NULL) {
2090 bus_dmamap_unload(bd->mbuf_dma_tag,
2091 bd->tx_buf[i].tb_mbuf_dmamap);
2092 m_freem(bd->tx_buf[i].tb_mbuf);
2094 bus_dmamap_destroy(bd->mbuf_dma_tag,
2095 bd->tx_buf[i].tb_mbuf_dmamap);
2099 if (bd->mbuf_dma_tag != NULL) {
2100 bus_dmamap_destroy(bd->mbuf_dma_tag, bd->mbuf_tmp_dmamap);
2101 bus_dma_tag_destroy(bd->mbuf_dma_tag);
2106 acx_init_tx_ring(struct acx_softc *sc)
2108 struct acx_ring_data *rd;
2109 struct acx_buf_data *bd;
2113 rd = &sc->sc_ring_data;
2114 paddr = rd->tx_ring_paddr;
2115 for (i = 0; i < (ACX_TX_DESC_CNT * 2) - 1; ++i) {
2116 paddr += sizeof(struct acx_host_desc);
2118 rd->tx_ring[i].h_ctrl = htole16(DESC_CTRL_HOSTOWN);
2120 if (i == (ACX_TX_DESC_CNT * 2) - 1)
2121 rd->tx_ring[i].h_next_desc = htole32(rd->tx_ring_paddr);
2123 rd->tx_ring[i].h_next_desc = htole32(paddr);
2126 bus_dmamap_sync(rd->tx_ring_dma_tag, rd->tx_ring_dmamap,
2127 BUS_DMASYNC_PREWRITE);
2129 bd = &sc->sc_buf_data;
2130 bd->tx_free_start = 0;
2131 bd->tx_used_start = 0;
2132 bd->tx_used_count = 0;
2138 acx_init_rx_ring(struct acx_softc *sc)
2140 struct acx_ring_data *rd;
2141 struct acx_buf_data *bd;
2145 bd = &sc->sc_buf_data;
2146 rd = &sc->sc_ring_data;
2147 paddr = rd->rx_ring_paddr;
2149 for (i = 0; i < ACX_RX_DESC_CNT; ++i) {
2152 paddr += sizeof(struct acx_host_desc);
2154 error = acx_newbuf(sc, &bd->rx_buf[i], 1);
2158 if (i == ACX_RX_DESC_CNT - 1)
2159 rd->rx_ring[i].h_next_desc = htole32(rd->rx_ring_paddr);
2161 rd->rx_ring[i].h_next_desc = htole32(paddr);
2164 bus_dmamap_sync(rd->rx_ring_dma_tag, rd->rx_ring_dmamap,
2165 BUS_DMASYNC_PREWRITE);
2167 bd->rx_scan_start = 0;
2172 acx_buf_dma_addr(void *arg, bus_dma_segment_t *seg, int nseg,
2173 bus_size_t mapsz, int error)
2179 KASSERT(nseg == 1, ("too many RX dma segments\n"));
2180 *((uint32_t *)arg) = seg->ds_addr;
2184 acx_newbuf(struct acx_softc *sc, struct acx_rxbuf *rb, int wait)
2186 struct acx_buf_data *bd;
2192 bd = &sc->sc_buf_data;
2194 m = m_getcl(wait ? MB_WAIT : MB_DONTWAIT, MT_DATA, M_PKTHDR);
2198 m->m_len = m->m_pkthdr.len = MCLBYTES;
2200 error = bus_dmamap_load_mbuf(bd->mbuf_dma_tag, bd->mbuf_tmp_dmamap,
2201 m, acx_buf_dma_addr, &paddr,
2202 wait ? BUS_DMA_WAITOK : BUS_DMA_NOWAIT);
2205 if_printf(&sc->sc_ic.ic_if, "can't map rx mbuf %d\n", error);
2209 /* Unload originally mapped mbuf */
2210 bus_dmamap_unload(bd->mbuf_dma_tag, rb->rb_mbuf_dmamap);
2212 /* Swap this dmamap with tmp dmamap */
2213 map = rb->rb_mbuf_dmamap;
2214 rb->rb_mbuf_dmamap = bd->mbuf_tmp_dmamap;
2215 bd->mbuf_tmp_dmamap = map;
2218 rb->rb_desc->h_data_paddr = htole32(paddr);
2219 rb->rb_desc->h_data_len = htole16(m->m_len);
2221 bus_dmamap_sync(bd->mbuf_dma_tag, rb->rb_mbuf_dmamap,
2222 BUS_DMASYNC_PREREAD);
2227 acx_encap(struct acx_softc *sc, struct acx_txbuf *txbuf, struct mbuf *m,
2228 struct ieee80211_node *ni)
2230 struct acx_buf_data *bd = &sc->sc_buf_data;
2231 struct acx_ring_data *rd = &sc->sc_ring_data;
2236 KASSERT(txbuf->tb_mbuf == NULL, ("free TX buf has mbuf installed\n"));
2239 if (m->m_pkthdr.len > MCLBYTES) {
2240 if_printf(&sc->sc_ic.ic_if, "mbuf too big\n");
2243 } else if (m->m_pkthdr.len < ACX_FRAME_HDRLEN) {
2244 if_printf(&sc->sc_ic.ic_if, "mbuf too small\n");
2249 error = bus_dmamap_load_mbuf(bd->mbuf_dma_tag, txbuf->tb_mbuf_dmamap,
2250 m, acx_buf_dma_addr, &paddr,
2252 if (error && error != EFBIG) {
2253 if_printf(&sc->sc_ic.ic_if, "can't map tx mbuf1 %d\n", error);
2257 if (error) { /* error == EFBIG */
2260 m_new = m_defrag(m, MB_DONTWAIT);
2261 if (m_new == NULL) {
2262 if_printf(&sc->sc_ic.ic_if, "can't defrag tx mbuf\n");
2269 error = bus_dmamap_load_mbuf(bd->mbuf_dma_tag,
2270 txbuf->tb_mbuf_dmamap, m,
2271 acx_buf_dma_addr, &paddr,
2274 if_printf(&sc->sc_ic.ic_if, "can't map tx mbuf2 %d\n",
2282 bus_dmamap_sync(bd->mbuf_dma_tag, txbuf->tb_mbuf_dmamap,
2283 BUS_DMASYNC_PREWRITE);
2286 txbuf->tb_node = ni;
2289 * TX buffers are accessed in following way:
2290 * acx_fw_txdesc -> acx_host_desc -> buffer
2292 * It is quite strange that acx also querys acx_host_desc next to
2293 * the one we have assigned to acx_fw_txdesc even if first one's
2294 * acx_host_desc.h_data_len == acx_fw_txdesc.f_tx_len
2296 * So we allocate two acx_host_desc for one acx_fw_txdesc and
2297 * assign the first acx_host_desc to acx_fw_txdesc
2300 * host_desc1.h_data_len = buffer_len
2301 * host_desc2.h_data_len = buffer_len - mac_header_len
2304 * host_desc1.h_data_len = mac_header_len
2305 * host_desc2.h_data_len = buffer_len - mac_header_len
2308 txbuf->tb_desc1->h_data_paddr = htole32(paddr);
2309 txbuf->tb_desc2->h_data_paddr = htole32(paddr + ACX_FRAME_HDRLEN);
2311 txbuf->tb_desc1->h_data_len =
2312 htole16(sc->chip_txdesc1_len ? sc->chip_txdesc1_len
2314 txbuf->tb_desc2->h_data_len =
2315 htole16(m->m_pkthdr.len - ACX_FRAME_HDRLEN);
2319 * We can't simply assign f_tx_ctrl, we will first read it back
2320 * and change it bit by bit
2322 ctrl = FW_TXDESC_GETFIELD_1(sc, txbuf, f_tx_ctrl);
2323 ctrl |= sc->chip_fw_txdesc_ctrl; /* extra chip specific flags */
2324 ctrl &= ~(DESC_CTRL_HOSTOWN | DESC_CTRL_ACXDONE);
2326 FW_TXDESC_SETFIELD_4(sc, txbuf, f_tx_len, m->m_pkthdr.len);
2327 FW_TXDESC_SETFIELD_1(sc, txbuf, f_tx_error, 0);
2328 FW_TXDESC_SETFIELD_1(sc, txbuf, f_tx_data_nretry, 0);
2329 FW_TXDESC_SETFIELD_1(sc, txbuf, f_tx_rts_nretry, 0);
2330 FW_TXDESC_SETFIELD_1(sc, txbuf, f_tx_rts_ok, 0);
2331 sc->chip_set_fw_txdesc_rate(sc, txbuf, ni, m->m_pkthdr.len);
2333 txbuf->tb_desc1->h_ctrl = 0;
2334 txbuf->tb_desc2->h_ctrl = 0;
2335 bus_dmamap_sync(rd->tx_ring_dma_tag, rd->tx_ring_dmamap,
2336 BUS_DMASYNC_PREWRITE);
2338 FW_TXDESC_SETFIELD_1(sc, txbuf, f_tx_ctrl2, 0);
2339 FW_TXDESC_SETFIELD_1(sc, txbuf, f_tx_ctrl, ctrl);
2341 /* Tell chip to inform us about TX completion */
2342 CSR_WRITE_2(sc, ACXREG_INTR_TRIG, ACXRV_TRIG_TX_FINI);
2350 acx_set_null_tmplt(struct acx_softc *sc)
2352 struct acx_tmplt_null_data n;
2353 struct ieee80211_frame *f;
2355 bzero(&n, sizeof(n));
2358 f->i_fc[0] = IEEE80211_FC0_VERSION_0 | IEEE80211_FC0_TYPE_DATA |
2359 IEEE80211_FC0_SUBTYPE_NODATA;
2360 IEEE80211_ADDR_COPY(f->i_addr1, etherbroadcastaddr);
2361 IEEE80211_ADDR_COPY(f->i_addr2, IF_LLADDR(&sc->sc_ic.ic_if));
2362 IEEE80211_ADDR_COPY(f->i_addr3, etherbroadcastaddr);
2364 return _acx_set_null_data_tmplt(sc, &n, sizeof(n));
2368 acx_set_probe_req_tmplt(struct acx_softc *sc, const char *ssid, int ssid_len)
2370 struct acx_tmplt_probe_req req;
2371 struct ieee80211_frame *f;
2375 bzero(&req, sizeof(req));
2377 f = &req.data.u_data.f;
2378 f->i_fc[0] = IEEE80211_FC0_VERSION_0 | IEEE80211_FC0_TYPE_MGT |
2379 IEEE80211_FC0_SUBTYPE_PROBE_REQ;
2380 IEEE80211_ADDR_COPY(f->i_addr1, etherbroadcastaddr);
2381 IEEE80211_ADDR_COPY(f->i_addr2, IF_LLADDR(&sc->sc_ic.ic_if));
2382 IEEE80211_ADDR_COPY(f->i_addr3, etherbroadcastaddr);
2384 v = req.data.u_data.var;
2385 v = ieee80211_add_ssid(v, ssid, ssid_len);
2386 v = ieee80211_add_rates(v, &sc->sc_ic.ic_sup_rates[sc->chip_phymode]);
2387 v = ieee80211_add_xrates(v, &sc->sc_ic.ic_sup_rates[sc->chip_phymode]);
2388 vlen = v - req.data.u_data.var;
2390 return _acx_set_probe_req_tmplt(sc, &req,
2391 ACX_TMPLT_PROBE_REQ_SIZ(vlen));
2395 acx_set_probe_resp_tmplt(struct acx_softc *sc, struct ieee80211_node *ni)
2397 struct ieee80211com *ic = &sc->sc_ic;
2398 struct acx_tmplt_probe_resp resp;
2399 struct ieee80211_frame *f;
2403 m = ieee80211_probe_resp_alloc(ic, ni);
2406 DPRINTF((&ic->ic_if, "%s alloc probe resp size %d\n", __func__,
2409 f = mtod(m, struct ieee80211_frame *);
2410 IEEE80211_ADDR_COPY(f->i_addr1, etherbroadcastaddr);
2412 bzero(&resp, sizeof(resp));
2413 m_copydata(m, 0, m->m_pkthdr.len, (caddr_t)&resp.data);
2414 len = m->m_pkthdr.len + sizeof(resp.size);
2417 return _acx_set_probe_resp_tmplt(sc, &resp, len);
2421 acx_set_beacon_tmplt(struct acx_softc *sc, struct ieee80211_node *ni)
2423 struct ieee80211com *ic = &sc->sc_ic;
2424 struct acx_tmplt_beacon beacon;
2425 struct ieee80211_beacon_offsets bo;
2429 bzero(&bo, sizeof(bo));
2430 m = ieee80211_beacon_alloc(ic, ni, &bo);
2433 DPRINTF((&ic->ic_if, "%s alloc beacon size %d\n", __func__,
2436 bzero(&beacon, sizeof(beacon));
2437 m_copydata(m, 0, m->m_pkthdr.len, (caddr_t)&beacon.data);
2438 len = m->m_pkthdr.len + sizeof(beacon.size);
2441 return _acx_set_beacon_tmplt(sc, &beacon, len);
2445 acx_sysctl_msdu_lifetime(SYSCTL_HANDLER_ARGS)
2447 struct acx_softc *sc = arg1;
2448 struct ifnet *ifp = &sc->sc_ic.ic_if;
2451 lwkt_serialize_enter(ifp->if_serializer);
2453 v = sc->sc_msdu_lifetime;
2454 error = sysctl_handle_int(oidp, &v, 0, req);
2455 if (error || req->newptr == NULL)
2462 if (sc->sc_flags & ACX_FLAG_FW_LOADED) {
2463 struct acx_conf_msdu_lifetime msdu_lifetime;
2465 msdu_lifetime.lifetime = htole32(v);
2466 if (acx_set_msdu_lifetime_conf(sc, &msdu_lifetime) != 0) {
2467 if_printf(&sc->sc_ic.ic_if,
2468 "can't set MSDU lifetime\n");
2473 sc->sc_msdu_lifetime = v;
2475 lwkt_serialize_exit(ifp->if_serializer);
2480 acx_media_change(struct ifnet *ifp)
2484 error = ieee80211_media_change(ifp);
2485 if (error != ENETRESET)
2488 if ((ifp->if_flags & (IFF_UP | IFF_RUNNING)) == (IFF_UP | IFF_RUNNING))
2489 acx_init(ifp->if_softc);
2494 acx_rx_config(struct acx_softc *sc, int promisc)
2496 struct acx_conf_rxopt rx_opt;
2497 struct ieee80211com *ic = &sc->sc_ic;
2500 * What we want to receive and how to receive
2503 /* Common for all operational modes */
2504 rx_opt.opt1 = RXOPT1_INCL_RXBUF_HDR;
2505 rx_opt.opt2 = RXOPT2_RECV_ASSOC_REQ |
2507 RXOPT2_RECV_BEACON |
2512 RXOPT2_RECV_PROBE_REQ |
2513 RXOPT2_RECV_PROBE_RESP |
2516 if (ic->ic_opmode == IEEE80211_M_MONITOR) {
2517 rx_opt.opt1 |= RXOPT1_PROMISC;
2518 rx_opt.opt2 |= RXOPT2_RECV_BROKEN | RXOPT2_RECV_ACK;
2520 rx_opt.opt1 |= promisc ? RXOPT1_PROMISC : RXOPT1_FILT_FDEST;
2523 if (acx_set_rxopt_conf(sc, &rx_opt) != 0) {
2524 if_printf(&sc->sc_ic.ic_if, "can't config RX\n");
2531 acx_set_chan(struct acx_softc *sc, struct ieee80211_channel *c)
2533 struct ieee80211com *ic = &sc->sc_ic;
2536 chan = ieee80211_chan2ieee(ic, c);
2537 DPRINTF((&ic->ic_if, "to chan %u\n", chan));
2538 if (acx_enable_txchan(sc, chan) != 0) {
2539 if_printf(&ic->ic_if, "enable TX on channel %d failed\n", chan);
2542 if (acx_enable_rxchan(sc, chan) != 0) {
2543 if_printf(&ic->ic_if, "enable RX on channel %d failed\n", chan);