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 int rt2860_setregdomain(struct ieee80211com
*ic
,
135 struct ieee80211_regdomain
*reg
,
136 int nchans
, struct ieee80211_channel chans
[]);
138 static void rt2860_getradiocaps(struct ieee80211com
*ic
,
139 int maxchans
, int *nchans
, struct ieee80211_channel chans
[]);
141 static void rt2860_scan_start(struct ieee80211com
*ic
);
143 static void rt2860_scan_end(struct ieee80211com
*ic
);
145 static void rt2860_set_channel(struct ieee80211com
*ic
);
147 static void rt2860_newassoc(struct ieee80211_node
*ni
, int isnew
);
149 static void rt2860_updateslot(struct ifnet
*ifp
);
151 static void rt2860_update_promisc(struct ifnet
*ifp
);
153 static void rt2860_update_mcast(struct ifnet
*ifp
);
155 static int rt2860_wme_update(struct ieee80211com
*ic
);
157 static int rt2860_raw_xmit(struct ieee80211_node
*ni
, struct mbuf
*m
,
158 const struct ieee80211_bpf_params
*params
);
160 static int rt2860_recv_action(struct ieee80211_node
*ni
,
161 const struct ieee80211_frame
*wh
,
162 const uint8_t *frm
, const uint8_t *efrm
);
164 static int rt2860_send_action(struct ieee80211_node
*ni
,
165 int cat
, int act
, void *sa
);
167 static void rt2860_amrr_update_iter_func(void *arg
, struct ieee80211_node
*ni
);
169 static void rt2860_periodic(void *arg
);
171 static void rt2860_tx_watchdog(void *arg
);
173 static void rt2860_asic_set_bssid(struct rt2860_softc
*sc
,
174 const uint8_t *bssid
);
176 static void rt2860_asic_set_macaddr(struct rt2860_softc
*sc
,
177 const uint8_t *addr
);
179 static void rt2860_asic_enable_tsf_sync(struct rt2860_softc
*sc
);
181 static void rt2860_asic_disable_tsf_sync(struct rt2860_softc
*sc
);
183 static void rt2860_asic_enable_mrr(struct rt2860_softc
*sc
);
185 static void rt2860_asic_set_txpreamble(struct rt2860_softc
*sc
);
187 static void rt2860_asic_set_basicrates(struct rt2860_softc
*sc
);
189 static void rt2860_asic_update_rtsthreshold(struct rt2860_softc
*sc
);
191 static void rt2860_asic_update_txpower(struct rt2860_softc
*sc
);
193 static void rt2860_asic_update_promisc(struct rt2860_softc
*sc
);
195 static void rt2860_asic_updateprot(struct rt2860_softc
*sc
);
197 static void rt2860_asic_updateslot(struct rt2860_softc
*sc
);
199 static void rt2860_asic_wme_update(struct rt2860_softc
*sc
);
201 static int rt2860_asic_update_beacon(struct rt2860_softc
*sc
,
202 struct ieee80211vap
*vap
);
204 static void rt2860_asic_clear_keytables(struct rt2860_softc
*sc
);
206 static uint8_t rt2860_rxrate(struct rt2860_rxwi
*rxwi
);
208 static uint8_t rt2860_maxrssi_rxpath(struct rt2860_softc
*sc
,
209 const struct rt2860_rxwi
*rxwi
);
211 static int8_t rt2860_rssi2dbm(struct rt2860_softc
*sc
,
212 uint8_t rssi
, uint8_t rxpath
);
214 static uint8_t rt2860_rate2mcs(uint8_t rate
);
216 static int rt2860_tx_mgmt(struct rt2860_softc
*sc
,
217 struct mbuf
*m
, struct ieee80211_node
*ni
, int qid
);
219 static int rt2860_tx_data(struct rt2860_softc
*sc
,
220 struct mbuf
*m
, struct ieee80211_node
*ni
, int qid
);
222 static int rt2860_tx_raw(struct rt2860_softc
*sc
,
223 struct mbuf
*m
, struct ieee80211_node
*ni
,
224 const struct ieee80211_bpf_params
*params
);
226 static void rt2860_intr(void *arg
);
228 static void rt2860_tx_coherent_intr(struct rt2860_softc
*sc
);
230 static void rt2860_rx_coherent_intr(struct rt2860_softc
*sc
);
232 static void rt2860_txrx_coherent_intr(struct rt2860_softc
*sc
);
234 static void rt2860_fifo_sta_full_intr(struct rt2860_softc
*sc
);
236 static void rt2860_rx_intr(struct rt2860_softc
*sc
);
238 static void rt2860_rx_delay_intr(struct rt2860_softc
*sc
);
240 static void rt2860_tx_intr(struct rt2860_softc
*sc
, int qid
);
242 static void rt2860_tx_delay_intr(struct rt2860_softc
*sc
);
244 static void rt2860_pre_tbtt_intr(struct rt2860_softc
*sc
);
246 static void rt2860_tbtt_intr(struct rt2860_softc
*sc
);
248 static void rt2860_mcu_cmd_intr(struct rt2860_softc
*sc
);
250 static void rt2860_auto_wakeup_intr(struct rt2860_softc
*sc
);
252 static void rt2860_gp_timer_intr(struct rt2860_softc
*sc
);
254 static void rt2860_rx_done_task(void *context
, int pending
);
256 static void rt2860_tx_done_task(void *context
, int pending
);
258 static void rt2860_fifo_sta_full_task(void *context
, int pending
);
260 static void rt2860_periodic_task(void *context
, int pending
);
262 static int rt2860_rx_eof(struct rt2860_softc
*sc
, int limit
);
264 static void rt2860_tx_eof(struct rt2860_softc
*sc
,
265 struct rt2860_softc_tx_ring
*ring
);
267 static void rt2860_update_stats(struct rt2860_softc
*sc
);
269 static void rt2860_bbp_tuning(struct rt2860_softc
*sc
);
271 static void rt2860_watchdog(struct rt2860_softc
*sc
);
273 static void rt2860_drain_fifo_stats(struct rt2860_softc
*sc
);
275 static void rt2860_update_raw_counters(struct rt2860_softc
*sc
);
277 static void rt2860_intr_enable(struct rt2860_softc
*sc
, uint32_t intr_mask
);
279 static void rt2860_intr_disable(struct rt2860_softc
*sc
, uint32_t intr_mask
);
281 static int rt2860_txrx_enable(struct rt2860_softc
*sc
);
283 static int rt2860_alloc_rx_ring(struct rt2860_softc
*sc
,
284 struct rt2860_softc_rx_ring
*ring
);
286 static void rt2860_reset_rx_ring(struct rt2860_softc
*sc
,
287 struct rt2860_softc_rx_ring
*ring
);
289 static void rt2860_free_rx_ring(struct rt2860_softc
*sc
,
290 struct rt2860_softc_rx_ring
*ring
);
292 static int rt2860_alloc_tx_ring(struct rt2860_softc
*sc
,
293 struct rt2860_softc_tx_ring
*ring
, int qid
);
295 static void rt2860_reset_tx_ring(struct rt2860_softc
*sc
,
296 struct rt2860_softc_tx_ring
*ring
);
298 static void rt2860_free_tx_ring(struct rt2860_softc
*sc
,
299 struct rt2860_softc_tx_ring
*ring
);
301 static void rt2860_dma_map_addr(void *arg
, bus_dma_segment_t
*segs
,
302 int nseg
, int error
);
304 static void rt2860_sysctl_attach(struct rt2860_softc
*sc
);
310 static const struct rt2860_pci_ident rt2860_pci_ids
[] =
312 { PCI_VENDOR_RALINK
, PCI_PRODUCT_RALINK_RT2860_PCI
, "Ralink RT2860 PCI" },
313 { PCI_VENDOR_RALINK
, PCI_PRODUCT_RALINK_RT2860_PCIe
, "Ralink RT2860 PCIe" },
314 { PCI_VENDOR_RALINK
, PCI_PRODUCT_RALINK_RT2760_PCI
, "Ralink RT2760 PCI" },
315 { PCI_VENDOR_RALINK
, PCI_PRODUCT_RALINK_RT2790_PCIe
, "Ralink RT2790 PCIe" },
325 { RT2860_REG_PBF_BCN_OFFSET0
, 0xf8f0e8e0 },
326 { RT2860_REG_PBF_BCN_OFFSET1
, 0x6f77d0c8 },
327 { RT2860_REG_LEGACY_BASIC_RATE
, 0x0000013f },
328 { RT2860_REG_HT_BASIC_RATE
, 0x00008003 },
329 { RT2860_REG_SYS_CTRL
, 0x00000000 },
330 { RT2860_REG_RX_FILTER_CFG
, 0x00017f97 },
331 { RT2860_REG_BKOFF_SLOT_CFG
, 0x00000209 },
332 { RT2860_REG_TX_SW_CFG0
, 0x00000000 },
333 { RT2860_REG_TX_SW_CFG1
, 0x00080606 },
334 { RT2860_REG_TX_LINK_CFG
, 0x00001020 },
335 { RT2860_REG_TX_TIMEOUT_CFG
, 0x000a2090 },
336 { RT2860_REG_MAX_LEN_CFG
, (1 << 12) | RT2860_MAX_AGG_SIZE
},
337 { RT2860_REG_LED_CFG
, 0x7f031e46 },
338 { RT2860_REG_PBF_MAX_PCNT
, 0x1f3fbf9f },
339 { RT2860_REG_TX_RTY_CFG
, 0x47d01f0f },
340 { RT2860_REG_AUTO_RSP_CFG
, 0x00000013 },
341 { RT2860_REG_TX_CCK_PROT_CFG
, 0x05740003 },
342 { RT2860_REG_TX_OFDM_PROT_CFG
, 0x05740003 },
343 { RT2860_REG_TX_GF20_PROT_CFG
, 0x01744004 },
344 { RT2860_REG_TX_GF40_PROT_CFG
, 0x03f44084 },
345 { RT2860_REG_TX_MM20_PROT_CFG
, 0x01744004 },
346 { RT2860_REG_TX_MM40_PROT_CFG
, 0x03f54084 },
347 { RT2860_REG_TX_TXOP_CTRL_CFG
, 0x0000583f },
348 { RT2860_REG_TX_RTS_CFG
, 0x00092b20 },
349 { RT2860_REG_TX_EXP_ACK_TIME
, 0x002400ca },
350 { RT2860_REG_HCCAPSMP_TXOP_HLDR_ET
, 0x00000002 },
351 { RT2860_REG_XIFS_TIME_CFG
, 0x33a41010 },
352 { RT2860_REG_PWR_PIN_CFG
, 0x00000003 },
353 { RT2860_REG_SCHDMA_WMM_AIFSN_CFG
, 0x00002273 },
354 { RT2860_REG_SCHDMA_WMM_CWMIN_CFG
, 0x00002344 },
355 { RT2860_REG_SCHDMA_WMM_CWMAX_CFG
, 0x000034aa },
358 #define RT2860_DEF_MAC_SIZE (sizeof(rt2860_def_mac) / sizeof(rt2860_def_mac[0]))
383 #define RT2860_DEF_BBP_SIZE (sizeof(rt2860_def_bbp) / sizeof(rt2860_def_bbp[0]))
385 SYSCTL_NODE(_hw
, OID_AUTO
, rt2860
, CTLFLAG_RD
, 0, "RT2860 driver parameters");
388 static int rt2860_debug
= 0;
389 SYSCTL_INT(_hw_rt2860
, OID_AUTO
, debug
, CTLFLAG_RW
, &rt2860_debug
, 0, "rt2860 debug level");
390 TUNABLE_INT("hw.rt2860.debug", &rt2860_debug
);
396 static int rt2860_probe(device_t dev
)
398 const struct rt2860_pci_ident
*ident
;
400 for (ident
= rt2860_pci_ids
; ident
->name
!= NULL
; ident
++)
402 if (pci_get_vendor(dev
) == ident
->vendor
&&
403 pci_get_device(dev
) == ident
->device
)
405 device_set_desc(dev
, ident
->name
);
416 static int rt2860_attach(device_t dev
)
418 struct rt2860_softc
*sc
;
420 struct ieee80211com
*ic
;
421 int error
, ntries
, i
;
423 sc
= device_get_softc(dev
);
425 if (pci_get_powerstate(dev
) != PCI_POWERSTATE_D0
)
427 printf("%s: chip is in D%d power mode, setting to D0\n",
428 device_get_nameunit(dev
), pci_get_powerstate(dev
));
429 pci_set_powerstate(dev
, PCI_POWERSTATE_D0
);
432 /* enable bus-mastering */
434 pci_enable_busmaster(dev
);
438 mtx_init(&sc
->lock
, device_get_nameunit(dev
),
439 MTX_NETWORK_LOCK
, MTX_DEF
| MTX_RECURSE
);
441 sc
->mem_rid
= PCIR_BAR(0);
442 sc
->mem
= bus_alloc_resource_any(dev
, SYS_RES_MEMORY
,
443 &sc
->mem_rid
, RF_ACTIVE
);
446 printf("%s: could not allocate memory resource\n",
447 device_get_nameunit(dev
));
452 sc
->bst
= rman_get_bustag(sc
->mem
);
453 sc
->bsh
= rman_get_bushandle(sc
->mem
);
456 sc
->irq
= bus_alloc_resource_any(dev
, SYS_RES_IRQ
,
457 &sc
->irq_rid
, RF_ACTIVE
| RF_SHAREABLE
);
460 printf("%s: could not allocate interrupt resource\n",
461 device_get_nameunit(dev
));
467 sc
->debug
= rt2860_debug
;
469 SYSCTL_ADD_INT(device_get_sysctl_ctx(dev
),
470 SYSCTL_CHILDREN(device_get_sysctl_tree(dev
)), OID_AUTO
,
471 "debug", CTLFLAG_RW
, &sc
->debug
, 0, "rt2860 debug level");
474 RT2860_DPRINTF(sc
, RT2860_DEBUG_ANY
,
476 device_get_nameunit(sc
->dev
));
478 /* wait for NIC to initialize */
480 for (ntries
= 0; ntries
< 100; ntries
++)
482 sc
->mac_rev
= rt2860_io_mac_read(sc
, RT2860_REG_MAC_CSR0
);
483 if (sc
->mac_rev
!= 0x00000000 && sc
->mac_rev
!= 0xffffffff)
491 printf("%s: timeout waiting for NIC to initialize\n",
492 device_get_nameunit(dev
));
497 rt2860_read_eeprom(sc
);
499 printf("%s: MAC/BBP RT2860 (rev 0x%08x), RF %s\n",
500 device_get_nameunit(sc
->dev
), sc
->mac_rev
,
501 rt2860_rf_name(sc
->rf_rev
));
503 /* allocate Tx and Rx rings */
505 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
507 error
= rt2860_alloc_tx_ring(sc
, &sc
->tx_ring
[i
], i
);
510 printf("%s: could not allocate Tx ring #%d\n",
511 device_get_nameunit(sc
->dev
), i
);
516 sc
->tx_ring_mgtqid
= 5;
518 error
= rt2860_alloc_rx_ring(sc
, &sc
->rx_ring
);
521 printf("%s: could not allocate Rx ring\n",
522 device_get_nameunit(sc
->dev
));
526 callout_init(&sc
->periodic_ch
, 0);
527 callout_init_mtx(&sc
->tx_watchdog_ch
, &sc
->lock
, 0);
529 ifp
= sc
->ifp
= if_alloc(IFT_IEEE80211
);
532 printf("%s: could not if_alloc()\n",
533 device_get_nameunit(sc
->dev
));
540 if_initname(ifp
, "rt2860", device_get_unit(sc
->dev
));
542 ifp
->if_flags
= IFF_BROADCAST
| IFF_SIMPLEX
| IFF_MULTICAST
;
544 ifp
->if_init
= rt2860_init
;
545 ifp
->if_ioctl
= rt2860_ioctl
;
546 ifp
->if_start
= rt2860_start
;
548 IFQ_SET_MAXLEN(&ifp
->if_snd
, IFQ_MAXLEN
);
549 ifp
->if_snd
.ifq_drv_maxlen
= IFQ_MAXLEN
;
550 IFQ_SET_READY(&ifp
->if_snd
);
556 ic
->ic_phytype
= IEEE80211_T_HT
;
557 ic
->ic_opmode
= IEEE80211_M_STA
;
559 ic
->ic_caps
= IEEE80211_C_MONITOR
|
568 IEEE80211_C_SHPREAMBLE
|
575 ic
->ic_cryptocaps
|= IEEE80211_CRYPTO_WEP
|
576 IEEE80211_CRYPTO_TKIP
|
577 IEEE80211_CRYPTO_TKIPMIC
|
578 IEEE80211_CRYPTO_AES_CCM
;
580 ic
->ic_htcaps
= IEEE80211_HTC_HT
|
581 IEEE80211_HTC_AMSDU
| /* A-MSDU Tx */
582 IEEE80211_HTC_AMPDU
| /* A-MPDU Tx */
583 IEEE80211_HTCAP_MAXAMSDU_3839
| /* max. A-MSDU Rx length */
584 IEEE80211_HTCAP_CHWIDTH40
| /* HT 40MHz channel width */
585 IEEE80211_HTCAP_GREENFIELD
| /* HT greenfield */
586 IEEE80211_HTCAP_SHORTGI20
| /* HT 20MHz short GI */
587 IEEE80211_HTCAP_SHORTGI40
| /* HT 40MHz short GI */
588 IEEE80211_HTCAP_SMPS_OFF
| /* SM power save mode */
589 IEEE80211_HTCAP_MCSFBACK_UNSOL
| /* unsolicited MCS feedback */
590 IEEE80211_HTCAP_HTC
; /* HTC+ */
592 /* spatial streams */
594 if (sc
->nrxpath
== 2)
595 ic
->ic_htcaps
|= IEEE80211_HTCAP_RXSTBC_2STREAM
;
596 else if (sc
->nrxpath
== 3)
597 ic
->ic_htcaps
|= IEEE80211_HTCAP_RXSTBC_3STREAM
;
599 ic
->ic_htcaps
|= IEEE80211_HTCAP_RXSTBC_1STREAM
;
602 ic
->ic_htcaps
|= IEEE80211_HTCAP_TXSTBC
;
606 if (sc
->mac_rev
!= 0x28600100)
607 ic
->ic_htcaps
|= IEEE80211_HTCAP_DELBA
;
613 rt2860_init_channels(sc
);
615 rt2860_init_channels_ht40(sc
);
617 ieee80211_ifattach(ic
, sc
->mac_addr
);
619 ic
->ic_vap_create
= rt2860_vap_create
;
620 ic
->ic_vap_delete
= rt2860_vap_delete
;
622 ic
->ic_node_alloc
= rt2860_node_alloc
;
623 ic
->ic_setregdomain
= rt2860_setregdomain
;
624 ic
->ic_getradiocaps
= rt2860_getradiocaps
;
625 ic
->ic_scan_start
= rt2860_scan_start
;
626 ic
->ic_scan_end
= rt2860_scan_end
;
627 ic
->ic_set_channel
= rt2860_set_channel
;
628 ic
->ic_newassoc
= rt2860_newassoc
;
629 ic
->ic_updateslot
= rt2860_updateslot
;
630 ic
->ic_update_promisc
= rt2860_update_promisc
;
631 ic
->ic_update_mcast
= rt2860_update_mcast
;
632 ic
->ic_wme
.wme_update
= rt2860_wme_update
;
633 ic
->ic_raw_xmit
= rt2860_raw_xmit
;
635 sc
->recv_action
= ic
->ic_recv_action
;
636 ic
->ic_recv_action
= rt2860_recv_action
;
638 sc
->send_action
= ic
->ic_send_action
;
639 ic
->ic_send_action
= rt2860_send_action
;
641 /* hardware requires padding between 802.11 frame header and body */
643 ic
->ic_flags
|= IEEE80211_F_DATAPAD
| IEEE80211_F_DOTH
;
645 ic
->ic_flags_ext
|= IEEE80211_FEXT_SWBMISS
;
647 ieee80211_radiotap_attach(ic
,
648 &sc
->txtap
.ihdr
, sizeof(sc
->txtap
),
649 RT2860_SOFTC_TX_RADIOTAP_PRESENT
,
650 &sc
->rxtap
.ihdr
, sizeof(sc
->rxtap
),
651 RT2860_SOFTC_RX_RADIOTAP_PRESENT
);
653 /* init task queue */
655 TASK_INIT(&sc
->rx_done_task
, 0, rt2860_rx_done_task
, sc
);
656 TASK_INIT(&sc
->tx_done_task
, 0, rt2860_tx_done_task
, sc
);
657 TASK_INIT(&sc
->fifo_sta_full_task
, 0, rt2860_fifo_sta_full_task
, sc
);
658 TASK_INIT(&sc
->periodic_task
, 0, rt2860_periodic_task
, sc
);
660 sc
->rx_process_limit
= 100;
662 sc
->taskqueue
= taskqueue_create("rt2860_taskq", M_NOWAIT
,
663 taskqueue_thread_enqueue
, &sc
->taskqueue
);
665 taskqueue_start_threads(&sc
->taskqueue
, 1, PI_NET
, "%s taskq",
666 device_get_nameunit(sc
->dev
));
668 rt2860_sysctl_attach(sc
);
671 ieee80211_announce(ic
);
673 /* set up interrupt */
675 error
= bus_setup_intr(dev
, sc
->irq
, INTR_TYPE_NET
| INTR_MPSAFE
,
676 NULL
, rt2860_intr
, sc
, &sc
->irqh
);
679 printf("%s: could not set up interrupt\n",
680 device_get_nameunit(dev
));
688 /* free Tx and Rx rings */
690 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
691 rt2860_free_tx_ring(sc
, &sc
->tx_ring
[i
]);
693 rt2860_free_rx_ring(sc
, &sc
->rx_ring
);
695 mtx_destroy(&sc
->lock
);
698 bus_release_resource(dev
, SYS_RES_MEMORY
, sc
->mem_rid
, sc
->mem
);
701 bus_release_resource(dev
, SYS_RES_IRQ
, sc
->irq_rid
, sc
->irq
);
709 static int rt2860_detach(device_t dev
)
711 struct rt2860_softc
*sc
;
713 struct ieee80211com
*ic
;
716 sc
= device_get_softc(dev
);
720 RT2860_DPRINTF(sc
, RT2860_DEBUG_ANY
,
722 device_get_nameunit(sc
->dev
));
724 RT2860_SOFTC_LOCK(sc
);
726 ifp
->if_drv_flags
&= ~(IFF_DRV_RUNNING
| IFF_DRV_OACTIVE
);
728 callout_stop(&sc
->periodic_ch
);
729 callout_stop(&sc
->tx_watchdog_ch
);
731 taskqueue_drain(sc
->taskqueue
, &sc
->rx_done_task
);
732 taskqueue_drain(sc
->taskqueue
, &sc
->tx_done_task
);
733 taskqueue_drain(sc
->taskqueue
, &sc
->fifo_sta_full_task
);
734 taskqueue_drain(sc
->taskqueue
, &sc
->periodic_task
);
736 /* free Tx and Rx rings */
738 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
739 rt2860_free_tx_ring(sc
, &sc
->tx_ring
[i
]);
741 rt2860_free_rx_ring(sc
, &sc
->rx_ring
);
743 RT2860_SOFTC_UNLOCK(sc
);
745 ieee80211_ifdetach(ic
);
749 taskqueue_free(sc
->taskqueue
);
751 mtx_destroy(&sc
->lock
);
753 bus_generic_detach(dev
);
755 bus_teardown_intr(dev
, sc
->irq
, sc
->irqh
);
757 bus_release_resource(dev
, SYS_RES_IRQ
, sc
->irq_rid
, sc
->irq
);
759 bus_release_resource(dev
, SYS_RES_MEMORY
, sc
->mem_rid
, sc
->mem
);
767 static int rt2860_shutdown(device_t dev
)
769 struct rt2860_softc
*sc
;
771 sc
= device_get_softc(dev
);
773 RT2860_DPRINTF(sc
, RT2860_DEBUG_ANY
,
774 "%s: shutting down\n",
775 device_get_nameunit(sc
->dev
));
779 sc
->flags
&= ~RT2860_SOFTC_FLAGS_UCODE_LOADED
;
787 static int rt2860_suspend(device_t dev
)
789 struct rt2860_softc
*sc
;
791 sc
= device_get_softc(dev
);
793 RT2860_DPRINTF(sc
, RT2860_DEBUG_ANY
,
795 device_get_nameunit(sc
->dev
));
799 sc
->flags
&= ~RT2860_SOFTC_FLAGS_UCODE_LOADED
;
807 static int rt2860_resume(device_t dev
)
809 struct rt2860_softc
*sc
;
812 sc
= device_get_softc(dev
);
815 RT2860_DPRINTF(sc
, RT2860_DEBUG_ANY
,
817 device_get_nameunit(sc
->dev
));
819 if (ifp
->if_flags
& IFF_UP
)
826 * rt2860_init_channels
828 static void rt2860_init_channels(struct rt2860_softc
*sc
)
831 struct ieee80211com
*ic
;
832 struct ieee80211_channel
*c
;
838 /* set supported channels for 2GHz band */
840 for (i
= 1; i
<= 14; i
++)
842 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
843 flags
= IEEE80211_CHAN_B
;
845 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
849 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
850 flags
= IEEE80211_CHAN_B
| IEEE80211_CHAN_HT20
;
852 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
856 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
857 flags
= IEEE80211_CHAN_G
;
859 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
863 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
864 flags
= IEEE80211_CHAN_G
| IEEE80211_CHAN_HT20
;
866 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
871 /* set supported channels for 5GHz band */
873 if (sc
->rf_rev
== RT2860_EEPROM_RF_2850
||
874 sc
->rf_rev
== RT2860_EEPROM_RF_2750
)
876 for (i
= 36; i
<= 64; i
+= 4)
878 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
879 flags
= IEEE80211_CHAN_A
;
881 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
885 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
886 flags
= IEEE80211_CHAN_A
| IEEE80211_CHAN_HT20
;
888 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
893 for (i
= 100; i
<= 140; i
+= 4)
895 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
896 flags
= IEEE80211_CHAN_A
;
898 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
902 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
903 flags
= IEEE80211_CHAN_A
| IEEE80211_CHAN_HT20
;
905 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
910 for (i
= 149; i
<= 165; i
+= 4)
912 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
913 flags
= IEEE80211_CHAN_A
;
915 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
919 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
920 flags
= IEEE80211_CHAN_A
| IEEE80211_CHAN_HT20
;
922 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
930 * rt2860_init_channels_ht40
932 static void rt2860_init_channels_ht40(struct rt2860_softc
*sc
)
935 struct ieee80211com
*ic
;
936 struct ieee80211_channel
*c
, *cent
, *ext
;
942 /* set supported channels for 2GHz band */
944 for (i
= 1; i
<= 14; i
++)
946 flags
= IEEE80211_CHAN_G
| IEEE80211_CHAN_HT40
;
948 /* find the center channel */
950 cent
= ieee80211_find_channel_byieee(ic
, i
,
951 flags
& ~IEEE80211_CHAN_HT
);
954 printf("%s: skip channel %d, could not find center channel\n",
955 device_get_nameunit(sc
->dev
), i
);
959 /* find the extension channel */
961 ext
= ieee80211_find_channel(ic
, cent
->ic_freq
+ 20,
962 flags
& ~IEEE80211_CHAN_HT
);
965 printf("%s: skip channel %d, could not find extension channel\n",
966 device_get_nameunit(sc
->dev
), i
);
970 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
973 c
->ic_extieee
= ext
->ic_ieee
;
974 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
975 c
->ic_flags
|= IEEE80211_CHAN_HT40U
;
977 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
980 c
->ic_extieee
= cent
->ic_ieee
;
981 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
982 c
->ic_flags
|= IEEE80211_CHAN_HT40D
;
985 /* set supported channels for 5GHz band */
987 if (sc
->rf_rev
== RT2860_EEPROM_RF_2850
||
988 sc
->rf_rev
== RT2860_EEPROM_RF_2750
)
990 for (i
= 36; i
<= 64; i
+= 4)
992 flags
= IEEE80211_CHAN_A
| IEEE80211_CHAN_HT40
;
994 /* find the center channel */
996 cent
= ieee80211_find_channel_byieee(ic
, i
,
997 flags
& ~IEEE80211_CHAN_HT
);
1000 printf("%s: skip channel %d, could not find center channel\n",
1001 device_get_nameunit(sc
->dev
), i
);
1005 /* find the extension channel */
1007 ext
= ieee80211_find_channel(ic
, cent
->ic_freq
+ 20,
1008 flags
& ~IEEE80211_CHAN_HT
);
1011 printf("%s: skip channel %d, could not find extension channel\n",
1012 device_get_nameunit(sc
->dev
), i
);
1016 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1019 c
->ic_extieee
= ext
->ic_ieee
;
1020 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1021 c
->ic_flags
|= IEEE80211_CHAN_HT40U
;
1023 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1026 c
->ic_extieee
= cent
->ic_ieee
;
1027 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1028 c
->ic_flags
|= IEEE80211_CHAN_HT40D
;
1031 for (i
= 100; i
<= 140; i
+= 4)
1033 flags
= IEEE80211_CHAN_A
| IEEE80211_CHAN_HT40
;
1035 /* find the center channel */
1037 cent
= ieee80211_find_channel_byieee(ic
, i
,
1038 flags
& ~IEEE80211_CHAN_HT
);
1041 printf("%s: skip channel %d, could not find center channel\n",
1042 device_get_nameunit(sc
->dev
), i
);
1046 /* find the extension channel */
1048 ext
= ieee80211_find_channel(ic
, cent
->ic_freq
+ 20,
1049 flags
& ~IEEE80211_CHAN_HT
);
1052 printf("%s: skip channel %d, could not find extension channel\n",
1053 device_get_nameunit(sc
->dev
), i
);
1057 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1060 c
->ic_extieee
= ext
->ic_ieee
;
1061 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1062 c
->ic_flags
|= IEEE80211_CHAN_HT40U
;
1064 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1067 c
->ic_extieee
= cent
->ic_ieee
;
1068 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1069 c
->ic_flags
|= IEEE80211_CHAN_HT40D
;
1072 for (i
= 149; i
<= 165; i
+= 4)
1074 flags
= IEEE80211_CHAN_A
| IEEE80211_CHAN_HT40
;
1076 /* find the center channel */
1078 cent
= ieee80211_find_channel_byieee(ic
, i
,
1079 flags
& ~IEEE80211_CHAN_HT
);
1082 printf("%s: skip channel %d, could not find center channel\n",
1083 device_get_nameunit(sc
->dev
), i
);
1087 /* find the extension channel */
1089 ext
= ieee80211_find_channel(ic
, cent
->ic_freq
+ 20,
1090 flags
& ~IEEE80211_CHAN_HT
);
1093 printf("%s: skip channel %d, could not find extension channel\n",
1094 device_get_nameunit(sc
->dev
), i
);
1098 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1101 c
->ic_extieee
= ext
->ic_ieee
;
1102 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1103 c
->ic_flags
|= IEEE80211_CHAN_HT40U
;
1105 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1108 c
->ic_extieee
= cent
->ic_ieee
;
1109 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1110 c
->ic_flags
|= IEEE80211_CHAN_HT40D
;
1116 * rt2860_init_locked
1118 static void rt2860_init_locked(void *priv
)
1120 struct rt2860_softc
*sc
;
1122 struct ieee80211com
*ic
;
1123 int error
, i
, ntries
;
1124 uint32_t tmp
, stacnt
[6];
1130 RT2860_DPRINTF(sc
, RT2860_DEBUG_ANY
,
1131 "%s: initializing\n",
1132 device_get_nameunit(sc
->dev
));
1134 RT2860_SOFTC_ASSERT_LOCKED(sc
);
1136 if (!(sc
->flags
& RT2860_SOFTC_FLAGS_UCODE_LOADED
))
1138 RT2860_DPRINTF(sc
, RT2860_DEBUG_ANY
,
1139 "%s: loading 8051 microcode\n",
1140 device_get_nameunit(sc
->dev
));
1142 error
= rt2860_io_mcu_load_ucode(sc
, rt2860_ucode
, sizeof(rt2860_ucode
));
1145 printf("%s: could not load 8051 microcode\n",
1146 device_get_nameunit(sc
->dev
));
1150 RT2860_DPRINTF(sc
, RT2860_DEBUG_ANY
,
1151 "%s: 8051 microcode was successfully loaded\n",
1152 device_get_nameunit(sc
->dev
));
1154 sc
->flags
|= RT2860_SOFTC_FLAGS_UCODE_LOADED
;
1157 rt2860_io_mac_write(sc
, RT2860_REG_PWR_PIN_CFG
, 0x2);
1159 /* disable DMA engine */
1161 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
);
1164 tmp
|= RT2860_REG_TX_WB_DDONE
;
1166 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
, tmp
);
1168 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WPDMA_RST_IDX
, 0xffffffff);
1170 /* PBF hardware reset */
1172 rt2860_io_mac_write(sc
, RT2860_REG_PBF_SYS_CTRL
, 0xe1f);
1173 rt2860_io_mac_write(sc
, RT2860_REG_PBF_SYS_CTRL
, 0xe00);
1175 /* wait while DMA engine is busy */
1177 for (ntries
= 0; ntries
< 100; ntries
++)
1179 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
);
1180 if (!(tmp
& (RT2860_REG_TX_DMA_BUSY
| RT2860_REG_RX_DMA_BUSY
)))
1188 printf("%s: timeout waiting for DMA engine\n",
1189 device_get_nameunit(sc
->dev
));
1194 tmp
|= RT2860_REG_TX_WB_DDONE
;
1196 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
, tmp
);
1198 /* reset Rx and Tx rings */
1200 tmp
= RT2860_REG_RST_IDX_RX
|
1201 RT2860_REG_RST_IDX_TX_MGMT
|
1202 RT2860_REG_RST_IDX_TX_HCCA
|
1203 RT2860_REG_RST_IDX_TX_AC3
|
1204 RT2860_REG_RST_IDX_TX_AC2
|
1205 RT2860_REG_RST_IDX_TX_AC1
|
1206 RT2860_REG_RST_IDX_TX_AC0
;
1208 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WPDMA_RST_IDX
, tmp
);
1210 /* PBF hardware reset */
1212 rt2860_io_mac_write(sc
, RT2860_REG_PBF_SYS_CTRL
, 0xe1f);
1213 rt2860_io_mac_write(sc
, RT2860_REG_PBF_SYS_CTRL
, 0xe00);
1215 rt2860_io_mac_write(sc
, RT2860_REG_PWR_PIN_CFG
, 0x3);
1217 rt2860_io_mac_write(sc
, RT2860_REG_SYS_CTRL
,
1218 RT2860_REG_MAC_SRST
| RT2860_REG_BBP_HRST
);
1219 rt2860_io_mac_write(sc
, RT2860_REG_SYS_CTRL
, 0);
1221 /* init Tx power per rate */
1223 for (i
= 0; i
< RT2860_SOFTC_TXPOW_RATE_COUNT
; i
++)
1225 if (sc
->txpow_rate_20mhz
[i
] == 0xffffffff)
1228 rt2860_io_mac_write(sc
, RT2860_REG_TX_PWR_CFG(i
),
1229 sc
->txpow_rate_20mhz
[i
]);
1232 for (i
= 0; i
< RT2860_DEF_MAC_SIZE
; i
++)
1233 rt2860_io_mac_write(sc
, rt2860_def_mac
[i
].reg
,
1234 rt2860_def_mac
[i
].val
);
1236 /* wait while MAC is busy */
1238 for (ntries
= 0; ntries
< 100; ntries
++)
1240 if (!(rt2860_io_mac_read(sc
, RT2860_REG_STATUS_CFG
) &
1241 (RT2860_REG_STATUS_TX_BUSY
| RT2860_REG_STATUS_RX_BUSY
)))
1249 printf("%s: timeout waiting for MAC\n",
1250 device_get_nameunit(sc
->dev
));
1254 /* clear Host to MCU mailbox */
1256 rt2860_io_mac_write(sc
, RT2860_REG_H2M_MAILBOX_BBP_AGENT
, 0);
1257 rt2860_io_mac_write(sc
, RT2860_REG_H2M_MAILBOX
, 0);
1259 rt2860_io_mcu_cmd(sc
, RT2860_IO_MCU_CMD_BOOT
,
1260 RT2860_REG_H2M_TOKEN_NO_INTR
, 0);
1264 error
= rt2860_init_bbp(sc
);
1268 /* set up maximum buffer sizes */
1270 tmp
= (1 << 12) | RT2860_MAX_AGG_SIZE
;
1272 rt2860_io_mac_write(sc
, RT2860_REG_MAX_LEN_CFG
, tmp
);
1274 if (sc
->mac_rev
== 0x28720200)
1276 /* set max. PSDU length from 16K to 32K bytes */
1278 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_MAX_LEN_CFG
);
1283 rt2860_io_mac_write(sc
, RT2860_REG_MAX_LEN_CFG
, tmp
);
1286 if (sc
->mac_rev
>= 0x28720200 && sc
->mac_rev
< 0x30700200)
1288 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_MAX_LEN_CFG
);
1293 rt2860_io_mac_write(sc
, RT2860_REG_MAX_LEN_CFG
, tmp
);
1296 /* set mac address */
1298 rt2860_asic_set_macaddr(sc
, IF_LLADDR(ifp
));
1300 /* clear statistic registers */
1302 rt2860_io_mac_read_multi(sc
, RT2860_REG_RX_STA_CNT0
,
1303 stacnt
, sizeof(stacnt
));
1305 /* set RTS threshold */
1307 rt2860_asic_update_rtsthreshold(sc
);
1311 rt2860_asic_update_txpower(sc
);
1313 /* set up protection mode */
1315 rt2860_asic_updateprot(sc
);
1317 /* clear key tables */
1319 rt2860_asic_clear_keytables(sc
);
1321 /* clear beacon frame space (entries = 8, entry size = 512) */
1323 rt2860_io_mac_set_region_4(sc
, RT2860_REG_BEACON_BASE(0), 0, 1024);
1325 taskqueue_unblock(sc
->taskqueue
);
1327 /* init Tx rings (4 EDCAs + HCCA + MGMT) */
1329 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
1330 rt2860_reset_tx_ring(sc
, &sc
->tx_ring
[i
]);
1332 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
1334 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_BASE_PTR(i
),
1335 sc
->tx_ring
[i
].desc_phys_addr
);
1336 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_MAX_CNT(i
),
1337 RT2860_SOFTC_TX_RING_DESC_COUNT
);
1338 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_CTX_IDX(i
), 0);
1343 rt2860_reset_rx_ring(sc
, &sc
->rx_ring
);
1345 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_BASE_PTR
,
1346 sc
->rx_ring
.desc_phys_addr
);
1347 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_MAX_CNT
,
1348 RT2860_SOFTC_RX_RING_DATA_COUNT
);
1349 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_CALC_IDX
,
1350 RT2860_SOFTC_RX_RING_DATA_COUNT
- 1);
1352 /* wait while DMA engine is busy */
1354 for (ntries
= 0; ntries
< 100; ntries
++)
1356 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
);
1357 if (!(tmp
& (RT2860_REG_TX_DMA_BUSY
| RT2860_REG_RX_DMA_BUSY
)))
1365 printf("%s: timeout waiting for DMA engine\n",
1366 device_get_nameunit(sc
->dev
));
1371 tmp
|= RT2860_REG_TX_WB_DDONE
;
1373 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
, tmp
);
1375 /* disable interrupts mitigation */
1377 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_DELAY_INT_CFG
, 0);
1379 /* send LEDs operating mode to microcontroller */
1381 rt2860_io_mcu_cmd(sc
, RT2860_IO_MCU_CMD_LED1
,
1382 RT2860_REG_H2M_TOKEN_NO_INTR
, sc
->led_off
[0]);
1383 rt2860_io_mcu_cmd(sc
, RT2860_IO_MCU_CMD_LED2
,
1384 RT2860_REG_H2M_TOKEN_NO_INTR
, sc
->led_off
[1]);
1385 rt2860_io_mcu_cmd(sc
, RT2860_IO_MCU_CMD_LED3
,
1386 RT2860_REG_H2M_TOKEN_NO_INTR
, sc
->led_off
[2]);
1388 /* turn radio LED on */
1390 rt2860_led_cmd(sc
, RT2860_LED_CMD_RADIO_ON
);
1392 /* write vendor-specific BBP values (from EEPROM) */
1394 for (i
= 0; i
< RT2860_SOFTC_BBP_EEPROM_COUNT
; i
++)
1396 if (sc
->bbp_eeprom
[i
].reg
== 0x00 ||
1397 sc
->bbp_eeprom
[i
].reg
== 0xff)
1400 rt2860_io_bbp_write(sc
, sc
->bbp_eeprom
[i
].reg
,
1401 sc
->bbp_eeprom
[i
].val
);
1405 tmp = rt2860_io_mac_read(sc, RT2860_REG_SCHDMA_GPIO_CTRL_CFG);
1408 rt2860_io_mcu_cmd(sc, RT2860_IO_MCU_CMD_SLEEP,
1409 RT2860_REG_H2M_TOKEN_RADIOOFF, 0x02ff);
1410 rt2860_io_mcu_cmd_check(sc, RT2860_REG_H2M_TOKEN_RADIOOFF);
1412 rt2860_io_mcu_cmd(sc, RT2860_IO_MCU_CMD_WAKEUP,
1413 RT2860_REG_H2M_TOKEN_WAKEUP, 0);
1414 rt2860_io_mcu_cmd_check(sc, RT2860_REG_H2M_TOKEN_WAKEUP);
1418 /* disable non-existing Rx chains */
1420 tmp
= rt2860_io_bbp_read(sc
, 3);
1422 tmp
&= ~((1 << 4) | (1 << 3));
1424 if (sc
->nrxpath
== 3)
1426 else if (sc
->nrxpath
== 2)
1429 rt2860_io_bbp_write(sc
, 3, tmp
);
1431 /* disable non-existing Tx chains */
1433 tmp
= rt2860_io_bbp_read(sc
, 1);
1435 tmp
&= ~((1 << 4) | (1 << 3));
1437 if (sc
->ntxpath
== 2)
1440 rt2860_io_bbp_write(sc
, 1, tmp
);
1442 /* set current channel */
1444 rt2860_rf_set_chan(sc
, ic
->ic_curchan
);
1446 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WMM_TXOP0_CFG
, 0);
1447 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WMM_TXOP1_CFG
,
1450 if ((sc
->mac_rev
& 0xffff) != 0x0101)
1451 rt2860_io_mac_write(sc
, RT2860_REG_TX_TXOP_CTRL_CFG
, 0x583f);
1453 /* clear pending interrupts */
1455 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_INT_STATUS
, 0xffffffff);
1457 /* enable interrupts */
1459 tmp
= RT2860_REG_INT_TX_COHERENT
|
1460 RT2860_REG_INT_RX_COHERENT
|
1461 RT2860_REG_INT_GP_TIMER
|
1462 RT2860_REG_INT_AUTO_WAKEUP
|
1463 RT2860_REG_INT_FIFO_STA_FULL
|
1465 RT2860_REG_INT_PRE_TBTT |
1466 RT2860_REG_INT_TBTT |
1468 RT2860_REG_INT_TXRX_COHERENT
|
1469 RT2860_REG_INT_MCU_CMD
|
1470 RT2860_REG_INT_TX_MGMT_DONE
|
1471 RT2860_REG_INT_TX_HCCA_DONE
|
1472 RT2860_REG_INT_TX_AC3_DONE
|
1473 RT2860_REG_INT_TX_AC2_DONE
|
1474 RT2860_REG_INT_TX_AC1_DONE
|
1475 RT2860_REG_INT_TX_AC0_DONE
|
1476 RT2860_REG_INT_RX_DONE
;
1478 sc
->intr_enable_mask
= tmp
;
1480 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_INT_MASK
, tmp
);
1482 if (rt2860_txrx_enable(sc
) != 0)
1485 /* clear garbage interrupts */
1487 tmp
= rt2860_io_mac_read(sc
, 0x1300);
1489 ifp
->if_drv_flags
&= ~IFF_DRV_OACTIVE
;
1490 ifp
->if_drv_flags
|= IFF_DRV_RUNNING
;
1492 sc
->periodic_round
= 0;
1494 callout_reset(&sc
->periodic_ch
, hz
/ 10, rt2860_periodic
, sc
);
1500 rt2860_stop_locked(sc
);
1506 static void rt2860_init(void *priv
)
1508 struct rt2860_softc
*sc
;
1512 RT2860_SOFTC_LOCK(sc
);
1514 rt2860_init_locked(sc
);
1516 RT2860_SOFTC_UNLOCK(sc
);
1522 static int rt2860_init_bbp(struct rt2860_softc
*sc
)
1527 for (ntries
= 0; ntries
< 20; ntries
++)
1529 tmp
= rt2860_io_bbp_read(sc
, 0);
1530 if (tmp
!= 0x00 && tmp
!= 0xff)
1534 if (tmp
== 0x00 || tmp
== 0xff)
1536 printf("%s: timeout waiting for BBP to wakeup\n",
1537 device_get_nameunit(sc
->dev
));
1541 for (i
= 0; i
< RT2860_DEF_BBP_SIZE
; i
++)
1542 rt2860_io_bbp_write(sc
, rt2860_def_bbp
[i
].reg
,
1543 rt2860_def_bbp
[i
].val
);
1545 if ((sc
->mac_rev
& 0xffff) != 0x0101)
1546 rt2860_io_bbp_write(sc
, 84, 0x19);
1548 if (sc
->mac_rev
== 0x28600100)
1550 rt2860_io_bbp_write(sc
, 69, 0x16);
1551 rt2860_io_bbp_write(sc
, 73, 0x12);
1558 * rt2860_stop_locked
1560 static void rt2860_stop_locked(void *priv
)
1562 struct rt2860_softc
*sc
;
1564 struct ieee80211com
*ic
;
1571 RT2860_DPRINTF(sc
, RT2860_DEBUG_ANY
,
1573 device_get_nameunit(sc
->dev
));
1575 RT2860_SOFTC_ASSERT_LOCKED(sc
);
1579 if (ifp
->if_drv_flags
& IFF_DRV_RUNNING
)
1580 rt2860_led_cmd(sc
, RT2860_LED_CMD_RADIO_OFF
);
1582 ifp
->if_drv_flags
&= ~(IFF_DRV_RUNNING
| IFF_DRV_OACTIVE
);
1584 callout_stop(&sc
->periodic_ch
);
1585 callout_stop(&sc
->tx_watchdog_ch
);
1587 RT2860_SOFTC_UNLOCK(sc
);
1589 taskqueue_block(sc
->taskqueue
);
1591 taskqueue_drain(sc
->taskqueue
, &sc
->rx_done_task
);
1592 taskqueue_drain(sc
->taskqueue
, &sc
->tx_done_task
);
1593 taskqueue_drain(sc
->taskqueue
, &sc
->fifo_sta_full_task
);
1594 taskqueue_drain(sc
->taskqueue
, &sc
->periodic_task
);
1596 RT2860_SOFTC_LOCK(sc
);
1598 /* clear key tables */
1600 rt2860_asic_clear_keytables(sc
);
1602 /* disable interrupts */
1604 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_INT_MASK
, 0);
1608 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_SYS_CTRL
);
1610 tmp
&= ~(RT2860_REG_RX_ENABLE
| RT2860_REG_TX_ENABLE
);
1612 rt2860_io_mac_write(sc
, RT2860_REG_SYS_CTRL
, tmp
);
1616 rt2860_io_mac_write(sc
, RT2860_REG_SYS_CTRL
,
1617 RT2860_REG_MAC_SRST
| RT2860_REG_BBP_HRST
);
1618 rt2860_io_mac_write(sc
, RT2860_REG_SYS_CTRL
, 0);
1624 static void rt2860_stop(void *priv
)
1626 struct rt2860_softc
*sc
;
1630 RT2860_SOFTC_LOCK(sc
);
1632 rt2860_stop_locked(sc
);
1634 RT2860_SOFTC_UNLOCK(sc
);
1640 static void rt2860_start(struct ifnet
*ifp
)
1642 struct rt2860_softc
*sc
;
1643 struct ieee80211_node
*ni
;
1649 RT2860_SOFTC_LOCK(sc
);
1651 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
1653 RT2860_SOFTC_UNLOCK(sc
);
1659 IF_POLL(&ifp
->if_snd
, m
);
1663 IFQ_DRV_DEQUEUE(&ifp
->if_snd
, m
);
1665 ni
= (struct ieee80211_node
*) m
->m_pkthdr
.rcvif
;
1667 qid
= M_WME_GETAC(m
);
1669 if (sc
->tx_ring
[qid
].data_queued
>= RT2860_SOFTC_TX_RING_DATA_COUNT
)
1671 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
1672 "%s: if_start: Tx ring with qid=%d is full\n",
1673 device_get_nameunit(sc
->dev
), qid
);
1676 ieee80211_free_node(ni
);
1678 ifp
->if_drv_flags
|= IFF_DRV_OACTIVE
;
1681 sc
->tx_data_queue_full
[qid
]++;
1686 if (rt2860_tx_data(sc
, m
, ni
, qid
) != 0)
1688 ieee80211_free_node(ni
);
1695 rt2860_drain_fifo_stats(sc
);
1697 sc
->tx_timer
= RT2860_TX_WATCHDOG_TIMEOUT
;
1699 callout_reset(&sc
->tx_watchdog_ch
, hz
, rt2860_tx_watchdog
, sc
);
1702 RT2860_SOFTC_UNLOCK(sc
);
1708 static int rt2860_ioctl(struct ifnet
*ifp
, u_long cmd
, caddr_t data
)
1710 struct rt2860_softc
*sc
;
1711 struct ieee80211com
*ic
;
1713 int error
, startall
;
1717 ifr
= (struct ifreq
*) data
;
1726 RT2860_SOFTC_LOCK(sc
);
1728 if (ifp
->if_flags
& IFF_UP
)
1730 if (ifp
->if_drv_flags
& IFF_DRV_RUNNING
)
1732 if ((ifp
->if_flags
^ sc
->if_flags
) & IFF_PROMISC
)
1733 rt2860_asic_update_promisc(sc
);
1737 rt2860_init_locked(sc
);
1743 if (ifp
->if_drv_flags
& IFF_DRV_RUNNING
)
1744 rt2860_stop_locked(sc
);
1747 sc
->if_flags
= ifp
->if_flags
;
1749 RT2860_SOFTC_UNLOCK(sc
);
1752 ieee80211_start_all(ic
);
1757 error
= ifmedia_ioctl(ifp
, ifr
, &ic
->ic_media
, cmd
);
1761 error
= ether_ioctl(ifp
, cmd
, data
);
1775 static struct ieee80211vap
*rt2860_vap_create(struct ieee80211com
*ic
,
1776 const char name
[IFNAMSIZ
], int unit
, int opmode
, int flags
,
1777 const uint8_t bssid
[IEEE80211_ADDR_LEN
],
1778 const uint8_t mac
[IEEE80211_ADDR_LEN
])
1780 struct rt2860_softc
*sc
;
1782 struct rt2860_softc_vap
*rvap
;
1783 struct ieee80211vap
*vap
;
1788 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATE
,
1789 "%s: VAP create: opmode=%s\n",
1790 device_get_nameunit(sc
->dev
),
1791 ieee80211_opmode_name
[opmode
]);
1795 case IEEE80211_M_MONITOR
:
1796 case IEEE80211_M_IBSS
:
1797 case IEEE80211_M_STA
:
1798 case IEEE80211_M_AHDEMO
:
1799 case IEEE80211_M_HOSTAP
:
1800 case IEEE80211_M_MBSS
:
1801 if (!TAILQ_EMPTY(&ic
->ic_vaps
))
1803 if_printf(ifp
, "only 1 VAP supported\n");
1807 if (opmode
== IEEE80211_M_STA
)
1808 flags
|= IEEE80211_CLONE_NOBEACONS
;
1811 case IEEE80211_M_WDS
:
1812 if (TAILQ_EMPTY(&ic
->ic_vaps
) || ic
->ic_opmode
!= IEEE80211_M_HOSTAP
)
1814 if_printf(ifp
, "WDS only supported in AP mode\n");
1818 flags
&= ~IEEE80211_CLONE_BSSID
;
1822 if_printf(ifp
, "unknown opmode %d\n", opmode
);
1826 rvap
= (struct rt2860_softc_vap
*) malloc(sizeof(struct rt2860_softc_vap
),
1827 M_80211_VAP
, M_NOWAIT
| M_ZERO
);
1833 ieee80211_vap_setup(ic
, vap
, name
, unit
, opmode
, flags
, bssid
, mac
);
1835 rvap
->newstate
= vap
->iv_newstate
;
1836 vap
->iv_newstate
= rt2860_vap_newstate
;
1838 vap
->iv_reset
= rt2860_vap_reset
;
1839 vap
->iv_key_update_begin
= rt2860_vap_key_update_begin
;
1840 vap
->iv_key_update_end
= rt2860_vap_key_update_end
;
1841 vap
->iv_key_set
= rt2860_vap_key_set
;
1842 vap
->iv_key_delete
= rt2860_vap_key_delete
;
1843 vap
->iv_update_beacon
= rt2860_vap_update_beacon
;
1845 rt2860_amrr_init(&rvap
->amrr
, vap
,
1847 RT2860_AMRR_MIN_SUCCESS_THRESHOLD
,
1848 RT2860_AMRR_MAX_SUCCESS_THRESHOLD
,
1851 ieee80211_vap_attach(vap
, rt2860_media_change
, ieee80211_media_status
);
1853 /* override default Rx A-MPDU factor */
1855 vap
->iv_ampdu_rxmax
= IEEE80211_HTCAP_MAXRXAMPDU_32K
;
1856 vap
->iv_ampdu_density
= IEEE80211_HTCAP_MPDUDENSITY_NA
;
1857 vap
->iv_ampdu_limit
= vap
->iv_ampdu_rxmax
;
1859 ic
->ic_opmode
= opmode
;
1867 static void rt2860_vap_delete(struct ieee80211vap
*vap
)
1869 struct rt2860_softc
*sc
;
1870 struct ieee80211com
*ic
;
1872 struct rt2860_softc_vap
*rvap
;
1877 rvap
= (struct rt2860_softc_vap
*) vap
;
1879 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATE
,
1880 "%s: VAP delete: opmode=%s\n",
1881 device_get_nameunit(sc
->dev
),
1882 ieee80211_opmode_name
[vap
->iv_opmode
]);
1884 rt2860_amrr_cleanup(&rvap
->amrr
);
1886 ieee80211_vap_detach(vap
);
1888 free(rvap
, M_80211_VAP
);
1894 static int rt2860_vap_reset(struct ieee80211vap
*vap
, u_long cmd
)
1896 struct rt2860_softc
*sc
;
1897 struct ieee80211com
*ic
;
1899 struct rt2860_softc_vap
*rvap
;
1905 rvap
= (struct rt2860_softc_vap
*) vap
;
1907 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATE
,
1908 "%s: VAP reset: cmd=%lu\n",
1909 device_get_nameunit(sc
->dev
), cmd
);
1915 case IEEE80211_IOC_RTSTHRESHOLD
:
1916 case IEEE80211_IOC_AMSDU
:
1917 rt2860_asic_update_rtsthreshold(sc
);
1920 case IEEE80211_IOC_PROTMODE
:
1921 case IEEE80211_IOC_HTPROTMODE
:
1922 rt2860_asic_updateprot(sc
);
1925 case IEEE80211_IOC_TXPOWER
:
1926 rt2860_asic_update_txpower(sc
);
1929 case IEEE80211_IOC_BURST
:
1930 rt2860_asic_updateslot(sc
);
1933 case IEEE80211_IOC_SHORTGI
:
1934 case IEEE80211_IOC_AMPDU_DENSITY
:
1946 * rt2860_vap_newstate
1948 static int rt2860_vap_newstate(struct ieee80211vap
*vap
,
1949 enum ieee80211_state nstate
, int arg
)
1951 struct rt2860_softc
*sc
;
1952 struct ieee80211com
*ic
;
1954 struct rt2860_softc_vap
*rvap
;
1955 struct ieee80211_node
*ni
;
1956 enum ieee80211_state ostate
;
1962 rvap
= (struct rt2860_softc_vap
*) vap
;
1964 ostate
= vap
->iv_state
;
1966 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATE
,
1967 "%s: VAP newstate: %s -> %s\n",
1968 device_get_nameunit(sc
->dev
),
1969 ieee80211_state_name
[ostate
], ieee80211_state_name
[nstate
]);
1971 error
= rvap
->newstate(vap
, nstate
, arg
);
1975 IEEE80211_UNLOCK(ic
);
1977 RT2860_SOFTC_LOCK(sc
);
1979 /* turn link LED off */
1981 if (nstate
!= IEEE80211_S_RUN
)
1982 rt2860_led_cmd(sc
, RT2860_LED_CMD_RADIO_OFF
);
1986 case IEEE80211_S_INIT
:
1987 rt2860_asic_disable_tsf_sync(sc
);
1990 case IEEE80211_S_RUN
:
1993 rt2860_rf_set_chan(sc
, ni
->ni_chan
);
1995 if (vap
->iv_opmode
!= IEEE80211_M_MONITOR
)
1997 rt2860_asic_enable_mrr(sc
);
1998 rt2860_asic_set_txpreamble(sc
);
1999 rt2860_asic_set_basicrates(sc
);
2000 rt2860_asic_update_txpower(sc
);
2001 rt2860_asic_set_bssid(sc
, ni
->ni_bssid
);
2004 if (vap
->iv_opmode
== IEEE80211_M_HOSTAP
||
2005 vap
->iv_opmode
== IEEE80211_M_IBSS
||
2006 vap
->iv_opmode
== IEEE80211_M_MBSS
)
2008 error
= rt2860_asic_update_beacon(sc
, vap
);
2013 if (vap
->iv_opmode
!= IEEE80211_M_MONITOR
)
2014 rt2860_asic_enable_tsf_sync(sc
);
2016 /* turn link LED on */
2018 if (vap
->iv_opmode
!= IEEE80211_M_MONITOR
)
2020 rt2860_led_cmd(sc
, RT2860_LED_CMD_RADIO_ON
|
2021 (IEEE80211_IS_CHAN_2GHZ(ni
->ni_chan
) ?
2022 RT2860_LED_CMD_LINK_2GHZ
: RT2860_LED_CMD_LINK_5GHZ
));
2030 RT2860_SOFTC_UNLOCK(sc
);
2038 * rt2860_vap_key_update_begin
2040 static void rt2860_vap_key_update_begin(struct ieee80211vap
*vap
)
2042 struct rt2860_softc
*sc
;
2043 struct ieee80211com
*ic
;
2050 RT2860_DPRINTF(sc
, RT2860_DEBUG_KEY
,
2051 "%s: VAP key update begin\n",
2052 device_get_nameunit(sc
->dev
));
2054 taskqueue_block(sc
->taskqueue
);
2056 IF_LOCK(&ifp
->if_snd
);
2060 * rt2860_vap_key_update_end
2062 static void rt2860_vap_key_update_end(struct ieee80211vap
*vap
)
2064 struct rt2860_softc
*sc
;
2065 struct ieee80211com
*ic
;
2072 RT2860_DPRINTF(sc
, RT2860_DEBUG_KEY
,
2073 "%s: VAP key update end\n",
2074 device_get_nameunit(sc
->dev
));
2076 IF_UNLOCK(&ifp
->if_snd
);
2078 taskqueue_unblock(sc
->taskqueue
);
2082 * rt2860_vap_key_set
2084 static int rt2860_vap_key_set(struct ieee80211vap
*vap
,
2085 const struct ieee80211_key
*k
, const uint8_t mac
[IEEE80211_ADDR_LEN
])
2087 struct rt2860_softc
*sc
;
2088 struct ieee80211com
*ic
;
2090 struct ieee80211_node
*ni
;
2091 uint16_t associd
, key_base
, keymode_base
;
2092 uint8_t mode
, vapid
, wcid
, iv
[8];
2095 if (k
->wk_cipher
->ic_cipher
!= IEEE80211_CIPHER_WEP
&&
2096 k
->wk_cipher
->ic_cipher
!= IEEE80211_CIPHER_TKIP
&&
2097 k
->wk_cipher
->ic_cipher
!= IEEE80211_CIPHER_AES_CCM
)
2104 if (vap
->iv_opmode
!= IEEE80211_M_HOSTAP
)
2107 ni
= ieee80211_find_vap_node(&ic
->ic_sta
, vap
, mac
);
2109 associd
= (ni
!= NULL
) ? ni
->ni_associd
: 0;
2111 if ((vap
->iv_opmode
== IEEE80211_M_HOSTAP
) && (ni
!= NULL
))
2112 ieee80211_free_node(ni
);
2114 switch (k
->wk_cipher
->ic_cipher
)
2116 case IEEE80211_CIPHER_WEP
:
2117 if(k
->wk_keylen
< 8)
2118 mode
= RT2860_REG_CIPHER_MODE_WEP40
;
2120 mode
= RT2860_REG_CIPHER_MODE_WEP104
;
2123 case IEEE80211_CIPHER_TKIP
:
2124 mode
= RT2860_REG_CIPHER_MODE_TKIP
;
2127 case IEEE80211_CIPHER_AES_CCM
:
2128 mode
= RT2860_REG_CIPHER_MODE_AES_CCMP
;
2135 RT2860_DPRINTF(sc
, RT2860_DEBUG_KEY
,
2136 "%s: VAP key set: keyix=%d, keylen=%d, associd=0x%04x, mode=%d, group=%d\n",
2137 device_get_nameunit(sc
->dev
), k
->wk_keyix
, k
->wk_keylen
, associd
, mode
,
2138 (k
->wk_flags
& IEEE80211_KEY_GROUP
) ? 1 : 0);
2140 if (!(k
->wk_flags
& IEEE80211_KEY_GROUP
))
2142 /* install pairwise key */
2145 wcid
= RT2860_AID2WCID(associd
);
2146 key_base
= RT2860_REG_PKEY(wcid
);
2148 if (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_WEP
)
2152 iv
[3] = (k
->wk_keyix
<< 6);
2156 if (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_TKIP
)
2158 iv
[0] = (k
->wk_keytsc
>> 8);
2159 iv
[1] = ((iv
[0] | 0x20) & 0x7f);
2160 iv
[2] = k
->wk_keytsc
;
2166 iv
[0] = k
->wk_keytsc
;
2167 iv
[1] = k
->wk_keytsc
>> 8;
2171 iv
[3] = ((k
->wk_keyix
<< 6) | IEEE80211_WEP_EXTIV
);
2172 iv
[4] = (k
->wk_keytsc
>> 16);
2173 iv
[5] = (k
->wk_keytsc
>> 24);
2174 iv
[6] = (k
->wk_keytsc
>> 32);
2175 iv
[7] = (k
->wk_keytsc
>> 40);
2177 RT2860_DPRINTF(sc
, RT2860_DEBUG_KEY
,
2178 "%s: VAP key set: iv=%02x %02x %02x %02x %02x %02x %02x %02x\n",
2179 device_get_nameunit(sc
->dev
),
2180 iv
[0], iv
[1], iv
[2], iv
[3], iv
[4], iv
[5], iv
[6], iv
[7]);
2183 rt2860_io_mac_write_multi(sc
, RT2860_REG_IVEIV(wcid
), iv
, 8);
2185 if (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_TKIP
)
2187 rt2860_io_mac_write_multi(sc
, key_base
, k
->wk_key
, 16);
2189 if (vap
->iv_opmode
!= IEEE80211_M_HOSTAP
)
2191 rt2860_io_mac_write_multi(sc
, key_base
+ 16, &k
->wk_key
[16], 8);
2192 rt2860_io_mac_write_multi(sc
, key_base
+ 24, &k
->wk_key
[24], 8);
2196 rt2860_io_mac_write_multi(sc
, key_base
+ 16, &k
->wk_key
[24], 8);
2197 rt2860_io_mac_write_multi(sc
, key_base
+ 24, &k
->wk_key
[16], 8);
2202 rt2860_io_mac_write_multi(sc
, key_base
, k
->wk_key
, k
->wk_keylen
);
2205 tmp
= ((vapid
& RT2860_REG_VAP_MASK
) << RT2860_REG_VAP_SHIFT
) |
2206 (mode
<< RT2860_REG_CIPHER_MODE_SHIFT
) | RT2860_REG_PKEY_ENABLE
;
2208 rt2860_io_mac_write(sc
, RT2860_REG_WCID_ATTR(wcid
), tmp
);
2211 if ((k
->wk_flags
& IEEE80211_KEY_GROUP
) ||
2212 (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_WEP
))
2214 /* install group key */
2217 key_base
= RT2860_REG_SKEY(vapid
, k
->wk_keyix
);
2218 keymode_base
= RT2860_REG_SKEY_MODE(vapid
);
2220 if (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_TKIP
)
2222 rt2860_io_mac_write_multi(sc
, key_base
, k
->wk_key
, 16);
2224 if (vap
->iv_opmode
!= IEEE80211_M_HOSTAP
)
2226 rt2860_io_mac_write_multi(sc
, key_base
+ 16, &k
->wk_key
[16], 8);
2227 rt2860_io_mac_write_multi(sc
, key_base
+ 24, &k
->wk_key
[24], 8);
2231 rt2860_io_mac_write_multi(sc
, key_base
+ 16, &k
->wk_key
[24], 8);
2232 rt2860_io_mac_write_multi(sc
, key_base
+ 24, &k
->wk_key
[16], 8);
2237 rt2860_io_mac_write_multi(sc
, key_base
, k
->wk_key
, k
->wk_keylen
);
2240 tmp
= rt2860_io_mac_read(sc
, keymode_base
);
2242 tmp
&= ~(0xf << (k
->wk_keyix
* 4 + 16 * (vapid
% 2)));
2243 tmp
|= (mode
<< (k
->wk_keyix
* 4 + 16 * (vapid
% 2)));
2245 rt2860_io_mac_write(sc
, keymode_base
, tmp
);
2252 * rt2860_vap_key_delete
2254 static int rt2860_vap_key_delete(struct ieee80211vap
*vap
,
2255 const struct ieee80211_key
*k
)
2257 struct rt2860_softc
*sc
;
2258 struct ieee80211com
*ic
;
2260 struct ieee80211_node
*ni
;
2262 uint8_t vapid
, wcid
;
2269 associd
= (ni
!= NULL
) ? ni
->ni_associd
: 0;
2271 RT2860_DPRINTF(sc
, RT2860_DEBUG_KEY
,
2272 "%s: VAP key delete: keyix=%d, keylen=%d, associd=0x%04x, group=%d\n",
2273 device_get_nameunit(sc
->dev
), k
->wk_keyix
, k
->wk_keylen
, associd
,
2274 (k
->wk_flags
& IEEE80211_KEY_GROUP
) ? 1 : 0);
2276 if (!(k
->wk_flags
& IEEE80211_KEY_GROUP
))
2278 /* remove pairwise key */
2281 wcid
= RT2860_AID2WCID(associd
);
2283 tmp
= ((vapid
& RT2860_REG_VAP_MASK
) << RT2860_REG_VAP_SHIFT
) |
2284 (RT2860_REG_CIPHER_MODE_NONE
<< RT2860_REG_CIPHER_MODE_SHIFT
) | RT2860_REG_PKEY_ENABLE
;
2286 rt2860_io_mac_write(sc
, RT2860_REG_WCID_ATTR(wcid
), tmp
);
2290 /* remove group key */
2294 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_SKEY_MODE(vapid
));
2296 tmp
&= ~(0xf << (k
->wk_keyix
* 4 + 16 * (vapid
% 2)));
2297 tmp
|= (RT2860_REG_CIPHER_MODE_NONE
<< (k
->wk_keyix
* 4 + 16 * (vapid
% 2)));
2299 rt2860_io_mac_write(sc
, RT2860_REG_SKEY_MODE(vapid
), tmp
);
2306 * rt2860_vap_update_beacon
2308 static void rt2860_vap_update_beacon(struct ieee80211vap
*vap
, int what
)
2310 struct rt2860_softc
*sc
;
2311 struct ieee80211com
*ic
;
2318 RT2860_DPRINTF(sc
, RT2860_DEBUG_BEACON
,
2319 "%s: VAP update beacon\n",
2320 device_get_nameunit(sc
->dev
));
2322 rt2860_asic_update_beacon(sc
, vap
);
2326 * rt2860_media_change
2328 static int rt2860_media_change(struct ifnet
*ifp
)
2332 error
= ieee80211_media_change(ifp
);
2334 return (error
== ENETRESET
? 0 : error
);
2340 static struct ieee80211_node
*rt2860_node_alloc(struct ieee80211vap
*vap
,
2341 const uint8_t mac
[IEEE80211_ADDR_LEN
])
2343 return malloc(sizeof(struct rt2860_softc_node
),
2344 M_80211_NODE
, M_NOWAIT
| M_ZERO
);
2348 * rt2860_setregdomain
2350 static int rt2860_setregdomain(struct ieee80211com
*ic
,
2351 struct ieee80211_regdomain
*reg
,
2352 int nchans
, struct ieee80211_channel chans
[])
2354 struct rt2860_softc
*sc
;
2360 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATE
,
2361 "%s: set regulatory domain: country=%d, country code string=%c%c, location=%c\n",
2362 device_get_nameunit(sc
->dev
),
2363 reg
->country
, reg
->isocc
[0], reg
->isocc
[1], reg
->location
);
2369 * rt2860_getradiocaps
2371 static void rt2860_getradiocaps(struct ieee80211com
*ic
,
2372 int maxchans
, int *nchans
, struct ieee80211_channel chans
[])
2374 *nchans
= (ic
->ic_nchans
>= maxchans
) ? maxchans
: ic
->ic_nchans
;
2376 memcpy(chans
, ic
->ic_channels
, (*nchans
) * sizeof(struct ieee80211_channel
));
2382 static void rt2860_scan_start(struct ieee80211com
*ic
)
2384 struct rt2860_softc
*sc
;
2390 rt2860_asic_disable_tsf_sync(sc
);
2396 static void rt2860_scan_end(struct ieee80211com
*ic
)
2398 struct rt2860_softc
*sc
;
2404 rt2860_asic_enable_tsf_sync(sc
);
2408 * rt2860_set_channel
2410 static void rt2860_set_channel(struct ieee80211com
*ic
)
2412 struct rt2860_softc
*sc
;
2418 RT2860_DPRINTF(sc
, RT2860_DEBUG_CHAN
,
2419 "%s: set channel: channel=%u, HT%s%s\n",
2420 device_get_nameunit(sc
->dev
),
2421 ieee80211_chan2ieee(ic
, ic
->ic_curchan
),
2422 !IEEE80211_IS_CHAN_HT(ic
->ic_curchan
) ? " disabled" :
2423 IEEE80211_IS_CHAN_HT20(ic
->ic_curchan
) ? "20":
2424 IEEE80211_IS_CHAN_HT40U(ic
->ic_curchan
) ? "40U" : "40D",
2425 (ic
->ic_flags
& IEEE80211_F_SCAN
) ? ", scanning" : "");
2427 RT2860_SOFTC_LOCK(sc
);
2429 rt2860_rf_set_chan(sc
, ic
->ic_curchan
);
2431 RT2860_SOFTC_UNLOCK(sc
);
2437 static void rt2860_newassoc(struct ieee80211_node
*ni
, int isnew
)
2439 struct rt2860_softc
*sc
;
2440 struct ieee80211com
*ic
;
2442 struct ieee80211vap
*vap
;
2443 struct rt2860_softc_vap
*rvap
;
2451 rvap
= (struct rt2860_softc_vap
*) vap
;
2453 associd
= (ni
!= NULL
) ? ni
->ni_associd
: 0;
2454 wcid
= RT2860_AID2WCID(associd
);
2456 RT2860_DPRINTF(sc
, RT2860_DEBUG_NODE
,
2457 "%s: new association: wcid=0x%02x, "
2458 "mac addr=%s, QoS %s, ERP %s, HT %s\n",
2459 device_get_nameunit(sc
->dev
), wcid
,
2460 ether_sprintf(ni
->ni_macaddr
),
2461 (ni
->ni_flags
& IEEE80211_NODE_QOS
) ? "enabled" : "disabled",
2462 (ni
->ni_flags
& IEEE80211_NODE_ERP
) ? "enabled" : "disabled",
2463 (ni
->ni_flags
& IEEE80211_NODE_HT
) ? "enabled" : "disabled");
2465 rt2860_io_mac_write_multi(sc
, RT2860_REG_WCID(wcid
),
2466 ni
->ni_macaddr
, IEEE80211_ADDR_LEN
);
2468 rt2860_amrr_node_init(&rvap
->amrr
, &sc
->amrr_node
[wcid
], ni
);
2470 RT2860_DPRINTF(sc
, RT2860_DEBUG_RATE
,
2471 "%s: initial%s node Tx rate: associd=0x%04x, rate=0x%02x, max rate=0x%02x\n",
2472 device_get_nameunit(sc
->dev
),
2473 (ni
->ni_flags
& IEEE80211_NODE_HT
) ? " HT" : "",
2474 ni
->ni_associd
, ni
->ni_txrate
,
2475 (ni
->ni_flags
& IEEE80211_NODE_HT
) ?
2476 (ni
->ni_htrates
.rs_rates
[ni
->ni_htrates
.rs_nrates
- 1] | IEEE80211_RATE_MCS
) :
2477 (ni
->ni_rates
.rs_rates
[ni
->ni_rates
.rs_nrates
- 1] & IEEE80211_RATE_VAL
));
2479 rt2860_asic_updateprot(sc
);
2480 rt2860_asic_updateslot(sc
);
2481 rt2860_asic_set_txpreamble(sc
);
2487 static void rt2860_updateslot(struct ifnet
*ifp
)
2489 struct rt2860_softc
*sc
;
2493 rt2860_asic_updateslot(sc
);
2497 * rt2860_update_promisc
2499 static void rt2860_update_promisc(struct ifnet
*ifp
)
2501 struct rt2860_softc
*sc
;
2505 rt2860_asic_update_promisc(sc
);
2509 * rt2860_update_mcast
2511 static void rt2860_update_mcast(struct ifnet
*ifp
)
2513 struct rt2860_softc
*sc
;
2521 static int rt2860_wme_update(struct ieee80211com
*ic
)
2523 struct rt2860_softc
*sc
;
2529 rt2860_asic_wme_update(sc
);
2537 static int rt2860_raw_xmit(struct ieee80211_node
*ni
, struct mbuf
*m
,
2538 const struct ieee80211_bpf_params
*params
)
2540 struct rt2860_softc
*sc
;
2541 struct ieee80211com
*ic
;
2548 RT2860_SOFTC_LOCK(sc
);
2550 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
2552 RT2860_SOFTC_UNLOCK(sc
);
2555 ieee80211_free_node(ni
);
2560 if (sc
->tx_ring
[sc
->tx_ring_mgtqid
].data_queued
>= RT2860_SOFTC_TX_RING_DATA_COUNT
)
2562 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
2563 "%s: raw xmit: Tx ring with qid=%d is full\n",
2564 device_get_nameunit(sc
->dev
), sc
->tx_ring_mgtqid
);
2566 ifp
->if_drv_flags
|= IFF_DRV_OACTIVE
;
2568 RT2860_SOFTC_UNLOCK(sc
);
2571 ieee80211_free_node(ni
);
2573 sc
->tx_data_queue_full
[sc
->tx_ring_mgtqid
]++;
2578 if (rt2860_tx_mgmt(sc
, m
, ni
, sc
->tx_ring_mgtqid
) != 0)
2582 RT2860_SOFTC_UNLOCK(sc
);
2584 ieee80211_free_node(ni
);
2589 sc
->tx_timer
= RT2860_TX_WATCHDOG_TIMEOUT
;
2591 RT2860_SOFTC_UNLOCK(sc
);
2597 * rt2860_recv_action
2599 static int rt2860_recv_action(struct ieee80211_node
*ni
,
2600 const struct ieee80211_frame
*wh
,
2601 const uint8_t *frm
, const uint8_t *efrm
)
2603 struct rt2860_softc
*sc
;
2604 struct ieee80211com
*ic
;
2606 const struct ieee80211_action
*ia
;
2607 struct ieee80211_tx_ampdu
*tx_ampdu
;
2608 uint16_t associd
, status
, baparamset
;
2610 int ret
, tid
, bufsize
, ac
;
2617 ia
= (const struct ieee80211_action
*) frm
;
2619 ret
= sc
->recv_action(ni
, wh
, frm
, efrm
);
2621 if (ia
->ia_category
!= IEEE80211_ACTION_CAT_BA
)
2624 associd
= (ni
!= NULL
) ? ni
->ni_associd
: 0;
2625 wcid
= RT2860_AID2WCID(associd
);
2627 switch (ia
->ia_action
)
2629 /* IEEE80211_ACTION_BA_ADDBA_REQUEST */
2630 case IEEE80211_ACTION_BA_ADDBA_REQUEST
:
2631 baparamset
= LE_READ_2(frm
+ 3);
2632 tid
= RT2860_MS(baparamset
, IEEE80211_BAPS_TID
);
2633 bufsize
= RT2860_MS(baparamset
, IEEE80211_BAPS_BUFSIZ
);
2635 RT2860_DPRINTF(sc
, RT2860_DEBUG_BA
,
2636 "%s: received ADDBA request: associd=0x%04x, tid=%d, bufsize=%d\n",
2637 device_get_nameunit(sc
->dev
), associd
, tid
, bufsize
);
2639 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_WCID(wcid
) + 4);
2641 tmp
|= (0x10000 << tid
);
2643 rt2860_io_mac_write(sc
, RT2860_REG_WCID(wcid
) + 4, tmp
);
2646 /* IEEE80211_ACTION_BA_ADDBA_RESPONSE */
2647 case IEEE80211_ACTION_BA_ADDBA_RESPONSE
:
2648 status
= LE_READ_2(frm
+ 3);
2649 baparamset
= LE_READ_2(frm
+ 4);
2650 tid
= RT2860_MS(baparamset
, IEEE80211_BAPS_TID
);
2651 bufsize
= RT2860_MS(baparamset
, IEEE80211_BAPS_BUFSIZ
);
2652 ac
= TID_TO_WME_AC(tid
);
2653 tx_ampdu
= &ni
->ni_tx_ampdu
[ac
];
2655 RT2860_DPRINTF(sc
, RT2860_DEBUG_BA
,
2656 "%s: received ADDBA response: associd=0x%04x, status=%d, tid=%d, bufsize=%d\n",
2657 device_get_nameunit(sc
->dev
), associd
, status
, tid
, bufsize
);
2659 if (sc
->mac_rev
>= 0x28720200)
2661 if (tx_ampdu
->txa_wnd
> 13)
2662 tx_ampdu
->txa_wnd
= 13;
2666 if (tx_ampdu
->txa_wnd
> 7)
2667 tx_ampdu
->txa_wnd
= 7;
2670 if (status
== IEEE80211_STATUS_SUCCESS
)
2672 sc
->tx_ampdu_sessions
++;
2674 rt2860_asic_updateprot(sc
);
2678 /* IEEE80211_ACTION_BA_DELBA */
2679 case IEEE80211_ACTION_BA_DELBA
:
2680 baparamset
= LE_READ_2(frm
+ 2);
2681 tid
= RT2860_MS(baparamset
, IEEE80211_BAPS_TID
);
2683 RT2860_DPRINTF(sc
, RT2860_DEBUG_BA
,
2684 "%s: received DELBA request: associd=0x%04x, tid=%d\n",
2685 device_get_nameunit(sc
->dev
), associd
, tid
);
2687 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_WCID(wcid
) + 4);
2689 tmp
&= ~(0x10000 << tid
);
2691 rt2860_io_mac_write(sc
, RT2860_REG_WCID(wcid
) + 4, tmp
);
2699 * rt2860_send_action
2701 static int rt2860_send_action(struct ieee80211_node
*ni
,
2702 int cat
, int act
, void *sa
)
2704 struct rt2860_softc
*sc
;
2705 struct ieee80211com
*ic
;
2707 uint16_t associd
, *args
, baparamset
;
2716 ret
= sc
->send_action(ni
, cat
, act
, sa
);
2718 if (cat
!= IEEE80211_ACTION_CAT_BA
)
2721 associd
= (ni
!= NULL
) ? ni
->ni_associd
: 0;
2722 wcid
= RT2860_AID2WCID(associd
);
2727 /* IEEE80211_ACTION_BA_DELBA */
2728 case IEEE80211_ACTION_BA_DELBA
:
2729 baparamset
= RT2860_SM(args
[0], IEEE80211_DELBAPS_TID
) | args
[1];
2731 tid
= RT2860_MS(baparamset
, IEEE80211_DELBAPS_TID
);
2733 RT2860_DPRINTF(sc
, RT2860_DEBUG_BA
,
2734 "%s: sending DELBA request: associd=0x%04x, tid=%d\n",
2735 device_get_nameunit(sc
->dev
), associd
, tid
);
2737 if (RT2860_MS(baparamset
, IEEE80211_DELBAPS_INIT
) != IEEE80211_DELBAPS_INIT
)
2739 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_WCID(wcid
) + 4);
2741 tmp
&= ~(0x10000 << tid
);
2743 rt2860_io_mac_write(sc
, RT2860_REG_WCID(wcid
) + 4, tmp
);
2747 sc
->tx_ampdu_sessions
--;
2749 rt2860_asic_updateprot(sc
);
2758 * rt2860_amrr_update_iter_func
2760 static void rt2860_amrr_update_iter_func(void *arg
, struct ieee80211_node
*ni
)
2762 struct rt2860_softc
*sc
;
2763 struct ieee80211com
*ic
;
2765 struct ieee80211vap
*vap
;
2766 struct rt2860_softc_vap
*rvap
;
2773 rvap
= (struct rt2860_softc_vap
*) vap
;
2775 /* only associated stations */
2777 if ((ni
->ni_vap
== vap
) && (ni
->ni_associd
!= 0))
2779 wcid
= RT2860_AID2WCID(ni
->ni_associd
);
2781 RT2860_DPRINTF(sc
, RT2860_DEBUG_RATE
,
2782 "%s: AMRR node: wcid=0x%02x, txcnt=%d, success=%d, retrycnt=%d\n",
2783 device_get_nameunit(sc
->dev
),
2784 wcid
, sc
->amrr_node
[wcid
].txcnt
, sc
->amrr_node
[wcid
].success
, sc
->amrr_node
[wcid
].retrycnt
);
2786 rt2860_amrr_choose(ni
, &sc
->amrr_node
[wcid
]);
2788 RT2860_DPRINTF(sc
, RT2860_DEBUG_RATE
,
2789 "%s:%s node Tx rate: associd=0x%04x, rate=0x%02x, max rate=0x%02x\n",
2790 device_get_nameunit(sc
->dev
),
2791 (ni
->ni_flags
& IEEE80211_NODE_HT
) ? " HT" : "",
2792 ni
->ni_associd
, ni
->ni_txrate
,
2793 (ni
->ni_flags
& IEEE80211_NODE_HT
) ?
2794 (ni
->ni_htrates
.rs_rates
[ni
->ni_htrates
.rs_nrates
- 1] | IEEE80211_RATE_MCS
) :
2795 (ni
->ni_rates
.rs_rates
[ni
->ni_rates
.rs_nrates
- 1] & IEEE80211_RATE_VAL
));
2802 static void rt2860_periodic(void *arg
)
2804 struct rt2860_softc
*sc
;
2808 RT2860_DPRINTF(sc
, RT2860_DEBUG_PERIODIC
,
2810 device_get_nameunit(sc
->dev
));
2812 taskqueue_enqueue(sc
->taskqueue
, &sc
->periodic_task
);
2816 * rt2860_tx_watchdog
2818 static void rt2860_tx_watchdog(void *arg
)
2820 struct rt2860_softc
*sc
;
2826 if (sc
->tx_timer
== 0)
2829 if (--sc
->tx_timer
== 0)
2831 printf("%s: Tx watchdog timeout: resetting\n",
2832 device_get_nameunit(sc
->dev
));
2834 rt2860_stop_locked(sc
);
2835 rt2860_init_locked(sc
);
2839 sc
->tx_watchdog_timeouts
++;
2842 callout_reset(&sc
->tx_watchdog_ch
, hz
, rt2860_tx_watchdog
, sc
);
2846 * rt2860_asic_set_bssid
2848 static void rt2860_asic_set_bssid(struct rt2860_softc
*sc
,
2849 const uint8_t *bssid
)
2853 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATE
,
2854 "%s: set bssid: bssid=%s\n",
2855 device_get_nameunit(sc
->dev
),
2856 ether_sprintf(bssid
));
2858 tmp
= bssid
[0] | (bssid
[1]) << 8 | (bssid
[2] << 16) | (bssid
[3] << 24);
2860 rt2860_io_mac_write(sc
, RT2860_REG_BSSID_DW0
, tmp
);
2862 tmp
= bssid
[4] | (bssid
[5] << 8);
2864 rt2860_io_mac_write(sc
, RT2860_REG_BSSID_DW1
, tmp
);
2868 * rt2860_asic_set_macaddr
2870 static void rt2860_asic_set_macaddr(struct rt2860_softc
*sc
,
2871 const uint8_t *addr
)
2875 tmp
= addr
[0] | (addr
[1] << 8) | (addr
[2] << 16) | (addr
[3] << 24);
2877 rt2860_io_mac_write(sc
, RT2860_REG_ADDR_DW0
, tmp
);
2879 tmp
= addr
[4] | (addr
[5] << 8);
2881 rt2860_io_mac_write(sc
, RT2860_REG_ADDR_DW1
, tmp
);
2885 * rt2860_asic_enable_tsf_sync
2887 static void rt2860_asic_enable_tsf_sync(struct rt2860_softc
*sc
)
2890 struct ieee80211com
*ic
;
2891 struct ieee80211vap
*vap
;
2896 vap
= TAILQ_FIRST(&ic
->ic_vaps
);
2898 RT2860_DPRINTF(sc
, RT2860_DEBUG_BEACON
,
2899 "%s: enabling TSF\n",
2900 device_get_nameunit(sc
->dev
));
2902 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_BCN_TIME_CFG
);
2905 tmp
|= vap
->iv_bss
->ni_intval
* 16;
2906 tmp
|= (RT2860_REG_TSF_TIMER_ENABLE
| RT2860_REG_TBTT_TIMER_ENABLE
);
2908 if (vap
->iv_opmode
== IEEE80211_M_STA
)
2910 tmp
|= (RT2860_REG_TSF_SYNC_MODE_STA
<< RT2860_REG_TSF_SYNC_MODE_SHIFT
);
2912 else if (vap
->iv_opmode
== IEEE80211_M_IBSS
)
2914 tmp
|= RT2860_REG_BCN_TX_ENABLE
;
2915 tmp
|= (RT2860_REG_TSF_SYNC_MODE_IBSS
<< RT2860_REG_TSF_SYNC_MODE_SHIFT
);
2917 else if (vap
->iv_opmode
== IEEE80211_M_HOSTAP
)
2919 tmp
|= RT2860_REG_BCN_TX_ENABLE
;
2920 tmp
|= (RT2860_REG_TSF_SYNC_MODE_HOSTAP
<< RT2860_REG_TSF_SYNC_MODE_SHIFT
);
2923 rt2860_io_mac_write(sc
, RT2860_REG_BCN_TIME_CFG
, tmp
);
2927 * rt2860_asic_disable_tsf_sync
2929 static void rt2860_asic_disable_tsf_sync(struct rt2860_softc
*sc
)
2933 RT2860_DPRINTF(sc
, RT2860_DEBUG_BEACON
,
2934 "%s: disabling TSF\n",
2935 device_get_nameunit(sc
->dev
));
2937 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_BCN_TIME_CFG
);
2939 tmp
&= ~(RT2860_REG_BCN_TX_ENABLE
|
2940 RT2860_REG_TSF_TIMER_ENABLE
|
2941 RT2860_REG_TBTT_TIMER_ENABLE
);
2943 tmp
&= ~(RT2860_REG_TSF_SYNC_MODE_MASK
<< RT2860_REG_TSF_SYNC_MODE_SHIFT
);
2944 tmp
|= (RT2860_REG_TSF_SYNC_MODE_DISABLE
<< RT2860_REG_TSF_SYNC_MODE_SHIFT
);
2946 rt2860_io_mac_write(sc
, RT2860_REG_BCN_TIME_CFG
, tmp
);
2950 * rt2860_asic_enable_mrr
2952 static void rt2860_asic_enable_mrr(struct rt2860_softc
*sc
)
2954 #define CCK(mcs) (mcs)
2955 #define OFDM(mcs) ((1 << 3) | (mcs))
2956 #define HT(mcs) (mcs)
2958 rt2860_io_mac_write(sc
, RT2860_REG_TX_LG_FBK_CFG0
,
2959 (OFDM(6) << 28) | /* 54 -> 48 */
2960 (OFDM(5) << 24) | /* 48 -> 36 */
2961 (OFDM(4) << 20) | /* 36 -> 24 */
2962 (OFDM(3) << 16) | /* 24 -> 18 */
2963 (OFDM(2) << 12) | /* 18 -> 12 */
2964 (OFDM(1) << 8) | /* 12 -> 9 */
2965 (OFDM(0) << 4) | /* 9 -> 6 */
2966 OFDM(0)); /* 6 -> 6 */
2968 rt2860_io_mac_write(sc
, RT2860_REG_TX_LG_FBK_CFG1
,
2969 (CCK(2) << 12) | /* 11 -> 5.5 */
2970 (CCK(1) << 8) | /* 5.5 -> 2 */
2971 (CCK(0) << 4) | /* 2 -> 1 */
2972 CCK(0)); /* 1 -> 1 */
2974 rt2860_io_mac_write(sc
, RT2860_REG_TX_HT_FBK_CFG0
,
2984 rt2860_io_mac_write(sc
, RT2860_REG_TX_HT_FBK_CFG1
,
3000 * rt2860_asic_set_txpreamble
3002 static void rt2860_asic_set_txpreamble(struct rt2860_softc
*sc
)
3005 struct ieee80211com
*ic
;
3011 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATE
,
3012 "%s: %s short Tx preamble\n",
3013 device_get_nameunit(sc
->dev
),
3014 (ic
->ic_flags
& IEEE80211_F_SHPREAMBLE
) ? "enabling" : "disabling");
3016 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_AUTO_RSP_CFG
);
3018 tmp
&= ~RT2860_REG_CCK_SHORT_ENABLE
;
3020 if (ic
->ic_flags
& IEEE80211_F_SHPREAMBLE
)
3021 tmp
|= RT2860_REG_CCK_SHORT_ENABLE
;
3023 rt2860_io_mac_write(sc
, RT2860_REG_AUTO_RSP_CFG
, tmp
);
3027 * rt2860_asic_set_basicrates
3029 static void rt2860_asic_set_basicrates(struct rt2860_softc
*sc
)
3032 struct ieee80211com
*ic
;
3037 if (ic
->ic_curmode
== IEEE80211_MODE_11B
)
3038 rt2860_io_mac_write(sc
, RT2860_REG_LEGACY_BASIC_RATE
, 0x3);
3039 else if (ic
->ic_curmode
== IEEE80211_MODE_11A
)
3040 rt2860_io_mac_write(sc
, RT2860_REG_LEGACY_BASIC_RATE
, 0x150);
3042 rt2860_io_mac_write(sc
, RT2860_REG_LEGACY_BASIC_RATE
, 0x15f);
3046 * rt2860_asic_update_rtsthreshold
3048 static void rt2860_asic_update_rtsthreshold(struct rt2860_softc
*sc
)
3051 struct ieee80211com
*ic
;
3052 struct ieee80211vap
*vap
;
3058 vap
= TAILQ_FIRST(&ic
->ic_vaps
);
3060 RT2860_DPRINTF(sc
, RT2860_DEBUG_PROT
,
3061 "%s: updating RTS threshold: %d\n",
3062 device_get_nameunit(sc
->dev
), vap
->iv_rtsthreshold
);
3064 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_RTS_CFG
);
3066 tmp
&= ~(RT2860_REG_TX_RTS_THRESHOLD_MASK
<< RT2860_REG_TX_RTS_THRESHOLD_SHIFT
);
3068 if (vap
->iv_flags_ht
& IEEE80211_FHT_AMSDU_TX
)
3071 threshold
= vap
->iv_rtsthreshold
;
3073 tmp
|= ((threshold
& RT2860_REG_TX_RTS_THRESHOLD_MASK
) <<
3074 RT2860_REG_TX_RTS_THRESHOLD_SHIFT
);
3076 rt2860_io_mac_write(sc
, RT2860_REG_TX_RTS_CFG
, tmp
);
3080 * rt2860_asic_update_txpower
3082 static void rt2860_asic_update_txpower(struct rt2860_softc
*sc
)
3085 struct ieee80211com
*ic
;
3086 uint32_t *txpow_rate
;
3095 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATE
,
3096 "%s: updating Tx power: %d\n",
3097 device_get_nameunit(sc
->dev
), ic
->ic_txpowlimit
);
3099 if (!IEEE80211_IS_CHAN_HT40(ic
->ic_curchan
))
3101 txpow_rate
= sc
->txpow_rate_20mhz
;
3105 if (IEEE80211_IS_CHAN_2GHZ(ic
->ic_curchan
))
3106 txpow_rate
= sc
->txpow_rate_40mhz_2ghz
;
3108 txpow_rate
= sc
->txpow_rate_40mhz_5ghz
;
3113 val
= rt2860_io_bbp_read(sc
, 1);
3116 if (ic
->ic_txpowlimit
> 90)
3120 else if (ic
->ic_txpowlimit
> 60)
3124 else if (ic
->ic_txpowlimit
> 30)
3128 else if (ic
->ic_txpowlimit
> 15)
3132 else if (ic
->ic_txpowlimit
> 9)
3142 rt2860_io_bbp_write(sc
, 1, val
);
3144 for (i
= 0; i
< RT2860_SOFTC_TXPOW_RATE_COUNT
; i
++)
3146 if (txpow_rate
[i
] == 0xffffffff)
3149 tmp
= rt2860_read_eeprom_txpow_rate_add_delta(txpow_rate
[i
], delta
);
3151 rt2860_io_mac_write(sc
, RT2860_REG_TX_PWR_CFG(i
), tmp
);
3156 * rt2860_asic_update_promisc
3158 static void rt2860_asic_update_promisc(struct rt2860_softc
*sc
)
3165 printf("%s: %s promiscuous mode\n",
3166 device_get_nameunit(sc
->dev
),
3167 (ifp
->if_flags
& IFF_PROMISC
) ? "entering" : "leaving");
3169 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_RX_FILTER_CFG
);
3171 tmp
&= ~RT2860_REG_RX_FILTER_DROP_UC_NOME
;
3173 if (!(ifp
->if_flags
& IFF_PROMISC
))
3174 tmp
|= RT2860_REG_RX_FILTER_DROP_UC_NOME
;
3176 rt2860_io_mac_write(sc
, RT2860_REG_RX_FILTER_CFG
, tmp
);
3180 * rt2860_asic_updateprot
3182 static void rt2860_asic_updateprot(struct rt2860_softc
*sc
)
3185 struct ieee80211com
*ic
;
3186 struct ieee80211vap
*vap
;
3187 uint32_t cck_prot
, ofdm_prot
, mm20_prot
, mm40_prot
, gf20_prot
, gf40_prot
;
3189 enum ieee80211_protmode htprotmode
;
3193 vap
= TAILQ_FIRST(&ic
->ic_vaps
);
3195 /* CCK frame protection */
3197 cck_prot
= RT2860_REG_RTSTH_ENABLE
| RT2860_REG_PROT_NAV_SHORT
|
3198 RT2860_REG_TXOP_ALLOW_ALL
| RT2860_REG_PROT_CTRL_NONE
;
3200 /* set up protection frame phy mode and rate (MCS code) */
3202 if (ic
->ic_curmode
== IEEE80211_MODE_11A
)
3203 cck_prot
|= (RT2860_REG_PROT_PHYMODE_OFDM
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3204 (0 << RT2860_REG_PROT_MCS_SHIFT
);
3206 cck_prot
|= ((RT2860_REG_PROT_PHYMODE_CCK
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3207 (3 << RT2860_REG_PROT_MCS_SHIFT
));
3209 rt2860_io_mac_write(sc
, RT2860_REG_TX_CCK_PROT_CFG
, cck_prot
);
3211 /* OFDM frame protection */
3213 ofdm_prot
= RT2860_REG_RTSTH_ENABLE
| RT2860_REG_PROT_NAV_SHORT
|
3214 RT2860_REG_TXOP_ALLOW_ALL
;
3216 if (ic
->ic_flags
& IEEE80211_F_USEPROT
)
3218 RT2860_DPRINTF(sc
, RT2860_DEBUG_PROT
,
3219 "%s: updating protection mode: b/g protection mode=%s\n",
3220 device_get_nameunit(sc
->dev
),
3221 (ic
->ic_protmode
== IEEE80211_PROT_RTSCTS
) ? "RTS/CTS" :
3222 ((ic
->ic_protmode
== IEEE80211_PROT_CTSONLY
) ? "CTS-to-self" : "none"));
3224 if (ic
->ic_protmode
== IEEE80211_PROT_RTSCTS
)
3225 ofdm_prot
|= RT2860_REG_PROT_CTRL_RTS_CTS
;
3226 else if (ic
->ic_protmode
== IEEE80211_PROT_CTSONLY
)
3227 ofdm_prot
|= RT2860_REG_PROT_CTRL_CTS
;
3229 ofdm_prot
|= RT2860_REG_PROT_CTRL_NONE
;
3233 RT2860_DPRINTF(sc
, RT2860_DEBUG_PROT
,
3234 "%s: updating protection mode: b/g protection mode=%s\n",
3235 device_get_nameunit(sc
->dev
), "none");
3237 ofdm_prot
|= RT2860_REG_PROT_CTRL_NONE
;
3240 rt2860_io_mac_write(sc
, RT2860_REG_TX_OFDM_PROT_CFG
, ofdm_prot
);
3242 /* HT frame protection */
3244 if ((vap
->iv_opmode
== IEEE80211_M_STA
) && (vap
->iv_state
== IEEE80211_S_RUN
))
3245 htopmode
= vap
->iv_bss
->ni_htopmode
;
3247 htopmode
= ic
->ic_curhtprotmode
;
3249 htprotmode
= ic
->ic_htprotmode
;
3251 /* force HT mixed mode and RTS/CTS protection if A-MPDU Tx aggregation is enabled */
3253 if (sc
->tx_ampdu_sessions
> 0)
3255 RT2860_DPRINTF(sc
, RT2860_DEBUG_PROT
,
3256 "%s: updating protection mode: forcing HT mixed mode and RTS/CTS protection\n",
3257 device_get_nameunit(sc
->dev
));
3259 htopmode
= IEEE80211_HTINFO_OPMODE_MIXED
;
3260 htprotmode
= IEEE80211_PROT_RTSCTS
;
3263 RT2860_DPRINTF(sc
, RT2860_DEBUG_PROT
,
3264 "%s: updating protection mode: HT operation mode=0x%02x, protection mode=%s\n",
3265 device_get_nameunit(sc
->dev
),
3266 htopmode
& IEEE80211_HTINFO_OPMODE
,
3267 (htprotmode
== IEEE80211_PROT_RTSCTS
) ? "RTS/CTS" :
3268 ((htprotmode
== IEEE80211_PROT_CTSONLY
) ? "CTS-to-self" : "none"));
3270 switch (htopmode
& IEEE80211_HTINFO_OPMODE
)
3272 /* IEEE80211_HTINFO_OPMODE_HT20PR */
3273 case IEEE80211_HTINFO_OPMODE_HT20PR
:
3274 mm20_prot
= RT2860_REG_PROT_NAV_SHORT
| RT2860_REG_PROT_CTRL_NONE
|
3275 RT2860_REG_TXOP_ALLOW_CCK
| RT2860_REG_TXOP_ALLOW_OFDM
|
3276 RT2860_REG_TXOP_ALLOW_MM20
| RT2860_REG_TXOP_ALLOW_GF20
|
3277 (RT2860_REG_PROT_PHYMODE_OFDM
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3278 (4 << RT2860_REG_PROT_MCS_SHIFT
);
3280 gf20_prot
= mm20_prot
;
3282 mm40_prot
= RT2860_REG_PROT_NAV_SHORT
| RT2860_REG_TXOP_ALLOW_ALL
|
3283 (RT2860_REG_PROT_PHYMODE_OFDM
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3284 (0x84 << RT2860_REG_PROT_MCS_SHIFT
);
3286 if (htprotmode
== IEEE80211_PROT_RTSCTS
)
3287 mm40_prot
|= RT2860_REG_PROT_CTRL_RTS_CTS
;
3288 else if (htprotmode
== IEEE80211_PROT_CTSONLY
)
3289 mm40_prot
|= RT2860_REG_PROT_CTRL_CTS
;
3291 mm40_prot
|= RT2860_REG_PROT_CTRL_NONE
;
3293 gf40_prot
= mm40_prot
;
3296 /* IEEE80211_HTINFO_OPMODE_MIXED */
3297 case IEEE80211_HTINFO_OPMODE_MIXED
:
3298 mm20_prot
= RT2860_REG_PROT_NAV_SHORT
|
3299 RT2860_REG_TXOP_ALLOW_CCK
| RT2860_REG_TXOP_ALLOW_OFDM
|
3300 RT2860_REG_TXOP_ALLOW_MM20
| RT2860_REG_TXOP_ALLOW_GF20
;
3302 if (ic
->ic_flags
& IEEE80211_F_USEPROT
)
3303 mm20_prot
|= (RT2860_REG_PROT_PHYMODE_CCK
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3304 (3 << RT2860_REG_PROT_MCS_SHIFT
);
3306 mm20_prot
|= (RT2860_REG_PROT_PHYMODE_OFDM
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3307 (4 << RT2860_REG_PROT_MCS_SHIFT
);
3309 if (htprotmode
== IEEE80211_PROT_RTSCTS
)
3310 mm20_prot
|= RT2860_REG_PROT_CTRL_RTS_CTS
;
3311 else if (htprotmode
== IEEE80211_PROT_CTSONLY
)
3312 mm20_prot
|= RT2860_REG_PROT_CTRL_CTS
;
3314 mm20_prot
|= RT2860_REG_PROT_CTRL_NONE
;
3316 gf20_prot
= mm20_prot
;
3318 mm40_prot
= RT2860_REG_PROT_NAV_SHORT
| RT2860_REG_TXOP_ALLOW_ALL
;
3320 if (ic
->ic_flags
& IEEE80211_F_USEPROT
)
3321 mm40_prot
|= (RT2860_REG_PROT_PHYMODE_CCK
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3322 (3 << RT2860_REG_PROT_MCS_SHIFT
);
3324 mm40_prot
|= (RT2860_REG_PROT_PHYMODE_OFDM
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3325 (0x84 << RT2860_REG_PROT_MCS_SHIFT
);
3327 if (htprotmode
== IEEE80211_PROT_RTSCTS
)
3328 mm40_prot
|= RT2860_REG_PROT_CTRL_RTS_CTS
;
3329 else if (htprotmode
== IEEE80211_PROT_CTSONLY
)
3330 mm40_prot
|= RT2860_REG_PROT_CTRL_CTS
;
3332 mm40_prot
|= RT2860_REG_PROT_CTRL_NONE
;
3334 gf40_prot
= mm40_prot
;
3338 * IEEE80211_HTINFO_OPMODE_PURE
3339 * IEEE80211_HTINFO_OPMODE_PROTOPT
3341 case IEEE80211_HTINFO_OPMODE_PURE
:
3342 case IEEE80211_HTINFO_OPMODE_PROTOPT
:
3344 mm20_prot
= RT2860_REG_PROT_NAV_SHORT
| RT2860_REG_PROT_CTRL_NONE
|
3345 RT2860_REG_TXOP_ALLOW_CCK
| RT2860_REG_TXOP_ALLOW_OFDM
|
3346 RT2860_REG_TXOP_ALLOW_MM20
| RT2860_REG_TXOP_ALLOW_GF20
|
3347 (RT2860_REG_PROT_PHYMODE_OFDM
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3348 (4 << RT2860_REG_PROT_MCS_SHIFT
);
3350 gf20_prot
= mm20_prot
;
3352 mm40_prot
= RT2860_REG_PROT_NAV_SHORT
| RT2860_REG_PROT_CTRL_NONE
|
3353 RT2860_REG_TXOP_ALLOW_ALL
|
3354 (RT2860_REG_PROT_PHYMODE_OFDM
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3355 (0x84 << RT2860_REG_PROT_MCS_SHIFT
);
3357 gf40_prot
= mm40_prot
;
3361 rt2860_io_mac_write(sc
, RT2860_REG_TX_MM20_PROT_CFG
, mm20_prot
);
3362 rt2860_io_mac_write(sc
, RT2860_REG_TX_MM40_PROT_CFG
, mm40_prot
);
3363 rt2860_io_mac_write(sc
, RT2860_REG_TX_GF20_PROT_CFG
, gf20_prot
);
3364 rt2860_io_mac_write(sc
, RT2860_REG_TX_GF40_PROT_CFG
, gf40_prot
);
3368 * rt2860_asic_updateslot
3370 static void rt2860_asic_updateslot(struct rt2860_softc
*sc
)
3373 struct ieee80211com
*ic
;
3374 struct ieee80211vap
*vap
;
3379 vap
= TAILQ_FIRST(&ic
->ic_vaps
);
3381 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATE
,
3382 "%s: %s short slot time\n",
3383 device_get_nameunit(sc
->dev
),
3384 ((ic
->ic_flags
& IEEE80211_F_SHSLOT
) ||
3385 ((vap
!= NULL
) && (vap
->iv_flags
& IEEE80211_F_BURST
))) ? "enabling" : "disabling");
3387 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_BKOFF_SLOT_CFG
);
3391 if ((ic
->ic_flags
& IEEE80211_F_SHSLOT
) ||
3392 ((vap
!= NULL
) && (vap
->iv_flags
& IEEE80211_F_BURST
)))
3393 tmp
|= IEEE80211_DUR_SHSLOT
;
3395 tmp
|= IEEE80211_DUR_SLOT
;
3397 rt2860_io_mac_write(sc
, RT2860_REG_BKOFF_SLOT_CFG
, tmp
);
3401 * rt2860_asic_wme_update
3403 static void rt2860_asic_wme_update(struct rt2860_softc
*sc
)
3406 struct ieee80211com
*ic
;
3407 struct ieee80211_wme_state
*wme
;
3408 const struct wmeParams
*wmep
;
3414 wmep
= wme
->wme_chanParams
.cap_wmeParams
;
3416 RT2860_DPRINTF(sc
, RT2860_DEBUG_WME
,
3417 "%s: wme update: WME_AC_VO=%d/%d/%d/%d, WME_AC_VI=%d/%d/%d/%d, "
3418 "WME_AC_BK=%d/%d/%d/%d, WME_AC_BE=%d/%d/%d/%d\n",
3419 device_get_nameunit(sc
->dev
),
3420 wmep
[WME_AC_VO
].wmep_aifsn
,
3421 wmep
[WME_AC_VO
].wmep_logcwmin
, wmep
[WME_AC_VO
].wmep_logcwmax
,
3422 wmep
[WME_AC_VO
].wmep_txopLimit
,
3423 wmep
[WME_AC_VI
].wmep_aifsn
,
3424 wmep
[WME_AC_VI
].wmep_logcwmin
, wmep
[WME_AC_VI
].wmep_logcwmax
,
3425 wmep
[WME_AC_VI
].wmep_txopLimit
,
3426 wmep
[WME_AC_BK
].wmep_aifsn
,
3427 wmep
[WME_AC_BK
].wmep_logcwmin
, wmep
[WME_AC_BK
].wmep_logcwmax
,
3428 wmep
[WME_AC_BK
].wmep_txopLimit
,
3429 wmep
[WME_AC_BE
].wmep_aifsn
,
3430 wmep
[WME_AC_BE
].wmep_logcwmin
, wmep
[WME_AC_BE
].wmep_logcwmax
,
3431 wmep
[WME_AC_BE
].wmep_txopLimit
);
3433 for (i
= 0; i
< WME_NUM_AC
; i
++)
3434 rt2860_io_mac_write(sc
, RT2860_REG_TX_EDCA_AC_CFG(i
),
3435 (wmep
[i
].wmep_logcwmax
<< 16) | (wmep
[i
].wmep_logcwmin
<< 12) |
3436 (wmep
[i
].wmep_aifsn
<< 8) | wmep
[i
].wmep_txopLimit
);
3438 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WMM_AIFSN_CFG
,
3439 (wmep
[WME_AC_VO
].wmep_aifsn
<< 12) | (wmep
[WME_AC_VI
].wmep_aifsn
<< 8) |
3440 (wmep
[WME_AC_BK
].wmep_aifsn
<< 4) | wmep
[WME_AC_BE
].wmep_aifsn
);
3442 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WMM_CWMIN_CFG
,
3443 (wmep
[WME_AC_VO
].wmep_logcwmin
<< 12) | (wmep
[WME_AC_VI
].wmep_logcwmin
<< 8) |
3444 (wmep
[WME_AC_BK
].wmep_logcwmin
<< 4) | wmep
[WME_AC_BE
].wmep_logcwmin
);
3446 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WMM_CWMAX_CFG
,
3447 (wmep
[WME_AC_VO
].wmep_logcwmax
<< 12) | (wmep
[WME_AC_VI
].wmep_logcwmax
<< 8) |
3448 (wmep
[WME_AC_BK
].wmep_logcwmax
<< 4) | wmep
[WME_AC_BE
].wmep_logcwmax
);
3450 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WMM_TXOP0_CFG
,
3451 (wmep
[WME_AC_BK
].wmep_txopLimit
<< 16) | wmep
[WME_AC_BE
].wmep_txopLimit
);
3453 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WMM_TXOP1_CFG
,
3454 (wmep
[WME_AC_VO
].wmep_txopLimit
<< 16) | wmep
[WME_AC_VI
].wmep_txopLimit
);
3458 * rt2860_asic_update_beacon
3460 static int rt2860_asic_update_beacon(struct rt2860_softc
*sc
,
3461 struct ieee80211vap
*vap
)
3464 struct ieee80211com
*ic
;
3465 struct rt2860_softc_vap
*rvap
;
3466 const struct ieee80211_txparam
*tp
;
3468 struct rt2860_txwi txwi
;
3474 rvap
= (struct rt2860_softc_vap
*) vap
;
3475 tp
= &vap
->iv_txparms
[ieee80211_chan2mode(ic
->ic_bsschan
)];
3477 m
= ieee80211_beacon_alloc(vap
->iv_bss
, &rvap
->beacon_offsets
);
3481 rate
= tp
->mgmtrate
;
3482 mcs
= rt2860_rate2mcs(rate
);
3484 memset(&txwi
, 0, sizeof(struct rt2860_txwi
));
3487 txwi
.pid_mpdu_len
= ((htole16(m
->m_pkthdr
.len
) & RT2860_TXWI_MPDU_LEN_MASK
) <<
3488 RT2860_TXWI_MPDU_LEN_SHIFT
);
3489 txwi
.txop
= (RT2860_TXWI_TXOP_HT
<< RT2860_TXWI_TXOP_SHIFT
);
3490 txwi
.mpdu_density_flags
|=
3491 (RT2860_TXWI_FLAGS_TS
<< RT2860_TXWI_FLAGS_SHIFT
);
3492 txwi
.bawin_size_xflags
|=
3493 (RT2860_TXWI_XFLAGS_NSEQ
<< RT2860_TXWI_XFLAGS_SHIFT
);
3495 if (ieee80211_rate2phytype(ic
->ic_rt
, rate
) != IEEE80211_T_OFDM
)
3497 txwi
.phymode_ifs_stbc_shortgi
=
3498 (RT2860_TXWI_PHYMODE_CCK
<< RT2860_TXWI_PHYMODE_SHIFT
);
3500 if (rate
!= 2 && (ic
->ic_flags
& IEEE80211_F_SHPREAMBLE
))
3501 mcs
|= RT2860_TXWI_MCS_SHOTPRE
;
3505 txwi
.phymode_ifs_stbc_shortgi
=
3506 (RT2860_TXWI_PHYMODE_OFDM
<< RT2860_TXWI_PHYMODE_SHIFT
);
3509 txwi
.bw_mcs
= (RT2860_TXWI_BW_20
<< RT2860_TXWI_BW_SHIFT
) |
3510 ((mcs
& RT2860_TXWI_MCS_MASK
) << RT2860_TXWI_MCS_SHIFT
);
3512 /* disable temporarily TSF sync */
3514 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_BCN_TIME_CFG
);
3516 tmp
&= ~(RT2860_REG_BCN_TX_ENABLE
|
3517 RT2860_REG_TSF_TIMER_ENABLE
|
3518 RT2860_REG_TBTT_TIMER_ENABLE
);
3520 rt2860_io_mac_write(sc
, RT2860_REG_BCN_TIME_CFG
, tmp
);
3522 /* write Tx wireless info and beacon frame to on-chip memory */
3524 rt2860_io_mac_write_multi(sc
, RT2860_REG_BEACON_BASE(0),
3525 &txwi
, sizeof(struct rt2860_txwi
));
3527 rt2860_io_mac_write_multi(sc
, RT2860_REG_BEACON_BASE(0) + sizeof(struct rt2860_txwi
),
3528 mtod(m
, uint8_t *), m
->m_pkthdr
.len
);
3530 /* enable again TSF sync */
3532 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_BCN_TIME_CFG
);
3534 tmp
|= (RT2860_REG_BCN_TX_ENABLE
|
3535 RT2860_REG_TSF_TIMER_ENABLE
|
3536 RT2860_REG_TBTT_TIMER_ENABLE
);
3538 rt2860_io_mac_write(sc
, RT2860_REG_BCN_TIME_CFG
, tmp
);
3546 * rt2860_asic_clear_keytables
3548 static void rt2860_asic_clear_keytables(struct rt2860_softc
*sc
)
3552 /* clear Rx WCID search table (entries = 256, entry size = 8) */
3554 for (i
= 0; i
< 256; i
++)
3556 rt2860_io_mac_write(sc
, RT2860_REG_WCID(i
), 0xffffffff);
3557 rt2860_io_mac_write(sc
, RT2860_REG_WCID(i
) + 4, 0x0000ffff);
3560 /* clear WCID attribute table (entries = 256, entry size = 4) */
3562 rt2860_io_mac_set_region_4(sc
, RT2860_REG_WCID_ATTR(0), 0, 256);
3564 /* clear IV/EIV table (entries = 256, entry size = 8) */
3566 rt2860_io_mac_set_region_4(sc
, RT2860_REG_IVEIV(0), 0, 2 * 256);
3568 /* clear pairwise key table (entries = 256, entry size = 32) */
3570 rt2860_io_mac_set_region_4(sc
, RT2860_REG_PKEY(0), 0, 8 * 256);
3572 /* clear shared key table (entries = 32, entry size = 32) */
3574 rt2860_io_mac_set_region_4(sc
, RT2860_REG_SKEY(0, 0), 0, 8 * 32);
3576 /* clear shared key mode (entries = 32, entry size = 2) */
3578 rt2860_io_mac_set_region_4(sc
, RT2860_REG_SKEY_MODE(0), 0, 16);
3584 static uint8_t rt2860_rxrate(struct rt2860_rxwi
*rxwi
)
3586 uint8_t mcs
, phymode
;
3589 mcs
= (rxwi
->bw_mcs
>> RT2860_RXWI_MCS_SHIFT
) & RT2860_RXWI_MCS_MASK
;
3590 phymode
= (rxwi
->phymode_stbc_shortgi
>> RT2860_RXWI_PHYMODE_SHIFT
) &
3591 RT2860_RXWI_PHYMODE_MASK
;
3597 case RT2860_RXWI_PHYMODE_CCK
:
3598 switch (mcs
& ~RT2860_RXWI_MCS_SHOTPRE
)
3600 case 0: rate
= 2; break; /* 1 Mbps */
3601 case 1: rate
= 4; break; /* 2 MBps */
3602 case 2: rate
= 11; break; /* 5.5 Mbps */
3603 case 3: rate
= 22; break; /* 11 Mbps */
3607 case RT2860_RXWI_PHYMODE_OFDM
:
3610 case 0: rate
= 12; break; /* 6 Mbps */
3611 case 1: rate
= 18; break; /* 9 Mbps */
3612 case 2: rate
= 24; break; /* 12 Mbps */
3613 case 3: rate
= 36; break; /* 18 Mbps */
3614 case 4: rate
= 48; break; /* 24 Mbps */
3615 case 5: rate
= 72; break; /* 36 Mbps */
3616 case 6: rate
= 96; break; /* 48 Mbps */
3617 case 7: rate
= 108; break; /* 54 Mbps */
3621 case RT2860_RXWI_PHYMODE_HT_MIXED
:
3622 case RT2860_RXWI_PHYMODE_HT_GF
:
3630 * rt2860_maxrssi_rxpath
3632 static uint8_t rt2860_maxrssi_rxpath(struct rt2860_softc
*sc
,
3633 const struct rt2860_rxwi
*rxwi
)
3639 if (sc
->nrxpath
> 1)
3640 if (rxwi
->rssi
[1] > rxwi
->rssi
[rxpath
])
3643 if (sc
->nrxpath
> 2)
3644 if (rxwi
->rssi
[2] > rxwi
->rssi
[rxpath
])
3653 static int8_t rt2860_rssi2dbm(struct rt2860_softc
*sc
,
3654 uint8_t rssi
, uint8_t rxpath
)
3657 struct ieee80211com
*ic
;
3658 struct ieee80211_channel
*c
;
3660 int8_t rssi_off
, lna_gain
;
3668 chan
= ieee80211_chan2ieee(ic
, c
);
3670 if (IEEE80211_IS_CHAN_5GHZ(c
))
3672 rssi_off
= sc
->rssi_off_5ghz
[rxpath
];
3675 lna_gain
= sc
->lna_gain
[1];
3676 else if (chan
<= 128)
3677 lna_gain
= sc
->lna_gain
[2];
3679 lna_gain
= sc
->lna_gain
[3];
3683 rssi_off
= sc
->rssi_off_2ghz
[rxpath
] - sc
->lna_gain
[0];
3684 lna_gain
= sc
->lna_gain
[0];
3687 return (-12 - rssi_off
- lna_gain
- rssi
);
3693 static uint8_t rt2860_rate2mcs(uint8_t rate
)
3720 static int rt2860_tx_mgmt(struct rt2860_softc
*sc
,
3721 struct mbuf
*m
, struct ieee80211_node
*ni
, int qid
)
3724 struct ieee80211com
*ic
;
3725 struct ieee80211vap
*vap
;
3726 const struct ieee80211_txparam
*tp
;
3727 struct rt2860_softc_node
*rni
;
3728 struct rt2860_softc_tx_ring
*ring
;
3729 struct rt2860_softc_tx_data
*data
;
3730 struct rt2860_txdesc
*desc
;
3731 struct rt2860_txwi
*txwi
;
3732 struct ieee80211_frame
*wh
;
3733 struct rt2860_softc_tx_radiotap_header
*tap
;
3734 bus_dma_segment_t dma_seg
[RT2860_SOFTC_MAX_SCATTER
];
3735 u_int hdrsize
, hdrspace
;
3736 uint8_t rate
, stbc
, shortgi
, mcs
, pid
, qsel
;
3737 uint16_t len
, dmalen
, mpdu_len
, dur
;
3738 int error
, ndmasegs
, ndescs
, i
, j
;
3740 KASSERT(qid
>= 0 && qid
< RT2860_SOFTC_TX_RING_COUNT
,
3741 ("%s: Tx MGMT: invalid qid=%d\n",
3742 device_get_nameunit(sc
->dev
), qid
));
3747 rni
= (struct rt2860_softc_node
*) ni
;
3748 tp
= ni
->ni_txparms
;
3750 ring
= &sc
->tx_ring
[qid
];
3751 desc
= &ring
->desc
[ring
->desc_cur
];
3752 data
= &ring
->data
[ring
->data_cur
];
3753 txwi
= (struct rt2860_txwi
*) (ring
->seg0
+ ring
->data_cur
* RT2860_TX_DATA_SEG0_SIZE
);
3755 wh
= mtod(m
, struct ieee80211_frame
*);
3757 rate
= tp
->mgmtrate
& IEEE80211_RATE_VAL
;
3759 /* fill Tx wireless info */
3761 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
3764 mcs
= rt2860_rate2mcs(rate
);
3768 /* calculate MPDU length without padding */
3770 hdrsize
= ieee80211_hdrsize(wh
);
3771 hdrspace
= ieee80211_hdrspace(ic
, wh
);
3772 mpdu_len
= m
->m_pkthdr
.len
- hdrspace
+ hdrsize
;
3774 memset(txwi
, 0, sizeof(struct rt2860_txwi
));
3776 /* management frames do not need encryption */
3780 txwi
->pid_mpdu_len
= ((htole16(pid
) & RT2860_TXWI_PID_MASK
) <<
3781 RT2860_TXWI_PID_SHIFT
) | ((htole16(mpdu_len
) & RT2860_TXWI_MPDU_LEN_MASK
) <<
3782 RT2860_TXWI_MPDU_LEN_SHIFT
);
3784 stbc
= (ic
->ic_htcaps
& IEEE80211_HTCAP_TXSTBC
) &&
3785 (ni
->ni_flags
& IEEE80211_NODE_HT
) && (ni
->ni_htcap
& IEEE80211_HTCAP_RXSTBC
);
3787 shortgi
= (vap
->iv_flags_ht
& (IEEE80211_FHT_SHORTGI20
| IEEE80211_FHT_SHORTGI40
)) &&
3788 (ni
->ni_flags
& IEEE80211_NODE_HT
) && (ni
->ni_flags
& (IEEE80211_NODE_SGI20
| IEEE80211_NODE_SGI40
));
3790 txwi
->phymode_ifs_stbc_shortgi
|=
3791 ((stbc
& RT2860_TXWI_STBC_MASK
) << RT2860_TXWI_STBC_SHIFT
) |
3792 ((shortgi
& RT2860_TXWI_SHORTGI_MASK
) << RT2860_TXWI_SHORTGI_SHIFT
);
3794 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
3796 txwi
->phymode_ifs_stbc_shortgi
|=
3797 (RT2860_TXWI_PHYMODE_HT_MIXED
<< RT2860_TXWI_PHYMODE_SHIFT
);
3801 if (ieee80211_rate2phytype(ic
->ic_rt
, rate
) != IEEE80211_T_OFDM
)
3803 txwi
->phymode_ifs_stbc_shortgi
|=
3804 (RT2860_TXWI_PHYMODE_CCK
<< RT2860_TXWI_PHYMODE_SHIFT
);
3806 if (rate
!= 2 && (ic
->ic_flags
& IEEE80211_F_SHPREAMBLE
))
3807 mcs
|= RT2860_TXWI_MCS_SHOTPRE
;
3811 txwi
->phymode_ifs_stbc_shortgi
|=
3812 (RT2860_TXWI_PHYMODE_OFDM
<< RT2860_TXWI_PHYMODE_SHIFT
);
3816 txwi
->bw_mcs
= (RT2860_TXWI_BW_20
<< RT2860_TXWI_BW_SHIFT
) |
3817 ((mcs
& RT2860_TXWI_MCS_MASK
) << RT2860_TXWI_MCS_SHIFT
);
3819 txwi
->txop
= (RT2860_TXWI_TXOP_BACKOFF
<< RT2860_TXWI_TXOP_SHIFT
);
3821 /* skip ACKs for multicast frames */
3823 if (!IEEE80211_IS_MULTICAST(wh
->i_addr1
))
3825 txwi
->bawin_size_xflags
|=
3826 (RT2860_TXWI_XFLAGS_ACK
<< RT2860_TXWI_XFLAGS_SHIFT
);
3828 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
3830 /* preamble + plcp + signal extension + SIFS */
3832 dur
= 16 + 4 + 6 + 10;
3836 dur
= ieee80211_ack_duration(ic
->ic_rt
, rate
,
3837 ic
->ic_flags
& IEEE80211_F_SHPREAMBLE
);
3840 *(uint16_t *) wh
->i_dur
= htole16(dur
);
3843 /* ask MAC to insert timestamp into probe responses */
3845 if ((wh
->i_fc
[0] & (IEEE80211_FC0_TYPE_MASK
| IEEE80211_FC0_SUBTYPE_MASK
)) ==
3846 (IEEE80211_FC0_TYPE_MGT
| IEEE80211_FC0_SUBTYPE_PROBE_RESP
))
3847 txwi
->mpdu_density_flags
|=
3848 (RT2860_TXWI_FLAGS_TS
<< RT2860_TXWI_FLAGS_SHIFT
);
3850 if (ieee80211_radiotap_active_vap(vap
))
3854 tap
->flags
= IEEE80211_RADIOTAP_F_DATAPAD
;
3855 tap
->chan_flags
= htole32(ic
->ic_curchan
->ic_flags
);
3856 tap
->chan_freq
= htole16(ic
->ic_curchan
->ic_freq
);
3857 tap
->chan_ieee
= ic
->ic_curchan
->ic_ieee
;
3858 tap
->chan_maxpow
= 0;
3860 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
3861 tap
->rate
= mcs
| IEEE80211_RATE_MCS
;
3865 if (mcs
& RT2860_TXWI_MCS_SHOTPRE
)
3866 tap
->flags
|= IEEE80211_RADIOTAP_F_SHORTPRE
;
3869 tap
->flags
|= IEEE80211_RADIOTAP_F_SHORTGI
;
3871 if (wh
->i_fc
[1] & IEEE80211_FC1_WEP
)
3872 tap
->flags
|= IEEE80211_RADIOTAP_F_WEP
;
3874 if (wh
->i_fc
[1] & IEEE80211_FC1_WEP
)
3876 wh
->i_fc
[1] &= ~IEEE80211_FC1_WEP
;
3878 ieee80211_radiotap_tx(vap
, m
);
3880 wh
->i_fc
[1] |= IEEE80211_FC1_WEP
;
3884 ieee80211_radiotap_tx(vap
, m
);
3888 /* copy and trim 802.11 header */
3890 m_copydata(m
, 0, hdrsize
, (caddr_t
) (txwi
+ 1));
3893 error
= bus_dmamap_load_mbuf_sg(ring
->data_dma_tag
, data
->dma_map
, m
,
3894 dma_seg
, &ndmasegs
, 0);
3897 /* too many fragments, linearize */
3899 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
3900 "%s: could not load mbuf DMA map, trying to linearize mbuf: ndmasegs=%d, len=%d, error=%d\n",
3901 device_get_nameunit(sc
->dev
), ndmasegs
, m
->m_pkthdr
.len
, error
);
3903 m
= m_defrag(m
, M_DONTWAIT
);
3907 sc
->tx_defrag_packets
++;
3909 error
= bus_dmamap_load_mbuf_sg(ring
->data_dma_tag
, data
->dma_map
, m
,
3910 dma_seg
, &ndmasegs
, 0);
3913 printf("%s: could not load mbuf DMA map: ndmasegs=%d, len=%d, error=%d\n",
3914 device_get_nameunit(sc
->dev
), ndmasegs
, m
->m_pkthdr
.len
, error
);
3920 if (m
->m_pkthdr
.len
== 0)
3923 /* determine how many Tx descs are required */
3925 ndescs
= 1 + ndmasegs
/ 2;
3926 if ((ring
->desc_queued
+ ndescs
) > (RT2860_SOFTC_TX_RING_DESC_COUNT
- 2))
3928 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
3929 "%s: there are not enough Tx descs\n",
3930 device_get_nameunit(sc
->dev
));
3932 sc
->no_tx_desc_avail
++;
3934 bus_dmamap_unload(ring
->data_dma_tag
, data
->dma_map
);
3942 /* set up Tx descs */
3944 /* first segment is Tx wireless info and 802.11 header */
3946 len
= sizeof(struct rt2860_txwi
) + hdrsize
;
3948 /* align end on a 4-bytes boundary */
3950 dmalen
= (len
+ 3) & ~ 3;
3952 memset((caddr_t
) txwi
+ len
, 0, dmalen
- len
);
3954 qsel
= RT2860_TXDESC_QSEL_EDCA
;
3956 desc
->sdp0
= htole32(ring
->seg0_phys_addr
+ ring
->data_cur
* RT2860_TX_DATA_SEG0_SIZE
);
3957 desc
->sdl0
= htole16(dmalen
);
3958 desc
->qsel_flags
= (qsel
<< RT2860_TXDESC_QSEL_SHIFT
);
3960 /* set up payload segments */
3962 for (i
= ndmasegs
, j
= 0; i
>= 2; i
-= 2)
3964 desc
->sdp1
= htole32(dma_seg
[j
].ds_addr
);
3965 desc
->sdl1
= htole16(dma_seg
[j
].ds_len
);
3967 ring
->desc_queued
++;
3968 ring
->desc_cur
= (ring
->desc_cur
+ 1) % RT2860_SOFTC_TX_RING_DESC_COUNT
;
3972 desc
= &ring
->desc
[ring
->desc_cur
];
3974 desc
->sdp0
= htole32(dma_seg
[j
].ds_addr
);
3975 desc
->sdl0
= htole16(dma_seg
[j
].ds_len
);
3976 desc
->qsel_flags
= (qsel
<< RT2860_TXDESC_QSEL_SHIFT
);
3981 /* finalize last payload segment */
3985 desc
->sdp1
= htole32(dma_seg
[j
].ds_addr
);
3986 desc
->sdl1
= htole16(dma_seg
[j
].ds_len
| RT2860_TXDESC_SDL1_LASTSEG
);
3990 desc
->sdl0
|= htole16(RT2860_TXDESC_SDL0_LASTSEG
);
3994 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
3995 "%s: sending MGMT frame: qid=%d, hdrsize=%d, hdrspace=%d, len=%d, "
3996 "stbc=%d, shortgi=%d, mcs=%d, DMA len=%d, ndmasegs=%d, DMA ds_len=%d/%d/%d/%d/%d\n",
3997 device_get_nameunit(sc
->dev
),
3998 qid
, hdrsize
, hdrspace
, m
->m_pkthdr
.len
+ hdrsize
,
3999 stbc
, shortgi
, mcs
, dmalen
, ndmasegs
,
4000 (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
);
4002 bus_dmamap_sync(ring
->seg0_dma_tag
, ring
->seg0_dma_map
,
4003 BUS_DMASYNC_PREWRITE
);
4004 bus_dmamap_sync(ring
->data_dma_tag
, data
->dma_map
,
4005 BUS_DMASYNC_PREWRITE
);
4006 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
4007 BUS_DMASYNC_PREWRITE
);
4009 ring
->desc_queued
++;
4010 ring
->desc_cur
= (ring
->desc_cur
+ 1) % RT2860_SOFTC_TX_RING_DESC_COUNT
;
4012 ring
->data_queued
++;
4013 ring
->data_cur
= (ring
->data_cur
+ 1) % RT2860_SOFTC_TX_RING_DATA_COUNT
;
4017 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_CTX_IDX(qid
), ring
->desc_cur
);
4025 static int rt2860_tx_data(struct rt2860_softc
*sc
,
4026 struct mbuf
*m
, struct ieee80211_node
*ni
, int qid
)
4029 struct ieee80211com
*ic
;
4030 struct ieee80211vap
*vap
;
4031 const struct ieee80211_txparam
*tp
;
4032 struct rt2860_softc_node
*rni
;
4033 struct rt2860_softc_tx_ring
*ring
;
4034 struct rt2860_softc_tx_data
*data
;
4035 struct rt2860_txdesc
*desc
;
4036 struct rt2860_txwi
*txwi
;
4037 struct ieee80211_frame
*wh
;
4038 struct ieee80211_tx_ampdu
*tx_ampdu
;
4039 ieee80211_seq seqno
;
4040 struct rt2860_softc_tx_radiotap_header
*tap
;
4041 bus_dma_segment_t dma_seg
[RT2860_SOFTC_MAX_SCATTER
];
4042 u_int hdrsize
, hdrspace
;
4043 uint8_t type
, rate
, bw
, stbc
, shortgi
, mcs
, pid
, wcid
, mpdu_density
, bawin_size
, qsel
;
4044 uint16_t qos
, len
, dmalen
, mpdu_len
, dur
;
4045 int error
, hasqos
, ac
, tid
, ampdu
, ndmasegs
, ndescs
, i
, j
;
4047 KASSERT(qid
>= 0 && qid
< RT2860_SOFTC_TX_RING_COUNT
,
4048 ("%s: Tx data: invalid qid=%d\n",
4049 device_get_nameunit(sc
->dev
), qid
));
4054 rni
= (struct rt2860_softc_node
*) ni
;
4055 tp
= ni
->ni_txparms
;
4057 ring
= &sc
->tx_ring
[qid
];
4058 desc
= &ring
->desc
[ring
->desc_cur
];
4059 data
= &ring
->data
[ring
->data_cur
];
4060 txwi
= (struct rt2860_txwi
*) (ring
->seg0
+ ring
->data_cur
* RT2860_TX_DATA_SEG0_SIZE
);
4062 wh
= mtod(m
, struct ieee80211_frame
*);
4064 type
= wh
->i_fc
[0] & IEEE80211_FC0_TYPE_MASK
;
4066 hasqos
= IEEE80211_QOS_HAS_SEQ(wh
);
4069 if (IEEE80211_HAS_ADDR4(wh
))
4070 qos
= le16toh(*(const uint16_t *)
4071 (((struct ieee80211_qosframe_addr4
*) wh
)->i_qos
));
4073 qos
= le16toh(*(const uint16_t *)
4074 (((struct ieee80211_qosframe
*) wh
)->i_qos
));
4081 if (IEEE80211_IS_MULTICAST(wh
->i_addr1
))
4082 rate
= tp
->mcastrate
;
4083 else if (m
->m_flags
& M_EAPOL
)
4084 rate
= tp
->mgmtrate
;
4085 else if (tp
->ucastrate
!= IEEE80211_FIXED_RATE_NONE
)
4086 rate
= tp
->ucastrate
;
4088 rate
= ni
->ni_txrate
;
4090 rate
&= IEEE80211_RATE_VAL
;
4092 /* fill Tx wireless info */
4094 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
4097 mcs
= rt2860_rate2mcs(rate
);
4101 wcid
= (type
== IEEE80211_FC0_TYPE_DATA
) ?
4102 RT2860_AID2WCID(ni
->ni_associd
) : 0xff;
4104 /* calculate MPDU length without padding */
4106 hdrsize
= ieee80211_hdrsize(wh
);
4107 hdrspace
= ieee80211_hdrspace(ic
, wh
);
4108 mpdu_len
= m
->m_pkthdr
.len
- hdrspace
+ hdrsize
;
4110 memset(txwi
, 0, sizeof(struct rt2860_txwi
));
4114 txwi
->pid_mpdu_len
= ((htole16(pid
) & RT2860_TXWI_PID_MASK
) <<
4115 RT2860_TXWI_PID_SHIFT
) | ((htole16(mpdu_len
) & RT2860_TXWI_MPDU_LEN_MASK
) <<
4116 RT2860_TXWI_MPDU_LEN_SHIFT
);
4118 stbc
= (ic
->ic_htcaps
& IEEE80211_HTCAP_TXSTBC
) &&
4119 (ni
->ni_flags
& IEEE80211_NODE_HT
) && (ni
->ni_htcap
& IEEE80211_HTCAP_RXSTBC
);
4121 shortgi
= (vap
->iv_flags_ht
& (IEEE80211_FHT_SHORTGI20
| IEEE80211_FHT_SHORTGI40
)) &&
4122 (ni
->ni_flags
& IEEE80211_NODE_HT
) && (ni
->ni_flags
& (IEEE80211_NODE_SGI20
| IEEE80211_NODE_SGI40
));
4124 txwi
->phymode_ifs_stbc_shortgi
|=
4125 ((stbc
& RT2860_TXWI_STBC_MASK
) << RT2860_TXWI_STBC_SHIFT
) |
4126 ((shortgi
& RT2860_TXWI_SHORTGI_MASK
) << RT2860_TXWI_SHORTGI_SHIFT
);
4128 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
4130 txwi
->phymode_ifs_stbc_shortgi
|=
4131 (RT2860_TXWI_PHYMODE_HT_MIXED
<< RT2860_TXWI_PHYMODE_SHIFT
);
4135 if (ieee80211_rate2phytype(ic
->ic_rt
, rate
) != IEEE80211_T_OFDM
)
4137 txwi
->phymode_ifs_stbc_shortgi
|=
4138 (RT2860_TXWI_PHYMODE_CCK
<< RT2860_TXWI_PHYMODE_SHIFT
);
4140 if (rate
!= 2 && (ic
->ic_flags
& IEEE80211_F_SHPREAMBLE
))
4141 mcs
|= RT2860_TXWI_MCS_SHOTPRE
;
4145 txwi
->phymode_ifs_stbc_shortgi
|=
4146 (RT2860_TXWI_PHYMODE_OFDM
<< RT2860_TXWI_PHYMODE_SHIFT
);
4150 if ((ni
->ni_flags
& IEEE80211_NODE_HT
) && (ni
->ni_chw
== 40))
4151 bw
= RT2860_TXWI_BW_40
;
4153 bw
= RT2860_TXWI_BW_20
;
4155 txwi
->bw_mcs
= ((bw
& RT2860_TXWI_BW_MASK
) << RT2860_TXWI_BW_SHIFT
) |
4156 ((mcs
& RT2860_TXWI_MCS_MASK
) << RT2860_TXWI_MCS_SHIFT
);
4158 txwi
->txop
= (RT2860_TXWI_TXOP_HT
<< RT2860_TXWI_TXOP_SHIFT
);
4160 if (!IEEE80211_IS_MULTICAST(wh
->i_addr1
) &&
4161 (!hasqos
|| (qos
& IEEE80211_QOS_ACKPOLICY
) != IEEE80211_QOS_ACKPOLICY_NOACK
))
4163 txwi
->bawin_size_xflags
|=
4164 (RT2860_TXWI_XFLAGS_ACK
<< RT2860_TXWI_XFLAGS_SHIFT
);
4166 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
4168 /* preamble + plcp + signal extension + SIFS */
4170 dur
= 16 + 4 + 6 + 10;
4174 dur
= ieee80211_ack_duration(ic
->ic_rt
, rate
,
4175 ic
->ic_flags
& IEEE80211_F_SHPREAMBLE
);
4178 *(uint16_t *) wh
->i_dur
= htole16(dur
);
4181 /* check for A-MPDU */
4183 if (m
->m_flags
& M_AMPDU_MPDU
)
4185 ac
= M_WME_GETAC(m
);
4186 tid
= WME_AC_TO_TID(ac
);
4187 tx_ampdu
= &ni
->ni_tx_ampdu
[ac
];
4189 mpdu_density
= RT2860_MS(ni
->ni_htparam
, IEEE80211_HTCAP_MPDUDENSITY
);
4190 bawin_size
= tx_ampdu
->txa_wnd
;
4192 txwi
->mpdu_density_flags
|=
4193 ((mpdu_density
& RT2860_TXWI_MPDU_DENSITY_MASK
) << RT2860_TXWI_MPDU_DENSITY_SHIFT
) |
4194 (RT2860_TXWI_FLAGS_AMPDU
<< RT2860_TXWI_FLAGS_SHIFT
);
4196 txwi
->bawin_size_xflags
|=
4197 ((bawin_size
& RT2860_TXWI_BAWIN_SIZE_MASK
) << RT2860_TXWI_BAWIN_SIZE_SHIFT
);
4199 seqno
= ni
->ni_txseqs
[tid
]++;
4201 *(uint16_t *) &wh
->i_seq
[0] = htole16(seqno
<< IEEE80211_SEQ_SEQ_SHIFT
);
4210 /* ask MAC to insert timestamp into probe responses */
4212 if ((wh
->i_fc
[0] & (IEEE80211_FC0_TYPE_MASK
| IEEE80211_FC0_SUBTYPE_MASK
)) ==
4213 (IEEE80211_FC0_TYPE_MGT
| IEEE80211_FC0_SUBTYPE_PROBE_RESP
))
4214 txwi
->mpdu_density_flags
|=
4215 (RT2860_TXWI_FLAGS_TS
<< RT2860_TXWI_FLAGS_SHIFT
);
4217 if (ieee80211_radiotap_active_vap(vap
))
4221 tap
->flags
= IEEE80211_RADIOTAP_F_DATAPAD
;
4222 tap
->chan_flags
= htole32(ic
->ic_curchan
->ic_flags
);
4223 tap
->chan_freq
= htole16(ic
->ic_curchan
->ic_freq
);
4224 tap
->chan_ieee
= ic
->ic_curchan
->ic_ieee
;
4225 tap
->chan_maxpow
= 0;
4227 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
4228 tap
->rate
= mcs
| IEEE80211_RATE_MCS
;
4232 if (mcs
& RT2860_TXWI_MCS_SHOTPRE
)
4233 tap
->flags
|= IEEE80211_RADIOTAP_F_SHORTPRE
;
4236 tap
->flags
|= IEEE80211_RADIOTAP_F_SHORTGI
;
4238 if (wh
->i_fc
[1] & IEEE80211_FC1_WEP
)
4239 tap
->flags
|= IEEE80211_RADIOTAP_F_WEP
;
4241 if (wh
->i_fc
[1] & IEEE80211_FC1_WEP
)
4243 wh
->i_fc
[1] &= ~IEEE80211_FC1_WEP
;
4245 ieee80211_radiotap_tx(vap
, m
);
4247 wh
->i_fc
[1] |= IEEE80211_FC1_WEP
;
4251 ieee80211_radiotap_tx(vap
, m
);
4255 /* copy and trim 802.11 header */
4257 m_copydata(m
, 0, hdrsize
, (caddr_t
) (txwi
+ 1));
4260 error
= bus_dmamap_load_mbuf_sg(ring
->data_dma_tag
, data
->dma_map
, m
,
4261 dma_seg
, &ndmasegs
, 0);
4264 /* too many fragments, linearize */
4266 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
4267 "%s: could not load mbuf DMA map, trying to linearize mbuf: ndmasegs=%d, len=%d, error=%d\n",
4268 device_get_nameunit(sc
->dev
), ndmasegs
, m
->m_pkthdr
.len
, error
);
4270 m
= m_defrag(m
, M_DONTWAIT
);
4274 sc
->tx_defrag_packets
++;
4276 error
= bus_dmamap_load_mbuf_sg(ring
->data_dma_tag
, data
->dma_map
, m
,
4277 dma_seg
, &ndmasegs
, 0);
4280 printf("%s: could not load mbuf DMA map: ndmasegs=%d, len=%d, error=%d\n",
4281 device_get_nameunit(sc
->dev
), ndmasegs
, m
->m_pkthdr
.len
, error
);
4287 if (m
->m_pkthdr
.len
== 0)
4290 /* determine how many Tx descs are required */
4292 ndescs
= 1 + ndmasegs
/ 2;
4293 if ((ring
->desc_queued
+ ndescs
) > (RT2860_SOFTC_TX_RING_DESC_COUNT
- 2))
4295 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
4296 "%s: there are not enough Tx descs\n",
4297 device_get_nameunit(sc
->dev
));
4299 sc
->no_tx_desc_avail
++;
4301 bus_dmamap_unload(ring
->data_dma_tag
, data
->dma_map
);
4309 /* set up Tx descs */
4311 /* first segment is Tx wireless info and 802.11 header */
4313 len
= sizeof(struct rt2860_txwi
) + hdrsize
;
4315 /* align end on a 4-bytes boundary */
4317 dmalen
= (len
+ 3) & ~ 3;
4319 memset((caddr_t
) txwi
+ len
, 0, dmalen
- len
);
4321 qsel
= RT2860_TXDESC_QSEL_EDCA
;
4323 desc
->sdp0
= htole32(ring
->seg0_phys_addr
+ ring
->data_cur
* RT2860_TX_DATA_SEG0_SIZE
);
4324 desc
->sdl0
= htole16(dmalen
);
4325 desc
->qsel_flags
= (qsel
<< RT2860_TXDESC_QSEL_SHIFT
);
4327 /* set up payload segments */
4329 for (i
= ndmasegs
, j
= 0; i
>= 2; i
-= 2)
4331 desc
->sdp1
= htole32(dma_seg
[j
].ds_addr
);
4332 desc
->sdl1
= htole16(dma_seg
[j
].ds_len
);
4334 ring
->desc_queued
++;
4335 ring
->desc_cur
= (ring
->desc_cur
+ 1) % RT2860_SOFTC_TX_RING_DESC_COUNT
;
4339 desc
= &ring
->desc
[ring
->desc_cur
];
4341 desc
->sdp0
= htole32(dma_seg
[j
].ds_addr
);
4342 desc
->sdl0
= htole16(dma_seg
[j
].ds_len
);
4343 desc
->qsel_flags
= (qsel
<< RT2860_TXDESC_QSEL_SHIFT
);
4348 /* finalize last payload segment */
4352 desc
->sdp1
= htole32(dma_seg
[j
].ds_addr
);
4353 desc
->sdl1
= htole16(dma_seg
[j
].ds_len
| RT2860_TXDESC_SDL1_LASTSEG
);
4357 desc
->sdl0
|= htole16(RT2860_TXDESC_SDL0_LASTSEG
);
4361 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
4362 "%s: sending data: qid=%d, hdrsize=%d, hdrspace=%d, len=%d, "
4363 "bw=%d, stbc=%d, shortgi=%d, mcs=%d, wcid=0x%02x, ampdu=%d, DMA len=%d, ndmasegs=%d, DMA ds_len=%d/%d/%d/%d/%d\n",
4364 device_get_nameunit(sc
->dev
),
4365 qid
, hdrsize
, hdrspace
, m
->m_pkthdr
.len
+ hdrsize
,
4366 bw
, stbc
, shortgi
, mcs
, wcid
, ampdu
, dmalen
, ndmasegs
,
4367 (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
);
4369 bus_dmamap_sync(ring
->seg0_dma_tag
, ring
->seg0_dma_map
,
4370 BUS_DMASYNC_PREWRITE
);
4371 bus_dmamap_sync(ring
->data_dma_tag
, data
->dma_map
,
4372 BUS_DMASYNC_PREWRITE
);
4373 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
4374 BUS_DMASYNC_PREWRITE
);
4376 ring
->desc_queued
++;
4377 ring
->desc_cur
= (ring
->desc_cur
+ 1) % RT2860_SOFTC_TX_RING_DESC_COUNT
;
4379 ring
->data_queued
++;
4380 ring
->data_cur
= (ring
->data_cur
+ 1) % RT2860_SOFTC_TX_RING_DATA_COUNT
;
4384 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_CTX_IDX(qid
), ring
->desc_cur
);
4392 static int rt2860_tx_raw(struct rt2860_softc
*sc
,
4393 struct mbuf
*m
, struct ieee80211_node
*ni
,
4394 const struct ieee80211_bpf_params
*params
)
4396 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
4398 device_get_nameunit(sc
->dev
));
4406 static void rt2860_intr(void *arg
)
4408 struct rt2860_softc
*sc
;
4415 /* acknowledge interrupts */
4417 status
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_INT_STATUS
);
4418 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_INT_STATUS
, status
);
4420 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4421 "%s: interrupt: status = 0x%08x\n",
4422 device_get_nameunit(sc
->dev
), status
);
4424 if (status
== 0xffffffff || /* device likely went away */
4425 status
== 0) /* not for us */
4430 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
4433 if (status
& RT2860_REG_INT_TX_COHERENT
)
4434 rt2860_tx_coherent_intr(sc
);
4436 if (status
& RT2860_REG_INT_RX_COHERENT
)
4437 rt2860_rx_coherent_intr(sc
);
4439 if (status
& RT2860_REG_INT_TXRX_COHERENT
)
4440 rt2860_txrx_coherent_intr(sc
);
4442 if (status
& RT2860_REG_INT_FIFO_STA_FULL
)
4443 rt2860_fifo_sta_full_intr(sc
);
4445 if (status
& RT2860_REG_INT_TX_MGMT_DONE
)
4446 rt2860_tx_intr(sc
, 5);
4448 if (status
& RT2860_REG_INT_RX_DONE
)
4451 if (status
& RT2860_REG_INT_RX_DELAY_DONE
)
4452 rt2860_rx_delay_intr(sc
);
4454 if (status
& RT2860_REG_INT_TX_HCCA_DONE
)
4455 rt2860_tx_intr(sc
, 4);
4457 if (status
& RT2860_REG_INT_TX_AC3_DONE
)
4458 rt2860_tx_intr(sc
, 3);
4460 if (status
& RT2860_REG_INT_TX_AC2_DONE
)
4461 rt2860_tx_intr(sc
, 2);
4463 if (status
& RT2860_REG_INT_TX_AC1_DONE
)
4464 rt2860_tx_intr(sc
, 1);
4466 if (status
& RT2860_REG_INT_TX_AC0_DONE
)
4467 rt2860_tx_intr(sc
, 0);
4469 if (status
& RT2860_REG_INT_TX_DELAY_DONE
)
4470 rt2860_tx_delay_intr(sc
);
4472 if (status
& RT2860_REG_INT_PRE_TBTT
)
4473 rt2860_pre_tbtt_intr(sc
);
4475 if (status
& RT2860_REG_INT_TBTT
)
4476 rt2860_tbtt_intr(sc
);
4478 if (status
& RT2860_REG_INT_MCU_CMD
)
4479 rt2860_mcu_cmd_intr(sc
);
4481 if (status
& RT2860_REG_INT_AUTO_WAKEUP
)
4482 rt2860_auto_wakeup_intr(sc
);
4484 if (status
& RT2860_REG_INT_GP_TIMER
)
4485 rt2860_gp_timer_intr(sc
);
4489 * rt2860_tx_coherent_intr
4491 static void rt2860_tx_coherent_intr(struct rt2860_softc
*sc
)
4496 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4497 "%s: Tx coherent interrupt\n",
4498 device_get_nameunit(sc
->dev
));
4500 sc
->tx_coherent_interrupts
++;
4502 /* restart DMA engine */
4504 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
);
4506 tmp
&= ~(RT2860_REG_TX_WB_DDONE
|
4507 RT2860_REG_RX_DMA_ENABLE
|
4508 RT2860_REG_TX_DMA_ENABLE
);
4510 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
, tmp
);
4512 /* init Tx rings (4 EDCAs + HCCA + MGMT) */
4514 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
4515 rt2860_reset_tx_ring(sc
, &sc
->tx_ring
[i
]);
4517 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
4519 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_BASE_PTR(i
),
4520 sc
->tx_ring
[i
].desc_phys_addr
);
4521 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_MAX_CNT(i
),
4522 RT2860_SOFTC_TX_RING_DESC_COUNT
);
4523 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_CTX_IDX(i
), 0);
4528 rt2860_reset_rx_ring(sc
, &sc
->rx_ring
);
4530 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_BASE_PTR
,
4531 sc
->rx_ring
.desc_phys_addr
);
4532 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_MAX_CNT
,
4533 RT2860_SOFTC_RX_RING_DATA_COUNT
);
4534 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_CALC_IDX
,
4535 RT2860_SOFTC_RX_RING_DATA_COUNT
- 1);
4537 rt2860_txrx_enable(sc
);
4541 * rt2860_rx_coherent_intr
4543 static void rt2860_rx_coherent_intr(struct rt2860_softc
*sc
)
4548 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4549 "%s: Rx coherent interrupt\n",
4550 device_get_nameunit(sc
->dev
));
4552 sc
->rx_coherent_interrupts
++;
4554 /* restart DMA engine */
4556 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
);
4558 tmp
&= ~(RT2860_REG_TX_WB_DDONE
|
4559 RT2860_REG_RX_DMA_ENABLE
|
4560 RT2860_REG_TX_DMA_ENABLE
);
4562 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
, tmp
);
4564 /* init Tx rings (4 EDCAs + HCCA + MGMT) */
4566 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
4567 rt2860_reset_tx_ring(sc
, &sc
->tx_ring
[i
]);
4569 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
4571 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_BASE_PTR(i
),
4572 sc
->tx_ring
[i
].desc_phys_addr
);
4573 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_MAX_CNT(i
),
4574 RT2860_SOFTC_TX_RING_DESC_COUNT
);
4575 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_CTX_IDX(i
), 0);
4580 rt2860_reset_rx_ring(sc
, &sc
->rx_ring
);
4582 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_BASE_PTR
,
4583 sc
->rx_ring
.desc_phys_addr
);
4584 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_MAX_CNT
,
4585 RT2860_SOFTC_RX_RING_DATA_COUNT
);
4586 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_CALC_IDX
,
4587 RT2860_SOFTC_RX_RING_DATA_COUNT
- 1);
4589 rt2860_txrx_enable(sc
);
4593 * rt2860_txrx_coherent_intr
4595 static void rt2860_txrx_coherent_intr(struct rt2860_softc
*sc
)
4600 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4601 "%s: Tx/Rx coherent interrupt\n",
4602 device_get_nameunit(sc
->dev
));
4604 sc
->txrx_coherent_interrupts
++;
4606 /* restart DMA engine */
4608 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
);
4610 tmp
&= ~(RT2860_REG_TX_WB_DDONE
|
4611 RT2860_REG_RX_DMA_ENABLE
|
4612 RT2860_REG_TX_DMA_ENABLE
);
4614 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
, tmp
);
4616 /* init Tx rings (4 EDCAs + HCCA + MGMT) */
4618 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
4619 rt2860_reset_tx_ring(sc
, &sc
->tx_ring
[i
]);
4621 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
4623 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_BASE_PTR(i
),
4624 sc
->tx_ring
[i
].desc_phys_addr
);
4625 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_MAX_CNT(i
),
4626 RT2860_SOFTC_TX_RING_DESC_COUNT
);
4627 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_CTX_IDX(i
), 0);
4632 rt2860_reset_rx_ring(sc
, &sc
->rx_ring
);
4634 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_BASE_PTR
,
4635 sc
->rx_ring
.desc_phys_addr
);
4636 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_MAX_CNT
,
4637 RT2860_SOFTC_RX_RING_DATA_COUNT
);
4638 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_CALC_IDX
,
4639 RT2860_SOFTC_RX_RING_DATA_COUNT
- 1);
4641 rt2860_txrx_enable(sc
);
4645 * rt2860_fifo_sta_full_intr
4647 static void rt2860_fifo_sta_full_intr(struct rt2860_softc
*sc
)
4649 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4650 "%s: FIFO statistic full interrupt\n",
4651 device_get_nameunit(sc
->dev
));
4653 sc
->fifo_sta_full_interrupts
++;
4655 RT2860_SOFTC_LOCK(sc
);
4657 if (!(sc
->intr_disable_mask
& RT2860_REG_INT_FIFO_STA_FULL
))
4659 rt2860_intr_disable(sc
, RT2860_REG_INT_FIFO_STA_FULL
);
4661 taskqueue_enqueue(sc
->taskqueue
, &sc
->fifo_sta_full_task
);
4664 sc
->intr_pending_mask
|= RT2860_REG_INT_FIFO_STA_FULL
;
4666 RT2860_SOFTC_UNLOCK(sc
);
4672 static void rt2860_rx_intr(struct rt2860_softc
*sc
)
4674 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4675 "%s: Rx interrupt\n",
4676 device_get_nameunit(sc
->dev
));
4678 sc
->rx_interrupts
++;
4680 RT2860_SOFTC_LOCK(sc
);
4682 if (!(sc
->intr_disable_mask
& RT2860_REG_INT_RX_DONE
))
4684 rt2860_intr_disable(sc
, RT2860_REG_INT_RX_DONE
);
4686 taskqueue_enqueue(sc
->taskqueue
, &sc
->rx_done_task
);
4689 sc
->intr_pending_mask
|= RT2860_REG_INT_RX_DONE
;
4691 RT2860_SOFTC_UNLOCK(sc
);
4695 * rt2860_rx_delay_intr
4697 static void rt2860_rx_delay_intr(struct rt2860_softc
*sc
)
4699 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4700 "%s: Rx delay interrupt\n",
4701 device_get_nameunit(sc
->dev
));
4703 sc
->rx_delay_interrupts
++;
4709 static void rt2860_tx_intr(struct rt2860_softc
*sc
, int qid
)
4711 KASSERT(qid
>= 0 && qid
< RT2860_SOFTC_TX_RING_COUNT
,
4712 ("%s: Tx interrupt: invalid qid=%d\n",
4713 device_get_nameunit(sc
->dev
), qid
));
4715 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4716 "%s: Tx interrupt: qid=%d\n",
4717 device_get_nameunit(sc
->dev
), qid
);
4719 sc
->tx_interrupts
[qid
]++;
4721 RT2860_SOFTC_LOCK(sc
);
4723 if (!(sc
->intr_disable_mask
& (RT2860_REG_INT_TX_AC0_DONE
<< qid
)))
4725 rt2860_intr_disable(sc
, (RT2860_REG_INT_TX_AC0_DONE
<< qid
));
4727 taskqueue_enqueue(sc
->taskqueue
, &sc
->tx_done_task
);
4730 sc
->intr_pending_mask
|= (RT2860_REG_INT_TX_AC0_DONE
<< qid
);
4732 RT2860_SOFTC_UNLOCK(sc
);
4736 * rt2860_tx_delay_intr
4738 static void rt2860_tx_delay_intr(struct rt2860_softc
*sc
)
4740 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4741 "%s: Tx delay interrupt\n",
4742 device_get_nameunit(sc
->dev
));
4744 sc
->tx_delay_interrupts
++;
4748 * rt2860_pre_tbtt_intr
4750 static void rt2860_pre_tbtt_intr(struct rt2860_softc
*sc
)
4752 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4753 "%s: Pre-TBTT interrupt\n",
4754 device_get_nameunit(sc
->dev
));
4756 sc
->pre_tbtt_interrupts
++;
4762 static void rt2860_tbtt_intr(struct rt2860_softc
*sc
)
4764 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4765 "%s: TBTT interrupt\n",
4766 device_get_nameunit(sc
->dev
));
4768 sc
->tbtt_interrupts
++;
4772 * rt2860_mcu_cmd_intr
4774 static void rt2860_mcu_cmd_intr(struct rt2860_softc
*sc
)
4776 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4777 "%s: MCU command interrupt\n",
4778 device_get_nameunit(sc
->dev
));
4780 sc
->mcu_cmd_interrupts
++;
4784 * rt2860_auto_wakeup_intr
4786 static void rt2860_auto_wakeup_intr(struct rt2860_softc
*sc
)
4788 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4789 "%s: auto wakeup interrupt\n",
4790 device_get_nameunit(sc
->dev
));
4792 sc
->auto_wakeup_interrupts
++;
4796 * rt2860_gp_timer_intr
4798 static void rt2860_gp_timer_intr(struct rt2860_softc
*sc
)
4800 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4801 "%s: GP timer interrupt\n",
4802 device_get_nameunit(sc
->dev
));
4804 sc
->gp_timer_interrupts
++;
4808 * rt2860_rx_done_task
4810 static void rt2860_rx_done_task(void *context
, int pending
)
4812 struct rt2860_softc
*sc
;
4819 RT2860_DPRINTF(sc
, RT2860_DEBUG_RX
,
4820 "%s: Rx done task\n",
4821 device_get_nameunit(sc
->dev
));
4823 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
4826 sc
->intr_pending_mask
&= ~RT2860_REG_INT_RX_DONE
;
4828 again
= rt2860_rx_eof(sc
, sc
->rx_process_limit
);
4830 RT2860_SOFTC_LOCK(sc
);
4832 if ((sc
->intr_pending_mask
& RT2860_REG_INT_RX_DONE
) || again
)
4834 RT2860_DPRINTF(sc
, RT2860_DEBUG_RX
,
4835 "%s: Rx done task: scheduling again\n",
4836 device_get_nameunit(sc
->dev
));
4838 taskqueue_enqueue(sc
->taskqueue
, &sc
->rx_done_task
);
4842 rt2860_intr_enable(sc
, RT2860_REG_INT_RX_DONE
);
4845 RT2860_SOFTC_UNLOCK(sc
);
4849 * rt2860_tx_done_task
4851 static void rt2860_tx_done_task(void *context
, int pending
)
4853 struct rt2860_softc
*sc
;
4861 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
4862 "%s: Tx done task\n",
4863 device_get_nameunit(sc
->dev
));
4865 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
4868 for (i
= RT2860_SOFTC_TX_RING_COUNT
- 1; i
>= 0; i
--)
4870 if (sc
->intr_pending_mask
& (RT2860_REG_INT_TX_AC0_DONE
<< i
))
4872 sc
->intr_pending_mask
&= ~(RT2860_REG_INT_TX_AC0_DONE
<< i
);
4874 rt2860_tx_eof(sc
, &sc
->tx_ring
[i
]);
4880 ifp
->if_drv_flags
&= ~IFF_DRV_OACTIVE
;
4882 intr_mask
= (RT2860_REG_INT_TX_MGMT_DONE
|
4883 RT2860_REG_INT_TX_HCCA_DONE
|
4884 RT2860_REG_INT_TX_AC3_DONE
|
4885 RT2860_REG_INT_TX_AC2_DONE
|
4886 RT2860_REG_INT_TX_AC1_DONE
|
4887 RT2860_REG_INT_TX_AC0_DONE
);
4889 RT2860_SOFTC_LOCK(sc
);
4891 rt2860_intr_enable(sc
, ~sc
->intr_pending_mask
&
4892 (sc
->intr_disable_mask
& intr_mask
));
4894 if (sc
->intr_pending_mask
& intr_mask
)
4896 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
4897 "%s: Tx done task: scheduling again\n",
4898 device_get_nameunit(sc
->dev
));
4900 taskqueue_enqueue(sc
->taskqueue
, &sc
->tx_done_task
);
4903 RT2860_SOFTC_UNLOCK(sc
);
4907 * rt2860_fifo_sta_full_task
4909 static void rt2860_fifo_sta_full_task(void *context
, int pending
)
4911 struct rt2860_softc
*sc
;
4917 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATS
,
4918 "%s: FIFO statistic full task\n",
4919 device_get_nameunit(sc
->dev
));
4921 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
4924 sc
->intr_pending_mask
&= ~RT2860_REG_INT_FIFO_STA_FULL
;
4926 rt2860_drain_fifo_stats(sc
);
4928 RT2860_SOFTC_LOCK(sc
);
4930 if (sc
->intr_pending_mask
& RT2860_REG_INT_FIFO_STA_FULL
)
4932 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATS
,
4933 "%s: FIFO statistic full task: scheduling again\n",
4934 device_get_nameunit(sc
->dev
));
4936 taskqueue_enqueue(sc
->taskqueue
, &sc
->fifo_sta_full_task
);
4940 rt2860_intr_enable(sc
, RT2860_REG_INT_FIFO_STA_FULL
);
4943 RT2860_SOFTC_UNLOCK(sc
);
4947 * rt2860_periodic_task
4949 static void rt2860_periodic_task(void *context
, int pending
)
4951 struct rt2860_softc
*sc
;
4953 struct ieee80211com
*ic
;
4954 struct ieee80211vap
*vap
;
4959 vap
= TAILQ_FIRST(&ic
->ic_vaps
);
4961 RT2860_DPRINTF(sc
, RT2860_DEBUG_PERIODIC
,
4962 "%s: periodic task: round=%lu\n",
4963 device_get_nameunit(sc
->dev
), sc
->periodic_round
);
4965 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
4968 RT2860_SOFTC_LOCK(sc
);
4970 sc
->periodic_round
++;
4972 rt2860_update_stats(sc
);
4974 if ((sc
->periodic_round
% 10) == 0)
4976 rt2860_bbp_tuning(sc
);
4978 rt2860_update_raw_counters(sc
);
4980 rt2860_watchdog(sc
);
4982 if (vap
!= NULL
&& vap
->iv_opmode
!= IEEE80211_M_MONITOR
&& vap
->iv_state
== IEEE80211_S_RUN
)
4984 if (vap
->iv_opmode
== IEEE80211_M_STA
)
4985 rt2860_amrr_update_iter_func(vap
, vap
->iv_bss
);
4987 ieee80211_iterate_nodes(&ic
->ic_sta
, rt2860_amrr_update_iter_func
, vap
);
4991 RT2860_SOFTC_UNLOCK(sc
);
4993 callout_reset(&sc
->periodic_ch
, hz
/ 10, rt2860_periodic
, sc
);
4999 static int rt2860_rx_eof(struct rt2860_softc
*sc
, int limit
)
5002 struct ieee80211com
*ic
;
5003 struct ieee80211_frame
*wh
;
5004 struct ieee80211_node
*ni
;
5005 struct rt2860_softc_node
*rni
;
5006 struct rt2860_softc_rx_radiotap_header
*tap
;
5007 struct rt2860_softc_rx_ring
*ring
;
5008 struct rt2860_rxdesc
*desc
;
5009 struct rt2860_softc_rx_data
*data
;
5010 struct rt2860_rxwi
*rxwi
;
5011 struct mbuf
*m
, *mnew
;
5012 bus_dma_segment_t segs
[1];
5013 bus_dmamap_t dma_map
;
5014 uint32_t index
, desc_flags
;
5015 uint8_t cipher_err
, rssi
, ant
, phymode
, bw
, shortgi
, mcs
, keyidx
;
5017 int error
, nsegs
, len
, ampdu
, amsdu
, rssi_dbm_rel
, nframes
, i
;
5021 ring
= &sc
->rx_ring
;
5027 index
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_RX_DRX_IDX
);
5028 if (ring
->cur
== index
)
5031 desc
= &ring
->desc
[ring
->cur
];
5032 desc_flags
= le32toh(desc
->flags
);
5033 data
= &ring
->data
[ring
->cur
];
5035 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
5036 BUS_DMASYNC_POSTREAD
| BUS_DMASYNC_POSTWRITE
);
5038 if (!(desc
->sdl0
& htole16(RT2860_RXDESC_SDL0_DDONE
)))
5043 mnew
= m_getjcl(M_DONTWAIT
, MT_DATA
, M_PKTHDR
, MJUMPAGESIZE
);
5046 sc
->rx_mbuf_alloc_errors
++;
5051 mnew
->m_len
= mnew
->m_pkthdr
.len
= MJUMPAGESIZE
;
5053 error
= bus_dmamap_load_mbuf_sg(ring
->data_dma_tag
, ring
->spare_dma_map
,
5054 mnew
, segs
, &nsegs
, BUS_DMA_NOWAIT
);
5057 RT2860_DPRINTF(sc
, RT2860_DEBUG_RX
,
5058 "%s: could not load Rx mbuf DMA map: error=%d, nsegs=%d\n",
5059 device_get_nameunit(sc
->dev
), error
, nsegs
);
5063 sc
->rx_mbuf_dmamap_errors
++;
5069 KASSERT(nsegs
== 1, ("%s: too many DMA segments",
5070 device_get_nameunit(sc
->dev
)));
5072 bus_dmamap_sync(ring
->data_dma_tag
, data
->dma_map
,
5073 BUS_DMASYNC_POSTREAD
);
5074 bus_dmamap_unload(ring
->data_dma_tag
, data
->dma_map
);
5076 dma_map
= data
->dma_map
;
5077 data
->dma_map
= ring
->spare_dma_map
;
5078 ring
->spare_dma_map
= dma_map
;
5080 bus_dmamap_sync(ring
->data_dma_tag
, data
->dma_map
,
5081 BUS_DMASYNC_PREREAD
);
5086 desc
->sdp0
= htole32(segs
[0].ds_addr
);
5088 /* get Rx wireless info */
5090 rxwi
= mtod(m
, struct rt2860_rxwi
*);
5091 len
= (le16toh(rxwi
->tid_size
) >> RT2860_RXWI_SIZE_SHIFT
) &
5092 RT2860_RXWI_SIZE_MASK
;
5094 /* check for L2 padding between IEEE 802.11 frame header and body */
5096 if (desc_flags
& RT2860_RXDESC_FLAGS_L2PAD
)
5098 RT2860_DPRINTF(sc
, RT2860_DEBUG_RX
,
5099 "%s: L2 padding: len=%d\n",
5100 device_get_nameunit(sc
->dev
), len
);
5105 m
->m_pkthdr
.rcvif
= ifp
;
5106 m
->m_data
= (caddr_t
) (rxwi
+ 1);
5107 m
->m_pkthdr
.len
= m
->m_len
= len
;
5109 /* check for crc errors */
5111 if (desc_flags
& RT2860_RXDESC_FLAGS_CRC_ERR
)
5113 RT2860_DPRINTF(sc
, RT2860_DEBUG_RX
,
5114 "%s: rxdesc: crc error\n",
5115 device_get_nameunit(sc
->dev
));
5119 if (!(ifp
->if_flags
& IFF_PROMISC
))
5126 wh
= (struct ieee80211_frame
*) (rxwi
+ 1);
5128 /* check for cipher errors */
5130 if (desc_flags
& RT2860_RXDESC_FLAGS_DECRYPTED
)
5132 cipher_err
= ((desc_flags
>> RT2860_RXDESC_FLAGS_CIPHER_ERR_SHIFT
) &
5133 RT2860_RXDESC_FLAGS_CIPHER_ERR_MASK
);
5134 if (cipher_err
== RT2860_RXDESC_FLAGS_CIPHER_ERR_NONE
)
5136 if (wh
->i_fc
[1] & IEEE80211_FC1_WEP
)
5137 wh
->i_fc
[1] &= ~IEEE80211_FC1_WEP
;
5139 m
->m_flags
|= M_WEP
;
5143 RT2860_DPRINTF(sc
, RT2860_DEBUG_RX
,
5144 "%s: rxdesc: cipher error=0x%02x\n",
5145 device_get_nameunit(sc
->dev
), cipher_err
);
5147 if ((cipher_err
== RT2860_RXDESC_FLAGS_CIPHER_ERR_MIC
) &&
5148 (desc_flags
& RT2860_RXDESC_FLAGS_MYBSS
))
5150 ni
= ieee80211_find_rxnode(ic
, (const struct ieee80211_frame_min
*) wh
);
5153 keyidx
= (rxwi
->udf_bssidx_keyidx
>> RT2860_RXWI_KEYIDX_SHIFT
) &
5154 RT2860_RXWI_KEYIDX_MASK
;
5156 ieee80211_notify_michael_failure(ni
->ni_vap
, wh
, keyidx
);
5158 ieee80211_free_node(ni
);
5164 if (!(ifp
->if_flags
& IFF_PROMISC
))
5173 if (wh
->i_fc
[1] & IEEE80211_FC1_WEP
)
5175 RT2860_DPRINTF(sc
, RT2860_DEBUG_RX
,
5176 "%s: rxdesc: not decrypted but protected flag set\n",
5177 device_get_nameunit(sc
->dev
));
5181 if (!(ifp
->if_flags
& IFF_PROMISC
))
5189 /* check for A-MPDU */
5191 if (desc_flags
& RT2860_RXDESC_FLAGS_AMPDU
)
5193 m
->m_flags
|= M_AMPDU
;
5204 /* check for A-MSDU */
5206 if (desc_flags
& RT2860_RXDESC_FLAGS_AMSDU
)
5217 ant
= rt2860_maxrssi_rxpath(sc
, rxwi
);
5218 rssi
= rxwi
->rssi
[ant
];
5219 rssi_dbm
= rt2860_rssi2dbm(sc
, rssi
, ant
);
5220 phymode
= ((rxwi
->phymode_stbc_shortgi
>> RT2860_RXWI_PHYMODE_SHIFT
) &
5221 RT2860_RXWI_PHYMODE_MASK
);
5222 bw
= ((rxwi
->bw_mcs
>> RT2860_RXWI_BW_SHIFT
) & RT2860_RXWI_BW_MASK
);
5223 shortgi
= ((rxwi
->phymode_stbc_shortgi
>> RT2860_RXWI_SHORTGI_SHIFT
) &
5224 RT2860_RXWI_SHORTGI_MASK
);
5225 mcs
= ((rxwi
->bw_mcs
>> RT2860_RXWI_MCS_SHIFT
) & RT2860_RXWI_MCS_MASK
);
5227 if (ieee80211_radiotap_active(ic
))
5231 tap
->flags
= (desc_flags
& RT2860_RXDESC_FLAGS_L2PAD
) ? IEEE80211_RADIOTAP_F_DATAPAD
: 0;
5232 tap
->dbm_antsignal
= rssi_dbm
;
5233 tap
->dbm_antnoise
= RT2860_NOISE_FLOOR
;
5235 tap
->antsignal
= rssi
;
5236 tap
->chan_flags
= htole32(ic
->ic_curchan
->ic_flags
);
5237 tap
->chan_freq
= htole16(ic
->ic_curchan
->ic_freq
);
5238 tap
->chan_ieee
= ic
->ic_curchan
->ic_ieee
;
5239 tap
->chan_maxpow
= 0;
5241 if (phymode
== RT2860_TXWI_PHYMODE_HT_MIXED
|| phymode
== RT2860_TXWI_PHYMODE_HT_GF
)
5242 tap
->rate
= mcs
| IEEE80211_RATE_MCS
;
5244 tap
->rate
= rt2860_rxrate(rxwi
);
5246 if (desc_flags
& RT2860_RXDESC_FLAGS_CRC_ERR
)
5247 tap
->flags
|= IEEE80211_RADIOTAP_F_BADFCS
;
5249 if (desc_flags
& RT2860_RXDESC_FLAGS_FRAG
)
5250 tap
->flags
|= IEEE80211_RADIOTAP_F_FRAG
;
5252 if (rxwi
->bw_mcs
& RT2860_RXWI_MCS_SHOTPRE
)
5253 tap
->flags
|= IEEE80211_RADIOTAP_F_SHORTPRE
;
5256 tap
->flags
|= IEEE80211_RADIOTAP_F_SHORTGI
;
5260 * net80211 assumes that RSSI data are in the range [-127..127] and
5261 * in .5 dBm units relative to the current noise floor
5264 rssi_dbm_rel
= (rssi_dbm
- RT2860_NOISE_FLOOR
) * 2;
5265 if (rssi_dbm_rel
> 127)
5268 RT2860_DPRINTF(sc
, RT2860_DEBUG_RX
,
5269 "%s: received frame: len=%d, phymode=%d, bw=%d, shortgi=%d, mcs=%d, "
5270 "ant=%d, rssi=%d/%d/%d, snr=%d/%d, wcid=0x%02x, ampdu=%d, amsdu=%d, "
5271 "rssi_dbm=%d, rssi_dbm_rel=%d\n",
5272 device_get_nameunit(sc
->dev
),
5273 len
, phymode
, bw
, shortgi
, mcs
,
5274 ant
, rxwi
->rssi
[0], rxwi
->rssi
[1], rxwi
->rssi
[2],
5275 rxwi
->snr
[0], rxwi
->snr
[1],
5276 rxwi
->wcid
, ampdu
, amsdu
, rssi_dbm
, rssi_dbm_rel
);
5278 ni
= ieee80211_find_rxnode(ic
, (struct ieee80211_frame_min
*) wh
);
5281 rni
= (struct rt2860_softc_node
*) ni
;
5283 for (i
= 0; i
< RT2860_SOFTC_RSSI_DBM_COUNT
; i
++)
5284 rni
->last_rssi_dbm
[i
] = rt2860_rssi2dbm(sc
, rxwi
->rssi
[i
], i
);
5286 ieee80211_input(ni
, m
, rssi_dbm_rel
, RT2860_NOISE_FLOOR
);
5287 ieee80211_free_node(ni
);
5291 ieee80211_input_all(ic
, m
, rssi_dbm_rel
, RT2860_NOISE_FLOOR
);
5296 desc
->sdl0
&= ~htole16(RT2860_RXDESC_SDL0_DDONE
);
5298 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
5299 BUS_DMASYNC_PREREAD
| BUS_DMASYNC_PREWRITE
);
5301 ring
->cur
= (ring
->cur
+ 1) % RT2860_SOFTC_RX_RING_DATA_COUNT
;
5307 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_CALC_IDX
,
5308 RT2860_SOFTC_RX_RING_DATA_COUNT
- 1);
5310 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_CALC_IDX
,
5313 RT2860_DPRINTF(sc
, RT2860_DEBUG_RX
,
5314 "%s: Rx eof: nframes=%d\n",
5315 device_get_nameunit(sc
->dev
), nframes
);
5317 sc
->rx_packets
+= nframes
;
5319 return (limit
== 0);
5325 static void rt2860_tx_eof(struct rt2860_softc
*sc
,
5326 struct rt2860_softc_tx_ring
*ring
)
5329 struct rt2860_txdesc
*desc
;
5330 struct rt2860_softc_tx_data
*data
;
5332 int ndescs
, nframes
;
5341 index
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_TX_DTX_IDX(ring
->qid
));
5342 if (ring
->desc_next
== index
)
5347 rt2860_drain_fifo_stats(sc
);
5349 desc
= &ring
->desc
[ring
->desc_next
];
5351 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
5352 BUS_DMASYNC_POSTREAD
| BUS_DMASYNC_POSTWRITE
);
5354 if (desc
->sdl0
& htole16(RT2860_TXDESC_SDL0_LASTSEG
) ||
5355 desc
->sdl1
& htole16(RT2860_TXDESC_SDL1_LASTSEG
))
5359 data
= &ring
->data
[ring
->data_next
];
5361 if (data
->m
->m_flags
& M_TXCB
)
5362 ieee80211_process_callback(data
->ni
, data
->m
, 0);
5364 bus_dmamap_sync(ring
->data_dma_tag
, data
->dma_map
,
5365 BUS_DMASYNC_POSTWRITE
);
5366 bus_dmamap_unload(ring
->data_dma_tag
, data
->dma_map
);
5370 ieee80211_free_node(data
->ni
);
5377 RT2860_SOFTC_LOCK(sc
);
5379 ring
->data_queued
--;
5380 ring
->data_next
= (ring
->data_next
+ 1) % RT2860_SOFTC_TX_RING_DATA_COUNT
;
5382 RT2860_SOFTC_UNLOCK(sc
);
5385 desc
->sdl0
&= ~htole16(RT2860_TXDESC_SDL0_DDONE
);
5387 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
5388 BUS_DMASYNC_PREREAD
| BUS_DMASYNC_PREWRITE
);
5390 RT2860_SOFTC_LOCK(sc
);
5392 ring
->desc_queued
--;
5393 ring
->desc_next
= (ring
->desc_next
+ 1) % RT2860_SOFTC_TX_RING_DESC_COUNT
;
5395 RT2860_SOFTC_UNLOCK(sc
);
5398 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
5399 "%s: Tx eof: qid=%d, ndescs=%d, nframes=%d\n",
5400 device_get_nameunit(sc
->dev
), ring
->qid
, ndescs
, nframes
);
5404 * rt2860_update_stats
5406 static void rt2860_update_stats(struct rt2860_softc
*sc
)
5409 struct ieee80211com
*ic
;
5410 struct ieee80211vap
*vap
;
5411 struct ieee80211_node
*ni
;
5413 int beacons
, noretryok
, retryok
, failed
, underflows
, zerolen
;
5419 vap
= TAILQ_FIRST(&ic
->ic_vaps
);
5421 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATS
,
5422 "%s: update statistic\n",
5423 device_get_nameunit(sc
->dev
));
5425 rt2860_drain_fifo_stats(sc
);
5427 /* read and clear Tx statistic registers */
5429 rt2860_io_mac_read_multi(sc
, RT2860_REG_TX_STA_CNT0
,
5430 stacnt
, sizeof(stacnt
));
5432 stacnt
[0] = le32toh(stacnt
[0]);
5433 stacnt
[1] = le32toh(stacnt
[1]);
5434 stacnt
[2] = le32toh(stacnt
[2]);
5436 beacons
= stacnt
[0] >> 16;
5437 noretryok
= stacnt
[1] & 0xffff;
5438 retryok
= stacnt
[1] >> 16;
5439 failed
= stacnt
[0] & 0xffff;
5440 underflows
= stacnt
[2] >> 16;
5441 zerolen
= stacnt
[2] & 0xffff;
5443 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATS
,
5444 "%s: update statistic: beacons=%d, noretryok=%d, retryok=%d, failed=%d, underflows=%d, zerolen=%d\n",
5445 device_get_nameunit(sc
->dev
),
5446 beacons
, noretryok
, retryok
, failed
, underflows
, zerolen
);
5448 ifp
->if_oerrors
+= failed
;
5450 sc
->tx_beacons
+= beacons
;
5451 sc
->tx_noretryok
+= noretryok
;
5452 sc
->tx_retryok
+= retryok
;
5453 sc
->tx_failed
+= failed
;
5454 sc
->tx_underflows
+= underflows
;
5455 sc
->tx_zerolen
+= zerolen
;
5457 if (vap
!= NULL
&& vap
->iv_opmode
== IEEE80211_M_STA
&& vap
->iv_state
== IEEE80211_S_RUN
)
5461 associd
= (ni
!= NULL
) ? ni
->ni_associd
: 0;
5462 wcid
= RT2860_AID2WCID(associd
);
5464 rt2860_amrr_tx_update(&sc
->amrr_node
[wcid
],
5465 noretryok
+ retryok
+ failed
, noretryok
+ retryok
, retryok
+ failed
);
5472 static void rt2860_bbp_tuning(struct rt2860_softc
*sc
)
5475 struct ieee80211com
*ic
;
5476 struct ieee80211vap
*vap
;
5477 struct ieee80211_node
*ni
;
5479 int8_t rssi
, old
, new;
5481 /* RT2860C does not support BBP tuning */
5483 if (sc
->mac_rev
== 0x28600100)
5488 vap
= TAILQ_FIRST(&ic
->ic_vaps
);
5490 if ((ic
->ic_flags
& IEEE80211_F_SCAN
) || vap
== NULL
||
5491 vap
->iv_opmode
!= IEEE80211_M_STA
|| vap
->iv_state
!= IEEE80211_S_RUN
)
5496 chan
= ieee80211_chan2ieee(ic
, ni
->ni_chan
);
5500 else if (chan
<= 64)
5502 else if (chan
<= 128)
5507 rssi
= ieee80211_getrssi(vap
);
5509 if (IEEE80211_IS_CHAN_2GHZ(ni
->ni_chan
))
5511 new = 0x2e + sc
->lna_gain
[group
];
5515 if (!IEEE80211_IS_CHAN_HT40(ni
->ni_chan
))
5516 new = 0x32 + sc
->lna_gain
[group
] * 5 / 3;
5518 new = 0x3a + sc
->lna_gain
[group
] * 5 / 3;
5521 /* Tune if absolute average RSSI is greater than -80 */
5526 old
= rt2860_io_bbp_read(sc
, 66);
5529 rt2860_io_bbp_write(sc
, 66, new);
5535 static void rt2860_watchdog(struct rt2860_softc
*sc
)
5540 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_PBF_TXRXQ_PCNT
);
5542 RT2860_DPRINTF(sc
, RT2860_DEBUG_WATCHDOG
,
5543 "%s: watchdog: TXRXQ_PCNT=0x%08x\n",
5544 device_get_nameunit(sc
->dev
), tmp
);
5546 if (((tmp
>> RT2860_REG_TX0Q_PCNT_SHIFT
) & RT2860_REG_TX0Q_PCNT_MASK
) != 0)
5548 sc
->tx_queue_not_empty
[0]++;
5550 rt2860_io_mac_write(sc
, RT2860_REG_PBF_CFG
, 0xf40012);
5552 for (ntries
= 0; ntries
< 10; ntries
++)
5554 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_PBF_TXRXQ_PCNT
);
5555 if (((tmp
>> RT2860_REG_TX0Q_PCNT_SHIFT
) & RT2860_REG_TX0Q_PCNT_MASK
) == 0)
5561 rt2860_io_mac_write(sc
, RT2860_REG_PBF_CFG
, 0xf40006);
5564 if (((tmp
>> RT2860_REG_TX1Q_PCNT_SHIFT
) & RT2860_REG_TX1Q_PCNT_MASK
) != 0)
5566 sc
->tx_queue_not_empty
[1]++;
5568 rt2860_io_mac_write(sc
, RT2860_REG_PBF_CFG
, 0xf4000a);
5570 for (ntries
= 0; ntries
< 10; ntries
++)
5572 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_PBF_TXRXQ_PCNT
);
5573 if (((tmp
>> RT2860_REG_TX1Q_PCNT_SHIFT
) & RT2860_REG_TX1Q_PCNT_MASK
) == 0)
5579 rt2860_io_mac_write(sc
, RT2860_REG_PBF_CFG
, 0xf40006);
5584 * rt2860_drain_fifo_stats
5586 static void rt2860_drain_fifo_stats(struct rt2860_softc
*sc
)
5590 uint8_t wcid
, mcs
, pid
;
5591 int ok
, agg
, retrycnt
;
5595 /* drain Tx status FIFO (maxsize = 16) */
5597 while ((stats
= rt2860_io_mac_read(sc
, RT2860_REG_TX_STA_FIFO
)) &
5598 RT2860_REG_TX_STA_FIFO_VALID
)
5600 wcid
= (stats
>> RT2860_REG_TX_STA_FIFO_WCID_SHIFT
) &
5601 RT2860_REG_TX_STA_FIFO_WCID_MASK
;
5603 /* if no ACK was requested, no feedback is available */
5605 if (!(stats
& RT2860_REG_TX_STA_FIFO_ACK_REQ
) || wcid
== 0xff)
5608 /* update AMRR statistic */
5610 ok
= (stats
& RT2860_REG_TX_STA_FIFO_TX_OK
) ? 1 : 0;
5611 agg
= (stats
& RT2860_REG_TX_STA_FIFO_AGG
) ? 1 : 0;
5612 mcs
= (stats
>> RT2860_REG_TX_STA_FIFO_MCS_SHIFT
) &
5613 RT2860_REG_TX_STA_FIFO_MCS_MASK
;
5614 pid
= (stats
>> RT2860_REG_TX_STA_FIFO_PID_SHIFT
) &
5615 RT2860_REG_TX_STA_FIFO_PID_MASK
;
5616 retrycnt
= pid
- mcs
;
5618 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATS
,
5619 "%s: FIFO statistic: wcid=0x%02x, ok=%d, agg=%d, mcs=0x%02x, pid=0x%02x, retrycnt=%d\n",
5620 device_get_nameunit(sc
->dev
),
5621 wcid
, ok
, agg
, mcs
, pid
, retrycnt
);
5623 rt2860_amrr_tx_complete(&sc
->amrr_node
[wcid
], ok
, retrycnt
);
5631 * rt2860_update_raw_counters
5633 static void rt2860_update_raw_counters(struct rt2860_softc
*sc
)
5637 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_AGG_CNT
);
5639 sc
->tx_nonagg
+= tmp
& 0xffff;
5640 sc
->tx_agg
+= tmp
>> 16;
5642 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_AGG_CNT0
);
5644 sc
->tx_ampdu
+= (tmp
& 0xffff) / 1 + (tmp
>> 16) / 2;
5646 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_AGG_CNT1
);
5648 sc
->tx_ampdu
+= (tmp
& 0xffff) / 3 + (tmp
>> 16) / 4;
5650 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_AGG_CNT2
);
5652 sc
->tx_ampdu
+= (tmp
& 0xffff) / 5 + (tmp
>> 16) / 6;
5654 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_AGG_CNT3
);
5656 sc
->tx_ampdu
+= (tmp
& 0xffff) / 7 + (tmp
>> 16) / 8;
5658 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_AGG_CNT4
);
5660 sc
->tx_ampdu
+= (tmp
& 0xffff) / 9 + (tmp
>> 16) / 10;
5662 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_AGG_CNT5
);
5664 sc
->tx_ampdu
+= (tmp
& 0xffff) / 11 + (tmp
>> 16) / 12;
5666 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_AGG_CNT6
);
5668 sc
->tx_ampdu
+= (tmp
& 0xffff) / 13 + (tmp
>> 16) / 14;
5670 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_AGG_CNT7
);
5672 sc
->tx_ampdu
+= (tmp
& 0xffff) / 15 + (tmp
>> 16) / 16;
5674 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_RX_STA_CNT0
);
5676 sc
->rx_crc_errors
+= tmp
& 0xffff;
5677 sc
->rx_phy_errors
+= tmp
>> 16;
5679 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_RX_STA_CNT1
);
5681 sc
->rx_false_ccas
+= tmp
& 0xffff;
5682 sc
->rx_plcp_errors
+= tmp
>> 16;
5684 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_RX_STA_CNT2
);
5686 sc
->rx_dup_packets
+= tmp
& 0xffff;
5687 sc
->rx_fifo_overflows
+= tmp
>> 16;
5689 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TXRX_MPDU_DEN_CNT
);
5691 sc
->tx_mpdu_zero_density
+= tmp
& 0xffff;
5692 sc
->rx_mpdu_zero_density
+= tmp
>> 16;
5696 * rt2860_intr_enable
5698 static void rt2860_intr_enable(struct rt2860_softc
*sc
, uint32_t intr_mask
)
5702 sc
->intr_disable_mask
&= ~intr_mask
;
5704 tmp
= sc
->intr_enable_mask
& ~sc
->intr_disable_mask
;
5706 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_INT_MASK
, tmp
);
5710 * rt2860_intr_disable
5712 static void rt2860_intr_disable(struct rt2860_softc
*sc
, uint32_t intr_mask
)
5716 sc
->intr_disable_mask
|= intr_mask
;
5718 tmp
= sc
->intr_enable_mask
& ~sc
->intr_disable_mask
;
5720 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_INT_MASK
, tmp
);
5724 * rt2860_txrx_enable
5726 static int rt2860_txrx_enable(struct rt2860_softc
*sc
)
5728 struct ieee80211com
*ic
;
5736 /* enable Tx/Rx DMA engine */
5738 rt2860_io_mac_write(sc
, RT2860_REG_SYS_CTRL
, RT2860_REG_TX_ENABLE
);
5740 for (ntries
= 0; ntries
< 200; ntries
++)
5742 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
);
5743 if (!(tmp
& (RT2860_REG_TX_DMA_BUSY
| RT2860_REG_RX_DMA_BUSY
)))
5751 printf("%s: timeout waiting for DMA engine\n",
5752 device_get_nameunit(sc
->dev
));
5758 tmp
|= RT2860_REG_TX_WB_DDONE
|
5759 RT2860_REG_RX_DMA_ENABLE
|
5760 RT2860_REG_TX_DMA_ENABLE
|
5761 (RT2860_REG_WPDMA_BT_SIZE64
<< RT2860_REG_WPDMA_BT_SIZE_SHIFT
);
5763 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
, tmp
);
5767 tmp
= RT2860_REG_RX_FILTER_DROP_CRC_ERR
|
5768 RT2860_REG_RX_FILTER_DROP_PHY_ERR
;
5770 if (ic
->ic_opmode
!= IEEE80211_M_MONITOR
)
5772 tmp
|= RT2860_REG_RX_FILTER_DROP_DUPL
|
5773 RT2860_REG_RX_FILTER_DROP_CTS
|
5774 RT2860_REG_RX_FILTER_DROP_BA
|
5775 RT2860_REG_RX_FILTER_DROP_ACK
|
5776 RT2860_REG_RX_FILTER_DROP_VER_ERR
|
5777 RT2860_REG_RX_FILTER_DROP_CTRL_RSV
|
5778 RT2860_REG_RX_FILTER_DROP_CFACK
|
5779 RT2860_REG_RX_FILTER_DROP_CFEND
;
5781 if (ic
->ic_opmode
== IEEE80211_M_STA
)
5782 tmp
|= RT2860_REG_RX_FILTER_DROP_RTS
|
5783 RT2860_REG_RX_FILTER_DROP_PSPOLL
;
5785 if (!(ifp
->if_flags
& IFF_PROMISC
))
5786 tmp
|= RT2860_REG_RX_FILTER_DROP_UC_NOME
;
5789 rt2860_io_mac_write(sc
, RT2860_REG_RX_FILTER_CFG
, tmp
);
5791 rt2860_io_mac_write(sc
, RT2860_REG_SYS_CTRL
,
5792 RT2860_REG_RX_ENABLE
| RT2860_REG_TX_ENABLE
);
5798 * rt2860_alloc_rx_ring
5800 static int rt2860_alloc_rx_ring(struct rt2860_softc
*sc
,
5801 struct rt2860_softc_rx_ring
*ring
)
5803 struct rt2860_rxdesc
*desc
;
5804 struct rt2860_softc_rx_data
*data
;
5805 bus_dma_segment_t segs
[1];
5806 int i
, nsegs
, error
;
5808 error
= bus_dma_tag_create(bus_get_dma_tag(sc
->dev
), PAGE_SIZE
, 0,
5809 BUS_SPACE_MAXADDR_32BIT
, BUS_SPACE_MAXADDR
, NULL
, NULL
,
5810 RT2860_SOFTC_RX_RING_DATA_COUNT
* sizeof(struct rt2860_rxdesc
), 1,
5811 RT2860_SOFTC_RX_RING_DATA_COUNT
* sizeof(struct rt2860_rxdesc
),
5812 0, NULL
, NULL
, &ring
->desc_dma_tag
);
5815 printf("%s: could not create Rx desc DMA tag\n",
5816 device_get_nameunit(sc
->dev
));
5820 error
= bus_dmamem_alloc(ring
->desc_dma_tag
, (void **) &ring
->desc
,
5821 BUS_DMA_NOWAIT
| BUS_DMA_ZERO
, &ring
->desc_dma_map
);
5824 printf("%s: could not allocate Rx desc DMA memory\n",
5825 device_get_nameunit(sc
->dev
));
5829 error
= bus_dmamap_load(ring
->desc_dma_tag
, ring
->desc_dma_map
,
5831 RT2860_SOFTC_RX_RING_DATA_COUNT
* sizeof(struct rt2860_rxdesc
),
5832 rt2860_dma_map_addr
, &ring
->desc_phys_addr
, 0);
5835 printf("%s: could not load Rx desc DMA map\n",
5836 device_get_nameunit(sc
->dev
));
5840 error
= bus_dma_tag_create(bus_get_dma_tag(sc
->dev
), PAGE_SIZE
, 0,
5841 BUS_SPACE_MAXADDR_32BIT
, BUS_SPACE_MAXADDR
, NULL
, NULL
,
5842 MJUMPAGESIZE
, 1, MJUMPAGESIZE
, 0, NULL
, NULL
,
5843 &ring
->data_dma_tag
);
5846 printf("%s: could not create Rx data DMA tag\n",
5847 device_get_nameunit(sc
->dev
));
5851 for (i
= 0; i
< RT2860_SOFTC_RX_RING_DATA_COUNT
; i
++)
5853 desc
= &ring
->desc
[i
];
5854 data
= &ring
->data
[i
];
5856 error
= bus_dmamap_create(ring
->data_dma_tag
, 0, &data
->dma_map
);
5859 printf("%s: could not create Rx data DMA map\n",
5860 device_get_nameunit(sc
->dev
));
5864 data
->m
= m_getjcl(M_DONTWAIT
, MT_DATA
, M_PKTHDR
, MJUMPAGESIZE
);
5865 if (data
->m
== NULL
)
5867 printf("%s: could not allocate Rx mbuf\n",
5868 device_get_nameunit(sc
->dev
));
5873 data
->m
->m_len
= data
->m
->m_pkthdr
.len
= MJUMPAGESIZE
;
5875 error
= bus_dmamap_load_mbuf_sg(ring
->data_dma_tag
, data
->dma_map
,
5876 data
->m
, segs
, &nsegs
, BUS_DMA_NOWAIT
);
5879 printf("%s: could not load Rx mbuf DMA map\n",
5880 device_get_nameunit(sc
->dev
));
5884 KASSERT(nsegs
== 1, ("%s: too many DMA segments",
5885 device_get_nameunit(sc
->dev
)));
5887 desc
->sdp0
= htole32(segs
[0].ds_addr
);
5888 desc
->sdl0
= htole16(MJUMPAGESIZE
);
5891 error
= bus_dmamap_create(ring
->data_dma_tag
, 0, &ring
->spare_dma_map
);
5894 printf("%s: could not create Rx spare DMA map\n",
5895 device_get_nameunit(sc
->dev
));
5899 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
5900 BUS_DMASYNC_PREREAD
| BUS_DMASYNC_PREWRITE
);
5906 rt2860_free_rx_ring(sc
, ring
);
5912 * rt2860_reset_rx_ring
5914 static void rt2860_reset_rx_ring(struct rt2860_softc
*sc
,
5915 struct rt2860_softc_rx_ring
*ring
)
5917 struct rt2860_rxdesc
*desc
;
5920 for (i
= 0; i
< RT2860_SOFTC_RX_RING_DATA_COUNT
; i
++)
5922 desc
= &ring
->desc
[i
];
5924 desc
->sdl0
&= ~htole16(RT2860_RXDESC_SDL0_DDONE
);
5927 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
5928 BUS_DMASYNC_PREREAD
| BUS_DMASYNC_PREWRITE
);
5934 * rt2860_free_rx_ring
5936 static void rt2860_free_rx_ring(struct rt2860_softc
*sc
,
5937 struct rt2860_softc_rx_ring
*ring
)
5939 struct rt2860_softc_rx_data
*data
;
5942 if (ring
->desc
!= NULL
)
5944 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
5945 BUS_DMASYNC_POSTWRITE
);
5946 bus_dmamap_unload(ring
->desc_dma_tag
, ring
->desc_dma_map
);
5947 bus_dmamem_free(ring
->desc_dma_tag
, ring
->desc
,
5948 ring
->desc_dma_map
);
5951 if (ring
->desc_dma_tag
!= NULL
)
5952 bus_dma_tag_destroy(ring
->desc_dma_tag
);
5954 for (i
= 0; i
< RT2860_SOFTC_RX_RING_DATA_COUNT
; i
++)
5956 data
= &ring
->data
[i
];
5958 if (data
->m
!= NULL
)
5960 bus_dmamap_sync(ring
->data_dma_tag
, data
->dma_map
,
5961 BUS_DMASYNC_POSTREAD
);
5962 bus_dmamap_unload(ring
->data_dma_tag
, data
->dma_map
);
5966 if (data
->dma_map
!= NULL
)
5967 bus_dmamap_destroy(ring
->data_dma_tag
, data
->dma_map
);
5970 if (ring
->spare_dma_map
!= NULL
)
5971 bus_dmamap_destroy(ring
->data_dma_tag
, ring
->spare_dma_map
);
5973 if (ring
->data_dma_tag
!= NULL
)
5974 bus_dma_tag_destroy(ring
->data_dma_tag
);
5978 * rt2860_alloc_tx_ring
5980 static int rt2860_alloc_tx_ring(struct rt2860_softc
*sc
,
5981 struct rt2860_softc_tx_ring
*ring
, int qid
)
5983 struct rt2860_softc_tx_data
*data
;
5986 error
= bus_dma_tag_create(bus_get_dma_tag(sc
->dev
), PAGE_SIZE
, 0,
5987 BUS_SPACE_MAXADDR_32BIT
, BUS_SPACE_MAXADDR
, NULL
, NULL
,
5988 RT2860_SOFTC_TX_RING_DESC_COUNT
* sizeof(struct rt2860_txdesc
), 1,
5989 RT2860_SOFTC_TX_RING_DESC_COUNT
* sizeof(struct rt2860_txdesc
),
5990 0, NULL
, NULL
, &ring
->desc_dma_tag
);
5993 printf("%s: could not create Tx desc DMA tag\n",
5994 device_get_nameunit(sc
->dev
));
5998 error
= bus_dmamem_alloc(ring
->desc_dma_tag
, (void **) &ring
->desc
,
5999 BUS_DMA_NOWAIT
| BUS_DMA_ZERO
, &ring
->desc_dma_map
);
6002 printf("%s: could not allocate Tx desc DMA memory\n",
6003 device_get_nameunit(sc
->dev
));
6007 error
= bus_dmamap_load(ring
->desc_dma_tag
, ring
->desc_dma_map
,
6009 RT2860_SOFTC_TX_RING_DESC_COUNT
* sizeof(struct rt2860_txdesc
),
6010 rt2860_dma_map_addr
, &ring
->desc_phys_addr
, 0);
6013 printf("%s: could not load Tx desc DMA map\n",
6014 device_get_nameunit(sc
->dev
));
6018 ring
->desc_queued
= 0;
6020 ring
->desc_next
= 0;
6022 error
= bus_dma_tag_create(bus_get_dma_tag(sc
->dev
), PAGE_SIZE
, 0,
6023 BUS_SPACE_MAXADDR_32BIT
, BUS_SPACE_MAXADDR
, NULL
, NULL
,
6024 RT2860_SOFTC_TX_RING_DATA_COUNT
* RT2860_TX_DATA_SEG0_SIZE
, 1,
6025 RT2860_SOFTC_TX_RING_DATA_COUNT
* RT2860_TX_DATA_SEG0_SIZE
,
6026 0, NULL
, NULL
, &ring
->seg0_dma_tag
);
6029 printf("%s: could not create Tx seg0 DMA tag\n",
6030 device_get_nameunit(sc
->dev
));
6034 error
= bus_dmamem_alloc(ring
->seg0_dma_tag
, (void **) &ring
->seg0
,
6035 BUS_DMA_NOWAIT
| BUS_DMA_ZERO
, &ring
->seg0_dma_map
);
6038 printf("%s: could not allocate Tx seg0 DMA memory\n",
6039 device_get_nameunit(sc
->dev
));
6043 error
= bus_dmamap_load(ring
->seg0_dma_tag
, ring
->seg0_dma_map
,
6045 RT2860_SOFTC_TX_RING_DATA_COUNT
* RT2860_TX_DATA_SEG0_SIZE
,
6046 rt2860_dma_map_addr
, &ring
->seg0_phys_addr
, 0);
6049 printf("%s: could not load Tx seg0 DMA map\n",
6050 device_get_nameunit(sc
->dev
));
6054 error
= bus_dma_tag_create(bus_get_dma_tag(sc
->dev
), PAGE_SIZE
, 0,
6055 BUS_SPACE_MAXADDR_32BIT
, BUS_SPACE_MAXADDR
, NULL
, NULL
,
6056 MJUMPAGESIZE
, RT2860_SOFTC_MAX_SCATTER
, MJUMPAGESIZE
, 0, NULL
, NULL
,
6057 &ring
->data_dma_tag
);
6060 printf("%s: could not create Tx data DMA tag\n",
6061 device_get_nameunit(sc
->dev
));
6065 for (i
= 0; i
< RT2860_SOFTC_TX_RING_DATA_COUNT
; i
++)
6067 data
= &ring
->data
[i
];
6069 error
= bus_dmamap_create(ring
->data_dma_tag
, 0, &data
->dma_map
);
6072 printf("%s: could not create Tx data DMA map\n",
6073 device_get_nameunit(sc
->dev
));
6078 ring
->data_queued
= 0;
6080 ring
->data_next
= 0;
6088 rt2860_free_tx_ring(sc
, ring
);
6094 * rt2860_reset_tx_ring
6096 static void rt2860_reset_tx_ring(struct rt2860_softc
*sc
,
6097 struct rt2860_softc_tx_ring
*ring
)
6099 struct rt2860_softc_tx_data
*data
;
6100 struct rt2860_txdesc
*desc
;
6103 for (i
= 0; i
< RT2860_SOFTC_TX_RING_DESC_COUNT
; i
++)
6105 desc
= &ring
->desc
[i
];
6111 ring
->desc_queued
= 0;
6113 ring
->desc_next
= 0;
6115 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
6116 BUS_DMASYNC_PREWRITE
);
6118 bus_dmamap_sync(ring
->seg0_dma_tag
, ring
->seg0_dma_map
,
6119 BUS_DMASYNC_PREWRITE
);
6121 for (i
= 0; i
< RT2860_SOFTC_TX_RING_DATA_COUNT
; i
++)
6123 data
= &ring
->data
[i
];
6125 if (data
->m
!= NULL
)
6127 bus_dmamap_sync(ring
->data_dma_tag
, data
->dma_map
,
6128 BUS_DMASYNC_POSTWRITE
);
6129 bus_dmamap_unload(ring
->data_dma_tag
, data
->dma_map
);
6134 if (data
->ni
!= NULL
)
6136 ieee80211_free_node(data
->ni
);
6141 ring
->data_queued
= 0;
6143 ring
->data_next
= 0;
6147 * rt2860_free_tx_ring
6149 static void rt2860_free_tx_ring(struct rt2860_softc
*sc
,
6150 struct rt2860_softc_tx_ring
*ring
)
6152 struct rt2860_softc_tx_data
*data
;
6155 if (ring
->desc
!= NULL
)
6157 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
6158 BUS_DMASYNC_POSTWRITE
);
6159 bus_dmamap_unload(ring
->desc_dma_tag
, ring
->desc_dma_map
);
6160 bus_dmamem_free(ring
->desc_dma_tag
, ring
->desc
,
6161 ring
->desc_dma_map
);
6164 if (ring
->desc_dma_tag
!= NULL
)
6165 bus_dma_tag_destroy(ring
->desc_dma_tag
);
6167 if (ring
->seg0
!= NULL
)
6169 bus_dmamap_sync(ring
->seg0_dma_tag
, ring
->seg0_dma_map
,
6170 BUS_DMASYNC_POSTWRITE
);
6171 bus_dmamap_unload(ring
->seg0_dma_tag
, ring
->seg0_dma_map
);
6172 bus_dmamem_free(ring
->seg0_dma_tag
, ring
->seg0
,
6173 ring
->seg0_dma_map
);
6176 if (ring
->seg0_dma_tag
!= NULL
)
6177 bus_dma_tag_destroy(ring
->seg0_dma_tag
);
6179 for (i
= 0; i
< RT2860_SOFTC_TX_RING_DATA_COUNT
; i
++)
6181 data
= &ring
->data
[i
];
6183 if (data
->m
!= NULL
)
6185 bus_dmamap_sync(ring
->data_dma_tag
, data
->dma_map
,
6186 BUS_DMASYNC_POSTWRITE
);
6187 bus_dmamap_unload(ring
->data_dma_tag
, data
->dma_map
);
6191 if (data
->ni
!= NULL
)
6192 ieee80211_free_node(data
->ni
);
6194 if (data
->dma_map
!= NULL
)
6195 bus_dmamap_destroy(ring
->data_dma_tag
, data
->dma_map
);
6198 if (ring
->data_dma_tag
!= NULL
)
6199 bus_dma_tag_destroy(ring
->data_dma_tag
);
6203 * rt2860_dma_map_addr
6205 static void rt2860_dma_map_addr(void *arg
, bus_dma_segment_t
*segs
,
6206 int nseg
, int error
)
6211 KASSERT(nseg
== 1, ("too many DMA segments, %d should be 1", nseg
));
6213 *(bus_addr_t
*) arg
= segs
[0].ds_addr
;
6217 * rt2860_sysctl_attach
6219 static void rt2860_sysctl_attach(struct rt2860_softc
*sc
)
6221 struct sysctl_ctx_list
*ctx
;
6222 struct sysctl_oid
*tree
;
6223 struct sysctl_oid
*stats
;
6225 ctx
= device_get_sysctl_ctx(sc
->dev
);
6226 tree
= device_get_sysctl_tree(sc
->dev
);
6228 stats
= SYSCTL_ADD_NODE(ctx
, SYSCTL_CHILDREN(tree
), OID_AUTO
,
6229 "stats", CTLFLAG_RD
, 0, "statistic");
6231 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6232 "interrupts", CTLFLAG_RD
, &sc
->interrupts
, 0,
6235 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6236 "tx_coherent_interrupts", CTLFLAG_RD
, &sc
->tx_coherent_interrupts
, 0,
6237 "Tx coherent interrupts");
6239 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6240 "rx_coherent_interrupts", CTLFLAG_RD
, &sc
->rx_coherent_interrupts
, 0,
6241 "Rx coherent interrupts");
6243 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6244 "txrx_coherent_interrupts", CTLFLAG_RD
, &sc
->txrx_coherent_interrupts
, 0,
6245 "Tx/Rx coherent interrupts");
6247 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6248 "fifo_sta_full_interrupts", CTLFLAG_RD
, &sc
->fifo_sta_full_interrupts
, 0,
6249 "FIFO statistic full interrupts");
6251 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6252 "rx_interrupts", CTLFLAG_RD
, &sc
->rx_interrupts
, 0,
6255 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6256 "rx_delay_interrupts", CTLFLAG_RD
, &sc
->rx_delay_interrupts
, 0,
6257 "Rx delay interrupts");
6259 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6260 "tx_mgmt_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[5], 0,
6261 "Tx MGMT interrupts");
6263 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6264 "tx_hcca_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[4], 0,
6265 "Tx HCCA interrupts");
6267 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6268 "tx_ac3_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[3], 0,
6269 "Tx AC3 interrupts");
6271 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6272 "tx_ac2_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[2], 0,
6273 "Tx AC2 interrupts");
6275 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6276 "tx_ac1_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[1], 0,
6277 "Tx AC1 interrupts");
6279 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6280 "tx_ac0_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[0], 0,
6281 "Tx AC0 interrupts");
6283 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6284 "tx_delay_interrupts", CTLFLAG_RD
, &sc
->tx_delay_interrupts
, 0,
6285 "Tx delay interrupts");
6287 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6288 "pre_tbtt_interrupts", CTLFLAG_RD
, &sc
->pre_tbtt_interrupts
, 0,
6289 "Pre-TBTT interrupts");
6291 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6292 "tbtt_interrupts", CTLFLAG_RD
, &sc
->tbtt_interrupts
, 0,
6295 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6296 "mcu_cmd_interrupts", CTLFLAG_RD
, &sc
->mcu_cmd_interrupts
, 0,
6297 "MCU command interrupts");
6299 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6300 "auto_wakeup_interrupts", CTLFLAG_RD
, &sc
->auto_wakeup_interrupts
, 0,
6301 "auto wakeup interrupts");
6303 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6304 "gp_timer_interrupts", CTLFLAG_RD
, &sc
->gp_timer_interrupts
, 0,
6305 "GP timer interrupts");
6307 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6308 "tx_mgmt_desc_queued", CTLFLAG_RD
, &sc
->tx_ring
[5].desc_queued
, 0,
6309 "Tx MGMT descriptors queued");
6311 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6312 "tx_mgmt_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[5].data_queued
, 0,
6313 "Tx MGMT data queued");
6315 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6316 "tx_hcca_desc_queued", CTLFLAG_RD
, &sc
->tx_ring
[4].desc_queued
, 0,
6317 "Tx HCCA descriptors queued");
6319 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6320 "tx_hcca_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[4].data_queued
, 0,
6321 "Tx HCCA data queued");
6323 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6324 "tx_ac3_desc_queued", CTLFLAG_RD
, &sc
->tx_ring
[3].desc_queued
, 0,
6325 "Tx AC3 descriptors queued");
6327 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6328 "tx_ac3_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[3].data_queued
, 0,
6329 "Tx AC3 data queued");
6331 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6332 "tx_ac2_desc_queued", CTLFLAG_RD
, &sc
->tx_ring
[2].desc_queued
, 0,
6333 "Tx AC2 descriptors queued");
6335 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6336 "tx_ac2_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[2].data_queued
, 0,
6337 "Tx AC2 data queued");
6339 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6340 "tx_ac1_desc_queued", CTLFLAG_RD
, &sc
->tx_ring
[1].desc_queued
, 0,
6341 "Tx AC1 descriptors queued");
6343 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6344 "tx_ac1_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[1].data_queued
, 0,
6345 "Tx AC1 data queued");
6347 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6348 "tx_ac0_desc_queued", CTLFLAG_RD
, &sc
->tx_ring
[0].desc_queued
, 0,
6349 "Tx AC0 descriptors queued");
6351 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6352 "tx_ac0_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[0].data_queued
, 0,
6353 "Tx AC0 data queued");
6355 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6356 "tx_mgmt_data_queue_full", CTLFLAG_RD
, &sc
->tx_data_queue_full
[5], 0,
6357 "Tx MGMT data queue full");
6359 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6360 "tx_hcca_data_queue_full", CTLFLAG_RD
, &sc
->tx_data_queue_full
[4], 0,
6361 "Tx HCCA data queue full");
6363 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6364 "tx_ac3_data_queue_full", CTLFLAG_RD
, &sc
->tx_data_queue_full
[3], 0,
6365 "Tx AC3 data queue full");
6367 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6368 "tx_ac2_data_queue_full", CTLFLAG_RD
, &sc
->tx_data_queue_full
[2], 0,
6369 "Tx AC2 data queue full");
6371 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6372 "tx_ac1_data_queue_full", CTLFLAG_RD
, &sc
->tx_data_queue_full
[1], 0,
6373 "Tx AC1 data queue full");
6375 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6376 "tx_ac0_data_queue_full", CTLFLAG_RD
, &sc
->tx_data_queue_full
[0], 0,
6377 "Tx AC0 data queue full");
6379 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6380 "tx_watchdog_timeouts", CTLFLAG_RD
, &sc
->tx_watchdog_timeouts
, 0,
6381 "Tx watchdog timeouts");
6383 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6384 "tx_defrag_packets", CTLFLAG_RD
, &sc
->tx_defrag_packets
, 0,
6385 "Tx defragmented packets");
6387 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6388 "no_tx_desc_avail", CTLFLAG_RD
, &sc
->no_tx_desc_avail
, 0,
6389 "no Tx descriptors available");
6391 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6392 "rx_mbuf_alloc_errors", CTLFLAG_RD
, &sc
->rx_mbuf_alloc_errors
, 0,
6393 "Rx mbuf allocation errors");
6395 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6396 "rx_mbuf_dmamap_errors", CTLFLAG_RD
, &sc
->rx_mbuf_dmamap_errors
, 0,
6397 "Rx mbuf DMA mapping errors");
6399 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6400 "tx_queue_0_not_empty", CTLFLAG_RD
, &sc
->tx_queue_not_empty
[0], 0,
6401 "Tx queue 0 not empty");
6403 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6404 "tx_queue_1_not_empty", CTLFLAG_RD
, &sc
->tx_queue_not_empty
[1], 0,
6405 "Tx queue 1 not empty");
6407 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6408 "tx_beacons", CTLFLAG_RD
, &sc
->tx_beacons
, 0,
6411 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6412 "tx_noretryok", CTLFLAG_RD
, &sc
->tx_noretryok
, 0,
6413 "Tx successfull without retries");
6415 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6416 "tx_retryok", CTLFLAG_RD
, &sc
->tx_retryok
, 0,
6417 "Tx successfull with retries");
6419 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6420 "tx_failed", CTLFLAG_RD
, &sc
->tx_failed
, 0,
6423 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6424 "tx_underflows", CTLFLAG_RD
, &sc
->tx_underflows
, 0,
6427 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6428 "tx_zerolen", CTLFLAG_RD
, &sc
->tx_zerolen
, 0,
6431 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6432 "tx_nonagg", CTLFLAG_RD
, &sc
->tx_nonagg
, 0,
6433 "Tx non-aggregated");
6435 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6436 "tx_agg", CTLFLAG_RD
, &sc
->tx_agg
, 0,
6439 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6440 "tx_ampdu", CTLFLAG_RD
, &sc
->tx_ampdu
, 0,
6443 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6444 "tx_mpdu_zero_density", CTLFLAG_RD
, &sc
->tx_mpdu_zero_density
, 0,
6445 "Tx MPDU with zero density");
6447 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6448 "rx_packets", CTLFLAG_RD
, &sc
->rx_packets
, 0,
6451 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6452 "rx_ampdu", CTLFLAG_RD
, &sc
->rx_ampdu
, 0,
6455 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6456 "rx_mpdu_zero_density", CTLFLAG_RD
, &sc
->rx_mpdu_zero_density
, 0,
6457 "Rx MPDU with zero density");
6459 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6460 "rx_amsdu", CTLFLAG_RD
, &sc
->rx_amsdu
, 0,
6463 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6464 "rx_crc_errors", CTLFLAG_RD
, &sc
->rx_crc_errors
, 0,
6467 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6468 "rx_phy_errors", CTLFLAG_RD
, &sc
->rx_phy_errors
, 0,
6471 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6472 "rx_false_ccas", CTLFLAG_RD
, &sc
->rx_false_ccas
, 0,
6475 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6476 "rx_plcp_errors", CTLFLAG_RD
, &sc
->rx_plcp_errors
, 0,
6479 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6480 "rx_dup_packets", CTLFLAG_RD
, &sc
->rx_dup_packets
, 0,
6481 "Rx duplicate packets");
6483 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6484 "rx_fifo_overflows", CTLFLAG_RD
, &sc
->rx_fifo_overflows
, 0,
6485 "Rx FIFO overflows");
6488 static device_method_t rt2860_dev_methods
[] =
6490 DEVMETHOD(device_probe
, rt2860_probe
),
6491 DEVMETHOD(device_attach
, rt2860_attach
),
6492 DEVMETHOD(device_detach
, rt2860_detach
),
6493 DEVMETHOD(device_shutdown
, rt2860_shutdown
),
6494 DEVMETHOD(device_suspend
, rt2860_suspend
),
6495 DEVMETHOD(device_resume
, rt2860_resume
),
6499 static driver_t rt2860_driver
=
6503 sizeof(struct rt2860_softc
)
6506 static devclass_t rt2860_dev_class
;
6508 DRIVER_MODULE(rt2860
, pci
, rt2860_driver
, rt2860_dev_class
, 0, 0);
6510 MODULE_DEPEND(rt2860
, pci
, 1, 1, 1);
6511 MODULE_DEPEND(rt2860
, wlan
, 1, 1, 1);