3 * Copyright (c) 2009-2010 Alexander Egorenkov <egorenar@gmail.com>
4 * Copyright (c) 2009 Damien Bergamini <damien.bergamini@free.fr>
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 #include "rt2860_softc.h"
20 #include "rt2860_reg.h"
21 #include "rt2860_eeprom.h"
22 #include "rt2860_ucode.h"
23 #include "rt2860_txwi.h"
24 #include "rt2860_rxwi.h"
25 #include "rt2860_io.h"
26 #include "rt2860_read_eeprom.h"
27 #include "rt2860_led.h"
28 #include "rt2860_rf.h"
29 #include "rt2860_debug.h"
35 #define PCI_VENDOR_RALINK 0x1814
36 #define PCI_PRODUCT_RALINK_RT2860_PCI 0x0601
37 #define PCI_PRODUCT_RALINK_RT2860_PCIe 0x0681
38 #define PCI_PRODUCT_RALINK_RT2760_PCI 0x0701
39 #define PCI_PRODUCT_RALINK_RT2790_PCIe 0x0781
41 #define RT2860_MAX_AGG_SIZE 3840
43 #define RT2860_TX_DATA_SEG0_SIZE \
44 (sizeof(struct rt2860_txwi) + sizeof(struct ieee80211_qosframe_addr4))
46 #define RT2860_NOISE_FLOOR -95
48 #define RT2860_AID2WCID(aid) ((aid) & 0xff)
50 #define RT2860_RATE_IS_OFDM(rate) ((rate) >= 12 && (rate) != 22)
52 #define RT2860_ACK_SIZE 14
54 #define IEEE80211_HAS_ADDR4(wh) \
55 (((wh)->i_fc[1] & IEEE80211_FC1_DIR_MASK) == IEEE80211_FC1_DIR_DSTODS)
57 #define RT2860_MS(_v, _f) (((_v) & _f) >> _f##_S)
58 #define RT2860_SM(_v, _f) (((_v) << _f##_S) & _f)
60 #define RT2860_TX_WATCHDOG_TIMEOUT 5
63 * Data structures and types
66 struct rt2860_pci_ident
74 * Static function prototypes
77 static int rt2860_probe(device_t dev
);
79 static int rt2860_attach(device_t dev
);
81 static int rt2860_detach(device_t dev
);
83 static int rt2860_shutdown(device_t dev
);
85 static int rt2860_suspend(device_t dev
);
87 static int rt2860_resume(device_t dev
);
89 static void rt2860_init_channels(struct rt2860_softc
*sc
);
91 static void rt2860_init_channels_ht40(struct rt2860_softc
*sc
);
93 static void rt2860_init_locked(void *priv
);
95 static void rt2860_init(void *priv
);
97 static int rt2860_init_bbp(struct rt2860_softc
*sc
);
99 static void rt2860_stop_locked(void *priv
);
101 static void rt2860_stop(void *priv
);
103 static void rt2860_start(struct ifnet
*ifp
);
105 static int rt2860_ioctl(struct ifnet
*ifp
, u_long cmd
, caddr_t data
);
107 static int rt2860_reset(struct ifnet
*ifp
);
109 static int rt2860_newstate(struct ieee80211com
*ic
,
110 enum ieee80211_state nstate
, int arg
);
112 static void rt2860_scan_start(struct ieee80211com
*ic
);
114 static void rt2860_scan_end(struct ieee80211com
*ic
);
116 static void rt2860_set_channel(struct ieee80211com
*ic
);
118 static void rt2860_newassoc(struct ieee80211_node
*ni
, int isnew
);
120 static void rt2860_updateslot(struct ifnet
*ifp
);
122 static int rt2860_wme_update(struct ieee80211com
*ic
);
124 static void rt2860_update_beacon(struct ieee80211com
*ic
, int what
);
126 static void rt2860_key_update_begin(struct ieee80211com
*ic
);
128 static void rt2860_key_update_end(struct ieee80211com
*ic
);
130 static int rt2860_key_set(struct ieee80211com
*ic
,
131 const struct ieee80211_key
*k
, const uint8_t mac
[IEEE80211_ADDR_LEN
]);
133 static int rt2860_key_delete(struct ieee80211com
*ic
,
134 const struct ieee80211_key
*k
);
136 static int rt2860_raw_xmit(struct ieee80211_node
*ni
, struct mbuf
*m
,
137 const struct ieee80211_bpf_params
*params
);
139 static int rt2860_media_change(struct ifnet
*ifp
);
141 static void rt2860_recv_action(struct ieee80211_node
*ni
,
142 const uint8_t *frm
, const uint8_t *efrm
);
144 static int rt2860_send_action(struct ieee80211_node
*ni
,
145 int category
, int action
, uint16_t args
[4]);
147 static void rt2860_amrr_update_iter_func(void *arg
, struct ieee80211_node
*ni
);
149 static void rt2860_periodic(void *arg
);
151 static void rt2860_tx_watchdog(void *arg
);
153 static void rt2860_asic_set_bssid(struct rt2860_softc
*sc
,
154 const uint8_t *bssid
);
156 static void rt2860_asic_set_macaddr(struct rt2860_softc
*sc
,
157 const uint8_t *addr
);
159 static void rt2860_asic_enable_tsf_sync(struct rt2860_softc
*sc
);
161 static void rt2860_asic_disable_tsf_sync(struct rt2860_softc
*sc
);
163 static void rt2860_asic_enable_mrr(struct rt2860_softc
*sc
);
165 static void rt2860_asic_set_txpreamble(struct rt2860_softc
*sc
);
167 static void rt2860_asic_set_basicrates(struct rt2860_softc
*sc
);
169 static void rt2860_asic_update_rtsthreshold(struct rt2860_softc
*sc
);
171 static void rt2860_asic_update_txpower(struct rt2860_softc
*sc
);
173 static void rt2860_asic_update_promisc(struct rt2860_softc
*sc
);
175 static void rt2860_asic_updateprot(struct rt2860_softc
*sc
);
177 static void rt2860_asic_updateslot(struct rt2860_softc
*sc
);
179 static void rt2860_asic_wme_update(struct rt2860_softc
*sc
);
181 static int rt2860_asic_update_beacon(struct rt2860_softc
*sc
);
183 static void rt2860_asic_clear_keytables(struct rt2860_softc
*sc
);
185 static uint8_t rt2860_rxrate(struct rt2860_rxwi
*rxwi
);
187 static uint8_t rt2860_maxrssi_rxpath(struct rt2860_softc
*sc
,
188 const struct rt2860_rxwi
*rxwi
);
190 static int8_t rt2860_rssi2dbm(struct rt2860_softc
*sc
,
191 uint8_t rssi
, uint8_t rxpath
);
193 static uint8_t rt2860_rate2mcs(uint8_t rate
);
195 static int rt2860_ackrate(struct ieee80211com
*ic
, int rate
);
197 static uint16_t rt2860_txtime(int len
, int rate
, uint32_t flags
);
199 static int rt2860_tx_frame(struct rt2860_softc
*sc
,
200 struct mbuf
*m
, struct ieee80211_node
*ni
, int qid
);
202 static int rt2860_tx_raw(struct rt2860_softc
*sc
,
203 struct mbuf
*m
, struct ieee80211_node
*ni
,
204 const struct ieee80211_bpf_params
*params
);
206 static void rt2860_intr(void *arg
);
208 static void rt2860_tx_coherent_intr(struct rt2860_softc
*sc
);
210 static void rt2860_rx_coherent_intr(struct rt2860_softc
*sc
);
212 static void rt2860_txrx_coherent_intr(struct rt2860_softc
*sc
);
214 static void rt2860_fifo_sta_full_intr(struct rt2860_softc
*sc
);
216 static void rt2860_rx_intr(struct rt2860_softc
*sc
);
218 static void rt2860_rx_delay_intr(struct rt2860_softc
*sc
);
220 static void rt2860_tx_intr(struct rt2860_softc
*sc
, int qid
);
222 static void rt2860_tx_delay_intr(struct rt2860_softc
*sc
);
224 static void rt2860_pre_tbtt_intr(struct rt2860_softc
*sc
);
226 static void rt2860_tbtt_intr(struct rt2860_softc
*sc
);
228 static void rt2860_mcu_cmd_intr(struct rt2860_softc
*sc
);
230 static void rt2860_auto_wakeup_intr(struct rt2860_softc
*sc
);
232 static void rt2860_gp_timer_intr(struct rt2860_softc
*sc
);
234 static void rt2860_rx_done_task(void *context
, int pending
);
236 static void rt2860_tx_done_task(void *context
, int pending
);
238 static void rt2860_fifo_sta_full_task(void *context
, int pending
);
240 static void rt2860_periodic_task(void *context
, int pending
);
242 static int rt2860_rx_eof(struct rt2860_softc
*sc
, int limit
);
244 static void rt2860_tx_eof(struct rt2860_softc
*sc
,
245 struct rt2860_softc_tx_ring
*ring
);
247 static void rt2860_update_stats(struct rt2860_softc
*sc
);
249 static void rt2860_bbp_tuning(struct rt2860_softc
*sc
);
251 static void rt2860_watchdog(struct rt2860_softc
*sc
);
253 static void rt2860_drain_fifo_stats(struct rt2860_softc
*sc
);
255 static void rt2860_update_raw_counters(struct rt2860_softc
*sc
);
257 static void rt2860_intr_enable(struct rt2860_softc
*sc
, uint32_t intr_mask
);
259 static void rt2860_intr_disable(struct rt2860_softc
*sc
, uint32_t intr_mask
);
261 static int rt2860_txrx_enable(struct rt2860_softc
*sc
);
263 static int rt2860_alloc_rx_ring(struct rt2860_softc
*sc
,
264 struct rt2860_softc_rx_ring
*ring
);
266 static void rt2860_reset_rx_ring(struct rt2860_softc
*sc
,
267 struct rt2860_softc_rx_ring
*ring
);
269 static void rt2860_free_rx_ring(struct rt2860_softc
*sc
,
270 struct rt2860_softc_rx_ring
*ring
);
272 static int rt2860_alloc_tx_ring(struct rt2860_softc
*sc
,
273 struct rt2860_softc_tx_ring
*ring
, int qid
);
275 static void rt2860_reset_tx_ring(struct rt2860_softc
*sc
,
276 struct rt2860_softc_tx_ring
*ring
);
278 static void rt2860_free_tx_ring(struct rt2860_softc
*sc
,
279 struct rt2860_softc_tx_ring
*ring
);
281 static void rt2860_dma_map_addr(void *arg
, bus_dma_segment_t
*segs
,
282 int nseg
, int error
);
284 static void rt2860_sysctl_attach(struct rt2860_softc
*sc
);
290 static const struct rt2860_pci_ident rt2860_pci_ids
[] =
292 { PCI_VENDOR_RALINK
, PCI_PRODUCT_RALINK_RT2860_PCI
, "Ralink RT2860 PCI" },
293 { PCI_VENDOR_RALINK
, PCI_PRODUCT_RALINK_RT2860_PCIe
, "Ralink RT2860 PCIe" },
294 { PCI_VENDOR_RALINK
, PCI_PRODUCT_RALINK_RT2760_PCI
, "Ralink RT2760 PCI" },
295 { PCI_VENDOR_RALINK
, PCI_PRODUCT_RALINK_RT2790_PCIe
, "Ralink RT2790 PCIe" },
305 { RT2860_REG_PBF_BCN_OFFSET0
, 0xf8f0e8e0 },
306 { RT2860_REG_PBF_BCN_OFFSET1
, 0x6f77d0c8 },
307 { RT2860_REG_LEGACY_BASIC_RATE
, 0x0000013f },
308 { RT2860_REG_HT_BASIC_RATE
, 0x00008003 },
309 { RT2860_REG_SYS_CTRL
, 0x00000000 },
310 { RT2860_REG_RX_FILTER_CFG
, 0x00017f97 },
311 { RT2860_REG_BKOFF_SLOT_CFG
, 0x00000209 },
312 { RT2860_REG_TX_SW_CFG0
, 0x00000000 },
313 { RT2860_REG_TX_SW_CFG1
, 0x00080606 },
314 { RT2860_REG_TX_LINK_CFG
, 0x00001020 },
315 { RT2860_REG_TX_TIMEOUT_CFG
, 0x000a2090 },
316 { RT2860_REG_MAX_LEN_CFG
, (1 << 12) | RT2860_MAX_AGG_SIZE
},
317 { RT2860_REG_LED_CFG
, 0x7f031e46 },
318 { RT2860_REG_PBF_MAX_PCNT
, 0x1f3fbf9f },
319 { RT2860_REG_TX_RTY_CFG
, 0x47d01f0f },
320 { RT2860_REG_AUTO_RSP_CFG
, 0x00000013 },
321 { RT2860_REG_TX_CCK_PROT_CFG
, 0x05740003 },
322 { RT2860_REG_TX_OFDM_PROT_CFG
, 0x05740003 },
323 { RT2860_REG_TX_MM40_PROT_CFG
, 0x03f44084 },
324 { RT2860_REG_SCHDMA_WPDMA_GLO_CFG
, 0x00000030 },
325 { RT2860_REG_TX_GF20_PROT_CFG
, 0x01744004 },
326 { RT2860_REG_TX_GF40_PROT_CFG
, 0x03f44084 },
327 { RT2860_REG_TX_MM20_PROT_CFG
, 0x01744004 },
328 { RT2860_REG_TX_MM40_PROT_CFG
, 0x03f54084 },
329 { RT2860_REG_TX_TXOP_CTRL_CFG
, 0x0000583f },
330 { RT2860_REG_TX_RTS_CFG
, 0x00092b20 },
331 { RT2860_REG_TX_EXP_ACK_TIME
, 0x002400ca },
332 { RT2860_REG_HCCAPSMP_TXOP_HLDR_ET
, 0x00000002 },
333 { RT2860_REG_XIFS_TIME_CFG
, 0x33a41010 },
334 { RT2860_REG_PWR_PIN_CFG
, 0x00000003 },
335 { RT2860_REG_SCHDMA_WMM_AIFSN_CFG
, 0x00002273 },
336 { RT2860_REG_SCHDMA_WMM_CWMIN_CFG
, 0x00002344 },
337 { RT2860_REG_SCHDMA_WMM_CWMAX_CFG
, 0x000034aa },
340 #define RT2860_DEF_MAC_SIZE (sizeof(rt2860_def_mac) / sizeof(rt2860_def_mac[0]))
365 #define RT2860_DEF_BBP_SIZE (sizeof(rt2860_def_bbp) / sizeof(rt2860_def_bbp[0]))
367 SYSCTL_NODE(_hw
, OID_AUTO
, rt2860
, CTLFLAG_RD
, 0, "RT2860 driver parameters");
370 static int rt2860_debug
= 0;
371 SYSCTL_INT(_hw_rt2860
, OID_AUTO
, debug
, CTLFLAG_RW
, &rt2860_debug
, 0, "rt2860 debug level");
372 TUNABLE_INT("hw.rt2860.debug", &rt2860_debug
);
378 static int rt2860_probe(device_t dev
)
380 const struct rt2860_pci_ident
*ident
;
382 for (ident
= rt2860_pci_ids
; ident
->name
!= NULL
; ident
++)
384 if (pci_get_vendor(dev
) == ident
->vendor
&&
385 pci_get_device(dev
) == ident
->device
)
387 device_set_desc(dev
, ident
->name
);
398 static int rt2860_attach(device_t dev
)
400 struct rt2860_softc
*sc
;
402 struct ieee80211com
*ic
;
403 int error
, ntries
, i
;
405 sc
= device_get_softc(dev
);
407 if (pci_get_powerstate(dev
) != PCI_POWERSTATE_D0
)
409 printf("%s: chip is in D%d power mode, setting to D0\n",
410 device_get_nameunit(dev
), pci_get_powerstate(dev
));
411 pci_set_powerstate(dev
, PCI_POWERSTATE_D0
);
414 /* enable bus-mastering */
416 pci_enable_busmaster(dev
);
420 mtx_init(&sc
->lock
, device_get_nameunit(dev
),
421 MTX_NETWORK_LOCK
, MTX_DEF
| MTX_RECURSE
);
423 sc
->mem_rid
= PCIR_BAR(0);
424 sc
->mem
= bus_alloc_resource_any(dev
, SYS_RES_MEMORY
,
425 &sc
->mem_rid
, RF_ACTIVE
);
428 printf("%s: could not allocate memory resource\n",
429 device_get_nameunit(dev
));
434 sc
->bst
= rman_get_bustag(sc
->mem
);
435 sc
->bsh
= rman_get_bushandle(sc
->mem
);
438 sc
->irq
= bus_alloc_resource_any(dev
, SYS_RES_IRQ
,
439 &sc
->irq_rid
, RF_ACTIVE
| RF_SHAREABLE
);
442 printf("%s: could not allocate interrupt resource\n",
443 device_get_nameunit(dev
));
449 sc
->debug
= rt2860_debug
;
451 SYSCTL_ADD_INT(device_get_sysctl_ctx(dev
),
452 SYSCTL_CHILDREN(device_get_sysctl_tree(dev
)), OID_AUTO
,
453 "debug", CTLFLAG_RW
, &sc
->debug
, 0, "rt2860 debug level");
456 RT2860_DPRINTF(sc
, RT2860_DEBUG_ANY
,
458 device_get_nameunit(sc
->dev
));
460 /* wait for NIC to initialize */
462 for (ntries
= 0; ntries
< 100; ntries
++)
464 sc
->mac_rev
= rt2860_io_mac_read(sc
, RT2860_REG_MAC_CSR0
);
465 if (sc
->mac_rev
!= 0x00000000 && sc
->mac_rev
!= 0xffffffff)
473 printf("%s: timeout waiting for NIC to initialize\n",
474 device_get_nameunit(dev
));
479 rt2860_read_eeprom(sc
);
481 printf("%s: MAC/BBP RT2860 (rev 0x%08x), RF %s\n",
482 device_get_nameunit(sc
->dev
), sc
->mac_rev
,
483 rt2860_rf_name(sc
->rf_rev
));
485 /* allocate Tx and Rx rings */
487 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
489 error
= rt2860_alloc_tx_ring(sc
, &sc
->tx_ring
[i
], i
);
492 printf("%s: could not allocate Tx ring #%d\n",
493 device_get_nameunit(sc
->dev
), i
);
498 sc
->tx_ring_mgtqid
= 5;
500 error
= rt2860_alloc_rx_ring(sc
, &sc
->rx_ring
);
503 printf("%s: could not allocate Rx ring\n",
504 device_get_nameunit(sc
->dev
));
508 callout_init(&sc
->periodic_ch
, 0);
509 callout_init_mtx(&sc
->tx_watchdog_ch
, &sc
->lock
, 0);
511 ifp
= sc
->ifp
= if_alloc(IFT_ETHER
);
514 printf("%s: could not if_alloc()\n",
515 device_get_nameunit(sc
->dev
));
522 if_initname(ifp
, "rt2860", device_get_unit(sc
->dev
));
524 ifp
->if_flags
= IFF_BROADCAST
| IFF_SIMPLEX
| IFF_MULTICAST
;
526 ifp
->if_init
= rt2860_init
;
527 ifp
->if_ioctl
= rt2860_ioctl
;
528 ifp
->if_start
= rt2860_start
;
530 IFQ_SET_MAXLEN(&ifp
->if_snd
, IFQ_MAXLEN
);
531 ifp
->if_snd
.ifq_drv_maxlen
= IFQ_MAXLEN
;
532 IFQ_SET_READY(&ifp
->if_snd
);
538 ic
->ic_phytype
= IEEE80211_T_HT
;
539 ic
->ic_opmode
= IEEE80211_M_STA
;
540 ic
->ic_state
= IEEE80211_S_INIT
;
542 ic
->ic_caps
= IEEE80211_C_MONITOR
|
547 /* IEEE80211_C_BGSCAN | */
549 IEEE80211_C_SHPREAMBLE
|
556 IEEE80211_C_AES_CCM
|
559 ic
->ic_htcaps
= IEEE80211_HTC_HT
|
560 IEEE80211_HTC_AMSDU
| /* A-MSDU Tx */
561 IEEE80211_HTC_AMPDU
| /* A-MPDU Tx */
562 IEEE80211_HTCAP_MAXAMSDU_3839
| /* max. A-MSDU Rx length */
563 IEEE80211_HTCAP_CHWIDTH40
| /* HT 40MHz channel width */
564 IEEE80211_HTCAP_GREENFIELD
| /* HT greenfield */
565 IEEE80211_HTCAP_SHORTGI20
| /* HT 20MHz short GI */
566 IEEE80211_HTCAP_SHORTGI40
| /* HT 40MHz short GI */
567 IEEE80211_HTCAP_DSSSCCK40
; /* HT 40MHz DSSS/CCK modulation */
569 /* spatial streams */
571 if (sc
->nrxpath
== 2)
572 ic
->ic_htcaps
|= IEEE80211_HTCAP_RXSTBC_2STREAM
;
573 else if (sc
->nrxpath
== 3)
574 ic
->ic_htcaps
|= IEEE80211_HTCAP_RXSTBC_3STREAM
;
576 ic
->ic_htcaps
|= IEEE80211_HTCAP_RXSTBC_1STREAM
;
579 ic
->ic_htcaps
|= IEEE80211_HTCAP_TXSTBC
;
583 if (sc
->mac_rev
!= 0x28600100)
584 ic
->ic_htcaps
|= IEEE80211_HTCAP_DELBA
;
589 ic
->ic_regdomain
= 0;
590 ic
->ic_countrycode
= CTRY_DEFAULT
;
593 rt2860_init_channels(sc
);
595 rt2860_init_channels_ht40(sc
);
597 IEEE80211_ADDR_COPY(ic
->ic_myaddr
, sc
->mac_addr
);
599 ieee80211_ifattach(ic
);
601 sc
->newstate
= ic
->ic_newstate
;
602 ic
->ic_newstate
= rt2860_newstate
;
604 ic
->ic_reset
= rt2860_reset
;
605 ic
->ic_scan_start
= rt2860_scan_start
;
606 ic
->ic_scan_end
= rt2860_scan_end
;
607 ic
->ic_set_channel
= rt2860_set_channel
;
608 ic
->ic_newassoc
= rt2860_newassoc
;
609 ic
->ic_updateslot
= rt2860_updateslot
;
610 ic
->ic_wme
.wme_update
= rt2860_wme_update
;
611 ic
->ic_update_beacon
= rt2860_update_beacon
;
612 ic
->ic_crypto
.cs_key_update_begin
= rt2860_key_update_begin
;
613 ic
->ic_crypto
.cs_key_update_end
= rt2860_key_update_end
;
614 ic
->ic_crypto
.cs_key_set
= rt2860_key_set
;
615 ic
->ic_crypto
.cs_key_delete
= rt2860_key_delete
;
616 ic
->ic_raw_xmit
= rt2860_raw_xmit
;
618 sc
->recv_action
= ic
->ic_recv_action
;
619 ic
->ic_recv_action
= rt2860_recv_action
;
621 sc
->send_action
= ic
->ic_send_action
;
622 ic
->ic_send_action
= rt2860_send_action
;
624 /* override Rx A-MPDU factor */
626 ic
->ic_ampdu_rxmax
= IEEE80211_HTCAP_MAXRXAMPDU_32K
;
627 ic
->ic_ampdu_density
= IEEE80211_HTCAP_MPDUDENSITY_NA
;
628 ic
->ic_ampdu_limit
= ic
->ic_ampdu_rxmax
;
630 /* hardware requires padding between 802.11 frame header and body */
632 ic
->ic_flags
|= IEEE80211_F_WME
| IEEE80211_F_DATAPAD
| IEEE80211_F_DOTH
;
634 ic
->ic_flags_ext
|= IEEE80211_FEXT_SWBMISS
;
636 ieee80211_media_init(ic
, rt2860_media_change
, ieee80211_media_status
);
638 rt2860_amrr_init(&sc
->amrr
, ic
,
640 RT2860_AMRR_MIN_SUCCESS_THRESHOLD
,
641 RT2860_AMRR_MAX_SUCCESS_THRESHOLD
,
644 bpfattach2(ifp
, DLT_IEEE802_11_RADIO
,
645 sizeof(struct ieee80211_frame
) + IEEE80211_RADIOTAP_HDRLEN
,
648 sc
->rxtap_len
= sizeof(sc
->rxtapu
);
649 sc
->rxtap
.ihdr
.it_len
= htole16(sc
->rxtap_len
);
650 sc
->rxtap
.ihdr
.it_present
= htole32(RT2860_SOFTC_RX_RADIOTAP_PRESENT
);
652 sc
->txtap_len
= sizeof(sc
->txtapu
);
653 sc
->txtap
.ihdr
.it_len
= htole16(sc
->txtap_len
);
654 sc
->txtap
.ihdr
.it_present
= htole32(RT2860_SOFTC_TX_RADIOTAP_PRESENT
);
656 /* init task queue */
658 TASK_INIT(&sc
->rx_done_task
, 0, rt2860_rx_done_task
, sc
);
659 TASK_INIT(&sc
->tx_done_task
, 0, rt2860_tx_done_task
, sc
);
660 TASK_INIT(&sc
->fifo_sta_full_task
, 0, rt2860_fifo_sta_full_task
, sc
);
661 TASK_INIT(&sc
->periodic_task
, 0, rt2860_periodic_task
, sc
);
663 sc
->rx_process_limit
= 100;
665 sc
->taskqueue
= taskqueue_create("rt2860_taskq", M_NOWAIT
,
666 taskqueue_thread_enqueue
, &sc
->taskqueue
);
668 taskqueue_start_threads(&sc
->taskqueue
, 1, PI_NET
, "%s taskq",
669 device_get_nameunit(sc
->dev
));
671 rt2860_sysctl_attach(sc
);
674 ieee80211_announce(ic
);
676 /* set up interrupt */
678 error
= bus_setup_intr(dev
, sc
->irq
, INTR_TYPE_NET
| INTR_MPSAFE
,
679 NULL
, rt2860_intr
, sc
, &sc
->irqh
);
682 printf("%s: could not set up interrupt\n",
683 device_get_nameunit(dev
));
691 /* free Tx and Rx rings */
693 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
694 rt2860_free_tx_ring(sc
, &sc
->tx_ring
[i
]);
696 rt2860_free_rx_ring(sc
, &sc
->rx_ring
);
698 mtx_destroy(&sc
->lock
);
701 bus_release_resource(dev
, SYS_RES_MEMORY
, sc
->mem_rid
, sc
->mem
);
704 bus_release_resource(dev
, SYS_RES_IRQ
, sc
->irq_rid
, sc
->irq
);
712 static int rt2860_detach(device_t dev
)
714 struct rt2860_softc
*sc
;
715 struct ieee80211com
*ic
;
719 sc
= device_get_softc(dev
);
723 RT2860_DPRINTF(sc
, RT2860_DEBUG_ANY
,
725 device_get_nameunit(sc
->dev
));
727 RT2860_SOFTC_LOCK(sc
);
729 ifp
->if_drv_flags
&= ~(IFF_DRV_RUNNING
| IFF_DRV_OACTIVE
);
731 ieee80211_new_state(ic
, IEEE80211_S_INIT
, -1);
733 callout_stop(&sc
->periodic_ch
);
734 callout_stop(&sc
->tx_watchdog_ch
);
736 taskqueue_drain(sc
->taskqueue
, &sc
->rx_done_task
);
737 taskqueue_drain(sc
->taskqueue
, &sc
->tx_done_task
);
738 taskqueue_drain(sc
->taskqueue
, &sc
->fifo_sta_full_task
);
739 taskqueue_drain(sc
->taskqueue
, &sc
->periodic_task
);
741 /* free Tx and Rx rings */
743 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
744 rt2860_free_tx_ring(sc
, &sc
->tx_ring
[i
]);
746 rt2860_free_rx_ring(sc
, &sc
->rx_ring
);
748 RT2860_SOFTC_UNLOCK(sc
);
752 ieee80211_ifdetach(ic
);
756 taskqueue_free(sc
->taskqueue
);
758 mtx_destroy(&sc
->lock
);
760 bus_generic_detach(dev
);
762 bus_teardown_intr(dev
, sc
->irq
, sc
->irqh
);
764 bus_release_resource(dev
, SYS_RES_IRQ
, sc
->irq_rid
, sc
->irq
);
766 bus_release_resource(dev
, SYS_RES_MEMORY
, sc
->mem_rid
, sc
->mem
);
774 static int rt2860_shutdown(device_t dev
)
776 struct rt2860_softc
*sc
;
778 sc
= device_get_softc(dev
);
780 RT2860_DPRINTF(sc
, RT2860_DEBUG_ANY
,
781 "%s: shutting down\n",
782 device_get_nameunit(sc
->dev
));
786 sc
->flags
&= ~RT2860_SOFTC_FLAGS_UCODE_LOADED
;
794 static int rt2860_suspend(device_t dev
)
796 struct rt2860_softc
*sc
;
798 sc
= device_get_softc(dev
);
800 RT2860_DPRINTF(sc
, RT2860_DEBUG_ANY
,
802 device_get_nameunit(sc
->dev
));
806 sc
->flags
&= ~RT2860_SOFTC_FLAGS_UCODE_LOADED
;
814 static int rt2860_resume(device_t dev
)
816 struct rt2860_softc
*sc
;
819 sc
= device_get_softc(dev
);
822 RT2860_DPRINTF(sc
, RT2860_DEBUG_ANY
,
824 device_get_nameunit(sc
->dev
));
826 if (ifp
->if_flags
& IFF_UP
)
833 * rt2860_init_channels
835 static void rt2860_init_channels(struct rt2860_softc
*sc
)
837 struct ieee80211com
*ic
;
838 struct ieee80211_channel
*c
;
843 /* set supported channels for 2GHz band */
845 for (i
= 1; i
<= 14; i
++)
847 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
848 flags
= IEEE80211_CHAN_B
;
850 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
854 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
855 flags
= IEEE80211_CHAN_B
| IEEE80211_CHAN_HT20
;
857 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
861 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
862 flags
= IEEE80211_CHAN_G
;
864 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
868 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
869 flags
= IEEE80211_CHAN_G
| IEEE80211_CHAN_HT20
;
871 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
876 /* set supported channels for 5GHz band */
878 if (sc
->rf_rev
== RT2860_EEPROM_RF_2850
||
879 sc
->rf_rev
== RT2860_EEPROM_RF_2750
)
881 for (i
= 36; i
<= 64; i
+= 4)
883 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
884 flags
= IEEE80211_CHAN_A
;
886 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
890 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
891 flags
= IEEE80211_CHAN_A
| IEEE80211_CHAN_HT20
;
893 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
898 for (i
= 100; i
<= 140; i
+= 4)
900 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
901 flags
= IEEE80211_CHAN_A
;
903 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
907 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
908 flags
= IEEE80211_CHAN_A
| IEEE80211_CHAN_HT20
;
910 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
915 for (i
= 149; i
<= 165; i
+= 4)
917 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
918 flags
= IEEE80211_CHAN_A
;
920 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
924 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
925 flags
= IEEE80211_CHAN_A
| IEEE80211_CHAN_HT20
;
927 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
935 * rt2860_init_channels_ht40
937 static void rt2860_init_channels_ht40(struct rt2860_softc
*sc
)
939 struct ieee80211com
*ic
;
940 struct ieee80211_channel
*c
, *cent
, *ext
;
945 /* set supported channels for 2GHz band */
947 for (i
= 1; i
<= 14; i
++)
949 flags
= IEEE80211_CHAN_G
| IEEE80211_CHAN_HT40
;
951 /* find the center channel */
953 cent
= ieee80211_find_channel_byieee(ic
, i
,
954 flags
& ~IEEE80211_CHAN_HT
);
957 printf("%s: skip channel %d, could not find center channel\n",
958 device_get_nameunit(sc
->dev
), i
);
962 /* find the extension channel */
964 ext
= ieee80211_find_channel(ic
, cent
->ic_freq
+ 20,
965 flags
& ~IEEE80211_CHAN_HT
);
968 printf("%s: skip channel %d, could not find extension channel\n",
969 device_get_nameunit(sc
->dev
), i
);
973 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
976 c
->ic_extieee
= ext
->ic_ieee
;
977 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
978 c
->ic_flags
|= IEEE80211_CHAN_HT40U
;
980 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
983 c
->ic_extieee
= cent
->ic_ieee
;
984 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
985 c
->ic_flags
|= IEEE80211_CHAN_HT40D
;
988 /* set supported channels for 5GHz band */
990 if (sc
->rf_rev
== RT2860_EEPROM_RF_2850
||
991 sc
->rf_rev
== RT2860_EEPROM_RF_2750
)
993 for (i
= 36; i
<= 64; i
+= 4)
995 flags
= IEEE80211_CHAN_A
| IEEE80211_CHAN_HT40
;
997 /* find the center channel */
999 cent
= ieee80211_find_channel_byieee(ic
, i
,
1000 flags
& ~IEEE80211_CHAN_HT
);
1003 printf("%s: skip channel %d, could not find center channel\n",
1004 device_get_nameunit(sc
->dev
), i
);
1008 /* find the extension channel */
1010 ext
= ieee80211_find_channel(ic
, cent
->ic_freq
+ 20,
1011 flags
& ~IEEE80211_CHAN_HT
);
1014 printf("%s: skip channel %d, could not find extension channel\n",
1015 device_get_nameunit(sc
->dev
), i
);
1019 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1022 c
->ic_extieee
= ext
->ic_ieee
;
1023 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1024 c
->ic_flags
|= IEEE80211_CHAN_HT40U
;
1026 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1029 c
->ic_extieee
= cent
->ic_ieee
;
1030 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1031 c
->ic_flags
|= IEEE80211_CHAN_HT40D
;
1034 for (i
= 100; i
<= 140; i
+= 4)
1036 flags
= IEEE80211_CHAN_A
| IEEE80211_CHAN_HT40
;
1038 /* find the center channel */
1040 cent
= ieee80211_find_channel_byieee(ic
, i
,
1041 flags
& ~IEEE80211_CHAN_HT
);
1044 printf("%s: skip channel %d, could not find center channel\n",
1045 device_get_nameunit(sc
->dev
), i
);
1049 /* find the extension channel */
1051 ext
= ieee80211_find_channel(ic
, cent
->ic_freq
+ 20,
1052 flags
& ~IEEE80211_CHAN_HT
);
1055 printf("%s: skip channel %d, could not find extension channel\n",
1056 device_get_nameunit(sc
->dev
), i
);
1060 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1063 c
->ic_extieee
= ext
->ic_ieee
;
1064 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1065 c
->ic_flags
|= IEEE80211_CHAN_HT40U
;
1067 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1070 c
->ic_extieee
= cent
->ic_ieee
;
1071 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1072 c
->ic_flags
|= IEEE80211_CHAN_HT40D
;
1075 for (i
= 149; i
<= 165; i
+= 4)
1077 flags
= IEEE80211_CHAN_A
| IEEE80211_CHAN_HT40
;
1079 /* find the center channel */
1081 cent
= ieee80211_find_channel_byieee(ic
, i
,
1082 flags
& ~IEEE80211_CHAN_HT
);
1085 printf("%s: skip channel %d, could not find center channel\n",
1086 device_get_nameunit(sc
->dev
), i
);
1090 /* find the extension channel */
1092 ext
= ieee80211_find_channel(ic
, cent
->ic_freq
+ 20,
1093 flags
& ~IEEE80211_CHAN_HT
);
1096 printf("%s: skip channel %d, could not find extension channel\n",
1097 device_get_nameunit(sc
->dev
), i
);
1101 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1104 c
->ic_extieee
= ext
->ic_ieee
;
1105 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1106 c
->ic_flags
|= IEEE80211_CHAN_HT40U
;
1108 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1111 c
->ic_extieee
= cent
->ic_ieee
;
1112 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1113 c
->ic_flags
|= IEEE80211_CHAN_HT40D
;
1119 * rt2860_init_locked
1121 static void rt2860_init_locked(void *priv
)
1123 struct rt2860_softc
*sc
;
1124 struct ieee80211com
*ic
;
1126 int error
, i
, ntries
;
1127 uint32_t tmp
, stacnt
[6];
1133 RT2860_DPRINTF(sc
, RT2860_DEBUG_ANY
,
1134 "%s: initializing\n",
1135 device_get_nameunit(sc
->dev
));
1137 RT2860_SOFTC_ASSERT_LOCKED(sc
);
1139 if (!(sc
->flags
& RT2860_SOFTC_FLAGS_UCODE_LOADED
))
1141 RT2860_DPRINTF(sc
, RT2860_DEBUG_ANY
,
1142 "%s: loading 8051 microcode\n",
1143 device_get_nameunit(sc
->dev
));
1145 error
= rt2860_io_mcu_load_ucode(sc
, rt2860_ucode
, sizeof(rt2860_ucode
));
1148 printf("%s: could not load 8051 microcode\n",
1149 device_get_nameunit(sc
->dev
));
1153 RT2860_DPRINTF(sc
, RT2860_DEBUG_ANY
,
1154 "%s: 8051 microcode was successfully loaded\n",
1155 device_get_nameunit(sc
->dev
));
1157 sc
->flags
|= RT2860_SOFTC_FLAGS_UCODE_LOADED
;
1160 rt2860_io_mac_write(sc
, RT2860_REG_PWR_PIN_CFG
, 0x2);
1162 /* disable DMA engine */
1164 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
);
1167 tmp
|= RT2860_REG_TX_WB_DDONE
;
1169 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
, tmp
);
1171 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WPDMA_RST_IDX
, 0xffffffff);
1173 /* PBF hardware reset */
1175 rt2860_io_mac_write(sc
, RT2860_REG_PBF_SYS_CTRL
, 0xe1f);
1176 rt2860_io_mac_write(sc
, RT2860_REG_PBF_SYS_CTRL
, 0xe00);
1178 /* wait while DMA engine is busy */
1180 for (ntries
= 0; ntries
< 100; ntries
++)
1182 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
);
1183 if (!(tmp
& (RT2860_REG_TX_DMA_BUSY
| RT2860_REG_RX_DMA_BUSY
)))
1191 printf("%s: timeout waiting for DMA engine\n",
1192 device_get_nameunit(sc
->dev
));
1197 tmp
|= RT2860_REG_TX_WB_DDONE
;
1199 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
, tmp
);
1201 /* reset Rx and Tx rings */
1203 tmp
= RT2860_REG_RST_IDX_RX
|
1204 RT2860_REG_RST_IDX_TX_MGMT
|
1205 RT2860_REG_RST_IDX_TX_HCCA
|
1206 RT2860_REG_RST_IDX_TX_AC3
|
1207 RT2860_REG_RST_IDX_TX_AC2
|
1208 RT2860_REG_RST_IDX_TX_AC1
|
1209 RT2860_REG_RST_IDX_TX_AC0
;
1211 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WPDMA_RST_IDX
, tmp
);
1213 /* PBF hardware reset */
1215 rt2860_io_mac_write(sc
, RT2860_REG_PBF_SYS_CTRL
, 0xe1f);
1216 rt2860_io_mac_write(sc
, RT2860_REG_PBF_SYS_CTRL
, 0xe00);
1218 rt2860_io_mac_write(sc
, RT2860_REG_PWR_PIN_CFG
, 0x3);
1220 rt2860_io_mac_write(sc
, RT2860_REG_SYS_CTRL
,
1221 RT2860_REG_MAC_SRST
| RT2860_REG_BBP_HRST
);
1222 rt2860_io_mac_write(sc
, RT2860_REG_SYS_CTRL
, 0);
1224 /* init Tx power per rate */
1226 for (i
= 0; i
< RT2860_SOFTC_TXPOW_RATE_COUNT
; i
++)
1228 if (sc
->txpow_rate_20mhz
[i
] == 0xffffffff)
1231 rt2860_io_mac_write(sc
, RT2860_REG_TX_PWR_CFG(i
),
1232 sc
->txpow_rate_20mhz
[i
]);
1235 for (i
= 0; i
< RT2860_DEF_MAC_SIZE
; i
++)
1236 rt2860_io_mac_write(sc
, rt2860_def_mac
[i
].reg
,
1237 rt2860_def_mac
[i
].val
);
1239 /* wait while MAC is busy */
1241 for (ntries
= 0; ntries
< 100; ntries
++)
1243 if (!(rt2860_io_mac_read(sc
, RT2860_REG_STATUS_CFG
) &
1244 (RT2860_REG_STATUS_TX_BUSY
| RT2860_REG_STATUS_RX_BUSY
)))
1252 printf("%s: timeout waiting for MAC\n",
1253 device_get_nameunit(sc
->dev
));
1257 /* clear Host to MCU mailbox */
1259 rt2860_io_mac_write(sc
, RT2860_REG_H2M_MAILBOX_BBP_AGENT
, 0);
1260 rt2860_io_mac_write(sc
, RT2860_REG_H2M_MAILBOX
, 0);
1262 rt2860_io_mcu_cmd(sc
, RT2860_IO_MCU_CMD_BOOT
,
1263 RT2860_REG_H2M_TOKEN_NO_INTR
, 0);
1267 error
= rt2860_init_bbp(sc
);
1271 /* set up maximum buffer sizes */
1273 tmp
= (1 << 12) | RT2860_MAX_AGG_SIZE
;
1275 rt2860_io_mac_write(sc
, RT2860_REG_MAX_LEN_CFG
, tmp
);
1277 /* set mac address */
1279 IEEE80211_ADDR_COPY(ic
->ic_myaddr
, IF_LLADDR(ifp
));
1281 rt2860_asic_set_macaddr(sc
, ic
->ic_myaddr
);
1283 /* clear statistic registers */
1285 rt2860_io_mac_read_multi(sc
, RT2860_REG_RX_STA_CNT0
,
1286 stacnt
, sizeof(stacnt
));
1288 /* set RTS threshold */
1290 rt2860_asic_update_rtsthreshold(sc
);
1294 rt2860_asic_update_txpower(sc
);
1296 /* set up protection mode */
1298 rt2860_asic_updateprot(sc
);
1300 /* clear key tables */
1302 rt2860_asic_clear_keytables(sc
);
1304 /* clear beacon frame space (entries = 8, entry size = 512) */
1306 rt2860_io_mac_set_region_4(sc
, RT2860_REG_BEACON_BASE(0), 0, 1024);
1308 taskqueue_unblock(sc
->taskqueue
);
1310 /* init Tx rings (4 EDCAs + HCCA + MGMT) */
1312 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
1313 rt2860_reset_tx_ring(sc
, &sc
->tx_ring
[i
]);
1315 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
1317 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_BASE_PTR(i
),
1318 sc
->tx_ring
[i
].desc_phys_addr
);
1319 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_MAX_CNT(i
),
1320 RT2860_SOFTC_TX_RING_DESC_COUNT
);
1321 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_CTX_IDX(i
), 0);
1326 rt2860_reset_rx_ring(sc
, &sc
->rx_ring
);
1328 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_BASE_PTR
,
1329 sc
->rx_ring
.desc_phys_addr
);
1330 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_MAX_CNT
,
1331 RT2860_SOFTC_RX_RING_DATA_COUNT
);
1332 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_CALC_IDX
,
1333 RT2860_SOFTC_RX_RING_DATA_COUNT
- 1);
1335 /* wait while DMA engine is busy */
1337 for (ntries
= 0; ntries
< 100; ntries
++)
1339 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
);
1340 if (!(tmp
& (RT2860_REG_TX_DMA_BUSY
| RT2860_REG_RX_DMA_BUSY
)))
1348 printf("%s: timeout waiting for DMA engine\n",
1349 device_get_nameunit(sc
->dev
));
1354 tmp
|= RT2860_REG_TX_WB_DDONE
;
1356 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
, tmp
);
1358 /* disable interrupts mitigation */
1360 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_DELAY_INT_CFG
, 0);
1362 /* send LEDs operating mode to microcontroller */
1364 rt2860_io_mcu_cmd(sc
, RT2860_IO_MCU_CMD_LED1
,
1365 RT2860_REG_H2M_TOKEN_NO_INTR
, sc
->led_off
[0]);
1366 rt2860_io_mcu_cmd(sc
, RT2860_IO_MCU_CMD_LED2
,
1367 RT2860_REG_H2M_TOKEN_NO_INTR
, sc
->led_off
[1]);
1368 rt2860_io_mcu_cmd(sc
, RT2860_IO_MCU_CMD_LED3
,
1369 RT2860_REG_H2M_TOKEN_NO_INTR
, sc
->led_off
[2]);
1371 /* turn radio LED on */
1373 rt2860_led_cmd(sc
, RT2860_LED_CMD_RADIO_ON
);
1375 /* write vendor-specific BBP values (from EEPROM) */
1377 for (i
= 0; i
< RT2860_SOFTC_BBP_EEPROM_COUNT
; i
++)
1379 if (sc
->bbp_eeprom
[i
].reg
== 0x00 ||
1380 sc
->bbp_eeprom
[i
].reg
== 0xff)
1383 rt2860_io_bbp_write(sc
, sc
->bbp_eeprom
[i
].reg
,
1384 sc
->bbp_eeprom
[i
].val
);
1388 tmp = rt2860_io_mac_read(sc, RT2860_REG_SCHDMA_GPIO_CTRL_CFG);
1391 rt2860_io_mcu_cmd(sc, RT2860_IO_MCU_CMD_SLEEP,
1392 RT2860_REG_H2M_TOKEN_RADIOOFF, 0x02ff);
1393 rt2860_io_mcu_cmd_check(sc, RT2860_REG_H2M_TOKEN_RADIOOFF);
1395 rt2860_io_mcu_cmd(sc, RT2860_IO_MCU_CMD_WAKEUP,
1396 RT2860_REG_H2M_TOKEN_WAKEUP, 0);
1397 rt2860_io_mcu_cmd_check(sc, RT2860_REG_H2M_TOKEN_WAKEUP);
1401 /* disable non-existing Rx chains */
1403 tmp
= rt2860_io_bbp_read(sc
, 3);
1405 tmp
&= ~((1 << 4) | (1 << 3));
1407 if (sc
->nrxpath
== 3)
1409 else if (sc
->nrxpath
== 2)
1412 rt2860_io_bbp_write(sc
, 3, tmp
);
1414 /* disable non-existing Tx chains */
1416 tmp
= rt2860_io_bbp_read(sc
, 1);
1418 tmp
&= ~((1 << 4) | (1 << 3));
1420 if (sc
->ntxpath
== 2)
1423 rt2860_io_bbp_write(sc
, 1, tmp
);
1425 /* set current channel */
1427 rt2860_rf_set_chan(sc
, ic
->ic_curchan
);
1429 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WMM_TXOP0_CFG
, 0);
1430 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WMM_TXOP1_CFG
,
1433 if ((sc
->mac_rev
& 0xffff) != 0x0101)
1434 rt2860_io_mac_write(sc
, RT2860_REG_TX_TXOP_CTRL_CFG
, 0x583f);
1436 /* clear pending interrupts */
1438 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_INT_STATUS
, 0xffffffff);
1440 /* enable interrupts */
1442 tmp
= RT2860_REG_INT_TX_COHERENT
|
1443 RT2860_REG_INT_RX_COHERENT
|
1444 RT2860_REG_INT_GP_TIMER
|
1445 RT2860_REG_INT_AUTO_WAKEUP
|
1446 RT2860_REG_INT_FIFO_STA_FULL
|
1448 RT2860_REG_INT_PRE_TBTT |
1449 RT2860_REG_INT_TBTT |
1451 RT2860_REG_INT_TXRX_COHERENT
|
1452 RT2860_REG_INT_MCU_CMD
|
1453 RT2860_REG_INT_TX_MGMT_DONE
|
1454 RT2860_REG_INT_TX_HCCA_DONE
|
1455 RT2860_REG_INT_TX_AC3_DONE
|
1456 RT2860_REG_INT_TX_AC2_DONE
|
1457 RT2860_REG_INT_TX_AC1_DONE
|
1458 RT2860_REG_INT_TX_AC0_DONE
|
1459 RT2860_REG_INT_RX_DONE
;
1461 sc
->intr_enable_mask
= tmp
;
1463 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_INT_MASK
, tmp
);
1465 if (rt2860_txrx_enable(sc
) != 0)
1468 /* clear garbage interrupts */
1470 tmp
= rt2860_io_mac_read(sc
, 0x1300);
1472 ifp
->if_drv_flags
&= ~IFF_DRV_OACTIVE
;
1473 ifp
->if_drv_flags
|= IFF_DRV_RUNNING
;
1475 if (ic
->ic_opmode
!= IEEE80211_M_MONITOR
)
1477 if (ic
->ic_roaming
!= IEEE80211_ROAMING_MANUAL
)
1478 ieee80211_new_state(ic
, IEEE80211_S_SCAN
, -1);
1482 ieee80211_new_state(ic
, IEEE80211_S_RUN
, -1);
1485 sc
->periodic_round
= 0;
1487 callout_reset(&sc
->periodic_ch
, hz
/ 10, rt2860_periodic
, sc
);
1493 rt2860_stop_locked(sc
);
1499 static void rt2860_init(void *priv
)
1501 struct rt2860_softc
*sc
;
1505 RT2860_SOFTC_LOCK(sc
);
1507 rt2860_init_locked(sc
);
1509 RT2860_SOFTC_UNLOCK(sc
);
1515 static int rt2860_init_bbp(struct rt2860_softc
*sc
)
1520 for (ntries
= 0; ntries
< 20; ntries
++)
1522 tmp
= rt2860_io_bbp_read(sc
, 0);
1523 if (tmp
!= 0x00 && tmp
!= 0xff)
1527 if (tmp
== 0x00 || tmp
== 0xff)
1529 printf("%s: timeout waiting for BBP to wakeup\n",
1530 device_get_nameunit(sc
->dev
));
1534 for (i
= 0; i
< RT2860_DEF_BBP_SIZE
; i
++)
1535 rt2860_io_bbp_write(sc
, rt2860_def_bbp
[i
].reg
,
1536 rt2860_def_bbp
[i
].val
);
1538 if ((sc
->mac_rev
& 0xffff) != 0x0101)
1539 rt2860_io_bbp_write(sc
, 84, 0x19);
1545 * rt2860_stop_locked
1547 static void rt2860_stop_locked(void *priv
)
1549 struct rt2860_softc
*sc
;
1550 struct ieee80211com
*ic
;
1558 RT2860_DPRINTF(sc
, RT2860_DEBUG_ANY
,
1560 device_get_nameunit(sc
->dev
));
1562 RT2860_SOFTC_ASSERT_LOCKED(sc
);
1566 if (ifp
->if_drv_flags
& IFF_DRV_RUNNING
)
1567 rt2860_led_cmd(sc
, RT2860_LED_CMD_RADIO_OFF
);
1569 ifp
->if_drv_flags
&= ~(IFF_DRV_RUNNING
| IFF_DRV_OACTIVE
);
1571 ieee80211_new_state(ic
, IEEE80211_S_INIT
, -1);
1573 callout_stop(&sc
->periodic_ch
);
1574 callout_stop(&sc
->tx_watchdog_ch
);
1576 RT2860_SOFTC_UNLOCK(sc
);
1578 taskqueue_block(sc
->taskqueue
);
1580 taskqueue_drain(sc
->taskqueue
, &sc
->rx_done_task
);
1581 taskqueue_drain(sc
->taskqueue
, &sc
->tx_done_task
);
1582 taskqueue_drain(sc
->taskqueue
, &sc
->fifo_sta_full_task
);
1583 taskqueue_drain(sc
->taskqueue
, &sc
->periodic_task
);
1585 RT2860_SOFTC_LOCK(sc
);
1587 /* clear key tables */
1589 rt2860_asic_clear_keytables(sc
);
1591 /* disable interrupts */
1593 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_INT_MASK
, 0);
1597 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_SYS_CTRL
);
1599 tmp
&= ~(RT2860_REG_RX_ENABLE
| RT2860_REG_TX_ENABLE
);
1601 rt2860_io_mac_write(sc
, RT2860_REG_SYS_CTRL
, tmp
);
1605 rt2860_io_mac_write(sc
, RT2860_REG_SYS_CTRL
,
1606 RT2860_REG_MAC_SRST
| RT2860_REG_BBP_HRST
);
1607 rt2860_io_mac_write(sc
, RT2860_REG_SYS_CTRL
, 0);
1613 static void rt2860_stop(void *priv
)
1615 struct rt2860_softc
*sc
;
1619 RT2860_SOFTC_LOCK(sc
);
1621 rt2860_stop_locked(sc
);
1623 RT2860_SOFTC_UNLOCK(sc
);
1629 static void rt2860_start(struct ifnet
*ifp
)
1631 struct rt2860_softc
*sc
;
1632 struct ieee80211com
*ic
;
1633 struct ieee80211_node
*ni
;
1634 struct ether_header
*eh
;
1641 RT2860_SOFTC_LOCK(sc
);
1643 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
1645 RT2860_SOFTC_UNLOCK(sc
);
1651 IF_POLL(&ic
->ic_mgtq
, m
);
1654 if (sc
->tx_ring
[sc
->tx_ring_mgtqid
].data_queued
>= RT2860_SOFTC_TX_RING_DATA_COUNT
)
1656 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
1657 "%s: if_start: Tx ring with qid=%d is full\n",
1658 device_get_nameunit(sc
->dev
), sc
->tx_ring_mgtqid
);
1660 ifp
->if_drv_flags
|= IFF_DRV_OACTIVE
;
1662 sc
->tx_data_queue_full
[sc
->tx_ring_mgtqid
]++;
1667 IF_DEQUEUE(&ic
->ic_mgtq
, m
);
1669 ni
= (struct ieee80211_node
*) m
->m_pkthdr
.rcvif
;
1670 m
->m_pkthdr
.rcvif
= NULL
;
1672 if (bpf_peers_present(ic
->ic_rawbpf
))
1673 bpf_mtap(ic
->ic_rawbpf
, m
);
1675 if (rt2860_tx_frame(sc
, m
, ni
, sc
->tx_ring_mgtqid
) != 0)
1678 rt2860_drain_fifo_stats(sc
);
1682 if (ic
->ic_state
!= IEEE80211_S_RUN
)
1685 IF_POLL(&ifp
->if_snd
, m
);
1689 IFQ_DRV_DEQUEUE(&ifp
->if_snd
, m
);
1691 if (ic
->ic_flags
& IEEE80211_F_SCAN
)
1692 ieee80211_cancel_scan(ic
);
1694 if (m
->m_len
< sizeof(struct ether_header
) &&
1695 !(m
= m_pullup(m
, sizeof (struct ether_header
))))
1698 eh
= mtod(m
, struct ether_header
*);
1700 ni
= ieee80211_find_txnode(ic
, eh
->ether_dhost
);
1703 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
1704 "%s: if_start: could not find Tx node\n",
1705 device_get_nameunit(sc
->dev
));
1711 ieee80211_classify(ic
, m
, ni
);
1713 qid
= M_WME_GETAC(m
);
1715 if (sc
->tx_ring
[qid
].data_queued
>= RT2860_SOFTC_TX_RING_DATA_COUNT
)
1717 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
1718 "%s: if_start: Tx ring with qid=%d is full\n",
1719 device_get_nameunit(sc
->dev
), qid
);
1722 ieee80211_free_node(ni
);
1724 ifp
->if_drv_flags
|= IFF_DRV_OACTIVE
;
1727 sc
->tx_data_queue_full
[qid
]++;
1734 m
= ieee80211_encap(ic
, m
, ni
);
1737 ieee80211_free_node(ni
);
1742 if (bpf_peers_present(ic
->ic_rawbpf
))
1743 bpf_mtap(ic
->ic_rawbpf
, m
);
1745 if (rt2860_tx_frame(sc
, m
, ni
, qid
) != 0)
1747 ieee80211_free_node(ni
);
1754 rt2860_drain_fifo_stats(sc
);
1757 sc
->tx_timer
= RT2860_TX_WATCHDOG_TIMEOUT
;
1759 ic
->ic_lastdata
= ticks
;
1761 callout_reset(&sc
->tx_watchdog_ch
, hz
, rt2860_tx_watchdog
, sc
);
1764 RT2860_SOFTC_UNLOCK(sc
);
1770 static int rt2860_ioctl(struct ifnet
*ifp
, u_long cmd
, caddr_t data
)
1772 struct rt2860_softc
*sc
;
1773 struct ieee80211com
*ic
;
1784 RT2860_SOFTC_LOCK(sc
);
1786 if (ifp
->if_flags
& IFF_UP
)
1788 if (ifp
->if_drv_flags
& IFF_DRV_RUNNING
)
1790 if ((ifp
->if_flags
^ sc
->if_flags
) & IFF_PROMISC
)
1791 rt2860_asic_update_promisc(sc
);
1795 rt2860_init_locked(sc
);
1800 if (ifp
->if_drv_flags
& IFF_DRV_RUNNING
)
1801 rt2860_stop_locked(sc
);
1804 sc
->if_flags
= ifp
->if_flags
;
1806 RT2860_SOFTC_UNLOCK(sc
);
1810 error
= ieee80211_ioctl(ic
, cmd
, data
);
1813 if (error
== ENETRESET
)
1815 RT2860_SOFTC_LOCK(sc
);
1817 if ((ifp
->if_flags
& IFF_UP
) &&
1818 (ifp
->if_drv_flags
& IFF_DRV_RUNNING
) &&
1819 (ic
->ic_roaming
!= IEEE80211_ROAMING_MANUAL
))
1821 rt2860_stop_locked(sc
);
1822 rt2860_init_locked(sc
);
1825 RT2860_SOFTC_UNLOCK(sc
);
1836 static int rt2860_reset(struct ifnet
*ifp
)
1838 struct rt2860_softc
*sc
;
1839 struct ieee80211com
*ic
;
1844 if (ic
->ic_opmode
!= IEEE80211_M_MONITOR
)
1847 rt2860_rf_set_chan(sc
, ic
->ic_curchan
);
1855 static int rt2860_newstate(struct ieee80211com
*ic
,
1856 enum ieee80211_state nstate
, int arg
)
1858 struct rt2860_softc
*sc
;
1860 struct ieee80211_node
*ni
;
1866 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATE
,
1867 "%s: newstate: %s -> %s\n",
1868 device_get_nameunit(sc
->dev
),
1869 ieee80211_state_name
[ic
->ic_state
], ieee80211_state_name
[nstate
]);
1871 error
= sc
->newstate(ic
, nstate
, arg
);
1875 RT2860_SOFTC_LOCK(sc
);
1877 /* turn link LED off */
1879 if (nstate
!= IEEE80211_S_RUN
)
1880 rt2860_led_cmd(sc
, RT2860_LED_CMD_RADIO_OFF
);
1884 case IEEE80211_S_INIT
:
1885 rt2860_asic_disable_tsf_sync(sc
);
1888 case IEEE80211_S_RUN
:
1891 rt2860_rf_set_chan(sc
, ni
->ni_chan
);
1893 if (ic
->ic_opmode
!= IEEE80211_M_MONITOR
)
1895 rt2860_asic_enable_mrr(sc
);
1896 rt2860_asic_set_txpreamble(sc
);
1897 rt2860_asic_set_basicrates(sc
);
1898 rt2860_asic_update_txpower(sc
);
1899 rt2860_asic_set_bssid(sc
, ni
->ni_bssid
);
1902 if (ic
->ic_opmode
== IEEE80211_M_STA
)
1903 rt2860_newassoc(ni
, 1);
1905 if (ic
->ic_opmode
== IEEE80211_M_HOSTAP
||
1906 ic
->ic_opmode
== IEEE80211_M_IBSS
)
1908 error
= rt2860_asic_update_beacon(sc
);
1913 if (ic
->ic_opmode
!= IEEE80211_M_MONITOR
)
1914 rt2860_asic_enable_tsf_sync(sc
);
1916 /* turn link LED on */
1918 if (ic
->ic_opmode
!= IEEE80211_M_MONITOR
)
1920 rt2860_led_cmd(sc
, RT2860_LED_CMD_RADIO_ON
|
1921 (IEEE80211_IS_CHAN_2GHZ(ni
->ni_chan
) ?
1922 RT2860_LED_CMD_LINK_2GHZ
: RT2860_LED_CMD_LINK_5GHZ
));
1930 RT2860_SOFTC_UNLOCK(sc
);
1938 static void rt2860_scan_start(struct ieee80211com
*ic
)
1940 struct rt2860_softc
*sc
;
1946 rt2860_asic_disable_tsf_sync(sc
);
1952 static void rt2860_scan_end(struct ieee80211com
*ic
)
1954 struct rt2860_softc
*sc
;
1960 rt2860_asic_enable_tsf_sync(sc
);
1964 * rt2860_set_channel
1966 static void rt2860_set_channel(struct ieee80211com
*ic
)
1968 struct rt2860_softc
*sc
;
1974 RT2860_DPRINTF(sc
, RT2860_DEBUG_CHAN
,
1975 "%s: set channel: channel=%u, HT%s%s\n",
1976 device_get_nameunit(sc
->dev
),
1977 ieee80211_chan2ieee(ic
, ic
->ic_curchan
),
1978 !IEEE80211_IS_CHAN_HT(ic
->ic_curchan
) ? " disabled" :
1979 IEEE80211_IS_CHAN_HT20(ic
->ic_curchan
) ? "20":
1980 IEEE80211_IS_CHAN_HT40U(ic
->ic_curchan
) ? "40U" : "40D",
1981 (ic
->ic_flags
& IEEE80211_F_SCAN
) ? ", scanning" : "");
1983 RT2860_SOFTC_LOCK(sc
);
1985 rt2860_rf_set_chan(sc
, ic
->ic_curchan
);
1987 RT2860_SOFTC_UNLOCK(sc
);
1993 static void rt2860_newassoc(struct ieee80211_node
*ni
, int isnew
)
1995 struct rt2860_softc
*sc
;
1996 struct ieee80211com
*ic
;
2005 associd
= (ni
!= NULL
) ? ni
->ni_associd
: 0;
2006 wcid
= RT2860_AID2WCID(associd
);
2008 RT2860_DPRINTF(sc
, RT2860_DEBUG_NODE
,
2009 "%s: new association: wcid=0x%02x, "
2010 "mac addr=%s, QoS %s, ERP %s, HT %s\n",
2011 device_get_nameunit(sc
->dev
), wcid
,
2012 ether_sprintf(ni
->ni_macaddr
),
2013 (ni
->ni_flags
& IEEE80211_NODE_QOS
) ? "enabled" : "disabled",
2014 (ni
->ni_flags
& IEEE80211_NODE_ERP
) ? "enabled" : "disabled",
2015 (ni
->ni_flags
& IEEE80211_NODE_HT
) ? "enabled" : "disabled");
2017 rt2860_io_mac_write_multi(sc
, RT2860_REG_WCID(wcid
),
2018 ni
->ni_macaddr
, IEEE80211_ADDR_LEN
);
2020 rt2860_amrr_node_init(&sc
->amrr
, &sc
->amrr_node
[wcid
], ni
);
2022 RT2860_DPRINTF(sc
, RT2860_DEBUG_RATE
,
2023 "%s: initial%s node Tx rate: associd=0x%04x, rate=0x%02x, max rate=0x%02x\n",
2024 device_get_nameunit(sc
->dev
),
2025 (ni
->ni_flags
& IEEE80211_NODE_HT
) ? " HT" : "",
2027 (ni
->ni_flags
& IEEE80211_NODE_HT
) ?
2028 (ni
->ni_htrates
.rs_rates
[ni
->ni_txrate
] | IEEE80211_RATE_MCS
) :
2029 (ni
->ni_rates
.rs_rates
[ni
->ni_txrate
] & IEEE80211_RATE_VAL
),
2030 (ni
->ni_flags
& IEEE80211_NODE_HT
) ?
2031 (ni
->ni_htrates
.rs_rates
[ni
->ni_htrates
.rs_nrates
- 1] | IEEE80211_RATE_MCS
) :
2032 (ni
->ni_rates
.rs_rates
[ni
->ni_rates
.rs_nrates
- 1] & IEEE80211_RATE_VAL
));
2034 rt2860_asic_updateprot(sc
);
2035 rt2860_asic_updateslot(sc
);
2036 rt2860_asic_set_txpreamble(sc
);
2042 static void rt2860_updateslot(struct ifnet
*ifp
)
2044 struct rt2860_softc
*sc
;
2048 rt2860_asic_updateslot(sc
);
2054 static int rt2860_wme_update(struct ieee80211com
*ic
)
2056 struct rt2860_softc
*sc
;
2062 rt2860_asic_wme_update(sc
);
2068 * rt2860_update_beacon
2070 static void rt2860_update_beacon(struct ieee80211com
*ic
, int what
)
2072 struct rt2860_softc
*sc
;
2078 rt2860_asic_update_beacon(sc
);
2082 * rt2860_key_update_begin
2084 static void rt2860_key_update_begin(struct ieee80211com
*ic
)
2086 struct rt2860_softc
*sc
;
2092 RT2860_DPRINTF(sc
, RT2860_DEBUG_KEY
,
2093 "%s: key update begin\n",
2094 device_get_nameunit(sc
->dev
));
2096 taskqueue_block(sc
->taskqueue
);
2098 IF_LOCK(&ifp
->if_snd
);
2102 * rt2860_key_update_end
2104 static void rt2860_key_update_end(struct ieee80211com
*ic
)
2106 struct rt2860_softc
*sc
;
2112 RT2860_DPRINTF(sc
, RT2860_DEBUG_KEY
,
2113 "%s: key update end\n",
2114 device_get_nameunit(sc
->dev
));
2116 IF_UNLOCK(&ifp
->if_snd
);
2118 taskqueue_unblock(sc
->taskqueue
);
2124 static int rt2860_key_set(struct ieee80211com
*ic
,
2125 const struct ieee80211_key
*k
, const uint8_t mac
[IEEE80211_ADDR_LEN
])
2127 struct rt2860_softc
*sc
;
2129 struct ieee80211_node
*ni
;
2130 uint16_t associd
, key_base
, keymode_base
;
2131 uint8_t mode
, vapid
, wcid
, iv
[8];
2134 if (k
->wk_cipher
->ic_cipher
!= IEEE80211_CIPHER_WEP
&&
2135 k
->wk_cipher
->ic_cipher
!= IEEE80211_CIPHER_TKIP
&&
2136 k
->wk_cipher
->ic_cipher
!= IEEE80211_CIPHER_AES_CCM
)
2142 if (ic
->ic_opmode
!= IEEE80211_M_HOSTAP
)
2145 ni
= ieee80211_find_node(&ic
->ic_sta
, mac
);
2147 associd
= (ni
!= NULL
) ? ni
->ni_associd
: 0;
2149 if ((ic
->ic_opmode
== IEEE80211_M_HOSTAP
) && (ni
!= NULL
))
2150 ieee80211_free_node(ni
);
2152 switch (k
->wk_cipher
->ic_cipher
)
2154 case IEEE80211_CIPHER_WEP
:
2155 if(k
->wk_keylen
< 8)
2156 mode
= RT2860_REG_CIPHER_MODE_WEP40
;
2158 mode
= RT2860_REG_CIPHER_MODE_WEP104
;
2161 case IEEE80211_CIPHER_TKIP
:
2162 mode
= RT2860_REG_CIPHER_MODE_TKIP
;
2165 case IEEE80211_CIPHER_AES_CCM
:
2166 mode
= RT2860_REG_CIPHER_MODE_AES_CCMP
;
2173 RT2860_DPRINTF(sc
, RT2860_DEBUG_KEY
,
2174 "%s: set key: keyix=%d, keylen=%d, associd=0x%04x, mode=%d, group=%d\n",
2175 device_get_nameunit(sc
->dev
), k
->wk_keyix
, k
->wk_keylen
, associd
, mode
,
2176 (k
->wk_flags
& IEEE80211_KEY_GROUP
) ? 1 : 0);
2178 if (!(k
->wk_flags
& IEEE80211_KEY_GROUP
))
2180 /* install pairwise key */
2183 wcid
= RT2860_AID2WCID(associd
);
2184 key_base
= RT2860_REG_PKEY(wcid
);
2186 if (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_WEP
)
2190 iv
[3] = (k
->wk_keyix
<< 6);
2194 if (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_TKIP
)
2196 iv
[0] = (k
->wk_keytsc
>> 8);
2197 iv
[1] = ((iv
[0] | 0x20) & 0x7f);
2198 iv
[2] = k
->wk_keytsc
;
2204 iv
[0] = k
->wk_keytsc
;
2205 iv
[1] = k
->wk_keytsc
>> 8;
2209 iv
[3] = ((k
->wk_keyix
<< 6) | IEEE80211_WEP_EXTIV
);
2210 iv
[4] = (k
->wk_keytsc
>> 16);
2211 iv
[5] = (k
->wk_keytsc
>> 24);
2212 iv
[6] = (k
->wk_keytsc
>> 32);
2213 iv
[7] = (k
->wk_keytsc
>> 40);
2215 RT2860_DPRINTF(sc
, RT2860_DEBUG_KEY
,
2216 "%s: set key: iv=%02x %02x %02x %02x %02x %02x %02x %02x\n",
2217 device_get_nameunit(sc
->dev
),
2218 iv
[0], iv
[1], iv
[2], iv
[3], iv
[4], iv
[5], iv
[6], iv
[7]);
2221 rt2860_io_mac_write_multi(sc
, RT2860_REG_IVEIV(wcid
), iv
, 8);
2223 if (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_TKIP
)
2225 rt2860_io_mac_write_multi(sc
, key_base
, k
->wk_key
, 16);
2227 if (ic
->ic_opmode
!= IEEE80211_M_HOSTAP
)
2229 rt2860_io_mac_write_multi(sc
, key_base
+ 16, &k
->wk_key
[16], 8);
2230 rt2860_io_mac_write_multi(sc
, key_base
+ 24, &k
->wk_key
[24], 8);
2234 rt2860_io_mac_write_multi(sc
, key_base
+ 16, &k
->wk_key
[24], 8);
2235 rt2860_io_mac_write_multi(sc
, key_base
+ 24, &k
->wk_key
[16], 8);
2240 rt2860_io_mac_write_multi(sc
, key_base
, k
->wk_key
, k
->wk_keylen
);
2243 tmp
= ((vapid
& RT2860_REG_VAP_MASK
) << RT2860_REG_VAP_SHIFT
) |
2244 (mode
<< RT2860_REG_CIPHER_MODE_SHIFT
) | RT2860_REG_PKEY_ENABLE
;
2246 rt2860_io_mac_write(sc
, RT2860_REG_WCID_ATTR(wcid
), tmp
);
2249 if ((k
->wk_flags
& IEEE80211_KEY_GROUP
) ||
2250 (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_WEP
))
2252 /* install group key */
2255 key_base
= RT2860_REG_SKEY(vapid
, k
->wk_keyix
);
2256 keymode_base
= RT2860_REG_SKEY_MODE(vapid
);
2258 if (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_TKIP
)
2260 rt2860_io_mac_write_multi(sc
, key_base
, k
->wk_key
, 16);
2262 if (ic
->ic_opmode
!= IEEE80211_M_HOSTAP
)
2264 rt2860_io_mac_write_multi(sc
, key_base
+ 16, &k
->wk_key
[16], 8);
2265 rt2860_io_mac_write_multi(sc
, key_base
+ 24, &k
->wk_key
[24], 8);
2269 rt2860_io_mac_write_multi(sc
, key_base
+ 16, &k
->wk_key
[24], 8);
2270 rt2860_io_mac_write_multi(sc
, key_base
+ 24, &k
->wk_key
[16], 8);
2275 rt2860_io_mac_write_multi(sc
, key_base
, k
->wk_key
, k
->wk_keylen
);
2278 tmp
= rt2860_io_mac_read(sc
, keymode_base
);
2280 tmp
&= ~(0xf << (k
->wk_keyix
* 4 + 16 * (vapid
% 2)));
2281 tmp
|= (mode
<< (k
->wk_keyix
* 4 + 16 * (vapid
% 2)));
2283 rt2860_io_mac_write(sc
, keymode_base
, tmp
);
2292 static int rt2860_key_delete(struct ieee80211com
*ic
,
2293 const struct ieee80211_key
*k
)
2295 struct rt2860_softc
*sc
;
2296 struct ieee80211_node
*ni
;
2298 uint8_t vapid
, wcid
;
2301 sc
= ic
->ic_ifp
->if_softc
;
2303 associd
= (ni
!= NULL
) ? ni
->ni_associd
: 0;
2305 RT2860_DPRINTF(sc
, RT2860_DEBUG_KEY
,
2306 "%s: delete key: keyix=%d, keylen=%d, associd=0x%04x, group=%d\n",
2307 device_get_nameunit(sc
->dev
), k
->wk_keyix
, k
->wk_keylen
, associd
,
2308 (k
->wk_flags
& IEEE80211_KEY_GROUP
) ? 1 : 0);
2310 if (!(k
->wk_flags
& IEEE80211_KEY_GROUP
))
2312 /* remove pairwise key */
2315 wcid
= RT2860_AID2WCID(associd
);
2317 tmp
= ((vapid
& RT2860_REG_VAP_MASK
) << RT2860_REG_VAP_SHIFT
) |
2318 (RT2860_REG_CIPHER_MODE_NONE
<< RT2860_REG_CIPHER_MODE_SHIFT
) | RT2860_REG_PKEY_ENABLE
;
2320 rt2860_io_mac_write(sc
, RT2860_REG_WCID_ATTR(wcid
), tmp
);
2324 /* remove group key */
2328 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_SKEY_MODE(vapid
));
2330 tmp
&= ~(0xf << (k
->wk_keyix
* 4 + 16 * (vapid
% 2)));
2331 tmp
|= (RT2860_REG_CIPHER_MODE_NONE
<< (k
->wk_keyix
* 4 + 16 * (vapid
% 2)));
2333 rt2860_io_mac_write(sc
, RT2860_REG_SKEY_MODE(vapid
), tmp
);
2342 static int rt2860_raw_xmit(struct ieee80211_node
*ni
, struct mbuf
*m
,
2343 const struct ieee80211_bpf_params
*params
)
2349 * rt2860_media_change
2351 static int rt2860_media_change(struct ifnet
*ifp
)
2353 struct rt2860_softc
*sc
;
2358 error
= ieee80211_media_change(ifp
);
2359 if (error
!= ENETRESET
)
2362 RT2860_SOFTC_LOCK(sc
);
2364 if ((ifp
->if_flags
& IFF_UP
) && (ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
2366 rt2860_stop_locked(sc
);
2367 rt2860_init_locked(sc
);
2370 RT2860_SOFTC_UNLOCK(sc
);
2376 * rt2860_recv_action
2378 static void rt2860_recv_action(struct ieee80211_node
*ni
,
2379 const uint8_t *frm
, const uint8_t *efrm
)
2381 struct rt2860_softc
*sc
;
2382 struct ieee80211com
*ic
;
2384 const struct ieee80211_action
*ia
;
2385 uint16_t associd
, status
, baparamset
;
2394 ia
= (const struct ieee80211_action
*) frm
;
2396 sc
->recv_action(ni
, frm
, efrm
);
2398 if (ia
->ia_category
!= IEEE80211_ACTION_CAT_BA
)
2401 associd
= (ni
!= NULL
) ? ni
->ni_associd
: 0;
2402 wcid
= RT2860_AID2WCID(associd
);
2404 switch (ia
->ia_action
)
2406 /* IEEE80211_ACTION_BA_ADDBA_REQUEST */
2407 case IEEE80211_ACTION_BA_ADDBA_REQUEST
:
2408 baparamset
= LE_READ_2(frm
+ 3);
2409 tid
= RT2860_MS(baparamset
, IEEE80211_BAPS_TID
);
2410 bufsize
= RT2860_MS(baparamset
, IEEE80211_BAPS_BUFSIZ
);
2412 RT2860_DPRINTF(sc
, RT2860_DEBUG_BA
,
2413 "%s: received ADDBA request: associd=0x%04x, tid=%d, bufsize=%d\n",
2414 device_get_nameunit(sc
->dev
), associd
, tid
, bufsize
);
2416 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_WCID(wcid
) + 4);
2418 tmp
|= (0x10000 << tid
);
2420 rt2860_io_mac_write(sc
, RT2860_REG_WCID(wcid
) + 4, tmp
);
2423 /* IEEE80211_ACTION_BA_ADDBA_RESPONSE */
2424 case IEEE80211_ACTION_BA_ADDBA_RESPONSE
:
2425 status
= LE_READ_2(frm
+ 3);
2426 baparamset
= LE_READ_2(frm
+ 4);
2427 tid
= RT2860_MS(baparamset
, IEEE80211_BAPS_TID
);
2428 bufsize
= RT2860_MS(baparamset
, IEEE80211_BAPS_BUFSIZ
);
2430 RT2860_DPRINTF(sc
, RT2860_DEBUG_BA
,
2431 "%s: received ADDBA response: associd=0x%04x, status=%d, tid=%d, bufsize=%d\n",
2432 device_get_nameunit(sc
->dev
), associd
, status
, tid
, bufsize
);
2434 if (status
== IEEE80211_STATUS_SUCCESS
)
2436 sc
->tx_ampdu_sessions
++;
2438 rt2860_asic_updateprot(sc
);
2442 /* IEEE80211_ACTION_BA_DELBA */
2443 case IEEE80211_ACTION_BA_DELBA
:
2444 baparamset
= LE_READ_2(frm
+ 2);
2445 tid
= RT2860_MS(baparamset
, IEEE80211_BAPS_TID
);
2447 RT2860_DPRINTF(sc
, RT2860_DEBUG_BA
,
2448 "%s: received DELBA request: associd=0x%04x, tid=%d\n",
2449 device_get_nameunit(sc
->dev
), associd
, tid
);
2451 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_WCID(wcid
) + 4);
2453 tmp
&= ~(0x10000 << tid
);
2455 rt2860_io_mac_write(sc
, RT2860_REG_WCID(wcid
) + 4, tmp
);
2461 * rt2860_send_action
2463 static int rt2860_send_action(struct ieee80211_node
*ni
,
2464 int category
, int action
, uint16_t args
[4])
2466 struct rt2860_softc
*sc
;
2467 struct ieee80211com
*ic
;
2469 uint16_t associd
, baparamset
;
2478 ret
= sc
->send_action(ni
, category
, action
, args
);
2480 if (category
!= IEEE80211_ACTION_CAT_BA
)
2483 associd
= (ni
!= NULL
) ? ni
->ni_associd
: 0;
2484 wcid
= RT2860_AID2WCID(associd
);
2488 /* IEEE80211_ACTION_BA_DELBA */
2489 case IEEE80211_ACTION_BA_DELBA
:
2490 baparamset
= RT2860_SM(args
[0], IEEE80211_DELBAPS_TID
) | args
[1];
2492 tid
= RT2860_MS(baparamset
, IEEE80211_DELBAPS_TID
);
2494 RT2860_DPRINTF(sc
, RT2860_DEBUG_BA
,
2495 "%s: sending DELBA request: associd=0x%04x, tid=%d\n",
2496 device_get_nameunit(sc
->dev
), associd
, tid
);
2498 if (RT2860_MS(baparamset
, IEEE80211_DELBAPS_INIT
) != IEEE80211_DELBAPS_INIT
)
2500 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_WCID(wcid
) + 4);
2502 tmp
&= ~(0x10000 << tid
);
2504 rt2860_io_mac_write(sc
, RT2860_REG_WCID(wcid
) + 4, tmp
);
2508 sc
->tx_ampdu_sessions
--;
2510 rt2860_asic_updateprot(sc
);
2519 * rt2860_amrr_update_iter_func
2521 static void rt2860_amrr_update_iter_func(void *arg
, struct ieee80211_node
*ni
)
2523 struct rt2860_softc
*sc
;
2524 struct ieee80211com
*ic
;
2530 /* only associated stations */
2532 if (ni
->ni_associd
!= 0)
2534 wcid
= RT2860_AID2WCID(ni
->ni_associd
);
2536 RT2860_DPRINTF(sc
, RT2860_DEBUG_RATE
,
2537 "%s: AMRR node: wcid=0x%02x, txcnt=%d, success=%d, retrycnt=%d\n",
2538 device_get_nameunit(sc
->dev
),
2539 wcid
, sc
->amrr_node
[wcid
].txcnt
, sc
->amrr_node
[wcid
].success
, sc
->amrr_node
[wcid
].retrycnt
);
2541 rt2860_amrr_choose(ni
, &sc
->amrr_node
[wcid
]);
2543 RT2860_DPRINTF(sc
, RT2860_DEBUG_RATE
,
2544 "%s:%s node Tx rate: associd=0x%04x, rate=0x%02x, max rate=0x%02x\n",
2545 device_get_nameunit(sc
->dev
),
2546 (ni
->ni_flags
& IEEE80211_NODE_HT
) ? " HT" : "",
2548 (ni
->ni_flags
& IEEE80211_NODE_HT
) ?
2549 (ni
->ni_htrates
.rs_rates
[ni
->ni_txrate
] | IEEE80211_RATE_MCS
) :
2550 (ni
->ni_rates
.rs_rates
[ni
->ni_txrate
] & IEEE80211_RATE_VAL
),
2551 (ni
->ni_flags
& IEEE80211_NODE_HT
) ?
2552 (ni
->ni_htrates
.rs_rates
[ni
->ni_htrates
.rs_nrates
- 1] | IEEE80211_RATE_MCS
) :
2553 (ni
->ni_rates
.rs_rates
[ni
->ni_rates
.rs_nrates
- 1] & IEEE80211_RATE_VAL
));
2560 static void rt2860_periodic(void *arg
)
2562 struct rt2860_softc
*sc
;
2566 RT2860_DPRINTF(sc
, RT2860_DEBUG_PERIODIC
,
2568 device_get_nameunit(sc
->dev
));
2570 taskqueue_enqueue(sc
->taskqueue
, &sc
->periodic_task
);
2574 * rt2860_tx_watchdog
2576 static void rt2860_tx_watchdog(void *arg
)
2578 struct rt2860_softc
*sc
;
2584 if (sc
->tx_timer
== 0)
2587 if (--sc
->tx_timer
== 0)
2589 printf("%s: Tx watchdog timeout: resetting\n",
2590 device_get_nameunit(sc
->dev
));
2592 rt2860_stop_locked(sc
);
2593 rt2860_init_locked(sc
);
2597 sc
->tx_watchdog_timeouts
++;
2600 callout_reset(&sc
->tx_watchdog_ch
, hz
, rt2860_tx_watchdog
, sc
);
2604 * rt2860_asic_set_bssid
2606 static void rt2860_asic_set_bssid(struct rt2860_softc
*sc
,
2607 const uint8_t *bssid
)
2611 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATE
,
2612 "%s: set bssid: bssid=%s\n",
2613 device_get_nameunit(sc
->dev
), ether_sprintf(bssid
));
2615 tmp
= bssid
[0] | (bssid
[1]) << 8 | (bssid
[2] << 16) | (bssid
[3] << 24);
2617 rt2860_io_mac_write(sc
, RT2860_REG_BSSID_DW0
, tmp
);
2619 tmp
= bssid
[4] | (bssid
[5] << 8);
2621 rt2860_io_mac_write(sc
, RT2860_REG_BSSID_DW1
, tmp
);
2625 * rt2860_asic_set_macaddr
2627 static void rt2860_asic_set_macaddr(struct rt2860_softc
*sc
,
2628 const uint8_t *addr
)
2632 tmp
= addr
[0] | (addr
[1] << 8) | (addr
[2] << 16) | (addr
[3] << 24);
2634 rt2860_io_mac_write(sc
, RT2860_REG_ADDR_DW0
, tmp
);
2636 tmp
= addr
[4] | (addr
[5] << 8);
2638 rt2860_io_mac_write(sc
, RT2860_REG_ADDR_DW1
, tmp
);
2642 * rt2860_asic_enable_tsf_sync
2644 static void rt2860_asic_enable_tsf_sync(struct rt2860_softc
*sc
)
2646 struct ieee80211com
*ic
;
2651 RT2860_DPRINTF(sc
, RT2860_DEBUG_BEACON
,
2652 "%s: enabling TSF\n",
2653 device_get_nameunit(sc
->dev
));
2655 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_BCN_TIME_CFG
);
2658 tmp
|= ic
->ic_bss
->ni_intval
* 16;
2659 tmp
|= (RT2860_REG_TSF_TIMER_ENABLE
| RT2860_REG_TBTT_TIMER_ENABLE
);
2661 if (ic
->ic_opmode
== IEEE80211_M_STA
)
2663 tmp
|= (RT2860_REG_TSF_SYNC_MODE_STA
<< RT2860_REG_TSF_SYNC_MODE_SHIFT
);
2665 else if (ic
->ic_opmode
== IEEE80211_M_IBSS
)
2667 tmp
|= RT2860_REG_BCN_TX_ENABLE
;
2668 tmp
|= (RT2860_REG_TSF_SYNC_MODE_IBSS
<< RT2860_REG_TSF_SYNC_MODE_SHIFT
);
2670 else if (ic
->ic_opmode
== IEEE80211_M_HOSTAP
)
2672 tmp
|= RT2860_REG_BCN_TX_ENABLE
;
2673 tmp
|= (RT2860_REG_TSF_SYNC_MODE_HOSTAP
<< RT2860_REG_TSF_SYNC_MODE_SHIFT
);
2676 rt2860_io_mac_write(sc
, RT2860_REG_BCN_TIME_CFG
, tmp
);
2680 * rt2860_asic_disable_tsf_sync
2682 static void rt2860_asic_disable_tsf_sync(struct rt2860_softc
*sc
)
2686 RT2860_DPRINTF(sc
, RT2860_DEBUG_BEACON
,
2687 "%s: disabling TSF\n",
2688 device_get_nameunit(sc
->dev
));
2690 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_BCN_TIME_CFG
);
2692 tmp
&= ~(RT2860_REG_BCN_TX_ENABLE
|
2693 RT2860_REG_TSF_TIMER_ENABLE
|
2694 RT2860_REG_TBTT_TIMER_ENABLE
);
2696 tmp
&= ~(RT2860_REG_TSF_SYNC_MODE_MASK
<< RT2860_REG_TSF_SYNC_MODE_SHIFT
);
2697 tmp
|= (RT2860_REG_TSF_SYNC_MODE_DISABLE
<< RT2860_REG_TSF_SYNC_MODE_SHIFT
);
2699 rt2860_io_mac_write(sc
, RT2860_REG_BCN_TIME_CFG
, tmp
);
2703 * rt2860_asic_enable_mrr
2705 static void rt2860_asic_enable_mrr(struct rt2860_softc
*sc
)
2707 #define CCK(mcs) (mcs)
2708 #define OFDM(mcs) ((1 << 3) | (mcs))
2709 #define HT(mcs) (mcs)
2711 rt2860_io_mac_write(sc
, RT2860_REG_TX_LG_FBK_CFG0
,
2712 (OFDM(6) << 28) | /* 54 -> 48 */
2713 (OFDM(5) << 24) | /* 48 -> 36 */
2714 (OFDM(4) << 20) | /* 36 -> 24 */
2715 (OFDM(3) << 16) | /* 24 -> 18 */
2716 (OFDM(2) << 12) | /* 18 -> 12 */
2717 (OFDM(1) << 8) | /* 12 -> 9 */
2718 (OFDM(0) << 4) | /* 9 -> 6 */
2719 OFDM(0)); /* 6 -> 6 */
2721 rt2860_io_mac_write(sc
, RT2860_REG_TX_LG_FBK_CFG1
,
2722 (CCK(2) << 12) | /* 11 -> 5.5 */
2723 (CCK(1) << 8) | /* 5.5 -> 2 */
2724 (CCK(0) << 4) | /* 2 -> 1 */
2725 CCK(0)); /* 1 -> 1 */
2727 rt2860_io_mac_write(sc
, RT2860_REG_TX_HT_FBK_CFG0
,
2737 rt2860_io_mac_write(sc
, RT2860_REG_TX_HT_FBK_CFG1
,
2753 * rt2860_asic_set_txpreamble
2755 static void rt2860_asic_set_txpreamble(struct rt2860_softc
*sc
)
2757 struct ieee80211com
*ic
;
2762 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATE
,
2763 "%s: %s short Tx preamble\n",
2764 device_get_nameunit(sc
->dev
),
2765 (ic
->ic_flags
& IEEE80211_F_SHPREAMBLE
) ? "enabling" : "disabling");
2767 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_AUTO_RSP_CFG
);
2769 tmp
&= ~RT2860_REG_CCK_SHORT_ENABLE
;
2771 if (sc
->ic
.ic_flags
& IEEE80211_F_SHPREAMBLE
)
2772 tmp
|= RT2860_REG_CCK_SHORT_ENABLE
;
2774 rt2860_io_mac_write(sc
, RT2860_REG_AUTO_RSP_CFG
, tmp
);
2778 * rt2860_asic_set_basicrates
2780 static void rt2860_asic_set_basicrates(struct rt2860_softc
*sc
)
2782 struct ieee80211com
*ic
;
2786 if (ic
->ic_curmode
== IEEE80211_MODE_11B
)
2787 rt2860_io_mac_write(sc
, RT2860_REG_LEGACY_BASIC_RATE
, 0x3);
2788 else if (ic
->ic_curmode
== IEEE80211_MODE_11A
)
2789 rt2860_io_mac_write(sc
, RT2860_REG_LEGACY_BASIC_RATE
, 0x150);
2791 rt2860_io_mac_write(sc
, RT2860_REG_LEGACY_BASIC_RATE
, 0x15f);
2795 * rt2860_asic_update_rtsthreshold
2797 static void rt2860_asic_update_rtsthreshold(struct rt2860_softc
*sc
)
2799 struct ieee80211com
*ic
;
2805 RT2860_DPRINTF(sc
, RT2860_DEBUG_PROT
,
2806 "%s: updating RTS threshold: %d\n",
2807 device_get_nameunit(sc
->dev
), ic
->ic_rtsthreshold
);
2809 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_RTS_CFG
);
2811 tmp
&= ~(RT2860_REG_TX_RTS_THRESHOLD_MASK
<< RT2860_REG_TX_RTS_THRESHOLD_SHIFT
);
2813 threshold
= (ic
->ic_rtsthreshold
< IEEE80211_RTS_MAX
) ?
2814 ic
->ic_rtsthreshold
: 0x1000;
2816 tmp
|= ((threshold
& RT2860_REG_TX_RTS_THRESHOLD_MASK
) <<
2817 RT2860_REG_TX_RTS_THRESHOLD_SHIFT
);
2819 rt2860_io_mac_write(sc
, RT2860_REG_TX_RTS_CFG
, tmp
);
2823 * rt2860_asic_update_txpower
2825 static void rt2860_asic_update_txpower(struct rt2860_softc
*sc
)
2827 struct ieee80211com
*ic
;
2828 uint32_t *txpow_rate
;
2836 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATE
,
2837 "%s: updating Tx power: %d\n",
2838 device_get_nameunit(sc
->dev
), ic
->ic_txpowlimit
);
2840 if (!IEEE80211_IS_CHAN_HT40(ic
->ic_curchan
))
2842 txpow_rate
= sc
->txpow_rate_20mhz
;
2846 if (IEEE80211_IS_CHAN_2GHZ(ic
->ic_curchan
))
2847 txpow_rate
= sc
->txpow_rate_40mhz_2ghz
;
2849 txpow_rate
= sc
->txpow_rate_40mhz_5ghz
;
2854 val
= rt2860_io_bbp_read(sc
, 1);
2857 if (ic
->ic_txpowlimit
> 90)
2861 else if (ic
->ic_txpowlimit
> 60)
2865 else if (ic
->ic_txpowlimit
> 30)
2869 else if (ic
->ic_txpowlimit
> 15)
2873 else if (ic
->ic_txpowlimit
> 9)
2883 rt2860_io_bbp_write(sc
, 1, val
);
2885 for (i
= 0; i
< RT2860_SOFTC_TXPOW_RATE_COUNT
; i
++)
2887 if (txpow_rate
[i
] == 0xffffffff)
2890 tmp
= rt2860_read_eeprom_txpow_rate_add_delta(txpow_rate
[i
], delta
);
2892 rt2860_io_mac_write(sc
, RT2860_REG_TX_PWR_CFG(i
), tmp
);
2897 * rt2860_asic_update_promisc
2899 static void rt2860_asic_update_promisc(struct rt2860_softc
*sc
)
2904 ifp
= sc
->ic
.ic_ifp
;
2906 printf("%s: %s promiscuous mode\n",
2907 device_get_nameunit(sc
->dev
),
2908 (ifp
->if_flags
& IFF_PROMISC
) ? "entering" : "leaving");
2910 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_RX_FILTER_CFG
);
2912 tmp
&= ~RT2860_REG_RX_FILTER_DROP_UC_NOME
;
2914 if (!(ifp
->if_flags
& IFF_PROMISC
))
2915 tmp
|= RT2860_REG_RX_FILTER_DROP_UC_NOME
;
2917 rt2860_io_mac_write(sc
, RT2860_REG_RX_FILTER_CFG
, tmp
);
2921 * rt2860_asic_updateprot
2923 static void rt2860_asic_updateprot(struct rt2860_softc
*sc
)
2925 struct ieee80211com
*ic
;
2926 uint32_t cck_prot
, ofdm_prot
, mm20_prot
, mm40_prot
, gf20_prot
, gf40_prot
;
2928 enum ieee80211_protmode htprotmode
;
2932 /* CCK frame protection */
2934 cck_prot
= RT2860_REG_RTSTH_ENABLE
| RT2860_REG_PROT_NAV_SHORT
|
2935 RT2860_REG_TXOP_ALLOW_ALL
| RT2860_REG_PROT_CTRL_NONE
;
2937 /* set up protection frame phy mode and rate (MCS code) */
2939 if (ic
->ic_curmode
== IEEE80211_MODE_11A
)
2940 cck_prot
|= (RT2860_REG_PROT_PHYMODE_OFDM
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
2941 (0 << RT2860_REG_PROT_MCS_SHIFT
);
2943 cck_prot
|= ((RT2860_REG_PROT_PHYMODE_CCK
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
2944 (3 << RT2860_REG_PROT_MCS_SHIFT
));
2946 rt2860_io_mac_write(sc
, RT2860_REG_TX_CCK_PROT_CFG
, cck_prot
);
2948 /* OFDM frame protection */
2950 ofdm_prot
= RT2860_REG_RTSTH_ENABLE
| RT2860_REG_PROT_NAV_SHORT
|
2951 RT2860_REG_TXOP_ALLOW_ALL
;
2953 if (ic
->ic_flags
& IEEE80211_F_USEPROT
)
2955 RT2860_DPRINTF(sc
, RT2860_DEBUG_PROT
,
2956 "%s: updating protection mode: b/g protection mode=%s\n",
2957 device_get_nameunit(sc
->dev
),
2958 (ic
->ic_protmode
== IEEE80211_PROT_RTSCTS
) ? "RTS/CTS" :
2959 ((ic
->ic_protmode
== IEEE80211_PROT_CTSONLY
) ? "CTS-to-self" : "none"));
2961 if (ic
->ic_protmode
== IEEE80211_PROT_RTSCTS
)
2962 ofdm_prot
|= RT2860_REG_PROT_CTRL_RTS_CTS
;
2963 else if (ic
->ic_protmode
== IEEE80211_PROT_CTSONLY
)
2964 ofdm_prot
|= RT2860_REG_PROT_CTRL_CTS
;
2966 ofdm_prot
|= RT2860_REG_PROT_CTRL_NONE
;
2970 RT2860_DPRINTF(sc
, RT2860_DEBUG_PROT
,
2971 "%s: updating protection mode: b/g protection mode=%s\n",
2972 device_get_nameunit(sc
->dev
), "none");
2974 ofdm_prot
|= RT2860_REG_PROT_CTRL_NONE
;
2977 rt2860_io_mac_write(sc
, RT2860_REG_TX_OFDM_PROT_CFG
, ofdm_prot
);
2979 /* HT frame protection */
2981 if ((ic
->ic_opmode
== IEEE80211_M_STA
) && (ic
->ic_state
== IEEE80211_S_RUN
))
2982 htopmode
= ic
->ic_bss
->ni_htopmode
;
2984 htopmode
= ic
->ic_curhtprotmode
;
2986 htprotmode
= ic
->ic_htprotmode
;
2988 /* force HT mixed mode and RTS/CTS protection if A-MPDU Tx aggregation is enabled */
2990 if (sc
->tx_ampdu_sessions
> 0)
2992 RT2860_DPRINTF(sc
, RT2860_DEBUG_PROT
,
2993 "%s: updating protection mode: forcing HT mixed mode and RTS/CTS protection\n",
2994 device_get_nameunit(sc
->dev
));
2996 htopmode
= IEEE80211_HTINFO_OPMODE_MIXED
;
2997 htprotmode
= IEEE80211_PROT_RTSCTS
;
3000 RT2860_DPRINTF(sc
, RT2860_DEBUG_PROT
,
3001 "%s: updating protection mode: HT operation mode=0x%02x, protection mode=%s\n",
3002 device_get_nameunit(sc
->dev
),
3003 htopmode
& IEEE80211_HTINFO_OPMODE
,
3004 (htprotmode
== IEEE80211_PROT_RTSCTS
) ? "RTS/CTS" :
3005 ((htprotmode
== IEEE80211_PROT_CTSONLY
) ? "CTS-to-self" : "none"));
3007 switch (htopmode
& IEEE80211_HTINFO_OPMODE
)
3009 /* IEEE80211_HTINFO_OPMODE_HT20PR */
3010 case IEEE80211_HTINFO_OPMODE_HT20PR
:
3011 mm20_prot
= RT2860_REG_PROT_NAV_SHORT
| RT2860_REG_PROT_CTRL_NONE
|
3012 RT2860_REG_TXOP_ALLOW_CCK
| RT2860_REG_TXOP_ALLOW_OFDM
|
3013 RT2860_REG_TXOP_ALLOW_MM20
| RT2860_REG_TXOP_ALLOW_GF20
|
3014 (RT2860_REG_PROT_PHYMODE_OFDM
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3015 (4 << RT2860_REG_PROT_MCS_SHIFT
);
3017 gf20_prot
= mm20_prot
;
3019 mm40_prot
= RT2860_REG_PROT_NAV_SHORT
| RT2860_REG_TXOP_ALLOW_ALL
|
3020 (RT2860_REG_PROT_PHYMODE_OFDM
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3021 (0x84 << RT2860_REG_PROT_MCS_SHIFT
);
3023 if (htprotmode
== IEEE80211_PROT_RTSCTS
)
3024 mm40_prot
|= RT2860_REG_PROT_CTRL_RTS_CTS
;
3025 else if (htprotmode
== IEEE80211_PROT_CTSONLY
)
3026 mm40_prot
|= RT2860_REG_PROT_CTRL_CTS
;
3028 mm40_prot
|= RT2860_REG_PROT_CTRL_NONE
;
3030 gf40_prot
= mm40_prot
;
3033 /* IEEE80211_HTINFO_OPMODE_MIXED */
3034 case IEEE80211_HTINFO_OPMODE_MIXED
:
3035 mm20_prot
= RT2860_REG_PROT_NAV_SHORT
|
3036 RT2860_REG_TXOP_ALLOW_CCK
| RT2860_REG_TXOP_ALLOW_OFDM
|
3037 RT2860_REG_TXOP_ALLOW_MM20
| RT2860_REG_TXOP_ALLOW_GF20
;
3039 if (ic
->ic_flags
& IEEE80211_F_USEPROT
)
3040 mm20_prot
|= (RT2860_REG_PROT_PHYMODE_CCK
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3041 (3 << RT2860_REG_PROT_MCS_SHIFT
);
3043 mm20_prot
|= (RT2860_REG_PROT_PHYMODE_OFDM
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3044 (4 << RT2860_REG_PROT_MCS_SHIFT
);
3046 if (htprotmode
== IEEE80211_PROT_RTSCTS
)
3047 mm20_prot
|= RT2860_REG_PROT_CTRL_RTS_CTS
;
3048 else if (htprotmode
== IEEE80211_PROT_CTSONLY
)
3049 mm20_prot
|= RT2860_REG_PROT_CTRL_CTS
;
3051 mm20_prot
|= RT2860_REG_PROT_CTRL_NONE
;
3053 gf20_prot
= mm20_prot
;
3055 mm40_prot
= RT2860_REG_PROT_NAV_SHORT
| RT2860_REG_TXOP_ALLOW_ALL
;
3057 if (ic
->ic_flags
& IEEE80211_F_USEPROT
)
3058 mm40_prot
|= (RT2860_REG_PROT_PHYMODE_CCK
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3059 (3 << RT2860_REG_PROT_MCS_SHIFT
);
3061 mm40_prot
|= (RT2860_REG_PROT_PHYMODE_OFDM
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3062 (0x84 << RT2860_REG_PROT_MCS_SHIFT
);
3064 if (htprotmode
== IEEE80211_PROT_RTSCTS
)
3065 mm40_prot
|= RT2860_REG_PROT_CTRL_RTS_CTS
;
3066 else if (htprotmode
== IEEE80211_PROT_CTSONLY
)
3067 mm40_prot
|= RT2860_REG_PROT_CTRL_CTS
;
3069 mm40_prot
|= RT2860_REG_PROT_CTRL_NONE
;
3071 gf40_prot
= mm40_prot
;
3075 * IEEE80211_HTINFO_OPMODE_PURE
3076 * IEEE80211_HTINFO_OPMODE_PROTOPT
3078 case IEEE80211_HTINFO_OPMODE_PURE
:
3079 case IEEE80211_HTINFO_OPMODE_PROTOPT
:
3081 mm20_prot
= RT2860_REG_PROT_NAV_SHORT
| RT2860_REG_PROT_CTRL_NONE
|
3082 RT2860_REG_TXOP_ALLOW_CCK
| RT2860_REG_TXOP_ALLOW_OFDM
|
3083 RT2860_REG_TXOP_ALLOW_MM20
| RT2860_REG_TXOP_ALLOW_GF20
|
3084 (RT2860_REG_PROT_PHYMODE_OFDM
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3085 (4 << RT2860_REG_PROT_MCS_SHIFT
);
3087 gf20_prot
= mm20_prot
;
3089 mm40_prot
= RT2860_REG_PROT_NAV_SHORT
| RT2860_REG_PROT_CTRL_NONE
|
3090 RT2860_REG_TXOP_ALLOW_ALL
|
3091 (RT2860_REG_PROT_PHYMODE_OFDM
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3092 (0x84 << RT2860_REG_PROT_MCS_SHIFT
);
3094 gf40_prot
= mm40_prot
;
3098 rt2860_io_mac_write(sc
, RT2860_REG_TX_MM20_PROT_CFG
, mm20_prot
);
3099 rt2860_io_mac_write(sc
, RT2860_REG_TX_MM40_PROT_CFG
, mm40_prot
);
3100 rt2860_io_mac_write(sc
, RT2860_REG_TX_GF20_PROT_CFG
, gf20_prot
);
3101 rt2860_io_mac_write(sc
, RT2860_REG_TX_GF40_PROT_CFG
, gf40_prot
);
3105 * rt2860_asic_updateslot
3107 static void rt2860_asic_updateslot(struct rt2860_softc
*sc
)
3109 struct ieee80211com
*ic
;
3114 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATE
,
3115 "%s: %s short slot time\n",
3116 device_get_nameunit(sc
->dev
),
3117 (ic
->ic_flags
& IEEE80211_F_SHSLOT
) ? "enabling" : "disabling");
3119 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_BKOFF_SLOT_CFG
);
3122 tmp
|= (ic
->ic_flags
& IEEE80211_F_SHSLOT
) ? 9 : 20;
3124 rt2860_io_mac_write(sc
, RT2860_REG_BKOFF_SLOT_CFG
, tmp
);
3128 * rt2860_asic_wme_update
3130 static void rt2860_asic_wme_update(struct rt2860_softc
*sc
)
3132 struct ieee80211com
*ic
;
3133 struct ieee80211_wme_state
*wme
;
3134 const struct wmeParams
*wmep
;
3139 wmep
= wme
->wme_chanParams
.cap_wmeParams
;
3141 RT2860_DPRINTF(sc
, RT2860_DEBUG_WME
,
3142 "%s: wme update: WME_AC_VO=%d/%d/%d/%d, WME_AC_VI=%d/%d/%d/%d, "
3143 "WME_AC_BK=%d/%d/%d/%d, WME_AC_BE=%d/%d/%d/%d\n",
3144 device_get_nameunit(sc
->dev
),
3145 wmep
[WME_AC_VO
].wmep_aifsn
,
3146 wmep
[WME_AC_VO
].wmep_logcwmin
, wmep
[WME_AC_VO
].wmep_logcwmax
,
3147 wmep
[WME_AC_VO
].wmep_txopLimit
,
3148 wmep
[WME_AC_VI
].wmep_aifsn
,
3149 wmep
[WME_AC_VI
].wmep_logcwmin
, wmep
[WME_AC_VI
].wmep_logcwmax
,
3150 wmep
[WME_AC_VI
].wmep_txopLimit
,
3151 wmep
[WME_AC_BK
].wmep_aifsn
,
3152 wmep
[WME_AC_BK
].wmep_logcwmin
, wmep
[WME_AC_BK
].wmep_logcwmax
,
3153 wmep
[WME_AC_BK
].wmep_txopLimit
,
3154 wmep
[WME_AC_BE
].wmep_aifsn
,
3155 wmep
[WME_AC_BE
].wmep_logcwmin
, wmep
[WME_AC_BE
].wmep_logcwmax
,
3156 wmep
[WME_AC_BE
].wmep_txopLimit
);
3158 for (i
= 0; i
< WME_NUM_AC
; i
++)
3159 rt2860_io_mac_write(sc
, RT2860_REG_TX_EDCA_AC_CFG(i
),
3160 (wmep
[i
].wmep_logcwmax
<< 16) | (wmep
[i
].wmep_logcwmin
<< 12) |
3161 (wmep
[i
].wmep_aifsn
<< 8) | wmep
[i
].wmep_txopLimit
);
3163 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WMM_AIFSN_CFG
,
3164 (wmep
[WME_AC_VO
].wmep_aifsn
<< 12) | (wmep
[WME_AC_VI
].wmep_aifsn
<< 8) |
3165 (wmep
[WME_AC_BK
].wmep_aifsn
<< 4) | wmep
[WME_AC_BE
].wmep_aifsn
);
3167 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WMM_CWMIN_CFG
,
3168 (wmep
[WME_AC_VO
].wmep_logcwmin
<< 12) | (wmep
[WME_AC_VI
].wmep_logcwmin
<< 8) |
3169 (wmep
[WME_AC_BK
].wmep_logcwmin
<< 4) | wmep
[WME_AC_BE
].wmep_logcwmin
);
3171 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WMM_CWMAX_CFG
,
3172 (wmep
[WME_AC_VO
].wmep_logcwmax
<< 12) | (wmep
[WME_AC_VI
].wmep_logcwmax
<< 8) |
3173 (wmep
[WME_AC_BK
].wmep_logcwmax
<< 4) | wmep
[WME_AC_BE
].wmep_logcwmax
);
3175 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WMM_TXOP0_CFG
,
3176 (wmep
[WME_AC_BK
].wmep_txopLimit
<< 16) | wmep
[WME_AC_BE
].wmep_txopLimit
);
3178 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WMM_TXOP1_CFG
,
3179 (wmep
[WME_AC_VO
].wmep_txopLimit
<< 16) | wmep
[WME_AC_VI
].wmep_txopLimit
);
3183 * rt2860_asic_update_beacon
3185 static int rt2860_asic_update_beacon(struct rt2860_softc
*sc
)
3187 struct ieee80211com
*ic
;
3189 struct rt2860_txwi txwi
;
3195 m
= ieee80211_beacon_alloc(ic
->ic_bss
, &sc
->beacon_offsets
);
3199 rate
= IEEE80211_IS_CHAN_5GHZ(ic
->ic_curchan
) ? 12 : 2;
3200 mcs
= rt2860_rate2mcs(rate
);
3202 memset(&txwi
, 0, sizeof(struct rt2860_txwi
));
3205 txwi
.pid_mpdu_len
= ((htole16(m
->m_pkthdr
.len
) & RT2860_TXWI_MPDU_LEN_MASK
) <<
3206 RT2860_TXWI_MPDU_LEN_SHIFT
);
3207 txwi
.txop
= (RT2860_TXWI_TXOP_HT
<< RT2860_TXWI_TXOP_SHIFT
);
3208 txwi
.mpdu_density_flags
|=
3209 (RT2860_TXWI_FLAGS_TS
<< RT2860_TXWI_FLAGS_SHIFT
);
3210 txwi
.bawin_size_xflags
|=
3211 (RT2860_TXWI_XFLAGS_NSEQ
<< RT2860_TXWI_XFLAGS_SHIFT
);
3215 txwi
.phymode_ifs_stbc_shortgi
=
3216 (RT2860_TXWI_PHYMODE_CCK
<< RT2860_TXWI_PHYMODE_SHIFT
);
3218 if (rate
!= 2 && (ic
->ic_flags
& IEEE80211_F_SHPREAMBLE
))
3219 mcs
|= RT2860_TXWI_MCS_SHOTPRE
;
3223 txwi
.phymode_ifs_stbc_shortgi
=
3224 (RT2860_TXWI_PHYMODE_OFDM
<< RT2860_TXWI_PHYMODE_SHIFT
);
3227 txwi
.bw_mcs
= (RT2860_TXWI_BW_20
<< RT2860_TXWI_BW_SHIFT
) |
3228 ((mcs
& RT2860_TXWI_MCS_MASK
) << RT2860_TXWI_MCS_SHIFT
);
3230 /* disable temporarily TSF sync */
3232 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_BCN_TIME_CFG
);
3234 tmp
&= ~(RT2860_REG_BCN_TX_ENABLE
|
3235 RT2860_REG_TSF_TIMER_ENABLE
|
3236 RT2860_REG_TBTT_TIMER_ENABLE
);
3238 rt2860_io_mac_write(sc
, RT2860_REG_BCN_TIME_CFG
, tmp
);
3240 /* write Tx wireless info and beacon frame to on-chip memory */
3242 rt2860_io_mac_write_multi(sc
, RT2860_REG_BEACON_BASE(0),
3243 &txwi
, sizeof(struct rt2860_txwi
));
3245 rt2860_io_mac_write_multi(sc
, RT2860_REG_BEACON_BASE(0) + sizeof(struct rt2860_txwi
),
3246 mtod(m
, uint8_t *), m
->m_pkthdr
.len
);
3248 /* enable again TSF sync */
3250 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_BCN_TIME_CFG
);
3252 tmp
|= (RT2860_REG_BCN_TX_ENABLE
|
3253 RT2860_REG_TSF_TIMER_ENABLE
|
3254 RT2860_REG_TBTT_TIMER_ENABLE
);
3256 rt2860_io_mac_write(sc
, RT2860_REG_BCN_TIME_CFG
, tmp
);
3264 * rt2860_asic_clear_keytables
3266 static void rt2860_asic_clear_keytables(struct rt2860_softc
*sc
)
3270 /* clear Rx WCID search table (entries = 256, entry size = 8) */
3272 for (i
= 0; i
< 256; i
++)
3274 rt2860_io_mac_write(sc
, RT2860_REG_WCID(i
), 0xffffffff);
3275 rt2860_io_mac_write(sc
, RT2860_REG_WCID(i
) + 4, 0x0000ffff);
3278 /* clear WCID attribute table (entries = 256, entry size = 4) */
3280 rt2860_io_mac_set_region_4(sc
, RT2860_REG_WCID_ATTR(0), 0, 256);
3282 /* clear IV/EIV table (entries = 256, entry size = 8) */
3284 rt2860_io_mac_set_region_4(sc
, RT2860_REG_IVEIV(0), 0, 2 * 256);
3286 /* clear pairwise key table (entries = 256, entry size = 32) */
3288 rt2860_io_mac_set_region_4(sc
, RT2860_REG_PKEY(0), 0, 8 * 256);
3290 /* clear shared key table (entries = 32, entry size = 32) */
3292 rt2860_io_mac_set_region_4(sc
, RT2860_REG_SKEY(0, 0), 0, 8 * 32);
3294 /* clear shared key mode (entries = 32, entry size = 2) */
3296 rt2860_io_mac_set_region_4(sc
, RT2860_REG_SKEY_MODE(0), 0, 16);
3302 static uint8_t rt2860_rxrate(struct rt2860_rxwi
*rxwi
)
3304 uint8_t mcs
, phymode
;
3307 mcs
= (rxwi
->bw_mcs
>> RT2860_RXWI_MCS_SHIFT
) & RT2860_RXWI_MCS_MASK
;
3308 phymode
= (rxwi
->phymode_stbc_shortgi
>> RT2860_RXWI_PHYMODE_SHIFT
) &
3309 RT2860_RXWI_PHYMODE_MASK
;
3315 case RT2860_RXWI_PHYMODE_CCK
:
3316 switch (mcs
& ~RT2860_RXWI_MCS_SHOTPRE
)
3318 case 0: rate
= 2; break; /* 1 Mbps */
3319 case 1: rate
= 4; break; /* 2 MBps */
3320 case 2: rate
= 11; break; /* 5.5 Mbps */
3321 case 3: rate
= 22; break; /* 11 Mbps */
3325 case RT2860_RXWI_PHYMODE_OFDM
:
3328 case 0: rate
= 12; break; /* 6 Mbps */
3329 case 1: rate
= 18; break; /* 9 Mbps */
3330 case 2: rate
= 24; break; /* 12 Mbps */
3331 case 3: rate
= 36; break; /* 18 Mbps */
3332 case 4: rate
= 48; break; /* 24 Mbps */
3333 case 5: rate
= 72; break; /* 36 Mbps */
3334 case 6: rate
= 96; break; /* 48 Mbps */
3335 case 7: rate
= 108; break; /* 54 Mbps */
3339 case RT2860_RXWI_PHYMODE_HT_MIXED
:
3340 case RT2860_RXWI_PHYMODE_HT_GF
:
3348 * rt2860_maxrssi_rxpath
3350 static uint8_t rt2860_maxrssi_rxpath(struct rt2860_softc
*sc
,
3351 const struct rt2860_rxwi
*rxwi
)
3357 if (sc
->nrxpath
> 1)
3358 if (rxwi
->rssi
[1] > rxwi
->rssi
[rxpath
])
3361 if (sc
->nrxpath
> 2)
3362 if (rxwi
->rssi
[2] > rxwi
->rssi
[rxpath
])
3371 static int8_t rt2860_rssi2dbm(struct rt2860_softc
*sc
,
3372 uint8_t rssi
, uint8_t rxpath
)
3374 struct ieee80211com
*ic
;
3375 struct ieee80211_channel
*c
;
3377 int8_t rssi_off
, lna_gain
;
3384 chan
= ieee80211_chan2ieee(ic
, c
);
3386 if (IEEE80211_IS_CHAN_5GHZ(c
))
3388 rssi_off
= sc
->rssi_off_5ghz
[rxpath
];
3391 lna_gain
= sc
->lna_gain
[1];
3392 else if (chan
<= 128)
3393 lna_gain
= sc
->lna_gain
[2];
3395 lna_gain
= sc
->lna_gain
[3];
3399 rssi_off
= sc
->rssi_off_2ghz
[rxpath
];
3400 lna_gain
= sc
->lna_gain
[0];
3403 return (-12 - rssi_off
- lna_gain
- rssi
);
3409 static uint8_t rt2860_rate2mcs(uint8_t rate
)
3436 static int rt2860_ackrate(struct ieee80211com
*ic
, int rate
)
3448 return (ic
->ic_curmode
== IEEE80211_MODE_11B
) ? 4 : rate
;
3467 /* default to 1Mbps */
3474 static uint16_t rt2860_txtime(int len
, int rate
, uint32_t flags
)
3478 if (RT2860_RATE_IS_OFDM(rate
))
3480 txtime
= (8 + 4 * len
+ 3 + rate
- 1) / rate
;
3481 txtime
= 16 + 4 + 4 * txtime
+ 6;
3485 txtime
= (16 * len
+ rate
- 1) / rate
;
3487 if (rate
!= 2 && (flags
& IEEE80211_F_SHPREAMBLE
))
3499 static int rt2860_tx_frame(struct rt2860_softc
*sc
,
3500 struct mbuf
*m
, struct ieee80211_node
*ni
, int qid
)
3502 struct ieee80211com
*ic
;
3503 struct rt2860_softc_tx_ring
*ring
;
3504 struct rt2860_softc_tx_data
*data
;
3505 struct rt2860_txdesc
*desc
;
3506 struct rt2860_txwi
*txwi
;
3507 struct ieee80211_frame
*wh
;
3508 struct ieee80211_tx_ampdu
*tx_ampdu
;
3509 struct rt2860_softc_tx_radiotap_header
*tap
;
3510 bus_dma_segment_t dma_seg
[RT2860_SOFTC_MAX_SCATTER
];
3511 u_int hdrsize
, hdrspace
;
3512 uint8_t type
, rate
, bw
, stbc
, shortgi
, mcs
, pid
, wcid
, mpdu_density
, bawin_size
, qsel
;
3513 uint16_t qos
, len
, dmalen
, mpdu_len
, dur
;
3514 int error
, hasqos
, ac
, ampdu
, ackrate
, ndmasegs
, ndescs
, i
, j
;
3516 KASSERT(qid
>= 0 && qid
< RT2860_SOFTC_TX_RING_COUNT
,
3517 ("%s: Tx frame: invalid qid=%d\n",
3518 device_get_nameunit(sc
->dev
), qid
));
3522 ring
= &sc
->tx_ring
[qid
];
3523 desc
= &ring
->desc
[ring
->desc_cur
];
3524 data
= &ring
->data
[ring
->data_cur
];
3525 txwi
= (struct rt2860_txwi
*) (ring
->seg0
+ ring
->data_cur
* RT2860_TX_DATA_SEG0_SIZE
);
3527 wh
= mtod(m
, struct ieee80211_frame
*);
3529 type
= wh
->i_fc
[0] & IEEE80211_FC0_TYPE_MASK
;
3531 hasqos
= IEEE80211_QOS_HAS_SEQ(wh
);
3534 if (IEEE80211_HAS_ADDR4(wh
))
3535 qos
= le16toh(*(const uint16_t *)
3536 (((struct ieee80211_qosframe_addr4
*) wh
)->i_qos
));
3538 qos
= le16toh(*(const uint16_t *)
3539 (((struct ieee80211_qosframe
*) wh
)->i_qos
));
3546 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
3548 if (IEEE80211_IS_MULTICAST(wh
->i_addr1
) || type
!= IEEE80211_FC0_TYPE_DATA
)
3550 else if (ic
->ic_fixed_rate
!= IEEE80211_FIXED_RATE_NONE
)
3551 rate
= ic
->ic_fixed_rate
;
3553 rate
= ni
->ni_htrates
.rs_rates
[ni
->ni_txrate
];
3557 if (IEEE80211_IS_MULTICAST(wh
->i_addr1
) || type
!= IEEE80211_FC0_TYPE_DATA
)
3558 rate
= IEEE80211_IS_CHAN_5GHZ(ic
->ic_curchan
) ? 12 : 2;
3559 else if (ic
->ic_fixed_rate
!= IEEE80211_FIXED_RATE_NONE
)
3560 rate
= ic
->ic_fixed_rate
;
3562 rate
= ni
->ni_rates
.rs_rates
[ni
->ni_txrate
];
3565 rate
&= IEEE80211_RATE_VAL
;
3567 /* fill Tx wireless info */
3569 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
3572 mcs
= rt2860_rate2mcs(rate
);
3576 /* management frames do not need encryption */
3578 wcid
= (type
== IEEE80211_FC0_TYPE_DATA
) ?
3579 RT2860_AID2WCID(ni
->ni_associd
) : 0xff;
3581 /* calculate MPDU length without padding */
3583 hdrsize
= ieee80211_hdrsize(wh
);
3584 hdrspace
= ieee80211_hdrspace(ic
, wh
);
3585 mpdu_len
= m
->m_pkthdr
.len
- hdrspace
+ hdrsize
;
3587 memset(txwi
, 0, sizeof(struct rt2860_txwi
));
3591 txwi
->pid_mpdu_len
= ((htole16(pid
) & RT2860_TXWI_PID_MASK
) <<
3592 RT2860_TXWI_PID_SHIFT
) | ((htole16(mpdu_len
) & RT2860_TXWI_MPDU_LEN_MASK
) <<
3593 RT2860_TXWI_MPDU_LEN_SHIFT
);
3595 stbc
= (ni
->ni_htcap
& IEEE80211_HTCAP_RXSTBC
) ? 1 : 0;
3597 shortgi
= (ic
->ic_flags_ext
& (IEEE80211_FEXT_SHORTGI20
| IEEE80211_FEXT_SHORTGI40
)) &&
3598 (ni
->ni_flags
& IEEE80211_NODE_HT
) && (ni
->ni_htcap
& (IEEE80211_HTCAP_SHORTGI20
| IEEE80211_HTCAP_SHORTGI40
));
3600 txwi
->phymode_ifs_stbc_shortgi
|=
3601 ((stbc
& RT2860_TXWI_STBC_MASK
) << RT2860_TXWI_STBC_SHIFT
) |
3602 ((shortgi
& RT2860_TXWI_SHORTGI_MASK
) << RT2860_TXWI_SHORTGI_SHIFT
);
3604 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
3606 txwi
->phymode_ifs_stbc_shortgi
|=
3607 (RT2860_TXWI_PHYMODE_HT_MIXED
<< RT2860_TXWI_PHYMODE_SHIFT
);
3611 if (!RT2860_RATE_IS_OFDM(rate
))
3613 txwi
->phymode_ifs_stbc_shortgi
|=
3614 (RT2860_TXWI_PHYMODE_CCK
<< RT2860_TXWI_PHYMODE_SHIFT
);
3616 if (rate
!= 2 && (ic
->ic_flags
& IEEE80211_F_SHPREAMBLE
))
3617 mcs
|= RT2860_TXWI_MCS_SHOTPRE
;
3621 txwi
->phymode_ifs_stbc_shortgi
|=
3622 (RT2860_TXWI_PHYMODE_OFDM
<< RT2860_TXWI_PHYMODE_SHIFT
);
3626 if ((ni
->ni_flags
& IEEE80211_NODE_HT
) && (ni
->ni_chw
== 40))
3627 bw
= RT2860_TXWI_BW_40
;
3629 bw
= RT2860_TXWI_BW_20
;
3631 txwi
->bw_mcs
= ((bw
& RT2860_TXWI_BW_MASK
) << RT2860_TXWI_BW_SHIFT
) |
3632 ((mcs
& RT2860_TXWI_MCS_MASK
) << RT2860_TXWI_MCS_SHIFT
);
3634 if (type
!= IEEE80211_FC0_TYPE_DATA
)
3635 txwi
->txop
= (RT2860_TXWI_TXOP_BACKOFF
<< RT2860_TXWI_TXOP_SHIFT
);
3637 txwi
->txop
= (RT2860_TXWI_TXOP_HT
<< RT2860_TXWI_TXOP_SHIFT
);
3639 /* skip ACKs for multicast frames and probe responses */
3641 if (!IEEE80211_IS_MULTICAST(wh
->i_addr1
) &&
3642 ((wh
->i_fc
[0] & (IEEE80211_FC0_TYPE_MASK
| IEEE80211_FC0_SUBTYPE_MASK
)) !=
3643 (IEEE80211_FC0_TYPE_MGT
| IEEE80211_FC0_SUBTYPE_PROBE_RESP
)) &&
3644 (!hasqos
|| (qos
& IEEE80211_QOS_ACKPOLICY
) != IEEE80211_QOS_ACKPOLICY_NOACK
))
3646 txwi
->bawin_size_xflags
|=
3647 (RT2860_TXWI_XFLAGS_ACK
<< RT2860_TXWI_XFLAGS_SHIFT
);
3649 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
3651 /* preamble + plcp + signal extension + SIFS */
3653 dur
= 16 + 4 + 6 + 10;
3657 ackrate
= rt2860_ackrate(ic
, rate
);
3659 dur
= rt2860_txtime(RT2860_ACK_SIZE
, ackrate
, ic
->ic_flags
) +
3663 *(uint16_t *) wh
->i_dur
= htole16(dur
);
3666 /* check for A-MPDU */
3668 if ((qos
& IEEE80211_QOS_ACKPOLICY
) == IEEE80211_QOS_ACKPOLICY_BA
)
3670 ac
= M_WME_GETAC(m
);
3671 tx_ampdu
= &ni
->ni_tx_ampdu
[ac
];
3673 mpdu_density
= RT2860_MS(ni
->ni_htparam
, IEEE80211_HTCAP_MPDUDENSITY
);
3674 bawin_size
= 13; //tx_ampdu->txa_wnd;
3676 txwi
->mpdu_density_flags
|=
3677 ((mpdu_density
& RT2860_TXWI_MPDU_DENSITY_MASK
) << RT2860_TXWI_MPDU_DENSITY_SHIFT
) |
3678 (RT2860_TXWI_FLAGS_AMPDU
<< RT2860_TXWI_FLAGS_SHIFT
);
3680 txwi
->bawin_size_xflags
|=
3681 ((bawin_size
& RT2860_TXWI_BAWIN_SIZE_MASK
) << RT2860_TXWI_BAWIN_SIZE_SHIFT
);
3683 if (IEEE80211_HAS_ADDR4(wh
))
3684 ((struct ieee80211_qosframe_addr4
*) wh
)->i_qos
[0] &= ~IEEE80211_QOS_ACKPOLICY
;
3686 ((struct ieee80211_qosframe
*) wh
)->i_qos
[0] &= ~IEEE80211_QOS_ACKPOLICY
;
3695 /* ask MAC to insert timestamp into probe responses */
3697 if ((wh
->i_fc
[0] & (IEEE80211_FC0_TYPE_MASK
| IEEE80211_FC0_SUBTYPE_MASK
)) ==
3698 (IEEE80211_FC0_TYPE_MGT
| IEEE80211_FC0_SUBTYPE_PROBE_RESP
))
3699 txwi
->mpdu_density_flags
|=
3700 (RT2860_TXWI_FLAGS_TS
<< RT2860_TXWI_FLAGS_SHIFT
);
3702 if (bpf_peers_present(sc
->drvbpf
))
3706 tap
->flags
= IEEE80211_RADIOTAP_F_DATAPAD
;
3707 tap
->chan_flags
= htole32(ic
->ic_curchan
->ic_flags
);
3708 tap
->chan_freq
= htole16(ic
->ic_curchan
->ic_freq
);
3709 tap
->chan_ieee
= ic
->ic_curchan
->ic_ieee
;
3710 tap
->chan_maxpow
= 0;
3712 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
3713 tap
->rate
= mcs
| IEEE80211_RATE_MCS
;
3717 if (mcs
& RT2860_TXWI_MCS_SHOTPRE
)
3718 tap
->flags
|= IEEE80211_RADIOTAP_F_SHORTPRE
;
3721 tap
->flags
|= IEEE80211_RADIOTAP_F_SHORTGI
;
3723 if (wh
->i_fc
[1] & IEEE80211_FC1_WEP
)
3724 tap
->flags
|= IEEE80211_RADIOTAP_F_WEP
;
3726 if (wh
->i_fc
[1] & IEEE80211_FC1_WEP
)
3728 wh
->i_fc
[1] &= ~IEEE80211_FC1_WEP
;
3730 bpf_mtap2(sc
->drvbpf
, tap
, sc
->txtap_len
, m
);
3732 wh
->i_fc
[1] |= IEEE80211_FC1_WEP
;
3736 bpf_mtap2(sc
->drvbpf
, tap
, sc
->txtap_len
, m
);
3740 /* copy and trim 802.11 header */
3742 m_copydata(m
, 0, hdrsize
, (caddr_t
) (txwi
+ 1));
3745 error
= bus_dmamap_load_mbuf_sg(ring
->data_dma_tag
, data
->dma_map
, m
,
3746 dma_seg
, &ndmasegs
, 0);
3749 /* too many fragments, linearize */
3751 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
3752 "%s: could not load mbuf DMA map, trying to linearize mbuf\n",
3753 device_get_nameunit(sc
->dev
));
3755 m
= m_defrag(m
, M_DONTWAIT
);
3759 sc
->tx_defrag_packets
++;
3761 error
= bus_dmamap_load_mbuf_sg(ring
->data_dma_tag
, data
->dma_map
, m
,
3762 dma_seg
, &ndmasegs
, 0);
3765 printf("%s: could not load mbuf DMA map: error=%d\n",
3766 device_get_nameunit(sc
->dev
), error
);
3772 if (m
->m_pkthdr
.len
== 0)
3775 /* determine how many Tx descs are required */
3777 ndescs
= 1 + ndmasegs
/ 2;
3778 if ((ring
->desc_queued
+ ndescs
) > (RT2860_SOFTC_TX_RING_DESC_COUNT
- 2))
3780 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
3781 "%s: there are not enough Tx descs\n",
3782 device_get_nameunit(sc
->dev
));
3784 sc
->no_tx_desc_avail
++;
3786 bus_dmamap_unload(ring
->data_dma_tag
, data
->dma_map
);
3794 /* set up Tx descs */
3796 /* first segment is Tx wireless info and 802.11 header */
3798 len
= sizeof(struct rt2860_txwi
) + hdrsize
;
3800 /* align end on a 4-bytes boundary */
3802 dmalen
= (len
+ 3) & ~ 3;
3804 memset((caddr_t
) txwi
+ len
, 0, dmalen
- len
);
3806 qsel
= RT2860_TXDESC_QSEL_EDCA
;
3808 desc
->sdp0
= htole32(ring
->seg0_phys_addr
+ ring
->data_cur
* RT2860_TX_DATA_SEG0_SIZE
);
3809 desc
->sdl0
= htole16(dmalen
);
3810 desc
->qsel_flags
= (qsel
<< RT2860_TXDESC_QSEL_SHIFT
);
3812 /* set up payload segments */
3814 for (i
= ndmasegs
, j
= 0; i
>= 2; i
-= 2)
3816 desc
->sdp1
= htole32(dma_seg
[j
].ds_addr
);
3817 desc
->sdl1
= htole16(dma_seg
[j
].ds_len
);
3819 ring
->desc_queued
++;
3820 ring
->desc_cur
= (ring
->desc_cur
+ 1) % RT2860_SOFTC_TX_RING_DESC_COUNT
;
3824 desc
= &ring
->desc
[ring
->desc_cur
];
3826 desc
->sdp0
= htole32(dma_seg
[j
].ds_addr
);
3827 desc
->sdl0
= htole16(dma_seg
[j
].ds_len
);
3828 desc
->qsel_flags
= (qsel
<< RT2860_TXDESC_QSEL_SHIFT
);
3833 /* finalize last payload segment */
3837 desc
->sdp1
= htole32(dma_seg
[j
].ds_addr
);
3838 desc
->sdl1
= htole16(dma_seg
[j
].ds_len
| RT2860_TXDESC_SDL1_LASTSEG
);
3842 desc
->sdl0
|= htole16(RT2860_TXDESC_SDL0_LASTSEG
);
3846 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
3847 "%s: sending frame: qid=%d, hdrsize=%d, hdrspace=%d, len=%d, "
3848 "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",
3849 device_get_nameunit(sc
->dev
),
3850 qid
, hdrsize
, hdrspace
, m
->m_pkthdr
.len
+ hdrsize
,
3851 bw
, stbc
, shortgi
, mcs
, wcid
, ampdu
, dmalen
, ndmasegs
,
3852 dma_seg
[0].ds_len
, dma_seg
[1].ds_len
, dma_seg
[2].ds_len
, dma_seg
[3].ds_len
, dma_seg
[4].ds_len
);
3854 bus_dmamap_sync(ring
->seg0_dma_tag
, ring
->seg0_dma_map
,
3855 BUS_DMASYNC_PREWRITE
);
3856 bus_dmamap_sync(ring
->data_dma_tag
, data
->dma_map
,
3857 BUS_DMASYNC_PREWRITE
);
3858 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
3859 BUS_DMASYNC_PREWRITE
);
3861 ring
->desc_queued
++;
3862 ring
->desc_cur
= (ring
->desc_cur
+ 1) % RT2860_SOFTC_TX_RING_DESC_COUNT
;
3864 ring
->data_queued
++;
3865 ring
->data_cur
= (ring
->data_cur
+ 1) % RT2860_SOFTC_TX_RING_DATA_COUNT
;
3869 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_CTX_IDX(qid
), ring
->desc_cur
);
3877 static int rt2860_tx_raw(struct rt2860_softc
*sc
,
3878 struct mbuf
*m
, struct ieee80211_node
*ni
,
3879 const struct ieee80211_bpf_params
*params
)
3881 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
3883 device_get_nameunit(sc
->dev
));
3891 static void rt2860_intr(void *arg
)
3893 struct rt2860_softc
*sc
;
3900 /* acknowledge interrupts */
3902 status
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_INT_STATUS
);
3903 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_INT_STATUS
, status
);
3905 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
3906 "%s: interrupt: status = 0x%08x\n",
3907 device_get_nameunit(sc
->dev
), status
);
3909 if (status
== 0xffffffff || /* device likely went away */
3910 status
== 0) /* not for us */
3915 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
3918 if (status
& RT2860_REG_INT_TX_COHERENT
)
3919 rt2860_tx_coherent_intr(sc
);
3921 if (status
& RT2860_REG_INT_RX_COHERENT
)
3922 rt2860_rx_coherent_intr(sc
);
3924 if (status
& RT2860_REG_INT_TXRX_COHERENT
)
3925 rt2860_txrx_coherent_intr(sc
);
3927 if (status
& RT2860_REG_INT_FIFO_STA_FULL
)
3928 rt2860_fifo_sta_full_intr(sc
);
3930 if (status
& RT2860_REG_INT_TX_MGMT_DONE
)
3931 rt2860_tx_intr(sc
, 5);
3933 if (status
& RT2860_REG_INT_RX_DONE
)
3936 if (status
& RT2860_REG_INT_RX_DELAY_DONE
)
3937 rt2860_rx_delay_intr(sc
);
3939 if (status
& RT2860_REG_INT_TX_HCCA_DONE
)
3940 rt2860_tx_intr(sc
, 4);
3942 if (status
& RT2860_REG_INT_TX_AC3_DONE
)
3943 rt2860_tx_intr(sc
, 3);
3945 if (status
& RT2860_REG_INT_TX_AC2_DONE
)
3946 rt2860_tx_intr(sc
, 2);
3948 if (status
& RT2860_REG_INT_TX_AC1_DONE
)
3949 rt2860_tx_intr(sc
, 1);
3951 if (status
& RT2860_REG_INT_TX_AC0_DONE
)
3952 rt2860_tx_intr(sc
, 0);
3954 if (status
& RT2860_REG_INT_TX_DELAY_DONE
)
3955 rt2860_tx_delay_intr(sc
);
3957 if (status
& RT2860_REG_INT_PRE_TBTT
)
3958 rt2860_pre_tbtt_intr(sc
);
3960 if (status
& RT2860_REG_INT_TBTT
)
3961 rt2860_tbtt_intr(sc
);
3963 if (status
& RT2860_REG_INT_MCU_CMD
)
3964 rt2860_mcu_cmd_intr(sc
);
3966 if (status
& RT2860_REG_INT_AUTO_WAKEUP
)
3967 rt2860_auto_wakeup_intr(sc
);
3969 if (status
& RT2860_REG_INT_GP_TIMER
)
3970 rt2860_gp_timer_intr(sc
);
3974 * rt2860_tx_coherent_intr
3976 static void rt2860_tx_coherent_intr(struct rt2860_softc
*sc
)
3981 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
3982 "%s: Tx coherent interrupt\n",
3983 device_get_nameunit(sc
->dev
));
3985 sc
->tx_coherent_interrupts
++;
3987 /* restart DMA engine */
3989 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
);
3991 tmp
&= ~(RT2860_REG_TX_WB_DDONE
|
3992 RT2860_REG_RX_DMA_ENABLE
|
3993 RT2860_REG_TX_DMA_ENABLE
);
3995 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
, tmp
);
3997 /* init Tx rings (4 EDCAs + HCCA + MGMT) */
3999 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
4000 rt2860_reset_tx_ring(sc
, &sc
->tx_ring
[i
]);
4002 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
4004 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_BASE_PTR(i
),
4005 sc
->tx_ring
[i
].desc_phys_addr
);
4006 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_MAX_CNT(i
),
4007 RT2860_SOFTC_TX_RING_DESC_COUNT
);
4008 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_CTX_IDX(i
), 0);
4013 rt2860_reset_rx_ring(sc
, &sc
->rx_ring
);
4015 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_BASE_PTR
,
4016 sc
->rx_ring
.desc_phys_addr
);
4017 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_MAX_CNT
,
4018 RT2860_SOFTC_RX_RING_DATA_COUNT
);
4019 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_CALC_IDX
,
4020 RT2860_SOFTC_RX_RING_DATA_COUNT
- 1);
4022 rt2860_txrx_enable(sc
);
4026 * rt2860_rx_coherent_intr
4028 static void rt2860_rx_coherent_intr(struct rt2860_softc
*sc
)
4033 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4034 "%s: Rx coherent interrupt\n",
4035 device_get_nameunit(sc
->dev
));
4037 sc
->rx_coherent_interrupts
++;
4039 /* restart DMA engine */
4041 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
);
4043 tmp
&= ~(RT2860_REG_TX_WB_DDONE
|
4044 RT2860_REG_RX_DMA_ENABLE
|
4045 RT2860_REG_TX_DMA_ENABLE
);
4047 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
, tmp
);
4049 /* init Tx rings (4 EDCAs + HCCA + MGMT) */
4051 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
4052 rt2860_reset_tx_ring(sc
, &sc
->tx_ring
[i
]);
4054 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
4056 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_BASE_PTR(i
),
4057 sc
->tx_ring
[i
].desc_phys_addr
);
4058 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_MAX_CNT(i
),
4059 RT2860_SOFTC_TX_RING_DESC_COUNT
);
4060 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_CTX_IDX(i
), 0);
4065 rt2860_reset_rx_ring(sc
, &sc
->rx_ring
);
4067 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_BASE_PTR
,
4068 sc
->rx_ring
.desc_phys_addr
);
4069 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_MAX_CNT
,
4070 RT2860_SOFTC_RX_RING_DATA_COUNT
);
4071 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_CALC_IDX
,
4072 RT2860_SOFTC_RX_RING_DATA_COUNT
- 1);
4074 rt2860_txrx_enable(sc
);
4078 * rt2860_txrx_coherent_intr
4080 static void rt2860_txrx_coherent_intr(struct rt2860_softc
*sc
)
4085 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4086 "%s: Tx/Rx coherent interrupt\n",
4087 device_get_nameunit(sc
->dev
));
4089 sc
->txrx_coherent_interrupts
++;
4091 /* restart DMA engine */
4093 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
);
4095 tmp
&= ~(RT2860_REG_TX_WB_DDONE
|
4096 RT2860_REG_RX_DMA_ENABLE
|
4097 RT2860_REG_TX_DMA_ENABLE
);
4099 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
, tmp
);
4101 /* init Tx rings (4 EDCAs + HCCA + MGMT) */
4103 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
4104 rt2860_reset_tx_ring(sc
, &sc
->tx_ring
[i
]);
4106 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
4108 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_BASE_PTR(i
),
4109 sc
->tx_ring
[i
].desc_phys_addr
);
4110 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_MAX_CNT(i
),
4111 RT2860_SOFTC_TX_RING_DESC_COUNT
);
4112 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_CTX_IDX(i
), 0);
4117 rt2860_reset_rx_ring(sc
, &sc
->rx_ring
);
4119 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_BASE_PTR
,
4120 sc
->rx_ring
.desc_phys_addr
);
4121 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_MAX_CNT
,
4122 RT2860_SOFTC_RX_RING_DATA_COUNT
);
4123 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_CALC_IDX
,
4124 RT2860_SOFTC_RX_RING_DATA_COUNT
- 1);
4126 rt2860_txrx_enable(sc
);
4130 * rt2860_fifo_sta_full_intr
4132 static void rt2860_fifo_sta_full_intr(struct rt2860_softc
*sc
)
4134 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4135 "%s: FIFO statistic full interrupt\n",
4136 device_get_nameunit(sc
->dev
));
4138 sc
->fifo_sta_full_interrupts
++;
4140 RT2860_SOFTC_LOCK(sc
);
4142 if (!(sc
->intr_disable_mask
& RT2860_REG_INT_FIFO_STA_FULL
))
4144 rt2860_intr_disable(sc
, RT2860_REG_INT_FIFO_STA_FULL
);
4146 taskqueue_enqueue(sc
->taskqueue
, &sc
->fifo_sta_full_task
);
4149 sc
->intr_pending_mask
|= RT2860_REG_INT_FIFO_STA_FULL
;
4151 RT2860_SOFTC_UNLOCK(sc
);
4157 static void rt2860_rx_intr(struct rt2860_softc
*sc
)
4159 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4160 "%s: Rx interrupt\n",
4161 device_get_nameunit(sc
->dev
));
4163 sc
->rx_interrupts
++;
4165 RT2860_SOFTC_LOCK(sc
);
4167 if (!(sc
->intr_disable_mask
& RT2860_REG_INT_RX_DONE
))
4169 rt2860_intr_disable(sc
, RT2860_REG_INT_RX_DONE
);
4171 taskqueue_enqueue(sc
->taskqueue
, &sc
->rx_done_task
);
4174 sc
->intr_pending_mask
|= RT2860_REG_INT_RX_DONE
;
4176 RT2860_SOFTC_UNLOCK(sc
);
4180 * rt2860_rx_delay_intr
4182 static void rt2860_rx_delay_intr(struct rt2860_softc
*sc
)
4184 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4185 "%s: Rx delay interrupt\n",
4186 device_get_nameunit(sc
->dev
));
4188 sc
->rx_delay_interrupts
++;
4194 static void rt2860_tx_intr(struct rt2860_softc
*sc
, int qid
)
4196 KASSERT(qid
>= 0 && qid
< RT2860_SOFTC_TX_RING_COUNT
,
4197 ("%s: Tx interrupt: invalid qid=%d\n",
4198 device_get_nameunit(sc
->dev
), qid
));
4200 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4201 "%s: Tx interrupt: qid=%d\n",
4202 device_get_nameunit(sc
->dev
), qid
);
4204 sc
->tx_interrupts
[qid
]++;
4206 RT2860_SOFTC_LOCK(sc
);
4208 if (!(sc
->intr_disable_mask
& (RT2860_REG_INT_TX_AC0_DONE
<< qid
)))
4210 rt2860_intr_disable(sc
, (RT2860_REG_INT_TX_AC0_DONE
<< qid
));
4212 taskqueue_enqueue(sc
->taskqueue
, &sc
->tx_done_task
);
4215 sc
->intr_pending_mask
|= (RT2860_REG_INT_TX_AC0_DONE
<< qid
);
4217 RT2860_SOFTC_UNLOCK(sc
);
4221 * rt2860_tx_delay_intr
4223 static void rt2860_tx_delay_intr(struct rt2860_softc
*sc
)
4225 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4226 "%s: Tx delay interrupt\n",
4227 device_get_nameunit(sc
->dev
));
4229 sc
->tx_delay_interrupts
++;
4233 * rt2860_pre_tbtt_intr
4235 static void rt2860_pre_tbtt_intr(struct rt2860_softc
*sc
)
4237 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4238 "%s: Pre-TBTT interrupt\n",
4239 device_get_nameunit(sc
->dev
));
4241 sc
->pre_tbtt_interrupts
++;
4247 static void rt2860_tbtt_intr(struct rt2860_softc
*sc
)
4249 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4250 "%s: TBTT interrupt\n",
4251 device_get_nameunit(sc
->dev
));
4253 sc
->tbtt_interrupts
++;
4257 * rt2860_mcu_cmd_intr
4259 static void rt2860_mcu_cmd_intr(struct rt2860_softc
*sc
)
4261 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4262 "%s: MCU command interrupt\n",
4263 device_get_nameunit(sc
->dev
));
4265 sc
->mcu_cmd_interrupts
++;
4269 * rt2860_auto_wakeup_intr
4271 static void rt2860_auto_wakeup_intr(struct rt2860_softc
*sc
)
4273 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4274 "%s: auto wakeup interrupt\n",
4275 device_get_nameunit(sc
->dev
));
4277 sc
->auto_wakeup_interrupts
++;
4281 * rt2860_gp_timer_intr
4283 static void rt2860_gp_timer_intr(struct rt2860_softc
*sc
)
4285 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4286 "%s: GP timer interrupt\n",
4287 device_get_nameunit(sc
->dev
));
4289 sc
->gp_timer_interrupts
++;
4293 * rt2860_rx_done_task
4295 static void rt2860_rx_done_task(void *context
, int pending
)
4297 struct rt2860_softc
*sc
;
4304 RT2860_DPRINTF(sc
, RT2860_DEBUG_RX
,
4305 "%s: Rx done task\n",
4306 device_get_nameunit(sc
->dev
));
4308 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
4311 sc
->intr_pending_mask
&= ~RT2860_REG_INT_RX_DONE
;
4313 again
= rt2860_rx_eof(sc
, sc
->rx_process_limit
);
4315 RT2860_SOFTC_LOCK(sc
);
4317 if ((sc
->intr_pending_mask
& RT2860_REG_INT_RX_DONE
) || again
)
4319 RT2860_DPRINTF(sc
, RT2860_DEBUG_RX
,
4320 "%s: Rx done task: scheduling again\n",
4321 device_get_nameunit(sc
->dev
));
4323 taskqueue_enqueue(sc
->taskqueue
, &sc
->rx_done_task
);
4327 rt2860_intr_enable(sc
, RT2860_REG_INT_RX_DONE
);
4330 RT2860_SOFTC_UNLOCK(sc
);
4334 * rt2860_tx_done_task
4336 static void rt2860_tx_done_task(void *context
, int pending
)
4338 struct rt2860_softc
*sc
;
4346 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
4347 "%s: Tx done task\n",
4348 device_get_nameunit(sc
->dev
));
4350 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
4353 for (i
= RT2860_SOFTC_TX_RING_COUNT
- 1; i
>= 0; i
--)
4355 if (sc
->intr_pending_mask
& (RT2860_REG_INT_TX_AC0_DONE
<< i
))
4357 sc
->intr_pending_mask
&= ~(RT2860_REG_INT_TX_AC0_DONE
<< i
);
4359 rt2860_tx_eof(sc
, &sc
->tx_ring
[i
]);
4365 ifp
->if_drv_flags
&= ~IFF_DRV_OACTIVE
;
4367 intr_mask
= (RT2860_REG_INT_TX_MGMT_DONE
|
4368 RT2860_REG_INT_TX_HCCA_DONE
|
4369 RT2860_REG_INT_TX_AC3_DONE
|
4370 RT2860_REG_INT_TX_AC2_DONE
|
4371 RT2860_REG_INT_TX_AC1_DONE
|
4372 RT2860_REG_INT_TX_AC0_DONE
);
4374 RT2860_SOFTC_LOCK(sc
);
4376 rt2860_intr_enable(sc
, ~sc
->intr_pending_mask
&
4377 (sc
->intr_disable_mask
& intr_mask
));
4379 if (sc
->intr_pending_mask
& intr_mask
)
4381 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
4382 "%s: Tx done task: scheduling again\n",
4383 device_get_nameunit(sc
->dev
));
4385 taskqueue_enqueue(sc
->taskqueue
, &sc
->tx_done_task
);
4388 RT2860_SOFTC_UNLOCK(sc
);
4392 * rt2860_fifo_sta_full_task
4394 static void rt2860_fifo_sta_full_task(void *context
, int pending
)
4396 struct rt2860_softc
*sc
;
4402 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATS
,
4403 "%s: FIFO statistic full task\n",
4404 device_get_nameunit(sc
->dev
));
4406 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
4409 sc
->intr_pending_mask
&= ~RT2860_REG_INT_FIFO_STA_FULL
;
4411 rt2860_drain_fifo_stats(sc
);
4413 RT2860_SOFTC_LOCK(sc
);
4415 if (sc
->intr_pending_mask
& RT2860_REG_INT_FIFO_STA_FULL
)
4417 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATS
,
4418 "%s: FIFO statistic full task: scheduling again\n",
4419 device_get_nameunit(sc
->dev
));
4421 taskqueue_enqueue(sc
->taskqueue
, &sc
->fifo_sta_full_task
);
4425 rt2860_intr_enable(sc
, RT2860_REG_INT_FIFO_STA_FULL
);
4428 RT2860_SOFTC_UNLOCK(sc
);
4432 * rt2860_periodic_task
4434 static void rt2860_periodic_task(void *context
, int pending
)
4436 struct rt2860_softc
*sc
;
4438 struct ieee80211com
*ic
;
4444 RT2860_DPRINTF(sc
, RT2860_DEBUG_PERIODIC
,
4445 "%s: periodic task: round=%lu\n",
4446 device_get_nameunit(sc
->dev
), sc
->periodic_round
);
4448 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
4451 RT2860_SOFTC_LOCK(sc
);
4453 sc
->periodic_round
++;
4455 rt2860_update_stats(sc
);
4457 if ((sc
->periodic_round
% 10) == 0)
4459 rt2860_bbp_tuning(sc
);
4461 rt2860_update_raw_counters(sc
);
4463 rt2860_watchdog(sc
);
4465 if (ic
->ic_opmode
!= IEEE80211_M_MONITOR
&& ic
->ic_state
== IEEE80211_S_RUN
)
4467 if (ic
->ic_opmode
== IEEE80211_M_STA
)
4468 rt2860_amrr_update_iter_func(sc
, ic
->ic_bss
);
4470 ieee80211_iterate_nodes(&ic
->ic_sta
, rt2860_amrr_update_iter_func
, sc
);
4474 RT2860_SOFTC_UNLOCK(sc
);
4476 callout_reset(&sc
->periodic_ch
, hz
/ 10, rt2860_periodic
, sc
);
4482 static int rt2860_rx_eof(struct rt2860_softc
*sc
, int limit
)
4484 struct ieee80211com
*ic
;
4486 struct ieee80211_frame
*wh
;
4487 struct ieee80211_node
*ni
;
4488 struct rt2860_softc_rx_radiotap_header
*tap
;
4489 struct rt2860_softc_rx_ring
*ring
;
4490 struct rt2860_rxdesc
*desc
;
4491 struct rt2860_softc_rx_data
*data
;
4492 struct rt2860_rxwi
*rxwi
;
4493 struct mbuf
*m
, *mnew
;
4494 bus_dma_segment_t segs
[1];
4495 bus_dmamap_t dma_map
;
4496 uint32_t index
, desc_flags
;
4497 uint8_t cipher_err
, rssi
, ant
, phymode
, bw
, shortgi
, mcs
;
4499 int error
, nsegs
, len
, ampdu
, amsdu
, nframes
;
4503 ring
= &sc
->rx_ring
;
4509 index
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_RX_DRX_IDX
);
4510 if (ring
->cur
== index
)
4513 desc
= &ring
->desc
[ring
->cur
];
4514 desc_flags
= le32toh(desc
->flags
);
4515 data
= &ring
->data
[ring
->cur
];
4517 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
4518 BUS_DMASYNC_POSTREAD
);
4520 if (!(desc
->sdl0
& htole16(RT2860_RXDESC_SDL0_DDONE
)))
4525 mnew
= m_getjcl(M_DONTWAIT
, MT_DATA
, M_PKTHDR
, MJUMPAGESIZE
);
4528 sc
->rx_mbuf_alloc_errors
++;
4533 mnew
->m_len
= mnew
->m_pkthdr
.len
= MJUMPAGESIZE
;
4535 error
= bus_dmamap_load_mbuf_sg(ring
->data_dma_tag
, ring
->spare_dma_map
,
4536 mnew
, segs
, &nsegs
, BUS_DMA_NOWAIT
);
4541 sc
->rx_mbuf_dmamap_errors
++;
4547 KASSERT(nsegs
== 1, ("%s: too many DMA segments",
4548 device_get_name(sc
->dev
)));
4550 bus_dmamap_sync(ring
->data_dma_tag
, data
->dma_map
,
4551 BUS_DMASYNC_POSTREAD
);
4552 bus_dmamap_unload(ring
->data_dma_tag
, data
->dma_map
);
4554 dma_map
= data
->dma_map
;
4555 data
->dma_map
= ring
->spare_dma_map
;
4556 ring
->spare_dma_map
= dma_map
;
4558 bus_dmamap_sync(ring
->data_dma_tag
, data
->dma_map
,
4559 BUS_DMASYNC_PREREAD
);
4564 desc
->sdp0
= htole32(segs
[0].ds_addr
);
4566 /* get Rx wireless info */
4568 rxwi
= mtod(m
, struct rt2860_rxwi
*);
4569 len
= (le16toh(rxwi
->tid_size
) >> RT2860_RXWI_SIZE_SHIFT
) &
4570 RT2860_RXWI_SIZE_MASK
;
4572 /* check for L2 padding between IEEE 802.11 frame header and body */
4574 if (desc_flags
& RT2860_RXDESC_FLAGS_L2PAD
)
4576 RT2860_DPRINTF(sc
, RT2860_DEBUG_RX
,
4577 "%s: L2 padding: len=%d\n",
4578 device_get_nameunit(sc
->dev
), len
);
4583 m
->m_pkthdr
.rcvif
= ifp
;
4584 m
->m_data
= (caddr_t
) (rxwi
+ 1);
4585 m
->m_pkthdr
.len
= m
->m_len
= len
;
4587 /* check for crc errors */
4589 if (desc_flags
& RT2860_RXDESC_FLAGS_CRC_ERR
)
4591 RT2860_DPRINTF(sc
, RT2860_DEBUG_RX
,
4592 "%s: rxdesc: crc error\n",
4593 device_get_nameunit(sc
->dev
));
4597 if (!(ifp
->if_flags
& IFF_PROMISC
))
4604 wh
= (struct ieee80211_frame
*) (rxwi
+ 1);
4606 /* check for cipher errors */
4608 if (desc_flags
& RT2860_RXDESC_FLAGS_DECRYPTED
)
4610 cipher_err
= ((desc_flags
>> RT2860_RXDESC_FLAGS_CIPHER_ERR_SHIFT
) &
4611 RT2860_RXDESC_FLAGS_CIPHER_ERR_MASK
);
4612 if (cipher_err
== RT2860_RXDESC_FLAGS_CIPHER_ERR_NONE
)
4614 if (wh
->i_fc
[1] & IEEE80211_FC1_WEP
)
4615 wh
->i_fc
[1] &= ~IEEE80211_FC1_WEP
;
4617 m
->m_flags
|= M_WEP
;
4621 RT2860_DPRINTF(sc
, RT2860_DEBUG_RX
,
4622 "%s: rxdesc: cipher error=0x%02x\n",
4623 device_get_nameunit(sc
->dev
), cipher_err
);
4627 if (!(ifp
->if_flags
& IFF_PROMISC
))
4636 if (wh
->i_fc
[1] & IEEE80211_FC1_WEP
)
4638 RT2860_DPRINTF(sc
, RT2860_DEBUG_RX
,
4639 "%s: rxdesc: not decrypted but protected flag set\n",
4640 device_get_nameunit(sc
->dev
));
4644 if (!(ifp
->if_flags
& IFF_PROMISC
))
4652 /* check for A-MPDU */
4654 if (desc_flags
& RT2860_RXDESC_FLAGS_AMPDU
)
4656 m
->m_flags
|= M_AMPDU
;
4667 /* check for A-MSDU */
4669 if (desc_flags
& RT2860_RXDESC_FLAGS_AMSDU
)
4680 ant
= rt2860_maxrssi_rxpath(sc
, rxwi
);
4681 rssi
= rxwi
->rssi
[ant
];
4682 rssi_dbm
= rt2860_rssi2dbm(sc
, rssi
, ant
);
4683 phymode
= ((rxwi
->phymode_stbc_shortgi
>> RT2860_RXWI_PHYMODE_SHIFT
) &
4684 RT2860_RXWI_PHYMODE_MASK
);
4685 bw
= ((rxwi
->bw_mcs
>> RT2860_RXWI_BW_SHIFT
) & RT2860_RXWI_BW_MASK
);
4686 shortgi
= ((rxwi
->phymode_stbc_shortgi
>> RT2860_RXWI_SHORTGI_SHIFT
) &
4687 RT2860_RXWI_SHORTGI_MASK
);
4688 mcs
= ((rxwi
->bw_mcs
>> RT2860_RXWI_MCS_SHIFT
) & RT2860_RXWI_MCS_MASK
);
4690 if (bpf_peers_present(sc
->drvbpf
))
4694 tap
->flags
= IEEE80211_RADIOTAP_F_DATAPAD
;
4695 tap
->dbm_antsignal
= rssi_dbm
;
4696 tap
->dbm_antnoise
= RT2860_NOISE_FLOOR
;
4698 tap
->antsignal
= rssi
;
4699 tap
->chan_flags
= htole32(ic
->ic_curchan
->ic_flags
);
4700 tap
->chan_freq
= htole16(ic
->ic_curchan
->ic_freq
);
4701 tap
->chan_ieee
= ic
->ic_curchan
->ic_ieee
;
4702 tap
->chan_maxpow
= 0;
4704 if (phymode
== RT2860_TXWI_PHYMODE_HT_MIXED
|| phymode
== RT2860_TXWI_PHYMODE_HT_GF
)
4705 tap
->rate
= mcs
| IEEE80211_RATE_MCS
;
4707 tap
->rate
= rt2860_rxrate(rxwi
);
4709 if (rxwi
->bw_mcs
& RT2860_RXWI_MCS_SHOTPRE
)
4710 tap
->flags
|= IEEE80211_RADIOTAP_F_SHORTPRE
;
4713 tap
->flags
|= IEEE80211_RADIOTAP_F_SHORTGI
;
4715 bpf_mtap2(sc
->drvbpf
, tap
, sc
->rxtap_len
, m
);
4718 RT2860_DPRINTF(sc
, RT2860_DEBUG_RX
,
4719 "%s: received frame: len=%d, phymode=%d, bw=%d, shortgi=%d, mcs=%d, "
4720 "ant=%d, rssi=%d/%d/%d, snr=%d/%d, wcid=0x%02x, ampdu=%d, amsdu=%d\n",
4721 device_get_nameunit(sc
->dev
),
4722 len
, phymode
, bw
, shortgi
, mcs
,
4723 ant
, rxwi
->rssi
[0], rxwi
->rssi
[1], rxwi
->rssi
[2],
4724 rxwi
->snr
[0], rxwi
->snr
[1],
4725 rxwi
->wcid
, ampdu
, amsdu
);
4727 ni
= ieee80211_find_rxnode(ic
, (struct ieee80211_frame_min
*) wh
);
4729 ieee80211_input(ic
, m
, ni
, rssi_dbm
, RT2860_NOISE_FLOOR
, 0);
4731 ieee80211_free_node(ni
);
4735 desc
->sdl0
&= ~htole16(RT2860_RXDESC_SDL0_DDONE
);
4737 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
4738 BUS_DMASYNC_PREREAD
| BUS_DMASYNC_PREWRITE
);
4740 ring
->cur
= (ring
->cur
+ 1) % RT2860_SOFTC_RX_RING_DATA_COUNT
;
4746 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_CALC_IDX
,
4747 RT2860_SOFTC_RX_RING_DATA_COUNT
- 1);
4749 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_CALC_IDX
,
4752 RT2860_DPRINTF(sc
, RT2860_DEBUG_RX
,
4753 "%s: Rx eof: nframes=%d\n",
4754 device_get_nameunit(sc
->dev
), nframes
);
4756 sc
->rx_packets
+= nframes
;
4758 return (limit
== 0);
4764 static void rt2860_tx_eof(struct rt2860_softc
*sc
,
4765 struct rt2860_softc_tx_ring
*ring
)
4768 struct rt2860_txdesc
*desc
;
4769 struct rt2860_softc_tx_data
*data
;
4771 int ndescs
, nframes
;
4780 index
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_TX_DTX_IDX(ring
->qid
));
4781 if (ring
->desc_next
== index
)
4786 rt2860_drain_fifo_stats(sc
);
4788 desc
= &ring
->desc
[ring
->desc_next
];
4790 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
4791 BUS_DMASYNC_POSTREAD
);
4793 if (desc
->sdl0
& htole16(RT2860_TXDESC_SDL0_LASTSEG
) ||
4794 desc
->sdl1
& htole16(RT2860_TXDESC_SDL1_LASTSEG
))
4798 data
= &ring
->data
[ring
->data_next
];
4800 if (data
->m
->m_flags
& M_TXCB
)
4801 ieee80211_process_callback(data
->ni
, data
->m
, 0);
4803 bus_dmamap_sync(ring
->data_dma_tag
, data
->dma_map
,
4804 BUS_DMASYNC_POSTWRITE
);
4805 bus_dmamap_unload(ring
->data_dma_tag
, data
->dma_map
);
4809 ieee80211_free_node(data
->ni
);
4816 RT2860_SOFTC_LOCK(sc
);
4818 ring
->data_queued
--;
4819 ring
->data_next
= (ring
->data_next
+ 1) % RT2860_SOFTC_TX_RING_DATA_COUNT
;
4821 RT2860_SOFTC_UNLOCK(sc
);
4824 desc
->sdl0
&= ~htole16(RT2860_TXDESC_SDL0_DDONE
);
4826 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
4827 BUS_DMASYNC_PREREAD
| BUS_DMASYNC_PREWRITE
);
4829 RT2860_SOFTC_LOCK(sc
);
4831 ring
->desc_queued
--;
4832 ring
->desc_next
= (ring
->desc_next
+ 1) % RT2860_SOFTC_TX_RING_DESC_COUNT
;
4834 RT2860_SOFTC_UNLOCK(sc
);
4837 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
4838 "%s: Tx eof: qid=%d, ndescs=%d, nframes=%d\n",
4839 device_get_nameunit(sc
->dev
), ring
->qid
, ndescs
, nframes
);
4843 * rt2860_update_stats
4845 static void rt2860_update_stats(struct rt2860_softc
*sc
)
4848 struct ieee80211com
*ic
;
4849 struct ieee80211_node
*ni
;
4851 int beacons
, noretryok
, retryok
, failed
;
4858 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATS
,
4859 "%s: update statistic\n",
4860 device_get_nameunit(sc
->dev
));
4862 rt2860_drain_fifo_stats(sc
);
4864 /* read and clear Tx statistic registers */
4866 rt2860_io_mac_read_multi(sc
, RT2860_REG_TX_STA_CNT0
,
4867 stacnt
, sizeof(stacnt
));
4869 stacnt
[0] = le32toh(stacnt
[0]);
4870 stacnt
[1] = le32toh(stacnt
[1]);
4871 stacnt
[2] = le32toh(stacnt
[2]);
4873 beacons
= stacnt
[0] >> 16;
4874 noretryok
= stacnt
[1] & 0xffff;
4875 retryok
= stacnt
[1] >> 16;
4876 failed
= stacnt
[0] & 0xffff;
4878 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATS
,
4879 "%s: update statistic: beacons=%d, noretryok=%d, retryok=%d, failed=%d\n",
4880 device_get_nameunit(sc
->dev
),
4881 beacons
, noretryok
, retryok
, failed
);
4883 ifp
->if_oerrors
+= failed
;
4885 sc
->tx_beacons
+= beacons
;
4886 sc
->tx_noretryok
+= noretryok
;
4887 sc
->tx_retryok
+= retryok
;
4888 sc
->tx_failed
+= failed
;
4890 if (ic
->ic_opmode
== IEEE80211_M_STA
&& ic
->ic_state
== IEEE80211_S_RUN
)
4894 associd
= (ni
!= NULL
) ? ni
->ni_associd
: 0;
4895 wcid
= RT2860_AID2WCID(associd
);
4897 rt2860_amrr_tx_update(&sc
->amrr_node
[wcid
],
4898 noretryok
+ retryok
+ failed
, noretryok
+ retryok
, retryok
+ failed
);
4905 static void rt2860_bbp_tuning(struct rt2860_softc
*sc
)
4907 struct ieee80211com
*ic
;
4908 struct ieee80211_node
*ni
;
4910 int8_t rssi
, old
, new;
4912 /* RT2860C does not support BBP tuning */
4914 if (sc
->mac_rev
== 0x28600100)
4919 if ((ic
->ic_flags
& IEEE80211_F_SCAN
) ||
4920 ic
->ic_opmode
!= IEEE80211_M_STA
|| ic
->ic_state
!= IEEE80211_S_RUN
)
4925 chan
= ieee80211_chan2ieee(ic
, ni
->ni_chan
);
4929 else if (chan
<= 64)
4931 else if (chan
<= 128)
4936 rssi
= ieee80211_getrssi(ic
);
4938 if (IEEE80211_IS_CHAN_2GHZ(ni
->ni_chan
))
4940 new = 0x2e + sc
->lna_gain
[group
];
4944 if (!IEEE80211_IS_CHAN_HT40(ni
->ni_chan
))
4945 new = 0x32 + sc
->lna_gain
[group
] * 5 / 3;
4947 new = 0x3a + sc
->lna_gain
[group
] * 5 / 3;
4950 /* Tune if absolute average RSSI is greater than -80 */
4955 old
= rt2860_io_bbp_read(sc
, 66);
4958 rt2860_io_bbp_write(sc
, 66, new);
4964 static void rt2860_watchdog(struct rt2860_softc
*sc
)
4969 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_PBF_TXRXQ_PCNT
);
4971 RT2860_DPRINTF(sc
, RT2860_DEBUG_WATCHDOG
,
4972 "%s: watchdog: TXRXQ_PCNT=0x%08x\n",
4973 device_get_nameunit(sc
->dev
), tmp
);
4975 if (((tmp
>> RT2860_REG_TX0Q_PCNT_SHIFT
) & RT2860_REG_TX0Q_PCNT_MASK
) != 0)
4977 sc
->tx_queue_not_empty
[0]++;
4979 rt2860_io_mac_write(sc
, RT2860_REG_PBF_CFG
, 0xf40012);
4981 for (ntries
= 0; ntries
< 10; ntries
++)
4983 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_PBF_TXRXQ_PCNT
);
4984 if (((tmp
>> RT2860_REG_TX0Q_PCNT_SHIFT
) & RT2860_REG_TX0Q_PCNT_MASK
) == 0)
4990 rt2860_io_mac_write(sc
, RT2860_REG_PBF_CFG
, 0xf40006);
4993 if (((tmp
>> RT2860_REG_TX1Q_PCNT_SHIFT
) & RT2860_REG_TX1Q_PCNT_MASK
) != 0)
4995 sc
->tx_queue_not_empty
[1]++;
4997 rt2860_io_mac_write(sc
, RT2860_REG_PBF_CFG
, 0xf4000a);
4999 for (ntries
= 0; ntries
< 10; ntries
++)
5001 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_PBF_TXRXQ_PCNT
);
5002 if (((tmp
>> RT2860_REG_TX1Q_PCNT_SHIFT
) & RT2860_REG_TX1Q_PCNT_MASK
) == 0)
5008 rt2860_io_mac_write(sc
, RT2860_REG_PBF_CFG
, 0xf40006);
5013 * rt2860_drain_fifo_stats
5015 static void rt2860_drain_fifo_stats(struct rt2860_softc
*sc
)
5019 uint8_t wcid
, mcs
, pid
;
5020 int ok
, agg
, retrycnt
;
5022 ifp
= sc
->ic
.ic_ifp
;
5024 /* drain Tx status FIFO (maxsize = 16) */
5026 while ((stats
= rt2860_io_mac_read(sc
, RT2860_REG_TX_STA_FIFO
)) &
5027 RT2860_REG_TX_STA_FIFO_VALID
)
5029 wcid
= (stats
>> RT2860_REG_TX_STA_FIFO_WCID_SHIFT
) &
5030 RT2860_REG_TX_STA_FIFO_WCID_MASK
;
5032 /* if no ACK was requested, no feedback is available */
5034 if (!(stats
& RT2860_REG_TX_STA_FIFO_ACK_REQ
) || wcid
== 0xff)
5037 /* update AMRR statistic */
5039 ok
= (stats
& RT2860_REG_TX_STA_FIFO_TX_OK
) ? 1 : 0;
5040 agg
= (stats
& RT2860_REG_TX_STA_FIFO_AGG
) ? 1 : 0;
5041 mcs
= (stats
>> RT2860_REG_TX_STA_FIFO_MCS_SHIFT
) &
5042 RT2860_REG_TX_STA_FIFO_MCS_MASK
;
5043 pid
= (stats
>> RT2860_REG_TX_STA_FIFO_PID_SHIFT
) &
5044 RT2860_REG_TX_STA_FIFO_PID_MASK
;
5045 retrycnt
= pid
- mcs
;
5047 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATS
,
5048 "%s: FIFO statistic: wcid=0x%02x, ok=%d, agg=%d, mcs=0x%02x, pid=0x%02x, retrycnt=%d\n",
5049 device_get_nameunit(sc
->dev
),
5050 wcid
, ok
, agg
, mcs
, pid
, retrycnt
);
5052 rt2860_amrr_tx_complete(&sc
->amrr_node
[wcid
], ok
, retrycnt
);
5060 * rt2860_update_raw_counters
5062 static void rt2860_update_raw_counters(struct rt2860_softc
*sc
)
5066 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_AGG_CNT
);
5068 sc
->tx_nonagg
+= tmp
& 0xffff;
5069 sc
->tx_agg
+= tmp
>> 16;
5071 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_AGG_CNT0
);
5073 sc
->tx_ampdu
+= (tmp
& 0xffff) / 1 + (tmp
>> 16) / 2;
5075 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_AGG_CNT1
);
5077 sc
->tx_ampdu
+= (tmp
& 0xffff) / 3 + (tmp
>> 16) / 4;
5079 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_AGG_CNT2
);
5081 sc
->tx_ampdu
+= (tmp
& 0xffff) / 5 + (tmp
>> 16) / 6;
5083 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_AGG_CNT3
);
5085 sc
->tx_ampdu
+= (tmp
& 0xffff) / 7 + (tmp
>> 16) / 8;
5087 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_AGG_CNT4
);
5089 sc
->tx_ampdu
+= (tmp
& 0xffff) / 9 + (tmp
>> 16) / 10;
5091 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_AGG_CNT5
);
5093 sc
->tx_ampdu
+= (tmp
& 0xffff) / 11 + (tmp
>> 16) / 12;
5095 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_AGG_CNT6
);
5097 sc
->tx_ampdu
+= (tmp
& 0xffff) / 13 + (tmp
>> 16) / 14;
5099 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_AGG_CNT7
);
5101 sc
->tx_ampdu
+= (tmp
& 0xffff) / 15 + (tmp
>> 16) / 16;
5103 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_RX_STA_CNT0
);
5105 sc
->rx_crc_errors
+= tmp
& 0xffff;
5106 sc
->rx_phy_errors
+= tmp
>> 16;
5108 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_RX_STA_CNT1
);
5110 sc
->rx_false_ccas
+= tmp
& 0xffff;
5111 sc
->rx_plcp_errors
+= tmp
>> 16;
5113 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_RX_STA_CNT2
);
5115 sc
->rx_dup_packets
+= tmp
& 0xffff;
5116 sc
->rx_fifo_overflows
+= tmp
>> 16;
5120 * rt2860_intr_enable
5122 static void rt2860_intr_enable(struct rt2860_softc
*sc
, uint32_t intr_mask
)
5126 sc
->intr_disable_mask
&= ~intr_mask
;
5128 tmp
= sc
->intr_enable_mask
& ~sc
->intr_disable_mask
;
5130 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_INT_MASK
, tmp
);
5134 * rt2860_intr_disable
5136 static void rt2860_intr_disable(struct rt2860_softc
*sc
, uint32_t intr_mask
)
5140 sc
->intr_disable_mask
|= intr_mask
;
5142 tmp
= sc
->intr_enable_mask
& ~sc
->intr_disable_mask
;
5144 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_INT_MASK
, tmp
);
5148 * rt2860_txrx_enable
5150 static int rt2860_txrx_enable(struct rt2860_softc
*sc
)
5152 struct ieee80211com
*ic
;
5160 /* enable Tx/Rx DMA engine */
5162 rt2860_io_mac_write(sc
, RT2860_REG_SYS_CTRL
, RT2860_REG_TX_ENABLE
);
5164 for (ntries
= 0; ntries
< 200; ntries
++)
5166 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
);
5167 if (!(tmp
& (RT2860_REG_TX_DMA_BUSY
| RT2860_REG_RX_DMA_BUSY
)))
5175 printf("%s: timeout waiting for DMA engine\n",
5176 device_get_nameunit(sc
->dev
));
5182 tmp
|= RT2860_REG_TX_WB_DDONE
|
5183 RT2860_REG_RX_DMA_ENABLE
|
5184 RT2860_REG_TX_DMA_ENABLE
|
5185 (RT2860_REG_WPDMA_BT_SIZE64
<< RT2860_REG_WPDMA_BT_SIZE_SHIFT
);
5187 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
, tmp
);
5191 tmp
= RT2860_REG_RX_FILTER_DROP_CRC_ERR
|
5192 RT2860_REG_RX_FILTER_DROP_PHY_ERR
;
5194 if (ic
->ic_opmode
!= IEEE80211_M_MONITOR
)
5196 tmp
|= RT2860_REG_RX_FILTER_DROP_DUPL
|
5197 RT2860_REG_RX_FILTER_DROP_CTS
|
5198 RT2860_REG_RX_FILTER_DROP_BA
|
5199 RT2860_REG_RX_FILTER_DROP_ACK
|
5200 RT2860_REG_RX_FILTER_DROP_VER_ERR
|
5201 RT2860_REG_RX_FILTER_DROP_CTRL_RSV
|
5202 RT2860_REG_RX_FILTER_DROP_CFACK
|
5203 RT2860_REG_RX_FILTER_DROP_CFEND
;
5205 if (ic
->ic_opmode
== IEEE80211_M_STA
)
5206 tmp
|= RT2860_REG_RX_FILTER_DROP_RTS
|
5207 RT2860_REG_RX_FILTER_DROP_PSPOLL
;
5209 if (!(ifp
->if_flags
& IFF_PROMISC
))
5210 tmp
|= RT2860_REG_RX_FILTER_DROP_UC_NOME
;
5213 rt2860_io_mac_write(sc
, RT2860_REG_RX_FILTER_CFG
, tmp
);
5215 rt2860_io_mac_write(sc
, RT2860_REG_SYS_CTRL
,
5216 RT2860_REG_RX_ENABLE
| RT2860_REG_TX_ENABLE
);
5222 * rt2860_alloc_rx_ring
5224 static int rt2860_alloc_rx_ring(struct rt2860_softc
*sc
,
5225 struct rt2860_softc_rx_ring
*ring
)
5227 struct rt2860_rxdesc
*desc
;
5228 struct rt2860_softc_rx_data
*data
;
5229 bus_dma_segment_t segs
[1];
5230 int i
, nsegs
, error
;
5232 error
= bus_dma_tag_create(bus_get_dma_tag(sc
->dev
), PAGE_SIZE
, 0,
5233 BUS_SPACE_MAXADDR_32BIT
, BUS_SPACE_MAXADDR
, NULL
, NULL
,
5234 RT2860_SOFTC_RX_RING_DATA_COUNT
* sizeof(struct rt2860_rxdesc
), 1,
5235 RT2860_SOFTC_RX_RING_DATA_COUNT
* sizeof(struct rt2860_rxdesc
),
5236 0, NULL
, NULL
, &ring
->desc_dma_tag
);
5239 printf("%s: could not create Rx desc DMA tag\n",
5240 device_get_nameunit(sc
->dev
));
5244 error
= bus_dmamem_alloc(ring
->desc_dma_tag
, (void **) &ring
->desc
,
5245 BUS_DMA_NOWAIT
| BUS_DMA_ZERO
, &ring
->desc_dma_map
);
5248 printf("%s: could not allocate Rx desc DMA memory\n",
5249 device_get_nameunit(sc
->dev
));
5253 error
= bus_dmamap_load(ring
->desc_dma_tag
, ring
->desc_dma_map
,
5255 RT2860_SOFTC_RX_RING_DATA_COUNT
* sizeof(struct rt2860_rxdesc
),
5256 rt2860_dma_map_addr
, &ring
->desc_phys_addr
, 0);
5259 printf("%s: could not load Rx desc DMA map\n",
5260 device_get_nameunit(sc
->dev
));
5264 error
= bus_dma_tag_create(bus_get_dma_tag(sc
->dev
), PAGE_SIZE
, 0,
5265 BUS_SPACE_MAXADDR_32BIT
, BUS_SPACE_MAXADDR
, NULL
, NULL
,
5266 MJUMPAGESIZE
, 1, MJUMPAGESIZE
, 0, NULL
, NULL
,
5267 &ring
->data_dma_tag
);
5270 printf("%s: could not create Rx data DMA tag\n",
5271 device_get_nameunit(sc
->dev
));
5275 for (i
= 0; i
< RT2860_SOFTC_RX_RING_DATA_COUNT
; i
++)
5277 desc
= &ring
->desc
[i
];
5278 data
= &ring
->data
[i
];
5280 error
= bus_dmamap_create(ring
->data_dma_tag
, 0, &data
->dma_map
);
5283 printf("%s: could not create Rx data DMA map\n",
5284 device_get_nameunit(sc
->dev
));
5288 data
->m
= m_getjcl(M_DONTWAIT
, MT_DATA
, M_PKTHDR
, MJUMPAGESIZE
);
5289 if (data
->m
== NULL
)
5291 printf("%s: could not allocate Rx mbuf\n",
5292 device_get_nameunit(sc
->dev
));
5297 data
->m
->m_len
= data
->m
->m_pkthdr
.len
= MJUMPAGESIZE
;
5299 error
= bus_dmamap_load_mbuf_sg(ring
->data_dma_tag
, data
->dma_map
,
5300 data
->m
, segs
, &nsegs
, BUS_DMA_NOWAIT
);
5303 printf("%s: could not load Rx mbuf DMA map\n",
5304 device_get_nameunit(sc
->dev
));
5308 KASSERT(nsegs
== 1, ("%s: too many DMA segments",
5309 device_get_name(sc
->dev
)));
5311 desc
->sdp0
= htole32(segs
[0].ds_addr
);
5312 desc
->sdl0
= htole16(MJUMPAGESIZE
);
5315 error
= bus_dmamap_create(ring
->data_dma_tag
, 0, &ring
->spare_dma_map
);
5318 printf("%s: could not create Rx spare DMA map\n",
5319 device_get_nameunit(sc
->dev
));
5323 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
5324 BUS_DMASYNC_PREWRITE
);
5330 rt2860_free_rx_ring(sc
, ring
);
5336 * rt2860_reset_rx_ring
5338 static void rt2860_reset_rx_ring(struct rt2860_softc
*sc
,
5339 struct rt2860_softc_rx_ring
*ring
)
5341 struct rt2860_rxdesc
*desc
;
5344 for (i
= 0; i
< RT2860_SOFTC_RX_RING_DATA_COUNT
; i
++)
5346 desc
= &ring
->desc
[i
];
5348 desc
->sdl0
&= ~htole16(RT2860_RXDESC_SDL0_DDONE
);
5351 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
5352 BUS_DMASYNC_PREWRITE
);
5358 * rt2860_free_rx_ring
5360 static void rt2860_free_rx_ring(struct rt2860_softc
*sc
,
5361 struct rt2860_softc_rx_ring
*ring
)
5363 struct rt2860_softc_rx_data
*data
;
5366 if (ring
->desc
!= NULL
)
5368 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
5369 BUS_DMASYNC_POSTWRITE
);
5370 bus_dmamap_unload(ring
->desc_dma_tag
, ring
->desc_dma_map
);
5371 bus_dmamem_free(ring
->desc_dma_tag
, ring
->desc
,
5372 ring
->desc_dma_map
);
5375 if (ring
->desc_dma_tag
!= NULL
)
5376 bus_dma_tag_destroy(ring
->desc_dma_tag
);
5378 for (i
= 0; i
< RT2860_SOFTC_RX_RING_DATA_COUNT
; i
++)
5380 data
= &ring
->data
[i
];
5382 if (data
->m
!= NULL
)
5384 bus_dmamap_sync(ring
->data_dma_tag
, data
->dma_map
,
5385 BUS_DMASYNC_POSTREAD
);
5386 bus_dmamap_unload(ring
->data_dma_tag
, data
->dma_map
);
5390 if (data
->dma_map
!= NULL
)
5391 bus_dmamap_destroy(ring
->data_dma_tag
, data
->dma_map
);
5394 if (ring
->spare_dma_map
!= NULL
)
5395 bus_dmamap_destroy(ring
->data_dma_tag
, ring
->spare_dma_map
);
5397 if (ring
->data_dma_tag
!= NULL
)
5398 bus_dma_tag_destroy(ring
->data_dma_tag
);
5402 * rt2860_alloc_tx_ring
5404 static int rt2860_alloc_tx_ring(struct rt2860_softc
*sc
,
5405 struct rt2860_softc_tx_ring
*ring
, int qid
)
5407 struct rt2860_softc_tx_data
*data
;
5410 error
= bus_dma_tag_create(bus_get_dma_tag(sc
->dev
), PAGE_SIZE
, 0,
5411 BUS_SPACE_MAXADDR_32BIT
, BUS_SPACE_MAXADDR
, NULL
, NULL
,
5412 RT2860_SOFTC_TX_RING_DESC_COUNT
* sizeof(struct rt2860_txdesc
), 1,
5413 RT2860_SOFTC_TX_RING_DESC_COUNT
* sizeof(struct rt2860_txdesc
),
5414 0, NULL
, NULL
, &ring
->desc_dma_tag
);
5417 printf("%s: could not create Tx desc DMA tag\n",
5418 device_get_nameunit(sc
->dev
));
5422 error
= bus_dmamem_alloc(ring
->desc_dma_tag
, (void **) &ring
->desc
,
5423 BUS_DMA_NOWAIT
| BUS_DMA_ZERO
, &ring
->desc_dma_map
);
5426 printf("%s: could not allocate Tx desc DMA memory\n",
5427 device_get_nameunit(sc
->dev
));
5431 error
= bus_dmamap_load(ring
->desc_dma_tag
, ring
->desc_dma_map
,
5433 RT2860_SOFTC_TX_RING_DESC_COUNT
* sizeof(struct rt2860_txdesc
),
5434 rt2860_dma_map_addr
, &ring
->desc_phys_addr
, 0);
5437 printf("%s: could not load Tx desc DMA map\n",
5438 device_get_nameunit(sc
->dev
));
5442 ring
->desc_queued
= 0;
5444 ring
->desc_next
= 0;
5446 error
= bus_dma_tag_create(bus_get_dma_tag(sc
->dev
), PAGE_SIZE
, 0,
5447 BUS_SPACE_MAXADDR_32BIT
, BUS_SPACE_MAXADDR
, NULL
, NULL
,
5448 RT2860_SOFTC_TX_RING_DATA_COUNT
* RT2860_TX_DATA_SEG0_SIZE
, 1,
5449 RT2860_SOFTC_TX_RING_DATA_COUNT
* RT2860_TX_DATA_SEG0_SIZE
,
5450 0, NULL
, NULL
, &ring
->seg0_dma_tag
);
5453 printf("%s: could not create Tx seg0 DMA tag\n",
5454 device_get_nameunit(sc
->dev
));
5458 error
= bus_dmamem_alloc(ring
->seg0_dma_tag
, (void **) &ring
->seg0
,
5459 BUS_DMA_NOWAIT
| BUS_DMA_ZERO
, &ring
->seg0_dma_map
);
5462 printf("%s: could not allocate Tx seg0 DMA memory\n",
5463 device_get_nameunit(sc
->dev
));
5467 error
= bus_dmamap_load(ring
->seg0_dma_tag
, ring
->seg0_dma_map
,
5469 RT2860_SOFTC_TX_RING_DATA_COUNT
* RT2860_TX_DATA_SEG0_SIZE
,
5470 rt2860_dma_map_addr
, &ring
->seg0_phys_addr
, 0);
5473 printf("%s: could not load Tx seg0 DMA map\n",
5474 device_get_nameunit(sc
->dev
));
5478 error
= bus_dma_tag_create(bus_get_dma_tag(sc
->dev
), PAGE_SIZE
, 0,
5479 BUS_SPACE_MAXADDR_32BIT
, BUS_SPACE_MAXADDR
, NULL
, NULL
,
5480 MJUMPAGESIZE
, RT2860_SOFTC_MAX_SCATTER
, MJUMPAGESIZE
, 0, NULL
, NULL
,
5481 &ring
->data_dma_tag
);
5484 printf("%s: could not create Tx data DMA tag\n",
5485 device_get_nameunit(sc
->dev
));
5489 for (i
= 0; i
< RT2860_SOFTC_TX_RING_DATA_COUNT
; i
++)
5491 data
= &ring
->data
[i
];
5493 error
= bus_dmamap_create(ring
->data_dma_tag
, 0, &data
->dma_map
);
5496 printf("%s: could not create Tx data DMA map\n",
5497 device_get_nameunit(sc
->dev
));
5502 ring
->data_queued
= 0;
5504 ring
->data_next
= 0;
5512 rt2860_free_tx_ring(sc
, ring
);
5518 * rt2860_reset_tx_ring
5520 static void rt2860_reset_tx_ring(struct rt2860_softc
*sc
,
5521 struct rt2860_softc_tx_ring
*ring
)
5523 struct rt2860_softc_tx_data
*data
;
5524 struct rt2860_txdesc
*desc
;
5527 for (i
= 0; i
< RT2860_SOFTC_TX_RING_DESC_COUNT
; i
++)
5529 desc
= &ring
->desc
[i
];
5535 ring
->desc_queued
= 0;
5537 ring
->desc_next
= 0;
5539 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
5540 BUS_DMASYNC_PREWRITE
);
5542 bus_dmamap_sync(ring
->seg0_dma_tag
, ring
->seg0_dma_map
,
5543 BUS_DMASYNC_PREWRITE
);
5545 for (i
= 0; i
< RT2860_SOFTC_TX_RING_DATA_COUNT
; i
++)
5547 data
= &ring
->data
[i
];
5549 if (data
->m
!= NULL
)
5551 bus_dmamap_sync(ring
->data_dma_tag
, data
->dma_map
,
5552 BUS_DMASYNC_POSTWRITE
);
5553 bus_dmamap_unload(ring
->data_dma_tag
, data
->dma_map
);
5558 if (data
->ni
!= NULL
)
5560 ieee80211_free_node(data
->ni
);
5565 ring
->data_queued
= 0;
5567 ring
->data_next
= 0;
5571 * rt2860_free_tx_ring
5573 static void rt2860_free_tx_ring(struct rt2860_softc
*sc
,
5574 struct rt2860_softc_tx_ring
*ring
)
5576 struct rt2860_softc_tx_data
*data
;
5579 if (ring
->desc
!= NULL
)
5581 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
5582 BUS_DMASYNC_POSTWRITE
);
5583 bus_dmamap_unload(ring
->desc_dma_tag
, ring
->desc_dma_map
);
5584 bus_dmamem_free(ring
->desc_dma_tag
, ring
->desc
,
5585 ring
->desc_dma_map
);
5588 if (ring
->desc_dma_tag
!= NULL
)
5589 bus_dma_tag_destroy(ring
->desc_dma_tag
);
5591 if (ring
->seg0
!= NULL
)
5593 bus_dmamap_sync(ring
->seg0_dma_tag
, ring
->seg0_dma_map
,
5594 BUS_DMASYNC_POSTWRITE
);
5595 bus_dmamap_unload(ring
->seg0_dma_tag
, ring
->seg0_dma_map
);
5596 bus_dmamem_free(ring
->seg0_dma_tag
, ring
->seg0
,
5597 ring
->seg0_dma_map
);
5600 if (ring
->seg0_dma_tag
!= NULL
)
5601 bus_dma_tag_destroy(ring
->seg0_dma_tag
);
5603 for (i
= 0; i
< RT2860_SOFTC_TX_RING_DATA_COUNT
; i
++)
5605 data
= &ring
->data
[i
];
5607 if (data
->m
!= NULL
)
5609 bus_dmamap_sync(ring
->data_dma_tag
, data
->dma_map
,
5610 BUS_DMASYNC_POSTWRITE
);
5611 bus_dmamap_unload(ring
->data_dma_tag
, data
->dma_map
);
5615 if (data
->ni
!= NULL
)
5616 ieee80211_free_node(data
->ni
);
5618 if (data
->dma_map
!= NULL
)
5619 bus_dmamap_destroy(ring
->data_dma_tag
, data
->dma_map
);
5622 if (ring
->data_dma_tag
!= NULL
)
5623 bus_dma_tag_destroy(ring
->data_dma_tag
);
5627 * rt2860_dma_map_addr
5629 static void rt2860_dma_map_addr(void *arg
, bus_dma_segment_t
*segs
,
5630 int nseg
, int error
)
5635 KASSERT(nseg
== 1, ("too many DMA segments, %d should be 1", nseg
));
5637 *(bus_addr_t
*) arg
= segs
[0].ds_addr
;
5641 * rt2860_sysctl_attach
5643 static void rt2860_sysctl_attach(struct rt2860_softc
*sc
)
5645 struct sysctl_ctx_list
*ctx
;
5646 struct sysctl_oid
*tree
;
5647 struct sysctl_oid
*stats
;
5649 ctx
= device_get_sysctl_ctx(sc
->dev
);
5650 tree
= device_get_sysctl_tree(sc
->dev
);
5652 stats
= SYSCTL_ADD_NODE(ctx
, SYSCTL_CHILDREN(tree
), OID_AUTO
,
5653 "stats", CTLFLAG_RD
, 0, "statistic");
5655 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5656 "interrupts", CTLFLAG_RD
, &sc
->interrupts
, 0,
5659 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5660 "tx_coherent_interrupts", CTLFLAG_RD
, &sc
->tx_coherent_interrupts
, 0,
5661 "Tx coherent interrupts");
5663 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5664 "rx_coherent_interrupts", CTLFLAG_RD
, &sc
->rx_coherent_interrupts
, 0,
5665 "Rx coherent interrupts");
5667 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5668 "txrx_coherent_interrupts", CTLFLAG_RD
, &sc
->txrx_coherent_interrupts
, 0,
5669 "Tx/Rx coherent interrupts");
5671 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5672 "fifo_sta_full_interrupts", CTLFLAG_RD
, &sc
->fifo_sta_full_interrupts
, 0,
5673 "FIFO statistic full interrupts");
5675 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5676 "rx_interrupts", CTLFLAG_RD
, &sc
->rx_interrupts
, 0,
5679 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5680 "rx_delay_interrupts", CTLFLAG_RD
, &sc
->rx_delay_interrupts
, 0,
5681 "Rx delay interrupts");
5683 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5684 "tx_mgmt_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[5], 0,
5685 "Tx MGMT interrupts");
5687 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5688 "tx_hcca_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[4], 0,
5689 "Tx HCCA interrupts");
5691 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5692 "tx_ac3_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[3], 0,
5693 "Tx AC3 interrupts");
5695 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5696 "tx_ac2_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[2], 0,
5697 "Tx AC2 interrupts");
5699 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5700 "tx_ac1_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[1], 0,
5701 "Tx AC1 interrupts");
5703 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5704 "tx_ac0_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[0], 0,
5705 "Tx AC0 interrupts");
5707 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5708 "tx_delay_interrupts", CTLFLAG_RD
, &sc
->tx_delay_interrupts
, 0,
5709 "Tx delay interrupts");
5711 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5712 "pre_tbtt_interrupts", CTLFLAG_RD
, &sc
->pre_tbtt_interrupts
, 0,
5713 "Pre-TBTT interrupts");
5715 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5716 "tbtt_interrupts", CTLFLAG_RD
, &sc
->tbtt_interrupts
, 0,
5719 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5720 "mcu_cmd_interrupts", CTLFLAG_RD
, &sc
->mcu_cmd_interrupts
, 0,
5721 "MCU command interrupts");
5723 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5724 "auto_wakeup_interrupts", CTLFLAG_RD
, &sc
->auto_wakeup_interrupts
, 0,
5725 "auto wakeup interrupts");
5727 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5728 "gp_timer_interrupts", CTLFLAG_RD
, &sc
->gp_timer_interrupts
, 0,
5729 "GP timer interrupts");
5731 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5732 "tx_mgmt_desc_queued", CTLFLAG_RD
, &sc
->tx_ring
[5].desc_queued
, 0,
5733 "Tx MGMT descriptors queued");
5735 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5736 "tx_mgmt_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[5].data_queued
, 0,
5737 "Tx MGMT data queued");
5739 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5740 "tx_hcca_desc_queued", CTLFLAG_RD
, &sc
->tx_ring
[4].desc_queued
, 0,
5741 "Tx HCCA descriptors queued");
5743 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5744 "tx_hcca_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[4].data_queued
, 0,
5745 "Tx HCCA data queued");
5747 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5748 "tx_ac3_desc_queued", CTLFLAG_RD
, &sc
->tx_ring
[3].desc_queued
, 0,
5749 "Tx AC3 descriptors queued");
5751 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5752 "tx_ac3_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[3].data_queued
, 0,
5753 "Tx AC3 data queued");
5755 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5756 "tx_ac2_desc_queued", CTLFLAG_RD
, &sc
->tx_ring
[2].desc_queued
, 0,
5757 "Tx AC2 descriptors queued");
5759 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5760 "tx_ac2_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[2].data_queued
, 0,
5761 "Tx AC2 data queued");
5763 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5764 "tx_ac1_desc_queued", CTLFLAG_RD
, &sc
->tx_ring
[1].desc_queued
, 0,
5765 "Tx AC1 descriptors queued");
5767 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5768 "tx_ac1_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[1].data_queued
, 0,
5769 "Tx AC1 data queued");
5771 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5772 "tx_ac0_desc_queued", CTLFLAG_RD
, &sc
->tx_ring
[0].desc_queued
, 0,
5773 "Tx AC0 descriptors queued");
5775 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5776 "tx_ac0_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[0].data_queued
, 0,
5777 "Tx AC0 data queued");
5779 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5780 "tx_mgmt_data_queue_full", CTLFLAG_RD
, &sc
->tx_data_queue_full
[5], 0,
5781 "Tx MGMT data queue full");
5783 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5784 "tx_hcca_data_queue_full", CTLFLAG_RD
, &sc
->tx_data_queue_full
[4], 0,
5785 "Tx HCCA data queue full");
5787 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5788 "tx_ac3_data_queue_full", CTLFLAG_RD
, &sc
->tx_data_queue_full
[3], 0,
5789 "Tx AC3 data queue full");
5791 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5792 "tx_ac2_data_queue_full", CTLFLAG_RD
, &sc
->tx_data_queue_full
[2], 0,
5793 "Tx AC2 data queue full");
5795 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5796 "tx_ac1_data_queue_full", CTLFLAG_RD
, &sc
->tx_data_queue_full
[1], 0,
5797 "Tx AC1 data queue full");
5799 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5800 "tx_ac0_data_queue_full", CTLFLAG_RD
, &sc
->tx_data_queue_full
[0], 0,
5801 "Tx AC0 data queue full");
5803 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5804 "tx_watchdog_timeouts", CTLFLAG_RD
, &sc
->tx_watchdog_timeouts
, 0,
5805 "Tx watchdog timeouts");
5807 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5808 "tx_defrag_packets", CTLFLAG_RD
, &sc
->tx_defrag_packets
, 0,
5809 "Tx defragmented packets");
5811 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5812 "no_tx_desc_avail", CTLFLAG_RD
, &sc
->no_tx_desc_avail
, 0,
5813 "no Tx descriptors available");
5815 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5816 "rx_mbuf_alloc_errors", CTLFLAG_RD
, &sc
->rx_mbuf_alloc_errors
, 0,
5817 "Rx mbuf allocation errors");
5819 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5820 "rx_mbuf_dmamap_errors", CTLFLAG_RD
, &sc
->rx_mbuf_dmamap_errors
, 0,
5821 "Rx mbuf DMA mapping errors");
5823 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5824 "tx_queue_0_not_empty", CTLFLAG_RD
, &sc
->tx_queue_not_empty
[0], 0,
5825 "Tx queue 0 not empty");
5827 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5828 "tx_queue_1_not_empty", CTLFLAG_RD
, &sc
->tx_queue_not_empty
[1], 0,
5829 "Tx queue 1 not empty");
5831 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5832 "tx_beacons", CTLFLAG_RD
, &sc
->tx_beacons
, 0,
5835 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5836 "tx_noretryok", CTLFLAG_RD
, &sc
->tx_noretryok
, 0,
5837 "Tx successfull without retries");
5839 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5840 "tx_retryok", CTLFLAG_RD
, &sc
->tx_retryok
, 0,
5841 "Tx successfull with retries");
5843 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5844 "tx_failed", CTLFLAG_RD
, &sc
->tx_failed
, 0,
5847 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5848 "tx_nonagg", CTLFLAG_RD
, &sc
->tx_nonagg
, 0,
5849 "Tx non-aggregated");
5851 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5852 "tx_agg", CTLFLAG_RD
, &sc
->tx_agg
, 0,
5855 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5856 "tx_ampdu", CTLFLAG_RD
, &sc
->tx_ampdu
, 0,
5859 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5860 "rx_packets", CTLFLAG_RD
, &sc
->rx_packets
, 0,
5863 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5864 "rx_ampdu", CTLFLAG_RD
, &sc
->rx_ampdu
, 0,
5867 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5868 "rx_amsdu", CTLFLAG_RD
, &sc
->rx_amsdu
, 0,
5871 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5872 "rx_crc_errors", CTLFLAG_RD
, &sc
->rx_crc_errors
, 0,
5875 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5876 "rx_phy_errors", CTLFLAG_RD
, &sc
->rx_phy_errors
, 0,
5879 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5880 "rx_false_ccas", CTLFLAG_RD
, &sc
->rx_false_ccas
, 0,
5883 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5884 "rx_plcp_errors", CTLFLAG_RD
, &sc
->rx_plcp_errors
, 0,
5887 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5888 "rx_dup_packets", CTLFLAG_RD
, &sc
->rx_dup_packets
, 0,
5889 "Rx duplicate packets");
5891 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5892 "rx_fifo_overflows", CTLFLAG_RD
, &sc
->rx_fifo_overflows
, 0,
5893 "Rx FIFO overflows");
5896 static device_method_t rt2860_dev_methods
[] =
5898 DEVMETHOD(device_probe
, rt2860_probe
),
5899 DEVMETHOD(device_attach
, rt2860_attach
),
5900 DEVMETHOD(device_detach
, rt2860_detach
),
5901 DEVMETHOD(device_shutdown
, rt2860_shutdown
),
5902 DEVMETHOD(device_suspend
, rt2860_suspend
),
5903 DEVMETHOD(device_resume
, rt2860_resume
),
5907 static driver_t rt2860_driver
=
5911 sizeof(struct rt2860_softc
)
5914 static devclass_t rt2860_dev_class
;
5916 DRIVER_MODULE(rt2860
, pci
, rt2860_driver
, rt2860_dev_class
, 0, 0);
5918 MODULE_DEPEND(rt2860
, pci
, 1, 1, 1);
5919 MODULE_DEPEND(rt2860
, wlan
, 1, 1, 1);