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_RATE_IS_OFDM(rate) ((rate) >= 12 && (rate) != 22)
52 #define RT2860_ACK_SIZE 14
54 #define IEEE80211_HAS_ADDR4(wh) \
55 (((wh)->i_fc[1] & IEEE80211_FC1_DIR_MASK) == IEEE80211_FC1_DIR_DSTODS)
57 #define RT2860_MS(_v, _f) (((_v) & _f) >> _f##_S)
58 #define RT2860_SM(_v, _f) (((_v) << _f##_S) & _f)
60 #define RT2860_TX_WATCHDOG_TIMEOUT 5
62 #define RT2860_WCID_RESERVED 0xff
63 #define RT2860_WCID_MCAST 0xf7
66 * Data structures and types
69 struct rt2860_pci_ident
77 * Static function prototypes
80 static int rt2860_probe(device_t dev
);
82 static int rt2860_attach(device_t dev
);
84 static int rt2860_detach(device_t dev
);
86 static int rt2860_shutdown(device_t dev
);
88 static int rt2860_suspend(device_t dev
);
90 static int rt2860_resume(device_t dev
);
92 static void rt2860_init_channels(struct rt2860_softc
*sc
);
94 static void rt2860_init_channels_ht40(struct rt2860_softc
*sc
);
96 static void rt2860_init_locked(void *priv
);
98 static void rt2860_init(void *priv
);
100 static int rt2860_init_bbp(struct rt2860_softc
*sc
);
102 static void rt2860_stop_locked(void *priv
);
104 static void rt2860_stop(void *priv
);
106 static void rt2860_start(struct ifnet
*ifp
);
108 static int rt2860_ioctl(struct ifnet
*ifp
, u_long cmd
, caddr_t data
);
110 static int rt2860_reset(struct ifnet
*ifp
);
112 static int rt2860_newstate(struct ieee80211com
*ic
,
113 enum ieee80211_state nstate
, int arg
);
115 static void rt2860_scan_start(struct ieee80211com
*ic
);
117 static void rt2860_scan_end(struct ieee80211com
*ic
);
119 static void rt2860_set_channel(struct ieee80211com
*ic
);
121 static void rt2860_newassoc(struct ieee80211_node
*ni
, int isnew
);
123 static void rt2860_updateslot(struct ifnet
*ifp
);
125 static int rt2860_wme_update(struct ieee80211com
*ic
);
127 static void rt2860_update_beacon(struct ieee80211com
*ic
, int what
);
129 static void rt2860_key_update_begin(struct ieee80211com
*ic
);
131 static void rt2860_key_update_end(struct ieee80211com
*ic
);
133 static int rt2860_key_set(struct ieee80211com
*ic
,
134 const struct ieee80211_key
*k
, const uint8_t mac
[IEEE80211_ADDR_LEN
]);
136 static int rt2860_key_delete(struct ieee80211com
*ic
,
137 const struct ieee80211_key
*k
);
139 static int rt2860_raw_xmit(struct ieee80211_node
*ni
, struct mbuf
*m
,
140 const struct ieee80211_bpf_params
*params
);
142 static int rt2860_media_change(struct ifnet
*ifp
);
144 static struct ieee80211_node
*rt2860_node_alloc(struct ieee80211_node_table
*nt
);
146 static void rt2860_node_cleanup(struct ieee80211_node
*ni
);
148 static void rt2860_recv_action(struct ieee80211_node
*ni
,
149 const uint8_t *frm
, const uint8_t *efrm
);
151 static int rt2860_send_action(struct ieee80211_node
*ni
,
152 int category
, int action
, uint16_t args
[4]);
154 static void rt2860_amrr_update_iter_func(void *arg
, struct ieee80211_node
*ni
);
156 static void rt2860_periodic(void *arg
);
158 static void rt2860_tx_watchdog(void *arg
);
160 static int rt2860_staid_alloc(struct rt2860_softc
*sc
, int aid
);
162 static void rt2860_staid_delete(struct rt2860_softc
*sc
, int staid
);
164 static void rt2860_asic_set_bssid(struct rt2860_softc
*sc
,
165 const uint8_t *bssid
);
167 static void rt2860_asic_set_macaddr(struct rt2860_softc
*sc
,
168 const uint8_t *addr
);
170 static void rt2860_asic_enable_tsf_sync(struct rt2860_softc
*sc
);
172 static void rt2860_asic_disable_tsf_sync(struct rt2860_softc
*sc
);
174 static void rt2860_asic_enable_mrr(struct rt2860_softc
*sc
);
176 static void rt2860_asic_set_txpreamble(struct rt2860_softc
*sc
);
178 static void rt2860_asic_set_basicrates(struct rt2860_softc
*sc
);
180 static void rt2860_asic_update_rtsthreshold(struct rt2860_softc
*sc
);
182 static void rt2860_asic_update_txpower(struct rt2860_softc
*sc
);
184 static void rt2860_asic_update_promisc(struct rt2860_softc
*sc
);
186 static void rt2860_asic_updateprot(struct rt2860_softc
*sc
);
188 static void rt2860_asic_updateslot(struct rt2860_softc
*sc
);
190 static void rt2860_asic_wme_update(struct rt2860_softc
*sc
);
192 static void rt2860_asic_update_beacon(struct rt2860_softc
*sc
);
194 static void rt2860_asic_clear_keytables(struct rt2860_softc
*sc
);
196 static int rt2860_beacon_alloc(struct rt2860_softc
*sc
);
198 static uint8_t rt2860_rxrate(struct rt2860_rxwi
*rxwi
);
200 static uint8_t rt2860_maxrssi_rxpath(struct rt2860_softc
*sc
,
201 const struct rt2860_rxwi
*rxwi
);
203 static int8_t rt2860_rssi2dbm(struct rt2860_softc
*sc
,
204 uint8_t rssi
, uint8_t rxpath
);
206 static uint8_t rt2860_rate2mcs(uint8_t rate
);
208 static int rt2860_ackrate(struct ieee80211com
*ic
, int rate
);
210 static uint16_t rt2860_txtime(int len
, int rate
, uint32_t flags
);
212 static int rt2860_tx_frame(struct rt2860_softc
*sc
,
213 struct mbuf
*m
, struct ieee80211_node
*ni
, int qid
);
215 static int rt2860_tx_raw(struct rt2860_softc
*sc
,
216 struct mbuf
*m
, struct ieee80211_node
*ni
,
217 const struct ieee80211_bpf_params
*params
);
219 static void rt2860_intr(void *arg
);
221 static void rt2860_tx_coherent_intr(struct rt2860_softc
*sc
);
223 static void rt2860_rx_coherent_intr(struct rt2860_softc
*sc
);
225 static void rt2860_txrx_coherent_intr(struct rt2860_softc
*sc
);
227 static void rt2860_fifo_sta_full_intr(struct rt2860_softc
*sc
);
229 static void rt2860_rx_intr(struct rt2860_softc
*sc
);
231 static void rt2860_rx_delay_intr(struct rt2860_softc
*sc
);
233 static void rt2860_tx_intr(struct rt2860_softc
*sc
, int qid
);
235 static void rt2860_tx_delay_intr(struct rt2860_softc
*sc
);
237 static void rt2860_pre_tbtt_intr(struct rt2860_softc
*sc
);
239 static void rt2860_tbtt_intr(struct rt2860_softc
*sc
);
241 static void rt2860_mcu_cmd_intr(struct rt2860_softc
*sc
);
243 static void rt2860_auto_wakeup_intr(struct rt2860_softc
*sc
);
245 static void rt2860_gp_timer_intr(struct rt2860_softc
*sc
);
247 static void rt2860_rx_done_task(void *context
, int pending
);
249 static void rt2860_tx_done_task(void *context
, int pending
);
251 static void rt2860_fifo_sta_full_task(void *context
, int pending
);
253 static void rt2860_periodic_task(void *context
, int pending
);
255 static int rt2860_rx_eof(struct rt2860_softc
*sc
, int limit
);
257 static void rt2860_tx_eof(struct rt2860_softc
*sc
,
258 struct rt2860_softc_tx_ring
*ring
);
260 static void rt2860_update_stats(struct rt2860_softc
*sc
);
262 static void rt2860_bbp_tuning(struct rt2860_softc
*sc
);
264 static void rt2860_watchdog(struct rt2860_softc
*sc
);
266 static void rt2860_drain_fifo_stats(struct rt2860_softc
*sc
);
268 static void rt2860_update_raw_counters(struct rt2860_softc
*sc
);
270 static void rt2860_intr_enable(struct rt2860_softc
*sc
, uint32_t intr_mask
);
272 static void rt2860_intr_disable(struct rt2860_softc
*sc
, uint32_t intr_mask
);
274 static int rt2860_txrx_enable(struct rt2860_softc
*sc
);
276 static int rt2860_alloc_rx_ring(struct rt2860_softc
*sc
,
277 struct rt2860_softc_rx_ring
*ring
);
279 static void rt2860_reset_rx_ring(struct rt2860_softc
*sc
,
280 struct rt2860_softc_rx_ring
*ring
);
282 static void rt2860_free_rx_ring(struct rt2860_softc
*sc
,
283 struct rt2860_softc_rx_ring
*ring
);
285 static int rt2860_alloc_tx_ring(struct rt2860_softc
*sc
,
286 struct rt2860_softc_tx_ring
*ring
, int qid
);
288 static void rt2860_reset_tx_ring(struct rt2860_softc
*sc
,
289 struct rt2860_softc_tx_ring
*ring
);
291 static void rt2860_free_tx_ring(struct rt2860_softc
*sc
,
292 struct rt2860_softc_tx_ring
*ring
);
294 static void rt2860_dma_map_addr(void *arg
, bus_dma_segment_t
*segs
,
295 int nseg
, int error
);
297 static void rt2860_sysctl_attach(struct rt2860_softc
*sc
);
303 static const struct rt2860_pci_ident rt2860_pci_ids
[] =
305 { PCI_VENDOR_RALINK
, PCI_PRODUCT_RALINK_RT2860_PCI
, "Ralink RT2860 PCI" },
306 { PCI_VENDOR_RALINK
, PCI_PRODUCT_RALINK_RT2860_PCIe
, "Ralink RT2860 PCIe" },
307 { PCI_VENDOR_RALINK
, PCI_PRODUCT_RALINK_RT2760_PCI
, "Ralink RT2760 PCI" },
308 { PCI_VENDOR_RALINK
, PCI_PRODUCT_RALINK_RT2790_PCIe
, "Ralink RT2790 PCIe" },
318 { RT2860_REG_PBF_BCN_OFFSET0
, 0xf8f0e8e0 },
319 { RT2860_REG_PBF_BCN_OFFSET1
, 0x6f77d0c8 },
320 { RT2860_REG_LEGACY_BASIC_RATE
, 0x0000013f },
321 { RT2860_REG_HT_BASIC_RATE
, 0x00008003 },
322 { RT2860_REG_SYS_CTRL
, 0x00000000 },
323 { RT2860_REG_RX_FILTER_CFG
, 0x00017f97 },
324 { RT2860_REG_BKOFF_SLOT_CFG
, 0x00000209 },
325 { RT2860_REG_TX_SW_CFG0
, 0x00000000 },
326 { RT2860_REG_TX_SW_CFG1
, 0x00080606 },
327 { RT2860_REG_TX_LINK_CFG
, 0x00001020 },
328 { RT2860_REG_TX_TIMEOUT_CFG
, 0x000a2090 },
329 { RT2860_REG_MAX_LEN_CFG
, (1 << 12) | RT2860_MAX_AGG_SIZE
},
330 { RT2860_REG_LED_CFG
, 0x7f031e46 },
331 { RT2860_REG_PBF_MAX_PCNT
, 0x1f3fbf9f },
332 { RT2860_REG_TX_RTY_CFG
, 0x47d01f0f },
333 { RT2860_REG_AUTO_RSP_CFG
, 0x00000013 },
334 { RT2860_REG_TX_CCK_PROT_CFG
, 0x05740003 },
335 { RT2860_REG_TX_OFDM_PROT_CFG
, 0x05740003 },
336 { RT2860_REG_TX_GF20_PROT_CFG
, 0x01744004 },
337 { RT2860_REG_TX_GF40_PROT_CFG
, 0x03f44084 },
338 { RT2860_REG_TX_MM20_PROT_CFG
, 0x01744004 },
339 { RT2860_REG_TX_MM40_PROT_CFG
, 0x03f54084 },
340 { RT2860_REG_TX_TXOP_CTRL_CFG
, 0x0000583f },
341 { RT2860_REG_TX_RTS_CFG
, 0x00092b20 },
342 { RT2860_REG_TX_EXP_ACK_TIME
, 0x002400ca },
343 { RT2860_REG_HCCAPSMP_TXOP_HLDR_ET
, 0x00000002 },
344 { RT2860_REG_XIFS_TIME_CFG
, 0x33a41010 },
345 { RT2860_REG_PWR_PIN_CFG
, 0x00000003 },
346 { RT2860_REG_SCHDMA_WMM_AIFSN_CFG
, 0x00002273 },
347 { RT2860_REG_SCHDMA_WMM_CWMIN_CFG
, 0x00002344 },
348 { RT2860_REG_SCHDMA_WMM_CWMAX_CFG
, 0x000034aa },
351 #define RT2860_DEF_MAC_SIZE (sizeof(rt2860_def_mac) / sizeof(rt2860_def_mac[0]))
376 #define RT2860_DEF_BBP_SIZE (sizeof(rt2860_def_bbp) / sizeof(rt2860_def_bbp[0]))
378 SYSCTL_NODE(_hw
, OID_AUTO
, rt2860
, CTLFLAG_RD
, 0, "RT2860 driver parameters");
381 static int rt2860_debug
= 0;
382 SYSCTL_INT(_hw_rt2860
, OID_AUTO
, debug
, CTLFLAG_RW
, &rt2860_debug
, 0, "rt2860 debug level");
383 TUNABLE_INT("hw.rt2860.debug", &rt2860_debug
);
389 static int rt2860_probe(device_t dev
)
391 const struct rt2860_pci_ident
*ident
;
393 for (ident
= rt2860_pci_ids
; ident
->name
!= NULL
; ident
++)
395 if (pci_get_vendor(dev
) == ident
->vendor
&&
396 pci_get_device(dev
) == ident
->device
)
398 device_set_desc(dev
, ident
->name
);
409 static int rt2860_attach(device_t dev
)
411 struct rt2860_softc
*sc
;
413 struct ieee80211com
*ic
;
414 int error
, ntries
, i
;
416 sc
= device_get_softc(dev
);
418 if (pci_get_powerstate(dev
) != PCI_POWERSTATE_D0
)
420 printf("%s: chip is in D%d power mode, setting to D0\n",
421 device_get_nameunit(dev
), pci_get_powerstate(dev
));
422 pci_set_powerstate(dev
, PCI_POWERSTATE_D0
);
425 /* enable bus-mastering */
427 pci_enable_busmaster(dev
);
431 mtx_init(&sc
->lock
, device_get_nameunit(dev
),
432 MTX_NETWORK_LOCK
, MTX_DEF
| MTX_RECURSE
);
434 sc
->mem_rid
= PCIR_BAR(0);
435 sc
->mem
= bus_alloc_resource_any(dev
, SYS_RES_MEMORY
,
436 &sc
->mem_rid
, RF_ACTIVE
);
439 printf("%s: could not allocate memory resource\n",
440 device_get_nameunit(dev
));
445 sc
->bst
= rman_get_bustag(sc
->mem
);
446 sc
->bsh
= rman_get_bushandle(sc
->mem
);
449 sc
->irq
= bus_alloc_resource_any(dev
, SYS_RES_IRQ
,
450 &sc
->irq_rid
, RF_ACTIVE
| RF_SHAREABLE
);
453 printf("%s: could not allocate interrupt resource\n",
454 device_get_nameunit(dev
));
460 sc
->debug
= rt2860_debug
;
462 SYSCTL_ADD_INT(device_get_sysctl_ctx(dev
),
463 SYSCTL_CHILDREN(device_get_sysctl_tree(dev
)), OID_AUTO
,
464 "debug", CTLFLAG_RW
, &sc
->debug
, 0, "rt2860 debug level");
467 RT2860_DPRINTF(sc
, RT2860_DEBUG_ANY
,
469 device_get_nameunit(sc
->dev
));
471 /* wait for NIC to initialize */
473 for (ntries
= 0; ntries
< 100; ntries
++)
475 sc
->mac_rev
= rt2860_io_mac_read(sc
, RT2860_REG_MAC_CSR0
);
476 if (sc
->mac_rev
!= 0x00000000 && sc
->mac_rev
!= 0xffffffff)
484 printf("%s: timeout waiting for NIC to initialize\n",
485 device_get_nameunit(dev
));
490 rt2860_read_eeprom(sc
);
492 printf("%s: MAC/BBP RT2860 (rev 0x%08x), RF %s\n",
493 device_get_nameunit(sc
->dev
), sc
->mac_rev
,
494 rt2860_rf_name(sc
->rf_rev
));
496 /* allocate Tx and Rx rings */
498 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
500 error
= rt2860_alloc_tx_ring(sc
, &sc
->tx_ring
[i
], i
);
503 printf("%s: could not allocate Tx ring #%d\n",
504 device_get_nameunit(sc
->dev
), i
);
509 sc
->tx_ring_mgtqid
= 5;
511 error
= rt2860_alloc_rx_ring(sc
, &sc
->rx_ring
);
514 printf("%s: could not allocate Rx ring\n",
515 device_get_nameunit(sc
->dev
));
519 callout_init(&sc
->periodic_ch
, 0);
520 callout_init_mtx(&sc
->tx_watchdog_ch
, &sc
->lock
, 0);
522 ifp
= sc
->ifp
= if_alloc(IFT_ETHER
);
525 printf("%s: could not if_alloc()\n",
526 device_get_nameunit(sc
->dev
));
533 if_initname(ifp
, "rt2860", device_get_unit(sc
->dev
));
535 ifp
->if_flags
= IFF_BROADCAST
| IFF_SIMPLEX
| IFF_MULTICAST
;
537 ifp
->if_init
= rt2860_init
;
538 ifp
->if_ioctl
= rt2860_ioctl
;
539 ifp
->if_start
= rt2860_start
;
541 IFQ_SET_MAXLEN(&ifp
->if_snd
, IFQ_MAXLEN
);
542 ifp
->if_snd
.ifq_drv_maxlen
= IFQ_MAXLEN
;
543 IFQ_SET_READY(&ifp
->if_snd
);
549 ic
->ic_phytype
= IEEE80211_T_HT
;
550 ic
->ic_opmode
= IEEE80211_M_STA
;
551 ic
->ic_state
= IEEE80211_S_INIT
;
553 ic
->ic_caps
= IEEE80211_C_MONITOR
|
560 IEEE80211_C_SHPREAMBLE
|
567 IEEE80211_C_AES_CCM
|
570 ic
->ic_htcaps
= IEEE80211_HTC_HT
|
571 IEEE80211_HTC_AMSDU
| /* A-MSDU Tx */
572 IEEE80211_HTC_AMPDU
| /* A-MPDU Tx */
573 IEEE80211_HTCAP_MAXAMSDU_3839
| /* max. A-MSDU Rx length */
574 IEEE80211_HTCAP_CHWIDTH40
| /* HT 40MHz channel width */
575 IEEE80211_HTCAP_GREENFIELD
| /* HT greenfield */
576 IEEE80211_HTCAP_SHORTGI20
| /* HT 20MHz short GI */
577 IEEE80211_HTCAP_SHORTGI40
| /* HT 40MHz short GI */
578 IEEE80211_HTCAP_SMPS_OFF
; /* MIMO power save disabled */
580 /* spatial streams */
582 if (sc
->nrxpath
== 2)
583 ic
->ic_htcaps
|= IEEE80211_HTCAP_RXSTBC_2STREAM
;
584 else if (sc
->nrxpath
== 3)
585 ic
->ic_htcaps
|= IEEE80211_HTCAP_RXSTBC_3STREAM
;
587 ic
->ic_htcaps
|= IEEE80211_HTCAP_RXSTBC_1STREAM
;
590 ic
->ic_htcaps
|= IEEE80211_HTCAP_TXSTBC
;
594 if (sc
->mac_rev
!= 0x28600100)
595 ic
->ic_htcaps
|= IEEE80211_HTCAP_DELBA
;
600 ic
->ic_regdomain
= 0;
601 ic
->ic_countrycode
= CTRY_DEFAULT
;
604 rt2860_init_channels(sc
);
606 rt2860_init_channels_ht40(sc
);
608 IEEE80211_ADDR_COPY(ic
->ic_myaddr
, sc
->mac_addr
);
610 ieee80211_ifattach(ic
);
612 sc
->newstate
= ic
->ic_newstate
;
613 ic
->ic_newstate
= rt2860_newstate
;
615 ic
->ic_reset
= rt2860_reset
;
616 ic
->ic_node_alloc
= rt2860_node_alloc
;
618 sc
->node_cleanup
= ic
->ic_node_cleanup
;
619 ic
->ic_node_cleanup
= rt2860_node_cleanup
;
621 ic
->ic_scan_start
= rt2860_scan_start
;
622 ic
->ic_scan_end
= rt2860_scan_end
;
623 ic
->ic_set_channel
= rt2860_set_channel
;
624 ic
->ic_newassoc
= rt2860_newassoc
;
625 ic
->ic_updateslot
= rt2860_updateslot
;
626 ic
->ic_wme
.wme_update
= rt2860_wme_update
;
627 ic
->ic_update_beacon
= rt2860_update_beacon
;
628 ic
->ic_crypto
.cs_key_update_begin
= rt2860_key_update_begin
;
629 ic
->ic_crypto
.cs_key_update_end
= rt2860_key_update_end
;
630 ic
->ic_crypto
.cs_key_set
= rt2860_key_set
;
631 ic
->ic_crypto
.cs_key_delete
= rt2860_key_delete
;
632 ic
->ic_raw_xmit
= rt2860_raw_xmit
;
634 sc
->recv_action
= ic
->ic_recv_action
;
635 ic
->ic_recv_action
= rt2860_recv_action
;
637 sc
->send_action
= ic
->ic_send_action
;
638 ic
->ic_send_action
= rt2860_send_action
;
640 /* override Rx A-MPDU factor */
642 ic
->ic_ampdu_rxmax
= IEEE80211_HTCAP_MAXRXAMPDU_32K
;
643 ic
->ic_ampdu_density
= IEEE80211_HTCAP_MPDUDENSITY_NA
;
644 ic
->ic_ampdu_limit
= ic
->ic_ampdu_rxmax
;
646 /* hardware requires padding between 802.11 frame header and body */
648 ic
->ic_flags
|= IEEE80211_F_WME
| IEEE80211_F_DATAPAD
| IEEE80211_F_DOTH
;
650 ic
->ic_flags_ext
|= IEEE80211_FEXT_SWBMISS
;
652 ieee80211_media_init(ic
, rt2860_media_change
, ieee80211_media_status
);
654 rt2860_amrr_init(&sc
->amrr
, ic
,
656 RT2860_AMRR_MIN_SUCCESS_THRESHOLD
,
657 RT2860_AMRR_MAX_SUCCESS_THRESHOLD
,
660 bpfattach2(ifp
, DLT_IEEE802_11_RADIO
,
661 sizeof(struct ieee80211_frame
) + IEEE80211_RADIOTAP_HDRLEN
,
664 sc
->rxtap_len
= sizeof(sc
->rxtapu
);
665 sc
->rxtap
.ihdr
.it_len
= htole16(sc
->rxtap_len
);
666 sc
->rxtap
.ihdr
.it_present
= htole32(RT2860_SOFTC_RX_RADIOTAP_PRESENT
);
668 sc
->txtap_len
= sizeof(sc
->txtapu
);
669 sc
->txtap
.ihdr
.it_len
= htole16(sc
->txtap_len
);
670 sc
->txtap
.ihdr
.it_present
= htole32(RT2860_SOFTC_TX_RADIOTAP_PRESENT
);
672 /* init task queue */
674 TASK_INIT(&sc
->rx_done_task
, 0, rt2860_rx_done_task
, sc
);
675 TASK_INIT(&sc
->tx_done_task
, 0, rt2860_tx_done_task
, sc
);
676 TASK_INIT(&sc
->fifo_sta_full_task
, 0, rt2860_fifo_sta_full_task
, sc
);
677 TASK_INIT(&sc
->periodic_task
, 0, rt2860_periodic_task
, sc
);
679 sc
->rx_process_limit
= 100;
681 sc
->taskqueue
= taskqueue_create("rt2860_taskq", M_NOWAIT
,
682 taskqueue_thread_enqueue
, &sc
->taskqueue
);
684 taskqueue_start_threads(&sc
->taskqueue
, 1, PI_NET
, "%s taskq",
685 device_get_nameunit(sc
->dev
));
687 rt2860_sysctl_attach(sc
);
690 ieee80211_announce(ic
);
692 /* set up interrupt */
694 error
= bus_setup_intr(dev
, sc
->irq
, INTR_TYPE_NET
| INTR_MPSAFE
,
695 NULL
, rt2860_intr
, sc
, &sc
->irqh
);
698 printf("%s: could not set up interrupt\n",
699 device_get_nameunit(dev
));
707 /* free Tx and Rx rings */
709 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
710 rt2860_free_tx_ring(sc
, &sc
->tx_ring
[i
]);
712 rt2860_free_rx_ring(sc
, &sc
->rx_ring
);
714 mtx_destroy(&sc
->lock
);
717 bus_release_resource(dev
, SYS_RES_MEMORY
, sc
->mem_rid
, sc
->mem
);
720 bus_release_resource(dev
, SYS_RES_IRQ
, sc
->irq_rid
, sc
->irq
);
728 static int rt2860_detach(device_t dev
)
730 struct rt2860_softc
*sc
;
731 struct ieee80211com
*ic
;
735 sc
= device_get_softc(dev
);
739 RT2860_DPRINTF(sc
, RT2860_DEBUG_ANY
,
741 device_get_nameunit(sc
->dev
));
743 RT2860_SOFTC_LOCK(sc
);
745 ifp
->if_drv_flags
&= ~(IFF_DRV_RUNNING
| IFF_DRV_OACTIVE
);
747 ieee80211_new_state(ic
, IEEE80211_S_INIT
, -1);
749 callout_stop(&sc
->periodic_ch
);
750 callout_stop(&sc
->tx_watchdog_ch
);
752 taskqueue_drain(sc
->taskqueue
, &sc
->rx_done_task
);
753 taskqueue_drain(sc
->taskqueue
, &sc
->tx_done_task
);
754 taskqueue_drain(sc
->taskqueue
, &sc
->fifo_sta_full_task
);
755 taskqueue_drain(sc
->taskqueue
, &sc
->periodic_task
);
757 /* free Tx and Rx rings */
759 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
760 rt2860_free_tx_ring(sc
, &sc
->tx_ring
[i
]);
762 rt2860_free_rx_ring(sc
, &sc
->rx_ring
);
764 RT2860_SOFTC_UNLOCK(sc
);
768 ieee80211_ifdetach(ic
);
772 taskqueue_free(sc
->taskqueue
);
774 mtx_destroy(&sc
->lock
);
776 bus_generic_detach(dev
);
778 bus_teardown_intr(dev
, sc
->irq
, sc
->irqh
);
780 bus_release_resource(dev
, SYS_RES_IRQ
, sc
->irq_rid
, sc
->irq
);
782 bus_release_resource(dev
, SYS_RES_MEMORY
, sc
->mem_rid
, sc
->mem
);
790 static int rt2860_shutdown(device_t dev
)
792 struct rt2860_softc
*sc
;
794 sc
= device_get_softc(dev
);
796 RT2860_DPRINTF(sc
, RT2860_DEBUG_ANY
,
797 "%s: shutting down\n",
798 device_get_nameunit(sc
->dev
));
802 sc
->flags
&= ~RT2860_SOFTC_FLAGS_UCODE_LOADED
;
810 static int rt2860_suspend(device_t dev
)
812 struct rt2860_softc
*sc
;
814 sc
= device_get_softc(dev
);
816 RT2860_DPRINTF(sc
, RT2860_DEBUG_ANY
,
818 device_get_nameunit(sc
->dev
));
822 sc
->flags
&= ~RT2860_SOFTC_FLAGS_UCODE_LOADED
;
830 static int rt2860_resume(device_t dev
)
832 struct rt2860_softc
*sc
;
835 sc
= device_get_softc(dev
);
838 RT2860_DPRINTF(sc
, RT2860_DEBUG_ANY
,
840 device_get_nameunit(sc
->dev
));
842 if (ifp
->if_flags
& IFF_UP
)
849 * rt2860_init_channels
851 static void rt2860_init_channels(struct rt2860_softc
*sc
)
853 struct ieee80211com
*ic
;
854 struct ieee80211_channel
*c
;
859 /* set supported channels for 2GHz band */
861 for (i
= 1; i
<= 14; i
++)
863 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
864 flags
= IEEE80211_CHAN_B
;
866 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
870 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
871 flags
= IEEE80211_CHAN_B
| IEEE80211_CHAN_HT20
;
873 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
877 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
878 flags
= IEEE80211_CHAN_G
;
880 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
884 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
885 flags
= IEEE80211_CHAN_G
| IEEE80211_CHAN_HT20
;
887 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
892 /* set supported channels for 5GHz band */
894 if (sc
->rf_rev
== RT2860_EEPROM_RF_2850
||
895 sc
->rf_rev
== RT2860_EEPROM_RF_2750
)
897 for (i
= 36; i
<= 64; i
+= 4)
899 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
900 flags
= IEEE80211_CHAN_A
;
902 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
906 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
907 flags
= IEEE80211_CHAN_A
| IEEE80211_CHAN_HT20
;
909 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
914 for (i
= 100; i
<= 140; i
+= 4)
916 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
917 flags
= IEEE80211_CHAN_A
;
919 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
923 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
924 flags
= IEEE80211_CHAN_A
| IEEE80211_CHAN_HT20
;
926 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
931 for (i
= 149; i
<= 165; i
+= 4)
933 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
934 flags
= IEEE80211_CHAN_A
;
936 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
940 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
941 flags
= IEEE80211_CHAN_A
| IEEE80211_CHAN_HT20
;
943 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
951 * rt2860_init_channels_ht40
953 static void rt2860_init_channels_ht40(struct rt2860_softc
*sc
)
955 struct ieee80211com
*ic
;
956 struct ieee80211_channel
*c
, *cent
, *ext
;
961 /* set supported channels for 2GHz band */
963 for (i
= 1; i
<= 14; i
++)
965 flags
= IEEE80211_CHAN_G
| IEEE80211_CHAN_HT40
;
967 /* find the center channel */
969 cent
= ieee80211_find_channel_byieee(ic
, i
,
970 flags
& ~IEEE80211_CHAN_HT
);
973 printf("%s: skip channel %d, could not find center channel\n",
974 device_get_nameunit(sc
->dev
), i
);
978 /* find the extension channel */
980 ext
= ieee80211_find_channel(ic
, cent
->ic_freq
+ 20,
981 flags
& ~IEEE80211_CHAN_HT
);
984 printf("%s: skip channel %d, could not find extension channel\n",
985 device_get_nameunit(sc
->dev
), i
);
989 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
992 c
->ic_extieee
= ext
->ic_ieee
;
993 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
994 c
->ic_flags
|= IEEE80211_CHAN_HT40U
;
996 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
999 c
->ic_extieee
= cent
->ic_ieee
;
1000 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1001 c
->ic_flags
|= IEEE80211_CHAN_HT40D
;
1004 /* set supported channels for 5GHz band */
1006 if (sc
->rf_rev
== RT2860_EEPROM_RF_2850
||
1007 sc
->rf_rev
== RT2860_EEPROM_RF_2750
)
1009 for (i
= 36; i
<= 64; i
+= 4)
1011 flags
= IEEE80211_CHAN_A
| IEEE80211_CHAN_HT40
;
1013 /* find the center channel */
1015 cent
= ieee80211_find_channel_byieee(ic
, i
,
1016 flags
& ~IEEE80211_CHAN_HT
);
1019 printf("%s: skip channel %d, could not find center channel\n",
1020 device_get_nameunit(sc
->dev
), i
);
1024 /* find the extension channel */
1026 ext
= ieee80211_find_channel(ic
, cent
->ic_freq
+ 20,
1027 flags
& ~IEEE80211_CHAN_HT
);
1030 printf("%s: skip channel %d, could not find extension channel\n",
1031 device_get_nameunit(sc
->dev
), i
);
1035 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1038 c
->ic_extieee
= ext
->ic_ieee
;
1039 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1040 c
->ic_flags
|= IEEE80211_CHAN_HT40U
;
1042 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1045 c
->ic_extieee
= cent
->ic_ieee
;
1046 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1047 c
->ic_flags
|= IEEE80211_CHAN_HT40D
;
1050 for (i
= 100; i
<= 140; i
+= 4)
1052 flags
= IEEE80211_CHAN_A
| IEEE80211_CHAN_HT40
;
1054 /* find the center channel */
1056 cent
= ieee80211_find_channel_byieee(ic
, i
,
1057 flags
& ~IEEE80211_CHAN_HT
);
1060 printf("%s: skip channel %d, could not find center channel\n",
1061 device_get_nameunit(sc
->dev
), i
);
1065 /* find the extension channel */
1067 ext
= ieee80211_find_channel(ic
, cent
->ic_freq
+ 20,
1068 flags
& ~IEEE80211_CHAN_HT
);
1071 printf("%s: skip channel %d, could not find extension channel\n",
1072 device_get_nameunit(sc
->dev
), i
);
1076 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1079 c
->ic_extieee
= ext
->ic_ieee
;
1080 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1081 c
->ic_flags
|= IEEE80211_CHAN_HT40U
;
1083 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1086 c
->ic_extieee
= cent
->ic_ieee
;
1087 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1088 c
->ic_flags
|= IEEE80211_CHAN_HT40D
;
1091 for (i
= 149; i
<= 165; i
+= 4)
1093 flags
= IEEE80211_CHAN_A
| IEEE80211_CHAN_HT40
;
1095 /* find the center channel */
1097 cent
= ieee80211_find_channel_byieee(ic
, i
,
1098 flags
& ~IEEE80211_CHAN_HT
);
1101 printf("%s: skip channel %d, could not find center channel\n",
1102 device_get_nameunit(sc
->dev
), i
);
1106 /* find the extension channel */
1108 ext
= ieee80211_find_channel(ic
, cent
->ic_freq
+ 20,
1109 flags
& ~IEEE80211_CHAN_HT
);
1112 printf("%s: skip channel %d, could not find extension channel\n",
1113 device_get_nameunit(sc
->dev
), i
);
1117 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1120 c
->ic_extieee
= ext
->ic_ieee
;
1121 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1122 c
->ic_flags
|= IEEE80211_CHAN_HT40U
;
1124 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1127 c
->ic_extieee
= cent
->ic_ieee
;
1128 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1129 c
->ic_flags
|= IEEE80211_CHAN_HT40D
;
1135 * rt2860_init_locked
1137 static void rt2860_init_locked(void *priv
)
1139 struct rt2860_softc
*sc
;
1140 struct ieee80211com
*ic
;
1142 int error
, i
, ntries
;
1143 uint32_t tmp
, stacnt
[6];
1149 RT2860_DPRINTF(sc
, RT2860_DEBUG_ANY
,
1150 "%s: initializing\n",
1151 device_get_nameunit(sc
->dev
));
1153 RT2860_SOFTC_ASSERT_LOCKED(sc
);
1155 if (!(sc
->flags
& RT2860_SOFTC_FLAGS_UCODE_LOADED
))
1157 RT2860_DPRINTF(sc
, RT2860_DEBUG_ANY
,
1158 "%s: loading 8051 microcode\n",
1159 device_get_nameunit(sc
->dev
));
1161 error
= rt2860_io_mcu_load_ucode(sc
, rt2860_ucode
, sizeof(rt2860_ucode
));
1164 printf("%s: could not load 8051 microcode\n",
1165 device_get_nameunit(sc
->dev
));
1169 RT2860_DPRINTF(sc
, RT2860_DEBUG_ANY
,
1170 "%s: 8051 microcode was successfully loaded\n",
1171 device_get_nameunit(sc
->dev
));
1173 sc
->flags
|= RT2860_SOFTC_FLAGS_UCODE_LOADED
;
1176 rt2860_io_mac_write(sc
, RT2860_REG_PWR_PIN_CFG
, 0x2);
1178 /* disable DMA engine */
1180 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
);
1183 tmp
|= RT2860_REG_TX_WB_DDONE
;
1185 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
, tmp
);
1187 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WPDMA_RST_IDX
, 0xffffffff);
1189 /* PBF hardware reset */
1191 rt2860_io_mac_write(sc
, RT2860_REG_PBF_SYS_CTRL
, 0xe1f);
1192 rt2860_io_mac_write(sc
, RT2860_REG_PBF_SYS_CTRL
, 0xe00);
1194 /* wait while DMA engine is busy */
1196 for (ntries
= 0; ntries
< 100; ntries
++)
1198 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
);
1199 if (!(tmp
& (RT2860_REG_TX_DMA_BUSY
| RT2860_REG_RX_DMA_BUSY
)))
1207 printf("%s: timeout waiting for DMA engine\n",
1208 device_get_nameunit(sc
->dev
));
1213 tmp
|= RT2860_REG_TX_WB_DDONE
;
1215 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
, tmp
);
1217 /* reset Rx and Tx rings */
1219 tmp
= RT2860_REG_RST_IDX_RX
|
1220 RT2860_REG_RST_IDX_TX_MGMT
|
1221 RT2860_REG_RST_IDX_TX_HCCA
|
1222 RT2860_REG_RST_IDX_TX_AC3
|
1223 RT2860_REG_RST_IDX_TX_AC2
|
1224 RT2860_REG_RST_IDX_TX_AC1
|
1225 RT2860_REG_RST_IDX_TX_AC0
;
1227 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WPDMA_RST_IDX
, tmp
);
1229 /* PBF hardware reset */
1231 rt2860_io_mac_write(sc
, RT2860_REG_PBF_SYS_CTRL
, 0xe1f);
1232 rt2860_io_mac_write(sc
, RT2860_REG_PBF_SYS_CTRL
, 0xe00);
1234 rt2860_io_mac_write(sc
, RT2860_REG_PWR_PIN_CFG
, 0x3);
1236 rt2860_io_mac_write(sc
, RT2860_REG_SYS_CTRL
,
1237 RT2860_REG_MAC_SRST
| RT2860_REG_BBP_HRST
);
1238 rt2860_io_mac_write(sc
, RT2860_REG_SYS_CTRL
, 0);
1240 /* init Tx power per rate */
1242 for (i
= 0; i
< RT2860_SOFTC_TXPOW_RATE_COUNT
; i
++)
1244 if (sc
->txpow_rate_20mhz
[i
] == 0xffffffff)
1247 rt2860_io_mac_write(sc
, RT2860_REG_TX_PWR_CFG(i
),
1248 sc
->txpow_rate_20mhz
[i
]);
1251 for (i
= 0; i
< RT2860_DEF_MAC_SIZE
; i
++)
1252 rt2860_io_mac_write(sc
, rt2860_def_mac
[i
].reg
,
1253 rt2860_def_mac
[i
].val
);
1255 /* wait while MAC is busy */
1257 for (ntries
= 0; ntries
< 100; ntries
++)
1259 if (!(rt2860_io_mac_read(sc
, RT2860_REG_STATUS_CFG
) &
1260 (RT2860_REG_STATUS_TX_BUSY
| RT2860_REG_STATUS_RX_BUSY
)))
1268 printf("%s: timeout waiting for MAC\n",
1269 device_get_nameunit(sc
->dev
));
1273 /* clear Host to MCU mailbox */
1275 rt2860_io_mac_write(sc
, RT2860_REG_H2M_MAILBOX_BBP_AGENT
, 0);
1276 rt2860_io_mac_write(sc
, RT2860_REG_H2M_MAILBOX
, 0);
1278 rt2860_io_mcu_cmd(sc
, RT2860_IO_MCU_CMD_BOOT
,
1279 RT2860_REG_H2M_TOKEN_NO_INTR
, 0);
1283 error
= rt2860_init_bbp(sc
);
1287 /* set up maximum buffer sizes */
1289 tmp
= (1 << 12) | RT2860_MAX_AGG_SIZE
;
1291 rt2860_io_mac_write(sc
, RT2860_REG_MAX_LEN_CFG
, tmp
);
1293 /* set mac address */
1295 IEEE80211_ADDR_COPY(ic
->ic_myaddr
, IF_LLADDR(ifp
));
1297 rt2860_asic_set_macaddr(sc
, ic
->ic_myaddr
);
1299 /* clear statistic registers */
1301 rt2860_io_mac_read_multi(sc
, RT2860_REG_RX_STA_CNT0
,
1302 stacnt
, sizeof(stacnt
));
1304 /* set RTS threshold */
1306 rt2860_asic_update_rtsthreshold(sc
);
1310 rt2860_asic_update_txpower(sc
);
1312 /* set up protection mode */
1314 sc
->tx_ampdu_sessions
= 0;
1316 rt2860_asic_updateprot(sc
);
1318 /* clear beacon frame space (entries = 8, entry size = 512) */
1320 rt2860_io_mac_set_region_4(sc
, RT2860_REG_BEACON_BASE(0), 0, 1024);
1322 taskqueue_unblock(sc
->taskqueue
);
1324 /* init Tx rings (4 EDCAs + HCCA + MGMT) */
1326 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
1327 rt2860_reset_tx_ring(sc
, &sc
->tx_ring
[i
]);
1329 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
1331 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_BASE_PTR(i
),
1332 sc
->tx_ring
[i
].desc_phys_addr
);
1333 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_MAX_CNT(i
),
1334 RT2860_SOFTC_TX_RING_DESC_COUNT
);
1335 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_CTX_IDX(i
), 0);
1340 rt2860_reset_rx_ring(sc
, &sc
->rx_ring
);
1342 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_BASE_PTR
,
1343 sc
->rx_ring
.desc_phys_addr
);
1344 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_MAX_CNT
,
1345 RT2860_SOFTC_RX_RING_DATA_COUNT
);
1346 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_CALC_IDX
,
1347 RT2860_SOFTC_RX_RING_DATA_COUNT
- 1);
1349 /* wait while DMA engine is busy */
1351 for (ntries
= 0; ntries
< 100; ntries
++)
1353 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
);
1354 if (!(tmp
& (RT2860_REG_TX_DMA_BUSY
| RT2860_REG_RX_DMA_BUSY
)))
1362 printf("%s: timeout waiting for DMA engine\n",
1363 device_get_nameunit(sc
->dev
));
1368 tmp
|= RT2860_REG_TX_WB_DDONE
;
1370 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
, tmp
);
1372 /* disable interrupts mitigation */
1374 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_DELAY_INT_CFG
, 0);
1376 /* send LEDs operating mode to microcontroller */
1378 rt2860_io_mcu_cmd(sc
, RT2860_IO_MCU_CMD_LED1
,
1379 RT2860_REG_H2M_TOKEN_NO_INTR
, sc
->led_off
[0]);
1380 rt2860_io_mcu_cmd(sc
, RT2860_IO_MCU_CMD_LED2
,
1381 RT2860_REG_H2M_TOKEN_NO_INTR
, sc
->led_off
[1]);
1382 rt2860_io_mcu_cmd(sc
, RT2860_IO_MCU_CMD_LED3
,
1383 RT2860_REG_H2M_TOKEN_NO_INTR
, sc
->led_off
[2]);
1385 /* turn radio LED on */
1387 rt2860_led_cmd(sc
, RT2860_LED_CMD_RADIO_ON
);
1389 /* write vendor-specific BBP values (from EEPROM) */
1391 for (i
= 0; i
< RT2860_SOFTC_BBP_EEPROM_COUNT
; i
++)
1393 if (sc
->bbp_eeprom
[i
].reg
== 0x00 ||
1394 sc
->bbp_eeprom
[i
].reg
== 0xff)
1397 rt2860_io_bbp_write(sc
, sc
->bbp_eeprom
[i
].reg
,
1398 sc
->bbp_eeprom
[i
].val
);
1402 tmp = rt2860_io_mac_read(sc, RT2860_REG_SCHDMA_GPIO_CTRL_CFG);
1405 rt2860_io_mcu_cmd(sc, RT2860_IO_MCU_CMD_SLEEP,
1406 RT2860_REG_H2M_TOKEN_RADIOOFF, 0x02ff);
1407 rt2860_io_mcu_cmd_check(sc, RT2860_REG_H2M_TOKEN_RADIOOFF);
1409 rt2860_io_mcu_cmd(sc, RT2860_IO_MCU_CMD_WAKEUP,
1410 RT2860_REG_H2M_TOKEN_WAKEUP, 0);
1411 rt2860_io_mcu_cmd_check(sc, RT2860_REG_H2M_TOKEN_WAKEUP);
1415 /* disable non-existing Rx chains */
1417 tmp
= rt2860_io_bbp_read(sc
, 3);
1419 tmp
&= ~((1 << 4) | (1 << 3));
1421 if (sc
->nrxpath
== 3)
1423 else if (sc
->nrxpath
== 2)
1426 rt2860_io_bbp_write(sc
, 3, tmp
);
1428 /* disable non-existing Tx chains */
1430 tmp
= rt2860_io_bbp_read(sc
, 1);
1432 tmp
&= ~((1 << 4) | (1 << 3));
1434 if (sc
->ntxpath
== 2)
1437 rt2860_io_bbp_write(sc
, 1, tmp
);
1439 /* set current channel */
1441 rt2860_rf_set_chan(sc
, ic
->ic_curchan
);
1443 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WMM_TXOP0_CFG
, 0);
1444 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WMM_TXOP1_CFG
,
1447 if ((sc
->mac_rev
& 0xffff) != 0x0101)
1448 rt2860_io_mac_write(sc
, RT2860_REG_TX_TXOP_CTRL_CFG
, 0x583f);
1450 /* clear pending interrupts */
1452 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_INT_STATUS
, 0xffffffff);
1454 /* enable interrupts */
1456 tmp
= RT2860_REG_INT_TX_COHERENT
|
1457 RT2860_REG_INT_RX_COHERENT
|
1458 RT2860_REG_INT_GP_TIMER
|
1459 RT2860_REG_INT_AUTO_WAKEUP
|
1460 RT2860_REG_INT_FIFO_STA_FULL
|
1462 RT2860_REG_INT_PRE_TBTT |
1463 RT2860_REG_INT_TBTT |
1465 RT2860_REG_INT_TXRX_COHERENT
|
1466 RT2860_REG_INT_MCU_CMD
|
1467 RT2860_REG_INT_TX_MGMT_DONE
|
1468 RT2860_REG_INT_TX_HCCA_DONE
|
1469 RT2860_REG_INT_TX_AC3_DONE
|
1470 RT2860_REG_INT_TX_AC2_DONE
|
1471 RT2860_REG_INT_TX_AC1_DONE
|
1472 RT2860_REG_INT_TX_AC0_DONE
|
1473 RT2860_REG_INT_RX_DONE
;
1475 sc
->intr_enable_mask
= tmp
;
1477 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_INT_MASK
, tmp
);
1479 if (rt2860_txrx_enable(sc
) != 0)
1482 /* clear garbage interrupts */
1484 tmp
= rt2860_io_mac_read(sc
, 0x1300);
1486 ifp
->if_drv_flags
&= ~IFF_DRV_OACTIVE
;
1487 ifp
->if_drv_flags
|= IFF_DRV_RUNNING
;
1489 if (ic
->ic_opmode
!= IEEE80211_M_MONITOR
)
1491 if (ic
->ic_roaming
!= IEEE80211_ROAMING_MANUAL
)
1492 ieee80211_new_state(ic
, IEEE80211_S_SCAN
, -1);
1496 ieee80211_new_state(ic
, IEEE80211_S_RUN
, -1);
1499 sc
->periodic_round
= 0;
1501 callout_reset(&sc
->periodic_ch
, hz
/ 10, rt2860_periodic
, sc
);
1507 rt2860_stop_locked(sc
);
1513 static void rt2860_init(void *priv
)
1515 struct rt2860_softc
*sc
;
1519 RT2860_SOFTC_LOCK(sc
);
1521 rt2860_init_locked(sc
);
1523 RT2860_SOFTC_UNLOCK(sc
);
1529 static int rt2860_init_bbp(struct rt2860_softc
*sc
)
1534 for (ntries
= 0; ntries
< 20; ntries
++)
1536 tmp
= rt2860_io_bbp_read(sc
, 0);
1537 if (tmp
!= 0x00 && tmp
!= 0xff)
1541 if (tmp
== 0x00 || tmp
== 0xff)
1543 printf("%s: timeout waiting for BBP to wakeup\n",
1544 device_get_nameunit(sc
->dev
));
1548 for (i
= 0; i
< RT2860_DEF_BBP_SIZE
; i
++)
1549 rt2860_io_bbp_write(sc
, rt2860_def_bbp
[i
].reg
,
1550 rt2860_def_bbp
[i
].val
);
1552 if ((sc
->mac_rev
& 0xffff) != 0x0101)
1553 rt2860_io_bbp_write(sc
, 84, 0x19);
1559 * rt2860_stop_locked
1561 static void rt2860_stop_locked(void *priv
)
1563 struct rt2860_softc
*sc
;
1564 struct ieee80211com
*ic
;
1572 RT2860_DPRINTF(sc
, RT2860_DEBUG_ANY
,
1574 device_get_nameunit(sc
->dev
));
1576 RT2860_SOFTC_ASSERT_LOCKED(sc
);
1580 if (ifp
->if_drv_flags
& IFF_DRV_RUNNING
)
1581 rt2860_led_cmd(sc
, RT2860_LED_CMD_RADIO_OFF
);
1583 ifp
->if_drv_flags
&= ~(IFF_DRV_RUNNING
| IFF_DRV_OACTIVE
);
1585 ieee80211_new_state(ic
, IEEE80211_S_INIT
, -1);
1587 callout_stop(&sc
->periodic_ch
);
1588 callout_stop(&sc
->tx_watchdog_ch
);
1590 RT2860_SOFTC_UNLOCK(sc
);
1592 taskqueue_block(sc
->taskqueue
);
1594 taskqueue_drain(sc
->taskqueue
, &sc
->rx_done_task
);
1595 taskqueue_drain(sc
->taskqueue
, &sc
->tx_done_task
);
1596 taskqueue_drain(sc
->taskqueue
, &sc
->fifo_sta_full_task
);
1597 taskqueue_drain(sc
->taskqueue
, &sc
->periodic_task
);
1599 RT2860_SOFTC_LOCK(sc
);
1601 /* clear key tables */
1603 rt2860_asic_clear_keytables(sc
);
1605 /* disable interrupts */
1607 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_INT_MASK
, 0);
1611 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_SYS_CTRL
);
1613 tmp
&= ~(RT2860_REG_RX_ENABLE
| RT2860_REG_TX_ENABLE
);
1615 rt2860_io_mac_write(sc
, RT2860_REG_SYS_CTRL
, tmp
);
1619 rt2860_io_mac_write(sc
, RT2860_REG_SYS_CTRL
,
1620 RT2860_REG_MAC_SRST
| RT2860_REG_BBP_HRST
);
1621 rt2860_io_mac_write(sc
, RT2860_REG_SYS_CTRL
, 0);
1623 if (sc
->beacon_mbuf
!= NULL
)
1625 m_free(sc
->beacon_mbuf
);
1626 sc
->beacon_mbuf
= NULL
;
1633 static void rt2860_stop(void *priv
)
1635 struct rt2860_softc
*sc
;
1639 RT2860_SOFTC_LOCK(sc
);
1641 rt2860_stop_locked(sc
);
1643 RT2860_SOFTC_UNLOCK(sc
);
1649 static void rt2860_start(struct ifnet
*ifp
)
1651 struct rt2860_softc
*sc
;
1652 struct ieee80211com
*ic
;
1653 struct ieee80211_node
*ni
;
1654 struct ether_header
*eh
;
1661 RT2860_SOFTC_LOCK(sc
);
1663 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
1665 RT2860_SOFTC_UNLOCK(sc
);
1671 IF_POLL(&ic
->ic_mgtq
, m
);
1674 if (sc
->tx_ring
[sc
->tx_ring_mgtqid
].data_queued
>= RT2860_SOFTC_TX_RING_DATA_COUNT
)
1676 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
1677 "%s: if_start: Tx ring with qid=%d is full\n",
1678 device_get_nameunit(sc
->dev
), sc
->tx_ring_mgtqid
);
1680 ifp
->if_drv_flags
|= IFF_DRV_OACTIVE
;
1682 sc
->tx_data_queue_full
[sc
->tx_ring_mgtqid
]++;
1687 IF_DEQUEUE(&ic
->ic_mgtq
, m
);
1689 ni
= (struct ieee80211_node
*) m
->m_pkthdr
.rcvif
;
1690 m
->m_pkthdr
.rcvif
= NULL
;
1692 if (bpf_peers_present(ic
->ic_rawbpf
))
1693 bpf_mtap(ic
->ic_rawbpf
, m
);
1695 if (rt2860_tx_frame(sc
, m
, ni
, sc
->tx_ring_mgtqid
) != 0)
1698 rt2860_drain_fifo_stats(sc
);
1702 if (ic
->ic_state
!= IEEE80211_S_RUN
)
1705 IF_POLL(&ifp
->if_snd
, m
);
1709 IFQ_DRV_DEQUEUE(&ifp
->if_snd
, m
);
1711 if (ic
->ic_flags
& IEEE80211_F_SCAN
)
1712 ieee80211_cancel_scan(ic
);
1714 if (m
->m_len
< sizeof(struct ether_header
) &&
1715 !(m
= m_pullup(m
, sizeof (struct ether_header
))))
1718 eh
= mtod(m
, struct ether_header
*);
1720 ni
= ieee80211_find_txnode(ic
, eh
->ether_dhost
);
1723 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
1724 "%s: if_start: could not find Tx node\n",
1725 device_get_nameunit(sc
->dev
));
1731 ieee80211_classify(ic
, m
, ni
);
1733 qid
= M_WME_GETAC(m
);
1735 if (sc
->tx_ring
[qid
].data_queued
>= RT2860_SOFTC_TX_RING_DATA_COUNT
)
1737 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
1738 "%s: if_start: Tx ring with qid=%d is full\n",
1739 device_get_nameunit(sc
->dev
), qid
);
1742 ieee80211_free_node(ni
);
1744 ifp
->if_drv_flags
|= IFF_DRV_OACTIVE
;
1747 sc
->tx_data_queue_full
[qid
]++;
1754 m
= ieee80211_encap(ic
, m
, ni
);
1757 ieee80211_free_node(ni
);
1762 if (bpf_peers_present(ic
->ic_rawbpf
))
1763 bpf_mtap(ic
->ic_rawbpf
, m
);
1765 if (rt2860_tx_frame(sc
, m
, ni
, qid
) != 0)
1767 ieee80211_free_node(ni
);
1774 rt2860_drain_fifo_stats(sc
);
1777 sc
->tx_timer
= RT2860_TX_WATCHDOG_TIMEOUT
;
1779 ic
->ic_lastdata
= ticks
;
1781 callout_reset(&sc
->tx_watchdog_ch
, hz
, rt2860_tx_watchdog
, sc
);
1784 RT2860_SOFTC_UNLOCK(sc
);
1790 static int rt2860_ioctl(struct ifnet
*ifp
, u_long cmd
, caddr_t data
)
1792 struct rt2860_softc
*sc
;
1793 struct ieee80211com
*ic
;
1804 RT2860_SOFTC_LOCK(sc
);
1806 if (ifp
->if_flags
& IFF_UP
)
1808 if (ifp
->if_drv_flags
& IFF_DRV_RUNNING
)
1810 if ((ifp
->if_flags
^ sc
->if_flags
) & IFF_PROMISC
)
1811 rt2860_asic_update_promisc(sc
);
1815 rt2860_init_locked(sc
);
1820 if (ifp
->if_drv_flags
& IFF_DRV_RUNNING
)
1821 rt2860_stop_locked(sc
);
1824 sc
->if_flags
= ifp
->if_flags
;
1826 RT2860_SOFTC_UNLOCK(sc
);
1830 error
= ieee80211_ioctl(ic
, cmd
, data
);
1833 if (error
== ENETRESET
)
1835 RT2860_SOFTC_LOCK(sc
);
1837 if ((ifp
->if_flags
& IFF_UP
) &&
1838 (ifp
->if_drv_flags
& IFF_DRV_RUNNING
) &&
1839 (ic
->ic_roaming
!= IEEE80211_ROAMING_MANUAL
))
1841 rt2860_stop_locked(sc
);
1842 rt2860_init_locked(sc
);
1845 RT2860_SOFTC_UNLOCK(sc
);
1856 static int rt2860_reset(struct ifnet
*ifp
)
1858 struct rt2860_softc
*sc
;
1859 struct ieee80211com
*ic
;
1864 if (ic
->ic_opmode
!= IEEE80211_M_MONITOR
)
1867 rt2860_rf_set_chan(sc
, ic
->ic_curchan
);
1875 static int rt2860_newstate(struct ieee80211com
*ic
,
1876 enum ieee80211_state nstate
, int arg
)
1878 struct rt2860_softc
*sc
;
1880 struct ieee80211_node
*ni
;
1886 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATE
,
1887 "%s: newstate: %s -> %s\n",
1888 device_get_nameunit(sc
->dev
),
1889 ieee80211_state_name
[ic
->ic_state
], ieee80211_state_name
[nstate
]);
1891 error
= sc
->newstate(ic
, nstate
, arg
);
1895 RT2860_SOFTC_LOCK(sc
);
1897 /* turn link LED off */
1899 if (nstate
!= IEEE80211_S_RUN
)
1900 rt2860_led_cmd(sc
, RT2860_LED_CMD_RADIO_OFF
);
1904 case IEEE80211_S_INIT
:
1905 rt2860_asic_disable_tsf_sync(sc
);
1908 case IEEE80211_S_RUN
:
1911 if (ic
->ic_opmode
!= IEEE80211_M_MONITOR
)
1912 rt2860_rf_set_chan(sc
, ni
->ni_chan
);
1914 if (ic
->ic_opmode
!= IEEE80211_M_MONITOR
)
1916 rt2860_asic_enable_mrr(sc
);
1917 rt2860_asic_set_txpreamble(sc
);
1918 rt2860_asic_set_basicrates(sc
);
1919 rt2860_asic_update_txpower(sc
);
1920 rt2860_asic_set_bssid(sc
, ni
->ni_bssid
);
1923 if (ic
->ic_opmode
== IEEE80211_M_STA
)
1924 rt2860_newassoc(ni
, 1);
1926 if (ic
->ic_opmode
== IEEE80211_M_HOSTAP
||
1927 ic
->ic_opmode
== IEEE80211_M_IBSS
)
1929 error
= rt2860_beacon_alloc(sc
);
1933 rt2860_asic_update_beacon(sc
);
1936 if (ic
->ic_opmode
!= IEEE80211_M_MONITOR
)
1937 rt2860_asic_enable_tsf_sync(sc
);
1939 /* turn link LED on */
1941 if (ic
->ic_opmode
!= IEEE80211_M_MONITOR
)
1943 rt2860_led_cmd(sc
, RT2860_LED_CMD_RADIO_ON
|
1944 (IEEE80211_IS_CHAN_2GHZ(ni
->ni_chan
) ?
1945 RT2860_LED_CMD_LINK_2GHZ
: RT2860_LED_CMD_LINK_5GHZ
));
1949 case IEEE80211_S_SLEEP
:
1956 RT2860_SOFTC_UNLOCK(sc
);
1964 static void rt2860_scan_start(struct ieee80211com
*ic
)
1966 struct rt2860_softc
*sc
;
1972 rt2860_asic_disable_tsf_sync(sc
);
1978 static void rt2860_scan_end(struct ieee80211com
*ic
)
1980 struct rt2860_softc
*sc
;
1986 rt2860_asic_enable_tsf_sync(sc
);
1990 * rt2860_set_channel
1992 static void rt2860_set_channel(struct ieee80211com
*ic
)
1994 struct rt2860_softc
*sc
;
2000 RT2860_DPRINTF(sc
, RT2860_DEBUG_CHAN
,
2001 "%s: set channel: channel=%u, HT%s%s\n",
2002 device_get_nameunit(sc
->dev
),
2003 ieee80211_chan2ieee(ic
, ic
->ic_curchan
),
2004 !IEEE80211_IS_CHAN_HT(ic
->ic_curchan
) ? " disabled" :
2005 IEEE80211_IS_CHAN_HT20(ic
->ic_curchan
) ? "20":
2006 IEEE80211_IS_CHAN_HT40U(ic
->ic_curchan
) ? "40U" : "40D",
2007 (ic
->ic_flags
& IEEE80211_F_SCAN
) ? ", scanning" : "");
2009 RT2860_SOFTC_LOCK(sc
);
2011 rt2860_rf_set_chan(sc
, ic
->ic_curchan
);
2013 RT2860_SOFTC_UNLOCK(sc
);
2019 static void rt2860_newassoc(struct ieee80211_node
*ni
, int isnew
)
2021 struct rt2860_softc
*sc
;
2022 struct ieee80211com
*ic
;
2024 struct rt2860_softc_node
*rni
;
2031 rni
= (struct rt2860_softc_node
*) ni
;
2035 aid
= IEEE80211_AID(ni
->ni_associd
);
2036 rni
->staid
= rt2860_staid_alloc(sc
, aid
);
2039 rt2860_io_mac_write_multi(sc
, RT2860_REG_WCID(wcid
),
2040 ni
->ni_macaddr
, IEEE80211_ADDR_LEN
);
2042 rt2860_amrr_node_init(&sc
->amrr
, &sc
->amrr_node
[wcid
], ni
);
2044 RT2860_DPRINTF(sc
, RT2860_DEBUG_RATE
,
2045 "%s: initial%s node Tx rate: associd=0x%04x, rate=0x%02x, max rate=0x%02x\n",
2046 device_get_nameunit(sc
->dev
),
2047 (ni
->ni_flags
& IEEE80211_NODE_HT
) ? " HT" : "",
2049 (ni
->ni_flags
& IEEE80211_NODE_HT
) ?
2050 (ni
->ni_htrates
.rs_rates
[ni
->ni_txrate
] | IEEE80211_RATE_MCS
) :
2051 (ni
->ni_rates
.rs_rates
[ni
->ni_txrate
] & IEEE80211_RATE_VAL
),
2052 (ni
->ni_flags
& IEEE80211_NODE_HT
) ?
2053 (ni
->ni_htrates
.rs_rates
[ni
->ni_htrates
.rs_nrates
- 1] | IEEE80211_RATE_MCS
) :
2054 (ni
->ni_rates
.rs_rates
[ni
->ni_rates
.rs_nrates
- 1] & IEEE80211_RATE_VAL
));
2056 rt2860_asic_updateprot(sc
);
2057 rt2860_asic_updateslot(sc
);
2058 rt2860_asic_set_txpreamble(sc
);
2061 RT2860_DPRINTF(sc
, RT2860_DEBUG_NODE
,
2062 "%s: new association: isnew=%d, macaddr=%s, associd=0x%04x, staid=0x%02x, QoS %s, ERP %s, HT %s\n",
2063 device_get_nameunit(sc
->dev
), isnew
, ether_sprintf(ni
->ni_macaddr
),
2064 ni
->ni_associd
, rni
->staid
,
2065 (ni
->ni_flags
& IEEE80211_NODE_QOS
) ? "enabled" : "disabled",
2066 (ni
->ni_flags
& IEEE80211_NODE_ERP
) ? "enabled" : "disabled",
2067 (ni
->ni_flags
& IEEE80211_NODE_HT
) ? "enabled" : "disabled");
2074 static void rt2860_updateslot(struct ifnet
*ifp
)
2076 struct rt2860_softc
*sc
;
2080 rt2860_asic_updateslot(sc
);
2086 static int rt2860_wme_update(struct ieee80211com
*ic
)
2088 struct rt2860_softc
*sc
;
2094 rt2860_asic_wme_update(sc
);
2100 * rt2860_update_beacon
2102 static void rt2860_update_beacon(struct ieee80211com
*ic
, int what
)
2104 struct rt2860_softc
*sc
;
2107 struct ieee80211_beacon_offsets
*bo
;
2111 m
= sc
->beacon_mbuf
;
2112 bo
= &sc
->beacon_offsets
;
2114 RT2860_DPRINTF(sc
, RT2860_DEBUG_BEACON
,
2115 "%s: update beacon: what=%d\n",
2116 device_get_nameunit(sc
->dev
), what
);
2118 setbit(bo
->bo_flags
, what
);
2120 ieee80211_beacon_update(ic
->ic_bss
, bo
, m
, 0);
2122 rt2860_asic_update_beacon(sc
);
2126 * rt2860_key_update_begin
2128 static void rt2860_key_update_begin(struct ieee80211com
*ic
)
2130 struct rt2860_softc
*sc
;
2136 RT2860_DPRINTF(sc
, RT2860_DEBUG_KEY
,
2137 "%s: key update begin\n",
2138 device_get_nameunit(sc
->dev
));
2140 taskqueue_block(sc
->taskqueue
);
2142 IF_LOCK(&ifp
->if_snd
);
2146 * rt2860_key_update_end
2148 static void rt2860_key_update_end(struct ieee80211com
*ic
)
2150 struct rt2860_softc
*sc
;
2156 RT2860_DPRINTF(sc
, RT2860_DEBUG_KEY
,
2157 "%s: key update end\n",
2158 device_get_nameunit(sc
->dev
));
2160 IF_UNLOCK(&ifp
->if_snd
);
2162 taskqueue_unblock(sc
->taskqueue
);
2168 static int rt2860_key_set(struct ieee80211com
*ic
,
2169 const struct ieee80211_key
*k
, const uint8_t mac
[IEEE80211_ADDR_LEN
])
2171 struct rt2860_softc
*sc
;
2173 struct ieee80211_node
*ni
;
2174 struct rt2860_softc_node
*rni
;
2175 uint16_t key_base
, keymode_base
;
2176 uint8_t mode
, vapid
, wcid
, iv
[8];
2179 if (k
->wk_cipher
->ic_cipher
!= IEEE80211_CIPHER_WEP
&&
2180 k
->wk_cipher
->ic_cipher
!= IEEE80211_CIPHER_TKIP
&&
2181 k
->wk_cipher
->ic_cipher
!= IEEE80211_CIPHER_AES_CCM
)
2187 switch (k
->wk_cipher
->ic_cipher
)
2189 case IEEE80211_CIPHER_WEP
:
2190 if(k
->wk_keylen
< 8)
2191 mode
= RT2860_REG_CIPHER_MODE_WEP40
;
2193 mode
= RT2860_REG_CIPHER_MODE_WEP104
;
2196 case IEEE80211_CIPHER_TKIP
:
2197 mode
= RT2860_REG_CIPHER_MODE_TKIP
;
2200 case IEEE80211_CIPHER_AES_CCM
:
2201 mode
= RT2860_REG_CIPHER_MODE_AES_CCMP
;
2208 RT2860_DPRINTF(sc
, RT2860_DEBUG_KEY
,
2209 "%s: set key: keyix=%d, keylen=%d, macaddr=%s, mode=%d, group=%d\n",
2210 device_get_nameunit(sc
->dev
), k
->wk_keyix
, k
->wk_keylen
, ether_sprintf(mac
),
2211 mode
, (k
->wk_flags
& IEEE80211_KEY_GROUP
) ? 1 : 0);
2213 if (!(k
->wk_flags
& IEEE80211_KEY_GROUP
))
2215 /* install pairwise key */
2217 ni
= ieee80211_find_node(&ic
->ic_sta
, mac
);
2218 rni
= (struct rt2860_softc_node
*) ni
;
2222 key_base
= RT2860_REG_PKEY(wcid
);
2224 ieee80211_free_node(ni
);
2226 if (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_WEP
)
2230 iv
[3] = (k
->wk_keyix
<< 6);
2234 if (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_TKIP
)
2236 iv
[0] = (k
->wk_keytsc
>> 8);
2237 iv
[1] = ((iv
[0] | 0x20) & 0x7f);
2238 iv
[2] = k
->wk_keytsc
;
2244 iv
[0] = k
->wk_keytsc
;
2245 iv
[1] = k
->wk_keytsc
>> 8;
2249 iv
[3] = ((k
->wk_keyix
<< 6) | IEEE80211_WEP_EXTIV
);
2250 iv
[4] = (k
->wk_keytsc
>> 16);
2251 iv
[5] = (k
->wk_keytsc
>> 24);
2252 iv
[6] = (k
->wk_keytsc
>> 32);
2253 iv
[7] = (k
->wk_keytsc
>> 40);
2255 RT2860_DPRINTF(sc
, RT2860_DEBUG_KEY
,
2256 "%s: set key: iv=%02x %02x %02x %02x %02x %02x %02x %02x\n",
2257 device_get_nameunit(sc
->dev
),
2258 iv
[0], iv
[1], iv
[2], iv
[3], iv
[4], iv
[5], iv
[6], iv
[7]);
2261 rt2860_io_mac_write_multi(sc
, RT2860_REG_IVEIV(wcid
), iv
, 8);
2263 if (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_TKIP
)
2265 rt2860_io_mac_write_multi(sc
, key_base
, k
->wk_key
, 16);
2267 if (ic
->ic_opmode
!= IEEE80211_M_HOSTAP
)
2269 rt2860_io_mac_write_multi(sc
, key_base
+ 16, &k
->wk_key
[16], 8);
2270 rt2860_io_mac_write_multi(sc
, key_base
+ 24, &k
->wk_key
[24], 8);
2274 rt2860_io_mac_write_multi(sc
, key_base
+ 16, &k
->wk_key
[24], 8);
2275 rt2860_io_mac_write_multi(sc
, key_base
+ 24, &k
->wk_key
[16], 8);
2280 rt2860_io_mac_write_multi(sc
, key_base
, k
->wk_key
, k
->wk_keylen
);
2283 tmp
= ((vapid
& RT2860_REG_VAP_MASK
) << RT2860_REG_VAP_SHIFT
) |
2284 (mode
<< RT2860_REG_CIPHER_MODE_SHIFT
) | RT2860_REG_PKEY_ENABLE
;
2286 rt2860_io_mac_write(sc
, RT2860_REG_WCID_ATTR(wcid
), tmp
);
2289 if ((k
->wk_flags
& IEEE80211_KEY_GROUP
) ||
2290 (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_WEP
))
2292 /* install group key */
2295 wcid
= RT2860_WCID_MCAST
;
2296 key_base
= RT2860_REG_SKEY(vapid
, k
->wk_keyix
);
2297 keymode_base
= RT2860_REG_SKEY_MODE(vapid
);
2299 if (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_TKIP
)
2301 rt2860_io_mac_write_multi(sc
, key_base
, k
->wk_key
, 16);
2303 if (ic
->ic_opmode
!= IEEE80211_M_HOSTAP
)
2305 rt2860_io_mac_write_multi(sc
, key_base
+ 16, &k
->wk_key
[16], 8);
2306 rt2860_io_mac_write_multi(sc
, key_base
+ 24, &k
->wk_key
[24], 8);
2310 rt2860_io_mac_write_multi(sc
, key_base
+ 16, &k
->wk_key
[24], 8);
2311 rt2860_io_mac_write_multi(sc
, key_base
+ 24, &k
->wk_key
[16], 8);
2316 rt2860_io_mac_write_multi(sc
, key_base
, k
->wk_key
, k
->wk_keylen
);
2319 tmp
= rt2860_io_mac_read(sc
, keymode_base
);
2321 tmp
&= ~(0xf << (k
->wk_keyix
* 4 + 16 * (vapid
% 2)));
2322 tmp
|= (mode
<< (k
->wk_keyix
* 4 + 16 * (vapid
% 2)));
2324 rt2860_io_mac_write(sc
, keymode_base
, tmp
);
2326 if (ic
->ic_opmode
== IEEE80211_M_HOSTAP
)
2328 if (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_WEP
)
2332 iv
[3] = (k
->wk_keyix
<< 6);
2336 if (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_TKIP
)
2338 iv
[0] = (k
->wk_keytsc
>> 8);
2339 iv
[1] = ((iv
[0] | 0x20) & 0x7f);
2340 iv
[2] = k
->wk_keytsc
;
2346 iv
[0] = k
->wk_keytsc
;
2347 iv
[1] = k
->wk_keytsc
>> 8;
2351 iv
[3] = ((k
->wk_keyix
<< 6) | IEEE80211_WEP_EXTIV
);
2352 iv
[4] = (k
->wk_keytsc
>> 16);
2353 iv
[5] = (k
->wk_keytsc
>> 24);
2354 iv
[6] = (k
->wk_keytsc
>> 32);
2355 iv
[7] = (k
->wk_keytsc
>> 40);
2357 RT2860_DPRINTF(sc
, RT2860_DEBUG_KEY
,
2358 "%s: set key: iv=%02x %02x %02x %02x %02x %02x %02x %02x\n",
2359 device_get_nameunit(sc
->dev
),
2360 iv
[0], iv
[1], iv
[2], iv
[3], iv
[4], iv
[5], iv
[6], iv
[7]);
2363 rt2860_io_mac_write_multi(sc
, RT2860_REG_IVEIV(wcid
), iv
, 8);
2365 tmp
= ((vapid
& RT2860_REG_VAP_MASK
) << RT2860_REG_VAP_SHIFT
) |
2366 (mode
<< RT2860_REG_CIPHER_MODE_SHIFT
);
2368 rt2860_io_mac_write(sc
, RT2860_REG_WCID_ATTR(wcid
), tmp
);
2378 static int rt2860_key_delete(struct ieee80211com
*ic
,
2379 const struct ieee80211_key
*k
)
2381 struct rt2860_softc
*sc
;
2382 uint8_t vapid
, wcid
;
2385 sc
= ic
->ic_ifp
->if_softc
;
2387 RT2860_DPRINTF(sc
, RT2860_DEBUG_KEY
,
2388 "%s: delete key: keyix=%d, keylen=%d, group=%d\n",
2389 device_get_nameunit(sc
->dev
), k
->wk_keyix
, k
->wk_keylen
,
2390 (k
->wk_flags
& IEEE80211_KEY_GROUP
) ? 1 : 0);
2392 if (k
->wk_flags
& IEEE80211_KEY_GROUP
)
2394 /* remove group key */
2397 wcid
= RT2860_WCID_MCAST
;
2399 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_SKEY_MODE(vapid
));
2401 tmp
&= ~(0xf << (k
->wk_keyix
* 4 + 16 * (vapid
% 2)));
2402 tmp
|= (RT2860_REG_CIPHER_MODE_NONE
<< (k
->wk_keyix
* 4 + 16 * (vapid
% 2)));
2404 rt2860_io_mac_write(sc
, RT2860_REG_SKEY_MODE(vapid
), tmp
);
2406 if (ic
->ic_opmode
== IEEE80211_M_HOSTAP
)
2408 tmp
= ((vapid
& RT2860_REG_VAP_MASK
) << RT2860_REG_VAP_SHIFT
) |
2409 (RT2860_REG_CIPHER_MODE_NONE
<< RT2860_REG_CIPHER_MODE_SHIFT
) | RT2860_REG_PKEY_ENABLE
;
2411 rt2860_io_mac_write(sc
, RT2860_REG_WCID_ATTR(wcid
), tmp
);
2421 static int rt2860_raw_xmit(struct ieee80211_node
*ni
, struct mbuf
*m
,
2422 const struct ieee80211_bpf_params
*params
)
2428 * rt2860_media_change
2430 static int rt2860_media_change(struct ifnet
*ifp
)
2432 struct rt2860_softc
*sc
;
2437 error
= ieee80211_media_change(ifp
);
2438 if (error
!= ENETRESET
)
2441 RT2860_SOFTC_LOCK(sc
);
2443 if ((ifp
->if_flags
& IFF_UP
) && (ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
2445 rt2860_stop_locked(sc
);
2446 rt2860_init_locked(sc
);
2449 RT2860_SOFTC_UNLOCK(sc
);
2457 static struct ieee80211_node
*rt2860_node_alloc(struct ieee80211_node_table
*nt
)
2459 return malloc(sizeof(struct rt2860_softc_node
),
2460 M_80211_NODE
, M_NOWAIT
| M_ZERO
);
2464 * rt2860_node_cleanup
2466 static void rt2860_node_cleanup(struct ieee80211_node
*ni
)
2468 struct rt2860_softc
*sc
;
2469 struct ieee80211com
*ic
;
2471 struct rt2860_softc_node
*rni
;
2472 uint8_t vapid
, wcid
;
2478 rni
= (struct rt2860_softc_node
*) ni
;
2480 RT2860_DPRINTF(sc
, RT2860_DEBUG_NODE
,
2481 "%s: node cleanup: macaddr=%s, associd=0x%04x, staid=0x%02x\n",
2482 device_get_nameunit(sc
->dev
), ni
->ni_macaddr
, ni
->ni_associd
, rni
->staid
);
2484 if (rni
->staid
!= 0)
2489 tmp
= ((vapid
& RT2860_REG_VAP_MASK
) << RT2860_REG_VAP_SHIFT
) |
2490 (RT2860_REG_CIPHER_MODE_NONE
<< RT2860_REG_CIPHER_MODE_SHIFT
) | RT2860_REG_PKEY_ENABLE
;
2492 rt2860_io_mac_write(sc
, RT2860_REG_WCID_ATTR(wcid
), tmp
);
2494 rt2860_staid_delete(sc
, rni
->staid
);
2499 sc
->node_cleanup(ni
);
2503 * rt2860_recv_action
2505 static void rt2860_recv_action(struct ieee80211_node
*ni
,
2506 const uint8_t *frm
, const uint8_t *efrm
)
2508 struct rt2860_softc
*sc
;
2509 struct ieee80211com
*ic
;
2511 struct rt2860_softc_node
*rni
;
2512 const struct ieee80211_action
*ia
;
2513 struct ieee80211_tx_ampdu
*tx_ampdu
;
2514 uint16_t status
, baparamset
;
2516 int tid
, bufsize
, ac
;
2522 rni
= (struct rt2860_softc_node
*) ni
;
2524 ia
= (const struct ieee80211_action
*) frm
;
2526 sc
->recv_action(ni
, frm
, efrm
);
2528 if (ia
->ia_category
!= IEEE80211_ACTION_CAT_BA
)
2533 switch (ia
->ia_action
)
2535 /* IEEE80211_ACTION_BA_ADDBA_REQUEST */
2536 case IEEE80211_ACTION_BA_ADDBA_REQUEST
:
2537 baparamset
= LE_READ_2(frm
+ 3);
2538 tid
= RT2860_MS(baparamset
, IEEE80211_BAPS_TID
);
2539 bufsize
= RT2860_MS(baparamset
, IEEE80211_BAPS_BUFSIZ
);
2541 RT2860_DPRINTF(sc
, RT2860_DEBUG_BA
,
2542 "%s: received ADDBA request: associd=0x%04x, tid=%d, bufsize=%d\n",
2543 device_get_nameunit(sc
->dev
), ni
->ni_associd
, tid
, bufsize
);
2545 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_WCID(wcid
) + 4);
2547 tmp
|= (0x10000 << tid
);
2549 rt2860_io_mac_write(sc
, RT2860_REG_WCID(wcid
) + 4, tmp
);
2552 /* IEEE80211_ACTION_BA_ADDBA_RESPONSE */
2553 case IEEE80211_ACTION_BA_ADDBA_RESPONSE
:
2554 status
= LE_READ_2(frm
+ 3);
2555 baparamset
= LE_READ_2(frm
+ 4);
2556 tid
= RT2860_MS(baparamset
, IEEE80211_BAPS_TID
);
2557 bufsize
= RT2860_MS(baparamset
, IEEE80211_BAPS_BUFSIZ
);
2558 ac
= TID_TO_WME_AC(tid
);
2559 tx_ampdu
= &ni
->ni_tx_ampdu
[ac
];
2561 RT2860_DPRINTF(sc
, RT2860_DEBUG_BA
,
2562 "%s: received ADDBA response: associd=0x%04x, status=%d, tid=%d, bufsize=%d\n",
2563 device_get_nameunit(sc
->dev
), ni
->ni_associd
, status
, tid
, bufsize
);
2565 if (sc
->mac_rev
>= 0x28720200)
2567 if (tx_ampdu
->txa_wnd
> 13)
2568 tx_ampdu
->txa_wnd
= 13;
2572 if (tx_ampdu
->txa_wnd
> 7)
2573 tx_ampdu
->txa_wnd
= 7;
2576 if (status
== IEEE80211_STATUS_SUCCESS
)
2578 sc
->tx_ampdu_sessions
++;
2580 rt2860_asic_updateprot(sc
);
2584 /* IEEE80211_ACTION_BA_DELBA */
2585 case IEEE80211_ACTION_BA_DELBA
:
2586 baparamset
= LE_READ_2(frm
+ 2);
2587 tid
= RT2860_MS(baparamset
, IEEE80211_BAPS_TID
);
2589 RT2860_DPRINTF(sc
, RT2860_DEBUG_BA
,
2590 "%s: received DELBA request: associd=0x%04x, tid=%d\n",
2591 device_get_nameunit(sc
->dev
), ni
->ni_associd
, tid
);
2593 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_WCID(wcid
) + 4);
2595 tmp
&= ~(0x10000 << tid
);
2597 rt2860_io_mac_write(sc
, RT2860_REG_WCID(wcid
) + 4, tmp
);
2603 * rt2860_send_action
2605 static int rt2860_send_action(struct ieee80211_node
*ni
,
2606 int category
, int action
, uint16_t args
[4])
2608 struct rt2860_softc
*sc
;
2609 struct ieee80211com
*ic
;
2611 struct rt2860_softc_node
*rni
;
2612 uint16_t baparamset
;
2620 rni
= (struct rt2860_softc_node
*) ni
;
2622 ret
= sc
->send_action(ni
, category
, action
, args
);
2624 if (category
!= IEEE80211_ACTION_CAT_BA
)
2631 /* IEEE80211_ACTION_BA_DELBA */
2632 case IEEE80211_ACTION_BA_DELBA
:
2633 baparamset
= RT2860_SM(args
[0], IEEE80211_DELBAPS_TID
) | args
[1];
2635 tid
= RT2860_MS(baparamset
, IEEE80211_DELBAPS_TID
);
2637 RT2860_DPRINTF(sc
, RT2860_DEBUG_BA
,
2638 "%s: sending DELBA request: associd=0x%04x, tid=%d\n",
2639 device_get_nameunit(sc
->dev
), ni
->ni_associd
, tid
);
2641 if (RT2860_MS(baparamset
, IEEE80211_DELBAPS_INIT
) != IEEE80211_DELBAPS_INIT
)
2643 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_WCID(wcid
) + 4);
2645 tmp
&= ~(0x10000 << tid
);
2647 rt2860_io_mac_write(sc
, RT2860_REG_WCID(wcid
) + 4, tmp
);
2651 sc
->tx_ampdu_sessions
--;
2653 rt2860_asic_updateprot(sc
);
2662 * rt2860_amrr_update_iter_func
2664 static void rt2860_amrr_update_iter_func(void *arg
, struct ieee80211_node
*ni
)
2666 struct rt2860_softc
*sc
;
2667 struct ieee80211com
*ic
;
2668 struct rt2860_softc_node
*rni
;
2673 rni
= (struct rt2860_softc_node
*) ni
;
2675 /* only associated stations */
2677 if (rni
->staid
!= 0)
2681 RT2860_DPRINTF(sc
, RT2860_DEBUG_RATE
,
2682 "%s: AMRR node: staid=0x%02x, txcnt=%d, success=%d, retrycnt=%d\n",
2683 device_get_nameunit(sc
->dev
),
2684 rni
->staid
, sc
->amrr_node
[wcid
].txcnt
, sc
->amrr_node
[wcid
].success
, sc
->amrr_node
[wcid
].retrycnt
);
2686 rt2860_amrr_choose(ni
, &sc
->amrr_node
[wcid
]);
2688 RT2860_DPRINTF(sc
, RT2860_DEBUG_RATE
,
2689 "%s:%s node Tx rate: associd=0x%04x, staid=0x%02x, rate=0x%02x, max rate=0x%02x\n",
2690 device_get_nameunit(sc
->dev
),
2691 (ni
->ni_flags
& IEEE80211_NODE_HT
) ? " HT" : "",
2692 ni
->ni_associd
, rni
->staid
,
2693 (ni
->ni_flags
& IEEE80211_NODE_HT
) ?
2694 (ni
->ni_htrates
.rs_rates
[ni
->ni_txrate
] | IEEE80211_RATE_MCS
) :
2695 (ni
->ni_rates
.rs_rates
[ni
->ni_txrate
] & IEEE80211_RATE_VAL
),
2696 (ni
->ni_flags
& IEEE80211_NODE_HT
) ?
2697 (ni
->ni_htrates
.rs_rates
[ni
->ni_htrates
.rs_nrates
- 1] | IEEE80211_RATE_MCS
) :
2698 (ni
->ni_rates
.rs_rates
[ni
->ni_rates
.rs_nrates
- 1] & IEEE80211_RATE_VAL
));
2705 static void rt2860_periodic(void *arg
)
2707 struct rt2860_softc
*sc
;
2711 RT2860_DPRINTF(sc
, RT2860_DEBUG_PERIODIC
,
2713 device_get_nameunit(sc
->dev
));
2715 taskqueue_enqueue(sc
->taskqueue
, &sc
->periodic_task
);
2719 * rt2860_tx_watchdog
2721 static void rt2860_tx_watchdog(void *arg
)
2723 struct rt2860_softc
*sc
;
2729 if (sc
->tx_timer
== 0)
2732 if (--sc
->tx_timer
== 0)
2734 printf("%s: Tx watchdog timeout: resetting\n",
2735 device_get_nameunit(sc
->dev
));
2737 rt2860_stop_locked(sc
);
2738 rt2860_init_locked(sc
);
2742 sc
->tx_watchdog_timeouts
++;
2745 callout_reset(&sc
->tx_watchdog_ch
, hz
, rt2860_tx_watchdog
, sc
);
2749 * rt2860_staid_alloc
2751 static int rt2860_staid_alloc(struct rt2860_softc
*sc
, int aid
)
2755 if ((aid
> 0 && aid
< RT2860_SOFTC_STAID_COUNT
) && isclr(sc
->staid_mask
, aid
))
2761 for (staid
= 1; staid
< RT2860_SOFTC_STAID_COUNT
; staid
++)
2763 if (isclr(sc
->staid_mask
, staid
))
2768 setbit(sc
->staid_mask
, staid
);
2774 * rt2860_staid_delete
2776 static void rt2860_staid_delete(struct rt2860_softc
*sc
, int staid
)
2778 clrbit(sc
->staid_mask
, staid
);
2782 * rt2860_asic_set_bssid
2784 static void rt2860_asic_set_bssid(struct rt2860_softc
*sc
,
2785 const uint8_t *bssid
)
2789 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATE
,
2790 "%s: set bssid: bssid=%s\n",
2791 device_get_nameunit(sc
->dev
), ether_sprintf(bssid
));
2793 tmp
= bssid
[0] | (bssid
[1]) << 8 | (bssid
[2] << 16) | (bssid
[3] << 24);
2795 rt2860_io_mac_write(sc
, RT2860_REG_BSSID_DW0
, tmp
);
2797 tmp
= bssid
[4] | (bssid
[5] << 8);
2799 rt2860_io_mac_write(sc
, RT2860_REG_BSSID_DW1
, tmp
);
2803 * rt2860_asic_set_macaddr
2805 static void rt2860_asic_set_macaddr(struct rt2860_softc
*sc
,
2806 const uint8_t *addr
)
2810 tmp
= addr
[0] | (addr
[1] << 8) | (addr
[2] << 16) | (addr
[3] << 24);
2812 rt2860_io_mac_write(sc
, RT2860_REG_ADDR_DW0
, tmp
);
2814 tmp
= addr
[4] | (addr
[5] << 8);
2816 rt2860_io_mac_write(sc
, RT2860_REG_ADDR_DW1
, tmp
);
2820 * rt2860_asic_enable_tsf_sync
2822 static void rt2860_asic_enable_tsf_sync(struct rt2860_softc
*sc
)
2824 struct ieee80211com
*ic
;
2829 RT2860_DPRINTF(sc
, RT2860_DEBUG_BEACON
,
2830 "%s: enabling TSF\n",
2831 device_get_nameunit(sc
->dev
));
2833 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_BCN_TIME_CFG
);
2836 tmp
|= ic
->ic_bss
->ni_intval
* 16;
2837 tmp
|= (RT2860_REG_TSF_TIMER_ENABLE
| RT2860_REG_TBTT_TIMER_ENABLE
);
2839 if (ic
->ic_opmode
== IEEE80211_M_STA
)
2841 tmp
|= (RT2860_REG_TSF_SYNC_MODE_STA
<< RT2860_REG_TSF_SYNC_MODE_SHIFT
);
2843 else if (ic
->ic_opmode
== IEEE80211_M_IBSS
)
2845 tmp
|= RT2860_REG_BCN_TX_ENABLE
;
2846 tmp
|= (RT2860_REG_TSF_SYNC_MODE_IBSS
<< RT2860_REG_TSF_SYNC_MODE_SHIFT
);
2848 else if (ic
->ic_opmode
== IEEE80211_M_HOSTAP
)
2850 tmp
|= RT2860_REG_BCN_TX_ENABLE
;
2851 tmp
|= (RT2860_REG_TSF_SYNC_MODE_HOSTAP
<< RT2860_REG_TSF_SYNC_MODE_SHIFT
);
2854 rt2860_io_mac_write(sc
, RT2860_REG_BCN_TIME_CFG
, tmp
);
2858 * rt2860_asic_disable_tsf_sync
2860 static void rt2860_asic_disable_tsf_sync(struct rt2860_softc
*sc
)
2864 RT2860_DPRINTF(sc
, RT2860_DEBUG_BEACON
,
2865 "%s: disabling TSF\n",
2866 device_get_nameunit(sc
->dev
));
2868 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_BCN_TIME_CFG
);
2870 tmp
&= ~(RT2860_REG_BCN_TX_ENABLE
|
2871 RT2860_REG_TSF_TIMER_ENABLE
|
2872 RT2860_REG_TBTT_TIMER_ENABLE
);
2874 tmp
&= ~(RT2860_REG_TSF_SYNC_MODE_MASK
<< RT2860_REG_TSF_SYNC_MODE_SHIFT
);
2875 tmp
|= (RT2860_REG_TSF_SYNC_MODE_DISABLE
<< RT2860_REG_TSF_SYNC_MODE_SHIFT
);
2877 rt2860_io_mac_write(sc
, RT2860_REG_BCN_TIME_CFG
, tmp
);
2881 * rt2860_asic_enable_mrr
2883 static void rt2860_asic_enable_mrr(struct rt2860_softc
*sc
)
2885 #define CCK(mcs) (mcs)
2886 #define OFDM(mcs) ((1 << 3) | (mcs))
2887 #define HT(mcs) (mcs)
2889 rt2860_io_mac_write(sc
, RT2860_REG_TX_LG_FBK_CFG0
,
2890 (OFDM(6) << 28) | /* 54 -> 48 */
2891 (OFDM(5) << 24) | /* 48 -> 36 */
2892 (OFDM(4) << 20) | /* 36 -> 24 */
2893 (OFDM(3) << 16) | /* 24 -> 18 */
2894 (OFDM(2) << 12) | /* 18 -> 12 */
2895 (OFDM(1) << 8) | /* 12 -> 9 */
2896 (OFDM(0) << 4) | /* 9 -> 6 */
2897 OFDM(0)); /* 6 -> 6 */
2899 rt2860_io_mac_write(sc
, RT2860_REG_TX_LG_FBK_CFG1
,
2900 (CCK(2) << 12) | /* 11 -> 5.5 */
2901 (CCK(1) << 8) | /* 5.5 -> 2 */
2902 (CCK(0) << 4) | /* 2 -> 1 */
2903 CCK(0)); /* 1 -> 1 */
2905 rt2860_io_mac_write(sc
, RT2860_REG_TX_HT_FBK_CFG0
,
2915 rt2860_io_mac_write(sc
, RT2860_REG_TX_HT_FBK_CFG1
,
2931 * rt2860_asic_set_txpreamble
2933 static void rt2860_asic_set_txpreamble(struct rt2860_softc
*sc
)
2935 struct ieee80211com
*ic
;
2940 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATE
,
2941 "%s: %s short Tx preamble\n",
2942 device_get_nameunit(sc
->dev
),
2943 (ic
->ic_flags
& IEEE80211_F_SHPREAMBLE
) ? "enabling" : "disabling");
2945 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_AUTO_RSP_CFG
);
2947 tmp
&= ~RT2860_REG_CCK_SHORT_ENABLE
;
2949 if (sc
->ic
.ic_flags
& IEEE80211_F_SHPREAMBLE
)
2950 tmp
|= RT2860_REG_CCK_SHORT_ENABLE
;
2952 rt2860_io_mac_write(sc
, RT2860_REG_AUTO_RSP_CFG
, tmp
);
2956 * rt2860_asic_set_basicrates
2958 static void rt2860_asic_set_basicrates(struct rt2860_softc
*sc
)
2960 struct ieee80211com
*ic
;
2964 if (ic
->ic_curmode
== IEEE80211_MODE_11B
)
2965 rt2860_io_mac_write(sc
, RT2860_REG_LEGACY_BASIC_RATE
, 0x3);
2966 else if (ic
->ic_curmode
== IEEE80211_MODE_11A
)
2967 rt2860_io_mac_write(sc
, RT2860_REG_LEGACY_BASIC_RATE
, 0x150);
2969 rt2860_io_mac_write(sc
, RT2860_REG_LEGACY_BASIC_RATE
, 0x15f);
2973 * rt2860_asic_update_rtsthreshold
2975 static void rt2860_asic_update_rtsthreshold(struct rt2860_softc
*sc
)
2977 struct ieee80211com
*ic
;
2983 RT2860_DPRINTF(sc
, RT2860_DEBUG_PROT
,
2984 "%s: updating RTS threshold: %d\n",
2985 device_get_nameunit(sc
->dev
), ic
->ic_rtsthreshold
);
2987 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_RTS_CFG
);
2989 tmp
&= ~(RT2860_REG_TX_RTS_THRESHOLD_MASK
<< RT2860_REG_TX_RTS_THRESHOLD_SHIFT
);
2991 if (ic
->ic_flags_ext
& IEEE80211_FEXT_AMSDU_TX
)
2994 threshold
= ic
->ic_rtsthreshold
;
2997 tmp
|= ((threshold
& RT2860_REG_TX_RTS_THRESHOLD_MASK
) <<
2998 RT2860_REG_TX_RTS_THRESHOLD_SHIFT
);
3000 rt2860_io_mac_write(sc
, RT2860_REG_TX_RTS_CFG
, tmp
);
3004 * rt2860_asic_update_txpower
3006 static void rt2860_asic_update_txpower(struct rt2860_softc
*sc
)
3008 struct ieee80211com
*ic
;
3009 uint32_t *txpow_rate
;
3017 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATE
,
3018 "%s: updating Tx power: %d\n",
3019 device_get_nameunit(sc
->dev
), ic
->ic_txpowlimit
);
3021 if (!IEEE80211_IS_CHAN_HT40(ic
->ic_curchan
))
3023 txpow_rate
= sc
->txpow_rate_20mhz
;
3027 if (IEEE80211_IS_CHAN_2GHZ(ic
->ic_curchan
))
3028 txpow_rate
= sc
->txpow_rate_40mhz_2ghz
;
3030 txpow_rate
= sc
->txpow_rate_40mhz_5ghz
;
3035 val
= rt2860_io_bbp_read(sc
, 1);
3038 if (ic
->ic_txpowlimit
> 90)
3042 else if (ic
->ic_txpowlimit
> 60)
3046 else if (ic
->ic_txpowlimit
> 30)
3050 else if (ic
->ic_txpowlimit
> 15)
3054 else if (ic
->ic_txpowlimit
> 9)
3064 rt2860_io_bbp_write(sc
, 1, val
);
3066 for (i
= 0; i
< RT2860_SOFTC_TXPOW_RATE_COUNT
; i
++)
3068 if (txpow_rate
[i
] == 0xffffffff)
3071 tmp
= rt2860_read_eeprom_txpow_rate_add_delta(txpow_rate
[i
], delta
);
3073 rt2860_io_mac_write(sc
, RT2860_REG_TX_PWR_CFG(i
), tmp
);
3078 * rt2860_asic_update_promisc
3080 static void rt2860_asic_update_promisc(struct rt2860_softc
*sc
)
3085 ifp
= sc
->ic
.ic_ifp
;
3087 printf("%s: %s promiscuous mode\n",
3088 device_get_nameunit(sc
->dev
),
3089 (ifp
->if_flags
& IFF_PROMISC
) ? "entering" : "leaving");
3091 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_RX_FILTER_CFG
);
3093 tmp
&= ~RT2860_REG_RX_FILTER_DROP_UC_NOME
;
3095 if (!(ifp
->if_flags
& IFF_PROMISC
))
3096 tmp
|= RT2860_REG_RX_FILTER_DROP_UC_NOME
;
3098 rt2860_io_mac_write(sc
, RT2860_REG_RX_FILTER_CFG
, tmp
);
3102 * rt2860_asic_updateprot
3104 static void rt2860_asic_updateprot(struct rt2860_softc
*sc
)
3106 struct ieee80211com
*ic
;
3107 uint32_t cck_prot
, ofdm_prot
, mm20_prot
, mm40_prot
, gf20_prot
, gf40_prot
;
3109 enum ieee80211_protmode htprotmode
;
3113 /* CCK frame protection */
3115 cck_prot
= RT2860_REG_RTSTH_ENABLE
| RT2860_REG_PROT_NAV_SHORT
|
3116 RT2860_REG_TXOP_ALLOW_ALL
| RT2860_REG_PROT_CTRL_NONE
;
3118 /* set up protection frame phy mode and rate (MCS code) */
3120 if (ic
->ic_curmode
== IEEE80211_MODE_11A
)
3121 cck_prot
|= (RT2860_REG_PROT_PHYMODE_OFDM
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3122 (0 << RT2860_REG_PROT_MCS_SHIFT
);
3124 cck_prot
|= ((RT2860_REG_PROT_PHYMODE_CCK
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3125 (3 << RT2860_REG_PROT_MCS_SHIFT
));
3127 rt2860_io_mac_write(sc
, RT2860_REG_TX_CCK_PROT_CFG
, cck_prot
);
3129 /* OFDM frame protection */
3131 ofdm_prot
= RT2860_REG_RTSTH_ENABLE
| RT2860_REG_PROT_NAV_SHORT
|
3132 RT2860_REG_TXOP_ALLOW_ALL
;
3134 if (ic
->ic_flags
& IEEE80211_F_USEPROT
)
3136 RT2860_DPRINTF(sc
, RT2860_DEBUG_PROT
,
3137 "%s: updating protection mode: b/g protection mode=%s\n",
3138 device_get_nameunit(sc
->dev
),
3139 (ic
->ic_protmode
== IEEE80211_PROT_RTSCTS
) ? "RTS/CTS" :
3140 ((ic
->ic_protmode
== IEEE80211_PROT_CTSONLY
) ? "CTS-to-self" : "none"));
3142 if (ic
->ic_protmode
== IEEE80211_PROT_RTSCTS
)
3143 ofdm_prot
|= RT2860_REG_PROT_CTRL_RTS_CTS
;
3144 else if (ic
->ic_protmode
== IEEE80211_PROT_CTSONLY
)
3145 ofdm_prot
|= RT2860_REG_PROT_CTRL_CTS
;
3147 ofdm_prot
|= RT2860_REG_PROT_CTRL_NONE
;
3151 RT2860_DPRINTF(sc
, RT2860_DEBUG_PROT
,
3152 "%s: updating protection mode: b/g protection mode=%s\n",
3153 device_get_nameunit(sc
->dev
), "none");
3155 ofdm_prot
|= RT2860_REG_PROT_CTRL_NONE
;
3158 rt2860_io_mac_write(sc
, RT2860_REG_TX_OFDM_PROT_CFG
, ofdm_prot
);
3160 /* HT frame protection */
3162 if ((ic
->ic_opmode
== IEEE80211_M_STA
) && (ic
->ic_state
== IEEE80211_S_RUN
))
3163 htopmode
= ic
->ic_bss
->ni_htopmode
;
3165 htopmode
= ic
->ic_curhtprotmode
;
3167 htprotmode
= ic
->ic_htprotmode
;
3169 /* force HT mixed mode and RTS/CTS protection if A-MPDU Tx aggregation is enabled */
3171 if (sc
->tx_ampdu_sessions
> 0)
3173 RT2860_DPRINTF(sc
, RT2860_DEBUG_PROT
,
3174 "%s: updating protection mode: forcing HT mixed mode and RTS/CTS protection\n",
3175 device_get_nameunit(sc
->dev
));
3177 htopmode
= IEEE80211_HTINFO_OPMODE_MIXED
;
3178 htprotmode
= IEEE80211_PROT_RTSCTS
;
3181 RT2860_DPRINTF(sc
, RT2860_DEBUG_PROT
,
3182 "%s: updating protection mode: HT operation mode=0x%02x, protection mode=%s\n",
3183 device_get_nameunit(sc
->dev
),
3184 htopmode
& IEEE80211_HTINFO_OPMODE
,
3185 (htprotmode
== IEEE80211_PROT_RTSCTS
) ? "RTS/CTS" :
3186 ((htprotmode
== IEEE80211_PROT_CTSONLY
) ? "CTS-to-self" : "none"));
3188 switch (htopmode
& IEEE80211_HTINFO_OPMODE
)
3190 /* IEEE80211_HTINFO_OPMODE_HT20PR */
3191 case IEEE80211_HTINFO_OPMODE_HT20PR
:
3192 mm20_prot
= RT2860_REG_PROT_NAV_SHORT
| RT2860_REG_PROT_CTRL_NONE
|
3193 RT2860_REG_TXOP_ALLOW_CCK
| RT2860_REG_TXOP_ALLOW_OFDM
|
3194 RT2860_REG_TXOP_ALLOW_MM20
| RT2860_REG_TXOP_ALLOW_GF20
|
3195 (RT2860_REG_PROT_PHYMODE_OFDM
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3196 (4 << RT2860_REG_PROT_MCS_SHIFT
);
3198 gf20_prot
= mm20_prot
;
3200 mm40_prot
= RT2860_REG_PROT_NAV_SHORT
| RT2860_REG_TXOP_ALLOW_ALL
|
3201 (RT2860_REG_PROT_PHYMODE_OFDM
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3202 (0x84 << RT2860_REG_PROT_MCS_SHIFT
);
3204 if (htprotmode
== IEEE80211_PROT_RTSCTS
)
3205 mm40_prot
|= RT2860_REG_PROT_CTRL_RTS_CTS
;
3206 else if (htprotmode
== IEEE80211_PROT_CTSONLY
)
3207 mm40_prot
|= RT2860_REG_PROT_CTRL_CTS
;
3209 mm40_prot
|= RT2860_REG_PROT_CTRL_NONE
;
3211 gf40_prot
= mm40_prot
;
3214 /* IEEE80211_HTINFO_OPMODE_MIXED */
3215 case IEEE80211_HTINFO_OPMODE_MIXED
:
3216 mm20_prot
= RT2860_REG_PROT_NAV_SHORT
|
3217 RT2860_REG_TXOP_ALLOW_CCK
| RT2860_REG_TXOP_ALLOW_OFDM
|
3218 RT2860_REG_TXOP_ALLOW_MM20
| RT2860_REG_TXOP_ALLOW_GF20
;
3220 if (ic
->ic_flags
& IEEE80211_F_USEPROT
)
3221 mm20_prot
|= (RT2860_REG_PROT_PHYMODE_CCK
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3222 (3 << RT2860_REG_PROT_MCS_SHIFT
);
3224 mm20_prot
|= (RT2860_REG_PROT_PHYMODE_OFDM
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3225 (4 << RT2860_REG_PROT_MCS_SHIFT
);
3227 if (htprotmode
== IEEE80211_PROT_RTSCTS
)
3228 mm20_prot
|= RT2860_REG_PROT_CTRL_RTS_CTS
;
3229 else if (htprotmode
== IEEE80211_PROT_CTSONLY
)
3230 mm20_prot
|= RT2860_REG_PROT_CTRL_CTS
;
3232 mm20_prot
|= RT2860_REG_PROT_CTRL_NONE
;
3234 gf20_prot
= mm20_prot
;
3236 mm40_prot
= RT2860_REG_PROT_NAV_SHORT
| RT2860_REG_TXOP_ALLOW_ALL
;
3238 if (ic
->ic_flags
& IEEE80211_F_USEPROT
)
3239 mm40_prot
|= (RT2860_REG_PROT_PHYMODE_CCK
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3240 (3 << RT2860_REG_PROT_MCS_SHIFT
);
3242 mm40_prot
|= (RT2860_REG_PROT_PHYMODE_OFDM
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3243 (0x84 << RT2860_REG_PROT_MCS_SHIFT
);
3245 if (htprotmode
== IEEE80211_PROT_RTSCTS
)
3246 mm40_prot
|= RT2860_REG_PROT_CTRL_RTS_CTS
;
3247 else if (htprotmode
== IEEE80211_PROT_CTSONLY
)
3248 mm40_prot
|= RT2860_REG_PROT_CTRL_CTS
;
3250 mm40_prot
|= RT2860_REG_PROT_CTRL_NONE
;
3252 gf40_prot
= mm40_prot
;
3256 * IEEE80211_HTINFO_OPMODE_PURE
3257 * IEEE80211_HTINFO_OPMODE_PROTOPT
3259 case IEEE80211_HTINFO_OPMODE_PURE
:
3260 case IEEE80211_HTINFO_OPMODE_PROTOPT
:
3262 mm20_prot
= RT2860_REG_PROT_NAV_SHORT
| RT2860_REG_PROT_CTRL_NONE
|
3263 RT2860_REG_TXOP_ALLOW_CCK
| RT2860_REG_TXOP_ALLOW_OFDM
|
3264 RT2860_REG_TXOP_ALLOW_MM20
| RT2860_REG_TXOP_ALLOW_GF20
|
3265 (RT2860_REG_PROT_PHYMODE_OFDM
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3266 (4 << RT2860_REG_PROT_MCS_SHIFT
);
3268 gf20_prot
= mm20_prot
;
3270 mm40_prot
= RT2860_REG_PROT_NAV_SHORT
| RT2860_REG_PROT_CTRL_NONE
|
3271 RT2860_REG_TXOP_ALLOW_ALL
|
3272 (RT2860_REG_PROT_PHYMODE_OFDM
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3273 (0x84 << RT2860_REG_PROT_MCS_SHIFT
);
3275 gf40_prot
= mm40_prot
;
3279 rt2860_io_mac_write(sc
, RT2860_REG_TX_MM20_PROT_CFG
, mm20_prot
);
3280 rt2860_io_mac_write(sc
, RT2860_REG_TX_MM40_PROT_CFG
, mm40_prot
);
3281 rt2860_io_mac_write(sc
, RT2860_REG_TX_GF20_PROT_CFG
, gf20_prot
);
3282 rt2860_io_mac_write(sc
, RT2860_REG_TX_GF40_PROT_CFG
, gf40_prot
);
3286 * rt2860_asic_updateslot
3288 static void rt2860_asic_updateslot(struct rt2860_softc
*sc
)
3290 struct ieee80211com
*ic
;
3295 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATE
,
3296 "%s: %s short slot time\n",
3297 device_get_nameunit(sc
->dev
),
3298 (ic
->ic_flags
& (IEEE80211_F_SHSLOT
| IEEE80211_F_BURST
)) ? "enabling" : "disabling");
3300 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_BKOFF_SLOT_CFG
);
3303 tmp
|= (ic
->ic_flags
& (IEEE80211_F_SHSLOT
|IEEE80211_F_BURST
)) ? 9 : 20;
3305 rt2860_io_mac_write(sc
, RT2860_REG_BKOFF_SLOT_CFG
, tmp
);
3309 * rt2860_asic_wme_update
3311 static void rt2860_asic_wme_update(struct rt2860_softc
*sc
)
3313 struct ieee80211com
*ic
;
3314 struct ieee80211_wme_state
*wme
;
3315 const struct wmeParams
*wmep
;
3320 wmep
= wme
->wme_chanParams
.cap_wmeParams
;
3322 RT2860_DPRINTF(sc
, RT2860_DEBUG_WME
,
3323 "%s: wme update: WME_AC_VO=%d/%d/%d/%d, WME_AC_VI=%d/%d/%d/%d, "
3324 "WME_AC_BK=%d/%d/%d/%d, WME_AC_BE=%d/%d/%d/%d\n",
3325 device_get_nameunit(sc
->dev
),
3326 wmep
[WME_AC_VO
].wmep_aifsn
,
3327 wmep
[WME_AC_VO
].wmep_logcwmin
, wmep
[WME_AC_VO
].wmep_logcwmax
,
3328 wmep
[WME_AC_VO
].wmep_txopLimit
,
3329 wmep
[WME_AC_VI
].wmep_aifsn
,
3330 wmep
[WME_AC_VI
].wmep_logcwmin
, wmep
[WME_AC_VI
].wmep_logcwmax
,
3331 wmep
[WME_AC_VI
].wmep_txopLimit
,
3332 wmep
[WME_AC_BK
].wmep_aifsn
,
3333 wmep
[WME_AC_BK
].wmep_logcwmin
, wmep
[WME_AC_BK
].wmep_logcwmax
,
3334 wmep
[WME_AC_BK
].wmep_txopLimit
,
3335 wmep
[WME_AC_BE
].wmep_aifsn
,
3336 wmep
[WME_AC_BE
].wmep_logcwmin
, wmep
[WME_AC_BE
].wmep_logcwmax
,
3337 wmep
[WME_AC_BE
].wmep_txopLimit
);
3339 for (i
= 0; i
< WME_NUM_AC
; i
++)
3340 rt2860_io_mac_write(sc
, RT2860_REG_TX_EDCA_AC_CFG(i
),
3341 (wmep
[i
].wmep_logcwmax
<< 16) | (wmep
[i
].wmep_logcwmin
<< 12) |
3342 (wmep
[i
].wmep_aifsn
<< 8) | wmep
[i
].wmep_txopLimit
);
3344 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WMM_AIFSN_CFG
,
3345 (wmep
[WME_AC_VO
].wmep_aifsn
<< 12) | (wmep
[WME_AC_VI
].wmep_aifsn
<< 8) |
3346 (wmep
[WME_AC_BK
].wmep_aifsn
<< 4) | wmep
[WME_AC_BE
].wmep_aifsn
);
3348 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WMM_CWMIN_CFG
,
3349 (wmep
[WME_AC_VO
].wmep_logcwmin
<< 12) | (wmep
[WME_AC_VI
].wmep_logcwmin
<< 8) |
3350 (wmep
[WME_AC_BK
].wmep_logcwmin
<< 4) | wmep
[WME_AC_BE
].wmep_logcwmin
);
3352 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WMM_CWMAX_CFG
,
3353 (wmep
[WME_AC_VO
].wmep_logcwmax
<< 12) | (wmep
[WME_AC_VI
].wmep_logcwmax
<< 8) |
3354 (wmep
[WME_AC_BK
].wmep_logcwmax
<< 4) | wmep
[WME_AC_BE
].wmep_logcwmax
);
3356 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WMM_TXOP0_CFG
,
3357 (wmep
[WME_AC_BK
].wmep_txopLimit
<< 16) | wmep
[WME_AC_BE
].wmep_txopLimit
);
3359 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WMM_TXOP1_CFG
,
3360 (wmep
[WME_AC_VO
].wmep_txopLimit
<< 16) | wmep
[WME_AC_VI
].wmep_txopLimit
);
3364 * rt2860_asic_update_beacon
3366 static void rt2860_asic_update_beacon(struct rt2860_softc
*sc
)
3368 struct ieee80211com
*ic
;
3370 struct rt2860_txwi
*txwi
;
3375 m
= sc
->beacon_mbuf
;
3376 txwi
= &sc
->beacon_txwi
;
3378 /* disable temporarily TSF sync */
3380 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_BCN_TIME_CFG
);
3382 tmp
&= ~(RT2860_REG_BCN_TX_ENABLE
|
3383 RT2860_REG_TSF_TIMER_ENABLE
|
3384 RT2860_REG_TBTT_TIMER_ENABLE
);
3386 rt2860_io_mac_write(sc
, RT2860_REG_BCN_TIME_CFG
, tmp
);
3388 /* write Tx wireless info and beacon frame to on-chip memory */
3390 rt2860_io_mac_write_multi(sc
, RT2860_REG_BEACON_BASE(0),
3391 txwi
, sizeof(struct rt2860_txwi
));
3393 rt2860_io_mac_write_multi(sc
, RT2860_REG_BEACON_BASE(0) + sizeof(struct rt2860_txwi
),
3394 mtod(m
, uint8_t *), m
->m_pkthdr
.len
);
3396 /* enable again TSF sync */
3398 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_BCN_TIME_CFG
);
3400 tmp
|= (RT2860_REG_BCN_TX_ENABLE
|
3401 RT2860_REG_TSF_TIMER_ENABLE
|
3402 RT2860_REG_TBTT_TIMER_ENABLE
);
3404 rt2860_io_mac_write(sc
, RT2860_REG_BCN_TIME_CFG
, tmp
);
3408 * rt2860_asic_clear_keytables
3410 static void rt2860_asic_clear_keytables(struct rt2860_softc
*sc
)
3414 /* clear Rx WCID search table (entries = 256, entry size = 8) */
3416 for (i
= 0; i
< 256; i
++)
3418 rt2860_io_mac_write(sc
, RT2860_REG_WCID(i
), 0xffffffff);
3419 rt2860_io_mac_write(sc
, RT2860_REG_WCID(i
) + 4, 0x0000ffff);
3422 /* clear WCID attribute table (entries = 256, entry size = 4) */
3424 rt2860_io_mac_set_region_4(sc
, RT2860_REG_WCID_ATTR(0), 0, 256);
3426 /* clear IV/EIV table (entries = 256, entry size = 8) */
3428 rt2860_io_mac_set_region_4(sc
, RT2860_REG_IVEIV(0), 0, 2 * 256);
3430 /* clear pairwise key table (entries = 64, entry size = 32) */
3432 rt2860_io_mac_set_region_4(sc
, RT2860_REG_PKEY(0), 0, 8 * 64);
3434 /* clear shared key table (entries = 32, entry size = 32) */
3436 rt2860_io_mac_set_region_4(sc
, RT2860_REG_SKEY(0, 0), 0, 8 * 32);
3438 /* clear shared key mode (entries = 32, entry size = 2) */
3440 rt2860_io_mac_set_region_4(sc
, RT2860_REG_SKEY_MODE(0), 0, 16);
3444 * rt2860_beacon_alloc
3446 static int rt2860_beacon_alloc(struct rt2860_softc
*sc
)
3448 struct ieee80211com
*ic
;
3450 struct rt2860_txwi txwi
;
3455 m
= ieee80211_beacon_alloc(ic
->ic_bss
, &sc
->beacon_offsets
);
3459 rate
= IEEE80211_IS_CHAN_5GHZ(ic
->ic_curchan
) ? 12 : 2;
3460 mcs
= rt2860_rate2mcs(rate
);
3462 memset(&txwi
, 0, sizeof(struct rt2860_txwi
));
3465 txwi
.pid_mpdu_len
= ((htole16(m
->m_pkthdr
.len
) & RT2860_TXWI_MPDU_LEN_MASK
) <<
3466 RT2860_TXWI_MPDU_LEN_SHIFT
);
3467 txwi
.txop
= (RT2860_TXWI_TXOP_HT
<< RT2860_TXWI_TXOP_SHIFT
);
3468 txwi
.mpdu_density_flags
|=
3469 (RT2860_TXWI_FLAGS_TS
<< RT2860_TXWI_FLAGS_SHIFT
);
3470 txwi
.bawin_size_xflags
|=
3471 (RT2860_TXWI_XFLAGS_NSEQ
<< RT2860_TXWI_XFLAGS_SHIFT
);
3475 txwi
.phymode_ifs_stbc_shortgi
=
3476 (RT2860_TXWI_PHYMODE_CCK
<< RT2860_TXWI_PHYMODE_SHIFT
);
3478 if (rate
!= 2 && (ic
->ic_flags
& IEEE80211_F_SHPREAMBLE
))
3479 mcs
|= RT2860_TXWI_MCS_SHOTPRE
;
3483 txwi
.phymode_ifs_stbc_shortgi
=
3484 (RT2860_TXWI_PHYMODE_OFDM
<< RT2860_TXWI_PHYMODE_SHIFT
);
3487 txwi
.bw_mcs
= (RT2860_TXWI_BW_20
<< RT2860_TXWI_BW_SHIFT
) |
3488 ((mcs
& RT2860_TXWI_MCS_MASK
) << RT2860_TXWI_MCS_SHIFT
);
3490 if (sc
->beacon_mbuf
!= NULL
)
3492 m_free(sc
->beacon_mbuf
);
3493 sc
->beacon_mbuf
= NULL
;
3496 sc
->beacon_mbuf
= m
;
3497 sc
->beacon_txwi
= txwi
;
3505 static uint8_t rt2860_rxrate(struct rt2860_rxwi
*rxwi
)
3507 uint8_t mcs
, phymode
;
3510 mcs
= (rxwi
->bw_mcs
>> RT2860_RXWI_MCS_SHIFT
) & RT2860_RXWI_MCS_MASK
;
3511 phymode
= (rxwi
->phymode_stbc_shortgi
>> RT2860_RXWI_PHYMODE_SHIFT
) &
3512 RT2860_RXWI_PHYMODE_MASK
;
3518 case RT2860_RXWI_PHYMODE_CCK
:
3519 switch (mcs
& ~RT2860_RXWI_MCS_SHOTPRE
)
3521 case 0: rate
= 2; break; /* 1 Mbps */
3522 case 1: rate
= 4; break; /* 2 MBps */
3523 case 2: rate
= 11; break; /* 5.5 Mbps */
3524 case 3: rate
= 22; break; /* 11 Mbps */
3528 case RT2860_RXWI_PHYMODE_OFDM
:
3531 case 0: rate
= 12; break; /* 6 Mbps */
3532 case 1: rate
= 18; break; /* 9 Mbps */
3533 case 2: rate
= 24; break; /* 12 Mbps */
3534 case 3: rate
= 36; break; /* 18 Mbps */
3535 case 4: rate
= 48; break; /* 24 Mbps */
3536 case 5: rate
= 72; break; /* 36 Mbps */
3537 case 6: rate
= 96; break; /* 48 Mbps */
3538 case 7: rate
= 108; break; /* 54 Mbps */
3542 case RT2860_RXWI_PHYMODE_HT_MIXED
:
3543 case RT2860_RXWI_PHYMODE_HT_GF
:
3551 * rt2860_maxrssi_rxpath
3553 static uint8_t rt2860_maxrssi_rxpath(struct rt2860_softc
*sc
,
3554 const struct rt2860_rxwi
*rxwi
)
3560 if (sc
->nrxpath
> 1)
3561 if (rxwi
->rssi
[1] > rxwi
->rssi
[rxpath
])
3564 if (sc
->nrxpath
> 2)
3565 if (rxwi
->rssi
[2] > rxwi
->rssi
[rxpath
])
3574 static int8_t rt2860_rssi2dbm(struct rt2860_softc
*sc
,
3575 uint8_t rssi
, uint8_t rxpath
)
3577 struct ieee80211com
*ic
;
3578 struct ieee80211_channel
*c
;
3580 int8_t rssi_off
, lna_gain
;
3587 chan
= ieee80211_chan2ieee(ic
, c
);
3589 if (IEEE80211_IS_CHAN_5GHZ(c
))
3591 rssi_off
= sc
->rssi_off_5ghz
[rxpath
];
3594 lna_gain
= sc
->lna_gain
[1];
3595 else if (chan
<= 128)
3596 lna_gain
= sc
->lna_gain
[2];
3598 lna_gain
= sc
->lna_gain
[3];
3602 rssi_off
= sc
->rssi_off_2ghz
[rxpath
];
3603 lna_gain
= sc
->lna_gain
[0];
3606 return (-12 - rssi_off
- lna_gain
- rssi
);
3612 static uint8_t rt2860_rate2mcs(uint8_t rate
)
3639 static int rt2860_ackrate(struct ieee80211com
*ic
, int rate
)
3651 return (ic
->ic_curmode
== IEEE80211_MODE_11B
) ? 4 : rate
;
3670 /* default to 1Mbps */
3677 static uint16_t rt2860_txtime(int len
, int rate
, uint32_t flags
)
3681 if (RT2860_RATE_IS_OFDM(rate
))
3683 txtime
= (8 + 4 * len
+ 3 + rate
- 1) / rate
;
3684 txtime
= 16 + 4 + 4 * txtime
+ 6;
3688 txtime
= (16 * len
+ rate
- 1) / rate
;
3690 if (rate
!= 2 && (flags
& IEEE80211_F_SHPREAMBLE
))
3702 static int rt2860_tx_frame(struct rt2860_softc
*sc
,
3703 struct mbuf
*m
, struct ieee80211_node
*ni
, int qid
)
3705 struct ieee80211com
*ic
;
3706 struct rt2860_softc_node
*rni
;
3707 struct rt2860_softc_tx_ring
*ring
;
3708 struct rt2860_softc_tx_data
*data
;
3709 struct rt2860_txdesc
*desc
;
3710 struct rt2860_txwi
*txwi
;
3711 struct ieee80211_frame
*wh
;
3712 struct ieee80211_tx_ampdu
*tx_ampdu
;
3713 struct rt2860_softc_tx_radiotap_header
*tap
;
3714 bus_dma_segment_t dma_seg
[RT2860_SOFTC_MAX_SCATTER
];
3715 u_int hdrsize
, hdrspace
;
3716 uint8_t type
, rate
, bw
, stbc
, shortgi
, mcs
, pid
, wcid
, mpdu_density
, bawin_size
, qsel
;
3717 uint16_t qos
, len
, dmalen
, mpdu_len
, dur
;
3718 int error
, hasqos
, ac
, ampdu
, mimops
, ackrate
, ndmasegs
, ndescs
, i
, j
;
3720 KASSERT(qid
>= 0 && qid
< RT2860_SOFTC_TX_RING_COUNT
,
3721 ("%s: Tx frame: invalid qid=%d\n",
3722 device_get_nameunit(sc
->dev
), qid
));
3725 rni
= (struct rt2860_softc_node
*) ni
;
3727 ring
= &sc
->tx_ring
[qid
];
3728 desc
= &ring
->desc
[ring
->desc_cur
];
3729 data
= &ring
->data
[ring
->data_cur
];
3730 txwi
= (struct rt2860_txwi
*) (ring
->seg0
+ ring
->data_cur
* RT2860_TX_DATA_SEG0_SIZE
);
3732 wh
= mtod(m
, struct ieee80211_frame
*);
3734 type
= wh
->i_fc
[0] & IEEE80211_FC0_TYPE_MASK
;
3736 hasqos
= IEEE80211_QOS_HAS_SEQ(wh
);
3739 if (IEEE80211_HAS_ADDR4(wh
))
3740 qos
= le16toh(*(const uint16_t *)
3741 (((struct ieee80211_qosframe_addr4
*) wh
)->i_qos
));
3743 qos
= le16toh(*(const uint16_t *)
3744 (((struct ieee80211_qosframe
*) wh
)->i_qos
));
3751 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
3753 if (IEEE80211_IS_MULTICAST(wh
->i_addr1
) || type
!= IEEE80211_FC0_TYPE_DATA
)
3755 else if (ic
->ic_fixed_rate
!= IEEE80211_FIXED_RATE_NONE
)
3756 rate
= ic
->ic_fixed_rate
;
3758 rate
= ni
->ni_htrates
.rs_rates
[ni
->ni_txrate
];
3762 if (IEEE80211_IS_MULTICAST(wh
->i_addr1
) || type
!= IEEE80211_FC0_TYPE_DATA
)
3763 rate
= IEEE80211_IS_CHAN_5GHZ(ic
->ic_curchan
) ? 12 : 2;
3764 else if (ic
->ic_fixed_rate
!= IEEE80211_FIXED_RATE_NONE
)
3765 rate
= ic
->ic_fixed_rate
;
3767 rate
= ni
->ni_rates
.rs_rates
[ni
->ni_txrate
];
3770 rate
&= IEEE80211_RATE_VAL
;
3772 /* fill Tx wireless info */
3774 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
3777 mcs
= rt2860_rate2mcs(rate
);
3779 /* management frames do not need encryption */
3781 if (type
== IEEE80211_FC0_TYPE_DATA
)
3782 wcid
= !IEEE80211_IS_MULTICAST(wh
->i_addr1
) ? rni
->staid
: RT2860_WCID_MCAST
;
3784 wcid
= RT2860_WCID_RESERVED
;
3786 /* calculate MPDU length without padding */
3788 hdrsize
= ieee80211_hdrsize(wh
);
3789 hdrspace
= ieee80211_hdrspace(ic
, wh
);
3790 mpdu_len
= m
->m_pkthdr
.len
- hdrspace
+ hdrsize
;
3792 memset(txwi
, 0, sizeof(struct rt2860_txwi
));
3796 /* MIMO power save */
3798 if ((ni
->ni_flags
& IEEE80211_NODE_HT
) &&
3799 ((ni
->ni_htcap
& IEEE80211_HTCAP_SMPS
) != IEEE80211_HTCAP_SMPS_OFF
))
3803 if ((ni
->ni_htcap
& IEEE80211_HTCAP_SMPS
) == IEEE80211_HTCAP_SMPS_DYNAMIC
)
3805 /* dynamic MIMO power save */
3807 txwi
->mpdu_density_flags
|=
3808 (RT2860_TXWI_FLAGS_MIMOPS
<< RT2860_TXWI_FLAGS_SHIFT
);
3812 /* static MIMO power save */
3827 txwi
->pid_mpdu_len
= ((htole16(pid
) & RT2860_TXWI_PID_MASK
) <<
3828 RT2860_TXWI_PID_SHIFT
) | ((htole16(mpdu_len
) & RT2860_TXWI_MPDU_LEN_MASK
) <<
3829 RT2860_TXWI_MPDU_LEN_SHIFT
);
3831 stbc
= (ic
->ic_htcaps
& IEEE80211_HTCAP_TXSTBC
) &&
3832 (ni
->ni_flags
& IEEE80211_NODE_HT
) && (ni
->ni_htcap
& IEEE80211_HTCAP_RXSTBC
);
3834 shortgi
= (ic
->ic_flags_ext
& (IEEE80211_FEXT_SHORTGI20
| IEEE80211_FEXT_SHORTGI40
)) &&
3835 (ni
->ni_flags
& IEEE80211_NODE_HT
) && (ni
->ni_htcap
& (IEEE80211_HTCAP_SHORTGI20
| IEEE80211_HTCAP_SHORTGI40
));
3837 txwi
->phymode_ifs_stbc_shortgi
|=
3838 ((stbc
& RT2860_TXWI_STBC_MASK
) << RT2860_TXWI_STBC_SHIFT
) |
3839 ((shortgi
& RT2860_TXWI_SHORTGI_MASK
) << RT2860_TXWI_SHORTGI_SHIFT
);
3841 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
3843 txwi
->phymode_ifs_stbc_shortgi
|=
3844 (RT2860_TXWI_PHYMODE_HT_MIXED
<< RT2860_TXWI_PHYMODE_SHIFT
);
3848 if (!RT2860_RATE_IS_OFDM(rate
))
3850 txwi
->phymode_ifs_stbc_shortgi
|=
3851 (RT2860_TXWI_PHYMODE_CCK
<< RT2860_TXWI_PHYMODE_SHIFT
);
3853 if (rate
!= 2 && (ic
->ic_flags
& IEEE80211_F_SHPREAMBLE
))
3854 mcs
|= RT2860_TXWI_MCS_SHOTPRE
;
3858 txwi
->phymode_ifs_stbc_shortgi
|=
3859 (RT2860_TXWI_PHYMODE_OFDM
<< RT2860_TXWI_PHYMODE_SHIFT
);
3863 if ((ni
->ni_flags
& IEEE80211_NODE_HT
) && (ni
->ni_chw
== 40))
3864 bw
= RT2860_TXWI_BW_40
;
3866 bw
= RT2860_TXWI_BW_20
;
3868 txwi
->bw_mcs
= ((bw
& RT2860_TXWI_BW_MASK
) << RT2860_TXWI_BW_SHIFT
) |
3869 ((mcs
& RT2860_TXWI_MCS_MASK
) << RT2860_TXWI_MCS_SHIFT
);
3871 if (type
!= IEEE80211_FC0_TYPE_DATA
)
3872 txwi
->txop
= (RT2860_TXWI_TXOP_BACKOFF
<< RT2860_TXWI_TXOP_SHIFT
);
3874 txwi
->txop
= (RT2860_TXWI_TXOP_HT
<< RT2860_TXWI_TXOP_SHIFT
);
3876 /* skip ACKs for multicast frames */
3878 if (!IEEE80211_IS_MULTICAST(wh
->i_addr1
) &&
3879 (!hasqos
|| (qos
& IEEE80211_QOS_ACKPOLICY
) != IEEE80211_QOS_ACKPOLICY_NOACK
))
3881 txwi
->bawin_size_xflags
|=
3882 (RT2860_TXWI_XFLAGS_ACK
<< RT2860_TXWI_XFLAGS_SHIFT
);
3884 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
3886 /* preamble + plcp + signal extension + SIFS */
3888 dur
= 16 + 4 + 6 + 10;
3892 ackrate
= rt2860_ackrate(ic
, rate
);
3894 dur
= rt2860_txtime(RT2860_ACK_SIZE
, ackrate
, ic
->ic_flags
) +
3898 *(uint16_t *) wh
->i_dur
= htole16(dur
);
3901 /* check for A-MPDU */
3903 if ((qos
& IEEE80211_QOS_ACKPOLICY
) == IEEE80211_QOS_ACKPOLICY_BA
)
3905 ac
= M_WME_GETAC(m
);
3906 tx_ampdu
= &ni
->ni_tx_ampdu
[ac
];
3908 mpdu_density
= RT2860_MS(ni
->ni_htparam
, IEEE80211_HTCAP_MPDUDENSITY
);
3909 bawin_size
= tx_ampdu
->txa_wnd
;
3911 txwi
->mpdu_density_flags
|=
3912 ((mpdu_density
& RT2860_TXWI_MPDU_DENSITY_MASK
) << RT2860_TXWI_MPDU_DENSITY_SHIFT
) |
3913 (RT2860_TXWI_FLAGS_AMPDU
<< RT2860_TXWI_FLAGS_SHIFT
);
3915 txwi
->bawin_size_xflags
|=
3916 ((bawin_size
& RT2860_TXWI_BAWIN_SIZE_MASK
) << RT2860_TXWI_BAWIN_SIZE_SHIFT
);
3918 if (IEEE80211_HAS_ADDR4(wh
))
3919 ((struct ieee80211_qosframe_addr4
*) wh
)->i_qos
[0] &= ~IEEE80211_QOS_ACKPOLICY
;
3921 ((struct ieee80211_qosframe
*) wh
)->i_qos
[0] &= ~IEEE80211_QOS_ACKPOLICY
;
3930 /* ask MAC to insert timestamp into probe responses */
3932 if ((wh
->i_fc
[0] & (IEEE80211_FC0_TYPE_MASK
| IEEE80211_FC0_SUBTYPE_MASK
)) ==
3933 (IEEE80211_FC0_TYPE_MGT
| IEEE80211_FC0_SUBTYPE_PROBE_RESP
))
3934 txwi
->mpdu_density_flags
|=
3935 (RT2860_TXWI_FLAGS_TS
<< RT2860_TXWI_FLAGS_SHIFT
);
3937 if (bpf_peers_present(sc
->drvbpf
))
3941 tap
->flags
= IEEE80211_RADIOTAP_F_DATAPAD
;
3942 tap
->chan_flags
= htole32(ic
->ic_curchan
->ic_flags
);
3943 tap
->chan_freq
= htole16(ic
->ic_curchan
->ic_freq
);
3944 tap
->chan_ieee
= ic
->ic_curchan
->ic_ieee
;
3945 tap
->chan_maxpow
= 0;
3947 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
3948 tap
->rate
= mcs
| IEEE80211_RATE_MCS
;
3952 if (mcs
& RT2860_TXWI_MCS_SHOTPRE
)
3953 tap
->flags
|= IEEE80211_RADIOTAP_F_SHORTPRE
;
3956 tap
->flags
|= IEEE80211_RADIOTAP_F_SHORTGI
;
3958 if (wh
->i_fc
[1] & IEEE80211_FC1_WEP
)
3959 tap
->flags
|= IEEE80211_RADIOTAP_F_WEP
;
3961 if (wh
->i_fc
[1] & IEEE80211_FC1_WEP
)
3963 wh
->i_fc
[1] &= ~IEEE80211_FC1_WEP
;
3965 bpf_mtap2(sc
->drvbpf
, tap
, sc
->txtap_len
, m
);
3967 wh
->i_fc
[1] |= IEEE80211_FC1_WEP
;
3971 bpf_mtap2(sc
->drvbpf
, tap
, sc
->txtap_len
, m
);
3975 /* copy and trim 802.11 header */
3977 m_copydata(m
, 0, hdrsize
, (caddr_t
) (txwi
+ 1));
3980 error
= bus_dmamap_load_mbuf_sg(ring
->data_dma_tag
, data
->dma_map
, m
,
3981 dma_seg
, &ndmasegs
, 0);
3984 /* too many fragments, linearize */
3986 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
3987 "%s: could not load mbuf DMA map, trying to linearize mbuf\n",
3988 device_get_nameunit(sc
->dev
));
3990 m
= m_defrag(m
, M_DONTWAIT
);
3994 sc
->tx_defrag_packets
++;
3996 error
= bus_dmamap_load_mbuf_sg(ring
->data_dma_tag
, data
->dma_map
, m
,
3997 dma_seg
, &ndmasegs
, 0);
4000 printf("%s: could not load mbuf DMA map: error=%d\n",
4001 device_get_nameunit(sc
->dev
), error
);
4007 if (m
->m_pkthdr
.len
== 0)
4010 /* determine how many Tx descs are required */
4012 ndescs
= 1 + ndmasegs
/ 2;
4013 if ((ring
->desc_queued
+ ndescs
) > (RT2860_SOFTC_TX_RING_DESC_COUNT
- 2))
4015 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
4016 "%s: there are not enough Tx descs\n",
4017 device_get_nameunit(sc
->dev
));
4019 sc
->no_tx_desc_avail
++;
4021 bus_dmamap_unload(ring
->data_dma_tag
, data
->dma_map
);
4029 /* set up Tx descs */
4031 /* first segment is Tx wireless info and 802.11 header */
4033 len
= sizeof(struct rt2860_txwi
) + hdrsize
;
4035 /* align end on a 4-bytes boundary */
4037 dmalen
= (len
+ 3) & ~ 3;
4039 memset((caddr_t
) txwi
+ len
, 0, dmalen
- len
);
4041 qsel
= RT2860_TXDESC_QSEL_EDCA
;
4043 desc
->sdp0
= htole32(ring
->seg0_phys_addr
+ ring
->data_cur
* RT2860_TX_DATA_SEG0_SIZE
);
4044 desc
->sdl0
= htole16(dmalen
);
4045 desc
->qsel_flags
= (qsel
<< RT2860_TXDESC_QSEL_SHIFT
);
4047 /* set up payload segments */
4049 for (i
= ndmasegs
, j
= 0; i
>= 2; i
-= 2)
4051 desc
->sdp1
= htole32(dma_seg
[j
].ds_addr
);
4052 desc
->sdl1
= htole16(dma_seg
[j
].ds_len
);
4054 ring
->desc_queued
++;
4055 ring
->desc_cur
= (ring
->desc_cur
+ 1) % RT2860_SOFTC_TX_RING_DESC_COUNT
;
4059 desc
= &ring
->desc
[ring
->desc_cur
];
4061 desc
->sdp0
= htole32(dma_seg
[j
].ds_addr
);
4062 desc
->sdl0
= htole16(dma_seg
[j
].ds_len
);
4063 desc
->qsel_flags
= (qsel
<< RT2860_TXDESC_QSEL_SHIFT
);
4068 /* finalize last payload segment */
4072 desc
->sdp1
= htole32(dma_seg
[j
].ds_addr
);
4073 desc
->sdl1
= htole16(dma_seg
[j
].ds_len
| RT2860_TXDESC_SDL1_LASTSEG
);
4077 desc
->sdl0
|= htole16(RT2860_TXDESC_SDL0_LASTSEG
);
4081 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
4082 "%s: sending frame: qid=%d, hdrsize=%d, hdrspace=%d, len=%d, "
4083 "bw=%d, stbc=%d, shortgi=%d, mcs=%d, wcid=0x%02x, ampdu=%d, mimops=%d, DMA len=%d, ndmasegs=%d, DMA ds_len=%d/%d/%d/%d/%d\n",
4084 device_get_nameunit(sc
->dev
),
4085 qid
, hdrsize
, hdrspace
, m
->m_pkthdr
.len
+ hdrsize
,
4086 bw
, stbc
, shortgi
, mcs
, wcid
, ampdu
, mimops
, dmalen
, ndmasegs
,
4087 dma_seg
[0].ds_len
, dma_seg
[1].ds_len
, dma_seg
[2].ds_len
, dma_seg
[3].ds_len
, dma_seg
[4].ds_len
);
4089 bus_dmamap_sync(ring
->seg0_dma_tag
, ring
->seg0_dma_map
,
4090 BUS_DMASYNC_PREWRITE
);
4091 bus_dmamap_sync(ring
->data_dma_tag
, data
->dma_map
,
4092 BUS_DMASYNC_PREWRITE
);
4093 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
4094 BUS_DMASYNC_PREWRITE
);
4096 ring
->desc_queued
++;
4097 ring
->desc_cur
= (ring
->desc_cur
+ 1) % RT2860_SOFTC_TX_RING_DESC_COUNT
;
4099 ring
->data_queued
++;
4100 ring
->data_cur
= (ring
->data_cur
+ 1) % RT2860_SOFTC_TX_RING_DATA_COUNT
;
4104 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_CTX_IDX(qid
), ring
->desc_cur
);
4112 static int rt2860_tx_raw(struct rt2860_softc
*sc
,
4113 struct mbuf
*m
, struct ieee80211_node
*ni
,
4114 const struct ieee80211_bpf_params
*params
)
4116 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
4118 device_get_nameunit(sc
->dev
));
4126 static void rt2860_intr(void *arg
)
4128 struct rt2860_softc
*sc
;
4135 /* acknowledge interrupts */
4137 status
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_INT_STATUS
);
4138 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_INT_STATUS
, status
);
4140 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4141 "%s: interrupt: status = 0x%08x\n",
4142 device_get_nameunit(sc
->dev
), status
);
4144 if (status
== 0xffffffff || /* device likely went away */
4145 status
== 0) /* not for us */
4150 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
4153 if (status
& RT2860_REG_INT_TX_COHERENT
)
4154 rt2860_tx_coherent_intr(sc
);
4156 if (status
& RT2860_REG_INT_RX_COHERENT
)
4157 rt2860_rx_coherent_intr(sc
);
4159 if (status
& RT2860_REG_INT_TXRX_COHERENT
)
4160 rt2860_txrx_coherent_intr(sc
);
4162 if (status
& RT2860_REG_INT_FIFO_STA_FULL
)
4163 rt2860_fifo_sta_full_intr(sc
);
4165 if (status
& RT2860_REG_INT_TX_MGMT_DONE
)
4166 rt2860_tx_intr(sc
, 5);
4168 if (status
& RT2860_REG_INT_RX_DONE
)
4171 if (status
& RT2860_REG_INT_RX_DELAY_DONE
)
4172 rt2860_rx_delay_intr(sc
);
4174 if (status
& RT2860_REG_INT_TX_HCCA_DONE
)
4175 rt2860_tx_intr(sc
, 4);
4177 if (status
& RT2860_REG_INT_TX_AC3_DONE
)
4178 rt2860_tx_intr(sc
, 3);
4180 if (status
& RT2860_REG_INT_TX_AC2_DONE
)
4181 rt2860_tx_intr(sc
, 2);
4183 if (status
& RT2860_REG_INT_TX_AC1_DONE
)
4184 rt2860_tx_intr(sc
, 1);
4186 if (status
& RT2860_REG_INT_TX_AC0_DONE
)
4187 rt2860_tx_intr(sc
, 0);
4189 if (status
& RT2860_REG_INT_TX_DELAY_DONE
)
4190 rt2860_tx_delay_intr(sc
);
4192 if (status
& RT2860_REG_INT_PRE_TBTT
)
4193 rt2860_pre_tbtt_intr(sc
);
4195 if (status
& RT2860_REG_INT_TBTT
)
4196 rt2860_tbtt_intr(sc
);
4198 if (status
& RT2860_REG_INT_MCU_CMD
)
4199 rt2860_mcu_cmd_intr(sc
);
4201 if (status
& RT2860_REG_INT_AUTO_WAKEUP
)
4202 rt2860_auto_wakeup_intr(sc
);
4204 if (status
& RT2860_REG_INT_GP_TIMER
)
4205 rt2860_gp_timer_intr(sc
);
4209 * rt2860_tx_coherent_intr
4211 static void rt2860_tx_coherent_intr(struct rt2860_softc
*sc
)
4216 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4217 "%s: Tx coherent interrupt\n",
4218 device_get_nameunit(sc
->dev
));
4220 sc
->tx_coherent_interrupts
++;
4222 /* restart DMA engine */
4224 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
);
4226 tmp
&= ~(RT2860_REG_TX_WB_DDONE
|
4227 RT2860_REG_RX_DMA_ENABLE
|
4228 RT2860_REG_TX_DMA_ENABLE
);
4230 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
, tmp
);
4232 /* init Tx rings (4 EDCAs + HCCA + MGMT) */
4234 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
4235 rt2860_reset_tx_ring(sc
, &sc
->tx_ring
[i
]);
4237 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
4239 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_BASE_PTR(i
),
4240 sc
->tx_ring
[i
].desc_phys_addr
);
4241 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_MAX_CNT(i
),
4242 RT2860_SOFTC_TX_RING_DESC_COUNT
);
4243 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_CTX_IDX(i
), 0);
4248 rt2860_reset_rx_ring(sc
, &sc
->rx_ring
);
4250 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_BASE_PTR
,
4251 sc
->rx_ring
.desc_phys_addr
);
4252 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_MAX_CNT
,
4253 RT2860_SOFTC_RX_RING_DATA_COUNT
);
4254 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_CALC_IDX
,
4255 RT2860_SOFTC_RX_RING_DATA_COUNT
- 1);
4257 rt2860_txrx_enable(sc
);
4261 * rt2860_rx_coherent_intr
4263 static void rt2860_rx_coherent_intr(struct rt2860_softc
*sc
)
4268 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4269 "%s: Rx coherent interrupt\n",
4270 device_get_nameunit(sc
->dev
));
4272 sc
->rx_coherent_interrupts
++;
4274 /* restart DMA engine */
4276 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
);
4278 tmp
&= ~(RT2860_REG_TX_WB_DDONE
|
4279 RT2860_REG_RX_DMA_ENABLE
|
4280 RT2860_REG_TX_DMA_ENABLE
);
4282 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
, tmp
);
4284 /* init Tx rings (4 EDCAs + HCCA + MGMT) */
4286 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
4287 rt2860_reset_tx_ring(sc
, &sc
->tx_ring
[i
]);
4289 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
4291 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_BASE_PTR(i
),
4292 sc
->tx_ring
[i
].desc_phys_addr
);
4293 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_MAX_CNT(i
),
4294 RT2860_SOFTC_TX_RING_DESC_COUNT
);
4295 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_CTX_IDX(i
), 0);
4300 rt2860_reset_rx_ring(sc
, &sc
->rx_ring
);
4302 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_BASE_PTR
,
4303 sc
->rx_ring
.desc_phys_addr
);
4304 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_MAX_CNT
,
4305 RT2860_SOFTC_RX_RING_DATA_COUNT
);
4306 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_CALC_IDX
,
4307 RT2860_SOFTC_RX_RING_DATA_COUNT
- 1);
4309 rt2860_txrx_enable(sc
);
4313 * rt2860_txrx_coherent_intr
4315 static void rt2860_txrx_coherent_intr(struct rt2860_softc
*sc
)
4320 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4321 "%s: Tx/Rx coherent interrupt\n",
4322 device_get_nameunit(sc
->dev
));
4324 sc
->txrx_coherent_interrupts
++;
4326 /* restart DMA engine */
4328 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
);
4330 tmp
&= ~(RT2860_REG_TX_WB_DDONE
|
4331 RT2860_REG_RX_DMA_ENABLE
|
4332 RT2860_REG_TX_DMA_ENABLE
);
4334 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
, tmp
);
4336 /* init Tx rings (4 EDCAs + HCCA + MGMT) */
4338 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
4339 rt2860_reset_tx_ring(sc
, &sc
->tx_ring
[i
]);
4341 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
4343 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_BASE_PTR(i
),
4344 sc
->tx_ring
[i
].desc_phys_addr
);
4345 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_MAX_CNT(i
),
4346 RT2860_SOFTC_TX_RING_DESC_COUNT
);
4347 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_CTX_IDX(i
), 0);
4352 rt2860_reset_rx_ring(sc
, &sc
->rx_ring
);
4354 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_BASE_PTR
,
4355 sc
->rx_ring
.desc_phys_addr
);
4356 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_MAX_CNT
,
4357 RT2860_SOFTC_RX_RING_DATA_COUNT
);
4358 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_CALC_IDX
,
4359 RT2860_SOFTC_RX_RING_DATA_COUNT
- 1);
4361 rt2860_txrx_enable(sc
);
4365 * rt2860_fifo_sta_full_intr
4367 static void rt2860_fifo_sta_full_intr(struct rt2860_softc
*sc
)
4369 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4370 "%s: FIFO statistic full interrupt\n",
4371 device_get_nameunit(sc
->dev
));
4373 sc
->fifo_sta_full_interrupts
++;
4375 RT2860_SOFTC_LOCK(sc
);
4377 if (!(sc
->intr_disable_mask
& RT2860_REG_INT_FIFO_STA_FULL
))
4379 rt2860_intr_disable(sc
, RT2860_REG_INT_FIFO_STA_FULL
);
4381 taskqueue_enqueue(sc
->taskqueue
, &sc
->fifo_sta_full_task
);
4384 sc
->intr_pending_mask
|= RT2860_REG_INT_FIFO_STA_FULL
;
4386 RT2860_SOFTC_UNLOCK(sc
);
4392 static void rt2860_rx_intr(struct rt2860_softc
*sc
)
4394 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4395 "%s: Rx interrupt\n",
4396 device_get_nameunit(sc
->dev
));
4398 sc
->rx_interrupts
++;
4400 RT2860_SOFTC_LOCK(sc
);
4402 if (!(sc
->intr_disable_mask
& RT2860_REG_INT_RX_DONE
))
4404 rt2860_intr_disable(sc
, RT2860_REG_INT_RX_DONE
);
4406 taskqueue_enqueue(sc
->taskqueue
, &sc
->rx_done_task
);
4409 sc
->intr_pending_mask
|= RT2860_REG_INT_RX_DONE
;
4411 RT2860_SOFTC_UNLOCK(sc
);
4415 * rt2860_rx_delay_intr
4417 static void rt2860_rx_delay_intr(struct rt2860_softc
*sc
)
4419 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4420 "%s: Rx delay interrupt\n",
4421 device_get_nameunit(sc
->dev
));
4423 sc
->rx_delay_interrupts
++;
4429 static void rt2860_tx_intr(struct rt2860_softc
*sc
, int qid
)
4431 KASSERT(qid
>= 0 && qid
< RT2860_SOFTC_TX_RING_COUNT
,
4432 ("%s: Tx interrupt: invalid qid=%d\n",
4433 device_get_nameunit(sc
->dev
), qid
));
4435 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4436 "%s: Tx interrupt: qid=%d\n",
4437 device_get_nameunit(sc
->dev
), qid
);
4439 sc
->tx_interrupts
[qid
]++;
4441 RT2860_SOFTC_LOCK(sc
);
4443 if (!(sc
->intr_disable_mask
& (RT2860_REG_INT_TX_AC0_DONE
<< qid
)))
4445 rt2860_intr_disable(sc
, (RT2860_REG_INT_TX_AC0_DONE
<< qid
));
4447 taskqueue_enqueue(sc
->taskqueue
, &sc
->tx_done_task
);
4450 sc
->intr_pending_mask
|= (RT2860_REG_INT_TX_AC0_DONE
<< qid
);
4452 RT2860_SOFTC_UNLOCK(sc
);
4456 * rt2860_tx_delay_intr
4458 static void rt2860_tx_delay_intr(struct rt2860_softc
*sc
)
4460 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4461 "%s: Tx delay interrupt\n",
4462 device_get_nameunit(sc
->dev
));
4464 sc
->tx_delay_interrupts
++;
4468 * rt2860_pre_tbtt_intr
4470 static void rt2860_pre_tbtt_intr(struct rt2860_softc
*sc
)
4472 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4473 "%s: Pre-TBTT interrupt\n",
4474 device_get_nameunit(sc
->dev
));
4476 sc
->pre_tbtt_interrupts
++;
4482 static void rt2860_tbtt_intr(struct rt2860_softc
*sc
)
4484 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4485 "%s: TBTT interrupt\n",
4486 device_get_nameunit(sc
->dev
));
4488 sc
->tbtt_interrupts
++;
4492 * rt2860_mcu_cmd_intr
4494 static void rt2860_mcu_cmd_intr(struct rt2860_softc
*sc
)
4496 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4497 "%s: MCU command interrupt\n",
4498 device_get_nameunit(sc
->dev
));
4500 sc
->mcu_cmd_interrupts
++;
4504 * rt2860_auto_wakeup_intr
4506 static void rt2860_auto_wakeup_intr(struct rt2860_softc
*sc
)
4508 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4509 "%s: auto wakeup interrupt\n",
4510 device_get_nameunit(sc
->dev
));
4512 sc
->auto_wakeup_interrupts
++;
4516 * rt2860_gp_timer_intr
4518 static void rt2860_gp_timer_intr(struct rt2860_softc
*sc
)
4520 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4521 "%s: GP timer interrupt\n",
4522 device_get_nameunit(sc
->dev
));
4524 sc
->gp_timer_interrupts
++;
4528 * rt2860_rx_done_task
4530 static void rt2860_rx_done_task(void *context
, int pending
)
4532 struct rt2860_softc
*sc
;
4539 RT2860_DPRINTF(sc
, RT2860_DEBUG_RX
,
4540 "%s: Rx done task\n",
4541 device_get_nameunit(sc
->dev
));
4543 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
4546 sc
->intr_pending_mask
&= ~RT2860_REG_INT_RX_DONE
;
4548 again
= rt2860_rx_eof(sc
, sc
->rx_process_limit
);
4550 RT2860_SOFTC_LOCK(sc
);
4552 if ((sc
->intr_pending_mask
& RT2860_REG_INT_RX_DONE
) || again
)
4554 RT2860_DPRINTF(sc
, RT2860_DEBUG_RX
,
4555 "%s: Rx done task: scheduling again\n",
4556 device_get_nameunit(sc
->dev
));
4558 taskqueue_enqueue(sc
->taskqueue
, &sc
->rx_done_task
);
4562 rt2860_intr_enable(sc
, RT2860_REG_INT_RX_DONE
);
4565 RT2860_SOFTC_UNLOCK(sc
);
4569 * rt2860_tx_done_task
4571 static void rt2860_tx_done_task(void *context
, int pending
)
4573 struct rt2860_softc
*sc
;
4581 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
4582 "%s: Tx done task\n",
4583 device_get_nameunit(sc
->dev
));
4585 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
4588 for (i
= RT2860_SOFTC_TX_RING_COUNT
- 1; i
>= 0; i
--)
4590 if (sc
->intr_pending_mask
& (RT2860_REG_INT_TX_AC0_DONE
<< i
))
4592 sc
->intr_pending_mask
&= ~(RT2860_REG_INT_TX_AC0_DONE
<< i
);
4594 rt2860_tx_eof(sc
, &sc
->tx_ring
[i
]);
4600 ifp
->if_drv_flags
&= ~IFF_DRV_OACTIVE
;
4602 intr_mask
= (RT2860_REG_INT_TX_MGMT_DONE
|
4603 RT2860_REG_INT_TX_HCCA_DONE
|
4604 RT2860_REG_INT_TX_AC3_DONE
|
4605 RT2860_REG_INT_TX_AC2_DONE
|
4606 RT2860_REG_INT_TX_AC1_DONE
|
4607 RT2860_REG_INT_TX_AC0_DONE
);
4609 RT2860_SOFTC_LOCK(sc
);
4611 rt2860_intr_enable(sc
, ~sc
->intr_pending_mask
&
4612 (sc
->intr_disable_mask
& intr_mask
));
4614 if (sc
->intr_pending_mask
& intr_mask
)
4616 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
4617 "%s: Tx done task: scheduling again\n",
4618 device_get_nameunit(sc
->dev
));
4620 taskqueue_enqueue(sc
->taskqueue
, &sc
->tx_done_task
);
4623 RT2860_SOFTC_UNLOCK(sc
);
4627 * rt2860_fifo_sta_full_task
4629 static void rt2860_fifo_sta_full_task(void *context
, int pending
)
4631 struct rt2860_softc
*sc
;
4637 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATS
,
4638 "%s: FIFO statistic full task\n",
4639 device_get_nameunit(sc
->dev
));
4641 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
4644 sc
->intr_pending_mask
&= ~RT2860_REG_INT_FIFO_STA_FULL
;
4646 rt2860_drain_fifo_stats(sc
);
4648 RT2860_SOFTC_LOCK(sc
);
4650 if (sc
->intr_pending_mask
& RT2860_REG_INT_FIFO_STA_FULL
)
4652 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATS
,
4653 "%s: FIFO statistic full task: scheduling again\n",
4654 device_get_nameunit(sc
->dev
));
4656 taskqueue_enqueue(sc
->taskqueue
, &sc
->fifo_sta_full_task
);
4660 rt2860_intr_enable(sc
, RT2860_REG_INT_FIFO_STA_FULL
);
4663 RT2860_SOFTC_UNLOCK(sc
);
4667 * rt2860_periodic_task
4669 static void rt2860_periodic_task(void *context
, int pending
)
4671 struct rt2860_softc
*sc
;
4673 struct ieee80211com
*ic
;
4679 RT2860_DPRINTF(sc
, RT2860_DEBUG_PERIODIC
,
4680 "%s: periodic task: round=%lu\n",
4681 device_get_nameunit(sc
->dev
), sc
->periodic_round
);
4683 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
4686 RT2860_SOFTC_LOCK(sc
);
4688 sc
->periodic_round
++;
4690 rt2860_update_stats(sc
);
4692 if ((sc
->periodic_round
% 10) == 0)
4694 rt2860_bbp_tuning(sc
);
4696 rt2860_update_raw_counters(sc
);
4698 rt2860_watchdog(sc
);
4700 if (ic
->ic_opmode
!= IEEE80211_M_MONITOR
&& ic
->ic_state
== IEEE80211_S_RUN
)
4702 if (ic
->ic_opmode
== IEEE80211_M_STA
)
4703 rt2860_amrr_update_iter_func(sc
, ic
->ic_bss
);
4705 ieee80211_iterate_nodes(&ic
->ic_sta
, rt2860_amrr_update_iter_func
, sc
);
4709 RT2860_SOFTC_UNLOCK(sc
);
4711 callout_reset(&sc
->periodic_ch
, hz
/ 10, rt2860_periodic
, sc
);
4717 static int rt2860_rx_eof(struct rt2860_softc
*sc
, int limit
)
4719 struct ieee80211com
*ic
;
4721 struct ieee80211_frame
*wh
;
4722 struct ieee80211_node
*ni
;
4723 struct rt2860_softc_node
*rni
;
4724 struct rt2860_softc_rx_radiotap_header
*tap
;
4725 struct rt2860_softc_rx_ring
*ring
;
4726 struct rt2860_rxdesc
*desc
;
4727 struct rt2860_softc_rx_data
*data
;
4728 struct rt2860_rxwi
*rxwi
;
4729 struct mbuf
*m
, *mnew
;
4730 bus_dma_segment_t segs
[1];
4731 bus_dmamap_t dma_map
;
4732 uint32_t index
, desc_flags
;
4733 uint8_t cipher_err
, rssi
, ant
, phymode
, bw
, shortgi
, mcs
, keyidx
;
4735 int error
, nsegs
, len
, ampdu
, amsdu
, nframes
, i
;
4739 ring
= &sc
->rx_ring
;
4745 index
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_RX_DRX_IDX
);
4746 if (ring
->cur
== index
)
4749 desc
= &ring
->desc
[ring
->cur
];
4750 desc_flags
= le32toh(desc
->flags
);
4751 data
= &ring
->data
[ring
->cur
];
4753 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
4754 BUS_DMASYNC_POSTREAD
);
4756 if (!(desc
->sdl0
& htole16(RT2860_RXDESC_SDL0_DDONE
)))
4761 mnew
= m_getjcl(M_DONTWAIT
, MT_DATA
, M_PKTHDR
, MJUMPAGESIZE
);
4764 sc
->rx_mbuf_alloc_errors
++;
4769 mnew
->m_len
= mnew
->m_pkthdr
.len
= MJUMPAGESIZE
;
4771 error
= bus_dmamap_load_mbuf_sg(ring
->data_dma_tag
, ring
->spare_dma_map
,
4772 mnew
, segs
, &nsegs
, BUS_DMA_NOWAIT
);
4777 sc
->rx_mbuf_dmamap_errors
++;
4783 KASSERT(nsegs
== 1, ("%s: too many DMA segments",
4784 device_get_name(sc
->dev
)));
4786 bus_dmamap_sync(ring
->data_dma_tag
, data
->dma_map
,
4787 BUS_DMASYNC_POSTREAD
);
4788 bus_dmamap_unload(ring
->data_dma_tag
, data
->dma_map
);
4790 dma_map
= data
->dma_map
;
4791 data
->dma_map
= ring
->spare_dma_map
;
4792 ring
->spare_dma_map
= dma_map
;
4794 bus_dmamap_sync(ring
->data_dma_tag
, data
->dma_map
,
4795 BUS_DMASYNC_PREREAD
);
4800 desc
->sdp0
= htole32(segs
[0].ds_addr
);
4802 /* get Rx wireless info */
4804 rxwi
= mtod(m
, struct rt2860_rxwi
*);
4805 len
= (le16toh(rxwi
->tid_size
) >> RT2860_RXWI_SIZE_SHIFT
) &
4806 RT2860_RXWI_SIZE_MASK
;
4808 /* check for L2 padding between IEEE 802.11 frame header and body */
4810 if (desc_flags
& RT2860_RXDESC_FLAGS_L2PAD
)
4812 RT2860_DPRINTF(sc
, RT2860_DEBUG_RX
,
4813 "%s: L2 padding: len=%d\n",
4814 device_get_nameunit(sc
->dev
), len
);
4819 m
->m_pkthdr
.rcvif
= ifp
;
4820 m
->m_data
= (caddr_t
) (rxwi
+ 1);
4821 m
->m_pkthdr
.len
= m
->m_len
= len
;
4823 /* check for crc errors */
4825 if (desc_flags
& RT2860_RXDESC_FLAGS_CRC_ERR
)
4827 RT2860_DPRINTF(sc
, RT2860_DEBUG_RX
,
4828 "%s: rxdesc: crc error\n",
4829 device_get_nameunit(sc
->dev
));
4833 if (!(ifp
->if_flags
& IFF_PROMISC
))
4840 wh
= (struct ieee80211_frame
*) (rxwi
+ 1);
4842 /* check for cipher errors */
4844 if (desc_flags
& RT2860_RXDESC_FLAGS_DECRYPTED
)
4846 cipher_err
= ((desc_flags
>> RT2860_RXDESC_FLAGS_CIPHER_ERR_SHIFT
) &
4847 RT2860_RXDESC_FLAGS_CIPHER_ERR_MASK
);
4848 if (cipher_err
== RT2860_RXDESC_FLAGS_CIPHER_ERR_NONE
)
4850 if (wh
->i_fc
[1] & IEEE80211_FC1_WEP
)
4851 wh
->i_fc
[1] &= ~IEEE80211_FC1_WEP
;
4853 m
->m_flags
|= M_WEP
;
4855 sc
->rx_cipher_no_errors
++;
4859 RT2860_DPRINTF(sc
, RT2860_DEBUG_RX
,
4860 "%s: rxdesc: cipher error=0x%02x\n",
4861 device_get_nameunit(sc
->dev
), cipher_err
);
4863 if (cipher_err
== RT2860_RXDESC_FLAGS_CIPHER_ERR_ICV
)
4864 sc
->rx_cipher_icv_errors
++;
4865 else if (cipher_err
== RT2860_RXDESC_FLAGS_CIPHER_ERR_MIC
)
4866 sc
->rx_cipher_mic_errors
++;
4867 else if (cipher_err
== RT2860_RXDESC_FLAGS_CIPHER_ERR_INVALID_KEY
)
4868 sc
->rx_cipher_invalid_key_errors
++;
4870 if ((cipher_err
== RT2860_RXDESC_FLAGS_CIPHER_ERR_MIC
) &&
4871 (desc_flags
& RT2860_RXDESC_FLAGS_MYBSS
))
4873 keyidx
= (rxwi
->udf_bssidx_keyidx
>> RT2860_RXWI_KEYIDX_SHIFT
) &
4874 RT2860_RXWI_KEYIDX_MASK
;
4876 ieee80211_notify_michael_failure(ic
, wh
, keyidx
);
4881 if (!(ifp
->if_flags
& IFF_PROMISC
))
4890 if (wh
->i_fc
[1] & IEEE80211_FC1_WEP
)
4892 RT2860_DPRINTF(sc
, RT2860_DEBUG_RX
,
4893 "%s: rxdesc: not decrypted but protected flag set\n",
4894 device_get_nameunit(sc
->dev
));
4898 if (!(ifp
->if_flags
& IFF_PROMISC
))
4906 /* check for A-MPDU */
4908 if (desc_flags
& RT2860_RXDESC_FLAGS_AMPDU
)
4910 m
->m_flags
|= M_AMPDU
;
4921 /* check for A-MSDU */
4923 if (desc_flags
& RT2860_RXDESC_FLAGS_AMSDU
)
4934 ant
= rt2860_maxrssi_rxpath(sc
, rxwi
);
4935 rssi
= rxwi
->rssi
[ant
];
4936 rssi_dbm
= rt2860_rssi2dbm(sc
, rssi
, ant
);
4937 phymode
= ((rxwi
->phymode_stbc_shortgi
>> RT2860_RXWI_PHYMODE_SHIFT
) &
4938 RT2860_RXWI_PHYMODE_MASK
);
4939 bw
= ((rxwi
->bw_mcs
>> RT2860_RXWI_BW_SHIFT
) & RT2860_RXWI_BW_MASK
);
4940 shortgi
= ((rxwi
->phymode_stbc_shortgi
>> RT2860_RXWI_SHORTGI_SHIFT
) &
4941 RT2860_RXWI_SHORTGI_MASK
);
4942 mcs
= ((rxwi
->bw_mcs
>> RT2860_RXWI_MCS_SHIFT
) & RT2860_RXWI_MCS_MASK
);
4944 if (bpf_peers_present(sc
->drvbpf
))
4948 tap
->flags
= IEEE80211_RADIOTAP_F_DATAPAD
;
4949 tap
->dbm_antsignal
= rssi_dbm
;
4950 tap
->dbm_antnoise
= RT2860_NOISE_FLOOR
;
4952 tap
->antsignal
= rssi
;
4953 tap
->chan_flags
= htole32(ic
->ic_curchan
->ic_flags
);
4954 tap
->chan_freq
= htole16(ic
->ic_curchan
->ic_freq
);
4955 tap
->chan_ieee
= ic
->ic_curchan
->ic_ieee
;
4956 tap
->chan_maxpow
= 0;
4958 if (phymode
== RT2860_TXWI_PHYMODE_HT_MIXED
|| phymode
== RT2860_TXWI_PHYMODE_HT_GF
)
4959 tap
->rate
= mcs
| IEEE80211_RATE_MCS
;
4961 tap
->rate
= rt2860_rxrate(rxwi
);
4963 if (desc_flags
& RT2860_RXDESC_FLAGS_CRC_ERR
)
4964 tap
->flags
|= IEEE80211_RADIOTAP_F_BADFCS
;
4966 if (desc_flags
& RT2860_RXDESC_FLAGS_FRAG
)
4967 tap
->flags
|= IEEE80211_RADIOTAP_F_FRAG
;
4969 if (rxwi
->bw_mcs
& RT2860_RXWI_MCS_SHOTPRE
)
4970 tap
->flags
|= IEEE80211_RADIOTAP_F_SHORTPRE
;
4972 if ((desc_flags
& RT2860_RXDESC_FLAGS_DECRYPTED
) ||
4973 (wh
->i_fc
[1] & IEEE80211_FC1_WEP
))
4974 tap
->flags
|= IEEE80211_RADIOTAP_F_WEP
;
4977 tap
->flags
|= IEEE80211_RADIOTAP_F_SHORTGI
;
4979 bpf_mtap2(sc
->drvbpf
, tap
, sc
->rxtap_len
, m
);
4982 RT2860_DPRINTF(sc
, RT2860_DEBUG_RX
,
4983 "%s: received frame: len=%d, phymode=%d, bw=%d, shortgi=%d, mcs=%d, "
4984 "ant=%d, rssi=%d/%d/%d, snr=%d/%d, wcid=0x%02x, ampdu=%d, amsdu=%d\n",
4985 device_get_nameunit(sc
->dev
),
4986 len
, phymode
, bw
, shortgi
, mcs
,
4987 ant
, rxwi
->rssi
[0], rxwi
->rssi
[1], rxwi
->rssi
[2],
4988 rxwi
->snr
[0], rxwi
->snr
[1],
4989 rxwi
->wcid
, ampdu
, amsdu
);
4991 ni
= ieee80211_find_rxnode(ic
, (struct ieee80211_frame_min
*) wh
);
4995 rni
= (struct rt2860_softc_node
*) ni
;
4997 for (i
= 0; i
< RT2860_SOFTC_RSSI_COUNT
; i
++)
4999 rni
->last_rssi
[i
] = rxwi
->rssi
[i
];
5000 rni
->last_rssi_dbm
[i
] = rt2860_rssi2dbm(sc
, rxwi
->rssi
[i
], i
);
5004 ieee80211_input(ic
, m
, ni
, rssi_dbm
, RT2860_NOISE_FLOOR
, 0);
5006 ieee80211_free_node(ni
);
5010 desc
->sdl0
&= ~htole16(RT2860_RXDESC_SDL0_DDONE
);
5012 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
5013 BUS_DMASYNC_PREREAD
| BUS_DMASYNC_PREWRITE
);
5015 ring
->cur
= (ring
->cur
+ 1) % RT2860_SOFTC_RX_RING_DATA_COUNT
;
5021 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_CALC_IDX
,
5022 RT2860_SOFTC_RX_RING_DATA_COUNT
- 1);
5024 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_CALC_IDX
,
5027 RT2860_DPRINTF(sc
, RT2860_DEBUG_RX
,
5028 "%s: Rx eof: nframes=%d\n",
5029 device_get_nameunit(sc
->dev
), nframes
);
5031 sc
->rx_packets
+= nframes
;
5033 return (limit
== 0);
5039 static void rt2860_tx_eof(struct rt2860_softc
*sc
,
5040 struct rt2860_softc_tx_ring
*ring
)
5043 struct rt2860_txdesc
*desc
;
5044 struct rt2860_softc_tx_data
*data
;
5046 int ndescs
, nframes
;
5055 index
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_TX_DTX_IDX(ring
->qid
));
5056 if (ring
->desc_next
== index
)
5061 rt2860_drain_fifo_stats(sc
);
5063 desc
= &ring
->desc
[ring
->desc_next
];
5065 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
5066 BUS_DMASYNC_POSTREAD
);
5068 if (desc
->sdl0
& htole16(RT2860_TXDESC_SDL0_LASTSEG
) ||
5069 desc
->sdl1
& htole16(RT2860_TXDESC_SDL1_LASTSEG
))
5073 data
= &ring
->data
[ring
->data_next
];
5075 if (data
->m
->m_flags
& M_TXCB
)
5076 ieee80211_process_callback(data
->ni
, data
->m
, 0);
5078 bus_dmamap_sync(ring
->data_dma_tag
, data
->dma_map
,
5079 BUS_DMASYNC_POSTWRITE
);
5080 bus_dmamap_unload(ring
->data_dma_tag
, data
->dma_map
);
5084 ieee80211_free_node(data
->ni
);
5091 RT2860_SOFTC_LOCK(sc
);
5093 ring
->data_queued
--;
5094 ring
->data_next
= (ring
->data_next
+ 1) % RT2860_SOFTC_TX_RING_DATA_COUNT
;
5096 RT2860_SOFTC_UNLOCK(sc
);
5099 desc
->sdl0
&= ~htole16(RT2860_TXDESC_SDL0_DDONE
);
5101 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
5102 BUS_DMASYNC_PREREAD
| BUS_DMASYNC_PREWRITE
);
5104 RT2860_SOFTC_LOCK(sc
);
5106 ring
->desc_queued
--;
5107 ring
->desc_next
= (ring
->desc_next
+ 1) % RT2860_SOFTC_TX_RING_DESC_COUNT
;
5109 RT2860_SOFTC_UNLOCK(sc
);
5112 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
5113 "%s: Tx eof: qid=%d, ndescs=%d, nframes=%d\n",
5114 device_get_nameunit(sc
->dev
), ring
->qid
, ndescs
, nframes
);
5118 * rt2860_update_stats
5120 static void rt2860_update_stats(struct rt2860_softc
*sc
)
5123 struct ieee80211com
*ic
;
5124 struct ieee80211_node
*ni
;
5125 struct rt2860_softc_node
*rni
;
5127 int beacons
, noretryok
, retryok
, failed
, underflows
, zerolen
;
5133 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATS
,
5134 "%s: update statistic\n",
5135 device_get_nameunit(sc
->dev
));
5137 rt2860_drain_fifo_stats(sc
);
5139 /* read and clear Tx statistic registers */
5141 rt2860_io_mac_read_multi(sc
, RT2860_REG_TX_STA_CNT0
,
5142 stacnt
, sizeof(stacnt
));
5144 stacnt
[0] = le32toh(stacnt
[0]);
5145 stacnt
[1] = le32toh(stacnt
[1]);
5146 stacnt
[2] = le32toh(stacnt
[2]);
5148 beacons
= stacnt
[0] >> 16;
5149 noretryok
= stacnt
[1] & 0xffff;
5150 retryok
= stacnt
[1] >> 16;
5151 failed
= stacnt
[0] & 0xffff;
5152 underflows
= stacnt
[2] >> 16;
5153 zerolen
= stacnt
[2] & 0xffff;
5155 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATS
,
5156 "%s: update statistic: beacons=%d, noretryok=%d, retryok=%d, failed=%d, underflows=%d, zerolen=%d\n",
5157 device_get_nameunit(sc
->dev
),
5158 beacons
, noretryok
, retryok
, failed
, underflows
, zerolen
);
5160 ifp
->if_oerrors
+= failed
;
5162 sc
->tx_beacons
+= beacons
;
5163 sc
->tx_noretryok
+= noretryok
;
5164 sc
->tx_retryok
+= retryok
;
5165 sc
->tx_failed
+= failed
;
5166 sc
->tx_underflows
+= underflows
;
5167 sc
->tx_zerolen
+= zerolen
;
5169 if (ic
->ic_opmode
== IEEE80211_M_STA
&& ic
->ic_state
== IEEE80211_S_RUN
)
5172 rni
= (struct rt2860_softc_node
*) ni
;
5175 rt2860_amrr_tx_update(&sc
->amrr_node
[wcid
],
5176 noretryok
+ retryok
+ failed
, noretryok
+ retryok
, retryok
+ failed
);
5183 static void rt2860_bbp_tuning(struct rt2860_softc
*sc
)
5185 struct ieee80211com
*ic
;
5186 struct ieee80211_node
*ni
;
5188 int8_t rssi
, old
, new;
5190 /* RT2860C does not support BBP tuning */
5192 if (sc
->mac_rev
== 0x28600100)
5197 if ((ic
->ic_flags
& IEEE80211_F_SCAN
) ||
5198 ic
->ic_opmode
!= IEEE80211_M_STA
|| ic
->ic_state
!= IEEE80211_S_RUN
)
5203 chan
= ieee80211_chan2ieee(ic
, ni
->ni_chan
);
5207 else if (chan
<= 64)
5209 else if (chan
<= 128)
5214 rssi
= ieee80211_getrssi(ic
);
5216 if (IEEE80211_IS_CHAN_2GHZ(ni
->ni_chan
))
5218 new = 0x2e + sc
->lna_gain
[group
];
5222 if (!IEEE80211_IS_CHAN_HT40(ni
->ni_chan
))
5223 new = 0x32 + sc
->lna_gain
[group
] * 5 / 3;
5225 new = 0x3a + sc
->lna_gain
[group
] * 5 / 3;
5228 /* Tune if absolute average RSSI is greater than -80 */
5233 old
= rt2860_io_bbp_read(sc
, 66);
5236 rt2860_io_bbp_write(sc
, 66, new);
5242 static void rt2860_watchdog(struct rt2860_softc
*sc
)
5247 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_PBF_TXRXQ_PCNT
);
5249 RT2860_DPRINTF(sc
, RT2860_DEBUG_WATCHDOG
,
5250 "%s: watchdog: TXRXQ_PCNT=0x%08x\n",
5251 device_get_nameunit(sc
->dev
), tmp
);
5253 if (((tmp
>> RT2860_REG_TX0Q_PCNT_SHIFT
) & RT2860_REG_TX0Q_PCNT_MASK
) != 0)
5255 sc
->tx_queue_not_empty
[0]++;
5257 rt2860_io_mac_write(sc
, RT2860_REG_PBF_CFG
, 0xf40012);
5259 for (ntries
= 0; ntries
< 10; ntries
++)
5261 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_PBF_TXRXQ_PCNT
);
5262 if (((tmp
>> RT2860_REG_TX0Q_PCNT_SHIFT
) & RT2860_REG_TX0Q_PCNT_MASK
) == 0)
5268 rt2860_io_mac_write(sc
, RT2860_REG_PBF_CFG
, 0xf40006);
5271 if (((tmp
>> RT2860_REG_TX1Q_PCNT_SHIFT
) & RT2860_REG_TX1Q_PCNT_MASK
) != 0)
5273 sc
->tx_queue_not_empty
[1]++;
5275 rt2860_io_mac_write(sc
, RT2860_REG_PBF_CFG
, 0xf4000a);
5277 for (ntries
= 0; ntries
< 10; ntries
++)
5279 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_PBF_TXRXQ_PCNT
);
5280 if (((tmp
>> RT2860_REG_TX1Q_PCNT_SHIFT
) & RT2860_REG_TX1Q_PCNT_MASK
) == 0)
5286 rt2860_io_mac_write(sc
, RT2860_REG_PBF_CFG
, 0xf40006);
5291 * rt2860_drain_fifo_stats
5293 static void rt2860_drain_fifo_stats(struct rt2860_softc
*sc
)
5297 uint8_t wcid
, mcs
, pid
;
5298 int ok
, agg
, retrycnt
;
5300 ifp
= sc
->ic
.ic_ifp
;
5302 /* drain Tx status FIFO (maxsize = 16) */
5304 while ((stats
= rt2860_io_mac_read(sc
, RT2860_REG_TX_STA_FIFO
)) &
5305 RT2860_REG_TX_STA_FIFO_VALID
)
5307 wcid
= (stats
>> RT2860_REG_TX_STA_FIFO_WCID_SHIFT
) &
5308 RT2860_REG_TX_STA_FIFO_WCID_MASK
;
5310 /* if no ACK was requested, no feedback is available */
5312 if (!(stats
& RT2860_REG_TX_STA_FIFO_ACK_REQ
) || wcid
== RT2860_WCID_RESERVED
)
5315 /* update AMRR statistic */
5317 ok
= (stats
& RT2860_REG_TX_STA_FIFO_TX_OK
) ? 1 : 0;
5318 agg
= (stats
& RT2860_REG_TX_STA_FIFO_AGG
) ? 1 : 0;
5319 mcs
= (stats
>> RT2860_REG_TX_STA_FIFO_MCS_SHIFT
) &
5320 RT2860_REG_TX_STA_FIFO_MCS_MASK
;
5321 pid
= (stats
>> RT2860_REG_TX_STA_FIFO_PID_SHIFT
) &
5322 RT2860_REG_TX_STA_FIFO_PID_MASK
;
5323 retrycnt
= pid
- mcs
;
5325 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATS
,
5326 "%s: FIFO statistic: wcid=0x%02x, ok=%d, agg=%d, mcs=0x%02x, pid=0x%02x, retrycnt=%d\n",
5327 device_get_nameunit(sc
->dev
),
5328 wcid
, ok
, agg
, mcs
, pid
, retrycnt
);
5330 rt2860_amrr_tx_complete(&sc
->amrr_node
[wcid
], ok
, retrycnt
);
5338 * rt2860_update_raw_counters
5340 static void rt2860_update_raw_counters(struct rt2860_softc
*sc
)
5344 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_AGG_CNT
);
5346 sc
->tx_nonagg
+= tmp
& 0xffff;
5347 sc
->tx_agg
+= tmp
>> 16;
5349 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_AGG_CNT0
);
5351 sc
->tx_ampdu
+= (tmp
& 0xffff) / 1 + (tmp
>> 16) / 2;
5353 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_AGG_CNT1
);
5355 sc
->tx_ampdu
+= (tmp
& 0xffff) / 3 + (tmp
>> 16) / 4;
5357 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_AGG_CNT2
);
5359 sc
->tx_ampdu
+= (tmp
& 0xffff) / 5 + (tmp
>> 16) / 6;
5361 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_AGG_CNT3
);
5363 sc
->tx_ampdu
+= (tmp
& 0xffff) / 7 + (tmp
>> 16) / 8;
5365 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_AGG_CNT4
);
5367 sc
->tx_ampdu
+= (tmp
& 0xffff) / 9 + (tmp
>> 16) / 10;
5369 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_AGG_CNT5
);
5371 sc
->tx_ampdu
+= (tmp
& 0xffff) / 11 + (tmp
>> 16) / 12;
5373 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_AGG_CNT6
);
5375 sc
->tx_ampdu
+= (tmp
& 0xffff) / 13 + (tmp
>> 16) / 14;
5377 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_AGG_CNT7
);
5379 sc
->tx_ampdu
+= (tmp
& 0xffff) / 15 + (tmp
>> 16) / 16;
5381 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_RX_STA_CNT0
);
5383 sc
->rx_crc_errors
+= tmp
& 0xffff;
5384 sc
->rx_phy_errors
+= tmp
>> 16;
5386 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_RX_STA_CNT1
);
5388 sc
->rx_false_ccas
+= tmp
& 0xffff;
5389 sc
->rx_plcp_errors
+= tmp
>> 16;
5391 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_RX_STA_CNT2
);
5393 sc
->rx_dup_packets
+= tmp
& 0xffff;
5394 sc
->rx_fifo_overflows
+= tmp
>> 16;
5396 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TXRX_MPDU_DEN_CNT
);
5398 sc
->tx_mpdu_zero_density
+= tmp
& 0xffff;
5399 sc
->rx_mpdu_zero_density
+= tmp
>> 16;
5403 * rt2860_intr_enable
5405 static void rt2860_intr_enable(struct rt2860_softc
*sc
, uint32_t intr_mask
)
5409 sc
->intr_disable_mask
&= ~intr_mask
;
5411 tmp
= sc
->intr_enable_mask
& ~sc
->intr_disable_mask
;
5413 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_INT_MASK
, tmp
);
5417 * rt2860_intr_disable
5419 static void rt2860_intr_disable(struct rt2860_softc
*sc
, uint32_t intr_mask
)
5423 sc
->intr_disable_mask
|= intr_mask
;
5425 tmp
= sc
->intr_enable_mask
& ~sc
->intr_disable_mask
;
5427 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_INT_MASK
, tmp
);
5431 * rt2860_txrx_enable
5433 static int rt2860_txrx_enable(struct rt2860_softc
*sc
)
5435 struct ieee80211com
*ic
;
5443 /* enable Tx/Rx DMA engine */
5445 rt2860_io_mac_write(sc
, RT2860_REG_SYS_CTRL
, RT2860_REG_TX_ENABLE
);
5447 for (ntries
= 0; ntries
< 200; ntries
++)
5449 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
);
5450 if (!(tmp
& (RT2860_REG_TX_DMA_BUSY
| RT2860_REG_RX_DMA_BUSY
)))
5458 printf("%s: timeout waiting for DMA engine\n",
5459 device_get_nameunit(sc
->dev
));
5465 tmp
|= RT2860_REG_TX_WB_DDONE
|
5466 RT2860_REG_RX_DMA_ENABLE
|
5467 RT2860_REG_TX_DMA_ENABLE
|
5468 (RT2860_REG_WPDMA_BT_SIZE64
<< RT2860_REG_WPDMA_BT_SIZE_SHIFT
);
5470 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
, tmp
);
5474 tmp
= RT2860_REG_RX_FILTER_DROP_CRC_ERR
|
5475 RT2860_REG_RX_FILTER_DROP_PHY_ERR
;
5477 if (ic
->ic_opmode
!= IEEE80211_M_MONITOR
)
5479 tmp
|= RT2860_REG_RX_FILTER_DROP_DUPL
|
5480 RT2860_REG_RX_FILTER_DROP_CTS
|
5481 RT2860_REG_RX_FILTER_DROP_BA
|
5482 RT2860_REG_RX_FILTER_DROP_ACK
|
5483 RT2860_REG_RX_FILTER_DROP_VER_ERR
|
5484 RT2860_REG_RX_FILTER_DROP_CTRL_RSV
|
5485 RT2860_REG_RX_FILTER_DROP_CFACK
|
5486 RT2860_REG_RX_FILTER_DROP_CFEND
;
5488 if (ic
->ic_opmode
== IEEE80211_M_STA
)
5489 tmp
|= RT2860_REG_RX_FILTER_DROP_RTS
|
5490 RT2860_REG_RX_FILTER_DROP_PSPOLL
;
5492 if (!(ifp
->if_flags
& IFF_PROMISC
))
5493 tmp
|= RT2860_REG_RX_FILTER_DROP_UC_NOME
;
5496 rt2860_io_mac_write(sc
, RT2860_REG_RX_FILTER_CFG
, tmp
);
5498 rt2860_io_mac_write(sc
, RT2860_REG_SYS_CTRL
,
5499 RT2860_REG_RX_ENABLE
| RT2860_REG_TX_ENABLE
);
5505 * rt2860_alloc_rx_ring
5507 static int rt2860_alloc_rx_ring(struct rt2860_softc
*sc
,
5508 struct rt2860_softc_rx_ring
*ring
)
5510 struct rt2860_rxdesc
*desc
;
5511 struct rt2860_softc_rx_data
*data
;
5512 bus_dma_segment_t segs
[1];
5513 int i
, nsegs
, error
;
5515 error
= bus_dma_tag_create(bus_get_dma_tag(sc
->dev
), PAGE_SIZE
, 0,
5516 BUS_SPACE_MAXADDR_32BIT
, BUS_SPACE_MAXADDR
, NULL
, NULL
,
5517 RT2860_SOFTC_RX_RING_DATA_COUNT
* sizeof(struct rt2860_rxdesc
), 1,
5518 RT2860_SOFTC_RX_RING_DATA_COUNT
* sizeof(struct rt2860_rxdesc
),
5519 0, NULL
, NULL
, &ring
->desc_dma_tag
);
5522 printf("%s: could not create Rx desc DMA tag\n",
5523 device_get_nameunit(sc
->dev
));
5527 error
= bus_dmamem_alloc(ring
->desc_dma_tag
, (void **) &ring
->desc
,
5528 BUS_DMA_NOWAIT
| BUS_DMA_ZERO
, &ring
->desc_dma_map
);
5531 printf("%s: could not allocate Rx desc DMA memory\n",
5532 device_get_nameunit(sc
->dev
));
5536 error
= bus_dmamap_load(ring
->desc_dma_tag
, ring
->desc_dma_map
,
5538 RT2860_SOFTC_RX_RING_DATA_COUNT
* sizeof(struct rt2860_rxdesc
),
5539 rt2860_dma_map_addr
, &ring
->desc_phys_addr
, 0);
5542 printf("%s: could not load Rx desc DMA map\n",
5543 device_get_nameunit(sc
->dev
));
5547 error
= bus_dma_tag_create(bus_get_dma_tag(sc
->dev
), PAGE_SIZE
, 0,
5548 BUS_SPACE_MAXADDR_32BIT
, BUS_SPACE_MAXADDR
, NULL
, NULL
,
5549 MJUMPAGESIZE
, 1, MJUMPAGESIZE
, 0, NULL
, NULL
,
5550 &ring
->data_dma_tag
);
5553 printf("%s: could not create Rx data DMA tag\n",
5554 device_get_nameunit(sc
->dev
));
5558 for (i
= 0; i
< RT2860_SOFTC_RX_RING_DATA_COUNT
; i
++)
5560 desc
= &ring
->desc
[i
];
5561 data
= &ring
->data
[i
];
5563 error
= bus_dmamap_create(ring
->data_dma_tag
, 0, &data
->dma_map
);
5566 printf("%s: could not create Rx data DMA map\n",
5567 device_get_nameunit(sc
->dev
));
5571 data
->m
= m_getjcl(M_DONTWAIT
, MT_DATA
, M_PKTHDR
, MJUMPAGESIZE
);
5572 if (data
->m
== NULL
)
5574 printf("%s: could not allocate Rx mbuf\n",
5575 device_get_nameunit(sc
->dev
));
5580 data
->m
->m_len
= data
->m
->m_pkthdr
.len
= MJUMPAGESIZE
;
5582 error
= bus_dmamap_load_mbuf_sg(ring
->data_dma_tag
, data
->dma_map
,
5583 data
->m
, segs
, &nsegs
, BUS_DMA_NOWAIT
);
5586 printf("%s: could not load Rx mbuf DMA map\n",
5587 device_get_nameunit(sc
->dev
));
5591 KASSERT(nsegs
== 1, ("%s: too many DMA segments",
5592 device_get_name(sc
->dev
)));
5594 desc
->sdp0
= htole32(segs
[0].ds_addr
);
5595 desc
->sdl0
= htole16(MJUMPAGESIZE
);
5598 error
= bus_dmamap_create(ring
->data_dma_tag
, 0, &ring
->spare_dma_map
);
5601 printf("%s: could not create Rx spare DMA map\n",
5602 device_get_nameunit(sc
->dev
));
5606 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
5607 BUS_DMASYNC_PREWRITE
);
5613 rt2860_free_rx_ring(sc
, ring
);
5619 * rt2860_reset_rx_ring
5621 static void rt2860_reset_rx_ring(struct rt2860_softc
*sc
,
5622 struct rt2860_softc_rx_ring
*ring
)
5624 struct rt2860_rxdesc
*desc
;
5627 for (i
= 0; i
< RT2860_SOFTC_RX_RING_DATA_COUNT
; i
++)
5629 desc
= &ring
->desc
[i
];
5631 desc
->sdl0
&= ~htole16(RT2860_RXDESC_SDL0_DDONE
);
5634 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
5635 BUS_DMASYNC_PREWRITE
);
5641 * rt2860_free_rx_ring
5643 static void rt2860_free_rx_ring(struct rt2860_softc
*sc
,
5644 struct rt2860_softc_rx_ring
*ring
)
5646 struct rt2860_softc_rx_data
*data
;
5649 if (ring
->desc
!= NULL
)
5651 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
5652 BUS_DMASYNC_POSTWRITE
);
5653 bus_dmamap_unload(ring
->desc_dma_tag
, ring
->desc_dma_map
);
5654 bus_dmamem_free(ring
->desc_dma_tag
, ring
->desc
,
5655 ring
->desc_dma_map
);
5658 if (ring
->desc_dma_tag
!= NULL
)
5659 bus_dma_tag_destroy(ring
->desc_dma_tag
);
5661 for (i
= 0; i
< RT2860_SOFTC_RX_RING_DATA_COUNT
; i
++)
5663 data
= &ring
->data
[i
];
5665 if (data
->m
!= NULL
)
5667 bus_dmamap_sync(ring
->data_dma_tag
, data
->dma_map
,
5668 BUS_DMASYNC_POSTREAD
);
5669 bus_dmamap_unload(ring
->data_dma_tag
, data
->dma_map
);
5673 if (data
->dma_map
!= NULL
)
5674 bus_dmamap_destroy(ring
->data_dma_tag
, data
->dma_map
);
5677 if (ring
->spare_dma_map
!= NULL
)
5678 bus_dmamap_destroy(ring
->data_dma_tag
, ring
->spare_dma_map
);
5680 if (ring
->data_dma_tag
!= NULL
)
5681 bus_dma_tag_destroy(ring
->data_dma_tag
);
5685 * rt2860_alloc_tx_ring
5687 static int rt2860_alloc_tx_ring(struct rt2860_softc
*sc
,
5688 struct rt2860_softc_tx_ring
*ring
, int qid
)
5690 struct rt2860_softc_tx_data
*data
;
5693 error
= bus_dma_tag_create(bus_get_dma_tag(sc
->dev
), PAGE_SIZE
, 0,
5694 BUS_SPACE_MAXADDR_32BIT
, BUS_SPACE_MAXADDR
, NULL
, NULL
,
5695 RT2860_SOFTC_TX_RING_DESC_COUNT
* sizeof(struct rt2860_txdesc
), 1,
5696 RT2860_SOFTC_TX_RING_DESC_COUNT
* sizeof(struct rt2860_txdesc
),
5697 0, NULL
, NULL
, &ring
->desc_dma_tag
);
5700 printf("%s: could not create Tx desc DMA tag\n",
5701 device_get_nameunit(sc
->dev
));
5705 error
= bus_dmamem_alloc(ring
->desc_dma_tag
, (void **) &ring
->desc
,
5706 BUS_DMA_NOWAIT
| BUS_DMA_ZERO
, &ring
->desc_dma_map
);
5709 printf("%s: could not allocate Tx desc DMA memory\n",
5710 device_get_nameunit(sc
->dev
));
5714 error
= bus_dmamap_load(ring
->desc_dma_tag
, ring
->desc_dma_map
,
5716 RT2860_SOFTC_TX_RING_DESC_COUNT
* sizeof(struct rt2860_txdesc
),
5717 rt2860_dma_map_addr
, &ring
->desc_phys_addr
, 0);
5720 printf("%s: could not load Tx desc DMA map\n",
5721 device_get_nameunit(sc
->dev
));
5725 ring
->desc_queued
= 0;
5727 ring
->desc_next
= 0;
5729 error
= bus_dma_tag_create(bus_get_dma_tag(sc
->dev
), PAGE_SIZE
, 0,
5730 BUS_SPACE_MAXADDR_32BIT
, BUS_SPACE_MAXADDR
, NULL
, NULL
,
5731 RT2860_SOFTC_TX_RING_DATA_COUNT
* RT2860_TX_DATA_SEG0_SIZE
, 1,
5732 RT2860_SOFTC_TX_RING_DATA_COUNT
* RT2860_TX_DATA_SEG0_SIZE
,
5733 0, NULL
, NULL
, &ring
->seg0_dma_tag
);
5736 printf("%s: could not create Tx seg0 DMA tag\n",
5737 device_get_nameunit(sc
->dev
));
5741 error
= bus_dmamem_alloc(ring
->seg0_dma_tag
, (void **) &ring
->seg0
,
5742 BUS_DMA_NOWAIT
| BUS_DMA_ZERO
, &ring
->seg0_dma_map
);
5745 printf("%s: could not allocate Tx seg0 DMA memory\n",
5746 device_get_nameunit(sc
->dev
));
5750 error
= bus_dmamap_load(ring
->seg0_dma_tag
, ring
->seg0_dma_map
,
5752 RT2860_SOFTC_TX_RING_DATA_COUNT
* RT2860_TX_DATA_SEG0_SIZE
,
5753 rt2860_dma_map_addr
, &ring
->seg0_phys_addr
, 0);
5756 printf("%s: could not load Tx seg0 DMA map\n",
5757 device_get_nameunit(sc
->dev
));
5761 error
= bus_dma_tag_create(bus_get_dma_tag(sc
->dev
), PAGE_SIZE
, 0,
5762 BUS_SPACE_MAXADDR_32BIT
, BUS_SPACE_MAXADDR
, NULL
, NULL
,
5763 MJUMPAGESIZE
, RT2860_SOFTC_MAX_SCATTER
, MJUMPAGESIZE
, 0, NULL
, NULL
,
5764 &ring
->data_dma_tag
);
5767 printf("%s: could not create Tx data DMA tag\n",
5768 device_get_nameunit(sc
->dev
));
5772 for (i
= 0; i
< RT2860_SOFTC_TX_RING_DATA_COUNT
; i
++)
5774 data
= &ring
->data
[i
];
5776 error
= bus_dmamap_create(ring
->data_dma_tag
, 0, &data
->dma_map
);
5779 printf("%s: could not create Tx data DMA map\n",
5780 device_get_nameunit(sc
->dev
));
5785 ring
->data_queued
= 0;
5787 ring
->data_next
= 0;
5795 rt2860_free_tx_ring(sc
, ring
);
5801 * rt2860_reset_tx_ring
5803 static void rt2860_reset_tx_ring(struct rt2860_softc
*sc
,
5804 struct rt2860_softc_tx_ring
*ring
)
5806 struct rt2860_softc_tx_data
*data
;
5807 struct rt2860_txdesc
*desc
;
5810 for (i
= 0; i
< RT2860_SOFTC_TX_RING_DESC_COUNT
; i
++)
5812 desc
= &ring
->desc
[i
];
5818 ring
->desc_queued
= 0;
5820 ring
->desc_next
= 0;
5822 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
5823 BUS_DMASYNC_PREWRITE
);
5825 bus_dmamap_sync(ring
->seg0_dma_tag
, ring
->seg0_dma_map
,
5826 BUS_DMASYNC_PREWRITE
);
5828 for (i
= 0; i
< RT2860_SOFTC_TX_RING_DATA_COUNT
; i
++)
5830 data
= &ring
->data
[i
];
5832 if (data
->m
!= NULL
)
5834 bus_dmamap_sync(ring
->data_dma_tag
, data
->dma_map
,
5835 BUS_DMASYNC_POSTWRITE
);
5836 bus_dmamap_unload(ring
->data_dma_tag
, data
->dma_map
);
5841 if (data
->ni
!= NULL
)
5843 ieee80211_free_node(data
->ni
);
5848 ring
->data_queued
= 0;
5850 ring
->data_next
= 0;
5854 * rt2860_free_tx_ring
5856 static void rt2860_free_tx_ring(struct rt2860_softc
*sc
,
5857 struct rt2860_softc_tx_ring
*ring
)
5859 struct rt2860_softc_tx_data
*data
;
5862 if (ring
->desc
!= NULL
)
5864 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
5865 BUS_DMASYNC_POSTWRITE
);
5866 bus_dmamap_unload(ring
->desc_dma_tag
, ring
->desc_dma_map
);
5867 bus_dmamem_free(ring
->desc_dma_tag
, ring
->desc
,
5868 ring
->desc_dma_map
);
5871 if (ring
->desc_dma_tag
!= NULL
)
5872 bus_dma_tag_destroy(ring
->desc_dma_tag
);
5874 if (ring
->seg0
!= NULL
)
5876 bus_dmamap_sync(ring
->seg0_dma_tag
, ring
->seg0_dma_map
,
5877 BUS_DMASYNC_POSTWRITE
);
5878 bus_dmamap_unload(ring
->seg0_dma_tag
, ring
->seg0_dma_map
);
5879 bus_dmamem_free(ring
->seg0_dma_tag
, ring
->seg0
,
5880 ring
->seg0_dma_map
);
5883 if (ring
->seg0_dma_tag
!= NULL
)
5884 bus_dma_tag_destroy(ring
->seg0_dma_tag
);
5886 for (i
= 0; i
< RT2860_SOFTC_TX_RING_DATA_COUNT
; i
++)
5888 data
= &ring
->data
[i
];
5890 if (data
->m
!= NULL
)
5892 bus_dmamap_sync(ring
->data_dma_tag
, data
->dma_map
,
5893 BUS_DMASYNC_POSTWRITE
);
5894 bus_dmamap_unload(ring
->data_dma_tag
, data
->dma_map
);
5898 if (data
->ni
!= NULL
)
5899 ieee80211_free_node(data
->ni
);
5901 if (data
->dma_map
!= NULL
)
5902 bus_dmamap_destroy(ring
->data_dma_tag
, data
->dma_map
);
5905 if (ring
->data_dma_tag
!= NULL
)
5906 bus_dma_tag_destroy(ring
->data_dma_tag
);
5910 * rt2860_dma_map_addr
5912 static void rt2860_dma_map_addr(void *arg
, bus_dma_segment_t
*segs
,
5913 int nseg
, int error
)
5918 KASSERT(nseg
== 1, ("too many DMA segments, %d should be 1", nseg
));
5920 *(bus_addr_t
*) arg
= segs
[0].ds_addr
;
5924 * rt2860_sysctl_attach
5926 static void rt2860_sysctl_attach(struct rt2860_softc
*sc
)
5928 struct sysctl_ctx_list
*ctx
;
5929 struct sysctl_oid
*tree
;
5930 struct sysctl_oid
*stats
;
5932 ctx
= device_get_sysctl_ctx(sc
->dev
);
5933 tree
= device_get_sysctl_tree(sc
->dev
);
5935 stats
= SYSCTL_ADD_NODE(ctx
, SYSCTL_CHILDREN(tree
), OID_AUTO
,
5936 "stats", CTLFLAG_RD
, 0, "statistic");
5938 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5939 "interrupts", CTLFLAG_RD
, &sc
->interrupts
, 0,
5942 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5943 "tx_coherent_interrupts", CTLFLAG_RD
, &sc
->tx_coherent_interrupts
, 0,
5944 "Tx coherent interrupts");
5946 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5947 "rx_coherent_interrupts", CTLFLAG_RD
, &sc
->rx_coherent_interrupts
, 0,
5948 "Rx coherent interrupts");
5950 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5951 "txrx_coherent_interrupts", CTLFLAG_RD
, &sc
->txrx_coherent_interrupts
, 0,
5952 "Tx/Rx coherent interrupts");
5954 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5955 "fifo_sta_full_interrupts", CTLFLAG_RD
, &sc
->fifo_sta_full_interrupts
, 0,
5956 "FIFO statistic full interrupts");
5958 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5959 "rx_interrupts", CTLFLAG_RD
, &sc
->rx_interrupts
, 0,
5962 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5963 "rx_delay_interrupts", CTLFLAG_RD
, &sc
->rx_delay_interrupts
, 0,
5964 "Rx delay interrupts");
5966 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5967 "tx_mgmt_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[5], 0,
5968 "Tx MGMT interrupts");
5970 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5971 "tx_hcca_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[4], 0,
5972 "Tx HCCA interrupts");
5974 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5975 "tx_ac3_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[3], 0,
5976 "Tx AC3 interrupts");
5978 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5979 "tx_ac2_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[2], 0,
5980 "Tx AC2 interrupts");
5982 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5983 "tx_ac1_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[1], 0,
5984 "Tx AC1 interrupts");
5986 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5987 "tx_ac0_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[0], 0,
5988 "Tx AC0 interrupts");
5990 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5991 "tx_delay_interrupts", CTLFLAG_RD
, &sc
->tx_delay_interrupts
, 0,
5992 "Tx delay interrupts");
5994 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5995 "pre_tbtt_interrupts", CTLFLAG_RD
, &sc
->pre_tbtt_interrupts
, 0,
5996 "Pre-TBTT interrupts");
5998 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5999 "tbtt_interrupts", CTLFLAG_RD
, &sc
->tbtt_interrupts
, 0,
6002 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6003 "mcu_cmd_interrupts", CTLFLAG_RD
, &sc
->mcu_cmd_interrupts
, 0,
6004 "MCU command interrupts");
6006 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6007 "auto_wakeup_interrupts", CTLFLAG_RD
, &sc
->auto_wakeup_interrupts
, 0,
6008 "auto wakeup interrupts");
6010 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6011 "gp_timer_interrupts", CTLFLAG_RD
, &sc
->gp_timer_interrupts
, 0,
6012 "GP timer interrupts");
6014 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6015 "tx_mgmt_desc_queued", CTLFLAG_RD
, &sc
->tx_ring
[5].desc_queued
, 0,
6016 "Tx MGMT descriptors queued");
6018 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6019 "tx_mgmt_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[5].data_queued
, 0,
6020 "Tx MGMT data queued");
6022 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6023 "tx_hcca_desc_queued", CTLFLAG_RD
, &sc
->tx_ring
[4].desc_queued
, 0,
6024 "Tx HCCA descriptors queued");
6026 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6027 "tx_hcca_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[4].data_queued
, 0,
6028 "Tx HCCA data queued");
6030 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6031 "tx_ac3_desc_queued", CTLFLAG_RD
, &sc
->tx_ring
[3].desc_queued
, 0,
6032 "Tx AC3 descriptors queued");
6034 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6035 "tx_ac3_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[3].data_queued
, 0,
6036 "Tx AC3 data queued");
6038 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6039 "tx_ac2_desc_queued", CTLFLAG_RD
, &sc
->tx_ring
[2].desc_queued
, 0,
6040 "Tx AC2 descriptors queued");
6042 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6043 "tx_ac2_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[2].data_queued
, 0,
6044 "Tx AC2 data queued");
6046 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6047 "tx_ac1_desc_queued", CTLFLAG_RD
, &sc
->tx_ring
[1].desc_queued
, 0,
6048 "Tx AC1 descriptors queued");
6050 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6051 "tx_ac1_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[1].data_queued
, 0,
6052 "Tx AC1 data queued");
6054 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6055 "tx_ac0_desc_queued", CTLFLAG_RD
, &sc
->tx_ring
[0].desc_queued
, 0,
6056 "Tx AC0 descriptors queued");
6058 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6059 "tx_ac0_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[0].data_queued
, 0,
6060 "Tx AC0 data queued");
6062 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6063 "tx_mgmt_data_queue_full", CTLFLAG_RD
, &sc
->tx_data_queue_full
[5], 0,
6064 "Tx MGMT data queue full");
6066 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6067 "tx_hcca_data_queue_full", CTLFLAG_RD
, &sc
->tx_data_queue_full
[4], 0,
6068 "Tx HCCA data queue full");
6070 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6071 "tx_ac3_data_queue_full", CTLFLAG_RD
, &sc
->tx_data_queue_full
[3], 0,
6072 "Tx AC3 data queue full");
6074 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6075 "tx_ac2_data_queue_full", CTLFLAG_RD
, &sc
->tx_data_queue_full
[2], 0,
6076 "Tx AC2 data queue full");
6078 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6079 "tx_ac1_data_queue_full", CTLFLAG_RD
, &sc
->tx_data_queue_full
[1], 0,
6080 "Tx AC1 data queue full");
6082 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6083 "tx_ac0_data_queue_full", CTLFLAG_RD
, &sc
->tx_data_queue_full
[0], 0,
6084 "Tx AC0 data queue full");
6086 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6087 "tx_watchdog_timeouts", CTLFLAG_RD
, &sc
->tx_watchdog_timeouts
, 0,
6088 "Tx watchdog timeouts");
6090 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6091 "tx_defrag_packets", CTLFLAG_RD
, &sc
->tx_defrag_packets
, 0,
6092 "Tx defragmented packets");
6094 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6095 "no_tx_desc_avail", CTLFLAG_RD
, &sc
->no_tx_desc_avail
, 0,
6096 "no Tx descriptors available");
6098 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6099 "rx_mbuf_alloc_errors", CTLFLAG_RD
, &sc
->rx_mbuf_alloc_errors
, 0,
6100 "Rx mbuf allocation errors");
6102 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6103 "rx_mbuf_dmamap_errors", CTLFLAG_RD
, &sc
->rx_mbuf_dmamap_errors
, 0,
6104 "Rx mbuf DMA mapping errors");
6106 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6107 "tx_queue_0_not_empty", CTLFLAG_RD
, &sc
->tx_queue_not_empty
[0], 0,
6108 "Tx queue 0 not empty");
6110 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6111 "tx_queue_1_not_empty", CTLFLAG_RD
, &sc
->tx_queue_not_empty
[1], 0,
6112 "Tx queue 1 not empty");
6114 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6115 "tx_beacons", CTLFLAG_RD
, &sc
->tx_beacons
, 0,
6118 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6119 "tx_noretryok", CTLFLAG_RD
, &sc
->tx_noretryok
, 0,
6120 "Tx successfull without retries");
6122 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6123 "tx_retryok", CTLFLAG_RD
, &sc
->tx_retryok
, 0,
6124 "Tx successfull with retries");
6126 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6127 "tx_failed", CTLFLAG_RD
, &sc
->tx_failed
, 0,
6130 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6131 "tx_underflows", CTLFLAG_RD
, &sc
->tx_underflows
, 0,
6134 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6135 "tx_zerolen", CTLFLAG_RD
, &sc
->tx_zerolen
, 0,
6138 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6139 "tx_nonagg", CTLFLAG_RD
, &sc
->tx_nonagg
, 0,
6140 "Tx non-aggregated");
6142 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6143 "tx_agg", CTLFLAG_RD
, &sc
->tx_agg
, 0,
6146 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6147 "tx_ampdu", CTLFLAG_RD
, &sc
->tx_ampdu
, 0,
6150 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6151 "tx_mpdu_zero_density", CTLFLAG_RD
, &sc
->tx_mpdu_zero_density
, 0,
6152 "Tx MPDU with zero density");
6154 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6155 "rx_packets", CTLFLAG_RD
, &sc
->rx_packets
, 0,
6158 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6159 "rx_ampdu", CTLFLAG_RD
, &sc
->rx_ampdu
, 0,
6162 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6163 "rx_mpdu_zero_density", CTLFLAG_RD
, &sc
->rx_mpdu_zero_density
, 0,
6164 "Rx MPDU with zero density");
6166 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6167 "rx_amsdu", CTLFLAG_RD
, &sc
->rx_amsdu
, 0,
6170 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6171 "rx_crc_errors", CTLFLAG_RD
, &sc
->rx_crc_errors
, 0,
6174 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6175 "rx_phy_errors", CTLFLAG_RD
, &sc
->rx_phy_errors
, 0,
6178 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6179 "rx_false_ccas", CTLFLAG_RD
, &sc
->rx_false_ccas
, 0,
6182 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6183 "rx_plcp_errors", CTLFLAG_RD
, &sc
->rx_plcp_errors
, 0,
6186 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6187 "rx_dup_packets", CTLFLAG_RD
, &sc
->rx_dup_packets
, 0,
6188 "Rx duplicate packets");
6190 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6191 "rx_fifo_overflows", CTLFLAG_RD
, &sc
->rx_fifo_overflows
, 0,
6192 "Rx FIFO overflows");
6194 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6195 "rx_cipher_no_errors", CTLFLAG_RD
, &sc
->rx_cipher_no_errors
, 0,
6196 "Rx cipher no errors");
6198 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6199 "rx_cipher_icv_errors", CTLFLAG_RD
, &sc
->rx_cipher_icv_errors
, 0,
6200 "Rx cipher ICV errors");
6202 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6203 "rx_cipher_mic_errors", CTLFLAG_RD
, &sc
->rx_cipher_mic_errors
, 0,
6204 "Rx cipher MIC errors");
6206 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6207 "rx_cipher_invalid_key_errors", CTLFLAG_RD
, &sc
->rx_cipher_invalid_key_errors
, 0,
6208 "Rx cipher invalid key errors");
6211 static device_method_t rt2860_dev_methods
[] =
6213 DEVMETHOD(device_probe
, rt2860_probe
),
6214 DEVMETHOD(device_attach
, rt2860_attach
),
6215 DEVMETHOD(device_detach
, rt2860_detach
),
6216 DEVMETHOD(device_shutdown
, rt2860_shutdown
),
6217 DEVMETHOD(device_suspend
, rt2860_suspend
),
6218 DEVMETHOD(device_resume
, rt2860_resume
),
6222 static driver_t rt2860_driver
=
6226 sizeof(struct rt2860_softc
)
6229 static devclass_t rt2860_dev_class
;
6231 DRIVER_MODULE(rt2860
, pci
, rt2860_driver
, rt2860_dev_class
, 0, 0);
6233 MODULE_DEPEND(rt2860
, pci
, 1, 1, 1);
6234 MODULE_DEPEND(rt2860
, wlan
, 1, 1, 1);