3 * Copyright (c) 2009-2010 Alexander Egorenkov <egorenar@gmail.com>
4 * Copyright (c) 2009 Damien Bergamini <damien.bergamini@free.fr>
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 #include "rt2860_softc.h"
20 #include "rt2860_reg.h"
21 #include "rt2860_eeprom.h"
22 #include "rt2860_ucode.h"
23 #include "rt2860_txwi.h"
24 #include "rt2860_rxwi.h"
25 #include "rt2860_io.h"
26 #include "rt2860_read_eeprom.h"
27 #include "rt2860_led.h"
28 #include "rt2860_rf.h"
29 #include "rt2860_debug.h"
35 #define PCI_VENDOR_RALINK 0x1814
36 #define PCI_PRODUCT_RALINK_RT2860_PCI 0x0601
37 #define PCI_PRODUCT_RALINK_RT2860_PCIe 0x0681
38 #define PCI_PRODUCT_RALINK_RT2760_PCI 0x0701
39 #define PCI_PRODUCT_RALINK_RT2790_PCIe 0x0781
41 #define RT2860_MAX_AGG_SIZE 3840
43 #define RT2860_TX_DATA_SEG0_SIZE \
44 (sizeof(struct rt2860_txwi) + sizeof(struct ieee80211_qosframe_addr4))
46 #define RT2860_NOISE_FLOOR -95
48 #define RT2860_AID2WCID(aid) ((aid) & 0xff)
50 #define RT2860_ACK_SIZE 14
52 #define IEEE80211_HAS_ADDR4(wh) \
53 (((wh)->i_fc[1] & IEEE80211_FC1_DIR_MASK) == IEEE80211_FC1_DIR_DSTODS)
55 #define RT2860_MS(_v, _f) (((_v) & _f) >> _f##_S)
56 #define RT2860_SM(_v, _f) (((_v) << _f##_S) & _f)
58 #define RT2860_TX_WATCHDOG_TIMEOUT 5
61 * Data structures and types
64 struct rt2860_pci_ident
72 * Static function prototypes
75 static int rt2860_probe(device_t dev
);
77 static int rt2860_attach(device_t dev
);
79 static int rt2860_detach(device_t dev
);
81 static int rt2860_shutdown(device_t dev
);
83 static int rt2860_suspend(device_t dev
);
85 static int rt2860_resume(device_t dev
);
87 static void rt2860_init_channels(struct rt2860_softc
*sc
);
89 static void rt2860_init_channels_ht40(struct rt2860_softc
*sc
);
91 static void rt2860_init_locked(void *priv
);
93 static void rt2860_init(void *priv
);
95 static int rt2860_init_bbp(struct rt2860_softc
*sc
);
97 static void rt2860_stop_locked(void *priv
);
99 static void rt2860_stop(void *priv
);
101 static void rt2860_start(struct ifnet
*ifp
);
103 static int rt2860_ioctl(struct ifnet
*ifp
, u_long cmd
, caddr_t data
);
105 static struct ieee80211vap
*rt2860_vap_create(struct ieee80211com
*ic
,
106 const char name
[IFNAMSIZ
], int unit
, int opmode
, int flags
,
107 const uint8_t bssid
[IEEE80211_ADDR_LEN
],
108 const uint8_t mac
[IEEE80211_ADDR_LEN
]);
110 static void rt2860_vap_delete(struct ieee80211vap
*vap
);
112 static int rt2860_vap_reset(struct ieee80211vap
*vap
, u_long cmd
);
114 static int rt2860_vap_newstate(struct ieee80211vap
*vap
,
115 enum ieee80211_state nstate
, int arg
);
117 static void rt2860_vap_key_update_begin(struct ieee80211vap
*vap
);
119 static void rt2860_vap_key_update_end(struct ieee80211vap
*vap
);
121 static int rt2860_vap_key_set(struct ieee80211vap
*vap
,
122 const struct ieee80211_key
*k
, const uint8_t mac
[IEEE80211_ADDR_LEN
]);
124 static int rt2860_vap_key_delete(struct ieee80211vap
*vap
,
125 const struct ieee80211_key
*k
);
127 static void rt2860_vap_update_beacon(struct ieee80211vap
*vap
, int what
);
129 static int rt2860_media_change(struct ifnet
*ifp
);
131 static struct ieee80211_node
*rt2860_node_alloc(struct ieee80211vap
*vap
,
132 const uint8_t mac
[IEEE80211_ADDR_LEN
]);
134 static void rt2860_node_getmimoinfo(const struct ieee80211_node
*ni
,
135 struct ieee80211_mimo_info
*mi
);
137 static int rt2860_setregdomain(struct ieee80211com
*ic
,
138 struct ieee80211_regdomain
*reg
,
139 int nchans
, struct ieee80211_channel chans
[]);
141 static void rt2860_getradiocaps(struct ieee80211com
*ic
,
142 int maxchans
, int *nchans
, struct ieee80211_channel chans
[]);
144 static void rt2860_scan_start(struct ieee80211com
*ic
);
146 static void rt2860_scan_end(struct ieee80211com
*ic
);
148 static void rt2860_set_channel(struct ieee80211com
*ic
);
150 static void rt2860_newassoc(struct ieee80211_node
*ni
, int isnew
);
152 static void rt2860_updateslot(struct ifnet
*ifp
);
154 static void rt2860_update_promisc(struct ifnet
*ifp
);
156 static void rt2860_update_mcast(struct ifnet
*ifp
);
158 static int rt2860_wme_update(struct ieee80211com
*ic
);
160 static int rt2860_raw_xmit(struct ieee80211_node
*ni
, struct mbuf
*m
,
161 const struct ieee80211_bpf_params
*params
);
163 static int rt2860_recv_action(struct ieee80211_node
*ni
,
164 const struct ieee80211_frame
*wh
,
165 const uint8_t *frm
, const uint8_t *efrm
);
167 static int rt2860_send_action(struct ieee80211_node
*ni
,
168 int cat
, int act
, void *sa
);
170 static void rt2860_amrr_update_iter_func(void *arg
, struct ieee80211_node
*ni
);
172 static void rt2860_periodic(void *arg
);
174 static void rt2860_tx_watchdog(void *arg
);
176 static void rt2860_asic_set_bssid(struct rt2860_softc
*sc
,
177 const uint8_t *bssid
);
179 static void rt2860_asic_set_macaddr(struct rt2860_softc
*sc
,
180 const uint8_t *addr
);
182 static void rt2860_asic_enable_tsf_sync(struct rt2860_softc
*sc
);
184 static void rt2860_asic_disable_tsf_sync(struct rt2860_softc
*sc
);
186 static void rt2860_asic_enable_mrr(struct rt2860_softc
*sc
);
188 static void rt2860_asic_set_txpreamble(struct rt2860_softc
*sc
);
190 static void rt2860_asic_set_basicrates(struct rt2860_softc
*sc
);
192 static void rt2860_asic_update_rtsthreshold(struct rt2860_softc
*sc
);
194 static void rt2860_asic_update_txpower(struct rt2860_softc
*sc
);
196 static void rt2860_asic_update_promisc(struct rt2860_softc
*sc
);
198 static void rt2860_asic_updateprot(struct rt2860_softc
*sc
);
200 static void rt2860_asic_updateslot(struct rt2860_softc
*sc
);
202 static void rt2860_asic_wme_update(struct rt2860_softc
*sc
);
204 static void rt2860_asic_update_beacon(struct rt2860_softc
*sc
,
205 struct ieee80211vap
*vap
);
207 static void rt2860_asic_clear_keytables(struct rt2860_softc
*sc
);
209 static int rt2860_beacon_alloc(struct rt2860_softc
*sc
,
210 struct ieee80211vap
*vap
);
212 static uint8_t rt2860_rxrate(struct rt2860_rxwi
*rxwi
);
214 static uint8_t rt2860_maxrssi_rxpath(struct rt2860_softc
*sc
,
215 const struct rt2860_rxwi
*rxwi
);
217 static int8_t rt2860_rssi2dbm(struct rt2860_softc
*sc
,
218 uint8_t rssi
, uint8_t rxpath
);
220 static uint8_t rt2860_rate2mcs(uint8_t rate
);
222 static int rt2860_tx_mgmt(struct rt2860_softc
*sc
,
223 struct mbuf
*m
, struct ieee80211_node
*ni
, int qid
);
225 static int rt2860_tx_data(struct rt2860_softc
*sc
,
226 struct mbuf
*m
, struct ieee80211_node
*ni
, int qid
);
228 static int rt2860_tx_raw(struct rt2860_softc
*sc
,
229 struct mbuf
*m
, struct ieee80211_node
*ni
,
230 const struct ieee80211_bpf_params
*params
);
232 static void rt2860_intr(void *arg
);
234 static void rt2860_tx_coherent_intr(struct rt2860_softc
*sc
);
236 static void rt2860_rx_coherent_intr(struct rt2860_softc
*sc
);
238 static void rt2860_txrx_coherent_intr(struct rt2860_softc
*sc
);
240 static void rt2860_fifo_sta_full_intr(struct rt2860_softc
*sc
);
242 static void rt2860_rx_intr(struct rt2860_softc
*sc
);
244 static void rt2860_rx_delay_intr(struct rt2860_softc
*sc
);
246 static void rt2860_tx_intr(struct rt2860_softc
*sc
, int qid
);
248 static void rt2860_tx_delay_intr(struct rt2860_softc
*sc
);
250 static void rt2860_pre_tbtt_intr(struct rt2860_softc
*sc
);
252 static void rt2860_tbtt_intr(struct rt2860_softc
*sc
);
254 static void rt2860_mcu_cmd_intr(struct rt2860_softc
*sc
);
256 static void rt2860_auto_wakeup_intr(struct rt2860_softc
*sc
);
258 static void rt2860_gp_timer_intr(struct rt2860_softc
*sc
);
260 static void rt2860_rx_done_task(void *context
, int pending
);
262 static void rt2860_tx_done_task(void *context
, int pending
);
264 static void rt2860_fifo_sta_full_task(void *context
, int pending
);
266 static void rt2860_periodic_task(void *context
, int pending
);
268 static int rt2860_rx_eof(struct rt2860_softc
*sc
, int limit
);
270 static void rt2860_tx_eof(struct rt2860_softc
*sc
,
271 struct rt2860_softc_tx_ring
*ring
);
273 static void rt2860_update_stats(struct rt2860_softc
*sc
);
275 static void rt2860_bbp_tuning(struct rt2860_softc
*sc
);
277 static void rt2860_watchdog(struct rt2860_softc
*sc
);
279 static void rt2860_drain_fifo_stats(struct rt2860_softc
*sc
);
281 static void rt2860_update_raw_counters(struct rt2860_softc
*sc
);
283 static void rt2860_intr_enable(struct rt2860_softc
*sc
, uint32_t intr_mask
);
285 static void rt2860_intr_disable(struct rt2860_softc
*sc
, uint32_t intr_mask
);
287 static int rt2860_txrx_enable(struct rt2860_softc
*sc
);
289 static int rt2860_alloc_rx_ring(struct rt2860_softc
*sc
,
290 struct rt2860_softc_rx_ring
*ring
);
292 static void rt2860_reset_rx_ring(struct rt2860_softc
*sc
,
293 struct rt2860_softc_rx_ring
*ring
);
295 static void rt2860_free_rx_ring(struct rt2860_softc
*sc
,
296 struct rt2860_softc_rx_ring
*ring
);
298 static int rt2860_alloc_tx_ring(struct rt2860_softc
*sc
,
299 struct rt2860_softc_tx_ring
*ring
, int qid
);
301 static void rt2860_reset_tx_ring(struct rt2860_softc
*sc
,
302 struct rt2860_softc_tx_ring
*ring
);
304 static void rt2860_free_tx_ring(struct rt2860_softc
*sc
,
305 struct rt2860_softc_tx_ring
*ring
);
307 static void rt2860_dma_map_addr(void *arg
, bus_dma_segment_t
*segs
,
308 int nseg
, int error
);
310 static void rt2860_sysctl_attach(struct rt2860_softc
*sc
);
316 static const struct rt2860_pci_ident rt2860_pci_ids
[] =
318 { PCI_VENDOR_RALINK
, PCI_PRODUCT_RALINK_RT2860_PCI
, "Ralink RT2860 PCI" },
319 { PCI_VENDOR_RALINK
, PCI_PRODUCT_RALINK_RT2860_PCIe
, "Ralink RT2860 PCIe" },
320 { PCI_VENDOR_RALINK
, PCI_PRODUCT_RALINK_RT2760_PCI
, "Ralink RT2760 PCI" },
321 { PCI_VENDOR_RALINK
, PCI_PRODUCT_RALINK_RT2790_PCIe
, "Ralink RT2790 PCIe" },
331 { RT2860_REG_PBF_BCN_OFFSET0
, 0xf8f0e8e0 },
332 { RT2860_REG_PBF_BCN_OFFSET1
, 0x6f77d0c8 },
333 { RT2860_REG_LEGACY_BASIC_RATE
, 0x0000013f },
334 { RT2860_REG_HT_BASIC_RATE
, 0x00008003 },
335 { RT2860_REG_SYS_CTRL
, 0x00000000 },
336 { RT2860_REG_RX_FILTER_CFG
, 0x00017f97 },
337 { RT2860_REG_BKOFF_SLOT_CFG
, 0x00000209 },
338 { RT2860_REG_TX_SW_CFG0
, 0x00000000 },
339 { RT2860_REG_TX_SW_CFG1
, 0x00080606 },
340 { RT2860_REG_TX_LINK_CFG
, 0x00001020 },
341 { RT2860_REG_TX_TIMEOUT_CFG
, 0x000a2090 },
342 { RT2860_REG_MAX_LEN_CFG
, (1 << 12) | RT2860_MAX_AGG_SIZE
},
343 { RT2860_REG_LED_CFG
, 0x7f031e46 },
344 { RT2860_REG_PBF_MAX_PCNT
, 0x1f3fbf9f },
345 { RT2860_REG_TX_RTY_CFG
, 0x47d01f0f },
346 { RT2860_REG_AUTO_RSP_CFG
, 0x00000013 },
347 { RT2860_REG_TX_CCK_PROT_CFG
, 0x05740003 },
348 { RT2860_REG_TX_OFDM_PROT_CFG
, 0x05740003 },
349 { RT2860_REG_TX_GF20_PROT_CFG
, 0x01744004 },
350 { RT2860_REG_TX_GF40_PROT_CFG
, 0x03f44084 },
351 { RT2860_REG_TX_MM20_PROT_CFG
, 0x01744004 },
352 { RT2860_REG_TX_MM40_PROT_CFG
, 0x03f54084 },
353 { RT2860_REG_TX_TXOP_CTRL_CFG
, 0x0000583f },
354 { RT2860_REG_TX_RTS_CFG
, 0x00092b20 },
355 { RT2860_REG_TX_EXP_ACK_TIME
, 0x002400ca },
356 { RT2860_REG_HCCAPSMP_TXOP_HLDR_ET
, 0x00000002 },
357 { RT2860_REG_XIFS_TIME_CFG
, 0x33a41010 },
358 { RT2860_REG_PWR_PIN_CFG
, 0x00000003 },
359 { RT2860_REG_SCHDMA_WMM_AIFSN_CFG
, 0x00002273 },
360 { RT2860_REG_SCHDMA_WMM_CWMIN_CFG
, 0x00002344 },
361 { RT2860_REG_SCHDMA_WMM_CWMAX_CFG
, 0x000034aa },
364 #define RT2860_DEF_MAC_SIZE (sizeof(rt2860_def_mac) / sizeof(rt2860_def_mac[0]))
389 #define RT2860_DEF_BBP_SIZE (sizeof(rt2860_def_bbp) / sizeof(rt2860_def_bbp[0]))
391 SYSCTL_NODE(_hw
, OID_AUTO
, rt2860
, CTLFLAG_RD
, 0, "RT2860 driver parameters");
394 static int rt2860_debug
= 0;
395 SYSCTL_INT(_hw_rt2860
, OID_AUTO
, debug
, CTLFLAG_RW
, &rt2860_debug
, 0, "rt2860 debug level");
396 TUNABLE_INT("hw.rt2860.debug", &rt2860_debug
);
402 static int rt2860_probe(device_t dev
)
404 const struct rt2860_pci_ident
*ident
;
406 for (ident
= rt2860_pci_ids
; ident
->name
!= NULL
; ident
++)
408 if (pci_get_vendor(dev
) == ident
->vendor
&&
409 pci_get_device(dev
) == ident
->device
)
411 device_set_desc(dev
, ident
->name
);
422 static int rt2860_attach(device_t dev
)
424 struct rt2860_softc
*sc
;
426 struct ieee80211com
*ic
;
427 int error
, ntries
, i
;
429 sc
= device_get_softc(dev
);
431 if (pci_get_powerstate(dev
) != PCI_POWERSTATE_D0
)
433 printf("%s: chip is in D%d power mode, setting to D0\n",
434 device_get_nameunit(dev
), pci_get_powerstate(dev
));
435 pci_set_powerstate(dev
, PCI_POWERSTATE_D0
);
438 /* enable bus-mastering */
440 pci_enable_busmaster(dev
);
444 mtx_init(&sc
->lock
, device_get_nameunit(dev
),
445 MTX_NETWORK_LOCK
, MTX_DEF
| MTX_RECURSE
);
447 sc
->mem_rid
= PCIR_BAR(0);
448 sc
->mem
= bus_alloc_resource_any(dev
, SYS_RES_MEMORY
,
449 &sc
->mem_rid
, RF_ACTIVE
);
452 printf("%s: could not allocate memory resource\n",
453 device_get_nameunit(dev
));
458 sc
->bst
= rman_get_bustag(sc
->mem
);
459 sc
->bsh
= rman_get_bushandle(sc
->mem
);
462 sc
->irq
= bus_alloc_resource_any(dev
, SYS_RES_IRQ
,
463 &sc
->irq_rid
, RF_ACTIVE
| RF_SHAREABLE
);
466 printf("%s: could not allocate interrupt resource\n",
467 device_get_nameunit(dev
));
473 sc
->debug
= rt2860_debug
;
475 SYSCTL_ADD_INT(device_get_sysctl_ctx(dev
),
476 SYSCTL_CHILDREN(device_get_sysctl_tree(dev
)), OID_AUTO
,
477 "debug", CTLFLAG_RW
, &sc
->debug
, 0, "rt2860 debug level");
480 RT2860_DPRINTF(sc
, RT2860_DEBUG_ANY
,
482 device_get_nameunit(sc
->dev
));
484 /* wait for NIC to initialize */
486 for (ntries
= 0; ntries
< 100; ntries
++)
488 sc
->mac_rev
= rt2860_io_mac_read(sc
, RT2860_REG_MAC_CSR0
);
489 if (sc
->mac_rev
!= 0x00000000 && sc
->mac_rev
!= 0xffffffff)
497 printf("%s: timeout waiting for NIC to initialize\n",
498 device_get_nameunit(dev
));
503 rt2860_read_eeprom(sc
);
505 printf("%s: MAC/BBP RT2860 (rev 0x%08x), RF %s\n",
506 device_get_nameunit(sc
->dev
), sc
->mac_rev
,
507 rt2860_rf_name(sc
->rf_rev
));
509 /* allocate Tx and Rx rings */
511 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
513 error
= rt2860_alloc_tx_ring(sc
, &sc
->tx_ring
[i
], i
);
516 printf("%s: could not allocate Tx ring #%d\n",
517 device_get_nameunit(sc
->dev
), i
);
522 sc
->tx_ring_mgtqid
= 5;
524 error
= rt2860_alloc_rx_ring(sc
, &sc
->rx_ring
);
527 printf("%s: could not allocate Rx ring\n",
528 device_get_nameunit(sc
->dev
));
532 callout_init(&sc
->periodic_ch
, 0);
533 callout_init_mtx(&sc
->tx_watchdog_ch
, &sc
->lock
, 0);
535 ifp
= sc
->ifp
= if_alloc(IFT_IEEE80211
);
538 printf("%s: could not if_alloc()\n",
539 device_get_nameunit(sc
->dev
));
546 if_initname(ifp
, "rt2860", device_get_unit(sc
->dev
));
548 ifp
->if_flags
= IFF_BROADCAST
| IFF_SIMPLEX
| IFF_MULTICAST
;
550 ifp
->if_init
= rt2860_init
;
551 ifp
->if_ioctl
= rt2860_ioctl
;
552 ifp
->if_start
= rt2860_start
;
554 IFQ_SET_MAXLEN(&ifp
->if_snd
, IFQ_MAXLEN
);
555 ifp
->if_snd
.ifq_drv_maxlen
= IFQ_MAXLEN
;
556 IFQ_SET_READY(&ifp
->if_snd
);
562 ic
->ic_phytype
= IEEE80211_T_HT
;
563 ic
->ic_opmode
= IEEE80211_M_STA
;
565 ic
->ic_caps
= IEEE80211_C_MONITOR
|
574 IEEE80211_C_SHPREAMBLE
|
581 ic
->ic_cryptocaps
|= IEEE80211_CRYPTO_WEP
|
582 IEEE80211_CRYPTO_TKIP
|
583 IEEE80211_CRYPTO_TKIPMIC
|
584 IEEE80211_CRYPTO_AES_CCM
;
586 ic
->ic_htcaps
= IEEE80211_HTC_HT
|
587 IEEE80211_HTC_AMSDU
| /* A-MSDU Tx */
588 IEEE80211_HTC_AMPDU
| /* A-MPDU Tx */
589 IEEE80211_HTC_SMPS
| /* MIMO power save */
590 IEEE80211_HTCAP_MAXAMSDU_3839
| /* max. A-MSDU Rx length */
591 IEEE80211_HTCAP_CHWIDTH40
| /* HT 40MHz channel width */
592 IEEE80211_HTCAP_GREENFIELD
| /* HT greenfield */
593 IEEE80211_HTCAP_SHORTGI20
| /* HT 20MHz short GI */
594 IEEE80211_HTCAP_SHORTGI40
| /* HT 40MHz short GI */
595 IEEE80211_HTCAP_SMPS_OFF
; /* MIMO power save disabled */
597 /* spatial streams */
599 if (sc
->nrxpath
== 2)
600 ic
->ic_htcaps
|= IEEE80211_HTCAP_RXSTBC_2STREAM
;
601 else if (sc
->nrxpath
== 3)
602 ic
->ic_htcaps
|= IEEE80211_HTCAP_RXSTBC_3STREAM
;
604 ic
->ic_htcaps
|= IEEE80211_HTCAP_RXSTBC_1STREAM
;
607 ic
->ic_htcaps
|= IEEE80211_HTCAP_TXSTBC
;
611 if (sc
->mac_rev
!= 0x28600100)
612 ic
->ic_htcaps
|= IEEE80211_HTCAP_DELBA
;
618 rt2860_init_channels(sc
);
620 rt2860_init_channels_ht40(sc
);
622 ieee80211_ifattach(ic
, sc
->mac_addr
);
624 ic
->ic_vap_create
= rt2860_vap_create
;
625 ic
->ic_vap_delete
= rt2860_vap_delete
;
627 ic
->ic_node_alloc
= rt2860_node_alloc
;
628 ic
->ic_node_getmimoinfo
= rt2860_node_getmimoinfo
;
629 ic
->ic_setregdomain
= rt2860_setregdomain
;
630 ic
->ic_getradiocaps
= rt2860_getradiocaps
;
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_update_promisc
= rt2860_update_promisc
;
637 ic
->ic_update_mcast
= rt2860_update_mcast
;
638 ic
->ic_wme
.wme_update
= rt2860_wme_update
;
639 ic
->ic_raw_xmit
= rt2860_raw_xmit
;
641 sc
->recv_action
= ic
->ic_recv_action
;
642 ic
->ic_recv_action
= rt2860_recv_action
;
644 sc
->send_action
= ic
->ic_send_action
;
645 ic
->ic_send_action
= rt2860_send_action
;
647 /* hardware requires padding between 802.11 frame header and body */
649 ic
->ic_flags
|= IEEE80211_F_DATAPAD
| IEEE80211_F_DOTH
;
651 ic
->ic_flags_ext
|= IEEE80211_FEXT_SWBMISS
;
653 ieee80211_radiotap_attach(ic
,
654 &sc
->txtap
.ihdr
, sizeof(sc
->txtap
),
655 RT2860_SOFTC_TX_RADIOTAP_PRESENT
,
656 &sc
->rxtap
.ihdr
, sizeof(sc
->rxtap
),
657 RT2860_SOFTC_RX_RADIOTAP_PRESENT
);
659 /* init task queue */
661 TASK_INIT(&sc
->rx_done_task
, 0, rt2860_rx_done_task
, sc
);
662 TASK_INIT(&sc
->tx_done_task
, 0, rt2860_tx_done_task
, sc
);
663 TASK_INIT(&sc
->fifo_sta_full_task
, 0, rt2860_fifo_sta_full_task
, sc
);
664 TASK_INIT(&sc
->periodic_task
, 0, rt2860_periodic_task
, sc
);
666 sc
->rx_process_limit
= 100;
668 sc
->taskqueue
= taskqueue_create("rt2860_taskq", M_NOWAIT
,
669 taskqueue_thread_enqueue
, &sc
->taskqueue
);
671 taskqueue_start_threads(&sc
->taskqueue
, 1, PI_NET
, "%s taskq",
672 device_get_nameunit(sc
->dev
));
674 rt2860_sysctl_attach(sc
);
677 ieee80211_announce(ic
);
679 /* set up interrupt */
681 error
= bus_setup_intr(dev
, sc
->irq
, INTR_TYPE_NET
| INTR_MPSAFE
,
682 NULL
, rt2860_intr
, sc
, &sc
->irqh
);
685 printf("%s: could not set up interrupt\n",
686 device_get_nameunit(dev
));
694 /* free Tx and Rx rings */
696 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
697 rt2860_free_tx_ring(sc
, &sc
->tx_ring
[i
]);
699 rt2860_free_rx_ring(sc
, &sc
->rx_ring
);
701 mtx_destroy(&sc
->lock
);
704 bus_release_resource(dev
, SYS_RES_MEMORY
, sc
->mem_rid
, sc
->mem
);
707 bus_release_resource(dev
, SYS_RES_IRQ
, sc
->irq_rid
, sc
->irq
);
715 static int rt2860_detach(device_t dev
)
717 struct rt2860_softc
*sc
;
719 struct ieee80211com
*ic
;
722 sc
= device_get_softc(dev
);
726 RT2860_DPRINTF(sc
, RT2860_DEBUG_ANY
,
728 device_get_nameunit(sc
->dev
));
730 RT2860_SOFTC_LOCK(sc
);
732 ifp
->if_drv_flags
&= ~(IFF_DRV_RUNNING
| IFF_DRV_OACTIVE
);
734 callout_stop(&sc
->periodic_ch
);
735 callout_stop(&sc
->tx_watchdog_ch
);
737 taskqueue_drain(sc
->taskqueue
, &sc
->rx_done_task
);
738 taskqueue_drain(sc
->taskqueue
, &sc
->tx_done_task
);
739 taskqueue_drain(sc
->taskqueue
, &sc
->fifo_sta_full_task
);
740 taskqueue_drain(sc
->taskqueue
, &sc
->periodic_task
);
742 /* free Tx and Rx rings */
744 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
745 rt2860_free_tx_ring(sc
, &sc
->tx_ring
[i
]);
747 rt2860_free_rx_ring(sc
, &sc
->rx_ring
);
749 RT2860_SOFTC_UNLOCK(sc
);
751 ieee80211_ifdetach(ic
);
755 taskqueue_free(sc
->taskqueue
);
757 mtx_destroy(&sc
->lock
);
759 bus_generic_detach(dev
);
761 bus_teardown_intr(dev
, sc
->irq
, sc
->irqh
);
763 bus_release_resource(dev
, SYS_RES_IRQ
, sc
->irq_rid
, sc
->irq
);
765 bus_release_resource(dev
, SYS_RES_MEMORY
, sc
->mem_rid
, sc
->mem
);
773 static int rt2860_shutdown(device_t dev
)
775 struct rt2860_softc
*sc
;
777 sc
= device_get_softc(dev
);
779 RT2860_DPRINTF(sc
, RT2860_DEBUG_ANY
,
780 "%s: shutting down\n",
781 device_get_nameunit(sc
->dev
));
785 sc
->flags
&= ~RT2860_SOFTC_FLAGS_UCODE_LOADED
;
793 static int rt2860_suspend(device_t dev
)
795 struct rt2860_softc
*sc
;
797 sc
= device_get_softc(dev
);
799 RT2860_DPRINTF(sc
, RT2860_DEBUG_ANY
,
801 device_get_nameunit(sc
->dev
));
805 sc
->flags
&= ~RT2860_SOFTC_FLAGS_UCODE_LOADED
;
813 static int rt2860_resume(device_t dev
)
815 struct rt2860_softc
*sc
;
818 sc
= device_get_softc(dev
);
821 RT2860_DPRINTF(sc
, RT2860_DEBUG_ANY
,
823 device_get_nameunit(sc
->dev
));
825 if (ifp
->if_flags
& IFF_UP
)
832 * rt2860_init_channels
834 static void rt2860_init_channels(struct rt2860_softc
*sc
)
837 struct ieee80211com
*ic
;
838 struct ieee80211_channel
*c
;
844 /* set supported channels for 2GHz band */
846 for (i
= 1; i
<= 14; i
++)
848 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
849 flags
= IEEE80211_CHAN_B
;
851 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
855 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
856 flags
= IEEE80211_CHAN_B
| IEEE80211_CHAN_HT20
;
858 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
862 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
863 flags
= IEEE80211_CHAN_G
;
865 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
869 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
870 flags
= IEEE80211_CHAN_G
| IEEE80211_CHAN_HT20
;
872 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
877 /* set supported channels for 5GHz band */
879 if (sc
->rf_rev
== RT2860_EEPROM_RF_2850
||
880 sc
->rf_rev
== RT2860_EEPROM_RF_2750
)
882 for (i
= 36; i
<= 64; i
+= 4)
884 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
885 flags
= IEEE80211_CHAN_A
;
887 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
891 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
892 flags
= IEEE80211_CHAN_A
| IEEE80211_CHAN_HT20
;
894 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
899 for (i
= 100; i
<= 140; i
+= 4)
901 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
902 flags
= IEEE80211_CHAN_A
;
904 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
908 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
909 flags
= IEEE80211_CHAN_A
| IEEE80211_CHAN_HT20
;
911 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
916 for (i
= 149; i
<= 165; i
+= 4)
918 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
919 flags
= IEEE80211_CHAN_A
;
921 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
925 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
926 flags
= IEEE80211_CHAN_A
| IEEE80211_CHAN_HT20
;
928 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
936 * rt2860_init_channels_ht40
938 static void rt2860_init_channels_ht40(struct rt2860_softc
*sc
)
941 struct ieee80211com
*ic
;
942 struct ieee80211_channel
*c
, *cent
, *ext
;
948 /* set supported channels for 2GHz band */
950 for (i
= 1; i
<= 14; i
++)
952 flags
= IEEE80211_CHAN_G
| IEEE80211_CHAN_HT40
;
954 /* find the center channel */
956 cent
= ieee80211_find_channel_byieee(ic
, i
,
957 flags
& ~IEEE80211_CHAN_HT
);
960 printf("%s: skip channel %d, could not find center channel\n",
961 device_get_nameunit(sc
->dev
), i
);
965 /* find the extension channel */
967 ext
= ieee80211_find_channel(ic
, cent
->ic_freq
+ 20,
968 flags
& ~IEEE80211_CHAN_HT
);
971 printf("%s: skip channel %d, could not find extension channel\n",
972 device_get_nameunit(sc
->dev
), i
);
976 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
979 c
->ic_extieee
= ext
->ic_ieee
;
980 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
981 c
->ic_flags
|= IEEE80211_CHAN_HT40U
;
983 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
986 c
->ic_extieee
= cent
->ic_ieee
;
987 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
988 c
->ic_flags
|= IEEE80211_CHAN_HT40D
;
991 /* set supported channels for 5GHz band */
993 if (sc
->rf_rev
== RT2860_EEPROM_RF_2850
||
994 sc
->rf_rev
== RT2860_EEPROM_RF_2750
)
996 for (i
= 36; i
<= 64; i
+= 4)
998 flags
= IEEE80211_CHAN_A
| IEEE80211_CHAN_HT40
;
1000 /* find the center channel */
1002 cent
= ieee80211_find_channel_byieee(ic
, i
,
1003 flags
& ~IEEE80211_CHAN_HT
);
1006 printf("%s: skip channel %d, could not find center channel\n",
1007 device_get_nameunit(sc
->dev
), i
);
1011 /* find the extension channel */
1013 ext
= ieee80211_find_channel(ic
, cent
->ic_freq
+ 20,
1014 flags
& ~IEEE80211_CHAN_HT
);
1017 printf("%s: skip channel %d, could not find extension channel\n",
1018 device_get_nameunit(sc
->dev
), i
);
1022 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1025 c
->ic_extieee
= ext
->ic_ieee
;
1026 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1027 c
->ic_flags
|= IEEE80211_CHAN_HT40U
;
1029 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1032 c
->ic_extieee
= cent
->ic_ieee
;
1033 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1034 c
->ic_flags
|= IEEE80211_CHAN_HT40D
;
1037 for (i
= 100; i
<= 140; i
+= 4)
1039 flags
= IEEE80211_CHAN_A
| IEEE80211_CHAN_HT40
;
1041 /* find the center channel */
1043 cent
= ieee80211_find_channel_byieee(ic
, i
,
1044 flags
& ~IEEE80211_CHAN_HT
);
1047 printf("%s: skip channel %d, could not find center channel\n",
1048 device_get_nameunit(sc
->dev
), i
);
1052 /* find the extension channel */
1054 ext
= ieee80211_find_channel(ic
, cent
->ic_freq
+ 20,
1055 flags
& ~IEEE80211_CHAN_HT
);
1058 printf("%s: skip channel %d, could not find extension channel\n",
1059 device_get_nameunit(sc
->dev
), i
);
1063 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1066 c
->ic_extieee
= ext
->ic_ieee
;
1067 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1068 c
->ic_flags
|= IEEE80211_CHAN_HT40U
;
1070 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1073 c
->ic_extieee
= cent
->ic_ieee
;
1074 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1075 c
->ic_flags
|= IEEE80211_CHAN_HT40D
;
1078 for (i
= 149; i
<= 165; i
+= 4)
1080 flags
= IEEE80211_CHAN_A
| IEEE80211_CHAN_HT40
;
1082 /* find the center channel */
1084 cent
= ieee80211_find_channel_byieee(ic
, i
,
1085 flags
& ~IEEE80211_CHAN_HT
);
1088 printf("%s: skip channel %d, could not find center channel\n",
1089 device_get_nameunit(sc
->dev
), i
);
1093 /* find the extension channel */
1095 ext
= ieee80211_find_channel(ic
, cent
->ic_freq
+ 20,
1096 flags
& ~IEEE80211_CHAN_HT
);
1099 printf("%s: skip channel %d, could not find extension channel\n",
1100 device_get_nameunit(sc
->dev
), i
);
1104 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1107 c
->ic_extieee
= ext
->ic_ieee
;
1108 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1109 c
->ic_flags
|= IEEE80211_CHAN_HT40U
;
1111 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1114 c
->ic_extieee
= cent
->ic_ieee
;
1115 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1116 c
->ic_flags
|= IEEE80211_CHAN_HT40D
;
1122 * rt2860_init_locked
1124 static void rt2860_init_locked(void *priv
)
1126 struct rt2860_softc
*sc
;
1128 struct ieee80211com
*ic
;
1129 int error
, i
, ntries
;
1130 uint32_t tmp
, stacnt
[6];
1136 RT2860_DPRINTF(sc
, RT2860_DEBUG_ANY
,
1137 "%s: initializing\n",
1138 device_get_nameunit(sc
->dev
));
1140 RT2860_SOFTC_ASSERT_LOCKED(sc
);
1142 if (!(sc
->flags
& RT2860_SOFTC_FLAGS_UCODE_LOADED
))
1144 RT2860_DPRINTF(sc
, RT2860_DEBUG_ANY
,
1145 "%s: loading 8051 microcode\n",
1146 device_get_nameunit(sc
->dev
));
1148 error
= rt2860_io_mcu_load_ucode(sc
, rt2860_ucode
, sizeof(rt2860_ucode
));
1151 printf("%s: could not load 8051 microcode\n",
1152 device_get_nameunit(sc
->dev
));
1156 RT2860_DPRINTF(sc
, RT2860_DEBUG_ANY
,
1157 "%s: 8051 microcode was successfully loaded\n",
1158 device_get_nameunit(sc
->dev
));
1160 sc
->flags
|= RT2860_SOFTC_FLAGS_UCODE_LOADED
;
1163 rt2860_io_mac_write(sc
, RT2860_REG_PWR_PIN_CFG
, 0x2);
1165 /* disable DMA engine */
1167 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
);
1170 tmp
|= RT2860_REG_TX_WB_DDONE
;
1172 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
, tmp
);
1174 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WPDMA_RST_IDX
, 0xffffffff);
1176 /* PBF hardware reset */
1178 rt2860_io_mac_write(sc
, RT2860_REG_PBF_SYS_CTRL
, 0xe1f);
1179 rt2860_io_mac_write(sc
, RT2860_REG_PBF_SYS_CTRL
, 0xe00);
1181 /* wait while DMA engine is busy */
1183 for (ntries
= 0; ntries
< 100; ntries
++)
1185 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
);
1186 if (!(tmp
& (RT2860_REG_TX_DMA_BUSY
| RT2860_REG_RX_DMA_BUSY
)))
1194 printf("%s: timeout waiting for DMA engine\n",
1195 device_get_nameunit(sc
->dev
));
1200 tmp
|= RT2860_REG_TX_WB_DDONE
;
1202 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
, tmp
);
1204 /* reset Rx and Tx rings */
1206 tmp
= RT2860_REG_RST_IDX_RX
|
1207 RT2860_REG_RST_IDX_TX_MGMT
|
1208 RT2860_REG_RST_IDX_TX_HCCA
|
1209 RT2860_REG_RST_IDX_TX_AC3
|
1210 RT2860_REG_RST_IDX_TX_AC2
|
1211 RT2860_REG_RST_IDX_TX_AC1
|
1212 RT2860_REG_RST_IDX_TX_AC0
;
1214 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WPDMA_RST_IDX
, tmp
);
1216 /* PBF hardware reset */
1218 rt2860_io_mac_write(sc
, RT2860_REG_PBF_SYS_CTRL
, 0xe1f);
1219 rt2860_io_mac_write(sc
, RT2860_REG_PBF_SYS_CTRL
, 0xe00);
1221 rt2860_io_mac_write(sc
, RT2860_REG_PWR_PIN_CFG
, 0x3);
1223 rt2860_io_mac_write(sc
, RT2860_REG_SYS_CTRL
,
1224 RT2860_REG_MAC_SRST
| RT2860_REG_BBP_HRST
);
1225 rt2860_io_mac_write(sc
, RT2860_REG_SYS_CTRL
, 0);
1227 /* init Tx power per rate */
1229 for (i
= 0; i
< RT2860_SOFTC_TXPOW_RATE_COUNT
; i
++)
1231 if (sc
->txpow_rate_20mhz
[i
] == 0xffffffff)
1234 rt2860_io_mac_write(sc
, RT2860_REG_TX_PWR_CFG(i
),
1235 sc
->txpow_rate_20mhz
[i
]);
1238 for (i
= 0; i
< RT2860_DEF_MAC_SIZE
; i
++)
1239 rt2860_io_mac_write(sc
, rt2860_def_mac
[i
].reg
,
1240 rt2860_def_mac
[i
].val
);
1242 /* wait while MAC is busy */
1244 for (ntries
= 0; ntries
< 100; ntries
++)
1246 if (!(rt2860_io_mac_read(sc
, RT2860_REG_STATUS_CFG
) &
1247 (RT2860_REG_STATUS_TX_BUSY
| RT2860_REG_STATUS_RX_BUSY
)))
1255 printf("%s: timeout waiting for MAC\n",
1256 device_get_nameunit(sc
->dev
));
1260 /* clear Host to MCU mailbox */
1262 rt2860_io_mac_write(sc
, RT2860_REG_H2M_MAILBOX_BBP_AGENT
, 0);
1263 rt2860_io_mac_write(sc
, RT2860_REG_H2M_MAILBOX
, 0);
1265 rt2860_io_mcu_cmd(sc
, RT2860_IO_MCU_CMD_BOOT
,
1266 RT2860_REG_H2M_TOKEN_NO_INTR
, 0);
1270 error
= rt2860_init_bbp(sc
);
1274 /* set up maximum buffer sizes */
1276 tmp
= (1 << 12) | RT2860_MAX_AGG_SIZE
;
1278 rt2860_io_mac_write(sc
, RT2860_REG_MAX_LEN_CFG
, tmp
);
1280 if (sc
->mac_rev
== 0x28720200)
1282 /* set max. PSDU length from 16K to 32K bytes */
1284 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_MAX_LEN_CFG
);
1289 rt2860_io_mac_write(sc
, RT2860_REG_MAX_LEN_CFG
, tmp
);
1292 if (sc
->mac_rev
>= 0x28720200 && sc
->mac_rev
< 0x30700200)
1294 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_MAX_LEN_CFG
);
1299 rt2860_io_mac_write(sc
, RT2860_REG_MAX_LEN_CFG
, tmp
);
1302 /* set mac address */
1304 rt2860_asic_set_macaddr(sc
, IF_LLADDR(ifp
));
1306 /* clear statistic registers */
1308 rt2860_io_mac_read_multi(sc
, RT2860_REG_RX_STA_CNT0
,
1309 stacnt
, sizeof(stacnt
));
1311 /* set RTS threshold */
1313 rt2860_asic_update_rtsthreshold(sc
);
1317 rt2860_asic_update_txpower(sc
);
1319 /* set up protection mode */
1321 sc
->tx_ampdu_sessions
= 0;
1323 rt2860_asic_updateprot(sc
);
1325 /* clear beacon frame space (entries = 8, entry size = 512) */
1327 rt2860_io_mac_set_region_4(sc
, RT2860_REG_BEACON_BASE(0), 0, 1024);
1329 taskqueue_unblock(sc
->taskqueue
);
1331 /* init Tx rings (4 EDCAs + HCCA + MGMT) */
1333 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
1334 rt2860_reset_tx_ring(sc
, &sc
->tx_ring
[i
]);
1336 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
1338 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_BASE_PTR(i
),
1339 sc
->tx_ring
[i
].desc_phys_addr
);
1340 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_MAX_CNT(i
),
1341 RT2860_SOFTC_TX_RING_DESC_COUNT
);
1342 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_CTX_IDX(i
), 0);
1347 rt2860_reset_rx_ring(sc
, &sc
->rx_ring
);
1349 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_BASE_PTR
,
1350 sc
->rx_ring
.desc_phys_addr
);
1351 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_MAX_CNT
,
1352 RT2860_SOFTC_RX_RING_DATA_COUNT
);
1353 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_CALC_IDX
,
1354 RT2860_SOFTC_RX_RING_DATA_COUNT
- 1);
1356 /* wait while DMA engine is busy */
1358 for (ntries
= 0; ntries
< 100; ntries
++)
1360 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
);
1361 if (!(tmp
& (RT2860_REG_TX_DMA_BUSY
| RT2860_REG_RX_DMA_BUSY
)))
1369 printf("%s: timeout waiting for DMA engine\n",
1370 device_get_nameunit(sc
->dev
));
1375 tmp
|= RT2860_REG_TX_WB_DDONE
;
1377 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
, tmp
);
1379 /* disable interrupts mitigation */
1381 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_DELAY_INT_CFG
, 0);
1383 /* send LEDs operating mode to microcontroller */
1385 rt2860_io_mcu_cmd(sc
, RT2860_IO_MCU_CMD_LED1
,
1386 RT2860_REG_H2M_TOKEN_NO_INTR
, sc
->led_off
[0]);
1387 rt2860_io_mcu_cmd(sc
, RT2860_IO_MCU_CMD_LED2
,
1388 RT2860_REG_H2M_TOKEN_NO_INTR
, sc
->led_off
[1]);
1389 rt2860_io_mcu_cmd(sc
, RT2860_IO_MCU_CMD_LED3
,
1390 RT2860_REG_H2M_TOKEN_NO_INTR
, sc
->led_off
[2]);
1392 /* turn radio LED on */
1394 rt2860_led_cmd(sc
, RT2860_LED_CMD_RADIO_ON
);
1396 /* write vendor-specific BBP values (from EEPROM) */
1398 for (i
= 0; i
< RT2860_SOFTC_BBP_EEPROM_COUNT
; i
++)
1400 if (sc
->bbp_eeprom
[i
].reg
== 0x00 ||
1401 sc
->bbp_eeprom
[i
].reg
== 0xff)
1404 rt2860_io_bbp_write(sc
, sc
->bbp_eeprom
[i
].reg
,
1405 sc
->bbp_eeprom
[i
].val
);
1409 tmp = rt2860_io_mac_read(sc, RT2860_REG_SCHDMA_GPIO_CTRL_CFG);
1412 rt2860_io_mcu_cmd(sc, RT2860_IO_MCU_CMD_SLEEP,
1413 RT2860_REG_H2M_TOKEN_RADIOOFF, 0x02ff);
1414 rt2860_io_mcu_cmd_check(sc, RT2860_REG_H2M_TOKEN_RADIOOFF);
1416 rt2860_io_mcu_cmd(sc, RT2860_IO_MCU_CMD_WAKEUP,
1417 RT2860_REG_H2M_TOKEN_WAKEUP, 0);
1418 rt2860_io_mcu_cmd_check(sc, RT2860_REG_H2M_TOKEN_WAKEUP);
1422 /* disable non-existing Rx chains */
1424 tmp
= rt2860_io_bbp_read(sc
, 3);
1426 tmp
&= ~((1 << 4) | (1 << 3));
1428 if (sc
->nrxpath
== 3)
1430 else if (sc
->nrxpath
== 2)
1433 rt2860_io_bbp_write(sc
, 3, tmp
);
1435 /* disable non-existing Tx chains */
1437 tmp
= rt2860_io_bbp_read(sc
, 1);
1439 tmp
&= ~((1 << 4) | (1 << 3));
1441 if (sc
->ntxpath
== 2)
1444 rt2860_io_bbp_write(sc
, 1, tmp
);
1446 /* set current channel */
1448 rt2860_rf_set_chan(sc
, ic
->ic_curchan
);
1450 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WMM_TXOP0_CFG
, 0);
1451 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WMM_TXOP1_CFG
,
1454 if ((sc
->mac_rev
& 0xffff) != 0x0101)
1455 rt2860_io_mac_write(sc
, RT2860_REG_TX_TXOP_CTRL_CFG
, 0x583f);
1457 /* clear pending interrupts */
1459 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_INT_STATUS
, 0xffffffff);
1461 /* enable interrupts */
1463 tmp
= RT2860_REG_INT_TX_COHERENT
|
1464 RT2860_REG_INT_RX_COHERENT
|
1465 RT2860_REG_INT_GP_TIMER
|
1466 RT2860_REG_INT_AUTO_WAKEUP
|
1467 RT2860_REG_INT_FIFO_STA_FULL
|
1469 RT2860_REG_INT_PRE_TBTT |
1470 RT2860_REG_INT_TBTT |
1472 RT2860_REG_INT_TXRX_COHERENT
|
1473 RT2860_REG_INT_MCU_CMD
|
1474 RT2860_REG_INT_TX_MGMT_DONE
|
1475 RT2860_REG_INT_TX_HCCA_DONE
|
1476 RT2860_REG_INT_TX_AC3_DONE
|
1477 RT2860_REG_INT_TX_AC2_DONE
|
1478 RT2860_REG_INT_TX_AC1_DONE
|
1479 RT2860_REG_INT_TX_AC0_DONE
|
1480 RT2860_REG_INT_RX_DONE
;
1482 sc
->intr_enable_mask
= tmp
;
1484 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_INT_MASK
, tmp
);
1486 if (rt2860_txrx_enable(sc
) != 0)
1489 /* clear garbage interrupts */
1491 tmp
= rt2860_io_mac_read(sc
, 0x1300);
1493 ifp
->if_drv_flags
&= ~IFF_DRV_OACTIVE
;
1494 ifp
->if_drv_flags
|= IFF_DRV_RUNNING
;
1496 sc
->periodic_round
= 0;
1498 callout_reset(&sc
->periodic_ch
, hz
/ 10, rt2860_periodic
, sc
);
1504 rt2860_stop_locked(sc
);
1510 static void rt2860_init(void *priv
)
1512 struct rt2860_softc
*sc
;
1516 RT2860_SOFTC_LOCK(sc
);
1518 rt2860_init_locked(sc
);
1520 RT2860_SOFTC_UNLOCK(sc
);
1526 static int rt2860_init_bbp(struct rt2860_softc
*sc
)
1531 for (ntries
= 0; ntries
< 20; ntries
++)
1533 tmp
= rt2860_io_bbp_read(sc
, 0);
1534 if (tmp
!= 0x00 && tmp
!= 0xff)
1538 if (tmp
== 0x00 || tmp
== 0xff)
1540 printf("%s: timeout waiting for BBP to wakeup\n",
1541 device_get_nameunit(sc
->dev
));
1545 for (i
= 0; i
< RT2860_DEF_BBP_SIZE
; i
++)
1546 rt2860_io_bbp_write(sc
, rt2860_def_bbp
[i
].reg
,
1547 rt2860_def_bbp
[i
].val
);
1549 if ((sc
->mac_rev
& 0xffff) != 0x0101)
1550 rt2860_io_bbp_write(sc
, 84, 0x19);
1552 if (sc
->mac_rev
== 0x28600100)
1554 rt2860_io_bbp_write(sc
, 69, 0x16);
1555 rt2860_io_bbp_write(sc
, 73, 0x12);
1562 * rt2860_stop_locked
1564 static void rt2860_stop_locked(void *priv
)
1566 struct rt2860_softc
*sc
;
1568 struct ieee80211com
*ic
;
1575 RT2860_DPRINTF(sc
, RT2860_DEBUG_ANY
,
1577 device_get_nameunit(sc
->dev
));
1579 RT2860_SOFTC_ASSERT_LOCKED(sc
);
1583 if (ifp
->if_drv_flags
& IFF_DRV_RUNNING
)
1584 rt2860_led_cmd(sc
, RT2860_LED_CMD_RADIO_OFF
);
1586 ifp
->if_drv_flags
&= ~(IFF_DRV_RUNNING
| IFF_DRV_OACTIVE
);
1588 callout_stop(&sc
->periodic_ch
);
1589 callout_stop(&sc
->tx_watchdog_ch
);
1591 RT2860_SOFTC_UNLOCK(sc
);
1593 taskqueue_block(sc
->taskqueue
);
1595 taskqueue_drain(sc
->taskqueue
, &sc
->rx_done_task
);
1596 taskqueue_drain(sc
->taskqueue
, &sc
->tx_done_task
);
1597 taskqueue_drain(sc
->taskqueue
, &sc
->fifo_sta_full_task
);
1598 taskqueue_drain(sc
->taskqueue
, &sc
->periodic_task
);
1600 RT2860_SOFTC_LOCK(sc
);
1602 /* clear key tables */
1604 rt2860_asic_clear_keytables(sc
);
1606 /* disable interrupts */
1608 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_INT_MASK
, 0);
1612 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_SYS_CTRL
);
1614 tmp
&= ~(RT2860_REG_RX_ENABLE
| RT2860_REG_TX_ENABLE
);
1616 rt2860_io_mac_write(sc
, RT2860_REG_SYS_CTRL
, tmp
);
1620 rt2860_io_mac_write(sc
, RT2860_REG_SYS_CTRL
,
1621 RT2860_REG_MAC_SRST
| RT2860_REG_BBP_HRST
);
1622 rt2860_io_mac_write(sc
, RT2860_REG_SYS_CTRL
, 0);
1628 static void rt2860_stop(void *priv
)
1630 struct rt2860_softc
*sc
;
1634 RT2860_SOFTC_LOCK(sc
);
1636 rt2860_stop_locked(sc
);
1638 RT2860_SOFTC_UNLOCK(sc
);
1644 static void rt2860_start(struct ifnet
*ifp
)
1646 struct rt2860_softc
*sc
;
1647 struct ieee80211_node
*ni
;
1653 RT2860_SOFTC_LOCK(sc
);
1655 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
1657 RT2860_SOFTC_UNLOCK(sc
);
1663 IF_POLL(&ifp
->if_snd
, m
);
1667 IFQ_DRV_DEQUEUE(&ifp
->if_snd
, m
);
1669 ni
= (struct ieee80211_node
*) m
->m_pkthdr
.rcvif
;
1671 qid
= M_WME_GETAC(m
);
1673 if (sc
->tx_ring
[qid
].data_queued
>= RT2860_SOFTC_TX_RING_DATA_COUNT
)
1675 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
1676 "%s: if_start: Tx ring with qid=%d is full\n",
1677 device_get_nameunit(sc
->dev
), qid
);
1680 ieee80211_free_node(ni
);
1682 ifp
->if_drv_flags
|= IFF_DRV_OACTIVE
;
1685 sc
->tx_data_queue_full
[qid
]++;
1690 if (rt2860_tx_data(sc
, m
, ni
, qid
) != 0)
1692 ieee80211_free_node(ni
);
1699 rt2860_drain_fifo_stats(sc
);
1701 sc
->tx_timer
= RT2860_TX_WATCHDOG_TIMEOUT
;
1703 callout_reset(&sc
->tx_watchdog_ch
, hz
, rt2860_tx_watchdog
, sc
);
1706 RT2860_SOFTC_UNLOCK(sc
);
1712 static int rt2860_ioctl(struct ifnet
*ifp
, u_long cmd
, caddr_t data
)
1714 struct rt2860_softc
*sc
;
1715 struct ieee80211com
*ic
;
1717 int error
, startall
;
1721 ifr
= (struct ifreq
*) data
;
1730 RT2860_SOFTC_LOCK(sc
);
1732 if (ifp
->if_flags
& IFF_UP
)
1734 if (ifp
->if_drv_flags
& IFF_DRV_RUNNING
)
1736 if ((ifp
->if_flags
^ sc
->if_flags
) & IFF_PROMISC
)
1737 rt2860_asic_update_promisc(sc
);
1741 rt2860_init_locked(sc
);
1747 if (ifp
->if_drv_flags
& IFF_DRV_RUNNING
)
1748 rt2860_stop_locked(sc
);
1751 sc
->if_flags
= ifp
->if_flags
;
1753 RT2860_SOFTC_UNLOCK(sc
);
1756 ieee80211_start_all(ic
);
1761 error
= ifmedia_ioctl(ifp
, ifr
, &ic
->ic_media
, cmd
);
1765 error
= ether_ioctl(ifp
, cmd
, data
);
1779 static struct ieee80211vap
*rt2860_vap_create(struct ieee80211com
*ic
,
1780 const char name
[IFNAMSIZ
], int unit
, int opmode
, int flags
,
1781 const uint8_t bssid
[IEEE80211_ADDR_LEN
],
1782 const uint8_t mac
[IEEE80211_ADDR_LEN
])
1784 struct rt2860_softc
*sc
;
1786 struct rt2860_softc_vap
*rvap
;
1787 struct ieee80211vap
*vap
;
1792 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATE
,
1793 "%s: VAP create: opmode=%s\n",
1794 device_get_nameunit(sc
->dev
),
1795 ieee80211_opmode_name
[opmode
]);
1799 case IEEE80211_M_MONITOR
:
1800 case IEEE80211_M_IBSS
:
1801 case IEEE80211_M_STA
:
1802 case IEEE80211_M_AHDEMO
:
1803 case IEEE80211_M_HOSTAP
:
1804 case IEEE80211_M_MBSS
:
1805 if (!TAILQ_EMPTY(&ic
->ic_vaps
))
1807 if_printf(ifp
, "only 1 VAP supported\n");
1811 if (opmode
== IEEE80211_M_STA
)
1812 flags
|= IEEE80211_CLONE_NOBEACONS
;
1815 case IEEE80211_M_WDS
:
1816 if (TAILQ_EMPTY(&ic
->ic_vaps
) || ic
->ic_opmode
!= IEEE80211_M_HOSTAP
)
1818 if_printf(ifp
, "WDS only supported in AP mode\n");
1822 flags
&= ~IEEE80211_CLONE_BSSID
;
1826 if_printf(ifp
, "unknown opmode %d\n", opmode
);
1830 rvap
= (struct rt2860_softc_vap
*) malloc(sizeof(struct rt2860_softc_vap
),
1831 M_80211_VAP
, M_NOWAIT
| M_ZERO
);
1837 ieee80211_vap_setup(ic
, vap
, name
, unit
, opmode
, flags
, bssid
, mac
);
1839 rvap
->newstate
= vap
->iv_newstate
;
1840 vap
->iv_newstate
= rt2860_vap_newstate
;
1842 vap
->iv_reset
= rt2860_vap_reset
;
1843 vap
->iv_key_update_begin
= rt2860_vap_key_update_begin
;
1844 vap
->iv_key_update_end
= rt2860_vap_key_update_end
;
1845 vap
->iv_key_set
= rt2860_vap_key_set
;
1846 vap
->iv_key_delete
= rt2860_vap_key_delete
;
1847 vap
->iv_update_beacon
= rt2860_vap_update_beacon
;
1849 rt2860_amrr_init(&rvap
->amrr
, vap
,
1851 RT2860_AMRR_MIN_SUCCESS_THRESHOLD
,
1852 RT2860_AMRR_MAX_SUCCESS_THRESHOLD
,
1855 ieee80211_vap_attach(vap
, rt2860_media_change
, ieee80211_media_status
);
1857 /* override default Rx A-MPDU factor */
1859 vap
->iv_ampdu_rxmax
= IEEE80211_HTCAP_MAXRXAMPDU_32K
;
1860 vap
->iv_ampdu_density
= IEEE80211_HTCAP_MPDUDENSITY_NA
;
1861 vap
->iv_ampdu_limit
= vap
->iv_ampdu_rxmax
;
1863 ic
->ic_opmode
= opmode
;
1871 static void rt2860_vap_delete(struct ieee80211vap
*vap
)
1873 struct rt2860_softc
*sc
;
1874 struct ieee80211com
*ic
;
1876 struct rt2860_softc_vap
*rvap
;
1881 rvap
= (struct rt2860_softc_vap
*) vap
;
1883 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATE
,
1884 "%s: VAP delete: opmode=%s\n",
1885 device_get_nameunit(sc
->dev
),
1886 ieee80211_opmode_name
[vap
->iv_opmode
]);
1888 rt2860_amrr_cleanup(&rvap
->amrr
);
1890 ieee80211_vap_detach(vap
);
1892 if (rvap
->beacon_mbuf
!= NULL
)
1894 m_free(rvap
->beacon_mbuf
);
1895 rvap
->beacon_mbuf
= NULL
;
1898 free(rvap
, M_80211_VAP
);
1904 static int rt2860_vap_reset(struct ieee80211vap
*vap
, u_long cmd
)
1906 struct rt2860_softc
*sc
;
1907 struct ieee80211com
*ic
;
1909 struct rt2860_softc_vap
*rvap
;
1915 rvap
= (struct rt2860_softc_vap
*) vap
;
1917 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATE
,
1918 "%s: VAP reset: cmd=%lu\n",
1919 device_get_nameunit(sc
->dev
), cmd
);
1925 case IEEE80211_IOC_RTSTHRESHOLD
:
1926 case IEEE80211_IOC_AMSDU
:
1927 rt2860_asic_update_rtsthreshold(sc
);
1930 case IEEE80211_IOC_PROTMODE
:
1931 case IEEE80211_IOC_HTPROTMODE
:
1932 rt2860_asic_updateprot(sc
);
1935 case IEEE80211_IOC_TXPOWER
:
1936 rt2860_asic_update_txpower(sc
);
1939 case IEEE80211_IOC_BURST
:
1940 rt2860_asic_updateslot(sc
);
1943 case IEEE80211_IOC_SHORTGI
:
1944 case IEEE80211_IOC_AMPDU_DENSITY
:
1945 case IEEE80211_IOC_SMPS
:
1957 * rt2860_vap_newstate
1959 static int rt2860_vap_newstate(struct ieee80211vap
*vap
,
1960 enum ieee80211_state nstate
, int arg
)
1962 struct rt2860_softc
*sc
;
1963 struct ieee80211com
*ic
;
1965 struct rt2860_softc_vap
*rvap
;
1966 struct ieee80211_node
*ni
;
1967 enum ieee80211_state ostate
;
1973 rvap
= (struct rt2860_softc_vap
*) vap
;
1975 ostate
= vap
->iv_state
;
1977 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATE
,
1978 "%s: VAP newstate: %s -> %s\n",
1979 device_get_nameunit(sc
->dev
),
1980 ieee80211_state_name
[ostate
], ieee80211_state_name
[nstate
]);
1982 error
= rvap
->newstate(vap
, nstate
, arg
);
1986 IEEE80211_UNLOCK(ic
);
1988 RT2860_SOFTC_LOCK(sc
);
1990 /* turn link LED off */
1992 if (nstate
!= IEEE80211_S_RUN
)
1993 rt2860_led_cmd(sc
, RT2860_LED_CMD_RADIO_OFF
);
1997 case IEEE80211_S_INIT
:
1998 rt2860_asic_disable_tsf_sync(sc
);
2001 case IEEE80211_S_RUN
:
2004 rt2860_rf_set_chan(sc
, ni
->ni_chan
);
2006 if (vap
->iv_opmode
!= IEEE80211_M_MONITOR
)
2008 rt2860_asic_enable_mrr(sc
);
2009 rt2860_asic_set_txpreamble(sc
);
2010 rt2860_asic_set_basicrates(sc
);
2011 rt2860_asic_update_txpower(sc
);
2012 rt2860_asic_set_bssid(sc
, ni
->ni_bssid
);
2015 if (vap
->iv_opmode
== IEEE80211_M_HOSTAP
||
2016 vap
->iv_opmode
== IEEE80211_M_IBSS
||
2017 vap
->iv_opmode
== IEEE80211_M_MBSS
)
2019 error
= rt2860_beacon_alloc(sc
, vap
);
2023 rt2860_asic_update_beacon(sc
, vap
);
2026 if (vap
->iv_opmode
!= IEEE80211_M_MONITOR
)
2027 rt2860_asic_enable_tsf_sync(sc
);
2029 /* turn link LED on */
2031 if (vap
->iv_opmode
!= IEEE80211_M_MONITOR
)
2033 rt2860_led_cmd(sc
, RT2860_LED_CMD_RADIO_ON
|
2034 (IEEE80211_IS_CHAN_2GHZ(ni
->ni_chan
) ?
2035 RT2860_LED_CMD_LINK_2GHZ
: RT2860_LED_CMD_LINK_5GHZ
));
2039 case IEEE80211_S_SLEEP
:
2046 RT2860_SOFTC_UNLOCK(sc
);
2054 * rt2860_vap_key_update_begin
2056 static void rt2860_vap_key_update_begin(struct ieee80211vap
*vap
)
2058 struct rt2860_softc
*sc
;
2059 struct ieee80211com
*ic
;
2066 RT2860_DPRINTF(sc
, RT2860_DEBUG_KEY
,
2067 "%s: VAP key update begin\n",
2068 device_get_nameunit(sc
->dev
));
2070 taskqueue_block(sc
->taskqueue
);
2072 IF_LOCK(&ifp
->if_snd
);
2076 * rt2860_vap_key_update_end
2078 static void rt2860_vap_key_update_end(struct ieee80211vap
*vap
)
2080 struct rt2860_softc
*sc
;
2081 struct ieee80211com
*ic
;
2088 RT2860_DPRINTF(sc
, RT2860_DEBUG_KEY
,
2089 "%s: VAP key update end\n",
2090 device_get_nameunit(sc
->dev
));
2092 IF_UNLOCK(&ifp
->if_snd
);
2094 taskqueue_unblock(sc
->taskqueue
);
2098 * rt2860_vap_key_set
2100 static int rt2860_vap_key_set(struct ieee80211vap
*vap
,
2101 const struct ieee80211_key
*k
, const uint8_t mac
[IEEE80211_ADDR_LEN
])
2103 struct rt2860_softc
*sc
;
2104 struct ieee80211com
*ic
;
2106 struct ieee80211_node
*ni
;
2107 uint16_t associd
, key_base
, keymode_base
;
2108 uint8_t mode
, vapid
, wcid
, iv
[8];
2111 if (k
->wk_cipher
->ic_cipher
!= IEEE80211_CIPHER_WEP
&&
2112 k
->wk_cipher
->ic_cipher
!= IEEE80211_CIPHER_TKIP
&&
2113 k
->wk_cipher
->ic_cipher
!= IEEE80211_CIPHER_AES_CCM
)
2119 ni
= ieee80211_find_vap_node(&ic
->ic_sta
, vap
, k
->wk_macaddr
);
2120 associd
= (ni
!= NULL
) ? ni
->ni_associd
: 0;
2123 ieee80211_free_node(ni
);
2125 switch (k
->wk_cipher
->ic_cipher
)
2127 case IEEE80211_CIPHER_WEP
:
2128 if(k
->wk_keylen
< 8)
2129 mode
= RT2860_REG_CIPHER_MODE_WEP40
;
2131 mode
= RT2860_REG_CIPHER_MODE_WEP104
;
2134 case IEEE80211_CIPHER_TKIP
:
2135 mode
= RT2860_REG_CIPHER_MODE_TKIP
;
2138 case IEEE80211_CIPHER_AES_CCM
:
2139 mode
= RT2860_REG_CIPHER_MODE_AES_CCMP
;
2146 RT2860_DPRINTF(sc
, RT2860_DEBUG_KEY
,
2147 "%s: VAP key set: keyix=%d, keylen=%d, macaddr=%s, associd=0x%04x, mode=%d, group=%d\n",
2148 device_get_nameunit(sc
->dev
), k
->wk_keyix
, k
->wk_keylen
, ether_sprintf(k
->wk_macaddr
),
2149 associd
, mode
, (k
->wk_flags
& IEEE80211_KEY_GROUP
) ? 1 : 0);
2151 if (!(k
->wk_flags
& IEEE80211_KEY_GROUP
))
2153 /* install pairwise key */
2157 wcid
= RT2860_AID2WCID(associd
);
2161 key_base
= RT2860_REG_PKEY(wcid
);
2163 if (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_WEP
)
2167 iv
[3] = (k
->wk_keyix
<< 6);
2171 if (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_TKIP
)
2173 iv
[0] = (k
->wk_keytsc
>> 8);
2174 iv
[1] = ((iv
[0] | 0x20) & 0x7f);
2175 iv
[2] = k
->wk_keytsc
;
2181 iv
[0] = k
->wk_keytsc
;
2182 iv
[1] = k
->wk_keytsc
>> 8;
2186 iv
[3] = ((k
->wk_keyix
<< 6) | IEEE80211_WEP_EXTIV
);
2187 iv
[4] = (k
->wk_keytsc
>> 16);
2188 iv
[5] = (k
->wk_keytsc
>> 24);
2189 iv
[6] = (k
->wk_keytsc
>> 32);
2190 iv
[7] = (k
->wk_keytsc
>> 40);
2192 RT2860_DPRINTF(sc
, RT2860_DEBUG_KEY
,
2193 "%s: VAP key set: iv=%02x %02x %02x %02x %02x %02x %02x %02x\n",
2194 device_get_nameunit(sc
->dev
),
2195 iv
[0], iv
[1], iv
[2], iv
[3], iv
[4], iv
[5], iv
[6], iv
[7]);
2198 rt2860_io_mac_write_multi(sc
, RT2860_REG_IVEIV(wcid
), iv
, 8);
2200 if (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_TKIP
)
2202 rt2860_io_mac_write_multi(sc
, key_base
, k
->wk_key
, 16);
2204 if (vap
->iv_opmode
!= IEEE80211_M_HOSTAP
)
2206 rt2860_io_mac_write_multi(sc
, key_base
+ 16, &k
->wk_key
[16], 8);
2207 rt2860_io_mac_write_multi(sc
, key_base
+ 24, &k
->wk_key
[24], 8);
2211 rt2860_io_mac_write_multi(sc
, key_base
+ 16, &k
->wk_key
[24], 8);
2212 rt2860_io_mac_write_multi(sc
, key_base
+ 24, &k
->wk_key
[16], 8);
2217 rt2860_io_mac_write_multi(sc
, key_base
, k
->wk_key
, k
->wk_keylen
);
2220 tmp
= ((vapid
& RT2860_REG_VAP_MASK
) << RT2860_REG_VAP_SHIFT
) |
2221 (mode
<< RT2860_REG_CIPHER_MODE_SHIFT
) | RT2860_REG_PKEY_ENABLE
;
2223 rt2860_io_mac_write(sc
, RT2860_REG_WCID_ATTR(wcid
), tmp
);
2226 if ((k
->wk_flags
& IEEE80211_KEY_GROUP
) ||
2227 (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_WEP
))
2229 /* install group key */
2232 wcid
= 0; /* mcast/bcast WCID */
2233 key_base
= RT2860_REG_SKEY(vapid
, k
->wk_keyix
);
2234 keymode_base
= RT2860_REG_SKEY_MODE(vapid
);
2236 if (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_TKIP
)
2238 rt2860_io_mac_write_multi(sc
, key_base
, k
->wk_key
, 16);
2240 if (vap
->iv_opmode
!= IEEE80211_M_HOSTAP
)
2242 rt2860_io_mac_write_multi(sc
, key_base
+ 16, &k
->wk_key
[16], 8);
2243 rt2860_io_mac_write_multi(sc
, key_base
+ 24, &k
->wk_key
[24], 8);
2247 rt2860_io_mac_write_multi(sc
, key_base
+ 16, &k
->wk_key
[24], 8);
2248 rt2860_io_mac_write_multi(sc
, key_base
+ 24, &k
->wk_key
[16], 8);
2253 rt2860_io_mac_write_multi(sc
, key_base
, k
->wk_key
, k
->wk_keylen
);
2256 tmp
= rt2860_io_mac_read(sc
, keymode_base
);
2258 tmp
&= ~(0xf << (k
->wk_keyix
* 4 + 16 * (vapid
% 2)));
2259 tmp
|= (mode
<< (k
->wk_keyix
* 4 + 16 * (vapid
% 2)));
2261 rt2860_io_mac_write(sc
, keymode_base
, tmp
);
2263 if (vap
->iv_opmode
== IEEE80211_M_HOSTAP
)
2265 if (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_WEP
)
2269 iv
[3] = (k
->wk_keyix
<< 6);
2273 if (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_TKIP
)
2275 iv
[0] = (k
->wk_keytsc
>> 8);
2276 iv
[1] = ((iv
[0] | 0x20) & 0x7f);
2277 iv
[2] = k
->wk_keytsc
;
2283 iv
[0] = k
->wk_keytsc
;
2284 iv
[1] = k
->wk_keytsc
>> 8;
2288 iv
[3] = ((k
->wk_keyix
<< 6) | IEEE80211_WEP_EXTIV
);
2289 iv
[4] = (k
->wk_keytsc
>> 16);
2290 iv
[5] = (k
->wk_keytsc
>> 24);
2291 iv
[6] = (k
->wk_keytsc
>> 32);
2292 iv
[7] = (k
->wk_keytsc
>> 40);
2294 RT2860_DPRINTF(sc
, RT2860_DEBUG_KEY
,
2295 "%s: VAP key set: iv=%02x %02x %02x %02x %02x %02x %02x %02x\n",
2296 device_get_nameunit(sc
->dev
),
2297 iv
[0], iv
[1], iv
[2], iv
[3], iv
[4], iv
[5], iv
[6], iv
[7]);
2300 rt2860_io_mac_write_multi(sc
, RT2860_REG_IVEIV(wcid
), iv
, 8);
2302 tmp
= ((vapid
& RT2860_REG_VAP_MASK
) << RT2860_REG_VAP_SHIFT
) |
2303 (mode
<< RT2860_REG_CIPHER_MODE_SHIFT
);
2305 rt2860_io_mac_write(sc
, RT2860_REG_WCID_ATTR(wcid
), tmp
);
2313 * rt2860_vap_key_delete
2315 static int rt2860_vap_key_delete(struct ieee80211vap
*vap
,
2316 const struct ieee80211_key
*k
)
2318 struct rt2860_softc
*sc
;
2319 struct ieee80211com
*ic
;
2321 struct ieee80211_node
*ni
;
2323 uint8_t vapid
, wcid
;
2329 ni
= ieee80211_find_vap_node(&ic
->ic_sta
, vap
, k
->wk_macaddr
);
2330 associd
= (ni
!= NULL
) ? ni
->ni_associd
: 0;
2333 ieee80211_free_node(ni
);
2335 RT2860_DPRINTF(sc
, RT2860_DEBUG_KEY
,
2336 "%s: VAP key delete: keyix=%d, keylen=%d, macaddr=%s, associd=0x%04x, group=%d\n",
2337 device_get_nameunit(sc
->dev
), k
->wk_keyix
, k
->wk_keylen
, ether_sprintf(k
->wk_macaddr
),
2338 associd
, (k
->wk_flags
& IEEE80211_KEY_GROUP
) ? 1 : 0);
2340 if (!(k
->wk_flags
& IEEE80211_KEY_GROUP
))
2342 /* remove pairwise key */
2346 wcid
= RT2860_AID2WCID(associd
);
2350 tmp
= ((vapid
& RT2860_REG_VAP_MASK
) << RT2860_REG_VAP_SHIFT
) |
2351 (RT2860_REG_CIPHER_MODE_NONE
<< RT2860_REG_CIPHER_MODE_SHIFT
) | RT2860_REG_PKEY_ENABLE
;
2353 rt2860_io_mac_write(sc
, RT2860_REG_WCID_ATTR(wcid
), tmp
);
2357 /* remove group key */
2360 wcid
= 0; /* mcast/bcast WCID */
2362 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_SKEY_MODE(vapid
));
2364 tmp
&= ~(0xf << (k
->wk_keyix
* 4 + 16 * (vapid
% 2)));
2365 tmp
|= (RT2860_REG_CIPHER_MODE_NONE
<< (k
->wk_keyix
* 4 + 16 * (vapid
% 2)));
2367 rt2860_io_mac_write(sc
, RT2860_REG_SKEY_MODE(vapid
), tmp
);
2369 if (vap
->iv_opmode
== IEEE80211_M_HOSTAP
)
2371 tmp
= ((vapid
& RT2860_REG_VAP_MASK
) << RT2860_REG_VAP_SHIFT
) |
2372 (RT2860_REG_CIPHER_MODE_NONE
<< RT2860_REG_CIPHER_MODE_SHIFT
) | RT2860_REG_PKEY_ENABLE
;
2374 rt2860_io_mac_write(sc
, RT2860_REG_WCID_ATTR(wcid
), tmp
);
2382 * rt2860_vap_update_beacon
2384 static void rt2860_vap_update_beacon(struct ieee80211vap
*vap
, int what
)
2386 struct rt2860_softc
*sc
;
2387 struct ieee80211com
*ic
;
2389 struct rt2860_softc_vap
*rvap
;
2391 struct ieee80211_beacon_offsets
*bo
;
2396 rvap
= (struct rt2860_softc_vap
*) vap
;
2397 m
= rvap
->beacon_mbuf
;
2398 bo
= &rvap
->beacon_offsets
;
2400 RT2860_DPRINTF(sc
, RT2860_DEBUG_BEACON
,
2401 "%s: VAP update beacon: what=%d\n",
2402 device_get_nameunit(sc
->dev
), what
);
2404 setbit(bo
->bo_flags
, what
);
2406 ieee80211_beacon_update(vap
->iv_bss
, bo
, m
, 0);
2408 rt2860_asic_update_beacon(sc
, vap
);
2412 * rt2860_media_change
2414 static int rt2860_media_change(struct ifnet
*ifp
)
2418 error
= ieee80211_media_change(ifp
);
2420 return (error
== ENETRESET
? 0 : error
);
2426 static struct ieee80211_node
*rt2860_node_alloc(struct ieee80211vap
*vap
,
2427 const uint8_t mac
[IEEE80211_ADDR_LEN
])
2429 return malloc(sizeof(struct rt2860_softc_node
),
2430 M_80211_NODE
, M_NOWAIT
| M_ZERO
);
2434 * rt2860_node_getmimoinfo
2436 static void rt2860_node_getmimoinfo(const struct ieee80211_node
*ni
,
2437 struct ieee80211_mimo_info
*mi
)
2439 const struct rt2860_softc_node
*rni
;
2442 rni
= (const struct rt2860_softc_node
*) ni
;
2444 for (i
= 0; i
< RT2860_SOFTC_RSSI_COUNT
; i
++)
2446 mi
->rssi
[i
] = rni
->last_rssi_dbm
[i
];
2447 mi
->noise
[i
] = RT2860_NOISE_FLOOR
;
2452 * rt2860_setregdomain
2454 static int rt2860_setregdomain(struct ieee80211com
*ic
,
2455 struct ieee80211_regdomain
*reg
,
2456 int nchans
, struct ieee80211_channel chans
[])
2458 struct rt2860_softc
*sc
;
2464 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATE
,
2465 "%s: set regulatory domain: country=%d, country code string=%c%c, location=%c\n",
2466 device_get_nameunit(sc
->dev
),
2467 reg
->country
, reg
->isocc
[0], reg
->isocc
[1], reg
->location
);
2473 * rt2860_getradiocaps
2475 static void rt2860_getradiocaps(struct ieee80211com
*ic
,
2476 int maxchans
, int *nchans
, struct ieee80211_channel chans
[])
2478 *nchans
= (ic
->ic_nchans
>= maxchans
) ? maxchans
: ic
->ic_nchans
;
2480 memcpy(chans
, ic
->ic_channels
, (*nchans
) * sizeof(struct ieee80211_channel
));
2486 static void rt2860_scan_start(struct ieee80211com
*ic
)
2488 struct rt2860_softc
*sc
;
2494 rt2860_asic_disable_tsf_sync(sc
);
2500 static void rt2860_scan_end(struct ieee80211com
*ic
)
2502 struct rt2860_softc
*sc
;
2508 rt2860_asic_enable_tsf_sync(sc
);
2512 * rt2860_set_channel
2514 static void rt2860_set_channel(struct ieee80211com
*ic
)
2516 struct rt2860_softc
*sc
;
2522 RT2860_DPRINTF(sc
, RT2860_DEBUG_CHAN
,
2523 "%s: set channel: channel=%u, HT%s%s\n",
2524 device_get_nameunit(sc
->dev
),
2525 ieee80211_chan2ieee(ic
, ic
->ic_curchan
),
2526 !IEEE80211_IS_CHAN_HT(ic
->ic_curchan
) ? " disabled" :
2527 IEEE80211_IS_CHAN_HT20(ic
->ic_curchan
) ? "20":
2528 IEEE80211_IS_CHAN_HT40U(ic
->ic_curchan
) ? "40U" : "40D",
2529 (ic
->ic_flags
& IEEE80211_F_SCAN
) ? ", scanning" : "");
2531 RT2860_SOFTC_LOCK(sc
);
2533 rt2860_rf_set_chan(sc
, ic
->ic_curchan
);
2535 RT2860_SOFTC_UNLOCK(sc
);
2541 static void rt2860_newassoc(struct ieee80211_node
*ni
, int isnew
)
2543 struct rt2860_softc
*sc
;
2544 struct ieee80211com
*ic
;
2546 struct ieee80211vap
*vap
;
2547 struct rt2860_softc_vap
*rvap
;
2554 rvap
= (struct rt2860_softc_vap
*) vap
;
2556 RT2860_DPRINTF(sc
, RT2860_DEBUG_NODE
,
2557 "%s: new association: associd=0x%04x, "
2558 "mac addr=%s, QoS %s, ERP %s, HT %s\n",
2559 device_get_nameunit(sc
->dev
), ni
->ni_associd
,
2560 ether_sprintf(ni
->ni_macaddr
),
2561 (ni
->ni_flags
& IEEE80211_NODE_QOS
) ? "enabled" : "disabled",
2562 (ni
->ni_flags
& IEEE80211_NODE_ERP
) ? "enabled" : "disabled",
2563 (ni
->ni_flags
& IEEE80211_NODE_HT
) ? "enabled" : "disabled");
2565 wcid
= RT2860_AID2WCID(ni
->ni_associd
);
2569 rt2860_io_mac_write_multi(sc
, RT2860_REG_WCID(wcid
),
2570 ni
->ni_macaddr
, IEEE80211_ADDR_LEN
);
2572 rt2860_amrr_node_init(&rvap
->amrr
, &sc
->amrr_node
[wcid
], ni
);
2574 RT2860_DPRINTF(sc
, RT2860_DEBUG_RATE
,
2575 "%s: initial%s node Tx rate: associd=0x%04x, rate=0x%02x, max rate=0x%02x\n",
2576 device_get_nameunit(sc
->dev
),
2577 (ni
->ni_flags
& IEEE80211_NODE_HT
) ? " HT" : "",
2578 ni
->ni_associd
, ni
->ni_txrate
,
2579 (ni
->ni_flags
& IEEE80211_NODE_HT
) ?
2580 (ni
->ni_htrates
.rs_rates
[ni
->ni_htrates
.rs_nrates
- 1] | IEEE80211_RATE_MCS
) :
2581 (ni
->ni_rates
.rs_rates
[ni
->ni_rates
.rs_nrates
- 1] & IEEE80211_RATE_VAL
));
2583 rt2860_asic_updateprot(sc
);
2584 rt2860_asic_updateslot(sc
);
2585 rt2860_asic_set_txpreamble(sc
);
2591 static void rt2860_updateslot(struct ifnet
*ifp
)
2593 struct rt2860_softc
*sc
;
2597 rt2860_asic_updateslot(sc
);
2601 * rt2860_update_promisc
2603 static void rt2860_update_promisc(struct ifnet
*ifp
)
2605 struct rt2860_softc
*sc
;
2609 rt2860_asic_update_promisc(sc
);
2613 * rt2860_update_mcast
2615 static void rt2860_update_mcast(struct ifnet
*ifp
)
2617 struct rt2860_softc
*sc
;
2625 static int rt2860_wme_update(struct ieee80211com
*ic
)
2627 struct rt2860_softc
*sc
;
2633 rt2860_asic_wme_update(sc
);
2641 static int rt2860_raw_xmit(struct ieee80211_node
*ni
, struct mbuf
*m
,
2642 const struct ieee80211_bpf_params
*params
)
2644 struct rt2860_softc
*sc
;
2645 struct ieee80211com
*ic
;
2652 RT2860_SOFTC_LOCK(sc
);
2654 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
2656 RT2860_SOFTC_UNLOCK(sc
);
2659 ieee80211_free_node(ni
);
2664 if (sc
->tx_ring
[sc
->tx_ring_mgtqid
].data_queued
>= RT2860_SOFTC_TX_RING_DATA_COUNT
)
2666 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
2667 "%s: raw xmit: Tx ring with qid=%d is full\n",
2668 device_get_nameunit(sc
->dev
), sc
->tx_ring_mgtqid
);
2670 ifp
->if_drv_flags
|= IFF_DRV_OACTIVE
;
2672 RT2860_SOFTC_UNLOCK(sc
);
2675 ieee80211_free_node(ni
);
2677 sc
->tx_data_queue_full
[sc
->tx_ring_mgtqid
]++;
2682 if (rt2860_tx_mgmt(sc
, m
, ni
, sc
->tx_ring_mgtqid
) != 0)
2686 RT2860_SOFTC_UNLOCK(sc
);
2688 ieee80211_free_node(ni
);
2693 sc
->tx_timer
= RT2860_TX_WATCHDOG_TIMEOUT
;
2695 RT2860_SOFTC_UNLOCK(sc
);
2701 * rt2860_recv_action
2703 static int rt2860_recv_action(struct ieee80211_node
*ni
,
2704 const struct ieee80211_frame
*wh
,
2705 const uint8_t *frm
, const uint8_t *efrm
)
2707 struct rt2860_softc
*sc
;
2708 struct ieee80211com
*ic
;
2710 const struct ieee80211_action
*ia
;
2711 struct ieee80211_tx_ampdu
*tx_ampdu
;
2712 uint16_t associd
, status
, baparamset
;
2714 int ret
, tid
, bufsize
, ac
;
2721 ia
= (const struct ieee80211_action
*) frm
;
2723 ret
= sc
->recv_action(ni
, wh
, frm
, efrm
);
2725 if (ia
->ia_category
!= IEEE80211_ACTION_CAT_BA
)
2728 associd
= (ni
!= NULL
) ? ni
->ni_associd
: 0;
2729 wcid
= RT2860_AID2WCID(associd
);
2731 switch (ia
->ia_action
)
2733 /* IEEE80211_ACTION_BA_ADDBA_REQUEST */
2734 case IEEE80211_ACTION_BA_ADDBA_REQUEST
:
2735 baparamset
= LE_READ_2(frm
+ 3);
2736 tid
= RT2860_MS(baparamset
, IEEE80211_BAPS_TID
);
2737 bufsize
= RT2860_MS(baparamset
, IEEE80211_BAPS_BUFSIZ
);
2739 RT2860_DPRINTF(sc
, RT2860_DEBUG_BA
,
2740 "%s: received ADDBA request: associd=0x%04x, tid=%d, bufsize=%d\n",
2741 device_get_nameunit(sc
->dev
), associd
, tid
, bufsize
);
2743 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_WCID(wcid
) + 4);
2745 tmp
|= (0x10000 << tid
);
2747 rt2860_io_mac_write(sc
, RT2860_REG_WCID(wcid
) + 4, tmp
);
2750 /* IEEE80211_ACTION_BA_ADDBA_RESPONSE */
2751 case IEEE80211_ACTION_BA_ADDBA_RESPONSE
:
2752 status
= LE_READ_2(frm
+ 3);
2753 baparamset
= LE_READ_2(frm
+ 4);
2754 tid
= RT2860_MS(baparamset
, IEEE80211_BAPS_TID
);
2755 bufsize
= RT2860_MS(baparamset
, IEEE80211_BAPS_BUFSIZ
);
2756 ac
= TID_TO_WME_AC(tid
);
2757 tx_ampdu
= &ni
->ni_tx_ampdu
[ac
];
2759 RT2860_DPRINTF(sc
, RT2860_DEBUG_BA
,
2760 "%s: received ADDBA response: associd=0x%04x, status=%d, tid=%d, bufsize=%d\n",
2761 device_get_nameunit(sc
->dev
), associd
, status
, tid
, bufsize
);
2763 if (sc
->mac_rev
>= 0x28720200)
2765 if (tx_ampdu
->txa_wnd
> 13)
2766 tx_ampdu
->txa_wnd
= 13;
2770 if (tx_ampdu
->txa_wnd
> 7)
2771 tx_ampdu
->txa_wnd
= 7;
2774 if (status
== IEEE80211_STATUS_SUCCESS
)
2776 sc
->tx_ampdu_sessions
++;
2778 rt2860_asic_updateprot(sc
);
2782 /* IEEE80211_ACTION_BA_DELBA */
2783 case IEEE80211_ACTION_BA_DELBA
:
2784 baparamset
= LE_READ_2(frm
+ 2);
2785 tid
= RT2860_MS(baparamset
, IEEE80211_BAPS_TID
);
2787 RT2860_DPRINTF(sc
, RT2860_DEBUG_BA
,
2788 "%s: received DELBA request: associd=0x%04x, tid=%d\n",
2789 device_get_nameunit(sc
->dev
), associd
, tid
);
2791 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_WCID(wcid
) + 4);
2793 tmp
&= ~(0x10000 << tid
);
2795 rt2860_io_mac_write(sc
, RT2860_REG_WCID(wcid
) + 4, tmp
);
2803 * rt2860_send_action
2805 static int rt2860_send_action(struct ieee80211_node
*ni
,
2806 int cat
, int act
, void *sa
)
2808 struct rt2860_softc
*sc
;
2809 struct ieee80211com
*ic
;
2811 uint16_t associd
, *args
, baparamset
;
2820 ret
= sc
->send_action(ni
, cat
, act
, sa
);
2822 if (cat
!= IEEE80211_ACTION_CAT_BA
)
2825 associd
= (ni
!= NULL
) ? ni
->ni_associd
: 0;
2826 wcid
= RT2860_AID2WCID(associd
);
2831 /* IEEE80211_ACTION_BA_DELBA */
2832 case IEEE80211_ACTION_BA_DELBA
:
2833 baparamset
= RT2860_SM(args
[0], IEEE80211_DELBAPS_TID
) | args
[1];
2835 tid
= RT2860_MS(baparamset
, IEEE80211_DELBAPS_TID
);
2837 RT2860_DPRINTF(sc
, RT2860_DEBUG_BA
,
2838 "%s: sending DELBA request: associd=0x%04x, tid=%d\n",
2839 device_get_nameunit(sc
->dev
), associd
, tid
);
2841 if (RT2860_MS(baparamset
, IEEE80211_DELBAPS_INIT
) != IEEE80211_DELBAPS_INIT
)
2843 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_WCID(wcid
) + 4);
2845 tmp
&= ~(0x10000 << tid
);
2847 rt2860_io_mac_write(sc
, RT2860_REG_WCID(wcid
) + 4, tmp
);
2851 sc
->tx_ampdu_sessions
--;
2853 rt2860_asic_updateprot(sc
);
2862 * rt2860_amrr_update_iter_func
2864 static void rt2860_amrr_update_iter_func(void *arg
, struct ieee80211_node
*ni
)
2866 struct rt2860_softc
*sc
;
2867 struct ieee80211com
*ic
;
2869 struct ieee80211vap
*vap
;
2870 struct rt2860_softc_vap
*rvap
;
2877 rvap
= (struct rt2860_softc_vap
*) vap
;
2879 /* only associated stations */
2881 if ((ni
->ni_vap
== vap
) && (ni
->ni_associd
!= 0))
2883 wcid
= RT2860_AID2WCID(ni
->ni_associd
);
2885 RT2860_DPRINTF(sc
, RT2860_DEBUG_RATE
,
2886 "%s: AMRR node: wcid=0x%02x, txcnt=%d, success=%d, retrycnt=%d\n",
2887 device_get_nameunit(sc
->dev
),
2888 wcid
, sc
->amrr_node
[wcid
].txcnt
, sc
->amrr_node
[wcid
].success
, sc
->amrr_node
[wcid
].retrycnt
);
2890 rt2860_amrr_choose(ni
, &sc
->amrr_node
[wcid
]);
2892 RT2860_DPRINTF(sc
, RT2860_DEBUG_RATE
,
2893 "%s:%s node Tx rate: associd=0x%04x, rate=0x%02x, max rate=0x%02x\n",
2894 device_get_nameunit(sc
->dev
),
2895 (ni
->ni_flags
& IEEE80211_NODE_HT
) ? " HT" : "",
2896 ni
->ni_associd
, ni
->ni_txrate
,
2897 (ni
->ni_flags
& IEEE80211_NODE_HT
) ?
2898 (ni
->ni_htrates
.rs_rates
[ni
->ni_htrates
.rs_nrates
- 1] | IEEE80211_RATE_MCS
) :
2899 (ni
->ni_rates
.rs_rates
[ni
->ni_rates
.rs_nrates
- 1] & IEEE80211_RATE_VAL
));
2906 static void rt2860_periodic(void *arg
)
2908 struct rt2860_softc
*sc
;
2912 RT2860_DPRINTF(sc
, RT2860_DEBUG_PERIODIC
,
2914 device_get_nameunit(sc
->dev
));
2916 taskqueue_enqueue(sc
->taskqueue
, &sc
->periodic_task
);
2920 * rt2860_tx_watchdog
2922 static void rt2860_tx_watchdog(void *arg
)
2924 struct rt2860_softc
*sc
;
2930 if (sc
->tx_timer
== 0)
2933 if (--sc
->tx_timer
== 0)
2935 printf("%s: Tx watchdog timeout: resetting\n",
2936 device_get_nameunit(sc
->dev
));
2938 rt2860_stop_locked(sc
);
2939 rt2860_init_locked(sc
);
2943 sc
->tx_watchdog_timeouts
++;
2946 callout_reset(&sc
->tx_watchdog_ch
, hz
, rt2860_tx_watchdog
, sc
);
2950 * rt2860_asic_set_bssid
2952 static void rt2860_asic_set_bssid(struct rt2860_softc
*sc
,
2953 const uint8_t *bssid
)
2957 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATE
,
2958 "%s: set bssid: bssid=%s\n",
2959 device_get_nameunit(sc
->dev
),
2960 ether_sprintf(bssid
));
2962 tmp
= bssid
[0] | (bssid
[1]) << 8 | (bssid
[2] << 16) | (bssid
[3] << 24);
2964 rt2860_io_mac_write(sc
, RT2860_REG_BSSID_DW0
, tmp
);
2966 tmp
= bssid
[4] | (bssid
[5] << 8);
2968 rt2860_io_mac_write(sc
, RT2860_REG_BSSID_DW1
, tmp
);
2972 * rt2860_asic_set_macaddr
2974 static void rt2860_asic_set_macaddr(struct rt2860_softc
*sc
,
2975 const uint8_t *addr
)
2979 tmp
= addr
[0] | (addr
[1] << 8) | (addr
[2] << 16) | (addr
[3] << 24);
2981 rt2860_io_mac_write(sc
, RT2860_REG_ADDR_DW0
, tmp
);
2983 tmp
= addr
[4] | (addr
[5] << 8);
2985 rt2860_io_mac_write(sc
, RT2860_REG_ADDR_DW1
, tmp
);
2989 * rt2860_asic_enable_tsf_sync
2991 static void rt2860_asic_enable_tsf_sync(struct rt2860_softc
*sc
)
2994 struct ieee80211com
*ic
;
2995 struct ieee80211vap
*vap
;
3000 vap
= TAILQ_FIRST(&ic
->ic_vaps
);
3002 RT2860_DPRINTF(sc
, RT2860_DEBUG_BEACON
,
3003 "%s: enabling TSF\n",
3004 device_get_nameunit(sc
->dev
));
3006 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_BCN_TIME_CFG
);
3009 tmp
|= vap
->iv_bss
->ni_intval
* 16;
3010 tmp
|= (RT2860_REG_TSF_TIMER_ENABLE
| RT2860_REG_TBTT_TIMER_ENABLE
);
3012 if (vap
->iv_opmode
== IEEE80211_M_STA
)
3014 tmp
|= (RT2860_REG_TSF_SYNC_MODE_STA
<< RT2860_REG_TSF_SYNC_MODE_SHIFT
);
3016 else if (vap
->iv_opmode
== IEEE80211_M_IBSS
)
3018 tmp
|= RT2860_REG_BCN_TX_ENABLE
;
3019 tmp
|= (RT2860_REG_TSF_SYNC_MODE_IBSS
<< RT2860_REG_TSF_SYNC_MODE_SHIFT
);
3021 else if (vap
->iv_opmode
== IEEE80211_M_HOSTAP
)
3023 tmp
|= RT2860_REG_BCN_TX_ENABLE
;
3024 tmp
|= (RT2860_REG_TSF_SYNC_MODE_HOSTAP
<< RT2860_REG_TSF_SYNC_MODE_SHIFT
);
3027 rt2860_io_mac_write(sc
, RT2860_REG_BCN_TIME_CFG
, tmp
);
3031 * rt2860_asic_disable_tsf_sync
3033 static void rt2860_asic_disable_tsf_sync(struct rt2860_softc
*sc
)
3037 RT2860_DPRINTF(sc
, RT2860_DEBUG_BEACON
,
3038 "%s: disabling TSF\n",
3039 device_get_nameunit(sc
->dev
));
3041 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_BCN_TIME_CFG
);
3043 tmp
&= ~(RT2860_REG_BCN_TX_ENABLE
|
3044 RT2860_REG_TSF_TIMER_ENABLE
|
3045 RT2860_REG_TBTT_TIMER_ENABLE
);
3047 tmp
&= ~(RT2860_REG_TSF_SYNC_MODE_MASK
<< RT2860_REG_TSF_SYNC_MODE_SHIFT
);
3048 tmp
|= (RT2860_REG_TSF_SYNC_MODE_DISABLE
<< RT2860_REG_TSF_SYNC_MODE_SHIFT
);
3050 rt2860_io_mac_write(sc
, RT2860_REG_BCN_TIME_CFG
, tmp
);
3054 * rt2860_asic_enable_mrr
3056 static void rt2860_asic_enable_mrr(struct rt2860_softc
*sc
)
3058 #define CCK(mcs) (mcs)
3059 #define OFDM(mcs) ((1 << 3) | (mcs))
3060 #define HT(mcs) (mcs)
3062 rt2860_io_mac_write(sc
, RT2860_REG_TX_LG_FBK_CFG0
,
3063 (OFDM(6) << 28) | /* 54 -> 48 */
3064 (OFDM(5) << 24) | /* 48 -> 36 */
3065 (OFDM(4) << 20) | /* 36 -> 24 */
3066 (OFDM(3) << 16) | /* 24 -> 18 */
3067 (OFDM(2) << 12) | /* 18 -> 12 */
3068 (OFDM(1) << 8) | /* 12 -> 9 */
3069 (OFDM(0) << 4) | /* 9 -> 6 */
3070 OFDM(0)); /* 6 -> 6 */
3072 rt2860_io_mac_write(sc
, RT2860_REG_TX_LG_FBK_CFG1
,
3073 (CCK(2) << 12) | /* 11 -> 5.5 */
3074 (CCK(1) << 8) | /* 5.5 -> 2 */
3075 (CCK(0) << 4) | /* 2 -> 1 */
3076 CCK(0)); /* 1 -> 1 */
3078 rt2860_io_mac_write(sc
, RT2860_REG_TX_HT_FBK_CFG0
,
3088 rt2860_io_mac_write(sc
, RT2860_REG_TX_HT_FBK_CFG1
,
3104 * rt2860_asic_set_txpreamble
3106 static void rt2860_asic_set_txpreamble(struct rt2860_softc
*sc
)
3109 struct ieee80211com
*ic
;
3115 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATE
,
3116 "%s: %s short Tx preamble\n",
3117 device_get_nameunit(sc
->dev
),
3118 (ic
->ic_flags
& IEEE80211_F_SHPREAMBLE
) ? "enabling" : "disabling");
3120 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_AUTO_RSP_CFG
);
3122 tmp
&= ~RT2860_REG_CCK_SHORT_ENABLE
;
3124 if (ic
->ic_flags
& IEEE80211_F_SHPREAMBLE
)
3125 tmp
|= RT2860_REG_CCK_SHORT_ENABLE
;
3127 rt2860_io_mac_write(sc
, RT2860_REG_AUTO_RSP_CFG
, tmp
);
3131 * rt2860_asic_set_basicrates
3133 static void rt2860_asic_set_basicrates(struct rt2860_softc
*sc
)
3136 struct ieee80211com
*ic
;
3141 if (ic
->ic_curmode
== IEEE80211_MODE_11B
)
3142 rt2860_io_mac_write(sc
, RT2860_REG_LEGACY_BASIC_RATE
, 0x3);
3143 else if (ic
->ic_curmode
== IEEE80211_MODE_11A
)
3144 rt2860_io_mac_write(sc
, RT2860_REG_LEGACY_BASIC_RATE
, 0x150);
3146 rt2860_io_mac_write(sc
, RT2860_REG_LEGACY_BASIC_RATE
, 0x15f);
3150 * rt2860_asic_update_rtsthreshold
3152 static void rt2860_asic_update_rtsthreshold(struct rt2860_softc
*sc
)
3155 struct ieee80211com
*ic
;
3156 struct ieee80211vap
*vap
;
3162 vap
= TAILQ_FIRST(&ic
->ic_vaps
);
3165 threshold
= IEEE80211_RTS_MAX
;
3166 else if (vap
->iv_flags_ht
& IEEE80211_FHT_AMSDU_TX
)
3169 threshold
= vap
->iv_rtsthreshold
;
3171 RT2860_DPRINTF(sc
, RT2860_DEBUG_PROT
,
3172 "%s: updating RTS threshold: %d\n",
3173 device_get_nameunit(sc
->dev
), threshold
);
3175 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_RTS_CFG
);
3177 tmp
&= ~(RT2860_REG_TX_RTS_THRESHOLD_MASK
<< RT2860_REG_TX_RTS_THRESHOLD_SHIFT
);
3179 tmp
|= ((threshold
& RT2860_REG_TX_RTS_THRESHOLD_MASK
) <<
3180 RT2860_REG_TX_RTS_THRESHOLD_SHIFT
);
3182 rt2860_io_mac_write(sc
, RT2860_REG_TX_RTS_CFG
, tmp
);
3186 * rt2860_asic_update_txpower
3188 static void rt2860_asic_update_txpower(struct rt2860_softc
*sc
)
3191 struct ieee80211com
*ic
;
3192 uint32_t *txpow_rate
;
3201 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATE
,
3202 "%s: updating Tx power: %d\n",
3203 device_get_nameunit(sc
->dev
), ic
->ic_txpowlimit
);
3205 if (!IEEE80211_IS_CHAN_HT40(ic
->ic_curchan
))
3207 txpow_rate
= sc
->txpow_rate_20mhz
;
3211 if (IEEE80211_IS_CHAN_2GHZ(ic
->ic_curchan
))
3212 txpow_rate
= sc
->txpow_rate_40mhz_2ghz
;
3214 txpow_rate
= sc
->txpow_rate_40mhz_5ghz
;
3219 val
= rt2860_io_bbp_read(sc
, 1);
3222 if (ic
->ic_txpowlimit
> 90)
3226 else if (ic
->ic_txpowlimit
> 60)
3230 else if (ic
->ic_txpowlimit
> 30)
3234 else if (ic
->ic_txpowlimit
> 15)
3238 else if (ic
->ic_txpowlimit
> 9)
3248 rt2860_io_bbp_write(sc
, 1, val
);
3250 for (i
= 0; i
< RT2860_SOFTC_TXPOW_RATE_COUNT
; i
++)
3252 if (txpow_rate
[i
] == 0xffffffff)
3255 tmp
= rt2860_read_eeprom_txpow_rate_add_delta(txpow_rate
[i
], delta
);
3257 rt2860_io_mac_write(sc
, RT2860_REG_TX_PWR_CFG(i
), tmp
);
3262 * rt2860_asic_update_promisc
3264 static void rt2860_asic_update_promisc(struct rt2860_softc
*sc
)
3271 printf("%s: %s promiscuous mode\n",
3272 device_get_nameunit(sc
->dev
),
3273 (ifp
->if_flags
& IFF_PROMISC
) ? "entering" : "leaving");
3275 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_RX_FILTER_CFG
);
3277 tmp
&= ~RT2860_REG_RX_FILTER_DROP_UC_NOME
;
3279 if (!(ifp
->if_flags
& IFF_PROMISC
))
3280 tmp
|= RT2860_REG_RX_FILTER_DROP_UC_NOME
;
3282 rt2860_io_mac_write(sc
, RT2860_REG_RX_FILTER_CFG
, tmp
);
3286 * rt2860_asic_updateprot
3288 static void rt2860_asic_updateprot(struct rt2860_softc
*sc
)
3291 struct ieee80211com
*ic
;
3292 struct ieee80211vap
*vap
;
3293 uint32_t cck_prot
, ofdm_prot
, mm20_prot
, mm40_prot
, gf20_prot
, gf40_prot
;
3295 enum ieee80211_protmode htprotmode
;
3299 vap
= TAILQ_FIRST(&ic
->ic_vaps
);
3301 /* CCK frame protection */
3303 cck_prot
= RT2860_REG_RTSTH_ENABLE
| RT2860_REG_PROT_NAV_SHORT
|
3304 RT2860_REG_TXOP_ALLOW_ALL
| RT2860_REG_PROT_CTRL_NONE
;
3306 /* set up protection frame phy mode and rate (MCS code) */
3308 if (ic
->ic_curmode
== IEEE80211_MODE_11A
)
3309 cck_prot
|= (RT2860_REG_PROT_PHYMODE_OFDM
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3310 (0 << RT2860_REG_PROT_MCS_SHIFT
);
3312 cck_prot
|= ((RT2860_REG_PROT_PHYMODE_CCK
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3313 (3 << RT2860_REG_PROT_MCS_SHIFT
));
3315 rt2860_io_mac_write(sc
, RT2860_REG_TX_CCK_PROT_CFG
, cck_prot
);
3317 /* OFDM frame protection */
3319 ofdm_prot
= RT2860_REG_RTSTH_ENABLE
| RT2860_REG_PROT_NAV_SHORT
|
3320 RT2860_REG_TXOP_ALLOW_ALL
;
3322 if (ic
->ic_flags
& IEEE80211_F_USEPROT
)
3324 RT2860_DPRINTF(sc
, RT2860_DEBUG_PROT
,
3325 "%s: updating protection mode: b/g protection mode=%s\n",
3326 device_get_nameunit(sc
->dev
),
3327 (ic
->ic_protmode
== IEEE80211_PROT_RTSCTS
) ? "RTS/CTS" :
3328 ((ic
->ic_protmode
== IEEE80211_PROT_CTSONLY
) ? "CTS-to-self" : "none"));
3330 if (ic
->ic_protmode
== IEEE80211_PROT_RTSCTS
)
3331 ofdm_prot
|= RT2860_REG_PROT_CTRL_RTS_CTS
;
3332 else if (ic
->ic_protmode
== IEEE80211_PROT_CTSONLY
)
3333 ofdm_prot
|= RT2860_REG_PROT_CTRL_CTS
;
3335 ofdm_prot
|= RT2860_REG_PROT_CTRL_NONE
;
3339 RT2860_DPRINTF(sc
, RT2860_DEBUG_PROT
,
3340 "%s: updating protection mode: b/g protection mode=%s\n",
3341 device_get_nameunit(sc
->dev
), "none");
3343 ofdm_prot
|= RT2860_REG_PROT_CTRL_NONE
;
3346 rt2860_io_mac_write(sc
, RT2860_REG_TX_OFDM_PROT_CFG
, ofdm_prot
);
3348 /* HT frame protection */
3350 if ((vap
!= NULL
) && (vap
->iv_opmode
== IEEE80211_M_STA
) && (vap
->iv_state
== IEEE80211_S_RUN
))
3351 htopmode
= vap
->iv_bss
->ni_htopmode
;
3353 htopmode
= ic
->ic_curhtprotmode
;
3355 htprotmode
= ic
->ic_htprotmode
;
3357 /* force HT mixed mode and RTS/CTS protection if A-MPDU Tx aggregation is enabled */
3359 if (sc
->tx_ampdu_sessions
> 0)
3361 RT2860_DPRINTF(sc
, RT2860_DEBUG_PROT
,
3362 "%s: updating protection mode: forcing HT mixed mode and RTS/CTS protection\n",
3363 device_get_nameunit(sc
->dev
));
3365 htopmode
= IEEE80211_HTINFO_OPMODE_MIXED
;
3366 htprotmode
= IEEE80211_PROT_RTSCTS
;
3369 RT2860_DPRINTF(sc
, RT2860_DEBUG_PROT
,
3370 "%s: updating protection mode: HT operation mode=0x%02x, protection mode=%s\n",
3371 device_get_nameunit(sc
->dev
),
3372 htopmode
& IEEE80211_HTINFO_OPMODE
,
3373 (htprotmode
== IEEE80211_PROT_RTSCTS
) ? "RTS/CTS" :
3374 ((htprotmode
== IEEE80211_PROT_CTSONLY
) ? "CTS-to-self" : "none"));
3376 switch (htopmode
& IEEE80211_HTINFO_OPMODE
)
3378 /* IEEE80211_HTINFO_OPMODE_HT20PR */
3379 case IEEE80211_HTINFO_OPMODE_HT20PR
:
3380 mm20_prot
= RT2860_REG_PROT_NAV_SHORT
| RT2860_REG_PROT_CTRL_NONE
|
3381 RT2860_REG_TXOP_ALLOW_CCK
| RT2860_REG_TXOP_ALLOW_OFDM
|
3382 RT2860_REG_TXOP_ALLOW_MM20
| RT2860_REG_TXOP_ALLOW_GF20
|
3383 (RT2860_REG_PROT_PHYMODE_OFDM
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3384 (4 << RT2860_REG_PROT_MCS_SHIFT
);
3386 gf20_prot
= mm20_prot
;
3388 mm40_prot
= RT2860_REG_PROT_NAV_SHORT
| RT2860_REG_TXOP_ALLOW_ALL
|
3389 (RT2860_REG_PROT_PHYMODE_OFDM
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3390 (0x84 << RT2860_REG_PROT_MCS_SHIFT
);
3392 if (htprotmode
== IEEE80211_PROT_RTSCTS
)
3393 mm40_prot
|= RT2860_REG_PROT_CTRL_RTS_CTS
;
3394 else if (htprotmode
== IEEE80211_PROT_CTSONLY
)
3395 mm40_prot
|= RT2860_REG_PROT_CTRL_CTS
;
3397 mm40_prot
|= RT2860_REG_PROT_CTRL_NONE
;
3399 gf40_prot
= mm40_prot
;
3402 /* IEEE80211_HTINFO_OPMODE_MIXED */
3403 case IEEE80211_HTINFO_OPMODE_MIXED
:
3404 mm20_prot
= RT2860_REG_PROT_NAV_SHORT
|
3405 RT2860_REG_TXOP_ALLOW_CCK
| RT2860_REG_TXOP_ALLOW_OFDM
|
3406 RT2860_REG_TXOP_ALLOW_MM20
| RT2860_REG_TXOP_ALLOW_GF20
;
3408 if (ic
->ic_flags
& IEEE80211_F_USEPROT
)
3409 mm20_prot
|= (RT2860_REG_PROT_PHYMODE_CCK
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3410 (3 << RT2860_REG_PROT_MCS_SHIFT
);
3412 mm20_prot
|= (RT2860_REG_PROT_PHYMODE_OFDM
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3413 (4 << RT2860_REG_PROT_MCS_SHIFT
);
3415 if (htprotmode
== IEEE80211_PROT_RTSCTS
)
3416 mm20_prot
|= RT2860_REG_PROT_CTRL_RTS_CTS
;
3417 else if (htprotmode
== IEEE80211_PROT_CTSONLY
)
3418 mm20_prot
|= RT2860_REG_PROT_CTRL_CTS
;
3420 mm20_prot
|= RT2860_REG_PROT_CTRL_NONE
;
3422 gf20_prot
= mm20_prot
;
3424 mm40_prot
= RT2860_REG_PROT_NAV_SHORT
| RT2860_REG_TXOP_ALLOW_ALL
;
3426 if (ic
->ic_flags
& IEEE80211_F_USEPROT
)
3427 mm40_prot
|= (RT2860_REG_PROT_PHYMODE_CCK
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3428 (3 << RT2860_REG_PROT_MCS_SHIFT
);
3430 mm40_prot
|= (RT2860_REG_PROT_PHYMODE_OFDM
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3431 (0x84 << RT2860_REG_PROT_MCS_SHIFT
);
3433 if (htprotmode
== IEEE80211_PROT_RTSCTS
)
3434 mm40_prot
|= RT2860_REG_PROT_CTRL_RTS_CTS
;
3435 else if (htprotmode
== IEEE80211_PROT_CTSONLY
)
3436 mm40_prot
|= RT2860_REG_PROT_CTRL_CTS
;
3438 mm40_prot
|= RT2860_REG_PROT_CTRL_NONE
;
3440 gf40_prot
= mm40_prot
;
3444 * IEEE80211_HTINFO_OPMODE_PURE
3445 * IEEE80211_HTINFO_OPMODE_PROTOPT
3447 case IEEE80211_HTINFO_OPMODE_PURE
:
3448 case IEEE80211_HTINFO_OPMODE_PROTOPT
:
3450 mm20_prot
= RT2860_REG_PROT_NAV_SHORT
| RT2860_REG_PROT_CTRL_NONE
|
3451 RT2860_REG_TXOP_ALLOW_CCK
| RT2860_REG_TXOP_ALLOW_OFDM
|
3452 RT2860_REG_TXOP_ALLOW_MM20
| RT2860_REG_TXOP_ALLOW_GF20
|
3453 (RT2860_REG_PROT_PHYMODE_OFDM
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3454 (4 << RT2860_REG_PROT_MCS_SHIFT
);
3456 gf20_prot
= mm20_prot
;
3458 mm40_prot
= RT2860_REG_PROT_NAV_SHORT
| RT2860_REG_PROT_CTRL_NONE
|
3459 RT2860_REG_TXOP_ALLOW_ALL
|
3460 (RT2860_REG_PROT_PHYMODE_OFDM
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3461 (0x84 << RT2860_REG_PROT_MCS_SHIFT
);
3463 gf40_prot
= mm40_prot
;
3467 rt2860_io_mac_write(sc
, RT2860_REG_TX_MM20_PROT_CFG
, mm20_prot
);
3468 rt2860_io_mac_write(sc
, RT2860_REG_TX_MM40_PROT_CFG
, mm40_prot
);
3469 rt2860_io_mac_write(sc
, RT2860_REG_TX_GF20_PROT_CFG
, gf20_prot
);
3470 rt2860_io_mac_write(sc
, RT2860_REG_TX_GF40_PROT_CFG
, gf40_prot
);
3474 * rt2860_asic_updateslot
3476 static void rt2860_asic_updateslot(struct rt2860_softc
*sc
)
3479 struct ieee80211com
*ic
;
3480 struct ieee80211vap
*vap
;
3485 vap
= TAILQ_FIRST(&ic
->ic_vaps
);
3487 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATE
,
3488 "%s: %s short slot time\n",
3489 device_get_nameunit(sc
->dev
),
3490 ((ic
->ic_flags
& IEEE80211_F_SHSLOT
) ||
3491 ((vap
!= NULL
) && (vap
->iv_flags
& IEEE80211_F_BURST
))) ? "enabling" : "disabling");
3493 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_BKOFF_SLOT_CFG
);
3497 if ((ic
->ic_flags
& IEEE80211_F_SHSLOT
) ||
3498 ((vap
!= NULL
) && (vap
->iv_flags
& IEEE80211_F_BURST
)))
3499 tmp
|= IEEE80211_DUR_SHSLOT
;
3501 tmp
|= IEEE80211_DUR_SLOT
;
3503 rt2860_io_mac_write(sc
, RT2860_REG_BKOFF_SLOT_CFG
, tmp
);
3507 * rt2860_asic_wme_update
3509 static void rt2860_asic_wme_update(struct rt2860_softc
*sc
)
3512 struct ieee80211com
*ic
;
3513 struct ieee80211_wme_state
*wme
;
3514 const struct wmeParams
*wmep
;
3520 wmep
= wme
->wme_chanParams
.cap_wmeParams
;
3522 RT2860_DPRINTF(sc
, RT2860_DEBUG_WME
,
3523 "%s: wme update: WME_AC_VO=%d/%d/%d/%d, WME_AC_VI=%d/%d/%d/%d, "
3524 "WME_AC_BK=%d/%d/%d/%d, WME_AC_BE=%d/%d/%d/%d\n",
3525 device_get_nameunit(sc
->dev
),
3526 wmep
[WME_AC_VO
].wmep_aifsn
,
3527 wmep
[WME_AC_VO
].wmep_logcwmin
, wmep
[WME_AC_VO
].wmep_logcwmax
,
3528 wmep
[WME_AC_VO
].wmep_txopLimit
,
3529 wmep
[WME_AC_VI
].wmep_aifsn
,
3530 wmep
[WME_AC_VI
].wmep_logcwmin
, wmep
[WME_AC_VI
].wmep_logcwmax
,
3531 wmep
[WME_AC_VI
].wmep_txopLimit
,
3532 wmep
[WME_AC_BK
].wmep_aifsn
,
3533 wmep
[WME_AC_BK
].wmep_logcwmin
, wmep
[WME_AC_BK
].wmep_logcwmax
,
3534 wmep
[WME_AC_BK
].wmep_txopLimit
,
3535 wmep
[WME_AC_BE
].wmep_aifsn
,
3536 wmep
[WME_AC_BE
].wmep_logcwmin
, wmep
[WME_AC_BE
].wmep_logcwmax
,
3537 wmep
[WME_AC_BE
].wmep_txopLimit
);
3539 for (i
= 0; i
< WME_NUM_AC
; i
++)
3540 rt2860_io_mac_write(sc
, RT2860_REG_TX_EDCA_AC_CFG(i
),
3541 (wmep
[i
].wmep_logcwmax
<< 16) | (wmep
[i
].wmep_logcwmin
<< 12) |
3542 (wmep
[i
].wmep_aifsn
<< 8) | wmep
[i
].wmep_txopLimit
);
3544 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WMM_AIFSN_CFG
,
3545 (wmep
[WME_AC_VO
].wmep_aifsn
<< 12) | (wmep
[WME_AC_VI
].wmep_aifsn
<< 8) |
3546 (wmep
[WME_AC_BK
].wmep_aifsn
<< 4) | wmep
[WME_AC_BE
].wmep_aifsn
);
3548 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WMM_CWMIN_CFG
,
3549 (wmep
[WME_AC_VO
].wmep_logcwmin
<< 12) | (wmep
[WME_AC_VI
].wmep_logcwmin
<< 8) |
3550 (wmep
[WME_AC_BK
].wmep_logcwmin
<< 4) | wmep
[WME_AC_BE
].wmep_logcwmin
);
3552 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WMM_CWMAX_CFG
,
3553 (wmep
[WME_AC_VO
].wmep_logcwmax
<< 12) | (wmep
[WME_AC_VI
].wmep_logcwmax
<< 8) |
3554 (wmep
[WME_AC_BK
].wmep_logcwmax
<< 4) | wmep
[WME_AC_BE
].wmep_logcwmax
);
3556 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WMM_TXOP0_CFG
,
3557 (wmep
[WME_AC_BK
].wmep_txopLimit
<< 16) | wmep
[WME_AC_BE
].wmep_txopLimit
);
3559 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WMM_TXOP1_CFG
,
3560 (wmep
[WME_AC_VO
].wmep_txopLimit
<< 16) | wmep
[WME_AC_VI
].wmep_txopLimit
);
3564 * rt2860_asic_update_beacon
3566 static void rt2860_asic_update_beacon(struct rt2860_softc
*sc
,
3567 struct ieee80211vap
*vap
)
3569 struct rt2860_softc_vap
*rvap
;
3571 struct rt2860_txwi
*txwi
;
3574 rvap
= (struct rt2860_softc_vap
*) vap
;
3576 m
= rvap
->beacon_mbuf
;
3577 txwi
= &rvap
->beacon_txwi
;
3579 /* disable temporarily TSF sync */
3581 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_BCN_TIME_CFG
);
3583 tmp
&= ~(RT2860_REG_BCN_TX_ENABLE
|
3584 RT2860_REG_TSF_TIMER_ENABLE
|
3585 RT2860_REG_TBTT_TIMER_ENABLE
);
3587 rt2860_io_mac_write(sc
, RT2860_REG_BCN_TIME_CFG
, tmp
);
3589 /* write Tx wireless info and beacon frame to on-chip memory */
3591 rt2860_io_mac_write_multi(sc
, RT2860_REG_BEACON_BASE(0),
3592 txwi
, sizeof(struct rt2860_txwi
));
3594 rt2860_io_mac_write_multi(sc
, RT2860_REG_BEACON_BASE(0) + sizeof(struct rt2860_txwi
),
3595 mtod(m
, uint8_t *), m
->m_pkthdr
.len
);
3597 /* enable again TSF sync */
3599 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_BCN_TIME_CFG
);
3601 tmp
|= (RT2860_REG_BCN_TX_ENABLE
|
3602 RT2860_REG_TSF_TIMER_ENABLE
|
3603 RT2860_REG_TBTT_TIMER_ENABLE
);
3605 rt2860_io_mac_write(sc
, RT2860_REG_BCN_TIME_CFG
, tmp
);
3609 * rt2860_asic_clear_keytables
3611 static void rt2860_asic_clear_keytables(struct rt2860_softc
*sc
)
3615 /* clear Rx WCID search table (entries = 256, entry size = 8) */
3617 for (i
= 0; i
< 256; i
++)
3619 rt2860_io_mac_write(sc
, RT2860_REG_WCID(i
), 0xffffffff);
3620 rt2860_io_mac_write(sc
, RT2860_REG_WCID(i
) + 4, 0x0000ffff);
3623 /* clear WCID attribute table (entries = 256, entry size = 4) */
3625 rt2860_io_mac_set_region_4(sc
, RT2860_REG_WCID_ATTR(0), 0, 256);
3627 /* clear IV/EIV table (entries = 256, entry size = 8) */
3629 rt2860_io_mac_set_region_4(sc
, RT2860_REG_IVEIV(0), 0, 2 * 256);
3631 /* clear pairwise key table (entries = 64, entry size = 32) */
3633 rt2860_io_mac_set_region_4(sc
, RT2860_REG_PKEY(0), 0, 8 * 64);
3635 /* clear shared key table (entries = 32, entry size = 32) */
3637 rt2860_io_mac_set_region_4(sc
, RT2860_REG_SKEY(0, 0), 0, 8 * 32);
3639 /* clear shared key mode (entries = 32, entry size = 2) */
3641 rt2860_io_mac_set_region_4(sc
, RT2860_REG_SKEY_MODE(0), 0, 16);
3645 * rt2860_beacon_alloc
3647 static int rt2860_beacon_alloc(struct rt2860_softc
*sc
,
3648 struct ieee80211vap
*vap
)
3650 struct ieee80211com
*ic
;
3651 struct rt2860_softc_vap
*rvap
;
3652 const struct ieee80211_txparam
*tp
;
3654 struct rt2860_txwi txwi
;
3658 rvap
= (struct rt2860_softc_vap
*) vap
;
3659 tp
= &vap
->iv_txparms
[ieee80211_chan2mode(ic
->ic_bsschan
)];
3661 m
= ieee80211_beacon_alloc(vap
->iv_bss
, &rvap
->beacon_offsets
);
3665 rate
= tp
->mgmtrate
;
3666 mcs
= rt2860_rate2mcs(rate
);
3668 memset(&txwi
, 0, sizeof(struct rt2860_txwi
));
3671 txwi
.pid_mpdu_len
= ((htole16(m
->m_pkthdr
.len
) & RT2860_TXWI_MPDU_LEN_MASK
) <<
3672 RT2860_TXWI_MPDU_LEN_SHIFT
);
3673 txwi
.txop
= (RT2860_TXWI_TXOP_HT
<< RT2860_TXWI_TXOP_SHIFT
);
3674 txwi
.mpdu_density_flags
|=
3675 (RT2860_TXWI_FLAGS_TS
<< RT2860_TXWI_FLAGS_SHIFT
);
3676 txwi
.bawin_size_xflags
|=
3677 (RT2860_TXWI_XFLAGS_NSEQ
<< RT2860_TXWI_XFLAGS_SHIFT
);
3679 if (ieee80211_rate2phytype(ic
->ic_rt
, rate
) != IEEE80211_T_OFDM
)
3681 txwi
.phymode_ifs_stbc_shortgi
=
3682 (RT2860_TXWI_PHYMODE_CCK
<< RT2860_TXWI_PHYMODE_SHIFT
);
3684 if (rate
!= 2 && (ic
->ic_flags
& IEEE80211_F_SHPREAMBLE
))
3685 mcs
|= RT2860_TXWI_MCS_SHOTPRE
;
3689 txwi
.phymode_ifs_stbc_shortgi
=
3690 (RT2860_TXWI_PHYMODE_OFDM
<< RT2860_TXWI_PHYMODE_SHIFT
);
3693 txwi
.bw_mcs
= (RT2860_TXWI_BW_20
<< RT2860_TXWI_BW_SHIFT
) |
3694 ((mcs
& RT2860_TXWI_MCS_MASK
) << RT2860_TXWI_MCS_SHIFT
);
3696 if (rvap
->beacon_mbuf
!= NULL
)
3698 m_free(rvap
->beacon_mbuf
);
3699 rvap
->beacon_mbuf
= NULL
;
3702 rvap
->beacon_mbuf
= m
;
3703 rvap
->beacon_txwi
= txwi
;
3711 static uint8_t rt2860_rxrate(struct rt2860_rxwi
*rxwi
)
3713 uint8_t mcs
, phymode
;
3716 mcs
= (rxwi
->bw_mcs
>> RT2860_RXWI_MCS_SHIFT
) & RT2860_RXWI_MCS_MASK
;
3717 phymode
= (rxwi
->phymode_stbc_shortgi
>> RT2860_RXWI_PHYMODE_SHIFT
) &
3718 RT2860_RXWI_PHYMODE_MASK
;
3724 case RT2860_RXWI_PHYMODE_CCK
:
3725 switch (mcs
& ~RT2860_RXWI_MCS_SHOTPRE
)
3727 case 0: rate
= 2; break; /* 1 Mbps */
3728 case 1: rate
= 4; break; /* 2 MBps */
3729 case 2: rate
= 11; break; /* 5.5 Mbps */
3730 case 3: rate
= 22; break; /* 11 Mbps */
3734 case RT2860_RXWI_PHYMODE_OFDM
:
3737 case 0: rate
= 12; break; /* 6 Mbps */
3738 case 1: rate
= 18; break; /* 9 Mbps */
3739 case 2: rate
= 24; break; /* 12 Mbps */
3740 case 3: rate
= 36; break; /* 18 Mbps */
3741 case 4: rate
= 48; break; /* 24 Mbps */
3742 case 5: rate
= 72; break; /* 36 Mbps */
3743 case 6: rate
= 96; break; /* 48 Mbps */
3744 case 7: rate
= 108; break; /* 54 Mbps */
3748 case RT2860_RXWI_PHYMODE_HT_MIXED
:
3749 case RT2860_RXWI_PHYMODE_HT_GF
:
3757 * rt2860_maxrssi_rxpath
3759 static uint8_t rt2860_maxrssi_rxpath(struct rt2860_softc
*sc
,
3760 const struct rt2860_rxwi
*rxwi
)
3766 if (sc
->nrxpath
> 1)
3767 if (rxwi
->rssi
[1] > rxwi
->rssi
[rxpath
])
3770 if (sc
->nrxpath
> 2)
3771 if (rxwi
->rssi
[2] > rxwi
->rssi
[rxpath
])
3780 static int8_t rt2860_rssi2dbm(struct rt2860_softc
*sc
,
3781 uint8_t rssi
, uint8_t rxpath
)
3784 struct ieee80211com
*ic
;
3785 struct ieee80211_channel
*c
;
3787 int8_t rssi_off
, lna_gain
;
3795 chan
= ieee80211_chan2ieee(ic
, c
);
3797 if (IEEE80211_IS_CHAN_5GHZ(c
))
3799 rssi_off
= sc
->rssi_off_5ghz
[rxpath
];
3802 lna_gain
= sc
->lna_gain
[1];
3803 else if (chan
<= 128)
3804 lna_gain
= sc
->lna_gain
[2];
3806 lna_gain
= sc
->lna_gain
[3];
3810 rssi_off
= sc
->rssi_off_2ghz
[rxpath
] - sc
->lna_gain
[0];
3811 lna_gain
= sc
->lna_gain
[0];
3814 return (-12 - rssi_off
- lna_gain
- rssi
);
3820 static uint8_t rt2860_rate2mcs(uint8_t rate
)
3847 static int rt2860_tx_mgmt(struct rt2860_softc
*sc
,
3848 struct mbuf
*m
, struct ieee80211_node
*ni
, int qid
)
3851 struct ieee80211com
*ic
;
3852 struct ieee80211vap
*vap
;
3853 const struct ieee80211_txparam
*tp
;
3854 struct rt2860_softc_node
*rni
;
3855 struct rt2860_softc_tx_ring
*ring
;
3856 struct rt2860_softc_tx_data
*data
;
3857 struct rt2860_txdesc
*desc
;
3858 struct rt2860_txwi
*txwi
;
3859 struct ieee80211_frame
*wh
;
3860 struct rt2860_softc_tx_radiotap_header
*tap
;
3861 bus_dma_segment_t dma_seg
[RT2860_SOFTC_MAX_SCATTER
];
3862 u_int hdrsize
, hdrspace
;
3863 uint8_t rate
, stbc
, shortgi
, mcs
, pid
, qsel
;
3864 uint16_t len
, dmalen
, mpdu_len
, dur
;
3865 int error
, mimops
, ndmasegs
, ndescs
, i
, j
;
3867 KASSERT(qid
>= 0 && qid
< RT2860_SOFTC_TX_RING_COUNT
,
3868 ("%s: Tx MGMT: invalid qid=%d\n",
3869 device_get_nameunit(sc
->dev
), qid
));
3874 rni
= (struct rt2860_softc_node
*) ni
;
3875 tp
= ni
->ni_txparms
;
3877 ring
= &sc
->tx_ring
[qid
];
3878 desc
= &ring
->desc
[ring
->desc_cur
];
3879 data
= &ring
->data
[ring
->data_cur
];
3880 txwi
= (struct rt2860_txwi
*) (ring
->seg0
+ ring
->data_cur
* RT2860_TX_DATA_SEG0_SIZE
);
3882 wh
= mtod(m
, struct ieee80211_frame
*);
3884 rate
= tp
->mgmtrate
& IEEE80211_RATE_VAL
;
3886 /* fill Tx wireless info */
3888 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
3891 mcs
= rt2860_rate2mcs(rate
);
3893 /* calculate MPDU length without padding */
3895 hdrsize
= ieee80211_hdrsize(wh
);
3896 hdrspace
= ieee80211_hdrspace(ic
, wh
);
3897 mpdu_len
= m
->m_pkthdr
.len
- hdrspace
+ hdrsize
;
3899 memset(txwi
, 0, sizeof(struct rt2860_txwi
));
3901 /* management frames do not need encryption */
3905 /* MIMO power save */
3907 if ((ni
->ni_flags
& IEEE80211_NODE_HT
) && (ni
->ni_flags
& IEEE80211_NODE_MIMO_PS
))
3911 if (ni
->ni_flags
& IEEE80211_NODE_MIMO_RTS
)
3913 /* dynamic MIMO power save */
3915 txwi
->mpdu_density_flags
|=
3916 (RT2860_TXWI_FLAGS_MIMOPS
<< RT2860_TXWI_FLAGS_SHIFT
);
3920 /* static MIMO power save */
3935 txwi
->pid_mpdu_len
= ((htole16(pid
) & RT2860_TXWI_PID_MASK
) <<
3936 RT2860_TXWI_PID_SHIFT
) | ((htole16(mpdu_len
) & RT2860_TXWI_MPDU_LEN_MASK
) <<
3937 RT2860_TXWI_MPDU_LEN_SHIFT
);
3939 stbc
= (ic
->ic_htcaps
& IEEE80211_HTCAP_TXSTBC
) &&
3940 (ni
->ni_flags
& IEEE80211_NODE_HT
) && (ni
->ni_htcap
& IEEE80211_HTCAP_RXSTBC
);
3942 shortgi
= (vap
->iv_flags_ht
& (IEEE80211_FHT_SHORTGI20
| IEEE80211_FHT_SHORTGI40
)) &&
3943 (ni
->ni_flags
& IEEE80211_NODE_HT
) && (ni
->ni_flags
& (IEEE80211_NODE_SGI20
| IEEE80211_NODE_SGI40
));
3945 txwi
->phymode_ifs_stbc_shortgi
|=
3946 ((stbc
& RT2860_TXWI_STBC_MASK
) << RT2860_TXWI_STBC_SHIFT
) |
3947 ((shortgi
& RT2860_TXWI_SHORTGI_MASK
) << RT2860_TXWI_SHORTGI_SHIFT
);
3949 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
3951 txwi
->phymode_ifs_stbc_shortgi
|=
3952 (RT2860_TXWI_PHYMODE_HT_MIXED
<< RT2860_TXWI_PHYMODE_SHIFT
);
3956 if (ieee80211_rate2phytype(ic
->ic_rt
, rate
) != IEEE80211_T_OFDM
)
3958 txwi
->phymode_ifs_stbc_shortgi
|=
3959 (RT2860_TXWI_PHYMODE_CCK
<< RT2860_TXWI_PHYMODE_SHIFT
);
3961 if (rate
!= 2 && (ic
->ic_flags
& IEEE80211_F_SHPREAMBLE
))
3962 mcs
|= RT2860_TXWI_MCS_SHOTPRE
;
3966 txwi
->phymode_ifs_stbc_shortgi
|=
3967 (RT2860_TXWI_PHYMODE_OFDM
<< RT2860_TXWI_PHYMODE_SHIFT
);
3971 txwi
->bw_mcs
= (RT2860_TXWI_BW_20
<< RT2860_TXWI_BW_SHIFT
) |
3972 ((mcs
& RT2860_TXWI_MCS_MASK
) << RT2860_TXWI_MCS_SHIFT
);
3974 txwi
->txop
= (RT2860_TXWI_TXOP_BACKOFF
<< RT2860_TXWI_TXOP_SHIFT
);
3976 /* skip ACKs for multicast frames */
3978 if (!IEEE80211_IS_MULTICAST(wh
->i_addr1
))
3980 txwi
->bawin_size_xflags
|=
3981 (RT2860_TXWI_XFLAGS_ACK
<< RT2860_TXWI_XFLAGS_SHIFT
);
3983 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
3985 /* preamble + plcp + signal extension + SIFS */
3987 dur
= 16 + 4 + 6 + 10;
3991 dur
= ieee80211_ack_duration(ic
->ic_rt
, rate
,
3992 ic
->ic_flags
& IEEE80211_F_SHPREAMBLE
);
3995 *(uint16_t *) wh
->i_dur
= htole16(dur
);
3998 /* ask MAC to insert timestamp into probe responses */
4000 if ((wh
->i_fc
[0] & (IEEE80211_FC0_TYPE_MASK
| IEEE80211_FC0_SUBTYPE_MASK
)) ==
4001 (IEEE80211_FC0_TYPE_MGT
| IEEE80211_FC0_SUBTYPE_PROBE_RESP
))
4002 txwi
->mpdu_density_flags
|=
4003 (RT2860_TXWI_FLAGS_TS
<< RT2860_TXWI_FLAGS_SHIFT
);
4005 if (ieee80211_radiotap_active_vap(vap
))
4009 tap
->flags
= IEEE80211_RADIOTAP_F_DATAPAD
;
4010 tap
->chan_flags
= htole32(ic
->ic_curchan
->ic_flags
);
4011 tap
->chan_freq
= htole16(ic
->ic_curchan
->ic_freq
);
4012 tap
->chan_ieee
= ic
->ic_curchan
->ic_ieee
;
4013 tap
->chan_maxpow
= 0;
4015 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
4016 tap
->rate
= mcs
| IEEE80211_RATE_MCS
;
4020 if (mcs
& RT2860_TXWI_MCS_SHOTPRE
)
4021 tap
->flags
|= IEEE80211_RADIOTAP_F_SHORTPRE
;
4024 tap
->flags
|= IEEE80211_RADIOTAP_F_SHORTGI
;
4026 if (wh
->i_fc
[1] & IEEE80211_FC1_WEP
)
4027 tap
->flags
|= IEEE80211_RADIOTAP_F_WEP
;
4029 if (wh
->i_fc
[1] & IEEE80211_FC1_WEP
)
4031 wh
->i_fc
[1] &= ~IEEE80211_FC1_WEP
;
4033 ieee80211_radiotap_tx(vap
, m
);
4035 wh
->i_fc
[1] |= IEEE80211_FC1_WEP
;
4039 ieee80211_radiotap_tx(vap
, m
);
4043 /* copy and trim 802.11 header */
4045 m_copydata(m
, 0, hdrsize
, (caddr_t
) (txwi
+ 1));
4048 error
= bus_dmamap_load_mbuf_sg(ring
->data_dma_tag
, data
->dma_map
, m
,
4049 dma_seg
, &ndmasegs
, 0);
4052 /* too many fragments, linearize */
4054 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
4055 "%s: could not load mbuf DMA map, trying to linearize mbuf: ndmasegs=%d, len=%d, error=%d\n",
4056 device_get_nameunit(sc
->dev
), ndmasegs
, m
->m_pkthdr
.len
, error
);
4058 m
= m_defrag(m
, M_DONTWAIT
);
4062 sc
->tx_defrag_packets
++;
4064 error
= bus_dmamap_load_mbuf_sg(ring
->data_dma_tag
, data
->dma_map
, m
,
4065 dma_seg
, &ndmasegs
, 0);
4068 printf("%s: could not load mbuf DMA map: ndmasegs=%d, len=%d, error=%d\n",
4069 device_get_nameunit(sc
->dev
), ndmasegs
, m
->m_pkthdr
.len
, error
);
4075 if (m
->m_pkthdr
.len
== 0)
4078 /* determine how many Tx descs are required */
4080 ndescs
= 1 + ndmasegs
/ 2;
4081 if ((ring
->desc_queued
+ ndescs
) > (RT2860_SOFTC_TX_RING_DESC_COUNT
- 2))
4083 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
4084 "%s: there are not enough Tx descs\n",
4085 device_get_nameunit(sc
->dev
));
4087 sc
->no_tx_desc_avail
++;
4089 bus_dmamap_unload(ring
->data_dma_tag
, data
->dma_map
);
4097 /* set up Tx descs */
4099 /* first segment is Tx wireless info and 802.11 header */
4101 len
= sizeof(struct rt2860_txwi
) + hdrsize
;
4103 /* align end on a 4-bytes boundary */
4105 dmalen
= (len
+ 3) & ~ 3;
4107 memset((caddr_t
) txwi
+ len
, 0, dmalen
- len
);
4109 qsel
= RT2860_TXDESC_QSEL_EDCA
;
4111 desc
->sdp0
= htole32(ring
->seg0_phys_addr
+ ring
->data_cur
* RT2860_TX_DATA_SEG0_SIZE
);
4112 desc
->sdl0
= htole16(dmalen
);
4113 desc
->qsel_flags
= (qsel
<< RT2860_TXDESC_QSEL_SHIFT
);
4115 /* set up payload segments */
4117 for (i
= ndmasegs
, j
= 0; i
>= 2; i
-= 2)
4119 desc
->sdp1
= htole32(dma_seg
[j
].ds_addr
);
4120 desc
->sdl1
= htole16(dma_seg
[j
].ds_len
);
4122 ring
->desc_queued
++;
4123 ring
->desc_cur
= (ring
->desc_cur
+ 1) % RT2860_SOFTC_TX_RING_DESC_COUNT
;
4127 desc
= &ring
->desc
[ring
->desc_cur
];
4129 desc
->sdp0
= htole32(dma_seg
[j
].ds_addr
);
4130 desc
->sdl0
= htole16(dma_seg
[j
].ds_len
);
4131 desc
->qsel_flags
= (qsel
<< RT2860_TXDESC_QSEL_SHIFT
);
4136 /* finalize last payload segment */
4140 desc
->sdp1
= htole32(dma_seg
[j
].ds_addr
);
4141 desc
->sdl1
= htole16(dma_seg
[j
].ds_len
| RT2860_TXDESC_SDL1_LASTSEG
);
4145 desc
->sdl0
|= htole16(RT2860_TXDESC_SDL0_LASTSEG
);
4149 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
4150 "%s: sending MGMT frame: qid=%d, hdrsize=%d, hdrspace=%d, len=%d, "
4151 "stbc=%d, shortgi=%d, mcs=%d, mimops=%d, DMA len=%d, ndmasegs=%d, DMA ds_len=%d/%d/%d/%d/%d\n",
4152 device_get_nameunit(sc
->dev
),
4153 qid
, hdrsize
, hdrspace
, m
->m_pkthdr
.len
+ hdrsize
,
4154 stbc
, shortgi
, mcs
, mimops
, dmalen
, ndmasegs
,
4155 (int) dma_seg
[0].ds_len
, (int) dma_seg
[1].ds_len
, (int) dma_seg
[2].ds_len
, (int) dma_seg
[3].ds_len
, (int) dma_seg
[4].ds_len
);
4157 bus_dmamap_sync(ring
->seg0_dma_tag
, ring
->seg0_dma_map
,
4158 BUS_DMASYNC_PREWRITE
);
4159 bus_dmamap_sync(ring
->data_dma_tag
, data
->dma_map
,
4160 BUS_DMASYNC_PREWRITE
);
4161 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
4162 BUS_DMASYNC_PREWRITE
);
4164 ring
->desc_queued
++;
4165 ring
->desc_cur
= (ring
->desc_cur
+ 1) % RT2860_SOFTC_TX_RING_DESC_COUNT
;
4167 ring
->data_queued
++;
4168 ring
->data_cur
= (ring
->data_cur
+ 1) % RT2860_SOFTC_TX_RING_DATA_COUNT
;
4172 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_CTX_IDX(qid
), ring
->desc_cur
);
4180 static int rt2860_tx_data(struct rt2860_softc
*sc
,
4181 struct mbuf
*m
, struct ieee80211_node
*ni
, int qid
)
4184 struct ieee80211com
*ic
;
4185 struct ieee80211vap
*vap
;
4186 const struct ieee80211_txparam
*tp
;
4187 struct rt2860_softc_node
*rni
;
4188 struct rt2860_softc_tx_ring
*ring
;
4189 struct rt2860_softc_tx_data
*data
;
4190 struct rt2860_txdesc
*desc
;
4191 struct rt2860_txwi
*txwi
;
4192 struct ieee80211_frame
*wh
;
4193 struct ieee80211_tx_ampdu
*tx_ampdu
;
4194 ieee80211_seq seqno
;
4195 struct rt2860_softc_tx_radiotap_header
*tap
;
4196 bus_dma_segment_t dma_seg
[RT2860_SOFTC_MAX_SCATTER
];
4197 u_int hdrsize
, hdrspace
;
4198 uint8_t type
, rate
, bw
, stbc
, shortgi
, mcs
, pid
, wcid
, mpdu_density
, bawin_size
, qsel
;
4199 uint16_t qos
, len
, dmalen
, mpdu_len
, dur
;
4200 int error
, hasqos
, ac
, tid
, ampdu
, mimops
, ndmasegs
, ndescs
, i
, j
;
4202 KASSERT(qid
>= 0 && qid
< RT2860_SOFTC_TX_RING_COUNT
,
4203 ("%s: Tx data: invalid qid=%d\n",
4204 device_get_nameunit(sc
->dev
), qid
));
4209 rni
= (struct rt2860_softc_node
*) ni
;
4210 tp
= ni
->ni_txparms
;
4212 ring
= &sc
->tx_ring
[qid
];
4213 desc
= &ring
->desc
[ring
->desc_cur
];
4214 data
= &ring
->data
[ring
->data_cur
];
4215 txwi
= (struct rt2860_txwi
*) (ring
->seg0
+ ring
->data_cur
* RT2860_TX_DATA_SEG0_SIZE
);
4217 wh
= mtod(m
, struct ieee80211_frame
*);
4219 type
= wh
->i_fc
[0] & IEEE80211_FC0_TYPE_MASK
;
4221 hasqos
= IEEE80211_QOS_HAS_SEQ(wh
);
4224 if (IEEE80211_HAS_ADDR4(wh
))
4225 qos
= le16toh(*(const uint16_t *)
4226 (((struct ieee80211_qosframe_addr4
*) wh
)->i_qos
));
4228 qos
= le16toh(*(const uint16_t *)
4229 (((struct ieee80211_qosframe
*) wh
)->i_qos
));
4236 if (IEEE80211_IS_MULTICAST(wh
->i_addr1
))
4237 rate
= tp
->mcastrate
;
4238 else if (m
->m_flags
& M_EAPOL
)
4239 rate
= tp
->mgmtrate
;
4240 else if (tp
->ucastrate
!= IEEE80211_FIXED_RATE_NONE
)
4241 rate
= tp
->ucastrate
;
4243 rate
= ni
->ni_txrate
;
4245 rate
&= IEEE80211_RATE_VAL
;
4247 /* fill Tx wireless info */
4249 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
4252 mcs
= rt2860_rate2mcs(rate
);
4254 if (type
== IEEE80211_FC0_TYPE_DATA
)
4255 wcid
= !IEEE80211_IS_MULTICAST(wh
->i_addr1
) ? RT2860_AID2WCID(ni
->ni_associd
) : 0;
4259 /* calculate MPDU length without padding */
4261 hdrsize
= ieee80211_hdrsize(wh
);
4262 hdrspace
= ieee80211_hdrspace(ic
, wh
);
4263 mpdu_len
= m
->m_pkthdr
.len
- hdrspace
+ hdrsize
;
4265 memset(txwi
, 0, sizeof(struct rt2860_txwi
));
4269 /* MIMO power save */
4271 if ((ni
->ni_flags
& IEEE80211_NODE_HT
) && (ni
->ni_flags
& IEEE80211_NODE_MIMO_PS
))
4275 if (ni
->ni_flags
& IEEE80211_NODE_MIMO_RTS
)
4277 /* dynamic MIMO power save */
4279 txwi
->mpdu_density_flags
|=
4280 (RT2860_TXWI_FLAGS_MIMOPS
<< RT2860_TXWI_FLAGS_SHIFT
);
4284 /* static MIMO power save */
4299 txwi
->pid_mpdu_len
= ((htole16(pid
) & RT2860_TXWI_PID_MASK
) <<
4300 RT2860_TXWI_PID_SHIFT
) | ((htole16(mpdu_len
) & RT2860_TXWI_MPDU_LEN_MASK
) <<
4301 RT2860_TXWI_MPDU_LEN_SHIFT
);
4303 stbc
= (ic
->ic_htcaps
& IEEE80211_HTCAP_TXSTBC
) &&
4304 (ni
->ni_flags
& IEEE80211_NODE_HT
) && (ni
->ni_htcap
& IEEE80211_HTCAP_RXSTBC
);
4306 shortgi
= (vap
->iv_flags_ht
& (IEEE80211_FHT_SHORTGI20
| IEEE80211_FHT_SHORTGI40
)) &&
4307 (ni
->ni_flags
& IEEE80211_NODE_HT
) && (ni
->ni_flags
& (IEEE80211_NODE_SGI20
| IEEE80211_NODE_SGI40
));
4309 txwi
->phymode_ifs_stbc_shortgi
|=
4310 ((stbc
& RT2860_TXWI_STBC_MASK
) << RT2860_TXWI_STBC_SHIFT
) |
4311 ((shortgi
& RT2860_TXWI_SHORTGI_MASK
) << RT2860_TXWI_SHORTGI_SHIFT
);
4313 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
4315 txwi
->phymode_ifs_stbc_shortgi
|=
4316 (RT2860_TXWI_PHYMODE_HT_MIXED
<< RT2860_TXWI_PHYMODE_SHIFT
);
4320 if (ieee80211_rate2phytype(ic
->ic_rt
, rate
) != IEEE80211_T_OFDM
)
4322 txwi
->phymode_ifs_stbc_shortgi
|=
4323 (RT2860_TXWI_PHYMODE_CCK
<< RT2860_TXWI_PHYMODE_SHIFT
);
4325 if (rate
!= 2 && (ic
->ic_flags
& IEEE80211_F_SHPREAMBLE
))
4326 mcs
|= RT2860_TXWI_MCS_SHOTPRE
;
4330 txwi
->phymode_ifs_stbc_shortgi
|=
4331 (RT2860_TXWI_PHYMODE_OFDM
<< RT2860_TXWI_PHYMODE_SHIFT
);
4335 if ((ni
->ni_flags
& IEEE80211_NODE_HT
) && (ni
->ni_chw
== 40))
4336 bw
= RT2860_TXWI_BW_40
;
4338 bw
= RT2860_TXWI_BW_20
;
4340 txwi
->bw_mcs
= ((bw
& RT2860_TXWI_BW_MASK
) << RT2860_TXWI_BW_SHIFT
) |
4341 ((mcs
& RT2860_TXWI_MCS_MASK
) << RT2860_TXWI_MCS_SHIFT
);
4343 txwi
->txop
= (RT2860_TXWI_TXOP_HT
<< RT2860_TXWI_TXOP_SHIFT
);
4345 if (!IEEE80211_IS_MULTICAST(wh
->i_addr1
) &&
4346 (!hasqos
|| (qos
& IEEE80211_QOS_ACKPOLICY
) != IEEE80211_QOS_ACKPOLICY_NOACK
))
4348 txwi
->bawin_size_xflags
|=
4349 (RT2860_TXWI_XFLAGS_ACK
<< RT2860_TXWI_XFLAGS_SHIFT
);
4351 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
4353 /* preamble + plcp + signal extension + SIFS */
4355 dur
= 16 + 4 + 6 + 10;
4359 dur
= ieee80211_ack_duration(ic
->ic_rt
, rate
,
4360 ic
->ic_flags
& IEEE80211_F_SHPREAMBLE
);
4363 *(uint16_t *) wh
->i_dur
= htole16(dur
);
4366 /* check for A-MPDU */
4368 if (m
->m_flags
& M_AMPDU_MPDU
)
4370 ac
= M_WME_GETAC(m
);
4371 tid
= WME_AC_TO_TID(ac
);
4372 tx_ampdu
= &ni
->ni_tx_ampdu
[ac
];
4374 mpdu_density
= RT2860_MS(ni
->ni_htparam
, IEEE80211_HTCAP_MPDUDENSITY
);
4375 bawin_size
= tx_ampdu
->txa_wnd
;
4377 txwi
->mpdu_density_flags
|=
4378 ((mpdu_density
& RT2860_TXWI_MPDU_DENSITY_MASK
) << RT2860_TXWI_MPDU_DENSITY_SHIFT
) |
4379 (RT2860_TXWI_FLAGS_AMPDU
<< RT2860_TXWI_FLAGS_SHIFT
);
4381 txwi
->bawin_size_xflags
|=
4382 ((bawin_size
& RT2860_TXWI_BAWIN_SIZE_MASK
) << RT2860_TXWI_BAWIN_SIZE_SHIFT
);
4384 seqno
= ni
->ni_txseqs
[tid
]++;
4386 *(uint16_t *) &wh
->i_seq
[0] = htole16(seqno
<< IEEE80211_SEQ_SEQ_SHIFT
);
4395 /* ask MAC to insert timestamp into probe responses */
4397 if ((wh
->i_fc
[0] & (IEEE80211_FC0_TYPE_MASK
| IEEE80211_FC0_SUBTYPE_MASK
)) ==
4398 (IEEE80211_FC0_TYPE_MGT
| IEEE80211_FC0_SUBTYPE_PROBE_RESP
))
4399 txwi
->mpdu_density_flags
|=
4400 (RT2860_TXWI_FLAGS_TS
<< RT2860_TXWI_FLAGS_SHIFT
);
4402 if (ieee80211_radiotap_active_vap(vap
))
4406 tap
->flags
= IEEE80211_RADIOTAP_F_DATAPAD
;
4407 tap
->chan_flags
= htole32(ic
->ic_curchan
->ic_flags
);
4408 tap
->chan_freq
= htole16(ic
->ic_curchan
->ic_freq
);
4409 tap
->chan_ieee
= ic
->ic_curchan
->ic_ieee
;
4410 tap
->chan_maxpow
= 0;
4412 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
4413 tap
->rate
= mcs
| IEEE80211_RATE_MCS
;
4417 if (mcs
& RT2860_TXWI_MCS_SHOTPRE
)
4418 tap
->flags
|= IEEE80211_RADIOTAP_F_SHORTPRE
;
4421 tap
->flags
|= IEEE80211_RADIOTAP_F_SHORTGI
;
4423 if (wh
->i_fc
[1] & IEEE80211_FC1_WEP
)
4424 tap
->flags
|= IEEE80211_RADIOTAP_F_WEP
;
4426 if (wh
->i_fc
[1] & IEEE80211_FC1_WEP
)
4428 wh
->i_fc
[1] &= ~IEEE80211_FC1_WEP
;
4430 ieee80211_radiotap_tx(vap
, m
);
4432 wh
->i_fc
[1] |= IEEE80211_FC1_WEP
;
4436 ieee80211_radiotap_tx(vap
, m
);
4440 /* copy and trim 802.11 header */
4442 m_copydata(m
, 0, hdrsize
, (caddr_t
) (txwi
+ 1));
4445 error
= bus_dmamap_load_mbuf_sg(ring
->data_dma_tag
, data
->dma_map
, m
,
4446 dma_seg
, &ndmasegs
, 0);
4449 /* too many fragments, linearize */
4451 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
4452 "%s: could not load mbuf DMA map, trying to linearize mbuf: ndmasegs=%d, len=%d, error=%d\n",
4453 device_get_nameunit(sc
->dev
), ndmasegs
, m
->m_pkthdr
.len
, error
);
4455 m
= m_defrag(m
, M_DONTWAIT
);
4459 sc
->tx_defrag_packets
++;
4461 error
= bus_dmamap_load_mbuf_sg(ring
->data_dma_tag
, data
->dma_map
, m
,
4462 dma_seg
, &ndmasegs
, 0);
4465 printf("%s: could not load mbuf DMA map: ndmasegs=%d, len=%d, error=%d\n",
4466 device_get_nameunit(sc
->dev
), ndmasegs
, m
->m_pkthdr
.len
, error
);
4472 if (m
->m_pkthdr
.len
== 0)
4475 /* determine how many Tx descs are required */
4477 ndescs
= 1 + ndmasegs
/ 2;
4478 if ((ring
->desc_queued
+ ndescs
) > (RT2860_SOFTC_TX_RING_DESC_COUNT
- 2))
4480 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
4481 "%s: there are not enough Tx descs\n",
4482 device_get_nameunit(sc
->dev
));
4484 sc
->no_tx_desc_avail
++;
4486 bus_dmamap_unload(ring
->data_dma_tag
, data
->dma_map
);
4494 /* set up Tx descs */
4496 /* first segment is Tx wireless info and 802.11 header */
4498 len
= sizeof(struct rt2860_txwi
) + hdrsize
;
4500 /* align end on a 4-bytes boundary */
4502 dmalen
= (len
+ 3) & ~ 3;
4504 memset((caddr_t
) txwi
+ len
, 0, dmalen
- len
);
4506 qsel
= RT2860_TXDESC_QSEL_EDCA
;
4508 desc
->sdp0
= htole32(ring
->seg0_phys_addr
+ ring
->data_cur
* RT2860_TX_DATA_SEG0_SIZE
);
4509 desc
->sdl0
= htole16(dmalen
);
4510 desc
->qsel_flags
= (qsel
<< RT2860_TXDESC_QSEL_SHIFT
);
4512 /* set up payload segments */
4514 for (i
= ndmasegs
, j
= 0; i
>= 2; i
-= 2)
4516 desc
->sdp1
= htole32(dma_seg
[j
].ds_addr
);
4517 desc
->sdl1
= htole16(dma_seg
[j
].ds_len
);
4519 ring
->desc_queued
++;
4520 ring
->desc_cur
= (ring
->desc_cur
+ 1) % RT2860_SOFTC_TX_RING_DESC_COUNT
;
4524 desc
= &ring
->desc
[ring
->desc_cur
];
4526 desc
->sdp0
= htole32(dma_seg
[j
].ds_addr
);
4527 desc
->sdl0
= htole16(dma_seg
[j
].ds_len
);
4528 desc
->qsel_flags
= (qsel
<< RT2860_TXDESC_QSEL_SHIFT
);
4533 /* finalize last payload segment */
4537 desc
->sdp1
= htole32(dma_seg
[j
].ds_addr
);
4538 desc
->sdl1
= htole16(dma_seg
[j
].ds_len
| RT2860_TXDESC_SDL1_LASTSEG
);
4542 desc
->sdl0
|= htole16(RT2860_TXDESC_SDL0_LASTSEG
);
4546 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
4547 "%s: sending data: qid=%d, hdrsize=%d, hdrspace=%d, len=%d, "
4548 "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",
4549 device_get_nameunit(sc
->dev
),
4550 qid
, hdrsize
, hdrspace
, m
->m_pkthdr
.len
+ hdrsize
,
4551 bw
, stbc
, shortgi
, mcs
, wcid
, ampdu
, mimops
, dmalen
, ndmasegs
,
4552 (int) dma_seg
[0].ds_len
, (int) dma_seg
[1].ds_len
, (int) dma_seg
[2].ds_len
, (int) dma_seg
[3].ds_len
, (int) dma_seg
[4].ds_len
);
4554 bus_dmamap_sync(ring
->seg0_dma_tag
, ring
->seg0_dma_map
,
4555 BUS_DMASYNC_PREWRITE
);
4556 bus_dmamap_sync(ring
->data_dma_tag
, data
->dma_map
,
4557 BUS_DMASYNC_PREWRITE
);
4558 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
4559 BUS_DMASYNC_PREWRITE
);
4561 ring
->desc_queued
++;
4562 ring
->desc_cur
= (ring
->desc_cur
+ 1) % RT2860_SOFTC_TX_RING_DESC_COUNT
;
4564 ring
->data_queued
++;
4565 ring
->data_cur
= (ring
->data_cur
+ 1) % RT2860_SOFTC_TX_RING_DATA_COUNT
;
4569 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_CTX_IDX(qid
), ring
->desc_cur
);
4577 static int rt2860_tx_raw(struct rt2860_softc
*sc
,
4578 struct mbuf
*m
, struct ieee80211_node
*ni
,
4579 const struct ieee80211_bpf_params
*params
)
4581 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
4583 device_get_nameunit(sc
->dev
));
4591 static void rt2860_intr(void *arg
)
4593 struct rt2860_softc
*sc
;
4600 /* acknowledge interrupts */
4602 status
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_INT_STATUS
);
4603 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_INT_STATUS
, status
);
4605 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4606 "%s: interrupt: status = 0x%08x\n",
4607 device_get_nameunit(sc
->dev
), status
);
4609 if (status
== 0xffffffff || /* device likely went away */
4610 status
== 0) /* not for us */
4615 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
4618 if (status
& RT2860_REG_INT_TX_COHERENT
)
4619 rt2860_tx_coherent_intr(sc
);
4621 if (status
& RT2860_REG_INT_RX_COHERENT
)
4622 rt2860_rx_coherent_intr(sc
);
4624 if (status
& RT2860_REG_INT_TXRX_COHERENT
)
4625 rt2860_txrx_coherent_intr(sc
);
4627 if (status
& RT2860_REG_INT_FIFO_STA_FULL
)
4628 rt2860_fifo_sta_full_intr(sc
);
4630 if (status
& RT2860_REG_INT_TX_MGMT_DONE
)
4631 rt2860_tx_intr(sc
, 5);
4633 if (status
& RT2860_REG_INT_RX_DONE
)
4636 if (status
& RT2860_REG_INT_RX_DELAY_DONE
)
4637 rt2860_rx_delay_intr(sc
);
4639 if (status
& RT2860_REG_INT_TX_HCCA_DONE
)
4640 rt2860_tx_intr(sc
, 4);
4642 if (status
& RT2860_REG_INT_TX_AC3_DONE
)
4643 rt2860_tx_intr(sc
, 3);
4645 if (status
& RT2860_REG_INT_TX_AC2_DONE
)
4646 rt2860_tx_intr(sc
, 2);
4648 if (status
& RT2860_REG_INT_TX_AC1_DONE
)
4649 rt2860_tx_intr(sc
, 1);
4651 if (status
& RT2860_REG_INT_TX_AC0_DONE
)
4652 rt2860_tx_intr(sc
, 0);
4654 if (status
& RT2860_REG_INT_TX_DELAY_DONE
)
4655 rt2860_tx_delay_intr(sc
);
4657 if (status
& RT2860_REG_INT_PRE_TBTT
)
4658 rt2860_pre_tbtt_intr(sc
);
4660 if (status
& RT2860_REG_INT_TBTT
)
4661 rt2860_tbtt_intr(sc
);
4663 if (status
& RT2860_REG_INT_MCU_CMD
)
4664 rt2860_mcu_cmd_intr(sc
);
4666 if (status
& RT2860_REG_INT_AUTO_WAKEUP
)
4667 rt2860_auto_wakeup_intr(sc
);
4669 if (status
& RT2860_REG_INT_GP_TIMER
)
4670 rt2860_gp_timer_intr(sc
);
4674 * rt2860_tx_coherent_intr
4676 static void rt2860_tx_coherent_intr(struct rt2860_softc
*sc
)
4681 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4682 "%s: Tx coherent interrupt\n",
4683 device_get_nameunit(sc
->dev
));
4685 sc
->tx_coherent_interrupts
++;
4687 /* restart DMA engine */
4689 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
);
4691 tmp
&= ~(RT2860_REG_TX_WB_DDONE
|
4692 RT2860_REG_RX_DMA_ENABLE
|
4693 RT2860_REG_TX_DMA_ENABLE
);
4695 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
, tmp
);
4697 /* init Tx rings (4 EDCAs + HCCA + MGMT) */
4699 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
4700 rt2860_reset_tx_ring(sc
, &sc
->tx_ring
[i
]);
4702 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
4704 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_BASE_PTR(i
),
4705 sc
->tx_ring
[i
].desc_phys_addr
);
4706 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_MAX_CNT(i
),
4707 RT2860_SOFTC_TX_RING_DESC_COUNT
);
4708 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_CTX_IDX(i
), 0);
4713 rt2860_reset_rx_ring(sc
, &sc
->rx_ring
);
4715 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_BASE_PTR
,
4716 sc
->rx_ring
.desc_phys_addr
);
4717 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_MAX_CNT
,
4718 RT2860_SOFTC_RX_RING_DATA_COUNT
);
4719 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_CALC_IDX
,
4720 RT2860_SOFTC_RX_RING_DATA_COUNT
- 1);
4722 rt2860_txrx_enable(sc
);
4726 * rt2860_rx_coherent_intr
4728 static void rt2860_rx_coherent_intr(struct rt2860_softc
*sc
)
4733 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4734 "%s: Rx coherent interrupt\n",
4735 device_get_nameunit(sc
->dev
));
4737 sc
->rx_coherent_interrupts
++;
4739 /* restart DMA engine */
4741 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
);
4743 tmp
&= ~(RT2860_REG_TX_WB_DDONE
|
4744 RT2860_REG_RX_DMA_ENABLE
|
4745 RT2860_REG_TX_DMA_ENABLE
);
4747 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
, tmp
);
4749 /* init Tx rings (4 EDCAs + HCCA + MGMT) */
4751 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
4752 rt2860_reset_tx_ring(sc
, &sc
->tx_ring
[i
]);
4754 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
4756 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_BASE_PTR(i
),
4757 sc
->tx_ring
[i
].desc_phys_addr
);
4758 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_MAX_CNT(i
),
4759 RT2860_SOFTC_TX_RING_DESC_COUNT
);
4760 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_CTX_IDX(i
), 0);
4765 rt2860_reset_rx_ring(sc
, &sc
->rx_ring
);
4767 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_BASE_PTR
,
4768 sc
->rx_ring
.desc_phys_addr
);
4769 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_MAX_CNT
,
4770 RT2860_SOFTC_RX_RING_DATA_COUNT
);
4771 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_CALC_IDX
,
4772 RT2860_SOFTC_RX_RING_DATA_COUNT
- 1);
4774 rt2860_txrx_enable(sc
);
4778 * rt2860_txrx_coherent_intr
4780 static void rt2860_txrx_coherent_intr(struct rt2860_softc
*sc
)
4785 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4786 "%s: Tx/Rx coherent interrupt\n",
4787 device_get_nameunit(sc
->dev
));
4789 sc
->txrx_coherent_interrupts
++;
4791 /* restart DMA engine */
4793 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
);
4795 tmp
&= ~(RT2860_REG_TX_WB_DDONE
|
4796 RT2860_REG_RX_DMA_ENABLE
|
4797 RT2860_REG_TX_DMA_ENABLE
);
4799 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
, tmp
);
4801 /* init Tx rings (4 EDCAs + HCCA + MGMT) */
4803 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
4804 rt2860_reset_tx_ring(sc
, &sc
->tx_ring
[i
]);
4806 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
4808 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_BASE_PTR(i
),
4809 sc
->tx_ring
[i
].desc_phys_addr
);
4810 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_MAX_CNT(i
),
4811 RT2860_SOFTC_TX_RING_DESC_COUNT
);
4812 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_CTX_IDX(i
), 0);
4817 rt2860_reset_rx_ring(sc
, &sc
->rx_ring
);
4819 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_BASE_PTR
,
4820 sc
->rx_ring
.desc_phys_addr
);
4821 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_MAX_CNT
,
4822 RT2860_SOFTC_RX_RING_DATA_COUNT
);
4823 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_CALC_IDX
,
4824 RT2860_SOFTC_RX_RING_DATA_COUNT
- 1);
4826 rt2860_txrx_enable(sc
);
4830 * rt2860_fifo_sta_full_intr
4832 static void rt2860_fifo_sta_full_intr(struct rt2860_softc
*sc
)
4834 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4835 "%s: FIFO statistic full interrupt\n",
4836 device_get_nameunit(sc
->dev
));
4838 sc
->fifo_sta_full_interrupts
++;
4840 RT2860_SOFTC_LOCK(sc
);
4842 if (!(sc
->intr_disable_mask
& RT2860_REG_INT_FIFO_STA_FULL
))
4844 rt2860_intr_disable(sc
, RT2860_REG_INT_FIFO_STA_FULL
);
4846 taskqueue_enqueue(sc
->taskqueue
, &sc
->fifo_sta_full_task
);
4849 sc
->intr_pending_mask
|= RT2860_REG_INT_FIFO_STA_FULL
;
4851 RT2860_SOFTC_UNLOCK(sc
);
4857 static void rt2860_rx_intr(struct rt2860_softc
*sc
)
4859 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4860 "%s: Rx interrupt\n",
4861 device_get_nameunit(sc
->dev
));
4863 sc
->rx_interrupts
++;
4865 RT2860_SOFTC_LOCK(sc
);
4867 if (!(sc
->intr_disable_mask
& RT2860_REG_INT_RX_DONE
))
4869 rt2860_intr_disable(sc
, RT2860_REG_INT_RX_DONE
);
4871 taskqueue_enqueue(sc
->taskqueue
, &sc
->rx_done_task
);
4874 sc
->intr_pending_mask
|= RT2860_REG_INT_RX_DONE
;
4876 RT2860_SOFTC_UNLOCK(sc
);
4880 * rt2860_rx_delay_intr
4882 static void rt2860_rx_delay_intr(struct rt2860_softc
*sc
)
4884 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4885 "%s: Rx delay interrupt\n",
4886 device_get_nameunit(sc
->dev
));
4888 sc
->rx_delay_interrupts
++;
4894 static void rt2860_tx_intr(struct rt2860_softc
*sc
, int qid
)
4896 KASSERT(qid
>= 0 && qid
< RT2860_SOFTC_TX_RING_COUNT
,
4897 ("%s: Tx interrupt: invalid qid=%d\n",
4898 device_get_nameunit(sc
->dev
), qid
));
4900 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4901 "%s: Tx interrupt: qid=%d\n",
4902 device_get_nameunit(sc
->dev
), qid
);
4904 sc
->tx_interrupts
[qid
]++;
4906 RT2860_SOFTC_LOCK(sc
);
4908 if (!(sc
->intr_disable_mask
& (RT2860_REG_INT_TX_AC0_DONE
<< qid
)))
4910 rt2860_intr_disable(sc
, (RT2860_REG_INT_TX_AC0_DONE
<< qid
));
4912 taskqueue_enqueue(sc
->taskqueue
, &sc
->tx_done_task
);
4915 sc
->intr_pending_mask
|= (RT2860_REG_INT_TX_AC0_DONE
<< qid
);
4917 RT2860_SOFTC_UNLOCK(sc
);
4921 * rt2860_tx_delay_intr
4923 static void rt2860_tx_delay_intr(struct rt2860_softc
*sc
)
4925 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4926 "%s: Tx delay interrupt\n",
4927 device_get_nameunit(sc
->dev
));
4929 sc
->tx_delay_interrupts
++;
4933 * rt2860_pre_tbtt_intr
4935 static void rt2860_pre_tbtt_intr(struct rt2860_softc
*sc
)
4937 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4938 "%s: Pre-TBTT interrupt\n",
4939 device_get_nameunit(sc
->dev
));
4941 sc
->pre_tbtt_interrupts
++;
4947 static void rt2860_tbtt_intr(struct rt2860_softc
*sc
)
4949 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4950 "%s: TBTT interrupt\n",
4951 device_get_nameunit(sc
->dev
));
4953 sc
->tbtt_interrupts
++;
4957 * rt2860_mcu_cmd_intr
4959 static void rt2860_mcu_cmd_intr(struct rt2860_softc
*sc
)
4961 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4962 "%s: MCU command interrupt\n",
4963 device_get_nameunit(sc
->dev
));
4965 sc
->mcu_cmd_interrupts
++;
4969 * rt2860_auto_wakeup_intr
4971 static void rt2860_auto_wakeup_intr(struct rt2860_softc
*sc
)
4973 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4974 "%s: auto wakeup interrupt\n",
4975 device_get_nameunit(sc
->dev
));
4977 sc
->auto_wakeup_interrupts
++;
4981 * rt2860_gp_timer_intr
4983 static void rt2860_gp_timer_intr(struct rt2860_softc
*sc
)
4985 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4986 "%s: GP timer interrupt\n",
4987 device_get_nameunit(sc
->dev
));
4989 sc
->gp_timer_interrupts
++;
4993 * rt2860_rx_done_task
4995 static void rt2860_rx_done_task(void *context
, int pending
)
4997 struct rt2860_softc
*sc
;
5004 RT2860_DPRINTF(sc
, RT2860_DEBUG_RX
,
5005 "%s: Rx done task\n",
5006 device_get_nameunit(sc
->dev
));
5008 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
5011 sc
->intr_pending_mask
&= ~RT2860_REG_INT_RX_DONE
;
5013 again
= rt2860_rx_eof(sc
, sc
->rx_process_limit
);
5015 RT2860_SOFTC_LOCK(sc
);
5017 if ((sc
->intr_pending_mask
& RT2860_REG_INT_RX_DONE
) || again
)
5019 RT2860_DPRINTF(sc
, RT2860_DEBUG_RX
,
5020 "%s: Rx done task: scheduling again\n",
5021 device_get_nameunit(sc
->dev
));
5023 taskqueue_enqueue(sc
->taskqueue
, &sc
->rx_done_task
);
5027 rt2860_intr_enable(sc
, RT2860_REG_INT_RX_DONE
);
5030 RT2860_SOFTC_UNLOCK(sc
);
5034 * rt2860_tx_done_task
5036 static void rt2860_tx_done_task(void *context
, int pending
)
5038 struct rt2860_softc
*sc
;
5046 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
5047 "%s: Tx done task\n",
5048 device_get_nameunit(sc
->dev
));
5050 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
5053 for (i
= RT2860_SOFTC_TX_RING_COUNT
- 1; i
>= 0; i
--)
5055 if (sc
->intr_pending_mask
& (RT2860_REG_INT_TX_AC0_DONE
<< i
))
5057 sc
->intr_pending_mask
&= ~(RT2860_REG_INT_TX_AC0_DONE
<< i
);
5059 rt2860_tx_eof(sc
, &sc
->tx_ring
[i
]);
5065 ifp
->if_drv_flags
&= ~IFF_DRV_OACTIVE
;
5067 intr_mask
= (RT2860_REG_INT_TX_MGMT_DONE
|
5068 RT2860_REG_INT_TX_HCCA_DONE
|
5069 RT2860_REG_INT_TX_AC3_DONE
|
5070 RT2860_REG_INT_TX_AC2_DONE
|
5071 RT2860_REG_INT_TX_AC1_DONE
|
5072 RT2860_REG_INT_TX_AC0_DONE
);
5074 RT2860_SOFTC_LOCK(sc
);
5076 rt2860_intr_enable(sc
, ~sc
->intr_pending_mask
&
5077 (sc
->intr_disable_mask
& intr_mask
));
5079 if (sc
->intr_pending_mask
& intr_mask
)
5081 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
5082 "%s: Tx done task: scheduling again\n",
5083 device_get_nameunit(sc
->dev
));
5085 taskqueue_enqueue(sc
->taskqueue
, &sc
->tx_done_task
);
5088 RT2860_SOFTC_UNLOCK(sc
);
5092 * rt2860_fifo_sta_full_task
5094 static void rt2860_fifo_sta_full_task(void *context
, int pending
)
5096 struct rt2860_softc
*sc
;
5102 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATS
,
5103 "%s: FIFO statistic full task\n",
5104 device_get_nameunit(sc
->dev
));
5106 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
5109 sc
->intr_pending_mask
&= ~RT2860_REG_INT_FIFO_STA_FULL
;
5111 rt2860_drain_fifo_stats(sc
);
5113 RT2860_SOFTC_LOCK(sc
);
5115 if (sc
->intr_pending_mask
& RT2860_REG_INT_FIFO_STA_FULL
)
5117 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATS
,
5118 "%s: FIFO statistic full task: scheduling again\n",
5119 device_get_nameunit(sc
->dev
));
5121 taskqueue_enqueue(sc
->taskqueue
, &sc
->fifo_sta_full_task
);
5125 rt2860_intr_enable(sc
, RT2860_REG_INT_FIFO_STA_FULL
);
5128 RT2860_SOFTC_UNLOCK(sc
);
5132 * rt2860_periodic_task
5134 static void rt2860_periodic_task(void *context
, int pending
)
5136 struct rt2860_softc
*sc
;
5138 struct ieee80211com
*ic
;
5139 struct ieee80211vap
*vap
;
5144 vap
= TAILQ_FIRST(&ic
->ic_vaps
);
5146 RT2860_DPRINTF(sc
, RT2860_DEBUG_PERIODIC
,
5147 "%s: periodic task: round=%lu\n",
5148 device_get_nameunit(sc
->dev
), sc
->periodic_round
);
5150 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
5153 RT2860_SOFTC_LOCK(sc
);
5155 sc
->periodic_round
++;
5157 rt2860_update_stats(sc
);
5159 if ((sc
->periodic_round
% 10) == 0)
5161 rt2860_bbp_tuning(sc
);
5163 rt2860_update_raw_counters(sc
);
5165 rt2860_watchdog(sc
);
5167 if (vap
!= NULL
&& vap
->iv_opmode
!= IEEE80211_M_MONITOR
&& vap
->iv_state
== IEEE80211_S_RUN
)
5169 if (vap
->iv_opmode
== IEEE80211_M_STA
)
5170 rt2860_amrr_update_iter_func(vap
, vap
->iv_bss
);
5172 ieee80211_iterate_nodes(&ic
->ic_sta
, rt2860_amrr_update_iter_func
, vap
);
5176 RT2860_SOFTC_UNLOCK(sc
);
5178 callout_reset(&sc
->periodic_ch
, hz
/ 10, rt2860_periodic
, sc
);
5184 static int rt2860_rx_eof(struct rt2860_softc
*sc
, int limit
)
5187 struct ieee80211com
*ic
;
5188 struct ieee80211_frame
*wh
;
5189 struct ieee80211_node
*ni
;
5190 struct rt2860_softc_node
*rni
;
5191 struct rt2860_softc_rx_radiotap_header
*tap
;
5192 struct rt2860_softc_rx_ring
*ring
;
5193 struct rt2860_rxdesc
*desc
;
5194 struct rt2860_softc_rx_data
*data
;
5195 struct rt2860_rxwi
*rxwi
;
5196 struct mbuf
*m
, *mnew
;
5197 bus_dma_segment_t segs
[1];
5198 bus_dmamap_t dma_map
;
5199 uint32_t index
, desc_flags
;
5200 uint8_t cipher_err
, rssi
, ant
, phymode
, bw
, shortgi
, mcs
, keyidx
;
5202 int error
, nsegs
, len
, ampdu
, amsdu
, rssi_dbm_rel
, nframes
, i
;
5206 ring
= &sc
->rx_ring
;
5212 index
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_RX_DRX_IDX
);
5213 if (ring
->cur
== index
)
5216 desc
= &ring
->desc
[ring
->cur
];
5217 desc_flags
= le32toh(desc
->flags
);
5218 data
= &ring
->data
[ring
->cur
];
5220 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
5221 BUS_DMASYNC_POSTREAD
| BUS_DMASYNC_POSTWRITE
);
5223 if (!(desc
->sdl0
& htole16(RT2860_RXDESC_SDL0_DDONE
)))
5228 mnew
= m_getjcl(M_DONTWAIT
, MT_DATA
, M_PKTHDR
, MJUMPAGESIZE
);
5231 sc
->rx_mbuf_alloc_errors
++;
5236 mnew
->m_len
= mnew
->m_pkthdr
.len
= MJUMPAGESIZE
;
5238 error
= bus_dmamap_load_mbuf_sg(ring
->data_dma_tag
, ring
->spare_dma_map
,
5239 mnew
, segs
, &nsegs
, BUS_DMA_NOWAIT
);
5242 RT2860_DPRINTF(sc
, RT2860_DEBUG_RX
,
5243 "%s: could not load Rx mbuf DMA map: error=%d, nsegs=%d\n",
5244 device_get_nameunit(sc
->dev
), error
, nsegs
);
5248 sc
->rx_mbuf_dmamap_errors
++;
5254 KASSERT(nsegs
== 1, ("%s: too many DMA segments",
5255 device_get_nameunit(sc
->dev
)));
5257 bus_dmamap_sync(ring
->data_dma_tag
, data
->dma_map
,
5258 BUS_DMASYNC_POSTREAD
);
5259 bus_dmamap_unload(ring
->data_dma_tag
, data
->dma_map
);
5261 dma_map
= data
->dma_map
;
5262 data
->dma_map
= ring
->spare_dma_map
;
5263 ring
->spare_dma_map
= dma_map
;
5265 bus_dmamap_sync(ring
->data_dma_tag
, data
->dma_map
,
5266 BUS_DMASYNC_PREREAD
);
5271 desc
->sdp0
= htole32(segs
[0].ds_addr
);
5273 /* get Rx wireless info */
5275 rxwi
= mtod(m
, struct rt2860_rxwi
*);
5276 len
= (le16toh(rxwi
->tid_size
) >> RT2860_RXWI_SIZE_SHIFT
) &
5277 RT2860_RXWI_SIZE_MASK
;
5279 /* check for L2 padding between IEEE 802.11 frame header and body */
5281 if (desc_flags
& RT2860_RXDESC_FLAGS_L2PAD
)
5283 RT2860_DPRINTF(sc
, RT2860_DEBUG_RX
,
5284 "%s: L2 padding: len=%d\n",
5285 device_get_nameunit(sc
->dev
), len
);
5290 m
->m_pkthdr
.rcvif
= ifp
;
5291 m
->m_data
= (caddr_t
) (rxwi
+ 1);
5292 m
->m_pkthdr
.len
= m
->m_len
= len
;
5294 /* check for crc errors */
5296 if (desc_flags
& RT2860_RXDESC_FLAGS_CRC_ERR
)
5298 RT2860_DPRINTF(sc
, RT2860_DEBUG_RX
,
5299 "%s: rxdesc: crc error\n",
5300 device_get_nameunit(sc
->dev
));
5304 if (!(ifp
->if_flags
& IFF_PROMISC
))
5311 wh
= (struct ieee80211_frame
*) (rxwi
+ 1);
5313 /* check for cipher errors */
5315 if (desc_flags
& RT2860_RXDESC_FLAGS_DECRYPTED
)
5317 cipher_err
= ((desc_flags
>> RT2860_RXDESC_FLAGS_CIPHER_ERR_SHIFT
) &
5318 RT2860_RXDESC_FLAGS_CIPHER_ERR_MASK
);
5319 if (cipher_err
== RT2860_RXDESC_FLAGS_CIPHER_ERR_NONE
)
5321 if (wh
->i_fc
[1] & IEEE80211_FC1_WEP
)
5322 wh
->i_fc
[1] &= ~IEEE80211_FC1_WEP
;
5324 m
->m_flags
|= M_WEP
;
5326 sc
->rx_cipher_no_errors
++;
5330 RT2860_DPRINTF(sc
, RT2860_DEBUG_RX
,
5331 "%s: rxdesc: cipher error=0x%02x\n",
5332 device_get_nameunit(sc
->dev
), cipher_err
);
5334 if (cipher_err
== RT2860_RXDESC_FLAGS_CIPHER_ERR_ICV
)
5335 sc
->rx_cipher_icv_errors
++;
5336 else if (cipher_err
== RT2860_RXDESC_FLAGS_CIPHER_ERR_MIC
)
5337 sc
->rx_cipher_mic_errors
++;
5338 else if (cipher_err
== RT2860_RXDESC_FLAGS_CIPHER_ERR_INVALID_KEY
)
5339 sc
->rx_cipher_invalid_key_errors
++;
5341 if ((cipher_err
== RT2860_RXDESC_FLAGS_CIPHER_ERR_MIC
) &&
5342 (desc_flags
& RT2860_RXDESC_FLAGS_MYBSS
))
5344 ni
= ieee80211_find_rxnode(ic
, (const struct ieee80211_frame_min
*) wh
);
5347 keyidx
= (rxwi
->udf_bssidx_keyidx
>> RT2860_RXWI_KEYIDX_SHIFT
) &
5348 RT2860_RXWI_KEYIDX_MASK
;
5350 ieee80211_notify_michael_failure(ni
->ni_vap
, wh
, keyidx
);
5352 ieee80211_free_node(ni
);
5358 if (!(ifp
->if_flags
& IFF_PROMISC
))
5367 if (wh
->i_fc
[1] & IEEE80211_FC1_WEP
)
5369 RT2860_DPRINTF(sc
, RT2860_DEBUG_RX
,
5370 "%s: rxdesc: not decrypted but protected flag set\n",
5371 device_get_nameunit(sc
->dev
));
5375 if (!(ifp
->if_flags
& IFF_PROMISC
))
5383 /* check for A-MPDU */
5385 if (desc_flags
& RT2860_RXDESC_FLAGS_AMPDU
)
5387 m
->m_flags
|= M_AMPDU
;
5398 /* check for A-MSDU */
5400 if (desc_flags
& RT2860_RXDESC_FLAGS_AMSDU
)
5411 ant
= rt2860_maxrssi_rxpath(sc
, rxwi
);
5412 rssi
= rxwi
->rssi
[ant
];
5413 rssi_dbm
= rt2860_rssi2dbm(sc
, rssi
, ant
);
5414 phymode
= ((rxwi
->phymode_stbc_shortgi
>> RT2860_RXWI_PHYMODE_SHIFT
) &
5415 RT2860_RXWI_PHYMODE_MASK
);
5416 bw
= ((rxwi
->bw_mcs
>> RT2860_RXWI_BW_SHIFT
) & RT2860_RXWI_BW_MASK
);
5417 shortgi
= ((rxwi
->phymode_stbc_shortgi
>> RT2860_RXWI_SHORTGI_SHIFT
) &
5418 RT2860_RXWI_SHORTGI_MASK
);
5419 mcs
= ((rxwi
->bw_mcs
>> RT2860_RXWI_MCS_SHIFT
) & RT2860_RXWI_MCS_MASK
);
5421 if (ieee80211_radiotap_active(ic
))
5425 tap
->flags
= (desc_flags
& RT2860_RXDESC_FLAGS_L2PAD
) ? IEEE80211_RADIOTAP_F_DATAPAD
: 0;
5426 tap
->dbm_antsignal
= rssi_dbm
;
5427 tap
->dbm_antnoise
= RT2860_NOISE_FLOOR
;
5429 tap
->antsignal
= rssi
;
5430 tap
->chan_flags
= htole32(ic
->ic_curchan
->ic_flags
);
5431 tap
->chan_freq
= htole16(ic
->ic_curchan
->ic_freq
);
5432 tap
->chan_ieee
= ic
->ic_curchan
->ic_ieee
;
5433 tap
->chan_maxpow
= 0;
5435 if (phymode
== RT2860_TXWI_PHYMODE_HT_MIXED
|| phymode
== RT2860_TXWI_PHYMODE_HT_GF
)
5436 tap
->rate
= mcs
| IEEE80211_RATE_MCS
;
5438 tap
->rate
= rt2860_rxrate(rxwi
);
5440 if (desc_flags
& RT2860_RXDESC_FLAGS_CRC_ERR
)
5441 tap
->flags
|= IEEE80211_RADIOTAP_F_BADFCS
;
5443 if (desc_flags
& RT2860_RXDESC_FLAGS_FRAG
)
5444 tap
->flags
|= IEEE80211_RADIOTAP_F_FRAG
;
5446 if (rxwi
->bw_mcs
& RT2860_RXWI_MCS_SHOTPRE
)
5447 tap
->flags
|= IEEE80211_RADIOTAP_F_SHORTPRE
;
5449 if ((desc_flags
& RT2860_RXDESC_FLAGS_DECRYPTED
) ||
5450 (wh
->i_fc
[1] & IEEE80211_FC1_WEP
))
5451 tap
->flags
|= IEEE80211_RADIOTAP_F_WEP
;
5454 tap
->flags
|= IEEE80211_RADIOTAP_F_SHORTGI
;
5458 * net80211 assumes that RSSI data are in the range [-127..127] and
5459 * in .5 dBm units relative to the current noise floor
5462 rssi_dbm_rel
= (rssi_dbm
- RT2860_NOISE_FLOOR
) * 2;
5463 if (rssi_dbm_rel
> 127)
5466 RT2860_DPRINTF(sc
, RT2860_DEBUG_RX
,
5467 "%s: received frame: len=%d, phymode=%d, bw=%d, shortgi=%d, mcs=%d, "
5468 "ant=%d, rssi=%d/%d/%d, snr=%d/%d, wcid=0x%02x, ampdu=%d, amsdu=%d, "
5469 "rssi_dbm=%d, rssi_dbm_rel=%d\n",
5470 device_get_nameunit(sc
->dev
),
5471 len
, phymode
, bw
, shortgi
, mcs
,
5472 ant
, rxwi
->rssi
[0], rxwi
->rssi
[1], rxwi
->rssi
[2],
5473 rxwi
->snr
[0], rxwi
->snr
[1],
5474 rxwi
->wcid
, ampdu
, amsdu
, rssi_dbm
, rssi_dbm_rel
);
5476 ni
= ieee80211_find_rxnode(ic
, (struct ieee80211_frame_min
*) wh
);
5479 rni
= (struct rt2860_softc_node
*) ni
;
5481 for (i
= 0; i
< RT2860_SOFTC_RSSI_COUNT
; i
++)
5483 rni
->last_rssi
[i
] = rxwi
->rssi
[i
];
5484 rni
->last_rssi_dbm
[i
] = rt2860_rssi2dbm(sc
, rxwi
->rssi
[i
], i
);
5487 ieee80211_input(ni
, m
, rssi_dbm_rel
, RT2860_NOISE_FLOOR
);
5488 ieee80211_free_node(ni
);
5492 ieee80211_input_all(ic
, m
, rssi_dbm_rel
, RT2860_NOISE_FLOOR
);
5497 desc
->sdl0
&= ~htole16(RT2860_RXDESC_SDL0_DDONE
);
5499 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
5500 BUS_DMASYNC_PREREAD
| BUS_DMASYNC_PREWRITE
);
5502 ring
->cur
= (ring
->cur
+ 1) % RT2860_SOFTC_RX_RING_DATA_COUNT
;
5508 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_CALC_IDX
,
5509 RT2860_SOFTC_RX_RING_DATA_COUNT
- 1);
5511 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_CALC_IDX
,
5514 RT2860_DPRINTF(sc
, RT2860_DEBUG_RX
,
5515 "%s: Rx eof: nframes=%d\n",
5516 device_get_nameunit(sc
->dev
), nframes
);
5518 sc
->rx_packets
+= nframes
;
5520 return (limit
== 0);
5526 static void rt2860_tx_eof(struct rt2860_softc
*sc
,
5527 struct rt2860_softc_tx_ring
*ring
)
5530 struct rt2860_txdesc
*desc
;
5531 struct rt2860_softc_tx_data
*data
;
5533 int ndescs
, nframes
;
5542 index
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_TX_DTX_IDX(ring
->qid
));
5543 if (ring
->desc_next
== index
)
5548 rt2860_drain_fifo_stats(sc
);
5550 desc
= &ring
->desc
[ring
->desc_next
];
5552 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
5553 BUS_DMASYNC_POSTREAD
| BUS_DMASYNC_POSTWRITE
);
5555 if (desc
->sdl0
& htole16(RT2860_TXDESC_SDL0_LASTSEG
) ||
5556 desc
->sdl1
& htole16(RT2860_TXDESC_SDL1_LASTSEG
))
5560 data
= &ring
->data
[ring
->data_next
];
5562 if (data
->m
->m_flags
& M_TXCB
)
5563 ieee80211_process_callback(data
->ni
, data
->m
, 0);
5565 bus_dmamap_sync(ring
->data_dma_tag
, data
->dma_map
,
5566 BUS_DMASYNC_POSTWRITE
);
5567 bus_dmamap_unload(ring
->data_dma_tag
, data
->dma_map
);
5571 ieee80211_free_node(data
->ni
);
5578 RT2860_SOFTC_LOCK(sc
);
5580 ring
->data_queued
--;
5581 ring
->data_next
= (ring
->data_next
+ 1) % RT2860_SOFTC_TX_RING_DATA_COUNT
;
5583 RT2860_SOFTC_UNLOCK(sc
);
5586 desc
->sdl0
&= ~htole16(RT2860_TXDESC_SDL0_DDONE
);
5588 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
5589 BUS_DMASYNC_PREREAD
| BUS_DMASYNC_PREWRITE
);
5591 RT2860_SOFTC_LOCK(sc
);
5593 ring
->desc_queued
--;
5594 ring
->desc_next
= (ring
->desc_next
+ 1) % RT2860_SOFTC_TX_RING_DESC_COUNT
;
5596 RT2860_SOFTC_UNLOCK(sc
);
5599 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
5600 "%s: Tx eof: qid=%d, ndescs=%d, nframes=%d\n",
5601 device_get_nameunit(sc
->dev
), ring
->qid
, ndescs
, nframes
);
5605 * rt2860_update_stats
5607 static void rt2860_update_stats(struct rt2860_softc
*sc
)
5610 struct ieee80211com
*ic
;
5611 struct ieee80211vap
*vap
;
5612 struct ieee80211_node
*ni
;
5614 int beacons
, noretryok
, retryok
, failed
, underflows
, zerolen
;
5620 vap
= TAILQ_FIRST(&ic
->ic_vaps
);
5622 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATS
,
5623 "%s: update statistic\n",
5624 device_get_nameunit(sc
->dev
));
5626 rt2860_drain_fifo_stats(sc
);
5628 /* read and clear Tx statistic registers */
5630 rt2860_io_mac_read_multi(sc
, RT2860_REG_TX_STA_CNT0
,
5631 stacnt
, sizeof(stacnt
));
5633 stacnt
[0] = le32toh(stacnt
[0]);
5634 stacnt
[1] = le32toh(stacnt
[1]);
5635 stacnt
[2] = le32toh(stacnt
[2]);
5637 beacons
= stacnt
[0] >> 16;
5638 noretryok
= stacnt
[1] & 0xffff;
5639 retryok
= stacnt
[1] >> 16;
5640 failed
= stacnt
[0] & 0xffff;
5641 underflows
= stacnt
[2] >> 16;
5642 zerolen
= stacnt
[2] & 0xffff;
5644 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATS
,
5645 "%s: update statistic: beacons=%d, noretryok=%d, retryok=%d, failed=%d, underflows=%d, zerolen=%d\n",
5646 device_get_nameunit(sc
->dev
),
5647 beacons
, noretryok
, retryok
, failed
, underflows
, zerolen
);
5649 ifp
->if_oerrors
+= failed
;
5651 sc
->tx_beacons
+= beacons
;
5652 sc
->tx_noretryok
+= noretryok
;
5653 sc
->tx_retryok
+= retryok
;
5654 sc
->tx_failed
+= failed
;
5655 sc
->tx_underflows
+= underflows
;
5656 sc
->tx_zerolen
+= zerolen
;
5658 if (vap
!= NULL
&& vap
->iv_opmode
== IEEE80211_M_STA
&& vap
->iv_state
== IEEE80211_S_RUN
)
5662 associd
= (ni
!= NULL
) ? ni
->ni_associd
: 0;
5663 wcid
= RT2860_AID2WCID(associd
);
5665 rt2860_amrr_tx_update(&sc
->amrr_node
[wcid
],
5666 noretryok
+ retryok
+ failed
, noretryok
+ retryok
, retryok
+ failed
);
5673 static void rt2860_bbp_tuning(struct rt2860_softc
*sc
)
5676 struct ieee80211com
*ic
;
5677 struct ieee80211vap
*vap
;
5678 struct ieee80211_node
*ni
;
5680 int8_t rssi
, old
, new;
5682 /* RT2860C does not support BBP tuning */
5684 if (sc
->mac_rev
== 0x28600100)
5689 vap
= TAILQ_FIRST(&ic
->ic_vaps
);
5691 if ((ic
->ic_flags
& IEEE80211_F_SCAN
) || vap
== NULL
||
5692 vap
->iv_opmode
!= IEEE80211_M_STA
|| vap
->iv_state
!= IEEE80211_S_RUN
)
5697 chan
= ieee80211_chan2ieee(ic
, ni
->ni_chan
);
5701 else if (chan
<= 64)
5703 else if (chan
<= 128)
5708 rssi
= ieee80211_getrssi(vap
);
5710 if (IEEE80211_IS_CHAN_2GHZ(ni
->ni_chan
))
5712 new = 0x2e + sc
->lna_gain
[group
];
5716 if (!IEEE80211_IS_CHAN_HT40(ni
->ni_chan
))
5717 new = 0x32 + sc
->lna_gain
[group
] * 5 / 3;
5719 new = 0x3a + sc
->lna_gain
[group
] * 5 / 3;
5722 /* Tune if absolute average RSSI is greater than -80 */
5727 old
= rt2860_io_bbp_read(sc
, 66);
5730 rt2860_io_bbp_write(sc
, 66, new);
5736 static void rt2860_watchdog(struct rt2860_softc
*sc
)
5741 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_PBF_TXRXQ_PCNT
);
5743 RT2860_DPRINTF(sc
, RT2860_DEBUG_WATCHDOG
,
5744 "%s: watchdog: TXRXQ_PCNT=0x%08x\n",
5745 device_get_nameunit(sc
->dev
), tmp
);
5747 if (((tmp
>> RT2860_REG_TX0Q_PCNT_SHIFT
) & RT2860_REG_TX0Q_PCNT_MASK
) != 0)
5749 sc
->tx_queue_not_empty
[0]++;
5751 rt2860_io_mac_write(sc
, RT2860_REG_PBF_CFG
, 0xf40012);
5753 for (ntries
= 0; ntries
< 10; ntries
++)
5755 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_PBF_TXRXQ_PCNT
);
5756 if (((tmp
>> RT2860_REG_TX0Q_PCNT_SHIFT
) & RT2860_REG_TX0Q_PCNT_MASK
) == 0)
5762 rt2860_io_mac_write(sc
, RT2860_REG_PBF_CFG
, 0xf40006);
5765 if (((tmp
>> RT2860_REG_TX1Q_PCNT_SHIFT
) & RT2860_REG_TX1Q_PCNT_MASK
) != 0)
5767 sc
->tx_queue_not_empty
[1]++;
5769 rt2860_io_mac_write(sc
, RT2860_REG_PBF_CFG
, 0xf4000a);
5771 for (ntries
= 0; ntries
< 10; ntries
++)
5773 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_PBF_TXRXQ_PCNT
);
5774 if (((tmp
>> RT2860_REG_TX1Q_PCNT_SHIFT
) & RT2860_REG_TX1Q_PCNT_MASK
) == 0)
5780 rt2860_io_mac_write(sc
, RT2860_REG_PBF_CFG
, 0xf40006);
5785 * rt2860_drain_fifo_stats
5787 static void rt2860_drain_fifo_stats(struct rt2860_softc
*sc
)
5791 uint8_t wcid
, mcs
, pid
;
5792 int ok
, agg
, retrycnt
;
5796 /* drain Tx status FIFO (maxsize = 16) */
5798 while ((stats
= rt2860_io_mac_read(sc
, RT2860_REG_TX_STA_FIFO
)) &
5799 RT2860_REG_TX_STA_FIFO_VALID
)
5801 wcid
= (stats
>> RT2860_REG_TX_STA_FIFO_WCID_SHIFT
) &
5802 RT2860_REG_TX_STA_FIFO_WCID_MASK
;
5804 /* if no ACK was requested, no feedback is available */
5806 if (!(stats
& RT2860_REG_TX_STA_FIFO_ACK_REQ
) || wcid
== 0xff)
5809 /* update AMRR statistic */
5811 ok
= (stats
& RT2860_REG_TX_STA_FIFO_TX_OK
) ? 1 : 0;
5812 agg
= (stats
& RT2860_REG_TX_STA_FIFO_AGG
) ? 1 : 0;
5813 mcs
= (stats
>> RT2860_REG_TX_STA_FIFO_MCS_SHIFT
) &
5814 RT2860_REG_TX_STA_FIFO_MCS_MASK
;
5815 pid
= (stats
>> RT2860_REG_TX_STA_FIFO_PID_SHIFT
) &
5816 RT2860_REG_TX_STA_FIFO_PID_MASK
;
5817 retrycnt
= pid
- mcs
;
5819 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATS
,
5820 "%s: FIFO statistic: wcid=0x%02x, ok=%d, agg=%d, mcs=0x%02x, pid=0x%02x, retrycnt=%d\n",
5821 device_get_nameunit(sc
->dev
),
5822 wcid
, ok
, agg
, mcs
, pid
, retrycnt
);
5824 rt2860_amrr_tx_complete(&sc
->amrr_node
[wcid
], ok
, retrycnt
);
5832 * rt2860_update_raw_counters
5834 static void rt2860_update_raw_counters(struct rt2860_softc
*sc
)
5838 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_AGG_CNT
);
5840 sc
->tx_nonagg
+= tmp
& 0xffff;
5841 sc
->tx_agg
+= tmp
>> 16;
5843 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_AGG_CNT0
);
5845 sc
->tx_ampdu
+= (tmp
& 0xffff) / 1 + (tmp
>> 16) / 2;
5847 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_AGG_CNT1
);
5849 sc
->tx_ampdu
+= (tmp
& 0xffff) / 3 + (tmp
>> 16) / 4;
5851 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_AGG_CNT2
);
5853 sc
->tx_ampdu
+= (tmp
& 0xffff) / 5 + (tmp
>> 16) / 6;
5855 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_AGG_CNT3
);
5857 sc
->tx_ampdu
+= (tmp
& 0xffff) / 7 + (tmp
>> 16) / 8;
5859 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_AGG_CNT4
);
5861 sc
->tx_ampdu
+= (tmp
& 0xffff) / 9 + (tmp
>> 16) / 10;
5863 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_AGG_CNT5
);
5865 sc
->tx_ampdu
+= (tmp
& 0xffff) / 11 + (tmp
>> 16) / 12;
5867 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_AGG_CNT6
);
5869 sc
->tx_ampdu
+= (tmp
& 0xffff) / 13 + (tmp
>> 16) / 14;
5871 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_AGG_CNT7
);
5873 sc
->tx_ampdu
+= (tmp
& 0xffff) / 15 + (tmp
>> 16) / 16;
5875 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_RX_STA_CNT0
);
5877 sc
->rx_crc_errors
+= tmp
& 0xffff;
5878 sc
->rx_phy_errors
+= tmp
>> 16;
5880 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_RX_STA_CNT1
);
5882 sc
->rx_false_ccas
+= tmp
& 0xffff;
5883 sc
->rx_plcp_errors
+= tmp
>> 16;
5885 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_RX_STA_CNT2
);
5887 sc
->rx_dup_packets
+= tmp
& 0xffff;
5888 sc
->rx_fifo_overflows
+= tmp
>> 16;
5890 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TXRX_MPDU_DEN_CNT
);
5892 sc
->tx_mpdu_zero_density
+= tmp
& 0xffff;
5893 sc
->rx_mpdu_zero_density
+= tmp
>> 16;
5897 * rt2860_intr_enable
5899 static void rt2860_intr_enable(struct rt2860_softc
*sc
, uint32_t intr_mask
)
5903 sc
->intr_disable_mask
&= ~intr_mask
;
5905 tmp
= sc
->intr_enable_mask
& ~sc
->intr_disable_mask
;
5907 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_INT_MASK
, tmp
);
5911 * rt2860_intr_disable
5913 static void rt2860_intr_disable(struct rt2860_softc
*sc
, uint32_t intr_mask
)
5917 sc
->intr_disable_mask
|= intr_mask
;
5919 tmp
= sc
->intr_enable_mask
& ~sc
->intr_disable_mask
;
5921 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_INT_MASK
, tmp
);
5925 * rt2860_txrx_enable
5927 static int rt2860_txrx_enable(struct rt2860_softc
*sc
)
5929 struct ieee80211com
*ic
;
5937 /* enable Tx/Rx DMA engine */
5939 rt2860_io_mac_write(sc
, RT2860_REG_SYS_CTRL
, RT2860_REG_TX_ENABLE
);
5941 for (ntries
= 0; ntries
< 200; ntries
++)
5943 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
);
5944 if (!(tmp
& (RT2860_REG_TX_DMA_BUSY
| RT2860_REG_RX_DMA_BUSY
)))
5952 printf("%s: timeout waiting for DMA engine\n",
5953 device_get_nameunit(sc
->dev
));
5959 tmp
|= RT2860_REG_TX_WB_DDONE
|
5960 RT2860_REG_RX_DMA_ENABLE
|
5961 RT2860_REG_TX_DMA_ENABLE
|
5962 (RT2860_REG_WPDMA_BT_SIZE64
<< RT2860_REG_WPDMA_BT_SIZE_SHIFT
);
5964 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
, tmp
);
5968 tmp
= RT2860_REG_RX_FILTER_DROP_CRC_ERR
|
5969 RT2860_REG_RX_FILTER_DROP_PHY_ERR
;
5971 if (ic
->ic_opmode
!= IEEE80211_M_MONITOR
)
5973 tmp
|= RT2860_REG_RX_FILTER_DROP_DUPL
|
5974 RT2860_REG_RX_FILTER_DROP_CTS
|
5975 RT2860_REG_RX_FILTER_DROP_BA
|
5976 RT2860_REG_RX_FILTER_DROP_ACK
|
5977 RT2860_REG_RX_FILTER_DROP_VER_ERR
|
5978 RT2860_REG_RX_FILTER_DROP_CTRL_RSV
|
5979 RT2860_REG_RX_FILTER_DROP_CFACK
|
5980 RT2860_REG_RX_FILTER_DROP_CFEND
;
5982 if (ic
->ic_opmode
== IEEE80211_M_STA
)
5983 tmp
|= RT2860_REG_RX_FILTER_DROP_RTS
|
5984 RT2860_REG_RX_FILTER_DROP_PSPOLL
;
5986 if (!(ifp
->if_flags
& IFF_PROMISC
))
5987 tmp
|= RT2860_REG_RX_FILTER_DROP_UC_NOME
;
5990 rt2860_io_mac_write(sc
, RT2860_REG_RX_FILTER_CFG
, tmp
);
5992 rt2860_io_mac_write(sc
, RT2860_REG_SYS_CTRL
,
5993 RT2860_REG_RX_ENABLE
| RT2860_REG_TX_ENABLE
);
5999 * rt2860_alloc_rx_ring
6001 static int rt2860_alloc_rx_ring(struct rt2860_softc
*sc
,
6002 struct rt2860_softc_rx_ring
*ring
)
6004 struct rt2860_rxdesc
*desc
;
6005 struct rt2860_softc_rx_data
*data
;
6006 bus_dma_segment_t segs
[1];
6007 int i
, nsegs
, error
;
6009 error
= bus_dma_tag_create(bus_get_dma_tag(sc
->dev
), PAGE_SIZE
, 0,
6010 BUS_SPACE_MAXADDR_32BIT
, BUS_SPACE_MAXADDR
, NULL
, NULL
,
6011 RT2860_SOFTC_RX_RING_DATA_COUNT
* sizeof(struct rt2860_rxdesc
), 1,
6012 RT2860_SOFTC_RX_RING_DATA_COUNT
* sizeof(struct rt2860_rxdesc
),
6013 0, NULL
, NULL
, &ring
->desc_dma_tag
);
6016 printf("%s: could not create Rx desc DMA tag\n",
6017 device_get_nameunit(sc
->dev
));
6021 error
= bus_dmamem_alloc(ring
->desc_dma_tag
, (void **) &ring
->desc
,
6022 BUS_DMA_NOWAIT
| BUS_DMA_ZERO
, &ring
->desc_dma_map
);
6025 printf("%s: could not allocate Rx desc DMA memory\n",
6026 device_get_nameunit(sc
->dev
));
6030 error
= bus_dmamap_load(ring
->desc_dma_tag
, ring
->desc_dma_map
,
6032 RT2860_SOFTC_RX_RING_DATA_COUNT
* sizeof(struct rt2860_rxdesc
),
6033 rt2860_dma_map_addr
, &ring
->desc_phys_addr
, 0);
6036 printf("%s: could not load Rx desc DMA map\n",
6037 device_get_nameunit(sc
->dev
));
6041 error
= bus_dma_tag_create(bus_get_dma_tag(sc
->dev
), PAGE_SIZE
, 0,
6042 BUS_SPACE_MAXADDR_32BIT
, BUS_SPACE_MAXADDR
, NULL
, NULL
,
6043 MJUMPAGESIZE
, 1, MJUMPAGESIZE
, 0, NULL
, NULL
,
6044 &ring
->data_dma_tag
);
6047 printf("%s: could not create Rx data DMA tag\n",
6048 device_get_nameunit(sc
->dev
));
6052 for (i
= 0; i
< RT2860_SOFTC_RX_RING_DATA_COUNT
; i
++)
6054 desc
= &ring
->desc
[i
];
6055 data
= &ring
->data
[i
];
6057 error
= bus_dmamap_create(ring
->data_dma_tag
, 0, &data
->dma_map
);
6060 printf("%s: could not create Rx data DMA map\n",
6061 device_get_nameunit(sc
->dev
));
6065 data
->m
= m_getjcl(M_DONTWAIT
, MT_DATA
, M_PKTHDR
, MJUMPAGESIZE
);
6066 if (data
->m
== NULL
)
6068 printf("%s: could not allocate Rx mbuf\n",
6069 device_get_nameunit(sc
->dev
));
6074 data
->m
->m_len
= data
->m
->m_pkthdr
.len
= MJUMPAGESIZE
;
6076 error
= bus_dmamap_load_mbuf_sg(ring
->data_dma_tag
, data
->dma_map
,
6077 data
->m
, segs
, &nsegs
, BUS_DMA_NOWAIT
);
6080 printf("%s: could not load Rx mbuf DMA map\n",
6081 device_get_nameunit(sc
->dev
));
6085 KASSERT(nsegs
== 1, ("%s: too many DMA segments",
6086 device_get_nameunit(sc
->dev
)));
6088 desc
->sdp0
= htole32(segs
[0].ds_addr
);
6089 desc
->sdl0
= htole16(MJUMPAGESIZE
);
6092 error
= bus_dmamap_create(ring
->data_dma_tag
, 0, &ring
->spare_dma_map
);
6095 printf("%s: could not create Rx spare DMA map\n",
6096 device_get_nameunit(sc
->dev
));
6100 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
6101 BUS_DMASYNC_PREREAD
| BUS_DMASYNC_PREWRITE
);
6107 rt2860_free_rx_ring(sc
, ring
);
6113 * rt2860_reset_rx_ring
6115 static void rt2860_reset_rx_ring(struct rt2860_softc
*sc
,
6116 struct rt2860_softc_rx_ring
*ring
)
6118 struct rt2860_rxdesc
*desc
;
6121 for (i
= 0; i
< RT2860_SOFTC_RX_RING_DATA_COUNT
; i
++)
6123 desc
= &ring
->desc
[i
];
6125 desc
->sdl0
&= ~htole16(RT2860_RXDESC_SDL0_DDONE
);
6128 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
6129 BUS_DMASYNC_PREREAD
| BUS_DMASYNC_PREWRITE
);
6135 * rt2860_free_rx_ring
6137 static void rt2860_free_rx_ring(struct rt2860_softc
*sc
,
6138 struct rt2860_softc_rx_ring
*ring
)
6140 struct rt2860_softc_rx_data
*data
;
6143 if (ring
->desc
!= NULL
)
6145 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
6146 BUS_DMASYNC_POSTWRITE
);
6147 bus_dmamap_unload(ring
->desc_dma_tag
, ring
->desc_dma_map
);
6148 bus_dmamem_free(ring
->desc_dma_tag
, ring
->desc
,
6149 ring
->desc_dma_map
);
6152 if (ring
->desc_dma_tag
!= NULL
)
6153 bus_dma_tag_destroy(ring
->desc_dma_tag
);
6155 for (i
= 0; i
< RT2860_SOFTC_RX_RING_DATA_COUNT
; i
++)
6157 data
= &ring
->data
[i
];
6159 if (data
->m
!= NULL
)
6161 bus_dmamap_sync(ring
->data_dma_tag
, data
->dma_map
,
6162 BUS_DMASYNC_POSTREAD
);
6163 bus_dmamap_unload(ring
->data_dma_tag
, data
->dma_map
);
6167 if (data
->dma_map
!= NULL
)
6168 bus_dmamap_destroy(ring
->data_dma_tag
, data
->dma_map
);
6171 if (ring
->spare_dma_map
!= NULL
)
6172 bus_dmamap_destroy(ring
->data_dma_tag
, ring
->spare_dma_map
);
6174 if (ring
->data_dma_tag
!= NULL
)
6175 bus_dma_tag_destroy(ring
->data_dma_tag
);
6179 * rt2860_alloc_tx_ring
6181 static int rt2860_alloc_tx_ring(struct rt2860_softc
*sc
,
6182 struct rt2860_softc_tx_ring
*ring
, int qid
)
6184 struct rt2860_softc_tx_data
*data
;
6187 error
= bus_dma_tag_create(bus_get_dma_tag(sc
->dev
), PAGE_SIZE
, 0,
6188 BUS_SPACE_MAXADDR_32BIT
, BUS_SPACE_MAXADDR
, NULL
, NULL
,
6189 RT2860_SOFTC_TX_RING_DESC_COUNT
* sizeof(struct rt2860_txdesc
), 1,
6190 RT2860_SOFTC_TX_RING_DESC_COUNT
* sizeof(struct rt2860_txdesc
),
6191 0, NULL
, NULL
, &ring
->desc_dma_tag
);
6194 printf("%s: could not create Tx desc DMA tag\n",
6195 device_get_nameunit(sc
->dev
));
6199 error
= bus_dmamem_alloc(ring
->desc_dma_tag
, (void **) &ring
->desc
,
6200 BUS_DMA_NOWAIT
| BUS_DMA_ZERO
, &ring
->desc_dma_map
);
6203 printf("%s: could not allocate Tx desc DMA memory\n",
6204 device_get_nameunit(sc
->dev
));
6208 error
= bus_dmamap_load(ring
->desc_dma_tag
, ring
->desc_dma_map
,
6210 RT2860_SOFTC_TX_RING_DESC_COUNT
* sizeof(struct rt2860_txdesc
),
6211 rt2860_dma_map_addr
, &ring
->desc_phys_addr
, 0);
6214 printf("%s: could not load Tx desc DMA map\n",
6215 device_get_nameunit(sc
->dev
));
6219 ring
->desc_queued
= 0;
6221 ring
->desc_next
= 0;
6223 error
= bus_dma_tag_create(bus_get_dma_tag(sc
->dev
), PAGE_SIZE
, 0,
6224 BUS_SPACE_MAXADDR_32BIT
, BUS_SPACE_MAXADDR
, NULL
, NULL
,
6225 RT2860_SOFTC_TX_RING_DATA_COUNT
* RT2860_TX_DATA_SEG0_SIZE
, 1,
6226 RT2860_SOFTC_TX_RING_DATA_COUNT
* RT2860_TX_DATA_SEG0_SIZE
,
6227 0, NULL
, NULL
, &ring
->seg0_dma_tag
);
6230 printf("%s: could not create Tx seg0 DMA tag\n",
6231 device_get_nameunit(sc
->dev
));
6235 error
= bus_dmamem_alloc(ring
->seg0_dma_tag
, (void **) &ring
->seg0
,
6236 BUS_DMA_NOWAIT
| BUS_DMA_ZERO
, &ring
->seg0_dma_map
);
6239 printf("%s: could not allocate Tx seg0 DMA memory\n",
6240 device_get_nameunit(sc
->dev
));
6244 error
= bus_dmamap_load(ring
->seg0_dma_tag
, ring
->seg0_dma_map
,
6246 RT2860_SOFTC_TX_RING_DATA_COUNT
* RT2860_TX_DATA_SEG0_SIZE
,
6247 rt2860_dma_map_addr
, &ring
->seg0_phys_addr
, 0);
6250 printf("%s: could not load Tx seg0 DMA map\n",
6251 device_get_nameunit(sc
->dev
));
6255 error
= bus_dma_tag_create(bus_get_dma_tag(sc
->dev
), PAGE_SIZE
, 0,
6256 BUS_SPACE_MAXADDR_32BIT
, BUS_SPACE_MAXADDR
, NULL
, NULL
,
6257 MJUMPAGESIZE
, RT2860_SOFTC_MAX_SCATTER
, MJUMPAGESIZE
, 0, NULL
, NULL
,
6258 &ring
->data_dma_tag
);
6261 printf("%s: could not create Tx data DMA tag\n",
6262 device_get_nameunit(sc
->dev
));
6266 for (i
= 0; i
< RT2860_SOFTC_TX_RING_DATA_COUNT
; i
++)
6268 data
= &ring
->data
[i
];
6270 error
= bus_dmamap_create(ring
->data_dma_tag
, 0, &data
->dma_map
);
6273 printf("%s: could not create Tx data DMA map\n",
6274 device_get_nameunit(sc
->dev
));
6279 ring
->data_queued
= 0;
6281 ring
->data_next
= 0;
6289 rt2860_free_tx_ring(sc
, ring
);
6295 * rt2860_reset_tx_ring
6297 static void rt2860_reset_tx_ring(struct rt2860_softc
*sc
,
6298 struct rt2860_softc_tx_ring
*ring
)
6300 struct rt2860_softc_tx_data
*data
;
6301 struct rt2860_txdesc
*desc
;
6304 for (i
= 0; i
< RT2860_SOFTC_TX_RING_DESC_COUNT
; i
++)
6306 desc
= &ring
->desc
[i
];
6312 ring
->desc_queued
= 0;
6314 ring
->desc_next
= 0;
6316 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
6317 BUS_DMASYNC_PREWRITE
);
6319 bus_dmamap_sync(ring
->seg0_dma_tag
, ring
->seg0_dma_map
,
6320 BUS_DMASYNC_PREWRITE
);
6322 for (i
= 0; i
< RT2860_SOFTC_TX_RING_DATA_COUNT
; i
++)
6324 data
= &ring
->data
[i
];
6326 if (data
->m
!= NULL
)
6328 bus_dmamap_sync(ring
->data_dma_tag
, data
->dma_map
,
6329 BUS_DMASYNC_POSTWRITE
);
6330 bus_dmamap_unload(ring
->data_dma_tag
, data
->dma_map
);
6335 if (data
->ni
!= NULL
)
6337 ieee80211_free_node(data
->ni
);
6342 ring
->data_queued
= 0;
6344 ring
->data_next
= 0;
6348 * rt2860_free_tx_ring
6350 static void rt2860_free_tx_ring(struct rt2860_softc
*sc
,
6351 struct rt2860_softc_tx_ring
*ring
)
6353 struct rt2860_softc_tx_data
*data
;
6356 if (ring
->desc
!= NULL
)
6358 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
6359 BUS_DMASYNC_POSTWRITE
);
6360 bus_dmamap_unload(ring
->desc_dma_tag
, ring
->desc_dma_map
);
6361 bus_dmamem_free(ring
->desc_dma_tag
, ring
->desc
,
6362 ring
->desc_dma_map
);
6365 if (ring
->desc_dma_tag
!= NULL
)
6366 bus_dma_tag_destroy(ring
->desc_dma_tag
);
6368 if (ring
->seg0
!= NULL
)
6370 bus_dmamap_sync(ring
->seg0_dma_tag
, ring
->seg0_dma_map
,
6371 BUS_DMASYNC_POSTWRITE
);
6372 bus_dmamap_unload(ring
->seg0_dma_tag
, ring
->seg0_dma_map
);
6373 bus_dmamem_free(ring
->seg0_dma_tag
, ring
->seg0
,
6374 ring
->seg0_dma_map
);
6377 if (ring
->seg0_dma_tag
!= NULL
)
6378 bus_dma_tag_destroy(ring
->seg0_dma_tag
);
6380 for (i
= 0; i
< RT2860_SOFTC_TX_RING_DATA_COUNT
; i
++)
6382 data
= &ring
->data
[i
];
6384 if (data
->m
!= NULL
)
6386 bus_dmamap_sync(ring
->data_dma_tag
, data
->dma_map
,
6387 BUS_DMASYNC_POSTWRITE
);
6388 bus_dmamap_unload(ring
->data_dma_tag
, data
->dma_map
);
6392 if (data
->ni
!= NULL
)
6393 ieee80211_free_node(data
->ni
);
6395 if (data
->dma_map
!= NULL
)
6396 bus_dmamap_destroy(ring
->data_dma_tag
, data
->dma_map
);
6399 if (ring
->data_dma_tag
!= NULL
)
6400 bus_dma_tag_destroy(ring
->data_dma_tag
);
6404 * rt2860_dma_map_addr
6406 static void rt2860_dma_map_addr(void *arg
, bus_dma_segment_t
*segs
,
6407 int nseg
, int error
)
6412 KASSERT(nseg
== 1, ("too many DMA segments, %d should be 1", nseg
));
6414 *(bus_addr_t
*) arg
= segs
[0].ds_addr
;
6418 * rt2860_sysctl_attach
6420 static void rt2860_sysctl_attach(struct rt2860_softc
*sc
)
6422 struct sysctl_ctx_list
*ctx
;
6423 struct sysctl_oid
*tree
;
6424 struct sysctl_oid
*stats
;
6426 ctx
= device_get_sysctl_ctx(sc
->dev
);
6427 tree
= device_get_sysctl_tree(sc
->dev
);
6429 stats
= SYSCTL_ADD_NODE(ctx
, SYSCTL_CHILDREN(tree
), OID_AUTO
,
6430 "stats", CTLFLAG_RD
, 0, "statistic");
6432 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6433 "interrupts", CTLFLAG_RD
, &sc
->interrupts
, 0,
6436 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6437 "tx_coherent_interrupts", CTLFLAG_RD
, &sc
->tx_coherent_interrupts
, 0,
6438 "Tx coherent interrupts");
6440 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6441 "rx_coherent_interrupts", CTLFLAG_RD
, &sc
->rx_coherent_interrupts
, 0,
6442 "Rx coherent interrupts");
6444 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6445 "txrx_coherent_interrupts", CTLFLAG_RD
, &sc
->txrx_coherent_interrupts
, 0,
6446 "Tx/Rx coherent interrupts");
6448 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6449 "fifo_sta_full_interrupts", CTLFLAG_RD
, &sc
->fifo_sta_full_interrupts
, 0,
6450 "FIFO statistic full interrupts");
6452 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6453 "rx_interrupts", CTLFLAG_RD
, &sc
->rx_interrupts
, 0,
6456 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6457 "rx_delay_interrupts", CTLFLAG_RD
, &sc
->rx_delay_interrupts
, 0,
6458 "Rx delay interrupts");
6460 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6461 "tx_mgmt_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[5], 0,
6462 "Tx MGMT interrupts");
6464 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6465 "tx_hcca_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[4], 0,
6466 "Tx HCCA interrupts");
6468 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6469 "tx_ac3_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[3], 0,
6470 "Tx AC3 interrupts");
6472 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6473 "tx_ac2_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[2], 0,
6474 "Tx AC2 interrupts");
6476 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6477 "tx_ac1_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[1], 0,
6478 "Tx AC1 interrupts");
6480 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6481 "tx_ac0_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[0], 0,
6482 "Tx AC0 interrupts");
6484 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6485 "tx_delay_interrupts", CTLFLAG_RD
, &sc
->tx_delay_interrupts
, 0,
6486 "Tx delay interrupts");
6488 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6489 "pre_tbtt_interrupts", CTLFLAG_RD
, &sc
->pre_tbtt_interrupts
, 0,
6490 "Pre-TBTT interrupts");
6492 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6493 "tbtt_interrupts", CTLFLAG_RD
, &sc
->tbtt_interrupts
, 0,
6496 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6497 "mcu_cmd_interrupts", CTLFLAG_RD
, &sc
->mcu_cmd_interrupts
, 0,
6498 "MCU command interrupts");
6500 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6501 "auto_wakeup_interrupts", CTLFLAG_RD
, &sc
->auto_wakeup_interrupts
, 0,
6502 "auto wakeup interrupts");
6504 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6505 "gp_timer_interrupts", CTLFLAG_RD
, &sc
->gp_timer_interrupts
, 0,
6506 "GP timer interrupts");
6508 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6509 "tx_mgmt_desc_queued", CTLFLAG_RD
, &sc
->tx_ring
[5].desc_queued
, 0,
6510 "Tx MGMT descriptors queued");
6512 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6513 "tx_mgmt_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[5].data_queued
, 0,
6514 "Tx MGMT data queued");
6516 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6517 "tx_hcca_desc_queued", CTLFLAG_RD
, &sc
->tx_ring
[4].desc_queued
, 0,
6518 "Tx HCCA descriptors queued");
6520 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6521 "tx_hcca_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[4].data_queued
, 0,
6522 "Tx HCCA data queued");
6524 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6525 "tx_ac3_desc_queued", CTLFLAG_RD
, &sc
->tx_ring
[3].desc_queued
, 0,
6526 "Tx AC3 descriptors queued");
6528 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6529 "tx_ac3_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[3].data_queued
, 0,
6530 "Tx AC3 data queued");
6532 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6533 "tx_ac2_desc_queued", CTLFLAG_RD
, &sc
->tx_ring
[2].desc_queued
, 0,
6534 "Tx AC2 descriptors queued");
6536 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6537 "tx_ac2_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[2].data_queued
, 0,
6538 "Tx AC2 data queued");
6540 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6541 "tx_ac1_desc_queued", CTLFLAG_RD
, &sc
->tx_ring
[1].desc_queued
, 0,
6542 "Tx AC1 descriptors queued");
6544 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6545 "tx_ac1_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[1].data_queued
, 0,
6546 "Tx AC1 data queued");
6548 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6549 "tx_ac0_desc_queued", CTLFLAG_RD
, &sc
->tx_ring
[0].desc_queued
, 0,
6550 "Tx AC0 descriptors queued");
6552 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6553 "tx_ac0_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[0].data_queued
, 0,
6554 "Tx AC0 data queued");
6556 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6557 "tx_mgmt_data_queue_full", CTLFLAG_RD
, &sc
->tx_data_queue_full
[5], 0,
6558 "Tx MGMT data queue full");
6560 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6561 "tx_hcca_data_queue_full", CTLFLAG_RD
, &sc
->tx_data_queue_full
[4], 0,
6562 "Tx HCCA data queue full");
6564 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6565 "tx_ac3_data_queue_full", CTLFLAG_RD
, &sc
->tx_data_queue_full
[3], 0,
6566 "Tx AC3 data queue full");
6568 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6569 "tx_ac2_data_queue_full", CTLFLAG_RD
, &sc
->tx_data_queue_full
[2], 0,
6570 "Tx AC2 data queue full");
6572 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6573 "tx_ac1_data_queue_full", CTLFLAG_RD
, &sc
->tx_data_queue_full
[1], 0,
6574 "Tx AC1 data queue full");
6576 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6577 "tx_ac0_data_queue_full", CTLFLAG_RD
, &sc
->tx_data_queue_full
[0], 0,
6578 "Tx AC0 data queue full");
6580 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6581 "tx_watchdog_timeouts", CTLFLAG_RD
, &sc
->tx_watchdog_timeouts
, 0,
6582 "Tx watchdog timeouts");
6584 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6585 "tx_defrag_packets", CTLFLAG_RD
, &sc
->tx_defrag_packets
, 0,
6586 "Tx defragmented packets");
6588 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6589 "no_tx_desc_avail", CTLFLAG_RD
, &sc
->no_tx_desc_avail
, 0,
6590 "no Tx descriptors available");
6592 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6593 "rx_mbuf_alloc_errors", CTLFLAG_RD
, &sc
->rx_mbuf_alloc_errors
, 0,
6594 "Rx mbuf allocation errors");
6596 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6597 "rx_mbuf_dmamap_errors", CTLFLAG_RD
, &sc
->rx_mbuf_dmamap_errors
, 0,
6598 "Rx mbuf DMA mapping errors");
6600 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6601 "tx_queue_0_not_empty", CTLFLAG_RD
, &sc
->tx_queue_not_empty
[0], 0,
6602 "Tx queue 0 not empty");
6604 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6605 "tx_queue_1_not_empty", CTLFLAG_RD
, &sc
->tx_queue_not_empty
[1], 0,
6606 "Tx queue 1 not empty");
6608 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6609 "tx_beacons", CTLFLAG_RD
, &sc
->tx_beacons
, 0,
6612 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6613 "tx_noretryok", CTLFLAG_RD
, &sc
->tx_noretryok
, 0,
6614 "Tx successfull without retries");
6616 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6617 "tx_retryok", CTLFLAG_RD
, &sc
->tx_retryok
, 0,
6618 "Tx successfull with retries");
6620 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6621 "tx_failed", CTLFLAG_RD
, &sc
->tx_failed
, 0,
6624 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6625 "tx_underflows", CTLFLAG_RD
, &sc
->tx_underflows
, 0,
6628 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6629 "tx_zerolen", CTLFLAG_RD
, &sc
->tx_zerolen
, 0,
6632 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6633 "tx_nonagg", CTLFLAG_RD
, &sc
->tx_nonagg
, 0,
6634 "Tx non-aggregated");
6636 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6637 "tx_agg", CTLFLAG_RD
, &sc
->tx_agg
, 0,
6640 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6641 "tx_ampdu", CTLFLAG_RD
, &sc
->tx_ampdu
, 0,
6644 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6645 "tx_mpdu_zero_density", CTLFLAG_RD
, &sc
->tx_mpdu_zero_density
, 0,
6646 "Tx MPDU with zero density");
6648 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6649 "rx_packets", CTLFLAG_RD
, &sc
->rx_packets
, 0,
6652 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6653 "rx_ampdu", CTLFLAG_RD
, &sc
->rx_ampdu
, 0,
6656 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6657 "rx_mpdu_zero_density", CTLFLAG_RD
, &sc
->rx_mpdu_zero_density
, 0,
6658 "Rx MPDU with zero density");
6660 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6661 "rx_amsdu", CTLFLAG_RD
, &sc
->rx_amsdu
, 0,
6664 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6665 "rx_crc_errors", CTLFLAG_RD
, &sc
->rx_crc_errors
, 0,
6668 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6669 "rx_phy_errors", CTLFLAG_RD
, &sc
->rx_phy_errors
, 0,
6672 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6673 "rx_false_ccas", CTLFLAG_RD
, &sc
->rx_false_ccas
, 0,
6676 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6677 "rx_plcp_errors", CTLFLAG_RD
, &sc
->rx_plcp_errors
, 0,
6680 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6681 "rx_dup_packets", CTLFLAG_RD
, &sc
->rx_dup_packets
, 0,
6682 "Rx duplicate packets");
6684 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6685 "rx_fifo_overflows", CTLFLAG_RD
, &sc
->rx_fifo_overflows
, 0,
6686 "Rx FIFO overflows");
6688 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6689 "rx_cipher_no_errors", CTLFLAG_RD
, &sc
->rx_cipher_no_errors
, 0,
6690 "Rx cipher no errors");
6692 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6693 "rx_cipher_icv_errors", CTLFLAG_RD
, &sc
->rx_cipher_icv_errors
, 0,
6694 "Rx cipher ICV errors");
6696 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6697 "rx_cipher_mic_errors", CTLFLAG_RD
, &sc
->rx_cipher_mic_errors
, 0,
6698 "Rx cipher MIC errors");
6700 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6701 "rx_cipher_invalid_key_errors", CTLFLAG_RD
, &sc
->rx_cipher_invalid_key_errors
, 0,
6702 "Rx cipher invalid key errors");
6705 static device_method_t rt2860_dev_methods
[] =
6707 DEVMETHOD(device_probe
, rt2860_probe
),
6708 DEVMETHOD(device_attach
, rt2860_attach
),
6709 DEVMETHOD(device_detach
, rt2860_detach
),
6710 DEVMETHOD(device_shutdown
, rt2860_shutdown
),
6711 DEVMETHOD(device_suspend
, rt2860_suspend
),
6712 DEVMETHOD(device_resume
, rt2860_resume
),
6716 static driver_t rt2860_driver
=
6720 sizeof(struct rt2860_softc
)
6723 static devclass_t rt2860_dev_class
;
6725 DRIVER_MODULE(rt2860
, pci
, rt2860_driver
, rt2860_dev_class
, 0, 0);
6727 MODULE_DEPEND(rt2860
, pci
, 1, 1, 1);
6728 MODULE_DEPEND(rt2860
, wlan
, 1, 1, 1);