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");
380 static int rt2860_tx_stbc
= 0;
381 SYSCTL_INT(_hw_rt2860
, OID_AUTO
, tx_stbc
, CTLFLAG_RW
, &rt2860_tx_stbc
, 0, "rt2860 Tx STBC");
382 TUNABLE_INT("hw.rt2860.tx_stbc", &rt2860_tx_stbc
);
385 static int rt2860_debug
= 0;
386 SYSCTL_INT(_hw_rt2860
, OID_AUTO
, debug
, CTLFLAG_RW
, &rt2860_debug
, 0, "rt2860 debug level");
387 TUNABLE_INT("hw.rt2860.debug", &rt2860_debug
);
393 static int rt2860_probe(device_t dev
)
395 const struct rt2860_pci_ident
*ident
;
397 for (ident
= rt2860_pci_ids
; ident
->name
!= NULL
; ident
++)
399 if (pci_get_vendor(dev
) == ident
->vendor
&&
400 pci_get_device(dev
) == ident
->device
)
402 device_set_desc(dev
, ident
->name
);
413 static int rt2860_attach(device_t dev
)
415 struct rt2860_softc
*sc
;
417 struct ieee80211com
*ic
;
418 int error
, ntries
, i
;
420 sc
= device_get_softc(dev
);
422 if (pci_get_powerstate(dev
) != PCI_POWERSTATE_D0
)
424 printf("%s: chip is in D%d power mode, setting to D0\n",
425 device_get_nameunit(dev
), pci_get_powerstate(dev
));
426 pci_set_powerstate(dev
, PCI_POWERSTATE_D0
);
429 /* enable bus-mastering */
431 pci_enable_busmaster(dev
);
435 mtx_init(&sc
->lock
, device_get_nameunit(dev
),
436 MTX_NETWORK_LOCK
, MTX_DEF
| MTX_RECURSE
);
438 sc
->mem_rid
= PCIR_BAR(0);
439 sc
->mem
= bus_alloc_resource_any(dev
, SYS_RES_MEMORY
,
440 &sc
->mem_rid
, RF_ACTIVE
);
443 printf("%s: could not allocate memory resource\n",
444 device_get_nameunit(dev
));
449 sc
->bst
= rman_get_bustag(sc
->mem
);
450 sc
->bsh
= rman_get_bushandle(sc
->mem
);
453 sc
->irq
= bus_alloc_resource_any(dev
, SYS_RES_IRQ
,
454 &sc
->irq_rid
, RF_ACTIVE
| RF_SHAREABLE
);
457 printf("%s: could not allocate interrupt resource\n",
458 device_get_nameunit(dev
));
463 sc
->tx_stbc
= rt2860_tx_stbc
;
466 sc
->debug
= rt2860_debug
;
468 SYSCTL_ADD_INT(device_get_sysctl_ctx(dev
),
469 SYSCTL_CHILDREN(device_get_sysctl_tree(dev
)), OID_AUTO
,
470 "debug", CTLFLAG_RW
, &sc
->debug
, 0, "rt2860 debug level");
473 RT2860_DPRINTF(sc
, RT2860_DEBUG_ANY
,
475 device_get_nameunit(sc
->dev
));
477 /* wait for NIC to initialize */
479 for (ntries
= 0; ntries
< 100; ntries
++)
481 sc
->mac_rev
= rt2860_io_mac_read(sc
, RT2860_REG_MAC_CSR0
);
482 if (sc
->mac_rev
!= 0x00000000 && sc
->mac_rev
!= 0xffffffff)
490 printf("%s: timeout waiting for NIC to initialize\n",
491 device_get_nameunit(dev
));
496 rt2860_read_eeprom(sc
);
498 printf("%s: MAC/BBP RT2860 (rev 0x%08x), RF %s\n",
499 device_get_nameunit(sc
->dev
), sc
->mac_rev
,
500 rt2860_rf_name(sc
->rf_rev
));
502 /* clear key tables */
504 rt2860_asic_clear_keytables(sc
);
506 /* allocate Tx and Rx rings */
508 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
510 error
= rt2860_alloc_tx_ring(sc
, &sc
->tx_ring
[i
], i
);
513 printf("%s: could not allocate Tx ring #%d\n",
514 device_get_nameunit(sc
->dev
), i
);
519 sc
->tx_ring_mgtqid
= 5;
521 error
= rt2860_alloc_rx_ring(sc
, &sc
->rx_ring
);
524 printf("%s: could not allocate Rx ring\n",
525 device_get_nameunit(sc
->dev
));
529 callout_init(&sc
->periodic_ch
, 0);
530 callout_init_mtx(&sc
->tx_watchdog_ch
, &sc
->lock
, 0);
532 ifp
= sc
->ifp
= if_alloc(IFT_ETHER
);
535 printf("%s: could not if_alloc()\n",
536 device_get_nameunit(sc
->dev
));
543 if_initname(ifp
, "rt2860", device_get_unit(sc
->dev
));
545 ifp
->if_flags
= IFF_BROADCAST
| IFF_SIMPLEX
| IFF_MULTICAST
;
547 ifp
->if_init
= rt2860_init
;
548 ifp
->if_ioctl
= rt2860_ioctl
;
549 ifp
->if_start
= rt2860_start
;
551 IFQ_SET_MAXLEN(&ifp
->if_snd
, IFQ_MAXLEN
);
552 ifp
->if_snd
.ifq_drv_maxlen
= IFQ_MAXLEN
;
553 IFQ_SET_READY(&ifp
->if_snd
);
559 ic
->ic_phytype
= IEEE80211_T_HT
;
560 ic
->ic_opmode
= IEEE80211_M_STA
;
561 ic
->ic_state
= IEEE80211_S_INIT
;
563 ic
->ic_caps
= IEEE80211_C_MONITOR
|
570 IEEE80211_C_SHPREAMBLE
|
577 IEEE80211_C_AES_CCM
|
580 ic
->ic_htcaps
= IEEE80211_HTC_HT
|
581 IEEE80211_HTC_AMSDU
| /* A-MSDU Tx */
582 IEEE80211_HTC_AMPDU
| /* A-MPDU Tx */
583 IEEE80211_HTCAP_MAXAMSDU_3839
| /* max. A-MSDU Rx length */
584 IEEE80211_HTCAP_CHWIDTH40
| /* HT 40MHz channel width */
585 IEEE80211_HTCAP_GREENFIELD
| /* HT greenfield */
586 IEEE80211_HTCAP_SHORTGI20
| /* HT 20MHz short GI */
587 IEEE80211_HTCAP_SHORTGI40
| /* HT 40MHz short GI */
588 IEEE80211_HTCAP_SMPS_OFF
; /* MIMO power save disabled */
590 /* spatial streams */
592 if (sc
->nrxpath
== 2)
593 ic
->ic_htcaps
|= IEEE80211_HTCAP_RXSTBC_2STREAM
;
594 else if (sc
->nrxpath
== 3)
595 ic
->ic_htcaps
|= IEEE80211_HTCAP_RXSTBC_3STREAM
;
597 ic
->ic_htcaps
|= IEEE80211_HTCAP_RXSTBC_1STREAM
;
600 ic
->ic_htcaps
|= IEEE80211_HTCAP_TXSTBC
;
604 if (sc
->mac_rev
!= 0x28600100)
605 ic
->ic_htcaps
|= IEEE80211_HTCAP_DELBA
;
610 ic
->ic_regdomain
= 0;
611 ic
->ic_countrycode
= CTRY_DEFAULT
;
614 rt2860_init_channels(sc
);
616 rt2860_init_channels_ht40(sc
);
618 IEEE80211_ADDR_COPY(ic
->ic_myaddr
, sc
->mac_addr
);
620 ieee80211_ifattach(ic
);
622 sc
->newstate
= ic
->ic_newstate
;
623 ic
->ic_newstate
= rt2860_newstate
;
625 ic
->ic_reset
= rt2860_reset
;
626 ic
->ic_node_alloc
= rt2860_node_alloc
;
628 sc
->node_cleanup
= ic
->ic_node_cleanup
;
629 ic
->ic_node_cleanup
= rt2860_node_cleanup
;
631 ic
->ic_scan_start
= rt2860_scan_start
;
632 ic
->ic_scan_end
= rt2860_scan_end
;
633 ic
->ic_set_channel
= rt2860_set_channel
;
634 ic
->ic_newassoc
= rt2860_newassoc
;
635 ic
->ic_updateslot
= rt2860_updateslot
;
636 ic
->ic_wme
.wme_update
= rt2860_wme_update
;
637 ic
->ic_update_beacon
= rt2860_update_beacon
;
638 ic
->ic_crypto
.cs_key_update_begin
= rt2860_key_update_begin
;
639 ic
->ic_crypto
.cs_key_update_end
= rt2860_key_update_end
;
640 ic
->ic_crypto
.cs_key_set
= rt2860_key_set
;
641 ic
->ic_crypto
.cs_key_delete
= rt2860_key_delete
;
642 ic
->ic_raw_xmit
= rt2860_raw_xmit
;
644 sc
->recv_action
= ic
->ic_recv_action
;
645 ic
->ic_recv_action
= rt2860_recv_action
;
647 sc
->send_action
= ic
->ic_send_action
;
648 ic
->ic_send_action
= rt2860_send_action
;
650 /* override Rx A-MPDU factor */
652 ic
->ic_ampdu_rxmax
= IEEE80211_HTCAP_MAXRXAMPDU_32K
;
653 ic
->ic_ampdu_density
= IEEE80211_HTCAP_MPDUDENSITY_NA
;
654 ic
->ic_ampdu_limit
= ic
->ic_ampdu_rxmax
;
656 /* hardware requires padding between 802.11 frame header and body */
658 ic
->ic_flags
|= IEEE80211_F_WME
| IEEE80211_F_DATAPAD
| IEEE80211_F_DOTH
;
660 ic
->ic_flags_ext
|= IEEE80211_FEXT_SWBMISS
;
662 ic
->ic_max_aid
= RT2860_SOFTC_STAID_COUNT
;
664 ieee80211_media_init(ic
, rt2860_media_change
, ieee80211_media_status
);
666 rt2860_amrr_init(&sc
->amrr
, ic
,
668 RT2860_AMRR_MIN_SUCCESS_THRESHOLD
,
669 RT2860_AMRR_MAX_SUCCESS_THRESHOLD
,
672 bpfattach2(ifp
, DLT_IEEE802_11_RADIO
,
673 sizeof(struct ieee80211_frame
) + IEEE80211_RADIOTAP_HDRLEN
,
676 sc
->rxtap_len
= sizeof(sc
->rxtapu
);
677 sc
->rxtap
.ihdr
.it_len
= htole16(sc
->rxtap_len
);
678 sc
->rxtap
.ihdr
.it_present
= htole32(RT2860_SOFTC_RX_RADIOTAP_PRESENT
);
680 sc
->txtap_len
= sizeof(sc
->txtapu
);
681 sc
->txtap
.ihdr
.it_len
= htole16(sc
->txtap_len
);
682 sc
->txtap
.ihdr
.it_present
= htole32(RT2860_SOFTC_TX_RADIOTAP_PRESENT
);
684 /* init task queue */
686 TASK_INIT(&sc
->rx_done_task
, 0, rt2860_rx_done_task
, sc
);
687 TASK_INIT(&sc
->tx_done_task
, 0, rt2860_tx_done_task
, sc
);
688 TASK_INIT(&sc
->fifo_sta_full_task
, 0, rt2860_fifo_sta_full_task
, sc
);
689 TASK_INIT(&sc
->periodic_task
, 0, rt2860_periodic_task
, sc
);
691 sc
->rx_process_limit
= 100;
693 sc
->taskqueue
= taskqueue_create("rt2860_taskq", M_NOWAIT
,
694 taskqueue_thread_enqueue
, &sc
->taskqueue
);
696 taskqueue_start_threads(&sc
->taskqueue
, 1, PI_NET
, "%s taskq",
697 device_get_nameunit(sc
->dev
));
699 rt2860_sysctl_attach(sc
);
702 ieee80211_announce(ic
);
704 /* set up interrupt */
706 error
= bus_setup_intr(dev
, sc
->irq
, INTR_TYPE_NET
| INTR_MPSAFE
,
707 NULL
, rt2860_intr
, sc
, &sc
->irqh
);
710 printf("%s: could not set up interrupt\n",
711 device_get_nameunit(dev
));
719 /* free Tx and Rx rings */
721 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
722 rt2860_free_tx_ring(sc
, &sc
->tx_ring
[i
]);
724 rt2860_free_rx_ring(sc
, &sc
->rx_ring
);
726 mtx_destroy(&sc
->lock
);
729 bus_release_resource(dev
, SYS_RES_MEMORY
, sc
->mem_rid
, sc
->mem
);
732 bus_release_resource(dev
, SYS_RES_IRQ
, sc
->irq_rid
, sc
->irq
);
740 static int rt2860_detach(device_t dev
)
742 struct rt2860_softc
*sc
;
743 struct ieee80211com
*ic
;
747 sc
= device_get_softc(dev
);
751 RT2860_DPRINTF(sc
, RT2860_DEBUG_ANY
,
753 device_get_nameunit(sc
->dev
));
755 RT2860_SOFTC_LOCK(sc
);
757 ifp
->if_drv_flags
&= ~(IFF_DRV_RUNNING
| IFF_DRV_OACTIVE
);
759 ieee80211_new_state(ic
, IEEE80211_S_INIT
, -1);
761 callout_stop(&sc
->periodic_ch
);
762 callout_stop(&sc
->tx_watchdog_ch
);
764 taskqueue_drain(sc
->taskqueue
, &sc
->rx_done_task
);
765 taskqueue_drain(sc
->taskqueue
, &sc
->tx_done_task
);
766 taskqueue_drain(sc
->taskqueue
, &sc
->fifo_sta_full_task
);
767 taskqueue_drain(sc
->taskqueue
, &sc
->periodic_task
);
769 /* free Tx and Rx rings */
771 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
772 rt2860_free_tx_ring(sc
, &sc
->tx_ring
[i
]);
774 rt2860_free_rx_ring(sc
, &sc
->rx_ring
);
776 RT2860_SOFTC_UNLOCK(sc
);
780 ieee80211_ifdetach(ic
);
784 taskqueue_free(sc
->taskqueue
);
786 mtx_destroy(&sc
->lock
);
788 bus_generic_detach(dev
);
790 bus_teardown_intr(dev
, sc
->irq
, sc
->irqh
);
792 bus_release_resource(dev
, SYS_RES_IRQ
, sc
->irq_rid
, sc
->irq
);
794 bus_release_resource(dev
, SYS_RES_MEMORY
, sc
->mem_rid
, sc
->mem
);
802 static int rt2860_shutdown(device_t dev
)
804 struct rt2860_softc
*sc
;
806 sc
= device_get_softc(dev
);
808 RT2860_DPRINTF(sc
, RT2860_DEBUG_ANY
,
809 "%s: shutting down\n",
810 device_get_nameunit(sc
->dev
));
814 sc
->flags
&= ~RT2860_SOFTC_FLAGS_UCODE_LOADED
;
822 static int rt2860_suspend(device_t dev
)
824 struct rt2860_softc
*sc
;
826 sc
= device_get_softc(dev
);
828 RT2860_DPRINTF(sc
, RT2860_DEBUG_ANY
,
830 device_get_nameunit(sc
->dev
));
834 sc
->flags
&= ~RT2860_SOFTC_FLAGS_UCODE_LOADED
;
842 static int rt2860_resume(device_t dev
)
844 struct rt2860_softc
*sc
;
847 sc
= device_get_softc(dev
);
850 RT2860_DPRINTF(sc
, RT2860_DEBUG_ANY
,
852 device_get_nameunit(sc
->dev
));
854 if (ifp
->if_flags
& IFF_UP
)
861 * rt2860_init_channels
863 static void rt2860_init_channels(struct rt2860_softc
*sc
)
865 struct ieee80211com
*ic
;
866 struct ieee80211_channel
*c
;
871 /* set supported channels for 2GHz band */
873 for (i
= 1; i
<= 14; i
++)
875 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
876 flags
= IEEE80211_CHAN_B
;
878 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
882 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
883 flags
= IEEE80211_CHAN_B
| IEEE80211_CHAN_HT20
;
885 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
889 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
890 flags
= IEEE80211_CHAN_G
;
892 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
896 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
897 flags
= IEEE80211_CHAN_G
| IEEE80211_CHAN_HT20
;
899 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
904 /* set supported channels for 5GHz band */
906 if (sc
->rf_rev
== RT2860_EEPROM_RF_2850
||
907 sc
->rf_rev
== RT2860_EEPROM_RF_2750
)
909 for (i
= 36; i
<= 64; i
+= 4)
911 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
912 flags
= IEEE80211_CHAN_A
;
914 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
918 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
919 flags
= IEEE80211_CHAN_A
| IEEE80211_CHAN_HT20
;
921 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
926 for (i
= 100; i
<= 140; i
+= 4)
928 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
929 flags
= IEEE80211_CHAN_A
;
931 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
935 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
936 flags
= IEEE80211_CHAN_A
| IEEE80211_CHAN_HT20
;
938 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
943 for (i
= 149; i
<= 165; i
+= 4)
945 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
946 flags
= IEEE80211_CHAN_A
;
948 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
952 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
953 flags
= IEEE80211_CHAN_A
| IEEE80211_CHAN_HT20
;
955 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
963 * rt2860_init_channels_ht40
965 static void rt2860_init_channels_ht40(struct rt2860_softc
*sc
)
967 struct ieee80211com
*ic
;
968 struct ieee80211_channel
*c
, *cent
, *ext
;
973 /* set supported channels for 2GHz band */
975 for (i
= 1; i
<= 14; i
++)
977 flags
= IEEE80211_CHAN_G
| IEEE80211_CHAN_HT40
;
979 /* find the center channel */
981 cent
= ieee80211_find_channel_byieee(ic
, i
,
982 flags
& ~IEEE80211_CHAN_HT
);
985 printf("%s: skip channel %d, could not find center channel\n",
986 device_get_nameunit(sc
->dev
), i
);
990 /* find the extension channel */
992 ext
= ieee80211_find_channel(ic
, cent
->ic_freq
+ 20,
993 flags
& ~IEEE80211_CHAN_HT
);
996 printf("%s: skip channel %d, could not find extension channel\n",
997 device_get_nameunit(sc
->dev
), i
);
1001 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1004 c
->ic_extieee
= ext
->ic_ieee
;
1005 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1006 c
->ic_flags
|= IEEE80211_CHAN_HT40U
;
1008 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1011 c
->ic_extieee
= cent
->ic_ieee
;
1012 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1013 c
->ic_flags
|= IEEE80211_CHAN_HT40D
;
1016 /* set supported channels for 5GHz band */
1018 if (sc
->rf_rev
== RT2860_EEPROM_RF_2850
||
1019 sc
->rf_rev
== RT2860_EEPROM_RF_2750
)
1021 for (i
= 36; i
<= 64; i
+= 4)
1023 flags
= IEEE80211_CHAN_A
| IEEE80211_CHAN_HT40
;
1025 /* find the center channel */
1027 cent
= ieee80211_find_channel_byieee(ic
, i
,
1028 flags
& ~IEEE80211_CHAN_HT
);
1031 printf("%s: skip channel %d, could not find center channel\n",
1032 device_get_nameunit(sc
->dev
), i
);
1036 /* find the extension channel */
1038 ext
= ieee80211_find_channel(ic
, cent
->ic_freq
+ 20,
1039 flags
& ~IEEE80211_CHAN_HT
);
1042 printf("%s: skip channel %d, could not find extension channel\n",
1043 device_get_nameunit(sc
->dev
), i
);
1047 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1050 c
->ic_extieee
= ext
->ic_ieee
;
1051 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1052 c
->ic_flags
|= IEEE80211_CHAN_HT40U
;
1054 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1057 c
->ic_extieee
= cent
->ic_ieee
;
1058 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1059 c
->ic_flags
|= IEEE80211_CHAN_HT40D
;
1062 for (i
= 100; i
<= 140; i
+= 4)
1064 flags
= IEEE80211_CHAN_A
| IEEE80211_CHAN_HT40
;
1066 /* find the center channel */
1068 cent
= ieee80211_find_channel_byieee(ic
, i
,
1069 flags
& ~IEEE80211_CHAN_HT
);
1072 printf("%s: skip channel %d, could not find center channel\n",
1073 device_get_nameunit(sc
->dev
), i
);
1077 /* find the extension channel */
1079 ext
= ieee80211_find_channel(ic
, cent
->ic_freq
+ 20,
1080 flags
& ~IEEE80211_CHAN_HT
);
1083 printf("%s: skip channel %d, could not find extension channel\n",
1084 device_get_nameunit(sc
->dev
), i
);
1088 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1091 c
->ic_extieee
= ext
->ic_ieee
;
1092 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1093 c
->ic_flags
|= IEEE80211_CHAN_HT40U
;
1095 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1098 c
->ic_extieee
= cent
->ic_ieee
;
1099 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1100 c
->ic_flags
|= IEEE80211_CHAN_HT40D
;
1103 for (i
= 149; i
<= 165; i
+= 4)
1105 flags
= IEEE80211_CHAN_A
| IEEE80211_CHAN_HT40
;
1107 /* find the center channel */
1109 cent
= ieee80211_find_channel_byieee(ic
, i
,
1110 flags
& ~IEEE80211_CHAN_HT
);
1113 printf("%s: skip channel %d, could not find center channel\n",
1114 device_get_nameunit(sc
->dev
), i
);
1118 /* find the extension channel */
1120 ext
= ieee80211_find_channel(ic
, cent
->ic_freq
+ 20,
1121 flags
& ~IEEE80211_CHAN_HT
);
1124 printf("%s: skip channel %d, could not find extension channel\n",
1125 device_get_nameunit(sc
->dev
), i
);
1129 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1132 c
->ic_extieee
= ext
->ic_ieee
;
1133 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1134 c
->ic_flags
|= IEEE80211_CHAN_HT40U
;
1136 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1139 c
->ic_extieee
= cent
->ic_ieee
;
1140 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1141 c
->ic_flags
|= IEEE80211_CHAN_HT40D
;
1147 * rt2860_init_locked
1149 static void rt2860_init_locked(void *priv
)
1151 struct rt2860_softc
*sc
;
1152 struct ieee80211com
*ic
;
1154 int error
, i
, ntries
;
1155 uint32_t tmp
, stacnt
[6];
1161 RT2860_DPRINTF(sc
, RT2860_DEBUG_ANY
,
1162 "%s: initializing\n",
1163 device_get_nameunit(sc
->dev
));
1165 RT2860_SOFTC_ASSERT_LOCKED(sc
);
1167 if (!(sc
->flags
& RT2860_SOFTC_FLAGS_UCODE_LOADED
))
1169 RT2860_DPRINTF(sc
, RT2860_DEBUG_ANY
,
1170 "%s: loading 8051 microcode\n",
1171 device_get_nameunit(sc
->dev
));
1173 error
= rt2860_io_mcu_load_ucode(sc
, rt2860_ucode
, sizeof(rt2860_ucode
));
1176 printf("%s: could not load 8051 microcode\n",
1177 device_get_nameunit(sc
->dev
));
1181 RT2860_DPRINTF(sc
, RT2860_DEBUG_ANY
,
1182 "%s: 8051 microcode was successfully loaded\n",
1183 device_get_nameunit(sc
->dev
));
1185 sc
->flags
|= RT2860_SOFTC_FLAGS_UCODE_LOADED
;
1188 rt2860_io_mac_write(sc
, RT2860_REG_PWR_PIN_CFG
, 0x2);
1190 /* disable DMA engine */
1192 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
);
1195 tmp
|= RT2860_REG_TX_WB_DDONE
;
1197 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
, tmp
);
1199 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WPDMA_RST_IDX
, 0xffffffff);
1201 /* PBF hardware reset */
1203 rt2860_io_mac_write(sc
, RT2860_REG_PBF_SYS_CTRL
, 0xe1f);
1204 rt2860_io_mac_write(sc
, RT2860_REG_PBF_SYS_CTRL
, 0xe00);
1206 /* wait while DMA engine is busy */
1208 for (ntries
= 0; ntries
< 100; ntries
++)
1210 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
);
1211 if (!(tmp
& (RT2860_REG_TX_DMA_BUSY
| RT2860_REG_RX_DMA_BUSY
)))
1219 printf("%s: timeout waiting for DMA engine\n",
1220 device_get_nameunit(sc
->dev
));
1225 tmp
|= RT2860_REG_TX_WB_DDONE
;
1227 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
, tmp
);
1229 /* reset Rx and Tx rings */
1231 tmp
= RT2860_REG_RST_IDX_RX
|
1232 RT2860_REG_RST_IDX_TX_MGMT
|
1233 RT2860_REG_RST_IDX_TX_HCCA
|
1234 RT2860_REG_RST_IDX_TX_AC3
|
1235 RT2860_REG_RST_IDX_TX_AC2
|
1236 RT2860_REG_RST_IDX_TX_AC1
|
1237 RT2860_REG_RST_IDX_TX_AC0
;
1239 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WPDMA_RST_IDX
, tmp
);
1241 /* PBF hardware reset */
1243 rt2860_io_mac_write(sc
, RT2860_REG_PBF_SYS_CTRL
, 0xe1f);
1244 rt2860_io_mac_write(sc
, RT2860_REG_PBF_SYS_CTRL
, 0xe00);
1246 rt2860_io_mac_write(sc
, RT2860_REG_PWR_PIN_CFG
, 0x3);
1248 rt2860_io_mac_write(sc
, RT2860_REG_SYS_CTRL
,
1249 RT2860_REG_MAC_SRST
| RT2860_REG_BBP_HRST
);
1250 rt2860_io_mac_write(sc
, RT2860_REG_SYS_CTRL
, 0);
1252 /* init Tx power per rate */
1254 for (i
= 0; i
< RT2860_SOFTC_TXPOW_RATE_COUNT
; i
++)
1256 if (sc
->txpow_rate_20mhz
[i
] == 0xffffffff)
1259 rt2860_io_mac_write(sc
, RT2860_REG_TX_PWR_CFG(i
),
1260 sc
->txpow_rate_20mhz
[i
]);
1263 for (i
= 0; i
< RT2860_DEF_MAC_SIZE
; i
++)
1264 rt2860_io_mac_write(sc
, rt2860_def_mac
[i
].reg
,
1265 rt2860_def_mac
[i
].val
);
1267 /* wait while MAC is busy */
1269 for (ntries
= 0; ntries
< 100; ntries
++)
1271 if (!(rt2860_io_mac_read(sc
, RT2860_REG_STATUS_CFG
) &
1272 (RT2860_REG_STATUS_TX_BUSY
| RT2860_REG_STATUS_RX_BUSY
)))
1280 printf("%s: timeout waiting for MAC\n",
1281 device_get_nameunit(sc
->dev
));
1285 /* clear Host to MCU mailbox */
1287 rt2860_io_mac_write(sc
, RT2860_REG_H2M_MAILBOX_BBP_AGENT
, 0);
1288 rt2860_io_mac_write(sc
, RT2860_REG_H2M_MAILBOX
, 0);
1290 rt2860_io_mcu_cmd(sc
, RT2860_IO_MCU_CMD_BOOT
,
1291 RT2860_REG_H2M_TOKEN_NO_INTR
, 0);
1295 error
= rt2860_init_bbp(sc
);
1299 /* set up maximum buffer sizes */
1301 tmp
= (1 << 12) | RT2860_MAX_AGG_SIZE
;
1303 rt2860_io_mac_write(sc
, RT2860_REG_MAX_LEN_CFG
, tmp
);
1305 /* set mac address */
1307 IEEE80211_ADDR_COPY(ic
->ic_myaddr
, IF_LLADDR(ifp
));
1309 rt2860_asic_set_macaddr(sc
, ic
->ic_myaddr
);
1311 /* clear statistic registers */
1313 rt2860_io_mac_read_multi(sc
, RT2860_REG_RX_STA_CNT0
,
1314 stacnt
, sizeof(stacnt
));
1316 /* set RTS threshold */
1318 rt2860_asic_update_rtsthreshold(sc
);
1322 rt2860_asic_update_txpower(sc
);
1324 /* set up protection mode */
1326 sc
->tx_ampdu_sessions
= 0;
1328 rt2860_asic_updateprot(sc
);
1330 /* clear beacon frame space (entries = 8, entry size = 512) */
1332 rt2860_io_mac_set_region_4(sc
, RT2860_REG_BEACON_BASE(0), 0, 1024);
1334 taskqueue_unblock(sc
->taskqueue
);
1336 /* init Tx rings (4 EDCAs + HCCA + MGMT) */
1338 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
1339 rt2860_reset_tx_ring(sc
, &sc
->tx_ring
[i
]);
1341 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
1343 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_BASE_PTR(i
),
1344 sc
->tx_ring
[i
].desc_phys_addr
);
1345 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_MAX_CNT(i
),
1346 RT2860_SOFTC_TX_RING_DESC_COUNT
);
1347 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_CTX_IDX(i
), 0);
1352 rt2860_reset_rx_ring(sc
, &sc
->rx_ring
);
1354 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_BASE_PTR
,
1355 sc
->rx_ring
.desc_phys_addr
);
1356 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_MAX_CNT
,
1357 RT2860_SOFTC_RX_RING_DATA_COUNT
);
1358 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_CALC_IDX
,
1359 RT2860_SOFTC_RX_RING_DATA_COUNT
- 1);
1361 /* wait while DMA engine is busy */
1363 for (ntries
= 0; ntries
< 100; ntries
++)
1365 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
);
1366 if (!(tmp
& (RT2860_REG_TX_DMA_BUSY
| RT2860_REG_RX_DMA_BUSY
)))
1374 printf("%s: timeout waiting for DMA engine\n",
1375 device_get_nameunit(sc
->dev
));
1380 tmp
|= RT2860_REG_TX_WB_DDONE
;
1382 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
, tmp
);
1384 /* disable interrupts mitigation */
1386 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_DELAY_INT_CFG
, 0);
1388 /* send LEDs operating mode to microcontroller */
1390 rt2860_io_mcu_cmd(sc
, RT2860_IO_MCU_CMD_LED1
,
1391 RT2860_REG_H2M_TOKEN_NO_INTR
, sc
->led_off
[0]);
1392 rt2860_io_mcu_cmd(sc
, RT2860_IO_MCU_CMD_LED2
,
1393 RT2860_REG_H2M_TOKEN_NO_INTR
, sc
->led_off
[1]);
1394 rt2860_io_mcu_cmd(sc
, RT2860_IO_MCU_CMD_LED3
,
1395 RT2860_REG_H2M_TOKEN_NO_INTR
, sc
->led_off
[2]);
1397 /* turn radio LED on */
1399 rt2860_led_cmd(sc
, RT2860_LED_CMD_RADIO_ON
);
1401 /* write vendor-specific BBP values (from EEPROM) */
1403 for (i
= 0; i
< RT2860_SOFTC_BBP_EEPROM_COUNT
; i
++)
1405 if (sc
->bbp_eeprom
[i
].reg
== 0x00 ||
1406 sc
->bbp_eeprom
[i
].reg
== 0xff)
1409 rt2860_io_bbp_write(sc
, sc
->bbp_eeprom
[i
].reg
,
1410 sc
->bbp_eeprom
[i
].val
);
1414 tmp = rt2860_io_mac_read(sc, RT2860_REG_SCHDMA_GPIO_CTRL_CFG);
1417 rt2860_io_mcu_cmd(sc, RT2860_IO_MCU_CMD_SLEEP,
1418 RT2860_REG_H2M_TOKEN_RADIOOFF, 0x02ff);
1419 rt2860_io_mcu_cmd_check(sc, RT2860_REG_H2M_TOKEN_RADIOOFF);
1421 rt2860_io_mcu_cmd(sc, RT2860_IO_MCU_CMD_WAKEUP,
1422 RT2860_REG_H2M_TOKEN_WAKEUP, 0);
1423 rt2860_io_mcu_cmd_check(sc, RT2860_REG_H2M_TOKEN_WAKEUP);
1427 /* disable non-existing Rx chains */
1429 tmp
= rt2860_io_bbp_read(sc
, 3);
1431 tmp
&= ~((1 << 4) | (1 << 3));
1433 if (sc
->nrxpath
== 3)
1435 else if (sc
->nrxpath
== 2)
1438 rt2860_io_bbp_write(sc
, 3, tmp
);
1440 /* disable non-existing Tx chains */
1442 tmp
= rt2860_io_bbp_read(sc
, 1);
1444 tmp
&= ~((1 << 4) | (1 << 3));
1446 if (sc
->ntxpath
== 2)
1449 rt2860_io_bbp_write(sc
, 1, tmp
);
1451 /* set current channel */
1453 rt2860_rf_set_chan(sc
, ic
->ic_curchan
);
1455 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WMM_TXOP0_CFG
, 0);
1456 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WMM_TXOP1_CFG
,
1459 if ((sc
->mac_rev
& 0xffff) != 0x0101)
1460 rt2860_io_mac_write(sc
, RT2860_REG_TX_TXOP_CTRL_CFG
, 0x583f);
1462 /* clear pending interrupts */
1464 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_INT_STATUS
, 0xffffffff);
1466 /* enable interrupts */
1468 tmp
= RT2860_REG_INT_TX_COHERENT
|
1469 RT2860_REG_INT_RX_COHERENT
|
1470 RT2860_REG_INT_GP_TIMER
|
1471 RT2860_REG_INT_AUTO_WAKEUP
|
1472 RT2860_REG_INT_FIFO_STA_FULL
|
1474 RT2860_REG_INT_PRE_TBTT |
1475 RT2860_REG_INT_TBTT |
1477 RT2860_REG_INT_TXRX_COHERENT
|
1478 RT2860_REG_INT_MCU_CMD
|
1479 RT2860_REG_INT_TX_MGMT_DONE
|
1480 RT2860_REG_INT_TX_HCCA_DONE
|
1481 RT2860_REG_INT_TX_AC3_DONE
|
1482 RT2860_REG_INT_TX_AC2_DONE
|
1483 RT2860_REG_INT_TX_AC1_DONE
|
1484 RT2860_REG_INT_TX_AC0_DONE
|
1485 RT2860_REG_INT_RX_DONE
;
1487 sc
->intr_enable_mask
= tmp
;
1489 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_INT_MASK
, tmp
);
1491 if (rt2860_txrx_enable(sc
) != 0)
1494 /* clear garbage interrupts */
1496 tmp
= rt2860_io_mac_read(sc
, 0x1300);
1498 ifp
->if_drv_flags
&= ~IFF_DRV_OACTIVE
;
1499 ifp
->if_drv_flags
|= IFF_DRV_RUNNING
;
1501 if (ic
->ic_opmode
!= IEEE80211_M_MONITOR
)
1503 if (ic
->ic_roaming
!= IEEE80211_ROAMING_MANUAL
)
1504 ieee80211_new_state(ic
, IEEE80211_S_SCAN
, -1);
1508 ieee80211_new_state(ic
, IEEE80211_S_RUN
, -1);
1511 sc
->periodic_round
= 0;
1513 callout_reset(&sc
->periodic_ch
, hz
/ 10, rt2860_periodic
, sc
);
1519 rt2860_stop_locked(sc
);
1525 static void rt2860_init(void *priv
)
1527 struct rt2860_softc
*sc
;
1531 RT2860_SOFTC_LOCK(sc
);
1533 rt2860_init_locked(sc
);
1535 RT2860_SOFTC_UNLOCK(sc
);
1541 static int rt2860_init_bbp(struct rt2860_softc
*sc
)
1546 for (ntries
= 0; ntries
< 20; ntries
++)
1548 tmp
= rt2860_io_bbp_read(sc
, 0);
1549 if (tmp
!= 0x00 && tmp
!= 0xff)
1553 if (tmp
== 0x00 || tmp
== 0xff)
1555 printf("%s: timeout waiting for BBP to wakeup\n",
1556 device_get_nameunit(sc
->dev
));
1560 for (i
= 0; i
< RT2860_DEF_BBP_SIZE
; i
++)
1561 rt2860_io_bbp_write(sc
, rt2860_def_bbp
[i
].reg
,
1562 rt2860_def_bbp
[i
].val
);
1564 if ((sc
->mac_rev
& 0xffff) != 0x0101)
1565 rt2860_io_bbp_write(sc
, 84, 0x19);
1571 * rt2860_stop_locked
1573 static void rt2860_stop_locked(void *priv
)
1575 struct rt2860_softc
*sc
;
1576 struct ieee80211com
*ic
;
1584 RT2860_DPRINTF(sc
, RT2860_DEBUG_ANY
,
1586 device_get_nameunit(sc
->dev
));
1588 RT2860_SOFTC_ASSERT_LOCKED(sc
);
1592 if (ifp
->if_drv_flags
& IFF_DRV_RUNNING
)
1593 rt2860_led_cmd(sc
, RT2860_LED_CMD_RADIO_OFF
);
1595 ifp
->if_drv_flags
&= ~(IFF_DRV_RUNNING
| IFF_DRV_OACTIVE
);
1597 ieee80211_new_state(ic
, IEEE80211_S_INIT
, -1);
1599 callout_stop(&sc
->periodic_ch
);
1600 callout_stop(&sc
->tx_watchdog_ch
);
1602 RT2860_SOFTC_UNLOCK(sc
);
1604 taskqueue_block(sc
->taskqueue
);
1606 taskqueue_drain(sc
->taskqueue
, &sc
->rx_done_task
);
1607 taskqueue_drain(sc
->taskqueue
, &sc
->tx_done_task
);
1608 taskqueue_drain(sc
->taskqueue
, &sc
->fifo_sta_full_task
);
1609 taskqueue_drain(sc
->taskqueue
, &sc
->periodic_task
);
1611 RT2860_SOFTC_LOCK(sc
);
1613 /* clear key tables */
1615 rt2860_asic_clear_keytables(sc
);
1617 /* disable interrupts */
1619 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_INT_MASK
, 0);
1623 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_SYS_CTRL
);
1625 tmp
&= ~(RT2860_REG_RX_ENABLE
| RT2860_REG_TX_ENABLE
);
1627 rt2860_io_mac_write(sc
, RT2860_REG_SYS_CTRL
, tmp
);
1631 rt2860_io_mac_write(sc
, RT2860_REG_SYS_CTRL
,
1632 RT2860_REG_MAC_SRST
| RT2860_REG_BBP_HRST
);
1633 rt2860_io_mac_write(sc
, RT2860_REG_SYS_CTRL
, 0);
1635 if (sc
->beacon_mbuf
!= NULL
)
1637 m_free(sc
->beacon_mbuf
);
1638 sc
->beacon_mbuf
= NULL
;
1645 static void rt2860_stop(void *priv
)
1647 struct rt2860_softc
*sc
;
1651 RT2860_SOFTC_LOCK(sc
);
1653 rt2860_stop_locked(sc
);
1655 RT2860_SOFTC_UNLOCK(sc
);
1661 static void rt2860_start(struct ifnet
*ifp
)
1663 struct rt2860_softc
*sc
;
1664 struct ieee80211com
*ic
;
1665 struct ieee80211_node
*ni
;
1666 struct ether_header
*eh
;
1673 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
1678 IF_POLL(&ic
->ic_mgtq
, m
);
1681 RT2860_SOFTC_TX_RING_LOCK(&sc
->tx_ring
[sc
->tx_ring_mgtqid
]);
1683 if (sc
->tx_ring
[sc
->tx_ring_mgtqid
].data_queued
>= RT2860_SOFTC_TX_RING_DATA_COUNT
)
1685 RT2860_SOFTC_TX_RING_UNLOCK(&sc
->tx_ring
[sc
->tx_ring_mgtqid
]);
1687 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
1688 "%s: if_start: Tx ring with qid=%d is full\n",
1689 device_get_nameunit(sc
->dev
), sc
->tx_ring_mgtqid
);
1691 ifp
->if_drv_flags
|= IFF_DRV_OACTIVE
;
1693 sc
->tx_data_queue_full
[sc
->tx_ring_mgtqid
]++;
1698 IF_DEQUEUE(&ic
->ic_mgtq
, m
);
1701 RT2860_SOFTC_TX_RING_UNLOCK(&sc
->tx_ring
[sc
->tx_ring_mgtqid
]);
1705 ni
= (struct ieee80211_node
*) m
->m_pkthdr
.rcvif
;
1707 m
->m_pkthdr
.rcvif
= NULL
;
1709 if (bpf_peers_present(ic
->ic_rawbpf
))
1710 bpf_mtap(ic
->ic_rawbpf
, m
);
1712 if (rt2860_tx_frame(sc
, m
, ni
, sc
->tx_ring_mgtqid
) != 0)
1714 RT2860_SOFTC_TX_RING_UNLOCK(&sc
->tx_ring
[sc
->tx_ring_mgtqid
]);
1718 RT2860_SOFTC_TX_RING_UNLOCK(&sc
->tx_ring
[sc
->tx_ring_mgtqid
]);
1720 rt2860_drain_fifo_stats(sc
);
1724 if (ic
->ic_state
!= IEEE80211_S_RUN
)
1727 IFQ_DRV_DEQUEUE(&ifp
->if_snd
, m
);
1731 if (ic
->ic_flags
& IEEE80211_F_SCAN
)
1732 ieee80211_cancel_scan(ic
);
1734 if (m
->m_len
< sizeof(struct ether_header
) &&
1735 !(m
= m_pullup(m
, sizeof (struct ether_header
))))
1738 eh
= mtod(m
, struct ether_header
*);
1740 ni
= ieee80211_find_txnode(ic
, eh
->ether_dhost
);
1743 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
1744 "%s: if_start: could not find Tx node\n",
1745 device_get_nameunit(sc
->dev
));
1752 ieee80211_classify(ic
, m
, ni
);
1754 qid
= M_WME_GETAC(m
);
1756 RT2860_SOFTC_TX_RING_LOCK(&sc
->tx_ring
[qid
]);
1758 if (sc
->tx_ring
[qid
].data_queued
>= RT2860_SOFTC_TX_RING_DATA_COUNT
)
1760 RT2860_SOFTC_TX_RING_UNLOCK(&sc
->tx_ring
[qid
]);
1762 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
1763 "%s: if_start: Tx ring with qid=%d is full\n",
1764 device_get_nameunit(sc
->dev
), qid
);
1767 ieee80211_free_node(ni
);
1769 ifp
->if_drv_flags
|= IFF_DRV_OACTIVE
;
1772 sc
->tx_data_queue_full
[qid
]++;
1779 m
= ieee80211_encap(ic
, m
, ni
);
1782 RT2860_SOFTC_TX_RING_UNLOCK(&sc
->tx_ring
[qid
]);
1784 ieee80211_free_node(ni
);
1791 if (bpf_peers_present(ic
->ic_rawbpf
))
1792 bpf_mtap(ic
->ic_rawbpf
, m
);
1794 if (rt2860_tx_frame(sc
, m
, ni
, qid
) != 0)
1796 RT2860_SOFTC_TX_RING_UNLOCK(&sc
->tx_ring
[qid
]);
1798 ieee80211_free_node(ni
);
1805 RT2860_SOFTC_TX_RING_UNLOCK(&sc
->tx_ring
[qid
]);
1807 rt2860_drain_fifo_stats(sc
);
1810 sc
->tx_timer
= RT2860_TX_WATCHDOG_TIMEOUT
;
1812 ic
->ic_lastdata
= ticks
;
1814 callout_reset(&sc
->tx_watchdog_ch
, hz
, rt2860_tx_watchdog
, sc
);
1821 static int rt2860_ioctl(struct ifnet
*ifp
, u_long cmd
, caddr_t data
)
1823 struct rt2860_softc
*sc
;
1824 struct ieee80211com
*ic
;
1835 RT2860_SOFTC_LOCK(sc
);
1837 if (ifp
->if_flags
& IFF_UP
)
1839 if (ifp
->if_drv_flags
& IFF_DRV_RUNNING
)
1841 if ((ifp
->if_flags
^ sc
->if_flags
) & IFF_PROMISC
)
1842 rt2860_asic_update_promisc(sc
);
1846 rt2860_init_locked(sc
);
1851 if (ifp
->if_drv_flags
& IFF_DRV_RUNNING
)
1852 rt2860_stop_locked(sc
);
1855 sc
->if_flags
= ifp
->if_flags
;
1857 RT2860_SOFTC_UNLOCK(sc
);
1861 error
= ieee80211_ioctl(ic
, cmd
, data
);
1864 if (error
== ENETRESET
)
1866 RT2860_SOFTC_LOCK(sc
);
1868 if ((ifp
->if_flags
& IFF_UP
) &&
1869 (ifp
->if_drv_flags
& IFF_DRV_RUNNING
) &&
1870 (ic
->ic_roaming
!= IEEE80211_ROAMING_MANUAL
))
1872 rt2860_stop_locked(sc
);
1873 rt2860_init_locked(sc
);
1876 RT2860_SOFTC_UNLOCK(sc
);
1887 static int rt2860_reset(struct ifnet
*ifp
)
1889 struct rt2860_softc
*sc
;
1890 struct ieee80211com
*ic
;
1895 if (ic
->ic_opmode
!= IEEE80211_M_MONITOR
)
1898 rt2860_rf_set_chan(sc
, ic
->ic_curchan
);
1906 static int rt2860_newstate(struct ieee80211com
*ic
,
1907 enum ieee80211_state nstate
, int arg
)
1909 struct rt2860_softc
*sc
;
1911 struct ieee80211_node
*ni
;
1917 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATE
,
1918 "%s: newstate: %s -> %s\n",
1919 device_get_nameunit(sc
->dev
),
1920 ieee80211_state_name
[ic
->ic_state
], ieee80211_state_name
[nstate
]);
1922 error
= sc
->newstate(ic
, nstate
, arg
);
1926 RT2860_SOFTC_LOCK(sc
);
1928 /* turn link LED off */
1930 if (nstate
!= IEEE80211_S_RUN
)
1931 rt2860_led_cmd(sc
, RT2860_LED_CMD_RADIO_OFF
);
1935 case IEEE80211_S_INIT
:
1936 rt2860_asic_disable_tsf_sync(sc
);
1939 case IEEE80211_S_RUN
:
1942 if (ic
->ic_opmode
!= IEEE80211_M_MONITOR
)
1943 rt2860_rf_set_chan(sc
, ni
->ni_chan
);
1945 if (ic
->ic_opmode
!= IEEE80211_M_MONITOR
)
1947 rt2860_asic_enable_mrr(sc
);
1948 rt2860_asic_set_txpreamble(sc
);
1949 rt2860_asic_set_basicrates(sc
);
1950 rt2860_asic_update_txpower(sc
);
1951 rt2860_asic_set_bssid(sc
, ni
->ni_bssid
);
1954 if (ic
->ic_opmode
== IEEE80211_M_STA
)
1955 rt2860_newassoc(ni
, 1);
1957 if (ic
->ic_opmode
== IEEE80211_M_HOSTAP
||
1958 ic
->ic_opmode
== IEEE80211_M_IBSS
)
1960 error
= rt2860_beacon_alloc(sc
);
1964 rt2860_asic_update_beacon(sc
);
1967 if (ic
->ic_opmode
!= IEEE80211_M_MONITOR
)
1968 rt2860_asic_enable_tsf_sync(sc
);
1970 /* turn link LED on */
1972 if (ic
->ic_opmode
!= IEEE80211_M_MONITOR
)
1974 rt2860_led_cmd(sc
, RT2860_LED_CMD_RADIO_ON
|
1975 (IEEE80211_IS_CHAN_2GHZ(ni
->ni_chan
) ?
1976 RT2860_LED_CMD_LINK_2GHZ
: RT2860_LED_CMD_LINK_5GHZ
));
1980 case IEEE80211_S_SLEEP
:
1987 RT2860_SOFTC_UNLOCK(sc
);
1995 static void rt2860_scan_start(struct ieee80211com
*ic
)
1997 struct rt2860_softc
*sc
;
2003 rt2860_asic_disable_tsf_sync(sc
);
2009 static void rt2860_scan_end(struct ieee80211com
*ic
)
2011 struct rt2860_softc
*sc
;
2017 rt2860_asic_enable_tsf_sync(sc
);
2021 * rt2860_set_channel
2023 static void rt2860_set_channel(struct ieee80211com
*ic
)
2025 struct rt2860_softc
*sc
;
2031 RT2860_DPRINTF(sc
, RT2860_DEBUG_CHAN
,
2032 "%s: set channel: channel=%u, HT%s%s\n",
2033 device_get_nameunit(sc
->dev
),
2034 ieee80211_chan2ieee(ic
, ic
->ic_curchan
),
2035 !IEEE80211_IS_CHAN_HT(ic
->ic_curchan
) ? " disabled" :
2036 IEEE80211_IS_CHAN_HT20(ic
->ic_curchan
) ? "20":
2037 IEEE80211_IS_CHAN_HT40U(ic
->ic_curchan
) ? "40U" : "40D",
2038 (ic
->ic_flags
& IEEE80211_F_SCAN
) ? ", scanning" : "");
2040 RT2860_SOFTC_LOCK(sc
);
2042 rt2860_rf_set_chan(sc
, ic
->ic_curchan
);
2044 RT2860_SOFTC_UNLOCK(sc
);
2050 static void rt2860_newassoc(struct ieee80211_node
*ni
, int isnew
)
2052 struct rt2860_softc
*sc
;
2053 struct ieee80211com
*ic
;
2055 struct rt2860_softc_node
*rni
;
2062 rni
= (struct rt2860_softc_node
*) ni
;
2066 aid
= IEEE80211_AID(ni
->ni_associd
);
2067 rni
->staid
= rt2860_staid_alloc(sc
, aid
);
2070 rt2860_io_mac_write_multi(sc
, RT2860_REG_WCID(wcid
),
2071 ni
->ni_macaddr
, IEEE80211_ADDR_LEN
);
2073 rt2860_amrr_node_init(&sc
->amrr
, &sc
->amrr_node
[wcid
], ni
);
2075 RT2860_DPRINTF(sc
, RT2860_DEBUG_RATE
,
2076 "%s: initial%s node Tx rate: associd=0x%04x, rate=0x%02x, max rate=0x%02x\n",
2077 device_get_nameunit(sc
->dev
),
2078 (ni
->ni_flags
& IEEE80211_NODE_HT
) ? " HT" : "",
2080 (ni
->ni_flags
& IEEE80211_NODE_HT
) ?
2081 (ni
->ni_htrates
.rs_rates
[ni
->ni_txrate
] | IEEE80211_RATE_MCS
) :
2082 (ni
->ni_rates
.rs_rates
[ni
->ni_txrate
] & IEEE80211_RATE_VAL
),
2083 (ni
->ni_flags
& IEEE80211_NODE_HT
) ?
2084 (ni
->ni_htrates
.rs_rates
[ni
->ni_htrates
.rs_nrates
- 1] | IEEE80211_RATE_MCS
) :
2085 (ni
->ni_rates
.rs_rates
[ni
->ni_rates
.rs_nrates
- 1] & IEEE80211_RATE_VAL
));
2087 rt2860_asic_updateprot(sc
);
2088 rt2860_asic_updateslot(sc
);
2089 rt2860_asic_set_txpreamble(sc
);
2092 RT2860_DPRINTF(sc
, RT2860_DEBUG_NODE
,
2093 "%s: new association: isnew=%d, macaddr=%s, associd=0x%04x, staid=0x%02x, QoS %s, ERP %s, HT %s\n",
2094 device_get_nameunit(sc
->dev
), isnew
, ether_sprintf(ni
->ni_macaddr
),
2095 ni
->ni_associd
, rni
->staid
,
2096 (ni
->ni_flags
& IEEE80211_NODE_QOS
) ? "enabled" : "disabled",
2097 (ni
->ni_flags
& IEEE80211_NODE_ERP
) ? "enabled" : "disabled",
2098 (ni
->ni_flags
& IEEE80211_NODE_HT
) ? "enabled" : "disabled");
2105 static void rt2860_updateslot(struct ifnet
*ifp
)
2107 struct rt2860_softc
*sc
;
2111 rt2860_asic_updateslot(sc
);
2117 static int rt2860_wme_update(struct ieee80211com
*ic
)
2119 struct rt2860_softc
*sc
;
2125 rt2860_asic_wme_update(sc
);
2131 * rt2860_update_beacon
2133 static void rt2860_update_beacon(struct ieee80211com
*ic
, int what
)
2135 struct rt2860_softc
*sc
;
2138 struct ieee80211_beacon_offsets
*bo
;
2142 m
= sc
->beacon_mbuf
;
2143 bo
= &sc
->beacon_offsets
;
2145 RT2860_DPRINTF(sc
, RT2860_DEBUG_BEACON
,
2146 "%s: update beacon: what=%d\n",
2147 device_get_nameunit(sc
->dev
), what
);
2149 setbit(bo
->bo_flags
, what
);
2151 ieee80211_beacon_update(ic
->ic_bss
, bo
, m
, 0);
2153 rt2860_asic_update_beacon(sc
);
2157 * rt2860_key_update_begin
2159 static void rt2860_key_update_begin(struct ieee80211com
*ic
)
2161 struct rt2860_softc
*sc
;
2167 RT2860_DPRINTF(sc
, RT2860_DEBUG_KEY
,
2168 "%s: key update begin\n",
2169 device_get_nameunit(sc
->dev
));
2171 taskqueue_block(sc
->taskqueue
);
2173 IF_LOCK(&ifp
->if_snd
);
2177 * rt2860_key_update_end
2179 static void rt2860_key_update_end(struct ieee80211com
*ic
)
2181 struct rt2860_softc
*sc
;
2187 RT2860_DPRINTF(sc
, RT2860_DEBUG_KEY
,
2188 "%s: key update end\n",
2189 device_get_nameunit(sc
->dev
));
2191 IF_UNLOCK(&ifp
->if_snd
);
2193 taskqueue_unblock(sc
->taskqueue
);
2199 static int rt2860_key_set(struct ieee80211com
*ic
,
2200 const struct ieee80211_key
*k
, const uint8_t mac
[IEEE80211_ADDR_LEN
])
2202 struct rt2860_softc
*sc
;
2204 struct ieee80211_node
*ni
;
2205 struct rt2860_softc_node
*rni
;
2206 uint16_t key_base
, keymode_base
;
2207 uint8_t mode
, vapid
, wcid
, iv
[8];
2210 if (k
->wk_cipher
->ic_cipher
!= IEEE80211_CIPHER_WEP
&&
2211 k
->wk_cipher
->ic_cipher
!= IEEE80211_CIPHER_TKIP
&&
2212 k
->wk_cipher
->ic_cipher
!= IEEE80211_CIPHER_AES_CCM
)
2218 switch (k
->wk_cipher
->ic_cipher
)
2220 case IEEE80211_CIPHER_WEP
:
2221 if(k
->wk_keylen
< 8)
2222 mode
= RT2860_REG_CIPHER_MODE_WEP40
;
2224 mode
= RT2860_REG_CIPHER_MODE_WEP104
;
2227 case IEEE80211_CIPHER_TKIP
:
2228 mode
= RT2860_REG_CIPHER_MODE_TKIP
;
2231 case IEEE80211_CIPHER_AES_CCM
:
2232 mode
= RT2860_REG_CIPHER_MODE_AES_CCMP
;
2239 RT2860_DPRINTF(sc
, RT2860_DEBUG_KEY
,
2240 "%s: set key: keyix=%d, keylen=%d, macaddr=%s, mode=%d, group=%d\n",
2241 device_get_nameunit(sc
->dev
), k
->wk_keyix
, k
->wk_keylen
, ether_sprintf(mac
),
2242 mode
, (k
->wk_flags
& IEEE80211_KEY_GROUP
) ? 1 : 0);
2244 if (!(k
->wk_flags
& IEEE80211_KEY_GROUP
))
2246 /* install pairwise key */
2248 ni
= ieee80211_find_node(&ic
->ic_sta
, mac
);
2249 rni
= (struct rt2860_softc_node
*) ni
;
2253 key_base
= RT2860_REG_PKEY(wcid
);
2255 ieee80211_free_node(ni
);
2257 if (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_WEP
)
2261 iv
[3] = (k
->wk_keyix
<< 6);
2265 if (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_TKIP
)
2267 iv
[0] = (k
->wk_keytsc
>> 8);
2268 iv
[1] = ((iv
[0] | 0x20) & 0x7f);
2269 iv
[2] = k
->wk_keytsc
;
2275 iv
[0] = k
->wk_keytsc
;
2276 iv
[1] = k
->wk_keytsc
>> 8;
2280 iv
[3] = ((k
->wk_keyix
<< 6) | IEEE80211_WEP_EXTIV
);
2281 iv
[4] = (k
->wk_keytsc
>> 16);
2282 iv
[5] = (k
->wk_keytsc
>> 24);
2283 iv
[6] = (k
->wk_keytsc
>> 32);
2284 iv
[7] = (k
->wk_keytsc
>> 40);
2286 RT2860_DPRINTF(sc
, RT2860_DEBUG_KEY
,
2287 "%s: set key: iv=%02x %02x %02x %02x %02x %02x %02x %02x\n",
2288 device_get_nameunit(sc
->dev
),
2289 iv
[0], iv
[1], iv
[2], iv
[3], iv
[4], iv
[5], iv
[6], iv
[7]);
2292 rt2860_io_mac_write_multi(sc
, RT2860_REG_IVEIV(wcid
), iv
, 8);
2294 if (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_TKIP
)
2296 rt2860_io_mac_write_multi(sc
, key_base
, k
->wk_key
, 16);
2298 if (ic
->ic_opmode
!= IEEE80211_M_HOSTAP
)
2300 rt2860_io_mac_write_multi(sc
, key_base
+ 16, &k
->wk_key
[16], 8);
2301 rt2860_io_mac_write_multi(sc
, key_base
+ 24, &k
->wk_key
[24], 8);
2305 rt2860_io_mac_write_multi(sc
, key_base
+ 16, &k
->wk_key
[24], 8);
2306 rt2860_io_mac_write_multi(sc
, key_base
+ 24, &k
->wk_key
[16], 8);
2311 rt2860_io_mac_write_multi(sc
, key_base
, k
->wk_key
, k
->wk_keylen
);
2314 tmp
= ((vapid
& RT2860_REG_VAP_MASK
) << RT2860_REG_VAP_SHIFT
) |
2315 (mode
<< RT2860_REG_CIPHER_MODE_SHIFT
) | RT2860_REG_PKEY_ENABLE
;
2317 rt2860_io_mac_write(sc
, RT2860_REG_WCID_ATTR(wcid
), tmp
);
2320 if ((k
->wk_flags
& IEEE80211_KEY_GROUP
) ||
2321 (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_WEP
))
2323 /* install group key */
2326 wcid
= RT2860_WCID_MCAST
;
2327 key_base
= RT2860_REG_SKEY(vapid
, k
->wk_keyix
);
2328 keymode_base
= RT2860_REG_SKEY_MODE(vapid
);
2330 if (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_TKIP
)
2332 rt2860_io_mac_write_multi(sc
, key_base
, k
->wk_key
, 16);
2334 if (ic
->ic_opmode
!= IEEE80211_M_HOSTAP
)
2336 rt2860_io_mac_write_multi(sc
, key_base
+ 16, &k
->wk_key
[16], 8);
2337 rt2860_io_mac_write_multi(sc
, key_base
+ 24, &k
->wk_key
[24], 8);
2341 rt2860_io_mac_write_multi(sc
, key_base
+ 16, &k
->wk_key
[24], 8);
2342 rt2860_io_mac_write_multi(sc
, key_base
+ 24, &k
->wk_key
[16], 8);
2347 rt2860_io_mac_write_multi(sc
, key_base
, k
->wk_key
, k
->wk_keylen
);
2350 tmp
= rt2860_io_mac_read(sc
, keymode_base
);
2352 tmp
&= ~(0xf << (k
->wk_keyix
* 4 + 16 * (vapid
% 2)));
2353 tmp
|= (mode
<< (k
->wk_keyix
* 4 + 16 * (vapid
% 2)));
2355 rt2860_io_mac_write(sc
, keymode_base
, tmp
);
2357 if (ic
->ic_opmode
== IEEE80211_M_HOSTAP
)
2359 if (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_WEP
)
2363 iv
[3] = (k
->wk_keyix
<< 6);
2367 if (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_TKIP
)
2369 iv
[0] = (k
->wk_keytsc
>> 8);
2370 iv
[1] = ((iv
[0] | 0x20) & 0x7f);
2371 iv
[2] = k
->wk_keytsc
;
2377 iv
[0] = k
->wk_keytsc
;
2378 iv
[1] = k
->wk_keytsc
>> 8;
2382 iv
[3] = ((k
->wk_keyix
<< 6) | IEEE80211_WEP_EXTIV
);
2383 iv
[4] = (k
->wk_keytsc
>> 16);
2384 iv
[5] = (k
->wk_keytsc
>> 24);
2385 iv
[6] = (k
->wk_keytsc
>> 32);
2386 iv
[7] = (k
->wk_keytsc
>> 40);
2388 RT2860_DPRINTF(sc
, RT2860_DEBUG_KEY
,
2389 "%s: set key: iv=%02x %02x %02x %02x %02x %02x %02x %02x\n",
2390 device_get_nameunit(sc
->dev
),
2391 iv
[0], iv
[1], iv
[2], iv
[3], iv
[4], iv
[5], iv
[6], iv
[7]);
2394 rt2860_io_mac_write_multi(sc
, RT2860_REG_IVEIV(wcid
), iv
, 8);
2396 tmp
= ((vapid
& RT2860_REG_VAP_MASK
) << RT2860_REG_VAP_SHIFT
) |
2397 (mode
<< RT2860_REG_CIPHER_MODE_SHIFT
);
2399 rt2860_io_mac_write(sc
, RT2860_REG_WCID_ATTR(wcid
), tmp
);
2409 static int rt2860_key_delete(struct ieee80211com
*ic
,
2410 const struct ieee80211_key
*k
)
2412 struct rt2860_softc
*sc
;
2413 uint8_t vapid
, wcid
;
2416 sc
= ic
->ic_ifp
->if_softc
;
2418 RT2860_DPRINTF(sc
, RT2860_DEBUG_KEY
,
2419 "%s: delete key: keyix=%d, keylen=%d, group=%d\n",
2420 device_get_nameunit(sc
->dev
), k
->wk_keyix
, k
->wk_keylen
,
2421 (k
->wk_flags
& IEEE80211_KEY_GROUP
) ? 1 : 0);
2423 if (k
->wk_flags
& IEEE80211_KEY_GROUP
)
2425 /* remove group key */
2428 wcid
= RT2860_WCID_MCAST
;
2430 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_SKEY_MODE(vapid
));
2432 tmp
&= ~(0xf << (k
->wk_keyix
* 4 + 16 * (vapid
% 2)));
2433 tmp
|= (RT2860_REG_CIPHER_MODE_NONE
<< (k
->wk_keyix
* 4 + 16 * (vapid
% 2)));
2435 rt2860_io_mac_write(sc
, RT2860_REG_SKEY_MODE(vapid
), tmp
);
2437 if (ic
->ic_opmode
== IEEE80211_M_HOSTAP
)
2439 tmp
= ((vapid
& RT2860_REG_VAP_MASK
) << RT2860_REG_VAP_SHIFT
) |
2440 (RT2860_REG_CIPHER_MODE_NONE
<< RT2860_REG_CIPHER_MODE_SHIFT
) | RT2860_REG_PKEY_ENABLE
;
2442 rt2860_io_mac_write(sc
, RT2860_REG_WCID_ATTR(wcid
), tmp
);
2452 static int rt2860_raw_xmit(struct ieee80211_node
*ni
, struct mbuf
*m
,
2453 const struct ieee80211_bpf_params
*params
)
2459 * rt2860_media_change
2461 static int rt2860_media_change(struct ifnet
*ifp
)
2463 struct rt2860_softc
*sc
;
2468 error
= ieee80211_media_change(ifp
);
2469 if (error
!= ENETRESET
)
2472 RT2860_SOFTC_LOCK(sc
);
2474 if ((ifp
->if_flags
& IFF_UP
) && (ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
2476 rt2860_stop_locked(sc
);
2477 rt2860_init_locked(sc
);
2480 RT2860_SOFTC_UNLOCK(sc
);
2488 static struct ieee80211_node
*rt2860_node_alloc(struct ieee80211_node_table
*nt
)
2490 return malloc(sizeof(struct rt2860_softc_node
),
2491 M_80211_NODE
, M_NOWAIT
| M_ZERO
);
2495 * rt2860_node_cleanup
2497 static void rt2860_node_cleanup(struct ieee80211_node
*ni
)
2499 struct rt2860_softc
*sc
;
2500 struct ieee80211com
*ic
;
2502 struct rt2860_softc_node
*rni
;
2503 uint8_t vapid
, wcid
;
2509 rni
= (struct rt2860_softc_node
*) ni
;
2511 RT2860_DPRINTF(sc
, RT2860_DEBUG_NODE
,
2512 "%s: node cleanup: macaddr=%s, associd=0x%04x, staid=0x%02x\n",
2513 device_get_nameunit(sc
->dev
), ether_sprintf(ni
->ni_macaddr
),
2514 ni
->ni_associd
, rni
->staid
);
2516 if (rni
->staid
!= 0)
2521 tmp
= ((vapid
& RT2860_REG_VAP_MASK
) << RT2860_REG_VAP_SHIFT
) |
2522 (RT2860_REG_CIPHER_MODE_NONE
<< RT2860_REG_CIPHER_MODE_SHIFT
) | RT2860_REG_PKEY_ENABLE
;
2524 rt2860_io_mac_write(sc
, RT2860_REG_WCID_ATTR(wcid
), tmp
);
2526 rt2860_io_mac_write(sc
, RT2860_REG_WCID(wcid
), 0xffffffff);
2527 rt2860_io_mac_write(sc
, RT2860_REG_WCID(wcid
) + 4, 0x0000ffff);
2529 rt2860_staid_delete(sc
, rni
->staid
);
2534 sc
->node_cleanup(ni
);
2538 * rt2860_recv_action
2540 static void rt2860_recv_action(struct ieee80211_node
*ni
,
2541 const uint8_t *frm
, const uint8_t *efrm
)
2543 struct rt2860_softc
*sc
;
2544 struct ieee80211com
*ic
;
2546 struct rt2860_softc_node
*rni
;
2547 const struct ieee80211_action
*ia
;
2548 struct ieee80211_tx_ampdu
*tx_ampdu
;
2549 uint16_t status
, baparamset
;
2551 int tid
, bufsize
, ac
;
2557 rni
= (struct rt2860_softc_node
*) ni
;
2559 ia
= (const struct ieee80211_action
*) frm
;
2561 sc
->recv_action(ni
, frm
, efrm
);
2563 if (ia
->ia_category
!= IEEE80211_ACTION_CAT_BA
)
2566 switch (ia
->ia_action
)
2568 /* IEEE80211_ACTION_BA_ADDBA_RESPONSE */
2569 case IEEE80211_ACTION_BA_ADDBA_RESPONSE
:
2570 status
= LE_READ_2(frm
+ 3);
2571 baparamset
= LE_READ_2(frm
+ 4);
2572 tid
= RT2860_MS(baparamset
, IEEE80211_BAPS_TID
);
2573 bufsize
= RT2860_MS(baparamset
, IEEE80211_BAPS_BUFSIZ
);
2574 ac
= TID_TO_WME_AC(tid
);
2575 tx_ampdu
= &ni
->ni_tx_ampdu
[ac
];
2577 RT2860_DPRINTF(sc
, RT2860_DEBUG_BA
,
2578 "%s: received ADDBA response: associd=0x%04x, staid=0x%02x, status=%d, tid=%d, bufsize=%d\n",
2579 device_get_nameunit(sc
->dev
), ni
->ni_associd
, rni
->staid
, status
, tid
, bufsize
);
2581 if (sc
->mac_rev
>= 0x28720200)
2583 if (tx_ampdu
->txa_wnd
> 13)
2584 tx_ampdu
->txa_wnd
= 13;
2588 if (tx_ampdu
->txa_wnd
> 7)
2589 tx_ampdu
->txa_wnd
= 7;
2592 if (status
== IEEE80211_STATUS_SUCCESS
)
2594 sc
->tx_ampdu_sessions
++;
2596 rt2860_asic_updateprot(sc
);
2600 /* IEEE80211_ACTION_BA_DELBA */
2601 case IEEE80211_ACTION_BA_DELBA
:
2602 baparamset
= LE_READ_2(frm
+ 2);
2603 tid
= RT2860_MS(baparamset
, IEEE80211_BAPS_TID
);
2606 RT2860_DPRINTF(sc
, RT2860_DEBUG_BA
,
2607 "%s: received DELBA request: associd=0x%04x, staid=0x%02x, tid=%d\n",
2608 device_get_nameunit(sc
->dev
), ni
->ni_associd
, rni
->staid
, tid
);
2610 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_WCID(wcid
) + 4);
2612 tmp
&= ~(0x10000 << tid
);
2614 rt2860_io_mac_write(sc
, RT2860_REG_WCID(wcid
) + 4, tmp
);
2620 * rt2860_send_action
2622 static int rt2860_send_action(struct ieee80211_node
*ni
,
2623 int category
, int action
, uint16_t args
[4])
2625 struct rt2860_softc
*sc
;
2626 struct ieee80211com
*ic
;
2628 struct rt2860_softc_node
*rni
;
2629 uint16_t status
, baparamset
;
2631 int ret
, tid
, bufsize
;
2637 rni
= (struct rt2860_softc_node
*) ni
;
2639 ret
= sc
->send_action(ni
, category
, action
, args
);
2641 if (category
!= IEEE80211_ACTION_CAT_BA
)
2648 /* IEEE80211_ACTION_BA_ADDBA_RESPONSE */
2649 case IEEE80211_ACTION_BA_ADDBA_RESPONSE
:
2651 baparamset
= args
[2];
2652 tid
= RT2860_MS(baparamset
, IEEE80211_BAPS_TID
);
2653 bufsize
= RT2860_MS(baparamset
, IEEE80211_BAPS_BUFSIZ
);
2655 RT2860_DPRINTF(sc
, RT2860_DEBUG_BA
,
2656 "%s: sending ADDBA response: associd=0x%04x, staid=0x%02x, status=%d, tid=%d, bufsize=%d\n",
2657 device_get_nameunit(sc
->dev
), ni
->ni_associd
, rni
->staid
, status
, tid
, bufsize
);
2659 if (status
== IEEE80211_STATUS_SUCCESS
)
2661 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_WCID(wcid
) + 4);
2663 tmp
|= (0x10000 << tid
);
2665 rt2860_io_mac_write(sc
, RT2860_REG_WCID(wcid
) + 4, tmp
);
2669 /* IEEE80211_ACTION_BA_DELBA */
2670 case IEEE80211_ACTION_BA_DELBA
:
2671 baparamset
= RT2860_SM(args
[0], IEEE80211_DELBAPS_TID
) | args
[1];
2673 tid
= RT2860_MS(baparamset
, IEEE80211_DELBAPS_TID
);
2675 RT2860_DPRINTF(sc
, RT2860_DEBUG_BA
,
2676 "%s: sending DELBA request: associd=0x%04x, staid=0x%02x, tid=%d\n",
2677 device_get_nameunit(sc
->dev
), ni
->ni_associd
, rni
->staid
, tid
);
2679 if (RT2860_MS(baparamset
, IEEE80211_DELBAPS_INIT
) != IEEE80211_DELBAPS_INIT
)
2681 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_WCID(wcid
) + 4);
2683 tmp
&= ~(0x10000 << tid
);
2685 rt2860_io_mac_write(sc
, RT2860_REG_WCID(wcid
) + 4, tmp
);
2689 sc
->tx_ampdu_sessions
--;
2691 rt2860_asic_updateprot(sc
);
2700 * rt2860_amrr_update_iter_func
2702 static void rt2860_amrr_update_iter_func(void *arg
, struct ieee80211_node
*ni
)
2704 struct rt2860_softc
*sc
;
2705 struct ieee80211com
*ic
;
2706 struct rt2860_softc_node
*rni
;
2711 rni
= (struct rt2860_softc_node
*) ni
;
2713 /* only associated stations */
2715 if (rni
->staid
!= 0)
2719 RT2860_DPRINTF(sc
, RT2860_DEBUG_RATE
,
2720 "%s: AMRR node: staid=0x%02x, txcnt=%d, success=%d, retrycnt=%d\n",
2721 device_get_nameunit(sc
->dev
),
2722 rni
->staid
, sc
->amrr_node
[wcid
].txcnt
, sc
->amrr_node
[wcid
].success
, sc
->amrr_node
[wcid
].retrycnt
);
2724 rt2860_amrr_choose(ni
, &sc
->amrr_node
[wcid
]);
2726 RT2860_DPRINTF(sc
, RT2860_DEBUG_RATE
,
2727 "%s:%s node Tx rate: associd=0x%04x, staid=0x%02x, rate=0x%02x, max rate=0x%02x\n",
2728 device_get_nameunit(sc
->dev
),
2729 (ni
->ni_flags
& IEEE80211_NODE_HT
) ? " HT" : "",
2730 ni
->ni_associd
, rni
->staid
,
2731 (ni
->ni_flags
& IEEE80211_NODE_HT
) ?
2732 (ni
->ni_htrates
.rs_rates
[ni
->ni_txrate
] | IEEE80211_RATE_MCS
) :
2733 (ni
->ni_rates
.rs_rates
[ni
->ni_txrate
] & IEEE80211_RATE_VAL
),
2734 (ni
->ni_flags
& IEEE80211_NODE_HT
) ?
2735 (ni
->ni_htrates
.rs_rates
[ni
->ni_htrates
.rs_nrates
- 1] | IEEE80211_RATE_MCS
) :
2736 (ni
->ni_rates
.rs_rates
[ni
->ni_rates
.rs_nrates
- 1] & IEEE80211_RATE_VAL
));
2743 static void rt2860_periodic(void *arg
)
2745 struct rt2860_softc
*sc
;
2749 RT2860_DPRINTF(sc
, RT2860_DEBUG_PERIODIC
,
2751 device_get_nameunit(sc
->dev
));
2753 taskqueue_enqueue(sc
->taskqueue
, &sc
->periodic_task
);
2757 * rt2860_tx_watchdog
2759 static void rt2860_tx_watchdog(void *arg
)
2761 struct rt2860_softc
*sc
;
2767 if (sc
->tx_timer
== 0)
2770 if (--sc
->tx_timer
== 0)
2772 printf("%s: Tx watchdog timeout: resetting\n",
2773 device_get_nameunit(sc
->dev
));
2775 rt2860_stop_locked(sc
);
2776 rt2860_init_locked(sc
);
2780 sc
->tx_watchdog_timeouts
++;
2783 callout_reset(&sc
->tx_watchdog_ch
, hz
, rt2860_tx_watchdog
, sc
);
2787 * rt2860_staid_alloc
2789 static int rt2860_staid_alloc(struct rt2860_softc
*sc
, int aid
)
2793 if ((aid
> 0 && aid
< RT2860_SOFTC_STAID_COUNT
) && isclr(sc
->staid_mask
, aid
))
2799 for (staid
= 1; staid
< RT2860_SOFTC_STAID_COUNT
; staid
++)
2801 if (isclr(sc
->staid_mask
, staid
))
2806 setbit(sc
->staid_mask
, staid
);
2812 * rt2860_staid_delete
2814 static void rt2860_staid_delete(struct rt2860_softc
*sc
, int staid
)
2816 clrbit(sc
->staid_mask
, staid
);
2820 * rt2860_asic_set_bssid
2822 static void rt2860_asic_set_bssid(struct rt2860_softc
*sc
,
2823 const uint8_t *bssid
)
2827 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATE
,
2828 "%s: set bssid: bssid=%s\n",
2829 device_get_nameunit(sc
->dev
), ether_sprintf(bssid
));
2831 tmp
= bssid
[0] | (bssid
[1]) << 8 | (bssid
[2] << 16) | (bssid
[3] << 24);
2833 rt2860_io_mac_write(sc
, RT2860_REG_BSSID_DW0
, tmp
);
2835 tmp
= bssid
[4] | (bssid
[5] << 8);
2837 rt2860_io_mac_write(sc
, RT2860_REG_BSSID_DW1
, tmp
);
2841 * rt2860_asic_set_macaddr
2843 static void rt2860_asic_set_macaddr(struct rt2860_softc
*sc
,
2844 const uint8_t *addr
)
2848 tmp
= addr
[0] | (addr
[1] << 8) | (addr
[2] << 16) | (addr
[3] << 24);
2850 rt2860_io_mac_write(sc
, RT2860_REG_ADDR_DW0
, tmp
);
2852 tmp
= addr
[4] | (addr
[5] << 8);
2854 rt2860_io_mac_write(sc
, RT2860_REG_ADDR_DW1
, tmp
);
2858 * rt2860_asic_enable_tsf_sync
2860 static void rt2860_asic_enable_tsf_sync(struct rt2860_softc
*sc
)
2862 struct ieee80211com
*ic
;
2867 RT2860_DPRINTF(sc
, RT2860_DEBUG_BEACON
,
2868 "%s: enabling TSF\n",
2869 device_get_nameunit(sc
->dev
));
2871 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_BCN_TIME_CFG
);
2874 tmp
|= ic
->ic_bss
->ni_intval
* 16;
2875 tmp
|= (RT2860_REG_TSF_TIMER_ENABLE
| RT2860_REG_TBTT_TIMER_ENABLE
);
2877 if (ic
->ic_opmode
== IEEE80211_M_STA
)
2879 tmp
|= (RT2860_REG_TSF_SYNC_MODE_STA
<< RT2860_REG_TSF_SYNC_MODE_SHIFT
);
2881 else if (ic
->ic_opmode
== IEEE80211_M_IBSS
)
2883 tmp
|= RT2860_REG_BCN_TX_ENABLE
;
2884 tmp
|= (RT2860_REG_TSF_SYNC_MODE_IBSS
<< RT2860_REG_TSF_SYNC_MODE_SHIFT
);
2886 else if (ic
->ic_opmode
== IEEE80211_M_HOSTAP
)
2888 tmp
|= RT2860_REG_BCN_TX_ENABLE
;
2889 tmp
|= (RT2860_REG_TSF_SYNC_MODE_HOSTAP
<< RT2860_REG_TSF_SYNC_MODE_SHIFT
);
2892 rt2860_io_mac_write(sc
, RT2860_REG_BCN_TIME_CFG
, tmp
);
2896 * rt2860_asic_disable_tsf_sync
2898 static void rt2860_asic_disable_tsf_sync(struct rt2860_softc
*sc
)
2902 RT2860_DPRINTF(sc
, RT2860_DEBUG_BEACON
,
2903 "%s: disabling TSF\n",
2904 device_get_nameunit(sc
->dev
));
2906 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_BCN_TIME_CFG
);
2908 tmp
&= ~(RT2860_REG_BCN_TX_ENABLE
|
2909 RT2860_REG_TSF_TIMER_ENABLE
|
2910 RT2860_REG_TBTT_TIMER_ENABLE
);
2912 tmp
&= ~(RT2860_REG_TSF_SYNC_MODE_MASK
<< RT2860_REG_TSF_SYNC_MODE_SHIFT
);
2913 tmp
|= (RT2860_REG_TSF_SYNC_MODE_DISABLE
<< RT2860_REG_TSF_SYNC_MODE_SHIFT
);
2915 rt2860_io_mac_write(sc
, RT2860_REG_BCN_TIME_CFG
, tmp
);
2919 * rt2860_asic_enable_mrr
2921 static void rt2860_asic_enable_mrr(struct rt2860_softc
*sc
)
2923 #define CCK(mcs) (mcs)
2924 #define OFDM(mcs) ((1 << 3) | (mcs))
2925 #define HT(mcs) (mcs)
2927 rt2860_io_mac_write(sc
, RT2860_REG_TX_LG_FBK_CFG0
,
2928 (OFDM(6) << 28) | /* 54 -> 48 */
2929 (OFDM(5) << 24) | /* 48 -> 36 */
2930 (OFDM(4) << 20) | /* 36 -> 24 */
2931 (OFDM(3) << 16) | /* 24 -> 18 */
2932 (OFDM(2) << 12) | /* 18 -> 12 */
2933 (OFDM(1) << 8) | /* 12 -> 9 */
2934 (OFDM(0) << 4) | /* 9 -> 6 */
2935 OFDM(0)); /* 6 -> 6 */
2937 rt2860_io_mac_write(sc
, RT2860_REG_TX_LG_FBK_CFG1
,
2938 (CCK(2) << 12) | /* 11 -> 5.5 */
2939 (CCK(1) << 8) | /* 5.5 -> 2 */
2940 (CCK(0) << 4) | /* 2 -> 1 */
2941 CCK(0)); /* 1 -> 1 */
2943 rt2860_io_mac_write(sc
, RT2860_REG_TX_HT_FBK_CFG0
,
2953 rt2860_io_mac_write(sc
, RT2860_REG_TX_HT_FBK_CFG1
,
2969 * rt2860_asic_set_txpreamble
2971 static void rt2860_asic_set_txpreamble(struct rt2860_softc
*sc
)
2973 struct ieee80211com
*ic
;
2978 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATE
,
2979 "%s: %s short Tx preamble\n",
2980 device_get_nameunit(sc
->dev
),
2981 (ic
->ic_flags
& IEEE80211_F_SHPREAMBLE
) ? "enabling" : "disabling");
2983 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_AUTO_RSP_CFG
);
2985 tmp
&= ~RT2860_REG_CCK_SHORT_ENABLE
;
2987 if (sc
->ic
.ic_flags
& IEEE80211_F_SHPREAMBLE
)
2988 tmp
|= RT2860_REG_CCK_SHORT_ENABLE
;
2990 rt2860_io_mac_write(sc
, RT2860_REG_AUTO_RSP_CFG
, tmp
);
2994 * rt2860_asic_set_basicrates
2996 static void rt2860_asic_set_basicrates(struct rt2860_softc
*sc
)
2998 struct ieee80211com
*ic
;
3002 if (ic
->ic_curmode
== IEEE80211_MODE_11B
)
3003 rt2860_io_mac_write(sc
, RT2860_REG_LEGACY_BASIC_RATE
, 0x3);
3004 else if (ic
->ic_curmode
== IEEE80211_MODE_11A
)
3005 rt2860_io_mac_write(sc
, RT2860_REG_LEGACY_BASIC_RATE
, 0x150);
3007 rt2860_io_mac_write(sc
, RT2860_REG_LEGACY_BASIC_RATE
, 0x15f);
3011 * rt2860_asic_update_rtsthreshold
3013 static void rt2860_asic_update_rtsthreshold(struct rt2860_softc
*sc
)
3015 struct ieee80211com
*ic
;
3021 RT2860_DPRINTF(sc
, RT2860_DEBUG_PROT
,
3022 "%s: updating RTS threshold: %d\n",
3023 device_get_nameunit(sc
->dev
), ic
->ic_rtsthreshold
);
3025 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_RTS_CFG
);
3027 tmp
&= ~(RT2860_REG_TX_RTS_THRESHOLD_MASK
<< RT2860_REG_TX_RTS_THRESHOLD_SHIFT
);
3029 if (ic
->ic_flags_ext
& IEEE80211_FEXT_AMSDU_TX
)
3032 threshold
= ic
->ic_rtsthreshold
;
3035 tmp
|= ((threshold
& RT2860_REG_TX_RTS_THRESHOLD_MASK
) <<
3036 RT2860_REG_TX_RTS_THRESHOLD_SHIFT
);
3038 rt2860_io_mac_write(sc
, RT2860_REG_TX_RTS_CFG
, tmp
);
3042 * rt2860_asic_update_txpower
3044 static void rt2860_asic_update_txpower(struct rt2860_softc
*sc
)
3046 struct ieee80211com
*ic
;
3047 uint32_t *txpow_rate
;
3055 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATE
,
3056 "%s: updating Tx power: %d\n",
3057 device_get_nameunit(sc
->dev
), ic
->ic_txpowlimit
);
3059 if (!IEEE80211_IS_CHAN_HT40(ic
->ic_curchan
))
3061 txpow_rate
= sc
->txpow_rate_20mhz
;
3065 if (IEEE80211_IS_CHAN_2GHZ(ic
->ic_curchan
))
3066 txpow_rate
= sc
->txpow_rate_40mhz_2ghz
;
3068 txpow_rate
= sc
->txpow_rate_40mhz_5ghz
;
3073 val
= rt2860_io_bbp_read(sc
, 1);
3076 if (ic
->ic_txpowlimit
> 90)
3080 else if (ic
->ic_txpowlimit
> 60)
3084 else if (ic
->ic_txpowlimit
> 30)
3088 else if (ic
->ic_txpowlimit
> 15)
3092 else if (ic
->ic_txpowlimit
> 9)
3102 rt2860_io_bbp_write(sc
, 1, val
);
3104 for (i
= 0; i
< RT2860_SOFTC_TXPOW_RATE_COUNT
; i
++)
3106 if (txpow_rate
[i
] == 0xffffffff)
3109 tmp
= rt2860_read_eeprom_txpow_rate_add_delta(txpow_rate
[i
], delta
);
3111 rt2860_io_mac_write(sc
, RT2860_REG_TX_PWR_CFG(i
), tmp
);
3116 * rt2860_asic_update_promisc
3118 static void rt2860_asic_update_promisc(struct rt2860_softc
*sc
)
3123 ifp
= sc
->ic
.ic_ifp
;
3125 printf("%s: %s promiscuous mode\n",
3126 device_get_nameunit(sc
->dev
),
3127 (ifp
->if_flags
& IFF_PROMISC
) ? "entering" : "leaving");
3129 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_RX_FILTER_CFG
);
3131 tmp
&= ~RT2860_REG_RX_FILTER_DROP_UC_NOME
;
3133 if (!(ifp
->if_flags
& IFF_PROMISC
))
3134 tmp
|= RT2860_REG_RX_FILTER_DROP_UC_NOME
;
3136 rt2860_io_mac_write(sc
, RT2860_REG_RX_FILTER_CFG
, tmp
);
3140 * rt2860_asic_updateprot
3142 static void rt2860_asic_updateprot(struct rt2860_softc
*sc
)
3144 struct ieee80211com
*ic
;
3145 uint32_t cck_prot
, ofdm_prot
, mm20_prot
, mm40_prot
, gf20_prot
, gf40_prot
;
3147 enum ieee80211_protmode htprotmode
;
3151 /* CCK frame protection */
3153 cck_prot
= RT2860_REG_RTSTH_ENABLE
| RT2860_REG_PROT_NAV_SHORT
|
3154 RT2860_REG_TXOP_ALLOW_ALL
| RT2860_REG_PROT_CTRL_NONE
;
3156 /* set up protection frame phy mode and rate (MCS code) */
3158 if (ic
->ic_curmode
== IEEE80211_MODE_11A
)
3159 cck_prot
|= (RT2860_REG_PROT_PHYMODE_OFDM
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3160 (0 << RT2860_REG_PROT_MCS_SHIFT
);
3162 cck_prot
|= ((RT2860_REG_PROT_PHYMODE_CCK
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3163 (3 << RT2860_REG_PROT_MCS_SHIFT
));
3165 rt2860_io_mac_write(sc
, RT2860_REG_TX_CCK_PROT_CFG
, cck_prot
);
3167 /* OFDM frame protection */
3169 ofdm_prot
= RT2860_REG_RTSTH_ENABLE
| RT2860_REG_PROT_NAV_SHORT
|
3170 RT2860_REG_TXOP_ALLOW_ALL
;
3172 if (ic
->ic_flags
& IEEE80211_F_USEPROT
)
3174 RT2860_DPRINTF(sc
, RT2860_DEBUG_PROT
,
3175 "%s: updating protection mode: b/g protection mode=%s\n",
3176 device_get_nameunit(sc
->dev
),
3177 (ic
->ic_protmode
== IEEE80211_PROT_RTSCTS
) ? "RTS/CTS" :
3178 ((ic
->ic_protmode
== IEEE80211_PROT_CTSONLY
) ? "CTS-to-self" : "none"));
3180 if (ic
->ic_protmode
== IEEE80211_PROT_RTSCTS
)
3181 ofdm_prot
|= RT2860_REG_PROT_CTRL_RTS_CTS
;
3182 else if (ic
->ic_protmode
== IEEE80211_PROT_CTSONLY
)
3183 ofdm_prot
|= RT2860_REG_PROT_CTRL_CTS
;
3185 ofdm_prot
|= RT2860_REG_PROT_CTRL_NONE
;
3189 RT2860_DPRINTF(sc
, RT2860_DEBUG_PROT
,
3190 "%s: updating protection mode: b/g protection mode=%s\n",
3191 device_get_nameunit(sc
->dev
), "none");
3193 ofdm_prot
|= RT2860_REG_PROT_CTRL_NONE
;
3196 rt2860_io_mac_write(sc
, RT2860_REG_TX_OFDM_PROT_CFG
, ofdm_prot
);
3198 /* HT frame protection */
3200 if ((ic
->ic_opmode
== IEEE80211_M_STA
) && (ic
->ic_state
== IEEE80211_S_RUN
))
3201 htopmode
= ic
->ic_bss
->ni_htopmode
;
3203 htopmode
= ic
->ic_curhtprotmode
;
3205 htprotmode
= ic
->ic_htprotmode
;
3207 /* force HT mixed mode and RTS/CTS protection if A-MPDU Tx aggregation is enabled */
3209 if (sc
->tx_ampdu_sessions
> 0)
3211 RT2860_DPRINTF(sc
, RT2860_DEBUG_PROT
,
3212 "%s: updating protection mode: forcing HT mixed mode and RTS/CTS protection\n",
3213 device_get_nameunit(sc
->dev
));
3215 htopmode
= IEEE80211_HTINFO_OPMODE_MIXED
;
3216 htprotmode
= IEEE80211_PROT_RTSCTS
;
3219 RT2860_DPRINTF(sc
, RT2860_DEBUG_PROT
,
3220 "%s: updating protection mode: HT operation mode=0x%02x, protection mode=%s\n",
3221 device_get_nameunit(sc
->dev
),
3222 htopmode
& IEEE80211_HTINFO_OPMODE
,
3223 (htprotmode
== IEEE80211_PROT_RTSCTS
) ? "RTS/CTS" :
3224 ((htprotmode
== IEEE80211_PROT_CTSONLY
) ? "CTS-to-self" : "none"));
3226 switch (htopmode
& IEEE80211_HTINFO_OPMODE
)
3228 /* IEEE80211_HTINFO_OPMODE_HT20PR */
3229 case IEEE80211_HTINFO_OPMODE_HT20PR
:
3230 mm20_prot
= RT2860_REG_PROT_NAV_SHORT
| RT2860_REG_PROT_CTRL_NONE
|
3231 RT2860_REG_TXOP_ALLOW_CCK
| RT2860_REG_TXOP_ALLOW_OFDM
|
3232 RT2860_REG_TXOP_ALLOW_MM20
| RT2860_REG_TXOP_ALLOW_GF20
|
3233 (RT2860_REG_PROT_PHYMODE_OFDM
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3234 (4 << RT2860_REG_PROT_MCS_SHIFT
);
3236 gf20_prot
= mm20_prot
;
3238 mm40_prot
= RT2860_REG_PROT_NAV_SHORT
| RT2860_REG_TXOP_ALLOW_ALL
|
3239 (RT2860_REG_PROT_PHYMODE_OFDM
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3240 (0x84 << RT2860_REG_PROT_MCS_SHIFT
);
3242 if (htprotmode
== IEEE80211_PROT_RTSCTS
)
3243 mm40_prot
|= RT2860_REG_PROT_CTRL_RTS_CTS
;
3244 else if (htprotmode
== IEEE80211_PROT_CTSONLY
)
3245 mm40_prot
|= RT2860_REG_PROT_CTRL_CTS
;
3247 mm40_prot
|= RT2860_REG_PROT_CTRL_NONE
;
3249 gf40_prot
= mm40_prot
;
3252 /* IEEE80211_HTINFO_OPMODE_MIXED */
3253 case IEEE80211_HTINFO_OPMODE_MIXED
:
3254 mm20_prot
= RT2860_REG_PROT_NAV_SHORT
|
3255 RT2860_REG_TXOP_ALLOW_CCK
| RT2860_REG_TXOP_ALLOW_OFDM
|
3256 RT2860_REG_TXOP_ALLOW_MM20
| RT2860_REG_TXOP_ALLOW_GF20
;
3258 if (ic
->ic_flags
& IEEE80211_F_USEPROT
)
3259 mm20_prot
|= (RT2860_REG_PROT_PHYMODE_CCK
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3260 (3 << RT2860_REG_PROT_MCS_SHIFT
);
3262 mm20_prot
|= (RT2860_REG_PROT_PHYMODE_OFDM
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3263 (4 << RT2860_REG_PROT_MCS_SHIFT
);
3265 if (htprotmode
== IEEE80211_PROT_RTSCTS
)
3266 mm20_prot
|= RT2860_REG_PROT_CTRL_RTS_CTS
;
3267 else if (htprotmode
== IEEE80211_PROT_CTSONLY
)
3268 mm20_prot
|= RT2860_REG_PROT_CTRL_CTS
;
3270 mm20_prot
|= RT2860_REG_PROT_CTRL_NONE
;
3272 gf20_prot
= mm20_prot
;
3274 mm40_prot
= RT2860_REG_PROT_NAV_SHORT
| RT2860_REG_TXOP_ALLOW_ALL
;
3276 if (ic
->ic_flags
& IEEE80211_F_USEPROT
)
3277 mm40_prot
|= (RT2860_REG_PROT_PHYMODE_CCK
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3278 (3 << RT2860_REG_PROT_MCS_SHIFT
);
3280 mm40_prot
|= (RT2860_REG_PROT_PHYMODE_OFDM
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3281 (0x84 << RT2860_REG_PROT_MCS_SHIFT
);
3283 if (htprotmode
== IEEE80211_PROT_RTSCTS
)
3284 mm40_prot
|= RT2860_REG_PROT_CTRL_RTS_CTS
;
3285 else if (htprotmode
== IEEE80211_PROT_CTSONLY
)
3286 mm40_prot
|= RT2860_REG_PROT_CTRL_CTS
;
3288 mm40_prot
|= RT2860_REG_PROT_CTRL_NONE
;
3290 gf40_prot
= mm40_prot
;
3294 * IEEE80211_HTINFO_OPMODE_PURE
3295 * IEEE80211_HTINFO_OPMODE_PROTOPT
3297 case IEEE80211_HTINFO_OPMODE_PURE
:
3298 case IEEE80211_HTINFO_OPMODE_PROTOPT
:
3300 mm20_prot
= RT2860_REG_PROT_NAV_SHORT
| RT2860_REG_PROT_CTRL_NONE
|
3301 RT2860_REG_TXOP_ALLOW_CCK
| RT2860_REG_TXOP_ALLOW_OFDM
|
3302 RT2860_REG_TXOP_ALLOW_MM20
| RT2860_REG_TXOP_ALLOW_GF20
|
3303 (RT2860_REG_PROT_PHYMODE_OFDM
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3304 (4 << RT2860_REG_PROT_MCS_SHIFT
);
3306 gf20_prot
= mm20_prot
;
3308 mm40_prot
= RT2860_REG_PROT_NAV_SHORT
| RT2860_REG_PROT_CTRL_NONE
|
3309 RT2860_REG_TXOP_ALLOW_ALL
|
3310 (RT2860_REG_PROT_PHYMODE_OFDM
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3311 (0x84 << RT2860_REG_PROT_MCS_SHIFT
);
3313 gf40_prot
= mm40_prot
;
3317 rt2860_io_mac_write(sc
, RT2860_REG_TX_MM20_PROT_CFG
, mm20_prot
);
3318 rt2860_io_mac_write(sc
, RT2860_REG_TX_MM40_PROT_CFG
, mm40_prot
);
3319 rt2860_io_mac_write(sc
, RT2860_REG_TX_GF20_PROT_CFG
, gf20_prot
);
3320 rt2860_io_mac_write(sc
, RT2860_REG_TX_GF40_PROT_CFG
, gf40_prot
);
3324 * rt2860_asic_updateslot
3326 static void rt2860_asic_updateslot(struct rt2860_softc
*sc
)
3328 struct ieee80211com
*ic
;
3333 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATE
,
3334 "%s: %s short slot time\n",
3335 device_get_nameunit(sc
->dev
),
3336 (ic
->ic_flags
& (IEEE80211_F_SHSLOT
| IEEE80211_F_BURST
)) ? "enabling" : "disabling");
3338 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_BKOFF_SLOT_CFG
);
3341 tmp
|= (ic
->ic_flags
& (IEEE80211_F_SHSLOT
|IEEE80211_F_BURST
)) ? 9 : 20;
3343 rt2860_io_mac_write(sc
, RT2860_REG_BKOFF_SLOT_CFG
, tmp
);
3347 * rt2860_asic_wme_update
3349 static void rt2860_asic_wme_update(struct rt2860_softc
*sc
)
3351 struct ieee80211com
*ic
;
3352 struct ieee80211_wme_state
*wme
;
3353 const struct wmeParams
*wmep
;
3358 wmep
= wme
->wme_chanParams
.cap_wmeParams
;
3360 RT2860_DPRINTF(sc
, RT2860_DEBUG_WME
,
3361 "%s: wme update: WME_AC_VO=%d/%d/%d/%d, WME_AC_VI=%d/%d/%d/%d, "
3362 "WME_AC_BK=%d/%d/%d/%d, WME_AC_BE=%d/%d/%d/%d\n",
3363 device_get_nameunit(sc
->dev
),
3364 wmep
[WME_AC_VO
].wmep_aifsn
,
3365 wmep
[WME_AC_VO
].wmep_logcwmin
, wmep
[WME_AC_VO
].wmep_logcwmax
,
3366 wmep
[WME_AC_VO
].wmep_txopLimit
,
3367 wmep
[WME_AC_VI
].wmep_aifsn
,
3368 wmep
[WME_AC_VI
].wmep_logcwmin
, wmep
[WME_AC_VI
].wmep_logcwmax
,
3369 wmep
[WME_AC_VI
].wmep_txopLimit
,
3370 wmep
[WME_AC_BK
].wmep_aifsn
,
3371 wmep
[WME_AC_BK
].wmep_logcwmin
, wmep
[WME_AC_BK
].wmep_logcwmax
,
3372 wmep
[WME_AC_BK
].wmep_txopLimit
,
3373 wmep
[WME_AC_BE
].wmep_aifsn
,
3374 wmep
[WME_AC_BE
].wmep_logcwmin
, wmep
[WME_AC_BE
].wmep_logcwmax
,
3375 wmep
[WME_AC_BE
].wmep_txopLimit
);
3377 for (i
= 0; i
< WME_NUM_AC
; i
++)
3378 rt2860_io_mac_write(sc
, RT2860_REG_TX_EDCA_AC_CFG(i
),
3379 (wmep
[i
].wmep_logcwmax
<< 16) | (wmep
[i
].wmep_logcwmin
<< 12) |
3380 (wmep
[i
].wmep_aifsn
<< 8) | wmep
[i
].wmep_txopLimit
);
3382 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WMM_AIFSN_CFG
,
3383 (wmep
[WME_AC_VO
].wmep_aifsn
<< 12) | (wmep
[WME_AC_VI
].wmep_aifsn
<< 8) |
3384 (wmep
[WME_AC_BK
].wmep_aifsn
<< 4) | wmep
[WME_AC_BE
].wmep_aifsn
);
3386 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WMM_CWMIN_CFG
,
3387 (wmep
[WME_AC_VO
].wmep_logcwmin
<< 12) | (wmep
[WME_AC_VI
].wmep_logcwmin
<< 8) |
3388 (wmep
[WME_AC_BK
].wmep_logcwmin
<< 4) | wmep
[WME_AC_BE
].wmep_logcwmin
);
3390 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WMM_CWMAX_CFG
,
3391 (wmep
[WME_AC_VO
].wmep_logcwmax
<< 12) | (wmep
[WME_AC_VI
].wmep_logcwmax
<< 8) |
3392 (wmep
[WME_AC_BK
].wmep_logcwmax
<< 4) | wmep
[WME_AC_BE
].wmep_logcwmax
);
3394 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WMM_TXOP0_CFG
,
3395 (wmep
[WME_AC_BK
].wmep_txopLimit
<< 16) | wmep
[WME_AC_BE
].wmep_txopLimit
);
3397 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WMM_TXOP1_CFG
,
3398 (wmep
[WME_AC_VO
].wmep_txopLimit
<< 16) | wmep
[WME_AC_VI
].wmep_txopLimit
);
3402 * rt2860_asic_update_beacon
3404 static void rt2860_asic_update_beacon(struct rt2860_softc
*sc
)
3406 struct ieee80211com
*ic
;
3408 struct rt2860_txwi
*txwi
;
3413 m
= sc
->beacon_mbuf
;
3414 txwi
= &sc
->beacon_txwi
;
3416 /* disable temporarily TSF sync */
3418 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_BCN_TIME_CFG
);
3420 tmp
&= ~(RT2860_REG_BCN_TX_ENABLE
|
3421 RT2860_REG_TSF_TIMER_ENABLE
|
3422 RT2860_REG_TBTT_TIMER_ENABLE
);
3424 rt2860_io_mac_write(sc
, RT2860_REG_BCN_TIME_CFG
, tmp
);
3426 /* write Tx wireless info and beacon frame to on-chip memory */
3428 rt2860_io_mac_write_multi(sc
, RT2860_REG_BEACON_BASE(0),
3429 txwi
, sizeof(struct rt2860_txwi
));
3431 rt2860_io_mac_write_multi(sc
, RT2860_REG_BEACON_BASE(0) + sizeof(struct rt2860_txwi
),
3432 mtod(m
, uint8_t *), m
->m_pkthdr
.len
);
3434 /* enable again TSF sync */
3436 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_BCN_TIME_CFG
);
3438 tmp
|= (RT2860_REG_BCN_TX_ENABLE
|
3439 RT2860_REG_TSF_TIMER_ENABLE
|
3440 RT2860_REG_TBTT_TIMER_ENABLE
);
3442 rt2860_io_mac_write(sc
, RT2860_REG_BCN_TIME_CFG
, tmp
);
3446 * rt2860_asic_clear_keytables
3448 static void rt2860_asic_clear_keytables(struct rt2860_softc
*sc
)
3452 /* clear Rx WCID search table (entries = 256, entry size = 8) */
3454 for (i
= 0; i
< 256; i
++)
3456 rt2860_io_mac_write(sc
, RT2860_REG_WCID(i
), 0xffffffff);
3457 rt2860_io_mac_write(sc
, RT2860_REG_WCID(i
) + 4, 0x0000ffff);
3460 /* clear WCID attribute table (entries = 256, entry size = 4) */
3462 rt2860_io_mac_set_region_4(sc
, RT2860_REG_WCID_ATTR(0), 0, 256);
3464 /* clear IV/EIV table (entries = 256, entry size = 8) */
3466 rt2860_io_mac_set_region_4(sc
, RT2860_REG_IVEIV(0), 0, 2 * 256);
3468 /* clear pairwise key table (entries = 64, entry size = 32) */
3470 rt2860_io_mac_set_region_4(sc
, RT2860_REG_PKEY(0), 0, 8 * 64);
3472 /* clear shared key table (entries = 32, entry size = 32) */
3474 rt2860_io_mac_set_region_4(sc
, RT2860_REG_SKEY(0, 0), 0, 8 * 32);
3476 /* clear shared key mode (entries = 32, entry size = 2) */
3478 rt2860_io_mac_set_region_4(sc
, RT2860_REG_SKEY_MODE(0), 0, 16);
3482 * rt2860_beacon_alloc
3484 static int rt2860_beacon_alloc(struct rt2860_softc
*sc
)
3486 struct ieee80211com
*ic
;
3488 struct rt2860_txwi txwi
;
3493 m
= ieee80211_beacon_alloc(ic
->ic_bss
, &sc
->beacon_offsets
);
3497 rate
= IEEE80211_IS_CHAN_5GHZ(ic
->ic_curchan
) ? 12 : 2;
3498 mcs
= rt2860_rate2mcs(rate
);
3500 RT2860_DPRINTF(sc
, RT2860_DEBUG_BEACON
,
3501 "%s: beacon allocate: mcs=0x%02x\n",
3502 device_get_nameunit(sc
->dev
), mcs
);
3504 memset(&txwi
, 0, sizeof(struct rt2860_txwi
));
3506 txwi
.wcid
= RT2860_WCID_RESERVED
;
3507 txwi
.pid_mpdu_len
= ((htole16(m
->m_pkthdr
.len
) & RT2860_TXWI_MPDU_LEN_MASK
) <<
3508 RT2860_TXWI_MPDU_LEN_SHIFT
);
3509 txwi
.txop
= (RT2860_TXWI_TXOP_HT
<< RT2860_TXWI_TXOP_SHIFT
);
3510 txwi
.mpdu_density_flags
|=
3511 (RT2860_TXWI_FLAGS_TS
<< RT2860_TXWI_FLAGS_SHIFT
);
3512 txwi
.bawin_size_xflags
|=
3513 (RT2860_TXWI_XFLAGS_NSEQ
<< RT2860_TXWI_XFLAGS_SHIFT
);
3517 txwi
.phymode_ifs_stbc_shortgi
=
3518 (RT2860_TXWI_PHYMODE_CCK
<< RT2860_TXWI_PHYMODE_SHIFT
);
3520 if (rate
!= 2 && (ic
->ic_flags
& IEEE80211_F_SHPREAMBLE
))
3521 mcs
|= RT2860_TXWI_MCS_SHOTPRE
;
3525 txwi
.phymode_ifs_stbc_shortgi
=
3526 (RT2860_TXWI_PHYMODE_OFDM
<< RT2860_TXWI_PHYMODE_SHIFT
);
3529 txwi
.bw_mcs
= (RT2860_TXWI_BW_20
<< RT2860_TXWI_BW_SHIFT
) |
3530 ((mcs
& RT2860_TXWI_MCS_MASK
) << RT2860_TXWI_MCS_SHIFT
);
3532 if (sc
->beacon_mbuf
!= NULL
)
3534 m_free(sc
->beacon_mbuf
);
3535 sc
->beacon_mbuf
= NULL
;
3538 sc
->beacon_mbuf
= m
;
3539 sc
->beacon_txwi
= txwi
;
3547 static uint8_t rt2860_rxrate(struct rt2860_rxwi
*rxwi
)
3549 uint8_t mcs
, phymode
;
3552 mcs
= (rxwi
->bw_mcs
>> RT2860_RXWI_MCS_SHIFT
) & RT2860_RXWI_MCS_MASK
;
3553 phymode
= (rxwi
->phymode_stbc_shortgi
>> RT2860_RXWI_PHYMODE_SHIFT
) &
3554 RT2860_RXWI_PHYMODE_MASK
;
3560 case RT2860_RXWI_PHYMODE_CCK
:
3561 switch (mcs
& ~RT2860_RXWI_MCS_SHOTPRE
)
3563 case 0: rate
= 2; break; /* 1 Mbps */
3564 case 1: rate
= 4; break; /* 2 MBps */
3565 case 2: rate
= 11; break; /* 5.5 Mbps */
3566 case 3: rate
= 22; break; /* 11 Mbps */
3570 case RT2860_RXWI_PHYMODE_OFDM
:
3573 case 0: rate
= 12; break; /* 6 Mbps */
3574 case 1: rate
= 18; break; /* 9 Mbps */
3575 case 2: rate
= 24; break; /* 12 Mbps */
3576 case 3: rate
= 36; break; /* 18 Mbps */
3577 case 4: rate
= 48; break; /* 24 Mbps */
3578 case 5: rate
= 72; break; /* 36 Mbps */
3579 case 6: rate
= 96; break; /* 48 Mbps */
3580 case 7: rate
= 108; break; /* 54 Mbps */
3584 case RT2860_RXWI_PHYMODE_HT_MIXED
:
3585 case RT2860_RXWI_PHYMODE_HT_GF
:
3593 * rt2860_maxrssi_rxpath
3595 static uint8_t rt2860_maxrssi_rxpath(struct rt2860_softc
*sc
,
3596 const struct rt2860_rxwi
*rxwi
)
3602 if (sc
->nrxpath
> 1)
3603 if (rxwi
->rssi
[1] > rxwi
->rssi
[rxpath
])
3606 if (sc
->nrxpath
> 2)
3607 if (rxwi
->rssi
[2] > rxwi
->rssi
[rxpath
])
3616 static int8_t rt2860_rssi2dbm(struct rt2860_softc
*sc
,
3617 uint8_t rssi
, uint8_t rxpath
)
3619 struct ieee80211com
*ic
;
3620 struct ieee80211_channel
*c
;
3622 int8_t rssi_off
, lna_gain
;
3629 chan
= ieee80211_chan2ieee(ic
, c
);
3631 if (IEEE80211_IS_CHAN_5GHZ(c
))
3633 rssi_off
= sc
->rssi_off_5ghz
[rxpath
];
3636 lna_gain
= sc
->lna_gain
[1];
3637 else if (chan
<= 128)
3638 lna_gain
= sc
->lna_gain
[2];
3640 lna_gain
= sc
->lna_gain
[3];
3644 rssi_off
= sc
->rssi_off_2ghz
[rxpath
];
3645 lna_gain
= sc
->lna_gain
[0];
3648 return (-12 - rssi_off
- lna_gain
- rssi
);
3654 static uint8_t rt2860_rate2mcs(uint8_t rate
)
3681 static int rt2860_ackrate(struct ieee80211com
*ic
, int rate
)
3693 return (ic
->ic_curmode
== IEEE80211_MODE_11B
) ? 4 : rate
;
3712 /* default to 1Mbps */
3719 static uint16_t rt2860_txtime(int len
, int rate
, uint32_t flags
)
3723 if (RT2860_RATE_IS_OFDM(rate
))
3725 txtime
= (8 + 4 * len
+ 3 + rate
- 1) / rate
;
3726 txtime
= 16 + 4 + 4 * txtime
+ 6;
3730 txtime
= (16 * len
+ rate
- 1) / rate
;
3732 if (rate
!= 2 && (flags
& IEEE80211_F_SHPREAMBLE
))
3744 static int rt2860_tx_frame(struct rt2860_softc
*sc
,
3745 struct mbuf
*m
, struct ieee80211_node
*ni
, int qid
)
3747 struct ieee80211com
*ic
;
3748 struct rt2860_softc_node
*rni
;
3749 struct rt2860_softc_tx_ring
*ring
;
3750 struct rt2860_softc_tx_data
*data
;
3751 struct rt2860_txdesc
*desc
;
3752 struct rt2860_txwi
*txwi
;
3753 struct ieee80211_frame
*wh
;
3754 struct ieee80211_tx_ampdu
*tx_ampdu
;
3755 struct rt2860_softc_tx_radiotap_header
*tap
;
3756 bus_dma_segment_t dma_seg
[RT2860_SOFTC_MAX_SCATTER
];
3757 u_int hdrsize
, hdrspace
;
3758 uint8_t type
, rate
, bw
, stbc
, shortgi
, mcs
, pid
, wcid
, mpdu_density
, bawin_size
, qsel
;
3759 uint16_t qos
, len
, dmalen
, mpdu_len
, dur
;
3760 int error
, hasqos
, ac
, ampdu
, mimops
, ackrate
, ndmasegs
, ndescs
, i
, j
;
3762 KASSERT(qid
>= 0 && qid
< RT2860_SOFTC_TX_RING_COUNT
,
3763 ("%s: Tx frame: invalid qid=%d\n",
3764 device_get_nameunit(sc
->dev
), qid
));
3766 RT2860_SOFTC_TX_RING_ASSERT_LOCKED(&sc
->tx_ring
[qid
]);
3769 rni
= (struct rt2860_softc_node
*) ni
;
3771 ring
= &sc
->tx_ring
[qid
];
3772 desc
= &ring
->desc
[ring
->desc_cur
];
3773 data
= &ring
->data
[ring
->data_cur
];
3774 txwi
= (struct rt2860_txwi
*) (ring
->seg0
+ ring
->data_cur
* RT2860_TX_DATA_SEG0_SIZE
);
3776 wh
= mtod(m
, struct ieee80211_frame
*);
3778 type
= wh
->i_fc
[0] & IEEE80211_FC0_TYPE_MASK
;
3780 hasqos
= IEEE80211_QOS_HAS_SEQ(wh
);
3783 if (IEEE80211_HAS_ADDR4(wh
))
3784 qos
= le16toh(*(const uint16_t *)
3785 (((struct ieee80211_qosframe_addr4
*) wh
)->i_qos
));
3787 qos
= le16toh(*(const uint16_t *)
3788 (((struct ieee80211_qosframe
*) wh
)->i_qos
));
3795 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
3797 if (IEEE80211_IS_MULTICAST(wh
->i_addr1
) || type
!= IEEE80211_FC0_TYPE_DATA
)
3799 else if (ic
->ic_fixed_rate
!= IEEE80211_FIXED_RATE_NONE
)
3800 rate
= ic
->ic_fixed_rate
;
3802 rate
= ni
->ni_htrates
.rs_rates
[ni
->ni_txrate
];
3806 if (IEEE80211_IS_MULTICAST(wh
->i_addr1
) || type
!= IEEE80211_FC0_TYPE_DATA
)
3807 rate
= IEEE80211_IS_CHAN_5GHZ(ic
->ic_curchan
) ? 12 : 2;
3808 else if (ic
->ic_fixed_rate
!= IEEE80211_FIXED_RATE_NONE
)
3809 rate
= ic
->ic_fixed_rate
;
3811 rate
= ni
->ni_rates
.rs_rates
[ni
->ni_txrate
];
3814 rate
&= IEEE80211_RATE_VAL
;
3816 /* fill Tx wireless info */
3818 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
3821 mcs
= rt2860_rate2mcs(rate
);
3823 /* management frames do not need encryption */
3825 if (type
== IEEE80211_FC0_TYPE_DATA
)
3826 wcid
= !IEEE80211_IS_MULTICAST(wh
->i_addr1
) ? rni
->staid
: RT2860_WCID_MCAST
;
3828 wcid
= RT2860_WCID_RESERVED
;
3830 /* calculate MPDU length without padding */
3832 hdrsize
= ieee80211_hdrsize(wh
);
3833 hdrspace
= ieee80211_hdrspace(ic
, wh
);
3834 mpdu_len
= m
->m_pkthdr
.len
- hdrspace
+ hdrsize
;
3836 memset(txwi
, 0, sizeof(struct rt2860_txwi
));
3840 /* MIMO power save */
3842 if ((ni
->ni_flags
& IEEE80211_NODE_HT
) &&
3843 ((ni
->ni_htcap
& IEEE80211_HTCAP_SMPS
) != IEEE80211_HTCAP_SMPS_OFF
))
3847 if ((ni
->ni_htcap
& IEEE80211_HTCAP_SMPS
) == IEEE80211_HTCAP_SMPS_DYNAMIC
)
3849 /* dynamic MIMO power save */
3851 txwi
->mpdu_density_flags
|=
3852 (RT2860_TXWI_FLAGS_MIMOPS
<< RT2860_TXWI_FLAGS_SHIFT
);
3856 /* static MIMO power save */
3871 txwi
->pid_mpdu_len
= ((htole16(pid
) & RT2860_TXWI_PID_MASK
) <<
3872 RT2860_TXWI_PID_SHIFT
) | ((htole16(mpdu_len
) & RT2860_TXWI_MPDU_LEN_MASK
) <<
3873 RT2860_TXWI_MPDU_LEN_SHIFT
);
3875 stbc
= sc
->tx_stbc
&& (ic
->ic_htcaps
& IEEE80211_HTCAP_TXSTBC
) &&
3876 (ni
->ni_flags
& IEEE80211_NODE_HT
) && (ni
->ni_htcap
& IEEE80211_HTCAP_RXSTBC
);
3878 shortgi
= ((ic
->ic_flags_ext
& IEEE80211_FEXT_SHORTGI20
) &&
3879 (ni
->ni_flags
& IEEE80211_NODE_HT
) && (ni
->ni_htcap
& IEEE80211_HTCAP_SHORTGI20
) &&
3880 (ni
->ni_chw
== 20)) ||
3881 ((ic
->ic_flags_ext
& IEEE80211_FEXT_SHORTGI40
) &&
3882 (ni
->ni_flags
& IEEE80211_NODE_HT
) && (ni
->ni_htcap
& IEEE80211_HTCAP_SHORTGI40
) &&
3883 (ni
->ni_chw
== 40));
3885 txwi
->phymode_ifs_stbc_shortgi
|=
3886 ((stbc
& RT2860_TXWI_STBC_MASK
) << RT2860_TXWI_STBC_SHIFT
) |
3887 ((shortgi
& RT2860_TXWI_SHORTGI_MASK
) << RT2860_TXWI_SHORTGI_SHIFT
);
3889 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
3891 txwi
->phymode_ifs_stbc_shortgi
|=
3892 (RT2860_TXWI_PHYMODE_HT_MIXED
<< RT2860_TXWI_PHYMODE_SHIFT
);
3896 if (!RT2860_RATE_IS_OFDM(rate
))
3898 txwi
->phymode_ifs_stbc_shortgi
|=
3899 (RT2860_TXWI_PHYMODE_CCK
<< RT2860_TXWI_PHYMODE_SHIFT
);
3901 if (rate
!= 2 && (ic
->ic_flags
& IEEE80211_F_SHPREAMBLE
))
3902 mcs
|= RT2860_TXWI_MCS_SHOTPRE
;
3906 txwi
->phymode_ifs_stbc_shortgi
|=
3907 (RT2860_TXWI_PHYMODE_OFDM
<< RT2860_TXWI_PHYMODE_SHIFT
);
3911 if ((ni
->ni_flags
& IEEE80211_NODE_HT
) && (ni
->ni_chw
== 40))
3912 bw
= RT2860_TXWI_BW_40
;
3914 bw
= RT2860_TXWI_BW_20
;
3916 txwi
->bw_mcs
= ((bw
& RT2860_TXWI_BW_MASK
) << RT2860_TXWI_BW_SHIFT
) |
3917 ((mcs
& RT2860_TXWI_MCS_MASK
) << RT2860_TXWI_MCS_SHIFT
);
3919 if (type
!= IEEE80211_FC0_TYPE_DATA
)
3920 txwi
->txop
= (RT2860_TXWI_TXOP_BACKOFF
<< RT2860_TXWI_TXOP_SHIFT
);
3922 txwi
->txop
= (RT2860_TXWI_TXOP_HT
<< RT2860_TXWI_TXOP_SHIFT
);
3924 /* skip ACKs for multicast frames */
3926 if (!IEEE80211_IS_MULTICAST(wh
->i_addr1
) &&
3927 (!hasqos
|| (qos
& IEEE80211_QOS_ACKPOLICY
) != IEEE80211_QOS_ACKPOLICY_NOACK
))
3929 txwi
->bawin_size_xflags
|=
3930 (RT2860_TXWI_XFLAGS_ACK
<< RT2860_TXWI_XFLAGS_SHIFT
);
3932 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
3934 /* preamble + plcp + signal extension + SIFS */
3936 dur
= 16 + 4 + 6 + 10;
3940 ackrate
= rt2860_ackrate(ic
, rate
);
3942 dur
= rt2860_txtime(RT2860_ACK_SIZE
, ackrate
, ic
->ic_flags
) +
3946 *(uint16_t *) wh
->i_dur
= htole16(dur
);
3949 /* check for A-MPDU */
3951 if ((qos
& IEEE80211_QOS_ACKPOLICY
) == IEEE80211_QOS_ACKPOLICY_BA
)
3953 ac
= M_WME_GETAC(m
);
3954 tx_ampdu
= &ni
->ni_tx_ampdu
[ac
];
3956 mpdu_density
= RT2860_MS(ni
->ni_htparam
, IEEE80211_HTCAP_MPDUDENSITY
);
3957 bawin_size
= tx_ampdu
->txa_wnd
;
3959 txwi
->mpdu_density_flags
|=
3960 ((mpdu_density
& RT2860_TXWI_MPDU_DENSITY_MASK
) << RT2860_TXWI_MPDU_DENSITY_SHIFT
) |
3961 (RT2860_TXWI_FLAGS_AMPDU
<< RT2860_TXWI_FLAGS_SHIFT
);
3963 txwi
->bawin_size_xflags
|=
3964 ((bawin_size
& RT2860_TXWI_BAWIN_SIZE_MASK
) << RT2860_TXWI_BAWIN_SIZE_SHIFT
);
3966 if (IEEE80211_HAS_ADDR4(wh
))
3967 ((struct ieee80211_qosframe_addr4
*) wh
)->i_qos
[0] &= ~IEEE80211_QOS_ACKPOLICY
;
3969 ((struct ieee80211_qosframe
*) wh
)->i_qos
[0] &= ~IEEE80211_QOS_ACKPOLICY
;
3978 /* ask MAC to insert timestamp into probe responses */
3980 if ((wh
->i_fc
[0] & (IEEE80211_FC0_TYPE_MASK
| IEEE80211_FC0_SUBTYPE_MASK
)) ==
3981 (IEEE80211_FC0_TYPE_MGT
| IEEE80211_FC0_SUBTYPE_PROBE_RESP
))
3982 txwi
->mpdu_density_flags
|=
3983 (RT2860_TXWI_FLAGS_TS
<< RT2860_TXWI_FLAGS_SHIFT
);
3985 if (bpf_peers_present(sc
->drvbpf
))
3989 tap
->flags
= IEEE80211_RADIOTAP_F_DATAPAD
;
3990 tap
->chan_flags
= htole32(ic
->ic_curchan
->ic_flags
);
3991 tap
->chan_freq
= htole16(ic
->ic_curchan
->ic_freq
);
3992 tap
->chan_ieee
= ic
->ic_curchan
->ic_ieee
;
3993 tap
->chan_maxpow
= 0;
3995 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
3996 tap
->rate
= mcs
| IEEE80211_RATE_MCS
;
4000 if (mcs
& RT2860_TXWI_MCS_SHOTPRE
)
4001 tap
->flags
|= IEEE80211_RADIOTAP_F_SHORTPRE
;
4004 tap
->flags
|= IEEE80211_RADIOTAP_F_SHORTGI
;
4006 if (wh
->i_fc
[1] & IEEE80211_FC1_WEP
)
4007 tap
->flags
|= IEEE80211_RADIOTAP_F_WEP
;
4009 if (wh
->i_fc
[1] & IEEE80211_FC1_WEP
)
4011 wh
->i_fc
[1] &= ~IEEE80211_FC1_WEP
;
4013 bpf_mtap2(sc
->drvbpf
, tap
, sc
->txtap_len
, m
);
4015 wh
->i_fc
[1] |= IEEE80211_FC1_WEP
;
4019 bpf_mtap2(sc
->drvbpf
, tap
, sc
->txtap_len
, m
);
4023 /* copy and trim 802.11 header */
4025 m_copydata(m
, 0, hdrsize
, (caddr_t
) (txwi
+ 1));
4028 error
= bus_dmamap_load_mbuf_sg(ring
->data_dma_tag
, data
->dma_map
, m
,
4029 dma_seg
, &ndmasegs
, 0);
4032 /* too many fragments, linearize */
4034 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
4035 "%s: could not load mbuf DMA map, trying to linearize mbuf\n",
4036 device_get_nameunit(sc
->dev
));
4038 m
= m_defrag(m
, M_DONTWAIT
);
4042 sc
->tx_defrag_packets
++;
4044 error
= bus_dmamap_load_mbuf_sg(ring
->data_dma_tag
, data
->dma_map
, m
,
4045 dma_seg
, &ndmasegs
, 0);
4048 printf("%s: could not load mbuf DMA map: error=%d\n",
4049 device_get_nameunit(sc
->dev
), error
);
4055 if (m
->m_pkthdr
.len
== 0)
4058 /* determine how many Tx descs are required */
4060 ndescs
= 1 + ndmasegs
/ 2;
4061 if ((ring
->desc_queued
+ ndescs
) > (RT2860_SOFTC_TX_RING_DESC_COUNT
- 2))
4063 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
4064 "%s: there are not enough Tx descs\n",
4065 device_get_nameunit(sc
->dev
));
4067 sc
->no_tx_desc_avail
++;
4069 bus_dmamap_unload(ring
->data_dma_tag
, data
->dma_map
);
4077 /* set up Tx descs */
4079 /* first segment is Tx wireless info and 802.11 header */
4081 len
= sizeof(struct rt2860_txwi
) + hdrsize
;
4083 /* align end on a 4-bytes boundary */
4085 dmalen
= (len
+ 3) & ~ 3;
4087 memset((caddr_t
) txwi
+ len
, 0, dmalen
- len
);
4089 qsel
= RT2860_TXDESC_QSEL_EDCA
;
4091 desc
->sdp0
= htole32(ring
->seg0_phys_addr
+ ring
->data_cur
* RT2860_TX_DATA_SEG0_SIZE
);
4092 desc
->sdl0
= htole16(dmalen
);
4093 desc
->qsel_flags
= (qsel
<< RT2860_TXDESC_QSEL_SHIFT
);
4095 /* set up payload segments */
4097 for (i
= ndmasegs
, j
= 0; i
>= 2; i
-= 2)
4099 desc
->sdp1
= htole32(dma_seg
[j
].ds_addr
);
4100 desc
->sdl1
= htole16(dma_seg
[j
].ds_len
);
4102 ring
->desc_queued
++;
4103 ring
->desc_cur
= (ring
->desc_cur
+ 1) % RT2860_SOFTC_TX_RING_DESC_COUNT
;
4107 desc
= &ring
->desc
[ring
->desc_cur
];
4109 desc
->sdp0
= htole32(dma_seg
[j
].ds_addr
);
4110 desc
->sdl0
= htole16(dma_seg
[j
].ds_len
);
4111 desc
->qsel_flags
= (qsel
<< RT2860_TXDESC_QSEL_SHIFT
);
4116 /* finalize last payload segment */
4120 desc
->sdp1
= htole32(dma_seg
[j
].ds_addr
);
4121 desc
->sdl1
= htole16(dma_seg
[j
].ds_len
| RT2860_TXDESC_SDL1_LASTSEG
);
4125 desc
->sdl0
|= htole16(RT2860_TXDESC_SDL0_LASTSEG
);
4129 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
4130 "%s: sending frame: qid=%d, hdrsize=%d, hdrspace=%d, len=%d, "
4131 "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",
4132 device_get_nameunit(sc
->dev
),
4133 qid
, hdrsize
, hdrspace
, m
->m_pkthdr
.len
+ hdrsize
,
4134 bw
, stbc
, shortgi
, mcs
, wcid
, ampdu
, mimops
, dmalen
, ndmasegs
,
4135 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
);
4137 bus_dmamap_sync(ring
->seg0_dma_tag
, ring
->seg0_dma_map
,
4138 BUS_DMASYNC_PREWRITE
);
4139 bus_dmamap_sync(ring
->data_dma_tag
, data
->dma_map
,
4140 BUS_DMASYNC_PREWRITE
);
4141 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
4142 BUS_DMASYNC_PREWRITE
);
4144 ring
->desc_queued
++;
4145 ring
->desc_cur
= (ring
->desc_cur
+ 1) % RT2860_SOFTC_TX_RING_DESC_COUNT
;
4147 ring
->data_queued
++;
4148 ring
->data_cur
= (ring
->data_cur
+ 1) % RT2860_SOFTC_TX_RING_DATA_COUNT
;
4152 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_CTX_IDX(qid
), ring
->desc_cur
);
4160 static int rt2860_tx_raw(struct rt2860_softc
*sc
,
4161 struct mbuf
*m
, struct ieee80211_node
*ni
,
4162 const struct ieee80211_bpf_params
*params
)
4164 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
4166 device_get_nameunit(sc
->dev
));
4174 static void rt2860_intr(void *arg
)
4176 struct rt2860_softc
*sc
;
4183 /* acknowledge interrupts */
4185 status
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_INT_STATUS
);
4186 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_INT_STATUS
, status
);
4188 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4189 "%s: interrupt: status = 0x%08x\n",
4190 device_get_nameunit(sc
->dev
), status
);
4192 if (status
== 0xffffffff || /* device likely went away */
4193 status
== 0) /* not for us */
4198 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
4201 if (status
& RT2860_REG_INT_TX_COHERENT
)
4202 rt2860_tx_coherent_intr(sc
);
4204 if (status
& RT2860_REG_INT_RX_COHERENT
)
4205 rt2860_rx_coherent_intr(sc
);
4207 if (status
& RT2860_REG_INT_TXRX_COHERENT
)
4208 rt2860_txrx_coherent_intr(sc
);
4210 if (status
& RT2860_REG_INT_FIFO_STA_FULL
)
4211 rt2860_fifo_sta_full_intr(sc
);
4213 if (status
& RT2860_REG_INT_TX_MGMT_DONE
)
4214 rt2860_tx_intr(sc
, 5);
4216 if (status
& RT2860_REG_INT_RX_DONE
)
4219 if (status
& RT2860_REG_INT_RX_DELAY_DONE
)
4220 rt2860_rx_delay_intr(sc
);
4222 if (status
& RT2860_REG_INT_TX_HCCA_DONE
)
4223 rt2860_tx_intr(sc
, 4);
4225 if (status
& RT2860_REG_INT_TX_AC3_DONE
)
4226 rt2860_tx_intr(sc
, 3);
4228 if (status
& RT2860_REG_INT_TX_AC2_DONE
)
4229 rt2860_tx_intr(sc
, 2);
4231 if (status
& RT2860_REG_INT_TX_AC1_DONE
)
4232 rt2860_tx_intr(sc
, 1);
4234 if (status
& RT2860_REG_INT_TX_AC0_DONE
)
4235 rt2860_tx_intr(sc
, 0);
4237 if (status
& RT2860_REG_INT_TX_DELAY_DONE
)
4238 rt2860_tx_delay_intr(sc
);
4240 if (status
& RT2860_REG_INT_PRE_TBTT
)
4241 rt2860_pre_tbtt_intr(sc
);
4243 if (status
& RT2860_REG_INT_TBTT
)
4244 rt2860_tbtt_intr(sc
);
4246 if (status
& RT2860_REG_INT_MCU_CMD
)
4247 rt2860_mcu_cmd_intr(sc
);
4249 if (status
& RT2860_REG_INT_AUTO_WAKEUP
)
4250 rt2860_auto_wakeup_intr(sc
);
4252 if (status
& RT2860_REG_INT_GP_TIMER
)
4253 rt2860_gp_timer_intr(sc
);
4257 * rt2860_tx_coherent_intr
4259 static void rt2860_tx_coherent_intr(struct rt2860_softc
*sc
)
4264 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4265 "%s: Tx coherent interrupt\n",
4266 device_get_nameunit(sc
->dev
));
4268 sc
->tx_coherent_interrupts
++;
4270 /* restart DMA engine */
4272 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
);
4274 tmp
&= ~(RT2860_REG_TX_WB_DDONE
|
4275 RT2860_REG_RX_DMA_ENABLE
|
4276 RT2860_REG_TX_DMA_ENABLE
);
4278 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
, tmp
);
4280 /* init Tx rings (4 EDCAs + HCCA + MGMT) */
4282 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
4283 rt2860_reset_tx_ring(sc
, &sc
->tx_ring
[i
]);
4285 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
4287 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_BASE_PTR(i
),
4288 sc
->tx_ring
[i
].desc_phys_addr
);
4289 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_MAX_CNT(i
),
4290 RT2860_SOFTC_TX_RING_DESC_COUNT
);
4291 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_CTX_IDX(i
), 0);
4296 rt2860_reset_rx_ring(sc
, &sc
->rx_ring
);
4298 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_BASE_PTR
,
4299 sc
->rx_ring
.desc_phys_addr
);
4300 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_MAX_CNT
,
4301 RT2860_SOFTC_RX_RING_DATA_COUNT
);
4302 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_CALC_IDX
,
4303 RT2860_SOFTC_RX_RING_DATA_COUNT
- 1);
4305 rt2860_txrx_enable(sc
);
4309 * rt2860_rx_coherent_intr
4311 static void rt2860_rx_coherent_intr(struct rt2860_softc
*sc
)
4316 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4317 "%s: Rx coherent interrupt\n",
4318 device_get_nameunit(sc
->dev
));
4320 sc
->rx_coherent_interrupts
++;
4322 /* restart DMA engine */
4324 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
);
4326 tmp
&= ~(RT2860_REG_TX_WB_DDONE
|
4327 RT2860_REG_RX_DMA_ENABLE
|
4328 RT2860_REG_TX_DMA_ENABLE
);
4330 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
, tmp
);
4332 /* init Tx rings (4 EDCAs + HCCA + MGMT) */
4334 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
4335 rt2860_reset_tx_ring(sc
, &sc
->tx_ring
[i
]);
4337 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
4339 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_BASE_PTR(i
),
4340 sc
->tx_ring
[i
].desc_phys_addr
);
4341 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_MAX_CNT(i
),
4342 RT2860_SOFTC_TX_RING_DESC_COUNT
);
4343 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_CTX_IDX(i
), 0);
4348 rt2860_reset_rx_ring(sc
, &sc
->rx_ring
);
4350 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_BASE_PTR
,
4351 sc
->rx_ring
.desc_phys_addr
);
4352 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_MAX_CNT
,
4353 RT2860_SOFTC_RX_RING_DATA_COUNT
);
4354 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_CALC_IDX
,
4355 RT2860_SOFTC_RX_RING_DATA_COUNT
- 1);
4357 rt2860_txrx_enable(sc
);
4361 * rt2860_txrx_coherent_intr
4363 static void rt2860_txrx_coherent_intr(struct rt2860_softc
*sc
)
4368 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4369 "%s: Tx/Rx coherent interrupt\n",
4370 device_get_nameunit(sc
->dev
));
4372 sc
->txrx_coherent_interrupts
++;
4374 /* restart DMA engine */
4376 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
);
4378 tmp
&= ~(RT2860_REG_TX_WB_DDONE
|
4379 RT2860_REG_RX_DMA_ENABLE
|
4380 RT2860_REG_TX_DMA_ENABLE
);
4382 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
, tmp
);
4384 /* init Tx rings (4 EDCAs + HCCA + MGMT) */
4386 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
4387 rt2860_reset_tx_ring(sc
, &sc
->tx_ring
[i
]);
4389 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
4391 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_BASE_PTR(i
),
4392 sc
->tx_ring
[i
].desc_phys_addr
);
4393 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_MAX_CNT(i
),
4394 RT2860_SOFTC_TX_RING_DESC_COUNT
);
4395 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_CTX_IDX(i
), 0);
4400 rt2860_reset_rx_ring(sc
, &sc
->rx_ring
);
4402 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_BASE_PTR
,
4403 sc
->rx_ring
.desc_phys_addr
);
4404 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_MAX_CNT
,
4405 RT2860_SOFTC_RX_RING_DATA_COUNT
);
4406 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_CALC_IDX
,
4407 RT2860_SOFTC_RX_RING_DATA_COUNT
- 1);
4409 rt2860_txrx_enable(sc
);
4413 * rt2860_fifo_sta_full_intr
4415 static void rt2860_fifo_sta_full_intr(struct rt2860_softc
*sc
)
4417 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4418 "%s: FIFO statistic full interrupt\n",
4419 device_get_nameunit(sc
->dev
));
4421 sc
->fifo_sta_full_interrupts
++;
4423 RT2860_SOFTC_LOCK(sc
);
4425 if (!(sc
->intr_disable_mask
& RT2860_REG_INT_FIFO_STA_FULL
))
4427 rt2860_intr_disable(sc
, RT2860_REG_INT_FIFO_STA_FULL
);
4429 taskqueue_enqueue(sc
->taskqueue
, &sc
->fifo_sta_full_task
);
4432 sc
->intr_pending_mask
|= RT2860_REG_INT_FIFO_STA_FULL
;
4434 RT2860_SOFTC_UNLOCK(sc
);
4440 static void rt2860_rx_intr(struct rt2860_softc
*sc
)
4442 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4443 "%s: Rx interrupt\n",
4444 device_get_nameunit(sc
->dev
));
4446 sc
->rx_interrupts
++;
4448 RT2860_SOFTC_LOCK(sc
);
4450 if (!(sc
->intr_disable_mask
& RT2860_REG_INT_RX_DONE
))
4452 rt2860_intr_disable(sc
, RT2860_REG_INT_RX_DONE
);
4454 taskqueue_enqueue(sc
->taskqueue
, &sc
->rx_done_task
);
4457 sc
->intr_pending_mask
|= RT2860_REG_INT_RX_DONE
;
4459 RT2860_SOFTC_UNLOCK(sc
);
4463 * rt2860_rx_delay_intr
4465 static void rt2860_rx_delay_intr(struct rt2860_softc
*sc
)
4467 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4468 "%s: Rx delay interrupt\n",
4469 device_get_nameunit(sc
->dev
));
4471 sc
->rx_delay_interrupts
++;
4477 static void rt2860_tx_intr(struct rt2860_softc
*sc
, int qid
)
4479 KASSERT(qid
>= 0 && qid
< RT2860_SOFTC_TX_RING_COUNT
,
4480 ("%s: Tx interrupt: invalid qid=%d\n",
4481 device_get_nameunit(sc
->dev
), qid
));
4483 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4484 "%s: Tx interrupt: qid=%d\n",
4485 device_get_nameunit(sc
->dev
), qid
);
4487 sc
->tx_interrupts
[qid
]++;
4489 RT2860_SOFTC_LOCK(sc
);
4491 if (!(sc
->intr_disable_mask
& (RT2860_REG_INT_TX_AC0_DONE
<< qid
)))
4493 rt2860_intr_disable(sc
, (RT2860_REG_INT_TX_AC0_DONE
<< qid
));
4495 taskqueue_enqueue(sc
->taskqueue
, &sc
->tx_done_task
);
4498 sc
->intr_pending_mask
|= (RT2860_REG_INT_TX_AC0_DONE
<< qid
);
4500 RT2860_SOFTC_UNLOCK(sc
);
4504 * rt2860_tx_delay_intr
4506 static void rt2860_tx_delay_intr(struct rt2860_softc
*sc
)
4508 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4509 "%s: Tx delay interrupt\n",
4510 device_get_nameunit(sc
->dev
));
4512 sc
->tx_delay_interrupts
++;
4516 * rt2860_pre_tbtt_intr
4518 static void rt2860_pre_tbtt_intr(struct rt2860_softc
*sc
)
4520 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4521 "%s: Pre-TBTT interrupt\n",
4522 device_get_nameunit(sc
->dev
));
4524 sc
->pre_tbtt_interrupts
++;
4530 static void rt2860_tbtt_intr(struct rt2860_softc
*sc
)
4532 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4533 "%s: TBTT interrupt\n",
4534 device_get_nameunit(sc
->dev
));
4536 sc
->tbtt_interrupts
++;
4540 * rt2860_mcu_cmd_intr
4542 static void rt2860_mcu_cmd_intr(struct rt2860_softc
*sc
)
4544 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4545 "%s: MCU command interrupt\n",
4546 device_get_nameunit(sc
->dev
));
4548 sc
->mcu_cmd_interrupts
++;
4552 * rt2860_auto_wakeup_intr
4554 static void rt2860_auto_wakeup_intr(struct rt2860_softc
*sc
)
4556 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4557 "%s: auto wakeup interrupt\n",
4558 device_get_nameunit(sc
->dev
));
4560 sc
->auto_wakeup_interrupts
++;
4564 * rt2860_gp_timer_intr
4566 static void rt2860_gp_timer_intr(struct rt2860_softc
*sc
)
4568 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4569 "%s: GP timer interrupt\n",
4570 device_get_nameunit(sc
->dev
));
4572 sc
->gp_timer_interrupts
++;
4576 * rt2860_rx_done_task
4578 static void rt2860_rx_done_task(void *context
, int pending
)
4580 struct rt2860_softc
*sc
;
4587 RT2860_DPRINTF(sc
, RT2860_DEBUG_RX
,
4588 "%s: Rx done task\n",
4589 device_get_nameunit(sc
->dev
));
4591 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
4594 sc
->intr_pending_mask
&= ~RT2860_REG_INT_RX_DONE
;
4596 again
= rt2860_rx_eof(sc
, sc
->rx_process_limit
);
4598 RT2860_SOFTC_LOCK(sc
);
4600 if ((sc
->intr_pending_mask
& RT2860_REG_INT_RX_DONE
) || again
)
4602 RT2860_DPRINTF(sc
, RT2860_DEBUG_RX
,
4603 "%s: Rx done task: scheduling again\n",
4604 device_get_nameunit(sc
->dev
));
4606 taskqueue_enqueue(sc
->taskqueue
, &sc
->rx_done_task
);
4610 rt2860_intr_enable(sc
, RT2860_REG_INT_RX_DONE
);
4613 RT2860_SOFTC_UNLOCK(sc
);
4617 * rt2860_tx_done_task
4619 static void rt2860_tx_done_task(void *context
, int pending
)
4621 struct rt2860_softc
*sc
;
4623 struct ieee80211com
*ic
;
4631 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
4632 "%s: Tx done task\n",
4633 device_get_nameunit(sc
->dev
));
4635 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
4638 for (i
= RT2860_SOFTC_TX_RING_COUNT
- 1; i
>= 0; i
--)
4640 if (sc
->intr_pending_mask
& (RT2860_REG_INT_TX_AC0_DONE
<< i
))
4642 sc
->intr_pending_mask
&= ~(RT2860_REG_INT_TX_AC0_DONE
<< i
);
4644 rt2860_tx_eof(sc
, &sc
->tx_ring
[i
]);
4650 ifp
->if_drv_flags
&= ~IFF_DRV_OACTIVE
;
4652 intr_mask
= (RT2860_REG_INT_TX_MGMT_DONE
|
4653 RT2860_REG_INT_TX_HCCA_DONE
|
4654 RT2860_REG_INT_TX_AC3_DONE
|
4655 RT2860_REG_INT_TX_AC2_DONE
|
4656 RT2860_REG_INT_TX_AC1_DONE
|
4657 RT2860_REG_INT_TX_AC0_DONE
);
4659 RT2860_SOFTC_LOCK(sc
);
4661 rt2860_intr_enable(sc
, ~sc
->intr_pending_mask
&
4662 (sc
->intr_disable_mask
& intr_mask
));
4664 if (sc
->intr_pending_mask
& intr_mask
)
4666 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
4667 "%s: Tx done task: scheduling again\n",
4668 device_get_nameunit(sc
->dev
));
4670 taskqueue_enqueue(sc
->taskqueue
, &sc
->tx_done_task
);
4673 RT2860_SOFTC_UNLOCK(sc
);
4675 if (!IFQ_IS_EMPTY(&ic
->ic_mgtq
) || !IFQ_IS_EMPTY(&ifp
->if_snd
))
4680 * rt2860_fifo_sta_full_task
4682 static void rt2860_fifo_sta_full_task(void *context
, int pending
)
4684 struct rt2860_softc
*sc
;
4686 struct ieee80211com
*ic
;
4692 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATS
,
4693 "%s: FIFO statistic full task\n",
4694 device_get_nameunit(sc
->dev
));
4696 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
4699 sc
->intr_pending_mask
&= ~RT2860_REG_INT_FIFO_STA_FULL
;
4701 rt2860_drain_fifo_stats(sc
);
4703 RT2860_SOFTC_LOCK(sc
);
4705 if (sc
->intr_pending_mask
& RT2860_REG_INT_FIFO_STA_FULL
)
4707 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATS
,
4708 "%s: FIFO statistic full task: scheduling again\n",
4709 device_get_nameunit(sc
->dev
));
4711 taskqueue_enqueue(sc
->taskqueue
, &sc
->fifo_sta_full_task
);
4715 rt2860_intr_enable(sc
, RT2860_REG_INT_FIFO_STA_FULL
);
4718 RT2860_SOFTC_UNLOCK(sc
);
4720 if (!IFQ_IS_EMPTY(&ic
->ic_mgtq
) || !IFQ_IS_EMPTY(&ifp
->if_snd
))
4725 * rt2860_periodic_task
4727 static void rt2860_periodic_task(void *context
, int pending
)
4729 struct rt2860_softc
*sc
;
4731 struct ieee80211com
*ic
;
4737 RT2860_DPRINTF(sc
, RT2860_DEBUG_PERIODIC
,
4738 "%s: periodic task: round=%lu\n",
4739 device_get_nameunit(sc
->dev
), sc
->periodic_round
);
4741 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
4744 RT2860_SOFTC_LOCK(sc
);
4746 sc
->periodic_round
++;
4748 rt2860_update_stats(sc
);
4750 if ((sc
->periodic_round
% 10) == 0)
4752 rt2860_bbp_tuning(sc
);
4754 rt2860_update_raw_counters(sc
);
4756 rt2860_watchdog(sc
);
4758 if (ic
->ic_opmode
!= IEEE80211_M_MONITOR
&& ic
->ic_state
== IEEE80211_S_RUN
)
4760 if (ic
->ic_opmode
== IEEE80211_M_STA
)
4761 rt2860_amrr_update_iter_func(sc
, ic
->ic_bss
);
4763 ieee80211_iterate_nodes(&ic
->ic_sta
, rt2860_amrr_update_iter_func
, sc
);
4767 RT2860_SOFTC_UNLOCK(sc
);
4769 callout_reset(&sc
->periodic_ch
, hz
/ 10, rt2860_periodic
, sc
);
4775 static int rt2860_rx_eof(struct rt2860_softc
*sc
, int limit
)
4777 struct ieee80211com
*ic
;
4779 struct ieee80211_frame
*wh
;
4780 struct ieee80211_node
*ni
;
4781 struct rt2860_softc_node
*rni
;
4782 struct rt2860_softc_rx_radiotap_header
*tap
;
4783 struct rt2860_softc_rx_ring
*ring
;
4784 struct rt2860_rxdesc
*desc
;
4785 struct rt2860_softc_rx_data
*data
;
4786 struct rt2860_rxwi
*rxwi
;
4787 struct mbuf
*m
, *mnew
;
4788 bus_dma_segment_t segs
[1];
4789 bus_dmamap_t dma_map
;
4790 uint32_t index
, desc_flags
;
4791 uint8_t cipher_err
, rssi
, ant
, phymode
, bw
, shortgi
, mcs
, keyidx
;
4793 int error
, nsegs
, len
, ampdu
, amsdu
, nframes
, i
;
4797 ring
= &sc
->rx_ring
;
4803 index
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_RX_DRX_IDX
);
4804 if (ring
->cur
== index
)
4807 desc
= &ring
->desc
[ring
->cur
];
4808 desc_flags
= le32toh(desc
->flags
);
4809 data
= &ring
->data
[ring
->cur
];
4811 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
4812 BUS_DMASYNC_POSTREAD
);
4814 if (!(desc
->sdl0
& htole16(RT2860_RXDESC_SDL0_DDONE
)))
4819 mnew
= m_getjcl(M_DONTWAIT
, MT_DATA
, M_PKTHDR
, MJUMPAGESIZE
);
4822 sc
->rx_mbuf_alloc_errors
++;
4827 mnew
->m_len
= mnew
->m_pkthdr
.len
= MJUMPAGESIZE
;
4829 error
= bus_dmamap_load_mbuf_sg(ring
->data_dma_tag
, ring
->spare_dma_map
,
4830 mnew
, segs
, &nsegs
, BUS_DMA_NOWAIT
);
4835 sc
->rx_mbuf_dmamap_errors
++;
4841 KASSERT(nsegs
== 1, ("%s: too many DMA segments",
4842 device_get_name(sc
->dev
)));
4844 bus_dmamap_sync(ring
->data_dma_tag
, data
->dma_map
,
4845 BUS_DMASYNC_POSTREAD
);
4846 bus_dmamap_unload(ring
->data_dma_tag
, data
->dma_map
);
4848 dma_map
= data
->dma_map
;
4849 data
->dma_map
= ring
->spare_dma_map
;
4850 ring
->spare_dma_map
= dma_map
;
4852 bus_dmamap_sync(ring
->data_dma_tag
, data
->dma_map
,
4853 BUS_DMASYNC_PREREAD
);
4858 desc
->sdp0
= htole32(segs
[0].ds_addr
);
4860 /* get Rx wireless info */
4862 rxwi
= mtod(m
, struct rt2860_rxwi
*);
4863 len
= (le16toh(rxwi
->tid_size
) >> RT2860_RXWI_SIZE_SHIFT
) &
4864 RT2860_RXWI_SIZE_MASK
;
4866 /* check for L2 padding between IEEE 802.11 frame header and body */
4868 if (desc_flags
& RT2860_RXDESC_FLAGS_L2PAD
)
4870 RT2860_DPRINTF(sc
, RT2860_DEBUG_RX
,
4871 "%s: L2 padding: len=%d\n",
4872 device_get_nameunit(sc
->dev
), len
);
4877 m
->m_pkthdr
.rcvif
= ifp
;
4878 m
->m_data
= (caddr_t
) (rxwi
+ 1);
4879 m
->m_pkthdr
.len
= m
->m_len
= len
;
4881 /* check for crc errors */
4883 if (desc_flags
& RT2860_RXDESC_FLAGS_CRC_ERR
)
4885 RT2860_DPRINTF(sc
, RT2860_DEBUG_RX
,
4886 "%s: rxdesc: crc error\n",
4887 device_get_nameunit(sc
->dev
));
4891 if (!(ifp
->if_flags
& IFF_PROMISC
))
4898 wh
= (struct ieee80211_frame
*) (rxwi
+ 1);
4900 /* check for cipher errors */
4902 if (desc_flags
& RT2860_RXDESC_FLAGS_DECRYPTED
)
4904 cipher_err
= ((desc_flags
>> RT2860_RXDESC_FLAGS_CIPHER_ERR_SHIFT
) &
4905 RT2860_RXDESC_FLAGS_CIPHER_ERR_MASK
);
4906 if (cipher_err
== RT2860_RXDESC_FLAGS_CIPHER_ERR_NONE
)
4908 if (wh
->i_fc
[1] & IEEE80211_FC1_WEP
)
4909 wh
->i_fc
[1] &= ~IEEE80211_FC1_WEP
;
4911 m
->m_flags
|= M_WEP
;
4913 sc
->rx_cipher_no_errors
++;
4917 RT2860_DPRINTF(sc
, RT2860_DEBUG_RX
,
4918 "%s: rxdesc: cipher error=0x%02x\n",
4919 device_get_nameunit(sc
->dev
), cipher_err
);
4921 if (cipher_err
== RT2860_RXDESC_FLAGS_CIPHER_ERR_ICV
)
4922 sc
->rx_cipher_icv_errors
++;
4923 else if (cipher_err
== RT2860_RXDESC_FLAGS_CIPHER_ERR_MIC
)
4924 sc
->rx_cipher_mic_errors
++;
4925 else if (cipher_err
== RT2860_RXDESC_FLAGS_CIPHER_ERR_INVALID_KEY
)
4926 sc
->rx_cipher_invalid_key_errors
++;
4928 if ((cipher_err
== RT2860_RXDESC_FLAGS_CIPHER_ERR_MIC
) &&
4929 (desc_flags
& RT2860_RXDESC_FLAGS_MYBSS
))
4931 keyidx
= (rxwi
->udf_bssidx_keyidx
>> RT2860_RXWI_KEYIDX_SHIFT
) &
4932 RT2860_RXWI_KEYIDX_MASK
;
4934 ieee80211_notify_michael_failure(ic
, wh
, keyidx
);
4939 if (!(ifp
->if_flags
& IFF_PROMISC
))
4948 if (wh
->i_fc
[1] & IEEE80211_FC1_WEP
)
4950 RT2860_DPRINTF(sc
, RT2860_DEBUG_RX
,
4951 "%s: rxdesc: not decrypted but protected flag set\n",
4952 device_get_nameunit(sc
->dev
));
4956 if (!(ifp
->if_flags
& IFF_PROMISC
))
4964 /* check for A-MPDU */
4966 if (desc_flags
& RT2860_RXDESC_FLAGS_AMPDU
)
4968 m
->m_flags
|= M_AMPDU
;
4979 /* check for A-MSDU */
4981 if (desc_flags
& RT2860_RXDESC_FLAGS_AMSDU
)
4992 ant
= rt2860_maxrssi_rxpath(sc
, rxwi
);
4993 rssi
= rxwi
->rssi
[ant
];
4994 rssi_dbm
= rt2860_rssi2dbm(sc
, rssi
, ant
);
4995 phymode
= ((rxwi
->phymode_stbc_shortgi
>> RT2860_RXWI_PHYMODE_SHIFT
) &
4996 RT2860_RXWI_PHYMODE_MASK
);
4997 bw
= ((rxwi
->bw_mcs
>> RT2860_RXWI_BW_SHIFT
) & RT2860_RXWI_BW_MASK
);
4998 shortgi
= ((rxwi
->phymode_stbc_shortgi
>> RT2860_RXWI_SHORTGI_SHIFT
) &
4999 RT2860_RXWI_SHORTGI_MASK
);
5000 mcs
= ((rxwi
->bw_mcs
>> RT2860_RXWI_MCS_SHIFT
) & RT2860_RXWI_MCS_MASK
);
5002 if (bpf_peers_present(sc
->drvbpf
))
5006 tap
->flags
= IEEE80211_RADIOTAP_F_DATAPAD
;
5007 tap
->dbm_antsignal
= rssi_dbm
;
5008 tap
->dbm_antnoise
= RT2860_NOISE_FLOOR
;
5010 tap
->antsignal
= rssi
;
5011 tap
->chan_flags
= htole32(ic
->ic_curchan
->ic_flags
);
5012 tap
->chan_freq
= htole16(ic
->ic_curchan
->ic_freq
);
5013 tap
->chan_ieee
= ic
->ic_curchan
->ic_ieee
;
5014 tap
->chan_maxpow
= 0;
5016 if (phymode
== RT2860_TXWI_PHYMODE_HT_MIXED
|| phymode
== RT2860_TXWI_PHYMODE_HT_GF
)
5017 tap
->rate
= mcs
| IEEE80211_RATE_MCS
;
5019 tap
->rate
= rt2860_rxrate(rxwi
);
5021 if (desc_flags
& RT2860_RXDESC_FLAGS_CRC_ERR
)
5022 tap
->flags
|= IEEE80211_RADIOTAP_F_BADFCS
;
5024 if (desc_flags
& RT2860_RXDESC_FLAGS_FRAG
)
5025 tap
->flags
|= IEEE80211_RADIOTAP_F_FRAG
;
5027 if (rxwi
->bw_mcs
& RT2860_RXWI_MCS_SHOTPRE
)
5028 tap
->flags
|= IEEE80211_RADIOTAP_F_SHORTPRE
;
5030 if ((desc_flags
& RT2860_RXDESC_FLAGS_DECRYPTED
) ||
5031 (wh
->i_fc
[1] & IEEE80211_FC1_WEP
))
5032 tap
->flags
|= IEEE80211_RADIOTAP_F_WEP
;
5035 tap
->flags
|= IEEE80211_RADIOTAP_F_SHORTGI
;
5037 bpf_mtap2(sc
->drvbpf
, tap
, sc
->rxtap_len
, m
);
5040 RT2860_DPRINTF(sc
, RT2860_DEBUG_RX
,
5041 "%s: received frame: len=%d, phymode=%d, bw=%d, shortgi=%d, mcs=%d, "
5042 "ant=%d, rssi=%d/%d/%d, snr=%d/%d, wcid=0x%02x, ampdu=%d, amsdu=%d\n",
5043 device_get_nameunit(sc
->dev
),
5044 len
, phymode
, bw
, shortgi
, mcs
,
5045 ant
, rxwi
->rssi
[0], rxwi
->rssi
[1], rxwi
->rssi
[2],
5046 rxwi
->snr
[0], rxwi
->snr
[1],
5047 rxwi
->wcid
, ampdu
, amsdu
);
5049 ni
= ieee80211_find_rxnode(ic
, (struct ieee80211_frame_min
*) wh
);
5053 rni
= (struct rt2860_softc_node
*) ni
;
5055 for (i
= 0; i
< RT2860_SOFTC_RSSI_COUNT
; i
++)
5057 rni
->last_rssi
[i
] = rxwi
->rssi
[i
];
5058 rni
->last_rssi_dbm
[i
] = rt2860_rssi2dbm(sc
, rxwi
->rssi
[i
], i
);
5062 ieee80211_input(ic
, m
, ni
, rssi_dbm
, RT2860_NOISE_FLOOR
, 0);
5064 ieee80211_free_node(ni
);
5068 desc
->sdl0
&= ~htole16(RT2860_RXDESC_SDL0_DDONE
);
5070 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
5071 BUS_DMASYNC_PREREAD
| BUS_DMASYNC_PREWRITE
);
5073 ring
->cur
= (ring
->cur
+ 1) % RT2860_SOFTC_RX_RING_DATA_COUNT
;
5079 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_CALC_IDX
,
5080 RT2860_SOFTC_RX_RING_DATA_COUNT
- 1);
5082 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_CALC_IDX
,
5085 RT2860_DPRINTF(sc
, RT2860_DEBUG_RX
,
5086 "%s: Rx eof: nframes=%d\n",
5087 device_get_nameunit(sc
->dev
), nframes
);
5089 sc
->rx_packets
+= nframes
;
5091 return (limit
== 0);
5097 static void rt2860_tx_eof(struct rt2860_softc
*sc
,
5098 struct rt2860_softc_tx_ring
*ring
)
5101 struct rt2860_txdesc
*desc
;
5102 struct rt2860_softc_tx_data
*data
;
5104 int ndescs
, nframes
;
5113 index
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_TX_DTX_IDX(ring
->qid
));
5114 if (ring
->desc_next
== index
)
5119 rt2860_drain_fifo_stats(sc
);
5121 desc
= &ring
->desc
[ring
->desc_next
];
5123 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
5124 BUS_DMASYNC_POSTREAD
);
5126 if (desc
->sdl0
& htole16(RT2860_TXDESC_SDL0_LASTSEG
) ||
5127 desc
->sdl1
& htole16(RT2860_TXDESC_SDL1_LASTSEG
))
5131 data
= &ring
->data
[ring
->data_next
];
5133 if (data
->m
->m_flags
& M_TXCB
)
5134 ieee80211_process_callback(data
->ni
, data
->m
, 0);
5136 bus_dmamap_sync(ring
->data_dma_tag
, data
->dma_map
,
5137 BUS_DMASYNC_POSTWRITE
);
5138 bus_dmamap_unload(ring
->data_dma_tag
, data
->dma_map
);
5142 ieee80211_free_node(data
->ni
);
5149 RT2860_SOFTC_TX_RING_LOCK(ring
);
5151 ring
->data_queued
--;
5152 ring
->data_next
= (ring
->data_next
+ 1) % RT2860_SOFTC_TX_RING_DATA_COUNT
;
5154 RT2860_SOFTC_TX_RING_UNLOCK(ring
);
5157 desc
->sdl0
&= ~htole16(RT2860_TXDESC_SDL0_DDONE
);
5159 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
5160 BUS_DMASYNC_PREREAD
| BUS_DMASYNC_PREWRITE
);
5162 RT2860_SOFTC_TX_RING_LOCK(ring
);
5164 ring
->desc_queued
--;
5165 ring
->desc_next
= (ring
->desc_next
+ 1) % RT2860_SOFTC_TX_RING_DESC_COUNT
;
5167 RT2860_SOFTC_TX_RING_UNLOCK(ring
);
5170 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
5171 "%s: Tx eof: qid=%d, ndescs=%d, nframes=%d\n",
5172 device_get_nameunit(sc
->dev
), ring
->qid
, ndescs
, nframes
);
5176 * rt2860_update_stats
5178 static void rt2860_update_stats(struct rt2860_softc
*sc
)
5182 int beacons
, noretryok
, retryok
, failed
, underflows
, zerolen
;
5186 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATS
,
5187 "%s: update statistic\n",
5188 device_get_nameunit(sc
->dev
));
5190 rt2860_drain_fifo_stats(sc
);
5192 /* read and clear Tx statistic registers */
5194 rt2860_io_mac_read_multi(sc
, RT2860_REG_TX_STA_CNT0
,
5195 stacnt
, sizeof(stacnt
));
5197 stacnt
[0] = le32toh(stacnt
[0]);
5198 stacnt
[1] = le32toh(stacnt
[1]);
5199 stacnt
[2] = le32toh(stacnt
[2]);
5201 beacons
= stacnt
[0] >> 16;
5202 noretryok
= stacnt
[1] & 0xffff;
5203 retryok
= stacnt
[1] >> 16;
5204 failed
= stacnt
[0] & 0xffff;
5205 underflows
= stacnt
[2] >> 16;
5206 zerolen
= stacnt
[2] & 0xffff;
5208 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATS
,
5209 "%s: update statistic: beacons=%d, noretryok=%d, retryok=%d, failed=%d, underflows=%d, zerolen=%d\n",
5210 device_get_nameunit(sc
->dev
),
5211 beacons
, noretryok
, retryok
, failed
, underflows
, zerolen
);
5213 ifp
->if_oerrors
+= failed
;
5215 sc
->tx_beacons
+= beacons
;
5216 sc
->tx_noretryok
+= noretryok
;
5217 sc
->tx_retryok
+= retryok
;
5218 sc
->tx_failed
+= failed
;
5219 sc
->tx_underflows
+= underflows
;
5220 sc
->tx_zerolen
+= zerolen
;
5226 static void rt2860_bbp_tuning(struct rt2860_softc
*sc
)
5228 struct ieee80211com
*ic
;
5229 struct ieee80211_node
*ni
;
5231 int8_t rssi
, old
, new;
5233 /* RT2860C does not support BBP tuning */
5235 if (sc
->mac_rev
== 0x28600100)
5240 if ((ic
->ic_flags
& IEEE80211_F_SCAN
) ||
5241 ic
->ic_opmode
!= IEEE80211_M_STA
|| ic
->ic_state
!= IEEE80211_S_RUN
)
5246 chan
= ieee80211_chan2ieee(ic
, ni
->ni_chan
);
5250 else if (chan
<= 64)
5252 else if (chan
<= 128)
5257 rssi
= ieee80211_getrssi(ic
);
5259 if (IEEE80211_IS_CHAN_2GHZ(ni
->ni_chan
))
5261 new = 0x2e + sc
->lna_gain
[group
];
5265 if (!IEEE80211_IS_CHAN_HT40(ni
->ni_chan
))
5266 new = 0x32 + sc
->lna_gain
[group
] * 5 / 3;
5268 new = 0x3a + sc
->lna_gain
[group
] * 5 / 3;
5271 /* Tune if absolute average RSSI is greater than -80 */
5276 old
= rt2860_io_bbp_read(sc
, 66);
5279 rt2860_io_bbp_write(sc
, 66, new);
5285 static void rt2860_watchdog(struct rt2860_softc
*sc
)
5290 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_PBF_TXRXQ_PCNT
);
5292 RT2860_DPRINTF(sc
, RT2860_DEBUG_WATCHDOG
,
5293 "%s: watchdog: TXRXQ_PCNT=0x%08x\n",
5294 device_get_nameunit(sc
->dev
), tmp
);
5296 if (((tmp
>> RT2860_REG_TX0Q_PCNT_SHIFT
) & RT2860_REG_TX0Q_PCNT_MASK
) != 0)
5298 sc
->tx_queue_not_empty
[0]++;
5300 rt2860_io_mac_write(sc
, RT2860_REG_PBF_CFG
, 0xf40012);
5302 for (ntries
= 0; ntries
< 10; ntries
++)
5304 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_PBF_TXRXQ_PCNT
);
5305 if (((tmp
>> RT2860_REG_TX0Q_PCNT_SHIFT
) & RT2860_REG_TX0Q_PCNT_MASK
) == 0)
5311 rt2860_io_mac_write(sc
, RT2860_REG_PBF_CFG
, 0xf40006);
5314 if (((tmp
>> RT2860_REG_TX1Q_PCNT_SHIFT
) & RT2860_REG_TX1Q_PCNT_MASK
) != 0)
5316 sc
->tx_queue_not_empty
[1]++;
5318 rt2860_io_mac_write(sc
, RT2860_REG_PBF_CFG
, 0xf4000a);
5320 for (ntries
= 0; ntries
< 10; ntries
++)
5322 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_PBF_TXRXQ_PCNT
);
5323 if (((tmp
>> RT2860_REG_TX1Q_PCNT_SHIFT
) & RT2860_REG_TX1Q_PCNT_MASK
) == 0)
5329 rt2860_io_mac_write(sc
, RT2860_REG_PBF_CFG
, 0xf40006);
5334 * rt2860_drain_fifo_stats
5336 static void rt2860_drain_fifo_stats(struct rt2860_softc
*sc
)
5340 uint8_t wcid
, mcs
, pid
;
5341 int ok
, agg
, retrycnt
;
5343 ifp
= sc
->ic
.ic_ifp
;
5345 /* drain Tx status FIFO (maxsize = 16) */
5347 while ((stats
= rt2860_io_mac_read(sc
, RT2860_REG_TX_STA_FIFO
)) &
5348 RT2860_REG_TX_STA_FIFO_VALID
)
5350 wcid
= (stats
>> RT2860_REG_TX_STA_FIFO_WCID_SHIFT
) &
5351 RT2860_REG_TX_STA_FIFO_WCID_MASK
;
5353 /* if no ACK was requested, no feedback is available */
5355 if (!(stats
& RT2860_REG_TX_STA_FIFO_ACK_REQ
) || wcid
== RT2860_WCID_RESERVED
)
5358 /* update AMRR statistic */
5360 ok
= (stats
& RT2860_REG_TX_STA_FIFO_TX_OK
) ? 1 : 0;
5361 agg
= (stats
& RT2860_REG_TX_STA_FIFO_AGG
) ? 1 : 0;
5362 mcs
= (stats
>> RT2860_REG_TX_STA_FIFO_MCS_SHIFT
) &
5363 RT2860_REG_TX_STA_FIFO_MCS_MASK
;
5364 pid
= (stats
>> RT2860_REG_TX_STA_FIFO_PID_SHIFT
) &
5365 RT2860_REG_TX_STA_FIFO_PID_MASK
;
5366 retrycnt
= pid
- mcs
;
5368 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATS
,
5369 "%s: FIFO statistic: wcid=0x%02x, ok=%d, agg=%d, mcs=0x%02x, pid=0x%02x, retrycnt=%d\n",
5370 device_get_nameunit(sc
->dev
),
5371 wcid
, ok
, agg
, mcs
, pid
, retrycnt
);
5373 rt2860_amrr_tx_complete(&sc
->amrr_node
[wcid
], ok
, retrycnt
);
5381 * rt2860_update_raw_counters
5383 static void rt2860_update_raw_counters(struct rt2860_softc
*sc
)
5387 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_AGG_CNT
);
5389 sc
->tx_nonagg
+= tmp
& 0xffff;
5390 sc
->tx_agg
+= tmp
>> 16;
5392 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_AGG_CNT0
);
5394 sc
->tx_ampdu
+= (tmp
& 0xffff) / 1 + (tmp
>> 16) / 2;
5396 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_AGG_CNT1
);
5398 sc
->tx_ampdu
+= (tmp
& 0xffff) / 3 + (tmp
>> 16) / 4;
5400 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_AGG_CNT2
);
5402 sc
->tx_ampdu
+= (tmp
& 0xffff) / 5 + (tmp
>> 16) / 6;
5404 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_AGG_CNT3
);
5406 sc
->tx_ampdu
+= (tmp
& 0xffff) / 7 + (tmp
>> 16) / 8;
5408 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_AGG_CNT4
);
5410 sc
->tx_ampdu
+= (tmp
& 0xffff) / 9 + (tmp
>> 16) / 10;
5412 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_AGG_CNT5
);
5414 sc
->tx_ampdu
+= (tmp
& 0xffff) / 11 + (tmp
>> 16) / 12;
5416 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_AGG_CNT6
);
5418 sc
->tx_ampdu
+= (tmp
& 0xffff) / 13 + (tmp
>> 16) / 14;
5420 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_AGG_CNT7
);
5422 sc
->tx_ampdu
+= (tmp
& 0xffff) / 15 + (tmp
>> 16) / 16;
5424 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_RX_STA_CNT0
);
5426 sc
->rx_crc_errors
+= tmp
& 0xffff;
5427 sc
->rx_phy_errors
+= tmp
>> 16;
5429 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_RX_STA_CNT1
);
5431 sc
->rx_false_ccas
+= tmp
& 0xffff;
5432 sc
->rx_plcp_errors
+= tmp
>> 16;
5434 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_RX_STA_CNT2
);
5436 sc
->rx_dup_packets
+= tmp
& 0xffff;
5437 sc
->rx_fifo_overflows
+= tmp
>> 16;
5439 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TXRX_MPDU_DEN_CNT
);
5441 sc
->tx_mpdu_zero_density
+= tmp
& 0xffff;
5442 sc
->rx_mpdu_zero_density
+= tmp
>> 16;
5446 * rt2860_intr_enable
5448 static void rt2860_intr_enable(struct rt2860_softc
*sc
, uint32_t intr_mask
)
5452 sc
->intr_disable_mask
&= ~intr_mask
;
5454 tmp
= sc
->intr_enable_mask
& ~sc
->intr_disable_mask
;
5456 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_INT_MASK
, tmp
);
5460 * rt2860_intr_disable
5462 static void rt2860_intr_disable(struct rt2860_softc
*sc
, uint32_t intr_mask
)
5466 sc
->intr_disable_mask
|= intr_mask
;
5468 tmp
= sc
->intr_enable_mask
& ~sc
->intr_disable_mask
;
5470 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_INT_MASK
, tmp
);
5474 * rt2860_txrx_enable
5476 static int rt2860_txrx_enable(struct rt2860_softc
*sc
)
5478 struct ieee80211com
*ic
;
5486 /* enable Tx/Rx DMA engine */
5488 rt2860_io_mac_write(sc
, RT2860_REG_SYS_CTRL
, RT2860_REG_TX_ENABLE
);
5490 for (ntries
= 0; ntries
< 200; ntries
++)
5492 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
);
5493 if (!(tmp
& (RT2860_REG_TX_DMA_BUSY
| RT2860_REG_RX_DMA_BUSY
)))
5501 printf("%s: timeout waiting for DMA engine\n",
5502 device_get_nameunit(sc
->dev
));
5508 tmp
|= RT2860_REG_TX_WB_DDONE
|
5509 RT2860_REG_RX_DMA_ENABLE
|
5510 RT2860_REG_TX_DMA_ENABLE
|
5511 (RT2860_REG_WPDMA_BT_SIZE64
<< RT2860_REG_WPDMA_BT_SIZE_SHIFT
);
5513 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
, tmp
);
5517 tmp
= RT2860_REG_RX_FILTER_DROP_CRC_ERR
|
5518 RT2860_REG_RX_FILTER_DROP_PHY_ERR
;
5520 if (ic
->ic_opmode
!= IEEE80211_M_MONITOR
)
5522 tmp
|= RT2860_REG_RX_FILTER_DROP_DUPL
|
5523 RT2860_REG_RX_FILTER_DROP_CTS
|
5524 RT2860_REG_RX_FILTER_DROP_BA
|
5525 RT2860_REG_RX_FILTER_DROP_ACK
|
5526 RT2860_REG_RX_FILTER_DROP_VER_ERR
|
5527 RT2860_REG_RX_FILTER_DROP_CTRL_RSV
|
5528 RT2860_REG_RX_FILTER_DROP_CFACK
|
5529 RT2860_REG_RX_FILTER_DROP_CFEND
;
5531 if (ic
->ic_opmode
== IEEE80211_M_STA
)
5532 tmp
|= RT2860_REG_RX_FILTER_DROP_RTS
|
5533 RT2860_REG_RX_FILTER_DROP_PSPOLL
;
5535 if (!(ifp
->if_flags
& IFF_PROMISC
))
5536 tmp
|= RT2860_REG_RX_FILTER_DROP_UC_NOME
;
5539 rt2860_io_mac_write(sc
, RT2860_REG_RX_FILTER_CFG
, tmp
);
5541 rt2860_io_mac_write(sc
, RT2860_REG_SYS_CTRL
,
5542 RT2860_REG_RX_ENABLE
| RT2860_REG_TX_ENABLE
);
5548 * rt2860_alloc_rx_ring
5550 static int rt2860_alloc_rx_ring(struct rt2860_softc
*sc
,
5551 struct rt2860_softc_rx_ring
*ring
)
5553 struct rt2860_rxdesc
*desc
;
5554 struct rt2860_softc_rx_data
*data
;
5555 bus_dma_segment_t segs
[1];
5556 int i
, nsegs
, error
;
5558 error
= bus_dma_tag_create(bus_get_dma_tag(sc
->dev
), PAGE_SIZE
, 0,
5559 BUS_SPACE_MAXADDR_32BIT
, BUS_SPACE_MAXADDR
, NULL
, NULL
,
5560 RT2860_SOFTC_RX_RING_DATA_COUNT
* sizeof(struct rt2860_rxdesc
), 1,
5561 RT2860_SOFTC_RX_RING_DATA_COUNT
* sizeof(struct rt2860_rxdesc
),
5562 0, NULL
, NULL
, &ring
->desc_dma_tag
);
5565 printf("%s: could not create Rx desc DMA tag\n",
5566 device_get_nameunit(sc
->dev
));
5570 error
= bus_dmamem_alloc(ring
->desc_dma_tag
, (void **) &ring
->desc
,
5571 BUS_DMA_NOWAIT
| BUS_DMA_ZERO
, &ring
->desc_dma_map
);
5574 printf("%s: could not allocate Rx desc DMA memory\n",
5575 device_get_nameunit(sc
->dev
));
5579 error
= bus_dmamap_load(ring
->desc_dma_tag
, ring
->desc_dma_map
,
5581 RT2860_SOFTC_RX_RING_DATA_COUNT
* sizeof(struct rt2860_rxdesc
),
5582 rt2860_dma_map_addr
, &ring
->desc_phys_addr
, 0);
5585 printf("%s: could not load Rx desc DMA map\n",
5586 device_get_nameunit(sc
->dev
));
5590 error
= bus_dma_tag_create(bus_get_dma_tag(sc
->dev
), PAGE_SIZE
, 0,
5591 BUS_SPACE_MAXADDR_32BIT
, BUS_SPACE_MAXADDR
, NULL
, NULL
,
5592 MJUMPAGESIZE
, 1, MJUMPAGESIZE
, 0, NULL
, NULL
,
5593 &ring
->data_dma_tag
);
5596 printf("%s: could not create Rx data DMA tag\n",
5597 device_get_nameunit(sc
->dev
));
5601 for (i
= 0; i
< RT2860_SOFTC_RX_RING_DATA_COUNT
; i
++)
5603 desc
= &ring
->desc
[i
];
5604 data
= &ring
->data
[i
];
5606 error
= bus_dmamap_create(ring
->data_dma_tag
, 0, &data
->dma_map
);
5609 printf("%s: could not create Rx data DMA map\n",
5610 device_get_nameunit(sc
->dev
));
5614 data
->m
= m_getjcl(M_DONTWAIT
, MT_DATA
, M_PKTHDR
, MJUMPAGESIZE
);
5615 if (data
->m
== NULL
)
5617 printf("%s: could not allocate Rx mbuf\n",
5618 device_get_nameunit(sc
->dev
));
5623 data
->m
->m_len
= data
->m
->m_pkthdr
.len
= MJUMPAGESIZE
;
5625 error
= bus_dmamap_load_mbuf_sg(ring
->data_dma_tag
, data
->dma_map
,
5626 data
->m
, segs
, &nsegs
, BUS_DMA_NOWAIT
);
5629 printf("%s: could not load Rx mbuf DMA map\n",
5630 device_get_nameunit(sc
->dev
));
5634 KASSERT(nsegs
== 1, ("%s: too many DMA segments",
5635 device_get_name(sc
->dev
)));
5637 desc
->sdp0
= htole32(segs
[0].ds_addr
);
5638 desc
->sdl0
= htole16(MJUMPAGESIZE
);
5641 error
= bus_dmamap_create(ring
->data_dma_tag
, 0, &ring
->spare_dma_map
);
5644 printf("%s: could not create Rx spare DMA map\n",
5645 device_get_nameunit(sc
->dev
));
5649 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
5650 BUS_DMASYNC_PREWRITE
);
5656 rt2860_free_rx_ring(sc
, ring
);
5662 * rt2860_reset_rx_ring
5664 static void rt2860_reset_rx_ring(struct rt2860_softc
*sc
,
5665 struct rt2860_softc_rx_ring
*ring
)
5667 struct rt2860_rxdesc
*desc
;
5670 for (i
= 0; i
< RT2860_SOFTC_RX_RING_DATA_COUNT
; i
++)
5672 desc
= &ring
->desc
[i
];
5674 desc
->sdl0
&= ~htole16(RT2860_RXDESC_SDL0_DDONE
);
5677 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
5678 BUS_DMASYNC_PREWRITE
);
5684 * rt2860_free_rx_ring
5686 static void rt2860_free_rx_ring(struct rt2860_softc
*sc
,
5687 struct rt2860_softc_rx_ring
*ring
)
5689 struct rt2860_softc_rx_data
*data
;
5692 if (ring
->desc
!= NULL
)
5694 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
5695 BUS_DMASYNC_POSTWRITE
);
5696 bus_dmamap_unload(ring
->desc_dma_tag
, ring
->desc_dma_map
);
5697 bus_dmamem_free(ring
->desc_dma_tag
, ring
->desc
,
5698 ring
->desc_dma_map
);
5701 if (ring
->desc_dma_tag
!= NULL
)
5702 bus_dma_tag_destroy(ring
->desc_dma_tag
);
5704 for (i
= 0; i
< RT2860_SOFTC_RX_RING_DATA_COUNT
; i
++)
5706 data
= &ring
->data
[i
];
5708 if (data
->m
!= NULL
)
5710 bus_dmamap_sync(ring
->data_dma_tag
, data
->dma_map
,
5711 BUS_DMASYNC_POSTREAD
);
5712 bus_dmamap_unload(ring
->data_dma_tag
, data
->dma_map
);
5716 if (data
->dma_map
!= NULL
)
5717 bus_dmamap_destroy(ring
->data_dma_tag
, data
->dma_map
);
5720 if (ring
->spare_dma_map
!= NULL
)
5721 bus_dmamap_destroy(ring
->data_dma_tag
, ring
->spare_dma_map
);
5723 if (ring
->data_dma_tag
!= NULL
)
5724 bus_dma_tag_destroy(ring
->data_dma_tag
);
5728 * rt2860_alloc_tx_ring
5730 static int rt2860_alloc_tx_ring(struct rt2860_softc
*sc
,
5731 struct rt2860_softc_tx_ring
*ring
, int qid
)
5733 struct rt2860_softc_tx_data
*data
;
5736 mtx_init(&ring
->lock
, device_get_nameunit(sc
->dev
), NULL
, MTX_DEF
);
5738 error
= bus_dma_tag_create(bus_get_dma_tag(sc
->dev
), PAGE_SIZE
, 0,
5739 BUS_SPACE_MAXADDR_32BIT
, BUS_SPACE_MAXADDR
, NULL
, NULL
,
5740 RT2860_SOFTC_TX_RING_DESC_COUNT
* sizeof(struct rt2860_txdesc
), 1,
5741 RT2860_SOFTC_TX_RING_DESC_COUNT
* sizeof(struct rt2860_txdesc
),
5742 0, NULL
, NULL
, &ring
->desc_dma_tag
);
5745 printf("%s: could not create Tx desc DMA tag\n",
5746 device_get_nameunit(sc
->dev
));
5750 error
= bus_dmamem_alloc(ring
->desc_dma_tag
, (void **) &ring
->desc
,
5751 BUS_DMA_NOWAIT
| BUS_DMA_ZERO
, &ring
->desc_dma_map
);
5754 printf("%s: could not allocate Tx desc DMA memory\n",
5755 device_get_nameunit(sc
->dev
));
5759 error
= bus_dmamap_load(ring
->desc_dma_tag
, ring
->desc_dma_map
,
5761 RT2860_SOFTC_TX_RING_DESC_COUNT
* sizeof(struct rt2860_txdesc
),
5762 rt2860_dma_map_addr
, &ring
->desc_phys_addr
, 0);
5765 printf("%s: could not load Tx desc DMA map\n",
5766 device_get_nameunit(sc
->dev
));
5770 ring
->desc_queued
= 0;
5772 ring
->desc_next
= 0;
5774 error
= bus_dma_tag_create(bus_get_dma_tag(sc
->dev
), PAGE_SIZE
, 0,
5775 BUS_SPACE_MAXADDR_32BIT
, BUS_SPACE_MAXADDR
, NULL
, NULL
,
5776 RT2860_SOFTC_TX_RING_DATA_COUNT
* RT2860_TX_DATA_SEG0_SIZE
, 1,
5777 RT2860_SOFTC_TX_RING_DATA_COUNT
* RT2860_TX_DATA_SEG0_SIZE
,
5778 0, NULL
, NULL
, &ring
->seg0_dma_tag
);
5781 printf("%s: could not create Tx seg0 DMA tag\n",
5782 device_get_nameunit(sc
->dev
));
5786 error
= bus_dmamem_alloc(ring
->seg0_dma_tag
, (void **) &ring
->seg0
,
5787 BUS_DMA_NOWAIT
| BUS_DMA_ZERO
, &ring
->seg0_dma_map
);
5790 printf("%s: could not allocate Tx seg0 DMA memory\n",
5791 device_get_nameunit(sc
->dev
));
5795 error
= bus_dmamap_load(ring
->seg0_dma_tag
, ring
->seg0_dma_map
,
5797 RT2860_SOFTC_TX_RING_DATA_COUNT
* RT2860_TX_DATA_SEG0_SIZE
,
5798 rt2860_dma_map_addr
, &ring
->seg0_phys_addr
, 0);
5801 printf("%s: could not load Tx seg0 DMA map\n",
5802 device_get_nameunit(sc
->dev
));
5806 error
= bus_dma_tag_create(bus_get_dma_tag(sc
->dev
), PAGE_SIZE
, 0,
5807 BUS_SPACE_MAXADDR_32BIT
, BUS_SPACE_MAXADDR
, NULL
, NULL
,
5808 MJUMPAGESIZE
, RT2860_SOFTC_MAX_SCATTER
, MJUMPAGESIZE
, 0, NULL
, NULL
,
5809 &ring
->data_dma_tag
);
5812 printf("%s: could not create Tx data DMA tag\n",
5813 device_get_nameunit(sc
->dev
));
5817 for (i
= 0; i
< RT2860_SOFTC_TX_RING_DATA_COUNT
; i
++)
5819 data
= &ring
->data
[i
];
5821 error
= bus_dmamap_create(ring
->data_dma_tag
, 0, &data
->dma_map
);
5824 printf("%s: could not create Tx data DMA map\n",
5825 device_get_nameunit(sc
->dev
));
5830 ring
->data_queued
= 0;
5832 ring
->data_next
= 0;
5840 rt2860_free_tx_ring(sc
, ring
);
5846 * rt2860_reset_tx_ring
5848 static void rt2860_reset_tx_ring(struct rt2860_softc
*sc
,
5849 struct rt2860_softc_tx_ring
*ring
)
5851 struct rt2860_softc_tx_data
*data
;
5852 struct rt2860_txdesc
*desc
;
5855 for (i
= 0; i
< RT2860_SOFTC_TX_RING_DESC_COUNT
; i
++)
5857 desc
= &ring
->desc
[i
];
5863 ring
->desc_queued
= 0;
5865 ring
->desc_next
= 0;
5867 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
5868 BUS_DMASYNC_PREWRITE
);
5870 bus_dmamap_sync(ring
->seg0_dma_tag
, ring
->seg0_dma_map
,
5871 BUS_DMASYNC_PREWRITE
);
5873 for (i
= 0; i
< RT2860_SOFTC_TX_RING_DATA_COUNT
; i
++)
5875 data
= &ring
->data
[i
];
5877 if (data
->m
!= NULL
)
5879 bus_dmamap_sync(ring
->data_dma_tag
, data
->dma_map
,
5880 BUS_DMASYNC_POSTWRITE
);
5881 bus_dmamap_unload(ring
->data_dma_tag
, data
->dma_map
);
5886 if (data
->ni
!= NULL
)
5888 ieee80211_free_node(data
->ni
);
5893 ring
->data_queued
= 0;
5895 ring
->data_next
= 0;
5899 * rt2860_free_tx_ring
5901 static void rt2860_free_tx_ring(struct rt2860_softc
*sc
,
5902 struct rt2860_softc_tx_ring
*ring
)
5904 struct rt2860_softc_tx_data
*data
;
5907 if (ring
->desc
!= NULL
)
5909 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
5910 BUS_DMASYNC_POSTWRITE
);
5911 bus_dmamap_unload(ring
->desc_dma_tag
, ring
->desc_dma_map
);
5912 bus_dmamem_free(ring
->desc_dma_tag
, ring
->desc
,
5913 ring
->desc_dma_map
);
5916 if (ring
->desc_dma_tag
!= NULL
)
5917 bus_dma_tag_destroy(ring
->desc_dma_tag
);
5919 if (ring
->seg0
!= NULL
)
5921 bus_dmamap_sync(ring
->seg0_dma_tag
, ring
->seg0_dma_map
,
5922 BUS_DMASYNC_POSTWRITE
);
5923 bus_dmamap_unload(ring
->seg0_dma_tag
, ring
->seg0_dma_map
);
5924 bus_dmamem_free(ring
->seg0_dma_tag
, ring
->seg0
,
5925 ring
->seg0_dma_map
);
5928 if (ring
->seg0_dma_tag
!= NULL
)
5929 bus_dma_tag_destroy(ring
->seg0_dma_tag
);
5931 for (i
= 0; i
< RT2860_SOFTC_TX_RING_DATA_COUNT
; i
++)
5933 data
= &ring
->data
[i
];
5935 if (data
->m
!= NULL
)
5937 bus_dmamap_sync(ring
->data_dma_tag
, data
->dma_map
,
5938 BUS_DMASYNC_POSTWRITE
);
5939 bus_dmamap_unload(ring
->data_dma_tag
, data
->dma_map
);
5943 if (data
->ni
!= NULL
)
5944 ieee80211_free_node(data
->ni
);
5946 if (data
->dma_map
!= NULL
)
5947 bus_dmamap_destroy(ring
->data_dma_tag
, data
->dma_map
);
5950 if (ring
->data_dma_tag
!= NULL
)
5951 bus_dma_tag_destroy(ring
->data_dma_tag
);
5953 mtx_destroy(&ring
->lock
);
5957 * rt2860_dma_map_addr
5959 static void rt2860_dma_map_addr(void *arg
, bus_dma_segment_t
*segs
,
5960 int nseg
, int error
)
5965 KASSERT(nseg
== 1, ("too many DMA segments, %d should be 1", nseg
));
5967 *(bus_addr_t
*) arg
= segs
[0].ds_addr
;
5971 * rt2860_sysctl_attach
5973 static void rt2860_sysctl_attach(struct rt2860_softc
*sc
)
5975 struct sysctl_ctx_list
*ctx
;
5976 struct sysctl_oid
*tree
;
5977 struct sysctl_oid
*stats
;
5979 ctx
= device_get_sysctl_ctx(sc
->dev
);
5980 tree
= device_get_sysctl_tree(sc
->dev
);
5982 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(tree
), OID_AUTO
,
5983 "tx_stbc", CTLFLAG_RW
, &sc
->tx_stbc
, 0,
5986 /* statistic counters */
5988 stats
= SYSCTL_ADD_NODE(ctx
, SYSCTL_CHILDREN(tree
), OID_AUTO
,
5989 "stats", CTLFLAG_RD
, 0, "statistic");
5991 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5992 "interrupts", CTLFLAG_RD
, &sc
->interrupts
, 0,
5995 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5996 "tx_coherent_interrupts", CTLFLAG_RD
, &sc
->tx_coherent_interrupts
, 0,
5997 "Tx coherent interrupts");
5999 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6000 "rx_coherent_interrupts", CTLFLAG_RD
, &sc
->rx_coherent_interrupts
, 0,
6001 "Rx coherent interrupts");
6003 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6004 "txrx_coherent_interrupts", CTLFLAG_RD
, &sc
->txrx_coherent_interrupts
, 0,
6005 "Tx/Rx coherent interrupts");
6007 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6008 "fifo_sta_full_interrupts", CTLFLAG_RD
, &sc
->fifo_sta_full_interrupts
, 0,
6009 "FIFO statistic full interrupts");
6011 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6012 "rx_interrupts", CTLFLAG_RD
, &sc
->rx_interrupts
, 0,
6015 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6016 "rx_delay_interrupts", CTLFLAG_RD
, &sc
->rx_delay_interrupts
, 0,
6017 "Rx delay interrupts");
6019 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6020 "tx_mgmt_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[5], 0,
6021 "Tx MGMT interrupts");
6023 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6024 "tx_hcca_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[4], 0,
6025 "Tx HCCA interrupts");
6027 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6028 "tx_ac3_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[3], 0,
6029 "Tx AC3 interrupts");
6031 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6032 "tx_ac2_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[2], 0,
6033 "Tx AC2 interrupts");
6035 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6036 "tx_ac1_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[1], 0,
6037 "Tx AC1 interrupts");
6039 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6040 "tx_ac0_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[0], 0,
6041 "Tx AC0 interrupts");
6043 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6044 "tx_delay_interrupts", CTLFLAG_RD
, &sc
->tx_delay_interrupts
, 0,
6045 "Tx delay interrupts");
6047 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6048 "pre_tbtt_interrupts", CTLFLAG_RD
, &sc
->pre_tbtt_interrupts
, 0,
6049 "Pre-TBTT interrupts");
6051 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6052 "tbtt_interrupts", CTLFLAG_RD
, &sc
->tbtt_interrupts
, 0,
6055 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6056 "mcu_cmd_interrupts", CTLFLAG_RD
, &sc
->mcu_cmd_interrupts
, 0,
6057 "MCU command interrupts");
6059 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6060 "auto_wakeup_interrupts", CTLFLAG_RD
, &sc
->auto_wakeup_interrupts
, 0,
6061 "auto wakeup interrupts");
6063 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6064 "gp_timer_interrupts", CTLFLAG_RD
, &sc
->gp_timer_interrupts
, 0,
6065 "GP timer interrupts");
6067 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6068 "tx_mgmt_desc_queued", CTLFLAG_RD
, &sc
->tx_ring
[5].desc_queued
, 0,
6069 "Tx MGMT descriptors queued");
6071 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6072 "tx_mgmt_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[5].data_queued
, 0,
6073 "Tx MGMT data queued");
6075 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6076 "tx_hcca_desc_queued", CTLFLAG_RD
, &sc
->tx_ring
[4].desc_queued
, 0,
6077 "Tx HCCA descriptors queued");
6079 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6080 "tx_hcca_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[4].data_queued
, 0,
6081 "Tx HCCA data queued");
6083 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6084 "tx_ac3_desc_queued", CTLFLAG_RD
, &sc
->tx_ring
[3].desc_queued
, 0,
6085 "Tx AC3 descriptors queued");
6087 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6088 "tx_ac3_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[3].data_queued
, 0,
6089 "Tx AC3 data queued");
6091 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6092 "tx_ac2_desc_queued", CTLFLAG_RD
, &sc
->tx_ring
[2].desc_queued
, 0,
6093 "Tx AC2 descriptors queued");
6095 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6096 "tx_ac2_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[2].data_queued
, 0,
6097 "Tx AC2 data queued");
6099 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6100 "tx_ac1_desc_queued", CTLFLAG_RD
, &sc
->tx_ring
[1].desc_queued
, 0,
6101 "Tx AC1 descriptors queued");
6103 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6104 "tx_ac1_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[1].data_queued
, 0,
6105 "Tx AC1 data queued");
6107 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6108 "tx_ac0_desc_queued", CTLFLAG_RD
, &sc
->tx_ring
[0].desc_queued
, 0,
6109 "Tx AC0 descriptors queued");
6111 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6112 "tx_ac0_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[0].data_queued
, 0,
6113 "Tx AC0 data queued");
6115 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6116 "tx_mgmt_data_queue_full", CTLFLAG_RD
, &sc
->tx_data_queue_full
[5], 0,
6117 "Tx MGMT data queue full");
6119 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6120 "tx_hcca_data_queue_full", CTLFLAG_RD
, &sc
->tx_data_queue_full
[4], 0,
6121 "Tx HCCA data queue full");
6123 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6124 "tx_ac3_data_queue_full", CTLFLAG_RD
, &sc
->tx_data_queue_full
[3], 0,
6125 "Tx AC3 data queue full");
6127 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6128 "tx_ac2_data_queue_full", CTLFLAG_RD
, &sc
->tx_data_queue_full
[2], 0,
6129 "Tx AC2 data queue full");
6131 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6132 "tx_ac1_data_queue_full", CTLFLAG_RD
, &sc
->tx_data_queue_full
[1], 0,
6133 "Tx AC1 data queue full");
6135 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6136 "tx_ac0_data_queue_full", CTLFLAG_RD
, &sc
->tx_data_queue_full
[0], 0,
6137 "Tx AC0 data queue full");
6139 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6140 "tx_watchdog_timeouts", CTLFLAG_RD
, &sc
->tx_watchdog_timeouts
, 0,
6141 "Tx watchdog timeouts");
6143 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6144 "tx_defrag_packets", CTLFLAG_RD
, &sc
->tx_defrag_packets
, 0,
6145 "Tx defragmented packets");
6147 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6148 "no_tx_desc_avail", CTLFLAG_RD
, &sc
->no_tx_desc_avail
, 0,
6149 "no Tx descriptors available");
6151 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6152 "rx_mbuf_alloc_errors", CTLFLAG_RD
, &sc
->rx_mbuf_alloc_errors
, 0,
6153 "Rx mbuf allocation errors");
6155 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6156 "rx_mbuf_dmamap_errors", CTLFLAG_RD
, &sc
->rx_mbuf_dmamap_errors
, 0,
6157 "Rx mbuf DMA mapping errors");
6159 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6160 "tx_queue_0_not_empty", CTLFLAG_RD
, &sc
->tx_queue_not_empty
[0], 0,
6161 "Tx queue 0 not empty");
6163 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6164 "tx_queue_1_not_empty", CTLFLAG_RD
, &sc
->tx_queue_not_empty
[1], 0,
6165 "Tx queue 1 not empty");
6167 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6168 "tx_beacons", CTLFLAG_RD
, &sc
->tx_beacons
, 0,
6171 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6172 "tx_noretryok", CTLFLAG_RD
, &sc
->tx_noretryok
, 0,
6173 "Tx successfull without retries");
6175 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6176 "tx_retryok", CTLFLAG_RD
, &sc
->tx_retryok
, 0,
6177 "Tx successfull with retries");
6179 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6180 "tx_failed", CTLFLAG_RD
, &sc
->tx_failed
, 0,
6183 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6184 "tx_underflows", CTLFLAG_RD
, &sc
->tx_underflows
, 0,
6187 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6188 "tx_zerolen", CTLFLAG_RD
, &sc
->tx_zerolen
, 0,
6191 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6192 "tx_nonagg", CTLFLAG_RD
, &sc
->tx_nonagg
, 0,
6193 "Tx non-aggregated");
6195 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6196 "tx_agg", CTLFLAG_RD
, &sc
->tx_agg
, 0,
6199 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6200 "tx_ampdu", CTLFLAG_RD
, &sc
->tx_ampdu
, 0,
6203 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6204 "tx_mpdu_zero_density", CTLFLAG_RD
, &sc
->tx_mpdu_zero_density
, 0,
6205 "Tx MPDU with zero density");
6207 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6208 "tx_ampdu_sessions", CTLFLAG_RD
, &sc
->tx_ampdu_sessions
, 0,
6209 "Tx A-MPDU sessions");
6211 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6212 "rx_packets", CTLFLAG_RD
, &sc
->rx_packets
, 0,
6215 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6216 "rx_ampdu", CTLFLAG_RD
, &sc
->rx_ampdu
, 0,
6219 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6220 "rx_mpdu_zero_density", CTLFLAG_RD
, &sc
->rx_mpdu_zero_density
, 0,
6221 "Rx MPDU with zero density");
6223 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6224 "rx_amsdu", CTLFLAG_RD
, &sc
->rx_amsdu
, 0,
6227 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6228 "rx_crc_errors", CTLFLAG_RD
, &sc
->rx_crc_errors
, 0,
6231 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6232 "rx_phy_errors", CTLFLAG_RD
, &sc
->rx_phy_errors
, 0,
6235 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6236 "rx_false_ccas", CTLFLAG_RD
, &sc
->rx_false_ccas
, 0,
6239 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6240 "rx_plcp_errors", CTLFLAG_RD
, &sc
->rx_plcp_errors
, 0,
6243 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6244 "rx_dup_packets", CTLFLAG_RD
, &sc
->rx_dup_packets
, 0,
6245 "Rx duplicate packets");
6247 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6248 "rx_fifo_overflows", CTLFLAG_RD
, &sc
->rx_fifo_overflows
, 0,
6249 "Rx FIFO overflows");
6251 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6252 "rx_cipher_no_errors", CTLFLAG_RD
, &sc
->rx_cipher_no_errors
, 0,
6253 "Rx cipher no errors");
6255 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6256 "rx_cipher_icv_errors", CTLFLAG_RD
, &sc
->rx_cipher_icv_errors
, 0,
6257 "Rx cipher ICV errors");
6259 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6260 "rx_cipher_mic_errors", CTLFLAG_RD
, &sc
->rx_cipher_mic_errors
, 0,
6261 "Rx cipher MIC errors");
6263 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6264 "rx_cipher_invalid_key_errors", CTLFLAG_RD
, &sc
->rx_cipher_invalid_key_errors
, 0,
6265 "Rx cipher invalid key errors");
6268 static device_method_t rt2860_dev_methods
[] =
6270 DEVMETHOD(device_probe
, rt2860_probe
),
6271 DEVMETHOD(device_attach
, rt2860_attach
),
6272 DEVMETHOD(device_detach
, rt2860_detach
),
6273 DEVMETHOD(device_shutdown
, rt2860_shutdown
),
6274 DEVMETHOD(device_suspend
, rt2860_suspend
),
6275 DEVMETHOD(device_resume
, rt2860_resume
),
6279 static driver_t rt2860_driver
=
6283 sizeof(struct rt2860_softc
)
6286 static devclass_t rt2860_dev_class
;
6288 DRIVER_MODULE(rt2860
, pci
, rt2860_driver
, rt2860_dev_class
, 0, 0);
6290 MODULE_DEPEND(rt2860
, pci
, 1, 1, 1);
6291 MODULE_DEPEND(rt2860
, wlan
, 1, 1, 1);