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]))
396 SYSCTL_DECL(_hw_rt2870
);
399 static int rt2870_debug
= 0;
400 SYSCTL_INT(_hw_rt2870
, OID_AUTO
, debug
, CTLFLAG_RW
, &rt2870_debug
, 0, "rt2870 debug level");
401 TUNABLE_INT("hw.rt2870.debug", &rt2870_debug
);
407 static int rt2870_probe(device_t dev
)
409 struct usb_attach_arg
*uaa
;
411 uaa
= device_get_ivars(dev
);
413 if (uaa
->iface
!= NULL
)
416 return (usb_lookup(rt2870_usb_devno
, uaa
->vendor
, uaa
->product
) != NULL
) ?
417 UMATCH_VENDOR_PRODUCT
: UMATCH_NONE
;
423 static int rt2870_attach(device_t dev
)
425 struct rt2870_softc
*sc
;
426 struct usb_attach_arg
*uaa
;
427 usbd_status usb_error
;
428 struct ieee80211com
*ic
;
430 int error
, ntries
, i
;
432 sc
= device_get_softc(dev
);
433 uaa
= device_get_ivars(dev
);
436 sc
->usb_dev
= uaa
->device
;
439 sc
->debug
= rt2870_debug
;
441 SYSCTL_ADD_INT(device_get_sysctl_ctx(dev
),
442 SYSCTL_CHILDREN(device_get_sysctl_tree(dev
)), OID_AUTO
,
443 "debug", CTLFLAG_RW
, &sc
->debug
, 0, "rt2870 debug level");
446 RT2870_DPRINTF(sc
, RT2870_DEBUG_ANY
,
448 device_get_nameunit(sc
->dev
));
450 if (usbd_set_config_no(sc
->usb_dev
, RT2870_USB_CONFIG_NO
, 0) != 0)
452 printf("%s: could not set USB configuration no\n",
453 device_get_nameunit(sc
->dev
));
457 usb_error
= usbd_device2interface_handle(sc
->usb_dev
,
458 RT2870_USB_IFACE_INDEX
, &sc
->usb_iface
);
461 printf("%s: could not get USB interface handle\n",
462 device_get_nameunit(sc
->dev
));
466 error
= rt2870_find_usb_endpoints(sc
);
470 for (ntries
= 0; ntries
< 100; ntries
++)
472 sc
->mac_rev
= rt2870_io_mac_read(sc
, RT2870_REG_MAC_CSR0
);
473 if (sc
->mac_rev
!= 0x00000000 && sc
->mac_rev
!= 0xffffffff)
481 printf("%s: timeout waiting for NIC to initialize\n",
482 device_get_nameunit(sc
->dev
));
486 rt2870_read_eeprom(sc
);
488 printf("%s: MAC/BBP RT2870 (rev 0x%08x), RF %s\n",
489 device_get_nameunit(sc
->dev
), sc
->mac_rev
,
490 rt2870_rf_name(sc
->rf_rev
));
492 /* open Tx and Rx USB bulk pipes */
494 for (i
= 0; i
< sc
->usb_endpoints
- 1; i
++)
496 error
= usbd_open_pipe(sc
->usb_iface
, sc
->tx_ring
[i
].usb_ep
,
497 USBD_EXCLUSIVE_USE
, &sc
->tx_ring
[i
].usb_pipe
);
500 printf("%s: could not open Tx pipe #%d: %s\n",
501 device_get_nameunit(sc
->dev
), i
, usbd_errstr(error
));
506 error
= usbd_open_pipe(sc
->usb_iface
, sc
->rx_ring
.usb_ep
,
507 USBD_EXCLUSIVE_USE
, &sc
->rx_ring
.usb_pipe
);
510 printf("%s: could not open Rx pipe: %s\n",
511 device_get_nameunit(sc
->dev
), usbd_errstr(error
));
515 /* allocate Tx and Rx rings */
517 for (i
= 0; i
< sc
->usb_endpoints
- 1; i
++)
519 error
= rt2870_alloc_tx_ring(sc
, &sc
->tx_ring
[i
], i
);
522 printf("%s: could not allocate Tx ring #%d\n",
523 device_get_nameunit(sc
->dev
), i
);
528 if (sc
->usb_endpoints
== (RT2870_SOFTC_TX_RING_COUNT
+ 1))
529 sc
->tx_ring_mgtqid
= 5;
531 sc
->tx_ring_mgtqid
= 0;
533 error
= rt2870_alloc_rx_ring(sc
, &sc
->rx_ring
);
536 printf("%s: could not allocate Rx ring\n",
537 device_get_nameunit(sc
->dev
));
541 callout_init(&sc
->periodic_ch
, 0);
542 callout_init(&sc
->tx_watchdog_ch
, 0);
544 ifp
= sc
->ifp
= if_alloc(IFT_ETHER
);
547 printf("%s: could not if_alloc()\n",
548 device_get_nameunit(sc
->dev
));
555 if_initname(ifp
, "rt2870", device_get_unit(sc
->dev
));
557 ifp
->if_flags
= IFF_BROADCAST
| IFF_SIMPLEX
| IFF_MULTICAST
|
560 ifp
->if_init
= rt2870_init
;
561 ifp
->if_ioctl
= rt2870_ioctl
;
562 ifp
->if_start
= rt2870_start
;
564 IFQ_SET_MAXLEN(&ifp
->if_snd
, IFQ_MAXLEN
);
565 ifp
->if_snd
.ifq_drv_maxlen
= IFQ_MAXLEN
;
566 IFQ_SET_READY(&ifp
->if_snd
);
572 ic
->ic_phytype
= IEEE80211_T_HT
;
573 ic
->ic_opmode
= IEEE80211_M_STA
;
574 ic
->ic_state
= IEEE80211_S_INIT
;
576 ic
->ic_caps
= IEEE80211_C_MONITOR
|
581 /* IEEE80211_C_BGSCAN | */
583 IEEE80211_C_SHPREAMBLE
|
590 IEEE80211_C_AES_CCM
|
593 ic
->ic_htcaps
= IEEE80211_HTC_HT
|
594 IEEE80211_HTC_AMSDU
| /* A-MSDU Tx */
595 IEEE80211_HTCAP_MAXAMSDU_3839
| /* max. A-MSDU Rx length */
596 IEEE80211_HTCAP_CHWIDTH40
| /* HT 40MHz channel width */
597 IEEE80211_HTCAP_GREENFIELD
| /* HT greenfield */
598 IEEE80211_HTCAP_SHORTGI20
| /* HT 20MHz short GI */
599 IEEE80211_HTCAP_SHORTGI40
| /* HT 40MHz short GI */
600 IEEE80211_HTCAP_DSSSCCK40
; /* HT 40MHz DSSS/CCK modulation */
602 /* spatial streams */
604 if (sc
->nrxpath
== 2)
605 ic
->ic_htcaps
|= IEEE80211_HTCAP_RXSTBC_2STREAM
;
606 else if (sc
->nrxpath
== 3)
607 ic
->ic_htcaps
|= IEEE80211_HTCAP_RXSTBC_3STREAM
;
609 ic
->ic_htcaps
|= IEEE80211_HTCAP_RXSTBC_1STREAM
;
612 ic
->ic_htcaps
|= IEEE80211_HTCAP_TXSTBC
;
616 if (sc
->mac_rev
!= 0x28600100)
617 ic
->ic_htcaps
|= IEEE80211_HTCAP_DELBA
;
622 ic
->ic_regdomain
= 0;
623 ic
->ic_countrycode
= CTRY_DEFAULT
;
626 rt2870_init_channels(sc
);
628 rt2870_init_channels_ht40(sc
);
630 IEEE80211_ADDR_COPY(ic
->ic_myaddr
, sc
->mac_addr
);
632 ieee80211_ifattach(ic
);
634 sc
->newstate
= ic
->ic_newstate
;
635 ic
->ic_newstate
= rt2870_newstate
;
637 ic
->ic_reset
= rt2870_reset
;
638 ic
->ic_scan_start
= rt2870_scan_start
;
639 ic
->ic_scan_end
= rt2870_scan_end
;
640 ic
->ic_set_channel
= rt2870_set_channel
;
641 ic
->ic_newassoc
= rt2870_newassoc
;
642 ic
->ic_updateslot
= rt2870_updateslot
;
643 ic
->ic_wme
.wme_update
= rt2870_wme_update
;
644 ic
->ic_update_beacon
= rt2870_update_beacon
;
645 ic
->ic_crypto
.cs_key_update_begin
= rt2870_key_update_begin
;
646 ic
->ic_crypto
.cs_key_update_end
= rt2870_key_update_end
;
647 ic
->ic_crypto
.cs_key_set
= rt2870_key_set
;
648 ic
->ic_crypto
.cs_key_delete
= rt2870_key_delete
;
649 ic
->ic_raw_xmit
= rt2870_raw_xmit
;
651 sc
->recv_action
= ic
->ic_recv_action
;
652 ic
->ic_recv_action
= rt2870_recv_action
;
654 sc
->send_action
= ic
->ic_send_action
;
655 ic
->ic_send_action
= rt2870_send_action
;
657 /* hardware requires padding between 802.11 frame header and body */
659 ic
->ic_flags
|= IEEE80211_F_WME
| IEEE80211_F_DATAPAD
| IEEE80211_F_DOTH
;
661 ic
->ic_flags_ext
|= IEEE80211_FEXT_SWBMISS
;
663 ieee80211_media_init(ic
, rt2870_media_change
, ieee80211_media_status
);
665 rt2870_amrr_init(&sc
->amrr
, ic
,
666 RT2870_AMRR_MIN_SUCCESS_THRESHOLD
,
667 RT2870_AMRR_MAX_SUCCESS_THRESHOLD
,
670 bpfattach2(ifp
, DLT_IEEE802_11_RADIO
,
671 sizeof(struct ieee80211_frame
) + IEEE80211_RADIOTAP_HDRLEN
,
674 sc
->rxtap_len
= sizeof(sc
->rxtapu
);
675 sc
->rxtap
.ihdr
.it_len
= htole16(sc
->rxtap_len
);
676 sc
->rxtap
.ihdr
.it_present
= htole32(RT2870_SOFTC_RX_RADIOTAP_PRESENT
);
678 sc
->txtap_len
= sizeof(sc
->txtapu
);
679 sc
->txtap
.ihdr
.it_len
= htole16(sc
->txtap_len
);
680 sc
->txtap
.ihdr
.it_present
= htole32(RT2870_SOFTC_TX_RADIOTAP_PRESENT
);
682 /* init task queue */
684 TASK_INIT(&sc
->rx_done_task
, 0, rt2870_rx_done_task
, sc
);
685 TASK_INIT(&sc
->tx_done_task
, 0, rt2870_tx_done_task
, sc
);
686 TASK_INIT(&sc
->periodic_task
, 0, rt2870_periodic_task
, sc
);
687 TASK_INIT(&sc
->cmd_task
, 0, rt2870_cmd_task
, sc
);
689 sc
->rx_process_limit
= 100;
691 sc
->taskqueue
= taskqueue_create("rt2870_taskq", M_NOWAIT
,
692 taskqueue_thread_enqueue
, &sc
->taskqueue
);
694 taskqueue_start_threads(&sc
->taskqueue
, 1, PI_NET
, "%s taskq",
695 device_get_nameunit(sc
->dev
));
697 rt2870_sysctl_attach(sc
);
700 ieee80211_announce(ic
);
702 usbd_add_drv_event(USB_EVENT_DRIVER_ATTACH
, sc
->usb_dev
, sc
->dev
);
708 /* close Tx and Rx USB bulk pipes */
710 if (sc
->rx_ring
.usb_pipe
!= NULL
)
712 usbd_abort_pipe(sc
->rx_ring
.usb_pipe
);
713 usbd_close_pipe(sc
->rx_ring
.usb_pipe
);
714 sc
->rx_ring
.usb_pipe
= NULL
;
717 for (i
= 0; i
< sc
->usb_endpoints
- 1; i
++)
719 if (sc
->tx_ring
[i
].usb_pipe
!= NULL
)
721 usbd_abort_pipe(sc
->tx_ring
[i
].usb_pipe
);
722 usbd_close_pipe(sc
->tx_ring
[i
].usb_pipe
);
723 sc
->tx_ring
[i
].usb_pipe
= NULL
;
727 /* free Tx and Rx rings */
729 for (i
= 0; i
< sc
->usb_endpoints
- 1; i
++)
730 rt2870_free_tx_ring(sc
, &sc
->tx_ring
[i
]);
732 rt2870_free_rx_ring(sc
, &sc
->rx_ring
);
740 static int rt2870_detach(device_t dev
)
742 struct rt2870_softc
*sc
;
743 struct ieee80211com
*ic
;
747 if (!device_is_attached(dev
))
750 sc
= device_get_softc(dev
);
754 RT2870_DPRINTF(sc
, RT2870_DEBUG_ANY
,
756 device_get_nameunit(sc
->dev
));
760 ifp
->if_drv_flags
&= ~(IFF_DRV_RUNNING
| IFF_DRV_OACTIVE
);
762 ieee80211_new_state(ic
, IEEE80211_S_INIT
, -1);
764 callout_stop(&sc
->periodic_ch
);
765 callout_stop(&sc
->tx_watchdog_ch
);
767 taskqueue_drain(sc
->taskqueue
, &sc
->rx_done_task
);
768 taskqueue_drain(sc
->taskqueue
, &sc
->tx_done_task
);
769 taskqueue_drain(sc
->taskqueue
, &sc
->periodic_task
);
770 taskqueue_drain(sc
->taskqueue
, &sc
->cmd_task
);
772 /* close Tx and Rx USB bulk pipes */
774 if (sc
->rx_ring
.usb_pipe
!= NULL
)
776 usbd_abort_pipe(sc
->rx_ring
.usb_pipe
);
777 usbd_close_pipe(sc
->rx_ring
.usb_pipe
);
778 sc
->rx_ring
.usb_pipe
= NULL
;
781 for (i
= 0; i
< sc
->usb_endpoints
- 1; i
++)
783 if (sc
->tx_ring
[i
].usb_pipe
!= NULL
)
785 usbd_abort_pipe(sc
->tx_ring
[i
].usb_pipe
);
786 usbd_close_pipe(sc
->tx_ring
[i
].usb_pipe
);
787 sc
->tx_ring
[i
].usb_pipe
= NULL
;
791 /* free Tx and Rx rings */
793 for (i
= 0; i
< sc
->usb_endpoints
- 1; i
++)
794 rt2870_free_tx_ring(sc
, &sc
->tx_ring
[i
]);
796 rt2870_free_rx_ring(sc
, &sc
->rx_ring
);
800 ieee80211_ifdetach(ic
);
804 taskqueue_free(sc
->taskqueue
);
806 usbd_add_drv_event(USB_EVENT_DRIVER_DETACH
, sc
->usb_dev
, sc
->dev
);
812 * rt2870_find_usb_endpoints
814 static int rt2870_find_usb_endpoints(struct rt2870_softc
*sc
)
816 usb_interface_descriptor_t
*id
;
817 usb_endpoint_descriptor_t
*ed
;
820 id
= usbd_get_interface_descriptor(sc
->usb_iface
);
822 sc
->usb_endpoints
= id
->bNumEndpoints
;
823 if ((sc
->usb_endpoints
!= (RT2870_SOFTC_TX_RING_COUNT
+ 1)) &&
824 (sc
->usb_endpoints
!= (RT2870_SOFTC_TX_RING_COUNT
- 2 + 1)))
826 printf("%s: wrong number of USB endpoints=%d\n",
827 device_get_nameunit(sc
->dev
), sc
->usb_endpoints
);
831 sc
->rx_ring
.usb_ep
= -1;
833 for (i
= 0; i
< RT2870_SOFTC_TX_RING_COUNT
; i
++)
834 sc
->tx_ring
[i
].usb_ep
= -1;
836 for (i
= 0, j
= 0; i
< id
->bNumEndpoints
; i
++)
838 ed
= usbd_interface2endpoint_descriptor(sc
->usb_iface
, i
);
841 printf("%s: no endpoint descriptor #%d for USB interface\n",
842 device_get_nameunit(sc
->dev
), i
);
846 if (UE_GET_DIR(ed
->bEndpointAddress
) == UE_DIR_IN
&&
847 UE_GET_XFERTYPE(ed
->bmAttributes
) == UE_BULK
)
849 sc
->rx_ring
.usb_ep
= ed
->bEndpointAddress
;
851 else if (UE_GET_DIR(ed
->bEndpointAddress
) == UE_DIR_OUT
&&
852 UE_GET_XFERTYPE(ed
->bmAttributes
) == UE_BULK
)
854 if (j
< RT2870_SOFTC_TX_RING_COUNT
)
855 sc
->tx_ring
[j
++].usb_ep
= ed
->bEndpointAddress
;
857 sc
->tx_ring
[RT2870_SOFTC_TX_RING_COUNT
- 1].usb_ep
=
858 ed
->bEndpointAddress
;
862 if ((sc
->rx_ring
.usb_ep
== -1) ||
863 ((j
!= RT2870_SOFTC_TX_RING_COUNT
) && (j
!= RT2870_SOFTC_TX_RING_COUNT
- 2)))
865 printf("%s: missing USB endpoints\n",
866 device_get_nameunit(sc
->dev
));
874 * rt2870_init_channels
876 static void rt2870_init_channels(struct rt2870_softc
*sc
)
878 struct ieee80211com
*ic
;
879 struct ieee80211_channel
*c
;
884 /* set supported channels for 2GHz band */
886 for (i
= 1; i
<= 14; i
++)
888 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
889 flags
= IEEE80211_CHAN_B
;
891 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
895 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
896 flags
= IEEE80211_CHAN_B
| IEEE80211_CHAN_HT20
;
898 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
902 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
903 flags
= IEEE80211_CHAN_G
;
905 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
909 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
910 flags
= IEEE80211_CHAN_G
| IEEE80211_CHAN_HT20
;
912 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
917 /* set supported channels for 5GHz band */
919 if (sc
->rf_rev
== RT2870_EEPROM_RF_2850
||
920 sc
->rf_rev
== RT2870_EEPROM_RF_2750
)
922 for (i
= 36; i
<= 64; i
+= 4)
924 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
925 flags
= IEEE80211_CHAN_A
;
927 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
931 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
932 flags
= IEEE80211_CHAN_A
| IEEE80211_CHAN_HT20
;
934 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
939 for (i
= 100; i
<= 140; i
+= 4)
941 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
942 flags
= IEEE80211_CHAN_A
;
944 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
948 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
949 flags
= IEEE80211_CHAN_A
| IEEE80211_CHAN_HT20
;
951 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
956 for (i
= 149; i
<= 165; i
+= 4)
958 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
959 flags
= IEEE80211_CHAN_A
;
961 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
965 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
966 flags
= IEEE80211_CHAN_A
| IEEE80211_CHAN_HT20
;
968 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
976 * rt2870_init_channels_ht40
978 static void rt2870_init_channels_ht40(struct rt2870_softc
*sc
)
980 struct ieee80211com
*ic
;
981 struct ieee80211_channel
*c
, *cent
, *ext
;
986 /* set supported channels for 2GHz band */
988 for (i
= 1; i
<= 14; i
++)
990 flags
= IEEE80211_CHAN_G
| IEEE80211_CHAN_HT40
;
992 /* find the center channel */
994 cent
= ieee80211_find_channel_byieee(ic
, i
,
995 flags
& ~IEEE80211_CHAN_HT
);
998 printf("%s: skip channel %d, could not find center channel\n",
999 device_get_nameunit(sc
->dev
), i
);
1003 /* find the extension channel */
1005 ext
= ieee80211_find_channel(ic
, cent
->ic_freq
+ 20,
1006 flags
& ~IEEE80211_CHAN_HT
);
1009 printf("%s: skip channel %d, could not find extension channel\n",
1010 device_get_nameunit(sc
->dev
), i
);
1014 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1017 c
->ic_extieee
= ext
->ic_ieee
;
1018 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1019 c
->ic_flags
|= IEEE80211_CHAN_HT40U
;
1021 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1024 c
->ic_extieee
= cent
->ic_ieee
;
1025 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1026 c
->ic_flags
|= IEEE80211_CHAN_HT40D
;
1029 /* set supported channels for 5GHz band */
1031 if (sc
->rf_rev
== RT2870_EEPROM_RF_2850
||
1032 sc
->rf_rev
== RT2870_EEPROM_RF_2750
)
1034 for (i
= 36; i
<= 64; i
+= 4)
1036 flags
= IEEE80211_CHAN_A
| IEEE80211_CHAN_HT40
;
1038 /* find the center channel */
1040 cent
= ieee80211_find_channel_byieee(ic
, i
,
1041 flags
& ~IEEE80211_CHAN_HT
);
1044 printf("%s: skip channel %d, could not find center channel\n",
1045 device_get_nameunit(sc
->dev
), i
);
1049 /* find the extension channel */
1051 ext
= ieee80211_find_channel(ic
, cent
->ic_freq
+ 20,
1052 flags
& ~IEEE80211_CHAN_HT
);
1055 printf("%s: skip channel %d, could not find extension channel\n",
1056 device_get_nameunit(sc
->dev
), i
);
1060 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1063 c
->ic_extieee
= ext
->ic_ieee
;
1064 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1065 c
->ic_flags
|= IEEE80211_CHAN_HT40U
;
1067 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1070 c
->ic_extieee
= cent
->ic_ieee
;
1071 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1072 c
->ic_flags
|= IEEE80211_CHAN_HT40D
;
1075 for (i
= 100; i
<= 140; i
+= 4)
1077 flags
= IEEE80211_CHAN_A
| IEEE80211_CHAN_HT40
;
1079 /* find the center channel */
1081 cent
= ieee80211_find_channel_byieee(ic
, i
,
1082 flags
& ~IEEE80211_CHAN_HT
);
1085 printf("%s: skip channel %d, could not find center channel\n",
1086 device_get_nameunit(sc
->dev
), i
);
1090 /* find the extension channel */
1092 ext
= ieee80211_find_channel(ic
, cent
->ic_freq
+ 20,
1093 flags
& ~IEEE80211_CHAN_HT
);
1096 printf("%s: skip channel %d, could not find extension channel\n",
1097 device_get_nameunit(sc
->dev
), i
);
1101 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1104 c
->ic_extieee
= ext
->ic_ieee
;
1105 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1106 c
->ic_flags
|= IEEE80211_CHAN_HT40U
;
1108 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1111 c
->ic_extieee
= cent
->ic_ieee
;
1112 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1113 c
->ic_flags
|= IEEE80211_CHAN_HT40D
;
1116 for (i
= 149; i
<= 165; i
+= 4)
1118 flags
= IEEE80211_CHAN_A
| IEEE80211_CHAN_HT40
;
1120 /* find the center channel */
1122 cent
= ieee80211_find_channel_byieee(ic
, i
,
1123 flags
& ~IEEE80211_CHAN_HT
);
1126 printf("%s: skip channel %d, could not find center channel\n",
1127 device_get_nameunit(sc
->dev
), i
);
1131 /* find the extension channel */
1133 ext
= ieee80211_find_channel(ic
, cent
->ic_freq
+ 20,
1134 flags
& ~IEEE80211_CHAN_HT
);
1137 printf("%s: skip channel %d, could not find extension channel\n",
1138 device_get_nameunit(sc
->dev
), i
);
1142 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1145 c
->ic_extieee
= ext
->ic_ieee
;
1146 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1147 c
->ic_flags
|= IEEE80211_CHAN_HT40U
;
1149 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1152 c
->ic_extieee
= cent
->ic_ieee
;
1153 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1154 c
->ic_flags
|= IEEE80211_CHAN_HT40D
;
1160 * rt2870_init_locked
1162 static void rt2870_init_locked(void *priv
)
1164 struct rt2870_softc
*sc
;
1165 struct ieee80211com
*ic
;
1167 struct rt2870_softc_rx_data
*data
;
1168 int ntries
, error
, i
;
1169 uint32_t tmp
, stacnt
[6];
1175 RT2870_DPRINTF(sc
, RT2870_DEBUG_ANY
,
1176 "%s: initializing\n",
1177 device_get_nameunit(sc
->dev
));
1179 if (!(sc
->flags
& RT2870_SOFTC_FLAGS_UCODE_LOADED
))
1181 RT2870_DPRINTF(sc
, RT2870_DEBUG_ANY
,
1182 "%s: loading 8051 microcode\n",
1183 device_get_nameunit(sc
->dev
));
1185 error
= rt2870_io_mcu_load_ucode(sc
, rt2870_ucode
, sizeof(rt2870_ucode
));
1188 printf("%s: could not load 8051 microcode\n",
1189 device_get_nameunit(sc
->dev
));
1193 RT2870_DPRINTF(sc
, RT2870_DEBUG_ANY
,
1194 "%s: 8051 microcode was successfully loaded\n",
1195 device_get_nameunit(sc
->dev
));
1197 sc
->flags
|= RT2870_SOFTC_FLAGS_UCODE_LOADED
;
1200 /* wait while DMA engine is busy */
1202 for (ntries
= 0; ntries
< 100; ntries
++)
1204 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_SCHDMA_WPDMA_GLO_CFG
);
1205 if (!(tmp
& (RT2870_REG_TX_DMA_BUSY
| RT2870_REG_RX_DMA_BUSY
)))
1213 printf("%s: timeout waiting for DMA engine\n",
1214 device_get_nameunit(sc
->dev
));
1219 tmp
|= RT2870_REG_TX_WB_DDONE
;
1221 rt2870_io_mac_write(sc
, RT2870_REG_SCHDMA_WPDMA_GLO_CFG
, tmp
);
1223 /* PBF hardware reset */
1225 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_PBF_SYS_CTRL
);
1229 rt2870_io_mac_write(sc
, RT2870_REG_PBF_SYS_CTRL
, tmp
);
1231 rt2870_io_mac_write(sc
, RT2870_REG_SYS_CTRL
,
1232 RT2870_REG_MAC_SRST
| RT2870_REG_BBP_HRST
);
1234 rt2870_io_mac_write(sc
, RT2870_REG_SCHDMA_USB_DMA_CFG
, 0);
1236 rt2870_io_mcu_reset(sc
);
1238 rt2870_io_mac_write(sc
, RT2870_REG_SYS_CTRL
, 0);
1240 /* init Tx power per rate */
1242 for (i
= 0; i
< RT2870_SOFTC_TXPOW_RATE_COUNT
; i
++)
1244 if (sc
->txpow_rate_20mhz
[i
] == 0xffffffff)
1247 rt2870_io_mac_write(sc
, RT2870_REG_TX_PWR_CFG(i
),
1248 sc
->txpow_rate_20mhz
[i
]);
1251 for (i
= 0; i
< RT2870_DEF_MAC_SIZE
; i
++)
1252 rt2870_io_mac_write(sc
, rt2870_def_mac
[i
].reg
,
1253 rt2870_def_mac
[i
].val
);
1255 /* wait while MAC is busy */
1257 for (ntries
= 0; ntries
< 100; ntries
++)
1259 if (!(rt2870_io_mac_read(sc
, RT2870_REG_STATUS_CFG
) &
1260 (RT2870_REG_STATUS_TX_BUSY
| RT2870_REG_STATUS_RX_BUSY
)))
1268 printf("%s: timeout waiting for MAC\n",
1269 device_get_nameunit(sc
->dev
));
1273 /* clear Host to MCU mailbox */
1275 rt2870_io_mac_write(sc
, RT2870_REG_H2M_MAILBOX_BBP_AGENT
, 0);
1276 rt2870_io_mac_write(sc
, RT2870_REG_H2M_MAILBOX
, 0);
1280 error
= rt2870_init_bbp(sc
);
1284 /* set up maximum buffer sizes */
1286 tmp
= (1 << 12) | RT2870_MAX_AGG_SIZE
;
1288 if (sc
->mac_rev
>= 0x28720200 && sc
->mac_rev
< 0x30700200)
1294 rt2870_io_mac_write(sc
, RT2870_REG_MAX_LEN_CFG
, tmp
);
1296 /* set mac address */
1298 IEEE80211_ADDR_COPY(ic
->ic_myaddr
, IF_LLADDR(ifp
));
1300 rt2870_asic_set_macaddr(sc
, ic
->ic_myaddr
);
1302 /* clear statistic registers */
1304 rt2870_io_mac_read_multi(sc
, RT2870_REG_RX_STA_CNT0
,
1305 stacnt
, sizeof(stacnt
));
1307 /* send LEDs operating mode to microcontroller */
1309 rt2870_io_mcu_cmd(sc
, RT2870_IO_MCU_CMD_LED1
,
1310 RT2870_REG_H2M_TOKEN_NO_INTR
, sc
->led_off
[0]);
1311 rt2870_io_mcu_cmd(sc
, RT2870_IO_MCU_CMD_LED2
,
1312 RT2870_REG_H2M_TOKEN_NO_INTR
, sc
->led_off
[1]);
1313 rt2870_io_mcu_cmd(sc
, RT2870_IO_MCU_CMD_LED3
,
1314 RT2870_REG_H2M_TOKEN_NO_INTR
, sc
->led_off
[2]);
1316 /* write vendor-specific BBP values (from EEPROM) */
1318 for (i
= 0; i
< RT2870_SOFTC_BBP_EEPROM_COUNT
; i
++)
1320 if (sc
->bbp_eeprom
[i
].reg
== 0x00 ||
1321 sc
->bbp_eeprom
[i
].reg
== 0xff)
1324 rt2870_io_bbp_write(sc
, sc
->bbp_eeprom
[i
].reg
,
1325 sc
->bbp_eeprom
[i
].val
);
1328 /* disable non-existing Rx chains */
1330 tmp
= rt2870_io_bbp_read(sc
, 3);
1332 tmp
&= ~((1 << 4) | (1 << 3));
1334 if (sc
->nrxpath
== 3)
1336 else if (sc
->nrxpath
== 2)
1339 rt2870_io_bbp_write(sc
, 3, tmp
);
1341 /* disable non-existing Tx chains */
1343 tmp
= rt2870_io_bbp_read(sc
, 1);
1345 if (sc
->ntxpath
== 1)
1346 tmp
&= ~((1 << 4) | (1 << 3));
1348 rt2870_io_bbp_write(sc
, 1, tmp
);
1350 tmp
= rt2870_io_bbp_read(sc
, 4);
1354 rt2870_io_bbp_write(sc
, 4, tmp
);
1356 /* set current channel */
1358 rt2870_rf_set_chan(sc
, ic
->ic_curchan
);
1360 /* turn radio LED on */
1362 rt2870_led_cmd(sc
, RT2870_LED_CMD_RADIO_ON
);
1364 rt2870_io_mcu_cmd(sc
, RT2870_IO_MCU_CMD_BOOT
,
1365 RT2870_REG_H2M_TOKEN_NO_INTR
, 0);
1367 /* set RTS threshold */
1369 rt2870_asic_update_rtsthreshold(sc
);
1373 rt2870_asic_update_txpower(sc
);
1375 /* set up protection mode */
1377 rt2870_asic_updateprot(sc
);
1379 /* clear key tables */
1381 rt2870_asic_clear_keytables(sc
);
1383 /* enable Tx/Rx DMA engine */
1385 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_SCHDMA_USB_CYC_CFG
);
1390 rt2870_io_mac_write(sc
, RT2870_REG_SCHDMA_USB_CYC_CFG
, tmp
);
1392 if ((sc
->mac_rev
& 0xffff) != 0x0101)
1393 rt2870_io_mac_write(sc
, RT2870_REG_TX_TXOP_CTRL_CFG
, 0x583f);
1395 rt2870_io_mac_write(sc
, RT2870_REG_SYS_CTRL
, RT2870_REG_TX_ENABLE
);
1397 for (ntries
= 0; ntries
< 200; ntries
++)
1399 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_SCHDMA_WPDMA_GLO_CFG
);
1400 if (!(tmp
& (RT2870_REG_TX_DMA_BUSY
| RT2870_REG_RX_DMA_BUSY
)))
1408 printf("%s: timeout waiting for DMA engine\n",
1409 device_get_nameunit(sc
->dev
));
1415 rt2870_io_mac_write(sc
, RT2870_REG_SCHDMA_WMM_TXOP0_CFG
, 0);
1416 rt2870_io_mac_write(sc
, RT2870_REG_SCHDMA_WMM_TXOP1_CFG
,
1419 tmp
|= RT2870_REG_TX_WB_DDONE
|
1420 RT2870_REG_RX_DMA_ENABLE
|
1421 RT2870_REG_TX_DMA_ENABLE
;
1423 rt2870_io_mac_write(sc
, RT2870_REG_SCHDMA_WPDMA_GLO_CFG
, tmp
);
1425 tmp
= RT2870_REG_USB_DMA_TX_ENABLE
|
1426 RT2870_REG_USB_DMA_RX_ENABLE
|
1427 RT2870_REG_USB_DMA_RX_AGG_ENABLE
|
1428 /* Rx agg limit in unit of 1024 byte */
1429 ((RT2870_USB_RX_BULK_BUFLEN
/ 1024 - 3) << RT2870_REG_USB_DMA_RX_AGG_LIMIT_SHIFT
) |
1430 /* Rx agg timeout in unit of 33ns */
1433 rt2870_io_mac_write(sc
, RT2870_REG_SCHDMA_USB_DMA_CFG
, tmp
);
1437 tmp
= RT2870_REG_RX_FILTER_DROP_CRC_ERR
|
1438 RT2870_REG_RX_FILTER_DROP_PHY_ERR
;
1440 if (ic
->ic_opmode
!= IEEE80211_M_MONITOR
)
1442 tmp
|= RT2870_REG_RX_FILTER_DROP_DUPL
|
1443 RT2870_REG_RX_FILTER_DROP_CTS
|
1444 RT2870_REG_RX_FILTER_DROP_BA
|
1445 RT2870_REG_RX_FILTER_DROP_ACK
|
1446 RT2870_REG_RX_FILTER_DROP_VER_ERR
|
1447 RT2870_REG_RX_FILTER_DROP_CTRL_RSV
|
1448 RT2870_REG_RX_FILTER_DROP_CFACK
|
1449 RT2870_REG_RX_FILTER_DROP_CFEND
;
1451 if (ic
->ic_opmode
== IEEE80211_M_STA
)
1452 tmp
|= RT2870_REG_RX_FILTER_DROP_RTS
|
1453 RT2870_REG_RX_FILTER_DROP_PSPOLL
;
1455 if (!(ifp
->if_flags
& IFF_PROMISC
))
1456 tmp
|= RT2870_REG_RX_FILTER_DROP_UC_NOME
;
1459 rt2870_io_mac_write(sc
, RT2870_REG_RX_FILTER_CFG
, tmp
);
1461 rt2870_io_mac_write(sc
, RT2870_REG_SYS_CTRL
,
1462 RT2870_REG_RX_ENABLE
| RT2870_REG_TX_ENABLE
);
1464 /* clear garbage interrupts */
1466 tmp
= rt2870_io_mac_read(sc
, 0x1300);
1468 taskqueue_unblock(sc
->taskqueue
);
1470 /* init Tx and Rx rings */
1472 for(i
= 0; i
< sc
->usb_endpoints
- 1; i
++)
1473 rt2870_reset_tx_ring(sc
, &sc
->tx_ring
[i
]);
1475 rt2870_reset_rx_ring(sc
, &sc
->rx_ring
);
1477 rt2870_reset_cmd_ring(sc
, &sc
->cmd_ring
);
1479 /* start up the receive pipe */
1481 for (i
= 0; i
< RT2870_SOFTC_RX_RING_DATA_COUNT
; i
++)
1483 data
= &sc
->rx_ring
.data
[i
];
1485 STAILQ_INSERT_TAIL(&sc
->rx_ring
.active
, data
, next
);
1487 usbd_setup_xfer(data
->xfer
, sc
->rx_ring
.usb_pipe
, sc
, data
->buf
,
1488 RT2870_USB_RX_BULK_BUFLEN
, USBD_SHORT_XFER_OK
| USBD_NO_COPY
,
1489 USBD_NO_TIMEOUT
, rt2870_rx_intr
);
1491 usbd_transfer(data
->xfer
);
1494 ifp
->if_drv_flags
&= ~IFF_DRV_OACTIVE
;
1495 ifp
->if_drv_flags
|= IFF_DRV_RUNNING
;
1497 if (ic
->ic_opmode
!= IEEE80211_M_MONITOR
)
1499 if (ic
->ic_roaming
!= IEEE80211_ROAMING_MANUAL
)
1500 ieee80211_new_state(ic
, IEEE80211_S_SCAN
, -1);
1504 ieee80211_new_state(ic
, IEEE80211_S_RUN
, -1);
1507 sc
->periodic_round
= 0;
1509 callout_reset(&sc
->periodic_ch
, hz
/ 10, rt2870_periodic
, sc
);
1515 rt2870_stop_locked(sc
);
1521 static void rt2870_init(void *priv
)
1523 struct rt2870_softc
*sc
;
1527 rt2870_init_locked(sc
);
1533 static int rt2870_init_bbp(struct rt2870_softc
*sc
)
1538 for (ntries
= 0; ntries
< 20; ntries
++)
1540 tmp
= rt2870_io_bbp_read(sc
, 0);
1541 if (tmp
!= 0x00 && tmp
!= 0xff)
1545 if (tmp
== 0x00 || tmp
== 0xff)
1547 printf("%s: timeout waiting for BBP to wakeup\n",
1548 device_get_nameunit(sc
->dev
));
1552 for (i
= 0; i
< RT2870_DEF_BBP_SIZE
; i
++)
1553 rt2870_io_bbp_write(sc
, rt2870_def_bbp
[i
].reg
,
1554 rt2870_def_bbp
[i
].val
);
1556 if ((sc
->mac_rev
& 0xffff) != 0x0101)
1557 rt2870_io_bbp_write(sc
, 84, 0x19);
1565 static void rt2870_stop_locked(void *priv
)
1567 struct rt2870_softc
*sc
;
1568 struct ieee80211com
*ic
;
1577 RT2870_DPRINTF(sc
, RT2870_DEBUG_ANY
,
1579 device_get_nameunit(sc
->dev
));
1583 if (ifp
->if_drv_flags
& IFF_DRV_RUNNING
)
1584 rt2870_led_cmd(sc
, RT2870_LED_CMD_RADIO_OFF
);
1586 ifp
->if_drv_flags
&= ~(IFF_DRV_RUNNING
| IFF_DRV_OACTIVE
);
1588 ieee80211_new_state(ic
, IEEE80211_S_INIT
, -1);
1590 callout_stop(&sc
->periodic_ch
);
1591 callout_stop(&sc
->tx_watchdog_ch
);
1593 taskqueue_block(sc
->taskqueue
);
1595 taskqueue_drain(sc
->taskqueue
, &sc
->rx_done_task
);
1596 taskqueue_drain(sc
->taskqueue
, &sc
->tx_done_task
);
1597 taskqueue_drain(sc
->taskqueue
, &sc
->periodic_task
);
1598 taskqueue_drain(sc
->taskqueue
, &sc
->cmd_task
);
1600 /* clear key tables */
1602 rt2870_asic_clear_keytables(sc
);
1606 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_SYS_CTRL
);
1608 tmp
&= ~(RT2870_REG_RX_ENABLE
| RT2870_REG_TX_ENABLE
);
1610 rt2870_io_mac_write(sc
, RT2870_REG_SYS_CTRL
, tmp
);
1612 rt2870_io_mac_write(sc
, RT2870_REG_SCHDMA_USB_DMA_CFG
, 0);
1616 rt2870_io_mac_write(sc
, RT2870_REG_SYS_CTRL
,
1617 RT2870_REG_MAC_SRST
| RT2870_REG_BBP_HRST
);
1618 rt2870_io_mac_write(sc
, RT2870_REG_SYS_CTRL
, 0);
1620 /* abort any pending transfers */
1622 if (sc
->rx_ring
.usb_pipe
!= NULL
)
1623 usbd_abort_pipe(sc
->rx_ring
.usb_pipe
);
1625 for (i
= 0; i
< sc
->usb_endpoints
- 1; i
++)
1626 if (sc
->tx_ring
[i
].usb_pipe
!= NULL
)
1627 usbd_abort_pipe(sc
->tx_ring
[i
].usb_pipe
);
1633 static void rt2870_stop(void *priv
)
1635 struct rt2870_softc
*sc
;
1639 rt2870_stop_locked(sc
);
1645 static void rt2870_start(struct ifnet
*ifp
)
1647 struct rt2870_softc
*sc
;
1648 struct ieee80211com
*ic
;
1649 struct ieee80211_node
*ni
;
1650 struct ether_header
*eh
;
1657 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
1662 IF_POLL(&ic
->ic_mgtq
, m
);
1665 if (sc
->tx_ring
[sc
->tx_ring_mgtqid
].queued
>= RT2870_SOFTC_TX_RING_DATA_COUNT
)
1667 RT2870_DPRINTF(sc
, RT2870_DEBUG_TX
,
1668 "%s: if_start: Tx ring with qid=%d is full\n",
1669 device_get_nameunit(sc
->dev
), sc
->tx_ring_mgtqid
);
1671 ifp
->if_drv_flags
|= IFF_DRV_OACTIVE
;
1675 IF_DEQUEUE(&ic
->ic_mgtq
, m
);
1677 ni
= (struct ieee80211_node
*) m
->m_pkthdr
.rcvif
;
1678 m
->m_pkthdr
.rcvif
= NULL
;
1680 if (bpf_peers_present(ic
->ic_rawbpf
))
1681 bpf_mtap(ic
->ic_rawbpf
, m
);
1683 if (rt2870_tx_frame(sc
, m
, ni
, sc
->tx_ring_mgtqid
) != 0)
1688 if (ic
->ic_state
!= IEEE80211_S_RUN
)
1691 IF_POLL(&ifp
->if_snd
, m
);
1695 IFQ_DRV_DEQUEUE(&ifp
->if_snd
, m
);
1697 if (ic
->ic_flags
& IEEE80211_F_SCAN
)
1698 ieee80211_cancel_scan(ic
);
1700 if (m
->m_len
< sizeof(struct ether_header
) &&
1701 !(m
= m_pullup(m
, sizeof (struct ether_header
))))
1704 eh
= mtod(m
, struct ether_header
*);
1706 ni
= ieee80211_find_txnode(ic
, eh
->ether_dhost
);
1709 RT2870_DPRINTF(sc
, RT2870_DEBUG_TX
,
1710 "%s: if_start: could not find Tx node\n",
1711 device_get_nameunit(sc
->dev
));
1717 ieee80211_classify(ic
, m
, ni
);
1719 qid
= M_WME_GETAC(m
);
1721 if (sc
->tx_ring
[qid
].queued
>= RT2870_SOFTC_TX_RING_DATA_COUNT
)
1723 RT2870_DPRINTF(sc
, RT2870_DEBUG_TX
,
1724 "%s: if_start: Tx ring with qid=%d is full\n",
1725 device_get_nameunit(sc
->dev
), qid
);
1728 ieee80211_free_node(ni
);
1729 ifp
->if_drv_flags
|= IFF_DRV_OACTIVE
;
1736 m
= ieee80211_encap(ic
, m
, ni
);
1739 ieee80211_free_node(ni
);
1744 if (bpf_peers_present(ic
->ic_rawbpf
))
1745 bpf_mtap(ic
->ic_rawbpf
, m
);
1747 if (rt2870_tx_frame(sc
, m
, ni
, qid
) != 0)
1749 ieee80211_free_node(ni
);
1750 ifp
->if_drv_flags
|= IFF_DRV_OACTIVE
;
1756 sc
->tx_timer
= RT2870_TX_WATCHDOG_TIMEOUT
;
1758 ic
->ic_lastdata
= ticks
;
1760 callout_reset(&sc
->tx_watchdog_ch
, hz
, rt2870_tx_watchdog
, sc
);
1767 static int rt2870_ioctl(struct ifnet
*ifp
, u_long cmd
, caddr_t data
)
1769 struct rt2870_softc
*sc
;
1770 struct ieee80211com
*ic
;
1781 if (ifp
->if_flags
& IFF_UP
)
1783 if (ifp
->if_drv_flags
& IFF_DRV_RUNNING
)
1785 if ((ifp
->if_flags
^ sc
->if_flags
) & IFF_PROMISC
)
1786 rt2870_asic_update_promisc(sc
);
1790 rt2870_init_locked(sc
);
1795 if (ifp
->if_drv_flags
& IFF_DRV_RUNNING
)
1796 rt2870_stop_locked(sc
);
1799 sc
->if_flags
= ifp
->if_flags
;
1803 error
= ieee80211_ioctl(ic
, cmd
, data
);
1806 if (error
== ENETRESET
)
1808 if ((ifp
->if_flags
& IFF_UP
) &&
1809 (ifp
->if_drv_flags
& IFF_DRV_RUNNING
) &&
1810 (ic
->ic_roaming
!= IEEE80211_ROAMING_MANUAL
))
1812 rt2870_stop_locked(sc
);
1813 rt2870_init_locked(sc
);
1825 static int rt2870_reset(struct ifnet
*ifp
)
1827 struct rt2870_softc
*sc
;
1828 struct ieee80211com
*ic
;
1833 if (ic
->ic_opmode
!= IEEE80211_M_MONITOR
)
1836 rt2870_rf_set_chan(sc
, ic
->ic_curchan
);
1844 static int rt2870_newstate(struct ieee80211com
*ic
,
1845 enum ieee80211_state nstate
, int arg
)
1847 struct rt2870_softc
*sc
;
1849 struct rt2870_cmd_argv_newstate cmd_argv
;
1854 cmd_argv
.nstate
= nstate
;
1857 rt2870_do_async(sc
, rt2870_newstate_cb
, &cmd_argv
,
1858 sizeof(struct rt2870_cmd_argv_newstate
));
1866 static void rt2870_scan_start(struct ieee80211com
*ic
)
1868 struct rt2870_softc
*sc
;
1874 rt2870_do_async(sc
, rt2870_scan_start_cb
, NULL
, 0);
1880 static void rt2870_scan_end(struct ieee80211com
*ic
)
1882 struct rt2870_softc
*sc
;
1888 rt2870_do_async(sc
, rt2870_scan_end_cb
, NULL
, 0);
1892 * rt2870_set_channel
1894 static void rt2870_set_channel(struct ieee80211com
*ic
)
1896 struct rt2870_softc
*sc
;
1902 rt2870_do_async(sc
, rt2870_set_channel_cb
, NULL
, 0);
1908 static void rt2870_newassoc(struct ieee80211_node
*ni
, int isnew
)
1910 struct rt2870_softc
*sc
;
1911 struct ieee80211com
*ic
;
1913 struct rt2870_cmd_argv_newassoc cmd_argv
;
1919 cmd_argv
.associd
= (ni
!= NULL
) ? ni
->ni_associd
: 0;
1920 cmd_argv
.isnew
= isnew
;
1921 memcpy(cmd_argv
.macaddr
, ni
->ni_macaddr
, IEEE80211_ADDR_LEN
);
1923 rt2870_do_async(sc
, rt2870_newassoc_cb
, &cmd_argv
,
1924 sizeof(struct rt2870_cmd_argv_newassoc
));
1930 static void rt2870_updateslot(struct ifnet
*ifp
)
1932 struct rt2870_softc
*sc
;
1936 rt2870_do_async(sc
, rt2870_updateslot_cb
, NULL
, 0);
1942 static int rt2870_wme_update(struct ieee80211com
*ic
)
1944 struct rt2870_softc
*sc
;
1950 rt2870_do_async(sc
, rt2870_wme_update_cb
, NULL
, 0);
1956 * rt2870_update_beacon
1958 static void rt2870_update_beacon(struct ieee80211com
*ic
, int what
)
1960 struct rt2870_softc
*sc
;
1962 struct rt2870_cmd_argv_updatebeacon cmd_argv
;
1967 cmd_argv
.what
= what
;
1969 rt2870_do_async(sc
, rt2870_update_beacon_cb
, &cmd_argv
,
1970 sizeof(struct rt2870_cmd_argv_updatebeacon
));
1974 * rt2870_key_update_begin
1976 static void rt2870_key_update_begin(struct ieee80211com
*ic
)
1978 struct rt2870_softc
*sc
;
1984 rt2870_do_async(sc
, rt2870_key_update_begin_cb
, NULL
, 0);
1988 * rt2870_key_update_end
1990 static void rt2870_key_update_end(struct ieee80211com
*ic
)
1992 struct rt2870_softc
*sc
;
1998 rt2870_do_async(sc
, rt2870_key_update_end_cb
, NULL
, 0);
2004 static int rt2870_key_set(struct ieee80211com
*ic
,
2005 const struct ieee80211_key
*k
, const uint8_t mac
[IEEE80211_ADDR_LEN
])
2007 struct rt2870_softc
*sc
;
2009 struct ieee80211_node
*ni
;
2010 struct rt2870_cmd_argv_keyset cmd_argv
;
2012 if (k
->wk_cipher
->ic_cipher
!= IEEE80211_CIPHER_WEP
&&
2013 k
->wk_cipher
->ic_cipher
!= IEEE80211_CIPHER_TKIP
&&
2014 k
->wk_cipher
->ic_cipher
!= IEEE80211_CIPHER_AES_CCM
)
2020 if (ic
->ic_opmode
!= IEEE80211_M_HOSTAP
)
2023 ni
= ieee80211_find_node(&ic
->ic_sta
, mac
);
2025 memcpy(&cmd_argv
.key
, k
, sizeof(struct ieee80211_key
));
2026 cmd_argv
.associd
= (ni
!= NULL
) ? ni
->ni_associd
: 0;
2028 if ((ic
->ic_opmode
== IEEE80211_M_HOSTAP
) && (ni
!= NULL
))
2029 ieee80211_free_node(ni
);
2031 rt2870_do_async(sc
, rt2870_key_set_cb
, &cmd_argv
,
2032 sizeof(struct rt2870_cmd_argv_keyset
));
2040 static int rt2870_key_delete(struct ieee80211com
*ic
,
2041 const struct ieee80211_key
*k
)
2043 struct rt2870_softc
*sc
;
2045 struct ieee80211_node
*ni
;
2046 struct rt2870_cmd_argv_keydelete cmd_argv
;
2052 memcpy(&cmd_argv
.key
, k
, sizeof(struct ieee80211_key
));
2053 cmd_argv
.associd
= (ni
!= NULL
) ? ni
->ni_associd
: 0;
2055 rt2870_do_async(sc
, rt2870_key_delete_cb
, &cmd_argv
,
2056 sizeof(struct rt2870_cmd_argv_keydelete
));
2064 static int rt2870_raw_xmit(struct ieee80211_node
*ni
, struct mbuf
*m
,
2065 const struct ieee80211_bpf_params
*params
)
2067 struct ieee80211com
*ic
;
2069 struct rt2870_softc
*sc
;
2079 * rt2870_media_change
2081 static int rt2870_media_change(struct ifnet
*ifp
)
2083 struct rt2870_softc
*sc
;
2088 error
= ieee80211_media_change(ifp
);
2089 if (error
!= ENETRESET
)
2092 if ((ifp
->if_flags
& IFF_UP
) && (ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
2102 * rt2870_recv_action
2104 static void rt2870_recv_action(struct ieee80211_node
*ni
,
2105 const uint8_t *frm
, const uint8_t *efrm
)
2107 struct rt2870_softc
*sc
;
2108 struct ieee80211com
*ic
;
2110 const struct ieee80211_action
*ia
;
2111 uint16_t associd
, baparamset
;
2120 ia
= (const struct ieee80211_action
*) frm
;
2122 sc
->recv_action(ni
, frm
, efrm
);
2124 if (ia
->ia_category
!= IEEE80211_ACTION_CAT_BA
)
2127 associd
= (ni
!= NULL
) ? ni
->ni_associd
: 0;
2128 wcid
= RT2870_AID2WCID(associd
);
2130 switch (ia
->ia_action
)
2132 /* IEEE80211_ACTION_BA_ADDBA_REQUEST */
2133 case IEEE80211_ACTION_BA_ADDBA_REQUEST
:
2134 baparamset
= LE_READ_2(frm
+ 3);
2135 tid
= RT2870_MS(baparamset
, IEEE80211_BAPS_TID
);
2137 RT2870_DPRINTF(sc
, RT2870_DEBUG_BA
,
2138 "%s: adding A-MPDU Rx block ACK: associd=0x%04x, tid=%d\n",
2139 device_get_nameunit(sc
->dev
), associd
, tid
);
2141 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_WCID(wcid
) + 4);
2143 tmp
|= (0x10000 << tid
);
2145 rt2870_io_mac_write(sc
, RT2870_REG_WCID(wcid
) + 4, tmp
);
2148 /* IEEE80211_ACTION_BA_DELBA */
2149 case IEEE80211_ACTION_BA_DELBA
:
2150 baparamset
= LE_READ_2(frm
+ 2);
2151 tid
= RT2870_MS(baparamset
, IEEE80211_BAPS_TID
);
2153 RT2870_DPRINTF(sc
, RT2870_DEBUG_BA
,
2154 "%s: deleting A-MPDU Rx block ACK: associd=0x%04x, tid=%d\n",
2155 device_get_nameunit(sc
->dev
), associd
, tid
);
2157 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_WCID(wcid
) + 4);
2159 tmp
&= ~(0x10000 << tid
);
2161 rt2870_io_mac_write(sc
, RT2870_REG_WCID(wcid
) + 4, tmp
);
2167 * rt2870_send_action
2169 static int rt2870_send_action(struct ieee80211_node
*ni
,
2170 int category
, int action
, uint16_t args
[4])
2172 struct rt2870_softc
*sc
;
2173 struct ieee80211com
*ic
;
2175 uint16_t associd
, baparamset
;
2184 ret
= sc
->send_action(ni
, category
, action
, args
);
2186 if (category
!= IEEE80211_ACTION_CAT_BA
)
2189 associd
= (ni
!= NULL
) ? ni
->ni_associd
: 0;
2190 wcid
= RT2870_AID2WCID(associd
);
2194 /* IEEE80211_ACTION_BA_DELBA */
2195 case IEEE80211_ACTION_BA_DELBA
:
2196 baparamset
= RT2870_SM(args
[0], IEEE80211_DELBAPS_TID
) |
2197 RT2870_SM(args
[1], IEEE80211_DELBAPS_INIT
);
2199 if (RT2870_MS(baparamset
, IEEE80211_DELBAPS_INIT
) == IEEE80211_DELBAPS_INIT
)
2202 tid
= RT2870_MS(baparamset
, IEEE80211_DELBAPS_TID
);
2204 RT2870_DPRINTF(sc
, RT2870_DEBUG_BA
,
2205 "%s: deleting A-MPDU Rx block ACK: associd=0x%04x, tid=%d\n",
2206 device_get_nameunit(sc
->dev
), associd
, tid
);
2208 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_WCID(wcid
) + 4);
2210 tmp
&= ~(0x10000 << tid
);
2212 rt2870_io_mac_write(sc
, RT2870_REG_WCID(wcid
) + 4, tmp
);
2220 * rt2870_amrr_update_iter_func
2222 static void rt2870_amrr_update_iter_func(void *arg
, struct ieee80211_node
*ni
)
2224 struct rt2870_softc
*sc
;
2225 struct ieee80211com
*ic
;
2231 /* only associated stations */
2233 if (ni
->ni_associd
!= 0)
2235 wcid
= RT2870_AID2WCID(ni
->ni_associd
);
2237 rt2870_amrr_choose(ni
, &sc
->amrr_node
[wcid
]);
2239 RT2870_DPRINTF(sc
, RT2870_DEBUG_RATE
,
2240 "%s:%s node Tx rate: associd=0x%04x, rate=0x%02x, max rate=0x%02x\n",
2241 device_get_nameunit(sc
->dev
),
2242 (ni
->ni_flags
& IEEE80211_NODE_HT
) ? " HT" : "",
2244 (ni
->ni_flags
& IEEE80211_NODE_HT
) ?
2245 (ni
->ni_htrates
.rs_rates
[ni
->ni_txrate
] | IEEE80211_RATE_MCS
) :
2246 (ni
->ni_rates
.rs_rates
[ni
->ni_txrate
] & IEEE80211_RATE_VAL
),
2247 (ni
->ni_flags
& IEEE80211_NODE_HT
) ?
2248 (ni
->ni_htrates
.rs_rates
[ni
->ni_htrates
.rs_nrates
- 1] | IEEE80211_RATE_MCS
) :
2249 (ni
->ni_rates
.rs_rates
[ni
->ni_rates
.rs_nrates
- 1] & IEEE80211_RATE_VAL
));
2256 static void rt2870_periodic(void *arg
)
2258 struct rt2870_softc
*sc
;
2264 RT2870_DPRINTF(sc
, RT2870_DEBUG_PERIODIC
,
2266 device_get_nameunit(sc
->dev
));
2268 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
2271 taskqueue_enqueue(sc
->taskqueue
, &sc
->periodic_task
);
2275 * rt2870_tx_watchdog
2277 static void rt2870_tx_watchdog(void *arg
)
2279 struct rt2870_softc
*sc
;
2285 if (sc
->tx_timer
== 0)
2288 if (--sc
->tx_timer
== 0)
2290 printf("%s: Tx watchdog timeout: resetting\n",
2291 device_get_nameunit(sc
->dev
));
2293 rt2870_stop_locked(sc
);
2294 rt2870_init_locked(sc
);
2298 sc
->tx_watchdog_timeouts
++;
2301 callout_reset(&sc
->tx_watchdog_ch
, hz
, rt2870_tx_watchdog
, sc
);
2307 static int rt2870_do_async(struct rt2870_softc
*sc
,
2308 void (*cb
)(struct rt2870_softc
*sc
, void *arg
),
2312 struct rt2870_softc_cmd_ring
*ring
;
2313 struct rt2870_softc_cmd
*cmd
;
2317 ring
= &sc
->cmd_ring
;
2319 RT2870_SOFTC_LOCK(sc
);
2321 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
2323 RT2870_SOFTC_UNLOCK(sc
);
2327 if (ring
->queued
>= RT2870_SOFTC_CMD_RING_CMD_COUNT
)
2329 RT2870_SOFTC_UNLOCK(sc
);
2333 cmd
= STAILQ_FIRST(&ring
->inactive
);
2334 STAILQ_REMOVE_HEAD(&ring
->inactive
, next
);
2339 memcpy(cmd
->data
, arg
, len
);
2341 STAILQ_INSERT_TAIL(&ring
->active
, cmd
, next
);
2344 run_cmd_task
= (ring
->queued
== 1);
2346 RT2870_SOFTC_UNLOCK(sc
);
2349 taskqueue_enqueue(sc
->taskqueue
, &sc
->cmd_task
);
2355 * rt2870_newstate_cb
2357 static void rt2870_newstate_cb(struct rt2870_softc
*sc
, void *arg
)
2359 struct ieee80211com
*ic
;
2360 enum ieee80211_state nstate
;
2361 struct ieee80211_node
*ni
;
2362 struct rt2870_cmd_argv_newstate
*cmd_argv
;
2367 nstate
= cmd_argv
->nstate
;
2369 RT2870_DPRINTF(sc
, RT2870_DEBUG_STATE
,
2370 "%s: newstate: %s -> %s\n",
2371 device_get_nameunit(sc
->dev
),
2372 ieee80211_state_name
[ic
->ic_state
], ieee80211_state_name
[nstate
]);
2374 error
= sc
->newstate(ic
, nstate
, cmd_argv
->arg
);
2378 /* turn link LED off */
2380 if (nstate
!= IEEE80211_S_RUN
)
2381 rt2870_led_cmd(sc
, RT2870_LED_CMD_RADIO_OFF
);
2385 case IEEE80211_S_INIT
:
2386 rt2870_asic_disable_tsf_sync(sc
);
2389 case IEEE80211_S_RUN
:
2392 rt2870_rf_set_chan(sc
, ni
->ni_chan
);
2394 if (ic
->ic_opmode
!= IEEE80211_M_MONITOR
)
2396 rt2870_asic_enable_mrr(sc
);
2397 rt2870_asic_set_txpreamble(sc
);
2398 rt2870_asic_set_basicrates(sc
);
2399 rt2870_asic_set_bssid(sc
, ni
->ni_bssid
);
2402 if (ic
->ic_opmode
== IEEE80211_M_STA
)
2403 rt2870_newassoc(ni
, 1);
2405 if (ic
->ic_opmode
== IEEE80211_M_HOSTAP
||
2406 ic
->ic_opmode
== IEEE80211_M_IBSS
)
2408 error
= rt2870_asic_update_beacon(sc
);
2413 if (ic
->ic_opmode
!= IEEE80211_M_MONITOR
)
2414 rt2870_asic_enable_tsf_sync(sc
);
2416 /* turn link LED on */
2418 if (ic
->ic_opmode
!= IEEE80211_M_MONITOR
)
2420 rt2870_led_cmd(sc
, RT2870_LED_CMD_RADIO_ON
|
2421 (IEEE80211_IS_CHAN_2GHZ(ni
->ni_chan
) ?
2422 RT2870_LED_CMD_LINK_2GHZ
: RT2870_LED_CMD_LINK_5GHZ
));
2432 * rt2870_scan_start_cb
2434 static void rt2870_scan_start_cb(struct rt2870_softc
*sc
, void *arg
)
2436 struct ieee80211com
*ic
;
2442 rt2870_asic_disable_tsf_sync(sc
);
2446 * rt2870_scan_end_cb
2448 static void rt2870_scan_end_cb(struct rt2870_softc
*sc
, void *arg
)
2450 struct ieee80211com
*ic
;
2451 struct ieee80211_node
*ni
;
2456 rt2870_asic_enable_tsf_sync(sc
);
2460 * rt2870_set_channel_cb
2462 static void rt2870_set_channel_cb(struct rt2870_softc
*sc
, void *arg
)
2464 struct ieee80211com
*ic
;
2468 RT2870_DPRINTF(sc
, RT2870_DEBUG_CHAN
,
2469 "%s: set channel: channel=%u, HT%s%s\n",
2470 device_get_nameunit(sc
->dev
),
2471 ieee80211_chan2ieee(ic
, ic
->ic_curchan
),
2472 !IEEE80211_IS_CHAN_HT(ic
->ic_curchan
) ? " disabled" :
2473 IEEE80211_IS_CHAN_HT20(ic
->ic_curchan
) ? "20":
2474 IEEE80211_IS_CHAN_HT40U(ic
->ic_curchan
) ? "40U" : "40D",
2475 (ic
->ic_flags
& IEEE80211_F_SCAN
) ? ", scanning" : "");
2477 rt2870_rf_set_chan(sc
, ic
->ic_curchan
);
2481 * rt2870_newassoc_cb
2483 static void rt2870_newassoc_cb(struct rt2870_softc
*sc
, void *arg
)
2485 struct ieee80211com
*ic
;
2486 struct ieee80211_node
*ni
;
2487 struct rt2870_cmd_argv_newassoc
*cmd_argv
;
2490 uint8_t *macaddr
, wcid
;
2495 associd
= cmd_argv
->associd
;
2496 isnew
= cmd_argv
->isnew
;
2497 macaddr
= cmd_argv
->macaddr
;
2499 wcid
= RT2870_AID2WCID(associd
);
2501 RT2870_DPRINTF(sc
, RT2870_DEBUG_NODE
,
2502 "%s: new association: wcid=0x%02x, "
2503 "mac addr=%s, QoS %s, ERP %s, HT %s\n",
2504 device_get_nameunit(sc
->dev
), wcid
,
2505 ether_sprintf(macaddr
),
2506 (ni
->ni_flags
& IEEE80211_NODE_QOS
) ? "enabled" : "disabled",
2507 (ni
->ni_flags
& IEEE80211_NODE_ERP
) ? "enabled" : "disabled",
2508 (ni
->ni_flags
& IEEE80211_NODE_HT
) ? "enabled" : "disabled");
2510 rt2870_io_mac_write_multi(sc
, RT2870_REG_WCID(wcid
),
2511 macaddr
, IEEE80211_ADDR_LEN
);
2513 rt2870_amrr_node_init(&sc
->amrr
, &sc
->amrr_node
[wcid
], ni
);
2515 RT2870_DPRINTF(sc
, RT2870_DEBUG_RATE
,
2516 "%s: initial%s node Tx rate: associd=0x%04x, rate=0x%02x, max rate=0x%02x\n",
2517 device_get_nameunit(sc
->dev
),
2518 (ni
->ni_flags
& IEEE80211_NODE_HT
) ? " HT" : "",
2520 (ni
->ni_flags
& IEEE80211_NODE_HT
) ?
2521 (ni
->ni_htrates
.rs_rates
[ni
->ni_txrate
] | IEEE80211_RATE_MCS
) :
2522 (ni
->ni_rates
.rs_rates
[ni
->ni_txrate
] & IEEE80211_RATE_VAL
),
2523 (ni
->ni_flags
& IEEE80211_NODE_HT
) ?
2524 (ni
->ni_htrates
.rs_rates
[ni
->ni_htrates
.rs_nrates
- 1] | IEEE80211_RATE_MCS
) :
2525 (ni
->ni_rates
.rs_rates
[ni
->ni_rates
.rs_nrates
- 1] & IEEE80211_RATE_VAL
));
2527 rt2870_asic_updateprot(sc
);
2528 rt2870_asic_updateslot(sc
);
2529 rt2870_asic_set_txpreamble(sc
);
2533 * rt2870_updateslot_cb
2535 static void rt2870_updateslot_cb(struct rt2870_softc
*sc
, void *arg
)
2537 rt2870_asic_updateslot(sc
);
2541 * rt2870_wme_update_cb
2543 static void rt2870_wme_update_cb(struct rt2870_softc
*sc
, void *arg
)
2545 rt2870_asic_wme_update(sc
);
2549 * rt2870_update_beacon_cb
2551 static void rt2870_update_beacon_cb(struct rt2870_softc
*sc
, void *arg
)
2553 struct rt2870_cmd_argv_updatebeacon
*cmd_argv
;
2557 RT2870_DPRINTF(sc
, RT2870_DEBUG_BEACON
,
2558 "%s: update beacon\n",
2559 device_get_nameunit(sc
->dev
));
2561 rt2870_asic_update_beacon(sc
);
2565 * rt2870_key_update_begin_cb
2567 static void rt2870_key_update_begin_cb(struct rt2870_softc
*sc
, void *arg
)
2573 RT2870_DPRINTF(sc
, RT2870_DEBUG_KEY
,
2574 "%s: key update begin\n",
2575 device_get_nameunit(sc
->dev
));
2577 taskqueue_block(sc
->taskqueue
);
2579 IF_LOCK(&ifp
->if_snd
);
2583 * rt2870_key_update_end_cb
2585 static void rt2870_key_update_end_cb(struct rt2870_softc
*sc
, void *arg
)
2591 RT2870_DPRINTF(sc
, RT2870_DEBUG_KEY
,
2592 "%s: key update end\n",
2593 device_get_nameunit(sc
->dev
));
2595 IF_UNLOCK(&ifp
->if_snd
);
2597 taskqueue_unblock(sc
->taskqueue
);
2603 static void rt2870_key_set_cb(struct rt2870_softc
*sc
, void *arg
)
2605 struct ieee80211com
*ic
;
2606 struct ieee80211_key
*k
;
2607 struct rt2870_cmd_argv_keyset
*cmd_argv
;
2608 uint16_t associd
, key_base
, keymode_base
;
2609 uint8_t mode
, vapid
, wcid
, iv
[8];
2615 associd
= cmd_argv
->associd
;
2617 switch (k
->wk_cipher
->ic_cipher
)
2619 case IEEE80211_CIPHER_WEP
:
2620 if(k
->wk_keylen
< 8)
2621 mode
= RT2870_REG_CIPHER_MODE_WEP40
;
2623 mode
= RT2870_REG_CIPHER_MODE_WEP104
;
2626 case IEEE80211_CIPHER_TKIP
:
2627 mode
= RT2870_REG_CIPHER_MODE_TKIP
;
2630 case IEEE80211_CIPHER_AES_CCM
:
2631 mode
= RT2870_REG_CIPHER_MODE_AES_CCMP
;
2638 RT2870_DPRINTF(sc
, RT2870_DEBUG_KEY
,
2639 "%s: set key: keyix=%d, keylen=%d, associd=0x%04x, mode=%d, group=%d\n",
2640 device_get_nameunit(sc
->dev
), k
->wk_keyix
, k
->wk_keylen
, associd
, mode
,
2641 (k
->wk_flags
& IEEE80211_KEY_GROUP
) ? 1 : 0);
2643 if (!(k
->wk_flags
& IEEE80211_KEY_GROUP
))
2645 /* install pairwise key */
2648 wcid
= RT2870_AID2WCID(associd
);
2649 key_base
= RT2870_REG_PKEY(wcid
);
2651 if (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_WEP
)
2655 iv
[3] = (k
->wk_keyix
<< 6);
2659 if (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_TKIP
)
2661 iv
[0] = (k
->wk_keytsc
>> 8);
2662 iv
[1] = ((iv
[0] | 0x20) & 0x7f);
2663 iv
[2] = k
->wk_keytsc
;
2669 iv
[0] = k
->wk_keytsc
;
2670 iv
[1] = k
->wk_keytsc
>> 8;
2674 iv
[3] = ((k
->wk_keyix
<< 6) | IEEE80211_WEP_EXTIV
);
2675 iv
[4] = (k
->wk_keytsc
>> 16);
2676 iv
[5] = (k
->wk_keytsc
>> 24);
2677 iv
[6] = (k
->wk_keytsc
>> 32);
2678 iv
[7] = (k
->wk_keytsc
>> 40);
2680 RT2870_DPRINTF(sc
, RT2870_DEBUG_KEY
,
2681 "%s: set key: iv=%02x %02x %02x %02x %02x %02x %02x %02x\n",
2682 device_get_nameunit(sc
->dev
),
2683 iv
[0], iv
[1], iv
[2], iv
[3], iv
[4], iv
[5], iv
[6], iv
[7]);
2686 rt2870_io_mac_write_multi(sc
, RT2870_REG_IVEIV(wcid
), iv
, 8);
2688 if (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_TKIP
)
2690 rt2870_io_mac_write_multi(sc
, key_base
, k
->wk_key
, 16);
2692 if (ic
->ic_opmode
!= IEEE80211_M_HOSTAP
)
2694 rt2870_io_mac_write_multi(sc
, key_base
+ 16, &k
->wk_key
[16], 8);
2695 rt2870_io_mac_write_multi(sc
, key_base
+ 24, &k
->wk_key
[24], 8);
2699 rt2870_io_mac_write_multi(sc
, key_base
+ 16, &k
->wk_key
[24], 8);
2700 rt2870_io_mac_write_multi(sc
, key_base
+ 24, &k
->wk_key
[16], 8);
2705 rt2870_io_mac_write_multi(sc
, key_base
, k
->wk_key
, k
->wk_keylen
);
2708 tmp
= ((vapid
& RT2870_REG_VAP_MASK
) << RT2870_REG_VAP_SHIFT
) |
2709 (mode
<< RT2870_REG_CIPHER_MODE_SHIFT
) | RT2870_REG_PKEY_ENABLE
;
2711 rt2870_io_mac_write(sc
, RT2870_REG_WCID_ATTR(wcid
), tmp
);
2714 if ((k
->wk_flags
& IEEE80211_KEY_GROUP
) ||
2715 (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_WEP
))
2717 /* install group key */
2720 key_base
= RT2870_REG_SKEY(vapid
, k
->wk_keyix
);
2721 keymode_base
= RT2870_REG_SKEY_MODE(vapid
);
2723 if (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_TKIP
)
2725 rt2870_io_mac_write_multi(sc
, key_base
, k
->wk_key
, 16);
2727 if (ic
->ic_opmode
!= IEEE80211_M_HOSTAP
)
2729 rt2870_io_mac_write_multi(sc
, key_base
+ 16, &k
->wk_key
[16], 8);
2730 rt2870_io_mac_write_multi(sc
, key_base
+ 24, &k
->wk_key
[24], 8);
2734 rt2870_io_mac_write_multi(sc
, key_base
+ 16, &k
->wk_key
[24], 8);
2735 rt2870_io_mac_write_multi(sc
, key_base
+ 24, &k
->wk_key
[16], 8);
2740 rt2870_io_mac_write_multi(sc
, key_base
, k
->wk_key
, k
->wk_keylen
);
2743 tmp
= rt2870_io_mac_read(sc
, keymode_base
);
2745 tmp
&= ~(0xf << (k
->wk_keyix
* 4 + 16 * (vapid
% 2)));
2746 tmp
|= (mode
<< (k
->wk_keyix
* 4 + 16 * (vapid
% 2)));
2748 rt2870_io_mac_write(sc
, keymode_base
, tmp
);
2753 * rt2870_key_delete_cb
2755 static void rt2870_key_delete_cb(struct rt2870_softc
*sc
, void *arg
)
2757 struct ieee80211com
*ic
;
2758 struct ieee80211_key
*k
;
2759 struct rt2870_cmd_argv_keydelete
*cmd_argv
;
2761 uint8_t vapid
, wcid
;
2767 associd
= cmd_argv
->associd
;
2769 RT2870_DPRINTF(sc
, RT2870_DEBUG_KEY
,
2770 "%s: delete key: keyix=%d, keylen=%d, associd=0x%04x, group=%d\n",
2771 device_get_nameunit(sc
->dev
), k
->wk_keyix
, k
->wk_keylen
, associd
,
2772 (k
->wk_flags
& IEEE80211_KEY_GROUP
) ? 1 : 0);
2774 if (!(k
->wk_flags
& IEEE80211_KEY_GROUP
))
2776 /* remove pairwise key */
2778 wcid
= RT2870_AID2WCID(associd
);
2780 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_WCID_ATTR(wcid
));
2783 tmp
|= (RT2870_REG_CIPHER_MODE_NONE
<< RT2870_REG_CIPHER_MODE_SHIFT
);
2785 rt2870_io_mac_write(sc
, RT2870_REG_WCID_ATTR(wcid
), tmp
);
2789 /* remove group key */
2793 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_SKEY_MODE(vapid
));
2795 tmp
&= ~(0xf << (k
->wk_keyix
* 4 + 16 * (vapid
% 2)));
2796 tmp
|= (RT2870_REG_CIPHER_MODE_NONE
<< (k
->wk_keyix
* 4 + 16 * (vapid
% 2)));
2798 rt2870_io_mac_write(sc
, RT2870_REG_SKEY_MODE(vapid
), tmp
);
2803 * rt2870_asic_set_bssid
2805 static void rt2870_asic_set_bssid(struct rt2870_softc
*sc
,
2806 const uint8_t *bssid
)
2810 RT2870_DPRINTF(sc
, RT2870_DEBUG_STATE
,
2811 "%s: set bssid: bssid=%s\n",
2812 device_get_nameunit(sc
->dev
), ether_sprintf(bssid
));
2814 tmp
= bssid
[0] | (bssid
[1]) << 8 | (bssid
[2] << 16) | (bssid
[3] << 24);
2816 rt2870_io_mac_write(sc
, RT2870_REG_BSSID_DW0
, tmp
);
2818 tmp
= bssid
[4] | (bssid
[5] << 8);
2820 rt2870_io_mac_write(sc
, RT2870_REG_BSSID_DW1
, tmp
);
2824 * rt2870_asic_set_macaddr
2826 static void rt2870_asic_set_macaddr(struct rt2870_softc
*sc
,
2827 const uint8_t *addr
)
2831 tmp
= addr
[0] | (addr
[1] << 8) | (addr
[2] << 16) | (addr
[3] << 24);
2833 rt2870_io_mac_write(sc
, RT2870_REG_ADDR_DW0
, tmp
);
2835 tmp
= addr
[4] | (addr
[5] << 8);
2837 rt2870_io_mac_write(sc
, RT2870_REG_ADDR_DW1
, tmp
);
2841 * rt2870_asic_enable_tsf_sync
2843 static void rt2870_asic_enable_tsf_sync(struct rt2870_softc
*sc
)
2845 struct ieee80211com
*ic
;
2850 RT2870_DPRINTF(sc
, RT2870_DEBUG_BEACON
,
2851 "%s: enabling TSF\n",
2852 device_get_nameunit(sc
->dev
));
2854 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_BCN_TIME_CFG
);
2857 tmp
|= ic
->ic_bss
->ni_intval
* 16;
2858 tmp
|= (RT2870_REG_TSF_TIMER_ENABLE
| RT2870_REG_TBTT_TIMER_ENABLE
);
2860 if (ic
->ic_opmode
== IEEE80211_M_STA
)
2862 tmp
|= (RT2870_REG_TSF_SYNC_MODE_STA
<< RT2870_REG_TSF_SYNC_MODE_SHIFT
);
2864 else if (ic
->ic_opmode
== IEEE80211_M_IBSS
)
2866 tmp
|= RT2870_REG_BCN_TX_ENABLE
;
2867 tmp
|= (RT2870_REG_TSF_SYNC_MODE_IBSS
<< RT2870_REG_TSF_SYNC_MODE_SHIFT
);
2869 else if (ic
->ic_opmode
== IEEE80211_M_HOSTAP
)
2871 tmp
|= RT2870_REG_BCN_TX_ENABLE
;
2872 tmp
|= (RT2870_REG_TSF_SYNC_MODE_HOSTAP
<< RT2870_REG_TSF_SYNC_MODE_SHIFT
);
2875 rt2870_io_mac_write(sc
, RT2870_REG_BCN_TIME_CFG
, tmp
);
2879 * rt2870_asic_disable_tsf_sync
2881 static void rt2870_asic_disable_tsf_sync(struct rt2870_softc
*sc
)
2885 RT2870_DPRINTF(sc
, RT2870_DEBUG_BEACON
,
2886 "%s: disabling TSF\n",
2887 device_get_nameunit(sc
->dev
));
2889 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_BCN_TIME_CFG
);
2891 tmp
&= ~(RT2870_REG_BCN_TX_ENABLE
|
2892 RT2870_REG_TSF_TIMER_ENABLE
|
2893 RT2870_REG_TBTT_TIMER_ENABLE
);
2895 tmp
&= ~(RT2870_REG_TSF_SYNC_MODE_MASK
<< RT2870_REG_TSF_SYNC_MODE_SHIFT
);
2896 tmp
|= (RT2870_REG_TSF_SYNC_MODE_DISABLE
<< RT2870_REG_TSF_SYNC_MODE_SHIFT
);
2898 rt2870_io_mac_write(sc
, RT2870_REG_BCN_TIME_CFG
, tmp
);
2902 * rt2870_asic_enable_mrr
2904 static void rt2870_asic_enable_mrr(struct rt2870_softc
*sc
)
2906 #define CCK(mcs) (mcs)
2907 #define OFDM(mcs) ((1 << 3) | (mcs))
2908 #define HT(mcs) (mcs)
2910 rt2870_io_mac_write(sc
, RT2870_REG_TX_LG_FBK_CFG0
,
2911 (OFDM(6) << 28) | /* 54 -> 48 */
2912 (OFDM(5) << 24) | /* 48 -> 36 */
2913 (OFDM(4) << 20) | /* 36 -> 24 */
2914 (OFDM(3) << 16) | /* 24 -> 18 */
2915 (OFDM(2) << 12) | /* 18 -> 12 */
2916 (OFDM(1) << 8) | /* 12 -> 9 */
2917 (OFDM(0) << 4) | /* 9 -> 6 */
2918 OFDM(0)); /* 6 -> 6 */
2920 rt2870_io_mac_write(sc
, RT2870_REG_TX_LG_FBK_CFG1
,
2921 (CCK(2) << 12) | /* 11 -> 5.5 */
2922 (CCK(1) << 8) | /* 5.5 -> 2 */
2923 (CCK(0) << 4) | /* 2 -> 1 */
2924 CCK(0)); /* 1 -> 1 */
2926 rt2870_io_mac_write(sc
, RT2870_REG_TX_HT_FBK_CFG0
,
2936 rt2870_io_mac_write(sc
, RT2870_REG_TX_HT_FBK_CFG1
,
2952 * rt2870_asic_set_txpreamble
2954 static void rt2870_asic_set_txpreamble(struct rt2870_softc
*sc
)
2956 struct ieee80211com
*ic
;
2961 RT2870_DPRINTF(sc
, RT2870_DEBUG_STATE
,
2962 "%s: %s short Tx preamble\n",
2963 device_get_nameunit(sc
->dev
),
2964 (ic
->ic_flags
& IEEE80211_F_SHPREAMBLE
) ? "enabling" : "disabling");
2966 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_AUTO_RSP_CFG
);
2968 tmp
&= ~RT2870_REG_CCK_SHORT_ENABLE
;
2970 if (ic
->ic_flags
& IEEE80211_F_SHPREAMBLE
)
2971 tmp
|= RT2870_REG_CCK_SHORT_ENABLE
;
2973 rt2870_io_mac_write(sc
, RT2870_REG_AUTO_RSP_CFG
, tmp
);
2977 * rt2870_asic_set_basicrates
2979 static void rt2870_asic_set_basicrates(struct rt2870_softc
*sc
)
2981 struct ieee80211com
*ic
;
2985 if (ic
->ic_curmode
== IEEE80211_MODE_11B
)
2986 rt2870_io_mac_write(sc
, RT2870_REG_LEGACY_BASIC_RATE
, 0x3);
2987 else if (ic
->ic_curmode
== IEEE80211_MODE_11A
)
2988 rt2870_io_mac_write(sc
, RT2870_REG_LEGACY_BASIC_RATE
, 0x150);
2990 rt2870_io_mac_write(sc
, RT2870_REG_LEGACY_BASIC_RATE
, 0x15f);
2994 * rt2870_asic_update_rtsthreshold
2996 static void rt2870_asic_update_rtsthreshold(struct rt2870_softc
*sc
)
2998 struct ieee80211com
*ic
;
3004 RT2870_DPRINTF(sc
, RT2870_DEBUG_PROT
,
3005 "%s: updating RTS threshold: %d\n",
3006 device_get_nameunit(sc
->dev
), ic
->ic_rtsthreshold
);
3008 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_TX_RTS_CFG
);
3010 tmp
&= ~(RT2870_REG_TX_RTS_THRESHOLD_MASK
<< RT2870_REG_TX_RTS_THRESHOLD_SHIFT
);
3012 threshold
= (ic
->ic_rtsthreshold
< IEEE80211_RTS_MAX
) ?
3013 ic
->ic_rtsthreshold
: 0x1000;
3015 tmp
|= ((threshold
& RT2870_REG_TX_RTS_THRESHOLD_MASK
) <<
3016 RT2870_REG_TX_RTS_THRESHOLD_SHIFT
);
3018 rt2870_io_mac_write(sc
, RT2870_REG_TX_RTS_CFG
, tmp
);
3022 * rt2870_asic_update_txpower
3024 static void rt2870_asic_update_txpower(struct rt2870_softc
*sc
)
3026 struct ieee80211com
*ic
;
3027 uint32_t *txpow_rate
;
3035 RT2870_DPRINTF(sc
, RT2870_DEBUG_STATE
,
3036 "%s: updating Tx power: %d\n",
3037 device_get_nameunit(sc
->dev
), ic
->ic_txpowlimit
);
3039 if (!IEEE80211_IS_CHAN_HT40(ic
->ic_curchan
))
3041 txpow_rate
= sc
->txpow_rate_20mhz
;
3045 if (IEEE80211_IS_CHAN_2GHZ(ic
->ic_curchan
))
3046 txpow_rate
= sc
->txpow_rate_40mhz_2ghz
;
3048 txpow_rate
= sc
->txpow_rate_40mhz_5ghz
;
3053 val
= rt2870_io_bbp_read(sc
, 1);
3056 if (ic
->ic_txpowlimit
> 90)
3060 else if (ic
->ic_txpowlimit
> 60)
3064 else if (ic
->ic_txpowlimit
> 30)
3068 else if (ic
->ic_txpowlimit
> 15)
3072 else if (ic
->ic_txpowlimit
> 9)
3082 rt2870_io_bbp_write(sc
, 1, val
);
3084 for (i
= 0; i
< RT2870_SOFTC_TXPOW_RATE_COUNT
; i
++)
3086 if (txpow_rate
[i
] == 0xffffffff)
3089 tmp
= rt2870_read_eeprom_txpow_rate_add_delta(txpow_rate
[i
], delta
);
3091 rt2870_io_mac_write(sc
, RT2870_REG_TX_PWR_CFG(i
), tmp
);
3096 * rt2870_asic_update_promisc
3098 static void rt2870_asic_update_promisc(struct rt2870_softc
*sc
)
3103 ifp
= sc
->ic
.ic_ifp
;
3105 printf("%s: %s promiscuous mode\n",
3106 device_get_nameunit(sc
->dev
),
3107 (ifp
->if_flags
& IFF_PROMISC
) ? "entering" : "leaving");
3109 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_RX_FILTER_CFG
);
3111 tmp
&= ~RT2870_REG_RX_FILTER_DROP_UC_NOME
;
3113 if (!(ifp
->if_flags
& IFF_PROMISC
))
3114 tmp
|= RT2870_REG_RX_FILTER_DROP_UC_NOME
;
3116 rt2870_io_mac_write(sc
, RT2870_REG_RX_FILTER_CFG
, tmp
);
3120 * rt2870_asic_updateprot
3122 static void rt2870_asic_updateprot(struct rt2870_softc
*sc
)
3124 struct ieee80211com
*ic
;
3125 uint32_t cck_prot
, ofdm_prot
, mm20_prot
, mm40_prot
, gf20_prot
, gf40_prot
;
3130 /* CCK frame protection */
3132 cck_prot
= RT2870_REG_RTSTH_ENABLE
| RT2870_REG_PROT_NAV_SHORT
|
3133 RT2870_REG_TXOP_ALLOW_ALL
| RT2870_REG_PROT_CTRL_NONE
;
3135 /* set up protection frame phy mode and rate (MCS code) */
3137 if (ic
->ic_curmode
== IEEE80211_MODE_11A
)
3138 cck_prot
|= (RT2870_REG_PROT_PHYMODE_OFDM
<< RT2870_REG_PROT_PHYMODE_SHIFT
) |
3139 (0 << RT2870_REG_PROT_MCS_SHIFT
);
3141 cck_prot
|= ((RT2870_REG_PROT_PHYMODE_CCK
<< RT2870_REG_PROT_PHYMODE_SHIFT
) |
3142 (3 << RT2870_REG_PROT_MCS_SHIFT
));
3144 rt2870_io_mac_write(sc
, RT2870_REG_TX_CCK_PROT_CFG
, cck_prot
);
3146 /* OFDM frame protection */
3148 ofdm_prot
= RT2870_REG_RTSTH_ENABLE
| RT2870_REG_PROT_NAV_SHORT
|
3149 RT2870_REG_TXOP_ALLOW_ALL
;
3151 if (ic
->ic_flags
& IEEE80211_F_USEPROT
)
3153 RT2870_DPRINTF(sc
, RT2870_DEBUG_PROT
,
3154 "%s: updating protection mode: b/g protection mode=%s\n",
3155 device_get_nameunit(sc
->dev
),
3156 (ic
->ic_protmode
== IEEE80211_PROT_RTSCTS
) ? "RTS/CTS" :
3157 ((ic
->ic_protmode
== IEEE80211_PROT_CTSONLY
) ? "CTS-to-self" : "none"));
3159 if (ic
->ic_protmode
== IEEE80211_PROT_RTSCTS
)
3160 ofdm_prot
|= RT2870_REG_PROT_CTRL_RTS_CTS
;
3161 else if (ic
->ic_protmode
== IEEE80211_PROT_CTSONLY
)
3162 ofdm_prot
|= RT2870_REG_PROT_CTRL_CTS
;
3164 ofdm_prot
|= RT2870_REG_PROT_CTRL_NONE
;
3168 RT2870_DPRINTF(sc
, RT2870_DEBUG_PROT
,
3169 "%s: updating protection mode: b/g protection mode=%s\n",
3170 device_get_nameunit(sc
->dev
), "none");
3172 ofdm_prot
|= RT2870_REG_PROT_CTRL_NONE
;
3175 rt2870_io_mac_write(sc
, RT2870_REG_TX_OFDM_PROT_CFG
, ofdm_prot
);
3177 /* HT frame protection */
3179 if ((ic
->ic_opmode
== IEEE80211_M_STA
) && (ic
->ic_state
== IEEE80211_S_RUN
))
3180 htopmode
= ic
->ic_bss
->ni_htopmode
;
3182 htopmode
= ic
->ic_curhtprotmode
;
3184 RT2870_DPRINTF(sc
, RT2870_DEBUG_PROT
,
3185 "%s: updating protection mode: HT operation mode=0x%02x, protection mode=%s\n",
3186 device_get_nameunit(sc
->dev
),
3187 htopmode
& IEEE80211_HTINFO_OPMODE
,
3188 (ic
->ic_htprotmode
== IEEE80211_PROT_RTSCTS
) ? "RTS/CTS" :
3189 ((ic
->ic_htprotmode
== IEEE80211_PROT_CTSONLY
) ? "CTS-to-self" : "none"));
3191 switch (htopmode
& IEEE80211_HTINFO_OPMODE
)
3193 /* IEEE80211_HTINFO_OPMODE_HT20PR */
3194 case IEEE80211_HTINFO_OPMODE_HT20PR
:
3195 mm20_prot
= RT2870_REG_PROT_NAV_SHORT
| RT2870_REG_PROT_CTRL_NONE
|
3196 RT2870_REG_TXOP_ALLOW_CCK
| RT2870_REG_TXOP_ALLOW_OFDM
|
3197 RT2870_REG_TXOP_ALLOW_MM20
| RT2870_REG_TXOP_ALLOW_GF20
|
3198 (RT2870_REG_PROT_PHYMODE_OFDM
<< RT2870_REG_PROT_PHYMODE_SHIFT
) |
3199 (4 << RT2870_REG_PROT_MCS_SHIFT
);
3201 gf20_prot
= mm20_prot
;
3203 mm40_prot
= RT2870_REG_PROT_NAV_SHORT
| RT2870_REG_PROT_CTRL_NONE
|
3204 RT2870_REG_TXOP_ALLOW_ALL
|
3205 (RT2870_REG_PROT_PHYMODE_OFDM
<< RT2870_REG_PROT_PHYMODE_SHIFT
) |
3206 (0x84 << RT2870_REG_PROT_MCS_SHIFT
);
3208 if (ic
->ic_htprotmode
== IEEE80211_PROT_RTSCTS
)
3209 mm40_prot
|= RT2870_REG_PROT_CTRL_RTS_CTS
;
3210 else if (ic
->ic_htprotmode
== IEEE80211_PROT_CTSONLY
)
3211 mm40_prot
|= RT2870_REG_PROT_CTRL_CTS
;
3213 mm40_prot
|= RT2870_REG_PROT_CTRL_NONE
;
3215 gf40_prot
= mm40_prot
;
3218 /* IEEE80211_HTINFO_OPMODE_MIXED */
3219 case IEEE80211_HTINFO_OPMODE_MIXED
:
3220 mm20_prot
= RT2870_REG_PROT_NAV_SHORT
|
3221 RT2870_REG_TXOP_ALLOW_CCK
| RT2870_REG_TXOP_ALLOW_OFDM
|
3222 RT2870_REG_TXOP_ALLOW_MM20
| RT2870_REG_TXOP_ALLOW_GF20
;
3224 if (ic
->ic_flags
& IEEE80211_F_USEPROT
)
3225 mm20_prot
|= (RT2870_REG_PROT_PHYMODE_CCK
<< RT2870_REG_PROT_PHYMODE_SHIFT
) |
3226 (3 << RT2870_REG_PROT_MCS_SHIFT
);
3228 mm20_prot
|= (RT2870_REG_PROT_PHYMODE_OFDM
<< RT2870_REG_PROT_PHYMODE_SHIFT
) |
3229 (4 << RT2870_REG_PROT_MCS_SHIFT
);
3231 if (ic
->ic_htprotmode
== IEEE80211_PROT_RTSCTS
)
3232 mm20_prot
|= RT2870_REG_PROT_CTRL_RTS_CTS
;
3233 else if (ic
->ic_htprotmode
== IEEE80211_PROT_CTSONLY
)
3234 mm20_prot
|= RT2870_REG_PROT_CTRL_CTS
;
3236 mm20_prot
|= RT2870_REG_PROT_CTRL_NONE
;
3238 gf20_prot
= mm20_prot
;
3240 mm40_prot
= RT2870_REG_PROT_NAV_SHORT
| RT2870_REG_TXOP_ALLOW_ALL
;
3242 if (ic
->ic_flags
& IEEE80211_F_USEPROT
)
3243 mm40_prot
|= (RT2870_REG_PROT_PHYMODE_CCK
<< RT2870_REG_PROT_PHYMODE_SHIFT
) |
3244 (3 << RT2870_REG_PROT_MCS_SHIFT
);
3246 mm40_prot
|= (RT2870_REG_PROT_PHYMODE_OFDM
<< RT2870_REG_PROT_PHYMODE_SHIFT
) |
3247 (0x84 << RT2870_REG_PROT_MCS_SHIFT
);
3249 if (ic
->ic_htprotmode
== IEEE80211_PROT_RTSCTS
)
3250 mm40_prot
|= RT2870_REG_PROT_CTRL_RTS_CTS
;
3251 else if (ic
->ic_htprotmode
== IEEE80211_PROT_CTSONLY
)
3252 mm40_prot
|= RT2870_REG_PROT_CTRL_CTS
;
3254 mm40_prot
|= RT2870_REG_PROT_CTRL_NONE
;
3256 gf40_prot
= mm40_prot
;
3260 * IEEE80211_HTINFO_OPMODE_PURE
3261 * IEEE80211_HTINFO_OPMODE_PROTOPT
3263 case IEEE80211_HTINFO_OPMODE_PURE
:
3264 case IEEE80211_HTINFO_OPMODE_PROTOPT
:
3266 mm20_prot
= RT2870_REG_PROT_NAV_SHORT
| RT2870_REG_PROT_CTRL_NONE
|
3267 RT2870_REG_TXOP_ALLOW_CCK
| RT2870_REG_TXOP_ALLOW_OFDM
|
3268 RT2870_REG_TXOP_ALLOW_MM20
| RT2870_REG_TXOP_ALLOW_GF20
|
3269 (RT2870_REG_PROT_PHYMODE_OFDM
<< RT2870_REG_PROT_PHYMODE_SHIFT
) |
3270 (4 << RT2870_REG_PROT_MCS_SHIFT
);
3272 gf20_prot
= mm20_prot
;
3274 mm40_prot
= RT2870_REG_PROT_NAV_SHORT
| RT2870_REG_PROT_CTRL_NONE
|
3275 RT2870_REG_TXOP_ALLOW_ALL
|
3276 (RT2870_REG_PROT_PHYMODE_OFDM
<< RT2870_REG_PROT_PHYMODE_SHIFT
) |
3277 (0x84 << RT2870_REG_PROT_MCS_SHIFT
);
3279 gf40_prot
= mm40_prot
;
3283 rt2870_io_mac_write(sc
, RT2870_REG_TX_MM20_PROT_CFG
, mm20_prot
);
3284 rt2870_io_mac_write(sc
, RT2870_REG_TX_MM40_PROT_CFG
, mm40_prot
);
3285 rt2870_io_mac_write(sc
, RT2870_REG_TX_GF20_PROT_CFG
, gf20_prot
);
3286 rt2870_io_mac_write(sc
, RT2870_REG_TX_GF40_PROT_CFG
, gf40_prot
);
3290 * rt2870_asic_updateslot
3292 static void rt2870_asic_updateslot(struct rt2870_softc
*sc
)
3294 struct ieee80211com
*ic
;
3299 RT2870_DPRINTF(sc
, RT2870_DEBUG_STATE
,
3300 "%s: %s short slot time\n",
3301 device_get_nameunit(sc
->dev
),
3302 (ic
->ic_flags
& IEEE80211_F_SHSLOT
) ? "enabling" : "disabling");
3304 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_BKOFF_SLOT_CFG
);
3307 tmp
|= (ic
->ic_flags
& IEEE80211_F_SHSLOT
) ? 9 : 20;
3309 rt2870_io_mac_write(sc
, RT2870_REG_BKOFF_SLOT_CFG
, tmp
);
3313 * rt2870_asic_wme_update
3315 static void rt2870_asic_wme_update(struct rt2870_softc
*sc
)
3317 struct ieee80211com
*ic
;
3318 struct ieee80211_wme_state
*wme
;
3319 const struct wmeParams
*wmep
;
3324 wmep
= wme
->wme_chanParams
.cap_wmeParams
;
3326 RT2870_DPRINTF(sc
, RT2870_DEBUG_WME
,
3327 "%s: wme update: WME_AC_VO=%d/%d/%d/%d, WME_AC_VI=%d/%d/%d/%d, "
3328 "WME_AC_BK=%d/%d/%d/%d, WME_AC_BE=%d/%d/%d/%d\n",
3329 device_get_nameunit(sc
->dev
),
3330 wmep
[WME_AC_VO
].wmep_aifsn
,
3331 wmep
[WME_AC_VO
].wmep_logcwmin
, wmep
[WME_AC_VO
].wmep_logcwmax
,
3332 wmep
[WME_AC_VO
].wmep_txopLimit
,
3333 wmep
[WME_AC_VI
].wmep_aifsn
,
3334 wmep
[WME_AC_VI
].wmep_logcwmin
, wmep
[WME_AC_VI
].wmep_logcwmax
,
3335 wmep
[WME_AC_VI
].wmep_txopLimit
,
3336 wmep
[WME_AC_BK
].wmep_aifsn
,
3337 wmep
[WME_AC_BK
].wmep_logcwmin
, wmep
[WME_AC_BK
].wmep_logcwmax
,
3338 wmep
[WME_AC_BK
].wmep_txopLimit
,
3339 wmep
[WME_AC_BE
].wmep_aifsn
,
3340 wmep
[WME_AC_BE
].wmep_logcwmin
, wmep
[WME_AC_BE
].wmep_logcwmax
,
3341 wmep
[WME_AC_BE
].wmep_txopLimit
);
3343 for (i
= 0; i
< WME_NUM_AC
; i
++)
3344 rt2870_io_mac_write(sc
, RT2870_REG_TX_EDCA_AC_CFG(i
),
3345 (wmep
[i
].wmep_logcwmax
<< 16) | (wmep
[i
].wmep_logcwmin
<< 12) |
3346 (wmep
[i
].wmep_aifsn
<< 8) | wmep
[i
].wmep_txopLimit
);
3348 rt2870_io_mac_write(sc
, RT2870_REG_SCHDMA_WMM_AIFSN_CFG
,
3349 (wmep
[WME_AC_VO
].wmep_aifsn
<< 12) | (wmep
[WME_AC_VI
].wmep_aifsn
<< 8) |
3350 (wmep
[WME_AC_BK
].wmep_aifsn
<< 4) | wmep
[WME_AC_BE
].wmep_aifsn
);
3352 rt2870_io_mac_write(sc
, RT2870_REG_SCHDMA_WMM_CWMIN_CFG
,
3353 (wmep
[WME_AC_VO
].wmep_logcwmin
<< 12) | (wmep
[WME_AC_VI
].wmep_logcwmin
<< 8) |
3354 (wmep
[WME_AC_BK
].wmep_logcwmin
<< 4) | wmep
[WME_AC_BE
].wmep_logcwmin
);
3356 rt2870_io_mac_write(sc
, RT2870_REG_SCHDMA_WMM_CWMAX_CFG
,
3357 (wmep
[WME_AC_VO
].wmep_logcwmax
<< 12) | (wmep
[WME_AC_VI
].wmep_logcwmax
<< 8) |
3358 (wmep
[WME_AC_BK
].wmep_logcwmax
<< 4) | wmep
[WME_AC_BE
].wmep_logcwmax
);
3360 rt2870_io_mac_write(sc
, RT2870_REG_SCHDMA_WMM_TXOP0_CFG
,
3361 (wmep
[WME_AC_BK
].wmep_txopLimit
<< 16) | wmep
[WME_AC_BE
].wmep_txopLimit
);
3363 rt2870_io_mac_write(sc
, RT2870_REG_SCHDMA_WMM_TXOP1_CFG
,
3364 (wmep
[WME_AC_VO
].wmep_txopLimit
<< 16) | wmep
[WME_AC_VI
].wmep_txopLimit
);
3368 * rt2870_asic_update_beacon
3370 static int rt2870_asic_update_beacon(struct rt2870_softc
*sc
)
3372 struct ieee80211com
*ic
;
3374 struct rt2870_txwi txwi
;
3380 m
= ieee80211_beacon_alloc(ic
->ic_bss
, &sc
->beacon_offsets
);
3384 rate
= IEEE80211_IS_CHAN_5GHZ(ic
->ic_curchan
) ? 12 : 2;
3385 mcs
= rt2870_rate2mcs(rate
);
3387 memset(&txwi
, 0, sizeof(struct rt2870_txwi
));
3390 txwi
.pid_mpdu_len
= ((htole16(m
->m_pkthdr
.len
) & RT2870_TXWI_MPDU_LEN_MASK
) <<
3391 RT2870_TXWI_MPDU_LEN_SHIFT
);
3392 txwi
.txop
= (RT2870_TXWI_TXOP_HT
<< RT2870_TXWI_TXOP_SHIFT
);
3393 txwi
.mpdu_density_flags
|=
3394 (RT2870_TXWI_FLAGS_TS
<< RT2870_TXWI_FLAGS_SHIFT
);
3395 txwi
.bawin_size_xflags
|=
3396 (RT2870_TXWI_XFLAGS_NSEQ
<< RT2870_TXWI_XFLAGS_SHIFT
);
3400 txwi
.phymode_ifs_stbc_shortgi
=
3401 (RT2870_TXWI_PHYMODE_CCK
<< RT2870_TXWI_PHYMODE_SHIFT
);
3403 if (rate
!= 2 && (ic
->ic_flags
& IEEE80211_F_SHPREAMBLE
))
3404 mcs
|= RT2870_TXWI_MCS_SHOTPRE
;
3408 txwi
.phymode_ifs_stbc_shortgi
=
3409 (RT2870_TXWI_PHYMODE_OFDM
<< RT2870_TXWI_PHYMODE_SHIFT
);
3412 txwi
.bw_mcs
= (RT2870_TXWI_BW_20
<< RT2870_TXWI_BW_SHIFT
) |
3413 ((mcs
& RT2870_TXWI_MCS_MASK
) << RT2870_TXWI_MCS_SHIFT
);
3415 /* disable temporarily TSF sync */
3417 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_BCN_TIME_CFG
);
3419 tmp
&= ~(RT2870_REG_BCN_TX_ENABLE
|
3420 RT2870_REG_TSF_TIMER_ENABLE
|
3421 RT2870_REG_TBTT_TIMER_ENABLE
);
3423 rt2870_io_mac_write(sc
, RT2870_REG_BCN_TIME_CFG
, tmp
);
3425 /* write Tx wireless info and beacon frame to on-chip memory */
3427 rt2870_io_mac_write_multi(sc
, RT2870_REG_BEACON_BASE(0),
3428 &txwi
, sizeof(struct rt2870_txwi
));
3430 rt2870_io_mac_write_multi(sc
, RT2870_REG_BEACON_BASE(0) + sizeof(struct rt2870_txwi
),
3431 mtod(m
, uint8_t *), m
->m_pkthdr
.len
);
3433 /* enable again TSF sync */
3435 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_BCN_TIME_CFG
);
3437 tmp
|= (RT2870_REG_BCN_TX_ENABLE
|
3438 RT2870_REG_TSF_TIMER_ENABLE
|
3439 RT2870_REG_TBTT_TIMER_ENABLE
);
3441 rt2870_io_mac_write(sc
, RT2870_REG_BCN_TIME_CFG
, tmp
);
3449 * rt2870_asic_clear_keytables
3451 static void rt2870_asic_clear_keytables(struct rt2870_softc
*sc
)
3453 /* clear Rx WCID search table (entries = 256, entry size = 8) */
3455 rt2870_io_mac_set_region_4(sc
, RT2870_REG_WCID(0), 0, 2 * 256);
3457 /* clear WCID attribute table (entries = 256, entry size = 4) */
3459 rt2870_io_mac_set_region_4(sc
, RT2870_REG_WCID_ATTR(0), 0, 256);
3461 /* clear IV/EIV table (entries = 256, entry size = 8) */
3463 rt2870_io_mac_set_region_4(sc
, RT2870_REG_IVEIV(0), 0, 2 * 256);
3465 /* clear pairwise key table (entries = 256, entry size = 32) */
3467 rt2870_io_mac_set_region_4(sc
, RT2870_REG_PKEY(0), 0, 8 * 256);
3469 /* clear shared key table (entries = 32, entry size = 32) */
3471 rt2870_io_mac_set_region_4(sc
, RT2870_REG_SKEY(0, 0), 0, 8 * 32);
3473 /* clear shared key mode (entries = 32, entry size = 2) */
3475 rt2870_io_mac_set_region_4(sc
, RT2870_REG_SKEY_MODE(0), 0, 16);
3481 static uint8_t rt2870_rxrate(struct rt2870_rxwi
*rxwi
)
3483 uint8_t mcs
, phymode
;
3486 mcs
= (rxwi
->bw_mcs
>> RT2870_RXWI_MCS_SHIFT
) & RT2870_RXWI_MCS_MASK
;
3487 phymode
= (rxwi
->phymode_stbc_shortgi
>> RT2870_RXWI_PHYMODE_SHIFT
) &
3488 RT2870_RXWI_PHYMODE_MASK
;
3494 case RT2870_RXWI_PHYMODE_CCK
:
3495 switch (mcs
& ~RT2870_RXWI_MCS_SHOTPRE
)
3497 case 0: rate
= 2; break; /* 1 Mbps */
3498 case 1: rate
= 4; break; /* 2 MBps */
3499 case 2: rate
= 11; break; /* 5.5 Mbps */
3500 case 3: rate
= 22; break; /* 11 Mbps */
3504 case RT2870_RXWI_PHYMODE_OFDM
:
3507 case 0: rate
= 12; break; /* 6 Mbps */
3508 case 1: rate
= 18; break; /* 9 Mbps */
3509 case 2: rate
= 24; break; /* 12 Mbps */
3510 case 3: rate
= 36; break; /* 18 Mbps */
3511 case 4: rate
= 48; break; /* 24 Mbps */
3512 case 5: rate
= 72; break; /* 36 Mbps */
3513 case 6: rate
= 96; break; /* 48 Mbps */
3514 case 7: rate
= 108; break; /* 54 Mbps */
3518 case RT2870_RXWI_PHYMODE_HT_MIXED
:
3519 case RT2870_RXWI_PHYMODE_HT_GF
:
3527 * rt2870_maxrssi_rxpath
3529 static uint8_t rt2870_maxrssi_rxpath(struct rt2870_softc
*sc
,
3530 const struct rt2870_rxwi
*rxwi
)
3536 if (sc
->nrxpath
> 1)
3537 if (rxwi
->rssi
[1] > rxwi
->rssi
[rxpath
])
3540 if (sc
->nrxpath
> 2)
3541 if (rxwi
->rssi
[2] > rxwi
->rssi
[rxpath
])
3550 static int8_t rt2870_rssi2dbm(struct rt2870_softc
*sc
,
3551 uint8_t rssi
, uint8_t rxpath
)
3553 struct ieee80211com
*ic
;
3554 struct ieee80211_channel
*c
;
3559 chan
= ieee80211_chan2ieee(ic
, c
);
3561 if (IEEE80211_IS_CHAN_5GHZ(c
))
3563 delta
= sc
->rssi_off_5ghz
[rxpath
];
3566 delta
-= sc
->lna_gain
[1];
3567 else if (chan
<= 128)
3568 delta
-= sc
->lna_gain
[2];
3570 delta
-= sc
->lna_gain
[3];
3574 delta
= sc
->rssi_off_2ghz
[rxpath
] - sc
->lna_gain
[0];
3577 return (-12 - delta
- rssi
);
3583 static uint8_t rt2870_rate2mcs(uint8_t rate
)
3610 static int rt2870_ackrate(struct ieee80211com
*ic
, int rate
)
3622 return (ic
->ic_curmode
== IEEE80211_MODE_11B
) ? 4 : rate
;
3641 /* default to 1Mbps */
3648 static uint16_t rt2870_txtime(int len
, int rate
, uint32_t flags
)
3652 if (RT2870_RATE_IS_OFDM(rate
))
3654 txtime
= (8 + 4 * len
+ 3 + rate
- 1) / rate
;
3655 txtime
= 16 + 4 + 4 * txtime
+ 6;
3659 txtime
= (16 * len
+ rate
- 1) / rate
;
3661 if (rate
!= 2 && (flags
& IEEE80211_F_SHPREAMBLE
))
3673 static void rt2870_rx_frame(struct rt2870_softc
*sc
,
3674 uint8_t *buf
, uint32_t dmalen
)
3676 struct ieee80211com
*ic
;
3678 struct ieee80211_frame
*wh
;
3679 struct ieee80211_node
*ni
;
3680 struct rt2870_softc_rx_radiotap_header
*tap
;
3681 struct rt2870_rxwi
*rxwi
;
3682 struct rt2870_rxinfo
*rxinfo
;
3684 uint32_t rxinfo_flags
;
3685 uint8_t cipher_err
, rssi
, ant
, phymode
, bw
, shortgi
, mcs
;
3687 int len
, ampdu
, amsdu
;
3692 /* get Rx wireless info */
3694 rxwi
= (struct rt2870_rxwi
*) buf
;
3695 len
= (le16toh(rxwi
->tid_size
) >> RT2870_RXWI_SIZE_SHIFT
) &
3696 RT2870_RXWI_SIZE_MASK
;
3700 RT2870_DPRINTF(sc
, RT2870_DEBUG_RX
,
3701 "%s: bad rxwi len: DMA len=%d, rxwi len=%d\n",
3702 device_get_nameunit(sc
->dev
), dmalen
, len
);
3708 rxinfo
= (struct rt2870_rxinfo
*) ((caddr_t
) rxwi
+ dmalen
);
3709 rxinfo_flags
= le32toh(rxinfo
->flags
);
3711 RT2870_DPRINTF(sc
, RT2870_DEBUG_RX
,
3712 "%s: Rx frame: DMA len=%d, len=%d, rxinfo flags=0x%08x\n",
3713 device_get_nameunit(sc
->dev
), dmalen
, len
, rxinfo_flags
);
3715 /* check for crc errors */
3717 if (rxinfo_flags
& RT2870_RXINFO_FLAGS_CRC_ERR
)
3719 RT2870_DPRINTF(sc
, RT2870_DEBUG_RX
,
3720 "%s: rxinfo: crc error\n",
3721 device_get_nameunit(sc
->dev
));
3725 if (!(ifp
->if_flags
& IFF_PROMISC
))
3729 wh
= (struct ieee80211_frame
*) (rxwi
+ 1);
3731 /* check for L2 padding between IEEE 802.11 frame header and body */
3733 if (rxinfo_flags
& RT2870_RXINFO_FLAGS_L2PAD
)
3735 RT2870_DPRINTF(sc
, RT2870_DEBUG_RX
,
3736 "%s: L2 padding: DMA len=%d, len=%d\n",
3737 device_get_nameunit(sc
->dev
), dmalen
, len
);
3742 m
= m_getjcl(M_DONTWAIT
, MT_DATA
, M_PKTHDR
, MJUMPAGESIZE
);
3745 sc
->rx_mbuf_alloc_errors
++;
3750 m
->m_pkthdr
.rcvif
= ifp
;
3751 m
->m_pkthdr
.len
= m
->m_len
= len
;
3753 m_copyback(m
, 0, len
, (caddr_t
) wh
);
3755 wh
= mtod(m
, struct ieee80211_frame
*);
3757 /* check for cipher errors */
3759 if (rxinfo_flags
& RT2870_RXINFO_FLAGS_DECRYPTED
)
3761 cipher_err
= ((rxinfo_flags
>> RT2870_RXINFO_FLAGS_CIPHER_ERR_SHIFT
) &
3762 RT2870_RXINFO_FLAGS_CIPHER_ERR_MASK
);
3763 if (cipher_err
== RT2870_RXINFO_FLAGS_CIPHER_ERR_NONE
)
3765 if (wh
->i_fc
[1] & IEEE80211_FC1_WEP
)
3766 wh
->i_fc
[1] &= ~IEEE80211_FC1_WEP
;
3768 m
->m_flags
|= M_WEP
;
3772 RT2870_DPRINTF(sc
, RT2870_DEBUG_RX
,
3773 "%s: rxinfo: cipher error=0x%02x\n",
3774 device_get_nameunit(sc
->dev
), cipher_err
);
3778 if (!(ifp
->if_flags
& IFF_PROMISC
))
3787 if (wh
->i_fc
[1] & IEEE80211_FC1_WEP
)
3791 if (!(ifp
->if_flags
& IFF_PROMISC
))
3799 /* check for A-MPDU */
3801 if (rxinfo_flags
& RT2870_RXINFO_FLAGS_AMPDU
)
3803 m
->m_flags
|= M_AMPDU
;
3811 ant
= rt2870_maxrssi_rxpath(sc
, rxwi
);
3812 rssi
= rxwi
->rssi
[ant
];
3813 rssi_dbm
= rt2870_rssi2dbm(sc
, rssi
, ant
);
3814 phymode
= ((rxwi
->phymode_stbc_shortgi
>> RT2870_RXWI_PHYMODE_SHIFT
) &
3815 RT2870_RXWI_PHYMODE_MASK
);
3816 bw
= ((rxwi
->bw_mcs
>> RT2870_RXWI_BW_SHIFT
) & RT2870_RXWI_BW_MASK
);
3817 shortgi
= ((rxwi
->phymode_stbc_shortgi
>> RT2870_RXWI_SHORTGI_SHIFT
) &
3818 RT2870_RXWI_SHORTGI_MASK
);
3819 mcs
= ((rxwi
->bw_mcs
>> RT2870_RXWI_MCS_SHIFT
) & RT2870_RXWI_MCS_MASK
);
3820 amsdu
= (rxinfo_flags
& RT2870_RXINFO_FLAGS_AMSDU
);
3822 if (bpf_peers_present(sc
->drvbpf
))
3826 tap
->flags
= IEEE80211_RADIOTAP_F_DATAPAD
;
3827 tap
->dbm_antsignal
= rssi_dbm
;
3828 tap
->dbm_antnoise
= RT2870_NOISE_FLOOR
;
3830 tap
->antsignal
= rssi
;
3831 tap
->chan_flags
= htole32(ic
->ic_curchan
->ic_flags
);
3832 tap
->chan_freq
= htole16(ic
->ic_curchan
->ic_freq
);
3833 tap
->chan_ieee
= ic
->ic_curchan
->ic_ieee
;
3834 tap
->chan_maxpow
= 0;
3836 if (phymode
== RT2870_RXWI_PHYMODE_CCK
|| phymode
== RT2870_RXWI_PHYMODE_OFDM
)
3837 tap
->rate
= rt2870_rxrate(rxwi
);
3839 tap
->rate
= mcs
| IEEE80211_RATE_MCS
;
3841 if (rxwi
->bw_mcs
& RT2870_RXWI_MCS_SHOTPRE
)
3842 tap
->flags
|= IEEE80211_RADIOTAP_F_SHORTPRE
;
3845 tap
->flags
|= IEEE80211_RADIOTAP_F_SHORTGI
;
3847 bpf_mtap2(sc
->drvbpf
, tap
, sc
->rxtap_len
, m
);
3850 RT2870_DPRINTF(sc
, RT2870_DEBUG_RX
,
3851 "%s: received frame: len=%d, phymode=%d, bw=%d, shortgi=%d, mcs=%d, "
3852 "ant=%d, rssi=%d/%d/%d, snr=%d/%d, wcid=0x%02x, ampdu=%d, amsdu=%d\n",
3853 device_get_nameunit(sc
->dev
),
3854 len
, phymode
, bw
, shortgi
, mcs
,
3855 ant
, rxwi
->rssi
[0], rxwi
->rssi
[1], rxwi
->rssi
[2],
3856 rxwi
->snr
[0], rxwi
->snr
[1],
3857 rxwi
->wcid
, ampdu
, amsdu
);
3859 ni
= ieee80211_find_rxnode(ic
, (struct ieee80211_frame_min
*) wh
);
3861 ieee80211_input(ic
, m
, ni
, rssi_dbm
- RT2870_NOISE_FLOOR
, RT2870_NOISE_FLOOR
, 0);
3863 ieee80211_free_node(ni
);
3869 static int rt2870_tx_frame(struct rt2870_softc
*sc
,
3870 struct mbuf
*m
, struct ieee80211_node
*ni
, int qid
)
3872 struct ieee80211com
*ic
;
3873 struct rt2870_softc_tx_ring
*ring
;
3874 struct rt2870_softc_tx_data
*data
;
3875 struct rt2870_txinfo
*txinfo
;
3876 struct rt2870_txwi
*txwi
;
3877 struct ieee80211_frame
*wh
;
3878 struct rt2870_softc_tx_radiotap_header
*tap
;
3879 u_int hdrsize
, hdrspace
;
3880 uint8_t type
, rate
, bw
, shortgi
, mcs
, pid
, wcid
;
3881 uint16_t qos
, len
, dmalen
, mpdu_len
, dur
;
3882 int hasqos
, ackrate
;
3886 ring
= &sc
->tx_ring
[qid
];
3887 data
= STAILQ_FIRST(&ring
->inactive
);
3888 STAILQ_REMOVE_HEAD(&ring
->inactive
, next
);
3889 txinfo
= (struct rt2870_txinfo
*) data
->buf
;
3890 txwi
= (struct rt2870_txwi
*) (txinfo
+ 1);
3892 wh
= mtod(m
, struct ieee80211_frame
*);
3894 type
= wh
->i_fc
[0] & IEEE80211_FC0_TYPE_MASK
;
3896 hasqos
= IEEE80211_QOS_HAS_SEQ(wh
);
3899 if (IEEE80211_HAS_ADDR4(wh
))
3900 qos
= le16toh(*(const uint16_t *)
3901 (((struct ieee80211_qosframe_addr4
*) wh
)->i_qos
));
3903 qos
= le16toh(*(const uint16_t *)
3904 (((struct ieee80211_qosframe
*) wh
)->i_qos
));
3911 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
3913 if (IEEE80211_IS_MULTICAST(wh
->i_addr1
) || type
!= IEEE80211_FC0_TYPE_DATA
)
3915 else if (ic
->ic_fixed_rate
!= IEEE80211_FIXED_RATE_NONE
)
3916 rate
= ic
->ic_fixed_rate
;
3918 rate
= ni
->ni_htrates
.rs_rates
[ni
->ni_txrate
];
3922 if (IEEE80211_IS_MULTICAST(wh
->i_addr1
) || type
!= IEEE80211_FC0_TYPE_DATA
)
3923 rate
= IEEE80211_IS_CHAN_5GHZ(ic
->ic_curchan
) ? 12 : 2;
3924 else if (ic
->ic_fixed_rate
!= IEEE80211_FIXED_RATE_NONE
)
3925 rate
= ic
->ic_fixed_rate
;
3927 rate
= ni
->ni_rates
.rs_rates
[ni
->ni_txrate
];
3930 rate
&= IEEE80211_RATE_VAL
;
3932 len
= sizeof(struct rt2870_txinfo
) + sizeof(struct rt2870_txwi
) + m
->m_pkthdr
.len
;
3934 /* align end on a 4-bytes boundary */
3936 dmalen
= (len
+ 3) & ~3;
3940 memset(txinfo
, 0, sizeof(struct rt2870_txinfo
));
3942 txinfo
->len
= htole16(dmalen
);
3944 txinfo
->qsel_flags
= (RT2870_TXINFO_QSEL_EDCA
<< RT2870_TXINFO_QSEL_SHIFT
);
3946 /* fill Tx wireless info */
3948 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
3951 mcs
= rt2870_rate2mcs(rate
);
3955 wcid
= (type
== IEEE80211_FC0_TYPE_DATA
) ?
3956 RT2870_AID2WCID(ni
->ni_associd
) : 0xff;
3958 /* calculate MPDU length without padding */
3960 hdrsize
= ieee80211_hdrsize(wh
);
3961 hdrspace
= ieee80211_hdrspace(ic
, wh
);
3962 mpdu_len
= m
->m_pkthdr
.len
- hdrspace
+ hdrsize
;
3964 memset(txwi
, 0, sizeof(struct rt2870_txwi
));
3968 txwi
->pid_mpdu_len
= ((htole16(pid
) & RT2870_TXWI_PID_MASK
) <<
3969 RT2870_TXWI_PID_SHIFT
) | ((htole16(mpdu_len
) & RT2870_TXWI_MPDU_LEN_MASK
) <<
3970 RT2870_TXWI_MPDU_LEN_SHIFT
);
3972 if ((ic
->ic_flags_ext
& (IEEE80211_FEXT_SHORTGI20
| IEEE80211_FEXT_SHORTGI40
)) &&
3973 (ni
->ni_flags
& IEEE80211_NODE_HT
))
3978 txwi
->phymode_ifs_stbc_shortgi
|=
3979 ((shortgi
& RT2870_TXWI_SHORTGI_MASK
) << RT2870_TXWI_SHORTGI_SHIFT
);
3981 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
3983 txwi
->phymode_ifs_stbc_shortgi
|=
3984 (RT2870_TXWI_PHYMODE_HT_MIXED
<< RT2870_TXWI_PHYMODE_SHIFT
);
3988 if (!RT2870_RATE_IS_OFDM(rate
))
3990 txwi
->phymode_ifs_stbc_shortgi
|=
3991 (RT2870_TXWI_PHYMODE_CCK
<< RT2870_TXWI_PHYMODE_SHIFT
);
3993 if (rate
!= 2 && (ic
->ic_flags
& IEEE80211_F_SHPREAMBLE
))
3994 mcs
|= RT2870_TXWI_MCS_SHOTPRE
;
3998 txwi
->phymode_ifs_stbc_shortgi
|=
3999 (RT2870_TXWI_PHYMODE_OFDM
<< RT2870_TXWI_PHYMODE_SHIFT
);
4003 if ((ni
->ni_flags
& IEEE80211_NODE_HT
) &&
4004 (ni
->ni_htcap
& IEEE80211_HTCAP_CHWIDTH40
))
4005 bw
= RT2870_TXWI_BW_40
;
4007 bw
= RT2870_TXWI_BW_20
;
4009 txwi
->bw_mcs
= ((bw
& RT2870_TXWI_BW_MASK
) << RT2870_TXWI_BW_SHIFT
) |
4010 ((mcs
& RT2870_TXWI_MCS_MASK
) << RT2870_TXWI_MCS_SHIFT
);
4012 if (type
!= IEEE80211_FC0_TYPE_DATA
)
4013 txwi
->txop
= (RT2870_TXWI_TXOP_BACKOFF
<< RT2870_TXWI_TXOP_SHIFT
);
4015 txwi
->txop
= (RT2870_TXWI_TXOP_HT
<< RT2870_TXWI_TXOP_SHIFT
);
4017 /* skip ACKs for multicast frames and probe responses */
4019 if (!IEEE80211_IS_MULTICAST(wh
->i_addr1
) &&
4020 ((wh
->i_fc
[0] & (IEEE80211_FC0_TYPE_MASK
| IEEE80211_FC0_SUBTYPE_MASK
)) !=
4021 (IEEE80211_FC0_TYPE_MGT
| IEEE80211_FC0_SUBTYPE_PROBE_RESP
)) &&
4022 (!hasqos
|| (qos
& IEEE80211_QOS_ACKPOLICY
) != IEEE80211_QOS_ACKPOLICY_NOACK
))
4024 txwi
->bawin_size_xflags
|=
4025 (RT2870_TXWI_XFLAGS_ACK
<< RT2870_TXWI_XFLAGS_SHIFT
);
4027 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
4029 /* preamble + plcp + signal extension */
4035 ackrate
= rt2870_ackrate(ic
, rate
);
4037 dur
= rt2870_txtime(RT2870_ACK_SIZE
, ackrate
, ic
->ic_flags
) +
4041 *(uint16_t *) wh
->i_dur
= htole16(dur
);
4044 /* ask MAC to insert timestamp into probe responses */
4046 if ((wh
->i_fc
[0] & (IEEE80211_FC0_TYPE_MASK
| IEEE80211_FC0_SUBTYPE_MASK
)) ==
4047 (IEEE80211_FC0_TYPE_MGT
| IEEE80211_FC0_SUBTYPE_PROBE_RESP
))
4048 txwi
->mpdu_density_flags
|=
4049 (RT2870_TXWI_FLAGS_TS
<< RT2870_TXWI_FLAGS_SHIFT
);
4051 if (bpf_peers_present(sc
->drvbpf
))
4055 tap
->flags
= IEEE80211_RADIOTAP_F_DATAPAD
;
4056 tap
->chan_flags
= htole32(ic
->ic_curchan
->ic_flags
);
4057 tap
->chan_freq
= htole16(ic
->ic_curchan
->ic_freq
);
4058 tap
->chan_ieee
= ic
->ic_curchan
->ic_ieee
;
4059 tap
->chan_maxpow
= 0;
4061 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
4062 tap
->rate
= mcs
| IEEE80211_RATE_MCS
;
4066 if (mcs
& RT2870_TXWI_MCS_SHOTPRE
)
4067 tap
->flags
|= IEEE80211_RADIOTAP_F_SHORTPRE
;
4070 tap
->flags
|= IEEE80211_RADIOTAP_F_SHORTGI
;
4072 if (wh
->i_fc
[1] & IEEE80211_FC1_WEP
)
4073 tap
->flags
|= IEEE80211_RADIOTAP_F_WEP
;
4075 if (wh
->i_fc
[1] & IEEE80211_FC1_WEP
)
4077 wh
->i_fc
[1] &= ~IEEE80211_FC1_WEP
;
4079 bpf_mtap2(sc
->drvbpf
, tap
, sc
->txtap_len
, m
);
4081 wh
->i_fc
[1] |= IEEE80211_FC1_WEP
;
4085 bpf_mtap2(sc
->drvbpf
, tap
, sc
->txtap_len
, m
);
4089 m_copydata(m
, 0, m
->m_pkthdr
.len
, (caddr_t
) (txwi
+ 1));
4091 RT2870_DPRINTF(sc
, RT2870_DEBUG_TX
,
4092 "%s: sending frame: qid=%d, hdrsize=%d, hdrspace=%d, len=%d, "
4093 "bw=%d, shortgi=%d, mcs=%d, wcid=0x%02x, DMA len=%d\n",
4094 device_get_nameunit(sc
->dev
),
4095 qid
, hdrsize
, hdrspace
, m
->m_pkthdr
.len
, bw
, shortgi
, mcs
, wcid
, dmalen
);
4100 STAILQ_INSERT_TAIL(&ring
->active
, data
, next
);
4103 usbd_setup_xfer(data
->xfer
, ring
->usb_pipe
, ring
, data
->buf
, len
,
4104 USBD_FORCE_SHORT_XFER
| USBD_NO_COPY
, RT2870_USB_XFER_TIMEOUT
, rt2870_tx_intr
);
4106 usbd_transfer(data
->xfer
);
4114 static int rt2870_tx_raw(struct rt2870_softc
*sc
,
4115 struct mbuf
*m
, struct ieee80211_node
*ni
,
4116 const struct ieee80211_bpf_params
*params
)
4118 RT2870_DPRINTF(sc
, RT2870_DEBUG_TX
,
4120 device_get_nameunit(sc
->dev
));
4128 static void rt2870_rx_intr(usbd_xfer_handle xfer
,
4129 usbd_private_handle priv
, usbd_status status
)
4131 struct rt2870_softc
*sc
;
4133 struct rt2870_softc_rx_ring
*ring
;
4134 struct rt2870_softc_rx_data
*data
;
4139 ring
= &sc
->rx_ring
;
4141 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
4144 RT2870_DPRINTF(sc
, RT2870_DEBUG_INTR
,
4145 "%s: Rx interrupt: %s\n",
4146 device_get_nameunit(sc
->dev
), usbd_errstr(status
));
4149 sc
->rx_interrupts
++;
4153 case USBD_NORMAL_COMPLETION
:
4154 data
= STAILQ_FIRST(&ring
->active
);
4158 STAILQ_REMOVE_HEAD(&ring
->active
, next
);
4160 KASSERT(data
->xfer
== xfer
,
4161 ("%s: Rx interrupt: invalid USB xfer\n",
4162 device_get_nameunit(sc
->dev
)));
4164 usbd_get_xfer_status(xfer
, NULL
, NULL
, &len
, NULL
);
4168 STAILQ_INSERT_TAIL(&ring
->done
, data
, next
);
4170 taskqueue_enqueue(sc
->taskqueue
, &sc
->rx_done_task
);
4173 case USBD_CANCELLED
:
4174 case USBD_NOT_STARTED
:
4178 if (status
== USBD_STALLED
)
4179 usbd_clear_endpoint_stall_async(ring
->usb_pipe
);
4181 data
= STAILQ_FIRST(&ring
->active
);
4184 STAILQ_REMOVE_HEAD(&ring
->active
, next
);
4186 STAILQ_INSERT_TAIL(&ring
->active
, data
, next
);
4188 usbd_setup_xfer(xfer
, ring
->usb_pipe
, sc
, data
->buf
,
4189 RT2870_USB_RX_BULK_BUFLEN
, USBD_SHORT_XFER_OK
| USBD_NO_COPY
,
4190 USBD_NO_TIMEOUT
, rt2870_rx_intr
);
4192 usbd_transfer(xfer
);
4201 static void rt2870_tx_intr(usbd_xfer_handle xfer
,
4202 usbd_private_handle priv
, usbd_status status
)
4204 struct rt2870_softc
*sc
;
4206 struct rt2870_softc_tx_ring
*ring
;
4207 struct rt2870_softc_tx_data
*data
;
4213 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
4216 RT2870_DPRINTF(sc
, RT2870_DEBUG_INTR
,
4217 "%s: Tx interrupt: %s\n",
4218 device_get_nameunit(sc
->dev
), usbd_errstr(status
));
4221 sc
->tx_interrupts
[ring
->qid
]++;
4225 case USBD_NORMAL_COMPLETION
:
4226 data
= STAILQ_FIRST(&ring
->active
);
4230 STAILQ_REMOVE_HEAD(&ring
->active
, next
);
4232 STAILQ_INSERT_TAIL(&ring
->done
, data
, next
);
4234 taskqueue_enqueue(sc
->taskqueue
, &sc
->tx_done_task
);
4237 case USBD_CANCELLED
:
4238 case USBD_NOT_STARTED
:
4242 data
= STAILQ_FIRST(&ring
->active
);
4245 STAILQ_REMOVE_HEAD(&ring
->active
, next
);
4247 if (data
->m
!= NULL
)
4253 if (data
->ni
!= NULL
)
4255 ieee80211_free_node(data
->ni
);
4259 STAILQ_INSERT_TAIL(&ring
->inactive
, data
, next
);
4264 printf("%s: could not transmit buffer: qid=%d, status=%s\n",
4265 device_get_nameunit(sc
->dev
), ring
->qid
, usbd_errstr(status
));
4268 ifp
->if_drv_flags
&= ~IFF_DRV_OACTIVE
;
4270 if (status
== USBD_STALLED
)
4271 usbd_clear_endpoint_stall_async(ring
->usb_pipe
);
4277 * rt2870_rx_done_task
4279 static void rt2870_rx_done_task(void *context
, int pending
)
4281 struct rt2870_softc
*sc
;
4287 RT2870_DPRINTF(sc
, RT2870_DEBUG_RX
,
4288 "%s: Rx done task\n",
4289 device_get_nameunit(sc
->dev
));
4291 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
4294 if (rt2870_rx_eof(sc
, sc
->rx_process_limit
) != 0)
4295 taskqueue_enqueue(sc
->taskqueue
, &sc
->rx_done_task
);
4299 * rt2870_tx_done_task
4301 static void rt2870_tx_done_task(void *context
, int pending
)
4303 struct rt2870_softc
*sc
;
4310 RT2870_DPRINTF(sc
, RT2870_DEBUG_TX
,
4311 "%s: Tx done task\n",
4312 device_get_nameunit(sc
->dev
));
4314 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
4317 for (i
= sc
->usb_endpoints
- 2; i
>= 0; i
--)
4318 rt2870_tx_eof(sc
, &sc
->tx_ring
[i
]);
4322 ifp
->if_drv_flags
&= ~IFF_DRV_OACTIVE
;
4326 * rt2870_periodic_task
4328 static void rt2870_periodic_task(void *context
, int pending
)
4330 struct rt2870_softc
*sc
;
4332 struct ieee80211com
*ic
;
4338 RT2870_DPRINTF(sc
, RT2870_DEBUG_PERIODIC
,
4339 "%s: periodic task: round=%lu\n",
4340 device_get_nameunit(sc
->dev
), sc
->periodic_round
);
4342 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
4345 sc
->periodic_round
++;
4347 rt2870_update_stats(sc
);
4349 if ((sc
->periodic_round
% 10) == 0)
4351 rt2870_update_raw_counters(sc
);
4353 rt2870_watchdog(sc
);
4355 if (ic
->ic_opmode
== IEEE80211_M_STA
)
4356 rt2870_amrr_update_iter_func(sc
, ic
->ic_bss
);
4358 ieee80211_iterate_nodes(&ic
->ic_sta
, rt2870_amrr_update_iter_func
, sc
);
4361 callout_reset(&sc
->periodic_ch
, hz
/ 10, rt2870_periodic
, sc
);
4367 static void rt2870_cmd_task(void *context
, int pending
)
4369 struct rt2870_softc
*sc
;
4370 struct rt2870_softc_cmd_ring
*ring
;
4371 struct rt2870_softc_cmd
*cmd
;
4374 ring
= &sc
->cmd_ring
;
4378 RT2870_SOFTC_LOCK(sc
);
4380 cmd
= STAILQ_FIRST(&ring
->active
);
4383 RT2870_SOFTC_UNLOCK(sc
);
4387 STAILQ_REMOVE_HEAD(&ring
->active
, next
);
4389 RT2870_SOFTC_UNLOCK(sc
);
4391 cmd
->cb(sc
, cmd
->data
);
4393 RT2870_SOFTC_LOCK(sc
);
4395 STAILQ_INSERT_TAIL(&ring
->inactive
, cmd
, next
);
4398 RT2870_SOFTC_UNLOCK(sc
);
4405 static int rt2870_rx_eof(struct rt2870_softc
*sc
, int limit
)
4408 struct rt2870_softc_rx_ring
*ring
;
4409 struct rt2870_softc_rx_data
*data
;
4415 ring
= &sc
->rx_ring
;
4421 RT2870_SOFTC_LOCK(sc
);
4423 data
= STAILQ_FIRST(&ring
->done
);
4426 RT2870_SOFTC_UNLOCK(sc
);
4430 STAILQ_REMOVE_HEAD(&ring
->done
, next
);
4432 RT2870_SOFTC_UNLOCK(sc
);
4437 if (len
< RT2870_RX_DESC_SIZE
)
4443 while (len
> (sizeof(uint32_t) + sizeof(struct rt2870_rxinfo
)))
4445 dmalen
= (le32toh(*(uint32_t *) buf
) & 0xffff);
4447 if (dmalen
== 0 || (dmalen
& 3) != 0)
4449 RT2870_DPRINTF(sc
, RT2870_DEBUG_RX
,
4450 "%s: bad DMA len=%u\n",
4451 device_get_nameunit(sc
->dev
), dmalen
);
4455 if ((dmalen
+ sizeof(uint32_t) + sizeof(struct rt2870_rxinfo
)) > len
)
4457 RT2870_DPRINTF(sc
, RT2870_DEBUG_RX
,
4458 "%s: bad DMA len: DMA len=%u, USB len=%d\n",
4459 device_get_nameunit(sc
->dev
),
4460 (dmalen
+ sizeof(uint32_t) + sizeof(struct rt2870_rxinfo
)), len
);
4466 rt2870_rx_frame(sc
, buf
+ sizeof(uint32_t), dmalen
);
4468 buf
+= (dmalen
+ sizeof(uint32_t) + sizeof(struct rt2870_rxinfo
));
4469 len
-= (dmalen
+ sizeof(uint32_t) + sizeof(struct rt2870_rxinfo
));
4474 RT2870_SOFTC_LOCK(sc
);
4476 STAILQ_INSERT_TAIL(&ring
->active
, data
, next
);
4478 RT2870_SOFTC_UNLOCK(sc
);
4480 usbd_setup_xfer(data
->xfer
, ring
->usb_pipe
, sc
, data
->buf
,
4481 RT2870_USB_RX_BULK_BUFLEN
, USBD_SHORT_XFER_OK
| USBD_NO_COPY
,
4482 USBD_NO_TIMEOUT
, rt2870_rx_intr
);
4484 usbd_transfer(data
->xfer
);
4489 RT2870_DPRINTF(sc
, RT2870_DEBUG_RX
,
4490 "%s: Rx eof: nframes=%d\n",
4491 device_get_nameunit(sc
->dev
), nframes
);
4493 sc
->rx_packets
+= nframes
;
4495 return (limit
== 0);
4501 static void rt2870_tx_eof(struct rt2870_softc
*sc
,
4502 struct rt2870_softc_tx_ring
*ring
)
4505 struct rt2870_softc_tx_data
*data
;
4514 RT2870_SOFTC_LOCK(sc
);
4516 data
= STAILQ_FIRST(&ring
->done
);
4519 RT2870_SOFTC_UNLOCK(sc
);
4523 STAILQ_REMOVE_HEAD(&ring
->done
, next
);
4525 RT2870_SOFTC_UNLOCK(sc
);
4529 if (data
->m
->m_flags
& M_TXCB
)
4530 ieee80211_process_callback(data
->ni
, data
->m
, 0);
4534 ieee80211_free_node(data
->ni
);
4539 RT2870_SOFTC_LOCK(sc
);
4541 STAILQ_INSERT_TAIL(&ring
->inactive
, data
, next
);
4545 RT2870_SOFTC_UNLOCK(sc
);
4550 RT2870_DPRINTF(sc
, RT2870_DEBUG_TX
,
4551 "%s: Tx eof: qid=%d, nframes=%d\n",
4552 device_get_nameunit(sc
->dev
), ring
->qid
, nframes
);
4556 * rt2870_update_stats
4558 static void rt2870_update_stats(struct rt2870_softc
*sc
)
4561 struct ieee80211com
*ic
;
4562 struct ieee80211_node
*ni
;
4566 int txcnt
, retrycnt
, failcnt
;
4571 RT2870_DPRINTF(sc
, RT2870_DEBUG_STATS
,
4572 "%s: update statistic\n",
4573 device_get_nameunit(sc
->dev
));
4575 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
4578 rt2870_drain_fifo_stats(sc
);
4580 if (ic
->ic_opmode
== IEEE80211_M_STA
)
4584 associd
= (ni
!= NULL
) ? ni
->ni_associd
: 0;
4585 wcid
= RT2870_AID2WCID(associd
);
4587 /* read and clear Tx statistic registers */
4589 rt2870_io_mac_read_multi(sc
, RT2870_REG_TX_STA_CNT0
,
4590 stacnt
, sizeof(stacnt
));
4592 txcnt
= le32toh(stacnt
[1]) & 0xffff;
4593 retrycnt
= le32toh(stacnt
[1]) >> 16;
4594 failcnt
= le32toh(stacnt
[0]) & 0xffff;
4596 RT2870_DPRINTF(sc
, RT2870_DEBUG_STATS
,
4597 "%s: update statistic: associd=0x%04x, txcnt=%d, retrycnt=%d, failcnt=%d\n",
4598 device_get_nameunit(sc
->dev
),
4599 associd
, txcnt
, retrycnt
, failcnt
);
4601 ifp
->if_oerrors
+= failcnt
;
4603 rt2870_amrr_tx_update(&sc
->amrr_node
[wcid
],
4604 txcnt
+ retrycnt
+ failcnt
, txcnt
+ retrycnt
, retrycnt
+ failcnt
);
4611 static void rt2870_watchdog(struct rt2870_softc
*sc
)
4616 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_PBF_TXRXQ_PCNT
);
4618 RT2870_DPRINTF(sc
, RT2870_DEBUG_WATCHDOG
,
4619 "%s: watchdog: TXRXQ_PCNT=0x%08x\n",
4620 device_get_nameunit(sc
->dev
), tmp
);
4622 if (((tmp
>> RT2870_REG_TX0Q_PCNT_SHIFT
) & RT2870_REG_TX0Q_PCNT_MASK
) != 0)
4624 sc
->tx_queue_not_empty
[0]++;
4626 rt2870_io_mac_write(sc
, RT2870_REG_PBF_CFG
, 0xf40012);
4628 for (ntries
= 0; ntries
< 10; ntries
++)
4630 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_PBF_TXRXQ_PCNT
);
4631 if (((tmp
>> RT2870_REG_TX0Q_PCNT_SHIFT
) & RT2870_REG_TX0Q_PCNT_MASK
) == 0)
4637 rt2870_io_mac_write(sc
, RT2870_REG_PBF_CFG
, 0xf40006);
4640 if (((tmp
>> RT2870_REG_TX1Q_PCNT_SHIFT
) & RT2870_REG_TX1Q_PCNT_MASK
) != 0)
4642 sc
->tx_queue_not_empty
[1]++;
4644 rt2870_io_mac_write(sc
, RT2870_REG_PBF_CFG
, 0xf4000a);
4646 for (ntries
= 0; ntries
< 10; ntries
++)
4648 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_PBF_TXRXQ_PCNT
);
4649 if (((tmp
>> RT2870_REG_TX1Q_PCNT_SHIFT
) & RT2870_REG_TX1Q_PCNT_MASK
) == 0)
4655 rt2870_io_mac_write(sc
, RT2870_REG_PBF_CFG
, 0xf40006);
4660 * rt2870_drain_fifo_stats
4662 static void rt2870_drain_fifo_stats(struct rt2870_softc
*sc
)
4666 uint8_t wcid
, mcs
, pid
;
4669 ifp
= sc
->ic
.ic_ifp
;
4671 /* drain Tx status FIFO (maxsize = 16) */
4673 while ((stats
= rt2870_io_mac_read(sc
, RT2870_REG_TX_STA_FIFO
)) &
4674 RT2870_REG_TX_STA_FIFO_VALID
)
4676 wcid
= (stats
>> RT2870_REG_TX_STA_FIFO_WCID_SHIFT
) &
4677 RT2870_REG_TX_STA_FIFO_WCID_MASK
;
4679 /* if no ACK was requested, no feedback is available */
4681 if (!(stats
& RT2870_REG_TX_STA_FIFO_ACK_REQ
) || wcid
== 0xff)
4684 /* update AMRR statistic */
4686 ok
= (stats
& RT2870_REG_TX_STA_FIFO_TX_OK
) ? 1 : 0;
4689 mcs
= (stats
>> RT2870_REG_TX_STA_FIFO_MCS_SHIFT
) &
4690 RT2870_REG_TX_STA_FIFO_MCS_MASK
;
4691 pid
= (stats
>> RT2870_REG_TX_STA_FIFO_PID_SHIFT
) &
4692 RT2870_REG_TX_STA_FIFO_PID_MASK
;
4694 if (!ok
|| (mcs
+ 1) != pid
)
4697 rt2870_amrr_tx_complete(&sc
->amrr_node
[wcid
],
4706 * rt2870_update_raw_counters
4708 static void rt2870_update_raw_counters(struct rt2870_softc
*sc
)
4712 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_RX_STA_CNT0
);
4714 sc
->rx_crc_errors
+= tmp
& 0xffff;
4715 sc
->rx_phy_errors
+= tmp
>> 16;
4717 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_RX_STA_CNT1
);
4719 sc
->rx_false_ccas
+= tmp
& 0xffff;
4720 sc
->rx_plcp_errors
+= tmp
>> 16;
4722 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_RX_STA_CNT2
);
4724 sc
->rx_dup_packets
+= tmp
& 0xffff;
4725 sc
->rx_fifo_overflows
+= tmp
>> 16;
4729 * rt2870_alloc_rx_ring
4731 static int rt2870_alloc_rx_ring(struct rt2870_softc
*sc
,
4732 struct rt2870_softc_rx_ring
*ring
)
4734 struct rt2870_softc_rx_data
*data
;
4737 STAILQ_INIT(&ring
->active
);
4738 STAILQ_INIT(&ring
->done
);
4740 for (i
= 0; i
< RT2870_SOFTC_RX_RING_DATA_COUNT
; i
++)
4742 data
= &ring
->data
[i
];
4744 data
->xfer
= usbd_alloc_xfer(sc
->usb_dev
);
4745 if (data
->xfer
== NULL
)
4747 printf("%s: could not allocate Rx xfer\n",
4748 device_get_nameunit(sc
->dev
));
4753 data
->buf
= usbd_alloc_buffer(data
->xfer
, RT2870_USB_RX_BULK_BUFLEN
);
4754 if (data
->buf
== NULL
)
4756 printf("%s: could not allocate Rx buffer\n",
4757 device_get_nameunit(sc
->dev
));
4767 rt2870_free_rx_ring(sc
, ring
);
4773 * rt2870_reset_rx_ring
4775 static void rt2870_reset_rx_ring(struct rt2870_softc
*sc
,
4776 struct rt2870_softc_rx_ring
*ring
)
4778 STAILQ_INIT(&ring
->active
);
4779 STAILQ_INIT(&ring
->done
);
4783 * rt2870_free_rx_ring
4785 static void rt2870_free_rx_ring(struct rt2870_softc
*sc
,
4786 struct rt2870_softc_rx_ring
*ring
)
4788 struct rt2870_softc_rx_data
*data
;
4791 for (i
= 0; i
< RT2870_SOFTC_RX_RING_DATA_COUNT
; i
++)
4793 data
= &ring
->data
[i
];
4795 if (data
->xfer
!= NULL
)
4797 usbd_free_xfer(data
->xfer
);
4804 * rt2870_alloc_tx_ring
4806 static int rt2870_alloc_tx_ring(struct rt2870_softc
*sc
,
4807 struct rt2870_softc_tx_ring
*ring
, int qid
)
4809 struct rt2870_softc_tx_data
*data
;
4812 STAILQ_INIT(&ring
->inactive
);
4813 STAILQ_INIT(&ring
->active
);
4814 STAILQ_INIT(&ring
->done
);
4820 for (i
= 0; i
< RT2870_SOFTC_TX_RING_DATA_COUNT
; i
++)
4822 data
= &ring
->data
[i
];
4824 data
->xfer
= usbd_alloc_xfer(sc
->usb_dev
);
4825 if (data
->xfer
== NULL
)
4827 printf("%s: could not allocate Tx xfer\n",
4828 device_get_nameunit(sc
->dev
));
4833 data
->buf
= usbd_alloc_buffer(data
->xfer
,
4834 RT2870_TX_DESC_SIZE
+ MJUMPAGESIZE
);
4835 if (data
->buf
== NULL
)
4837 printf("%s: could not allocate Tx buffer\n",
4838 device_get_nameunit(sc
->dev
));
4843 memset(data
->buf
, 0, RT2870_TX_DESC_SIZE
);
4845 STAILQ_INSERT_TAIL(&ring
->inactive
, data
, next
);
4852 rt2870_free_tx_ring(sc
, ring
);
4858 * rt2870_reset_tx_ring
4860 static void rt2870_reset_tx_ring(struct rt2870_softc
*sc
,
4861 struct rt2870_softc_tx_ring
*ring
)
4863 struct rt2870_softc_tx_data
*data
;
4866 STAILQ_INIT(&ring
->inactive
);
4867 STAILQ_INIT(&ring
->active
);
4868 STAILQ_INIT(&ring
->done
);
4872 for (i
= 0; i
< RT2870_SOFTC_TX_RING_DATA_COUNT
; i
++)
4874 data
= &ring
->data
[i
];
4876 if (data
->m
!= NULL
)
4882 if (data
->ni
!= NULL
)
4884 ieee80211_free_node(data
->ni
);
4888 STAILQ_INSERT_TAIL(&ring
->inactive
, data
, next
);
4893 * rt2870_free_tx_ring
4895 static void rt2870_free_tx_ring(struct rt2870_softc
*sc
,
4896 struct rt2870_softc_tx_ring
*ring
)
4898 struct rt2870_softc_tx_data
*data
;
4901 for (i
= 0; i
< RT2870_SOFTC_TX_RING_DATA_COUNT
; i
++)
4903 data
= &ring
->data
[i
];
4905 if (data
->xfer
!= NULL
)
4907 usbd_free_xfer(data
->xfer
);
4911 if (data
->m
!= NULL
)
4917 if (data
->ni
!= NULL
)
4919 ieee80211_free_node(data
->ni
);
4926 * rt2870_reset_cmd_ring
4928 static void rt2870_reset_cmd_ring(struct rt2870_softc
*sc
,
4929 struct rt2870_softc_cmd_ring
*ring
)
4931 struct rt2870_softc_cmd
*cmd
;
4934 STAILQ_INIT(&ring
->inactive
);
4935 STAILQ_INIT(&ring
->active
);
4939 for (i
= 0; i
< RT2870_SOFTC_CMD_RING_CMD_COUNT
; i
++)
4941 cmd
= &ring
->cmd
[i
];
4943 STAILQ_INSERT_TAIL(&ring
->inactive
, cmd
, next
);
4948 * rt2870_sysctl_attach
4950 static void rt2870_sysctl_attach(struct rt2870_softc
*sc
)
4952 struct sysctl_ctx_list
*ctx
;
4953 struct sysctl_oid
*tree
;
4954 struct sysctl_oid
*stats
;
4956 ctx
= device_get_sysctl_ctx(sc
->dev
);
4957 tree
= device_get_sysctl_tree(sc
->dev
);
4959 stats
= SYSCTL_ADD_NODE(ctx
, SYSCTL_CHILDREN(tree
), OID_AUTO
,
4960 "stats", CTLFLAG_RD
, 0, "statistic");
4962 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
4963 "interrupts", CTLFLAG_RD
, &sc
->interrupts
, 0,
4966 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
4967 "rx_interrupts", CTLFLAG_RD
, &sc
->rx_interrupts
, 0,
4970 if (sc
->usb_endpoints
== (RT2870_SOFTC_TX_RING_COUNT
+ 1))
4972 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
4973 "tx_mgmt_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[5], 0,
4974 "Tx MGMT interrupts");
4976 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
4977 "tx_hcca_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[4], 0,
4978 "Tx HCCA interrupts");
4981 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
4982 "tx_ac3_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[3], 0,
4983 "Tx AC3 interrupts");
4985 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
4986 "tx_ac2_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[2], 0,
4987 "Tx AC2 interrupts");
4989 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
4990 "tx_ac1_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[1], 0,
4991 "Tx AC1 interrupts");
4993 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
4994 "tx_ac0_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[0], 0,
4995 "Tx AC0 interrupts");
4997 if (sc
->usb_endpoints
== (RT2870_SOFTC_TX_RING_COUNT
+ 1))
4999 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5000 "tx_mgmt_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[5].queued
, 0,
5001 "Tx MGMT data queued");
5003 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5004 "tx_hcca_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[4].queued
, 0,
5005 "Tx HCCA data queued");
5008 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5009 "tx_ac3_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[3].queued
, 0,
5010 "Tx AC3 data queued");
5012 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5013 "tx_ac2_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[2].queued
, 0,
5014 "Tx AC2 data queued");
5016 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5017 "tx_ac1_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[1].queued
, 0,
5018 "Tx AC1 data queued");
5020 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5021 "tx_ac0_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[0].queued
, 0,
5022 "Tx AC0 data queued");
5024 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5025 "tx_watchdog_timeouts", CTLFLAG_RD
, &sc
->tx_watchdog_timeouts
, 0,
5026 "Tx watchdog timeouts");
5028 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5029 "rx_mbuf_alloc_errors", CTLFLAG_RD
, &sc
->rx_mbuf_alloc_errors
, 0,
5030 "Rx mbuf allocation errors");
5032 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5033 "tx_queue_0_not_empty", CTLFLAG_RD
, &sc
->tx_queue_not_empty
[0], 0,
5034 "Tx queue 0 not empty");
5036 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5037 "tx_queue_1_not_empty", CTLFLAG_RD
, &sc
->tx_queue_not_empty
[1], 0,
5038 "Tx queue 1 not empty");
5040 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5041 "rx_packets", CTLFLAG_RD
, &sc
->rx_packets
, 0,
5044 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5045 "rx_crc_errors", CTLFLAG_RD
, &sc
->rx_crc_errors
, 0,
5048 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5049 "rx_phy_errors", CTLFLAG_RD
, &sc
->rx_phy_errors
, 0,
5052 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5053 "rx_false_ccas", CTLFLAG_RD
, &sc
->rx_false_ccas
, 0,
5056 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5057 "rx_plcp_errors", CTLFLAG_RD
, &sc
->rx_plcp_errors
, 0,
5060 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5061 "rx_dup_packets", CTLFLAG_RD
, &sc
->rx_dup_packets
, 0,
5062 "Rx duplicate packets");
5064 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5065 "rx_fifo_overflows", CTLFLAG_RD
, &sc
->rx_fifo_overflows
, 0,
5066 "Rx FIFO overflows");
5069 static device_method_t rt2870_dev_methods
[] =
5071 DEVMETHOD(device_probe
, rt2870_probe
),
5072 DEVMETHOD(device_attach
, rt2870_attach
),
5073 DEVMETHOD(device_detach
, rt2870_detach
),
5077 static driver_t rt2870_driver
=
5081 sizeof(struct rt2870_softc
),
5084 static devclass_t rt2870_dev_class
;
5086 DRIVER_MODULE(rt2870
, uhub
, rt2870_driver
, rt2870_dev_class
,
5087 usbd_driver_load
, 0);
5089 MODULE_DEPEND(rt2870
, usb
, 1, 1, 1);
5090 MODULE_DEPEND(rt2870
, wlan
, 1, 1, 1);