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_RATE_IS_OFDM(rate) ((rate) >= 12 && (rate) != 22)
50 #define RT2860_ACK_SIZE 14
52 #define IEEE80211_HAS_ADDR4(wh) \
53 (((wh)->i_fc[1] & IEEE80211_FC1_DIR_MASK) == IEEE80211_FC1_DIR_DSTODS)
55 #define RT2860_MS(_v, _f) (((_v) & _f) >> _f##_S)
56 #define RT2860_SM(_v, _f) (((_v) << _f##_S) & _f)
58 #define RT2860_TX_WATCHDOG_TIMEOUT 5
60 #define RT2860_WCID_RESERVED 0xff
61 #define RT2860_WCID_MCAST 0xf7
64 * Data structures and types
67 struct rt2860_pci_ident
75 * Static function prototypes
78 static int rt2860_probe(device_t dev
);
80 static int rt2860_attach(device_t dev
);
82 static int rt2860_detach(device_t dev
);
84 static int rt2860_shutdown(device_t dev
);
86 static int rt2860_suspend(device_t dev
);
88 static int rt2860_resume(device_t dev
);
90 static void rt2860_init_channels(struct rt2860_softc
*sc
);
92 static void rt2860_init_channels_ht40(struct rt2860_softc
*sc
);
94 static void rt2860_init_locked(void *priv
);
96 static void rt2860_init(void *priv
);
98 static int rt2860_init_bbp(struct rt2860_softc
*sc
);
100 static void rt2860_stop_locked(void *priv
);
102 static void rt2860_stop(void *priv
);
104 static void rt2860_start(struct ifnet
*ifp
);
106 static int rt2860_ioctl(struct ifnet
*ifp
, u_long cmd
, caddr_t data
);
108 static int rt2860_reset(struct ifnet
*ifp
);
110 static int rt2860_newstate(struct ieee80211com
*ic
,
111 enum ieee80211_state nstate
, int arg
);
113 static void rt2860_scan_start(struct ieee80211com
*ic
);
115 static void rt2860_scan_end(struct ieee80211com
*ic
);
117 static void rt2860_set_channel(struct ieee80211com
*ic
);
119 static void rt2860_newassoc(struct ieee80211_node
*ni
, int isnew
);
121 static void rt2860_updateslot(struct ifnet
*ifp
);
123 static int rt2860_wme_update(struct ieee80211com
*ic
);
125 static void rt2860_update_beacon(struct ieee80211com
*ic
, int what
);
127 static void rt2860_key_update_begin(struct ieee80211com
*ic
);
129 static void rt2860_key_update_end(struct ieee80211com
*ic
);
131 static int rt2860_key_set(struct ieee80211com
*ic
,
132 const struct ieee80211_key
*k
, const uint8_t mac
[IEEE80211_ADDR_LEN
]);
134 static int rt2860_key_delete(struct ieee80211com
*ic
,
135 const struct ieee80211_key
*k
);
137 static int rt2860_raw_xmit(struct ieee80211_node
*ni
, struct mbuf
*m
,
138 const struct ieee80211_bpf_params
*params
);
140 static int rt2860_media_change(struct ifnet
*ifp
);
142 static struct ieee80211_node
*rt2860_node_alloc(struct ieee80211_node_table
*nt
);
144 static void rt2860_node_cleanup(struct ieee80211_node
*ni
);
146 static void rt2860_recv_action(struct ieee80211_node
*ni
,
147 const uint8_t *frm
, const uint8_t *efrm
);
149 static int rt2860_send_action(struct ieee80211_node
*ni
,
150 int category
, int action
, uint16_t args
[4]);
152 static int rt2860_addba_response(struct ieee80211_node
*ni
,
153 struct ieee80211_tx_ampdu
*tap
,
154 int status
, int baparamset
, int batimeout
);
156 static void rt2860_addba_stop(struct ieee80211_node
*ni
,
157 struct ieee80211_tx_ampdu
*tap
);
159 static int rt2860_send_bar(struct ieee80211_node
*ni
,
160 struct ieee80211_tx_ampdu
*tap
, ieee80211_seq seqno
);
162 static void rt2860_amrr_update_iter_func(void *arg
, struct ieee80211_node
*ni
);
164 static void rt2860_periodic(void *arg
);
166 static void rt2860_tx_watchdog(void *arg
);
168 static int rt2860_staid_alloc(struct rt2860_softc
*sc
, int aid
);
170 static void rt2860_staid_delete(struct rt2860_softc
*sc
, int staid
);
172 static void rt2860_asic_set_bssid(struct rt2860_softc
*sc
,
173 const uint8_t *bssid
);
175 static void rt2860_asic_set_macaddr(struct rt2860_softc
*sc
,
176 const uint8_t *addr
);
178 static void rt2860_asic_enable_tsf_sync(struct rt2860_softc
*sc
);
180 static void rt2860_asic_disable_tsf_sync(struct rt2860_softc
*sc
);
182 static void rt2860_asic_enable_mrr(struct rt2860_softc
*sc
);
184 static void rt2860_asic_set_txpreamble(struct rt2860_softc
*sc
);
186 static void rt2860_asic_set_basicrates(struct rt2860_softc
*sc
);
188 static void rt2860_asic_update_rtsthreshold(struct rt2860_softc
*sc
);
190 static void rt2860_asic_update_txpower(struct rt2860_softc
*sc
);
192 static void rt2860_asic_update_promisc(struct rt2860_softc
*sc
);
194 static void rt2860_asic_updateprot(struct rt2860_softc
*sc
);
196 static void rt2860_asic_updateslot(struct rt2860_softc
*sc
);
198 static void rt2860_asic_wme_update(struct rt2860_softc
*sc
);
200 static void rt2860_asic_update_beacon(struct rt2860_softc
*sc
);
202 static void rt2860_asic_clear_keytables(struct rt2860_softc
*sc
);
204 static void rt2860_asic_add_ba_session(struct rt2860_softc
*sc
,
205 uint8_t wcid
, int tid
);
207 static void rt2860_asic_del_ba_session(struct rt2860_softc
*sc
,
208 uint8_t wcid
, int tid
);
210 static int rt2860_beacon_alloc(struct rt2860_softc
*sc
);
212 static uint8_t rt2860_rxrate(struct rt2860_rxwi
*rxwi
);
214 static uint8_t rt2860_maxrssi_rxpath(struct rt2860_softc
*sc
,
215 const struct rt2860_rxwi
*rxwi
);
217 static int8_t rt2860_rssi2dbm(struct rt2860_softc
*sc
,
218 uint8_t rssi
, uint8_t rxpath
);
220 static uint8_t rt2860_rate2mcs(uint8_t rate
);
222 static int rt2860_ackrate(struct ieee80211com
*ic
, int rate
);
224 static uint16_t rt2860_txtime(int len
, int rate
, uint32_t flags
);
226 static int rt2860_tx_frame(struct rt2860_softc
*sc
,
227 struct mbuf
*m
, struct ieee80211_node
*ni
, int qid
);
229 static int rt2860_tx_raw(struct rt2860_softc
*sc
,
230 struct mbuf
*m
, struct ieee80211_node
*ni
,
231 const struct ieee80211_bpf_params
*params
);
233 static void rt2860_intr(void *arg
);
235 static void rt2860_tx_coherent_intr(struct rt2860_softc
*sc
);
237 static void rt2860_rx_coherent_intr(struct rt2860_softc
*sc
);
239 static void rt2860_txrx_coherent_intr(struct rt2860_softc
*sc
);
241 static void rt2860_fifo_sta_full_intr(struct rt2860_softc
*sc
);
243 static void rt2860_rx_intr(struct rt2860_softc
*sc
);
245 static void rt2860_rx_delay_intr(struct rt2860_softc
*sc
);
247 static void rt2860_tx_intr(struct rt2860_softc
*sc
, int qid
);
249 static void rt2860_tx_delay_intr(struct rt2860_softc
*sc
);
251 static void rt2860_pre_tbtt_intr(struct rt2860_softc
*sc
);
253 static void rt2860_tbtt_intr(struct rt2860_softc
*sc
);
255 static void rt2860_mcu_cmd_intr(struct rt2860_softc
*sc
);
257 static void rt2860_auto_wakeup_intr(struct rt2860_softc
*sc
);
259 static void rt2860_gp_timer_intr(struct rt2860_softc
*sc
);
261 static void rt2860_rx_done_task(void *context
, int pending
);
263 static void rt2860_tx_done_task(void *context
, int pending
);
265 static void rt2860_fifo_sta_full_task(void *context
, int pending
);
267 static void rt2860_periodic_task(void *context
, int pending
);
269 static int rt2860_rx_eof(struct rt2860_softc
*sc
, int limit
);
271 static void rt2860_tx_eof(struct rt2860_softc
*sc
,
272 struct rt2860_softc_tx_ring
*ring
);
274 static void rt2860_update_stats(struct rt2860_softc
*sc
);
276 static void rt2860_bbp_tuning(struct rt2860_softc
*sc
);
278 static void rt2860_watchdog(struct rt2860_softc
*sc
);
280 static void rt2860_drain_fifo_stats(struct rt2860_softc
*sc
);
282 static void rt2860_update_raw_counters(struct rt2860_softc
*sc
);
284 static void rt2860_intr_enable(struct rt2860_softc
*sc
, uint32_t intr_mask
);
286 static void rt2860_intr_disable(struct rt2860_softc
*sc
, uint32_t intr_mask
);
288 static int rt2860_txrx_enable(struct rt2860_softc
*sc
);
290 static int rt2860_alloc_rx_ring(struct rt2860_softc
*sc
,
291 struct rt2860_softc_rx_ring
*ring
);
293 static void rt2860_reset_rx_ring(struct rt2860_softc
*sc
,
294 struct rt2860_softc_rx_ring
*ring
);
296 static void rt2860_free_rx_ring(struct rt2860_softc
*sc
,
297 struct rt2860_softc_rx_ring
*ring
);
299 static int rt2860_alloc_tx_ring(struct rt2860_softc
*sc
,
300 struct rt2860_softc_tx_ring
*ring
, int qid
);
302 static void rt2860_reset_tx_ring(struct rt2860_softc
*sc
,
303 struct rt2860_softc_tx_ring
*ring
);
305 static void rt2860_free_tx_ring(struct rt2860_softc
*sc
,
306 struct rt2860_softc_tx_ring
*ring
);
308 static void rt2860_dma_map_addr(void *arg
, bus_dma_segment_t
*segs
,
309 int nseg
, int error
);
311 static void rt2860_sysctl_attach(struct rt2860_softc
*sc
);
317 static const struct rt2860_pci_ident rt2860_pci_ids
[] =
319 { PCI_VENDOR_RALINK
, PCI_PRODUCT_RALINK_RT2860_PCI
, "Ralink RT2860 PCI" },
320 { PCI_VENDOR_RALINK
, PCI_PRODUCT_RALINK_RT2860_PCIe
, "Ralink RT2860 PCIe" },
321 { PCI_VENDOR_RALINK
, PCI_PRODUCT_RALINK_RT2760_PCI
, "Ralink RT2760 PCI" },
322 { PCI_VENDOR_RALINK
, PCI_PRODUCT_RALINK_RT2790_PCIe
, "Ralink RT2790 PCIe" },
332 { RT2860_REG_PBF_BCN_OFFSET0
, 0xf8f0e8e0 },
333 { RT2860_REG_PBF_BCN_OFFSET1
, 0x6f77d0c8 },
334 { RT2860_REG_LEGACY_BASIC_RATE
, 0x0000013f },
335 { RT2860_REG_HT_BASIC_RATE
, 0x00008003 },
336 { RT2860_REG_SYS_CTRL
, 0x00000000 },
337 { RT2860_REG_RX_FILTER_CFG
, 0x00017f97 },
338 { RT2860_REG_BKOFF_SLOT_CFG
, 0x00000209 },
339 { RT2860_REG_TX_SW_CFG0
, 0x00000000 },
340 { RT2860_REG_TX_SW_CFG1
, 0x00080606 },
341 { RT2860_REG_TX_LINK_CFG
, 0x00001020 },
342 { RT2860_REG_TX_TIMEOUT_CFG
, 0x000a2090 },
343 { RT2860_REG_MAX_LEN_CFG
, (1 << 12) | RT2860_MAX_AGG_SIZE
},
344 { RT2860_REG_LED_CFG
, 0x7f031e46 },
345 { RT2860_REG_PBF_MAX_PCNT
, 0x1f3fbf9f },
346 { RT2860_REG_TX_RTY_CFG
, 0x47d01f0f },
347 { RT2860_REG_AUTO_RSP_CFG
, 0x00000013 },
348 { RT2860_REG_TX_CCK_PROT_CFG
, 0x05740003 },
349 { RT2860_REG_TX_OFDM_PROT_CFG
, 0x05740003 },
350 { RT2860_REG_TX_GF20_PROT_CFG
, 0x01744004 },
351 { RT2860_REG_TX_GF40_PROT_CFG
, 0x03f44084 },
352 { RT2860_REG_TX_MM20_PROT_CFG
, 0x01744004 },
353 { RT2860_REG_TX_MM40_PROT_CFG
, 0x03f54084 },
354 { RT2860_REG_TX_TXOP_CTRL_CFG
, 0x0000583f },
355 { RT2860_REG_TX_RTS_CFG
, 0x00092b20 },
356 { RT2860_REG_TX_EXP_ACK_TIME
, 0x002400ca },
357 { RT2860_REG_HCCAPSMP_TXOP_HLDR_ET
, 0x00000002 },
358 { RT2860_REG_XIFS_TIME_CFG
, 0x33a41010 },
359 { RT2860_REG_PWR_PIN_CFG
, 0x00000003 },
360 { RT2860_REG_SCHDMA_WMM_AIFSN_CFG
, 0x00002273 },
361 { RT2860_REG_SCHDMA_WMM_CWMIN_CFG
, 0x00002344 },
362 { RT2860_REG_SCHDMA_WMM_CWMAX_CFG
, 0x000034aa },
365 #define RT2860_DEF_MAC_SIZE (sizeof(rt2860_def_mac) / sizeof(rt2860_def_mac[0]))
390 #define RT2860_DEF_BBP_SIZE (sizeof(rt2860_def_bbp) / sizeof(rt2860_def_bbp[0]))
392 SYSCTL_NODE(_hw
, OID_AUTO
, rt2860
, CTLFLAG_RD
, 0, "RT2860 driver parameters");
394 static int rt2860_tx_stbc
= 1;
395 SYSCTL_INT(_hw_rt2860
, OID_AUTO
, tx_stbc
, CTLFLAG_RW
, &rt2860_tx_stbc
, 0, "RT2860 Tx STBC");
396 TUNABLE_INT("hw.rt2860.tx_stbc", &rt2860_tx_stbc
);
399 static int rt2860_debug
= 0;
400 SYSCTL_INT(_hw_rt2860
, OID_AUTO
, debug
, CTLFLAG_RW
, &rt2860_debug
, 0, "RT2860 debug level");
401 TUNABLE_INT("hw.rt2860.debug", &rt2860_debug
);
407 static int rt2860_probe(device_t dev
)
409 const struct rt2860_pci_ident
*ident
;
411 for (ident
= rt2860_pci_ids
; ident
->name
!= NULL
; ident
++)
413 if (pci_get_vendor(dev
) == ident
->vendor
&&
414 pci_get_device(dev
) == ident
->device
)
416 device_set_desc(dev
, ident
->name
);
427 static int rt2860_attach(device_t dev
)
429 struct rt2860_softc
*sc
;
431 struct ieee80211com
*ic
;
432 int error
, ntries
, i
;
434 sc
= device_get_softc(dev
);
436 if (pci_get_powerstate(dev
) != PCI_POWERSTATE_D0
)
438 printf("%s: chip is in D%d power mode, setting to D0\n",
439 device_get_nameunit(dev
), pci_get_powerstate(dev
));
440 pci_set_powerstate(dev
, PCI_POWERSTATE_D0
);
443 /* enable bus-mastering */
445 pci_enable_busmaster(dev
);
449 mtx_init(&sc
->lock
, device_get_nameunit(dev
),
450 MTX_NETWORK_LOCK
, MTX_DEF
| MTX_RECURSE
);
452 sc
->mem_rid
= PCIR_BAR(0);
453 sc
->mem
= bus_alloc_resource_any(dev
, SYS_RES_MEMORY
,
454 &sc
->mem_rid
, RF_ACTIVE
);
457 printf("%s: could not allocate memory resource\n",
458 device_get_nameunit(dev
));
463 sc
->bst
= rman_get_bustag(sc
->mem
);
464 sc
->bsh
= rman_get_bushandle(sc
->mem
);
467 sc
->irq
= bus_alloc_resource_any(dev
, SYS_RES_IRQ
,
468 &sc
->irq_rid
, RF_ACTIVE
| RF_SHAREABLE
);
471 printf("%s: could not allocate interrupt resource\n",
472 device_get_nameunit(dev
));
477 sc
->tx_stbc
= rt2860_tx_stbc
;
480 sc
->debug
= rt2860_debug
;
482 SYSCTL_ADD_INT(device_get_sysctl_ctx(dev
),
483 SYSCTL_CHILDREN(device_get_sysctl_tree(dev
)), OID_AUTO
,
484 "debug", CTLFLAG_RW
, &sc
->debug
, 0, "rt2860 debug level");
487 RT2860_DPRINTF(sc
, RT2860_DEBUG_ANY
,
489 device_get_nameunit(sc
->dev
));
491 /* wait for NIC to initialize */
493 for (ntries
= 0; ntries
< 100; ntries
++)
495 sc
->mac_rev
= rt2860_io_mac_read(sc
, RT2860_REG_MAC_CSR0
);
496 if (sc
->mac_rev
!= 0x00000000 && sc
->mac_rev
!= 0xffffffff)
504 printf("%s: timeout waiting for NIC to initialize\n",
505 device_get_nameunit(dev
));
510 rt2860_read_eeprom(sc
);
512 printf("%s: MAC/BBP RT2860 (rev 0x%08x), RF %s\n",
513 device_get_nameunit(sc
->dev
), sc
->mac_rev
,
514 rt2860_rf_name(sc
->rf_rev
));
516 /* clear key tables */
518 rt2860_asic_clear_keytables(sc
);
520 /* allocate Tx and Rx rings */
522 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
524 error
= rt2860_alloc_tx_ring(sc
, &sc
->tx_ring
[i
], i
);
527 printf("%s: could not allocate Tx ring #%d\n",
528 device_get_nameunit(sc
->dev
), i
);
533 sc
->tx_ring_mgtqid
= 5;
535 error
= rt2860_alloc_rx_ring(sc
, &sc
->rx_ring
);
538 printf("%s: could not allocate Rx ring\n",
539 device_get_nameunit(sc
->dev
));
543 callout_init(&sc
->periodic_ch
, 0);
544 callout_init_mtx(&sc
->tx_watchdog_ch
, &sc
->lock
, 0);
546 ifp
= sc
->ifp
= if_alloc(IFT_ETHER
);
549 printf("%s: could not if_alloc()\n",
550 device_get_nameunit(sc
->dev
));
557 if_initname(ifp
, "rt2860", device_get_unit(sc
->dev
));
559 ifp
->if_flags
= IFF_BROADCAST
| IFF_SIMPLEX
| IFF_MULTICAST
;
561 ifp
->if_init
= rt2860_init
;
562 ifp
->if_ioctl
= rt2860_ioctl
;
563 ifp
->if_start
= rt2860_start
;
565 IFQ_SET_MAXLEN(&ifp
->if_snd
, IFQ_MAXLEN
);
566 ifp
->if_snd
.ifq_drv_maxlen
= IFQ_MAXLEN
;
567 IFQ_SET_READY(&ifp
->if_snd
);
573 ic
->ic_phytype
= IEEE80211_T_HT
;
574 ic
->ic_opmode
= IEEE80211_M_STA
;
575 ic
->ic_state
= IEEE80211_S_INIT
;
577 ic
->ic_caps
= IEEE80211_C_MONITOR
|
584 IEEE80211_C_SHPREAMBLE
|
591 IEEE80211_C_AES_CCM
|
594 ic
->ic_htcaps
= IEEE80211_HTC_HT
|
595 IEEE80211_HTC_AMSDU
| /* A-MSDU Tx */
596 IEEE80211_HTC_AMPDU
| /* A-MPDU Tx */
597 IEEE80211_HTCAP_MAXAMSDU_3839
| /* max. A-MSDU Rx length */
598 IEEE80211_HTCAP_CHWIDTH40
| /* HT 40MHz channel width */
599 IEEE80211_HTCAP_GREENFIELD
| /* HT greenfield */
600 IEEE80211_HTCAP_SHORTGI20
| /* HT 20MHz short GI */
601 IEEE80211_HTCAP_SHORTGI40
| /* HT 40MHz short GI */
602 IEEE80211_HTCAP_SMPS_OFF
; /* MIMO power save disabled */
604 /* spatial streams */
606 if (sc
->nrxpath
== 2)
607 ic
->ic_htcaps
|= IEEE80211_HTCAP_RXSTBC_2STREAM
;
608 else if (sc
->nrxpath
== 3)
609 ic
->ic_htcaps
|= IEEE80211_HTCAP_RXSTBC_3STREAM
;
611 ic
->ic_htcaps
|= IEEE80211_HTCAP_RXSTBC_1STREAM
;
614 ic
->ic_htcaps
|= IEEE80211_HTCAP_TXSTBC
;
618 if (sc
->mac_rev
!= 0x28600100)
619 ic
->ic_htcaps
|= IEEE80211_HTCAP_DELBA
;
624 ic
->ic_regdomain
= 0;
625 ic
->ic_countrycode
= CTRY_DEFAULT
;
628 rt2860_init_channels(sc
);
630 rt2860_init_channels_ht40(sc
);
632 IEEE80211_ADDR_COPY(ic
->ic_myaddr
, sc
->mac_addr
);
634 ieee80211_ifattach(ic
);
636 sc
->newstate
= ic
->ic_newstate
;
637 ic
->ic_newstate
= rt2860_newstate
;
639 ic
->ic_reset
= rt2860_reset
;
640 ic
->ic_node_alloc
= rt2860_node_alloc
;
642 sc
->node_cleanup
= ic
->ic_node_cleanup
;
643 ic
->ic_node_cleanup
= rt2860_node_cleanup
;
645 ic
->ic_scan_start
= rt2860_scan_start
;
646 ic
->ic_scan_end
= rt2860_scan_end
;
647 ic
->ic_set_channel
= rt2860_set_channel
;
648 ic
->ic_newassoc
= rt2860_newassoc
;
649 ic
->ic_updateslot
= rt2860_updateslot
;
650 ic
->ic_wme
.wme_update
= rt2860_wme_update
;
651 ic
->ic_update_beacon
= rt2860_update_beacon
;
652 ic
->ic_crypto
.cs_key_update_begin
= rt2860_key_update_begin
;
653 ic
->ic_crypto
.cs_key_update_end
= rt2860_key_update_end
;
654 ic
->ic_crypto
.cs_key_set
= rt2860_key_set
;
655 ic
->ic_crypto
.cs_key_delete
= rt2860_key_delete
;
656 ic
->ic_raw_xmit
= rt2860_raw_xmit
;
658 sc
->recv_action
= ic
->ic_recv_action
;
659 ic
->ic_recv_action
= rt2860_recv_action
;
661 sc
->send_action
= ic
->ic_send_action
;
662 ic
->ic_send_action
= rt2860_send_action
;
664 sc
->addba_response
= ic
->ic_addba_response
;
665 ic
->ic_addba_response
= rt2860_addba_response
;
667 sc
->addba_stop
= ic
->ic_addba_stop
;
668 ic
->ic_addba_stop
= rt2860_addba_stop
;
670 /* override Rx A-MPDU factor */
672 ic
->ic_ampdu_rxmax
= IEEE80211_HTCAP_MAXRXAMPDU_32K
;
673 ic
->ic_ampdu_density
= IEEE80211_HTCAP_MPDUDENSITY_NA
;
674 ic
->ic_ampdu_limit
= ic
->ic_ampdu_rxmax
;
676 /* hardware requires padding between 802.11 frame header and body */
678 ic
->ic_flags
|= IEEE80211_F_WME
| IEEE80211_F_DATAPAD
| IEEE80211_F_DOTH
;
680 ic
->ic_flags_ext
|= IEEE80211_FEXT_SWBMISS
;
682 ic
->ic_max_aid
= RT2860_SOFTC_STAID_COUNT
;
684 ieee80211_media_init(ic
, rt2860_media_change
, ieee80211_media_status
);
686 rt2860_amrr_init(&sc
->amrr
, ic
,
688 RT2860_AMRR_MIN_SUCCESS_THRESHOLD
,
689 RT2860_AMRR_MAX_SUCCESS_THRESHOLD
,
692 bpfattach2(ifp
, DLT_IEEE802_11_RADIO
,
693 sizeof(struct ieee80211_frame
) + IEEE80211_RADIOTAP_HDRLEN
,
696 sc
->rxtap_len
= sizeof(sc
->rxtapu
);
697 sc
->rxtap
.ihdr
.it_len
= htole16(sc
->rxtap_len
);
698 sc
->rxtap
.ihdr
.it_present
= htole32(RT2860_SOFTC_RX_RADIOTAP_PRESENT
);
700 sc
->txtap_len
= sizeof(sc
->txtapu
);
701 sc
->txtap
.ihdr
.it_len
= htole16(sc
->txtap_len
);
702 sc
->txtap
.ihdr
.it_present
= htole32(RT2860_SOFTC_TX_RADIOTAP_PRESENT
);
704 /* init task queue */
706 TASK_INIT(&sc
->rx_done_task
, 0, rt2860_rx_done_task
, sc
);
707 TASK_INIT(&sc
->tx_done_task
, 0, rt2860_tx_done_task
, sc
);
708 TASK_INIT(&sc
->fifo_sta_full_task
, 0, rt2860_fifo_sta_full_task
, sc
);
709 TASK_INIT(&sc
->periodic_task
, 0, rt2860_periodic_task
, sc
);
711 sc
->rx_process_limit
= 100;
713 sc
->taskqueue
= taskqueue_create("rt2860_taskq", M_NOWAIT
,
714 taskqueue_thread_enqueue
, &sc
->taskqueue
);
716 taskqueue_start_threads(&sc
->taskqueue
, 1, PI_NET
, "%s taskq",
717 device_get_nameunit(sc
->dev
));
719 rt2860_sysctl_attach(sc
);
722 ieee80211_announce(ic
);
724 /* set up interrupt */
726 error
= bus_setup_intr(dev
, sc
->irq
, INTR_TYPE_NET
| INTR_MPSAFE
,
727 NULL
, rt2860_intr
, sc
, &sc
->irqh
);
730 printf("%s: could not set up interrupt\n",
731 device_get_nameunit(dev
));
739 /* free Tx and Rx rings */
741 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
742 rt2860_free_tx_ring(sc
, &sc
->tx_ring
[i
]);
744 rt2860_free_rx_ring(sc
, &sc
->rx_ring
);
746 mtx_destroy(&sc
->lock
);
749 bus_release_resource(dev
, SYS_RES_MEMORY
, sc
->mem_rid
, sc
->mem
);
752 bus_release_resource(dev
, SYS_RES_IRQ
, sc
->irq_rid
, sc
->irq
);
760 static int rt2860_detach(device_t dev
)
762 struct rt2860_softc
*sc
;
763 struct ieee80211com
*ic
;
767 sc
= device_get_softc(dev
);
771 RT2860_DPRINTF(sc
, RT2860_DEBUG_ANY
,
773 device_get_nameunit(sc
->dev
));
775 RT2860_SOFTC_LOCK(sc
);
777 ifp
->if_drv_flags
&= ~(IFF_DRV_RUNNING
| IFF_DRV_OACTIVE
);
779 ieee80211_new_state(ic
, IEEE80211_S_INIT
, -1);
781 callout_stop(&sc
->periodic_ch
);
782 callout_stop(&sc
->tx_watchdog_ch
);
784 taskqueue_drain(sc
->taskqueue
, &sc
->rx_done_task
);
785 taskqueue_drain(sc
->taskqueue
, &sc
->tx_done_task
);
786 taskqueue_drain(sc
->taskqueue
, &sc
->fifo_sta_full_task
);
787 taskqueue_drain(sc
->taskqueue
, &sc
->periodic_task
);
789 /* free Tx and Rx rings */
791 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
792 rt2860_free_tx_ring(sc
, &sc
->tx_ring
[i
]);
794 rt2860_free_rx_ring(sc
, &sc
->rx_ring
);
796 RT2860_SOFTC_UNLOCK(sc
);
800 ieee80211_ifdetach(ic
);
804 taskqueue_free(sc
->taskqueue
);
806 mtx_destroy(&sc
->lock
);
808 bus_generic_detach(dev
);
810 bus_teardown_intr(dev
, sc
->irq
, sc
->irqh
);
812 bus_release_resource(dev
, SYS_RES_IRQ
, sc
->irq_rid
, sc
->irq
);
814 bus_release_resource(dev
, SYS_RES_MEMORY
, sc
->mem_rid
, sc
->mem
);
822 static int rt2860_shutdown(device_t dev
)
824 struct rt2860_softc
*sc
;
826 sc
= device_get_softc(dev
);
828 RT2860_DPRINTF(sc
, RT2860_DEBUG_ANY
,
829 "%s: shutting down\n",
830 device_get_nameunit(sc
->dev
));
834 sc
->flags
&= ~RT2860_SOFTC_FLAGS_UCODE_LOADED
;
842 static int rt2860_suspend(device_t dev
)
844 struct rt2860_softc
*sc
;
846 sc
= device_get_softc(dev
);
848 RT2860_DPRINTF(sc
, RT2860_DEBUG_ANY
,
850 device_get_nameunit(sc
->dev
));
854 sc
->flags
&= ~RT2860_SOFTC_FLAGS_UCODE_LOADED
;
862 static int rt2860_resume(device_t dev
)
864 struct rt2860_softc
*sc
;
867 sc
= device_get_softc(dev
);
870 RT2860_DPRINTF(sc
, RT2860_DEBUG_ANY
,
872 device_get_nameunit(sc
->dev
));
874 if (ifp
->if_flags
& IFF_UP
)
881 * rt2860_init_channels
883 static void rt2860_init_channels(struct rt2860_softc
*sc
)
885 struct ieee80211com
*ic
;
886 struct ieee80211_channel
*c
;
891 /* set supported channels for 2GHz band */
893 for (i
= 1; i
<= 14; i
++)
895 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
896 flags
= IEEE80211_CHAN_B
;
898 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
902 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
903 flags
= IEEE80211_CHAN_B
| IEEE80211_CHAN_HT20
;
905 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
909 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
910 flags
= IEEE80211_CHAN_G
;
912 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
916 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
917 flags
= IEEE80211_CHAN_G
| IEEE80211_CHAN_HT20
;
919 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
924 /* set supported channels for 5GHz band */
926 if (sc
->rf_rev
== RT2860_EEPROM_RF_2850
||
927 sc
->rf_rev
== RT2860_EEPROM_RF_2750
)
929 for (i
= 36; i
<= 64; i
+= 4)
931 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
932 flags
= IEEE80211_CHAN_A
;
934 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
938 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
939 flags
= IEEE80211_CHAN_A
| IEEE80211_CHAN_HT20
;
941 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
946 for (i
= 100; i
<= 140; i
+= 4)
948 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
949 flags
= IEEE80211_CHAN_A
;
951 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
955 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
956 flags
= IEEE80211_CHAN_A
| IEEE80211_CHAN_HT20
;
958 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
963 for (i
= 149; i
<= 165; i
+= 4)
965 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
966 flags
= IEEE80211_CHAN_A
;
968 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
972 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
973 flags
= IEEE80211_CHAN_A
| IEEE80211_CHAN_HT20
;
975 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
983 * rt2860_init_channels_ht40
985 static void rt2860_init_channels_ht40(struct rt2860_softc
*sc
)
987 struct ieee80211com
*ic
;
988 struct ieee80211_channel
*c
, *cent
, *ext
;
993 /* set supported channels for 2GHz band */
995 for (i
= 1; i
<= 14; i
++)
997 flags
= IEEE80211_CHAN_G
| IEEE80211_CHAN_HT40
;
999 /* find the center channel */
1001 cent
= ieee80211_find_channel_byieee(ic
, i
,
1002 flags
& ~IEEE80211_CHAN_HT
);
1005 printf("%s: skip channel %d, could not find center channel\n",
1006 device_get_nameunit(sc
->dev
), i
);
1010 /* find the extension channel */
1012 ext
= ieee80211_find_channel(ic
, cent
->ic_freq
+ 20,
1013 flags
& ~IEEE80211_CHAN_HT
);
1016 printf("%s: skip channel %d, could not find extension channel\n",
1017 device_get_nameunit(sc
->dev
), i
);
1021 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1024 c
->ic_extieee
= ext
->ic_ieee
;
1025 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1026 c
->ic_flags
|= IEEE80211_CHAN_HT40U
;
1028 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1031 c
->ic_extieee
= cent
->ic_ieee
;
1032 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1033 c
->ic_flags
|= IEEE80211_CHAN_HT40D
;
1036 /* set supported channels for 5GHz band */
1038 if (sc
->rf_rev
== RT2860_EEPROM_RF_2850
||
1039 sc
->rf_rev
== RT2860_EEPROM_RF_2750
)
1041 for (i
= 36; i
<= 64; i
+= 4)
1043 flags
= IEEE80211_CHAN_A
| IEEE80211_CHAN_HT40
;
1045 /* find the center channel */
1047 cent
= ieee80211_find_channel_byieee(ic
, i
,
1048 flags
& ~IEEE80211_CHAN_HT
);
1051 printf("%s: skip channel %d, could not find center channel\n",
1052 device_get_nameunit(sc
->dev
), i
);
1056 /* find the extension channel */
1058 ext
= ieee80211_find_channel(ic
, cent
->ic_freq
+ 20,
1059 flags
& ~IEEE80211_CHAN_HT
);
1062 printf("%s: skip channel %d, could not find extension channel\n",
1063 device_get_nameunit(sc
->dev
), i
);
1067 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1070 c
->ic_extieee
= ext
->ic_ieee
;
1071 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1072 c
->ic_flags
|= IEEE80211_CHAN_HT40U
;
1074 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1077 c
->ic_extieee
= cent
->ic_ieee
;
1078 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1079 c
->ic_flags
|= IEEE80211_CHAN_HT40D
;
1082 for (i
= 100; i
<= 140; i
+= 4)
1084 flags
= IEEE80211_CHAN_A
| IEEE80211_CHAN_HT40
;
1086 /* find the center channel */
1088 cent
= ieee80211_find_channel_byieee(ic
, i
,
1089 flags
& ~IEEE80211_CHAN_HT
);
1092 printf("%s: skip channel %d, could not find center channel\n",
1093 device_get_nameunit(sc
->dev
), i
);
1097 /* find the extension channel */
1099 ext
= ieee80211_find_channel(ic
, cent
->ic_freq
+ 20,
1100 flags
& ~IEEE80211_CHAN_HT
);
1103 printf("%s: skip channel %d, could not find extension channel\n",
1104 device_get_nameunit(sc
->dev
), i
);
1108 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1111 c
->ic_extieee
= ext
->ic_ieee
;
1112 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1113 c
->ic_flags
|= IEEE80211_CHAN_HT40U
;
1115 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1118 c
->ic_extieee
= cent
->ic_ieee
;
1119 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1120 c
->ic_flags
|= IEEE80211_CHAN_HT40D
;
1123 for (i
= 149; i
<= 165; i
+= 4)
1125 flags
= IEEE80211_CHAN_A
| IEEE80211_CHAN_HT40
;
1127 /* find the center channel */
1129 cent
= ieee80211_find_channel_byieee(ic
, i
,
1130 flags
& ~IEEE80211_CHAN_HT
);
1133 printf("%s: skip channel %d, could not find center channel\n",
1134 device_get_nameunit(sc
->dev
), i
);
1138 /* find the extension channel */
1140 ext
= ieee80211_find_channel(ic
, cent
->ic_freq
+ 20,
1141 flags
& ~IEEE80211_CHAN_HT
);
1144 printf("%s: skip channel %d, could not find extension channel\n",
1145 device_get_nameunit(sc
->dev
), i
);
1149 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1152 c
->ic_extieee
= ext
->ic_ieee
;
1153 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1154 c
->ic_flags
|= IEEE80211_CHAN_HT40U
;
1156 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1159 c
->ic_extieee
= cent
->ic_ieee
;
1160 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1161 c
->ic_flags
|= IEEE80211_CHAN_HT40D
;
1167 * rt2860_init_locked
1169 static void rt2860_init_locked(void *priv
)
1171 struct rt2860_softc
*sc
;
1172 struct ieee80211com
*ic
;
1174 int error
, i
, ntries
;
1175 uint32_t tmp
, stacnt
[6];
1181 RT2860_DPRINTF(sc
, RT2860_DEBUG_ANY
,
1182 "%s: initializing\n",
1183 device_get_nameunit(sc
->dev
));
1185 RT2860_SOFTC_ASSERT_LOCKED(sc
);
1187 if (!(sc
->flags
& RT2860_SOFTC_FLAGS_UCODE_LOADED
))
1189 RT2860_DPRINTF(sc
, RT2860_DEBUG_ANY
,
1190 "%s: loading 8051 microcode\n",
1191 device_get_nameunit(sc
->dev
));
1193 error
= rt2860_io_mcu_load_ucode(sc
, rt2860_ucode
, sizeof(rt2860_ucode
));
1196 printf("%s: could not load 8051 microcode\n",
1197 device_get_nameunit(sc
->dev
));
1201 RT2860_DPRINTF(sc
, RT2860_DEBUG_ANY
,
1202 "%s: 8051 microcode was successfully loaded\n",
1203 device_get_nameunit(sc
->dev
));
1205 sc
->flags
|= RT2860_SOFTC_FLAGS_UCODE_LOADED
;
1208 rt2860_io_mac_write(sc
, RT2860_REG_PWR_PIN_CFG
, 0x2);
1210 /* disable DMA engine */
1212 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
);
1215 tmp
|= RT2860_REG_TX_WB_DDONE
;
1217 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
, tmp
);
1219 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WPDMA_RST_IDX
, 0xffffffff);
1221 /* PBF hardware reset */
1223 rt2860_io_mac_write(sc
, RT2860_REG_PBF_SYS_CTRL
, 0xe1f);
1224 rt2860_io_mac_write(sc
, RT2860_REG_PBF_SYS_CTRL
, 0xe00);
1226 /* wait while DMA engine is busy */
1228 for (ntries
= 0; ntries
< 100; ntries
++)
1230 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
);
1231 if (!(tmp
& (RT2860_REG_TX_DMA_BUSY
| RT2860_REG_RX_DMA_BUSY
)))
1239 printf("%s: timeout waiting for DMA engine\n",
1240 device_get_nameunit(sc
->dev
));
1245 tmp
|= RT2860_REG_TX_WB_DDONE
;
1247 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
, tmp
);
1249 /* reset Rx and Tx rings */
1251 tmp
= RT2860_REG_RST_IDX_RX
|
1252 RT2860_REG_RST_IDX_TX_MGMT
|
1253 RT2860_REG_RST_IDX_TX_HCCA
|
1254 RT2860_REG_RST_IDX_TX_AC3
|
1255 RT2860_REG_RST_IDX_TX_AC2
|
1256 RT2860_REG_RST_IDX_TX_AC1
|
1257 RT2860_REG_RST_IDX_TX_AC0
;
1259 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WPDMA_RST_IDX
, tmp
);
1261 /* PBF hardware reset */
1263 rt2860_io_mac_write(sc
, RT2860_REG_PBF_SYS_CTRL
, 0xe1f);
1264 rt2860_io_mac_write(sc
, RT2860_REG_PBF_SYS_CTRL
, 0xe00);
1266 rt2860_io_mac_write(sc
, RT2860_REG_PWR_PIN_CFG
, 0x3);
1268 rt2860_io_mac_write(sc
, RT2860_REG_SYS_CTRL
,
1269 RT2860_REG_MAC_SRST
| RT2860_REG_BBP_HRST
);
1270 rt2860_io_mac_write(sc
, RT2860_REG_SYS_CTRL
, 0);
1272 /* init Tx power per rate */
1274 for (i
= 0; i
< RT2860_SOFTC_TXPOW_RATE_COUNT
; i
++)
1276 if (sc
->txpow_rate_20mhz
[i
] == 0xffffffff)
1279 rt2860_io_mac_write(sc
, RT2860_REG_TX_PWR_CFG(i
),
1280 sc
->txpow_rate_20mhz
[i
]);
1283 for (i
= 0; i
< RT2860_DEF_MAC_SIZE
; i
++)
1284 rt2860_io_mac_write(sc
, rt2860_def_mac
[i
].reg
,
1285 rt2860_def_mac
[i
].val
);
1287 /* wait while MAC is busy */
1289 for (ntries
= 0; ntries
< 100; ntries
++)
1291 if (!(rt2860_io_mac_read(sc
, RT2860_REG_STATUS_CFG
) &
1292 (RT2860_REG_STATUS_TX_BUSY
| RT2860_REG_STATUS_RX_BUSY
)))
1300 printf("%s: timeout waiting for MAC\n",
1301 device_get_nameunit(sc
->dev
));
1305 /* clear Host to MCU mailbox */
1307 rt2860_io_mac_write(sc
, RT2860_REG_H2M_MAILBOX_BBP_AGENT
, 0);
1308 rt2860_io_mac_write(sc
, RT2860_REG_H2M_MAILBOX
, 0);
1310 rt2860_io_mcu_cmd(sc
, RT2860_IO_MCU_CMD_BOOT
,
1311 RT2860_REG_H2M_TOKEN_NO_INTR
, 0);
1315 error
= rt2860_init_bbp(sc
);
1319 /* set up maximum buffer sizes */
1321 tmp
= (1 << 12) | RT2860_MAX_AGG_SIZE
;
1323 rt2860_io_mac_write(sc
, RT2860_REG_MAX_LEN_CFG
, tmp
);
1325 /* set mac address */
1327 IEEE80211_ADDR_COPY(ic
->ic_myaddr
, IF_LLADDR(ifp
));
1329 rt2860_asic_set_macaddr(sc
, ic
->ic_myaddr
);
1331 /* clear statistic registers */
1333 rt2860_io_mac_read_multi(sc
, RT2860_REG_RX_STA_CNT0
,
1334 stacnt
, sizeof(stacnt
));
1336 /* set RTS threshold */
1338 rt2860_asic_update_rtsthreshold(sc
);
1342 rt2860_asic_update_txpower(sc
);
1344 /* set up protection mode */
1346 sc
->tx_ampdu_sessions
= 0;
1348 rt2860_asic_updateprot(sc
);
1350 /* clear beacon frame space (entries = 8, entry size = 512) */
1352 rt2860_io_mac_set_region_4(sc
, RT2860_REG_BEACON_BASE(0), 0, 1024);
1354 taskqueue_unblock(sc
->taskqueue
);
1356 /* init Tx rings (4 EDCAs + HCCA + MGMT) */
1358 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
1359 rt2860_reset_tx_ring(sc
, &sc
->tx_ring
[i
]);
1361 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
1363 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_BASE_PTR(i
),
1364 sc
->tx_ring
[i
].desc_phys_addr
);
1365 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_MAX_CNT(i
),
1366 RT2860_SOFTC_TX_RING_DESC_COUNT
);
1367 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_CTX_IDX(i
), 0);
1372 rt2860_reset_rx_ring(sc
, &sc
->rx_ring
);
1374 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_BASE_PTR
,
1375 sc
->rx_ring
.desc_phys_addr
);
1376 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_MAX_CNT
,
1377 RT2860_SOFTC_RX_RING_DATA_COUNT
);
1378 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_CALC_IDX
,
1379 RT2860_SOFTC_RX_RING_DATA_COUNT
- 1);
1381 /* wait while DMA engine is busy */
1383 for (ntries
= 0; ntries
< 100; ntries
++)
1385 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
);
1386 if (!(tmp
& (RT2860_REG_TX_DMA_BUSY
| RT2860_REG_RX_DMA_BUSY
)))
1394 printf("%s: timeout waiting for DMA engine\n",
1395 device_get_nameunit(sc
->dev
));
1400 tmp
|= RT2860_REG_TX_WB_DDONE
;
1402 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
, tmp
);
1404 /* disable interrupts mitigation */
1406 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_DELAY_INT_CFG
, 0);
1408 /* send LEDs operating mode to microcontroller */
1410 rt2860_io_mcu_cmd(sc
, RT2860_IO_MCU_CMD_LED1
,
1411 RT2860_REG_H2M_TOKEN_NO_INTR
, sc
->led_off
[0]);
1412 rt2860_io_mcu_cmd(sc
, RT2860_IO_MCU_CMD_LED2
,
1413 RT2860_REG_H2M_TOKEN_NO_INTR
, sc
->led_off
[1]);
1414 rt2860_io_mcu_cmd(sc
, RT2860_IO_MCU_CMD_LED3
,
1415 RT2860_REG_H2M_TOKEN_NO_INTR
, sc
->led_off
[2]);
1417 /* turn radio LED on */
1419 rt2860_led_cmd(sc
, RT2860_LED_CMD_RADIO_ON
);
1421 /* write vendor-specific BBP values (from EEPROM) */
1423 for (i
= 0; i
< RT2860_SOFTC_BBP_EEPROM_COUNT
; i
++)
1425 if (sc
->bbp_eeprom
[i
].reg
== 0x00 ||
1426 sc
->bbp_eeprom
[i
].reg
== 0xff)
1429 rt2860_io_bbp_write(sc
, sc
->bbp_eeprom
[i
].reg
,
1430 sc
->bbp_eeprom
[i
].val
);
1433 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_GPIO_CTRL_CFG
);
1436 rt2860_io_mcu_cmd(sc
, RT2860_IO_MCU_CMD_SLEEP
,
1437 RT2860_REG_H2M_TOKEN_RADIOOFF
, 0x02ff);
1438 rt2860_io_mcu_cmd_check(sc
, RT2860_REG_H2M_TOKEN_RADIOOFF
);
1440 rt2860_io_mcu_cmd(sc
, RT2860_IO_MCU_CMD_WAKEUP
,
1441 RT2860_REG_H2M_TOKEN_WAKEUP
, 0);
1442 rt2860_io_mcu_cmd_check(sc
, RT2860_REG_H2M_TOKEN_WAKEUP
);
1445 /* disable non-existing Rx chains */
1447 tmp
= rt2860_io_bbp_read(sc
, 3);
1449 tmp
&= ~((1 << 4) | (1 << 3));
1451 if (sc
->nrxpath
== 3)
1453 else if (sc
->nrxpath
== 2)
1456 rt2860_io_bbp_write(sc
, 3, tmp
);
1458 /* disable non-existing Tx chains */
1460 tmp
= rt2860_io_bbp_read(sc
, 1);
1462 tmp
&= ~((1 << 4) | (1 << 3));
1464 if (sc
->ntxpath
== 2)
1467 rt2860_io_bbp_write(sc
, 1, tmp
);
1469 /* set current channel */
1471 rt2860_rf_set_chan(sc
, ic
->ic_curchan
);
1473 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WMM_TXOP0_CFG
, 0);
1474 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WMM_TXOP1_CFG
,
1477 if ((sc
->mac_rev
& 0xffff) != 0x0101)
1478 rt2860_io_mac_write(sc
, RT2860_REG_TX_TXOP_CTRL_CFG
, 0x583f);
1480 /* clear pending interrupts */
1482 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_INT_STATUS
, 0xffffffff);
1484 /* enable interrupts */
1486 tmp
= RT2860_REG_INT_TX_COHERENT
|
1487 RT2860_REG_INT_RX_COHERENT
|
1488 RT2860_REG_INT_GP_TIMER
|
1489 RT2860_REG_INT_AUTO_WAKEUP
|
1490 RT2860_REG_INT_FIFO_STA_FULL
|
1492 RT2860_REG_INT_PRE_TBTT |
1493 RT2860_REG_INT_TBTT |
1495 RT2860_REG_INT_TXRX_COHERENT
|
1496 RT2860_REG_INT_MCU_CMD
|
1497 RT2860_REG_INT_TX_MGMT_DONE
|
1498 RT2860_REG_INT_TX_HCCA_DONE
|
1499 RT2860_REG_INT_TX_AC3_DONE
|
1500 RT2860_REG_INT_TX_AC2_DONE
|
1501 RT2860_REG_INT_TX_AC1_DONE
|
1502 RT2860_REG_INT_TX_AC0_DONE
|
1503 RT2860_REG_INT_RX_DONE
;
1505 sc
->intr_enable_mask
= tmp
;
1507 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_INT_MASK
, tmp
);
1509 if (rt2860_txrx_enable(sc
) != 0)
1512 /* clear garbage interrupts */
1514 tmp
= rt2860_io_mac_read(sc
, 0x1300);
1516 ifp
->if_drv_flags
&= ~IFF_DRV_OACTIVE
;
1517 ifp
->if_drv_flags
|= IFF_DRV_RUNNING
;
1519 if (ic
->ic_opmode
!= IEEE80211_M_MONITOR
)
1521 if (ic
->ic_roaming
!= IEEE80211_ROAMING_MANUAL
)
1522 ieee80211_new_state(ic
, IEEE80211_S_SCAN
, -1);
1526 ieee80211_new_state(ic
, IEEE80211_S_RUN
, -1);
1529 sc
->periodic_round
= 0;
1531 callout_reset(&sc
->periodic_ch
, hz
/ 10, rt2860_periodic
, sc
);
1537 rt2860_stop_locked(sc
);
1543 static void rt2860_init(void *priv
)
1545 struct rt2860_softc
*sc
;
1549 RT2860_SOFTC_LOCK(sc
);
1551 rt2860_init_locked(sc
);
1553 RT2860_SOFTC_UNLOCK(sc
);
1559 static int rt2860_init_bbp(struct rt2860_softc
*sc
)
1564 for (ntries
= 0; ntries
< 20; ntries
++)
1566 tmp
= rt2860_io_bbp_read(sc
, 0);
1567 if (tmp
!= 0x00 && tmp
!= 0xff)
1571 if (tmp
== 0x00 || tmp
== 0xff)
1573 printf("%s: timeout waiting for BBP to wakeup\n",
1574 device_get_nameunit(sc
->dev
));
1578 for (i
= 0; i
< RT2860_DEF_BBP_SIZE
; i
++)
1579 rt2860_io_bbp_write(sc
, rt2860_def_bbp
[i
].reg
,
1580 rt2860_def_bbp
[i
].val
);
1582 if ((sc
->mac_rev
& 0xffff) != 0x0101)
1583 rt2860_io_bbp_write(sc
, 84, 0x19);
1589 * rt2860_stop_locked
1591 static void rt2860_stop_locked(void *priv
)
1593 struct rt2860_softc
*sc
;
1594 struct ieee80211com
*ic
;
1602 RT2860_DPRINTF(sc
, RT2860_DEBUG_ANY
,
1604 device_get_nameunit(sc
->dev
));
1606 RT2860_SOFTC_ASSERT_LOCKED(sc
);
1610 if (ifp
->if_drv_flags
& IFF_DRV_RUNNING
)
1611 rt2860_led_cmd(sc
, RT2860_LED_CMD_RADIO_OFF
);
1613 ifp
->if_drv_flags
&= ~(IFF_DRV_RUNNING
| IFF_DRV_OACTIVE
);
1615 ieee80211_new_state(ic
, IEEE80211_S_INIT
, -1);
1617 callout_stop(&sc
->periodic_ch
);
1618 callout_stop(&sc
->tx_watchdog_ch
);
1620 RT2860_SOFTC_UNLOCK(sc
);
1622 taskqueue_block(sc
->taskqueue
);
1624 taskqueue_drain(sc
->taskqueue
, &sc
->rx_done_task
);
1625 taskqueue_drain(sc
->taskqueue
, &sc
->tx_done_task
);
1626 taskqueue_drain(sc
->taskqueue
, &sc
->fifo_sta_full_task
);
1627 taskqueue_drain(sc
->taskqueue
, &sc
->periodic_task
);
1629 RT2860_SOFTC_LOCK(sc
);
1631 /* clear key tables */
1633 rt2860_asic_clear_keytables(sc
);
1635 /* disable interrupts */
1637 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_INT_MASK
, 0);
1641 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_SYS_CTRL
);
1643 tmp
&= ~(RT2860_REG_RX_ENABLE
| RT2860_REG_TX_ENABLE
);
1645 rt2860_io_mac_write(sc
, RT2860_REG_SYS_CTRL
, tmp
);
1649 rt2860_io_mac_write(sc
, RT2860_REG_SYS_CTRL
,
1650 RT2860_REG_MAC_SRST
| RT2860_REG_BBP_HRST
);
1651 rt2860_io_mac_write(sc
, RT2860_REG_SYS_CTRL
, 0);
1653 if (sc
->beacon_mbuf
!= NULL
)
1655 m_free(sc
->beacon_mbuf
);
1656 sc
->beacon_mbuf
= NULL
;
1663 static void rt2860_stop(void *priv
)
1665 struct rt2860_softc
*sc
;
1669 RT2860_SOFTC_LOCK(sc
);
1671 rt2860_stop_locked(sc
);
1673 RT2860_SOFTC_UNLOCK(sc
);
1679 static void rt2860_start(struct ifnet
*ifp
)
1681 struct rt2860_softc
*sc
;
1682 struct ieee80211com
*ic
;
1683 struct ieee80211_node
*ni
;
1684 struct ether_header
*eh
;
1691 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
1696 IF_POLL(&ic
->ic_mgtq
, m
);
1699 RT2860_SOFTC_TX_RING_LOCK(&sc
->tx_ring
[sc
->tx_ring_mgtqid
]);
1701 if (sc
->tx_ring
[sc
->tx_ring_mgtqid
].data_queued
>= RT2860_SOFTC_TX_RING_DATA_COUNT
)
1703 RT2860_SOFTC_TX_RING_UNLOCK(&sc
->tx_ring
[sc
->tx_ring_mgtqid
]);
1705 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
1706 "%s: if_start: Tx ring with qid=%d is full\n",
1707 device_get_nameunit(sc
->dev
), sc
->tx_ring_mgtqid
);
1709 ifp
->if_drv_flags
|= IFF_DRV_OACTIVE
;
1711 sc
->tx_data_queue_full
[sc
->tx_ring_mgtqid
]++;
1716 IF_DEQUEUE(&ic
->ic_mgtq
, m
);
1719 RT2860_SOFTC_TX_RING_UNLOCK(&sc
->tx_ring
[sc
->tx_ring_mgtqid
]);
1723 ni
= (struct ieee80211_node
*) m
->m_pkthdr
.rcvif
;
1725 m
->m_pkthdr
.rcvif
= NULL
;
1727 if (bpf_peers_present(ic
->ic_rawbpf
))
1728 bpf_mtap(ic
->ic_rawbpf
, m
);
1730 if (rt2860_tx_frame(sc
, m
, ni
, sc
->tx_ring_mgtqid
) != 0)
1732 RT2860_SOFTC_TX_RING_UNLOCK(&sc
->tx_ring
[sc
->tx_ring_mgtqid
]);
1736 RT2860_SOFTC_TX_RING_UNLOCK(&sc
->tx_ring
[sc
->tx_ring_mgtqid
]);
1738 rt2860_drain_fifo_stats(sc
);
1742 if (ic
->ic_state
!= IEEE80211_S_RUN
)
1745 IFQ_DRV_DEQUEUE(&ifp
->if_snd
, m
);
1749 if (ic
->ic_flags
& IEEE80211_F_SCAN
)
1750 ieee80211_cancel_scan(ic
);
1752 if (m
->m_len
< sizeof(struct ether_header
) &&
1753 !(m
= m_pullup(m
, sizeof (struct ether_header
))))
1756 eh
= mtod(m
, struct ether_header
*);
1758 ni
= ieee80211_find_txnode(ic
, eh
->ether_dhost
);
1761 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
1762 "%s: if_start: could not find Tx node\n",
1763 device_get_nameunit(sc
->dev
));
1770 ieee80211_classify(ic
, m
, ni
);
1772 qid
= M_WME_GETAC(m
);
1774 RT2860_SOFTC_TX_RING_LOCK(&sc
->tx_ring
[qid
]);
1776 if (sc
->tx_ring
[qid
].data_queued
>= RT2860_SOFTC_TX_RING_DATA_COUNT
)
1778 RT2860_SOFTC_TX_RING_UNLOCK(&sc
->tx_ring
[qid
]);
1780 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
1781 "%s: if_start: Tx ring with qid=%d is full\n",
1782 device_get_nameunit(sc
->dev
), qid
);
1785 ieee80211_free_node(ni
);
1787 ifp
->if_drv_flags
|= IFF_DRV_OACTIVE
;
1790 sc
->tx_data_queue_full
[qid
]++;
1797 m
= ieee80211_encap(ic
, m
, ni
);
1800 RT2860_SOFTC_TX_RING_UNLOCK(&sc
->tx_ring
[qid
]);
1802 ieee80211_free_node(ni
);
1809 if (bpf_peers_present(ic
->ic_rawbpf
))
1810 bpf_mtap(ic
->ic_rawbpf
, m
);
1812 if (rt2860_tx_frame(sc
, m
, ni
, qid
) != 0)
1814 RT2860_SOFTC_TX_RING_UNLOCK(&sc
->tx_ring
[qid
]);
1816 ieee80211_free_node(ni
);
1823 RT2860_SOFTC_TX_RING_UNLOCK(&sc
->tx_ring
[qid
]);
1825 rt2860_drain_fifo_stats(sc
);
1828 sc
->tx_timer
= RT2860_TX_WATCHDOG_TIMEOUT
;
1830 ic
->ic_lastdata
= ticks
;
1832 callout_reset(&sc
->tx_watchdog_ch
, hz
, rt2860_tx_watchdog
, sc
);
1839 static int rt2860_ioctl(struct ifnet
*ifp
, u_long cmd
, caddr_t data
)
1841 struct rt2860_softc
*sc
;
1842 struct ieee80211com
*ic
;
1853 RT2860_SOFTC_LOCK(sc
);
1855 if (ifp
->if_flags
& IFF_UP
)
1857 if (ifp
->if_drv_flags
& IFF_DRV_RUNNING
)
1859 if ((ifp
->if_flags
^ sc
->if_flags
) & IFF_PROMISC
)
1860 rt2860_asic_update_promisc(sc
);
1864 rt2860_init_locked(sc
);
1869 if (ifp
->if_drv_flags
& IFF_DRV_RUNNING
)
1870 rt2860_stop_locked(sc
);
1873 sc
->if_flags
= ifp
->if_flags
;
1875 RT2860_SOFTC_UNLOCK(sc
);
1879 error
= ieee80211_ioctl(ic
, cmd
, data
);
1882 if (error
== ENETRESET
)
1884 RT2860_SOFTC_LOCK(sc
);
1886 if ((ifp
->if_flags
& IFF_UP
) &&
1887 (ifp
->if_drv_flags
& IFF_DRV_RUNNING
) &&
1888 (ic
->ic_roaming
!= IEEE80211_ROAMING_MANUAL
))
1890 rt2860_stop_locked(sc
);
1891 rt2860_init_locked(sc
);
1894 RT2860_SOFTC_UNLOCK(sc
);
1905 static int rt2860_reset(struct ifnet
*ifp
)
1907 struct rt2860_softc
*sc
;
1908 struct ieee80211com
*ic
;
1913 if (ic
->ic_opmode
!= IEEE80211_M_MONITOR
)
1916 rt2860_rf_set_chan(sc
, ic
->ic_curchan
);
1924 static int rt2860_newstate(struct ieee80211com
*ic
,
1925 enum ieee80211_state nstate
, int arg
)
1927 struct rt2860_softc
*sc
;
1929 struct ieee80211_node
*ni
;
1935 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATE
,
1936 "%s: newstate: %s -> %s\n",
1937 device_get_nameunit(sc
->dev
),
1938 ieee80211_state_name
[ic
->ic_state
], ieee80211_state_name
[nstate
]);
1940 error
= sc
->newstate(ic
, nstate
, arg
);
1944 RT2860_SOFTC_LOCK(sc
);
1946 /* turn link LED off */
1948 if (nstate
!= IEEE80211_S_RUN
)
1949 rt2860_led_cmd(sc
, RT2860_LED_CMD_RADIO_OFF
);
1953 case IEEE80211_S_INIT
:
1954 rt2860_asic_disable_tsf_sync(sc
);
1957 case IEEE80211_S_RUN
:
1960 if (ic
->ic_opmode
!= IEEE80211_M_MONITOR
)
1961 rt2860_rf_set_chan(sc
, ni
->ni_chan
);
1963 if (ic
->ic_opmode
!= IEEE80211_M_MONITOR
)
1965 rt2860_asic_enable_mrr(sc
);
1966 rt2860_asic_set_txpreamble(sc
);
1967 rt2860_asic_set_basicrates(sc
);
1968 rt2860_asic_update_txpower(sc
);
1969 rt2860_asic_set_bssid(sc
, ni
->ni_bssid
);
1972 if (ic
->ic_opmode
== IEEE80211_M_STA
)
1973 rt2860_newassoc(ni
, 1);
1975 if (ic
->ic_opmode
== IEEE80211_M_HOSTAP
||
1976 ic
->ic_opmode
== IEEE80211_M_IBSS
)
1978 error
= rt2860_beacon_alloc(sc
);
1982 rt2860_asic_update_beacon(sc
);
1985 if (ic
->ic_opmode
!= IEEE80211_M_MONITOR
)
1986 rt2860_asic_enable_tsf_sync(sc
);
1988 /* turn link LED on */
1990 if (ic
->ic_opmode
!= IEEE80211_M_MONITOR
)
1992 rt2860_led_cmd(sc
, RT2860_LED_CMD_RADIO_ON
|
1993 (IEEE80211_IS_CHAN_2GHZ(ni
->ni_chan
) ?
1994 RT2860_LED_CMD_LINK_2GHZ
: RT2860_LED_CMD_LINK_5GHZ
));
1998 case IEEE80211_S_SLEEP
:
2005 RT2860_SOFTC_UNLOCK(sc
);
2013 static void rt2860_scan_start(struct ieee80211com
*ic
)
2015 struct rt2860_softc
*sc
;
2021 rt2860_asic_disable_tsf_sync(sc
);
2027 static void rt2860_scan_end(struct ieee80211com
*ic
)
2029 struct rt2860_softc
*sc
;
2035 rt2860_asic_enable_tsf_sync(sc
);
2039 * rt2860_set_channel
2041 static void rt2860_set_channel(struct ieee80211com
*ic
)
2043 struct rt2860_softc
*sc
;
2049 RT2860_DPRINTF(sc
, RT2860_DEBUG_CHAN
,
2050 "%s: set channel: channel=%u, HT%s%s\n",
2051 device_get_nameunit(sc
->dev
),
2052 ieee80211_chan2ieee(ic
, ic
->ic_curchan
),
2053 !IEEE80211_IS_CHAN_HT(ic
->ic_curchan
) ? " disabled" :
2054 IEEE80211_IS_CHAN_HT20(ic
->ic_curchan
) ? "20":
2055 IEEE80211_IS_CHAN_HT40U(ic
->ic_curchan
) ? "40U" : "40D",
2056 (ic
->ic_flags
& IEEE80211_F_SCAN
) ? ", scanning" : "");
2058 RT2860_SOFTC_LOCK(sc
);
2060 rt2860_rf_set_chan(sc
, ic
->ic_curchan
);
2062 RT2860_SOFTC_UNLOCK(sc
);
2068 static void rt2860_newassoc(struct ieee80211_node
*ni
, int isnew
)
2070 struct rt2860_softc
*sc
;
2071 struct ieee80211com
*ic
;
2073 struct rt2860_softc_node
*rni
;
2080 rni
= (struct rt2860_softc_node
*) ni
;
2084 aid
= IEEE80211_AID(ni
->ni_associd
);
2085 rni
->staid
= rt2860_staid_alloc(sc
, aid
);
2088 rt2860_io_mac_write_multi(sc
, RT2860_REG_WCID(wcid
),
2089 ni
->ni_macaddr
, IEEE80211_ADDR_LEN
);
2091 rt2860_amrr_node_init(&sc
->amrr
, &sc
->amrr_node
[wcid
], ni
);
2093 RT2860_DPRINTF(sc
, RT2860_DEBUG_RATE
,
2094 "%s: initial%s node Tx rate: associd=0x%04x, rate=0x%02x, max rate=0x%02x\n",
2095 device_get_nameunit(sc
->dev
),
2096 (ni
->ni_flags
& IEEE80211_NODE_HT
) ? " HT" : "",
2098 (ni
->ni_flags
& IEEE80211_NODE_HT
) ?
2099 (ni
->ni_htrates
.rs_rates
[ni
->ni_txrate
] | IEEE80211_RATE_MCS
) :
2100 (ni
->ni_rates
.rs_rates
[ni
->ni_txrate
] & IEEE80211_RATE_VAL
),
2101 (ni
->ni_flags
& IEEE80211_NODE_HT
) ?
2102 (ni
->ni_htrates
.rs_rates
[ni
->ni_htrates
.rs_nrates
- 1] | IEEE80211_RATE_MCS
) :
2103 (ni
->ni_rates
.rs_rates
[ni
->ni_rates
.rs_nrates
- 1] & IEEE80211_RATE_VAL
));
2105 rt2860_asic_updateprot(sc
);
2106 rt2860_asic_updateslot(sc
);
2107 rt2860_asic_set_txpreamble(sc
);
2110 RT2860_DPRINTF(sc
, RT2860_DEBUG_NODE
,
2111 "%s: new association: isnew=%d, macaddr=%s, associd=0x%04x, staid=0x%02x, QoS %s, ERP %s, HT %s\n",
2112 device_get_nameunit(sc
->dev
), isnew
, ether_sprintf(ni
->ni_macaddr
),
2113 ni
->ni_associd
, rni
->staid
,
2114 (ni
->ni_flags
& IEEE80211_NODE_QOS
) ? "enabled" : "disabled",
2115 (ni
->ni_flags
& IEEE80211_NODE_ERP
) ? "enabled" : "disabled",
2116 (ni
->ni_flags
& IEEE80211_NODE_HT
) ? "enabled" : "disabled");
2123 static void rt2860_updateslot(struct ifnet
*ifp
)
2125 struct rt2860_softc
*sc
;
2129 rt2860_asic_updateslot(sc
);
2135 static int rt2860_wme_update(struct ieee80211com
*ic
)
2137 struct rt2860_softc
*sc
;
2143 rt2860_asic_wme_update(sc
);
2149 * rt2860_update_beacon
2151 static void rt2860_update_beacon(struct ieee80211com
*ic
, int what
)
2153 struct rt2860_softc
*sc
;
2156 struct ieee80211_beacon_offsets
*bo
;
2160 m
= sc
->beacon_mbuf
;
2161 bo
= &sc
->beacon_offsets
;
2163 RT2860_DPRINTF(sc
, RT2860_DEBUG_BEACON
,
2164 "%s: update beacon: what=%d\n",
2165 device_get_nameunit(sc
->dev
), what
);
2167 setbit(bo
->bo_flags
, what
);
2169 ieee80211_beacon_update(ic
->ic_bss
, bo
, m
, 0);
2171 rt2860_asic_update_beacon(sc
);
2175 * rt2860_key_update_begin
2177 static void rt2860_key_update_begin(struct ieee80211com
*ic
)
2179 struct rt2860_softc
*sc
;
2185 RT2860_DPRINTF(sc
, RT2860_DEBUG_KEY
,
2186 "%s: key update begin\n",
2187 device_get_nameunit(sc
->dev
));
2189 taskqueue_block(sc
->taskqueue
);
2191 IF_LOCK(&ifp
->if_snd
);
2195 * rt2860_key_update_end
2197 static void rt2860_key_update_end(struct ieee80211com
*ic
)
2199 struct rt2860_softc
*sc
;
2205 RT2860_DPRINTF(sc
, RT2860_DEBUG_KEY
,
2206 "%s: key update end\n",
2207 device_get_nameunit(sc
->dev
));
2209 IF_UNLOCK(&ifp
->if_snd
);
2211 taskqueue_unblock(sc
->taskqueue
);
2217 static int rt2860_key_set(struct ieee80211com
*ic
,
2218 const struct ieee80211_key
*k
, const uint8_t mac
[IEEE80211_ADDR_LEN
])
2220 struct rt2860_softc
*sc
;
2222 struct ieee80211_node
*ni
;
2223 struct rt2860_softc_node
*rni
;
2224 uint16_t key_base
, keymode_base
;
2225 uint8_t mode
, vapid
, wcid
, iv
[8];
2228 if (k
->wk_cipher
->ic_cipher
!= IEEE80211_CIPHER_WEP
&&
2229 k
->wk_cipher
->ic_cipher
!= IEEE80211_CIPHER_TKIP
&&
2230 k
->wk_cipher
->ic_cipher
!= IEEE80211_CIPHER_AES_CCM
)
2236 switch (k
->wk_cipher
->ic_cipher
)
2238 case IEEE80211_CIPHER_WEP
:
2239 if(k
->wk_keylen
< 8)
2240 mode
= RT2860_REG_CIPHER_MODE_WEP40
;
2242 mode
= RT2860_REG_CIPHER_MODE_WEP104
;
2245 case IEEE80211_CIPHER_TKIP
:
2246 mode
= RT2860_REG_CIPHER_MODE_TKIP
;
2249 case IEEE80211_CIPHER_AES_CCM
:
2250 mode
= RT2860_REG_CIPHER_MODE_AES_CCMP
;
2257 RT2860_DPRINTF(sc
, RT2860_DEBUG_KEY
,
2258 "%s: set key: keyix=%d, keylen=%d, macaddr=%s, mode=%d, group=%d\n",
2259 device_get_nameunit(sc
->dev
), k
->wk_keyix
, k
->wk_keylen
, ether_sprintf(mac
),
2260 mode
, (k
->wk_flags
& IEEE80211_KEY_GROUP
) ? 1 : 0);
2262 if (!(k
->wk_flags
& IEEE80211_KEY_GROUP
))
2264 /* install pairwise key */
2266 ni
= ieee80211_find_node(&ic
->ic_sta
, mac
);
2267 rni
= (struct rt2860_softc_node
*) ni
;
2271 key_base
= RT2860_REG_PKEY(wcid
);
2273 ieee80211_free_node(ni
);
2275 if (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_WEP
)
2279 iv
[3] = (k
->wk_keyix
<< 6);
2283 if (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_TKIP
)
2285 iv
[0] = (k
->wk_keytsc
>> 8);
2286 iv
[1] = ((iv
[0] | 0x20) & 0x7f);
2287 iv
[2] = k
->wk_keytsc
;
2293 iv
[0] = k
->wk_keytsc
;
2294 iv
[1] = k
->wk_keytsc
>> 8;
2298 iv
[3] = ((k
->wk_keyix
<< 6) | IEEE80211_WEP_EXTIV
);
2299 iv
[4] = (k
->wk_keytsc
>> 16);
2300 iv
[5] = (k
->wk_keytsc
>> 24);
2301 iv
[6] = (k
->wk_keytsc
>> 32);
2302 iv
[7] = (k
->wk_keytsc
>> 40);
2304 RT2860_DPRINTF(sc
, RT2860_DEBUG_KEY
,
2305 "%s: set key: iv=%02x %02x %02x %02x %02x %02x %02x %02x\n",
2306 device_get_nameunit(sc
->dev
),
2307 iv
[0], iv
[1], iv
[2], iv
[3], iv
[4], iv
[5], iv
[6], iv
[7]);
2310 rt2860_io_mac_write_multi(sc
, RT2860_REG_IVEIV(wcid
), iv
, 8);
2312 if (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_TKIP
)
2314 rt2860_io_mac_write_multi(sc
, key_base
, k
->wk_key
, 16);
2316 if (ic
->ic_opmode
!= IEEE80211_M_HOSTAP
)
2318 rt2860_io_mac_write_multi(sc
, key_base
+ 16, &k
->wk_key
[16], 8);
2319 rt2860_io_mac_write_multi(sc
, key_base
+ 24, &k
->wk_key
[24], 8);
2323 rt2860_io_mac_write_multi(sc
, key_base
+ 16, &k
->wk_key
[24], 8);
2324 rt2860_io_mac_write_multi(sc
, key_base
+ 24, &k
->wk_key
[16], 8);
2329 rt2860_io_mac_write_multi(sc
, key_base
, k
->wk_key
, k
->wk_keylen
);
2332 tmp
= ((vapid
& RT2860_REG_VAP_MASK
) << RT2860_REG_VAP_SHIFT
) |
2333 (mode
<< RT2860_REG_CIPHER_MODE_SHIFT
) | RT2860_REG_PKEY_ENABLE
;
2335 rt2860_io_mac_write(sc
, RT2860_REG_WCID_ATTR(wcid
), tmp
);
2338 if ((k
->wk_flags
& IEEE80211_KEY_GROUP
) ||
2339 (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_WEP
))
2341 /* install group key */
2344 wcid
= RT2860_WCID_MCAST
;
2345 key_base
= RT2860_REG_SKEY(vapid
, k
->wk_keyix
);
2346 keymode_base
= RT2860_REG_SKEY_MODE(vapid
);
2348 if (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_TKIP
)
2350 rt2860_io_mac_write_multi(sc
, key_base
, k
->wk_key
, 16);
2352 if (ic
->ic_opmode
!= IEEE80211_M_HOSTAP
)
2354 rt2860_io_mac_write_multi(sc
, key_base
+ 16, &k
->wk_key
[16], 8);
2355 rt2860_io_mac_write_multi(sc
, key_base
+ 24, &k
->wk_key
[24], 8);
2359 rt2860_io_mac_write_multi(sc
, key_base
+ 16, &k
->wk_key
[24], 8);
2360 rt2860_io_mac_write_multi(sc
, key_base
+ 24, &k
->wk_key
[16], 8);
2365 rt2860_io_mac_write_multi(sc
, key_base
, k
->wk_key
, k
->wk_keylen
);
2368 tmp
= rt2860_io_mac_read(sc
, keymode_base
);
2370 tmp
&= ~(0xf << (k
->wk_keyix
* 4 + 16 * (vapid
% 2)));
2371 tmp
|= (mode
<< (k
->wk_keyix
* 4 + 16 * (vapid
% 2)));
2373 rt2860_io_mac_write(sc
, keymode_base
, tmp
);
2375 if (ic
->ic_opmode
== IEEE80211_M_HOSTAP
)
2377 if (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_WEP
)
2381 iv
[3] = (k
->wk_keyix
<< 6);
2385 if (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_TKIP
)
2387 iv
[0] = (k
->wk_keytsc
>> 8);
2388 iv
[1] = ((iv
[0] | 0x20) & 0x7f);
2389 iv
[2] = k
->wk_keytsc
;
2395 iv
[0] = k
->wk_keytsc
;
2396 iv
[1] = k
->wk_keytsc
>> 8;
2400 iv
[3] = ((k
->wk_keyix
<< 6) | IEEE80211_WEP_EXTIV
);
2401 iv
[4] = (k
->wk_keytsc
>> 16);
2402 iv
[5] = (k
->wk_keytsc
>> 24);
2403 iv
[6] = (k
->wk_keytsc
>> 32);
2404 iv
[7] = (k
->wk_keytsc
>> 40);
2406 RT2860_DPRINTF(sc
, RT2860_DEBUG_KEY
,
2407 "%s: set key: iv=%02x %02x %02x %02x %02x %02x %02x %02x\n",
2408 device_get_nameunit(sc
->dev
),
2409 iv
[0], iv
[1], iv
[2], iv
[3], iv
[4], iv
[5], iv
[6], iv
[7]);
2412 rt2860_io_mac_write_multi(sc
, RT2860_REG_IVEIV(wcid
), iv
, 8);
2414 tmp
= ((vapid
& RT2860_REG_VAP_MASK
) << RT2860_REG_VAP_SHIFT
) |
2415 (mode
<< RT2860_REG_CIPHER_MODE_SHIFT
);
2417 rt2860_io_mac_write(sc
, RT2860_REG_WCID_ATTR(wcid
), tmp
);
2427 static int rt2860_key_delete(struct ieee80211com
*ic
,
2428 const struct ieee80211_key
*k
)
2430 struct rt2860_softc
*sc
;
2431 uint8_t vapid
, wcid
;
2434 sc
= ic
->ic_ifp
->if_softc
;
2436 RT2860_DPRINTF(sc
, RT2860_DEBUG_KEY
,
2437 "%s: delete key: keyix=%d, keylen=%d, group=%d\n",
2438 device_get_nameunit(sc
->dev
), k
->wk_keyix
, k
->wk_keylen
,
2439 (k
->wk_flags
& IEEE80211_KEY_GROUP
) ? 1 : 0);
2441 if (k
->wk_flags
& IEEE80211_KEY_GROUP
)
2443 /* remove group key */
2446 wcid
= RT2860_WCID_MCAST
;
2448 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_SKEY_MODE(vapid
));
2450 tmp
&= ~(0xf << (k
->wk_keyix
* 4 + 16 * (vapid
% 2)));
2451 tmp
|= (RT2860_REG_CIPHER_MODE_NONE
<< (k
->wk_keyix
* 4 + 16 * (vapid
% 2)));
2453 rt2860_io_mac_write(sc
, RT2860_REG_SKEY_MODE(vapid
), tmp
);
2455 if (ic
->ic_opmode
== IEEE80211_M_HOSTAP
)
2457 tmp
= ((vapid
& RT2860_REG_VAP_MASK
) << RT2860_REG_VAP_SHIFT
) |
2458 (RT2860_REG_CIPHER_MODE_NONE
<< RT2860_REG_CIPHER_MODE_SHIFT
) | RT2860_REG_PKEY_ENABLE
;
2460 rt2860_io_mac_write(sc
, RT2860_REG_WCID_ATTR(wcid
), tmp
);
2470 static int rt2860_raw_xmit(struct ieee80211_node
*ni
, struct mbuf
*m
,
2471 const struct ieee80211_bpf_params
*params
)
2477 * rt2860_media_change
2479 static int rt2860_media_change(struct ifnet
*ifp
)
2481 struct rt2860_softc
*sc
;
2486 error
= ieee80211_media_change(ifp
);
2487 if (error
!= ENETRESET
)
2490 RT2860_SOFTC_LOCK(sc
);
2492 if ((ifp
->if_flags
& IFF_UP
) && (ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
2494 rt2860_stop_locked(sc
);
2495 rt2860_init_locked(sc
);
2498 RT2860_SOFTC_UNLOCK(sc
);
2506 static struct ieee80211_node
*rt2860_node_alloc(struct ieee80211_node_table
*nt
)
2508 return malloc(sizeof(struct rt2860_softc_node
),
2509 M_80211_NODE
, M_NOWAIT
| M_ZERO
);
2513 * rt2860_node_cleanup
2515 static void rt2860_node_cleanup(struct ieee80211_node
*ni
)
2517 struct rt2860_softc
*sc
;
2518 struct ieee80211com
*ic
;
2520 struct ieee80211_rx_ampdu
*rx_ampdu
;
2521 struct rt2860_softc_node
*rni
;
2522 uint8_t vapid
, wcid
;
2529 rni
= (struct rt2860_softc_node
*) ni
;
2531 RT2860_DPRINTF(sc
, RT2860_DEBUG_NODE
,
2532 "%s: node cleanup: macaddr=%s, associd=0x%04x, staid=0x%02x\n",
2533 device_get_nameunit(sc
->dev
), ether_sprintf(ni
->ni_macaddr
),
2534 ni
->ni_associd
, rni
->staid
);
2536 if (rni
->staid
!= 0)
2541 tmp
= ((vapid
& RT2860_REG_VAP_MASK
) << RT2860_REG_VAP_SHIFT
) |
2542 (RT2860_REG_CIPHER_MODE_NONE
<< RT2860_REG_CIPHER_MODE_SHIFT
) | RT2860_REG_PKEY_ENABLE
;
2544 rt2860_io_mac_write(sc
, RT2860_REG_WCID_ATTR(wcid
), tmp
);
2546 rt2860_io_mac_write(sc
, RT2860_REG_WCID(wcid
), 0xffffffff);
2547 rt2860_io_mac_write(sc
, RT2860_REG_WCID(wcid
) + 4, 0x0000ffff);
2549 rt2860_staid_delete(sc
, rni
->staid
);
2553 for (i
= 0; i
< WME_NUM_TID
; i
++)
2555 rx_ampdu
= &ni
->ni_rx_ampdu
[i
];
2557 if (rx_ampdu
->rxa_flags
& IEEE80211_AGGR_XCHGPEND
)
2558 sc
->rx_ampdu_sessions
--;
2562 sc
->node_cleanup(ni
);
2566 * rt2860_recv_action
2568 static void rt2860_recv_action(struct ieee80211_node
*ni
,
2569 const uint8_t *frm
, const uint8_t *efrm
)
2571 struct rt2860_softc
*sc
;
2572 struct ieee80211com
*ic
;
2574 struct rt2860_softc_node
*rni
;
2575 const struct ieee80211_action
*ia
;
2576 uint16_t baparamset
;
2583 rni
= (struct rt2860_softc_node
*) ni
;
2585 ia
= (const struct ieee80211_action
*) frm
;
2587 if (ia
->ia_category
== IEEE80211_ACTION_CAT_BA
)
2589 switch (ia
->ia_action
)
2591 /* IEEE80211_ACTION_BA_DELBA */
2592 case IEEE80211_ACTION_BA_DELBA
:
2593 baparamset
= LE_READ_2(frm
+ 2);
2594 tid
= RT2860_MS(baparamset
, IEEE80211_BAPS_TID
);
2597 RT2860_DPRINTF(sc
, RT2860_DEBUG_BA
,
2598 "%s: received DELBA request: associd=0x%04x, staid=0x%02x, tid=%d\n",
2599 device_get_nameunit(sc
->dev
), ni
->ni_associd
, rni
->staid
, tid
);
2601 if (rni
->staid
!= 0)
2602 rt2860_asic_del_ba_session(sc
, wcid
, tid
);
2607 sc
->recv_action(ni
, frm
, efrm
);
2611 * rt2860_send_action
2613 static int rt2860_send_action(struct ieee80211_node
*ni
,
2614 int category
, int action
, uint16_t args
[4])
2616 struct rt2860_softc
*sc
;
2617 struct ieee80211com
*ic
;
2619 struct ieee80211_rx_ampdu
*rx_ampdu
;
2620 struct rt2860_softc_node
*rni
;
2621 uint16_t status
, baparamset
;
2628 rni
= (struct rt2860_softc_node
*) ni
;
2632 if (category
== IEEE80211_ACTION_CAT_BA
)
2636 /* IEEE80211_ACTION_BA_ADDBA_RESPONSE */
2637 case IEEE80211_ACTION_BA_ADDBA_RESPONSE
:
2639 baparamset
= args
[2];
2640 tid
= RT2860_MS(baparamset
, IEEE80211_BAPS_TID
);
2641 bufsize
= RT2860_MS(baparamset
, IEEE80211_BAPS_BUFSIZ
);
2642 rx_ampdu
= &ni
->ni_rx_ampdu
[tid
];
2644 RT2860_DPRINTF(sc
, RT2860_DEBUG_BA
,
2645 "%s: sending ADDBA response: associd=0x%04x, staid=0x%02x, status=%d, tid=%d, bufsize=%d\n",
2646 device_get_nameunit(sc
->dev
), ni
->ni_associd
, rni
->staid
, status
, tid
, bufsize
);
2648 if (status
== IEEE80211_STATUS_SUCCESS
)
2650 rt2860_asic_add_ba_session(sc
, wcid
, tid
);
2652 if (!(rx_ampdu
->rxa_flags
& IEEE80211_AGGR_XCHGPEND
))
2653 sc
->rx_ampdu_sessions
++;
2657 /* IEEE80211_ACTION_BA_DELBA */
2658 case IEEE80211_ACTION_BA_DELBA
:
2659 baparamset
= RT2860_SM(args
[0], IEEE80211_DELBAPS_TID
) | args
[1];
2660 tid
= RT2860_MS(baparamset
, IEEE80211_DELBAPS_TID
);
2661 rx_ampdu
= &ni
->ni_rx_ampdu
[tid
];
2663 RT2860_DPRINTF(sc
, RT2860_DEBUG_BA
,
2664 "%s: sending DELBA request: associd=0x%04x, staid=0x%02x, tid=%d\n",
2665 device_get_nameunit(sc
->dev
), ni
->ni_associd
, rni
->staid
, tid
);
2667 if (RT2860_MS(baparamset
, IEEE80211_DELBAPS_INIT
) != IEEE80211_DELBAPS_INIT
)
2669 rt2860_asic_del_ba_session(sc
, wcid
, tid
);
2671 if (rx_ampdu
->rxa_flags
& IEEE80211_AGGR_XCHGPEND
)
2672 sc
->rx_ampdu_sessions
--;
2678 return sc
->send_action(ni
, category
, action
, args
);
2683 * rt2860_addba_response
2685 static int rt2860_addba_response(struct ieee80211_node
*ni
,
2686 struct ieee80211_tx_ampdu
*tap
,
2687 int status
, int baparamset
, int batimeout
)
2689 struct rt2860_softc
*sc
;
2690 struct ieee80211com
*ic
;
2692 struct rt2860_softc_node
*rni
;
2693 ieee80211_seq seqno
;
2694 int ret
, tid
, old_bufsize
, new_bufsize
;
2699 rni
= (struct rt2860_softc_node
*) ni
;
2701 tid
= RT2860_MS(baparamset
, IEEE80211_BAPS_TID
);
2702 old_bufsize
= RT2860_MS(baparamset
, IEEE80211_BAPS_BUFSIZ
);
2703 new_bufsize
= old_bufsize
;
2705 if (status
== IEEE80211_STATUS_SUCCESS
)
2707 if (sc
->mac_rev
>= 0x28830300)
2709 if (sc
->mac_rev
>= 0x30700200)
2714 else if (sc
->mac_rev
>= 0x28720200)
2723 if (old_bufsize
> new_bufsize
)
2725 baparamset
&= ~IEEE80211_BAPS_BUFSIZ
;
2726 baparamset
= RT2860_SM(new_bufsize
, IEEE80211_BAPS_BUFSIZ
);
2729 if (!(tap
->txa_flags
& IEEE80211_AGGR_RUNNING
))
2731 sc
->tx_ampdu_sessions
++;
2733 if (sc
->tx_ampdu_sessions
== 1)
2734 rt2860_asic_updateprot(sc
);
2738 RT2860_DPRINTF(sc
, RT2860_DEBUG_BA
,
2739 "%s: received ADDBA response: associd=0x%04x, staid=0x%02x, status=%d, tid=%d, "
2740 "old bufsize=%d, new bufsize=%d\n",
2741 device_get_nameunit(sc
->dev
), ni
->ni_associd
, rni
->staid
, status
, tid
,
2742 old_bufsize
, new_bufsize
);
2744 ret
= sc
->addba_response(ni
, tap
, status
, baparamset
, batimeout
);
2746 if (status
== IEEE80211_STATUS_SUCCESS
)
2748 seqno
= ni
->ni_txseqs
[tid
];
2750 rt2860_send_bar(ni
, tap
, seqno
);
2759 static void rt2860_addba_stop(struct ieee80211_node
*ni
,
2760 struct ieee80211_tx_ampdu
*tap
)
2762 struct rt2860_softc
*sc
;
2763 struct ieee80211com
*ic
;
2765 struct rt2860_softc_node
*rni
;
2771 rni
= (struct rt2860_softc_node
*) ni
;
2773 tid
= WME_AC_TO_TID(tap
->txa_ac
);
2775 RT2860_DPRINTF(sc
, RT2860_DEBUG_BA
,
2776 "%s: stopping A-MPDU Tx: associd=0x%04x, staid=0x%02x, tid=%d\n",
2777 device_get_nameunit(sc
->dev
), ni
->ni_associd
, rni
->staid
, tid
);
2779 if (tap
->txa_flags
& IEEE80211_AGGR_RUNNING
)
2781 if (sc
->tx_ampdu_sessions
> 0)
2783 sc
->tx_ampdu_sessions
--;
2785 if (sc
->tx_ampdu_sessions
== 0)
2786 rt2860_asic_updateprot(sc
);
2790 printf("%s: number of A-MPDU Tx sessions cannot be negative\n",
2791 device_get_nameunit(sc
->dev
));
2795 sc
->addba_stop(ni
, tap
);
2801 static int rt2860_send_bar(struct ieee80211_node
*ni
,
2802 struct ieee80211_tx_ampdu
*tap
, ieee80211_seq seqno
)
2804 struct rt2860_softc
*sc
;
2805 struct ieee80211com
*ic
;
2807 struct ieee80211_frame_bar
*bar
;
2808 struct rt2860_softc_node
*rni
;
2810 uint16_t barctl
, barseqctl
;
2817 rni
= (struct rt2860_softc_node
*) ni
;
2819 if (!(tap
->txa_flags
& IEEE80211_AGGR_RUNNING
))
2822 m
= ieee80211_getmgtframe(&frm
, ic
->ic_headroom
, sizeof(struct ieee80211_frame_bar
));
2826 bar
= mtod(m
, struct ieee80211_frame_bar
*);
2828 bar
->i_fc
[0] = IEEE80211_FC0_VERSION_0
| IEEE80211_FC0_TYPE_CTL
| IEEE80211_FC0_SUBTYPE_BAR
;
2831 IEEE80211_ADDR_COPY(bar
->i_ra
, ni
->ni_macaddr
);
2832 IEEE80211_ADDR_COPY(bar
->i_ta
, ic
->ic_myaddr
);
2834 tid
= WME_AC_TO_TID(tap
->txa_ac
);
2836 barctl
= (tap
->txa_flags
& IEEE80211_AGGR_IMMEDIATE
? 0 : IEEE80211_BAR_NOACK
) |
2837 IEEE80211_BAR_COMP
|
2838 RT2860_SM(tid
, IEEE80211_BAR_TID
);
2839 barseqctl
= RT2860_SM(seqno
, IEEE80211_BASEQ_START
);
2841 bar
->i_ctl
= htole16(barctl
);
2842 bar
->i_seq
= htole16(barseqctl
);
2844 m
->m_pkthdr
.len
= m
->m_len
= sizeof(struct ieee80211_frame_bar
);
2845 m
->m_pkthdr
.rcvif
= (void *) ni
;
2847 tap
->txa_start
= seqno
;
2849 ieee80211_ref_node(ni
);
2851 RT2860_DPRINTF(sc
, RT2860_DEBUG_BA
,
2852 "%s: sending BAR: associd=0x%04x, staid=0x%02x, tid=%d, seqno=%d\n",
2853 device_get_nameunit(sc
->dev
), ni
->ni_associd
, rni
->staid
, tid
, seqno
);
2855 IF_ENQUEUE(&ic
->ic_mgtq
, m
);
2863 * rt2860_amrr_update_iter_func
2865 static void rt2860_amrr_update_iter_func(void *arg
, struct ieee80211_node
*ni
)
2867 struct rt2860_softc
*sc
;
2868 struct ieee80211com
*ic
;
2869 struct rt2860_softc_node
*rni
;
2874 rni
= (struct rt2860_softc_node
*) ni
;
2876 /* only associated stations */
2878 if (rni
->staid
!= 0)
2882 RT2860_DPRINTF(sc
, RT2860_DEBUG_RATE
,
2883 "%s: AMRR node: staid=0x%02x, txcnt=%d, success=%d, retrycnt=%d\n",
2884 device_get_nameunit(sc
->dev
),
2885 rni
->staid
, sc
->amrr_node
[wcid
].txcnt
, sc
->amrr_node
[wcid
].success
, sc
->amrr_node
[wcid
].retrycnt
);
2887 rt2860_amrr_choose(ni
, &sc
->amrr_node
[wcid
]);
2889 RT2860_DPRINTF(sc
, RT2860_DEBUG_RATE
,
2890 "%s:%s node Tx rate: associd=0x%04x, staid=0x%02x, rate=0x%02x, max rate=0x%02x\n",
2891 device_get_nameunit(sc
->dev
),
2892 (ni
->ni_flags
& IEEE80211_NODE_HT
) ? " HT" : "",
2893 ni
->ni_associd
, rni
->staid
,
2894 (ni
->ni_flags
& IEEE80211_NODE_HT
) ?
2895 (ni
->ni_htrates
.rs_rates
[ni
->ni_txrate
] | IEEE80211_RATE_MCS
) :
2896 (ni
->ni_rates
.rs_rates
[ni
->ni_txrate
] & IEEE80211_RATE_VAL
),
2897 (ni
->ni_flags
& IEEE80211_NODE_HT
) ?
2898 (ni
->ni_htrates
.rs_rates
[ni
->ni_htrates
.rs_nrates
- 1] | IEEE80211_RATE_MCS
) :
2899 (ni
->ni_rates
.rs_rates
[ni
->ni_rates
.rs_nrates
- 1] & IEEE80211_RATE_VAL
));
2906 static void rt2860_periodic(void *arg
)
2908 struct rt2860_softc
*sc
;
2912 RT2860_DPRINTF(sc
, RT2860_DEBUG_PERIODIC
,
2914 device_get_nameunit(sc
->dev
));
2916 taskqueue_enqueue(sc
->taskqueue
, &sc
->periodic_task
);
2920 * rt2860_tx_watchdog
2922 static void rt2860_tx_watchdog(void *arg
)
2924 struct rt2860_softc
*sc
;
2930 if (sc
->tx_timer
== 0)
2933 if (--sc
->tx_timer
== 0)
2935 printf("%s: Tx watchdog timeout: resetting\n",
2936 device_get_nameunit(sc
->dev
));
2938 rt2860_stop_locked(sc
);
2939 rt2860_init_locked(sc
);
2943 sc
->tx_watchdog_timeouts
++;
2946 callout_reset(&sc
->tx_watchdog_ch
, hz
, rt2860_tx_watchdog
, sc
);
2950 * rt2860_staid_alloc
2952 static int rt2860_staid_alloc(struct rt2860_softc
*sc
, int aid
)
2956 if ((aid
> 0 && aid
< RT2860_SOFTC_STAID_COUNT
) && isclr(sc
->staid_mask
, aid
))
2962 for (staid
= 1; staid
< RT2860_SOFTC_STAID_COUNT
; staid
++)
2964 if (isclr(sc
->staid_mask
, staid
))
2969 setbit(sc
->staid_mask
, staid
);
2975 * rt2860_staid_delete
2977 static void rt2860_staid_delete(struct rt2860_softc
*sc
, int staid
)
2979 clrbit(sc
->staid_mask
, staid
);
2983 * rt2860_asic_set_bssid
2985 static void rt2860_asic_set_bssid(struct rt2860_softc
*sc
,
2986 const uint8_t *bssid
)
2990 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATE
,
2991 "%s: set bssid: bssid=%s\n",
2992 device_get_nameunit(sc
->dev
), ether_sprintf(bssid
));
2994 tmp
= bssid
[0] | (bssid
[1]) << 8 | (bssid
[2] << 16) | (bssid
[3] << 24);
2996 rt2860_io_mac_write(sc
, RT2860_REG_BSSID_DW0
, tmp
);
2998 tmp
= bssid
[4] | (bssid
[5] << 8);
3000 rt2860_io_mac_write(sc
, RT2860_REG_BSSID_DW1
, tmp
);
3004 * rt2860_asic_set_macaddr
3006 static void rt2860_asic_set_macaddr(struct rt2860_softc
*sc
,
3007 const uint8_t *addr
)
3011 tmp
= addr
[0] | (addr
[1] << 8) | (addr
[2] << 16) | (addr
[3] << 24);
3013 rt2860_io_mac_write(sc
, RT2860_REG_ADDR_DW0
, tmp
);
3015 tmp
= addr
[4] | (addr
[5] << 8) | (0xff << 16);
3017 rt2860_io_mac_write(sc
, RT2860_REG_ADDR_DW1
, tmp
);
3021 * rt2860_asic_enable_tsf_sync
3023 static void rt2860_asic_enable_tsf_sync(struct rt2860_softc
*sc
)
3025 struct ieee80211com
*ic
;
3030 RT2860_DPRINTF(sc
, RT2860_DEBUG_BEACON
,
3031 "%s: enabling TSF\n",
3032 device_get_nameunit(sc
->dev
));
3034 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_BCN_TIME_CFG
);
3037 tmp
|= ic
->ic_bss
->ni_intval
* 16;
3038 tmp
|= (RT2860_REG_TSF_TIMER_ENABLE
| RT2860_REG_TBTT_TIMER_ENABLE
);
3040 if (ic
->ic_opmode
== IEEE80211_M_STA
)
3042 tmp
|= (RT2860_REG_TSF_SYNC_MODE_STA
<< RT2860_REG_TSF_SYNC_MODE_SHIFT
);
3044 else if (ic
->ic_opmode
== IEEE80211_M_IBSS
)
3046 tmp
|= RT2860_REG_BCN_TX_ENABLE
;
3047 tmp
|= (RT2860_REG_TSF_SYNC_MODE_IBSS
<< RT2860_REG_TSF_SYNC_MODE_SHIFT
);
3049 else if (ic
->ic_opmode
== IEEE80211_M_HOSTAP
)
3051 tmp
|= RT2860_REG_BCN_TX_ENABLE
;
3052 tmp
|= (RT2860_REG_TSF_SYNC_MODE_HOSTAP
<< RT2860_REG_TSF_SYNC_MODE_SHIFT
);
3055 rt2860_io_mac_write(sc
, RT2860_REG_BCN_TIME_CFG
, tmp
);
3059 * rt2860_asic_disable_tsf_sync
3061 static void rt2860_asic_disable_tsf_sync(struct rt2860_softc
*sc
)
3065 RT2860_DPRINTF(sc
, RT2860_DEBUG_BEACON
,
3066 "%s: disabling TSF\n",
3067 device_get_nameunit(sc
->dev
));
3069 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_BCN_TIME_CFG
);
3071 tmp
&= ~(RT2860_REG_BCN_TX_ENABLE
|
3072 RT2860_REG_TSF_TIMER_ENABLE
|
3073 RT2860_REG_TBTT_TIMER_ENABLE
);
3075 tmp
&= ~(RT2860_REG_TSF_SYNC_MODE_MASK
<< RT2860_REG_TSF_SYNC_MODE_SHIFT
);
3076 tmp
|= (RT2860_REG_TSF_SYNC_MODE_DISABLE
<< RT2860_REG_TSF_SYNC_MODE_SHIFT
);
3078 rt2860_io_mac_write(sc
, RT2860_REG_BCN_TIME_CFG
, tmp
);
3082 * rt2860_asic_enable_mrr
3084 static void rt2860_asic_enable_mrr(struct rt2860_softc
*sc
)
3086 #define CCK(mcs) (mcs)
3087 #define OFDM(mcs) ((1 << 3) | (mcs))
3088 #define HT(mcs) (mcs)
3090 rt2860_io_mac_write(sc
, RT2860_REG_TX_LG_FBK_CFG0
,
3091 (OFDM(6) << 28) | /* 54 -> 48 */
3092 (OFDM(5) << 24) | /* 48 -> 36 */
3093 (OFDM(4) << 20) | /* 36 -> 24 */
3094 (OFDM(3) << 16) | /* 24 -> 18 */
3095 (OFDM(2) << 12) | /* 18 -> 12 */
3096 (OFDM(1) << 8) | /* 12 -> 9 */
3097 (OFDM(0) << 4) | /* 9 -> 6 */
3098 OFDM(0)); /* 6 -> 6 */
3100 rt2860_io_mac_write(sc
, RT2860_REG_TX_LG_FBK_CFG1
,
3101 (CCK(2) << 12) | /* 11 -> 5.5 */
3102 (CCK(1) << 8) | /* 5.5 -> 2 */
3103 (CCK(0) << 4) | /* 2 -> 1 */
3104 CCK(0)); /* 1 -> 1 */
3106 rt2860_io_mac_write(sc
, RT2860_REG_TX_HT_FBK_CFG0
,
3116 rt2860_io_mac_write(sc
, RT2860_REG_TX_HT_FBK_CFG1
,
3132 * rt2860_asic_set_txpreamble
3134 static void rt2860_asic_set_txpreamble(struct rt2860_softc
*sc
)
3136 struct ieee80211com
*ic
;
3141 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATE
,
3142 "%s: %s short Tx preamble\n",
3143 device_get_nameunit(sc
->dev
),
3144 (ic
->ic_flags
& IEEE80211_F_SHPREAMBLE
) ? "enabling" : "disabling");
3146 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_AUTO_RSP_CFG
);
3148 tmp
&= ~RT2860_REG_CCK_SHORT_ENABLE
;
3150 if (sc
->ic
.ic_flags
& IEEE80211_F_SHPREAMBLE
)
3151 tmp
|= RT2860_REG_CCK_SHORT_ENABLE
;
3153 rt2860_io_mac_write(sc
, RT2860_REG_AUTO_RSP_CFG
, tmp
);
3157 * rt2860_asic_set_basicrates
3159 static void rt2860_asic_set_basicrates(struct rt2860_softc
*sc
)
3161 struct ieee80211com
*ic
;
3165 if (ic
->ic_curmode
== IEEE80211_MODE_11B
)
3166 rt2860_io_mac_write(sc
, RT2860_REG_LEGACY_BASIC_RATE
, 0xf);
3167 else if (ic
->ic_curmode
== IEEE80211_MODE_11A
)
3168 rt2860_io_mac_write(sc
, RT2860_REG_LEGACY_BASIC_RATE
, 0x150);
3170 rt2860_io_mac_write(sc
, RT2860_REG_LEGACY_BASIC_RATE
, 0x15f);
3174 * rt2860_asic_update_rtsthreshold
3176 static void rt2860_asic_update_rtsthreshold(struct rt2860_softc
*sc
)
3178 struct ieee80211com
*ic
;
3184 RT2860_DPRINTF(sc
, RT2860_DEBUG_PROT
,
3185 "%s: updating RTS threshold: %d\n",
3186 device_get_nameunit(sc
->dev
), ic
->ic_rtsthreshold
);
3188 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_RTS_CFG
);
3190 tmp
&= ~(RT2860_REG_TX_RTS_THRESHOLD_MASK
<< RT2860_REG_TX_RTS_THRESHOLD_SHIFT
);
3192 if (ic
->ic_flags_ext
& IEEE80211_FEXT_AMSDU_TX
)
3195 threshold
= ic
->ic_rtsthreshold
;
3198 tmp
|= ((threshold
& RT2860_REG_TX_RTS_THRESHOLD_MASK
) <<
3199 RT2860_REG_TX_RTS_THRESHOLD_SHIFT
);
3201 rt2860_io_mac_write(sc
, RT2860_REG_TX_RTS_CFG
, tmp
);
3205 * rt2860_asic_update_txpower
3207 static void rt2860_asic_update_txpower(struct rt2860_softc
*sc
)
3209 struct ieee80211com
*ic
;
3210 uint32_t *txpow_rate
;
3218 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATE
,
3219 "%s: updating Tx power: %d\n",
3220 device_get_nameunit(sc
->dev
), ic
->ic_txpowlimit
);
3222 if (!IEEE80211_IS_CHAN_HT40(ic
->ic_curchan
))
3224 txpow_rate
= sc
->txpow_rate_20mhz
;
3228 if (IEEE80211_IS_CHAN_2GHZ(ic
->ic_curchan
))
3229 txpow_rate
= sc
->txpow_rate_40mhz_2ghz
;
3231 txpow_rate
= sc
->txpow_rate_40mhz_5ghz
;
3236 val
= rt2860_io_bbp_read(sc
, 1);
3239 if (ic
->ic_txpowlimit
> 90)
3243 else if (ic
->ic_txpowlimit
> 60)
3247 else if (ic
->ic_txpowlimit
> 30)
3251 else if (ic
->ic_txpowlimit
> 15)
3255 else if (ic
->ic_txpowlimit
> 9)
3265 rt2860_io_bbp_write(sc
, 1, val
);
3267 for (i
= 0; i
< RT2860_SOFTC_TXPOW_RATE_COUNT
; i
++)
3269 if (txpow_rate
[i
] == 0xffffffff)
3272 tmp
= rt2860_read_eeprom_txpow_rate_add_delta(txpow_rate
[i
], delta
);
3274 rt2860_io_mac_write(sc
, RT2860_REG_TX_PWR_CFG(i
), tmp
);
3279 * rt2860_asic_update_promisc
3281 static void rt2860_asic_update_promisc(struct rt2860_softc
*sc
)
3286 ifp
= sc
->ic
.ic_ifp
;
3288 printf("%s: %s promiscuous mode\n",
3289 device_get_nameunit(sc
->dev
),
3290 (ifp
->if_flags
& IFF_PROMISC
) ? "entering" : "leaving");
3292 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_RX_FILTER_CFG
);
3294 tmp
&= ~RT2860_REG_RX_FILTER_DROP_UC_NOME
;
3296 if (!(ifp
->if_flags
& IFF_PROMISC
))
3297 tmp
|= RT2860_REG_RX_FILTER_DROP_UC_NOME
;
3299 rt2860_io_mac_write(sc
, RT2860_REG_RX_FILTER_CFG
, tmp
);
3303 * rt2860_asic_updateprot
3305 static void rt2860_asic_updateprot(struct rt2860_softc
*sc
)
3307 struct ieee80211com
*ic
;
3308 uint32_t cck_prot
, ofdm_prot
, mm20_prot
, mm40_prot
, gf20_prot
, gf40_prot
;
3310 enum ieee80211_protmode htprotmode
;
3314 /* CCK frame protection */
3316 cck_prot
= RT2860_REG_RTSTH_ENABLE
| RT2860_REG_PROT_NAV_SHORT
|
3317 RT2860_REG_TXOP_ALLOW_ALL
| RT2860_REG_PROT_CTRL_NONE
;
3319 /* set up protection frame phy mode and rate (MCS code) */
3321 if (ic
->ic_curmode
== IEEE80211_MODE_11A
)
3322 cck_prot
|= (RT2860_REG_PROT_PHYMODE_OFDM
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3323 (0 << RT2860_REG_PROT_MCS_SHIFT
);
3325 cck_prot
|= ((RT2860_REG_PROT_PHYMODE_CCK
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3326 (3 << RT2860_REG_PROT_MCS_SHIFT
));
3328 rt2860_io_mac_write(sc
, RT2860_REG_TX_CCK_PROT_CFG
, cck_prot
);
3330 /* OFDM frame protection */
3332 ofdm_prot
= RT2860_REG_RTSTH_ENABLE
| RT2860_REG_PROT_NAV_SHORT
|
3333 RT2860_REG_TXOP_ALLOW_ALL
;
3335 if (ic
->ic_flags
& IEEE80211_F_USEPROT
)
3337 RT2860_DPRINTF(sc
, RT2860_DEBUG_PROT
,
3338 "%s: updating protection mode: b/g protection mode=%s\n",
3339 device_get_nameunit(sc
->dev
),
3340 (ic
->ic_protmode
== IEEE80211_PROT_RTSCTS
) ? "RTS/CTS" :
3341 ((ic
->ic_protmode
== IEEE80211_PROT_CTSONLY
) ? "CTS-to-self" : "none"));
3343 if (ic
->ic_protmode
== IEEE80211_PROT_RTSCTS
)
3344 ofdm_prot
|= RT2860_REG_PROT_CTRL_RTS_CTS
;
3345 else if (ic
->ic_protmode
== IEEE80211_PROT_CTSONLY
)
3346 ofdm_prot
|= RT2860_REG_PROT_CTRL_CTS
;
3348 ofdm_prot
|= RT2860_REG_PROT_CTRL_NONE
;
3352 RT2860_DPRINTF(sc
, RT2860_DEBUG_PROT
,
3353 "%s: updating protection mode: b/g protection mode=%s\n",
3354 device_get_nameunit(sc
->dev
), "none");
3356 ofdm_prot
|= RT2860_REG_PROT_CTRL_NONE
;
3359 rt2860_io_mac_write(sc
, RT2860_REG_TX_OFDM_PROT_CFG
, ofdm_prot
);
3361 /* HT frame protection */
3363 if ((ic
->ic_opmode
== IEEE80211_M_STA
) && (ic
->ic_state
== IEEE80211_S_RUN
))
3364 htopmode
= ic
->ic_bss
->ni_htopmode
;
3366 htopmode
= ic
->ic_curhtprotmode
;
3368 htprotmode
= ic
->ic_htprotmode
;
3370 /* force HT mixed mode and RTS/CTS protection if A-MPDU Tx aggregation is enabled */
3372 if (sc
->tx_ampdu_sessions
> 0)
3374 RT2860_DPRINTF(sc
, RT2860_DEBUG_PROT
,
3375 "%s: updating protection mode: forcing HT mixed mode and RTS/CTS protection\n",
3376 device_get_nameunit(sc
->dev
));
3378 htopmode
= IEEE80211_HTINFO_OPMODE_MIXED
;
3379 htprotmode
= IEEE80211_PROT_RTSCTS
;
3382 RT2860_DPRINTF(sc
, RT2860_DEBUG_PROT
,
3383 "%s: updating protection mode: HT operation mode=0x%02x, protection mode=%s\n",
3384 device_get_nameunit(sc
->dev
),
3385 htopmode
& IEEE80211_HTINFO_OPMODE
,
3386 (htprotmode
== IEEE80211_PROT_RTSCTS
) ? "RTS/CTS" :
3387 ((htprotmode
== IEEE80211_PROT_CTSONLY
) ? "CTS-to-self" : "none"));
3389 switch (htopmode
& IEEE80211_HTINFO_OPMODE
)
3391 /* IEEE80211_HTINFO_OPMODE_HT20PR */
3392 case IEEE80211_HTINFO_OPMODE_HT20PR
:
3393 mm20_prot
= RT2860_REG_PROT_NAV_SHORT
| RT2860_REG_PROT_CTRL_NONE
|
3394 RT2860_REG_TXOP_ALLOW_CCK
| RT2860_REG_TXOP_ALLOW_OFDM
|
3395 RT2860_REG_TXOP_ALLOW_MM20
| RT2860_REG_TXOP_ALLOW_GF20
|
3396 (RT2860_REG_PROT_PHYMODE_OFDM
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3397 (4 << RT2860_REG_PROT_MCS_SHIFT
);
3399 gf20_prot
= mm20_prot
;
3401 mm40_prot
= RT2860_REG_PROT_NAV_SHORT
| RT2860_REG_TXOP_ALLOW_ALL
|
3402 (RT2860_REG_PROT_PHYMODE_OFDM
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3403 (0x84 << RT2860_REG_PROT_MCS_SHIFT
);
3405 if (htprotmode
== IEEE80211_PROT_RTSCTS
)
3406 mm40_prot
|= RT2860_REG_PROT_CTRL_RTS_CTS
;
3407 else if (htprotmode
== IEEE80211_PROT_CTSONLY
)
3408 mm40_prot
|= RT2860_REG_PROT_CTRL_CTS
;
3410 mm40_prot
|= RT2860_REG_PROT_CTRL_NONE
;
3412 gf40_prot
= mm40_prot
;
3415 /* IEEE80211_HTINFO_OPMODE_MIXED */
3416 case IEEE80211_HTINFO_OPMODE_MIXED
:
3417 mm20_prot
= RT2860_REG_PROT_NAV_SHORT
|
3418 RT2860_REG_TXOP_ALLOW_CCK
| RT2860_REG_TXOP_ALLOW_OFDM
|
3419 RT2860_REG_TXOP_ALLOW_MM20
| RT2860_REG_TXOP_ALLOW_GF20
;
3421 if (ic
->ic_flags
& IEEE80211_F_USEPROT
)
3422 mm20_prot
|= (RT2860_REG_PROT_PHYMODE_CCK
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3423 (3 << RT2860_REG_PROT_MCS_SHIFT
);
3425 mm20_prot
|= (RT2860_REG_PROT_PHYMODE_OFDM
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3426 (4 << RT2860_REG_PROT_MCS_SHIFT
);
3428 if (htprotmode
== IEEE80211_PROT_RTSCTS
)
3429 mm20_prot
|= RT2860_REG_PROT_CTRL_RTS_CTS
;
3430 else if (htprotmode
== IEEE80211_PROT_CTSONLY
)
3431 mm20_prot
|= RT2860_REG_PROT_CTRL_CTS
;
3433 mm20_prot
|= RT2860_REG_PROT_CTRL_NONE
;
3435 gf20_prot
= mm20_prot
;
3437 mm40_prot
= RT2860_REG_PROT_NAV_SHORT
| RT2860_REG_TXOP_ALLOW_ALL
;
3439 if (ic
->ic_flags
& IEEE80211_F_USEPROT
)
3440 mm40_prot
|= (RT2860_REG_PROT_PHYMODE_CCK
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3441 (3 << RT2860_REG_PROT_MCS_SHIFT
);
3443 mm40_prot
|= (RT2860_REG_PROT_PHYMODE_OFDM
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3444 (0x84 << RT2860_REG_PROT_MCS_SHIFT
);
3446 if (htprotmode
== IEEE80211_PROT_RTSCTS
)
3447 mm40_prot
|= RT2860_REG_PROT_CTRL_RTS_CTS
;
3448 else if (htprotmode
== IEEE80211_PROT_CTSONLY
)
3449 mm40_prot
|= RT2860_REG_PROT_CTRL_CTS
;
3451 mm40_prot
|= RT2860_REG_PROT_CTRL_NONE
;
3453 gf40_prot
= mm40_prot
;
3457 * IEEE80211_HTINFO_OPMODE_PURE
3458 * IEEE80211_HTINFO_OPMODE_PROTOPT
3460 case IEEE80211_HTINFO_OPMODE_PURE
:
3461 case IEEE80211_HTINFO_OPMODE_PROTOPT
:
3463 mm20_prot
= RT2860_REG_PROT_NAV_SHORT
| RT2860_REG_PROT_CTRL_NONE
|
3464 RT2860_REG_TXOP_ALLOW_CCK
| RT2860_REG_TXOP_ALLOW_OFDM
|
3465 RT2860_REG_TXOP_ALLOW_MM20
| RT2860_REG_TXOP_ALLOW_GF20
|
3466 (RT2860_REG_PROT_PHYMODE_OFDM
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3467 (4 << RT2860_REG_PROT_MCS_SHIFT
);
3469 gf20_prot
= mm20_prot
;
3471 mm40_prot
= RT2860_REG_PROT_NAV_SHORT
| RT2860_REG_PROT_CTRL_NONE
|
3472 RT2860_REG_TXOP_ALLOW_ALL
|
3473 (RT2860_REG_PROT_PHYMODE_OFDM
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3474 (0x84 << RT2860_REG_PROT_MCS_SHIFT
);
3476 gf40_prot
= mm40_prot
;
3480 rt2860_io_mac_write(sc
, RT2860_REG_TX_MM20_PROT_CFG
, mm20_prot
);
3481 rt2860_io_mac_write(sc
, RT2860_REG_TX_MM40_PROT_CFG
, mm40_prot
);
3482 rt2860_io_mac_write(sc
, RT2860_REG_TX_GF20_PROT_CFG
, gf20_prot
);
3483 rt2860_io_mac_write(sc
, RT2860_REG_TX_GF40_PROT_CFG
, gf40_prot
);
3487 * rt2860_asic_updateslot
3489 static void rt2860_asic_updateslot(struct rt2860_softc
*sc
)
3491 struct ieee80211com
*ic
;
3496 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATE
,
3497 "%s: %s short slot time\n",
3498 device_get_nameunit(sc
->dev
),
3499 (ic
->ic_flags
& (IEEE80211_F_SHSLOT
| IEEE80211_F_BURST
)) ? "enabling" : "disabling");
3501 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_BKOFF_SLOT_CFG
);
3504 tmp
|= (ic
->ic_flags
& (IEEE80211_F_SHSLOT
|IEEE80211_F_BURST
)) ? 9 : 20;
3506 rt2860_io_mac_write(sc
, RT2860_REG_BKOFF_SLOT_CFG
, tmp
);
3510 * rt2860_asic_wme_update
3512 static void rt2860_asic_wme_update(struct rt2860_softc
*sc
)
3514 struct ieee80211com
*ic
;
3515 struct ieee80211_wme_state
*wme
;
3516 const struct wmeParams
*wmep
;
3521 wmep
= wme
->wme_chanParams
.cap_wmeParams
;
3523 RT2860_DPRINTF(sc
, RT2860_DEBUG_WME
,
3524 "%s: wme update: WME_AC_VO=%d/%d/%d/%d, WME_AC_VI=%d/%d/%d/%d, "
3525 "WME_AC_BK=%d/%d/%d/%d, WME_AC_BE=%d/%d/%d/%d\n",
3526 device_get_nameunit(sc
->dev
),
3527 wmep
[WME_AC_VO
].wmep_aifsn
,
3528 wmep
[WME_AC_VO
].wmep_logcwmin
, wmep
[WME_AC_VO
].wmep_logcwmax
,
3529 wmep
[WME_AC_VO
].wmep_txopLimit
,
3530 wmep
[WME_AC_VI
].wmep_aifsn
,
3531 wmep
[WME_AC_VI
].wmep_logcwmin
, wmep
[WME_AC_VI
].wmep_logcwmax
,
3532 wmep
[WME_AC_VI
].wmep_txopLimit
,
3533 wmep
[WME_AC_BK
].wmep_aifsn
,
3534 wmep
[WME_AC_BK
].wmep_logcwmin
, wmep
[WME_AC_BK
].wmep_logcwmax
,
3535 wmep
[WME_AC_BK
].wmep_txopLimit
,
3536 wmep
[WME_AC_BE
].wmep_aifsn
,
3537 wmep
[WME_AC_BE
].wmep_logcwmin
, wmep
[WME_AC_BE
].wmep_logcwmax
,
3538 wmep
[WME_AC_BE
].wmep_txopLimit
);
3540 for (i
= 0; i
< WME_NUM_AC
; i
++)
3541 rt2860_io_mac_write(sc
, RT2860_REG_TX_EDCA_AC_CFG(i
),
3542 (wmep
[i
].wmep_logcwmax
<< 16) | (wmep
[i
].wmep_logcwmin
<< 12) |
3543 (wmep
[i
].wmep_aifsn
<< 8) | wmep
[i
].wmep_txopLimit
);
3545 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WMM_AIFSN_CFG
,
3546 (wmep
[WME_AC_VO
].wmep_aifsn
<< 12) | (wmep
[WME_AC_VI
].wmep_aifsn
<< 8) |
3547 (wmep
[WME_AC_BK
].wmep_aifsn
<< 4) | wmep
[WME_AC_BE
].wmep_aifsn
);
3549 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WMM_CWMIN_CFG
,
3550 (wmep
[WME_AC_VO
].wmep_logcwmin
<< 12) | (wmep
[WME_AC_VI
].wmep_logcwmin
<< 8) |
3551 (wmep
[WME_AC_BK
].wmep_logcwmin
<< 4) | wmep
[WME_AC_BE
].wmep_logcwmin
);
3553 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WMM_CWMAX_CFG
,
3554 (wmep
[WME_AC_VO
].wmep_logcwmax
<< 12) | (wmep
[WME_AC_VI
].wmep_logcwmax
<< 8) |
3555 (wmep
[WME_AC_BK
].wmep_logcwmax
<< 4) | wmep
[WME_AC_BE
].wmep_logcwmax
);
3557 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WMM_TXOP0_CFG
,
3558 (wmep
[WME_AC_BK
].wmep_txopLimit
<< 16) | wmep
[WME_AC_BE
].wmep_txopLimit
);
3560 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WMM_TXOP1_CFG
,
3561 (wmep
[WME_AC_VO
].wmep_txopLimit
<< 16) | wmep
[WME_AC_VI
].wmep_txopLimit
);
3565 * rt2860_asic_update_beacon
3567 static void rt2860_asic_update_beacon(struct rt2860_softc
*sc
)
3569 struct ieee80211com
*ic
;
3571 struct rt2860_txwi
*txwi
;
3576 m
= sc
->beacon_mbuf
;
3577 txwi
= &sc
->beacon_txwi
;
3579 /* disable temporarily TSF sync */
3581 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_BCN_TIME_CFG
);
3583 tmp
&= ~(RT2860_REG_BCN_TX_ENABLE
|
3584 RT2860_REG_TSF_TIMER_ENABLE
|
3585 RT2860_REG_TBTT_TIMER_ENABLE
);
3587 rt2860_io_mac_write(sc
, RT2860_REG_BCN_TIME_CFG
, tmp
);
3589 /* write Tx wireless info and beacon frame to on-chip memory */
3591 rt2860_io_mac_write_multi(sc
, RT2860_REG_BEACON_BASE(0),
3592 txwi
, sizeof(struct rt2860_txwi
));
3594 rt2860_io_mac_write_multi(sc
, RT2860_REG_BEACON_BASE(0) + sizeof(struct rt2860_txwi
),
3595 mtod(m
, uint8_t *), m
->m_pkthdr
.len
);
3597 /* enable again TSF sync */
3599 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_BCN_TIME_CFG
);
3601 tmp
|= (RT2860_REG_BCN_TX_ENABLE
|
3602 RT2860_REG_TSF_TIMER_ENABLE
|
3603 RT2860_REG_TBTT_TIMER_ENABLE
);
3605 rt2860_io_mac_write(sc
, RT2860_REG_BCN_TIME_CFG
, tmp
);
3609 * rt2860_asic_clear_keytables
3611 static void rt2860_asic_clear_keytables(struct rt2860_softc
*sc
)
3615 /* clear Rx WCID search table (entries = 256, entry size = 8) */
3617 for (i
= 0; i
< 256; i
++)
3619 rt2860_io_mac_write(sc
, RT2860_REG_WCID(i
), 0xffffffff);
3620 rt2860_io_mac_write(sc
, RT2860_REG_WCID(i
) + 4, 0x0000ffff);
3623 /* clear WCID attribute table (entries = 256, entry size = 4) */
3625 rt2860_io_mac_set_region_4(sc
, RT2860_REG_WCID_ATTR(0), 0, 256);
3627 /* clear IV/EIV table (entries = 256, entry size = 8) */
3629 rt2860_io_mac_set_region_4(sc
, RT2860_REG_IVEIV(0), 0, 2 * 256);
3631 /* clear pairwise key table (entries = 64, entry size = 32) */
3633 rt2860_io_mac_set_region_4(sc
, RT2860_REG_PKEY(0), 0, 8 * 64);
3635 /* clear shared key table (entries = 32, entry size = 32) */
3637 rt2860_io_mac_set_region_4(sc
, RT2860_REG_SKEY(0, 0), 0, 8 * 32);
3639 /* clear shared key mode (entries = 32, entry size = 2) */
3641 rt2860_io_mac_set_region_4(sc
, RT2860_REG_SKEY_MODE(0), 0, 16);
3645 * rt2860_asic_add_ba_session
3647 static void rt2860_asic_add_ba_session(struct rt2860_softc
*sc
,
3648 uint8_t wcid
, int tid
)
3652 RT2860_DPRINTF(sc
, RT2860_DEBUG_BA
,
3653 "%s: adding BA session: wcid=0x%02x, tid=%d\n",
3654 device_get_nameunit(sc
->dev
), wcid
, tid
);
3656 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_WCID(wcid
) + 4);
3658 tmp
|= (0x10000 << tid
);
3660 rt2860_io_mac_write(sc
, RT2860_REG_WCID(wcid
) + 4, tmp
);
3664 * rt2860_asic_del_ba_session
3666 static void rt2860_asic_del_ba_session(struct rt2860_softc
*sc
,
3667 uint8_t wcid
, int tid
)
3671 RT2860_DPRINTF(sc
, RT2860_DEBUG_BA
,
3672 "%s: deleting BA session: wcid=0x%02x, tid=%d\n",
3673 device_get_nameunit(sc
->dev
), wcid
, tid
);
3675 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_WCID(wcid
) + 4);
3677 tmp
&= ~(0x10000 << tid
);
3679 rt2860_io_mac_write(sc
, RT2860_REG_WCID(wcid
) + 4, tmp
);
3683 * rt2860_beacon_alloc
3685 static int rt2860_beacon_alloc(struct rt2860_softc
*sc
)
3687 struct ieee80211com
*ic
;
3689 struct rt2860_txwi txwi
;
3694 m
= ieee80211_beacon_alloc(ic
->ic_bss
, &sc
->beacon_offsets
);
3698 rate
= IEEE80211_IS_CHAN_5GHZ(ic
->ic_curchan
) ? 12 : 2;
3699 mcs
= rt2860_rate2mcs(rate
);
3701 RT2860_DPRINTF(sc
, RT2860_DEBUG_BEACON
,
3702 "%s: beacon allocate: mcs=0x%02x\n",
3703 device_get_nameunit(sc
->dev
), mcs
);
3705 memset(&txwi
, 0, sizeof(struct rt2860_txwi
));
3707 txwi
.wcid
= RT2860_WCID_RESERVED
;
3708 txwi
.pid_mpdu_len
= ((htole16(m
->m_pkthdr
.len
) & RT2860_TXWI_MPDU_LEN_MASK
) <<
3709 RT2860_TXWI_MPDU_LEN_SHIFT
);
3710 txwi
.txop
= (RT2860_TXWI_TXOP_HT
<< RT2860_TXWI_TXOP_SHIFT
);
3711 txwi
.mpdu_density_flags
|=
3712 (RT2860_TXWI_FLAGS_TS
<< RT2860_TXWI_FLAGS_SHIFT
);
3713 txwi
.bawin_size_xflags
|=
3714 (RT2860_TXWI_XFLAGS_NSEQ
<< RT2860_TXWI_XFLAGS_SHIFT
);
3718 txwi
.phymode_ifs_stbc_shortgi
=
3719 (RT2860_TXWI_PHYMODE_CCK
<< RT2860_TXWI_PHYMODE_SHIFT
);
3721 if (rate
!= 2 && (ic
->ic_flags
& IEEE80211_F_SHPREAMBLE
))
3722 mcs
|= RT2860_TXWI_MCS_SHOTPRE
;
3726 txwi
.phymode_ifs_stbc_shortgi
=
3727 (RT2860_TXWI_PHYMODE_OFDM
<< RT2860_TXWI_PHYMODE_SHIFT
);
3730 txwi
.bw_mcs
= (RT2860_TXWI_BW_20
<< RT2860_TXWI_BW_SHIFT
) |
3731 ((mcs
& RT2860_TXWI_MCS_MASK
) << RT2860_TXWI_MCS_SHIFT
);
3733 if (sc
->beacon_mbuf
!= NULL
)
3735 m_free(sc
->beacon_mbuf
);
3736 sc
->beacon_mbuf
= NULL
;
3739 sc
->beacon_mbuf
= m
;
3740 sc
->beacon_txwi
= txwi
;
3748 static uint8_t rt2860_rxrate(struct rt2860_rxwi
*rxwi
)
3750 uint8_t mcs
, phymode
;
3753 mcs
= (rxwi
->bw_mcs
>> RT2860_RXWI_MCS_SHIFT
) & RT2860_RXWI_MCS_MASK
;
3754 phymode
= (rxwi
->phymode_stbc_shortgi
>> RT2860_RXWI_PHYMODE_SHIFT
) &
3755 RT2860_RXWI_PHYMODE_MASK
;
3761 case RT2860_RXWI_PHYMODE_CCK
:
3762 switch (mcs
& ~RT2860_RXWI_MCS_SHOTPRE
)
3764 case 0: rate
= 2; break; /* 1 Mbps */
3765 case 1: rate
= 4; break; /* 2 MBps */
3766 case 2: rate
= 11; break; /* 5.5 Mbps */
3767 case 3: rate
= 22; break; /* 11 Mbps */
3771 case RT2860_RXWI_PHYMODE_OFDM
:
3774 case 0: rate
= 12; break; /* 6 Mbps */
3775 case 1: rate
= 18; break; /* 9 Mbps */
3776 case 2: rate
= 24; break; /* 12 Mbps */
3777 case 3: rate
= 36; break; /* 18 Mbps */
3778 case 4: rate
= 48; break; /* 24 Mbps */
3779 case 5: rate
= 72; break; /* 36 Mbps */
3780 case 6: rate
= 96; break; /* 48 Mbps */
3781 case 7: rate
= 108; break; /* 54 Mbps */
3785 case RT2860_RXWI_PHYMODE_HT_MIXED
:
3786 case RT2860_RXWI_PHYMODE_HT_GF
:
3794 * rt2860_maxrssi_rxpath
3796 static uint8_t rt2860_maxrssi_rxpath(struct rt2860_softc
*sc
,
3797 const struct rt2860_rxwi
*rxwi
)
3803 if (sc
->nrxpath
> 1)
3804 if (rxwi
->rssi
[1] > rxwi
->rssi
[rxpath
])
3807 if (sc
->nrxpath
> 2)
3808 if (rxwi
->rssi
[2] > rxwi
->rssi
[rxpath
])
3817 static int8_t rt2860_rssi2dbm(struct rt2860_softc
*sc
,
3818 uint8_t rssi
, uint8_t rxpath
)
3820 struct ieee80211com
*ic
;
3821 struct ieee80211_channel
*c
;
3823 int8_t rssi_off
, lna_gain
;
3830 chan
= ieee80211_chan2ieee(ic
, c
);
3832 if (IEEE80211_IS_CHAN_5GHZ(c
))
3834 rssi_off
= sc
->rssi_off_5ghz
[rxpath
];
3837 lna_gain
= sc
->lna_gain
[1];
3838 else if (chan
<= 128)
3839 lna_gain
= sc
->lna_gain
[2];
3841 lna_gain
= sc
->lna_gain
[3];
3845 rssi_off
= sc
->rssi_off_2ghz
[rxpath
];
3846 lna_gain
= sc
->lna_gain
[0];
3849 return (-12 - rssi_off
- lna_gain
- rssi
);
3855 static uint8_t rt2860_rate2mcs(uint8_t rate
)
3882 static int rt2860_ackrate(struct ieee80211com
*ic
, int rate
)
3894 return (ic
->ic_curmode
== IEEE80211_MODE_11B
) ? 4 : rate
;
3913 /* default to 1Mbps */
3920 static uint16_t rt2860_txtime(int len
, int rate
, uint32_t flags
)
3924 if (RT2860_RATE_IS_OFDM(rate
))
3926 txtime
= (8 + 4 * len
+ 3 + rate
- 1) / rate
;
3927 txtime
= 16 + 4 + 4 * txtime
+ 6;
3931 txtime
= (16 * len
+ rate
- 1) / rate
;
3933 if (rate
!= 2 && (flags
& IEEE80211_F_SHPREAMBLE
))
3945 static int rt2860_tx_frame(struct rt2860_softc
*sc
,
3946 struct mbuf
*m
, struct ieee80211_node
*ni
, int qid
)
3948 struct ieee80211com
*ic
;
3949 struct rt2860_softc_node
*rni
;
3950 struct rt2860_softc_tx_ring
*ring
;
3951 struct rt2860_softc_tx_data
*data
;
3952 struct rt2860_txdesc
*desc
;
3953 struct rt2860_txwi
*txwi
;
3954 struct ieee80211_frame
*wh
;
3955 struct ieee80211_tx_ampdu
*tx_ampdu
;
3956 struct rt2860_softc_tx_radiotap_header
*tap
;
3957 bus_dma_segment_t dma_seg
[RT2860_SOFTC_MAX_SCATTER
];
3958 u_int hdrsize
, hdrspace
;
3959 uint8_t type
, rate
, bw
, stbc
, shortgi
, mcs
, pid
, wcid
, mpdu_density
, bawin_size
, qsel
;
3960 uint16_t qos
, len
, dmalen
, mpdu_len
, dur
;
3961 int error
, hasqos
, ac
, ampdu
, mimops
, ackrate
, ndmasegs
, ndescs
, i
, j
;
3963 KASSERT(qid
>= 0 && qid
< RT2860_SOFTC_TX_RING_COUNT
,
3964 ("%s: Tx frame: invalid qid=%d\n",
3965 device_get_nameunit(sc
->dev
), qid
));
3967 RT2860_SOFTC_TX_RING_ASSERT_LOCKED(&sc
->tx_ring
[qid
]);
3970 rni
= (struct rt2860_softc_node
*) ni
;
3972 ring
= &sc
->tx_ring
[qid
];
3973 desc
= &ring
->desc
[ring
->desc_cur
];
3974 data
= &ring
->data
[ring
->data_cur
];
3975 txwi
= (struct rt2860_txwi
*) (ring
->seg0
+ ring
->data_cur
* RT2860_TX_DATA_SEG0_SIZE
);
3977 wh
= mtod(m
, struct ieee80211_frame
*);
3979 type
= wh
->i_fc
[0] & IEEE80211_FC0_TYPE_MASK
;
3981 hasqos
= IEEE80211_QOS_HAS_SEQ(wh
);
3984 if (IEEE80211_HAS_ADDR4(wh
))
3985 qos
= le16toh(*(const uint16_t *)
3986 (((struct ieee80211_qosframe_addr4
*) wh
)->i_qos
));
3988 qos
= le16toh(*(const uint16_t *)
3989 (((struct ieee80211_qosframe
*) wh
)->i_qos
));
3996 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
3998 if (IEEE80211_IS_MULTICAST(wh
->i_addr1
) || type
!= IEEE80211_FC0_TYPE_DATA
)
4000 else if (ic
->ic_fixed_rate
!= IEEE80211_FIXED_RATE_NONE
)
4001 rate
= ic
->ic_fixed_rate
;
4003 rate
= ni
->ni_htrates
.rs_rates
[ni
->ni_txrate
];
4007 if (IEEE80211_IS_MULTICAST(wh
->i_addr1
) || type
!= IEEE80211_FC0_TYPE_DATA
)
4008 rate
= IEEE80211_IS_CHAN_5GHZ(ic
->ic_curchan
) ? 12 : 2;
4009 else if (ic
->ic_fixed_rate
!= IEEE80211_FIXED_RATE_NONE
)
4010 rate
= ic
->ic_fixed_rate
;
4012 rate
= ni
->ni_rates
.rs_rates
[ni
->ni_txrate
];
4015 rate
&= IEEE80211_RATE_VAL
;
4017 /* fill Tx wireless info */
4019 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
4022 mcs
= rt2860_rate2mcs(rate
);
4024 /* management frames do not need encryption */
4026 if (type
== IEEE80211_FC0_TYPE_DATA
)
4027 wcid
= !IEEE80211_IS_MULTICAST(wh
->i_addr1
) ? rni
->staid
: RT2860_WCID_MCAST
;
4029 wcid
= RT2860_WCID_RESERVED
;
4031 /* calculate MPDU length without padding */
4033 hdrsize
= ieee80211_anyhdrsize(wh
);
4034 hdrspace
= ieee80211_anyhdrspace(ic
, wh
);
4035 mpdu_len
= m
->m_pkthdr
.len
- hdrspace
+ hdrsize
;
4037 memset(txwi
, 0, sizeof(struct rt2860_txwi
));
4041 /* MIMO power save */
4043 if ((ni
->ni_flags
& IEEE80211_NODE_HT
) &&
4044 ((ni
->ni_htcap
& IEEE80211_HTCAP_SMPS
) != IEEE80211_HTCAP_SMPS_OFF
))
4048 if ((ni
->ni_htcap
& IEEE80211_HTCAP_SMPS
) == IEEE80211_HTCAP_SMPS_DYNAMIC
)
4050 /* dynamic MIMO power save */
4052 txwi
->mpdu_density_flags
|=
4053 (RT2860_TXWI_FLAGS_MIMOPS
<< RT2860_TXWI_FLAGS_SHIFT
);
4057 /* static MIMO power save */
4070 pid
= (mcs
< 0xf) ? (mcs
+ 1) : mcs
;
4072 txwi
->pid_mpdu_len
= ((htole16(pid
) & RT2860_TXWI_PID_MASK
) <<
4073 RT2860_TXWI_PID_SHIFT
) | ((htole16(mpdu_len
) & RT2860_TXWI_MPDU_LEN_MASK
) <<
4074 RT2860_TXWI_MPDU_LEN_SHIFT
);
4076 stbc
= sc
->tx_stbc
&& (mcs
<= 7) && (ic
->ic_htcaps
& IEEE80211_HTCAP_TXSTBC
) &&
4077 (ni
->ni_flags
& IEEE80211_NODE_HT
) && (ni
->ni_htcap
& IEEE80211_HTCAP_RXSTBC
);
4079 shortgi
= ((ic
->ic_flags_ext
& IEEE80211_FEXT_SHORTGI20
) &&
4080 (ni
->ni_flags
& IEEE80211_NODE_HT
) && (ni
->ni_htcap
& IEEE80211_HTCAP_SHORTGI20
) &&
4081 (ni
->ni_chw
== 20)) ||
4082 ((ic
->ic_flags_ext
& IEEE80211_FEXT_SHORTGI40
) &&
4083 (ni
->ni_flags
& IEEE80211_NODE_HT
) && (ni
->ni_htcap
& IEEE80211_HTCAP_SHORTGI40
) &&
4084 (ni
->ni_chw
== 40));
4086 txwi
->phymode_ifs_stbc_shortgi
|=
4087 ((stbc
& RT2860_TXWI_STBC_MASK
) << RT2860_TXWI_STBC_SHIFT
) |
4088 ((shortgi
& RT2860_TXWI_SHORTGI_MASK
) << RT2860_TXWI_SHORTGI_SHIFT
);
4090 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
4092 txwi
->phymode_ifs_stbc_shortgi
|=
4093 (RT2860_TXWI_PHYMODE_HT_MIXED
<< RT2860_TXWI_PHYMODE_SHIFT
);
4097 if (!RT2860_RATE_IS_OFDM(rate
))
4099 txwi
->phymode_ifs_stbc_shortgi
|=
4100 (RT2860_TXWI_PHYMODE_CCK
<< RT2860_TXWI_PHYMODE_SHIFT
);
4102 if (rate
!= 2 && (ic
->ic_flags
& IEEE80211_F_SHPREAMBLE
))
4103 mcs
|= RT2860_TXWI_MCS_SHOTPRE
;
4107 txwi
->phymode_ifs_stbc_shortgi
|=
4108 (RT2860_TXWI_PHYMODE_OFDM
<< RT2860_TXWI_PHYMODE_SHIFT
);
4112 if ((ni
->ni_flags
& IEEE80211_NODE_HT
) && (ni
->ni_chw
== 40))
4113 bw
= RT2860_TXWI_BW_40
;
4115 bw
= RT2860_TXWI_BW_20
;
4117 txwi
->bw_mcs
= ((bw
& RT2860_TXWI_BW_MASK
) << RT2860_TXWI_BW_SHIFT
) |
4118 ((mcs
& RT2860_TXWI_MCS_MASK
) << RT2860_TXWI_MCS_SHIFT
);
4120 if (type
!= IEEE80211_FC0_TYPE_DATA
)
4121 txwi
->txop
= (RT2860_TXWI_TXOP_BACKOFF
<< RT2860_TXWI_TXOP_SHIFT
);
4123 txwi
->txop
= (RT2860_TXWI_TXOP_HT
<< RT2860_TXWI_TXOP_SHIFT
);
4125 /* skip ACKs for multicast frames */
4127 if (!IEEE80211_IS_MULTICAST(wh
->i_addr1
) &&
4128 (!hasqos
|| (qos
& IEEE80211_QOS_ACKPOLICY
) != IEEE80211_QOS_ACKPOLICY_NOACK
))
4130 txwi
->bawin_size_xflags
|=
4131 (RT2860_TXWI_XFLAGS_ACK
<< RT2860_TXWI_XFLAGS_SHIFT
);
4133 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
4135 /* preamble + plcp + signal extension + SIFS */
4137 dur
= 16 + 4 + 6 + 10;
4141 ackrate
= rt2860_ackrate(ic
, rate
);
4143 dur
= rt2860_txtime(RT2860_ACK_SIZE
, ackrate
, ic
->ic_flags
) +
4147 *(uint16_t *) wh
->i_dur
= htole16(dur
);
4150 /* check for A-MPDU */
4152 if ((qos
& IEEE80211_QOS_ACKPOLICY
) == IEEE80211_QOS_ACKPOLICY_BA
)
4154 ac
= M_WME_GETAC(m
);
4155 tx_ampdu
= &ni
->ni_tx_ampdu
[ac
];
4157 mpdu_density
= RT2860_MS(ni
->ni_htparam
, IEEE80211_HTCAP_MPDUDENSITY
);
4158 bawin_size
= tx_ampdu
->txa_wnd
;
4160 txwi
->mpdu_density_flags
|=
4161 ((mpdu_density
& RT2860_TXWI_MPDU_DENSITY_MASK
) << RT2860_TXWI_MPDU_DENSITY_SHIFT
) |
4162 (RT2860_TXWI_FLAGS_AMPDU
<< RT2860_TXWI_FLAGS_SHIFT
);
4164 txwi
->bawin_size_xflags
|=
4165 ((bawin_size
& RT2860_TXWI_BAWIN_SIZE_MASK
) << RT2860_TXWI_BAWIN_SIZE_SHIFT
);
4167 if (IEEE80211_HAS_ADDR4(wh
))
4168 ((struct ieee80211_qosframe_addr4
*) wh
)->i_qos
[0] &= ~IEEE80211_QOS_ACKPOLICY
;
4170 ((struct ieee80211_qosframe
*) wh
)->i_qos
[0] &= ~IEEE80211_QOS_ACKPOLICY
;
4179 /* ask MAC to insert timestamp into probe responses */
4181 if ((wh
->i_fc
[0] & (IEEE80211_FC0_TYPE_MASK
| IEEE80211_FC0_SUBTYPE_MASK
)) ==
4182 (IEEE80211_FC0_TYPE_MGT
| IEEE80211_FC0_SUBTYPE_PROBE_RESP
))
4183 txwi
->mpdu_density_flags
|=
4184 (RT2860_TXWI_FLAGS_TS
<< RT2860_TXWI_FLAGS_SHIFT
);
4186 if (bpf_peers_present(sc
->drvbpf
))
4190 tap
->flags
= IEEE80211_RADIOTAP_F_DATAPAD
;
4191 tap
->chan_flags
= htole32(ic
->ic_curchan
->ic_flags
);
4192 tap
->chan_freq
= htole16(ic
->ic_curchan
->ic_freq
);
4193 tap
->chan_ieee
= ic
->ic_curchan
->ic_ieee
;
4194 tap
->chan_maxpow
= 0;
4196 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
4197 tap
->rate
= mcs
| IEEE80211_RATE_MCS
;
4201 if (mcs
& RT2860_TXWI_MCS_SHOTPRE
)
4202 tap
->flags
|= IEEE80211_RADIOTAP_F_SHORTPRE
;
4205 tap
->flags
|= IEEE80211_RADIOTAP_F_SHORTGI
;
4207 if (wh
->i_fc
[1] & IEEE80211_FC1_WEP
)
4208 tap
->flags
|= IEEE80211_RADIOTAP_F_WEP
;
4210 /* XXX use temporarily radiotap CFP flag as A-MPDU flag */
4213 tap
->flags
|= IEEE80211_RADIOTAP_F_CFP
;
4215 if (wh
->i_fc
[1] & IEEE80211_FC1_WEP
)
4217 wh
->i_fc
[1] &= ~IEEE80211_FC1_WEP
;
4219 bpf_mtap2(sc
->drvbpf
, tap
, sc
->txtap_len
, m
);
4221 wh
->i_fc
[1] |= IEEE80211_FC1_WEP
;
4225 bpf_mtap2(sc
->drvbpf
, tap
, sc
->txtap_len
, m
);
4229 /* copy and trim 802.11 header */
4231 m_copydata(m
, 0, hdrsize
, (caddr_t
) (txwi
+ 1));
4234 error
= bus_dmamap_load_mbuf_sg(ring
->data_dma_tag
, data
->dma_map
, m
,
4235 dma_seg
, &ndmasegs
, 0);
4238 /* too many fragments, linearize */
4240 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
4241 "%s: could not load mbuf DMA map, trying to linearize mbuf\n",
4242 device_get_nameunit(sc
->dev
));
4244 m
= m_defrag(m
, M_DONTWAIT
);
4248 sc
->tx_defrag_packets
++;
4250 error
= bus_dmamap_load_mbuf_sg(ring
->data_dma_tag
, data
->dma_map
, m
,
4251 dma_seg
, &ndmasegs
, 0);
4254 printf("%s: could not load mbuf DMA map: error=%d\n",
4255 device_get_nameunit(sc
->dev
), error
);
4261 if (m
->m_pkthdr
.len
== 0)
4264 /* determine how many Tx descs are required */
4266 ndescs
= 1 + ndmasegs
/ 2;
4267 if ((ring
->desc_queued
+ ndescs
) > (RT2860_SOFTC_TX_RING_DESC_COUNT
- 2))
4269 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
4270 "%s: there are not enough Tx descs\n",
4271 device_get_nameunit(sc
->dev
));
4273 sc
->no_tx_desc_avail
++;
4275 bus_dmamap_unload(ring
->data_dma_tag
, data
->dma_map
);
4283 /* set up Tx descs */
4285 /* first segment is Tx wireless info and 802.11 header */
4287 len
= sizeof(struct rt2860_txwi
) + hdrsize
;
4289 /* align end on a 4-bytes boundary */
4291 dmalen
= (len
+ 3) & ~ 3;
4293 memset((caddr_t
) txwi
+ len
, 0, dmalen
- len
);
4295 qsel
= RT2860_TXDESC_QSEL_EDCA
;
4297 desc
->sdp0
= htole32(ring
->seg0_phys_addr
+ ring
->data_cur
* RT2860_TX_DATA_SEG0_SIZE
);
4298 desc
->sdl0
= htole16(dmalen
);
4299 desc
->qsel_flags
= (qsel
<< RT2860_TXDESC_QSEL_SHIFT
);
4301 /* set up payload segments */
4303 for (i
= ndmasegs
, j
= 0; i
>= 2; i
-= 2)
4305 desc
->sdp1
= htole32(dma_seg
[j
].ds_addr
);
4306 desc
->sdl1
= htole16(dma_seg
[j
].ds_len
);
4308 ring
->desc_queued
++;
4309 ring
->desc_cur
= (ring
->desc_cur
+ 1) % RT2860_SOFTC_TX_RING_DESC_COUNT
;
4313 desc
= &ring
->desc
[ring
->desc_cur
];
4315 desc
->sdp0
= htole32(dma_seg
[j
].ds_addr
);
4316 desc
->sdl0
= htole16(dma_seg
[j
].ds_len
);
4317 desc
->qsel_flags
= (qsel
<< RT2860_TXDESC_QSEL_SHIFT
);
4322 /* finalize last payload segment */
4326 desc
->sdp1
= htole32(dma_seg
[j
].ds_addr
);
4327 desc
->sdl1
= htole16(dma_seg
[j
].ds_len
| RT2860_TXDESC_SDL1_LASTSEG
);
4331 desc
->sdl0
|= htole16(RT2860_TXDESC_SDL0_LASTSEG
);
4335 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
4336 "%s: sending frame: qid=%d, hdrsize=%d, hdrspace=%d, len=%d, "
4337 "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",
4338 device_get_nameunit(sc
->dev
),
4339 qid
, hdrsize
, hdrspace
, m
->m_pkthdr
.len
+ hdrsize
,
4340 bw
, stbc
, shortgi
, mcs
, wcid
, ampdu
, mimops
, dmalen
, ndmasegs
,
4341 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
);
4343 bus_dmamap_sync(ring
->seg0_dma_tag
, ring
->seg0_dma_map
,
4344 BUS_DMASYNC_PREWRITE
);
4345 bus_dmamap_sync(ring
->data_dma_tag
, data
->dma_map
,
4346 BUS_DMASYNC_PREWRITE
);
4347 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
4348 BUS_DMASYNC_PREWRITE
);
4350 ring
->desc_queued
++;
4351 ring
->desc_cur
= (ring
->desc_cur
+ 1) % RT2860_SOFTC_TX_RING_DESC_COUNT
;
4353 ring
->data_queued
++;
4354 ring
->data_cur
= (ring
->data_cur
+ 1) % RT2860_SOFTC_TX_RING_DATA_COUNT
;
4358 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_CTX_IDX(qid
), ring
->desc_cur
);
4366 static int rt2860_tx_raw(struct rt2860_softc
*sc
,
4367 struct mbuf
*m
, struct ieee80211_node
*ni
,
4368 const struct ieee80211_bpf_params
*params
)
4370 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
4372 device_get_nameunit(sc
->dev
));
4380 static void rt2860_intr(void *arg
)
4382 struct rt2860_softc
*sc
;
4389 /* acknowledge interrupts */
4391 status
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_INT_STATUS
);
4392 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_INT_STATUS
, status
);
4394 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4395 "%s: interrupt: status = 0x%08x\n",
4396 device_get_nameunit(sc
->dev
), status
);
4398 if (status
== 0xffffffff || /* device likely went away */
4399 status
== 0) /* not for us */
4404 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
4407 if (status
& RT2860_REG_INT_TX_COHERENT
)
4408 rt2860_tx_coherent_intr(sc
);
4410 if (status
& RT2860_REG_INT_RX_COHERENT
)
4411 rt2860_rx_coherent_intr(sc
);
4413 if (status
& RT2860_REG_INT_TXRX_COHERENT
)
4414 rt2860_txrx_coherent_intr(sc
);
4416 if (status
& RT2860_REG_INT_FIFO_STA_FULL
)
4417 rt2860_fifo_sta_full_intr(sc
);
4419 if (status
& RT2860_REG_INT_TX_MGMT_DONE
)
4420 rt2860_tx_intr(sc
, 5);
4422 if (status
& RT2860_REG_INT_RX_DONE
)
4425 if (status
& RT2860_REG_INT_RX_DELAY_DONE
)
4426 rt2860_rx_delay_intr(sc
);
4428 if (status
& RT2860_REG_INT_TX_HCCA_DONE
)
4429 rt2860_tx_intr(sc
, 4);
4431 if (status
& RT2860_REG_INT_TX_AC3_DONE
)
4432 rt2860_tx_intr(sc
, 3);
4434 if (status
& RT2860_REG_INT_TX_AC2_DONE
)
4435 rt2860_tx_intr(sc
, 2);
4437 if (status
& RT2860_REG_INT_TX_AC1_DONE
)
4438 rt2860_tx_intr(sc
, 1);
4440 if (status
& RT2860_REG_INT_TX_AC0_DONE
)
4441 rt2860_tx_intr(sc
, 0);
4443 if (status
& RT2860_REG_INT_TX_DELAY_DONE
)
4444 rt2860_tx_delay_intr(sc
);
4446 if (status
& RT2860_REG_INT_PRE_TBTT
)
4447 rt2860_pre_tbtt_intr(sc
);
4449 if (status
& RT2860_REG_INT_TBTT
)
4450 rt2860_tbtt_intr(sc
);
4452 if (status
& RT2860_REG_INT_MCU_CMD
)
4453 rt2860_mcu_cmd_intr(sc
);
4455 if (status
& RT2860_REG_INT_AUTO_WAKEUP
)
4456 rt2860_auto_wakeup_intr(sc
);
4458 if (status
& RT2860_REG_INT_GP_TIMER
)
4459 rt2860_gp_timer_intr(sc
);
4463 * rt2860_tx_coherent_intr
4465 static void rt2860_tx_coherent_intr(struct rt2860_softc
*sc
)
4470 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4471 "%s: Tx coherent interrupt\n",
4472 device_get_nameunit(sc
->dev
));
4474 sc
->tx_coherent_interrupts
++;
4476 /* restart DMA engine */
4478 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
);
4480 tmp
&= ~(RT2860_REG_TX_WB_DDONE
|
4481 RT2860_REG_RX_DMA_ENABLE
|
4482 RT2860_REG_TX_DMA_ENABLE
);
4484 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
, tmp
);
4486 /* init Tx rings (4 EDCAs + HCCA + MGMT) */
4488 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
4489 rt2860_reset_tx_ring(sc
, &sc
->tx_ring
[i
]);
4491 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
4493 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_BASE_PTR(i
),
4494 sc
->tx_ring
[i
].desc_phys_addr
);
4495 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_MAX_CNT(i
),
4496 RT2860_SOFTC_TX_RING_DESC_COUNT
);
4497 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_CTX_IDX(i
), 0);
4502 rt2860_reset_rx_ring(sc
, &sc
->rx_ring
);
4504 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_BASE_PTR
,
4505 sc
->rx_ring
.desc_phys_addr
);
4506 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_MAX_CNT
,
4507 RT2860_SOFTC_RX_RING_DATA_COUNT
);
4508 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_CALC_IDX
,
4509 RT2860_SOFTC_RX_RING_DATA_COUNT
- 1);
4511 rt2860_txrx_enable(sc
);
4515 * rt2860_rx_coherent_intr
4517 static void rt2860_rx_coherent_intr(struct rt2860_softc
*sc
)
4522 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4523 "%s: Rx coherent interrupt\n",
4524 device_get_nameunit(sc
->dev
));
4526 sc
->rx_coherent_interrupts
++;
4528 /* restart DMA engine */
4530 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
);
4532 tmp
&= ~(RT2860_REG_TX_WB_DDONE
|
4533 RT2860_REG_RX_DMA_ENABLE
|
4534 RT2860_REG_TX_DMA_ENABLE
);
4536 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
, tmp
);
4538 /* init Tx rings (4 EDCAs + HCCA + MGMT) */
4540 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
4541 rt2860_reset_tx_ring(sc
, &sc
->tx_ring
[i
]);
4543 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
4545 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_BASE_PTR(i
),
4546 sc
->tx_ring
[i
].desc_phys_addr
);
4547 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_MAX_CNT(i
),
4548 RT2860_SOFTC_TX_RING_DESC_COUNT
);
4549 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_CTX_IDX(i
), 0);
4554 rt2860_reset_rx_ring(sc
, &sc
->rx_ring
);
4556 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_BASE_PTR
,
4557 sc
->rx_ring
.desc_phys_addr
);
4558 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_MAX_CNT
,
4559 RT2860_SOFTC_RX_RING_DATA_COUNT
);
4560 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_CALC_IDX
,
4561 RT2860_SOFTC_RX_RING_DATA_COUNT
- 1);
4563 rt2860_txrx_enable(sc
);
4567 * rt2860_txrx_coherent_intr
4569 static void rt2860_txrx_coherent_intr(struct rt2860_softc
*sc
)
4574 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4575 "%s: Tx/Rx coherent interrupt\n",
4576 device_get_nameunit(sc
->dev
));
4578 sc
->txrx_coherent_interrupts
++;
4580 /* restart DMA engine */
4582 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
);
4584 tmp
&= ~(RT2860_REG_TX_WB_DDONE
|
4585 RT2860_REG_RX_DMA_ENABLE
|
4586 RT2860_REG_TX_DMA_ENABLE
);
4588 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
, tmp
);
4590 /* init Tx rings (4 EDCAs + HCCA + MGMT) */
4592 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
4593 rt2860_reset_tx_ring(sc
, &sc
->tx_ring
[i
]);
4595 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
4597 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_BASE_PTR(i
),
4598 sc
->tx_ring
[i
].desc_phys_addr
);
4599 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_MAX_CNT(i
),
4600 RT2860_SOFTC_TX_RING_DESC_COUNT
);
4601 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_CTX_IDX(i
), 0);
4606 rt2860_reset_rx_ring(sc
, &sc
->rx_ring
);
4608 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_BASE_PTR
,
4609 sc
->rx_ring
.desc_phys_addr
);
4610 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_MAX_CNT
,
4611 RT2860_SOFTC_RX_RING_DATA_COUNT
);
4612 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_CALC_IDX
,
4613 RT2860_SOFTC_RX_RING_DATA_COUNT
- 1);
4615 rt2860_txrx_enable(sc
);
4619 * rt2860_fifo_sta_full_intr
4621 static void rt2860_fifo_sta_full_intr(struct rt2860_softc
*sc
)
4623 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4624 "%s: FIFO statistic full interrupt\n",
4625 device_get_nameunit(sc
->dev
));
4627 sc
->fifo_sta_full_interrupts
++;
4629 RT2860_SOFTC_LOCK(sc
);
4631 if (!(sc
->intr_disable_mask
& RT2860_REG_INT_FIFO_STA_FULL
))
4633 rt2860_intr_disable(sc
, RT2860_REG_INT_FIFO_STA_FULL
);
4635 taskqueue_enqueue(sc
->taskqueue
, &sc
->fifo_sta_full_task
);
4638 sc
->intr_pending_mask
|= RT2860_REG_INT_FIFO_STA_FULL
;
4640 RT2860_SOFTC_UNLOCK(sc
);
4646 static void rt2860_rx_intr(struct rt2860_softc
*sc
)
4648 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4649 "%s: Rx interrupt\n",
4650 device_get_nameunit(sc
->dev
));
4652 sc
->rx_interrupts
++;
4654 RT2860_SOFTC_LOCK(sc
);
4656 if (!(sc
->intr_disable_mask
& RT2860_REG_INT_RX_DONE
))
4658 rt2860_intr_disable(sc
, RT2860_REG_INT_RX_DONE
);
4660 taskqueue_enqueue(sc
->taskqueue
, &sc
->rx_done_task
);
4663 sc
->intr_pending_mask
|= RT2860_REG_INT_RX_DONE
;
4665 RT2860_SOFTC_UNLOCK(sc
);
4669 * rt2860_rx_delay_intr
4671 static void rt2860_rx_delay_intr(struct rt2860_softc
*sc
)
4673 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4674 "%s: Rx delay interrupt\n",
4675 device_get_nameunit(sc
->dev
));
4677 sc
->rx_delay_interrupts
++;
4683 static void rt2860_tx_intr(struct rt2860_softc
*sc
, int qid
)
4685 KASSERT(qid
>= 0 && qid
< RT2860_SOFTC_TX_RING_COUNT
,
4686 ("%s: Tx interrupt: invalid qid=%d\n",
4687 device_get_nameunit(sc
->dev
), qid
));
4689 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4690 "%s: Tx interrupt: qid=%d\n",
4691 device_get_nameunit(sc
->dev
), qid
);
4693 sc
->tx_interrupts
[qid
]++;
4695 RT2860_SOFTC_LOCK(sc
);
4697 if (!(sc
->intr_disable_mask
& (RT2860_REG_INT_TX_AC0_DONE
<< qid
)))
4699 rt2860_intr_disable(sc
, (RT2860_REG_INT_TX_AC0_DONE
<< qid
));
4701 taskqueue_enqueue(sc
->taskqueue
, &sc
->tx_done_task
);
4704 sc
->intr_pending_mask
|= (RT2860_REG_INT_TX_AC0_DONE
<< qid
);
4706 RT2860_SOFTC_UNLOCK(sc
);
4710 * rt2860_tx_delay_intr
4712 static void rt2860_tx_delay_intr(struct rt2860_softc
*sc
)
4714 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4715 "%s: Tx delay interrupt\n",
4716 device_get_nameunit(sc
->dev
));
4718 sc
->tx_delay_interrupts
++;
4722 * rt2860_pre_tbtt_intr
4724 static void rt2860_pre_tbtt_intr(struct rt2860_softc
*sc
)
4726 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4727 "%s: Pre-TBTT interrupt\n",
4728 device_get_nameunit(sc
->dev
));
4730 sc
->pre_tbtt_interrupts
++;
4736 static void rt2860_tbtt_intr(struct rt2860_softc
*sc
)
4738 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4739 "%s: TBTT interrupt\n",
4740 device_get_nameunit(sc
->dev
));
4742 sc
->tbtt_interrupts
++;
4746 * rt2860_mcu_cmd_intr
4748 static void rt2860_mcu_cmd_intr(struct rt2860_softc
*sc
)
4750 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4751 "%s: MCU command interrupt\n",
4752 device_get_nameunit(sc
->dev
));
4754 sc
->mcu_cmd_interrupts
++;
4758 * rt2860_auto_wakeup_intr
4760 static void rt2860_auto_wakeup_intr(struct rt2860_softc
*sc
)
4762 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4763 "%s: auto wakeup interrupt\n",
4764 device_get_nameunit(sc
->dev
));
4766 sc
->auto_wakeup_interrupts
++;
4770 * rt2860_gp_timer_intr
4772 static void rt2860_gp_timer_intr(struct rt2860_softc
*sc
)
4774 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4775 "%s: GP timer interrupt\n",
4776 device_get_nameunit(sc
->dev
));
4778 sc
->gp_timer_interrupts
++;
4782 * rt2860_rx_done_task
4784 static void rt2860_rx_done_task(void *context
, int pending
)
4786 struct rt2860_softc
*sc
;
4793 RT2860_DPRINTF(sc
, RT2860_DEBUG_RX
,
4794 "%s: Rx done task\n",
4795 device_get_nameunit(sc
->dev
));
4797 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
4800 sc
->intr_pending_mask
&= ~RT2860_REG_INT_RX_DONE
;
4802 again
= rt2860_rx_eof(sc
, sc
->rx_process_limit
);
4804 RT2860_SOFTC_LOCK(sc
);
4806 if ((sc
->intr_pending_mask
& RT2860_REG_INT_RX_DONE
) || again
)
4808 RT2860_DPRINTF(sc
, RT2860_DEBUG_RX
,
4809 "%s: Rx done task: scheduling again\n",
4810 device_get_nameunit(sc
->dev
));
4812 taskqueue_enqueue(sc
->taskqueue
, &sc
->rx_done_task
);
4816 rt2860_intr_enable(sc
, RT2860_REG_INT_RX_DONE
);
4819 RT2860_SOFTC_UNLOCK(sc
);
4823 * rt2860_tx_done_task
4825 static void rt2860_tx_done_task(void *context
, int pending
)
4827 struct rt2860_softc
*sc
;
4829 struct ieee80211com
*ic
;
4837 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
4838 "%s: Tx done task\n",
4839 device_get_nameunit(sc
->dev
));
4841 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
4844 for (i
= RT2860_SOFTC_TX_RING_COUNT
- 1; i
>= 0; i
--)
4846 if (sc
->intr_pending_mask
& (RT2860_REG_INT_TX_AC0_DONE
<< i
))
4848 sc
->intr_pending_mask
&= ~(RT2860_REG_INT_TX_AC0_DONE
<< i
);
4850 rt2860_tx_eof(sc
, &sc
->tx_ring
[i
]);
4856 ifp
->if_drv_flags
&= ~IFF_DRV_OACTIVE
;
4858 intr_mask
= (RT2860_REG_INT_TX_MGMT_DONE
|
4859 RT2860_REG_INT_TX_HCCA_DONE
|
4860 RT2860_REG_INT_TX_AC3_DONE
|
4861 RT2860_REG_INT_TX_AC2_DONE
|
4862 RT2860_REG_INT_TX_AC1_DONE
|
4863 RT2860_REG_INT_TX_AC0_DONE
);
4865 RT2860_SOFTC_LOCK(sc
);
4867 rt2860_intr_enable(sc
, ~sc
->intr_pending_mask
&
4868 (sc
->intr_disable_mask
& intr_mask
));
4870 if (sc
->intr_pending_mask
& intr_mask
)
4872 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
4873 "%s: Tx done task: scheduling again\n",
4874 device_get_nameunit(sc
->dev
));
4876 taskqueue_enqueue(sc
->taskqueue
, &sc
->tx_done_task
);
4879 RT2860_SOFTC_UNLOCK(sc
);
4881 if (!IFQ_IS_EMPTY(&ic
->ic_mgtq
) || !IFQ_IS_EMPTY(&ifp
->if_snd
))
4886 * rt2860_fifo_sta_full_task
4888 static void rt2860_fifo_sta_full_task(void *context
, int pending
)
4890 struct rt2860_softc
*sc
;
4892 struct ieee80211com
*ic
;
4898 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATS
,
4899 "%s: FIFO statistic full task\n",
4900 device_get_nameunit(sc
->dev
));
4902 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
4905 sc
->intr_pending_mask
&= ~RT2860_REG_INT_FIFO_STA_FULL
;
4907 rt2860_drain_fifo_stats(sc
);
4909 RT2860_SOFTC_LOCK(sc
);
4911 if (sc
->intr_pending_mask
& RT2860_REG_INT_FIFO_STA_FULL
)
4913 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATS
,
4914 "%s: FIFO statistic full task: scheduling again\n",
4915 device_get_nameunit(sc
->dev
));
4917 taskqueue_enqueue(sc
->taskqueue
, &sc
->fifo_sta_full_task
);
4921 rt2860_intr_enable(sc
, RT2860_REG_INT_FIFO_STA_FULL
);
4924 RT2860_SOFTC_UNLOCK(sc
);
4926 if (!IFQ_IS_EMPTY(&ic
->ic_mgtq
) || !IFQ_IS_EMPTY(&ifp
->if_snd
))
4931 * rt2860_periodic_task
4933 static void rt2860_periodic_task(void *context
, int pending
)
4935 struct rt2860_softc
*sc
;
4937 struct ieee80211com
*ic
;
4943 RT2860_DPRINTF(sc
, RT2860_DEBUG_PERIODIC
,
4944 "%s: periodic task: round=%lu\n",
4945 device_get_nameunit(sc
->dev
), sc
->periodic_round
);
4947 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
4950 RT2860_SOFTC_LOCK(sc
);
4952 sc
->periodic_round
++;
4954 rt2860_update_stats(sc
);
4956 if ((sc
->periodic_round
% 10) == 0)
4958 rt2860_bbp_tuning(sc
);
4960 rt2860_update_raw_counters(sc
);
4962 rt2860_watchdog(sc
);
4964 if (ic
->ic_opmode
!= IEEE80211_M_MONITOR
&& ic
->ic_state
== IEEE80211_S_RUN
)
4966 if (ic
->ic_opmode
== IEEE80211_M_STA
)
4967 rt2860_amrr_update_iter_func(sc
, ic
->ic_bss
);
4969 ieee80211_iterate_nodes(&ic
->ic_sta
, rt2860_amrr_update_iter_func
, sc
);
4973 RT2860_SOFTC_UNLOCK(sc
);
4975 callout_reset(&sc
->periodic_ch
, hz
/ 10, rt2860_periodic
, sc
);
4981 static int rt2860_rx_eof(struct rt2860_softc
*sc
, int limit
)
4983 struct ieee80211com
*ic
;
4985 struct ieee80211_frame
*wh
;
4986 struct ieee80211_node
*ni
;
4987 struct rt2860_softc_node
*rni
;
4988 struct rt2860_softc_rx_radiotap_header
*tap
;
4989 struct rt2860_softc_rx_ring
*ring
;
4990 struct rt2860_rxdesc
*desc
;
4991 struct rt2860_softc_rx_data
*data
;
4992 struct rt2860_rxwi
*rxwi
;
4993 struct mbuf
*m
, *mnew
;
4994 bus_dma_segment_t segs
[1];
4995 bus_dmamap_t dma_map
;
4996 uint32_t index
, desc_flags
;
4997 uint8_t cipher_err
, rssi
, ant
, phymode
, bw
, shortgi
, mcs
, keyidx
;
4999 int error
, nsegs
, len
, ampdu
, amsdu
, nframes
, i
;
5003 ring
= &sc
->rx_ring
;
5009 index
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_RX_DRX_IDX
);
5010 if (ring
->cur
== index
)
5013 desc
= &ring
->desc
[ring
->cur
];
5014 data
= &ring
->data
[ring
->cur
];
5016 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
5017 BUS_DMASYNC_POSTREAD
);
5019 if (!(desc
->sdl0
& htole16(RT2860_RXDESC_SDL0_DDONE
)))
5024 mnew
= m_getjcl(M_DONTWAIT
, MT_DATA
, M_PKTHDR
, MJUMPAGESIZE
);
5027 sc
->rx_mbuf_alloc_errors
++;
5032 mnew
->m_len
= mnew
->m_pkthdr
.len
= MJUMPAGESIZE
;
5034 error
= bus_dmamap_load_mbuf_sg(ring
->data_dma_tag
, ring
->spare_dma_map
,
5035 mnew
, segs
, &nsegs
, BUS_DMA_NOWAIT
);
5040 sc
->rx_mbuf_dmamap_errors
++;
5046 KASSERT(nsegs
== 1, ("%s: too many DMA segments",
5047 device_get_name(sc
->dev
)));
5049 bus_dmamap_sync(ring
->data_dma_tag
, data
->dma_map
,
5050 BUS_DMASYNC_POSTREAD
);
5051 bus_dmamap_unload(ring
->data_dma_tag
, data
->dma_map
);
5053 dma_map
= data
->dma_map
;
5054 data
->dma_map
= ring
->spare_dma_map
;
5055 ring
->spare_dma_map
= dma_map
;
5057 bus_dmamap_sync(ring
->data_dma_tag
, data
->dma_map
,
5058 BUS_DMASYNC_PREREAD
);
5063 desc
->sdp0
= htole32(segs
[0].ds_addr
);
5065 desc_flags
= le32toh(desc
->flags
);
5067 RT2860_DPRINTF(sc
, RT2860_DEBUG_RX
,
5068 "%s: Rx frame: rxdesc flags=0x%08x\n",
5069 device_get_nameunit(sc
->dev
), desc_flags
);
5071 /* get Rx wireless info */
5073 rxwi
= mtod(m
, struct rt2860_rxwi
*);
5074 len
= (le16toh(rxwi
->tid_size
) >> RT2860_RXWI_SIZE_SHIFT
) &
5075 RT2860_RXWI_SIZE_MASK
;
5077 /* check for L2 padding between IEEE 802.11 frame header and body */
5079 if (desc_flags
& RT2860_RXDESC_FLAGS_L2PAD
)
5081 RT2860_DPRINTF(sc
, RT2860_DEBUG_RX
,
5082 "%s: L2 padding: len=%d\n",
5083 device_get_nameunit(sc
->dev
), len
);
5088 m
->m_pkthdr
.rcvif
= ifp
;
5089 m
->m_data
= (caddr_t
) (rxwi
+ 1);
5090 m
->m_pkthdr
.len
= m
->m_len
= len
;
5092 /* check for crc errors */
5094 if (desc_flags
& RT2860_RXDESC_FLAGS_CRC_ERR
)
5096 RT2860_DPRINTF(sc
, RT2860_DEBUG_RX
,
5097 "%s: rxdesc: crc error\n",
5098 device_get_nameunit(sc
->dev
));
5102 if (!(ifp
->if_flags
& IFF_PROMISC
))
5109 wh
= (struct ieee80211_frame
*) (rxwi
+ 1);
5111 /* check for cipher errors */
5113 if (desc_flags
& RT2860_RXDESC_FLAGS_DECRYPTED
)
5115 cipher_err
= ((desc_flags
>> RT2860_RXDESC_FLAGS_CIPHER_ERR_SHIFT
) &
5116 RT2860_RXDESC_FLAGS_CIPHER_ERR_MASK
);
5117 if (cipher_err
== RT2860_RXDESC_FLAGS_CIPHER_ERR_NONE
)
5119 if (wh
->i_fc
[1] & IEEE80211_FC1_WEP
)
5120 wh
->i_fc
[1] &= ~IEEE80211_FC1_WEP
;
5122 m
->m_flags
|= M_WEP
;
5124 sc
->rx_cipher_no_errors
++;
5128 RT2860_DPRINTF(sc
, RT2860_DEBUG_RX
,
5129 "%s: rxdesc: cipher error=0x%02x\n",
5130 device_get_nameunit(sc
->dev
), cipher_err
);
5132 if (cipher_err
== RT2860_RXDESC_FLAGS_CIPHER_ERR_ICV
)
5133 sc
->rx_cipher_icv_errors
++;
5134 else if (cipher_err
== RT2860_RXDESC_FLAGS_CIPHER_ERR_MIC
)
5135 sc
->rx_cipher_mic_errors
++;
5136 else if (cipher_err
== RT2860_RXDESC_FLAGS_CIPHER_ERR_INVALID_KEY
)
5137 sc
->rx_cipher_invalid_key_errors
++;
5139 if ((cipher_err
== RT2860_RXDESC_FLAGS_CIPHER_ERR_MIC
) &&
5140 (desc_flags
& RT2860_RXDESC_FLAGS_MYBSS
))
5142 keyidx
= (rxwi
->udf_bssidx_keyidx
>> RT2860_RXWI_KEYIDX_SHIFT
) &
5143 RT2860_RXWI_KEYIDX_MASK
;
5145 ieee80211_notify_michael_failure(ic
, wh
, keyidx
);
5150 if (!(ifp
->if_flags
& IFF_PROMISC
))
5159 if (wh
->i_fc
[1] & IEEE80211_FC1_WEP
)
5161 RT2860_DPRINTF(sc
, RT2860_DEBUG_RX
,
5162 "%s: rxdesc: not decrypted but protected flag set\n",
5163 device_get_nameunit(sc
->dev
));
5167 if (!(ifp
->if_flags
& IFF_PROMISC
))
5175 /* check for A-MPDU */
5177 if (desc_flags
& RT2860_RXDESC_FLAGS_BA
)
5179 m
->m_flags
|= M_AMPDU
;
5190 /* check for A-MSDU */
5192 if (desc_flags
& RT2860_RXDESC_FLAGS_AMSDU
)
5203 ant
= rt2860_maxrssi_rxpath(sc
, rxwi
);
5204 rssi
= rxwi
->rssi
[ant
];
5205 rssi_dbm
= rt2860_rssi2dbm(sc
, rssi
, ant
);
5206 phymode
= ((rxwi
->phymode_stbc_shortgi
>> RT2860_RXWI_PHYMODE_SHIFT
) &
5207 RT2860_RXWI_PHYMODE_MASK
);
5208 bw
= ((rxwi
->bw_mcs
>> RT2860_RXWI_BW_SHIFT
) & RT2860_RXWI_BW_MASK
);
5209 shortgi
= ((rxwi
->phymode_stbc_shortgi
>> RT2860_RXWI_SHORTGI_SHIFT
) &
5210 RT2860_RXWI_SHORTGI_MASK
);
5211 mcs
= ((rxwi
->bw_mcs
>> RT2860_RXWI_MCS_SHIFT
) & RT2860_RXWI_MCS_MASK
);
5213 if (bpf_peers_present(sc
->drvbpf
))
5217 tap
->flags
= IEEE80211_RADIOTAP_F_DATAPAD
;
5218 tap
->dbm_antsignal
= rssi_dbm
;
5219 tap
->dbm_antnoise
= RT2860_NOISE_FLOOR
;
5221 tap
->antsignal
= rssi
;
5222 tap
->chan_flags
= htole32(ic
->ic_curchan
->ic_flags
);
5223 tap
->chan_freq
= htole16(ic
->ic_curchan
->ic_freq
);
5224 tap
->chan_ieee
= ic
->ic_curchan
->ic_ieee
;
5225 tap
->chan_maxpow
= 0;
5227 if (phymode
== RT2860_TXWI_PHYMODE_HT_MIXED
|| phymode
== RT2860_TXWI_PHYMODE_HT_GF
)
5228 tap
->rate
= mcs
| IEEE80211_RATE_MCS
;
5230 tap
->rate
= rt2860_rxrate(rxwi
);
5232 if (desc_flags
& RT2860_RXDESC_FLAGS_CRC_ERR
)
5233 tap
->flags
|= IEEE80211_RADIOTAP_F_BADFCS
;
5235 if (desc_flags
& RT2860_RXDESC_FLAGS_FRAG
)
5236 tap
->flags
|= IEEE80211_RADIOTAP_F_FRAG
;
5238 if (rxwi
->bw_mcs
& RT2860_RXWI_MCS_SHOTPRE
)
5239 tap
->flags
|= IEEE80211_RADIOTAP_F_SHORTPRE
;
5241 if ((desc_flags
& RT2860_RXDESC_FLAGS_DECRYPTED
) ||
5242 (wh
->i_fc
[1] & IEEE80211_FC1_WEP
))
5243 tap
->flags
|= IEEE80211_RADIOTAP_F_WEP
;
5246 tap
->flags
|= IEEE80211_RADIOTAP_F_SHORTGI
;
5248 /* XXX use temporarily radiotap CFP flag as A-MPDU flag */
5251 tap
->flags
|= IEEE80211_RADIOTAP_F_CFP
;
5253 bpf_mtap2(sc
->drvbpf
, tap
, sc
->rxtap_len
, m
);
5256 RT2860_DPRINTF(sc
, RT2860_DEBUG_RX
,
5257 "%s: received frame: len=%d, phymode=%d, bw=%d, shortgi=%d, mcs=%d, "
5258 "ant=%d, rssi=%d/%d/%d, snr=%d/%d, wcid=0x%02x, ampdu=%d, amsdu=%d\n",
5259 device_get_nameunit(sc
->dev
),
5260 len
, phymode
, bw
, shortgi
, mcs
,
5261 ant
, rxwi
->rssi
[0], rxwi
->rssi
[1], rxwi
->rssi
[2],
5262 rxwi
->snr
[0], rxwi
->snr
[1],
5263 rxwi
->wcid
, ampdu
, amsdu
);
5265 ni
= ieee80211_find_rxnode(ic
, (struct ieee80211_frame_min
*) wh
);
5269 rni
= (struct rt2860_softc_node
*) ni
;
5271 for (i
= 0; i
< RT2860_SOFTC_RSSI_COUNT
; i
++)
5273 rni
->last_rssi
[i
] = rxwi
->rssi
[i
];
5274 rni
->last_rssi_dbm
[i
] = rt2860_rssi2dbm(sc
, rxwi
->rssi
[i
], i
);
5278 ieee80211_input(ic
, m
, ni
, rssi_dbm
, RT2860_NOISE_FLOOR
, 0);
5280 ieee80211_free_node(ni
);
5284 desc
->sdl0
&= ~htole16(RT2860_RXDESC_SDL0_DDONE
);
5286 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
5287 BUS_DMASYNC_PREREAD
| BUS_DMASYNC_PREWRITE
);
5289 ring
->cur
= (ring
->cur
+ 1) % RT2860_SOFTC_RX_RING_DATA_COUNT
;
5295 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_CALC_IDX
,
5296 RT2860_SOFTC_RX_RING_DATA_COUNT
- 1);
5298 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_CALC_IDX
,
5301 RT2860_DPRINTF(sc
, RT2860_DEBUG_RX
,
5302 "%s: Rx eof: nframes=%d\n",
5303 device_get_nameunit(sc
->dev
), nframes
);
5305 sc
->rx_packets
+= nframes
;
5307 return (limit
== 0);
5313 static void rt2860_tx_eof(struct rt2860_softc
*sc
,
5314 struct rt2860_softc_tx_ring
*ring
)
5317 struct rt2860_txdesc
*desc
;
5318 struct rt2860_softc_tx_data
*data
;
5320 int ndescs
, nframes
;
5329 index
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_TX_DTX_IDX(ring
->qid
));
5330 if (ring
->desc_next
== index
)
5335 rt2860_drain_fifo_stats(sc
);
5337 desc
= &ring
->desc
[ring
->desc_next
];
5339 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
5340 BUS_DMASYNC_POSTREAD
);
5342 if (desc
->sdl0
& htole16(RT2860_TXDESC_SDL0_LASTSEG
) ||
5343 desc
->sdl1
& htole16(RT2860_TXDESC_SDL1_LASTSEG
))
5347 data
= &ring
->data
[ring
->data_next
];
5349 if (data
->m
->m_flags
& M_TXCB
)
5350 ieee80211_process_callback(data
->ni
, data
->m
, 0);
5352 bus_dmamap_sync(ring
->data_dma_tag
, data
->dma_map
,
5353 BUS_DMASYNC_POSTWRITE
);
5354 bus_dmamap_unload(ring
->data_dma_tag
, data
->dma_map
);
5358 ieee80211_free_node(data
->ni
);
5365 RT2860_SOFTC_TX_RING_LOCK(ring
);
5367 ring
->data_queued
--;
5368 ring
->data_next
= (ring
->data_next
+ 1) % RT2860_SOFTC_TX_RING_DATA_COUNT
;
5370 RT2860_SOFTC_TX_RING_UNLOCK(ring
);
5373 desc
->sdl0
&= ~htole16(RT2860_TXDESC_SDL0_DDONE
);
5375 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
5376 BUS_DMASYNC_PREREAD
| BUS_DMASYNC_PREWRITE
);
5378 RT2860_SOFTC_TX_RING_LOCK(ring
);
5380 ring
->desc_queued
--;
5381 ring
->desc_next
= (ring
->desc_next
+ 1) % RT2860_SOFTC_TX_RING_DESC_COUNT
;
5383 RT2860_SOFTC_TX_RING_UNLOCK(ring
);
5386 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
5387 "%s: Tx eof: qid=%d, ndescs=%d, nframes=%d\n",
5388 device_get_nameunit(sc
->dev
), ring
->qid
, ndescs
, nframes
);
5392 * rt2860_update_stats
5394 static void rt2860_update_stats(struct rt2860_softc
*sc
)
5398 int beacons
, noretryok
, retryok
, failed
, underflows
, zerolen
;
5402 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATS
,
5403 "%s: update statistic\n",
5404 device_get_nameunit(sc
->dev
));
5406 rt2860_drain_fifo_stats(sc
);
5408 /* read and clear Tx statistic registers */
5410 rt2860_io_mac_read_multi(sc
, RT2860_REG_TX_STA_CNT0
,
5411 stacnt
, sizeof(stacnt
));
5413 stacnt
[0] = le32toh(stacnt
[0]);
5414 stacnt
[1] = le32toh(stacnt
[1]);
5415 stacnt
[2] = le32toh(stacnt
[2]);
5417 beacons
= stacnt
[0] >> 16;
5418 noretryok
= stacnt
[1] & 0xffff;
5419 retryok
= stacnt
[1] >> 16;
5420 failed
= stacnt
[0] & 0xffff;
5421 underflows
= stacnt
[2] >> 16;
5422 zerolen
= stacnt
[2] & 0xffff;
5424 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATS
,
5425 "%s: update statistic: beacons=%d, noretryok=%d, retryok=%d, failed=%d, underflows=%d, zerolen=%d\n",
5426 device_get_nameunit(sc
->dev
),
5427 beacons
, noretryok
, retryok
, failed
, underflows
, zerolen
);
5429 ifp
->if_oerrors
+= failed
;
5431 sc
->tx_beacons
+= beacons
;
5432 sc
->tx_noretryok
+= noretryok
;
5433 sc
->tx_retryok
+= retryok
;
5434 sc
->tx_failed
+= failed
;
5435 sc
->tx_underflows
+= underflows
;
5436 sc
->tx_zerolen
+= zerolen
;
5442 static void rt2860_bbp_tuning(struct rt2860_softc
*sc
)
5444 struct ieee80211com
*ic
;
5445 struct ieee80211_node
*ni
;
5447 int8_t rssi
, old
, new;
5449 /* RT2860C does not support BBP tuning */
5451 if (sc
->mac_rev
== 0x28600100)
5456 if ((ic
->ic_flags
& IEEE80211_F_SCAN
) ||
5457 ic
->ic_opmode
!= IEEE80211_M_STA
|| ic
->ic_state
!= IEEE80211_S_RUN
)
5462 chan
= ieee80211_chan2ieee(ic
, ni
->ni_chan
);
5466 else if (chan
<= 64)
5468 else if (chan
<= 128)
5473 rssi
= ieee80211_getrssi(ic
);
5475 if (IEEE80211_IS_CHAN_2GHZ(ni
->ni_chan
))
5477 new = 0x2e + sc
->lna_gain
[group
];
5481 if (!IEEE80211_IS_CHAN_HT40(ni
->ni_chan
))
5482 new = 0x32 + sc
->lna_gain
[group
] * 5 / 3;
5484 new = 0x3a + sc
->lna_gain
[group
] * 5 / 3;
5487 /* Tune if absolute average RSSI is greater than -80 */
5492 old
= rt2860_io_bbp_read(sc
, 66);
5495 rt2860_io_bbp_write(sc
, 66, new);
5501 static void rt2860_watchdog(struct rt2860_softc
*sc
)
5506 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_PBF_TXRXQ_PCNT
);
5508 RT2860_DPRINTF(sc
, RT2860_DEBUG_WATCHDOG
,
5509 "%s: watchdog: TXRXQ_PCNT=0x%08x\n",
5510 device_get_nameunit(sc
->dev
), tmp
);
5512 if (((tmp
>> RT2860_REG_TX0Q_PCNT_SHIFT
) & RT2860_REG_TX0Q_PCNT_MASK
) != 0)
5514 sc
->tx_queue_not_empty
[0]++;
5516 rt2860_io_mac_write(sc
, RT2860_REG_PBF_CFG
, 0xf40012);
5518 for (ntries
= 0; ntries
< 10; ntries
++)
5520 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_PBF_TXRXQ_PCNT
);
5521 if (((tmp
>> RT2860_REG_TX0Q_PCNT_SHIFT
) & RT2860_REG_TX0Q_PCNT_MASK
) == 0)
5527 rt2860_io_mac_write(sc
, RT2860_REG_PBF_CFG
, 0xf40006);
5530 if (((tmp
>> RT2860_REG_TX1Q_PCNT_SHIFT
) & RT2860_REG_TX1Q_PCNT_MASK
) != 0)
5532 sc
->tx_queue_not_empty
[1]++;
5534 rt2860_io_mac_write(sc
, RT2860_REG_PBF_CFG
, 0xf4000a);
5536 for (ntries
= 0; ntries
< 10; ntries
++)
5538 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_PBF_TXRXQ_PCNT
);
5539 if (((tmp
>> RT2860_REG_TX1Q_PCNT_SHIFT
) & RT2860_REG_TX1Q_PCNT_MASK
) == 0)
5545 rt2860_io_mac_write(sc
, RT2860_REG_PBF_CFG
, 0xf40006);
5550 * rt2860_drain_fifo_stats
5552 static void rt2860_drain_fifo_stats(struct rt2860_softc
*sc
)
5556 uint8_t wcid
, mcs
, pid
;
5557 int ok
, agg
, retrycnt
;
5559 ifp
= sc
->ic
.ic_ifp
;
5561 /* drain Tx status FIFO (maxsize = 16) */
5563 while ((stats
= rt2860_io_mac_read(sc
, RT2860_REG_TX_STA_FIFO
)) &
5564 RT2860_REG_TX_STA_FIFO_VALID
)
5566 wcid
= (stats
>> RT2860_REG_TX_STA_FIFO_WCID_SHIFT
) &
5567 RT2860_REG_TX_STA_FIFO_WCID_MASK
;
5569 /* if no ACK was requested, no feedback is available */
5571 if (!(stats
& RT2860_REG_TX_STA_FIFO_ACK_REQ
) || wcid
== RT2860_WCID_RESERVED
)
5574 /* update AMRR statistic */
5576 ok
= (stats
& RT2860_REG_TX_STA_FIFO_TX_OK
) ? 1 : 0;
5577 agg
= (stats
& RT2860_REG_TX_STA_FIFO_AGG
) ? 1 : 0;
5578 mcs
= (stats
>> RT2860_REG_TX_STA_FIFO_MCS_SHIFT
) &
5579 RT2860_REG_TX_STA_FIFO_MCS_MASK
;
5580 pid
= (stats
>> RT2860_REG_TX_STA_FIFO_PID_SHIFT
) &
5581 RT2860_REG_TX_STA_FIFO_PID_MASK
;
5582 retrycnt
= (mcs
< 0xf) ? (pid
- mcs
- 1) : 0;
5584 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATS
,
5585 "%s: FIFO statistic: wcid=0x%02x, ok=%d, agg=%d, mcs=0x%02x, pid=0x%02x, retrycnt=%d\n",
5586 device_get_nameunit(sc
->dev
),
5587 wcid
, ok
, agg
, mcs
, pid
, retrycnt
);
5589 rt2860_amrr_tx_complete(&sc
->amrr_node
[wcid
], ok
, retrycnt
);
5597 * rt2860_update_raw_counters
5599 static void rt2860_update_raw_counters(struct rt2860_softc
*sc
)
5603 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_AGG_CNT
);
5605 sc
->tx_nonagg
+= tmp
& 0xffff;
5606 sc
->tx_agg
+= tmp
>> 16;
5608 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_AGG_CNT0
);
5610 sc
->tx_ampdu
+= (tmp
& 0xffff) / 1 + (tmp
>> 16) / 2;
5612 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_AGG_CNT1
);
5614 sc
->tx_ampdu
+= (tmp
& 0xffff) / 3 + (tmp
>> 16) / 4;
5616 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_AGG_CNT2
);
5618 sc
->tx_ampdu
+= (tmp
& 0xffff) / 5 + (tmp
>> 16) / 6;
5620 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_AGG_CNT3
);
5622 sc
->tx_ampdu
+= (tmp
& 0xffff) / 7 + (tmp
>> 16) / 8;
5624 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_AGG_CNT4
);
5626 sc
->tx_ampdu
+= (tmp
& 0xffff) / 9 + (tmp
>> 16) / 10;
5628 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_AGG_CNT5
);
5630 sc
->tx_ampdu
+= (tmp
& 0xffff) / 11 + (tmp
>> 16) / 12;
5632 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_AGG_CNT6
);
5634 sc
->tx_ampdu
+= (tmp
& 0xffff) / 13 + (tmp
>> 16) / 14;
5636 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_AGG_CNT7
);
5638 sc
->tx_ampdu
+= (tmp
& 0xffff) / 15 + (tmp
>> 16) / 16;
5640 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_RX_STA_CNT0
);
5642 sc
->rx_crc_errors
+= tmp
& 0xffff;
5643 sc
->rx_phy_errors
+= tmp
>> 16;
5645 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_RX_STA_CNT1
);
5647 sc
->rx_false_ccas
+= tmp
& 0xffff;
5648 sc
->rx_plcp_errors
+= tmp
>> 16;
5650 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_RX_STA_CNT2
);
5652 sc
->rx_dup_packets
+= tmp
& 0xffff;
5653 sc
->rx_fifo_overflows
+= tmp
>> 16;
5655 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TXRX_MPDU_DEN_CNT
);
5657 sc
->tx_mpdu_zero_density
+= tmp
& 0xffff;
5658 sc
->rx_mpdu_zero_density
+= tmp
>> 16;
5662 * rt2860_intr_enable
5664 static void rt2860_intr_enable(struct rt2860_softc
*sc
, uint32_t intr_mask
)
5668 sc
->intr_disable_mask
&= ~intr_mask
;
5670 tmp
= sc
->intr_enable_mask
& ~sc
->intr_disable_mask
;
5672 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_INT_MASK
, tmp
);
5676 * rt2860_intr_disable
5678 static void rt2860_intr_disable(struct rt2860_softc
*sc
, uint32_t intr_mask
)
5682 sc
->intr_disable_mask
|= intr_mask
;
5684 tmp
= sc
->intr_enable_mask
& ~sc
->intr_disable_mask
;
5686 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_INT_MASK
, tmp
);
5690 * rt2860_txrx_enable
5692 static int rt2860_txrx_enable(struct rt2860_softc
*sc
)
5694 struct ieee80211com
*ic
;
5702 /* enable Tx/Rx DMA engine */
5704 rt2860_io_mac_write(sc
, RT2860_REG_SYS_CTRL
, RT2860_REG_TX_ENABLE
);
5706 for (ntries
= 0; ntries
< 200; ntries
++)
5708 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
);
5709 if (!(tmp
& (RT2860_REG_TX_DMA_BUSY
| RT2860_REG_RX_DMA_BUSY
)))
5717 printf("%s: timeout waiting for DMA engine\n",
5718 device_get_nameunit(sc
->dev
));
5724 tmp
|= RT2860_REG_TX_WB_DDONE
|
5725 RT2860_REG_RX_DMA_ENABLE
|
5726 RT2860_REG_TX_DMA_ENABLE
|
5727 (RT2860_REG_WPDMA_BT_SIZE64
<< RT2860_REG_WPDMA_BT_SIZE_SHIFT
);
5729 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
, tmp
);
5733 tmp
= RT2860_REG_RX_FILTER_DROP_CRC_ERR
|
5734 RT2860_REG_RX_FILTER_DROP_PHY_ERR
;
5736 if (ic
->ic_opmode
!= IEEE80211_M_MONITOR
)
5738 tmp
|= RT2860_REG_RX_FILTER_DROP_DUPL
|
5739 RT2860_REG_RX_FILTER_DROP_CTS
|
5740 RT2860_REG_RX_FILTER_DROP_BA
|
5741 RT2860_REG_RX_FILTER_DROP_ACK
|
5742 RT2860_REG_RX_FILTER_DROP_VER_ERR
|
5743 RT2860_REG_RX_FILTER_DROP_CTRL_RSV
|
5744 RT2860_REG_RX_FILTER_DROP_CFACK
|
5745 RT2860_REG_RX_FILTER_DROP_CFEND
;
5747 if (ic
->ic_opmode
== IEEE80211_M_STA
)
5748 tmp
|= RT2860_REG_RX_FILTER_DROP_RTS
|
5749 RT2860_REG_RX_FILTER_DROP_PSPOLL
;
5751 if (!(ifp
->if_flags
& IFF_PROMISC
))
5752 tmp
|= RT2860_REG_RX_FILTER_DROP_UC_NOME
;
5755 rt2860_io_mac_write(sc
, RT2860_REG_RX_FILTER_CFG
, tmp
);
5757 rt2860_io_mac_write(sc
, RT2860_REG_SYS_CTRL
,
5758 RT2860_REG_RX_ENABLE
| RT2860_REG_TX_ENABLE
);
5764 * rt2860_alloc_rx_ring
5766 static int rt2860_alloc_rx_ring(struct rt2860_softc
*sc
,
5767 struct rt2860_softc_rx_ring
*ring
)
5769 struct rt2860_rxdesc
*desc
;
5770 struct rt2860_softc_rx_data
*data
;
5771 bus_dma_segment_t segs
[1];
5772 int i
, nsegs
, error
;
5774 error
= bus_dma_tag_create(bus_get_dma_tag(sc
->dev
), PAGE_SIZE
, 0,
5775 BUS_SPACE_MAXADDR_32BIT
, BUS_SPACE_MAXADDR
, NULL
, NULL
,
5776 RT2860_SOFTC_RX_RING_DATA_COUNT
* sizeof(struct rt2860_rxdesc
), 1,
5777 RT2860_SOFTC_RX_RING_DATA_COUNT
* sizeof(struct rt2860_rxdesc
),
5778 0, NULL
, NULL
, &ring
->desc_dma_tag
);
5781 printf("%s: could not create Rx desc DMA tag\n",
5782 device_get_nameunit(sc
->dev
));
5786 error
= bus_dmamem_alloc(ring
->desc_dma_tag
, (void **) &ring
->desc
,
5787 BUS_DMA_NOWAIT
| BUS_DMA_ZERO
, &ring
->desc_dma_map
);
5790 printf("%s: could not allocate Rx desc DMA memory\n",
5791 device_get_nameunit(sc
->dev
));
5795 error
= bus_dmamap_load(ring
->desc_dma_tag
, ring
->desc_dma_map
,
5797 RT2860_SOFTC_RX_RING_DATA_COUNT
* sizeof(struct rt2860_rxdesc
),
5798 rt2860_dma_map_addr
, &ring
->desc_phys_addr
, 0);
5801 printf("%s: could not load Rx desc DMA map\n",
5802 device_get_nameunit(sc
->dev
));
5806 error
= bus_dma_tag_create(bus_get_dma_tag(sc
->dev
), PAGE_SIZE
, 0,
5807 BUS_SPACE_MAXADDR_32BIT
, BUS_SPACE_MAXADDR
, NULL
, NULL
,
5808 MJUMPAGESIZE
, 1, MJUMPAGESIZE
, 0, NULL
, NULL
,
5809 &ring
->data_dma_tag
);
5812 printf("%s: could not create Rx data DMA tag\n",
5813 device_get_nameunit(sc
->dev
));
5817 for (i
= 0; i
< RT2860_SOFTC_RX_RING_DATA_COUNT
; i
++)
5819 desc
= &ring
->desc
[i
];
5820 data
= &ring
->data
[i
];
5822 error
= bus_dmamap_create(ring
->data_dma_tag
, 0, &data
->dma_map
);
5825 printf("%s: could not create Rx data DMA map\n",
5826 device_get_nameunit(sc
->dev
));
5830 data
->m
= m_getjcl(M_DONTWAIT
, MT_DATA
, M_PKTHDR
, MJUMPAGESIZE
);
5831 if (data
->m
== NULL
)
5833 printf("%s: could not allocate Rx mbuf\n",
5834 device_get_nameunit(sc
->dev
));
5839 data
->m
->m_len
= data
->m
->m_pkthdr
.len
= MJUMPAGESIZE
;
5841 error
= bus_dmamap_load_mbuf_sg(ring
->data_dma_tag
, data
->dma_map
,
5842 data
->m
, segs
, &nsegs
, BUS_DMA_NOWAIT
);
5845 printf("%s: could not load Rx mbuf DMA map\n",
5846 device_get_nameunit(sc
->dev
));
5850 KASSERT(nsegs
== 1, ("%s: too many DMA segments",
5851 device_get_name(sc
->dev
)));
5853 desc
->sdp0
= htole32(segs
[0].ds_addr
);
5854 desc
->sdl0
= htole16(MJUMPAGESIZE
);
5857 error
= bus_dmamap_create(ring
->data_dma_tag
, 0, &ring
->spare_dma_map
);
5860 printf("%s: could not create Rx spare DMA map\n",
5861 device_get_nameunit(sc
->dev
));
5865 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
5866 BUS_DMASYNC_PREWRITE
);
5872 rt2860_free_rx_ring(sc
, ring
);
5878 * rt2860_reset_rx_ring
5880 static void rt2860_reset_rx_ring(struct rt2860_softc
*sc
,
5881 struct rt2860_softc_rx_ring
*ring
)
5883 struct rt2860_rxdesc
*desc
;
5886 for (i
= 0; i
< RT2860_SOFTC_RX_RING_DATA_COUNT
; i
++)
5888 desc
= &ring
->desc
[i
];
5890 desc
->sdl0
&= ~htole16(RT2860_RXDESC_SDL0_DDONE
);
5893 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
5894 BUS_DMASYNC_PREWRITE
);
5900 * rt2860_free_rx_ring
5902 static void rt2860_free_rx_ring(struct rt2860_softc
*sc
,
5903 struct rt2860_softc_rx_ring
*ring
)
5905 struct rt2860_softc_rx_data
*data
;
5908 if (ring
->desc
!= NULL
)
5910 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
5911 BUS_DMASYNC_POSTWRITE
);
5912 bus_dmamap_unload(ring
->desc_dma_tag
, ring
->desc_dma_map
);
5913 bus_dmamem_free(ring
->desc_dma_tag
, ring
->desc
,
5914 ring
->desc_dma_map
);
5917 if (ring
->desc_dma_tag
!= NULL
)
5918 bus_dma_tag_destroy(ring
->desc_dma_tag
);
5920 for (i
= 0; i
< RT2860_SOFTC_RX_RING_DATA_COUNT
; i
++)
5922 data
= &ring
->data
[i
];
5924 if (data
->m
!= NULL
)
5926 bus_dmamap_sync(ring
->data_dma_tag
, data
->dma_map
,
5927 BUS_DMASYNC_POSTREAD
);
5928 bus_dmamap_unload(ring
->data_dma_tag
, data
->dma_map
);
5932 if (data
->dma_map
!= NULL
)
5933 bus_dmamap_destroy(ring
->data_dma_tag
, data
->dma_map
);
5936 if (ring
->spare_dma_map
!= NULL
)
5937 bus_dmamap_destroy(ring
->data_dma_tag
, ring
->spare_dma_map
);
5939 if (ring
->data_dma_tag
!= NULL
)
5940 bus_dma_tag_destroy(ring
->data_dma_tag
);
5944 * rt2860_alloc_tx_ring
5946 static int rt2860_alloc_tx_ring(struct rt2860_softc
*sc
,
5947 struct rt2860_softc_tx_ring
*ring
, int qid
)
5949 struct rt2860_softc_tx_data
*data
;
5952 mtx_init(&ring
->lock
, device_get_nameunit(sc
->dev
), NULL
, MTX_DEF
);
5954 error
= bus_dma_tag_create(bus_get_dma_tag(sc
->dev
), PAGE_SIZE
, 0,
5955 BUS_SPACE_MAXADDR_32BIT
, BUS_SPACE_MAXADDR
, NULL
, NULL
,
5956 RT2860_SOFTC_TX_RING_DESC_COUNT
* sizeof(struct rt2860_txdesc
), 1,
5957 RT2860_SOFTC_TX_RING_DESC_COUNT
* sizeof(struct rt2860_txdesc
),
5958 0, NULL
, NULL
, &ring
->desc_dma_tag
);
5961 printf("%s: could not create Tx desc DMA tag\n",
5962 device_get_nameunit(sc
->dev
));
5966 error
= bus_dmamem_alloc(ring
->desc_dma_tag
, (void **) &ring
->desc
,
5967 BUS_DMA_NOWAIT
| BUS_DMA_ZERO
, &ring
->desc_dma_map
);
5970 printf("%s: could not allocate Tx desc DMA memory\n",
5971 device_get_nameunit(sc
->dev
));
5975 error
= bus_dmamap_load(ring
->desc_dma_tag
, ring
->desc_dma_map
,
5977 RT2860_SOFTC_TX_RING_DESC_COUNT
* sizeof(struct rt2860_txdesc
),
5978 rt2860_dma_map_addr
, &ring
->desc_phys_addr
, 0);
5981 printf("%s: could not load Tx desc DMA map\n",
5982 device_get_nameunit(sc
->dev
));
5986 ring
->desc_queued
= 0;
5988 ring
->desc_next
= 0;
5990 error
= bus_dma_tag_create(bus_get_dma_tag(sc
->dev
), PAGE_SIZE
, 0,
5991 BUS_SPACE_MAXADDR_32BIT
, BUS_SPACE_MAXADDR
, NULL
, NULL
,
5992 RT2860_SOFTC_TX_RING_DATA_COUNT
* RT2860_TX_DATA_SEG0_SIZE
, 1,
5993 RT2860_SOFTC_TX_RING_DATA_COUNT
* RT2860_TX_DATA_SEG0_SIZE
,
5994 0, NULL
, NULL
, &ring
->seg0_dma_tag
);
5997 printf("%s: could not create Tx seg0 DMA tag\n",
5998 device_get_nameunit(sc
->dev
));
6002 error
= bus_dmamem_alloc(ring
->seg0_dma_tag
, (void **) &ring
->seg0
,
6003 BUS_DMA_NOWAIT
| BUS_DMA_ZERO
, &ring
->seg0_dma_map
);
6006 printf("%s: could not allocate Tx seg0 DMA memory\n",
6007 device_get_nameunit(sc
->dev
));
6011 error
= bus_dmamap_load(ring
->seg0_dma_tag
, ring
->seg0_dma_map
,
6013 RT2860_SOFTC_TX_RING_DATA_COUNT
* RT2860_TX_DATA_SEG0_SIZE
,
6014 rt2860_dma_map_addr
, &ring
->seg0_phys_addr
, 0);
6017 printf("%s: could not load Tx seg0 DMA map\n",
6018 device_get_nameunit(sc
->dev
));
6022 error
= bus_dma_tag_create(bus_get_dma_tag(sc
->dev
), PAGE_SIZE
, 0,
6023 BUS_SPACE_MAXADDR_32BIT
, BUS_SPACE_MAXADDR
, NULL
, NULL
,
6024 MJUMPAGESIZE
, RT2860_SOFTC_MAX_SCATTER
, MJUMPAGESIZE
, 0, NULL
, NULL
,
6025 &ring
->data_dma_tag
);
6028 printf("%s: could not create Tx data DMA tag\n",
6029 device_get_nameunit(sc
->dev
));
6033 for (i
= 0; i
< RT2860_SOFTC_TX_RING_DATA_COUNT
; i
++)
6035 data
= &ring
->data
[i
];
6037 error
= bus_dmamap_create(ring
->data_dma_tag
, 0, &data
->dma_map
);
6040 printf("%s: could not create Tx data DMA map\n",
6041 device_get_nameunit(sc
->dev
));
6046 ring
->data_queued
= 0;
6048 ring
->data_next
= 0;
6056 rt2860_free_tx_ring(sc
, ring
);
6062 * rt2860_reset_tx_ring
6064 static void rt2860_reset_tx_ring(struct rt2860_softc
*sc
,
6065 struct rt2860_softc_tx_ring
*ring
)
6067 struct rt2860_softc_tx_data
*data
;
6068 struct rt2860_txdesc
*desc
;
6071 for (i
= 0; i
< RT2860_SOFTC_TX_RING_DESC_COUNT
; i
++)
6073 desc
= &ring
->desc
[i
];
6079 ring
->desc_queued
= 0;
6081 ring
->desc_next
= 0;
6083 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
6084 BUS_DMASYNC_PREWRITE
);
6086 bus_dmamap_sync(ring
->seg0_dma_tag
, ring
->seg0_dma_map
,
6087 BUS_DMASYNC_PREWRITE
);
6089 for (i
= 0; i
< RT2860_SOFTC_TX_RING_DATA_COUNT
; i
++)
6091 data
= &ring
->data
[i
];
6093 if (data
->m
!= NULL
)
6095 bus_dmamap_sync(ring
->data_dma_tag
, data
->dma_map
,
6096 BUS_DMASYNC_POSTWRITE
);
6097 bus_dmamap_unload(ring
->data_dma_tag
, data
->dma_map
);
6102 if (data
->ni
!= NULL
)
6104 ieee80211_free_node(data
->ni
);
6109 ring
->data_queued
= 0;
6111 ring
->data_next
= 0;
6115 * rt2860_free_tx_ring
6117 static void rt2860_free_tx_ring(struct rt2860_softc
*sc
,
6118 struct rt2860_softc_tx_ring
*ring
)
6120 struct rt2860_softc_tx_data
*data
;
6123 if (ring
->desc
!= NULL
)
6125 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
6126 BUS_DMASYNC_POSTWRITE
);
6127 bus_dmamap_unload(ring
->desc_dma_tag
, ring
->desc_dma_map
);
6128 bus_dmamem_free(ring
->desc_dma_tag
, ring
->desc
,
6129 ring
->desc_dma_map
);
6132 if (ring
->desc_dma_tag
!= NULL
)
6133 bus_dma_tag_destroy(ring
->desc_dma_tag
);
6135 if (ring
->seg0
!= NULL
)
6137 bus_dmamap_sync(ring
->seg0_dma_tag
, ring
->seg0_dma_map
,
6138 BUS_DMASYNC_POSTWRITE
);
6139 bus_dmamap_unload(ring
->seg0_dma_tag
, ring
->seg0_dma_map
);
6140 bus_dmamem_free(ring
->seg0_dma_tag
, ring
->seg0
,
6141 ring
->seg0_dma_map
);
6144 if (ring
->seg0_dma_tag
!= NULL
)
6145 bus_dma_tag_destroy(ring
->seg0_dma_tag
);
6147 for (i
= 0; i
< RT2860_SOFTC_TX_RING_DATA_COUNT
; i
++)
6149 data
= &ring
->data
[i
];
6151 if (data
->m
!= NULL
)
6153 bus_dmamap_sync(ring
->data_dma_tag
, data
->dma_map
,
6154 BUS_DMASYNC_POSTWRITE
);
6155 bus_dmamap_unload(ring
->data_dma_tag
, data
->dma_map
);
6159 if (data
->ni
!= NULL
)
6160 ieee80211_free_node(data
->ni
);
6162 if (data
->dma_map
!= NULL
)
6163 bus_dmamap_destroy(ring
->data_dma_tag
, data
->dma_map
);
6166 if (ring
->data_dma_tag
!= NULL
)
6167 bus_dma_tag_destroy(ring
->data_dma_tag
);
6169 mtx_destroy(&ring
->lock
);
6173 * rt2860_dma_map_addr
6175 static void rt2860_dma_map_addr(void *arg
, bus_dma_segment_t
*segs
,
6176 int nseg
, int error
)
6181 KASSERT(nseg
== 1, ("too many DMA segments, %d should be 1", nseg
));
6183 *(bus_addr_t
*) arg
= segs
[0].ds_addr
;
6187 * rt2860_sysctl_attach
6189 static void rt2860_sysctl_attach(struct rt2860_softc
*sc
)
6191 struct sysctl_ctx_list
*ctx
;
6192 struct sysctl_oid
*tree
;
6193 struct sysctl_oid
*stats
;
6195 ctx
= device_get_sysctl_ctx(sc
->dev
);
6196 tree
= device_get_sysctl_tree(sc
->dev
);
6198 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(tree
), OID_AUTO
,
6199 "tx_stbc", CTLFLAG_RW
, &sc
->tx_stbc
, 0,
6202 /* statistic counters */
6204 stats
= SYSCTL_ADD_NODE(ctx
, SYSCTL_CHILDREN(tree
), OID_AUTO
,
6205 "stats", CTLFLAG_RD
, 0, "statistic");
6207 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6208 "interrupts", CTLFLAG_RD
, &sc
->interrupts
, 0,
6211 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6212 "tx_coherent_interrupts", CTLFLAG_RD
, &sc
->tx_coherent_interrupts
, 0,
6213 "Tx coherent interrupts");
6215 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6216 "rx_coherent_interrupts", CTLFLAG_RD
, &sc
->rx_coherent_interrupts
, 0,
6217 "Rx coherent interrupts");
6219 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6220 "txrx_coherent_interrupts", CTLFLAG_RD
, &sc
->txrx_coherent_interrupts
, 0,
6221 "Tx/Rx coherent interrupts");
6223 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6224 "fifo_sta_full_interrupts", CTLFLAG_RD
, &sc
->fifo_sta_full_interrupts
, 0,
6225 "FIFO statistic full interrupts");
6227 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6228 "rx_interrupts", CTLFLAG_RD
, &sc
->rx_interrupts
, 0,
6231 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6232 "rx_delay_interrupts", CTLFLAG_RD
, &sc
->rx_delay_interrupts
, 0,
6233 "Rx delay interrupts");
6235 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6236 "tx_mgmt_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[5], 0,
6237 "Tx MGMT interrupts");
6239 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6240 "tx_hcca_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[4], 0,
6241 "Tx HCCA interrupts");
6243 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6244 "tx_ac3_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[3], 0,
6245 "Tx AC3 interrupts");
6247 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6248 "tx_ac2_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[2], 0,
6249 "Tx AC2 interrupts");
6251 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6252 "tx_ac1_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[1], 0,
6253 "Tx AC1 interrupts");
6255 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6256 "tx_ac0_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[0], 0,
6257 "Tx AC0 interrupts");
6259 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6260 "tx_delay_interrupts", CTLFLAG_RD
, &sc
->tx_delay_interrupts
, 0,
6261 "Tx delay interrupts");
6263 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6264 "pre_tbtt_interrupts", CTLFLAG_RD
, &sc
->pre_tbtt_interrupts
, 0,
6265 "Pre-TBTT interrupts");
6267 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6268 "tbtt_interrupts", CTLFLAG_RD
, &sc
->tbtt_interrupts
, 0,
6271 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6272 "mcu_cmd_interrupts", CTLFLAG_RD
, &sc
->mcu_cmd_interrupts
, 0,
6273 "MCU command interrupts");
6275 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6276 "auto_wakeup_interrupts", CTLFLAG_RD
, &sc
->auto_wakeup_interrupts
, 0,
6277 "auto wakeup interrupts");
6279 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6280 "gp_timer_interrupts", CTLFLAG_RD
, &sc
->gp_timer_interrupts
, 0,
6281 "GP timer interrupts");
6283 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6284 "tx_mgmt_desc_queued", CTLFLAG_RD
, &sc
->tx_ring
[5].desc_queued
, 0,
6285 "Tx MGMT descriptors queued");
6287 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6288 "tx_mgmt_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[5].data_queued
, 0,
6289 "Tx MGMT data queued");
6291 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6292 "tx_hcca_desc_queued", CTLFLAG_RD
, &sc
->tx_ring
[4].desc_queued
, 0,
6293 "Tx HCCA descriptors queued");
6295 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6296 "tx_hcca_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[4].data_queued
, 0,
6297 "Tx HCCA data queued");
6299 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6300 "tx_ac3_desc_queued", CTLFLAG_RD
, &sc
->tx_ring
[3].desc_queued
, 0,
6301 "Tx AC3 descriptors queued");
6303 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6304 "tx_ac3_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[3].data_queued
, 0,
6305 "Tx AC3 data queued");
6307 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6308 "tx_ac2_desc_queued", CTLFLAG_RD
, &sc
->tx_ring
[2].desc_queued
, 0,
6309 "Tx AC2 descriptors queued");
6311 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6312 "tx_ac2_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[2].data_queued
, 0,
6313 "Tx AC2 data queued");
6315 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6316 "tx_ac1_desc_queued", CTLFLAG_RD
, &sc
->tx_ring
[1].desc_queued
, 0,
6317 "Tx AC1 descriptors queued");
6319 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6320 "tx_ac1_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[1].data_queued
, 0,
6321 "Tx AC1 data queued");
6323 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6324 "tx_ac0_desc_queued", CTLFLAG_RD
, &sc
->tx_ring
[0].desc_queued
, 0,
6325 "Tx AC0 descriptors queued");
6327 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6328 "tx_ac0_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[0].data_queued
, 0,
6329 "Tx AC0 data queued");
6331 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6332 "tx_mgmt_data_queue_full", CTLFLAG_RD
, &sc
->tx_data_queue_full
[5], 0,
6333 "Tx MGMT data queue full");
6335 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6336 "tx_hcca_data_queue_full", CTLFLAG_RD
, &sc
->tx_data_queue_full
[4], 0,
6337 "Tx HCCA data queue full");
6339 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6340 "tx_ac3_data_queue_full", CTLFLAG_RD
, &sc
->tx_data_queue_full
[3], 0,
6341 "Tx AC3 data queue full");
6343 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6344 "tx_ac2_data_queue_full", CTLFLAG_RD
, &sc
->tx_data_queue_full
[2], 0,
6345 "Tx AC2 data queue full");
6347 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6348 "tx_ac1_data_queue_full", CTLFLAG_RD
, &sc
->tx_data_queue_full
[1], 0,
6349 "Tx AC1 data queue full");
6351 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6352 "tx_ac0_data_queue_full", CTLFLAG_RD
, &sc
->tx_data_queue_full
[0], 0,
6353 "Tx AC0 data queue full");
6355 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6356 "tx_watchdog_timeouts", CTLFLAG_RD
, &sc
->tx_watchdog_timeouts
, 0,
6357 "Tx watchdog timeouts");
6359 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6360 "tx_defrag_packets", CTLFLAG_RD
, &sc
->tx_defrag_packets
, 0,
6361 "Tx defragmented packets");
6363 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6364 "no_tx_desc_avail", CTLFLAG_RD
, &sc
->no_tx_desc_avail
, 0,
6365 "no Tx descriptors available");
6367 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6368 "rx_mbuf_alloc_errors", CTLFLAG_RD
, &sc
->rx_mbuf_alloc_errors
, 0,
6369 "Rx mbuf allocation errors");
6371 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6372 "rx_mbuf_dmamap_errors", CTLFLAG_RD
, &sc
->rx_mbuf_dmamap_errors
, 0,
6373 "Rx mbuf DMA mapping errors");
6375 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6376 "tx_queue_0_not_empty", CTLFLAG_RD
, &sc
->tx_queue_not_empty
[0], 0,
6377 "Tx queue 0 not empty");
6379 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6380 "tx_queue_1_not_empty", CTLFLAG_RD
, &sc
->tx_queue_not_empty
[1], 0,
6381 "Tx queue 1 not empty");
6383 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6384 "tx_beacons", CTLFLAG_RD
, &sc
->tx_beacons
, 0,
6387 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6388 "tx_noretryok", CTLFLAG_RD
, &sc
->tx_noretryok
, 0,
6389 "Tx successfull without retries");
6391 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6392 "tx_retryok", CTLFLAG_RD
, &sc
->tx_retryok
, 0,
6393 "Tx successfull with retries");
6395 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6396 "tx_failed", CTLFLAG_RD
, &sc
->tx_failed
, 0,
6399 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6400 "tx_underflows", CTLFLAG_RD
, &sc
->tx_underflows
, 0,
6403 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6404 "tx_zerolen", CTLFLAG_RD
, &sc
->tx_zerolen
, 0,
6407 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6408 "tx_nonagg", CTLFLAG_RD
, &sc
->tx_nonagg
, 0,
6409 "Tx non-aggregated");
6411 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6412 "tx_agg", CTLFLAG_RD
, &sc
->tx_agg
, 0,
6415 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6416 "tx_ampdu", CTLFLAG_RD
, &sc
->tx_ampdu
, 0,
6419 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6420 "tx_mpdu_zero_density", CTLFLAG_RD
, &sc
->tx_mpdu_zero_density
, 0,
6421 "Tx MPDU with zero density");
6423 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6424 "tx_ampdu_sessions", CTLFLAG_RD
, &sc
->tx_ampdu_sessions
, 0,
6425 "Tx A-MPDU sessions");
6427 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6428 "rx_packets", CTLFLAG_RD
, &sc
->rx_packets
, 0,
6431 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6432 "rx_ampdu", CTLFLAG_RD
, &sc
->rx_ampdu
, 0,
6435 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6436 "rx_mpdu_zero_density", CTLFLAG_RD
, &sc
->rx_mpdu_zero_density
, 0,
6437 "Rx MPDU with zero density");
6439 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6440 "rx_ampdu_sessions", CTLFLAG_RD
, &sc
->rx_ampdu_sessions
, 0,
6441 "Rx A-MPDU sessions");
6443 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6444 "rx_amsdu", CTLFLAG_RD
, &sc
->rx_amsdu
, 0,
6447 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6448 "rx_crc_errors", CTLFLAG_RD
, &sc
->rx_crc_errors
, 0,
6451 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6452 "rx_phy_errors", CTLFLAG_RD
, &sc
->rx_phy_errors
, 0,
6455 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6456 "rx_false_ccas", CTLFLAG_RD
, &sc
->rx_false_ccas
, 0,
6459 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6460 "rx_plcp_errors", CTLFLAG_RD
, &sc
->rx_plcp_errors
, 0,
6463 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6464 "rx_dup_packets", CTLFLAG_RD
, &sc
->rx_dup_packets
, 0,
6465 "Rx duplicate packets");
6467 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6468 "rx_fifo_overflows", CTLFLAG_RD
, &sc
->rx_fifo_overflows
, 0,
6469 "Rx FIFO overflows");
6471 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6472 "rx_cipher_no_errors", CTLFLAG_RD
, &sc
->rx_cipher_no_errors
, 0,
6473 "Rx cipher no errors");
6475 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6476 "rx_cipher_icv_errors", CTLFLAG_RD
, &sc
->rx_cipher_icv_errors
, 0,
6477 "Rx cipher ICV errors");
6479 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6480 "rx_cipher_mic_errors", CTLFLAG_RD
, &sc
->rx_cipher_mic_errors
, 0,
6481 "Rx cipher MIC errors");
6483 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6484 "rx_cipher_invalid_key_errors", CTLFLAG_RD
, &sc
->rx_cipher_invalid_key_errors
, 0,
6485 "Rx cipher invalid key errors");
6488 static device_method_t rt2860_dev_methods
[] =
6490 DEVMETHOD(device_probe
, rt2860_probe
),
6491 DEVMETHOD(device_attach
, rt2860_attach
),
6492 DEVMETHOD(device_detach
, rt2860_detach
),
6493 DEVMETHOD(device_shutdown
, rt2860_shutdown
),
6494 DEVMETHOD(device_suspend
, rt2860_suspend
),
6495 DEVMETHOD(device_resume
, rt2860_resume
),
6499 static driver_t rt2860_driver
=
6503 sizeof(struct rt2860_softc
)
6506 static devclass_t rt2860_dev_class
;
6508 DRIVER_MODULE(rt2860
, pci
, rt2860_driver
, rt2860_dev_class
, 0, 0);
6510 MODULE_DEPEND(rt2860
, pci
, 1, 1, 1);
6511 MODULE_DEPEND(rt2860
, wlan
, 1, 1, 1);