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 struct ieee80211_node
*rt2860_node_alloc(struct ieee80211_node_table
*nt
);
143 static void rt2860_recv_action(struct ieee80211_node
*ni
,
144 const uint8_t *frm
, const uint8_t *efrm
);
146 static int rt2860_send_action(struct ieee80211_node
*ni
,
147 int category
, int action
, uint16_t args
[4]);
149 static void rt2860_amrr_update_iter_func(void *arg
, struct ieee80211_node
*ni
);
151 static void rt2860_periodic(void *arg
);
153 static void rt2860_tx_watchdog(void *arg
);
155 static void rt2860_asic_set_bssid(struct rt2860_softc
*sc
,
156 const uint8_t *bssid
);
158 static void rt2860_asic_set_macaddr(struct rt2860_softc
*sc
,
159 const uint8_t *addr
);
161 static void rt2860_asic_enable_tsf_sync(struct rt2860_softc
*sc
);
163 static void rt2860_asic_disable_tsf_sync(struct rt2860_softc
*sc
);
165 static void rt2860_asic_enable_mrr(struct rt2860_softc
*sc
);
167 static void rt2860_asic_set_txpreamble(struct rt2860_softc
*sc
);
169 static void rt2860_asic_set_basicrates(struct rt2860_softc
*sc
);
171 static void rt2860_asic_update_rtsthreshold(struct rt2860_softc
*sc
);
173 static void rt2860_asic_update_txpower(struct rt2860_softc
*sc
);
175 static void rt2860_asic_update_promisc(struct rt2860_softc
*sc
);
177 static void rt2860_asic_updateprot(struct rt2860_softc
*sc
);
179 static void rt2860_asic_updateslot(struct rt2860_softc
*sc
);
181 static void rt2860_asic_wme_update(struct rt2860_softc
*sc
);
183 static int rt2860_asic_update_beacon(struct rt2860_softc
*sc
);
185 static void rt2860_asic_clear_keytables(struct rt2860_softc
*sc
);
187 static uint8_t rt2860_rxrate(struct rt2860_rxwi
*rxwi
);
189 static uint8_t rt2860_maxrssi_rxpath(struct rt2860_softc
*sc
,
190 const struct rt2860_rxwi
*rxwi
);
192 static int8_t rt2860_rssi2dbm(struct rt2860_softc
*sc
,
193 uint8_t rssi
, uint8_t rxpath
);
195 static uint8_t rt2860_rate2mcs(uint8_t rate
);
197 static int rt2860_ackrate(struct ieee80211com
*ic
, int rate
);
199 static uint16_t rt2860_txtime(int len
, int rate
, uint32_t flags
);
201 static int rt2860_tx_frame(struct rt2860_softc
*sc
,
202 struct mbuf
*m
, struct ieee80211_node
*ni
, int qid
);
204 static int rt2860_tx_raw(struct rt2860_softc
*sc
,
205 struct mbuf
*m
, struct ieee80211_node
*ni
,
206 const struct ieee80211_bpf_params
*params
);
208 static void rt2860_intr(void *arg
);
210 static void rt2860_tx_coherent_intr(struct rt2860_softc
*sc
);
212 static void rt2860_rx_coherent_intr(struct rt2860_softc
*sc
);
214 static void rt2860_txrx_coherent_intr(struct rt2860_softc
*sc
);
216 static void rt2860_fifo_sta_full_intr(struct rt2860_softc
*sc
);
218 static void rt2860_rx_intr(struct rt2860_softc
*sc
);
220 static void rt2860_rx_delay_intr(struct rt2860_softc
*sc
);
222 static void rt2860_tx_intr(struct rt2860_softc
*sc
, int qid
);
224 static void rt2860_tx_delay_intr(struct rt2860_softc
*sc
);
226 static void rt2860_pre_tbtt_intr(struct rt2860_softc
*sc
);
228 static void rt2860_tbtt_intr(struct rt2860_softc
*sc
);
230 static void rt2860_mcu_cmd_intr(struct rt2860_softc
*sc
);
232 static void rt2860_auto_wakeup_intr(struct rt2860_softc
*sc
);
234 static void rt2860_gp_timer_intr(struct rt2860_softc
*sc
);
236 static void rt2860_rx_done_task(void *context
, int pending
);
238 static void rt2860_tx_done_task(void *context
, int pending
);
240 static void rt2860_fifo_sta_full_task(void *context
, int pending
);
242 static void rt2860_periodic_task(void *context
, int pending
);
244 static int rt2860_rx_eof(struct rt2860_softc
*sc
, int limit
);
246 static void rt2860_tx_eof(struct rt2860_softc
*sc
,
247 struct rt2860_softc_tx_ring
*ring
);
249 static void rt2860_update_stats(struct rt2860_softc
*sc
);
251 static void rt2860_bbp_tuning(struct rt2860_softc
*sc
);
253 static void rt2860_watchdog(struct rt2860_softc
*sc
);
255 static void rt2860_drain_fifo_stats(struct rt2860_softc
*sc
);
257 static void rt2860_update_raw_counters(struct rt2860_softc
*sc
);
259 static void rt2860_intr_enable(struct rt2860_softc
*sc
, uint32_t intr_mask
);
261 static void rt2860_intr_disable(struct rt2860_softc
*sc
, uint32_t intr_mask
);
263 static int rt2860_txrx_enable(struct rt2860_softc
*sc
);
265 static int rt2860_alloc_rx_ring(struct rt2860_softc
*sc
,
266 struct rt2860_softc_rx_ring
*ring
);
268 static void rt2860_reset_rx_ring(struct rt2860_softc
*sc
,
269 struct rt2860_softc_rx_ring
*ring
);
271 static void rt2860_free_rx_ring(struct rt2860_softc
*sc
,
272 struct rt2860_softc_rx_ring
*ring
);
274 static int rt2860_alloc_tx_ring(struct rt2860_softc
*sc
,
275 struct rt2860_softc_tx_ring
*ring
, int qid
);
277 static void rt2860_reset_tx_ring(struct rt2860_softc
*sc
,
278 struct rt2860_softc_tx_ring
*ring
);
280 static void rt2860_free_tx_ring(struct rt2860_softc
*sc
,
281 struct rt2860_softc_tx_ring
*ring
);
283 static void rt2860_dma_map_addr(void *arg
, bus_dma_segment_t
*segs
,
284 int nseg
, int error
);
286 static void rt2860_sysctl_attach(struct rt2860_softc
*sc
);
292 static const struct rt2860_pci_ident rt2860_pci_ids
[] =
294 { PCI_VENDOR_RALINK
, PCI_PRODUCT_RALINK_RT2860_PCI
, "Ralink RT2860 PCI" },
295 { PCI_VENDOR_RALINK
, PCI_PRODUCT_RALINK_RT2860_PCIe
, "Ralink RT2860 PCIe" },
296 { PCI_VENDOR_RALINK
, PCI_PRODUCT_RALINK_RT2760_PCI
, "Ralink RT2760 PCI" },
297 { PCI_VENDOR_RALINK
, PCI_PRODUCT_RALINK_RT2790_PCIe
, "Ralink RT2790 PCIe" },
307 { RT2860_REG_PBF_BCN_OFFSET0
, 0xf8f0e8e0 },
308 { RT2860_REG_PBF_BCN_OFFSET1
, 0x6f77d0c8 },
309 { RT2860_REG_LEGACY_BASIC_RATE
, 0x0000013f },
310 { RT2860_REG_HT_BASIC_RATE
, 0x00008003 },
311 { RT2860_REG_SYS_CTRL
, 0x00000000 },
312 { RT2860_REG_RX_FILTER_CFG
, 0x00017f97 },
313 { RT2860_REG_BKOFF_SLOT_CFG
, 0x00000209 },
314 { RT2860_REG_TX_SW_CFG0
, 0x00000000 },
315 { RT2860_REG_TX_SW_CFG1
, 0x00080606 },
316 { RT2860_REG_TX_LINK_CFG
, 0x00001020 },
317 { RT2860_REG_TX_TIMEOUT_CFG
, 0x000a2090 },
318 { RT2860_REG_MAX_LEN_CFG
, (1 << 12) | RT2860_MAX_AGG_SIZE
},
319 { RT2860_REG_LED_CFG
, 0x7f031e46 },
320 { RT2860_REG_PBF_MAX_PCNT
, 0x1f3fbf9f },
321 { RT2860_REG_TX_RTY_CFG
, 0x47d01f0f },
322 { RT2860_REG_AUTO_RSP_CFG
, 0x00000013 },
323 { RT2860_REG_TX_CCK_PROT_CFG
, 0x05740003 },
324 { RT2860_REG_TX_OFDM_PROT_CFG
, 0x05740003 },
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
|
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_SMPS_OFF
; /* MIMO power save disabled */
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_node_alloc
= rt2860_node_alloc
;
606 ic
->ic_scan_start
= rt2860_scan_start
;
607 ic
->ic_scan_end
= rt2860_scan_end
;
608 ic
->ic_set_channel
= rt2860_set_channel
;
609 ic
->ic_newassoc
= rt2860_newassoc
;
610 ic
->ic_updateslot
= rt2860_updateslot
;
611 ic
->ic_wme
.wme_update
= rt2860_wme_update
;
612 ic
->ic_update_beacon
= rt2860_update_beacon
;
613 ic
->ic_crypto
.cs_key_update_begin
= rt2860_key_update_begin
;
614 ic
->ic_crypto
.cs_key_update_end
= rt2860_key_update_end
;
615 ic
->ic_crypto
.cs_key_set
= rt2860_key_set
;
616 ic
->ic_crypto
.cs_key_delete
= rt2860_key_delete
;
617 ic
->ic_raw_xmit
= rt2860_raw_xmit
;
619 sc
->recv_action
= ic
->ic_recv_action
;
620 ic
->ic_recv_action
= rt2860_recv_action
;
622 sc
->send_action
= ic
->ic_send_action
;
623 ic
->ic_send_action
= rt2860_send_action
;
625 /* override Rx A-MPDU factor */
627 ic
->ic_ampdu_rxmax
= IEEE80211_HTCAP_MAXRXAMPDU_32K
;
628 ic
->ic_ampdu_density
= IEEE80211_HTCAP_MPDUDENSITY_NA
;
629 ic
->ic_ampdu_limit
= ic
->ic_ampdu_rxmax
;
631 /* hardware requires padding between 802.11 frame header and body */
633 ic
->ic_flags
|= IEEE80211_F_WME
| IEEE80211_F_DATAPAD
| IEEE80211_F_DOTH
;
635 ic
->ic_flags_ext
|= IEEE80211_FEXT_SWBMISS
;
637 ieee80211_media_init(ic
, rt2860_media_change
, ieee80211_media_status
);
639 rt2860_amrr_init(&sc
->amrr
, ic
,
641 RT2860_AMRR_MIN_SUCCESS_THRESHOLD
,
642 RT2860_AMRR_MAX_SUCCESS_THRESHOLD
,
645 bpfattach2(ifp
, DLT_IEEE802_11_RADIO
,
646 sizeof(struct ieee80211_frame
) + IEEE80211_RADIOTAP_HDRLEN
,
649 sc
->rxtap_len
= sizeof(sc
->rxtapu
);
650 sc
->rxtap
.ihdr
.it_len
= htole16(sc
->rxtap_len
);
651 sc
->rxtap
.ihdr
.it_present
= htole32(RT2860_SOFTC_RX_RADIOTAP_PRESENT
);
653 sc
->txtap_len
= sizeof(sc
->txtapu
);
654 sc
->txtap
.ihdr
.it_len
= htole16(sc
->txtap_len
);
655 sc
->txtap
.ihdr
.it_present
= htole32(RT2860_SOFTC_TX_RADIOTAP_PRESENT
);
657 /* init task queue */
659 TASK_INIT(&sc
->rx_done_task
, 0, rt2860_rx_done_task
, sc
);
660 TASK_INIT(&sc
->tx_done_task
, 0, rt2860_tx_done_task
, sc
);
661 TASK_INIT(&sc
->fifo_sta_full_task
, 0, rt2860_fifo_sta_full_task
, sc
);
662 TASK_INIT(&sc
->periodic_task
, 0, rt2860_periodic_task
, sc
);
664 sc
->rx_process_limit
= 100;
666 sc
->taskqueue
= taskqueue_create("rt2860_taskq", M_NOWAIT
,
667 taskqueue_thread_enqueue
, &sc
->taskqueue
);
669 taskqueue_start_threads(&sc
->taskqueue
, 1, PI_NET
, "%s taskq",
670 device_get_nameunit(sc
->dev
));
672 rt2860_sysctl_attach(sc
);
675 ieee80211_announce(ic
);
677 /* set up interrupt */
679 error
= bus_setup_intr(dev
, sc
->irq
, INTR_TYPE_NET
| INTR_MPSAFE
,
680 NULL
, rt2860_intr
, sc
, &sc
->irqh
);
683 printf("%s: could not set up interrupt\n",
684 device_get_nameunit(dev
));
692 /* free Tx and Rx rings */
694 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
695 rt2860_free_tx_ring(sc
, &sc
->tx_ring
[i
]);
697 rt2860_free_rx_ring(sc
, &sc
->rx_ring
);
699 mtx_destroy(&sc
->lock
);
702 bus_release_resource(dev
, SYS_RES_MEMORY
, sc
->mem_rid
, sc
->mem
);
705 bus_release_resource(dev
, SYS_RES_IRQ
, sc
->irq_rid
, sc
->irq
);
713 static int rt2860_detach(device_t dev
)
715 struct rt2860_softc
*sc
;
716 struct ieee80211com
*ic
;
720 sc
= device_get_softc(dev
);
724 RT2860_DPRINTF(sc
, RT2860_DEBUG_ANY
,
726 device_get_nameunit(sc
->dev
));
728 RT2860_SOFTC_LOCK(sc
);
730 ifp
->if_drv_flags
&= ~(IFF_DRV_RUNNING
| IFF_DRV_OACTIVE
);
732 ieee80211_new_state(ic
, IEEE80211_S_INIT
, -1);
734 callout_stop(&sc
->periodic_ch
);
735 callout_stop(&sc
->tx_watchdog_ch
);
737 taskqueue_drain(sc
->taskqueue
, &sc
->rx_done_task
);
738 taskqueue_drain(sc
->taskqueue
, &sc
->tx_done_task
);
739 taskqueue_drain(sc
->taskqueue
, &sc
->fifo_sta_full_task
);
740 taskqueue_drain(sc
->taskqueue
, &sc
->periodic_task
);
742 /* free Tx and Rx rings */
744 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
745 rt2860_free_tx_ring(sc
, &sc
->tx_ring
[i
]);
747 rt2860_free_rx_ring(sc
, &sc
->rx_ring
);
749 RT2860_SOFTC_UNLOCK(sc
);
753 ieee80211_ifdetach(ic
);
757 taskqueue_free(sc
->taskqueue
);
759 mtx_destroy(&sc
->lock
);
761 bus_generic_detach(dev
);
763 bus_teardown_intr(dev
, sc
->irq
, sc
->irqh
);
765 bus_release_resource(dev
, SYS_RES_IRQ
, sc
->irq_rid
, sc
->irq
);
767 bus_release_resource(dev
, SYS_RES_MEMORY
, sc
->mem_rid
, sc
->mem
);
775 static int rt2860_shutdown(device_t dev
)
777 struct rt2860_softc
*sc
;
779 sc
= device_get_softc(dev
);
781 RT2860_DPRINTF(sc
, RT2860_DEBUG_ANY
,
782 "%s: shutting down\n",
783 device_get_nameunit(sc
->dev
));
787 sc
->flags
&= ~RT2860_SOFTC_FLAGS_UCODE_LOADED
;
795 static int rt2860_suspend(device_t dev
)
797 struct rt2860_softc
*sc
;
799 sc
= device_get_softc(dev
);
801 RT2860_DPRINTF(sc
, RT2860_DEBUG_ANY
,
803 device_get_nameunit(sc
->dev
));
807 sc
->flags
&= ~RT2860_SOFTC_FLAGS_UCODE_LOADED
;
815 static int rt2860_resume(device_t dev
)
817 struct rt2860_softc
*sc
;
820 sc
= device_get_softc(dev
);
823 RT2860_DPRINTF(sc
, RT2860_DEBUG_ANY
,
825 device_get_nameunit(sc
->dev
));
827 if (ifp
->if_flags
& IFF_UP
)
834 * rt2860_init_channels
836 static void rt2860_init_channels(struct rt2860_softc
*sc
)
838 struct ieee80211com
*ic
;
839 struct ieee80211_channel
*c
;
844 /* set supported channels for 2GHz band */
846 for (i
= 1; i
<= 14; i
++)
848 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
849 flags
= IEEE80211_CHAN_B
;
851 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
855 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
856 flags
= IEEE80211_CHAN_B
| IEEE80211_CHAN_HT20
;
858 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
862 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
863 flags
= IEEE80211_CHAN_G
;
865 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
869 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
870 flags
= IEEE80211_CHAN_G
| IEEE80211_CHAN_HT20
;
872 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
877 /* set supported channels for 5GHz band */
879 if (sc
->rf_rev
== RT2860_EEPROM_RF_2850
||
880 sc
->rf_rev
== RT2860_EEPROM_RF_2750
)
882 for (i
= 36; i
<= 64; i
+= 4)
884 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
885 flags
= IEEE80211_CHAN_A
;
887 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
891 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
892 flags
= IEEE80211_CHAN_A
| IEEE80211_CHAN_HT20
;
894 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
899 for (i
= 100; i
<= 140; i
+= 4)
901 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
902 flags
= IEEE80211_CHAN_A
;
904 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
908 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
909 flags
= IEEE80211_CHAN_A
| IEEE80211_CHAN_HT20
;
911 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
916 for (i
= 149; i
<= 165; i
+= 4)
918 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
919 flags
= IEEE80211_CHAN_A
;
921 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
925 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
926 flags
= IEEE80211_CHAN_A
| IEEE80211_CHAN_HT20
;
928 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
936 * rt2860_init_channels_ht40
938 static void rt2860_init_channels_ht40(struct rt2860_softc
*sc
)
940 struct ieee80211com
*ic
;
941 struct ieee80211_channel
*c
, *cent
, *ext
;
946 /* set supported channels for 2GHz band */
948 for (i
= 1; i
<= 14; i
++)
950 flags
= IEEE80211_CHAN_G
| IEEE80211_CHAN_HT40
;
952 /* find the center channel */
954 cent
= ieee80211_find_channel_byieee(ic
, i
,
955 flags
& ~IEEE80211_CHAN_HT
);
958 printf("%s: skip channel %d, could not find center channel\n",
959 device_get_nameunit(sc
->dev
), i
);
963 /* find the extension channel */
965 ext
= ieee80211_find_channel(ic
, cent
->ic_freq
+ 20,
966 flags
& ~IEEE80211_CHAN_HT
);
969 printf("%s: skip channel %d, could not find extension channel\n",
970 device_get_nameunit(sc
->dev
), i
);
974 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
977 c
->ic_extieee
= ext
->ic_ieee
;
978 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
979 c
->ic_flags
|= IEEE80211_CHAN_HT40U
;
981 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
984 c
->ic_extieee
= cent
->ic_ieee
;
985 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
986 c
->ic_flags
|= IEEE80211_CHAN_HT40D
;
989 /* set supported channels for 5GHz band */
991 if (sc
->rf_rev
== RT2860_EEPROM_RF_2850
||
992 sc
->rf_rev
== RT2860_EEPROM_RF_2750
)
994 for (i
= 36; i
<= 64; i
+= 4)
996 flags
= IEEE80211_CHAN_A
| IEEE80211_CHAN_HT40
;
998 /* find the center channel */
1000 cent
= ieee80211_find_channel_byieee(ic
, i
,
1001 flags
& ~IEEE80211_CHAN_HT
);
1004 printf("%s: skip channel %d, could not find center channel\n",
1005 device_get_nameunit(sc
->dev
), i
);
1009 /* find the extension channel */
1011 ext
= ieee80211_find_channel(ic
, cent
->ic_freq
+ 20,
1012 flags
& ~IEEE80211_CHAN_HT
);
1015 printf("%s: skip channel %d, could not find extension channel\n",
1016 device_get_nameunit(sc
->dev
), i
);
1020 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1023 c
->ic_extieee
= ext
->ic_ieee
;
1024 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1025 c
->ic_flags
|= IEEE80211_CHAN_HT40U
;
1027 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1030 c
->ic_extieee
= cent
->ic_ieee
;
1031 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1032 c
->ic_flags
|= IEEE80211_CHAN_HT40D
;
1035 for (i
= 100; i
<= 140; i
+= 4)
1037 flags
= IEEE80211_CHAN_A
| IEEE80211_CHAN_HT40
;
1039 /* find the center channel */
1041 cent
= ieee80211_find_channel_byieee(ic
, i
,
1042 flags
& ~IEEE80211_CHAN_HT
);
1045 printf("%s: skip channel %d, could not find center channel\n",
1046 device_get_nameunit(sc
->dev
), i
);
1050 /* find the extension channel */
1052 ext
= ieee80211_find_channel(ic
, cent
->ic_freq
+ 20,
1053 flags
& ~IEEE80211_CHAN_HT
);
1056 printf("%s: skip channel %d, could not find extension channel\n",
1057 device_get_nameunit(sc
->dev
), i
);
1061 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1064 c
->ic_extieee
= ext
->ic_ieee
;
1065 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1066 c
->ic_flags
|= IEEE80211_CHAN_HT40U
;
1068 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1071 c
->ic_extieee
= cent
->ic_ieee
;
1072 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1073 c
->ic_flags
|= IEEE80211_CHAN_HT40D
;
1076 for (i
= 149; i
<= 165; i
+= 4)
1078 flags
= IEEE80211_CHAN_A
| IEEE80211_CHAN_HT40
;
1080 /* find the center channel */
1082 cent
= ieee80211_find_channel_byieee(ic
, i
,
1083 flags
& ~IEEE80211_CHAN_HT
);
1086 printf("%s: skip channel %d, could not find center channel\n",
1087 device_get_nameunit(sc
->dev
), i
);
1091 /* find the extension channel */
1093 ext
= ieee80211_find_channel(ic
, cent
->ic_freq
+ 20,
1094 flags
& ~IEEE80211_CHAN_HT
);
1097 printf("%s: skip channel %d, could not find extension channel\n",
1098 device_get_nameunit(sc
->dev
), i
);
1102 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1105 c
->ic_extieee
= ext
->ic_ieee
;
1106 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1107 c
->ic_flags
|= IEEE80211_CHAN_HT40U
;
1109 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1112 c
->ic_extieee
= cent
->ic_ieee
;
1113 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1114 c
->ic_flags
|= IEEE80211_CHAN_HT40D
;
1120 * rt2860_init_locked
1122 static void rt2860_init_locked(void *priv
)
1124 struct rt2860_softc
*sc
;
1125 struct ieee80211com
*ic
;
1127 int error
, i
, ntries
;
1128 uint32_t tmp
, stacnt
[6];
1134 RT2860_DPRINTF(sc
, RT2860_DEBUG_ANY
,
1135 "%s: initializing\n",
1136 device_get_nameunit(sc
->dev
));
1138 RT2860_SOFTC_ASSERT_LOCKED(sc
);
1140 if (!(sc
->flags
& RT2860_SOFTC_FLAGS_UCODE_LOADED
))
1142 RT2860_DPRINTF(sc
, RT2860_DEBUG_ANY
,
1143 "%s: loading 8051 microcode\n",
1144 device_get_nameunit(sc
->dev
));
1146 error
= rt2860_io_mcu_load_ucode(sc
, rt2860_ucode
, sizeof(rt2860_ucode
));
1149 printf("%s: could not load 8051 microcode\n",
1150 device_get_nameunit(sc
->dev
));
1154 RT2860_DPRINTF(sc
, RT2860_DEBUG_ANY
,
1155 "%s: 8051 microcode was successfully loaded\n",
1156 device_get_nameunit(sc
->dev
));
1158 sc
->flags
|= RT2860_SOFTC_FLAGS_UCODE_LOADED
;
1161 rt2860_io_mac_write(sc
, RT2860_REG_PWR_PIN_CFG
, 0x2);
1163 /* disable DMA engine */
1165 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
);
1168 tmp
|= RT2860_REG_TX_WB_DDONE
;
1170 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
, tmp
);
1172 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WPDMA_RST_IDX
, 0xffffffff);
1174 /* PBF hardware reset */
1176 rt2860_io_mac_write(sc
, RT2860_REG_PBF_SYS_CTRL
, 0xe1f);
1177 rt2860_io_mac_write(sc
, RT2860_REG_PBF_SYS_CTRL
, 0xe00);
1179 /* wait while DMA engine is busy */
1181 for (ntries
= 0; ntries
< 100; ntries
++)
1183 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
);
1184 if (!(tmp
& (RT2860_REG_TX_DMA_BUSY
| RT2860_REG_RX_DMA_BUSY
)))
1192 printf("%s: timeout waiting for DMA engine\n",
1193 device_get_nameunit(sc
->dev
));
1198 tmp
|= RT2860_REG_TX_WB_DDONE
;
1200 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
, tmp
);
1202 /* reset Rx and Tx rings */
1204 tmp
= RT2860_REG_RST_IDX_RX
|
1205 RT2860_REG_RST_IDX_TX_MGMT
|
1206 RT2860_REG_RST_IDX_TX_HCCA
|
1207 RT2860_REG_RST_IDX_TX_AC3
|
1208 RT2860_REG_RST_IDX_TX_AC2
|
1209 RT2860_REG_RST_IDX_TX_AC1
|
1210 RT2860_REG_RST_IDX_TX_AC0
;
1212 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WPDMA_RST_IDX
, tmp
);
1214 /* PBF hardware reset */
1216 rt2860_io_mac_write(sc
, RT2860_REG_PBF_SYS_CTRL
, 0xe1f);
1217 rt2860_io_mac_write(sc
, RT2860_REG_PBF_SYS_CTRL
, 0xe00);
1219 rt2860_io_mac_write(sc
, RT2860_REG_PWR_PIN_CFG
, 0x3);
1221 rt2860_io_mac_write(sc
, RT2860_REG_SYS_CTRL
,
1222 RT2860_REG_MAC_SRST
| RT2860_REG_BBP_HRST
);
1223 rt2860_io_mac_write(sc
, RT2860_REG_SYS_CTRL
, 0);
1225 /* init Tx power per rate */
1227 for (i
= 0; i
< RT2860_SOFTC_TXPOW_RATE_COUNT
; i
++)
1229 if (sc
->txpow_rate_20mhz
[i
] == 0xffffffff)
1232 rt2860_io_mac_write(sc
, RT2860_REG_TX_PWR_CFG(i
),
1233 sc
->txpow_rate_20mhz
[i
]);
1236 for (i
= 0; i
< RT2860_DEF_MAC_SIZE
; i
++)
1237 rt2860_io_mac_write(sc
, rt2860_def_mac
[i
].reg
,
1238 rt2860_def_mac
[i
].val
);
1240 /* wait while MAC is busy */
1242 for (ntries
= 0; ntries
< 100; ntries
++)
1244 if (!(rt2860_io_mac_read(sc
, RT2860_REG_STATUS_CFG
) &
1245 (RT2860_REG_STATUS_TX_BUSY
| RT2860_REG_STATUS_RX_BUSY
)))
1253 printf("%s: timeout waiting for MAC\n",
1254 device_get_nameunit(sc
->dev
));
1258 /* clear Host to MCU mailbox */
1260 rt2860_io_mac_write(sc
, RT2860_REG_H2M_MAILBOX_BBP_AGENT
, 0);
1261 rt2860_io_mac_write(sc
, RT2860_REG_H2M_MAILBOX
, 0);
1263 rt2860_io_mcu_cmd(sc
, RT2860_IO_MCU_CMD_BOOT
,
1264 RT2860_REG_H2M_TOKEN_NO_INTR
, 0);
1268 error
= rt2860_init_bbp(sc
);
1272 /* set up maximum buffer sizes */
1274 tmp
= (1 << 12) | RT2860_MAX_AGG_SIZE
;
1276 rt2860_io_mac_write(sc
, RT2860_REG_MAX_LEN_CFG
, tmp
);
1278 /* set mac address */
1280 IEEE80211_ADDR_COPY(ic
->ic_myaddr
, IF_LLADDR(ifp
));
1282 rt2860_asic_set_macaddr(sc
, ic
->ic_myaddr
);
1284 /* clear statistic registers */
1286 rt2860_io_mac_read_multi(sc
, RT2860_REG_RX_STA_CNT0
,
1287 stacnt
, sizeof(stacnt
));
1289 /* set RTS threshold */
1291 rt2860_asic_update_rtsthreshold(sc
);
1295 rt2860_asic_update_txpower(sc
);
1297 /* set up protection mode */
1299 sc
->tx_ampdu_sessions
= 0;
1301 rt2860_asic_updateprot(sc
);
1303 /* clear key tables */
1305 rt2860_asic_clear_keytables(sc
);
1307 /* clear beacon frame space (entries = 8, entry size = 512) */
1309 rt2860_io_mac_set_region_4(sc
, RT2860_REG_BEACON_BASE(0), 0, 1024);
1311 taskqueue_unblock(sc
->taskqueue
);
1313 /* init Tx rings (4 EDCAs + HCCA + MGMT) */
1315 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
1316 rt2860_reset_tx_ring(sc
, &sc
->tx_ring
[i
]);
1318 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
1320 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_BASE_PTR(i
),
1321 sc
->tx_ring
[i
].desc_phys_addr
);
1322 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_MAX_CNT(i
),
1323 RT2860_SOFTC_TX_RING_DESC_COUNT
);
1324 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_CTX_IDX(i
), 0);
1329 rt2860_reset_rx_ring(sc
, &sc
->rx_ring
);
1331 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_BASE_PTR
,
1332 sc
->rx_ring
.desc_phys_addr
);
1333 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_MAX_CNT
,
1334 RT2860_SOFTC_RX_RING_DATA_COUNT
);
1335 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_CALC_IDX
,
1336 RT2860_SOFTC_RX_RING_DATA_COUNT
- 1);
1338 /* wait while DMA engine is busy */
1340 for (ntries
= 0; ntries
< 100; ntries
++)
1342 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
);
1343 if (!(tmp
& (RT2860_REG_TX_DMA_BUSY
| RT2860_REG_RX_DMA_BUSY
)))
1351 printf("%s: timeout waiting for DMA engine\n",
1352 device_get_nameunit(sc
->dev
));
1357 tmp
|= RT2860_REG_TX_WB_DDONE
;
1359 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
, tmp
);
1361 /* disable interrupts mitigation */
1363 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_DELAY_INT_CFG
, 0);
1365 /* send LEDs operating mode to microcontroller */
1367 rt2860_io_mcu_cmd(sc
, RT2860_IO_MCU_CMD_LED1
,
1368 RT2860_REG_H2M_TOKEN_NO_INTR
, sc
->led_off
[0]);
1369 rt2860_io_mcu_cmd(sc
, RT2860_IO_MCU_CMD_LED2
,
1370 RT2860_REG_H2M_TOKEN_NO_INTR
, sc
->led_off
[1]);
1371 rt2860_io_mcu_cmd(sc
, RT2860_IO_MCU_CMD_LED3
,
1372 RT2860_REG_H2M_TOKEN_NO_INTR
, sc
->led_off
[2]);
1374 /* turn radio LED on */
1376 rt2860_led_cmd(sc
, RT2860_LED_CMD_RADIO_ON
);
1378 /* write vendor-specific BBP values (from EEPROM) */
1380 for (i
= 0; i
< RT2860_SOFTC_BBP_EEPROM_COUNT
; i
++)
1382 if (sc
->bbp_eeprom
[i
].reg
== 0x00 ||
1383 sc
->bbp_eeprom
[i
].reg
== 0xff)
1386 rt2860_io_bbp_write(sc
, sc
->bbp_eeprom
[i
].reg
,
1387 sc
->bbp_eeprom
[i
].val
);
1391 tmp = rt2860_io_mac_read(sc, RT2860_REG_SCHDMA_GPIO_CTRL_CFG);
1394 rt2860_io_mcu_cmd(sc, RT2860_IO_MCU_CMD_SLEEP,
1395 RT2860_REG_H2M_TOKEN_RADIOOFF, 0x02ff);
1396 rt2860_io_mcu_cmd_check(sc, RT2860_REG_H2M_TOKEN_RADIOOFF);
1398 rt2860_io_mcu_cmd(sc, RT2860_IO_MCU_CMD_WAKEUP,
1399 RT2860_REG_H2M_TOKEN_WAKEUP, 0);
1400 rt2860_io_mcu_cmd_check(sc, RT2860_REG_H2M_TOKEN_WAKEUP);
1404 /* disable non-existing Rx chains */
1406 tmp
= rt2860_io_bbp_read(sc
, 3);
1408 tmp
&= ~((1 << 4) | (1 << 3));
1410 if (sc
->nrxpath
== 3)
1412 else if (sc
->nrxpath
== 2)
1415 rt2860_io_bbp_write(sc
, 3, tmp
);
1417 /* disable non-existing Tx chains */
1419 tmp
= rt2860_io_bbp_read(sc
, 1);
1421 tmp
&= ~((1 << 4) | (1 << 3));
1423 if (sc
->ntxpath
== 2)
1426 rt2860_io_bbp_write(sc
, 1, tmp
);
1428 /* set current channel */
1430 rt2860_rf_set_chan(sc
, ic
->ic_curchan
);
1432 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WMM_TXOP0_CFG
, 0);
1433 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WMM_TXOP1_CFG
,
1436 if ((sc
->mac_rev
& 0xffff) != 0x0101)
1437 rt2860_io_mac_write(sc
, RT2860_REG_TX_TXOP_CTRL_CFG
, 0x583f);
1439 /* clear pending interrupts */
1441 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_INT_STATUS
, 0xffffffff);
1443 /* enable interrupts */
1445 tmp
= RT2860_REG_INT_TX_COHERENT
|
1446 RT2860_REG_INT_RX_COHERENT
|
1447 RT2860_REG_INT_GP_TIMER
|
1448 RT2860_REG_INT_AUTO_WAKEUP
|
1449 RT2860_REG_INT_FIFO_STA_FULL
|
1451 RT2860_REG_INT_PRE_TBTT |
1452 RT2860_REG_INT_TBTT |
1454 RT2860_REG_INT_TXRX_COHERENT
|
1455 RT2860_REG_INT_MCU_CMD
|
1456 RT2860_REG_INT_TX_MGMT_DONE
|
1457 RT2860_REG_INT_TX_HCCA_DONE
|
1458 RT2860_REG_INT_TX_AC3_DONE
|
1459 RT2860_REG_INT_TX_AC2_DONE
|
1460 RT2860_REG_INT_TX_AC1_DONE
|
1461 RT2860_REG_INT_TX_AC0_DONE
|
1462 RT2860_REG_INT_RX_DONE
;
1464 sc
->intr_enable_mask
= tmp
;
1466 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_INT_MASK
, tmp
);
1468 if (rt2860_txrx_enable(sc
) != 0)
1471 /* clear garbage interrupts */
1473 tmp
= rt2860_io_mac_read(sc
, 0x1300);
1475 ifp
->if_drv_flags
&= ~IFF_DRV_OACTIVE
;
1476 ifp
->if_drv_flags
|= IFF_DRV_RUNNING
;
1478 if (ic
->ic_opmode
!= IEEE80211_M_MONITOR
)
1480 if (ic
->ic_roaming
!= IEEE80211_ROAMING_MANUAL
)
1481 ieee80211_new_state(ic
, IEEE80211_S_SCAN
, -1);
1485 ieee80211_new_state(ic
, IEEE80211_S_RUN
, -1);
1488 sc
->periodic_round
= 0;
1490 callout_reset(&sc
->periodic_ch
, hz
/ 10, rt2860_periodic
, sc
);
1496 rt2860_stop_locked(sc
);
1502 static void rt2860_init(void *priv
)
1504 struct rt2860_softc
*sc
;
1508 RT2860_SOFTC_LOCK(sc
);
1510 rt2860_init_locked(sc
);
1512 RT2860_SOFTC_UNLOCK(sc
);
1518 static int rt2860_init_bbp(struct rt2860_softc
*sc
)
1523 for (ntries
= 0; ntries
< 20; ntries
++)
1525 tmp
= rt2860_io_bbp_read(sc
, 0);
1526 if (tmp
!= 0x00 && tmp
!= 0xff)
1530 if (tmp
== 0x00 || tmp
== 0xff)
1532 printf("%s: timeout waiting for BBP to wakeup\n",
1533 device_get_nameunit(sc
->dev
));
1537 for (i
= 0; i
< RT2860_DEF_BBP_SIZE
; i
++)
1538 rt2860_io_bbp_write(sc
, rt2860_def_bbp
[i
].reg
,
1539 rt2860_def_bbp
[i
].val
);
1541 if ((sc
->mac_rev
& 0xffff) != 0x0101)
1542 rt2860_io_bbp_write(sc
, 84, 0x19);
1548 * rt2860_stop_locked
1550 static void rt2860_stop_locked(void *priv
)
1552 struct rt2860_softc
*sc
;
1553 struct ieee80211com
*ic
;
1561 RT2860_DPRINTF(sc
, RT2860_DEBUG_ANY
,
1563 device_get_nameunit(sc
->dev
));
1565 RT2860_SOFTC_ASSERT_LOCKED(sc
);
1569 if (ifp
->if_drv_flags
& IFF_DRV_RUNNING
)
1570 rt2860_led_cmd(sc
, RT2860_LED_CMD_RADIO_OFF
);
1572 ifp
->if_drv_flags
&= ~(IFF_DRV_RUNNING
| IFF_DRV_OACTIVE
);
1574 ieee80211_new_state(ic
, IEEE80211_S_INIT
, -1);
1576 callout_stop(&sc
->periodic_ch
);
1577 callout_stop(&sc
->tx_watchdog_ch
);
1579 RT2860_SOFTC_UNLOCK(sc
);
1581 taskqueue_block(sc
->taskqueue
);
1583 taskqueue_drain(sc
->taskqueue
, &sc
->rx_done_task
);
1584 taskqueue_drain(sc
->taskqueue
, &sc
->tx_done_task
);
1585 taskqueue_drain(sc
->taskqueue
, &sc
->fifo_sta_full_task
);
1586 taskqueue_drain(sc
->taskqueue
, &sc
->periodic_task
);
1588 RT2860_SOFTC_LOCK(sc
);
1590 /* clear key tables */
1592 rt2860_asic_clear_keytables(sc
);
1594 /* disable interrupts */
1596 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_INT_MASK
, 0);
1600 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_SYS_CTRL
);
1602 tmp
&= ~(RT2860_REG_RX_ENABLE
| RT2860_REG_TX_ENABLE
);
1604 rt2860_io_mac_write(sc
, RT2860_REG_SYS_CTRL
, tmp
);
1608 rt2860_io_mac_write(sc
, RT2860_REG_SYS_CTRL
,
1609 RT2860_REG_MAC_SRST
| RT2860_REG_BBP_HRST
);
1610 rt2860_io_mac_write(sc
, RT2860_REG_SYS_CTRL
, 0);
1616 static void rt2860_stop(void *priv
)
1618 struct rt2860_softc
*sc
;
1622 RT2860_SOFTC_LOCK(sc
);
1624 rt2860_stop_locked(sc
);
1626 RT2860_SOFTC_UNLOCK(sc
);
1632 static void rt2860_start(struct ifnet
*ifp
)
1634 struct rt2860_softc
*sc
;
1635 struct ieee80211com
*ic
;
1636 struct ieee80211_node
*ni
;
1637 struct ether_header
*eh
;
1644 RT2860_SOFTC_LOCK(sc
);
1646 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
1648 RT2860_SOFTC_UNLOCK(sc
);
1654 IF_POLL(&ic
->ic_mgtq
, m
);
1657 if (sc
->tx_ring
[sc
->tx_ring_mgtqid
].data_queued
>= RT2860_SOFTC_TX_RING_DATA_COUNT
)
1659 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
1660 "%s: if_start: Tx ring with qid=%d is full\n",
1661 device_get_nameunit(sc
->dev
), sc
->tx_ring_mgtqid
);
1663 ifp
->if_drv_flags
|= IFF_DRV_OACTIVE
;
1665 sc
->tx_data_queue_full
[sc
->tx_ring_mgtqid
]++;
1670 IF_DEQUEUE(&ic
->ic_mgtq
, m
);
1672 ni
= (struct ieee80211_node
*) m
->m_pkthdr
.rcvif
;
1673 m
->m_pkthdr
.rcvif
= NULL
;
1675 if (bpf_peers_present(ic
->ic_rawbpf
))
1676 bpf_mtap(ic
->ic_rawbpf
, m
);
1678 if (rt2860_tx_frame(sc
, m
, ni
, sc
->tx_ring_mgtqid
) != 0)
1681 rt2860_drain_fifo_stats(sc
);
1685 if (ic
->ic_state
!= IEEE80211_S_RUN
)
1688 IF_POLL(&ifp
->if_snd
, m
);
1692 IFQ_DRV_DEQUEUE(&ifp
->if_snd
, m
);
1694 if (ic
->ic_flags
& IEEE80211_F_SCAN
)
1695 ieee80211_cancel_scan(ic
);
1697 if (m
->m_len
< sizeof(struct ether_header
) &&
1698 !(m
= m_pullup(m
, sizeof (struct ether_header
))))
1701 eh
= mtod(m
, struct ether_header
*);
1703 ni
= ieee80211_find_txnode(ic
, eh
->ether_dhost
);
1706 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
1707 "%s: if_start: could not find Tx node\n",
1708 device_get_nameunit(sc
->dev
));
1714 ieee80211_classify(ic
, m
, ni
);
1716 qid
= M_WME_GETAC(m
);
1718 if (sc
->tx_ring
[qid
].data_queued
>= RT2860_SOFTC_TX_RING_DATA_COUNT
)
1720 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
1721 "%s: if_start: Tx ring with qid=%d is full\n",
1722 device_get_nameunit(sc
->dev
), qid
);
1725 ieee80211_free_node(ni
);
1727 ifp
->if_drv_flags
|= IFF_DRV_OACTIVE
;
1730 sc
->tx_data_queue_full
[qid
]++;
1737 m
= ieee80211_encap(ic
, m
, ni
);
1740 ieee80211_free_node(ni
);
1745 if (bpf_peers_present(ic
->ic_rawbpf
))
1746 bpf_mtap(ic
->ic_rawbpf
, m
);
1748 if (rt2860_tx_frame(sc
, m
, ni
, qid
) != 0)
1750 ieee80211_free_node(ni
);
1757 rt2860_drain_fifo_stats(sc
);
1760 sc
->tx_timer
= RT2860_TX_WATCHDOG_TIMEOUT
;
1762 ic
->ic_lastdata
= ticks
;
1764 callout_reset(&sc
->tx_watchdog_ch
, hz
, rt2860_tx_watchdog
, sc
);
1767 RT2860_SOFTC_UNLOCK(sc
);
1773 static int rt2860_ioctl(struct ifnet
*ifp
, u_long cmd
, caddr_t data
)
1775 struct rt2860_softc
*sc
;
1776 struct ieee80211com
*ic
;
1787 RT2860_SOFTC_LOCK(sc
);
1789 if (ifp
->if_flags
& IFF_UP
)
1791 if (ifp
->if_drv_flags
& IFF_DRV_RUNNING
)
1793 if ((ifp
->if_flags
^ sc
->if_flags
) & IFF_PROMISC
)
1794 rt2860_asic_update_promisc(sc
);
1798 rt2860_init_locked(sc
);
1803 if (ifp
->if_drv_flags
& IFF_DRV_RUNNING
)
1804 rt2860_stop_locked(sc
);
1807 sc
->if_flags
= ifp
->if_flags
;
1809 RT2860_SOFTC_UNLOCK(sc
);
1813 error
= ieee80211_ioctl(ic
, cmd
, data
);
1816 if (error
== ENETRESET
)
1818 RT2860_SOFTC_LOCK(sc
);
1820 if ((ifp
->if_flags
& IFF_UP
) &&
1821 (ifp
->if_drv_flags
& IFF_DRV_RUNNING
) &&
1822 (ic
->ic_roaming
!= IEEE80211_ROAMING_MANUAL
))
1824 rt2860_stop_locked(sc
);
1825 rt2860_init_locked(sc
);
1828 RT2860_SOFTC_UNLOCK(sc
);
1839 static int rt2860_reset(struct ifnet
*ifp
)
1841 struct rt2860_softc
*sc
;
1842 struct ieee80211com
*ic
;
1847 if (ic
->ic_opmode
!= IEEE80211_M_MONITOR
)
1850 rt2860_rf_set_chan(sc
, ic
->ic_curchan
);
1858 static int rt2860_newstate(struct ieee80211com
*ic
,
1859 enum ieee80211_state nstate
, int arg
)
1861 struct rt2860_softc
*sc
;
1863 struct ieee80211_node
*ni
;
1869 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATE
,
1870 "%s: newstate: %s -> %s\n",
1871 device_get_nameunit(sc
->dev
),
1872 ieee80211_state_name
[ic
->ic_state
], ieee80211_state_name
[nstate
]);
1874 error
= sc
->newstate(ic
, nstate
, arg
);
1878 RT2860_SOFTC_LOCK(sc
);
1880 /* turn link LED off */
1882 if (nstate
!= IEEE80211_S_RUN
)
1883 rt2860_led_cmd(sc
, RT2860_LED_CMD_RADIO_OFF
);
1887 case IEEE80211_S_INIT
:
1888 rt2860_asic_disable_tsf_sync(sc
);
1891 case IEEE80211_S_RUN
:
1894 if (ic
->ic_opmode
!= IEEE80211_M_MONITOR
)
1895 rt2860_rf_set_chan(sc
, ni
->ni_chan
);
1897 if (ic
->ic_opmode
!= IEEE80211_M_MONITOR
)
1899 rt2860_asic_enable_mrr(sc
);
1900 rt2860_asic_set_txpreamble(sc
);
1901 rt2860_asic_set_basicrates(sc
);
1902 rt2860_asic_update_txpower(sc
);
1903 rt2860_asic_set_bssid(sc
, ni
->ni_bssid
);
1906 if (ic
->ic_opmode
== IEEE80211_M_STA
)
1907 rt2860_newassoc(ni
, 1);
1909 if (ic
->ic_opmode
== IEEE80211_M_HOSTAP
||
1910 ic
->ic_opmode
== IEEE80211_M_IBSS
)
1912 error
= rt2860_asic_update_beacon(sc
);
1917 if (ic
->ic_opmode
!= IEEE80211_M_MONITOR
)
1918 rt2860_asic_enable_tsf_sync(sc
);
1920 /* turn link LED on */
1922 if (ic
->ic_opmode
!= IEEE80211_M_MONITOR
)
1924 rt2860_led_cmd(sc
, RT2860_LED_CMD_RADIO_ON
|
1925 (IEEE80211_IS_CHAN_2GHZ(ni
->ni_chan
) ?
1926 RT2860_LED_CMD_LINK_2GHZ
: RT2860_LED_CMD_LINK_5GHZ
));
1934 RT2860_SOFTC_UNLOCK(sc
);
1942 static void rt2860_scan_start(struct ieee80211com
*ic
)
1944 struct rt2860_softc
*sc
;
1950 rt2860_asic_disable_tsf_sync(sc
);
1956 static void rt2860_scan_end(struct ieee80211com
*ic
)
1958 struct rt2860_softc
*sc
;
1964 rt2860_asic_enable_tsf_sync(sc
);
1968 * rt2860_set_channel
1970 static void rt2860_set_channel(struct ieee80211com
*ic
)
1972 struct rt2860_softc
*sc
;
1978 RT2860_DPRINTF(sc
, RT2860_DEBUG_CHAN
,
1979 "%s: set channel: channel=%u, HT%s%s\n",
1980 device_get_nameunit(sc
->dev
),
1981 ieee80211_chan2ieee(ic
, ic
->ic_curchan
),
1982 !IEEE80211_IS_CHAN_HT(ic
->ic_curchan
) ? " disabled" :
1983 IEEE80211_IS_CHAN_HT20(ic
->ic_curchan
) ? "20":
1984 IEEE80211_IS_CHAN_HT40U(ic
->ic_curchan
) ? "40U" : "40D",
1985 (ic
->ic_flags
& IEEE80211_F_SCAN
) ? ", scanning" : "");
1987 RT2860_SOFTC_LOCK(sc
);
1989 rt2860_rf_set_chan(sc
, ic
->ic_curchan
);
1991 RT2860_SOFTC_UNLOCK(sc
);
1997 static void rt2860_newassoc(struct ieee80211_node
*ni
, int isnew
)
1999 struct rt2860_softc
*sc
;
2000 struct ieee80211com
*ic
;
2009 associd
= (ni
!= NULL
) ? ni
->ni_associd
: 0;
2010 wcid
= RT2860_AID2WCID(associd
);
2012 RT2860_DPRINTF(sc
, RT2860_DEBUG_NODE
,
2013 "%s: new association: wcid=0x%02x, "
2014 "mac addr=%s, QoS %s, ERP %s, HT %s\n",
2015 device_get_nameunit(sc
->dev
), wcid
,
2016 ether_sprintf(ni
->ni_macaddr
),
2017 (ni
->ni_flags
& IEEE80211_NODE_QOS
) ? "enabled" : "disabled",
2018 (ni
->ni_flags
& IEEE80211_NODE_ERP
) ? "enabled" : "disabled",
2019 (ni
->ni_flags
& IEEE80211_NODE_HT
) ? "enabled" : "disabled");
2021 rt2860_io_mac_write_multi(sc
, RT2860_REG_WCID(wcid
),
2022 ni
->ni_macaddr
, IEEE80211_ADDR_LEN
);
2024 rt2860_amrr_node_init(&sc
->amrr
, &sc
->amrr_node
[wcid
], ni
);
2026 RT2860_DPRINTF(sc
, RT2860_DEBUG_RATE
,
2027 "%s: initial%s node Tx rate: associd=0x%04x, rate=0x%02x, max rate=0x%02x\n",
2028 device_get_nameunit(sc
->dev
),
2029 (ni
->ni_flags
& IEEE80211_NODE_HT
) ? " HT" : "",
2031 (ni
->ni_flags
& IEEE80211_NODE_HT
) ?
2032 (ni
->ni_htrates
.rs_rates
[ni
->ni_txrate
] | IEEE80211_RATE_MCS
) :
2033 (ni
->ni_rates
.rs_rates
[ni
->ni_txrate
] & IEEE80211_RATE_VAL
),
2034 (ni
->ni_flags
& IEEE80211_NODE_HT
) ?
2035 (ni
->ni_htrates
.rs_rates
[ni
->ni_htrates
.rs_nrates
- 1] | IEEE80211_RATE_MCS
) :
2036 (ni
->ni_rates
.rs_rates
[ni
->ni_rates
.rs_nrates
- 1] & IEEE80211_RATE_VAL
));
2038 rt2860_asic_updateprot(sc
);
2039 rt2860_asic_updateslot(sc
);
2040 rt2860_asic_set_txpreamble(sc
);
2046 static void rt2860_updateslot(struct ifnet
*ifp
)
2048 struct rt2860_softc
*sc
;
2052 rt2860_asic_updateslot(sc
);
2058 static int rt2860_wme_update(struct ieee80211com
*ic
)
2060 struct rt2860_softc
*sc
;
2066 rt2860_asic_wme_update(sc
);
2072 * rt2860_update_beacon
2074 static void rt2860_update_beacon(struct ieee80211com
*ic
, int what
)
2076 struct rt2860_softc
*sc
;
2082 rt2860_asic_update_beacon(sc
);
2086 * rt2860_key_update_begin
2088 static void rt2860_key_update_begin(struct ieee80211com
*ic
)
2090 struct rt2860_softc
*sc
;
2096 RT2860_DPRINTF(sc
, RT2860_DEBUG_KEY
,
2097 "%s: key update begin\n",
2098 device_get_nameunit(sc
->dev
));
2100 taskqueue_block(sc
->taskqueue
);
2102 IF_LOCK(&ifp
->if_snd
);
2106 * rt2860_key_update_end
2108 static void rt2860_key_update_end(struct ieee80211com
*ic
)
2110 struct rt2860_softc
*sc
;
2116 RT2860_DPRINTF(sc
, RT2860_DEBUG_KEY
,
2117 "%s: key update end\n",
2118 device_get_nameunit(sc
->dev
));
2120 IF_UNLOCK(&ifp
->if_snd
);
2122 taskqueue_unblock(sc
->taskqueue
);
2128 static int rt2860_key_set(struct ieee80211com
*ic
,
2129 const struct ieee80211_key
*k
, const uint8_t mac
[IEEE80211_ADDR_LEN
])
2131 struct rt2860_softc
*sc
;
2133 struct ieee80211_node
*ni
;
2134 uint16_t associd
, key_base
, keymode_base
;
2135 uint8_t mode
, vapid
, wcid
, iv
[8];
2138 if (k
->wk_cipher
->ic_cipher
!= IEEE80211_CIPHER_WEP
&&
2139 k
->wk_cipher
->ic_cipher
!= IEEE80211_CIPHER_TKIP
&&
2140 k
->wk_cipher
->ic_cipher
!= IEEE80211_CIPHER_AES_CCM
)
2146 if (ic
->ic_opmode
!= IEEE80211_M_HOSTAP
)
2149 ni
= ieee80211_find_node(&ic
->ic_sta
, mac
);
2151 associd
= (ni
!= NULL
) ? ni
->ni_associd
: 0;
2153 if ((ic
->ic_opmode
== IEEE80211_M_HOSTAP
) && (ni
!= NULL
))
2154 ieee80211_free_node(ni
);
2156 switch (k
->wk_cipher
->ic_cipher
)
2158 case IEEE80211_CIPHER_WEP
:
2159 if(k
->wk_keylen
< 8)
2160 mode
= RT2860_REG_CIPHER_MODE_WEP40
;
2162 mode
= RT2860_REG_CIPHER_MODE_WEP104
;
2165 case IEEE80211_CIPHER_TKIP
:
2166 mode
= RT2860_REG_CIPHER_MODE_TKIP
;
2169 case IEEE80211_CIPHER_AES_CCM
:
2170 mode
= RT2860_REG_CIPHER_MODE_AES_CCMP
;
2177 RT2860_DPRINTF(sc
, RT2860_DEBUG_KEY
,
2178 "%s: set key: keyix=%d, keylen=%d, associd=0x%04x, mode=%d, group=%d\n",
2179 device_get_nameunit(sc
->dev
), k
->wk_keyix
, k
->wk_keylen
, associd
, mode
,
2180 (k
->wk_flags
& IEEE80211_KEY_GROUP
) ? 1 : 0);
2182 if (!(k
->wk_flags
& IEEE80211_KEY_GROUP
))
2184 /* install pairwise key */
2187 wcid
= RT2860_AID2WCID(associd
);
2188 key_base
= RT2860_REG_PKEY(wcid
);
2190 if (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_WEP
)
2194 iv
[3] = (k
->wk_keyix
<< 6);
2198 if (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_TKIP
)
2200 iv
[0] = (k
->wk_keytsc
>> 8);
2201 iv
[1] = ((iv
[0] | 0x20) & 0x7f);
2202 iv
[2] = k
->wk_keytsc
;
2208 iv
[0] = k
->wk_keytsc
;
2209 iv
[1] = k
->wk_keytsc
>> 8;
2213 iv
[3] = ((k
->wk_keyix
<< 6) | IEEE80211_WEP_EXTIV
);
2214 iv
[4] = (k
->wk_keytsc
>> 16);
2215 iv
[5] = (k
->wk_keytsc
>> 24);
2216 iv
[6] = (k
->wk_keytsc
>> 32);
2217 iv
[7] = (k
->wk_keytsc
>> 40);
2219 RT2860_DPRINTF(sc
, RT2860_DEBUG_KEY
,
2220 "%s: set key: iv=%02x %02x %02x %02x %02x %02x %02x %02x\n",
2221 device_get_nameunit(sc
->dev
),
2222 iv
[0], iv
[1], iv
[2], iv
[3], iv
[4], iv
[5], iv
[6], iv
[7]);
2225 rt2860_io_mac_write_multi(sc
, RT2860_REG_IVEIV(wcid
), iv
, 8);
2227 if (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_TKIP
)
2229 rt2860_io_mac_write_multi(sc
, key_base
, k
->wk_key
, 16);
2231 if (ic
->ic_opmode
!= IEEE80211_M_HOSTAP
)
2233 rt2860_io_mac_write_multi(sc
, key_base
+ 16, &k
->wk_key
[16], 8);
2234 rt2860_io_mac_write_multi(sc
, key_base
+ 24, &k
->wk_key
[24], 8);
2238 rt2860_io_mac_write_multi(sc
, key_base
+ 16, &k
->wk_key
[24], 8);
2239 rt2860_io_mac_write_multi(sc
, key_base
+ 24, &k
->wk_key
[16], 8);
2244 rt2860_io_mac_write_multi(sc
, key_base
, k
->wk_key
, k
->wk_keylen
);
2247 tmp
= ((vapid
& RT2860_REG_VAP_MASK
) << RT2860_REG_VAP_SHIFT
) |
2248 (mode
<< RT2860_REG_CIPHER_MODE_SHIFT
) | RT2860_REG_PKEY_ENABLE
;
2250 rt2860_io_mac_write(sc
, RT2860_REG_WCID_ATTR(wcid
), tmp
);
2253 if ((k
->wk_flags
& IEEE80211_KEY_GROUP
) ||
2254 (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_WEP
))
2256 /* install group key */
2259 key_base
= RT2860_REG_SKEY(vapid
, k
->wk_keyix
);
2260 keymode_base
= RT2860_REG_SKEY_MODE(vapid
);
2262 if (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_TKIP
)
2264 rt2860_io_mac_write_multi(sc
, key_base
, k
->wk_key
, 16);
2266 if (ic
->ic_opmode
!= IEEE80211_M_HOSTAP
)
2268 rt2860_io_mac_write_multi(sc
, key_base
+ 16, &k
->wk_key
[16], 8);
2269 rt2860_io_mac_write_multi(sc
, key_base
+ 24, &k
->wk_key
[24], 8);
2273 rt2860_io_mac_write_multi(sc
, key_base
+ 16, &k
->wk_key
[24], 8);
2274 rt2860_io_mac_write_multi(sc
, key_base
+ 24, &k
->wk_key
[16], 8);
2279 rt2860_io_mac_write_multi(sc
, key_base
, k
->wk_key
, k
->wk_keylen
);
2282 tmp
= rt2860_io_mac_read(sc
, keymode_base
);
2284 tmp
&= ~(0xf << (k
->wk_keyix
* 4 + 16 * (vapid
% 2)));
2285 tmp
|= (mode
<< (k
->wk_keyix
* 4 + 16 * (vapid
% 2)));
2287 rt2860_io_mac_write(sc
, keymode_base
, tmp
);
2296 static int rt2860_key_delete(struct ieee80211com
*ic
,
2297 const struct ieee80211_key
*k
)
2299 struct rt2860_softc
*sc
;
2300 struct ieee80211_node
*ni
;
2302 uint8_t vapid
, wcid
;
2305 sc
= ic
->ic_ifp
->if_softc
;
2307 associd
= (ni
!= NULL
) ? ni
->ni_associd
: 0;
2309 RT2860_DPRINTF(sc
, RT2860_DEBUG_KEY
,
2310 "%s: delete key: keyix=%d, keylen=%d, associd=0x%04x, group=%d\n",
2311 device_get_nameunit(sc
->dev
), k
->wk_keyix
, k
->wk_keylen
, associd
,
2312 (k
->wk_flags
& IEEE80211_KEY_GROUP
) ? 1 : 0);
2314 if (!(k
->wk_flags
& IEEE80211_KEY_GROUP
))
2316 /* remove pairwise key */
2319 wcid
= RT2860_AID2WCID(associd
);
2321 tmp
= ((vapid
& RT2860_REG_VAP_MASK
) << RT2860_REG_VAP_SHIFT
) |
2322 (RT2860_REG_CIPHER_MODE_NONE
<< RT2860_REG_CIPHER_MODE_SHIFT
) | RT2860_REG_PKEY_ENABLE
;
2324 rt2860_io_mac_write(sc
, RT2860_REG_WCID_ATTR(wcid
), tmp
);
2328 /* remove group key */
2332 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_SKEY_MODE(vapid
));
2334 tmp
&= ~(0xf << (k
->wk_keyix
* 4 + 16 * (vapid
% 2)));
2335 tmp
|= (RT2860_REG_CIPHER_MODE_NONE
<< (k
->wk_keyix
* 4 + 16 * (vapid
% 2)));
2337 rt2860_io_mac_write(sc
, RT2860_REG_SKEY_MODE(vapid
), tmp
);
2346 static int rt2860_raw_xmit(struct ieee80211_node
*ni
, struct mbuf
*m
,
2347 const struct ieee80211_bpf_params
*params
)
2353 * rt2860_media_change
2355 static int rt2860_media_change(struct ifnet
*ifp
)
2357 struct rt2860_softc
*sc
;
2362 error
= ieee80211_media_change(ifp
);
2363 if (error
!= ENETRESET
)
2366 RT2860_SOFTC_LOCK(sc
);
2368 if ((ifp
->if_flags
& IFF_UP
) && (ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
2370 rt2860_stop_locked(sc
);
2371 rt2860_init_locked(sc
);
2374 RT2860_SOFTC_UNLOCK(sc
);
2382 static struct ieee80211_node
*rt2860_node_alloc(struct ieee80211_node_table
*nt
)
2384 return malloc(sizeof(struct rt2860_softc_node
),
2385 M_80211_NODE
, M_NOWAIT
| M_ZERO
);
2389 * rt2860_recv_action
2391 static void rt2860_recv_action(struct ieee80211_node
*ni
,
2392 const uint8_t *frm
, const uint8_t *efrm
)
2394 struct rt2860_softc
*sc
;
2395 struct ieee80211com
*ic
;
2397 const struct ieee80211_action
*ia
;
2398 struct ieee80211_tx_ampdu
*tx_ampdu
;
2399 uint16_t associd
, status
, baparamset
;
2401 int tid
, bufsize
, ac
;
2408 ia
= (const struct ieee80211_action
*) frm
;
2410 sc
->recv_action(ni
, frm
, efrm
);
2412 if (ia
->ia_category
!= IEEE80211_ACTION_CAT_BA
)
2415 associd
= (ni
!= NULL
) ? ni
->ni_associd
: 0;
2416 wcid
= RT2860_AID2WCID(associd
);
2418 switch (ia
->ia_action
)
2420 /* IEEE80211_ACTION_BA_ADDBA_REQUEST */
2421 case IEEE80211_ACTION_BA_ADDBA_REQUEST
:
2422 baparamset
= LE_READ_2(frm
+ 3);
2423 tid
= RT2860_MS(baparamset
, IEEE80211_BAPS_TID
);
2424 bufsize
= RT2860_MS(baparamset
, IEEE80211_BAPS_BUFSIZ
);
2426 RT2860_DPRINTF(sc
, RT2860_DEBUG_BA
,
2427 "%s: received ADDBA request: associd=0x%04x, tid=%d, bufsize=%d\n",
2428 device_get_nameunit(sc
->dev
), associd
, tid
, bufsize
);
2430 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_WCID(wcid
) + 4);
2432 tmp
|= (0x10000 << tid
);
2434 rt2860_io_mac_write(sc
, RT2860_REG_WCID(wcid
) + 4, tmp
);
2437 /* IEEE80211_ACTION_BA_ADDBA_RESPONSE */
2438 case IEEE80211_ACTION_BA_ADDBA_RESPONSE
:
2439 status
= LE_READ_2(frm
+ 3);
2440 baparamset
= LE_READ_2(frm
+ 4);
2441 tid
= RT2860_MS(baparamset
, IEEE80211_BAPS_TID
);
2442 bufsize
= RT2860_MS(baparamset
, IEEE80211_BAPS_BUFSIZ
);
2443 ac
= TID_TO_WME_AC(tid
);
2444 tx_ampdu
= &ni
->ni_tx_ampdu
[ac
];
2446 RT2860_DPRINTF(sc
, RT2860_DEBUG_BA
,
2447 "%s: received ADDBA response: associd=0x%04x, status=%d, tid=%d, bufsize=%d\n",
2448 device_get_nameunit(sc
->dev
), associd
, status
, tid
, bufsize
);
2450 if (sc
->mac_rev
>= 0x28720200)
2452 if (tx_ampdu
->txa_wnd
> 13)
2453 tx_ampdu
->txa_wnd
= 13;
2457 if (tx_ampdu
->txa_wnd
> 7)
2458 tx_ampdu
->txa_wnd
= 7;
2461 if (status
== IEEE80211_STATUS_SUCCESS
)
2463 sc
->tx_ampdu_sessions
++;
2465 rt2860_asic_updateprot(sc
);
2469 /* IEEE80211_ACTION_BA_DELBA */
2470 case IEEE80211_ACTION_BA_DELBA
:
2471 baparamset
= LE_READ_2(frm
+ 2);
2472 tid
= RT2860_MS(baparamset
, IEEE80211_BAPS_TID
);
2474 RT2860_DPRINTF(sc
, RT2860_DEBUG_BA
,
2475 "%s: received DELBA request: associd=0x%04x, tid=%d\n",
2476 device_get_nameunit(sc
->dev
), associd
, tid
);
2478 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_WCID(wcid
) + 4);
2480 tmp
&= ~(0x10000 << tid
);
2482 rt2860_io_mac_write(sc
, RT2860_REG_WCID(wcid
) + 4, tmp
);
2488 * rt2860_send_action
2490 static int rt2860_send_action(struct ieee80211_node
*ni
,
2491 int category
, int action
, uint16_t args
[4])
2493 struct rt2860_softc
*sc
;
2494 struct ieee80211com
*ic
;
2496 uint16_t associd
, baparamset
;
2505 ret
= sc
->send_action(ni
, category
, action
, args
);
2507 if (category
!= IEEE80211_ACTION_CAT_BA
)
2510 associd
= (ni
!= NULL
) ? ni
->ni_associd
: 0;
2511 wcid
= RT2860_AID2WCID(associd
);
2515 /* IEEE80211_ACTION_BA_DELBA */
2516 case IEEE80211_ACTION_BA_DELBA
:
2517 baparamset
= RT2860_SM(args
[0], IEEE80211_DELBAPS_TID
) | args
[1];
2519 tid
= RT2860_MS(baparamset
, IEEE80211_DELBAPS_TID
);
2521 RT2860_DPRINTF(sc
, RT2860_DEBUG_BA
,
2522 "%s: sending DELBA request: associd=0x%04x, tid=%d\n",
2523 device_get_nameunit(sc
->dev
), associd
, tid
);
2525 if (RT2860_MS(baparamset
, IEEE80211_DELBAPS_INIT
) != IEEE80211_DELBAPS_INIT
)
2527 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_WCID(wcid
) + 4);
2529 tmp
&= ~(0x10000 << tid
);
2531 rt2860_io_mac_write(sc
, RT2860_REG_WCID(wcid
) + 4, tmp
);
2535 sc
->tx_ampdu_sessions
--;
2537 rt2860_asic_updateprot(sc
);
2546 * rt2860_amrr_update_iter_func
2548 static void rt2860_amrr_update_iter_func(void *arg
, struct ieee80211_node
*ni
)
2550 struct rt2860_softc
*sc
;
2551 struct ieee80211com
*ic
;
2557 /* only associated stations */
2559 if (ni
->ni_associd
!= 0)
2561 wcid
= RT2860_AID2WCID(ni
->ni_associd
);
2563 RT2860_DPRINTF(sc
, RT2860_DEBUG_RATE
,
2564 "%s: AMRR node: wcid=0x%02x, txcnt=%d, success=%d, retrycnt=%d\n",
2565 device_get_nameunit(sc
->dev
),
2566 wcid
, sc
->amrr_node
[wcid
].txcnt
, sc
->amrr_node
[wcid
].success
, sc
->amrr_node
[wcid
].retrycnt
);
2568 rt2860_amrr_choose(ni
, &sc
->amrr_node
[wcid
]);
2570 RT2860_DPRINTF(sc
, RT2860_DEBUG_RATE
,
2571 "%s:%s node Tx rate: associd=0x%04x, rate=0x%02x, max rate=0x%02x\n",
2572 device_get_nameunit(sc
->dev
),
2573 (ni
->ni_flags
& IEEE80211_NODE_HT
) ? " HT" : "",
2575 (ni
->ni_flags
& IEEE80211_NODE_HT
) ?
2576 (ni
->ni_htrates
.rs_rates
[ni
->ni_txrate
] | IEEE80211_RATE_MCS
) :
2577 (ni
->ni_rates
.rs_rates
[ni
->ni_txrate
] & IEEE80211_RATE_VAL
),
2578 (ni
->ni_flags
& IEEE80211_NODE_HT
) ?
2579 (ni
->ni_htrates
.rs_rates
[ni
->ni_htrates
.rs_nrates
- 1] | IEEE80211_RATE_MCS
) :
2580 (ni
->ni_rates
.rs_rates
[ni
->ni_rates
.rs_nrates
- 1] & IEEE80211_RATE_VAL
));
2587 static void rt2860_periodic(void *arg
)
2589 struct rt2860_softc
*sc
;
2593 RT2860_DPRINTF(sc
, RT2860_DEBUG_PERIODIC
,
2595 device_get_nameunit(sc
->dev
));
2597 taskqueue_enqueue(sc
->taskqueue
, &sc
->periodic_task
);
2601 * rt2860_tx_watchdog
2603 static void rt2860_tx_watchdog(void *arg
)
2605 struct rt2860_softc
*sc
;
2611 if (sc
->tx_timer
== 0)
2614 if (--sc
->tx_timer
== 0)
2616 printf("%s: Tx watchdog timeout: resetting\n",
2617 device_get_nameunit(sc
->dev
));
2619 rt2860_stop_locked(sc
);
2620 rt2860_init_locked(sc
);
2624 sc
->tx_watchdog_timeouts
++;
2627 callout_reset(&sc
->tx_watchdog_ch
, hz
, rt2860_tx_watchdog
, sc
);
2631 * rt2860_asic_set_bssid
2633 static void rt2860_asic_set_bssid(struct rt2860_softc
*sc
,
2634 const uint8_t *bssid
)
2638 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATE
,
2639 "%s: set bssid: bssid=%s\n",
2640 device_get_nameunit(sc
->dev
), ether_sprintf(bssid
));
2642 tmp
= bssid
[0] | (bssid
[1]) << 8 | (bssid
[2] << 16) | (bssid
[3] << 24);
2644 rt2860_io_mac_write(sc
, RT2860_REG_BSSID_DW0
, tmp
);
2646 tmp
= bssid
[4] | (bssid
[5] << 8);
2648 rt2860_io_mac_write(sc
, RT2860_REG_BSSID_DW1
, tmp
);
2652 * rt2860_asic_set_macaddr
2654 static void rt2860_asic_set_macaddr(struct rt2860_softc
*sc
,
2655 const uint8_t *addr
)
2659 tmp
= addr
[0] | (addr
[1] << 8) | (addr
[2] << 16) | (addr
[3] << 24);
2661 rt2860_io_mac_write(sc
, RT2860_REG_ADDR_DW0
, tmp
);
2663 tmp
= addr
[4] | (addr
[5] << 8);
2665 rt2860_io_mac_write(sc
, RT2860_REG_ADDR_DW1
, tmp
);
2669 * rt2860_asic_enable_tsf_sync
2671 static void rt2860_asic_enable_tsf_sync(struct rt2860_softc
*sc
)
2673 struct ieee80211com
*ic
;
2678 RT2860_DPRINTF(sc
, RT2860_DEBUG_BEACON
,
2679 "%s: enabling TSF\n",
2680 device_get_nameunit(sc
->dev
));
2682 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_BCN_TIME_CFG
);
2685 tmp
|= ic
->ic_bss
->ni_intval
* 16;
2686 tmp
|= (RT2860_REG_TSF_TIMER_ENABLE
| RT2860_REG_TBTT_TIMER_ENABLE
);
2688 if (ic
->ic_opmode
== IEEE80211_M_STA
)
2690 tmp
|= (RT2860_REG_TSF_SYNC_MODE_STA
<< RT2860_REG_TSF_SYNC_MODE_SHIFT
);
2692 else if (ic
->ic_opmode
== IEEE80211_M_IBSS
)
2694 tmp
|= RT2860_REG_BCN_TX_ENABLE
;
2695 tmp
|= (RT2860_REG_TSF_SYNC_MODE_IBSS
<< RT2860_REG_TSF_SYNC_MODE_SHIFT
);
2697 else if (ic
->ic_opmode
== IEEE80211_M_HOSTAP
)
2699 tmp
|= RT2860_REG_BCN_TX_ENABLE
;
2700 tmp
|= (RT2860_REG_TSF_SYNC_MODE_HOSTAP
<< RT2860_REG_TSF_SYNC_MODE_SHIFT
);
2703 rt2860_io_mac_write(sc
, RT2860_REG_BCN_TIME_CFG
, tmp
);
2707 * rt2860_asic_disable_tsf_sync
2709 static void rt2860_asic_disable_tsf_sync(struct rt2860_softc
*sc
)
2713 RT2860_DPRINTF(sc
, RT2860_DEBUG_BEACON
,
2714 "%s: disabling TSF\n",
2715 device_get_nameunit(sc
->dev
));
2717 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_BCN_TIME_CFG
);
2719 tmp
&= ~(RT2860_REG_BCN_TX_ENABLE
|
2720 RT2860_REG_TSF_TIMER_ENABLE
|
2721 RT2860_REG_TBTT_TIMER_ENABLE
);
2723 tmp
&= ~(RT2860_REG_TSF_SYNC_MODE_MASK
<< RT2860_REG_TSF_SYNC_MODE_SHIFT
);
2724 tmp
|= (RT2860_REG_TSF_SYNC_MODE_DISABLE
<< RT2860_REG_TSF_SYNC_MODE_SHIFT
);
2726 rt2860_io_mac_write(sc
, RT2860_REG_BCN_TIME_CFG
, tmp
);
2730 * rt2860_asic_enable_mrr
2732 static void rt2860_asic_enable_mrr(struct rt2860_softc
*sc
)
2734 #define CCK(mcs) (mcs)
2735 #define OFDM(mcs) ((1 << 3) | (mcs))
2736 #define HT(mcs) (mcs)
2738 rt2860_io_mac_write(sc
, RT2860_REG_TX_LG_FBK_CFG0
,
2739 (OFDM(6) << 28) | /* 54 -> 48 */
2740 (OFDM(5) << 24) | /* 48 -> 36 */
2741 (OFDM(4) << 20) | /* 36 -> 24 */
2742 (OFDM(3) << 16) | /* 24 -> 18 */
2743 (OFDM(2) << 12) | /* 18 -> 12 */
2744 (OFDM(1) << 8) | /* 12 -> 9 */
2745 (OFDM(0) << 4) | /* 9 -> 6 */
2746 OFDM(0)); /* 6 -> 6 */
2748 rt2860_io_mac_write(sc
, RT2860_REG_TX_LG_FBK_CFG1
,
2749 (CCK(2) << 12) | /* 11 -> 5.5 */
2750 (CCK(1) << 8) | /* 5.5 -> 2 */
2751 (CCK(0) << 4) | /* 2 -> 1 */
2752 CCK(0)); /* 1 -> 1 */
2754 rt2860_io_mac_write(sc
, RT2860_REG_TX_HT_FBK_CFG0
,
2764 rt2860_io_mac_write(sc
, RT2860_REG_TX_HT_FBK_CFG1
,
2780 * rt2860_asic_set_txpreamble
2782 static void rt2860_asic_set_txpreamble(struct rt2860_softc
*sc
)
2784 struct ieee80211com
*ic
;
2789 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATE
,
2790 "%s: %s short Tx preamble\n",
2791 device_get_nameunit(sc
->dev
),
2792 (ic
->ic_flags
& IEEE80211_F_SHPREAMBLE
) ? "enabling" : "disabling");
2794 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_AUTO_RSP_CFG
);
2796 tmp
&= ~RT2860_REG_CCK_SHORT_ENABLE
;
2798 if (sc
->ic
.ic_flags
& IEEE80211_F_SHPREAMBLE
)
2799 tmp
|= RT2860_REG_CCK_SHORT_ENABLE
;
2801 rt2860_io_mac_write(sc
, RT2860_REG_AUTO_RSP_CFG
, tmp
);
2805 * rt2860_asic_set_basicrates
2807 static void rt2860_asic_set_basicrates(struct rt2860_softc
*sc
)
2809 struct ieee80211com
*ic
;
2813 if (ic
->ic_curmode
== IEEE80211_MODE_11B
)
2814 rt2860_io_mac_write(sc
, RT2860_REG_LEGACY_BASIC_RATE
, 0x3);
2815 else if (ic
->ic_curmode
== IEEE80211_MODE_11A
)
2816 rt2860_io_mac_write(sc
, RT2860_REG_LEGACY_BASIC_RATE
, 0x150);
2818 rt2860_io_mac_write(sc
, RT2860_REG_LEGACY_BASIC_RATE
, 0x15f);
2822 * rt2860_asic_update_rtsthreshold
2824 static void rt2860_asic_update_rtsthreshold(struct rt2860_softc
*sc
)
2826 struct ieee80211com
*ic
;
2832 RT2860_DPRINTF(sc
, RT2860_DEBUG_PROT
,
2833 "%s: updating RTS threshold: %d\n",
2834 device_get_nameunit(sc
->dev
), ic
->ic_rtsthreshold
);
2836 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_RTS_CFG
);
2838 tmp
&= ~(RT2860_REG_TX_RTS_THRESHOLD_MASK
<< RT2860_REG_TX_RTS_THRESHOLD_SHIFT
);
2840 if (ic
->ic_flags_ext
& IEEE80211_FEXT_AMSDU_TX
)
2843 threshold
= ic
->ic_rtsthreshold
;
2846 tmp
|= ((threshold
& RT2860_REG_TX_RTS_THRESHOLD_MASK
) <<
2847 RT2860_REG_TX_RTS_THRESHOLD_SHIFT
);
2849 rt2860_io_mac_write(sc
, RT2860_REG_TX_RTS_CFG
, tmp
);
2853 * rt2860_asic_update_txpower
2855 static void rt2860_asic_update_txpower(struct rt2860_softc
*sc
)
2857 struct ieee80211com
*ic
;
2858 uint32_t *txpow_rate
;
2866 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATE
,
2867 "%s: updating Tx power: %d\n",
2868 device_get_nameunit(sc
->dev
), ic
->ic_txpowlimit
);
2870 if (!IEEE80211_IS_CHAN_HT40(ic
->ic_curchan
))
2872 txpow_rate
= sc
->txpow_rate_20mhz
;
2876 if (IEEE80211_IS_CHAN_2GHZ(ic
->ic_curchan
))
2877 txpow_rate
= sc
->txpow_rate_40mhz_2ghz
;
2879 txpow_rate
= sc
->txpow_rate_40mhz_5ghz
;
2884 val
= rt2860_io_bbp_read(sc
, 1);
2887 if (ic
->ic_txpowlimit
> 90)
2891 else if (ic
->ic_txpowlimit
> 60)
2895 else if (ic
->ic_txpowlimit
> 30)
2899 else if (ic
->ic_txpowlimit
> 15)
2903 else if (ic
->ic_txpowlimit
> 9)
2913 rt2860_io_bbp_write(sc
, 1, val
);
2915 for (i
= 0; i
< RT2860_SOFTC_TXPOW_RATE_COUNT
; i
++)
2917 if (txpow_rate
[i
] == 0xffffffff)
2920 tmp
= rt2860_read_eeprom_txpow_rate_add_delta(txpow_rate
[i
], delta
);
2922 rt2860_io_mac_write(sc
, RT2860_REG_TX_PWR_CFG(i
), tmp
);
2927 * rt2860_asic_update_promisc
2929 static void rt2860_asic_update_promisc(struct rt2860_softc
*sc
)
2934 ifp
= sc
->ic
.ic_ifp
;
2936 printf("%s: %s promiscuous mode\n",
2937 device_get_nameunit(sc
->dev
),
2938 (ifp
->if_flags
& IFF_PROMISC
) ? "entering" : "leaving");
2940 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_RX_FILTER_CFG
);
2942 tmp
&= ~RT2860_REG_RX_FILTER_DROP_UC_NOME
;
2944 if (!(ifp
->if_flags
& IFF_PROMISC
))
2945 tmp
|= RT2860_REG_RX_FILTER_DROP_UC_NOME
;
2947 rt2860_io_mac_write(sc
, RT2860_REG_RX_FILTER_CFG
, tmp
);
2951 * rt2860_asic_updateprot
2953 static void rt2860_asic_updateprot(struct rt2860_softc
*sc
)
2955 struct ieee80211com
*ic
;
2956 uint32_t cck_prot
, ofdm_prot
, mm20_prot
, mm40_prot
, gf20_prot
, gf40_prot
;
2958 enum ieee80211_protmode htprotmode
;
2962 /* CCK frame protection */
2964 cck_prot
= RT2860_REG_RTSTH_ENABLE
| RT2860_REG_PROT_NAV_SHORT
|
2965 RT2860_REG_TXOP_ALLOW_ALL
| RT2860_REG_PROT_CTRL_NONE
;
2967 /* set up protection frame phy mode and rate (MCS code) */
2969 if (ic
->ic_curmode
== IEEE80211_MODE_11A
)
2970 cck_prot
|= (RT2860_REG_PROT_PHYMODE_OFDM
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
2971 (0 << RT2860_REG_PROT_MCS_SHIFT
);
2973 cck_prot
|= ((RT2860_REG_PROT_PHYMODE_CCK
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
2974 (3 << RT2860_REG_PROT_MCS_SHIFT
));
2976 rt2860_io_mac_write(sc
, RT2860_REG_TX_CCK_PROT_CFG
, cck_prot
);
2978 /* OFDM frame protection */
2980 ofdm_prot
= RT2860_REG_RTSTH_ENABLE
| RT2860_REG_PROT_NAV_SHORT
|
2981 RT2860_REG_TXOP_ALLOW_ALL
;
2983 if (ic
->ic_flags
& IEEE80211_F_USEPROT
)
2985 RT2860_DPRINTF(sc
, RT2860_DEBUG_PROT
,
2986 "%s: updating protection mode: b/g protection mode=%s\n",
2987 device_get_nameunit(sc
->dev
),
2988 (ic
->ic_protmode
== IEEE80211_PROT_RTSCTS
) ? "RTS/CTS" :
2989 ((ic
->ic_protmode
== IEEE80211_PROT_CTSONLY
) ? "CTS-to-self" : "none"));
2991 if (ic
->ic_protmode
== IEEE80211_PROT_RTSCTS
)
2992 ofdm_prot
|= RT2860_REG_PROT_CTRL_RTS_CTS
;
2993 else if (ic
->ic_protmode
== IEEE80211_PROT_CTSONLY
)
2994 ofdm_prot
|= RT2860_REG_PROT_CTRL_CTS
;
2996 ofdm_prot
|= RT2860_REG_PROT_CTRL_NONE
;
3000 RT2860_DPRINTF(sc
, RT2860_DEBUG_PROT
,
3001 "%s: updating protection mode: b/g protection mode=%s\n",
3002 device_get_nameunit(sc
->dev
), "none");
3004 ofdm_prot
|= RT2860_REG_PROT_CTRL_NONE
;
3007 rt2860_io_mac_write(sc
, RT2860_REG_TX_OFDM_PROT_CFG
, ofdm_prot
);
3009 /* HT frame protection */
3011 if ((ic
->ic_opmode
== IEEE80211_M_STA
) && (ic
->ic_state
== IEEE80211_S_RUN
))
3012 htopmode
= ic
->ic_bss
->ni_htopmode
;
3014 htopmode
= ic
->ic_curhtprotmode
;
3016 htprotmode
= ic
->ic_htprotmode
;
3018 /* force HT mixed mode and RTS/CTS protection if A-MPDU Tx aggregation is enabled */
3020 if (sc
->tx_ampdu_sessions
> 0)
3022 RT2860_DPRINTF(sc
, RT2860_DEBUG_PROT
,
3023 "%s: updating protection mode: forcing HT mixed mode and RTS/CTS protection\n",
3024 device_get_nameunit(sc
->dev
));
3026 htopmode
= IEEE80211_HTINFO_OPMODE_MIXED
;
3027 htprotmode
= IEEE80211_PROT_RTSCTS
;
3030 RT2860_DPRINTF(sc
, RT2860_DEBUG_PROT
,
3031 "%s: updating protection mode: HT operation mode=0x%02x, protection mode=%s\n",
3032 device_get_nameunit(sc
->dev
),
3033 htopmode
& IEEE80211_HTINFO_OPMODE
,
3034 (htprotmode
== IEEE80211_PROT_RTSCTS
) ? "RTS/CTS" :
3035 ((htprotmode
== IEEE80211_PROT_CTSONLY
) ? "CTS-to-self" : "none"));
3037 switch (htopmode
& IEEE80211_HTINFO_OPMODE
)
3039 /* IEEE80211_HTINFO_OPMODE_HT20PR */
3040 case IEEE80211_HTINFO_OPMODE_HT20PR
:
3041 mm20_prot
= RT2860_REG_PROT_NAV_SHORT
| RT2860_REG_PROT_CTRL_NONE
|
3042 RT2860_REG_TXOP_ALLOW_CCK
| RT2860_REG_TXOP_ALLOW_OFDM
|
3043 RT2860_REG_TXOP_ALLOW_MM20
| RT2860_REG_TXOP_ALLOW_GF20
|
3044 (RT2860_REG_PROT_PHYMODE_OFDM
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3045 (4 << RT2860_REG_PROT_MCS_SHIFT
);
3047 gf20_prot
= mm20_prot
;
3049 mm40_prot
= RT2860_REG_PROT_NAV_SHORT
| RT2860_REG_TXOP_ALLOW_ALL
|
3050 (RT2860_REG_PROT_PHYMODE_OFDM
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3051 (0x84 << RT2860_REG_PROT_MCS_SHIFT
);
3053 if (htprotmode
== IEEE80211_PROT_RTSCTS
)
3054 mm40_prot
|= RT2860_REG_PROT_CTRL_RTS_CTS
;
3055 else if (htprotmode
== IEEE80211_PROT_CTSONLY
)
3056 mm40_prot
|= RT2860_REG_PROT_CTRL_CTS
;
3058 mm40_prot
|= RT2860_REG_PROT_CTRL_NONE
;
3060 gf40_prot
= mm40_prot
;
3063 /* IEEE80211_HTINFO_OPMODE_MIXED */
3064 case IEEE80211_HTINFO_OPMODE_MIXED
:
3065 mm20_prot
= RT2860_REG_PROT_NAV_SHORT
|
3066 RT2860_REG_TXOP_ALLOW_CCK
| RT2860_REG_TXOP_ALLOW_OFDM
|
3067 RT2860_REG_TXOP_ALLOW_MM20
| RT2860_REG_TXOP_ALLOW_GF20
;
3069 if (ic
->ic_flags
& IEEE80211_F_USEPROT
)
3070 mm20_prot
|= (RT2860_REG_PROT_PHYMODE_CCK
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3071 (3 << RT2860_REG_PROT_MCS_SHIFT
);
3073 mm20_prot
|= (RT2860_REG_PROT_PHYMODE_OFDM
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3074 (4 << RT2860_REG_PROT_MCS_SHIFT
);
3076 if (htprotmode
== IEEE80211_PROT_RTSCTS
)
3077 mm20_prot
|= RT2860_REG_PROT_CTRL_RTS_CTS
;
3078 else if (htprotmode
== IEEE80211_PROT_CTSONLY
)
3079 mm20_prot
|= RT2860_REG_PROT_CTRL_CTS
;
3081 mm20_prot
|= RT2860_REG_PROT_CTRL_NONE
;
3083 gf20_prot
= mm20_prot
;
3085 mm40_prot
= RT2860_REG_PROT_NAV_SHORT
| RT2860_REG_TXOP_ALLOW_ALL
;
3087 if (ic
->ic_flags
& IEEE80211_F_USEPROT
)
3088 mm40_prot
|= (RT2860_REG_PROT_PHYMODE_CCK
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3089 (3 << RT2860_REG_PROT_MCS_SHIFT
);
3091 mm40_prot
|= (RT2860_REG_PROT_PHYMODE_OFDM
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3092 (0x84 << RT2860_REG_PROT_MCS_SHIFT
);
3094 if (htprotmode
== IEEE80211_PROT_RTSCTS
)
3095 mm40_prot
|= RT2860_REG_PROT_CTRL_RTS_CTS
;
3096 else if (htprotmode
== IEEE80211_PROT_CTSONLY
)
3097 mm40_prot
|= RT2860_REG_PROT_CTRL_CTS
;
3099 mm40_prot
|= RT2860_REG_PROT_CTRL_NONE
;
3101 gf40_prot
= mm40_prot
;
3105 * IEEE80211_HTINFO_OPMODE_PURE
3106 * IEEE80211_HTINFO_OPMODE_PROTOPT
3108 case IEEE80211_HTINFO_OPMODE_PURE
:
3109 case IEEE80211_HTINFO_OPMODE_PROTOPT
:
3111 mm20_prot
= RT2860_REG_PROT_NAV_SHORT
| RT2860_REG_PROT_CTRL_NONE
|
3112 RT2860_REG_TXOP_ALLOW_CCK
| RT2860_REG_TXOP_ALLOW_OFDM
|
3113 RT2860_REG_TXOP_ALLOW_MM20
| RT2860_REG_TXOP_ALLOW_GF20
|
3114 (RT2860_REG_PROT_PHYMODE_OFDM
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3115 (4 << RT2860_REG_PROT_MCS_SHIFT
);
3117 gf20_prot
= mm20_prot
;
3119 mm40_prot
= RT2860_REG_PROT_NAV_SHORT
| RT2860_REG_PROT_CTRL_NONE
|
3120 RT2860_REG_TXOP_ALLOW_ALL
|
3121 (RT2860_REG_PROT_PHYMODE_OFDM
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3122 (0x84 << RT2860_REG_PROT_MCS_SHIFT
);
3124 gf40_prot
= mm40_prot
;
3128 rt2860_io_mac_write(sc
, RT2860_REG_TX_MM20_PROT_CFG
, mm20_prot
);
3129 rt2860_io_mac_write(sc
, RT2860_REG_TX_MM40_PROT_CFG
, mm40_prot
);
3130 rt2860_io_mac_write(sc
, RT2860_REG_TX_GF20_PROT_CFG
, gf20_prot
);
3131 rt2860_io_mac_write(sc
, RT2860_REG_TX_GF40_PROT_CFG
, gf40_prot
);
3135 * rt2860_asic_updateslot
3137 static void rt2860_asic_updateslot(struct rt2860_softc
*sc
)
3139 struct ieee80211com
*ic
;
3144 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATE
,
3145 "%s: %s short slot time\n",
3146 device_get_nameunit(sc
->dev
),
3147 (ic
->ic_flags
& (IEEE80211_F_SHSLOT
| IEEE80211_F_BURST
)) ? "enabling" : "disabling");
3149 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_BKOFF_SLOT_CFG
);
3152 tmp
|= (ic
->ic_flags
& (IEEE80211_F_SHSLOT
|IEEE80211_F_BURST
)) ? 9 : 20;
3154 rt2860_io_mac_write(sc
, RT2860_REG_BKOFF_SLOT_CFG
, tmp
);
3158 * rt2860_asic_wme_update
3160 static void rt2860_asic_wme_update(struct rt2860_softc
*sc
)
3162 struct ieee80211com
*ic
;
3163 struct ieee80211_wme_state
*wme
;
3164 const struct wmeParams
*wmep
;
3169 wmep
= wme
->wme_chanParams
.cap_wmeParams
;
3171 RT2860_DPRINTF(sc
, RT2860_DEBUG_WME
,
3172 "%s: wme update: WME_AC_VO=%d/%d/%d/%d, WME_AC_VI=%d/%d/%d/%d, "
3173 "WME_AC_BK=%d/%d/%d/%d, WME_AC_BE=%d/%d/%d/%d\n",
3174 device_get_nameunit(sc
->dev
),
3175 wmep
[WME_AC_VO
].wmep_aifsn
,
3176 wmep
[WME_AC_VO
].wmep_logcwmin
, wmep
[WME_AC_VO
].wmep_logcwmax
,
3177 wmep
[WME_AC_VO
].wmep_txopLimit
,
3178 wmep
[WME_AC_VI
].wmep_aifsn
,
3179 wmep
[WME_AC_VI
].wmep_logcwmin
, wmep
[WME_AC_VI
].wmep_logcwmax
,
3180 wmep
[WME_AC_VI
].wmep_txopLimit
,
3181 wmep
[WME_AC_BK
].wmep_aifsn
,
3182 wmep
[WME_AC_BK
].wmep_logcwmin
, wmep
[WME_AC_BK
].wmep_logcwmax
,
3183 wmep
[WME_AC_BK
].wmep_txopLimit
,
3184 wmep
[WME_AC_BE
].wmep_aifsn
,
3185 wmep
[WME_AC_BE
].wmep_logcwmin
, wmep
[WME_AC_BE
].wmep_logcwmax
,
3186 wmep
[WME_AC_BE
].wmep_txopLimit
);
3188 for (i
= 0; i
< WME_NUM_AC
; i
++)
3189 rt2860_io_mac_write(sc
, RT2860_REG_TX_EDCA_AC_CFG(i
),
3190 (wmep
[i
].wmep_logcwmax
<< 16) | (wmep
[i
].wmep_logcwmin
<< 12) |
3191 (wmep
[i
].wmep_aifsn
<< 8) | wmep
[i
].wmep_txopLimit
);
3193 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WMM_AIFSN_CFG
,
3194 (wmep
[WME_AC_VO
].wmep_aifsn
<< 12) | (wmep
[WME_AC_VI
].wmep_aifsn
<< 8) |
3195 (wmep
[WME_AC_BK
].wmep_aifsn
<< 4) | wmep
[WME_AC_BE
].wmep_aifsn
);
3197 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WMM_CWMIN_CFG
,
3198 (wmep
[WME_AC_VO
].wmep_logcwmin
<< 12) | (wmep
[WME_AC_VI
].wmep_logcwmin
<< 8) |
3199 (wmep
[WME_AC_BK
].wmep_logcwmin
<< 4) | wmep
[WME_AC_BE
].wmep_logcwmin
);
3201 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WMM_CWMAX_CFG
,
3202 (wmep
[WME_AC_VO
].wmep_logcwmax
<< 12) | (wmep
[WME_AC_VI
].wmep_logcwmax
<< 8) |
3203 (wmep
[WME_AC_BK
].wmep_logcwmax
<< 4) | wmep
[WME_AC_BE
].wmep_logcwmax
);
3205 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WMM_TXOP0_CFG
,
3206 (wmep
[WME_AC_BK
].wmep_txopLimit
<< 16) | wmep
[WME_AC_BE
].wmep_txopLimit
);
3208 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WMM_TXOP1_CFG
,
3209 (wmep
[WME_AC_VO
].wmep_txopLimit
<< 16) | wmep
[WME_AC_VI
].wmep_txopLimit
);
3213 * rt2860_asic_update_beacon
3215 static int rt2860_asic_update_beacon(struct rt2860_softc
*sc
)
3217 struct ieee80211com
*ic
;
3219 struct rt2860_txwi txwi
;
3225 m
= ieee80211_beacon_alloc(ic
->ic_bss
, &sc
->beacon_offsets
);
3229 rate
= IEEE80211_IS_CHAN_5GHZ(ic
->ic_curchan
) ? 12 : 2;
3230 mcs
= rt2860_rate2mcs(rate
);
3232 memset(&txwi
, 0, sizeof(struct rt2860_txwi
));
3235 txwi
.pid_mpdu_len
= ((htole16(m
->m_pkthdr
.len
) & RT2860_TXWI_MPDU_LEN_MASK
) <<
3236 RT2860_TXWI_MPDU_LEN_SHIFT
);
3237 txwi
.txop
= (RT2860_TXWI_TXOP_HT
<< RT2860_TXWI_TXOP_SHIFT
);
3238 txwi
.mpdu_density_flags
|=
3239 (RT2860_TXWI_FLAGS_TS
<< RT2860_TXWI_FLAGS_SHIFT
);
3240 txwi
.bawin_size_xflags
|=
3241 (RT2860_TXWI_XFLAGS_NSEQ
<< RT2860_TXWI_XFLAGS_SHIFT
);
3245 txwi
.phymode_ifs_stbc_shortgi
=
3246 (RT2860_TXWI_PHYMODE_CCK
<< RT2860_TXWI_PHYMODE_SHIFT
);
3248 if (rate
!= 2 && (ic
->ic_flags
& IEEE80211_F_SHPREAMBLE
))
3249 mcs
|= RT2860_TXWI_MCS_SHOTPRE
;
3253 txwi
.phymode_ifs_stbc_shortgi
=
3254 (RT2860_TXWI_PHYMODE_OFDM
<< RT2860_TXWI_PHYMODE_SHIFT
);
3257 txwi
.bw_mcs
= (RT2860_TXWI_BW_20
<< RT2860_TXWI_BW_SHIFT
) |
3258 ((mcs
& RT2860_TXWI_MCS_MASK
) << RT2860_TXWI_MCS_SHIFT
);
3260 /* disable temporarily TSF sync */
3262 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_BCN_TIME_CFG
);
3264 tmp
&= ~(RT2860_REG_BCN_TX_ENABLE
|
3265 RT2860_REG_TSF_TIMER_ENABLE
|
3266 RT2860_REG_TBTT_TIMER_ENABLE
);
3268 rt2860_io_mac_write(sc
, RT2860_REG_BCN_TIME_CFG
, tmp
);
3270 /* write Tx wireless info and beacon frame to on-chip memory */
3272 rt2860_io_mac_write_multi(sc
, RT2860_REG_BEACON_BASE(0),
3273 &txwi
, sizeof(struct rt2860_txwi
));
3275 rt2860_io_mac_write_multi(sc
, RT2860_REG_BEACON_BASE(0) + sizeof(struct rt2860_txwi
),
3276 mtod(m
, uint8_t *), m
->m_pkthdr
.len
);
3278 /* enable again TSF sync */
3280 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_BCN_TIME_CFG
);
3282 tmp
|= (RT2860_REG_BCN_TX_ENABLE
|
3283 RT2860_REG_TSF_TIMER_ENABLE
|
3284 RT2860_REG_TBTT_TIMER_ENABLE
);
3286 rt2860_io_mac_write(sc
, RT2860_REG_BCN_TIME_CFG
, tmp
);
3294 * rt2860_asic_clear_keytables
3296 static void rt2860_asic_clear_keytables(struct rt2860_softc
*sc
)
3300 /* clear Rx WCID search table (entries = 256, entry size = 8) */
3302 for (i
= 0; i
< 256; i
++)
3304 rt2860_io_mac_write(sc
, RT2860_REG_WCID(i
), 0xffffffff);
3305 rt2860_io_mac_write(sc
, RT2860_REG_WCID(i
) + 4, 0x0000ffff);
3308 /* clear WCID attribute table (entries = 256, entry size = 4) */
3310 rt2860_io_mac_set_region_4(sc
, RT2860_REG_WCID_ATTR(0), 0, 256);
3312 /* clear IV/EIV table (entries = 256, entry size = 8) */
3314 rt2860_io_mac_set_region_4(sc
, RT2860_REG_IVEIV(0), 0, 2 * 256);
3316 /* clear pairwise key table (entries = 256, entry size = 32) */
3318 rt2860_io_mac_set_region_4(sc
, RT2860_REG_PKEY(0), 0, 8 * 256);
3320 /* clear shared key table (entries = 32, entry size = 32) */
3322 rt2860_io_mac_set_region_4(sc
, RT2860_REG_SKEY(0, 0), 0, 8 * 32);
3324 /* clear shared key mode (entries = 32, entry size = 2) */
3326 rt2860_io_mac_set_region_4(sc
, RT2860_REG_SKEY_MODE(0), 0, 16);
3332 static uint8_t rt2860_rxrate(struct rt2860_rxwi
*rxwi
)
3334 uint8_t mcs
, phymode
;
3337 mcs
= (rxwi
->bw_mcs
>> RT2860_RXWI_MCS_SHIFT
) & RT2860_RXWI_MCS_MASK
;
3338 phymode
= (rxwi
->phymode_stbc_shortgi
>> RT2860_RXWI_PHYMODE_SHIFT
) &
3339 RT2860_RXWI_PHYMODE_MASK
;
3345 case RT2860_RXWI_PHYMODE_CCK
:
3346 switch (mcs
& ~RT2860_RXWI_MCS_SHOTPRE
)
3348 case 0: rate
= 2; break; /* 1 Mbps */
3349 case 1: rate
= 4; break; /* 2 MBps */
3350 case 2: rate
= 11; break; /* 5.5 Mbps */
3351 case 3: rate
= 22; break; /* 11 Mbps */
3355 case RT2860_RXWI_PHYMODE_OFDM
:
3358 case 0: rate
= 12; break; /* 6 Mbps */
3359 case 1: rate
= 18; break; /* 9 Mbps */
3360 case 2: rate
= 24; break; /* 12 Mbps */
3361 case 3: rate
= 36; break; /* 18 Mbps */
3362 case 4: rate
= 48; break; /* 24 Mbps */
3363 case 5: rate
= 72; break; /* 36 Mbps */
3364 case 6: rate
= 96; break; /* 48 Mbps */
3365 case 7: rate
= 108; break; /* 54 Mbps */
3369 case RT2860_RXWI_PHYMODE_HT_MIXED
:
3370 case RT2860_RXWI_PHYMODE_HT_GF
:
3378 * rt2860_maxrssi_rxpath
3380 static uint8_t rt2860_maxrssi_rxpath(struct rt2860_softc
*sc
,
3381 const struct rt2860_rxwi
*rxwi
)
3387 if (sc
->nrxpath
> 1)
3388 if (rxwi
->rssi
[1] > rxwi
->rssi
[rxpath
])
3391 if (sc
->nrxpath
> 2)
3392 if (rxwi
->rssi
[2] > rxwi
->rssi
[rxpath
])
3401 static int8_t rt2860_rssi2dbm(struct rt2860_softc
*sc
,
3402 uint8_t rssi
, uint8_t rxpath
)
3404 struct ieee80211com
*ic
;
3405 struct ieee80211_channel
*c
;
3407 int8_t rssi_off
, lna_gain
;
3414 chan
= ieee80211_chan2ieee(ic
, c
);
3416 if (IEEE80211_IS_CHAN_5GHZ(c
))
3418 rssi_off
= sc
->rssi_off_5ghz
[rxpath
];
3421 lna_gain
= sc
->lna_gain
[1];
3422 else if (chan
<= 128)
3423 lna_gain
= sc
->lna_gain
[2];
3425 lna_gain
= sc
->lna_gain
[3];
3429 rssi_off
= sc
->rssi_off_2ghz
[rxpath
];
3430 lna_gain
= sc
->lna_gain
[0];
3433 return (-12 - rssi_off
- lna_gain
- rssi
);
3439 static uint8_t rt2860_rate2mcs(uint8_t rate
)
3466 static int rt2860_ackrate(struct ieee80211com
*ic
, int rate
)
3478 return (ic
->ic_curmode
== IEEE80211_MODE_11B
) ? 4 : rate
;
3497 /* default to 1Mbps */
3504 static uint16_t rt2860_txtime(int len
, int rate
, uint32_t flags
)
3508 if (RT2860_RATE_IS_OFDM(rate
))
3510 txtime
= (8 + 4 * len
+ 3 + rate
- 1) / rate
;
3511 txtime
= 16 + 4 + 4 * txtime
+ 6;
3515 txtime
= (16 * len
+ rate
- 1) / rate
;
3517 if (rate
!= 2 && (flags
& IEEE80211_F_SHPREAMBLE
))
3529 static int rt2860_tx_frame(struct rt2860_softc
*sc
,
3530 struct mbuf
*m
, struct ieee80211_node
*ni
, int qid
)
3532 struct ieee80211com
*ic
;
3533 struct rt2860_softc_tx_ring
*ring
;
3534 struct rt2860_softc_tx_data
*data
;
3535 struct rt2860_txdesc
*desc
;
3536 struct rt2860_txwi
*txwi
;
3537 struct ieee80211_frame
*wh
;
3538 struct ieee80211_tx_ampdu
*tx_ampdu
;
3539 struct rt2860_softc_tx_radiotap_header
*tap
;
3540 bus_dma_segment_t dma_seg
[RT2860_SOFTC_MAX_SCATTER
];
3541 u_int hdrsize
, hdrspace
;
3542 uint8_t type
, rate
, bw
, stbc
, shortgi
, mcs
, pid
, wcid
, mpdu_density
, bawin_size
, qsel
;
3543 uint16_t qos
, len
, dmalen
, mpdu_len
, dur
;
3544 int error
, hasqos
, ac
, ampdu
, mimops
, ackrate
, ndmasegs
, ndescs
, i
, j
;
3546 KASSERT(qid
>= 0 && qid
< RT2860_SOFTC_TX_RING_COUNT
,
3547 ("%s: Tx frame: invalid qid=%d\n",
3548 device_get_nameunit(sc
->dev
), qid
));
3552 ring
= &sc
->tx_ring
[qid
];
3553 desc
= &ring
->desc
[ring
->desc_cur
];
3554 data
= &ring
->data
[ring
->data_cur
];
3555 txwi
= (struct rt2860_txwi
*) (ring
->seg0
+ ring
->data_cur
* RT2860_TX_DATA_SEG0_SIZE
);
3557 wh
= mtod(m
, struct ieee80211_frame
*);
3559 type
= wh
->i_fc
[0] & IEEE80211_FC0_TYPE_MASK
;
3561 hasqos
= IEEE80211_QOS_HAS_SEQ(wh
);
3564 if (IEEE80211_HAS_ADDR4(wh
))
3565 qos
= le16toh(*(const uint16_t *)
3566 (((struct ieee80211_qosframe_addr4
*) wh
)->i_qos
));
3568 qos
= le16toh(*(const uint16_t *)
3569 (((struct ieee80211_qosframe
*) wh
)->i_qos
));
3576 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
3578 if (IEEE80211_IS_MULTICAST(wh
->i_addr1
) || type
!= IEEE80211_FC0_TYPE_DATA
)
3580 else if (ic
->ic_fixed_rate
!= IEEE80211_FIXED_RATE_NONE
)
3581 rate
= ic
->ic_fixed_rate
;
3583 rate
= ni
->ni_htrates
.rs_rates
[ni
->ni_txrate
];
3587 if (IEEE80211_IS_MULTICAST(wh
->i_addr1
) || type
!= IEEE80211_FC0_TYPE_DATA
)
3588 rate
= IEEE80211_IS_CHAN_5GHZ(ic
->ic_curchan
) ? 12 : 2;
3589 else if (ic
->ic_fixed_rate
!= IEEE80211_FIXED_RATE_NONE
)
3590 rate
= ic
->ic_fixed_rate
;
3592 rate
= ni
->ni_rates
.rs_rates
[ni
->ni_txrate
];
3595 rate
&= IEEE80211_RATE_VAL
;
3597 /* fill Tx wireless info */
3599 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
3602 mcs
= rt2860_rate2mcs(rate
);
3604 /* management frames do not need encryption */
3606 wcid
= (type
== IEEE80211_FC0_TYPE_DATA
) ?
3607 RT2860_AID2WCID(ni
->ni_associd
) : 0xff;
3609 /* calculate MPDU length without padding */
3611 hdrsize
= ieee80211_hdrsize(wh
);
3612 hdrspace
= ieee80211_hdrspace(ic
, wh
);
3613 mpdu_len
= m
->m_pkthdr
.len
- hdrspace
+ hdrsize
;
3615 memset(txwi
, 0, sizeof(struct rt2860_txwi
));
3619 /* MIMO power save */
3621 if ((ni
->ni_flags
& IEEE80211_NODE_HT
) &&
3622 ((ni
->ni_htcap
& IEEE80211_HTCAP_SMPS
) != IEEE80211_HTCAP_SMPS_OFF
))
3626 if ((ni
->ni_htcap
& IEEE80211_HTCAP_SMPS
) == IEEE80211_HTCAP_SMPS_DYNAMIC
)
3628 /* dynamic MIMO power save */
3630 txwi
->mpdu_density_flags
|=
3631 (RT2860_TXWI_FLAGS_MIMOPS
<< RT2860_TXWI_FLAGS_SHIFT
);
3635 /* static MIMO power save */
3650 txwi
->pid_mpdu_len
= ((htole16(pid
) & RT2860_TXWI_PID_MASK
) <<
3651 RT2860_TXWI_PID_SHIFT
) | ((htole16(mpdu_len
) & RT2860_TXWI_MPDU_LEN_MASK
) <<
3652 RT2860_TXWI_MPDU_LEN_SHIFT
);
3654 stbc
= (ic
->ic_htcaps
& IEEE80211_HTCAP_TXSTBC
) &&
3655 (ni
->ni_flags
& IEEE80211_NODE_HT
) && (ni
->ni_htcap
& IEEE80211_HTCAP_RXSTBC
);
3657 shortgi
= (ic
->ic_flags_ext
& (IEEE80211_FEXT_SHORTGI20
| IEEE80211_FEXT_SHORTGI40
)) &&
3658 (ni
->ni_flags
& IEEE80211_NODE_HT
) && (ni
->ni_htcap
& (IEEE80211_HTCAP_SHORTGI20
| IEEE80211_HTCAP_SHORTGI40
));
3660 txwi
->phymode_ifs_stbc_shortgi
|=
3661 ((stbc
& RT2860_TXWI_STBC_MASK
) << RT2860_TXWI_STBC_SHIFT
) |
3662 ((shortgi
& RT2860_TXWI_SHORTGI_MASK
) << RT2860_TXWI_SHORTGI_SHIFT
);
3664 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
3666 txwi
->phymode_ifs_stbc_shortgi
|=
3667 (RT2860_TXWI_PHYMODE_HT_MIXED
<< RT2860_TXWI_PHYMODE_SHIFT
);
3671 if (!RT2860_RATE_IS_OFDM(rate
))
3673 txwi
->phymode_ifs_stbc_shortgi
|=
3674 (RT2860_TXWI_PHYMODE_CCK
<< RT2860_TXWI_PHYMODE_SHIFT
);
3676 if (rate
!= 2 && (ic
->ic_flags
& IEEE80211_F_SHPREAMBLE
))
3677 mcs
|= RT2860_TXWI_MCS_SHOTPRE
;
3681 txwi
->phymode_ifs_stbc_shortgi
|=
3682 (RT2860_TXWI_PHYMODE_OFDM
<< RT2860_TXWI_PHYMODE_SHIFT
);
3686 if ((ni
->ni_flags
& IEEE80211_NODE_HT
) && (ni
->ni_chw
== 40))
3687 bw
= RT2860_TXWI_BW_40
;
3689 bw
= RT2860_TXWI_BW_20
;
3691 txwi
->bw_mcs
= ((bw
& RT2860_TXWI_BW_MASK
) << RT2860_TXWI_BW_SHIFT
) |
3692 ((mcs
& RT2860_TXWI_MCS_MASK
) << RT2860_TXWI_MCS_SHIFT
);
3694 if (type
!= IEEE80211_FC0_TYPE_DATA
)
3695 txwi
->txop
= (RT2860_TXWI_TXOP_BACKOFF
<< RT2860_TXWI_TXOP_SHIFT
);
3697 txwi
->txop
= (RT2860_TXWI_TXOP_HT
<< RT2860_TXWI_TXOP_SHIFT
);
3699 /* skip ACKs for multicast frames */
3701 if (!IEEE80211_IS_MULTICAST(wh
->i_addr1
) &&
3702 (!hasqos
|| (qos
& IEEE80211_QOS_ACKPOLICY
) != IEEE80211_QOS_ACKPOLICY_NOACK
))
3704 txwi
->bawin_size_xflags
|=
3705 (RT2860_TXWI_XFLAGS_ACK
<< RT2860_TXWI_XFLAGS_SHIFT
);
3707 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
3709 /* preamble + plcp + signal extension + SIFS */
3711 dur
= 16 + 4 + 6 + 10;
3715 ackrate
= rt2860_ackrate(ic
, rate
);
3717 dur
= rt2860_txtime(RT2860_ACK_SIZE
, ackrate
, ic
->ic_flags
) +
3721 *(uint16_t *) wh
->i_dur
= htole16(dur
);
3724 /* check for A-MPDU */
3726 if ((qos
& IEEE80211_QOS_ACKPOLICY
) == IEEE80211_QOS_ACKPOLICY_BA
)
3728 ac
= M_WME_GETAC(m
);
3729 tx_ampdu
= &ni
->ni_tx_ampdu
[ac
];
3731 mpdu_density
= RT2860_MS(ni
->ni_htparam
, IEEE80211_HTCAP_MPDUDENSITY
);
3732 bawin_size
= tx_ampdu
->txa_wnd
;
3734 txwi
->mpdu_density_flags
|=
3735 ((mpdu_density
& RT2860_TXWI_MPDU_DENSITY_MASK
) << RT2860_TXWI_MPDU_DENSITY_SHIFT
) |
3736 (RT2860_TXWI_FLAGS_AMPDU
<< RT2860_TXWI_FLAGS_SHIFT
);
3738 txwi
->bawin_size_xflags
|=
3739 ((bawin_size
& RT2860_TXWI_BAWIN_SIZE_MASK
) << RT2860_TXWI_BAWIN_SIZE_SHIFT
);
3741 if (IEEE80211_HAS_ADDR4(wh
))
3742 ((struct ieee80211_qosframe_addr4
*) wh
)->i_qos
[0] &= ~IEEE80211_QOS_ACKPOLICY
;
3744 ((struct ieee80211_qosframe
*) wh
)->i_qos
[0] &= ~IEEE80211_QOS_ACKPOLICY
;
3753 /* ask MAC to insert timestamp into probe responses */
3755 if ((wh
->i_fc
[0] & (IEEE80211_FC0_TYPE_MASK
| IEEE80211_FC0_SUBTYPE_MASK
)) ==
3756 (IEEE80211_FC0_TYPE_MGT
| IEEE80211_FC0_SUBTYPE_PROBE_RESP
))
3757 txwi
->mpdu_density_flags
|=
3758 (RT2860_TXWI_FLAGS_TS
<< RT2860_TXWI_FLAGS_SHIFT
);
3760 if (bpf_peers_present(sc
->drvbpf
))
3764 tap
->flags
= IEEE80211_RADIOTAP_F_DATAPAD
;
3765 tap
->chan_flags
= htole32(ic
->ic_curchan
->ic_flags
);
3766 tap
->chan_freq
= htole16(ic
->ic_curchan
->ic_freq
);
3767 tap
->chan_ieee
= ic
->ic_curchan
->ic_ieee
;
3768 tap
->chan_maxpow
= 0;
3770 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
3771 tap
->rate
= mcs
| IEEE80211_RATE_MCS
;
3775 if (mcs
& RT2860_TXWI_MCS_SHOTPRE
)
3776 tap
->flags
|= IEEE80211_RADIOTAP_F_SHORTPRE
;
3779 tap
->flags
|= IEEE80211_RADIOTAP_F_SHORTGI
;
3781 if (wh
->i_fc
[1] & IEEE80211_FC1_WEP
)
3782 tap
->flags
|= IEEE80211_RADIOTAP_F_WEP
;
3784 if (wh
->i_fc
[1] & IEEE80211_FC1_WEP
)
3786 wh
->i_fc
[1] &= ~IEEE80211_FC1_WEP
;
3788 bpf_mtap2(sc
->drvbpf
, tap
, sc
->txtap_len
, m
);
3790 wh
->i_fc
[1] |= IEEE80211_FC1_WEP
;
3794 bpf_mtap2(sc
->drvbpf
, tap
, sc
->txtap_len
, m
);
3798 /* copy and trim 802.11 header */
3800 m_copydata(m
, 0, hdrsize
, (caddr_t
) (txwi
+ 1));
3803 error
= bus_dmamap_load_mbuf_sg(ring
->data_dma_tag
, data
->dma_map
, m
,
3804 dma_seg
, &ndmasegs
, 0);
3807 /* too many fragments, linearize */
3809 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
3810 "%s: could not load mbuf DMA map, trying to linearize mbuf\n",
3811 device_get_nameunit(sc
->dev
));
3813 m
= m_defrag(m
, M_DONTWAIT
);
3817 sc
->tx_defrag_packets
++;
3819 error
= bus_dmamap_load_mbuf_sg(ring
->data_dma_tag
, data
->dma_map
, m
,
3820 dma_seg
, &ndmasegs
, 0);
3823 printf("%s: could not load mbuf DMA map: error=%d\n",
3824 device_get_nameunit(sc
->dev
), error
);
3830 if (m
->m_pkthdr
.len
== 0)
3833 /* determine how many Tx descs are required */
3835 ndescs
= 1 + ndmasegs
/ 2;
3836 if ((ring
->desc_queued
+ ndescs
) > (RT2860_SOFTC_TX_RING_DESC_COUNT
- 2))
3838 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
3839 "%s: there are not enough Tx descs\n",
3840 device_get_nameunit(sc
->dev
));
3842 sc
->no_tx_desc_avail
++;
3844 bus_dmamap_unload(ring
->data_dma_tag
, data
->dma_map
);
3852 /* set up Tx descs */
3854 /* first segment is Tx wireless info and 802.11 header */
3856 len
= sizeof(struct rt2860_txwi
) + hdrsize
;
3858 /* align end on a 4-bytes boundary */
3860 dmalen
= (len
+ 3) & ~ 3;
3862 memset((caddr_t
) txwi
+ len
, 0, dmalen
- len
);
3864 qsel
= RT2860_TXDESC_QSEL_EDCA
;
3866 desc
->sdp0
= htole32(ring
->seg0_phys_addr
+ ring
->data_cur
* RT2860_TX_DATA_SEG0_SIZE
);
3867 desc
->sdl0
= htole16(dmalen
);
3868 desc
->qsel_flags
= (qsel
<< RT2860_TXDESC_QSEL_SHIFT
);
3870 /* set up payload segments */
3872 for (i
= ndmasegs
, j
= 0; i
>= 2; i
-= 2)
3874 desc
->sdp1
= htole32(dma_seg
[j
].ds_addr
);
3875 desc
->sdl1
= htole16(dma_seg
[j
].ds_len
);
3877 ring
->desc_queued
++;
3878 ring
->desc_cur
= (ring
->desc_cur
+ 1) % RT2860_SOFTC_TX_RING_DESC_COUNT
;
3882 desc
= &ring
->desc
[ring
->desc_cur
];
3884 desc
->sdp0
= htole32(dma_seg
[j
].ds_addr
);
3885 desc
->sdl0
= htole16(dma_seg
[j
].ds_len
);
3886 desc
->qsel_flags
= (qsel
<< RT2860_TXDESC_QSEL_SHIFT
);
3891 /* finalize last payload segment */
3895 desc
->sdp1
= htole32(dma_seg
[j
].ds_addr
);
3896 desc
->sdl1
= htole16(dma_seg
[j
].ds_len
| RT2860_TXDESC_SDL1_LASTSEG
);
3900 desc
->sdl0
|= htole16(RT2860_TXDESC_SDL0_LASTSEG
);
3904 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
3905 "%s: sending frame: qid=%d, hdrsize=%d, hdrspace=%d, len=%d, "
3906 "bw=%d, stbc=%d, shortgi=%d, mcs=%d, wcid=0x%02x, ampdu=%d, mimops=%d, DMA len=%d, ndmasegs=%d, DMA ds_len=%d/%d/%d/%d/%d\n",
3907 device_get_nameunit(sc
->dev
),
3908 qid
, hdrsize
, hdrspace
, m
->m_pkthdr
.len
+ hdrsize
,
3909 bw
, stbc
, shortgi
, mcs
, wcid
, ampdu
, mimops
, dmalen
, ndmasegs
,
3910 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
);
3912 bus_dmamap_sync(ring
->seg0_dma_tag
, ring
->seg0_dma_map
,
3913 BUS_DMASYNC_PREWRITE
);
3914 bus_dmamap_sync(ring
->data_dma_tag
, data
->dma_map
,
3915 BUS_DMASYNC_PREWRITE
);
3916 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
3917 BUS_DMASYNC_PREWRITE
);
3919 ring
->desc_queued
++;
3920 ring
->desc_cur
= (ring
->desc_cur
+ 1) % RT2860_SOFTC_TX_RING_DESC_COUNT
;
3922 ring
->data_queued
++;
3923 ring
->data_cur
= (ring
->data_cur
+ 1) % RT2860_SOFTC_TX_RING_DATA_COUNT
;
3927 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_CTX_IDX(qid
), ring
->desc_cur
);
3935 static int rt2860_tx_raw(struct rt2860_softc
*sc
,
3936 struct mbuf
*m
, struct ieee80211_node
*ni
,
3937 const struct ieee80211_bpf_params
*params
)
3939 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
3941 device_get_nameunit(sc
->dev
));
3949 static void rt2860_intr(void *arg
)
3951 struct rt2860_softc
*sc
;
3958 /* acknowledge interrupts */
3960 status
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_INT_STATUS
);
3961 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_INT_STATUS
, status
);
3963 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
3964 "%s: interrupt: status = 0x%08x\n",
3965 device_get_nameunit(sc
->dev
), status
);
3967 if (status
== 0xffffffff || /* device likely went away */
3968 status
== 0) /* not for us */
3973 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
3976 if (status
& RT2860_REG_INT_TX_COHERENT
)
3977 rt2860_tx_coherent_intr(sc
);
3979 if (status
& RT2860_REG_INT_RX_COHERENT
)
3980 rt2860_rx_coherent_intr(sc
);
3982 if (status
& RT2860_REG_INT_TXRX_COHERENT
)
3983 rt2860_txrx_coherent_intr(sc
);
3985 if (status
& RT2860_REG_INT_FIFO_STA_FULL
)
3986 rt2860_fifo_sta_full_intr(sc
);
3988 if (status
& RT2860_REG_INT_TX_MGMT_DONE
)
3989 rt2860_tx_intr(sc
, 5);
3991 if (status
& RT2860_REG_INT_RX_DONE
)
3994 if (status
& RT2860_REG_INT_RX_DELAY_DONE
)
3995 rt2860_rx_delay_intr(sc
);
3997 if (status
& RT2860_REG_INT_TX_HCCA_DONE
)
3998 rt2860_tx_intr(sc
, 4);
4000 if (status
& RT2860_REG_INT_TX_AC3_DONE
)
4001 rt2860_tx_intr(sc
, 3);
4003 if (status
& RT2860_REG_INT_TX_AC2_DONE
)
4004 rt2860_tx_intr(sc
, 2);
4006 if (status
& RT2860_REG_INT_TX_AC1_DONE
)
4007 rt2860_tx_intr(sc
, 1);
4009 if (status
& RT2860_REG_INT_TX_AC0_DONE
)
4010 rt2860_tx_intr(sc
, 0);
4012 if (status
& RT2860_REG_INT_TX_DELAY_DONE
)
4013 rt2860_tx_delay_intr(sc
);
4015 if (status
& RT2860_REG_INT_PRE_TBTT
)
4016 rt2860_pre_tbtt_intr(sc
);
4018 if (status
& RT2860_REG_INT_TBTT
)
4019 rt2860_tbtt_intr(sc
);
4021 if (status
& RT2860_REG_INT_MCU_CMD
)
4022 rt2860_mcu_cmd_intr(sc
);
4024 if (status
& RT2860_REG_INT_AUTO_WAKEUP
)
4025 rt2860_auto_wakeup_intr(sc
);
4027 if (status
& RT2860_REG_INT_GP_TIMER
)
4028 rt2860_gp_timer_intr(sc
);
4032 * rt2860_tx_coherent_intr
4034 static void rt2860_tx_coherent_intr(struct rt2860_softc
*sc
)
4039 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4040 "%s: Tx coherent interrupt\n",
4041 device_get_nameunit(sc
->dev
));
4043 sc
->tx_coherent_interrupts
++;
4045 /* restart DMA engine */
4047 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
);
4049 tmp
&= ~(RT2860_REG_TX_WB_DDONE
|
4050 RT2860_REG_RX_DMA_ENABLE
|
4051 RT2860_REG_TX_DMA_ENABLE
);
4053 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
, tmp
);
4055 /* init Tx rings (4 EDCAs + HCCA + MGMT) */
4057 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
4058 rt2860_reset_tx_ring(sc
, &sc
->tx_ring
[i
]);
4060 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
4062 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_BASE_PTR(i
),
4063 sc
->tx_ring
[i
].desc_phys_addr
);
4064 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_MAX_CNT(i
),
4065 RT2860_SOFTC_TX_RING_DESC_COUNT
);
4066 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_CTX_IDX(i
), 0);
4071 rt2860_reset_rx_ring(sc
, &sc
->rx_ring
);
4073 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_BASE_PTR
,
4074 sc
->rx_ring
.desc_phys_addr
);
4075 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_MAX_CNT
,
4076 RT2860_SOFTC_RX_RING_DATA_COUNT
);
4077 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_CALC_IDX
,
4078 RT2860_SOFTC_RX_RING_DATA_COUNT
- 1);
4080 rt2860_txrx_enable(sc
);
4084 * rt2860_rx_coherent_intr
4086 static void rt2860_rx_coherent_intr(struct rt2860_softc
*sc
)
4091 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4092 "%s: Rx coherent interrupt\n",
4093 device_get_nameunit(sc
->dev
));
4095 sc
->rx_coherent_interrupts
++;
4097 /* restart DMA engine */
4099 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
);
4101 tmp
&= ~(RT2860_REG_TX_WB_DDONE
|
4102 RT2860_REG_RX_DMA_ENABLE
|
4103 RT2860_REG_TX_DMA_ENABLE
);
4105 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
, tmp
);
4107 /* init Tx rings (4 EDCAs + HCCA + MGMT) */
4109 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
4110 rt2860_reset_tx_ring(sc
, &sc
->tx_ring
[i
]);
4112 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
4114 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_BASE_PTR(i
),
4115 sc
->tx_ring
[i
].desc_phys_addr
);
4116 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_MAX_CNT(i
),
4117 RT2860_SOFTC_TX_RING_DESC_COUNT
);
4118 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_CTX_IDX(i
), 0);
4123 rt2860_reset_rx_ring(sc
, &sc
->rx_ring
);
4125 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_BASE_PTR
,
4126 sc
->rx_ring
.desc_phys_addr
);
4127 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_MAX_CNT
,
4128 RT2860_SOFTC_RX_RING_DATA_COUNT
);
4129 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_CALC_IDX
,
4130 RT2860_SOFTC_RX_RING_DATA_COUNT
- 1);
4132 rt2860_txrx_enable(sc
);
4136 * rt2860_txrx_coherent_intr
4138 static void rt2860_txrx_coherent_intr(struct rt2860_softc
*sc
)
4143 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4144 "%s: Tx/Rx coherent interrupt\n",
4145 device_get_nameunit(sc
->dev
));
4147 sc
->txrx_coherent_interrupts
++;
4149 /* restart DMA engine */
4151 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
);
4153 tmp
&= ~(RT2860_REG_TX_WB_DDONE
|
4154 RT2860_REG_RX_DMA_ENABLE
|
4155 RT2860_REG_TX_DMA_ENABLE
);
4157 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
, tmp
);
4159 /* init Tx rings (4 EDCAs + HCCA + MGMT) */
4161 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
4162 rt2860_reset_tx_ring(sc
, &sc
->tx_ring
[i
]);
4164 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
4166 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_BASE_PTR(i
),
4167 sc
->tx_ring
[i
].desc_phys_addr
);
4168 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_MAX_CNT(i
),
4169 RT2860_SOFTC_TX_RING_DESC_COUNT
);
4170 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_CTX_IDX(i
), 0);
4175 rt2860_reset_rx_ring(sc
, &sc
->rx_ring
);
4177 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_BASE_PTR
,
4178 sc
->rx_ring
.desc_phys_addr
);
4179 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_MAX_CNT
,
4180 RT2860_SOFTC_RX_RING_DATA_COUNT
);
4181 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_CALC_IDX
,
4182 RT2860_SOFTC_RX_RING_DATA_COUNT
- 1);
4184 rt2860_txrx_enable(sc
);
4188 * rt2860_fifo_sta_full_intr
4190 static void rt2860_fifo_sta_full_intr(struct rt2860_softc
*sc
)
4192 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4193 "%s: FIFO statistic full interrupt\n",
4194 device_get_nameunit(sc
->dev
));
4196 sc
->fifo_sta_full_interrupts
++;
4198 RT2860_SOFTC_LOCK(sc
);
4200 if (!(sc
->intr_disable_mask
& RT2860_REG_INT_FIFO_STA_FULL
))
4202 rt2860_intr_disable(sc
, RT2860_REG_INT_FIFO_STA_FULL
);
4204 taskqueue_enqueue(sc
->taskqueue
, &sc
->fifo_sta_full_task
);
4207 sc
->intr_pending_mask
|= RT2860_REG_INT_FIFO_STA_FULL
;
4209 RT2860_SOFTC_UNLOCK(sc
);
4215 static void rt2860_rx_intr(struct rt2860_softc
*sc
)
4217 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4218 "%s: Rx interrupt\n",
4219 device_get_nameunit(sc
->dev
));
4221 sc
->rx_interrupts
++;
4223 RT2860_SOFTC_LOCK(sc
);
4225 if (!(sc
->intr_disable_mask
& RT2860_REG_INT_RX_DONE
))
4227 rt2860_intr_disable(sc
, RT2860_REG_INT_RX_DONE
);
4229 taskqueue_enqueue(sc
->taskqueue
, &sc
->rx_done_task
);
4232 sc
->intr_pending_mask
|= RT2860_REG_INT_RX_DONE
;
4234 RT2860_SOFTC_UNLOCK(sc
);
4238 * rt2860_rx_delay_intr
4240 static void rt2860_rx_delay_intr(struct rt2860_softc
*sc
)
4242 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4243 "%s: Rx delay interrupt\n",
4244 device_get_nameunit(sc
->dev
));
4246 sc
->rx_delay_interrupts
++;
4252 static void rt2860_tx_intr(struct rt2860_softc
*sc
, int qid
)
4254 KASSERT(qid
>= 0 && qid
< RT2860_SOFTC_TX_RING_COUNT
,
4255 ("%s: Tx interrupt: invalid qid=%d\n",
4256 device_get_nameunit(sc
->dev
), qid
));
4258 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4259 "%s: Tx interrupt: qid=%d\n",
4260 device_get_nameunit(sc
->dev
), qid
);
4262 sc
->tx_interrupts
[qid
]++;
4264 RT2860_SOFTC_LOCK(sc
);
4266 if (!(sc
->intr_disable_mask
& (RT2860_REG_INT_TX_AC0_DONE
<< qid
)))
4268 rt2860_intr_disable(sc
, (RT2860_REG_INT_TX_AC0_DONE
<< qid
));
4270 taskqueue_enqueue(sc
->taskqueue
, &sc
->tx_done_task
);
4273 sc
->intr_pending_mask
|= (RT2860_REG_INT_TX_AC0_DONE
<< qid
);
4275 RT2860_SOFTC_UNLOCK(sc
);
4279 * rt2860_tx_delay_intr
4281 static void rt2860_tx_delay_intr(struct rt2860_softc
*sc
)
4283 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4284 "%s: Tx delay interrupt\n",
4285 device_get_nameunit(sc
->dev
));
4287 sc
->tx_delay_interrupts
++;
4291 * rt2860_pre_tbtt_intr
4293 static void rt2860_pre_tbtt_intr(struct rt2860_softc
*sc
)
4295 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4296 "%s: Pre-TBTT interrupt\n",
4297 device_get_nameunit(sc
->dev
));
4299 sc
->pre_tbtt_interrupts
++;
4305 static void rt2860_tbtt_intr(struct rt2860_softc
*sc
)
4307 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4308 "%s: TBTT interrupt\n",
4309 device_get_nameunit(sc
->dev
));
4311 sc
->tbtt_interrupts
++;
4315 * rt2860_mcu_cmd_intr
4317 static void rt2860_mcu_cmd_intr(struct rt2860_softc
*sc
)
4319 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4320 "%s: MCU command interrupt\n",
4321 device_get_nameunit(sc
->dev
));
4323 sc
->mcu_cmd_interrupts
++;
4327 * rt2860_auto_wakeup_intr
4329 static void rt2860_auto_wakeup_intr(struct rt2860_softc
*sc
)
4331 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4332 "%s: auto wakeup interrupt\n",
4333 device_get_nameunit(sc
->dev
));
4335 sc
->auto_wakeup_interrupts
++;
4339 * rt2860_gp_timer_intr
4341 static void rt2860_gp_timer_intr(struct rt2860_softc
*sc
)
4343 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4344 "%s: GP timer interrupt\n",
4345 device_get_nameunit(sc
->dev
));
4347 sc
->gp_timer_interrupts
++;
4351 * rt2860_rx_done_task
4353 static void rt2860_rx_done_task(void *context
, int pending
)
4355 struct rt2860_softc
*sc
;
4362 RT2860_DPRINTF(sc
, RT2860_DEBUG_RX
,
4363 "%s: Rx done task\n",
4364 device_get_nameunit(sc
->dev
));
4366 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
4369 sc
->intr_pending_mask
&= ~RT2860_REG_INT_RX_DONE
;
4371 again
= rt2860_rx_eof(sc
, sc
->rx_process_limit
);
4373 RT2860_SOFTC_LOCK(sc
);
4375 if ((sc
->intr_pending_mask
& RT2860_REG_INT_RX_DONE
) || again
)
4377 RT2860_DPRINTF(sc
, RT2860_DEBUG_RX
,
4378 "%s: Rx done task: scheduling again\n",
4379 device_get_nameunit(sc
->dev
));
4381 taskqueue_enqueue(sc
->taskqueue
, &sc
->rx_done_task
);
4385 rt2860_intr_enable(sc
, RT2860_REG_INT_RX_DONE
);
4388 RT2860_SOFTC_UNLOCK(sc
);
4392 * rt2860_tx_done_task
4394 static void rt2860_tx_done_task(void *context
, int pending
)
4396 struct rt2860_softc
*sc
;
4404 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
4405 "%s: Tx done task\n",
4406 device_get_nameunit(sc
->dev
));
4408 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
4411 for (i
= RT2860_SOFTC_TX_RING_COUNT
- 1; i
>= 0; i
--)
4413 if (sc
->intr_pending_mask
& (RT2860_REG_INT_TX_AC0_DONE
<< i
))
4415 sc
->intr_pending_mask
&= ~(RT2860_REG_INT_TX_AC0_DONE
<< i
);
4417 rt2860_tx_eof(sc
, &sc
->tx_ring
[i
]);
4423 ifp
->if_drv_flags
&= ~IFF_DRV_OACTIVE
;
4425 intr_mask
= (RT2860_REG_INT_TX_MGMT_DONE
|
4426 RT2860_REG_INT_TX_HCCA_DONE
|
4427 RT2860_REG_INT_TX_AC3_DONE
|
4428 RT2860_REG_INT_TX_AC2_DONE
|
4429 RT2860_REG_INT_TX_AC1_DONE
|
4430 RT2860_REG_INT_TX_AC0_DONE
);
4432 RT2860_SOFTC_LOCK(sc
);
4434 rt2860_intr_enable(sc
, ~sc
->intr_pending_mask
&
4435 (sc
->intr_disable_mask
& intr_mask
));
4437 if (sc
->intr_pending_mask
& intr_mask
)
4439 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
4440 "%s: Tx done task: scheduling again\n",
4441 device_get_nameunit(sc
->dev
));
4443 taskqueue_enqueue(sc
->taskqueue
, &sc
->tx_done_task
);
4446 RT2860_SOFTC_UNLOCK(sc
);
4450 * rt2860_fifo_sta_full_task
4452 static void rt2860_fifo_sta_full_task(void *context
, int pending
)
4454 struct rt2860_softc
*sc
;
4460 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATS
,
4461 "%s: FIFO statistic full task\n",
4462 device_get_nameunit(sc
->dev
));
4464 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
4467 sc
->intr_pending_mask
&= ~RT2860_REG_INT_FIFO_STA_FULL
;
4469 rt2860_drain_fifo_stats(sc
);
4471 RT2860_SOFTC_LOCK(sc
);
4473 if (sc
->intr_pending_mask
& RT2860_REG_INT_FIFO_STA_FULL
)
4475 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATS
,
4476 "%s: FIFO statistic full task: scheduling again\n",
4477 device_get_nameunit(sc
->dev
));
4479 taskqueue_enqueue(sc
->taskqueue
, &sc
->fifo_sta_full_task
);
4483 rt2860_intr_enable(sc
, RT2860_REG_INT_FIFO_STA_FULL
);
4486 RT2860_SOFTC_UNLOCK(sc
);
4490 * rt2860_periodic_task
4492 static void rt2860_periodic_task(void *context
, int pending
)
4494 struct rt2860_softc
*sc
;
4496 struct ieee80211com
*ic
;
4502 RT2860_DPRINTF(sc
, RT2860_DEBUG_PERIODIC
,
4503 "%s: periodic task: round=%lu\n",
4504 device_get_nameunit(sc
->dev
), sc
->periodic_round
);
4506 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
4509 RT2860_SOFTC_LOCK(sc
);
4511 sc
->periodic_round
++;
4513 rt2860_update_stats(sc
);
4515 if ((sc
->periodic_round
% 10) == 0)
4517 rt2860_bbp_tuning(sc
);
4519 rt2860_update_raw_counters(sc
);
4521 rt2860_watchdog(sc
);
4523 if (ic
->ic_opmode
!= IEEE80211_M_MONITOR
&& ic
->ic_state
== IEEE80211_S_RUN
)
4525 if (ic
->ic_opmode
== IEEE80211_M_STA
)
4526 rt2860_amrr_update_iter_func(sc
, ic
->ic_bss
);
4528 ieee80211_iterate_nodes(&ic
->ic_sta
, rt2860_amrr_update_iter_func
, sc
);
4532 RT2860_SOFTC_UNLOCK(sc
);
4534 callout_reset(&sc
->periodic_ch
, hz
/ 10, rt2860_periodic
, sc
);
4540 static int rt2860_rx_eof(struct rt2860_softc
*sc
, int limit
)
4542 struct ieee80211com
*ic
;
4544 struct ieee80211_frame
*wh
;
4545 struct ieee80211_node
*ni
;
4546 struct rt2860_softc_node
*rni
;
4547 struct rt2860_softc_rx_radiotap_header
*tap
;
4548 struct rt2860_softc_rx_ring
*ring
;
4549 struct rt2860_rxdesc
*desc
;
4550 struct rt2860_softc_rx_data
*data
;
4551 struct rt2860_rxwi
*rxwi
;
4552 struct mbuf
*m
, *mnew
;
4553 bus_dma_segment_t segs
[1];
4554 bus_dmamap_t dma_map
;
4555 uint32_t index
, desc_flags
;
4556 uint8_t cipher_err
, rssi
, ant
, phymode
, bw
, shortgi
, mcs
, keyidx
;
4558 int error
, nsegs
, len
, ampdu
, amsdu
, nframes
, i
;
4562 ring
= &sc
->rx_ring
;
4568 index
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_RX_DRX_IDX
);
4569 if (ring
->cur
== index
)
4572 desc
= &ring
->desc
[ring
->cur
];
4573 desc_flags
= le32toh(desc
->flags
);
4574 data
= &ring
->data
[ring
->cur
];
4576 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
4577 BUS_DMASYNC_POSTREAD
);
4579 if (!(desc
->sdl0
& htole16(RT2860_RXDESC_SDL0_DDONE
)))
4584 mnew
= m_getjcl(M_DONTWAIT
, MT_DATA
, M_PKTHDR
, MJUMPAGESIZE
);
4587 sc
->rx_mbuf_alloc_errors
++;
4592 mnew
->m_len
= mnew
->m_pkthdr
.len
= MJUMPAGESIZE
;
4594 error
= bus_dmamap_load_mbuf_sg(ring
->data_dma_tag
, ring
->spare_dma_map
,
4595 mnew
, segs
, &nsegs
, BUS_DMA_NOWAIT
);
4600 sc
->rx_mbuf_dmamap_errors
++;
4606 KASSERT(nsegs
== 1, ("%s: too many DMA segments",
4607 device_get_name(sc
->dev
)));
4609 bus_dmamap_sync(ring
->data_dma_tag
, data
->dma_map
,
4610 BUS_DMASYNC_POSTREAD
);
4611 bus_dmamap_unload(ring
->data_dma_tag
, data
->dma_map
);
4613 dma_map
= data
->dma_map
;
4614 data
->dma_map
= ring
->spare_dma_map
;
4615 ring
->spare_dma_map
= dma_map
;
4617 bus_dmamap_sync(ring
->data_dma_tag
, data
->dma_map
,
4618 BUS_DMASYNC_PREREAD
);
4623 desc
->sdp0
= htole32(segs
[0].ds_addr
);
4625 /* get Rx wireless info */
4627 rxwi
= mtod(m
, struct rt2860_rxwi
*);
4628 len
= (le16toh(rxwi
->tid_size
) >> RT2860_RXWI_SIZE_SHIFT
) &
4629 RT2860_RXWI_SIZE_MASK
;
4631 /* check for L2 padding between IEEE 802.11 frame header and body */
4633 if (desc_flags
& RT2860_RXDESC_FLAGS_L2PAD
)
4635 RT2860_DPRINTF(sc
, RT2860_DEBUG_RX
,
4636 "%s: L2 padding: len=%d\n",
4637 device_get_nameunit(sc
->dev
), len
);
4642 m
->m_pkthdr
.rcvif
= ifp
;
4643 m
->m_data
= (caddr_t
) (rxwi
+ 1);
4644 m
->m_pkthdr
.len
= m
->m_len
= len
;
4646 /* check for crc errors */
4648 if (desc_flags
& RT2860_RXDESC_FLAGS_CRC_ERR
)
4650 RT2860_DPRINTF(sc
, RT2860_DEBUG_RX
,
4651 "%s: rxdesc: crc error\n",
4652 device_get_nameunit(sc
->dev
));
4656 if (!(ifp
->if_flags
& IFF_PROMISC
))
4663 wh
= (struct ieee80211_frame
*) (rxwi
+ 1);
4665 /* check for cipher errors */
4667 if (desc_flags
& RT2860_RXDESC_FLAGS_DECRYPTED
)
4669 cipher_err
= ((desc_flags
>> RT2860_RXDESC_FLAGS_CIPHER_ERR_SHIFT
) &
4670 RT2860_RXDESC_FLAGS_CIPHER_ERR_MASK
);
4671 if (cipher_err
== RT2860_RXDESC_FLAGS_CIPHER_ERR_NONE
)
4673 if (wh
->i_fc
[1] & IEEE80211_FC1_WEP
)
4674 wh
->i_fc
[1] &= ~IEEE80211_FC1_WEP
;
4676 m
->m_flags
|= M_WEP
;
4680 RT2860_DPRINTF(sc
, RT2860_DEBUG_RX
,
4681 "%s: rxdesc: cipher error=0x%02x\n",
4682 device_get_nameunit(sc
->dev
), cipher_err
);
4684 if ((cipher_err
== RT2860_RXDESC_FLAGS_CIPHER_ERR_MIC
) &&
4685 (desc_flags
& RT2860_RXDESC_FLAGS_MYBSS
))
4687 keyidx
= (rxwi
->udf_bssidx_keyidx
>> RT2860_RXWI_KEYIDX_SHIFT
) &
4688 RT2860_RXWI_KEYIDX_MASK
;
4690 ieee80211_notify_michael_failure(ic
, wh
, keyidx
);
4695 if (!(ifp
->if_flags
& IFF_PROMISC
))
4704 if (wh
->i_fc
[1] & IEEE80211_FC1_WEP
)
4706 RT2860_DPRINTF(sc
, RT2860_DEBUG_RX
,
4707 "%s: rxdesc: not decrypted but protected flag set\n",
4708 device_get_nameunit(sc
->dev
));
4712 if (!(ifp
->if_flags
& IFF_PROMISC
))
4720 /* check for A-MPDU */
4722 if (desc_flags
& RT2860_RXDESC_FLAGS_AMPDU
)
4724 m
->m_flags
|= M_AMPDU
;
4735 /* check for A-MSDU */
4737 if (desc_flags
& RT2860_RXDESC_FLAGS_AMSDU
)
4748 ant
= rt2860_maxrssi_rxpath(sc
, rxwi
);
4749 rssi
= rxwi
->rssi
[ant
];
4750 rssi_dbm
= rt2860_rssi2dbm(sc
, rssi
, ant
);
4751 phymode
= ((rxwi
->phymode_stbc_shortgi
>> RT2860_RXWI_PHYMODE_SHIFT
) &
4752 RT2860_RXWI_PHYMODE_MASK
);
4753 bw
= ((rxwi
->bw_mcs
>> RT2860_RXWI_BW_SHIFT
) & RT2860_RXWI_BW_MASK
);
4754 shortgi
= ((rxwi
->phymode_stbc_shortgi
>> RT2860_RXWI_SHORTGI_SHIFT
) &
4755 RT2860_RXWI_SHORTGI_MASK
);
4756 mcs
= ((rxwi
->bw_mcs
>> RT2860_RXWI_MCS_SHIFT
) & RT2860_RXWI_MCS_MASK
);
4758 if (bpf_peers_present(sc
->drvbpf
))
4762 tap
->flags
= IEEE80211_RADIOTAP_F_DATAPAD
;
4763 tap
->dbm_antsignal
= rssi_dbm
;
4764 tap
->dbm_antnoise
= RT2860_NOISE_FLOOR
;
4766 tap
->antsignal
= rssi
;
4767 tap
->chan_flags
= htole32(ic
->ic_curchan
->ic_flags
);
4768 tap
->chan_freq
= htole16(ic
->ic_curchan
->ic_freq
);
4769 tap
->chan_ieee
= ic
->ic_curchan
->ic_ieee
;
4770 tap
->chan_maxpow
= 0;
4772 if (phymode
== RT2860_TXWI_PHYMODE_HT_MIXED
|| phymode
== RT2860_TXWI_PHYMODE_HT_GF
)
4773 tap
->rate
= mcs
| IEEE80211_RATE_MCS
;
4775 tap
->rate
= rt2860_rxrate(rxwi
);
4777 if (desc_flags
& RT2860_RXDESC_FLAGS_CRC_ERR
)
4778 tap
->flags
|= IEEE80211_RADIOTAP_F_BADFCS
;
4780 if (desc_flags
& RT2860_RXDESC_FLAGS_FRAG
)
4781 tap
->flags
|= IEEE80211_RADIOTAP_F_FRAG
;
4783 if (rxwi
->bw_mcs
& RT2860_RXWI_MCS_SHOTPRE
)
4784 tap
->flags
|= IEEE80211_RADIOTAP_F_SHORTPRE
;
4787 tap
->flags
|= IEEE80211_RADIOTAP_F_SHORTGI
;
4789 bpf_mtap2(sc
->drvbpf
, tap
, sc
->rxtap_len
, m
);
4792 RT2860_DPRINTF(sc
, RT2860_DEBUG_RX
,
4793 "%s: received frame: len=%d, phymode=%d, bw=%d, shortgi=%d, mcs=%d, "
4794 "ant=%d, rssi=%d/%d/%d, snr=%d/%d, wcid=0x%02x, ampdu=%d, amsdu=%d\n",
4795 device_get_nameunit(sc
->dev
),
4796 len
, phymode
, bw
, shortgi
, mcs
,
4797 ant
, rxwi
->rssi
[0], rxwi
->rssi
[1], rxwi
->rssi
[2],
4798 rxwi
->snr
[0], rxwi
->snr
[1],
4799 rxwi
->wcid
, ampdu
, amsdu
);
4801 ni
= ieee80211_find_rxnode(ic
, (struct ieee80211_frame_min
*) wh
);
4805 rni
= (struct rt2860_softc_node
*) ni
;
4807 for (i
= 0; i
< RT2860_SOFTC_RSSI_DBM_COUNT
; i
++)
4808 rni
->last_rssi_dbm
[i
] = rt2860_rssi2dbm(sc
, rxwi
->rssi
[i
], i
);
4811 ieee80211_input(ic
, m
, ni
, rssi_dbm
, RT2860_NOISE_FLOOR
, 0);
4813 ieee80211_free_node(ni
);
4817 desc
->sdl0
&= ~htole16(RT2860_RXDESC_SDL0_DDONE
);
4819 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
4820 BUS_DMASYNC_PREREAD
| BUS_DMASYNC_PREWRITE
);
4822 ring
->cur
= (ring
->cur
+ 1) % RT2860_SOFTC_RX_RING_DATA_COUNT
;
4828 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_CALC_IDX
,
4829 RT2860_SOFTC_RX_RING_DATA_COUNT
- 1);
4831 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_CALC_IDX
,
4834 RT2860_DPRINTF(sc
, RT2860_DEBUG_RX
,
4835 "%s: Rx eof: nframes=%d\n",
4836 device_get_nameunit(sc
->dev
), nframes
);
4838 sc
->rx_packets
+= nframes
;
4840 return (limit
== 0);
4846 static void rt2860_tx_eof(struct rt2860_softc
*sc
,
4847 struct rt2860_softc_tx_ring
*ring
)
4850 struct rt2860_txdesc
*desc
;
4851 struct rt2860_softc_tx_data
*data
;
4853 int ndescs
, nframes
;
4862 index
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_TX_DTX_IDX(ring
->qid
));
4863 if (ring
->desc_next
== index
)
4868 rt2860_drain_fifo_stats(sc
);
4870 desc
= &ring
->desc
[ring
->desc_next
];
4872 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
4873 BUS_DMASYNC_POSTREAD
);
4875 if (desc
->sdl0
& htole16(RT2860_TXDESC_SDL0_LASTSEG
) ||
4876 desc
->sdl1
& htole16(RT2860_TXDESC_SDL1_LASTSEG
))
4880 data
= &ring
->data
[ring
->data_next
];
4882 if (data
->m
->m_flags
& M_TXCB
)
4883 ieee80211_process_callback(data
->ni
, data
->m
, 0);
4885 bus_dmamap_sync(ring
->data_dma_tag
, data
->dma_map
,
4886 BUS_DMASYNC_POSTWRITE
);
4887 bus_dmamap_unload(ring
->data_dma_tag
, data
->dma_map
);
4891 ieee80211_free_node(data
->ni
);
4898 RT2860_SOFTC_LOCK(sc
);
4900 ring
->data_queued
--;
4901 ring
->data_next
= (ring
->data_next
+ 1) % RT2860_SOFTC_TX_RING_DATA_COUNT
;
4903 RT2860_SOFTC_UNLOCK(sc
);
4906 desc
->sdl0
&= ~htole16(RT2860_TXDESC_SDL0_DDONE
);
4908 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
4909 BUS_DMASYNC_PREREAD
| BUS_DMASYNC_PREWRITE
);
4911 RT2860_SOFTC_LOCK(sc
);
4913 ring
->desc_queued
--;
4914 ring
->desc_next
= (ring
->desc_next
+ 1) % RT2860_SOFTC_TX_RING_DESC_COUNT
;
4916 RT2860_SOFTC_UNLOCK(sc
);
4919 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
4920 "%s: Tx eof: qid=%d, ndescs=%d, nframes=%d\n",
4921 device_get_nameunit(sc
->dev
), ring
->qid
, ndescs
, nframes
);
4925 * rt2860_update_stats
4927 static void rt2860_update_stats(struct rt2860_softc
*sc
)
4930 struct ieee80211com
*ic
;
4931 struct ieee80211_node
*ni
;
4933 int beacons
, noretryok
, retryok
, failed
, underflows
, zerolen
;
4940 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATS
,
4941 "%s: update statistic\n",
4942 device_get_nameunit(sc
->dev
));
4944 rt2860_drain_fifo_stats(sc
);
4946 /* read and clear Tx statistic registers */
4948 rt2860_io_mac_read_multi(sc
, RT2860_REG_TX_STA_CNT0
,
4949 stacnt
, sizeof(stacnt
));
4951 stacnt
[0] = le32toh(stacnt
[0]);
4952 stacnt
[1] = le32toh(stacnt
[1]);
4953 stacnt
[2] = le32toh(stacnt
[2]);
4955 beacons
= stacnt
[0] >> 16;
4956 noretryok
= stacnt
[1] & 0xffff;
4957 retryok
= stacnt
[1] >> 16;
4958 failed
= stacnt
[0] & 0xffff;
4959 underflows
= stacnt
[2] >> 16;
4960 zerolen
= stacnt
[2] & 0xffff;
4962 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATS
,
4963 "%s: update statistic: beacons=%d, noretryok=%d, retryok=%d, failed=%d, underflows=%d, zerolen=%d\n",
4964 device_get_nameunit(sc
->dev
),
4965 beacons
, noretryok
, retryok
, failed
, underflows
, zerolen
);
4967 ifp
->if_oerrors
+= failed
;
4969 sc
->tx_beacons
+= beacons
;
4970 sc
->tx_noretryok
+= noretryok
;
4971 sc
->tx_retryok
+= retryok
;
4972 sc
->tx_failed
+= failed
;
4973 sc
->tx_underflows
+= underflows
;
4974 sc
->tx_zerolen
+= zerolen
;
4976 if (ic
->ic_opmode
== IEEE80211_M_STA
&& ic
->ic_state
== IEEE80211_S_RUN
)
4980 associd
= (ni
!= NULL
) ? ni
->ni_associd
: 0;
4981 wcid
= RT2860_AID2WCID(associd
);
4983 rt2860_amrr_tx_update(&sc
->amrr_node
[wcid
],
4984 noretryok
+ retryok
+ failed
, noretryok
+ retryok
, retryok
+ failed
);
4991 static void rt2860_bbp_tuning(struct rt2860_softc
*sc
)
4993 struct ieee80211com
*ic
;
4994 struct ieee80211_node
*ni
;
4996 int8_t rssi
, old
, new;
4998 /* RT2860C does not support BBP tuning */
5000 if (sc
->mac_rev
== 0x28600100)
5005 if ((ic
->ic_flags
& IEEE80211_F_SCAN
) ||
5006 ic
->ic_opmode
!= IEEE80211_M_STA
|| ic
->ic_state
!= IEEE80211_S_RUN
)
5011 chan
= ieee80211_chan2ieee(ic
, ni
->ni_chan
);
5015 else if (chan
<= 64)
5017 else if (chan
<= 128)
5022 rssi
= ieee80211_getrssi(ic
);
5024 if (IEEE80211_IS_CHAN_2GHZ(ni
->ni_chan
))
5026 new = 0x2e + sc
->lna_gain
[group
];
5030 if (!IEEE80211_IS_CHAN_HT40(ni
->ni_chan
))
5031 new = 0x32 + sc
->lna_gain
[group
] * 5 / 3;
5033 new = 0x3a + sc
->lna_gain
[group
] * 5 / 3;
5036 /* Tune if absolute average RSSI is greater than -80 */
5041 old
= rt2860_io_bbp_read(sc
, 66);
5044 rt2860_io_bbp_write(sc
, 66, new);
5050 static void rt2860_watchdog(struct rt2860_softc
*sc
)
5055 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_PBF_TXRXQ_PCNT
);
5057 RT2860_DPRINTF(sc
, RT2860_DEBUG_WATCHDOG
,
5058 "%s: watchdog: TXRXQ_PCNT=0x%08x\n",
5059 device_get_nameunit(sc
->dev
), tmp
);
5061 if (((tmp
>> RT2860_REG_TX0Q_PCNT_SHIFT
) & RT2860_REG_TX0Q_PCNT_MASK
) != 0)
5063 sc
->tx_queue_not_empty
[0]++;
5065 rt2860_io_mac_write(sc
, RT2860_REG_PBF_CFG
, 0xf40012);
5067 for (ntries
= 0; ntries
< 10; ntries
++)
5069 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_PBF_TXRXQ_PCNT
);
5070 if (((tmp
>> RT2860_REG_TX0Q_PCNT_SHIFT
) & RT2860_REG_TX0Q_PCNT_MASK
) == 0)
5076 rt2860_io_mac_write(sc
, RT2860_REG_PBF_CFG
, 0xf40006);
5079 if (((tmp
>> RT2860_REG_TX1Q_PCNT_SHIFT
) & RT2860_REG_TX1Q_PCNT_MASK
) != 0)
5081 sc
->tx_queue_not_empty
[1]++;
5083 rt2860_io_mac_write(sc
, RT2860_REG_PBF_CFG
, 0xf4000a);
5085 for (ntries
= 0; ntries
< 10; ntries
++)
5087 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_PBF_TXRXQ_PCNT
);
5088 if (((tmp
>> RT2860_REG_TX1Q_PCNT_SHIFT
) & RT2860_REG_TX1Q_PCNT_MASK
) == 0)
5094 rt2860_io_mac_write(sc
, RT2860_REG_PBF_CFG
, 0xf40006);
5099 * rt2860_drain_fifo_stats
5101 static void rt2860_drain_fifo_stats(struct rt2860_softc
*sc
)
5105 uint8_t wcid
, mcs
, pid
;
5106 int ok
, agg
, retrycnt
;
5108 ifp
= sc
->ic
.ic_ifp
;
5110 /* drain Tx status FIFO (maxsize = 16) */
5112 while ((stats
= rt2860_io_mac_read(sc
, RT2860_REG_TX_STA_FIFO
)) &
5113 RT2860_REG_TX_STA_FIFO_VALID
)
5115 wcid
= (stats
>> RT2860_REG_TX_STA_FIFO_WCID_SHIFT
) &
5116 RT2860_REG_TX_STA_FIFO_WCID_MASK
;
5118 /* if no ACK was requested, no feedback is available */
5120 if (!(stats
& RT2860_REG_TX_STA_FIFO_ACK_REQ
) || wcid
== 0xff)
5123 /* update AMRR statistic */
5125 ok
= (stats
& RT2860_REG_TX_STA_FIFO_TX_OK
) ? 1 : 0;
5126 agg
= (stats
& RT2860_REG_TX_STA_FIFO_AGG
) ? 1 : 0;
5127 mcs
= (stats
>> RT2860_REG_TX_STA_FIFO_MCS_SHIFT
) &
5128 RT2860_REG_TX_STA_FIFO_MCS_MASK
;
5129 pid
= (stats
>> RT2860_REG_TX_STA_FIFO_PID_SHIFT
) &
5130 RT2860_REG_TX_STA_FIFO_PID_MASK
;
5131 retrycnt
= pid
- mcs
;
5133 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATS
,
5134 "%s: FIFO statistic: wcid=0x%02x, ok=%d, agg=%d, mcs=0x%02x, pid=0x%02x, retrycnt=%d\n",
5135 device_get_nameunit(sc
->dev
),
5136 wcid
, ok
, agg
, mcs
, pid
, retrycnt
);
5138 rt2860_amrr_tx_complete(&sc
->amrr_node
[wcid
], ok
, retrycnt
);
5146 * rt2860_update_raw_counters
5148 static void rt2860_update_raw_counters(struct rt2860_softc
*sc
)
5152 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_AGG_CNT
);
5154 sc
->tx_nonagg
+= tmp
& 0xffff;
5155 sc
->tx_agg
+= tmp
>> 16;
5157 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_AGG_CNT0
);
5159 sc
->tx_ampdu
+= (tmp
& 0xffff) / 1 + (tmp
>> 16) / 2;
5161 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_AGG_CNT1
);
5163 sc
->tx_ampdu
+= (tmp
& 0xffff) / 3 + (tmp
>> 16) / 4;
5165 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_AGG_CNT2
);
5167 sc
->tx_ampdu
+= (tmp
& 0xffff) / 5 + (tmp
>> 16) / 6;
5169 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_AGG_CNT3
);
5171 sc
->tx_ampdu
+= (tmp
& 0xffff) / 7 + (tmp
>> 16) / 8;
5173 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_AGG_CNT4
);
5175 sc
->tx_ampdu
+= (tmp
& 0xffff) / 9 + (tmp
>> 16) / 10;
5177 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_AGG_CNT5
);
5179 sc
->tx_ampdu
+= (tmp
& 0xffff) / 11 + (tmp
>> 16) / 12;
5181 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_AGG_CNT6
);
5183 sc
->tx_ampdu
+= (tmp
& 0xffff) / 13 + (tmp
>> 16) / 14;
5185 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_AGG_CNT7
);
5187 sc
->tx_ampdu
+= (tmp
& 0xffff) / 15 + (tmp
>> 16) / 16;
5189 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_RX_STA_CNT0
);
5191 sc
->rx_crc_errors
+= tmp
& 0xffff;
5192 sc
->rx_phy_errors
+= tmp
>> 16;
5194 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_RX_STA_CNT1
);
5196 sc
->rx_false_ccas
+= tmp
& 0xffff;
5197 sc
->rx_plcp_errors
+= tmp
>> 16;
5199 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_RX_STA_CNT2
);
5201 sc
->rx_dup_packets
+= tmp
& 0xffff;
5202 sc
->rx_fifo_overflows
+= tmp
>> 16;
5204 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TXRX_MPDU_DEN_CNT
);
5206 sc
->tx_mpdu_zero_density
+= tmp
& 0xffff;
5207 sc
->rx_mpdu_zero_density
+= tmp
>> 16;
5211 * rt2860_intr_enable
5213 static void rt2860_intr_enable(struct rt2860_softc
*sc
, uint32_t intr_mask
)
5217 sc
->intr_disable_mask
&= ~intr_mask
;
5219 tmp
= sc
->intr_enable_mask
& ~sc
->intr_disable_mask
;
5221 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_INT_MASK
, tmp
);
5225 * rt2860_intr_disable
5227 static void rt2860_intr_disable(struct rt2860_softc
*sc
, uint32_t intr_mask
)
5231 sc
->intr_disable_mask
|= intr_mask
;
5233 tmp
= sc
->intr_enable_mask
& ~sc
->intr_disable_mask
;
5235 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_INT_MASK
, tmp
);
5239 * rt2860_txrx_enable
5241 static int rt2860_txrx_enable(struct rt2860_softc
*sc
)
5243 struct ieee80211com
*ic
;
5251 /* enable Tx/Rx DMA engine */
5253 rt2860_io_mac_write(sc
, RT2860_REG_SYS_CTRL
, RT2860_REG_TX_ENABLE
);
5255 for (ntries
= 0; ntries
< 200; ntries
++)
5257 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
);
5258 if (!(tmp
& (RT2860_REG_TX_DMA_BUSY
| RT2860_REG_RX_DMA_BUSY
)))
5266 printf("%s: timeout waiting for DMA engine\n",
5267 device_get_nameunit(sc
->dev
));
5273 tmp
|= RT2860_REG_TX_WB_DDONE
|
5274 RT2860_REG_RX_DMA_ENABLE
|
5275 RT2860_REG_TX_DMA_ENABLE
|
5276 (RT2860_REG_WPDMA_BT_SIZE64
<< RT2860_REG_WPDMA_BT_SIZE_SHIFT
);
5278 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
, tmp
);
5282 tmp
= RT2860_REG_RX_FILTER_DROP_CRC_ERR
|
5283 RT2860_REG_RX_FILTER_DROP_PHY_ERR
;
5285 if (ic
->ic_opmode
!= IEEE80211_M_MONITOR
)
5287 tmp
|= RT2860_REG_RX_FILTER_DROP_DUPL
|
5288 RT2860_REG_RX_FILTER_DROP_CTS
|
5289 RT2860_REG_RX_FILTER_DROP_BA
|
5290 RT2860_REG_RX_FILTER_DROP_ACK
|
5291 RT2860_REG_RX_FILTER_DROP_VER_ERR
|
5292 RT2860_REG_RX_FILTER_DROP_CTRL_RSV
|
5293 RT2860_REG_RX_FILTER_DROP_CFACK
|
5294 RT2860_REG_RX_FILTER_DROP_CFEND
;
5296 if (ic
->ic_opmode
== IEEE80211_M_STA
)
5297 tmp
|= RT2860_REG_RX_FILTER_DROP_RTS
|
5298 RT2860_REG_RX_FILTER_DROP_PSPOLL
;
5300 if (!(ifp
->if_flags
& IFF_PROMISC
))
5301 tmp
|= RT2860_REG_RX_FILTER_DROP_UC_NOME
;
5304 rt2860_io_mac_write(sc
, RT2860_REG_RX_FILTER_CFG
, tmp
);
5306 rt2860_io_mac_write(sc
, RT2860_REG_SYS_CTRL
,
5307 RT2860_REG_RX_ENABLE
| RT2860_REG_TX_ENABLE
);
5313 * rt2860_alloc_rx_ring
5315 static int rt2860_alloc_rx_ring(struct rt2860_softc
*sc
,
5316 struct rt2860_softc_rx_ring
*ring
)
5318 struct rt2860_rxdesc
*desc
;
5319 struct rt2860_softc_rx_data
*data
;
5320 bus_dma_segment_t segs
[1];
5321 int i
, nsegs
, error
;
5323 error
= bus_dma_tag_create(bus_get_dma_tag(sc
->dev
), PAGE_SIZE
, 0,
5324 BUS_SPACE_MAXADDR_32BIT
, BUS_SPACE_MAXADDR
, NULL
, NULL
,
5325 RT2860_SOFTC_RX_RING_DATA_COUNT
* sizeof(struct rt2860_rxdesc
), 1,
5326 RT2860_SOFTC_RX_RING_DATA_COUNT
* sizeof(struct rt2860_rxdesc
),
5327 0, NULL
, NULL
, &ring
->desc_dma_tag
);
5330 printf("%s: could not create Rx desc DMA tag\n",
5331 device_get_nameunit(sc
->dev
));
5335 error
= bus_dmamem_alloc(ring
->desc_dma_tag
, (void **) &ring
->desc
,
5336 BUS_DMA_NOWAIT
| BUS_DMA_ZERO
, &ring
->desc_dma_map
);
5339 printf("%s: could not allocate Rx desc DMA memory\n",
5340 device_get_nameunit(sc
->dev
));
5344 error
= bus_dmamap_load(ring
->desc_dma_tag
, ring
->desc_dma_map
,
5346 RT2860_SOFTC_RX_RING_DATA_COUNT
* sizeof(struct rt2860_rxdesc
),
5347 rt2860_dma_map_addr
, &ring
->desc_phys_addr
, 0);
5350 printf("%s: could not load Rx desc DMA map\n",
5351 device_get_nameunit(sc
->dev
));
5355 error
= bus_dma_tag_create(bus_get_dma_tag(sc
->dev
), PAGE_SIZE
, 0,
5356 BUS_SPACE_MAXADDR_32BIT
, BUS_SPACE_MAXADDR
, NULL
, NULL
,
5357 MJUMPAGESIZE
, 1, MJUMPAGESIZE
, 0, NULL
, NULL
,
5358 &ring
->data_dma_tag
);
5361 printf("%s: could not create Rx data DMA tag\n",
5362 device_get_nameunit(sc
->dev
));
5366 for (i
= 0; i
< RT2860_SOFTC_RX_RING_DATA_COUNT
; i
++)
5368 desc
= &ring
->desc
[i
];
5369 data
= &ring
->data
[i
];
5371 error
= bus_dmamap_create(ring
->data_dma_tag
, 0, &data
->dma_map
);
5374 printf("%s: could not create Rx data DMA map\n",
5375 device_get_nameunit(sc
->dev
));
5379 data
->m
= m_getjcl(M_DONTWAIT
, MT_DATA
, M_PKTHDR
, MJUMPAGESIZE
);
5380 if (data
->m
== NULL
)
5382 printf("%s: could not allocate Rx mbuf\n",
5383 device_get_nameunit(sc
->dev
));
5388 data
->m
->m_len
= data
->m
->m_pkthdr
.len
= MJUMPAGESIZE
;
5390 error
= bus_dmamap_load_mbuf_sg(ring
->data_dma_tag
, data
->dma_map
,
5391 data
->m
, segs
, &nsegs
, BUS_DMA_NOWAIT
);
5394 printf("%s: could not load Rx mbuf DMA map\n",
5395 device_get_nameunit(sc
->dev
));
5399 KASSERT(nsegs
== 1, ("%s: too many DMA segments",
5400 device_get_name(sc
->dev
)));
5402 desc
->sdp0
= htole32(segs
[0].ds_addr
);
5403 desc
->sdl0
= htole16(MJUMPAGESIZE
);
5406 error
= bus_dmamap_create(ring
->data_dma_tag
, 0, &ring
->spare_dma_map
);
5409 printf("%s: could not create Rx spare DMA map\n",
5410 device_get_nameunit(sc
->dev
));
5414 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
5415 BUS_DMASYNC_PREWRITE
);
5421 rt2860_free_rx_ring(sc
, ring
);
5427 * rt2860_reset_rx_ring
5429 static void rt2860_reset_rx_ring(struct rt2860_softc
*sc
,
5430 struct rt2860_softc_rx_ring
*ring
)
5432 struct rt2860_rxdesc
*desc
;
5435 for (i
= 0; i
< RT2860_SOFTC_RX_RING_DATA_COUNT
; i
++)
5437 desc
= &ring
->desc
[i
];
5439 desc
->sdl0
&= ~htole16(RT2860_RXDESC_SDL0_DDONE
);
5442 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
5443 BUS_DMASYNC_PREWRITE
);
5449 * rt2860_free_rx_ring
5451 static void rt2860_free_rx_ring(struct rt2860_softc
*sc
,
5452 struct rt2860_softc_rx_ring
*ring
)
5454 struct rt2860_softc_rx_data
*data
;
5457 if (ring
->desc
!= NULL
)
5459 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
5460 BUS_DMASYNC_POSTWRITE
);
5461 bus_dmamap_unload(ring
->desc_dma_tag
, ring
->desc_dma_map
);
5462 bus_dmamem_free(ring
->desc_dma_tag
, ring
->desc
,
5463 ring
->desc_dma_map
);
5466 if (ring
->desc_dma_tag
!= NULL
)
5467 bus_dma_tag_destroy(ring
->desc_dma_tag
);
5469 for (i
= 0; i
< RT2860_SOFTC_RX_RING_DATA_COUNT
; i
++)
5471 data
= &ring
->data
[i
];
5473 if (data
->m
!= NULL
)
5475 bus_dmamap_sync(ring
->data_dma_tag
, data
->dma_map
,
5476 BUS_DMASYNC_POSTREAD
);
5477 bus_dmamap_unload(ring
->data_dma_tag
, data
->dma_map
);
5481 if (data
->dma_map
!= NULL
)
5482 bus_dmamap_destroy(ring
->data_dma_tag
, data
->dma_map
);
5485 if (ring
->spare_dma_map
!= NULL
)
5486 bus_dmamap_destroy(ring
->data_dma_tag
, ring
->spare_dma_map
);
5488 if (ring
->data_dma_tag
!= NULL
)
5489 bus_dma_tag_destroy(ring
->data_dma_tag
);
5493 * rt2860_alloc_tx_ring
5495 static int rt2860_alloc_tx_ring(struct rt2860_softc
*sc
,
5496 struct rt2860_softc_tx_ring
*ring
, int qid
)
5498 struct rt2860_softc_tx_data
*data
;
5501 error
= bus_dma_tag_create(bus_get_dma_tag(sc
->dev
), PAGE_SIZE
, 0,
5502 BUS_SPACE_MAXADDR_32BIT
, BUS_SPACE_MAXADDR
, NULL
, NULL
,
5503 RT2860_SOFTC_TX_RING_DESC_COUNT
* sizeof(struct rt2860_txdesc
), 1,
5504 RT2860_SOFTC_TX_RING_DESC_COUNT
* sizeof(struct rt2860_txdesc
),
5505 0, NULL
, NULL
, &ring
->desc_dma_tag
);
5508 printf("%s: could not create Tx desc DMA tag\n",
5509 device_get_nameunit(sc
->dev
));
5513 error
= bus_dmamem_alloc(ring
->desc_dma_tag
, (void **) &ring
->desc
,
5514 BUS_DMA_NOWAIT
| BUS_DMA_ZERO
, &ring
->desc_dma_map
);
5517 printf("%s: could not allocate Tx desc DMA memory\n",
5518 device_get_nameunit(sc
->dev
));
5522 error
= bus_dmamap_load(ring
->desc_dma_tag
, ring
->desc_dma_map
,
5524 RT2860_SOFTC_TX_RING_DESC_COUNT
* sizeof(struct rt2860_txdesc
),
5525 rt2860_dma_map_addr
, &ring
->desc_phys_addr
, 0);
5528 printf("%s: could not load Tx desc DMA map\n",
5529 device_get_nameunit(sc
->dev
));
5533 ring
->desc_queued
= 0;
5535 ring
->desc_next
= 0;
5537 error
= bus_dma_tag_create(bus_get_dma_tag(sc
->dev
), PAGE_SIZE
, 0,
5538 BUS_SPACE_MAXADDR_32BIT
, BUS_SPACE_MAXADDR
, NULL
, NULL
,
5539 RT2860_SOFTC_TX_RING_DATA_COUNT
* RT2860_TX_DATA_SEG0_SIZE
, 1,
5540 RT2860_SOFTC_TX_RING_DATA_COUNT
* RT2860_TX_DATA_SEG0_SIZE
,
5541 0, NULL
, NULL
, &ring
->seg0_dma_tag
);
5544 printf("%s: could not create Tx seg0 DMA tag\n",
5545 device_get_nameunit(sc
->dev
));
5549 error
= bus_dmamem_alloc(ring
->seg0_dma_tag
, (void **) &ring
->seg0
,
5550 BUS_DMA_NOWAIT
| BUS_DMA_ZERO
, &ring
->seg0_dma_map
);
5553 printf("%s: could not allocate Tx seg0 DMA memory\n",
5554 device_get_nameunit(sc
->dev
));
5558 error
= bus_dmamap_load(ring
->seg0_dma_tag
, ring
->seg0_dma_map
,
5560 RT2860_SOFTC_TX_RING_DATA_COUNT
* RT2860_TX_DATA_SEG0_SIZE
,
5561 rt2860_dma_map_addr
, &ring
->seg0_phys_addr
, 0);
5564 printf("%s: could not load Tx seg0 DMA map\n",
5565 device_get_nameunit(sc
->dev
));
5569 error
= bus_dma_tag_create(bus_get_dma_tag(sc
->dev
), PAGE_SIZE
, 0,
5570 BUS_SPACE_MAXADDR_32BIT
, BUS_SPACE_MAXADDR
, NULL
, NULL
,
5571 MJUMPAGESIZE
, RT2860_SOFTC_MAX_SCATTER
, MJUMPAGESIZE
, 0, NULL
, NULL
,
5572 &ring
->data_dma_tag
);
5575 printf("%s: could not create Tx data DMA tag\n",
5576 device_get_nameunit(sc
->dev
));
5580 for (i
= 0; i
< RT2860_SOFTC_TX_RING_DATA_COUNT
; i
++)
5582 data
= &ring
->data
[i
];
5584 error
= bus_dmamap_create(ring
->data_dma_tag
, 0, &data
->dma_map
);
5587 printf("%s: could not create Tx data DMA map\n",
5588 device_get_nameunit(sc
->dev
));
5593 ring
->data_queued
= 0;
5595 ring
->data_next
= 0;
5603 rt2860_free_tx_ring(sc
, ring
);
5609 * rt2860_reset_tx_ring
5611 static void rt2860_reset_tx_ring(struct rt2860_softc
*sc
,
5612 struct rt2860_softc_tx_ring
*ring
)
5614 struct rt2860_softc_tx_data
*data
;
5615 struct rt2860_txdesc
*desc
;
5618 for (i
= 0; i
< RT2860_SOFTC_TX_RING_DESC_COUNT
; i
++)
5620 desc
= &ring
->desc
[i
];
5626 ring
->desc_queued
= 0;
5628 ring
->desc_next
= 0;
5630 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
5631 BUS_DMASYNC_PREWRITE
);
5633 bus_dmamap_sync(ring
->seg0_dma_tag
, ring
->seg0_dma_map
,
5634 BUS_DMASYNC_PREWRITE
);
5636 for (i
= 0; i
< RT2860_SOFTC_TX_RING_DATA_COUNT
; i
++)
5638 data
= &ring
->data
[i
];
5640 if (data
->m
!= NULL
)
5642 bus_dmamap_sync(ring
->data_dma_tag
, data
->dma_map
,
5643 BUS_DMASYNC_POSTWRITE
);
5644 bus_dmamap_unload(ring
->data_dma_tag
, data
->dma_map
);
5649 if (data
->ni
!= NULL
)
5651 ieee80211_free_node(data
->ni
);
5656 ring
->data_queued
= 0;
5658 ring
->data_next
= 0;
5662 * rt2860_free_tx_ring
5664 static void rt2860_free_tx_ring(struct rt2860_softc
*sc
,
5665 struct rt2860_softc_tx_ring
*ring
)
5667 struct rt2860_softc_tx_data
*data
;
5670 if (ring
->desc
!= NULL
)
5672 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
5673 BUS_DMASYNC_POSTWRITE
);
5674 bus_dmamap_unload(ring
->desc_dma_tag
, ring
->desc_dma_map
);
5675 bus_dmamem_free(ring
->desc_dma_tag
, ring
->desc
,
5676 ring
->desc_dma_map
);
5679 if (ring
->desc_dma_tag
!= NULL
)
5680 bus_dma_tag_destroy(ring
->desc_dma_tag
);
5682 if (ring
->seg0
!= NULL
)
5684 bus_dmamap_sync(ring
->seg0_dma_tag
, ring
->seg0_dma_map
,
5685 BUS_DMASYNC_POSTWRITE
);
5686 bus_dmamap_unload(ring
->seg0_dma_tag
, ring
->seg0_dma_map
);
5687 bus_dmamem_free(ring
->seg0_dma_tag
, ring
->seg0
,
5688 ring
->seg0_dma_map
);
5691 if (ring
->seg0_dma_tag
!= NULL
)
5692 bus_dma_tag_destroy(ring
->seg0_dma_tag
);
5694 for (i
= 0; i
< RT2860_SOFTC_TX_RING_DATA_COUNT
; i
++)
5696 data
= &ring
->data
[i
];
5698 if (data
->m
!= NULL
)
5700 bus_dmamap_sync(ring
->data_dma_tag
, data
->dma_map
,
5701 BUS_DMASYNC_POSTWRITE
);
5702 bus_dmamap_unload(ring
->data_dma_tag
, data
->dma_map
);
5706 if (data
->ni
!= NULL
)
5707 ieee80211_free_node(data
->ni
);
5709 if (data
->dma_map
!= NULL
)
5710 bus_dmamap_destroy(ring
->data_dma_tag
, data
->dma_map
);
5713 if (ring
->data_dma_tag
!= NULL
)
5714 bus_dma_tag_destroy(ring
->data_dma_tag
);
5718 * rt2860_dma_map_addr
5720 static void rt2860_dma_map_addr(void *arg
, bus_dma_segment_t
*segs
,
5721 int nseg
, int error
)
5726 KASSERT(nseg
== 1, ("too many DMA segments, %d should be 1", nseg
));
5728 *(bus_addr_t
*) arg
= segs
[0].ds_addr
;
5732 * rt2860_sysctl_attach
5734 static void rt2860_sysctl_attach(struct rt2860_softc
*sc
)
5736 struct sysctl_ctx_list
*ctx
;
5737 struct sysctl_oid
*tree
;
5738 struct sysctl_oid
*stats
;
5740 ctx
= device_get_sysctl_ctx(sc
->dev
);
5741 tree
= device_get_sysctl_tree(sc
->dev
);
5743 stats
= SYSCTL_ADD_NODE(ctx
, SYSCTL_CHILDREN(tree
), OID_AUTO
,
5744 "stats", CTLFLAG_RD
, 0, "statistic");
5746 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5747 "interrupts", CTLFLAG_RD
, &sc
->interrupts
, 0,
5750 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5751 "tx_coherent_interrupts", CTLFLAG_RD
, &sc
->tx_coherent_interrupts
, 0,
5752 "Tx coherent interrupts");
5754 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5755 "rx_coherent_interrupts", CTLFLAG_RD
, &sc
->rx_coherent_interrupts
, 0,
5756 "Rx coherent interrupts");
5758 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5759 "txrx_coherent_interrupts", CTLFLAG_RD
, &sc
->txrx_coherent_interrupts
, 0,
5760 "Tx/Rx coherent interrupts");
5762 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5763 "fifo_sta_full_interrupts", CTLFLAG_RD
, &sc
->fifo_sta_full_interrupts
, 0,
5764 "FIFO statistic full interrupts");
5766 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5767 "rx_interrupts", CTLFLAG_RD
, &sc
->rx_interrupts
, 0,
5770 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5771 "rx_delay_interrupts", CTLFLAG_RD
, &sc
->rx_delay_interrupts
, 0,
5772 "Rx delay interrupts");
5774 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5775 "tx_mgmt_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[5], 0,
5776 "Tx MGMT interrupts");
5778 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5779 "tx_hcca_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[4], 0,
5780 "Tx HCCA interrupts");
5782 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5783 "tx_ac3_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[3], 0,
5784 "Tx AC3 interrupts");
5786 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5787 "tx_ac2_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[2], 0,
5788 "Tx AC2 interrupts");
5790 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5791 "tx_ac1_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[1], 0,
5792 "Tx AC1 interrupts");
5794 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5795 "tx_ac0_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[0], 0,
5796 "Tx AC0 interrupts");
5798 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5799 "tx_delay_interrupts", CTLFLAG_RD
, &sc
->tx_delay_interrupts
, 0,
5800 "Tx delay interrupts");
5802 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5803 "pre_tbtt_interrupts", CTLFLAG_RD
, &sc
->pre_tbtt_interrupts
, 0,
5804 "Pre-TBTT interrupts");
5806 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5807 "tbtt_interrupts", CTLFLAG_RD
, &sc
->tbtt_interrupts
, 0,
5810 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5811 "mcu_cmd_interrupts", CTLFLAG_RD
, &sc
->mcu_cmd_interrupts
, 0,
5812 "MCU command interrupts");
5814 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5815 "auto_wakeup_interrupts", CTLFLAG_RD
, &sc
->auto_wakeup_interrupts
, 0,
5816 "auto wakeup interrupts");
5818 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5819 "gp_timer_interrupts", CTLFLAG_RD
, &sc
->gp_timer_interrupts
, 0,
5820 "GP timer interrupts");
5822 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5823 "tx_mgmt_desc_queued", CTLFLAG_RD
, &sc
->tx_ring
[5].desc_queued
, 0,
5824 "Tx MGMT descriptors queued");
5826 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5827 "tx_mgmt_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[5].data_queued
, 0,
5828 "Tx MGMT data queued");
5830 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5831 "tx_hcca_desc_queued", CTLFLAG_RD
, &sc
->tx_ring
[4].desc_queued
, 0,
5832 "Tx HCCA descriptors queued");
5834 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5835 "tx_hcca_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[4].data_queued
, 0,
5836 "Tx HCCA data queued");
5838 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5839 "tx_ac3_desc_queued", CTLFLAG_RD
, &sc
->tx_ring
[3].desc_queued
, 0,
5840 "Tx AC3 descriptors queued");
5842 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5843 "tx_ac3_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[3].data_queued
, 0,
5844 "Tx AC3 data queued");
5846 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5847 "tx_ac2_desc_queued", CTLFLAG_RD
, &sc
->tx_ring
[2].desc_queued
, 0,
5848 "Tx AC2 descriptors queued");
5850 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5851 "tx_ac2_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[2].data_queued
, 0,
5852 "Tx AC2 data queued");
5854 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5855 "tx_ac1_desc_queued", CTLFLAG_RD
, &sc
->tx_ring
[1].desc_queued
, 0,
5856 "Tx AC1 descriptors queued");
5858 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5859 "tx_ac1_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[1].data_queued
, 0,
5860 "Tx AC1 data queued");
5862 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5863 "tx_ac0_desc_queued", CTLFLAG_RD
, &sc
->tx_ring
[0].desc_queued
, 0,
5864 "Tx AC0 descriptors queued");
5866 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5867 "tx_ac0_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[0].data_queued
, 0,
5868 "Tx AC0 data queued");
5870 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5871 "tx_mgmt_data_queue_full", CTLFLAG_RD
, &sc
->tx_data_queue_full
[5], 0,
5872 "Tx MGMT data queue full");
5874 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5875 "tx_hcca_data_queue_full", CTLFLAG_RD
, &sc
->tx_data_queue_full
[4], 0,
5876 "Tx HCCA data queue full");
5878 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5879 "tx_ac3_data_queue_full", CTLFLAG_RD
, &sc
->tx_data_queue_full
[3], 0,
5880 "Tx AC3 data queue full");
5882 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5883 "tx_ac2_data_queue_full", CTLFLAG_RD
, &sc
->tx_data_queue_full
[2], 0,
5884 "Tx AC2 data queue full");
5886 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5887 "tx_ac1_data_queue_full", CTLFLAG_RD
, &sc
->tx_data_queue_full
[1], 0,
5888 "Tx AC1 data queue full");
5890 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5891 "tx_ac0_data_queue_full", CTLFLAG_RD
, &sc
->tx_data_queue_full
[0], 0,
5892 "Tx AC0 data queue full");
5894 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5895 "tx_watchdog_timeouts", CTLFLAG_RD
, &sc
->tx_watchdog_timeouts
, 0,
5896 "Tx watchdog timeouts");
5898 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5899 "tx_defrag_packets", CTLFLAG_RD
, &sc
->tx_defrag_packets
, 0,
5900 "Tx defragmented packets");
5902 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5903 "no_tx_desc_avail", CTLFLAG_RD
, &sc
->no_tx_desc_avail
, 0,
5904 "no Tx descriptors available");
5906 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5907 "rx_mbuf_alloc_errors", CTLFLAG_RD
, &sc
->rx_mbuf_alloc_errors
, 0,
5908 "Rx mbuf allocation errors");
5910 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5911 "rx_mbuf_dmamap_errors", CTLFLAG_RD
, &sc
->rx_mbuf_dmamap_errors
, 0,
5912 "Rx mbuf DMA mapping errors");
5914 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5915 "tx_queue_0_not_empty", CTLFLAG_RD
, &sc
->tx_queue_not_empty
[0], 0,
5916 "Tx queue 0 not empty");
5918 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5919 "tx_queue_1_not_empty", CTLFLAG_RD
, &sc
->tx_queue_not_empty
[1], 0,
5920 "Tx queue 1 not empty");
5922 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5923 "tx_beacons", CTLFLAG_RD
, &sc
->tx_beacons
, 0,
5926 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5927 "tx_noretryok", CTLFLAG_RD
, &sc
->tx_noretryok
, 0,
5928 "Tx successfull without retries");
5930 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5931 "tx_retryok", CTLFLAG_RD
, &sc
->tx_retryok
, 0,
5932 "Tx successfull with retries");
5934 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5935 "tx_failed", CTLFLAG_RD
, &sc
->tx_failed
, 0,
5938 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5939 "tx_underflows", CTLFLAG_RD
, &sc
->tx_underflows
, 0,
5942 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5943 "tx_zerolen", CTLFLAG_RD
, &sc
->tx_zerolen
, 0,
5946 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5947 "tx_nonagg", CTLFLAG_RD
, &sc
->tx_nonagg
, 0,
5948 "Tx non-aggregated");
5950 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5951 "tx_agg", CTLFLAG_RD
, &sc
->tx_agg
, 0,
5954 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5955 "tx_ampdu", CTLFLAG_RD
, &sc
->tx_ampdu
, 0,
5958 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5959 "tx_mpdu_zero_density", CTLFLAG_RD
, &sc
->tx_mpdu_zero_density
, 0,
5960 "Tx MPDU with zero density");
5962 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5963 "rx_packets", CTLFLAG_RD
, &sc
->rx_packets
, 0,
5966 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5967 "rx_ampdu", CTLFLAG_RD
, &sc
->rx_ampdu
, 0,
5970 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5971 "rx_mpdu_zero_density", CTLFLAG_RD
, &sc
->rx_mpdu_zero_density
, 0,
5972 "Rx MPDU with zero density");
5974 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5975 "rx_amsdu", CTLFLAG_RD
, &sc
->rx_amsdu
, 0,
5978 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5979 "rx_crc_errors", CTLFLAG_RD
, &sc
->rx_crc_errors
, 0,
5982 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5983 "rx_phy_errors", CTLFLAG_RD
, &sc
->rx_phy_errors
, 0,
5986 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5987 "rx_false_ccas", CTLFLAG_RD
, &sc
->rx_false_ccas
, 0,
5990 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5991 "rx_plcp_errors", CTLFLAG_RD
, &sc
->rx_plcp_errors
, 0,
5994 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5995 "rx_dup_packets", CTLFLAG_RD
, &sc
->rx_dup_packets
, 0,
5996 "Rx duplicate packets");
5998 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5999 "rx_fifo_overflows", CTLFLAG_RD
, &sc
->rx_fifo_overflows
, 0,
6000 "Rx FIFO overflows");
6003 static device_method_t rt2860_dev_methods
[] =
6005 DEVMETHOD(device_probe
, rt2860_probe
),
6006 DEVMETHOD(device_attach
, rt2860_attach
),
6007 DEVMETHOD(device_detach
, rt2860_detach
),
6008 DEVMETHOD(device_shutdown
, rt2860_shutdown
),
6009 DEVMETHOD(device_suspend
, rt2860_suspend
),
6010 DEVMETHOD(device_resume
, rt2860_resume
),
6014 static driver_t rt2860_driver
=
6018 sizeof(struct rt2860_softc
)
6021 static devclass_t rt2860_dev_class
;
6023 DRIVER_MODULE(rt2860
, pci
, rt2860_driver
, rt2860_dev_class
, 0, 0);
6025 MODULE_DEPEND(rt2860
, pci
, 1, 1, 1);
6026 MODULE_DEPEND(rt2860
, wlan
, 1, 1, 1);