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
= 0;
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
);
1434 tmp = rt2860_io_mac_read(sc, RT2860_REG_SCHDMA_GPIO_CTRL_CFG);
1437 rt2860_io_mcu_cmd(sc, RT2860_IO_MCU_CMD_SLEEP,
1438 RT2860_REG_H2M_TOKEN_RADIOOFF, 0x02ff);
1439 rt2860_io_mcu_cmd_check(sc, RT2860_REG_H2M_TOKEN_RADIOOFF);
1441 rt2860_io_mcu_cmd(sc, RT2860_IO_MCU_CMD_WAKEUP,
1442 RT2860_REG_H2M_TOKEN_WAKEUP, 0);
1443 rt2860_io_mcu_cmd_check(sc, RT2860_REG_H2M_TOKEN_WAKEUP);
1447 /* disable non-existing Rx chains */
1449 tmp
= rt2860_io_bbp_read(sc
, 3);
1451 tmp
&= ~((1 << 4) | (1 << 3));
1453 if (sc
->nrxpath
== 3)
1455 else if (sc
->nrxpath
== 2)
1458 rt2860_io_bbp_write(sc
, 3, tmp
);
1460 /* disable non-existing Tx chains */
1462 tmp
= rt2860_io_bbp_read(sc
, 1);
1464 tmp
&= ~((1 << 4) | (1 << 3));
1466 if (sc
->ntxpath
== 2)
1469 rt2860_io_bbp_write(sc
, 1, tmp
);
1471 /* set current channel */
1473 rt2860_rf_set_chan(sc
, ic
->ic_curchan
);
1475 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WMM_TXOP0_CFG
, 0);
1476 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WMM_TXOP1_CFG
,
1479 if ((sc
->mac_rev
& 0xffff) != 0x0101)
1480 rt2860_io_mac_write(sc
, RT2860_REG_TX_TXOP_CTRL_CFG
, 0x583f);
1482 /* clear pending interrupts */
1484 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_INT_STATUS
, 0xffffffff);
1486 /* enable interrupts */
1488 tmp
= RT2860_REG_INT_TX_COHERENT
|
1489 RT2860_REG_INT_RX_COHERENT
|
1490 RT2860_REG_INT_GP_TIMER
|
1491 RT2860_REG_INT_AUTO_WAKEUP
|
1492 RT2860_REG_INT_FIFO_STA_FULL
|
1494 RT2860_REG_INT_PRE_TBTT |
1495 RT2860_REG_INT_TBTT |
1497 RT2860_REG_INT_TXRX_COHERENT
|
1498 RT2860_REG_INT_MCU_CMD
|
1499 RT2860_REG_INT_TX_MGMT_DONE
|
1500 RT2860_REG_INT_TX_HCCA_DONE
|
1501 RT2860_REG_INT_TX_AC3_DONE
|
1502 RT2860_REG_INT_TX_AC2_DONE
|
1503 RT2860_REG_INT_TX_AC1_DONE
|
1504 RT2860_REG_INT_TX_AC0_DONE
|
1505 RT2860_REG_INT_RX_DONE
;
1507 sc
->intr_enable_mask
= tmp
;
1509 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_INT_MASK
, tmp
);
1511 if (rt2860_txrx_enable(sc
) != 0)
1514 /* clear garbage interrupts */
1516 tmp
= rt2860_io_mac_read(sc
, 0x1300);
1518 ifp
->if_drv_flags
&= ~IFF_DRV_OACTIVE
;
1519 ifp
->if_drv_flags
|= IFF_DRV_RUNNING
;
1521 if (ic
->ic_opmode
!= IEEE80211_M_MONITOR
)
1523 if (ic
->ic_roaming
!= IEEE80211_ROAMING_MANUAL
)
1524 ieee80211_new_state(ic
, IEEE80211_S_SCAN
, -1);
1528 ieee80211_new_state(ic
, IEEE80211_S_RUN
, -1);
1531 sc
->periodic_round
= 0;
1533 callout_reset(&sc
->periodic_ch
, hz
/ 10, rt2860_periodic
, sc
);
1539 rt2860_stop_locked(sc
);
1545 static void rt2860_init(void *priv
)
1547 struct rt2860_softc
*sc
;
1551 RT2860_SOFTC_LOCK(sc
);
1553 rt2860_init_locked(sc
);
1555 RT2860_SOFTC_UNLOCK(sc
);
1561 static int rt2860_init_bbp(struct rt2860_softc
*sc
)
1566 for (ntries
= 0; ntries
< 20; ntries
++)
1568 tmp
= rt2860_io_bbp_read(sc
, 0);
1569 if (tmp
!= 0x00 && tmp
!= 0xff)
1573 if (tmp
== 0x00 || tmp
== 0xff)
1575 printf("%s: timeout waiting for BBP to wakeup\n",
1576 device_get_nameunit(sc
->dev
));
1580 for (i
= 0; i
< RT2860_DEF_BBP_SIZE
; i
++)
1581 rt2860_io_bbp_write(sc
, rt2860_def_bbp
[i
].reg
,
1582 rt2860_def_bbp
[i
].val
);
1584 if ((sc
->mac_rev
& 0xffff) != 0x0101)
1585 rt2860_io_bbp_write(sc
, 84, 0x19);
1591 * rt2860_stop_locked
1593 static void rt2860_stop_locked(void *priv
)
1595 struct rt2860_softc
*sc
;
1596 struct ieee80211com
*ic
;
1604 RT2860_DPRINTF(sc
, RT2860_DEBUG_ANY
,
1606 device_get_nameunit(sc
->dev
));
1608 RT2860_SOFTC_ASSERT_LOCKED(sc
);
1612 if (ifp
->if_drv_flags
& IFF_DRV_RUNNING
)
1613 rt2860_led_cmd(sc
, RT2860_LED_CMD_RADIO_OFF
);
1615 ifp
->if_drv_flags
&= ~(IFF_DRV_RUNNING
| IFF_DRV_OACTIVE
);
1617 ieee80211_new_state(ic
, IEEE80211_S_INIT
, -1);
1619 callout_stop(&sc
->periodic_ch
);
1620 callout_stop(&sc
->tx_watchdog_ch
);
1622 RT2860_SOFTC_UNLOCK(sc
);
1624 taskqueue_block(sc
->taskqueue
);
1626 taskqueue_drain(sc
->taskqueue
, &sc
->rx_done_task
);
1627 taskqueue_drain(sc
->taskqueue
, &sc
->tx_done_task
);
1628 taskqueue_drain(sc
->taskqueue
, &sc
->fifo_sta_full_task
);
1629 taskqueue_drain(sc
->taskqueue
, &sc
->periodic_task
);
1631 RT2860_SOFTC_LOCK(sc
);
1633 /* clear key tables */
1635 rt2860_asic_clear_keytables(sc
);
1637 /* disable interrupts */
1639 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_INT_MASK
, 0);
1643 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_SYS_CTRL
);
1645 tmp
&= ~(RT2860_REG_RX_ENABLE
| RT2860_REG_TX_ENABLE
);
1647 rt2860_io_mac_write(sc
, RT2860_REG_SYS_CTRL
, tmp
);
1651 rt2860_io_mac_write(sc
, RT2860_REG_SYS_CTRL
,
1652 RT2860_REG_MAC_SRST
| RT2860_REG_BBP_HRST
);
1653 rt2860_io_mac_write(sc
, RT2860_REG_SYS_CTRL
, 0);
1655 if (sc
->beacon_mbuf
!= NULL
)
1657 m_free(sc
->beacon_mbuf
);
1658 sc
->beacon_mbuf
= NULL
;
1665 static void rt2860_stop(void *priv
)
1667 struct rt2860_softc
*sc
;
1671 RT2860_SOFTC_LOCK(sc
);
1673 rt2860_stop_locked(sc
);
1675 RT2860_SOFTC_UNLOCK(sc
);
1681 static void rt2860_start(struct ifnet
*ifp
)
1683 struct rt2860_softc
*sc
;
1684 struct ieee80211com
*ic
;
1685 struct ieee80211_node
*ni
;
1686 struct ether_header
*eh
;
1693 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
1698 IF_POLL(&ic
->ic_mgtq
, m
);
1701 RT2860_SOFTC_TX_RING_LOCK(&sc
->tx_ring
[sc
->tx_ring_mgtqid
]);
1703 if (sc
->tx_ring
[sc
->tx_ring_mgtqid
].data_queued
>= RT2860_SOFTC_TX_RING_DATA_COUNT
)
1705 RT2860_SOFTC_TX_RING_UNLOCK(&sc
->tx_ring
[sc
->tx_ring_mgtqid
]);
1707 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
1708 "%s: if_start: Tx ring with qid=%d is full\n",
1709 device_get_nameunit(sc
->dev
), sc
->tx_ring_mgtqid
);
1711 ifp
->if_drv_flags
|= IFF_DRV_OACTIVE
;
1713 sc
->tx_data_queue_full
[sc
->tx_ring_mgtqid
]++;
1718 IF_DEQUEUE(&ic
->ic_mgtq
, m
);
1721 RT2860_SOFTC_TX_RING_UNLOCK(&sc
->tx_ring
[sc
->tx_ring_mgtqid
]);
1725 ni
= (struct ieee80211_node
*) m
->m_pkthdr
.rcvif
;
1727 m
->m_pkthdr
.rcvif
= NULL
;
1729 if (bpf_peers_present(ic
->ic_rawbpf
))
1730 bpf_mtap(ic
->ic_rawbpf
, m
);
1732 if (rt2860_tx_frame(sc
, m
, ni
, sc
->tx_ring_mgtqid
) != 0)
1734 RT2860_SOFTC_TX_RING_UNLOCK(&sc
->tx_ring
[sc
->tx_ring_mgtqid
]);
1738 RT2860_SOFTC_TX_RING_UNLOCK(&sc
->tx_ring
[sc
->tx_ring_mgtqid
]);
1740 rt2860_drain_fifo_stats(sc
);
1744 if (ic
->ic_state
!= IEEE80211_S_RUN
)
1747 IFQ_DRV_DEQUEUE(&ifp
->if_snd
, m
);
1751 if (ic
->ic_flags
& IEEE80211_F_SCAN
)
1752 ieee80211_cancel_scan(ic
);
1754 if (m
->m_len
< sizeof(struct ether_header
) &&
1755 !(m
= m_pullup(m
, sizeof (struct ether_header
))))
1758 eh
= mtod(m
, struct ether_header
*);
1760 ni
= ieee80211_find_txnode(ic
, eh
->ether_dhost
);
1763 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
1764 "%s: if_start: could not find Tx node\n",
1765 device_get_nameunit(sc
->dev
));
1772 ieee80211_classify(ic
, m
, ni
);
1774 qid
= M_WME_GETAC(m
);
1776 RT2860_SOFTC_TX_RING_LOCK(&sc
->tx_ring
[qid
]);
1778 if (sc
->tx_ring
[qid
].data_queued
>= RT2860_SOFTC_TX_RING_DATA_COUNT
)
1780 RT2860_SOFTC_TX_RING_UNLOCK(&sc
->tx_ring
[qid
]);
1782 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
1783 "%s: if_start: Tx ring with qid=%d is full\n",
1784 device_get_nameunit(sc
->dev
), qid
);
1787 ieee80211_free_node(ni
);
1789 ifp
->if_drv_flags
|= IFF_DRV_OACTIVE
;
1792 sc
->tx_data_queue_full
[qid
]++;
1799 m
= ieee80211_encap(ic
, m
, ni
);
1802 RT2860_SOFTC_TX_RING_UNLOCK(&sc
->tx_ring
[qid
]);
1804 ieee80211_free_node(ni
);
1811 if (bpf_peers_present(ic
->ic_rawbpf
))
1812 bpf_mtap(ic
->ic_rawbpf
, m
);
1814 if (rt2860_tx_frame(sc
, m
, ni
, qid
) != 0)
1816 RT2860_SOFTC_TX_RING_UNLOCK(&sc
->tx_ring
[qid
]);
1818 ieee80211_free_node(ni
);
1825 RT2860_SOFTC_TX_RING_UNLOCK(&sc
->tx_ring
[qid
]);
1827 rt2860_drain_fifo_stats(sc
);
1830 sc
->tx_timer
= RT2860_TX_WATCHDOG_TIMEOUT
;
1832 ic
->ic_lastdata
= ticks
;
1834 callout_reset(&sc
->tx_watchdog_ch
, hz
, rt2860_tx_watchdog
, sc
);
1841 static int rt2860_ioctl(struct ifnet
*ifp
, u_long cmd
, caddr_t data
)
1843 struct rt2860_softc
*sc
;
1844 struct ieee80211com
*ic
;
1855 RT2860_SOFTC_LOCK(sc
);
1857 if (ifp
->if_flags
& IFF_UP
)
1859 if (ifp
->if_drv_flags
& IFF_DRV_RUNNING
)
1861 if ((ifp
->if_flags
^ sc
->if_flags
) & IFF_PROMISC
)
1862 rt2860_asic_update_promisc(sc
);
1866 rt2860_init_locked(sc
);
1871 if (ifp
->if_drv_flags
& IFF_DRV_RUNNING
)
1872 rt2860_stop_locked(sc
);
1875 sc
->if_flags
= ifp
->if_flags
;
1877 RT2860_SOFTC_UNLOCK(sc
);
1881 error
= ieee80211_ioctl(ic
, cmd
, data
);
1884 if (error
== ENETRESET
)
1886 RT2860_SOFTC_LOCK(sc
);
1888 if ((ifp
->if_flags
& IFF_UP
) &&
1889 (ifp
->if_drv_flags
& IFF_DRV_RUNNING
) &&
1890 (ic
->ic_roaming
!= IEEE80211_ROAMING_MANUAL
))
1892 rt2860_stop_locked(sc
);
1893 rt2860_init_locked(sc
);
1896 RT2860_SOFTC_UNLOCK(sc
);
1907 static int rt2860_reset(struct ifnet
*ifp
)
1909 struct rt2860_softc
*sc
;
1910 struct ieee80211com
*ic
;
1915 if (ic
->ic_opmode
!= IEEE80211_M_MONITOR
)
1918 rt2860_rf_set_chan(sc
, ic
->ic_curchan
);
1926 static int rt2860_newstate(struct ieee80211com
*ic
,
1927 enum ieee80211_state nstate
, int arg
)
1929 struct rt2860_softc
*sc
;
1931 struct ieee80211_node
*ni
;
1937 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATE
,
1938 "%s: newstate: %s -> %s\n",
1939 device_get_nameunit(sc
->dev
),
1940 ieee80211_state_name
[ic
->ic_state
], ieee80211_state_name
[nstate
]);
1942 error
= sc
->newstate(ic
, nstate
, arg
);
1946 RT2860_SOFTC_LOCK(sc
);
1948 /* turn link LED off */
1950 if (nstate
!= IEEE80211_S_RUN
)
1951 rt2860_led_cmd(sc
, RT2860_LED_CMD_RADIO_OFF
);
1955 case IEEE80211_S_INIT
:
1956 rt2860_asic_disable_tsf_sync(sc
);
1959 case IEEE80211_S_RUN
:
1962 if (ic
->ic_opmode
!= IEEE80211_M_MONITOR
)
1963 rt2860_rf_set_chan(sc
, ni
->ni_chan
);
1965 if (ic
->ic_opmode
!= IEEE80211_M_MONITOR
)
1967 rt2860_asic_enable_mrr(sc
);
1968 rt2860_asic_set_txpreamble(sc
);
1969 rt2860_asic_set_basicrates(sc
);
1970 rt2860_asic_update_txpower(sc
);
1971 rt2860_asic_set_bssid(sc
, ni
->ni_bssid
);
1974 if (ic
->ic_opmode
== IEEE80211_M_STA
)
1975 rt2860_newassoc(ni
, 1);
1977 if (ic
->ic_opmode
== IEEE80211_M_HOSTAP
||
1978 ic
->ic_opmode
== IEEE80211_M_IBSS
)
1980 error
= rt2860_beacon_alloc(sc
);
1984 rt2860_asic_update_beacon(sc
);
1987 if (ic
->ic_opmode
!= IEEE80211_M_MONITOR
)
1988 rt2860_asic_enable_tsf_sync(sc
);
1990 /* turn link LED on */
1992 if (ic
->ic_opmode
!= IEEE80211_M_MONITOR
)
1994 rt2860_led_cmd(sc
, RT2860_LED_CMD_RADIO_ON
|
1995 (IEEE80211_IS_CHAN_2GHZ(ni
->ni_chan
) ?
1996 RT2860_LED_CMD_LINK_2GHZ
: RT2860_LED_CMD_LINK_5GHZ
));
2000 case IEEE80211_S_SLEEP
:
2007 RT2860_SOFTC_UNLOCK(sc
);
2015 static void rt2860_scan_start(struct ieee80211com
*ic
)
2017 struct rt2860_softc
*sc
;
2023 rt2860_asic_disable_tsf_sync(sc
);
2029 static void rt2860_scan_end(struct ieee80211com
*ic
)
2031 struct rt2860_softc
*sc
;
2037 rt2860_asic_enable_tsf_sync(sc
);
2041 * rt2860_set_channel
2043 static void rt2860_set_channel(struct ieee80211com
*ic
)
2045 struct rt2860_softc
*sc
;
2051 RT2860_DPRINTF(sc
, RT2860_DEBUG_CHAN
,
2052 "%s: set channel: channel=%u, HT%s%s\n",
2053 device_get_nameunit(sc
->dev
),
2054 ieee80211_chan2ieee(ic
, ic
->ic_curchan
),
2055 !IEEE80211_IS_CHAN_HT(ic
->ic_curchan
) ? " disabled" :
2056 IEEE80211_IS_CHAN_HT20(ic
->ic_curchan
) ? "20":
2057 IEEE80211_IS_CHAN_HT40U(ic
->ic_curchan
) ? "40U" : "40D",
2058 (ic
->ic_flags
& IEEE80211_F_SCAN
) ? ", scanning" : "");
2060 RT2860_SOFTC_LOCK(sc
);
2062 rt2860_rf_set_chan(sc
, ic
->ic_curchan
);
2064 RT2860_SOFTC_UNLOCK(sc
);
2070 static void rt2860_newassoc(struct ieee80211_node
*ni
, int isnew
)
2072 struct rt2860_softc
*sc
;
2073 struct ieee80211com
*ic
;
2075 struct rt2860_softc_node
*rni
;
2082 rni
= (struct rt2860_softc_node
*) ni
;
2086 aid
= IEEE80211_AID(ni
->ni_associd
);
2087 rni
->staid
= rt2860_staid_alloc(sc
, aid
);
2090 rt2860_io_mac_write_multi(sc
, RT2860_REG_WCID(wcid
),
2091 ni
->ni_macaddr
, IEEE80211_ADDR_LEN
);
2093 rt2860_amrr_node_init(&sc
->amrr
, &sc
->amrr_node
[wcid
], ni
);
2095 RT2860_DPRINTF(sc
, RT2860_DEBUG_RATE
,
2096 "%s: initial%s node Tx rate: associd=0x%04x, rate=0x%02x, max rate=0x%02x\n",
2097 device_get_nameunit(sc
->dev
),
2098 (ni
->ni_flags
& IEEE80211_NODE_HT
) ? " HT" : "",
2100 (ni
->ni_flags
& IEEE80211_NODE_HT
) ?
2101 (ni
->ni_htrates
.rs_rates
[ni
->ni_txrate
] | IEEE80211_RATE_MCS
) :
2102 (ni
->ni_rates
.rs_rates
[ni
->ni_txrate
] & IEEE80211_RATE_VAL
),
2103 (ni
->ni_flags
& IEEE80211_NODE_HT
) ?
2104 (ni
->ni_htrates
.rs_rates
[ni
->ni_htrates
.rs_nrates
- 1] | IEEE80211_RATE_MCS
) :
2105 (ni
->ni_rates
.rs_rates
[ni
->ni_rates
.rs_nrates
- 1] & IEEE80211_RATE_VAL
));
2107 rt2860_asic_updateprot(sc
);
2108 rt2860_asic_updateslot(sc
);
2109 rt2860_asic_set_txpreamble(sc
);
2112 RT2860_DPRINTF(sc
, RT2860_DEBUG_NODE
,
2113 "%s: new association: isnew=%d, macaddr=%s, associd=0x%04x, staid=0x%02x, QoS %s, ERP %s, HT %s\n",
2114 device_get_nameunit(sc
->dev
), isnew
, ether_sprintf(ni
->ni_macaddr
),
2115 ni
->ni_associd
, rni
->staid
,
2116 (ni
->ni_flags
& IEEE80211_NODE_QOS
) ? "enabled" : "disabled",
2117 (ni
->ni_flags
& IEEE80211_NODE_ERP
) ? "enabled" : "disabled",
2118 (ni
->ni_flags
& IEEE80211_NODE_HT
) ? "enabled" : "disabled");
2125 static void rt2860_updateslot(struct ifnet
*ifp
)
2127 struct rt2860_softc
*sc
;
2131 rt2860_asic_updateslot(sc
);
2137 static int rt2860_wme_update(struct ieee80211com
*ic
)
2139 struct rt2860_softc
*sc
;
2145 rt2860_asic_wme_update(sc
);
2151 * rt2860_update_beacon
2153 static void rt2860_update_beacon(struct ieee80211com
*ic
, int what
)
2155 struct rt2860_softc
*sc
;
2158 struct ieee80211_beacon_offsets
*bo
;
2162 m
= sc
->beacon_mbuf
;
2163 bo
= &sc
->beacon_offsets
;
2165 RT2860_DPRINTF(sc
, RT2860_DEBUG_BEACON
,
2166 "%s: update beacon: what=%d\n",
2167 device_get_nameunit(sc
->dev
), what
);
2169 setbit(bo
->bo_flags
, what
);
2171 ieee80211_beacon_update(ic
->ic_bss
, bo
, m
, 0);
2173 rt2860_asic_update_beacon(sc
);
2177 * rt2860_key_update_begin
2179 static void rt2860_key_update_begin(struct ieee80211com
*ic
)
2181 struct rt2860_softc
*sc
;
2187 RT2860_DPRINTF(sc
, RT2860_DEBUG_KEY
,
2188 "%s: key update begin\n",
2189 device_get_nameunit(sc
->dev
));
2191 taskqueue_block(sc
->taskqueue
);
2193 IF_LOCK(&ifp
->if_snd
);
2197 * rt2860_key_update_end
2199 static void rt2860_key_update_end(struct ieee80211com
*ic
)
2201 struct rt2860_softc
*sc
;
2207 RT2860_DPRINTF(sc
, RT2860_DEBUG_KEY
,
2208 "%s: key update end\n",
2209 device_get_nameunit(sc
->dev
));
2211 IF_UNLOCK(&ifp
->if_snd
);
2213 taskqueue_unblock(sc
->taskqueue
);
2219 static int rt2860_key_set(struct ieee80211com
*ic
,
2220 const struct ieee80211_key
*k
, const uint8_t mac
[IEEE80211_ADDR_LEN
])
2222 struct rt2860_softc
*sc
;
2224 struct ieee80211_node
*ni
;
2225 struct rt2860_softc_node
*rni
;
2226 uint16_t key_base
, keymode_base
;
2227 uint8_t mode
, vapid
, wcid
, iv
[8];
2230 if (k
->wk_cipher
->ic_cipher
!= IEEE80211_CIPHER_WEP
&&
2231 k
->wk_cipher
->ic_cipher
!= IEEE80211_CIPHER_TKIP
&&
2232 k
->wk_cipher
->ic_cipher
!= IEEE80211_CIPHER_AES_CCM
)
2238 switch (k
->wk_cipher
->ic_cipher
)
2240 case IEEE80211_CIPHER_WEP
:
2241 if(k
->wk_keylen
< 8)
2242 mode
= RT2860_REG_CIPHER_MODE_WEP40
;
2244 mode
= RT2860_REG_CIPHER_MODE_WEP104
;
2247 case IEEE80211_CIPHER_TKIP
:
2248 mode
= RT2860_REG_CIPHER_MODE_TKIP
;
2251 case IEEE80211_CIPHER_AES_CCM
:
2252 mode
= RT2860_REG_CIPHER_MODE_AES_CCMP
;
2259 RT2860_DPRINTF(sc
, RT2860_DEBUG_KEY
,
2260 "%s: set key: keyix=%d, keylen=%d, macaddr=%s, mode=%d, group=%d\n",
2261 device_get_nameunit(sc
->dev
), k
->wk_keyix
, k
->wk_keylen
, ether_sprintf(mac
),
2262 mode
, (k
->wk_flags
& IEEE80211_KEY_GROUP
) ? 1 : 0);
2264 if (!(k
->wk_flags
& IEEE80211_KEY_GROUP
))
2266 /* install pairwise key */
2268 ni
= ieee80211_find_node(&ic
->ic_sta
, mac
);
2269 rni
= (struct rt2860_softc_node
*) ni
;
2273 key_base
= RT2860_REG_PKEY(wcid
);
2275 ieee80211_free_node(ni
);
2277 if (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_WEP
)
2281 iv
[3] = (k
->wk_keyix
<< 6);
2285 if (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_TKIP
)
2287 iv
[0] = (k
->wk_keytsc
>> 8);
2288 iv
[1] = ((iv
[0] | 0x20) & 0x7f);
2289 iv
[2] = k
->wk_keytsc
;
2295 iv
[0] = k
->wk_keytsc
;
2296 iv
[1] = k
->wk_keytsc
>> 8;
2300 iv
[3] = ((k
->wk_keyix
<< 6) | IEEE80211_WEP_EXTIV
);
2301 iv
[4] = (k
->wk_keytsc
>> 16);
2302 iv
[5] = (k
->wk_keytsc
>> 24);
2303 iv
[6] = (k
->wk_keytsc
>> 32);
2304 iv
[7] = (k
->wk_keytsc
>> 40);
2306 RT2860_DPRINTF(sc
, RT2860_DEBUG_KEY
,
2307 "%s: set key: iv=%02x %02x %02x %02x %02x %02x %02x %02x\n",
2308 device_get_nameunit(sc
->dev
),
2309 iv
[0], iv
[1], iv
[2], iv
[3], iv
[4], iv
[5], iv
[6], iv
[7]);
2312 rt2860_io_mac_write_multi(sc
, RT2860_REG_IVEIV(wcid
), iv
, 8);
2314 if (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_TKIP
)
2316 rt2860_io_mac_write_multi(sc
, key_base
, k
->wk_key
, 16);
2318 if (ic
->ic_opmode
!= IEEE80211_M_HOSTAP
)
2320 rt2860_io_mac_write_multi(sc
, key_base
+ 16, &k
->wk_key
[16], 8);
2321 rt2860_io_mac_write_multi(sc
, key_base
+ 24, &k
->wk_key
[24], 8);
2325 rt2860_io_mac_write_multi(sc
, key_base
+ 16, &k
->wk_key
[24], 8);
2326 rt2860_io_mac_write_multi(sc
, key_base
+ 24, &k
->wk_key
[16], 8);
2331 rt2860_io_mac_write_multi(sc
, key_base
, k
->wk_key
, k
->wk_keylen
);
2334 tmp
= ((vapid
& RT2860_REG_VAP_MASK
) << RT2860_REG_VAP_SHIFT
) |
2335 (mode
<< RT2860_REG_CIPHER_MODE_SHIFT
) | RT2860_REG_PKEY_ENABLE
;
2337 rt2860_io_mac_write(sc
, RT2860_REG_WCID_ATTR(wcid
), tmp
);
2340 if ((k
->wk_flags
& IEEE80211_KEY_GROUP
) ||
2341 (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_WEP
))
2343 /* install group key */
2346 wcid
= RT2860_WCID_MCAST
;
2347 key_base
= RT2860_REG_SKEY(vapid
, k
->wk_keyix
);
2348 keymode_base
= RT2860_REG_SKEY_MODE(vapid
);
2350 if (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_TKIP
)
2352 rt2860_io_mac_write_multi(sc
, key_base
, k
->wk_key
, 16);
2354 if (ic
->ic_opmode
!= IEEE80211_M_HOSTAP
)
2356 rt2860_io_mac_write_multi(sc
, key_base
+ 16, &k
->wk_key
[16], 8);
2357 rt2860_io_mac_write_multi(sc
, key_base
+ 24, &k
->wk_key
[24], 8);
2361 rt2860_io_mac_write_multi(sc
, key_base
+ 16, &k
->wk_key
[24], 8);
2362 rt2860_io_mac_write_multi(sc
, key_base
+ 24, &k
->wk_key
[16], 8);
2367 rt2860_io_mac_write_multi(sc
, key_base
, k
->wk_key
, k
->wk_keylen
);
2370 tmp
= rt2860_io_mac_read(sc
, keymode_base
);
2372 tmp
&= ~(0xf << (k
->wk_keyix
* 4 + 16 * (vapid
% 2)));
2373 tmp
|= (mode
<< (k
->wk_keyix
* 4 + 16 * (vapid
% 2)));
2375 rt2860_io_mac_write(sc
, keymode_base
, tmp
);
2377 if (ic
->ic_opmode
== IEEE80211_M_HOSTAP
)
2379 if (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_WEP
)
2383 iv
[3] = (k
->wk_keyix
<< 6);
2387 if (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_TKIP
)
2389 iv
[0] = (k
->wk_keytsc
>> 8);
2390 iv
[1] = ((iv
[0] | 0x20) & 0x7f);
2391 iv
[2] = k
->wk_keytsc
;
2397 iv
[0] = k
->wk_keytsc
;
2398 iv
[1] = k
->wk_keytsc
>> 8;
2402 iv
[3] = ((k
->wk_keyix
<< 6) | IEEE80211_WEP_EXTIV
);
2403 iv
[4] = (k
->wk_keytsc
>> 16);
2404 iv
[5] = (k
->wk_keytsc
>> 24);
2405 iv
[6] = (k
->wk_keytsc
>> 32);
2406 iv
[7] = (k
->wk_keytsc
>> 40);
2408 RT2860_DPRINTF(sc
, RT2860_DEBUG_KEY
,
2409 "%s: set key: iv=%02x %02x %02x %02x %02x %02x %02x %02x\n",
2410 device_get_nameunit(sc
->dev
),
2411 iv
[0], iv
[1], iv
[2], iv
[3], iv
[4], iv
[5], iv
[6], iv
[7]);
2414 rt2860_io_mac_write_multi(sc
, RT2860_REG_IVEIV(wcid
), iv
, 8);
2416 tmp
= ((vapid
& RT2860_REG_VAP_MASK
) << RT2860_REG_VAP_SHIFT
) |
2417 (mode
<< RT2860_REG_CIPHER_MODE_SHIFT
);
2419 rt2860_io_mac_write(sc
, RT2860_REG_WCID_ATTR(wcid
), tmp
);
2429 static int rt2860_key_delete(struct ieee80211com
*ic
,
2430 const struct ieee80211_key
*k
)
2432 struct rt2860_softc
*sc
;
2433 uint8_t vapid
, wcid
;
2436 sc
= ic
->ic_ifp
->if_softc
;
2438 RT2860_DPRINTF(sc
, RT2860_DEBUG_KEY
,
2439 "%s: delete key: keyix=%d, keylen=%d, group=%d\n",
2440 device_get_nameunit(sc
->dev
), k
->wk_keyix
, k
->wk_keylen
,
2441 (k
->wk_flags
& IEEE80211_KEY_GROUP
) ? 1 : 0);
2443 if (k
->wk_flags
& IEEE80211_KEY_GROUP
)
2445 /* remove group key */
2448 wcid
= RT2860_WCID_MCAST
;
2450 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_SKEY_MODE(vapid
));
2452 tmp
&= ~(0xf << (k
->wk_keyix
* 4 + 16 * (vapid
% 2)));
2453 tmp
|= (RT2860_REG_CIPHER_MODE_NONE
<< (k
->wk_keyix
* 4 + 16 * (vapid
% 2)));
2455 rt2860_io_mac_write(sc
, RT2860_REG_SKEY_MODE(vapid
), tmp
);
2457 if (ic
->ic_opmode
== IEEE80211_M_HOSTAP
)
2459 tmp
= ((vapid
& RT2860_REG_VAP_MASK
) << RT2860_REG_VAP_SHIFT
) |
2460 (RT2860_REG_CIPHER_MODE_NONE
<< RT2860_REG_CIPHER_MODE_SHIFT
) | RT2860_REG_PKEY_ENABLE
;
2462 rt2860_io_mac_write(sc
, RT2860_REG_WCID_ATTR(wcid
), tmp
);
2472 static int rt2860_raw_xmit(struct ieee80211_node
*ni
, struct mbuf
*m
,
2473 const struct ieee80211_bpf_params
*params
)
2479 * rt2860_media_change
2481 static int rt2860_media_change(struct ifnet
*ifp
)
2483 struct rt2860_softc
*sc
;
2488 error
= ieee80211_media_change(ifp
);
2489 if (error
!= ENETRESET
)
2492 RT2860_SOFTC_LOCK(sc
);
2494 if ((ifp
->if_flags
& IFF_UP
) && (ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
2496 rt2860_stop_locked(sc
);
2497 rt2860_init_locked(sc
);
2500 RT2860_SOFTC_UNLOCK(sc
);
2508 static struct ieee80211_node
*rt2860_node_alloc(struct ieee80211_node_table
*nt
)
2510 return malloc(sizeof(struct rt2860_softc_node
),
2511 M_80211_NODE
, M_NOWAIT
| M_ZERO
);
2515 * rt2860_node_cleanup
2517 static void rt2860_node_cleanup(struct ieee80211_node
*ni
)
2519 struct rt2860_softc
*sc
;
2520 struct ieee80211com
*ic
;
2522 struct ieee80211_rx_ampdu
*rx_ampdu
;
2523 struct rt2860_softc_node
*rni
;
2524 uint8_t vapid
, wcid
;
2531 rni
= (struct rt2860_softc_node
*) ni
;
2533 RT2860_DPRINTF(sc
, RT2860_DEBUG_NODE
,
2534 "%s: node cleanup: macaddr=%s, associd=0x%04x, staid=0x%02x\n",
2535 device_get_nameunit(sc
->dev
), ether_sprintf(ni
->ni_macaddr
),
2536 ni
->ni_associd
, rni
->staid
);
2538 if (rni
->staid
!= 0)
2543 tmp
= ((vapid
& RT2860_REG_VAP_MASK
) << RT2860_REG_VAP_SHIFT
) |
2544 (RT2860_REG_CIPHER_MODE_NONE
<< RT2860_REG_CIPHER_MODE_SHIFT
) | RT2860_REG_PKEY_ENABLE
;
2546 rt2860_io_mac_write(sc
, RT2860_REG_WCID_ATTR(wcid
), tmp
);
2548 rt2860_io_mac_write(sc
, RT2860_REG_WCID(wcid
), 0xffffffff);
2549 rt2860_io_mac_write(sc
, RT2860_REG_WCID(wcid
) + 4, 0x0000ffff);
2551 rt2860_staid_delete(sc
, rni
->staid
);
2555 for (i
= 0; i
< WME_NUM_TID
; i
++)
2557 rx_ampdu
= &ni
->ni_rx_ampdu
[i
];
2559 if (rx_ampdu
->rxa_flags
& IEEE80211_AGGR_XCHGPEND
)
2560 sc
->rx_ampdu_sessions
--;
2564 sc
->node_cleanup(ni
);
2568 * rt2860_recv_action
2570 static void rt2860_recv_action(struct ieee80211_node
*ni
,
2571 const uint8_t *frm
, const uint8_t *efrm
)
2573 struct rt2860_softc
*sc
;
2574 struct ieee80211com
*ic
;
2576 struct rt2860_softc_node
*rni
;
2577 const struct ieee80211_action
*ia
;
2578 uint16_t baparamset
;
2585 rni
= (struct rt2860_softc_node
*) ni
;
2587 ia
= (const struct ieee80211_action
*) frm
;
2589 if (ia
->ia_category
== IEEE80211_ACTION_CAT_BA
)
2591 switch (ia
->ia_action
)
2593 /* IEEE80211_ACTION_BA_DELBA */
2594 case IEEE80211_ACTION_BA_DELBA
:
2595 baparamset
= LE_READ_2(frm
+ 2);
2596 tid
= RT2860_MS(baparamset
, IEEE80211_BAPS_TID
);
2599 RT2860_DPRINTF(sc
, RT2860_DEBUG_BA
,
2600 "%s: received DELBA request: associd=0x%04x, staid=0x%02x, tid=%d\n",
2601 device_get_nameunit(sc
->dev
), ni
->ni_associd
, rni
->staid
, tid
);
2603 if (rni
->staid
!= 0)
2604 rt2860_asic_del_ba_session(sc
, wcid
, tid
);
2609 sc
->recv_action(ni
, frm
, efrm
);
2613 * rt2860_send_action
2615 static int rt2860_send_action(struct ieee80211_node
*ni
,
2616 int category
, int action
, uint16_t args
[4])
2618 struct rt2860_softc
*sc
;
2619 struct ieee80211com
*ic
;
2621 struct ieee80211_rx_ampdu
*rx_ampdu
;
2622 struct rt2860_softc_node
*rni
;
2623 uint16_t status
, baparamset
;
2630 rni
= (struct rt2860_softc_node
*) ni
;
2634 if (category
== IEEE80211_ACTION_CAT_BA
)
2638 /* IEEE80211_ACTION_BA_ADDBA_RESPONSE */
2639 case IEEE80211_ACTION_BA_ADDBA_RESPONSE
:
2641 baparamset
= args
[2];
2642 tid
= RT2860_MS(baparamset
, IEEE80211_BAPS_TID
);
2643 bufsize
= RT2860_MS(baparamset
, IEEE80211_BAPS_BUFSIZ
);
2644 rx_ampdu
= &ni
->ni_rx_ampdu
[tid
];
2646 RT2860_DPRINTF(sc
, RT2860_DEBUG_BA
,
2647 "%s: sending ADDBA response: associd=0x%04x, staid=0x%02x, status=%d, tid=%d, bufsize=%d\n",
2648 device_get_nameunit(sc
->dev
), ni
->ni_associd
, rni
->staid
, status
, tid
, bufsize
);
2650 if (status
== IEEE80211_STATUS_SUCCESS
)
2652 rt2860_asic_add_ba_session(sc
, wcid
, tid
);
2654 if (!(rx_ampdu
->rxa_flags
& IEEE80211_AGGR_XCHGPEND
))
2655 sc
->rx_ampdu_sessions
++;
2659 /* IEEE80211_ACTION_BA_DELBA */
2660 case IEEE80211_ACTION_BA_DELBA
:
2661 baparamset
= RT2860_SM(args
[0], IEEE80211_DELBAPS_TID
) | args
[1];
2662 tid
= RT2860_MS(baparamset
, IEEE80211_DELBAPS_TID
);
2663 rx_ampdu
= &ni
->ni_rx_ampdu
[tid
];
2665 RT2860_DPRINTF(sc
, RT2860_DEBUG_BA
,
2666 "%s: sending DELBA request: associd=0x%04x, staid=0x%02x, tid=%d\n",
2667 device_get_nameunit(sc
->dev
), ni
->ni_associd
, rni
->staid
, tid
);
2669 if (RT2860_MS(baparamset
, IEEE80211_DELBAPS_INIT
) != IEEE80211_DELBAPS_INIT
)
2671 rt2860_asic_del_ba_session(sc
, wcid
, tid
);
2673 if (rx_ampdu
->rxa_flags
& IEEE80211_AGGR_XCHGPEND
)
2674 sc
->rx_ampdu_sessions
--;
2680 return sc
->send_action(ni
, category
, action
, args
);
2685 * rt2860_addba_response
2687 static int rt2860_addba_response(struct ieee80211_node
*ni
,
2688 struct ieee80211_tx_ampdu
*tap
,
2689 int status
, int baparamset
, int batimeout
)
2691 struct rt2860_softc
*sc
;
2692 struct ieee80211com
*ic
;
2694 struct rt2860_softc_node
*rni
;
2695 ieee80211_seq seqno
;
2696 int ret
, tid
, old_bufsize
, new_bufsize
;
2701 rni
= (struct rt2860_softc_node
*) ni
;
2703 tid
= RT2860_MS(baparamset
, IEEE80211_BAPS_TID
);
2704 old_bufsize
= RT2860_MS(baparamset
, IEEE80211_BAPS_BUFSIZ
);
2705 new_bufsize
= old_bufsize
;
2707 if (status
== IEEE80211_STATUS_SUCCESS
)
2709 if (sc
->mac_rev
>= 0x28830300)
2711 if (sc
->mac_rev
>= 0x30700200)
2716 else if (sc
->mac_rev
>= 0x28720200)
2725 if (old_bufsize
> new_bufsize
)
2727 baparamset
&= ~IEEE80211_BAPS_BUFSIZ
;
2728 baparamset
= RT2860_SM(new_bufsize
, IEEE80211_BAPS_BUFSIZ
);
2731 if (!(tap
->txa_flags
& IEEE80211_AGGR_RUNNING
))
2733 sc
->tx_ampdu_sessions
++;
2735 if (sc
->tx_ampdu_sessions
== 1)
2736 rt2860_asic_updateprot(sc
);
2740 RT2860_DPRINTF(sc
, RT2860_DEBUG_BA
,
2741 "%s: received ADDBA response: associd=0x%04x, staid=0x%02x, status=%d, tid=%d, "
2742 "old bufsize=%d, new bufsize=%d\n",
2743 device_get_nameunit(sc
->dev
), ni
->ni_associd
, rni
->staid
, status
, tid
,
2744 old_bufsize
, new_bufsize
);
2746 ret
= sc
->addba_response(ni
, tap
, status
, baparamset
, batimeout
);
2748 if (status
== IEEE80211_STATUS_SUCCESS
)
2750 seqno
= ni
->ni_txseqs
[tid
];
2752 rt2860_send_bar(ni
, tap
, seqno
);
2761 static void rt2860_addba_stop(struct ieee80211_node
*ni
,
2762 struct ieee80211_tx_ampdu
*tap
)
2764 struct rt2860_softc
*sc
;
2765 struct ieee80211com
*ic
;
2767 struct rt2860_softc_node
*rni
;
2773 rni
= (struct rt2860_softc_node
*) ni
;
2775 tid
= WME_AC_TO_TID(tap
->txa_ac
);
2777 RT2860_DPRINTF(sc
, RT2860_DEBUG_BA
,
2778 "%s: stopping A-MPDU Tx: associd=0x%04x, staid=0x%02x, tid=%d\n",
2779 device_get_nameunit(sc
->dev
), ni
->ni_associd
, rni
->staid
, tid
);
2781 if (tap
->txa_flags
& IEEE80211_AGGR_RUNNING
)
2783 if (sc
->tx_ampdu_sessions
> 0)
2785 sc
->tx_ampdu_sessions
--;
2787 if (sc
->tx_ampdu_sessions
== 0)
2788 rt2860_asic_updateprot(sc
);
2792 printf("%s: number of A-MPDU Tx sessions cannot be negative\n",
2793 device_get_nameunit(sc
->dev
));
2797 sc
->addba_stop(ni
, tap
);
2803 static int rt2860_send_bar(struct ieee80211_node
*ni
,
2804 struct ieee80211_tx_ampdu
*tap
, ieee80211_seq seqno
)
2806 struct rt2860_softc
*sc
;
2807 struct ieee80211com
*ic
;
2809 struct ieee80211_frame_bar
*bar
;
2810 struct rt2860_softc_node
*rni
;
2812 uint16_t barctl
, barseqctl
;
2819 rni
= (struct rt2860_softc_node
*) ni
;
2821 if (!(tap
->txa_flags
& IEEE80211_AGGR_RUNNING
))
2824 m
= ieee80211_getmgtframe(&frm
, ic
->ic_headroom
, sizeof(struct ieee80211_frame_bar
));
2828 bar
= mtod(m
, struct ieee80211_frame_bar
*);
2830 bar
->i_fc
[0] = IEEE80211_FC0_VERSION_0
| IEEE80211_FC0_TYPE_CTL
| IEEE80211_FC0_SUBTYPE_BAR
;
2833 IEEE80211_ADDR_COPY(bar
->i_ra
, ni
->ni_macaddr
);
2834 IEEE80211_ADDR_COPY(bar
->i_ta
, ic
->ic_myaddr
);
2836 tid
= WME_AC_TO_TID(tap
->txa_ac
);
2838 barctl
= (tap
->txa_flags
& IEEE80211_AGGR_IMMEDIATE
? 0 : IEEE80211_BAR_NOACK
) |
2839 IEEE80211_BAR_COMP
|
2840 RT2860_SM(tid
, IEEE80211_BAR_TID
);
2841 barseqctl
= RT2860_SM(seqno
, IEEE80211_BASEQ_START
);
2843 bar
->i_ctl
= htole16(barctl
);
2844 bar
->i_seq
= htole16(barseqctl
);
2846 m
->m_pkthdr
.len
= m
->m_len
= sizeof(struct ieee80211_frame_bar
);
2847 m
->m_pkthdr
.rcvif
= (void *) ni
;
2849 tap
->txa_start
= seqno
;
2851 ieee80211_ref_node(ni
);
2853 RT2860_DPRINTF(sc
, RT2860_DEBUG_BA
,
2854 "%s: sending BAR: associd=0x%04x, staid=0x%02x, tid=%d, seqno=%d\n",
2855 device_get_nameunit(sc
->dev
), ni
->ni_associd
, rni
->staid
, tid
, seqno
);
2857 IF_ENQUEUE(&ic
->ic_mgtq
, m
);
2865 * rt2860_amrr_update_iter_func
2867 static void rt2860_amrr_update_iter_func(void *arg
, struct ieee80211_node
*ni
)
2869 struct rt2860_softc
*sc
;
2870 struct ieee80211com
*ic
;
2871 struct rt2860_softc_node
*rni
;
2876 rni
= (struct rt2860_softc_node
*) ni
;
2878 /* only associated stations */
2880 if (rni
->staid
!= 0)
2884 RT2860_DPRINTF(sc
, RT2860_DEBUG_RATE
,
2885 "%s: AMRR node: staid=0x%02x, txcnt=%d, success=%d, retrycnt=%d\n",
2886 device_get_nameunit(sc
->dev
),
2887 rni
->staid
, sc
->amrr_node
[wcid
].txcnt
, sc
->amrr_node
[wcid
].success
, sc
->amrr_node
[wcid
].retrycnt
);
2889 rt2860_amrr_choose(ni
, &sc
->amrr_node
[wcid
]);
2891 RT2860_DPRINTF(sc
, RT2860_DEBUG_RATE
,
2892 "%s:%s node Tx rate: associd=0x%04x, staid=0x%02x, rate=0x%02x, max rate=0x%02x\n",
2893 device_get_nameunit(sc
->dev
),
2894 (ni
->ni_flags
& IEEE80211_NODE_HT
) ? " HT" : "",
2895 ni
->ni_associd
, rni
->staid
,
2896 (ni
->ni_flags
& IEEE80211_NODE_HT
) ?
2897 (ni
->ni_htrates
.rs_rates
[ni
->ni_txrate
] | IEEE80211_RATE_MCS
) :
2898 (ni
->ni_rates
.rs_rates
[ni
->ni_txrate
] & IEEE80211_RATE_VAL
),
2899 (ni
->ni_flags
& IEEE80211_NODE_HT
) ?
2900 (ni
->ni_htrates
.rs_rates
[ni
->ni_htrates
.rs_nrates
- 1] | IEEE80211_RATE_MCS
) :
2901 (ni
->ni_rates
.rs_rates
[ni
->ni_rates
.rs_nrates
- 1] & IEEE80211_RATE_VAL
));
2908 static void rt2860_periodic(void *arg
)
2910 struct rt2860_softc
*sc
;
2914 RT2860_DPRINTF(sc
, RT2860_DEBUG_PERIODIC
,
2916 device_get_nameunit(sc
->dev
));
2918 taskqueue_enqueue(sc
->taskqueue
, &sc
->periodic_task
);
2922 * rt2860_tx_watchdog
2924 static void rt2860_tx_watchdog(void *arg
)
2926 struct rt2860_softc
*sc
;
2932 if (sc
->tx_timer
== 0)
2935 if (--sc
->tx_timer
== 0)
2937 printf("%s: Tx watchdog timeout: resetting\n",
2938 device_get_nameunit(sc
->dev
));
2940 rt2860_stop_locked(sc
);
2941 rt2860_init_locked(sc
);
2945 sc
->tx_watchdog_timeouts
++;
2948 callout_reset(&sc
->tx_watchdog_ch
, hz
, rt2860_tx_watchdog
, sc
);
2952 * rt2860_staid_alloc
2954 static int rt2860_staid_alloc(struct rt2860_softc
*sc
, int aid
)
2958 if ((aid
> 0 && aid
< RT2860_SOFTC_STAID_COUNT
) && isclr(sc
->staid_mask
, aid
))
2964 for (staid
= 1; staid
< RT2860_SOFTC_STAID_COUNT
; staid
++)
2966 if (isclr(sc
->staid_mask
, staid
))
2971 setbit(sc
->staid_mask
, staid
);
2977 * rt2860_staid_delete
2979 static void rt2860_staid_delete(struct rt2860_softc
*sc
, int staid
)
2981 clrbit(sc
->staid_mask
, staid
);
2985 * rt2860_asic_set_bssid
2987 static void rt2860_asic_set_bssid(struct rt2860_softc
*sc
,
2988 const uint8_t *bssid
)
2992 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATE
,
2993 "%s: set bssid: bssid=%s\n",
2994 device_get_nameunit(sc
->dev
), ether_sprintf(bssid
));
2996 tmp
= bssid
[0] | (bssid
[1]) << 8 | (bssid
[2] << 16) | (bssid
[3] << 24);
2998 rt2860_io_mac_write(sc
, RT2860_REG_BSSID_DW0
, tmp
);
3000 tmp
= bssid
[4] | (bssid
[5] << 8);
3002 rt2860_io_mac_write(sc
, RT2860_REG_BSSID_DW1
, tmp
);
3006 * rt2860_asic_set_macaddr
3008 static void rt2860_asic_set_macaddr(struct rt2860_softc
*sc
,
3009 const uint8_t *addr
)
3013 tmp
= addr
[0] | (addr
[1] << 8) | (addr
[2] << 16) | (addr
[3] << 24);
3015 rt2860_io_mac_write(sc
, RT2860_REG_ADDR_DW0
, tmp
);
3017 tmp
= addr
[4] | (addr
[5] << 8);
3019 rt2860_io_mac_write(sc
, RT2860_REG_ADDR_DW1
, tmp
);
3023 * rt2860_asic_enable_tsf_sync
3025 static void rt2860_asic_enable_tsf_sync(struct rt2860_softc
*sc
)
3027 struct ieee80211com
*ic
;
3032 RT2860_DPRINTF(sc
, RT2860_DEBUG_BEACON
,
3033 "%s: enabling TSF\n",
3034 device_get_nameunit(sc
->dev
));
3036 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_BCN_TIME_CFG
);
3039 tmp
|= ic
->ic_bss
->ni_intval
* 16;
3040 tmp
|= (RT2860_REG_TSF_TIMER_ENABLE
| RT2860_REG_TBTT_TIMER_ENABLE
);
3042 if (ic
->ic_opmode
== IEEE80211_M_STA
)
3044 tmp
|= (RT2860_REG_TSF_SYNC_MODE_STA
<< RT2860_REG_TSF_SYNC_MODE_SHIFT
);
3046 else if (ic
->ic_opmode
== IEEE80211_M_IBSS
)
3048 tmp
|= RT2860_REG_BCN_TX_ENABLE
;
3049 tmp
|= (RT2860_REG_TSF_SYNC_MODE_IBSS
<< RT2860_REG_TSF_SYNC_MODE_SHIFT
);
3051 else if (ic
->ic_opmode
== IEEE80211_M_HOSTAP
)
3053 tmp
|= RT2860_REG_BCN_TX_ENABLE
;
3054 tmp
|= (RT2860_REG_TSF_SYNC_MODE_HOSTAP
<< RT2860_REG_TSF_SYNC_MODE_SHIFT
);
3057 rt2860_io_mac_write(sc
, RT2860_REG_BCN_TIME_CFG
, tmp
);
3061 * rt2860_asic_disable_tsf_sync
3063 static void rt2860_asic_disable_tsf_sync(struct rt2860_softc
*sc
)
3067 RT2860_DPRINTF(sc
, RT2860_DEBUG_BEACON
,
3068 "%s: disabling TSF\n",
3069 device_get_nameunit(sc
->dev
));
3071 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_BCN_TIME_CFG
);
3073 tmp
&= ~(RT2860_REG_BCN_TX_ENABLE
|
3074 RT2860_REG_TSF_TIMER_ENABLE
|
3075 RT2860_REG_TBTT_TIMER_ENABLE
);
3077 tmp
&= ~(RT2860_REG_TSF_SYNC_MODE_MASK
<< RT2860_REG_TSF_SYNC_MODE_SHIFT
);
3078 tmp
|= (RT2860_REG_TSF_SYNC_MODE_DISABLE
<< RT2860_REG_TSF_SYNC_MODE_SHIFT
);
3080 rt2860_io_mac_write(sc
, RT2860_REG_BCN_TIME_CFG
, tmp
);
3084 * rt2860_asic_enable_mrr
3086 static void rt2860_asic_enable_mrr(struct rt2860_softc
*sc
)
3088 #define CCK(mcs) (mcs)
3089 #define OFDM(mcs) ((1 << 3) | (mcs))
3090 #define HT(mcs) (mcs)
3092 rt2860_io_mac_write(sc
, RT2860_REG_TX_LG_FBK_CFG0
,
3093 (OFDM(6) << 28) | /* 54 -> 48 */
3094 (OFDM(5) << 24) | /* 48 -> 36 */
3095 (OFDM(4) << 20) | /* 36 -> 24 */
3096 (OFDM(3) << 16) | /* 24 -> 18 */
3097 (OFDM(2) << 12) | /* 18 -> 12 */
3098 (OFDM(1) << 8) | /* 12 -> 9 */
3099 (OFDM(0) << 4) | /* 9 -> 6 */
3100 OFDM(0)); /* 6 -> 6 */
3102 rt2860_io_mac_write(sc
, RT2860_REG_TX_LG_FBK_CFG1
,
3103 (CCK(2) << 12) | /* 11 -> 5.5 */
3104 (CCK(1) << 8) | /* 5.5 -> 2 */
3105 (CCK(0) << 4) | /* 2 -> 1 */
3106 CCK(0)); /* 1 -> 1 */
3108 rt2860_io_mac_write(sc
, RT2860_REG_TX_HT_FBK_CFG0
,
3118 rt2860_io_mac_write(sc
, RT2860_REG_TX_HT_FBK_CFG1
,
3134 * rt2860_asic_set_txpreamble
3136 static void rt2860_asic_set_txpreamble(struct rt2860_softc
*sc
)
3138 struct ieee80211com
*ic
;
3143 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATE
,
3144 "%s: %s short Tx preamble\n",
3145 device_get_nameunit(sc
->dev
),
3146 (ic
->ic_flags
& IEEE80211_F_SHPREAMBLE
) ? "enabling" : "disabling");
3148 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_AUTO_RSP_CFG
);
3150 tmp
&= ~RT2860_REG_CCK_SHORT_ENABLE
;
3152 if (sc
->ic
.ic_flags
& IEEE80211_F_SHPREAMBLE
)
3153 tmp
|= RT2860_REG_CCK_SHORT_ENABLE
;
3155 rt2860_io_mac_write(sc
, RT2860_REG_AUTO_RSP_CFG
, tmp
);
3159 * rt2860_asic_set_basicrates
3161 static void rt2860_asic_set_basicrates(struct rt2860_softc
*sc
)
3163 struct ieee80211com
*ic
;
3167 if (ic
->ic_curmode
== IEEE80211_MODE_11B
)
3168 rt2860_io_mac_write(sc
, RT2860_REG_LEGACY_BASIC_RATE
, 0xf);
3169 else if (ic
->ic_curmode
== IEEE80211_MODE_11A
)
3170 rt2860_io_mac_write(sc
, RT2860_REG_LEGACY_BASIC_RATE
, 0x150);
3172 rt2860_io_mac_write(sc
, RT2860_REG_LEGACY_BASIC_RATE
, 0x15f);
3176 * rt2860_asic_update_rtsthreshold
3178 static void rt2860_asic_update_rtsthreshold(struct rt2860_softc
*sc
)
3180 struct ieee80211com
*ic
;
3186 RT2860_DPRINTF(sc
, RT2860_DEBUG_PROT
,
3187 "%s: updating RTS threshold: %d\n",
3188 device_get_nameunit(sc
->dev
), ic
->ic_rtsthreshold
);
3190 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_RTS_CFG
);
3192 tmp
&= ~(RT2860_REG_TX_RTS_THRESHOLD_MASK
<< RT2860_REG_TX_RTS_THRESHOLD_SHIFT
);
3194 if (ic
->ic_flags_ext
& IEEE80211_FEXT_AMSDU_TX
)
3197 threshold
= ic
->ic_rtsthreshold
;
3200 tmp
|= ((threshold
& RT2860_REG_TX_RTS_THRESHOLD_MASK
) <<
3201 RT2860_REG_TX_RTS_THRESHOLD_SHIFT
);
3203 rt2860_io_mac_write(sc
, RT2860_REG_TX_RTS_CFG
, tmp
);
3207 * rt2860_asic_update_txpower
3209 static void rt2860_asic_update_txpower(struct rt2860_softc
*sc
)
3211 struct ieee80211com
*ic
;
3212 uint32_t *txpow_rate
;
3220 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATE
,
3221 "%s: updating Tx power: %d\n",
3222 device_get_nameunit(sc
->dev
), ic
->ic_txpowlimit
);
3224 if (!IEEE80211_IS_CHAN_HT40(ic
->ic_curchan
))
3226 txpow_rate
= sc
->txpow_rate_20mhz
;
3230 if (IEEE80211_IS_CHAN_2GHZ(ic
->ic_curchan
))
3231 txpow_rate
= sc
->txpow_rate_40mhz_2ghz
;
3233 txpow_rate
= sc
->txpow_rate_40mhz_5ghz
;
3238 val
= rt2860_io_bbp_read(sc
, 1);
3241 if (ic
->ic_txpowlimit
> 90)
3245 else if (ic
->ic_txpowlimit
> 60)
3249 else if (ic
->ic_txpowlimit
> 30)
3253 else if (ic
->ic_txpowlimit
> 15)
3257 else if (ic
->ic_txpowlimit
> 9)
3267 rt2860_io_bbp_write(sc
, 1, val
);
3269 for (i
= 0; i
< RT2860_SOFTC_TXPOW_RATE_COUNT
; i
++)
3271 if (txpow_rate
[i
] == 0xffffffff)
3274 tmp
= rt2860_read_eeprom_txpow_rate_add_delta(txpow_rate
[i
], delta
);
3276 rt2860_io_mac_write(sc
, RT2860_REG_TX_PWR_CFG(i
), tmp
);
3281 * rt2860_asic_update_promisc
3283 static void rt2860_asic_update_promisc(struct rt2860_softc
*sc
)
3288 ifp
= sc
->ic
.ic_ifp
;
3290 printf("%s: %s promiscuous mode\n",
3291 device_get_nameunit(sc
->dev
),
3292 (ifp
->if_flags
& IFF_PROMISC
) ? "entering" : "leaving");
3294 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_RX_FILTER_CFG
);
3296 tmp
&= ~RT2860_REG_RX_FILTER_DROP_UC_NOME
;
3298 if (!(ifp
->if_flags
& IFF_PROMISC
))
3299 tmp
|= RT2860_REG_RX_FILTER_DROP_UC_NOME
;
3301 rt2860_io_mac_write(sc
, RT2860_REG_RX_FILTER_CFG
, tmp
);
3305 * rt2860_asic_updateprot
3307 static void rt2860_asic_updateprot(struct rt2860_softc
*sc
)
3309 struct ieee80211com
*ic
;
3310 uint32_t cck_prot
, ofdm_prot
, mm20_prot
, mm40_prot
, gf20_prot
, gf40_prot
;
3312 enum ieee80211_protmode htprotmode
;
3316 /* CCK frame protection */
3318 cck_prot
= RT2860_REG_RTSTH_ENABLE
| RT2860_REG_PROT_NAV_SHORT
|
3319 RT2860_REG_TXOP_ALLOW_ALL
| RT2860_REG_PROT_CTRL_NONE
;
3321 /* set up protection frame phy mode and rate (MCS code) */
3323 if (ic
->ic_curmode
== IEEE80211_MODE_11A
)
3324 cck_prot
|= (RT2860_REG_PROT_PHYMODE_OFDM
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3325 (0 << RT2860_REG_PROT_MCS_SHIFT
);
3327 cck_prot
|= ((RT2860_REG_PROT_PHYMODE_CCK
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3328 (3 << RT2860_REG_PROT_MCS_SHIFT
));
3330 rt2860_io_mac_write(sc
, RT2860_REG_TX_CCK_PROT_CFG
, cck_prot
);
3332 /* OFDM frame protection */
3334 ofdm_prot
= RT2860_REG_RTSTH_ENABLE
| RT2860_REG_PROT_NAV_SHORT
|
3335 RT2860_REG_TXOP_ALLOW_ALL
;
3337 if (ic
->ic_flags
& IEEE80211_F_USEPROT
)
3339 RT2860_DPRINTF(sc
, RT2860_DEBUG_PROT
,
3340 "%s: updating protection mode: b/g protection mode=%s\n",
3341 device_get_nameunit(sc
->dev
),
3342 (ic
->ic_protmode
== IEEE80211_PROT_RTSCTS
) ? "RTS/CTS" :
3343 ((ic
->ic_protmode
== IEEE80211_PROT_CTSONLY
) ? "CTS-to-self" : "none"));
3345 if (ic
->ic_protmode
== IEEE80211_PROT_RTSCTS
)
3346 ofdm_prot
|= RT2860_REG_PROT_CTRL_RTS_CTS
;
3347 else if (ic
->ic_protmode
== IEEE80211_PROT_CTSONLY
)
3348 ofdm_prot
|= RT2860_REG_PROT_CTRL_CTS
;
3350 ofdm_prot
|= RT2860_REG_PROT_CTRL_NONE
;
3354 RT2860_DPRINTF(sc
, RT2860_DEBUG_PROT
,
3355 "%s: updating protection mode: b/g protection mode=%s\n",
3356 device_get_nameunit(sc
->dev
), "none");
3358 ofdm_prot
|= RT2860_REG_PROT_CTRL_NONE
;
3361 rt2860_io_mac_write(sc
, RT2860_REG_TX_OFDM_PROT_CFG
, ofdm_prot
);
3363 /* HT frame protection */
3365 if ((ic
->ic_opmode
== IEEE80211_M_STA
) && (ic
->ic_state
== IEEE80211_S_RUN
))
3366 htopmode
= ic
->ic_bss
->ni_htopmode
;
3368 htopmode
= ic
->ic_curhtprotmode
;
3370 htprotmode
= ic
->ic_htprotmode
;
3372 /* force HT mixed mode and RTS/CTS protection if A-MPDU Tx aggregation is enabled */
3374 if (sc
->tx_ampdu_sessions
> 0)
3376 RT2860_DPRINTF(sc
, RT2860_DEBUG_PROT
,
3377 "%s: updating protection mode: forcing HT mixed mode and RTS/CTS protection\n",
3378 device_get_nameunit(sc
->dev
));
3380 htopmode
= IEEE80211_HTINFO_OPMODE_MIXED
;
3381 htprotmode
= IEEE80211_PROT_RTSCTS
;
3384 RT2860_DPRINTF(sc
, RT2860_DEBUG_PROT
,
3385 "%s: updating protection mode: HT operation mode=0x%02x, protection mode=%s\n",
3386 device_get_nameunit(sc
->dev
),
3387 htopmode
& IEEE80211_HTINFO_OPMODE
,
3388 (htprotmode
== IEEE80211_PROT_RTSCTS
) ? "RTS/CTS" :
3389 ((htprotmode
== IEEE80211_PROT_CTSONLY
) ? "CTS-to-self" : "none"));
3391 switch (htopmode
& IEEE80211_HTINFO_OPMODE
)
3393 /* IEEE80211_HTINFO_OPMODE_HT20PR */
3394 case IEEE80211_HTINFO_OPMODE_HT20PR
:
3395 mm20_prot
= RT2860_REG_PROT_NAV_SHORT
| RT2860_REG_PROT_CTRL_NONE
|
3396 RT2860_REG_TXOP_ALLOW_CCK
| RT2860_REG_TXOP_ALLOW_OFDM
|
3397 RT2860_REG_TXOP_ALLOW_MM20
| RT2860_REG_TXOP_ALLOW_GF20
|
3398 (RT2860_REG_PROT_PHYMODE_OFDM
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3399 (4 << RT2860_REG_PROT_MCS_SHIFT
);
3401 gf20_prot
= mm20_prot
;
3403 mm40_prot
= RT2860_REG_PROT_NAV_SHORT
| RT2860_REG_TXOP_ALLOW_ALL
|
3404 (RT2860_REG_PROT_PHYMODE_OFDM
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3405 (0x84 << RT2860_REG_PROT_MCS_SHIFT
);
3407 if (htprotmode
== IEEE80211_PROT_RTSCTS
)
3408 mm40_prot
|= RT2860_REG_PROT_CTRL_RTS_CTS
;
3409 else if (htprotmode
== IEEE80211_PROT_CTSONLY
)
3410 mm40_prot
|= RT2860_REG_PROT_CTRL_CTS
;
3412 mm40_prot
|= RT2860_REG_PROT_CTRL_NONE
;
3414 gf40_prot
= mm40_prot
;
3417 /* IEEE80211_HTINFO_OPMODE_MIXED */
3418 case IEEE80211_HTINFO_OPMODE_MIXED
:
3419 mm20_prot
= RT2860_REG_PROT_NAV_SHORT
|
3420 RT2860_REG_TXOP_ALLOW_CCK
| RT2860_REG_TXOP_ALLOW_OFDM
|
3421 RT2860_REG_TXOP_ALLOW_MM20
| RT2860_REG_TXOP_ALLOW_GF20
;
3423 if (ic
->ic_flags
& IEEE80211_F_USEPROT
)
3424 mm20_prot
|= (RT2860_REG_PROT_PHYMODE_CCK
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3425 (3 << RT2860_REG_PROT_MCS_SHIFT
);
3427 mm20_prot
|= (RT2860_REG_PROT_PHYMODE_OFDM
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3428 (4 << RT2860_REG_PROT_MCS_SHIFT
);
3430 if (htprotmode
== IEEE80211_PROT_RTSCTS
)
3431 mm20_prot
|= RT2860_REG_PROT_CTRL_RTS_CTS
;
3432 else if (htprotmode
== IEEE80211_PROT_CTSONLY
)
3433 mm20_prot
|= RT2860_REG_PROT_CTRL_CTS
;
3435 mm20_prot
|= RT2860_REG_PROT_CTRL_NONE
;
3437 gf20_prot
= mm20_prot
;
3439 mm40_prot
= RT2860_REG_PROT_NAV_SHORT
| RT2860_REG_TXOP_ALLOW_ALL
;
3441 if (ic
->ic_flags
& IEEE80211_F_USEPROT
)
3442 mm40_prot
|= (RT2860_REG_PROT_PHYMODE_CCK
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3443 (3 << RT2860_REG_PROT_MCS_SHIFT
);
3445 mm40_prot
|= (RT2860_REG_PROT_PHYMODE_OFDM
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3446 (0x84 << RT2860_REG_PROT_MCS_SHIFT
);
3448 if (htprotmode
== IEEE80211_PROT_RTSCTS
)
3449 mm40_prot
|= RT2860_REG_PROT_CTRL_RTS_CTS
;
3450 else if (htprotmode
== IEEE80211_PROT_CTSONLY
)
3451 mm40_prot
|= RT2860_REG_PROT_CTRL_CTS
;
3453 mm40_prot
|= RT2860_REG_PROT_CTRL_NONE
;
3455 gf40_prot
= mm40_prot
;
3459 * IEEE80211_HTINFO_OPMODE_PURE
3460 * IEEE80211_HTINFO_OPMODE_PROTOPT
3462 case IEEE80211_HTINFO_OPMODE_PURE
:
3463 case IEEE80211_HTINFO_OPMODE_PROTOPT
:
3465 mm20_prot
= RT2860_REG_PROT_NAV_SHORT
| RT2860_REG_PROT_CTRL_NONE
|
3466 RT2860_REG_TXOP_ALLOW_CCK
| RT2860_REG_TXOP_ALLOW_OFDM
|
3467 RT2860_REG_TXOP_ALLOW_MM20
| RT2860_REG_TXOP_ALLOW_GF20
|
3468 (RT2860_REG_PROT_PHYMODE_OFDM
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3469 (4 << RT2860_REG_PROT_MCS_SHIFT
);
3471 gf20_prot
= mm20_prot
;
3473 mm40_prot
= RT2860_REG_PROT_NAV_SHORT
| RT2860_REG_PROT_CTRL_NONE
|
3474 RT2860_REG_TXOP_ALLOW_ALL
|
3475 (RT2860_REG_PROT_PHYMODE_OFDM
<< RT2860_REG_PROT_PHYMODE_SHIFT
) |
3476 (0x84 << RT2860_REG_PROT_MCS_SHIFT
);
3478 gf40_prot
= mm40_prot
;
3482 rt2860_io_mac_write(sc
, RT2860_REG_TX_MM20_PROT_CFG
, mm20_prot
);
3483 rt2860_io_mac_write(sc
, RT2860_REG_TX_MM40_PROT_CFG
, mm40_prot
);
3484 rt2860_io_mac_write(sc
, RT2860_REG_TX_GF20_PROT_CFG
, gf20_prot
);
3485 rt2860_io_mac_write(sc
, RT2860_REG_TX_GF40_PROT_CFG
, gf40_prot
);
3489 * rt2860_asic_updateslot
3491 static void rt2860_asic_updateslot(struct rt2860_softc
*sc
)
3493 struct ieee80211com
*ic
;
3498 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATE
,
3499 "%s: %s short slot time\n",
3500 device_get_nameunit(sc
->dev
),
3501 (ic
->ic_flags
& (IEEE80211_F_SHSLOT
| IEEE80211_F_BURST
)) ? "enabling" : "disabling");
3503 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_BKOFF_SLOT_CFG
);
3506 tmp
|= (ic
->ic_flags
& (IEEE80211_F_SHSLOT
|IEEE80211_F_BURST
)) ? 9 : 20;
3508 rt2860_io_mac_write(sc
, RT2860_REG_BKOFF_SLOT_CFG
, tmp
);
3512 * rt2860_asic_wme_update
3514 static void rt2860_asic_wme_update(struct rt2860_softc
*sc
)
3516 struct ieee80211com
*ic
;
3517 struct ieee80211_wme_state
*wme
;
3518 const struct wmeParams
*wmep
;
3523 wmep
= wme
->wme_chanParams
.cap_wmeParams
;
3525 RT2860_DPRINTF(sc
, RT2860_DEBUG_WME
,
3526 "%s: wme update: WME_AC_VO=%d/%d/%d/%d, WME_AC_VI=%d/%d/%d/%d, "
3527 "WME_AC_BK=%d/%d/%d/%d, WME_AC_BE=%d/%d/%d/%d\n",
3528 device_get_nameunit(sc
->dev
),
3529 wmep
[WME_AC_VO
].wmep_aifsn
,
3530 wmep
[WME_AC_VO
].wmep_logcwmin
, wmep
[WME_AC_VO
].wmep_logcwmax
,
3531 wmep
[WME_AC_VO
].wmep_txopLimit
,
3532 wmep
[WME_AC_VI
].wmep_aifsn
,
3533 wmep
[WME_AC_VI
].wmep_logcwmin
, wmep
[WME_AC_VI
].wmep_logcwmax
,
3534 wmep
[WME_AC_VI
].wmep_txopLimit
,
3535 wmep
[WME_AC_BK
].wmep_aifsn
,
3536 wmep
[WME_AC_BK
].wmep_logcwmin
, wmep
[WME_AC_BK
].wmep_logcwmax
,
3537 wmep
[WME_AC_BK
].wmep_txopLimit
,
3538 wmep
[WME_AC_BE
].wmep_aifsn
,
3539 wmep
[WME_AC_BE
].wmep_logcwmin
, wmep
[WME_AC_BE
].wmep_logcwmax
,
3540 wmep
[WME_AC_BE
].wmep_txopLimit
);
3542 for (i
= 0; i
< WME_NUM_AC
; i
++)
3543 rt2860_io_mac_write(sc
, RT2860_REG_TX_EDCA_AC_CFG(i
),
3544 (wmep
[i
].wmep_logcwmax
<< 16) | (wmep
[i
].wmep_logcwmin
<< 12) |
3545 (wmep
[i
].wmep_aifsn
<< 8) | wmep
[i
].wmep_txopLimit
);
3547 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WMM_AIFSN_CFG
,
3548 (wmep
[WME_AC_VO
].wmep_aifsn
<< 12) | (wmep
[WME_AC_VI
].wmep_aifsn
<< 8) |
3549 (wmep
[WME_AC_BK
].wmep_aifsn
<< 4) | wmep
[WME_AC_BE
].wmep_aifsn
);
3551 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WMM_CWMIN_CFG
,
3552 (wmep
[WME_AC_VO
].wmep_logcwmin
<< 12) | (wmep
[WME_AC_VI
].wmep_logcwmin
<< 8) |
3553 (wmep
[WME_AC_BK
].wmep_logcwmin
<< 4) | wmep
[WME_AC_BE
].wmep_logcwmin
);
3555 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WMM_CWMAX_CFG
,
3556 (wmep
[WME_AC_VO
].wmep_logcwmax
<< 12) | (wmep
[WME_AC_VI
].wmep_logcwmax
<< 8) |
3557 (wmep
[WME_AC_BK
].wmep_logcwmax
<< 4) | wmep
[WME_AC_BE
].wmep_logcwmax
);
3559 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WMM_TXOP0_CFG
,
3560 (wmep
[WME_AC_BK
].wmep_txopLimit
<< 16) | wmep
[WME_AC_BE
].wmep_txopLimit
);
3562 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WMM_TXOP1_CFG
,
3563 (wmep
[WME_AC_VO
].wmep_txopLimit
<< 16) | wmep
[WME_AC_VI
].wmep_txopLimit
);
3567 * rt2860_asic_update_beacon
3569 static void rt2860_asic_update_beacon(struct rt2860_softc
*sc
)
3571 struct ieee80211com
*ic
;
3573 struct rt2860_txwi
*txwi
;
3578 m
= sc
->beacon_mbuf
;
3579 txwi
= &sc
->beacon_txwi
;
3581 /* disable temporarily TSF sync */
3583 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_BCN_TIME_CFG
);
3585 tmp
&= ~(RT2860_REG_BCN_TX_ENABLE
|
3586 RT2860_REG_TSF_TIMER_ENABLE
|
3587 RT2860_REG_TBTT_TIMER_ENABLE
);
3589 rt2860_io_mac_write(sc
, RT2860_REG_BCN_TIME_CFG
, tmp
);
3591 /* write Tx wireless info and beacon frame to on-chip memory */
3593 rt2860_io_mac_write_multi(sc
, RT2860_REG_BEACON_BASE(0),
3594 txwi
, sizeof(struct rt2860_txwi
));
3596 rt2860_io_mac_write_multi(sc
, RT2860_REG_BEACON_BASE(0) + sizeof(struct rt2860_txwi
),
3597 mtod(m
, uint8_t *), m
->m_pkthdr
.len
);
3599 /* enable again TSF sync */
3601 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_BCN_TIME_CFG
);
3603 tmp
|= (RT2860_REG_BCN_TX_ENABLE
|
3604 RT2860_REG_TSF_TIMER_ENABLE
|
3605 RT2860_REG_TBTT_TIMER_ENABLE
);
3607 rt2860_io_mac_write(sc
, RT2860_REG_BCN_TIME_CFG
, tmp
);
3611 * rt2860_asic_clear_keytables
3613 static void rt2860_asic_clear_keytables(struct rt2860_softc
*sc
)
3617 /* clear Rx WCID search table (entries = 256, entry size = 8) */
3619 for (i
= 0; i
< 256; i
++)
3621 rt2860_io_mac_write(sc
, RT2860_REG_WCID(i
), 0xffffffff);
3622 rt2860_io_mac_write(sc
, RT2860_REG_WCID(i
) + 4, 0x0000ffff);
3625 /* clear WCID attribute table (entries = 256, entry size = 4) */
3627 rt2860_io_mac_set_region_4(sc
, RT2860_REG_WCID_ATTR(0), 0, 256);
3629 /* clear IV/EIV table (entries = 256, entry size = 8) */
3631 rt2860_io_mac_set_region_4(sc
, RT2860_REG_IVEIV(0), 0, 2 * 256);
3633 /* clear pairwise key table (entries = 64, entry size = 32) */
3635 rt2860_io_mac_set_region_4(sc
, RT2860_REG_PKEY(0), 0, 8 * 64);
3637 /* clear shared key table (entries = 32, entry size = 32) */
3639 rt2860_io_mac_set_region_4(sc
, RT2860_REG_SKEY(0, 0), 0, 8 * 32);
3641 /* clear shared key mode (entries = 32, entry size = 2) */
3643 rt2860_io_mac_set_region_4(sc
, RT2860_REG_SKEY_MODE(0), 0, 16);
3647 * rt2860_asic_add_ba_session
3649 static void rt2860_asic_add_ba_session(struct rt2860_softc
*sc
,
3650 uint8_t wcid
, int tid
)
3654 RT2860_DPRINTF(sc
, RT2860_DEBUG_BA
,
3655 "%s: adding BA session: wcid=0x%02x, tid=%d\n",
3656 device_get_nameunit(sc
->dev
), wcid
, tid
);
3658 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_WCID(wcid
) + 4);
3660 tmp
|= (0x10000 << tid
);
3662 rt2860_io_mac_write(sc
, RT2860_REG_WCID(wcid
) + 4, tmp
);
3666 * rt2860_asic_del_ba_session
3668 static void rt2860_asic_del_ba_session(struct rt2860_softc
*sc
,
3669 uint8_t wcid
, int tid
)
3673 RT2860_DPRINTF(sc
, RT2860_DEBUG_BA
,
3674 "%s: deleting BA session: wcid=0x%02x, tid=%d\n",
3675 device_get_nameunit(sc
->dev
), wcid
, tid
);
3677 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_WCID(wcid
) + 4);
3679 tmp
&= ~(0x10000 << tid
);
3681 rt2860_io_mac_write(sc
, RT2860_REG_WCID(wcid
) + 4, tmp
);
3685 * rt2860_beacon_alloc
3687 static int rt2860_beacon_alloc(struct rt2860_softc
*sc
)
3689 struct ieee80211com
*ic
;
3691 struct rt2860_txwi txwi
;
3696 m
= ieee80211_beacon_alloc(ic
->ic_bss
, &sc
->beacon_offsets
);
3700 rate
= IEEE80211_IS_CHAN_5GHZ(ic
->ic_curchan
) ? 12 : 2;
3701 mcs
= rt2860_rate2mcs(rate
);
3703 RT2860_DPRINTF(sc
, RT2860_DEBUG_BEACON
,
3704 "%s: beacon allocate: mcs=0x%02x\n",
3705 device_get_nameunit(sc
->dev
), mcs
);
3707 memset(&txwi
, 0, sizeof(struct rt2860_txwi
));
3709 txwi
.wcid
= RT2860_WCID_RESERVED
;
3710 txwi
.pid_mpdu_len
= ((htole16(m
->m_pkthdr
.len
) & RT2860_TXWI_MPDU_LEN_MASK
) <<
3711 RT2860_TXWI_MPDU_LEN_SHIFT
);
3712 txwi
.txop
= (RT2860_TXWI_TXOP_HT
<< RT2860_TXWI_TXOP_SHIFT
);
3713 txwi
.mpdu_density_flags
|=
3714 (RT2860_TXWI_FLAGS_TS
<< RT2860_TXWI_FLAGS_SHIFT
);
3715 txwi
.bawin_size_xflags
|=
3716 (RT2860_TXWI_XFLAGS_NSEQ
<< RT2860_TXWI_XFLAGS_SHIFT
);
3720 txwi
.phymode_ifs_stbc_shortgi
=
3721 (RT2860_TXWI_PHYMODE_CCK
<< RT2860_TXWI_PHYMODE_SHIFT
);
3723 if (rate
!= 2 && (ic
->ic_flags
& IEEE80211_F_SHPREAMBLE
))
3724 mcs
|= RT2860_TXWI_MCS_SHOTPRE
;
3728 txwi
.phymode_ifs_stbc_shortgi
=
3729 (RT2860_TXWI_PHYMODE_OFDM
<< RT2860_TXWI_PHYMODE_SHIFT
);
3732 txwi
.bw_mcs
= (RT2860_TXWI_BW_20
<< RT2860_TXWI_BW_SHIFT
) |
3733 ((mcs
& RT2860_TXWI_MCS_MASK
) << RT2860_TXWI_MCS_SHIFT
);
3735 if (sc
->beacon_mbuf
!= NULL
)
3737 m_free(sc
->beacon_mbuf
);
3738 sc
->beacon_mbuf
= NULL
;
3741 sc
->beacon_mbuf
= m
;
3742 sc
->beacon_txwi
= txwi
;
3750 static uint8_t rt2860_rxrate(struct rt2860_rxwi
*rxwi
)
3752 uint8_t mcs
, phymode
;
3755 mcs
= (rxwi
->bw_mcs
>> RT2860_RXWI_MCS_SHIFT
) & RT2860_RXWI_MCS_MASK
;
3756 phymode
= (rxwi
->phymode_stbc_shortgi
>> RT2860_RXWI_PHYMODE_SHIFT
) &
3757 RT2860_RXWI_PHYMODE_MASK
;
3763 case RT2860_RXWI_PHYMODE_CCK
:
3764 switch (mcs
& ~RT2860_RXWI_MCS_SHOTPRE
)
3766 case 0: rate
= 2; break; /* 1 Mbps */
3767 case 1: rate
= 4; break; /* 2 MBps */
3768 case 2: rate
= 11; break; /* 5.5 Mbps */
3769 case 3: rate
= 22; break; /* 11 Mbps */
3773 case RT2860_RXWI_PHYMODE_OFDM
:
3776 case 0: rate
= 12; break; /* 6 Mbps */
3777 case 1: rate
= 18; break; /* 9 Mbps */
3778 case 2: rate
= 24; break; /* 12 Mbps */
3779 case 3: rate
= 36; break; /* 18 Mbps */
3780 case 4: rate
= 48; break; /* 24 Mbps */
3781 case 5: rate
= 72; break; /* 36 Mbps */
3782 case 6: rate
= 96; break; /* 48 Mbps */
3783 case 7: rate
= 108; break; /* 54 Mbps */
3787 case RT2860_RXWI_PHYMODE_HT_MIXED
:
3788 case RT2860_RXWI_PHYMODE_HT_GF
:
3796 * rt2860_maxrssi_rxpath
3798 static uint8_t rt2860_maxrssi_rxpath(struct rt2860_softc
*sc
,
3799 const struct rt2860_rxwi
*rxwi
)
3805 if (sc
->nrxpath
> 1)
3806 if (rxwi
->rssi
[1] > rxwi
->rssi
[rxpath
])
3809 if (sc
->nrxpath
> 2)
3810 if (rxwi
->rssi
[2] > rxwi
->rssi
[rxpath
])
3819 static int8_t rt2860_rssi2dbm(struct rt2860_softc
*sc
,
3820 uint8_t rssi
, uint8_t rxpath
)
3822 struct ieee80211com
*ic
;
3823 struct ieee80211_channel
*c
;
3825 int8_t rssi_off
, lna_gain
;
3832 chan
= ieee80211_chan2ieee(ic
, c
);
3834 if (IEEE80211_IS_CHAN_5GHZ(c
))
3836 rssi_off
= sc
->rssi_off_5ghz
[rxpath
];
3839 lna_gain
= sc
->lna_gain
[1];
3840 else if (chan
<= 128)
3841 lna_gain
= sc
->lna_gain
[2];
3843 lna_gain
= sc
->lna_gain
[3];
3847 rssi_off
= sc
->rssi_off_2ghz
[rxpath
];
3848 lna_gain
= sc
->lna_gain
[0];
3851 return (-12 - rssi_off
- lna_gain
- rssi
);
3857 static uint8_t rt2860_rate2mcs(uint8_t rate
)
3884 static int rt2860_ackrate(struct ieee80211com
*ic
, int rate
)
3896 return (ic
->ic_curmode
== IEEE80211_MODE_11B
) ? 4 : rate
;
3915 /* default to 1Mbps */
3922 static uint16_t rt2860_txtime(int len
, int rate
, uint32_t flags
)
3926 if (RT2860_RATE_IS_OFDM(rate
))
3928 txtime
= (8 + 4 * len
+ 3 + rate
- 1) / rate
;
3929 txtime
= 16 + 4 + 4 * txtime
+ 6;
3933 txtime
= (16 * len
+ rate
- 1) / rate
;
3935 if (rate
!= 2 && (flags
& IEEE80211_F_SHPREAMBLE
))
3947 static int rt2860_tx_frame(struct rt2860_softc
*sc
,
3948 struct mbuf
*m
, struct ieee80211_node
*ni
, int qid
)
3950 struct ieee80211com
*ic
;
3951 struct rt2860_softc_node
*rni
;
3952 struct rt2860_softc_tx_ring
*ring
;
3953 struct rt2860_softc_tx_data
*data
;
3954 struct rt2860_txdesc
*desc
;
3955 struct rt2860_txwi
*txwi
;
3956 struct ieee80211_frame
*wh
;
3957 struct ieee80211_tx_ampdu
*tx_ampdu
;
3958 struct rt2860_softc_tx_radiotap_header
*tap
;
3959 bus_dma_segment_t dma_seg
[RT2860_SOFTC_MAX_SCATTER
];
3960 u_int hdrsize
, hdrspace
;
3961 uint8_t type
, rate
, bw
, stbc
, shortgi
, mcs
, pid
, wcid
, mpdu_density
, bawin_size
, qsel
;
3962 uint16_t qos
, len
, dmalen
, mpdu_len
, dur
;
3963 int error
, hasqos
, ac
, ampdu
, mimops
, ackrate
, ndmasegs
, ndescs
, i
, j
;
3965 KASSERT(qid
>= 0 && qid
< RT2860_SOFTC_TX_RING_COUNT
,
3966 ("%s: Tx frame: invalid qid=%d\n",
3967 device_get_nameunit(sc
->dev
), qid
));
3969 RT2860_SOFTC_TX_RING_ASSERT_LOCKED(&sc
->tx_ring
[qid
]);
3972 rni
= (struct rt2860_softc_node
*) ni
;
3974 ring
= &sc
->tx_ring
[qid
];
3975 desc
= &ring
->desc
[ring
->desc_cur
];
3976 data
= &ring
->data
[ring
->data_cur
];
3977 txwi
= (struct rt2860_txwi
*) (ring
->seg0
+ ring
->data_cur
* RT2860_TX_DATA_SEG0_SIZE
);
3979 wh
= mtod(m
, struct ieee80211_frame
*);
3981 type
= wh
->i_fc
[0] & IEEE80211_FC0_TYPE_MASK
;
3983 hasqos
= IEEE80211_QOS_HAS_SEQ(wh
);
3986 if (IEEE80211_HAS_ADDR4(wh
))
3987 qos
= le16toh(*(const uint16_t *)
3988 (((struct ieee80211_qosframe_addr4
*) wh
)->i_qos
));
3990 qos
= le16toh(*(const uint16_t *)
3991 (((struct ieee80211_qosframe
*) wh
)->i_qos
));
3998 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
4000 if (IEEE80211_IS_MULTICAST(wh
->i_addr1
) || type
!= IEEE80211_FC0_TYPE_DATA
)
4002 else if (ic
->ic_fixed_rate
!= IEEE80211_FIXED_RATE_NONE
)
4003 rate
= ic
->ic_fixed_rate
;
4005 rate
= ni
->ni_htrates
.rs_rates
[ni
->ni_txrate
];
4009 if (IEEE80211_IS_MULTICAST(wh
->i_addr1
) || type
!= IEEE80211_FC0_TYPE_DATA
)
4010 rate
= IEEE80211_IS_CHAN_5GHZ(ic
->ic_curchan
) ? 12 : 2;
4011 else if (ic
->ic_fixed_rate
!= IEEE80211_FIXED_RATE_NONE
)
4012 rate
= ic
->ic_fixed_rate
;
4014 rate
= ni
->ni_rates
.rs_rates
[ni
->ni_txrate
];
4017 rate
&= IEEE80211_RATE_VAL
;
4019 /* fill Tx wireless info */
4021 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
4024 mcs
= rt2860_rate2mcs(rate
);
4026 /* management frames do not need encryption */
4028 if (type
== IEEE80211_FC0_TYPE_DATA
)
4029 wcid
= !IEEE80211_IS_MULTICAST(wh
->i_addr1
) ? rni
->staid
: RT2860_WCID_MCAST
;
4031 wcid
= RT2860_WCID_RESERVED
;
4033 /* calculate MPDU length without padding */
4035 hdrsize
= ieee80211_anyhdrsize(wh
);
4036 hdrspace
= ieee80211_anyhdrspace(ic
, wh
);
4037 mpdu_len
= m
->m_pkthdr
.len
- hdrspace
+ hdrsize
;
4039 memset(txwi
, 0, sizeof(struct rt2860_txwi
));
4043 /* MIMO power save */
4045 if ((ni
->ni_flags
& IEEE80211_NODE_HT
) &&
4046 ((ni
->ni_htcap
& IEEE80211_HTCAP_SMPS
) != IEEE80211_HTCAP_SMPS_OFF
))
4050 if ((ni
->ni_htcap
& IEEE80211_HTCAP_SMPS
) == IEEE80211_HTCAP_SMPS_DYNAMIC
)
4052 /* dynamic MIMO power save */
4054 txwi
->mpdu_density_flags
|=
4055 (RT2860_TXWI_FLAGS_MIMOPS
<< RT2860_TXWI_FLAGS_SHIFT
);
4059 /* static MIMO power save */
4074 txwi
->pid_mpdu_len
= ((htole16(pid
) & RT2860_TXWI_PID_MASK
) <<
4075 RT2860_TXWI_PID_SHIFT
) | ((htole16(mpdu_len
) & RT2860_TXWI_MPDU_LEN_MASK
) <<
4076 RT2860_TXWI_MPDU_LEN_SHIFT
);
4078 stbc
= sc
->tx_stbc
&& (ic
->ic_htcaps
& IEEE80211_HTCAP_TXSTBC
) &&
4079 (ni
->ni_flags
& IEEE80211_NODE_HT
) && (ni
->ni_htcap
& IEEE80211_HTCAP_RXSTBC
);
4081 shortgi
= ((ic
->ic_flags_ext
& IEEE80211_FEXT_SHORTGI20
) &&
4082 (ni
->ni_flags
& IEEE80211_NODE_HT
) && (ni
->ni_htcap
& IEEE80211_HTCAP_SHORTGI20
) &&
4083 (ni
->ni_chw
== 20)) ||
4084 ((ic
->ic_flags_ext
& IEEE80211_FEXT_SHORTGI40
) &&
4085 (ni
->ni_flags
& IEEE80211_NODE_HT
) && (ni
->ni_htcap
& IEEE80211_HTCAP_SHORTGI40
) &&
4086 (ni
->ni_chw
== 40));
4088 txwi
->phymode_ifs_stbc_shortgi
|=
4089 ((stbc
& RT2860_TXWI_STBC_MASK
) << RT2860_TXWI_STBC_SHIFT
) |
4090 ((shortgi
& RT2860_TXWI_SHORTGI_MASK
) << RT2860_TXWI_SHORTGI_SHIFT
);
4092 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
4094 txwi
->phymode_ifs_stbc_shortgi
|=
4095 (RT2860_TXWI_PHYMODE_HT_MIXED
<< RT2860_TXWI_PHYMODE_SHIFT
);
4099 if (!RT2860_RATE_IS_OFDM(rate
))
4101 txwi
->phymode_ifs_stbc_shortgi
|=
4102 (RT2860_TXWI_PHYMODE_CCK
<< RT2860_TXWI_PHYMODE_SHIFT
);
4104 if (rate
!= 2 && (ic
->ic_flags
& IEEE80211_F_SHPREAMBLE
))
4105 mcs
|= RT2860_TXWI_MCS_SHOTPRE
;
4109 txwi
->phymode_ifs_stbc_shortgi
|=
4110 (RT2860_TXWI_PHYMODE_OFDM
<< RT2860_TXWI_PHYMODE_SHIFT
);
4114 if ((ni
->ni_flags
& IEEE80211_NODE_HT
) && (ni
->ni_chw
== 40))
4115 bw
= RT2860_TXWI_BW_40
;
4117 bw
= RT2860_TXWI_BW_20
;
4119 txwi
->bw_mcs
= ((bw
& RT2860_TXWI_BW_MASK
) << RT2860_TXWI_BW_SHIFT
) |
4120 ((mcs
& RT2860_TXWI_MCS_MASK
) << RT2860_TXWI_MCS_SHIFT
);
4122 if (type
!= IEEE80211_FC0_TYPE_DATA
)
4123 txwi
->txop
= (RT2860_TXWI_TXOP_BACKOFF
<< RT2860_TXWI_TXOP_SHIFT
);
4125 txwi
->txop
= (RT2860_TXWI_TXOP_HT
<< RT2860_TXWI_TXOP_SHIFT
);
4127 /* skip ACKs for multicast frames */
4129 if (!IEEE80211_IS_MULTICAST(wh
->i_addr1
) &&
4130 (!hasqos
|| (qos
& IEEE80211_QOS_ACKPOLICY
) != IEEE80211_QOS_ACKPOLICY_NOACK
))
4132 txwi
->bawin_size_xflags
|=
4133 (RT2860_TXWI_XFLAGS_ACK
<< RT2860_TXWI_XFLAGS_SHIFT
);
4135 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
4137 /* preamble + plcp + signal extension + SIFS */
4139 dur
= 16 + 4 + 6 + 10;
4143 ackrate
= rt2860_ackrate(ic
, rate
);
4145 dur
= rt2860_txtime(RT2860_ACK_SIZE
, ackrate
, ic
->ic_flags
) +
4149 *(uint16_t *) wh
->i_dur
= htole16(dur
);
4152 /* check for A-MPDU */
4154 if ((qos
& IEEE80211_QOS_ACKPOLICY
) == IEEE80211_QOS_ACKPOLICY_BA
)
4156 ac
= M_WME_GETAC(m
);
4157 tx_ampdu
= &ni
->ni_tx_ampdu
[ac
];
4159 mpdu_density
= RT2860_MS(ni
->ni_htparam
, IEEE80211_HTCAP_MPDUDENSITY
);
4160 bawin_size
= tx_ampdu
->txa_wnd
;
4162 txwi
->mpdu_density_flags
|=
4163 ((mpdu_density
& RT2860_TXWI_MPDU_DENSITY_MASK
) << RT2860_TXWI_MPDU_DENSITY_SHIFT
) |
4164 (RT2860_TXWI_FLAGS_AMPDU
<< RT2860_TXWI_FLAGS_SHIFT
);
4166 txwi
->bawin_size_xflags
|=
4167 ((bawin_size
& RT2860_TXWI_BAWIN_SIZE_MASK
) << RT2860_TXWI_BAWIN_SIZE_SHIFT
);
4169 if (IEEE80211_HAS_ADDR4(wh
))
4170 ((struct ieee80211_qosframe_addr4
*) wh
)->i_qos
[0] &= ~IEEE80211_QOS_ACKPOLICY
;
4172 ((struct ieee80211_qosframe
*) wh
)->i_qos
[0] &= ~IEEE80211_QOS_ACKPOLICY
;
4181 /* ask MAC to insert timestamp into probe responses */
4183 if ((wh
->i_fc
[0] & (IEEE80211_FC0_TYPE_MASK
| IEEE80211_FC0_SUBTYPE_MASK
)) ==
4184 (IEEE80211_FC0_TYPE_MGT
| IEEE80211_FC0_SUBTYPE_PROBE_RESP
))
4185 txwi
->mpdu_density_flags
|=
4186 (RT2860_TXWI_FLAGS_TS
<< RT2860_TXWI_FLAGS_SHIFT
);
4188 if (bpf_peers_present(sc
->drvbpf
))
4192 tap
->flags
= IEEE80211_RADIOTAP_F_DATAPAD
;
4193 tap
->chan_flags
= htole32(ic
->ic_curchan
->ic_flags
);
4194 tap
->chan_freq
= htole16(ic
->ic_curchan
->ic_freq
);
4195 tap
->chan_ieee
= ic
->ic_curchan
->ic_ieee
;
4196 tap
->chan_maxpow
= 0;
4198 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
4199 tap
->rate
= mcs
| IEEE80211_RATE_MCS
;
4203 if (mcs
& RT2860_TXWI_MCS_SHOTPRE
)
4204 tap
->flags
|= IEEE80211_RADIOTAP_F_SHORTPRE
;
4207 tap
->flags
|= IEEE80211_RADIOTAP_F_SHORTGI
;
4209 if (wh
->i_fc
[1] & IEEE80211_FC1_WEP
)
4210 tap
->flags
|= IEEE80211_RADIOTAP_F_WEP
;
4212 if (wh
->i_fc
[1] & IEEE80211_FC1_WEP
)
4214 wh
->i_fc
[1] &= ~IEEE80211_FC1_WEP
;
4216 bpf_mtap2(sc
->drvbpf
, tap
, sc
->txtap_len
, m
);
4218 wh
->i_fc
[1] |= IEEE80211_FC1_WEP
;
4222 bpf_mtap2(sc
->drvbpf
, tap
, sc
->txtap_len
, m
);
4226 /* copy and trim 802.11 header */
4228 m_copydata(m
, 0, hdrsize
, (caddr_t
) (txwi
+ 1));
4231 error
= bus_dmamap_load_mbuf_sg(ring
->data_dma_tag
, data
->dma_map
, m
,
4232 dma_seg
, &ndmasegs
, 0);
4235 /* too many fragments, linearize */
4237 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
4238 "%s: could not load mbuf DMA map, trying to linearize mbuf\n",
4239 device_get_nameunit(sc
->dev
));
4241 m
= m_defrag(m
, M_DONTWAIT
);
4245 sc
->tx_defrag_packets
++;
4247 error
= bus_dmamap_load_mbuf_sg(ring
->data_dma_tag
, data
->dma_map
, m
,
4248 dma_seg
, &ndmasegs
, 0);
4251 printf("%s: could not load mbuf DMA map: error=%d\n",
4252 device_get_nameunit(sc
->dev
), error
);
4258 if (m
->m_pkthdr
.len
== 0)
4261 /* determine how many Tx descs are required */
4263 ndescs
= 1 + ndmasegs
/ 2;
4264 if ((ring
->desc_queued
+ ndescs
) > (RT2860_SOFTC_TX_RING_DESC_COUNT
- 2))
4266 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
4267 "%s: there are not enough Tx descs\n",
4268 device_get_nameunit(sc
->dev
));
4270 sc
->no_tx_desc_avail
++;
4272 bus_dmamap_unload(ring
->data_dma_tag
, data
->dma_map
);
4280 /* set up Tx descs */
4282 /* first segment is Tx wireless info and 802.11 header */
4284 len
= sizeof(struct rt2860_txwi
) + hdrsize
;
4286 /* align end on a 4-bytes boundary */
4288 dmalen
= (len
+ 3) & ~ 3;
4290 memset((caddr_t
) txwi
+ len
, 0, dmalen
- len
);
4292 qsel
= RT2860_TXDESC_QSEL_EDCA
;
4294 desc
->sdp0
= htole32(ring
->seg0_phys_addr
+ ring
->data_cur
* RT2860_TX_DATA_SEG0_SIZE
);
4295 desc
->sdl0
= htole16(dmalen
);
4296 desc
->qsel_flags
= (qsel
<< RT2860_TXDESC_QSEL_SHIFT
);
4298 /* set up payload segments */
4300 for (i
= ndmasegs
, j
= 0; i
>= 2; i
-= 2)
4302 desc
->sdp1
= htole32(dma_seg
[j
].ds_addr
);
4303 desc
->sdl1
= htole16(dma_seg
[j
].ds_len
);
4305 ring
->desc_queued
++;
4306 ring
->desc_cur
= (ring
->desc_cur
+ 1) % RT2860_SOFTC_TX_RING_DESC_COUNT
;
4310 desc
= &ring
->desc
[ring
->desc_cur
];
4312 desc
->sdp0
= htole32(dma_seg
[j
].ds_addr
);
4313 desc
->sdl0
= htole16(dma_seg
[j
].ds_len
);
4314 desc
->qsel_flags
= (qsel
<< RT2860_TXDESC_QSEL_SHIFT
);
4319 /* finalize last payload segment */
4323 desc
->sdp1
= htole32(dma_seg
[j
].ds_addr
);
4324 desc
->sdl1
= htole16(dma_seg
[j
].ds_len
| RT2860_TXDESC_SDL1_LASTSEG
);
4328 desc
->sdl0
|= htole16(RT2860_TXDESC_SDL0_LASTSEG
);
4332 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
4333 "%s: sending frame: qid=%d, hdrsize=%d, hdrspace=%d, len=%d, "
4334 "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",
4335 device_get_nameunit(sc
->dev
),
4336 qid
, hdrsize
, hdrspace
, m
->m_pkthdr
.len
+ hdrsize
,
4337 bw
, stbc
, shortgi
, mcs
, wcid
, ampdu
, mimops
, dmalen
, ndmasegs
,
4338 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
);
4340 bus_dmamap_sync(ring
->seg0_dma_tag
, ring
->seg0_dma_map
,
4341 BUS_DMASYNC_PREWRITE
);
4342 bus_dmamap_sync(ring
->data_dma_tag
, data
->dma_map
,
4343 BUS_DMASYNC_PREWRITE
);
4344 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
4345 BUS_DMASYNC_PREWRITE
);
4347 ring
->desc_queued
++;
4348 ring
->desc_cur
= (ring
->desc_cur
+ 1) % RT2860_SOFTC_TX_RING_DESC_COUNT
;
4350 ring
->data_queued
++;
4351 ring
->data_cur
= (ring
->data_cur
+ 1) % RT2860_SOFTC_TX_RING_DATA_COUNT
;
4355 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_CTX_IDX(qid
), ring
->desc_cur
);
4363 static int rt2860_tx_raw(struct rt2860_softc
*sc
,
4364 struct mbuf
*m
, struct ieee80211_node
*ni
,
4365 const struct ieee80211_bpf_params
*params
)
4367 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
4369 device_get_nameunit(sc
->dev
));
4377 static void rt2860_intr(void *arg
)
4379 struct rt2860_softc
*sc
;
4386 /* acknowledge interrupts */
4388 status
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_INT_STATUS
);
4389 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_INT_STATUS
, status
);
4391 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4392 "%s: interrupt: status = 0x%08x\n",
4393 device_get_nameunit(sc
->dev
), status
);
4395 if (status
== 0xffffffff || /* device likely went away */
4396 status
== 0) /* not for us */
4401 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
4404 if (status
& RT2860_REG_INT_TX_COHERENT
)
4405 rt2860_tx_coherent_intr(sc
);
4407 if (status
& RT2860_REG_INT_RX_COHERENT
)
4408 rt2860_rx_coherent_intr(sc
);
4410 if (status
& RT2860_REG_INT_TXRX_COHERENT
)
4411 rt2860_txrx_coherent_intr(sc
);
4413 if (status
& RT2860_REG_INT_FIFO_STA_FULL
)
4414 rt2860_fifo_sta_full_intr(sc
);
4416 if (status
& RT2860_REG_INT_TX_MGMT_DONE
)
4417 rt2860_tx_intr(sc
, 5);
4419 if (status
& RT2860_REG_INT_RX_DONE
)
4422 if (status
& RT2860_REG_INT_RX_DELAY_DONE
)
4423 rt2860_rx_delay_intr(sc
);
4425 if (status
& RT2860_REG_INT_TX_HCCA_DONE
)
4426 rt2860_tx_intr(sc
, 4);
4428 if (status
& RT2860_REG_INT_TX_AC3_DONE
)
4429 rt2860_tx_intr(sc
, 3);
4431 if (status
& RT2860_REG_INT_TX_AC2_DONE
)
4432 rt2860_tx_intr(sc
, 2);
4434 if (status
& RT2860_REG_INT_TX_AC1_DONE
)
4435 rt2860_tx_intr(sc
, 1);
4437 if (status
& RT2860_REG_INT_TX_AC0_DONE
)
4438 rt2860_tx_intr(sc
, 0);
4440 if (status
& RT2860_REG_INT_TX_DELAY_DONE
)
4441 rt2860_tx_delay_intr(sc
);
4443 if (status
& RT2860_REG_INT_PRE_TBTT
)
4444 rt2860_pre_tbtt_intr(sc
);
4446 if (status
& RT2860_REG_INT_TBTT
)
4447 rt2860_tbtt_intr(sc
);
4449 if (status
& RT2860_REG_INT_MCU_CMD
)
4450 rt2860_mcu_cmd_intr(sc
);
4452 if (status
& RT2860_REG_INT_AUTO_WAKEUP
)
4453 rt2860_auto_wakeup_intr(sc
);
4455 if (status
& RT2860_REG_INT_GP_TIMER
)
4456 rt2860_gp_timer_intr(sc
);
4460 * rt2860_tx_coherent_intr
4462 static void rt2860_tx_coherent_intr(struct rt2860_softc
*sc
)
4467 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4468 "%s: Tx coherent interrupt\n",
4469 device_get_nameunit(sc
->dev
));
4471 sc
->tx_coherent_interrupts
++;
4473 /* restart DMA engine */
4475 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
);
4477 tmp
&= ~(RT2860_REG_TX_WB_DDONE
|
4478 RT2860_REG_RX_DMA_ENABLE
|
4479 RT2860_REG_TX_DMA_ENABLE
);
4481 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
, tmp
);
4483 /* init Tx rings (4 EDCAs + HCCA + MGMT) */
4485 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
4486 rt2860_reset_tx_ring(sc
, &sc
->tx_ring
[i
]);
4488 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
4490 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_BASE_PTR(i
),
4491 sc
->tx_ring
[i
].desc_phys_addr
);
4492 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_MAX_CNT(i
),
4493 RT2860_SOFTC_TX_RING_DESC_COUNT
);
4494 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_CTX_IDX(i
), 0);
4499 rt2860_reset_rx_ring(sc
, &sc
->rx_ring
);
4501 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_BASE_PTR
,
4502 sc
->rx_ring
.desc_phys_addr
);
4503 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_MAX_CNT
,
4504 RT2860_SOFTC_RX_RING_DATA_COUNT
);
4505 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_CALC_IDX
,
4506 RT2860_SOFTC_RX_RING_DATA_COUNT
- 1);
4508 rt2860_txrx_enable(sc
);
4512 * rt2860_rx_coherent_intr
4514 static void rt2860_rx_coherent_intr(struct rt2860_softc
*sc
)
4519 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4520 "%s: Rx coherent interrupt\n",
4521 device_get_nameunit(sc
->dev
));
4523 sc
->rx_coherent_interrupts
++;
4525 /* restart DMA engine */
4527 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
);
4529 tmp
&= ~(RT2860_REG_TX_WB_DDONE
|
4530 RT2860_REG_RX_DMA_ENABLE
|
4531 RT2860_REG_TX_DMA_ENABLE
);
4533 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
, tmp
);
4535 /* init Tx rings (4 EDCAs + HCCA + MGMT) */
4537 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
4538 rt2860_reset_tx_ring(sc
, &sc
->tx_ring
[i
]);
4540 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
4542 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_BASE_PTR(i
),
4543 sc
->tx_ring
[i
].desc_phys_addr
);
4544 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_MAX_CNT(i
),
4545 RT2860_SOFTC_TX_RING_DESC_COUNT
);
4546 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_CTX_IDX(i
), 0);
4551 rt2860_reset_rx_ring(sc
, &sc
->rx_ring
);
4553 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_BASE_PTR
,
4554 sc
->rx_ring
.desc_phys_addr
);
4555 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_MAX_CNT
,
4556 RT2860_SOFTC_RX_RING_DATA_COUNT
);
4557 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_CALC_IDX
,
4558 RT2860_SOFTC_RX_RING_DATA_COUNT
- 1);
4560 rt2860_txrx_enable(sc
);
4564 * rt2860_txrx_coherent_intr
4566 static void rt2860_txrx_coherent_intr(struct rt2860_softc
*sc
)
4571 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4572 "%s: Tx/Rx coherent interrupt\n",
4573 device_get_nameunit(sc
->dev
));
4575 sc
->txrx_coherent_interrupts
++;
4577 /* restart DMA engine */
4579 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
);
4581 tmp
&= ~(RT2860_REG_TX_WB_DDONE
|
4582 RT2860_REG_RX_DMA_ENABLE
|
4583 RT2860_REG_TX_DMA_ENABLE
);
4585 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
, tmp
);
4587 /* init Tx rings (4 EDCAs + HCCA + MGMT) */
4589 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
4590 rt2860_reset_tx_ring(sc
, &sc
->tx_ring
[i
]);
4592 for (i
= 0; i
< RT2860_SOFTC_TX_RING_COUNT
; i
++)
4594 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_BASE_PTR(i
),
4595 sc
->tx_ring
[i
].desc_phys_addr
);
4596 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_MAX_CNT(i
),
4597 RT2860_SOFTC_TX_RING_DESC_COUNT
);
4598 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_TX_CTX_IDX(i
), 0);
4603 rt2860_reset_rx_ring(sc
, &sc
->rx_ring
);
4605 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_BASE_PTR
,
4606 sc
->rx_ring
.desc_phys_addr
);
4607 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_MAX_CNT
,
4608 RT2860_SOFTC_RX_RING_DATA_COUNT
);
4609 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_CALC_IDX
,
4610 RT2860_SOFTC_RX_RING_DATA_COUNT
- 1);
4612 rt2860_txrx_enable(sc
);
4616 * rt2860_fifo_sta_full_intr
4618 static void rt2860_fifo_sta_full_intr(struct rt2860_softc
*sc
)
4620 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4621 "%s: FIFO statistic full interrupt\n",
4622 device_get_nameunit(sc
->dev
));
4624 sc
->fifo_sta_full_interrupts
++;
4626 RT2860_SOFTC_LOCK(sc
);
4628 if (!(sc
->intr_disable_mask
& RT2860_REG_INT_FIFO_STA_FULL
))
4630 rt2860_intr_disable(sc
, RT2860_REG_INT_FIFO_STA_FULL
);
4632 taskqueue_enqueue(sc
->taskqueue
, &sc
->fifo_sta_full_task
);
4635 sc
->intr_pending_mask
|= RT2860_REG_INT_FIFO_STA_FULL
;
4637 RT2860_SOFTC_UNLOCK(sc
);
4643 static void rt2860_rx_intr(struct rt2860_softc
*sc
)
4645 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4646 "%s: Rx interrupt\n",
4647 device_get_nameunit(sc
->dev
));
4649 sc
->rx_interrupts
++;
4651 RT2860_SOFTC_LOCK(sc
);
4653 if (!(sc
->intr_disable_mask
& RT2860_REG_INT_RX_DONE
))
4655 rt2860_intr_disable(sc
, RT2860_REG_INT_RX_DONE
);
4657 taskqueue_enqueue(sc
->taskqueue
, &sc
->rx_done_task
);
4660 sc
->intr_pending_mask
|= RT2860_REG_INT_RX_DONE
;
4662 RT2860_SOFTC_UNLOCK(sc
);
4666 * rt2860_rx_delay_intr
4668 static void rt2860_rx_delay_intr(struct rt2860_softc
*sc
)
4670 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4671 "%s: Rx delay interrupt\n",
4672 device_get_nameunit(sc
->dev
));
4674 sc
->rx_delay_interrupts
++;
4680 static void rt2860_tx_intr(struct rt2860_softc
*sc
, int qid
)
4682 KASSERT(qid
>= 0 && qid
< RT2860_SOFTC_TX_RING_COUNT
,
4683 ("%s: Tx interrupt: invalid qid=%d\n",
4684 device_get_nameunit(sc
->dev
), qid
));
4686 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4687 "%s: Tx interrupt: qid=%d\n",
4688 device_get_nameunit(sc
->dev
), qid
);
4690 sc
->tx_interrupts
[qid
]++;
4692 RT2860_SOFTC_LOCK(sc
);
4694 if (!(sc
->intr_disable_mask
& (RT2860_REG_INT_TX_AC0_DONE
<< qid
)))
4696 rt2860_intr_disable(sc
, (RT2860_REG_INT_TX_AC0_DONE
<< qid
));
4698 taskqueue_enqueue(sc
->taskqueue
, &sc
->tx_done_task
);
4701 sc
->intr_pending_mask
|= (RT2860_REG_INT_TX_AC0_DONE
<< qid
);
4703 RT2860_SOFTC_UNLOCK(sc
);
4707 * rt2860_tx_delay_intr
4709 static void rt2860_tx_delay_intr(struct rt2860_softc
*sc
)
4711 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4712 "%s: Tx delay interrupt\n",
4713 device_get_nameunit(sc
->dev
));
4715 sc
->tx_delay_interrupts
++;
4719 * rt2860_pre_tbtt_intr
4721 static void rt2860_pre_tbtt_intr(struct rt2860_softc
*sc
)
4723 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4724 "%s: Pre-TBTT interrupt\n",
4725 device_get_nameunit(sc
->dev
));
4727 sc
->pre_tbtt_interrupts
++;
4733 static void rt2860_tbtt_intr(struct rt2860_softc
*sc
)
4735 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4736 "%s: TBTT interrupt\n",
4737 device_get_nameunit(sc
->dev
));
4739 sc
->tbtt_interrupts
++;
4743 * rt2860_mcu_cmd_intr
4745 static void rt2860_mcu_cmd_intr(struct rt2860_softc
*sc
)
4747 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4748 "%s: MCU command interrupt\n",
4749 device_get_nameunit(sc
->dev
));
4751 sc
->mcu_cmd_interrupts
++;
4755 * rt2860_auto_wakeup_intr
4757 static void rt2860_auto_wakeup_intr(struct rt2860_softc
*sc
)
4759 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4760 "%s: auto wakeup interrupt\n",
4761 device_get_nameunit(sc
->dev
));
4763 sc
->auto_wakeup_interrupts
++;
4767 * rt2860_gp_timer_intr
4769 static void rt2860_gp_timer_intr(struct rt2860_softc
*sc
)
4771 RT2860_DPRINTF(sc
, RT2860_DEBUG_INTR
,
4772 "%s: GP timer interrupt\n",
4773 device_get_nameunit(sc
->dev
));
4775 sc
->gp_timer_interrupts
++;
4779 * rt2860_rx_done_task
4781 static void rt2860_rx_done_task(void *context
, int pending
)
4783 struct rt2860_softc
*sc
;
4790 RT2860_DPRINTF(sc
, RT2860_DEBUG_RX
,
4791 "%s: Rx done task\n",
4792 device_get_nameunit(sc
->dev
));
4794 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
4797 sc
->intr_pending_mask
&= ~RT2860_REG_INT_RX_DONE
;
4799 again
= rt2860_rx_eof(sc
, sc
->rx_process_limit
);
4801 RT2860_SOFTC_LOCK(sc
);
4803 if ((sc
->intr_pending_mask
& RT2860_REG_INT_RX_DONE
) || again
)
4805 RT2860_DPRINTF(sc
, RT2860_DEBUG_RX
,
4806 "%s: Rx done task: scheduling again\n",
4807 device_get_nameunit(sc
->dev
));
4809 taskqueue_enqueue(sc
->taskqueue
, &sc
->rx_done_task
);
4813 rt2860_intr_enable(sc
, RT2860_REG_INT_RX_DONE
);
4816 RT2860_SOFTC_UNLOCK(sc
);
4820 * rt2860_tx_done_task
4822 static void rt2860_tx_done_task(void *context
, int pending
)
4824 struct rt2860_softc
*sc
;
4826 struct ieee80211com
*ic
;
4834 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
4835 "%s: Tx done task\n",
4836 device_get_nameunit(sc
->dev
));
4838 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
4841 for (i
= RT2860_SOFTC_TX_RING_COUNT
- 1; i
>= 0; i
--)
4843 if (sc
->intr_pending_mask
& (RT2860_REG_INT_TX_AC0_DONE
<< i
))
4845 sc
->intr_pending_mask
&= ~(RT2860_REG_INT_TX_AC0_DONE
<< i
);
4847 rt2860_tx_eof(sc
, &sc
->tx_ring
[i
]);
4853 ifp
->if_drv_flags
&= ~IFF_DRV_OACTIVE
;
4855 intr_mask
= (RT2860_REG_INT_TX_MGMT_DONE
|
4856 RT2860_REG_INT_TX_HCCA_DONE
|
4857 RT2860_REG_INT_TX_AC3_DONE
|
4858 RT2860_REG_INT_TX_AC2_DONE
|
4859 RT2860_REG_INT_TX_AC1_DONE
|
4860 RT2860_REG_INT_TX_AC0_DONE
);
4862 RT2860_SOFTC_LOCK(sc
);
4864 rt2860_intr_enable(sc
, ~sc
->intr_pending_mask
&
4865 (sc
->intr_disable_mask
& intr_mask
));
4867 if (sc
->intr_pending_mask
& intr_mask
)
4869 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
4870 "%s: Tx done task: scheduling again\n",
4871 device_get_nameunit(sc
->dev
));
4873 taskqueue_enqueue(sc
->taskqueue
, &sc
->tx_done_task
);
4876 RT2860_SOFTC_UNLOCK(sc
);
4878 if (!IFQ_IS_EMPTY(&ic
->ic_mgtq
) || !IFQ_IS_EMPTY(&ifp
->if_snd
))
4883 * rt2860_fifo_sta_full_task
4885 static void rt2860_fifo_sta_full_task(void *context
, int pending
)
4887 struct rt2860_softc
*sc
;
4889 struct ieee80211com
*ic
;
4895 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATS
,
4896 "%s: FIFO statistic full task\n",
4897 device_get_nameunit(sc
->dev
));
4899 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
4902 sc
->intr_pending_mask
&= ~RT2860_REG_INT_FIFO_STA_FULL
;
4904 rt2860_drain_fifo_stats(sc
);
4906 RT2860_SOFTC_LOCK(sc
);
4908 if (sc
->intr_pending_mask
& RT2860_REG_INT_FIFO_STA_FULL
)
4910 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATS
,
4911 "%s: FIFO statistic full task: scheduling again\n",
4912 device_get_nameunit(sc
->dev
));
4914 taskqueue_enqueue(sc
->taskqueue
, &sc
->fifo_sta_full_task
);
4918 rt2860_intr_enable(sc
, RT2860_REG_INT_FIFO_STA_FULL
);
4921 RT2860_SOFTC_UNLOCK(sc
);
4923 if (!IFQ_IS_EMPTY(&ic
->ic_mgtq
) || !IFQ_IS_EMPTY(&ifp
->if_snd
))
4928 * rt2860_periodic_task
4930 static void rt2860_periodic_task(void *context
, int pending
)
4932 struct rt2860_softc
*sc
;
4934 struct ieee80211com
*ic
;
4940 RT2860_DPRINTF(sc
, RT2860_DEBUG_PERIODIC
,
4941 "%s: periodic task: round=%lu\n",
4942 device_get_nameunit(sc
->dev
), sc
->periodic_round
);
4944 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
4947 RT2860_SOFTC_LOCK(sc
);
4949 sc
->periodic_round
++;
4951 rt2860_update_stats(sc
);
4953 if ((sc
->periodic_round
% 10) == 0)
4955 rt2860_bbp_tuning(sc
);
4957 rt2860_update_raw_counters(sc
);
4959 rt2860_watchdog(sc
);
4961 if (ic
->ic_opmode
!= IEEE80211_M_MONITOR
&& ic
->ic_state
== IEEE80211_S_RUN
)
4963 if (ic
->ic_opmode
== IEEE80211_M_STA
)
4964 rt2860_amrr_update_iter_func(sc
, ic
->ic_bss
);
4966 ieee80211_iterate_nodes(&ic
->ic_sta
, rt2860_amrr_update_iter_func
, sc
);
4970 RT2860_SOFTC_UNLOCK(sc
);
4972 callout_reset(&sc
->periodic_ch
, hz
/ 10, rt2860_periodic
, sc
);
4978 static int rt2860_rx_eof(struct rt2860_softc
*sc
, int limit
)
4980 struct ieee80211com
*ic
;
4982 struct ieee80211_frame
*wh
;
4983 struct ieee80211_node
*ni
;
4984 struct rt2860_softc_node
*rni
;
4985 struct rt2860_softc_rx_radiotap_header
*tap
;
4986 struct rt2860_softc_rx_ring
*ring
;
4987 struct rt2860_rxdesc
*desc
;
4988 struct rt2860_softc_rx_data
*data
;
4989 struct rt2860_rxwi
*rxwi
;
4990 struct mbuf
*m
, *mnew
;
4991 bus_dma_segment_t segs
[1];
4992 bus_dmamap_t dma_map
;
4993 uint32_t index
, desc_flags
;
4994 uint8_t cipher_err
, rssi
, ant
, phymode
, bw
, shortgi
, mcs
, keyidx
;
4996 int error
, nsegs
, len
, ampdu
, amsdu
, nframes
, i
;
5000 ring
= &sc
->rx_ring
;
5006 index
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_RX_DRX_IDX
);
5007 if (ring
->cur
== index
)
5010 desc
= &ring
->desc
[ring
->cur
];
5011 desc_flags
= le32toh(desc
->flags
);
5012 data
= &ring
->data
[ring
->cur
];
5014 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
5015 BUS_DMASYNC_POSTREAD
);
5017 if (!(desc
->sdl0
& htole16(RT2860_RXDESC_SDL0_DDONE
)))
5022 mnew
= m_getjcl(M_DONTWAIT
, MT_DATA
, M_PKTHDR
, MJUMPAGESIZE
);
5025 sc
->rx_mbuf_alloc_errors
++;
5030 mnew
->m_len
= mnew
->m_pkthdr
.len
= MJUMPAGESIZE
;
5032 error
= bus_dmamap_load_mbuf_sg(ring
->data_dma_tag
, ring
->spare_dma_map
,
5033 mnew
, segs
, &nsegs
, BUS_DMA_NOWAIT
);
5038 sc
->rx_mbuf_dmamap_errors
++;
5044 KASSERT(nsegs
== 1, ("%s: too many DMA segments",
5045 device_get_name(sc
->dev
)));
5047 bus_dmamap_sync(ring
->data_dma_tag
, data
->dma_map
,
5048 BUS_DMASYNC_POSTREAD
);
5049 bus_dmamap_unload(ring
->data_dma_tag
, data
->dma_map
);
5051 dma_map
= data
->dma_map
;
5052 data
->dma_map
= ring
->spare_dma_map
;
5053 ring
->spare_dma_map
= dma_map
;
5055 bus_dmamap_sync(ring
->data_dma_tag
, data
->dma_map
,
5056 BUS_DMASYNC_PREREAD
);
5061 desc
->sdp0
= htole32(segs
[0].ds_addr
);
5063 /* get Rx wireless info */
5065 rxwi
= mtod(m
, struct rt2860_rxwi
*);
5066 len
= (le16toh(rxwi
->tid_size
) >> RT2860_RXWI_SIZE_SHIFT
) &
5067 RT2860_RXWI_SIZE_MASK
;
5069 /* check for L2 padding between IEEE 802.11 frame header and body */
5071 if (desc_flags
& RT2860_RXDESC_FLAGS_L2PAD
)
5073 RT2860_DPRINTF(sc
, RT2860_DEBUG_RX
,
5074 "%s: L2 padding: len=%d\n",
5075 device_get_nameunit(sc
->dev
), len
);
5080 m
->m_pkthdr
.rcvif
= ifp
;
5081 m
->m_data
= (caddr_t
) (rxwi
+ 1);
5082 m
->m_pkthdr
.len
= m
->m_len
= len
;
5084 /* check for crc errors */
5086 if (desc_flags
& RT2860_RXDESC_FLAGS_CRC_ERR
)
5088 RT2860_DPRINTF(sc
, RT2860_DEBUG_RX
,
5089 "%s: rxdesc: crc error\n",
5090 device_get_nameunit(sc
->dev
));
5094 if (!(ifp
->if_flags
& IFF_PROMISC
))
5101 wh
= (struct ieee80211_frame
*) (rxwi
+ 1);
5103 /* check for cipher errors */
5105 if (desc_flags
& RT2860_RXDESC_FLAGS_DECRYPTED
)
5107 cipher_err
= ((desc_flags
>> RT2860_RXDESC_FLAGS_CIPHER_ERR_SHIFT
) &
5108 RT2860_RXDESC_FLAGS_CIPHER_ERR_MASK
);
5109 if (cipher_err
== RT2860_RXDESC_FLAGS_CIPHER_ERR_NONE
)
5111 if (wh
->i_fc
[1] & IEEE80211_FC1_WEP
)
5112 wh
->i_fc
[1] &= ~IEEE80211_FC1_WEP
;
5114 m
->m_flags
|= M_WEP
;
5116 sc
->rx_cipher_no_errors
++;
5120 RT2860_DPRINTF(sc
, RT2860_DEBUG_RX
,
5121 "%s: rxdesc: cipher error=0x%02x\n",
5122 device_get_nameunit(sc
->dev
), cipher_err
);
5124 if (cipher_err
== RT2860_RXDESC_FLAGS_CIPHER_ERR_ICV
)
5125 sc
->rx_cipher_icv_errors
++;
5126 else if (cipher_err
== RT2860_RXDESC_FLAGS_CIPHER_ERR_MIC
)
5127 sc
->rx_cipher_mic_errors
++;
5128 else if (cipher_err
== RT2860_RXDESC_FLAGS_CIPHER_ERR_INVALID_KEY
)
5129 sc
->rx_cipher_invalid_key_errors
++;
5131 if ((cipher_err
== RT2860_RXDESC_FLAGS_CIPHER_ERR_MIC
) &&
5132 (desc_flags
& RT2860_RXDESC_FLAGS_MYBSS
))
5134 keyidx
= (rxwi
->udf_bssidx_keyidx
>> RT2860_RXWI_KEYIDX_SHIFT
) &
5135 RT2860_RXWI_KEYIDX_MASK
;
5137 ieee80211_notify_michael_failure(ic
, wh
, keyidx
);
5142 if (!(ifp
->if_flags
& IFF_PROMISC
))
5151 if (wh
->i_fc
[1] & IEEE80211_FC1_WEP
)
5153 RT2860_DPRINTF(sc
, RT2860_DEBUG_RX
,
5154 "%s: rxdesc: not decrypted but protected flag set\n",
5155 device_get_nameunit(sc
->dev
));
5159 if (!(ifp
->if_flags
& IFF_PROMISC
))
5167 /* check for A-MPDU */
5169 if (desc_flags
& RT2860_RXDESC_FLAGS_AMPDU
)
5171 m
->m_flags
|= M_AMPDU
;
5182 /* check for A-MSDU */
5184 if (desc_flags
& RT2860_RXDESC_FLAGS_AMSDU
)
5195 ant
= rt2860_maxrssi_rxpath(sc
, rxwi
);
5196 rssi
= rxwi
->rssi
[ant
];
5197 rssi_dbm
= rt2860_rssi2dbm(sc
, rssi
, ant
);
5198 phymode
= ((rxwi
->phymode_stbc_shortgi
>> RT2860_RXWI_PHYMODE_SHIFT
) &
5199 RT2860_RXWI_PHYMODE_MASK
);
5200 bw
= ((rxwi
->bw_mcs
>> RT2860_RXWI_BW_SHIFT
) & RT2860_RXWI_BW_MASK
);
5201 shortgi
= ((rxwi
->phymode_stbc_shortgi
>> RT2860_RXWI_SHORTGI_SHIFT
) &
5202 RT2860_RXWI_SHORTGI_MASK
);
5203 mcs
= ((rxwi
->bw_mcs
>> RT2860_RXWI_MCS_SHIFT
) & RT2860_RXWI_MCS_MASK
);
5205 if (bpf_peers_present(sc
->drvbpf
))
5209 tap
->flags
= IEEE80211_RADIOTAP_F_DATAPAD
;
5210 tap
->dbm_antsignal
= rssi_dbm
;
5211 tap
->dbm_antnoise
= RT2860_NOISE_FLOOR
;
5213 tap
->antsignal
= rssi
;
5214 tap
->chan_flags
= htole32(ic
->ic_curchan
->ic_flags
);
5215 tap
->chan_freq
= htole16(ic
->ic_curchan
->ic_freq
);
5216 tap
->chan_ieee
= ic
->ic_curchan
->ic_ieee
;
5217 tap
->chan_maxpow
= 0;
5219 if (phymode
== RT2860_TXWI_PHYMODE_HT_MIXED
|| phymode
== RT2860_TXWI_PHYMODE_HT_GF
)
5220 tap
->rate
= mcs
| IEEE80211_RATE_MCS
;
5222 tap
->rate
= rt2860_rxrate(rxwi
);
5224 if (desc_flags
& RT2860_RXDESC_FLAGS_CRC_ERR
)
5225 tap
->flags
|= IEEE80211_RADIOTAP_F_BADFCS
;
5227 if (desc_flags
& RT2860_RXDESC_FLAGS_FRAG
)
5228 tap
->flags
|= IEEE80211_RADIOTAP_F_FRAG
;
5230 if (rxwi
->bw_mcs
& RT2860_RXWI_MCS_SHOTPRE
)
5231 tap
->flags
|= IEEE80211_RADIOTAP_F_SHORTPRE
;
5233 if ((desc_flags
& RT2860_RXDESC_FLAGS_DECRYPTED
) ||
5234 (wh
->i_fc
[1] & IEEE80211_FC1_WEP
))
5235 tap
->flags
|= IEEE80211_RADIOTAP_F_WEP
;
5238 tap
->flags
|= IEEE80211_RADIOTAP_F_SHORTGI
;
5240 bpf_mtap2(sc
->drvbpf
, tap
, sc
->rxtap_len
, m
);
5243 RT2860_DPRINTF(sc
, RT2860_DEBUG_RX
,
5244 "%s: received frame: len=%d, phymode=%d, bw=%d, shortgi=%d, mcs=%d, "
5245 "ant=%d, rssi=%d/%d/%d, snr=%d/%d, wcid=0x%02x, ampdu=%d, amsdu=%d\n",
5246 device_get_nameunit(sc
->dev
),
5247 len
, phymode
, bw
, shortgi
, mcs
,
5248 ant
, rxwi
->rssi
[0], rxwi
->rssi
[1], rxwi
->rssi
[2],
5249 rxwi
->snr
[0], rxwi
->snr
[1],
5250 rxwi
->wcid
, ampdu
, amsdu
);
5252 ni
= ieee80211_find_rxnode(ic
, (struct ieee80211_frame_min
*) wh
);
5256 rni
= (struct rt2860_softc_node
*) ni
;
5258 for (i
= 0; i
< RT2860_SOFTC_RSSI_COUNT
; i
++)
5260 rni
->last_rssi
[i
] = rxwi
->rssi
[i
];
5261 rni
->last_rssi_dbm
[i
] = rt2860_rssi2dbm(sc
, rxwi
->rssi
[i
], i
);
5265 ieee80211_input(ic
, m
, ni
, rssi_dbm
, RT2860_NOISE_FLOOR
, 0);
5267 ieee80211_free_node(ni
);
5271 desc
->sdl0
&= ~htole16(RT2860_RXDESC_SDL0_DDONE
);
5273 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
5274 BUS_DMASYNC_PREREAD
| BUS_DMASYNC_PREWRITE
);
5276 ring
->cur
= (ring
->cur
+ 1) % RT2860_SOFTC_RX_RING_DATA_COUNT
;
5282 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_CALC_IDX
,
5283 RT2860_SOFTC_RX_RING_DATA_COUNT
- 1);
5285 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_RX_CALC_IDX
,
5288 RT2860_DPRINTF(sc
, RT2860_DEBUG_RX
,
5289 "%s: Rx eof: nframes=%d\n",
5290 device_get_nameunit(sc
->dev
), nframes
);
5292 sc
->rx_packets
+= nframes
;
5294 return (limit
== 0);
5300 static void rt2860_tx_eof(struct rt2860_softc
*sc
,
5301 struct rt2860_softc_tx_ring
*ring
)
5304 struct rt2860_txdesc
*desc
;
5305 struct rt2860_softc_tx_data
*data
;
5307 int ndescs
, nframes
;
5316 index
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_TX_DTX_IDX(ring
->qid
));
5317 if (ring
->desc_next
== index
)
5322 rt2860_drain_fifo_stats(sc
);
5324 desc
= &ring
->desc
[ring
->desc_next
];
5326 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
5327 BUS_DMASYNC_POSTREAD
);
5329 if (desc
->sdl0
& htole16(RT2860_TXDESC_SDL0_LASTSEG
) ||
5330 desc
->sdl1
& htole16(RT2860_TXDESC_SDL1_LASTSEG
))
5334 data
= &ring
->data
[ring
->data_next
];
5336 if (data
->m
->m_flags
& M_TXCB
)
5337 ieee80211_process_callback(data
->ni
, data
->m
, 0);
5339 bus_dmamap_sync(ring
->data_dma_tag
, data
->dma_map
,
5340 BUS_DMASYNC_POSTWRITE
);
5341 bus_dmamap_unload(ring
->data_dma_tag
, data
->dma_map
);
5345 ieee80211_free_node(data
->ni
);
5352 RT2860_SOFTC_TX_RING_LOCK(ring
);
5354 ring
->data_queued
--;
5355 ring
->data_next
= (ring
->data_next
+ 1) % RT2860_SOFTC_TX_RING_DATA_COUNT
;
5357 RT2860_SOFTC_TX_RING_UNLOCK(ring
);
5360 desc
->sdl0
&= ~htole16(RT2860_TXDESC_SDL0_DDONE
);
5362 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
5363 BUS_DMASYNC_PREREAD
| BUS_DMASYNC_PREWRITE
);
5365 RT2860_SOFTC_TX_RING_LOCK(ring
);
5367 ring
->desc_queued
--;
5368 ring
->desc_next
= (ring
->desc_next
+ 1) % RT2860_SOFTC_TX_RING_DESC_COUNT
;
5370 RT2860_SOFTC_TX_RING_UNLOCK(ring
);
5373 RT2860_DPRINTF(sc
, RT2860_DEBUG_TX
,
5374 "%s: Tx eof: qid=%d, ndescs=%d, nframes=%d\n",
5375 device_get_nameunit(sc
->dev
), ring
->qid
, ndescs
, nframes
);
5379 * rt2860_update_stats
5381 static void rt2860_update_stats(struct rt2860_softc
*sc
)
5385 int beacons
, noretryok
, retryok
, failed
, underflows
, zerolen
;
5389 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATS
,
5390 "%s: update statistic\n",
5391 device_get_nameunit(sc
->dev
));
5393 rt2860_drain_fifo_stats(sc
);
5395 /* read and clear Tx statistic registers */
5397 rt2860_io_mac_read_multi(sc
, RT2860_REG_TX_STA_CNT0
,
5398 stacnt
, sizeof(stacnt
));
5400 stacnt
[0] = le32toh(stacnt
[0]);
5401 stacnt
[1] = le32toh(stacnt
[1]);
5402 stacnt
[2] = le32toh(stacnt
[2]);
5404 beacons
= stacnt
[0] >> 16;
5405 noretryok
= stacnt
[1] & 0xffff;
5406 retryok
= stacnt
[1] >> 16;
5407 failed
= stacnt
[0] & 0xffff;
5408 underflows
= stacnt
[2] >> 16;
5409 zerolen
= stacnt
[2] & 0xffff;
5411 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATS
,
5412 "%s: update statistic: beacons=%d, noretryok=%d, retryok=%d, failed=%d, underflows=%d, zerolen=%d\n",
5413 device_get_nameunit(sc
->dev
),
5414 beacons
, noretryok
, retryok
, failed
, underflows
, zerolen
);
5416 ifp
->if_oerrors
+= failed
;
5418 sc
->tx_beacons
+= beacons
;
5419 sc
->tx_noretryok
+= noretryok
;
5420 sc
->tx_retryok
+= retryok
;
5421 sc
->tx_failed
+= failed
;
5422 sc
->tx_underflows
+= underflows
;
5423 sc
->tx_zerolen
+= zerolen
;
5429 static void rt2860_bbp_tuning(struct rt2860_softc
*sc
)
5431 struct ieee80211com
*ic
;
5432 struct ieee80211_node
*ni
;
5434 int8_t rssi
, old
, new;
5436 /* RT2860C does not support BBP tuning */
5438 if (sc
->mac_rev
== 0x28600100)
5443 if ((ic
->ic_flags
& IEEE80211_F_SCAN
) ||
5444 ic
->ic_opmode
!= IEEE80211_M_STA
|| ic
->ic_state
!= IEEE80211_S_RUN
)
5449 chan
= ieee80211_chan2ieee(ic
, ni
->ni_chan
);
5453 else if (chan
<= 64)
5455 else if (chan
<= 128)
5460 rssi
= ieee80211_getrssi(ic
);
5462 if (IEEE80211_IS_CHAN_2GHZ(ni
->ni_chan
))
5464 new = 0x2e + sc
->lna_gain
[group
];
5468 if (!IEEE80211_IS_CHAN_HT40(ni
->ni_chan
))
5469 new = 0x32 + sc
->lna_gain
[group
] * 5 / 3;
5471 new = 0x3a + sc
->lna_gain
[group
] * 5 / 3;
5474 /* Tune if absolute average RSSI is greater than -80 */
5479 old
= rt2860_io_bbp_read(sc
, 66);
5482 rt2860_io_bbp_write(sc
, 66, new);
5488 static void rt2860_watchdog(struct rt2860_softc
*sc
)
5493 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_PBF_TXRXQ_PCNT
);
5495 RT2860_DPRINTF(sc
, RT2860_DEBUG_WATCHDOG
,
5496 "%s: watchdog: TXRXQ_PCNT=0x%08x\n",
5497 device_get_nameunit(sc
->dev
), tmp
);
5499 if (((tmp
>> RT2860_REG_TX0Q_PCNT_SHIFT
) & RT2860_REG_TX0Q_PCNT_MASK
) != 0)
5501 sc
->tx_queue_not_empty
[0]++;
5503 rt2860_io_mac_write(sc
, RT2860_REG_PBF_CFG
, 0xf40012);
5505 for (ntries
= 0; ntries
< 10; ntries
++)
5507 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_PBF_TXRXQ_PCNT
);
5508 if (((tmp
>> RT2860_REG_TX0Q_PCNT_SHIFT
) & RT2860_REG_TX0Q_PCNT_MASK
) == 0)
5514 rt2860_io_mac_write(sc
, RT2860_REG_PBF_CFG
, 0xf40006);
5517 if (((tmp
>> RT2860_REG_TX1Q_PCNT_SHIFT
) & RT2860_REG_TX1Q_PCNT_MASK
) != 0)
5519 sc
->tx_queue_not_empty
[1]++;
5521 rt2860_io_mac_write(sc
, RT2860_REG_PBF_CFG
, 0xf4000a);
5523 for (ntries
= 0; ntries
< 10; ntries
++)
5525 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_PBF_TXRXQ_PCNT
);
5526 if (((tmp
>> RT2860_REG_TX1Q_PCNT_SHIFT
) & RT2860_REG_TX1Q_PCNT_MASK
) == 0)
5532 rt2860_io_mac_write(sc
, RT2860_REG_PBF_CFG
, 0xf40006);
5537 * rt2860_drain_fifo_stats
5539 static void rt2860_drain_fifo_stats(struct rt2860_softc
*sc
)
5543 uint8_t wcid
, mcs
, pid
;
5544 int ok
, agg
, retrycnt
;
5546 ifp
= sc
->ic
.ic_ifp
;
5548 /* drain Tx status FIFO (maxsize = 16) */
5550 while ((stats
= rt2860_io_mac_read(sc
, RT2860_REG_TX_STA_FIFO
)) &
5551 RT2860_REG_TX_STA_FIFO_VALID
)
5553 wcid
= (stats
>> RT2860_REG_TX_STA_FIFO_WCID_SHIFT
) &
5554 RT2860_REG_TX_STA_FIFO_WCID_MASK
;
5556 /* if no ACK was requested, no feedback is available */
5558 if (!(stats
& RT2860_REG_TX_STA_FIFO_ACK_REQ
) || wcid
== RT2860_WCID_RESERVED
)
5561 /* update AMRR statistic */
5563 ok
= (stats
& RT2860_REG_TX_STA_FIFO_TX_OK
) ? 1 : 0;
5564 agg
= (stats
& RT2860_REG_TX_STA_FIFO_AGG
) ? 1 : 0;
5565 mcs
= (stats
>> RT2860_REG_TX_STA_FIFO_MCS_SHIFT
) &
5566 RT2860_REG_TX_STA_FIFO_MCS_MASK
;
5567 pid
= (stats
>> RT2860_REG_TX_STA_FIFO_PID_SHIFT
) &
5568 RT2860_REG_TX_STA_FIFO_PID_MASK
;
5569 retrycnt
= pid
- mcs
;
5571 RT2860_DPRINTF(sc
, RT2860_DEBUG_STATS
,
5572 "%s: FIFO statistic: wcid=0x%02x, ok=%d, agg=%d, mcs=0x%02x, pid=0x%02x, retrycnt=%d\n",
5573 device_get_nameunit(sc
->dev
),
5574 wcid
, ok
, agg
, mcs
, pid
, retrycnt
);
5576 rt2860_amrr_tx_complete(&sc
->amrr_node
[wcid
], ok
, retrycnt
);
5584 * rt2860_update_raw_counters
5586 static void rt2860_update_raw_counters(struct rt2860_softc
*sc
)
5590 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_AGG_CNT
);
5592 sc
->tx_nonagg
+= tmp
& 0xffff;
5593 sc
->tx_agg
+= tmp
>> 16;
5595 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_AGG_CNT0
);
5597 sc
->tx_ampdu
+= (tmp
& 0xffff) / 1 + (tmp
>> 16) / 2;
5599 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_AGG_CNT1
);
5601 sc
->tx_ampdu
+= (tmp
& 0xffff) / 3 + (tmp
>> 16) / 4;
5603 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_AGG_CNT2
);
5605 sc
->tx_ampdu
+= (tmp
& 0xffff) / 5 + (tmp
>> 16) / 6;
5607 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_AGG_CNT3
);
5609 sc
->tx_ampdu
+= (tmp
& 0xffff) / 7 + (tmp
>> 16) / 8;
5611 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_AGG_CNT4
);
5613 sc
->tx_ampdu
+= (tmp
& 0xffff) / 9 + (tmp
>> 16) / 10;
5615 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_AGG_CNT5
);
5617 sc
->tx_ampdu
+= (tmp
& 0xffff) / 11 + (tmp
>> 16) / 12;
5619 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_AGG_CNT6
);
5621 sc
->tx_ampdu
+= (tmp
& 0xffff) / 13 + (tmp
>> 16) / 14;
5623 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TX_AGG_CNT7
);
5625 sc
->tx_ampdu
+= (tmp
& 0xffff) / 15 + (tmp
>> 16) / 16;
5627 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_RX_STA_CNT0
);
5629 sc
->rx_crc_errors
+= tmp
& 0xffff;
5630 sc
->rx_phy_errors
+= tmp
>> 16;
5632 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_RX_STA_CNT1
);
5634 sc
->rx_false_ccas
+= tmp
& 0xffff;
5635 sc
->rx_plcp_errors
+= tmp
>> 16;
5637 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_RX_STA_CNT2
);
5639 sc
->rx_dup_packets
+= tmp
& 0xffff;
5640 sc
->rx_fifo_overflows
+= tmp
>> 16;
5642 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_TXRX_MPDU_DEN_CNT
);
5644 sc
->tx_mpdu_zero_density
+= tmp
& 0xffff;
5645 sc
->rx_mpdu_zero_density
+= tmp
>> 16;
5649 * rt2860_intr_enable
5651 static void rt2860_intr_enable(struct rt2860_softc
*sc
, uint32_t intr_mask
)
5655 sc
->intr_disable_mask
&= ~intr_mask
;
5657 tmp
= sc
->intr_enable_mask
& ~sc
->intr_disable_mask
;
5659 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_INT_MASK
, tmp
);
5663 * rt2860_intr_disable
5665 static void rt2860_intr_disable(struct rt2860_softc
*sc
, uint32_t intr_mask
)
5669 sc
->intr_disable_mask
|= intr_mask
;
5671 tmp
= sc
->intr_enable_mask
& ~sc
->intr_disable_mask
;
5673 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_INT_MASK
, tmp
);
5677 * rt2860_txrx_enable
5679 static int rt2860_txrx_enable(struct rt2860_softc
*sc
)
5681 struct ieee80211com
*ic
;
5689 /* enable Tx/Rx DMA engine */
5691 rt2860_io_mac_write(sc
, RT2860_REG_SYS_CTRL
, RT2860_REG_TX_ENABLE
);
5693 for (ntries
= 0; ntries
< 200; ntries
++)
5695 tmp
= rt2860_io_mac_read(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
);
5696 if (!(tmp
& (RT2860_REG_TX_DMA_BUSY
| RT2860_REG_RX_DMA_BUSY
)))
5704 printf("%s: timeout waiting for DMA engine\n",
5705 device_get_nameunit(sc
->dev
));
5711 tmp
|= RT2860_REG_TX_WB_DDONE
|
5712 RT2860_REG_RX_DMA_ENABLE
|
5713 RT2860_REG_TX_DMA_ENABLE
|
5714 (RT2860_REG_WPDMA_BT_SIZE64
<< RT2860_REG_WPDMA_BT_SIZE_SHIFT
);
5716 rt2860_io_mac_write(sc
, RT2860_REG_SCHDMA_WPDMA_GLO_CFG
, tmp
);
5720 tmp
= RT2860_REG_RX_FILTER_DROP_CRC_ERR
|
5721 RT2860_REG_RX_FILTER_DROP_PHY_ERR
;
5723 if (ic
->ic_opmode
!= IEEE80211_M_MONITOR
)
5725 tmp
|= RT2860_REG_RX_FILTER_DROP_DUPL
|
5726 RT2860_REG_RX_FILTER_DROP_CTS
|
5727 RT2860_REG_RX_FILTER_DROP_BA
|
5728 RT2860_REG_RX_FILTER_DROP_ACK
|
5729 RT2860_REG_RX_FILTER_DROP_VER_ERR
|
5730 RT2860_REG_RX_FILTER_DROP_CTRL_RSV
|
5731 RT2860_REG_RX_FILTER_DROP_CFACK
|
5732 RT2860_REG_RX_FILTER_DROP_CFEND
;
5734 if (ic
->ic_opmode
== IEEE80211_M_STA
)
5735 tmp
|= RT2860_REG_RX_FILTER_DROP_RTS
|
5736 RT2860_REG_RX_FILTER_DROP_PSPOLL
;
5738 if (!(ifp
->if_flags
& IFF_PROMISC
))
5739 tmp
|= RT2860_REG_RX_FILTER_DROP_UC_NOME
;
5742 rt2860_io_mac_write(sc
, RT2860_REG_RX_FILTER_CFG
, tmp
);
5744 rt2860_io_mac_write(sc
, RT2860_REG_SYS_CTRL
,
5745 RT2860_REG_RX_ENABLE
| RT2860_REG_TX_ENABLE
);
5751 * rt2860_alloc_rx_ring
5753 static int rt2860_alloc_rx_ring(struct rt2860_softc
*sc
,
5754 struct rt2860_softc_rx_ring
*ring
)
5756 struct rt2860_rxdesc
*desc
;
5757 struct rt2860_softc_rx_data
*data
;
5758 bus_dma_segment_t segs
[1];
5759 int i
, nsegs
, error
;
5761 error
= bus_dma_tag_create(bus_get_dma_tag(sc
->dev
), PAGE_SIZE
, 0,
5762 BUS_SPACE_MAXADDR_32BIT
, BUS_SPACE_MAXADDR
, NULL
, NULL
,
5763 RT2860_SOFTC_RX_RING_DATA_COUNT
* sizeof(struct rt2860_rxdesc
), 1,
5764 RT2860_SOFTC_RX_RING_DATA_COUNT
* sizeof(struct rt2860_rxdesc
),
5765 0, NULL
, NULL
, &ring
->desc_dma_tag
);
5768 printf("%s: could not create Rx desc DMA tag\n",
5769 device_get_nameunit(sc
->dev
));
5773 error
= bus_dmamem_alloc(ring
->desc_dma_tag
, (void **) &ring
->desc
,
5774 BUS_DMA_NOWAIT
| BUS_DMA_ZERO
, &ring
->desc_dma_map
);
5777 printf("%s: could not allocate Rx desc DMA memory\n",
5778 device_get_nameunit(sc
->dev
));
5782 error
= bus_dmamap_load(ring
->desc_dma_tag
, ring
->desc_dma_map
,
5784 RT2860_SOFTC_RX_RING_DATA_COUNT
* sizeof(struct rt2860_rxdesc
),
5785 rt2860_dma_map_addr
, &ring
->desc_phys_addr
, 0);
5788 printf("%s: could not load Rx desc DMA map\n",
5789 device_get_nameunit(sc
->dev
));
5793 error
= bus_dma_tag_create(bus_get_dma_tag(sc
->dev
), PAGE_SIZE
, 0,
5794 BUS_SPACE_MAXADDR_32BIT
, BUS_SPACE_MAXADDR
, NULL
, NULL
,
5795 MJUMPAGESIZE
, 1, MJUMPAGESIZE
, 0, NULL
, NULL
,
5796 &ring
->data_dma_tag
);
5799 printf("%s: could not create Rx data DMA tag\n",
5800 device_get_nameunit(sc
->dev
));
5804 for (i
= 0; i
< RT2860_SOFTC_RX_RING_DATA_COUNT
; i
++)
5806 desc
= &ring
->desc
[i
];
5807 data
= &ring
->data
[i
];
5809 error
= bus_dmamap_create(ring
->data_dma_tag
, 0, &data
->dma_map
);
5812 printf("%s: could not create Rx data DMA map\n",
5813 device_get_nameunit(sc
->dev
));
5817 data
->m
= m_getjcl(M_DONTWAIT
, MT_DATA
, M_PKTHDR
, MJUMPAGESIZE
);
5818 if (data
->m
== NULL
)
5820 printf("%s: could not allocate Rx mbuf\n",
5821 device_get_nameunit(sc
->dev
));
5826 data
->m
->m_len
= data
->m
->m_pkthdr
.len
= MJUMPAGESIZE
;
5828 error
= bus_dmamap_load_mbuf_sg(ring
->data_dma_tag
, data
->dma_map
,
5829 data
->m
, segs
, &nsegs
, BUS_DMA_NOWAIT
);
5832 printf("%s: could not load Rx mbuf DMA map\n",
5833 device_get_nameunit(sc
->dev
));
5837 KASSERT(nsegs
== 1, ("%s: too many DMA segments",
5838 device_get_name(sc
->dev
)));
5840 desc
->sdp0
= htole32(segs
[0].ds_addr
);
5841 desc
->sdl0
= htole16(MJUMPAGESIZE
);
5844 error
= bus_dmamap_create(ring
->data_dma_tag
, 0, &ring
->spare_dma_map
);
5847 printf("%s: could not create Rx spare DMA map\n",
5848 device_get_nameunit(sc
->dev
));
5852 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
5853 BUS_DMASYNC_PREWRITE
);
5859 rt2860_free_rx_ring(sc
, ring
);
5865 * rt2860_reset_rx_ring
5867 static void rt2860_reset_rx_ring(struct rt2860_softc
*sc
,
5868 struct rt2860_softc_rx_ring
*ring
)
5870 struct rt2860_rxdesc
*desc
;
5873 for (i
= 0; i
< RT2860_SOFTC_RX_RING_DATA_COUNT
; i
++)
5875 desc
= &ring
->desc
[i
];
5877 desc
->sdl0
&= ~htole16(RT2860_RXDESC_SDL0_DDONE
);
5880 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
5881 BUS_DMASYNC_PREWRITE
);
5887 * rt2860_free_rx_ring
5889 static void rt2860_free_rx_ring(struct rt2860_softc
*sc
,
5890 struct rt2860_softc_rx_ring
*ring
)
5892 struct rt2860_softc_rx_data
*data
;
5895 if (ring
->desc
!= NULL
)
5897 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
5898 BUS_DMASYNC_POSTWRITE
);
5899 bus_dmamap_unload(ring
->desc_dma_tag
, ring
->desc_dma_map
);
5900 bus_dmamem_free(ring
->desc_dma_tag
, ring
->desc
,
5901 ring
->desc_dma_map
);
5904 if (ring
->desc_dma_tag
!= NULL
)
5905 bus_dma_tag_destroy(ring
->desc_dma_tag
);
5907 for (i
= 0; i
< RT2860_SOFTC_RX_RING_DATA_COUNT
; i
++)
5909 data
= &ring
->data
[i
];
5911 if (data
->m
!= NULL
)
5913 bus_dmamap_sync(ring
->data_dma_tag
, data
->dma_map
,
5914 BUS_DMASYNC_POSTREAD
);
5915 bus_dmamap_unload(ring
->data_dma_tag
, data
->dma_map
);
5919 if (data
->dma_map
!= NULL
)
5920 bus_dmamap_destroy(ring
->data_dma_tag
, data
->dma_map
);
5923 if (ring
->spare_dma_map
!= NULL
)
5924 bus_dmamap_destroy(ring
->data_dma_tag
, ring
->spare_dma_map
);
5926 if (ring
->data_dma_tag
!= NULL
)
5927 bus_dma_tag_destroy(ring
->data_dma_tag
);
5931 * rt2860_alloc_tx_ring
5933 static int rt2860_alloc_tx_ring(struct rt2860_softc
*sc
,
5934 struct rt2860_softc_tx_ring
*ring
, int qid
)
5936 struct rt2860_softc_tx_data
*data
;
5939 mtx_init(&ring
->lock
, device_get_nameunit(sc
->dev
), NULL
, MTX_DEF
);
5941 error
= bus_dma_tag_create(bus_get_dma_tag(sc
->dev
), PAGE_SIZE
, 0,
5942 BUS_SPACE_MAXADDR_32BIT
, BUS_SPACE_MAXADDR
, NULL
, NULL
,
5943 RT2860_SOFTC_TX_RING_DESC_COUNT
* sizeof(struct rt2860_txdesc
), 1,
5944 RT2860_SOFTC_TX_RING_DESC_COUNT
* sizeof(struct rt2860_txdesc
),
5945 0, NULL
, NULL
, &ring
->desc_dma_tag
);
5948 printf("%s: could not create Tx desc DMA tag\n",
5949 device_get_nameunit(sc
->dev
));
5953 error
= bus_dmamem_alloc(ring
->desc_dma_tag
, (void **) &ring
->desc
,
5954 BUS_DMA_NOWAIT
| BUS_DMA_ZERO
, &ring
->desc_dma_map
);
5957 printf("%s: could not allocate Tx desc DMA memory\n",
5958 device_get_nameunit(sc
->dev
));
5962 error
= bus_dmamap_load(ring
->desc_dma_tag
, ring
->desc_dma_map
,
5964 RT2860_SOFTC_TX_RING_DESC_COUNT
* sizeof(struct rt2860_txdesc
),
5965 rt2860_dma_map_addr
, &ring
->desc_phys_addr
, 0);
5968 printf("%s: could not load Tx desc DMA map\n",
5969 device_get_nameunit(sc
->dev
));
5973 ring
->desc_queued
= 0;
5975 ring
->desc_next
= 0;
5977 error
= bus_dma_tag_create(bus_get_dma_tag(sc
->dev
), PAGE_SIZE
, 0,
5978 BUS_SPACE_MAXADDR_32BIT
, BUS_SPACE_MAXADDR
, NULL
, NULL
,
5979 RT2860_SOFTC_TX_RING_DATA_COUNT
* RT2860_TX_DATA_SEG0_SIZE
, 1,
5980 RT2860_SOFTC_TX_RING_DATA_COUNT
* RT2860_TX_DATA_SEG0_SIZE
,
5981 0, NULL
, NULL
, &ring
->seg0_dma_tag
);
5984 printf("%s: could not create Tx seg0 DMA tag\n",
5985 device_get_nameunit(sc
->dev
));
5989 error
= bus_dmamem_alloc(ring
->seg0_dma_tag
, (void **) &ring
->seg0
,
5990 BUS_DMA_NOWAIT
| BUS_DMA_ZERO
, &ring
->seg0_dma_map
);
5993 printf("%s: could not allocate Tx seg0 DMA memory\n",
5994 device_get_nameunit(sc
->dev
));
5998 error
= bus_dmamap_load(ring
->seg0_dma_tag
, ring
->seg0_dma_map
,
6000 RT2860_SOFTC_TX_RING_DATA_COUNT
* RT2860_TX_DATA_SEG0_SIZE
,
6001 rt2860_dma_map_addr
, &ring
->seg0_phys_addr
, 0);
6004 printf("%s: could not load Tx seg0 DMA map\n",
6005 device_get_nameunit(sc
->dev
));
6009 error
= bus_dma_tag_create(bus_get_dma_tag(sc
->dev
), PAGE_SIZE
, 0,
6010 BUS_SPACE_MAXADDR_32BIT
, BUS_SPACE_MAXADDR
, NULL
, NULL
,
6011 MJUMPAGESIZE
, RT2860_SOFTC_MAX_SCATTER
, MJUMPAGESIZE
, 0, NULL
, NULL
,
6012 &ring
->data_dma_tag
);
6015 printf("%s: could not create Tx data DMA tag\n",
6016 device_get_nameunit(sc
->dev
));
6020 for (i
= 0; i
< RT2860_SOFTC_TX_RING_DATA_COUNT
; i
++)
6022 data
= &ring
->data
[i
];
6024 error
= bus_dmamap_create(ring
->data_dma_tag
, 0, &data
->dma_map
);
6027 printf("%s: could not create Tx data DMA map\n",
6028 device_get_nameunit(sc
->dev
));
6033 ring
->data_queued
= 0;
6035 ring
->data_next
= 0;
6043 rt2860_free_tx_ring(sc
, ring
);
6049 * rt2860_reset_tx_ring
6051 static void rt2860_reset_tx_ring(struct rt2860_softc
*sc
,
6052 struct rt2860_softc_tx_ring
*ring
)
6054 struct rt2860_softc_tx_data
*data
;
6055 struct rt2860_txdesc
*desc
;
6058 for (i
= 0; i
< RT2860_SOFTC_TX_RING_DESC_COUNT
; i
++)
6060 desc
= &ring
->desc
[i
];
6066 ring
->desc_queued
= 0;
6068 ring
->desc_next
= 0;
6070 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
6071 BUS_DMASYNC_PREWRITE
);
6073 bus_dmamap_sync(ring
->seg0_dma_tag
, ring
->seg0_dma_map
,
6074 BUS_DMASYNC_PREWRITE
);
6076 for (i
= 0; i
< RT2860_SOFTC_TX_RING_DATA_COUNT
; i
++)
6078 data
= &ring
->data
[i
];
6080 if (data
->m
!= NULL
)
6082 bus_dmamap_sync(ring
->data_dma_tag
, data
->dma_map
,
6083 BUS_DMASYNC_POSTWRITE
);
6084 bus_dmamap_unload(ring
->data_dma_tag
, data
->dma_map
);
6089 if (data
->ni
!= NULL
)
6091 ieee80211_free_node(data
->ni
);
6096 ring
->data_queued
= 0;
6098 ring
->data_next
= 0;
6102 * rt2860_free_tx_ring
6104 static void rt2860_free_tx_ring(struct rt2860_softc
*sc
,
6105 struct rt2860_softc_tx_ring
*ring
)
6107 struct rt2860_softc_tx_data
*data
;
6110 if (ring
->desc
!= NULL
)
6112 bus_dmamap_sync(ring
->desc_dma_tag
, ring
->desc_dma_map
,
6113 BUS_DMASYNC_POSTWRITE
);
6114 bus_dmamap_unload(ring
->desc_dma_tag
, ring
->desc_dma_map
);
6115 bus_dmamem_free(ring
->desc_dma_tag
, ring
->desc
,
6116 ring
->desc_dma_map
);
6119 if (ring
->desc_dma_tag
!= NULL
)
6120 bus_dma_tag_destroy(ring
->desc_dma_tag
);
6122 if (ring
->seg0
!= NULL
)
6124 bus_dmamap_sync(ring
->seg0_dma_tag
, ring
->seg0_dma_map
,
6125 BUS_DMASYNC_POSTWRITE
);
6126 bus_dmamap_unload(ring
->seg0_dma_tag
, ring
->seg0_dma_map
);
6127 bus_dmamem_free(ring
->seg0_dma_tag
, ring
->seg0
,
6128 ring
->seg0_dma_map
);
6131 if (ring
->seg0_dma_tag
!= NULL
)
6132 bus_dma_tag_destroy(ring
->seg0_dma_tag
);
6134 for (i
= 0; i
< RT2860_SOFTC_TX_RING_DATA_COUNT
; i
++)
6136 data
= &ring
->data
[i
];
6138 if (data
->m
!= NULL
)
6140 bus_dmamap_sync(ring
->data_dma_tag
, data
->dma_map
,
6141 BUS_DMASYNC_POSTWRITE
);
6142 bus_dmamap_unload(ring
->data_dma_tag
, data
->dma_map
);
6146 if (data
->ni
!= NULL
)
6147 ieee80211_free_node(data
->ni
);
6149 if (data
->dma_map
!= NULL
)
6150 bus_dmamap_destroy(ring
->data_dma_tag
, data
->dma_map
);
6153 if (ring
->data_dma_tag
!= NULL
)
6154 bus_dma_tag_destroy(ring
->data_dma_tag
);
6156 mtx_destroy(&ring
->lock
);
6160 * rt2860_dma_map_addr
6162 static void rt2860_dma_map_addr(void *arg
, bus_dma_segment_t
*segs
,
6163 int nseg
, int error
)
6168 KASSERT(nseg
== 1, ("too many DMA segments, %d should be 1", nseg
));
6170 *(bus_addr_t
*) arg
= segs
[0].ds_addr
;
6174 * rt2860_sysctl_attach
6176 static void rt2860_sysctl_attach(struct rt2860_softc
*sc
)
6178 struct sysctl_ctx_list
*ctx
;
6179 struct sysctl_oid
*tree
;
6180 struct sysctl_oid
*stats
;
6182 ctx
= device_get_sysctl_ctx(sc
->dev
);
6183 tree
= device_get_sysctl_tree(sc
->dev
);
6185 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(tree
), OID_AUTO
,
6186 "tx_stbc", CTLFLAG_RW
, &sc
->tx_stbc
, 0,
6189 /* statistic counters */
6191 stats
= SYSCTL_ADD_NODE(ctx
, SYSCTL_CHILDREN(tree
), OID_AUTO
,
6192 "stats", CTLFLAG_RD
, 0, "statistic");
6194 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6195 "interrupts", CTLFLAG_RD
, &sc
->interrupts
, 0,
6198 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6199 "tx_coherent_interrupts", CTLFLAG_RD
, &sc
->tx_coherent_interrupts
, 0,
6200 "Tx coherent interrupts");
6202 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6203 "rx_coherent_interrupts", CTLFLAG_RD
, &sc
->rx_coherent_interrupts
, 0,
6204 "Rx coherent interrupts");
6206 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6207 "txrx_coherent_interrupts", CTLFLAG_RD
, &sc
->txrx_coherent_interrupts
, 0,
6208 "Tx/Rx coherent interrupts");
6210 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6211 "fifo_sta_full_interrupts", CTLFLAG_RD
, &sc
->fifo_sta_full_interrupts
, 0,
6212 "FIFO statistic full interrupts");
6214 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6215 "rx_interrupts", CTLFLAG_RD
, &sc
->rx_interrupts
, 0,
6218 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6219 "rx_delay_interrupts", CTLFLAG_RD
, &sc
->rx_delay_interrupts
, 0,
6220 "Rx delay interrupts");
6222 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6223 "tx_mgmt_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[5], 0,
6224 "Tx MGMT interrupts");
6226 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6227 "tx_hcca_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[4], 0,
6228 "Tx HCCA interrupts");
6230 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6231 "tx_ac3_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[3], 0,
6232 "Tx AC3 interrupts");
6234 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6235 "tx_ac2_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[2], 0,
6236 "Tx AC2 interrupts");
6238 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6239 "tx_ac1_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[1], 0,
6240 "Tx AC1 interrupts");
6242 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6243 "tx_ac0_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[0], 0,
6244 "Tx AC0 interrupts");
6246 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6247 "tx_delay_interrupts", CTLFLAG_RD
, &sc
->tx_delay_interrupts
, 0,
6248 "Tx delay interrupts");
6250 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6251 "pre_tbtt_interrupts", CTLFLAG_RD
, &sc
->pre_tbtt_interrupts
, 0,
6252 "Pre-TBTT interrupts");
6254 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6255 "tbtt_interrupts", CTLFLAG_RD
, &sc
->tbtt_interrupts
, 0,
6258 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6259 "mcu_cmd_interrupts", CTLFLAG_RD
, &sc
->mcu_cmd_interrupts
, 0,
6260 "MCU command interrupts");
6262 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6263 "auto_wakeup_interrupts", CTLFLAG_RD
, &sc
->auto_wakeup_interrupts
, 0,
6264 "auto wakeup interrupts");
6266 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6267 "gp_timer_interrupts", CTLFLAG_RD
, &sc
->gp_timer_interrupts
, 0,
6268 "GP timer interrupts");
6270 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6271 "tx_mgmt_desc_queued", CTLFLAG_RD
, &sc
->tx_ring
[5].desc_queued
, 0,
6272 "Tx MGMT descriptors queued");
6274 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6275 "tx_mgmt_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[5].data_queued
, 0,
6276 "Tx MGMT data queued");
6278 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6279 "tx_hcca_desc_queued", CTLFLAG_RD
, &sc
->tx_ring
[4].desc_queued
, 0,
6280 "Tx HCCA descriptors queued");
6282 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6283 "tx_hcca_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[4].data_queued
, 0,
6284 "Tx HCCA data queued");
6286 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6287 "tx_ac3_desc_queued", CTLFLAG_RD
, &sc
->tx_ring
[3].desc_queued
, 0,
6288 "Tx AC3 descriptors queued");
6290 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6291 "tx_ac3_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[3].data_queued
, 0,
6292 "Tx AC3 data queued");
6294 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6295 "tx_ac2_desc_queued", CTLFLAG_RD
, &sc
->tx_ring
[2].desc_queued
, 0,
6296 "Tx AC2 descriptors queued");
6298 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6299 "tx_ac2_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[2].data_queued
, 0,
6300 "Tx AC2 data queued");
6302 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6303 "tx_ac1_desc_queued", CTLFLAG_RD
, &sc
->tx_ring
[1].desc_queued
, 0,
6304 "Tx AC1 descriptors queued");
6306 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6307 "tx_ac1_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[1].data_queued
, 0,
6308 "Tx AC1 data queued");
6310 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6311 "tx_ac0_desc_queued", CTLFLAG_RD
, &sc
->tx_ring
[0].desc_queued
, 0,
6312 "Tx AC0 descriptors queued");
6314 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6315 "tx_ac0_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[0].data_queued
, 0,
6316 "Tx AC0 data queued");
6318 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6319 "tx_mgmt_data_queue_full", CTLFLAG_RD
, &sc
->tx_data_queue_full
[5], 0,
6320 "Tx MGMT data queue full");
6322 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6323 "tx_hcca_data_queue_full", CTLFLAG_RD
, &sc
->tx_data_queue_full
[4], 0,
6324 "Tx HCCA data queue full");
6326 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6327 "tx_ac3_data_queue_full", CTLFLAG_RD
, &sc
->tx_data_queue_full
[3], 0,
6328 "Tx AC3 data queue full");
6330 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6331 "tx_ac2_data_queue_full", CTLFLAG_RD
, &sc
->tx_data_queue_full
[2], 0,
6332 "Tx AC2 data queue full");
6334 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6335 "tx_ac1_data_queue_full", CTLFLAG_RD
, &sc
->tx_data_queue_full
[1], 0,
6336 "Tx AC1 data queue full");
6338 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6339 "tx_ac0_data_queue_full", CTLFLAG_RD
, &sc
->tx_data_queue_full
[0], 0,
6340 "Tx AC0 data queue full");
6342 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6343 "tx_watchdog_timeouts", CTLFLAG_RD
, &sc
->tx_watchdog_timeouts
, 0,
6344 "Tx watchdog timeouts");
6346 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6347 "tx_defrag_packets", CTLFLAG_RD
, &sc
->tx_defrag_packets
, 0,
6348 "Tx defragmented packets");
6350 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6351 "no_tx_desc_avail", CTLFLAG_RD
, &sc
->no_tx_desc_avail
, 0,
6352 "no Tx descriptors available");
6354 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6355 "rx_mbuf_alloc_errors", CTLFLAG_RD
, &sc
->rx_mbuf_alloc_errors
, 0,
6356 "Rx mbuf allocation errors");
6358 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6359 "rx_mbuf_dmamap_errors", CTLFLAG_RD
, &sc
->rx_mbuf_dmamap_errors
, 0,
6360 "Rx mbuf DMA mapping errors");
6362 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6363 "tx_queue_0_not_empty", CTLFLAG_RD
, &sc
->tx_queue_not_empty
[0], 0,
6364 "Tx queue 0 not empty");
6366 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6367 "tx_queue_1_not_empty", CTLFLAG_RD
, &sc
->tx_queue_not_empty
[1], 0,
6368 "Tx queue 1 not empty");
6370 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6371 "tx_beacons", CTLFLAG_RD
, &sc
->tx_beacons
, 0,
6374 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6375 "tx_noretryok", CTLFLAG_RD
, &sc
->tx_noretryok
, 0,
6376 "Tx successfull without retries");
6378 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6379 "tx_retryok", CTLFLAG_RD
, &sc
->tx_retryok
, 0,
6380 "Tx successfull with retries");
6382 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6383 "tx_failed", CTLFLAG_RD
, &sc
->tx_failed
, 0,
6386 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6387 "tx_underflows", CTLFLAG_RD
, &sc
->tx_underflows
, 0,
6390 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6391 "tx_zerolen", CTLFLAG_RD
, &sc
->tx_zerolen
, 0,
6394 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6395 "tx_nonagg", CTLFLAG_RD
, &sc
->tx_nonagg
, 0,
6396 "Tx non-aggregated");
6398 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6399 "tx_agg", CTLFLAG_RD
, &sc
->tx_agg
, 0,
6402 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6403 "tx_ampdu", CTLFLAG_RD
, &sc
->tx_ampdu
, 0,
6406 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6407 "tx_mpdu_zero_density", CTLFLAG_RD
, &sc
->tx_mpdu_zero_density
, 0,
6408 "Tx MPDU with zero density");
6410 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6411 "tx_ampdu_sessions", CTLFLAG_RD
, &sc
->tx_ampdu_sessions
, 0,
6412 "Tx A-MPDU sessions");
6414 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6415 "rx_packets", CTLFLAG_RD
, &sc
->rx_packets
, 0,
6418 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6419 "rx_ampdu", CTLFLAG_RD
, &sc
->rx_ampdu
, 0,
6422 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6423 "rx_mpdu_zero_density", CTLFLAG_RD
, &sc
->rx_mpdu_zero_density
, 0,
6424 "Rx MPDU with zero density");
6426 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6427 "rx_ampdu_sessions", CTLFLAG_RD
, &sc
->rx_ampdu_sessions
, 0,
6428 "Rx A-MPDU sessions");
6430 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6431 "rx_amsdu", CTLFLAG_RD
, &sc
->rx_amsdu
, 0,
6434 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6435 "rx_crc_errors", CTLFLAG_RD
, &sc
->rx_crc_errors
, 0,
6438 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6439 "rx_phy_errors", CTLFLAG_RD
, &sc
->rx_phy_errors
, 0,
6442 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6443 "rx_false_ccas", CTLFLAG_RD
, &sc
->rx_false_ccas
, 0,
6446 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6447 "rx_plcp_errors", CTLFLAG_RD
, &sc
->rx_plcp_errors
, 0,
6450 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6451 "rx_dup_packets", CTLFLAG_RD
, &sc
->rx_dup_packets
, 0,
6452 "Rx duplicate packets");
6454 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6455 "rx_fifo_overflows", CTLFLAG_RD
, &sc
->rx_fifo_overflows
, 0,
6456 "Rx FIFO overflows");
6458 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6459 "rx_cipher_no_errors", CTLFLAG_RD
, &sc
->rx_cipher_no_errors
, 0,
6460 "Rx cipher no errors");
6462 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6463 "rx_cipher_icv_errors", CTLFLAG_RD
, &sc
->rx_cipher_icv_errors
, 0,
6464 "Rx cipher ICV errors");
6466 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6467 "rx_cipher_mic_errors", CTLFLAG_RD
, &sc
->rx_cipher_mic_errors
, 0,
6468 "Rx cipher MIC errors");
6470 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6471 "rx_cipher_invalid_key_errors", CTLFLAG_RD
, &sc
->rx_cipher_invalid_key_errors
, 0,
6472 "Rx cipher invalid key errors");
6475 static device_method_t rt2860_dev_methods
[] =
6477 DEVMETHOD(device_probe
, rt2860_probe
),
6478 DEVMETHOD(device_attach
, rt2860_attach
),
6479 DEVMETHOD(device_detach
, rt2860_detach
),
6480 DEVMETHOD(device_shutdown
, rt2860_shutdown
),
6481 DEVMETHOD(device_suspend
, rt2860_suspend
),
6482 DEVMETHOD(device_resume
, rt2860_resume
),
6486 static driver_t rt2860_driver
=
6490 sizeof(struct rt2860_softc
)
6493 static devclass_t rt2860_dev_class
;
6495 DRIVER_MODULE(rt2860
, pci
, rt2860_driver
, rt2860_dev_class
, 0, 0);
6497 MODULE_DEPEND(rt2860
, pci
, 1, 1, 1);
6498 MODULE_DEPEND(rt2860
, wlan
, 1, 1, 1);