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.15 2007/01/02 23:28:49 swildner 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 ACX_ENABLE_TXCHAN(sc, chan) \
109 if (acx_enable_txchan((sc), (chan)) != 0) { \
110 if_printf(&(sc)->sc_ic.ic_if, \
111 "enable TX on channel %d failed\n", (chan)); \
115 #define ACX_ENABLE_RXCHAN(sc, chan) \
117 if (acx_enable_rxchan((sc), (chan)) != 0) { \
118 if_printf(&(sc)->sc_ic.ic_if, \
119 "enable RX on channel %d failed\n", (chan)); \
123 #define SIOCSLOADFW _IOW('i', 137, struct ifreq) /* load firmware */
124 #define SIOCGRADIO _IOW('i', 138, struct ifreq) /* get radio type */
125 #define SIOCGSTATS _IOW('i', 139, struct ifreq) /* get acx stats */
126 #define SIOCSKILLFW _IOW('i', 140, struct ifreq) /* free firmware */
127 #define SIOCGFWVER _IOW('i', 141, struct ifreq) /* get firmware ver */
128 #define SIOCGHWID _IOW('i', 142, struct ifreq) /* get hardware id */
130 static int acx_probe(device_t);
131 static int acx_attach(device_t);
132 static int acx_detach(device_t);
133 static int acx_shutdown(device_t);
134 static int acx_media_change(struct ifnet *);
136 static void acx_init(void *);
137 static int acx_stop(struct acx_softc *);
138 static void acx_init_info_reg(struct acx_softc *);
139 static int acx_config(struct acx_softc *);
140 static int acx_read_config(struct acx_softc *, struct acx_config *);
141 static int acx_write_config(struct acx_softc *, struct acx_config *);
142 static int acx_set_crypt_keys(struct acx_softc *);
144 static void acx_begin_scan(struct acx_softc *);
146 static void acx_next_scan(void *);
148 static void acx_start(struct ifnet *);
149 static void acx_watchdog(struct ifnet *);
151 static int acx_ioctl(struct ifnet *, u_long, caddr_t, struct ucred *);
153 static void acx_intr(void *);
154 static void acx_disable_intr(struct acx_softc *);
155 static void acx_enable_intr(struct acx_softc *);
156 static void acx_txeof(struct acx_softc *);
157 static void acx_txerr(struct acx_softc *, uint8_t);
158 static void acx_rxeof(struct acx_softc *);
160 static int acx_dma_alloc(struct acx_softc *);
161 static void acx_dma_free(struct acx_softc *);
162 static int acx_init_tx_ring(struct acx_softc *);
163 static int acx_init_rx_ring(struct acx_softc *);
164 static int acx_newbuf(struct acx_softc *, struct acx_rxbuf *, int);
165 static int acx_encap(struct acx_softc *, struct acx_txbuf *,
166 struct mbuf *, struct ieee80211_node *);
168 static int acx_reset(struct acx_softc *);
170 static int acx_set_null_tmplt(struct acx_softc *);
171 static int acx_set_probe_req_tmplt(struct acx_softc *, const char *, int);
172 static int acx_set_probe_resp_tmplt(struct acx_softc *,
173 struct ieee80211_node *);
174 static int acx_set_beacon_tmplt(struct acx_softc *,
175 struct ieee80211_node *);
177 static int acx_read_eeprom(struct acx_softc *, uint32_t, uint8_t *);
178 static int acx_read_phyreg(struct acx_softc *, uint32_t, uint8_t *);
180 static int acx_copyin_firmware(struct acx_softc *, struct ifreq *);
181 static void acx_free_firmware(struct acx_softc *);
182 static int acx_load_firmware(struct acx_softc *, uint32_t,
183 const uint8_t *, int);
184 static int acx_load_radio_firmware(struct acx_softc *, const uint8_t *,
186 static int acx_load_base_firmware(struct acx_softc *, const uint8_t *,
189 static int acx_newstate(struct ieee80211com *, enum ieee80211_state, int);
191 static int acx_sysctl_msdu_lifetime(SYSCTL_HANDLER_ARGS);
193 const struct ieee80211_rateset acx_rates_11b =
194 { 5, { 2, 4, 11, 22, 44 } };
195 const struct ieee80211_rateset acx_rates_11g =
196 { 13, { 2, 4, 11, 22, 44, 12, 18, 24, 36, 48, 72, 96, 108 } };
198 static int acx_chanscan_rate = 5; /* 5/second */
200 static const struct acx_device {
203 void (*set_param)(device_t);
206 { PCI_VENDOR_TI, PCI_PRODUCT_TI_ACX100A, acx100_set_param,
207 "Texas Instruments TNETW1100A Wireless Adapter" },
208 { PCI_VENDOR_TI, PCI_PRODUCT_TI_ACX100B, acx100_set_param,
209 "Texas Instruments TNETW1100B Wireless Adapter" },
210 { PCI_VENDOR_TI, PCI_PRODUCT_TI_ACX111, acx111_set_param,
211 "Texas Instruments TNETW1130 Wireless Adapter" },
215 static device_method_t acx_methods[] = {
216 DEVMETHOD(device_probe, acx_probe),
217 DEVMETHOD(device_attach, acx_attach),
218 DEVMETHOD(device_detach, acx_detach),
219 DEVMETHOD(device_shutdown, acx_shutdown),
221 DEVMETHOD(device_suspend, acx_suspend),
222 DEVMETHOD(device_resume, acx_resume),
227 static driver_t acx_driver = {
230 sizeof(struct acx_softc)
233 static devclass_t acx_devclass;
235 DRIVER_MODULE(acx, pci, acx_driver, acx_devclass, 0, 0);
236 DRIVER_MODULE(acx, cardbus, acx_driver, acx_devclass, 0, 0);
238 MODULE_DEPEND(acx, wlan, 1, 1, 1);
239 MODULE_DEPEND(acx, wlan_ratectl_onoe, 1, 1, 1);
240 MODULE_DEPEND(acx, wlan_ratectl_amrr, 1, 1, 1);
241 MODULE_DEPEND(acx, pci, 1, 1, 1);
242 MODULE_DEPEND(acx, cardbus, 1, 1, 1);
245 acx_probe(device_t dev)
247 const struct acx_device *a;
250 vid = pci_get_vendor(dev);
251 did = pci_get_device(dev);
252 for (a = acx_devices; a->desc != NULL; ++a) {
253 if (vid == a->vid && did == a->did) {
255 device_set_desc(dev, a->desc);
263 acx_attach(device_t dev)
265 struct acx_softc *sc;
267 struct ieee80211com *ic;
270 sc = device_get_softc(dev);
274 if_initname(ifp, device_get_name(dev), device_get_unit(dev));
277 if (pci_get_powerstate(dev) != PCI_POWERSTATE_D0) {
278 uint32_t mem1, mem2, irq;
280 mem1 = pci_read_config(dev, sc->chip_mem1_rid, 4);
281 mem2 = pci_read_config(dev, sc->chip_mem2_rid, 4);
282 irq = pci_read_config(dev, PCIR_INTLINE, 4);
284 device_printf(dev, "chip is in D%d power mode "
285 "-- setting to D0\n", pci_get_powerstate(dev));
287 pci_set_powerstate(dev, PCI_POWERSTATE_D0);
289 pci_write_config(dev, sc->chip_mem1_rid, mem1, 4);
290 pci_write_config(dev, sc->chip_mem2_rid, mem2, 4);
291 pci_write_config(dev, PCIR_INTLINE, irq, 4);
293 #endif /* !BURN_BRIDGE */
295 /* Enable bus mastering */
296 pci_enable_busmaster(dev);
298 /* Allocate IO memory 1 */
299 sc->sc_mem1_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY,
302 if (sc->sc_mem1_res == NULL) {
304 device_printf(dev, "can't allocate IO mem1\n");
307 sc->sc_mem1_bt = rman_get_bustag(sc->sc_mem1_res);
308 sc->sc_mem1_bh = rman_get_bushandle(sc->sc_mem1_res);
310 /* Allocate IO memory 2 */
311 sc->sc_mem2_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY,
314 if (sc->sc_mem2_res == NULL) {
316 device_printf(dev, "can't allocate IO mem2\n");
319 sc->sc_mem2_bt = rman_get_bustag(sc->sc_mem2_res);
320 sc->sc_mem2_bh = rman_get_bushandle(sc->sc_mem2_res);
323 sc->sc_irq_res = bus_alloc_resource_any(dev, SYS_RES_IRQ,
325 RF_SHAREABLE | RF_ACTIVE);
326 if (sc->sc_irq_res == NULL) {
328 device_printf(dev, "can't allocate intr\n");
332 /* Initilize channel scanning timer */
333 callout_init(&sc->sc_chanscan_timer);
335 /* Allocate busdma stuffs */
336 error = acx_dma_alloc(sc);
341 error = acx_reset(sc);
345 /* Disable interrupts before firmware is loaded */
346 acx_disable_intr(sc);
348 /* Get radio type and form factor */
349 #define EEINFO_RETRY_MAX 50
350 for (i = 0; i < EEINFO_RETRY_MAX; ++i) {
353 ee_info = CSR_READ_2(sc, ACXREG_EEPROM_INFO);
354 if (ACX_EEINFO_HAS_RADIO_TYPE(ee_info)) {
355 sc->sc_form_factor = ACX_EEINFO_FORM_FACTOR(ee_info);
356 sc->sc_radio_type = ACX_EEINFO_RADIO_TYPE(ee_info);
361 if (i == EEINFO_RETRY_MAX) {
365 #undef EEINFO_RETRY_MAX
367 DPRINTF((&sc->sc_ic.ic_if, "radio type %02x\n", sc->sc_radio_type));
370 for (i = 0; i < 0x40; ++i) {
373 error = acx_read_eeprom(sc, i, &val);
376 kprintf("%02x ", val);
379 #endif /* DUMP_EEPROM */
381 /* Get EEPROM version */
382 error = acx_read_eeprom(sc, ACX_EE_VERSION_OFS, &sc->sc_eeprom_ver);
385 DPRINTF((&sc->sc_ic.ic_if, "EEPROM version %u\n", sc->sc_eeprom_ver));
388 ifp->if_init = acx_init;
389 ifp->if_ioctl = acx_ioctl;
390 ifp->if_start = acx_start;
391 ifp->if_watchdog = acx_watchdog;
392 ifp->if_flags = IFF_SIMPLEX | IFF_BROADCAST | IFF_MULTICAST;
393 ifq_set_maxlen(&ifp->if_snd, IFQ_MAXLEN);
394 ifq_set_ready(&ifp->if_snd);
397 for (i = 1; i <= 14; ++i) {
398 ic->ic_channels[i].ic_freq =
399 ieee80211_ieee2mhz(i, IEEE80211_CHAN_2GHZ);
400 ic->ic_channels[i].ic_flags = sc->chip_chan_flags;
403 ic->ic_opmode = IEEE80211_M_STA;
404 ic->ic_state = IEEE80211_S_INIT;
407 * NOTE: Don't overwrite ic_caps set by chip specific code
409 ic->ic_caps |= IEEE80211_C_WEP | /* WEP */
410 IEEE80211_C_HOSTAP | /* Host AP modes */
411 IEEE80211_C_IBSS | /* IBSS modes */
412 IEEE80211_C_SHPREAMBLE; /* Short preamble */
413 ic->ic_caps_ext = IEEE80211_CEXT_PBCC; /* PBCC modulation */
416 for (i = 0; i < IEEE80211_ADDR_LEN; ++i) {
417 error = acx_read_eeprom(sc, sc->chip_ee_eaddr_ofs - i,
421 ieee80211_ifattach(ic);
423 /* Enable software beacon missing */
424 ic->ic_flags_ext |= IEEE80211_FEXT_SWBMISS;
426 /* Override newstate */
427 sc->sc_newstate = ic->ic_newstate;
428 ic->ic_newstate = acx_newstate;
430 ieee80211_media_init(ic, acx_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 ieee80211_new_state(&sc->sc_ic, IEEE80211_S_INIT, -1);
724 sc->sc_firmware_ver = 0;
725 sc->sc_hardware_id = 0;
728 error = acx_reset(sc);
732 /* Firmware no longer functions after hardware reset */
733 sc->sc_flags &= ~ACX_FLAG_FW_LOADED;
735 acx_disable_intr(sc);
737 /* Stop backgroud scanning */
738 callout_stop(&sc->sc_chanscan_timer);
740 /* Turn off power led */
741 CSR_SETB_2(sc, ACXREG_GPIO_OUT, sc->chip_gpio_pled);
744 for (i = 0; i < ACX_TX_DESC_CNT; ++i) {
745 struct acx_txbuf *buf;
747 buf = &bd->tx_buf[i];
749 if (buf->tb_mbuf != NULL) {
750 bus_dmamap_unload(bd->mbuf_dma_tag,
751 buf->tb_mbuf_dmamap);
752 m_freem(buf->tb_mbuf);
756 if (buf->tb_node != NULL)
757 ieee80211_free_node(buf->tb_node);
761 /* Clear TX host descriptors */
762 bzero(rd->tx_ring, ACX_TX_RING_SIZE);
765 for (i = 0; i < ACX_RX_DESC_CNT; ++i) {
766 if (bd->rx_buf[i].rb_mbuf != NULL) {
767 bus_dmamap_unload(bd->mbuf_dma_tag,
768 bd->rx_buf[i].rb_mbuf_dmamap);
769 m_freem(bd->rx_buf[i].rb_mbuf);
770 bd->rx_buf[i].rb_mbuf = NULL;
774 /* Clear RX host descriptors */
775 bzero(rd->rx_ring, ACX_RX_RING_SIZE);
779 ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE);
785 acx_config(struct acx_softc *sc)
787 struct acx_config conf;
790 error = acx_read_config(sc, &conf);
794 error = acx_write_config(sc, &conf);
798 if (acx_set_probe_req_tmplt(sc, "", 0) != 0) {
799 if_printf(&sc->sc_ic.ic_if, "can't set probe req template "
805 if (acx_set_null_tmplt(sc) != 0) {
806 if_printf(&sc->sc_ic.ic_if, "can't set null data template\n");
813 acx_read_config(struct acx_softc *sc, struct acx_config *conf)
815 struct acx_conf_eaddr addr;
816 struct acx_conf_regdom reg_dom;
817 struct acx_conf_antenna ant;
818 struct acx_conf_fwrev fw_rev;
824 if (acx_get_eaddr_conf(sc, &addr) != 0) {
825 if_printf(&sc->sc_ic.ic_if, "can't get station id\n");
830 * Get and print station id in case that EEPROM station id's
831 * offset is not correct
833 for (i = 0; i < IEEE80211_ADDR_LEN; ++i)
834 conf->eaddr[IEEE80211_ADDR_LEN - 1 - i] = addr.eaddr[i];
835 if_printf(&sc->sc_ic.ic_if, "MAC address (from firmware): %6D\n",
838 /* Get region domain */
839 if (acx_get_regdom_conf(sc, ®_dom) != 0) {
840 if_printf(&sc->sc_ic.ic_if, "can't get region domain\n");
843 conf->regdom = reg_dom.regdom;
844 DPRINTF((&sc->sc_ic.ic_if, "regdom %02x\n", reg_dom.regdom));
847 if (acx_get_antenna_conf(sc, &ant) != 0) {
848 if_printf(&sc->sc_ic.ic_if, "can't get antenna\n");
851 conf->antenna = ant.antenna;
852 DPRINTF((&sc->sc_ic.ic_if, "antenna %02x\n", ant.antenna));
854 /* Get sensitivity XXX not used */
855 if (sc->sc_radio_type == ACX_RADIO_TYPE_MAXIM ||
856 sc->sc_radio_type == ACX_RADIO_TYPE_RFMD ||
857 sc->sc_radio_type == ACX_RADIO_TYPE_RALINK) {
858 error = acx_read_phyreg(sc, ACXRV_PHYREG_SENSITIVITY, &sen);
860 if_printf(&sc->sc_ic.ic_if, "can't get sensitivity\n");
866 DPRINTF((&sc->sc_ic.ic_if, "sensitivity %02x\n", sen));
868 /* Get firmware revision */
869 if (acx_get_fwrev_conf(sc, &fw_rev) != 0) {
870 if_printf(&sc->sc_ic.ic_if, "can't get firmware revision\n");
874 if (strncmp(fw_rev.fw_rev, "Rev ", 4) != 0) {
875 if_printf(&sc->sc_ic.ic_if, "strange revision string -- %s\n",
877 fw_rev_no = 0x01090407;
886 s = &fw_rev.fw_rev[4];
888 for (i = 0; i < 4; ++i) {
891 val = strtoul(s, &endp, 16);
892 fw_rev_no |= val << ((3 - i) * 8);
900 sc->sc_firmware_ver = fw_rev_no;
901 sc->sc_hardware_id = le32toh(fw_rev.hw_id);
902 DPRINTF((&sc->sc_ic.ic_if, "fw rev %08x, hw id %08x\n",
903 sc->sc_firmware_ver, sc->sc_hardware_id));
905 if (sc->chip_read_config != NULL) {
906 error = sc->chip_read_config(sc, conf);
914 acx_write_config(struct acx_softc *sc, struct acx_config *conf)
916 struct acx_conf_nretry_short sretry;
917 struct acx_conf_nretry_long lretry;
918 struct acx_conf_msdu_lifetime msdu_lifetime;
919 struct acx_conf_rate_fallback rate_fb;
920 struct acx_conf_antenna ant;
921 struct acx_conf_regdom reg_dom;
922 struct acx_conf_rxopt rx_opt;
925 /* Set number of long/short retry */
926 KKASSERT(sc->chip_short_retry_limit > 0);
927 sretry.nretry = sc->chip_short_retry_limit;
928 if (acx_set_nretry_short_conf(sc, &sretry) != 0) {
929 if_printf(&sc->sc_ic.ic_if, "can't set short retry limit\n");
933 lretry.nretry = sc->sc_long_retry_limit;
934 if (acx_set_nretry_long_conf(sc, &lretry) != 0) {
935 if_printf(&sc->sc_ic.ic_if, "can't set long retry limit\n");
939 /* Set MSDU lifetime */
940 msdu_lifetime.lifetime = htole32(sc->sc_msdu_lifetime);
941 if (acx_set_msdu_lifetime_conf(sc, &msdu_lifetime) != 0) {
942 if_printf(&sc->sc_ic.ic_if, "can't set MSDU lifetime\n");
946 /* Enable rate fallback */
947 rate_fb.ratefb_enable = 1;
948 if (acx_set_rate_fallback_conf(sc, &rate_fb) != 0) {
949 if_printf(&sc->sc_ic.ic_if, "can't enable rate fallback\n");
954 ant.antenna = conf->antenna;
955 if (acx_set_antenna_conf(sc, &ant) != 0) {
956 if_printf(&sc->sc_ic.ic_if, "can't set antenna\n");
960 /* Set region domain */
961 reg_dom.regdom = conf->regdom;
962 if (acx_set_regdom_conf(sc, ®_dom) != 0) {
963 if_printf(&sc->sc_ic.ic_if, "can't set region domain\n");
967 if (sc->chip_write_config != NULL) {
968 error = sc->chip_write_config(sc, conf);
973 /* What we want to receive and how to receive */
974 /* XXX may not belong here, acx_init() */
975 rx_opt.opt1 = RXOPT1_FILT_FDEST | RXOPT1_INCL_RXBUF_HDR;
976 rx_opt.opt2 = RXOPT2_RECV_ASSOC_REQ |
983 RXOPT2_RECV_PROBE_REQ |
984 RXOPT2_RECV_PROBE_RESP |
986 if (acx_set_rxopt_conf(sc, &rx_opt) != 0) {
987 if_printf(&sc->sc_ic.ic_if, "can't set RX option\n");
994 acx_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data, struct ucred *cr)
996 struct acx_softc *sc = ifp->if_softc;
1001 req = (struct ifreq *)data;
1005 error = suser_cred(cr, NULL_CRED_OKAY);
1009 error = acx_copyin_firmware(sc, req);
1012 error = suser_cred(cr, NULL_CRED_OKAY);
1015 acx_free_firmware(sc);
1018 error = copyout(&sc->sc_radio_type, req->ifr_data,
1019 sizeof(sc->sc_radio_type));
1022 error = copyout(&sc->sc_firmware_ver, req->ifr_data,
1023 sizeof(sc->sc_firmware_ver));
1026 error = copyout(&sc->sc_hardware_id, req->ifr_data,
1027 sizeof(sc->sc_hardware_id));
1030 error = copyout(&sc->sc_stats, req->ifr_data,
1031 sizeof(sc->sc_stats));
1034 if (ifp->if_flags & IFF_UP) {
1035 if ((ifp->if_flags & IFF_RUNNING) == 0)
1038 if (ifp->if_flags & IFF_RUNNING)
1047 error = ieee80211_ioctl(&sc->sc_ic, cmd, data, cr);
1051 if (error == ENETRESET) {
1052 if ((ifp->if_flags & (IFF_RUNNING | IFF_UP)) ==
1053 (IFF_RUNNING | IFF_UP))
1061 acx_start(struct ifnet *ifp)
1063 struct acx_softc *sc = ifp->if_softc;
1064 struct ieee80211com *ic = &sc->sc_ic;
1065 struct acx_buf_data *bd = &sc->sc_buf_data;
1066 struct acx_txbuf *buf;
1069 ASSERT_SERIALIZED(ifp->if_serializer);
1071 if ((sc->sc_flags & ACX_FLAG_FW_LOADED) == 0 ||
1072 (ifp->if_flags & IFF_RUNNING) == 0 ||
1073 (ifp->if_flags & IFF_OACTIVE))
1078 * We can't start from a random position that TX descriptor
1079 * is free, since hardware will be confused by that.
1080 * We have to follow the order of the TX ring.
1082 idx = bd->tx_free_start;
1084 for (buf = &bd->tx_buf[idx]; buf->tb_mbuf == NULL;
1085 buf = &bd->tx_buf[idx]) {
1086 struct ieee80211_frame *f;
1087 struct ieee80211_node *ni = NULL;
1091 if (!IF_QEMPTY(&ic->ic_mgtq)) {
1092 IF_DEQUEUE(&ic->ic_mgtq, m);
1094 ni = (struct ieee80211_node *)m->m_pkthdr.rcvif;
1095 m->m_pkthdr.rcvif = NULL;
1100 * Don't transmit probe response firmware will
1103 f = mtod(m, struct ieee80211_frame *);
1104 if ((f->i_fc[0] & IEEE80211_FC0_TYPE_MASK) ==
1105 IEEE80211_FC0_TYPE_MGT &&
1106 (f->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK) ==
1107 IEEE80211_FC0_SUBTYPE_PROBE_RESP) {
1109 ieee80211_free_node(ni);
1113 } else if (!ifq_is_empty(&ifp->if_snd)) {
1114 struct ether_header *eh;
1116 if (ic->ic_state != IEEE80211_S_RUN) {
1117 if_printf(ifp, "data packet dropped due to "
1118 "not RUN. Current state %d\n",
1123 m = ifq_dequeue(&ifp->if_snd, NULL);
1127 if (m->m_len < sizeof(struct ether_header)) {
1128 m = m_pullup(m, sizeof(struct ether_header));
1134 eh = mtod(m, struct ether_header *);
1136 ni = ieee80211_find_txnode(ic, eh->ether_dhost);
1143 /* TODO power save */
1145 m = ieee80211_encap(ic, m, ni);
1147 ieee80211_free_node(ni);
1157 f = mtod(m, struct ieee80211_frame *);
1158 if ((f->i_fc[1] & IEEE80211_FC1_WEP) && !sc->chip_hw_crypt) {
1159 KASSERT(ni != NULL, ("TX node is NULL (WEP)\n"));
1160 if (ieee80211_crypto_encap(ic, ni, m) == NULL) {
1161 ieee80211_free_node(ni);
1168 if (ic->ic_rawbpf != NULL)
1169 bpf_mtap(ic->ic_rawbpf, m);
1172 * Since mgmt data are transmitted at fixed rate
1173 * they will not be used to do rate control.
1175 if (mgmt_pkt && ni != NULL) {
1176 ieee80211_free_node(ni);
1180 if (acx_encap(sc, buf, m, ni) != 0) {
1182 * NOTE: `m' will be freed in acx_encap()
1186 ieee80211_free_node(ni);
1193 * 1) `m' should not be touched after acx_encap()
1194 * 2) `node' will be used to do TX rate control during
1195 * acx_txeof(), so it is not freed here. acx_txeof()
1196 * will free it for us
1200 bd->tx_used_count++;
1201 idx = (idx + 1) % ACX_TX_DESC_CNT;
1203 bd->tx_free_start = idx;
1205 if (bd->tx_used_count == ACX_TX_DESC_CNT)
1206 ifp->if_flags |= IFF_OACTIVE;
1208 if (trans && sc->sc_tx_timer == 0)
1209 sc->sc_tx_timer = 5;
1214 acx_watchdog(struct ifnet *ifp)
1216 struct acx_softc *sc = ifp->if_softc;
1220 if ((ifp->if_flags & IFF_RUNNING) == 0)
1223 if (sc->sc_tx_timer) {
1224 if (--sc->sc_tx_timer == 0) {
1225 if_printf(ifp, "watchdog timeout\n");
1227 acx_txeof(ifp->if_softc);
1232 ieee80211_watchdog(&sc->sc_ic);
1238 struct acx_softc *sc = arg;
1239 uint16_t intr_status;
1241 if ((sc->sc_flags & ACX_FLAG_FW_LOADED) == 0)
1244 intr_status = CSR_READ_2(sc, ACXREG_INTR_STATUS_CLR);
1245 if (intr_status == ACXRV_INTR_ALL) {
1246 /* not our interrupt */
1250 intr_status &= sc->chip_intr_enable;
1251 if (intr_status == 0) {
1252 /* not interrupts we care about */
1256 /* Acknowledge all interrupts */
1257 CSR_WRITE_2(sc, ACXREG_INTR_ACK, ACXRV_INTR_ALL);
1259 if (intr_status & ACXRV_INTR_TX_FINI)
1262 if (intr_status & ACXRV_INTR_RX_FINI)
1267 acx_disable_intr(struct acx_softc *sc)
1269 CSR_WRITE_2(sc, ACXREG_INTR_MASK, sc->chip_intr_disable);
1270 CSR_WRITE_2(sc, ACXREG_EVENT_MASK, 0);
1274 acx_enable_intr(struct acx_softc *sc)
1276 /* Mask out interrupts that are not in the enable set */
1277 CSR_WRITE_2(sc, ACXREG_INTR_MASK, ~sc->chip_intr_enable);
1278 CSR_WRITE_2(sc, ACXREG_EVENT_MASK, ACXRV_EVENT_DISABLE);
1282 acx_txeof(struct acx_softc *sc)
1284 struct acx_buf_data *bd;
1285 struct acx_txbuf *buf;
1289 ifp = &sc->sc_ic.ic_if;
1290 ASSERT_SERIALIZED(ifp->if_serializer);
1292 bd = &sc->sc_buf_data;
1293 idx = bd->tx_used_start;
1294 for (buf = &bd->tx_buf[idx]; buf->tb_mbuf != NULL;
1295 buf = &bd->tx_buf[idx]) {
1296 uint8_t ctrl, error;
1299 ctrl = FW_TXDESC_GETFIELD_1(sc, buf, f_tx_ctrl);
1300 if ((ctrl & (DESC_CTRL_HOSTOWN | DESC_CTRL_ACXDONE)) !=
1301 (DESC_CTRL_HOSTOWN | DESC_CTRL_ACXDONE))
1304 bus_dmamap_unload(bd->mbuf_dma_tag, buf->tb_mbuf_dmamap);
1305 frame_len = buf->tb_mbuf->m_pkthdr.len;
1306 m_freem(buf->tb_mbuf);
1307 buf->tb_mbuf = NULL;
1309 error = FW_TXDESC_GETFIELD_1(sc, buf, f_tx_error);
1311 acx_txerr(sc, error);
1317 if (buf->tb_node != NULL) {
1318 sc->chip_tx_complete(sc, buf, frame_len, error);
1319 ieee80211_free_node(buf->tb_node);
1320 buf->tb_node = NULL;
1323 FW_TXDESC_SETFIELD_1(sc, buf, f_tx_ctrl, DESC_CTRL_HOSTOWN);
1325 bd->tx_used_count--;
1327 idx = (idx + 1) % ACX_TX_DESC_CNT;
1329 bd->tx_used_start = idx;
1331 sc->sc_tx_timer = bd->tx_used_count == 0 ? 0 : 5;
1333 if (bd->tx_used_count != ACX_TX_DESC_CNT) {
1334 ifp->if_flags &= ~IFF_OACTIVE;
1340 acx_txerr(struct acx_softc *sc, uint8_t err)
1342 struct ifnet *ifp = &sc->sc_ic.ic_if;
1343 struct acx_stats *stats = &sc->sc_stats;
1345 if (err == DESC_ERR_EXCESSIVE_RETRY) {
1347 * This a common error (see comment below),
1348 * so print it using DPRINTF()
1350 DPRINTF((ifp, "TX failed -- excessive retry\n"));
1352 if_printf(ifp, "TX failed -- ");
1356 * Although `err' looks like bitmask, it never
1357 * has multiple bits set.
1361 case DESC_ERR_OTHER_FRAG:
1362 /* XXX what's this */
1363 kprintf("error in other fragment\n");
1364 stats->err_oth_frag++;
1367 case DESC_ERR_ABORT:
1368 kprintf("aborted\n");
1371 case DESC_ERR_PARAM:
1372 kprintf("wrong paramters in descriptor\n");
1375 case DESC_ERR_NO_WEPKEY:
1376 kprintf("WEP key missing\n");
1377 stats->err_no_wepkey++;
1379 case DESC_ERR_MSDU_TIMEOUT:
1380 kprintf("MSDU life timeout\n");
1381 stats->err_msdu_timeout++;
1383 case DESC_ERR_EXCESSIVE_RETRY:
1386 * 1) Distance is too long
1387 * 2) Transmit failed (e.g. no MAC level ACK)
1388 * 3) Chip overheated (this should be rare)
1390 stats->err_ex_retry++;
1392 case DESC_ERR_BUF_OVERFLOW:
1393 kprintf("buffer overflow\n");
1394 stats->err_buf_oflow++;
1397 kprintf("DMA error\n");
1401 kprintf("unknown error %d\n", err);
1408 acx_rxeof(struct acx_softc *sc)
1410 struct ieee80211com *ic = &sc->sc_ic;
1411 struct acx_ring_data *rd = &sc->sc_ring_data;
1412 struct acx_buf_data *bd = &sc->sc_buf_data;
1413 struct ifnet *ifp = &ic->ic_if;
1416 ASSERT_SERIALIZED(ic->ic_if.if_serializer);
1418 bus_dmamap_sync(rd->rx_ring_dma_tag, rd->rx_ring_dmamap,
1419 BUS_DMASYNC_POSTREAD);
1422 * Locate first "ready" rx buffer,
1423 * start from last stopped position
1425 idx = bd->rx_scan_start;
1428 struct acx_rxbuf *buf;
1430 buf = &bd->rx_buf[idx];
1431 if ((buf->rb_desc->h_ctrl & htole16(DESC_CTRL_HOSTOWN)) &&
1432 (buf->rb_desc->h_status & htole32(DESC_STATUS_FULL))) {
1436 idx = (idx + 1) % ACX_RX_DESC_CNT;
1437 } while (idx != bd->rx_scan_start);
1443 * NOTE: don't mess up `idx' here, it will
1444 * be used in the following code
1448 struct acx_rxbuf_hdr *head;
1449 struct acx_rxbuf *buf;
1451 uint32_t desc_status;
1455 buf = &bd->rx_buf[idx];
1457 desc_ctrl = le16toh(buf->rb_desc->h_ctrl);
1458 desc_status = le32toh(buf->rb_desc->h_status);
1459 if (!(desc_ctrl & DESC_CTRL_HOSTOWN) ||
1460 !(desc_status & DESC_STATUS_FULL))
1463 bus_dmamap_sync(bd->mbuf_dma_tag, buf->rb_mbuf_dmamap,
1464 BUS_DMASYNC_POSTREAD);
1468 error = acx_newbuf(sc, buf, 0);
1474 head = mtod(m, struct acx_rxbuf_hdr *);
1476 len = le16toh(head->rbh_len) & ACX_RXBUF_LEN_MASK;
1477 if (len >= sizeof(struct ieee80211_frame_min) &&
1479 struct ieee80211_frame *f;
1480 struct ieee80211_node *ni;
1482 m_adj(m, sizeof(struct acx_rxbuf_hdr) +
1483 sc->chip_rxbuf_exhdr);
1484 f = mtod(m, struct ieee80211_frame *);
1486 if ((f->i_fc[1] & IEEE80211_FC1_WEP) &&
1487 sc->chip_hw_crypt) {
1488 /* Short circuit software WEP */
1489 f->i_fc[1] &= ~IEEE80211_FC1_WEP;
1491 /* Do chip specific RX buffer processing */
1492 if (sc->chip_proc_wep_rxbuf != NULL) {
1493 sc->chip_proc_wep_rxbuf(sc, m, &len);
1494 f = mtod(m, struct ieee80211_frame *);
1498 ni = ieee80211_find_rxnode(ic,
1499 (struct ieee80211_frame_min *)f);
1501 m->m_len = m->m_pkthdr.len = len;
1502 m->m_pkthdr.rcvif = &ic->ic_if;
1504 ieee80211_input(ic, m, ni, head->rbh_level,
1505 le32toh(head->rbh_time));
1507 ieee80211_free_node(ni);
1515 buf->rb_desc->h_ctrl = htole16(desc_ctrl & ~DESC_CTRL_HOSTOWN);
1516 buf->rb_desc->h_status = 0;
1517 bus_dmamap_sync(rd->rx_ring_dma_tag, rd->rx_ring_dmamap,
1518 BUS_DMASYNC_PREWRITE);
1520 idx = (idx + 1) % ACX_RX_DESC_CNT;
1521 } while (idx != bd->rx_scan_start);
1524 * Record the position so that next
1525 * time we can start from it
1527 bd->rx_scan_start = idx;
1531 acx_reset(struct acx_softc *sc)
1536 CSR_SETB_2(sc, ACXREG_ECPU_CTRL, ACXRV_ECPU_HALT);
1538 /* Software reset */
1539 reg = CSR_READ_2(sc, ACXREG_SOFT_RESET);
1540 CSR_WRITE_2(sc, ACXREG_SOFT_RESET, reg | ACXRV_SOFT_RESET);
1542 CSR_WRITE_2(sc, ACXREG_SOFT_RESET, reg);
1544 /* Initialize EEPROM */
1545 CSR_SETB_2(sc, ACXREG_EEPROM_INIT, ACXRV_EEPROM_INIT);
1548 /* Test whether ECPU is stopped */
1549 reg = CSR_READ_2(sc, ACXREG_ECPU_CTRL);
1550 if (!(reg & ACXRV_ECPU_HALT)) {
1551 if_printf(&sc->sc_ic.ic_if, "can't halt ECPU\n");
1558 acx_read_eeprom(struct acx_softc *sc, uint32_t offset, uint8_t *val)
1562 CSR_WRITE_4(sc, ACXREG_EEPROM_CONF, 0);
1563 CSR_WRITE_4(sc, ACXREG_EEPROM_ADDR, offset);
1564 CSR_WRITE_4(sc, ACXREG_EEPROM_CTRL, ACXRV_EEPROM_READ);
1566 #define EE_READ_RETRY_MAX 100
1567 for (i = 0; i < EE_READ_RETRY_MAX; ++i) {
1568 if (CSR_READ_2(sc, ACXREG_EEPROM_CTRL) == 0)
1572 if (i == EE_READ_RETRY_MAX) {
1573 if_printf(&sc->sc_ic.ic_if, "can't read EEPROM offset %x "
1574 "(timeout)\n", offset);
1577 #undef EE_READ_RETRY_MAX
1579 *val = CSR_READ_1(sc, ACXREG_EEPROM_DATA);
1584 acx_read_phyreg(struct acx_softc *sc, uint32_t reg, uint8_t *val)
1588 CSR_WRITE_4(sc, ACXREG_PHY_ADDR, reg);
1589 CSR_WRITE_4(sc, ACXREG_PHY_CTRL, ACXRV_PHY_READ);
1591 #define PHY_READ_RETRY_MAX 100
1592 for (i = 0; i < PHY_READ_RETRY_MAX; ++i) {
1593 if (CSR_READ_4(sc, ACXREG_PHY_CTRL) == 0)
1597 if (i == PHY_READ_RETRY_MAX) {
1598 if_printf(&sc->sc_ic.ic_if, "can't read phy reg %x (timeout)\n",
1602 #undef PHY_READ_RETRY_MAX
1604 *val = CSR_READ_1(sc, ACXREG_PHY_DATA);
1609 acx_write_phyreg(struct acx_softc *sc, uint32_t reg, uint8_t val)
1611 CSR_WRITE_4(sc, ACXREG_PHY_DATA, val);
1612 CSR_WRITE_4(sc, ACXREG_PHY_ADDR, reg);
1613 CSR_WRITE_4(sc, ACXREG_PHY_CTRL, ACXRV_PHY_WRITE);
1617 acx_copyin_firmware(struct acx_softc *sc, struct ifreq *req)
1619 struct acx_firmware ufw, *kfw;
1620 uint8_t *base_fw, *radio_fw;
1623 kfw = &sc->sc_firmware;
1627 error = copyin(req->ifr_data, &ufw, sizeof(ufw));
1632 * For combined base firmware, there is no radio firmware.
1633 * But base firmware must exist.
1635 if (ufw.base_fw_len <= 0 || ufw.radio_fw_len < 0)
1638 base_fw = kmalloc(ufw.base_fw_len, M_DEVBUF, M_INTWAIT);
1639 error = copyin(ufw.base_fw, base_fw, ufw.base_fw_len);
1643 if (ufw.radio_fw_len > 0) {
1644 radio_fw = kmalloc(ufw.radio_fw_len, M_DEVBUF, M_INTWAIT);
1645 error = copyin(ufw.radio_fw, radio_fw, ufw.radio_fw_len);
1650 kfw->base_fw_len = ufw.base_fw_len;
1651 if (kfw->base_fw != NULL)
1652 kfree(kfw->base_fw, M_DEVBUF);
1653 kfw->base_fw = base_fw;
1655 kfw->radio_fw_len = ufw.radio_fw_len;
1656 if (kfw->radio_fw != NULL)
1657 kfree(kfw->radio_fw, M_DEVBUF);
1658 kfw->radio_fw = radio_fw;
1662 if (base_fw != NULL)
1663 kfree(base_fw, M_DEVBUF);
1664 if (radio_fw != NULL)
1665 kfree(radio_fw, M_DEVBUF);
1670 acx_free_firmware(struct acx_softc *sc)
1672 struct acx_firmware *fw = &sc->sc_firmware;
1674 if (fw->base_fw != NULL) {
1675 kfree(fw->base_fw, M_DEVBUF);
1677 fw->base_fw_len = 0;
1679 if (fw->radio_fw != NULL) {
1680 kfree(fw->radio_fw, M_DEVBUF);
1681 fw->radio_fw = NULL;
1682 fw->radio_fw_len = 0;
1687 acx_load_base_firmware(struct acx_softc *sc, const uint8_t *base_fw,
1688 uint32_t base_fw_len)
1692 /* Load base firmware */
1693 error = acx_load_firmware(sc, 0, base_fw, base_fw_len);
1695 if_printf(&sc->sc_ic.ic_if, "can't load base firmware\n");
1698 DPRINTF((&sc->sc_ic.ic_if, "base firmware loaded\n"));
1701 CSR_WRITE_2(sc, ACXREG_ECPU_CTRL, ACXRV_ECPU_START);
1703 /* Wait for ECPU to be up */
1704 for (i = 0; i < 500; ++i) {
1707 reg = CSR_READ_2(sc, ACXREG_INTR_STATUS);
1708 if (reg & ACXRV_INTR_FCS_THRESH) {
1709 CSR_WRITE_2(sc, ACXREG_INTR_ACK, ACXRV_INTR_FCS_THRESH);
1715 if_printf(&sc->sc_ic.ic_if, "can't initialize ECPU (timeout)\n");
1720 acx_load_radio_firmware(struct acx_softc *sc, const uint8_t *radio_fw,
1721 uint32_t radio_fw_len)
1723 struct acx_conf_mmap mem_map;
1724 uint32_t radio_fw_ofs;
1728 * Get the position, where base firmware is loaded, so that
1729 * radio firmware can be loaded after it.
1731 if (acx_get_mmap_conf(sc, &mem_map) != 0)
1733 radio_fw_ofs = le32toh(mem_map.code_end);
1735 /* Put ECPU into sleeping state, before loading radio firmware */
1736 if (acx_sleep(sc) != 0)
1739 /* Load radio firmware */
1740 error = acx_load_firmware(sc, radio_fw_ofs, radio_fw, radio_fw_len);
1742 if_printf(&sc->sc_ic.ic_if, "can't load radio firmware\n");
1745 DPRINTF((&sc->sc_ic.ic_if, "radio firmware loaded\n"));
1747 /* Wake up sleeping ECPU, after radio firmware is loaded */
1748 if (acx_wakeup(sc) != 0)
1751 /* Initialize radio */
1752 if (acx_init_radio(sc, radio_fw_ofs, radio_fw_len) != 0)
1755 /* Verify radio firmware's loading position */
1756 if (acx_get_mmap_conf(sc, &mem_map) != 0)
1758 if (le32toh(mem_map.code_end) != radio_fw_ofs + radio_fw_len) {
1759 if_printf(&sc->sc_ic.ic_if, "loaded radio firmware position "
1764 DPRINTF((&sc->sc_ic.ic_if, "radio firmware initialized\n"));
1769 acx_load_firmware(struct acx_softc *sc, uint32_t offset, const uint8_t *data,
1775 fw = (const uint32_t *)data;
1776 fw_len = data_len / sizeof(uint32_t);
1779 * LOADFW_AUTO_INC only works with some older firmware:
1780 * 1) acx100's firmware
1781 * 2) acx111's firmware whose rev is 0x00010011
1785 CSR_WRITE_4(sc, ACXREG_FWMEM_START, ACXRV_FWMEM_START_OP);
1786 #ifndef LOADFW_AUTO_INC
1787 CSR_WRITE_4(sc, ACXREG_FWMEM_CTRL, 0);
1789 CSR_WRITE_4(sc, ACXREG_FWMEM_CTRL, ACXRV_FWMEM_ADDR_AUTOINC);
1790 CSR_WRITE_4(sc, ACXREG_FWMEM_ADDR, offset);
1793 for (i = 0; i < fw_len; ++i) {
1794 #ifndef LOADFW_AUTO_INC
1795 CSR_WRITE_4(sc, ACXREG_FWMEM_ADDR, offset + (i * 4));
1797 CSR_WRITE_4(sc, ACXREG_FWMEM_DATA, be32toh(fw[i]));
1800 /* Verify firmware */
1801 CSR_WRITE_4(sc, ACXREG_FWMEM_START, ACXRV_FWMEM_START_OP);
1802 #ifndef LOADFW_AUTO_INC
1803 CSR_WRITE_4(sc, ACXREG_FWMEM_CTRL, 0);
1805 CSR_WRITE_4(sc, ACXREG_FWMEM_CTRL, ACXRV_FWMEM_ADDR_AUTOINC);
1806 CSR_WRITE_4(sc, ACXREG_FWMEM_ADDR, offset);
1809 for (i = 0; i < fw_len; ++i) {
1812 #ifndef LOADFW_AUTO_INC
1813 CSR_WRITE_4(sc, ACXREG_FWMEM_ADDR, offset + (i * 4));
1815 val = CSR_READ_4(sc, ACXREG_FWMEM_DATA);
1816 if (be32toh(fw[i]) != val) {
1817 if_printf(&sc->sc_ic.ic_if, "fireware mismatch "
1818 "fw %08x loaded %08x\n", fw[i], val);
1826 acx_newstate(struct ieee80211com *ic, enum ieee80211_state nstate, int arg)
1828 struct acx_softc *sc = ic->ic_if.if_softc;
1829 int error = 0, mode = 0;
1831 ASSERT_SERIALIZED(ic->ic_if.if_serializer);
1833 ieee80211_ratectl_newstate(ic, nstate);
1836 case IEEE80211_S_SCAN:
1837 if (ic->ic_state != IEEE80211_S_INIT) {
1840 chan = ieee80211_chan2ieee(ic, ic->ic_curchan);
1841 ACX_ENABLE_TXCHAN(sc, chan);
1842 ACX_ENABLE_RXCHAN(sc, chan);
1844 callout_reset(&sc->sc_chanscan_timer,
1845 hz / acx_chanscan_rate,
1849 case IEEE80211_S_AUTH:
1850 if (ic->ic_opmode == IEEE80211_M_STA) {
1851 struct ieee80211_node *ni;
1855 if (acx_join_bss(sc, ACX_MODE_STA, ni) != 0) {
1856 if_printf(&ic->ic_if, "join BSS failed\n");
1861 DPRINTF((&ic->ic_if, "join BSS\n"));
1862 if (ic->ic_state == IEEE80211_S_ASSOC) {
1863 DPRINTF((&ic->ic_if,
1864 "change from assoc to run\n"));
1865 ic->ic_state = IEEE80211_S_RUN;
1869 case IEEE80211_S_RUN:
1870 if (ic->ic_opmode == IEEE80211_M_IBSS ||
1871 ic->ic_opmode == IEEE80211_M_HOSTAP) {
1872 struct ieee80211_node *ni;
1876 chan = ieee80211_chan2ieee(ic, ni->ni_chan);
1880 if (acx_enable_txchan(sc, chan) != 0) {
1881 if_printf(&ic->ic_if,
1882 "enable TX on channel %d failed\n",
1887 if (acx_enable_rxchan(sc, chan) != 0) {
1888 if_printf(&ic->ic_if,
1889 "enable RX on channel %d failed\n",
1894 if (acx_set_beacon_tmplt(sc, ni) != 0) {
1895 if_printf(&ic->ic_if,
1896 "set bescon template failed\n");
1900 if (acx_set_probe_resp_tmplt(sc, ni) != 0) {
1901 if_printf(&ic->ic_if, "set probe response "
1902 "template failed\n");
1906 if (ic->ic_opmode == IEEE80211_M_IBSS)
1907 mode = ACX_MODE_ADHOC;
1911 if (acx_join_bss(sc, mode, ni) != 0) {
1912 if_printf(&ic->ic_if, "acx_join_ibss failed\n");
1916 DPRINTF((&ic->ic_if, "join IBSS\n"));
1927 nstate = IEEE80211_S_INIT;
1930 return sc->sc_newstate(ic, nstate, arg);
1934 acx_init_tmplt_ordered(struct acx_softc *sc)
1936 struct acx_tmplt_tim tim;
1938 #define INIT_TMPLT(name) \
1940 if (acx_init_##name##_tmplt(sc) != 0) \
1946 * Order of templates initialization:
1952 * Above order is critical to get a correct memory map.
1954 INIT_TMPLT(probe_req);
1955 INIT_TMPLT(null_data);
1958 INIT_TMPLT(probe_resp);
1960 /* Setup TIM template */
1961 bzero(&tim, sizeof(tim));
1962 tim.tim_eid = IEEE80211_ELEMID_TIM;
1963 tim.tim_len = ACX_TIM_LEN(ACX_TIM_BITMAP_LEN);
1964 if (_acx_set_tim_tmplt(sc, &tim,
1965 ACX_TMPLT_TIM_SIZ(ACX_TIM_BITMAP_LEN)) != 0) {
1966 if_printf(&sc->sc_ic.ic_if, "%s can't set tim tmplt\n",
1976 acx_ring_dma_addr(void *arg, bus_dma_segment_t *seg, int nseg, int error)
1978 *((uint32_t *)arg) = seg->ds_addr;
1982 acx_dma_alloc(struct acx_softc *sc)
1984 struct acx_ring_data *rd = &sc->sc_ring_data;
1985 struct acx_buf_data *bd = &sc->sc_buf_data;
1988 /* Allocate DMA stuffs for RX descriptors */
1989 error = bus_dma_tag_create(NULL, PAGE_SIZE, 0,
1990 BUS_SPACE_MAXADDR_32BIT, BUS_SPACE_MAXADDR,
1992 ACX_RX_RING_SIZE, 1, ACX_RX_RING_SIZE,
1993 0, &rd->rx_ring_dma_tag);
1995 if_printf(&sc->sc_ic.ic_if, "can't create rx ring dma tag\n");
1999 error = bus_dmamem_alloc(rd->rx_ring_dma_tag, (void **)&rd->rx_ring,
2000 BUS_DMA_WAITOK | BUS_DMA_ZERO,
2001 &rd->rx_ring_dmamap);
2003 if_printf(&sc->sc_ic.ic_if,
2004 "can't allocate rx ring dma memory\n");
2005 bus_dma_tag_destroy(rd->rx_ring_dma_tag);
2006 rd->rx_ring_dma_tag = NULL;
2010 error = bus_dmamap_load(rd->rx_ring_dma_tag, rd->rx_ring_dmamap,
2011 rd->rx_ring, ACX_RX_RING_SIZE,
2012 acx_ring_dma_addr, &rd->rx_ring_paddr,
2015 if_printf(&sc->sc_ic.ic_if, "can't get rx ring dma address\n");
2016 bus_dmamem_free(rd->rx_ring_dma_tag, rd->rx_ring,
2017 rd->rx_ring_dmamap);
2018 bus_dma_tag_destroy(rd->rx_ring_dma_tag);
2019 rd->rx_ring_dma_tag = NULL;
2023 /* Allocate DMA stuffs for TX descriptors */
2024 error = bus_dma_tag_create(NULL, PAGE_SIZE, 0,
2025 BUS_SPACE_MAXADDR_32BIT, BUS_SPACE_MAXADDR,
2027 ACX_TX_RING_SIZE, 1, ACX_TX_RING_SIZE,
2028 0, &rd->tx_ring_dma_tag);
2030 if_printf(&sc->sc_ic.ic_if, "can't create tx ring dma tag\n");
2034 error = bus_dmamem_alloc(rd->tx_ring_dma_tag, (void **)&rd->tx_ring,
2035 BUS_DMA_WAITOK | BUS_DMA_ZERO,
2036 &rd->tx_ring_dmamap);
2038 if_printf(&sc->sc_ic.ic_if,
2039 "can't allocate tx ring dma memory\n");
2040 bus_dma_tag_destroy(rd->tx_ring_dma_tag);
2041 rd->tx_ring_dma_tag = NULL;
2045 error = bus_dmamap_load(rd->tx_ring_dma_tag, rd->tx_ring_dmamap,
2046 rd->tx_ring, ACX_TX_RING_SIZE,
2047 acx_ring_dma_addr, &rd->tx_ring_paddr,
2050 if_printf(&sc->sc_ic.ic_if, "can't get tx ring dma address\n");
2051 bus_dmamem_free(rd->tx_ring_dma_tag, rd->tx_ring,
2052 rd->tx_ring_dmamap);
2053 bus_dma_tag_destroy(rd->tx_ring_dma_tag);
2054 rd->tx_ring_dma_tag = NULL;
2058 /* Create DMA tag for RX/TX mbuf map */
2059 error = bus_dma_tag_create(NULL, 1, 0,
2060 BUS_SPACE_MAXADDR_32BIT, BUS_SPACE_MAXADDR,
2062 MCLBYTES, 1, MCLBYTES,
2063 0, &bd->mbuf_dma_tag);
2065 if_printf(&sc->sc_ic.ic_if, "can't create mbuf dma tag\n");
2069 /* Create a spare RX DMA map */
2070 error = bus_dmamap_create(bd->mbuf_dma_tag, 0, &bd->mbuf_tmp_dmamap);
2072 if_printf(&sc->sc_ic.ic_if, "can't create tmp mbuf dma map\n");
2073 bus_dma_tag_destroy(bd->mbuf_dma_tag);
2074 bd->mbuf_dma_tag = NULL;
2078 /* Create DMA map for RX mbufs */
2079 for (i = 0; i < ACX_RX_DESC_CNT; ++i) {
2080 error = bus_dmamap_create(bd->mbuf_dma_tag, 0,
2081 &bd->rx_buf[i].rb_mbuf_dmamap);
2083 if_printf(&sc->sc_ic.ic_if, "can't create rx mbuf "
2084 "dma map (%d)\n", i);
2087 bd->rx_buf[i].rb_desc = &rd->rx_ring[i];
2090 /* Create DMA map for TX mbufs */
2091 for (i = 0; i < ACX_TX_DESC_CNT; ++i) {
2092 error = bus_dmamap_create(bd->mbuf_dma_tag, 0,
2093 &bd->tx_buf[i].tb_mbuf_dmamap);
2095 if_printf(&sc->sc_ic.ic_if, "can't create tx mbuf "
2096 "dma map (%d)\n", i);
2099 bd->tx_buf[i].tb_desc1 = &rd->tx_ring[i * 2];
2100 bd->tx_buf[i].tb_desc2 = &rd->tx_ring[(i * 2) + 1];
2107 acx_dma_free(struct acx_softc *sc)
2109 struct acx_ring_data *rd = &sc->sc_ring_data;
2110 struct acx_buf_data *bd = &sc->sc_buf_data;
2113 if (rd->rx_ring_dma_tag != NULL) {
2114 bus_dmamap_unload(rd->rx_ring_dma_tag, rd->rx_ring_dmamap);
2115 bus_dmamem_free(rd->rx_ring_dma_tag, rd->rx_ring,
2116 rd->rx_ring_dmamap);
2117 bus_dma_tag_destroy(rd->rx_ring_dma_tag);
2120 if (rd->tx_ring_dma_tag != NULL) {
2121 bus_dmamap_unload(rd->tx_ring_dma_tag, rd->tx_ring_dmamap);
2122 bus_dmamem_free(rd->tx_ring_dma_tag, rd->tx_ring,
2123 rd->tx_ring_dmamap);
2124 bus_dma_tag_destroy(rd->tx_ring_dma_tag);
2127 for (i = 0; i < ACX_RX_DESC_CNT; ++i) {
2128 if (bd->rx_buf[i].rb_desc != NULL) {
2129 if (bd->rx_buf[i].rb_mbuf != NULL) {
2130 bus_dmamap_unload(bd->mbuf_dma_tag,
2131 bd->rx_buf[i].rb_mbuf_dmamap);
2132 m_freem(bd->rx_buf[i].rb_mbuf);
2134 bus_dmamap_destroy(bd->mbuf_dma_tag,
2135 bd->rx_buf[i].rb_mbuf_dmamap);
2139 for (i = 0; i < ACX_TX_DESC_CNT; ++i) {
2140 if (bd->tx_buf[i].tb_desc1 != NULL) {
2141 if (bd->tx_buf[i].tb_mbuf != NULL) {
2142 bus_dmamap_unload(bd->mbuf_dma_tag,
2143 bd->tx_buf[i].tb_mbuf_dmamap);
2144 m_freem(bd->tx_buf[i].tb_mbuf);
2146 bus_dmamap_destroy(bd->mbuf_dma_tag,
2147 bd->tx_buf[i].tb_mbuf_dmamap);
2151 if (bd->mbuf_dma_tag != NULL) {
2152 bus_dmamap_destroy(bd->mbuf_dma_tag, bd->mbuf_tmp_dmamap);
2153 bus_dma_tag_destroy(bd->mbuf_dma_tag);
2158 acx_init_tx_ring(struct acx_softc *sc)
2160 struct acx_ring_data *rd;
2161 struct acx_buf_data *bd;
2165 rd = &sc->sc_ring_data;
2166 paddr = rd->tx_ring_paddr;
2167 for (i = 0; i < (ACX_TX_DESC_CNT * 2) - 1; ++i) {
2168 paddr += sizeof(struct acx_host_desc);
2170 rd->tx_ring[i].h_ctrl = htole16(DESC_CTRL_HOSTOWN);
2172 if (i == (ACX_TX_DESC_CNT * 2) - 1)
2173 rd->tx_ring[i].h_next_desc = htole32(rd->tx_ring_paddr);
2175 rd->tx_ring[i].h_next_desc = htole32(paddr);
2178 bus_dmamap_sync(rd->tx_ring_dma_tag, rd->tx_ring_dmamap,
2179 BUS_DMASYNC_PREWRITE);
2181 bd = &sc->sc_buf_data;
2182 bd->tx_free_start = 0;
2183 bd->tx_used_start = 0;
2184 bd->tx_used_count = 0;
2190 acx_init_rx_ring(struct acx_softc *sc)
2192 struct acx_ring_data *rd;
2193 struct acx_buf_data *bd;
2197 bd = &sc->sc_buf_data;
2198 rd = &sc->sc_ring_data;
2199 paddr = rd->rx_ring_paddr;
2201 for (i = 0; i < ACX_RX_DESC_CNT; ++i) {
2204 paddr += sizeof(struct acx_host_desc);
2206 error = acx_newbuf(sc, &bd->rx_buf[i], 1);
2210 if (i == ACX_RX_DESC_CNT - 1)
2211 rd->rx_ring[i].h_next_desc = htole32(rd->rx_ring_paddr);
2213 rd->rx_ring[i].h_next_desc = htole32(paddr);
2216 bus_dmamap_sync(rd->rx_ring_dma_tag, rd->rx_ring_dmamap,
2217 BUS_DMASYNC_PREWRITE);
2219 bd->rx_scan_start = 0;
2224 acx_buf_dma_addr(void *arg, bus_dma_segment_t *seg, int nseg,
2225 bus_size_t mapsz, int error)
2231 KASSERT(nseg == 1, ("too many RX dma segments\n"));
2232 *((uint32_t *)arg) = seg->ds_addr;
2236 acx_newbuf(struct acx_softc *sc, struct acx_rxbuf *rb, int wait)
2238 struct acx_buf_data *bd;
2244 bd = &sc->sc_buf_data;
2246 m = m_getcl(wait ? MB_WAIT : MB_DONTWAIT, MT_DATA, M_PKTHDR);
2250 m->m_len = m->m_pkthdr.len = MCLBYTES;
2252 error = bus_dmamap_load_mbuf(bd->mbuf_dma_tag, bd->mbuf_tmp_dmamap,
2253 m, acx_buf_dma_addr, &paddr,
2254 wait ? BUS_DMA_WAITOK : BUS_DMA_NOWAIT);
2257 if_printf(&sc->sc_ic.ic_if, "can't map rx mbuf %d\n", error);
2261 /* Unload originally mapped mbuf */
2262 bus_dmamap_unload(bd->mbuf_dma_tag, rb->rb_mbuf_dmamap);
2264 /* Swap this dmamap with tmp dmamap */
2265 map = rb->rb_mbuf_dmamap;
2266 rb->rb_mbuf_dmamap = bd->mbuf_tmp_dmamap;
2267 bd->mbuf_tmp_dmamap = map;
2270 rb->rb_desc->h_data_paddr = htole32(paddr);
2271 rb->rb_desc->h_data_len = htole16(m->m_len);
2273 bus_dmamap_sync(bd->mbuf_dma_tag, rb->rb_mbuf_dmamap,
2274 BUS_DMASYNC_PREREAD);
2279 acx_encap(struct acx_softc *sc, struct acx_txbuf *txbuf, struct mbuf *m,
2280 struct ieee80211_node *ni)
2282 struct acx_buf_data *bd = &sc->sc_buf_data;
2283 struct acx_ring_data *rd = &sc->sc_ring_data;
2288 KASSERT(txbuf->tb_mbuf == NULL, ("free TX buf has mbuf installed\n"));
2291 if (m->m_pkthdr.len > MCLBYTES) {
2292 if_printf(&sc->sc_ic.ic_if, "mbuf too big\n");
2295 } else if (m->m_pkthdr.len < ACX_FRAME_HDRLEN) {
2296 if_printf(&sc->sc_ic.ic_if, "mbuf too small\n");
2301 error = bus_dmamap_load_mbuf(bd->mbuf_dma_tag, txbuf->tb_mbuf_dmamap,
2302 m, acx_buf_dma_addr, &paddr,
2304 if (error && error != EFBIG) {
2305 if_printf(&sc->sc_ic.ic_if, "can't map tx mbuf1 %d\n", error);
2309 if (error) { /* error == EFBIG */
2312 m_new = m_defrag(m, MB_DONTWAIT);
2313 if (m_new == NULL) {
2314 if_printf(&sc->sc_ic.ic_if, "can't defrag tx mbuf\n");
2321 error = bus_dmamap_load_mbuf(bd->mbuf_dma_tag,
2322 txbuf->tb_mbuf_dmamap, m,
2323 acx_buf_dma_addr, &paddr,
2326 if_printf(&sc->sc_ic.ic_if, "can't map tx mbuf2 %d\n",
2334 bus_dmamap_sync(bd->mbuf_dma_tag, txbuf->tb_mbuf_dmamap,
2335 BUS_DMASYNC_PREWRITE);
2338 txbuf->tb_node = ni;
2341 * TX buffers are accessed in following way:
2342 * acx_fw_txdesc -> acx_host_desc -> buffer
2344 * It is quite strange that acx also querys acx_host_desc next to
2345 * the one we have assigned to acx_fw_txdesc even if first one's
2346 * acx_host_desc.h_data_len == acx_fw_txdesc.f_tx_len
2348 * So we allocate two acx_host_desc for one acx_fw_txdesc and
2349 * assign the first acx_host_desc to acx_fw_txdesc
2352 * host_desc1.h_data_len = buffer_len
2353 * host_desc2.h_data_len = buffer_len - mac_header_len
2356 * host_desc1.h_data_len = mac_header_len
2357 * host_desc2.h_data_len = buffer_len - mac_header_len
2360 txbuf->tb_desc1->h_data_paddr = htole32(paddr);
2361 txbuf->tb_desc2->h_data_paddr = htole32(paddr + ACX_FRAME_HDRLEN);
2363 txbuf->tb_desc1->h_data_len =
2364 htole16(sc->chip_txdesc1_len ? sc->chip_txdesc1_len
2366 txbuf->tb_desc2->h_data_len =
2367 htole16(m->m_pkthdr.len - ACX_FRAME_HDRLEN);
2371 * We can't simply assign f_tx_ctrl, we will first read it back
2372 * and change it bit by bit
2374 ctrl = FW_TXDESC_GETFIELD_1(sc, txbuf, f_tx_ctrl);
2375 ctrl |= sc->chip_fw_txdesc_ctrl; /* extra chip specific flags */
2376 ctrl &= ~(DESC_CTRL_HOSTOWN | DESC_CTRL_ACXDONE);
2378 FW_TXDESC_SETFIELD_4(sc, txbuf, f_tx_len, m->m_pkthdr.len);
2379 FW_TXDESC_SETFIELD_1(sc, txbuf, f_tx_error, 0);
2380 FW_TXDESC_SETFIELD_1(sc, txbuf, f_tx_data_nretry, 0);
2381 FW_TXDESC_SETFIELD_1(sc, txbuf, f_tx_rts_nretry, 0);
2382 FW_TXDESC_SETFIELD_1(sc, txbuf, f_tx_rts_ok, 0);
2383 sc->chip_set_fw_txdesc_rate(sc, txbuf, ni, m->m_pkthdr.len);
2385 txbuf->tb_desc1->h_ctrl = 0;
2386 txbuf->tb_desc2->h_ctrl = 0;
2387 bus_dmamap_sync(rd->tx_ring_dma_tag, rd->tx_ring_dmamap,
2388 BUS_DMASYNC_PREWRITE);
2390 FW_TXDESC_SETFIELD_1(sc, txbuf, f_tx_ctrl2, 0);
2391 FW_TXDESC_SETFIELD_1(sc, txbuf, f_tx_ctrl, ctrl);
2393 /* Tell chip to inform us about TX completion */
2394 CSR_WRITE_2(sc, ACXREG_INTR_TRIG, ACXRV_TRIG_TX_FINI);
2402 acx_set_null_tmplt(struct acx_softc *sc)
2404 struct acx_tmplt_null_data n;
2405 struct ieee80211_frame *f;
2407 bzero(&n, sizeof(n));
2410 f->i_fc[0] = IEEE80211_FC0_VERSION_0 | IEEE80211_FC0_TYPE_DATA |
2411 IEEE80211_FC0_SUBTYPE_NODATA;
2412 IEEE80211_ADDR_COPY(f->i_addr1, etherbroadcastaddr);
2413 IEEE80211_ADDR_COPY(f->i_addr2, IF_LLADDR(&sc->sc_ic.ic_if));
2414 IEEE80211_ADDR_COPY(f->i_addr3, etherbroadcastaddr);
2416 return _acx_set_null_data_tmplt(sc, &n, sizeof(n));
2420 acx_set_probe_req_tmplt(struct acx_softc *sc, const char *ssid, int ssid_len)
2422 struct acx_tmplt_probe_req req;
2423 struct ieee80211_frame *f;
2427 bzero(&req, sizeof(req));
2429 f = &req.data.u_data.f;
2430 f->i_fc[0] = IEEE80211_FC0_VERSION_0 | IEEE80211_FC0_TYPE_MGT |
2431 IEEE80211_FC0_SUBTYPE_PROBE_REQ;
2432 IEEE80211_ADDR_COPY(f->i_addr1, etherbroadcastaddr);
2433 IEEE80211_ADDR_COPY(f->i_addr2, IF_LLADDR(&sc->sc_ic.ic_if));
2434 IEEE80211_ADDR_COPY(f->i_addr3, etherbroadcastaddr);
2436 v = req.data.u_data.var;
2437 v = ieee80211_add_ssid(v, ssid, ssid_len);
2438 v = ieee80211_add_rates(v, &sc->sc_ic.ic_sup_rates[sc->chip_phymode]);
2439 v = ieee80211_add_xrates(v, &sc->sc_ic.ic_sup_rates[sc->chip_phymode]);
2440 vlen = v - req.data.u_data.var;
2442 return _acx_set_probe_req_tmplt(sc, &req,
2443 ACX_TMPLT_PROBE_REQ_SIZ(vlen));
2447 acx_set_probe_resp_tmplt(struct acx_softc *sc, struct ieee80211_node *ni)
2449 struct ieee80211com *ic = &sc->sc_ic;
2450 struct acx_tmplt_probe_resp resp;
2451 struct ieee80211_frame *f;
2455 m = ieee80211_probe_resp_alloc(ic, ni);
2458 DPRINTF((&ic->ic_if, "%s alloc probe resp size %d\n", __func__,
2461 f = mtod(m, struct ieee80211_frame *);
2462 IEEE80211_ADDR_COPY(f->i_addr1, etherbroadcastaddr);
2464 bzero(&resp, sizeof(resp));
2465 m_copydata(m, 0, m->m_pkthdr.len, (caddr_t)&resp.data);
2466 len = m->m_pkthdr.len + sizeof(resp.size);
2469 return _acx_set_probe_resp_tmplt(sc, &resp, len);
2473 acx_set_beacon_tmplt(struct acx_softc *sc, struct ieee80211_node *ni)
2475 struct ieee80211com *ic = &sc->sc_ic;
2476 struct acx_tmplt_beacon beacon;
2477 struct ieee80211_beacon_offsets bo;
2481 bzero(&bo, sizeof(bo));
2482 m = ieee80211_beacon_alloc(ic, ni, &bo);
2485 DPRINTF((&ic->ic_if, "%s alloc beacon size %d\n", __func__,
2488 bzero(&beacon, sizeof(beacon));
2489 m_copydata(m, 0, m->m_pkthdr.len, (caddr_t)&beacon.data);
2490 len = m->m_pkthdr.len + sizeof(beacon.size);
2493 return _acx_set_beacon_tmplt(sc, &beacon, len);
2497 acx_sysctl_msdu_lifetime(SYSCTL_HANDLER_ARGS)
2499 struct acx_softc *sc = arg1;
2500 struct ifnet *ifp = &sc->sc_ic.ic_if;
2503 lwkt_serialize_enter(ifp->if_serializer);
2505 v = sc->sc_msdu_lifetime;
2506 error = sysctl_handle_int(oidp, &v, 0, req);
2507 if (error || req->newptr == NULL)
2514 if (sc->sc_flags & ACX_FLAG_FW_LOADED) {
2515 struct acx_conf_msdu_lifetime msdu_lifetime;
2517 msdu_lifetime.lifetime = htole32(v);
2518 if (acx_set_msdu_lifetime_conf(sc, &msdu_lifetime) != 0) {
2519 if_printf(&sc->sc_ic.ic_if,
2520 "can't set MSDU lifetime\n");
2525 sc->sc_msdu_lifetime = v;
2527 lwkt_serialize_exit(ifp->if_serializer);
2532 acx_media_change(struct ifnet *ifp)
2536 error = ieee80211_media_change(ifp);
2537 if (error != ENETRESET)
2540 if ((ifp->if_flags & (IFF_UP | IFF_RUNNING)) == (IFF_UP | IFF_RUNNING))
2541 acx_init(ifp->if_softc);