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 "rt2870_softc.h"
20 #include "rt2870_reg.h"
21 #include "rt2870_eeprom.h"
22 #include "rt2870_ucode.h"
23 #include "rt2870_rxwi.h"
24 #include "rt2870_rxinfo.h"
25 #include "rt2870_txwi.h"
26 #include "rt2870_txinfo.h"
27 #include "rt2870_read_eeprom.h"
28 #include "rt2870_io.h"
29 #include "rt2870_rf.h"
30 #include "rt2870_led.h"
31 #include "rt2870_debug.h"
37 #define USB_PRODUCT_LINKSYS4_WUSB600N 0x0071
38 #define USB_PRODUCT_DLINK2_DWA140 0x3c09
39 #define USB_PRODUCT_DLINK2_DWA160AREVB 0x3c11
40 #define USB_PRODUCT_ASUS_RT2770F 0x1742
41 #define USB_PRODUCT_RALINK_RT2770 0x2770
43 #define RT2870_USB_CONFIG_NO 1
44 #define RT2870_USB_IFACE_INDEX 0
46 #define RT2870_USB_REQ_MAC_READ_MULTI 0x07
48 /* packet length + Rx wireless info + Rx info */
49 #define RT2870_RX_DESC_SIZE \
50 (sizeof(uint32_t) + sizeof(struct rt2870_rxwi) + sizeof(struct rt2870_rxinfo))
52 /* Tx info + Tx wireless info + max padding */
53 #define RT2870_TX_DESC_SIZE \
54 (sizeof(struct rt2870_txinfo) + sizeof(struct rt2870_txwi) + 11)
56 #define RT2870_MAX_AGG_SIZE 3840
58 #define RT2870_USB_RX_BULK_BUFLEN (2048 * 12)
60 #define RT2870_NOISE_FLOOR -95
62 #define RT2870_AID2WCID(aid) ((aid) & 0xff)
64 #define RT2870_RATE_IS_OFDM(rate) ((rate) >= 12 && (rate) != 22)
66 #define RT2870_ACK_SIZE 14
68 #define IEEE80211_HAS_ADDR4(wh) \
69 (((wh)->i_fc[1] & IEEE80211_FC1_DIR_MASK) == IEEE80211_FC1_DIR_DSTODS)
71 #define RT2870_MS(_v, _f) (((_v) & _f) >> _f##_S)
72 #define RT2870_SM(_v, _f) (((_v) << _f##_S) & _f)
74 #define RT2870_USB_XFER_TIMEOUT 5000
76 #define RT2870_TX_WATCHDOG_TIMEOUT 5
79 * Data structures and types
82 struct rt2870_cmd_argv_newstate
84 enum ieee80211_state nstate
;
88 struct rt2870_cmd_argv_newassoc
92 uint8_t macaddr
[IEEE80211_ADDR_LEN
];
95 struct rt2870_cmd_argv_updatebeacon
100 struct rt2870_cmd_argv_keyset
102 struct ieee80211_key key
;
106 struct rt2870_cmd_argv_keydelete
108 struct ieee80211_key key
;
113 * Static function prototypes
116 static int rt2870_find_usb_endpoints(struct rt2870_softc
*sc
);
118 static void rt2870_init_channels(struct rt2870_softc
*sc
);
120 static void rt2870_init_channels_ht40(struct rt2870_softc
*sc
);
122 static void rt2870_init_locked(void *priv
);
124 static void rt2870_init(void *priv
);
126 static int rt2870_init_bbp(struct rt2870_softc
*sc
);
128 static void rt2870_stop_locked(void *priv
);
130 static void rt2870_stop(void *priv
);
132 static void rt2870_start(struct ifnet
*ifp
);
134 static int rt2870_ioctl(struct ifnet
*ifp
, u_long cmd
, caddr_t data
);
136 static int rt2870_reset(struct ifnet
*ifp
);
138 static int rt2870_newstate(struct ieee80211com
*ic
,
139 enum ieee80211_state nstate
, int arg
);
141 static void rt2870_scan_start(struct ieee80211com
*ic
);
143 static void rt2870_scan_end(struct ieee80211com
*ic
);
145 static void rt2870_set_channel(struct ieee80211com
*ic
);
147 static void rt2870_newassoc(struct ieee80211_node
*ni
, int isnew
);
149 static void rt2870_updateslot(struct ifnet
*ifp
);
151 static int rt2870_wme_update(struct ieee80211com
*ic
);
153 static void rt2870_update_beacon(struct ieee80211com
*ic
, int what
);
155 static void rt2870_key_update_begin(struct ieee80211com
*ic
);
157 static void rt2870_key_update_end(struct ieee80211com
*ic
);
159 static int rt2870_key_set(struct ieee80211com
*ic
,
160 const struct ieee80211_key
*k
, const uint8_t mac
[IEEE80211_ADDR_LEN
]);
162 static int rt2870_key_delete(struct ieee80211com
*ic
,
163 const struct ieee80211_key
*k
);
165 static int rt2870_raw_xmit(struct ieee80211_node
*ni
, struct mbuf
*m
,
166 const struct ieee80211_bpf_params
*params
);
168 static int rt2870_media_change(struct ifnet
*ifp
);
170 static void rt2870_recv_action(struct ieee80211_node
*ni
,
171 const uint8_t *frm
, const uint8_t *efrm
);
173 static int rt2870_send_action(struct ieee80211_node
*ni
,
174 int category
, int action
, uint16_t args
[4]);
176 static void rt2870_amrr_update_iter_func(void *arg
, struct ieee80211_node
*ni
);
178 static void rt2870_periodic(void *arg
);
180 static void rt2870_tx_watchdog(void *arg
);
182 static int rt2870_do_async(struct rt2870_softc
*sc
,
183 void (*cb
)(struct rt2870_softc
*sc
, void *priv
),
186 static void rt2870_newstate_cb(struct rt2870_softc
*sc
, void *arg
);
188 static void rt2870_scan_start_cb(struct rt2870_softc
*sc
, void *arg
);
190 static void rt2870_scan_end_cb(struct rt2870_softc
*sc
, void *arg
);
192 static void rt2870_set_channel_cb(struct rt2870_softc
*sc
, void *arg
);
194 static void rt2870_newassoc_cb(struct rt2870_softc
*sc
, void *arg
);
196 static void rt2870_updateslot_cb(struct rt2870_softc
*sc
, void *arg
);
198 static void rt2870_update_beacon_cb(struct rt2870_softc
*sc
, void *arg
);
200 static void rt2870_wme_update_cb(struct rt2870_softc
*sc
, void *arg
);
202 static void rt2870_key_update_begin_cb(struct rt2870_softc
*sc
, void *arg
);
204 static void rt2870_key_update_end_cb(struct rt2870_softc
*sc
, void *arg
);
206 static void rt2870_key_set_cb(struct rt2870_softc
*sc
, void *arg
);
208 static void rt2870_key_delete_cb(struct rt2870_softc
*sc
, void *arg
);
210 static void rt2870_asic_set_bssid(struct rt2870_softc
*sc
,
211 const uint8_t *bssid
);
213 static void rt2870_asic_set_macaddr(struct rt2870_softc
*sc
,
214 const uint8_t *addr
);
216 static void rt2870_asic_enable_tsf_sync(struct rt2870_softc
*sc
);
218 static void rt2870_asic_disable_tsf_sync(struct rt2870_softc
*sc
);
220 static void rt2870_asic_enable_mrr(struct rt2870_softc
*sc
);
222 static void rt2870_asic_set_txpreamble(struct rt2870_softc
*sc
);
224 static void rt2870_asic_set_basicrates(struct rt2870_softc
*sc
);
226 static void rt2870_asic_update_rtsthreshold(struct rt2870_softc
*sc
);
228 static void rt2870_asic_update_txpower(struct rt2870_softc
*sc
);
230 static void rt2870_asic_update_promisc(struct rt2870_softc
*sc
);
232 static void rt2870_asic_updateprot(struct rt2870_softc
*sc
);
234 static void rt2870_asic_updateslot(struct rt2870_softc
*sc
);
236 static void rt2870_asic_wme_update(struct rt2870_softc
*sc
);
238 static int rt2870_asic_update_beacon(struct rt2870_softc
*sc
);
240 static void rt2870_asic_clear_keytables(struct rt2870_softc
*sc
);
242 static uint8_t rt2870_rxrate(struct rt2870_rxwi
*rxwi
);
244 static uint8_t rt2870_maxrssi_rxpath(struct rt2870_softc
*sc
,
245 const struct rt2870_rxwi
*rxwi
);
247 static int8_t rt2870_rssi2dbm(struct rt2870_softc
*sc
,
248 uint8_t rssi
, uint8_t rxpath
);
250 static uint8_t rt2870_rate2mcs(uint8_t rate
);
252 static int rt2870_ackrate(struct ieee80211com
*ic
, int rate
);
254 static uint16_t rt2870_txtime(int len
, int rate
, uint32_t flags
);
256 static void rt2870_rx_frame(struct rt2870_softc
*sc
,
257 uint8_t *buf
, uint32_t dmalen
);
259 static int rt2870_tx_frame(struct rt2870_softc
*sc
,
260 struct mbuf
*m
, struct ieee80211_node
*ni
, int qid
);
262 static int rt2870_tx_raw(struct rt2870_softc
*sc
,
263 struct mbuf
*m
, struct ieee80211_node
*ni
,
264 const struct ieee80211_bpf_params
*params
);
266 static void rt2870_rx_intr(usbd_xfer_handle xfer
,
267 usbd_private_handle priv
, usbd_status status
);
269 static void rt2870_tx_intr(usbd_xfer_handle xfer
,
270 usbd_private_handle priv
, usbd_status status
);
272 static void rt2870_rx_done_task(void *context
, int pending
);
274 static void rt2870_tx_done_task(void *context
, int pending
);
276 static void rt2870_periodic_task(void *context
, int pending
);
278 static void rt2870_cmd_task(void *context
, int pending
);
280 static int rt2870_rx_eof(struct rt2870_softc
*sc
, int limit
);
282 static void rt2870_tx_eof(struct rt2870_softc
*sc
,
283 struct rt2870_softc_tx_ring
*ring
);
285 static void rt2870_update_stats(struct rt2870_softc
*sc
);
287 static void rt2870_watchdog(struct rt2870_softc
*sc
);
289 static void rt2870_drain_fifo_stats(struct rt2870_softc
*sc
);
291 static void rt2870_update_raw_counters(struct rt2870_softc
*sc
);
293 static int rt2870_alloc_rx_ring(struct rt2870_softc
*sc
,
294 struct rt2870_softc_rx_ring
*ring
);
296 static void rt2870_reset_rx_ring(struct rt2870_softc
*sc
,
297 struct rt2870_softc_rx_ring
*ring
);
299 static void rt2870_free_rx_ring(struct rt2870_softc
*sc
,
300 struct rt2870_softc_rx_ring
*ring
);
302 static int rt2870_alloc_tx_ring(struct rt2870_softc
*sc
,
303 struct rt2870_softc_tx_ring
*ring
, int qid
);
305 static void rt2870_reset_tx_ring(struct rt2870_softc
*sc
,
306 struct rt2870_softc_tx_ring
*ring
);
308 static void rt2870_free_tx_ring(struct rt2870_softc
*sc
,
309 struct rt2870_softc_tx_ring
*ring
);
311 static void rt2870_reset_cmd_ring(struct rt2870_softc
*sc
,
312 struct rt2870_softc_cmd_ring
*ring
);
314 static void rt2870_sysctl_attach(struct rt2870_softc
*sc
);
320 static const struct usb_devno rt2870_usb_devno
[] =
322 { USB_VENDOR_LINKSYS4
, USB_PRODUCT_LINKSYS4_WUSB600N
}, /* Linksys WUSB600N */
323 { USB_VENDOR_DLINK2
, USB_PRODUCT_DLINK2_DWA140
}, /* D-Link DWA-140 */
324 { USB_VENDOR_DLINK2
, USB_PRODUCT_DLINK2_DWA160AREVB
}, /* D-Link DWA-160A Rev. B */
325 { USB_VENDOR_ASUS
, USB_PRODUCT_ASUS_RT2770F
}, /* Asus RT2770F */
326 { USB_VENDOR_RALINK
, USB_PRODUCT_RALINK_RT2770
}, /* Ralink RT2770 */
335 { RT2870_REG_PBF_BCN_OFFSET0
, 0xf8f0e8e0 },
336 { RT2870_REG_PBF_BCN_OFFSET1
, 0x6f77d0c8 },
337 { RT2870_REG_LEGACY_BASIC_RATE
, 0x0000013f },
338 { RT2870_REG_HT_BASIC_RATE
, 0x00008003 },
339 { RT2870_REG_SYS_CTRL
, 0x00000000 },
340 { RT2870_REG_RX_FILTER_CFG
, 0x00017f97 },
341 { RT2870_REG_BKOFF_SLOT_CFG
, 0x00000209 },
342 { RT2870_REG_TX_SW_CFG0
, 0x00000000 },
343 { RT2870_REG_TX_SW_CFG1
, 0x00080606 },
344 { RT2870_REG_TX_LINK_CFG
, 0x00001020 },
345 { RT2870_REG_TX_TIMEOUT_CFG
, 0x000a2090 },
346 { RT2870_REG_MAX_LEN_CFG
, (1 << 12) | RT2870_MAX_AGG_SIZE
},
347 { RT2870_REG_LED_CFG
, 0x7f031e46 },
348 { RT2870_REG_PBF_MAX_PCNT
, 0x1f3fbf9f },
349 { RT2870_REG_TX_RTY_CFG
, 0x47d01f0f },
350 { RT2870_REG_AUTO_RSP_CFG
, 0x00000013 },
351 { RT2870_REG_TX_CCK_PROT_CFG
, 0x05740003 },
352 { RT2870_REG_TX_OFDM_PROT_CFG
, 0x05740003 },
353 { RT2870_REG_PBF_CFG
, 0x00f40006 },
354 { RT2870_REG_TX_MM40_PROT_CFG
, 0x03f44084 },
355 { RT2870_REG_SCHDMA_WPDMA_GLO_CFG
, 0x00000030 },
356 { RT2870_REG_TX_GF20_PROT_CFG
, 0x01744004 },
357 { RT2870_REG_TX_GF40_PROT_CFG
, 0x03f44084 },
358 { RT2870_REG_TX_MM20_PROT_CFG
, 0x01744004 },
359 { RT2870_REG_TX_TXOP_CTRL_CFG
, 0x0000583f },
360 { RT2870_REG_TX_RTS_CFG
, 0x00092b20 },
361 { RT2870_REG_TX_EXP_ACK_TIME
, 0x002400ca },
362 { RT2870_REG_HCCAPSMP_TXOP_HLDR_ET
, 0x00000002 },
363 { RT2870_REG_XIFS_TIME_CFG
, 0x33a41010 },
364 { RT2870_REG_PWR_PIN_CFG
, 0x00000003 },
365 { RT2870_REG_SCHDMA_WMM_AIFSN_CFG
, 0x00002273 },
366 { RT2870_REG_SCHDMA_WMM_CWMIN_CFG
, 0x00002344 },
367 { RT2870_REG_SCHDMA_WMM_CWMAX_CFG
, 0x000034aa },
370 #define RT2870_DEF_MAC_SIZE (sizeof(rt2870_def_mac) / sizeof(rt2870_def_mac[0]))
394 #define RT2870_DEF_BBP_SIZE (sizeof(rt2870_def_bbp) / sizeof(rt2870_def_bbp[0]))
399 static int rt2870_probe(device_t dev
)
401 struct usb_attach_arg
*uaa
;
403 uaa
= device_get_ivars(dev
);
405 if (uaa
->iface
!= NULL
)
408 return (usb_lookup(rt2870_usb_devno
, uaa
->vendor
, uaa
->product
) != NULL
) ?
409 UMATCH_VENDOR_PRODUCT
: UMATCH_NONE
;
415 static int rt2870_attach(device_t dev
)
417 struct rt2870_softc
*sc
;
418 struct usb_attach_arg
*uaa
;
419 usbd_status usb_error
;
420 struct ieee80211com
*ic
;
422 int error
, ntries
, i
;
424 sc
= device_get_softc(dev
);
425 uaa
= device_get_ivars(dev
);
428 sc
->usb_dev
= uaa
->device
;
433 SYSCTL_ADD_INT(device_get_sysctl_ctx(dev
),
434 SYSCTL_CHILDREN(device_get_sysctl_tree(dev
)), OID_AUTO
,
435 "debug", CTLFLAG_RW
, &sc
->debug
, 0, "rt2870 debug level");
438 RT2870_DPRINTF(sc
, RT2870_DEBUG_ANY
,
440 device_get_nameunit(sc
->dev
));
442 if (usbd_set_config_no(sc
->usb_dev
, RT2870_USB_CONFIG_NO
, 0) != 0)
444 printf("%s: could not set USB configuration no\n",
445 device_get_nameunit(sc
->dev
));
449 usb_error
= usbd_device2interface_handle(sc
->usb_dev
,
450 RT2870_USB_IFACE_INDEX
, &sc
->usb_iface
);
453 printf("%s: could not get USB interface handle\n",
454 device_get_nameunit(sc
->dev
));
458 error
= rt2870_find_usb_endpoints(sc
);
462 for (ntries
= 0; ntries
< 100; ntries
++)
464 sc
->mac_rev
= rt2870_io_mac_read(sc
, RT2870_REG_MAC_CSR0
);
465 if (sc
->mac_rev
!= 0x00000000 && sc
->mac_rev
!= 0xffffffff)
473 printf("%s: timeout waiting for NIC to initialize\n",
474 device_get_nameunit(sc
->dev
));
478 rt2870_read_eeprom(sc
);
480 printf("%s: MAC/BBP RT2870 (rev 0x%08x), RF %s\n",
481 device_get_nameunit(sc
->dev
), sc
->mac_rev
,
482 rt2870_rf_name(sc
->rf_rev
));
484 /* open Tx and Rx USB bulk pipes */
486 for (i
= 0; i
< sc
->usb_endpoints
- 1; i
++)
488 error
= usbd_open_pipe(sc
->usb_iface
, sc
->tx_ring
[i
].usb_ep
,
489 USBD_EXCLUSIVE_USE
, &sc
->tx_ring
[i
].usb_pipe
);
492 printf("%s: could not open Tx pipe #%d: %s\n",
493 device_get_nameunit(sc
->dev
), i
, usbd_errstr(error
));
498 error
= usbd_open_pipe(sc
->usb_iface
, sc
->rx_ring
.usb_ep
,
499 USBD_EXCLUSIVE_USE
, &sc
->rx_ring
.usb_pipe
);
502 printf("%s: could not open Rx pipe: %s\n",
503 device_get_nameunit(sc
->dev
), usbd_errstr(error
));
507 /* allocate Tx and Rx rings */
509 for (i
= 0; i
< sc
->usb_endpoints
- 1; i
++)
511 error
= rt2870_alloc_tx_ring(sc
, &sc
->tx_ring
[i
], i
);
514 printf("%s: could not allocate Tx ring #%d\n",
515 device_get_nameunit(sc
->dev
), i
);
520 if (sc
->usb_endpoints
== (RT2870_SOFTC_TX_RING_COUNT
+ 1))
521 sc
->tx_ring_mgtqid
= 5;
523 sc
->tx_ring_mgtqid
= 0;
525 error
= rt2870_alloc_rx_ring(sc
, &sc
->rx_ring
);
528 printf("%s: could not allocate Rx ring\n",
529 device_get_nameunit(sc
->dev
));
533 callout_init(&sc
->periodic_ch
, 0);
534 callout_init(&sc
->tx_watchdog_ch
, 0);
536 ifp
= sc
->ifp
= if_alloc(IFT_ETHER
);
539 printf("%s: could not if_alloc()\n",
540 device_get_nameunit(sc
->dev
));
547 if_initname(ifp
, "rt2870", device_get_unit(sc
->dev
));
549 ifp
->if_flags
= IFF_BROADCAST
| IFF_SIMPLEX
| IFF_MULTICAST
|
552 ifp
->if_init
= rt2870_init
;
553 ifp
->if_ioctl
= rt2870_ioctl
;
554 ifp
->if_start
= rt2870_start
;
556 IFQ_SET_MAXLEN(&ifp
->if_snd
, IFQ_MAXLEN
);
557 ifp
->if_snd
.ifq_drv_maxlen
= IFQ_MAXLEN
;
558 IFQ_SET_READY(&ifp
->if_snd
);
564 ic
->ic_phytype
= IEEE80211_T_HT
;
565 ic
->ic_opmode
= IEEE80211_M_STA
;
566 ic
->ic_state
= IEEE80211_S_INIT
;
568 ic
->ic_caps
= IEEE80211_C_MONITOR
|
573 /* IEEE80211_C_BGSCAN | */
575 IEEE80211_C_SHPREAMBLE
|
582 IEEE80211_C_AES_CCM
|
585 ic
->ic_htcaps
= IEEE80211_HTC_HT
|
586 IEEE80211_HTC_AMSDU
| /* A-MSDU Tx */
587 IEEE80211_HTCAP_MAXAMSDU_3839
| /* max. A-MSDU Rx length */
588 IEEE80211_HTCAP_CHWIDTH40
| /* HT 40MHz channel width */
589 IEEE80211_HTCAP_GREENFIELD
|
590 IEEE80211_HTCAP_SHORTGI20
| /* short GI for HT 20MHz */
591 IEEE80211_HTCAP_SHORTGI40
| /* short GI for HT 40MHz */
592 IEEE80211_HTCAP_RXSTBC_2STREAM
;
597 ic
->ic_regdomain
= 0;
598 ic
->ic_countrycode
= CTRY_DEFAULT
;
601 rt2870_init_channels(sc
);
603 rt2870_init_channels_ht40(sc
);
605 IEEE80211_ADDR_COPY(ic
->ic_myaddr
, sc
->mac_addr
);
607 ieee80211_ifattach(ic
);
609 sc
->newstate
= ic
->ic_newstate
;
610 ic
->ic_newstate
= rt2870_newstate
;
612 ic
->ic_reset
= rt2870_reset
;
613 ic
->ic_scan_start
= rt2870_scan_start
;
614 ic
->ic_scan_end
= rt2870_scan_end
;
615 ic
->ic_set_channel
= rt2870_set_channel
;
616 ic
->ic_newassoc
= rt2870_newassoc
;
617 ic
->ic_updateslot
= rt2870_updateslot
;
618 ic
->ic_wme
.wme_update
= rt2870_wme_update
;
619 ic
->ic_update_beacon
= rt2870_update_beacon
;
620 ic
->ic_crypto
.cs_key_update_begin
= rt2870_key_update_begin
;
621 ic
->ic_crypto
.cs_key_update_end
= rt2870_key_update_end
;
622 ic
->ic_crypto
.cs_key_set
= rt2870_key_set
;
623 ic
->ic_crypto
.cs_key_delete
= rt2870_key_delete
;
624 ic
->ic_raw_xmit
= rt2870_raw_xmit
;
626 sc
->recv_action
= ic
->ic_recv_action
;
627 ic
->ic_recv_action
= rt2870_recv_action
;
629 sc
->send_action
= ic
->ic_send_action
;
630 ic
->ic_send_action
= rt2870_send_action
;
632 /* hardware requires padding between 802.11 frame header and body */
634 ic
->ic_flags
|= IEEE80211_F_WME
| IEEE80211_F_DATAPAD
| IEEE80211_F_DOTH
;
636 ic
->ic_flags_ext
|= IEEE80211_FEXT_SWBMISS
;
638 ieee80211_media_init(ic
, rt2870_media_change
, ieee80211_media_status
);
640 rt2870_amrr_init(&sc
->amrr
, ic
,
641 RT2870_AMRR_MIN_SUCCESS_THRESHOLD
,
642 RT2870_AMRR_MAX_SUCCESS_THRESHOLD
,
645 bpfattach2(ifp
, DLT_IEEE802_11_RADIO
,
646 sizeof(struct ieee80211_frame
) + IEEE80211_RADIOTAP_HDRLEN
,
649 sc
->rxtap_len
= sizeof(sc
->rxtapu
);
650 sc
->rxtap
.ihdr
.it_len
= htole16(sc
->rxtap_len
);
651 sc
->rxtap
.ihdr
.it_present
= htole32(RT2870_SOFTC_RX_RADIOTAP_PRESENT
);
653 sc
->txtap_len
= sizeof(sc
->txtapu
);
654 sc
->txtap
.ihdr
.it_len
= htole16(sc
->txtap_len
);
655 sc
->txtap
.ihdr
.it_present
= htole32(RT2870_SOFTC_TX_RADIOTAP_PRESENT
);
657 /* init task queue */
659 TASK_INIT(&sc
->rx_done_task
, 0, rt2870_rx_done_task
, sc
);
660 TASK_INIT(&sc
->tx_done_task
, 0, rt2870_tx_done_task
, sc
);
661 TASK_INIT(&sc
->periodic_task
, 0, rt2870_periodic_task
, sc
);
662 TASK_INIT(&sc
->cmd_task
, 0, rt2870_cmd_task
, sc
);
664 sc
->rx_process_limit
= 100;
666 sc
->taskqueue
= taskqueue_create("rt2870_taskq", M_NOWAIT
,
667 taskqueue_thread_enqueue
, &sc
->taskqueue
);
669 taskqueue_start_threads(&sc
->taskqueue
, 1, PI_NET
, "%s taskq",
670 device_get_nameunit(sc
->dev
));
672 rt2870_sysctl_attach(sc
);
675 ieee80211_announce(ic
);
677 usbd_add_drv_event(USB_EVENT_DRIVER_ATTACH
, sc
->usb_dev
, sc
->dev
);
683 /* close Tx and Rx USB bulk pipes */
685 if (sc
->rx_ring
.usb_pipe
!= NULL
)
687 usbd_abort_pipe(sc
->rx_ring
.usb_pipe
);
688 usbd_close_pipe(sc
->rx_ring
.usb_pipe
);
689 sc
->rx_ring
.usb_pipe
= NULL
;
692 for (i
= 0; i
< sc
->usb_endpoints
- 1; i
++)
694 if (sc
->tx_ring
[i
].usb_pipe
!= NULL
)
696 usbd_abort_pipe(sc
->tx_ring
[i
].usb_pipe
);
697 usbd_close_pipe(sc
->tx_ring
[i
].usb_pipe
);
698 sc
->tx_ring
[i
].usb_pipe
= NULL
;
702 /* free Tx and Rx rings */
704 for (i
= 0; i
< sc
->usb_endpoints
- 1; i
++)
705 rt2870_free_tx_ring(sc
, &sc
->tx_ring
[i
]);
707 rt2870_free_rx_ring(sc
, &sc
->rx_ring
);
715 static int rt2870_detach(device_t dev
)
717 struct rt2870_softc
*sc
;
718 struct ieee80211com
*ic
;
722 if (!device_is_attached(dev
))
725 sc
= device_get_softc(dev
);
729 RT2870_DPRINTF(sc
, RT2870_DEBUG_ANY
,
731 device_get_nameunit(sc
->dev
));
735 ifp
->if_drv_flags
&= ~(IFF_DRV_RUNNING
| IFF_DRV_OACTIVE
);
737 ieee80211_new_state(ic
, IEEE80211_S_INIT
, -1);
739 callout_stop(&sc
->periodic_ch
);
740 callout_stop(&sc
->tx_watchdog_ch
);
742 taskqueue_drain(sc
->taskqueue
, &sc
->rx_done_task
);
743 taskqueue_drain(sc
->taskqueue
, &sc
->tx_done_task
);
744 taskqueue_drain(sc
->taskqueue
, &sc
->periodic_task
);
745 taskqueue_drain(sc
->taskqueue
, &sc
->cmd_task
);
747 /* close Tx and Rx USB bulk pipes */
749 if (sc
->rx_ring
.usb_pipe
!= NULL
)
751 usbd_abort_pipe(sc
->rx_ring
.usb_pipe
);
752 usbd_close_pipe(sc
->rx_ring
.usb_pipe
);
753 sc
->rx_ring
.usb_pipe
= NULL
;
756 for (i
= 0; i
< sc
->usb_endpoints
- 1; i
++)
758 if (sc
->tx_ring
[i
].usb_pipe
!= NULL
)
760 usbd_abort_pipe(sc
->tx_ring
[i
].usb_pipe
);
761 usbd_close_pipe(sc
->tx_ring
[i
].usb_pipe
);
762 sc
->tx_ring
[i
].usb_pipe
= NULL
;
766 /* free Tx and Rx rings */
768 for (i
= 0; i
< sc
->usb_endpoints
- 1; i
++)
769 rt2870_free_tx_ring(sc
, &sc
->tx_ring
[i
]);
771 rt2870_free_rx_ring(sc
, &sc
->rx_ring
);
775 ieee80211_ifdetach(ic
);
779 taskqueue_free(sc
->taskqueue
);
781 usbd_add_drv_event(USB_EVENT_DRIVER_DETACH
, sc
->usb_dev
, sc
->dev
);
787 * rt2870_find_usb_endpoints
789 static int rt2870_find_usb_endpoints(struct rt2870_softc
*sc
)
791 usb_interface_descriptor_t
*id
;
792 usb_endpoint_descriptor_t
*ed
;
795 id
= usbd_get_interface_descriptor(sc
->usb_iface
);
797 sc
->usb_endpoints
= id
->bNumEndpoints
;
798 if ((sc
->usb_endpoints
!= (RT2870_SOFTC_TX_RING_COUNT
+ 1)) &&
799 (sc
->usb_endpoints
!= (RT2870_SOFTC_TX_RING_COUNT
- 2 + 1)))
801 printf("%s: wrong number of USB endpoints=%d\n",
802 device_get_nameunit(sc
->dev
), sc
->usb_endpoints
);
806 sc
->rx_ring
.usb_ep
= -1;
808 for (i
= 0; i
< RT2870_SOFTC_TX_RING_COUNT
; i
++)
809 sc
->tx_ring
[i
].usb_ep
= -1;
811 for (i
= 0, j
= 0; i
< id
->bNumEndpoints
; i
++)
813 ed
= usbd_interface2endpoint_descriptor(sc
->usb_iface
, i
);
816 printf("%s: no endpoint descriptor #%d for USB interface\n",
817 device_get_nameunit(sc
->dev
), i
);
821 if (UE_GET_DIR(ed
->bEndpointAddress
) == UE_DIR_IN
&&
822 UE_GET_XFERTYPE(ed
->bmAttributes
) == UE_BULK
)
824 sc
->rx_ring
.usb_ep
= ed
->bEndpointAddress
;
826 else if (UE_GET_DIR(ed
->bEndpointAddress
) == UE_DIR_OUT
&&
827 UE_GET_XFERTYPE(ed
->bmAttributes
) == UE_BULK
)
829 if (j
< RT2870_SOFTC_TX_RING_COUNT
)
830 sc
->tx_ring
[j
++].usb_ep
= ed
->bEndpointAddress
;
832 sc
->tx_ring
[RT2870_SOFTC_TX_RING_COUNT
- 1].usb_ep
=
833 ed
->bEndpointAddress
;
837 if ((sc
->rx_ring
.usb_ep
== -1) ||
838 ((j
!= RT2870_SOFTC_TX_RING_COUNT
) && (j
!= RT2870_SOFTC_TX_RING_COUNT
- 2)))
840 printf("%s: missing USB endpoints\n",
841 device_get_nameunit(sc
->dev
));
849 * rt2870_init_channels
851 static void rt2870_init_channels(struct rt2870_softc
*sc
)
853 struct ieee80211com
*ic
;
854 struct ieee80211_channel
*c
;
859 /* set supported channels for 2GHz band */
861 for (i
= 1; i
<= 14; i
++)
863 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
864 flags
= IEEE80211_CHAN_B
;
866 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
870 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
871 flags
= IEEE80211_CHAN_B
| IEEE80211_CHAN_HT20
;
873 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
877 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
878 flags
= IEEE80211_CHAN_G
;
880 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
884 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
885 flags
= IEEE80211_CHAN_G
| IEEE80211_CHAN_HT20
;
887 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
892 /* set supported channels for 5GHz band */
894 if (sc
->rf_rev
== RT2870_EEPROM_RF_2850
||
895 sc
->rf_rev
== RT2870_EEPROM_RF_2750
)
897 for (i
= 36; i
<= 64; i
+= 4)
899 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
900 flags
= IEEE80211_CHAN_A
;
902 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
906 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
907 flags
= IEEE80211_CHAN_A
| IEEE80211_CHAN_HT20
;
909 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
914 for (i
= 100; i
<= 140; i
+= 4)
916 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
917 flags
= IEEE80211_CHAN_A
;
919 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
923 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
924 flags
= IEEE80211_CHAN_A
| IEEE80211_CHAN_HT20
;
926 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
931 for (i
= 149; i
<= 165; i
+= 4)
933 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
934 flags
= IEEE80211_CHAN_A
;
936 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
940 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
941 flags
= IEEE80211_CHAN_A
| IEEE80211_CHAN_HT20
;
943 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
951 * rt2870_init_channels_ht40
953 static void rt2870_init_channels_ht40(struct rt2870_softc
*sc
)
955 struct ieee80211com
*ic
;
956 struct ieee80211_channel
*c
, *cent
, *ext
;
961 /* set supported channels for 2GHz band */
963 for (i
= 1; i
<= 14; i
++)
965 flags
= IEEE80211_CHAN_G
| IEEE80211_CHAN_HT40
;
967 /* find the center channel */
969 cent
= ieee80211_find_channel_byieee(ic
, i
,
970 flags
& ~IEEE80211_CHAN_HT
);
973 printf("%s: skip channel %d, could not find center channel\n",
974 device_get_nameunit(sc
->dev
), i
);
978 /* find the extension channel */
980 ext
= ieee80211_find_channel(ic
, cent
->ic_freq
+ 20,
981 flags
& ~IEEE80211_CHAN_HT
);
984 printf("%s: skip channel %d, could not find extension channel\n",
985 device_get_nameunit(sc
->dev
), i
);
989 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
992 c
->ic_extieee
= ext
->ic_ieee
;
993 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
994 c
->ic_flags
|= IEEE80211_CHAN_HT40U
;
996 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
999 c
->ic_extieee
= cent
->ic_ieee
;
1000 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1001 c
->ic_flags
|= IEEE80211_CHAN_HT40D
;
1004 /* set supported channels for 5GHz band */
1006 if (sc
->rf_rev
== RT2870_EEPROM_RF_2850
||
1007 sc
->rf_rev
== RT2870_EEPROM_RF_2750
)
1009 for (i
= 36; i
<= 64; i
+= 4)
1011 flags
= IEEE80211_CHAN_A
| IEEE80211_CHAN_HT40
;
1013 /* find the center channel */
1015 cent
= ieee80211_find_channel_byieee(ic
, i
,
1016 flags
& ~IEEE80211_CHAN_HT
);
1019 printf("%s: skip channel %d, could not find center channel\n",
1020 device_get_nameunit(sc
->dev
), i
);
1024 /* find the extension channel */
1026 ext
= ieee80211_find_channel(ic
, cent
->ic_freq
+ 20,
1027 flags
& ~IEEE80211_CHAN_HT
);
1030 printf("%s: skip channel %d, could not find extension channel\n",
1031 device_get_nameunit(sc
->dev
), i
);
1035 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1038 c
->ic_extieee
= ext
->ic_ieee
;
1039 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1040 c
->ic_flags
|= IEEE80211_CHAN_HT40U
;
1042 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1045 c
->ic_extieee
= cent
->ic_ieee
;
1046 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1047 c
->ic_flags
|= IEEE80211_CHAN_HT40D
;
1050 for (i
= 100; i
<= 140; i
+= 4)
1052 flags
= IEEE80211_CHAN_A
| IEEE80211_CHAN_HT40
;
1054 /* find the center channel */
1056 cent
= ieee80211_find_channel_byieee(ic
, i
,
1057 flags
& ~IEEE80211_CHAN_HT
);
1060 printf("%s: skip channel %d, could not find center channel\n",
1061 device_get_nameunit(sc
->dev
), i
);
1065 /* find the extension channel */
1067 ext
= ieee80211_find_channel(ic
, cent
->ic_freq
+ 20,
1068 flags
& ~IEEE80211_CHAN_HT
);
1071 printf("%s: skip channel %d, could not find extension channel\n",
1072 device_get_nameunit(sc
->dev
), i
);
1076 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1079 c
->ic_extieee
= ext
->ic_ieee
;
1080 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1081 c
->ic_flags
|= IEEE80211_CHAN_HT40U
;
1083 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1086 c
->ic_extieee
= cent
->ic_ieee
;
1087 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1088 c
->ic_flags
|= IEEE80211_CHAN_HT40D
;
1091 for (i
= 149; i
<= 165; i
+= 4)
1093 flags
= IEEE80211_CHAN_A
| IEEE80211_CHAN_HT40
;
1095 /* find the center channel */
1097 cent
= ieee80211_find_channel_byieee(ic
, i
,
1098 flags
& ~IEEE80211_CHAN_HT
);
1101 printf("%s: skip channel %d, could not find center channel\n",
1102 device_get_nameunit(sc
->dev
), i
);
1106 /* find the extension channel */
1108 ext
= ieee80211_find_channel(ic
, cent
->ic_freq
+ 20,
1109 flags
& ~IEEE80211_CHAN_HT
);
1112 printf("%s: skip channel %d, could not find extension channel\n",
1113 device_get_nameunit(sc
->dev
), i
);
1117 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1120 c
->ic_extieee
= ext
->ic_ieee
;
1121 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1122 c
->ic_flags
|= IEEE80211_CHAN_HT40U
;
1124 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1127 c
->ic_extieee
= cent
->ic_ieee
;
1128 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1129 c
->ic_flags
|= IEEE80211_CHAN_HT40D
;
1135 * rt2870_init_locked
1137 static void rt2870_init_locked(void *priv
)
1139 struct rt2870_softc
*sc
;
1140 struct ieee80211com
*ic
;
1142 struct rt2870_softc_rx_data
*data
;
1143 int ntries
, error
, i
;
1144 uint32_t tmp
, stacnt
[6];
1150 RT2870_DPRINTF(sc
, RT2870_DEBUG_ANY
,
1151 "%s: initializing\n",
1152 device_get_nameunit(sc
->dev
));
1154 if (!(sc
->flags
& RT2870_SOFTC_FLAGS_UCODE_LOADED
))
1156 RT2870_DPRINTF(sc
, RT2870_DEBUG_ANY
,
1157 "%s: loading 8051 microcode\n",
1158 device_get_nameunit(sc
->dev
));
1160 error
= rt2870_io_mcu_load_ucode(sc
, rt2870_ucode
, sizeof(rt2870_ucode
));
1163 printf("%s: could not load 8051 microcode\n",
1164 device_get_nameunit(sc
->dev
));
1168 RT2870_DPRINTF(sc
, RT2870_DEBUG_ANY
,
1169 "%s: 8051 microcode was successfully loaded\n",
1170 device_get_nameunit(sc
->dev
));
1172 sc
->flags
|= RT2870_SOFTC_FLAGS_UCODE_LOADED
;
1175 /* wait while DMA engine is busy */
1177 for (ntries
= 0; ntries
< 100; ntries
++)
1179 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_SCHDMA_WPDMA_GLO_CFG
);
1180 if (!(tmp
& (RT2870_REG_TX_DMA_BUSY
| RT2870_REG_RX_DMA_BUSY
)))
1188 printf("%s: timeout waiting for DMA engine\n",
1189 device_get_nameunit(sc
->dev
));
1194 tmp
|= RT2870_REG_TX_WB_DDONE
;
1196 rt2870_io_mac_write(sc
, RT2870_REG_SCHDMA_WPDMA_GLO_CFG
, tmp
);
1198 /* PBF hardware reset */
1200 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_PBF_SYS_CTRL
);
1204 rt2870_io_mac_write(sc
, RT2870_REG_PBF_SYS_CTRL
, tmp
);
1206 rt2870_io_mac_write(sc
, RT2870_REG_SYS_CTRL
,
1207 RT2870_REG_MAC_SRST
| RT2870_REG_BBP_HRST
);
1209 rt2870_io_mac_write(sc
, RT2870_REG_SCHDMA_USB_DMA_CFG
, 0);
1211 rt2870_io_mcu_reset(sc
);
1213 rt2870_io_mac_write(sc
, RT2870_REG_SYS_CTRL
, 0);
1215 /* init Tx power per rate */
1217 for (i
= 0; i
< RT2870_SOFTC_TXPOW_RATE_COUNT
; i
++)
1219 if (sc
->txpow_rate_20mhz
[i
] == 0xffffffff)
1222 rt2870_io_mac_write(sc
, RT2870_REG_TX_PWR_CFG(i
),
1223 sc
->txpow_rate_20mhz
[i
]);
1226 for (i
= 0; i
< RT2870_DEF_MAC_SIZE
; i
++)
1227 rt2870_io_mac_write(sc
, rt2870_def_mac
[i
].reg
,
1228 rt2870_def_mac
[i
].val
);
1230 /* wait while MAC is busy */
1232 for (ntries
= 0; ntries
< 100; ntries
++)
1234 if (!(rt2870_io_mac_read(sc
, RT2870_REG_STATUS_CFG
) &
1235 (RT2870_REG_STATUS_TX_BUSY
| RT2870_REG_STATUS_RX_BUSY
)))
1243 printf("%s: timeout waiting for MAC\n",
1244 device_get_nameunit(sc
->dev
));
1248 /* clear Host to MCU mailbox */
1250 rt2870_io_mac_write(sc
, RT2870_REG_H2M_MAILBOX_BBP_AGENT
, 0);
1251 rt2870_io_mac_write(sc
, RT2870_REG_H2M_MAILBOX
, 0);
1255 error
= rt2870_init_bbp(sc
);
1259 /* set up maximum buffer sizes */
1261 tmp
= (1 << 12) | RT2870_MAX_AGG_SIZE
;
1263 if (sc
->mac_rev
>= 0x28720200 && sc
->mac_rev
< 0x30700200)
1269 rt2870_io_mac_write(sc
, RT2870_REG_MAX_LEN_CFG
, tmp
);
1271 /* set mac address */
1273 IEEE80211_ADDR_COPY(ic
->ic_myaddr
, IF_LLADDR(ifp
));
1275 rt2870_asic_set_macaddr(sc
, ic
->ic_myaddr
);
1277 /* clear statistic registers */
1279 rt2870_io_mac_read_multi(sc
, RT2870_REG_RX_STA_CNT0
,
1280 stacnt
, sizeof(stacnt
));
1282 /* send LEDs operating mode to microcontroller */
1284 rt2870_io_mcu_cmd(sc
, RT2870_IO_MCU_CMD_LED1
,
1285 RT2870_REG_H2M_TOKEN_NO_INTR
, sc
->led_off
[0]);
1286 rt2870_io_mcu_cmd(sc
, RT2870_IO_MCU_CMD_LED2
,
1287 RT2870_REG_H2M_TOKEN_NO_INTR
, sc
->led_off
[1]);
1288 rt2870_io_mcu_cmd(sc
, RT2870_IO_MCU_CMD_LED3
,
1289 RT2870_REG_H2M_TOKEN_NO_INTR
, sc
->led_off
[2]);
1291 /* write vendor-specific BBP values (from EEPROM) */
1293 for (i
= 0; i
< RT2870_SOFTC_BBP_EEPROM_COUNT
; i
++)
1295 if (sc
->bbp_eeprom
[i
].reg
== 0x00 ||
1296 sc
->bbp_eeprom
[i
].reg
== 0xff)
1299 rt2870_io_bbp_write(sc
, sc
->bbp_eeprom
[i
].reg
,
1300 sc
->bbp_eeprom
[i
].val
);
1303 /* disable non-existing Rx chains */
1305 tmp
= rt2870_io_bbp_read(sc
, 3);
1307 tmp
&= ~((1 << 4) | (1 << 3));
1309 if (sc
->nrxpath
== 3)
1311 else if (sc
->nrxpath
== 2)
1314 rt2870_io_bbp_write(sc
, 3, tmp
);
1316 /* disable non-existing Tx chains */
1318 tmp
= rt2870_io_bbp_read(sc
, 1);
1320 if (sc
->ntxpath
== 1)
1321 tmp
&= ~((1 << 4) | (1 << 3));
1323 rt2870_io_bbp_write(sc
, 1, tmp
);
1325 tmp
= rt2870_io_bbp_read(sc
, 4);
1329 rt2870_io_bbp_write(sc
, 4, tmp
);
1331 /* set current channel */
1333 rt2870_rf_set_chan(sc
, ic
->ic_curchan
);
1335 /* turn radio LED on */
1337 rt2870_led_cmd(sc
, RT2870_LED_CMD_RADIO_ON
);
1339 rt2870_io_mcu_cmd(sc
, RT2870_IO_MCU_CMD_BOOT
,
1340 RT2870_REG_H2M_TOKEN_NO_INTR
, 0);
1342 /* set RTS threshold */
1344 rt2870_asic_update_rtsthreshold(sc
);
1348 rt2870_asic_update_txpower(sc
);
1350 /* set up protection mode */
1352 rt2870_asic_updateprot(sc
);
1354 /* clear key tables */
1356 rt2870_asic_clear_keytables(sc
);
1358 /* enable Tx/Rx DMA engine */
1360 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_SCHDMA_USB_CYC_CFG
);
1365 rt2870_io_mac_write(sc
, RT2870_REG_SCHDMA_USB_CYC_CFG
, tmp
);
1367 if ((sc
->mac_rev
& 0xffff) != 0x0101)
1368 rt2870_io_mac_write(sc
, RT2870_REG_TX_TXOP_CTRL_CFG
, 0x583f);
1370 rt2870_io_mac_write(sc
, RT2870_REG_SYS_CTRL
, RT2870_REG_TX_ENABLE
);
1372 for (ntries
= 0; ntries
< 200; ntries
++)
1374 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_SCHDMA_WPDMA_GLO_CFG
);
1375 if (!(tmp
& (RT2870_REG_TX_DMA_BUSY
| RT2870_REG_RX_DMA_BUSY
)))
1383 printf("%s: timeout waiting for DMA engine\n",
1384 device_get_nameunit(sc
->dev
));
1390 rt2870_io_mac_write(sc
, RT2870_REG_SCHDMA_WMM_TXOP0_CFG
, 0);
1391 rt2870_io_mac_write(sc
, RT2870_REG_SCHDMA_WMM_TXOP1_CFG
,
1394 tmp
|= RT2870_REG_TX_WB_DDONE
|
1395 RT2870_REG_RX_DMA_ENABLE
|
1396 RT2870_REG_TX_DMA_ENABLE
;
1398 rt2870_io_mac_write(sc
, RT2870_REG_SCHDMA_WPDMA_GLO_CFG
, tmp
);
1400 tmp
= RT2870_REG_USB_DMA_TX_ENABLE
|
1401 RT2870_REG_USB_DMA_RX_ENABLE
|
1402 RT2870_REG_USB_DMA_RX_AGG_ENABLE
|
1403 /* Rx agg limit in unit of 1024 byte */
1404 ((RT2870_USB_RX_BULK_BUFLEN
/ 1024 - 3) << RT2870_REG_USB_DMA_RX_AGG_LIMIT_SHIFT
) |
1405 /* Rx agg timeout in unit of 33ns */
1408 rt2870_io_mac_write(sc
, RT2870_REG_SCHDMA_USB_DMA_CFG
, tmp
);
1412 tmp
= RT2870_REG_RX_FILTER_DROP_CRC_ERR
|
1413 RT2870_REG_RX_FILTER_DROP_PHY_ERR
;
1415 if (ic
->ic_opmode
!= IEEE80211_M_MONITOR
)
1417 tmp
|= RT2870_REG_RX_FILTER_DROP_DUPL
|
1418 RT2870_REG_RX_FILTER_DROP_CTS
|
1419 RT2870_REG_RX_FILTER_DROP_BA
|
1420 RT2870_REG_RX_FILTER_DROP_ACK
|
1421 RT2870_REG_RX_FILTER_DROP_VER_ERR
|
1422 RT2870_REG_RX_FILTER_DROP_CTRL_RSV
|
1423 RT2870_REG_RX_FILTER_DROP_CFACK
|
1424 RT2870_REG_RX_FILTER_DROP_CFEND
;
1426 if (ic
->ic_opmode
== IEEE80211_M_STA
)
1427 tmp
|= RT2870_REG_RX_FILTER_DROP_RTS
|
1428 RT2870_REG_RX_FILTER_DROP_PSPOLL
;
1430 if (!(ifp
->if_flags
& IFF_PROMISC
))
1431 tmp
|= RT2870_REG_RX_FILTER_DROP_UC_NOME
;
1434 rt2870_io_mac_write(sc
, RT2870_REG_RX_FILTER_CFG
, tmp
);
1436 rt2870_io_mac_write(sc
, RT2870_REG_SYS_CTRL
,
1437 RT2870_REG_RX_ENABLE
| RT2870_REG_TX_ENABLE
);
1439 /* clear garbage interrupts */
1441 tmp
= rt2870_io_mac_read(sc
, 0x1300);
1443 taskqueue_unblock(sc
->taskqueue
);
1445 /* init Tx and Rx rings */
1447 for(i
= 0; i
< sc
->usb_endpoints
- 1; i
++)
1448 rt2870_reset_tx_ring(sc
, &sc
->tx_ring
[i
]);
1450 rt2870_reset_rx_ring(sc
, &sc
->rx_ring
);
1452 rt2870_reset_cmd_ring(sc
, &sc
->cmd_ring
);
1454 /* start up the receive pipe */
1456 for (i
= 0; i
< RT2870_SOFTC_RX_RING_DATA_COUNT
; i
++)
1458 data
= &sc
->rx_ring
.data
[i
];
1460 STAILQ_INSERT_TAIL(&sc
->rx_ring
.active
, data
, next
);
1462 usbd_setup_xfer(data
->xfer
, sc
->rx_ring
.usb_pipe
, sc
, data
->buf
,
1463 RT2870_USB_RX_BULK_BUFLEN
, USBD_SHORT_XFER_OK
| USBD_NO_COPY
,
1464 USBD_NO_TIMEOUT
, rt2870_rx_intr
);
1466 usbd_transfer(data
->xfer
);
1469 ifp
->if_drv_flags
&= ~IFF_DRV_OACTIVE
;
1470 ifp
->if_drv_flags
|= IFF_DRV_RUNNING
;
1472 if (ic
->ic_opmode
!= IEEE80211_M_MONITOR
)
1474 if (ic
->ic_roaming
!= IEEE80211_ROAMING_MANUAL
)
1475 ieee80211_new_state(ic
, IEEE80211_S_SCAN
, -1);
1479 ieee80211_new_state(ic
, IEEE80211_S_RUN
, -1);
1482 sc
->periodic_round
= 0;
1484 callout_reset(&sc
->periodic_ch
, hz
/ 10, rt2870_periodic
, sc
);
1490 rt2870_stop_locked(sc
);
1496 static void rt2870_init(void *priv
)
1498 struct rt2870_softc
*sc
;
1502 rt2870_init_locked(sc
);
1508 static int rt2870_init_bbp(struct rt2870_softc
*sc
)
1513 for (ntries
= 0; ntries
< 20; ntries
++)
1515 tmp
= rt2870_io_bbp_read(sc
, 0);
1516 if (tmp
!= 0x00 && tmp
!= 0xff)
1520 if (tmp
== 0x00 || tmp
== 0xff)
1522 printf("%s: timeout waiting for BBP to wakeup\n",
1523 device_get_nameunit(sc
->dev
));
1527 for (i
= 0; i
< RT2870_DEF_BBP_SIZE
; i
++)
1528 rt2870_io_bbp_write(sc
, rt2870_def_bbp
[i
].reg
,
1529 rt2870_def_bbp
[i
].val
);
1531 if ((sc
->mac_rev
& 0xffff) != 0x0101)
1532 rt2870_io_bbp_write(sc
, 84, 0x19);
1540 static void rt2870_stop_locked(void *priv
)
1542 struct rt2870_softc
*sc
;
1543 struct ieee80211com
*ic
;
1552 RT2870_DPRINTF(sc
, RT2870_DEBUG_ANY
,
1554 device_get_nameunit(sc
->dev
));
1558 if (ifp
->if_drv_flags
& IFF_DRV_RUNNING
)
1559 rt2870_led_cmd(sc
, RT2870_LED_CMD_RADIO_OFF
);
1561 ifp
->if_drv_flags
&= ~(IFF_DRV_RUNNING
| IFF_DRV_OACTIVE
);
1563 ieee80211_new_state(ic
, IEEE80211_S_INIT
, -1);
1565 callout_stop(&sc
->periodic_ch
);
1566 callout_stop(&sc
->tx_watchdog_ch
);
1568 taskqueue_block(sc
->taskqueue
);
1570 taskqueue_drain(sc
->taskqueue
, &sc
->rx_done_task
);
1571 taskqueue_drain(sc
->taskqueue
, &sc
->tx_done_task
);
1572 taskqueue_drain(sc
->taskqueue
, &sc
->periodic_task
);
1573 taskqueue_drain(sc
->taskqueue
, &sc
->cmd_task
);
1575 /* clear key tables */
1577 rt2870_asic_clear_keytables(sc
);
1581 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_SYS_CTRL
);
1583 tmp
&= ~(RT2870_REG_RX_ENABLE
| RT2870_REG_TX_ENABLE
);
1585 rt2870_io_mac_write(sc
, RT2870_REG_SYS_CTRL
, tmp
);
1587 rt2870_io_mac_write(sc
, RT2870_REG_SCHDMA_USB_DMA_CFG
, 0);
1591 rt2870_io_mac_write(sc
, RT2870_REG_SYS_CTRL
,
1592 RT2870_REG_MAC_SRST
| RT2870_REG_BBP_HRST
);
1593 rt2870_io_mac_write(sc
, RT2870_REG_SYS_CTRL
, 0);
1595 /* abort any pending transfers */
1597 if (sc
->rx_ring
.usb_pipe
!= NULL
)
1598 usbd_abort_pipe(sc
->rx_ring
.usb_pipe
);
1600 for (i
= 0; i
< sc
->usb_endpoints
- 1; i
++)
1601 if (sc
->tx_ring
[i
].usb_pipe
!= NULL
)
1602 usbd_abort_pipe(sc
->tx_ring
[i
].usb_pipe
);
1608 static void rt2870_stop(void *priv
)
1610 struct rt2870_softc
*sc
;
1614 rt2870_stop_locked(sc
);
1620 static void rt2870_start(struct ifnet
*ifp
)
1622 struct rt2870_softc
*sc
;
1623 struct ieee80211com
*ic
;
1624 struct ieee80211_node
*ni
;
1625 struct ether_header
*eh
;
1632 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
1637 IF_POLL(&ic
->ic_mgtq
, m
);
1640 if (sc
->tx_ring
[sc
->tx_ring_mgtqid
].queued
>= RT2870_SOFTC_TX_RING_DATA_COUNT
)
1642 RT2870_DPRINTF(sc
, RT2870_DEBUG_TX
,
1643 "%s: if_start: Tx ring with qid=%d is full\n",
1644 device_get_nameunit(sc
->dev
), sc
->tx_ring_mgtqid
);
1646 ifp
->if_drv_flags
|= IFF_DRV_OACTIVE
;
1650 IF_DEQUEUE(&ic
->ic_mgtq
, m
);
1652 ni
= (struct ieee80211_node
*) m
->m_pkthdr
.rcvif
;
1653 m
->m_pkthdr
.rcvif
= NULL
;
1655 if (bpf_peers_present(ic
->ic_rawbpf
))
1656 bpf_mtap(ic
->ic_rawbpf
, m
);
1658 if (rt2870_tx_frame(sc
, m
, ni
, sc
->tx_ring_mgtqid
) != 0)
1663 if (ic
->ic_state
!= IEEE80211_S_RUN
)
1666 IF_POLL(&ifp
->if_snd
, m
);
1670 IFQ_DRV_DEQUEUE(&ifp
->if_snd
, m
);
1672 if (ic
->ic_flags
& IEEE80211_F_SCAN
)
1673 ieee80211_cancel_scan(ic
);
1675 if (m
->m_len
< sizeof(struct ether_header
) &&
1676 !(m
= m_pullup(m
, sizeof (struct ether_header
))))
1679 eh
= mtod(m
, struct ether_header
*);
1681 ni
= ieee80211_find_txnode(ic
, eh
->ether_dhost
);
1684 RT2870_DPRINTF(sc
, RT2870_DEBUG_TX
,
1685 "%s: if_start: could not find Tx node\n",
1686 device_get_nameunit(sc
->dev
));
1692 ieee80211_classify(ic
, m
, ni
);
1694 qid
= M_WME_GETAC(m
);
1696 if (sc
->tx_ring
[qid
].queued
>= RT2870_SOFTC_TX_RING_DATA_COUNT
)
1698 RT2870_DPRINTF(sc
, RT2870_DEBUG_TX
,
1699 "%s: if_start: Tx ring with qid=%d is full\n",
1700 device_get_nameunit(sc
->dev
), qid
);
1703 ieee80211_free_node(ni
);
1704 ifp
->if_drv_flags
|= IFF_DRV_OACTIVE
;
1711 m
= ieee80211_encap(ic
, m
, ni
);
1714 ieee80211_free_node(ni
);
1719 if (bpf_peers_present(ic
->ic_rawbpf
))
1720 bpf_mtap(ic
->ic_rawbpf
, m
);
1722 if (rt2870_tx_frame(sc
, m
, ni
, qid
) != 0)
1724 ieee80211_free_node(ni
);
1725 ifp
->if_drv_flags
|= IFF_DRV_OACTIVE
;
1731 sc
->tx_timer
= RT2870_TX_WATCHDOG_TIMEOUT
;
1733 ic
->ic_lastdata
= ticks
;
1735 callout_reset(&sc
->tx_watchdog_ch
, hz
, rt2870_tx_watchdog
, sc
);
1742 static int rt2870_ioctl(struct ifnet
*ifp
, u_long cmd
, caddr_t data
)
1744 struct rt2870_softc
*sc
;
1745 struct ieee80211com
*ic
;
1756 if (ifp
->if_flags
& IFF_UP
)
1758 if (ifp
->if_drv_flags
& IFF_DRV_RUNNING
)
1760 if ((ifp
->if_flags
^ sc
->if_flags
) & IFF_PROMISC
)
1761 rt2870_asic_update_promisc(sc
);
1765 rt2870_init_locked(sc
);
1770 if (ifp
->if_drv_flags
& IFF_DRV_RUNNING
)
1771 rt2870_stop_locked(sc
);
1774 sc
->if_flags
= ifp
->if_flags
;
1778 error
= ieee80211_ioctl(ic
, cmd
, data
);
1781 if (error
== ENETRESET
)
1783 if ((ifp
->if_flags
& IFF_UP
) &&
1784 (ifp
->if_drv_flags
& IFF_DRV_RUNNING
) &&
1785 (ic
->ic_roaming
!= IEEE80211_ROAMING_MANUAL
))
1787 rt2870_stop_locked(sc
);
1788 rt2870_init_locked(sc
);
1800 static int rt2870_reset(struct ifnet
*ifp
)
1802 struct rt2870_softc
*sc
;
1803 struct ieee80211com
*ic
;
1808 if (ic
->ic_opmode
!= IEEE80211_M_MONITOR
)
1811 rt2870_rf_set_chan(sc
, ic
->ic_curchan
);
1819 static int rt2870_newstate(struct ieee80211com
*ic
,
1820 enum ieee80211_state nstate
, int arg
)
1822 struct rt2870_softc
*sc
;
1824 struct rt2870_cmd_argv_newstate cmd_argv
;
1829 cmd_argv
.nstate
= nstate
;
1832 rt2870_do_async(sc
, rt2870_newstate_cb
, &cmd_argv
,
1833 sizeof(struct rt2870_cmd_argv_newstate
));
1841 static void rt2870_scan_start(struct ieee80211com
*ic
)
1843 struct rt2870_softc
*sc
;
1849 rt2870_do_async(sc
, rt2870_scan_start_cb
, NULL
, 0);
1855 static void rt2870_scan_end(struct ieee80211com
*ic
)
1857 struct rt2870_softc
*sc
;
1863 rt2870_do_async(sc
, rt2870_scan_end_cb
, NULL
, 0);
1867 * rt2870_set_channel
1869 static void rt2870_set_channel(struct ieee80211com
*ic
)
1871 struct rt2870_softc
*sc
;
1877 rt2870_do_async(sc
, rt2870_set_channel_cb
, NULL
, 0);
1883 static void rt2870_newassoc(struct ieee80211_node
*ni
, int isnew
)
1885 struct rt2870_softc
*sc
;
1886 struct ieee80211com
*ic
;
1888 struct rt2870_cmd_argv_newassoc cmd_argv
;
1894 cmd_argv
.associd
= (ni
!= NULL
) ? ni
->ni_associd
: 0;
1895 cmd_argv
.isnew
= isnew
;
1896 memcpy(cmd_argv
.macaddr
, ni
->ni_macaddr
, IEEE80211_ADDR_LEN
);
1898 rt2870_do_async(sc
, rt2870_newassoc_cb
, &cmd_argv
,
1899 sizeof(struct rt2870_cmd_argv_newassoc
));
1905 static void rt2870_updateslot(struct ifnet
*ifp
)
1907 struct rt2870_softc
*sc
;
1911 rt2870_do_async(sc
, rt2870_updateslot_cb
, NULL
, 0);
1917 static int rt2870_wme_update(struct ieee80211com
*ic
)
1919 struct rt2870_softc
*sc
;
1925 rt2870_do_async(sc
, rt2870_wme_update_cb
, NULL
, 0);
1931 * rt2870_update_beacon
1933 static void rt2870_update_beacon(struct ieee80211com
*ic
, int what
)
1935 struct rt2870_softc
*sc
;
1937 struct rt2870_cmd_argv_updatebeacon cmd_argv
;
1942 cmd_argv
.what
= what
;
1944 rt2870_do_async(sc
, rt2870_update_beacon_cb
, &cmd_argv
,
1945 sizeof(struct rt2870_cmd_argv_updatebeacon
));
1949 * rt2870_key_update_begin
1951 static void rt2870_key_update_begin(struct ieee80211com
*ic
)
1953 struct rt2870_softc
*sc
;
1959 rt2870_do_async(sc
, rt2870_key_update_begin_cb
, NULL
, 0);
1963 * rt2870_key_update_end
1965 static void rt2870_key_update_end(struct ieee80211com
*ic
)
1967 struct rt2870_softc
*sc
;
1973 rt2870_do_async(sc
, rt2870_key_update_end_cb
, NULL
, 0);
1979 static int rt2870_key_set(struct ieee80211com
*ic
,
1980 const struct ieee80211_key
*k
, const uint8_t mac
[IEEE80211_ADDR_LEN
])
1982 struct rt2870_softc
*sc
;
1984 struct ieee80211_node
*ni
;
1985 struct rt2870_cmd_argv_keyset cmd_argv
;
1987 if (k
->wk_cipher
->ic_cipher
!= IEEE80211_CIPHER_WEP
&&
1988 k
->wk_cipher
->ic_cipher
!= IEEE80211_CIPHER_TKIP
&&
1989 k
->wk_cipher
->ic_cipher
!= IEEE80211_CIPHER_AES_CCM
)
1995 if (ic
->ic_opmode
!= IEEE80211_M_HOSTAP
)
1998 ni
= ieee80211_find_node(&ic
->ic_sta
, mac
);
2000 memcpy(&cmd_argv
.key
, k
, sizeof(struct ieee80211_key
));
2001 cmd_argv
.associd
= (ni
!= NULL
) ? ni
->ni_associd
: 0;
2003 if ((ic
->ic_opmode
== IEEE80211_M_HOSTAP
) && (ni
!= NULL
))
2004 ieee80211_free_node(ni
);
2006 rt2870_do_async(sc
, rt2870_key_set_cb
, &cmd_argv
,
2007 sizeof(struct rt2870_cmd_argv_keyset
));
2015 static int rt2870_key_delete(struct ieee80211com
*ic
,
2016 const struct ieee80211_key
*k
)
2018 struct rt2870_softc
*sc
;
2020 struct ieee80211_node
*ni
;
2021 struct rt2870_cmd_argv_keydelete cmd_argv
;
2027 memcpy(&cmd_argv
.key
, k
, sizeof(struct ieee80211_key
));
2028 cmd_argv
.associd
= (ni
!= NULL
) ? ni
->ni_associd
: 0;
2030 rt2870_do_async(sc
, rt2870_key_delete_cb
, &cmd_argv
,
2031 sizeof(struct rt2870_cmd_argv_keydelete
));
2039 static int rt2870_raw_xmit(struct ieee80211_node
*ni
, struct mbuf
*m
,
2040 const struct ieee80211_bpf_params
*params
)
2042 struct ieee80211com
*ic
;
2044 struct rt2870_softc
*sc
;
2054 * rt2870_media_change
2056 static int rt2870_media_change(struct ifnet
*ifp
)
2058 struct rt2870_softc
*sc
;
2063 error
= ieee80211_media_change(ifp
);
2064 if (error
!= ENETRESET
)
2067 if ((ifp
->if_flags
& IFF_UP
) && (ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
2077 * rt2870_recv_action
2079 static void rt2870_recv_action(struct ieee80211_node
*ni
,
2080 const uint8_t *frm
, const uint8_t *efrm
)
2082 struct rt2870_softc
*sc
;
2083 struct ieee80211com
*ic
;
2085 const struct ieee80211_action
*ia
;
2086 uint16_t associd
, baparamset
;
2095 ia
= (const struct ieee80211_action
*) frm
;
2097 sc
->recv_action(ni
, frm
, efrm
);
2099 if (ia
->ia_category
!= IEEE80211_ACTION_CAT_BA
)
2102 associd
= (ni
!= NULL
) ? ni
->ni_associd
: 0;
2103 wcid
= RT2870_AID2WCID(associd
);
2105 switch (ia
->ia_action
)
2107 /* IEEE80211_ACTION_BA_ADDBA_REQUEST */
2108 case IEEE80211_ACTION_BA_ADDBA_REQUEST
:
2109 baparamset
= LE_READ_2(frm
+ 3);
2110 tid
= RT2870_MS(baparamset
, IEEE80211_BAPS_TID
);
2112 RT2870_DPRINTF(sc
, RT2870_DEBUG_BA
,
2113 "%s: adding A-MPDU Rx block ACK: associd=0x%04x, tid=%d\n",
2114 device_get_nameunit(sc
->dev
), associd
, tid
);
2116 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_WCID(wcid
) + 4);
2118 tmp
|= (0x10000 << tid
);
2120 rt2870_io_mac_write(sc
, RT2870_REG_WCID(wcid
) + 4, tmp
);
2123 /* IEEE80211_ACTION_BA_DELBA */
2124 case IEEE80211_ACTION_BA_DELBA
:
2125 baparamset
= LE_READ_2(frm
+ 2);
2126 tid
= RT2870_MS(baparamset
, IEEE80211_BAPS_TID
);
2128 RT2870_DPRINTF(sc
, RT2870_DEBUG_BA
,
2129 "%s: deleting A-MPDU Rx block ACK: associd=0x%04x, tid=%d\n",
2130 device_get_nameunit(sc
->dev
), associd
, tid
);
2132 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_WCID(wcid
) + 4);
2134 tmp
&= ~(0x10000 << tid
);
2136 rt2870_io_mac_write(sc
, RT2870_REG_WCID(wcid
) + 4, tmp
);
2142 * rt2870_send_action
2144 static int rt2870_send_action(struct ieee80211_node
*ni
,
2145 int category
, int action
, uint16_t args
[4])
2147 struct rt2870_softc
*sc
;
2148 struct ieee80211com
*ic
;
2150 uint16_t associd
, baparamset
;
2159 ret
= sc
->send_action(ni
, category
, action
, args
);
2161 if (category
!= IEEE80211_ACTION_CAT_BA
)
2164 associd
= (ni
!= NULL
) ? ni
->ni_associd
: 0;
2165 wcid
= RT2870_AID2WCID(associd
);
2169 /* IEEE80211_ACTION_BA_DELBA */
2170 case IEEE80211_ACTION_BA_DELBA
:
2171 baparamset
= RT2870_SM(args
[0], IEEE80211_DELBAPS_TID
) |
2172 RT2870_SM(args
[1], IEEE80211_DELBAPS_INIT
);
2174 if (RT2870_MS(baparamset
, IEEE80211_DELBAPS_INIT
) == IEEE80211_DELBAPS_INIT
)
2177 tid
= RT2870_MS(baparamset
, IEEE80211_DELBAPS_TID
);
2179 RT2870_DPRINTF(sc
, RT2870_DEBUG_BA
,
2180 "%s: deleting A-MPDU Rx block ACK: associd=0x%04x, tid=%d\n",
2181 device_get_nameunit(sc
->dev
), associd
, tid
);
2183 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_WCID(wcid
) + 4);
2185 tmp
&= ~(0x10000 << tid
);
2187 rt2870_io_mac_write(sc
, RT2870_REG_WCID(wcid
) + 4, tmp
);
2195 * rt2870_amrr_update_iter_func
2197 static void rt2870_amrr_update_iter_func(void *arg
, struct ieee80211_node
*ni
)
2199 struct rt2870_softc
*sc
;
2200 struct ieee80211com
*ic
;
2206 /* only associated stations */
2208 if (ni
->ni_associd
!= 0)
2210 wcid
= RT2870_AID2WCID(ni
->ni_associd
);
2212 rt2870_amrr_choose(ni
, &sc
->amrr_node
[wcid
]);
2214 RT2870_DPRINTF(sc
, RT2870_DEBUG_RATE
,
2215 "%s:%s node Tx rate: associd=0x%04x, rate=0x%02x, max rate=0x%02x\n",
2216 device_get_nameunit(sc
->dev
),
2217 (ni
->ni_flags
& IEEE80211_NODE_HT
) ? " HT" : "",
2219 (ni
->ni_flags
& IEEE80211_NODE_HT
) ?
2220 (ni
->ni_htrates
.rs_rates
[ni
->ni_txrate
] | IEEE80211_RATE_MCS
) :
2221 (ni
->ni_rates
.rs_rates
[ni
->ni_txrate
] & IEEE80211_RATE_VAL
),
2222 (ni
->ni_flags
& IEEE80211_NODE_HT
) ?
2223 (ni
->ni_htrates
.rs_rates
[ni
->ni_htrates
.rs_nrates
- 1] | IEEE80211_RATE_MCS
) :
2224 (ni
->ni_rates
.rs_rates
[ni
->ni_rates
.rs_nrates
- 1] & IEEE80211_RATE_VAL
));
2231 static void rt2870_periodic(void *arg
)
2233 struct rt2870_softc
*sc
;
2239 RT2870_DPRINTF(sc
, RT2870_DEBUG_PERIODIC
,
2241 device_get_nameunit(sc
->dev
));
2243 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
2246 taskqueue_enqueue(sc
->taskqueue
, &sc
->periodic_task
);
2250 * rt2870_tx_watchdog
2252 static void rt2870_tx_watchdog(void *arg
)
2254 struct rt2870_softc
*sc
;
2260 if (sc
->tx_timer
== 0)
2263 if (--sc
->tx_timer
== 0)
2265 printf("%s: Tx watchdog timeout: resetting\n",
2266 device_get_nameunit(sc
->dev
));
2268 rt2870_stop_locked(sc
);
2269 rt2870_init_locked(sc
);
2273 sc
->tx_watchdog_timeouts
++;
2276 callout_reset(&sc
->tx_watchdog_ch
, hz
, rt2870_tx_watchdog
, sc
);
2282 static int rt2870_do_async(struct rt2870_softc
*sc
,
2283 void (*cb
)(struct rt2870_softc
*sc
, void *arg
),
2287 struct rt2870_softc_cmd_ring
*ring
;
2288 struct rt2870_softc_cmd
*cmd
;
2292 ring
= &sc
->cmd_ring
;
2294 RT2870_SOFTC_LOCK(sc
);
2296 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
2298 RT2870_SOFTC_UNLOCK(sc
);
2302 if (ring
->queued
>= RT2870_SOFTC_CMD_RING_CMD_COUNT
)
2304 RT2870_SOFTC_UNLOCK(sc
);
2308 cmd
= STAILQ_FIRST(&ring
->inactive
);
2309 STAILQ_REMOVE_HEAD(&ring
->inactive
, next
);
2314 memcpy(cmd
->data
, arg
, len
);
2316 STAILQ_INSERT_TAIL(&ring
->active
, cmd
, next
);
2319 run_cmd_task
= (ring
->queued
== 1);
2321 RT2870_SOFTC_UNLOCK(sc
);
2324 taskqueue_enqueue(sc
->taskqueue
, &sc
->cmd_task
);
2330 * rt2870_newstate_cb
2332 static void rt2870_newstate_cb(struct rt2870_softc
*sc
, void *arg
)
2334 struct ieee80211com
*ic
;
2335 enum ieee80211_state nstate
;
2336 struct ieee80211_node
*ni
;
2337 struct rt2870_cmd_argv_newstate
*cmd_argv
;
2342 nstate
= cmd_argv
->nstate
;
2344 RT2870_DPRINTF(sc
, RT2870_DEBUG_STATE
,
2345 "%s: newstate: %s -> %s\n",
2346 device_get_nameunit(sc
->dev
),
2347 ieee80211_state_name
[ic
->ic_state
], ieee80211_state_name
[nstate
]);
2349 error
= sc
->newstate(ic
, nstate
, cmd_argv
->arg
);
2353 /* turn link LED off */
2355 if (nstate
!= IEEE80211_S_RUN
)
2356 rt2870_led_cmd(sc
, RT2870_LED_CMD_RADIO_OFF
);
2360 case IEEE80211_S_INIT
:
2361 rt2870_asic_disable_tsf_sync(sc
);
2364 case IEEE80211_S_RUN
:
2367 if (ic
->ic_opmode
!= IEEE80211_M_MONITOR
)
2369 rt2870_asic_enable_mrr(sc
);
2370 rt2870_asic_set_txpreamble(sc
);
2371 rt2870_asic_set_basicrates(sc
);
2372 rt2870_asic_set_bssid(sc
, ni
->ni_bssid
);
2375 if (ic
->ic_opmode
== IEEE80211_M_STA
)
2376 rt2870_newassoc(ni
, 1);
2378 if (ic
->ic_opmode
== IEEE80211_M_HOSTAP
||
2379 ic
->ic_opmode
== IEEE80211_M_IBSS
)
2381 error
= rt2870_asic_update_beacon(sc
);
2386 if (ic
->ic_opmode
!= IEEE80211_M_MONITOR
)
2387 rt2870_asic_enable_tsf_sync(sc
);
2389 /* turn link LED on */
2391 if (ic
->ic_opmode
!= IEEE80211_M_MONITOR
)
2393 rt2870_led_cmd(sc
, RT2870_LED_CMD_RADIO_ON
|
2394 (IEEE80211_IS_CHAN_2GHZ(ni
->ni_chan
) ?
2395 RT2870_LED_CMD_LINK_2GHZ
: RT2870_LED_CMD_LINK_5GHZ
));
2405 * rt2870_scan_start_cb
2407 static void rt2870_scan_start_cb(struct rt2870_softc
*sc
, void *arg
)
2409 struct ieee80211com
*ic
;
2415 rt2870_asic_disable_tsf_sync(sc
);
2419 * rt2870_scan_end_cb
2421 static void rt2870_scan_end_cb(struct rt2870_softc
*sc
, void *arg
)
2423 struct ieee80211com
*ic
;
2424 struct ieee80211_node
*ni
;
2429 rt2870_asic_enable_tsf_sync(sc
);
2433 * rt2870_set_channel_cb
2435 static void rt2870_set_channel_cb(struct rt2870_softc
*sc
, void *arg
)
2437 struct ieee80211com
*ic
;
2441 RT2870_DPRINTF(sc
, RT2870_DEBUG_CHAN
,
2442 "%s: set channel: channel=%u, HT%s%s\n",
2443 device_get_nameunit(sc
->dev
),
2444 ieee80211_chan2ieee(ic
, ic
->ic_curchan
),
2445 !IEEE80211_IS_CHAN_HT(ic
->ic_curchan
) ? " disabled" :
2446 IEEE80211_IS_CHAN_HT20(ic
->ic_curchan
) ? "20":
2447 IEEE80211_IS_CHAN_HT40U(ic
->ic_curchan
) ? "40U" : "40D",
2448 (ic
->ic_flags
& IEEE80211_F_SCAN
) ? ", scanning" : "");
2450 rt2870_rf_set_chan(sc
, ic
->ic_curchan
);
2454 * rt2870_newassoc_cb
2456 static void rt2870_newassoc_cb(struct rt2870_softc
*sc
, void *arg
)
2458 struct ieee80211com
*ic
;
2459 struct ieee80211_node
*ni
;
2460 struct rt2870_cmd_argv_newassoc
*cmd_argv
;
2463 uint8_t *macaddr
, wcid
;
2468 associd
= cmd_argv
->associd
;
2469 isnew
= cmd_argv
->isnew
;
2470 macaddr
= cmd_argv
->macaddr
;
2472 wcid
= RT2870_AID2WCID(associd
);
2474 RT2870_DPRINTF(sc
, RT2870_DEBUG_NODE
,
2475 "%s: new association: wcid=0x%02x, "
2476 "mac addr=%s, QoS %s, ERP %s, HT %s\n",
2477 device_get_nameunit(sc
->dev
), wcid
,
2478 ether_sprintf(macaddr
),
2479 (ni
->ni_flags
& IEEE80211_NODE_QOS
) ? "enabled" : "disabled",
2480 (ni
->ni_flags
& IEEE80211_NODE_ERP
) ? "enabled" : "disabled",
2481 (ni
->ni_flags
& IEEE80211_NODE_HT
) ? "enabled" : "disabled");
2483 rt2870_io_mac_write_multi(sc
, RT2870_REG_WCID(wcid
),
2484 macaddr
, IEEE80211_ADDR_LEN
);
2486 rt2870_amrr_node_init(&sc
->amrr
, &sc
->amrr_node
[wcid
], ni
);
2488 RT2870_DPRINTF(sc
, RT2870_DEBUG_RATE
,
2489 "%s: initial%s node Tx rate: associd=0x%04x, rate=0x%02x, max rate=0x%02x\n",
2490 device_get_nameunit(sc
->dev
),
2491 (ni
->ni_flags
& IEEE80211_NODE_HT
) ? " HT" : "",
2493 (ni
->ni_flags
& IEEE80211_NODE_HT
) ?
2494 (ni
->ni_htrates
.rs_rates
[ni
->ni_txrate
] | IEEE80211_RATE_MCS
) :
2495 (ni
->ni_rates
.rs_rates
[ni
->ni_txrate
] & IEEE80211_RATE_VAL
),
2496 (ni
->ni_flags
& IEEE80211_NODE_HT
) ?
2497 (ni
->ni_htrates
.rs_rates
[ni
->ni_htrates
.rs_nrates
- 1] | IEEE80211_RATE_MCS
) :
2498 (ni
->ni_rates
.rs_rates
[ni
->ni_rates
.rs_nrates
- 1] & IEEE80211_RATE_VAL
));
2500 rt2870_asic_updateprot(sc
);
2501 rt2870_asic_updateslot(sc
);
2502 rt2870_asic_set_txpreamble(sc
);
2506 * rt2870_updateslot_cb
2508 static void rt2870_updateslot_cb(struct rt2870_softc
*sc
, void *arg
)
2510 rt2870_asic_updateslot(sc
);
2514 * rt2870_wme_update_cb
2516 static void rt2870_wme_update_cb(struct rt2870_softc
*sc
, void *arg
)
2518 rt2870_asic_wme_update(sc
);
2522 * rt2870_update_beacon_cb
2524 static void rt2870_update_beacon_cb(struct rt2870_softc
*sc
, void *arg
)
2526 struct rt2870_cmd_argv_updatebeacon
*cmd_argv
;
2530 RT2870_DPRINTF(sc
, RT2870_DEBUG_BEACON
,
2531 "%s: update beacon\n",
2532 device_get_nameunit(sc
->dev
));
2534 rt2870_asic_update_beacon(sc
);
2538 * rt2870_key_update_begin_cb
2540 static void rt2870_key_update_begin_cb(struct rt2870_softc
*sc
, void *arg
)
2546 RT2870_DPRINTF(sc
, RT2870_DEBUG_KEY
,
2547 "%s: key update begin\n",
2548 device_get_nameunit(sc
->dev
));
2550 taskqueue_block(sc
->taskqueue
);
2552 IF_LOCK(&ifp
->if_snd
);
2556 * rt2870_key_update_end_cb
2558 static void rt2870_key_update_end_cb(struct rt2870_softc
*sc
, void *arg
)
2564 RT2870_DPRINTF(sc
, RT2870_DEBUG_KEY
,
2565 "%s: key update end\n",
2566 device_get_nameunit(sc
->dev
));
2568 IF_UNLOCK(&ifp
->if_snd
);
2570 taskqueue_unblock(sc
->taskqueue
);
2576 static void rt2870_key_set_cb(struct rt2870_softc
*sc
, void *arg
)
2578 struct ieee80211com
*ic
;
2579 struct ieee80211_key
*k
;
2580 struct rt2870_cmd_argv_keyset
*cmd_argv
;
2581 uint16_t associd
, key_base
, keymode_base
;
2582 uint8_t mode
, vapid
, wcid
, iv
[8];
2588 associd
= cmd_argv
->associd
;
2590 switch (k
->wk_cipher
->ic_cipher
)
2592 case IEEE80211_CIPHER_WEP
:
2593 if(k
->wk_keylen
< 8)
2594 mode
= RT2870_REG_CIPHER_MODE_WEP40
;
2596 mode
= RT2870_REG_CIPHER_MODE_WEP104
;
2599 case IEEE80211_CIPHER_TKIP
:
2600 mode
= RT2870_REG_CIPHER_MODE_TKIP
;
2603 case IEEE80211_CIPHER_AES_CCM
:
2604 mode
= RT2870_REG_CIPHER_MODE_AES_CCMP
;
2611 RT2870_DPRINTF(sc
, RT2870_DEBUG_KEY
,
2612 "%s: set key: keyix=%d, keylen=%d, associd=0x%04x, mode=%d, group=%d\n",
2613 device_get_nameunit(sc
->dev
), k
->wk_keyix
, k
->wk_keylen
, associd
, mode
,
2614 (k
->wk_flags
& IEEE80211_KEY_GROUP
) ? 1 : 0);
2616 if (!(k
->wk_flags
& IEEE80211_KEY_GROUP
))
2618 /* install pairwise key */
2621 wcid
= RT2870_AID2WCID(associd
);
2622 key_base
= RT2870_REG_PKEY(wcid
);
2624 if (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_WEP
)
2628 iv
[3] = (k
->wk_keyix
<< 6);
2632 if (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_TKIP
)
2634 iv
[0] = (k
->wk_keytsc
>> 8);
2635 iv
[1] = ((iv
[0] | 0x20) & 0x7f);
2636 iv
[2] = k
->wk_keytsc
;
2642 iv
[0] = k
->wk_keytsc
;
2643 iv
[1] = k
->wk_keytsc
>> 8;
2647 iv
[3] = ((k
->wk_keyix
<< 6) | IEEE80211_WEP_EXTIV
);
2648 iv
[4] = (k
->wk_keytsc
>> 16);
2649 iv
[5] = (k
->wk_keytsc
>> 24);
2650 iv
[6] = (k
->wk_keytsc
>> 32);
2651 iv
[7] = (k
->wk_keytsc
>> 40);
2653 RT2870_DPRINTF(sc
, RT2870_DEBUG_KEY
,
2654 "%s: set key: iv=%02x %02x %02x %02x %02x %02x %02x %02x\n",
2655 device_get_nameunit(sc
->dev
),
2656 iv
[0], iv
[1], iv
[2], iv
[3], iv
[4], iv
[5], iv
[6], iv
[7]);
2659 rt2870_io_mac_write_multi(sc
, RT2870_REG_IVEIV(wcid
), iv
, 8);
2661 if (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_TKIP
)
2663 rt2870_io_mac_write_multi(sc
, key_base
, k
->wk_key
, 16);
2665 if (ic
->ic_opmode
!= IEEE80211_M_HOSTAP
)
2667 rt2870_io_mac_write_multi(sc
, key_base
+ 16, &k
->wk_key
[16], 8);
2668 rt2870_io_mac_write_multi(sc
, key_base
+ 24, &k
->wk_key
[24], 8);
2672 rt2870_io_mac_write_multi(sc
, key_base
+ 16, &k
->wk_key
[24], 8);
2673 rt2870_io_mac_write_multi(sc
, key_base
+ 24, &k
->wk_key
[16], 8);
2678 rt2870_io_mac_write_multi(sc
, key_base
, k
->wk_key
, k
->wk_keylen
);
2681 tmp
= ((vapid
& RT2870_REG_VAP_MASK
) << RT2870_REG_VAP_SHIFT
) |
2682 (mode
<< RT2870_REG_CIPHER_MODE_SHIFT
) | RT2870_REG_PKEY_ENABLE
;
2684 rt2870_io_mac_write(sc
, RT2870_REG_WCID_ATTR(wcid
), tmp
);
2687 if ((k
->wk_flags
& IEEE80211_KEY_GROUP
) ||
2688 (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_WEP
))
2690 /* install group key */
2693 key_base
= RT2870_REG_SKEY(vapid
, k
->wk_keyix
);
2694 keymode_base
= RT2870_REG_SKEY_MODE(vapid
);
2696 if (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_TKIP
)
2698 rt2870_io_mac_write_multi(sc
, key_base
, k
->wk_key
, 16);
2700 if (ic
->ic_opmode
!= IEEE80211_M_HOSTAP
)
2702 rt2870_io_mac_write_multi(sc
, key_base
+ 16, &k
->wk_key
[16], 8);
2703 rt2870_io_mac_write_multi(sc
, key_base
+ 24, &k
->wk_key
[24], 8);
2707 rt2870_io_mac_write_multi(sc
, key_base
+ 16, &k
->wk_key
[24], 8);
2708 rt2870_io_mac_write_multi(sc
, key_base
+ 24, &k
->wk_key
[16], 8);
2713 rt2870_io_mac_write_multi(sc
, key_base
, k
->wk_key
, k
->wk_keylen
);
2716 tmp
= rt2870_io_mac_read(sc
, keymode_base
);
2718 tmp
&= ~(0xf << (k
->wk_keyix
* 4 + 16 * (vapid
% 2)));
2719 tmp
|= (mode
<< (k
->wk_keyix
* 4 + 16 * (vapid
% 2)));
2721 rt2870_io_mac_write(sc
, keymode_base
, tmp
);
2726 * rt2870_key_delete_cb
2728 static void rt2870_key_delete_cb(struct rt2870_softc
*sc
, void *arg
)
2730 struct ieee80211com
*ic
;
2731 struct ieee80211_key
*k
;
2732 struct rt2870_cmd_argv_keydelete
*cmd_argv
;
2734 uint8_t vapid
, wcid
;
2740 associd
= cmd_argv
->associd
;
2742 RT2870_DPRINTF(sc
, RT2870_DEBUG_KEY
,
2743 "%s: delete key: keyix=%d, keylen=%d, associd=0x%04x, group=%d\n",
2744 device_get_nameunit(sc
->dev
), k
->wk_keyix
, k
->wk_keylen
, associd
,
2745 (k
->wk_flags
& IEEE80211_KEY_GROUP
) ? 1 : 0);
2747 if (!(k
->wk_flags
& IEEE80211_KEY_GROUP
))
2749 /* remove pairwise key */
2751 wcid
= RT2870_AID2WCID(associd
);
2753 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_WCID_ATTR(wcid
));
2756 tmp
|= (RT2870_REG_CIPHER_MODE_NONE
<< RT2870_REG_CIPHER_MODE_SHIFT
);
2758 rt2870_io_mac_write(sc
, RT2870_REG_WCID_ATTR(wcid
), tmp
);
2762 /* remove group key */
2766 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_SKEY_MODE(vapid
));
2768 tmp
&= ~(0xf << (k
->wk_keyix
* 4 + 16 * (vapid
% 2)));
2769 tmp
|= (RT2870_REG_CIPHER_MODE_NONE
<< (k
->wk_keyix
* 4 + 16 * (vapid
% 2)));
2771 rt2870_io_mac_write(sc
, RT2870_REG_SKEY_MODE(vapid
), tmp
);
2776 * rt2870_asic_set_bssid
2778 static void rt2870_asic_set_bssid(struct rt2870_softc
*sc
,
2779 const uint8_t *bssid
)
2783 RT2870_DPRINTF(sc
, RT2870_DEBUG_STATE
,
2784 "%s: set bssid: bssid=%s\n",
2785 device_get_nameunit(sc
->dev
), ether_sprintf(bssid
));
2787 tmp
= bssid
[0] | (bssid
[1]) << 8 | (bssid
[2] << 16) | (bssid
[3] << 24);
2789 rt2870_io_mac_write(sc
, RT2870_REG_BSSID_DW0
, tmp
);
2791 tmp
= bssid
[4] | (bssid
[5] << 8);
2793 rt2870_io_mac_write(sc
, RT2870_REG_BSSID_DW1
, tmp
);
2797 * rt2870_asic_set_macaddr
2799 static void rt2870_asic_set_macaddr(struct rt2870_softc
*sc
,
2800 const uint8_t *addr
)
2804 tmp
= addr
[0] | (addr
[1] << 8) | (addr
[2] << 16) | (addr
[3] << 24);
2806 rt2870_io_mac_write(sc
, RT2870_REG_ADDR_DW0
, tmp
);
2808 tmp
= addr
[4] | (addr
[5] << 8);
2810 rt2870_io_mac_write(sc
, RT2870_REG_ADDR_DW1
, tmp
);
2814 * rt2870_asic_enable_tsf_sync
2816 static void rt2870_asic_enable_tsf_sync(struct rt2870_softc
*sc
)
2818 struct ieee80211com
*ic
;
2823 RT2870_DPRINTF(sc
, RT2870_DEBUG_BEACON
,
2824 "%s: enabling TSF\n",
2825 device_get_nameunit(sc
->dev
));
2827 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_BCN_TIME_CFG
);
2830 tmp
|= ic
->ic_bss
->ni_intval
* 16;
2831 tmp
|= (RT2870_REG_TSF_TIMER_ENABLE
| RT2870_REG_TBTT_TIMER_ENABLE
);
2833 if (ic
->ic_opmode
== IEEE80211_M_STA
)
2835 tmp
|= (RT2870_REG_TSF_SYNC_MODE_STA
<< RT2870_REG_TSF_SYNC_MODE_SHIFT
);
2837 else if (ic
->ic_opmode
== IEEE80211_M_IBSS
)
2839 tmp
|= RT2870_REG_BCN_TX_ENABLE
;
2840 tmp
|= (RT2870_REG_TSF_SYNC_MODE_IBSS
<< RT2870_REG_TSF_SYNC_MODE_SHIFT
);
2842 else if (ic
->ic_opmode
== IEEE80211_M_HOSTAP
)
2844 tmp
|= RT2870_REG_BCN_TX_ENABLE
;
2845 tmp
|= (RT2870_REG_TSF_SYNC_MODE_HOSTAP
<< RT2870_REG_TSF_SYNC_MODE_SHIFT
);
2848 rt2870_io_mac_write(sc
, RT2870_REG_BCN_TIME_CFG
, tmp
);
2852 * rt2870_asic_disable_tsf_sync
2854 static void rt2870_asic_disable_tsf_sync(struct rt2870_softc
*sc
)
2858 RT2870_DPRINTF(sc
, RT2870_DEBUG_BEACON
,
2859 "%s: disabling TSF\n",
2860 device_get_nameunit(sc
->dev
));
2862 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_BCN_TIME_CFG
);
2864 tmp
&= ~(RT2870_REG_BCN_TX_ENABLE
|
2865 RT2870_REG_TSF_TIMER_ENABLE
|
2866 RT2870_REG_TBTT_TIMER_ENABLE
);
2868 tmp
&= ~(RT2870_REG_TSF_SYNC_MODE_MASK
<< RT2870_REG_TSF_SYNC_MODE_SHIFT
);
2869 tmp
|= (RT2870_REG_TSF_SYNC_MODE_DISABLE
<< RT2870_REG_TSF_SYNC_MODE_SHIFT
);
2871 rt2870_io_mac_write(sc
, RT2870_REG_BCN_TIME_CFG
, tmp
);
2875 * rt2870_asic_enable_mrr
2877 static void rt2870_asic_enable_mrr(struct rt2870_softc
*sc
)
2879 #define CCK(mcs) (mcs)
2880 #define OFDM(mcs) ((1 << 3) | (mcs))
2881 #define HT(mcs) (mcs)
2883 rt2870_io_mac_write(sc
, RT2870_REG_TX_LG_FBK_CFG0
,
2884 (OFDM(6) << 28) | /* 54 -> 48 */
2885 (OFDM(5) << 24) | /* 48 -> 36 */
2886 (OFDM(4) << 20) | /* 36 -> 24 */
2887 (OFDM(3) << 16) | /* 24 -> 18 */
2888 (OFDM(2) << 12) | /* 18 -> 12 */
2889 (OFDM(1) << 8) | /* 12 -> 9 */
2890 (OFDM(0) << 4) | /* 9 -> 6 */
2891 OFDM(0)); /* 6 -> 6 */
2893 rt2870_io_mac_write(sc
, RT2870_REG_TX_LG_FBK_CFG1
,
2894 (CCK(2) << 12) | /* 11 -> 5.5 */
2895 (CCK(1) << 8) | /* 5.5 -> 2 */
2896 (CCK(0) << 4) | /* 2 -> 1 */
2897 CCK(0)); /* 1 -> 1 */
2899 rt2870_io_mac_write(sc
, RT2870_REG_TX_HT_FBK_CFG0
,
2909 rt2870_io_mac_write(sc
, RT2870_REG_TX_HT_FBK_CFG1
,
2925 * rt2870_asic_set_txpreamble
2927 static void rt2870_asic_set_txpreamble(struct rt2870_softc
*sc
)
2929 struct ieee80211com
*ic
;
2934 RT2870_DPRINTF(sc
, RT2870_DEBUG_STATE
,
2935 "%s: %s short Tx preamble\n",
2936 device_get_nameunit(sc
->dev
),
2937 (ic
->ic_flags
& IEEE80211_F_SHPREAMBLE
) ? "enabling" : "disabling");
2939 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_AUTO_RSP_CFG
);
2941 tmp
&= ~RT2870_REG_CCK_SHORT_ENABLE
;
2943 if (ic
->ic_flags
& IEEE80211_F_SHPREAMBLE
)
2944 tmp
|= RT2870_REG_CCK_SHORT_ENABLE
;
2946 rt2870_io_mac_write(sc
, RT2870_REG_AUTO_RSP_CFG
, tmp
);
2950 * rt2870_asic_set_basicrates
2952 static void rt2870_asic_set_basicrates(struct rt2870_softc
*sc
)
2954 struct ieee80211com
*ic
;
2958 if (ic
->ic_curmode
== IEEE80211_MODE_11B
)
2959 rt2870_io_mac_write(sc
, RT2870_REG_LEGACY_BASIC_RATE
, 0x3);
2960 else if (ic
->ic_curmode
== IEEE80211_MODE_11A
)
2961 rt2870_io_mac_write(sc
, RT2870_REG_LEGACY_BASIC_RATE
, 0x150);
2963 rt2870_io_mac_write(sc
, RT2870_REG_LEGACY_BASIC_RATE
, 0x15f);
2967 * rt2870_asic_update_rtsthreshold
2969 static void rt2870_asic_update_rtsthreshold(struct rt2870_softc
*sc
)
2971 struct ieee80211com
*ic
;
2977 RT2870_DPRINTF(sc
, RT2870_DEBUG_PROT
,
2978 "%s: updating RTS threshold: %d\n",
2979 device_get_nameunit(sc
->dev
), ic
->ic_rtsthreshold
);
2981 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_TX_RTS_CFG
);
2983 tmp
&= ~(RT2870_REG_TX_RTS_THRESHOLD_MASK
<< RT2870_REG_TX_RTS_THRESHOLD_SHIFT
);
2985 threshold
= (ic
->ic_rtsthreshold
< IEEE80211_RTS_MAX
) ?
2986 ic
->ic_rtsthreshold
: 0x1000;
2988 tmp
|= ((threshold
& RT2870_REG_TX_RTS_THRESHOLD_MASK
) <<
2989 RT2870_REG_TX_RTS_THRESHOLD_SHIFT
);
2991 rt2870_io_mac_write(sc
, RT2870_REG_TX_RTS_CFG
, tmp
);
2995 * rt2870_asic_update_txpower
2997 static void rt2870_asic_update_txpower(struct rt2870_softc
*sc
)
2999 struct ieee80211com
*ic
;
3000 uint32_t *txpow_rate
;
3008 RT2870_DPRINTF(sc
, RT2870_DEBUG_STATE
,
3009 "%s: updating Tx power: %d\n",
3010 device_get_nameunit(sc
->dev
), ic
->ic_txpowlimit
);
3012 if (!IEEE80211_IS_CHAN_HT40(ic
->ic_curchan
))
3014 txpow_rate
= sc
->txpow_rate_20mhz
;
3018 if (IEEE80211_IS_CHAN_2GHZ(ic
->ic_curchan
))
3019 txpow_rate
= sc
->txpow_rate_40mhz_2ghz
;
3021 txpow_rate
= sc
->txpow_rate_40mhz_5ghz
;
3026 val
= rt2870_io_bbp_read(sc
, 1);
3029 if (ic
->ic_txpowlimit
> 90)
3033 else if (ic
->ic_txpowlimit
> 60)
3037 else if (ic
->ic_txpowlimit
> 30)
3041 else if (ic
->ic_txpowlimit
> 15)
3045 else if (ic
->ic_txpowlimit
> 9)
3055 rt2870_io_bbp_write(sc
, 1, val
);
3057 for (i
= 0; i
< RT2870_SOFTC_TXPOW_RATE_COUNT
; i
++)
3059 if (txpow_rate
[i
] == 0xffffffff)
3062 tmp
= rt2870_read_eeprom_txpow_rate_add_delta(txpow_rate
[i
], delta
);
3064 rt2870_io_mac_write(sc
, RT2870_REG_TX_PWR_CFG(i
), tmp
);
3069 * rt2870_asic_update_promisc
3071 static void rt2870_asic_update_promisc(struct rt2870_softc
*sc
)
3076 ifp
= sc
->ic
.ic_ifp
;
3078 printf("%s: %s promiscuous mode\n",
3079 device_get_nameunit(sc
->dev
),
3080 (ifp
->if_flags
& IFF_PROMISC
) ? "entering" : "leaving");
3082 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_RX_FILTER_CFG
);
3084 tmp
&= ~RT2870_REG_RX_FILTER_DROP_UC_NOME
;
3086 if (!(ifp
->if_flags
& IFF_PROMISC
))
3087 tmp
|= RT2870_REG_RX_FILTER_DROP_UC_NOME
;
3089 rt2870_io_mac_write(sc
, RT2870_REG_RX_FILTER_CFG
, tmp
);
3093 * rt2870_asic_updateprot
3095 static void rt2870_asic_updateprot(struct rt2870_softc
*sc
)
3097 struct ieee80211com
*ic
;
3098 uint32_t cck_prot
, ofdm_prot
, mm20_prot
, mm40_prot
, gf20_prot
, gf40_prot
;
3103 /* CCK frame protection */
3105 cck_prot
= RT2870_REG_RTSTH_ENABLE
| RT2870_REG_PROT_NAV_SHORT
|
3106 RT2870_REG_TXOP_ALLOW_ALL
| RT2870_REG_PROT_CTRL_NONE
;
3108 /* set up protection frame phy mode and rate (MCS code) */
3110 if (ic
->ic_curmode
== IEEE80211_MODE_11A
)
3111 cck_prot
|= (RT2870_REG_PROT_PHYMODE_OFDM
<< RT2870_REG_PROT_PHYMODE_SHIFT
) |
3112 (0 << RT2870_REG_PROT_MCS_SHIFT
);
3114 cck_prot
|= ((RT2870_REG_PROT_PHYMODE_CCK
<< RT2870_REG_PROT_PHYMODE_SHIFT
) |
3115 (3 << RT2870_REG_PROT_MCS_SHIFT
));
3117 rt2870_io_mac_write(sc
, RT2870_REG_TX_CCK_PROT_CFG
, cck_prot
);
3119 /* OFDM frame protection */
3121 ofdm_prot
= RT2870_REG_RTSTH_ENABLE
| RT2870_REG_PROT_NAV_SHORT
|
3122 RT2870_REG_TXOP_ALLOW_ALL
;
3124 if (ic
->ic_flags
& IEEE80211_F_USEPROT
)
3126 RT2870_DPRINTF(sc
, RT2870_DEBUG_PROT
,
3127 "%s: updating protection mode: b/g protection mode=%s\n",
3128 device_get_nameunit(sc
->dev
),
3129 (ic
->ic_protmode
== IEEE80211_PROT_RTSCTS
) ? "RTS/CTS" :
3130 ((ic
->ic_protmode
== IEEE80211_PROT_CTSONLY
) ? "CTS-to-self" : "none"));
3132 if (ic
->ic_protmode
== IEEE80211_PROT_RTSCTS
)
3133 ofdm_prot
|= RT2870_REG_PROT_CTRL_RTS_CTS
;
3134 else if (ic
->ic_protmode
== IEEE80211_PROT_CTSONLY
)
3135 ofdm_prot
|= RT2870_REG_PROT_CTRL_CTS
;
3137 ofdm_prot
|= RT2870_REG_PROT_CTRL_NONE
;
3141 RT2870_DPRINTF(sc
, RT2870_DEBUG_PROT
,
3142 "%s: updating protection mode: b/g protection mode=%s\n",
3143 device_get_nameunit(sc
->dev
), "none");
3145 ofdm_prot
|= RT2870_REG_PROT_CTRL_NONE
;
3148 rt2870_io_mac_write(sc
, RT2870_REG_TX_OFDM_PROT_CFG
, ofdm_prot
);
3150 /* HT frame protection */
3152 if ((ic
->ic_opmode
== IEEE80211_M_STA
) && (ic
->ic_state
== IEEE80211_S_RUN
))
3153 htopmode
= ic
->ic_bss
->ni_htopmode
;
3155 htopmode
= ic
->ic_curhtprotmode
;
3157 RT2870_DPRINTF(sc
, RT2870_DEBUG_PROT
,
3158 "%s: updating protection mode: HT operation mode=0x%02x, protection mode=%s\n",
3159 device_get_nameunit(sc
->dev
),
3160 htopmode
& IEEE80211_HTINFO_OPMODE
,
3161 (ic
->ic_htprotmode
== IEEE80211_PROT_RTSCTS
) ? "RTS/CTS" :
3162 ((ic
->ic_htprotmode
== IEEE80211_PROT_CTSONLY
) ? "CTS-to-self" : "none"));
3164 switch (htopmode
& IEEE80211_HTINFO_OPMODE
)
3166 /* IEEE80211_HTINFO_OPMODE_HT20PR */
3167 case IEEE80211_HTINFO_OPMODE_HT20PR
:
3168 mm20_prot
= RT2870_REG_PROT_NAV_SHORT
| RT2870_REG_PROT_CTRL_NONE
|
3169 RT2870_REG_TXOP_ALLOW_CCK
| RT2870_REG_TXOP_ALLOW_OFDM
|
3170 RT2870_REG_TXOP_ALLOW_MM20
| RT2870_REG_TXOP_ALLOW_GF20
|
3171 (RT2870_REG_PROT_PHYMODE_OFDM
<< RT2870_REG_PROT_PHYMODE_SHIFT
) |
3172 (4 << RT2870_REG_PROT_MCS_SHIFT
);
3174 gf20_prot
= mm20_prot
;
3176 mm40_prot
= RT2870_REG_PROT_NAV_SHORT
| RT2870_REG_PROT_CTRL_NONE
|
3177 RT2870_REG_TXOP_ALLOW_ALL
|
3178 (RT2870_REG_PROT_PHYMODE_OFDM
<< RT2870_REG_PROT_PHYMODE_SHIFT
) |
3179 (0x84 << RT2870_REG_PROT_MCS_SHIFT
);
3181 if (ic
->ic_htprotmode
== IEEE80211_PROT_RTSCTS
)
3182 mm40_prot
|= RT2870_REG_PROT_CTRL_RTS_CTS
;
3183 else if (ic
->ic_htprotmode
== IEEE80211_PROT_CTSONLY
)
3184 mm40_prot
|= RT2870_REG_PROT_CTRL_CTS
;
3186 mm40_prot
|= RT2870_REG_PROT_CTRL_NONE
;
3188 gf40_prot
= mm40_prot
;
3191 /* IEEE80211_HTINFO_OPMODE_MIXED */
3192 case IEEE80211_HTINFO_OPMODE_MIXED
:
3193 mm20_prot
= RT2870_REG_PROT_NAV_SHORT
|
3194 RT2870_REG_TXOP_ALLOW_CCK
| RT2870_REG_TXOP_ALLOW_OFDM
|
3195 RT2870_REG_TXOP_ALLOW_MM20
| RT2870_REG_TXOP_ALLOW_GF20
;
3197 if (ic
->ic_flags
& IEEE80211_F_USEPROT
)
3198 mm20_prot
|= (RT2870_REG_PROT_PHYMODE_CCK
<< RT2870_REG_PROT_PHYMODE_SHIFT
) |
3199 (3 << RT2870_REG_PROT_MCS_SHIFT
);
3201 mm20_prot
|= (RT2870_REG_PROT_PHYMODE_OFDM
<< RT2870_REG_PROT_PHYMODE_SHIFT
) |
3202 (4 << RT2870_REG_PROT_MCS_SHIFT
);
3204 if (ic
->ic_htprotmode
== IEEE80211_PROT_RTSCTS
)
3205 mm20_prot
|= RT2870_REG_PROT_CTRL_RTS_CTS
;
3206 else if (ic
->ic_htprotmode
== IEEE80211_PROT_CTSONLY
)
3207 mm20_prot
|= RT2870_REG_PROT_CTRL_CTS
;
3209 mm20_prot
|= RT2870_REG_PROT_CTRL_NONE
;
3211 gf20_prot
= mm20_prot
;
3213 mm40_prot
= RT2870_REG_PROT_NAV_SHORT
| RT2870_REG_TXOP_ALLOW_ALL
;
3215 if (ic
->ic_flags
& IEEE80211_F_USEPROT
)
3216 mm40_prot
|= (RT2870_REG_PROT_PHYMODE_CCK
<< RT2870_REG_PROT_PHYMODE_SHIFT
) |
3217 (3 << RT2870_REG_PROT_MCS_SHIFT
);
3219 mm40_prot
|= (RT2870_REG_PROT_PHYMODE_OFDM
<< RT2870_REG_PROT_PHYMODE_SHIFT
) |
3220 (0x84 << RT2870_REG_PROT_MCS_SHIFT
);
3222 if (ic
->ic_htprotmode
== IEEE80211_PROT_RTSCTS
)
3223 mm40_prot
|= RT2870_REG_PROT_CTRL_RTS_CTS
;
3224 else if (ic
->ic_htprotmode
== IEEE80211_PROT_CTSONLY
)
3225 mm40_prot
|= RT2870_REG_PROT_CTRL_CTS
;
3227 mm40_prot
|= RT2870_REG_PROT_CTRL_NONE
;
3229 gf40_prot
= mm40_prot
;
3233 * IEEE80211_HTINFO_OPMODE_PURE
3234 * IEEE80211_HTINFO_OPMODE_PROTOPT
3236 case IEEE80211_HTINFO_OPMODE_PURE
:
3237 case IEEE80211_HTINFO_OPMODE_PROTOPT
:
3239 mm20_prot
= RT2870_REG_PROT_NAV_SHORT
| RT2870_REG_PROT_CTRL_NONE
|
3240 RT2870_REG_TXOP_ALLOW_CCK
| RT2870_REG_TXOP_ALLOW_OFDM
|
3241 RT2870_REG_TXOP_ALLOW_MM20
| RT2870_REG_TXOP_ALLOW_GF20
|
3242 (RT2870_REG_PROT_PHYMODE_OFDM
<< RT2870_REG_PROT_PHYMODE_SHIFT
) |
3243 (4 << RT2870_REG_PROT_MCS_SHIFT
);
3245 gf20_prot
= mm20_prot
;
3247 mm40_prot
= RT2870_REG_PROT_NAV_SHORT
| RT2870_REG_PROT_CTRL_NONE
|
3248 RT2870_REG_TXOP_ALLOW_ALL
|
3249 (RT2870_REG_PROT_PHYMODE_OFDM
<< RT2870_REG_PROT_PHYMODE_SHIFT
) |
3250 (0x84 << RT2870_REG_PROT_MCS_SHIFT
);
3252 gf40_prot
= mm40_prot
;
3256 rt2870_io_mac_write(sc
, RT2870_REG_TX_MM20_PROT_CFG
, mm20_prot
);
3257 rt2870_io_mac_write(sc
, RT2870_REG_TX_MM40_PROT_CFG
, mm40_prot
);
3258 rt2870_io_mac_write(sc
, RT2870_REG_TX_GF20_PROT_CFG
, gf20_prot
);
3259 rt2870_io_mac_write(sc
, RT2870_REG_TX_GF40_PROT_CFG
, gf40_prot
);
3263 * rt2870_asic_updateslot
3265 static void rt2870_asic_updateslot(struct rt2870_softc
*sc
)
3267 struct ieee80211com
*ic
;
3272 RT2870_DPRINTF(sc
, RT2870_DEBUG_STATE
,
3273 "%s: %s short slot time\n",
3274 device_get_nameunit(sc
->dev
),
3275 (ic
->ic_flags
& IEEE80211_F_SHSLOT
) ? "enabling" : "disabling");
3277 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_BKOFF_SLOT_CFG
);
3280 tmp
|= (ic
->ic_flags
& IEEE80211_F_SHSLOT
) ? 9 : 20;
3282 rt2870_io_mac_write(sc
, RT2870_REG_BKOFF_SLOT_CFG
, tmp
);
3286 * rt2870_asic_wme_update
3288 static void rt2870_asic_wme_update(struct rt2870_softc
*sc
)
3290 struct ieee80211com
*ic
;
3291 struct ieee80211_wme_state
*wme
;
3292 const struct wmeParams
*wmep
;
3297 wmep
= wme
->wme_chanParams
.cap_wmeParams
;
3299 RT2870_DPRINTF(sc
, RT2870_DEBUG_WME
,
3300 "%s: wme update: WME_AC_VO=%d/%d/%d/%d, WME_AC_VI=%d/%d/%d/%d, "
3301 "WME_AC_BK=%d/%d/%d/%d, WME_AC_BE=%d/%d/%d/%d\n",
3302 device_get_nameunit(sc
->dev
),
3303 wmep
[WME_AC_VO
].wmep_aifsn
,
3304 wmep
[WME_AC_VO
].wmep_logcwmin
, wmep
[WME_AC_VO
].wmep_logcwmax
,
3305 wmep
[WME_AC_VO
].wmep_txopLimit
,
3306 wmep
[WME_AC_VI
].wmep_aifsn
,
3307 wmep
[WME_AC_VI
].wmep_logcwmin
, wmep
[WME_AC_VI
].wmep_logcwmax
,
3308 wmep
[WME_AC_VI
].wmep_txopLimit
,
3309 wmep
[WME_AC_BK
].wmep_aifsn
,
3310 wmep
[WME_AC_BK
].wmep_logcwmin
, wmep
[WME_AC_BK
].wmep_logcwmax
,
3311 wmep
[WME_AC_BK
].wmep_txopLimit
,
3312 wmep
[WME_AC_BE
].wmep_aifsn
,
3313 wmep
[WME_AC_BE
].wmep_logcwmin
, wmep
[WME_AC_BE
].wmep_logcwmax
,
3314 wmep
[WME_AC_BE
].wmep_txopLimit
);
3316 for (i
= 0; i
< WME_NUM_AC
; i
++)
3317 rt2870_io_mac_write(sc
, RT2870_REG_TX_EDCA_AC_CFG(i
),
3318 (wmep
[i
].wmep_logcwmax
<< 16) | (wmep
[i
].wmep_logcwmin
<< 12) |
3319 (wmep
[i
].wmep_aifsn
<< 8) | wmep
[i
].wmep_txopLimit
);
3321 rt2870_io_mac_write(sc
, RT2870_REG_SCHDMA_WMM_AIFSN_CFG
,
3322 (wmep
[WME_AC_VO
].wmep_aifsn
<< 12) | (wmep
[WME_AC_VI
].wmep_aifsn
<< 8) |
3323 (wmep
[WME_AC_BK
].wmep_aifsn
<< 4) | wmep
[WME_AC_BE
].wmep_aifsn
);
3325 rt2870_io_mac_write(sc
, RT2870_REG_SCHDMA_WMM_CWMIN_CFG
,
3326 (wmep
[WME_AC_VO
].wmep_logcwmin
<< 12) | (wmep
[WME_AC_VI
].wmep_logcwmin
<< 8) |
3327 (wmep
[WME_AC_BK
].wmep_logcwmin
<< 4) | wmep
[WME_AC_BE
].wmep_logcwmin
);
3329 rt2870_io_mac_write(sc
, RT2870_REG_SCHDMA_WMM_CWMAX_CFG
,
3330 (wmep
[WME_AC_VO
].wmep_logcwmax
<< 12) | (wmep
[WME_AC_VI
].wmep_logcwmax
<< 8) |
3331 (wmep
[WME_AC_BK
].wmep_logcwmax
<< 4) | wmep
[WME_AC_BE
].wmep_logcwmax
);
3333 rt2870_io_mac_write(sc
, RT2870_REG_SCHDMA_WMM_TXOP0_CFG
,
3334 (wmep
[WME_AC_BK
].wmep_txopLimit
<< 16) | wmep
[WME_AC_BE
].wmep_txopLimit
);
3336 rt2870_io_mac_write(sc
, RT2870_REG_SCHDMA_WMM_TXOP1_CFG
,
3337 (wmep
[WME_AC_VO
].wmep_txopLimit
<< 16) | wmep
[WME_AC_VI
].wmep_txopLimit
);
3341 * rt2870_asic_update_beacon
3343 static int rt2870_asic_update_beacon(struct rt2870_softc
*sc
)
3345 struct ieee80211com
*ic
;
3347 struct rt2870_txwi txwi
;
3353 m
= ieee80211_beacon_alloc(ic
->ic_bss
, &sc
->beacon_offsets
);
3357 rate
= IEEE80211_IS_CHAN_5GHZ(ic
->ic_curchan
) ? 12 : 2;
3358 mcs
= rt2870_rate2mcs(rate
);
3360 memset(&txwi
, 0, sizeof(struct rt2870_txwi
));
3363 txwi
.pid_mpdu_len
= ((htole16(m
->m_pkthdr
.len
) & RT2870_TXWI_MPDU_LEN_MASK
) <<
3364 RT2870_TXWI_MPDU_LEN_SHIFT
);
3365 txwi
.txop
= (RT2870_TXWI_TXOP_HT
<< RT2870_TXWI_TXOP_SHIFT
);
3366 txwi
.mpdu_density_flags
|=
3367 (RT2870_TXWI_FLAGS_TS
<< RT2870_TXWI_FLAGS_SHIFT
);
3368 txwi
.bawin_size_xflags
|=
3369 (RT2870_TXWI_XFLAGS_NSEQ
<< RT2870_TXWI_XFLAGS_SHIFT
);
3373 txwi
.phymode_ifs_stbc_shortgi
=
3374 (RT2870_TXWI_PHYMODE_CCK
<< RT2870_TXWI_PHYMODE_SHIFT
);
3376 if (rate
!= 2 && (ic
->ic_flags
& IEEE80211_F_SHPREAMBLE
))
3377 mcs
|= RT2870_TXWI_MCS_SHOTPRE
;
3381 txwi
.phymode_ifs_stbc_shortgi
=
3382 (RT2870_TXWI_PHYMODE_OFDM
<< RT2870_TXWI_PHYMODE_SHIFT
);
3385 txwi
.bw_mcs
= (RT2870_TXWI_BW_20
<< RT2870_TXWI_BW_SHIFT
) |
3386 ((mcs
& RT2870_TXWI_MCS_MASK
) << RT2870_TXWI_MCS_SHIFT
);
3388 /* disable temporarily TSF sync */
3390 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_BCN_TIME_CFG
);
3392 tmp
&= ~(RT2870_REG_BCN_TX_ENABLE
|
3393 RT2870_REG_TSF_TIMER_ENABLE
|
3394 RT2870_REG_TBTT_TIMER_ENABLE
);
3396 rt2870_io_mac_write(sc
, RT2870_REG_BCN_TIME_CFG
, tmp
);
3398 /* write Tx wireless info and beacon frame to on-chip memory */
3400 rt2870_io_mac_write_multi(sc
, RT2870_REG_BEACON_BASE(0),
3401 &txwi
, sizeof(struct rt2870_txwi
));
3403 rt2870_io_mac_write_multi(sc
, RT2870_REG_BEACON_BASE(0) + sizeof(struct rt2870_txwi
),
3404 mtod(m
, uint8_t *), m
->m_pkthdr
.len
);
3406 /* enable again TSF sync */
3408 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_BCN_TIME_CFG
);
3410 tmp
|= (RT2870_REG_BCN_TX_ENABLE
|
3411 RT2870_REG_TSF_TIMER_ENABLE
|
3412 RT2870_REG_TBTT_TIMER_ENABLE
);
3414 rt2870_io_mac_write(sc
, RT2870_REG_BCN_TIME_CFG
, tmp
);
3422 * rt2870_asic_clear_keytables
3424 static void rt2870_asic_clear_keytables(struct rt2870_softc
*sc
)
3426 /* clear Rx WCID search table (entries = 256, entry size = 8) */
3428 rt2870_io_mac_set_region_4(sc
, RT2870_REG_WCID(0), 0, 2 * 256);
3430 /* clear WCID attribute table (entries = 256, entry size = 4) */
3432 rt2870_io_mac_set_region_4(sc
, RT2870_REG_WCID_ATTR(0), 0, 256);
3434 /* clear IV/EIV table (entries = 256, entry size = 8) */
3436 rt2870_io_mac_set_region_4(sc
, RT2870_REG_IVEIV(0), 0, 2 * 256);
3438 /* clear pairwise key table (entries = 256, entry size = 32) */
3440 rt2870_io_mac_set_region_4(sc
, RT2870_REG_PKEY(0), 0, 8 * 256);
3442 /* clear shared key table (entries = 32, entry size = 32) */
3444 rt2870_io_mac_set_region_4(sc
, RT2870_REG_SKEY(0, 0), 0, 8 * 32);
3446 /* clear shared key mode (entries = 32, entry size = 2) */
3448 rt2870_io_mac_set_region_4(sc
, RT2870_REG_SKEY_MODE(0), 0, 16);
3454 static uint8_t rt2870_rxrate(struct rt2870_rxwi
*rxwi
)
3456 uint8_t mcs
, phymode
;
3459 mcs
= (rxwi
->bw_mcs
>> RT2870_RXWI_MCS_SHIFT
) & RT2870_RXWI_MCS_MASK
;
3460 phymode
= (rxwi
->phymode_stbc_shortgi
>> RT2870_RXWI_PHYMODE_SHIFT
) &
3461 RT2870_RXWI_PHYMODE_MASK
;
3467 case RT2870_RXWI_PHYMODE_CCK
:
3468 switch (mcs
& ~RT2870_RXWI_MCS_SHOTPRE
)
3470 case 0: rate
= 2; break; /* 1 Mbps */
3471 case 1: rate
= 4; break; /* 2 MBps */
3472 case 2: rate
= 11; break; /* 5.5 Mbps */
3473 case 3: rate
= 22; break; /* 11 Mbps */
3477 case RT2870_RXWI_PHYMODE_OFDM
:
3480 case 0: rate
= 12; break; /* 6 Mbps */
3481 case 1: rate
= 18; break; /* 9 Mbps */
3482 case 2: rate
= 24; break; /* 12 Mbps */
3483 case 3: rate
= 36; break; /* 18 Mbps */
3484 case 4: rate
= 48; break; /* 24 Mbps */
3485 case 5: rate
= 72; break; /* 36 Mbps */
3486 case 6: rate
= 96; break; /* 48 Mbps */
3487 case 7: rate
= 108; break; /* 54 Mbps */
3491 case RT2870_RXWI_PHYMODE_HT_MIXED
:
3492 case RT2870_RXWI_PHYMODE_HT_GF
:
3500 * rt2870_maxrssi_rxpath
3502 static uint8_t rt2870_maxrssi_rxpath(struct rt2870_softc
*sc
,
3503 const struct rt2870_rxwi
*rxwi
)
3509 if (sc
->nrxpath
> 1)
3510 if (rxwi
->rssi
[1] > rxwi
->rssi
[rxpath
])
3513 if (sc
->nrxpath
> 2)
3514 if (rxwi
->rssi
[2] > rxwi
->rssi
[rxpath
])
3523 static int8_t rt2870_rssi2dbm(struct rt2870_softc
*sc
,
3524 uint8_t rssi
, uint8_t rxpath
)
3526 struct ieee80211com
*ic
;
3527 struct ieee80211_channel
*c
;
3532 chan
= ieee80211_chan2ieee(ic
, c
);
3534 if (IEEE80211_IS_CHAN_5GHZ(c
))
3536 delta
= sc
->rssi_off_5ghz
[rxpath
];
3539 delta
-= sc
->lna_gain
[1];
3540 else if (chan
<= 128)
3541 delta
-= sc
->lna_gain
[2];
3543 delta
-= sc
->lna_gain
[3];
3547 delta
= sc
->rssi_off_2ghz
[rxpath
] - sc
->lna_gain
[0];
3550 return (-12 - delta
- rssi
);
3556 static uint8_t rt2870_rate2mcs(uint8_t rate
)
3583 static int rt2870_ackrate(struct ieee80211com
*ic
, int rate
)
3595 return (ic
->ic_curmode
== IEEE80211_MODE_11B
) ? 4 : rate
;
3614 /* default to 1Mbps */
3621 static uint16_t rt2870_txtime(int len
, int rate
, uint32_t flags
)
3625 if (RT2870_RATE_IS_OFDM(rate
))
3627 txtime
= (8 + 4 * len
+ 3 + rate
- 1) / rate
;
3628 txtime
= 16 + 4 + 4 * txtime
+ 6;
3632 txtime
= (16 * len
+ rate
- 1) / rate
;
3634 if (rate
!= 2 && (flags
& IEEE80211_F_SHPREAMBLE
))
3646 static void rt2870_rx_frame(struct rt2870_softc
*sc
,
3647 uint8_t *buf
, uint32_t dmalen
)
3649 struct ieee80211com
*ic
;
3651 struct ieee80211_frame
*wh
;
3652 struct ieee80211_node
*ni
;
3653 struct rt2870_softc_rx_radiotap_header
*tap
;
3654 struct rt2870_rxwi
*rxwi
;
3655 struct rt2870_rxinfo
*rxinfo
;
3657 uint32_t rxinfo_flags
;
3658 uint8_t cipher_err
, rssi
, ant
, phymode
, bw
, shortgi
, mcs
;
3660 int len
, ampdu
, amsdu
;
3665 /* get Rx wireless info */
3667 rxwi
= (struct rt2870_rxwi
*) buf
;
3668 len
= (le16toh(rxwi
->tid_size
) >> RT2870_RXWI_SIZE_SHIFT
) &
3669 RT2870_RXWI_SIZE_MASK
;
3673 RT2870_DPRINTF(sc
, RT2870_DEBUG_RX
,
3674 "%s: bad rxwi len: DMA len=%d, rxwi len=%d\n",
3675 device_get_nameunit(sc
->dev
), dmalen
, len
);
3681 rxinfo
= (struct rt2870_rxinfo
*) ((caddr_t
) rxwi
+ dmalen
);
3682 rxinfo_flags
= le32toh(rxinfo
->flags
);
3684 RT2870_DPRINTF(sc
, RT2870_DEBUG_RX
,
3685 "%s: Rx frame: DMA len=%d, len=%d, rxinfo flags=0x%08x\n",
3686 device_get_nameunit(sc
->dev
), dmalen
, len
, rxinfo_flags
);
3688 /* check for crc errors */
3690 if (rxinfo_flags
& RT2870_RXINFO_FLAGS_CRC_ERR
)
3692 RT2870_DPRINTF(sc
, RT2870_DEBUG_RX
,
3693 "%s: rxinfo: crc error\n",
3694 device_get_nameunit(sc
->dev
));
3698 if (!(ifp
->if_flags
& IFF_PROMISC
))
3702 wh
= (struct ieee80211_frame
*) (rxwi
+ 1);
3704 /* check for L2 padding between IEEE 802.11 frame header and body */
3706 if (rxinfo_flags
& RT2870_RXINFO_FLAGS_L2PAD
)
3708 RT2870_DPRINTF(sc
, RT2870_DEBUG_RX
,
3709 "%s: L2 padding: DMA len=%d, len=%d\n",
3710 device_get_nameunit(sc
->dev
), dmalen
, len
);
3715 m
= m_getjcl(M_DONTWAIT
, MT_DATA
, M_PKTHDR
, MJUM9BYTES
);
3722 memcpy(mtod(m
, caddr_t
), (caddr_t
) wh
, len
);
3724 m
->m_pkthdr
.rcvif
= ifp
;
3725 m
->m_pkthdr
.len
= m
->m_len
= len
;
3727 wh
= mtod(m
, struct ieee80211_frame
*);
3729 /* check for cipher errors */
3731 if (rxinfo_flags
& RT2870_RXINFO_FLAGS_DECRYPTED
)
3733 cipher_err
= ((rxinfo_flags
>> RT2870_RXINFO_FLAGS_CIPHER_ERR_SHIFT
) &
3734 RT2870_RXINFO_FLAGS_CIPHER_ERR_MASK
);
3735 if (cipher_err
== RT2870_RXINFO_FLAGS_CIPHER_ERR_NONE
)
3737 if (wh
->i_fc
[1] & IEEE80211_FC1_WEP
)
3738 wh
->i_fc
[1] &= ~IEEE80211_FC1_WEP
;
3740 m
->m_flags
|= M_WEP
;
3744 RT2870_DPRINTF(sc
, RT2870_DEBUG_RX
,
3745 "%s: rxinfo: cipher error=0x%02x\n",
3746 device_get_nameunit(sc
->dev
), cipher_err
);
3750 if (!(ifp
->if_flags
& IFF_PROMISC
))
3759 if (wh
->i_fc
[1] & IEEE80211_FC1_WEP
)
3763 if (!(ifp
->if_flags
& IFF_PROMISC
))
3771 /* check for A-MPDU */
3773 if (rxinfo_flags
& RT2870_RXINFO_FLAGS_AMPDU
)
3775 m
->m_flags
|= M_AMPDU
;
3783 ant
= rt2870_maxrssi_rxpath(sc
, rxwi
);
3784 rssi
= rxwi
->rssi
[ant
];
3785 rssi_dbm
= rt2870_rssi2dbm(sc
, rssi
, ant
);
3786 phymode
= ((rxwi
->phymode_stbc_shortgi
>> RT2870_RXWI_PHYMODE_SHIFT
) &
3787 RT2870_RXWI_PHYMODE_MASK
);
3788 bw
= ((rxwi
->bw_mcs
>> RT2870_RXWI_BW_SHIFT
) & RT2870_RXWI_BW_MASK
);
3789 shortgi
= ((rxwi
->phymode_stbc_shortgi
>> RT2870_RXWI_SHORTGI_SHIFT
) &
3790 RT2870_RXWI_SHORTGI_MASK
);
3791 mcs
= ((rxwi
->bw_mcs
>> RT2870_RXWI_MCS_SHIFT
) & RT2870_RXWI_MCS_MASK
);
3792 amsdu
= (rxinfo_flags
& RT2870_RXINFO_FLAGS_AMSDU
);
3794 if (bpf_peers_present(sc
->drvbpf
))
3798 tap
->flags
= IEEE80211_RADIOTAP_F_DATAPAD
;
3799 tap
->dbm_antsignal
= rssi_dbm
;
3800 tap
->dbm_antnoise
= RT2870_NOISE_FLOOR
;
3802 tap
->antsignal
= rssi
;
3803 tap
->chan_flags
= htole32(ic
->ic_curchan
->ic_flags
);
3804 tap
->chan_freq
= htole16(ic
->ic_curchan
->ic_freq
);
3805 tap
->chan_ieee
= ic
->ic_curchan
->ic_ieee
;
3806 tap
->chan_maxpow
= 0;
3808 if (phymode
== RT2870_RXWI_PHYMODE_CCK
|| phymode
== RT2870_RXWI_PHYMODE_OFDM
)
3809 tap
->rate
= rt2870_rxrate(rxwi
);
3811 tap
->rate
= mcs
| IEEE80211_RATE_MCS
;
3813 if (rxwi
->bw_mcs
& RT2870_RXWI_MCS_SHOTPRE
)
3814 tap
->flags
|= IEEE80211_RADIOTAP_F_SHORTPRE
;
3817 tap
->flags
|= IEEE80211_RADIOTAP_F_SHORTGI
;
3819 bpf_mtap2(sc
->drvbpf
, tap
, sc
->rxtap_len
, m
);
3822 RT2870_DPRINTF(sc
, RT2870_DEBUG_RX
,
3823 "%s: received frame: phymode=%d, bw=%d, shortgi=%d, mcs=%d, "
3824 "ant=%d, rssi=%d/%d/%d, snr=%d/%d, wcid=0x%02x, ampdu=%d, amsdu=%d\n",
3825 device_get_nameunit(sc
->dev
),
3826 phymode
, bw
, shortgi
, mcs
,
3827 ant
, rxwi
->rssi
[0], rxwi
->rssi
[1], rxwi
->rssi
[2],
3828 rxwi
->snr
[0], rxwi
->snr
[1],
3829 rxwi
->wcid
, ampdu
, amsdu
);
3831 ni
= ieee80211_find_rxnode(ic
, (struct ieee80211_frame_min
*) wh
);
3833 ieee80211_input(ic
, m
, ni
, rssi_dbm
- RT2870_NOISE_FLOOR
, RT2870_NOISE_FLOOR
, 0);
3835 ieee80211_free_node(ni
);
3841 static int rt2870_tx_frame(struct rt2870_softc
*sc
,
3842 struct mbuf
*m
, struct ieee80211_node
*ni
, int qid
)
3844 struct ieee80211com
*ic
;
3845 struct rt2870_softc_tx_ring
*ring
;
3846 struct rt2870_softc_tx_data
*data
;
3847 struct rt2870_txinfo
*txinfo
;
3848 struct rt2870_txwi
*txwi
;
3849 struct ieee80211_frame
*wh
;
3850 struct rt2870_softc_tx_radiotap_header
*tap
;
3851 u_int hdrsize
, hdrspace
;
3852 uint8_t type
, rate
, bw
, shortgi
, mcs
, pid
, wcid
;
3853 uint16_t qos
, len
, dmalen
, mpdu_len
, dur
;
3854 int hasqos
, ackrate
;
3858 ring
= &sc
->tx_ring
[qid
];
3859 data
= STAILQ_FIRST(&ring
->inactive
);
3860 STAILQ_REMOVE_HEAD(&ring
->inactive
, next
);
3861 txinfo
= (struct rt2870_txinfo
*) data
->buf
;
3862 txwi
= (struct rt2870_txwi
*) (txinfo
+ 1);
3864 wh
= mtod(m
, struct ieee80211_frame
*);
3866 type
= wh
->i_fc
[0] & IEEE80211_FC0_TYPE_MASK
;
3868 hasqos
= IEEE80211_QOS_HAS_SEQ(wh
);
3871 if (IEEE80211_HAS_ADDR4(wh
))
3872 qos
= le16toh(*(const uint16_t *)
3873 (((struct ieee80211_qosframe_addr4
*) wh
)->i_qos
));
3875 qos
= le16toh(*(const uint16_t *)
3876 (((struct ieee80211_qosframe
*) wh
)->i_qos
));
3883 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
3885 if (IEEE80211_IS_MULTICAST(wh
->i_addr1
) || type
!= IEEE80211_FC0_TYPE_DATA
)
3887 else if (ic
->ic_fixed_rate
!= IEEE80211_FIXED_RATE_NONE
)
3888 rate
= ic
->ic_fixed_rate
;
3890 rate
= ni
->ni_htrates
.rs_rates
[ni
->ni_txrate
];
3894 if (IEEE80211_IS_MULTICAST(wh
->i_addr1
) || type
!= IEEE80211_FC0_TYPE_DATA
)
3895 rate
= IEEE80211_IS_CHAN_5GHZ(ic
->ic_curchan
) ? 12 : 2;
3896 else if (ic
->ic_fixed_rate
!= IEEE80211_FIXED_RATE_NONE
)
3897 rate
= ic
->ic_fixed_rate
;
3899 rate
= ni
->ni_rates
.rs_rates
[ni
->ni_txrate
];
3902 rate
&= IEEE80211_RATE_VAL
;
3904 len
= sizeof(struct rt2870_txinfo
) + sizeof(struct rt2870_txwi
) + m
->m_pkthdr
.len
;
3906 /* align end on a 4-bytes boundary */
3908 dmalen
= (len
+ 3) & ~3;
3912 memset(txinfo
, 0, sizeof(struct rt2870_txinfo
));
3914 txinfo
->len
= htole16(dmalen
);
3916 txinfo
->qsel_flags
= (RT2870_TXINFO_QSEL_EDCA
<< RT2870_TXINFO_QSEL_SHIFT
);
3918 /* fill Tx wireless info */
3920 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
3923 mcs
= rt2870_rate2mcs(rate
);
3927 wcid
= (type
== IEEE80211_FC0_TYPE_DATA
) ?
3928 RT2870_AID2WCID(ni
->ni_associd
) : 0xff;
3930 /* calculate MPDU length without padding */
3932 hdrsize
= ieee80211_hdrsize(wh
);
3933 hdrspace
= ieee80211_hdrspace(ic
, wh
);
3934 mpdu_len
= m
->m_pkthdr
.len
- hdrspace
+ hdrsize
;
3936 memset(txwi
, 0, sizeof(struct rt2870_txwi
));
3940 txwi
->pid_mpdu_len
= ((htole16(pid
) & RT2870_TXWI_PID_MASK
) <<
3941 RT2870_TXWI_PID_SHIFT
) | ((htole16(mpdu_len
) & RT2870_TXWI_MPDU_LEN_MASK
) <<
3942 RT2870_TXWI_MPDU_LEN_SHIFT
);
3944 if ((ic
->ic_flags_ext
& (IEEE80211_FEXT_SHORTGI20
| IEEE80211_FEXT_SHORTGI40
)) &&
3945 (ni
->ni_flags
& IEEE80211_NODE_HT
))
3950 txwi
->phymode_ifs_stbc_shortgi
|=
3951 ((shortgi
& RT2870_TXWI_SHORTGI_MASK
) << RT2870_TXWI_SHORTGI_SHIFT
);
3953 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
3955 txwi
->phymode_ifs_stbc_shortgi
|=
3956 (RT2870_TXWI_PHYMODE_HT_MIXED
<< RT2870_TXWI_PHYMODE_SHIFT
);
3960 if (!RT2870_RATE_IS_OFDM(rate
))
3962 txwi
->phymode_ifs_stbc_shortgi
|=
3963 (RT2870_TXWI_PHYMODE_CCK
<< RT2870_TXWI_PHYMODE_SHIFT
);
3965 if (rate
!= 2 && (ic
->ic_flags
& IEEE80211_F_SHPREAMBLE
))
3966 mcs
|= RT2870_TXWI_MCS_SHOTPRE
;
3970 txwi
->phymode_ifs_stbc_shortgi
|=
3971 (RT2870_TXWI_PHYMODE_OFDM
<< RT2870_TXWI_PHYMODE_SHIFT
);
3975 if ((ni
->ni_flags
& IEEE80211_NODE_HT
) &&
3976 (ni
->ni_htcap
& IEEE80211_HTCAP_CHWIDTH40
))
3977 bw
= RT2870_TXWI_BW_40
;
3979 bw
= RT2870_TXWI_BW_20
;
3981 txwi
->bw_mcs
= ((bw
& RT2870_TXWI_BW_MASK
) << RT2870_TXWI_BW_SHIFT
) |
3982 ((mcs
& RT2870_TXWI_MCS_MASK
) << RT2870_TXWI_MCS_SHIFT
);
3984 if (type
!= IEEE80211_FC0_TYPE_DATA
)
3985 txwi
->txop
= (RT2870_TXWI_TXOP_BACKOFF
<< RT2870_TXWI_TXOP_SHIFT
);
3987 txwi
->txop
= (RT2870_TXWI_TXOP_HT
<< RT2870_TXWI_TXOP_SHIFT
);
3989 /* skip ACKs for multicast frames and probe responses */
3991 if (!IEEE80211_IS_MULTICAST(wh
->i_addr1
) &&
3992 ((wh
->i_fc
[0] & (IEEE80211_FC0_TYPE_MASK
| IEEE80211_FC0_SUBTYPE_MASK
)) !=
3993 (IEEE80211_FC0_TYPE_MGT
| IEEE80211_FC0_SUBTYPE_PROBE_RESP
)) &&
3994 (!hasqos
|| (qos
& IEEE80211_QOS_ACKPOLICY
) != IEEE80211_QOS_ACKPOLICY_NOACK
))
3996 txwi
->bawin_size_xflags
|=
3997 (RT2870_TXWI_XFLAGS_ACK
<< RT2870_TXWI_XFLAGS_SHIFT
);
3999 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
4001 /* preamble + plcp + signal extension */
4007 ackrate
= rt2870_ackrate(ic
, rate
);
4009 dur
= rt2870_txtime(RT2870_ACK_SIZE
, ackrate
, ic
->ic_flags
) +
4013 *(uint16_t *) wh
->i_dur
= htole16(dur
);
4016 /* ask MAC to insert timestamp into probe responses */
4018 if ((wh
->i_fc
[0] & (IEEE80211_FC0_TYPE_MASK
| IEEE80211_FC0_SUBTYPE_MASK
)) ==
4019 (IEEE80211_FC0_TYPE_MGT
| IEEE80211_FC0_SUBTYPE_PROBE_RESP
))
4020 txwi
->mpdu_density_flags
|=
4021 (RT2870_TXWI_FLAGS_TS
<< RT2870_TXWI_FLAGS_SHIFT
);
4023 if (bpf_peers_present(sc
->drvbpf
))
4027 tap
->flags
= IEEE80211_RADIOTAP_F_DATAPAD
;
4028 tap
->chan_flags
= htole32(ic
->ic_curchan
->ic_flags
);
4029 tap
->chan_freq
= htole16(ic
->ic_curchan
->ic_freq
);
4030 tap
->chan_ieee
= ic
->ic_curchan
->ic_ieee
;
4031 tap
->chan_maxpow
= 0;
4033 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
4034 tap
->rate
= mcs
| IEEE80211_RATE_MCS
;
4038 if (mcs
& RT2870_TXWI_MCS_SHOTPRE
)
4039 tap
->flags
|= IEEE80211_RADIOTAP_F_SHORTPRE
;
4042 tap
->flags
|= IEEE80211_RADIOTAP_F_SHORTGI
;
4044 if (wh
->i_fc
[1] & IEEE80211_FC1_WEP
)
4045 tap
->flags
|= IEEE80211_RADIOTAP_F_WEP
;
4047 if (wh
->i_fc
[1] & IEEE80211_FC1_WEP
)
4049 wh
->i_fc
[1] &= ~IEEE80211_FC1_WEP
;
4051 bpf_mtap2(sc
->drvbpf
, tap
, sc
->txtap_len
, m
);
4053 wh
->i_fc
[1] |= IEEE80211_FC1_WEP
;
4057 bpf_mtap2(sc
->drvbpf
, tap
, sc
->txtap_len
, m
);
4061 m_copydata(m
, 0, m
->m_pkthdr
.len
, (caddr_t
) (txwi
+ 1));
4063 RT2870_DPRINTF(sc
, RT2870_DEBUG_TX
,
4064 "%s: sending frame: qid=%d, hdrsize=%d, hdrspace=%d, len=%d, "
4065 "bw=%d, shortgi=%d, mcs=%d, wcid=0x%02x, DMA len=%d\n",
4066 device_get_nameunit(sc
->dev
),
4067 qid
, hdrsize
, hdrspace
, m
->m_pkthdr
.len
, bw
, shortgi
, mcs
, wcid
, dmalen
);
4072 STAILQ_INSERT_TAIL(&ring
->active
, data
, next
);
4075 usbd_setup_xfer(data
->xfer
, ring
->usb_pipe
, ring
, data
->buf
, len
,
4076 USBD_FORCE_SHORT_XFER
| USBD_NO_COPY
, RT2870_USB_XFER_TIMEOUT
, rt2870_tx_intr
);
4078 usbd_transfer(data
->xfer
);
4086 static int rt2870_tx_raw(struct rt2870_softc
*sc
,
4087 struct mbuf
*m
, struct ieee80211_node
*ni
,
4088 const struct ieee80211_bpf_params
*params
)
4090 RT2870_DPRINTF(sc
, RT2870_DEBUG_TX
,
4092 device_get_nameunit(sc
->dev
));
4100 static void rt2870_rx_intr(usbd_xfer_handle xfer
,
4101 usbd_private_handle priv
, usbd_status status
)
4103 struct rt2870_softc
*sc
;
4105 struct rt2870_softc_rx_ring
*ring
;
4106 struct rt2870_softc_rx_data
*data
;
4111 ring
= &sc
->rx_ring
;
4113 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
4116 RT2870_DPRINTF(sc
, RT2870_DEBUG_INTR
,
4117 "%s: Rx interrupt: %s\n",
4118 device_get_nameunit(sc
->dev
), usbd_errstr(status
));
4121 sc
->rx_interrupts
++;
4125 case USBD_NORMAL_COMPLETION
:
4126 data
= STAILQ_FIRST(&ring
->active
);
4130 STAILQ_REMOVE_HEAD(&ring
->active
, next
);
4132 KASSERT(data
->xfer
== xfer
,
4133 ("%s: Rx interrupt: invalid USB xfer\n",
4134 device_get_nameunit(sc
->dev
)));
4136 usbd_get_xfer_status(xfer
, NULL
, NULL
, &len
, NULL
);
4140 STAILQ_INSERT_TAIL(&ring
->done
, data
, next
);
4142 taskqueue_enqueue(sc
->taskqueue
, &sc
->rx_done_task
);
4145 case USBD_CANCELLED
:
4146 case USBD_NOT_STARTED
:
4150 if (status
== USBD_STALLED
)
4151 usbd_clear_endpoint_stall_async(ring
->usb_pipe
);
4153 data
= STAILQ_FIRST(&ring
->active
);
4156 STAILQ_REMOVE_HEAD(&ring
->active
, next
);
4158 STAILQ_INSERT_TAIL(&ring
->active
, data
, next
);
4160 usbd_setup_xfer(xfer
, ring
->usb_pipe
, sc
, data
->buf
,
4161 RT2870_USB_RX_BULK_BUFLEN
, USBD_SHORT_XFER_OK
| USBD_NO_COPY
,
4162 USBD_NO_TIMEOUT
, rt2870_rx_intr
);
4164 usbd_transfer(xfer
);
4173 static void rt2870_tx_intr(usbd_xfer_handle xfer
,
4174 usbd_private_handle priv
, usbd_status status
)
4176 struct rt2870_softc
*sc
;
4178 struct rt2870_softc_tx_ring
*ring
;
4179 struct rt2870_softc_tx_data
*data
;
4185 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
4188 RT2870_DPRINTF(sc
, RT2870_DEBUG_INTR
,
4189 "%s: Tx interrupt: %s\n",
4190 device_get_nameunit(sc
->dev
), usbd_errstr(status
));
4193 sc
->tx_interrupts
[ring
->qid
]++;
4197 case USBD_NORMAL_COMPLETION
:
4198 data
= STAILQ_FIRST(&ring
->active
);
4202 STAILQ_REMOVE_HEAD(&ring
->active
, next
);
4204 STAILQ_INSERT_TAIL(&ring
->done
, data
, next
);
4206 taskqueue_enqueue(sc
->taskqueue
, &sc
->tx_done_task
);
4209 case USBD_CANCELLED
:
4210 case USBD_NOT_STARTED
:
4214 data
= STAILQ_FIRST(&ring
->active
);
4217 STAILQ_REMOVE_HEAD(&ring
->active
, next
);
4219 if (data
->m
!= NULL
)
4225 if (data
->ni
!= NULL
)
4227 ieee80211_free_node(data
->ni
);
4231 STAILQ_INSERT_TAIL(&ring
->inactive
, data
, next
);
4236 printf("%s: could not transmit buffer: qid=%d, status=%s\n",
4237 device_get_nameunit(sc
->dev
), ring
->qid
, usbd_errstr(status
));
4240 ifp
->if_drv_flags
&= ~IFF_DRV_OACTIVE
;
4242 if (status
== USBD_STALLED
)
4243 usbd_clear_endpoint_stall_async(ring
->usb_pipe
);
4249 * rt2870_rx_done_task
4251 static void rt2870_rx_done_task(void *context
, int pending
)
4253 struct rt2870_softc
*sc
;
4259 RT2870_DPRINTF(sc
, RT2870_DEBUG_RX
,
4260 "%s: Rx done task\n",
4261 device_get_nameunit(sc
->dev
));
4263 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
4266 if (rt2870_rx_eof(sc
, sc
->rx_process_limit
) != 0)
4267 taskqueue_enqueue(sc
->taskqueue
, &sc
->rx_done_task
);
4271 * rt2870_tx_done_task
4273 static void rt2870_tx_done_task(void *context
, int pending
)
4275 struct rt2870_softc
*sc
;
4282 RT2870_DPRINTF(sc
, RT2870_DEBUG_TX
,
4283 "%s: Tx done task\n",
4284 device_get_nameunit(sc
->dev
));
4286 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
4289 for (i
= sc
->usb_endpoints
- 2; i
>= 0; i
--)
4290 rt2870_tx_eof(sc
, &sc
->tx_ring
[i
]);
4294 ifp
->if_drv_flags
&= ~IFF_DRV_OACTIVE
;
4298 * rt2870_periodic_task
4300 static void rt2870_periodic_task(void *context
, int pending
)
4302 struct rt2870_softc
*sc
;
4304 struct ieee80211com
*ic
;
4310 RT2870_DPRINTF(sc
, RT2870_DEBUG_PERIODIC
,
4311 "%s: periodic task: round=%lu\n",
4312 device_get_nameunit(sc
->dev
), sc
->periodic_round
);
4314 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
4317 sc
->periodic_round
++;
4319 rt2870_update_stats(sc
);
4321 if ((sc
->periodic_round
% 10) == 0)
4323 rt2870_update_raw_counters(sc
);
4325 rt2870_watchdog(sc
);
4327 if (ic
->ic_opmode
== IEEE80211_M_STA
)
4328 rt2870_amrr_update_iter_func(sc
, ic
->ic_bss
);
4330 ieee80211_iterate_nodes(&ic
->ic_sta
, rt2870_amrr_update_iter_func
, sc
);
4333 callout_reset(&sc
->periodic_ch
, hz
/ 10, rt2870_periodic
, sc
);
4339 static void rt2870_cmd_task(void *context
, int pending
)
4341 struct rt2870_softc
*sc
;
4342 struct rt2870_softc_cmd_ring
*ring
;
4343 struct rt2870_softc_cmd
*cmd
;
4346 ring
= &sc
->cmd_ring
;
4350 RT2870_SOFTC_LOCK(sc
);
4352 cmd
= STAILQ_FIRST(&ring
->active
);
4355 RT2870_SOFTC_UNLOCK(sc
);
4359 STAILQ_REMOVE_HEAD(&ring
->active
, next
);
4361 RT2870_SOFTC_UNLOCK(sc
);
4363 cmd
->cb(sc
, cmd
->data
);
4365 RT2870_SOFTC_LOCK(sc
);
4367 STAILQ_INSERT_TAIL(&ring
->inactive
, cmd
, next
);
4370 RT2870_SOFTC_UNLOCK(sc
);
4377 static int rt2870_rx_eof(struct rt2870_softc
*sc
, int limit
)
4380 struct rt2870_softc_rx_ring
*ring
;
4381 struct rt2870_softc_rx_data
*data
;
4387 ring
= &sc
->rx_ring
;
4393 RT2870_SOFTC_LOCK(sc
);
4395 data
= STAILQ_FIRST(&ring
->done
);
4398 RT2870_SOFTC_UNLOCK(sc
);
4402 STAILQ_REMOVE_HEAD(&ring
->done
, next
);
4404 RT2870_SOFTC_UNLOCK(sc
);
4409 if (len
< RT2870_RX_DESC_SIZE
)
4415 while (len
> (sizeof(uint32_t) + sizeof(struct rt2870_rxinfo
)))
4417 dmalen
= (le32toh(*(uint32_t *) buf
) & 0xffff);
4419 if (dmalen
== 0 || (dmalen
& 3) != 0)
4421 RT2870_DPRINTF(sc
, RT2870_DEBUG_RX
,
4422 "%s: bad DMA len=%u\n",
4423 device_get_nameunit(sc
->dev
), dmalen
);
4427 if ((dmalen
+ sizeof(uint32_t) + sizeof(struct rt2870_rxinfo
)) > len
)
4429 RT2870_DPRINTF(sc
, RT2870_DEBUG_RX
,
4430 "%s: bad DMA len: DMA len=%u, USB len=%d\n",
4431 device_get_nameunit(sc
->dev
),
4432 (dmalen
+ sizeof(uint32_t) + sizeof(struct rt2870_rxinfo
)), len
);
4438 rt2870_rx_frame(sc
, buf
+ sizeof(uint32_t), dmalen
);
4440 buf
+= (dmalen
+ sizeof(uint32_t) + sizeof(struct rt2870_rxinfo
));
4441 len
-= (dmalen
+ sizeof(uint32_t) + sizeof(struct rt2870_rxinfo
));
4446 RT2870_SOFTC_LOCK(sc
);
4448 STAILQ_INSERT_TAIL(&ring
->active
, data
, next
);
4450 RT2870_SOFTC_UNLOCK(sc
);
4452 usbd_setup_xfer(data
->xfer
, ring
->usb_pipe
, sc
, data
->buf
,
4453 RT2870_USB_RX_BULK_BUFLEN
, USBD_SHORT_XFER_OK
| USBD_NO_COPY
,
4454 USBD_NO_TIMEOUT
, rt2870_rx_intr
);
4456 usbd_transfer(data
->xfer
);
4461 RT2870_DPRINTF(sc
, RT2870_DEBUG_RX
,
4462 "%s: Rx eof: nframes=%d\n",
4463 device_get_nameunit(sc
->dev
), nframes
);
4465 sc
->rx_packets
+= nframes
;
4467 return (limit
== 0);
4473 static void rt2870_tx_eof(struct rt2870_softc
*sc
,
4474 struct rt2870_softc_tx_ring
*ring
)
4477 struct rt2870_softc_tx_data
*data
;
4486 RT2870_SOFTC_LOCK(sc
);
4488 data
= STAILQ_FIRST(&ring
->done
);
4491 RT2870_SOFTC_UNLOCK(sc
);
4495 STAILQ_REMOVE_HEAD(&ring
->done
, next
);
4497 RT2870_SOFTC_UNLOCK(sc
);
4501 if (data
->m
->m_flags
& M_TXCB
)
4502 ieee80211_process_callback(data
->ni
, data
->m
, 0);
4506 ieee80211_free_node(data
->ni
);
4511 RT2870_SOFTC_LOCK(sc
);
4513 STAILQ_INSERT_TAIL(&ring
->inactive
, data
, next
);
4517 RT2870_SOFTC_UNLOCK(sc
);
4522 RT2870_DPRINTF(sc
, RT2870_DEBUG_TX
,
4523 "%s: Tx eof: qid=%d, nframes=%d\n",
4524 device_get_nameunit(sc
->dev
), ring
->qid
, nframes
);
4528 * rt2870_update_stats
4530 static void rt2870_update_stats(struct rt2870_softc
*sc
)
4533 struct ieee80211com
*ic
;
4534 struct ieee80211_node
*ni
;
4538 int txcnt
, retrycnt
, failcnt
;
4543 RT2870_DPRINTF(sc
, RT2870_DEBUG_STATS
,
4544 "%s: update statistic\n",
4545 device_get_nameunit(sc
->dev
));
4547 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
4550 rt2870_drain_fifo_stats(sc
);
4552 if (ic
->ic_opmode
== IEEE80211_M_STA
)
4556 associd
= (ni
!= NULL
) ? ni
->ni_associd
: 0;
4557 wcid
= RT2870_AID2WCID(associd
);
4559 /* read and clear Tx statistic registers */
4561 rt2870_io_mac_read_multi(sc
, RT2870_REG_TX_STA_CNT0
,
4562 stacnt
, sizeof(stacnt
));
4564 txcnt
= le32toh(stacnt
[1]) & 0xffff;
4565 retrycnt
= le32toh(stacnt
[1]) >> 16;
4566 failcnt
= le32toh(stacnt
[0]) & 0xffff;
4568 RT2870_DPRINTF(sc
, RT2870_DEBUG_STATS
,
4569 "%s: update statistic: associd=0x%04x, txcnt=%d, retrycnt=%d, failcnt=%d\n",
4570 device_get_nameunit(sc
->dev
),
4571 associd
, txcnt
, retrycnt
, failcnt
);
4573 ifp
->if_oerrors
+= failcnt
;
4575 rt2870_amrr_tx_update(&sc
->amrr_node
[wcid
],
4576 txcnt
+ retrycnt
+ failcnt
, txcnt
+ retrycnt
, retrycnt
+ failcnt
);
4583 static void rt2870_watchdog(struct rt2870_softc
*sc
)
4588 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_PBF_TXRXQ_PCNT
);
4590 RT2870_DPRINTF(sc
, RT2870_DEBUG_WATCHDOG
,
4591 "%s: watchdog: TXRXQ_PCNT=0x%08x\n",
4592 device_get_nameunit(sc
->dev
), tmp
);
4594 if (((tmp
>> RT2870_REG_TX0Q_PCNT_SHIFT
) & RT2870_REG_TX0Q_PCNT_MASK
) != 0)
4596 sc
->tx_queue_not_empty
[0]++;
4598 rt2870_io_mac_write(sc
, RT2870_REG_PBF_CFG
, 0xf40012);
4600 for (ntries
= 0; ntries
< 10; ntries
++)
4602 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_PBF_TXRXQ_PCNT
);
4603 if (((tmp
>> RT2870_REG_TX0Q_PCNT_SHIFT
) & RT2870_REG_TX0Q_PCNT_MASK
) == 0)
4609 rt2870_io_mac_write(sc
, RT2870_REG_PBF_CFG
, 0xf40006);
4612 if (((tmp
>> RT2870_REG_TX1Q_PCNT_SHIFT
) & RT2870_REG_TX1Q_PCNT_MASK
) != 0)
4614 sc
->tx_queue_not_empty
[1]++;
4616 rt2870_io_mac_write(sc
, RT2870_REG_PBF_CFG
, 0xf4000a);
4618 for (ntries
= 0; ntries
< 10; ntries
++)
4620 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_PBF_TXRXQ_PCNT
);
4621 if (((tmp
>> RT2870_REG_TX1Q_PCNT_SHIFT
) & RT2870_REG_TX1Q_PCNT_MASK
) == 0)
4627 rt2870_io_mac_write(sc
, RT2870_REG_PBF_CFG
, 0xf40006);
4632 * rt2870_drain_fifo_stats
4634 static void rt2870_drain_fifo_stats(struct rt2870_softc
*sc
)
4638 uint8_t wcid
, mcs
, pid
;
4641 ifp
= sc
->ic
.ic_ifp
;
4643 /* drain Tx status FIFO (maxsize = 16) */
4645 while ((stats
= rt2870_io_mac_read(sc
, RT2870_REG_TX_STA_FIFO
)) &
4646 RT2870_REG_TX_STA_FIFO_VALID
)
4648 wcid
= (stats
>> RT2870_REG_TX_STA_FIFO_WCID_SHIFT
) &
4649 RT2870_REG_TX_STA_FIFO_WCID_MASK
;
4651 /* if no ACK was requested, no feedback is available */
4653 if (!(stats
& RT2870_REG_TX_STA_FIFO_ACK_REQ
) || wcid
== 0xff)
4656 /* update AMRR statistic */
4658 ok
= (stats
& RT2870_REG_TX_STA_FIFO_TX_OK
) ? 1 : 0;
4661 mcs
= (stats
>> RT2870_REG_TX_STA_FIFO_MCS_SHIFT
) &
4662 RT2870_REG_TX_STA_FIFO_MCS_MASK
;
4663 pid
= (stats
>> RT2870_REG_TX_STA_FIFO_PID_SHIFT
) &
4664 RT2870_REG_TX_STA_FIFO_PID_MASK
;
4666 if (!ok
|| (mcs
+ 1) != pid
)
4669 rt2870_amrr_tx_complete(&sc
->amrr_node
[wcid
],
4678 * rt2870_update_raw_counters
4680 static void rt2870_update_raw_counters(struct rt2870_softc
*sc
)
4684 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_RX_STA_CNT0
);
4686 sc
->rx_crc_errors
+= tmp
& 0xffff;
4687 sc
->rx_phy_errors
+= tmp
>> 16;
4689 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_RX_STA_CNT1
);
4691 sc
->rx_false_ccas
+= tmp
& 0xffff;
4692 sc
->rx_plcp_errors
+= tmp
>> 16;
4694 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_RX_STA_CNT2
);
4696 sc
->rx_dup_packets
+= tmp
& 0xffff;
4697 sc
->rx_fifo_overflows
+= tmp
>> 16;
4701 * rt2870_alloc_rx_ring
4703 static int rt2870_alloc_rx_ring(struct rt2870_softc
*sc
,
4704 struct rt2870_softc_rx_ring
*ring
)
4706 struct rt2870_softc_rx_data
*data
;
4709 STAILQ_INIT(&ring
->active
);
4710 STAILQ_INIT(&ring
->done
);
4712 for (i
= 0; i
< RT2870_SOFTC_RX_RING_DATA_COUNT
; i
++)
4714 data
= &ring
->data
[i
];
4716 data
->xfer
= usbd_alloc_xfer(sc
->usb_dev
);
4717 if (data
->xfer
== NULL
)
4719 printf("%s: could not allocate Rx xfer\n",
4720 device_get_nameunit(sc
->dev
));
4725 data
->buf
= usbd_alloc_buffer(data
->xfer
, RT2870_USB_RX_BULK_BUFLEN
);
4726 if (data
->buf
== NULL
)
4728 printf("%s: could not allocate Rx buffer\n",
4729 device_get_nameunit(sc
->dev
));
4739 rt2870_free_rx_ring(sc
, ring
);
4745 * rt2870_reset_rx_ring
4747 static void rt2870_reset_rx_ring(struct rt2870_softc
*sc
,
4748 struct rt2870_softc_rx_ring
*ring
)
4750 STAILQ_INIT(&ring
->active
);
4751 STAILQ_INIT(&ring
->done
);
4755 * rt2870_free_rx_ring
4757 static void rt2870_free_rx_ring(struct rt2870_softc
*sc
,
4758 struct rt2870_softc_rx_ring
*ring
)
4760 struct rt2870_softc_rx_data
*data
;
4763 for (i
= 0; i
< RT2870_SOFTC_RX_RING_DATA_COUNT
; i
++)
4765 data
= &ring
->data
[i
];
4767 if (data
->xfer
!= NULL
)
4769 usbd_free_xfer(data
->xfer
);
4776 * rt2870_alloc_tx_ring
4778 static int rt2870_alloc_tx_ring(struct rt2870_softc
*sc
,
4779 struct rt2870_softc_tx_ring
*ring
, int qid
)
4781 struct rt2870_softc_tx_data
*data
;
4784 STAILQ_INIT(&ring
->inactive
);
4785 STAILQ_INIT(&ring
->active
);
4786 STAILQ_INIT(&ring
->done
);
4792 for (i
= 0; i
< RT2870_SOFTC_TX_RING_DATA_COUNT
; i
++)
4794 data
= &ring
->data
[i
];
4796 data
->xfer
= usbd_alloc_xfer(sc
->usb_dev
);
4797 if (data
->xfer
== NULL
)
4799 printf("%s: could not allocate Tx xfer\n",
4800 device_get_nameunit(sc
->dev
));
4805 data
->buf
= usbd_alloc_buffer(data
->xfer
,
4806 RT2870_TX_DESC_SIZE
+ MJUM9BYTES
);
4807 if (data
->buf
== NULL
)
4809 printf("%s: could not allocate Tx buffer\n",
4810 device_get_nameunit(sc
->dev
));
4815 memset(data
->buf
, 0, RT2870_TX_DESC_SIZE
);
4817 STAILQ_INSERT_TAIL(&ring
->inactive
, data
, next
);
4824 rt2870_free_tx_ring(sc
, ring
);
4830 * rt2870_reset_tx_ring
4832 static void rt2870_reset_tx_ring(struct rt2870_softc
*sc
,
4833 struct rt2870_softc_tx_ring
*ring
)
4835 struct rt2870_softc_tx_data
*data
;
4838 STAILQ_INIT(&ring
->inactive
);
4839 STAILQ_INIT(&ring
->active
);
4840 STAILQ_INIT(&ring
->done
);
4844 for (i
= 0; i
< RT2870_SOFTC_TX_RING_DATA_COUNT
; i
++)
4846 data
= &ring
->data
[i
];
4848 if (data
->m
!= NULL
)
4854 if (data
->ni
!= NULL
)
4856 ieee80211_free_node(data
->ni
);
4860 STAILQ_INSERT_TAIL(&ring
->inactive
, data
, next
);
4865 * rt2870_free_tx_ring
4867 static void rt2870_free_tx_ring(struct rt2870_softc
*sc
,
4868 struct rt2870_softc_tx_ring
*ring
)
4870 struct rt2870_softc_tx_data
*data
;
4873 for (i
= 0; i
< RT2870_SOFTC_TX_RING_DATA_COUNT
; i
++)
4875 data
= &ring
->data
[i
];
4877 if (data
->xfer
!= NULL
)
4879 usbd_free_xfer(data
->xfer
);
4883 if (data
->m
!= NULL
)
4889 if (data
->ni
!= NULL
)
4891 ieee80211_free_node(data
->ni
);
4898 * rt2870_reset_cmd_ring
4900 static void rt2870_reset_cmd_ring(struct rt2870_softc
*sc
,
4901 struct rt2870_softc_cmd_ring
*ring
)
4903 struct rt2870_softc_cmd
*cmd
;
4906 STAILQ_INIT(&ring
->inactive
);
4907 STAILQ_INIT(&ring
->active
);
4911 for (i
= 0; i
< RT2870_SOFTC_CMD_RING_CMD_COUNT
; i
++)
4913 cmd
= &ring
->cmd
[i
];
4915 STAILQ_INSERT_TAIL(&ring
->inactive
, cmd
, next
);
4920 * rt2870_sysctl_attach
4922 static void rt2870_sysctl_attach(struct rt2870_softc
*sc
)
4924 struct sysctl_ctx_list
*ctx
;
4925 struct sysctl_oid
*tree
;
4926 struct sysctl_oid
*stats
;
4928 ctx
= device_get_sysctl_ctx(sc
->dev
);
4929 tree
= device_get_sysctl_tree(sc
->dev
);
4931 stats
= SYSCTL_ADD_NODE(ctx
, SYSCTL_CHILDREN(tree
), OID_AUTO
,
4932 "stats", CTLFLAG_RD
, 0, "statistic");
4934 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
4935 "interrupts", CTLFLAG_RD
, &sc
->interrupts
, 0,
4938 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
4939 "rx_interrupts", CTLFLAG_RD
, &sc
->rx_interrupts
, 0,
4942 if (sc
->usb_endpoints
== (RT2870_SOFTC_TX_RING_COUNT
+ 1))
4944 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
4945 "tx_mgmt_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[5], 0,
4946 "Tx MGMT interrupts");
4948 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
4949 "tx_hcca_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[4], 0,
4950 "Tx HCCA interrupts");
4953 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
4954 "tx_ac3_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[3], 0,
4955 "Tx AC3 interrupts");
4957 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
4958 "tx_ac2_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[2], 0,
4959 "Tx AC2 interrupts");
4961 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
4962 "tx_ac1_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[1], 0,
4963 "Tx AC1 interrupts");
4965 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
4966 "tx_ac0_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[0], 0,
4967 "Tx AC0 interrupts");
4969 if (sc
->usb_endpoints
== (RT2870_SOFTC_TX_RING_COUNT
+ 1))
4971 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
4972 "tx_mgmt_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[5].queued
, 0,
4973 "Tx MGMT data queued");
4975 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
4976 "tx_hcca_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[4].queued
, 0,
4977 "Tx HCCA data queued");
4980 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
4981 "tx_ac3_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[3].queued
, 0,
4982 "Tx AC3 data queued");
4984 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
4985 "tx_ac2_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[2].queued
, 0,
4986 "Tx AC2 data queued");
4988 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
4989 "tx_ac1_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[1].queued
, 0,
4990 "Tx AC1 data queued");
4992 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
4993 "tx_ac0_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[0].queued
, 0,
4994 "Tx AC0 data queued");
4996 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
4997 "tx_watchdog_timeouts", CTLFLAG_RD
, &sc
->tx_watchdog_timeouts
, 0,
4998 "Tx watchdog timeouts");
5000 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5001 "tx_queue_0_not_empty", CTLFLAG_RD
, &sc
->tx_queue_not_empty
[0], 0,
5002 "Tx queue 0 not empty");
5004 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5005 "tx_queue_1_not_empty", CTLFLAG_RD
, &sc
->tx_queue_not_empty
[1], 0,
5006 "Tx queue 1 not empty");
5008 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5009 "rx_packets", CTLFLAG_RD
, &sc
->rx_packets
, 0,
5012 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5013 "rx_crc_errors", CTLFLAG_RD
, &sc
->rx_crc_errors
, 0,
5016 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5017 "rx_phy_errors", CTLFLAG_RD
, &sc
->rx_phy_errors
, 0,
5020 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5021 "rx_false_ccas", CTLFLAG_RD
, &sc
->rx_false_ccas
, 0,
5024 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5025 "rx_plcp_errors", CTLFLAG_RD
, &sc
->rx_plcp_errors
, 0,
5028 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5029 "rx_dup_packets", CTLFLAG_RD
, &sc
->rx_dup_packets
, 0,
5030 "Rx duplicate packets");
5032 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5033 "rx_fifo_overflows", CTLFLAG_RD
, &sc
->rx_fifo_overflows
, 0,
5034 "Rx FIFO overflows");
5037 static device_method_t rt2870_dev_methods
[] =
5039 DEVMETHOD(device_probe
, rt2870_probe
),
5040 DEVMETHOD(device_attach
, rt2870_attach
),
5041 DEVMETHOD(device_detach
, rt2870_detach
),
5045 static driver_t rt2870_driver
=
5049 sizeof(struct rt2870_softc
),
5052 static devclass_t rt2870_dev_class
;
5054 DRIVER_MODULE(rt2870
, uhub
, rt2870_driver
, rt2870_dev_class
,
5055 usbd_driver_load
, 0);
5057 MODULE_DEPEND(rt2870
, usb
, 1, 1, 1);
5058 MODULE_DEPEND(rt2870
, wlan
, 1, 1, 1);