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_txinfo.h"
26 #include "rt2870_txwi.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_INDEX 0
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_ACK_SIZE 14
66 #define IEEE80211_HAS_ADDR4(wh) \
67 (((wh)->i_fc[1] & IEEE80211_FC1_DIR_MASK) == IEEE80211_FC1_DIR_DSTODS)
69 #define RT2870_MS(_v, _f) (((_v) & _f) >> _f##_S)
70 #define RT2870_SM(_v, _f) (((_v) << _f##_S) & _f)
72 #define RT2870_USB_XFER_TIMEOUT 5000
74 #define RT2870_TX_WATCHDOG_TIMEOUT 5
76 #define RT2870_WCID_RESERVED 0xff
77 #define RT2870_WCID_MCAST 0xf7
80 * Data structures and types
83 struct rt2870_cmd_argv_nodecleanup
88 struct rt2870_cmd_argv_keyset
90 enum ieee80211_opmode opmode
;
91 struct ieee80211_key key
;
95 struct rt2870_cmd_argv_keydelete
97 enum ieee80211_opmode opmode
;
98 struct ieee80211_key key
;
102 * Static function prototypes
105 static void rt2870_init_channels(struct rt2870_softc
*sc
);
107 static void rt2870_init_channels_ht40(struct rt2870_softc
*sc
);
109 static void rt2870_init_locked(void *priv
);
111 static void rt2870_init(void *priv
);
113 static int rt2870_init_bbp(struct rt2870_softc
*sc
);
115 static void rt2870_stop_locked(void *priv
);
117 static void rt2870_stop(void *priv
);
119 static void rt2870_start(struct ifnet
*ifp
);
121 static int rt2870_ioctl(struct ifnet
*ifp
, u_long cmd
, caddr_t data
);
123 static struct ieee80211vap
*rt2870_vap_create(struct ieee80211com
*ic
,
124 const char name
[IFNAMSIZ
], int unit
, int opmode
, int flags
,
125 const uint8_t bssid
[IEEE80211_ADDR_LEN
],
126 const uint8_t mac
[IEEE80211_ADDR_LEN
]);
128 static void rt2870_vap_delete(struct ieee80211vap
*vap
);
130 static int rt2870_vap_reset(struct ieee80211vap
*vap
, u_long cmd
);
132 static int rt2870_vap_newstate(struct ieee80211vap
*vap
,
133 enum ieee80211_state nstate
, int arg
);
135 static void rt2870_vap_key_update_begin(struct ieee80211vap
*vap
);
137 static void rt2870_vap_key_update_end(struct ieee80211vap
*vap
);
139 static int rt2870_vap_key_set(struct ieee80211vap
*vap
,
140 const struct ieee80211_key
*k
, const uint8_t mac
[IEEE80211_ADDR_LEN
]);
142 static int rt2870_vap_key_delete(struct ieee80211vap
*vap
,
143 const struct ieee80211_key
*k
);
145 static void rt2870_vap_update_beacon(struct ieee80211vap
*vap
, int what
);
147 static struct ieee80211_node
*rt2870_node_alloc(struct ieee80211vap
*vap
,
148 const uint8_t mac
[IEEE80211_ADDR_LEN
]);
150 static void rt2870_node_cleanup(struct ieee80211_node
*ni
);
152 static void rt2870_node_getmimoinfo(const struct ieee80211_node
*ni
,
153 struct ieee80211_mimo_info
*mi
);
155 static int rt2870_setregdomain(struct ieee80211com
*ic
,
156 struct ieee80211_regdomain
*reg
,
157 int nchans
, struct ieee80211_channel chans
[]);
159 static void rt2870_getradiocaps(struct ieee80211com
*ic
,
160 int maxchans
, int *nchans
, struct ieee80211_channel chans
[]);
162 static void rt2870_scan_start(struct ieee80211com
*ic
);
164 static void rt2870_scan_end(struct ieee80211com
*ic
);
166 static void rt2870_set_channel(struct ieee80211com
*ic
);
168 static void rt2870_newassoc(struct ieee80211_node
*ni
, int isnew
);
170 static void rt2870_updateslot(struct ifnet
*ifp
);
172 static void rt2870_update_promisc(struct ifnet
*ifp
);
174 static void rt2870_update_mcast(struct ifnet
*ifp
);
176 static int rt2870_wme_update(struct ieee80211com
*ic
);
178 static int rt2870_raw_xmit(struct ieee80211_node
*ni
, struct mbuf
*m
,
179 const struct ieee80211_bpf_params
*params
);
181 static int rt2870_recv_action(struct ieee80211_node
*ni
,
182 const struct ieee80211_frame
*wh
,
183 const uint8_t *frm
, const uint8_t *efrm
);
185 static int rt2870_send_action(struct ieee80211_node
*ni
,
186 int cat
, int act
, void *sa
);
188 static void rt2870_amrr_update_iter_func(void *arg
, struct ieee80211_node
*ni
);
190 static void rt2870_periodic(void *arg
);
192 static void rt2870_tx_watchdog(void *arg
);
194 static int rt2870_staid_alloc(struct rt2870_softc
*sc
, int aid
);
196 static void rt2870_staid_delete(struct rt2870_softc
*sc
, int staid
);
198 static int rt2870_do_async(struct rt2870_softc
*sc
,
199 void (*cb
)(struct rt2870_softc
*sc
, void *arg
),
202 static void rt2870_node_cleanup_cb(struct rt2870_softc
*sc
, void *arg
);
204 static void rt2870_updateslot_cb(struct rt2870_softc
*sc
, void *arg
);
206 static void rt2870_wme_update_cb(struct rt2870_softc
*sc
, void *arg
);
208 static void rt2870_vap_key_set_cb(struct rt2870_softc
*sc
, void *arg
);
210 static void rt2870_vap_key_delete_cb(struct rt2870_softc
*sc
, void *arg
);
212 static void rt2870_vap_update_beacon_cb(struct rt2870_softc
*sc
, void *arg
);
214 static void rt2870_asic_set_bssid(struct rt2870_softc
*sc
,
215 const uint8_t *bssid
);
217 static void rt2870_asic_set_macaddr(struct rt2870_softc
*sc
,
218 const uint8_t *addr
);
220 static void rt2870_asic_enable_tsf_sync(struct rt2870_softc
*sc
);
222 static void rt2870_asic_disable_tsf_sync(struct rt2870_softc
*sc
);
224 static void rt2870_asic_enable_mrr(struct rt2870_softc
*sc
);
226 static void rt2870_asic_set_txpreamble(struct rt2870_softc
*sc
);
228 static void rt2870_asic_set_basicrates(struct rt2870_softc
*sc
);
230 static void rt2870_asic_update_rtsthreshold(struct rt2870_softc
*sc
);
232 static void rt2870_asic_update_txpower(struct rt2870_softc
*sc
);
234 static void rt2870_asic_update_promisc(struct rt2870_softc
*sc
);
236 static void rt2870_asic_updateprot(struct rt2870_softc
*sc
);
238 static void rt2870_asic_updateslot(struct rt2870_softc
*sc
);
240 static void rt2870_asic_wme_update(struct rt2870_softc
*sc
);
242 static void rt2870_asic_update_beacon(struct rt2870_softc
*sc
,
243 struct ieee80211vap
*vap
);
245 static void rt2870_asic_clear_keytables(struct rt2870_softc
*sc
);
247 static int rt2870_beacon_alloc(struct rt2870_softc
*sc
,
248 struct ieee80211vap
*vap
);
250 static uint8_t rt2870_rxrate(struct rt2870_rxwi
*rxwi
);
252 static uint8_t rt2870_maxrssi_rxpath(struct rt2870_softc
*sc
,
253 const struct rt2870_rxwi
*rxwi
);
255 static int8_t rt2870_rssi2dbm(struct rt2870_softc
*sc
,
256 uint8_t rssi
, uint8_t rxpath
);
258 static uint8_t rt2870_rate2mcs(uint8_t rate
);
260 static void rt2870_rx_frame(struct rt2870_softc
*sc
,
261 uint8_t *buf
, uint32_t dmalen
);
263 static int rt2870_tx_mgmt(struct rt2870_softc
*sc
,
264 struct mbuf
*m
, struct ieee80211_node
*ni
, int qid
);
266 static int rt2870_tx_data(struct rt2870_softc
*sc
,
267 struct mbuf
*m
, struct ieee80211_node
*ni
, int qid
);
269 static int rt2870_tx_raw(struct rt2870_softc
*sc
,
270 struct mbuf
*m
, struct ieee80211_node
*ni
,
271 const struct ieee80211_bpf_params
*params
);
273 static void rt2870_rx_intr(struct usb_xfer
*xfer
, usb_error_t error
);
275 static void rt2870_tx_intr(struct usb_xfer
*xfer
, usb_error_t error
);
277 static void rt2870_rx_done_task(void *context
, int pending
);
279 static void rt2870_tx_done_task(void *context
, int pending
);
281 static void rt2870_periodic_task(void *context
, int pending
);
283 static void rt2870_cmd_task(void *context
, int pending
);
285 static int rt2870_rx_eof(struct rt2870_softc
*sc
, int limit
);
287 static void rt2870_tx_eof(struct rt2870_softc
*sc
,
288 struct rt2870_softc_tx_ring
*ring
);
290 static void rt2870_update_stats(struct rt2870_softc
*sc
);
292 static void rt2870_bbp_tuning(struct rt2870_softc
*sc
);
294 static void rt2870_watchdog(struct rt2870_softc
*sc
);
296 static void rt2870_drain_fifo_stats(struct rt2870_softc
*sc
);
298 static void rt2870_update_raw_counters(struct rt2870_softc
*sc
);
300 static int rt2870_txrx_enable(struct rt2870_softc
*sc
);
302 static int rt2870_alloc_rx_ring(struct rt2870_softc
*sc
,
303 struct rt2870_softc_rx_ring
*ring
);
305 static void rt2870_reset_rx_ring(struct rt2870_softc
*sc
,
306 struct rt2870_softc_rx_ring
*ring
);
308 static void rt2870_free_rx_ring(struct rt2870_softc
*sc
,
309 struct rt2870_softc_rx_ring
*ring
);
311 static int rt2870_alloc_tx_ring(struct rt2870_softc
*sc
,
312 struct rt2870_softc_tx_ring
*ring
, int qid
);
314 static void rt2870_reset_tx_ring(struct rt2870_softc
*sc
,
315 struct rt2870_softc_tx_ring
*ring
);
317 static void rt2870_free_tx_ring(struct rt2870_softc
*sc
,
318 struct rt2870_softc_tx_ring
*ring
);
320 static void rt2870_reset_cmd_ring(struct rt2870_softc
*sc
,
321 struct rt2870_softc_cmd_ring
*ring
);
323 static void rt2870_sysctl_attach(struct rt2870_softc
*sc
);
329 static const struct usb_device_id rt2870_usb_devid
[] =
331 { USB_VP(USB_VENDOR_LINKSYS4
, USB_PRODUCT_LINKSYS4_WUSB600N
) }, /* Linksys WUSB600N */
332 { USB_VP(USB_VENDOR_DLINK2
, USB_PRODUCT_DLINK2_DWA140
) }, /* D-Link DWA-140 */
333 { USB_VP(USB_VENDOR_DLINK2
, USB_PRODUCT_DLINK2_DWA160AREVB
) }, /* D-Link DWA-160A Rev. B */
334 { USB_VP(USB_VENDOR_ASUS
, USB_PRODUCT_ASUS_RT2770F
) }, /* Asus RT2770F */
335 { USB_VP(USB_VENDOR_RALINK
, USB_PRODUCT_RALINK_RT2770
) }, /* Ralink RT2770 */
338 static const struct usb_config rt2870_usb_config
[RT2870_SOFTC_USB_XFER_COUNT
] =
343 .direction
= UE_DIR_IN
,
344 .bufsize
= RT2870_USB_RX_BULK_BUFLEN
,
345 .flags
= { .ext_buffer
= 1, .pipe_bof
= 1, .short_xfer_ok
= 1, },
346 .callback
= rt2870_rx_intr
,
351 .direction
= UE_DIR_OUT
,
352 .bufsize
= (RT2870_TX_DESC_SIZE
+ MJUMPAGESIZE
),
353 .flags
= { .ext_buffer
= 1, .pipe_bof
= 1, .force_short_xfer
= 1, },
354 .callback
= rt2870_tx_intr
,
355 .timeout
= RT2870_USB_XFER_TIMEOUT
,
360 .direction
= UE_DIR_OUT
,
361 .bufsize
= (RT2870_TX_DESC_SIZE
+ MJUMPAGESIZE
),
362 .flags
= { .ext_buffer
= 1, .pipe_bof
= 1, .force_short_xfer
= 1, },
363 .callback
= rt2870_tx_intr
,
364 .timeout
= RT2870_USB_XFER_TIMEOUT
,
369 .direction
= UE_DIR_OUT
,
370 .bufsize
= (RT2870_TX_DESC_SIZE
+ MJUMPAGESIZE
),
371 .flags
= { .ext_buffer
= 1, .pipe_bof
= 1, .force_short_xfer
= 1, },
372 .callback
= rt2870_tx_intr
,
373 .timeout
= RT2870_USB_XFER_TIMEOUT
,
378 .direction
= UE_DIR_OUT
,
379 .bufsize
= (RT2870_TX_DESC_SIZE
+ MJUMPAGESIZE
),
380 .flags
= { .ext_buffer
= 1, .pipe_bof
= 1, .force_short_xfer
= 1, },
381 .callback
= rt2870_tx_intr
,
382 .timeout
= RT2870_USB_XFER_TIMEOUT
,
387 .direction
= UE_DIR_OUT
,
388 .bufsize
= (RT2870_TX_DESC_SIZE
+ MJUMPAGESIZE
),
389 .flags
= { .ext_buffer
= 1, .pipe_bof
= 1, .force_short_xfer
= 1, },
390 .callback
= rt2870_tx_intr
,
391 .timeout
= RT2870_USB_XFER_TIMEOUT
,
396 .direction
= UE_DIR_OUT
,
397 .bufsize
= (RT2870_TX_DESC_SIZE
+ MJUMPAGESIZE
),
398 .flags
= { .ext_buffer
= 1, .pipe_bof
= 1, .force_short_xfer
= 1, },
399 .callback
= rt2870_tx_intr
,
400 .timeout
= RT2870_USB_XFER_TIMEOUT
,
410 { RT2870_REG_PBF_BCN_OFFSET0
, 0xf8f0e8e0 },
411 { RT2870_REG_PBF_BCN_OFFSET1
, 0x6f77d0c8 },
412 { RT2870_REG_LEGACY_BASIC_RATE
, 0x0000013f },
413 { RT2870_REG_HT_BASIC_RATE
, 0x00008003 },
414 { RT2870_REG_SYS_CTRL
, 0x00000000 },
415 { RT2870_REG_RX_FILTER_CFG
, 0x00017f97 },
416 { RT2870_REG_BKOFF_SLOT_CFG
, 0x00000209 },
417 { RT2870_REG_TX_SW_CFG0
, 0x00000000 },
418 { RT2870_REG_TX_SW_CFG1
, 0x00080606 },
419 { RT2870_REG_TX_LINK_CFG
, 0x00001020 },
420 { RT2870_REG_TX_TIMEOUT_CFG
, 0x000a2090 },
421 { RT2870_REG_MAX_LEN_CFG
, (1 << 12) | RT2870_MAX_AGG_SIZE
},
422 { RT2870_REG_LED_CFG
, 0x7f031e46 },
423 { RT2870_REG_PBF_MAX_PCNT
, 0x1f3fbf9f },
424 { RT2870_REG_TX_RTY_CFG
, 0x47d01f0f },
425 { RT2870_REG_AUTO_RSP_CFG
, 0x00000013 },
426 { RT2870_REG_TX_CCK_PROT_CFG
, 0x05740003 },
427 { RT2870_REG_TX_OFDM_PROT_CFG
, 0x05740003 },
428 { RT2870_REG_PBF_CFG
, 0x00f40006 },
429 { RT2870_REG_TX_MM40_PROT_CFG
, 0x03f44084 },
430 { RT2870_REG_SCHDMA_WPDMA_GLO_CFG
, 0x00000030 },
431 { RT2870_REG_TX_GF20_PROT_CFG
, 0x01744004 },
432 { RT2870_REG_TX_GF40_PROT_CFG
, 0x03f44084 },
433 { RT2870_REG_TX_MM20_PROT_CFG
, 0x01744004 },
434 { RT2870_REG_TX_TXOP_CTRL_CFG
, 0x0000583f },
435 { RT2870_REG_TX_RTS_CFG
, 0x00092b20 },
436 { RT2870_REG_TX_EXP_ACK_TIME
, 0x002400ca },
437 { RT2870_REG_HCCAPSMP_TXOP_HLDR_ET
, 0x00000002 },
438 { RT2870_REG_XIFS_TIME_CFG
, 0x33a41010 },
439 { RT2870_REG_PWR_PIN_CFG
, 0x00000003 },
440 { RT2870_REG_SCHDMA_WMM_AIFSN_CFG
, 0x00002273 },
441 { RT2870_REG_SCHDMA_WMM_CWMIN_CFG
, 0x00002344 },
442 { RT2870_REG_SCHDMA_WMM_CWMAX_CFG
, 0x000034aa },
445 #define RT2870_DEF_MAC_SIZE (sizeof(rt2870_def_mac) / sizeof(rt2870_def_mac[0]))
470 #define RT2870_DEF_BBP_SIZE (sizeof(rt2870_def_bbp) / sizeof(rt2870_def_bbp[0]))
472 SYSCTL_NODE(_hw
, OID_AUTO
, rt2870
, CTLFLAG_RD
, 0, "RT2870 driver parameters");
475 static int rt2870_debug
= 0;
476 SYSCTL_INT(_hw_rt2870
, OID_AUTO
, debug
, CTLFLAG_RW
, &rt2870_debug
, 0, "rt2870 debug level");
477 TUNABLE_INT("hw.rt2870.debug", &rt2870_debug
);
483 static int rt2870_probe(device_t dev
)
485 struct usb_attach_arg
*uaa
;
487 uaa
= device_get_ivars(dev
);
489 if (uaa
->usb_mode
!= USB_MODE_HOST
)
492 if (uaa
->info
.bConfigIndex
!= RT2870_USB_CONFIG_INDEX
)
495 if (uaa
->info
.bIfaceIndex
!= RT2870_USB_IFACE_INDEX
)
498 return (usbd_lookup_id_by_uaa(rt2870_usb_devid
,
499 sizeof(rt2870_usb_devid
), uaa
));
505 static int rt2870_attach(device_t dev
)
507 struct rt2870_softc
*sc
;
508 struct usb_attach_arg
*uaa
;
509 usb_error_t usb_error
;
510 struct ieee80211com
*ic
;
512 struct usb_interface
*iface
;
513 struct usb_interface_descriptor
*iface_desc
;
515 int error
, ntries
, i
;
517 sc
= device_get_softc(dev
);
518 uaa
= device_get_ivars(dev
);
521 sc
->usb_dev
= uaa
->device
;
523 device_set_usb_desc(dev
);
526 sc
->debug
= rt2870_debug
;
528 SYSCTL_ADD_INT(device_get_sysctl_ctx(dev
),
529 SYSCTL_CHILDREN(device_get_sysctl_tree(dev
)), OID_AUTO
,
530 "debug", CTLFLAG_RW
, &sc
->debug
, 0, "rt2870 debug level");
533 RT2870_DPRINTF(sc
, RT2870_DEBUG_ANY
,
535 device_get_nameunit(sc
->dev
));
537 iface_index
= RT2870_USB_IFACE_INDEX
;
539 iface
= usbd_get_iface(uaa
->device
, iface_index
);
542 printf("%s: could not get USB interface\n",
543 device_get_nameunit(sc
->dev
));
547 iface_desc
= usbd_get_interface_descriptor(iface
);
548 if (iface_desc
== NULL
)
550 printf("%s: could not get USB interface descriptor\n",
551 device_get_nameunit(sc
->dev
));
555 sc
->usb_endpoints
= iface_desc
->bNumEndpoints
;
556 if ((sc
->usb_endpoints
!= RT2870_SOFTC_USB_XFER_COUNT
) &&
557 (sc
->usb_endpoints
!= RT2870_SOFTC_USB_XFER_COUNT
- 2))
559 printf("%s: wrong number of USB endpoints=%d\n",
560 device_get_nameunit(sc
->dev
), sc
->usb_endpoints
);
564 mtx_init(&sc
->lock
, device_get_nameunit(dev
),
565 MTX_NETWORK_LOCK
, MTX_DEF
);
567 usb_error
= usbd_transfer_setup(uaa
->device
, &iface_index
,
568 sc
->usb_xfer
, rt2870_usb_config
, sc
->usb_endpoints
,
572 printf("%s: could not allocate USB transfers: error=%s\n",
573 device_get_nameunit(sc
->dev
), usbd_errstr(usb_error
));
578 sc
->flags
|= RT2870_SOFTC_FLAGS_VALID
;
580 RT2870_SOFTC_LOCK(sc
);
582 for (ntries
= 0; ntries
< 100; ntries
++)
584 sc
->mac_rev
= rt2870_io_mac_read(sc
, RT2870_REG_MAC_CSR0
);
585 if (sc
->mac_rev
!= 0x00000000 && sc
->mac_rev
!= 0xffffffff)
593 printf("%s: timeout waiting for NIC to initialize\n",
594 device_get_nameunit(sc
->dev
));
599 rt2870_read_eeprom(sc
);
601 RT2870_SOFTC_UNLOCK(sc
);
603 printf("%s: MAC/BBP RT2870 (rev 0x%08x), RF %s\n",
604 device_get_nameunit(sc
->dev
), sc
->mac_rev
,
605 rt2870_rf_name(sc
->rf_rev
));
607 RT2870_SOFTC_LOCK(sc
);
609 /* clear key tables */
611 rt2870_asic_clear_keytables(sc
);
613 RT2870_SOFTC_UNLOCK(sc
);
615 /* allocate Tx and Rx rings */
617 for (i
= 0; i
< sc
->usb_endpoints
- 1; i
++)
619 error
= rt2870_alloc_tx_ring(sc
, &sc
->tx_ring
[i
], i
);
622 printf("%s: could not allocate Tx ring #%d\n",
623 device_get_nameunit(sc
->dev
), i
);
628 if (sc
->usb_endpoints
== RT2870_SOFTC_USB_XFER_COUNT
)
629 sc
->tx_ring_mgtqid
= 5;
631 sc
->tx_ring_mgtqid
= 0;
633 error
= rt2870_alloc_rx_ring(sc
, &sc
->rx_ring
);
636 printf("%s: could not allocate Rx ring\n",
637 device_get_nameunit(sc
->dev
));
641 callout_init(&sc
->periodic_ch
, 0);
642 callout_init_mtx(&sc
->tx_watchdog_ch
, &sc
->lock
, 0);
644 ifp
= sc
->ifp
= if_alloc(IFT_IEEE80211
);
647 printf("%s: could not if_alloc()\n",
648 device_get_nameunit(sc
->dev
));
655 if_initname(ifp
, "rt2870", device_get_unit(sc
->dev
));
657 ifp
->if_flags
= IFF_BROADCAST
| IFF_SIMPLEX
| IFF_MULTICAST
;
659 ifp
->if_init
= rt2870_init
;
660 ifp
->if_ioctl
= rt2870_ioctl
;
661 ifp
->if_start
= rt2870_start
;
663 IFQ_SET_MAXLEN(&ifp
->if_snd
, IFQ_MAXLEN
);
664 ifp
->if_snd
.ifq_drv_maxlen
= IFQ_MAXLEN
;
665 IFQ_SET_READY(&ifp
->if_snd
);
671 ic
->ic_phytype
= IEEE80211_T_HT
;
672 ic
->ic_opmode
= IEEE80211_M_STA
;
674 ic
->ic_caps
= IEEE80211_C_MONITOR
|
683 IEEE80211_C_SHPREAMBLE
|
690 ic
->ic_cryptocaps
|= IEEE80211_CRYPTO_WEP
|
691 IEEE80211_CRYPTO_TKIP
|
692 IEEE80211_CRYPTO_TKIPMIC
|
693 IEEE80211_CRYPTO_AES_CCM
;
695 ic
->ic_htcaps
= IEEE80211_HTC_HT
|
696 IEEE80211_HTC_AMSDU
| /* A-MSDU Tx */
697 IEEE80211_HTC_AMPDU
| /* A-MPDU Tx */
698 IEEE80211_HTC_SMPS
| /* MIMO power save */
699 IEEE80211_HTCAP_MAXAMSDU_3839
| /* max. A-MSDU Rx length */
700 IEEE80211_HTCAP_CHWIDTH40
| /* HT 40MHz channel width */
701 IEEE80211_HTCAP_GREENFIELD
| /* HT greenfield */
702 IEEE80211_HTCAP_SHORTGI20
| /* HT 20MHz short GI */
703 IEEE80211_HTCAP_SHORTGI40
| /* HT 40MHz short GI */
704 IEEE80211_HTCAP_SMPS_OFF
; /* MIMO power save disabled */
706 /* spatial streams */
708 if (sc
->nrxpath
== 2)
709 ic
->ic_htcaps
|= IEEE80211_HTCAP_RXSTBC_2STREAM
;
710 else if (sc
->nrxpath
== 3)
711 ic
->ic_htcaps
|= IEEE80211_HTCAP_RXSTBC_3STREAM
;
713 ic
->ic_htcaps
|= IEEE80211_HTCAP_RXSTBC_1STREAM
;
716 ic
->ic_htcaps
|= IEEE80211_HTCAP_TXSTBC
;
720 if (sc
->mac_rev
!= 0x28600100)
721 ic
->ic_htcaps
|= IEEE80211_HTCAP_DELBA
;
727 rt2870_init_channels(sc
);
729 rt2870_init_channels_ht40(sc
);
731 ieee80211_ifattach(ic
, sc
->mac_addr
);
733 ic
->ic_vap_create
= rt2870_vap_create
;
734 ic
->ic_vap_delete
= rt2870_vap_delete
;
736 ic
->ic_node_alloc
= rt2870_node_alloc
;
738 sc
->node_cleanup
= ic
->ic_node_cleanup
;
739 ic
->ic_node_cleanup
= rt2870_node_cleanup
;
741 ic
->ic_node_getmimoinfo
= rt2870_node_getmimoinfo
;
742 ic
->ic_setregdomain
= rt2870_setregdomain
;
743 ic
->ic_getradiocaps
= rt2870_getradiocaps
;
744 ic
->ic_scan_start
= rt2870_scan_start
;
745 ic
->ic_scan_end
= rt2870_scan_end
;
746 ic
->ic_set_channel
= rt2870_set_channel
;
747 ic
->ic_newassoc
= rt2870_newassoc
;
748 ic
->ic_updateslot
= rt2870_updateslot
;
749 ic
->ic_update_promisc
= rt2870_update_promisc
;
750 ic
->ic_update_mcast
= rt2870_update_mcast
;
751 ic
->ic_wme
.wme_update
= rt2870_wme_update
;
752 ic
->ic_raw_xmit
= rt2870_raw_xmit
;
754 sc
->recv_action
= ic
->ic_recv_action
;
755 ic
->ic_recv_action
= rt2870_recv_action
;
757 sc
->send_action
= ic
->ic_send_action
;
758 ic
->ic_send_action
= rt2870_send_action
;
760 /* hardware requires padding between 802.11 frame header and body */
762 ic
->ic_flags
|= IEEE80211_F_DATAPAD
| IEEE80211_F_DOTH
;
764 ic
->ic_flags_ext
|= IEEE80211_FEXT_SWBMISS
;
766 ieee80211_radiotap_attach(ic
,
767 &sc
->txtap
.ihdr
, sizeof(sc
->txtap
),
768 RT2870_SOFTC_TX_RADIOTAP_PRESENT
,
769 &sc
->rxtap
.ihdr
, sizeof(sc
->rxtap
),
770 RT2870_SOFTC_RX_RADIOTAP_PRESENT
);
772 /* init task queue */
774 TASK_INIT(&sc
->rx_done_task
, 0, rt2870_rx_done_task
, sc
);
775 TASK_INIT(&sc
->tx_done_task
, 0, rt2870_tx_done_task
, sc
);
776 TASK_INIT(&sc
->periodic_task
, 0, rt2870_periodic_task
, sc
);
777 TASK_INIT(&sc
->cmd_task
, 0, rt2870_cmd_task
, sc
);
779 sc
->rx_process_limit
= 100;
781 sc
->taskqueue
= taskqueue_create("rt2870_taskq", M_NOWAIT
,
782 taskqueue_thread_enqueue
, &sc
->taskqueue
);
784 taskqueue_start_threads(&sc
->taskqueue
, 1, PI_NET
, "%s taskq",
785 device_get_nameunit(sc
->dev
));
787 rt2870_reset_cmd_ring(sc
, &sc
->cmd_ring
);
789 rt2870_sysctl_attach(sc
);
792 ieee80211_announce(ic
);
798 /* stop all USB transfers */
800 usbd_transfer_unsetup(sc
->usb_xfer
, sc
->usb_endpoints
);
802 /* free Tx and Rx rings */
804 for (i
= 0; i
< sc
->usb_endpoints
- 1; i
++)
805 rt2870_free_tx_ring(sc
, &sc
->tx_ring
[i
]);
807 rt2870_free_rx_ring(sc
, &sc
->rx_ring
);
809 mtx_destroy(&sc
->lock
);
817 static int rt2870_detach(device_t dev
)
819 struct rt2870_softc
*sc
;
820 struct ieee80211com
*ic
;
824 if (!device_is_attached(dev
))
827 sc
= device_get_softc(dev
);
831 RT2870_DPRINTF(sc
, RT2870_DEBUG_ANY
,
833 device_get_nameunit(sc
->dev
));
835 RT2870_SOFTC_LOCK(sc
);
837 sc
->flags
&= ~RT2870_SOFTC_FLAGS_VALID
;
841 ifp
->if_drv_flags
&= ~(IFF_DRV_RUNNING
| IFF_DRV_OACTIVE
);
843 callout_stop(&sc
->periodic_ch
);
844 callout_stop(&sc
->tx_watchdog_ch
);
846 RT2870_SOFTC_UNLOCK(sc
);
848 taskqueue_block(sc
->taskqueue
);
850 taskqueue_drain(sc
->taskqueue
, &sc
->rx_done_task
);
851 taskqueue_drain(sc
->taskqueue
, &sc
->tx_done_task
);
852 taskqueue_drain(sc
->taskqueue
, &sc
->periodic_task
);
853 taskqueue_drain(sc
->taskqueue
, &sc
->cmd_task
);
855 /* stop all USB transfers */
857 usbd_transfer_unsetup(sc
->usb_xfer
, sc
->usb_endpoints
);
859 RT2870_SOFTC_LOCK(sc
);
861 /* free Tx and Rx rings */
863 for (i
= 0; i
< sc
->usb_endpoints
- 1; i
++)
864 rt2870_free_tx_ring(sc
, &sc
->tx_ring
[i
]);
866 rt2870_free_rx_ring(sc
, &sc
->rx_ring
);
868 RT2870_SOFTC_UNLOCK(sc
);
870 ieee80211_ifdetach(ic
);
874 taskqueue_free(sc
->taskqueue
);
876 mtx_destroy(&sc
->lock
);
882 * rt2870_init_channels
884 static void rt2870_init_channels(struct rt2870_softc
*sc
)
887 struct ieee80211com
*ic
;
888 struct ieee80211_channel
*c
;
894 /* set supported channels for 2GHz band */
896 for (i
= 1; i
<= 14; i
++)
898 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
899 flags
= IEEE80211_CHAN_B
;
901 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
905 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
906 flags
= IEEE80211_CHAN_B
| IEEE80211_CHAN_HT20
;
908 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
912 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
913 flags
= IEEE80211_CHAN_G
;
915 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
919 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
920 flags
= IEEE80211_CHAN_G
| IEEE80211_CHAN_HT20
;
922 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
927 /* set supported channels for 5GHz band */
929 if (sc
->rf_rev
== RT2870_EEPROM_RF_2850
||
930 sc
->rf_rev
== RT2870_EEPROM_RF_2750
)
932 for (i
= 36; i
<= 64; i
+= 4)
934 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
935 flags
= IEEE80211_CHAN_A
;
937 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
941 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
942 flags
= IEEE80211_CHAN_A
| IEEE80211_CHAN_HT20
;
944 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
949 for (i
= 100; i
<= 140; i
+= 4)
951 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
952 flags
= IEEE80211_CHAN_A
;
954 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
958 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
959 flags
= IEEE80211_CHAN_A
| IEEE80211_CHAN_HT20
;
961 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
966 for (i
= 149; i
<= 165; i
+= 4)
968 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
969 flags
= IEEE80211_CHAN_A
;
971 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
975 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
976 flags
= IEEE80211_CHAN_A
| IEEE80211_CHAN_HT20
;
978 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
986 * rt2870_init_channels_ht40
988 static void rt2870_init_channels_ht40(struct rt2870_softc
*sc
)
991 struct ieee80211com
*ic
;
992 struct ieee80211_channel
*c
, *cent
, *ext
;
998 /* set supported channels for 2GHz band */
1000 for (i
= 1; i
<= 14; i
++)
1002 flags
= IEEE80211_CHAN_G
| IEEE80211_CHAN_HT40
;
1004 /* find the center channel */
1006 cent
= ieee80211_find_channel_byieee(ic
, i
,
1007 flags
& ~IEEE80211_CHAN_HT
);
1010 printf("%s: skip channel %d, could not find center channel\n",
1011 device_get_nameunit(sc
->dev
), i
);
1015 /* find the extension channel */
1017 ext
= ieee80211_find_channel(ic
, cent
->ic_freq
+ 20,
1018 flags
& ~IEEE80211_CHAN_HT
);
1021 printf("%s: skip channel %d, could not find extension channel\n",
1022 device_get_nameunit(sc
->dev
), i
);
1026 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1029 c
->ic_extieee
= ext
->ic_ieee
;
1030 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1031 c
->ic_flags
|= IEEE80211_CHAN_HT40U
;
1033 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1036 c
->ic_extieee
= cent
->ic_ieee
;
1037 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1038 c
->ic_flags
|= IEEE80211_CHAN_HT40D
;
1041 /* set supported channels for 5GHz band */
1043 if (sc
->rf_rev
== RT2870_EEPROM_RF_2850
||
1044 sc
->rf_rev
== RT2870_EEPROM_RF_2750
)
1046 for (i
= 36; i
<= 64; i
+= 4)
1048 flags
= IEEE80211_CHAN_A
| IEEE80211_CHAN_HT40
;
1050 /* find the center channel */
1052 cent
= ieee80211_find_channel_byieee(ic
, i
,
1053 flags
& ~IEEE80211_CHAN_HT
);
1056 printf("%s: skip channel %d, could not find center channel\n",
1057 device_get_nameunit(sc
->dev
), i
);
1061 /* find the extension channel */
1063 ext
= ieee80211_find_channel(ic
, cent
->ic_freq
+ 20,
1064 flags
& ~IEEE80211_CHAN_HT
);
1067 printf("%s: skip channel %d, could not find extension channel\n",
1068 device_get_nameunit(sc
->dev
), i
);
1072 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1075 c
->ic_extieee
= ext
->ic_ieee
;
1076 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1077 c
->ic_flags
|= IEEE80211_CHAN_HT40U
;
1079 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1082 c
->ic_extieee
= cent
->ic_ieee
;
1083 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1084 c
->ic_flags
|= IEEE80211_CHAN_HT40D
;
1087 for (i
= 100; i
<= 140; i
+= 4)
1089 flags
= IEEE80211_CHAN_A
| IEEE80211_CHAN_HT40
;
1091 /* find the center channel */
1093 cent
= ieee80211_find_channel_byieee(ic
, i
,
1094 flags
& ~IEEE80211_CHAN_HT
);
1097 printf("%s: skip channel %d, could not find center channel\n",
1098 device_get_nameunit(sc
->dev
), i
);
1102 /* find the extension channel */
1104 ext
= ieee80211_find_channel(ic
, cent
->ic_freq
+ 20,
1105 flags
& ~IEEE80211_CHAN_HT
);
1108 printf("%s: skip channel %d, could not find extension channel\n",
1109 device_get_nameunit(sc
->dev
), i
);
1113 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1116 c
->ic_extieee
= ext
->ic_ieee
;
1117 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1118 c
->ic_flags
|= IEEE80211_CHAN_HT40U
;
1120 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1123 c
->ic_extieee
= cent
->ic_ieee
;
1124 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1125 c
->ic_flags
|= IEEE80211_CHAN_HT40D
;
1128 for (i
= 149; i
<= 165; i
+= 4)
1130 flags
= IEEE80211_CHAN_A
| IEEE80211_CHAN_HT40
;
1132 /* find the center channel */
1134 cent
= ieee80211_find_channel_byieee(ic
, i
,
1135 flags
& ~IEEE80211_CHAN_HT
);
1138 printf("%s: skip channel %d, could not find center channel\n",
1139 device_get_nameunit(sc
->dev
), i
);
1143 /* find the extension channel */
1145 ext
= ieee80211_find_channel(ic
, cent
->ic_freq
+ 20,
1146 flags
& ~IEEE80211_CHAN_HT
);
1149 printf("%s: skip channel %d, could not find extension channel\n",
1150 device_get_nameunit(sc
->dev
), i
);
1154 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1157 c
->ic_extieee
= ext
->ic_ieee
;
1158 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1159 c
->ic_flags
|= IEEE80211_CHAN_HT40U
;
1161 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1164 c
->ic_extieee
= cent
->ic_ieee
;
1165 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1166 c
->ic_flags
|= IEEE80211_CHAN_HT40D
;
1172 * rt2870_init_locked
1174 static void rt2870_init_locked(void *priv
)
1176 struct rt2870_softc
*sc
;
1178 struct ieee80211com
*ic
;
1179 int ntries
, error
, i
;
1180 uint32_t tmp
, stacnt
[6];
1186 RT2870_DPRINTF(sc
, RT2870_DEBUG_ANY
,
1187 "%s: initializing\n",
1188 device_get_nameunit(sc
->dev
));
1190 RT2870_SOFTC_ASSERT_LOCKED(sc
);
1192 if (!(sc
->flags
& RT2870_SOFTC_FLAGS_UCODE_LOADED
))
1194 RT2870_DPRINTF(sc
, RT2870_DEBUG_ANY
,
1195 "%s: loading 8051 microcode\n",
1196 device_get_nameunit(sc
->dev
));
1198 error
= rt2870_io_mcu_load_ucode(sc
, rt2870_ucode
, sizeof(rt2870_ucode
));
1201 printf("%s: could not load 8051 microcode\n",
1202 device_get_nameunit(sc
->dev
));
1206 RT2870_DPRINTF(sc
, RT2870_DEBUG_ANY
,
1207 "%s: 8051 microcode was successfully loaded\n",
1208 device_get_nameunit(sc
->dev
));
1210 sc
->flags
|= RT2870_SOFTC_FLAGS_UCODE_LOADED
;
1213 /* wait while DMA engine is busy */
1215 for (ntries
= 0; ntries
< 100; ntries
++)
1217 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_SCHDMA_WPDMA_GLO_CFG
);
1218 if (!(tmp
& (RT2870_REG_TX_DMA_BUSY
| RT2870_REG_RX_DMA_BUSY
)))
1226 printf("%s: timeout waiting for DMA engine\n",
1227 device_get_nameunit(sc
->dev
));
1232 tmp
|= RT2870_REG_TX_WB_DDONE
;
1234 rt2870_io_mac_write(sc
, RT2870_REG_SCHDMA_WPDMA_GLO_CFG
, tmp
);
1236 /* PBF hardware reset */
1238 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_PBF_SYS_CTRL
);
1242 rt2870_io_mac_write(sc
, RT2870_REG_PBF_SYS_CTRL
, tmp
);
1244 rt2870_io_mac_write(sc
, RT2870_REG_SYS_CTRL
,
1245 RT2870_REG_MAC_SRST
| RT2870_REG_BBP_HRST
);
1247 rt2870_io_mac_write(sc
, RT2870_REG_SCHDMA_USB_DMA_CFG
, 0);
1249 rt2870_io_mcu_reset(sc
);
1251 rt2870_io_mac_write(sc
, RT2870_REG_SYS_CTRL
, 0);
1253 /* init Tx power per rate */
1255 for (i
= 0; i
< RT2870_SOFTC_TXPOW_RATE_COUNT
; i
++)
1257 if (sc
->txpow_rate_20mhz
[i
] == 0xffffffff)
1260 rt2870_io_mac_write(sc
, RT2870_REG_TX_PWR_CFG(i
),
1261 sc
->txpow_rate_20mhz
[i
]);
1264 for (i
= 0; i
< RT2870_DEF_MAC_SIZE
; i
++)
1265 rt2870_io_mac_write(sc
, rt2870_def_mac
[i
].reg
,
1266 rt2870_def_mac
[i
].val
);
1268 /* wait while MAC is busy */
1270 for (ntries
= 0; ntries
< 100; ntries
++)
1272 if (!(rt2870_io_mac_read(sc
, RT2870_REG_STATUS_CFG
) &
1273 (RT2870_REG_STATUS_TX_BUSY
| RT2870_REG_STATUS_RX_BUSY
)))
1281 printf("%s: timeout waiting for MAC\n",
1282 device_get_nameunit(sc
->dev
));
1286 /* clear Host to MCU mailbox */
1288 rt2870_io_mac_write(sc
, RT2870_REG_H2M_MAILBOX_BBP_AGENT
, 0);
1289 rt2870_io_mac_write(sc
, RT2870_REG_H2M_MAILBOX
, 0);
1293 error
= rt2870_init_bbp(sc
);
1297 /* set up maximum buffer sizes */
1299 tmp
= (1 << 12) | RT2870_MAX_AGG_SIZE
;
1301 rt2870_io_mac_write(sc
, RT2870_REG_MAX_LEN_CFG
, tmp
);
1303 if (sc
->mac_rev
== 0x28720200)
1305 /* set max. PSDU length from 16K to 32K bytes */
1307 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_MAX_LEN_CFG
);
1312 rt2870_io_mac_write(sc
, RT2870_REG_MAX_LEN_CFG
, tmp
);
1315 if (sc
->mac_rev
>= 0x28720200 && sc
->mac_rev
< 0x30700200)
1317 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_MAX_LEN_CFG
);
1322 rt2870_io_mac_write(sc
, RT2870_REG_MAX_LEN_CFG
, tmp
);
1325 /* set mac address */
1327 rt2870_asic_set_macaddr(sc
, IF_LLADDR(ifp
));
1329 /* clear statistic registers */
1331 rt2870_io_mac_read_multi(sc
, RT2870_REG_RX_STA_CNT0
,
1332 stacnt
, sizeof(stacnt
));
1334 /* send LEDs operating mode to microcontroller */
1336 rt2870_io_mcu_cmd(sc
, RT2870_IO_MCU_CMD_LED1
,
1337 RT2870_REG_H2M_TOKEN_NO_INTR
, sc
->led_off
[0]);
1338 rt2870_io_mcu_cmd(sc
, RT2870_IO_MCU_CMD_LED2
,
1339 RT2870_REG_H2M_TOKEN_NO_INTR
, sc
->led_off
[1]);
1340 rt2870_io_mcu_cmd(sc
, RT2870_IO_MCU_CMD_LED3
,
1341 RT2870_REG_H2M_TOKEN_NO_INTR
, sc
->led_off
[2]);
1343 /* write vendor-specific BBP values (from EEPROM) */
1345 for (i
= 0; i
< RT2870_SOFTC_BBP_EEPROM_COUNT
; i
++)
1347 if (sc
->bbp_eeprom
[i
].reg
== 0x00 ||
1348 sc
->bbp_eeprom
[i
].reg
== 0xff)
1351 rt2870_io_bbp_write(sc
, sc
->bbp_eeprom
[i
].reg
,
1352 sc
->bbp_eeprom
[i
].val
);
1355 /* disable non-existing Rx chains */
1357 tmp
= rt2870_io_bbp_read(sc
, 3);
1359 tmp
&= ~((1 << 4) | (1 << 3));
1361 if (sc
->nrxpath
== 3)
1363 else if (sc
->nrxpath
== 2)
1366 rt2870_io_bbp_write(sc
, 3, tmp
);
1368 /* disable non-existing Tx chains */
1370 tmp
= rt2870_io_bbp_read(sc
, 1);
1372 tmp
&= ~((1 << 4) | (1 << 3));
1374 if (sc
->ntxpath
== 2)
1377 rt2870_io_bbp_write(sc
, 1, tmp
);
1379 /* set current channel */
1381 rt2870_rf_set_chan(sc
, ic
->ic_curchan
);
1383 /* turn radio LED on */
1385 rt2870_led_cmd(sc
, RT2870_LED_CMD_RADIO_ON
);
1387 rt2870_io_mcu_cmd(sc
, RT2870_IO_MCU_CMD_BOOT
,
1388 RT2870_REG_H2M_TOKEN_NO_INTR
, 0);
1390 /* set RTS threshold */
1392 rt2870_asic_update_rtsthreshold(sc
);
1396 rt2870_asic_update_txpower(sc
);
1398 /* set up protection mode */
1400 sc
->tx_ampdu_sessions
= 0;
1402 rt2870_asic_updateprot(sc
);
1404 /* clear beacon frame space (entries = 8, entry size = 512) */
1406 rt2870_io_mac_set_region_4(sc
, RT2870_REG_BEACON_BASE(0), 0, 1024);
1408 if (rt2870_txrx_enable(sc
) != 0)
1411 /* clear garbage interrupts */
1413 tmp
= rt2870_io_mac_read(sc
, 0x1300);
1415 taskqueue_unblock(sc
->taskqueue
);
1417 /* init Tx and Rx rings */
1419 for(i
= 0; i
< sc
->usb_endpoints
- 1; i
++)
1420 rt2870_reset_tx_ring(sc
, &sc
->tx_ring
[i
]);
1422 rt2870_reset_rx_ring(sc
, &sc
->rx_ring
);
1424 for(i
= 0; i
< sc
->usb_endpoints
- 1; i
++)
1426 usbd_xfer_set_priv(sc
->usb_xfer
[i
+ 1], &sc
->tx_ring
[i
]);
1427 usbd_xfer_set_stall(sc
->usb_xfer
[i
+ 1]);
1430 /* start up the receive pipe */
1432 for(i
= 0; i
< RT2870_SOFTC_RX_RING_DATA_COUNT
; i
++)
1433 usbd_transfer_start(sc
->usb_xfer
[0]);
1435 ifp
->if_drv_flags
&= ~IFF_DRV_OACTIVE
;
1436 ifp
->if_drv_flags
|= IFF_DRV_RUNNING
;
1438 sc
->periodic_round
= 0;
1440 callout_reset(&sc
->periodic_ch
, hz
/ 10, rt2870_periodic
, sc
);
1446 rt2870_stop_locked(sc
);
1452 static void rt2870_init(void *priv
)
1454 struct rt2870_softc
*sc
;
1458 RT2870_SOFTC_LOCK(sc
);
1460 rt2870_init_locked(sc
);
1462 RT2870_SOFTC_UNLOCK(sc
);
1468 static int rt2870_init_bbp(struct rt2870_softc
*sc
)
1473 for (ntries
= 0; ntries
< 20; ntries
++)
1475 tmp
= rt2870_io_bbp_read(sc
, 0);
1476 if (tmp
!= 0x00 && tmp
!= 0xff)
1480 if (tmp
== 0x00 || tmp
== 0xff)
1482 printf("%s: timeout waiting for BBP to wakeup\n",
1483 device_get_nameunit(sc
->dev
));
1487 for (i
= 0; i
< RT2870_DEF_BBP_SIZE
; i
++)
1488 rt2870_io_bbp_write(sc
, rt2870_def_bbp
[i
].reg
,
1489 rt2870_def_bbp
[i
].val
);
1491 if ((sc
->mac_rev
& 0xffff) != 0x0101)
1492 rt2870_io_bbp_write(sc
, 84, 0x19);
1494 if (sc
->mac_rev
== 0x28600100)
1496 rt2870_io_bbp_write(sc
, 69, 0x16);
1497 rt2870_io_bbp_write(sc
, 73, 0x12);
1504 * rt2870_stop_locked
1506 static void rt2870_stop_locked(void *priv
)
1508 struct rt2870_softc
*sc
;
1510 struct ieee80211com
*ic
;
1518 RT2870_DPRINTF(sc
, RT2870_DEBUG_ANY
,
1520 device_get_nameunit(sc
->dev
));
1522 RT2870_SOFTC_ASSERT_LOCKED(sc
);
1526 if (ifp
->if_drv_flags
& IFF_DRV_RUNNING
)
1527 rt2870_led_cmd(sc
, RT2870_LED_CMD_RADIO_OFF
);
1529 ifp
->if_drv_flags
&= ~(IFF_DRV_RUNNING
| IFF_DRV_OACTIVE
);
1531 callout_stop(&sc
->periodic_ch
);
1532 callout_stop(&sc
->tx_watchdog_ch
);
1534 RT2870_SOFTC_UNLOCK(sc
);
1536 taskqueue_block(sc
->taskqueue
);
1538 taskqueue_drain(sc
->taskqueue
, &sc
->rx_done_task
);
1539 taskqueue_drain(sc
->taskqueue
, &sc
->tx_done_task
);
1540 taskqueue_drain(sc
->taskqueue
, &sc
->periodic_task
);
1541 taskqueue_drain(sc
->taskqueue
, &sc
->cmd_task
);
1543 RT2870_SOFTC_LOCK(sc
);
1545 /* clear key tables */
1547 rt2870_asic_clear_keytables(sc
);
1551 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_SYS_CTRL
);
1553 tmp
&= ~(RT2870_REG_RX_ENABLE
| RT2870_REG_TX_ENABLE
);
1555 rt2870_io_mac_write(sc
, RT2870_REG_SYS_CTRL
, tmp
);
1557 rt2870_io_mac_write(sc
, RT2870_REG_SCHDMA_USB_DMA_CFG
, 0);
1561 rt2870_io_mac_write(sc
, RT2870_REG_SYS_CTRL
,
1562 RT2870_REG_MAC_SRST
| RT2870_REG_BBP_HRST
);
1563 rt2870_io_mac_write(sc
, RT2870_REG_SYS_CTRL
, 0);
1565 /* abort any pending transfers */
1567 for (i
= 0; i
< sc
->usb_endpoints
; i
++)
1568 usbd_transfer_stop(sc
->usb_xfer
[i
]);
1574 static void rt2870_stop(void *priv
)
1576 struct rt2870_softc
*sc
;
1580 RT2870_SOFTC_LOCK(sc
);
1582 rt2870_stop_locked(sc
);
1584 RT2870_SOFTC_UNLOCK(sc
);
1590 static void rt2870_start(struct ifnet
*ifp
)
1592 struct rt2870_softc
*sc
;
1593 struct ieee80211_node
*ni
;
1599 RT2870_SOFTC_LOCK(sc
);
1601 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
1603 RT2870_SOFTC_UNLOCK(sc
);
1609 IF_POLL(&ifp
->if_snd
, m
);
1613 IFQ_DRV_DEQUEUE(&ifp
->if_snd
, m
);
1615 ni
= (struct ieee80211_node
*) m
->m_pkthdr
.rcvif
;
1617 qid
= M_WME_GETAC(m
);
1619 if (sc
->tx_ring
[qid
].queued
>= RT2870_SOFTC_TX_RING_DATA_COUNT
)
1621 RT2870_DPRINTF(sc
, RT2870_DEBUG_TX
,
1622 "%s: if_start: Tx ring with qid=%d is full\n",
1623 device_get_nameunit(sc
->dev
), qid
);
1626 ieee80211_free_node(ni
);
1628 ifp
->if_drv_flags
|= IFF_DRV_OACTIVE
;
1631 sc
->tx_data_queue_full
[qid
]++;
1636 if (rt2870_tx_data(sc
, m
, ni
, qid
) != 0)
1638 ieee80211_free_node(ni
);
1643 sc
->tx_timer
= RT2870_TX_WATCHDOG_TIMEOUT
;
1645 callout_reset(&sc
->tx_watchdog_ch
, hz
, rt2870_tx_watchdog
, sc
);
1648 RT2870_SOFTC_UNLOCK(sc
);
1654 static int rt2870_ioctl(struct ifnet
*ifp
, u_long cmd
, caddr_t data
)
1656 struct rt2870_softc
*sc
;
1657 struct ieee80211com
*ic
;
1659 int error
, startall
;
1663 ifr
= (struct ifreq
*) data
;
1672 RT2870_SOFTC_LOCK(sc
);
1674 if (ifp
->if_flags
& IFF_UP
)
1676 if (ifp
->if_drv_flags
& IFF_DRV_RUNNING
)
1678 if ((ifp
->if_flags
^ sc
->if_flags
) & IFF_PROMISC
)
1679 rt2870_asic_update_promisc(sc
);
1683 rt2870_init_locked(sc
);
1689 if (ifp
->if_drv_flags
& IFF_DRV_RUNNING
)
1690 rt2870_stop_locked(sc
);
1693 sc
->if_flags
= ifp
->if_flags
;
1695 RT2870_SOFTC_UNLOCK(sc
);
1698 ieee80211_start_all(ic
);
1703 error
= ifmedia_ioctl(ifp
, ifr
, &ic
->ic_media
, cmd
);
1707 error
= ether_ioctl(ifp
, cmd
, data
);
1721 static struct ieee80211vap
*rt2870_vap_create(struct ieee80211com
*ic
,
1722 const char name
[IFNAMSIZ
], int unit
, int opmode
, int flags
,
1723 const uint8_t bssid
[IEEE80211_ADDR_LEN
],
1724 const uint8_t mac
[IEEE80211_ADDR_LEN
])
1726 struct rt2870_softc
*sc
;
1728 struct rt2870_softc_vap
*rvap
;
1729 struct ieee80211vap
*vap
;
1734 RT2870_DPRINTF(sc
, RT2870_DEBUG_STATE
,
1735 "%s: VAP create: opmode=%s\n",
1736 device_get_nameunit(sc
->dev
),
1737 ieee80211_opmode_name
[opmode
]);
1741 case IEEE80211_M_IBSS
:
1742 case IEEE80211_M_STA
:
1743 case IEEE80211_M_AHDEMO
:
1744 case IEEE80211_M_HOSTAP
:
1745 case IEEE80211_M_MBSS
:
1746 if ((sc
->napvaps
+ sc
->nadhocvaps
+ sc
->nstavaps
) != 0)
1748 if_printf(ifp
, "only 1 VAP supported\n");
1752 if (opmode
== IEEE80211_M_STA
)
1753 flags
|= IEEE80211_CLONE_NOBEACONS
;
1756 case IEEE80211_M_WDS
:
1757 if (sc
->napvaps
== 0)
1759 if_printf(ifp
, "WDS only supported in AP mode\n");
1764 case IEEE80211_M_MONITOR
:
1768 if_printf(ifp
, "unknown opmode %d\n", opmode
);
1772 rvap
= (struct rt2870_softc_vap
*) malloc(sizeof(struct rt2870_softc_vap
),
1773 M_80211_VAP
, M_NOWAIT
| M_ZERO
);
1779 ieee80211_vap_setup(ic
, vap
, name
, unit
, opmode
, flags
, bssid
, mac
);
1781 rvap
->newstate
= vap
->iv_newstate
;
1782 vap
->iv_newstate
= rt2870_vap_newstate
;
1784 vap
->iv_reset
= rt2870_vap_reset
;
1785 vap
->iv_key_update_begin
= rt2870_vap_key_update_begin
;
1786 vap
->iv_key_update_end
= rt2870_vap_key_update_end
;
1787 vap
->iv_key_set
= rt2870_vap_key_set
;
1788 vap
->iv_key_delete
= rt2870_vap_key_delete
;
1789 vap
->iv_update_beacon
= rt2870_vap_update_beacon
;
1791 rt2870_amrr_init(&rvap
->amrr
, vap
,
1793 RT2870_AMRR_MIN_SUCCESS_THRESHOLD
,
1794 RT2870_AMRR_MAX_SUCCESS_THRESHOLD
,
1797 vap
->iv_max_aid
= RT2870_SOFTC_STAID_COUNT
;
1799 /* override default Rx A-MPDU factor */
1801 vap
->iv_ampdu_rxmax
= IEEE80211_HTCAP_MAXRXAMPDU_32K
;
1802 vap
->iv_ampdu_density
= IEEE80211_HTCAP_MPDUDENSITY_NA
;
1803 vap
->iv_ampdu_limit
= vap
->iv_ampdu_rxmax
;
1805 ieee80211_vap_attach(vap
, ieee80211_media_change
, ieee80211_media_status
);
1807 switch (vap
->iv_opmode
)
1809 case IEEE80211_M_HOSTAP
:
1810 case IEEE80211_M_MBSS
:
1811 case IEEE80211_M_AHDEMO
:
1815 case IEEE80211_M_IBSS
:
1819 case IEEE80211_M_STA
:
1823 case IEEE80211_M_WDS
:
1833 if (sc
->napvaps
> 0)
1834 ic
->ic_opmode
= IEEE80211_M_HOSTAP
;
1835 else if (sc
->nadhocvaps
> 0)
1836 ic
->ic_opmode
= IEEE80211_M_IBSS
;
1837 else if (sc
->nstavaps
> 0)
1838 ic
->ic_opmode
= IEEE80211_M_STA
;
1840 ic
->ic_opmode
= opmode
;
1848 static void rt2870_vap_delete(struct ieee80211vap
*vap
)
1850 struct rt2870_softc
*sc
;
1851 struct ieee80211com
*ic
;
1853 struct rt2870_softc_vap
*rvap
;
1854 enum ieee80211_opmode opmode
;
1859 rvap
= (struct rt2870_softc_vap
*) vap
;
1860 opmode
= vap
->iv_opmode
;
1862 RT2870_DPRINTF(sc
, RT2870_DEBUG_STATE
,
1863 "%s: VAP delete: opmode=%s\n",
1864 device_get_nameunit(sc
->dev
),
1865 ieee80211_opmode_name
[opmode
]);
1867 rt2870_amrr_cleanup(&rvap
->amrr
);
1869 ieee80211_vap_detach(vap
);
1871 if (rvap
->beacon_mbuf
!= NULL
)
1873 m_free(rvap
->beacon_mbuf
);
1874 rvap
->beacon_mbuf
= NULL
;
1879 case IEEE80211_M_HOSTAP
:
1880 case IEEE80211_M_MBSS
:
1881 case IEEE80211_M_AHDEMO
:
1885 case IEEE80211_M_IBSS
:
1889 case IEEE80211_M_STA
:
1893 case IEEE80211_M_WDS
:
1903 if (sc
->napvaps
> 0)
1904 ic
->ic_opmode
= IEEE80211_M_HOSTAP
;
1905 else if (sc
->nadhocvaps
> 0)
1906 ic
->ic_opmode
= IEEE80211_M_IBSS
;
1907 else if (sc
->nstavaps
> 0)
1908 ic
->ic_opmode
= IEEE80211_M_STA
;
1910 free(rvap
, M_80211_VAP
);
1916 static int rt2870_vap_reset(struct ieee80211vap
*vap
, u_long cmd
)
1918 struct rt2870_softc
*sc
;
1919 struct ieee80211com
*ic
;
1921 struct rt2870_softc_vap
*rvap
;
1927 rvap
= (struct rt2870_softc_vap
*) vap
;
1929 RT2870_DPRINTF(sc
, RT2870_DEBUG_STATE
,
1930 "%s: VAP reset: cmd=%lu\n",
1931 device_get_nameunit(sc
->dev
), cmd
);
1935 RT2870_SOFTC_LOCK(sc
);
1939 case IEEE80211_IOC_RTSTHRESHOLD
:
1940 case IEEE80211_IOC_AMSDU
:
1941 rt2870_asic_update_rtsthreshold(sc
);
1944 case IEEE80211_IOC_PROTMODE
:
1945 case IEEE80211_IOC_HTPROTMODE
:
1946 rt2870_asic_updateprot(sc
);
1949 case IEEE80211_IOC_TXPOWER
:
1950 rt2870_asic_update_txpower(sc
);
1953 case IEEE80211_IOC_BURST
:
1954 rt2870_asic_updateslot(sc
);
1957 case IEEE80211_IOC_SHORTGI
:
1958 case IEEE80211_IOC_AMPDU_DENSITY
:
1959 case IEEE80211_IOC_SMPS
:
1967 RT2870_SOFTC_UNLOCK(sc
);
1973 * rt2870_vap_newstate
1975 static int rt2870_vap_newstate(struct ieee80211vap
*vap
,
1976 enum ieee80211_state nstate
, int arg
)
1978 struct rt2870_softc
*sc
;
1979 struct ieee80211com
*ic
;
1981 struct rt2870_softc_vap
*rvap
;
1982 struct ieee80211_node
*ni
;
1988 rvap
= (struct rt2870_softc_vap
*) vap
;
1990 RT2870_DPRINTF(sc
, RT2870_DEBUG_STATE
,
1991 "%s: VAP newstate: %s -> %s\n",
1992 device_get_nameunit(sc
->dev
),
1993 ieee80211_state_name
[vap
->iv_state
], ieee80211_state_name
[nstate
]);
1995 error
= rvap
->newstate(vap
, nstate
, arg
);
1999 if (!(sc
->flags
& RT2870_SOFTC_FLAGS_VALID
))
2002 IEEE80211_UNLOCK(ic
);
2004 RT2870_SOFTC_LOCK(sc
);
2006 /* turn link LED off */
2008 if (nstate
!= IEEE80211_S_RUN
)
2009 rt2870_led_cmd(sc
, RT2870_LED_CMD_RADIO_OFF
);
2013 case IEEE80211_S_INIT
:
2014 rt2870_asic_disable_tsf_sync(sc
);
2017 case IEEE80211_S_RUN
:
2020 rt2870_rf_set_chan(sc
, ni
->ni_chan
);
2022 if (vap
->iv_opmode
!= IEEE80211_M_MONITOR
)
2024 rt2870_asic_enable_mrr(sc
);
2025 rt2870_asic_set_txpreamble(sc
);
2026 rt2870_asic_set_basicrates(sc
);
2027 rt2870_asic_update_txpower(sc
);
2028 rt2870_asic_set_bssid(sc
, ni
->ni_bssid
);
2031 if (vap
->iv_opmode
== IEEE80211_M_HOSTAP
||
2032 vap
->iv_opmode
== IEEE80211_M_IBSS
||
2033 vap
->iv_opmode
== IEEE80211_M_MBSS
)
2035 error
= rt2870_beacon_alloc(sc
, vap
);
2039 rt2870_asic_update_beacon(sc
, vap
);
2042 if (vap
->iv_opmode
!= IEEE80211_M_MONITOR
)
2043 rt2870_asic_enable_tsf_sync(sc
);
2045 /* turn link LED on */
2047 if (vap
->iv_opmode
!= IEEE80211_M_MONITOR
)
2049 rt2870_led_cmd(sc
, RT2870_LED_CMD_RADIO_ON
|
2050 (IEEE80211_IS_CHAN_2GHZ(ni
->ni_chan
) ?
2051 RT2870_LED_CMD_LINK_2GHZ
: RT2870_LED_CMD_LINK_5GHZ
));
2059 RT2870_SOFTC_UNLOCK(sc
);
2067 * rt2870_vap_key_update_begin
2069 static void rt2870_vap_key_update_begin(struct ieee80211vap
*vap
)
2071 struct rt2870_softc
*sc
;
2072 struct ieee80211com
*ic
;
2079 RT2870_DPRINTF(sc
, RT2870_DEBUG_KEY
,
2080 "%s: VAP key update begin\n",
2081 device_get_nameunit(sc
->dev
));
2083 taskqueue_block(sc
->taskqueue
);
2085 IF_LOCK(&ifp
->if_snd
);
2089 * rt2870_vap_key_update_end
2091 static void rt2870_vap_key_update_end(struct ieee80211vap
*vap
)
2093 struct rt2870_softc
*sc
;
2094 struct ieee80211com
*ic
;
2101 RT2870_DPRINTF(sc
, RT2870_DEBUG_KEY
,
2102 "%s: VAP key update end\n",
2103 device_get_nameunit(sc
->dev
));
2105 IF_UNLOCK(&ifp
->if_snd
);
2107 taskqueue_unblock(sc
->taskqueue
);
2111 * rt2870_vap_key_set
2113 static int rt2870_vap_key_set(struct ieee80211vap
*vap
,
2114 const struct ieee80211_key
*k
, const uint8_t mac
[IEEE80211_ADDR_LEN
])
2116 struct rt2870_softc
*sc
;
2117 struct ieee80211com
*ic
;
2119 struct ieee80211_node
*ni
;
2120 struct rt2870_softc_node
*rni
;
2121 struct rt2870_cmd_argv_keyset cmd_argv
;
2123 if (k
->wk_cipher
->ic_cipher
!= IEEE80211_CIPHER_WEP
&&
2124 k
->wk_cipher
->ic_cipher
!= IEEE80211_CIPHER_TKIP
&&
2125 k
->wk_cipher
->ic_cipher
!= IEEE80211_CIPHER_AES_CCM
)
2132 cmd_argv
.opmode
= vap
->iv_opmode
;
2134 memcpy(&cmd_argv
.key
, k
, sizeof(struct ieee80211_key
));
2136 if (!(k
->wk_flags
& IEEE80211_KEY_GROUP
))
2138 ni
= ieee80211_find_vap_node(&ic
->ic_sta
, vap
, mac
);
2139 rni
= (struct rt2870_softc_node
*) ni
;
2141 cmd_argv
.staid
= rni
->staid
;
2143 ieee80211_free_node(ni
);
2146 rt2870_do_async(sc
, rt2870_vap_key_set_cb
,
2147 &cmd_argv
, sizeof(struct rt2870_cmd_argv_keyset
));
2153 * rt2870_vap_key_delete
2155 static int rt2870_vap_key_delete(struct ieee80211vap
*vap
,
2156 const struct ieee80211_key
*k
)
2158 struct rt2870_softc
*sc
;
2159 struct ieee80211com
*ic
;
2161 struct rt2870_cmd_argv_keydelete cmd_argv
;
2167 cmd_argv
.opmode
= vap
->iv_opmode
;
2169 memcpy(&cmd_argv
.key
, k
, sizeof(struct ieee80211_key
));
2171 rt2870_do_async(sc
, rt2870_vap_key_delete_cb
,
2172 &cmd_argv
, sizeof(struct rt2870_cmd_argv_keydelete
));
2178 * rt2870_vap_update_beacon
2180 static void rt2870_vap_update_beacon(struct ieee80211vap
*vap
, int what
)
2182 struct rt2870_softc
*sc
;
2183 struct ieee80211com
*ic
;
2185 struct rt2870_softc_vap
*rvap
;
2187 struct ieee80211_beacon_offsets
*bo
;
2192 rvap
= (struct rt2870_softc_vap
*) vap
;
2193 m
= rvap
->beacon_mbuf
;
2194 bo
= &rvap
->beacon_offsets
;
2196 RT2870_DPRINTF(sc
, RT2870_DEBUG_BEACON
,
2197 "%s: VAP update beacon: what=%d\n",
2198 device_get_nameunit(sc
->dev
), what
);
2200 setbit(bo
->bo_flags
, what
);
2202 ieee80211_beacon_update(vap
->iv_bss
, bo
, m
, 0);
2204 rt2870_do_async(sc
, rt2870_vap_update_beacon_cb
, NULL
, 0);
2210 static struct ieee80211_node
*rt2870_node_alloc(struct ieee80211vap
*vap
,
2211 const uint8_t mac
[IEEE80211_ADDR_LEN
])
2213 return malloc(sizeof(struct rt2870_softc_node
),
2214 M_80211_NODE
, M_NOWAIT
| M_ZERO
);
2218 * rt2870_node_cleanup
2220 static void rt2870_node_cleanup(struct ieee80211_node
*ni
)
2222 struct rt2870_softc
*sc
;
2223 struct ieee80211com
*ic
;
2225 struct rt2870_softc_node
*rni
;
2226 struct rt2870_cmd_argv_nodecleanup cmd_argv
;
2231 rni
= (struct rt2870_softc_node
*) ni
;
2233 RT2870_DPRINTF(sc
, RT2870_DEBUG_NODE
,
2234 "%s: node cleanup: macaddr=%s, associd=0x%04x, staid=0x%02x\n",
2235 device_get_nameunit(sc
->dev
), ether_sprintf(ni
->ni_macaddr
),
2236 ni
->ni_associd
, rni
->staid
);
2238 if (rni
->staid
!= 0)
2240 cmd_argv
.staid
= rni
->staid
;
2244 rt2870_do_async(sc
, rt2870_node_cleanup_cb
,
2245 &cmd_argv
, sizeof(struct rt2870_cmd_argv_nodecleanup
));
2248 sc
->node_cleanup(ni
);
2252 * rt2870_node_getmimoinfo
2254 static void rt2870_node_getmimoinfo(const struct ieee80211_node
*ni
,
2255 struct ieee80211_mimo_info
*mi
)
2257 const struct rt2870_softc_node
*rni
;
2260 rni
= (const struct rt2870_softc_node
*) ni
;
2262 for (i
= 0; i
< RT2870_SOFTC_RSSI_COUNT
; i
++)
2264 mi
->rssi
[i
] = rni
->last_rssi_dbm
[i
];
2265 mi
->noise
[i
] = RT2870_NOISE_FLOOR
;
2270 * rt2870_setregdomain
2272 static int rt2870_setregdomain(struct ieee80211com
*ic
,
2273 struct ieee80211_regdomain
*reg
,
2274 int nchans
, struct ieee80211_channel chans
[])
2276 struct rt2870_softc
*sc
;
2282 RT2870_DPRINTF(sc
, RT2870_DEBUG_STATE
,
2283 "%s: set regulatory domain: country=%d, country code string=%c%c, location=%c\n",
2284 device_get_nameunit(sc
->dev
),
2285 reg
->country
, reg
->isocc
[0], reg
->isocc
[1], reg
->location
);
2291 * rt2870_getradiocaps
2293 static void rt2870_getradiocaps(struct ieee80211com
*ic
,
2294 int maxchans
, int *nchans
, struct ieee80211_channel chans
[])
2296 *nchans
= (ic
->ic_nchans
>= maxchans
) ? maxchans
: ic
->ic_nchans
;
2298 memcpy(chans
, ic
->ic_channels
, (*nchans
) * sizeof(struct ieee80211_channel
));
2304 static void rt2870_scan_start(struct ieee80211com
*ic
)
2306 struct rt2870_softc
*sc
;
2312 if (!(sc
->flags
& RT2870_SOFTC_FLAGS_VALID
))
2315 RT2870_SOFTC_LOCK(sc
);
2317 rt2870_asic_disable_tsf_sync(sc
);
2319 RT2870_SOFTC_UNLOCK(sc
);
2325 static void rt2870_scan_end(struct ieee80211com
*ic
)
2327 struct rt2870_softc
*sc
;
2333 if (!(sc
->flags
& RT2870_SOFTC_FLAGS_VALID
))
2336 RT2870_SOFTC_LOCK(sc
);
2338 rt2870_asic_enable_tsf_sync(sc
);
2340 RT2870_SOFTC_UNLOCK(sc
);
2344 * rt2870_set_channel
2346 static void rt2870_set_channel(struct ieee80211com
*ic
)
2348 struct rt2870_softc
*sc
;
2354 if (!(sc
->flags
& RT2870_SOFTC_FLAGS_VALID
))
2357 RT2870_DPRINTF(sc
, RT2870_DEBUG_CHAN
,
2358 "%s: set channel: channel=%u, HT%s%s\n",
2359 device_get_nameunit(sc
->dev
),
2360 ieee80211_chan2ieee(ic
, ic
->ic_curchan
),
2361 !IEEE80211_IS_CHAN_HT(ic
->ic_curchan
) ? " disabled" :
2362 IEEE80211_IS_CHAN_HT20(ic
->ic_curchan
) ? "20":
2363 IEEE80211_IS_CHAN_HT40U(ic
->ic_curchan
) ? "40U" : "40D",
2364 (ic
->ic_flags
& IEEE80211_F_SCAN
) ? ", scanning" : "");
2366 RT2870_SOFTC_LOCK(sc
);
2368 rt2870_rf_set_chan(sc
, ic
->ic_curchan
);
2370 RT2870_SOFTC_UNLOCK(sc
);
2376 static void rt2870_newassoc(struct ieee80211_node
*ni
, int isnew
)
2378 struct rt2870_softc
*sc
;
2379 struct ieee80211com
*ic
;
2381 struct ieee80211vap
*vap
;
2382 struct rt2870_softc_vap
*rvap
;
2383 struct rt2870_softc_node
*rni
;
2391 rvap
= (struct rt2870_softc_vap
*) vap
;
2392 rni
= (struct rt2870_softc_node
*) ni
;
2396 aid
= IEEE80211_AID(ni
->ni_associd
);
2397 rni
->staid
= rt2870_staid_alloc(sc
, aid
);
2400 RT2870_SOFTC_LOCK(sc
);
2402 rt2870_io_mac_write_multi(sc
, RT2870_REG_WCID(wcid
),
2403 ni
->ni_macaddr
, IEEE80211_ADDR_LEN
);
2405 rt2870_amrr_node_init(&rvap
->amrr
, &sc
->amrr_node
[wcid
], ni
);
2407 RT2870_DPRINTF(sc
, RT2870_DEBUG_RATE
,
2408 "%s: initial%s node Tx rate: associd=0x%04x, rate=0x%02x, max rate=0x%02x\n",
2409 device_get_nameunit(sc
->dev
),
2410 (ni
->ni_flags
& IEEE80211_NODE_HT
) ? " HT" : "",
2411 ni
->ni_associd
, ni
->ni_txrate
,
2412 (ni
->ni_flags
& IEEE80211_NODE_HT
) ?
2413 (ni
->ni_htrates
.rs_rates
[ni
->ni_htrates
.rs_nrates
- 1] | IEEE80211_RATE_MCS
) :
2414 (ni
->ni_rates
.rs_rates
[ni
->ni_rates
.rs_nrates
- 1] & IEEE80211_RATE_VAL
));
2416 rt2870_asic_updateprot(sc
);
2417 rt2870_asic_updateslot(sc
);
2418 rt2870_asic_set_txpreamble(sc
);
2420 RT2870_SOFTC_UNLOCK(sc
);
2423 RT2870_DPRINTF(sc
, RT2870_DEBUG_NODE
,
2424 "%s: new association: isnew=%d, macaddr=%s, associd=0x%04x, staid=0x%02x, QoS %s, ERP %s, HT %s\n",
2425 device_get_nameunit(sc
->dev
), isnew
, ether_sprintf(ni
->ni_macaddr
),
2426 ni
->ni_associd
, rni
->staid
,
2427 (ni
->ni_flags
& IEEE80211_NODE_QOS
) ? "enabled" : "disabled",
2428 (ni
->ni_flags
& IEEE80211_NODE_ERP
) ? "enabled" : "disabled",
2429 (ni
->ni_flags
& IEEE80211_NODE_HT
) ? "enabled" : "disabled");
2435 static void rt2870_updateslot(struct ifnet
*ifp
)
2437 struct rt2870_softc
*sc
;
2441 rt2870_do_async(sc
, rt2870_updateslot_cb
, NULL
, 0);
2445 * rt2870_update_promisc
2447 static void rt2870_update_promisc(struct ifnet
*ifp
)
2449 struct rt2870_softc
*sc
;
2453 RT2870_SOFTC_LOCK(sc
);
2455 rt2870_asic_update_promisc(sc
);
2457 RT2870_SOFTC_UNLOCK(sc
);
2461 * rt2870_update_mcast
2463 static void rt2870_update_mcast(struct ifnet
*ifp
)
2465 struct rt2870_softc
*sc
;
2473 static int rt2870_wme_update(struct ieee80211com
*ic
)
2475 struct rt2870_softc
*sc
;
2481 rt2870_do_async(sc
, rt2870_wme_update_cb
, NULL
, 0);
2489 static int rt2870_raw_xmit(struct ieee80211_node
*ni
, struct mbuf
*m
,
2490 const struct ieee80211_bpf_params
*params
)
2492 struct rt2870_softc
*sc
;
2493 struct ieee80211com
*ic
;
2500 RT2870_SOFTC_LOCK(sc
);
2502 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
2504 RT2870_SOFTC_UNLOCK(sc
);
2507 ieee80211_free_node(ni
);
2512 if (sc
->tx_ring
[sc
->tx_ring_mgtqid
].queued
>= RT2870_SOFTC_TX_RING_DATA_COUNT
)
2514 RT2870_DPRINTF(sc
, RT2870_DEBUG_TX
,
2515 "%s: raw xmit: Tx ring with qid=%d is full\n",
2516 device_get_nameunit(sc
->dev
), sc
->tx_ring_mgtqid
);
2518 ifp
->if_drv_flags
|= IFF_DRV_OACTIVE
;
2520 RT2870_SOFTC_UNLOCK(sc
);
2523 ieee80211_free_node(ni
);
2525 sc
->tx_data_queue_full
[sc
->tx_ring_mgtqid
]++;
2530 if (rt2870_tx_mgmt(sc
, m
, ni
, sc
->tx_ring_mgtqid
) != 0)
2534 RT2870_SOFTC_UNLOCK(sc
);
2536 ieee80211_free_node(ni
);
2541 sc
->tx_timer
= RT2870_TX_WATCHDOG_TIMEOUT
;
2543 RT2870_SOFTC_UNLOCK(sc
);
2549 * rt2870_recv_action
2551 static int rt2870_recv_action(struct ieee80211_node
*ni
,
2552 const struct ieee80211_frame
*wh
,
2553 const uint8_t *frm
, const uint8_t *efrm
)
2555 struct rt2870_softc
*sc
;
2556 struct ieee80211com
*ic
;
2558 struct rt2870_softc_node
*rni
;
2559 const struct ieee80211_action
*ia
;
2560 struct ieee80211_tx_ampdu
*tx_ampdu
;
2561 uint16_t status
, baparamset
;
2563 int ret
, tid
, bufsize
, ac
;
2569 rni
= (struct rt2870_softc_node
*) ni
;
2571 ia
= (const struct ieee80211_action
*) frm
;
2573 ret
= sc
->recv_action(ni
, wh
, frm
, efrm
);
2575 if (ia
->ia_category
!= IEEE80211_ACTION_CAT_BA
)
2580 switch (ia
->ia_action
)
2582 /* IEEE80211_ACTION_BA_ADDBA_REQUEST */
2583 case IEEE80211_ACTION_BA_ADDBA_REQUEST
:
2584 baparamset
= LE_READ_2(frm
+ 3);
2585 tid
= RT2870_MS(baparamset
, IEEE80211_BAPS_TID
);
2586 bufsize
= RT2870_MS(baparamset
, IEEE80211_BAPS_BUFSIZ
);
2588 RT2870_DPRINTF(sc
, RT2870_DEBUG_BA
,
2589 "%s: received ADDBA request: associd=0x%04x, tid=%d, bufsize=%d\n",
2590 device_get_nameunit(sc
->dev
), ni
->ni_associd
, tid
, bufsize
);
2592 RT2870_SOFTC_LOCK(sc
);
2594 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_WCID(wcid
) + 4);
2596 tmp
|= (0x10000 << tid
);
2598 rt2870_io_mac_write(sc
, RT2870_REG_WCID(wcid
) + 4, tmp
);
2600 RT2870_SOFTC_UNLOCK(sc
);
2603 /* IEEE80211_ACTION_BA_ADDBA_RESPONSE */
2604 case IEEE80211_ACTION_BA_ADDBA_RESPONSE
:
2605 status
= LE_READ_2(frm
+ 3);
2606 baparamset
= LE_READ_2(frm
+ 4);
2607 tid
= RT2870_MS(baparamset
, IEEE80211_BAPS_TID
);
2608 bufsize
= RT2870_MS(baparamset
, IEEE80211_BAPS_BUFSIZ
);
2609 ac
= TID_TO_WME_AC(tid
);
2610 tx_ampdu
= &ni
->ni_tx_ampdu
[ac
];
2612 RT2870_DPRINTF(sc
, RT2870_DEBUG_BA
,
2613 "%s: received ADDBA response: associd=0x%04x, status=%d, tid=%d, bufsize=%d\n",
2614 device_get_nameunit(sc
->dev
), ni
->ni_associd
, status
, tid
, bufsize
);
2616 if (sc
->mac_rev
>= 0x28720200)
2618 if (tx_ampdu
->txa_wnd
> 13)
2619 tx_ampdu
->txa_wnd
= 13;
2623 if (tx_ampdu
->txa_wnd
> 7)
2624 tx_ampdu
->txa_wnd
= 7;
2627 if (status
== IEEE80211_STATUS_SUCCESS
)
2629 sc
->tx_ampdu_sessions
++;
2631 RT2870_SOFTC_LOCK(sc
);
2633 rt2870_asic_updateprot(sc
);
2635 RT2870_SOFTC_UNLOCK(sc
);
2639 /* IEEE80211_ACTION_BA_DELBA */
2640 case IEEE80211_ACTION_BA_DELBA
:
2641 baparamset
= LE_READ_2(frm
+ 2);
2642 tid
= RT2870_MS(baparamset
, IEEE80211_BAPS_TID
);
2644 RT2870_DPRINTF(sc
, RT2870_DEBUG_BA
,
2645 "%s: received DELBA request: associd=0x%04x, tid=%d\n",
2646 device_get_nameunit(sc
->dev
), ni
->ni_associd
, tid
);
2648 RT2870_SOFTC_LOCK(sc
);
2650 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_WCID(wcid
) + 4);
2652 tmp
&= ~(0x10000 << tid
);
2654 rt2870_io_mac_write(sc
, RT2870_REG_WCID(wcid
) + 4, tmp
);
2656 RT2870_SOFTC_UNLOCK(sc
);
2664 * rt2870_send_action
2666 static int rt2870_send_action(struct ieee80211_node
*ni
,
2667 int cat
, int act
, void *sa
)
2669 struct rt2870_softc
*sc
;
2670 struct ieee80211com
*ic
;
2672 struct rt2870_softc_node
*rni
;
2673 uint16_t *args
, baparamset
;
2681 rni
= (struct rt2870_softc_node
*) ni
;
2683 ret
= sc
->send_action(ni
, cat
, act
, sa
);
2685 if (cat
!= IEEE80211_ACTION_CAT_BA
)
2693 /* IEEE80211_ACTION_BA_DELBA */
2694 case IEEE80211_ACTION_BA_DELBA
:
2695 baparamset
= RT2870_SM(args
[0], IEEE80211_DELBAPS_TID
) | args
[1];
2697 tid
= RT2870_MS(baparamset
, IEEE80211_DELBAPS_TID
);
2699 RT2870_DPRINTF(sc
, RT2870_DEBUG_BA
,
2700 "%s: sending DELBA request: associd=0x%04x, tid=%d\n",
2701 device_get_nameunit(sc
->dev
), ni
->ni_associd
, tid
);
2703 RT2870_SOFTC_LOCK(sc
);
2705 if (RT2870_MS(baparamset
, IEEE80211_DELBAPS_INIT
) != IEEE80211_DELBAPS_INIT
)
2707 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_WCID(wcid
) + 4);
2709 tmp
&= ~(0x10000 << tid
);
2711 rt2870_io_mac_write(sc
, RT2870_REG_WCID(wcid
) + 4, tmp
);
2715 sc
->tx_ampdu_sessions
--;
2717 rt2870_asic_updateprot(sc
);
2720 RT2870_SOFTC_UNLOCK(sc
);
2728 * rt2870_amrr_update_iter_func
2730 static void rt2870_amrr_update_iter_func(void *arg
, struct ieee80211_node
*ni
)
2732 struct rt2870_softc
*sc
;
2733 struct ieee80211com
*ic
;
2735 struct ieee80211vap
*vap
;
2736 struct rt2870_softc_vap
*rvap
;
2737 struct rt2870_softc_node
*rni
;
2744 rvap
= (struct rt2870_softc_vap
*) vap
;
2745 rni
= (struct rt2870_softc_node
*) ni
;
2747 /* only associated stations */
2749 if ((ni
->ni_vap
== vap
) && (rni
->staid
!= 0))
2753 RT2870_DPRINTF(sc
, RT2870_DEBUG_RATE
,
2754 "%s: AMRR node: staid=0x%02x, txcnt=%d, success=%d, retrycnt=%d\n",
2755 device_get_nameunit(sc
->dev
),
2756 rni
->staid
, sc
->amrr_node
[wcid
].txcnt
, sc
->amrr_node
[wcid
].success
, sc
->amrr_node
[wcid
].retrycnt
);
2758 rt2870_amrr_choose(ni
, &sc
->amrr_node
[wcid
]);
2760 RT2870_DPRINTF(sc
, RT2870_DEBUG_RATE
,
2761 "%s:%s node Tx rate: associd=0x%04x, staid=0x%02x, rate=0x%02x, max rate=0x%02x\n",
2762 device_get_nameunit(sc
->dev
),
2763 (ni
->ni_flags
& IEEE80211_NODE_HT
) ? " HT" : "",
2764 ni
->ni_associd
, rni
->staid
, ni
->ni_txrate
,
2765 (ni
->ni_flags
& IEEE80211_NODE_HT
) ?
2766 (ni
->ni_htrates
.rs_rates
[ni
->ni_htrates
.rs_nrates
- 1] | IEEE80211_RATE_MCS
) :
2767 (ni
->ni_rates
.rs_rates
[ni
->ni_rates
.rs_nrates
- 1] & IEEE80211_RATE_VAL
));
2774 static void rt2870_periodic(void *arg
)
2776 struct rt2870_softc
*sc
;
2782 RT2870_DPRINTF(sc
, RT2870_DEBUG_PERIODIC
,
2784 device_get_nameunit(sc
->dev
));
2786 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
2789 taskqueue_enqueue(sc
->taskqueue
, &sc
->periodic_task
);
2793 * rt2870_tx_watchdog
2795 static void rt2870_tx_watchdog(void *arg
)
2797 struct rt2870_softc
*sc
;
2803 if (sc
->tx_timer
== 0)
2806 if (--sc
->tx_timer
== 0)
2808 printf("%s: Tx watchdog timeout: resetting\n",
2809 device_get_nameunit(sc
->dev
));
2811 rt2870_stop_locked(sc
);
2812 rt2870_init_locked(sc
);
2816 sc
->tx_watchdog_timeouts
++;
2819 callout_reset(&sc
->tx_watchdog_ch
, hz
, rt2870_tx_watchdog
, sc
);
2823 * rt2870_staid_alloc
2825 static int rt2870_staid_alloc(struct rt2870_softc
*sc
, int aid
)
2829 if ((aid
> 0 && aid
< RT2870_SOFTC_STAID_COUNT
) && isclr(sc
->staid_mask
, aid
))
2835 for (staid
= 1; staid
< RT2870_SOFTC_STAID_COUNT
; staid
++)
2837 if (isclr(sc
->staid_mask
, staid
))
2842 setbit(sc
->staid_mask
, staid
);
2848 * rt2870_staid_delete
2850 static void rt2870_staid_delete(struct rt2870_softc
*sc
, int staid
)
2852 clrbit(sc
->staid_mask
, staid
);
2859 static int rt2870_do_async(struct rt2870_softc
*sc
,
2860 void (*cb
)(struct rt2870_softc
*sc
, void *arg
),
2864 struct rt2870_softc_cmd_ring
*ring
;
2865 struct rt2870_softc_cmd
*cmd
;
2869 ring
= &sc
->cmd_ring
;
2871 RT2870_SOFTC_LOCK(sc
);
2873 if (ring
->queued
>= RT2870_SOFTC_CMD_RING_CMD_COUNT
)
2875 RT2870_SOFTC_UNLOCK(sc
);
2879 cmd
= STAILQ_FIRST(&ring
->inactive
);
2880 STAILQ_REMOVE_HEAD(&ring
->inactive
, next
);
2885 memcpy(cmd
->data
, arg
, len
);
2887 STAILQ_INSERT_TAIL(&ring
->active
, cmd
, next
);
2890 run_cmd_task
= (ring
->queued
== 1);
2892 RT2870_SOFTC_UNLOCK(sc
);
2895 taskqueue_enqueue(sc
->taskqueue
, &sc
->cmd_task
);
2901 * rt2870_node_cleanup_cb
2903 static void rt2870_node_cleanup_cb(struct rt2870_softc
*sc
, void *arg
)
2906 struct ieee80211com
*ic
;
2907 struct rt2870_cmd_argv_nodecleanup
*cmd_argv
;
2908 uint8_t staid
, vapid
, wcid
;
2914 staid
= cmd_argv
->staid
;
2919 tmp
= ((vapid
& RT2870_REG_VAP_MASK
) << RT2870_REG_VAP_SHIFT
) |
2920 (RT2870_REG_CIPHER_MODE_NONE
<< RT2870_REG_CIPHER_MODE_SHIFT
) | RT2870_REG_PKEY_ENABLE
;
2922 RT2870_SOFTC_LOCK(sc
);
2924 rt2870_io_mac_write(sc
, RT2870_REG_WCID_ATTR(wcid
), tmp
);
2926 rt2870_staid_delete(sc
, staid
);
2928 RT2870_SOFTC_UNLOCK(sc
);
2932 * rt2870_updateslot_cb
2934 static void rt2870_updateslot_cb(struct rt2870_softc
*sc
, void *arg
)
2936 RT2870_SOFTC_LOCK(sc
);
2938 rt2870_asic_updateslot(sc
);
2940 RT2870_SOFTC_UNLOCK(sc
);
2944 * rt2870_wme_update_cb
2946 static void rt2870_wme_update_cb(struct rt2870_softc
*sc
, void *arg
)
2948 RT2870_SOFTC_LOCK(sc
);
2950 rt2870_asic_wme_update(sc
);
2952 RT2870_SOFTC_UNLOCK(sc
);
2956 * rt2870_vap_key_set_cb
2958 static void rt2870_vap_key_set_cb(struct rt2870_softc
*sc
, void *arg
)
2960 struct ieee80211com
*ic
;
2962 struct ieee80211_key
*k
;
2963 enum ieee80211_opmode opmode
;
2964 struct rt2870_cmd_argv_keyset
*cmd_argv
;
2965 uint16_t key_base
, keymode_base
;
2966 uint8_t mode
, vapid
, wcid
, iv
[8];
2973 opmode
= cmd_argv
->opmode
;
2975 switch (k
->wk_cipher
->ic_cipher
)
2977 case IEEE80211_CIPHER_WEP
:
2978 if(k
->wk_keylen
< 8)
2979 mode
= RT2870_REG_CIPHER_MODE_WEP40
;
2981 mode
= RT2870_REG_CIPHER_MODE_WEP104
;
2984 case IEEE80211_CIPHER_TKIP
:
2985 mode
= RT2870_REG_CIPHER_MODE_TKIP
;
2988 case IEEE80211_CIPHER_AES_CCM
:
2989 mode
= RT2870_REG_CIPHER_MODE_AES_CCMP
;
2996 RT2870_DPRINTF(sc
, RT2870_DEBUG_KEY
,
2997 "%s: VAP key set: keyix=%d, keylen=%d, macaddr=%s, mode=%d, group=%d\n",
2998 device_get_nameunit(sc
->dev
), k
->wk_keyix
, k
->wk_keylen
, ether_sprintf(k
->wk_macaddr
),
2999 mode
, (k
->wk_flags
& IEEE80211_KEY_GROUP
) ? 1 : 0);
3001 RT2870_SOFTC_LOCK(sc
);
3003 if (!(k
->wk_flags
& IEEE80211_KEY_GROUP
))
3005 /* install pairwise key */
3008 wcid
= cmd_argv
->staid
;
3009 key_base
= RT2870_REG_PKEY(wcid
);
3011 if (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_WEP
)
3015 iv
[3] = (k
->wk_keyix
<< 6);
3019 if (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_TKIP
)
3021 iv
[0] = (k
->wk_keytsc
>> 8);
3022 iv
[1] = ((iv
[0] | 0x20) & 0x7f);
3023 iv
[2] = k
->wk_keytsc
;
3029 iv
[0] = k
->wk_keytsc
;
3030 iv
[1] = k
->wk_keytsc
>> 8;
3034 iv
[3] = ((k
->wk_keyix
<< 6) | IEEE80211_WEP_EXTIV
);
3035 iv
[4] = (k
->wk_keytsc
>> 16);
3036 iv
[5] = (k
->wk_keytsc
>> 24);
3037 iv
[6] = (k
->wk_keytsc
>> 32);
3038 iv
[7] = (k
->wk_keytsc
>> 40);
3040 RT2870_DPRINTF(sc
, RT2870_DEBUG_KEY
,
3041 "%s: VAP key set: iv=%02x %02x %02x %02x %02x %02x %02x %02x\n",
3042 device_get_nameunit(sc
->dev
),
3043 iv
[0], iv
[1], iv
[2], iv
[3], iv
[4], iv
[5], iv
[6], iv
[7]);
3046 rt2870_io_mac_write_multi(sc
, RT2870_REG_IVEIV(wcid
), iv
, 8);
3048 if (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_TKIP
)
3050 rt2870_io_mac_write_multi(sc
, key_base
, k
->wk_key
, 16);
3052 if (opmode
!= IEEE80211_M_HOSTAP
)
3054 rt2870_io_mac_write_multi(sc
, key_base
+ 16, &k
->wk_key
[16], 8);
3055 rt2870_io_mac_write_multi(sc
, key_base
+ 24, &k
->wk_key
[24], 8);
3059 rt2870_io_mac_write_multi(sc
, key_base
+ 16, &k
->wk_key
[24], 8);
3060 rt2870_io_mac_write_multi(sc
, key_base
+ 24, &k
->wk_key
[16], 8);
3065 rt2870_io_mac_write_multi(sc
, key_base
, k
->wk_key
, k
->wk_keylen
);
3068 tmp
= ((vapid
& RT2870_REG_VAP_MASK
) << RT2870_REG_VAP_SHIFT
) |
3069 (mode
<< RT2870_REG_CIPHER_MODE_SHIFT
) | RT2870_REG_PKEY_ENABLE
;
3071 rt2870_io_mac_write(sc
, RT2870_REG_WCID_ATTR(wcid
), tmp
);
3074 if ((k
->wk_flags
& IEEE80211_KEY_GROUP
) ||
3075 (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_WEP
))
3077 /* install group key */
3080 wcid
= RT2870_WCID_MCAST
;
3081 key_base
= RT2870_REG_SKEY(vapid
, k
->wk_keyix
);
3082 keymode_base
= RT2870_REG_SKEY_MODE(vapid
);
3084 if (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_TKIP
)
3086 rt2870_io_mac_write_multi(sc
, key_base
, k
->wk_key
, 16);
3088 if (opmode
!= IEEE80211_M_HOSTAP
)
3090 rt2870_io_mac_write_multi(sc
, key_base
+ 16, &k
->wk_key
[16], 8);
3091 rt2870_io_mac_write_multi(sc
, key_base
+ 24, &k
->wk_key
[24], 8);
3095 rt2870_io_mac_write_multi(sc
, key_base
+ 16, &k
->wk_key
[24], 8);
3096 rt2870_io_mac_write_multi(sc
, key_base
+ 24, &k
->wk_key
[16], 8);
3101 rt2870_io_mac_write_multi(sc
, key_base
, k
->wk_key
, k
->wk_keylen
);
3104 tmp
= rt2870_io_mac_read(sc
, keymode_base
);
3106 tmp
&= ~(0xf << (k
->wk_keyix
* 4 + 16 * (vapid
% 2)));
3107 tmp
|= (mode
<< (k
->wk_keyix
* 4 + 16 * (vapid
% 2)));
3109 rt2870_io_mac_write(sc
, keymode_base
, tmp
);
3111 if (opmode
== IEEE80211_M_HOSTAP
)
3113 if (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_WEP
)
3117 iv
[3] = (k
->wk_keyix
<< 6);
3121 if (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_TKIP
)
3123 iv
[0] = (k
->wk_keytsc
>> 8);
3124 iv
[1] = ((iv
[0] | 0x20) & 0x7f);
3125 iv
[2] = k
->wk_keytsc
;
3131 iv
[0] = k
->wk_keytsc
;
3132 iv
[1] = k
->wk_keytsc
>> 8;
3136 iv
[3] = ((k
->wk_keyix
<< 6) | IEEE80211_WEP_EXTIV
);
3137 iv
[4] = (k
->wk_keytsc
>> 16);
3138 iv
[5] = (k
->wk_keytsc
>> 24);
3139 iv
[6] = (k
->wk_keytsc
>> 32);
3140 iv
[7] = (k
->wk_keytsc
>> 40);
3142 RT2870_DPRINTF(sc
, RT2870_DEBUG_KEY
,
3143 "%s: VAP key set: iv=%02x %02x %02x %02x %02x %02x %02x %02x\n",
3144 device_get_nameunit(sc
->dev
),
3145 iv
[0], iv
[1], iv
[2], iv
[3], iv
[4], iv
[5], iv
[6], iv
[7]);
3148 rt2870_io_mac_write_multi(sc
, RT2870_REG_IVEIV(wcid
), iv
, 8);
3150 tmp
= ((vapid
& RT2870_REG_VAP_MASK
) << RT2870_REG_VAP_SHIFT
) |
3151 (mode
<< RT2870_REG_CIPHER_MODE_SHIFT
);
3153 rt2870_io_mac_write(sc
, RT2870_REG_WCID_ATTR(wcid
), tmp
);
3157 RT2870_SOFTC_UNLOCK(sc
);
3161 * rt2870_vap_key_delete_cb
3163 static void rt2870_vap_key_delete_cb(struct rt2870_softc
*sc
, void *arg
)
3165 struct ieee80211com
*ic
;
3167 struct ieee80211_key
*k
;
3168 enum ieee80211_opmode opmode
;
3169 struct rt2870_cmd_argv_keydelete
*cmd_argv
;
3170 uint8_t vapid
, wcid
;
3177 opmode
= cmd_argv
->opmode
;
3179 RT2870_DPRINTF(sc
, RT2870_DEBUG_KEY
,
3180 "%s: VAP key delete: keyix=%d, keylen=%d, macaddr=%s, group=%d\n",
3181 device_get_nameunit(sc
->dev
), k
->wk_keyix
, k
->wk_keylen
, ether_sprintf(k
->wk_macaddr
),
3182 (k
->wk_flags
& IEEE80211_KEY_GROUP
) ? 1 : 0);
3184 RT2870_SOFTC_LOCK(sc
);
3186 if (k
->wk_flags
& IEEE80211_KEY_GROUP
)
3188 /* remove group key */
3191 wcid
= RT2870_WCID_MCAST
;
3193 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_SKEY_MODE(vapid
));
3195 tmp
&= ~(0xf << (k
->wk_keyix
* 4 + 16 * (vapid
% 2)));
3196 tmp
|= (RT2870_REG_CIPHER_MODE_NONE
<< (k
->wk_keyix
* 4 + 16 * (vapid
% 2)));
3198 rt2870_io_mac_write(sc
, RT2870_REG_SKEY_MODE(vapid
), tmp
);
3200 if (opmode
== IEEE80211_M_HOSTAP
)
3202 tmp
= ((vapid
& RT2870_REG_VAP_MASK
) << RT2870_REG_VAP_SHIFT
) |
3203 (RT2870_REG_CIPHER_MODE_NONE
<< RT2870_REG_CIPHER_MODE_SHIFT
);
3205 rt2870_io_mac_write(sc
, RT2870_REG_WCID_ATTR(wcid
), tmp
);
3209 RT2870_SOFTC_UNLOCK(sc
);
3213 * rt2870_vap_update_beacon_cb
3215 static void rt2870_vap_update_beacon_cb(struct rt2870_softc
*sc
, void *arg
)
3218 struct ieee80211com
*ic
;
3219 struct ieee80211vap
*vap
;
3223 vap
= TAILQ_FIRST(&ic
->ic_vaps
);
3228 RT2870_SOFTC_LOCK(sc
);
3230 rt2870_asic_update_beacon(sc
, vap
);
3232 RT2870_SOFTC_UNLOCK(sc
);
3236 * rt2870_asic_set_bssid
3238 static void rt2870_asic_set_bssid(struct rt2870_softc
*sc
,
3239 const uint8_t *bssid
)
3243 RT2870_DPRINTF(sc
, RT2870_DEBUG_STATE
,
3244 "%s: set bssid: bssid=%s\n",
3245 device_get_nameunit(sc
->dev
),
3246 ether_sprintf(bssid
));
3248 tmp
= bssid
[0] | (bssid
[1]) << 8 | (bssid
[2] << 16) | (bssid
[3] << 24);
3250 rt2870_io_mac_write(sc
, RT2870_REG_BSSID_DW0
, tmp
);
3252 tmp
= bssid
[4] | (bssid
[5] << 8);
3254 rt2870_io_mac_write(sc
, RT2870_REG_BSSID_DW1
, tmp
);
3258 * rt2870_asic_set_macaddr
3260 static void rt2870_asic_set_macaddr(struct rt2870_softc
*sc
,
3261 const uint8_t *addr
)
3265 tmp
= addr
[0] | (addr
[1] << 8) | (addr
[2] << 16) | (addr
[3] << 24);
3267 rt2870_io_mac_write(sc
, RT2870_REG_ADDR_DW0
, tmp
);
3269 tmp
= addr
[4] | (addr
[5] << 8);
3271 rt2870_io_mac_write(sc
, RT2870_REG_ADDR_DW1
, tmp
);
3275 * rt2870_asic_enable_tsf_sync
3277 static void rt2870_asic_enable_tsf_sync(struct rt2870_softc
*sc
)
3280 struct ieee80211com
*ic
;
3281 struct ieee80211vap
*vap
;
3286 vap
= TAILQ_FIRST(&ic
->ic_vaps
);
3288 RT2870_DPRINTF(sc
, RT2870_DEBUG_BEACON
,
3289 "%s: enabling TSF\n",
3290 device_get_nameunit(sc
->dev
));
3292 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_BCN_TIME_CFG
);
3295 tmp
|= vap
->iv_bss
->ni_intval
* 16;
3296 tmp
|= (RT2870_REG_TSF_TIMER_ENABLE
| RT2870_REG_TBTT_TIMER_ENABLE
);
3298 if (vap
->iv_opmode
== IEEE80211_M_STA
)
3300 tmp
|= (RT2870_REG_TSF_SYNC_MODE_STA
<< RT2870_REG_TSF_SYNC_MODE_SHIFT
);
3302 else if (vap
->iv_opmode
== IEEE80211_M_IBSS
)
3304 tmp
|= RT2870_REG_BCN_TX_ENABLE
;
3305 tmp
|= (RT2870_REG_TSF_SYNC_MODE_IBSS
<< RT2870_REG_TSF_SYNC_MODE_SHIFT
);
3307 else if (vap
->iv_opmode
== IEEE80211_M_HOSTAP
)
3309 tmp
|= RT2870_REG_BCN_TX_ENABLE
;
3310 tmp
|= (RT2870_REG_TSF_SYNC_MODE_HOSTAP
<< RT2870_REG_TSF_SYNC_MODE_SHIFT
);
3313 rt2870_io_mac_write(sc
, RT2870_REG_BCN_TIME_CFG
, tmp
);
3317 * rt2870_asic_disable_tsf_sync
3319 static void rt2870_asic_disable_tsf_sync(struct rt2870_softc
*sc
)
3323 RT2870_DPRINTF(sc
, RT2870_DEBUG_BEACON
,
3324 "%s: disabling TSF\n",
3325 device_get_nameunit(sc
->dev
));
3327 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_BCN_TIME_CFG
);
3329 tmp
&= ~(RT2870_REG_BCN_TX_ENABLE
|
3330 RT2870_REG_TSF_TIMER_ENABLE
|
3331 RT2870_REG_TBTT_TIMER_ENABLE
);
3333 tmp
&= ~(RT2870_REG_TSF_SYNC_MODE_MASK
<< RT2870_REG_TSF_SYNC_MODE_SHIFT
);
3334 tmp
|= (RT2870_REG_TSF_SYNC_MODE_DISABLE
<< RT2870_REG_TSF_SYNC_MODE_SHIFT
);
3336 rt2870_io_mac_write(sc
, RT2870_REG_BCN_TIME_CFG
, tmp
);
3340 * rt2870_asic_enable_mrr
3342 static void rt2870_asic_enable_mrr(struct rt2870_softc
*sc
)
3344 #define CCK(mcs) (mcs)
3345 #define OFDM(mcs) ((1 << 3) | (mcs))
3346 #define HT(mcs) (mcs)
3348 rt2870_io_mac_write(sc
, RT2870_REG_TX_LG_FBK_CFG0
,
3349 (OFDM(6) << 28) | /* 54 -> 48 */
3350 (OFDM(5) << 24) | /* 48 -> 36 */
3351 (OFDM(4) << 20) | /* 36 -> 24 */
3352 (OFDM(3) << 16) | /* 24 -> 18 */
3353 (OFDM(2) << 12) | /* 18 -> 12 */
3354 (OFDM(1) << 8) | /* 12 -> 9 */
3355 (OFDM(0) << 4) | /* 9 -> 6 */
3356 OFDM(0)); /* 6 -> 6 */
3358 rt2870_io_mac_write(sc
, RT2870_REG_TX_LG_FBK_CFG1
,
3359 (CCK(2) << 12) | /* 11 -> 5.5 */
3360 (CCK(1) << 8) | /* 5.5 -> 2 */
3361 (CCK(0) << 4) | /* 2 -> 1 */
3362 CCK(0)); /* 1 -> 1 */
3364 rt2870_io_mac_write(sc
, RT2870_REG_TX_HT_FBK_CFG0
,
3374 rt2870_io_mac_write(sc
, RT2870_REG_TX_HT_FBK_CFG1
,
3390 * rt2870_asic_set_txpreamble
3392 static void rt2870_asic_set_txpreamble(struct rt2870_softc
*sc
)
3395 struct ieee80211com
*ic
;
3401 RT2870_DPRINTF(sc
, RT2870_DEBUG_STATE
,
3402 "%s: %s short Tx preamble\n",
3403 device_get_nameunit(sc
->dev
),
3404 (ic
->ic_flags
& IEEE80211_F_SHPREAMBLE
) ? "enabling" : "disabling");
3406 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_AUTO_RSP_CFG
);
3408 tmp
&= ~RT2870_REG_CCK_SHORT_ENABLE
;
3410 if (ic
->ic_flags
& IEEE80211_F_SHPREAMBLE
)
3411 tmp
|= RT2870_REG_CCK_SHORT_ENABLE
;
3413 rt2870_io_mac_write(sc
, RT2870_REG_AUTO_RSP_CFG
, tmp
);
3417 * rt2870_asic_set_basicrates
3419 static void rt2870_asic_set_basicrates(struct rt2870_softc
*sc
)
3422 struct ieee80211com
*ic
;
3427 if (ic
->ic_curmode
== IEEE80211_MODE_11B
)
3428 rt2870_io_mac_write(sc
, RT2870_REG_LEGACY_BASIC_RATE
, 0x3);
3429 else if (ic
->ic_curmode
== IEEE80211_MODE_11A
)
3430 rt2870_io_mac_write(sc
, RT2870_REG_LEGACY_BASIC_RATE
, 0x150);
3432 rt2870_io_mac_write(sc
, RT2870_REG_LEGACY_BASIC_RATE
, 0x15f);
3436 * rt2870_asic_update_rtsthreshold
3438 static void rt2870_asic_update_rtsthreshold(struct rt2870_softc
*sc
)
3441 struct ieee80211com
*ic
;
3442 struct ieee80211vap
*vap
;
3448 vap
= TAILQ_FIRST(&ic
->ic_vaps
);
3451 threshold
= IEEE80211_RTS_MAX
;
3452 else if (vap
->iv_flags_ht
& IEEE80211_FHT_AMSDU_TX
)
3455 threshold
= vap
->iv_rtsthreshold
;
3457 RT2870_DPRINTF(sc
, RT2870_DEBUG_PROT
,
3458 "%s: updating RTS threshold: %d\n",
3459 device_get_nameunit(sc
->dev
), threshold
);
3461 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_TX_RTS_CFG
);
3463 tmp
&= ~(RT2870_REG_TX_RTS_THRESHOLD_MASK
<< RT2870_REG_TX_RTS_THRESHOLD_SHIFT
);
3465 tmp
|= ((threshold
& RT2870_REG_TX_RTS_THRESHOLD_MASK
) <<
3466 RT2870_REG_TX_RTS_THRESHOLD_SHIFT
);
3468 rt2870_io_mac_write(sc
, RT2870_REG_TX_RTS_CFG
, tmp
);
3472 * rt2870_asic_update_txpower
3474 static void rt2870_asic_update_txpower(struct rt2870_softc
*sc
)
3477 struct ieee80211com
*ic
;
3478 uint32_t *txpow_rate
;
3487 RT2870_DPRINTF(sc
, RT2870_DEBUG_STATE
,
3488 "%s: updating Tx power: %d\n",
3489 device_get_nameunit(sc
->dev
), ic
->ic_txpowlimit
);
3491 if (!IEEE80211_IS_CHAN_HT40(ic
->ic_curchan
))
3493 txpow_rate
= sc
->txpow_rate_20mhz
;
3497 if (IEEE80211_IS_CHAN_2GHZ(ic
->ic_curchan
))
3498 txpow_rate
= sc
->txpow_rate_40mhz_2ghz
;
3500 txpow_rate
= sc
->txpow_rate_40mhz_5ghz
;
3505 val
= rt2870_io_bbp_read(sc
, 1);
3508 if (ic
->ic_txpowlimit
> 90)
3512 else if (ic
->ic_txpowlimit
> 60)
3516 else if (ic
->ic_txpowlimit
> 30)
3520 else if (ic
->ic_txpowlimit
> 15)
3524 else if (ic
->ic_txpowlimit
> 9)
3534 rt2870_io_bbp_write(sc
, 1, val
);
3536 for (i
= 0; i
< RT2870_SOFTC_TXPOW_RATE_COUNT
; i
++)
3538 if (txpow_rate
[i
] == 0xffffffff)
3541 tmp
= rt2870_read_eeprom_txpow_rate_add_delta(txpow_rate
[i
], delta
);
3543 rt2870_io_mac_write(sc
, RT2870_REG_TX_PWR_CFG(i
), tmp
);
3548 * rt2870_asic_update_promisc
3550 static void rt2870_asic_update_promisc(struct rt2870_softc
*sc
)
3557 printf("%s: %s promiscuous mode\n",
3558 device_get_nameunit(sc
->dev
),
3559 (ifp
->if_flags
& IFF_PROMISC
) ? "entering" : "leaving");
3561 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_RX_FILTER_CFG
);
3563 tmp
&= ~RT2870_REG_RX_FILTER_DROP_UC_NOME
;
3565 if (!(ifp
->if_flags
& IFF_PROMISC
))
3566 tmp
|= RT2870_REG_RX_FILTER_DROP_UC_NOME
;
3568 rt2870_io_mac_write(sc
, RT2870_REG_RX_FILTER_CFG
, tmp
);
3572 * rt2870_asic_updateprot
3574 static void rt2870_asic_updateprot(struct rt2870_softc
*sc
)
3577 struct ieee80211com
*ic
;
3578 struct ieee80211vap
*vap
;
3579 uint32_t cck_prot
, ofdm_prot
, mm20_prot
, mm40_prot
, gf20_prot
, gf40_prot
;
3581 enum ieee80211_protmode htprotmode
;
3585 vap
= TAILQ_FIRST(&ic
->ic_vaps
);
3587 /* CCK frame protection */
3589 cck_prot
= RT2870_REG_RTSTH_ENABLE
| RT2870_REG_PROT_NAV_SHORT
|
3590 RT2870_REG_TXOP_ALLOW_ALL
| RT2870_REG_PROT_CTRL_NONE
;
3592 /* set up protection frame phy mode and rate (MCS code) */
3594 if (ic
->ic_curmode
== IEEE80211_MODE_11A
)
3595 cck_prot
|= (RT2870_REG_PROT_PHYMODE_OFDM
<< RT2870_REG_PROT_PHYMODE_SHIFT
) |
3596 (0 << RT2870_REG_PROT_MCS_SHIFT
);
3598 cck_prot
|= ((RT2870_REG_PROT_PHYMODE_CCK
<< RT2870_REG_PROT_PHYMODE_SHIFT
) |
3599 (3 << RT2870_REG_PROT_MCS_SHIFT
));
3601 rt2870_io_mac_write(sc
, RT2870_REG_TX_CCK_PROT_CFG
, cck_prot
);
3603 /* OFDM frame protection */
3605 ofdm_prot
= RT2870_REG_RTSTH_ENABLE
| RT2870_REG_PROT_NAV_SHORT
|
3606 RT2870_REG_TXOP_ALLOW_ALL
;
3608 if (ic
->ic_flags
& IEEE80211_F_USEPROT
)
3610 RT2870_DPRINTF(sc
, RT2870_DEBUG_PROT
,
3611 "%s: updating protection mode: b/g protection mode=%s\n",
3612 device_get_nameunit(sc
->dev
),
3613 (ic
->ic_protmode
== IEEE80211_PROT_RTSCTS
) ? "RTS/CTS" :
3614 ((ic
->ic_protmode
== IEEE80211_PROT_CTSONLY
) ? "CTS-to-self" : "none"));
3616 if (ic
->ic_protmode
== IEEE80211_PROT_RTSCTS
)
3617 ofdm_prot
|= RT2870_REG_PROT_CTRL_RTS_CTS
;
3618 else if (ic
->ic_protmode
== IEEE80211_PROT_CTSONLY
)
3619 ofdm_prot
|= RT2870_REG_PROT_CTRL_CTS
;
3621 ofdm_prot
|= RT2870_REG_PROT_CTRL_NONE
;
3625 RT2870_DPRINTF(sc
, RT2870_DEBUG_PROT
,
3626 "%s: updating protection mode: b/g protection mode=%s\n",
3627 device_get_nameunit(sc
->dev
), "none");
3629 ofdm_prot
|= RT2870_REG_PROT_CTRL_NONE
;
3632 rt2870_io_mac_write(sc
, RT2870_REG_TX_OFDM_PROT_CFG
, ofdm_prot
);
3634 /* HT frame protection */
3636 if ((vap
!= NULL
) && (vap
->iv_opmode
== IEEE80211_M_STA
) && (vap
->iv_state
== IEEE80211_S_RUN
))
3637 htopmode
= vap
->iv_bss
->ni_htopmode
;
3639 htopmode
= ic
->ic_curhtprotmode
;
3641 htprotmode
= ic
->ic_htprotmode
;
3643 /* force HT mixed mode and RTS/CTS protection if A-MPDU Tx aggregation is enabled */
3645 if (sc
->tx_ampdu_sessions
> 0)
3647 RT2870_DPRINTF(sc
, RT2870_DEBUG_PROT
,
3648 "%s: updating protection mode: forcing HT mixed mode and RTS/CTS protection\n",
3649 device_get_nameunit(sc
->dev
));
3651 htopmode
= IEEE80211_HTINFO_OPMODE_MIXED
;
3652 htprotmode
= IEEE80211_PROT_RTSCTS
;
3655 RT2870_DPRINTF(sc
, RT2870_DEBUG_PROT
,
3656 "%s: updating protection mode: HT operation mode=0x%02x, protection mode=%s\n",
3657 device_get_nameunit(sc
->dev
),
3658 htopmode
& IEEE80211_HTINFO_OPMODE
,
3659 (htprotmode
== IEEE80211_PROT_RTSCTS
) ? "RTS/CTS" :
3660 ((htprotmode
== IEEE80211_PROT_CTSONLY
) ? "CTS-to-self" : "none"));
3662 switch (htopmode
& IEEE80211_HTINFO_OPMODE
)
3664 /* IEEE80211_HTINFO_OPMODE_HT20PR */
3665 case IEEE80211_HTINFO_OPMODE_HT20PR
:
3666 mm20_prot
= RT2870_REG_PROT_NAV_SHORT
| RT2870_REG_PROT_CTRL_NONE
|
3667 RT2870_REG_TXOP_ALLOW_CCK
| RT2870_REG_TXOP_ALLOW_OFDM
|
3668 RT2870_REG_TXOP_ALLOW_MM20
| RT2870_REG_TXOP_ALLOW_GF20
|
3669 (RT2870_REG_PROT_PHYMODE_OFDM
<< RT2870_REG_PROT_PHYMODE_SHIFT
) |
3670 (4 << RT2870_REG_PROT_MCS_SHIFT
);
3672 gf20_prot
= mm20_prot
;
3674 mm40_prot
= RT2870_REG_PROT_NAV_SHORT
| RT2870_REG_PROT_CTRL_NONE
|
3675 RT2870_REG_TXOP_ALLOW_ALL
|
3676 (RT2870_REG_PROT_PHYMODE_OFDM
<< RT2870_REG_PROT_PHYMODE_SHIFT
) |
3677 (0x84 << RT2870_REG_PROT_MCS_SHIFT
);
3679 if (htprotmode
== IEEE80211_PROT_RTSCTS
)
3680 mm40_prot
|= RT2870_REG_PROT_CTRL_RTS_CTS
;
3681 else if (htprotmode
== IEEE80211_PROT_CTSONLY
)
3682 mm40_prot
|= RT2870_REG_PROT_CTRL_CTS
;
3684 mm40_prot
|= RT2870_REG_PROT_CTRL_NONE
;
3686 gf40_prot
= mm40_prot
;
3689 /* IEEE80211_HTINFO_OPMODE_MIXED */
3690 case IEEE80211_HTINFO_OPMODE_MIXED
:
3691 mm20_prot
= RT2870_REG_PROT_NAV_SHORT
|
3692 RT2870_REG_TXOP_ALLOW_CCK
| RT2870_REG_TXOP_ALLOW_OFDM
|
3693 RT2870_REG_TXOP_ALLOW_MM20
| RT2870_REG_TXOP_ALLOW_GF20
;
3695 if (ic
->ic_flags
& IEEE80211_F_USEPROT
)
3696 mm20_prot
|= (RT2870_REG_PROT_PHYMODE_CCK
<< RT2870_REG_PROT_PHYMODE_SHIFT
) |
3697 (3 << RT2870_REG_PROT_MCS_SHIFT
);
3699 mm20_prot
|= (RT2870_REG_PROT_PHYMODE_OFDM
<< RT2870_REG_PROT_PHYMODE_SHIFT
) |
3700 (4 << RT2870_REG_PROT_MCS_SHIFT
);
3702 if (htprotmode
== IEEE80211_PROT_RTSCTS
)
3703 mm20_prot
|= RT2870_REG_PROT_CTRL_RTS_CTS
;
3704 else if (htprotmode
== IEEE80211_PROT_CTSONLY
)
3705 mm20_prot
|= RT2870_REG_PROT_CTRL_CTS
;
3707 mm20_prot
|= RT2870_REG_PROT_CTRL_NONE
;
3709 gf20_prot
= mm20_prot
;
3711 mm40_prot
= RT2870_REG_PROT_NAV_SHORT
| RT2870_REG_TXOP_ALLOW_ALL
;
3713 if (ic
->ic_flags
& IEEE80211_F_USEPROT
)
3714 mm40_prot
|= (RT2870_REG_PROT_PHYMODE_CCK
<< RT2870_REG_PROT_PHYMODE_SHIFT
) |
3715 (3 << RT2870_REG_PROT_MCS_SHIFT
);
3717 mm40_prot
|= (RT2870_REG_PROT_PHYMODE_OFDM
<< RT2870_REG_PROT_PHYMODE_SHIFT
) |
3718 (0x84 << RT2870_REG_PROT_MCS_SHIFT
);
3720 if (htprotmode
== IEEE80211_PROT_RTSCTS
)
3721 mm40_prot
|= RT2870_REG_PROT_CTRL_RTS_CTS
;
3722 else if (htprotmode
== IEEE80211_PROT_CTSONLY
)
3723 mm40_prot
|= RT2870_REG_PROT_CTRL_CTS
;
3725 mm40_prot
|= RT2870_REG_PROT_CTRL_NONE
;
3727 gf40_prot
= mm40_prot
;
3731 * IEEE80211_HTINFO_OPMODE_PURE
3732 * IEEE80211_HTINFO_OPMODE_PROTOPT
3734 case IEEE80211_HTINFO_OPMODE_PURE
:
3735 case IEEE80211_HTINFO_OPMODE_PROTOPT
:
3737 mm20_prot
= RT2870_REG_PROT_NAV_SHORT
| RT2870_REG_PROT_CTRL_NONE
|
3738 RT2870_REG_TXOP_ALLOW_CCK
| RT2870_REG_TXOP_ALLOW_OFDM
|
3739 RT2870_REG_TXOP_ALLOW_MM20
| RT2870_REG_TXOP_ALLOW_GF20
|
3740 (RT2870_REG_PROT_PHYMODE_OFDM
<< RT2870_REG_PROT_PHYMODE_SHIFT
) |
3741 (4 << RT2870_REG_PROT_MCS_SHIFT
);
3743 gf20_prot
= mm20_prot
;
3745 mm40_prot
= RT2870_REG_PROT_NAV_SHORT
| RT2870_REG_PROT_CTRL_NONE
|
3746 RT2870_REG_TXOP_ALLOW_ALL
|
3747 (RT2870_REG_PROT_PHYMODE_OFDM
<< RT2870_REG_PROT_PHYMODE_SHIFT
) |
3748 (0x84 << RT2870_REG_PROT_MCS_SHIFT
);
3750 gf40_prot
= mm40_prot
;
3754 rt2870_io_mac_write(sc
, RT2870_REG_TX_MM20_PROT_CFG
, mm20_prot
);
3755 rt2870_io_mac_write(sc
, RT2870_REG_TX_MM40_PROT_CFG
, mm40_prot
);
3756 rt2870_io_mac_write(sc
, RT2870_REG_TX_GF20_PROT_CFG
, gf20_prot
);
3757 rt2870_io_mac_write(sc
, RT2870_REG_TX_GF40_PROT_CFG
, gf40_prot
);
3761 * rt2870_asic_updateslot
3763 static void rt2870_asic_updateslot(struct rt2870_softc
*sc
)
3766 struct ieee80211com
*ic
;
3767 struct ieee80211vap
*vap
;
3772 vap
= TAILQ_FIRST(&ic
->ic_vaps
);
3774 RT2870_DPRINTF(sc
, RT2870_DEBUG_STATE
,
3775 "%s: %s short slot time\n",
3776 device_get_nameunit(sc
->dev
),
3777 ((ic
->ic_flags
& IEEE80211_F_SHSLOT
) ||
3778 ((vap
!= NULL
) && (vap
->iv_flags
& IEEE80211_F_BURST
))) ? "enabling" : "disabling");
3780 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_BKOFF_SLOT_CFG
);
3784 if ((ic
->ic_flags
& IEEE80211_F_SHSLOT
) ||
3785 ((vap
!= NULL
) && (vap
->iv_flags
& IEEE80211_F_BURST
)))
3786 tmp
|= IEEE80211_DUR_SHSLOT
;
3788 tmp
|= IEEE80211_DUR_SLOT
;
3790 rt2870_io_mac_write(sc
, RT2870_REG_BKOFF_SLOT_CFG
, tmp
);
3794 * rt2870_asic_wme_update
3796 static void rt2870_asic_wme_update(struct rt2870_softc
*sc
)
3799 struct ieee80211com
*ic
;
3800 struct ieee80211_wme_state
*wme
;
3801 const struct wmeParams
*wmep
;
3807 wmep
= wme
->wme_chanParams
.cap_wmeParams
;
3809 RT2870_DPRINTF(sc
, RT2870_DEBUG_WME
,
3810 "%s: wme update: WME_AC_VO=%d/%d/%d/%d, WME_AC_VI=%d/%d/%d/%d, "
3811 "WME_AC_BK=%d/%d/%d/%d, WME_AC_BE=%d/%d/%d/%d\n",
3812 device_get_nameunit(sc
->dev
),
3813 wmep
[WME_AC_VO
].wmep_aifsn
,
3814 wmep
[WME_AC_VO
].wmep_logcwmin
, wmep
[WME_AC_VO
].wmep_logcwmax
,
3815 wmep
[WME_AC_VO
].wmep_txopLimit
,
3816 wmep
[WME_AC_VI
].wmep_aifsn
,
3817 wmep
[WME_AC_VI
].wmep_logcwmin
, wmep
[WME_AC_VI
].wmep_logcwmax
,
3818 wmep
[WME_AC_VI
].wmep_txopLimit
,
3819 wmep
[WME_AC_BK
].wmep_aifsn
,
3820 wmep
[WME_AC_BK
].wmep_logcwmin
, wmep
[WME_AC_BK
].wmep_logcwmax
,
3821 wmep
[WME_AC_BK
].wmep_txopLimit
,
3822 wmep
[WME_AC_BE
].wmep_aifsn
,
3823 wmep
[WME_AC_BE
].wmep_logcwmin
, wmep
[WME_AC_BE
].wmep_logcwmax
,
3824 wmep
[WME_AC_BE
].wmep_txopLimit
);
3826 for (i
= 0; i
< WME_NUM_AC
; i
++)
3827 rt2870_io_mac_write(sc
, RT2870_REG_TX_EDCA_AC_CFG(i
),
3828 (wmep
[i
].wmep_logcwmax
<< 16) | (wmep
[i
].wmep_logcwmin
<< 12) |
3829 (wmep
[i
].wmep_aifsn
<< 8) | wmep
[i
].wmep_txopLimit
);
3831 rt2870_io_mac_write(sc
, RT2870_REG_SCHDMA_WMM_AIFSN_CFG
,
3832 (wmep
[WME_AC_VO
].wmep_aifsn
<< 12) | (wmep
[WME_AC_VI
].wmep_aifsn
<< 8) |
3833 (wmep
[WME_AC_BK
].wmep_aifsn
<< 4) | wmep
[WME_AC_BE
].wmep_aifsn
);
3835 rt2870_io_mac_write(sc
, RT2870_REG_SCHDMA_WMM_CWMIN_CFG
,
3836 (wmep
[WME_AC_VO
].wmep_logcwmin
<< 12) | (wmep
[WME_AC_VI
].wmep_logcwmin
<< 8) |
3837 (wmep
[WME_AC_BK
].wmep_logcwmin
<< 4) | wmep
[WME_AC_BE
].wmep_logcwmin
);
3839 rt2870_io_mac_write(sc
, RT2870_REG_SCHDMA_WMM_CWMAX_CFG
,
3840 (wmep
[WME_AC_VO
].wmep_logcwmax
<< 12) | (wmep
[WME_AC_VI
].wmep_logcwmax
<< 8) |
3841 (wmep
[WME_AC_BK
].wmep_logcwmax
<< 4) | wmep
[WME_AC_BE
].wmep_logcwmax
);
3843 rt2870_io_mac_write(sc
, RT2870_REG_SCHDMA_WMM_TXOP0_CFG
,
3844 (wmep
[WME_AC_BK
].wmep_txopLimit
<< 16) | wmep
[WME_AC_BE
].wmep_txopLimit
);
3846 rt2870_io_mac_write(sc
, RT2870_REG_SCHDMA_WMM_TXOP1_CFG
,
3847 (wmep
[WME_AC_VO
].wmep_txopLimit
<< 16) | wmep
[WME_AC_VI
].wmep_txopLimit
);
3851 * rt2870_asic_update_beacon
3853 static void rt2870_asic_update_beacon(struct rt2870_softc
*sc
,
3854 struct ieee80211vap
*vap
)
3856 struct rt2870_softc_vap
*rvap
;
3858 struct rt2870_txwi
*txwi
;
3861 rvap
= (struct rt2870_softc_vap
*) vap
;
3863 m
= rvap
->beacon_mbuf
;
3864 txwi
= &rvap
->beacon_txwi
;
3866 /* disable temporarily TSF sync */
3868 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_BCN_TIME_CFG
);
3870 tmp
&= ~(RT2870_REG_BCN_TX_ENABLE
|
3871 RT2870_REG_TSF_TIMER_ENABLE
|
3872 RT2870_REG_TBTT_TIMER_ENABLE
);
3874 rt2870_io_mac_write(sc
, RT2870_REG_BCN_TIME_CFG
, tmp
);
3876 /* write Tx wireless info and beacon frame to on-chip memory */
3878 rt2870_io_mac_write_multi(sc
, RT2870_REG_BEACON_BASE(0),
3879 txwi
, sizeof(struct rt2870_txwi
));
3881 rt2870_io_mac_write_multi(sc
, RT2870_REG_BEACON_BASE(0) + sizeof(struct rt2870_txwi
),
3882 mtod(m
, uint8_t *), m
->m_pkthdr
.len
);
3884 /* enable again TSF sync */
3886 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_BCN_TIME_CFG
);
3888 tmp
|= (RT2870_REG_BCN_TX_ENABLE
|
3889 RT2870_REG_TSF_TIMER_ENABLE
|
3890 RT2870_REG_TBTT_TIMER_ENABLE
);
3892 rt2870_io_mac_write(sc
, RT2870_REG_BCN_TIME_CFG
, tmp
);
3896 * rt2870_asic_clear_keytables
3898 static void rt2870_asic_clear_keytables(struct rt2870_softc
*sc
)
3902 /* clear Rx WCID search table (entries = 256, entry size = 8) */
3904 for (i
= 0; i
< 256; i
++)
3906 rt2870_io_mac_write(sc
, RT2870_REG_WCID(i
), 0xffffffff);
3907 rt2870_io_mac_write(sc
, RT2870_REG_WCID(i
) + 4, 0x0000ffff);
3910 /* clear WCID attribute table (entries = 256, entry size = 4) */
3912 rt2870_io_mac_set_region_4(sc
, RT2870_REG_WCID_ATTR(0), 0, 256);
3914 /* clear IV/EIV table (entries = 256, entry size = 8) */
3916 rt2870_io_mac_set_region_4(sc
, RT2870_REG_IVEIV(0), 0, 2 * 256);
3918 /* clear pairwise key table (entries = 256, entry size = 32) */
3920 rt2870_io_mac_set_region_4(sc
, RT2870_REG_PKEY(0), 0, 8 * 256);
3922 /* clear shared key table (entries = 32, entry size = 32) */
3924 rt2870_io_mac_set_region_4(sc
, RT2870_REG_SKEY(0, 0), 0, 8 * 32);
3926 /* clear shared key mode (entries = 32, entry size = 2) */
3928 rt2870_io_mac_set_region_4(sc
, RT2870_REG_SKEY_MODE(0), 0, 16);
3932 * rt2870_beacon_alloc
3934 static int rt2870_beacon_alloc(struct rt2870_softc
*sc
,
3935 struct ieee80211vap
*vap
)
3937 struct ieee80211com
*ic
;
3938 struct rt2870_softc_vap
*rvap
;
3939 const struct ieee80211_txparam
*tp
;
3941 struct rt2870_txwi txwi
;
3945 rvap
= (struct rt2870_softc_vap
*) vap
;
3946 tp
= &vap
->iv_txparms
[ieee80211_chan2mode(ic
->ic_bsschan
)];
3948 m
= ieee80211_beacon_alloc(vap
->iv_bss
, &rvap
->beacon_offsets
);
3952 rate
= tp
->mgmtrate
;
3953 mcs
= rt2870_rate2mcs(rate
);
3955 memset(&txwi
, 0, sizeof(struct rt2870_txwi
));
3957 txwi
.wcid
= RT2870_WCID_RESERVED
;
3958 txwi
.pid_mpdu_len
= ((htole16(m
->m_pkthdr
.len
) & RT2870_TXWI_MPDU_LEN_MASK
) <<
3959 RT2870_TXWI_MPDU_LEN_SHIFT
);
3960 txwi
.txop
= (RT2870_TXWI_TXOP_HT
<< RT2870_TXWI_TXOP_SHIFT
);
3961 txwi
.mpdu_density_flags
|=
3962 (RT2870_TXWI_FLAGS_TS
<< RT2870_TXWI_FLAGS_SHIFT
);
3963 txwi
.bawin_size_xflags
|=
3964 (RT2870_TXWI_XFLAGS_NSEQ
<< RT2870_TXWI_XFLAGS_SHIFT
);
3966 if (ieee80211_rate2phytype(ic
->ic_rt
, rate
) != IEEE80211_T_OFDM
)
3968 txwi
.phymode_ifs_stbc_shortgi
=
3969 (RT2870_TXWI_PHYMODE_CCK
<< RT2870_TXWI_PHYMODE_SHIFT
);
3971 if (rate
!= 2 && (ic
->ic_flags
& IEEE80211_F_SHPREAMBLE
))
3972 mcs
|= RT2870_TXWI_MCS_SHOTPRE
;
3976 txwi
.phymode_ifs_stbc_shortgi
=
3977 (RT2870_TXWI_PHYMODE_OFDM
<< RT2870_TXWI_PHYMODE_SHIFT
);
3980 txwi
.bw_mcs
= (RT2870_TXWI_BW_20
<< RT2870_TXWI_BW_SHIFT
) |
3981 ((mcs
& RT2870_TXWI_MCS_MASK
) << RT2870_TXWI_MCS_SHIFT
);
3983 if (rvap
->beacon_mbuf
!= NULL
)
3985 m_free(rvap
->beacon_mbuf
);
3986 rvap
->beacon_mbuf
= NULL
;
3989 rvap
->beacon_mbuf
= m
;
3990 rvap
->beacon_txwi
= txwi
;
3998 static uint8_t rt2870_rxrate(struct rt2870_rxwi
*rxwi
)
4000 uint8_t mcs
, phymode
;
4003 mcs
= (rxwi
->bw_mcs
>> RT2870_RXWI_MCS_SHIFT
) & RT2870_RXWI_MCS_MASK
;
4004 phymode
= (rxwi
->phymode_stbc_shortgi
>> RT2870_RXWI_PHYMODE_SHIFT
) &
4005 RT2870_RXWI_PHYMODE_MASK
;
4011 case RT2870_RXWI_PHYMODE_CCK
:
4012 switch (mcs
& ~RT2870_RXWI_MCS_SHOTPRE
)
4014 case 0: rate
= 2; break; /* 1 Mbps */
4015 case 1: rate
= 4; break; /* 2 MBps */
4016 case 2: rate
= 11; break; /* 5.5 Mbps */
4017 case 3: rate
= 22; break; /* 11 Mbps */
4021 case RT2870_RXWI_PHYMODE_OFDM
:
4024 case 0: rate
= 12; break; /* 6 Mbps */
4025 case 1: rate
= 18; break; /* 9 Mbps */
4026 case 2: rate
= 24; break; /* 12 Mbps */
4027 case 3: rate
= 36; break; /* 18 Mbps */
4028 case 4: rate
= 48; break; /* 24 Mbps */
4029 case 5: rate
= 72; break; /* 36 Mbps */
4030 case 6: rate
= 96; break; /* 48 Mbps */
4031 case 7: rate
= 108; break; /* 54 Mbps */
4035 case RT2870_RXWI_PHYMODE_HT_MIXED
:
4036 case RT2870_RXWI_PHYMODE_HT_GF
:
4044 * rt2870_maxrssi_rxpath
4046 static uint8_t rt2870_maxrssi_rxpath(struct rt2870_softc
*sc
,
4047 const struct rt2870_rxwi
*rxwi
)
4053 if (sc
->nrxpath
> 1)
4054 if (rxwi
->rssi
[1] > rxwi
->rssi
[rxpath
])
4057 if (sc
->nrxpath
> 2)
4058 if (rxwi
->rssi
[2] > rxwi
->rssi
[rxpath
])
4067 static int8_t rt2870_rssi2dbm(struct rt2870_softc
*sc
,
4068 uint8_t rssi
, uint8_t rxpath
)
4071 struct ieee80211com
*ic
;
4072 struct ieee80211_channel
*c
;
4074 int8_t rssi_off
, lna_gain
;
4082 chan
= ieee80211_chan2ieee(ic
, c
);
4084 if (IEEE80211_IS_CHAN_5GHZ(c
))
4086 rssi_off
= sc
->rssi_off_5ghz
[rxpath
];
4089 lna_gain
= sc
->lna_gain
[1];
4090 else if (chan
<= 128)
4091 lna_gain
= sc
->lna_gain
[2];
4093 lna_gain
= sc
->lna_gain
[3];
4097 rssi_off
= sc
->rssi_off_2ghz
[rxpath
];
4098 lna_gain
= sc
->lna_gain
[0];
4101 return (-12 - rssi_off
- lna_gain
- rssi
);
4107 static uint8_t rt2870_rate2mcs(uint8_t rate
)
4134 static void rt2870_rx_frame(struct rt2870_softc
*sc
,
4135 uint8_t *buf
, uint32_t dmalen
)
4138 struct ieee80211com
*ic
;
4139 struct ieee80211_frame
*wh
;
4140 struct ieee80211_node
*ni
;
4141 struct rt2870_softc_node
*rni
;
4142 struct rt2870_softc_rx_radiotap_header
*tap
;
4143 struct rt2870_rxwi
*rxwi
;
4144 struct rt2870_rxinfo
*rxinfo
;
4146 uint32_t rxinfo_flags
;
4147 uint8_t cipher_err
, rssi
, ant
, phymode
, bw
, shortgi
, mcs
, keyidx
;
4149 int len
, ampdu
, amsdu
, rssi_dbm_rel
, i
;
4154 /* get Rx wireless info */
4156 rxwi
= (struct rt2870_rxwi
*) buf
;
4157 len
= (le16toh(rxwi
->tid_size
) >> RT2870_RXWI_SIZE_SHIFT
) &
4158 RT2870_RXWI_SIZE_MASK
;
4162 RT2870_DPRINTF(sc
, RT2870_DEBUG_RX
,
4163 "%s: bad rxwi len: DMA len=%d, rxwi len=%d\n",
4164 device_get_nameunit(sc
->dev
), dmalen
, len
);
4170 rxinfo
= (struct rt2870_rxinfo
*) ((caddr_t
) rxwi
+ dmalen
);
4171 rxinfo_flags
= le32toh(rxinfo
->flags
);
4173 RT2870_DPRINTF(sc
, RT2870_DEBUG_RX
,
4174 "%s: Rx frame: DMA len=%d, len=%d, rxinfo flags=0x%08x\n",
4175 device_get_nameunit(sc
->dev
), dmalen
, len
, rxinfo_flags
);
4177 /* check for crc errors */
4179 if (rxinfo_flags
& RT2870_RXINFO_FLAGS_CRC_ERR
)
4181 RT2870_DPRINTF(sc
, RT2870_DEBUG_RX
,
4182 "%s: rxinfo: crc error\n",
4183 device_get_nameunit(sc
->dev
));
4187 if (!(ifp
->if_flags
& IFF_PROMISC
))
4191 wh
= (struct ieee80211_frame
*) (rxwi
+ 1);
4193 /* check for L2 padding between IEEE 802.11 frame header and body */
4195 if (rxinfo_flags
& RT2870_RXINFO_FLAGS_L2PAD
)
4197 RT2870_DPRINTF(sc
, RT2870_DEBUG_RX
,
4198 "%s: L2 padding: DMA len=%d, len=%d\n",
4199 device_get_nameunit(sc
->dev
), dmalen
, len
);
4204 m
= m_getjcl(M_DONTWAIT
, MT_DATA
, M_PKTHDR
, MJUMPAGESIZE
);
4207 sc
->rx_mbuf_alloc_errors
++;
4212 m
->m_pkthdr
.rcvif
= ifp
;
4213 m
->m_pkthdr
.len
= m
->m_len
= len
;
4215 m_copyback(m
, 0, len
, (caddr_t
) wh
);
4217 wh
= mtod(m
, struct ieee80211_frame
*);
4219 /* check for cipher errors */
4221 if (rxinfo_flags
& RT2870_RXINFO_FLAGS_DECRYPTED
)
4223 cipher_err
= ((rxinfo_flags
>> RT2870_RXINFO_FLAGS_CIPHER_ERR_SHIFT
) &
4224 RT2870_RXINFO_FLAGS_CIPHER_ERR_MASK
);
4225 if (cipher_err
== RT2870_RXINFO_FLAGS_CIPHER_ERR_NONE
)
4227 if (wh
->i_fc
[1] & IEEE80211_FC1_WEP
)
4228 wh
->i_fc
[1] &= ~IEEE80211_FC1_WEP
;
4230 m
->m_flags
|= M_WEP
;
4232 sc
->rx_cipher_no_errors
++;
4236 RT2870_DPRINTF(sc
, RT2870_DEBUG_RX
,
4237 "%s: rxinfo: cipher error=0x%02x\n",
4238 device_get_nameunit(sc
->dev
), cipher_err
);
4240 if (cipher_err
== RT2870_RXINFO_FLAGS_CIPHER_ERR_ICV
)
4241 sc
->rx_cipher_icv_errors
++;
4242 else if (cipher_err
== RT2870_RXINFO_FLAGS_CIPHER_ERR_MIC
)
4243 sc
->rx_cipher_mic_errors
++;
4244 else if (cipher_err
== RT2870_RXINFO_FLAGS_CIPHER_ERR_INVALID_KEY
)
4245 sc
->rx_cipher_invalid_key_errors
++;
4247 if ((cipher_err
== RT2870_RXINFO_FLAGS_CIPHER_ERR_MIC
) &&
4248 (rxinfo_flags
& RT2870_RXINFO_FLAGS_MYBSS
))
4250 ni
= ieee80211_find_rxnode(ic
, (const struct ieee80211_frame_min
*) wh
);
4253 keyidx
= (rxwi
->udf_bssidx_keyidx
>> RT2870_RXWI_KEYIDX_SHIFT
) &
4254 RT2870_RXWI_KEYIDX_MASK
;
4256 ieee80211_notify_michael_failure(ni
->ni_vap
, wh
, keyidx
);
4258 ieee80211_free_node(ni
);
4264 if (!(ifp
->if_flags
& IFF_PROMISC
))
4273 if (wh
->i_fc
[1] & IEEE80211_FC1_WEP
)
4275 RT2870_DPRINTF(sc
, RT2870_DEBUG_RX
,
4276 "%s: rxinfo: not decrypted but protected flag set\n",
4277 device_get_nameunit(sc
->dev
));
4281 if (!(ifp
->if_flags
& IFF_PROMISC
))
4289 /* check for A-MPDU */
4291 if (rxinfo_flags
& RT2870_RXINFO_FLAGS_AMPDU
)
4293 m
->m_flags
|= M_AMPDU
;
4304 /* check for A-MSDU */
4306 if (rxinfo_flags
& RT2870_RXINFO_FLAGS_AMSDU
)
4317 ant
= rt2870_maxrssi_rxpath(sc
, rxwi
);
4318 rssi
= rxwi
->rssi
[ant
];
4319 rssi_dbm
= rt2870_rssi2dbm(sc
, rssi
, ant
);
4320 phymode
= ((rxwi
->phymode_stbc_shortgi
>> RT2870_RXWI_PHYMODE_SHIFT
) &
4321 RT2870_RXWI_PHYMODE_MASK
);
4322 bw
= ((rxwi
->bw_mcs
>> RT2870_RXWI_BW_SHIFT
) & RT2870_RXWI_BW_MASK
);
4323 shortgi
= ((rxwi
->phymode_stbc_shortgi
>> RT2870_RXWI_SHORTGI_SHIFT
) &
4324 RT2870_RXWI_SHORTGI_MASK
);
4325 mcs
= ((rxwi
->bw_mcs
>> RT2870_RXWI_MCS_SHIFT
) & RT2870_RXWI_MCS_MASK
);
4327 if (ieee80211_radiotap_active(ic
))
4331 tap
->flags
= (rxinfo_flags
& RT2870_RXINFO_FLAGS_L2PAD
) ? IEEE80211_RADIOTAP_F_DATAPAD
: 0;
4332 tap
->dbm_antsignal
= rssi_dbm
;
4333 tap
->dbm_antnoise
= RT2870_NOISE_FLOOR
;
4335 tap
->antsignal
= rssi
;
4336 tap
->chan_flags
= htole32(ic
->ic_curchan
->ic_flags
);
4337 tap
->chan_freq
= htole16(ic
->ic_curchan
->ic_freq
);
4338 tap
->chan_ieee
= ic
->ic_curchan
->ic_ieee
;
4339 tap
->chan_maxpow
= 0;
4341 if (phymode
== RT2870_RXWI_PHYMODE_CCK
|| phymode
== RT2870_RXWI_PHYMODE_OFDM
)
4342 tap
->rate
= rt2870_rxrate(rxwi
);
4344 tap
->rate
= mcs
| IEEE80211_RATE_MCS
;
4346 if (rxinfo_flags
& RT2870_RXINFO_FLAGS_CRC_ERR
)
4347 tap
->flags
|= IEEE80211_RADIOTAP_F_BADFCS
;
4349 if (rxinfo_flags
& RT2870_RXINFO_FLAGS_FRAG
)
4350 tap
->flags
|= IEEE80211_RADIOTAP_F_FRAG
;
4352 if (rxwi
->bw_mcs
& RT2870_RXWI_MCS_SHOTPRE
)
4353 tap
->flags
|= IEEE80211_RADIOTAP_F_SHORTPRE
;
4355 if ((rxinfo_flags
& RT2870_RXINFO_FLAGS_DECRYPTED
) ||
4356 (wh
->i_fc
[1] & IEEE80211_FC1_WEP
))
4357 tap
->flags
|= IEEE80211_RADIOTAP_F_WEP
;
4360 tap
->flags
|= IEEE80211_RADIOTAP_F_SHORTGI
;
4364 * net80211 assumes that RSSI data are in the range [-127..127] and
4365 * in .5 dBm units relative to the current noise floor
4368 rssi_dbm_rel
= (rssi_dbm
- RT2870_NOISE_FLOOR
) * 2;
4369 if (rssi_dbm_rel
> 127)
4372 RT2870_DPRINTF(sc
, RT2870_DEBUG_RX
,
4373 "%s: received frame: len=%d, phymode=%d, bw=%d, shortgi=%d, mcs=%d, "
4374 "ant=%d, rssi=%d/%d/%d, snr=%d/%d, wcid=0x%02x, ampdu=%d, amsdu=%d, "
4375 "rssi_dbm=%d, rssi_dbm_rel=%d\n",
4376 device_get_nameunit(sc
->dev
),
4377 len
, phymode
, bw
, shortgi
, mcs
,
4378 ant
, rxwi
->rssi
[0], rxwi
->rssi
[1], rxwi
->rssi
[2],
4379 rxwi
->snr
[0], rxwi
->snr
[1],
4380 rxwi
->wcid
, ampdu
, amsdu
, rssi_dbm
, rssi_dbm_rel
);
4382 ni
= ieee80211_find_rxnode(ic
, (struct ieee80211_frame_min
*) wh
);
4385 rni
= (struct rt2870_softc_node
*) ni
;
4387 for (i
= 0; i
< RT2870_SOFTC_RSSI_COUNT
; i
++)
4389 rni
->last_rssi
[i
] = rxwi
->rssi
[i
];
4390 rni
->last_rssi_dbm
[i
] = rt2870_rssi2dbm(sc
, rxwi
->rssi
[i
], i
);
4393 ieee80211_input(ni
, m
, rssi_dbm_rel
, RT2870_NOISE_FLOOR
);
4394 ieee80211_free_node(ni
);
4398 ieee80211_input_all(ic
, m
, rssi_dbm_rel
, RT2870_NOISE_FLOOR
);
4405 static int rt2870_tx_mgmt(struct rt2870_softc
*sc
,
4406 struct mbuf
*m
, struct ieee80211_node
*ni
, int qid
)
4409 struct ieee80211com
*ic
;
4410 struct ieee80211vap
*vap
;
4411 const struct ieee80211_txparam
*tp
;
4412 struct rt2870_softc_node
*rni
;
4413 struct rt2870_softc_tx_ring
*ring
;
4414 struct rt2870_softc_tx_data
*data
;
4415 struct rt2870_txinfo
*txinfo
;
4416 struct rt2870_txwi
*txwi
;
4417 struct ieee80211_frame
*wh
;
4418 struct rt2870_softc_tx_radiotap_header
*tap
;
4419 u_int hdrsize
, hdrspace
;
4420 uint8_t rate
, stbc
, shortgi
, mcs
, pid
;
4421 uint16_t len
, dmalen
, mpdu_len
, dur
;
4424 KASSERT(qid
>= 0 && qid
< (sc
->usb_endpoints
- 1),
4425 ("%s: Tx MGMT: invalid qid=%d\n",
4426 device_get_nameunit(sc
->dev
), qid
));
4431 rni
= (struct rt2870_softc_node
*) ni
;
4432 tp
= ni
->ni_txparms
;
4434 ring
= &sc
->tx_ring
[qid
];
4435 data
= STAILQ_FIRST(&ring
->inactive
);
4436 STAILQ_REMOVE_HEAD(&ring
->inactive
, next
);
4437 txinfo
= (struct rt2870_txinfo
*) data
->buf
;
4438 txwi
= (struct rt2870_txwi
*) (txinfo
+ 1);
4440 wh
= mtod(m
, struct ieee80211_frame
*);
4442 rate
= tp
->mgmtrate
& IEEE80211_RATE_VAL
;
4444 len
= sizeof(struct rt2870_txinfo
) + sizeof(struct rt2870_txwi
) + m
->m_pkthdr
.len
;
4446 /* align end on a 4-bytes boundary */
4448 dmalen
= (len
+ 3) & ~3;
4452 memset(txinfo
, 0, sizeof(struct rt2870_txinfo
));
4454 txinfo
->len
= htole16(dmalen
- sizeof(struct rt2870_txinfo
));
4456 txinfo
->qsel_flags
= (RT2870_TXINFO_QSEL_EDCA
<< RT2870_TXINFO_QSEL_SHIFT
);
4460 memset((caddr_t
) txinfo
+ len
, 0, dmalen
- len
);
4462 /* fill Tx wireless info */
4464 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
4467 mcs
= rt2870_rate2mcs(rate
);
4469 /* calculate MPDU length without padding */
4471 hdrsize
= ieee80211_hdrsize(wh
);
4472 hdrspace
= ieee80211_hdrspace(ic
, wh
);
4473 mpdu_len
= m
->m_pkthdr
.len
- hdrspace
+ hdrsize
;
4475 memset(txwi
, 0, sizeof(struct rt2870_txwi
));
4477 /* management frames do not need encryption */
4481 /* MIMO power save */
4483 if ((ni
->ni_flags
& IEEE80211_NODE_HT
) && (ni
->ni_flags
& IEEE80211_NODE_MIMO_PS
))
4487 if (ni
->ni_flags
& IEEE80211_NODE_MIMO_RTS
)
4489 /* dynamic MIMO power save */
4491 txwi
->mpdu_density_flags
|=
4492 (RT2870_TXWI_FLAGS_MIMOPS
<< RT2870_TXWI_FLAGS_SHIFT
);
4496 /* static MIMO power save */
4511 txwi
->pid_mpdu_len
= ((htole16(pid
) & RT2870_TXWI_PID_MASK
) <<
4512 RT2870_TXWI_PID_SHIFT
) | ((htole16(mpdu_len
) & RT2870_TXWI_MPDU_LEN_MASK
) <<
4513 RT2870_TXWI_MPDU_LEN_SHIFT
);
4515 stbc
= (ic
->ic_htcaps
& IEEE80211_HTCAP_TXSTBC
) &&
4516 (ni
->ni_flags
& IEEE80211_NODE_HT
) && (ni
->ni_htcap
& IEEE80211_HTCAP_RXSTBC
);
4518 shortgi
= (vap
->iv_flags_ht
& (IEEE80211_FHT_SHORTGI20
| IEEE80211_FHT_SHORTGI40
)) &&
4519 (ni
->ni_flags
& IEEE80211_NODE_HT
) && (ni
->ni_flags
& (IEEE80211_NODE_SGI20
| IEEE80211_NODE_SGI40
));
4521 txwi
->phymode_ifs_stbc_shortgi
|=
4522 ((stbc
& RT2870_TXWI_STBC_MASK
) << RT2870_TXWI_STBC_SHIFT
) |
4523 ((shortgi
& RT2870_TXWI_SHORTGI_MASK
) << RT2870_TXWI_SHORTGI_SHIFT
);
4525 txwi
->phymode_ifs_stbc_shortgi
|=
4526 ((shortgi
& RT2870_TXWI_SHORTGI_MASK
) << RT2870_TXWI_SHORTGI_SHIFT
);
4528 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
4530 txwi
->phymode_ifs_stbc_shortgi
|=
4531 (RT2870_TXWI_PHYMODE_HT_MIXED
<< RT2870_TXWI_PHYMODE_SHIFT
);
4535 if (ieee80211_rate2phytype(ic
->ic_rt
, rate
) != IEEE80211_T_OFDM
)
4537 txwi
->phymode_ifs_stbc_shortgi
|=
4538 (RT2870_TXWI_PHYMODE_CCK
<< RT2870_TXWI_PHYMODE_SHIFT
);
4540 if (rate
!= 2 && (ic
->ic_flags
& IEEE80211_F_SHPREAMBLE
))
4541 mcs
|= RT2870_TXWI_MCS_SHOTPRE
;
4545 txwi
->phymode_ifs_stbc_shortgi
|=
4546 (RT2870_TXWI_PHYMODE_OFDM
<< RT2870_TXWI_PHYMODE_SHIFT
);
4550 txwi
->bw_mcs
= (RT2870_TXWI_BW_20
<< RT2870_TXWI_BW_SHIFT
) |
4551 ((mcs
& RT2870_TXWI_MCS_MASK
) << RT2870_TXWI_MCS_SHIFT
);
4553 txwi
->txop
= (RT2870_TXWI_TXOP_BACKOFF
<< RT2870_TXWI_TXOP_SHIFT
);
4555 /* skip ACKs for multicast frames */
4557 if (!IEEE80211_IS_MULTICAST(wh
->i_addr1
))
4559 txwi
->bawin_size_xflags
|=
4560 (RT2870_TXWI_XFLAGS_ACK
<< RT2870_TXWI_XFLAGS_SHIFT
);
4562 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
4564 /* preamble + plcp + signal extension + SIFS */
4566 dur
= 16 + 4 + 6 + 10;
4570 dur
= ieee80211_ack_duration(ic
->ic_rt
, rate
,
4571 ic
->ic_flags
& IEEE80211_F_SHPREAMBLE
);
4574 *(uint16_t *) wh
->i_dur
= htole16(dur
);
4577 /* ask MAC to insert timestamp into probe responses */
4579 if ((wh
->i_fc
[0] & (IEEE80211_FC0_TYPE_MASK
| IEEE80211_FC0_SUBTYPE_MASK
)) ==
4580 (IEEE80211_FC0_TYPE_MGT
| IEEE80211_FC0_SUBTYPE_PROBE_RESP
))
4581 txwi
->mpdu_density_flags
|=
4582 (RT2870_TXWI_FLAGS_TS
<< RT2870_TXWI_FLAGS_SHIFT
);
4584 if (ieee80211_radiotap_active_vap(vap
))
4588 tap
->flags
= IEEE80211_RADIOTAP_F_DATAPAD
;
4589 tap
->chan_flags
= htole32(ic
->ic_curchan
->ic_flags
);
4590 tap
->chan_freq
= htole16(ic
->ic_curchan
->ic_freq
);
4591 tap
->chan_ieee
= ic
->ic_curchan
->ic_ieee
;
4592 tap
->chan_maxpow
= 0;
4594 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
4595 tap
->rate
= mcs
| IEEE80211_RATE_MCS
;
4599 if (mcs
& RT2870_TXWI_MCS_SHOTPRE
)
4600 tap
->flags
|= IEEE80211_RADIOTAP_F_SHORTPRE
;
4603 tap
->flags
|= IEEE80211_RADIOTAP_F_SHORTGI
;
4605 if (wh
->i_fc
[1] & IEEE80211_FC1_WEP
)
4606 tap
->flags
|= IEEE80211_RADIOTAP_F_WEP
;
4608 if (wh
->i_fc
[1] & IEEE80211_FC1_WEP
)
4610 wh
->i_fc
[1] &= ~IEEE80211_FC1_WEP
;
4612 ieee80211_radiotap_tx(vap
, m
);
4614 wh
->i_fc
[1] |= IEEE80211_FC1_WEP
;
4618 ieee80211_radiotap_tx(vap
, m
);
4622 m_copydata(m
, 0, m
->m_pkthdr
.len
, (caddr_t
) (txwi
+ 1));
4624 RT2870_DPRINTF(sc
, RT2870_DEBUG_TX
,
4625 "%s: sending MGMT frame: qid=%d, hdrsize=%d, hdrspace=%d, len=%d, "
4626 "stbc=%d, shortgi=%d, mcs=%d, mimops=%d, DMA len=%d\n",
4627 device_get_nameunit(sc
->dev
),
4628 qid
, hdrsize
, hdrspace
, m
->m_pkthdr
.len
, stbc
, shortgi
, mcs
, mimops
, dmalen
);
4634 STAILQ_INSERT_TAIL(&ring
->pending
, data
, next
);
4637 usbd_transfer_start(sc
->usb_xfer
[1 + qid
]);
4645 static int rt2870_tx_data(struct rt2870_softc
*sc
,
4646 struct mbuf
*m
, struct ieee80211_node
*ni
, int qid
)
4649 struct ieee80211com
*ic
;
4650 struct ieee80211vap
*vap
;
4651 const struct ieee80211_txparam
*tp
;
4652 struct rt2870_softc_node
*rni
;
4653 struct rt2870_softc_tx_ring
*ring
;
4654 struct rt2870_softc_tx_data
*data
;
4655 struct rt2870_txinfo
*txinfo
;
4656 struct rt2870_txwi
*txwi
;
4657 struct ieee80211_frame
*wh
;
4658 struct ieee80211_tx_ampdu
*tx_ampdu
;
4659 ieee80211_seq seqno
;
4660 struct rt2870_softc_tx_radiotap_header
*tap
;
4661 u_int hdrsize
, hdrspace
;
4662 uint8_t type
, rate
, bw
, stbc
, shortgi
, mcs
, pid
, wcid
, mpdu_density
, bawin_size
;
4663 uint16_t qos
, len
, dmalen
, mpdu_len
, dur
;
4664 int hasqos
, ac
, tid
, ampdu
, mimops
;
4666 KASSERT(qid
>= 0 && qid
< (sc
->usb_endpoints
- 1),
4667 ("%s: Tx data: invalid qid=%d\n",
4668 device_get_nameunit(sc
->dev
), qid
));
4673 rni
= (struct rt2870_softc_node
*) ni
;
4674 tp
= ni
->ni_txparms
;
4676 ring
= &sc
->tx_ring
[qid
];
4677 data
= STAILQ_FIRST(&ring
->inactive
);
4678 STAILQ_REMOVE_HEAD(&ring
->inactive
, next
);
4679 txinfo
= (struct rt2870_txinfo
*) data
->buf
;
4680 txwi
= (struct rt2870_txwi
*) (txinfo
+ 1);
4682 wh
= mtod(m
, struct ieee80211_frame
*);
4684 type
= wh
->i_fc
[0] & IEEE80211_FC0_TYPE_MASK
;
4686 hasqos
= IEEE80211_QOS_HAS_SEQ(wh
);
4689 if (IEEE80211_HAS_ADDR4(wh
))
4690 qos
= le16toh(*(const uint16_t *)
4691 (((struct ieee80211_qosframe_addr4
*) wh
)->i_qos
));
4693 qos
= le16toh(*(const uint16_t *)
4694 (((struct ieee80211_qosframe
*) wh
)->i_qos
));
4701 if (IEEE80211_IS_MULTICAST(wh
->i_addr1
))
4702 rate
= tp
->mcastrate
;
4703 else if (m
->m_flags
& M_EAPOL
)
4704 rate
= tp
->mgmtrate
;
4705 else if (tp
->ucastrate
!= IEEE80211_FIXED_RATE_NONE
)
4706 rate
= tp
->ucastrate
;
4708 rate
= ni
->ni_txrate
;
4710 rate
&= IEEE80211_RATE_VAL
;
4712 len
= sizeof(struct rt2870_txinfo
) + sizeof(struct rt2870_txwi
) + m
->m_pkthdr
.len
;
4714 /* align end on a 4-bytes boundary */
4716 dmalen
= (len
+ 3) & ~3;
4720 memset(txinfo
, 0, sizeof(struct rt2870_txinfo
));
4722 txinfo
->len
= htole16(dmalen
- sizeof(struct rt2870_txinfo
));
4724 txinfo
->qsel_flags
= (RT2870_TXINFO_QSEL_EDCA
<< RT2870_TXINFO_QSEL_SHIFT
);
4728 memset((caddr_t
) txinfo
+ len
, 0, dmalen
- len
);
4730 /* fill Tx wireless info */
4732 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
4735 mcs
= rt2870_rate2mcs(rate
);
4737 if (type
== IEEE80211_FC0_TYPE_DATA
)
4738 wcid
= !IEEE80211_IS_MULTICAST(wh
->i_addr1
) ? rni
->staid
: RT2870_WCID_MCAST
;
4740 wcid
= RT2870_WCID_RESERVED
;
4742 /* calculate MPDU length without padding */
4744 hdrsize
= ieee80211_hdrsize(wh
);
4745 hdrspace
= ieee80211_hdrspace(ic
, wh
);
4746 mpdu_len
= m
->m_pkthdr
.len
- hdrspace
+ hdrsize
;
4748 memset(txwi
, 0, sizeof(struct rt2870_txwi
));
4752 /* MIMO power save */
4754 if ((ni
->ni_flags
& IEEE80211_NODE_HT
) && (ni
->ni_flags
& IEEE80211_NODE_MIMO_PS
))
4758 if (ni
->ni_flags
& IEEE80211_NODE_MIMO_RTS
)
4760 /* dynamic MIMO power save */
4762 txwi
->mpdu_density_flags
|=
4763 (RT2870_TXWI_FLAGS_MIMOPS
<< RT2870_TXWI_FLAGS_SHIFT
);
4767 /* static MIMO power save */
4782 txwi
->pid_mpdu_len
= ((htole16(pid
) & RT2870_TXWI_PID_MASK
) <<
4783 RT2870_TXWI_PID_SHIFT
) | ((htole16(mpdu_len
) & RT2870_TXWI_MPDU_LEN_MASK
) <<
4784 RT2870_TXWI_MPDU_LEN_SHIFT
);
4786 stbc
= (ic
->ic_htcaps
& IEEE80211_HTCAP_TXSTBC
) &&
4787 (ni
->ni_flags
& IEEE80211_NODE_HT
) && (ni
->ni_htcap
& IEEE80211_HTCAP_RXSTBC
);
4789 shortgi
= (vap
->iv_flags_ht
& (IEEE80211_FHT_SHORTGI20
| IEEE80211_FHT_SHORTGI40
)) &&
4790 (ni
->ni_flags
& IEEE80211_NODE_HT
) && (ni
->ni_flags
& (IEEE80211_NODE_SGI20
| IEEE80211_NODE_SGI40
));
4792 txwi
->phymode_ifs_stbc_shortgi
|=
4793 ((stbc
& RT2870_TXWI_STBC_MASK
) << RT2870_TXWI_STBC_SHIFT
) |
4794 ((shortgi
& RT2870_TXWI_SHORTGI_MASK
) << RT2870_TXWI_SHORTGI_SHIFT
);
4796 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
4798 txwi
->phymode_ifs_stbc_shortgi
|=
4799 (RT2870_TXWI_PHYMODE_HT_MIXED
<< RT2870_TXWI_PHYMODE_SHIFT
);
4803 if (ieee80211_rate2phytype(ic
->ic_rt
, rate
) != IEEE80211_T_OFDM
)
4805 txwi
->phymode_ifs_stbc_shortgi
|=
4806 (RT2870_TXWI_PHYMODE_CCK
<< RT2870_TXWI_PHYMODE_SHIFT
);
4808 if (rate
!= 2 && (ic
->ic_flags
& IEEE80211_F_SHPREAMBLE
))
4809 mcs
|= RT2870_TXWI_MCS_SHOTPRE
;
4813 txwi
->phymode_ifs_stbc_shortgi
|=
4814 (RT2870_TXWI_PHYMODE_OFDM
<< RT2870_TXWI_PHYMODE_SHIFT
);
4818 if ((ni
->ni_flags
& IEEE80211_NODE_HT
) && (ni
->ni_chw
== 40))
4819 bw
= RT2870_TXWI_BW_40
;
4821 bw
= RT2870_TXWI_BW_20
;
4823 txwi
->bw_mcs
= ((bw
& RT2870_TXWI_BW_MASK
) << RT2870_TXWI_BW_SHIFT
) |
4824 ((mcs
& RT2870_TXWI_MCS_MASK
) << RT2870_TXWI_MCS_SHIFT
);
4826 txwi
->txop
= (RT2870_TXWI_TXOP_HT
<< RT2870_TXWI_TXOP_SHIFT
);
4828 if (!IEEE80211_IS_MULTICAST(wh
->i_addr1
) &&
4829 (!hasqos
|| (qos
& IEEE80211_QOS_ACKPOLICY
) != IEEE80211_QOS_ACKPOLICY_NOACK
))
4831 txwi
->bawin_size_xflags
|=
4832 (RT2870_TXWI_XFLAGS_ACK
<< RT2870_TXWI_XFLAGS_SHIFT
);
4834 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
4836 /* preamble + plcp + signal extension + SIFS */
4838 dur
= 16 + 4 + 6 + 10;
4842 dur
= ieee80211_ack_duration(ic
->ic_rt
, rate
,
4843 ic
->ic_flags
& IEEE80211_F_SHPREAMBLE
);
4846 *(uint16_t *) wh
->i_dur
= htole16(dur
);
4849 /* check fo A-MPDU */
4851 if (m
->m_flags
& M_AMPDU_MPDU
)
4853 ac
= M_WME_GETAC(m
);
4854 tid
= WME_AC_TO_TID(ac
);
4855 tx_ampdu
= &ni
->ni_tx_ampdu
[ac
];
4857 mpdu_density
= RT2870_MS(ni
->ni_htparam
, IEEE80211_HTCAP_MPDUDENSITY
);
4858 bawin_size
= tx_ampdu
->txa_wnd
;
4860 txwi
->mpdu_density_flags
|=
4861 ((mpdu_density
& RT2870_TXWI_MPDU_DENSITY_MASK
) << RT2870_TXWI_MPDU_DENSITY_SHIFT
) |
4862 (RT2870_TXWI_FLAGS_AMPDU
<< RT2870_TXWI_FLAGS_SHIFT
);
4864 txwi
->bawin_size_xflags
|=
4865 ((bawin_size
& RT2870_TXWI_BAWIN_SIZE_MASK
) << RT2870_TXWI_BAWIN_SIZE_SHIFT
);
4867 seqno
= ni
->ni_txseqs
[tid
]++;
4869 *(uint16_t *) &wh
->i_seq
[0] = htole16(seqno
<< IEEE80211_SEQ_SEQ_SHIFT
);
4878 /* ask MAC to insert timestamp into probe responses */
4880 if ((wh
->i_fc
[0] & (IEEE80211_FC0_TYPE_MASK
| IEEE80211_FC0_SUBTYPE_MASK
)) ==
4881 (IEEE80211_FC0_TYPE_MGT
| IEEE80211_FC0_SUBTYPE_PROBE_RESP
))
4882 txwi
->mpdu_density_flags
|=
4883 (RT2870_TXWI_FLAGS_TS
<< RT2870_TXWI_FLAGS_SHIFT
);
4885 if (ieee80211_radiotap_active_vap(vap
))
4889 tap
->flags
= IEEE80211_RADIOTAP_F_DATAPAD
;
4890 tap
->chan_flags
= htole32(ic
->ic_curchan
->ic_flags
);
4891 tap
->chan_freq
= htole16(ic
->ic_curchan
->ic_freq
);
4892 tap
->chan_ieee
= ic
->ic_curchan
->ic_ieee
;
4893 tap
->chan_maxpow
= 0;
4895 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
4896 tap
->rate
= mcs
| IEEE80211_RATE_MCS
;
4900 if (mcs
& RT2870_TXWI_MCS_SHOTPRE
)
4901 tap
->flags
|= IEEE80211_RADIOTAP_F_SHORTPRE
;
4904 tap
->flags
|= IEEE80211_RADIOTAP_F_SHORTGI
;
4906 if (wh
->i_fc
[1] & IEEE80211_FC1_WEP
)
4907 tap
->flags
|= IEEE80211_RADIOTAP_F_WEP
;
4909 if (wh
->i_fc
[1] & IEEE80211_FC1_WEP
)
4911 wh
->i_fc
[1] &= ~IEEE80211_FC1_WEP
;
4913 ieee80211_radiotap_tx(vap
, m
);
4915 wh
->i_fc
[1] |= IEEE80211_FC1_WEP
;
4919 ieee80211_radiotap_tx(vap
, m
);
4923 m_copydata(m
, 0, m
->m_pkthdr
.len
, (caddr_t
) (txwi
+ 1));
4925 RT2870_DPRINTF(sc
, RT2870_DEBUG_TX
,
4926 "%s: sending data: qid=%d, hdrsize=%d, hdrspace=%d, len=%d, "
4927 "bw=%d, stbc=%d, shortgi=%d, mcs=%d, wcid=0x%02x, ampdu=%d, mimops=%d, DMA len=%d\n",
4928 device_get_nameunit(sc
->dev
),
4929 qid
, hdrsize
, hdrspace
, m
->m_pkthdr
.len
,
4930 bw
, stbc
, shortgi
, mcs
, wcid
, ampdu
, mimops
, dmalen
);
4936 STAILQ_INSERT_TAIL(&ring
->pending
, data
, next
);
4939 usbd_transfer_start(sc
->usb_xfer
[1 + qid
]);
4947 static int rt2870_tx_raw(struct rt2870_softc
*sc
,
4948 struct mbuf
*m
, struct ieee80211_node
*ni
,
4949 const struct ieee80211_bpf_params
*params
)
4951 RT2870_DPRINTF(sc
, RT2870_DEBUG_TX
,
4953 device_get_nameunit(sc
->dev
));
4961 static void rt2870_rx_intr(struct usb_xfer
*xfer
, usb_error_t error
)
4963 struct rt2870_softc
*sc
;
4965 struct rt2870_softc_rx_ring
*ring
;
4966 struct rt2870_softc_rx_data
*data
;
4969 sc
= usbd_xfer_softc(xfer
);
4971 ring
= &sc
->rx_ring
;
4973 RT2870_DPRINTF(sc
, RT2870_DEBUG_INTR
,
4974 "%s: Rx interrupt: state=%d, error=%s\n",
4975 device_get_nameunit(sc
->dev
),
4976 USB_GET_STATE(xfer
), usbd_errstr(error
));
4978 switch (USB_GET_STATE(xfer
))
4980 case USB_ST_TRANSFERRED
:
4982 sc
->rx_interrupts
++;
4984 data
= STAILQ_FIRST(&ring
->active
);
4988 STAILQ_REMOVE_HEAD(&ring
->active
, next
);
4990 usbd_xfer_status(xfer
, &len
, NULL
, NULL
, NULL
);
4994 STAILQ_INSERT_TAIL(&ring
->done
, data
, next
);
4996 taskqueue_enqueue(sc
->taskqueue
, &sc
->rx_done_task
);
5003 data
= STAILQ_FIRST(&ring
->inactive
);
5007 STAILQ_REMOVE_HEAD(&ring
->inactive
, next
);
5009 STAILQ_INSERT_TAIL(&ring
->active
, data
, next
);
5011 usbd_xfer_set_frame_data(xfer
, 0, data
->buf
, usbd_xfer_max_len(xfer
));
5012 usbd_transfer_submit(xfer
);
5017 sc
->rx_interrupts
++;
5019 data
= STAILQ_FIRST(&ring
->active
);
5022 STAILQ_REMOVE_HEAD(&ring
->active
, next
);
5023 STAILQ_INSERT_TAIL(&ring
->inactive
, data
, next
);
5026 if (error
!= USB_ERR_CANCELLED
)
5030 usbd_xfer_set_stall(xfer
);
5041 static void rt2870_tx_intr(struct usb_xfer
*xfer
, usb_error_t error
)
5043 struct rt2870_softc
*sc
;
5045 struct rt2870_softc_tx_ring
*ring
;
5046 struct rt2870_softc_tx_data
*data
;
5048 sc
= usbd_xfer_softc(xfer
);
5050 ring
= usbd_xfer_get_priv(xfer
);
5052 usbd_xfer_status(xfer
, NULL
, NULL
, NULL
, NULL
);
5054 RT2870_DPRINTF(sc
, RT2870_DEBUG_INTR
,
5055 "%s: Tx interrupt: state=%d, error=%s\n",
5056 device_get_nameunit(sc
->dev
),
5057 USB_GET_STATE(xfer
), usbd_errstr(error
));
5059 switch (USB_GET_STATE(xfer
))
5061 case USB_ST_TRANSFERRED
:
5063 sc
->tx_interrupts
[ring
->qid
]++;
5065 data
= STAILQ_FIRST(&ring
->active
);
5069 STAILQ_REMOVE_HEAD(&ring
->active
, next
);
5071 STAILQ_INSERT_TAIL(&ring
->done
, data
, next
);
5073 sc
->tx_qid_pending_mask
|= (1 << ring
->qid
);
5075 taskqueue_enqueue(sc
->taskqueue
, &sc
->tx_done_task
);
5082 data
= STAILQ_FIRST(&ring
->pending
);
5086 STAILQ_REMOVE_HEAD(&ring
->pending
, next
);
5087 STAILQ_INSERT_TAIL(&ring
->active
, data
, next
);
5089 usbd_xfer_set_frame_data(xfer
, 0, data
->buf
, data
->len
);
5090 usbd_transfer_submit(xfer
);
5092 RT2870_SOFTC_UNLOCK(sc
);
5096 RT2870_SOFTC_LOCK(sc
);
5101 sc
->tx_interrupts
[ring
->qid
]++;
5103 data
= STAILQ_FIRST(&ring
->active
);
5106 STAILQ_REMOVE_HEAD(&ring
->active
, next
);
5108 printf("%s: could not transmit buffer: qid=%d, error=%s\n",
5109 device_get_nameunit(sc
->dev
), ring
->qid
, usbd_errstr(error
));
5111 if (data
->m
!= NULL
)
5117 if (data
->ni
!= NULL
)
5119 ieee80211_free_node(data
->ni
);
5123 STAILQ_INSERT_TAIL(&ring
->inactive
, data
, next
);
5128 if (error
!= USB_ERR_CANCELLED
)
5131 ifp
->if_drv_flags
&= ~IFF_DRV_OACTIVE
;
5133 usbd_xfer_set_stall(xfer
);
5142 * rt2870_rx_done_task
5144 static void rt2870_rx_done_task(void *context
, int pending
)
5146 struct rt2870_softc
*sc
;
5152 RT2870_DPRINTF(sc
, RT2870_DEBUG_RX
,
5153 "%s: Rx done task\n",
5154 device_get_nameunit(sc
->dev
));
5156 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
5159 if (rt2870_rx_eof(sc
, sc
->rx_process_limit
) != 0)
5161 RT2870_DPRINTF(sc
, RT2870_DEBUG_RX
,
5162 "%s: Rx done task: scheduling again\n",
5163 device_get_nameunit(sc
->dev
));
5165 taskqueue_enqueue(sc
->taskqueue
, &sc
->rx_done_task
);
5170 * rt2870_tx_done_task
5172 static void rt2870_tx_done_task(void *context
, int pending
)
5174 struct rt2870_softc
*sc
;
5181 RT2870_DPRINTF(sc
, RT2870_DEBUG_TX
,
5182 "%s: Tx done task\n",
5183 device_get_nameunit(sc
->dev
));
5185 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
5188 for (i
= sc
->usb_endpoints
- 2; i
>= 0; i
--)
5190 if (sc
->tx_qid_pending_mask
& (1 << i
))
5192 sc
->tx_qid_pending_mask
&= ~(1 << i
);
5194 rt2870_tx_eof(sc
, &sc
->tx_ring
[i
]);
5198 if (sc
->tx_qid_pending_mask
!= 0)
5200 RT2870_DPRINTF(sc
, RT2870_DEBUG_TX
,
5201 "%s: Tx done task: scheduling again\n",
5202 device_get_nameunit(sc
->dev
));
5204 taskqueue_enqueue(sc
->taskqueue
, &sc
->tx_done_task
);
5209 ifp
->if_drv_flags
&= ~IFF_DRV_OACTIVE
;
5213 * rt2870_periodic_task
5215 static void rt2870_periodic_task(void *context
, int pending
)
5217 struct rt2870_softc
*sc
;
5219 struct ieee80211com
*ic
;
5220 struct ieee80211vap
*vap
;
5225 vap
= TAILQ_FIRST(&ic
->ic_vaps
);
5227 RT2870_DPRINTF(sc
, RT2870_DEBUG_PERIODIC
,
5228 "%s: periodic task: round=%lu\n",
5229 device_get_nameunit(sc
->dev
), sc
->periodic_round
);
5231 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
5234 RT2870_SOFTC_LOCK(sc
);
5236 sc
->periodic_round
++;
5238 rt2870_update_stats(sc
);
5240 if ((sc
->periodic_round
% 10) == 0)
5242 rt2870_bbp_tuning(sc
);
5244 rt2870_update_raw_counters(sc
);
5246 rt2870_watchdog(sc
);
5248 if (vap
!= NULL
&& vap
->iv_opmode
!= IEEE80211_M_MONITOR
&& vap
->iv_state
== IEEE80211_S_RUN
)
5250 if (vap
->iv_opmode
== IEEE80211_M_STA
)
5251 rt2870_amrr_update_iter_func(vap
, vap
->iv_bss
);
5253 ieee80211_iterate_nodes(&ic
->ic_sta
, rt2870_amrr_update_iter_func
, vap
);
5257 RT2870_SOFTC_UNLOCK(sc
);
5259 callout_reset(&sc
->periodic_ch
, hz
/ 10, rt2870_periodic
, sc
);
5265 static void rt2870_cmd_task(void *context
, int pending
)
5267 struct rt2870_softc
*sc
;
5268 struct rt2870_softc_cmd_ring
*ring
;
5269 struct rt2870_softc_cmd
*cmd
;
5272 ring
= &sc
->cmd_ring
;
5274 if (!(sc
->flags
& RT2870_SOFTC_FLAGS_VALID
))
5279 RT2870_SOFTC_LOCK(sc
);
5281 cmd
= STAILQ_FIRST(&ring
->active
);
5284 RT2870_SOFTC_UNLOCK(sc
);
5288 STAILQ_REMOVE_HEAD(&ring
->active
, next
);
5290 RT2870_SOFTC_UNLOCK(sc
);
5292 cmd
->cb(sc
, cmd
->data
);
5294 RT2870_SOFTC_LOCK(sc
);
5296 STAILQ_INSERT_TAIL(&ring
->inactive
, cmd
, next
);
5299 RT2870_SOFTC_UNLOCK(sc
);
5306 static int rt2870_rx_eof(struct rt2870_softc
*sc
, int limit
)
5309 struct rt2870_softc_rx_ring
*ring
;
5310 struct rt2870_softc_rx_data
*data
;
5316 ring
= &sc
->rx_ring
;
5322 RT2870_SOFTC_LOCK(sc
);
5324 data
= STAILQ_FIRST(&ring
->done
);
5327 RT2870_SOFTC_UNLOCK(sc
);
5331 STAILQ_REMOVE_HEAD(&ring
->done
, next
);
5333 RT2870_SOFTC_UNLOCK(sc
);
5338 if (len
< RT2870_RX_DESC_SIZE
)
5344 while (len
> (sizeof(uint32_t) + sizeof(struct rt2870_rxinfo
)))
5346 dmalen
= (le32toh(*(uint32_t *) buf
) & 0xffff);
5348 if (dmalen
== 0 || (dmalen
& 3) != 0)
5350 RT2870_DPRINTF(sc
, RT2870_DEBUG_RX
,
5351 "%s: bad DMA len=%u\n",
5352 device_get_nameunit(sc
->dev
), dmalen
);
5356 if ((dmalen
+ sizeof(uint32_t) + sizeof(struct rt2870_rxinfo
)) > len
)
5358 RT2870_DPRINTF(sc
, RT2870_DEBUG_RX
,
5359 "%s: bad DMA len: DMA len=%u, USB len=%d\n",
5360 device_get_nameunit(sc
->dev
),
5361 (unsigned int) (dmalen
+ sizeof(uint32_t) + sizeof(struct rt2870_rxinfo
)), len
);
5367 rt2870_rx_frame(sc
, buf
+ sizeof(uint32_t), dmalen
);
5369 buf
+= (dmalen
+ sizeof(uint32_t) + sizeof(struct rt2870_rxinfo
));
5370 len
-= (dmalen
+ sizeof(uint32_t) + sizeof(struct rt2870_rxinfo
));
5375 RT2870_SOFTC_LOCK(sc
);
5377 STAILQ_INSERT_TAIL(&ring
->inactive
, data
, next
);
5379 usbd_transfer_start(sc
->usb_xfer
[0]);
5381 RT2870_SOFTC_UNLOCK(sc
);
5386 RT2870_DPRINTF(sc
, RT2870_DEBUG_RX
,
5387 "%s: Rx eof: nframes=%d\n",
5388 device_get_nameunit(sc
->dev
), nframes
);
5390 sc
->rx_packets
+= nframes
;
5392 return (limit
== 0);
5398 static void rt2870_tx_eof(struct rt2870_softc
*sc
,
5399 struct rt2870_softc_tx_ring
*ring
)
5402 struct rt2870_softc_tx_data
*data
;
5411 RT2870_SOFTC_LOCK(sc
);
5413 data
= STAILQ_FIRST(&ring
->done
);
5416 RT2870_SOFTC_UNLOCK(sc
);
5420 STAILQ_REMOVE_HEAD(&ring
->done
, next
);
5422 rt2870_drain_fifo_stats(sc
);
5424 RT2870_SOFTC_UNLOCK(sc
);
5428 if (data
->m
->m_flags
& M_TXCB
)
5429 ieee80211_process_callback(data
->ni
, data
->m
, 0);
5433 ieee80211_free_node(data
->ni
);
5438 RT2870_SOFTC_LOCK(sc
);
5440 STAILQ_INSERT_TAIL(&ring
->inactive
, data
, next
);
5445 RT2870_SOFTC_UNLOCK(sc
);
5448 RT2870_DPRINTF(sc
, RT2870_DEBUG_TX
,
5449 "%s: Tx eof: qid=%d, nframes=%d\n",
5450 device_get_nameunit(sc
->dev
), ring
->qid
, nframes
);
5454 * rt2870_update_stats
5456 static void rt2870_update_stats(struct rt2870_softc
*sc
)
5459 struct ieee80211com
*ic
;
5461 int beacons
, noretryok
, retryok
, failed
, underflows
, zerolen
;
5466 RT2870_DPRINTF(sc
, RT2870_DEBUG_STATS
,
5467 "%s: update statistic\n",
5468 device_get_nameunit(sc
->dev
));
5470 rt2870_drain_fifo_stats(sc
);
5472 /* read and clear Tx statistic registers */
5474 rt2870_io_mac_read_multi(sc
, RT2870_REG_TX_STA_CNT0
,
5475 stacnt
, sizeof(stacnt
));
5477 stacnt
[0] = le32toh(stacnt
[0]);
5478 stacnt
[1] = le32toh(stacnt
[1]);
5479 stacnt
[2] = le32toh(stacnt
[2]);
5481 beacons
= stacnt
[0] >> 16;
5482 noretryok
= stacnt
[1] & 0xffff;
5483 retryok
= stacnt
[1] >> 16;
5484 failed
= stacnt
[0] & 0xffff;
5485 underflows
= stacnt
[2] >> 16;
5486 zerolen
= stacnt
[2] & 0xffff;
5488 RT2870_DPRINTF(sc
, RT2870_DEBUG_STATS
,
5489 "%s: update statistic: beacons=%d, noretryok=%d, retryok=%d, failed=%d, underflows=%d, zerolen=%d\n",
5490 device_get_nameunit(sc
->dev
),
5491 beacons
, noretryok
, retryok
, failed
, underflows
, zerolen
);
5493 ifp
->if_oerrors
+= failed
;
5495 sc
->tx_beacons
+= beacons
;
5496 sc
->tx_noretryok
+= noretryok
;
5497 sc
->tx_retryok
+= retryok
;
5498 sc
->tx_failed
+= failed
;
5499 sc
->tx_underflows
+= underflows
;
5500 sc
->tx_zerolen
+= zerolen
;
5506 static void rt2870_bbp_tuning(struct rt2870_softc
*sc
)
5509 struct ieee80211com
*ic
;
5510 struct ieee80211vap
*vap
;
5511 struct ieee80211_node
*ni
;
5513 int8_t rssi
, old
, new;
5515 /* RT2860C does not support BBP tuning */
5517 if (sc
->mac_rev
== 0x28600100)
5522 vap
= TAILQ_FIRST(&ic
->ic_vaps
);
5524 if ((ic
->ic_flags
& IEEE80211_F_SCAN
) || vap
== NULL
||
5525 vap
->iv_opmode
!= IEEE80211_M_STA
|| vap
->iv_state
!= IEEE80211_S_RUN
)
5530 chan
= ieee80211_chan2ieee(ic
, ni
->ni_chan
);
5534 else if (chan
<= 64)
5536 else if (chan
<= 128)
5541 rssi
= ieee80211_getrssi(vap
);
5543 if (IEEE80211_IS_CHAN_2GHZ(ni
->ni_chan
))
5545 new = 0x2e + sc
->lna_gain
[group
];
5549 if (!IEEE80211_IS_CHAN_HT40(ni
->ni_chan
))
5550 new = 0x32 + sc
->lna_gain
[group
] * 5 / 3;
5552 new = 0x3a + sc
->lna_gain
[group
] * 5 / 3;
5555 /* Tune if absolute average RSSI is greater than -80 */
5560 old
= rt2870_io_bbp_read(sc
, 66);
5563 rt2870_io_bbp_write(sc
, 66, new);
5569 static void rt2870_watchdog(struct rt2870_softc
*sc
)
5574 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_PBF_TXRXQ_PCNT
);
5576 RT2870_DPRINTF(sc
, RT2870_DEBUG_WATCHDOG
,
5577 "%s: watchdog: TXRXQ_PCNT=0x%08x\n",
5578 device_get_nameunit(sc
->dev
), tmp
);
5580 if (((tmp
>> RT2870_REG_TX0Q_PCNT_SHIFT
) & RT2870_REG_TX0Q_PCNT_MASK
) != 0)
5582 sc
->tx_queue_not_empty
[0]++;
5584 rt2870_io_mac_write(sc
, RT2870_REG_PBF_CFG
, 0xf40012);
5586 for (ntries
= 0; ntries
< 10; ntries
++)
5588 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_PBF_TXRXQ_PCNT
);
5589 if (((tmp
>> RT2870_REG_TX0Q_PCNT_SHIFT
) & RT2870_REG_TX0Q_PCNT_MASK
) == 0)
5595 rt2870_io_mac_write(sc
, RT2870_REG_PBF_CFG
, 0xf40006);
5598 if (((tmp
>> RT2870_REG_TX1Q_PCNT_SHIFT
) & RT2870_REG_TX1Q_PCNT_MASK
) != 0)
5600 sc
->tx_queue_not_empty
[1]++;
5602 rt2870_io_mac_write(sc
, RT2870_REG_PBF_CFG
, 0xf4000a);
5604 for (ntries
= 0; ntries
< 10; ntries
++)
5606 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_PBF_TXRXQ_PCNT
);
5607 if (((tmp
>> RT2870_REG_TX1Q_PCNT_SHIFT
) & RT2870_REG_TX1Q_PCNT_MASK
) == 0)
5613 rt2870_io_mac_write(sc
, RT2870_REG_PBF_CFG
, 0xf40006);
5618 * rt2870_drain_fifo_stats
5620 static void rt2870_drain_fifo_stats(struct rt2870_softc
*sc
)
5624 uint8_t wcid
, mcs
, pid
;
5625 int ok
, agg
, retrycnt
;
5629 /* drain Tx status FIFO (maxsize = 16) */
5631 while ((sc
->flags
& RT2870_SOFTC_FLAGS_VALID
) &&
5632 ((stats
= rt2870_io_mac_read(sc
, RT2870_REG_TX_STA_FIFO
)) &
5633 RT2870_REG_TX_STA_FIFO_VALID
))
5635 wcid
= (stats
>> RT2870_REG_TX_STA_FIFO_WCID_SHIFT
) &
5636 RT2870_REG_TX_STA_FIFO_WCID_MASK
;
5638 /* if no ACK was requested, no feedback is available */
5640 if (!(stats
& RT2870_REG_TX_STA_FIFO_ACK_REQ
) || wcid
== RT2870_WCID_RESERVED
)
5643 /* update AMRR statistic */
5645 ok
= (stats
& RT2870_REG_TX_STA_FIFO_TX_OK
) ? 1 : 0;
5646 agg
= (stats
& RT2870_REG_TX_STA_FIFO_AGG
) ? 1 : 0;
5647 mcs
= (stats
>> RT2870_REG_TX_STA_FIFO_MCS_SHIFT
) &
5648 RT2870_REG_TX_STA_FIFO_MCS_MASK
;
5649 pid
= (stats
>> RT2870_REG_TX_STA_FIFO_PID_SHIFT
) &
5650 RT2870_REG_TX_STA_FIFO_PID_MASK
;
5651 retrycnt
= pid
- mcs
;
5653 RT2870_DPRINTF(sc
, RT2870_DEBUG_STATS
,
5654 "%s: FIFO statistic: wcid=0x%02x, ok=%d, agg=%d, mcs=0x%02x, pid=0x%02x, retrycnt=%d\n",
5655 device_get_nameunit(sc
->dev
),
5656 wcid
, ok
, agg
, mcs
, pid
, retrycnt
);
5658 rt2870_amrr_tx_complete(&sc
->amrr_node
[wcid
], ok
, retrycnt
);
5666 * rt2870_update_raw_counters
5668 static void rt2870_update_raw_counters(struct rt2870_softc
*sc
)
5672 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_TX_AGG_CNT
);
5674 sc
->tx_nonagg
+= tmp
& 0xffff;
5675 sc
->tx_agg
+= tmp
>> 16;
5677 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_TX_AGG_CNT0
);
5679 sc
->tx_ampdu
+= (tmp
& 0xffff) / 1 + (tmp
>> 16) / 2;
5681 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_TX_AGG_CNT1
);
5683 sc
->tx_ampdu
+= (tmp
& 0xffff) / 3 + (tmp
>> 16) / 4;
5685 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_TX_AGG_CNT2
);
5687 sc
->tx_ampdu
+= (tmp
& 0xffff) / 5 + (tmp
>> 16) / 6;
5689 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_TX_AGG_CNT3
);
5691 sc
->tx_ampdu
+= (tmp
& 0xffff) / 7 + (tmp
>> 16) / 8;
5693 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_TX_AGG_CNT4
);
5695 sc
->tx_ampdu
+= (tmp
& 0xffff) / 9 + (tmp
>> 16) / 10;
5697 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_TX_AGG_CNT5
);
5699 sc
->tx_ampdu
+= (tmp
& 0xffff) / 11 + (tmp
>> 16) / 12;
5701 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_TX_AGG_CNT6
);
5703 sc
->tx_ampdu
+= (tmp
& 0xffff) / 13 + (tmp
>> 16) / 14;
5705 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_TX_AGG_CNT7
);
5707 sc
->tx_ampdu
+= (tmp
& 0xffff) / 15 + (tmp
>> 16) / 16;
5709 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_RX_STA_CNT0
);
5711 sc
->rx_crc_errors
+= tmp
& 0xffff;
5712 sc
->rx_phy_errors
+= tmp
>> 16;
5714 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_RX_STA_CNT1
);
5716 sc
->rx_false_ccas
+= tmp
& 0xffff;
5717 sc
->rx_plcp_errors
+= tmp
>> 16;
5719 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_RX_STA_CNT2
);
5721 sc
->rx_dup_packets
+= tmp
& 0xffff;
5722 sc
->rx_fifo_overflows
+= tmp
>> 16;
5724 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_TXRX_MPDU_DEN_CNT
);
5726 sc
->tx_mpdu_zero_density
+= tmp
& 0xffff;
5727 sc
->rx_mpdu_zero_density
+= tmp
>> 16;
5731 * rt2870_txrx_enable
5733 static int rt2870_txrx_enable(struct rt2870_softc
*sc
)
5735 struct ieee80211com
*ic
;
5743 /* enable Tx/Rx DMA engine */
5745 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_SCHDMA_USB_CYC_CFG
);
5750 rt2870_io_mac_write(sc
, RT2870_REG_SCHDMA_USB_CYC_CFG
, tmp
);
5752 if ((sc
->mac_rev
& 0xffff) != 0x0101)
5753 rt2870_io_mac_write(sc
, RT2870_REG_TX_TXOP_CTRL_CFG
, 0x583f);
5755 rt2870_io_mac_write(sc
, RT2870_REG_SYS_CTRL
, RT2870_REG_TX_ENABLE
);
5757 for (ntries
= 0; ntries
< 200; ntries
++)
5759 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_SCHDMA_WPDMA_GLO_CFG
);
5760 if (!(tmp
& (RT2870_REG_TX_DMA_BUSY
| RT2870_REG_RX_DMA_BUSY
)))
5768 printf("%s: timeout waiting for DMA engine\n",
5769 device_get_nameunit(sc
->dev
));
5775 rt2870_io_mac_write(sc
, RT2870_REG_SCHDMA_WMM_TXOP0_CFG
, 0);
5776 rt2870_io_mac_write(sc
, RT2870_REG_SCHDMA_WMM_TXOP1_CFG
,
5779 tmp
|= RT2870_REG_TX_WB_DDONE
|
5780 RT2870_REG_RX_DMA_ENABLE
|
5781 RT2870_REG_TX_DMA_ENABLE
;
5783 rt2870_io_mac_write(sc
, RT2870_REG_SCHDMA_WPDMA_GLO_CFG
, tmp
);
5785 tmp
= RT2870_REG_USB_DMA_TX_ENABLE
|
5786 RT2870_REG_USB_DMA_RX_ENABLE
|
5787 RT2870_REG_USB_DMA_RX_AGG_ENABLE
|
5788 /* Rx agg limit in unit of 1024 byte */
5789 ((RT2870_USB_RX_BULK_BUFLEN
/ 1024 - 3) << RT2870_REG_USB_DMA_RX_AGG_LIMIT_SHIFT
) |
5790 /* Rx agg timeout in unit of 33ns */
5793 rt2870_io_mac_write(sc
, RT2870_REG_SCHDMA_USB_DMA_CFG
, tmp
);
5797 tmp
= RT2870_REG_RX_FILTER_DROP_CRC_ERR
|
5798 RT2870_REG_RX_FILTER_DROP_PHY_ERR
;
5800 if (ic
->ic_opmode
!= IEEE80211_M_MONITOR
)
5802 tmp
|= RT2870_REG_RX_FILTER_DROP_DUPL
|
5803 RT2870_REG_RX_FILTER_DROP_CTS
|
5804 RT2870_REG_RX_FILTER_DROP_BA
|
5805 RT2870_REG_RX_FILTER_DROP_ACK
|
5806 RT2870_REG_RX_FILTER_DROP_VER_ERR
|
5807 RT2870_REG_RX_FILTER_DROP_CTRL_RSV
|
5808 RT2870_REG_RX_FILTER_DROP_CFACK
|
5809 RT2870_REG_RX_FILTER_DROP_CFEND
;
5811 if (ic
->ic_opmode
== IEEE80211_M_STA
)
5812 tmp
|= RT2870_REG_RX_FILTER_DROP_RTS
|
5813 RT2870_REG_RX_FILTER_DROP_PSPOLL
;
5815 if (!(ifp
->if_flags
& IFF_PROMISC
))
5816 tmp
|= RT2870_REG_RX_FILTER_DROP_UC_NOME
;
5819 rt2870_io_mac_write(sc
, RT2870_REG_RX_FILTER_CFG
, tmp
);
5821 rt2870_io_mac_write(sc
, RT2870_REG_SYS_CTRL
,
5822 RT2870_REG_RX_ENABLE
| RT2870_REG_TX_ENABLE
);
5828 * rt2870_alloc_rx_ring
5830 static int rt2870_alloc_rx_ring(struct rt2870_softc
*sc
,
5831 struct rt2870_softc_rx_ring
*ring
)
5833 struct rt2870_softc_rx_data
*data
;
5836 STAILQ_INIT(&ring
->inactive
);
5837 STAILQ_INIT(&ring
->active
);
5838 STAILQ_INIT(&ring
->done
);
5840 for (i
= 0; i
< RT2870_SOFTC_RX_RING_DATA_COUNT
; i
++)
5842 data
= &ring
->data
[i
];
5844 data
->buf
= malloc(RT2870_USB_RX_BULK_BUFLEN
, M_USBDEV
, M_NOWAIT
);
5845 if (data
->buf
== NULL
)
5847 printf("%s: could not allocate Rx buffer\n",
5848 device_get_nameunit(sc
->dev
));
5853 STAILQ_INSERT_TAIL(&ring
->inactive
, data
, next
);
5860 rt2870_free_rx_ring(sc
, ring
);
5866 * rt2870_reset_rx_ring
5868 static void rt2870_reset_rx_ring(struct rt2870_softc
*sc
,
5869 struct rt2870_softc_rx_ring
*ring
)
5871 struct rt2870_softc_rx_data
*data
;
5874 STAILQ_INIT(&ring
->inactive
);
5875 STAILQ_INIT(&ring
->active
);
5876 STAILQ_INIT(&ring
->done
);
5878 for (i
= 0; i
< RT2870_SOFTC_RX_RING_DATA_COUNT
; i
++)
5880 data
= &ring
->data
[i
];
5882 STAILQ_INSERT_TAIL(&ring
->inactive
, data
, next
);
5887 * rt2870_free_rx_ring
5889 static void rt2870_free_rx_ring(struct rt2870_softc
*sc
,
5890 struct rt2870_softc_rx_ring
*ring
)
5892 struct rt2870_softc_rx_data
*data
;
5895 for (i
= 0; i
< RT2870_SOFTC_RX_RING_DATA_COUNT
; i
++)
5897 data
= &ring
->data
[i
];
5899 if (data
->buf
!= NULL
)
5901 free(data
->buf
, M_USBDEV
);
5908 * rt2870_alloc_tx_ring
5910 static int rt2870_alloc_tx_ring(struct rt2870_softc
*sc
,
5911 struct rt2870_softc_tx_ring
*ring
, int qid
)
5913 struct rt2870_softc_tx_data
*data
;
5916 STAILQ_INIT(&ring
->inactive
);
5917 STAILQ_INIT(&ring
->pending
);
5918 STAILQ_INIT(&ring
->active
);
5919 STAILQ_INIT(&ring
->done
);
5924 for (i
= 0; i
< RT2870_SOFTC_TX_RING_DATA_COUNT
; i
++)
5926 data
= &ring
->data
[i
];
5928 data
->buf
= malloc(RT2870_TX_DESC_SIZE
+ MJUMPAGESIZE
, M_USBDEV
, M_NOWAIT
);
5929 if (data
->buf
== NULL
)
5931 printf("%s: could not allocate Tx buffer\n",
5932 device_get_nameunit(sc
->dev
));
5937 memset(data
->buf
, 0, RT2870_TX_DESC_SIZE
);
5939 STAILQ_INSERT_TAIL(&ring
->inactive
, data
, next
);
5946 rt2870_free_tx_ring(sc
, ring
);
5952 * rt2870_reset_tx_ring
5954 static void rt2870_reset_tx_ring(struct rt2870_softc
*sc
,
5955 struct rt2870_softc_tx_ring
*ring
)
5957 struct rt2870_softc_tx_data
*data
;
5960 STAILQ_INIT(&ring
->inactive
);
5961 STAILQ_INIT(&ring
->pending
);
5962 STAILQ_INIT(&ring
->active
);
5963 STAILQ_INIT(&ring
->done
);
5967 for (i
= 0; i
< RT2870_SOFTC_TX_RING_DATA_COUNT
; i
++)
5969 data
= &ring
->data
[i
];
5971 if (data
->m
!= NULL
)
5977 if (data
->ni
!= NULL
)
5979 ieee80211_free_node(data
->ni
);
5983 STAILQ_INSERT_TAIL(&ring
->inactive
, data
, next
);
5988 * rt2870_free_tx_ring
5990 static void rt2870_free_tx_ring(struct rt2870_softc
*sc
,
5991 struct rt2870_softc_tx_ring
*ring
)
5993 struct rt2870_softc_tx_data
*data
;
5996 for (i
= 0; i
< RT2870_SOFTC_TX_RING_DATA_COUNT
; i
++)
5998 data
= &ring
->data
[i
];
6000 if (data
->buf
!= NULL
)
6002 free(data
->buf
, M_USBDEV
);
6006 if (data
->m
!= NULL
)
6012 if (data
->ni
!= NULL
)
6014 ieee80211_free_node(data
->ni
);
6021 * rt2870_reset_cmd_ring
6023 static void rt2870_reset_cmd_ring(struct rt2870_softc
*sc
,
6024 struct rt2870_softc_cmd_ring
*ring
)
6026 struct rt2870_softc_cmd
*cmd
;
6029 STAILQ_INIT(&ring
->inactive
);
6030 STAILQ_INIT(&ring
->active
);
6034 for (i
= 0; i
< RT2870_SOFTC_CMD_RING_CMD_COUNT
; i
++)
6036 cmd
= &ring
->cmd
[i
];
6038 STAILQ_INSERT_TAIL(&ring
->inactive
, cmd
, next
);
6043 * rt2870_sysctl_attach
6045 static void rt2870_sysctl_attach(struct rt2870_softc
*sc
)
6047 struct sysctl_ctx_list
*ctx
;
6048 struct sysctl_oid
*tree
;
6049 struct sysctl_oid
*stats
;
6051 ctx
= device_get_sysctl_ctx(sc
->dev
);
6052 tree
= device_get_sysctl_tree(sc
->dev
);
6054 stats
= SYSCTL_ADD_NODE(ctx
, SYSCTL_CHILDREN(tree
), OID_AUTO
,
6055 "stats", CTLFLAG_RD
, 0, "statistic");
6057 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6058 "interrupts", CTLFLAG_RD
, &sc
->interrupts
, 0,
6061 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6062 "rx_interrupts", CTLFLAG_RD
, &sc
->rx_interrupts
, 0,
6065 if (sc
->usb_endpoints
== RT2870_SOFTC_USB_XFER_COUNT
)
6067 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6068 "tx_mgmt_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[5], 0,
6069 "Tx MGMT interrupts");
6071 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6072 "tx_hcca_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[4], 0,
6073 "Tx HCCA interrupts");
6076 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6077 "tx_ac3_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[3], 0,
6078 "Tx AC3 interrupts");
6080 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6081 "tx_ac2_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[2], 0,
6082 "Tx AC2 interrupts");
6084 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6085 "tx_ac1_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[1], 0,
6086 "Tx AC1 interrupts");
6088 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6089 "tx_ac0_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[0], 0,
6090 "Tx AC0 interrupts");
6092 if (sc
->usb_endpoints
== RT2870_SOFTC_USB_XFER_COUNT
)
6094 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6095 "tx_mgmt_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[5].queued
, 0,
6096 "Tx MGMT data queued");
6098 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6099 "tx_hcca_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[4].queued
, 0,
6100 "Tx HCCA data queued");
6103 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6104 "tx_ac3_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[3].queued
, 0,
6105 "Tx AC3 data queued");
6107 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6108 "tx_ac2_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[2].queued
, 0,
6109 "Tx AC2 data queued");
6111 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6112 "tx_ac1_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[1].queued
, 0,
6113 "Tx AC1 data queued");
6115 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6116 "tx_ac0_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[0].queued
, 0,
6117 "Tx AC0 data queued");
6119 if (sc
->usb_endpoints
== RT2870_SOFTC_USB_XFER_COUNT
)
6121 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6122 "tx_mgmt_data_queue_full", CTLFLAG_RD
, &sc
->tx_data_queue_full
[5], 0,
6123 "Tx MGMT data queue full");
6125 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6126 "tx_hcca_data_queue_full", CTLFLAG_RD
, &sc
->tx_data_queue_full
[4], 0,
6127 "Tx HCCA data queue full");
6130 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6131 "tx_ac3_data_queue_full", CTLFLAG_RD
, &sc
->tx_data_queue_full
[3], 0,
6132 "Tx AC3 data queue full");
6134 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6135 "tx_ac2_data_queue_full", CTLFLAG_RD
, &sc
->tx_data_queue_full
[2], 0,
6136 "Tx AC2 data queue full");
6138 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6139 "tx_ac1_data_queue_full", CTLFLAG_RD
, &sc
->tx_data_queue_full
[1], 0,
6140 "Tx AC1 data queue full");
6142 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6143 "tx_ac0_data_queue_full", CTLFLAG_RD
, &sc
->tx_data_queue_full
[0], 0,
6144 "Tx AC0 data queue full");
6146 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6147 "tx_watchdog_timeouts", CTLFLAG_RD
, &sc
->tx_watchdog_timeouts
, 0,
6148 "Tx watchdog timeouts");
6150 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6151 "rx_mbuf_alloc_errors", CTLFLAG_RD
, &sc
->rx_mbuf_alloc_errors
, 0,
6152 "Rx mbuf allocation errors");
6154 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6155 "tx_queue_0_not_empty", CTLFLAG_RD
, &sc
->tx_queue_not_empty
[0], 0,
6156 "Tx queue 0 not empty");
6158 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6159 "tx_queue_1_not_empty", CTLFLAG_RD
, &sc
->tx_queue_not_empty
[1], 0,
6160 "Tx queue 1 not empty");
6162 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6163 "tx_beacons", CTLFLAG_RD
, &sc
->tx_beacons
, 0,
6166 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6167 "tx_noretryok", CTLFLAG_RD
, &sc
->tx_noretryok
, 0,
6168 "Tx successfull without retries");
6170 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6171 "tx_retryok", CTLFLAG_RD
, &sc
->tx_retryok
, 0,
6172 "Tx successfull with retries");
6174 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6175 "tx_failed", CTLFLAG_RD
, &sc
->tx_failed
, 0,
6178 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6179 "tx_underflows", CTLFLAG_RD
, &sc
->tx_underflows
, 0,
6182 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6183 "tx_zerolen", CTLFLAG_RD
, &sc
->tx_zerolen
, 0,
6186 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6187 "tx_nonagg", CTLFLAG_RD
, &sc
->tx_nonagg
, 0,
6188 "Tx non-aggregated");
6190 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6191 "tx_agg", CTLFLAG_RD
, &sc
->tx_agg
, 0,
6194 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6195 "tx_ampdu", CTLFLAG_RD
, &sc
->tx_ampdu
, 0,
6198 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6199 "tx_mpdu_zero_density", CTLFLAG_RD
, &sc
->tx_mpdu_zero_density
, 0,
6200 "Tx MPDU with zero density");
6202 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6203 "tx_ampdu_sessions", CTLFLAG_RD
, &sc
->tx_ampdu_sessions
, 0,
6204 "Tx A-MPDU sessions");
6206 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6207 "rx_packets", CTLFLAG_RD
, &sc
->rx_packets
, 0,
6210 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6211 "rx_ampdu", CTLFLAG_RD
, &sc
->rx_ampdu
, 0,
6214 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6215 "rx_mpdu_zero_density", CTLFLAG_RD
, &sc
->rx_mpdu_zero_density
, 0,
6216 "Rx MPDU with zero density");
6218 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6219 "rx_amsdu", CTLFLAG_RD
, &sc
->rx_amsdu
, 0,
6222 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6223 "rx_crc_errors", CTLFLAG_RD
, &sc
->rx_crc_errors
, 0,
6226 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6227 "rx_phy_errors", CTLFLAG_RD
, &sc
->rx_phy_errors
, 0,
6230 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6231 "rx_false_ccas", CTLFLAG_RD
, &sc
->rx_false_ccas
, 0,
6234 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6235 "rx_plcp_errors", CTLFLAG_RD
, &sc
->rx_plcp_errors
, 0,
6238 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6239 "rx_dup_packets", CTLFLAG_RD
, &sc
->rx_dup_packets
, 0,
6240 "Rx duplicate packets");
6242 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6243 "rx_fifo_overflows", CTLFLAG_RD
, &sc
->rx_fifo_overflows
, 0,
6244 "Rx FIFO overflows");
6246 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6247 "rx_cipher_no_errors", CTLFLAG_RD
, &sc
->rx_cipher_no_errors
, 0,
6248 "Rx cipher no errors");
6250 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6251 "rx_cipher_icv_errors", CTLFLAG_RD
, &sc
->rx_cipher_icv_errors
, 0,
6252 "Rx cipher ICV errors");
6254 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6255 "rx_cipher_mic_errors", CTLFLAG_RD
, &sc
->rx_cipher_mic_errors
, 0,
6256 "Rx cipher MIC errors");
6258 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
6259 "rx_cipher_invalid_key_errors", CTLFLAG_RD
, &sc
->rx_cipher_invalid_key_errors
, 0,
6260 "Rx cipher invalid key errors");
6263 static device_method_t rt2870_dev_methods
[] =
6265 DEVMETHOD(device_probe
, rt2870_probe
),
6266 DEVMETHOD(device_attach
, rt2870_attach
),
6267 DEVMETHOD(device_detach
, rt2870_detach
),
6271 static driver_t rt2870_driver
=
6275 sizeof(struct rt2870_softc
),
6278 static devclass_t rt2870_dev_class
;
6280 DRIVER_MODULE(rt2870
, uhub
, rt2870_driver
, rt2870_dev_class
,
6283 MODULE_DEPEND(rt2870
, usb
, 1, 1, 1);
6284 MODULE_DEPEND(rt2870
, wlan
, 1, 1, 1);