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
|
598 IEEE80211_HTCAP_SHORTGI20
| /* short GI for HT 20MHz */
599 IEEE80211_HTCAP_SHORTGI40
| /* short GI for HT 40MHz */
600 IEEE80211_HTCAP_RXSTBC_2STREAM
;
605 ic
->ic_regdomain
= 0;
606 ic
->ic_countrycode
= CTRY_DEFAULT
;
609 rt2870_init_channels(sc
);
611 rt2870_init_channels_ht40(sc
);
613 IEEE80211_ADDR_COPY(ic
->ic_myaddr
, sc
->mac_addr
);
615 ieee80211_ifattach(ic
);
617 sc
->newstate
= ic
->ic_newstate
;
618 ic
->ic_newstate
= rt2870_newstate
;
620 ic
->ic_reset
= rt2870_reset
;
621 ic
->ic_scan_start
= rt2870_scan_start
;
622 ic
->ic_scan_end
= rt2870_scan_end
;
623 ic
->ic_set_channel
= rt2870_set_channel
;
624 ic
->ic_newassoc
= rt2870_newassoc
;
625 ic
->ic_updateslot
= rt2870_updateslot
;
626 ic
->ic_wme
.wme_update
= rt2870_wme_update
;
627 ic
->ic_update_beacon
= rt2870_update_beacon
;
628 ic
->ic_crypto
.cs_key_update_begin
= rt2870_key_update_begin
;
629 ic
->ic_crypto
.cs_key_update_end
= rt2870_key_update_end
;
630 ic
->ic_crypto
.cs_key_set
= rt2870_key_set
;
631 ic
->ic_crypto
.cs_key_delete
= rt2870_key_delete
;
632 ic
->ic_raw_xmit
= rt2870_raw_xmit
;
634 sc
->recv_action
= ic
->ic_recv_action
;
635 ic
->ic_recv_action
= rt2870_recv_action
;
637 sc
->send_action
= ic
->ic_send_action
;
638 ic
->ic_send_action
= rt2870_send_action
;
640 /* hardware requires padding between 802.11 frame header and body */
642 ic
->ic_flags
|= IEEE80211_F_WME
| IEEE80211_F_DATAPAD
| IEEE80211_F_DOTH
;
644 ic
->ic_flags_ext
|= IEEE80211_FEXT_SWBMISS
;
646 ieee80211_media_init(ic
, rt2870_media_change
, ieee80211_media_status
);
648 rt2870_amrr_init(&sc
->amrr
, ic
,
649 RT2870_AMRR_MIN_SUCCESS_THRESHOLD
,
650 RT2870_AMRR_MAX_SUCCESS_THRESHOLD
,
653 bpfattach2(ifp
, DLT_IEEE802_11_RADIO
,
654 sizeof(struct ieee80211_frame
) + IEEE80211_RADIOTAP_HDRLEN
,
657 sc
->rxtap_len
= sizeof(sc
->rxtapu
);
658 sc
->rxtap
.ihdr
.it_len
= htole16(sc
->rxtap_len
);
659 sc
->rxtap
.ihdr
.it_present
= htole32(RT2870_SOFTC_RX_RADIOTAP_PRESENT
);
661 sc
->txtap_len
= sizeof(sc
->txtapu
);
662 sc
->txtap
.ihdr
.it_len
= htole16(sc
->txtap_len
);
663 sc
->txtap
.ihdr
.it_present
= htole32(RT2870_SOFTC_TX_RADIOTAP_PRESENT
);
665 /* init task queue */
667 TASK_INIT(&sc
->rx_done_task
, 0, rt2870_rx_done_task
, sc
);
668 TASK_INIT(&sc
->tx_done_task
, 0, rt2870_tx_done_task
, sc
);
669 TASK_INIT(&sc
->periodic_task
, 0, rt2870_periodic_task
, sc
);
670 TASK_INIT(&sc
->cmd_task
, 0, rt2870_cmd_task
, sc
);
672 sc
->rx_process_limit
= 100;
674 sc
->taskqueue
= taskqueue_create("rt2870_taskq", M_NOWAIT
,
675 taskqueue_thread_enqueue
, &sc
->taskqueue
);
677 taskqueue_start_threads(&sc
->taskqueue
, 1, PI_NET
, "%s taskq",
678 device_get_nameunit(sc
->dev
));
680 rt2870_sysctl_attach(sc
);
683 ieee80211_announce(ic
);
685 usbd_add_drv_event(USB_EVENT_DRIVER_ATTACH
, sc
->usb_dev
, sc
->dev
);
691 /* close Tx and Rx USB bulk pipes */
693 if (sc
->rx_ring
.usb_pipe
!= NULL
)
695 usbd_abort_pipe(sc
->rx_ring
.usb_pipe
);
696 usbd_close_pipe(sc
->rx_ring
.usb_pipe
);
697 sc
->rx_ring
.usb_pipe
= NULL
;
700 for (i
= 0; i
< sc
->usb_endpoints
- 1; i
++)
702 if (sc
->tx_ring
[i
].usb_pipe
!= NULL
)
704 usbd_abort_pipe(sc
->tx_ring
[i
].usb_pipe
);
705 usbd_close_pipe(sc
->tx_ring
[i
].usb_pipe
);
706 sc
->tx_ring
[i
].usb_pipe
= NULL
;
710 /* free Tx and Rx rings */
712 for (i
= 0; i
< sc
->usb_endpoints
- 1; i
++)
713 rt2870_free_tx_ring(sc
, &sc
->tx_ring
[i
]);
715 rt2870_free_rx_ring(sc
, &sc
->rx_ring
);
723 static int rt2870_detach(device_t dev
)
725 struct rt2870_softc
*sc
;
726 struct ieee80211com
*ic
;
730 if (!device_is_attached(dev
))
733 sc
= device_get_softc(dev
);
737 RT2870_DPRINTF(sc
, RT2870_DEBUG_ANY
,
739 device_get_nameunit(sc
->dev
));
743 ifp
->if_drv_flags
&= ~(IFF_DRV_RUNNING
| IFF_DRV_OACTIVE
);
745 ieee80211_new_state(ic
, IEEE80211_S_INIT
, -1);
747 callout_stop(&sc
->periodic_ch
);
748 callout_stop(&sc
->tx_watchdog_ch
);
750 taskqueue_drain(sc
->taskqueue
, &sc
->rx_done_task
);
751 taskqueue_drain(sc
->taskqueue
, &sc
->tx_done_task
);
752 taskqueue_drain(sc
->taskqueue
, &sc
->periodic_task
);
753 taskqueue_drain(sc
->taskqueue
, &sc
->cmd_task
);
755 /* close Tx and Rx USB bulk pipes */
757 if (sc
->rx_ring
.usb_pipe
!= NULL
)
759 usbd_abort_pipe(sc
->rx_ring
.usb_pipe
);
760 usbd_close_pipe(sc
->rx_ring
.usb_pipe
);
761 sc
->rx_ring
.usb_pipe
= NULL
;
764 for (i
= 0; i
< sc
->usb_endpoints
- 1; i
++)
766 if (sc
->tx_ring
[i
].usb_pipe
!= NULL
)
768 usbd_abort_pipe(sc
->tx_ring
[i
].usb_pipe
);
769 usbd_close_pipe(sc
->tx_ring
[i
].usb_pipe
);
770 sc
->tx_ring
[i
].usb_pipe
= NULL
;
774 /* free Tx and Rx rings */
776 for (i
= 0; i
< sc
->usb_endpoints
- 1; i
++)
777 rt2870_free_tx_ring(sc
, &sc
->tx_ring
[i
]);
779 rt2870_free_rx_ring(sc
, &sc
->rx_ring
);
783 ieee80211_ifdetach(ic
);
787 taskqueue_free(sc
->taskqueue
);
789 usbd_add_drv_event(USB_EVENT_DRIVER_DETACH
, sc
->usb_dev
, sc
->dev
);
795 * rt2870_find_usb_endpoints
797 static int rt2870_find_usb_endpoints(struct rt2870_softc
*sc
)
799 usb_interface_descriptor_t
*id
;
800 usb_endpoint_descriptor_t
*ed
;
803 id
= usbd_get_interface_descriptor(sc
->usb_iface
);
805 sc
->usb_endpoints
= id
->bNumEndpoints
;
806 if ((sc
->usb_endpoints
!= (RT2870_SOFTC_TX_RING_COUNT
+ 1)) &&
807 (sc
->usb_endpoints
!= (RT2870_SOFTC_TX_RING_COUNT
- 2 + 1)))
809 printf("%s: wrong number of USB endpoints=%d\n",
810 device_get_nameunit(sc
->dev
), sc
->usb_endpoints
);
814 sc
->rx_ring
.usb_ep
= -1;
816 for (i
= 0; i
< RT2870_SOFTC_TX_RING_COUNT
; i
++)
817 sc
->tx_ring
[i
].usb_ep
= -1;
819 for (i
= 0, j
= 0; i
< id
->bNumEndpoints
; i
++)
821 ed
= usbd_interface2endpoint_descriptor(sc
->usb_iface
, i
);
824 printf("%s: no endpoint descriptor #%d for USB interface\n",
825 device_get_nameunit(sc
->dev
), i
);
829 if (UE_GET_DIR(ed
->bEndpointAddress
) == UE_DIR_IN
&&
830 UE_GET_XFERTYPE(ed
->bmAttributes
) == UE_BULK
)
832 sc
->rx_ring
.usb_ep
= ed
->bEndpointAddress
;
834 else if (UE_GET_DIR(ed
->bEndpointAddress
) == UE_DIR_OUT
&&
835 UE_GET_XFERTYPE(ed
->bmAttributes
) == UE_BULK
)
837 if (j
< RT2870_SOFTC_TX_RING_COUNT
)
838 sc
->tx_ring
[j
++].usb_ep
= ed
->bEndpointAddress
;
840 sc
->tx_ring
[RT2870_SOFTC_TX_RING_COUNT
- 1].usb_ep
=
841 ed
->bEndpointAddress
;
845 if ((sc
->rx_ring
.usb_ep
== -1) ||
846 ((j
!= RT2870_SOFTC_TX_RING_COUNT
) && (j
!= RT2870_SOFTC_TX_RING_COUNT
- 2)))
848 printf("%s: missing USB endpoints\n",
849 device_get_nameunit(sc
->dev
));
857 * rt2870_init_channels
859 static void rt2870_init_channels(struct rt2870_softc
*sc
)
861 struct ieee80211com
*ic
;
862 struct ieee80211_channel
*c
;
867 /* set supported channels for 2GHz band */
869 for (i
= 1; i
<= 14; i
++)
871 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
872 flags
= IEEE80211_CHAN_B
;
874 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
878 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
879 flags
= IEEE80211_CHAN_B
| IEEE80211_CHAN_HT20
;
881 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
885 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
886 flags
= IEEE80211_CHAN_G
;
888 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
892 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
893 flags
= IEEE80211_CHAN_G
| IEEE80211_CHAN_HT20
;
895 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
900 /* set supported channels for 5GHz band */
902 if (sc
->rf_rev
== RT2870_EEPROM_RF_2850
||
903 sc
->rf_rev
== RT2870_EEPROM_RF_2750
)
905 for (i
= 36; i
<= 64; i
+= 4)
907 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
908 flags
= IEEE80211_CHAN_A
;
910 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
914 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
915 flags
= IEEE80211_CHAN_A
| IEEE80211_CHAN_HT20
;
917 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
922 for (i
= 100; i
<= 140; 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
= 149; i
<= 165; 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
);
959 * rt2870_init_channels_ht40
961 static void rt2870_init_channels_ht40(struct rt2870_softc
*sc
)
963 struct ieee80211com
*ic
;
964 struct ieee80211_channel
*c
, *cent
, *ext
;
969 /* set supported channels for 2GHz band */
971 for (i
= 1; i
<= 14; i
++)
973 flags
= IEEE80211_CHAN_G
| IEEE80211_CHAN_HT40
;
975 /* find the center channel */
977 cent
= ieee80211_find_channel_byieee(ic
, i
,
978 flags
& ~IEEE80211_CHAN_HT
);
981 printf("%s: skip channel %d, could not find center channel\n",
982 device_get_nameunit(sc
->dev
), i
);
986 /* find the extension channel */
988 ext
= ieee80211_find_channel(ic
, cent
->ic_freq
+ 20,
989 flags
& ~IEEE80211_CHAN_HT
);
992 printf("%s: skip channel %d, could not find extension channel\n",
993 device_get_nameunit(sc
->dev
), i
);
997 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1000 c
->ic_extieee
= ext
->ic_ieee
;
1001 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1002 c
->ic_flags
|= IEEE80211_CHAN_HT40U
;
1004 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1007 c
->ic_extieee
= cent
->ic_ieee
;
1008 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1009 c
->ic_flags
|= IEEE80211_CHAN_HT40D
;
1012 /* set supported channels for 5GHz band */
1014 if (sc
->rf_rev
== RT2870_EEPROM_RF_2850
||
1015 sc
->rf_rev
== RT2870_EEPROM_RF_2750
)
1017 for (i
= 36; i
<= 64; i
+= 4)
1019 flags
= IEEE80211_CHAN_A
| IEEE80211_CHAN_HT40
;
1021 /* find the center channel */
1023 cent
= ieee80211_find_channel_byieee(ic
, i
,
1024 flags
& ~IEEE80211_CHAN_HT
);
1027 printf("%s: skip channel %d, could not find center channel\n",
1028 device_get_nameunit(sc
->dev
), i
);
1032 /* find the extension channel */
1034 ext
= ieee80211_find_channel(ic
, cent
->ic_freq
+ 20,
1035 flags
& ~IEEE80211_CHAN_HT
);
1038 printf("%s: skip channel %d, could not find extension channel\n",
1039 device_get_nameunit(sc
->dev
), i
);
1043 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1046 c
->ic_extieee
= ext
->ic_ieee
;
1047 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1048 c
->ic_flags
|= IEEE80211_CHAN_HT40U
;
1050 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1053 c
->ic_extieee
= cent
->ic_ieee
;
1054 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1055 c
->ic_flags
|= IEEE80211_CHAN_HT40D
;
1058 for (i
= 100; i
<= 140; i
+= 4)
1060 flags
= IEEE80211_CHAN_A
| IEEE80211_CHAN_HT40
;
1062 /* find the center channel */
1064 cent
= ieee80211_find_channel_byieee(ic
, i
,
1065 flags
& ~IEEE80211_CHAN_HT
);
1068 printf("%s: skip channel %d, could not find center channel\n",
1069 device_get_nameunit(sc
->dev
), i
);
1073 /* find the extension channel */
1075 ext
= ieee80211_find_channel(ic
, cent
->ic_freq
+ 20,
1076 flags
& ~IEEE80211_CHAN_HT
);
1079 printf("%s: skip channel %d, could not find extension channel\n",
1080 device_get_nameunit(sc
->dev
), i
);
1084 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1087 c
->ic_extieee
= ext
->ic_ieee
;
1088 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1089 c
->ic_flags
|= IEEE80211_CHAN_HT40U
;
1091 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1094 c
->ic_extieee
= cent
->ic_ieee
;
1095 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1096 c
->ic_flags
|= IEEE80211_CHAN_HT40D
;
1099 for (i
= 149; i
<= 165; i
+= 4)
1101 flags
= IEEE80211_CHAN_A
| IEEE80211_CHAN_HT40
;
1103 /* find the center channel */
1105 cent
= ieee80211_find_channel_byieee(ic
, i
,
1106 flags
& ~IEEE80211_CHAN_HT
);
1109 printf("%s: skip channel %d, could not find center channel\n",
1110 device_get_nameunit(sc
->dev
), i
);
1114 /* find the extension channel */
1116 ext
= ieee80211_find_channel(ic
, cent
->ic_freq
+ 20,
1117 flags
& ~IEEE80211_CHAN_HT
);
1120 printf("%s: skip channel %d, could not find extension channel\n",
1121 device_get_nameunit(sc
->dev
), i
);
1125 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1128 c
->ic_extieee
= ext
->ic_ieee
;
1129 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1130 c
->ic_flags
|= IEEE80211_CHAN_HT40U
;
1132 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1135 c
->ic_extieee
= cent
->ic_ieee
;
1136 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1137 c
->ic_flags
|= IEEE80211_CHAN_HT40D
;
1143 * rt2870_init_locked
1145 static void rt2870_init_locked(void *priv
)
1147 struct rt2870_softc
*sc
;
1148 struct ieee80211com
*ic
;
1150 struct rt2870_softc_rx_data
*data
;
1151 int ntries
, error
, i
;
1152 uint32_t tmp
, stacnt
[6];
1158 RT2870_DPRINTF(sc
, RT2870_DEBUG_ANY
,
1159 "%s: initializing\n",
1160 device_get_nameunit(sc
->dev
));
1162 if (!(sc
->flags
& RT2870_SOFTC_FLAGS_UCODE_LOADED
))
1164 RT2870_DPRINTF(sc
, RT2870_DEBUG_ANY
,
1165 "%s: loading 8051 microcode\n",
1166 device_get_nameunit(sc
->dev
));
1168 error
= rt2870_io_mcu_load_ucode(sc
, rt2870_ucode
, sizeof(rt2870_ucode
));
1171 printf("%s: could not load 8051 microcode\n",
1172 device_get_nameunit(sc
->dev
));
1176 RT2870_DPRINTF(sc
, RT2870_DEBUG_ANY
,
1177 "%s: 8051 microcode was successfully loaded\n",
1178 device_get_nameunit(sc
->dev
));
1180 sc
->flags
|= RT2870_SOFTC_FLAGS_UCODE_LOADED
;
1183 /* wait while DMA engine is busy */
1185 for (ntries
= 0; ntries
< 100; ntries
++)
1187 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_SCHDMA_WPDMA_GLO_CFG
);
1188 if (!(tmp
& (RT2870_REG_TX_DMA_BUSY
| RT2870_REG_RX_DMA_BUSY
)))
1196 printf("%s: timeout waiting for DMA engine\n",
1197 device_get_nameunit(sc
->dev
));
1202 tmp
|= RT2870_REG_TX_WB_DDONE
;
1204 rt2870_io_mac_write(sc
, RT2870_REG_SCHDMA_WPDMA_GLO_CFG
, tmp
);
1206 /* PBF hardware reset */
1208 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_PBF_SYS_CTRL
);
1212 rt2870_io_mac_write(sc
, RT2870_REG_PBF_SYS_CTRL
, tmp
);
1214 rt2870_io_mac_write(sc
, RT2870_REG_SYS_CTRL
,
1215 RT2870_REG_MAC_SRST
| RT2870_REG_BBP_HRST
);
1217 rt2870_io_mac_write(sc
, RT2870_REG_SCHDMA_USB_DMA_CFG
, 0);
1219 rt2870_io_mcu_reset(sc
);
1221 rt2870_io_mac_write(sc
, RT2870_REG_SYS_CTRL
, 0);
1223 /* init Tx power per rate */
1225 for (i
= 0; i
< RT2870_SOFTC_TXPOW_RATE_COUNT
; i
++)
1227 if (sc
->txpow_rate_20mhz
[i
] == 0xffffffff)
1230 rt2870_io_mac_write(sc
, RT2870_REG_TX_PWR_CFG(i
),
1231 sc
->txpow_rate_20mhz
[i
]);
1234 for (i
= 0; i
< RT2870_DEF_MAC_SIZE
; i
++)
1235 rt2870_io_mac_write(sc
, rt2870_def_mac
[i
].reg
,
1236 rt2870_def_mac
[i
].val
);
1238 /* wait while MAC is busy */
1240 for (ntries
= 0; ntries
< 100; ntries
++)
1242 if (!(rt2870_io_mac_read(sc
, RT2870_REG_STATUS_CFG
) &
1243 (RT2870_REG_STATUS_TX_BUSY
| RT2870_REG_STATUS_RX_BUSY
)))
1251 printf("%s: timeout waiting for MAC\n",
1252 device_get_nameunit(sc
->dev
));
1256 /* clear Host to MCU mailbox */
1258 rt2870_io_mac_write(sc
, RT2870_REG_H2M_MAILBOX_BBP_AGENT
, 0);
1259 rt2870_io_mac_write(sc
, RT2870_REG_H2M_MAILBOX
, 0);
1263 error
= rt2870_init_bbp(sc
);
1267 /* set up maximum buffer sizes */
1269 tmp
= (1 << 12) | RT2870_MAX_AGG_SIZE
;
1271 if (sc
->mac_rev
>= 0x28720200 && sc
->mac_rev
< 0x30700200)
1277 rt2870_io_mac_write(sc
, RT2870_REG_MAX_LEN_CFG
, tmp
);
1279 /* set mac address */
1281 IEEE80211_ADDR_COPY(ic
->ic_myaddr
, IF_LLADDR(ifp
));
1283 rt2870_asic_set_macaddr(sc
, ic
->ic_myaddr
);
1285 /* clear statistic registers */
1287 rt2870_io_mac_read_multi(sc
, RT2870_REG_RX_STA_CNT0
,
1288 stacnt
, sizeof(stacnt
));
1290 /* send LEDs operating mode to microcontroller */
1292 rt2870_io_mcu_cmd(sc
, RT2870_IO_MCU_CMD_LED1
,
1293 RT2870_REG_H2M_TOKEN_NO_INTR
, sc
->led_off
[0]);
1294 rt2870_io_mcu_cmd(sc
, RT2870_IO_MCU_CMD_LED2
,
1295 RT2870_REG_H2M_TOKEN_NO_INTR
, sc
->led_off
[1]);
1296 rt2870_io_mcu_cmd(sc
, RT2870_IO_MCU_CMD_LED3
,
1297 RT2870_REG_H2M_TOKEN_NO_INTR
, sc
->led_off
[2]);
1299 /* write vendor-specific BBP values (from EEPROM) */
1301 for (i
= 0; i
< RT2870_SOFTC_BBP_EEPROM_COUNT
; i
++)
1303 if (sc
->bbp_eeprom
[i
].reg
== 0x00 ||
1304 sc
->bbp_eeprom
[i
].reg
== 0xff)
1307 rt2870_io_bbp_write(sc
, sc
->bbp_eeprom
[i
].reg
,
1308 sc
->bbp_eeprom
[i
].val
);
1311 /* disable non-existing Rx chains */
1313 tmp
= rt2870_io_bbp_read(sc
, 3);
1315 tmp
&= ~((1 << 4) | (1 << 3));
1317 if (sc
->nrxpath
== 3)
1319 else if (sc
->nrxpath
== 2)
1322 rt2870_io_bbp_write(sc
, 3, tmp
);
1324 /* disable non-existing Tx chains */
1326 tmp
= rt2870_io_bbp_read(sc
, 1);
1328 if (sc
->ntxpath
== 1)
1329 tmp
&= ~((1 << 4) | (1 << 3));
1331 rt2870_io_bbp_write(sc
, 1, tmp
);
1333 tmp
= rt2870_io_bbp_read(sc
, 4);
1337 rt2870_io_bbp_write(sc
, 4, tmp
);
1339 /* set current channel */
1341 rt2870_rf_set_chan(sc
, ic
->ic_curchan
);
1343 /* turn radio LED on */
1345 rt2870_led_cmd(sc
, RT2870_LED_CMD_RADIO_ON
);
1347 rt2870_io_mcu_cmd(sc
, RT2870_IO_MCU_CMD_BOOT
,
1348 RT2870_REG_H2M_TOKEN_NO_INTR
, 0);
1350 /* set RTS threshold */
1352 rt2870_asic_update_rtsthreshold(sc
);
1356 rt2870_asic_update_txpower(sc
);
1358 /* set up protection mode */
1360 rt2870_asic_updateprot(sc
);
1362 /* clear key tables */
1364 rt2870_asic_clear_keytables(sc
);
1366 /* enable Tx/Rx DMA engine */
1368 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_SCHDMA_USB_CYC_CFG
);
1373 rt2870_io_mac_write(sc
, RT2870_REG_SCHDMA_USB_CYC_CFG
, tmp
);
1375 if ((sc
->mac_rev
& 0xffff) != 0x0101)
1376 rt2870_io_mac_write(sc
, RT2870_REG_TX_TXOP_CTRL_CFG
, 0x583f);
1378 rt2870_io_mac_write(sc
, RT2870_REG_SYS_CTRL
, RT2870_REG_TX_ENABLE
);
1380 for (ntries
= 0; ntries
< 200; ntries
++)
1382 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_SCHDMA_WPDMA_GLO_CFG
);
1383 if (!(tmp
& (RT2870_REG_TX_DMA_BUSY
| RT2870_REG_RX_DMA_BUSY
)))
1391 printf("%s: timeout waiting for DMA engine\n",
1392 device_get_nameunit(sc
->dev
));
1398 rt2870_io_mac_write(sc
, RT2870_REG_SCHDMA_WMM_TXOP0_CFG
, 0);
1399 rt2870_io_mac_write(sc
, RT2870_REG_SCHDMA_WMM_TXOP1_CFG
,
1402 tmp
|= RT2870_REG_TX_WB_DDONE
|
1403 RT2870_REG_RX_DMA_ENABLE
|
1404 RT2870_REG_TX_DMA_ENABLE
;
1406 rt2870_io_mac_write(sc
, RT2870_REG_SCHDMA_WPDMA_GLO_CFG
, tmp
);
1408 tmp
= RT2870_REG_USB_DMA_TX_ENABLE
|
1409 RT2870_REG_USB_DMA_RX_ENABLE
|
1410 RT2870_REG_USB_DMA_RX_AGG_ENABLE
|
1411 /* Rx agg limit in unit of 1024 byte */
1412 ((RT2870_USB_RX_BULK_BUFLEN
/ 1024 - 3) << RT2870_REG_USB_DMA_RX_AGG_LIMIT_SHIFT
) |
1413 /* Rx agg timeout in unit of 33ns */
1416 rt2870_io_mac_write(sc
, RT2870_REG_SCHDMA_USB_DMA_CFG
, tmp
);
1420 tmp
= RT2870_REG_RX_FILTER_DROP_CRC_ERR
|
1421 RT2870_REG_RX_FILTER_DROP_PHY_ERR
;
1423 if (ic
->ic_opmode
!= IEEE80211_M_MONITOR
)
1425 tmp
|= RT2870_REG_RX_FILTER_DROP_DUPL
|
1426 RT2870_REG_RX_FILTER_DROP_CTS
|
1427 RT2870_REG_RX_FILTER_DROP_BA
|
1428 RT2870_REG_RX_FILTER_DROP_ACK
|
1429 RT2870_REG_RX_FILTER_DROP_VER_ERR
|
1430 RT2870_REG_RX_FILTER_DROP_CTRL_RSV
|
1431 RT2870_REG_RX_FILTER_DROP_CFACK
|
1432 RT2870_REG_RX_FILTER_DROP_CFEND
;
1434 if (ic
->ic_opmode
== IEEE80211_M_STA
)
1435 tmp
|= RT2870_REG_RX_FILTER_DROP_RTS
|
1436 RT2870_REG_RX_FILTER_DROP_PSPOLL
;
1438 if (!(ifp
->if_flags
& IFF_PROMISC
))
1439 tmp
|= RT2870_REG_RX_FILTER_DROP_UC_NOME
;
1442 rt2870_io_mac_write(sc
, RT2870_REG_RX_FILTER_CFG
, tmp
);
1444 rt2870_io_mac_write(sc
, RT2870_REG_SYS_CTRL
,
1445 RT2870_REG_RX_ENABLE
| RT2870_REG_TX_ENABLE
);
1447 /* clear garbage interrupts */
1449 tmp
= rt2870_io_mac_read(sc
, 0x1300);
1451 taskqueue_unblock(sc
->taskqueue
);
1453 /* init Tx and Rx rings */
1455 for(i
= 0; i
< sc
->usb_endpoints
- 1; i
++)
1456 rt2870_reset_tx_ring(sc
, &sc
->tx_ring
[i
]);
1458 rt2870_reset_rx_ring(sc
, &sc
->rx_ring
);
1460 rt2870_reset_cmd_ring(sc
, &sc
->cmd_ring
);
1462 /* start up the receive pipe */
1464 for (i
= 0; i
< RT2870_SOFTC_RX_RING_DATA_COUNT
; i
++)
1466 data
= &sc
->rx_ring
.data
[i
];
1468 STAILQ_INSERT_TAIL(&sc
->rx_ring
.active
, data
, next
);
1470 usbd_setup_xfer(data
->xfer
, sc
->rx_ring
.usb_pipe
, sc
, data
->buf
,
1471 RT2870_USB_RX_BULK_BUFLEN
, USBD_SHORT_XFER_OK
| USBD_NO_COPY
,
1472 USBD_NO_TIMEOUT
, rt2870_rx_intr
);
1474 usbd_transfer(data
->xfer
);
1477 ifp
->if_drv_flags
&= ~IFF_DRV_OACTIVE
;
1478 ifp
->if_drv_flags
|= IFF_DRV_RUNNING
;
1480 if (ic
->ic_opmode
!= IEEE80211_M_MONITOR
)
1482 if (ic
->ic_roaming
!= IEEE80211_ROAMING_MANUAL
)
1483 ieee80211_new_state(ic
, IEEE80211_S_SCAN
, -1);
1487 ieee80211_new_state(ic
, IEEE80211_S_RUN
, -1);
1490 sc
->periodic_round
= 0;
1492 callout_reset(&sc
->periodic_ch
, hz
/ 10, rt2870_periodic
, sc
);
1498 rt2870_stop_locked(sc
);
1504 static void rt2870_init(void *priv
)
1506 struct rt2870_softc
*sc
;
1510 rt2870_init_locked(sc
);
1516 static int rt2870_init_bbp(struct rt2870_softc
*sc
)
1521 for (ntries
= 0; ntries
< 20; ntries
++)
1523 tmp
= rt2870_io_bbp_read(sc
, 0);
1524 if (tmp
!= 0x00 && tmp
!= 0xff)
1528 if (tmp
== 0x00 || tmp
== 0xff)
1530 printf("%s: timeout waiting for BBP to wakeup\n",
1531 device_get_nameunit(sc
->dev
));
1535 for (i
= 0; i
< RT2870_DEF_BBP_SIZE
; i
++)
1536 rt2870_io_bbp_write(sc
, rt2870_def_bbp
[i
].reg
,
1537 rt2870_def_bbp
[i
].val
);
1539 if ((sc
->mac_rev
& 0xffff) != 0x0101)
1540 rt2870_io_bbp_write(sc
, 84, 0x19);
1548 static void rt2870_stop_locked(void *priv
)
1550 struct rt2870_softc
*sc
;
1551 struct ieee80211com
*ic
;
1560 RT2870_DPRINTF(sc
, RT2870_DEBUG_ANY
,
1562 device_get_nameunit(sc
->dev
));
1566 if (ifp
->if_drv_flags
& IFF_DRV_RUNNING
)
1567 rt2870_led_cmd(sc
, RT2870_LED_CMD_RADIO_OFF
);
1569 ifp
->if_drv_flags
&= ~(IFF_DRV_RUNNING
| IFF_DRV_OACTIVE
);
1571 ieee80211_new_state(ic
, IEEE80211_S_INIT
, -1);
1573 callout_stop(&sc
->periodic_ch
);
1574 callout_stop(&sc
->tx_watchdog_ch
);
1576 taskqueue_block(sc
->taskqueue
);
1578 taskqueue_drain(sc
->taskqueue
, &sc
->rx_done_task
);
1579 taskqueue_drain(sc
->taskqueue
, &sc
->tx_done_task
);
1580 taskqueue_drain(sc
->taskqueue
, &sc
->periodic_task
);
1581 taskqueue_drain(sc
->taskqueue
, &sc
->cmd_task
);
1583 /* clear key tables */
1585 rt2870_asic_clear_keytables(sc
);
1589 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_SYS_CTRL
);
1591 tmp
&= ~(RT2870_REG_RX_ENABLE
| RT2870_REG_TX_ENABLE
);
1593 rt2870_io_mac_write(sc
, RT2870_REG_SYS_CTRL
, tmp
);
1595 rt2870_io_mac_write(sc
, RT2870_REG_SCHDMA_USB_DMA_CFG
, 0);
1599 rt2870_io_mac_write(sc
, RT2870_REG_SYS_CTRL
,
1600 RT2870_REG_MAC_SRST
| RT2870_REG_BBP_HRST
);
1601 rt2870_io_mac_write(sc
, RT2870_REG_SYS_CTRL
, 0);
1603 /* abort any pending transfers */
1605 if (sc
->rx_ring
.usb_pipe
!= NULL
)
1606 usbd_abort_pipe(sc
->rx_ring
.usb_pipe
);
1608 for (i
= 0; i
< sc
->usb_endpoints
- 1; i
++)
1609 if (sc
->tx_ring
[i
].usb_pipe
!= NULL
)
1610 usbd_abort_pipe(sc
->tx_ring
[i
].usb_pipe
);
1616 static void rt2870_stop(void *priv
)
1618 struct rt2870_softc
*sc
;
1622 rt2870_stop_locked(sc
);
1628 static void rt2870_start(struct ifnet
*ifp
)
1630 struct rt2870_softc
*sc
;
1631 struct ieee80211com
*ic
;
1632 struct ieee80211_node
*ni
;
1633 struct ether_header
*eh
;
1640 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
1645 IF_POLL(&ic
->ic_mgtq
, m
);
1648 if (sc
->tx_ring
[sc
->tx_ring_mgtqid
].queued
>= RT2870_SOFTC_TX_RING_DATA_COUNT
)
1650 RT2870_DPRINTF(sc
, RT2870_DEBUG_TX
,
1651 "%s: if_start: Tx ring with qid=%d is full\n",
1652 device_get_nameunit(sc
->dev
), sc
->tx_ring_mgtqid
);
1654 ifp
->if_drv_flags
|= IFF_DRV_OACTIVE
;
1658 IF_DEQUEUE(&ic
->ic_mgtq
, m
);
1660 ni
= (struct ieee80211_node
*) m
->m_pkthdr
.rcvif
;
1661 m
->m_pkthdr
.rcvif
= NULL
;
1663 if (bpf_peers_present(ic
->ic_rawbpf
))
1664 bpf_mtap(ic
->ic_rawbpf
, m
);
1666 if (rt2870_tx_frame(sc
, m
, ni
, sc
->tx_ring_mgtqid
) != 0)
1671 if (ic
->ic_state
!= IEEE80211_S_RUN
)
1674 IF_POLL(&ifp
->if_snd
, m
);
1678 IFQ_DRV_DEQUEUE(&ifp
->if_snd
, m
);
1680 if (ic
->ic_flags
& IEEE80211_F_SCAN
)
1681 ieee80211_cancel_scan(ic
);
1683 if (m
->m_len
< sizeof(struct ether_header
) &&
1684 !(m
= m_pullup(m
, sizeof (struct ether_header
))))
1687 eh
= mtod(m
, struct ether_header
*);
1689 ni
= ieee80211_find_txnode(ic
, eh
->ether_dhost
);
1692 RT2870_DPRINTF(sc
, RT2870_DEBUG_TX
,
1693 "%s: if_start: could not find Tx node\n",
1694 device_get_nameunit(sc
->dev
));
1700 ieee80211_classify(ic
, m
, ni
);
1702 qid
= M_WME_GETAC(m
);
1704 if (sc
->tx_ring
[qid
].queued
>= RT2870_SOFTC_TX_RING_DATA_COUNT
)
1706 RT2870_DPRINTF(sc
, RT2870_DEBUG_TX
,
1707 "%s: if_start: Tx ring with qid=%d is full\n",
1708 device_get_nameunit(sc
->dev
), qid
);
1711 ieee80211_free_node(ni
);
1712 ifp
->if_drv_flags
|= IFF_DRV_OACTIVE
;
1719 m
= ieee80211_encap(ic
, m
, ni
);
1722 ieee80211_free_node(ni
);
1727 if (bpf_peers_present(ic
->ic_rawbpf
))
1728 bpf_mtap(ic
->ic_rawbpf
, m
);
1730 if (rt2870_tx_frame(sc
, m
, ni
, qid
) != 0)
1732 ieee80211_free_node(ni
);
1733 ifp
->if_drv_flags
|= IFF_DRV_OACTIVE
;
1739 sc
->tx_timer
= RT2870_TX_WATCHDOG_TIMEOUT
;
1741 ic
->ic_lastdata
= ticks
;
1743 callout_reset(&sc
->tx_watchdog_ch
, hz
, rt2870_tx_watchdog
, sc
);
1750 static int rt2870_ioctl(struct ifnet
*ifp
, u_long cmd
, caddr_t data
)
1752 struct rt2870_softc
*sc
;
1753 struct ieee80211com
*ic
;
1764 if (ifp
->if_flags
& IFF_UP
)
1766 if (ifp
->if_drv_flags
& IFF_DRV_RUNNING
)
1768 if ((ifp
->if_flags
^ sc
->if_flags
) & IFF_PROMISC
)
1769 rt2870_asic_update_promisc(sc
);
1773 rt2870_init_locked(sc
);
1778 if (ifp
->if_drv_flags
& IFF_DRV_RUNNING
)
1779 rt2870_stop_locked(sc
);
1782 sc
->if_flags
= ifp
->if_flags
;
1786 error
= ieee80211_ioctl(ic
, cmd
, data
);
1789 if (error
== ENETRESET
)
1791 if ((ifp
->if_flags
& IFF_UP
) &&
1792 (ifp
->if_drv_flags
& IFF_DRV_RUNNING
) &&
1793 (ic
->ic_roaming
!= IEEE80211_ROAMING_MANUAL
))
1795 rt2870_stop_locked(sc
);
1796 rt2870_init_locked(sc
);
1808 static int rt2870_reset(struct ifnet
*ifp
)
1810 struct rt2870_softc
*sc
;
1811 struct ieee80211com
*ic
;
1816 if (ic
->ic_opmode
!= IEEE80211_M_MONITOR
)
1819 rt2870_rf_set_chan(sc
, ic
->ic_curchan
);
1827 static int rt2870_newstate(struct ieee80211com
*ic
,
1828 enum ieee80211_state nstate
, int arg
)
1830 struct rt2870_softc
*sc
;
1832 struct rt2870_cmd_argv_newstate cmd_argv
;
1837 cmd_argv
.nstate
= nstate
;
1840 rt2870_do_async(sc
, rt2870_newstate_cb
, &cmd_argv
,
1841 sizeof(struct rt2870_cmd_argv_newstate
));
1849 static void rt2870_scan_start(struct ieee80211com
*ic
)
1851 struct rt2870_softc
*sc
;
1857 rt2870_do_async(sc
, rt2870_scan_start_cb
, NULL
, 0);
1863 static void rt2870_scan_end(struct ieee80211com
*ic
)
1865 struct rt2870_softc
*sc
;
1871 rt2870_do_async(sc
, rt2870_scan_end_cb
, NULL
, 0);
1875 * rt2870_set_channel
1877 static void rt2870_set_channel(struct ieee80211com
*ic
)
1879 struct rt2870_softc
*sc
;
1885 rt2870_do_async(sc
, rt2870_set_channel_cb
, NULL
, 0);
1891 static void rt2870_newassoc(struct ieee80211_node
*ni
, int isnew
)
1893 struct rt2870_softc
*sc
;
1894 struct ieee80211com
*ic
;
1896 struct rt2870_cmd_argv_newassoc cmd_argv
;
1902 cmd_argv
.associd
= (ni
!= NULL
) ? ni
->ni_associd
: 0;
1903 cmd_argv
.isnew
= isnew
;
1904 memcpy(cmd_argv
.macaddr
, ni
->ni_macaddr
, IEEE80211_ADDR_LEN
);
1906 rt2870_do_async(sc
, rt2870_newassoc_cb
, &cmd_argv
,
1907 sizeof(struct rt2870_cmd_argv_newassoc
));
1913 static void rt2870_updateslot(struct ifnet
*ifp
)
1915 struct rt2870_softc
*sc
;
1919 rt2870_do_async(sc
, rt2870_updateslot_cb
, NULL
, 0);
1925 static int rt2870_wme_update(struct ieee80211com
*ic
)
1927 struct rt2870_softc
*sc
;
1933 rt2870_do_async(sc
, rt2870_wme_update_cb
, NULL
, 0);
1939 * rt2870_update_beacon
1941 static void rt2870_update_beacon(struct ieee80211com
*ic
, int what
)
1943 struct rt2870_softc
*sc
;
1945 struct rt2870_cmd_argv_updatebeacon cmd_argv
;
1950 cmd_argv
.what
= what
;
1952 rt2870_do_async(sc
, rt2870_update_beacon_cb
, &cmd_argv
,
1953 sizeof(struct rt2870_cmd_argv_updatebeacon
));
1957 * rt2870_key_update_begin
1959 static void rt2870_key_update_begin(struct ieee80211com
*ic
)
1961 struct rt2870_softc
*sc
;
1967 rt2870_do_async(sc
, rt2870_key_update_begin_cb
, NULL
, 0);
1971 * rt2870_key_update_end
1973 static void rt2870_key_update_end(struct ieee80211com
*ic
)
1975 struct rt2870_softc
*sc
;
1981 rt2870_do_async(sc
, rt2870_key_update_end_cb
, NULL
, 0);
1987 static int rt2870_key_set(struct ieee80211com
*ic
,
1988 const struct ieee80211_key
*k
, const uint8_t mac
[IEEE80211_ADDR_LEN
])
1990 struct rt2870_softc
*sc
;
1992 struct ieee80211_node
*ni
;
1993 struct rt2870_cmd_argv_keyset cmd_argv
;
1995 if (k
->wk_cipher
->ic_cipher
!= IEEE80211_CIPHER_WEP
&&
1996 k
->wk_cipher
->ic_cipher
!= IEEE80211_CIPHER_TKIP
&&
1997 k
->wk_cipher
->ic_cipher
!= IEEE80211_CIPHER_AES_CCM
)
2003 if (ic
->ic_opmode
!= IEEE80211_M_HOSTAP
)
2006 ni
= ieee80211_find_node(&ic
->ic_sta
, mac
);
2008 memcpy(&cmd_argv
.key
, k
, sizeof(struct ieee80211_key
));
2009 cmd_argv
.associd
= (ni
!= NULL
) ? ni
->ni_associd
: 0;
2011 if ((ic
->ic_opmode
== IEEE80211_M_HOSTAP
) && (ni
!= NULL
))
2012 ieee80211_free_node(ni
);
2014 rt2870_do_async(sc
, rt2870_key_set_cb
, &cmd_argv
,
2015 sizeof(struct rt2870_cmd_argv_keyset
));
2023 static int rt2870_key_delete(struct ieee80211com
*ic
,
2024 const struct ieee80211_key
*k
)
2026 struct rt2870_softc
*sc
;
2028 struct ieee80211_node
*ni
;
2029 struct rt2870_cmd_argv_keydelete cmd_argv
;
2035 memcpy(&cmd_argv
.key
, k
, sizeof(struct ieee80211_key
));
2036 cmd_argv
.associd
= (ni
!= NULL
) ? ni
->ni_associd
: 0;
2038 rt2870_do_async(sc
, rt2870_key_delete_cb
, &cmd_argv
,
2039 sizeof(struct rt2870_cmd_argv_keydelete
));
2047 static int rt2870_raw_xmit(struct ieee80211_node
*ni
, struct mbuf
*m
,
2048 const struct ieee80211_bpf_params
*params
)
2050 struct ieee80211com
*ic
;
2052 struct rt2870_softc
*sc
;
2062 * rt2870_media_change
2064 static int rt2870_media_change(struct ifnet
*ifp
)
2066 struct rt2870_softc
*sc
;
2071 error
= ieee80211_media_change(ifp
);
2072 if (error
!= ENETRESET
)
2075 if ((ifp
->if_flags
& IFF_UP
) && (ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
2085 * rt2870_recv_action
2087 static void rt2870_recv_action(struct ieee80211_node
*ni
,
2088 const uint8_t *frm
, const uint8_t *efrm
)
2090 struct rt2870_softc
*sc
;
2091 struct ieee80211com
*ic
;
2093 const struct ieee80211_action
*ia
;
2094 uint16_t associd
, baparamset
;
2103 ia
= (const struct ieee80211_action
*) frm
;
2105 sc
->recv_action(ni
, frm
, efrm
);
2107 if (ia
->ia_category
!= IEEE80211_ACTION_CAT_BA
)
2110 associd
= (ni
!= NULL
) ? ni
->ni_associd
: 0;
2111 wcid
= RT2870_AID2WCID(associd
);
2113 switch (ia
->ia_action
)
2115 /* IEEE80211_ACTION_BA_ADDBA_REQUEST */
2116 case IEEE80211_ACTION_BA_ADDBA_REQUEST
:
2117 baparamset
= LE_READ_2(frm
+ 3);
2118 tid
= RT2870_MS(baparamset
, IEEE80211_BAPS_TID
);
2120 RT2870_DPRINTF(sc
, RT2870_DEBUG_BA
,
2121 "%s: adding A-MPDU Rx block ACK: associd=0x%04x, tid=%d\n",
2122 device_get_nameunit(sc
->dev
), associd
, tid
);
2124 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_WCID(wcid
) + 4);
2126 tmp
|= (0x10000 << tid
);
2128 rt2870_io_mac_write(sc
, RT2870_REG_WCID(wcid
) + 4, tmp
);
2131 /* IEEE80211_ACTION_BA_DELBA */
2132 case IEEE80211_ACTION_BA_DELBA
:
2133 baparamset
= LE_READ_2(frm
+ 2);
2134 tid
= RT2870_MS(baparamset
, IEEE80211_BAPS_TID
);
2136 RT2870_DPRINTF(sc
, RT2870_DEBUG_BA
,
2137 "%s: deleting A-MPDU Rx block ACK: associd=0x%04x, tid=%d\n",
2138 device_get_nameunit(sc
->dev
), associd
, tid
);
2140 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_WCID(wcid
) + 4);
2142 tmp
&= ~(0x10000 << tid
);
2144 rt2870_io_mac_write(sc
, RT2870_REG_WCID(wcid
) + 4, tmp
);
2150 * rt2870_send_action
2152 static int rt2870_send_action(struct ieee80211_node
*ni
,
2153 int category
, int action
, uint16_t args
[4])
2155 struct rt2870_softc
*sc
;
2156 struct ieee80211com
*ic
;
2158 uint16_t associd
, baparamset
;
2167 ret
= sc
->send_action(ni
, category
, action
, args
);
2169 if (category
!= IEEE80211_ACTION_CAT_BA
)
2172 associd
= (ni
!= NULL
) ? ni
->ni_associd
: 0;
2173 wcid
= RT2870_AID2WCID(associd
);
2177 /* IEEE80211_ACTION_BA_DELBA */
2178 case IEEE80211_ACTION_BA_DELBA
:
2179 baparamset
= RT2870_SM(args
[0], IEEE80211_DELBAPS_TID
) |
2180 RT2870_SM(args
[1], IEEE80211_DELBAPS_INIT
);
2182 if (RT2870_MS(baparamset
, IEEE80211_DELBAPS_INIT
) == IEEE80211_DELBAPS_INIT
)
2185 tid
= RT2870_MS(baparamset
, IEEE80211_DELBAPS_TID
);
2187 RT2870_DPRINTF(sc
, RT2870_DEBUG_BA
,
2188 "%s: deleting A-MPDU Rx block ACK: associd=0x%04x, tid=%d\n",
2189 device_get_nameunit(sc
->dev
), associd
, tid
);
2191 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_WCID(wcid
) + 4);
2193 tmp
&= ~(0x10000 << tid
);
2195 rt2870_io_mac_write(sc
, RT2870_REG_WCID(wcid
) + 4, tmp
);
2203 * rt2870_amrr_update_iter_func
2205 static void rt2870_amrr_update_iter_func(void *arg
, struct ieee80211_node
*ni
)
2207 struct rt2870_softc
*sc
;
2208 struct ieee80211com
*ic
;
2214 /* only associated stations */
2216 if (ni
->ni_associd
!= 0)
2218 wcid
= RT2870_AID2WCID(ni
->ni_associd
);
2220 rt2870_amrr_choose(ni
, &sc
->amrr_node
[wcid
]);
2222 RT2870_DPRINTF(sc
, RT2870_DEBUG_RATE
,
2223 "%s:%s node Tx rate: associd=0x%04x, rate=0x%02x, max rate=0x%02x\n",
2224 device_get_nameunit(sc
->dev
),
2225 (ni
->ni_flags
& IEEE80211_NODE_HT
) ? " HT" : "",
2227 (ni
->ni_flags
& IEEE80211_NODE_HT
) ?
2228 (ni
->ni_htrates
.rs_rates
[ni
->ni_txrate
] | IEEE80211_RATE_MCS
) :
2229 (ni
->ni_rates
.rs_rates
[ni
->ni_txrate
] & IEEE80211_RATE_VAL
),
2230 (ni
->ni_flags
& IEEE80211_NODE_HT
) ?
2231 (ni
->ni_htrates
.rs_rates
[ni
->ni_htrates
.rs_nrates
- 1] | IEEE80211_RATE_MCS
) :
2232 (ni
->ni_rates
.rs_rates
[ni
->ni_rates
.rs_nrates
- 1] & IEEE80211_RATE_VAL
));
2239 static void rt2870_periodic(void *arg
)
2241 struct rt2870_softc
*sc
;
2247 RT2870_DPRINTF(sc
, RT2870_DEBUG_PERIODIC
,
2249 device_get_nameunit(sc
->dev
));
2251 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
2254 taskqueue_enqueue(sc
->taskqueue
, &sc
->periodic_task
);
2258 * rt2870_tx_watchdog
2260 static void rt2870_tx_watchdog(void *arg
)
2262 struct rt2870_softc
*sc
;
2268 if (sc
->tx_timer
== 0)
2271 if (--sc
->tx_timer
== 0)
2273 printf("%s: Tx watchdog timeout: resetting\n",
2274 device_get_nameunit(sc
->dev
));
2276 rt2870_stop_locked(sc
);
2277 rt2870_init_locked(sc
);
2281 sc
->tx_watchdog_timeouts
++;
2284 callout_reset(&sc
->tx_watchdog_ch
, hz
, rt2870_tx_watchdog
, sc
);
2290 static int rt2870_do_async(struct rt2870_softc
*sc
,
2291 void (*cb
)(struct rt2870_softc
*sc
, void *arg
),
2295 struct rt2870_softc_cmd_ring
*ring
;
2296 struct rt2870_softc_cmd
*cmd
;
2300 ring
= &sc
->cmd_ring
;
2302 RT2870_SOFTC_LOCK(sc
);
2304 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
2306 RT2870_SOFTC_UNLOCK(sc
);
2310 if (ring
->queued
>= RT2870_SOFTC_CMD_RING_CMD_COUNT
)
2312 RT2870_SOFTC_UNLOCK(sc
);
2316 cmd
= STAILQ_FIRST(&ring
->inactive
);
2317 STAILQ_REMOVE_HEAD(&ring
->inactive
, next
);
2322 memcpy(cmd
->data
, arg
, len
);
2324 STAILQ_INSERT_TAIL(&ring
->active
, cmd
, next
);
2327 run_cmd_task
= (ring
->queued
== 1);
2329 RT2870_SOFTC_UNLOCK(sc
);
2332 taskqueue_enqueue(sc
->taskqueue
, &sc
->cmd_task
);
2338 * rt2870_newstate_cb
2340 static void rt2870_newstate_cb(struct rt2870_softc
*sc
, void *arg
)
2342 struct ieee80211com
*ic
;
2343 enum ieee80211_state nstate
;
2344 struct ieee80211_node
*ni
;
2345 struct rt2870_cmd_argv_newstate
*cmd_argv
;
2350 nstate
= cmd_argv
->nstate
;
2352 RT2870_DPRINTF(sc
, RT2870_DEBUG_STATE
,
2353 "%s: newstate: %s -> %s\n",
2354 device_get_nameunit(sc
->dev
),
2355 ieee80211_state_name
[ic
->ic_state
], ieee80211_state_name
[nstate
]);
2357 error
= sc
->newstate(ic
, nstate
, cmd_argv
->arg
);
2361 /* turn link LED off */
2363 if (nstate
!= IEEE80211_S_RUN
)
2364 rt2870_led_cmd(sc
, RT2870_LED_CMD_RADIO_OFF
);
2368 case IEEE80211_S_INIT
:
2369 rt2870_asic_disable_tsf_sync(sc
);
2372 case IEEE80211_S_RUN
:
2375 rt2870_rf_set_chan(sc
, ni
->ni_chan
);
2377 if (ic
->ic_opmode
!= IEEE80211_M_MONITOR
)
2379 rt2870_asic_enable_mrr(sc
);
2380 rt2870_asic_set_txpreamble(sc
);
2381 rt2870_asic_set_basicrates(sc
);
2382 rt2870_asic_set_bssid(sc
, ni
->ni_bssid
);
2385 if (ic
->ic_opmode
== IEEE80211_M_STA
)
2386 rt2870_newassoc(ni
, 1);
2388 if (ic
->ic_opmode
== IEEE80211_M_HOSTAP
||
2389 ic
->ic_opmode
== IEEE80211_M_IBSS
)
2391 error
= rt2870_asic_update_beacon(sc
);
2396 if (ic
->ic_opmode
!= IEEE80211_M_MONITOR
)
2397 rt2870_asic_enable_tsf_sync(sc
);
2399 /* turn link LED on */
2401 if (ic
->ic_opmode
!= IEEE80211_M_MONITOR
)
2403 rt2870_led_cmd(sc
, RT2870_LED_CMD_RADIO_ON
|
2404 (IEEE80211_IS_CHAN_2GHZ(ni
->ni_chan
) ?
2405 RT2870_LED_CMD_LINK_2GHZ
: RT2870_LED_CMD_LINK_5GHZ
));
2415 * rt2870_scan_start_cb
2417 static void rt2870_scan_start_cb(struct rt2870_softc
*sc
, void *arg
)
2419 struct ieee80211com
*ic
;
2425 rt2870_asic_disable_tsf_sync(sc
);
2429 * rt2870_scan_end_cb
2431 static void rt2870_scan_end_cb(struct rt2870_softc
*sc
, void *arg
)
2433 struct ieee80211com
*ic
;
2434 struct ieee80211_node
*ni
;
2439 rt2870_asic_enable_tsf_sync(sc
);
2443 * rt2870_set_channel_cb
2445 static void rt2870_set_channel_cb(struct rt2870_softc
*sc
, void *arg
)
2447 struct ieee80211com
*ic
;
2451 RT2870_DPRINTF(sc
, RT2870_DEBUG_CHAN
,
2452 "%s: set channel: channel=%u, HT%s%s\n",
2453 device_get_nameunit(sc
->dev
),
2454 ieee80211_chan2ieee(ic
, ic
->ic_curchan
),
2455 !IEEE80211_IS_CHAN_HT(ic
->ic_curchan
) ? " disabled" :
2456 IEEE80211_IS_CHAN_HT20(ic
->ic_curchan
) ? "20":
2457 IEEE80211_IS_CHAN_HT40U(ic
->ic_curchan
) ? "40U" : "40D",
2458 (ic
->ic_flags
& IEEE80211_F_SCAN
) ? ", scanning" : "");
2460 rt2870_rf_set_chan(sc
, ic
->ic_curchan
);
2464 * rt2870_newassoc_cb
2466 static void rt2870_newassoc_cb(struct rt2870_softc
*sc
, void *arg
)
2468 struct ieee80211com
*ic
;
2469 struct ieee80211_node
*ni
;
2470 struct rt2870_cmd_argv_newassoc
*cmd_argv
;
2473 uint8_t *macaddr
, wcid
;
2478 associd
= cmd_argv
->associd
;
2479 isnew
= cmd_argv
->isnew
;
2480 macaddr
= cmd_argv
->macaddr
;
2482 wcid
= RT2870_AID2WCID(associd
);
2484 RT2870_DPRINTF(sc
, RT2870_DEBUG_NODE
,
2485 "%s: new association: wcid=0x%02x, "
2486 "mac addr=%s, QoS %s, ERP %s, HT %s\n",
2487 device_get_nameunit(sc
->dev
), wcid
,
2488 ether_sprintf(macaddr
),
2489 (ni
->ni_flags
& IEEE80211_NODE_QOS
) ? "enabled" : "disabled",
2490 (ni
->ni_flags
& IEEE80211_NODE_ERP
) ? "enabled" : "disabled",
2491 (ni
->ni_flags
& IEEE80211_NODE_HT
) ? "enabled" : "disabled");
2493 rt2870_io_mac_write_multi(sc
, RT2870_REG_WCID(wcid
),
2494 macaddr
, IEEE80211_ADDR_LEN
);
2496 rt2870_amrr_node_init(&sc
->amrr
, &sc
->amrr_node
[wcid
], ni
);
2498 RT2870_DPRINTF(sc
, RT2870_DEBUG_RATE
,
2499 "%s: initial%s node Tx rate: associd=0x%04x, rate=0x%02x, max rate=0x%02x\n",
2500 device_get_nameunit(sc
->dev
),
2501 (ni
->ni_flags
& IEEE80211_NODE_HT
) ? " HT" : "",
2503 (ni
->ni_flags
& IEEE80211_NODE_HT
) ?
2504 (ni
->ni_htrates
.rs_rates
[ni
->ni_txrate
] | IEEE80211_RATE_MCS
) :
2505 (ni
->ni_rates
.rs_rates
[ni
->ni_txrate
] & IEEE80211_RATE_VAL
),
2506 (ni
->ni_flags
& IEEE80211_NODE_HT
) ?
2507 (ni
->ni_htrates
.rs_rates
[ni
->ni_htrates
.rs_nrates
- 1] | IEEE80211_RATE_MCS
) :
2508 (ni
->ni_rates
.rs_rates
[ni
->ni_rates
.rs_nrates
- 1] & IEEE80211_RATE_VAL
));
2510 rt2870_asic_updateprot(sc
);
2511 rt2870_asic_updateslot(sc
);
2512 rt2870_asic_set_txpreamble(sc
);
2516 * rt2870_updateslot_cb
2518 static void rt2870_updateslot_cb(struct rt2870_softc
*sc
, void *arg
)
2520 rt2870_asic_updateslot(sc
);
2524 * rt2870_wme_update_cb
2526 static void rt2870_wme_update_cb(struct rt2870_softc
*sc
, void *arg
)
2528 rt2870_asic_wme_update(sc
);
2532 * rt2870_update_beacon_cb
2534 static void rt2870_update_beacon_cb(struct rt2870_softc
*sc
, void *arg
)
2536 struct rt2870_cmd_argv_updatebeacon
*cmd_argv
;
2540 RT2870_DPRINTF(sc
, RT2870_DEBUG_BEACON
,
2541 "%s: update beacon\n",
2542 device_get_nameunit(sc
->dev
));
2544 rt2870_asic_update_beacon(sc
);
2548 * rt2870_key_update_begin_cb
2550 static void rt2870_key_update_begin_cb(struct rt2870_softc
*sc
, void *arg
)
2556 RT2870_DPRINTF(sc
, RT2870_DEBUG_KEY
,
2557 "%s: key update begin\n",
2558 device_get_nameunit(sc
->dev
));
2560 taskqueue_block(sc
->taskqueue
);
2562 IF_LOCK(&ifp
->if_snd
);
2566 * rt2870_key_update_end_cb
2568 static void rt2870_key_update_end_cb(struct rt2870_softc
*sc
, void *arg
)
2574 RT2870_DPRINTF(sc
, RT2870_DEBUG_KEY
,
2575 "%s: key update end\n",
2576 device_get_nameunit(sc
->dev
));
2578 IF_UNLOCK(&ifp
->if_snd
);
2580 taskqueue_unblock(sc
->taskqueue
);
2586 static void rt2870_key_set_cb(struct rt2870_softc
*sc
, void *arg
)
2588 struct ieee80211com
*ic
;
2589 struct ieee80211_key
*k
;
2590 struct rt2870_cmd_argv_keyset
*cmd_argv
;
2591 uint16_t associd
, key_base
, keymode_base
;
2592 uint8_t mode
, vapid
, wcid
, iv
[8];
2598 associd
= cmd_argv
->associd
;
2600 switch (k
->wk_cipher
->ic_cipher
)
2602 case IEEE80211_CIPHER_WEP
:
2603 if(k
->wk_keylen
< 8)
2604 mode
= RT2870_REG_CIPHER_MODE_WEP40
;
2606 mode
= RT2870_REG_CIPHER_MODE_WEP104
;
2609 case IEEE80211_CIPHER_TKIP
:
2610 mode
= RT2870_REG_CIPHER_MODE_TKIP
;
2613 case IEEE80211_CIPHER_AES_CCM
:
2614 mode
= RT2870_REG_CIPHER_MODE_AES_CCMP
;
2621 RT2870_DPRINTF(sc
, RT2870_DEBUG_KEY
,
2622 "%s: set key: keyix=%d, keylen=%d, associd=0x%04x, mode=%d, group=%d\n",
2623 device_get_nameunit(sc
->dev
), k
->wk_keyix
, k
->wk_keylen
, associd
, mode
,
2624 (k
->wk_flags
& IEEE80211_KEY_GROUP
) ? 1 : 0);
2626 if (!(k
->wk_flags
& IEEE80211_KEY_GROUP
))
2628 /* install pairwise key */
2631 wcid
= RT2870_AID2WCID(associd
);
2632 key_base
= RT2870_REG_PKEY(wcid
);
2634 if (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_WEP
)
2638 iv
[3] = (k
->wk_keyix
<< 6);
2642 if (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_TKIP
)
2644 iv
[0] = (k
->wk_keytsc
>> 8);
2645 iv
[1] = ((iv
[0] | 0x20) & 0x7f);
2646 iv
[2] = k
->wk_keytsc
;
2652 iv
[0] = k
->wk_keytsc
;
2653 iv
[1] = k
->wk_keytsc
>> 8;
2657 iv
[3] = ((k
->wk_keyix
<< 6) | IEEE80211_WEP_EXTIV
);
2658 iv
[4] = (k
->wk_keytsc
>> 16);
2659 iv
[5] = (k
->wk_keytsc
>> 24);
2660 iv
[6] = (k
->wk_keytsc
>> 32);
2661 iv
[7] = (k
->wk_keytsc
>> 40);
2663 RT2870_DPRINTF(sc
, RT2870_DEBUG_KEY
,
2664 "%s: set key: iv=%02x %02x %02x %02x %02x %02x %02x %02x\n",
2665 device_get_nameunit(sc
->dev
),
2666 iv
[0], iv
[1], iv
[2], iv
[3], iv
[4], iv
[5], iv
[6], iv
[7]);
2669 rt2870_io_mac_write_multi(sc
, RT2870_REG_IVEIV(wcid
), iv
, 8);
2671 if (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_TKIP
)
2673 rt2870_io_mac_write_multi(sc
, key_base
, k
->wk_key
, 16);
2675 if (ic
->ic_opmode
!= IEEE80211_M_HOSTAP
)
2677 rt2870_io_mac_write_multi(sc
, key_base
+ 16, &k
->wk_key
[16], 8);
2678 rt2870_io_mac_write_multi(sc
, key_base
+ 24, &k
->wk_key
[24], 8);
2682 rt2870_io_mac_write_multi(sc
, key_base
+ 16, &k
->wk_key
[24], 8);
2683 rt2870_io_mac_write_multi(sc
, key_base
+ 24, &k
->wk_key
[16], 8);
2688 rt2870_io_mac_write_multi(sc
, key_base
, k
->wk_key
, k
->wk_keylen
);
2691 tmp
= ((vapid
& RT2870_REG_VAP_MASK
) << RT2870_REG_VAP_SHIFT
) |
2692 (mode
<< RT2870_REG_CIPHER_MODE_SHIFT
) | RT2870_REG_PKEY_ENABLE
;
2694 rt2870_io_mac_write(sc
, RT2870_REG_WCID_ATTR(wcid
), tmp
);
2697 if ((k
->wk_flags
& IEEE80211_KEY_GROUP
) ||
2698 (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_WEP
))
2700 /* install group key */
2703 key_base
= RT2870_REG_SKEY(vapid
, k
->wk_keyix
);
2704 keymode_base
= RT2870_REG_SKEY_MODE(vapid
);
2706 if (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_TKIP
)
2708 rt2870_io_mac_write_multi(sc
, key_base
, k
->wk_key
, 16);
2710 if (ic
->ic_opmode
!= IEEE80211_M_HOSTAP
)
2712 rt2870_io_mac_write_multi(sc
, key_base
+ 16, &k
->wk_key
[16], 8);
2713 rt2870_io_mac_write_multi(sc
, key_base
+ 24, &k
->wk_key
[24], 8);
2717 rt2870_io_mac_write_multi(sc
, key_base
+ 16, &k
->wk_key
[24], 8);
2718 rt2870_io_mac_write_multi(sc
, key_base
+ 24, &k
->wk_key
[16], 8);
2723 rt2870_io_mac_write_multi(sc
, key_base
, k
->wk_key
, k
->wk_keylen
);
2726 tmp
= rt2870_io_mac_read(sc
, keymode_base
);
2728 tmp
&= ~(0xf << (k
->wk_keyix
* 4 + 16 * (vapid
% 2)));
2729 tmp
|= (mode
<< (k
->wk_keyix
* 4 + 16 * (vapid
% 2)));
2731 rt2870_io_mac_write(sc
, keymode_base
, tmp
);
2736 * rt2870_key_delete_cb
2738 static void rt2870_key_delete_cb(struct rt2870_softc
*sc
, void *arg
)
2740 struct ieee80211com
*ic
;
2741 struct ieee80211_key
*k
;
2742 struct rt2870_cmd_argv_keydelete
*cmd_argv
;
2744 uint8_t vapid
, wcid
;
2750 associd
= cmd_argv
->associd
;
2752 RT2870_DPRINTF(sc
, RT2870_DEBUG_KEY
,
2753 "%s: delete key: keyix=%d, keylen=%d, associd=0x%04x, group=%d\n",
2754 device_get_nameunit(sc
->dev
), k
->wk_keyix
, k
->wk_keylen
, associd
,
2755 (k
->wk_flags
& IEEE80211_KEY_GROUP
) ? 1 : 0);
2757 if (!(k
->wk_flags
& IEEE80211_KEY_GROUP
))
2759 /* remove pairwise key */
2761 wcid
= RT2870_AID2WCID(associd
);
2763 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_WCID_ATTR(wcid
));
2766 tmp
|= (RT2870_REG_CIPHER_MODE_NONE
<< RT2870_REG_CIPHER_MODE_SHIFT
);
2768 rt2870_io_mac_write(sc
, RT2870_REG_WCID_ATTR(wcid
), tmp
);
2772 /* remove group key */
2776 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_SKEY_MODE(vapid
));
2778 tmp
&= ~(0xf << (k
->wk_keyix
* 4 + 16 * (vapid
% 2)));
2779 tmp
|= (RT2870_REG_CIPHER_MODE_NONE
<< (k
->wk_keyix
* 4 + 16 * (vapid
% 2)));
2781 rt2870_io_mac_write(sc
, RT2870_REG_SKEY_MODE(vapid
), tmp
);
2786 * rt2870_asic_set_bssid
2788 static void rt2870_asic_set_bssid(struct rt2870_softc
*sc
,
2789 const uint8_t *bssid
)
2793 RT2870_DPRINTF(sc
, RT2870_DEBUG_STATE
,
2794 "%s: set bssid: bssid=%s\n",
2795 device_get_nameunit(sc
->dev
), ether_sprintf(bssid
));
2797 tmp
= bssid
[0] | (bssid
[1]) << 8 | (bssid
[2] << 16) | (bssid
[3] << 24);
2799 rt2870_io_mac_write(sc
, RT2870_REG_BSSID_DW0
, tmp
);
2801 tmp
= bssid
[4] | (bssid
[5] << 8);
2803 rt2870_io_mac_write(sc
, RT2870_REG_BSSID_DW1
, tmp
);
2807 * rt2870_asic_set_macaddr
2809 static void rt2870_asic_set_macaddr(struct rt2870_softc
*sc
,
2810 const uint8_t *addr
)
2814 tmp
= addr
[0] | (addr
[1] << 8) | (addr
[2] << 16) | (addr
[3] << 24);
2816 rt2870_io_mac_write(sc
, RT2870_REG_ADDR_DW0
, tmp
);
2818 tmp
= addr
[4] | (addr
[5] << 8);
2820 rt2870_io_mac_write(sc
, RT2870_REG_ADDR_DW1
, tmp
);
2824 * rt2870_asic_enable_tsf_sync
2826 static void rt2870_asic_enable_tsf_sync(struct rt2870_softc
*sc
)
2828 struct ieee80211com
*ic
;
2833 RT2870_DPRINTF(sc
, RT2870_DEBUG_BEACON
,
2834 "%s: enabling TSF\n",
2835 device_get_nameunit(sc
->dev
));
2837 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_BCN_TIME_CFG
);
2840 tmp
|= ic
->ic_bss
->ni_intval
* 16;
2841 tmp
|= (RT2870_REG_TSF_TIMER_ENABLE
| RT2870_REG_TBTT_TIMER_ENABLE
);
2843 if (ic
->ic_opmode
== IEEE80211_M_STA
)
2845 tmp
|= (RT2870_REG_TSF_SYNC_MODE_STA
<< RT2870_REG_TSF_SYNC_MODE_SHIFT
);
2847 else if (ic
->ic_opmode
== IEEE80211_M_IBSS
)
2849 tmp
|= RT2870_REG_BCN_TX_ENABLE
;
2850 tmp
|= (RT2870_REG_TSF_SYNC_MODE_IBSS
<< RT2870_REG_TSF_SYNC_MODE_SHIFT
);
2852 else if (ic
->ic_opmode
== IEEE80211_M_HOSTAP
)
2854 tmp
|= RT2870_REG_BCN_TX_ENABLE
;
2855 tmp
|= (RT2870_REG_TSF_SYNC_MODE_HOSTAP
<< RT2870_REG_TSF_SYNC_MODE_SHIFT
);
2858 rt2870_io_mac_write(sc
, RT2870_REG_BCN_TIME_CFG
, tmp
);
2862 * rt2870_asic_disable_tsf_sync
2864 static void rt2870_asic_disable_tsf_sync(struct rt2870_softc
*sc
)
2868 RT2870_DPRINTF(sc
, RT2870_DEBUG_BEACON
,
2869 "%s: disabling TSF\n",
2870 device_get_nameunit(sc
->dev
));
2872 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_BCN_TIME_CFG
);
2874 tmp
&= ~(RT2870_REG_BCN_TX_ENABLE
|
2875 RT2870_REG_TSF_TIMER_ENABLE
|
2876 RT2870_REG_TBTT_TIMER_ENABLE
);
2878 tmp
&= ~(RT2870_REG_TSF_SYNC_MODE_MASK
<< RT2870_REG_TSF_SYNC_MODE_SHIFT
);
2879 tmp
|= (RT2870_REG_TSF_SYNC_MODE_DISABLE
<< RT2870_REG_TSF_SYNC_MODE_SHIFT
);
2881 rt2870_io_mac_write(sc
, RT2870_REG_BCN_TIME_CFG
, tmp
);
2885 * rt2870_asic_enable_mrr
2887 static void rt2870_asic_enable_mrr(struct rt2870_softc
*sc
)
2889 #define CCK(mcs) (mcs)
2890 #define OFDM(mcs) ((1 << 3) | (mcs))
2891 #define HT(mcs) (mcs)
2893 rt2870_io_mac_write(sc
, RT2870_REG_TX_LG_FBK_CFG0
,
2894 (OFDM(6) << 28) | /* 54 -> 48 */
2895 (OFDM(5) << 24) | /* 48 -> 36 */
2896 (OFDM(4) << 20) | /* 36 -> 24 */
2897 (OFDM(3) << 16) | /* 24 -> 18 */
2898 (OFDM(2) << 12) | /* 18 -> 12 */
2899 (OFDM(1) << 8) | /* 12 -> 9 */
2900 (OFDM(0) << 4) | /* 9 -> 6 */
2901 OFDM(0)); /* 6 -> 6 */
2903 rt2870_io_mac_write(sc
, RT2870_REG_TX_LG_FBK_CFG1
,
2904 (CCK(2) << 12) | /* 11 -> 5.5 */
2905 (CCK(1) << 8) | /* 5.5 -> 2 */
2906 (CCK(0) << 4) | /* 2 -> 1 */
2907 CCK(0)); /* 1 -> 1 */
2909 rt2870_io_mac_write(sc
, RT2870_REG_TX_HT_FBK_CFG0
,
2919 rt2870_io_mac_write(sc
, RT2870_REG_TX_HT_FBK_CFG1
,
2935 * rt2870_asic_set_txpreamble
2937 static void rt2870_asic_set_txpreamble(struct rt2870_softc
*sc
)
2939 struct ieee80211com
*ic
;
2944 RT2870_DPRINTF(sc
, RT2870_DEBUG_STATE
,
2945 "%s: %s short Tx preamble\n",
2946 device_get_nameunit(sc
->dev
),
2947 (ic
->ic_flags
& IEEE80211_F_SHPREAMBLE
) ? "enabling" : "disabling");
2949 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_AUTO_RSP_CFG
);
2951 tmp
&= ~RT2870_REG_CCK_SHORT_ENABLE
;
2953 if (ic
->ic_flags
& IEEE80211_F_SHPREAMBLE
)
2954 tmp
|= RT2870_REG_CCK_SHORT_ENABLE
;
2956 rt2870_io_mac_write(sc
, RT2870_REG_AUTO_RSP_CFG
, tmp
);
2960 * rt2870_asic_set_basicrates
2962 static void rt2870_asic_set_basicrates(struct rt2870_softc
*sc
)
2964 struct ieee80211com
*ic
;
2968 if (ic
->ic_curmode
== IEEE80211_MODE_11B
)
2969 rt2870_io_mac_write(sc
, RT2870_REG_LEGACY_BASIC_RATE
, 0x3);
2970 else if (ic
->ic_curmode
== IEEE80211_MODE_11A
)
2971 rt2870_io_mac_write(sc
, RT2870_REG_LEGACY_BASIC_RATE
, 0x150);
2973 rt2870_io_mac_write(sc
, RT2870_REG_LEGACY_BASIC_RATE
, 0x15f);
2977 * rt2870_asic_update_rtsthreshold
2979 static void rt2870_asic_update_rtsthreshold(struct rt2870_softc
*sc
)
2981 struct ieee80211com
*ic
;
2987 RT2870_DPRINTF(sc
, RT2870_DEBUG_PROT
,
2988 "%s: updating RTS threshold: %d\n",
2989 device_get_nameunit(sc
->dev
), ic
->ic_rtsthreshold
);
2991 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_TX_RTS_CFG
);
2993 tmp
&= ~(RT2870_REG_TX_RTS_THRESHOLD_MASK
<< RT2870_REG_TX_RTS_THRESHOLD_SHIFT
);
2995 threshold
= (ic
->ic_rtsthreshold
< IEEE80211_RTS_MAX
) ?
2996 ic
->ic_rtsthreshold
: 0x1000;
2998 tmp
|= ((threshold
& RT2870_REG_TX_RTS_THRESHOLD_MASK
) <<
2999 RT2870_REG_TX_RTS_THRESHOLD_SHIFT
);
3001 rt2870_io_mac_write(sc
, RT2870_REG_TX_RTS_CFG
, tmp
);
3005 * rt2870_asic_update_txpower
3007 static void rt2870_asic_update_txpower(struct rt2870_softc
*sc
)
3009 struct ieee80211com
*ic
;
3010 uint32_t *txpow_rate
;
3018 RT2870_DPRINTF(sc
, RT2870_DEBUG_STATE
,
3019 "%s: updating Tx power: %d\n",
3020 device_get_nameunit(sc
->dev
), ic
->ic_txpowlimit
);
3022 if (!IEEE80211_IS_CHAN_HT40(ic
->ic_curchan
))
3024 txpow_rate
= sc
->txpow_rate_20mhz
;
3028 if (IEEE80211_IS_CHAN_2GHZ(ic
->ic_curchan
))
3029 txpow_rate
= sc
->txpow_rate_40mhz_2ghz
;
3031 txpow_rate
= sc
->txpow_rate_40mhz_5ghz
;
3036 val
= rt2870_io_bbp_read(sc
, 1);
3039 if (ic
->ic_txpowlimit
> 90)
3043 else if (ic
->ic_txpowlimit
> 60)
3047 else if (ic
->ic_txpowlimit
> 30)
3051 else if (ic
->ic_txpowlimit
> 15)
3055 else if (ic
->ic_txpowlimit
> 9)
3065 rt2870_io_bbp_write(sc
, 1, val
);
3067 for (i
= 0; i
< RT2870_SOFTC_TXPOW_RATE_COUNT
; i
++)
3069 if (txpow_rate
[i
] == 0xffffffff)
3072 tmp
= rt2870_read_eeprom_txpow_rate_add_delta(txpow_rate
[i
], delta
);
3074 rt2870_io_mac_write(sc
, RT2870_REG_TX_PWR_CFG(i
), tmp
);
3079 * rt2870_asic_update_promisc
3081 static void rt2870_asic_update_promisc(struct rt2870_softc
*sc
)
3086 ifp
= sc
->ic
.ic_ifp
;
3088 printf("%s: %s promiscuous mode\n",
3089 device_get_nameunit(sc
->dev
),
3090 (ifp
->if_flags
& IFF_PROMISC
) ? "entering" : "leaving");
3092 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_RX_FILTER_CFG
);
3094 tmp
&= ~RT2870_REG_RX_FILTER_DROP_UC_NOME
;
3096 if (!(ifp
->if_flags
& IFF_PROMISC
))
3097 tmp
|= RT2870_REG_RX_FILTER_DROP_UC_NOME
;
3099 rt2870_io_mac_write(sc
, RT2870_REG_RX_FILTER_CFG
, tmp
);
3103 * rt2870_asic_updateprot
3105 static void rt2870_asic_updateprot(struct rt2870_softc
*sc
)
3107 struct ieee80211com
*ic
;
3108 uint32_t cck_prot
, ofdm_prot
, mm20_prot
, mm40_prot
, gf20_prot
, gf40_prot
;
3113 /* CCK frame protection */
3115 cck_prot
= RT2870_REG_RTSTH_ENABLE
| RT2870_REG_PROT_NAV_SHORT
|
3116 RT2870_REG_TXOP_ALLOW_ALL
| RT2870_REG_PROT_CTRL_NONE
;
3118 /* set up protection frame phy mode and rate (MCS code) */
3120 if (ic
->ic_curmode
== IEEE80211_MODE_11A
)
3121 cck_prot
|= (RT2870_REG_PROT_PHYMODE_OFDM
<< RT2870_REG_PROT_PHYMODE_SHIFT
) |
3122 (0 << RT2870_REG_PROT_MCS_SHIFT
);
3124 cck_prot
|= ((RT2870_REG_PROT_PHYMODE_CCK
<< RT2870_REG_PROT_PHYMODE_SHIFT
) |
3125 (3 << RT2870_REG_PROT_MCS_SHIFT
));
3127 rt2870_io_mac_write(sc
, RT2870_REG_TX_CCK_PROT_CFG
, cck_prot
);
3129 /* OFDM frame protection */
3131 ofdm_prot
= RT2870_REG_RTSTH_ENABLE
| RT2870_REG_PROT_NAV_SHORT
|
3132 RT2870_REG_TXOP_ALLOW_ALL
;
3134 if (ic
->ic_flags
& IEEE80211_F_USEPROT
)
3136 RT2870_DPRINTF(sc
, RT2870_DEBUG_PROT
,
3137 "%s: updating protection mode: b/g protection mode=%s\n",
3138 device_get_nameunit(sc
->dev
),
3139 (ic
->ic_protmode
== IEEE80211_PROT_RTSCTS
) ? "RTS/CTS" :
3140 ((ic
->ic_protmode
== IEEE80211_PROT_CTSONLY
) ? "CTS-to-self" : "none"));
3142 if (ic
->ic_protmode
== IEEE80211_PROT_RTSCTS
)
3143 ofdm_prot
|= RT2870_REG_PROT_CTRL_RTS_CTS
;
3144 else if (ic
->ic_protmode
== IEEE80211_PROT_CTSONLY
)
3145 ofdm_prot
|= RT2870_REG_PROT_CTRL_CTS
;
3147 ofdm_prot
|= RT2870_REG_PROT_CTRL_NONE
;
3151 RT2870_DPRINTF(sc
, RT2870_DEBUG_PROT
,
3152 "%s: updating protection mode: b/g protection mode=%s\n",
3153 device_get_nameunit(sc
->dev
), "none");
3155 ofdm_prot
|= RT2870_REG_PROT_CTRL_NONE
;
3158 rt2870_io_mac_write(sc
, RT2870_REG_TX_OFDM_PROT_CFG
, ofdm_prot
);
3160 /* HT frame protection */
3162 if ((ic
->ic_opmode
== IEEE80211_M_STA
) && (ic
->ic_state
== IEEE80211_S_RUN
))
3163 htopmode
= ic
->ic_bss
->ni_htopmode
;
3165 htopmode
= ic
->ic_curhtprotmode
;
3167 RT2870_DPRINTF(sc
, RT2870_DEBUG_PROT
,
3168 "%s: updating protection mode: HT operation mode=0x%02x, protection mode=%s\n",
3169 device_get_nameunit(sc
->dev
),
3170 htopmode
& IEEE80211_HTINFO_OPMODE
,
3171 (ic
->ic_htprotmode
== IEEE80211_PROT_RTSCTS
) ? "RTS/CTS" :
3172 ((ic
->ic_htprotmode
== IEEE80211_PROT_CTSONLY
) ? "CTS-to-self" : "none"));
3174 switch (htopmode
& IEEE80211_HTINFO_OPMODE
)
3176 /* IEEE80211_HTINFO_OPMODE_HT20PR */
3177 case IEEE80211_HTINFO_OPMODE_HT20PR
:
3178 mm20_prot
= RT2870_REG_PROT_NAV_SHORT
| RT2870_REG_PROT_CTRL_NONE
|
3179 RT2870_REG_TXOP_ALLOW_CCK
| RT2870_REG_TXOP_ALLOW_OFDM
|
3180 RT2870_REG_TXOP_ALLOW_MM20
| RT2870_REG_TXOP_ALLOW_GF20
|
3181 (RT2870_REG_PROT_PHYMODE_OFDM
<< RT2870_REG_PROT_PHYMODE_SHIFT
) |
3182 (4 << RT2870_REG_PROT_MCS_SHIFT
);
3184 gf20_prot
= mm20_prot
;
3186 mm40_prot
= RT2870_REG_PROT_NAV_SHORT
| RT2870_REG_PROT_CTRL_NONE
|
3187 RT2870_REG_TXOP_ALLOW_ALL
|
3188 (RT2870_REG_PROT_PHYMODE_OFDM
<< RT2870_REG_PROT_PHYMODE_SHIFT
) |
3189 (0x84 << RT2870_REG_PROT_MCS_SHIFT
);
3191 if (ic
->ic_htprotmode
== IEEE80211_PROT_RTSCTS
)
3192 mm40_prot
|= RT2870_REG_PROT_CTRL_RTS_CTS
;
3193 else if (ic
->ic_htprotmode
== IEEE80211_PROT_CTSONLY
)
3194 mm40_prot
|= RT2870_REG_PROT_CTRL_CTS
;
3196 mm40_prot
|= RT2870_REG_PROT_CTRL_NONE
;
3198 gf40_prot
= mm40_prot
;
3201 /* IEEE80211_HTINFO_OPMODE_MIXED */
3202 case IEEE80211_HTINFO_OPMODE_MIXED
:
3203 mm20_prot
= RT2870_REG_PROT_NAV_SHORT
|
3204 RT2870_REG_TXOP_ALLOW_CCK
| RT2870_REG_TXOP_ALLOW_OFDM
|
3205 RT2870_REG_TXOP_ALLOW_MM20
| RT2870_REG_TXOP_ALLOW_GF20
;
3207 if (ic
->ic_flags
& IEEE80211_F_USEPROT
)
3208 mm20_prot
|= (RT2870_REG_PROT_PHYMODE_CCK
<< RT2870_REG_PROT_PHYMODE_SHIFT
) |
3209 (3 << RT2870_REG_PROT_MCS_SHIFT
);
3211 mm20_prot
|= (RT2870_REG_PROT_PHYMODE_OFDM
<< RT2870_REG_PROT_PHYMODE_SHIFT
) |
3212 (4 << RT2870_REG_PROT_MCS_SHIFT
);
3214 if (ic
->ic_htprotmode
== IEEE80211_PROT_RTSCTS
)
3215 mm20_prot
|= RT2870_REG_PROT_CTRL_RTS_CTS
;
3216 else if (ic
->ic_htprotmode
== IEEE80211_PROT_CTSONLY
)
3217 mm20_prot
|= RT2870_REG_PROT_CTRL_CTS
;
3219 mm20_prot
|= RT2870_REG_PROT_CTRL_NONE
;
3221 gf20_prot
= mm20_prot
;
3223 mm40_prot
= RT2870_REG_PROT_NAV_SHORT
| RT2870_REG_TXOP_ALLOW_ALL
;
3225 if (ic
->ic_flags
& IEEE80211_F_USEPROT
)
3226 mm40_prot
|= (RT2870_REG_PROT_PHYMODE_CCK
<< RT2870_REG_PROT_PHYMODE_SHIFT
) |
3227 (3 << RT2870_REG_PROT_MCS_SHIFT
);
3229 mm40_prot
|= (RT2870_REG_PROT_PHYMODE_OFDM
<< RT2870_REG_PROT_PHYMODE_SHIFT
) |
3230 (0x84 << RT2870_REG_PROT_MCS_SHIFT
);
3232 if (ic
->ic_htprotmode
== IEEE80211_PROT_RTSCTS
)
3233 mm40_prot
|= RT2870_REG_PROT_CTRL_RTS_CTS
;
3234 else if (ic
->ic_htprotmode
== IEEE80211_PROT_CTSONLY
)
3235 mm40_prot
|= RT2870_REG_PROT_CTRL_CTS
;
3237 mm40_prot
|= RT2870_REG_PROT_CTRL_NONE
;
3239 gf40_prot
= mm40_prot
;
3243 * IEEE80211_HTINFO_OPMODE_PURE
3244 * IEEE80211_HTINFO_OPMODE_PROTOPT
3246 case IEEE80211_HTINFO_OPMODE_PURE
:
3247 case IEEE80211_HTINFO_OPMODE_PROTOPT
:
3249 mm20_prot
= RT2870_REG_PROT_NAV_SHORT
| RT2870_REG_PROT_CTRL_NONE
|
3250 RT2870_REG_TXOP_ALLOW_CCK
| RT2870_REG_TXOP_ALLOW_OFDM
|
3251 RT2870_REG_TXOP_ALLOW_MM20
| RT2870_REG_TXOP_ALLOW_GF20
|
3252 (RT2870_REG_PROT_PHYMODE_OFDM
<< RT2870_REG_PROT_PHYMODE_SHIFT
) |
3253 (4 << RT2870_REG_PROT_MCS_SHIFT
);
3255 gf20_prot
= mm20_prot
;
3257 mm40_prot
= RT2870_REG_PROT_NAV_SHORT
| RT2870_REG_PROT_CTRL_NONE
|
3258 RT2870_REG_TXOP_ALLOW_ALL
|
3259 (RT2870_REG_PROT_PHYMODE_OFDM
<< RT2870_REG_PROT_PHYMODE_SHIFT
) |
3260 (0x84 << RT2870_REG_PROT_MCS_SHIFT
);
3262 gf40_prot
= mm40_prot
;
3266 rt2870_io_mac_write(sc
, RT2870_REG_TX_MM20_PROT_CFG
, mm20_prot
);
3267 rt2870_io_mac_write(sc
, RT2870_REG_TX_MM40_PROT_CFG
, mm40_prot
);
3268 rt2870_io_mac_write(sc
, RT2870_REG_TX_GF20_PROT_CFG
, gf20_prot
);
3269 rt2870_io_mac_write(sc
, RT2870_REG_TX_GF40_PROT_CFG
, gf40_prot
);
3273 * rt2870_asic_updateslot
3275 static void rt2870_asic_updateslot(struct rt2870_softc
*sc
)
3277 struct ieee80211com
*ic
;
3282 RT2870_DPRINTF(sc
, RT2870_DEBUG_STATE
,
3283 "%s: %s short slot time\n",
3284 device_get_nameunit(sc
->dev
),
3285 (ic
->ic_flags
& IEEE80211_F_SHSLOT
) ? "enabling" : "disabling");
3287 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_BKOFF_SLOT_CFG
);
3290 tmp
|= (ic
->ic_flags
& IEEE80211_F_SHSLOT
) ? 9 : 20;
3292 rt2870_io_mac_write(sc
, RT2870_REG_BKOFF_SLOT_CFG
, tmp
);
3296 * rt2870_asic_wme_update
3298 static void rt2870_asic_wme_update(struct rt2870_softc
*sc
)
3300 struct ieee80211com
*ic
;
3301 struct ieee80211_wme_state
*wme
;
3302 const struct wmeParams
*wmep
;
3307 wmep
= wme
->wme_chanParams
.cap_wmeParams
;
3309 RT2870_DPRINTF(sc
, RT2870_DEBUG_WME
,
3310 "%s: wme update: WME_AC_VO=%d/%d/%d/%d, WME_AC_VI=%d/%d/%d/%d, "
3311 "WME_AC_BK=%d/%d/%d/%d, WME_AC_BE=%d/%d/%d/%d\n",
3312 device_get_nameunit(sc
->dev
),
3313 wmep
[WME_AC_VO
].wmep_aifsn
,
3314 wmep
[WME_AC_VO
].wmep_logcwmin
, wmep
[WME_AC_VO
].wmep_logcwmax
,
3315 wmep
[WME_AC_VO
].wmep_txopLimit
,
3316 wmep
[WME_AC_VI
].wmep_aifsn
,
3317 wmep
[WME_AC_VI
].wmep_logcwmin
, wmep
[WME_AC_VI
].wmep_logcwmax
,
3318 wmep
[WME_AC_VI
].wmep_txopLimit
,
3319 wmep
[WME_AC_BK
].wmep_aifsn
,
3320 wmep
[WME_AC_BK
].wmep_logcwmin
, wmep
[WME_AC_BK
].wmep_logcwmax
,
3321 wmep
[WME_AC_BK
].wmep_txopLimit
,
3322 wmep
[WME_AC_BE
].wmep_aifsn
,
3323 wmep
[WME_AC_BE
].wmep_logcwmin
, wmep
[WME_AC_BE
].wmep_logcwmax
,
3324 wmep
[WME_AC_BE
].wmep_txopLimit
);
3326 for (i
= 0; i
< WME_NUM_AC
; i
++)
3327 rt2870_io_mac_write(sc
, RT2870_REG_TX_EDCA_AC_CFG(i
),
3328 (wmep
[i
].wmep_logcwmax
<< 16) | (wmep
[i
].wmep_logcwmin
<< 12) |
3329 (wmep
[i
].wmep_aifsn
<< 8) | wmep
[i
].wmep_txopLimit
);
3331 rt2870_io_mac_write(sc
, RT2870_REG_SCHDMA_WMM_AIFSN_CFG
,
3332 (wmep
[WME_AC_VO
].wmep_aifsn
<< 12) | (wmep
[WME_AC_VI
].wmep_aifsn
<< 8) |
3333 (wmep
[WME_AC_BK
].wmep_aifsn
<< 4) | wmep
[WME_AC_BE
].wmep_aifsn
);
3335 rt2870_io_mac_write(sc
, RT2870_REG_SCHDMA_WMM_CWMIN_CFG
,
3336 (wmep
[WME_AC_VO
].wmep_logcwmin
<< 12) | (wmep
[WME_AC_VI
].wmep_logcwmin
<< 8) |
3337 (wmep
[WME_AC_BK
].wmep_logcwmin
<< 4) | wmep
[WME_AC_BE
].wmep_logcwmin
);
3339 rt2870_io_mac_write(sc
, RT2870_REG_SCHDMA_WMM_CWMAX_CFG
,
3340 (wmep
[WME_AC_VO
].wmep_logcwmax
<< 12) | (wmep
[WME_AC_VI
].wmep_logcwmax
<< 8) |
3341 (wmep
[WME_AC_BK
].wmep_logcwmax
<< 4) | wmep
[WME_AC_BE
].wmep_logcwmax
);
3343 rt2870_io_mac_write(sc
, RT2870_REG_SCHDMA_WMM_TXOP0_CFG
,
3344 (wmep
[WME_AC_BK
].wmep_txopLimit
<< 16) | wmep
[WME_AC_BE
].wmep_txopLimit
);
3346 rt2870_io_mac_write(sc
, RT2870_REG_SCHDMA_WMM_TXOP1_CFG
,
3347 (wmep
[WME_AC_VO
].wmep_txopLimit
<< 16) | wmep
[WME_AC_VI
].wmep_txopLimit
);
3351 * rt2870_asic_update_beacon
3353 static int rt2870_asic_update_beacon(struct rt2870_softc
*sc
)
3355 struct ieee80211com
*ic
;
3357 struct rt2870_txwi txwi
;
3363 m
= ieee80211_beacon_alloc(ic
->ic_bss
, &sc
->beacon_offsets
);
3367 rate
= IEEE80211_IS_CHAN_5GHZ(ic
->ic_curchan
) ? 12 : 2;
3368 mcs
= rt2870_rate2mcs(rate
);
3370 memset(&txwi
, 0, sizeof(struct rt2870_txwi
));
3373 txwi
.pid_mpdu_len
= ((htole16(m
->m_pkthdr
.len
) & RT2870_TXWI_MPDU_LEN_MASK
) <<
3374 RT2870_TXWI_MPDU_LEN_SHIFT
);
3375 txwi
.txop
= (RT2870_TXWI_TXOP_HT
<< RT2870_TXWI_TXOP_SHIFT
);
3376 txwi
.mpdu_density_flags
|=
3377 (RT2870_TXWI_FLAGS_TS
<< RT2870_TXWI_FLAGS_SHIFT
);
3378 txwi
.bawin_size_xflags
|=
3379 (RT2870_TXWI_XFLAGS_NSEQ
<< RT2870_TXWI_XFLAGS_SHIFT
);
3383 txwi
.phymode_ifs_stbc_shortgi
=
3384 (RT2870_TXWI_PHYMODE_CCK
<< RT2870_TXWI_PHYMODE_SHIFT
);
3386 if (rate
!= 2 && (ic
->ic_flags
& IEEE80211_F_SHPREAMBLE
))
3387 mcs
|= RT2870_TXWI_MCS_SHOTPRE
;
3391 txwi
.phymode_ifs_stbc_shortgi
=
3392 (RT2870_TXWI_PHYMODE_OFDM
<< RT2870_TXWI_PHYMODE_SHIFT
);
3395 txwi
.bw_mcs
= (RT2870_TXWI_BW_20
<< RT2870_TXWI_BW_SHIFT
) |
3396 ((mcs
& RT2870_TXWI_MCS_MASK
) << RT2870_TXWI_MCS_SHIFT
);
3398 /* disable temporarily TSF sync */
3400 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_BCN_TIME_CFG
);
3402 tmp
&= ~(RT2870_REG_BCN_TX_ENABLE
|
3403 RT2870_REG_TSF_TIMER_ENABLE
|
3404 RT2870_REG_TBTT_TIMER_ENABLE
);
3406 rt2870_io_mac_write(sc
, RT2870_REG_BCN_TIME_CFG
, tmp
);
3408 /* write Tx wireless info and beacon frame to on-chip memory */
3410 rt2870_io_mac_write_multi(sc
, RT2870_REG_BEACON_BASE(0),
3411 &txwi
, sizeof(struct rt2870_txwi
));
3413 rt2870_io_mac_write_multi(sc
, RT2870_REG_BEACON_BASE(0) + sizeof(struct rt2870_txwi
),
3414 mtod(m
, uint8_t *), m
->m_pkthdr
.len
);
3416 /* enable again TSF sync */
3418 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_BCN_TIME_CFG
);
3420 tmp
|= (RT2870_REG_BCN_TX_ENABLE
|
3421 RT2870_REG_TSF_TIMER_ENABLE
|
3422 RT2870_REG_TBTT_TIMER_ENABLE
);
3424 rt2870_io_mac_write(sc
, RT2870_REG_BCN_TIME_CFG
, tmp
);
3432 * rt2870_asic_clear_keytables
3434 static void rt2870_asic_clear_keytables(struct rt2870_softc
*sc
)
3436 /* clear Rx WCID search table (entries = 256, entry size = 8) */
3438 rt2870_io_mac_set_region_4(sc
, RT2870_REG_WCID(0), 0, 2 * 256);
3440 /* clear WCID attribute table (entries = 256, entry size = 4) */
3442 rt2870_io_mac_set_region_4(sc
, RT2870_REG_WCID_ATTR(0), 0, 256);
3444 /* clear IV/EIV table (entries = 256, entry size = 8) */
3446 rt2870_io_mac_set_region_4(sc
, RT2870_REG_IVEIV(0), 0, 2 * 256);
3448 /* clear pairwise key table (entries = 256, entry size = 32) */
3450 rt2870_io_mac_set_region_4(sc
, RT2870_REG_PKEY(0), 0, 8 * 256);
3452 /* clear shared key table (entries = 32, entry size = 32) */
3454 rt2870_io_mac_set_region_4(sc
, RT2870_REG_SKEY(0, 0), 0, 8 * 32);
3456 /* clear shared key mode (entries = 32, entry size = 2) */
3458 rt2870_io_mac_set_region_4(sc
, RT2870_REG_SKEY_MODE(0), 0, 16);
3464 static uint8_t rt2870_rxrate(struct rt2870_rxwi
*rxwi
)
3466 uint8_t mcs
, phymode
;
3469 mcs
= (rxwi
->bw_mcs
>> RT2870_RXWI_MCS_SHIFT
) & RT2870_RXWI_MCS_MASK
;
3470 phymode
= (rxwi
->phymode_stbc_shortgi
>> RT2870_RXWI_PHYMODE_SHIFT
) &
3471 RT2870_RXWI_PHYMODE_MASK
;
3477 case RT2870_RXWI_PHYMODE_CCK
:
3478 switch (mcs
& ~RT2870_RXWI_MCS_SHOTPRE
)
3480 case 0: rate
= 2; break; /* 1 Mbps */
3481 case 1: rate
= 4; break; /* 2 MBps */
3482 case 2: rate
= 11; break; /* 5.5 Mbps */
3483 case 3: rate
= 22; break; /* 11 Mbps */
3487 case RT2870_RXWI_PHYMODE_OFDM
:
3490 case 0: rate
= 12; break; /* 6 Mbps */
3491 case 1: rate
= 18; break; /* 9 Mbps */
3492 case 2: rate
= 24; break; /* 12 Mbps */
3493 case 3: rate
= 36; break; /* 18 Mbps */
3494 case 4: rate
= 48; break; /* 24 Mbps */
3495 case 5: rate
= 72; break; /* 36 Mbps */
3496 case 6: rate
= 96; break; /* 48 Mbps */
3497 case 7: rate
= 108; break; /* 54 Mbps */
3501 case RT2870_RXWI_PHYMODE_HT_MIXED
:
3502 case RT2870_RXWI_PHYMODE_HT_GF
:
3510 * rt2870_maxrssi_rxpath
3512 static uint8_t rt2870_maxrssi_rxpath(struct rt2870_softc
*sc
,
3513 const struct rt2870_rxwi
*rxwi
)
3519 if (sc
->nrxpath
> 1)
3520 if (rxwi
->rssi
[1] > rxwi
->rssi
[rxpath
])
3523 if (sc
->nrxpath
> 2)
3524 if (rxwi
->rssi
[2] > rxwi
->rssi
[rxpath
])
3533 static int8_t rt2870_rssi2dbm(struct rt2870_softc
*sc
,
3534 uint8_t rssi
, uint8_t rxpath
)
3536 struct ieee80211com
*ic
;
3537 struct ieee80211_channel
*c
;
3542 chan
= ieee80211_chan2ieee(ic
, c
);
3544 if (IEEE80211_IS_CHAN_5GHZ(c
))
3546 delta
= sc
->rssi_off_5ghz
[rxpath
];
3549 delta
-= sc
->lna_gain
[1];
3550 else if (chan
<= 128)
3551 delta
-= sc
->lna_gain
[2];
3553 delta
-= sc
->lna_gain
[3];
3557 delta
= sc
->rssi_off_2ghz
[rxpath
] - sc
->lna_gain
[0];
3560 return (-12 - delta
- rssi
);
3566 static uint8_t rt2870_rate2mcs(uint8_t rate
)
3593 static int rt2870_ackrate(struct ieee80211com
*ic
, int rate
)
3605 return (ic
->ic_curmode
== IEEE80211_MODE_11B
) ? 4 : rate
;
3624 /* default to 1Mbps */
3631 static uint16_t rt2870_txtime(int len
, int rate
, uint32_t flags
)
3635 if (RT2870_RATE_IS_OFDM(rate
))
3637 txtime
= (8 + 4 * len
+ 3 + rate
- 1) / rate
;
3638 txtime
= 16 + 4 + 4 * txtime
+ 6;
3642 txtime
= (16 * len
+ rate
- 1) / rate
;
3644 if (rate
!= 2 && (flags
& IEEE80211_F_SHPREAMBLE
))
3656 static void rt2870_rx_frame(struct rt2870_softc
*sc
,
3657 uint8_t *buf
, uint32_t dmalen
)
3659 struct ieee80211com
*ic
;
3661 struct ieee80211_frame
*wh
;
3662 struct ieee80211_node
*ni
;
3663 struct rt2870_softc_rx_radiotap_header
*tap
;
3664 struct rt2870_rxwi
*rxwi
;
3665 struct rt2870_rxinfo
*rxinfo
;
3667 uint32_t rxinfo_flags
;
3668 uint8_t cipher_err
, rssi
, ant
, phymode
, bw
, shortgi
, mcs
;
3670 int len
, ampdu
, amsdu
;
3675 /* get Rx wireless info */
3677 rxwi
= (struct rt2870_rxwi
*) buf
;
3678 len
= (le16toh(rxwi
->tid_size
) >> RT2870_RXWI_SIZE_SHIFT
) &
3679 RT2870_RXWI_SIZE_MASK
;
3683 RT2870_DPRINTF(sc
, RT2870_DEBUG_RX
,
3684 "%s: bad rxwi len: DMA len=%d, rxwi len=%d\n",
3685 device_get_nameunit(sc
->dev
), dmalen
, len
);
3691 rxinfo
= (struct rt2870_rxinfo
*) ((caddr_t
) rxwi
+ dmalen
);
3692 rxinfo_flags
= le32toh(rxinfo
->flags
);
3694 RT2870_DPRINTF(sc
, RT2870_DEBUG_RX
,
3695 "%s: Rx frame: DMA len=%d, len=%d, rxinfo flags=0x%08x\n",
3696 device_get_nameunit(sc
->dev
), dmalen
, len
, rxinfo_flags
);
3698 /* check for crc errors */
3700 if (rxinfo_flags
& RT2870_RXINFO_FLAGS_CRC_ERR
)
3702 RT2870_DPRINTF(sc
, RT2870_DEBUG_RX
,
3703 "%s: rxinfo: crc error\n",
3704 device_get_nameunit(sc
->dev
));
3708 if (!(ifp
->if_flags
& IFF_PROMISC
))
3712 wh
= (struct ieee80211_frame
*) (rxwi
+ 1);
3714 /* check for L2 padding between IEEE 802.11 frame header and body */
3716 if (rxinfo_flags
& RT2870_RXINFO_FLAGS_L2PAD
)
3718 RT2870_DPRINTF(sc
, RT2870_DEBUG_RX
,
3719 "%s: L2 padding: DMA len=%d, len=%d\n",
3720 device_get_nameunit(sc
->dev
), dmalen
, len
);
3725 m
= m_getjcl(M_DONTWAIT
, MT_DATA
, M_PKTHDR
, MJUMPAGESIZE
);
3728 sc
->rx_mbuf_alloc_errors
++;
3733 m
->m_pkthdr
.rcvif
= ifp
;
3734 m
->m_pkthdr
.len
= m
->m_len
= len
;
3736 m_copyback(m
, 0, len
, (caddr_t
) wh
);
3738 wh
= mtod(m
, struct ieee80211_frame
*);
3740 /* check for cipher errors */
3742 if (rxinfo_flags
& RT2870_RXINFO_FLAGS_DECRYPTED
)
3744 cipher_err
= ((rxinfo_flags
>> RT2870_RXINFO_FLAGS_CIPHER_ERR_SHIFT
) &
3745 RT2870_RXINFO_FLAGS_CIPHER_ERR_MASK
);
3746 if (cipher_err
== RT2870_RXINFO_FLAGS_CIPHER_ERR_NONE
)
3748 if (wh
->i_fc
[1] & IEEE80211_FC1_WEP
)
3749 wh
->i_fc
[1] &= ~IEEE80211_FC1_WEP
;
3751 m
->m_flags
|= M_WEP
;
3755 RT2870_DPRINTF(sc
, RT2870_DEBUG_RX
,
3756 "%s: rxinfo: cipher error=0x%02x\n",
3757 device_get_nameunit(sc
->dev
), cipher_err
);
3761 if (!(ifp
->if_flags
& IFF_PROMISC
))
3770 if (wh
->i_fc
[1] & IEEE80211_FC1_WEP
)
3774 if (!(ifp
->if_flags
& IFF_PROMISC
))
3782 /* check for A-MPDU */
3784 if (rxinfo_flags
& RT2870_RXINFO_FLAGS_AMPDU
)
3786 m
->m_flags
|= M_AMPDU
;
3794 ant
= rt2870_maxrssi_rxpath(sc
, rxwi
);
3795 rssi
= rxwi
->rssi
[ant
];
3796 rssi_dbm
= rt2870_rssi2dbm(sc
, rssi
, ant
);
3797 phymode
= ((rxwi
->phymode_stbc_shortgi
>> RT2870_RXWI_PHYMODE_SHIFT
) &
3798 RT2870_RXWI_PHYMODE_MASK
);
3799 bw
= ((rxwi
->bw_mcs
>> RT2870_RXWI_BW_SHIFT
) & RT2870_RXWI_BW_MASK
);
3800 shortgi
= ((rxwi
->phymode_stbc_shortgi
>> RT2870_RXWI_SHORTGI_SHIFT
) &
3801 RT2870_RXWI_SHORTGI_MASK
);
3802 mcs
= ((rxwi
->bw_mcs
>> RT2870_RXWI_MCS_SHIFT
) & RT2870_RXWI_MCS_MASK
);
3803 amsdu
= (rxinfo_flags
& RT2870_RXINFO_FLAGS_AMSDU
);
3805 if (bpf_peers_present(sc
->drvbpf
))
3809 tap
->flags
= IEEE80211_RADIOTAP_F_DATAPAD
;
3810 tap
->dbm_antsignal
= rssi_dbm
;
3811 tap
->dbm_antnoise
= RT2870_NOISE_FLOOR
;
3813 tap
->antsignal
= rssi
;
3814 tap
->chan_flags
= htole32(ic
->ic_curchan
->ic_flags
);
3815 tap
->chan_freq
= htole16(ic
->ic_curchan
->ic_freq
);
3816 tap
->chan_ieee
= ic
->ic_curchan
->ic_ieee
;
3817 tap
->chan_maxpow
= 0;
3819 if (phymode
== RT2870_RXWI_PHYMODE_CCK
|| phymode
== RT2870_RXWI_PHYMODE_OFDM
)
3820 tap
->rate
= rt2870_rxrate(rxwi
);
3822 tap
->rate
= mcs
| IEEE80211_RATE_MCS
;
3824 if (rxwi
->bw_mcs
& RT2870_RXWI_MCS_SHOTPRE
)
3825 tap
->flags
|= IEEE80211_RADIOTAP_F_SHORTPRE
;
3828 tap
->flags
|= IEEE80211_RADIOTAP_F_SHORTGI
;
3830 bpf_mtap2(sc
->drvbpf
, tap
, sc
->rxtap_len
, m
);
3833 RT2870_DPRINTF(sc
, RT2870_DEBUG_RX
,
3834 "%s: received frame: len=%d, phymode=%d, bw=%d, shortgi=%d, mcs=%d, "
3835 "ant=%d, rssi=%d/%d/%d, snr=%d/%d, wcid=0x%02x, ampdu=%d, amsdu=%d\n",
3836 device_get_nameunit(sc
->dev
),
3837 len
, phymode
, bw
, shortgi
, mcs
,
3838 ant
, rxwi
->rssi
[0], rxwi
->rssi
[1], rxwi
->rssi
[2],
3839 rxwi
->snr
[0], rxwi
->snr
[1],
3840 rxwi
->wcid
, ampdu
, amsdu
);
3842 ni
= ieee80211_find_rxnode(ic
, (struct ieee80211_frame_min
*) wh
);
3844 ieee80211_input(ic
, m
, ni
, rssi_dbm
- RT2870_NOISE_FLOOR
, RT2870_NOISE_FLOOR
, 0);
3846 ieee80211_free_node(ni
);
3852 static int rt2870_tx_frame(struct rt2870_softc
*sc
,
3853 struct mbuf
*m
, struct ieee80211_node
*ni
, int qid
)
3855 struct ieee80211com
*ic
;
3856 struct rt2870_softc_tx_ring
*ring
;
3857 struct rt2870_softc_tx_data
*data
;
3858 struct rt2870_txinfo
*txinfo
;
3859 struct rt2870_txwi
*txwi
;
3860 struct ieee80211_frame
*wh
;
3861 struct rt2870_softc_tx_radiotap_header
*tap
;
3862 u_int hdrsize
, hdrspace
;
3863 uint8_t type
, rate
, bw
, shortgi
, mcs
, pid
, wcid
;
3864 uint16_t qos
, len
, dmalen
, mpdu_len
, dur
;
3865 int hasqos
, ackrate
;
3869 ring
= &sc
->tx_ring
[qid
];
3870 data
= STAILQ_FIRST(&ring
->inactive
);
3871 STAILQ_REMOVE_HEAD(&ring
->inactive
, next
);
3872 txinfo
= (struct rt2870_txinfo
*) data
->buf
;
3873 txwi
= (struct rt2870_txwi
*) (txinfo
+ 1);
3875 wh
= mtod(m
, struct ieee80211_frame
*);
3877 type
= wh
->i_fc
[0] & IEEE80211_FC0_TYPE_MASK
;
3879 hasqos
= IEEE80211_QOS_HAS_SEQ(wh
);
3882 if (IEEE80211_HAS_ADDR4(wh
))
3883 qos
= le16toh(*(const uint16_t *)
3884 (((struct ieee80211_qosframe_addr4
*) wh
)->i_qos
));
3886 qos
= le16toh(*(const uint16_t *)
3887 (((struct ieee80211_qosframe
*) wh
)->i_qos
));
3894 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
3896 if (IEEE80211_IS_MULTICAST(wh
->i_addr1
) || type
!= IEEE80211_FC0_TYPE_DATA
)
3898 else if (ic
->ic_fixed_rate
!= IEEE80211_FIXED_RATE_NONE
)
3899 rate
= ic
->ic_fixed_rate
;
3901 rate
= ni
->ni_htrates
.rs_rates
[ni
->ni_txrate
];
3905 if (IEEE80211_IS_MULTICAST(wh
->i_addr1
) || type
!= IEEE80211_FC0_TYPE_DATA
)
3906 rate
= IEEE80211_IS_CHAN_5GHZ(ic
->ic_curchan
) ? 12 : 2;
3907 else if (ic
->ic_fixed_rate
!= IEEE80211_FIXED_RATE_NONE
)
3908 rate
= ic
->ic_fixed_rate
;
3910 rate
= ni
->ni_rates
.rs_rates
[ni
->ni_txrate
];
3913 rate
&= IEEE80211_RATE_VAL
;
3915 len
= sizeof(struct rt2870_txinfo
) + sizeof(struct rt2870_txwi
) + m
->m_pkthdr
.len
;
3917 /* align end on a 4-bytes boundary */
3919 dmalen
= (len
+ 3) & ~3;
3923 memset(txinfo
, 0, sizeof(struct rt2870_txinfo
));
3925 txinfo
->len
= htole16(dmalen
);
3927 txinfo
->qsel_flags
= (RT2870_TXINFO_QSEL_EDCA
<< RT2870_TXINFO_QSEL_SHIFT
);
3929 /* fill Tx wireless info */
3931 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
3934 mcs
= rt2870_rate2mcs(rate
);
3938 wcid
= (type
== IEEE80211_FC0_TYPE_DATA
) ?
3939 RT2870_AID2WCID(ni
->ni_associd
) : 0xff;
3941 /* calculate MPDU length without padding */
3943 hdrsize
= ieee80211_hdrsize(wh
);
3944 hdrspace
= ieee80211_hdrspace(ic
, wh
);
3945 mpdu_len
= m
->m_pkthdr
.len
- hdrspace
+ hdrsize
;
3947 memset(txwi
, 0, sizeof(struct rt2870_txwi
));
3951 txwi
->pid_mpdu_len
= ((htole16(pid
) & RT2870_TXWI_PID_MASK
) <<
3952 RT2870_TXWI_PID_SHIFT
) | ((htole16(mpdu_len
) & RT2870_TXWI_MPDU_LEN_MASK
) <<
3953 RT2870_TXWI_MPDU_LEN_SHIFT
);
3955 if ((ic
->ic_flags_ext
& (IEEE80211_FEXT_SHORTGI20
| IEEE80211_FEXT_SHORTGI40
)) &&
3956 (ni
->ni_flags
& IEEE80211_NODE_HT
))
3961 txwi
->phymode_ifs_stbc_shortgi
|=
3962 ((shortgi
& RT2870_TXWI_SHORTGI_MASK
) << RT2870_TXWI_SHORTGI_SHIFT
);
3964 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
3966 txwi
->phymode_ifs_stbc_shortgi
|=
3967 (RT2870_TXWI_PHYMODE_HT_MIXED
<< RT2870_TXWI_PHYMODE_SHIFT
);
3971 if (!RT2870_RATE_IS_OFDM(rate
))
3973 txwi
->phymode_ifs_stbc_shortgi
|=
3974 (RT2870_TXWI_PHYMODE_CCK
<< RT2870_TXWI_PHYMODE_SHIFT
);
3976 if (rate
!= 2 && (ic
->ic_flags
& IEEE80211_F_SHPREAMBLE
))
3977 mcs
|= RT2870_TXWI_MCS_SHOTPRE
;
3981 txwi
->phymode_ifs_stbc_shortgi
|=
3982 (RT2870_TXWI_PHYMODE_OFDM
<< RT2870_TXWI_PHYMODE_SHIFT
);
3986 if ((ni
->ni_flags
& IEEE80211_NODE_HT
) &&
3987 (ni
->ni_htcap
& IEEE80211_HTCAP_CHWIDTH40
))
3988 bw
= RT2870_TXWI_BW_40
;
3990 bw
= RT2870_TXWI_BW_20
;
3992 txwi
->bw_mcs
= ((bw
& RT2870_TXWI_BW_MASK
) << RT2870_TXWI_BW_SHIFT
) |
3993 ((mcs
& RT2870_TXWI_MCS_MASK
) << RT2870_TXWI_MCS_SHIFT
);
3995 if (type
!= IEEE80211_FC0_TYPE_DATA
)
3996 txwi
->txop
= (RT2870_TXWI_TXOP_BACKOFF
<< RT2870_TXWI_TXOP_SHIFT
);
3998 txwi
->txop
= (RT2870_TXWI_TXOP_HT
<< RT2870_TXWI_TXOP_SHIFT
);
4000 /* skip ACKs for multicast frames and probe responses */
4002 if (!IEEE80211_IS_MULTICAST(wh
->i_addr1
) &&
4003 ((wh
->i_fc
[0] & (IEEE80211_FC0_TYPE_MASK
| IEEE80211_FC0_SUBTYPE_MASK
)) !=
4004 (IEEE80211_FC0_TYPE_MGT
| IEEE80211_FC0_SUBTYPE_PROBE_RESP
)) &&
4005 (!hasqos
|| (qos
& IEEE80211_QOS_ACKPOLICY
) != IEEE80211_QOS_ACKPOLICY_NOACK
))
4007 txwi
->bawin_size_xflags
|=
4008 (RT2870_TXWI_XFLAGS_ACK
<< RT2870_TXWI_XFLAGS_SHIFT
);
4010 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
4012 /* preamble + plcp + signal extension */
4018 ackrate
= rt2870_ackrate(ic
, rate
);
4020 dur
= rt2870_txtime(RT2870_ACK_SIZE
, ackrate
, ic
->ic_flags
) +
4024 *(uint16_t *) wh
->i_dur
= htole16(dur
);
4027 /* ask MAC to insert timestamp into probe responses */
4029 if ((wh
->i_fc
[0] & (IEEE80211_FC0_TYPE_MASK
| IEEE80211_FC0_SUBTYPE_MASK
)) ==
4030 (IEEE80211_FC0_TYPE_MGT
| IEEE80211_FC0_SUBTYPE_PROBE_RESP
))
4031 txwi
->mpdu_density_flags
|=
4032 (RT2870_TXWI_FLAGS_TS
<< RT2870_TXWI_FLAGS_SHIFT
);
4034 if (bpf_peers_present(sc
->drvbpf
))
4038 tap
->flags
= IEEE80211_RADIOTAP_F_DATAPAD
;
4039 tap
->chan_flags
= htole32(ic
->ic_curchan
->ic_flags
);
4040 tap
->chan_freq
= htole16(ic
->ic_curchan
->ic_freq
);
4041 tap
->chan_ieee
= ic
->ic_curchan
->ic_ieee
;
4042 tap
->chan_maxpow
= 0;
4044 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
4045 tap
->rate
= mcs
| IEEE80211_RATE_MCS
;
4049 if (mcs
& RT2870_TXWI_MCS_SHOTPRE
)
4050 tap
->flags
|= IEEE80211_RADIOTAP_F_SHORTPRE
;
4053 tap
->flags
|= IEEE80211_RADIOTAP_F_SHORTGI
;
4055 if (wh
->i_fc
[1] & IEEE80211_FC1_WEP
)
4056 tap
->flags
|= IEEE80211_RADIOTAP_F_WEP
;
4058 if (wh
->i_fc
[1] & IEEE80211_FC1_WEP
)
4060 wh
->i_fc
[1] &= ~IEEE80211_FC1_WEP
;
4062 bpf_mtap2(sc
->drvbpf
, tap
, sc
->txtap_len
, m
);
4064 wh
->i_fc
[1] |= IEEE80211_FC1_WEP
;
4068 bpf_mtap2(sc
->drvbpf
, tap
, sc
->txtap_len
, m
);
4072 m_copydata(m
, 0, m
->m_pkthdr
.len
, (caddr_t
) (txwi
+ 1));
4074 RT2870_DPRINTF(sc
, RT2870_DEBUG_TX
,
4075 "%s: sending frame: qid=%d, hdrsize=%d, hdrspace=%d, len=%d, "
4076 "bw=%d, shortgi=%d, mcs=%d, wcid=0x%02x, DMA len=%d\n",
4077 device_get_nameunit(sc
->dev
),
4078 qid
, hdrsize
, hdrspace
, m
->m_pkthdr
.len
, bw
, shortgi
, mcs
, wcid
, dmalen
);
4083 STAILQ_INSERT_TAIL(&ring
->active
, data
, next
);
4086 usbd_setup_xfer(data
->xfer
, ring
->usb_pipe
, ring
, data
->buf
, len
,
4087 USBD_FORCE_SHORT_XFER
| USBD_NO_COPY
, RT2870_USB_XFER_TIMEOUT
, rt2870_tx_intr
);
4089 usbd_transfer(data
->xfer
);
4097 static int rt2870_tx_raw(struct rt2870_softc
*sc
,
4098 struct mbuf
*m
, struct ieee80211_node
*ni
,
4099 const struct ieee80211_bpf_params
*params
)
4101 RT2870_DPRINTF(sc
, RT2870_DEBUG_TX
,
4103 device_get_nameunit(sc
->dev
));
4111 static void rt2870_rx_intr(usbd_xfer_handle xfer
,
4112 usbd_private_handle priv
, usbd_status status
)
4114 struct rt2870_softc
*sc
;
4116 struct rt2870_softc_rx_ring
*ring
;
4117 struct rt2870_softc_rx_data
*data
;
4122 ring
= &sc
->rx_ring
;
4124 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
4127 RT2870_DPRINTF(sc
, RT2870_DEBUG_INTR
,
4128 "%s: Rx interrupt: %s\n",
4129 device_get_nameunit(sc
->dev
), usbd_errstr(status
));
4132 sc
->rx_interrupts
++;
4136 case USBD_NORMAL_COMPLETION
:
4137 data
= STAILQ_FIRST(&ring
->active
);
4141 STAILQ_REMOVE_HEAD(&ring
->active
, next
);
4143 KASSERT(data
->xfer
== xfer
,
4144 ("%s: Rx interrupt: invalid USB xfer\n",
4145 device_get_nameunit(sc
->dev
)));
4147 usbd_get_xfer_status(xfer
, NULL
, NULL
, &len
, NULL
);
4151 STAILQ_INSERT_TAIL(&ring
->done
, data
, next
);
4153 taskqueue_enqueue(sc
->taskqueue
, &sc
->rx_done_task
);
4156 case USBD_CANCELLED
:
4157 case USBD_NOT_STARTED
:
4161 if (status
== USBD_STALLED
)
4162 usbd_clear_endpoint_stall_async(ring
->usb_pipe
);
4164 data
= STAILQ_FIRST(&ring
->active
);
4167 STAILQ_REMOVE_HEAD(&ring
->active
, next
);
4169 STAILQ_INSERT_TAIL(&ring
->active
, data
, next
);
4171 usbd_setup_xfer(xfer
, ring
->usb_pipe
, sc
, data
->buf
,
4172 RT2870_USB_RX_BULK_BUFLEN
, USBD_SHORT_XFER_OK
| USBD_NO_COPY
,
4173 USBD_NO_TIMEOUT
, rt2870_rx_intr
);
4175 usbd_transfer(xfer
);
4184 static void rt2870_tx_intr(usbd_xfer_handle xfer
,
4185 usbd_private_handle priv
, usbd_status status
)
4187 struct rt2870_softc
*sc
;
4189 struct rt2870_softc_tx_ring
*ring
;
4190 struct rt2870_softc_tx_data
*data
;
4196 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
4199 RT2870_DPRINTF(sc
, RT2870_DEBUG_INTR
,
4200 "%s: Tx interrupt: %s\n",
4201 device_get_nameunit(sc
->dev
), usbd_errstr(status
));
4204 sc
->tx_interrupts
[ring
->qid
]++;
4208 case USBD_NORMAL_COMPLETION
:
4209 data
= STAILQ_FIRST(&ring
->active
);
4213 STAILQ_REMOVE_HEAD(&ring
->active
, next
);
4215 STAILQ_INSERT_TAIL(&ring
->done
, data
, next
);
4217 taskqueue_enqueue(sc
->taskqueue
, &sc
->tx_done_task
);
4220 case USBD_CANCELLED
:
4221 case USBD_NOT_STARTED
:
4225 data
= STAILQ_FIRST(&ring
->active
);
4228 STAILQ_REMOVE_HEAD(&ring
->active
, next
);
4230 if (data
->m
!= NULL
)
4236 if (data
->ni
!= NULL
)
4238 ieee80211_free_node(data
->ni
);
4242 STAILQ_INSERT_TAIL(&ring
->inactive
, data
, next
);
4247 printf("%s: could not transmit buffer: qid=%d, status=%s\n",
4248 device_get_nameunit(sc
->dev
), ring
->qid
, usbd_errstr(status
));
4251 ifp
->if_drv_flags
&= ~IFF_DRV_OACTIVE
;
4253 if (status
== USBD_STALLED
)
4254 usbd_clear_endpoint_stall_async(ring
->usb_pipe
);
4260 * rt2870_rx_done_task
4262 static void rt2870_rx_done_task(void *context
, int pending
)
4264 struct rt2870_softc
*sc
;
4270 RT2870_DPRINTF(sc
, RT2870_DEBUG_RX
,
4271 "%s: Rx done task\n",
4272 device_get_nameunit(sc
->dev
));
4274 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
4277 if (rt2870_rx_eof(sc
, sc
->rx_process_limit
) != 0)
4278 taskqueue_enqueue(sc
->taskqueue
, &sc
->rx_done_task
);
4282 * rt2870_tx_done_task
4284 static void rt2870_tx_done_task(void *context
, int pending
)
4286 struct rt2870_softc
*sc
;
4293 RT2870_DPRINTF(sc
, RT2870_DEBUG_TX
,
4294 "%s: Tx done task\n",
4295 device_get_nameunit(sc
->dev
));
4297 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
4300 for (i
= sc
->usb_endpoints
- 2; i
>= 0; i
--)
4301 rt2870_tx_eof(sc
, &sc
->tx_ring
[i
]);
4305 ifp
->if_drv_flags
&= ~IFF_DRV_OACTIVE
;
4309 * rt2870_periodic_task
4311 static void rt2870_periodic_task(void *context
, int pending
)
4313 struct rt2870_softc
*sc
;
4315 struct ieee80211com
*ic
;
4321 RT2870_DPRINTF(sc
, RT2870_DEBUG_PERIODIC
,
4322 "%s: periodic task: round=%lu\n",
4323 device_get_nameunit(sc
->dev
), sc
->periodic_round
);
4325 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
4328 sc
->periodic_round
++;
4330 rt2870_update_stats(sc
);
4332 if ((sc
->periodic_round
% 10) == 0)
4334 rt2870_update_raw_counters(sc
);
4336 rt2870_watchdog(sc
);
4338 if (ic
->ic_opmode
== IEEE80211_M_STA
)
4339 rt2870_amrr_update_iter_func(sc
, ic
->ic_bss
);
4341 ieee80211_iterate_nodes(&ic
->ic_sta
, rt2870_amrr_update_iter_func
, sc
);
4344 callout_reset(&sc
->periodic_ch
, hz
/ 10, rt2870_periodic
, sc
);
4350 static void rt2870_cmd_task(void *context
, int pending
)
4352 struct rt2870_softc
*sc
;
4353 struct rt2870_softc_cmd_ring
*ring
;
4354 struct rt2870_softc_cmd
*cmd
;
4357 ring
= &sc
->cmd_ring
;
4361 RT2870_SOFTC_LOCK(sc
);
4363 cmd
= STAILQ_FIRST(&ring
->active
);
4366 RT2870_SOFTC_UNLOCK(sc
);
4370 STAILQ_REMOVE_HEAD(&ring
->active
, next
);
4372 RT2870_SOFTC_UNLOCK(sc
);
4374 cmd
->cb(sc
, cmd
->data
);
4376 RT2870_SOFTC_LOCK(sc
);
4378 STAILQ_INSERT_TAIL(&ring
->inactive
, cmd
, next
);
4381 RT2870_SOFTC_UNLOCK(sc
);
4388 static int rt2870_rx_eof(struct rt2870_softc
*sc
, int limit
)
4391 struct rt2870_softc_rx_ring
*ring
;
4392 struct rt2870_softc_rx_data
*data
;
4398 ring
= &sc
->rx_ring
;
4404 RT2870_SOFTC_LOCK(sc
);
4406 data
= STAILQ_FIRST(&ring
->done
);
4409 RT2870_SOFTC_UNLOCK(sc
);
4413 STAILQ_REMOVE_HEAD(&ring
->done
, next
);
4415 RT2870_SOFTC_UNLOCK(sc
);
4420 if (len
< RT2870_RX_DESC_SIZE
)
4426 while (len
> (sizeof(uint32_t) + sizeof(struct rt2870_rxinfo
)))
4428 dmalen
= (le32toh(*(uint32_t *) buf
) & 0xffff);
4430 if (dmalen
== 0 || (dmalen
& 3) != 0)
4432 RT2870_DPRINTF(sc
, RT2870_DEBUG_RX
,
4433 "%s: bad DMA len=%u\n",
4434 device_get_nameunit(sc
->dev
), dmalen
);
4438 if ((dmalen
+ sizeof(uint32_t) + sizeof(struct rt2870_rxinfo
)) > len
)
4440 RT2870_DPRINTF(sc
, RT2870_DEBUG_RX
,
4441 "%s: bad DMA len: DMA len=%u, USB len=%d\n",
4442 device_get_nameunit(sc
->dev
),
4443 (dmalen
+ sizeof(uint32_t) + sizeof(struct rt2870_rxinfo
)), len
);
4449 rt2870_rx_frame(sc
, buf
+ sizeof(uint32_t), dmalen
);
4451 buf
+= (dmalen
+ sizeof(uint32_t) + sizeof(struct rt2870_rxinfo
));
4452 len
-= (dmalen
+ sizeof(uint32_t) + sizeof(struct rt2870_rxinfo
));
4457 RT2870_SOFTC_LOCK(sc
);
4459 STAILQ_INSERT_TAIL(&ring
->active
, data
, next
);
4461 RT2870_SOFTC_UNLOCK(sc
);
4463 usbd_setup_xfer(data
->xfer
, ring
->usb_pipe
, sc
, data
->buf
,
4464 RT2870_USB_RX_BULK_BUFLEN
, USBD_SHORT_XFER_OK
| USBD_NO_COPY
,
4465 USBD_NO_TIMEOUT
, rt2870_rx_intr
);
4467 usbd_transfer(data
->xfer
);
4472 RT2870_DPRINTF(sc
, RT2870_DEBUG_RX
,
4473 "%s: Rx eof: nframes=%d\n",
4474 device_get_nameunit(sc
->dev
), nframes
);
4476 sc
->rx_packets
+= nframes
;
4478 return (limit
== 0);
4484 static void rt2870_tx_eof(struct rt2870_softc
*sc
,
4485 struct rt2870_softc_tx_ring
*ring
)
4488 struct rt2870_softc_tx_data
*data
;
4497 RT2870_SOFTC_LOCK(sc
);
4499 data
= STAILQ_FIRST(&ring
->done
);
4502 RT2870_SOFTC_UNLOCK(sc
);
4506 STAILQ_REMOVE_HEAD(&ring
->done
, next
);
4508 RT2870_SOFTC_UNLOCK(sc
);
4512 if (data
->m
->m_flags
& M_TXCB
)
4513 ieee80211_process_callback(data
->ni
, data
->m
, 0);
4517 ieee80211_free_node(data
->ni
);
4522 RT2870_SOFTC_LOCK(sc
);
4524 STAILQ_INSERT_TAIL(&ring
->inactive
, data
, next
);
4528 RT2870_SOFTC_UNLOCK(sc
);
4533 RT2870_DPRINTF(sc
, RT2870_DEBUG_TX
,
4534 "%s: Tx eof: qid=%d, nframes=%d\n",
4535 device_get_nameunit(sc
->dev
), ring
->qid
, nframes
);
4539 * rt2870_update_stats
4541 static void rt2870_update_stats(struct rt2870_softc
*sc
)
4544 struct ieee80211com
*ic
;
4545 struct ieee80211_node
*ni
;
4549 int txcnt
, retrycnt
, failcnt
;
4554 RT2870_DPRINTF(sc
, RT2870_DEBUG_STATS
,
4555 "%s: update statistic\n",
4556 device_get_nameunit(sc
->dev
));
4558 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
4561 rt2870_drain_fifo_stats(sc
);
4563 if (ic
->ic_opmode
== IEEE80211_M_STA
)
4567 associd
= (ni
!= NULL
) ? ni
->ni_associd
: 0;
4568 wcid
= RT2870_AID2WCID(associd
);
4570 /* read and clear Tx statistic registers */
4572 rt2870_io_mac_read_multi(sc
, RT2870_REG_TX_STA_CNT0
,
4573 stacnt
, sizeof(stacnt
));
4575 txcnt
= le32toh(stacnt
[1]) & 0xffff;
4576 retrycnt
= le32toh(stacnt
[1]) >> 16;
4577 failcnt
= le32toh(stacnt
[0]) & 0xffff;
4579 RT2870_DPRINTF(sc
, RT2870_DEBUG_STATS
,
4580 "%s: update statistic: associd=0x%04x, txcnt=%d, retrycnt=%d, failcnt=%d\n",
4581 device_get_nameunit(sc
->dev
),
4582 associd
, txcnt
, retrycnt
, failcnt
);
4584 ifp
->if_oerrors
+= failcnt
;
4586 rt2870_amrr_tx_update(&sc
->amrr_node
[wcid
],
4587 txcnt
+ retrycnt
+ failcnt
, txcnt
+ retrycnt
, retrycnt
+ failcnt
);
4594 static void rt2870_watchdog(struct rt2870_softc
*sc
)
4599 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_PBF_TXRXQ_PCNT
);
4601 RT2870_DPRINTF(sc
, RT2870_DEBUG_WATCHDOG
,
4602 "%s: watchdog: TXRXQ_PCNT=0x%08x\n",
4603 device_get_nameunit(sc
->dev
), tmp
);
4605 if (((tmp
>> RT2870_REG_TX0Q_PCNT_SHIFT
) & RT2870_REG_TX0Q_PCNT_MASK
) != 0)
4607 sc
->tx_queue_not_empty
[0]++;
4609 rt2870_io_mac_write(sc
, RT2870_REG_PBF_CFG
, 0xf40012);
4611 for (ntries
= 0; ntries
< 10; ntries
++)
4613 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_PBF_TXRXQ_PCNT
);
4614 if (((tmp
>> RT2870_REG_TX0Q_PCNT_SHIFT
) & RT2870_REG_TX0Q_PCNT_MASK
) == 0)
4620 rt2870_io_mac_write(sc
, RT2870_REG_PBF_CFG
, 0xf40006);
4623 if (((tmp
>> RT2870_REG_TX1Q_PCNT_SHIFT
) & RT2870_REG_TX1Q_PCNT_MASK
) != 0)
4625 sc
->tx_queue_not_empty
[1]++;
4627 rt2870_io_mac_write(sc
, RT2870_REG_PBF_CFG
, 0xf4000a);
4629 for (ntries
= 0; ntries
< 10; ntries
++)
4631 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_PBF_TXRXQ_PCNT
);
4632 if (((tmp
>> RT2870_REG_TX1Q_PCNT_SHIFT
) & RT2870_REG_TX1Q_PCNT_MASK
) == 0)
4638 rt2870_io_mac_write(sc
, RT2870_REG_PBF_CFG
, 0xf40006);
4643 * rt2870_drain_fifo_stats
4645 static void rt2870_drain_fifo_stats(struct rt2870_softc
*sc
)
4649 uint8_t wcid
, mcs
, pid
;
4652 ifp
= sc
->ic
.ic_ifp
;
4654 /* drain Tx status FIFO (maxsize = 16) */
4656 while ((stats
= rt2870_io_mac_read(sc
, RT2870_REG_TX_STA_FIFO
)) &
4657 RT2870_REG_TX_STA_FIFO_VALID
)
4659 wcid
= (stats
>> RT2870_REG_TX_STA_FIFO_WCID_SHIFT
) &
4660 RT2870_REG_TX_STA_FIFO_WCID_MASK
;
4662 /* if no ACK was requested, no feedback is available */
4664 if (!(stats
& RT2870_REG_TX_STA_FIFO_ACK_REQ
) || wcid
== 0xff)
4667 /* update AMRR statistic */
4669 ok
= (stats
& RT2870_REG_TX_STA_FIFO_TX_OK
) ? 1 : 0;
4672 mcs
= (stats
>> RT2870_REG_TX_STA_FIFO_MCS_SHIFT
) &
4673 RT2870_REG_TX_STA_FIFO_MCS_MASK
;
4674 pid
= (stats
>> RT2870_REG_TX_STA_FIFO_PID_SHIFT
) &
4675 RT2870_REG_TX_STA_FIFO_PID_MASK
;
4677 if (!ok
|| (mcs
+ 1) != pid
)
4680 rt2870_amrr_tx_complete(&sc
->amrr_node
[wcid
],
4689 * rt2870_update_raw_counters
4691 static void rt2870_update_raw_counters(struct rt2870_softc
*sc
)
4695 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_RX_STA_CNT0
);
4697 sc
->rx_crc_errors
+= tmp
& 0xffff;
4698 sc
->rx_phy_errors
+= tmp
>> 16;
4700 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_RX_STA_CNT1
);
4702 sc
->rx_false_ccas
+= tmp
& 0xffff;
4703 sc
->rx_plcp_errors
+= tmp
>> 16;
4705 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_RX_STA_CNT2
);
4707 sc
->rx_dup_packets
+= tmp
& 0xffff;
4708 sc
->rx_fifo_overflows
+= tmp
>> 16;
4712 * rt2870_alloc_rx_ring
4714 static int rt2870_alloc_rx_ring(struct rt2870_softc
*sc
,
4715 struct rt2870_softc_rx_ring
*ring
)
4717 struct rt2870_softc_rx_data
*data
;
4720 STAILQ_INIT(&ring
->active
);
4721 STAILQ_INIT(&ring
->done
);
4723 for (i
= 0; i
< RT2870_SOFTC_RX_RING_DATA_COUNT
; i
++)
4725 data
= &ring
->data
[i
];
4727 data
->xfer
= usbd_alloc_xfer(sc
->usb_dev
);
4728 if (data
->xfer
== NULL
)
4730 printf("%s: could not allocate Rx xfer\n",
4731 device_get_nameunit(sc
->dev
));
4736 data
->buf
= usbd_alloc_buffer(data
->xfer
, RT2870_USB_RX_BULK_BUFLEN
);
4737 if (data
->buf
== NULL
)
4739 printf("%s: could not allocate Rx buffer\n",
4740 device_get_nameunit(sc
->dev
));
4750 rt2870_free_rx_ring(sc
, ring
);
4756 * rt2870_reset_rx_ring
4758 static void rt2870_reset_rx_ring(struct rt2870_softc
*sc
,
4759 struct rt2870_softc_rx_ring
*ring
)
4761 STAILQ_INIT(&ring
->active
);
4762 STAILQ_INIT(&ring
->done
);
4766 * rt2870_free_rx_ring
4768 static void rt2870_free_rx_ring(struct rt2870_softc
*sc
,
4769 struct rt2870_softc_rx_ring
*ring
)
4771 struct rt2870_softc_rx_data
*data
;
4774 for (i
= 0; i
< RT2870_SOFTC_RX_RING_DATA_COUNT
; i
++)
4776 data
= &ring
->data
[i
];
4778 if (data
->xfer
!= NULL
)
4780 usbd_free_xfer(data
->xfer
);
4787 * rt2870_alloc_tx_ring
4789 static int rt2870_alloc_tx_ring(struct rt2870_softc
*sc
,
4790 struct rt2870_softc_tx_ring
*ring
, int qid
)
4792 struct rt2870_softc_tx_data
*data
;
4795 STAILQ_INIT(&ring
->inactive
);
4796 STAILQ_INIT(&ring
->active
);
4797 STAILQ_INIT(&ring
->done
);
4803 for (i
= 0; i
< RT2870_SOFTC_TX_RING_DATA_COUNT
; i
++)
4805 data
= &ring
->data
[i
];
4807 data
->xfer
= usbd_alloc_xfer(sc
->usb_dev
);
4808 if (data
->xfer
== NULL
)
4810 printf("%s: could not allocate Tx xfer\n",
4811 device_get_nameunit(sc
->dev
));
4816 data
->buf
= usbd_alloc_buffer(data
->xfer
,
4817 RT2870_TX_DESC_SIZE
+ MJUMPAGESIZE
);
4818 if (data
->buf
== NULL
)
4820 printf("%s: could not allocate Tx buffer\n",
4821 device_get_nameunit(sc
->dev
));
4826 memset(data
->buf
, 0, RT2870_TX_DESC_SIZE
);
4828 STAILQ_INSERT_TAIL(&ring
->inactive
, data
, next
);
4835 rt2870_free_tx_ring(sc
, ring
);
4841 * rt2870_reset_tx_ring
4843 static void rt2870_reset_tx_ring(struct rt2870_softc
*sc
,
4844 struct rt2870_softc_tx_ring
*ring
)
4846 struct rt2870_softc_tx_data
*data
;
4849 STAILQ_INIT(&ring
->inactive
);
4850 STAILQ_INIT(&ring
->active
);
4851 STAILQ_INIT(&ring
->done
);
4855 for (i
= 0; i
< RT2870_SOFTC_TX_RING_DATA_COUNT
; i
++)
4857 data
= &ring
->data
[i
];
4859 if (data
->m
!= NULL
)
4865 if (data
->ni
!= NULL
)
4867 ieee80211_free_node(data
->ni
);
4871 STAILQ_INSERT_TAIL(&ring
->inactive
, data
, next
);
4876 * rt2870_free_tx_ring
4878 static void rt2870_free_tx_ring(struct rt2870_softc
*sc
,
4879 struct rt2870_softc_tx_ring
*ring
)
4881 struct rt2870_softc_tx_data
*data
;
4884 for (i
= 0; i
< RT2870_SOFTC_TX_RING_DATA_COUNT
; i
++)
4886 data
= &ring
->data
[i
];
4888 if (data
->xfer
!= NULL
)
4890 usbd_free_xfer(data
->xfer
);
4894 if (data
->m
!= NULL
)
4900 if (data
->ni
!= NULL
)
4902 ieee80211_free_node(data
->ni
);
4909 * rt2870_reset_cmd_ring
4911 static void rt2870_reset_cmd_ring(struct rt2870_softc
*sc
,
4912 struct rt2870_softc_cmd_ring
*ring
)
4914 struct rt2870_softc_cmd
*cmd
;
4917 STAILQ_INIT(&ring
->inactive
);
4918 STAILQ_INIT(&ring
->active
);
4922 for (i
= 0; i
< RT2870_SOFTC_CMD_RING_CMD_COUNT
; i
++)
4924 cmd
= &ring
->cmd
[i
];
4926 STAILQ_INSERT_TAIL(&ring
->inactive
, cmd
, next
);
4931 * rt2870_sysctl_attach
4933 static void rt2870_sysctl_attach(struct rt2870_softc
*sc
)
4935 struct sysctl_ctx_list
*ctx
;
4936 struct sysctl_oid
*tree
;
4937 struct sysctl_oid
*stats
;
4939 ctx
= device_get_sysctl_ctx(sc
->dev
);
4940 tree
= device_get_sysctl_tree(sc
->dev
);
4942 stats
= SYSCTL_ADD_NODE(ctx
, SYSCTL_CHILDREN(tree
), OID_AUTO
,
4943 "stats", CTLFLAG_RD
, 0, "statistic");
4945 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
4946 "interrupts", CTLFLAG_RD
, &sc
->interrupts
, 0,
4949 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
4950 "rx_interrupts", CTLFLAG_RD
, &sc
->rx_interrupts
, 0,
4953 if (sc
->usb_endpoints
== (RT2870_SOFTC_TX_RING_COUNT
+ 1))
4955 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
4956 "tx_mgmt_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[5], 0,
4957 "Tx MGMT interrupts");
4959 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
4960 "tx_hcca_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[4], 0,
4961 "Tx HCCA interrupts");
4964 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
4965 "tx_ac3_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[3], 0,
4966 "Tx AC3 interrupts");
4968 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
4969 "tx_ac2_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[2], 0,
4970 "Tx AC2 interrupts");
4972 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
4973 "tx_ac1_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[1], 0,
4974 "Tx AC1 interrupts");
4976 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
4977 "tx_ac0_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[0], 0,
4978 "Tx AC0 interrupts");
4980 if (sc
->usb_endpoints
== (RT2870_SOFTC_TX_RING_COUNT
+ 1))
4982 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
4983 "tx_mgmt_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[5].queued
, 0,
4984 "Tx MGMT data queued");
4986 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
4987 "tx_hcca_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[4].queued
, 0,
4988 "Tx HCCA data queued");
4991 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
4992 "tx_ac3_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[3].queued
, 0,
4993 "Tx AC3 data queued");
4995 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
4996 "tx_ac2_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[2].queued
, 0,
4997 "Tx AC2 data queued");
4999 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5000 "tx_ac1_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[1].queued
, 0,
5001 "Tx AC1 data queued");
5003 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5004 "tx_ac0_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[0].queued
, 0,
5005 "Tx AC0 data queued");
5007 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5008 "tx_watchdog_timeouts", CTLFLAG_RD
, &sc
->tx_watchdog_timeouts
, 0,
5009 "Tx watchdog timeouts");
5011 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5012 "rx_mbuf_alloc_errors", CTLFLAG_RD
, &sc
->rx_mbuf_alloc_errors
, 0,
5013 "Rx mbuf allocation errors");
5015 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5016 "tx_queue_0_not_empty", CTLFLAG_RD
, &sc
->tx_queue_not_empty
[0], 0,
5017 "Tx queue 0 not empty");
5019 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5020 "tx_queue_1_not_empty", CTLFLAG_RD
, &sc
->tx_queue_not_empty
[1], 0,
5021 "Tx queue 1 not empty");
5023 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5024 "rx_packets", CTLFLAG_RD
, &sc
->rx_packets
, 0,
5027 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5028 "rx_crc_errors", CTLFLAG_RD
, &sc
->rx_crc_errors
, 0,
5031 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5032 "rx_phy_errors", CTLFLAG_RD
, &sc
->rx_phy_errors
, 0,
5035 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5036 "rx_false_ccas", CTLFLAG_RD
, &sc
->rx_false_ccas
, 0,
5039 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5040 "rx_plcp_errors", CTLFLAG_RD
, &sc
->rx_plcp_errors
, 0,
5043 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5044 "rx_dup_packets", CTLFLAG_RD
, &sc
->rx_dup_packets
, 0,
5045 "Rx duplicate packets");
5047 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5048 "rx_fifo_overflows", CTLFLAG_RD
, &sc
->rx_fifo_overflows
, 0,
5049 "Rx FIFO overflows");
5052 static device_method_t rt2870_dev_methods
[] =
5054 DEVMETHOD(device_probe
, rt2870_probe
),
5055 DEVMETHOD(device_attach
, rt2870_attach
),
5056 DEVMETHOD(device_detach
, rt2870_detach
),
5060 static driver_t rt2870_driver
=
5064 sizeof(struct rt2870_softc
),
5067 static devclass_t rt2870_dev_class
;
5069 DRIVER_MODULE(rt2870
, uhub
, rt2870_driver
, rt2870_dev_class
,
5070 usbd_driver_load
, 0);
5072 MODULE_DEPEND(rt2870
, usb
, 1, 1, 1);
5073 MODULE_DEPEND(rt2870
, wlan
, 1, 1, 1);