3 * Copyright (c) 2009-2010 Alexander Egorenkov <egorenar@gmail.com>
4 * Copyright (c) 2009 Damien Bergamini <damien.bergamini@free.fr>
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 #include "rt2860_softc.h"
20 #include "rt2860_reg.h"
21 #include "rt2860_eeprom.h"
22 #include "rt2860_ucode.h"
23 #include "rt2860_txwi.h"
24 #include "rt2860_rxwi.h"
25 #include "rt2860_io.h"
26 #include "rt2860_read_eeprom.h"
27 #include "rt2860_led.h"
28 #include "rt2860_rf.h"
29 #include "rt2860_debug.h"
35 #define PCI_VENDOR_RALINK 0x1814
36 #define PCI_PRODUCT_RALINK_RT2860_PCI 0x0601
37 #define PCI_PRODUCT_RALINK_RT2860_PCIe 0x0681
38 #define PCI_PRODUCT_RALINK_RT2760_PCI 0x0701
39 #define PCI_PRODUCT_RALINK_RT2790_PCIe 0x0781
41 #define RT2860_MAX_AGG_SIZE 3840
43 #define RT2860_TX_DATA_SEG0_SIZE \
44 (sizeof(struct rt2860_txwi) + sizeof(struct ieee80211_qosframe_addr4))
46 #define RT2860_NOISE_FLOOR -95
48 #define RT2860_AID2WCID(aid) ((aid) & 0xff)
50 #define RT2860_ACK_SIZE 14
52 #define IEEE80211_HAS_ADDR4(wh) \
53 (((wh)->i_fc[1] & IEEE80211_FC1_DIR_MASK) == IEEE80211_FC1_DIR_DSTODS)
55 #define RT2860_MS(_v, _f) (((_v) & _f) >> _f##_S)
56 #define RT2860_SM(_v, _f) (((_v) << _f##_S) & _f)
58 #define RT2860_TX_WATCHDOG_TIMEOUT 5
60 #define RT2860_WCID_RESERVED 0xff
61 #define RT2860_WCID_MCAST 0xf7
64 * Data structures and types
67 struct rt2860_pci_ident
75 * Static function prototypes
78 static int rt2860_probe(device_t dev
);
80 static int rt2860_attach(device_t dev
);
82 static int rt2860_detach(device_t dev
);
84 static int rt2860_shutdown(device_t dev
);
86 static int rt2860_suspend(device_t dev
);
88 static int rt2860_resume(device_t dev
);
90 static void rt2860_init_channels(struct rt2860_softc
*sc
);
92 static void rt2860_init_channels_ht40(struct rt2860_softc
*sc
);
94 static void rt2860_init_locked(void *priv
);
96 static void rt2860_init(void *priv
);
98 static int rt2860_init_bbp(struct rt2860_softc
*sc
);
100 static void rt2860_stop_locked(void *priv
);
102 static void rt2860_stop(void *priv
);
104 static void rt2860_start(struct ifnet
*ifp
);
106 static int rt2860_ioctl(struct ifnet
*ifp
, u_long cmd
, caddr_t data
);
108 static struct ieee80211vap
*rt2860_vap_create(struct ieee80211com
*ic
,
109 const char name
[IFNAMSIZ
], int unit
, int opmode
, int flags
,
110 const uint8_t bssid
[IEEE80211_ADDR_LEN
],
111 const uint8_t mac
[IEEE80211_ADDR_LEN
]);
113 static void rt2860_vap_delete(struct ieee80211vap
*vap
);
115 static int rt2860_vap_reset(struct ieee80211vap
*vap
, u_long cmd
);
117 static int rt2860_vap_newstate(struct ieee80211vap
*vap
,
118 enum ieee80211_state nstate
, int arg
);
120 static void rt2860_vap_key_update_begin(struct ieee80211vap
*vap
);
122 static void rt2860_vap_key_update_end(struct ieee80211vap
*vap
);
124 static int rt2860_vap_key_set(struct ieee80211vap
*vap
,
125 const struct ieee80211_key
*k
, const uint8_t mac
[IEEE80211_ADDR_LEN
]);
127 static int rt2860_vap_key_delete(struct ieee80211vap
*vap
,
128 const struct ieee80211_key
*k
);
130 static void rt2860_vap_update_beacon(struct ieee80211vap
*vap
, int what
);
132 static int rt2860_media_change(struct ifnet
*ifp
);
134 static struct ieee80211_node
*rt2860_node_alloc(struct ieee80211vap
*vap
,
135 const uint8_t mac
[IEEE80211_ADDR_LEN
]);
137 static void rt2860_node_cleanup(struct ieee80211_node
*ni
);
139 static void rt2860_node_getmimoinfo(const struct ieee80211_node
*ni
,
140 struct ieee80211_mimo_info
*mi
);
142 static int rt2860_setregdomain(struct ieee80211com
*ic
,
143 struct ieee80211_regdomain
*reg
,
144 int nchans
, struct ieee80211_channel chans
[]);
146 static void rt2860_getradiocaps(struct ieee80211com
*ic
,
147 int maxchans
, int *nchans
, struct ieee80211_channel chans
[]);
149 static void rt2860_scan_start(struct ieee80211com
*ic
);
151 static void rt2860_scan_end(struct ieee80211com
*ic
);
153 static void rt2860_set_channel(struct ieee80211com
*ic
);
155 static void rt2860_newassoc(struct ieee80211_node
*ni
, int isnew
);
157 static void rt2860_updateslot(struct ifnet
*ifp
);
159 static void rt2860_update_promisc(struct ifnet
*ifp
);
161 static void rt2860_update_mcast(struct ifnet
*ifp
);
163 static int rt2860_wme_update(struct ieee80211com
*ic
);
165 static int rt2860_raw_xmit(struct ieee80211_node
*ni
, struct mbuf
*m
,
166 const struct ieee80211_bpf_params
*params
);
168 static int rt2860_recv_action(struct ieee80211_node
*ni
,
169 const struct ieee80211_frame
*wh
,
170 const uint8_t *frm
, const uint8_t *efrm
);
172 static int rt2860_send_action(struct ieee80211_node
*ni
,
173 int cat
, int act
, void *sa
);
175 static void rt2860_amrr_update_iter_func(void *arg
, struct ieee80211_node
*ni
);
177 static void rt2860_periodic(void *arg
);
179 static void rt2860_tx_watchdog(void *arg
);
181 static int rt2860_staid_alloc(struct rt2860_softc
*sc
, int aid
);
183 static void rt2860_staid_delete(struct rt2860_softc
*sc
, int staid
);
185 static void rt2860_asic_set_bssid(struct rt2860_softc
*sc
,
186 const uint8_t *bssid
);
188 static void rt2860_asic_set_macaddr(struct rt2860_softc
*sc
,
189 const uint8_t *addr
);
191 static void rt2860_asic_enable_tsf_sync(struct rt2860_softc
*sc
);
193 static void rt2860_asic_disable_tsf_sync(struct rt2860_softc
*sc
);
195 static void rt2860_asic_enable_mrr(struct rt2860_softc
*sc
);
197 static void rt2860_asic_set_txpreamble(struct rt2860_softc
*sc
);
199 static void rt2860_asic_set_basicrates(struct rt2860_softc
*sc
);
201 static void rt2860_asic_update_rtsthreshold(struct rt2860_softc
*sc
);
203 static void rt2860_asic_update_txpower(struct rt2860_softc
*sc
);
205 static void rt2860_asic_update_promisc(struct rt2860_softc
*sc
);
207 static void rt2860_asic_updateprot(struct rt2860_softc
*sc
);
209 static void rt2860_asic_updateslot(struct rt2860_softc
*sc
);
211 static void rt2860_asic_wme_update(struct rt2860_softc
*sc
);
213 static void rt2860_asic_update_beacon(struct rt2860_softc
*sc
,
214 struct ieee80211vap
*vap
);
216 static void rt2860_asic_clear_keytables(struct rt2860_softc
*sc
);
218 static int rt2860_beacon_alloc(struct rt2860_softc
*sc
,
219 struct ieee80211vap
*vap
);
221 static uint8_t rt2860_rxrate(struct rt2860_rxwi
*rxwi
);
223 static uint8_t rt2860_maxrssi_rxpath(struct rt2860_softc
*sc
,
224 const struct rt2860_rxwi
*rxwi
);
226 static int8_t rt2860_rssi2dbm(struct rt2860_softc
*sc
,
227 uint8_t rssi
, uint8_t rxpath
);
229 static uint8_t rt2860_rate2mcs(uint8_t rate
);
231 static int rt2860_tx_mgmt(struct rt2860_softc
*sc
,
232 struct mbuf
*m
, struct ieee80211_node
*ni
, int qid
);
234 static int rt2860_tx_data(struct rt2860_softc
*sc
,
235 struct mbuf
*m
, struct ieee80211_node
*ni
, int qid
);
237 static int rt2860_tx_raw(struct rt2860_softc
*sc
,
238 struct mbuf
*m
, struct ieee80211_node
*ni
,
239 const struct ieee80211_bpf_params
*params
);
241 static void rt2860_intr(void *arg
);
243 static void rt2860_tx_coherent_intr(struct rt2860_softc
*sc
);
245 static void rt2860_rx_coherent_intr(struct rt2860_softc
*sc
);
247 static void rt2860_txrx_coherent_intr(struct rt2860_softc
*sc
);
249 static void rt2860_fifo_sta_full_intr(struct rt2860_softc
*sc
);
251 static void rt2860_rx_intr(struct rt2860_softc
*sc
);
253 static void rt2860_rx_delay_intr(struct rt2860_softc
*sc
);
255 static void rt2860_tx_intr(struct rt2860_softc
*sc
, int qid
);
257 static void rt2860_tx_delay_intr(struct rt2860_softc
*sc
);
259 static void rt2860_pre_tbtt_intr(struct rt2860_softc
*sc
);
261 static void rt2860_tbtt_intr(struct rt2860_softc
*sc
);
263 static void rt2860_mcu_cmd_intr(struct rt2860_softc
*sc
);
265 static void rt2860_auto_wakeup_intr(struct rt2860_softc
*sc
);
267 static void rt2860_gp_timer_intr(struct rt2860_softc
*sc
);
269 static void rt2860_rx_done_task(void *context
, int pending
);
271 static void rt2860_tx_done_task(void *context
, int pending
);
273 static void rt2860_fifo_sta_full_task(void *context
, int pending
);
275 static void rt2860_periodic_task(void *context
, int pending
);
277 static int rt2860_rx_eof(struct rt2860_softc
*sc
, int limit
);
279 static void rt2860_tx_eof(struct rt2860_softc
*sc
,
280 struct rt2860_softc_tx_ring
*ring
);
282 static void rt2860_update_stats(struct rt2860_softc
*sc
);
284 static void rt2860_bbp_tuning(struct rt2860_softc
*sc
);
286 static void rt2860_watchdog(struct rt2860_softc
*sc
);
288 static void rt2860_drain_fifo_stats(struct rt2860_softc
*sc
);
290 static void rt2860_update_raw_counters(struct rt2860_softc
*sc
);
292 static void rt2860_intr_enable(struct rt2860_softc
*sc
, uint32_t intr_mask
);
294 static void rt2860_intr_disable(struct rt2860_softc
*sc
, uint32_t intr_mask
);
296 static int rt2860_txrx_enable(struct rt2860_softc
*sc
);
298 static int rt2860_alloc_rx_ring(struct rt2860_softc
*sc
,
299 struct rt2860_softc_rx_ring
*ring
);
301 static void rt2860_reset_rx_ring(struct rt2860_softc
*sc
,
302 struct rt2860_softc_rx_ring
*ring
);
304 static void rt2860_free_rx_ring(struct rt2860_softc
*sc
,
305 struct rt2860_softc_rx_ring
*ring
);
307 static int rt2860_alloc_tx_ring(struct rt2860_softc
*sc
,
308 struct rt2860_softc_tx_ring
*ring
, int qid
);
310 static void rt2860_reset_tx_ring(struct rt2860_softc
*sc
,
311 struct rt2860_softc_tx_ring
*ring
);
313 static void rt2860_free_tx_ring(struct rt2860_softc
*sc
,
314 struct rt2860_softc_tx_ring
*ring
);
316 static void rt2860_dma_map_addr(void *arg
, bus_dma_segment_t
*segs
,
317 int nseg
, int error
);
319 static void rt2860_sysctl_attach(struct rt2860_softc
*sc
);
325 static const struct rt2860_pci_ident rt2860_pci_ids
[] =
327 { PCI_VENDOR_RALINK
, PCI_PRODUCT_RALINK_RT2860_PCI
, "Ralink RT2860 PCI" },
328 { PCI_VENDOR_RALINK
, PCI_PRODUCT_RALINK_RT2860_PCIe
, "Ralink RT2860 PCIe" },
329 { PCI_VENDOR_RALINK
, PCI_PRODUCT_RALINK_RT2760_PCI
, "Ralink RT2760 PCI" },
330 { PCI_VENDOR_RALINK
, PCI_PRODUCT_RALINK_RT2790_PCIe
, "Ralink RT2790 PCIe" },
340 { RT2860_REG_PBF_BCN_OFFSET0
, 0xf8f0e8e0 },
341 { RT2860_REG_PBF_BCN_OFFSET1
, 0x6f77d0c8 },
342 { RT2860_REG_LEGACY_BASIC_RATE
, 0x0000013f },
343 { RT2860_REG_HT_BASIC_RATE
, 0x00008003 },
344 { RT2860_REG_SYS_CTRL
, 0x00000000 },
345 { RT2860_REG_RX_FILTER_CFG
, 0x00017f97 },
346 { RT2860_REG_BKOFF_SLOT_CFG
, 0x00000209 },
347 { RT2860_REG_TX_SW_CFG0
, 0x00000000 },
348 { RT2860_REG_TX_SW_CFG1
, 0x00080606 },
349 { RT2860_REG_TX_LINK_CFG
, 0x00001020 },
350 { RT2860_REG_TX_TIMEOUT_CFG
, 0x000a2090 },
351 { RT2860_REG_MAX_LEN_CFG
, (1 << 12) | RT2860_MAX_AGG_SIZE
},
352 { RT2860_REG_LED_CFG
, 0x7f031e46 },
353 { RT2860_REG_PBF_MAX_PCNT
, 0x1f3fbf9f },
354 { RT2860_REG_TX_RTY_CFG
, 0x47d01f0f },
355 { RT2860_REG_AUTO_RSP_CFG
, 0x00000013 },
356 { RT2860_REG_TX_CCK_PROT_CFG
, 0x05740003 },
357 { RT2860_REG_TX_OFDM_PROT_CFG
, 0x05740003 },
358 { RT2860_REG_TX_GF20_PROT_CFG
, 0x01744004 },
359 { RT2860_REG_TX_GF40_PROT_CFG
, 0x03f44084 },
360 { RT2860_REG_TX_MM20_PROT_CFG
, 0x01744004 },
361 { RT2860_REG_TX_MM40_PROT_CFG
, 0x03f54084 },
362 { RT2860_REG_TX_TXOP_CTRL_CFG
, 0x0000583f },
363 { RT2860_REG_TX_RTS_CFG
, 0x00092b20 },
364 { RT2860_REG_TX_EXP_ACK_TIME
, 0x002400ca },
365 { RT2860_REG_HCCAPSMP_TXOP_HLDR_ET
, 0x00000002 },
366 { RT2860_REG_XIFS_TIME_CFG
, 0x33a41010 },
367 { RT2860_REG_PWR_PIN_CFG
, 0x00000003 },
368 { RT2860_REG_SCHDMA_WMM_AIFSN_CFG
, 0x00002273 },
369 { RT2860_REG_SCHDMA_WMM_CWMIN_CFG
, 0x00002344 },
370 { RT2860_REG_SCHDMA_WMM_CWMAX_CFG
, 0x000034aa },
373 #define RT2860_DEF_MAC_SIZE (sizeof(rt2860_def_mac) / sizeof(rt2860_def_mac[0]))
398 #define RT2860_DEF_BBP_SIZE (sizeof(rt2860_def_bbp) / sizeof(rt2860_def_bbp[0]))
400 SYSCTL_NODE(_hw
, OID_AUTO
, rt2860
, CTLFLAG_RD
, 0, "RT2860 driver parameters");
403 static int rt2860_debug
= 0;
404 SYSCTL_INT(_hw_rt2860
, OID_AUTO
, debug
, CTLFLAG_RW
, &rt2860_debug
, 0, "rt2860 debug level");
405 TUNABLE_INT("hw.rt2860.debug", &rt2860_debug
);
411 static int rt2860_probe(device_t dev
)
413 const struct rt2860_pci_ident
*ident
;
415 for (ident
= rt2860_pci_ids
; ident
->name
!= NULL
; ident
++)
417 if (pci_get_vendor(dev
) == ident
->vendor
&&
418 pci_get_device(dev
) == ident
->device
)
420 device_set_desc(dev
, ident
->name
);
431 static int rt2860_attach(device_t dev
)
433 struct rt2860_softc
*sc
;
435 struct ieee80211com
*ic
;
436 int error
, ntries
, i
;
438 sc
= device_get_softc(dev
);
440 if (pci_get_powerstate(dev
) != PCI_POWERSTATE_D0
)
442 printf("%s: chip is in D%d power mode, setting to D0\n",
443 device_get_nameunit(dev
), pci_get_powerstate(dev
));
444 pci_set_powerstate(dev
, PCI_POWERSTATE_D0
);
447 /* enable bus-mastering */
449 pci_enable_busmaster(dev
);
453 mtx_init(&sc
->lock
, device_get_nameunit(dev
),
454 MTX_NETWORK_LOCK
, MTX_DEF
| MTX_RECURSE
);
456 sc
->mem_rid
= PCIR_BAR(0);
457 sc
->mem
= bus_alloc_resource_any(dev
, SYS_RES_MEMORY
,
458 &sc
->mem_rid
, RF_ACTIVE
);
461 printf("%s: could not allocate memory resource\n",
462 device_get_nameunit(dev
));
467 sc
->bst
= rman_get_bustag(sc
->mem
);
468 sc
->bsh
= rman_get_bushandle(sc
->mem
);
471 sc
->irq
= bus_alloc_resource_any(dev
, SYS_RES_IRQ
,
472 &sc
->irq_rid
, RF_ACTIVE
| RF_SHAREABLE
);
475 printf("%s: could not allocate interrupt resource\n",
476 device_get_nameunit(dev
));
482 sc
->debug
= rt2860_debug
;
484 SYSCTL_ADD_INT(device_get_sysctl_ctx(dev
),
485 SYSCTL_CHILDREN(device_get_sysctl_tree(dev
)), OID_AUTO
,
486 "debug", CTLFLAG_RW
, &sc
->debug
, 0, "rt2860 debug level");
489 RT2860_DPRINTF(sc
, RT2860_DEBUG_ANY
,
491 device_get_nameunit(sc
->dev
));
493 /* wait for NIC to initialize */
495 for (ntries
= 0; ntries
< 100; ntries
++)
497 sc
->mac_rev
= rt2860_io_mac_read(sc
, RT2860_REG_MAC_CSR0
);
498 if (sc
->mac_rev
!= 0x00000000 && sc
->mac_rev
!= 0xffffffff)
506 printf("%s: timeout waiting for NIC to initialize\n",
507 device_get_nameunit(dev
));
512 rt2860_read_eeprom(sc
);
514 printf("%s: MAC/BBP RT2860 (rev 0x%08x), RF %s\n",
515 device_get_nameunit(sc
->dev
), sc
->mac_rev
,
516 rt2860_rf_name(sc
->rf_rev
));
518 /* clear key tables */
520 rt2860_asic_clear_keytables(sc
);
522 /* allocate Tx and Rx rings */
524 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
526 error
= rt2860_alloc_tx_ring(sc
, &sc
->tx_ring
[i
], i
);
529 printf("%s: could not allocate Tx ring #%d\n",
530 device_get_nameunit(sc
->dev
), i
);
535 sc
->tx_ring_mgtqid
= 5;
537 error
= rt2860_alloc_rx_ring(sc
, &sc
->rx_ring
);
540 printf("%s: could not allocate Rx ring\n",
541 device_get_nameunit(sc
->dev
));
545 callout_init(&sc
->periodic_ch
, 0);
546 callout_init_mtx(&sc
->tx_watchdog_ch
, &sc
->lock
, 0);
548 ifp
= sc
->ifp
= if_alloc(IFT_IEEE80211
);
551 printf("%s: could not if_alloc()\n",
552 device_get_nameunit(sc
->dev
));
559 if_initname(ifp
, "rt2860", device_get_unit(sc
->dev
));
561 ifp
->if_flags
= IFF_BROADCAST
| IFF_SIMPLEX
| IFF_MULTICAST
;
563 ifp
->if_init
= rt2860_init
;
564 ifp
->if_ioctl
= rt2860_ioctl
;
565 ifp
->if_start
= rt2860_start
;
567 IFQ_SET_MAXLEN(&ifp
->if_snd
, IFQ_MAXLEN
);
568 ifp
->if_snd
.ifq_drv_maxlen
= IFQ_MAXLEN
;
569 IFQ_SET_READY(&ifp
->if_snd
);
575 ic
->ic_phytype
= IEEE80211_T_HT
;
576 ic
->ic_opmode
= IEEE80211_M_STA
;
578 ic
->ic_caps
= IEEE80211_C_MONITOR
|
587 IEEE80211_C_SHPREAMBLE
|
594 ic
->ic_cryptocaps
|= IEEE80211_CRYPTO_WEP
|
595 IEEE80211_CRYPTO_TKIP
|
596 IEEE80211_CRYPTO_TKIPMIC
|
597 IEEE80211_CRYPTO_AES_CCM
;
599 ic
->ic_htcaps
= IEEE80211_HTC_HT
|
600 IEEE80211_HTC_AMSDU
| /* A-MSDU Tx */
601 IEEE80211_HTC_AMPDU
| /* A-MPDU Tx */
602 IEEE80211_HTC_SMPS
| /* MIMO power save */
603 IEEE80211_HTCAP_MAXAMSDU_3839
| /* max. A-MSDU Rx length */
604 IEEE80211_HTCAP_CHWIDTH40
| /* HT 40MHz channel width */
605 IEEE80211_HTCAP_GREENFIELD
| /* HT greenfield */
606 IEEE80211_HTCAP_SHORTGI20
| /* HT 20MHz short GI */
607 IEEE80211_HTCAP_SHORTGI40
| /* HT 40MHz short GI */
608 IEEE80211_HTCAP_SMPS_OFF
; /* MIMO power save disabled */
610 /* spatial streams */
612 if (sc
->nrxpath
== 2)
613 ic
->ic_htcaps
|= IEEE80211_HTCAP_RXSTBC_2STREAM
;
614 else if (sc
->nrxpath
== 3)
615 ic
->ic_htcaps
|= IEEE80211_HTCAP_RXSTBC_3STREAM
;
617 ic
->ic_htcaps
|= IEEE80211_HTCAP_RXSTBC_1STREAM
;
620 ic
->ic_htcaps
|= IEEE80211_HTCAP_TXSTBC
;
624 if (sc
->mac_rev
!= 0x28600100)
625 ic
->ic_htcaps
|= IEEE80211_HTCAP_DELBA
;
631 rt2860_init_channels(sc
);
633 rt2860_init_channels_ht40(sc
);
635 ieee80211_ifattach(ic
, sc
->mac_addr
);
637 ic
->ic_vap_create
= rt2860_vap_create
;
638 ic
->ic_vap_delete
= rt2860_vap_delete
;
640 ic
->ic_node_alloc
= rt2860_node_alloc
;
642 sc
->node_cleanup
= ic
->ic_node_cleanup
;
643 ic
->ic_node_cleanup
= rt2860_node_cleanup
;
645 ic
->ic_node_getmimoinfo
= rt2860_node_getmimoinfo
;
646 ic
->ic_setregdomain
= rt2860_setregdomain
;
647 ic
->ic_getradiocaps
= rt2860_getradiocaps
;
648 ic
->ic_scan_start
= rt2860_scan_start
;
649 ic
->ic_scan_end
= rt2860_scan_end
;
650 ic
->ic_set_channel
= rt2860_set_channel
;
651 ic
->ic_newassoc
= rt2860_newassoc
;
652 ic
->ic_updateslot
= rt2860_updateslot
;
653 ic
->ic_update_promisc
= rt2860_update_promisc
;
654 ic
->ic_update_mcast
= rt2860_update_mcast
;
655 ic
->ic_wme
.wme_update
= rt2860_wme_update
;
656 ic
->ic_raw_xmit
= rt2860_raw_xmit
;
658 sc
->recv_action
= ic
->ic_recv_action
;
659 ic
->ic_recv_action
= rt2860_recv_action
;
661 sc
->send_action
= ic
->ic_send_action
;
662 ic
->ic_send_action
= rt2860_send_action
;
664 /* hardware requires padding between 802.11 frame header and body */
666 ic
->ic_flags
|= IEEE80211_F_DATAPAD
| IEEE80211_F_DOTH
;
668 ic
->ic_flags_ext
|= IEEE80211_FEXT_SWBMISS
;
670 ieee80211_radiotap_attach(ic
,
671 &sc
->txtap
.ihdr
, sizeof(sc
->txtap
),
672 RT2860_SOFTC_TX_RADIOTAP_PRESENT
,
673 &sc
->rxtap
.ihdr
, sizeof(sc
->rxtap
),
674 RT2860_SOFTC_RX_RADIOTAP_PRESENT
);
676 /* init task queue */
678 TASK_INIT(&sc
->rx_done_task
, 0, rt2860_rx_done_task
, sc
);
679 TASK_INIT(&sc
->tx_done_task
, 0, rt2860_tx_done_task
, sc
);
680 TASK_INIT(&sc
->fifo_sta_full_task
, 0, rt2860_fifo_sta_full_task
, sc
);
681 TASK_INIT(&sc
->periodic_task
, 0, rt2860_periodic_task
, sc
);
683 sc
->rx_process_limit
= 100;
685 sc
->taskqueue
= taskqueue_create("rt2860_taskq", M_NOWAIT
,
686 taskqueue_thread_enqueue
, &sc
->taskqueue
);
688 taskqueue_start_threads(&sc
->taskqueue
, 1, PI_NET
, "%s taskq",
689 device_get_nameunit(sc
->dev
));
691 rt2860_sysctl_attach(sc
);
694 ieee80211_announce(ic
);
696 /* set up interrupt */
698 error
= bus_setup_intr(dev
, sc
->irq
, INTR_TYPE_NET
| INTR_MPSAFE
,
699 NULL
, rt2860_intr
, sc
, &sc
->irqh
);
702 printf("%s: could not set up interrupt\n",
703 device_get_nameunit(dev
));
711 /* free Tx and Rx rings */
713 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
714 rt2860_free_tx_ring(sc
, &sc
->tx_ring
[i
]);
716 rt2860_free_rx_ring(sc
, &sc
->rx_ring
);
718 mtx_destroy(&sc
->lock
);
721 bus_release_resource(dev
, SYS_RES_MEMORY
, sc
->mem_rid
, sc
->mem
);
724 bus_release_resource(dev
, SYS_RES_IRQ
, sc
->irq_rid
, sc
->irq
);
732 static int rt2860_detach(device_t dev
)
734 struct rt2860_softc
*sc
;
736 struct ieee80211com
*ic
;
739 sc
= device_get_softc(dev
);
743 RT2860_DPRINTF(sc
, RT2860_DEBUG_ANY
,
745 device_get_nameunit(sc
->dev
));
747 RT2860_SOFTC_LOCK(sc
);
749 ifp
->if_drv_flags
&= ~(IFF_DRV_RUNNING
| IFF_DRV_OACTIVE
);
751 callout_stop(&sc
->periodic_ch
);
752 callout_stop(&sc
->tx_watchdog_ch
);
754 taskqueue_drain(sc
->taskqueue
, &sc
->rx_done_task
);
755 taskqueue_drain(sc
->taskqueue
, &sc
->tx_done_task
);
756 taskqueue_drain(sc
->taskqueue
, &sc
->fifo_sta_full_task
);
757 taskqueue_drain(sc
->taskqueue
, &sc
->periodic_task
);
759 /* free Tx and Rx rings */
761 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
762 rt2860_free_tx_ring(sc
, &sc
->tx_ring
[i
]);
764 rt2860_free_rx_ring(sc
, &sc
->rx_ring
);
766 RT2860_SOFTC_UNLOCK(sc
);
768 ieee80211_ifdetach(ic
);
772 taskqueue_free(sc
->taskqueue
);
774 mtx_destroy(&sc
->lock
);
776 bus_generic_detach(dev
);
778 bus_teardown_intr(dev
, sc
->irq
, sc
->irqh
);
780 bus_release_resource(dev
, SYS_RES_IRQ
, sc
->irq_rid
, sc
->irq
);
782 bus_release_resource(dev
, SYS_RES_MEMORY
, sc
->mem_rid
, sc
->mem
);
790 static int rt2860_shutdown(device_t dev
)
792 struct rt2860_softc
*sc
;
794 sc
= device_get_softc(dev
);
796 RT2860_DPRINTF(sc
, RT2860_DEBUG_ANY
,
797 "%s: shutting down\n",
798 device_get_nameunit(sc
->dev
));
802 sc
->flags
&= ~RT2860_SOFTC_FLAGS_UCODE_LOADED
;
810 static int rt2860_suspend(device_t dev
)
812 struct rt2860_softc
*sc
;
814 sc
= device_get_softc(dev
);
816 RT2860_DPRINTF(sc
, RT2860_DEBUG_ANY
,
818 device_get_nameunit(sc
->dev
));
822 sc
->flags
&= ~RT2860_SOFTC_FLAGS_UCODE_LOADED
;
830 static int rt2860_resume(device_t dev
)
832 struct rt2860_softc
*sc
;
835 sc
= device_get_softc(dev
);
838 RT2860_DPRINTF(sc
, RT2860_DEBUG_ANY
,
840 device_get_nameunit(sc
->dev
));
842 if (ifp
->if_flags
& IFF_UP
)
849 * rt2860_init_channels
851 static void rt2860_init_channels(struct rt2860_softc
*sc
)
854 struct ieee80211com
*ic
;
855 struct ieee80211_channel
*c
;
861 /* set supported channels for 2GHz band */
863 for (i
= 1; i
<= 14; i
++)
865 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
866 flags
= IEEE80211_CHAN_B
;
868 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
872 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
873 flags
= IEEE80211_CHAN_B
| IEEE80211_CHAN_HT20
;
875 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
879 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
880 flags
= IEEE80211_CHAN_G
;
882 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
886 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
887 flags
= IEEE80211_CHAN_G
| IEEE80211_CHAN_HT20
;
889 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
894 /* set supported channels for 5GHz band */
896 if (sc
->rf_rev
== RT2860_EEPROM_RF_2850
||
897 sc
->rf_rev
== RT2860_EEPROM_RF_2750
)
899 for (i
= 36; i
<= 64; i
+= 4)
901 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
902 flags
= IEEE80211_CHAN_A
;
904 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
908 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
909 flags
= IEEE80211_CHAN_A
| IEEE80211_CHAN_HT20
;
911 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
916 for (i
= 100; i
<= 140; i
+= 4)
918 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
919 flags
= IEEE80211_CHAN_A
;
921 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
925 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
926 flags
= IEEE80211_CHAN_A
| IEEE80211_CHAN_HT20
;
928 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
933 for (i
= 149; i
<= 165; i
+= 4)
935 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
936 flags
= IEEE80211_CHAN_A
;
938 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
942 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
943 flags
= IEEE80211_CHAN_A
| IEEE80211_CHAN_HT20
;
945 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
953 * rt2860_init_channels_ht40
955 static void rt2860_init_channels_ht40(struct rt2860_softc
*sc
)
958 struct ieee80211com
*ic
;
959 struct ieee80211_channel
*c
, *cent
, *ext
;
965 /* set supported channels for 2GHz band */
967 for (i
= 1; i
<= 14; i
++)
969 flags
= IEEE80211_CHAN_G
| IEEE80211_CHAN_HT40
;
971 /* find the center channel */
973 cent
= ieee80211_find_channel_byieee(ic
, i
,
974 flags
& ~IEEE80211_CHAN_HT
);
977 printf("%s: skip channel %d, could not find center channel\n",
978 device_get_nameunit(sc
->dev
), i
);
982 /* find the extension channel */
984 ext
= ieee80211_find_channel(ic
, cent
->ic_freq
+ 20,
985 flags
& ~IEEE80211_CHAN_HT
);
988 printf("%s: skip channel %d, could not find extension channel\n",
989 device_get_nameunit(sc
->dev
), i
);
993 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
996 c
->ic_extieee
= ext
->ic_ieee
;
997 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
998 c
->ic_flags
|= IEEE80211_CHAN_HT40U
;
1000 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1003 c
->ic_extieee
= cent
->ic_ieee
;
1004 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1005 c
->ic_flags
|= IEEE80211_CHAN_HT40D
;
1008 /* set supported channels for 5GHz band */
1010 if (sc
->rf_rev
== RT2860_EEPROM_RF_2850
||
1011 sc
->rf_rev
== RT2860_EEPROM_RF_2750
)
1013 for (i
= 36; i
<= 64; i
+= 4)
1015 flags
= IEEE80211_CHAN_A
| IEEE80211_CHAN_HT40
;
1017 /* find the center channel */
1019 cent
= ieee80211_find_channel_byieee(ic
, i
,
1020 flags
& ~IEEE80211_CHAN_HT
);
1023 printf("%s: skip channel %d, could not find center channel\n",
1024 device_get_nameunit(sc
->dev
), i
);
1028 /* find the extension channel */
1030 ext
= ieee80211_find_channel(ic
, cent
->ic_freq
+ 20,
1031 flags
& ~IEEE80211_CHAN_HT
);
1034 printf("%s: skip channel %d, could not find extension channel\n",
1035 device_get_nameunit(sc
->dev
), i
);
1039 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1042 c
->ic_extieee
= ext
->ic_ieee
;
1043 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1044 c
->ic_flags
|= IEEE80211_CHAN_HT40U
;
1046 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1049 c
->ic_extieee
= cent
->ic_ieee
;
1050 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1051 c
->ic_flags
|= IEEE80211_CHAN_HT40D
;
1054 for (i
= 100; i
<= 140; i
+= 4)
1056 flags
= IEEE80211_CHAN_A
| IEEE80211_CHAN_HT40
;
1058 /* find the center channel */
1060 cent
= ieee80211_find_channel_byieee(ic
, i
,
1061 flags
& ~IEEE80211_CHAN_HT
);
1064 printf("%s: skip channel %d, could not find center channel\n",
1065 device_get_nameunit(sc
->dev
), i
);
1069 /* find the extension channel */
1071 ext
= ieee80211_find_channel(ic
, cent
->ic_freq
+ 20,
1072 flags
& ~IEEE80211_CHAN_HT
);
1075 printf("%s: skip channel %d, could not find extension channel\n",
1076 device_get_nameunit(sc
->dev
), i
);
1080 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1083 c
->ic_extieee
= ext
->ic_ieee
;
1084 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1085 c
->ic_flags
|= IEEE80211_CHAN_HT40U
;
1087 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1090 c
->ic_extieee
= cent
->ic_ieee
;
1091 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1092 c
->ic_flags
|= IEEE80211_CHAN_HT40D
;
1095 for (i
= 149; i
<= 165; i
+= 4)
1097 flags
= IEEE80211_CHAN_A
| IEEE80211_CHAN_HT40
;
1099 /* find the center channel */
1101 cent
= ieee80211_find_channel_byieee(ic
, i
,
1102 flags
& ~IEEE80211_CHAN_HT
);
1105 printf("%s: skip channel %d, could not find center channel\n",
1106 device_get_nameunit(sc
->dev
), i
);
1110 /* find the extension channel */
1112 ext
= ieee80211_find_channel(ic
, cent
->ic_freq
+ 20,
1113 flags
& ~IEEE80211_CHAN_HT
);
1116 printf("%s: skip channel %d, could not find extension channel\n",
1117 device_get_nameunit(sc
->dev
), i
);
1121 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1124 c
->ic_extieee
= ext
->ic_ieee
;
1125 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1126 c
->ic_flags
|= IEEE80211_CHAN_HT40U
;
1128 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1131 c
->ic_extieee
= cent
->ic_ieee
;
1132 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1133 c
->ic_flags
|= IEEE80211_CHAN_HT40D
;
1139 * rt2860_init_locked
1141 static void rt2860_init_locked(void *priv
)
1143 struct rt2860_softc
*sc
;
1145 struct ieee80211com
*ic
;
1146 int error
, i
, ntries
;
1147 uint32_t tmp
, stacnt
[6];
1153 RT2860_DPRINTF(sc
, RT2860_DEBUG_ANY
,
1154 "%s: initializing\n",
1155 device_get_nameunit(sc
->dev
));
1157 RT2860_SOFTC_ASSERT_LOCKED(sc
);
1159 if (!(sc
->flags
& RT2860_SOFTC_FLAGS_UCODE_LOADED
))
1161 RT2860_DPRINTF(sc
, RT2860_DEBUG_ANY
,
1162 "%s: loading 8051 microcode\n",
1163 device_get_nameunit(sc
->dev
));
1165 error
= rt2860_io_mcu_load_ucode(sc
, rt2860_ucode
, sizeof(rt2860_ucode
));
1168 printf("%s: could not load 8051 microcode\n",
1169 device_get_nameunit(sc
->dev
));
1173 RT2860_DPRINTF(sc
, RT2860_DEBUG_ANY
,
1174 "%s: 8051 microcode was successfully loaded\n",
1175 device_get_nameunit(sc
->dev
));
1177 sc
->flags
|= RT2860_SOFTC_FLAGS_UCODE_LOADED
;
1180 rt2860_io_mac_write(sc
, RT2860_REG_PWR_PIN_CFG
, 0x2);
1182 /* disable DMA engine */
1184 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
);
1187 tmp
|= RT2860_REG_TX_WB_DDONE
;
1189 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
, tmp
);
1191 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WPDMA_RST_IDX
, 0xffffffff);
1193 /* PBF hardware reset */
1195 rt2860_io_mac_write(sc
, RT2860_REG_PBF_SYS_CTRL
, 0xe1f);
1196 rt2860_io_mac_write(sc
, RT2860_REG_PBF_SYS_CTRL
, 0xe00);
1198 /* wait while DMA engine is busy */
1200 for (ntries
= 0; ntries
< 100; ntries
++)
1202 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
);
1203 if (!(tmp
& (RT2860_REG_TX_DMA_BUSY
| RT2860_REG_RX_DMA_BUSY
)))
1211 printf("%s: timeout waiting for DMA engine\n",
1212 device_get_nameunit(sc
->dev
));
1217 tmp
|= RT2860_REG_TX_WB_DDONE
;
1219 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
, tmp
);
1221 /* reset Rx and Tx rings */
1223 tmp
= RT2860_REG_RST_IDX_RX
|
1224 RT2860_REG_RST_IDX_TX_MGMT
|
1225 RT2860_REG_RST_IDX_TX_HCCA
|
1226 RT2860_REG_RST_IDX_TX_AC3
|
1227 RT2860_REG_RST_IDX_TX_AC2
|
1228 RT2860_REG_RST_IDX_TX_AC1
|
1229 RT2860_REG_RST_IDX_TX_AC0
;
1231 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WPDMA_RST_IDX
, tmp
);
1233 /* PBF hardware reset */
1235 rt2860_io_mac_write(sc
, RT2860_REG_PBF_SYS_CTRL
, 0xe1f);
1236 rt2860_io_mac_write(sc
, RT2860_REG_PBF_SYS_CTRL
, 0xe00);
1238 rt2860_io_mac_write(sc
, RT2860_REG_PWR_PIN_CFG
, 0x3);
1240 rt2860_io_mac_write(sc
, RT2860_REG_SYS_CTRL
,
1241 RT2860_REG_MAC_SRST
| RT2860_REG_BBP_HRST
);
1242 rt2860_io_mac_write(sc
, RT2860_REG_SYS_CTRL
, 0);
1244 /* init Tx power per rate */
1246 for (i
= 0; i
< RT2860_SOFTC_TXPOW_RATE_COUNT
; i
++)
1248 if (sc
->txpow_rate_20mhz
[i
] == 0xffffffff)
1251 rt2860_io_mac_write(sc
, RT2860_REG_TX_PWR_CFG(i
),
1252 sc
->txpow_rate_20mhz
[i
]);
1255 for (i
= 0; i
< RT2860_DEF_MAC_SIZE
; i
++)
1256 rt2860_io_mac_write(sc
, rt2860_def_mac
[i
].reg
,
1257 rt2860_def_mac
[i
].val
);
1259 /* wait while MAC is busy */
1261 for (ntries
= 0; ntries
< 100; ntries
++)
1263 if (!(rt2860_io_mac_read(sc
, RT2860_REG_STATUS_CFG
) &
1264 (RT2860_REG_STATUS_TX_BUSY
| RT2860_REG_STATUS_RX_BUSY
)))
1272 printf("%s: timeout waiting for MAC\n",
1273 device_get_nameunit(sc
->dev
));
1277 /* clear Host to MCU mailbox */
1279 rt2860_io_mac_write(sc
, RT2860_REG_H2M_MAILBOX_BBP_AGENT
, 0);
1280 rt2860_io_mac_write(sc
, RT2860_REG_H2M_MAILBOX
, 0);
1282 rt2860_io_mcu_cmd(sc
, RT2860_IO_MCU_CMD_BOOT
,
1283 RT2860_REG_H2M_TOKEN_NO_INTR
, 0);
1287 error
= rt2860_init_bbp(sc
);
1291 /* set up maximum buffer sizes */
1293 tmp
= (1 << 12) | RT2860_MAX_AGG_SIZE
;
1295 rt2860_io_mac_write(sc
, RT2860_REG_MAX_LEN_CFG
, tmp
);
1297 if (sc
->mac_rev
== 0x28720200)
1299 /* set max. PSDU length from 16K to 32K bytes */
1301 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_MAX_LEN_CFG
);
1306 rt2860_io_mac_write(sc
, RT2860_REG_MAX_LEN_CFG
, tmp
);
1309 if (sc
->mac_rev
>= 0x28720200 && sc
->mac_rev
< 0x30700200)
1311 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_MAX_LEN_CFG
);
1316 rt2860_io_mac_write(sc
, RT2860_REG_MAX_LEN_CFG
, tmp
);
1319 /* set mac address */
1321 rt2860_asic_set_macaddr(sc
, IF_LLADDR(ifp
));
1323 /* clear statistic registers */
1325 rt2860_io_mac_read_multi(sc
, RT2860_REG_RX_STA_CNT0
,
1326 stacnt
, sizeof(stacnt
));
1328 /* set RTS threshold */
1330 rt2860_asic_update_rtsthreshold(sc
);
1334 rt2860_asic_update_txpower(sc
);
1336 /* set up protection mode */
1338 sc
->tx_ampdu_sessions
= 0;
1340 rt2860_asic_updateprot(sc
);
1342 /* clear beacon frame space (entries = 8, entry size = 512) */
1344 rt2860_io_mac_set_region_4(sc
, RT2860_REG_BEACON_BASE(0), 0, 1024);
1346 taskqueue_unblock(sc
->taskqueue
);
1348 /* init Tx rings (4 EDCAs + HCCA + MGMT) */
1350 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
1351 rt2860_reset_tx_ring(sc
, &sc
->tx_ring
[i
]);
1353 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
1355 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_BASE_PTR(i
),
1356 sc
->tx_ring
[i
].desc_phys_addr
);
1357 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_MAX_CNT(i
),
1358 RT2860_SOFTC_TX_RING_DESC_COUNT
);
1359 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_CTX_IDX(i
), 0);
1364 rt2860_reset_rx_ring(sc
, &sc
->rx_ring
);
1366 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_BASE_PTR
,
1367 sc
->rx_ring
.desc_phys_addr
);
1368 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_MAX_CNT
,
1369 RT2860_SOFTC_RX_RING_DATA_COUNT
);
1370 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_CALC_IDX
,
1371 RT2860_SOFTC_RX_RING_DATA_COUNT
- 1);
1373 /* wait while DMA engine is busy */
1375 for (ntries
= 0; ntries
< 100; ntries
++)
1377 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
);
1378 if (!(tmp
& (RT2860_REG_TX_DMA_BUSY
| RT2860_REG_RX_DMA_BUSY
)))
1386 printf("%s: timeout waiting for DMA engine\n",
1387 device_get_nameunit(sc
->dev
));
1392 tmp
|= RT2860_REG_TX_WB_DDONE
;
1394 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
, tmp
);
1396 /* disable interrupts mitigation */
1398 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_DELAY_INT_CFG
, 0);
1400 /* send LEDs operating mode to microcontroller */
1402 rt2860_io_mcu_cmd(sc
, RT2860_IO_MCU_CMD_LED1
,
1403 RT2860_REG_H2M_TOKEN_NO_INTR
, sc
->led_off
[0]);
1404 rt2860_io_mcu_cmd(sc
, RT2860_IO_MCU_CMD_LED2
,
1405 RT2860_REG_H2M_TOKEN_NO_INTR
, sc
->led_off
[1]);
1406 rt2860_io_mcu_cmd(sc
, RT2860_IO_MCU_CMD_LED3
,
1407 RT2860_REG_H2M_TOKEN_NO_INTR
, sc
->led_off
[2]);
1409 /* turn radio LED on */
1411 rt2860_led_cmd(sc
, RT2860_LED_CMD_RADIO_ON
);
1413 /* write vendor-specific BBP values (from EEPROM) */
1415 for (i
= 0; i
< RT2860_SOFTC_BBP_EEPROM_COUNT
; i
++)
1417 if (sc
->bbp_eeprom
[i
].reg
== 0x00 ||
1418 sc
->bbp_eeprom
[i
].reg
== 0xff)
1421 rt2860_io_bbp_write(sc
, sc
->bbp_eeprom
[i
].reg
,
1422 sc
->bbp_eeprom
[i
].val
);
1426 tmp = rt2860_io_mac_read(sc, RT2860_REG_SCHDMA_GPIO_CTRL_CFG);
1429 rt2860_io_mcu_cmd(sc, RT2860_IO_MCU_CMD_SLEEP,
1430 RT2860_REG_H2M_TOKEN_RADIOOFF, 0x02ff);
1431 rt2860_io_mcu_cmd_check(sc, RT2860_REG_H2M_TOKEN_RADIOOFF);
1433 rt2860_io_mcu_cmd(sc, RT2860_IO_MCU_CMD_WAKEUP,
1434 RT2860_REG_H2M_TOKEN_WAKEUP, 0);
1435 rt2860_io_mcu_cmd_check(sc, RT2860_REG_H2M_TOKEN_WAKEUP);
1439 /* disable non-existing Rx chains */
1441 tmp
= rt2860_io_bbp_read(sc
, 3);
1443 tmp
&= ~((1 << 4) | (1 << 3));
1445 if (sc
->nrxpath
== 3)
1447 else if (sc
->nrxpath
== 2)
1450 rt2860_io_bbp_write(sc
, 3, tmp
);
1452 /* disable non-existing Tx chains */
1454 tmp
= rt2860_io_bbp_read(sc
, 1);
1456 tmp
&= ~((1 << 4) | (1 << 3));
1458 if (sc
->ntxpath
== 2)
1461 rt2860_io_bbp_write(sc
, 1, tmp
);
1463 /* set current channel */
1465 rt2860_rf_set_chan(sc
, ic
->ic_curchan
);
1467 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WMM_TXOP0_CFG
, 0);
1468 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WMM_TXOP1_CFG
,
1471 if ((sc
->mac_rev
& 0xffff) != 0x0101)
1472 rt2860_io_mac_write(sc
, RT2860_REG_TX_TXOP_CTRL_CFG
, 0x583f);
1474 /* clear pending interrupts */
1476 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_INT_STATUS
, 0xffffffff);
1478 /* enable interrupts */
1480 tmp
= RT2860_REG_INT_TX_COHERENT
|
1481 RT2860_REG_INT_RX_COHERENT
|
1482 RT2860_REG_INT_GP_TIMER
|
1483 RT2860_REG_INT_AUTO_WAKEUP
|
1484 RT2860_REG_INT_FIFO_STA_FULL
|
1486 RT2860_REG_INT_PRE_TBTT |
1487 RT2860_REG_INT_TBTT |
1489 RT2860_REG_INT_TXRX_COHERENT
|
1490 RT2860_REG_INT_MCU_CMD
|
1491 RT2860_REG_INT_TX_MGMT_DONE
|
1492 RT2860_REG_INT_TX_HCCA_DONE
|
1493 RT2860_REG_INT_TX_AC3_DONE
|
1494 RT2860_REG_INT_TX_AC2_DONE
|
1495 RT2860_REG_INT_TX_AC1_DONE
|
1496 RT2860_REG_INT_TX_AC0_DONE
|
1497 RT2860_REG_INT_RX_DONE
;
1499 sc
->intr_enable_mask
= tmp
;
1501 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_INT_MASK
, tmp
);
1503 if (rt2860_txrx_enable(sc
) != 0)
1506 /* clear garbage interrupts */
1508 tmp
= rt2860_io_mac_read(sc
, 0x1300);
1510 ifp
->if_drv_flags
&= ~IFF_DRV_OACTIVE
;
1511 ifp
->if_drv_flags
|= IFF_DRV_RUNNING
;
1513 sc
->periodic_round
= 0;
1515 callout_reset(&sc
->periodic_ch
, hz
/ 10, rt2860_periodic
, sc
);
1521 rt2860_stop_locked(sc
);
1527 static void rt2860_init(void *priv
)
1529 struct rt2860_softc
*sc
;
1533 RT2860_SOFTC_LOCK(sc
);
1535 rt2860_init_locked(sc
);
1537 RT2860_SOFTC_UNLOCK(sc
);
1543 static int rt2860_init_bbp(struct rt2860_softc
*sc
)
1548 for (ntries
= 0; ntries
< 20; ntries
++)
1550 tmp
= rt2860_io_bbp_read(sc
, 0);
1551 if (tmp
!= 0x00 && tmp
!= 0xff)
1555 if (tmp
== 0x00 || tmp
== 0xff)
1557 printf("%s: timeout waiting for BBP to wakeup\n",
1558 device_get_nameunit(sc
->dev
));
1562 for (i
= 0; i
< RT2860_DEF_BBP_SIZE
; i
++)
1563 rt2860_io_bbp_write(sc
, rt2860_def_bbp
[i
].reg
,
1564 rt2860_def_bbp
[i
].val
);
1566 if ((sc
->mac_rev
& 0xffff) != 0x0101)
1567 rt2860_io_bbp_write(sc
, 84, 0x19);
1569 if (sc
->mac_rev
== 0x28600100)
1571 rt2860_io_bbp_write(sc
, 69, 0x16);
1572 rt2860_io_bbp_write(sc
, 73, 0x12);
1579 * rt2860_stop_locked
1581 static void rt2860_stop_locked(void *priv
)
1583 struct rt2860_softc
*sc
;
1585 struct ieee80211com
*ic
;
1592 RT2860_DPRINTF(sc
, RT2860_DEBUG_ANY
,
1594 device_get_nameunit(sc
->dev
));
1596 RT2860_SOFTC_ASSERT_LOCKED(sc
);
1600 if (ifp
->if_drv_flags
& IFF_DRV_RUNNING
)
1601 rt2860_led_cmd(sc
, RT2860_LED_CMD_RADIO_OFF
);
1603 ifp
->if_drv_flags
&= ~(IFF_DRV_RUNNING
| IFF_DRV_OACTIVE
);
1605 callout_stop(&sc
->periodic_ch
);
1606 callout_stop(&sc
->tx_watchdog_ch
);
1608 RT2860_SOFTC_UNLOCK(sc
);
1610 taskqueue_block(sc
->taskqueue
);
1612 taskqueue_drain(sc
->taskqueue
, &sc
->rx_done_task
);
1613 taskqueue_drain(sc
->taskqueue
, &sc
->tx_done_task
);
1614 taskqueue_drain(sc
->taskqueue
, &sc
->fifo_sta_full_task
);
1615 taskqueue_drain(sc
->taskqueue
, &sc
->periodic_task
);
1617 RT2860_SOFTC_LOCK(sc
);
1619 /* clear key tables */
1621 rt2860_asic_clear_keytables(sc
);
1623 /* disable interrupts */
1625 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_INT_MASK
, 0);
1629 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_SYS_CTRL
);
1631 tmp
&= ~(RT2860_REG_RX_ENABLE
| RT2860_REG_TX_ENABLE
);
1633 rt2860_io_mac_write(sc
, RT2860_REG_SYS_CTRL
, tmp
);
1637 rt2860_io_mac_write(sc
, RT2860_REG_SYS_CTRL
,
1638 RT2860_REG_MAC_SRST
| RT2860_REG_BBP_HRST
);
1639 rt2860_io_mac_write(sc
, RT2860_REG_SYS_CTRL
, 0);
1645 static void rt2860_stop(void *priv
)
1647 struct rt2860_softc
*sc
;
1651 RT2860_SOFTC_LOCK(sc
);
1653 rt2860_stop_locked(sc
);
1655 RT2860_SOFTC_UNLOCK(sc
);
1661 static void rt2860_start(struct ifnet
*ifp
)
1663 struct rt2860_softc
*sc
;
1664 struct ieee80211_node
*ni
;
1670 RT2860_SOFTC_LOCK(sc
);
1672 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
1674 RT2860_SOFTC_UNLOCK(sc
);
1680 IF_POLL(&ifp
->if_snd
, m
);
1684 IFQ_DRV_DEQUEUE(&ifp
->if_snd
, m
);
1686 ni
= (struct ieee80211_node
*) m
->m_pkthdr
.rcvif
;
1688 qid
= M_WME_GETAC(m
);
1690 if (sc
->tx_ring
[qid
].data_queued
>= RT2860_SOFTC_TX_RING_DATA_COUNT
)
1692 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
1693 "%s: if_start: Tx ring with qid=%d is full\n",
1694 device_get_nameunit(sc
->dev
), qid
);
1697 ieee80211_free_node(ni
);
1699 ifp
->if_drv_flags
|= IFF_DRV_OACTIVE
;
1702 sc
->tx_data_queue_full
[qid
]++;
1707 if (rt2860_tx_data(sc
, m
, ni
, qid
) != 0)
1709 ieee80211_free_node(ni
);
1716 rt2860_drain_fifo_stats(sc
);
1718 sc
->tx_timer
= RT2860_TX_WATCHDOG_TIMEOUT
;
1720 callout_reset(&sc
->tx_watchdog_ch
, hz
, rt2860_tx_watchdog
, sc
);
1723 RT2860_SOFTC_UNLOCK(sc
);
1729 static int rt2860_ioctl(struct ifnet
*ifp
, u_long cmd
, caddr_t data
)
1731 struct rt2860_softc
*sc
;
1732 struct ieee80211com
*ic
;
1734 int error
, startall
;
1738 ifr
= (struct ifreq
*) data
;
1747 RT2860_SOFTC_LOCK(sc
);
1749 if (ifp
->if_flags
& IFF_UP
)
1751 if (ifp
->if_drv_flags
& IFF_DRV_RUNNING
)
1753 if ((ifp
->if_flags
^ sc
->if_flags
) & IFF_PROMISC
)
1754 rt2860_asic_update_promisc(sc
);
1758 rt2860_init_locked(sc
);
1764 if (ifp
->if_drv_flags
& IFF_DRV_RUNNING
)
1765 rt2860_stop_locked(sc
);
1768 sc
->if_flags
= ifp
->if_flags
;
1770 RT2860_SOFTC_UNLOCK(sc
);
1773 ieee80211_start_all(ic
);
1778 error
= ifmedia_ioctl(ifp
, ifr
, &ic
->ic_media
, cmd
);
1782 error
= ether_ioctl(ifp
, cmd
, data
);
1796 static struct ieee80211vap
*rt2860_vap_create(struct ieee80211com
*ic
,
1797 const char name
[IFNAMSIZ
], int unit
, int opmode
, int flags
,
1798 const uint8_t bssid
[IEEE80211_ADDR_LEN
],
1799 const uint8_t mac
[IEEE80211_ADDR_LEN
])
1801 struct rt2860_softc
*sc
;
1803 struct rt2860_softc_vap
*rvap
;
1804 struct ieee80211vap
*vap
;
1809 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATE
,
1810 "%s: VAP create: opmode=%s\n",
1811 device_get_nameunit(sc
->dev
),
1812 ieee80211_opmode_name
[opmode
]);
1816 case IEEE80211_M_IBSS
:
1817 case IEEE80211_M_STA
:
1818 case IEEE80211_M_AHDEMO
:
1819 case IEEE80211_M_HOSTAP
:
1820 case IEEE80211_M_MBSS
:
1821 if ((sc
->napvaps
+ sc
->nadhocvaps
+ sc
->nstavaps
) != 0)
1823 if_printf(ifp
, "only 1 VAP supported\n");
1827 if (opmode
== IEEE80211_M_STA
)
1828 flags
|= IEEE80211_CLONE_NOBEACONS
;
1831 case IEEE80211_M_WDS
:
1832 if (sc
->napvaps
== 0)
1834 if_printf(ifp
, "WDS only supported in AP mode\n");
1839 case IEEE80211_M_MONITOR
:
1843 if_printf(ifp
, "unknown opmode %d\n", opmode
);
1847 rvap
= (struct rt2860_softc_vap
*) malloc(sizeof(struct rt2860_softc_vap
),
1848 M_80211_VAP
, M_NOWAIT
| M_ZERO
);
1854 ieee80211_vap_setup(ic
, vap
, name
, unit
, opmode
, flags
, bssid
, mac
);
1856 rvap
->newstate
= vap
->iv_newstate
;
1857 vap
->iv_newstate
= rt2860_vap_newstate
;
1859 vap
->iv_reset
= rt2860_vap_reset
;
1860 vap
->iv_key_update_begin
= rt2860_vap_key_update_begin
;
1861 vap
->iv_key_update_end
= rt2860_vap_key_update_end
;
1862 vap
->iv_key_set
= rt2860_vap_key_set
;
1863 vap
->iv_key_delete
= rt2860_vap_key_delete
;
1864 vap
->iv_update_beacon
= rt2860_vap_update_beacon
;
1866 rt2860_amrr_init(&rvap
->amrr
, vap
,
1868 RT2860_AMRR_MIN_SUCCESS_THRESHOLD
,
1869 RT2860_AMRR_MAX_SUCCESS_THRESHOLD
,
1872 vap
->iv_max_aid
= RT2860_SOFTC_STAID_COUNT
;
1874 /* override default Rx A-MPDU factor */
1876 vap
->iv_ampdu_rxmax
= IEEE80211_HTCAP_MAXRXAMPDU_32K
;
1877 vap
->iv_ampdu_density
= IEEE80211_HTCAP_MPDUDENSITY_NA
;
1878 vap
->iv_ampdu_limit
= vap
->iv_ampdu_rxmax
;
1880 ieee80211_vap_attach(vap
, rt2860_media_change
, ieee80211_media_status
);
1882 switch (vap
->iv_opmode
)
1884 case IEEE80211_M_HOSTAP
:
1885 case IEEE80211_M_MBSS
:
1886 case IEEE80211_M_AHDEMO
:
1890 case IEEE80211_M_IBSS
:
1894 case IEEE80211_M_STA
:
1898 case IEEE80211_M_WDS
:
1908 if (sc
->napvaps
> 0)
1909 ic
->ic_opmode
= IEEE80211_M_HOSTAP
;
1910 else if (sc
->nadhocvaps
> 0)
1911 ic
->ic_opmode
= IEEE80211_M_IBSS
;
1912 else if (sc
->nstavaps
> 0)
1913 ic
->ic_opmode
= IEEE80211_M_STA
;
1915 ic
->ic_opmode
= opmode
;
1923 static void rt2860_vap_delete(struct ieee80211vap
*vap
)
1925 struct rt2860_softc
*sc
;
1926 struct ieee80211com
*ic
;
1928 struct rt2860_softc_vap
*rvap
;
1929 enum ieee80211_opmode opmode
;
1934 rvap
= (struct rt2860_softc_vap
*) vap
;
1935 opmode
= vap
->iv_opmode
;
1937 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATE
,
1938 "%s: VAP delete: opmode=%s\n",
1939 device_get_nameunit(sc
->dev
), ieee80211_opmode_name
[opmode
]);
1941 rt2860_amrr_cleanup(&rvap
->amrr
);
1943 ieee80211_vap_detach(vap
);
1945 if (rvap
->beacon_mbuf
!= NULL
)
1947 m_free(rvap
->beacon_mbuf
);
1948 rvap
->beacon_mbuf
= NULL
;
1953 case IEEE80211_M_HOSTAP
:
1954 case IEEE80211_M_MBSS
:
1955 case IEEE80211_M_AHDEMO
:
1959 case IEEE80211_M_IBSS
:
1963 case IEEE80211_M_STA
:
1967 case IEEE80211_M_WDS
:
1977 if (sc
->napvaps
> 0)
1978 ic
->ic_opmode
= IEEE80211_M_HOSTAP
;
1979 else if (sc
->nadhocvaps
> 0)
1980 ic
->ic_opmode
= IEEE80211_M_IBSS
;
1981 else if (sc
->nstavaps
> 0)
1982 ic
->ic_opmode
= IEEE80211_M_STA
;
1984 free(rvap
, M_80211_VAP
);
1990 static int rt2860_vap_reset(struct ieee80211vap
*vap
, u_long cmd
)
1992 struct rt2860_softc
*sc
;
1993 struct ieee80211com
*ic
;
1995 struct rt2860_softc_vap
*rvap
;
2001 rvap
= (struct rt2860_softc_vap
*) vap
;
2003 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATE
,
2004 "%s: VAP reset: cmd=%lu\n",
2005 device_get_nameunit(sc
->dev
), cmd
);
2011 case IEEE80211_IOC_RTSTHRESHOLD
:
2012 case IEEE80211_IOC_AMSDU
:
2013 rt2860_asic_update_rtsthreshold(sc
);
2016 case IEEE80211_IOC_PROTMODE
:
2017 case IEEE80211_IOC_HTPROTMODE
:
2018 rt2860_asic_updateprot(sc
);
2021 case IEEE80211_IOC_TXPOWER
:
2022 rt2860_asic_update_txpower(sc
);
2025 case IEEE80211_IOC_BURST
:
2026 rt2860_asic_updateslot(sc
);
2029 case IEEE80211_IOC_SHORTGI
:
2030 case IEEE80211_IOC_AMPDU_DENSITY
:
2031 case IEEE80211_IOC_SMPS
:
2043 * rt2860_vap_newstate
2045 static int rt2860_vap_newstate(struct ieee80211vap
*vap
,
2046 enum ieee80211_state nstate
, int arg
)
2048 struct rt2860_softc
*sc
;
2049 struct ieee80211com
*ic
;
2051 struct rt2860_softc_vap
*rvap
;
2052 struct ieee80211_node
*ni
;
2053 enum ieee80211_state ostate
;
2059 rvap
= (struct rt2860_softc_vap
*) vap
;
2061 ostate
= vap
->iv_state
;
2063 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATE
,
2064 "%s: VAP newstate: %s -> %s\n",
2065 device_get_nameunit(sc
->dev
),
2066 ieee80211_state_name
[ostate
], ieee80211_state_name
[nstate
]);
2068 error
= rvap
->newstate(vap
, nstate
, arg
);
2072 IEEE80211_UNLOCK(ic
);
2074 RT2860_SOFTC_LOCK(sc
);
2076 /* turn link LED off */
2078 if (nstate
!= IEEE80211_S_RUN
)
2079 rt2860_led_cmd(sc
, RT2860_LED_CMD_RADIO_OFF
);
2083 case IEEE80211_S_INIT
:
2084 rt2860_asic_disable_tsf_sync(sc
);
2087 case IEEE80211_S_RUN
:
2090 rt2860_rf_set_chan(sc
, ni
->ni_chan
);
2092 if (vap
->iv_opmode
!= IEEE80211_M_MONITOR
)
2094 rt2860_asic_enable_mrr(sc
);
2095 rt2860_asic_set_txpreamble(sc
);
2096 rt2860_asic_set_basicrates(sc
);
2097 rt2860_asic_update_txpower(sc
);
2098 rt2860_asic_set_bssid(sc
, ni
->ni_bssid
);
2101 if (vap
->iv_opmode
== IEEE80211_M_HOSTAP
||
2102 vap
->iv_opmode
== IEEE80211_M_IBSS
||
2103 vap
->iv_opmode
== IEEE80211_M_MBSS
)
2105 error
= rt2860_beacon_alloc(sc
, vap
);
2109 rt2860_asic_update_beacon(sc
, vap
);
2112 if (vap
->iv_opmode
!= IEEE80211_M_MONITOR
)
2113 rt2860_asic_enable_tsf_sync(sc
);
2115 /* turn link LED on */
2117 if (vap
->iv_opmode
!= IEEE80211_M_MONITOR
)
2119 rt2860_led_cmd(sc
, RT2860_LED_CMD_RADIO_ON
|
2120 (IEEE80211_IS_CHAN_2GHZ(ni
->ni_chan
) ?
2121 RT2860_LED_CMD_LINK_2GHZ
: RT2860_LED_CMD_LINK_5GHZ
));
2125 case IEEE80211_S_SLEEP
:
2132 RT2860_SOFTC_UNLOCK(sc
);
2140 * rt2860_vap_key_update_begin
2142 static void rt2860_vap_key_update_begin(struct ieee80211vap
*vap
)
2144 struct rt2860_softc
*sc
;
2145 struct ieee80211com
*ic
;
2152 RT2860_DPRINTF(sc
, RT2860_DEBUG_KEY
,
2153 "%s: VAP key update begin\n",
2154 device_get_nameunit(sc
->dev
));
2156 taskqueue_block(sc
->taskqueue
);
2158 IF_LOCK(&ifp
->if_snd
);
2162 * rt2860_vap_key_update_end
2164 static void rt2860_vap_key_update_end(struct ieee80211vap
*vap
)
2166 struct rt2860_softc
*sc
;
2167 struct ieee80211com
*ic
;
2174 RT2860_DPRINTF(sc
, RT2860_DEBUG_KEY
,
2175 "%s: VAP key update end\n",
2176 device_get_nameunit(sc
->dev
));
2178 IF_UNLOCK(&ifp
->if_snd
);
2180 taskqueue_unblock(sc
->taskqueue
);
2184 * rt2860_vap_key_set
2186 static int rt2860_vap_key_set(struct ieee80211vap
*vap
,
2187 const struct ieee80211_key
*k
, const uint8_t mac
[IEEE80211_ADDR_LEN
])
2189 struct rt2860_softc
*sc
;
2190 struct ieee80211com
*ic
;
2192 struct ieee80211_node
*ni
;
2193 struct rt2860_softc_node
*rni
;
2194 uint16_t key_base
, keymode_base
;
2195 uint8_t mode
, vapid
, wcid
, iv
[8];
2198 if (k
->wk_cipher
->ic_cipher
!= IEEE80211_CIPHER_WEP
&&
2199 k
->wk_cipher
->ic_cipher
!= IEEE80211_CIPHER_TKIP
&&
2200 k
->wk_cipher
->ic_cipher
!= IEEE80211_CIPHER_AES_CCM
)
2207 switch (k
->wk_cipher
->ic_cipher
)
2209 case IEEE80211_CIPHER_WEP
:
2210 if(k
->wk_keylen
< 8)
2211 mode
= RT2860_REG_CIPHER_MODE_WEP40
;
2213 mode
= RT2860_REG_CIPHER_MODE_WEP104
;
2216 case IEEE80211_CIPHER_TKIP
:
2217 mode
= RT2860_REG_CIPHER_MODE_TKIP
;
2220 case IEEE80211_CIPHER_AES_CCM
:
2221 mode
= RT2860_REG_CIPHER_MODE_AES_CCMP
;
2228 RT2860_DPRINTF(sc
, RT2860_DEBUG_KEY
,
2229 "%s: VAP key set: keyix=%d, keylen=%d, macaddr=%s, mode=%d, group=%d\n",
2230 device_get_nameunit(sc
->dev
), k
->wk_keyix
, k
->wk_keylen
, ether_sprintf(k
->wk_macaddr
),
2231 mode
, (k
->wk_flags
& IEEE80211_KEY_GROUP
) ? 1 : 0);
2233 if (!(k
->wk_flags
& IEEE80211_KEY_GROUP
))
2235 /* install pairwise key */
2237 ni
= ieee80211_find_vap_node(&ic
->ic_sta
, vap
, mac
);
2238 rni
= (struct rt2860_softc_node
*) ni
;
2242 key_base
= RT2860_REG_PKEY(wcid
);
2244 ieee80211_free_node(ni
);
2246 if (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_WEP
)
2250 iv
[3] = (k
->wk_keyix
<< 6);
2254 if (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_TKIP
)
2256 iv
[0] = (k
->wk_keytsc
>> 8);
2257 iv
[1] = ((iv
[0] | 0x20) & 0x7f);
2258 iv
[2] = k
->wk_keytsc
;
2264 iv
[0] = k
->wk_keytsc
;
2265 iv
[1] = k
->wk_keytsc
>> 8;
2269 iv
[3] = ((k
->wk_keyix
<< 6) | IEEE80211_WEP_EXTIV
);
2270 iv
[4] = (k
->wk_keytsc
>> 16);
2271 iv
[5] = (k
->wk_keytsc
>> 24);
2272 iv
[6] = (k
->wk_keytsc
>> 32);
2273 iv
[7] = (k
->wk_keytsc
>> 40);
2275 RT2860_DPRINTF(sc
, RT2860_DEBUG_KEY
,
2276 "%s: VAP key set: iv=%02x %02x %02x %02x %02x %02x %02x %02x\n",
2277 device_get_nameunit(sc
->dev
),
2278 iv
[0], iv
[1], iv
[2], iv
[3], iv
[4], iv
[5], iv
[6], iv
[7]);
2281 rt2860_io_mac_write_multi(sc
, RT2860_REG_IVEIV(wcid
), iv
, 8);
2283 if (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_TKIP
)
2285 rt2860_io_mac_write_multi(sc
, key_base
, k
->wk_key
, 16);
2287 if (vap
->iv_opmode
!= IEEE80211_M_HOSTAP
)
2289 rt2860_io_mac_write_multi(sc
, key_base
+ 16, &k
->wk_key
[16], 8);
2290 rt2860_io_mac_write_multi(sc
, key_base
+ 24, &k
->wk_key
[24], 8);
2294 rt2860_io_mac_write_multi(sc
, key_base
+ 16, &k
->wk_key
[24], 8);
2295 rt2860_io_mac_write_multi(sc
, key_base
+ 24, &k
->wk_key
[16], 8);
2300 rt2860_io_mac_write_multi(sc
, key_base
, k
->wk_key
, k
->wk_keylen
);
2303 tmp
= ((vapid
& RT2860_REG_VAP_MASK
) << RT2860_REG_VAP_SHIFT
) |
2304 (mode
<< RT2860_REG_CIPHER_MODE_SHIFT
) | RT2860_REG_PKEY_ENABLE
;
2306 rt2860_io_mac_write(sc
, RT2860_REG_WCID_ATTR(wcid
), tmp
);
2309 if ((k
->wk_flags
& IEEE80211_KEY_GROUP
) ||
2310 (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_WEP
))
2312 /* install group key */
2315 wcid
= RT2860_WCID_MCAST
;
2316 key_base
= RT2860_REG_SKEY(vapid
, k
->wk_keyix
);
2317 keymode_base
= RT2860_REG_SKEY_MODE(vapid
);
2319 if (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_TKIP
)
2321 rt2860_io_mac_write_multi(sc
, key_base
, k
->wk_key
, 16);
2323 if (vap
->iv_opmode
!= IEEE80211_M_HOSTAP
)
2325 rt2860_io_mac_write_multi(sc
, key_base
+ 16, &k
->wk_key
[16], 8);
2326 rt2860_io_mac_write_multi(sc
, key_base
+ 24, &k
->wk_key
[24], 8);
2330 rt2860_io_mac_write_multi(sc
, key_base
+ 16, &k
->wk_key
[24], 8);
2331 rt2860_io_mac_write_multi(sc
, key_base
+ 24, &k
->wk_key
[16], 8);
2336 rt2860_io_mac_write_multi(sc
, key_base
, k
->wk_key
, k
->wk_keylen
);
2339 tmp
= rt2860_io_mac_read(sc
, keymode_base
);
2341 tmp
&= ~(0xf << (k
->wk_keyix
* 4 + 16 * (vapid
% 2)));
2342 tmp
|= (mode
<< (k
->wk_keyix
* 4 + 16 * (vapid
% 2)));
2344 rt2860_io_mac_write(sc
, keymode_base
, tmp
);
2346 if (vap
->iv_opmode
== IEEE80211_M_HOSTAP
)
2348 if (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_WEP
)
2352 iv
[3] = (k
->wk_keyix
<< 6);
2356 if (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_TKIP
)
2358 iv
[0] = (k
->wk_keytsc
>> 8);
2359 iv
[1] = ((iv
[0] | 0x20) & 0x7f);
2360 iv
[2] = k
->wk_keytsc
;
2366 iv
[0] = k
->wk_keytsc
;
2367 iv
[1] = k
->wk_keytsc
>> 8;
2371 iv
[3] = ((k
->wk_keyix
<< 6) | IEEE80211_WEP_EXTIV
);
2372 iv
[4] = (k
->wk_keytsc
>> 16);
2373 iv
[5] = (k
->wk_keytsc
>> 24);
2374 iv
[6] = (k
->wk_keytsc
>> 32);
2375 iv
[7] = (k
->wk_keytsc
>> 40);
2377 RT2860_DPRINTF(sc
, RT2860_DEBUG_KEY
,
2378 "%s: VAP key set: iv=%02x %02x %02x %02x %02x %02x %02x %02x\n",
2379 device_get_nameunit(sc
->dev
),
2380 iv
[0], iv
[1], iv
[2], iv
[3], iv
[4], iv
[5], iv
[6], iv
[7]);
2383 rt2860_io_mac_write_multi(sc
, RT2860_REG_IVEIV(wcid
), iv
, 8);
2385 tmp
= ((vapid
& RT2860_REG_VAP_MASK
) << RT2860_REG_VAP_SHIFT
) |
2386 (mode
<< RT2860_REG_CIPHER_MODE_SHIFT
);
2388 rt2860_io_mac_write(sc
, RT2860_REG_WCID_ATTR(wcid
), tmp
);
2396 * rt2860_vap_key_delete
2398 static int rt2860_vap_key_delete(struct ieee80211vap
*vap
,
2399 const struct ieee80211_key
*k
)
2401 struct rt2860_softc
*sc
;
2402 struct ieee80211com
*ic
;
2404 uint8_t vapid
, wcid
;
2411 RT2860_DPRINTF(sc
, RT2860_DEBUG_KEY
,
2412 "%s: VAP key delete: keyix=%d, keylen=%d, macaddr=%s, group=%d\n",
2413 device_get_nameunit(sc
->dev
), k
->wk_keyix
, k
->wk_keylen
, ether_sprintf(k
->wk_macaddr
),
2414 (k
->wk_flags
& IEEE80211_KEY_GROUP
) ? 1 : 0);
2416 if (k
->wk_flags
& IEEE80211_KEY_GROUP
)
2418 /* remove group key */
2421 wcid
= RT2860_WCID_MCAST
;
2423 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_SKEY_MODE(vapid
));
2425 tmp
&= ~(0xf << (k
->wk_keyix
* 4 + 16 * (vapid
% 2)));
2426 tmp
|= (RT2860_REG_CIPHER_MODE_NONE
<< (k
->wk_keyix
* 4 + 16 * (vapid
% 2)));
2428 rt2860_io_mac_write(sc
, RT2860_REG_SKEY_MODE(vapid
), tmp
);
2430 if (vap
->iv_opmode
== IEEE80211_M_HOSTAP
)
2432 tmp
= ((vapid
& RT2860_REG_VAP_MASK
) << RT2860_REG_VAP_SHIFT
) |
2433 (RT2860_REG_CIPHER_MODE_NONE
<< RT2860_REG_CIPHER_MODE_SHIFT
) | RT2860_REG_PKEY_ENABLE
;
2435 rt2860_io_mac_write(sc
, RT2860_REG_WCID_ATTR(wcid
), tmp
);
2443 * rt2860_vap_update_beacon
2445 static void rt2860_vap_update_beacon(struct ieee80211vap
*vap
, int what
)
2447 struct rt2860_softc
*sc
;
2448 struct ieee80211com
*ic
;
2450 struct rt2860_softc_vap
*rvap
;
2452 struct ieee80211_beacon_offsets
*bo
;
2457 rvap
= (struct rt2860_softc_vap
*) vap
;
2458 m
= rvap
->beacon_mbuf
;
2459 bo
= &rvap
->beacon_offsets
;
2461 RT2860_DPRINTF(sc
, RT2860_DEBUG_BEACON
,
2462 "%s: VAP update beacon: what=%d\n",
2463 device_get_nameunit(sc
->dev
), what
);
2465 setbit(bo
->bo_flags
, what
);
2467 ieee80211_beacon_update(vap
->iv_bss
, bo
, m
, 0);
2469 rt2860_asic_update_beacon(sc
, vap
);
2473 * rt2860_media_change
2475 static int rt2860_media_change(struct ifnet
*ifp
)
2479 error
= ieee80211_media_change(ifp
);
2481 return (error
== ENETRESET
? 0 : error
);
2487 static struct ieee80211_node
*rt2860_node_alloc(struct ieee80211vap
*vap
,
2488 const uint8_t mac
[IEEE80211_ADDR_LEN
])
2490 return malloc(sizeof(struct rt2860_softc_node
),
2491 M_80211_NODE
, M_NOWAIT
| M_ZERO
);
2495 * rt2860_node_cleanup
2497 static void rt2860_node_cleanup(struct ieee80211_node
*ni
)
2499 struct rt2860_softc
*sc
;
2500 struct ieee80211com
*ic
;
2502 struct rt2860_softc_node
*rni
;
2503 uint8_t vapid
, wcid
;
2509 rni
= (struct rt2860_softc_node
*) ni
;
2511 RT2860_DPRINTF(sc
, RT2860_DEBUG_NODE
,
2512 "%s: node cleanup: macaddr=%s, associd=0x%04x, staid=0x%02x\n",
2513 device_get_nameunit(sc
->dev
), ether_sprintf(ni
->ni_macaddr
),
2514 ni
->ni_associd
, rni
->staid
);
2516 if (rni
->staid
!= 0)
2521 tmp
= ((vapid
& RT2860_REG_VAP_MASK
) << RT2860_REG_VAP_SHIFT
) |
2522 (RT2860_REG_CIPHER_MODE_NONE
<< RT2860_REG_CIPHER_MODE_SHIFT
) | RT2860_REG_PKEY_ENABLE
;
2524 rt2860_io_mac_write(sc
, RT2860_REG_WCID_ATTR(wcid
), tmp
);
2526 rt2860_staid_delete(sc
, rni
->staid
);
2531 sc
->node_cleanup(ni
);
2535 * rt2860_node_getmimoinfo
2537 static void rt2860_node_getmimoinfo(const struct ieee80211_node
*ni
,
2538 struct ieee80211_mimo_info
*mi
)
2540 const struct rt2860_softc_node
*rni
;
2543 rni
= (const struct rt2860_softc_node
*) ni
;
2545 for (i
= 0; i
< RT2860_SOFTC_RSSI_COUNT
; i
++)
2547 mi
->rssi
[i
] = rni
->last_rssi_dbm
[i
];
2548 mi
->noise
[i
] = RT2860_NOISE_FLOOR
;
2553 * rt2860_setregdomain
2555 static int rt2860_setregdomain(struct ieee80211com
*ic
,
2556 struct ieee80211_regdomain
*reg
,
2557 int nchans
, struct ieee80211_channel chans
[])
2559 struct rt2860_softc
*sc
;
2565 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATE
,
2566 "%s: set regulatory domain: country=%d, country code string=%c%c, location=%c\n",
2567 device_get_nameunit(sc
->dev
),
2568 reg
->country
, reg
->isocc
[0], reg
->isocc
[1], reg
->location
);
2574 * rt2860_getradiocaps
2576 static void rt2860_getradiocaps(struct ieee80211com
*ic
,
2577 int maxchans
, int *nchans
, struct ieee80211_channel chans
[])
2579 *nchans
= (ic
->ic_nchans
>= maxchans
) ? maxchans
: ic
->ic_nchans
;
2581 memcpy(chans
, ic
->ic_channels
, (*nchans
) * sizeof(struct ieee80211_channel
));
2587 static void rt2860_scan_start(struct ieee80211com
*ic
)
2589 struct rt2860_softc
*sc
;
2595 rt2860_asic_disable_tsf_sync(sc
);
2601 static void rt2860_scan_end(struct ieee80211com
*ic
)
2603 struct rt2860_softc
*sc
;
2609 rt2860_asic_enable_tsf_sync(sc
);
2613 * rt2860_set_channel
2615 static void rt2860_set_channel(struct ieee80211com
*ic
)
2617 struct rt2860_softc
*sc
;
2623 RT2860_DPRINTF(sc
, RT2860_DEBUG_CHAN
,
2624 "%s: set channel: channel=%u, HT%s%s\n",
2625 device_get_nameunit(sc
->dev
),
2626 ieee80211_chan2ieee(ic
, ic
->ic_curchan
),
2627 !IEEE80211_IS_CHAN_HT(ic
->ic_curchan
) ? " disabled" :
2628 IEEE80211_IS_CHAN_HT20(ic
->ic_curchan
) ? "20":
2629 IEEE80211_IS_CHAN_HT40U(ic
->ic_curchan
) ? "40U" : "40D",
2630 (ic
->ic_flags
& IEEE80211_F_SCAN
) ? ", scanning" : "");
2632 RT2860_SOFTC_LOCK(sc
);
2634 rt2860_rf_set_chan(sc
, ic
->ic_curchan
);
2636 RT2860_SOFTC_UNLOCK(sc
);
2642 static void rt2860_newassoc(struct ieee80211_node
*ni
, int isnew
)
2644 struct rt2860_softc
*sc
;
2645 struct ieee80211com
*ic
;
2647 struct ieee80211vap
*vap
;
2648 struct rt2860_softc_vap
*rvap
;
2649 struct rt2860_softc_node
*rni
;
2657 rvap
= (struct rt2860_softc_vap
*) vap
;
2658 rni
= (struct rt2860_softc_node
*) ni
;
2662 aid
= IEEE80211_AID(ni
->ni_associd
);
2663 rni
->staid
= rt2860_staid_alloc(sc
, aid
);
2666 rt2860_io_mac_write_multi(sc
, RT2860_REG_WCID(wcid
),
2667 ni
->ni_macaddr
, IEEE80211_ADDR_LEN
);
2669 rt2860_amrr_node_init(&rvap
->amrr
, &sc
->amrr_node
[wcid
], ni
);
2671 RT2860_DPRINTF(sc
, RT2860_DEBUG_RATE
,
2672 "%s: initial%s node Tx rate: associd=0x%04x, rate=0x%02x, max rate=0x%02x\n",
2673 device_get_nameunit(sc
->dev
),
2674 (ni
->ni_flags
& IEEE80211_NODE_HT
) ? " HT" : "",
2675 ni
->ni_associd
, ni
->ni_txrate
,
2676 (ni
->ni_flags
& IEEE80211_NODE_HT
) ?
2677 (ni
->ni_htrates
.rs_rates
[ni
->ni_htrates
.rs_nrates
- 1] | IEEE80211_RATE_MCS
) :
2678 (ni
->ni_rates
.rs_rates
[ni
->ni_rates
.rs_nrates
- 1] & IEEE80211_RATE_VAL
));
2680 rt2860_asic_updateprot(sc
);
2681 rt2860_asic_updateslot(sc
);
2682 rt2860_asic_set_txpreamble(sc
);
2685 RT2860_DPRINTF(sc
, RT2860_DEBUG_NODE
,
2686 "%s: new association: isnew=%d, macaddr=%s, associd=0x%04x, staid=0x%02x, QoS %s, ERP %s, HT %s\n",
2687 device_get_nameunit(sc
->dev
), isnew
, ether_sprintf(ni
->ni_macaddr
),
2688 ni
->ni_associd
, rni
->staid
,
2689 (ni
->ni_flags
& IEEE80211_NODE_QOS
) ? "enabled" : "disabled",
2690 (ni
->ni_flags
& IEEE80211_NODE_ERP
) ? "enabled" : "disabled",
2691 (ni
->ni_flags
& IEEE80211_NODE_HT
) ? "enabled" : "disabled");
2697 static void rt2860_updateslot(struct ifnet
*ifp
)
2699 struct rt2860_softc
*sc
;
2703 rt2860_asic_updateslot(sc
);
2707 * rt2860_update_promisc
2709 static void rt2860_update_promisc(struct ifnet
*ifp
)
2711 struct rt2860_softc
*sc
;
2715 rt2860_asic_update_promisc(sc
);
2719 * rt2860_update_mcast
2721 static void rt2860_update_mcast(struct ifnet
*ifp
)
2723 struct rt2860_softc
*sc
;
2731 static int rt2860_wme_update(struct ieee80211com
*ic
)
2733 struct rt2860_softc
*sc
;
2739 rt2860_asic_wme_update(sc
);
2747 static int rt2860_raw_xmit(struct ieee80211_node
*ni
, struct mbuf
*m
,
2748 const struct ieee80211_bpf_params
*params
)
2750 struct rt2860_softc
*sc
;
2751 struct ieee80211com
*ic
;
2758 RT2860_SOFTC_LOCK(sc
);
2760 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
2762 RT2860_SOFTC_UNLOCK(sc
);
2765 ieee80211_free_node(ni
);
2770 if (sc
->tx_ring
[sc
->tx_ring_mgtqid
].data_queued
>= RT2860_SOFTC_TX_RING_DATA_COUNT
)
2772 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
2773 "%s: raw xmit: Tx ring with qid=%d is full\n",
2774 device_get_nameunit(sc
->dev
), sc
->tx_ring_mgtqid
);
2776 ifp
->if_drv_flags
|= IFF_DRV_OACTIVE
;
2778 RT2860_SOFTC_UNLOCK(sc
);
2781 ieee80211_free_node(ni
);
2783 sc
->tx_data_queue_full
[sc
->tx_ring_mgtqid
]++;
2788 if (rt2860_tx_mgmt(sc
, m
, ni
, sc
->tx_ring_mgtqid
) != 0)
2792 RT2860_SOFTC_UNLOCK(sc
);
2794 ieee80211_free_node(ni
);
2799 sc
->tx_timer
= RT2860_TX_WATCHDOG_TIMEOUT
;
2801 RT2860_SOFTC_UNLOCK(sc
);
2807 * rt2860_recv_action
2809 static int rt2860_recv_action(struct ieee80211_node
*ni
,
2810 const struct ieee80211_frame
*wh
,
2811 const uint8_t *frm
, const uint8_t *efrm
)
2813 struct rt2860_softc
*sc
;
2814 struct ieee80211com
*ic
;
2816 struct rt2860_softc_node
*rni
;
2817 const struct ieee80211_action
*ia
;
2818 struct ieee80211_tx_ampdu
*tx_ampdu
;
2819 uint16_t status
, baparamset
;
2821 int ret
, tid
, bufsize
, ac
;
2827 rni
= (struct rt2860_softc_node
*) ni
;
2829 ia
= (const struct ieee80211_action
*) frm
;
2831 ret
= sc
->recv_action(ni
, wh
, frm
, efrm
);
2833 if (ia
->ia_category
!= IEEE80211_ACTION_CAT_BA
)
2838 switch (ia
->ia_action
)
2840 /* IEEE80211_ACTION_BA_ADDBA_REQUEST */
2841 case IEEE80211_ACTION_BA_ADDBA_REQUEST
:
2842 baparamset
= LE_READ_2(frm
+ 3);
2843 tid
= RT2860_MS(baparamset
, IEEE80211_BAPS_TID
);
2844 bufsize
= RT2860_MS(baparamset
, IEEE80211_BAPS_BUFSIZ
);
2846 RT2860_DPRINTF(sc
, RT2860_DEBUG_BA
,
2847 "%s: received ADDBA request: associd=0x%04x, tid=%d, bufsize=%d\n",
2848 device_get_nameunit(sc
->dev
), ni
->ni_associd
, tid
, bufsize
);
2850 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_WCID(wcid
) + 4);
2852 tmp
|= (0x10000 << tid
);
2854 rt2860_io_mac_write(sc
, RT2860_REG_WCID(wcid
) + 4, tmp
);
2857 /* IEEE80211_ACTION_BA_ADDBA_RESPONSE */
2858 case IEEE80211_ACTION_BA_ADDBA_RESPONSE
:
2859 status
= LE_READ_2(frm
+ 3);
2860 baparamset
= LE_READ_2(frm
+ 4);
2861 tid
= RT2860_MS(baparamset
, IEEE80211_BAPS_TID
);
2862 bufsize
= RT2860_MS(baparamset
, IEEE80211_BAPS_BUFSIZ
);
2863 ac
= TID_TO_WME_AC(tid
);
2864 tx_ampdu
= &ni
->ni_tx_ampdu
[ac
];
2866 RT2860_DPRINTF(sc
, RT2860_DEBUG_BA
,
2867 "%s: received ADDBA response: associd=0x%04x, status=%d, tid=%d, bufsize=%d\n",
2868 device_get_nameunit(sc
->dev
), ni
->ni_associd
, status
, tid
, bufsize
);
2870 if (sc
->mac_rev
>= 0x28720200)
2872 if (tx_ampdu
->txa_wnd
> 13)
2873 tx_ampdu
->txa_wnd
= 13;
2877 if (tx_ampdu
->txa_wnd
> 7)
2878 tx_ampdu
->txa_wnd
= 7;
2881 if (status
== IEEE80211_STATUS_SUCCESS
)
2883 sc
->tx_ampdu_sessions
++;
2885 rt2860_asic_updateprot(sc
);
2889 /* IEEE80211_ACTION_BA_DELBA */
2890 case IEEE80211_ACTION_BA_DELBA
:
2891 baparamset
= LE_READ_2(frm
+ 2);
2892 tid
= RT2860_MS(baparamset
, IEEE80211_BAPS_TID
);
2894 RT2860_DPRINTF(sc
, RT2860_DEBUG_BA
,
2895 "%s: received DELBA request: associd=0x%04x, tid=%d\n",
2896 device_get_nameunit(sc
->dev
), ni
->ni_associd
, tid
);
2898 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_WCID(wcid
) + 4);
2900 tmp
&= ~(0x10000 << tid
);
2902 rt2860_io_mac_write(sc
, RT2860_REG_WCID(wcid
) + 4, tmp
);
2910 * rt2860_send_action
2912 static int rt2860_send_action(struct ieee80211_node
*ni
,
2913 int cat
, int act
, void *sa
)
2915 struct rt2860_softc
*sc
;
2916 struct ieee80211com
*ic
;
2918 struct rt2860_softc_node
*rni
;
2919 uint16_t *args
, baparamset
;
2927 rni
= (struct rt2860_softc_node
*) ni
;
2929 ret
= sc
->send_action(ni
, cat
, act
, sa
);
2931 if (cat
!= IEEE80211_ACTION_CAT_BA
)
2939 /* IEEE80211_ACTION_BA_DELBA */
2940 case IEEE80211_ACTION_BA_DELBA
:
2941 baparamset
= RT2860_SM(args
[0], IEEE80211_DELBAPS_TID
) | args
[1];
2943 tid
= RT2860_MS(baparamset
, IEEE80211_DELBAPS_TID
);
2945 RT2860_DPRINTF(sc
, RT2860_DEBUG_BA
,
2946 "%s: sending DELBA request: associd=0x%04x, tid=%d\n",
2947 device_get_nameunit(sc
->dev
), ni
->ni_associd
, tid
);
2949 if (RT2860_MS(baparamset
, IEEE80211_DELBAPS_INIT
) != IEEE80211_DELBAPS_INIT
)
2951 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_WCID(wcid
) + 4);
2953 tmp
&= ~(0x10000 << tid
);
2955 rt2860_io_mac_write(sc
, RT2860_REG_WCID(wcid
) + 4, tmp
);
2959 sc
->tx_ampdu_sessions
--;
2961 rt2860_asic_updateprot(sc
);
2970 * rt2860_amrr_update_iter_func
2972 static void rt2860_amrr_update_iter_func(void *arg
, struct ieee80211_node
*ni
)
2974 struct rt2860_softc
*sc
;
2975 struct ieee80211com
*ic
;
2977 struct ieee80211vap
*vap
;
2978 struct rt2860_softc_vap
*rvap
;
2979 struct rt2860_softc_node
*rni
;
2986 rvap
= (struct rt2860_softc_vap
*) vap
;
2987 rni
= (struct rt2860_softc_node
*) ni
;
2989 /* only associated stations */
2991 if ((ni
->ni_vap
== vap
) && (rni
->staid
!= 0))
2995 RT2860_DPRINTF(sc
, RT2860_DEBUG_RATE
,
2996 "%s: AMRR node: staid=0x%02x, txcnt=%d, success=%d, retrycnt=%d\n",
2997 device_get_nameunit(sc
->dev
),
2998 rni
->staid
, sc
->amrr_node
[wcid
].txcnt
, sc
->amrr_node
[wcid
].success
, sc
->amrr_node
[wcid
].retrycnt
);
3000 rt2860_amrr_choose(ni
, &sc
->amrr_node
[wcid
]);
3002 RT2860_DPRINTF(sc
, RT2860_DEBUG_RATE
,
3003 "%s:%s node Tx rate: associd=0x%04x, staid=0x%02x, rate=0x%02x, max rate=0x%02x\n",
3004 device_get_nameunit(sc
->dev
),
3005 (ni
->ni_flags
& IEEE80211_NODE_HT
) ? " HT" : "",
3006 ni
->ni_associd
, rni
->staid
, ni
->ni_txrate
,
3007 (ni
->ni_flags
& IEEE80211_NODE_HT
) ?
3008 (ni
->ni_htrates
.rs_rates
[ni
->ni_htrates
.rs_nrates
- 1] | IEEE80211_RATE_MCS
) :
3009 (ni
->ni_rates
.rs_rates
[ni
->ni_rates
.rs_nrates
- 1] & IEEE80211_RATE_VAL
));
3016 static void rt2860_periodic(void *arg
)
3018 struct rt2860_softc
*sc
;
3022 RT2860_DPRINTF(sc
, RT2860_DEBUG_PERIODIC
,
3024 device_get_nameunit(sc
->dev
));
3026 taskqueue_enqueue(sc
->taskqueue
, &sc
->periodic_task
);
3030 * rt2860_tx_watchdog
3032 static void rt2860_tx_watchdog(void *arg
)
3034 struct rt2860_softc
*sc
;
3040 if (sc
->tx_timer
== 0)
3043 if (--sc
->tx_timer
== 0)
3045 printf("%s: Tx watchdog timeout: resetting\n",
3046 device_get_nameunit(sc
->dev
));
3048 rt2860_stop_locked(sc
);
3049 rt2860_init_locked(sc
);
3053 sc
->tx_watchdog_timeouts
++;
3056 callout_reset(&sc
->tx_watchdog_ch
, hz
, rt2860_tx_watchdog
, sc
);
3060 * rt2860_staid_alloc
3062 static int rt2860_staid_alloc(struct rt2860_softc
*sc
, int aid
)
3066 if ((aid
> 0 && aid
< RT2860_SOFTC_STAID_COUNT
) && isclr(sc
->staid_mask
, aid
))
3072 for (staid
= 1; staid
< RT2860_SOFTC_STAID_COUNT
; staid
++)
3074 if (isclr(sc
->staid_mask
, staid
))
3079 setbit(sc
->staid_mask
, staid
);
3085 * rt2860_staid_delete
3087 static void rt2860_staid_delete(struct rt2860_softc
*sc
, int staid
)
3089 clrbit(sc
->staid_mask
, staid
);
3093 * rt2860_asic_set_bssid
3095 static void rt2860_asic_set_bssid(struct rt2860_softc
*sc
,
3096 const uint8_t *bssid
)
3100 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATE
,
3101 "%s: set bssid: bssid=%s\n",
3102 device_get_nameunit(sc
->dev
),
3103 ether_sprintf(bssid
));
3105 tmp
= bssid
[0] | (bssid
[1]) << 8 | (bssid
[2] << 16) | (bssid
[3] << 24);
3107 rt2860_io_mac_write(sc
, RT2860_REG_BSSID_DW0
, tmp
);
3109 tmp
= bssid
[4] | (bssid
[5] << 8);
3111 rt2860_io_mac_write(sc
, RT2860_REG_BSSID_DW1
, tmp
);
3115 * rt2860_asic_set_macaddr
3117 static void rt2860_asic_set_macaddr(struct rt2860_softc
*sc
,
3118 const uint8_t *addr
)
3122 tmp
= addr
[0] | (addr
[1] << 8) | (addr
[2] << 16) | (addr
[3] << 24);
3124 rt2860_io_mac_write(sc
, RT2860_REG_ADDR_DW0
, tmp
);
3126 tmp
= addr
[4] | (addr
[5] << 8);
3128 rt2860_io_mac_write(sc
, RT2860_REG_ADDR_DW1
, tmp
);
3132 * rt2860_asic_enable_tsf_sync
3134 static void rt2860_asic_enable_tsf_sync(struct rt2860_softc
*sc
)
3137 struct ieee80211com
*ic
;
3138 struct ieee80211vap
*vap
;
3143 vap
= TAILQ_FIRST(&ic
->ic_vaps
);
3145 RT2860_DPRINTF(sc
, RT2860_DEBUG_BEACON
,
3146 "%s: enabling TSF\n",
3147 device_get_nameunit(sc
->dev
));
3149 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_BCN_TIME_CFG
);
3152 tmp
|= vap
->iv_bss
->ni_intval
* 16;
3153 tmp
|= (RT2860_REG_TSF_TIMER_ENABLE
| RT2860_REG_TBTT_TIMER_ENABLE
);
3155 if (vap
->iv_opmode
== IEEE80211_M_STA
)
3157 tmp
|= (RT2860_REG_TSF_SYNC_MODE_STA
<< RT2860_REG_TSF_SYNC_MODE_SHIFT
);
3159 else if (vap
->iv_opmode
== IEEE80211_M_IBSS
)
3161 tmp
|= RT2860_REG_BCN_TX_ENABLE
;
3162 tmp
|= (RT2860_REG_TSF_SYNC_MODE_IBSS
<< RT2860_REG_TSF_SYNC_MODE_SHIFT
);
3164 else if (vap
->iv_opmode
== IEEE80211_M_HOSTAP
)
3166 tmp
|= RT2860_REG_BCN_TX_ENABLE
;
3167 tmp
|= (RT2860_REG_TSF_SYNC_MODE_HOSTAP
<< RT2860_REG_TSF_SYNC_MODE_SHIFT
);
3170 rt2860_io_mac_write(sc
, RT2860_REG_BCN_TIME_CFG
, tmp
);
3174 * rt2860_asic_disable_tsf_sync
3176 static void rt2860_asic_disable_tsf_sync(struct rt2860_softc
*sc
)
3180 RT2860_DPRINTF(sc
, RT2860_DEBUG_BEACON
,
3181 "%s: disabling TSF\n",
3182 device_get_nameunit(sc
->dev
));
3184 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_BCN_TIME_CFG
);
3186 tmp
&= ~(RT2860_REG_BCN_TX_ENABLE
|
3187 RT2860_REG_TSF_TIMER_ENABLE
|
3188 RT2860_REG_TBTT_TIMER_ENABLE
);
3190 tmp
&= ~(RT2860_REG_TSF_SYNC_MODE_MASK
<< RT2860_REG_TSF_SYNC_MODE_SHIFT
);
3191 tmp
|= (RT2860_REG_TSF_SYNC_MODE_DISABLE
<< RT2860_REG_TSF_SYNC_MODE_SHIFT
);
3193 rt2860_io_mac_write(sc
, RT2860_REG_BCN_TIME_CFG
, tmp
);
3197 * rt2860_asic_enable_mrr
3199 static void rt2860_asic_enable_mrr(struct rt2860_softc
*sc
)
3201 #define CCK(mcs) (mcs)
3202 #define OFDM(mcs) ((1 << 3) | (mcs))
3203 #define HT(mcs) (mcs)
3205 rt2860_io_mac_write(sc
, RT2860_REG_TX_LG_FBK_CFG0
,
3206 (OFDM(6) << 28) | /* 54 -> 48 */
3207 (OFDM(5) << 24) | /* 48 -> 36 */
3208 (OFDM(4) << 20) | /* 36 -> 24 */
3209 (OFDM(3) << 16) | /* 24 -> 18 */
3210 (OFDM(2) << 12) | /* 18 -> 12 */
3211 (OFDM(1) << 8) | /* 12 -> 9 */
3212 (OFDM(0) << 4) | /* 9 -> 6 */
3213 OFDM(0)); /* 6 -> 6 */
3215 rt2860_io_mac_write(sc
, RT2860_REG_TX_LG_FBK_CFG1
,
3216 (CCK(2) << 12) | /* 11 -> 5.5 */
3217 (CCK(1) << 8) | /* 5.5 -> 2 */
3218 (CCK(0) << 4) | /* 2 -> 1 */
3219 CCK(0)); /* 1 -> 1 */
3221 rt2860_io_mac_write(sc
, RT2860_REG_TX_HT_FBK_CFG0
,
3231 rt2860_io_mac_write(sc
, RT2860_REG_TX_HT_FBK_CFG1
,
3247 * rt2860_asic_set_txpreamble
3249 static void rt2860_asic_set_txpreamble(struct rt2860_softc
*sc
)
3252 struct ieee80211com
*ic
;
3258 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATE
,
3259 "%s: %s short Tx preamble\n",
3260 device_get_nameunit(sc
->dev
),
3261 (ic
->ic_flags
& IEEE80211_F_SHPREAMBLE
) ? "enabling" : "disabling");
3263 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_AUTO_RSP_CFG
);
3265 tmp
&= ~RT2860_REG_CCK_SHORT_ENABLE
;
3267 if (ic
->ic_flags
& IEEE80211_F_SHPREAMBLE
)
3268 tmp
|= RT2860_REG_CCK_SHORT_ENABLE
;
3270 rt2860_io_mac_write(sc
, RT2860_REG_AUTO_RSP_CFG
, tmp
);
3274 * rt2860_asic_set_basicrates
3276 static void rt2860_asic_set_basicrates(struct rt2860_softc
*sc
)
3279 struct ieee80211com
*ic
;
3284 if (ic
->ic_curmode
== IEEE80211_MODE_11B
)
3285 rt2860_io_mac_write(sc
, RT2860_REG_LEGACY_BASIC_RATE
, 0x3);
3286 else if (ic
->ic_curmode
== IEEE80211_MODE_11A
)
3287 rt2860_io_mac_write(sc
, RT2860_REG_LEGACY_BASIC_RATE
, 0x150);
3289 rt2860_io_mac_write(sc
, RT2860_REG_LEGACY_BASIC_RATE
, 0x15f);
3293 * rt2860_asic_update_rtsthreshold
3295 static void rt2860_asic_update_rtsthreshold(struct rt2860_softc
*sc
)
3298 struct ieee80211com
*ic
;
3299 struct ieee80211vap
*vap
;
3305 vap
= TAILQ_FIRST(&ic
->ic_vaps
);
3308 threshold
= IEEE80211_RTS_MAX
;
3309 else if (vap
->iv_flags_ht
& IEEE80211_FHT_AMSDU_TX
)
3312 threshold
= vap
->iv_rtsthreshold
;
3314 RT2860_DPRINTF(sc
, RT2860_DEBUG_PROT
,
3315 "%s: updating RTS threshold: %d\n",
3316 device_get_nameunit(sc
->dev
), threshold
);
3318 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_RTS_CFG
);
3320 tmp
&= ~(RT2860_REG_TX_RTS_THRESHOLD_MASK
<< RT2860_REG_TX_RTS_THRESHOLD_SHIFT
);
3322 tmp
|= ((threshold
& RT2860_REG_TX_RTS_THRESHOLD_MASK
) <<
3323 RT2860_REG_TX_RTS_THRESHOLD_SHIFT
);
3325 rt2860_io_mac_write(sc
, RT2860_REG_TX_RTS_CFG
, tmp
);
3329 * rt2860_asic_update_txpower
3331 static void rt2860_asic_update_txpower(struct rt2860_softc
*sc
)
3334 struct ieee80211com
*ic
;
3335 uint32_t *txpow_rate
;
3344 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATE
,
3345 "%s: updating Tx power: %d\n",
3346 device_get_nameunit(sc
->dev
), ic
->ic_txpowlimit
);
3348 if (!IEEE80211_IS_CHAN_HT40(ic
->ic_curchan
))
3350 txpow_rate
= sc
->txpow_rate_20mhz
;
3354 if (IEEE80211_IS_CHAN_2GHZ(ic
->ic_curchan
))
3355 txpow_rate
= sc
->txpow_rate_40mhz_2ghz
;
3357 txpow_rate
= sc
->txpow_rate_40mhz_5ghz
;
3362 val
= rt2860_io_bbp_read(sc
, 1);
3365 if (ic
->ic_txpowlimit
> 90)
3369 else if (ic
->ic_txpowlimit
> 60)
3373 else if (ic
->ic_txpowlimit
> 30)
3377 else if (ic
->ic_txpowlimit
> 15)
3381 else if (ic
->ic_txpowlimit
> 9)
3391 rt2860_io_bbp_write(sc
, 1, val
);
3393 for (i
= 0; i
< RT2860_SOFTC_TXPOW_RATE_COUNT
; i
++)
3395 if (txpow_rate
[i
] == 0xffffffff)
3398 tmp
= rt2860_read_eeprom_txpow_rate_add_delta(txpow_rate
[i
], delta
);
3400 rt2860_io_mac_write(sc
, RT2860_REG_TX_PWR_CFG(i
), tmp
);
3405 * rt2860_asic_update_promisc
3407 static void rt2860_asic_update_promisc(struct rt2860_softc
*sc
)
3414 printf("%s: %s promiscuous mode\n",
3415 device_get_nameunit(sc
->dev
),
3416 (ifp
->if_flags
& IFF_PROMISC
) ? "entering" : "leaving");
3418 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_RX_FILTER_CFG
);
3420 tmp
&= ~RT2860_REG_RX_FILTER_DROP_UC_NOME
;
3422 if (!(ifp
->if_flags
& IFF_PROMISC
))
3423 tmp
|= RT2860_REG_RX_FILTER_DROP_UC_NOME
;
3425 rt2860_io_mac_write(sc
, RT2860_REG_RX_FILTER_CFG
, tmp
);
3429 * rt2860_asic_updateprot
3431 static void rt2860_asic_updateprot(struct rt2860_softc
*sc
)
3434 struct ieee80211com
*ic
;
3435 struct ieee80211vap
*vap
;
3436 uint32_t cck_prot
, ofdm_prot
, mm20_prot
, mm40_prot
, gf20_prot
, gf40_prot
;
3438 enum ieee80211_protmode htprotmode
;
3442 vap
= TAILQ_FIRST(&ic
->ic_vaps
);
3444 /* CCK frame protection */
3446 cck_prot
= RT2860_REG_RTSTH_ENABLE
| RT2860_REG_PROT_NAV_SHORT
|
3447 RT2860_REG_TXOP_ALLOW_ALL
| RT2860_REG_PROT_CTRL_NONE
;
3449 /* set up protection frame phy mode and rate (MCS code) */
3451 if (ic
->ic_curmode
== IEEE80211_MODE_11A
)
3452 cck_prot
|= (RT2860_REG_PROT_PHYMODE_OFDM
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3453 (0 << RT2860_REG_PROT_MCS_SHIFT
);
3455 cck_prot
|= ((RT2860_REG_PROT_PHYMODE_CCK
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3456 (3 << RT2860_REG_PROT_MCS_SHIFT
));
3458 rt2860_io_mac_write(sc
, RT2860_REG_TX_CCK_PROT_CFG
, cck_prot
);
3460 /* OFDM frame protection */
3462 ofdm_prot
= RT2860_REG_RTSTH_ENABLE
| RT2860_REG_PROT_NAV_SHORT
|
3463 RT2860_REG_TXOP_ALLOW_ALL
;
3465 if (ic
->ic_flags
& IEEE80211_F_USEPROT
)
3467 RT2860_DPRINTF(sc
, RT2860_DEBUG_PROT
,
3468 "%s: updating protection mode: b/g protection mode=%s\n",
3469 device_get_nameunit(sc
->dev
),
3470 (ic
->ic_protmode
== IEEE80211_PROT_RTSCTS
) ? "RTS/CTS" :
3471 ((ic
->ic_protmode
== IEEE80211_PROT_CTSONLY
) ? "CTS-to-self" : "none"));
3473 if (ic
->ic_protmode
== IEEE80211_PROT_RTSCTS
)
3474 ofdm_prot
|= RT2860_REG_PROT_CTRL_RTS_CTS
;
3475 else if (ic
->ic_protmode
== IEEE80211_PROT_CTSONLY
)
3476 ofdm_prot
|= RT2860_REG_PROT_CTRL_CTS
;
3478 ofdm_prot
|= RT2860_REG_PROT_CTRL_NONE
;
3482 RT2860_DPRINTF(sc
, RT2860_DEBUG_PROT
,
3483 "%s: updating protection mode: b/g protection mode=%s\n",
3484 device_get_nameunit(sc
->dev
), "none");
3486 ofdm_prot
|= RT2860_REG_PROT_CTRL_NONE
;
3489 rt2860_io_mac_write(sc
, RT2860_REG_TX_OFDM_PROT_CFG
, ofdm_prot
);
3491 /* HT frame protection */
3493 if ((vap
!= NULL
) && (vap
->iv_opmode
== IEEE80211_M_STA
) && (vap
->iv_state
== IEEE80211_S_RUN
))
3494 htopmode
= vap
->iv_bss
->ni_htopmode
;
3496 htopmode
= ic
->ic_curhtprotmode
;
3498 htprotmode
= ic
->ic_htprotmode
;
3500 /* force HT mixed mode and RTS/CTS protection if A-MPDU Tx aggregation is enabled */
3502 if (sc
->tx_ampdu_sessions
> 0)
3504 RT2860_DPRINTF(sc
, RT2860_DEBUG_PROT
,
3505 "%s: updating protection mode: forcing HT mixed mode and RTS/CTS protection\n",
3506 device_get_nameunit(sc
->dev
));
3508 htopmode
= IEEE80211_HTINFO_OPMODE_MIXED
;
3509 htprotmode
= IEEE80211_PROT_RTSCTS
;
3512 RT2860_DPRINTF(sc
, RT2860_DEBUG_PROT
,
3513 "%s: updating protection mode: HT operation mode=0x%02x, protection mode=%s\n",
3514 device_get_nameunit(sc
->dev
),
3515 htopmode
& IEEE80211_HTINFO_OPMODE
,
3516 (htprotmode
== IEEE80211_PROT_RTSCTS
) ? "RTS/CTS" :
3517 ((htprotmode
== IEEE80211_PROT_CTSONLY
) ? "CTS-to-self" : "none"));
3519 switch (htopmode
& IEEE80211_HTINFO_OPMODE
)
3521 /* IEEE80211_HTINFO_OPMODE_HT20PR */
3522 case IEEE80211_HTINFO_OPMODE_HT20PR
:
3523 mm20_prot
= RT2860_REG_PROT_NAV_SHORT
| RT2860_REG_PROT_CTRL_NONE
|
3524 RT2860_REG_TXOP_ALLOW_CCK
| RT2860_REG_TXOP_ALLOW_OFDM
|
3525 RT2860_REG_TXOP_ALLOW_MM20
| RT2860_REG_TXOP_ALLOW_GF20
|
3526 (RT2860_REG_PROT_PHYMODE_OFDM
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3527 (4 << RT2860_REG_PROT_MCS_SHIFT
);
3529 gf20_prot
= mm20_prot
;
3531 mm40_prot
= RT2860_REG_PROT_NAV_SHORT
| RT2860_REG_TXOP_ALLOW_ALL
|
3532 (RT2860_REG_PROT_PHYMODE_OFDM
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3533 (0x84 << RT2860_REG_PROT_MCS_SHIFT
);
3535 if (htprotmode
== IEEE80211_PROT_RTSCTS
)
3536 mm40_prot
|= RT2860_REG_PROT_CTRL_RTS_CTS
;
3537 else if (htprotmode
== IEEE80211_PROT_CTSONLY
)
3538 mm40_prot
|= RT2860_REG_PROT_CTRL_CTS
;
3540 mm40_prot
|= RT2860_REG_PROT_CTRL_NONE
;
3542 gf40_prot
= mm40_prot
;
3545 /* IEEE80211_HTINFO_OPMODE_MIXED */
3546 case IEEE80211_HTINFO_OPMODE_MIXED
:
3547 mm20_prot
= RT2860_REG_PROT_NAV_SHORT
|
3548 RT2860_REG_TXOP_ALLOW_CCK
| RT2860_REG_TXOP_ALLOW_OFDM
|
3549 RT2860_REG_TXOP_ALLOW_MM20
| RT2860_REG_TXOP_ALLOW_GF20
;
3551 if (ic
->ic_flags
& IEEE80211_F_USEPROT
)
3552 mm20_prot
|= (RT2860_REG_PROT_PHYMODE_CCK
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3553 (3 << RT2860_REG_PROT_MCS_SHIFT
);
3555 mm20_prot
|= (RT2860_REG_PROT_PHYMODE_OFDM
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3556 (4 << RT2860_REG_PROT_MCS_SHIFT
);
3558 if (htprotmode
== IEEE80211_PROT_RTSCTS
)
3559 mm20_prot
|= RT2860_REG_PROT_CTRL_RTS_CTS
;
3560 else if (htprotmode
== IEEE80211_PROT_CTSONLY
)
3561 mm20_prot
|= RT2860_REG_PROT_CTRL_CTS
;
3563 mm20_prot
|= RT2860_REG_PROT_CTRL_NONE
;
3565 gf20_prot
= mm20_prot
;
3567 mm40_prot
= RT2860_REG_PROT_NAV_SHORT
| RT2860_REG_TXOP_ALLOW_ALL
;
3569 if (ic
->ic_flags
& IEEE80211_F_USEPROT
)
3570 mm40_prot
|= (RT2860_REG_PROT_PHYMODE_CCK
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3571 (3 << RT2860_REG_PROT_MCS_SHIFT
);
3573 mm40_prot
|= (RT2860_REG_PROT_PHYMODE_OFDM
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3574 (0x84 << RT2860_REG_PROT_MCS_SHIFT
);
3576 if (htprotmode
== IEEE80211_PROT_RTSCTS
)
3577 mm40_prot
|= RT2860_REG_PROT_CTRL_RTS_CTS
;
3578 else if (htprotmode
== IEEE80211_PROT_CTSONLY
)
3579 mm40_prot
|= RT2860_REG_PROT_CTRL_CTS
;
3581 mm40_prot
|= RT2860_REG_PROT_CTRL_NONE
;
3583 gf40_prot
= mm40_prot
;
3587 * IEEE80211_HTINFO_OPMODE_PURE
3588 * IEEE80211_HTINFO_OPMODE_PROTOPT
3590 case IEEE80211_HTINFO_OPMODE_PURE
:
3591 case IEEE80211_HTINFO_OPMODE_PROTOPT
:
3593 mm20_prot
= RT2860_REG_PROT_NAV_SHORT
| RT2860_REG_PROT_CTRL_NONE
|
3594 RT2860_REG_TXOP_ALLOW_CCK
| RT2860_REG_TXOP_ALLOW_OFDM
|
3595 RT2860_REG_TXOP_ALLOW_MM20
| RT2860_REG_TXOP_ALLOW_GF20
|
3596 (RT2860_REG_PROT_PHYMODE_OFDM
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3597 (4 << RT2860_REG_PROT_MCS_SHIFT
);
3599 gf20_prot
= mm20_prot
;
3601 mm40_prot
= RT2860_REG_PROT_NAV_SHORT
| RT2860_REG_PROT_CTRL_NONE
|
3602 RT2860_REG_TXOP_ALLOW_ALL
|
3603 (RT2860_REG_PROT_PHYMODE_OFDM
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3604 (0x84 << RT2860_REG_PROT_MCS_SHIFT
);
3606 gf40_prot
= mm40_prot
;
3610 rt2860_io_mac_write(sc
, RT2860_REG_TX_MM20_PROT_CFG
, mm20_prot
);
3611 rt2860_io_mac_write(sc
, RT2860_REG_TX_MM40_PROT_CFG
, mm40_prot
);
3612 rt2860_io_mac_write(sc
, RT2860_REG_TX_GF20_PROT_CFG
, gf20_prot
);
3613 rt2860_io_mac_write(sc
, RT2860_REG_TX_GF40_PROT_CFG
, gf40_prot
);
3617 * rt2860_asic_updateslot
3619 static void rt2860_asic_updateslot(struct rt2860_softc
*sc
)
3622 struct ieee80211com
*ic
;
3623 struct ieee80211vap
*vap
;
3628 vap
= TAILQ_FIRST(&ic
->ic_vaps
);
3630 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATE
,
3631 "%s: %s short slot time\n",
3632 device_get_nameunit(sc
->dev
),
3633 ((ic
->ic_flags
& IEEE80211_F_SHSLOT
) ||
3634 ((vap
!= NULL
) && (vap
->iv_flags
& IEEE80211_F_BURST
))) ? "enabling" : "disabling");
3636 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_BKOFF_SLOT_CFG
);
3640 if ((ic
->ic_flags
& IEEE80211_F_SHSLOT
) ||
3641 ((vap
!= NULL
) && (vap
->iv_flags
& IEEE80211_F_BURST
)))
3642 tmp
|= IEEE80211_DUR_SHSLOT
;
3644 tmp
|= IEEE80211_DUR_SLOT
;
3646 rt2860_io_mac_write(sc
, RT2860_REG_BKOFF_SLOT_CFG
, tmp
);
3650 * rt2860_asic_wme_update
3652 static void rt2860_asic_wme_update(struct rt2860_softc
*sc
)
3655 struct ieee80211com
*ic
;
3656 struct ieee80211_wme_state
*wme
;
3657 const struct wmeParams
*wmep
;
3663 wmep
= wme
->wme_chanParams
.cap_wmeParams
;
3665 RT2860_DPRINTF(sc
, RT2860_DEBUG_WME
,
3666 "%s: wme update: WME_AC_VO=%d/%d/%d/%d, WME_AC_VI=%d/%d/%d/%d, "
3667 "WME_AC_BK=%d/%d/%d/%d, WME_AC_BE=%d/%d/%d/%d\n",
3668 device_get_nameunit(sc
->dev
),
3669 wmep
[WME_AC_VO
].wmep_aifsn
,
3670 wmep
[WME_AC_VO
].wmep_logcwmin
, wmep
[WME_AC_VO
].wmep_logcwmax
,
3671 wmep
[WME_AC_VO
].wmep_txopLimit
,
3672 wmep
[WME_AC_VI
].wmep_aifsn
,
3673 wmep
[WME_AC_VI
].wmep_logcwmin
, wmep
[WME_AC_VI
].wmep_logcwmax
,
3674 wmep
[WME_AC_VI
].wmep_txopLimit
,
3675 wmep
[WME_AC_BK
].wmep_aifsn
,
3676 wmep
[WME_AC_BK
].wmep_logcwmin
, wmep
[WME_AC_BK
].wmep_logcwmax
,
3677 wmep
[WME_AC_BK
].wmep_txopLimit
,
3678 wmep
[WME_AC_BE
].wmep_aifsn
,
3679 wmep
[WME_AC_BE
].wmep_logcwmin
, wmep
[WME_AC_BE
].wmep_logcwmax
,
3680 wmep
[WME_AC_BE
].wmep_txopLimit
);
3682 for (i
= 0; i
< WME_NUM_AC
; i
++)
3683 rt2860_io_mac_write(sc
, RT2860_REG_TX_EDCA_AC_CFG(i
),
3684 (wmep
[i
].wmep_logcwmax
<< 16) | (wmep
[i
].wmep_logcwmin
<< 12) |
3685 (wmep
[i
].wmep_aifsn
<< 8) | wmep
[i
].wmep_txopLimit
);
3687 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WMM_AIFSN_CFG
,
3688 (wmep
[WME_AC_VO
].wmep_aifsn
<< 12) | (wmep
[WME_AC_VI
].wmep_aifsn
<< 8) |
3689 (wmep
[WME_AC_BK
].wmep_aifsn
<< 4) | wmep
[WME_AC_BE
].wmep_aifsn
);
3691 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WMM_CWMIN_CFG
,
3692 (wmep
[WME_AC_VO
].wmep_logcwmin
<< 12) | (wmep
[WME_AC_VI
].wmep_logcwmin
<< 8) |
3693 (wmep
[WME_AC_BK
].wmep_logcwmin
<< 4) | wmep
[WME_AC_BE
].wmep_logcwmin
);
3695 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WMM_CWMAX_CFG
,
3696 (wmep
[WME_AC_VO
].wmep_logcwmax
<< 12) | (wmep
[WME_AC_VI
].wmep_logcwmax
<< 8) |
3697 (wmep
[WME_AC_BK
].wmep_logcwmax
<< 4) | wmep
[WME_AC_BE
].wmep_logcwmax
);
3699 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WMM_TXOP0_CFG
,
3700 (wmep
[WME_AC_BK
].wmep_txopLimit
<< 16) | wmep
[WME_AC_BE
].wmep_txopLimit
);
3702 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WMM_TXOP1_CFG
,
3703 (wmep
[WME_AC_VO
].wmep_txopLimit
<< 16) | wmep
[WME_AC_VI
].wmep_txopLimit
);
3707 * rt2860_asic_update_beacon
3709 static void rt2860_asic_update_beacon(struct rt2860_softc
*sc
,
3710 struct ieee80211vap
*vap
)
3712 struct rt2860_softc_vap
*rvap
;
3714 struct rt2860_txwi
*txwi
;
3717 rvap
= (struct rt2860_softc_vap
*) vap
;
3719 m
= rvap
->beacon_mbuf
;
3720 txwi
= &rvap
->beacon_txwi
;
3722 /* disable temporarily TSF sync */
3724 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_BCN_TIME_CFG
);
3726 tmp
&= ~(RT2860_REG_BCN_TX_ENABLE
|
3727 RT2860_REG_TSF_TIMER_ENABLE
|
3728 RT2860_REG_TBTT_TIMER_ENABLE
);
3730 rt2860_io_mac_write(sc
, RT2860_REG_BCN_TIME_CFG
, tmp
);
3732 /* write Tx wireless info and beacon frame to on-chip memory */
3734 rt2860_io_mac_write_multi(sc
, RT2860_REG_BEACON_BASE(0),
3735 txwi
, sizeof(struct rt2860_txwi
));
3737 rt2860_io_mac_write_multi(sc
, RT2860_REG_BEACON_BASE(0) + sizeof(struct rt2860_txwi
),
3738 mtod(m
, uint8_t *), m
->m_pkthdr
.len
);
3740 /* enable again TSF sync */
3742 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_BCN_TIME_CFG
);
3744 tmp
|= (RT2860_REG_BCN_TX_ENABLE
|
3745 RT2860_REG_TSF_TIMER_ENABLE
|
3746 RT2860_REG_TBTT_TIMER_ENABLE
);
3748 rt2860_io_mac_write(sc
, RT2860_REG_BCN_TIME_CFG
, tmp
);
3752 * rt2860_asic_clear_keytables
3754 static void rt2860_asic_clear_keytables(struct rt2860_softc
*sc
)
3758 /* clear Rx WCID search table (entries = 256, entry size = 8) */
3760 for (i
= 0; i
< 256; i
++)
3762 rt2860_io_mac_write(sc
, RT2860_REG_WCID(i
), 0xffffffff);
3763 rt2860_io_mac_write(sc
, RT2860_REG_WCID(i
) + 4, 0x0000ffff);
3766 /* clear WCID attribute table (entries = 256, entry size = 4) */
3768 rt2860_io_mac_set_region_4(sc
, RT2860_REG_WCID_ATTR(0), 0, 256);
3770 /* clear IV/EIV table (entries = 256, entry size = 8) */
3772 rt2860_io_mac_set_region_4(sc
, RT2860_REG_IVEIV(0), 0, 2 * 256);
3774 /* clear pairwise key table (entries = 64, entry size = 32) */
3776 rt2860_io_mac_set_region_4(sc
, RT2860_REG_PKEY(0), 0, 8 * 64);
3778 /* clear shared key table (entries = 32, entry size = 32) */
3780 rt2860_io_mac_set_region_4(sc
, RT2860_REG_SKEY(0, 0), 0, 8 * 32);
3782 /* clear shared key mode (entries = 32, entry size = 2) */
3784 rt2860_io_mac_set_region_4(sc
, RT2860_REG_SKEY_MODE(0), 0, 16);
3788 * rt2860_beacon_alloc
3790 static int rt2860_beacon_alloc(struct rt2860_softc
*sc
,
3791 struct ieee80211vap
*vap
)
3793 struct ieee80211com
*ic
;
3794 struct rt2860_softc_vap
*rvap
;
3795 const struct ieee80211_txparam
*tp
;
3797 struct rt2860_txwi txwi
;
3801 rvap
= (struct rt2860_softc_vap
*) vap
;
3802 tp
= &vap
->iv_txparms
[ieee80211_chan2mode(ic
->ic_bsschan
)];
3804 m
= ieee80211_beacon_alloc(vap
->iv_bss
, &rvap
->beacon_offsets
);
3808 rate
= tp
->mgmtrate
;
3809 mcs
= rt2860_rate2mcs(rate
);
3811 memset(&txwi
, 0, sizeof(struct rt2860_txwi
));
3813 txwi
.wcid
= RT2860_WCID_RESERVED
;
3814 txwi
.pid_mpdu_len
= ((htole16(m
->m_pkthdr
.len
) & RT2860_TXWI_MPDU_LEN_MASK
) <<
3815 RT2860_TXWI_MPDU_LEN_SHIFT
);
3816 txwi
.txop
= (RT2860_TXWI_TXOP_HT
<< RT2860_TXWI_TXOP_SHIFT
);
3817 txwi
.mpdu_density_flags
|=
3818 (RT2860_TXWI_FLAGS_TS
<< RT2860_TXWI_FLAGS_SHIFT
);
3819 txwi
.bawin_size_xflags
|=
3820 (RT2860_TXWI_XFLAGS_NSEQ
<< RT2860_TXWI_XFLAGS_SHIFT
);
3822 if (ieee80211_rate2phytype(ic
->ic_rt
, rate
) != IEEE80211_T_OFDM
)
3824 txwi
.phymode_ifs_stbc_shortgi
=
3825 (RT2860_TXWI_PHYMODE_CCK
<< RT2860_TXWI_PHYMODE_SHIFT
);
3827 if (rate
!= 2 && (ic
->ic_flags
& IEEE80211_F_SHPREAMBLE
))
3828 mcs
|= RT2860_TXWI_MCS_SHOTPRE
;
3832 txwi
.phymode_ifs_stbc_shortgi
=
3833 (RT2860_TXWI_PHYMODE_OFDM
<< RT2860_TXWI_PHYMODE_SHIFT
);
3836 txwi
.bw_mcs
= (RT2860_TXWI_BW_20
<< RT2860_TXWI_BW_SHIFT
) |
3837 ((mcs
& RT2860_TXWI_MCS_MASK
) << RT2860_TXWI_MCS_SHIFT
);
3839 if (rvap
->beacon_mbuf
!= NULL
)
3841 m_free(rvap
->beacon_mbuf
);
3842 rvap
->beacon_mbuf
= NULL
;
3845 rvap
->beacon_mbuf
= m
;
3846 rvap
->beacon_txwi
= txwi
;
3854 static uint8_t rt2860_rxrate(struct rt2860_rxwi
*rxwi
)
3856 uint8_t mcs
, phymode
;
3859 mcs
= (rxwi
->bw_mcs
>> RT2860_RXWI_MCS_SHIFT
) & RT2860_RXWI_MCS_MASK
;
3860 phymode
= (rxwi
->phymode_stbc_shortgi
>> RT2860_RXWI_PHYMODE_SHIFT
) &
3861 RT2860_RXWI_PHYMODE_MASK
;
3867 case RT2860_RXWI_PHYMODE_CCK
:
3868 switch (mcs
& ~RT2860_RXWI_MCS_SHOTPRE
)
3870 case 0: rate
= 2; break; /* 1 Mbps */
3871 case 1: rate
= 4; break; /* 2 MBps */
3872 case 2: rate
= 11; break; /* 5.5 Mbps */
3873 case 3: rate
= 22; break; /* 11 Mbps */
3877 case RT2860_RXWI_PHYMODE_OFDM
:
3880 case 0: rate
= 12; break; /* 6 Mbps */
3881 case 1: rate
= 18; break; /* 9 Mbps */
3882 case 2: rate
= 24; break; /* 12 Mbps */
3883 case 3: rate
= 36; break; /* 18 Mbps */
3884 case 4: rate
= 48; break; /* 24 Mbps */
3885 case 5: rate
= 72; break; /* 36 Mbps */
3886 case 6: rate
= 96; break; /* 48 Mbps */
3887 case 7: rate
= 108; break; /* 54 Mbps */
3891 case RT2860_RXWI_PHYMODE_HT_MIXED
:
3892 case RT2860_RXWI_PHYMODE_HT_GF
:
3900 * rt2860_maxrssi_rxpath
3902 static uint8_t rt2860_maxrssi_rxpath(struct rt2860_softc
*sc
,
3903 const struct rt2860_rxwi
*rxwi
)
3909 if (sc
->nrxpath
> 1)
3910 if (rxwi
->rssi
[1] > rxwi
->rssi
[rxpath
])
3913 if (sc
->nrxpath
> 2)
3914 if (rxwi
->rssi
[2] > rxwi
->rssi
[rxpath
])
3923 static int8_t rt2860_rssi2dbm(struct rt2860_softc
*sc
,
3924 uint8_t rssi
, uint8_t rxpath
)
3927 struct ieee80211com
*ic
;
3928 struct ieee80211_channel
*c
;
3930 int8_t rssi_off
, lna_gain
;
3938 chan
= ieee80211_chan2ieee(ic
, c
);
3940 if (IEEE80211_IS_CHAN_5GHZ(c
))
3942 rssi_off
= sc
->rssi_off_5ghz
[rxpath
];
3945 lna_gain
= sc
->lna_gain
[1];
3946 else if (chan
<= 128)
3947 lna_gain
= sc
->lna_gain
[2];
3949 lna_gain
= sc
->lna_gain
[3];
3953 rssi_off
= sc
->rssi_off_2ghz
[rxpath
] - sc
->lna_gain
[0];
3954 lna_gain
= sc
->lna_gain
[0];
3957 return (-12 - rssi_off
- lna_gain
- rssi
);
3963 static uint8_t rt2860_rate2mcs(uint8_t rate
)
3990 static int rt2860_tx_mgmt(struct rt2860_softc
*sc
,
3991 struct mbuf
*m
, struct ieee80211_node
*ni
, int qid
)
3994 struct ieee80211com
*ic
;
3995 struct ieee80211vap
*vap
;
3996 const struct ieee80211_txparam
*tp
;
3997 struct rt2860_softc_node
*rni
;
3998 struct rt2860_softc_tx_ring
*ring
;
3999 struct rt2860_softc_tx_data
*data
;
4000 struct rt2860_txdesc
*desc
;
4001 struct rt2860_txwi
*txwi
;
4002 struct ieee80211_frame
*wh
;
4003 struct rt2860_softc_tx_radiotap_header
*tap
;
4004 bus_dma_segment_t dma_seg
[RT2860_SOFTC_MAX_SCATTER
];
4005 u_int hdrsize
, hdrspace
;
4006 uint8_t rate
, stbc
, shortgi
, mcs
, pid
, qsel
;
4007 uint16_t len
, dmalen
, mpdu_len
, dur
;
4008 int error
, mimops
, ndmasegs
, ndescs
, i
, j
;
4010 KASSERT(qid
>= 0 && qid
< RT2860_SOFTC_TX_RING_COUNT
,
4011 ("%s: Tx MGMT: invalid qid=%d\n",
4012 device_get_nameunit(sc
->dev
), qid
));
4017 rni
= (struct rt2860_softc_node
*) ni
;
4018 tp
= ni
->ni_txparms
;
4020 ring
= &sc
->tx_ring
[qid
];
4021 desc
= &ring
->desc
[ring
->desc_cur
];
4022 data
= &ring
->data
[ring
->data_cur
];
4023 txwi
= (struct rt2860_txwi
*) (ring
->seg0
+ ring
->data_cur
* RT2860_TX_DATA_SEG0_SIZE
);
4025 wh
= mtod(m
, struct ieee80211_frame
*);
4027 rate
= tp
->mgmtrate
& IEEE80211_RATE_VAL
;
4029 /* fill Tx wireless info */
4031 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
4034 mcs
= rt2860_rate2mcs(rate
);
4036 /* calculate MPDU length without padding */
4038 hdrsize
= ieee80211_hdrsize(wh
);
4039 hdrspace
= ieee80211_hdrspace(ic
, wh
);
4040 mpdu_len
= m
->m_pkthdr
.len
- hdrspace
+ hdrsize
;
4042 memset(txwi
, 0, sizeof(struct rt2860_txwi
));
4044 /* management frames do not need encryption */
4046 txwi
->wcid
= RT2860_WCID_RESERVED
;
4048 /* MIMO power save */
4050 if ((ni
->ni_flags
& IEEE80211_NODE_HT
) && (ni
->ni_flags
& IEEE80211_NODE_MIMO_PS
))
4054 if (ni
->ni_flags
& IEEE80211_NODE_MIMO_RTS
)
4056 /* dynamic MIMO power save */
4058 txwi
->mpdu_density_flags
|=
4059 (RT2860_TXWI_FLAGS_MIMOPS
<< RT2860_TXWI_FLAGS_SHIFT
);
4063 /* static MIMO power save */
4078 txwi
->pid_mpdu_len
= ((htole16(pid
) & RT2860_TXWI_PID_MASK
) <<
4079 RT2860_TXWI_PID_SHIFT
) | ((htole16(mpdu_len
) & RT2860_TXWI_MPDU_LEN_MASK
) <<
4080 RT2860_TXWI_MPDU_LEN_SHIFT
);
4082 stbc
= (ic
->ic_htcaps
& IEEE80211_HTCAP_TXSTBC
) &&
4083 (ni
->ni_flags
& IEEE80211_NODE_HT
) && (ni
->ni_htcap
& IEEE80211_HTCAP_RXSTBC
);
4085 shortgi
= (vap
->iv_flags_ht
& (IEEE80211_FHT_SHORTGI20
| IEEE80211_FHT_SHORTGI40
)) &&
4086 (ni
->ni_flags
& IEEE80211_NODE_HT
) && (ni
->ni_flags
& (IEEE80211_NODE_SGI20
| IEEE80211_NODE_SGI40
));
4088 txwi
->phymode_ifs_stbc_shortgi
|=
4089 ((stbc
& RT2860_TXWI_STBC_MASK
) << RT2860_TXWI_STBC_SHIFT
) |
4090 ((shortgi
& RT2860_TXWI_SHORTGI_MASK
) << RT2860_TXWI_SHORTGI_SHIFT
);
4092 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
4094 txwi
->phymode_ifs_stbc_shortgi
|=
4095 (RT2860_TXWI_PHYMODE_HT_MIXED
<< RT2860_TXWI_PHYMODE_SHIFT
);
4099 if (ieee80211_rate2phytype(ic
->ic_rt
, rate
) != IEEE80211_T_OFDM
)
4101 txwi
->phymode_ifs_stbc_shortgi
|=
4102 (RT2860_TXWI_PHYMODE_CCK
<< RT2860_TXWI_PHYMODE_SHIFT
);
4104 if (rate
!= 2 && (ic
->ic_flags
& IEEE80211_F_SHPREAMBLE
))
4105 mcs
|= RT2860_TXWI_MCS_SHOTPRE
;
4109 txwi
->phymode_ifs_stbc_shortgi
|=
4110 (RT2860_TXWI_PHYMODE_OFDM
<< RT2860_TXWI_PHYMODE_SHIFT
);
4114 txwi
->bw_mcs
= (RT2860_TXWI_BW_20
<< RT2860_TXWI_BW_SHIFT
) |
4115 ((mcs
& RT2860_TXWI_MCS_MASK
) << RT2860_TXWI_MCS_SHIFT
);
4117 txwi
->txop
= (RT2860_TXWI_TXOP_BACKOFF
<< RT2860_TXWI_TXOP_SHIFT
);
4119 /* skip ACKs for multicast frames */
4121 if (!IEEE80211_IS_MULTICAST(wh
->i_addr1
))
4123 txwi
->bawin_size_xflags
|=
4124 (RT2860_TXWI_XFLAGS_ACK
<< RT2860_TXWI_XFLAGS_SHIFT
);
4126 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
4128 /* preamble + plcp + signal extension + SIFS */
4130 dur
= 16 + 4 + 6 + 10;
4134 dur
= ieee80211_ack_duration(ic
->ic_rt
, rate
,
4135 ic
->ic_flags
& IEEE80211_F_SHPREAMBLE
);
4138 *(uint16_t *) wh
->i_dur
= htole16(dur
);
4141 /* ask MAC to insert timestamp into probe responses */
4143 if ((wh
->i_fc
[0] & (IEEE80211_FC0_TYPE_MASK
| IEEE80211_FC0_SUBTYPE_MASK
)) ==
4144 (IEEE80211_FC0_TYPE_MGT
| IEEE80211_FC0_SUBTYPE_PROBE_RESP
))
4145 txwi
->mpdu_density_flags
|=
4146 (RT2860_TXWI_FLAGS_TS
<< RT2860_TXWI_FLAGS_SHIFT
);
4148 if (ieee80211_radiotap_active_vap(vap
))
4152 tap
->flags
= IEEE80211_RADIOTAP_F_DATAPAD
;
4153 tap
->chan_flags
= htole32(ic
->ic_curchan
->ic_flags
);
4154 tap
->chan_freq
= htole16(ic
->ic_curchan
->ic_freq
);
4155 tap
->chan_ieee
= ic
->ic_curchan
->ic_ieee
;
4156 tap
->chan_maxpow
= 0;
4158 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
4159 tap
->rate
= mcs
| IEEE80211_RATE_MCS
;
4163 if (mcs
& RT2860_TXWI_MCS_SHOTPRE
)
4164 tap
->flags
|= IEEE80211_RADIOTAP_F_SHORTPRE
;
4167 tap
->flags
|= IEEE80211_RADIOTAP_F_SHORTGI
;
4169 if (wh
->i_fc
[1] & IEEE80211_FC1_WEP
)
4170 tap
->flags
|= IEEE80211_RADIOTAP_F_WEP
;
4172 if (wh
->i_fc
[1] & IEEE80211_FC1_WEP
)
4174 wh
->i_fc
[1] &= ~IEEE80211_FC1_WEP
;
4176 ieee80211_radiotap_tx(vap
, m
);
4178 wh
->i_fc
[1] |= IEEE80211_FC1_WEP
;
4182 ieee80211_radiotap_tx(vap
, m
);
4186 /* copy and trim 802.11 header */
4188 m_copydata(m
, 0, hdrsize
, (caddr_t
) (txwi
+ 1));
4191 error
= bus_dmamap_load_mbuf_sg(ring
->data_dma_tag
, data
->dma_map
, m
,
4192 dma_seg
, &ndmasegs
, 0);
4195 /* too many fragments, linearize */
4197 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
4198 "%s: could not load mbuf DMA map, trying to linearize mbuf: ndmasegs=%d, len=%d, error=%d\n",
4199 device_get_nameunit(sc
->dev
), ndmasegs
, m
->m_pkthdr
.len
, error
);
4201 m
= m_defrag(m
, M_DONTWAIT
);
4205 sc
->tx_defrag_packets
++;
4207 error
= bus_dmamap_load_mbuf_sg(ring
->data_dma_tag
, data
->dma_map
, m
,
4208 dma_seg
, &ndmasegs
, 0);
4211 printf("%s: could not load mbuf DMA map: ndmasegs=%d, len=%d, error=%d\n",
4212 device_get_nameunit(sc
->dev
), ndmasegs
, m
->m_pkthdr
.len
, error
);
4218 if (m
->m_pkthdr
.len
== 0)
4221 /* determine how many Tx descs are required */
4223 ndescs
= 1 + ndmasegs
/ 2;
4224 if ((ring
->desc_queued
+ ndescs
) > (RT2860_SOFTC_TX_RING_DESC_COUNT
- 2))
4226 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
4227 "%s: there are not enough Tx descs\n",
4228 device_get_nameunit(sc
->dev
));
4230 sc
->no_tx_desc_avail
++;
4232 bus_dmamap_unload(ring
->data_dma_tag
, data
->dma_map
);
4240 /* set up Tx descs */
4242 /* first segment is Tx wireless info and 802.11 header */
4244 len
= sizeof(struct rt2860_txwi
) + hdrsize
;
4246 /* align end on a 4-bytes boundary */
4248 dmalen
= (len
+ 3) & ~ 3;
4250 memset((caddr_t
) txwi
+ len
, 0, dmalen
- len
);
4252 qsel
= RT2860_TXDESC_QSEL_EDCA
;
4254 desc
->sdp0
= htole32(ring
->seg0_phys_addr
+ ring
->data_cur
* RT2860_TX_DATA_SEG0_SIZE
);
4255 desc
->sdl0
= htole16(dmalen
);
4256 desc
->qsel_flags
= (qsel
<< RT2860_TXDESC_QSEL_SHIFT
);
4258 /* set up payload segments */
4260 for (i
= ndmasegs
, j
= 0; i
>= 2; i
-= 2)
4262 desc
->sdp1
= htole32(dma_seg
[j
].ds_addr
);
4263 desc
->sdl1
= htole16(dma_seg
[j
].ds_len
);
4265 ring
->desc_queued
++;
4266 ring
->desc_cur
= (ring
->desc_cur
+ 1) % RT2860_SOFTC_TX_RING_DESC_COUNT
;
4270 desc
= &ring
->desc
[ring
->desc_cur
];
4272 desc
->sdp0
= htole32(dma_seg
[j
].ds_addr
);
4273 desc
->sdl0
= htole16(dma_seg
[j
].ds_len
);
4274 desc
->qsel_flags
= (qsel
<< RT2860_TXDESC_QSEL_SHIFT
);
4279 /* finalize last payload segment */
4283 desc
->sdp1
= htole32(dma_seg
[j
].ds_addr
);
4284 desc
->sdl1
= htole16(dma_seg
[j
].ds_len
| RT2860_TXDESC_SDL1_LASTSEG
);
4288 desc
->sdl0
|= htole16(RT2860_TXDESC_SDL0_LASTSEG
);
4292 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
4293 "%s: sending MGMT frame: qid=%d, hdrsize=%d, hdrspace=%d, len=%d, "
4294 "stbc=%d, shortgi=%d, mcs=%d, mimops=%d, DMA len=%d, ndmasegs=%d, DMA ds_len=%d/%d/%d/%d/%d\n",
4295 device_get_nameunit(sc
->dev
),
4296 qid
, hdrsize
, hdrspace
, m
->m_pkthdr
.len
+ hdrsize
,
4297 stbc
, shortgi
, mcs
, mimops
, dmalen
, ndmasegs
,
4298 (int) dma_seg
[0].ds_len
, (int) dma_seg
[1].ds_len
, (int) dma_seg
[2].ds_len
, (int) dma_seg
[3].ds_len
, (int) dma_seg
[4].ds_len
);
4300 bus_dmamap_sync(ring
->seg0_dma_tag
, ring
->seg0_dma_map
,
4301 BUS_DMASYNC_PREWRITE
);
4302 bus_dmamap_sync(ring
->data_dma_tag
, data
->dma_map
,
4303 BUS_DMASYNC_PREWRITE
);
4304 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
4305 BUS_DMASYNC_PREWRITE
);
4307 ring
->desc_queued
++;
4308 ring
->desc_cur
= (ring
->desc_cur
+ 1) % RT2860_SOFTC_TX_RING_DESC_COUNT
;
4310 ring
->data_queued
++;
4311 ring
->data_cur
= (ring
->data_cur
+ 1) % RT2860_SOFTC_TX_RING_DATA_COUNT
;
4315 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_CTX_IDX(qid
), ring
->desc_cur
);
4323 static int rt2860_tx_data(struct rt2860_softc
*sc
,
4324 struct mbuf
*m
, struct ieee80211_node
*ni
, int qid
)
4327 struct ieee80211com
*ic
;
4328 struct ieee80211vap
*vap
;
4329 const struct ieee80211_txparam
*tp
;
4330 struct rt2860_softc_node
*rni
;
4331 struct rt2860_softc_tx_ring
*ring
;
4332 struct rt2860_softc_tx_data
*data
;
4333 struct rt2860_txdesc
*desc
;
4334 struct rt2860_txwi
*txwi
;
4335 struct ieee80211_frame
*wh
;
4336 struct ieee80211_tx_ampdu
*tx_ampdu
;
4337 ieee80211_seq seqno
;
4338 struct rt2860_softc_tx_radiotap_header
*tap
;
4339 bus_dma_segment_t dma_seg
[RT2860_SOFTC_MAX_SCATTER
];
4340 u_int hdrsize
, hdrspace
;
4341 uint8_t type
, rate
, bw
, stbc
, shortgi
, mcs
, pid
, wcid
, mpdu_density
, bawin_size
, qsel
;
4342 uint16_t qos
, len
, dmalen
, mpdu_len
, dur
;
4343 int error
, hasqos
, ac
, tid
, ampdu
, mimops
, ndmasegs
, ndescs
, i
, j
;
4345 KASSERT(qid
>= 0 && qid
< RT2860_SOFTC_TX_RING_COUNT
,
4346 ("%s: Tx data: invalid qid=%d\n",
4347 device_get_nameunit(sc
->dev
), qid
));
4352 rni
= (struct rt2860_softc_node
*) ni
;
4353 tp
= ni
->ni_txparms
;
4355 ring
= &sc
->tx_ring
[qid
];
4356 desc
= &ring
->desc
[ring
->desc_cur
];
4357 data
= &ring
->data
[ring
->data_cur
];
4358 txwi
= (struct rt2860_txwi
*) (ring
->seg0
+ ring
->data_cur
* RT2860_TX_DATA_SEG0_SIZE
);
4360 wh
= mtod(m
, struct ieee80211_frame
*);
4362 type
= wh
->i_fc
[0] & IEEE80211_FC0_TYPE_MASK
;
4364 hasqos
= IEEE80211_QOS_HAS_SEQ(wh
);
4367 if (IEEE80211_HAS_ADDR4(wh
))
4368 qos
= le16toh(*(const uint16_t *)
4369 (((struct ieee80211_qosframe_addr4
*) wh
)->i_qos
));
4371 qos
= le16toh(*(const uint16_t *)
4372 (((struct ieee80211_qosframe
*) wh
)->i_qos
));
4379 if (IEEE80211_IS_MULTICAST(wh
->i_addr1
))
4380 rate
= tp
->mcastrate
;
4381 else if (m
->m_flags
& M_EAPOL
)
4382 rate
= tp
->mgmtrate
;
4383 else if (tp
->ucastrate
!= IEEE80211_FIXED_RATE_NONE
)
4384 rate
= tp
->ucastrate
;
4386 rate
= ni
->ni_txrate
;
4388 rate
&= IEEE80211_RATE_VAL
;
4390 /* fill Tx wireless info */
4392 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
4395 mcs
= rt2860_rate2mcs(rate
);
4397 if (type
== IEEE80211_FC0_TYPE_DATA
)
4398 wcid
= !IEEE80211_IS_MULTICAST(wh
->i_addr1
) ? rni
->staid
: RT2860_WCID_MCAST
;
4400 wcid
= RT2860_WCID_RESERVED
;
4402 /* calculate MPDU length without padding */
4404 hdrsize
= ieee80211_hdrsize(wh
);
4405 hdrspace
= ieee80211_hdrspace(ic
, wh
);
4406 mpdu_len
= m
->m_pkthdr
.len
- hdrspace
+ hdrsize
;
4408 memset(txwi
, 0, sizeof(struct rt2860_txwi
));
4412 /* MIMO power save */
4414 if ((ni
->ni_flags
& IEEE80211_NODE_HT
) && (ni
->ni_flags
& IEEE80211_NODE_MIMO_PS
))
4418 if (ni
->ni_flags
& IEEE80211_NODE_MIMO_RTS
)
4420 /* dynamic MIMO power save */
4422 txwi
->mpdu_density_flags
|=
4423 (RT2860_TXWI_FLAGS_MIMOPS
<< RT2860_TXWI_FLAGS_SHIFT
);
4427 /* static MIMO power save */
4442 txwi
->pid_mpdu_len
= ((htole16(pid
) & RT2860_TXWI_PID_MASK
) <<
4443 RT2860_TXWI_PID_SHIFT
) | ((htole16(mpdu_len
) & RT2860_TXWI_MPDU_LEN_MASK
) <<
4444 RT2860_TXWI_MPDU_LEN_SHIFT
);
4446 stbc
= (ic
->ic_htcaps
& IEEE80211_HTCAP_TXSTBC
) &&
4447 (ni
->ni_flags
& IEEE80211_NODE_HT
) && (ni
->ni_htcap
& IEEE80211_HTCAP_RXSTBC
);
4449 shortgi
= (vap
->iv_flags_ht
& (IEEE80211_FHT_SHORTGI20
| IEEE80211_FHT_SHORTGI40
)) &&
4450 (ni
->ni_flags
& IEEE80211_NODE_HT
) && (ni
->ni_flags
& (IEEE80211_NODE_SGI20
| IEEE80211_NODE_SGI40
));
4452 txwi
->phymode_ifs_stbc_shortgi
|=
4453 ((stbc
& RT2860_TXWI_STBC_MASK
) << RT2860_TXWI_STBC_SHIFT
) |
4454 ((shortgi
& RT2860_TXWI_SHORTGI_MASK
) << RT2860_TXWI_SHORTGI_SHIFT
);
4456 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
4458 txwi
->phymode_ifs_stbc_shortgi
|=
4459 (RT2860_TXWI_PHYMODE_HT_MIXED
<< RT2860_TXWI_PHYMODE_SHIFT
);
4463 if (ieee80211_rate2phytype(ic
->ic_rt
, rate
) != IEEE80211_T_OFDM
)
4465 txwi
->phymode_ifs_stbc_shortgi
|=
4466 (RT2860_TXWI_PHYMODE_CCK
<< RT2860_TXWI_PHYMODE_SHIFT
);
4468 if (rate
!= 2 && (ic
->ic_flags
& IEEE80211_F_SHPREAMBLE
))
4469 mcs
|= RT2860_TXWI_MCS_SHOTPRE
;
4473 txwi
->phymode_ifs_stbc_shortgi
|=
4474 (RT2860_TXWI_PHYMODE_OFDM
<< RT2860_TXWI_PHYMODE_SHIFT
);
4478 if ((ni
->ni_flags
& IEEE80211_NODE_HT
) && (ni
->ni_chw
== 40))
4479 bw
= RT2860_TXWI_BW_40
;
4481 bw
= RT2860_TXWI_BW_20
;
4483 txwi
->bw_mcs
= ((bw
& RT2860_TXWI_BW_MASK
) << RT2860_TXWI_BW_SHIFT
) |
4484 ((mcs
& RT2860_TXWI_MCS_MASK
) << RT2860_TXWI_MCS_SHIFT
);
4486 txwi
->txop
= (RT2860_TXWI_TXOP_HT
<< RT2860_TXWI_TXOP_SHIFT
);
4488 if (!IEEE80211_IS_MULTICAST(wh
->i_addr1
) &&
4489 (!hasqos
|| (qos
& IEEE80211_QOS_ACKPOLICY
) != IEEE80211_QOS_ACKPOLICY_NOACK
))
4491 txwi
->bawin_size_xflags
|=
4492 (RT2860_TXWI_XFLAGS_ACK
<< RT2860_TXWI_XFLAGS_SHIFT
);
4494 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
4496 /* preamble + plcp + signal extension + SIFS */
4498 dur
= 16 + 4 + 6 + 10;
4502 dur
= ieee80211_ack_duration(ic
->ic_rt
, rate
,
4503 ic
->ic_flags
& IEEE80211_F_SHPREAMBLE
);
4506 *(uint16_t *) wh
->i_dur
= htole16(dur
);
4509 /* check for A-MPDU */
4511 if (m
->m_flags
& M_AMPDU_MPDU
)
4513 ac
= M_WME_GETAC(m
);
4514 tid
= WME_AC_TO_TID(ac
);
4515 tx_ampdu
= &ni
->ni_tx_ampdu
[ac
];
4517 mpdu_density
= RT2860_MS(ni
->ni_htparam
, IEEE80211_HTCAP_MPDUDENSITY
);
4518 bawin_size
= tx_ampdu
->txa_wnd
;
4520 txwi
->mpdu_density_flags
|=
4521 ((mpdu_density
& RT2860_TXWI_MPDU_DENSITY_MASK
) << RT2860_TXWI_MPDU_DENSITY_SHIFT
) |
4522 (RT2860_TXWI_FLAGS_AMPDU
<< RT2860_TXWI_FLAGS_SHIFT
);
4524 txwi
->bawin_size_xflags
|=
4525 ((bawin_size
& RT2860_TXWI_BAWIN_SIZE_MASK
) << RT2860_TXWI_BAWIN_SIZE_SHIFT
);
4527 seqno
= ni
->ni_txseqs
[tid
]++;
4529 *(uint16_t *) &wh
->i_seq
[0] = htole16(seqno
<< IEEE80211_SEQ_SEQ_SHIFT
);
4538 /* ask MAC to insert timestamp into probe responses */
4540 if ((wh
->i_fc
[0] & (IEEE80211_FC0_TYPE_MASK
| IEEE80211_FC0_SUBTYPE_MASK
)) ==
4541 (IEEE80211_FC0_TYPE_MGT
| IEEE80211_FC0_SUBTYPE_PROBE_RESP
))
4542 txwi
->mpdu_density_flags
|=
4543 (RT2860_TXWI_FLAGS_TS
<< RT2860_TXWI_FLAGS_SHIFT
);
4545 if (ieee80211_radiotap_active_vap(vap
))
4549 tap
->flags
= IEEE80211_RADIOTAP_F_DATAPAD
;
4550 tap
->chan_flags
= htole32(ic
->ic_curchan
->ic_flags
);
4551 tap
->chan_freq
= htole16(ic
->ic_curchan
->ic_freq
);
4552 tap
->chan_ieee
= ic
->ic_curchan
->ic_ieee
;
4553 tap
->chan_maxpow
= 0;
4555 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
4556 tap
->rate
= mcs
| IEEE80211_RATE_MCS
;
4560 if (mcs
& RT2860_TXWI_MCS_SHOTPRE
)
4561 tap
->flags
|= IEEE80211_RADIOTAP_F_SHORTPRE
;
4564 tap
->flags
|= IEEE80211_RADIOTAP_F_SHORTGI
;
4566 if (wh
->i_fc
[1] & IEEE80211_FC1_WEP
)
4567 tap
->flags
|= IEEE80211_RADIOTAP_F_WEP
;
4569 if (wh
->i_fc
[1] & IEEE80211_FC1_WEP
)
4571 wh
->i_fc
[1] &= ~IEEE80211_FC1_WEP
;
4573 ieee80211_radiotap_tx(vap
, m
);
4575 wh
->i_fc
[1] |= IEEE80211_FC1_WEP
;
4579 ieee80211_radiotap_tx(vap
, m
);
4583 /* copy and trim 802.11 header */
4585 m_copydata(m
, 0, hdrsize
, (caddr_t
) (txwi
+ 1));
4588 error
= bus_dmamap_load_mbuf_sg(ring
->data_dma_tag
, data
->dma_map
, m
,
4589 dma_seg
, &ndmasegs
, 0);
4592 /* too many fragments, linearize */
4594 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
4595 "%s: could not load mbuf DMA map, trying to linearize mbuf: ndmasegs=%d, len=%d, error=%d\n",
4596 device_get_nameunit(sc
->dev
), ndmasegs
, m
->m_pkthdr
.len
, error
);
4598 m
= m_defrag(m
, M_DONTWAIT
);
4602 sc
->tx_defrag_packets
++;
4604 error
= bus_dmamap_load_mbuf_sg(ring
->data_dma_tag
, data
->dma_map
, m
,
4605 dma_seg
, &ndmasegs
, 0);
4608 printf("%s: could not load mbuf DMA map: ndmasegs=%d, len=%d, error=%d\n",
4609 device_get_nameunit(sc
->dev
), ndmasegs
, m
->m_pkthdr
.len
, error
);
4615 if (m
->m_pkthdr
.len
== 0)
4618 /* determine how many Tx descs are required */
4620 ndescs
= 1 + ndmasegs
/ 2;
4621 if ((ring
->desc_queued
+ ndescs
) > (RT2860_SOFTC_TX_RING_DESC_COUNT
- 2))
4623 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
4624 "%s: there are not enough Tx descs\n",
4625 device_get_nameunit(sc
->dev
));
4627 sc
->no_tx_desc_avail
++;
4629 bus_dmamap_unload(ring
->data_dma_tag
, data
->dma_map
);
4637 /* set up Tx descs */
4639 /* first segment is Tx wireless info and 802.11 header */
4641 len
= sizeof(struct rt2860_txwi
) + hdrsize
;
4643 /* align end on a 4-bytes boundary */
4645 dmalen
= (len
+ 3) & ~ 3;
4647 memset((caddr_t
) txwi
+ len
, 0, dmalen
- len
);
4649 qsel
= RT2860_TXDESC_QSEL_EDCA
;
4651 desc
->sdp0
= htole32(ring
->seg0_phys_addr
+ ring
->data_cur
* RT2860_TX_DATA_SEG0_SIZE
);
4652 desc
->sdl0
= htole16(dmalen
);
4653 desc
->qsel_flags
= (qsel
<< RT2860_TXDESC_QSEL_SHIFT
);
4655 /* set up payload segments */
4657 for (i
= ndmasegs
, j
= 0; i
>= 2; i
-= 2)
4659 desc
->sdp1
= htole32(dma_seg
[j
].ds_addr
);
4660 desc
->sdl1
= htole16(dma_seg
[j
].ds_len
);
4662 ring
->desc_queued
++;
4663 ring
->desc_cur
= (ring
->desc_cur
+ 1) % RT2860_SOFTC_TX_RING_DESC_COUNT
;
4667 desc
= &ring
->desc
[ring
->desc_cur
];
4669 desc
->sdp0
= htole32(dma_seg
[j
].ds_addr
);
4670 desc
->sdl0
= htole16(dma_seg
[j
].ds_len
);
4671 desc
->qsel_flags
= (qsel
<< RT2860_TXDESC_QSEL_SHIFT
);
4676 /* finalize last payload segment */
4680 desc
->sdp1
= htole32(dma_seg
[j
].ds_addr
);
4681 desc
->sdl1
= htole16(dma_seg
[j
].ds_len
| RT2860_TXDESC_SDL1_LASTSEG
);
4685 desc
->sdl0
|= htole16(RT2860_TXDESC_SDL0_LASTSEG
);
4689 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
4690 "%s: sending data: qid=%d, hdrsize=%d, hdrspace=%d, len=%d, "
4691 "bw=%d, stbc=%d, shortgi=%d, mcs=%d, wcid=0x%02x, ampdu=%d, mimops=%d, DMA len=%d, ndmasegs=%d, DMA ds_len=%d/%d/%d/%d/%d\n",
4692 device_get_nameunit(sc
->dev
),
4693 qid
, hdrsize
, hdrspace
, m
->m_pkthdr
.len
+ hdrsize
,
4694 bw
, stbc
, shortgi
, mcs
, wcid
, ampdu
, mimops
, dmalen
, ndmasegs
,
4695 (int) dma_seg
[0].ds_len
, (int) dma_seg
[1].ds_len
, (int) dma_seg
[2].ds_len
, (int) dma_seg
[3].ds_len
, (int) dma_seg
[4].ds_len
);
4697 bus_dmamap_sync(ring
->seg0_dma_tag
, ring
->seg0_dma_map
,
4698 BUS_DMASYNC_PREWRITE
);
4699 bus_dmamap_sync(ring
->data_dma_tag
, data
->dma_map
,
4700 BUS_DMASYNC_PREWRITE
);
4701 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
4702 BUS_DMASYNC_PREWRITE
);
4704 ring
->desc_queued
++;
4705 ring
->desc_cur
= (ring
->desc_cur
+ 1) % RT2860_SOFTC_TX_RING_DESC_COUNT
;
4707 ring
->data_queued
++;
4708 ring
->data_cur
= (ring
->data_cur
+ 1) % RT2860_SOFTC_TX_RING_DATA_COUNT
;
4712 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_CTX_IDX(qid
), ring
->desc_cur
);
4720 static int rt2860_tx_raw(struct rt2860_softc
*sc
,
4721 struct mbuf
*m
, struct ieee80211_node
*ni
,
4722 const struct ieee80211_bpf_params
*params
)
4724 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
4726 device_get_nameunit(sc
->dev
));
4734 static void rt2860_intr(void *arg
)
4736 struct rt2860_softc
*sc
;
4743 /* acknowledge interrupts */
4745 status
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_INT_STATUS
);
4746 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_INT_STATUS
, status
);
4748 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4749 "%s: interrupt: status = 0x%08x\n",
4750 device_get_nameunit(sc
->dev
), status
);
4752 if (status
== 0xffffffff || /* device likely went away */
4753 status
== 0) /* not for us */
4758 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
4761 if (status
& RT2860_REG_INT_TX_COHERENT
)
4762 rt2860_tx_coherent_intr(sc
);
4764 if (status
& RT2860_REG_INT_RX_COHERENT
)
4765 rt2860_rx_coherent_intr(sc
);
4767 if (status
& RT2860_REG_INT_TXRX_COHERENT
)
4768 rt2860_txrx_coherent_intr(sc
);
4770 if (status
& RT2860_REG_INT_FIFO_STA_FULL
)
4771 rt2860_fifo_sta_full_intr(sc
);
4773 if (status
& RT2860_REG_INT_TX_MGMT_DONE
)
4774 rt2860_tx_intr(sc
, 5);
4776 if (status
& RT2860_REG_INT_RX_DONE
)
4779 if (status
& RT2860_REG_INT_RX_DELAY_DONE
)
4780 rt2860_rx_delay_intr(sc
);
4782 if (status
& RT2860_REG_INT_TX_HCCA_DONE
)
4783 rt2860_tx_intr(sc
, 4);
4785 if (status
& RT2860_REG_INT_TX_AC3_DONE
)
4786 rt2860_tx_intr(sc
, 3);
4788 if (status
& RT2860_REG_INT_TX_AC2_DONE
)
4789 rt2860_tx_intr(sc
, 2);
4791 if (status
& RT2860_REG_INT_TX_AC1_DONE
)
4792 rt2860_tx_intr(sc
, 1);
4794 if (status
& RT2860_REG_INT_TX_AC0_DONE
)
4795 rt2860_tx_intr(sc
, 0);
4797 if (status
& RT2860_REG_INT_TX_DELAY_DONE
)
4798 rt2860_tx_delay_intr(sc
);
4800 if (status
& RT2860_REG_INT_PRE_TBTT
)
4801 rt2860_pre_tbtt_intr(sc
);
4803 if (status
& RT2860_REG_INT_TBTT
)
4804 rt2860_tbtt_intr(sc
);
4806 if (status
& RT2860_REG_INT_MCU_CMD
)
4807 rt2860_mcu_cmd_intr(sc
);
4809 if (status
& RT2860_REG_INT_AUTO_WAKEUP
)
4810 rt2860_auto_wakeup_intr(sc
);
4812 if (status
& RT2860_REG_INT_GP_TIMER
)
4813 rt2860_gp_timer_intr(sc
);
4817 * rt2860_tx_coherent_intr
4819 static void rt2860_tx_coherent_intr(struct rt2860_softc
*sc
)
4824 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4825 "%s: Tx coherent interrupt\n",
4826 device_get_nameunit(sc
->dev
));
4828 sc
->tx_coherent_interrupts
++;
4830 /* restart DMA engine */
4832 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
);
4834 tmp
&= ~(RT2860_REG_TX_WB_DDONE
|
4835 RT2860_REG_RX_DMA_ENABLE
|
4836 RT2860_REG_TX_DMA_ENABLE
);
4838 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
, tmp
);
4840 /* init Tx rings (4 EDCAs + HCCA + MGMT) */
4842 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
4843 rt2860_reset_tx_ring(sc
, &sc
->tx_ring
[i
]);
4845 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
4847 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_BASE_PTR(i
),
4848 sc
->tx_ring
[i
].desc_phys_addr
);
4849 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_MAX_CNT(i
),
4850 RT2860_SOFTC_TX_RING_DESC_COUNT
);
4851 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_CTX_IDX(i
), 0);
4856 rt2860_reset_rx_ring(sc
, &sc
->rx_ring
);
4858 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_BASE_PTR
,
4859 sc
->rx_ring
.desc_phys_addr
);
4860 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_MAX_CNT
,
4861 RT2860_SOFTC_RX_RING_DATA_COUNT
);
4862 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_CALC_IDX
,
4863 RT2860_SOFTC_RX_RING_DATA_COUNT
- 1);
4865 rt2860_txrx_enable(sc
);
4869 * rt2860_rx_coherent_intr
4871 static void rt2860_rx_coherent_intr(struct rt2860_softc
*sc
)
4876 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4877 "%s: Rx coherent interrupt\n",
4878 device_get_nameunit(sc
->dev
));
4880 sc
->rx_coherent_interrupts
++;
4882 /* restart DMA engine */
4884 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
);
4886 tmp
&= ~(RT2860_REG_TX_WB_DDONE
|
4887 RT2860_REG_RX_DMA_ENABLE
|
4888 RT2860_REG_TX_DMA_ENABLE
);
4890 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
, tmp
);
4892 /* init Tx rings (4 EDCAs + HCCA + MGMT) */
4894 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
4895 rt2860_reset_tx_ring(sc
, &sc
->tx_ring
[i
]);
4897 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
4899 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_BASE_PTR(i
),
4900 sc
->tx_ring
[i
].desc_phys_addr
);
4901 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_MAX_CNT(i
),
4902 RT2860_SOFTC_TX_RING_DESC_COUNT
);
4903 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_CTX_IDX(i
), 0);
4908 rt2860_reset_rx_ring(sc
, &sc
->rx_ring
);
4910 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_BASE_PTR
,
4911 sc
->rx_ring
.desc_phys_addr
);
4912 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_MAX_CNT
,
4913 RT2860_SOFTC_RX_RING_DATA_COUNT
);
4914 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_CALC_IDX
,
4915 RT2860_SOFTC_RX_RING_DATA_COUNT
- 1);
4917 rt2860_txrx_enable(sc
);
4921 * rt2860_txrx_coherent_intr
4923 static void rt2860_txrx_coherent_intr(struct rt2860_softc
*sc
)
4928 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4929 "%s: Tx/Rx coherent interrupt\n",
4930 device_get_nameunit(sc
->dev
));
4932 sc
->txrx_coherent_interrupts
++;
4934 /* restart DMA engine */
4936 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
);
4938 tmp
&= ~(RT2860_REG_TX_WB_DDONE
|
4939 RT2860_REG_RX_DMA_ENABLE
|
4940 RT2860_REG_TX_DMA_ENABLE
);
4942 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
, tmp
);
4944 /* init Tx rings (4 EDCAs + HCCA + MGMT) */
4946 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
4947 rt2860_reset_tx_ring(sc
, &sc
->tx_ring
[i
]);
4949 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
4951 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_BASE_PTR(i
),
4952 sc
->tx_ring
[i
].desc_phys_addr
);
4953 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_MAX_CNT(i
),
4954 RT2860_SOFTC_TX_RING_DESC_COUNT
);
4955 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_CTX_IDX(i
), 0);
4960 rt2860_reset_rx_ring(sc
, &sc
->rx_ring
);
4962 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_BASE_PTR
,
4963 sc
->rx_ring
.desc_phys_addr
);
4964 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_MAX_CNT
,
4965 RT2860_SOFTC_RX_RING_DATA_COUNT
);
4966 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_CALC_IDX
,
4967 RT2860_SOFTC_RX_RING_DATA_COUNT
- 1);
4969 rt2860_txrx_enable(sc
);
4973 * rt2860_fifo_sta_full_intr
4975 static void rt2860_fifo_sta_full_intr(struct rt2860_softc
*sc
)
4977 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4978 "%s: FIFO statistic full interrupt\n",
4979 device_get_nameunit(sc
->dev
));
4981 sc
->fifo_sta_full_interrupts
++;
4983 RT2860_SOFTC_LOCK(sc
);
4985 if (!(sc
->intr_disable_mask
& RT2860_REG_INT_FIFO_STA_FULL
))
4987 rt2860_intr_disable(sc
, RT2860_REG_INT_FIFO_STA_FULL
);
4989 taskqueue_enqueue(sc
->taskqueue
, &sc
->fifo_sta_full_task
);
4992 sc
->intr_pending_mask
|= RT2860_REG_INT_FIFO_STA_FULL
;
4994 RT2860_SOFTC_UNLOCK(sc
);
5000 static void rt2860_rx_intr(struct rt2860_softc
*sc
)
5002 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
5003 "%s: Rx interrupt\n",
5004 device_get_nameunit(sc
->dev
));
5006 sc
->rx_interrupts
++;
5008 RT2860_SOFTC_LOCK(sc
);
5010 if (!(sc
->intr_disable_mask
& RT2860_REG_INT_RX_DONE
))
5012 rt2860_intr_disable(sc
, RT2860_REG_INT_RX_DONE
);
5014 taskqueue_enqueue(sc
->taskqueue
, &sc
->rx_done_task
);
5017 sc
->intr_pending_mask
|= RT2860_REG_INT_RX_DONE
;
5019 RT2860_SOFTC_UNLOCK(sc
);
5023 * rt2860_rx_delay_intr
5025 static void rt2860_rx_delay_intr(struct rt2860_softc
*sc
)
5027 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
5028 "%s: Rx delay interrupt\n",
5029 device_get_nameunit(sc
->dev
));
5031 sc
->rx_delay_interrupts
++;
5037 static void rt2860_tx_intr(struct rt2860_softc
*sc
, int qid
)
5039 KASSERT(qid
>= 0 && qid
< RT2860_SOFTC_TX_RING_COUNT
,
5040 ("%s: Tx interrupt: invalid qid=%d\n",
5041 device_get_nameunit(sc
->dev
), qid
));
5043 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
5044 "%s: Tx interrupt: qid=%d\n",
5045 device_get_nameunit(sc
->dev
), qid
);
5047 sc
->tx_interrupts
[qid
]++;
5049 RT2860_SOFTC_LOCK(sc
);
5051 if (!(sc
->intr_disable_mask
& (RT2860_REG_INT_TX_AC0_DONE
<< qid
)))
5053 rt2860_intr_disable(sc
, (RT2860_REG_INT_TX_AC0_DONE
<< qid
));
5055 taskqueue_enqueue(sc
->taskqueue
, &sc
->tx_done_task
);
5058 sc
->intr_pending_mask
|= (RT2860_REG_INT_TX_AC0_DONE
<< qid
);
5060 RT2860_SOFTC_UNLOCK(sc
);
5064 * rt2860_tx_delay_intr
5066 static void rt2860_tx_delay_intr(struct rt2860_softc
*sc
)
5068 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
5069 "%s: Tx delay interrupt\n",
5070 device_get_nameunit(sc
->dev
));
5072 sc
->tx_delay_interrupts
++;
5076 * rt2860_pre_tbtt_intr
5078 static void rt2860_pre_tbtt_intr(struct rt2860_softc
*sc
)
5080 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
5081 "%s: Pre-TBTT interrupt\n",
5082 device_get_nameunit(sc
->dev
));
5084 sc
->pre_tbtt_interrupts
++;
5090 static void rt2860_tbtt_intr(struct rt2860_softc
*sc
)
5092 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
5093 "%s: TBTT interrupt\n",
5094 device_get_nameunit(sc
->dev
));
5096 sc
->tbtt_interrupts
++;
5100 * rt2860_mcu_cmd_intr
5102 static void rt2860_mcu_cmd_intr(struct rt2860_softc
*sc
)
5104 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
5105 "%s: MCU command interrupt\n",
5106 device_get_nameunit(sc
->dev
));
5108 sc
->mcu_cmd_interrupts
++;
5112 * rt2860_auto_wakeup_intr
5114 static void rt2860_auto_wakeup_intr(struct rt2860_softc
*sc
)
5116 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
5117 "%s: auto wakeup interrupt\n",
5118 device_get_nameunit(sc
->dev
));
5120 sc
->auto_wakeup_interrupts
++;
5124 * rt2860_gp_timer_intr
5126 static void rt2860_gp_timer_intr(struct rt2860_softc
*sc
)
5128 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
5129 "%s: GP timer interrupt\n",
5130 device_get_nameunit(sc
->dev
));
5132 sc
->gp_timer_interrupts
++;
5136 * rt2860_rx_done_task
5138 static void rt2860_rx_done_task(void *context
, int pending
)
5140 struct rt2860_softc
*sc
;
5147 RT2860_DPRINTF(sc
, RT2860_DEBUG_RX
,
5148 "%s: Rx done task\n",
5149 device_get_nameunit(sc
->dev
));
5151 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
5154 sc
->intr_pending_mask
&= ~RT2860_REG_INT_RX_DONE
;
5156 again
= rt2860_rx_eof(sc
, sc
->rx_process_limit
);
5158 RT2860_SOFTC_LOCK(sc
);
5160 if ((sc
->intr_pending_mask
& RT2860_REG_INT_RX_DONE
) || again
)
5162 RT2860_DPRINTF(sc
, RT2860_DEBUG_RX
,
5163 "%s: Rx done task: scheduling again\n",
5164 device_get_nameunit(sc
->dev
));
5166 taskqueue_enqueue(sc
->taskqueue
, &sc
->rx_done_task
);
5170 rt2860_intr_enable(sc
, RT2860_REG_INT_RX_DONE
);
5173 RT2860_SOFTC_UNLOCK(sc
);
5177 * rt2860_tx_done_task
5179 static void rt2860_tx_done_task(void *context
, int pending
)
5181 struct rt2860_softc
*sc
;
5189 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
5190 "%s: Tx done task\n",
5191 device_get_nameunit(sc
->dev
));
5193 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
5196 for (i
= RT2860_SOFTC_TX_RING_COUNT
- 1; i
>= 0; i
--)
5198 if (sc
->intr_pending_mask
& (RT2860_REG_INT_TX_AC0_DONE
<< i
))
5200 sc
->intr_pending_mask
&= ~(RT2860_REG_INT_TX_AC0_DONE
<< i
);
5202 rt2860_tx_eof(sc
, &sc
->tx_ring
[i
]);
5208 ifp
->if_drv_flags
&= ~IFF_DRV_OACTIVE
;
5210 intr_mask
= (RT2860_REG_INT_TX_MGMT_DONE
|
5211 RT2860_REG_INT_TX_HCCA_DONE
|
5212 RT2860_REG_INT_TX_AC3_DONE
|
5213 RT2860_REG_INT_TX_AC2_DONE
|
5214 RT2860_REG_INT_TX_AC1_DONE
|
5215 RT2860_REG_INT_TX_AC0_DONE
);
5217 RT2860_SOFTC_LOCK(sc
);
5219 rt2860_intr_enable(sc
, ~sc
->intr_pending_mask
&
5220 (sc
->intr_disable_mask
& intr_mask
));
5222 if (sc
->intr_pending_mask
& intr_mask
)
5224 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
5225 "%s: Tx done task: scheduling again\n",
5226 device_get_nameunit(sc
->dev
));
5228 taskqueue_enqueue(sc
->taskqueue
, &sc
->tx_done_task
);
5231 RT2860_SOFTC_UNLOCK(sc
);
5235 * rt2860_fifo_sta_full_task
5237 static void rt2860_fifo_sta_full_task(void *context
, int pending
)
5239 struct rt2860_softc
*sc
;
5245 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATS
,
5246 "%s: FIFO statistic full task\n",
5247 device_get_nameunit(sc
->dev
));
5249 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
5252 sc
->intr_pending_mask
&= ~RT2860_REG_INT_FIFO_STA_FULL
;
5254 rt2860_drain_fifo_stats(sc
);
5256 RT2860_SOFTC_LOCK(sc
);
5258 if (sc
->intr_pending_mask
& RT2860_REG_INT_FIFO_STA_FULL
)
5260 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATS
,
5261 "%s: FIFO statistic full task: scheduling again\n",
5262 device_get_nameunit(sc
->dev
));
5264 taskqueue_enqueue(sc
->taskqueue
, &sc
->fifo_sta_full_task
);
5268 rt2860_intr_enable(sc
, RT2860_REG_INT_FIFO_STA_FULL
);
5271 RT2860_SOFTC_UNLOCK(sc
);
5275 * rt2860_periodic_task
5277 static void rt2860_periodic_task(void *context
, int pending
)
5279 struct rt2860_softc
*sc
;
5281 struct ieee80211com
*ic
;
5282 struct ieee80211vap
*vap
;
5287 vap
= TAILQ_FIRST(&ic
->ic_vaps
);
5289 RT2860_DPRINTF(sc
, RT2860_DEBUG_PERIODIC
,
5290 "%s: periodic task: round=%lu\n",
5291 device_get_nameunit(sc
->dev
), sc
->periodic_round
);
5293 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
5296 RT2860_SOFTC_LOCK(sc
);
5298 sc
->periodic_round
++;
5300 rt2860_update_stats(sc
);
5302 if ((sc
->periodic_round
% 10) == 0)
5304 rt2860_bbp_tuning(sc
);
5306 rt2860_update_raw_counters(sc
);
5308 rt2860_watchdog(sc
);
5310 if (vap
!= NULL
&& vap
->iv_opmode
!= IEEE80211_M_MONITOR
&& vap
->iv_state
== IEEE80211_S_RUN
)
5312 if (vap
->iv_opmode
== IEEE80211_M_STA
)
5313 rt2860_amrr_update_iter_func(vap
, vap
->iv_bss
);
5315 ieee80211_iterate_nodes(&ic
->ic_sta
, rt2860_amrr_update_iter_func
, vap
);
5319 RT2860_SOFTC_UNLOCK(sc
);
5321 callout_reset(&sc
->periodic_ch
, hz
/ 10, rt2860_periodic
, sc
);
5327 static int rt2860_rx_eof(struct rt2860_softc
*sc
, int limit
)
5330 struct ieee80211com
*ic
;
5331 struct ieee80211_frame
*wh
;
5332 struct ieee80211_node
*ni
;
5333 struct rt2860_softc_node
*rni
;
5334 struct rt2860_softc_rx_radiotap_header
*tap
;
5335 struct rt2860_softc_rx_ring
*ring
;
5336 struct rt2860_rxdesc
*desc
;
5337 struct rt2860_softc_rx_data
*data
;
5338 struct rt2860_rxwi
*rxwi
;
5339 struct mbuf
*m
, *mnew
;
5340 bus_dma_segment_t segs
[1];
5341 bus_dmamap_t dma_map
;
5342 uint32_t index
, desc_flags
;
5343 uint8_t cipher_err
, rssi
, ant
, phymode
, bw
, shortgi
, mcs
, keyidx
;
5345 int error
, nsegs
, len
, ampdu
, amsdu
, rssi_dbm_rel
, nframes
, i
;
5349 ring
= &sc
->rx_ring
;
5355 index
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_RX_DRX_IDX
);
5356 if (ring
->cur
== index
)
5359 desc
= &ring
->desc
[ring
->cur
];
5360 desc_flags
= le32toh(desc
->flags
);
5361 data
= &ring
->data
[ring
->cur
];
5363 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
5364 BUS_DMASYNC_POSTREAD
| BUS_DMASYNC_POSTWRITE
);
5366 if (!(desc
->sdl0
& htole16(RT2860_RXDESC_SDL0_DDONE
)))
5371 mnew
= m_getjcl(M_DONTWAIT
, MT_DATA
, M_PKTHDR
, MJUMPAGESIZE
);
5374 sc
->rx_mbuf_alloc_errors
++;
5379 mnew
->m_len
= mnew
->m_pkthdr
.len
= MJUMPAGESIZE
;
5381 error
= bus_dmamap_load_mbuf_sg(ring
->data_dma_tag
, ring
->spare_dma_map
,
5382 mnew
, segs
, &nsegs
, BUS_DMA_NOWAIT
);
5385 RT2860_DPRINTF(sc
, RT2860_DEBUG_RX
,
5386 "%s: could not load Rx mbuf DMA map: error=%d, nsegs=%d\n",
5387 device_get_nameunit(sc
->dev
), error
, nsegs
);
5391 sc
->rx_mbuf_dmamap_errors
++;
5397 KASSERT(nsegs
== 1, ("%s: too many DMA segments",
5398 device_get_nameunit(sc
->dev
)));
5400 bus_dmamap_sync(ring
->data_dma_tag
, data
->dma_map
,
5401 BUS_DMASYNC_POSTREAD
);
5402 bus_dmamap_unload(ring
->data_dma_tag
, data
->dma_map
);
5404 dma_map
= data
->dma_map
;
5405 data
->dma_map
= ring
->spare_dma_map
;
5406 ring
->spare_dma_map
= dma_map
;
5408 bus_dmamap_sync(ring
->data_dma_tag
, data
->dma_map
,
5409 BUS_DMASYNC_PREREAD
);
5414 desc
->sdp0
= htole32(segs
[0].ds_addr
);
5416 /* get Rx wireless info */
5418 rxwi
= mtod(m
, struct rt2860_rxwi
*);
5419 len
= (le16toh(rxwi
->tid_size
) >> RT2860_RXWI_SIZE_SHIFT
) &
5420 RT2860_RXWI_SIZE_MASK
;
5422 /* check for L2 padding between IEEE 802.11 frame header and body */
5424 if (desc_flags
& RT2860_RXDESC_FLAGS_L2PAD
)
5426 RT2860_DPRINTF(sc
, RT2860_DEBUG_RX
,
5427 "%s: L2 padding: len=%d\n",
5428 device_get_nameunit(sc
->dev
), len
);
5433 m
->m_pkthdr
.rcvif
= ifp
;
5434 m
->m_data
= (caddr_t
) (rxwi
+ 1);
5435 m
->m_pkthdr
.len
= m
->m_len
= len
;
5437 /* check for crc errors */
5439 if (desc_flags
& RT2860_RXDESC_FLAGS_CRC_ERR
)
5441 RT2860_DPRINTF(sc
, RT2860_DEBUG_RX
,
5442 "%s: rxdesc: crc error\n",
5443 device_get_nameunit(sc
->dev
));
5447 if (!(ifp
->if_flags
& IFF_PROMISC
))
5454 wh
= (struct ieee80211_frame
*) (rxwi
+ 1);
5456 /* check for cipher errors */
5458 if (desc_flags
& RT2860_RXDESC_FLAGS_DECRYPTED
)
5460 cipher_err
= ((desc_flags
>> RT2860_RXDESC_FLAGS_CIPHER_ERR_SHIFT
) &
5461 RT2860_RXDESC_FLAGS_CIPHER_ERR_MASK
);
5462 if (cipher_err
== RT2860_RXDESC_FLAGS_CIPHER_ERR_NONE
)
5464 if (wh
->i_fc
[1] & IEEE80211_FC1_WEP
)
5465 wh
->i_fc
[1] &= ~IEEE80211_FC1_WEP
;
5467 m
->m_flags
|= M_WEP
;
5469 sc
->rx_cipher_no_errors
++;
5473 RT2860_DPRINTF(sc
, RT2860_DEBUG_RX
,
5474 "%s: rxdesc: cipher error=0x%02x\n",
5475 device_get_nameunit(sc
->dev
), cipher_err
);
5477 if (cipher_err
== RT2860_RXDESC_FLAGS_CIPHER_ERR_ICV
)
5478 sc
->rx_cipher_icv_errors
++;
5479 else if (cipher_err
== RT2860_RXDESC_FLAGS_CIPHER_ERR_MIC
)
5480 sc
->rx_cipher_mic_errors
++;
5481 else if (cipher_err
== RT2860_RXDESC_FLAGS_CIPHER_ERR_INVALID_KEY
)
5482 sc
->rx_cipher_invalid_key_errors
++;
5484 if ((cipher_err
== RT2860_RXDESC_FLAGS_CIPHER_ERR_MIC
) &&
5485 (desc_flags
& RT2860_RXDESC_FLAGS_MYBSS
))
5487 ni
= ieee80211_find_rxnode(ic
, (const struct ieee80211_frame_min
*) wh
);
5490 keyidx
= (rxwi
->udf_bssidx_keyidx
>> RT2860_RXWI_KEYIDX_SHIFT
) &
5491 RT2860_RXWI_KEYIDX_MASK
;
5493 ieee80211_notify_michael_failure(ni
->ni_vap
, wh
, keyidx
);
5495 ieee80211_free_node(ni
);
5501 if (!(ifp
->if_flags
& IFF_PROMISC
))
5510 if (wh
->i_fc
[1] & IEEE80211_FC1_WEP
)
5512 RT2860_DPRINTF(sc
, RT2860_DEBUG_RX
,
5513 "%s: rxdesc: not decrypted but protected flag set\n",
5514 device_get_nameunit(sc
->dev
));
5518 if (!(ifp
->if_flags
& IFF_PROMISC
))
5526 /* check for A-MPDU */
5528 if (desc_flags
& RT2860_RXDESC_FLAGS_AMPDU
)
5530 m
->m_flags
|= M_AMPDU
;
5541 /* check for A-MSDU */
5543 if (desc_flags
& RT2860_RXDESC_FLAGS_AMSDU
)
5554 ant
= rt2860_maxrssi_rxpath(sc
, rxwi
);
5555 rssi
= rxwi
->rssi
[ant
];
5556 rssi_dbm
= rt2860_rssi2dbm(sc
, rssi
, ant
);
5557 phymode
= ((rxwi
->phymode_stbc_shortgi
>> RT2860_RXWI_PHYMODE_SHIFT
) &
5558 RT2860_RXWI_PHYMODE_MASK
);
5559 bw
= ((rxwi
->bw_mcs
>> RT2860_RXWI_BW_SHIFT
) & RT2860_RXWI_BW_MASK
);
5560 shortgi
= ((rxwi
->phymode_stbc_shortgi
>> RT2860_RXWI_SHORTGI_SHIFT
) &
5561 RT2860_RXWI_SHORTGI_MASK
);
5562 mcs
= ((rxwi
->bw_mcs
>> RT2860_RXWI_MCS_SHIFT
) & RT2860_RXWI_MCS_MASK
);
5564 if (ieee80211_radiotap_active(ic
))
5568 tap
->flags
= (desc_flags
& RT2860_RXDESC_FLAGS_L2PAD
) ? IEEE80211_RADIOTAP_F_DATAPAD
: 0;
5569 tap
->dbm_antsignal
= rssi_dbm
;
5570 tap
->dbm_antnoise
= RT2860_NOISE_FLOOR
;
5572 tap
->antsignal
= rssi
;
5573 tap
->chan_flags
= htole32(ic
->ic_curchan
->ic_flags
);
5574 tap
->chan_freq
= htole16(ic
->ic_curchan
->ic_freq
);
5575 tap
->chan_ieee
= ic
->ic_curchan
->ic_ieee
;
5576 tap
->chan_maxpow
= 0;
5578 if (phymode
== RT2860_TXWI_PHYMODE_HT_MIXED
|| phymode
== RT2860_TXWI_PHYMODE_HT_GF
)
5579 tap
->rate
= mcs
| IEEE80211_RATE_MCS
;
5581 tap
->rate
= rt2860_rxrate(rxwi
);
5583 if (desc_flags
& RT2860_RXDESC_FLAGS_CRC_ERR
)
5584 tap
->flags
|= IEEE80211_RADIOTAP_F_BADFCS
;
5586 if (desc_flags
& RT2860_RXDESC_FLAGS_FRAG
)
5587 tap
->flags
|= IEEE80211_RADIOTAP_F_FRAG
;
5589 if (rxwi
->bw_mcs
& RT2860_RXWI_MCS_SHOTPRE
)
5590 tap
->flags
|= IEEE80211_RADIOTAP_F_SHORTPRE
;
5592 if ((desc_flags
& RT2860_RXDESC_FLAGS_DECRYPTED
) ||
5593 (wh
->i_fc
[1] & IEEE80211_FC1_WEP
))
5594 tap
->flags
|= IEEE80211_RADIOTAP_F_WEP
;
5597 tap
->flags
|= IEEE80211_RADIOTAP_F_SHORTGI
;
5601 * net80211 assumes that RSSI data are in the range [-127..127] and
5602 * in .5 dBm units relative to the current noise floor
5605 rssi_dbm_rel
= (rssi_dbm
- RT2860_NOISE_FLOOR
) * 2;
5606 if (rssi_dbm_rel
> 127)
5609 RT2860_DPRINTF(sc
, RT2860_DEBUG_RX
,
5610 "%s: received frame: len=%d, phymode=%d, bw=%d, shortgi=%d, mcs=%d, "
5611 "ant=%d, rssi=%d/%d/%d, snr=%d/%d, wcid=0x%02x, ampdu=%d, amsdu=%d, "
5612 "rssi_dbm=%d, rssi_dbm_rel=%d\n",
5613 device_get_nameunit(sc
->dev
),
5614 len
, phymode
, bw
, shortgi
, mcs
,
5615 ant
, rxwi
->rssi
[0], rxwi
->rssi
[1], rxwi
->rssi
[2],
5616 rxwi
->snr
[0], rxwi
->snr
[1],
5617 rxwi
->wcid
, ampdu
, amsdu
, rssi_dbm
, rssi_dbm_rel
);
5619 ni
= ieee80211_find_rxnode(ic
, (struct ieee80211_frame_min
*) wh
);
5622 rni
= (struct rt2860_softc_node
*) ni
;
5624 for (i
= 0; i
< RT2860_SOFTC_RSSI_COUNT
; i
++)
5626 rni
->last_rssi
[i
] = rxwi
->rssi
[i
];
5627 rni
->last_rssi_dbm
[i
] = rt2860_rssi2dbm(sc
, rxwi
->rssi
[i
], i
);
5630 ieee80211_input(ni
, m
, rssi_dbm_rel
, RT2860_NOISE_FLOOR
);
5631 ieee80211_free_node(ni
);
5635 ieee80211_input_all(ic
, m
, rssi_dbm_rel
, RT2860_NOISE_FLOOR
);
5640 desc
->sdl0
&= ~htole16(RT2860_RXDESC_SDL0_DDONE
);
5642 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
5643 BUS_DMASYNC_PREREAD
| BUS_DMASYNC_PREWRITE
);
5645 ring
->cur
= (ring
->cur
+ 1) % RT2860_SOFTC_RX_RING_DATA_COUNT
;
5651 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_CALC_IDX
,
5652 RT2860_SOFTC_RX_RING_DATA_COUNT
- 1);
5654 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_CALC_IDX
,
5657 RT2860_DPRINTF(sc
, RT2860_DEBUG_RX
,
5658 "%s: Rx eof: nframes=%d\n",
5659 device_get_nameunit(sc
->dev
), nframes
);
5661 sc
->rx_packets
+= nframes
;
5663 return (limit
== 0);
5669 static void rt2860_tx_eof(struct rt2860_softc
*sc
,
5670 struct rt2860_softc_tx_ring
*ring
)
5673 struct rt2860_txdesc
*desc
;
5674 struct rt2860_softc_tx_data
*data
;
5676 int ndescs
, nframes
;
5685 index
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_TX_DTX_IDX(ring
->qid
));
5686 if (ring
->desc_next
== index
)
5691 rt2860_drain_fifo_stats(sc
);
5693 desc
= &ring
->desc
[ring
->desc_next
];
5695 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
5696 BUS_DMASYNC_POSTREAD
| BUS_DMASYNC_POSTWRITE
);
5698 if (desc
->sdl0
& htole16(RT2860_TXDESC_SDL0_LASTSEG
) ||
5699 desc
->sdl1
& htole16(RT2860_TXDESC_SDL1_LASTSEG
))
5703 data
= &ring
->data
[ring
->data_next
];
5705 if (data
->m
->m_flags
& M_TXCB
)
5706 ieee80211_process_callback(data
->ni
, data
->m
, 0);
5708 bus_dmamap_sync(ring
->data_dma_tag
, data
->dma_map
,
5709 BUS_DMASYNC_POSTWRITE
);
5710 bus_dmamap_unload(ring
->data_dma_tag
, data
->dma_map
);
5714 ieee80211_free_node(data
->ni
);
5721 RT2860_SOFTC_LOCK(sc
);
5723 ring
->data_queued
--;
5724 ring
->data_next
= (ring
->data_next
+ 1) % RT2860_SOFTC_TX_RING_DATA_COUNT
;
5726 RT2860_SOFTC_UNLOCK(sc
);
5729 desc
->sdl0
&= ~htole16(RT2860_TXDESC_SDL0_DDONE
);
5731 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
5732 BUS_DMASYNC_PREREAD
| BUS_DMASYNC_PREWRITE
);
5734 RT2860_SOFTC_LOCK(sc
);
5736 ring
->desc_queued
--;
5737 ring
->desc_next
= (ring
->desc_next
+ 1) % RT2860_SOFTC_TX_RING_DESC_COUNT
;
5739 RT2860_SOFTC_UNLOCK(sc
);
5742 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
5743 "%s: Tx eof: qid=%d, ndescs=%d, nframes=%d\n",
5744 device_get_nameunit(sc
->dev
), ring
->qid
, ndescs
, nframes
);
5748 * rt2860_update_stats
5750 static void rt2860_update_stats(struct rt2860_softc
*sc
)
5753 struct ieee80211com
*ic
;
5755 int beacons
, noretryok
, retryok
, failed
, underflows
, zerolen
;
5760 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATS
,
5761 "%s: update statistic\n",
5762 device_get_nameunit(sc
->dev
));
5764 rt2860_drain_fifo_stats(sc
);
5766 /* read and clear Tx statistic registers */
5768 rt2860_io_mac_read_multi(sc
, RT2860_REG_TX_STA_CNT0
,
5769 stacnt
, sizeof(stacnt
));
5771 stacnt
[0] = le32toh(stacnt
[0]);
5772 stacnt
[1] = le32toh(stacnt
[1]);
5773 stacnt
[2] = le32toh(stacnt
[2]);
5775 beacons
= stacnt
[0] >> 16;
5776 noretryok
= stacnt
[1] & 0xffff;
5777 retryok
= stacnt
[1] >> 16;
5778 failed
= stacnt
[0] & 0xffff;
5779 underflows
= stacnt
[2] >> 16;
5780 zerolen
= stacnt
[2] & 0xffff;
5782 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATS
,
5783 "%s: update statistic: beacons=%d, noretryok=%d, retryok=%d, failed=%d, underflows=%d, zerolen=%d\n",
5784 device_get_nameunit(sc
->dev
),
5785 beacons
, noretryok
, retryok
, failed
, underflows
, zerolen
);
5787 ifp
->if_oerrors
+= failed
;
5789 sc
->tx_beacons
+= beacons
;
5790 sc
->tx_noretryok
+= noretryok
;
5791 sc
->tx_retryok
+= retryok
;
5792 sc
->tx_failed
+= failed
;
5793 sc
->tx_underflows
+= underflows
;
5794 sc
->tx_zerolen
+= zerolen
;
5800 static void rt2860_bbp_tuning(struct rt2860_softc
*sc
)
5803 struct ieee80211com
*ic
;
5804 struct ieee80211vap
*vap
;
5805 struct ieee80211_node
*ni
;
5807 int8_t rssi
, old
, new;
5809 /* RT2860C does not support BBP tuning */
5811 if (sc
->mac_rev
== 0x28600100)
5816 vap
= TAILQ_FIRST(&ic
->ic_vaps
);
5818 if ((ic
->ic_flags
& IEEE80211_F_SCAN
) || vap
== NULL
||
5819 vap
->iv_opmode
!= IEEE80211_M_STA
|| vap
->iv_state
!= IEEE80211_S_RUN
)
5824 chan
= ieee80211_chan2ieee(ic
, ni
->ni_chan
);
5828 else if (chan
<= 64)
5830 else if (chan
<= 128)
5835 rssi
= ieee80211_getrssi(vap
);
5837 if (IEEE80211_IS_CHAN_2GHZ(ni
->ni_chan
))
5839 new = 0x2e + sc
->lna_gain
[group
];
5843 if (!IEEE80211_IS_CHAN_HT40(ni
->ni_chan
))
5844 new = 0x32 + sc
->lna_gain
[group
] * 5 / 3;
5846 new = 0x3a + sc
->lna_gain
[group
] * 5 / 3;
5849 /* Tune if absolute average RSSI is greater than -80 */
5854 old
= rt2860_io_bbp_read(sc
, 66);
5857 rt2860_io_bbp_write(sc
, 66, new);
5863 static void rt2860_watchdog(struct rt2860_softc
*sc
)
5868 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_PBF_TXRXQ_PCNT
);
5870 RT2860_DPRINTF(sc
, RT2860_DEBUG_WATCHDOG
,
5871 "%s: watchdog: TXRXQ_PCNT=0x%08x\n",
5872 device_get_nameunit(sc
->dev
), tmp
);
5874 if (((tmp
>> RT2860_REG_TX0Q_PCNT_SHIFT
) & RT2860_REG_TX0Q_PCNT_MASK
) != 0)
5876 sc
->tx_queue_not_empty
[0]++;
5878 rt2860_io_mac_write(sc
, RT2860_REG_PBF_CFG
, 0xf40012);
5880 for (ntries
= 0; ntries
< 10; ntries
++)
5882 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_PBF_TXRXQ_PCNT
);
5883 if (((tmp
>> RT2860_REG_TX0Q_PCNT_SHIFT
) & RT2860_REG_TX0Q_PCNT_MASK
) == 0)
5889 rt2860_io_mac_write(sc
, RT2860_REG_PBF_CFG
, 0xf40006);
5892 if (((tmp
>> RT2860_REG_TX1Q_PCNT_SHIFT
) & RT2860_REG_TX1Q_PCNT_MASK
) != 0)
5894 sc
->tx_queue_not_empty
[1]++;
5896 rt2860_io_mac_write(sc
, RT2860_REG_PBF_CFG
, 0xf4000a);
5898 for (ntries
= 0; ntries
< 10; ntries
++)
5900 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_PBF_TXRXQ_PCNT
);
5901 if (((tmp
>> RT2860_REG_TX1Q_PCNT_SHIFT
) & RT2860_REG_TX1Q_PCNT_MASK
) == 0)
5907 rt2860_io_mac_write(sc
, RT2860_REG_PBF_CFG
, 0xf40006);
5912 * rt2860_drain_fifo_stats
5914 static void rt2860_drain_fifo_stats(struct rt2860_softc
*sc
)
5918 uint8_t wcid
, mcs
, pid
;
5919 int ok
, agg
, retrycnt
;
5923 /* drain Tx status FIFO (maxsize = 16) */
5925 while ((stats
= rt2860_io_mac_read(sc
, RT2860_REG_TX_STA_FIFO
)) &
5926 RT2860_REG_TX_STA_FIFO_VALID
)
5928 wcid
= (stats
>> RT2860_REG_TX_STA_FIFO_WCID_SHIFT
) &
5929 RT2860_REG_TX_STA_FIFO_WCID_MASK
;
5931 /* if no ACK was requested, no feedback is available */
5933 if (!(stats
& RT2860_REG_TX_STA_FIFO_ACK_REQ
) || wcid
== RT2860_WCID_RESERVED
)
5936 /* update AMRR statistic */
5938 ok
= (stats
& RT2860_REG_TX_STA_FIFO_TX_OK
) ? 1 : 0;
5939 agg
= (stats
& RT2860_REG_TX_STA_FIFO_AGG
) ? 1 : 0;
5940 mcs
= (stats
>> RT2860_REG_TX_STA_FIFO_MCS_SHIFT
) &
5941 RT2860_REG_TX_STA_FIFO_MCS_MASK
;
5942 pid
= (stats
>> RT2860_REG_TX_STA_FIFO_PID_SHIFT
) &
5943 RT2860_REG_TX_STA_FIFO_PID_MASK
;
5944 retrycnt
= pid
- mcs
;
5946 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATS
,
5947 "%s: FIFO statistic: wcid=0x%02x, ok=%d, agg=%d, mcs=0x%02x, pid=0x%02x, retrycnt=%d\n",
5948 device_get_nameunit(sc
->dev
),
5949 wcid
, ok
, agg
, mcs
, pid
, retrycnt
);
5951 rt2860_amrr_tx_complete(&sc
->amrr_node
[wcid
], ok
, retrycnt
);
5959 * rt2860_update_raw_counters
5961 static void rt2860_update_raw_counters(struct rt2860_softc
*sc
)
5965 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_AGG_CNT
);
5967 sc
->tx_nonagg
+= tmp
& 0xffff;
5968 sc
->tx_agg
+= tmp
>> 16;
5970 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_AGG_CNT0
);
5972 sc
->tx_ampdu
+= (tmp
& 0xffff) / 1 + (tmp
>> 16) / 2;
5974 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_AGG_CNT1
);
5976 sc
->tx_ampdu
+= (tmp
& 0xffff) / 3 + (tmp
>> 16) / 4;
5978 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_AGG_CNT2
);
5980 sc
->tx_ampdu
+= (tmp
& 0xffff) / 5 + (tmp
>> 16) / 6;
5982 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_AGG_CNT3
);
5984 sc
->tx_ampdu
+= (tmp
& 0xffff) / 7 + (tmp
>> 16) / 8;
5986 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_AGG_CNT4
);
5988 sc
->tx_ampdu
+= (tmp
& 0xffff) / 9 + (tmp
>> 16) / 10;
5990 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_AGG_CNT5
);
5992 sc
->tx_ampdu
+= (tmp
& 0xffff) / 11 + (tmp
>> 16) / 12;
5994 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_AGG_CNT6
);
5996 sc
->tx_ampdu
+= (tmp
& 0xffff) / 13 + (tmp
>> 16) / 14;
5998 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_AGG_CNT7
);
6000 sc
->tx_ampdu
+= (tmp
& 0xffff) / 15 + (tmp
>> 16) / 16;
6002 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_RX_STA_CNT0
);
6004 sc
->rx_crc_errors
+= tmp
& 0xffff;
6005 sc
->rx_phy_errors
+= tmp
>> 16;
6007 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_RX_STA_CNT1
);
6009 sc
->rx_false_ccas
+= tmp
& 0xffff;
6010 sc
->rx_plcp_errors
+= tmp
>> 16;
6012 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_RX_STA_CNT2
);
6014 sc
->rx_dup_packets
+= tmp
& 0xffff;
6015 sc
->rx_fifo_overflows
+= tmp
>> 16;
6017 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TXRX_MPDU_DEN_CNT
);
6019 sc
->tx_mpdu_zero_density
+= tmp
& 0xffff;
6020 sc
->rx_mpdu_zero_density
+= tmp
>> 16;
6024 * rt2860_intr_enable
6026 static void rt2860_intr_enable(struct rt2860_softc
*sc
, uint32_t intr_mask
)
6030 sc
->intr_disable_mask
&= ~intr_mask
;
6032 tmp
= sc
->intr_enable_mask
& ~sc
->intr_disable_mask
;
6034 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_INT_MASK
, tmp
);
6038 * rt2860_intr_disable
6040 static void rt2860_intr_disable(struct rt2860_softc
*sc
, uint32_t intr_mask
)
6044 sc
->intr_disable_mask
|= intr_mask
;
6046 tmp
= sc
->intr_enable_mask
& ~sc
->intr_disable_mask
;
6048 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_INT_MASK
, tmp
);
6052 * rt2860_txrx_enable
6054 static int rt2860_txrx_enable(struct rt2860_softc
*sc
)
6056 struct ieee80211com
*ic
;
6064 /* enable Tx/Rx DMA engine */
6066 rt2860_io_mac_write(sc
, RT2860_REG_SYS_CTRL
, RT2860_REG_TX_ENABLE
);
6068 for (ntries
= 0; ntries
< 200; ntries
++)
6070 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
);
6071 if (!(tmp
& (RT2860_REG_TX_DMA_BUSY
| RT2860_REG_RX_DMA_BUSY
)))
6079 printf("%s: timeout waiting for DMA engine\n",
6080 device_get_nameunit(sc
->dev
));
6086 tmp
|= RT2860_REG_TX_WB_DDONE
|
6087 RT2860_REG_RX_DMA_ENABLE
|
6088 RT2860_REG_TX_DMA_ENABLE
|
6089 (RT2860_REG_WPDMA_BT_SIZE64
<< RT2860_REG_WPDMA_BT_SIZE_SHIFT
);
6091 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
, tmp
);
6095 tmp
= RT2860_REG_RX_FILTER_DROP_CRC_ERR
|
6096 RT2860_REG_RX_FILTER_DROP_PHY_ERR
;
6098 if (ic
->ic_opmode
!= IEEE80211_M_MONITOR
)
6100 tmp
|= RT2860_REG_RX_FILTER_DROP_DUPL
|
6101 RT2860_REG_RX_FILTER_DROP_CTS
|
6102 RT2860_REG_RX_FILTER_DROP_BA
|
6103 RT2860_REG_RX_FILTER_DROP_ACK
|
6104 RT2860_REG_RX_FILTER_DROP_VER_ERR
|
6105 RT2860_REG_RX_FILTER_DROP_CTRL_RSV
|
6106 RT2860_REG_RX_FILTER_DROP_CFACK
|
6107 RT2860_REG_RX_FILTER_DROP_CFEND
;
6109 if (ic
->ic_opmode
== IEEE80211_M_STA
)
6110 tmp
|= RT2860_REG_RX_FILTER_DROP_RTS
|
6111 RT2860_REG_RX_FILTER_DROP_PSPOLL
;
6113 if (!(ifp
->if_flags
& IFF_PROMISC
))
6114 tmp
|= RT2860_REG_RX_FILTER_DROP_UC_NOME
;
6117 rt2860_io_mac_write(sc
, RT2860_REG_RX_FILTER_CFG
, tmp
);
6119 rt2860_io_mac_write(sc
, RT2860_REG_SYS_CTRL
,
6120 RT2860_REG_RX_ENABLE
| RT2860_REG_TX_ENABLE
);
6126 * rt2860_alloc_rx_ring
6128 static int rt2860_alloc_rx_ring(struct rt2860_softc
*sc
,
6129 struct rt2860_softc_rx_ring
*ring
)
6131 struct rt2860_rxdesc
*desc
;
6132 struct rt2860_softc_rx_data
*data
;
6133 bus_dma_segment_t segs
[1];
6134 int i
, nsegs
, error
;
6136 error
= bus_dma_tag_create(bus_get_dma_tag(sc
->dev
), PAGE_SIZE
, 0,
6137 BUS_SPACE_MAXADDR_32BIT
, BUS_SPACE_MAXADDR
, NULL
, NULL
,
6138 RT2860_SOFTC_RX_RING_DATA_COUNT
* sizeof(struct rt2860_rxdesc
), 1,
6139 RT2860_SOFTC_RX_RING_DATA_COUNT
* sizeof(struct rt2860_rxdesc
),
6140 0, NULL
, NULL
, &ring
->desc_dma_tag
);
6143 printf("%s: could not create Rx desc DMA tag\n",
6144 device_get_nameunit(sc
->dev
));
6148 error
= bus_dmamem_alloc(ring
->desc_dma_tag
, (void **) &ring
->desc
,
6149 BUS_DMA_NOWAIT
| BUS_DMA_ZERO
, &ring
->desc_dma_map
);
6152 printf("%s: could not allocate Rx desc DMA memory\n",
6153 device_get_nameunit(sc
->dev
));
6157 error
= bus_dmamap_load(ring
->desc_dma_tag
, ring
->desc_dma_map
,
6159 RT2860_SOFTC_RX_RING_DATA_COUNT
* sizeof(struct rt2860_rxdesc
),
6160 rt2860_dma_map_addr
, &ring
->desc_phys_addr
, 0);
6163 printf("%s: could not load Rx desc DMA map\n",
6164 device_get_nameunit(sc
->dev
));
6168 error
= bus_dma_tag_create(bus_get_dma_tag(sc
->dev
), PAGE_SIZE
, 0,
6169 BUS_SPACE_MAXADDR_32BIT
, BUS_SPACE_MAXADDR
, NULL
, NULL
,
6170 MJUMPAGESIZE
, 1, MJUMPAGESIZE
, 0, NULL
, NULL
,
6171 &ring
->data_dma_tag
);
6174 printf("%s: could not create Rx data DMA tag\n",
6175 device_get_nameunit(sc
->dev
));
6179 for (i
= 0; i
< RT2860_SOFTC_RX_RING_DATA_COUNT
; i
++)
6181 desc
= &ring
->desc
[i
];
6182 data
= &ring
->data
[i
];
6184 error
= bus_dmamap_create(ring
->data_dma_tag
, 0, &data
->dma_map
);
6187 printf("%s: could not create Rx data DMA map\n",
6188 device_get_nameunit(sc
->dev
));
6192 data
->m
= m_getjcl(M_DONTWAIT
, MT_DATA
, M_PKTHDR
, MJUMPAGESIZE
);
6193 if (data
->m
== NULL
)
6195 printf("%s: could not allocate Rx mbuf\n",
6196 device_get_nameunit(sc
->dev
));
6201 data
->m
->m_len
= data
->m
->m_pkthdr
.len
= MJUMPAGESIZE
;
6203 error
= bus_dmamap_load_mbuf_sg(ring
->data_dma_tag
, data
->dma_map
,
6204 data
->m
, segs
, &nsegs
, BUS_DMA_NOWAIT
);
6207 printf("%s: could not load Rx mbuf DMA map\n",
6208 device_get_nameunit(sc
->dev
));
6212 KASSERT(nsegs
== 1, ("%s: too many DMA segments",
6213 device_get_nameunit(sc
->dev
)));
6215 desc
->sdp0
= htole32(segs
[0].ds_addr
);
6216 desc
->sdl0
= htole16(MJUMPAGESIZE
);
6219 error
= bus_dmamap_create(ring
->data_dma_tag
, 0, &ring
->spare_dma_map
);
6222 printf("%s: could not create Rx spare DMA map\n",
6223 device_get_nameunit(sc
->dev
));
6227 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
6228 BUS_DMASYNC_PREREAD
| BUS_DMASYNC_PREWRITE
);
6234 rt2860_free_rx_ring(sc
, ring
);
6240 * rt2860_reset_rx_ring
6242 static void rt2860_reset_rx_ring(struct rt2860_softc
*sc
,
6243 struct rt2860_softc_rx_ring
*ring
)
6245 struct rt2860_rxdesc
*desc
;
6248 for (i
= 0; i
< RT2860_SOFTC_RX_RING_DATA_COUNT
; i
++)
6250 desc
= &ring
->desc
[i
];
6252 desc
->sdl0
&= ~htole16(RT2860_RXDESC_SDL0_DDONE
);
6255 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
6256 BUS_DMASYNC_PREREAD
| BUS_DMASYNC_PREWRITE
);
6262 * rt2860_free_rx_ring
6264 static void rt2860_free_rx_ring(struct rt2860_softc
*sc
,
6265 struct rt2860_softc_rx_ring
*ring
)
6267 struct rt2860_softc_rx_data
*data
;
6270 if (ring
->desc
!= NULL
)
6272 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
6273 BUS_DMASYNC_POSTWRITE
);
6274 bus_dmamap_unload(ring
->desc_dma_tag
, ring
->desc_dma_map
);
6275 bus_dmamem_free(ring
->desc_dma_tag
, ring
->desc
,
6276 ring
->desc_dma_map
);
6279 if (ring
->desc_dma_tag
!= NULL
)
6280 bus_dma_tag_destroy(ring
->desc_dma_tag
);
6282 for (i
= 0; i
< RT2860_SOFTC_RX_RING_DATA_COUNT
; i
++)
6284 data
= &ring
->data
[i
];
6286 if (data
->m
!= NULL
)
6288 bus_dmamap_sync(ring
->data_dma_tag
, data
->dma_map
,
6289 BUS_DMASYNC_POSTREAD
);
6290 bus_dmamap_unload(ring
->data_dma_tag
, data
->dma_map
);
6294 if (data
->dma_map
!= NULL
)
6295 bus_dmamap_destroy(ring
->data_dma_tag
, data
->dma_map
);
6298 if (ring
->spare_dma_map
!= NULL
)
6299 bus_dmamap_destroy(ring
->data_dma_tag
, ring
->spare_dma_map
);
6301 if (ring
->data_dma_tag
!= NULL
)
6302 bus_dma_tag_destroy(ring
->data_dma_tag
);
6306 * rt2860_alloc_tx_ring
6308 static int rt2860_alloc_tx_ring(struct rt2860_softc
*sc
,
6309 struct rt2860_softc_tx_ring
*ring
, int qid
)
6311 struct rt2860_softc_tx_data
*data
;
6314 error
= bus_dma_tag_create(bus_get_dma_tag(sc
->dev
), PAGE_SIZE
, 0,
6315 BUS_SPACE_MAXADDR_32BIT
, BUS_SPACE_MAXADDR
, NULL
, NULL
,
6316 RT2860_SOFTC_TX_RING_DESC_COUNT
* sizeof(struct rt2860_txdesc
), 1,
6317 RT2860_SOFTC_TX_RING_DESC_COUNT
* sizeof(struct rt2860_txdesc
),
6318 0, NULL
, NULL
, &ring
->desc_dma_tag
);
6321 printf("%s: could not create Tx desc DMA tag\n",
6322 device_get_nameunit(sc
->dev
));
6326 error
= bus_dmamem_alloc(ring
->desc_dma_tag
, (void **) &ring
->desc
,
6327 BUS_DMA_NOWAIT
| BUS_DMA_ZERO
, &ring
->desc_dma_map
);
6330 printf("%s: could not allocate Tx desc DMA memory\n",
6331 device_get_nameunit(sc
->dev
));
6335 error
= bus_dmamap_load(ring
->desc_dma_tag
, ring
->desc_dma_map
,
6337 RT2860_SOFTC_TX_RING_DESC_COUNT
* sizeof(struct rt2860_txdesc
),
6338 rt2860_dma_map_addr
, &ring
->desc_phys_addr
, 0);
6341 printf("%s: could not load Tx desc DMA map\n",
6342 device_get_nameunit(sc
->dev
));
6346 ring
->desc_queued
= 0;
6348 ring
->desc_next
= 0;
6350 error
= bus_dma_tag_create(bus_get_dma_tag(sc
->dev
), PAGE_SIZE
, 0,
6351 BUS_SPACE_MAXADDR_32BIT
, BUS_SPACE_MAXADDR
, NULL
, NULL
,
6352 RT2860_SOFTC_TX_RING_DATA_COUNT
* RT2860_TX_DATA_SEG0_SIZE
, 1,
6353 RT2860_SOFTC_TX_RING_DATA_COUNT
* RT2860_TX_DATA_SEG0_SIZE
,
6354 0, NULL
, NULL
, &ring
->seg0_dma_tag
);
6357 printf("%s: could not create Tx seg0 DMA tag\n",
6358 device_get_nameunit(sc
->dev
));
6362 error
= bus_dmamem_alloc(ring
->seg0_dma_tag
, (void **) &ring
->seg0
,
6363 BUS_DMA_NOWAIT
| BUS_DMA_ZERO
, &ring
->seg0_dma_map
);
6366 printf("%s: could not allocate Tx seg0 DMA memory\n",
6367 device_get_nameunit(sc
->dev
));
6371 error
= bus_dmamap_load(ring
->seg0_dma_tag
, ring
->seg0_dma_map
,
6373 RT2860_SOFTC_TX_RING_DATA_COUNT
* RT2860_TX_DATA_SEG0_SIZE
,
6374 rt2860_dma_map_addr
, &ring
->seg0_phys_addr
, 0);
6377 printf("%s: could not load Tx seg0 DMA map\n",
6378 device_get_nameunit(sc
->dev
));
6382 error
= bus_dma_tag_create(bus_get_dma_tag(sc
->dev
), PAGE_SIZE
, 0,
6383 BUS_SPACE_MAXADDR_32BIT
, BUS_SPACE_MAXADDR
, NULL
, NULL
,
6384 MJUMPAGESIZE
, RT2860_SOFTC_MAX_SCATTER
, MJUMPAGESIZE
, 0, NULL
, NULL
,
6385 &ring
->data_dma_tag
);
6388 printf("%s: could not create Tx data DMA tag\n",
6389 device_get_nameunit(sc
->dev
));
6393 for (i
= 0; i
< RT2860_SOFTC_TX_RING_DATA_COUNT
; i
++)
6395 data
= &ring
->data
[i
];
6397 error
= bus_dmamap_create(ring
->data_dma_tag
, 0, &data
->dma_map
);
6400 printf("%s: could not create Tx data DMA map\n",
6401 device_get_nameunit(sc
->dev
));
6406 ring
->data_queued
= 0;
6408 ring
->data_next
= 0;
6416 rt2860_free_tx_ring(sc
, ring
);
6422 * rt2860_reset_tx_ring
6424 static void rt2860_reset_tx_ring(struct rt2860_softc
*sc
,
6425 struct rt2860_softc_tx_ring
*ring
)
6427 struct rt2860_softc_tx_data
*data
;
6428 struct rt2860_txdesc
*desc
;
6431 for (i
= 0; i
< RT2860_SOFTC_TX_RING_DESC_COUNT
; i
++)
6433 desc
= &ring
->desc
[i
];
6439 ring
->desc_queued
= 0;
6441 ring
->desc_next
= 0;
6443 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
6444 BUS_DMASYNC_PREWRITE
);
6446 bus_dmamap_sync(ring
->seg0_dma_tag
, ring
->seg0_dma_map
,
6447 BUS_DMASYNC_PREWRITE
);
6449 for (i
= 0; i
< RT2860_SOFTC_TX_RING_DATA_COUNT
; i
++)
6451 data
= &ring
->data
[i
];
6453 if (data
->m
!= NULL
)
6455 bus_dmamap_sync(ring
->data_dma_tag
, data
->dma_map
,
6456 BUS_DMASYNC_POSTWRITE
);
6457 bus_dmamap_unload(ring
->data_dma_tag
, data
->dma_map
);
6462 if (data
->ni
!= NULL
)
6464 ieee80211_free_node(data
->ni
);
6469 ring
->data_queued
= 0;
6471 ring
->data_next
= 0;
6475 * rt2860_free_tx_ring
6477 static void rt2860_free_tx_ring(struct rt2860_softc
*sc
,
6478 struct rt2860_softc_tx_ring
*ring
)
6480 struct rt2860_softc_tx_data
*data
;
6483 if (ring
->desc
!= NULL
)
6485 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
6486 BUS_DMASYNC_POSTWRITE
);
6487 bus_dmamap_unload(ring
->desc_dma_tag
, ring
->desc_dma_map
);
6488 bus_dmamem_free(ring
->desc_dma_tag
, ring
->desc
,
6489 ring
->desc_dma_map
);
6492 if (ring
->desc_dma_tag
!= NULL
)
6493 bus_dma_tag_destroy(ring
->desc_dma_tag
);
6495 if (ring
->seg0
!= NULL
)
6497 bus_dmamap_sync(ring
->seg0_dma_tag
, ring
->seg0_dma_map
,
6498 BUS_DMASYNC_POSTWRITE
);
6499 bus_dmamap_unload(ring
->seg0_dma_tag
, ring
->seg0_dma_map
);
6500 bus_dmamem_free(ring
->seg0_dma_tag
, ring
->seg0
,
6501 ring
->seg0_dma_map
);
6504 if (ring
->seg0_dma_tag
!= NULL
)
6505 bus_dma_tag_destroy(ring
->seg0_dma_tag
);
6507 for (i
= 0; i
< RT2860_SOFTC_TX_RING_DATA_COUNT
; i
++)
6509 data
= &ring
->data
[i
];
6511 if (data
->m
!= NULL
)
6513 bus_dmamap_sync(ring
->data_dma_tag
, data
->dma_map
,
6514 BUS_DMASYNC_POSTWRITE
);
6515 bus_dmamap_unload(ring
->data_dma_tag
, data
->dma_map
);
6519 if (data
->ni
!= NULL
)
6520 ieee80211_free_node(data
->ni
);
6522 if (data
->dma_map
!= NULL
)
6523 bus_dmamap_destroy(ring
->data_dma_tag
, data
->dma_map
);
6526 if (ring
->data_dma_tag
!= NULL
)
6527 bus_dma_tag_destroy(ring
->data_dma_tag
);
6531 * rt2860_dma_map_addr
6533 static void rt2860_dma_map_addr(void *arg
, bus_dma_segment_t
*segs
,
6534 int nseg
, int error
)
6539 KASSERT(nseg
== 1, ("too many DMA segments, %d should be 1", nseg
));
6541 *(bus_addr_t
*) arg
= segs
[0].ds_addr
;
6545 * rt2860_sysctl_attach
6547 static void rt2860_sysctl_attach(struct rt2860_softc
*sc
)
6549 struct sysctl_ctx_list
*ctx
;
6550 struct sysctl_oid
*tree
;
6551 struct sysctl_oid
*stats
;
6553 ctx
= device_get_sysctl_ctx(sc
->dev
);
6554 tree
= device_get_sysctl_tree(sc
->dev
);
6556 stats
= SYSCTL_ADD_NODE(ctx
, SYSCTL_CHILDREN(tree
), OID_AUTO
,
6557 "stats", CTLFLAG_RD
, 0, "statistic");
6559 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6560 "interrupts", CTLFLAG_RD
, &sc
->interrupts
, 0,
6563 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6564 "tx_coherent_interrupts", CTLFLAG_RD
, &sc
->tx_coherent_interrupts
, 0,
6565 "Tx coherent interrupts");
6567 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6568 "rx_coherent_interrupts", CTLFLAG_RD
, &sc
->rx_coherent_interrupts
, 0,
6569 "Rx coherent interrupts");
6571 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6572 "txrx_coherent_interrupts", CTLFLAG_RD
, &sc
->txrx_coherent_interrupts
, 0,
6573 "Tx/Rx coherent interrupts");
6575 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6576 "fifo_sta_full_interrupts", CTLFLAG_RD
, &sc
->fifo_sta_full_interrupts
, 0,
6577 "FIFO statistic full interrupts");
6579 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6580 "rx_interrupts", CTLFLAG_RD
, &sc
->rx_interrupts
, 0,
6583 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6584 "rx_delay_interrupts", CTLFLAG_RD
, &sc
->rx_delay_interrupts
, 0,
6585 "Rx delay interrupts");
6587 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6588 "tx_mgmt_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[5], 0,
6589 "Tx MGMT interrupts");
6591 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6592 "tx_hcca_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[4], 0,
6593 "Tx HCCA interrupts");
6595 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6596 "tx_ac3_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[3], 0,
6597 "Tx AC3 interrupts");
6599 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6600 "tx_ac2_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[2], 0,
6601 "Tx AC2 interrupts");
6603 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6604 "tx_ac1_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[1], 0,
6605 "Tx AC1 interrupts");
6607 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6608 "tx_ac0_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[0], 0,
6609 "Tx AC0 interrupts");
6611 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6612 "tx_delay_interrupts", CTLFLAG_RD
, &sc
->tx_delay_interrupts
, 0,
6613 "Tx delay interrupts");
6615 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6616 "pre_tbtt_interrupts", CTLFLAG_RD
, &sc
->pre_tbtt_interrupts
, 0,
6617 "Pre-TBTT interrupts");
6619 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6620 "tbtt_interrupts", CTLFLAG_RD
, &sc
->tbtt_interrupts
, 0,
6623 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6624 "mcu_cmd_interrupts", CTLFLAG_RD
, &sc
->mcu_cmd_interrupts
, 0,
6625 "MCU command interrupts");
6627 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6628 "auto_wakeup_interrupts", CTLFLAG_RD
, &sc
->auto_wakeup_interrupts
, 0,
6629 "auto wakeup interrupts");
6631 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6632 "gp_timer_interrupts", CTLFLAG_RD
, &sc
->gp_timer_interrupts
, 0,
6633 "GP timer interrupts");
6635 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6636 "tx_mgmt_desc_queued", CTLFLAG_RD
, &sc
->tx_ring
[5].desc_queued
, 0,
6637 "Tx MGMT descriptors queued");
6639 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6640 "tx_mgmt_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[5].data_queued
, 0,
6641 "Tx MGMT data queued");
6643 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6644 "tx_hcca_desc_queued", CTLFLAG_RD
, &sc
->tx_ring
[4].desc_queued
, 0,
6645 "Tx HCCA descriptors queued");
6647 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6648 "tx_hcca_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[4].data_queued
, 0,
6649 "Tx HCCA data queued");
6651 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6652 "tx_ac3_desc_queued", CTLFLAG_RD
, &sc
->tx_ring
[3].desc_queued
, 0,
6653 "Tx AC3 descriptors queued");
6655 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6656 "tx_ac3_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[3].data_queued
, 0,
6657 "Tx AC3 data queued");
6659 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6660 "tx_ac2_desc_queued", CTLFLAG_RD
, &sc
->tx_ring
[2].desc_queued
, 0,
6661 "Tx AC2 descriptors queued");
6663 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6664 "tx_ac2_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[2].data_queued
, 0,
6665 "Tx AC2 data queued");
6667 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6668 "tx_ac1_desc_queued", CTLFLAG_RD
, &sc
->tx_ring
[1].desc_queued
, 0,
6669 "Tx AC1 descriptors queued");
6671 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6672 "tx_ac1_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[1].data_queued
, 0,
6673 "Tx AC1 data queued");
6675 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6676 "tx_ac0_desc_queued", CTLFLAG_RD
, &sc
->tx_ring
[0].desc_queued
, 0,
6677 "Tx AC0 descriptors queued");
6679 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6680 "tx_ac0_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[0].data_queued
, 0,
6681 "Tx AC0 data queued");
6683 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6684 "tx_mgmt_data_queue_full", CTLFLAG_RD
, &sc
->tx_data_queue_full
[5], 0,
6685 "Tx MGMT data queue full");
6687 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6688 "tx_hcca_data_queue_full", CTLFLAG_RD
, &sc
->tx_data_queue_full
[4], 0,
6689 "Tx HCCA data queue full");
6691 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6692 "tx_ac3_data_queue_full", CTLFLAG_RD
, &sc
->tx_data_queue_full
[3], 0,
6693 "Tx AC3 data queue full");
6695 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6696 "tx_ac2_data_queue_full", CTLFLAG_RD
, &sc
->tx_data_queue_full
[2], 0,
6697 "Tx AC2 data queue full");
6699 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6700 "tx_ac1_data_queue_full", CTLFLAG_RD
, &sc
->tx_data_queue_full
[1], 0,
6701 "Tx AC1 data queue full");
6703 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6704 "tx_ac0_data_queue_full", CTLFLAG_RD
, &sc
->tx_data_queue_full
[0], 0,
6705 "Tx AC0 data queue full");
6707 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6708 "tx_watchdog_timeouts", CTLFLAG_RD
, &sc
->tx_watchdog_timeouts
, 0,
6709 "Tx watchdog timeouts");
6711 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6712 "tx_defrag_packets", CTLFLAG_RD
, &sc
->tx_defrag_packets
, 0,
6713 "Tx defragmented packets");
6715 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6716 "no_tx_desc_avail", CTLFLAG_RD
, &sc
->no_tx_desc_avail
, 0,
6717 "no Tx descriptors available");
6719 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6720 "rx_mbuf_alloc_errors", CTLFLAG_RD
, &sc
->rx_mbuf_alloc_errors
, 0,
6721 "Rx mbuf allocation errors");
6723 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6724 "rx_mbuf_dmamap_errors", CTLFLAG_RD
, &sc
->rx_mbuf_dmamap_errors
, 0,
6725 "Rx mbuf DMA mapping errors");
6727 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6728 "tx_queue_0_not_empty", CTLFLAG_RD
, &sc
->tx_queue_not_empty
[0], 0,
6729 "Tx queue 0 not empty");
6731 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6732 "tx_queue_1_not_empty", CTLFLAG_RD
, &sc
->tx_queue_not_empty
[1], 0,
6733 "Tx queue 1 not empty");
6735 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6736 "tx_beacons", CTLFLAG_RD
, &sc
->tx_beacons
, 0,
6739 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6740 "tx_noretryok", CTLFLAG_RD
, &sc
->tx_noretryok
, 0,
6741 "Tx successfull without retries");
6743 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6744 "tx_retryok", CTLFLAG_RD
, &sc
->tx_retryok
, 0,
6745 "Tx successfull with retries");
6747 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6748 "tx_failed", CTLFLAG_RD
, &sc
->tx_failed
, 0,
6751 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6752 "tx_underflows", CTLFLAG_RD
, &sc
->tx_underflows
, 0,
6755 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6756 "tx_zerolen", CTLFLAG_RD
, &sc
->tx_zerolen
, 0,
6759 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6760 "tx_nonagg", CTLFLAG_RD
, &sc
->tx_nonagg
, 0,
6761 "Tx non-aggregated");
6763 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6764 "tx_agg", CTLFLAG_RD
, &sc
->tx_agg
, 0,
6767 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6768 "tx_ampdu", CTLFLAG_RD
, &sc
->tx_ampdu
, 0,
6771 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6772 "tx_mpdu_zero_density", CTLFLAG_RD
, &sc
->tx_mpdu_zero_density
, 0,
6773 "Tx MPDU with zero density");
6775 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6776 "tx_ampdu_sessions", CTLFLAG_RD
, &sc
->tx_ampdu_sessions
, 0,
6777 "Tx A-MPDU sessions");
6779 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6780 "rx_packets", CTLFLAG_RD
, &sc
->rx_packets
, 0,
6783 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6784 "rx_ampdu", CTLFLAG_RD
, &sc
->rx_ampdu
, 0,
6787 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6788 "rx_mpdu_zero_density", CTLFLAG_RD
, &sc
->rx_mpdu_zero_density
, 0,
6789 "Rx MPDU with zero density");
6791 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6792 "rx_amsdu", CTLFLAG_RD
, &sc
->rx_amsdu
, 0,
6795 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6796 "rx_crc_errors", CTLFLAG_RD
, &sc
->rx_crc_errors
, 0,
6799 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6800 "rx_phy_errors", CTLFLAG_RD
, &sc
->rx_phy_errors
, 0,
6803 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6804 "rx_false_ccas", CTLFLAG_RD
, &sc
->rx_false_ccas
, 0,
6807 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6808 "rx_plcp_errors", CTLFLAG_RD
, &sc
->rx_plcp_errors
, 0,
6811 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6812 "rx_dup_packets", CTLFLAG_RD
, &sc
->rx_dup_packets
, 0,
6813 "Rx duplicate packets");
6815 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6816 "rx_fifo_overflows", CTLFLAG_RD
, &sc
->rx_fifo_overflows
, 0,
6817 "Rx FIFO overflows");
6819 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6820 "rx_cipher_no_errors", CTLFLAG_RD
, &sc
->rx_cipher_no_errors
, 0,
6821 "Rx cipher no errors");
6823 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6824 "rx_cipher_icv_errors", CTLFLAG_RD
, &sc
->rx_cipher_icv_errors
, 0,
6825 "Rx cipher ICV errors");
6827 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6828 "rx_cipher_mic_errors", CTLFLAG_RD
, &sc
->rx_cipher_mic_errors
, 0,
6829 "Rx cipher MIC errors");
6831 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6832 "rx_cipher_invalid_key_errors", CTLFLAG_RD
, &sc
->rx_cipher_invalid_key_errors
, 0,
6833 "Rx cipher invalid key errors");
6836 static device_method_t rt2860_dev_methods
[] =
6838 DEVMETHOD(device_probe
, rt2860_probe
),
6839 DEVMETHOD(device_attach
, rt2860_attach
),
6840 DEVMETHOD(device_detach
, rt2860_detach
),
6841 DEVMETHOD(device_shutdown
, rt2860_shutdown
),
6842 DEVMETHOD(device_suspend
, rt2860_suspend
),
6843 DEVMETHOD(device_resume
, rt2860_resume
),
6847 static driver_t rt2860_driver
=
6851 sizeof(struct rt2860_softc
)
6854 static devclass_t rt2860_dev_class
;
6856 DRIVER_MODULE(rt2860
, pci
, rt2860_driver
, rt2860_dev_class
, 0, 0);
6858 MODULE_DEPEND(rt2860
, pci
, 1, 1, 1);
6859 MODULE_DEPEND(rt2860
, wlan
, 1, 1, 1);