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 /* clear key tables */
498 rt2860_asic_clear_keytables(sc
);
500 /* allocate Tx and Rx rings */
502 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
504 error
= rt2860_alloc_tx_ring(sc
, &sc
->tx_ring
[i
], i
);
507 printf("%s: could not allocate Tx ring #%d\n",
508 device_get_nameunit(sc
->dev
), i
);
513 sc
->tx_ring_mgtqid
= 5;
515 error
= rt2860_alloc_rx_ring(sc
, &sc
->rx_ring
);
518 printf("%s: could not allocate Rx ring\n",
519 device_get_nameunit(sc
->dev
));
523 callout_init(&sc
->periodic_ch
, 0);
524 callout_init_mtx(&sc
->tx_watchdog_ch
, &sc
->lock
, 0);
526 ifp
= sc
->ifp
= if_alloc(IFT_ETHER
);
529 printf("%s: could not if_alloc()\n",
530 device_get_nameunit(sc
->dev
));
537 if_initname(ifp
, "rt2860", device_get_unit(sc
->dev
));
539 ifp
->if_flags
= IFF_BROADCAST
| IFF_SIMPLEX
| IFF_MULTICAST
;
541 ifp
->if_init
= rt2860_init
;
542 ifp
->if_ioctl
= rt2860_ioctl
;
543 ifp
->if_start
= rt2860_start
;
545 IFQ_SET_MAXLEN(&ifp
->if_snd
, IFQ_MAXLEN
);
546 ifp
->if_snd
.ifq_drv_maxlen
= IFQ_MAXLEN
;
547 IFQ_SET_READY(&ifp
->if_snd
);
553 ic
->ic_phytype
= IEEE80211_T_HT
;
554 ic
->ic_opmode
= IEEE80211_M_STA
;
555 ic
->ic_state
= IEEE80211_S_INIT
;
557 ic
->ic_caps
= IEEE80211_C_MONITOR
|
564 IEEE80211_C_SHPREAMBLE
|
571 IEEE80211_C_AES_CCM
|
574 ic
->ic_htcaps
= IEEE80211_HTC_HT
|
575 IEEE80211_HTC_AMSDU
| /* A-MSDU Tx */
576 IEEE80211_HTC_AMPDU
| /* A-MPDU Tx */
577 IEEE80211_HTCAP_MAXAMSDU_3839
| /* max. A-MSDU Rx length */
578 IEEE80211_HTCAP_CHWIDTH40
| /* HT 40MHz channel width */
579 IEEE80211_HTCAP_GREENFIELD
| /* HT greenfield */
580 IEEE80211_HTCAP_SHORTGI20
| /* HT 20MHz short GI */
581 IEEE80211_HTCAP_SHORTGI40
| /* HT 40MHz short GI */
582 IEEE80211_HTCAP_SMPS_OFF
; /* MIMO power save disabled */
584 /* spatial streams */
586 if (sc
->nrxpath
== 2)
587 ic
->ic_htcaps
|= IEEE80211_HTCAP_RXSTBC_2STREAM
;
588 else if (sc
->nrxpath
== 3)
589 ic
->ic_htcaps
|= IEEE80211_HTCAP_RXSTBC_3STREAM
;
591 ic
->ic_htcaps
|= IEEE80211_HTCAP_RXSTBC_1STREAM
;
594 ic
->ic_htcaps
|= IEEE80211_HTCAP_TXSTBC
;
598 if (sc
->mac_rev
!= 0x28600100)
599 ic
->ic_htcaps
|= IEEE80211_HTCAP_DELBA
;
604 ic
->ic_regdomain
= 0;
605 ic
->ic_countrycode
= CTRY_DEFAULT
;
608 rt2860_init_channels(sc
);
610 rt2860_init_channels_ht40(sc
);
612 IEEE80211_ADDR_COPY(ic
->ic_myaddr
, sc
->mac_addr
);
614 ieee80211_ifattach(ic
);
616 sc
->newstate
= ic
->ic_newstate
;
617 ic
->ic_newstate
= rt2860_newstate
;
619 ic
->ic_reset
= rt2860_reset
;
620 ic
->ic_node_alloc
= rt2860_node_alloc
;
622 sc
->node_cleanup
= ic
->ic_node_cleanup
;
623 ic
->ic_node_cleanup
= rt2860_node_cleanup
;
625 ic
->ic_scan_start
= rt2860_scan_start
;
626 ic
->ic_scan_end
= rt2860_scan_end
;
627 ic
->ic_set_channel
= rt2860_set_channel
;
628 ic
->ic_newassoc
= rt2860_newassoc
;
629 ic
->ic_updateslot
= rt2860_updateslot
;
630 ic
->ic_wme
.wme_update
= rt2860_wme_update
;
631 ic
->ic_update_beacon
= rt2860_update_beacon
;
632 ic
->ic_crypto
.cs_key_update_begin
= rt2860_key_update_begin
;
633 ic
->ic_crypto
.cs_key_update_end
= rt2860_key_update_end
;
634 ic
->ic_crypto
.cs_key_set
= rt2860_key_set
;
635 ic
->ic_crypto
.cs_key_delete
= rt2860_key_delete
;
636 ic
->ic_raw_xmit
= rt2860_raw_xmit
;
638 sc
->recv_action
= ic
->ic_recv_action
;
639 ic
->ic_recv_action
= rt2860_recv_action
;
641 sc
->send_action
= ic
->ic_send_action
;
642 ic
->ic_send_action
= rt2860_send_action
;
644 /* override Rx A-MPDU factor */
646 ic
->ic_ampdu_rxmax
= IEEE80211_HTCAP_MAXRXAMPDU_32K
;
647 ic
->ic_ampdu_density
= IEEE80211_HTCAP_MPDUDENSITY_NA
;
648 ic
->ic_ampdu_limit
= ic
->ic_ampdu_rxmax
;
650 /* hardware requires padding between 802.11 frame header and body */
652 ic
->ic_flags
|= IEEE80211_F_WME
| IEEE80211_F_DATAPAD
| IEEE80211_F_DOTH
;
654 ic
->ic_flags_ext
|= IEEE80211_FEXT_SWBMISS
;
656 ieee80211_media_init(ic
, rt2860_media_change
, ieee80211_media_status
);
658 rt2860_amrr_init(&sc
->amrr
, ic
,
660 RT2860_AMRR_MIN_SUCCESS_THRESHOLD
,
661 RT2860_AMRR_MAX_SUCCESS_THRESHOLD
,
664 bpfattach2(ifp
, DLT_IEEE802_11_RADIO
,
665 sizeof(struct ieee80211_frame
) + IEEE80211_RADIOTAP_HDRLEN
,
668 sc
->rxtap_len
= sizeof(sc
->rxtapu
);
669 sc
->rxtap
.ihdr
.it_len
= htole16(sc
->rxtap_len
);
670 sc
->rxtap
.ihdr
.it_present
= htole32(RT2860_SOFTC_RX_RADIOTAP_PRESENT
);
672 sc
->txtap_len
= sizeof(sc
->txtapu
);
673 sc
->txtap
.ihdr
.it_len
= htole16(sc
->txtap_len
);
674 sc
->txtap
.ihdr
.it_present
= htole32(RT2860_SOFTC_TX_RADIOTAP_PRESENT
);
676 /* init task queue */
678 TASK_INIT(&sc
->rx_done_task
, 0, rt2860_rx_done_task
, sc
);
679 TASK_INIT(&sc
->tx_done_task
, 0, rt2860_tx_done_task
, sc
);
680 TASK_INIT(&sc
->fifo_sta_full_task
, 0, rt2860_fifo_sta_full_task
, sc
);
681 TASK_INIT(&sc
->periodic_task
, 0, rt2860_periodic_task
, sc
);
683 sc
->rx_process_limit
= 100;
685 sc
->taskqueue
= taskqueue_create("rt2860_taskq", M_NOWAIT
,
686 taskqueue_thread_enqueue
, &sc
->taskqueue
);
688 taskqueue_start_threads(&sc
->taskqueue
, 1, PI_NET
, "%s taskq",
689 device_get_nameunit(sc
->dev
));
691 rt2860_sysctl_attach(sc
);
694 ieee80211_announce(ic
);
696 /* set up interrupt */
698 error
= bus_setup_intr(dev
, sc
->irq
, INTR_TYPE_NET
| INTR_MPSAFE
,
699 NULL
, rt2860_intr
, sc
, &sc
->irqh
);
702 printf("%s: could not set up interrupt\n",
703 device_get_nameunit(dev
));
711 /* free Tx and Rx rings */
713 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
714 rt2860_free_tx_ring(sc
, &sc
->tx_ring
[i
]);
716 rt2860_free_rx_ring(sc
, &sc
->rx_ring
);
718 mtx_destroy(&sc
->lock
);
721 bus_release_resource(dev
, SYS_RES_MEMORY
, sc
->mem_rid
, sc
->mem
);
724 bus_release_resource(dev
, SYS_RES_IRQ
, sc
->irq_rid
, sc
->irq
);
732 static int rt2860_detach(device_t dev
)
734 struct rt2860_softc
*sc
;
735 struct ieee80211com
*ic
;
739 sc
= device_get_softc(dev
);
743 RT2860_DPRINTF(sc
, RT2860_DEBUG_ANY
,
745 device_get_nameunit(sc
->dev
));
747 RT2860_SOFTC_LOCK(sc
);
749 ifp
->if_drv_flags
&= ~(IFF_DRV_RUNNING
| IFF_DRV_OACTIVE
);
751 ieee80211_new_state(ic
, IEEE80211_S_INIT
, -1);
753 callout_stop(&sc
->periodic_ch
);
754 callout_stop(&sc
->tx_watchdog_ch
);
756 taskqueue_drain(sc
->taskqueue
, &sc
->rx_done_task
);
757 taskqueue_drain(sc
->taskqueue
, &sc
->tx_done_task
);
758 taskqueue_drain(sc
->taskqueue
, &sc
->fifo_sta_full_task
);
759 taskqueue_drain(sc
->taskqueue
, &sc
->periodic_task
);
761 /* free Tx and Rx rings */
763 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
764 rt2860_free_tx_ring(sc
, &sc
->tx_ring
[i
]);
766 rt2860_free_rx_ring(sc
, &sc
->rx_ring
);
768 RT2860_SOFTC_UNLOCK(sc
);
772 ieee80211_ifdetach(ic
);
776 taskqueue_free(sc
->taskqueue
);
778 mtx_destroy(&sc
->lock
);
780 bus_generic_detach(dev
);
782 bus_teardown_intr(dev
, sc
->irq
, sc
->irqh
);
784 bus_release_resource(dev
, SYS_RES_IRQ
, sc
->irq_rid
, sc
->irq
);
786 bus_release_resource(dev
, SYS_RES_MEMORY
, sc
->mem_rid
, sc
->mem
);
794 static int rt2860_shutdown(device_t dev
)
796 struct rt2860_softc
*sc
;
798 sc
= device_get_softc(dev
);
800 RT2860_DPRINTF(sc
, RT2860_DEBUG_ANY
,
801 "%s: shutting down\n",
802 device_get_nameunit(sc
->dev
));
806 sc
->flags
&= ~RT2860_SOFTC_FLAGS_UCODE_LOADED
;
814 static int rt2860_suspend(device_t dev
)
816 struct rt2860_softc
*sc
;
818 sc
= device_get_softc(dev
);
820 RT2860_DPRINTF(sc
, RT2860_DEBUG_ANY
,
822 device_get_nameunit(sc
->dev
));
826 sc
->flags
&= ~RT2860_SOFTC_FLAGS_UCODE_LOADED
;
834 static int rt2860_resume(device_t dev
)
836 struct rt2860_softc
*sc
;
839 sc
= device_get_softc(dev
);
842 RT2860_DPRINTF(sc
, RT2860_DEBUG_ANY
,
844 device_get_nameunit(sc
->dev
));
846 if (ifp
->if_flags
& IFF_UP
)
853 * rt2860_init_channels
855 static void rt2860_init_channels(struct rt2860_softc
*sc
)
857 struct ieee80211com
*ic
;
858 struct ieee80211_channel
*c
;
863 /* set supported channels for 2GHz band */
865 for (i
= 1; i
<= 14; i
++)
867 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
868 flags
= IEEE80211_CHAN_B
;
870 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
874 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
875 flags
= IEEE80211_CHAN_B
| IEEE80211_CHAN_HT20
;
877 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
881 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
882 flags
= IEEE80211_CHAN_G
;
884 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
888 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
889 flags
= IEEE80211_CHAN_G
| IEEE80211_CHAN_HT20
;
891 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
896 /* set supported channels for 5GHz band */
898 if (sc
->rf_rev
== RT2860_EEPROM_RF_2850
||
899 sc
->rf_rev
== RT2860_EEPROM_RF_2750
)
901 for (i
= 36; i
<= 64; i
+= 4)
903 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
904 flags
= IEEE80211_CHAN_A
;
906 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
910 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
911 flags
= IEEE80211_CHAN_A
| IEEE80211_CHAN_HT20
;
913 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
918 for (i
= 100; i
<= 140; i
+= 4)
920 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
921 flags
= IEEE80211_CHAN_A
;
923 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
927 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
928 flags
= IEEE80211_CHAN_A
| IEEE80211_CHAN_HT20
;
930 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
935 for (i
= 149; i
<= 165; i
+= 4)
937 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
938 flags
= IEEE80211_CHAN_A
;
940 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
944 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
945 flags
= IEEE80211_CHAN_A
| IEEE80211_CHAN_HT20
;
947 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
955 * rt2860_init_channels_ht40
957 static void rt2860_init_channels_ht40(struct rt2860_softc
*sc
)
959 struct ieee80211com
*ic
;
960 struct ieee80211_channel
*c
, *cent
, *ext
;
965 /* set supported channels for 2GHz band */
967 for (i
= 1; i
<= 14; i
++)
969 flags
= IEEE80211_CHAN_G
| IEEE80211_CHAN_HT40
;
971 /* find the center channel */
973 cent
= ieee80211_find_channel_byieee(ic
, i
,
974 flags
& ~IEEE80211_CHAN_HT
);
977 printf("%s: skip channel %d, could not find center channel\n",
978 device_get_nameunit(sc
->dev
), i
);
982 /* find the extension channel */
984 ext
= ieee80211_find_channel(ic
, cent
->ic_freq
+ 20,
985 flags
& ~IEEE80211_CHAN_HT
);
988 printf("%s: skip channel %d, could not find extension channel\n",
989 device_get_nameunit(sc
->dev
), i
);
993 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
996 c
->ic_extieee
= ext
->ic_ieee
;
997 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
998 c
->ic_flags
|= IEEE80211_CHAN_HT40U
;
1000 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1003 c
->ic_extieee
= cent
->ic_ieee
;
1004 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1005 c
->ic_flags
|= IEEE80211_CHAN_HT40D
;
1008 /* set supported channels for 5GHz band */
1010 if (sc
->rf_rev
== RT2860_EEPROM_RF_2850
||
1011 sc
->rf_rev
== RT2860_EEPROM_RF_2750
)
1013 for (i
= 36; i
<= 64; i
+= 4)
1015 flags
= IEEE80211_CHAN_A
| IEEE80211_CHAN_HT40
;
1017 /* find the center channel */
1019 cent
= ieee80211_find_channel_byieee(ic
, i
,
1020 flags
& ~IEEE80211_CHAN_HT
);
1023 printf("%s: skip channel %d, could not find center channel\n",
1024 device_get_nameunit(sc
->dev
), i
);
1028 /* find the extension channel */
1030 ext
= ieee80211_find_channel(ic
, cent
->ic_freq
+ 20,
1031 flags
& ~IEEE80211_CHAN_HT
);
1034 printf("%s: skip channel %d, could not find extension channel\n",
1035 device_get_nameunit(sc
->dev
), i
);
1039 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1042 c
->ic_extieee
= ext
->ic_ieee
;
1043 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1044 c
->ic_flags
|= IEEE80211_CHAN_HT40U
;
1046 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1049 c
->ic_extieee
= cent
->ic_ieee
;
1050 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1051 c
->ic_flags
|= IEEE80211_CHAN_HT40D
;
1054 for (i
= 100; i
<= 140; i
+= 4)
1056 flags
= IEEE80211_CHAN_A
| IEEE80211_CHAN_HT40
;
1058 /* find the center channel */
1060 cent
= ieee80211_find_channel_byieee(ic
, i
,
1061 flags
& ~IEEE80211_CHAN_HT
);
1064 printf("%s: skip channel %d, could not find center channel\n",
1065 device_get_nameunit(sc
->dev
), i
);
1069 /* find the extension channel */
1071 ext
= ieee80211_find_channel(ic
, cent
->ic_freq
+ 20,
1072 flags
& ~IEEE80211_CHAN_HT
);
1075 printf("%s: skip channel %d, could not find extension channel\n",
1076 device_get_nameunit(sc
->dev
), i
);
1080 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1083 c
->ic_extieee
= ext
->ic_ieee
;
1084 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1085 c
->ic_flags
|= IEEE80211_CHAN_HT40U
;
1087 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1090 c
->ic_extieee
= cent
->ic_ieee
;
1091 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1092 c
->ic_flags
|= IEEE80211_CHAN_HT40D
;
1095 for (i
= 149; i
<= 165; i
+= 4)
1097 flags
= IEEE80211_CHAN_A
| IEEE80211_CHAN_HT40
;
1099 /* find the center channel */
1101 cent
= ieee80211_find_channel_byieee(ic
, i
,
1102 flags
& ~IEEE80211_CHAN_HT
);
1105 printf("%s: skip channel %d, could not find center channel\n",
1106 device_get_nameunit(sc
->dev
), i
);
1110 /* find the extension channel */
1112 ext
= ieee80211_find_channel(ic
, cent
->ic_freq
+ 20,
1113 flags
& ~IEEE80211_CHAN_HT
);
1116 printf("%s: skip channel %d, could not find extension channel\n",
1117 device_get_nameunit(sc
->dev
), i
);
1121 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1124 c
->ic_extieee
= ext
->ic_ieee
;
1125 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1126 c
->ic_flags
|= IEEE80211_CHAN_HT40U
;
1128 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1131 c
->ic_extieee
= cent
->ic_ieee
;
1132 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1133 c
->ic_flags
|= IEEE80211_CHAN_HT40D
;
1139 * rt2860_init_locked
1141 static void rt2860_init_locked(void *priv
)
1143 struct rt2860_softc
*sc
;
1144 struct ieee80211com
*ic
;
1146 int error
, i
, ntries
;
1147 uint32_t tmp
, stacnt
[6];
1153 RT2860_DPRINTF(sc
, RT2860_DEBUG_ANY
,
1154 "%s: initializing\n",
1155 device_get_nameunit(sc
->dev
));
1157 RT2860_SOFTC_ASSERT_LOCKED(sc
);
1159 if (!(sc
->flags
& RT2860_SOFTC_FLAGS_UCODE_LOADED
))
1161 RT2860_DPRINTF(sc
, RT2860_DEBUG_ANY
,
1162 "%s: loading 8051 microcode\n",
1163 device_get_nameunit(sc
->dev
));
1165 error
= rt2860_io_mcu_load_ucode(sc
, rt2860_ucode
, sizeof(rt2860_ucode
));
1168 printf("%s: could not load 8051 microcode\n",
1169 device_get_nameunit(sc
->dev
));
1173 RT2860_DPRINTF(sc
, RT2860_DEBUG_ANY
,
1174 "%s: 8051 microcode was successfully loaded\n",
1175 device_get_nameunit(sc
->dev
));
1177 sc
->flags
|= RT2860_SOFTC_FLAGS_UCODE_LOADED
;
1180 rt2860_io_mac_write(sc
, RT2860_REG_PWR_PIN_CFG
, 0x2);
1182 /* disable DMA engine */
1184 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
);
1187 tmp
|= RT2860_REG_TX_WB_DDONE
;
1189 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
, tmp
);
1191 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WPDMA_RST_IDX
, 0xffffffff);
1193 /* PBF hardware reset */
1195 rt2860_io_mac_write(sc
, RT2860_REG_PBF_SYS_CTRL
, 0xe1f);
1196 rt2860_io_mac_write(sc
, RT2860_REG_PBF_SYS_CTRL
, 0xe00);
1198 /* wait while DMA engine is busy */
1200 for (ntries
= 0; ntries
< 100; ntries
++)
1202 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
);
1203 if (!(tmp
& (RT2860_REG_TX_DMA_BUSY
| RT2860_REG_RX_DMA_BUSY
)))
1211 printf("%s: timeout waiting for DMA engine\n",
1212 device_get_nameunit(sc
->dev
));
1217 tmp
|= RT2860_REG_TX_WB_DDONE
;
1219 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
, tmp
);
1221 /* reset Rx and Tx rings */
1223 tmp
= RT2860_REG_RST_IDX_RX
|
1224 RT2860_REG_RST_IDX_TX_MGMT
|
1225 RT2860_REG_RST_IDX_TX_HCCA
|
1226 RT2860_REG_RST_IDX_TX_AC3
|
1227 RT2860_REG_RST_IDX_TX_AC2
|
1228 RT2860_REG_RST_IDX_TX_AC1
|
1229 RT2860_REG_RST_IDX_TX_AC0
;
1231 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WPDMA_RST_IDX
, tmp
);
1233 /* PBF hardware reset */
1235 rt2860_io_mac_write(sc
, RT2860_REG_PBF_SYS_CTRL
, 0xe1f);
1236 rt2860_io_mac_write(sc
, RT2860_REG_PBF_SYS_CTRL
, 0xe00);
1238 rt2860_io_mac_write(sc
, RT2860_REG_PWR_PIN_CFG
, 0x3);
1240 rt2860_io_mac_write(sc
, RT2860_REG_SYS_CTRL
,
1241 RT2860_REG_MAC_SRST
| RT2860_REG_BBP_HRST
);
1242 rt2860_io_mac_write(sc
, RT2860_REG_SYS_CTRL
, 0);
1244 /* init Tx power per rate */
1246 for (i
= 0; i
< RT2860_SOFTC_TXPOW_RATE_COUNT
; i
++)
1248 if (sc
->txpow_rate_20mhz
[i
] == 0xffffffff)
1251 rt2860_io_mac_write(sc
, RT2860_REG_TX_PWR_CFG(i
),
1252 sc
->txpow_rate_20mhz
[i
]);
1255 for (i
= 0; i
< RT2860_DEF_MAC_SIZE
; i
++)
1256 rt2860_io_mac_write(sc
, rt2860_def_mac
[i
].reg
,
1257 rt2860_def_mac
[i
].val
);
1259 /* wait while MAC is busy */
1261 for (ntries
= 0; ntries
< 100; ntries
++)
1263 if (!(rt2860_io_mac_read(sc
, RT2860_REG_STATUS_CFG
) &
1264 (RT2860_REG_STATUS_TX_BUSY
| RT2860_REG_STATUS_RX_BUSY
)))
1272 printf("%s: timeout waiting for MAC\n",
1273 device_get_nameunit(sc
->dev
));
1277 /* clear Host to MCU mailbox */
1279 rt2860_io_mac_write(sc
, RT2860_REG_H2M_MAILBOX_BBP_AGENT
, 0);
1280 rt2860_io_mac_write(sc
, RT2860_REG_H2M_MAILBOX
, 0);
1282 rt2860_io_mcu_cmd(sc
, RT2860_IO_MCU_CMD_BOOT
,
1283 RT2860_REG_H2M_TOKEN_NO_INTR
, 0);
1287 error
= rt2860_init_bbp(sc
);
1291 /* set up maximum buffer sizes */
1293 tmp
= (1 << 12) | RT2860_MAX_AGG_SIZE
;
1295 rt2860_io_mac_write(sc
, RT2860_REG_MAX_LEN_CFG
, tmp
);
1297 /* set mac address */
1299 IEEE80211_ADDR_COPY(ic
->ic_myaddr
, IF_LLADDR(ifp
));
1301 rt2860_asic_set_macaddr(sc
, ic
->ic_myaddr
);
1303 /* clear statistic registers */
1305 rt2860_io_mac_read_multi(sc
, RT2860_REG_RX_STA_CNT0
,
1306 stacnt
, sizeof(stacnt
));
1308 /* set RTS threshold */
1310 rt2860_asic_update_rtsthreshold(sc
);
1314 rt2860_asic_update_txpower(sc
);
1316 /* set up protection mode */
1318 sc
->tx_ampdu_sessions
= 0;
1320 rt2860_asic_updateprot(sc
);
1322 /* clear beacon frame space (entries = 8, entry size = 512) */
1324 rt2860_io_mac_set_region_4(sc
, RT2860_REG_BEACON_BASE(0), 0, 1024);
1326 taskqueue_unblock(sc
->taskqueue
);
1328 /* init Tx rings (4 EDCAs + HCCA + MGMT) */
1330 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
1331 rt2860_reset_tx_ring(sc
, &sc
->tx_ring
[i
]);
1333 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
1335 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_BASE_PTR(i
),
1336 sc
->tx_ring
[i
].desc_phys_addr
);
1337 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_MAX_CNT(i
),
1338 RT2860_SOFTC_TX_RING_DESC_COUNT
);
1339 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_CTX_IDX(i
), 0);
1344 rt2860_reset_rx_ring(sc
, &sc
->rx_ring
);
1346 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_BASE_PTR
,
1347 sc
->rx_ring
.desc_phys_addr
);
1348 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_MAX_CNT
,
1349 RT2860_SOFTC_RX_RING_DATA_COUNT
);
1350 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_CALC_IDX
,
1351 RT2860_SOFTC_RX_RING_DATA_COUNT
- 1);
1353 /* wait while DMA engine is busy */
1355 for (ntries
= 0; ntries
< 100; ntries
++)
1357 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
);
1358 if (!(tmp
& (RT2860_REG_TX_DMA_BUSY
| RT2860_REG_RX_DMA_BUSY
)))
1366 printf("%s: timeout waiting for DMA engine\n",
1367 device_get_nameunit(sc
->dev
));
1372 tmp
|= RT2860_REG_TX_WB_DDONE
;
1374 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
, tmp
);
1376 /* disable interrupts mitigation */
1378 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_DELAY_INT_CFG
, 0);
1380 /* send LEDs operating mode to microcontroller */
1382 rt2860_io_mcu_cmd(sc
, RT2860_IO_MCU_CMD_LED1
,
1383 RT2860_REG_H2M_TOKEN_NO_INTR
, sc
->led_off
[0]);
1384 rt2860_io_mcu_cmd(sc
, RT2860_IO_MCU_CMD_LED2
,
1385 RT2860_REG_H2M_TOKEN_NO_INTR
, sc
->led_off
[1]);
1386 rt2860_io_mcu_cmd(sc
, RT2860_IO_MCU_CMD_LED3
,
1387 RT2860_REG_H2M_TOKEN_NO_INTR
, sc
->led_off
[2]);
1389 /* turn radio LED on */
1391 rt2860_led_cmd(sc
, RT2860_LED_CMD_RADIO_ON
);
1393 /* write vendor-specific BBP values (from EEPROM) */
1395 for (i
= 0; i
< RT2860_SOFTC_BBP_EEPROM_COUNT
; i
++)
1397 if (sc
->bbp_eeprom
[i
].reg
== 0x00 ||
1398 sc
->bbp_eeprom
[i
].reg
== 0xff)
1401 rt2860_io_bbp_write(sc
, sc
->bbp_eeprom
[i
].reg
,
1402 sc
->bbp_eeprom
[i
].val
);
1406 tmp = rt2860_io_mac_read(sc, RT2860_REG_SCHDMA_GPIO_CTRL_CFG);
1409 rt2860_io_mcu_cmd(sc, RT2860_IO_MCU_CMD_SLEEP,
1410 RT2860_REG_H2M_TOKEN_RADIOOFF, 0x02ff);
1411 rt2860_io_mcu_cmd_check(sc, RT2860_REG_H2M_TOKEN_RADIOOFF);
1413 rt2860_io_mcu_cmd(sc, RT2860_IO_MCU_CMD_WAKEUP,
1414 RT2860_REG_H2M_TOKEN_WAKEUP, 0);
1415 rt2860_io_mcu_cmd_check(sc, RT2860_REG_H2M_TOKEN_WAKEUP);
1419 /* disable non-existing Rx chains */
1421 tmp
= rt2860_io_bbp_read(sc
, 3);
1423 tmp
&= ~((1 << 4) | (1 << 3));
1425 if (sc
->nrxpath
== 3)
1427 else if (sc
->nrxpath
== 2)
1430 rt2860_io_bbp_write(sc
, 3, tmp
);
1432 /* disable non-existing Tx chains */
1434 tmp
= rt2860_io_bbp_read(sc
, 1);
1436 tmp
&= ~((1 << 4) | (1 << 3));
1438 if (sc
->ntxpath
== 2)
1441 rt2860_io_bbp_write(sc
, 1, tmp
);
1443 /* set current channel */
1445 rt2860_rf_set_chan(sc
, ic
->ic_curchan
);
1447 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WMM_TXOP0_CFG
, 0);
1448 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WMM_TXOP1_CFG
,
1451 if ((sc
->mac_rev
& 0xffff) != 0x0101)
1452 rt2860_io_mac_write(sc
, RT2860_REG_TX_TXOP_CTRL_CFG
, 0x583f);
1454 /* clear pending interrupts */
1456 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_INT_STATUS
, 0xffffffff);
1458 /* enable interrupts */
1460 tmp
= RT2860_REG_INT_TX_COHERENT
|
1461 RT2860_REG_INT_RX_COHERENT
|
1462 RT2860_REG_INT_GP_TIMER
|
1463 RT2860_REG_INT_AUTO_WAKEUP
|
1464 RT2860_REG_INT_FIFO_STA_FULL
|
1466 RT2860_REG_INT_PRE_TBTT |
1467 RT2860_REG_INT_TBTT |
1469 RT2860_REG_INT_TXRX_COHERENT
|
1470 RT2860_REG_INT_MCU_CMD
|
1471 RT2860_REG_INT_TX_MGMT_DONE
|
1472 RT2860_REG_INT_TX_HCCA_DONE
|
1473 RT2860_REG_INT_TX_AC3_DONE
|
1474 RT2860_REG_INT_TX_AC2_DONE
|
1475 RT2860_REG_INT_TX_AC1_DONE
|
1476 RT2860_REG_INT_TX_AC0_DONE
|
1477 RT2860_REG_INT_RX_DONE
;
1479 sc
->intr_enable_mask
= tmp
;
1481 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_INT_MASK
, tmp
);
1483 if (rt2860_txrx_enable(sc
) != 0)
1486 /* clear garbage interrupts */
1488 tmp
= rt2860_io_mac_read(sc
, 0x1300);
1490 ifp
->if_drv_flags
&= ~IFF_DRV_OACTIVE
;
1491 ifp
->if_drv_flags
|= IFF_DRV_RUNNING
;
1493 if (ic
->ic_opmode
!= IEEE80211_M_MONITOR
)
1495 if (ic
->ic_roaming
!= IEEE80211_ROAMING_MANUAL
)
1496 ieee80211_new_state(ic
, IEEE80211_S_SCAN
, -1);
1500 ieee80211_new_state(ic
, IEEE80211_S_RUN
, -1);
1503 sc
->periodic_round
= 0;
1505 callout_reset(&sc
->periodic_ch
, hz
/ 10, rt2860_periodic
, sc
);
1511 rt2860_stop_locked(sc
);
1517 static void rt2860_init(void *priv
)
1519 struct rt2860_softc
*sc
;
1523 RT2860_SOFTC_LOCK(sc
);
1525 rt2860_init_locked(sc
);
1527 RT2860_SOFTC_UNLOCK(sc
);
1533 static int rt2860_init_bbp(struct rt2860_softc
*sc
)
1538 for (ntries
= 0; ntries
< 20; ntries
++)
1540 tmp
= rt2860_io_bbp_read(sc
, 0);
1541 if (tmp
!= 0x00 && tmp
!= 0xff)
1545 if (tmp
== 0x00 || tmp
== 0xff)
1547 printf("%s: timeout waiting for BBP to wakeup\n",
1548 device_get_nameunit(sc
->dev
));
1552 for (i
= 0; i
< RT2860_DEF_BBP_SIZE
; i
++)
1553 rt2860_io_bbp_write(sc
, rt2860_def_bbp
[i
].reg
,
1554 rt2860_def_bbp
[i
].val
);
1556 if ((sc
->mac_rev
& 0xffff) != 0x0101)
1557 rt2860_io_bbp_write(sc
, 84, 0x19);
1563 * rt2860_stop_locked
1565 static void rt2860_stop_locked(void *priv
)
1567 struct rt2860_softc
*sc
;
1568 struct ieee80211com
*ic
;
1576 RT2860_DPRINTF(sc
, RT2860_DEBUG_ANY
,
1578 device_get_nameunit(sc
->dev
));
1580 RT2860_SOFTC_ASSERT_LOCKED(sc
);
1584 if (ifp
->if_drv_flags
& IFF_DRV_RUNNING
)
1585 rt2860_led_cmd(sc
, RT2860_LED_CMD_RADIO_OFF
);
1587 ifp
->if_drv_flags
&= ~(IFF_DRV_RUNNING
| IFF_DRV_OACTIVE
);
1589 ieee80211_new_state(ic
, IEEE80211_S_INIT
, -1);
1591 callout_stop(&sc
->periodic_ch
);
1592 callout_stop(&sc
->tx_watchdog_ch
);
1594 RT2860_SOFTC_UNLOCK(sc
);
1596 taskqueue_block(sc
->taskqueue
);
1598 taskqueue_drain(sc
->taskqueue
, &sc
->rx_done_task
);
1599 taskqueue_drain(sc
->taskqueue
, &sc
->tx_done_task
);
1600 taskqueue_drain(sc
->taskqueue
, &sc
->fifo_sta_full_task
);
1601 taskqueue_drain(sc
->taskqueue
, &sc
->periodic_task
);
1603 RT2860_SOFTC_LOCK(sc
);
1605 /* clear key tables */
1607 rt2860_asic_clear_keytables(sc
);
1609 /* disable interrupts */
1611 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_INT_MASK
, 0);
1615 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_SYS_CTRL
);
1617 tmp
&= ~(RT2860_REG_RX_ENABLE
| RT2860_REG_TX_ENABLE
);
1619 rt2860_io_mac_write(sc
, RT2860_REG_SYS_CTRL
, tmp
);
1623 rt2860_io_mac_write(sc
, RT2860_REG_SYS_CTRL
,
1624 RT2860_REG_MAC_SRST
| RT2860_REG_BBP_HRST
);
1625 rt2860_io_mac_write(sc
, RT2860_REG_SYS_CTRL
, 0);
1627 if (sc
->beacon_mbuf
!= NULL
)
1629 m_free(sc
->beacon_mbuf
);
1630 sc
->beacon_mbuf
= NULL
;
1637 static void rt2860_stop(void *priv
)
1639 struct rt2860_softc
*sc
;
1643 RT2860_SOFTC_LOCK(sc
);
1645 rt2860_stop_locked(sc
);
1647 RT2860_SOFTC_UNLOCK(sc
);
1653 static void rt2860_start(struct ifnet
*ifp
)
1655 struct rt2860_softc
*sc
;
1656 struct ieee80211com
*ic
;
1657 struct ieee80211_node
*ni
;
1658 struct ether_header
*eh
;
1665 RT2860_SOFTC_LOCK(sc
);
1667 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
1669 RT2860_SOFTC_UNLOCK(sc
);
1675 IF_POLL(&ic
->ic_mgtq
, m
);
1678 if (sc
->tx_ring
[sc
->tx_ring_mgtqid
].data_queued
>= RT2860_SOFTC_TX_RING_DATA_COUNT
)
1680 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
1681 "%s: if_start: Tx ring with qid=%d is full\n",
1682 device_get_nameunit(sc
->dev
), sc
->tx_ring_mgtqid
);
1684 ifp
->if_drv_flags
|= IFF_DRV_OACTIVE
;
1686 sc
->tx_data_queue_full
[sc
->tx_ring_mgtqid
]++;
1691 IF_DEQUEUE(&ic
->ic_mgtq
, m
);
1693 ni
= (struct ieee80211_node
*) m
->m_pkthdr
.rcvif
;
1694 m
->m_pkthdr
.rcvif
= NULL
;
1696 if (bpf_peers_present(ic
->ic_rawbpf
))
1697 bpf_mtap(ic
->ic_rawbpf
, m
);
1699 if (rt2860_tx_frame(sc
, m
, ni
, sc
->tx_ring_mgtqid
) != 0)
1702 rt2860_drain_fifo_stats(sc
);
1706 if (ic
->ic_state
!= IEEE80211_S_RUN
)
1709 IF_POLL(&ifp
->if_snd
, m
);
1713 IFQ_DRV_DEQUEUE(&ifp
->if_snd
, m
);
1715 if (ic
->ic_flags
& IEEE80211_F_SCAN
)
1716 ieee80211_cancel_scan(ic
);
1718 if (m
->m_len
< sizeof(struct ether_header
) &&
1719 !(m
= m_pullup(m
, sizeof (struct ether_header
))))
1722 eh
= mtod(m
, struct ether_header
*);
1724 ni
= ieee80211_find_txnode(ic
, eh
->ether_dhost
);
1727 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
1728 "%s: if_start: could not find Tx node\n",
1729 device_get_nameunit(sc
->dev
));
1735 ieee80211_classify(ic
, m
, ni
);
1737 qid
= M_WME_GETAC(m
);
1739 if (sc
->tx_ring
[qid
].data_queued
>= RT2860_SOFTC_TX_RING_DATA_COUNT
)
1741 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
1742 "%s: if_start: Tx ring with qid=%d is full\n",
1743 device_get_nameunit(sc
->dev
), qid
);
1746 ieee80211_free_node(ni
);
1748 ifp
->if_drv_flags
|= IFF_DRV_OACTIVE
;
1751 sc
->tx_data_queue_full
[qid
]++;
1758 m
= ieee80211_encap(ic
, m
, ni
);
1761 ieee80211_free_node(ni
);
1766 if (bpf_peers_present(ic
->ic_rawbpf
))
1767 bpf_mtap(ic
->ic_rawbpf
, m
);
1769 if (rt2860_tx_frame(sc
, m
, ni
, qid
) != 0)
1771 ieee80211_free_node(ni
);
1778 rt2860_drain_fifo_stats(sc
);
1781 sc
->tx_timer
= RT2860_TX_WATCHDOG_TIMEOUT
;
1783 ic
->ic_lastdata
= ticks
;
1785 callout_reset(&sc
->tx_watchdog_ch
, hz
, rt2860_tx_watchdog
, sc
);
1788 RT2860_SOFTC_UNLOCK(sc
);
1794 static int rt2860_ioctl(struct ifnet
*ifp
, u_long cmd
, caddr_t data
)
1796 struct rt2860_softc
*sc
;
1797 struct ieee80211com
*ic
;
1808 RT2860_SOFTC_LOCK(sc
);
1810 if (ifp
->if_flags
& IFF_UP
)
1812 if (ifp
->if_drv_flags
& IFF_DRV_RUNNING
)
1814 if ((ifp
->if_flags
^ sc
->if_flags
) & IFF_PROMISC
)
1815 rt2860_asic_update_promisc(sc
);
1819 rt2860_init_locked(sc
);
1824 if (ifp
->if_drv_flags
& IFF_DRV_RUNNING
)
1825 rt2860_stop_locked(sc
);
1828 sc
->if_flags
= ifp
->if_flags
;
1830 RT2860_SOFTC_UNLOCK(sc
);
1834 error
= ieee80211_ioctl(ic
, cmd
, data
);
1837 if (error
== ENETRESET
)
1839 RT2860_SOFTC_LOCK(sc
);
1841 if ((ifp
->if_flags
& IFF_UP
) &&
1842 (ifp
->if_drv_flags
& IFF_DRV_RUNNING
) &&
1843 (ic
->ic_roaming
!= IEEE80211_ROAMING_MANUAL
))
1845 rt2860_stop_locked(sc
);
1846 rt2860_init_locked(sc
);
1849 RT2860_SOFTC_UNLOCK(sc
);
1860 static int rt2860_reset(struct ifnet
*ifp
)
1862 struct rt2860_softc
*sc
;
1863 struct ieee80211com
*ic
;
1868 if (ic
->ic_opmode
!= IEEE80211_M_MONITOR
)
1871 rt2860_rf_set_chan(sc
, ic
->ic_curchan
);
1879 static int rt2860_newstate(struct ieee80211com
*ic
,
1880 enum ieee80211_state nstate
, int arg
)
1882 struct rt2860_softc
*sc
;
1884 struct ieee80211_node
*ni
;
1890 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATE
,
1891 "%s: newstate: %s -> %s\n",
1892 device_get_nameunit(sc
->dev
),
1893 ieee80211_state_name
[ic
->ic_state
], ieee80211_state_name
[nstate
]);
1895 error
= sc
->newstate(ic
, nstate
, arg
);
1899 RT2860_SOFTC_LOCK(sc
);
1901 /* turn link LED off */
1903 if (nstate
!= IEEE80211_S_RUN
)
1904 rt2860_led_cmd(sc
, RT2860_LED_CMD_RADIO_OFF
);
1908 case IEEE80211_S_INIT
:
1909 rt2860_asic_disable_tsf_sync(sc
);
1912 case IEEE80211_S_RUN
:
1915 if (ic
->ic_opmode
!= IEEE80211_M_MONITOR
)
1916 rt2860_rf_set_chan(sc
, ni
->ni_chan
);
1918 if (ic
->ic_opmode
!= IEEE80211_M_MONITOR
)
1920 rt2860_asic_enable_mrr(sc
);
1921 rt2860_asic_set_txpreamble(sc
);
1922 rt2860_asic_set_basicrates(sc
);
1923 rt2860_asic_update_txpower(sc
);
1924 rt2860_asic_set_bssid(sc
, ni
->ni_bssid
);
1927 if (ic
->ic_opmode
== IEEE80211_M_STA
)
1928 rt2860_newassoc(ni
, 1);
1930 if (ic
->ic_opmode
== IEEE80211_M_HOSTAP
||
1931 ic
->ic_opmode
== IEEE80211_M_IBSS
)
1933 error
= rt2860_beacon_alloc(sc
);
1937 rt2860_asic_update_beacon(sc
);
1940 if (ic
->ic_opmode
!= IEEE80211_M_MONITOR
)
1941 rt2860_asic_enable_tsf_sync(sc
);
1943 /* turn link LED on */
1945 if (ic
->ic_opmode
!= IEEE80211_M_MONITOR
)
1947 rt2860_led_cmd(sc
, RT2860_LED_CMD_RADIO_ON
|
1948 (IEEE80211_IS_CHAN_2GHZ(ni
->ni_chan
) ?
1949 RT2860_LED_CMD_LINK_2GHZ
: RT2860_LED_CMD_LINK_5GHZ
));
1953 case IEEE80211_S_SLEEP
:
1960 RT2860_SOFTC_UNLOCK(sc
);
1968 static void rt2860_scan_start(struct ieee80211com
*ic
)
1970 struct rt2860_softc
*sc
;
1976 rt2860_asic_disable_tsf_sync(sc
);
1982 static void rt2860_scan_end(struct ieee80211com
*ic
)
1984 struct rt2860_softc
*sc
;
1990 rt2860_asic_enable_tsf_sync(sc
);
1994 * rt2860_set_channel
1996 static void rt2860_set_channel(struct ieee80211com
*ic
)
1998 struct rt2860_softc
*sc
;
2004 RT2860_DPRINTF(sc
, RT2860_DEBUG_CHAN
,
2005 "%s: set channel: channel=%u, HT%s%s\n",
2006 device_get_nameunit(sc
->dev
),
2007 ieee80211_chan2ieee(ic
, ic
->ic_curchan
),
2008 !IEEE80211_IS_CHAN_HT(ic
->ic_curchan
) ? " disabled" :
2009 IEEE80211_IS_CHAN_HT20(ic
->ic_curchan
) ? "20":
2010 IEEE80211_IS_CHAN_HT40U(ic
->ic_curchan
) ? "40U" : "40D",
2011 (ic
->ic_flags
& IEEE80211_F_SCAN
) ? ", scanning" : "");
2013 RT2860_SOFTC_LOCK(sc
);
2015 rt2860_rf_set_chan(sc
, ic
->ic_curchan
);
2017 RT2860_SOFTC_UNLOCK(sc
);
2023 static void rt2860_newassoc(struct ieee80211_node
*ni
, int isnew
)
2025 struct rt2860_softc
*sc
;
2026 struct ieee80211com
*ic
;
2028 struct rt2860_softc_node
*rni
;
2035 rni
= (struct rt2860_softc_node
*) ni
;
2039 aid
= IEEE80211_AID(ni
->ni_associd
);
2040 rni
->staid
= rt2860_staid_alloc(sc
, aid
);
2043 rt2860_io_mac_write_multi(sc
, RT2860_REG_WCID(wcid
),
2044 ni
->ni_macaddr
, IEEE80211_ADDR_LEN
);
2046 rt2860_amrr_node_init(&sc
->amrr
, &sc
->amrr_node
[wcid
], ni
);
2048 RT2860_DPRINTF(sc
, RT2860_DEBUG_RATE
,
2049 "%s: initial%s node Tx rate: associd=0x%04x, rate=0x%02x, max rate=0x%02x\n",
2050 device_get_nameunit(sc
->dev
),
2051 (ni
->ni_flags
& IEEE80211_NODE_HT
) ? " HT" : "",
2053 (ni
->ni_flags
& IEEE80211_NODE_HT
) ?
2054 (ni
->ni_htrates
.rs_rates
[ni
->ni_txrate
] | IEEE80211_RATE_MCS
) :
2055 (ni
->ni_rates
.rs_rates
[ni
->ni_txrate
] & IEEE80211_RATE_VAL
),
2056 (ni
->ni_flags
& IEEE80211_NODE_HT
) ?
2057 (ni
->ni_htrates
.rs_rates
[ni
->ni_htrates
.rs_nrates
- 1] | IEEE80211_RATE_MCS
) :
2058 (ni
->ni_rates
.rs_rates
[ni
->ni_rates
.rs_nrates
- 1] & IEEE80211_RATE_VAL
));
2060 rt2860_asic_updateprot(sc
);
2061 rt2860_asic_updateslot(sc
);
2062 rt2860_asic_set_txpreamble(sc
);
2065 RT2860_DPRINTF(sc
, RT2860_DEBUG_NODE
,
2066 "%s: new association: isnew=%d, macaddr=%s, associd=0x%04x, staid=0x%02x, QoS %s, ERP %s, HT %s\n",
2067 device_get_nameunit(sc
->dev
), isnew
, ether_sprintf(ni
->ni_macaddr
),
2068 ni
->ni_associd
, rni
->staid
,
2069 (ni
->ni_flags
& IEEE80211_NODE_QOS
) ? "enabled" : "disabled",
2070 (ni
->ni_flags
& IEEE80211_NODE_ERP
) ? "enabled" : "disabled",
2071 (ni
->ni_flags
& IEEE80211_NODE_HT
) ? "enabled" : "disabled");
2078 static void rt2860_updateslot(struct ifnet
*ifp
)
2080 struct rt2860_softc
*sc
;
2084 rt2860_asic_updateslot(sc
);
2090 static int rt2860_wme_update(struct ieee80211com
*ic
)
2092 struct rt2860_softc
*sc
;
2098 rt2860_asic_wme_update(sc
);
2104 * rt2860_update_beacon
2106 static void rt2860_update_beacon(struct ieee80211com
*ic
, int what
)
2108 struct rt2860_softc
*sc
;
2111 struct ieee80211_beacon_offsets
*bo
;
2115 m
= sc
->beacon_mbuf
;
2116 bo
= &sc
->beacon_offsets
;
2118 RT2860_DPRINTF(sc
, RT2860_DEBUG_BEACON
,
2119 "%s: update beacon: what=%d\n",
2120 device_get_nameunit(sc
->dev
), what
);
2122 setbit(bo
->bo_flags
, what
);
2124 ieee80211_beacon_update(ic
->ic_bss
, bo
, m
, 0);
2126 rt2860_asic_update_beacon(sc
);
2130 * rt2860_key_update_begin
2132 static void rt2860_key_update_begin(struct ieee80211com
*ic
)
2134 struct rt2860_softc
*sc
;
2140 RT2860_DPRINTF(sc
, RT2860_DEBUG_KEY
,
2141 "%s: key update begin\n",
2142 device_get_nameunit(sc
->dev
));
2144 taskqueue_block(sc
->taskqueue
);
2146 IF_LOCK(&ifp
->if_snd
);
2150 * rt2860_key_update_end
2152 static void rt2860_key_update_end(struct ieee80211com
*ic
)
2154 struct rt2860_softc
*sc
;
2160 RT2860_DPRINTF(sc
, RT2860_DEBUG_KEY
,
2161 "%s: key update end\n",
2162 device_get_nameunit(sc
->dev
));
2164 IF_UNLOCK(&ifp
->if_snd
);
2166 taskqueue_unblock(sc
->taskqueue
);
2172 static int rt2860_key_set(struct ieee80211com
*ic
,
2173 const struct ieee80211_key
*k
, const uint8_t mac
[IEEE80211_ADDR_LEN
])
2175 struct rt2860_softc
*sc
;
2177 struct ieee80211_node
*ni
;
2178 struct rt2860_softc_node
*rni
;
2179 uint16_t key_base
, keymode_base
;
2180 uint8_t mode
, vapid
, wcid
, iv
[8];
2183 if (k
->wk_cipher
->ic_cipher
!= IEEE80211_CIPHER_WEP
&&
2184 k
->wk_cipher
->ic_cipher
!= IEEE80211_CIPHER_TKIP
&&
2185 k
->wk_cipher
->ic_cipher
!= IEEE80211_CIPHER_AES_CCM
)
2191 switch (k
->wk_cipher
->ic_cipher
)
2193 case IEEE80211_CIPHER_WEP
:
2194 if(k
->wk_keylen
< 8)
2195 mode
= RT2860_REG_CIPHER_MODE_WEP40
;
2197 mode
= RT2860_REG_CIPHER_MODE_WEP104
;
2200 case IEEE80211_CIPHER_TKIP
:
2201 mode
= RT2860_REG_CIPHER_MODE_TKIP
;
2204 case IEEE80211_CIPHER_AES_CCM
:
2205 mode
= RT2860_REG_CIPHER_MODE_AES_CCMP
;
2212 RT2860_DPRINTF(sc
, RT2860_DEBUG_KEY
,
2213 "%s: set key: keyix=%d, keylen=%d, macaddr=%s, mode=%d, group=%d\n",
2214 device_get_nameunit(sc
->dev
), k
->wk_keyix
, k
->wk_keylen
, ether_sprintf(mac
),
2215 mode
, (k
->wk_flags
& IEEE80211_KEY_GROUP
) ? 1 : 0);
2217 if (!(k
->wk_flags
& IEEE80211_KEY_GROUP
))
2219 /* install pairwise key */
2221 ni
= ieee80211_find_node(&ic
->ic_sta
, mac
);
2222 rni
= (struct rt2860_softc_node
*) ni
;
2226 key_base
= RT2860_REG_PKEY(wcid
);
2228 ieee80211_free_node(ni
);
2230 if (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_WEP
)
2234 iv
[3] = (k
->wk_keyix
<< 6);
2238 if (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_TKIP
)
2240 iv
[0] = (k
->wk_keytsc
>> 8);
2241 iv
[1] = ((iv
[0] | 0x20) & 0x7f);
2242 iv
[2] = k
->wk_keytsc
;
2248 iv
[0] = k
->wk_keytsc
;
2249 iv
[1] = k
->wk_keytsc
>> 8;
2253 iv
[3] = ((k
->wk_keyix
<< 6) | IEEE80211_WEP_EXTIV
);
2254 iv
[4] = (k
->wk_keytsc
>> 16);
2255 iv
[5] = (k
->wk_keytsc
>> 24);
2256 iv
[6] = (k
->wk_keytsc
>> 32);
2257 iv
[7] = (k
->wk_keytsc
>> 40);
2259 RT2860_DPRINTF(sc
, RT2860_DEBUG_KEY
,
2260 "%s: set key: iv=%02x %02x %02x %02x %02x %02x %02x %02x\n",
2261 device_get_nameunit(sc
->dev
),
2262 iv
[0], iv
[1], iv
[2], iv
[3], iv
[4], iv
[5], iv
[6], iv
[7]);
2265 rt2860_io_mac_write_multi(sc
, RT2860_REG_IVEIV(wcid
), iv
, 8);
2267 if (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_TKIP
)
2269 rt2860_io_mac_write_multi(sc
, key_base
, k
->wk_key
, 16);
2271 if (ic
->ic_opmode
!= IEEE80211_M_HOSTAP
)
2273 rt2860_io_mac_write_multi(sc
, key_base
+ 16, &k
->wk_key
[16], 8);
2274 rt2860_io_mac_write_multi(sc
, key_base
+ 24, &k
->wk_key
[24], 8);
2278 rt2860_io_mac_write_multi(sc
, key_base
+ 16, &k
->wk_key
[24], 8);
2279 rt2860_io_mac_write_multi(sc
, key_base
+ 24, &k
->wk_key
[16], 8);
2284 rt2860_io_mac_write_multi(sc
, key_base
, k
->wk_key
, k
->wk_keylen
);
2287 tmp
= ((vapid
& RT2860_REG_VAP_MASK
) << RT2860_REG_VAP_SHIFT
) |
2288 (mode
<< RT2860_REG_CIPHER_MODE_SHIFT
) | RT2860_REG_PKEY_ENABLE
;
2290 rt2860_io_mac_write(sc
, RT2860_REG_WCID_ATTR(wcid
), tmp
);
2293 if ((k
->wk_flags
& IEEE80211_KEY_GROUP
) ||
2294 (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_WEP
))
2296 /* install group key */
2299 wcid
= RT2860_WCID_MCAST
;
2300 key_base
= RT2860_REG_SKEY(vapid
, k
->wk_keyix
);
2301 keymode_base
= RT2860_REG_SKEY_MODE(vapid
);
2303 if (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_TKIP
)
2305 rt2860_io_mac_write_multi(sc
, key_base
, k
->wk_key
, 16);
2307 if (ic
->ic_opmode
!= IEEE80211_M_HOSTAP
)
2309 rt2860_io_mac_write_multi(sc
, key_base
+ 16, &k
->wk_key
[16], 8);
2310 rt2860_io_mac_write_multi(sc
, key_base
+ 24, &k
->wk_key
[24], 8);
2314 rt2860_io_mac_write_multi(sc
, key_base
+ 16, &k
->wk_key
[24], 8);
2315 rt2860_io_mac_write_multi(sc
, key_base
+ 24, &k
->wk_key
[16], 8);
2320 rt2860_io_mac_write_multi(sc
, key_base
, k
->wk_key
, k
->wk_keylen
);
2323 tmp
= rt2860_io_mac_read(sc
, keymode_base
);
2325 tmp
&= ~(0xf << (k
->wk_keyix
* 4 + 16 * (vapid
% 2)));
2326 tmp
|= (mode
<< (k
->wk_keyix
* 4 + 16 * (vapid
% 2)));
2328 rt2860_io_mac_write(sc
, keymode_base
, tmp
);
2330 if (ic
->ic_opmode
== IEEE80211_M_HOSTAP
)
2332 if (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_WEP
)
2336 iv
[3] = (k
->wk_keyix
<< 6);
2340 if (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_TKIP
)
2342 iv
[0] = (k
->wk_keytsc
>> 8);
2343 iv
[1] = ((iv
[0] | 0x20) & 0x7f);
2344 iv
[2] = k
->wk_keytsc
;
2350 iv
[0] = k
->wk_keytsc
;
2351 iv
[1] = k
->wk_keytsc
>> 8;
2355 iv
[3] = ((k
->wk_keyix
<< 6) | IEEE80211_WEP_EXTIV
);
2356 iv
[4] = (k
->wk_keytsc
>> 16);
2357 iv
[5] = (k
->wk_keytsc
>> 24);
2358 iv
[6] = (k
->wk_keytsc
>> 32);
2359 iv
[7] = (k
->wk_keytsc
>> 40);
2361 RT2860_DPRINTF(sc
, RT2860_DEBUG_KEY
,
2362 "%s: set key: iv=%02x %02x %02x %02x %02x %02x %02x %02x\n",
2363 device_get_nameunit(sc
->dev
),
2364 iv
[0], iv
[1], iv
[2], iv
[3], iv
[4], iv
[5], iv
[6], iv
[7]);
2367 rt2860_io_mac_write_multi(sc
, RT2860_REG_IVEIV(wcid
), iv
, 8);
2369 tmp
= ((vapid
& RT2860_REG_VAP_MASK
) << RT2860_REG_VAP_SHIFT
) |
2370 (mode
<< RT2860_REG_CIPHER_MODE_SHIFT
);
2372 rt2860_io_mac_write(sc
, RT2860_REG_WCID_ATTR(wcid
), tmp
);
2382 static int rt2860_key_delete(struct ieee80211com
*ic
,
2383 const struct ieee80211_key
*k
)
2385 struct rt2860_softc
*sc
;
2386 uint8_t vapid
, wcid
;
2389 sc
= ic
->ic_ifp
->if_softc
;
2391 RT2860_DPRINTF(sc
, RT2860_DEBUG_KEY
,
2392 "%s: delete key: keyix=%d, keylen=%d, group=%d\n",
2393 device_get_nameunit(sc
->dev
), k
->wk_keyix
, k
->wk_keylen
,
2394 (k
->wk_flags
& IEEE80211_KEY_GROUP
) ? 1 : 0);
2396 if (k
->wk_flags
& IEEE80211_KEY_GROUP
)
2398 /* remove group key */
2401 wcid
= RT2860_WCID_MCAST
;
2403 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_SKEY_MODE(vapid
));
2405 tmp
&= ~(0xf << (k
->wk_keyix
* 4 + 16 * (vapid
% 2)));
2406 tmp
|= (RT2860_REG_CIPHER_MODE_NONE
<< (k
->wk_keyix
* 4 + 16 * (vapid
% 2)));
2408 rt2860_io_mac_write(sc
, RT2860_REG_SKEY_MODE(vapid
), tmp
);
2410 if (ic
->ic_opmode
== IEEE80211_M_HOSTAP
)
2412 tmp
= ((vapid
& RT2860_REG_VAP_MASK
) << RT2860_REG_VAP_SHIFT
) |
2413 (RT2860_REG_CIPHER_MODE_NONE
<< RT2860_REG_CIPHER_MODE_SHIFT
) | RT2860_REG_PKEY_ENABLE
;
2415 rt2860_io_mac_write(sc
, RT2860_REG_WCID_ATTR(wcid
), tmp
);
2425 static int rt2860_raw_xmit(struct ieee80211_node
*ni
, struct mbuf
*m
,
2426 const struct ieee80211_bpf_params
*params
)
2432 * rt2860_media_change
2434 static int rt2860_media_change(struct ifnet
*ifp
)
2436 struct rt2860_softc
*sc
;
2441 error
= ieee80211_media_change(ifp
);
2442 if (error
!= ENETRESET
)
2445 RT2860_SOFTC_LOCK(sc
);
2447 if ((ifp
->if_flags
& IFF_UP
) && (ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
2449 rt2860_stop_locked(sc
);
2450 rt2860_init_locked(sc
);
2453 RT2860_SOFTC_UNLOCK(sc
);
2461 static struct ieee80211_node
*rt2860_node_alloc(struct ieee80211_node_table
*nt
)
2463 return malloc(sizeof(struct rt2860_softc_node
),
2464 M_80211_NODE
, M_NOWAIT
| M_ZERO
);
2468 * rt2860_node_cleanup
2470 static void rt2860_node_cleanup(struct ieee80211_node
*ni
)
2472 struct rt2860_softc
*sc
;
2473 struct ieee80211com
*ic
;
2475 struct rt2860_softc_node
*rni
;
2476 uint8_t vapid
, wcid
;
2482 rni
= (struct rt2860_softc_node
*) ni
;
2484 RT2860_DPRINTF(sc
, RT2860_DEBUG_NODE
,
2485 "%s: node cleanup: macaddr=%s, associd=0x%04x, staid=0x%02x\n",
2486 device_get_nameunit(sc
->dev
), ether_sprintf(ni
->ni_macaddr
),
2487 ni
->ni_associd
, rni
->staid
);
2489 if (rni
->staid
!= 0)
2494 tmp
= ((vapid
& RT2860_REG_VAP_MASK
) << RT2860_REG_VAP_SHIFT
) |
2495 (RT2860_REG_CIPHER_MODE_NONE
<< RT2860_REG_CIPHER_MODE_SHIFT
) | RT2860_REG_PKEY_ENABLE
;
2497 rt2860_io_mac_write(sc
, RT2860_REG_WCID_ATTR(wcid
), tmp
);
2499 rt2860_staid_delete(sc
, rni
->staid
);
2504 sc
->node_cleanup(ni
);
2508 * rt2860_recv_action
2510 static void rt2860_recv_action(struct ieee80211_node
*ni
,
2511 const uint8_t *frm
, const uint8_t *efrm
)
2513 struct rt2860_softc
*sc
;
2514 struct ieee80211com
*ic
;
2516 struct rt2860_softc_node
*rni
;
2517 const struct ieee80211_action
*ia
;
2518 struct ieee80211_tx_ampdu
*tx_ampdu
;
2519 uint16_t status
, baparamset
;
2521 int tid
, bufsize
, ac
;
2527 rni
= (struct rt2860_softc_node
*) ni
;
2529 ia
= (const struct ieee80211_action
*) frm
;
2531 sc
->recv_action(ni
, frm
, efrm
);
2533 if (ia
->ia_category
!= IEEE80211_ACTION_CAT_BA
)
2538 switch (ia
->ia_action
)
2540 /* IEEE80211_ACTION_BA_ADDBA_REQUEST */
2541 case IEEE80211_ACTION_BA_ADDBA_REQUEST
:
2542 baparamset
= LE_READ_2(frm
+ 3);
2543 tid
= RT2860_MS(baparamset
, IEEE80211_BAPS_TID
);
2544 bufsize
= RT2860_MS(baparamset
, IEEE80211_BAPS_BUFSIZ
);
2546 RT2860_DPRINTF(sc
, RT2860_DEBUG_BA
,
2547 "%s: received ADDBA request: associd=0x%04x, tid=%d, bufsize=%d\n",
2548 device_get_nameunit(sc
->dev
), ni
->ni_associd
, tid
, bufsize
);
2550 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_WCID(wcid
) + 4);
2552 tmp
|= (0x10000 << tid
);
2554 rt2860_io_mac_write(sc
, RT2860_REG_WCID(wcid
) + 4, tmp
);
2557 /* IEEE80211_ACTION_BA_ADDBA_RESPONSE */
2558 case IEEE80211_ACTION_BA_ADDBA_RESPONSE
:
2559 status
= LE_READ_2(frm
+ 3);
2560 baparamset
= LE_READ_2(frm
+ 4);
2561 tid
= RT2860_MS(baparamset
, IEEE80211_BAPS_TID
);
2562 bufsize
= RT2860_MS(baparamset
, IEEE80211_BAPS_BUFSIZ
);
2563 ac
= TID_TO_WME_AC(tid
);
2564 tx_ampdu
= &ni
->ni_tx_ampdu
[ac
];
2566 RT2860_DPRINTF(sc
, RT2860_DEBUG_BA
,
2567 "%s: received ADDBA response: associd=0x%04x, status=%d, tid=%d, bufsize=%d\n",
2568 device_get_nameunit(sc
->dev
), ni
->ni_associd
, status
, tid
, bufsize
);
2570 if (sc
->mac_rev
>= 0x28720200)
2572 if (tx_ampdu
->txa_wnd
> 13)
2573 tx_ampdu
->txa_wnd
= 13;
2577 if (tx_ampdu
->txa_wnd
> 7)
2578 tx_ampdu
->txa_wnd
= 7;
2581 if (status
== IEEE80211_STATUS_SUCCESS
)
2583 sc
->tx_ampdu_sessions
++;
2585 rt2860_asic_updateprot(sc
);
2589 /* IEEE80211_ACTION_BA_DELBA */
2590 case IEEE80211_ACTION_BA_DELBA
:
2591 baparamset
= LE_READ_2(frm
+ 2);
2592 tid
= RT2860_MS(baparamset
, IEEE80211_BAPS_TID
);
2594 RT2860_DPRINTF(sc
, RT2860_DEBUG_BA
,
2595 "%s: received DELBA request: associd=0x%04x, tid=%d\n",
2596 device_get_nameunit(sc
->dev
), ni
->ni_associd
, tid
);
2598 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_WCID(wcid
) + 4);
2600 tmp
&= ~(0x10000 << tid
);
2602 rt2860_io_mac_write(sc
, RT2860_REG_WCID(wcid
) + 4, tmp
);
2608 * rt2860_send_action
2610 static int rt2860_send_action(struct ieee80211_node
*ni
,
2611 int category
, int action
, uint16_t args
[4])
2613 struct rt2860_softc
*sc
;
2614 struct ieee80211com
*ic
;
2616 struct rt2860_softc_node
*rni
;
2617 uint16_t baparamset
;
2625 rni
= (struct rt2860_softc_node
*) ni
;
2627 ret
= sc
->send_action(ni
, category
, action
, args
);
2629 if (category
!= IEEE80211_ACTION_CAT_BA
)
2636 /* IEEE80211_ACTION_BA_DELBA */
2637 case IEEE80211_ACTION_BA_DELBA
:
2638 baparamset
= RT2860_SM(args
[0], IEEE80211_DELBAPS_TID
) | args
[1];
2640 tid
= RT2860_MS(baparamset
, IEEE80211_DELBAPS_TID
);
2642 RT2860_DPRINTF(sc
, RT2860_DEBUG_BA
,
2643 "%s: sending DELBA request: associd=0x%04x, tid=%d\n",
2644 device_get_nameunit(sc
->dev
), ni
->ni_associd
, tid
);
2646 if (RT2860_MS(baparamset
, IEEE80211_DELBAPS_INIT
) != IEEE80211_DELBAPS_INIT
)
2648 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_WCID(wcid
) + 4);
2650 tmp
&= ~(0x10000 << tid
);
2652 rt2860_io_mac_write(sc
, RT2860_REG_WCID(wcid
) + 4, tmp
);
2656 sc
->tx_ampdu_sessions
--;
2658 rt2860_asic_updateprot(sc
);
2667 * rt2860_amrr_update_iter_func
2669 static void rt2860_amrr_update_iter_func(void *arg
, struct ieee80211_node
*ni
)
2671 struct rt2860_softc
*sc
;
2672 struct ieee80211com
*ic
;
2673 struct rt2860_softc_node
*rni
;
2678 rni
= (struct rt2860_softc_node
*) ni
;
2680 /* only associated stations */
2682 if (rni
->staid
!= 0)
2686 RT2860_DPRINTF(sc
, RT2860_DEBUG_RATE
,
2687 "%s: AMRR node: staid=0x%02x, txcnt=%d, success=%d, retrycnt=%d\n",
2688 device_get_nameunit(sc
->dev
),
2689 rni
->staid
, sc
->amrr_node
[wcid
].txcnt
, sc
->amrr_node
[wcid
].success
, sc
->amrr_node
[wcid
].retrycnt
);
2691 rt2860_amrr_choose(ni
, &sc
->amrr_node
[wcid
]);
2693 RT2860_DPRINTF(sc
, RT2860_DEBUG_RATE
,
2694 "%s:%s node Tx rate: associd=0x%04x, staid=0x%02x, rate=0x%02x, max rate=0x%02x\n",
2695 device_get_nameunit(sc
->dev
),
2696 (ni
->ni_flags
& IEEE80211_NODE_HT
) ? " HT" : "",
2697 ni
->ni_associd
, rni
->staid
,
2698 (ni
->ni_flags
& IEEE80211_NODE_HT
) ?
2699 (ni
->ni_htrates
.rs_rates
[ni
->ni_txrate
] | IEEE80211_RATE_MCS
) :
2700 (ni
->ni_rates
.rs_rates
[ni
->ni_txrate
] & IEEE80211_RATE_VAL
),
2701 (ni
->ni_flags
& IEEE80211_NODE_HT
) ?
2702 (ni
->ni_htrates
.rs_rates
[ni
->ni_htrates
.rs_nrates
- 1] | IEEE80211_RATE_MCS
) :
2703 (ni
->ni_rates
.rs_rates
[ni
->ni_rates
.rs_nrates
- 1] & IEEE80211_RATE_VAL
));
2710 static void rt2860_periodic(void *arg
)
2712 struct rt2860_softc
*sc
;
2716 RT2860_DPRINTF(sc
, RT2860_DEBUG_PERIODIC
,
2718 device_get_nameunit(sc
->dev
));
2720 taskqueue_enqueue(sc
->taskqueue
, &sc
->periodic_task
);
2724 * rt2860_tx_watchdog
2726 static void rt2860_tx_watchdog(void *arg
)
2728 struct rt2860_softc
*sc
;
2734 if (sc
->tx_timer
== 0)
2737 if (--sc
->tx_timer
== 0)
2739 printf("%s: Tx watchdog timeout: resetting\n",
2740 device_get_nameunit(sc
->dev
));
2742 rt2860_stop_locked(sc
);
2743 rt2860_init_locked(sc
);
2747 sc
->tx_watchdog_timeouts
++;
2750 callout_reset(&sc
->tx_watchdog_ch
, hz
, rt2860_tx_watchdog
, sc
);
2754 * rt2860_staid_alloc
2756 static int rt2860_staid_alloc(struct rt2860_softc
*sc
, int aid
)
2760 if ((aid
> 0 && aid
< RT2860_SOFTC_STAID_COUNT
) && isclr(sc
->staid_mask
, aid
))
2766 for (staid
= 1; staid
< RT2860_SOFTC_STAID_COUNT
; staid
++)
2768 if (isclr(sc
->staid_mask
, staid
))
2773 setbit(sc
->staid_mask
, staid
);
2779 * rt2860_staid_delete
2781 static void rt2860_staid_delete(struct rt2860_softc
*sc
, int staid
)
2783 clrbit(sc
->staid_mask
, staid
);
2787 * rt2860_asic_set_bssid
2789 static void rt2860_asic_set_bssid(struct rt2860_softc
*sc
,
2790 const uint8_t *bssid
)
2794 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATE
,
2795 "%s: set bssid: bssid=%s\n",
2796 device_get_nameunit(sc
->dev
), ether_sprintf(bssid
));
2798 tmp
= bssid
[0] | (bssid
[1]) << 8 | (bssid
[2] << 16) | (bssid
[3] << 24);
2800 rt2860_io_mac_write(sc
, RT2860_REG_BSSID_DW0
, tmp
);
2802 tmp
= bssid
[4] | (bssid
[5] << 8);
2804 rt2860_io_mac_write(sc
, RT2860_REG_BSSID_DW1
, tmp
);
2808 * rt2860_asic_set_macaddr
2810 static void rt2860_asic_set_macaddr(struct rt2860_softc
*sc
,
2811 const uint8_t *addr
)
2815 tmp
= addr
[0] | (addr
[1] << 8) | (addr
[2] << 16) | (addr
[3] << 24);
2817 rt2860_io_mac_write(sc
, RT2860_REG_ADDR_DW0
, tmp
);
2819 tmp
= addr
[4] | (addr
[5] << 8);
2821 rt2860_io_mac_write(sc
, RT2860_REG_ADDR_DW1
, tmp
);
2825 * rt2860_asic_enable_tsf_sync
2827 static void rt2860_asic_enable_tsf_sync(struct rt2860_softc
*sc
)
2829 struct ieee80211com
*ic
;
2834 RT2860_DPRINTF(sc
, RT2860_DEBUG_BEACON
,
2835 "%s: enabling TSF\n",
2836 device_get_nameunit(sc
->dev
));
2838 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_BCN_TIME_CFG
);
2841 tmp
|= ic
->ic_bss
->ni_intval
* 16;
2842 tmp
|= (RT2860_REG_TSF_TIMER_ENABLE
| RT2860_REG_TBTT_TIMER_ENABLE
);
2844 if (ic
->ic_opmode
== IEEE80211_M_STA
)
2846 tmp
|= (RT2860_REG_TSF_SYNC_MODE_STA
<< RT2860_REG_TSF_SYNC_MODE_SHIFT
);
2848 else if (ic
->ic_opmode
== IEEE80211_M_IBSS
)
2850 tmp
|= RT2860_REG_BCN_TX_ENABLE
;
2851 tmp
|= (RT2860_REG_TSF_SYNC_MODE_IBSS
<< RT2860_REG_TSF_SYNC_MODE_SHIFT
);
2853 else if (ic
->ic_opmode
== IEEE80211_M_HOSTAP
)
2855 tmp
|= RT2860_REG_BCN_TX_ENABLE
;
2856 tmp
|= (RT2860_REG_TSF_SYNC_MODE_HOSTAP
<< RT2860_REG_TSF_SYNC_MODE_SHIFT
);
2859 rt2860_io_mac_write(sc
, RT2860_REG_BCN_TIME_CFG
, tmp
);
2863 * rt2860_asic_disable_tsf_sync
2865 static void rt2860_asic_disable_tsf_sync(struct rt2860_softc
*sc
)
2869 RT2860_DPRINTF(sc
, RT2860_DEBUG_BEACON
,
2870 "%s: disabling TSF\n",
2871 device_get_nameunit(sc
->dev
));
2873 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_BCN_TIME_CFG
);
2875 tmp
&= ~(RT2860_REG_BCN_TX_ENABLE
|
2876 RT2860_REG_TSF_TIMER_ENABLE
|
2877 RT2860_REG_TBTT_TIMER_ENABLE
);
2879 tmp
&= ~(RT2860_REG_TSF_SYNC_MODE_MASK
<< RT2860_REG_TSF_SYNC_MODE_SHIFT
);
2880 tmp
|= (RT2860_REG_TSF_SYNC_MODE_DISABLE
<< RT2860_REG_TSF_SYNC_MODE_SHIFT
);
2882 rt2860_io_mac_write(sc
, RT2860_REG_BCN_TIME_CFG
, tmp
);
2886 * rt2860_asic_enable_mrr
2888 static void rt2860_asic_enable_mrr(struct rt2860_softc
*sc
)
2890 #define CCK(mcs) (mcs)
2891 #define OFDM(mcs) ((1 << 3) | (mcs))
2892 #define HT(mcs) (mcs)
2894 rt2860_io_mac_write(sc
, RT2860_REG_TX_LG_FBK_CFG0
,
2895 (OFDM(6) << 28) | /* 54 -> 48 */
2896 (OFDM(5) << 24) | /* 48 -> 36 */
2897 (OFDM(4) << 20) | /* 36 -> 24 */
2898 (OFDM(3) << 16) | /* 24 -> 18 */
2899 (OFDM(2) << 12) | /* 18 -> 12 */
2900 (OFDM(1) << 8) | /* 12 -> 9 */
2901 (OFDM(0) << 4) | /* 9 -> 6 */
2902 OFDM(0)); /* 6 -> 6 */
2904 rt2860_io_mac_write(sc
, RT2860_REG_TX_LG_FBK_CFG1
,
2905 (CCK(2) << 12) | /* 11 -> 5.5 */
2906 (CCK(1) << 8) | /* 5.5 -> 2 */
2907 (CCK(0) << 4) | /* 2 -> 1 */
2908 CCK(0)); /* 1 -> 1 */
2910 rt2860_io_mac_write(sc
, RT2860_REG_TX_HT_FBK_CFG0
,
2920 rt2860_io_mac_write(sc
, RT2860_REG_TX_HT_FBK_CFG1
,
2936 * rt2860_asic_set_txpreamble
2938 static void rt2860_asic_set_txpreamble(struct rt2860_softc
*sc
)
2940 struct ieee80211com
*ic
;
2945 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATE
,
2946 "%s: %s short Tx preamble\n",
2947 device_get_nameunit(sc
->dev
),
2948 (ic
->ic_flags
& IEEE80211_F_SHPREAMBLE
) ? "enabling" : "disabling");
2950 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_AUTO_RSP_CFG
);
2952 tmp
&= ~RT2860_REG_CCK_SHORT_ENABLE
;
2954 if (sc
->ic
.ic_flags
& IEEE80211_F_SHPREAMBLE
)
2955 tmp
|= RT2860_REG_CCK_SHORT_ENABLE
;
2957 rt2860_io_mac_write(sc
, RT2860_REG_AUTO_RSP_CFG
, tmp
);
2961 * rt2860_asic_set_basicrates
2963 static void rt2860_asic_set_basicrates(struct rt2860_softc
*sc
)
2965 struct ieee80211com
*ic
;
2969 if (ic
->ic_curmode
== IEEE80211_MODE_11B
)
2970 rt2860_io_mac_write(sc
, RT2860_REG_LEGACY_BASIC_RATE
, 0x3);
2971 else if (ic
->ic_curmode
== IEEE80211_MODE_11A
)
2972 rt2860_io_mac_write(sc
, RT2860_REG_LEGACY_BASIC_RATE
, 0x150);
2974 rt2860_io_mac_write(sc
, RT2860_REG_LEGACY_BASIC_RATE
, 0x15f);
2978 * rt2860_asic_update_rtsthreshold
2980 static void rt2860_asic_update_rtsthreshold(struct rt2860_softc
*sc
)
2982 struct ieee80211com
*ic
;
2988 RT2860_DPRINTF(sc
, RT2860_DEBUG_PROT
,
2989 "%s: updating RTS threshold: %d\n",
2990 device_get_nameunit(sc
->dev
), ic
->ic_rtsthreshold
);
2992 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_RTS_CFG
);
2994 tmp
&= ~(RT2860_REG_TX_RTS_THRESHOLD_MASK
<< RT2860_REG_TX_RTS_THRESHOLD_SHIFT
);
2996 if (ic
->ic_flags_ext
& IEEE80211_FEXT_AMSDU_TX
)
2999 threshold
= ic
->ic_rtsthreshold
;
3002 tmp
|= ((threshold
& RT2860_REG_TX_RTS_THRESHOLD_MASK
) <<
3003 RT2860_REG_TX_RTS_THRESHOLD_SHIFT
);
3005 rt2860_io_mac_write(sc
, RT2860_REG_TX_RTS_CFG
, tmp
);
3009 * rt2860_asic_update_txpower
3011 static void rt2860_asic_update_txpower(struct rt2860_softc
*sc
)
3013 struct ieee80211com
*ic
;
3014 uint32_t *txpow_rate
;
3022 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATE
,
3023 "%s: updating Tx power: %d\n",
3024 device_get_nameunit(sc
->dev
), ic
->ic_txpowlimit
);
3026 if (!IEEE80211_IS_CHAN_HT40(ic
->ic_curchan
))
3028 txpow_rate
= sc
->txpow_rate_20mhz
;
3032 if (IEEE80211_IS_CHAN_2GHZ(ic
->ic_curchan
))
3033 txpow_rate
= sc
->txpow_rate_40mhz_2ghz
;
3035 txpow_rate
= sc
->txpow_rate_40mhz_5ghz
;
3040 val
= rt2860_io_bbp_read(sc
, 1);
3043 if (ic
->ic_txpowlimit
> 90)
3047 else if (ic
->ic_txpowlimit
> 60)
3051 else if (ic
->ic_txpowlimit
> 30)
3055 else if (ic
->ic_txpowlimit
> 15)
3059 else if (ic
->ic_txpowlimit
> 9)
3069 rt2860_io_bbp_write(sc
, 1, val
);
3071 for (i
= 0; i
< RT2860_SOFTC_TXPOW_RATE_COUNT
; i
++)
3073 if (txpow_rate
[i
] == 0xffffffff)
3076 tmp
= rt2860_read_eeprom_txpow_rate_add_delta(txpow_rate
[i
], delta
);
3078 rt2860_io_mac_write(sc
, RT2860_REG_TX_PWR_CFG(i
), tmp
);
3083 * rt2860_asic_update_promisc
3085 static void rt2860_asic_update_promisc(struct rt2860_softc
*sc
)
3090 ifp
= sc
->ic
.ic_ifp
;
3092 printf("%s: %s promiscuous mode\n",
3093 device_get_nameunit(sc
->dev
),
3094 (ifp
->if_flags
& IFF_PROMISC
) ? "entering" : "leaving");
3096 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_RX_FILTER_CFG
);
3098 tmp
&= ~RT2860_REG_RX_FILTER_DROP_UC_NOME
;
3100 if (!(ifp
->if_flags
& IFF_PROMISC
))
3101 tmp
|= RT2860_REG_RX_FILTER_DROP_UC_NOME
;
3103 rt2860_io_mac_write(sc
, RT2860_REG_RX_FILTER_CFG
, tmp
);
3107 * rt2860_asic_updateprot
3109 static void rt2860_asic_updateprot(struct rt2860_softc
*sc
)
3111 struct ieee80211com
*ic
;
3112 uint32_t cck_prot
, ofdm_prot
, mm20_prot
, mm40_prot
, gf20_prot
, gf40_prot
;
3114 enum ieee80211_protmode htprotmode
;
3118 /* CCK frame protection */
3120 cck_prot
= RT2860_REG_RTSTH_ENABLE
| RT2860_REG_PROT_NAV_SHORT
|
3121 RT2860_REG_TXOP_ALLOW_ALL
| RT2860_REG_PROT_CTRL_NONE
;
3123 /* set up protection frame phy mode and rate (MCS code) */
3125 if (ic
->ic_curmode
== IEEE80211_MODE_11A
)
3126 cck_prot
|= (RT2860_REG_PROT_PHYMODE_OFDM
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3127 (0 << RT2860_REG_PROT_MCS_SHIFT
);
3129 cck_prot
|= ((RT2860_REG_PROT_PHYMODE_CCK
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3130 (3 << RT2860_REG_PROT_MCS_SHIFT
));
3132 rt2860_io_mac_write(sc
, RT2860_REG_TX_CCK_PROT_CFG
, cck_prot
);
3134 /* OFDM frame protection */
3136 ofdm_prot
= RT2860_REG_RTSTH_ENABLE
| RT2860_REG_PROT_NAV_SHORT
|
3137 RT2860_REG_TXOP_ALLOW_ALL
;
3139 if (ic
->ic_flags
& IEEE80211_F_USEPROT
)
3141 RT2860_DPRINTF(sc
, RT2860_DEBUG_PROT
,
3142 "%s: updating protection mode: b/g protection mode=%s\n",
3143 device_get_nameunit(sc
->dev
),
3144 (ic
->ic_protmode
== IEEE80211_PROT_RTSCTS
) ? "RTS/CTS" :
3145 ((ic
->ic_protmode
== IEEE80211_PROT_CTSONLY
) ? "CTS-to-self" : "none"));
3147 if (ic
->ic_protmode
== IEEE80211_PROT_RTSCTS
)
3148 ofdm_prot
|= RT2860_REG_PROT_CTRL_RTS_CTS
;
3149 else if (ic
->ic_protmode
== IEEE80211_PROT_CTSONLY
)
3150 ofdm_prot
|= RT2860_REG_PROT_CTRL_CTS
;
3152 ofdm_prot
|= RT2860_REG_PROT_CTRL_NONE
;
3156 RT2860_DPRINTF(sc
, RT2860_DEBUG_PROT
,
3157 "%s: updating protection mode: b/g protection mode=%s\n",
3158 device_get_nameunit(sc
->dev
), "none");
3160 ofdm_prot
|= RT2860_REG_PROT_CTRL_NONE
;
3163 rt2860_io_mac_write(sc
, RT2860_REG_TX_OFDM_PROT_CFG
, ofdm_prot
);
3165 /* HT frame protection */
3167 if ((ic
->ic_opmode
== IEEE80211_M_STA
) && (ic
->ic_state
== IEEE80211_S_RUN
))
3168 htopmode
= ic
->ic_bss
->ni_htopmode
;
3170 htopmode
= ic
->ic_curhtprotmode
;
3172 htprotmode
= ic
->ic_htprotmode
;
3174 /* force HT mixed mode and RTS/CTS protection if A-MPDU Tx aggregation is enabled */
3176 if (sc
->tx_ampdu_sessions
> 0)
3178 RT2860_DPRINTF(sc
, RT2860_DEBUG_PROT
,
3179 "%s: updating protection mode: forcing HT mixed mode and RTS/CTS protection\n",
3180 device_get_nameunit(sc
->dev
));
3182 htopmode
= IEEE80211_HTINFO_OPMODE_MIXED
;
3183 htprotmode
= IEEE80211_PROT_RTSCTS
;
3186 RT2860_DPRINTF(sc
, RT2860_DEBUG_PROT
,
3187 "%s: updating protection mode: HT operation mode=0x%02x, protection mode=%s\n",
3188 device_get_nameunit(sc
->dev
),
3189 htopmode
& IEEE80211_HTINFO_OPMODE
,
3190 (htprotmode
== IEEE80211_PROT_RTSCTS
) ? "RTS/CTS" :
3191 ((htprotmode
== IEEE80211_PROT_CTSONLY
) ? "CTS-to-self" : "none"));
3193 switch (htopmode
& IEEE80211_HTINFO_OPMODE
)
3195 /* IEEE80211_HTINFO_OPMODE_HT20PR */
3196 case IEEE80211_HTINFO_OPMODE_HT20PR
:
3197 mm20_prot
= RT2860_REG_PROT_NAV_SHORT
| RT2860_REG_PROT_CTRL_NONE
|
3198 RT2860_REG_TXOP_ALLOW_CCK
| RT2860_REG_TXOP_ALLOW_OFDM
|
3199 RT2860_REG_TXOP_ALLOW_MM20
| RT2860_REG_TXOP_ALLOW_GF20
|
3200 (RT2860_REG_PROT_PHYMODE_OFDM
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3201 (4 << RT2860_REG_PROT_MCS_SHIFT
);
3203 gf20_prot
= mm20_prot
;
3205 mm40_prot
= RT2860_REG_PROT_NAV_SHORT
| RT2860_REG_TXOP_ALLOW_ALL
|
3206 (RT2860_REG_PROT_PHYMODE_OFDM
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3207 (0x84 << RT2860_REG_PROT_MCS_SHIFT
);
3209 if (htprotmode
== IEEE80211_PROT_RTSCTS
)
3210 mm40_prot
|= RT2860_REG_PROT_CTRL_RTS_CTS
;
3211 else if (htprotmode
== IEEE80211_PROT_CTSONLY
)
3212 mm40_prot
|= RT2860_REG_PROT_CTRL_CTS
;
3214 mm40_prot
|= RT2860_REG_PROT_CTRL_NONE
;
3216 gf40_prot
= mm40_prot
;
3219 /* IEEE80211_HTINFO_OPMODE_MIXED */
3220 case IEEE80211_HTINFO_OPMODE_MIXED
:
3221 mm20_prot
= RT2860_REG_PROT_NAV_SHORT
|
3222 RT2860_REG_TXOP_ALLOW_CCK
| RT2860_REG_TXOP_ALLOW_OFDM
|
3223 RT2860_REG_TXOP_ALLOW_MM20
| RT2860_REG_TXOP_ALLOW_GF20
;
3225 if (ic
->ic_flags
& IEEE80211_F_USEPROT
)
3226 mm20_prot
|= (RT2860_REG_PROT_PHYMODE_CCK
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3227 (3 << RT2860_REG_PROT_MCS_SHIFT
);
3229 mm20_prot
|= (RT2860_REG_PROT_PHYMODE_OFDM
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3230 (4 << RT2860_REG_PROT_MCS_SHIFT
);
3232 if (htprotmode
== IEEE80211_PROT_RTSCTS
)
3233 mm20_prot
|= RT2860_REG_PROT_CTRL_RTS_CTS
;
3234 else if (htprotmode
== IEEE80211_PROT_CTSONLY
)
3235 mm20_prot
|= RT2860_REG_PROT_CTRL_CTS
;
3237 mm20_prot
|= RT2860_REG_PROT_CTRL_NONE
;
3239 gf20_prot
= mm20_prot
;
3241 mm40_prot
= RT2860_REG_PROT_NAV_SHORT
| RT2860_REG_TXOP_ALLOW_ALL
;
3243 if (ic
->ic_flags
& IEEE80211_F_USEPROT
)
3244 mm40_prot
|= (RT2860_REG_PROT_PHYMODE_CCK
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3245 (3 << RT2860_REG_PROT_MCS_SHIFT
);
3247 mm40_prot
|= (RT2860_REG_PROT_PHYMODE_OFDM
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3248 (0x84 << RT2860_REG_PROT_MCS_SHIFT
);
3250 if (htprotmode
== IEEE80211_PROT_RTSCTS
)
3251 mm40_prot
|= RT2860_REG_PROT_CTRL_RTS_CTS
;
3252 else if (htprotmode
== IEEE80211_PROT_CTSONLY
)
3253 mm40_prot
|= RT2860_REG_PROT_CTRL_CTS
;
3255 mm40_prot
|= RT2860_REG_PROT_CTRL_NONE
;
3257 gf40_prot
= mm40_prot
;
3261 * IEEE80211_HTINFO_OPMODE_PURE
3262 * IEEE80211_HTINFO_OPMODE_PROTOPT
3264 case IEEE80211_HTINFO_OPMODE_PURE
:
3265 case IEEE80211_HTINFO_OPMODE_PROTOPT
:
3267 mm20_prot
= RT2860_REG_PROT_NAV_SHORT
| RT2860_REG_PROT_CTRL_NONE
|
3268 RT2860_REG_TXOP_ALLOW_CCK
| RT2860_REG_TXOP_ALLOW_OFDM
|
3269 RT2860_REG_TXOP_ALLOW_MM20
| RT2860_REG_TXOP_ALLOW_GF20
|
3270 (RT2860_REG_PROT_PHYMODE_OFDM
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3271 (4 << RT2860_REG_PROT_MCS_SHIFT
);
3273 gf20_prot
= mm20_prot
;
3275 mm40_prot
= RT2860_REG_PROT_NAV_SHORT
| RT2860_REG_PROT_CTRL_NONE
|
3276 RT2860_REG_TXOP_ALLOW_ALL
|
3277 (RT2860_REG_PROT_PHYMODE_OFDM
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3278 (0x84 << RT2860_REG_PROT_MCS_SHIFT
);
3280 gf40_prot
= mm40_prot
;
3284 rt2860_io_mac_write(sc
, RT2860_REG_TX_MM20_PROT_CFG
, mm20_prot
);
3285 rt2860_io_mac_write(sc
, RT2860_REG_TX_MM40_PROT_CFG
, mm40_prot
);
3286 rt2860_io_mac_write(sc
, RT2860_REG_TX_GF20_PROT_CFG
, gf20_prot
);
3287 rt2860_io_mac_write(sc
, RT2860_REG_TX_GF40_PROT_CFG
, gf40_prot
);
3291 * rt2860_asic_updateslot
3293 static void rt2860_asic_updateslot(struct rt2860_softc
*sc
)
3295 struct ieee80211com
*ic
;
3300 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATE
,
3301 "%s: %s short slot time\n",
3302 device_get_nameunit(sc
->dev
),
3303 (ic
->ic_flags
& (IEEE80211_F_SHSLOT
| IEEE80211_F_BURST
)) ? "enabling" : "disabling");
3305 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_BKOFF_SLOT_CFG
);
3308 tmp
|= (ic
->ic_flags
& (IEEE80211_F_SHSLOT
|IEEE80211_F_BURST
)) ? 9 : 20;
3310 rt2860_io_mac_write(sc
, RT2860_REG_BKOFF_SLOT_CFG
, tmp
);
3314 * rt2860_asic_wme_update
3316 static void rt2860_asic_wme_update(struct rt2860_softc
*sc
)
3318 struct ieee80211com
*ic
;
3319 struct ieee80211_wme_state
*wme
;
3320 const struct wmeParams
*wmep
;
3325 wmep
= wme
->wme_chanParams
.cap_wmeParams
;
3327 RT2860_DPRINTF(sc
, RT2860_DEBUG_WME
,
3328 "%s: wme update: WME_AC_VO=%d/%d/%d/%d, WME_AC_VI=%d/%d/%d/%d, "
3329 "WME_AC_BK=%d/%d/%d/%d, WME_AC_BE=%d/%d/%d/%d\n",
3330 device_get_nameunit(sc
->dev
),
3331 wmep
[WME_AC_VO
].wmep_aifsn
,
3332 wmep
[WME_AC_VO
].wmep_logcwmin
, wmep
[WME_AC_VO
].wmep_logcwmax
,
3333 wmep
[WME_AC_VO
].wmep_txopLimit
,
3334 wmep
[WME_AC_VI
].wmep_aifsn
,
3335 wmep
[WME_AC_VI
].wmep_logcwmin
, wmep
[WME_AC_VI
].wmep_logcwmax
,
3336 wmep
[WME_AC_VI
].wmep_txopLimit
,
3337 wmep
[WME_AC_BK
].wmep_aifsn
,
3338 wmep
[WME_AC_BK
].wmep_logcwmin
, wmep
[WME_AC_BK
].wmep_logcwmax
,
3339 wmep
[WME_AC_BK
].wmep_txopLimit
,
3340 wmep
[WME_AC_BE
].wmep_aifsn
,
3341 wmep
[WME_AC_BE
].wmep_logcwmin
, wmep
[WME_AC_BE
].wmep_logcwmax
,
3342 wmep
[WME_AC_BE
].wmep_txopLimit
);
3344 for (i
= 0; i
< WME_NUM_AC
; i
++)
3345 rt2860_io_mac_write(sc
, RT2860_REG_TX_EDCA_AC_CFG(i
),
3346 (wmep
[i
].wmep_logcwmax
<< 16) | (wmep
[i
].wmep_logcwmin
<< 12) |
3347 (wmep
[i
].wmep_aifsn
<< 8) | wmep
[i
].wmep_txopLimit
);
3349 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WMM_AIFSN_CFG
,
3350 (wmep
[WME_AC_VO
].wmep_aifsn
<< 12) | (wmep
[WME_AC_VI
].wmep_aifsn
<< 8) |
3351 (wmep
[WME_AC_BK
].wmep_aifsn
<< 4) | wmep
[WME_AC_BE
].wmep_aifsn
);
3353 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WMM_CWMIN_CFG
,
3354 (wmep
[WME_AC_VO
].wmep_logcwmin
<< 12) | (wmep
[WME_AC_VI
].wmep_logcwmin
<< 8) |
3355 (wmep
[WME_AC_BK
].wmep_logcwmin
<< 4) | wmep
[WME_AC_BE
].wmep_logcwmin
);
3357 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WMM_CWMAX_CFG
,
3358 (wmep
[WME_AC_VO
].wmep_logcwmax
<< 12) | (wmep
[WME_AC_VI
].wmep_logcwmax
<< 8) |
3359 (wmep
[WME_AC_BK
].wmep_logcwmax
<< 4) | wmep
[WME_AC_BE
].wmep_logcwmax
);
3361 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WMM_TXOP0_CFG
,
3362 (wmep
[WME_AC_BK
].wmep_txopLimit
<< 16) | wmep
[WME_AC_BE
].wmep_txopLimit
);
3364 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WMM_TXOP1_CFG
,
3365 (wmep
[WME_AC_VO
].wmep_txopLimit
<< 16) | wmep
[WME_AC_VI
].wmep_txopLimit
);
3369 * rt2860_asic_update_beacon
3371 static void rt2860_asic_update_beacon(struct rt2860_softc
*sc
)
3373 struct ieee80211com
*ic
;
3375 struct rt2860_txwi
*txwi
;
3380 m
= sc
->beacon_mbuf
;
3381 txwi
= &sc
->beacon_txwi
;
3383 /* disable temporarily TSF sync */
3385 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_BCN_TIME_CFG
);
3387 tmp
&= ~(RT2860_REG_BCN_TX_ENABLE
|
3388 RT2860_REG_TSF_TIMER_ENABLE
|
3389 RT2860_REG_TBTT_TIMER_ENABLE
);
3391 rt2860_io_mac_write(sc
, RT2860_REG_BCN_TIME_CFG
, tmp
);
3393 /* write Tx wireless info and beacon frame to on-chip memory */
3395 rt2860_io_mac_write_multi(sc
, RT2860_REG_BEACON_BASE(0),
3396 txwi
, sizeof(struct rt2860_txwi
));
3398 rt2860_io_mac_write_multi(sc
, RT2860_REG_BEACON_BASE(0) + sizeof(struct rt2860_txwi
),
3399 mtod(m
, uint8_t *), m
->m_pkthdr
.len
);
3401 /* enable again TSF sync */
3403 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_BCN_TIME_CFG
);
3405 tmp
|= (RT2860_REG_BCN_TX_ENABLE
|
3406 RT2860_REG_TSF_TIMER_ENABLE
|
3407 RT2860_REG_TBTT_TIMER_ENABLE
);
3409 rt2860_io_mac_write(sc
, RT2860_REG_BCN_TIME_CFG
, tmp
);
3413 * rt2860_asic_clear_keytables
3415 static void rt2860_asic_clear_keytables(struct rt2860_softc
*sc
)
3419 /* clear Rx WCID search table (entries = 256, entry size = 8) */
3421 for (i
= 0; i
< 256; i
++)
3423 rt2860_io_mac_write(sc
, RT2860_REG_WCID(i
), 0xffffffff);
3424 rt2860_io_mac_write(sc
, RT2860_REG_WCID(i
) + 4, 0x0000ffff);
3427 /* clear WCID attribute table (entries = 256, entry size = 4) */
3429 rt2860_io_mac_set_region_4(sc
, RT2860_REG_WCID_ATTR(0), 0, 256);
3431 /* clear IV/EIV table (entries = 256, entry size = 8) */
3433 rt2860_io_mac_set_region_4(sc
, RT2860_REG_IVEIV(0), 0, 2 * 256);
3435 /* clear pairwise key table (entries = 64, entry size = 32) */
3437 rt2860_io_mac_set_region_4(sc
, RT2860_REG_PKEY(0), 0, 8 * 64);
3439 /* clear shared key table (entries = 32, entry size = 32) */
3441 rt2860_io_mac_set_region_4(sc
, RT2860_REG_SKEY(0, 0), 0, 8 * 32);
3443 /* clear shared key mode (entries = 32, entry size = 2) */
3445 rt2860_io_mac_set_region_4(sc
, RT2860_REG_SKEY_MODE(0), 0, 16);
3449 * rt2860_beacon_alloc
3451 static int rt2860_beacon_alloc(struct rt2860_softc
*sc
)
3453 struct ieee80211com
*ic
;
3455 struct rt2860_txwi txwi
;
3460 m
= ieee80211_beacon_alloc(ic
->ic_bss
, &sc
->beacon_offsets
);
3464 rate
= IEEE80211_IS_CHAN_5GHZ(ic
->ic_curchan
) ? 12 : 2;
3465 mcs
= rt2860_rate2mcs(rate
);
3467 memset(&txwi
, 0, sizeof(struct rt2860_txwi
));
3470 txwi
.pid_mpdu_len
= ((htole16(m
->m_pkthdr
.len
) & RT2860_TXWI_MPDU_LEN_MASK
) <<
3471 RT2860_TXWI_MPDU_LEN_SHIFT
);
3472 txwi
.txop
= (RT2860_TXWI_TXOP_HT
<< RT2860_TXWI_TXOP_SHIFT
);
3473 txwi
.mpdu_density_flags
|=
3474 (RT2860_TXWI_FLAGS_TS
<< RT2860_TXWI_FLAGS_SHIFT
);
3475 txwi
.bawin_size_xflags
|=
3476 (RT2860_TXWI_XFLAGS_NSEQ
<< RT2860_TXWI_XFLAGS_SHIFT
);
3480 txwi
.phymode_ifs_stbc_shortgi
=
3481 (RT2860_TXWI_PHYMODE_CCK
<< RT2860_TXWI_PHYMODE_SHIFT
);
3483 if (rate
!= 2 && (ic
->ic_flags
& IEEE80211_F_SHPREAMBLE
))
3484 mcs
|= RT2860_TXWI_MCS_SHOTPRE
;
3488 txwi
.phymode_ifs_stbc_shortgi
=
3489 (RT2860_TXWI_PHYMODE_OFDM
<< RT2860_TXWI_PHYMODE_SHIFT
);
3492 txwi
.bw_mcs
= (RT2860_TXWI_BW_20
<< RT2860_TXWI_BW_SHIFT
) |
3493 ((mcs
& RT2860_TXWI_MCS_MASK
) << RT2860_TXWI_MCS_SHIFT
);
3495 if (sc
->beacon_mbuf
!= NULL
)
3497 m_free(sc
->beacon_mbuf
);
3498 sc
->beacon_mbuf
= NULL
;
3501 sc
->beacon_mbuf
= m
;
3502 sc
->beacon_txwi
= txwi
;
3510 static uint8_t rt2860_rxrate(struct rt2860_rxwi
*rxwi
)
3512 uint8_t mcs
, phymode
;
3515 mcs
= (rxwi
->bw_mcs
>> RT2860_RXWI_MCS_SHIFT
) & RT2860_RXWI_MCS_MASK
;
3516 phymode
= (rxwi
->phymode_stbc_shortgi
>> RT2860_RXWI_PHYMODE_SHIFT
) &
3517 RT2860_RXWI_PHYMODE_MASK
;
3523 case RT2860_RXWI_PHYMODE_CCK
:
3524 switch (mcs
& ~RT2860_RXWI_MCS_SHOTPRE
)
3526 case 0: rate
= 2; break; /* 1 Mbps */
3527 case 1: rate
= 4; break; /* 2 MBps */
3528 case 2: rate
= 11; break; /* 5.5 Mbps */
3529 case 3: rate
= 22; break; /* 11 Mbps */
3533 case RT2860_RXWI_PHYMODE_OFDM
:
3536 case 0: rate
= 12; break; /* 6 Mbps */
3537 case 1: rate
= 18; break; /* 9 Mbps */
3538 case 2: rate
= 24; break; /* 12 Mbps */
3539 case 3: rate
= 36; break; /* 18 Mbps */
3540 case 4: rate
= 48; break; /* 24 Mbps */
3541 case 5: rate
= 72; break; /* 36 Mbps */
3542 case 6: rate
= 96; break; /* 48 Mbps */
3543 case 7: rate
= 108; break; /* 54 Mbps */
3547 case RT2860_RXWI_PHYMODE_HT_MIXED
:
3548 case RT2860_RXWI_PHYMODE_HT_GF
:
3556 * rt2860_maxrssi_rxpath
3558 static uint8_t rt2860_maxrssi_rxpath(struct rt2860_softc
*sc
,
3559 const struct rt2860_rxwi
*rxwi
)
3565 if (sc
->nrxpath
> 1)
3566 if (rxwi
->rssi
[1] > rxwi
->rssi
[rxpath
])
3569 if (sc
->nrxpath
> 2)
3570 if (rxwi
->rssi
[2] > rxwi
->rssi
[rxpath
])
3579 static int8_t rt2860_rssi2dbm(struct rt2860_softc
*sc
,
3580 uint8_t rssi
, uint8_t rxpath
)
3582 struct ieee80211com
*ic
;
3583 struct ieee80211_channel
*c
;
3585 int8_t rssi_off
, lna_gain
;
3592 chan
= ieee80211_chan2ieee(ic
, c
);
3594 if (IEEE80211_IS_CHAN_5GHZ(c
))
3596 rssi_off
= sc
->rssi_off_5ghz
[rxpath
];
3599 lna_gain
= sc
->lna_gain
[1];
3600 else if (chan
<= 128)
3601 lna_gain
= sc
->lna_gain
[2];
3603 lna_gain
= sc
->lna_gain
[3];
3607 rssi_off
= sc
->rssi_off_2ghz
[rxpath
];
3608 lna_gain
= sc
->lna_gain
[0];
3611 return (-12 - rssi_off
- lna_gain
- rssi
);
3617 static uint8_t rt2860_rate2mcs(uint8_t rate
)
3644 static int rt2860_ackrate(struct ieee80211com
*ic
, int rate
)
3656 return (ic
->ic_curmode
== IEEE80211_MODE_11B
) ? 4 : rate
;
3675 /* default to 1Mbps */
3682 static uint16_t rt2860_txtime(int len
, int rate
, uint32_t flags
)
3686 if (RT2860_RATE_IS_OFDM(rate
))
3688 txtime
= (8 + 4 * len
+ 3 + rate
- 1) / rate
;
3689 txtime
= 16 + 4 + 4 * txtime
+ 6;
3693 txtime
= (16 * len
+ rate
- 1) / rate
;
3695 if (rate
!= 2 && (flags
& IEEE80211_F_SHPREAMBLE
))
3707 static int rt2860_tx_frame(struct rt2860_softc
*sc
,
3708 struct mbuf
*m
, struct ieee80211_node
*ni
, int qid
)
3710 struct ieee80211com
*ic
;
3711 struct rt2860_softc_node
*rni
;
3712 struct rt2860_softc_tx_ring
*ring
;
3713 struct rt2860_softc_tx_data
*data
;
3714 struct rt2860_txdesc
*desc
;
3715 struct rt2860_txwi
*txwi
;
3716 struct ieee80211_frame
*wh
;
3717 struct ieee80211_tx_ampdu
*tx_ampdu
;
3718 struct rt2860_softc_tx_radiotap_header
*tap
;
3719 bus_dma_segment_t dma_seg
[RT2860_SOFTC_MAX_SCATTER
];
3720 u_int hdrsize
, hdrspace
;
3721 uint8_t type
, rate
, bw
, stbc
, shortgi
, mcs
, pid
, wcid
, mpdu_density
, bawin_size
, qsel
;
3722 uint16_t qos
, len
, dmalen
, mpdu_len
, dur
;
3723 int error
, hasqos
, ac
, ampdu
, mimops
, ackrate
, ndmasegs
, ndescs
, i
, j
;
3725 KASSERT(qid
>= 0 && qid
< RT2860_SOFTC_TX_RING_COUNT
,
3726 ("%s: Tx frame: invalid qid=%d\n",
3727 device_get_nameunit(sc
->dev
), qid
));
3730 rni
= (struct rt2860_softc_node
*) ni
;
3732 ring
= &sc
->tx_ring
[qid
];
3733 desc
= &ring
->desc
[ring
->desc_cur
];
3734 data
= &ring
->data
[ring
->data_cur
];
3735 txwi
= (struct rt2860_txwi
*) (ring
->seg0
+ ring
->data_cur
* RT2860_TX_DATA_SEG0_SIZE
);
3737 wh
= mtod(m
, struct ieee80211_frame
*);
3739 type
= wh
->i_fc
[0] & IEEE80211_FC0_TYPE_MASK
;
3741 hasqos
= IEEE80211_QOS_HAS_SEQ(wh
);
3744 if (IEEE80211_HAS_ADDR4(wh
))
3745 qos
= le16toh(*(const uint16_t *)
3746 (((struct ieee80211_qosframe_addr4
*) wh
)->i_qos
));
3748 qos
= le16toh(*(const uint16_t *)
3749 (((struct ieee80211_qosframe
*) wh
)->i_qos
));
3756 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
3758 if (IEEE80211_IS_MULTICAST(wh
->i_addr1
) || type
!= IEEE80211_FC0_TYPE_DATA
)
3760 else if (ic
->ic_fixed_rate
!= IEEE80211_FIXED_RATE_NONE
)
3761 rate
= ic
->ic_fixed_rate
;
3763 rate
= ni
->ni_htrates
.rs_rates
[ni
->ni_txrate
];
3767 if (IEEE80211_IS_MULTICAST(wh
->i_addr1
) || type
!= IEEE80211_FC0_TYPE_DATA
)
3768 rate
= IEEE80211_IS_CHAN_5GHZ(ic
->ic_curchan
) ? 12 : 2;
3769 else if (ic
->ic_fixed_rate
!= IEEE80211_FIXED_RATE_NONE
)
3770 rate
= ic
->ic_fixed_rate
;
3772 rate
= ni
->ni_rates
.rs_rates
[ni
->ni_txrate
];
3775 rate
&= IEEE80211_RATE_VAL
;
3777 /* fill Tx wireless info */
3779 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
3782 mcs
= rt2860_rate2mcs(rate
);
3784 /* management frames do not need encryption */
3786 if (type
== IEEE80211_FC0_TYPE_DATA
)
3787 wcid
= !IEEE80211_IS_MULTICAST(wh
->i_addr1
) ? rni
->staid
: RT2860_WCID_MCAST
;
3789 wcid
= RT2860_WCID_RESERVED
;
3791 /* calculate MPDU length without padding */
3793 hdrsize
= ieee80211_hdrsize(wh
);
3794 hdrspace
= ieee80211_hdrspace(ic
, wh
);
3795 mpdu_len
= m
->m_pkthdr
.len
- hdrspace
+ hdrsize
;
3797 memset(txwi
, 0, sizeof(struct rt2860_txwi
));
3801 /* MIMO power save */
3803 if ((ni
->ni_flags
& IEEE80211_NODE_HT
) &&
3804 ((ni
->ni_htcap
& IEEE80211_HTCAP_SMPS
) != IEEE80211_HTCAP_SMPS_OFF
))
3808 if ((ni
->ni_htcap
& IEEE80211_HTCAP_SMPS
) == IEEE80211_HTCAP_SMPS_DYNAMIC
)
3810 /* dynamic MIMO power save */
3812 txwi
->mpdu_density_flags
|=
3813 (RT2860_TXWI_FLAGS_MIMOPS
<< RT2860_TXWI_FLAGS_SHIFT
);
3817 /* static MIMO power save */
3832 txwi
->pid_mpdu_len
= ((htole16(pid
) & RT2860_TXWI_PID_MASK
) <<
3833 RT2860_TXWI_PID_SHIFT
) | ((htole16(mpdu_len
) & RT2860_TXWI_MPDU_LEN_MASK
) <<
3834 RT2860_TXWI_MPDU_LEN_SHIFT
);
3836 stbc
= (ic
->ic_htcaps
& IEEE80211_HTCAP_TXSTBC
) &&
3837 (ni
->ni_flags
& IEEE80211_NODE_HT
) && (ni
->ni_htcap
& IEEE80211_HTCAP_RXSTBC
);
3839 shortgi
= (ic
->ic_flags_ext
& (IEEE80211_FEXT_SHORTGI20
| IEEE80211_FEXT_SHORTGI40
)) &&
3840 (ni
->ni_flags
& IEEE80211_NODE_HT
) && (ni
->ni_htcap
& (IEEE80211_HTCAP_SHORTGI20
| IEEE80211_HTCAP_SHORTGI40
));
3842 txwi
->phymode_ifs_stbc_shortgi
|=
3843 ((stbc
& RT2860_TXWI_STBC_MASK
) << RT2860_TXWI_STBC_SHIFT
) |
3844 ((shortgi
& RT2860_TXWI_SHORTGI_MASK
) << RT2860_TXWI_SHORTGI_SHIFT
);
3846 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
3848 txwi
->phymode_ifs_stbc_shortgi
|=
3849 (RT2860_TXWI_PHYMODE_HT_MIXED
<< RT2860_TXWI_PHYMODE_SHIFT
);
3853 if (!RT2860_RATE_IS_OFDM(rate
))
3855 txwi
->phymode_ifs_stbc_shortgi
|=
3856 (RT2860_TXWI_PHYMODE_CCK
<< RT2860_TXWI_PHYMODE_SHIFT
);
3858 if (rate
!= 2 && (ic
->ic_flags
& IEEE80211_F_SHPREAMBLE
))
3859 mcs
|= RT2860_TXWI_MCS_SHOTPRE
;
3863 txwi
->phymode_ifs_stbc_shortgi
|=
3864 (RT2860_TXWI_PHYMODE_OFDM
<< RT2860_TXWI_PHYMODE_SHIFT
);
3868 if ((ni
->ni_flags
& IEEE80211_NODE_HT
) && (ni
->ni_chw
== 40))
3869 bw
= RT2860_TXWI_BW_40
;
3871 bw
= RT2860_TXWI_BW_20
;
3873 txwi
->bw_mcs
= ((bw
& RT2860_TXWI_BW_MASK
) << RT2860_TXWI_BW_SHIFT
) |
3874 ((mcs
& RT2860_TXWI_MCS_MASK
) << RT2860_TXWI_MCS_SHIFT
);
3876 if (type
!= IEEE80211_FC0_TYPE_DATA
)
3877 txwi
->txop
= (RT2860_TXWI_TXOP_BACKOFF
<< RT2860_TXWI_TXOP_SHIFT
);
3879 txwi
->txop
= (RT2860_TXWI_TXOP_HT
<< RT2860_TXWI_TXOP_SHIFT
);
3881 /* skip ACKs for multicast frames */
3883 if (!IEEE80211_IS_MULTICAST(wh
->i_addr1
) &&
3884 (!hasqos
|| (qos
& IEEE80211_QOS_ACKPOLICY
) != IEEE80211_QOS_ACKPOLICY_NOACK
))
3886 txwi
->bawin_size_xflags
|=
3887 (RT2860_TXWI_XFLAGS_ACK
<< RT2860_TXWI_XFLAGS_SHIFT
);
3889 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
3891 /* preamble + plcp + signal extension + SIFS */
3893 dur
= 16 + 4 + 6 + 10;
3897 ackrate
= rt2860_ackrate(ic
, rate
);
3899 dur
= rt2860_txtime(RT2860_ACK_SIZE
, ackrate
, ic
->ic_flags
) +
3903 *(uint16_t *) wh
->i_dur
= htole16(dur
);
3906 /* check for A-MPDU */
3908 if ((qos
& IEEE80211_QOS_ACKPOLICY
) == IEEE80211_QOS_ACKPOLICY_BA
)
3910 ac
= M_WME_GETAC(m
);
3911 tx_ampdu
= &ni
->ni_tx_ampdu
[ac
];
3913 mpdu_density
= RT2860_MS(ni
->ni_htparam
, IEEE80211_HTCAP_MPDUDENSITY
);
3914 bawin_size
= tx_ampdu
->txa_wnd
;
3916 txwi
->mpdu_density_flags
|=
3917 ((mpdu_density
& RT2860_TXWI_MPDU_DENSITY_MASK
) << RT2860_TXWI_MPDU_DENSITY_SHIFT
) |
3918 (RT2860_TXWI_FLAGS_AMPDU
<< RT2860_TXWI_FLAGS_SHIFT
);
3920 txwi
->bawin_size_xflags
|=
3921 ((bawin_size
& RT2860_TXWI_BAWIN_SIZE_MASK
) << RT2860_TXWI_BAWIN_SIZE_SHIFT
);
3923 if (IEEE80211_HAS_ADDR4(wh
))
3924 ((struct ieee80211_qosframe_addr4
*) wh
)->i_qos
[0] &= ~IEEE80211_QOS_ACKPOLICY
;
3926 ((struct ieee80211_qosframe
*) wh
)->i_qos
[0] &= ~IEEE80211_QOS_ACKPOLICY
;
3935 /* ask MAC to insert timestamp into probe responses */
3937 if ((wh
->i_fc
[0] & (IEEE80211_FC0_TYPE_MASK
| IEEE80211_FC0_SUBTYPE_MASK
)) ==
3938 (IEEE80211_FC0_TYPE_MGT
| IEEE80211_FC0_SUBTYPE_PROBE_RESP
))
3939 txwi
->mpdu_density_flags
|=
3940 (RT2860_TXWI_FLAGS_TS
<< RT2860_TXWI_FLAGS_SHIFT
);
3942 if (bpf_peers_present(sc
->drvbpf
))
3946 tap
->flags
= IEEE80211_RADIOTAP_F_DATAPAD
;
3947 tap
->chan_flags
= htole32(ic
->ic_curchan
->ic_flags
);
3948 tap
->chan_freq
= htole16(ic
->ic_curchan
->ic_freq
);
3949 tap
->chan_ieee
= ic
->ic_curchan
->ic_ieee
;
3950 tap
->chan_maxpow
= 0;
3952 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
3953 tap
->rate
= mcs
| IEEE80211_RATE_MCS
;
3957 if (mcs
& RT2860_TXWI_MCS_SHOTPRE
)
3958 tap
->flags
|= IEEE80211_RADIOTAP_F_SHORTPRE
;
3961 tap
->flags
|= IEEE80211_RADIOTAP_F_SHORTGI
;
3963 if (wh
->i_fc
[1] & IEEE80211_FC1_WEP
)
3964 tap
->flags
|= IEEE80211_RADIOTAP_F_WEP
;
3966 if (wh
->i_fc
[1] & IEEE80211_FC1_WEP
)
3968 wh
->i_fc
[1] &= ~IEEE80211_FC1_WEP
;
3970 bpf_mtap2(sc
->drvbpf
, tap
, sc
->txtap_len
, m
);
3972 wh
->i_fc
[1] |= IEEE80211_FC1_WEP
;
3976 bpf_mtap2(sc
->drvbpf
, tap
, sc
->txtap_len
, m
);
3980 /* copy and trim 802.11 header */
3982 m_copydata(m
, 0, hdrsize
, (caddr_t
) (txwi
+ 1));
3985 error
= bus_dmamap_load_mbuf_sg(ring
->data_dma_tag
, data
->dma_map
, m
,
3986 dma_seg
, &ndmasegs
, 0);
3989 /* too many fragments, linearize */
3991 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
3992 "%s: could not load mbuf DMA map, trying to linearize mbuf\n",
3993 device_get_nameunit(sc
->dev
));
3995 m
= m_defrag(m
, M_DONTWAIT
);
3999 sc
->tx_defrag_packets
++;
4001 error
= bus_dmamap_load_mbuf_sg(ring
->data_dma_tag
, data
->dma_map
, m
,
4002 dma_seg
, &ndmasegs
, 0);
4005 printf("%s: could not load mbuf DMA map: error=%d\n",
4006 device_get_nameunit(sc
->dev
), error
);
4012 if (m
->m_pkthdr
.len
== 0)
4015 /* determine how many Tx descs are required */
4017 ndescs
= 1 + ndmasegs
/ 2;
4018 if ((ring
->desc_queued
+ ndescs
) > (RT2860_SOFTC_TX_RING_DESC_COUNT
- 2))
4020 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
4021 "%s: there are not enough Tx descs\n",
4022 device_get_nameunit(sc
->dev
));
4024 sc
->no_tx_desc_avail
++;
4026 bus_dmamap_unload(ring
->data_dma_tag
, data
->dma_map
);
4034 /* set up Tx descs */
4036 /* first segment is Tx wireless info and 802.11 header */
4038 len
= sizeof(struct rt2860_txwi
) + hdrsize
;
4040 /* align end on a 4-bytes boundary */
4042 dmalen
= (len
+ 3) & ~ 3;
4044 memset((caddr_t
) txwi
+ len
, 0, dmalen
- len
);
4046 qsel
= RT2860_TXDESC_QSEL_EDCA
;
4048 desc
->sdp0
= htole32(ring
->seg0_phys_addr
+ ring
->data_cur
* RT2860_TX_DATA_SEG0_SIZE
);
4049 desc
->sdl0
= htole16(dmalen
);
4050 desc
->qsel_flags
= (qsel
<< RT2860_TXDESC_QSEL_SHIFT
);
4052 /* set up payload segments */
4054 for (i
= ndmasegs
, j
= 0; i
>= 2; i
-= 2)
4056 desc
->sdp1
= htole32(dma_seg
[j
].ds_addr
);
4057 desc
->sdl1
= htole16(dma_seg
[j
].ds_len
);
4059 ring
->desc_queued
++;
4060 ring
->desc_cur
= (ring
->desc_cur
+ 1) % RT2860_SOFTC_TX_RING_DESC_COUNT
;
4064 desc
= &ring
->desc
[ring
->desc_cur
];
4066 desc
->sdp0
= htole32(dma_seg
[j
].ds_addr
);
4067 desc
->sdl0
= htole16(dma_seg
[j
].ds_len
);
4068 desc
->qsel_flags
= (qsel
<< RT2860_TXDESC_QSEL_SHIFT
);
4073 /* finalize last payload segment */
4077 desc
->sdp1
= htole32(dma_seg
[j
].ds_addr
);
4078 desc
->sdl1
= htole16(dma_seg
[j
].ds_len
| RT2860_TXDESC_SDL1_LASTSEG
);
4082 desc
->sdl0
|= htole16(RT2860_TXDESC_SDL0_LASTSEG
);
4086 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
4087 "%s: sending frame: qid=%d, hdrsize=%d, hdrspace=%d, len=%d, "
4088 "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",
4089 device_get_nameunit(sc
->dev
),
4090 qid
, hdrsize
, hdrspace
, m
->m_pkthdr
.len
+ hdrsize
,
4091 bw
, stbc
, shortgi
, mcs
, wcid
, ampdu
, mimops
, dmalen
, ndmasegs
,
4092 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
);
4094 bus_dmamap_sync(ring
->seg0_dma_tag
, ring
->seg0_dma_map
,
4095 BUS_DMASYNC_PREWRITE
);
4096 bus_dmamap_sync(ring
->data_dma_tag
, data
->dma_map
,
4097 BUS_DMASYNC_PREWRITE
);
4098 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
4099 BUS_DMASYNC_PREWRITE
);
4101 ring
->desc_queued
++;
4102 ring
->desc_cur
= (ring
->desc_cur
+ 1) % RT2860_SOFTC_TX_RING_DESC_COUNT
;
4104 ring
->data_queued
++;
4105 ring
->data_cur
= (ring
->data_cur
+ 1) % RT2860_SOFTC_TX_RING_DATA_COUNT
;
4109 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_CTX_IDX(qid
), ring
->desc_cur
);
4117 static int rt2860_tx_raw(struct rt2860_softc
*sc
,
4118 struct mbuf
*m
, struct ieee80211_node
*ni
,
4119 const struct ieee80211_bpf_params
*params
)
4121 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
4123 device_get_nameunit(sc
->dev
));
4131 static void rt2860_intr(void *arg
)
4133 struct rt2860_softc
*sc
;
4140 /* acknowledge interrupts */
4142 status
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_INT_STATUS
);
4143 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_INT_STATUS
, status
);
4145 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4146 "%s: interrupt: status = 0x%08x\n",
4147 device_get_nameunit(sc
->dev
), status
);
4149 if (status
== 0xffffffff || /* device likely went away */
4150 status
== 0) /* not for us */
4155 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
4158 if (status
& RT2860_REG_INT_TX_COHERENT
)
4159 rt2860_tx_coherent_intr(sc
);
4161 if (status
& RT2860_REG_INT_RX_COHERENT
)
4162 rt2860_rx_coherent_intr(sc
);
4164 if (status
& RT2860_REG_INT_TXRX_COHERENT
)
4165 rt2860_txrx_coherent_intr(sc
);
4167 if (status
& RT2860_REG_INT_FIFO_STA_FULL
)
4168 rt2860_fifo_sta_full_intr(sc
);
4170 if (status
& RT2860_REG_INT_TX_MGMT_DONE
)
4171 rt2860_tx_intr(sc
, 5);
4173 if (status
& RT2860_REG_INT_RX_DONE
)
4176 if (status
& RT2860_REG_INT_RX_DELAY_DONE
)
4177 rt2860_rx_delay_intr(sc
);
4179 if (status
& RT2860_REG_INT_TX_HCCA_DONE
)
4180 rt2860_tx_intr(sc
, 4);
4182 if (status
& RT2860_REG_INT_TX_AC3_DONE
)
4183 rt2860_tx_intr(sc
, 3);
4185 if (status
& RT2860_REG_INT_TX_AC2_DONE
)
4186 rt2860_tx_intr(sc
, 2);
4188 if (status
& RT2860_REG_INT_TX_AC1_DONE
)
4189 rt2860_tx_intr(sc
, 1);
4191 if (status
& RT2860_REG_INT_TX_AC0_DONE
)
4192 rt2860_tx_intr(sc
, 0);
4194 if (status
& RT2860_REG_INT_TX_DELAY_DONE
)
4195 rt2860_tx_delay_intr(sc
);
4197 if (status
& RT2860_REG_INT_PRE_TBTT
)
4198 rt2860_pre_tbtt_intr(sc
);
4200 if (status
& RT2860_REG_INT_TBTT
)
4201 rt2860_tbtt_intr(sc
);
4203 if (status
& RT2860_REG_INT_MCU_CMD
)
4204 rt2860_mcu_cmd_intr(sc
);
4206 if (status
& RT2860_REG_INT_AUTO_WAKEUP
)
4207 rt2860_auto_wakeup_intr(sc
);
4209 if (status
& RT2860_REG_INT_GP_TIMER
)
4210 rt2860_gp_timer_intr(sc
);
4214 * rt2860_tx_coherent_intr
4216 static void rt2860_tx_coherent_intr(struct rt2860_softc
*sc
)
4221 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4222 "%s: Tx coherent interrupt\n",
4223 device_get_nameunit(sc
->dev
));
4225 sc
->tx_coherent_interrupts
++;
4227 /* restart DMA engine */
4229 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
);
4231 tmp
&= ~(RT2860_REG_TX_WB_DDONE
|
4232 RT2860_REG_RX_DMA_ENABLE
|
4233 RT2860_REG_TX_DMA_ENABLE
);
4235 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
, tmp
);
4237 /* init Tx rings (4 EDCAs + HCCA + MGMT) */
4239 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
4240 rt2860_reset_tx_ring(sc
, &sc
->tx_ring
[i
]);
4242 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
4244 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_BASE_PTR(i
),
4245 sc
->tx_ring
[i
].desc_phys_addr
);
4246 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_MAX_CNT(i
),
4247 RT2860_SOFTC_TX_RING_DESC_COUNT
);
4248 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_CTX_IDX(i
), 0);
4253 rt2860_reset_rx_ring(sc
, &sc
->rx_ring
);
4255 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_BASE_PTR
,
4256 sc
->rx_ring
.desc_phys_addr
);
4257 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_MAX_CNT
,
4258 RT2860_SOFTC_RX_RING_DATA_COUNT
);
4259 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_CALC_IDX
,
4260 RT2860_SOFTC_RX_RING_DATA_COUNT
- 1);
4262 rt2860_txrx_enable(sc
);
4266 * rt2860_rx_coherent_intr
4268 static void rt2860_rx_coherent_intr(struct rt2860_softc
*sc
)
4273 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4274 "%s: Rx coherent interrupt\n",
4275 device_get_nameunit(sc
->dev
));
4277 sc
->rx_coherent_interrupts
++;
4279 /* restart DMA engine */
4281 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
);
4283 tmp
&= ~(RT2860_REG_TX_WB_DDONE
|
4284 RT2860_REG_RX_DMA_ENABLE
|
4285 RT2860_REG_TX_DMA_ENABLE
);
4287 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
, tmp
);
4289 /* init Tx rings (4 EDCAs + HCCA + MGMT) */
4291 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
4292 rt2860_reset_tx_ring(sc
, &sc
->tx_ring
[i
]);
4294 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
4296 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_BASE_PTR(i
),
4297 sc
->tx_ring
[i
].desc_phys_addr
);
4298 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_MAX_CNT(i
),
4299 RT2860_SOFTC_TX_RING_DESC_COUNT
);
4300 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_CTX_IDX(i
), 0);
4305 rt2860_reset_rx_ring(sc
, &sc
->rx_ring
);
4307 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_BASE_PTR
,
4308 sc
->rx_ring
.desc_phys_addr
);
4309 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_MAX_CNT
,
4310 RT2860_SOFTC_RX_RING_DATA_COUNT
);
4311 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_CALC_IDX
,
4312 RT2860_SOFTC_RX_RING_DATA_COUNT
- 1);
4314 rt2860_txrx_enable(sc
);
4318 * rt2860_txrx_coherent_intr
4320 static void rt2860_txrx_coherent_intr(struct rt2860_softc
*sc
)
4325 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4326 "%s: Tx/Rx coherent interrupt\n",
4327 device_get_nameunit(sc
->dev
));
4329 sc
->txrx_coherent_interrupts
++;
4331 /* restart DMA engine */
4333 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
);
4335 tmp
&= ~(RT2860_REG_TX_WB_DDONE
|
4336 RT2860_REG_RX_DMA_ENABLE
|
4337 RT2860_REG_TX_DMA_ENABLE
);
4339 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
, tmp
);
4341 /* init Tx rings (4 EDCAs + HCCA + MGMT) */
4343 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
4344 rt2860_reset_tx_ring(sc
, &sc
->tx_ring
[i
]);
4346 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
4348 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_BASE_PTR(i
),
4349 sc
->tx_ring
[i
].desc_phys_addr
);
4350 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_MAX_CNT(i
),
4351 RT2860_SOFTC_TX_RING_DESC_COUNT
);
4352 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_CTX_IDX(i
), 0);
4357 rt2860_reset_rx_ring(sc
, &sc
->rx_ring
);
4359 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_BASE_PTR
,
4360 sc
->rx_ring
.desc_phys_addr
);
4361 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_MAX_CNT
,
4362 RT2860_SOFTC_RX_RING_DATA_COUNT
);
4363 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_CALC_IDX
,
4364 RT2860_SOFTC_RX_RING_DATA_COUNT
- 1);
4366 rt2860_txrx_enable(sc
);
4370 * rt2860_fifo_sta_full_intr
4372 static void rt2860_fifo_sta_full_intr(struct rt2860_softc
*sc
)
4374 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4375 "%s: FIFO statistic full interrupt\n",
4376 device_get_nameunit(sc
->dev
));
4378 sc
->fifo_sta_full_interrupts
++;
4380 RT2860_SOFTC_LOCK(sc
);
4382 if (!(sc
->intr_disable_mask
& RT2860_REG_INT_FIFO_STA_FULL
))
4384 rt2860_intr_disable(sc
, RT2860_REG_INT_FIFO_STA_FULL
);
4386 taskqueue_enqueue(sc
->taskqueue
, &sc
->fifo_sta_full_task
);
4389 sc
->intr_pending_mask
|= RT2860_REG_INT_FIFO_STA_FULL
;
4391 RT2860_SOFTC_UNLOCK(sc
);
4397 static void rt2860_rx_intr(struct rt2860_softc
*sc
)
4399 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4400 "%s: Rx interrupt\n",
4401 device_get_nameunit(sc
->dev
));
4403 sc
->rx_interrupts
++;
4405 RT2860_SOFTC_LOCK(sc
);
4407 if (!(sc
->intr_disable_mask
& RT2860_REG_INT_RX_DONE
))
4409 rt2860_intr_disable(sc
, RT2860_REG_INT_RX_DONE
);
4411 taskqueue_enqueue(sc
->taskqueue
, &sc
->rx_done_task
);
4414 sc
->intr_pending_mask
|= RT2860_REG_INT_RX_DONE
;
4416 RT2860_SOFTC_UNLOCK(sc
);
4420 * rt2860_rx_delay_intr
4422 static void rt2860_rx_delay_intr(struct rt2860_softc
*sc
)
4424 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4425 "%s: Rx delay interrupt\n",
4426 device_get_nameunit(sc
->dev
));
4428 sc
->rx_delay_interrupts
++;
4434 static void rt2860_tx_intr(struct rt2860_softc
*sc
, int qid
)
4436 KASSERT(qid
>= 0 && qid
< RT2860_SOFTC_TX_RING_COUNT
,
4437 ("%s: Tx interrupt: invalid qid=%d\n",
4438 device_get_nameunit(sc
->dev
), qid
));
4440 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4441 "%s: Tx interrupt: qid=%d\n",
4442 device_get_nameunit(sc
->dev
), qid
);
4444 sc
->tx_interrupts
[qid
]++;
4446 RT2860_SOFTC_LOCK(sc
);
4448 if (!(sc
->intr_disable_mask
& (RT2860_REG_INT_TX_AC0_DONE
<< qid
)))
4450 rt2860_intr_disable(sc
, (RT2860_REG_INT_TX_AC0_DONE
<< qid
));
4452 taskqueue_enqueue(sc
->taskqueue
, &sc
->tx_done_task
);
4455 sc
->intr_pending_mask
|= (RT2860_REG_INT_TX_AC0_DONE
<< qid
);
4457 RT2860_SOFTC_UNLOCK(sc
);
4461 * rt2860_tx_delay_intr
4463 static void rt2860_tx_delay_intr(struct rt2860_softc
*sc
)
4465 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4466 "%s: Tx delay interrupt\n",
4467 device_get_nameunit(sc
->dev
));
4469 sc
->tx_delay_interrupts
++;
4473 * rt2860_pre_tbtt_intr
4475 static void rt2860_pre_tbtt_intr(struct rt2860_softc
*sc
)
4477 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4478 "%s: Pre-TBTT interrupt\n",
4479 device_get_nameunit(sc
->dev
));
4481 sc
->pre_tbtt_interrupts
++;
4487 static void rt2860_tbtt_intr(struct rt2860_softc
*sc
)
4489 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4490 "%s: TBTT interrupt\n",
4491 device_get_nameunit(sc
->dev
));
4493 sc
->tbtt_interrupts
++;
4497 * rt2860_mcu_cmd_intr
4499 static void rt2860_mcu_cmd_intr(struct rt2860_softc
*sc
)
4501 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4502 "%s: MCU command interrupt\n",
4503 device_get_nameunit(sc
->dev
));
4505 sc
->mcu_cmd_interrupts
++;
4509 * rt2860_auto_wakeup_intr
4511 static void rt2860_auto_wakeup_intr(struct rt2860_softc
*sc
)
4513 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4514 "%s: auto wakeup interrupt\n",
4515 device_get_nameunit(sc
->dev
));
4517 sc
->auto_wakeup_interrupts
++;
4521 * rt2860_gp_timer_intr
4523 static void rt2860_gp_timer_intr(struct rt2860_softc
*sc
)
4525 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4526 "%s: GP timer interrupt\n",
4527 device_get_nameunit(sc
->dev
));
4529 sc
->gp_timer_interrupts
++;
4533 * rt2860_rx_done_task
4535 static void rt2860_rx_done_task(void *context
, int pending
)
4537 struct rt2860_softc
*sc
;
4544 RT2860_DPRINTF(sc
, RT2860_DEBUG_RX
,
4545 "%s: Rx done task\n",
4546 device_get_nameunit(sc
->dev
));
4548 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
4551 sc
->intr_pending_mask
&= ~RT2860_REG_INT_RX_DONE
;
4553 again
= rt2860_rx_eof(sc
, sc
->rx_process_limit
);
4555 RT2860_SOFTC_LOCK(sc
);
4557 if ((sc
->intr_pending_mask
& RT2860_REG_INT_RX_DONE
) || again
)
4559 RT2860_DPRINTF(sc
, RT2860_DEBUG_RX
,
4560 "%s: Rx done task: scheduling again\n",
4561 device_get_nameunit(sc
->dev
));
4563 taskqueue_enqueue(sc
->taskqueue
, &sc
->rx_done_task
);
4567 rt2860_intr_enable(sc
, RT2860_REG_INT_RX_DONE
);
4570 RT2860_SOFTC_UNLOCK(sc
);
4574 * rt2860_tx_done_task
4576 static void rt2860_tx_done_task(void *context
, int pending
)
4578 struct rt2860_softc
*sc
;
4586 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
4587 "%s: Tx done task\n",
4588 device_get_nameunit(sc
->dev
));
4590 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
4593 for (i
= RT2860_SOFTC_TX_RING_COUNT
- 1; i
>= 0; i
--)
4595 if (sc
->intr_pending_mask
& (RT2860_REG_INT_TX_AC0_DONE
<< i
))
4597 sc
->intr_pending_mask
&= ~(RT2860_REG_INT_TX_AC0_DONE
<< i
);
4599 rt2860_tx_eof(sc
, &sc
->tx_ring
[i
]);
4605 ifp
->if_drv_flags
&= ~IFF_DRV_OACTIVE
;
4607 intr_mask
= (RT2860_REG_INT_TX_MGMT_DONE
|
4608 RT2860_REG_INT_TX_HCCA_DONE
|
4609 RT2860_REG_INT_TX_AC3_DONE
|
4610 RT2860_REG_INT_TX_AC2_DONE
|
4611 RT2860_REG_INT_TX_AC1_DONE
|
4612 RT2860_REG_INT_TX_AC0_DONE
);
4614 RT2860_SOFTC_LOCK(sc
);
4616 rt2860_intr_enable(sc
, ~sc
->intr_pending_mask
&
4617 (sc
->intr_disable_mask
& intr_mask
));
4619 if (sc
->intr_pending_mask
& intr_mask
)
4621 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
4622 "%s: Tx done task: scheduling again\n",
4623 device_get_nameunit(sc
->dev
));
4625 taskqueue_enqueue(sc
->taskqueue
, &sc
->tx_done_task
);
4628 RT2860_SOFTC_UNLOCK(sc
);
4632 * rt2860_fifo_sta_full_task
4634 static void rt2860_fifo_sta_full_task(void *context
, int pending
)
4636 struct rt2860_softc
*sc
;
4642 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATS
,
4643 "%s: FIFO statistic full task\n",
4644 device_get_nameunit(sc
->dev
));
4646 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
4649 sc
->intr_pending_mask
&= ~RT2860_REG_INT_FIFO_STA_FULL
;
4651 rt2860_drain_fifo_stats(sc
);
4653 RT2860_SOFTC_LOCK(sc
);
4655 if (sc
->intr_pending_mask
& RT2860_REG_INT_FIFO_STA_FULL
)
4657 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATS
,
4658 "%s: FIFO statistic full task: scheduling again\n",
4659 device_get_nameunit(sc
->dev
));
4661 taskqueue_enqueue(sc
->taskqueue
, &sc
->fifo_sta_full_task
);
4665 rt2860_intr_enable(sc
, RT2860_REG_INT_FIFO_STA_FULL
);
4668 RT2860_SOFTC_UNLOCK(sc
);
4672 * rt2860_periodic_task
4674 static void rt2860_periodic_task(void *context
, int pending
)
4676 struct rt2860_softc
*sc
;
4678 struct ieee80211com
*ic
;
4684 RT2860_DPRINTF(sc
, RT2860_DEBUG_PERIODIC
,
4685 "%s: periodic task: round=%lu\n",
4686 device_get_nameunit(sc
->dev
), sc
->periodic_round
);
4688 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
4691 RT2860_SOFTC_LOCK(sc
);
4693 sc
->periodic_round
++;
4695 rt2860_update_stats(sc
);
4697 if ((sc
->periodic_round
% 10) == 0)
4699 rt2860_bbp_tuning(sc
);
4701 rt2860_update_raw_counters(sc
);
4703 rt2860_watchdog(sc
);
4705 if (ic
->ic_opmode
!= IEEE80211_M_MONITOR
&& ic
->ic_state
== IEEE80211_S_RUN
)
4707 if (ic
->ic_opmode
== IEEE80211_M_STA
)
4708 rt2860_amrr_update_iter_func(sc
, ic
->ic_bss
);
4710 ieee80211_iterate_nodes(&ic
->ic_sta
, rt2860_amrr_update_iter_func
, sc
);
4714 RT2860_SOFTC_UNLOCK(sc
);
4716 callout_reset(&sc
->periodic_ch
, hz
/ 10, rt2860_periodic
, sc
);
4722 static int rt2860_rx_eof(struct rt2860_softc
*sc
, int limit
)
4724 struct ieee80211com
*ic
;
4726 struct ieee80211_frame
*wh
;
4727 struct ieee80211_node
*ni
;
4728 struct rt2860_softc_node
*rni
;
4729 struct rt2860_softc_rx_radiotap_header
*tap
;
4730 struct rt2860_softc_rx_ring
*ring
;
4731 struct rt2860_rxdesc
*desc
;
4732 struct rt2860_softc_rx_data
*data
;
4733 struct rt2860_rxwi
*rxwi
;
4734 struct mbuf
*m
, *mnew
;
4735 bus_dma_segment_t segs
[1];
4736 bus_dmamap_t dma_map
;
4737 uint32_t index
, desc_flags
;
4738 uint8_t cipher_err
, rssi
, ant
, phymode
, bw
, shortgi
, mcs
, keyidx
;
4740 int error
, nsegs
, len
, ampdu
, amsdu
, nframes
, i
;
4744 ring
= &sc
->rx_ring
;
4750 index
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_RX_DRX_IDX
);
4751 if (ring
->cur
== index
)
4754 desc
= &ring
->desc
[ring
->cur
];
4755 desc_flags
= le32toh(desc
->flags
);
4756 data
= &ring
->data
[ring
->cur
];
4758 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
4759 BUS_DMASYNC_POSTREAD
);
4761 if (!(desc
->sdl0
& htole16(RT2860_RXDESC_SDL0_DDONE
)))
4766 mnew
= m_getjcl(M_DONTWAIT
, MT_DATA
, M_PKTHDR
, MJUMPAGESIZE
);
4769 sc
->rx_mbuf_alloc_errors
++;
4774 mnew
->m_len
= mnew
->m_pkthdr
.len
= MJUMPAGESIZE
;
4776 error
= bus_dmamap_load_mbuf_sg(ring
->data_dma_tag
, ring
->spare_dma_map
,
4777 mnew
, segs
, &nsegs
, BUS_DMA_NOWAIT
);
4782 sc
->rx_mbuf_dmamap_errors
++;
4788 KASSERT(nsegs
== 1, ("%s: too many DMA segments",
4789 device_get_name(sc
->dev
)));
4791 bus_dmamap_sync(ring
->data_dma_tag
, data
->dma_map
,
4792 BUS_DMASYNC_POSTREAD
);
4793 bus_dmamap_unload(ring
->data_dma_tag
, data
->dma_map
);
4795 dma_map
= data
->dma_map
;
4796 data
->dma_map
= ring
->spare_dma_map
;
4797 ring
->spare_dma_map
= dma_map
;
4799 bus_dmamap_sync(ring
->data_dma_tag
, data
->dma_map
,
4800 BUS_DMASYNC_PREREAD
);
4805 desc
->sdp0
= htole32(segs
[0].ds_addr
);
4807 /* get Rx wireless info */
4809 rxwi
= mtod(m
, struct rt2860_rxwi
*);
4810 len
= (le16toh(rxwi
->tid_size
) >> RT2860_RXWI_SIZE_SHIFT
) &
4811 RT2860_RXWI_SIZE_MASK
;
4813 /* check for L2 padding between IEEE 802.11 frame header and body */
4815 if (desc_flags
& RT2860_RXDESC_FLAGS_L2PAD
)
4817 RT2860_DPRINTF(sc
, RT2860_DEBUG_RX
,
4818 "%s: L2 padding: len=%d\n",
4819 device_get_nameunit(sc
->dev
), len
);
4824 m
->m_pkthdr
.rcvif
= ifp
;
4825 m
->m_data
= (caddr_t
) (rxwi
+ 1);
4826 m
->m_pkthdr
.len
= m
->m_len
= len
;
4828 /* check for crc errors */
4830 if (desc_flags
& RT2860_RXDESC_FLAGS_CRC_ERR
)
4832 RT2860_DPRINTF(sc
, RT2860_DEBUG_RX
,
4833 "%s: rxdesc: crc error\n",
4834 device_get_nameunit(sc
->dev
));
4838 if (!(ifp
->if_flags
& IFF_PROMISC
))
4845 wh
= (struct ieee80211_frame
*) (rxwi
+ 1);
4847 /* check for cipher errors */
4849 if (desc_flags
& RT2860_RXDESC_FLAGS_DECRYPTED
)
4851 cipher_err
= ((desc_flags
>> RT2860_RXDESC_FLAGS_CIPHER_ERR_SHIFT
) &
4852 RT2860_RXDESC_FLAGS_CIPHER_ERR_MASK
);
4853 if (cipher_err
== RT2860_RXDESC_FLAGS_CIPHER_ERR_NONE
)
4855 if (wh
->i_fc
[1] & IEEE80211_FC1_WEP
)
4856 wh
->i_fc
[1] &= ~IEEE80211_FC1_WEP
;
4858 m
->m_flags
|= M_WEP
;
4860 sc
->rx_cipher_no_errors
++;
4864 RT2860_DPRINTF(sc
, RT2860_DEBUG_RX
,
4865 "%s: rxdesc: cipher error=0x%02x\n",
4866 device_get_nameunit(sc
->dev
), cipher_err
);
4868 if (cipher_err
== RT2860_RXDESC_FLAGS_CIPHER_ERR_ICV
)
4869 sc
->rx_cipher_icv_errors
++;
4870 else if (cipher_err
== RT2860_RXDESC_FLAGS_CIPHER_ERR_MIC
)
4871 sc
->rx_cipher_mic_errors
++;
4872 else if (cipher_err
== RT2860_RXDESC_FLAGS_CIPHER_ERR_INVALID_KEY
)
4873 sc
->rx_cipher_invalid_key_errors
++;
4875 if ((cipher_err
== RT2860_RXDESC_FLAGS_CIPHER_ERR_MIC
) &&
4876 (desc_flags
& RT2860_RXDESC_FLAGS_MYBSS
))
4878 keyidx
= (rxwi
->udf_bssidx_keyidx
>> RT2860_RXWI_KEYIDX_SHIFT
) &
4879 RT2860_RXWI_KEYIDX_MASK
;
4881 ieee80211_notify_michael_failure(ic
, wh
, keyidx
);
4886 if (!(ifp
->if_flags
& IFF_PROMISC
))
4895 if (wh
->i_fc
[1] & IEEE80211_FC1_WEP
)
4897 RT2860_DPRINTF(sc
, RT2860_DEBUG_RX
,
4898 "%s: rxdesc: not decrypted but protected flag set\n",
4899 device_get_nameunit(sc
->dev
));
4903 if (!(ifp
->if_flags
& IFF_PROMISC
))
4911 /* check for A-MPDU */
4913 if (desc_flags
& RT2860_RXDESC_FLAGS_AMPDU
)
4915 m
->m_flags
|= M_AMPDU
;
4926 /* check for A-MSDU */
4928 if (desc_flags
& RT2860_RXDESC_FLAGS_AMSDU
)
4939 ant
= rt2860_maxrssi_rxpath(sc
, rxwi
);
4940 rssi
= rxwi
->rssi
[ant
];
4941 rssi_dbm
= rt2860_rssi2dbm(sc
, rssi
, ant
);
4942 phymode
= ((rxwi
->phymode_stbc_shortgi
>> RT2860_RXWI_PHYMODE_SHIFT
) &
4943 RT2860_RXWI_PHYMODE_MASK
);
4944 bw
= ((rxwi
->bw_mcs
>> RT2860_RXWI_BW_SHIFT
) & RT2860_RXWI_BW_MASK
);
4945 shortgi
= ((rxwi
->phymode_stbc_shortgi
>> RT2860_RXWI_SHORTGI_SHIFT
) &
4946 RT2860_RXWI_SHORTGI_MASK
);
4947 mcs
= ((rxwi
->bw_mcs
>> RT2860_RXWI_MCS_SHIFT
) & RT2860_RXWI_MCS_MASK
);
4949 if (bpf_peers_present(sc
->drvbpf
))
4953 tap
->flags
= IEEE80211_RADIOTAP_F_DATAPAD
;
4954 tap
->dbm_antsignal
= rssi_dbm
;
4955 tap
->dbm_antnoise
= RT2860_NOISE_FLOOR
;
4957 tap
->antsignal
= rssi
;
4958 tap
->chan_flags
= htole32(ic
->ic_curchan
->ic_flags
);
4959 tap
->chan_freq
= htole16(ic
->ic_curchan
->ic_freq
);
4960 tap
->chan_ieee
= ic
->ic_curchan
->ic_ieee
;
4961 tap
->chan_maxpow
= 0;
4963 if (phymode
== RT2860_TXWI_PHYMODE_HT_MIXED
|| phymode
== RT2860_TXWI_PHYMODE_HT_GF
)
4964 tap
->rate
= mcs
| IEEE80211_RATE_MCS
;
4966 tap
->rate
= rt2860_rxrate(rxwi
);
4968 if (desc_flags
& RT2860_RXDESC_FLAGS_CRC_ERR
)
4969 tap
->flags
|= IEEE80211_RADIOTAP_F_BADFCS
;
4971 if (desc_flags
& RT2860_RXDESC_FLAGS_FRAG
)
4972 tap
->flags
|= IEEE80211_RADIOTAP_F_FRAG
;
4974 if (rxwi
->bw_mcs
& RT2860_RXWI_MCS_SHOTPRE
)
4975 tap
->flags
|= IEEE80211_RADIOTAP_F_SHORTPRE
;
4977 if ((desc_flags
& RT2860_RXDESC_FLAGS_DECRYPTED
) ||
4978 (wh
->i_fc
[1] & IEEE80211_FC1_WEP
))
4979 tap
->flags
|= IEEE80211_RADIOTAP_F_WEP
;
4982 tap
->flags
|= IEEE80211_RADIOTAP_F_SHORTGI
;
4984 bpf_mtap2(sc
->drvbpf
, tap
, sc
->rxtap_len
, m
);
4987 RT2860_DPRINTF(sc
, RT2860_DEBUG_RX
,
4988 "%s: received frame: len=%d, phymode=%d, bw=%d, shortgi=%d, mcs=%d, "
4989 "ant=%d, rssi=%d/%d/%d, snr=%d/%d, wcid=0x%02x, ampdu=%d, amsdu=%d\n",
4990 device_get_nameunit(sc
->dev
),
4991 len
, phymode
, bw
, shortgi
, mcs
,
4992 ant
, rxwi
->rssi
[0], rxwi
->rssi
[1], rxwi
->rssi
[2],
4993 rxwi
->snr
[0], rxwi
->snr
[1],
4994 rxwi
->wcid
, ampdu
, amsdu
);
4996 ni
= ieee80211_find_rxnode(ic
, (struct ieee80211_frame_min
*) wh
);
5000 rni
= (struct rt2860_softc_node
*) ni
;
5002 for (i
= 0; i
< RT2860_SOFTC_RSSI_COUNT
; i
++)
5004 rni
->last_rssi
[i
] = rxwi
->rssi
[i
];
5005 rni
->last_rssi_dbm
[i
] = rt2860_rssi2dbm(sc
, rxwi
->rssi
[i
], i
);
5009 ieee80211_input(ic
, m
, ni
, rssi_dbm
, RT2860_NOISE_FLOOR
, 0);
5011 ieee80211_free_node(ni
);
5015 desc
->sdl0
&= ~htole16(RT2860_RXDESC_SDL0_DDONE
);
5017 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
5018 BUS_DMASYNC_PREREAD
| BUS_DMASYNC_PREWRITE
);
5020 ring
->cur
= (ring
->cur
+ 1) % RT2860_SOFTC_RX_RING_DATA_COUNT
;
5026 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_CALC_IDX
,
5027 RT2860_SOFTC_RX_RING_DATA_COUNT
- 1);
5029 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_CALC_IDX
,
5032 RT2860_DPRINTF(sc
, RT2860_DEBUG_RX
,
5033 "%s: Rx eof: nframes=%d\n",
5034 device_get_nameunit(sc
->dev
), nframes
);
5036 sc
->rx_packets
+= nframes
;
5038 return (limit
== 0);
5044 static void rt2860_tx_eof(struct rt2860_softc
*sc
,
5045 struct rt2860_softc_tx_ring
*ring
)
5048 struct rt2860_txdesc
*desc
;
5049 struct rt2860_softc_tx_data
*data
;
5051 int ndescs
, nframes
;
5060 index
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_TX_DTX_IDX(ring
->qid
));
5061 if (ring
->desc_next
== index
)
5066 rt2860_drain_fifo_stats(sc
);
5068 desc
= &ring
->desc
[ring
->desc_next
];
5070 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
5071 BUS_DMASYNC_POSTREAD
);
5073 if (desc
->sdl0
& htole16(RT2860_TXDESC_SDL0_LASTSEG
) ||
5074 desc
->sdl1
& htole16(RT2860_TXDESC_SDL1_LASTSEG
))
5078 data
= &ring
->data
[ring
->data_next
];
5080 if (data
->m
->m_flags
& M_TXCB
)
5081 ieee80211_process_callback(data
->ni
, data
->m
, 0);
5083 bus_dmamap_sync(ring
->data_dma_tag
, data
->dma_map
,
5084 BUS_DMASYNC_POSTWRITE
);
5085 bus_dmamap_unload(ring
->data_dma_tag
, data
->dma_map
);
5089 ieee80211_free_node(data
->ni
);
5096 RT2860_SOFTC_LOCK(sc
);
5098 ring
->data_queued
--;
5099 ring
->data_next
= (ring
->data_next
+ 1) % RT2860_SOFTC_TX_RING_DATA_COUNT
;
5101 RT2860_SOFTC_UNLOCK(sc
);
5104 desc
->sdl0
&= ~htole16(RT2860_TXDESC_SDL0_DDONE
);
5106 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
5107 BUS_DMASYNC_PREREAD
| BUS_DMASYNC_PREWRITE
);
5109 RT2860_SOFTC_LOCK(sc
);
5111 ring
->desc_queued
--;
5112 ring
->desc_next
= (ring
->desc_next
+ 1) % RT2860_SOFTC_TX_RING_DESC_COUNT
;
5114 RT2860_SOFTC_UNLOCK(sc
);
5117 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
5118 "%s: Tx eof: qid=%d, ndescs=%d, nframes=%d\n",
5119 device_get_nameunit(sc
->dev
), ring
->qid
, ndescs
, nframes
);
5123 * rt2860_update_stats
5125 static void rt2860_update_stats(struct rt2860_softc
*sc
)
5129 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
;
5173 static void rt2860_bbp_tuning(struct rt2860_softc
*sc
)
5175 struct ieee80211com
*ic
;
5176 struct ieee80211_node
*ni
;
5178 int8_t rssi
, old
, new;
5180 /* RT2860C does not support BBP tuning */
5182 if (sc
->mac_rev
== 0x28600100)
5187 if ((ic
->ic_flags
& IEEE80211_F_SCAN
) ||
5188 ic
->ic_opmode
!= IEEE80211_M_STA
|| ic
->ic_state
!= IEEE80211_S_RUN
)
5193 chan
= ieee80211_chan2ieee(ic
, ni
->ni_chan
);
5197 else if (chan
<= 64)
5199 else if (chan
<= 128)
5204 rssi
= ieee80211_getrssi(ic
);
5206 if (IEEE80211_IS_CHAN_2GHZ(ni
->ni_chan
))
5208 new = 0x2e + sc
->lna_gain
[group
];
5212 if (!IEEE80211_IS_CHAN_HT40(ni
->ni_chan
))
5213 new = 0x32 + sc
->lna_gain
[group
] * 5 / 3;
5215 new = 0x3a + sc
->lna_gain
[group
] * 5 / 3;
5218 /* Tune if absolute average RSSI is greater than -80 */
5223 old
= rt2860_io_bbp_read(sc
, 66);
5226 rt2860_io_bbp_write(sc
, 66, new);
5232 static void rt2860_watchdog(struct rt2860_softc
*sc
)
5237 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_PBF_TXRXQ_PCNT
);
5239 RT2860_DPRINTF(sc
, RT2860_DEBUG_WATCHDOG
,
5240 "%s: watchdog: TXRXQ_PCNT=0x%08x\n",
5241 device_get_nameunit(sc
->dev
), tmp
);
5243 if (((tmp
>> RT2860_REG_TX0Q_PCNT_SHIFT
) & RT2860_REG_TX0Q_PCNT_MASK
) != 0)
5245 sc
->tx_queue_not_empty
[0]++;
5247 rt2860_io_mac_write(sc
, RT2860_REG_PBF_CFG
, 0xf40012);
5249 for (ntries
= 0; ntries
< 10; ntries
++)
5251 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_PBF_TXRXQ_PCNT
);
5252 if (((tmp
>> RT2860_REG_TX0Q_PCNT_SHIFT
) & RT2860_REG_TX0Q_PCNT_MASK
) == 0)
5258 rt2860_io_mac_write(sc
, RT2860_REG_PBF_CFG
, 0xf40006);
5261 if (((tmp
>> RT2860_REG_TX1Q_PCNT_SHIFT
) & RT2860_REG_TX1Q_PCNT_MASK
) != 0)
5263 sc
->tx_queue_not_empty
[1]++;
5265 rt2860_io_mac_write(sc
, RT2860_REG_PBF_CFG
, 0xf4000a);
5267 for (ntries
= 0; ntries
< 10; ntries
++)
5269 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_PBF_TXRXQ_PCNT
);
5270 if (((tmp
>> RT2860_REG_TX1Q_PCNT_SHIFT
) & RT2860_REG_TX1Q_PCNT_MASK
) == 0)
5276 rt2860_io_mac_write(sc
, RT2860_REG_PBF_CFG
, 0xf40006);
5281 * rt2860_drain_fifo_stats
5283 static void rt2860_drain_fifo_stats(struct rt2860_softc
*sc
)
5287 uint8_t wcid
, mcs
, pid
;
5288 int ok
, agg
, retrycnt
;
5290 ifp
= sc
->ic
.ic_ifp
;
5292 /* drain Tx status FIFO (maxsize = 16) */
5294 while ((stats
= rt2860_io_mac_read(sc
, RT2860_REG_TX_STA_FIFO
)) &
5295 RT2860_REG_TX_STA_FIFO_VALID
)
5297 wcid
= (stats
>> RT2860_REG_TX_STA_FIFO_WCID_SHIFT
) &
5298 RT2860_REG_TX_STA_FIFO_WCID_MASK
;
5300 /* if no ACK was requested, no feedback is available */
5302 if (!(stats
& RT2860_REG_TX_STA_FIFO_ACK_REQ
) || wcid
== RT2860_WCID_RESERVED
)
5305 /* update AMRR statistic */
5307 ok
= (stats
& RT2860_REG_TX_STA_FIFO_TX_OK
) ? 1 : 0;
5308 agg
= (stats
& RT2860_REG_TX_STA_FIFO_AGG
) ? 1 : 0;
5309 mcs
= (stats
>> RT2860_REG_TX_STA_FIFO_MCS_SHIFT
) &
5310 RT2860_REG_TX_STA_FIFO_MCS_MASK
;
5311 pid
= (stats
>> RT2860_REG_TX_STA_FIFO_PID_SHIFT
) &
5312 RT2860_REG_TX_STA_FIFO_PID_MASK
;
5313 retrycnt
= pid
- mcs
;
5315 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATS
,
5316 "%s: FIFO statistic: wcid=0x%02x, ok=%d, agg=%d, mcs=0x%02x, pid=0x%02x, retrycnt=%d\n",
5317 device_get_nameunit(sc
->dev
),
5318 wcid
, ok
, agg
, mcs
, pid
, retrycnt
);
5320 rt2860_amrr_tx_complete(&sc
->amrr_node
[wcid
], ok
, retrycnt
);
5328 * rt2860_update_raw_counters
5330 static void rt2860_update_raw_counters(struct rt2860_softc
*sc
)
5334 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_AGG_CNT
);
5336 sc
->tx_nonagg
+= tmp
& 0xffff;
5337 sc
->tx_agg
+= tmp
>> 16;
5339 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_AGG_CNT0
);
5341 sc
->tx_ampdu
+= (tmp
& 0xffff) / 1 + (tmp
>> 16) / 2;
5343 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_AGG_CNT1
);
5345 sc
->tx_ampdu
+= (tmp
& 0xffff) / 3 + (tmp
>> 16) / 4;
5347 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_AGG_CNT2
);
5349 sc
->tx_ampdu
+= (tmp
& 0xffff) / 5 + (tmp
>> 16) / 6;
5351 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_AGG_CNT3
);
5353 sc
->tx_ampdu
+= (tmp
& 0xffff) / 7 + (tmp
>> 16) / 8;
5355 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_AGG_CNT4
);
5357 sc
->tx_ampdu
+= (tmp
& 0xffff) / 9 + (tmp
>> 16) / 10;
5359 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_AGG_CNT5
);
5361 sc
->tx_ampdu
+= (tmp
& 0xffff) / 11 + (tmp
>> 16) / 12;
5363 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_AGG_CNT6
);
5365 sc
->tx_ampdu
+= (tmp
& 0xffff) / 13 + (tmp
>> 16) / 14;
5367 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_AGG_CNT7
);
5369 sc
->tx_ampdu
+= (tmp
& 0xffff) / 15 + (tmp
>> 16) / 16;
5371 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_RX_STA_CNT0
);
5373 sc
->rx_crc_errors
+= tmp
& 0xffff;
5374 sc
->rx_phy_errors
+= tmp
>> 16;
5376 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_RX_STA_CNT1
);
5378 sc
->rx_false_ccas
+= tmp
& 0xffff;
5379 sc
->rx_plcp_errors
+= tmp
>> 16;
5381 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_RX_STA_CNT2
);
5383 sc
->rx_dup_packets
+= tmp
& 0xffff;
5384 sc
->rx_fifo_overflows
+= tmp
>> 16;
5386 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TXRX_MPDU_DEN_CNT
);
5388 sc
->tx_mpdu_zero_density
+= tmp
& 0xffff;
5389 sc
->rx_mpdu_zero_density
+= tmp
>> 16;
5393 * rt2860_intr_enable
5395 static void rt2860_intr_enable(struct rt2860_softc
*sc
, uint32_t intr_mask
)
5399 sc
->intr_disable_mask
&= ~intr_mask
;
5401 tmp
= sc
->intr_enable_mask
& ~sc
->intr_disable_mask
;
5403 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_INT_MASK
, tmp
);
5407 * rt2860_intr_disable
5409 static void rt2860_intr_disable(struct rt2860_softc
*sc
, uint32_t intr_mask
)
5413 sc
->intr_disable_mask
|= intr_mask
;
5415 tmp
= sc
->intr_enable_mask
& ~sc
->intr_disable_mask
;
5417 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_INT_MASK
, tmp
);
5421 * rt2860_txrx_enable
5423 static int rt2860_txrx_enable(struct rt2860_softc
*sc
)
5425 struct ieee80211com
*ic
;
5433 /* enable Tx/Rx DMA engine */
5435 rt2860_io_mac_write(sc
, RT2860_REG_SYS_CTRL
, RT2860_REG_TX_ENABLE
);
5437 for (ntries
= 0; ntries
< 200; ntries
++)
5439 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
);
5440 if (!(tmp
& (RT2860_REG_TX_DMA_BUSY
| RT2860_REG_RX_DMA_BUSY
)))
5448 printf("%s: timeout waiting for DMA engine\n",
5449 device_get_nameunit(sc
->dev
));
5455 tmp
|= RT2860_REG_TX_WB_DDONE
|
5456 RT2860_REG_RX_DMA_ENABLE
|
5457 RT2860_REG_TX_DMA_ENABLE
|
5458 (RT2860_REG_WPDMA_BT_SIZE64
<< RT2860_REG_WPDMA_BT_SIZE_SHIFT
);
5460 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
, tmp
);
5464 tmp
= RT2860_REG_RX_FILTER_DROP_CRC_ERR
|
5465 RT2860_REG_RX_FILTER_DROP_PHY_ERR
;
5467 if (ic
->ic_opmode
!= IEEE80211_M_MONITOR
)
5469 tmp
|= RT2860_REG_RX_FILTER_DROP_DUPL
|
5470 RT2860_REG_RX_FILTER_DROP_CTS
|
5471 RT2860_REG_RX_FILTER_DROP_BA
|
5472 RT2860_REG_RX_FILTER_DROP_ACK
|
5473 RT2860_REG_RX_FILTER_DROP_VER_ERR
|
5474 RT2860_REG_RX_FILTER_DROP_CTRL_RSV
|
5475 RT2860_REG_RX_FILTER_DROP_CFACK
|
5476 RT2860_REG_RX_FILTER_DROP_CFEND
;
5478 if (ic
->ic_opmode
== IEEE80211_M_STA
)
5479 tmp
|= RT2860_REG_RX_FILTER_DROP_RTS
|
5480 RT2860_REG_RX_FILTER_DROP_PSPOLL
;
5482 if (!(ifp
->if_flags
& IFF_PROMISC
))
5483 tmp
|= RT2860_REG_RX_FILTER_DROP_UC_NOME
;
5486 rt2860_io_mac_write(sc
, RT2860_REG_RX_FILTER_CFG
, tmp
);
5488 rt2860_io_mac_write(sc
, RT2860_REG_SYS_CTRL
,
5489 RT2860_REG_RX_ENABLE
| RT2860_REG_TX_ENABLE
);
5495 * rt2860_alloc_rx_ring
5497 static int rt2860_alloc_rx_ring(struct rt2860_softc
*sc
,
5498 struct rt2860_softc_rx_ring
*ring
)
5500 struct rt2860_rxdesc
*desc
;
5501 struct rt2860_softc_rx_data
*data
;
5502 bus_dma_segment_t segs
[1];
5503 int i
, nsegs
, error
;
5505 error
= bus_dma_tag_create(bus_get_dma_tag(sc
->dev
), PAGE_SIZE
, 0,
5506 BUS_SPACE_MAXADDR_32BIT
, BUS_SPACE_MAXADDR
, NULL
, NULL
,
5507 RT2860_SOFTC_RX_RING_DATA_COUNT
* sizeof(struct rt2860_rxdesc
), 1,
5508 RT2860_SOFTC_RX_RING_DATA_COUNT
* sizeof(struct rt2860_rxdesc
),
5509 0, NULL
, NULL
, &ring
->desc_dma_tag
);
5512 printf("%s: could not create Rx desc DMA tag\n",
5513 device_get_nameunit(sc
->dev
));
5517 error
= bus_dmamem_alloc(ring
->desc_dma_tag
, (void **) &ring
->desc
,
5518 BUS_DMA_NOWAIT
| BUS_DMA_ZERO
, &ring
->desc_dma_map
);
5521 printf("%s: could not allocate Rx desc DMA memory\n",
5522 device_get_nameunit(sc
->dev
));
5526 error
= bus_dmamap_load(ring
->desc_dma_tag
, ring
->desc_dma_map
,
5528 RT2860_SOFTC_RX_RING_DATA_COUNT
* sizeof(struct rt2860_rxdesc
),
5529 rt2860_dma_map_addr
, &ring
->desc_phys_addr
, 0);
5532 printf("%s: could not load Rx desc DMA map\n",
5533 device_get_nameunit(sc
->dev
));
5537 error
= bus_dma_tag_create(bus_get_dma_tag(sc
->dev
), PAGE_SIZE
, 0,
5538 BUS_SPACE_MAXADDR_32BIT
, BUS_SPACE_MAXADDR
, NULL
, NULL
,
5539 MJUMPAGESIZE
, 1, MJUMPAGESIZE
, 0, NULL
, NULL
,
5540 &ring
->data_dma_tag
);
5543 printf("%s: could not create Rx data DMA tag\n",
5544 device_get_nameunit(sc
->dev
));
5548 for (i
= 0; i
< RT2860_SOFTC_RX_RING_DATA_COUNT
; i
++)
5550 desc
= &ring
->desc
[i
];
5551 data
= &ring
->data
[i
];
5553 error
= bus_dmamap_create(ring
->data_dma_tag
, 0, &data
->dma_map
);
5556 printf("%s: could not create Rx data DMA map\n",
5557 device_get_nameunit(sc
->dev
));
5561 data
->m
= m_getjcl(M_DONTWAIT
, MT_DATA
, M_PKTHDR
, MJUMPAGESIZE
);
5562 if (data
->m
== NULL
)
5564 printf("%s: could not allocate Rx mbuf\n",
5565 device_get_nameunit(sc
->dev
));
5570 data
->m
->m_len
= data
->m
->m_pkthdr
.len
= MJUMPAGESIZE
;
5572 error
= bus_dmamap_load_mbuf_sg(ring
->data_dma_tag
, data
->dma_map
,
5573 data
->m
, segs
, &nsegs
, BUS_DMA_NOWAIT
);
5576 printf("%s: could not load Rx mbuf DMA map\n",
5577 device_get_nameunit(sc
->dev
));
5581 KASSERT(nsegs
== 1, ("%s: too many DMA segments",
5582 device_get_name(sc
->dev
)));
5584 desc
->sdp0
= htole32(segs
[0].ds_addr
);
5585 desc
->sdl0
= htole16(MJUMPAGESIZE
);
5588 error
= bus_dmamap_create(ring
->data_dma_tag
, 0, &ring
->spare_dma_map
);
5591 printf("%s: could not create Rx spare DMA map\n",
5592 device_get_nameunit(sc
->dev
));
5596 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
5597 BUS_DMASYNC_PREWRITE
);
5603 rt2860_free_rx_ring(sc
, ring
);
5609 * rt2860_reset_rx_ring
5611 static void rt2860_reset_rx_ring(struct rt2860_softc
*sc
,
5612 struct rt2860_softc_rx_ring
*ring
)
5614 struct rt2860_rxdesc
*desc
;
5617 for (i
= 0; i
< RT2860_SOFTC_RX_RING_DATA_COUNT
; i
++)
5619 desc
= &ring
->desc
[i
];
5621 desc
->sdl0
&= ~htole16(RT2860_RXDESC_SDL0_DDONE
);
5624 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
5625 BUS_DMASYNC_PREWRITE
);
5631 * rt2860_free_rx_ring
5633 static void rt2860_free_rx_ring(struct rt2860_softc
*sc
,
5634 struct rt2860_softc_rx_ring
*ring
)
5636 struct rt2860_softc_rx_data
*data
;
5639 if (ring
->desc
!= NULL
)
5641 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
5642 BUS_DMASYNC_POSTWRITE
);
5643 bus_dmamap_unload(ring
->desc_dma_tag
, ring
->desc_dma_map
);
5644 bus_dmamem_free(ring
->desc_dma_tag
, ring
->desc
,
5645 ring
->desc_dma_map
);
5648 if (ring
->desc_dma_tag
!= NULL
)
5649 bus_dma_tag_destroy(ring
->desc_dma_tag
);
5651 for (i
= 0; i
< RT2860_SOFTC_RX_RING_DATA_COUNT
; i
++)
5653 data
= &ring
->data
[i
];
5655 if (data
->m
!= NULL
)
5657 bus_dmamap_sync(ring
->data_dma_tag
, data
->dma_map
,
5658 BUS_DMASYNC_POSTREAD
);
5659 bus_dmamap_unload(ring
->data_dma_tag
, data
->dma_map
);
5663 if (data
->dma_map
!= NULL
)
5664 bus_dmamap_destroy(ring
->data_dma_tag
, data
->dma_map
);
5667 if (ring
->spare_dma_map
!= NULL
)
5668 bus_dmamap_destroy(ring
->data_dma_tag
, ring
->spare_dma_map
);
5670 if (ring
->data_dma_tag
!= NULL
)
5671 bus_dma_tag_destroy(ring
->data_dma_tag
);
5675 * rt2860_alloc_tx_ring
5677 static int rt2860_alloc_tx_ring(struct rt2860_softc
*sc
,
5678 struct rt2860_softc_tx_ring
*ring
, int qid
)
5680 struct rt2860_softc_tx_data
*data
;
5683 error
= bus_dma_tag_create(bus_get_dma_tag(sc
->dev
), PAGE_SIZE
, 0,
5684 BUS_SPACE_MAXADDR_32BIT
, BUS_SPACE_MAXADDR
, NULL
, NULL
,
5685 RT2860_SOFTC_TX_RING_DESC_COUNT
* sizeof(struct rt2860_txdesc
), 1,
5686 RT2860_SOFTC_TX_RING_DESC_COUNT
* sizeof(struct rt2860_txdesc
),
5687 0, NULL
, NULL
, &ring
->desc_dma_tag
);
5690 printf("%s: could not create Tx desc DMA tag\n",
5691 device_get_nameunit(sc
->dev
));
5695 error
= bus_dmamem_alloc(ring
->desc_dma_tag
, (void **) &ring
->desc
,
5696 BUS_DMA_NOWAIT
| BUS_DMA_ZERO
, &ring
->desc_dma_map
);
5699 printf("%s: could not allocate Tx desc DMA memory\n",
5700 device_get_nameunit(sc
->dev
));
5704 error
= bus_dmamap_load(ring
->desc_dma_tag
, ring
->desc_dma_map
,
5706 RT2860_SOFTC_TX_RING_DESC_COUNT
* sizeof(struct rt2860_txdesc
),
5707 rt2860_dma_map_addr
, &ring
->desc_phys_addr
, 0);
5710 printf("%s: could not load Tx desc DMA map\n",
5711 device_get_nameunit(sc
->dev
));
5715 ring
->desc_queued
= 0;
5717 ring
->desc_next
= 0;
5719 error
= bus_dma_tag_create(bus_get_dma_tag(sc
->dev
), PAGE_SIZE
, 0,
5720 BUS_SPACE_MAXADDR_32BIT
, BUS_SPACE_MAXADDR
, NULL
, NULL
,
5721 RT2860_SOFTC_TX_RING_DATA_COUNT
* RT2860_TX_DATA_SEG0_SIZE
, 1,
5722 RT2860_SOFTC_TX_RING_DATA_COUNT
* RT2860_TX_DATA_SEG0_SIZE
,
5723 0, NULL
, NULL
, &ring
->seg0_dma_tag
);
5726 printf("%s: could not create Tx seg0 DMA tag\n",
5727 device_get_nameunit(sc
->dev
));
5731 error
= bus_dmamem_alloc(ring
->seg0_dma_tag
, (void **) &ring
->seg0
,
5732 BUS_DMA_NOWAIT
| BUS_DMA_ZERO
, &ring
->seg0_dma_map
);
5735 printf("%s: could not allocate Tx seg0 DMA memory\n",
5736 device_get_nameunit(sc
->dev
));
5740 error
= bus_dmamap_load(ring
->seg0_dma_tag
, ring
->seg0_dma_map
,
5742 RT2860_SOFTC_TX_RING_DATA_COUNT
* RT2860_TX_DATA_SEG0_SIZE
,
5743 rt2860_dma_map_addr
, &ring
->seg0_phys_addr
, 0);
5746 printf("%s: could not load Tx seg0 DMA map\n",
5747 device_get_nameunit(sc
->dev
));
5751 error
= bus_dma_tag_create(bus_get_dma_tag(sc
->dev
), PAGE_SIZE
, 0,
5752 BUS_SPACE_MAXADDR_32BIT
, BUS_SPACE_MAXADDR
, NULL
, NULL
,
5753 MJUMPAGESIZE
, RT2860_SOFTC_MAX_SCATTER
, MJUMPAGESIZE
, 0, NULL
, NULL
,
5754 &ring
->data_dma_tag
);
5757 printf("%s: could not create Tx data DMA tag\n",
5758 device_get_nameunit(sc
->dev
));
5762 for (i
= 0; i
< RT2860_SOFTC_TX_RING_DATA_COUNT
; i
++)
5764 data
= &ring
->data
[i
];
5766 error
= bus_dmamap_create(ring
->data_dma_tag
, 0, &data
->dma_map
);
5769 printf("%s: could not create Tx data DMA map\n",
5770 device_get_nameunit(sc
->dev
));
5775 ring
->data_queued
= 0;
5777 ring
->data_next
= 0;
5785 rt2860_free_tx_ring(sc
, ring
);
5791 * rt2860_reset_tx_ring
5793 static void rt2860_reset_tx_ring(struct rt2860_softc
*sc
,
5794 struct rt2860_softc_tx_ring
*ring
)
5796 struct rt2860_softc_tx_data
*data
;
5797 struct rt2860_txdesc
*desc
;
5800 for (i
= 0; i
< RT2860_SOFTC_TX_RING_DESC_COUNT
; i
++)
5802 desc
= &ring
->desc
[i
];
5808 ring
->desc_queued
= 0;
5810 ring
->desc_next
= 0;
5812 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
5813 BUS_DMASYNC_PREWRITE
);
5815 bus_dmamap_sync(ring
->seg0_dma_tag
, ring
->seg0_dma_map
,
5816 BUS_DMASYNC_PREWRITE
);
5818 for (i
= 0; i
< RT2860_SOFTC_TX_RING_DATA_COUNT
; i
++)
5820 data
= &ring
->data
[i
];
5822 if (data
->m
!= NULL
)
5824 bus_dmamap_sync(ring
->data_dma_tag
, data
->dma_map
,
5825 BUS_DMASYNC_POSTWRITE
);
5826 bus_dmamap_unload(ring
->data_dma_tag
, data
->dma_map
);
5831 if (data
->ni
!= NULL
)
5833 ieee80211_free_node(data
->ni
);
5838 ring
->data_queued
= 0;
5840 ring
->data_next
= 0;
5844 * rt2860_free_tx_ring
5846 static void rt2860_free_tx_ring(struct rt2860_softc
*sc
,
5847 struct rt2860_softc_tx_ring
*ring
)
5849 struct rt2860_softc_tx_data
*data
;
5852 if (ring
->desc
!= NULL
)
5854 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
5855 BUS_DMASYNC_POSTWRITE
);
5856 bus_dmamap_unload(ring
->desc_dma_tag
, ring
->desc_dma_map
);
5857 bus_dmamem_free(ring
->desc_dma_tag
, ring
->desc
,
5858 ring
->desc_dma_map
);
5861 if (ring
->desc_dma_tag
!= NULL
)
5862 bus_dma_tag_destroy(ring
->desc_dma_tag
);
5864 if (ring
->seg0
!= NULL
)
5866 bus_dmamap_sync(ring
->seg0_dma_tag
, ring
->seg0_dma_map
,
5867 BUS_DMASYNC_POSTWRITE
);
5868 bus_dmamap_unload(ring
->seg0_dma_tag
, ring
->seg0_dma_map
);
5869 bus_dmamem_free(ring
->seg0_dma_tag
, ring
->seg0
,
5870 ring
->seg0_dma_map
);
5873 if (ring
->seg0_dma_tag
!= NULL
)
5874 bus_dma_tag_destroy(ring
->seg0_dma_tag
);
5876 for (i
= 0; i
< RT2860_SOFTC_TX_RING_DATA_COUNT
; i
++)
5878 data
= &ring
->data
[i
];
5880 if (data
->m
!= NULL
)
5882 bus_dmamap_sync(ring
->data_dma_tag
, data
->dma_map
,
5883 BUS_DMASYNC_POSTWRITE
);
5884 bus_dmamap_unload(ring
->data_dma_tag
, data
->dma_map
);
5888 if (data
->ni
!= NULL
)
5889 ieee80211_free_node(data
->ni
);
5891 if (data
->dma_map
!= NULL
)
5892 bus_dmamap_destroy(ring
->data_dma_tag
, data
->dma_map
);
5895 if (ring
->data_dma_tag
!= NULL
)
5896 bus_dma_tag_destroy(ring
->data_dma_tag
);
5900 * rt2860_dma_map_addr
5902 static void rt2860_dma_map_addr(void *arg
, bus_dma_segment_t
*segs
,
5903 int nseg
, int error
)
5908 KASSERT(nseg
== 1, ("too many DMA segments, %d should be 1", nseg
));
5910 *(bus_addr_t
*) arg
= segs
[0].ds_addr
;
5914 * rt2860_sysctl_attach
5916 static void rt2860_sysctl_attach(struct rt2860_softc
*sc
)
5918 struct sysctl_ctx_list
*ctx
;
5919 struct sysctl_oid
*tree
;
5920 struct sysctl_oid
*stats
;
5922 ctx
= device_get_sysctl_ctx(sc
->dev
);
5923 tree
= device_get_sysctl_tree(sc
->dev
);
5925 stats
= SYSCTL_ADD_NODE(ctx
, SYSCTL_CHILDREN(tree
), OID_AUTO
,
5926 "stats", CTLFLAG_RD
, 0, "statistic");
5928 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5929 "interrupts", CTLFLAG_RD
, &sc
->interrupts
, 0,
5932 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5933 "tx_coherent_interrupts", CTLFLAG_RD
, &sc
->tx_coherent_interrupts
, 0,
5934 "Tx coherent interrupts");
5936 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5937 "rx_coherent_interrupts", CTLFLAG_RD
, &sc
->rx_coherent_interrupts
, 0,
5938 "Rx coherent interrupts");
5940 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5941 "txrx_coherent_interrupts", CTLFLAG_RD
, &sc
->txrx_coherent_interrupts
, 0,
5942 "Tx/Rx coherent interrupts");
5944 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5945 "fifo_sta_full_interrupts", CTLFLAG_RD
, &sc
->fifo_sta_full_interrupts
, 0,
5946 "FIFO statistic full interrupts");
5948 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5949 "rx_interrupts", CTLFLAG_RD
, &sc
->rx_interrupts
, 0,
5952 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5953 "rx_delay_interrupts", CTLFLAG_RD
, &sc
->rx_delay_interrupts
, 0,
5954 "Rx delay interrupts");
5956 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5957 "tx_mgmt_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[5], 0,
5958 "Tx MGMT interrupts");
5960 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5961 "tx_hcca_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[4], 0,
5962 "Tx HCCA interrupts");
5964 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5965 "tx_ac3_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[3], 0,
5966 "Tx AC3 interrupts");
5968 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5969 "tx_ac2_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[2], 0,
5970 "Tx AC2 interrupts");
5972 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5973 "tx_ac1_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[1], 0,
5974 "Tx AC1 interrupts");
5976 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5977 "tx_ac0_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[0], 0,
5978 "Tx AC0 interrupts");
5980 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5981 "tx_delay_interrupts", CTLFLAG_RD
, &sc
->tx_delay_interrupts
, 0,
5982 "Tx delay interrupts");
5984 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5985 "pre_tbtt_interrupts", CTLFLAG_RD
, &sc
->pre_tbtt_interrupts
, 0,
5986 "Pre-TBTT interrupts");
5988 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5989 "tbtt_interrupts", CTLFLAG_RD
, &sc
->tbtt_interrupts
, 0,
5992 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5993 "mcu_cmd_interrupts", CTLFLAG_RD
, &sc
->mcu_cmd_interrupts
, 0,
5994 "MCU command interrupts");
5996 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5997 "auto_wakeup_interrupts", CTLFLAG_RD
, &sc
->auto_wakeup_interrupts
, 0,
5998 "auto wakeup interrupts");
6000 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6001 "gp_timer_interrupts", CTLFLAG_RD
, &sc
->gp_timer_interrupts
, 0,
6002 "GP timer interrupts");
6004 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6005 "tx_mgmt_desc_queued", CTLFLAG_RD
, &sc
->tx_ring
[5].desc_queued
, 0,
6006 "Tx MGMT descriptors queued");
6008 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6009 "tx_mgmt_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[5].data_queued
, 0,
6010 "Tx MGMT data queued");
6012 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6013 "tx_hcca_desc_queued", CTLFLAG_RD
, &sc
->tx_ring
[4].desc_queued
, 0,
6014 "Tx HCCA descriptors queued");
6016 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6017 "tx_hcca_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[4].data_queued
, 0,
6018 "Tx HCCA data queued");
6020 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6021 "tx_ac3_desc_queued", CTLFLAG_RD
, &sc
->tx_ring
[3].desc_queued
, 0,
6022 "Tx AC3 descriptors queued");
6024 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6025 "tx_ac3_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[3].data_queued
, 0,
6026 "Tx AC3 data queued");
6028 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6029 "tx_ac2_desc_queued", CTLFLAG_RD
, &sc
->tx_ring
[2].desc_queued
, 0,
6030 "Tx AC2 descriptors queued");
6032 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6033 "tx_ac2_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[2].data_queued
, 0,
6034 "Tx AC2 data queued");
6036 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6037 "tx_ac1_desc_queued", CTLFLAG_RD
, &sc
->tx_ring
[1].desc_queued
, 0,
6038 "Tx AC1 descriptors queued");
6040 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6041 "tx_ac1_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[1].data_queued
, 0,
6042 "Tx AC1 data queued");
6044 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6045 "tx_ac0_desc_queued", CTLFLAG_RD
, &sc
->tx_ring
[0].desc_queued
, 0,
6046 "Tx AC0 descriptors queued");
6048 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6049 "tx_ac0_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[0].data_queued
, 0,
6050 "Tx AC0 data queued");
6052 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6053 "tx_mgmt_data_queue_full", CTLFLAG_RD
, &sc
->tx_data_queue_full
[5], 0,
6054 "Tx MGMT data queue full");
6056 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6057 "tx_hcca_data_queue_full", CTLFLAG_RD
, &sc
->tx_data_queue_full
[4], 0,
6058 "Tx HCCA data queue full");
6060 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6061 "tx_ac3_data_queue_full", CTLFLAG_RD
, &sc
->tx_data_queue_full
[3], 0,
6062 "Tx AC3 data queue full");
6064 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6065 "tx_ac2_data_queue_full", CTLFLAG_RD
, &sc
->tx_data_queue_full
[2], 0,
6066 "Tx AC2 data queue full");
6068 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6069 "tx_ac1_data_queue_full", CTLFLAG_RD
, &sc
->tx_data_queue_full
[1], 0,
6070 "Tx AC1 data queue full");
6072 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6073 "tx_ac0_data_queue_full", CTLFLAG_RD
, &sc
->tx_data_queue_full
[0], 0,
6074 "Tx AC0 data queue full");
6076 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6077 "tx_watchdog_timeouts", CTLFLAG_RD
, &sc
->tx_watchdog_timeouts
, 0,
6078 "Tx watchdog timeouts");
6080 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6081 "tx_defrag_packets", CTLFLAG_RD
, &sc
->tx_defrag_packets
, 0,
6082 "Tx defragmented packets");
6084 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6085 "no_tx_desc_avail", CTLFLAG_RD
, &sc
->no_tx_desc_avail
, 0,
6086 "no Tx descriptors available");
6088 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6089 "rx_mbuf_alloc_errors", CTLFLAG_RD
, &sc
->rx_mbuf_alloc_errors
, 0,
6090 "Rx mbuf allocation errors");
6092 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6093 "rx_mbuf_dmamap_errors", CTLFLAG_RD
, &sc
->rx_mbuf_dmamap_errors
, 0,
6094 "Rx mbuf DMA mapping errors");
6096 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6097 "tx_queue_0_not_empty", CTLFLAG_RD
, &sc
->tx_queue_not_empty
[0], 0,
6098 "Tx queue 0 not empty");
6100 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6101 "tx_queue_1_not_empty", CTLFLAG_RD
, &sc
->tx_queue_not_empty
[1], 0,
6102 "Tx queue 1 not empty");
6104 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6105 "tx_beacons", CTLFLAG_RD
, &sc
->tx_beacons
, 0,
6108 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6109 "tx_noretryok", CTLFLAG_RD
, &sc
->tx_noretryok
, 0,
6110 "Tx successfull without retries");
6112 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6113 "tx_retryok", CTLFLAG_RD
, &sc
->tx_retryok
, 0,
6114 "Tx successfull with retries");
6116 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6117 "tx_failed", CTLFLAG_RD
, &sc
->tx_failed
, 0,
6120 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6121 "tx_underflows", CTLFLAG_RD
, &sc
->tx_underflows
, 0,
6124 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6125 "tx_zerolen", CTLFLAG_RD
, &sc
->tx_zerolen
, 0,
6128 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6129 "tx_nonagg", CTLFLAG_RD
, &sc
->tx_nonagg
, 0,
6130 "Tx non-aggregated");
6132 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6133 "tx_agg", CTLFLAG_RD
, &sc
->tx_agg
, 0,
6136 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6137 "tx_ampdu", CTLFLAG_RD
, &sc
->tx_ampdu
, 0,
6140 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6141 "tx_mpdu_zero_density", CTLFLAG_RD
, &sc
->tx_mpdu_zero_density
, 0,
6142 "Tx MPDU with zero density");
6144 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6145 "rx_packets", CTLFLAG_RD
, &sc
->rx_packets
, 0,
6148 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6149 "rx_ampdu", CTLFLAG_RD
, &sc
->rx_ampdu
, 0,
6152 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6153 "rx_mpdu_zero_density", CTLFLAG_RD
, &sc
->rx_mpdu_zero_density
, 0,
6154 "Rx MPDU with zero density");
6156 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6157 "rx_amsdu", CTLFLAG_RD
, &sc
->rx_amsdu
, 0,
6160 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6161 "rx_crc_errors", CTLFLAG_RD
, &sc
->rx_crc_errors
, 0,
6164 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6165 "rx_phy_errors", CTLFLAG_RD
, &sc
->rx_phy_errors
, 0,
6168 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6169 "rx_false_ccas", CTLFLAG_RD
, &sc
->rx_false_ccas
, 0,
6172 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6173 "rx_plcp_errors", CTLFLAG_RD
, &sc
->rx_plcp_errors
, 0,
6176 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6177 "rx_dup_packets", CTLFLAG_RD
, &sc
->rx_dup_packets
, 0,
6178 "Rx duplicate packets");
6180 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6181 "rx_fifo_overflows", CTLFLAG_RD
, &sc
->rx_fifo_overflows
, 0,
6182 "Rx FIFO overflows");
6184 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6185 "rx_cipher_no_errors", CTLFLAG_RD
, &sc
->rx_cipher_no_errors
, 0,
6186 "Rx cipher no errors");
6188 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6189 "rx_cipher_icv_errors", CTLFLAG_RD
, &sc
->rx_cipher_icv_errors
, 0,
6190 "Rx cipher ICV errors");
6192 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6193 "rx_cipher_mic_errors", CTLFLAG_RD
, &sc
->rx_cipher_mic_errors
, 0,
6194 "Rx cipher MIC errors");
6196 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6197 "rx_cipher_invalid_key_errors", CTLFLAG_RD
, &sc
->rx_cipher_invalid_key_errors
, 0,
6198 "Rx cipher invalid key errors");
6201 static device_method_t rt2860_dev_methods
[] =
6203 DEVMETHOD(device_probe
, rt2860_probe
),
6204 DEVMETHOD(device_attach
, rt2860_attach
),
6205 DEVMETHOD(device_detach
, rt2860_detach
),
6206 DEVMETHOD(device_shutdown
, rt2860_shutdown
),
6207 DEVMETHOD(device_suspend
, rt2860_suspend
),
6208 DEVMETHOD(device_resume
, rt2860_resume
),
6212 static driver_t rt2860_driver
=
6216 sizeof(struct rt2860_softc
)
6219 static devclass_t rt2860_dev_class
;
6221 DRIVER_MODULE(rt2860
, pci
, rt2860_driver
, rt2860_dev_class
, 0, 0);
6223 MODULE_DEPEND(rt2860
, pci
, 1, 1, 1);
6224 MODULE_DEPEND(rt2860
, wlan
, 1, 1, 1);