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 int rt2860_addba_response(struct ieee80211_node
*ni
,
176 struct ieee80211_tx_ampdu
*tap
,
177 int status
, int baparamset
, int batimeout
);
179 static void rt2860_addba_stop(struct ieee80211_node
*ni
,
180 struct ieee80211_tx_ampdu
*tap
);
182 static int rt2860_ampdu_rx_start(struct ieee80211_node
*ni
,
183 struct ieee80211_rx_ampdu
*rap
,
184 int baparamset
, int batimeout
, int baseqctl
);
186 static void rt2860_ampdu_rx_stop(struct ieee80211_node
*ni
,
187 struct ieee80211_rx_ampdu
*rap
);
189 static int rt2860_send_bar(struct ieee80211_node
*ni
,
190 struct ieee80211_tx_ampdu
*tap
, ieee80211_seq seqno
);
192 static void rt2860_amrr_update_iter_func(void *arg
, struct ieee80211_node
*ni
);
194 static void rt2860_periodic(void *arg
);
196 static void rt2860_tx_watchdog(void *arg
);
198 static int rt2860_staid_alloc(struct rt2860_softc
*sc
, int aid
);
200 static void rt2860_staid_delete(struct rt2860_softc
*sc
, int staid
);
202 static void rt2860_asic_set_bssid(struct rt2860_softc
*sc
,
203 const uint8_t *bssid
);
205 static void rt2860_asic_set_macaddr(struct rt2860_softc
*sc
,
206 const uint8_t *addr
);
208 static void rt2860_asic_enable_tsf_sync(struct rt2860_softc
*sc
);
210 static void rt2860_asic_disable_tsf_sync(struct rt2860_softc
*sc
);
212 static void rt2860_asic_enable_mrr(struct rt2860_softc
*sc
);
214 static void rt2860_asic_set_txpreamble(struct rt2860_softc
*sc
);
216 static void rt2860_asic_set_basicrates(struct rt2860_softc
*sc
);
218 static void rt2860_asic_update_rtsthreshold(struct rt2860_softc
*sc
);
220 static void rt2860_asic_update_txpower(struct rt2860_softc
*sc
);
222 static void rt2860_asic_update_promisc(struct rt2860_softc
*sc
);
224 static void rt2860_asic_updateprot(struct rt2860_softc
*sc
);
226 static void rt2860_asic_updateslot(struct rt2860_softc
*sc
);
228 static void rt2860_asic_wme_update(struct rt2860_softc
*sc
);
230 static void rt2860_asic_update_beacon(struct rt2860_softc
*sc
,
231 struct ieee80211vap
*vap
);
233 static void rt2860_asic_clear_keytables(struct rt2860_softc
*sc
);
235 static void rt2860_asic_add_ba_session(struct rt2860_softc
*sc
,
236 uint8_t wcid
, int tid
);
238 static void rt2860_asic_del_ba_session(struct rt2860_softc
*sc
,
239 uint8_t wcid
, int tid
);
241 static int rt2860_beacon_alloc(struct rt2860_softc
*sc
,
242 struct ieee80211vap
*vap
);
244 static uint8_t rt2860_rxrate(struct rt2860_rxwi
*rxwi
);
246 static uint8_t rt2860_maxrssi_rxpath(struct rt2860_softc
*sc
,
247 const struct rt2860_rxwi
*rxwi
);
249 static int8_t rt2860_rssi2dbm(struct rt2860_softc
*sc
,
250 uint8_t rssi
, uint8_t rxpath
);
252 static uint8_t rt2860_rate2mcs(uint8_t rate
);
254 static int rt2860_tx_mgmt(struct rt2860_softc
*sc
,
255 struct mbuf
*m
, struct ieee80211_node
*ni
, int qid
);
257 static int rt2860_tx_data(struct rt2860_softc
*sc
,
258 struct mbuf
*m
, struct ieee80211_node
*ni
, int qid
);
260 static int rt2860_tx_raw(struct rt2860_softc
*sc
,
261 struct mbuf
*m
, struct ieee80211_node
*ni
,
262 const struct ieee80211_bpf_params
*params
);
264 static void rt2860_intr(void *arg
);
266 static void rt2860_tx_coherent_intr(struct rt2860_softc
*sc
);
268 static void rt2860_rx_coherent_intr(struct rt2860_softc
*sc
);
270 static void rt2860_txrx_coherent_intr(struct rt2860_softc
*sc
);
272 static void rt2860_fifo_sta_full_intr(struct rt2860_softc
*sc
);
274 static void rt2860_rx_intr(struct rt2860_softc
*sc
);
276 static void rt2860_rx_delay_intr(struct rt2860_softc
*sc
);
278 static void rt2860_tx_intr(struct rt2860_softc
*sc
, int qid
);
280 static void rt2860_tx_delay_intr(struct rt2860_softc
*sc
);
282 static void rt2860_pre_tbtt_intr(struct rt2860_softc
*sc
);
284 static void rt2860_tbtt_intr(struct rt2860_softc
*sc
);
286 static void rt2860_mcu_cmd_intr(struct rt2860_softc
*sc
);
288 static void rt2860_auto_wakeup_intr(struct rt2860_softc
*sc
);
290 static void rt2860_gp_timer_intr(struct rt2860_softc
*sc
);
292 static void rt2860_rx_done_task(void *context
, int pending
);
294 static void rt2860_tx_done_task(void *context
, int pending
);
296 static void rt2860_fifo_sta_full_task(void *context
, int pending
);
298 static void rt2860_periodic_task(void *context
, int pending
);
300 static int rt2860_rx_eof(struct rt2860_softc
*sc
, int limit
);
302 static void rt2860_tx_eof(struct rt2860_softc
*sc
,
303 struct rt2860_softc_tx_ring
*ring
);
305 static void rt2860_update_stats(struct rt2860_softc
*sc
);
307 static void rt2860_bbp_tuning(struct rt2860_softc
*sc
);
309 static void rt2860_watchdog(struct rt2860_softc
*sc
);
311 static void rt2860_drain_fifo_stats(struct rt2860_softc
*sc
);
313 static void rt2860_update_raw_counters(struct rt2860_softc
*sc
);
315 static void rt2860_intr_enable(struct rt2860_softc
*sc
, uint32_t intr_mask
);
317 static void rt2860_intr_disable(struct rt2860_softc
*sc
, uint32_t intr_mask
);
319 static int rt2860_txrx_enable(struct rt2860_softc
*sc
);
321 static int rt2860_alloc_rx_ring(struct rt2860_softc
*sc
,
322 struct rt2860_softc_rx_ring
*ring
);
324 static void rt2860_reset_rx_ring(struct rt2860_softc
*sc
,
325 struct rt2860_softc_rx_ring
*ring
);
327 static void rt2860_free_rx_ring(struct rt2860_softc
*sc
,
328 struct rt2860_softc_rx_ring
*ring
);
330 static int rt2860_alloc_tx_ring(struct rt2860_softc
*sc
,
331 struct rt2860_softc_tx_ring
*ring
, int qid
);
333 static void rt2860_reset_tx_ring(struct rt2860_softc
*sc
,
334 struct rt2860_softc_tx_ring
*ring
);
336 static void rt2860_free_tx_ring(struct rt2860_softc
*sc
,
337 struct rt2860_softc_tx_ring
*ring
);
339 static void rt2860_dma_map_addr(void *arg
, bus_dma_segment_t
*segs
,
340 int nseg
, int error
);
342 static void rt2860_sysctl_attach(struct rt2860_softc
*sc
);
348 static const struct rt2860_pci_ident rt2860_pci_ids
[] =
350 { PCI_VENDOR_RALINK
, PCI_PRODUCT_RALINK_RT2860_PCI
, "Ralink RT2860 PCI" },
351 { PCI_VENDOR_RALINK
, PCI_PRODUCT_RALINK_RT2860_PCIe
, "Ralink RT2860 PCIe" },
352 { PCI_VENDOR_RALINK
, PCI_PRODUCT_RALINK_RT2760_PCI
, "Ralink RT2760 PCI" },
353 { PCI_VENDOR_RALINK
, PCI_PRODUCT_RALINK_RT2790_PCIe
, "Ralink RT2790 PCIe" },
363 { RT2860_REG_PBF_BCN_OFFSET0
, 0xf8f0e8e0 },
364 { RT2860_REG_PBF_BCN_OFFSET1
, 0x6f77d0c8 },
365 { RT2860_REG_LEGACY_BASIC_RATE
, 0x0000013f },
366 { RT2860_REG_HT_BASIC_RATE
, 0x00008003 },
367 { RT2860_REG_SYS_CTRL
, 0x00000000 },
368 { RT2860_REG_RX_FILTER_CFG
, 0x00017f97 },
369 { RT2860_REG_BKOFF_SLOT_CFG
, 0x00000209 },
370 { RT2860_REG_TX_SW_CFG0
, 0x00000000 },
371 { RT2860_REG_TX_SW_CFG1
, 0x00080606 },
372 { RT2860_REG_TX_LINK_CFG
, 0x00001020 },
373 { RT2860_REG_TX_TIMEOUT_CFG
, 0x000a2090 },
374 { RT2860_REG_MAX_LEN_CFG
, (1 << 12) | RT2860_MAX_AGG_SIZE
},
375 { RT2860_REG_LED_CFG
, 0x7f031e46 },
376 { RT2860_REG_PBF_MAX_PCNT
, 0x1f3fbf9f },
377 { RT2860_REG_TX_RTY_CFG
, 0x47d01f0f },
378 { RT2860_REG_AUTO_RSP_CFG
, 0x00000013 },
379 { RT2860_REG_TX_CCK_PROT_CFG
, 0x05740003 },
380 { RT2860_REG_TX_OFDM_PROT_CFG
, 0x05740003 },
381 { RT2860_REG_TX_GF20_PROT_CFG
, 0x01744004 },
382 { RT2860_REG_TX_GF40_PROT_CFG
, 0x03f44084 },
383 { RT2860_REG_TX_MM20_PROT_CFG
, 0x01744004 },
384 { RT2860_REG_TX_MM40_PROT_CFG
, 0x03f54084 },
385 { RT2860_REG_TX_TXOP_CTRL_CFG
, 0x0000583f },
386 { RT2860_REG_TX_RTS_CFG
, 0x00092b20 },
387 { RT2860_REG_TX_EXP_ACK_TIME
, 0x002400ca },
388 { RT2860_REG_HCCAPSMP_TXOP_HLDR_ET
, 0x00000002 },
389 { RT2860_REG_XIFS_TIME_CFG
, 0x33a41010 },
390 { RT2860_REG_PWR_PIN_CFG
, 0x00000003 },
391 { RT2860_REG_SCHDMA_WMM_AIFSN_CFG
, 0x00002273 },
392 { RT2860_REG_SCHDMA_WMM_CWMIN_CFG
, 0x00002344 },
393 { RT2860_REG_SCHDMA_WMM_CWMAX_CFG
, 0x000034aa },
396 #define RT2860_DEF_MAC_SIZE (sizeof(rt2860_def_mac) / sizeof(rt2860_def_mac[0]))
421 #define RT2860_DEF_BBP_SIZE (sizeof(rt2860_def_bbp) / sizeof(rt2860_def_bbp[0]))
423 SYSCTL_NODE(_hw
, OID_AUTO
, rt2860
, CTLFLAG_RD
, 0, "RT2860 driver parameters");
425 static int rt2860_tx_stbc
= 1;
426 SYSCTL_INT(_hw_rt2860
, OID_AUTO
, tx_stbc
, CTLFLAG_RW
, &rt2860_tx_stbc
, 0, "RT2860 Tx STBC");
427 TUNABLE_INT("hw.rt2860.tx_stbc", &rt2860_tx_stbc
);
430 static int rt2860_debug
= 0;
431 SYSCTL_INT(_hw_rt2860
, OID_AUTO
, debug
, CTLFLAG_RW
, &rt2860_debug
, 0, "RT2860 debug level");
432 TUNABLE_INT("hw.rt2860.debug", &rt2860_debug
);
438 static int rt2860_probe(device_t dev
)
440 const struct rt2860_pci_ident
*ident
;
442 for (ident
= rt2860_pci_ids
; ident
->name
!= NULL
; ident
++)
444 if (pci_get_vendor(dev
) == ident
->vendor
&&
445 pci_get_device(dev
) == ident
->device
)
447 device_set_desc(dev
, ident
->name
);
458 static int rt2860_attach(device_t dev
)
460 struct rt2860_softc
*sc
;
462 struct ieee80211com
*ic
;
463 int error
, ntries
, i
;
465 sc
= device_get_softc(dev
);
467 if (pci_get_powerstate(dev
) != PCI_POWERSTATE_D0
)
469 printf("%s: chip is in D%d power mode, setting to D0\n",
470 device_get_nameunit(dev
), pci_get_powerstate(dev
));
471 pci_set_powerstate(dev
, PCI_POWERSTATE_D0
);
474 /* enable bus-mastering */
476 pci_enable_busmaster(dev
);
480 mtx_init(&sc
->lock
, device_get_nameunit(dev
),
481 MTX_NETWORK_LOCK
, MTX_DEF
| MTX_RECURSE
);
483 sc
->mem_rid
= PCIR_BAR(0);
484 sc
->mem
= bus_alloc_resource_any(dev
, SYS_RES_MEMORY
,
485 &sc
->mem_rid
, RF_ACTIVE
);
488 printf("%s: could not allocate memory resource\n",
489 device_get_nameunit(dev
));
494 sc
->bst
= rman_get_bustag(sc
->mem
);
495 sc
->bsh
= rman_get_bushandle(sc
->mem
);
498 sc
->irq
= bus_alloc_resource_any(dev
, SYS_RES_IRQ
,
499 &sc
->irq_rid
, RF_ACTIVE
| RF_SHAREABLE
);
502 printf("%s: could not allocate interrupt resource\n",
503 device_get_nameunit(dev
));
508 sc
->tx_stbc
= rt2860_tx_stbc
;
511 sc
->debug
= rt2860_debug
;
513 SYSCTL_ADD_INT(device_get_sysctl_ctx(dev
),
514 SYSCTL_CHILDREN(device_get_sysctl_tree(dev
)), OID_AUTO
,
515 "debug", CTLFLAG_RW
, &sc
->debug
, 0, "rt2860 debug level");
518 RT2860_DPRINTF(sc
, RT2860_DEBUG_ANY
,
520 device_get_nameunit(sc
->dev
));
522 /* wait for NIC to initialize */
524 for (ntries
= 0; ntries
< 100; ntries
++)
526 sc
->mac_rev
= rt2860_io_mac_read(sc
, RT2860_REG_MAC_CSR0
);
527 if (sc
->mac_rev
!= 0x00000000 && sc
->mac_rev
!= 0xffffffff)
535 printf("%s: timeout waiting for NIC to initialize\n",
536 device_get_nameunit(dev
));
541 rt2860_read_eeprom(sc
);
543 printf("%s: MAC/BBP RT2860 (rev 0x%08x), RF %s\n",
544 device_get_nameunit(sc
->dev
), sc
->mac_rev
,
545 rt2860_rf_name(sc
->rf_rev
));
547 /* clear key tables */
549 rt2860_asic_clear_keytables(sc
);
551 /* allocate Tx and Rx rings */
553 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
555 error
= rt2860_alloc_tx_ring(sc
, &sc
->tx_ring
[i
], i
);
558 printf("%s: could not allocate Tx ring #%d\n",
559 device_get_nameunit(sc
->dev
), i
);
564 sc
->tx_ring_mgtqid
= 5;
566 error
= rt2860_alloc_rx_ring(sc
, &sc
->rx_ring
);
569 printf("%s: could not allocate Rx ring\n",
570 device_get_nameunit(sc
->dev
));
574 callout_init(&sc
->periodic_ch
, 0);
575 callout_init_mtx(&sc
->tx_watchdog_ch
, &sc
->lock
, 0);
577 ifp
= sc
->ifp
= if_alloc(IFT_IEEE80211
);
580 printf("%s: could not if_alloc()\n",
581 device_get_nameunit(sc
->dev
));
588 if_initname(ifp
, "rt2860", device_get_unit(sc
->dev
));
590 ifp
->if_flags
= IFF_BROADCAST
| IFF_SIMPLEX
| IFF_MULTICAST
;
592 ifp
->if_init
= rt2860_init
;
593 ifp
->if_ioctl
= rt2860_ioctl
;
594 ifp
->if_start
= rt2860_start
;
596 IFQ_SET_MAXLEN(&ifp
->if_snd
, IFQ_MAXLEN
);
597 ifp
->if_snd
.ifq_drv_maxlen
= IFQ_MAXLEN
;
598 IFQ_SET_READY(&ifp
->if_snd
);
604 ic
->ic_phytype
= IEEE80211_T_HT
;
605 ic
->ic_opmode
= IEEE80211_M_STA
;
607 ic
->ic_caps
= IEEE80211_C_MONITOR
|
616 IEEE80211_C_SHPREAMBLE
|
623 ic
->ic_cryptocaps
|= IEEE80211_CRYPTO_WEP
|
624 IEEE80211_CRYPTO_TKIP
|
625 IEEE80211_CRYPTO_TKIPMIC
|
626 IEEE80211_CRYPTO_AES_CCM
;
628 ic
->ic_htcaps
= IEEE80211_HTC_HT
|
629 IEEE80211_HTC_AMSDU
| /* A-MSDU Tx */
630 IEEE80211_HTC_AMPDU
| /* A-MPDU Tx */
631 IEEE80211_HTC_SMPS
| /* MIMO power save */
632 IEEE80211_HTCAP_MAXAMSDU_3839
| /* max. A-MSDU Rx length */
633 IEEE80211_HTCAP_CHWIDTH40
| /* HT 40MHz channel width */
634 IEEE80211_HTCAP_GREENFIELD
| /* HT greenfield */
635 IEEE80211_HTCAP_SHORTGI20
| /* HT 20MHz short GI */
636 IEEE80211_HTCAP_SHORTGI40
| /* HT 40MHz short GI */
637 IEEE80211_HTCAP_SMPS_OFF
; /* MIMO power save disabled */
639 /* spatial streams */
641 if (sc
->nrxpath
== 2)
642 ic
->ic_htcaps
|= IEEE80211_HTCAP_RXSTBC_2STREAM
;
643 else if (sc
->nrxpath
== 3)
644 ic
->ic_htcaps
|= IEEE80211_HTCAP_RXSTBC_3STREAM
;
646 ic
->ic_htcaps
|= IEEE80211_HTCAP_RXSTBC_1STREAM
;
649 ic
->ic_htcaps
|= IEEE80211_HTCAP_TXSTBC
;
653 if (sc
->mac_rev
!= 0x28600100)
654 ic
->ic_htcaps
|= IEEE80211_HTCAP_DELBA
;
660 rt2860_init_channels(sc
);
662 rt2860_init_channels_ht40(sc
);
664 ieee80211_ifattach(ic
, sc
->mac_addr
);
666 ic
->ic_vap_create
= rt2860_vap_create
;
667 ic
->ic_vap_delete
= rt2860_vap_delete
;
669 ic
->ic_node_alloc
= rt2860_node_alloc
;
671 sc
->node_cleanup
= ic
->ic_node_cleanup
;
672 ic
->ic_node_cleanup
= rt2860_node_cleanup
;
674 ic
->ic_node_getmimoinfo
= rt2860_node_getmimoinfo
;
675 ic
->ic_setregdomain
= rt2860_setregdomain
;
676 ic
->ic_getradiocaps
= rt2860_getradiocaps
;
677 ic
->ic_scan_start
= rt2860_scan_start
;
678 ic
->ic_scan_end
= rt2860_scan_end
;
679 ic
->ic_set_channel
= rt2860_set_channel
;
680 ic
->ic_newassoc
= rt2860_newassoc
;
681 ic
->ic_updateslot
= rt2860_updateslot
;
682 ic
->ic_update_promisc
= rt2860_update_promisc
;
683 ic
->ic_update_mcast
= rt2860_update_mcast
;
684 ic
->ic_wme
.wme_update
= rt2860_wme_update
;
685 ic
->ic_raw_xmit
= rt2860_raw_xmit
;
687 sc
->recv_action
= ic
->ic_recv_action
;
688 ic
->ic_recv_action
= rt2860_recv_action
;
690 sc
->send_action
= ic
->ic_send_action
;
691 ic
->ic_send_action
= rt2860_send_action
;
693 sc
->addba_response
= ic
->ic_addba_response
;
694 ic
->ic_addba_response
= rt2860_addba_response
;
696 sc
->addba_stop
= ic
->ic_addba_stop
;
697 ic
->ic_addba_stop
= rt2860_addba_stop
;
699 sc
->ampdu_rx_start
= ic
->ic_ampdu_rx_start
;
700 ic
->ic_ampdu_rx_start
= rt2860_ampdu_rx_start
;
702 sc
->ampdu_rx_stop
= ic
->ic_ampdu_rx_stop
;
703 ic
->ic_ampdu_rx_stop
= rt2860_ampdu_rx_stop
;
705 /* hardware requires padding between 802.11 frame header and body */
707 ic
->ic_flags
|= IEEE80211_F_DATAPAD
| IEEE80211_F_DOTH
;
709 ic
->ic_flags_ext
|= IEEE80211_FEXT_SWBMISS
;
711 ieee80211_radiotap_attach(ic
,
712 &sc
->txtap
.ihdr
, sizeof(sc
->txtap
),
713 RT2860_SOFTC_TX_RADIOTAP_PRESENT
,
714 &sc
->rxtap
.ihdr
, sizeof(sc
->rxtap
),
715 RT2860_SOFTC_RX_RADIOTAP_PRESENT
);
717 /* init task queue */
719 TASK_INIT(&sc
->rx_done_task
, 0, rt2860_rx_done_task
, sc
);
720 TASK_INIT(&sc
->tx_done_task
, 0, rt2860_tx_done_task
, sc
);
721 TASK_INIT(&sc
->fifo_sta_full_task
, 0, rt2860_fifo_sta_full_task
, sc
);
722 TASK_INIT(&sc
->periodic_task
, 0, rt2860_periodic_task
, sc
);
724 sc
->rx_process_limit
= 100;
726 sc
->taskqueue
= taskqueue_create("rt2860_taskq", M_NOWAIT
,
727 taskqueue_thread_enqueue
, &sc
->taskqueue
);
729 taskqueue_start_threads(&sc
->taskqueue
, 1, PI_NET
, "%s taskq",
730 device_get_nameunit(sc
->dev
));
732 rt2860_sysctl_attach(sc
);
735 ieee80211_announce(ic
);
737 /* set up interrupt */
739 error
= bus_setup_intr(dev
, sc
->irq
, INTR_TYPE_NET
| INTR_MPSAFE
,
740 NULL
, rt2860_intr
, sc
, &sc
->irqh
);
743 printf("%s: could not set up interrupt\n",
744 device_get_nameunit(dev
));
752 /* free Tx and Rx rings */
754 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
755 rt2860_free_tx_ring(sc
, &sc
->tx_ring
[i
]);
757 rt2860_free_rx_ring(sc
, &sc
->rx_ring
);
759 mtx_destroy(&sc
->lock
);
762 bus_release_resource(dev
, SYS_RES_MEMORY
, sc
->mem_rid
, sc
->mem
);
765 bus_release_resource(dev
, SYS_RES_IRQ
, sc
->irq_rid
, sc
->irq
);
773 static int rt2860_detach(device_t dev
)
775 struct rt2860_softc
*sc
;
777 struct ieee80211com
*ic
;
780 sc
= device_get_softc(dev
);
784 RT2860_DPRINTF(sc
, RT2860_DEBUG_ANY
,
786 device_get_nameunit(sc
->dev
));
788 RT2860_SOFTC_LOCK(sc
);
790 ifp
->if_drv_flags
&= ~(IFF_DRV_RUNNING
| IFF_DRV_OACTIVE
);
792 callout_stop(&sc
->periodic_ch
);
793 callout_stop(&sc
->tx_watchdog_ch
);
795 taskqueue_drain(sc
->taskqueue
, &sc
->rx_done_task
);
796 taskqueue_drain(sc
->taskqueue
, &sc
->tx_done_task
);
797 taskqueue_drain(sc
->taskqueue
, &sc
->fifo_sta_full_task
);
798 taskqueue_drain(sc
->taskqueue
, &sc
->periodic_task
);
800 /* free Tx and Rx rings */
802 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
803 rt2860_free_tx_ring(sc
, &sc
->tx_ring
[i
]);
805 rt2860_free_rx_ring(sc
, &sc
->rx_ring
);
807 RT2860_SOFTC_UNLOCK(sc
);
809 ieee80211_ifdetach(ic
);
813 taskqueue_free(sc
->taskqueue
);
815 mtx_destroy(&sc
->lock
);
817 bus_generic_detach(dev
);
819 bus_teardown_intr(dev
, sc
->irq
, sc
->irqh
);
821 bus_release_resource(dev
, SYS_RES_IRQ
, sc
->irq_rid
, sc
->irq
);
823 bus_release_resource(dev
, SYS_RES_MEMORY
, sc
->mem_rid
, sc
->mem
);
831 static int rt2860_shutdown(device_t dev
)
833 struct rt2860_softc
*sc
;
835 sc
= device_get_softc(dev
);
837 RT2860_DPRINTF(sc
, RT2860_DEBUG_ANY
,
838 "%s: shutting down\n",
839 device_get_nameunit(sc
->dev
));
843 sc
->flags
&= ~RT2860_SOFTC_FLAGS_UCODE_LOADED
;
851 static int rt2860_suspend(device_t dev
)
853 struct rt2860_softc
*sc
;
855 sc
= device_get_softc(dev
);
857 RT2860_DPRINTF(sc
, RT2860_DEBUG_ANY
,
859 device_get_nameunit(sc
->dev
));
863 sc
->flags
&= ~RT2860_SOFTC_FLAGS_UCODE_LOADED
;
871 static int rt2860_resume(device_t dev
)
873 struct rt2860_softc
*sc
;
876 sc
= device_get_softc(dev
);
879 RT2860_DPRINTF(sc
, RT2860_DEBUG_ANY
,
881 device_get_nameunit(sc
->dev
));
883 if (ifp
->if_flags
& IFF_UP
)
890 * rt2860_init_channels
892 static void rt2860_init_channels(struct rt2860_softc
*sc
)
895 struct ieee80211com
*ic
;
896 struct ieee80211_channel
*c
;
902 /* set supported channels for 2GHz band */
904 for (i
= 1; i
<= 14; i
++)
906 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
907 flags
= IEEE80211_CHAN_B
;
909 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
913 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
914 flags
= IEEE80211_CHAN_B
| IEEE80211_CHAN_HT20
;
916 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
920 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
921 flags
= IEEE80211_CHAN_G
;
923 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
927 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
928 flags
= IEEE80211_CHAN_G
| IEEE80211_CHAN_HT20
;
930 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
935 /* set supported channels for 5GHz band */
937 if (sc
->rf_rev
== RT2860_EEPROM_RF_2850
||
938 sc
->rf_rev
== RT2860_EEPROM_RF_2750
)
940 for (i
= 36; i
<= 64; i
+= 4)
942 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
943 flags
= IEEE80211_CHAN_A
;
945 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
949 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
950 flags
= IEEE80211_CHAN_A
| IEEE80211_CHAN_HT20
;
952 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
957 for (i
= 100; i
<= 140; i
+= 4)
959 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
960 flags
= IEEE80211_CHAN_A
;
962 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
966 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
967 flags
= IEEE80211_CHAN_A
| IEEE80211_CHAN_HT20
;
969 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
974 for (i
= 149; i
<= 165; i
+= 4)
976 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
977 flags
= IEEE80211_CHAN_A
;
979 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
983 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
984 flags
= IEEE80211_CHAN_A
| IEEE80211_CHAN_HT20
;
986 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
994 * rt2860_init_channels_ht40
996 static void rt2860_init_channels_ht40(struct rt2860_softc
*sc
)
999 struct ieee80211com
*ic
;
1000 struct ieee80211_channel
*c
, *cent
, *ext
;
1006 /* set supported channels for 2GHz band */
1008 for (i
= 1; i
<= 14; i
++)
1010 flags
= IEEE80211_CHAN_G
| IEEE80211_CHAN_HT40
;
1012 /* find the center channel */
1014 cent
= ieee80211_find_channel_byieee(ic
, i
,
1015 flags
& ~IEEE80211_CHAN_HT
);
1018 printf("%s: skip channel %d, could not find center channel\n",
1019 device_get_nameunit(sc
->dev
), i
);
1023 /* find the extension channel */
1025 ext
= ieee80211_find_channel(ic
, cent
->ic_freq
+ 20,
1026 flags
& ~IEEE80211_CHAN_HT
);
1029 printf("%s: skip channel %d, could not find extension channel\n",
1030 device_get_nameunit(sc
->dev
), i
);
1034 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1037 c
->ic_extieee
= ext
->ic_ieee
;
1038 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1039 c
->ic_flags
|= IEEE80211_CHAN_HT40U
;
1041 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1044 c
->ic_extieee
= cent
->ic_ieee
;
1045 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1046 c
->ic_flags
|= IEEE80211_CHAN_HT40D
;
1049 /* set supported channels for 5GHz band */
1051 if (sc
->rf_rev
== RT2860_EEPROM_RF_2850
||
1052 sc
->rf_rev
== RT2860_EEPROM_RF_2750
)
1054 for (i
= 36; i
<= 64; 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
= 100; i
<= 140; 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
;
1136 for (i
= 149; i
<= 165; i
+= 4)
1138 flags
= IEEE80211_CHAN_A
| IEEE80211_CHAN_HT40
;
1140 /* find the center channel */
1142 cent
= ieee80211_find_channel_byieee(ic
, i
,
1143 flags
& ~IEEE80211_CHAN_HT
);
1146 printf("%s: skip channel %d, could not find center channel\n",
1147 device_get_nameunit(sc
->dev
), i
);
1151 /* find the extension channel */
1153 ext
= ieee80211_find_channel(ic
, cent
->ic_freq
+ 20,
1154 flags
& ~IEEE80211_CHAN_HT
);
1157 printf("%s: skip channel %d, could not find extension channel\n",
1158 device_get_nameunit(sc
->dev
), i
);
1162 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1165 c
->ic_extieee
= ext
->ic_ieee
;
1166 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1167 c
->ic_flags
|= IEEE80211_CHAN_HT40U
;
1169 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1172 c
->ic_extieee
= cent
->ic_ieee
;
1173 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1174 c
->ic_flags
|= IEEE80211_CHAN_HT40D
;
1180 * rt2860_init_locked
1182 static void rt2860_init_locked(void *priv
)
1184 struct rt2860_softc
*sc
;
1186 struct ieee80211com
*ic
;
1187 int error
, i
, ntries
;
1188 uint32_t tmp
, stacnt
[6];
1194 RT2860_DPRINTF(sc
, RT2860_DEBUG_ANY
,
1195 "%s: initializing\n",
1196 device_get_nameunit(sc
->dev
));
1198 RT2860_SOFTC_ASSERT_LOCKED(sc
);
1200 if (!(sc
->flags
& RT2860_SOFTC_FLAGS_UCODE_LOADED
))
1202 RT2860_DPRINTF(sc
, RT2860_DEBUG_ANY
,
1203 "%s: loading 8051 microcode\n",
1204 device_get_nameunit(sc
->dev
));
1206 error
= rt2860_io_mcu_load_ucode(sc
, rt2860_ucode
, sizeof(rt2860_ucode
));
1209 printf("%s: could not load 8051 microcode\n",
1210 device_get_nameunit(sc
->dev
));
1214 RT2860_DPRINTF(sc
, RT2860_DEBUG_ANY
,
1215 "%s: 8051 microcode was successfully loaded\n",
1216 device_get_nameunit(sc
->dev
));
1218 sc
->flags
|= RT2860_SOFTC_FLAGS_UCODE_LOADED
;
1221 rt2860_io_mac_write(sc
, RT2860_REG_PWR_PIN_CFG
, 0x2);
1223 /* disable DMA engine */
1225 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
);
1228 tmp
|= RT2860_REG_TX_WB_DDONE
;
1230 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
, tmp
);
1232 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WPDMA_RST_IDX
, 0xffffffff);
1234 /* PBF hardware reset */
1236 rt2860_io_mac_write(sc
, RT2860_REG_PBF_SYS_CTRL
, 0xe1f);
1237 rt2860_io_mac_write(sc
, RT2860_REG_PBF_SYS_CTRL
, 0xe00);
1239 /* wait while DMA engine is busy */
1241 for (ntries
= 0; ntries
< 100; ntries
++)
1243 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
);
1244 if (!(tmp
& (RT2860_REG_TX_DMA_BUSY
| RT2860_REG_RX_DMA_BUSY
)))
1252 printf("%s: timeout waiting for DMA engine\n",
1253 device_get_nameunit(sc
->dev
));
1258 tmp
|= RT2860_REG_TX_WB_DDONE
;
1260 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
, tmp
);
1262 /* reset Rx and Tx rings */
1264 tmp
= RT2860_REG_RST_IDX_RX
|
1265 RT2860_REG_RST_IDX_TX_MGMT
|
1266 RT2860_REG_RST_IDX_TX_HCCA
|
1267 RT2860_REG_RST_IDX_TX_AC3
|
1268 RT2860_REG_RST_IDX_TX_AC2
|
1269 RT2860_REG_RST_IDX_TX_AC1
|
1270 RT2860_REG_RST_IDX_TX_AC0
;
1272 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WPDMA_RST_IDX
, tmp
);
1274 /* PBF hardware reset */
1276 rt2860_io_mac_write(sc
, RT2860_REG_PBF_SYS_CTRL
, 0xe1f);
1277 rt2860_io_mac_write(sc
, RT2860_REG_PBF_SYS_CTRL
, 0xe00);
1279 rt2860_io_mac_write(sc
, RT2860_REG_PWR_PIN_CFG
, 0x3);
1281 rt2860_io_mac_write(sc
, RT2860_REG_SYS_CTRL
,
1282 RT2860_REG_MAC_SRST
| RT2860_REG_BBP_HRST
);
1283 rt2860_io_mac_write(sc
, RT2860_REG_SYS_CTRL
, 0);
1285 /* init Tx power per rate */
1287 for (i
= 0; i
< RT2860_SOFTC_TXPOW_RATE_COUNT
; i
++)
1289 if (sc
->txpow_rate_20mhz
[i
] == 0xffffffff)
1292 rt2860_io_mac_write(sc
, RT2860_REG_TX_PWR_CFG(i
),
1293 sc
->txpow_rate_20mhz
[i
]);
1296 for (i
= 0; i
< RT2860_DEF_MAC_SIZE
; i
++)
1297 rt2860_io_mac_write(sc
, rt2860_def_mac
[i
].reg
,
1298 rt2860_def_mac
[i
].val
);
1300 /* wait while MAC is busy */
1302 for (ntries
= 0; ntries
< 100; ntries
++)
1304 if (!(rt2860_io_mac_read(sc
, RT2860_REG_STATUS_CFG
) &
1305 (RT2860_REG_STATUS_TX_BUSY
| RT2860_REG_STATUS_RX_BUSY
)))
1313 printf("%s: timeout waiting for MAC\n",
1314 device_get_nameunit(sc
->dev
));
1318 /* clear Host to MCU mailbox */
1320 rt2860_io_mac_write(sc
, RT2860_REG_H2M_MAILBOX_BBP_AGENT
, 0);
1321 rt2860_io_mac_write(sc
, RT2860_REG_H2M_MAILBOX
, 0);
1323 rt2860_io_mcu_cmd(sc
, RT2860_IO_MCU_CMD_BOOT
,
1324 RT2860_REG_H2M_TOKEN_NO_INTR
, 0);
1328 error
= rt2860_init_bbp(sc
);
1332 /* set up maximum buffer sizes */
1334 tmp
= (1 << 12) | RT2860_MAX_AGG_SIZE
;
1336 rt2860_io_mac_write(sc
, RT2860_REG_MAX_LEN_CFG
, tmp
);
1338 if (sc
->mac_rev
== 0x28720200)
1340 /* set max. PSDU length from 16K to 32K bytes */
1342 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_MAX_LEN_CFG
);
1347 rt2860_io_mac_write(sc
, RT2860_REG_MAX_LEN_CFG
, tmp
);
1350 if (sc
->mac_rev
>= 0x28720200 && sc
->mac_rev
< 0x30700200)
1352 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_MAX_LEN_CFG
);
1357 rt2860_io_mac_write(sc
, RT2860_REG_MAX_LEN_CFG
, tmp
);
1360 /* set mac address */
1362 rt2860_asic_set_macaddr(sc
, IF_LLADDR(ifp
));
1364 /* clear statistic registers */
1366 rt2860_io_mac_read_multi(sc
, RT2860_REG_RX_STA_CNT0
,
1367 stacnt
, sizeof(stacnt
));
1369 /* set RTS threshold */
1371 rt2860_asic_update_rtsthreshold(sc
);
1375 rt2860_asic_update_txpower(sc
);
1377 /* set up protection mode */
1379 sc
->tx_ampdu_sessions
= 0;
1381 rt2860_asic_updateprot(sc
);
1383 /* clear beacon frame space (entries = 8, entry size = 512) */
1385 rt2860_io_mac_set_region_4(sc
, RT2860_REG_BEACON_BASE(0), 0, 1024);
1387 taskqueue_unblock(sc
->taskqueue
);
1389 /* init Tx rings (4 EDCAs + HCCA + MGMT) */
1391 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
1392 rt2860_reset_tx_ring(sc
, &sc
->tx_ring
[i
]);
1394 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
1396 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_BASE_PTR(i
),
1397 sc
->tx_ring
[i
].desc_phys_addr
);
1398 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_MAX_CNT(i
),
1399 RT2860_SOFTC_TX_RING_DESC_COUNT
);
1400 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_CTX_IDX(i
), 0);
1405 rt2860_reset_rx_ring(sc
, &sc
->rx_ring
);
1407 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_BASE_PTR
,
1408 sc
->rx_ring
.desc_phys_addr
);
1409 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_MAX_CNT
,
1410 RT2860_SOFTC_RX_RING_DATA_COUNT
);
1411 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_CALC_IDX
,
1412 RT2860_SOFTC_RX_RING_DATA_COUNT
- 1);
1414 /* wait while DMA engine is busy */
1416 for (ntries
= 0; ntries
< 100; ntries
++)
1418 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
);
1419 if (!(tmp
& (RT2860_REG_TX_DMA_BUSY
| RT2860_REG_RX_DMA_BUSY
)))
1427 printf("%s: timeout waiting for DMA engine\n",
1428 device_get_nameunit(sc
->dev
));
1433 tmp
|= RT2860_REG_TX_WB_DDONE
;
1435 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
, tmp
);
1437 /* disable interrupts mitigation */
1439 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_DELAY_INT_CFG
, 0);
1441 /* send LEDs operating mode to microcontroller */
1443 rt2860_io_mcu_cmd(sc
, RT2860_IO_MCU_CMD_LED1
,
1444 RT2860_REG_H2M_TOKEN_NO_INTR
, sc
->led_off
[0]);
1445 rt2860_io_mcu_cmd(sc
, RT2860_IO_MCU_CMD_LED2
,
1446 RT2860_REG_H2M_TOKEN_NO_INTR
, sc
->led_off
[1]);
1447 rt2860_io_mcu_cmd(sc
, RT2860_IO_MCU_CMD_LED3
,
1448 RT2860_REG_H2M_TOKEN_NO_INTR
, sc
->led_off
[2]);
1450 /* turn radio LED on */
1452 rt2860_led_cmd(sc
, RT2860_LED_CMD_RADIO_ON
);
1454 /* write vendor-specific BBP values (from EEPROM) */
1456 for (i
= 0; i
< RT2860_SOFTC_BBP_EEPROM_COUNT
; i
++)
1458 if (sc
->bbp_eeprom
[i
].reg
== 0x00 ||
1459 sc
->bbp_eeprom
[i
].reg
== 0xff)
1462 rt2860_io_bbp_write(sc
, sc
->bbp_eeprom
[i
].reg
,
1463 sc
->bbp_eeprom
[i
].val
);
1466 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_GPIO_CTRL_CFG
);
1469 rt2860_io_mcu_cmd(sc
, RT2860_IO_MCU_CMD_SLEEP
,
1470 RT2860_REG_H2M_TOKEN_RADIOOFF
, 0x02ff);
1471 rt2860_io_mcu_cmd_check(sc
, RT2860_REG_H2M_TOKEN_RADIOOFF
);
1473 rt2860_io_mcu_cmd(sc
, RT2860_IO_MCU_CMD_WAKEUP
,
1474 RT2860_REG_H2M_TOKEN_WAKEUP
, 0);
1475 rt2860_io_mcu_cmd_check(sc
, RT2860_REG_H2M_TOKEN_WAKEUP
);
1478 /* disable non-existing Rx chains */
1480 tmp
= rt2860_io_bbp_read(sc
, 3);
1482 tmp
&= ~((1 << 4) | (1 << 3));
1484 if (sc
->nrxpath
== 3)
1486 else if (sc
->nrxpath
== 2)
1489 rt2860_io_bbp_write(sc
, 3, tmp
);
1491 /* disable non-existing Tx chains */
1493 tmp
= rt2860_io_bbp_read(sc
, 1);
1495 tmp
&= ~((1 << 4) | (1 << 3));
1497 if (sc
->ntxpath
== 2)
1500 rt2860_io_bbp_write(sc
, 1, tmp
);
1502 /* set current channel */
1504 rt2860_rf_set_chan(sc
, ic
->ic_curchan
);
1506 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WMM_TXOP0_CFG
, 0);
1507 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WMM_TXOP1_CFG
,
1510 if ((sc
->mac_rev
& 0xffff) != 0x0101)
1511 rt2860_io_mac_write(sc
, RT2860_REG_TX_TXOP_CTRL_CFG
, 0x583f);
1513 /* clear pending interrupts */
1515 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_INT_STATUS
, 0xffffffff);
1517 /* enable interrupts */
1519 tmp
= RT2860_REG_INT_TX_COHERENT
|
1520 RT2860_REG_INT_RX_COHERENT
|
1521 RT2860_REG_INT_GP_TIMER
|
1522 RT2860_REG_INT_AUTO_WAKEUP
|
1523 RT2860_REG_INT_FIFO_STA_FULL
|
1524 RT2860_REG_INT_PRE_TBTT
|
1525 RT2860_REG_INT_TBTT
|
1526 RT2860_REG_INT_TXRX_COHERENT
|
1527 RT2860_REG_INT_MCU_CMD
|
1528 RT2860_REG_INT_TX_MGMT_DONE
|
1529 RT2860_REG_INT_TX_HCCA_DONE
|
1530 RT2860_REG_INT_TX_AC3_DONE
|
1531 RT2860_REG_INT_TX_AC2_DONE
|
1532 RT2860_REG_INT_TX_AC1_DONE
|
1533 RT2860_REG_INT_TX_AC0_DONE
|
1534 RT2860_REG_INT_RX_DONE
;
1536 sc
->intr_enable_mask
= tmp
;
1538 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_INT_MASK
, tmp
);
1540 if (rt2860_txrx_enable(sc
) != 0)
1543 /* clear garbage interrupts */
1545 tmp
= rt2860_io_mac_read(sc
, 0x1300);
1547 ifp
->if_drv_flags
&= ~IFF_DRV_OACTIVE
;
1548 ifp
->if_drv_flags
|= IFF_DRV_RUNNING
;
1550 sc
->periodic_round
= 0;
1552 callout_reset(&sc
->periodic_ch
, hz
/ 10, rt2860_periodic
, sc
);
1558 rt2860_stop_locked(sc
);
1564 static void rt2860_init(void *priv
)
1566 struct rt2860_softc
*sc
;
1570 RT2860_SOFTC_LOCK(sc
);
1572 rt2860_init_locked(sc
);
1574 RT2860_SOFTC_UNLOCK(sc
);
1580 static int rt2860_init_bbp(struct rt2860_softc
*sc
)
1585 for (ntries
= 0; ntries
< 20; ntries
++)
1587 tmp
= rt2860_io_bbp_read(sc
, 0);
1588 if (tmp
!= 0x00 && tmp
!= 0xff)
1592 if (tmp
== 0x00 || tmp
== 0xff)
1594 printf("%s: timeout waiting for BBP to wakeup\n",
1595 device_get_nameunit(sc
->dev
));
1599 for (i
= 0; i
< RT2860_DEF_BBP_SIZE
; i
++)
1600 rt2860_io_bbp_write(sc
, rt2860_def_bbp
[i
].reg
,
1601 rt2860_def_bbp
[i
].val
);
1603 if ((sc
->mac_rev
& 0xffff) != 0x0101)
1604 rt2860_io_bbp_write(sc
, 84, 0x19);
1606 if (sc
->mac_rev
== 0x28600100)
1608 rt2860_io_bbp_write(sc
, 69, 0x16);
1609 rt2860_io_bbp_write(sc
, 73, 0x12);
1616 * rt2860_stop_locked
1618 static void rt2860_stop_locked(void *priv
)
1620 struct rt2860_softc
*sc
;
1622 struct ieee80211com
*ic
;
1629 RT2860_DPRINTF(sc
, RT2860_DEBUG_ANY
,
1631 device_get_nameunit(sc
->dev
));
1633 RT2860_SOFTC_ASSERT_LOCKED(sc
);
1637 if (ifp
->if_drv_flags
& IFF_DRV_RUNNING
)
1638 rt2860_led_cmd(sc
, RT2860_LED_CMD_RADIO_OFF
);
1640 ifp
->if_drv_flags
&= ~(IFF_DRV_RUNNING
| IFF_DRV_OACTIVE
);
1642 callout_stop(&sc
->periodic_ch
);
1643 callout_stop(&sc
->tx_watchdog_ch
);
1645 RT2860_SOFTC_UNLOCK(sc
);
1647 taskqueue_block(sc
->taskqueue
);
1649 taskqueue_drain(sc
->taskqueue
, &sc
->rx_done_task
);
1650 taskqueue_drain(sc
->taskqueue
, &sc
->tx_done_task
);
1651 taskqueue_drain(sc
->taskqueue
, &sc
->fifo_sta_full_task
);
1652 taskqueue_drain(sc
->taskqueue
, &sc
->periodic_task
);
1654 RT2860_SOFTC_LOCK(sc
);
1656 /* clear key tables */
1658 rt2860_asic_clear_keytables(sc
);
1660 /* disable interrupts */
1662 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_INT_MASK
, 0);
1666 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_SYS_CTRL
);
1668 tmp
&= ~(RT2860_REG_RX_ENABLE
| RT2860_REG_TX_ENABLE
);
1670 rt2860_io_mac_write(sc
, RT2860_REG_SYS_CTRL
, tmp
);
1674 rt2860_io_mac_write(sc
, RT2860_REG_SYS_CTRL
,
1675 RT2860_REG_MAC_SRST
| RT2860_REG_BBP_HRST
);
1676 rt2860_io_mac_write(sc
, RT2860_REG_SYS_CTRL
, 0);
1682 static void rt2860_stop(void *priv
)
1684 struct rt2860_softc
*sc
;
1688 RT2860_SOFTC_LOCK(sc
);
1690 rt2860_stop_locked(sc
);
1692 RT2860_SOFTC_UNLOCK(sc
);
1698 static void rt2860_start(struct ifnet
*ifp
)
1700 struct rt2860_softc
*sc
;
1701 struct ieee80211_node
*ni
;
1707 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
1712 IFQ_DRV_DEQUEUE(&ifp
->if_snd
, m
);
1716 ni
= (struct ieee80211_node
*) m
->m_pkthdr
.rcvif
;
1718 m
->m_pkthdr
.rcvif
= NULL
;
1720 qid
= M_WME_GETAC(m
);
1722 RT2860_SOFTC_TX_RING_LOCK(&sc
->tx_ring
[qid
]);
1724 if (sc
->tx_ring
[qid
].data_queued
>= RT2860_SOFTC_TX_RING_DATA_COUNT
)
1726 RT2860_SOFTC_TX_RING_UNLOCK(&sc
->tx_ring
[qid
]);
1728 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
1729 "%s: if_start: Tx ring with qid=%d is full\n",
1730 device_get_nameunit(sc
->dev
), qid
);
1733 ieee80211_free_node(ni
);
1735 ifp
->if_drv_flags
|= IFF_DRV_OACTIVE
;
1738 sc
->tx_data_queue_full
[qid
]++;
1743 if (rt2860_tx_data(sc
, m
, ni
, qid
) != 0)
1745 RT2860_SOFTC_TX_RING_UNLOCK(&sc
->tx_ring
[qid
]);
1747 ieee80211_free_node(ni
);
1754 RT2860_SOFTC_TX_RING_UNLOCK(&sc
->tx_ring
[qid
]);
1756 rt2860_drain_fifo_stats(sc
);
1758 sc
->tx_timer
= RT2860_TX_WATCHDOG_TIMEOUT
;
1760 callout_reset(&sc
->tx_watchdog_ch
, hz
, rt2860_tx_watchdog
, sc
);
1767 static int rt2860_ioctl(struct ifnet
*ifp
, u_long cmd
, caddr_t data
)
1769 struct rt2860_softc
*sc
;
1770 struct ieee80211com
*ic
;
1772 int error
, startall
;
1776 ifr
= (struct ifreq
*) data
;
1785 RT2860_SOFTC_LOCK(sc
);
1787 if (ifp
->if_flags
& IFF_UP
)
1789 if (ifp
->if_drv_flags
& IFF_DRV_RUNNING
)
1791 if ((ifp
->if_flags
^ sc
->if_flags
) & IFF_PROMISC
)
1792 rt2860_asic_update_promisc(sc
);
1796 rt2860_init_locked(sc
);
1802 if (ifp
->if_drv_flags
& IFF_DRV_RUNNING
)
1803 rt2860_stop_locked(sc
);
1806 sc
->if_flags
= ifp
->if_flags
;
1808 RT2860_SOFTC_UNLOCK(sc
);
1811 ieee80211_start_all(ic
);
1816 error
= ifmedia_ioctl(ifp
, ifr
, &ic
->ic_media
, cmd
);
1820 error
= ether_ioctl(ifp
, cmd
, data
);
1834 static struct ieee80211vap
*rt2860_vap_create(struct ieee80211com
*ic
,
1835 const char name
[IFNAMSIZ
], int unit
, int opmode
, int flags
,
1836 const uint8_t bssid
[IEEE80211_ADDR_LEN
],
1837 const uint8_t mac
[IEEE80211_ADDR_LEN
])
1839 struct rt2860_softc
*sc
;
1841 struct rt2860_softc_vap
*rvap
;
1842 struct ieee80211vap
*vap
;
1847 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATE
,
1848 "%s: VAP create: opmode=%s\n",
1849 device_get_nameunit(sc
->dev
),
1850 ieee80211_opmode_name
[opmode
]);
1854 case IEEE80211_M_IBSS
:
1855 case IEEE80211_M_STA
:
1856 case IEEE80211_M_AHDEMO
:
1857 case IEEE80211_M_HOSTAP
:
1858 case IEEE80211_M_MBSS
:
1859 if ((sc
->napvaps
+ sc
->nadhocvaps
+ sc
->nstavaps
) != 0)
1861 if_printf(ifp
, "only 1 VAP supported\n");
1865 if (opmode
== IEEE80211_M_STA
)
1866 flags
|= IEEE80211_CLONE_NOBEACONS
;
1869 case IEEE80211_M_WDS
:
1870 if (sc
->napvaps
== 0)
1872 if_printf(ifp
, "WDS only supported in AP mode\n");
1877 case IEEE80211_M_MONITOR
:
1881 if_printf(ifp
, "unknown opmode %d\n", opmode
);
1885 rvap
= (struct rt2860_softc_vap
*) malloc(sizeof(struct rt2860_softc_vap
),
1886 M_80211_VAP
, M_NOWAIT
| M_ZERO
);
1892 ieee80211_vap_setup(ic
, vap
, name
, unit
, opmode
, flags
, bssid
, mac
);
1894 rvap
->newstate
= vap
->iv_newstate
;
1895 vap
->iv_newstate
= rt2860_vap_newstate
;
1897 vap
->iv_reset
= rt2860_vap_reset
;
1898 vap
->iv_key_update_begin
= rt2860_vap_key_update_begin
;
1899 vap
->iv_key_update_end
= rt2860_vap_key_update_end
;
1900 vap
->iv_key_set
= rt2860_vap_key_set
;
1901 vap
->iv_key_delete
= rt2860_vap_key_delete
;
1902 vap
->iv_update_beacon
= rt2860_vap_update_beacon
;
1904 rt2860_amrr_init(&rvap
->amrr
, vap
,
1906 RT2860_AMRR_MIN_SUCCESS_THRESHOLD
,
1907 RT2860_AMRR_MAX_SUCCESS_THRESHOLD
,
1910 vap
->iv_max_aid
= RT2860_SOFTC_STAID_COUNT
;
1912 /* override default Rx A-MPDU factor */
1914 vap
->iv_ampdu_rxmax
= IEEE80211_HTCAP_MAXRXAMPDU_32K
;
1915 vap
->iv_ampdu_density
= IEEE80211_HTCAP_MPDUDENSITY_NA
;
1916 vap
->iv_ampdu_limit
= vap
->iv_ampdu_rxmax
;
1918 ieee80211_vap_attach(vap
, rt2860_media_change
, ieee80211_media_status
);
1920 switch (vap
->iv_opmode
)
1922 case IEEE80211_M_HOSTAP
:
1923 case IEEE80211_M_MBSS
:
1924 case IEEE80211_M_AHDEMO
:
1928 case IEEE80211_M_IBSS
:
1932 case IEEE80211_M_STA
:
1936 case IEEE80211_M_WDS
:
1946 if (sc
->napvaps
> 0)
1947 ic
->ic_opmode
= IEEE80211_M_HOSTAP
;
1948 else if (sc
->nadhocvaps
> 0)
1949 ic
->ic_opmode
= IEEE80211_M_IBSS
;
1950 else if (sc
->nstavaps
> 0)
1951 ic
->ic_opmode
= IEEE80211_M_STA
;
1953 ic
->ic_opmode
= opmode
;
1961 static void rt2860_vap_delete(struct ieee80211vap
*vap
)
1963 struct rt2860_softc
*sc
;
1964 struct ieee80211com
*ic
;
1966 struct rt2860_softc_vap
*rvap
;
1967 enum ieee80211_opmode opmode
;
1972 rvap
= (struct rt2860_softc_vap
*) vap
;
1973 opmode
= vap
->iv_opmode
;
1975 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATE
,
1976 "%s: VAP delete: opmode=%s\n",
1977 device_get_nameunit(sc
->dev
), ieee80211_opmode_name
[opmode
]);
1979 rt2860_amrr_cleanup(&rvap
->amrr
);
1981 ieee80211_vap_detach(vap
);
1983 if (rvap
->beacon_mbuf
!= NULL
)
1985 m_free(rvap
->beacon_mbuf
);
1986 rvap
->beacon_mbuf
= NULL
;
1991 case IEEE80211_M_HOSTAP
:
1992 case IEEE80211_M_MBSS
:
1993 case IEEE80211_M_AHDEMO
:
1997 case IEEE80211_M_IBSS
:
2001 case IEEE80211_M_STA
:
2005 case IEEE80211_M_WDS
:
2015 if (sc
->napvaps
> 0)
2016 ic
->ic_opmode
= IEEE80211_M_HOSTAP
;
2017 else if (sc
->nadhocvaps
> 0)
2018 ic
->ic_opmode
= IEEE80211_M_IBSS
;
2019 else if (sc
->nstavaps
> 0)
2020 ic
->ic_opmode
= IEEE80211_M_STA
;
2022 free(rvap
, M_80211_VAP
);
2028 static int rt2860_vap_reset(struct ieee80211vap
*vap
, u_long cmd
)
2030 struct rt2860_softc
*sc
;
2031 struct ieee80211com
*ic
;
2033 struct rt2860_softc_vap
*rvap
;
2039 rvap
= (struct rt2860_softc_vap
*) vap
;
2041 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATE
,
2042 "%s: VAP reset: cmd=%lu\n",
2043 device_get_nameunit(sc
->dev
), cmd
);
2049 case IEEE80211_IOC_RTSTHRESHOLD
:
2050 case IEEE80211_IOC_AMSDU
:
2051 rt2860_asic_update_rtsthreshold(sc
);
2054 case IEEE80211_IOC_PROTMODE
:
2055 case IEEE80211_IOC_HTPROTMODE
:
2056 rt2860_asic_updateprot(sc
);
2059 case IEEE80211_IOC_TXPOWER
:
2060 rt2860_asic_update_txpower(sc
);
2063 case IEEE80211_IOC_BURST
:
2064 rt2860_asic_updateslot(sc
);
2067 case IEEE80211_IOC_SHORTGI
:
2068 case IEEE80211_IOC_AMPDU_DENSITY
:
2069 case IEEE80211_IOC_SMPS
:
2081 * rt2860_vap_newstate
2083 static int rt2860_vap_newstate(struct ieee80211vap
*vap
,
2084 enum ieee80211_state nstate
, int arg
)
2086 struct rt2860_softc
*sc
;
2087 struct ieee80211com
*ic
;
2089 struct rt2860_softc_vap
*rvap
;
2090 struct ieee80211_node
*ni
;
2091 enum ieee80211_state ostate
;
2097 rvap
= (struct rt2860_softc_vap
*) vap
;
2099 ostate
= vap
->iv_state
;
2101 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATE
,
2102 "%s: VAP newstate: %s -> %s\n",
2103 device_get_nameunit(sc
->dev
),
2104 ieee80211_state_name
[ostate
], ieee80211_state_name
[nstate
]);
2106 error
= rvap
->newstate(vap
, nstate
, arg
);
2110 IEEE80211_UNLOCK(ic
);
2112 RT2860_SOFTC_LOCK(sc
);
2114 /* turn link LED off */
2116 if (nstate
!= IEEE80211_S_RUN
)
2117 rt2860_led_cmd(sc
, RT2860_LED_CMD_RADIO_OFF
);
2121 case IEEE80211_S_INIT
:
2122 rt2860_asic_disable_tsf_sync(sc
);
2125 case IEEE80211_S_RUN
:
2128 rt2860_rf_set_chan(sc
, ni
->ni_chan
);
2130 if (vap
->iv_opmode
!= IEEE80211_M_MONITOR
)
2132 rt2860_asic_enable_mrr(sc
);
2133 rt2860_asic_set_txpreamble(sc
);
2134 rt2860_asic_set_basicrates(sc
);
2135 rt2860_asic_update_txpower(sc
);
2136 rt2860_asic_set_bssid(sc
, ni
->ni_bssid
);
2139 if (vap
->iv_opmode
== IEEE80211_M_HOSTAP
||
2140 vap
->iv_opmode
== IEEE80211_M_IBSS
||
2141 vap
->iv_opmode
== IEEE80211_M_MBSS
)
2143 error
= rt2860_beacon_alloc(sc
, vap
);
2147 rt2860_asic_update_beacon(sc
, vap
);
2150 if (vap
->iv_opmode
!= IEEE80211_M_MONITOR
)
2151 rt2860_asic_enable_tsf_sync(sc
);
2153 /* turn link LED on */
2155 if (vap
->iv_opmode
!= IEEE80211_M_MONITOR
)
2157 rt2860_led_cmd(sc
, RT2860_LED_CMD_RADIO_ON
|
2158 (IEEE80211_IS_CHAN_2GHZ(ni
->ni_chan
) ?
2159 RT2860_LED_CMD_LINK_2GHZ
: RT2860_LED_CMD_LINK_5GHZ
));
2163 case IEEE80211_S_SLEEP
:
2170 RT2860_SOFTC_UNLOCK(sc
);
2178 * rt2860_vap_key_update_begin
2180 static void rt2860_vap_key_update_begin(struct ieee80211vap
*vap
)
2182 struct rt2860_softc
*sc
;
2183 struct ieee80211com
*ic
;
2190 RT2860_DPRINTF(sc
, RT2860_DEBUG_KEY
,
2191 "%s: VAP key update begin\n",
2192 device_get_nameunit(sc
->dev
));
2194 taskqueue_block(sc
->taskqueue
);
2196 IF_LOCK(&ifp
->if_snd
);
2200 * rt2860_vap_key_update_end
2202 static void rt2860_vap_key_update_end(struct ieee80211vap
*vap
)
2204 struct rt2860_softc
*sc
;
2205 struct ieee80211com
*ic
;
2212 RT2860_DPRINTF(sc
, RT2860_DEBUG_KEY
,
2213 "%s: VAP key update end\n",
2214 device_get_nameunit(sc
->dev
));
2216 IF_UNLOCK(&ifp
->if_snd
);
2218 taskqueue_unblock(sc
->taskqueue
);
2222 * rt2860_vap_key_set
2224 static int rt2860_vap_key_set(struct ieee80211vap
*vap
,
2225 const struct ieee80211_key
*k
, const uint8_t mac
[IEEE80211_ADDR_LEN
])
2227 struct rt2860_softc
*sc
;
2228 struct ieee80211com
*ic
;
2230 struct ieee80211_node
*ni
;
2231 struct rt2860_softc_node
*rni
;
2232 uint16_t key_base
, keymode_base
;
2233 uint8_t mode
, vapid
, wcid
, iv
[8];
2236 if (k
->wk_cipher
->ic_cipher
!= IEEE80211_CIPHER_WEP
&&
2237 k
->wk_cipher
->ic_cipher
!= IEEE80211_CIPHER_TKIP
&&
2238 k
->wk_cipher
->ic_cipher
!= IEEE80211_CIPHER_AES_CCM
)
2245 switch (k
->wk_cipher
->ic_cipher
)
2247 case IEEE80211_CIPHER_WEP
:
2248 if(k
->wk_keylen
< 8)
2249 mode
= RT2860_REG_CIPHER_MODE_WEP40
;
2251 mode
= RT2860_REG_CIPHER_MODE_WEP104
;
2254 case IEEE80211_CIPHER_TKIP
:
2255 mode
= RT2860_REG_CIPHER_MODE_TKIP
;
2258 case IEEE80211_CIPHER_AES_CCM
:
2259 mode
= RT2860_REG_CIPHER_MODE_AES_CCMP
;
2266 RT2860_DPRINTF(sc
, RT2860_DEBUG_KEY
,
2267 "%s: VAP key set: keyix=%d, keylen=%d, macaddr=%s, mode=%d, group=%d\n",
2268 device_get_nameunit(sc
->dev
), k
->wk_keyix
, k
->wk_keylen
, ether_sprintf(k
->wk_macaddr
),
2269 mode
, (k
->wk_flags
& IEEE80211_KEY_GROUP
) ? 1 : 0);
2271 if (!(k
->wk_flags
& IEEE80211_KEY_GROUP
))
2273 /* install pairwise key */
2275 ni
= ieee80211_find_vap_node(&ic
->ic_sta
, vap
, mac
);
2276 rni
= (struct rt2860_softc_node
*) ni
;
2280 key_base
= RT2860_REG_PKEY(wcid
);
2282 ieee80211_free_node(ni
);
2284 if (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_WEP
)
2288 iv
[3] = (k
->wk_keyix
<< 6);
2292 if (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_TKIP
)
2294 iv
[0] = (k
->wk_keytsc
>> 8);
2295 iv
[1] = ((iv
[0] | 0x20) & 0x7f);
2296 iv
[2] = k
->wk_keytsc
;
2302 iv
[0] = k
->wk_keytsc
;
2303 iv
[1] = k
->wk_keytsc
>> 8;
2307 iv
[3] = ((k
->wk_keyix
<< 6) | IEEE80211_WEP_EXTIV
);
2308 iv
[4] = (k
->wk_keytsc
>> 16);
2309 iv
[5] = (k
->wk_keytsc
>> 24);
2310 iv
[6] = (k
->wk_keytsc
>> 32);
2311 iv
[7] = (k
->wk_keytsc
>> 40);
2313 RT2860_DPRINTF(sc
, RT2860_DEBUG_KEY
,
2314 "%s: VAP key set: iv=%02x %02x %02x %02x %02x %02x %02x %02x\n",
2315 device_get_nameunit(sc
->dev
),
2316 iv
[0], iv
[1], iv
[2], iv
[3], iv
[4], iv
[5], iv
[6], iv
[7]);
2319 rt2860_io_mac_write_multi(sc
, RT2860_REG_IVEIV(wcid
), iv
, 8);
2321 if (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_TKIP
)
2323 rt2860_io_mac_write_multi(sc
, key_base
, k
->wk_key
, 16);
2325 if (vap
->iv_opmode
!= IEEE80211_M_HOSTAP
)
2327 rt2860_io_mac_write_multi(sc
, key_base
+ 16, &k
->wk_key
[16], 8);
2328 rt2860_io_mac_write_multi(sc
, key_base
+ 24, &k
->wk_key
[24], 8);
2332 rt2860_io_mac_write_multi(sc
, key_base
+ 16, &k
->wk_key
[24], 8);
2333 rt2860_io_mac_write_multi(sc
, key_base
+ 24, &k
->wk_key
[16], 8);
2338 rt2860_io_mac_write_multi(sc
, key_base
, k
->wk_key
, k
->wk_keylen
);
2341 tmp
= ((vapid
& RT2860_REG_VAP_MASK
) << RT2860_REG_VAP_SHIFT
) |
2342 (mode
<< RT2860_REG_CIPHER_MODE_SHIFT
) | RT2860_REG_PKEY_ENABLE
;
2344 rt2860_io_mac_write(sc
, RT2860_REG_WCID_ATTR(wcid
), tmp
);
2347 if ((k
->wk_flags
& IEEE80211_KEY_GROUP
) ||
2348 (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_WEP
))
2350 /* install group key */
2353 wcid
= RT2860_WCID_MCAST
;
2354 key_base
= RT2860_REG_SKEY(vapid
, k
->wk_keyix
);
2355 keymode_base
= RT2860_REG_SKEY_MODE(vapid
);
2357 if (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_TKIP
)
2359 rt2860_io_mac_write_multi(sc
, key_base
, k
->wk_key
, 16);
2361 if (vap
->iv_opmode
!= IEEE80211_M_HOSTAP
)
2363 rt2860_io_mac_write_multi(sc
, key_base
+ 16, &k
->wk_key
[16], 8);
2364 rt2860_io_mac_write_multi(sc
, key_base
+ 24, &k
->wk_key
[24], 8);
2368 rt2860_io_mac_write_multi(sc
, key_base
+ 16, &k
->wk_key
[24], 8);
2369 rt2860_io_mac_write_multi(sc
, key_base
+ 24, &k
->wk_key
[16], 8);
2374 rt2860_io_mac_write_multi(sc
, key_base
, k
->wk_key
, k
->wk_keylen
);
2377 tmp
= rt2860_io_mac_read(sc
, keymode_base
);
2379 tmp
&= ~(0xf << (k
->wk_keyix
* 4 + 16 * (vapid
% 2)));
2380 tmp
|= (mode
<< (k
->wk_keyix
* 4 + 16 * (vapid
% 2)));
2382 rt2860_io_mac_write(sc
, keymode_base
, tmp
);
2384 if (vap
->iv_opmode
== IEEE80211_M_HOSTAP
)
2386 if (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_WEP
)
2390 iv
[3] = (k
->wk_keyix
<< 6);
2394 if (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_TKIP
)
2396 iv
[0] = (k
->wk_keytsc
>> 8);
2397 iv
[1] = ((iv
[0] | 0x20) & 0x7f);
2398 iv
[2] = k
->wk_keytsc
;
2404 iv
[0] = k
->wk_keytsc
;
2405 iv
[1] = k
->wk_keytsc
>> 8;
2409 iv
[3] = ((k
->wk_keyix
<< 6) | IEEE80211_WEP_EXTIV
);
2410 iv
[4] = (k
->wk_keytsc
>> 16);
2411 iv
[5] = (k
->wk_keytsc
>> 24);
2412 iv
[6] = (k
->wk_keytsc
>> 32);
2413 iv
[7] = (k
->wk_keytsc
>> 40);
2415 RT2860_DPRINTF(sc
, RT2860_DEBUG_KEY
,
2416 "%s: VAP key set: iv=%02x %02x %02x %02x %02x %02x %02x %02x\n",
2417 device_get_nameunit(sc
->dev
),
2418 iv
[0], iv
[1], iv
[2], iv
[3], iv
[4], iv
[5], iv
[6], iv
[7]);
2421 rt2860_io_mac_write_multi(sc
, RT2860_REG_IVEIV(wcid
), iv
, 8);
2423 tmp
= ((vapid
& RT2860_REG_VAP_MASK
) << RT2860_REG_VAP_SHIFT
) |
2424 (mode
<< RT2860_REG_CIPHER_MODE_SHIFT
);
2426 rt2860_io_mac_write(sc
, RT2860_REG_WCID_ATTR(wcid
), tmp
);
2434 * rt2860_vap_key_delete
2436 static int rt2860_vap_key_delete(struct ieee80211vap
*vap
,
2437 const struct ieee80211_key
*k
)
2439 struct rt2860_softc
*sc
;
2440 struct ieee80211com
*ic
;
2442 uint8_t vapid
, wcid
;
2449 RT2860_DPRINTF(sc
, RT2860_DEBUG_KEY
,
2450 "%s: VAP key delete: keyix=%d, keylen=%d, macaddr=%s, group=%d\n",
2451 device_get_nameunit(sc
->dev
), k
->wk_keyix
, k
->wk_keylen
, ether_sprintf(k
->wk_macaddr
),
2452 (k
->wk_flags
& IEEE80211_KEY_GROUP
) ? 1 : 0);
2454 if (k
->wk_flags
& IEEE80211_KEY_GROUP
)
2456 /* remove group key */
2459 wcid
= RT2860_WCID_MCAST
;
2461 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_SKEY_MODE(vapid
));
2463 tmp
&= ~(0xf << (k
->wk_keyix
* 4 + 16 * (vapid
% 2)));
2464 tmp
|= (RT2860_REG_CIPHER_MODE_NONE
<< (k
->wk_keyix
* 4 + 16 * (vapid
% 2)));
2466 rt2860_io_mac_write(sc
, RT2860_REG_SKEY_MODE(vapid
), tmp
);
2468 if (vap
->iv_opmode
== IEEE80211_M_HOSTAP
)
2470 tmp
= ((vapid
& RT2860_REG_VAP_MASK
) << RT2860_REG_VAP_SHIFT
) |
2471 (RT2860_REG_CIPHER_MODE_NONE
<< RT2860_REG_CIPHER_MODE_SHIFT
) | RT2860_REG_PKEY_ENABLE
;
2473 rt2860_io_mac_write(sc
, RT2860_REG_WCID_ATTR(wcid
), tmp
);
2481 * rt2860_vap_update_beacon
2483 static void rt2860_vap_update_beacon(struct ieee80211vap
*vap
, int what
)
2485 struct rt2860_softc
*sc
;
2486 struct ieee80211com
*ic
;
2488 struct rt2860_softc_vap
*rvap
;
2490 struct ieee80211_beacon_offsets
*bo
;
2495 rvap
= (struct rt2860_softc_vap
*) vap
;
2496 m
= rvap
->beacon_mbuf
;
2497 bo
= &rvap
->beacon_offsets
;
2499 RT2860_DPRINTF(sc
, RT2860_DEBUG_BEACON
,
2500 "%s: VAP update beacon: what=%d\n",
2501 device_get_nameunit(sc
->dev
), what
);
2503 setbit(bo
->bo_flags
, what
);
2505 ieee80211_beacon_update(vap
->iv_bss
, bo
, m
, 0);
2507 rt2860_asic_update_beacon(sc
, vap
);
2511 * rt2860_media_change
2513 static int rt2860_media_change(struct ifnet
*ifp
)
2517 error
= ieee80211_media_change(ifp
);
2519 return (error
== ENETRESET
? 0 : error
);
2525 static struct ieee80211_node
*rt2860_node_alloc(struct ieee80211vap
*vap
,
2526 const uint8_t mac
[IEEE80211_ADDR_LEN
])
2528 return malloc(sizeof(struct rt2860_softc_node
),
2529 M_80211_NODE
, M_NOWAIT
| M_ZERO
);
2533 * rt2860_node_cleanup
2535 static void rt2860_node_cleanup(struct ieee80211_node
*ni
)
2537 struct rt2860_softc
*sc
;
2538 struct ieee80211com
*ic
;
2540 struct rt2860_softc_node
*rni
;
2541 uint8_t vapid
, wcid
;
2547 rni
= (struct rt2860_softc_node
*) ni
;
2549 RT2860_DPRINTF(sc
, RT2860_DEBUG_NODE
,
2550 "%s: node cleanup: macaddr=%s, associd=0x%04x, staid=0x%02x\n",
2551 device_get_nameunit(sc
->dev
), ether_sprintf(ni
->ni_macaddr
),
2552 ni
->ni_associd
, rni
->staid
);
2554 if (rni
->staid
!= 0)
2559 tmp
= ((vapid
& RT2860_REG_VAP_MASK
) << RT2860_REG_VAP_SHIFT
) |
2560 (RT2860_REG_CIPHER_MODE_NONE
<< RT2860_REG_CIPHER_MODE_SHIFT
) | RT2860_REG_PKEY_ENABLE
;
2562 rt2860_io_mac_write(sc
, RT2860_REG_WCID_ATTR(wcid
), tmp
);
2564 rt2860_io_mac_write(sc
, RT2860_REG_WCID(wcid
), 0x00000000);
2565 rt2860_io_mac_write(sc
, RT2860_REG_WCID(wcid
) + 4, 0x00000000);
2567 rt2860_staid_delete(sc
, rni
->staid
);
2572 sc
->node_cleanup(ni
);
2576 * rt2860_node_getmimoinfo
2578 static void rt2860_node_getmimoinfo(const struct ieee80211_node
*ni
,
2579 struct ieee80211_mimo_info
*mi
)
2581 const struct rt2860_softc_node
*rni
;
2584 rni
= (const struct rt2860_softc_node
*) ni
;
2586 for (i
= 0; i
< RT2860_SOFTC_RSSI_COUNT
; i
++)
2588 mi
->rssi
[i
] = rni
->last_rssi_dbm
[i
];
2589 mi
->noise
[i
] = RT2860_NOISE_FLOOR
;
2594 * rt2860_setregdomain
2596 static int rt2860_setregdomain(struct ieee80211com
*ic
,
2597 struct ieee80211_regdomain
*reg
,
2598 int nchans
, struct ieee80211_channel chans
[])
2600 struct rt2860_softc
*sc
;
2606 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATE
,
2607 "%s: set regulatory domain: country=%d, country code string=%c%c, location=%c\n",
2608 device_get_nameunit(sc
->dev
),
2609 reg
->country
, reg
->isocc
[0], reg
->isocc
[1], reg
->location
);
2615 * rt2860_getradiocaps
2617 static void rt2860_getradiocaps(struct ieee80211com
*ic
,
2618 int maxchans
, int *nchans
, struct ieee80211_channel chans
[])
2620 *nchans
= (ic
->ic_nchans
>= maxchans
) ? maxchans
: ic
->ic_nchans
;
2622 memcpy(chans
, ic
->ic_channels
, (*nchans
) * sizeof(struct ieee80211_channel
));
2628 static void rt2860_scan_start(struct ieee80211com
*ic
)
2630 struct rt2860_softc
*sc
;
2636 rt2860_asic_disable_tsf_sync(sc
);
2642 static void rt2860_scan_end(struct ieee80211com
*ic
)
2644 struct rt2860_softc
*sc
;
2650 rt2860_asic_enable_tsf_sync(sc
);
2654 * rt2860_set_channel
2656 static void rt2860_set_channel(struct ieee80211com
*ic
)
2658 struct rt2860_softc
*sc
;
2664 RT2860_DPRINTF(sc
, RT2860_DEBUG_CHAN
,
2665 "%s: set channel: channel=%u, HT%s%s\n",
2666 device_get_nameunit(sc
->dev
),
2667 ieee80211_chan2ieee(ic
, ic
->ic_curchan
),
2668 !IEEE80211_IS_CHAN_HT(ic
->ic_curchan
) ? " disabled" :
2669 IEEE80211_IS_CHAN_HT20(ic
->ic_curchan
) ? "20":
2670 IEEE80211_IS_CHAN_HT40U(ic
->ic_curchan
) ? "40U" : "40D",
2671 (ic
->ic_flags
& IEEE80211_F_SCAN
) ? ", scanning" : "");
2673 RT2860_SOFTC_LOCK(sc
);
2675 rt2860_rf_set_chan(sc
, ic
->ic_curchan
);
2677 RT2860_SOFTC_UNLOCK(sc
);
2683 static void rt2860_newassoc(struct ieee80211_node
*ni
, int isnew
)
2685 struct rt2860_softc
*sc
;
2686 struct ieee80211com
*ic
;
2688 struct ieee80211vap
*vap
;
2689 struct rt2860_softc_vap
*rvap
;
2690 struct rt2860_softc_node
*rni
;
2699 rvap
= (struct rt2860_softc_vap
*) vap
;
2700 rni
= (struct rt2860_softc_node
*) ni
;
2704 aid
= IEEE80211_AID(ni
->ni_associd
);
2705 rni
->staid
= rt2860_staid_alloc(sc
, aid
);
2708 tmp
= (ni
->ni_macaddr
[3] << 24) |
2709 (ni
->ni_macaddr
[2] << 16) |
2710 (ni
->ni_macaddr
[1] << 8) |
2713 rt2860_io_mac_write(sc
, RT2860_REG_WCID(wcid
), tmp
);
2715 tmp
= (ni
->ni_macaddr
[5] << 8) |
2718 rt2860_io_mac_write(sc
, RT2860_REG_WCID(wcid
) + 4, tmp
);
2720 rt2860_amrr_node_init(&rvap
->amrr
, &sc
->amrr_node
[wcid
], ni
);
2722 RT2860_DPRINTF(sc
, RT2860_DEBUG_RATE
,
2723 "%s: initial%s node Tx rate: associd=0x%04x, rate=0x%02x, max rate=0x%02x\n",
2724 device_get_nameunit(sc
->dev
),
2725 (ni
->ni_flags
& IEEE80211_NODE_HT
) ? " HT" : "",
2726 ni
->ni_associd
, ni
->ni_txrate
,
2727 (ni
->ni_flags
& IEEE80211_NODE_HT
) ?
2728 (ni
->ni_htrates
.rs_rates
[ni
->ni_htrates
.rs_nrates
- 1] | IEEE80211_RATE_MCS
) :
2729 (ni
->ni_rates
.rs_rates
[ni
->ni_rates
.rs_nrates
- 1] & IEEE80211_RATE_VAL
));
2731 rt2860_asic_updateprot(sc
);
2732 rt2860_asic_updateslot(sc
);
2733 rt2860_asic_set_txpreamble(sc
);
2736 RT2860_DPRINTF(sc
, RT2860_DEBUG_NODE
,
2737 "%s: new association: isnew=%d, macaddr=%s, associd=0x%04x, staid=0x%02x, QoS %s, ERP %s, HT %s\n",
2738 device_get_nameunit(sc
->dev
), isnew
, ether_sprintf(ni
->ni_macaddr
),
2739 ni
->ni_associd
, rni
->staid
,
2740 (ni
->ni_flags
& IEEE80211_NODE_QOS
) ? "enabled" : "disabled",
2741 (ni
->ni_flags
& IEEE80211_NODE_ERP
) ? "enabled" : "disabled",
2742 (ni
->ni_flags
& IEEE80211_NODE_HT
) ? "enabled" : "disabled");
2748 static void rt2860_updateslot(struct ifnet
*ifp
)
2750 struct rt2860_softc
*sc
;
2754 rt2860_asic_updateslot(sc
);
2758 * rt2860_update_promisc
2760 static void rt2860_update_promisc(struct ifnet
*ifp
)
2762 struct rt2860_softc
*sc
;
2766 rt2860_asic_update_promisc(sc
);
2770 * rt2860_update_mcast
2772 static void rt2860_update_mcast(struct ifnet
*ifp
)
2774 struct rt2860_softc
*sc
;
2782 static int rt2860_wme_update(struct ieee80211com
*ic
)
2784 struct rt2860_softc
*sc
;
2790 rt2860_asic_wme_update(sc
);
2798 static int rt2860_raw_xmit(struct ieee80211_node
*ni
, struct mbuf
*m
,
2799 const struct ieee80211_bpf_params
*params
)
2801 struct rt2860_softc
*sc
;
2802 struct ieee80211com
*ic
;
2809 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
2812 ieee80211_free_node(ni
);
2817 RT2860_SOFTC_TX_RING_LOCK(&sc
->tx_ring
[sc
->tx_ring_mgtqid
]);
2819 if (sc
->tx_ring
[sc
->tx_ring_mgtqid
].data_queued
>= RT2860_SOFTC_TX_RING_DATA_COUNT
)
2821 RT2860_SOFTC_TX_RING_UNLOCK(&sc
->tx_ring
[sc
->tx_ring_mgtqid
]);
2823 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
2824 "%s: raw xmit: Tx ring with qid=%d is full\n",
2825 device_get_nameunit(sc
->dev
), sc
->tx_ring_mgtqid
);
2827 ifp
->if_drv_flags
|= IFF_DRV_OACTIVE
;
2830 ieee80211_free_node(ni
);
2832 sc
->tx_data_queue_full
[sc
->tx_ring_mgtqid
]++;
2837 if (rt2860_tx_mgmt(sc
, m
, ni
, sc
->tx_ring_mgtqid
) != 0)
2839 RT2860_SOFTC_TX_RING_UNLOCK(&sc
->tx_ring
[sc
->tx_ring_mgtqid
]);
2843 ieee80211_free_node(ni
);
2848 RT2860_SOFTC_TX_RING_UNLOCK(&sc
->tx_ring
[sc
->tx_ring_mgtqid
]);
2850 sc
->tx_timer
= RT2860_TX_WATCHDOG_TIMEOUT
;
2856 * rt2860_recv_action
2858 static int rt2860_recv_action(struct ieee80211_node
*ni
,
2859 const struct ieee80211_frame
*wh
,
2860 const uint8_t *frm
, const uint8_t *efrm
)
2862 struct rt2860_softc
*sc
;
2863 struct ieee80211com
*ic
;
2865 struct rt2860_softc_node
*rni
;
2866 const struct ieee80211_action
*ia
;
2867 uint16_t baparamset
;
2874 rni
= (struct rt2860_softc_node
*) ni
;
2876 ia
= (const struct ieee80211_action
*) frm
;
2878 if (ia
->ia_category
== IEEE80211_ACTION_CAT_BA
)
2880 switch (ia
->ia_action
)
2882 /* IEEE80211_ACTION_BA_DELBA */
2883 case IEEE80211_ACTION_BA_DELBA
:
2884 baparamset
= LE_READ_2(frm
+ 2);
2885 tid
= RT2860_MS(baparamset
, IEEE80211_BAPS_TID
);
2888 RT2860_DPRINTF(sc
, RT2860_DEBUG_BA
,
2889 "%s: received DELBA request: associd=0x%04x, staid=0x%02x, tid=%d\n",
2890 device_get_nameunit(sc
->dev
), ni
->ni_associd
, rni
->staid
, tid
);
2892 if (rni
->staid
!= 0)
2893 rt2860_asic_del_ba_session(sc
, wcid
, tid
);
2898 return sc
->recv_action(ni
, wh
, frm
, efrm
);
2902 * rt2860_send_action
2904 static int rt2860_send_action(struct ieee80211_node
*ni
,
2905 int cat
, int act
, void *sa
)
2907 struct rt2860_softc
*sc
;
2908 struct ieee80211com
*ic
;
2910 struct rt2860_softc_node
*rni
;
2911 uint16_t *args
, status
, baparamset
;
2918 rni
= (struct rt2860_softc_node
*) ni
;
2923 if (cat
== IEEE80211_ACTION_CAT_BA
)
2927 /* IEEE80211_ACTION_BA_ADDBA_RESPONSE */
2928 case IEEE80211_ACTION_BA_ADDBA_RESPONSE
:
2930 baparamset
= args
[2];
2931 tid
= RT2860_MS(baparamset
, IEEE80211_BAPS_TID
);
2932 bufsize
= RT2860_MS(baparamset
, IEEE80211_BAPS_BUFSIZ
);
2934 RT2860_DPRINTF(sc
, RT2860_DEBUG_BA
,
2935 "%s: sending ADDBA response: associd=0x%04x, staid=0x%02x, status=%d, tid=%d, bufsize=%d\n",
2936 device_get_nameunit(sc
->dev
), ni
->ni_associd
, rni
->staid
, status
, tid
, bufsize
);
2938 if (status
== IEEE80211_STATUS_SUCCESS
)
2939 rt2860_asic_add_ba_session(sc
, wcid
, tid
);
2942 /* IEEE80211_ACTION_BA_DELBA */
2943 case IEEE80211_ACTION_BA_DELBA
:
2944 baparamset
= RT2860_SM(args
[0], IEEE80211_DELBAPS_TID
) | args
[1];
2945 tid
= RT2860_MS(baparamset
, IEEE80211_DELBAPS_TID
);
2947 RT2860_DPRINTF(sc
, RT2860_DEBUG_BA
,
2948 "%s: sending DELBA request: associd=0x%04x, staid=0x%02x, tid=%d\n",
2949 device_get_nameunit(sc
->dev
), ni
->ni_associd
, rni
->staid
, tid
);
2951 if (RT2860_MS(baparamset
, IEEE80211_DELBAPS_INIT
) != IEEE80211_DELBAPS_INIT
)
2952 rt2860_asic_del_ba_session(sc
, wcid
, tid
);
2957 return sc
->send_action(ni
, cat
, act
, sa
);
2961 * rt2860_addba_response
2963 static int rt2860_addba_response(struct ieee80211_node
*ni
,
2964 struct ieee80211_tx_ampdu
*tap
,
2965 int status
, int baparamset
, int batimeout
)
2967 struct rt2860_softc
*sc
;
2968 struct ieee80211com
*ic
;
2970 struct rt2860_softc_node
*rni
;
2971 ieee80211_seq seqno
;
2972 int ret
, tid
, old_bufsize
, new_bufsize
;
2977 rni
= (struct rt2860_softc_node
*) ni
;
2979 tid
= RT2860_MS(baparamset
, IEEE80211_BAPS_TID
);
2980 old_bufsize
= RT2860_MS(baparamset
, IEEE80211_BAPS_BUFSIZ
);
2981 new_bufsize
= old_bufsize
;
2983 if (status
== IEEE80211_STATUS_SUCCESS
)
2985 if (sc
->mac_rev
>= 0x28830300)
2987 if (sc
->mac_rev
>= 0x30700200)
2992 else if (sc
->mac_rev
>= 0x28720200)
3001 if (old_bufsize
> new_bufsize
)
3003 baparamset
&= ~IEEE80211_BAPS_BUFSIZ
;
3004 baparamset
= RT2860_SM(new_bufsize
, IEEE80211_BAPS_BUFSIZ
);
3007 if (!(tap
->txa_flags
& IEEE80211_AGGR_RUNNING
))
3009 sc
->tx_ampdu_sessions
++;
3011 if (sc
->tx_ampdu_sessions
== 1)
3012 rt2860_asic_updateprot(sc
);
3016 RT2860_DPRINTF(sc
, RT2860_DEBUG_BA
,
3017 "%s: received ADDBA response: associd=0x%04x, staid=0x%02x, status=%d, tid=%d, "
3018 "old bufsize=%d, new bufsize=%d\n",
3019 device_get_nameunit(sc
->dev
), ni
->ni_associd
, rni
->staid
, status
, tid
,
3020 old_bufsize
, new_bufsize
);
3022 ret
= sc
->addba_response(ni
, tap
, status
, baparamset
, batimeout
);
3024 if (status
== IEEE80211_STATUS_SUCCESS
)
3026 seqno
= ni
->ni_txseqs
[tid
];
3028 rt2860_send_bar(ni
, tap
, seqno
);
3037 static void rt2860_addba_stop(struct ieee80211_node
*ni
,
3038 struct ieee80211_tx_ampdu
*tap
)
3040 struct rt2860_softc
*sc
;
3041 struct ieee80211com
*ic
;
3043 struct rt2860_softc_node
*rni
;
3049 rni
= (struct rt2860_softc_node
*) ni
;
3051 tid
= WME_AC_TO_TID(tap
->txa_ac
);
3053 RT2860_DPRINTF(sc
, RT2860_DEBUG_BA
,
3054 "%s: stopping A-MPDU Tx: associd=0x%04x, staid=0x%02x, tid=%d\n",
3055 device_get_nameunit(sc
->dev
), ni
->ni_associd
, rni
->staid
, tid
);
3057 if (tap
->txa_flags
& IEEE80211_AGGR_RUNNING
)
3059 if (sc
->tx_ampdu_sessions
> 0)
3061 sc
->tx_ampdu_sessions
--;
3063 if (sc
->tx_ampdu_sessions
== 0)
3064 rt2860_asic_updateprot(sc
);
3068 printf("%s: number of A-MPDU Tx sessions cannot be negative\n",
3069 device_get_nameunit(sc
->dev
));
3073 sc
->addba_stop(ni
, tap
);
3077 * rt2860_ampdu_rx_start
3079 static int rt2860_ampdu_rx_start(struct ieee80211_node
*ni
,
3080 struct ieee80211_rx_ampdu
*rap
,
3081 int baparamset
, int batimeout
, int baseqctl
)
3083 struct rt2860_softc
*sc
;
3084 struct ieee80211com
*ic
;
3086 struct rt2860_softc_node
*rni
;
3092 rni
= (struct rt2860_softc_node
*) ni
;
3094 tid
= RT2860_MS(baparamset
, IEEE80211_BAPS_TID
);
3096 RT2860_DPRINTF(sc
, RT2860_DEBUG_BA
,
3097 "%s: starting A-MPDU Rx: associd=0x%04x, staid=0x%02x, tid=%d\n",
3098 device_get_nameunit(sc
->dev
), ni
->ni_associd
, rni
->staid
, tid
);
3100 if (!(rap
->rxa_flags
& IEEE80211_AGGR_RUNNING
))
3101 sc
->rx_ampdu_sessions
++;
3103 return sc
->ampdu_rx_start(ni
, rap
, baparamset
, batimeout
, baseqctl
);
3107 * rt2860_ampdu_rx_stop
3109 static void rt2860_ampdu_rx_stop(struct ieee80211_node
*ni
,
3110 struct ieee80211_rx_ampdu
*rap
)
3112 struct rt2860_softc
*sc
;
3113 struct ieee80211com
*ic
;
3115 struct rt2860_softc_node
*rni
;
3120 rni
= (struct rt2860_softc_node
*) ni
;
3122 RT2860_DPRINTF(sc
, RT2860_DEBUG_BA
,
3123 "%s: stopping A-MPDU Rx: associd=0x%04x, staid=0x%02x\n",
3124 device_get_nameunit(sc
->dev
), ni
->ni_associd
, rni
->staid
);
3126 if (rap
->rxa_flags
& IEEE80211_AGGR_RUNNING
)
3128 if (sc
->rx_ampdu_sessions
> 0)
3129 sc
->rx_ampdu_sessions
--;
3131 printf("%s: number of A-MPDU Rx sessions cannot be negative\n",
3132 device_get_nameunit(sc
->dev
));
3135 sc
->ampdu_rx_stop(ni
, rap
);
3141 static int rt2860_send_bar(struct ieee80211_node
*ni
,
3142 struct ieee80211_tx_ampdu
*tap
, ieee80211_seq seqno
)
3144 struct rt2860_softc
*sc
;
3145 struct ieee80211com
*ic
;
3147 struct ieee80211vap
*vap
;
3148 struct ieee80211_frame_bar
*bar
;
3149 struct rt2860_softc_node
*rni
;
3151 uint16_t barctl
, barseqctl
;
3159 rni
= (struct rt2860_softc_node
*) ni
;
3161 if (!(tap
->txa_flags
& IEEE80211_AGGR_RUNNING
))
3164 m
= ieee80211_getmgtframe(&frm
, ic
->ic_headroom
, sizeof(struct ieee80211_frame_bar
));
3168 bar
= mtod(m
, struct ieee80211_frame_bar
*);
3170 bar
->i_fc
[0] = IEEE80211_FC0_VERSION_0
| IEEE80211_FC0_TYPE_CTL
| IEEE80211_FC0_SUBTYPE_BAR
;
3173 IEEE80211_ADDR_COPY(bar
->i_ra
, ni
->ni_macaddr
);
3174 IEEE80211_ADDR_COPY(bar
->i_ta
, vap
->iv_myaddr
);
3176 tid
= WME_AC_TO_TID(tap
->txa_ac
);
3178 barctl
= (tap
->txa_flags
& IEEE80211_AGGR_IMMEDIATE
? 0 : IEEE80211_BAR_NOACK
) |
3179 IEEE80211_BAR_COMP
|
3180 RT2860_SM(tid
, IEEE80211_BAR_TID
);
3181 barseqctl
= RT2860_SM(seqno
, IEEE80211_BAR_SEQ_START
);
3183 bar
->i_ctl
= htole16(barctl
);
3184 bar
->i_seq
= htole16(barseqctl
);
3186 m
->m_pkthdr
.len
= m
->m_len
= sizeof(struct ieee80211_frame_bar
);
3188 tap
->txa_start
= seqno
;
3190 ieee80211_ref_node(ni
);
3192 RT2860_DPRINTF(sc
, RT2860_DEBUG_BA
,
3193 "%s: sending BAR: associd=0x%04x, staid=0x%02x, tid=%d, seqno=%d\n",
3194 device_get_nameunit(sc
->dev
), ni
->ni_associd
, rni
->staid
, tid
, seqno
);
3196 ret
= ic
->ic_raw_xmit(ni
, m
, NULL
);
3198 ieee80211_free_node(ni
);
3204 * rt2860_amrr_update_iter_func
3206 static void rt2860_amrr_update_iter_func(void *arg
, struct ieee80211_node
*ni
)
3208 struct rt2860_softc
*sc
;
3209 struct ieee80211com
*ic
;
3211 struct ieee80211vap
*vap
;
3212 struct rt2860_softc_vap
*rvap
;
3213 struct rt2860_softc_node
*rni
;
3220 rvap
= (struct rt2860_softc_vap
*) vap
;
3221 rni
= (struct rt2860_softc_node
*) ni
;
3223 /* only associated stations */
3225 if ((ni
->ni_vap
== vap
) && (rni
->staid
!= 0))
3229 RT2860_DPRINTF(sc
, RT2860_DEBUG_RATE
,
3230 "%s: AMRR node: staid=0x%02x, txcnt=%d, success=%d, retrycnt=%d\n",
3231 device_get_nameunit(sc
->dev
),
3232 rni
->staid
, sc
->amrr_node
[wcid
].txcnt
, sc
->amrr_node
[wcid
].success
, sc
->amrr_node
[wcid
].retrycnt
);
3234 rt2860_amrr_choose(ni
, &sc
->amrr_node
[wcid
]);
3236 RT2860_DPRINTF(sc
, RT2860_DEBUG_RATE
,
3237 "%s:%s node Tx rate: associd=0x%04x, staid=0x%02x, rate=0x%02x, max rate=0x%02x\n",
3238 device_get_nameunit(sc
->dev
),
3239 (ni
->ni_flags
& IEEE80211_NODE_HT
) ? " HT" : "",
3240 ni
->ni_associd
, rni
->staid
, ni
->ni_txrate
,
3241 (ni
->ni_flags
& IEEE80211_NODE_HT
) ?
3242 (ni
->ni_htrates
.rs_rates
[ni
->ni_htrates
.rs_nrates
- 1] | IEEE80211_RATE_MCS
) :
3243 (ni
->ni_rates
.rs_rates
[ni
->ni_rates
.rs_nrates
- 1] & IEEE80211_RATE_VAL
));
3250 static void rt2860_periodic(void *arg
)
3252 struct rt2860_softc
*sc
;
3256 RT2860_DPRINTF(sc
, RT2860_DEBUG_PERIODIC
,
3258 device_get_nameunit(sc
->dev
));
3260 taskqueue_enqueue(sc
->taskqueue
, &sc
->periodic_task
);
3264 * rt2860_tx_watchdog
3266 static void rt2860_tx_watchdog(void *arg
)
3268 struct rt2860_softc
*sc
;
3274 if (sc
->tx_timer
== 0)
3277 if (--sc
->tx_timer
== 0)
3279 printf("%s: Tx watchdog timeout: resetting\n",
3280 device_get_nameunit(sc
->dev
));
3282 rt2860_stop_locked(sc
);
3283 rt2860_init_locked(sc
);
3287 sc
->tx_watchdog_timeouts
++;
3290 callout_reset(&sc
->tx_watchdog_ch
, hz
, rt2860_tx_watchdog
, sc
);
3294 * rt2860_staid_alloc
3296 static int rt2860_staid_alloc(struct rt2860_softc
*sc
, int aid
)
3300 if ((aid
> 0 && aid
< RT2860_SOFTC_STAID_COUNT
) && isclr(sc
->staid_mask
, aid
))
3306 for (staid
= 1; staid
< RT2860_SOFTC_STAID_COUNT
; staid
++)
3308 if (isclr(sc
->staid_mask
, staid
))
3313 setbit(sc
->staid_mask
, staid
);
3319 * rt2860_staid_delete
3321 static void rt2860_staid_delete(struct rt2860_softc
*sc
, int staid
)
3323 clrbit(sc
->staid_mask
, staid
);
3327 * rt2860_asic_set_bssid
3329 static void rt2860_asic_set_bssid(struct rt2860_softc
*sc
,
3330 const uint8_t *bssid
)
3334 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATE
,
3335 "%s: set bssid: bssid=%s\n",
3336 device_get_nameunit(sc
->dev
),
3337 ether_sprintf(bssid
));
3339 tmp
= bssid
[0] | (bssid
[1]) << 8 | (bssid
[2] << 16) | (bssid
[3] << 24);
3341 rt2860_io_mac_write(sc
, RT2860_REG_BSSID_DW0
, tmp
);
3343 tmp
= bssid
[4] | (bssid
[5] << 8);
3345 rt2860_io_mac_write(sc
, RT2860_REG_BSSID_DW1
, tmp
);
3349 * rt2860_asic_set_macaddr
3351 static void rt2860_asic_set_macaddr(struct rt2860_softc
*sc
,
3352 const uint8_t *addr
)
3356 tmp
= addr
[0] | (addr
[1] << 8) | (addr
[2] << 16) | (addr
[3] << 24);
3358 rt2860_io_mac_write(sc
, RT2860_REG_ADDR_DW0
, tmp
);
3360 tmp
= addr
[4] | (addr
[5] << 8) | (0xff << 16);
3362 rt2860_io_mac_write(sc
, RT2860_REG_ADDR_DW1
, tmp
);
3366 * rt2860_asic_enable_tsf_sync
3368 static void rt2860_asic_enable_tsf_sync(struct rt2860_softc
*sc
)
3371 struct ieee80211com
*ic
;
3372 struct ieee80211vap
*vap
;
3377 vap
= TAILQ_FIRST(&ic
->ic_vaps
);
3379 RT2860_DPRINTF(sc
, RT2860_DEBUG_BEACON
,
3380 "%s: enabling TSF\n",
3381 device_get_nameunit(sc
->dev
));
3383 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_BCN_TIME_CFG
);
3386 tmp
|= vap
->iv_bss
->ni_intval
* 16;
3387 tmp
|= (RT2860_REG_TSF_TIMER_ENABLE
| RT2860_REG_TBTT_TIMER_ENABLE
);
3389 if (vap
->iv_opmode
== IEEE80211_M_STA
)
3391 tmp
|= (RT2860_REG_TSF_SYNC_MODE_STA
<< RT2860_REG_TSF_SYNC_MODE_SHIFT
);
3393 else if (vap
->iv_opmode
== IEEE80211_M_IBSS
)
3395 tmp
|= RT2860_REG_BCN_TX_ENABLE
;
3396 tmp
|= (RT2860_REG_TSF_SYNC_MODE_IBSS
<< RT2860_REG_TSF_SYNC_MODE_SHIFT
);
3398 else if (vap
->iv_opmode
== IEEE80211_M_HOSTAP
)
3400 tmp
|= RT2860_REG_BCN_TX_ENABLE
;
3401 tmp
|= (RT2860_REG_TSF_SYNC_MODE_HOSTAP
<< RT2860_REG_TSF_SYNC_MODE_SHIFT
);
3404 rt2860_io_mac_write(sc
, RT2860_REG_BCN_TIME_CFG
, tmp
);
3408 * rt2860_asic_disable_tsf_sync
3410 static void rt2860_asic_disable_tsf_sync(struct rt2860_softc
*sc
)
3414 RT2860_DPRINTF(sc
, RT2860_DEBUG_BEACON
,
3415 "%s: disabling TSF\n",
3416 device_get_nameunit(sc
->dev
));
3418 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_BCN_TIME_CFG
);
3420 tmp
&= ~(RT2860_REG_BCN_TX_ENABLE
|
3421 RT2860_REG_TSF_TIMER_ENABLE
|
3422 RT2860_REG_TBTT_TIMER_ENABLE
);
3424 tmp
&= ~(RT2860_REG_TSF_SYNC_MODE_MASK
<< RT2860_REG_TSF_SYNC_MODE_SHIFT
);
3425 tmp
|= (RT2860_REG_TSF_SYNC_MODE_DISABLE
<< RT2860_REG_TSF_SYNC_MODE_SHIFT
);
3427 rt2860_io_mac_write(sc
, RT2860_REG_BCN_TIME_CFG
, tmp
);
3431 * rt2860_asic_enable_mrr
3433 static void rt2860_asic_enable_mrr(struct rt2860_softc
*sc
)
3435 #define CCK(mcs) (mcs)
3436 #define OFDM(mcs) ((1 << 3) | (mcs))
3437 #define HT(mcs) (mcs)
3439 rt2860_io_mac_write(sc
, RT2860_REG_TX_LG_FBK_CFG0
,
3440 (OFDM(6) << 28) | /* 54 -> 48 */
3441 (OFDM(5) << 24) | /* 48 -> 36 */
3442 (OFDM(4) << 20) | /* 36 -> 24 */
3443 (OFDM(3) << 16) | /* 24 -> 18 */
3444 (OFDM(2) << 12) | /* 18 -> 12 */
3445 (OFDM(1) << 8) | /* 12 -> 9 */
3446 (OFDM(0) << 4) | /* 9 -> 6 */
3447 OFDM(0)); /* 6 -> 6 */
3449 rt2860_io_mac_write(sc
, RT2860_REG_TX_LG_FBK_CFG1
,
3450 (CCK(2) << 12) | /* 11 -> 5.5 */
3451 (CCK(1) << 8) | /* 5.5 -> 2 */
3452 (CCK(0) << 4) | /* 2 -> 1 */
3453 CCK(0)); /* 1 -> 1 */
3455 rt2860_io_mac_write(sc
, RT2860_REG_TX_HT_FBK_CFG0
,
3465 rt2860_io_mac_write(sc
, RT2860_REG_TX_HT_FBK_CFG1
,
3481 * rt2860_asic_set_txpreamble
3483 static void rt2860_asic_set_txpreamble(struct rt2860_softc
*sc
)
3486 struct ieee80211com
*ic
;
3492 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATE
,
3493 "%s: %s short Tx preamble\n",
3494 device_get_nameunit(sc
->dev
),
3495 (ic
->ic_flags
& IEEE80211_F_SHPREAMBLE
) ? "enabling" : "disabling");
3497 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_AUTO_RSP_CFG
);
3499 tmp
&= ~RT2860_REG_CCK_SHORT_ENABLE
;
3501 if (ic
->ic_flags
& IEEE80211_F_SHPREAMBLE
)
3502 tmp
|= RT2860_REG_CCK_SHORT_ENABLE
;
3504 rt2860_io_mac_write(sc
, RT2860_REG_AUTO_RSP_CFG
, tmp
);
3508 * rt2860_asic_set_basicrates
3510 static void rt2860_asic_set_basicrates(struct rt2860_softc
*sc
)
3513 struct ieee80211com
*ic
;
3518 if (ic
->ic_curmode
== IEEE80211_MODE_11B
)
3519 rt2860_io_mac_write(sc
, RT2860_REG_LEGACY_BASIC_RATE
, 0xf);
3520 else if (ic
->ic_curmode
== IEEE80211_MODE_11A
)
3521 rt2860_io_mac_write(sc
, RT2860_REG_LEGACY_BASIC_RATE
, 0x150);
3523 rt2860_io_mac_write(sc
, RT2860_REG_LEGACY_BASIC_RATE
, 0x15f);
3527 * rt2860_asic_update_rtsthreshold
3529 static void rt2860_asic_update_rtsthreshold(struct rt2860_softc
*sc
)
3532 struct ieee80211com
*ic
;
3533 struct ieee80211vap
*vap
;
3539 vap
= TAILQ_FIRST(&ic
->ic_vaps
);
3542 threshold
= IEEE80211_RTS_MAX
;
3543 else if (vap
->iv_flags_ht
& IEEE80211_FHT_AMSDU_TX
)
3546 threshold
= vap
->iv_rtsthreshold
;
3548 RT2860_DPRINTF(sc
, RT2860_DEBUG_PROT
,
3549 "%s: updating RTS threshold: %d\n",
3550 device_get_nameunit(sc
->dev
), threshold
);
3552 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_RTS_CFG
);
3554 tmp
&= ~(RT2860_REG_TX_RTS_THRESHOLD_MASK
<< RT2860_REG_TX_RTS_THRESHOLD_SHIFT
);
3556 tmp
|= ((threshold
& RT2860_REG_TX_RTS_THRESHOLD_MASK
) <<
3557 RT2860_REG_TX_RTS_THRESHOLD_SHIFT
);
3559 rt2860_io_mac_write(sc
, RT2860_REG_TX_RTS_CFG
, tmp
);
3563 * rt2860_asic_update_txpower
3565 static void rt2860_asic_update_txpower(struct rt2860_softc
*sc
)
3568 struct ieee80211com
*ic
;
3569 uint32_t *txpow_rate
;
3578 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATE
,
3579 "%s: updating Tx power: %d\n",
3580 device_get_nameunit(sc
->dev
), ic
->ic_txpowlimit
);
3582 if (!IEEE80211_IS_CHAN_HT40(ic
->ic_curchan
))
3584 txpow_rate
= sc
->txpow_rate_20mhz
;
3588 if (IEEE80211_IS_CHAN_2GHZ(ic
->ic_curchan
))
3589 txpow_rate
= sc
->txpow_rate_40mhz_2ghz
;
3591 txpow_rate
= sc
->txpow_rate_40mhz_5ghz
;
3596 val
= rt2860_io_bbp_read(sc
, 1);
3599 if (ic
->ic_txpowlimit
> 90)
3603 else if (ic
->ic_txpowlimit
> 60)
3607 else if (ic
->ic_txpowlimit
> 30)
3611 else if (ic
->ic_txpowlimit
> 15)
3615 else if (ic
->ic_txpowlimit
> 9)
3625 rt2860_io_bbp_write(sc
, 1, val
);
3627 for (i
= 0; i
< RT2860_SOFTC_TXPOW_RATE_COUNT
; i
++)
3629 if (txpow_rate
[i
] == 0xffffffff)
3632 tmp
= rt2860_read_eeprom_txpow_rate_add_delta(txpow_rate
[i
], delta
);
3634 rt2860_io_mac_write(sc
, RT2860_REG_TX_PWR_CFG(i
), tmp
);
3639 * rt2860_asic_update_promisc
3641 static void rt2860_asic_update_promisc(struct rt2860_softc
*sc
)
3648 printf("%s: %s promiscuous mode\n",
3649 device_get_nameunit(sc
->dev
),
3650 (ifp
->if_flags
& IFF_PROMISC
) ? "entering" : "leaving");
3652 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_RX_FILTER_CFG
);
3654 tmp
&= ~RT2860_REG_RX_FILTER_DROP_UC_NOME
;
3656 if (!(ifp
->if_flags
& IFF_PROMISC
))
3657 tmp
|= RT2860_REG_RX_FILTER_DROP_UC_NOME
;
3659 rt2860_io_mac_write(sc
, RT2860_REG_RX_FILTER_CFG
, tmp
);
3663 * rt2860_asic_updateprot
3665 static void rt2860_asic_updateprot(struct rt2860_softc
*sc
)
3668 struct ieee80211com
*ic
;
3669 struct ieee80211vap
*vap
;
3670 uint32_t cck_prot
, ofdm_prot
, mm20_prot
, mm40_prot
, gf20_prot
, gf40_prot
;
3672 enum ieee80211_protmode htprotmode
;
3676 vap
= TAILQ_FIRST(&ic
->ic_vaps
);
3678 /* CCK frame protection */
3680 cck_prot
= RT2860_REG_RTSTH_ENABLE
| RT2860_REG_PROT_NAV_SHORT
|
3681 RT2860_REG_TXOP_ALLOW_ALL
| RT2860_REG_PROT_CTRL_NONE
;
3683 /* set up protection frame phy mode and rate (MCS code) */
3685 if (ic
->ic_curmode
== IEEE80211_MODE_11A
)
3686 cck_prot
|= (RT2860_REG_PROT_PHYMODE_OFDM
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3687 (0 << RT2860_REG_PROT_MCS_SHIFT
);
3689 cck_prot
|= ((RT2860_REG_PROT_PHYMODE_CCK
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3690 (3 << RT2860_REG_PROT_MCS_SHIFT
));
3692 rt2860_io_mac_write(sc
, RT2860_REG_TX_CCK_PROT_CFG
, cck_prot
);
3694 /* OFDM frame protection */
3696 ofdm_prot
= RT2860_REG_RTSTH_ENABLE
| RT2860_REG_PROT_NAV_SHORT
|
3697 RT2860_REG_TXOP_ALLOW_ALL
;
3699 if (ic
->ic_flags
& IEEE80211_F_USEPROT
)
3701 RT2860_DPRINTF(sc
, RT2860_DEBUG_PROT
,
3702 "%s: updating protection mode: b/g protection mode=%s\n",
3703 device_get_nameunit(sc
->dev
),
3704 (ic
->ic_protmode
== IEEE80211_PROT_RTSCTS
) ? "RTS/CTS" :
3705 ((ic
->ic_protmode
== IEEE80211_PROT_CTSONLY
) ? "CTS-to-self" : "none"));
3707 if (ic
->ic_protmode
== IEEE80211_PROT_RTSCTS
)
3708 ofdm_prot
|= RT2860_REG_PROT_CTRL_RTS_CTS
;
3709 else if (ic
->ic_protmode
== IEEE80211_PROT_CTSONLY
)
3710 ofdm_prot
|= RT2860_REG_PROT_CTRL_CTS
;
3712 ofdm_prot
|= RT2860_REG_PROT_CTRL_NONE
;
3716 RT2860_DPRINTF(sc
, RT2860_DEBUG_PROT
,
3717 "%s: updating protection mode: b/g protection mode=%s\n",
3718 device_get_nameunit(sc
->dev
), "none");
3720 ofdm_prot
|= RT2860_REG_PROT_CTRL_NONE
;
3723 rt2860_io_mac_write(sc
, RT2860_REG_TX_OFDM_PROT_CFG
, ofdm_prot
);
3725 /* HT frame protection */
3727 if ((vap
!= NULL
) && (vap
->iv_opmode
== IEEE80211_M_STA
) && (vap
->iv_state
== IEEE80211_S_RUN
))
3728 htopmode
= vap
->iv_bss
->ni_htopmode
;
3730 htopmode
= ic
->ic_curhtprotmode
;
3732 htprotmode
= ic
->ic_htprotmode
;
3734 /* force HT mixed mode and RTS/CTS protection if A-MPDU Tx aggregation is enabled */
3736 if (sc
->tx_ampdu_sessions
> 0)
3738 RT2860_DPRINTF(sc
, RT2860_DEBUG_PROT
,
3739 "%s: updating protection mode: forcing HT mixed mode and RTS/CTS protection\n",
3740 device_get_nameunit(sc
->dev
));
3742 htopmode
= IEEE80211_HTINFO_OPMODE_MIXED
;
3743 htprotmode
= IEEE80211_PROT_RTSCTS
;
3746 RT2860_DPRINTF(sc
, RT2860_DEBUG_PROT
,
3747 "%s: updating protection mode: HT operation mode=0x%02x, protection mode=%s\n",
3748 device_get_nameunit(sc
->dev
),
3749 htopmode
& IEEE80211_HTINFO_OPMODE
,
3750 (htprotmode
== IEEE80211_PROT_RTSCTS
) ? "RTS/CTS" :
3751 ((htprotmode
== IEEE80211_PROT_CTSONLY
) ? "CTS-to-self" : "none"));
3753 switch (htopmode
& IEEE80211_HTINFO_OPMODE
)
3755 /* IEEE80211_HTINFO_OPMODE_HT20PR */
3756 case IEEE80211_HTINFO_OPMODE_HT20PR
:
3757 mm20_prot
= RT2860_REG_PROT_NAV_SHORT
| RT2860_REG_PROT_CTRL_NONE
|
3758 RT2860_REG_TXOP_ALLOW_CCK
| RT2860_REG_TXOP_ALLOW_OFDM
|
3759 RT2860_REG_TXOP_ALLOW_MM20
| RT2860_REG_TXOP_ALLOW_GF20
|
3760 (RT2860_REG_PROT_PHYMODE_OFDM
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3761 (4 << RT2860_REG_PROT_MCS_SHIFT
);
3763 gf20_prot
= mm20_prot
;
3765 mm40_prot
= RT2860_REG_PROT_NAV_SHORT
| RT2860_REG_TXOP_ALLOW_ALL
|
3766 (RT2860_REG_PROT_PHYMODE_OFDM
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3767 (0x84 << RT2860_REG_PROT_MCS_SHIFT
);
3769 if (htprotmode
== IEEE80211_PROT_RTSCTS
)
3770 mm40_prot
|= RT2860_REG_PROT_CTRL_RTS_CTS
;
3771 else if (htprotmode
== IEEE80211_PROT_CTSONLY
)
3772 mm40_prot
|= RT2860_REG_PROT_CTRL_CTS
;
3774 mm40_prot
|= RT2860_REG_PROT_CTRL_NONE
;
3776 gf40_prot
= mm40_prot
;
3779 /* IEEE80211_HTINFO_OPMODE_MIXED */
3780 case IEEE80211_HTINFO_OPMODE_MIXED
:
3781 mm20_prot
= RT2860_REG_PROT_NAV_SHORT
|
3782 RT2860_REG_TXOP_ALLOW_CCK
| RT2860_REG_TXOP_ALLOW_OFDM
|
3783 RT2860_REG_TXOP_ALLOW_MM20
| RT2860_REG_TXOP_ALLOW_GF20
;
3785 if (ic
->ic_flags
& IEEE80211_F_USEPROT
)
3786 mm20_prot
|= (RT2860_REG_PROT_PHYMODE_CCK
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3787 (3 << RT2860_REG_PROT_MCS_SHIFT
);
3789 mm20_prot
|= (RT2860_REG_PROT_PHYMODE_OFDM
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3790 (4 << RT2860_REG_PROT_MCS_SHIFT
);
3792 if (htprotmode
== IEEE80211_PROT_RTSCTS
)
3793 mm20_prot
|= RT2860_REG_PROT_CTRL_RTS_CTS
;
3794 else if (htprotmode
== IEEE80211_PROT_CTSONLY
)
3795 mm20_prot
|= RT2860_REG_PROT_CTRL_CTS
;
3797 mm20_prot
|= RT2860_REG_PROT_CTRL_NONE
;
3799 gf20_prot
= mm20_prot
;
3801 mm40_prot
= RT2860_REG_PROT_NAV_SHORT
| RT2860_REG_TXOP_ALLOW_ALL
;
3803 if (ic
->ic_flags
& IEEE80211_F_USEPROT
)
3804 mm40_prot
|= (RT2860_REG_PROT_PHYMODE_CCK
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3805 (3 << RT2860_REG_PROT_MCS_SHIFT
);
3807 mm40_prot
|= (RT2860_REG_PROT_PHYMODE_OFDM
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3808 (0x84 << RT2860_REG_PROT_MCS_SHIFT
);
3810 if (htprotmode
== IEEE80211_PROT_RTSCTS
)
3811 mm40_prot
|= RT2860_REG_PROT_CTRL_RTS_CTS
;
3812 else if (htprotmode
== IEEE80211_PROT_CTSONLY
)
3813 mm40_prot
|= RT2860_REG_PROT_CTRL_CTS
;
3815 mm40_prot
|= RT2860_REG_PROT_CTRL_NONE
;
3817 gf40_prot
= mm40_prot
;
3821 * IEEE80211_HTINFO_OPMODE_PURE
3822 * IEEE80211_HTINFO_OPMODE_PROTOPT
3824 case IEEE80211_HTINFO_OPMODE_PURE
:
3825 case IEEE80211_HTINFO_OPMODE_PROTOPT
:
3827 mm20_prot
= RT2860_REG_PROT_NAV_SHORT
| RT2860_REG_PROT_CTRL_NONE
|
3828 RT2860_REG_TXOP_ALLOW_CCK
| RT2860_REG_TXOP_ALLOW_OFDM
|
3829 RT2860_REG_TXOP_ALLOW_MM20
| RT2860_REG_TXOP_ALLOW_GF20
|
3830 (RT2860_REG_PROT_PHYMODE_OFDM
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3831 (4 << RT2860_REG_PROT_MCS_SHIFT
);
3833 gf20_prot
= mm20_prot
;
3835 mm40_prot
= RT2860_REG_PROT_NAV_SHORT
| RT2860_REG_PROT_CTRL_NONE
|
3836 RT2860_REG_TXOP_ALLOW_ALL
|
3837 (RT2860_REG_PROT_PHYMODE_OFDM
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3838 (0x84 << RT2860_REG_PROT_MCS_SHIFT
);
3840 gf40_prot
= mm40_prot
;
3844 rt2860_io_mac_write(sc
, RT2860_REG_TX_MM20_PROT_CFG
, mm20_prot
);
3845 rt2860_io_mac_write(sc
, RT2860_REG_TX_MM40_PROT_CFG
, mm40_prot
);
3846 rt2860_io_mac_write(sc
, RT2860_REG_TX_GF20_PROT_CFG
, gf20_prot
);
3847 rt2860_io_mac_write(sc
, RT2860_REG_TX_GF40_PROT_CFG
, gf40_prot
);
3851 * rt2860_asic_updateslot
3853 static void rt2860_asic_updateslot(struct rt2860_softc
*sc
)
3856 struct ieee80211com
*ic
;
3857 struct ieee80211vap
*vap
;
3862 vap
= TAILQ_FIRST(&ic
->ic_vaps
);
3864 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATE
,
3865 "%s: %s short slot time\n",
3866 device_get_nameunit(sc
->dev
),
3867 ((ic
->ic_flags
& IEEE80211_F_SHSLOT
) ||
3868 ((vap
!= NULL
) && (vap
->iv_flags
& IEEE80211_F_BURST
))) ? "enabling" : "disabling");
3870 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_BKOFF_SLOT_CFG
);
3874 if ((ic
->ic_flags
& IEEE80211_F_SHSLOT
) ||
3875 ((vap
!= NULL
) && (vap
->iv_flags
& IEEE80211_F_BURST
)))
3876 tmp
|= IEEE80211_DUR_SHSLOT
;
3878 tmp
|= IEEE80211_DUR_SLOT
;
3880 rt2860_io_mac_write(sc
, RT2860_REG_BKOFF_SLOT_CFG
, tmp
);
3884 * rt2860_asic_wme_update
3886 static void rt2860_asic_wme_update(struct rt2860_softc
*sc
)
3889 struct ieee80211com
*ic
;
3890 struct ieee80211_wme_state
*wme
;
3891 const struct wmeParams
*wmep
;
3897 wmep
= wme
->wme_chanParams
.cap_wmeParams
;
3899 RT2860_DPRINTF(sc
, RT2860_DEBUG_WME
,
3900 "%s: wme update: WME_AC_VO=%d/%d/%d/%d, WME_AC_VI=%d/%d/%d/%d, "
3901 "WME_AC_BK=%d/%d/%d/%d, WME_AC_BE=%d/%d/%d/%d\n",
3902 device_get_nameunit(sc
->dev
),
3903 wmep
[WME_AC_VO
].wmep_aifsn
,
3904 wmep
[WME_AC_VO
].wmep_logcwmin
, wmep
[WME_AC_VO
].wmep_logcwmax
,
3905 wmep
[WME_AC_VO
].wmep_txopLimit
,
3906 wmep
[WME_AC_VI
].wmep_aifsn
,
3907 wmep
[WME_AC_VI
].wmep_logcwmin
, wmep
[WME_AC_VI
].wmep_logcwmax
,
3908 wmep
[WME_AC_VI
].wmep_txopLimit
,
3909 wmep
[WME_AC_BK
].wmep_aifsn
,
3910 wmep
[WME_AC_BK
].wmep_logcwmin
, wmep
[WME_AC_BK
].wmep_logcwmax
,
3911 wmep
[WME_AC_BK
].wmep_txopLimit
,
3912 wmep
[WME_AC_BE
].wmep_aifsn
,
3913 wmep
[WME_AC_BE
].wmep_logcwmin
, wmep
[WME_AC_BE
].wmep_logcwmax
,
3914 wmep
[WME_AC_BE
].wmep_txopLimit
);
3916 for (i
= 0; i
< WME_NUM_AC
; i
++)
3917 rt2860_io_mac_write(sc
, RT2860_REG_TX_EDCA_AC_CFG(i
),
3918 (wmep
[i
].wmep_logcwmax
<< 16) | (wmep
[i
].wmep_logcwmin
<< 12) |
3919 (wmep
[i
].wmep_aifsn
<< 8) | wmep
[i
].wmep_txopLimit
);
3921 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WMM_AIFSN_CFG
,
3922 (wmep
[WME_AC_VO
].wmep_aifsn
<< 12) | (wmep
[WME_AC_VI
].wmep_aifsn
<< 8) |
3923 (wmep
[WME_AC_BK
].wmep_aifsn
<< 4) | wmep
[WME_AC_BE
].wmep_aifsn
);
3925 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WMM_CWMIN_CFG
,
3926 (wmep
[WME_AC_VO
].wmep_logcwmin
<< 12) | (wmep
[WME_AC_VI
].wmep_logcwmin
<< 8) |
3927 (wmep
[WME_AC_BK
].wmep_logcwmin
<< 4) | wmep
[WME_AC_BE
].wmep_logcwmin
);
3929 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WMM_CWMAX_CFG
,
3930 (wmep
[WME_AC_VO
].wmep_logcwmax
<< 12) | (wmep
[WME_AC_VI
].wmep_logcwmax
<< 8) |
3931 (wmep
[WME_AC_BK
].wmep_logcwmax
<< 4) | wmep
[WME_AC_BE
].wmep_logcwmax
);
3933 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WMM_TXOP0_CFG
,
3934 (wmep
[WME_AC_BK
].wmep_txopLimit
<< 16) | wmep
[WME_AC_BE
].wmep_txopLimit
);
3936 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WMM_TXOP1_CFG
,
3937 (wmep
[WME_AC_VO
].wmep_txopLimit
<< 16) | wmep
[WME_AC_VI
].wmep_txopLimit
);
3941 * rt2860_asic_update_beacon
3943 static void rt2860_asic_update_beacon(struct rt2860_softc
*sc
,
3944 struct ieee80211vap
*vap
)
3946 struct rt2860_softc_vap
*rvap
;
3948 struct rt2860_txwi
*txwi
;
3951 rvap
= (struct rt2860_softc_vap
*) vap
;
3953 m
= rvap
->beacon_mbuf
;
3954 txwi
= &rvap
->beacon_txwi
;
3956 /* disable temporarily TSF sync */
3958 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_BCN_TIME_CFG
);
3960 tmp
&= ~(RT2860_REG_BCN_TX_ENABLE
|
3961 RT2860_REG_TSF_TIMER_ENABLE
|
3962 RT2860_REG_TBTT_TIMER_ENABLE
);
3964 rt2860_io_mac_write(sc
, RT2860_REG_BCN_TIME_CFG
, tmp
);
3966 /* write Tx wireless info and beacon frame to on-chip memory */
3968 rt2860_io_mac_write_multi(sc
, RT2860_REG_BEACON_BASE(0),
3969 txwi
, sizeof(struct rt2860_txwi
));
3971 rt2860_io_mac_write_multi(sc
, RT2860_REG_BEACON_BASE(0) + sizeof(struct rt2860_txwi
),
3972 mtod(m
, uint8_t *), m
->m_pkthdr
.len
);
3974 /* enable again TSF sync */
3976 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_BCN_TIME_CFG
);
3978 tmp
|= (RT2860_REG_BCN_TX_ENABLE
|
3979 RT2860_REG_TSF_TIMER_ENABLE
|
3980 RT2860_REG_TBTT_TIMER_ENABLE
);
3982 rt2860_io_mac_write(sc
, RT2860_REG_BCN_TIME_CFG
, tmp
);
3986 * rt2860_asic_clear_keytables
3988 static void rt2860_asic_clear_keytables(struct rt2860_softc
*sc
)
3992 /* clear Rx WCID search table (entries = 256, entry size = 8) */
3994 for (i
= 0; i
< 256; i
++)
3996 rt2860_io_mac_write(sc
, RT2860_REG_WCID(i
), 0xffffffff);
3997 rt2860_io_mac_write(sc
, RT2860_REG_WCID(i
) + 4, 0x0000ffff);
4000 /* clear WCID attribute table (entries = 256, entry size = 4) */
4002 rt2860_io_mac_set_region_4(sc
, RT2860_REG_WCID_ATTR(0), 0, 256);
4004 /* clear IV/EIV table (entries = 256, entry size = 8) */
4006 rt2860_io_mac_set_region_4(sc
, RT2860_REG_IVEIV(0), 0, 2 * 256);
4008 /* clear pairwise key table (entries = 64, entry size = 32) */
4010 rt2860_io_mac_set_region_4(sc
, RT2860_REG_PKEY(0), 0, 8 * 64);
4012 /* clear shared key table (entries = 32, entry size = 32) */
4014 rt2860_io_mac_set_region_4(sc
, RT2860_REG_SKEY(0, 0), 0, 8 * 32);
4016 /* clear shared key mode (entries = 32, entry size = 2) */
4018 rt2860_io_mac_set_region_4(sc
, RT2860_REG_SKEY_MODE(0), 0, 16);
4022 * rt2860_asic_add_ba_session
4024 static void rt2860_asic_add_ba_session(struct rt2860_softc
*sc
,
4025 uint8_t wcid
, int tid
)
4029 RT2860_DPRINTF(sc
, RT2860_DEBUG_BA
,
4030 "%s: adding BA session: wcid=0x%02x, tid=%d\n",
4031 device_get_nameunit(sc
->dev
), wcid
, tid
);
4033 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_WCID(wcid
) + 4);
4035 tmp
|= (0x10000 << tid
);
4037 rt2860_io_mac_write(sc
, RT2860_REG_WCID(wcid
) + 4, tmp
);
4041 * rt2860_asic_del_ba_session
4043 static void rt2860_asic_del_ba_session(struct rt2860_softc
*sc
,
4044 uint8_t wcid
, int tid
)
4048 RT2860_DPRINTF(sc
, RT2860_DEBUG_BA
,
4049 "%s: deleting BA session: wcid=0x%02x, tid=%d\n",
4050 device_get_nameunit(sc
->dev
), wcid
, tid
);
4052 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_WCID(wcid
) + 4);
4054 tmp
&= ~(0x10000 << tid
);
4056 rt2860_io_mac_write(sc
, RT2860_REG_WCID(wcid
) + 4, tmp
);
4060 * rt2860_beacon_alloc
4062 static int rt2860_beacon_alloc(struct rt2860_softc
*sc
,
4063 struct ieee80211vap
*vap
)
4065 struct ieee80211com
*ic
;
4066 struct rt2860_softc_vap
*rvap
;
4068 struct rt2860_txwi txwi
;
4072 rvap
= (struct rt2860_softc_vap
*) vap
;
4074 m
= ieee80211_beacon_alloc(vap
->iv_bss
, &rvap
->beacon_offsets
);
4078 rate
= IEEE80211_IS_CHAN_5GHZ(vap
->iv_bss
->ni_chan
) ? 12 : 2;
4079 mcs
= rt2860_rate2mcs(rate
);
4081 RT2860_DPRINTF(sc
, RT2860_DEBUG_BEACON
,
4082 "%s: beacon allocate: mcs=0x%02x\n",
4083 device_get_nameunit(sc
->dev
), mcs
);
4085 memset(&txwi
, 0, sizeof(struct rt2860_txwi
));
4087 txwi
.wcid
= RT2860_WCID_RESERVED
;
4088 txwi
.pid_mpdu_len
= ((htole16(m
->m_pkthdr
.len
) & RT2860_TXWI_MPDU_LEN_MASK
) <<
4089 RT2860_TXWI_MPDU_LEN_SHIFT
);
4090 txwi
.txop
= (RT2860_TXWI_TXOP_HT
<< RT2860_TXWI_TXOP_SHIFT
);
4091 txwi
.mpdu_density_flags
|=
4092 (RT2860_TXWI_FLAGS_TS
<< RT2860_TXWI_FLAGS_SHIFT
);
4093 txwi
.bawin_size_xflags
|=
4094 (RT2860_TXWI_XFLAGS_NSEQ
<< RT2860_TXWI_XFLAGS_SHIFT
);
4098 txwi
.phymode_ifs_stbc_shortgi
=
4099 (RT2860_TXWI_PHYMODE_CCK
<< RT2860_TXWI_PHYMODE_SHIFT
);
4101 if (rate
!= 2 && (ic
->ic_flags
& IEEE80211_F_SHPREAMBLE
))
4102 mcs
|= RT2860_TXWI_MCS_SHOTPRE
;
4106 txwi
.phymode_ifs_stbc_shortgi
=
4107 (RT2860_TXWI_PHYMODE_OFDM
<< RT2860_TXWI_PHYMODE_SHIFT
);
4110 txwi
.bw_mcs
= (RT2860_TXWI_BW_20
<< RT2860_TXWI_BW_SHIFT
) |
4111 ((mcs
& RT2860_TXWI_MCS_MASK
) << RT2860_TXWI_MCS_SHIFT
);
4113 if (rvap
->beacon_mbuf
!= NULL
)
4115 m_free(rvap
->beacon_mbuf
);
4116 rvap
->beacon_mbuf
= NULL
;
4119 rvap
->beacon_mbuf
= m
;
4120 rvap
->beacon_txwi
= txwi
;
4128 static uint8_t rt2860_rxrate(struct rt2860_rxwi
*rxwi
)
4130 uint8_t mcs
, phymode
;
4133 mcs
= (rxwi
->bw_mcs
>> RT2860_RXWI_MCS_SHIFT
) & RT2860_RXWI_MCS_MASK
;
4134 phymode
= (rxwi
->phymode_stbc_shortgi
>> RT2860_RXWI_PHYMODE_SHIFT
) &
4135 RT2860_RXWI_PHYMODE_MASK
;
4141 case RT2860_RXWI_PHYMODE_CCK
:
4142 switch (mcs
& ~RT2860_RXWI_MCS_SHOTPRE
)
4144 case 0: rate
= 2; break; /* 1 Mbps */
4145 case 1: rate
= 4; break; /* 2 MBps */
4146 case 2: rate
= 11; break; /* 5.5 Mbps */
4147 case 3: rate
= 22; break; /* 11 Mbps */
4151 case RT2860_RXWI_PHYMODE_OFDM
:
4154 case 0: rate
= 12; break; /* 6 Mbps */
4155 case 1: rate
= 18; break; /* 9 Mbps */
4156 case 2: rate
= 24; break; /* 12 Mbps */
4157 case 3: rate
= 36; break; /* 18 Mbps */
4158 case 4: rate
= 48; break; /* 24 Mbps */
4159 case 5: rate
= 72; break; /* 36 Mbps */
4160 case 6: rate
= 96; break; /* 48 Mbps */
4161 case 7: rate
= 108; break; /* 54 Mbps */
4165 case RT2860_RXWI_PHYMODE_HT_MIXED
:
4166 case RT2860_RXWI_PHYMODE_HT_GF
:
4174 * rt2860_maxrssi_rxpath
4176 static uint8_t rt2860_maxrssi_rxpath(struct rt2860_softc
*sc
,
4177 const struct rt2860_rxwi
*rxwi
)
4183 if (sc
->nrxpath
> 1)
4184 if (rxwi
->rssi
[1] > rxwi
->rssi
[rxpath
])
4187 if (sc
->nrxpath
> 2)
4188 if (rxwi
->rssi
[2] > rxwi
->rssi
[rxpath
])
4197 static int8_t rt2860_rssi2dbm(struct rt2860_softc
*sc
,
4198 uint8_t rssi
, uint8_t rxpath
)
4201 struct ieee80211com
*ic
;
4202 struct ieee80211_channel
*c
;
4204 int8_t rssi_off
, lna_gain
;
4212 chan
= ieee80211_chan2ieee(ic
, c
);
4214 if (IEEE80211_IS_CHAN_5GHZ(c
))
4216 rssi_off
= sc
->rssi_off_5ghz
[rxpath
];
4219 lna_gain
= sc
->lna_gain
[1];
4220 else if (chan
<= 128)
4221 lna_gain
= sc
->lna_gain
[2];
4223 lna_gain
= sc
->lna_gain
[3];
4227 rssi_off
= sc
->rssi_off_2ghz
[rxpath
] - sc
->lna_gain
[0];
4228 lna_gain
= sc
->lna_gain
[0];
4231 return (-12 - rssi_off
- lna_gain
- rssi
);
4237 static uint8_t rt2860_rate2mcs(uint8_t rate
)
4264 static int rt2860_tx_mgmt(struct rt2860_softc
*sc
,
4265 struct mbuf
*m
, struct ieee80211_node
*ni
, int qid
)
4268 struct ieee80211com
*ic
;
4269 struct ieee80211vap
*vap
;
4270 const struct ieee80211_txparam
*tp
;
4271 struct rt2860_softc_node
*rni
;
4272 struct rt2860_softc_tx_ring
*ring
;
4273 struct rt2860_softc_tx_data
*data
;
4274 struct rt2860_txdesc
*desc
;
4275 struct rt2860_txwi
*txwi
;
4276 struct ieee80211_frame
*wh
;
4277 struct rt2860_softc_tx_radiotap_header
*tap
;
4278 bus_dma_segment_t dma_seg
[RT2860_SOFTC_MAX_SCATTER
];
4279 u_int hdrsize
, hdrspace
;
4280 uint8_t rate
, stbc
, shortgi
, mcs
, pid
, qsel
;
4281 uint16_t len
, dmalen
, mpdu_len
, dur
;
4282 int error
, mimops
, ndmasegs
, ndescs
, i
, j
;
4284 KASSERT(qid
>= 0 && qid
< RT2860_SOFTC_TX_RING_COUNT
,
4285 ("%s: Tx MGMT: invalid qid=%d\n",
4286 device_get_nameunit(sc
->dev
), qid
));
4288 RT2860_SOFTC_TX_RING_ASSERT_LOCKED(&sc
->tx_ring
[qid
]);
4293 rni
= (struct rt2860_softc_node
*) ni
;
4294 tp
= ni
->ni_txparms
;
4296 ring
= &sc
->tx_ring
[qid
];
4297 desc
= &ring
->desc
[ring
->desc_cur
];
4298 data
= &ring
->data
[ring
->data_cur
];
4299 txwi
= (struct rt2860_txwi
*) (ring
->seg0
+ ring
->data_cur
* RT2860_TX_DATA_SEG0_SIZE
);
4301 wh
= mtod(m
, struct ieee80211_frame
*);
4303 rate
= tp
->mgmtrate
& IEEE80211_RATE_VAL
;
4305 /* fill Tx wireless info */
4307 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
4310 mcs
= rt2860_rate2mcs(rate
);
4312 /* calculate MPDU length without padding */
4314 hdrsize
= ieee80211_anyhdrsize(wh
);
4315 hdrspace
= ieee80211_anyhdrspace(ic
, wh
);
4316 mpdu_len
= m
->m_pkthdr
.len
- hdrspace
+ hdrsize
;
4318 memset(txwi
, 0, sizeof(struct rt2860_txwi
));
4320 /* management frames do not need encryption */
4322 txwi
->wcid
= RT2860_WCID_RESERVED
;
4324 /* MIMO power save */
4326 if ((ni
->ni_flags
& IEEE80211_NODE_HT
) && (ni
->ni_flags
& IEEE80211_NODE_MIMO_PS
))
4330 if (ni
->ni_flags
& IEEE80211_NODE_MIMO_RTS
)
4332 /* dynamic MIMO power save */
4334 txwi
->mpdu_density_flags
|=
4335 (RT2860_TXWI_FLAGS_MIMOPS
<< RT2860_TXWI_FLAGS_SHIFT
);
4339 /* static MIMO power save */
4352 pid
= (mcs
< 0xf) ? (mcs
+ 1) : mcs
;
4354 txwi
->pid_mpdu_len
= ((htole16(pid
) & RT2860_TXWI_PID_MASK
) <<
4355 RT2860_TXWI_PID_SHIFT
) | ((htole16(mpdu_len
) & RT2860_TXWI_MPDU_LEN_MASK
) <<
4356 RT2860_TXWI_MPDU_LEN_SHIFT
);
4358 stbc
= sc
->tx_stbc
&& (mcs
<= 7) && (vap
->iv_htcaps
& IEEE80211_HTCAP_TXSTBC
) &&
4359 (ni
->ni_flags
& IEEE80211_NODE_HT
) && (ni
->ni_htcap
& IEEE80211_HTCAP_RXSTBC
);
4361 shortgi
= ((vap
->iv_flags_ht
& IEEE80211_FHT_SHORTGI20
) && (ni
->ni_flags
& IEEE80211_NODE_SGI20
) && (ni
->ni_chw
== 20)) ||
4362 ((vap
->iv_flags_ht
& IEEE80211_FHT_SHORTGI40
) && (ni
->ni_flags
& IEEE80211_NODE_SGI40
) && (ni
->ni_chw
== 40));
4364 txwi
->phymode_ifs_stbc_shortgi
|=
4365 ((stbc
& RT2860_TXWI_STBC_MASK
) << RT2860_TXWI_STBC_SHIFT
) |
4366 ((shortgi
& RT2860_TXWI_SHORTGI_MASK
) << RT2860_TXWI_SHORTGI_SHIFT
);
4368 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
4370 txwi
->phymode_ifs_stbc_shortgi
|=
4371 (RT2860_TXWI_PHYMODE_HT_MIXED
<< RT2860_TXWI_PHYMODE_SHIFT
);
4375 if (ieee80211_rate2phytype(ic
->ic_rt
, rate
) != IEEE80211_T_OFDM
)
4377 txwi
->phymode_ifs_stbc_shortgi
|=
4378 (RT2860_TXWI_PHYMODE_CCK
<< RT2860_TXWI_PHYMODE_SHIFT
);
4380 if (rate
!= 2 && (ic
->ic_flags
& IEEE80211_F_SHPREAMBLE
))
4381 mcs
|= RT2860_TXWI_MCS_SHOTPRE
;
4385 txwi
->phymode_ifs_stbc_shortgi
|=
4386 (RT2860_TXWI_PHYMODE_OFDM
<< RT2860_TXWI_PHYMODE_SHIFT
);
4390 txwi
->bw_mcs
= (RT2860_TXWI_BW_20
<< RT2860_TXWI_BW_SHIFT
) |
4391 ((mcs
& RT2860_TXWI_MCS_MASK
) << RT2860_TXWI_MCS_SHIFT
);
4393 txwi
->txop
= (RT2860_TXWI_TXOP_BACKOFF
<< RT2860_TXWI_TXOP_SHIFT
);
4395 /* skip ACKs for multicast frames */
4397 if (!IEEE80211_IS_MULTICAST(wh
->i_addr1
))
4399 txwi
->bawin_size_xflags
|=
4400 (RT2860_TXWI_XFLAGS_ACK
<< RT2860_TXWI_XFLAGS_SHIFT
);
4402 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
4404 /* preamble + plcp + signal extension + SIFS */
4406 dur
= 16 + 4 + 6 + 10;
4410 dur
= ieee80211_ack_duration(ic
->ic_rt
, rate
,
4411 ic
->ic_flags
& IEEE80211_F_SHPREAMBLE
);
4414 *(uint16_t *) wh
->i_dur
= htole16(dur
);
4417 /* ask MAC to insert timestamp into probe responses */
4419 if ((wh
->i_fc
[0] & (IEEE80211_FC0_TYPE_MASK
| IEEE80211_FC0_SUBTYPE_MASK
)) ==
4420 (IEEE80211_FC0_TYPE_MGT
| IEEE80211_FC0_SUBTYPE_PROBE_RESP
))
4421 txwi
->mpdu_density_flags
|=
4422 (RT2860_TXWI_FLAGS_TS
<< RT2860_TXWI_FLAGS_SHIFT
);
4424 if (ieee80211_radiotap_active_vap(vap
))
4428 tap
->flags
= IEEE80211_RADIOTAP_F_DATAPAD
;
4429 tap
->chan_flags
= htole32(ic
->ic_curchan
->ic_flags
);
4430 tap
->chan_freq
= htole16(ic
->ic_curchan
->ic_freq
);
4431 tap
->chan_ieee
= ic
->ic_curchan
->ic_ieee
;
4432 tap
->chan_maxpow
= 0;
4434 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
4435 tap
->rate
= mcs
| IEEE80211_RATE_MCS
;
4439 if (mcs
& RT2860_TXWI_MCS_SHOTPRE
)
4440 tap
->flags
|= IEEE80211_RADIOTAP_F_SHORTPRE
;
4443 tap
->flags
|= IEEE80211_RADIOTAP_F_SHORTGI
;
4445 if (wh
->i_fc
[1] & IEEE80211_FC1_WEP
)
4446 tap
->flags
|= IEEE80211_RADIOTAP_F_WEP
;
4448 if (wh
->i_fc
[1] & IEEE80211_FC1_WEP
)
4450 wh
->i_fc
[1] &= ~IEEE80211_FC1_WEP
;
4452 ieee80211_radiotap_tx(vap
, m
);
4454 wh
->i_fc
[1] |= IEEE80211_FC1_WEP
;
4458 ieee80211_radiotap_tx(vap
, m
);
4462 /* copy and trim 802.11 header */
4464 m_copydata(m
, 0, hdrsize
, (caddr_t
) (txwi
+ 1));
4467 error
= bus_dmamap_load_mbuf_sg(ring
->data_dma_tag
, data
->dma_map
, m
,
4468 dma_seg
, &ndmasegs
, 0);
4471 /* too many fragments, linearize */
4473 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
4474 "%s: could not load mbuf DMA map, trying to linearize mbuf: ndmasegs=%d, len=%d, error=%d\n",
4475 device_get_nameunit(sc
->dev
), ndmasegs
, m
->m_pkthdr
.len
, error
);
4477 m
= m_defrag(m
, M_DONTWAIT
);
4481 sc
->tx_defrag_packets
++;
4483 error
= bus_dmamap_load_mbuf_sg(ring
->data_dma_tag
, data
->dma_map
, m
,
4484 dma_seg
, &ndmasegs
, 0);
4487 printf("%s: could not load mbuf DMA map: ndmasegs=%d, len=%d, error=%d\n",
4488 device_get_nameunit(sc
->dev
), ndmasegs
, m
->m_pkthdr
.len
, error
);
4494 if (m
->m_pkthdr
.len
== 0)
4497 /* determine how many Tx descs are required */
4499 ndescs
= 1 + ndmasegs
/ 2;
4500 if ((ring
->desc_queued
+ ndescs
) > (RT2860_SOFTC_TX_RING_DESC_COUNT
- 2))
4502 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
4503 "%s: there are not enough Tx descs\n",
4504 device_get_nameunit(sc
->dev
));
4506 sc
->no_tx_desc_avail
++;
4508 bus_dmamap_unload(ring
->data_dma_tag
, data
->dma_map
);
4516 /* set up Tx descs */
4518 /* first segment is Tx wireless info and 802.11 header */
4520 len
= sizeof(struct rt2860_txwi
) + hdrsize
;
4522 /* align end on a 4-bytes boundary */
4524 dmalen
= (len
+ 3) & ~ 3;
4526 memset((caddr_t
) txwi
+ len
, 0, dmalen
- len
);
4528 qsel
= RT2860_TXDESC_QSEL_EDCA
;
4530 desc
->sdp0
= htole32(ring
->seg0_phys_addr
+ ring
->data_cur
* RT2860_TX_DATA_SEG0_SIZE
);
4531 desc
->sdl0
= htole16(dmalen
);
4532 desc
->qsel_flags
= (qsel
<< RT2860_TXDESC_QSEL_SHIFT
);
4534 /* set up payload segments */
4536 for (i
= ndmasegs
, j
= 0; i
>= 2; i
-= 2)
4538 desc
->sdp1
= htole32(dma_seg
[j
].ds_addr
);
4539 desc
->sdl1
= htole16(dma_seg
[j
].ds_len
);
4541 ring
->desc_queued
++;
4542 ring
->desc_cur
= (ring
->desc_cur
+ 1) % RT2860_SOFTC_TX_RING_DESC_COUNT
;
4546 desc
= &ring
->desc
[ring
->desc_cur
];
4548 desc
->sdp0
= htole32(dma_seg
[j
].ds_addr
);
4549 desc
->sdl0
= htole16(dma_seg
[j
].ds_len
);
4550 desc
->qsel_flags
= (qsel
<< RT2860_TXDESC_QSEL_SHIFT
);
4555 /* finalize last payload segment */
4559 desc
->sdp1
= htole32(dma_seg
[j
].ds_addr
);
4560 desc
->sdl1
= htole16(dma_seg
[j
].ds_len
| RT2860_TXDESC_SDL1_LASTSEG
);
4564 desc
->sdl0
|= htole16(RT2860_TXDESC_SDL0_LASTSEG
);
4568 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
4569 "%s: sending MGMT frame: qid=%d, hdrsize=%d, hdrspace=%d, len=%d, "
4570 "stbc=%d, shortgi=%d, mcs=%d, mimops=%d, DMA len=%d, ndmasegs=%d, DMA ds_len=%d/%d/%d/%d/%d\n",
4571 device_get_nameunit(sc
->dev
),
4572 qid
, hdrsize
, hdrspace
, m
->m_pkthdr
.len
+ hdrsize
,
4573 stbc
, shortgi
, mcs
, mimops
, dmalen
, ndmasegs
,
4574 (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
);
4576 bus_dmamap_sync(ring
->seg0_dma_tag
, ring
->seg0_dma_map
,
4577 BUS_DMASYNC_PREWRITE
);
4578 bus_dmamap_sync(ring
->data_dma_tag
, data
->dma_map
,
4579 BUS_DMASYNC_PREWRITE
);
4580 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
4581 BUS_DMASYNC_PREWRITE
);
4583 ring
->desc_queued
++;
4584 ring
->desc_cur
= (ring
->desc_cur
+ 1) % RT2860_SOFTC_TX_RING_DESC_COUNT
;
4586 ring
->data_queued
++;
4587 ring
->data_cur
= (ring
->data_cur
+ 1) % RT2860_SOFTC_TX_RING_DATA_COUNT
;
4591 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_CTX_IDX(qid
), ring
->desc_cur
);
4599 static int rt2860_tx_data(struct rt2860_softc
*sc
,
4600 struct mbuf
*m
, struct ieee80211_node
*ni
, int qid
)
4603 struct ieee80211com
*ic
;
4604 struct ieee80211vap
*vap
;
4605 const struct ieee80211_txparam
*tp
;
4606 struct rt2860_softc_node
*rni
;
4607 struct rt2860_softc_tx_ring
*ring
;
4608 struct rt2860_softc_tx_data
*data
;
4609 struct rt2860_txdesc
*desc
;
4610 struct rt2860_txwi
*txwi
;
4611 struct ieee80211_frame
*wh
;
4612 struct ieee80211_tx_ampdu
*tx_ampdu
;
4613 ieee80211_seq seqno
;
4614 struct rt2860_softc_tx_radiotap_header
*tap
;
4615 bus_dma_segment_t dma_seg
[RT2860_SOFTC_MAX_SCATTER
];
4616 u_int hdrsize
, hdrspace
;
4617 uint8_t type
, rate
, bw
, stbc
, shortgi
, mcs
, pid
, wcid
, mpdu_density
, bawin_size
, qsel
;
4618 uint16_t qos
, len
, dmalen
, mpdu_len
, dur
;
4619 int error
, hasqos
, ac
, tid
, ampdu
, mimops
, ndmasegs
, ndescs
, i
, j
;
4621 KASSERT(qid
>= 0 && qid
< RT2860_SOFTC_TX_RING_COUNT
,
4622 ("%s: Tx data: invalid qid=%d\n",
4623 device_get_nameunit(sc
->dev
), qid
));
4625 RT2860_SOFTC_TX_RING_ASSERT_LOCKED(&sc
->tx_ring
[qid
]);
4630 rni
= (struct rt2860_softc_node
*) ni
;
4631 tp
= ni
->ni_txparms
;
4633 ring
= &sc
->tx_ring
[qid
];
4634 desc
= &ring
->desc
[ring
->desc_cur
];
4635 data
= &ring
->data
[ring
->data_cur
];
4636 txwi
= (struct rt2860_txwi
*) (ring
->seg0
+ ring
->data_cur
* RT2860_TX_DATA_SEG0_SIZE
);
4638 wh
= mtod(m
, struct ieee80211_frame
*);
4640 type
= wh
->i_fc
[0] & IEEE80211_FC0_TYPE_MASK
;
4642 hasqos
= IEEE80211_QOS_HAS_SEQ(wh
);
4645 if (IEEE80211_HAS_ADDR4(wh
))
4646 qos
= le16toh(*(const uint16_t *)
4647 (((struct ieee80211_qosframe_addr4
*) wh
)->i_qos
));
4649 qos
= le16toh(*(const uint16_t *)
4650 (((struct ieee80211_qosframe
*) wh
)->i_qos
));
4657 if (IEEE80211_IS_MULTICAST(wh
->i_addr1
))
4658 rate
= tp
->mcastrate
;
4659 else if (m
->m_flags
& M_EAPOL
)
4660 rate
= tp
->mgmtrate
;
4661 else if (tp
->ucastrate
!= IEEE80211_FIXED_RATE_NONE
)
4662 rate
= tp
->ucastrate
;
4664 rate
= ni
->ni_txrate
;
4666 rate
&= IEEE80211_RATE_VAL
;
4668 /* fill Tx wireless info */
4670 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
4673 mcs
= rt2860_rate2mcs(rate
);
4675 if (type
== IEEE80211_FC0_TYPE_DATA
)
4676 wcid
= !IEEE80211_IS_MULTICAST(wh
->i_addr1
) ? rni
->staid
: RT2860_WCID_MCAST
;
4678 wcid
= RT2860_WCID_RESERVED
;
4680 /* calculate MPDU length without padding */
4682 hdrsize
= ieee80211_anyhdrsize(wh
);
4683 hdrspace
= ieee80211_anyhdrspace(ic
, wh
);
4684 mpdu_len
= m
->m_pkthdr
.len
- hdrspace
+ hdrsize
;
4686 memset(txwi
, 0, sizeof(struct rt2860_txwi
));
4690 /* MIMO power save */
4692 if ((ni
->ni_flags
& IEEE80211_NODE_HT
) && (ni
->ni_flags
& IEEE80211_NODE_MIMO_PS
))
4696 if (ni
->ni_flags
& IEEE80211_NODE_MIMO_RTS
)
4698 /* dynamic MIMO power save */
4700 txwi
->mpdu_density_flags
|=
4701 (RT2860_TXWI_FLAGS_MIMOPS
<< RT2860_TXWI_FLAGS_SHIFT
);
4705 /* static MIMO power save */
4718 pid
= (mcs
< 0xf) ? (mcs
+ 1) : mcs
;
4720 txwi
->pid_mpdu_len
= ((htole16(pid
) & RT2860_TXWI_PID_MASK
) <<
4721 RT2860_TXWI_PID_SHIFT
) | ((htole16(mpdu_len
) & RT2860_TXWI_MPDU_LEN_MASK
) <<
4722 RT2860_TXWI_MPDU_LEN_SHIFT
);
4724 stbc
= sc
->tx_stbc
&& (mcs
<= 7) && (vap
->iv_htcaps
& IEEE80211_HTCAP_TXSTBC
) &&
4725 (ni
->ni_flags
& IEEE80211_NODE_HT
) && (ni
->ni_htcap
& IEEE80211_HTCAP_RXSTBC
);
4727 shortgi
= ((vap
->iv_flags_ht
& IEEE80211_FHT_SHORTGI20
) && (ni
->ni_flags
& IEEE80211_NODE_SGI20
) && (ni
->ni_chw
== 20)) ||
4728 ((vap
->iv_flags_ht
& IEEE80211_FHT_SHORTGI40
) && (ni
->ni_flags
& IEEE80211_NODE_SGI40
) && (ni
->ni_chw
== 40));
4730 txwi
->phymode_ifs_stbc_shortgi
|=
4731 ((stbc
& RT2860_TXWI_STBC_MASK
) << RT2860_TXWI_STBC_SHIFT
) |
4732 ((shortgi
& RT2860_TXWI_SHORTGI_MASK
) << RT2860_TXWI_SHORTGI_SHIFT
);
4734 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
4736 txwi
->phymode_ifs_stbc_shortgi
|=
4737 (RT2860_TXWI_PHYMODE_HT_MIXED
<< RT2860_TXWI_PHYMODE_SHIFT
);
4741 if (ieee80211_rate2phytype(ic
->ic_rt
, rate
) != IEEE80211_T_OFDM
)
4743 txwi
->phymode_ifs_stbc_shortgi
|=
4744 (RT2860_TXWI_PHYMODE_CCK
<< RT2860_TXWI_PHYMODE_SHIFT
);
4746 if (rate
!= 2 && (ic
->ic_flags
& IEEE80211_F_SHPREAMBLE
))
4747 mcs
|= RT2860_TXWI_MCS_SHOTPRE
;
4751 txwi
->phymode_ifs_stbc_shortgi
|=
4752 (RT2860_TXWI_PHYMODE_OFDM
<< RT2860_TXWI_PHYMODE_SHIFT
);
4756 if ((ni
->ni_flags
& IEEE80211_NODE_HT
) && (ni
->ni_chw
== 40))
4757 bw
= RT2860_TXWI_BW_40
;
4759 bw
= RT2860_TXWI_BW_20
;
4761 txwi
->bw_mcs
= ((bw
& RT2860_TXWI_BW_MASK
) << RT2860_TXWI_BW_SHIFT
) |
4762 ((mcs
& RT2860_TXWI_MCS_MASK
) << RT2860_TXWI_MCS_SHIFT
);
4764 txwi
->txop
= (RT2860_TXWI_TXOP_HT
<< RT2860_TXWI_TXOP_SHIFT
);
4766 if (!IEEE80211_IS_MULTICAST(wh
->i_addr1
) &&
4767 (!hasqos
|| (qos
& IEEE80211_QOS_ACKPOLICY
) != IEEE80211_QOS_ACKPOLICY_NOACK
))
4769 txwi
->bawin_size_xflags
|=
4770 (RT2860_TXWI_XFLAGS_ACK
<< RT2860_TXWI_XFLAGS_SHIFT
);
4772 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
4774 /* preamble + plcp + signal extension + SIFS */
4776 dur
= 16 + 4 + 6 + 10;
4780 dur
= ieee80211_ack_duration(ic
->ic_rt
, rate
,
4781 ic
->ic_flags
& IEEE80211_F_SHPREAMBLE
);
4784 *(uint16_t *) wh
->i_dur
= htole16(dur
);
4787 /* check for A-MPDU */
4789 if (m
->m_flags
& M_AMPDU_MPDU
)
4791 ac
= M_WME_GETAC(m
);
4792 tid
= WME_AC_TO_TID(ac
);
4793 tx_ampdu
= &ni
->ni_tx_ampdu
[ac
];
4795 mpdu_density
= RT2860_MS(ni
->ni_htparam
, IEEE80211_HTCAP_MPDUDENSITY
);
4796 bawin_size
= tx_ampdu
->txa_wnd
;
4798 txwi
->mpdu_density_flags
|=
4799 ((mpdu_density
& RT2860_TXWI_MPDU_DENSITY_MASK
) << RT2860_TXWI_MPDU_DENSITY_SHIFT
) |
4800 (RT2860_TXWI_FLAGS_AMPDU
<< RT2860_TXWI_FLAGS_SHIFT
);
4802 txwi
->bawin_size_xflags
|=
4803 ((bawin_size
& RT2860_TXWI_BAWIN_SIZE_MASK
) << RT2860_TXWI_BAWIN_SIZE_SHIFT
);
4805 seqno
= ni
->ni_txseqs
[tid
]++;
4807 *(uint16_t *) &wh
->i_seq
[0] = htole16(seqno
<< IEEE80211_SEQ_SEQ_SHIFT
);
4818 /* ask MAC to insert timestamp into probe responses */
4820 if ((wh
->i_fc
[0] & (IEEE80211_FC0_TYPE_MASK
| IEEE80211_FC0_SUBTYPE_MASK
)) ==
4821 (IEEE80211_FC0_TYPE_MGT
| IEEE80211_FC0_SUBTYPE_PROBE_RESP
))
4822 txwi
->mpdu_density_flags
|=
4823 (RT2860_TXWI_FLAGS_TS
<< RT2860_TXWI_FLAGS_SHIFT
);
4825 if (ieee80211_radiotap_active_vap(vap
))
4829 tap
->flags
= IEEE80211_RADIOTAP_F_DATAPAD
;
4830 tap
->chan_flags
= htole32(ic
->ic_curchan
->ic_flags
);
4831 tap
->chan_freq
= htole16(ic
->ic_curchan
->ic_freq
);
4832 tap
->chan_ieee
= ic
->ic_curchan
->ic_ieee
;
4833 tap
->chan_maxpow
= 0;
4835 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
4836 tap
->rate
= mcs
| IEEE80211_RATE_MCS
;
4840 if (mcs
& RT2860_TXWI_MCS_SHOTPRE
)
4841 tap
->flags
|= IEEE80211_RADIOTAP_F_SHORTPRE
;
4844 tap
->flags
|= IEEE80211_RADIOTAP_F_SHORTGI
;
4846 if (wh
->i_fc
[1] & IEEE80211_FC1_WEP
)
4847 tap
->flags
|= IEEE80211_RADIOTAP_F_WEP
;
4849 /* XXX use temporarily radiotap CFP flag as A-MPDU flag */
4852 tap
->flags
|= IEEE80211_RADIOTAP_F_CFP
;
4854 if (wh
->i_fc
[1] & IEEE80211_FC1_WEP
)
4856 wh
->i_fc
[1] &= ~IEEE80211_FC1_WEP
;
4858 ieee80211_radiotap_tx(vap
, m
);
4860 wh
->i_fc
[1] |= IEEE80211_FC1_WEP
;
4864 ieee80211_radiotap_tx(vap
, m
);
4868 /* copy and trim 802.11 header */
4870 m_copydata(m
, 0, hdrsize
, (caddr_t
) (txwi
+ 1));
4873 error
= bus_dmamap_load_mbuf_sg(ring
->data_dma_tag
, data
->dma_map
, m
,
4874 dma_seg
, &ndmasegs
, 0);
4877 /* too many fragments, linearize */
4879 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
4880 "%s: could not load mbuf DMA map, trying to linearize mbuf: ndmasegs=%d, len=%d, error=%d\n",
4881 device_get_nameunit(sc
->dev
), ndmasegs
, m
->m_pkthdr
.len
, error
);
4883 m
= m_defrag(m
, M_DONTWAIT
);
4887 sc
->tx_defrag_packets
++;
4889 error
= bus_dmamap_load_mbuf_sg(ring
->data_dma_tag
, data
->dma_map
, m
,
4890 dma_seg
, &ndmasegs
, 0);
4893 printf("%s: could not load mbuf DMA map: ndmasegs=%d, len=%d, error=%d\n",
4894 device_get_nameunit(sc
->dev
), ndmasegs
, m
->m_pkthdr
.len
, error
);
4900 if (m
->m_pkthdr
.len
== 0)
4903 /* determine how many Tx descs are required */
4905 ndescs
= 1 + ndmasegs
/ 2;
4906 if ((ring
->desc_queued
+ ndescs
) > (RT2860_SOFTC_TX_RING_DESC_COUNT
- 2))
4908 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
4909 "%s: there are not enough Tx descs\n",
4910 device_get_nameunit(sc
->dev
));
4912 sc
->no_tx_desc_avail
++;
4914 bus_dmamap_unload(ring
->data_dma_tag
, data
->dma_map
);
4922 /* set up Tx descs */
4924 /* first segment is Tx wireless info and 802.11 header */
4926 len
= sizeof(struct rt2860_txwi
) + hdrsize
;
4928 /* align end on a 4-bytes boundary */
4930 dmalen
= (len
+ 3) & ~ 3;
4932 memset((caddr_t
) txwi
+ len
, 0, dmalen
- len
);
4934 qsel
= RT2860_TXDESC_QSEL_EDCA
;
4936 desc
->sdp0
= htole32(ring
->seg0_phys_addr
+ ring
->data_cur
* RT2860_TX_DATA_SEG0_SIZE
);
4937 desc
->sdl0
= htole16(dmalen
);
4938 desc
->qsel_flags
= (qsel
<< RT2860_TXDESC_QSEL_SHIFT
);
4940 /* set up payload segments */
4942 for (i
= ndmasegs
, j
= 0; i
>= 2; i
-= 2)
4944 desc
->sdp1
= htole32(dma_seg
[j
].ds_addr
);
4945 desc
->sdl1
= htole16(dma_seg
[j
].ds_len
);
4947 ring
->desc_queued
++;
4948 ring
->desc_cur
= (ring
->desc_cur
+ 1) % RT2860_SOFTC_TX_RING_DESC_COUNT
;
4952 desc
= &ring
->desc
[ring
->desc_cur
];
4954 desc
->sdp0
= htole32(dma_seg
[j
].ds_addr
);
4955 desc
->sdl0
= htole16(dma_seg
[j
].ds_len
);
4956 desc
->qsel_flags
= (qsel
<< RT2860_TXDESC_QSEL_SHIFT
);
4961 /* finalize last payload segment */
4965 desc
->sdp1
= htole32(dma_seg
[j
].ds_addr
);
4966 desc
->sdl1
= htole16(dma_seg
[j
].ds_len
| RT2860_TXDESC_SDL1_LASTSEG
);
4970 desc
->sdl0
|= htole16(RT2860_TXDESC_SDL0_LASTSEG
);
4974 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
4975 "%s: sending data: qid=%d, hdrsize=%d, hdrspace=%d, len=%d, "
4976 "bw=%d, stbc=%d, shortgi=%d, mcs=%d, wcid=0x%02x, "
4977 "ampdu=%d (density=%d, winsize=%d), mimops=%d, DMA len=%d, ndmasegs=%d, DMA ds_len=%d/%d/%d/%d/%d\n",
4978 device_get_nameunit(sc
->dev
),
4979 qid
, hdrsize
, hdrspace
, m
->m_pkthdr
.len
+ hdrsize
,
4980 bw
, stbc
, shortgi
, mcs
, wcid
, ampdu
, mpdu_density
, bawin_size
, mimops
, dmalen
, ndmasegs
,
4981 (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
);
4983 bus_dmamap_sync(ring
->seg0_dma_tag
, ring
->seg0_dma_map
,
4984 BUS_DMASYNC_PREWRITE
);
4985 bus_dmamap_sync(ring
->data_dma_tag
, data
->dma_map
,
4986 BUS_DMASYNC_PREWRITE
);
4987 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
4988 BUS_DMASYNC_PREWRITE
);
4990 ring
->desc_queued
++;
4991 ring
->desc_cur
= (ring
->desc_cur
+ 1) % RT2860_SOFTC_TX_RING_DESC_COUNT
;
4993 ring
->data_queued
++;
4994 ring
->data_cur
= (ring
->data_cur
+ 1) % RT2860_SOFTC_TX_RING_DATA_COUNT
;
4998 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_CTX_IDX(qid
), ring
->desc_cur
);
5006 static int rt2860_tx_raw(struct rt2860_softc
*sc
,
5007 struct mbuf
*m
, struct ieee80211_node
*ni
,
5008 const struct ieee80211_bpf_params
*params
)
5010 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
5012 device_get_nameunit(sc
->dev
));
5020 static void rt2860_intr(void *arg
)
5022 struct rt2860_softc
*sc
;
5029 /* acknowledge interrupts */
5031 status
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_INT_STATUS
);
5032 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_INT_STATUS
, status
);
5034 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
5035 "%s: interrupt: status = 0x%08x\n",
5036 device_get_nameunit(sc
->dev
), status
);
5038 if (status
== 0xffffffff || /* device likely went away */
5039 status
== 0) /* not for us */
5044 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
5047 if (status
& RT2860_REG_INT_TX_COHERENT
)
5048 rt2860_tx_coherent_intr(sc
);
5050 if (status
& RT2860_REG_INT_RX_COHERENT
)
5051 rt2860_rx_coherent_intr(sc
);
5053 if (status
& RT2860_REG_INT_TXRX_COHERENT
)
5054 rt2860_txrx_coherent_intr(sc
);
5056 if (status
& RT2860_REG_INT_FIFO_STA_FULL
)
5057 rt2860_fifo_sta_full_intr(sc
);
5059 if (status
& RT2860_REG_INT_TX_MGMT_DONE
)
5060 rt2860_tx_intr(sc
, 5);
5062 if (status
& RT2860_REG_INT_RX_DONE
)
5065 if (status
& RT2860_REG_INT_RX_DELAY_DONE
)
5066 rt2860_rx_delay_intr(sc
);
5068 if (status
& RT2860_REG_INT_TX_HCCA_DONE
)
5069 rt2860_tx_intr(sc
, 4);
5071 if (status
& RT2860_REG_INT_TX_AC3_DONE
)
5072 rt2860_tx_intr(sc
, 3);
5074 if (status
& RT2860_REG_INT_TX_AC2_DONE
)
5075 rt2860_tx_intr(sc
, 2);
5077 if (status
& RT2860_REG_INT_TX_AC1_DONE
)
5078 rt2860_tx_intr(sc
, 1);
5080 if (status
& RT2860_REG_INT_TX_AC0_DONE
)
5081 rt2860_tx_intr(sc
, 0);
5083 if (status
& RT2860_REG_INT_TX_DELAY_DONE
)
5084 rt2860_tx_delay_intr(sc
);
5086 if (status
& RT2860_REG_INT_PRE_TBTT
)
5087 rt2860_pre_tbtt_intr(sc
);
5089 if (status
& RT2860_REG_INT_TBTT
)
5090 rt2860_tbtt_intr(sc
);
5092 if (status
& RT2860_REG_INT_MCU_CMD
)
5093 rt2860_mcu_cmd_intr(sc
);
5095 if (status
& RT2860_REG_INT_AUTO_WAKEUP
)
5096 rt2860_auto_wakeup_intr(sc
);
5098 if (status
& RT2860_REG_INT_GP_TIMER
)
5099 rt2860_gp_timer_intr(sc
);
5103 * rt2860_tx_coherent_intr
5105 static void rt2860_tx_coherent_intr(struct rt2860_softc
*sc
)
5110 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
5111 "%s: Tx coherent interrupt\n",
5112 device_get_nameunit(sc
->dev
));
5114 sc
->tx_coherent_interrupts
++;
5116 /* restart DMA engine */
5118 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
);
5120 tmp
&= ~(RT2860_REG_TX_WB_DDONE
|
5121 RT2860_REG_RX_DMA_ENABLE
|
5122 RT2860_REG_TX_DMA_ENABLE
);
5124 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
, tmp
);
5126 /* init Tx rings (4 EDCAs + HCCA + MGMT) */
5128 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
5129 rt2860_reset_tx_ring(sc
, &sc
->tx_ring
[i
]);
5131 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
5133 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_BASE_PTR(i
),
5134 sc
->tx_ring
[i
].desc_phys_addr
);
5135 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_MAX_CNT(i
),
5136 RT2860_SOFTC_TX_RING_DESC_COUNT
);
5137 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_CTX_IDX(i
), 0);
5142 rt2860_reset_rx_ring(sc
, &sc
->rx_ring
);
5144 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_BASE_PTR
,
5145 sc
->rx_ring
.desc_phys_addr
);
5146 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_MAX_CNT
,
5147 RT2860_SOFTC_RX_RING_DATA_COUNT
);
5148 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_CALC_IDX
,
5149 RT2860_SOFTC_RX_RING_DATA_COUNT
- 1);
5151 rt2860_txrx_enable(sc
);
5155 * rt2860_rx_coherent_intr
5157 static void rt2860_rx_coherent_intr(struct rt2860_softc
*sc
)
5162 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
5163 "%s: Rx coherent interrupt\n",
5164 device_get_nameunit(sc
->dev
));
5166 sc
->rx_coherent_interrupts
++;
5168 /* restart DMA engine */
5170 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
);
5172 tmp
&= ~(RT2860_REG_TX_WB_DDONE
|
5173 RT2860_REG_RX_DMA_ENABLE
|
5174 RT2860_REG_TX_DMA_ENABLE
);
5176 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
, tmp
);
5178 /* init Tx rings (4 EDCAs + HCCA + MGMT) */
5180 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
5181 rt2860_reset_tx_ring(sc
, &sc
->tx_ring
[i
]);
5183 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
5185 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_BASE_PTR(i
),
5186 sc
->tx_ring
[i
].desc_phys_addr
);
5187 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_MAX_CNT(i
),
5188 RT2860_SOFTC_TX_RING_DESC_COUNT
);
5189 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_CTX_IDX(i
), 0);
5194 rt2860_reset_rx_ring(sc
, &sc
->rx_ring
);
5196 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_BASE_PTR
,
5197 sc
->rx_ring
.desc_phys_addr
);
5198 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_MAX_CNT
,
5199 RT2860_SOFTC_RX_RING_DATA_COUNT
);
5200 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_CALC_IDX
,
5201 RT2860_SOFTC_RX_RING_DATA_COUNT
- 1);
5203 rt2860_txrx_enable(sc
);
5207 * rt2860_txrx_coherent_intr
5209 static void rt2860_txrx_coherent_intr(struct rt2860_softc
*sc
)
5214 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
5215 "%s: Tx/Rx coherent interrupt\n",
5216 device_get_nameunit(sc
->dev
));
5218 sc
->txrx_coherent_interrupts
++;
5220 /* restart DMA engine */
5222 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
);
5224 tmp
&= ~(RT2860_REG_TX_WB_DDONE
|
5225 RT2860_REG_RX_DMA_ENABLE
|
5226 RT2860_REG_TX_DMA_ENABLE
);
5228 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
, tmp
);
5230 /* init Tx rings (4 EDCAs + HCCA + MGMT) */
5232 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
5233 rt2860_reset_tx_ring(sc
, &sc
->tx_ring
[i
]);
5235 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
5237 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_BASE_PTR(i
),
5238 sc
->tx_ring
[i
].desc_phys_addr
);
5239 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_MAX_CNT(i
),
5240 RT2860_SOFTC_TX_RING_DESC_COUNT
);
5241 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_CTX_IDX(i
), 0);
5246 rt2860_reset_rx_ring(sc
, &sc
->rx_ring
);
5248 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_BASE_PTR
,
5249 sc
->rx_ring
.desc_phys_addr
);
5250 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_MAX_CNT
,
5251 RT2860_SOFTC_RX_RING_DATA_COUNT
);
5252 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_CALC_IDX
,
5253 RT2860_SOFTC_RX_RING_DATA_COUNT
- 1);
5255 rt2860_txrx_enable(sc
);
5259 * rt2860_fifo_sta_full_intr
5261 static void rt2860_fifo_sta_full_intr(struct rt2860_softc
*sc
)
5263 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
5264 "%s: FIFO statistic full interrupt\n",
5265 device_get_nameunit(sc
->dev
));
5267 sc
->fifo_sta_full_interrupts
++;
5269 RT2860_SOFTC_LOCK(sc
);
5271 if (!(sc
->intr_disable_mask
& RT2860_REG_INT_FIFO_STA_FULL
))
5273 rt2860_intr_disable(sc
, RT2860_REG_INT_FIFO_STA_FULL
);
5275 taskqueue_enqueue(sc
->taskqueue
, &sc
->fifo_sta_full_task
);
5278 sc
->intr_pending_mask
|= RT2860_REG_INT_FIFO_STA_FULL
;
5280 RT2860_SOFTC_UNLOCK(sc
);
5286 static void rt2860_rx_intr(struct rt2860_softc
*sc
)
5288 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
5289 "%s: Rx interrupt\n",
5290 device_get_nameunit(sc
->dev
));
5292 sc
->rx_interrupts
++;
5294 RT2860_SOFTC_LOCK(sc
);
5296 if (!(sc
->intr_disable_mask
& RT2860_REG_INT_RX_DONE
))
5298 rt2860_intr_disable(sc
, RT2860_REG_INT_RX_DONE
);
5300 taskqueue_enqueue(sc
->taskqueue
, &sc
->rx_done_task
);
5303 sc
->intr_pending_mask
|= RT2860_REG_INT_RX_DONE
;
5305 RT2860_SOFTC_UNLOCK(sc
);
5309 * rt2860_rx_delay_intr
5311 static void rt2860_rx_delay_intr(struct rt2860_softc
*sc
)
5313 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
5314 "%s: Rx delay interrupt\n",
5315 device_get_nameunit(sc
->dev
));
5317 sc
->rx_delay_interrupts
++;
5323 static void rt2860_tx_intr(struct rt2860_softc
*sc
, int qid
)
5325 KASSERT(qid
>= 0 && qid
< RT2860_SOFTC_TX_RING_COUNT
,
5326 ("%s: Tx interrupt: invalid qid=%d\n",
5327 device_get_nameunit(sc
->dev
), qid
));
5329 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
5330 "%s: Tx interrupt: qid=%d\n",
5331 device_get_nameunit(sc
->dev
), qid
);
5333 sc
->tx_interrupts
[qid
]++;
5335 RT2860_SOFTC_LOCK(sc
);
5337 if (!(sc
->intr_disable_mask
& (RT2860_REG_INT_TX_AC0_DONE
<< qid
)))
5339 rt2860_intr_disable(sc
, (RT2860_REG_INT_TX_AC0_DONE
<< qid
));
5341 taskqueue_enqueue(sc
->taskqueue
, &sc
->tx_done_task
);
5344 sc
->intr_pending_mask
|= (RT2860_REG_INT_TX_AC0_DONE
<< qid
);
5346 RT2860_SOFTC_UNLOCK(sc
);
5350 * rt2860_tx_delay_intr
5352 static void rt2860_tx_delay_intr(struct rt2860_softc
*sc
)
5354 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
5355 "%s: Tx delay interrupt\n",
5356 device_get_nameunit(sc
->dev
));
5358 sc
->tx_delay_interrupts
++;
5362 * rt2860_pre_tbtt_intr
5364 static void rt2860_pre_tbtt_intr(struct rt2860_softc
*sc
)
5366 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
5367 "%s: Pre-TBTT interrupt\n",
5368 device_get_nameunit(sc
->dev
));
5370 sc
->pre_tbtt_interrupts
++;
5376 static void rt2860_tbtt_intr(struct rt2860_softc
*sc
)
5378 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
5379 "%s: TBTT interrupt\n",
5380 device_get_nameunit(sc
->dev
));
5382 sc
->tbtt_interrupts
++;
5386 * rt2860_mcu_cmd_intr
5388 static void rt2860_mcu_cmd_intr(struct rt2860_softc
*sc
)
5390 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
5391 "%s: MCU command interrupt\n",
5392 device_get_nameunit(sc
->dev
));
5394 sc
->mcu_cmd_interrupts
++;
5398 * rt2860_auto_wakeup_intr
5400 static void rt2860_auto_wakeup_intr(struct rt2860_softc
*sc
)
5402 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
5403 "%s: auto wakeup interrupt\n",
5404 device_get_nameunit(sc
->dev
));
5406 sc
->auto_wakeup_interrupts
++;
5410 * rt2860_gp_timer_intr
5412 static void rt2860_gp_timer_intr(struct rt2860_softc
*sc
)
5414 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
5415 "%s: GP timer interrupt\n",
5416 device_get_nameunit(sc
->dev
));
5418 sc
->gp_timer_interrupts
++;
5422 * rt2860_rx_done_task
5424 static void rt2860_rx_done_task(void *context
, int pending
)
5426 struct rt2860_softc
*sc
;
5433 RT2860_DPRINTF(sc
, RT2860_DEBUG_RX
,
5434 "%s: Rx done task\n",
5435 device_get_nameunit(sc
->dev
));
5437 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
5440 sc
->intr_pending_mask
&= ~RT2860_REG_INT_RX_DONE
;
5442 again
= rt2860_rx_eof(sc
, sc
->rx_process_limit
);
5444 RT2860_SOFTC_LOCK(sc
);
5446 if ((sc
->intr_pending_mask
& RT2860_REG_INT_RX_DONE
) || again
)
5448 RT2860_DPRINTF(sc
, RT2860_DEBUG_RX
,
5449 "%s: Rx done task: scheduling again\n",
5450 device_get_nameunit(sc
->dev
));
5452 taskqueue_enqueue(sc
->taskqueue
, &sc
->rx_done_task
);
5456 rt2860_intr_enable(sc
, RT2860_REG_INT_RX_DONE
);
5459 RT2860_SOFTC_UNLOCK(sc
);
5463 * rt2860_tx_done_task
5465 static void rt2860_tx_done_task(void *context
, int pending
)
5467 struct rt2860_softc
*sc
;
5475 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
5476 "%s: Tx done task\n",
5477 device_get_nameunit(sc
->dev
));
5479 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
5482 for (i
= RT2860_SOFTC_TX_RING_COUNT
- 1; i
>= 0; i
--)
5484 if (sc
->intr_pending_mask
& (RT2860_REG_INT_TX_AC0_DONE
<< i
))
5486 sc
->intr_pending_mask
&= ~(RT2860_REG_INT_TX_AC0_DONE
<< i
);
5488 rt2860_tx_eof(sc
, &sc
->tx_ring
[i
]);
5494 ifp
->if_drv_flags
&= ~IFF_DRV_OACTIVE
;
5496 intr_mask
= (RT2860_REG_INT_TX_MGMT_DONE
|
5497 RT2860_REG_INT_TX_HCCA_DONE
|
5498 RT2860_REG_INT_TX_AC3_DONE
|
5499 RT2860_REG_INT_TX_AC2_DONE
|
5500 RT2860_REG_INT_TX_AC1_DONE
|
5501 RT2860_REG_INT_TX_AC0_DONE
);
5503 RT2860_SOFTC_LOCK(sc
);
5505 rt2860_intr_enable(sc
, ~sc
->intr_pending_mask
&
5506 (sc
->intr_disable_mask
& intr_mask
));
5508 if (sc
->intr_pending_mask
& intr_mask
)
5510 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
5511 "%s: Tx done task: scheduling again\n",
5512 device_get_nameunit(sc
->dev
));
5514 taskqueue_enqueue(sc
->taskqueue
, &sc
->tx_done_task
);
5517 RT2860_SOFTC_UNLOCK(sc
);
5519 if (!IFQ_IS_EMPTY(&ifp
->if_snd
))
5524 * rt2860_fifo_sta_full_task
5526 static void rt2860_fifo_sta_full_task(void *context
, int pending
)
5528 struct rt2860_softc
*sc
;
5534 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATS
,
5535 "%s: FIFO statistic full task\n",
5536 device_get_nameunit(sc
->dev
));
5538 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
5541 sc
->intr_pending_mask
&= ~RT2860_REG_INT_FIFO_STA_FULL
;
5543 rt2860_drain_fifo_stats(sc
);
5545 RT2860_SOFTC_LOCK(sc
);
5547 if (sc
->intr_pending_mask
& RT2860_REG_INT_FIFO_STA_FULL
)
5549 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATS
,
5550 "%s: FIFO statistic full task: scheduling again\n",
5551 device_get_nameunit(sc
->dev
));
5553 taskqueue_enqueue(sc
->taskqueue
, &sc
->fifo_sta_full_task
);
5557 rt2860_intr_enable(sc
, RT2860_REG_INT_FIFO_STA_FULL
);
5560 RT2860_SOFTC_UNLOCK(sc
);
5562 if (!IFQ_IS_EMPTY(&ifp
->if_snd
))
5567 * rt2860_periodic_task
5569 static void rt2860_periodic_task(void *context
, int pending
)
5571 struct rt2860_softc
*sc
;
5573 struct ieee80211com
*ic
;
5574 struct ieee80211vap
*vap
;
5579 vap
= TAILQ_FIRST(&ic
->ic_vaps
);
5581 RT2860_DPRINTF(sc
, RT2860_DEBUG_PERIODIC
,
5582 "%s: periodic task: round=%lu\n",
5583 device_get_nameunit(sc
->dev
), sc
->periodic_round
);
5585 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
5588 RT2860_SOFTC_LOCK(sc
);
5590 sc
->periodic_round
++;
5592 rt2860_update_stats(sc
);
5594 if ((sc
->periodic_round
% 10) == 0)
5596 rt2860_bbp_tuning(sc
);
5598 rt2860_update_raw_counters(sc
);
5600 rt2860_watchdog(sc
);
5602 if (vap
!= NULL
&& vap
->iv_opmode
!= IEEE80211_M_MONITOR
&& vap
->iv_state
== IEEE80211_S_RUN
)
5604 if (vap
->iv_opmode
== IEEE80211_M_STA
)
5605 rt2860_amrr_update_iter_func(vap
, vap
->iv_bss
);
5607 ieee80211_iterate_nodes(&ic
->ic_sta
, rt2860_amrr_update_iter_func
, vap
);
5611 RT2860_SOFTC_UNLOCK(sc
);
5613 callout_reset(&sc
->periodic_ch
, hz
/ 10, rt2860_periodic
, sc
);
5619 static int rt2860_rx_eof(struct rt2860_softc
*sc
, int limit
)
5622 struct ieee80211com
*ic
;
5623 struct ieee80211_frame
*wh
;
5624 struct ieee80211_node
*ni
;
5625 struct rt2860_softc_node
*rni
;
5626 struct rt2860_softc_rx_radiotap_header
*tap
;
5627 struct rt2860_softc_rx_ring
*ring
;
5628 struct rt2860_rxdesc
*desc
;
5629 struct rt2860_softc_rx_data
*data
;
5630 struct rt2860_rxwi
*rxwi
;
5631 struct mbuf
*m
, *mnew
;
5632 bus_dma_segment_t segs
[1];
5633 bus_dmamap_t dma_map
;
5634 uint32_t index
, desc_flags
;
5635 uint8_t cipher_err
, rssi
, ant
, phymode
, bw
, shortgi
, stbc
, mcs
, keyidx
, tid
, frag
;
5638 int error
, nsegs
, len
, ampdu
, amsdu
, rssi_dbm_rel
, nframes
, i
;
5642 ring
= &sc
->rx_ring
;
5648 index
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_RX_DRX_IDX
);
5649 if (ring
->cur
== index
)
5652 desc
= &ring
->desc
[ring
->cur
];
5653 data
= &ring
->data
[ring
->cur
];
5655 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
5656 BUS_DMASYNC_POSTREAD
| BUS_DMASYNC_POSTWRITE
);
5658 if (!(desc
->sdl0
& htole16(RT2860_RXDESC_SDL0_DDONE
)))
5663 mnew
= m_getjcl(M_DONTWAIT
, MT_DATA
, M_PKTHDR
, MJUMPAGESIZE
);
5666 sc
->rx_mbuf_alloc_errors
++;
5671 mnew
->m_len
= mnew
->m_pkthdr
.len
= MJUMPAGESIZE
;
5673 error
= bus_dmamap_load_mbuf_sg(ring
->data_dma_tag
, ring
->spare_dma_map
,
5674 mnew
, segs
, &nsegs
, BUS_DMA_NOWAIT
);
5677 RT2860_DPRINTF(sc
, RT2860_DEBUG_RX
,
5678 "%s: could not load Rx mbuf DMA map: error=%d, nsegs=%d\n",
5679 device_get_nameunit(sc
->dev
), error
, nsegs
);
5683 sc
->rx_mbuf_dmamap_errors
++;
5689 KASSERT(nsegs
== 1, ("%s: too many DMA segments",
5690 device_get_nameunit(sc
->dev
)));
5692 bus_dmamap_sync(ring
->data_dma_tag
, data
->dma_map
,
5693 BUS_DMASYNC_POSTREAD
);
5694 bus_dmamap_unload(ring
->data_dma_tag
, data
->dma_map
);
5696 dma_map
= data
->dma_map
;
5697 data
->dma_map
= ring
->spare_dma_map
;
5698 ring
->spare_dma_map
= dma_map
;
5700 bus_dmamap_sync(ring
->data_dma_tag
, data
->dma_map
,
5701 BUS_DMASYNC_PREREAD
);
5706 desc
->sdp0
= htole32(segs
[0].ds_addr
);
5708 desc_flags
= le32toh(desc
->flags
);
5710 RT2860_DPRINTF(sc
, RT2860_DEBUG_RX
,
5711 "%s: Rx frame: rxdesc flags=0x%08x\n",
5712 device_get_nameunit(sc
->dev
), desc_flags
);
5714 /* get Rx wireless info */
5716 rxwi
= mtod(m
, struct rt2860_rxwi
*);
5717 len
= (le16toh(rxwi
->tid_size
) >> RT2860_RXWI_SIZE_SHIFT
) &
5718 RT2860_RXWI_SIZE_MASK
;
5720 /* check for L2 padding between IEEE 802.11 frame header and body */
5722 if (desc_flags
& RT2860_RXDESC_FLAGS_L2PAD
)
5724 RT2860_DPRINTF(sc
, RT2860_DEBUG_RX
,
5725 "%s: L2 padding: len=%d\n",
5726 device_get_nameunit(sc
->dev
), len
);
5731 m
->m_pkthdr
.rcvif
= ifp
;
5732 m
->m_data
= (caddr_t
) (rxwi
+ 1);
5733 m
->m_pkthdr
.len
= m
->m_len
= len
;
5735 /* check for crc errors */
5737 if (desc_flags
& RT2860_RXDESC_FLAGS_CRC_ERR
)
5739 RT2860_DPRINTF(sc
, RT2860_DEBUG_RX
,
5740 "%s: rxdesc: crc error\n",
5741 device_get_nameunit(sc
->dev
));
5745 if (!(ifp
->if_flags
& IFF_PROMISC
))
5752 wh
= (struct ieee80211_frame
*) (rxwi
+ 1);
5754 /* check for cipher errors */
5756 if (desc_flags
& RT2860_RXDESC_FLAGS_DECRYPTED
)
5758 cipher_err
= ((desc_flags
>> RT2860_RXDESC_FLAGS_CIPHER_ERR_SHIFT
) &
5759 RT2860_RXDESC_FLAGS_CIPHER_ERR_MASK
);
5760 if (cipher_err
== RT2860_RXDESC_FLAGS_CIPHER_ERR_NONE
)
5762 if (wh
->i_fc
[1] & IEEE80211_FC1_WEP
)
5763 wh
->i_fc
[1] &= ~IEEE80211_FC1_WEP
;
5765 m
->m_flags
|= M_WEP
;
5767 sc
->rx_cipher_no_errors
++;
5771 RT2860_DPRINTF(sc
, RT2860_DEBUG_RX
,
5772 "%s: rxdesc: cipher error=0x%02x\n",
5773 device_get_nameunit(sc
->dev
), cipher_err
);
5775 if (cipher_err
== RT2860_RXDESC_FLAGS_CIPHER_ERR_ICV
)
5776 sc
->rx_cipher_icv_errors
++;
5777 else if (cipher_err
== RT2860_RXDESC_FLAGS_CIPHER_ERR_MIC
)
5778 sc
->rx_cipher_mic_errors
++;
5779 else if (cipher_err
== RT2860_RXDESC_FLAGS_CIPHER_ERR_INVALID_KEY
)
5780 sc
->rx_cipher_invalid_key_errors
++;
5782 if ((cipher_err
== RT2860_RXDESC_FLAGS_CIPHER_ERR_MIC
) &&
5783 (desc_flags
& RT2860_RXDESC_FLAGS_MYBSS
))
5785 ni
= ieee80211_find_rxnode(ic
, (const struct ieee80211_frame_min
*) wh
);
5788 keyidx
= (rxwi
->udf_bssidx_keyidx
>> RT2860_RXWI_KEYIDX_SHIFT
) &
5789 RT2860_RXWI_KEYIDX_MASK
;
5791 ieee80211_notify_michael_failure(ni
->ni_vap
, wh
, keyidx
);
5793 ieee80211_free_node(ni
);
5799 if (!(ifp
->if_flags
& IFF_PROMISC
))
5808 if (wh
->i_fc
[1] & IEEE80211_FC1_WEP
)
5810 RT2860_DPRINTF(sc
, RT2860_DEBUG_RX
,
5811 "%s: rxdesc: not decrypted but protected flag set\n",
5812 device_get_nameunit(sc
->dev
));
5816 if (!(ifp
->if_flags
& IFF_PROMISC
))
5824 /* check for A-MPDU */
5826 if (desc_flags
& RT2860_RXDESC_FLAGS_BA
)
5828 m
->m_flags
|= M_AMPDU
;
5832 if (wh
->i_fc
[1] & IEEE80211_FC1_RETRY
)
5833 sc
->rx_ampdu_retries
++;
5842 /* check for A-MSDU */
5844 if (desc_flags
& RT2860_RXDESC_FLAGS_AMSDU
)
5855 ant
= rt2860_maxrssi_rxpath(sc
, rxwi
);
5856 rssi
= rxwi
->rssi
[ant
];
5857 rssi_dbm
= rt2860_rssi2dbm(sc
, rssi
, ant
);
5858 phymode
= ((rxwi
->phymode_stbc_shortgi
>> RT2860_RXWI_PHYMODE_SHIFT
) &
5859 RT2860_RXWI_PHYMODE_MASK
);
5860 bw
= ((rxwi
->bw_mcs
>> RT2860_RXWI_BW_SHIFT
) & RT2860_RXWI_BW_MASK
);
5861 shortgi
= ((rxwi
->phymode_stbc_shortgi
>> RT2860_RXWI_SHORTGI_SHIFT
) &
5862 RT2860_RXWI_SHORTGI_MASK
);
5863 stbc
= ((rxwi
->phymode_stbc_shortgi
>> RT2860_RXWI_STBC_SHIFT
) &
5864 RT2860_RXWI_STBC_MASK
);
5865 mcs
= ((rxwi
->bw_mcs
>> RT2860_RXWI_MCS_SHIFT
) & RT2860_RXWI_MCS_MASK
);
5866 tid
= ((rxwi
->tid_size
>> RT2860_RXWI_TID_SHIFT
) & RT2860_RXWI_TID_MASK
);
5867 seq
= ((rxwi
->seq_frag
>> RT2860_RXWI_SEQ_SHIFT
) & RT2860_RXWI_SEQ_MASK
);
5868 frag
= ((rxwi
->seq_frag
>> RT2860_RXWI_FRAG_SHIFT
) & RT2860_RXWI_FRAG_MASK
);
5870 if (ieee80211_radiotap_active(ic
))
5874 tap
->flags
= (desc_flags
& RT2860_RXDESC_FLAGS_L2PAD
) ? IEEE80211_RADIOTAP_F_DATAPAD
: 0;
5875 tap
->dbm_antsignal
= rssi_dbm
;
5876 tap
->dbm_antnoise
= RT2860_NOISE_FLOOR
;
5878 tap
->antsignal
= rssi
;
5879 tap
->chan_flags
= htole32(ic
->ic_curchan
->ic_flags
);
5880 tap
->chan_freq
= htole16(ic
->ic_curchan
->ic_freq
);
5881 tap
->chan_ieee
= ic
->ic_curchan
->ic_ieee
;
5882 tap
->chan_maxpow
= 0;
5884 if (phymode
== RT2860_TXWI_PHYMODE_HT_MIXED
|| phymode
== RT2860_TXWI_PHYMODE_HT_GF
)
5885 tap
->rate
= mcs
| IEEE80211_RATE_MCS
;
5887 tap
->rate
= rt2860_rxrate(rxwi
);
5889 if (desc_flags
& RT2860_RXDESC_FLAGS_CRC_ERR
)
5890 tap
->flags
|= IEEE80211_RADIOTAP_F_BADFCS
;
5892 if (desc_flags
& RT2860_RXDESC_FLAGS_FRAG
)
5893 tap
->flags
|= IEEE80211_RADIOTAP_F_FRAG
;
5895 if (rxwi
->bw_mcs
& RT2860_RXWI_MCS_SHOTPRE
)
5896 tap
->flags
|= IEEE80211_RADIOTAP_F_SHORTPRE
;
5898 if ((desc_flags
& RT2860_RXDESC_FLAGS_DECRYPTED
) ||
5899 (wh
->i_fc
[1] & IEEE80211_FC1_WEP
))
5900 tap
->flags
|= IEEE80211_RADIOTAP_F_WEP
;
5903 tap
->flags
|= IEEE80211_RADIOTAP_F_SHORTGI
;
5905 /* XXX use temporarily radiotap CFP flag as A-MPDU flag */
5908 tap
->flags
|= IEEE80211_RADIOTAP_F_CFP
;
5912 * net80211 assumes that RSSI data are in the range [-127..127] and
5913 * in .5 dBm units relative to the current noise floor
5916 rssi_dbm_rel
= (rssi_dbm
- RT2860_NOISE_FLOOR
) * 2;
5917 if (rssi_dbm_rel
> 127)
5920 RT2860_DPRINTF(sc
, RT2860_DEBUG_RX
,
5921 "%s: received frame: len=%d, phymode=%d, bw=%d, shortgi=%d, stbc=0x%02x, mcs=%d, "
5922 "ant=%d, rssi=%d/%d/%d, snr=%d/%d, wcid=0x%02x, ampdu=%d, amsdu=%d, tid=%d, seq=%d, frag=%d, "
5923 "retry=%d, rssi_dbm=%d, rssi_dbm_rel=%d\n",
5924 device_get_nameunit(sc
->dev
),
5925 len
, phymode
, bw
, shortgi
, stbc
, mcs
,
5926 ant
, rxwi
->rssi
[0], rxwi
->rssi
[1], rxwi
->rssi
[2],
5927 rxwi
->snr
[0], rxwi
->snr
[1],
5928 rxwi
->wcid
, ampdu
, amsdu
, tid
, seq
, frag
, (wh
->i_fc
[1] & IEEE80211_FC1_RETRY
) ? 1 : 0,
5929 rssi_dbm
, rssi_dbm_rel
);
5931 ni
= ieee80211_find_rxnode(ic
, (struct ieee80211_frame_min
*) wh
);
5934 rni
= (struct rt2860_softc_node
*) ni
;
5936 for (i
= 0; i
< RT2860_SOFTC_RSSI_COUNT
; i
++)
5938 rni
->last_rssi
[i
] = rxwi
->rssi
[i
];
5939 rni
->last_rssi_dbm
[i
] = rt2860_rssi2dbm(sc
, rxwi
->rssi
[i
], i
);
5942 ieee80211_input(ni
, m
, rssi_dbm_rel
, RT2860_NOISE_FLOOR
);
5943 ieee80211_free_node(ni
);
5947 ieee80211_input_all(ic
, m
, rssi_dbm_rel
, RT2860_NOISE_FLOOR
);
5952 desc
->sdl0
&= ~htole16(RT2860_RXDESC_SDL0_DDONE
);
5954 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
5955 BUS_DMASYNC_PREREAD
| BUS_DMASYNC_PREWRITE
);
5957 ring
->cur
= (ring
->cur
+ 1) % RT2860_SOFTC_RX_RING_DATA_COUNT
;
5963 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_CALC_IDX
,
5964 RT2860_SOFTC_RX_RING_DATA_COUNT
- 1);
5966 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_CALC_IDX
,
5969 RT2860_DPRINTF(sc
, RT2860_DEBUG_RX
,
5970 "%s: Rx eof: nframes=%d\n",
5971 device_get_nameunit(sc
->dev
), nframes
);
5973 sc
->rx_packets
+= nframes
;
5975 return (limit
== 0);
5981 static void rt2860_tx_eof(struct rt2860_softc
*sc
,
5982 struct rt2860_softc_tx_ring
*ring
)
5985 struct rt2860_txdesc
*desc
;
5986 struct rt2860_softc_tx_data
*data
;
5988 int ndescs
, nframes
;
5997 index
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_TX_DTX_IDX(ring
->qid
));
5998 if (ring
->desc_next
== index
)
6003 rt2860_drain_fifo_stats(sc
);
6005 desc
= &ring
->desc
[ring
->desc_next
];
6007 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
6008 BUS_DMASYNC_POSTREAD
| BUS_DMASYNC_POSTWRITE
);
6010 if (desc
->sdl0
& htole16(RT2860_TXDESC_SDL0_LASTSEG
) ||
6011 desc
->sdl1
& htole16(RT2860_TXDESC_SDL1_LASTSEG
))
6015 data
= &ring
->data
[ring
->data_next
];
6017 if (data
->m
->m_flags
& M_TXCB
)
6018 ieee80211_process_callback(data
->ni
, data
->m
, 0);
6020 bus_dmamap_sync(ring
->data_dma_tag
, data
->dma_map
,
6021 BUS_DMASYNC_POSTWRITE
);
6022 bus_dmamap_unload(ring
->data_dma_tag
, data
->dma_map
);
6026 ieee80211_free_node(data
->ni
);
6033 RT2860_SOFTC_TX_RING_LOCK(ring
);
6035 ring
->data_queued
--;
6036 ring
->data_next
= (ring
->data_next
+ 1) % RT2860_SOFTC_TX_RING_DATA_COUNT
;
6038 RT2860_SOFTC_TX_RING_UNLOCK(ring
);
6041 desc
->sdl0
&= ~htole16(RT2860_TXDESC_SDL0_DDONE
);
6043 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
6044 BUS_DMASYNC_PREREAD
| BUS_DMASYNC_PREWRITE
);
6046 RT2860_SOFTC_TX_RING_LOCK(ring
);
6048 ring
->desc_queued
--;
6049 ring
->desc_next
= (ring
->desc_next
+ 1) % RT2860_SOFTC_TX_RING_DESC_COUNT
;
6051 RT2860_SOFTC_TX_RING_UNLOCK(ring
);
6054 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
6055 "%s: Tx eof: qid=%d, ndescs=%d, nframes=%d\n",
6056 device_get_nameunit(sc
->dev
), ring
->qid
, ndescs
, nframes
);
6060 * rt2860_update_stats
6062 static void rt2860_update_stats(struct rt2860_softc
*sc
)
6065 struct ieee80211com
*ic
;
6067 int beacons
, noretryok
, retryok
, failed
, underflows
, zerolen
;
6072 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATS
,
6073 "%s: update statistic\n",
6074 device_get_nameunit(sc
->dev
));
6076 rt2860_drain_fifo_stats(sc
);
6078 /* read and clear Tx statistic registers */
6080 rt2860_io_mac_read_multi(sc
, RT2860_REG_TX_STA_CNT0
,
6081 stacnt
, sizeof(stacnt
));
6083 stacnt
[0] = le32toh(stacnt
[0]);
6084 stacnt
[1] = le32toh(stacnt
[1]);
6085 stacnt
[2] = le32toh(stacnt
[2]);
6087 beacons
= stacnt
[0] >> 16;
6088 noretryok
= stacnt
[1] & 0xffff;
6089 retryok
= stacnt
[1] >> 16;
6090 failed
= stacnt
[0] & 0xffff;
6091 underflows
= stacnt
[2] >> 16;
6092 zerolen
= stacnt
[2] & 0xffff;
6094 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATS
,
6095 "%s: update statistic: beacons=%d, noretryok=%d, retryok=%d, failed=%d, underflows=%d, zerolen=%d\n",
6096 device_get_nameunit(sc
->dev
),
6097 beacons
, noretryok
, retryok
, failed
, underflows
, zerolen
);
6099 ifp
->if_oerrors
+= failed
;
6101 sc
->tx_beacons
+= beacons
;
6102 sc
->tx_noretryok
+= noretryok
;
6103 sc
->tx_retryok
+= retryok
;
6104 sc
->tx_failed
+= failed
;
6105 sc
->tx_underflows
+= underflows
;
6106 sc
->tx_zerolen
+= zerolen
;
6112 static void rt2860_bbp_tuning(struct rt2860_softc
*sc
)
6115 struct ieee80211com
*ic
;
6116 struct ieee80211vap
*vap
;
6117 struct ieee80211_node
*ni
;
6119 int8_t rssi
, old
, new;
6121 /* RT2860C does not support BBP tuning */
6123 if (sc
->mac_rev
== 0x28600100)
6128 vap
= TAILQ_FIRST(&ic
->ic_vaps
);
6130 if ((ic
->ic_flags
& IEEE80211_F_SCAN
) || vap
== NULL
||
6131 vap
->iv_opmode
!= IEEE80211_M_STA
|| vap
->iv_state
!= IEEE80211_S_RUN
)
6136 chan
= ieee80211_chan2ieee(ic
, ni
->ni_chan
);
6140 else if (chan
<= 64)
6142 else if (chan
<= 128)
6147 rssi
= ieee80211_getrssi(vap
);
6149 if (IEEE80211_IS_CHAN_2GHZ(ni
->ni_chan
))
6151 new = 0x2e + sc
->lna_gain
[group
];
6155 if (!IEEE80211_IS_CHAN_HT40(ni
->ni_chan
))
6156 new = 0x32 + sc
->lna_gain
[group
] * 5 / 3;
6158 new = 0x3a + sc
->lna_gain
[group
] * 5 / 3;
6161 /* Tune if absolute average RSSI is greater than -80 */
6166 old
= rt2860_io_bbp_read(sc
, 66);
6169 rt2860_io_bbp_write(sc
, 66, new);
6175 static void rt2860_watchdog(struct rt2860_softc
*sc
)
6180 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_PBF_TXRXQ_PCNT
);
6182 RT2860_DPRINTF(sc
, RT2860_DEBUG_WATCHDOG
,
6183 "%s: watchdog: TXRXQ_PCNT=0x%08x\n",
6184 device_get_nameunit(sc
->dev
), tmp
);
6186 if (((tmp
>> RT2860_REG_TX0Q_PCNT_SHIFT
) & RT2860_REG_TX0Q_PCNT_MASK
) != 0)
6188 sc
->tx_queue_not_empty
[0]++;
6190 rt2860_io_mac_write(sc
, RT2860_REG_PBF_CFG
, 0xf40012);
6192 for (ntries
= 0; ntries
< 10; ntries
++)
6194 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_PBF_TXRXQ_PCNT
);
6195 if (((tmp
>> RT2860_REG_TX0Q_PCNT_SHIFT
) & RT2860_REG_TX0Q_PCNT_MASK
) == 0)
6201 rt2860_io_mac_write(sc
, RT2860_REG_PBF_CFG
, 0xf40006);
6204 if (((tmp
>> RT2860_REG_TX1Q_PCNT_SHIFT
) & RT2860_REG_TX1Q_PCNT_MASK
) != 0)
6206 sc
->tx_queue_not_empty
[1]++;
6208 rt2860_io_mac_write(sc
, RT2860_REG_PBF_CFG
, 0xf4000a);
6210 for (ntries
= 0; ntries
< 10; ntries
++)
6212 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_PBF_TXRXQ_PCNT
);
6213 if (((tmp
>> RT2860_REG_TX1Q_PCNT_SHIFT
) & RT2860_REG_TX1Q_PCNT_MASK
) == 0)
6219 rt2860_io_mac_write(sc
, RT2860_REG_PBF_CFG
, 0xf40006);
6224 * rt2860_drain_fifo_stats
6226 static void rt2860_drain_fifo_stats(struct rt2860_softc
*sc
)
6230 uint8_t wcid
, mcs
, pid
;
6231 int ok
, agg
, retrycnt
;
6235 /* drain Tx status FIFO (maxsize = 16) */
6237 while ((stats
= rt2860_io_mac_read(sc
, RT2860_REG_TX_STA_FIFO
)) &
6238 RT2860_REG_TX_STA_FIFO_VALID
)
6240 wcid
= (stats
>> RT2860_REG_TX_STA_FIFO_WCID_SHIFT
) &
6241 RT2860_REG_TX_STA_FIFO_WCID_MASK
;
6243 /* if no ACK was requested, no feedback is available */
6245 if (!(stats
& RT2860_REG_TX_STA_FIFO_ACK_REQ
) || wcid
== RT2860_WCID_RESERVED
)
6248 /* update AMRR statistic */
6250 ok
= (stats
& RT2860_REG_TX_STA_FIFO_TX_OK
) ? 1 : 0;
6251 agg
= (stats
& RT2860_REG_TX_STA_FIFO_AGG
) ? 1 : 0;
6252 mcs
= (stats
>> RT2860_REG_TX_STA_FIFO_MCS_SHIFT
) &
6253 RT2860_REG_TX_STA_FIFO_MCS_MASK
;
6254 pid
= (stats
>> RT2860_REG_TX_STA_FIFO_PID_SHIFT
) &
6255 RT2860_REG_TX_STA_FIFO_PID_MASK
;
6256 retrycnt
= (mcs
< 0xf) ? (pid
- mcs
- 1) : 0;
6258 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATS
,
6259 "%s: FIFO statistic: wcid=0x%02x, ok=%d, agg=%d, mcs=0x%02x, pid=0x%02x, retrycnt=%d\n",
6260 device_get_nameunit(sc
->dev
),
6261 wcid
, ok
, agg
, mcs
, pid
, retrycnt
);
6263 rt2860_amrr_tx_complete(&sc
->amrr_node
[wcid
], ok
, retrycnt
);
6271 * rt2860_update_raw_counters
6273 static void rt2860_update_raw_counters(struct rt2860_softc
*sc
)
6277 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_AGG_CNT
);
6279 sc
->tx_nonagg
+= tmp
& 0xffff;
6280 sc
->tx_agg
+= tmp
>> 16;
6282 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_AGG_CNT0
);
6284 sc
->tx_ampdu
+= (tmp
& 0xffff) / 1 + (tmp
>> 16) / 2;
6286 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_AGG_CNT1
);
6288 sc
->tx_ampdu
+= (tmp
& 0xffff) / 3 + (tmp
>> 16) / 4;
6290 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_AGG_CNT2
);
6292 sc
->tx_ampdu
+= (tmp
& 0xffff) / 5 + (tmp
>> 16) / 6;
6294 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_AGG_CNT3
);
6296 sc
->tx_ampdu
+= (tmp
& 0xffff) / 7 + (tmp
>> 16) / 8;
6298 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_AGG_CNT4
);
6300 sc
->tx_ampdu
+= (tmp
& 0xffff) / 9 + (tmp
>> 16) / 10;
6302 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_AGG_CNT5
);
6304 sc
->tx_ampdu
+= (tmp
& 0xffff) / 11 + (tmp
>> 16) / 12;
6306 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_AGG_CNT6
);
6308 sc
->tx_ampdu
+= (tmp
& 0xffff) / 13 + (tmp
>> 16) / 14;
6310 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_AGG_CNT7
);
6312 sc
->tx_ampdu
+= (tmp
& 0xffff) / 15 + (tmp
>> 16) / 16;
6314 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_RX_STA_CNT0
);
6316 sc
->rx_crc_errors
+= tmp
& 0xffff;
6317 sc
->rx_phy_errors
+= tmp
>> 16;
6319 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_RX_STA_CNT1
);
6321 sc
->rx_false_ccas
+= tmp
& 0xffff;
6322 sc
->rx_plcp_errors
+= tmp
>> 16;
6324 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_RX_STA_CNT2
);
6326 sc
->rx_dup_packets
+= tmp
& 0xffff;
6327 sc
->rx_fifo_overflows
+= tmp
>> 16;
6329 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TXRX_MPDU_DEN_CNT
);
6331 sc
->tx_mpdu_zero_density
+= tmp
& 0xffff;
6332 sc
->rx_mpdu_zero_density
+= tmp
>> 16;
6336 * rt2860_intr_enable
6338 static void rt2860_intr_enable(struct rt2860_softc
*sc
, uint32_t intr_mask
)
6342 sc
->intr_disable_mask
&= ~intr_mask
;
6344 tmp
= sc
->intr_enable_mask
& ~sc
->intr_disable_mask
;
6346 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_INT_MASK
, tmp
);
6350 * rt2860_intr_disable
6352 static void rt2860_intr_disable(struct rt2860_softc
*sc
, uint32_t intr_mask
)
6356 sc
->intr_disable_mask
|= intr_mask
;
6358 tmp
= sc
->intr_enable_mask
& ~sc
->intr_disable_mask
;
6360 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_INT_MASK
, tmp
);
6364 * rt2860_txrx_enable
6366 static int rt2860_txrx_enable(struct rt2860_softc
*sc
)
6368 struct ieee80211com
*ic
;
6376 /* enable Tx/Rx DMA engine */
6378 rt2860_io_mac_write(sc
, RT2860_REG_SYS_CTRL
, RT2860_REG_TX_ENABLE
);
6380 for (ntries
= 0; ntries
< 200; ntries
++)
6382 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
);
6383 if (!(tmp
& (RT2860_REG_TX_DMA_BUSY
| RT2860_REG_RX_DMA_BUSY
)))
6391 printf("%s: timeout waiting for DMA engine\n",
6392 device_get_nameunit(sc
->dev
));
6398 tmp
|= RT2860_REG_TX_WB_DDONE
|
6399 RT2860_REG_RX_DMA_ENABLE
|
6400 RT2860_REG_TX_DMA_ENABLE
|
6401 (RT2860_REG_WPDMA_BT_SIZE64
<< RT2860_REG_WPDMA_BT_SIZE_SHIFT
);
6403 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
, tmp
);
6407 tmp
= RT2860_REG_RX_FILTER_DROP_CRC_ERR
|
6408 RT2860_REG_RX_FILTER_DROP_PHY_ERR
;
6410 if (ic
->ic_opmode
!= IEEE80211_M_MONITOR
)
6412 tmp
|= RT2860_REG_RX_FILTER_DROP_DUPL
|
6413 RT2860_REG_RX_FILTER_DROP_CTS
|
6414 RT2860_REG_RX_FILTER_DROP_BA
|
6415 RT2860_REG_RX_FILTER_DROP_ACK
|
6416 RT2860_REG_RX_FILTER_DROP_VER_ERR
|
6417 RT2860_REG_RX_FILTER_DROP_CTRL_RSV
|
6418 RT2860_REG_RX_FILTER_DROP_CFACK
|
6419 RT2860_REG_RX_FILTER_DROP_CFEND
;
6421 if (ic
->ic_opmode
== IEEE80211_M_STA
)
6422 tmp
|= RT2860_REG_RX_FILTER_DROP_RTS
|
6423 RT2860_REG_RX_FILTER_DROP_PSPOLL
;
6425 if (!(ifp
->if_flags
& IFF_PROMISC
))
6426 tmp
|= RT2860_REG_RX_FILTER_DROP_UC_NOME
;
6429 rt2860_io_mac_write(sc
, RT2860_REG_RX_FILTER_CFG
, tmp
);
6431 rt2860_io_mac_write(sc
, RT2860_REG_SYS_CTRL
,
6432 RT2860_REG_RX_ENABLE
| RT2860_REG_TX_ENABLE
);
6438 * rt2860_alloc_rx_ring
6440 static int rt2860_alloc_rx_ring(struct rt2860_softc
*sc
,
6441 struct rt2860_softc_rx_ring
*ring
)
6443 struct rt2860_rxdesc
*desc
;
6444 struct rt2860_softc_rx_data
*data
;
6445 bus_dma_segment_t segs
[1];
6446 int i
, nsegs
, error
;
6448 error
= bus_dma_tag_create(bus_get_dma_tag(sc
->dev
), PAGE_SIZE
, 0,
6449 BUS_SPACE_MAXADDR_32BIT
, BUS_SPACE_MAXADDR
, NULL
, NULL
,
6450 RT2860_SOFTC_RX_RING_DATA_COUNT
* sizeof(struct rt2860_rxdesc
), 1,
6451 RT2860_SOFTC_RX_RING_DATA_COUNT
* sizeof(struct rt2860_rxdesc
),
6452 0, NULL
, NULL
, &ring
->desc_dma_tag
);
6455 printf("%s: could not create Rx desc DMA tag\n",
6456 device_get_nameunit(sc
->dev
));
6460 error
= bus_dmamem_alloc(ring
->desc_dma_tag
, (void **) &ring
->desc
,
6461 BUS_DMA_NOWAIT
| BUS_DMA_ZERO
, &ring
->desc_dma_map
);
6464 printf("%s: could not allocate Rx desc DMA memory\n",
6465 device_get_nameunit(sc
->dev
));
6469 error
= bus_dmamap_load(ring
->desc_dma_tag
, ring
->desc_dma_map
,
6471 RT2860_SOFTC_RX_RING_DATA_COUNT
* sizeof(struct rt2860_rxdesc
),
6472 rt2860_dma_map_addr
, &ring
->desc_phys_addr
, 0);
6475 printf("%s: could not load Rx desc DMA map\n",
6476 device_get_nameunit(sc
->dev
));
6480 error
= bus_dma_tag_create(bus_get_dma_tag(sc
->dev
), PAGE_SIZE
, 0,
6481 BUS_SPACE_MAXADDR_32BIT
, BUS_SPACE_MAXADDR
, NULL
, NULL
,
6482 MJUMPAGESIZE
, 1, MJUMPAGESIZE
, 0, NULL
, NULL
,
6483 &ring
->data_dma_tag
);
6486 printf("%s: could not create Rx data DMA tag\n",
6487 device_get_nameunit(sc
->dev
));
6491 for (i
= 0; i
< RT2860_SOFTC_RX_RING_DATA_COUNT
; i
++)
6493 desc
= &ring
->desc
[i
];
6494 data
= &ring
->data
[i
];
6496 error
= bus_dmamap_create(ring
->data_dma_tag
, 0, &data
->dma_map
);
6499 printf("%s: could not create Rx data DMA map\n",
6500 device_get_nameunit(sc
->dev
));
6504 data
->m
= m_getjcl(M_DONTWAIT
, MT_DATA
, M_PKTHDR
, MJUMPAGESIZE
);
6505 if (data
->m
== NULL
)
6507 printf("%s: could not allocate Rx mbuf\n",
6508 device_get_nameunit(sc
->dev
));
6513 data
->m
->m_len
= data
->m
->m_pkthdr
.len
= MJUMPAGESIZE
;
6515 error
= bus_dmamap_load_mbuf_sg(ring
->data_dma_tag
, data
->dma_map
,
6516 data
->m
, segs
, &nsegs
, BUS_DMA_NOWAIT
);
6519 printf("%s: could not load Rx mbuf DMA map\n",
6520 device_get_nameunit(sc
->dev
));
6524 KASSERT(nsegs
== 1, ("%s: too many DMA segments",
6525 device_get_nameunit(sc
->dev
)));
6527 desc
->sdp0
= htole32(segs
[0].ds_addr
);
6528 desc
->sdl0
= htole16(MJUMPAGESIZE
);
6531 error
= bus_dmamap_create(ring
->data_dma_tag
, 0, &ring
->spare_dma_map
);
6534 printf("%s: could not create Rx spare DMA map\n",
6535 device_get_nameunit(sc
->dev
));
6539 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
6540 BUS_DMASYNC_PREREAD
| BUS_DMASYNC_PREWRITE
);
6546 rt2860_free_rx_ring(sc
, ring
);
6552 * rt2860_reset_rx_ring
6554 static void rt2860_reset_rx_ring(struct rt2860_softc
*sc
,
6555 struct rt2860_softc_rx_ring
*ring
)
6557 struct rt2860_rxdesc
*desc
;
6560 for (i
= 0; i
< RT2860_SOFTC_RX_RING_DATA_COUNT
; i
++)
6562 desc
= &ring
->desc
[i
];
6564 desc
->sdl0
&= ~htole16(RT2860_RXDESC_SDL0_DDONE
);
6567 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
6568 BUS_DMASYNC_PREREAD
| BUS_DMASYNC_PREWRITE
);
6574 * rt2860_free_rx_ring
6576 static void rt2860_free_rx_ring(struct rt2860_softc
*sc
,
6577 struct rt2860_softc_rx_ring
*ring
)
6579 struct rt2860_softc_rx_data
*data
;
6582 if (ring
->desc
!= NULL
)
6584 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
6585 BUS_DMASYNC_POSTWRITE
);
6586 bus_dmamap_unload(ring
->desc_dma_tag
, ring
->desc_dma_map
);
6587 bus_dmamem_free(ring
->desc_dma_tag
, ring
->desc
,
6588 ring
->desc_dma_map
);
6591 if (ring
->desc_dma_tag
!= NULL
)
6592 bus_dma_tag_destroy(ring
->desc_dma_tag
);
6594 for (i
= 0; i
< RT2860_SOFTC_RX_RING_DATA_COUNT
; i
++)
6596 data
= &ring
->data
[i
];
6598 if (data
->m
!= NULL
)
6600 bus_dmamap_sync(ring
->data_dma_tag
, data
->dma_map
,
6601 BUS_DMASYNC_POSTREAD
);
6602 bus_dmamap_unload(ring
->data_dma_tag
, data
->dma_map
);
6606 if (data
->dma_map
!= NULL
)
6607 bus_dmamap_destroy(ring
->data_dma_tag
, data
->dma_map
);
6610 if (ring
->spare_dma_map
!= NULL
)
6611 bus_dmamap_destroy(ring
->data_dma_tag
, ring
->spare_dma_map
);
6613 if (ring
->data_dma_tag
!= NULL
)
6614 bus_dma_tag_destroy(ring
->data_dma_tag
);
6618 * rt2860_alloc_tx_ring
6620 static int rt2860_alloc_tx_ring(struct rt2860_softc
*sc
,
6621 struct rt2860_softc_tx_ring
*ring
, int qid
)
6623 struct rt2860_softc_tx_data
*data
;
6626 mtx_init(&ring
->lock
, device_get_nameunit(sc
->dev
), NULL
, MTX_DEF
);
6628 error
= bus_dma_tag_create(bus_get_dma_tag(sc
->dev
), PAGE_SIZE
, 0,
6629 BUS_SPACE_MAXADDR_32BIT
, BUS_SPACE_MAXADDR
, NULL
, NULL
,
6630 RT2860_SOFTC_TX_RING_DESC_COUNT
* sizeof(struct rt2860_txdesc
), 1,
6631 RT2860_SOFTC_TX_RING_DESC_COUNT
* sizeof(struct rt2860_txdesc
),
6632 0, NULL
, NULL
, &ring
->desc_dma_tag
);
6635 printf("%s: could not create Tx desc DMA tag\n",
6636 device_get_nameunit(sc
->dev
));
6640 error
= bus_dmamem_alloc(ring
->desc_dma_tag
, (void **) &ring
->desc
,
6641 BUS_DMA_NOWAIT
| BUS_DMA_ZERO
, &ring
->desc_dma_map
);
6644 printf("%s: could not allocate Tx desc DMA memory\n",
6645 device_get_nameunit(sc
->dev
));
6649 error
= bus_dmamap_load(ring
->desc_dma_tag
, ring
->desc_dma_map
,
6651 RT2860_SOFTC_TX_RING_DESC_COUNT
* sizeof(struct rt2860_txdesc
),
6652 rt2860_dma_map_addr
, &ring
->desc_phys_addr
, 0);
6655 printf("%s: could not load Tx desc DMA map\n",
6656 device_get_nameunit(sc
->dev
));
6660 ring
->desc_queued
= 0;
6662 ring
->desc_next
= 0;
6664 error
= bus_dma_tag_create(bus_get_dma_tag(sc
->dev
), PAGE_SIZE
, 0,
6665 BUS_SPACE_MAXADDR_32BIT
, BUS_SPACE_MAXADDR
, NULL
, NULL
,
6666 RT2860_SOFTC_TX_RING_DATA_COUNT
* RT2860_TX_DATA_SEG0_SIZE
, 1,
6667 RT2860_SOFTC_TX_RING_DATA_COUNT
* RT2860_TX_DATA_SEG0_SIZE
,
6668 0, NULL
, NULL
, &ring
->seg0_dma_tag
);
6671 printf("%s: could not create Tx seg0 DMA tag\n",
6672 device_get_nameunit(sc
->dev
));
6676 error
= bus_dmamem_alloc(ring
->seg0_dma_tag
, (void **) &ring
->seg0
,
6677 BUS_DMA_NOWAIT
| BUS_DMA_ZERO
, &ring
->seg0_dma_map
);
6680 printf("%s: could not allocate Tx seg0 DMA memory\n",
6681 device_get_nameunit(sc
->dev
));
6685 error
= bus_dmamap_load(ring
->seg0_dma_tag
, ring
->seg0_dma_map
,
6687 RT2860_SOFTC_TX_RING_DATA_COUNT
* RT2860_TX_DATA_SEG0_SIZE
,
6688 rt2860_dma_map_addr
, &ring
->seg0_phys_addr
, 0);
6691 printf("%s: could not load Tx seg0 DMA map\n",
6692 device_get_nameunit(sc
->dev
));
6696 error
= bus_dma_tag_create(bus_get_dma_tag(sc
->dev
), PAGE_SIZE
, 0,
6697 BUS_SPACE_MAXADDR_32BIT
, BUS_SPACE_MAXADDR
, NULL
, NULL
,
6698 MJUMPAGESIZE
, RT2860_SOFTC_MAX_SCATTER
, MJUMPAGESIZE
, 0, NULL
, NULL
,
6699 &ring
->data_dma_tag
);
6702 printf("%s: could not create Tx data DMA tag\n",
6703 device_get_nameunit(sc
->dev
));
6707 for (i
= 0; i
< RT2860_SOFTC_TX_RING_DATA_COUNT
; i
++)
6709 data
= &ring
->data
[i
];
6711 error
= bus_dmamap_create(ring
->data_dma_tag
, 0, &data
->dma_map
);
6714 printf("%s: could not create Tx data DMA map\n",
6715 device_get_nameunit(sc
->dev
));
6720 ring
->data_queued
= 0;
6722 ring
->data_next
= 0;
6730 rt2860_free_tx_ring(sc
, ring
);
6736 * rt2860_reset_tx_ring
6738 static void rt2860_reset_tx_ring(struct rt2860_softc
*sc
,
6739 struct rt2860_softc_tx_ring
*ring
)
6741 struct rt2860_softc_tx_data
*data
;
6742 struct rt2860_txdesc
*desc
;
6745 for (i
= 0; i
< RT2860_SOFTC_TX_RING_DESC_COUNT
; i
++)
6747 desc
= &ring
->desc
[i
];
6753 ring
->desc_queued
= 0;
6755 ring
->desc_next
= 0;
6757 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
6758 BUS_DMASYNC_PREWRITE
);
6760 bus_dmamap_sync(ring
->seg0_dma_tag
, ring
->seg0_dma_map
,
6761 BUS_DMASYNC_PREWRITE
);
6763 for (i
= 0; i
< RT2860_SOFTC_TX_RING_DATA_COUNT
; i
++)
6765 data
= &ring
->data
[i
];
6767 if (data
->m
!= NULL
)
6769 bus_dmamap_sync(ring
->data_dma_tag
, data
->dma_map
,
6770 BUS_DMASYNC_POSTWRITE
);
6771 bus_dmamap_unload(ring
->data_dma_tag
, data
->dma_map
);
6776 if (data
->ni
!= NULL
)
6778 ieee80211_free_node(data
->ni
);
6783 ring
->data_queued
= 0;
6785 ring
->data_next
= 0;
6789 * rt2860_free_tx_ring
6791 static void rt2860_free_tx_ring(struct rt2860_softc
*sc
,
6792 struct rt2860_softc_tx_ring
*ring
)
6794 struct rt2860_softc_tx_data
*data
;
6797 if (ring
->desc
!= NULL
)
6799 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
6800 BUS_DMASYNC_POSTWRITE
);
6801 bus_dmamap_unload(ring
->desc_dma_tag
, ring
->desc_dma_map
);
6802 bus_dmamem_free(ring
->desc_dma_tag
, ring
->desc
,
6803 ring
->desc_dma_map
);
6806 if (ring
->desc_dma_tag
!= NULL
)
6807 bus_dma_tag_destroy(ring
->desc_dma_tag
);
6809 if (ring
->seg0
!= NULL
)
6811 bus_dmamap_sync(ring
->seg0_dma_tag
, ring
->seg0_dma_map
,
6812 BUS_DMASYNC_POSTWRITE
);
6813 bus_dmamap_unload(ring
->seg0_dma_tag
, ring
->seg0_dma_map
);
6814 bus_dmamem_free(ring
->seg0_dma_tag
, ring
->seg0
,
6815 ring
->seg0_dma_map
);
6818 if (ring
->seg0_dma_tag
!= NULL
)
6819 bus_dma_tag_destroy(ring
->seg0_dma_tag
);
6821 for (i
= 0; i
< RT2860_SOFTC_TX_RING_DATA_COUNT
; i
++)
6823 data
= &ring
->data
[i
];
6825 if (data
->m
!= NULL
)
6827 bus_dmamap_sync(ring
->data_dma_tag
, data
->dma_map
,
6828 BUS_DMASYNC_POSTWRITE
);
6829 bus_dmamap_unload(ring
->data_dma_tag
, data
->dma_map
);
6833 if (data
->ni
!= NULL
)
6834 ieee80211_free_node(data
->ni
);
6836 if (data
->dma_map
!= NULL
)
6837 bus_dmamap_destroy(ring
->data_dma_tag
, data
->dma_map
);
6840 if (ring
->data_dma_tag
!= NULL
)
6841 bus_dma_tag_destroy(ring
->data_dma_tag
);
6843 mtx_destroy(&ring
->lock
);
6847 * rt2860_dma_map_addr
6849 static void rt2860_dma_map_addr(void *arg
, bus_dma_segment_t
*segs
,
6850 int nseg
, int error
)
6855 KASSERT(nseg
== 1, ("too many DMA segments, %d should be 1", nseg
));
6857 *(bus_addr_t
*) arg
= segs
[0].ds_addr
;
6861 * rt2860_sysctl_attach
6863 static void rt2860_sysctl_attach(struct rt2860_softc
*sc
)
6865 struct sysctl_ctx_list
*ctx
;
6866 struct sysctl_oid
*tree
;
6867 struct sysctl_oid
*stats
;
6869 ctx
= device_get_sysctl_ctx(sc
->dev
);
6870 tree
= device_get_sysctl_tree(sc
->dev
);
6872 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(tree
), OID_AUTO
,
6873 "tx_stbc", CTLFLAG_RW
, &sc
->tx_stbc
, 0,
6876 /* statistic counters */
6878 stats
= SYSCTL_ADD_NODE(ctx
, SYSCTL_CHILDREN(tree
), OID_AUTO
,
6879 "stats", CTLFLAG_RD
, 0, "statistic");
6881 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6882 "interrupts", CTLFLAG_RD
, &sc
->interrupts
, 0,
6885 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6886 "tx_coherent_interrupts", CTLFLAG_RD
, &sc
->tx_coherent_interrupts
, 0,
6887 "Tx coherent interrupts");
6889 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6890 "rx_coherent_interrupts", CTLFLAG_RD
, &sc
->rx_coherent_interrupts
, 0,
6891 "Rx coherent interrupts");
6893 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6894 "txrx_coherent_interrupts", CTLFLAG_RD
, &sc
->txrx_coherent_interrupts
, 0,
6895 "Tx/Rx coherent interrupts");
6897 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6898 "fifo_sta_full_interrupts", CTLFLAG_RD
, &sc
->fifo_sta_full_interrupts
, 0,
6899 "FIFO statistic full interrupts");
6901 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6902 "rx_interrupts", CTLFLAG_RD
, &sc
->rx_interrupts
, 0,
6905 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6906 "rx_delay_interrupts", CTLFLAG_RD
, &sc
->rx_delay_interrupts
, 0,
6907 "Rx delay interrupts");
6909 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6910 "tx_mgmt_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[5], 0,
6911 "Tx MGMT interrupts");
6913 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6914 "tx_hcca_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[4], 0,
6915 "Tx HCCA interrupts");
6917 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6918 "tx_ac3_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[3], 0,
6919 "Tx AC3 interrupts");
6921 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6922 "tx_ac2_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[2], 0,
6923 "Tx AC2 interrupts");
6925 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6926 "tx_ac1_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[1], 0,
6927 "Tx AC1 interrupts");
6929 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6930 "tx_ac0_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[0], 0,
6931 "Tx AC0 interrupts");
6933 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6934 "tx_delay_interrupts", CTLFLAG_RD
, &sc
->tx_delay_interrupts
, 0,
6935 "Tx delay interrupts");
6937 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6938 "pre_tbtt_interrupts", CTLFLAG_RD
, &sc
->pre_tbtt_interrupts
, 0,
6939 "Pre-TBTT interrupts");
6941 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6942 "tbtt_interrupts", CTLFLAG_RD
, &sc
->tbtt_interrupts
, 0,
6945 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6946 "mcu_cmd_interrupts", CTLFLAG_RD
, &sc
->mcu_cmd_interrupts
, 0,
6947 "MCU command interrupts");
6949 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6950 "auto_wakeup_interrupts", CTLFLAG_RD
, &sc
->auto_wakeup_interrupts
, 0,
6951 "auto wakeup interrupts");
6953 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6954 "gp_timer_interrupts", CTLFLAG_RD
, &sc
->gp_timer_interrupts
, 0,
6955 "GP timer interrupts");
6957 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6958 "tx_mgmt_desc_queued", CTLFLAG_RD
, &sc
->tx_ring
[5].desc_queued
, 0,
6959 "Tx MGMT descriptors queued");
6961 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6962 "tx_mgmt_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[5].data_queued
, 0,
6963 "Tx MGMT data queued");
6965 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6966 "tx_hcca_desc_queued", CTLFLAG_RD
, &sc
->tx_ring
[4].desc_queued
, 0,
6967 "Tx HCCA descriptors queued");
6969 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6970 "tx_hcca_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[4].data_queued
, 0,
6971 "Tx HCCA data queued");
6973 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6974 "tx_ac3_desc_queued", CTLFLAG_RD
, &sc
->tx_ring
[3].desc_queued
, 0,
6975 "Tx AC3 descriptors queued");
6977 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6978 "tx_ac3_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[3].data_queued
, 0,
6979 "Tx AC3 data queued");
6981 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6982 "tx_ac2_desc_queued", CTLFLAG_RD
, &sc
->tx_ring
[2].desc_queued
, 0,
6983 "Tx AC2 descriptors queued");
6985 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6986 "tx_ac2_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[2].data_queued
, 0,
6987 "Tx AC2 data queued");
6989 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6990 "tx_ac1_desc_queued", CTLFLAG_RD
, &sc
->tx_ring
[1].desc_queued
, 0,
6991 "Tx AC1 descriptors queued");
6993 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6994 "tx_ac1_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[1].data_queued
, 0,
6995 "Tx AC1 data queued");
6997 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6998 "tx_ac0_desc_queued", CTLFLAG_RD
, &sc
->tx_ring
[0].desc_queued
, 0,
6999 "Tx AC0 descriptors queued");
7001 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
7002 "tx_ac0_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[0].data_queued
, 0,
7003 "Tx AC0 data queued");
7005 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
7006 "tx_mgmt_data_queue_full", CTLFLAG_RD
, &sc
->tx_data_queue_full
[5], 0,
7007 "Tx MGMT data queue full");
7009 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
7010 "tx_hcca_data_queue_full", CTLFLAG_RD
, &sc
->tx_data_queue_full
[4], 0,
7011 "Tx HCCA data queue full");
7013 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
7014 "tx_ac3_data_queue_full", CTLFLAG_RD
, &sc
->tx_data_queue_full
[3], 0,
7015 "Tx AC3 data queue full");
7017 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
7018 "tx_ac2_data_queue_full", CTLFLAG_RD
, &sc
->tx_data_queue_full
[2], 0,
7019 "Tx AC2 data queue full");
7021 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
7022 "tx_ac1_data_queue_full", CTLFLAG_RD
, &sc
->tx_data_queue_full
[1], 0,
7023 "Tx AC1 data queue full");
7025 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
7026 "tx_ac0_data_queue_full", CTLFLAG_RD
, &sc
->tx_data_queue_full
[0], 0,
7027 "Tx AC0 data queue full");
7029 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
7030 "tx_watchdog_timeouts", CTLFLAG_RD
, &sc
->tx_watchdog_timeouts
, 0,
7031 "Tx watchdog timeouts");
7033 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
7034 "tx_defrag_packets", CTLFLAG_RD
, &sc
->tx_defrag_packets
, 0,
7035 "Tx defragmented packets");
7037 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
7038 "no_tx_desc_avail", CTLFLAG_RD
, &sc
->no_tx_desc_avail
, 0,
7039 "no Tx descriptors available");
7041 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
7042 "rx_mbuf_alloc_errors", CTLFLAG_RD
, &sc
->rx_mbuf_alloc_errors
, 0,
7043 "Rx mbuf allocation errors");
7045 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
7046 "rx_mbuf_dmamap_errors", CTLFLAG_RD
, &sc
->rx_mbuf_dmamap_errors
, 0,
7047 "Rx mbuf DMA mapping errors");
7049 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
7050 "tx_queue_0_not_empty", CTLFLAG_RD
, &sc
->tx_queue_not_empty
[0], 0,
7051 "Tx queue 0 not empty");
7053 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
7054 "tx_queue_1_not_empty", CTLFLAG_RD
, &sc
->tx_queue_not_empty
[1], 0,
7055 "Tx queue 1 not empty");
7057 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
7058 "tx_beacons", CTLFLAG_RD
, &sc
->tx_beacons
, 0,
7061 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
7062 "tx_noretryok", CTLFLAG_RD
, &sc
->tx_noretryok
, 0,
7063 "Tx successfull without retries");
7065 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
7066 "tx_retryok", CTLFLAG_RD
, &sc
->tx_retryok
, 0,
7067 "Tx successfull with retries");
7069 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
7070 "tx_failed", CTLFLAG_RD
, &sc
->tx_failed
, 0,
7073 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
7074 "tx_underflows", CTLFLAG_RD
, &sc
->tx_underflows
, 0,
7077 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
7078 "tx_zerolen", CTLFLAG_RD
, &sc
->tx_zerolen
, 0,
7081 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
7082 "tx_nonagg", CTLFLAG_RD
, &sc
->tx_nonagg
, 0,
7083 "Tx non-aggregated");
7085 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
7086 "tx_agg", CTLFLAG_RD
, &sc
->tx_agg
, 0,
7089 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
7090 "tx_ampdu", CTLFLAG_RD
, &sc
->tx_ampdu
, 0,
7093 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
7094 "tx_mpdu_zero_density", CTLFLAG_RD
, &sc
->tx_mpdu_zero_density
, 0,
7095 "Tx MPDU with zero density");
7097 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
7098 "tx_ampdu_sessions", CTLFLAG_RD
, &sc
->tx_ampdu_sessions
, 0,
7099 "Tx A-MPDU sessions");
7101 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
7102 "rx_packets", CTLFLAG_RD
, &sc
->rx_packets
, 0,
7105 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
7106 "rx_ampdu", CTLFLAG_RD
, &sc
->rx_ampdu
, 0,
7109 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
7110 "rx_ampdu_retries", CTLFLAG_RD
, &sc
->rx_ampdu_retries
, 0,
7111 "Rx A-MPDU retries");
7113 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
7114 "rx_mpdu_zero_density", CTLFLAG_RD
, &sc
->rx_mpdu_zero_density
, 0,
7115 "Rx MPDU with zero density");
7117 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
7118 "rx_ampdu_sessions", CTLFLAG_RD
, &sc
->rx_ampdu_sessions
, 0,
7119 "Rx A-MPDU sessions");
7121 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
7122 "rx_amsdu", CTLFLAG_RD
, &sc
->rx_amsdu
, 0,
7125 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
7126 "rx_crc_errors", CTLFLAG_RD
, &sc
->rx_crc_errors
, 0,
7129 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
7130 "rx_phy_errors", CTLFLAG_RD
, &sc
->rx_phy_errors
, 0,
7133 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
7134 "rx_false_ccas", CTLFLAG_RD
, &sc
->rx_false_ccas
, 0,
7137 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
7138 "rx_plcp_errors", CTLFLAG_RD
, &sc
->rx_plcp_errors
, 0,
7141 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
7142 "rx_dup_packets", CTLFLAG_RD
, &sc
->rx_dup_packets
, 0,
7143 "Rx duplicate packets");
7145 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
7146 "rx_fifo_overflows", CTLFLAG_RD
, &sc
->rx_fifo_overflows
, 0,
7147 "Rx FIFO overflows");
7149 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
7150 "rx_cipher_no_errors", CTLFLAG_RD
, &sc
->rx_cipher_no_errors
, 0,
7151 "Rx cipher no errors");
7153 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
7154 "rx_cipher_icv_errors", CTLFLAG_RD
, &sc
->rx_cipher_icv_errors
, 0,
7155 "Rx cipher ICV errors");
7157 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
7158 "rx_cipher_mic_errors", CTLFLAG_RD
, &sc
->rx_cipher_mic_errors
, 0,
7159 "Rx cipher MIC errors");
7161 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
7162 "rx_cipher_invalid_key_errors", CTLFLAG_RD
, &sc
->rx_cipher_invalid_key_errors
, 0,
7163 "Rx cipher invalid key errors");
7166 static device_method_t rt2860_dev_methods
[] =
7168 DEVMETHOD(device_probe
, rt2860_probe
),
7169 DEVMETHOD(device_attach
, rt2860_attach
),
7170 DEVMETHOD(device_detach
, rt2860_detach
),
7171 DEVMETHOD(device_shutdown
, rt2860_shutdown
),
7172 DEVMETHOD(device_suspend
, rt2860_suspend
),
7173 DEVMETHOD(device_resume
, rt2860_resume
),
7177 static driver_t rt2860_driver
=
7181 sizeof(struct rt2860_softc
)
7184 static devclass_t rt2860_dev_class
;
7186 DRIVER_MODULE(rt2860
, pci
, rt2860_driver
, rt2860_dev_class
, 0, 0);
7188 MODULE_DEPEND(rt2860
, pci
, 1, 1, 1);
7189 MODULE_DEPEND(rt2860
, wlan
, 1, 1, 1);