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
77 * Data structures and types
80 struct rt2870_cmd_argv_keydelete
82 struct ieee80211_key key
;
87 * Static function prototypes
90 static void rt2870_init_channels(struct rt2870_softc
*sc
);
92 static void rt2870_init_channels_ht40(struct rt2870_softc
*sc
);
94 static void rt2870_init_locked(void *priv
);
96 static void rt2870_init(void *priv
);
98 static int rt2870_init_bbp(struct rt2870_softc
*sc
);
100 static void rt2870_stop_locked(void *priv
);
102 static void rt2870_stop(void *priv
);
104 static void rt2870_start(struct ifnet
*ifp
);
106 static int rt2870_ioctl(struct ifnet
*ifp
, u_long cmd
, caddr_t data
);
108 static struct ieee80211vap
*rt2870_vap_create(struct ieee80211com
*ic
,
109 const char name
[IFNAMSIZ
], int unit
, int opmode
, int flags
,
110 const uint8_t bssid
[IEEE80211_ADDR_LEN
],
111 const uint8_t mac
[IEEE80211_ADDR_LEN
]);
113 static void rt2870_vap_delete(struct ieee80211vap
*vap
);
115 static int rt2870_vap_reset(struct ieee80211vap
*vap
, u_long cmd
);
117 static int rt2870_vap_newstate(struct ieee80211vap
*vap
,
118 enum ieee80211_state nstate
, int arg
);
120 static void rt2870_vap_key_update_begin(struct ieee80211vap
*vap
);
122 static void rt2870_vap_key_update_end(struct ieee80211vap
*vap
);
124 static int rt2870_vap_key_set(struct ieee80211vap
*vap
,
125 const struct ieee80211_key
*k
, const uint8_t mac
[IEEE80211_ADDR_LEN
]);
127 static int rt2870_vap_key_delete(struct ieee80211vap
*vap
,
128 const struct ieee80211_key
*k
);
130 static void rt2870_vap_update_beacon(struct ieee80211vap
*vap
, int what
);
132 static struct ieee80211_node
*rt2870_node_alloc(struct ieee80211vap
*vap
,
133 const uint8_t mac
[IEEE80211_ADDR_LEN
]);
135 static int rt2870_setregdomain(struct ieee80211com
*ic
,
136 struct ieee80211_regdomain
*reg
,
137 int nchans
, struct ieee80211_channel chans
[]);
139 static void rt2870_getradiocaps(struct ieee80211com
*ic
,
140 int maxchans
, int *nchans
, struct ieee80211_channel chans
[]);
142 static void rt2870_scan_start(struct ieee80211com
*ic
);
144 static void rt2870_scan_end(struct ieee80211com
*ic
);
146 static void rt2870_set_channel(struct ieee80211com
*ic
);
148 static void rt2870_newassoc(struct ieee80211_node
*ni
, int isnew
);
150 static void rt2870_updateslot(struct ifnet
*ifp
);
152 static void rt2870_update_promisc(struct ifnet
*ifp
);
154 static void rt2870_update_mcast(struct ifnet
*ifp
);
156 static int rt2870_wme_update(struct ieee80211com
*ic
);
158 static int rt2870_raw_xmit(struct ieee80211_node
*ni
, struct mbuf
*m
,
159 const struct ieee80211_bpf_params
*params
);
161 static int rt2870_recv_action(struct ieee80211_node
*ni
,
162 const struct ieee80211_frame
*wh
,
163 const uint8_t *frm
, const uint8_t *efrm
);
165 static int rt2870_send_action(struct ieee80211_node
*ni
,
166 int cat
, int act
, void *sa
);
168 static void rt2870_amrr_update_iter_func(void *arg
, struct ieee80211_node
*ni
);
170 static void rt2870_periodic(void *arg
);
172 static void rt2870_tx_watchdog(void *arg
);
174 static int rt2870_do_async(struct rt2870_softc
*sc
,
175 void (*cb
)(struct rt2870_softc
*sc
, void *arg
),
178 static void rt2870_updateslot_cb(struct rt2870_softc
*sc
, void *arg
);
180 static void rt2870_wme_update_cb(struct rt2870_softc
*sc
, void *arg
);
182 static void rt2870_vap_key_delete_cb(struct rt2870_softc
*sc
, void *arg
);
184 static void rt2870_vap_update_beacon_cb(struct rt2870_softc
*sc
, void *arg
);
186 static void rt2870_asic_set_bssid(struct rt2870_softc
*sc
,
187 const uint8_t *bssid
);
189 static void rt2870_asic_set_macaddr(struct rt2870_softc
*sc
,
190 const uint8_t *addr
);
192 static void rt2870_asic_enable_tsf_sync(struct rt2870_softc
*sc
);
194 static void rt2870_asic_disable_tsf_sync(struct rt2870_softc
*sc
);
196 static void rt2870_asic_enable_mrr(struct rt2870_softc
*sc
);
198 static void rt2870_asic_set_txpreamble(struct rt2870_softc
*sc
);
200 static void rt2870_asic_set_basicrates(struct rt2870_softc
*sc
);
202 static void rt2870_asic_update_rtsthreshold(struct rt2870_softc
*sc
);
204 static void rt2870_asic_update_txpower(struct rt2870_softc
*sc
);
206 static void rt2870_asic_update_promisc(struct rt2870_softc
*sc
);
208 static void rt2870_asic_updateprot(struct rt2870_softc
*sc
);
210 static void rt2870_asic_updateslot(struct rt2870_softc
*sc
);
212 static void rt2870_asic_wme_update(struct rt2870_softc
*sc
);
214 static int rt2870_asic_update_beacon(struct rt2870_softc
*sc
,
215 struct ieee80211vap
*vap
);
217 static void rt2870_asic_clear_keytables(struct rt2870_softc
*sc
);
219 static uint8_t rt2870_rxrate(struct rt2870_rxwi
*rxwi
);
221 static uint8_t rt2870_maxrssi_rxpath(struct rt2870_softc
*sc
,
222 const struct rt2870_rxwi
*rxwi
);
224 static int8_t rt2870_rssi2dbm(struct rt2870_softc
*sc
,
225 uint8_t rssi
, uint8_t rxpath
);
227 static uint8_t rt2870_rate2mcs(uint8_t rate
);
229 static void rt2870_rx_frame(struct rt2870_softc
*sc
,
230 uint8_t *buf
, uint32_t dmalen
);
232 static int rt2870_tx_mgmt(struct rt2870_softc
*sc
,
233 struct mbuf
*m
, struct ieee80211_node
*ni
, int qid
);
235 static int rt2870_tx_data(struct rt2870_softc
*sc
,
236 struct mbuf
*m
, struct ieee80211_node
*ni
, int qid
);
238 static int rt2870_tx_raw(struct rt2870_softc
*sc
,
239 struct mbuf
*m
, struct ieee80211_node
*ni
,
240 const struct ieee80211_bpf_params
*params
);
242 static void rt2870_rx_intr(struct usb_xfer
*xfer
, usb_error_t error
);
244 static void rt2870_tx_intr(struct usb_xfer
*xfer
, usb_error_t error
);
246 static void rt2870_rx_done_task(void *context
, int pending
);
248 static void rt2870_tx_done_task(void *context
, int pending
);
250 static void rt2870_periodic_task(void *context
, int pending
);
252 static void rt2870_cmd_task(void *context
, int pending
);
254 static int rt2870_rx_eof(struct rt2870_softc
*sc
, int limit
);
256 static void rt2870_tx_eof(struct rt2870_softc
*sc
,
257 struct rt2870_softc_tx_ring
*ring
);
259 static void rt2870_update_stats(struct rt2870_softc
*sc
);
261 static void rt2870_bbp_tuning(struct rt2870_softc
*sc
);
263 static void rt2870_watchdog(struct rt2870_softc
*sc
);
265 static void rt2870_drain_fifo_stats(struct rt2870_softc
*sc
);
267 static void rt2870_update_raw_counters(struct rt2870_softc
*sc
);
269 static int rt2870_txrx_enable(struct rt2870_softc
*sc
);
271 static int rt2870_alloc_rx_ring(struct rt2870_softc
*sc
,
272 struct rt2870_softc_rx_ring
*ring
);
274 static void rt2870_reset_rx_ring(struct rt2870_softc
*sc
,
275 struct rt2870_softc_rx_ring
*ring
);
277 static void rt2870_free_rx_ring(struct rt2870_softc
*sc
,
278 struct rt2870_softc_rx_ring
*ring
);
280 static int rt2870_alloc_tx_ring(struct rt2870_softc
*sc
,
281 struct rt2870_softc_tx_ring
*ring
, int qid
);
283 static void rt2870_reset_tx_ring(struct rt2870_softc
*sc
,
284 struct rt2870_softc_tx_ring
*ring
);
286 static void rt2870_free_tx_ring(struct rt2870_softc
*sc
,
287 struct rt2870_softc_tx_ring
*ring
);
289 static void rt2870_reset_cmd_ring(struct rt2870_softc
*sc
,
290 struct rt2870_softc_cmd_ring
*ring
);
292 static void rt2870_sysctl_attach(struct rt2870_softc
*sc
);
298 static const struct usb_device_id rt2870_usb_devid
[] =
300 { USB_VP(USB_VENDOR_LINKSYS4
, USB_PRODUCT_LINKSYS4_WUSB600N
) }, /* Linksys WUSB600N */
301 { USB_VP(USB_VENDOR_DLINK2
, USB_PRODUCT_DLINK2_DWA140
) }, /* D-Link DWA-140 */
302 { USB_VP(USB_VENDOR_DLINK2
, USB_PRODUCT_DLINK2_DWA160AREVB
) }, /* D-Link DWA-160A Rev. B */
303 { USB_VP(USB_VENDOR_ASUS
, USB_PRODUCT_ASUS_RT2770F
) }, /* Asus RT2770F */
304 { USB_VP(USB_VENDOR_RALINK
, USB_PRODUCT_RALINK_RT2770
) }, /* Ralink RT2770 */
307 static const struct usb_config rt2870_usb_config
[RT2870_SOFTC_USB_XFER_COUNT
] =
312 .direction
= UE_DIR_IN
,
313 .bufsize
= RT2870_USB_RX_BULK_BUFLEN
,
314 .flags
= { .ext_buffer
= 1, .pipe_bof
= 1, .short_xfer_ok
= 1, },
315 .callback
= rt2870_rx_intr
,
320 .direction
= UE_DIR_OUT
,
321 .bufsize
= (RT2870_TX_DESC_SIZE
+ MJUMPAGESIZE
),
322 .flags
= { .ext_buffer
= 1, .pipe_bof
= 1, .force_short_xfer
= 1, },
323 .callback
= rt2870_tx_intr
,
324 .timeout
= RT2870_USB_XFER_TIMEOUT
,
329 .direction
= UE_DIR_OUT
,
330 .bufsize
= (RT2870_TX_DESC_SIZE
+ MJUMPAGESIZE
),
331 .flags
= { .ext_buffer
= 1, .pipe_bof
= 1, .force_short_xfer
= 1, },
332 .callback
= rt2870_tx_intr
,
333 .timeout
= RT2870_USB_XFER_TIMEOUT
,
338 .direction
= UE_DIR_OUT
,
339 .bufsize
= (RT2870_TX_DESC_SIZE
+ MJUMPAGESIZE
),
340 .flags
= { .ext_buffer
= 1, .pipe_bof
= 1, .force_short_xfer
= 1, },
341 .callback
= rt2870_tx_intr
,
342 .timeout
= RT2870_USB_XFER_TIMEOUT
,
347 .direction
= UE_DIR_OUT
,
348 .bufsize
= (RT2870_TX_DESC_SIZE
+ MJUMPAGESIZE
),
349 .flags
= { .ext_buffer
= 1, .pipe_bof
= 1, .force_short_xfer
= 1, },
350 .callback
= rt2870_tx_intr
,
351 .timeout
= RT2870_USB_XFER_TIMEOUT
,
356 .direction
= UE_DIR_OUT
,
357 .bufsize
= (RT2870_TX_DESC_SIZE
+ MJUMPAGESIZE
),
358 .flags
= { .ext_buffer
= 1, .pipe_bof
= 1, .force_short_xfer
= 1, },
359 .callback
= rt2870_tx_intr
,
360 .timeout
= RT2870_USB_XFER_TIMEOUT
,
365 .direction
= UE_DIR_OUT
,
366 .bufsize
= (RT2870_TX_DESC_SIZE
+ MJUMPAGESIZE
),
367 .flags
= { .ext_buffer
= 1, .pipe_bof
= 1, .force_short_xfer
= 1, },
368 .callback
= rt2870_tx_intr
,
369 .timeout
= RT2870_USB_XFER_TIMEOUT
,
379 { RT2870_REG_PBF_BCN_OFFSET0
, 0xf8f0e8e0 },
380 { RT2870_REG_PBF_BCN_OFFSET1
, 0x6f77d0c8 },
381 { RT2870_REG_LEGACY_BASIC_RATE
, 0x0000013f },
382 { RT2870_REG_HT_BASIC_RATE
, 0x00008003 },
383 { RT2870_REG_SYS_CTRL
, 0x00000000 },
384 { RT2870_REG_RX_FILTER_CFG
, 0x00017f97 },
385 { RT2870_REG_BKOFF_SLOT_CFG
, 0x00000209 },
386 { RT2870_REG_TX_SW_CFG0
, 0x00000000 },
387 { RT2870_REG_TX_SW_CFG1
, 0x00080606 },
388 { RT2870_REG_TX_LINK_CFG
, 0x00001020 },
389 { RT2870_REG_TX_TIMEOUT_CFG
, 0x000a2090 },
390 { RT2870_REG_MAX_LEN_CFG
, (1 << 12) | RT2870_MAX_AGG_SIZE
},
391 { RT2870_REG_LED_CFG
, 0x7f031e46 },
392 { RT2870_REG_PBF_MAX_PCNT
, 0x1f3fbf9f },
393 { RT2870_REG_TX_RTY_CFG
, 0x47d01f0f },
394 { RT2870_REG_AUTO_RSP_CFG
, 0x00000013 },
395 { RT2870_REG_TX_CCK_PROT_CFG
, 0x05740003 },
396 { RT2870_REG_TX_OFDM_PROT_CFG
, 0x05740003 },
397 { RT2870_REG_PBF_CFG
, 0x00f40006 },
398 { RT2870_REG_TX_MM40_PROT_CFG
, 0x03f44084 },
399 { RT2870_REG_SCHDMA_WPDMA_GLO_CFG
, 0x00000030 },
400 { RT2870_REG_TX_GF20_PROT_CFG
, 0x01744004 },
401 { RT2870_REG_TX_GF40_PROT_CFG
, 0x03f44084 },
402 { RT2870_REG_TX_MM20_PROT_CFG
, 0x01744004 },
403 { RT2870_REG_TX_TXOP_CTRL_CFG
, 0x0000583f },
404 { RT2870_REG_TX_RTS_CFG
, 0x00092b20 },
405 { RT2870_REG_TX_EXP_ACK_TIME
, 0x002400ca },
406 { RT2870_REG_HCCAPSMP_TXOP_HLDR_ET
, 0x00000002 },
407 { RT2870_REG_XIFS_TIME_CFG
, 0x33a41010 },
408 { RT2870_REG_PWR_PIN_CFG
, 0x00000003 },
409 { RT2870_REG_SCHDMA_WMM_AIFSN_CFG
, 0x00002273 },
410 { RT2870_REG_SCHDMA_WMM_CWMIN_CFG
, 0x00002344 },
411 { RT2870_REG_SCHDMA_WMM_CWMAX_CFG
, 0x000034aa },
414 #define RT2870_DEF_MAC_SIZE (sizeof(rt2870_def_mac) / sizeof(rt2870_def_mac[0]))
439 #define RT2870_DEF_BBP_SIZE (sizeof(rt2870_def_bbp) / sizeof(rt2870_def_bbp[0]))
441 SYSCTL_NODE(_hw
, OID_AUTO
, rt2870
, CTLFLAG_RD
, 0, "RT2870 driver parameters");
444 static int rt2870_debug
= 0;
445 SYSCTL_INT(_hw_rt2870
, OID_AUTO
, debug
, CTLFLAG_RW
, &rt2870_debug
, 0, "rt2870 debug level");
446 TUNABLE_INT("hw.rt2870.debug", &rt2870_debug
);
452 static int rt2870_probe(device_t dev
)
454 struct usb_attach_arg
*uaa
;
456 uaa
= device_get_ivars(dev
);
458 if (uaa
->usb_mode
!= USB_MODE_HOST
)
461 if (uaa
->info
.bConfigIndex
!= RT2870_USB_CONFIG_INDEX
)
464 if (uaa
->info
.bIfaceIndex
!= RT2870_USB_IFACE_INDEX
)
467 return (usbd_lookup_id_by_uaa(rt2870_usb_devid
,
468 sizeof(rt2870_usb_devid
), uaa
));
474 static int rt2870_attach(device_t dev
)
476 struct rt2870_softc
*sc
;
477 struct usb_attach_arg
*uaa
;
478 usb_error_t usb_error
;
479 struct ieee80211com
*ic
;
481 struct usb_interface
*iface
;
482 struct usb_interface_descriptor
*iface_desc
;
484 int error
, ntries
, i
;
486 sc
= device_get_softc(dev
);
487 uaa
= device_get_ivars(dev
);
490 sc
->usb_dev
= uaa
->device
;
492 device_set_usb_desc(dev
);
495 sc
->debug
= rt2870_debug
;
497 SYSCTL_ADD_INT(device_get_sysctl_ctx(dev
),
498 SYSCTL_CHILDREN(device_get_sysctl_tree(dev
)), OID_AUTO
,
499 "debug", CTLFLAG_RW
, &sc
->debug
, 0, "rt2870 debug level");
502 RT2870_DPRINTF(sc
, RT2870_DEBUG_ANY
,
504 device_get_nameunit(sc
->dev
));
506 iface_index
= RT2870_USB_IFACE_INDEX
;
508 iface
= usbd_get_iface(uaa
->device
, iface_index
);
511 printf("%s: could not get USB interface\n",
512 device_get_nameunit(sc
->dev
));
516 iface_desc
= usbd_get_interface_descriptor(iface
);
517 if (iface_desc
== NULL
)
519 printf("%s: could not get USB interface descriptor\n",
520 device_get_nameunit(sc
->dev
));
524 sc
->usb_endpoints
= iface_desc
->bNumEndpoints
;
525 if ((sc
->usb_endpoints
!= RT2870_SOFTC_USB_XFER_COUNT
) &&
526 (sc
->usb_endpoints
!= RT2870_SOFTC_USB_XFER_COUNT
- 2))
528 printf("%s: wrong number of USB endpoints=%d\n",
529 device_get_nameunit(sc
->dev
), sc
->usb_endpoints
);
533 mtx_init(&sc
->lock
, device_get_nameunit(dev
),
534 MTX_NETWORK_LOCK
, MTX_DEF
);
536 usb_error
= usbd_transfer_setup(uaa
->device
, &iface_index
,
537 sc
->usb_xfer
, rt2870_usb_config
, sc
->usb_endpoints
,
541 printf("%s: could not allocate USB transfers: error=%s\n",
542 device_get_nameunit(sc
->dev
), usbd_errstr(usb_error
));
547 RT2870_SOFTC_LOCK(sc
);
549 for (ntries
= 0; ntries
< 100; ntries
++)
551 sc
->mac_rev
= rt2870_io_mac_read(sc
, RT2870_REG_MAC_CSR0
);
552 if (sc
->mac_rev
!= 0x00000000 && sc
->mac_rev
!= 0xffffffff)
560 printf("%s: timeout waiting for NIC to initialize\n",
561 device_get_nameunit(sc
->dev
));
566 rt2870_read_eeprom(sc
);
568 RT2870_SOFTC_UNLOCK(sc
);
570 printf("%s: MAC/BBP RT2870 (rev 0x%08x), RF %s\n",
571 device_get_nameunit(sc
->dev
), sc
->mac_rev
,
572 rt2870_rf_name(sc
->rf_rev
));
574 /* allocate Tx and Rx rings */
576 for (i
= 0; i
< sc
->usb_endpoints
- 1; i
++)
578 error
= rt2870_alloc_tx_ring(sc
, &sc
->tx_ring
[i
], i
);
581 printf("%s: could not allocate Tx ring #%d\n",
582 device_get_nameunit(sc
->dev
), i
);
587 if (sc
->usb_endpoints
== RT2870_SOFTC_USB_XFER_COUNT
)
588 sc
->tx_ring_mgtqid
= 5;
590 sc
->tx_ring_mgtqid
= 0;
592 error
= rt2870_alloc_rx_ring(sc
, &sc
->rx_ring
);
595 printf("%s: could not allocate Rx ring\n",
596 device_get_nameunit(sc
->dev
));
600 callout_init(&sc
->periodic_ch
, 0);
601 callout_init_mtx(&sc
->tx_watchdog_ch
, &sc
->lock
, 0);
603 ifp
= sc
->ifp
= if_alloc(IFT_IEEE80211
);
606 printf("%s: could not if_alloc()\n",
607 device_get_nameunit(sc
->dev
));
614 if_initname(ifp
, "rt2870", device_get_unit(sc
->dev
));
616 ifp
->if_flags
= IFF_BROADCAST
| IFF_SIMPLEX
| IFF_MULTICAST
;
618 ifp
->if_init
= rt2870_init
;
619 ifp
->if_ioctl
= rt2870_ioctl
;
620 ifp
->if_start
= rt2870_start
;
622 IFQ_SET_MAXLEN(&ifp
->if_snd
, IFQ_MAXLEN
);
623 ifp
->if_snd
.ifq_drv_maxlen
= IFQ_MAXLEN
;
624 IFQ_SET_READY(&ifp
->if_snd
);
630 ic
->ic_phytype
= IEEE80211_T_HT
;
631 ic
->ic_opmode
= IEEE80211_M_STA
;
633 ic
->ic_caps
= IEEE80211_C_MONITOR
|
640 /* IEEE80211_C_BGSCAN | */
642 IEEE80211_C_SHPREAMBLE
|
649 ic
->ic_cryptocaps
|= IEEE80211_CRYPTO_WEP
|
650 IEEE80211_CRYPTO_TKIP
|
651 IEEE80211_CRYPTO_TKIPMIC
|
652 IEEE80211_CRYPTO_AES_CCM
;
654 ic
->ic_htcaps
= IEEE80211_HTC_HT
|
655 IEEE80211_HTC_AMSDU
| /* A-MSDU Tx */
656 IEEE80211_HTC_AMPDU
| /* A-MPDU Tx */
657 IEEE80211_HTCAP_MAXAMSDU_3839
| /* max. A-MSDU Rx length */
658 IEEE80211_HTCAP_CHWIDTH40
| /* HT 40MHz channel width */
659 IEEE80211_HTCAP_GREENFIELD
| /* HT greenfield */
660 IEEE80211_HTCAP_SHORTGI20
| /* HT 20MHz short GI */
661 IEEE80211_HTCAP_SHORTGI40
| /* HT 40MHz short GI */
662 IEEE80211_HTCAP_DSSSCCK40
; /* HT 40MHz DSSS/CCK modulation */
664 /* spatial streams */
666 if (sc
->nrxpath
== 2)
667 ic
->ic_htcaps
|= IEEE80211_HTCAP_RXSTBC_2STREAM
;
668 else if (sc
->nrxpath
== 3)
669 ic
->ic_htcaps
|= IEEE80211_HTCAP_RXSTBC_3STREAM
;
671 ic
->ic_htcaps
|= IEEE80211_HTCAP_RXSTBC_1STREAM
;
674 ic
->ic_htcaps
|= IEEE80211_HTCAP_TXSTBC
;
678 if (sc
->mac_rev
!= 0x28600100)
679 ic
->ic_htcaps
|= IEEE80211_HTCAP_DELBA
;
685 rt2870_init_channels(sc
);
687 rt2870_init_channels_ht40(sc
);
689 ieee80211_ifattach(ic
, sc
->mac_addr
);
691 ic
->ic_vap_create
= rt2870_vap_create
;
692 ic
->ic_vap_delete
= rt2870_vap_delete
;
694 ic
->ic_node_alloc
= rt2870_node_alloc
;
695 ic
->ic_setregdomain
= rt2870_setregdomain
;
696 ic
->ic_getradiocaps
= rt2870_getradiocaps
;
697 ic
->ic_scan_start
= rt2870_scan_start
;
698 ic
->ic_scan_end
= rt2870_scan_end
;
699 ic
->ic_set_channel
= rt2870_set_channel
;
700 ic
->ic_newassoc
= rt2870_newassoc
;
701 ic
->ic_updateslot
= rt2870_updateslot
;
702 ic
->ic_update_promisc
= rt2870_update_promisc
;
703 ic
->ic_update_mcast
= rt2870_update_mcast
;
704 ic
->ic_wme
.wme_update
= rt2870_wme_update
;
705 ic
->ic_raw_xmit
= rt2870_raw_xmit
;
707 sc
->recv_action
= ic
->ic_recv_action
;
708 ic
->ic_recv_action
= rt2870_recv_action
;
710 sc
->send_action
= ic
->ic_send_action
;
711 ic
->ic_send_action
= rt2870_send_action
;
713 /* hardware requires padding between 802.11 frame header and body */
715 ic
->ic_flags
|= IEEE80211_F_DATAPAD
| IEEE80211_F_DOTH
;
717 ic
->ic_flags_ext
|= IEEE80211_FEXT_SWBMISS
;
719 ieee80211_radiotap_attach(ic
,
720 &sc
->txtap
.ihdr
, sizeof(sc
->txtap
),
721 RT2870_SOFTC_TX_RADIOTAP_PRESENT
,
722 &sc
->rxtap
.ihdr
, sizeof(sc
->rxtap
),
723 RT2870_SOFTC_RX_RADIOTAP_PRESENT
);
725 /* init task queue */
727 TASK_INIT(&sc
->rx_done_task
, 0, rt2870_rx_done_task
, sc
);
728 TASK_INIT(&sc
->tx_done_task
, 0, rt2870_tx_done_task
, sc
);
729 TASK_INIT(&sc
->periodic_task
, 0, rt2870_periodic_task
, sc
);
730 TASK_INIT(&sc
->cmd_task
, 0, rt2870_cmd_task
, sc
);
732 sc
->rx_process_limit
= 100;
734 sc
->taskqueue
= taskqueue_create("rt2870_taskq", M_NOWAIT
,
735 taskqueue_thread_enqueue
, &sc
->taskqueue
);
737 taskqueue_start_threads(&sc
->taskqueue
, 1, PI_NET
, "%s taskq",
738 device_get_nameunit(sc
->dev
));
740 rt2870_sysctl_attach(sc
);
743 ieee80211_announce(ic
);
749 /* stop all USB transfers */
751 usbd_transfer_unsetup(sc
->usb_xfer
, sc
->usb_endpoints
);
753 /* free Tx and Rx rings */
755 for (i
= 0; i
< sc
->usb_endpoints
- 1; i
++)
756 rt2870_free_tx_ring(sc
, &sc
->tx_ring
[i
]);
758 rt2870_free_rx_ring(sc
, &sc
->rx_ring
);
760 mtx_destroy(&sc
->lock
);
768 static int rt2870_detach(device_t dev
)
770 struct rt2870_softc
*sc
;
771 struct ieee80211com
*ic
;
775 if (!device_is_attached(dev
))
778 sc
= device_get_softc(dev
);
782 RT2870_DPRINTF(sc
, RT2870_DEBUG_ANY
,
784 device_get_nameunit(sc
->dev
));
786 RT2870_SOFTC_LOCK(sc
);
790 ifp
->if_drv_flags
&= ~(IFF_DRV_RUNNING
| IFF_DRV_OACTIVE
);
792 callout_stop(&sc
->periodic_ch
);
793 callout_stop(&sc
->tx_watchdog_ch
);
795 RT2870_SOFTC_UNLOCK(sc
);
797 taskqueue_block(sc
->taskqueue
);
799 taskqueue_drain(sc
->taskqueue
, &sc
->rx_done_task
);
800 taskqueue_drain(sc
->taskqueue
, &sc
->tx_done_task
);
801 taskqueue_drain(sc
->taskqueue
, &sc
->periodic_task
);
802 taskqueue_drain(sc
->taskqueue
, &sc
->cmd_task
);
804 /* stop all USB transfers */
806 usbd_transfer_unsetup(sc
->usb_xfer
, sc
->usb_endpoints
);
808 RT2870_SOFTC_LOCK(sc
);
810 /* free Tx and Rx rings */
812 for (i
= 0; i
< sc
->usb_endpoints
- 1; i
++)
813 rt2870_free_tx_ring(sc
, &sc
->tx_ring
[i
]);
815 rt2870_free_rx_ring(sc
, &sc
->rx_ring
);
817 RT2870_SOFTC_UNLOCK(sc
);
819 ieee80211_ifdetach(ic
);
823 taskqueue_free(sc
->taskqueue
);
825 mtx_destroy(&sc
->lock
);
831 * rt2870_init_channels
833 static void rt2870_init_channels(struct rt2870_softc
*sc
)
836 struct ieee80211com
*ic
;
837 struct ieee80211_channel
*c
;
843 /* set supported channels for 2GHz band */
845 for (i
= 1; i
<= 14; i
++)
847 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
848 flags
= IEEE80211_CHAN_B
;
850 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
854 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
855 flags
= IEEE80211_CHAN_B
| IEEE80211_CHAN_HT20
;
857 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
861 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
862 flags
= IEEE80211_CHAN_G
;
864 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
868 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
869 flags
= IEEE80211_CHAN_G
| IEEE80211_CHAN_HT20
;
871 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
876 /* set supported channels for 5GHz band */
878 if (sc
->rf_rev
== RT2870_EEPROM_RF_2850
||
879 sc
->rf_rev
== RT2870_EEPROM_RF_2750
)
881 for (i
= 36; i
<= 64; i
+= 4)
883 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
884 flags
= IEEE80211_CHAN_A
;
886 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
890 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
891 flags
= IEEE80211_CHAN_A
| IEEE80211_CHAN_HT20
;
893 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
898 for (i
= 100; i
<= 140; i
+= 4)
900 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
901 flags
= IEEE80211_CHAN_A
;
903 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
907 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
908 flags
= IEEE80211_CHAN_A
| IEEE80211_CHAN_HT20
;
910 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
915 for (i
= 149; i
<= 165; i
+= 4)
917 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
918 flags
= IEEE80211_CHAN_A
;
920 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
924 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
925 flags
= IEEE80211_CHAN_A
| IEEE80211_CHAN_HT20
;
927 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
935 * rt2870_init_channels_ht40
937 static void rt2870_init_channels_ht40(struct rt2870_softc
*sc
)
940 struct ieee80211com
*ic
;
941 struct ieee80211_channel
*c
, *cent
, *ext
;
947 /* set supported channels for 2GHz band */
949 for (i
= 1; i
<= 14; i
++)
951 flags
= IEEE80211_CHAN_G
| IEEE80211_CHAN_HT40
;
953 /* find the center channel */
955 cent
= ieee80211_find_channel_byieee(ic
, i
,
956 flags
& ~IEEE80211_CHAN_HT
);
959 printf("%s: skip channel %d, could not find center channel\n",
960 device_get_nameunit(sc
->dev
), i
);
964 /* find the extension channel */
966 ext
= ieee80211_find_channel(ic
, cent
->ic_freq
+ 20,
967 flags
& ~IEEE80211_CHAN_HT
);
970 printf("%s: skip channel %d, could not find extension channel\n",
971 device_get_nameunit(sc
->dev
), i
);
975 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
978 c
->ic_extieee
= ext
->ic_ieee
;
979 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
980 c
->ic_flags
|= IEEE80211_CHAN_HT40U
;
982 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
985 c
->ic_extieee
= cent
->ic_ieee
;
986 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
987 c
->ic_flags
|= IEEE80211_CHAN_HT40D
;
990 /* set supported channels for 5GHz band */
992 if (sc
->rf_rev
== RT2870_EEPROM_RF_2850
||
993 sc
->rf_rev
== RT2870_EEPROM_RF_2750
)
995 for (i
= 36; i
<= 64; i
+= 4)
997 flags
= IEEE80211_CHAN_A
| IEEE80211_CHAN_HT40
;
999 /* find the center channel */
1001 cent
= ieee80211_find_channel_byieee(ic
, i
,
1002 flags
& ~IEEE80211_CHAN_HT
);
1005 printf("%s: skip channel %d, could not find center channel\n",
1006 device_get_nameunit(sc
->dev
), i
);
1010 /* find the extension channel */
1012 ext
= ieee80211_find_channel(ic
, cent
->ic_freq
+ 20,
1013 flags
& ~IEEE80211_CHAN_HT
);
1016 printf("%s: skip channel %d, could not find extension channel\n",
1017 device_get_nameunit(sc
->dev
), i
);
1021 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1024 c
->ic_extieee
= ext
->ic_ieee
;
1025 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1026 c
->ic_flags
|= IEEE80211_CHAN_HT40U
;
1028 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1031 c
->ic_extieee
= cent
->ic_ieee
;
1032 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1033 c
->ic_flags
|= IEEE80211_CHAN_HT40D
;
1036 for (i
= 100; i
<= 140; i
+= 4)
1038 flags
= IEEE80211_CHAN_A
| IEEE80211_CHAN_HT40
;
1040 /* find the center channel */
1042 cent
= ieee80211_find_channel_byieee(ic
, i
,
1043 flags
& ~IEEE80211_CHAN_HT
);
1046 printf("%s: skip channel %d, could not find center channel\n",
1047 device_get_nameunit(sc
->dev
), i
);
1051 /* find the extension channel */
1053 ext
= ieee80211_find_channel(ic
, cent
->ic_freq
+ 20,
1054 flags
& ~IEEE80211_CHAN_HT
);
1057 printf("%s: skip channel %d, could not find extension channel\n",
1058 device_get_nameunit(sc
->dev
), i
);
1062 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1065 c
->ic_extieee
= ext
->ic_ieee
;
1066 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1067 c
->ic_flags
|= IEEE80211_CHAN_HT40U
;
1069 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1072 c
->ic_extieee
= cent
->ic_ieee
;
1073 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1074 c
->ic_flags
|= IEEE80211_CHAN_HT40D
;
1077 for (i
= 149; i
<= 165; i
+= 4)
1079 flags
= IEEE80211_CHAN_A
| IEEE80211_CHAN_HT40
;
1081 /* find the center channel */
1083 cent
= ieee80211_find_channel_byieee(ic
, i
,
1084 flags
& ~IEEE80211_CHAN_HT
);
1087 printf("%s: skip channel %d, could not find center channel\n",
1088 device_get_nameunit(sc
->dev
), i
);
1092 /* find the extension channel */
1094 ext
= ieee80211_find_channel(ic
, cent
->ic_freq
+ 20,
1095 flags
& ~IEEE80211_CHAN_HT
);
1098 printf("%s: skip channel %d, could not find extension channel\n",
1099 device_get_nameunit(sc
->dev
), i
);
1103 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1106 c
->ic_extieee
= ext
->ic_ieee
;
1107 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1108 c
->ic_flags
|= IEEE80211_CHAN_HT40U
;
1110 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1113 c
->ic_extieee
= cent
->ic_ieee
;
1114 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1115 c
->ic_flags
|= IEEE80211_CHAN_HT40D
;
1121 * rt2870_init_locked
1123 static void rt2870_init_locked(void *priv
)
1125 struct rt2870_softc
*sc
;
1127 struct ieee80211com
*ic
;
1128 int ntries
, error
, i
;
1129 uint32_t tmp
, stacnt
[6];
1135 RT2870_DPRINTF(sc
, RT2870_DEBUG_ANY
,
1136 "%s: initializing\n",
1137 device_get_nameunit(sc
->dev
));
1139 RT2870_SOFTC_ASSERT_LOCKED(sc
);
1141 if (!(sc
->flags
& RT2870_SOFTC_FLAGS_UCODE_LOADED
))
1143 RT2870_DPRINTF(sc
, RT2870_DEBUG_ANY
,
1144 "%s: loading 8051 microcode\n",
1145 device_get_nameunit(sc
->dev
));
1147 error
= rt2870_io_mcu_load_ucode(sc
, rt2870_ucode
, sizeof(rt2870_ucode
));
1150 printf("%s: could not load 8051 microcode\n",
1151 device_get_nameunit(sc
->dev
));
1155 RT2870_DPRINTF(sc
, RT2870_DEBUG_ANY
,
1156 "%s: 8051 microcode was successfully loaded\n",
1157 device_get_nameunit(sc
->dev
));
1159 sc
->flags
|= RT2870_SOFTC_FLAGS_UCODE_LOADED
;
1162 /* wait while DMA engine is busy */
1164 for (ntries
= 0; ntries
< 100; ntries
++)
1166 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_SCHDMA_WPDMA_GLO_CFG
);
1167 if (!(tmp
& (RT2870_REG_TX_DMA_BUSY
| RT2870_REG_RX_DMA_BUSY
)))
1175 printf("%s: timeout waiting for DMA engine\n",
1176 device_get_nameunit(sc
->dev
));
1181 tmp
|= RT2870_REG_TX_WB_DDONE
;
1183 rt2870_io_mac_write(sc
, RT2870_REG_SCHDMA_WPDMA_GLO_CFG
, tmp
);
1185 /* PBF hardware reset */
1187 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_PBF_SYS_CTRL
);
1191 rt2870_io_mac_write(sc
, RT2870_REG_PBF_SYS_CTRL
, tmp
);
1193 rt2870_io_mac_write(sc
, RT2870_REG_SYS_CTRL
,
1194 RT2870_REG_MAC_SRST
| RT2870_REG_BBP_HRST
);
1196 rt2870_io_mac_write(sc
, RT2870_REG_SCHDMA_USB_DMA_CFG
, 0);
1198 rt2870_io_mcu_reset(sc
);
1200 rt2870_io_mac_write(sc
, RT2870_REG_SYS_CTRL
, 0);
1202 /* init Tx power per rate */
1204 for (i
= 0; i
< RT2870_SOFTC_TXPOW_RATE_COUNT
; i
++)
1206 if (sc
->txpow_rate_20mhz
[i
] == 0xffffffff)
1209 rt2870_io_mac_write(sc
, RT2870_REG_TX_PWR_CFG(i
),
1210 sc
->txpow_rate_20mhz
[i
]);
1213 for (i
= 0; i
< RT2870_DEF_MAC_SIZE
; i
++)
1214 rt2870_io_mac_write(sc
, rt2870_def_mac
[i
].reg
,
1215 rt2870_def_mac
[i
].val
);
1217 /* wait while MAC is busy */
1219 for (ntries
= 0; ntries
< 100; ntries
++)
1221 if (!(rt2870_io_mac_read(sc
, RT2870_REG_STATUS_CFG
) &
1222 (RT2870_REG_STATUS_TX_BUSY
| RT2870_REG_STATUS_RX_BUSY
)))
1230 printf("%s: timeout waiting for MAC\n",
1231 device_get_nameunit(sc
->dev
));
1235 /* clear Host to MCU mailbox */
1237 rt2870_io_mac_write(sc
, RT2870_REG_H2M_MAILBOX_BBP_AGENT
, 0);
1238 rt2870_io_mac_write(sc
, RT2870_REG_H2M_MAILBOX
, 0);
1242 error
= rt2870_init_bbp(sc
);
1246 /* set up maximum buffer sizes */
1248 tmp
= (1 << 12) | RT2870_MAX_AGG_SIZE
;
1250 rt2870_io_mac_write(sc
, RT2870_REG_MAX_LEN_CFG
, tmp
);
1252 if (sc
->mac_rev
== 0x28720200)
1254 /* set max. PSDU length from 16K to 32K bytes */
1256 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_MAX_LEN_CFG
);
1261 rt2870_io_mac_write(sc
, RT2870_REG_MAX_LEN_CFG
, tmp
);
1264 if (sc
->mac_rev
>= 0x28720200 && sc
->mac_rev
< 0x30700200)
1266 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_MAX_LEN_CFG
);
1271 rt2870_io_mac_write(sc
, RT2870_REG_MAX_LEN_CFG
, tmp
);
1274 /* set mac address */
1276 rt2870_asic_set_macaddr(sc
, IF_LLADDR(ifp
));
1278 /* clear statistic registers */
1280 rt2870_io_mac_read_multi(sc
, RT2870_REG_RX_STA_CNT0
,
1281 stacnt
, sizeof(stacnt
));
1283 /* send LEDs operating mode to microcontroller */
1285 rt2870_io_mcu_cmd(sc
, RT2870_IO_MCU_CMD_LED1
,
1286 RT2870_REG_H2M_TOKEN_NO_INTR
, sc
->led_off
[0]);
1287 rt2870_io_mcu_cmd(sc
, RT2870_IO_MCU_CMD_LED2
,
1288 RT2870_REG_H2M_TOKEN_NO_INTR
, sc
->led_off
[1]);
1289 rt2870_io_mcu_cmd(sc
, RT2870_IO_MCU_CMD_LED3
,
1290 RT2870_REG_H2M_TOKEN_NO_INTR
, sc
->led_off
[2]);
1292 /* write vendor-specific BBP values (from EEPROM) */
1294 for (i
= 0; i
< RT2870_SOFTC_BBP_EEPROM_COUNT
; i
++)
1296 if (sc
->bbp_eeprom
[i
].reg
== 0x00 ||
1297 sc
->bbp_eeprom
[i
].reg
== 0xff)
1300 rt2870_io_bbp_write(sc
, sc
->bbp_eeprom
[i
].reg
,
1301 sc
->bbp_eeprom
[i
].val
);
1304 /* disable non-existing Rx chains */
1306 tmp
= rt2870_io_bbp_read(sc
, 3);
1308 tmp
&= ~((1 << 4) | (1 << 3));
1310 if (sc
->nrxpath
== 3)
1312 else if (sc
->nrxpath
== 2)
1315 rt2870_io_bbp_write(sc
, 3, tmp
);
1317 /* disable non-existing Tx chains */
1319 tmp
= rt2870_io_bbp_read(sc
, 1);
1321 tmp
&= ~((1 << 4) | (1 << 3));
1323 if (sc
->ntxpath
== 2)
1326 rt2870_io_bbp_write(sc
, 1, tmp
);
1328 /* set current channel */
1330 rt2870_rf_set_chan(sc
, ic
->ic_curchan
);
1332 /* turn radio LED on */
1334 rt2870_led_cmd(sc
, RT2870_LED_CMD_RADIO_ON
);
1336 rt2870_io_mcu_cmd(sc
, RT2870_IO_MCU_CMD_BOOT
,
1337 RT2870_REG_H2M_TOKEN_NO_INTR
, 0);
1339 /* set RTS threshold */
1341 rt2870_asic_update_rtsthreshold(sc
);
1345 rt2870_asic_update_txpower(sc
);
1347 /* set up protection mode */
1349 rt2870_asic_updateprot(sc
);
1351 /* clear key tables */
1353 rt2870_asic_clear_keytables(sc
);
1355 /* clear beacon frame space (entries = 8, entry size = 512) */
1357 rt2870_io_mac_set_region_4(sc
, RT2870_REG_BEACON_BASE(0), 0, 1024);
1359 if (rt2870_txrx_enable(sc
) != 0)
1362 /* clear garbage interrupts */
1364 tmp
= rt2870_io_mac_read(sc
, 0x1300);
1366 taskqueue_unblock(sc
->taskqueue
);
1368 /* init Tx and Rx rings */
1370 for(i
= 0; i
< sc
->usb_endpoints
- 1; i
++)
1371 rt2870_reset_tx_ring(sc
, &sc
->tx_ring
[i
]);
1373 rt2870_reset_rx_ring(sc
, &sc
->rx_ring
);
1375 rt2870_reset_cmd_ring(sc
, &sc
->cmd_ring
);
1377 for(i
= 0; i
< sc
->usb_endpoints
- 1; i
++)
1379 usbd_xfer_set_priv(sc
->usb_xfer
[i
+ 1], &sc
->tx_ring
[i
]);
1380 usbd_xfer_set_stall(sc
->usb_xfer
[i
+ 1]);
1383 /* start up the receive pipe */
1385 for(i
= 0; i
< RT2870_SOFTC_RX_RING_DATA_COUNT
; i
++)
1386 usbd_transfer_start(sc
->usb_xfer
[0]);
1388 ifp
->if_drv_flags
&= ~IFF_DRV_OACTIVE
;
1389 ifp
->if_drv_flags
|= IFF_DRV_RUNNING
;
1391 sc
->periodic_round
= 0;
1393 callout_reset(&sc
->periodic_ch
, hz
/ 10, rt2870_periodic
, sc
);
1399 rt2870_stop_locked(sc
);
1405 static void rt2870_init(void *priv
)
1407 struct rt2870_softc
*sc
;
1411 RT2870_SOFTC_LOCK(sc
);
1413 rt2870_init_locked(sc
);
1415 RT2870_SOFTC_UNLOCK(sc
);
1421 static int rt2870_init_bbp(struct rt2870_softc
*sc
)
1426 for (ntries
= 0; ntries
< 20; ntries
++)
1428 tmp
= rt2870_io_bbp_read(sc
, 0);
1429 if (tmp
!= 0x00 && tmp
!= 0xff)
1433 if (tmp
== 0x00 || tmp
== 0xff)
1435 printf("%s: timeout waiting for BBP to wakeup\n",
1436 device_get_nameunit(sc
->dev
));
1440 for (i
= 0; i
< RT2870_DEF_BBP_SIZE
; i
++)
1441 rt2870_io_bbp_write(sc
, rt2870_def_bbp
[i
].reg
,
1442 rt2870_def_bbp
[i
].val
);
1444 if ((sc
->mac_rev
& 0xffff) != 0x0101)
1445 rt2870_io_bbp_write(sc
, 84, 0x19);
1447 if (sc
->mac_rev
== 0x28600100)
1449 rt2870_io_bbp_write(sc
, 69, 0x16);
1450 rt2870_io_bbp_write(sc
, 73, 0x12);
1457 * rt2870_stop_locked
1459 static void rt2870_stop_locked(void *priv
)
1461 struct rt2870_softc
*sc
;
1463 struct ieee80211com
*ic
;
1471 RT2870_DPRINTF(sc
, RT2870_DEBUG_ANY
,
1473 device_get_nameunit(sc
->dev
));
1475 RT2870_SOFTC_ASSERT_LOCKED(sc
);
1479 if (ifp
->if_drv_flags
& IFF_DRV_RUNNING
)
1480 rt2870_led_cmd(sc
, RT2870_LED_CMD_RADIO_OFF
);
1482 ifp
->if_drv_flags
&= ~(IFF_DRV_RUNNING
| IFF_DRV_OACTIVE
);
1484 callout_stop(&sc
->periodic_ch
);
1485 callout_stop(&sc
->tx_watchdog_ch
);
1487 RT2870_SOFTC_UNLOCK(sc
);
1489 taskqueue_block(sc
->taskqueue
);
1491 taskqueue_drain(sc
->taskqueue
, &sc
->rx_done_task
);
1492 taskqueue_drain(sc
->taskqueue
, &sc
->tx_done_task
);
1493 taskqueue_drain(sc
->taskqueue
, &sc
->periodic_task
);
1494 taskqueue_drain(sc
->taskqueue
, &sc
->cmd_task
);
1496 RT2870_SOFTC_LOCK(sc
);
1498 /* clear key tables */
1500 rt2870_asic_clear_keytables(sc
);
1504 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_SYS_CTRL
);
1506 tmp
&= ~(RT2870_REG_RX_ENABLE
| RT2870_REG_TX_ENABLE
);
1508 rt2870_io_mac_write(sc
, RT2870_REG_SYS_CTRL
, tmp
);
1510 rt2870_io_mac_write(sc
, RT2870_REG_SCHDMA_USB_DMA_CFG
, 0);
1514 rt2870_io_mac_write(sc
, RT2870_REG_SYS_CTRL
,
1515 RT2870_REG_MAC_SRST
| RT2870_REG_BBP_HRST
);
1516 rt2870_io_mac_write(sc
, RT2870_REG_SYS_CTRL
, 0);
1518 /* abort any pending transfers */
1520 for (i
= 0; i
< sc
->usb_endpoints
; i
++)
1521 usbd_transfer_stop(sc
->usb_xfer
[i
]);
1527 static void rt2870_stop(void *priv
)
1529 struct rt2870_softc
*sc
;
1533 RT2870_SOFTC_LOCK(sc
);
1535 rt2870_stop_locked(sc
);
1537 RT2870_SOFTC_UNLOCK(sc
);
1543 static void rt2870_start(struct ifnet
*ifp
)
1545 struct rt2870_softc
*sc
;
1546 struct ieee80211_node
*ni
;
1552 RT2870_SOFTC_LOCK(sc
);
1554 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
1556 RT2870_SOFTC_UNLOCK(sc
);
1562 IF_POLL(&ifp
->if_snd
, m
);
1566 IFQ_DRV_DEQUEUE(&ifp
->if_snd
, m
);
1568 ni
= (struct ieee80211_node
*) m
->m_pkthdr
.rcvif
;
1570 qid
= M_WME_GETAC(m
);
1572 if (sc
->tx_ring
[qid
].queued
>= RT2870_SOFTC_TX_RING_DATA_COUNT
)
1574 RT2870_DPRINTF(sc
, RT2870_DEBUG_TX
,
1575 "%s: if_start: Tx ring with qid=%d is full\n",
1576 device_get_nameunit(sc
->dev
), qid
);
1579 ieee80211_free_node(ni
);
1581 ifp
->if_drv_flags
|= IFF_DRV_OACTIVE
;
1584 sc
->tx_data_queue_full
[qid
]++;
1589 if (rt2870_tx_data(sc
, m
, ni
, qid
) != 0)
1591 ieee80211_free_node(ni
);
1596 sc
->tx_timer
= RT2870_TX_WATCHDOG_TIMEOUT
;
1598 callout_reset(&sc
->tx_watchdog_ch
, hz
, rt2870_tx_watchdog
, sc
);
1601 RT2870_SOFTC_UNLOCK(sc
);
1607 static int rt2870_ioctl(struct ifnet
*ifp
, u_long cmd
, caddr_t data
)
1609 struct rt2870_softc
*sc
;
1610 struct ieee80211com
*ic
;
1612 int error
, startall
;
1616 ifr
= (struct ifreq
*) data
;
1625 RT2870_SOFTC_LOCK(sc
);
1627 if (ifp
->if_flags
& IFF_UP
)
1629 if (ifp
->if_drv_flags
& IFF_DRV_RUNNING
)
1631 if ((ifp
->if_flags
^ sc
->if_flags
) & IFF_PROMISC
)
1632 rt2870_asic_update_promisc(sc
);
1636 rt2870_init_locked(sc
);
1642 if (ifp
->if_drv_flags
& IFF_DRV_RUNNING
)
1643 rt2870_stop_locked(sc
);
1646 sc
->if_flags
= ifp
->if_flags
;
1648 RT2870_SOFTC_UNLOCK(sc
);
1651 ieee80211_start_all(ic
);
1656 error
= ifmedia_ioctl(ifp
, ifr
, &ic
->ic_media
, cmd
);
1660 error
= ether_ioctl(ifp
, cmd
, data
);
1674 static struct ieee80211vap
*rt2870_vap_create(struct ieee80211com
*ic
,
1675 const char name
[IFNAMSIZ
], int unit
, int opmode
, int flags
,
1676 const uint8_t bssid
[IEEE80211_ADDR_LEN
],
1677 const uint8_t mac
[IEEE80211_ADDR_LEN
])
1679 struct rt2870_softc
*sc
;
1681 struct rt2870_softc_vap
*rvap
;
1682 struct ieee80211vap
*vap
;
1687 RT2870_DPRINTF(sc
, RT2870_DEBUG_STATE
,
1688 "%s: VAP create: opmode=%s\n",
1689 device_get_nameunit(sc
->dev
),
1690 ieee80211_opmode_name
[opmode
]);
1694 case IEEE80211_M_MONITOR
:
1695 case IEEE80211_M_IBSS
:
1696 case IEEE80211_M_STA
:
1697 case IEEE80211_M_AHDEMO
:
1698 case IEEE80211_M_HOSTAP
:
1699 case IEEE80211_M_MBSS
:
1700 if (!TAILQ_EMPTY(&ic
->ic_vaps
))
1702 if_printf(ifp
, "only 1 VAP supported\n");
1706 if (opmode
== IEEE80211_M_STA
)
1707 flags
|= IEEE80211_CLONE_NOBEACONS
;
1710 case IEEE80211_M_WDS
:
1711 if (TAILQ_EMPTY(&ic
->ic_vaps
) || ic
->ic_opmode
!= IEEE80211_M_HOSTAP
)
1713 if_printf(ifp
, "WDS only supported in AP mode\n");
1717 flags
&= ~IEEE80211_CLONE_BSSID
;
1721 if_printf(ifp
, "unknown opmode %d\n", opmode
);
1725 rvap
= (struct rt2870_softc_vap
*) malloc(sizeof(struct rt2870_softc_vap
),
1726 M_80211_VAP
, M_NOWAIT
| M_ZERO
);
1732 ieee80211_vap_setup(ic
, vap
, name
, unit
, opmode
, flags
, bssid
, mac
);
1734 rvap
->newstate
= vap
->iv_newstate
;
1735 vap
->iv_newstate
= rt2870_vap_newstate
;
1737 vap
->iv_reset
= rt2870_vap_reset
;
1738 vap
->iv_key_update_begin
= rt2870_vap_key_update_begin
;
1739 vap
->iv_key_update_end
= rt2870_vap_key_update_end
;
1740 vap
->iv_key_set
= rt2870_vap_key_set
;
1741 vap
->iv_key_delete
= rt2870_vap_key_delete
;
1742 vap
->iv_update_beacon
= rt2870_vap_update_beacon
;
1744 rt2870_amrr_init(&rvap
->amrr
, vap
,
1746 RT2870_AMRR_MIN_SUCCESS_THRESHOLD
,
1747 RT2870_AMRR_MAX_SUCCESS_THRESHOLD
,
1750 ieee80211_vap_attach(vap
, ieee80211_media_change
, ieee80211_media_status
);
1752 ic
->ic_opmode
= opmode
;
1760 static void rt2870_vap_delete(struct ieee80211vap
*vap
)
1762 struct rt2870_softc
*sc
;
1763 struct ieee80211com
*ic
;
1765 struct rt2870_softc_vap
*rvap
;
1770 rvap
= (struct rt2870_softc_vap
*) vap
;
1772 RT2870_DPRINTF(sc
, RT2870_DEBUG_STATE
,
1773 "%s: VAP delete: opmode=%s\n",
1774 device_get_nameunit(sc
->dev
),
1775 ieee80211_opmode_name
[vap
->iv_opmode
]);
1777 rt2870_amrr_cleanup(&rvap
->amrr
);
1779 ieee80211_vap_detach(vap
);
1781 free(rvap
, M_80211_VAP
);
1787 static int rt2870_vap_reset(struct ieee80211vap
*vap
, u_long cmd
)
1789 struct rt2870_softc
*sc
;
1790 struct ieee80211com
*ic
;
1792 struct rt2870_softc_vap
*rvap
;
1798 rvap
= (struct rt2870_softc_vap
*) vap
;
1800 RT2870_DPRINTF(sc
, RT2870_DEBUG_STATE
,
1801 "%s: VAP reset: cmd=%lu\n",
1802 device_get_nameunit(sc
->dev
), cmd
);
1806 RT2870_SOFTC_LOCK(sc
);
1810 case IEEE80211_IOC_RTSTHRESHOLD
:
1811 rt2870_asic_update_rtsthreshold(sc
);
1814 case IEEE80211_IOC_PROTMODE
:
1815 case IEEE80211_IOC_HTPROTMODE
:
1816 rt2870_asic_updateprot(sc
);
1819 case IEEE80211_IOC_TXPOWER
:
1820 rt2870_asic_update_txpower(sc
);
1823 case IEEE80211_IOC_SHORTGI
:
1824 case IEEE80211_IOC_AMPDU_DENSITY
:
1832 RT2870_SOFTC_UNLOCK(sc
);
1838 * rt2870_vap_newstate
1840 static int rt2870_vap_newstate(struct ieee80211vap
*vap
,
1841 enum ieee80211_state nstate
, int arg
)
1843 struct rt2870_softc
*sc
;
1844 struct ieee80211com
*ic
;
1846 struct rt2870_softc_vap
*rvap
;
1847 struct ieee80211_node
*ni
;
1853 rvap
= (struct rt2870_softc_vap
*) vap
;
1855 RT2870_DPRINTF(sc
, RT2870_DEBUG_STATE
,
1856 "%s: VAP newstate: %s -> %s\n",
1857 device_get_nameunit(sc
->dev
),
1858 ieee80211_state_name
[vap
->iv_state
], ieee80211_state_name
[nstate
]);
1860 error
= rvap
->newstate(vap
, nstate
, arg
);
1864 IEEE80211_UNLOCK(ic
);
1866 RT2870_SOFTC_LOCK(sc
);
1868 /* turn link LED off */
1870 if (nstate
!= IEEE80211_S_RUN
)
1871 rt2870_led_cmd(sc
, RT2870_LED_CMD_RADIO_OFF
);
1875 case IEEE80211_S_INIT
:
1876 rt2870_asic_disable_tsf_sync(sc
);
1879 case IEEE80211_S_RUN
:
1882 rt2870_rf_set_chan(sc
, ni
->ni_chan
);
1884 if (vap
->iv_opmode
!= IEEE80211_M_MONITOR
)
1886 rt2870_asic_enable_mrr(sc
);
1887 rt2870_asic_set_txpreamble(sc
);
1888 rt2870_asic_set_basicrates(sc
);
1889 rt2870_asic_update_txpower(sc
);
1890 rt2870_asic_set_bssid(sc
, ni
->ni_bssid
);
1893 if (vap
->iv_opmode
== IEEE80211_M_HOSTAP
||
1894 vap
->iv_opmode
== IEEE80211_M_IBSS
||
1895 vap
->iv_opmode
== IEEE80211_M_MBSS
)
1897 error
= rt2870_asic_update_beacon(sc
, vap
);
1902 if (vap
->iv_opmode
!= IEEE80211_M_MONITOR
)
1903 rt2870_asic_enable_tsf_sync(sc
);
1905 /* turn link LED on */
1907 if (vap
->iv_opmode
!= IEEE80211_M_MONITOR
)
1909 rt2870_led_cmd(sc
, RT2870_LED_CMD_RADIO_ON
|
1910 (IEEE80211_IS_CHAN_2GHZ(ni
->ni_chan
) ?
1911 RT2870_LED_CMD_LINK_2GHZ
: RT2870_LED_CMD_LINK_5GHZ
));
1919 RT2870_SOFTC_UNLOCK(sc
);
1927 * rt2870_vap_key_update_begin
1929 static void rt2870_vap_key_update_begin(struct ieee80211vap
*vap
)
1931 struct rt2870_softc
*sc
;
1932 struct ieee80211com
*ic
;
1939 RT2870_DPRINTF(sc
, RT2870_DEBUG_KEY
,
1940 "%s: VAP key update begin\n",
1941 device_get_nameunit(sc
->dev
));
1943 taskqueue_block(sc
->taskqueue
);
1945 IF_LOCK(&ifp
->if_snd
);
1949 * rt2870_vap_key_update_end
1951 static void rt2870_vap_key_update_end(struct ieee80211vap
*vap
)
1953 struct rt2870_softc
*sc
;
1954 struct ieee80211com
*ic
;
1961 RT2870_DPRINTF(sc
, RT2870_DEBUG_KEY
,
1962 "%s: VAP key update end\n",
1963 device_get_nameunit(sc
->dev
));
1965 IF_UNLOCK(&ifp
->if_snd
);
1967 taskqueue_unblock(sc
->taskqueue
);
1971 * rt2870_vap_key_set
1973 static int rt2870_vap_key_set(struct ieee80211vap
*vap
,
1974 const struct ieee80211_key
*k
, const uint8_t mac
[IEEE80211_ADDR_LEN
])
1976 struct rt2870_softc
*sc
;
1977 struct ieee80211com
*ic
;
1979 struct ieee80211_node
*ni
;
1980 uint16_t associd
, key_base
, keymode_base
;
1981 uint8_t mode
, vapid
, wcid
, iv
[8];
1984 if (k
->wk_cipher
->ic_cipher
!= IEEE80211_CIPHER_WEP
&&
1985 k
->wk_cipher
->ic_cipher
!= IEEE80211_CIPHER_TKIP
&&
1986 k
->wk_cipher
->ic_cipher
!= IEEE80211_CIPHER_AES_CCM
)
1993 if (vap
->iv_opmode
!= IEEE80211_M_HOSTAP
)
1996 ni
= ieee80211_find_vap_node(&ic
->ic_sta
, vap
, mac
);
1998 associd
= (ni
!= NULL
) ? ni
->ni_associd
: 0;
2000 if ((vap
->iv_opmode
== IEEE80211_M_HOSTAP
) && (ni
!= NULL
))
2001 ieee80211_free_node(ni
);
2003 switch (k
->wk_cipher
->ic_cipher
)
2005 case IEEE80211_CIPHER_WEP
:
2006 if(k
->wk_keylen
< 8)
2007 mode
= RT2870_REG_CIPHER_MODE_WEP40
;
2009 mode
= RT2870_REG_CIPHER_MODE_WEP104
;
2012 case IEEE80211_CIPHER_TKIP
:
2013 mode
= RT2870_REG_CIPHER_MODE_TKIP
;
2016 case IEEE80211_CIPHER_AES_CCM
:
2017 mode
= RT2870_REG_CIPHER_MODE_AES_CCMP
;
2024 RT2870_DPRINTF(sc
, RT2870_DEBUG_KEY
,
2025 "%s: VAP key set: keyix=%d, keylen=%d, associd=0x%04x, mode=%d, group=%d\n",
2026 device_get_nameunit(sc
->dev
), k
->wk_keyix
, k
->wk_keylen
, associd
, mode
,
2027 (k
->wk_flags
& IEEE80211_KEY_GROUP
) ? 1 : 0);
2029 RT2870_SOFTC_LOCK(sc
);
2031 if (!(k
->wk_flags
& IEEE80211_KEY_GROUP
))
2033 /* install pairwise key */
2036 wcid
= RT2870_AID2WCID(associd
);
2037 key_base
= RT2870_REG_PKEY(wcid
);
2039 if (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_WEP
)
2043 iv
[3] = (k
->wk_keyix
<< 6);
2047 if (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_TKIP
)
2049 iv
[0] = (k
->wk_keytsc
>> 8);
2050 iv
[1] = ((iv
[0] | 0x20) & 0x7f);
2051 iv
[2] = k
->wk_keytsc
;
2057 iv
[0] = k
->wk_keytsc
;
2058 iv
[1] = k
->wk_keytsc
>> 8;
2062 iv
[3] = ((k
->wk_keyix
<< 6) | IEEE80211_WEP_EXTIV
);
2063 iv
[4] = (k
->wk_keytsc
>> 16);
2064 iv
[5] = (k
->wk_keytsc
>> 24);
2065 iv
[6] = (k
->wk_keytsc
>> 32);
2066 iv
[7] = (k
->wk_keytsc
>> 40);
2068 RT2870_DPRINTF(sc
, RT2870_DEBUG_KEY
,
2069 "%s: set key: iv=%02x %02x %02x %02x %02x %02x %02x %02x\n",
2070 device_get_nameunit(sc
->dev
),
2071 iv
[0], iv
[1], iv
[2], iv
[3], iv
[4], iv
[5], iv
[6], iv
[7]);
2074 rt2870_io_mac_write_multi(sc
, RT2870_REG_IVEIV(wcid
), iv
, 8);
2076 if (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_TKIP
)
2078 rt2870_io_mac_write_multi(sc
, key_base
, k
->wk_key
, 16);
2080 if (vap
->iv_opmode
!= IEEE80211_M_HOSTAP
)
2082 rt2870_io_mac_write_multi(sc
, key_base
+ 16, &k
->wk_key
[16], 8);
2083 rt2870_io_mac_write_multi(sc
, key_base
+ 24, &k
->wk_key
[24], 8);
2087 rt2870_io_mac_write_multi(sc
, key_base
+ 16, &k
->wk_key
[24], 8);
2088 rt2870_io_mac_write_multi(sc
, key_base
+ 24, &k
->wk_key
[16], 8);
2093 rt2870_io_mac_write_multi(sc
, key_base
, k
->wk_key
, k
->wk_keylen
);
2096 tmp
= ((vapid
& RT2870_REG_VAP_MASK
) << RT2870_REG_VAP_SHIFT
) |
2097 (mode
<< RT2870_REG_CIPHER_MODE_SHIFT
) | RT2870_REG_PKEY_ENABLE
;
2099 rt2870_io_mac_write(sc
, RT2870_REG_WCID_ATTR(wcid
), tmp
);
2102 if ((k
->wk_flags
& IEEE80211_KEY_GROUP
) ||
2103 (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_WEP
))
2105 /* install group key */
2108 key_base
= RT2870_REG_SKEY(vapid
, k
->wk_keyix
);
2109 keymode_base
= RT2870_REG_SKEY_MODE(vapid
);
2111 if (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_TKIP
)
2113 rt2870_io_mac_write_multi(sc
, key_base
, k
->wk_key
, 16);
2115 if (vap
->iv_opmode
!= IEEE80211_M_HOSTAP
)
2117 rt2870_io_mac_write_multi(sc
, key_base
+ 16, &k
->wk_key
[16], 8);
2118 rt2870_io_mac_write_multi(sc
, key_base
+ 24, &k
->wk_key
[24], 8);
2122 rt2870_io_mac_write_multi(sc
, key_base
+ 16, &k
->wk_key
[24], 8);
2123 rt2870_io_mac_write_multi(sc
, key_base
+ 24, &k
->wk_key
[16], 8);
2128 rt2870_io_mac_write_multi(sc
, key_base
, k
->wk_key
, k
->wk_keylen
);
2131 tmp
= rt2870_io_mac_read(sc
, keymode_base
);
2133 tmp
&= ~(0xf << (k
->wk_keyix
* 4 + 16 * (vapid
% 2)));
2134 tmp
|= (mode
<< (k
->wk_keyix
* 4 + 16 * (vapid
% 2)));
2136 rt2870_io_mac_write(sc
, keymode_base
, tmp
);
2139 RT2870_SOFTC_UNLOCK(sc
);
2145 * rt2870_vap_key_delete
2147 static int rt2870_vap_key_delete(struct ieee80211vap
*vap
,
2148 const struct ieee80211_key
*k
)
2150 struct rt2870_softc
*sc
;
2151 struct ieee80211com
*ic
;
2153 struct ieee80211_node
*ni
;
2154 struct rt2870_cmd_argv_keydelete cmd_argv
;
2161 associd
= (ni
!= NULL
) ? ni
->ni_associd
: 0;
2163 RT2870_DPRINTF(sc
, RT2870_DEBUG_KEY
,
2164 "%s: VAP key delete: keyix=%d, keylen=%d, associd=0x%04x, group=%d\n",
2165 device_get_nameunit(sc
->dev
), k
->wk_keyix
, k
->wk_keylen
, associd
,
2166 (k
->wk_flags
& IEEE80211_KEY_GROUP
) ? 1 : 0);
2168 memcpy(&cmd_argv
.key
, k
, sizeof(struct ieee80211_key
));
2169 cmd_argv
.associd
= associd
;
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
;
2190 RT2870_DPRINTF(sc
, RT2870_DEBUG_BEACON
,
2191 "%s: VAP update beacon\n",
2192 device_get_nameunit(sc
->dev
));
2194 rt2870_do_async(sc
, rt2870_vap_update_beacon_cb
, NULL
, 0);
2200 static struct ieee80211_node
*rt2870_node_alloc(struct ieee80211vap
*vap
,
2201 const uint8_t mac
[IEEE80211_ADDR_LEN
])
2203 return malloc(sizeof(struct rt2870_softc_node
),
2204 M_80211_NODE
, M_NOWAIT
| M_ZERO
);
2208 * rt2870_setregdomain
2210 static int rt2870_setregdomain(struct ieee80211com
*ic
,
2211 struct ieee80211_regdomain
*reg
,
2212 int nchans
, struct ieee80211_channel chans
[])
2214 struct rt2870_softc
*sc
;
2220 RT2870_DPRINTF(sc
, RT2870_DEBUG_STATE
,
2221 "%s: set regulatory domain: country=%d, country code string=%c%c, location=%c\n",
2222 device_get_nameunit(sc
->dev
),
2223 reg
->country
, reg
->isocc
[0], reg
->isocc
[1], reg
->location
);
2229 * rt2870_getradiocaps
2231 static void rt2870_getradiocaps(struct ieee80211com
*ic
,
2232 int maxchans
, int *nchans
, struct ieee80211_channel chans
[])
2234 *nchans
= (ic
->ic_nchans
>= maxchans
) ? maxchans
: ic
->ic_nchans
;
2236 memcpy(chans
, ic
->ic_channels
, (*nchans
) * sizeof(struct ieee80211_channel
));
2242 static void rt2870_scan_start(struct ieee80211com
*ic
)
2244 struct rt2870_softc
*sc
;
2250 RT2870_SOFTC_LOCK(sc
);
2252 rt2870_asic_disable_tsf_sync(sc
);
2254 RT2870_SOFTC_UNLOCK(sc
);
2260 static void rt2870_scan_end(struct ieee80211com
*ic
)
2262 struct rt2870_softc
*sc
;
2268 RT2870_SOFTC_LOCK(sc
);
2270 rt2870_asic_enable_tsf_sync(sc
);
2272 RT2870_SOFTC_UNLOCK(sc
);
2276 * rt2870_set_channel
2278 static void rt2870_set_channel(struct ieee80211com
*ic
)
2280 struct rt2870_softc
*sc
;
2286 RT2870_DPRINTF(sc
, RT2870_DEBUG_CHAN
,
2287 "%s: set channel: channel=%u, HT%s%s\n",
2288 device_get_nameunit(sc
->dev
),
2289 ieee80211_chan2ieee(ic
, ic
->ic_curchan
),
2290 !IEEE80211_IS_CHAN_HT(ic
->ic_curchan
) ? " disabled" :
2291 IEEE80211_IS_CHAN_HT20(ic
->ic_curchan
) ? "20":
2292 IEEE80211_IS_CHAN_HT40U(ic
->ic_curchan
) ? "40U" : "40D",
2293 (ic
->ic_flags
& IEEE80211_F_SCAN
) ? ", scanning" : "");
2295 RT2870_SOFTC_LOCK(sc
);
2297 rt2870_rf_set_chan(sc
, ic
->ic_curchan
);
2299 RT2870_SOFTC_UNLOCK(sc
);
2305 static void rt2870_newassoc(struct ieee80211_node
*ni
, int isnew
)
2307 struct rt2870_softc
*sc
;
2308 struct ieee80211com
*ic
;
2310 struct ieee80211vap
*vap
;
2311 struct rt2870_softc_vap
*rvap
;
2319 rvap
= (struct rt2870_softc_vap
*) vap
;
2321 associd
= (ni
!= NULL
) ? ni
->ni_associd
: 0;
2322 wcid
= RT2870_AID2WCID(associd
);
2324 RT2870_DPRINTF(sc
, RT2870_DEBUG_NODE
,
2325 "%s: new association: wcid=0x%02x, "
2326 "mac addr=%s, QoS %s, ERP %s, HT %s\n",
2327 device_get_nameunit(sc
->dev
), wcid
,
2328 ether_sprintf(ni
->ni_macaddr
),
2329 (ni
->ni_flags
& IEEE80211_NODE_QOS
) ? "enabled" : "disabled",
2330 (ni
->ni_flags
& IEEE80211_NODE_ERP
) ? "enabled" : "disabled",
2331 (ni
->ni_flags
& IEEE80211_NODE_HT
) ? "enabled" : "disabled");
2333 RT2870_SOFTC_LOCK(sc
);
2335 rt2870_io_mac_write_multi(sc
, RT2870_REG_WCID(wcid
),
2336 ni
->ni_macaddr
, IEEE80211_ADDR_LEN
);
2338 rt2870_amrr_node_init(&rvap
->amrr
, &sc
->amrr_node
[wcid
], ni
);
2340 RT2870_DPRINTF(sc
, RT2870_DEBUG_RATE
,
2341 "%s: initial%s node Tx rate: associd=0x%04x, rate=0x%02x, max rate=0x%02x\n",
2342 device_get_nameunit(sc
->dev
),
2343 (ni
->ni_flags
& IEEE80211_NODE_HT
) ? " HT" : "",
2344 ni
->ni_associd
, ni
->ni_txrate
,
2345 (ni
->ni_flags
& IEEE80211_NODE_HT
) ?
2346 (ni
->ni_htrates
.rs_rates
[ni
->ni_htrates
.rs_nrates
- 1] | IEEE80211_RATE_MCS
) :
2347 (ni
->ni_rates
.rs_rates
[ni
->ni_rates
.rs_nrates
- 1] & IEEE80211_RATE_VAL
));
2349 rt2870_asic_updateprot(sc
);
2350 rt2870_asic_updateslot(sc
);
2351 rt2870_asic_set_txpreamble(sc
);
2353 RT2870_SOFTC_UNLOCK(sc
);
2359 static void rt2870_updateslot(struct ifnet
*ifp
)
2361 struct rt2870_softc
*sc
;
2365 rt2870_do_async(sc
, rt2870_updateslot_cb
, NULL
, 0);
2369 * rt2870_update_promisc
2371 static void rt2870_update_promisc(struct ifnet
*ifp
)
2373 struct rt2870_softc
*sc
;
2377 RT2870_SOFTC_LOCK(sc
);
2379 rt2870_asic_update_promisc(sc
);
2381 RT2870_SOFTC_UNLOCK(sc
);
2385 * rt2870_update_mcast
2387 static void rt2870_update_mcast(struct ifnet
*ifp
)
2389 struct rt2870_softc
*sc
;
2397 static int rt2870_wme_update(struct ieee80211com
*ic
)
2399 struct rt2870_softc
*sc
;
2405 rt2870_do_async(sc
, rt2870_wme_update_cb
, NULL
, 0);
2413 static int rt2870_raw_xmit(struct ieee80211_node
*ni
, struct mbuf
*m
,
2414 const struct ieee80211_bpf_params
*params
)
2416 struct rt2870_softc
*sc
;
2417 struct ieee80211com
*ic
;
2424 RT2870_SOFTC_LOCK(sc
);
2426 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
2428 RT2870_SOFTC_UNLOCK(sc
);
2431 ieee80211_free_node(ni
);
2436 if (sc
->tx_ring
[sc
->tx_ring_mgtqid
].queued
>= RT2870_SOFTC_TX_RING_DATA_COUNT
)
2438 RT2870_DPRINTF(sc
, RT2870_DEBUG_TX
,
2439 "%s: raw xmit: Tx ring with qid=%d is full\n",
2440 device_get_nameunit(sc
->dev
), sc
->tx_ring_mgtqid
);
2442 ifp
->if_drv_flags
|= IFF_DRV_OACTIVE
;
2444 RT2870_SOFTC_UNLOCK(sc
);
2447 ieee80211_free_node(ni
);
2449 sc
->tx_data_queue_full
[sc
->tx_ring_mgtqid
]++;
2454 if (rt2870_tx_mgmt(sc
, m
, ni
, sc
->tx_ring_mgtqid
) != 0)
2458 RT2870_SOFTC_UNLOCK(sc
);
2460 ieee80211_free_node(ni
);
2465 sc
->tx_timer
= RT2870_TX_WATCHDOG_TIMEOUT
;
2467 RT2870_SOFTC_UNLOCK(sc
);
2473 * rt2870_recv_action
2475 static int rt2870_recv_action(struct ieee80211_node
*ni
,
2476 const struct ieee80211_frame
*wh
,
2477 const uint8_t *frm
, const uint8_t *efrm
)
2479 struct rt2870_softc
*sc
;
2480 struct ieee80211com
*ic
;
2482 const struct ieee80211_action
*ia
;
2483 uint16_t associd
, status
, baparamset
;
2485 int ret
, tid
, bufsize
;
2492 ia
= (const struct ieee80211_action
*) frm
;
2494 ret
= sc
->recv_action(ni
, wh
, frm
, efrm
);
2496 if (ia
->ia_category
!= IEEE80211_ACTION_CAT_BA
)
2499 associd
= (ni
!= NULL
) ? ni
->ni_associd
: 0;
2500 wcid
= RT2870_AID2WCID(associd
);
2502 switch (ia
->ia_action
)
2504 /* IEEE80211_ACTION_BA_ADDBA_REQUEST */
2505 case IEEE80211_ACTION_BA_ADDBA_REQUEST
:
2506 baparamset
= LE_READ_2(frm
+ 3);
2507 tid
= RT2870_MS(baparamset
, IEEE80211_BAPS_TID
);
2508 bufsize
= RT2870_MS(baparamset
, IEEE80211_BAPS_BUFSIZ
);
2510 RT2870_DPRINTF(sc
, RT2870_DEBUG_BA
,
2511 "%s: received ADDBA request: associd=0x%04x, tid=%d, bufsize=%d\n",
2512 device_get_nameunit(sc
->dev
), associd
, tid
, bufsize
);
2514 RT2870_SOFTC_LOCK(sc
);
2516 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_WCID(wcid
) + 4);
2518 tmp
|= (0x10000 << tid
);
2520 rt2870_io_mac_write(sc
, RT2870_REG_WCID(wcid
) + 4, tmp
);
2522 RT2870_SOFTC_UNLOCK(sc
);
2525 /* IEEE80211_ACTION_BA_ADDBA_RESPONSE */
2526 case IEEE80211_ACTION_BA_ADDBA_RESPONSE
:
2527 status
= LE_READ_2(frm
+ 3);
2528 baparamset
= LE_READ_2(frm
+ 4);
2529 tid
= RT2870_MS(baparamset
, IEEE80211_BAPS_TID
);
2530 bufsize
= RT2870_MS(baparamset
, IEEE80211_BAPS_BUFSIZ
);
2532 RT2870_DPRINTF(sc
, RT2870_DEBUG_BA
,
2533 "%s: received ADDBA response: associd=0x%04x, status=%d, tid=%d, bufsize=%d\n",
2534 device_get_nameunit(sc
->dev
), associd
, status
, tid
, bufsize
);
2536 if (status
== IEEE80211_STATUS_SUCCESS
)
2538 sc
->tx_ampdu_sessions
++;
2540 RT2870_SOFTC_LOCK(sc
);
2542 rt2870_asic_updateprot(sc
);
2544 RT2870_SOFTC_UNLOCK(sc
);
2548 /* IEEE80211_ACTION_BA_DELBA */
2549 case IEEE80211_ACTION_BA_DELBA
:
2550 baparamset
= LE_READ_2(frm
+ 2);
2551 tid
= RT2870_MS(baparamset
, IEEE80211_BAPS_TID
);
2553 RT2870_DPRINTF(sc
, RT2870_DEBUG_BA
,
2554 "%s: received DELBA request: associd=0x%04x, tid=%d\n",
2555 device_get_nameunit(sc
->dev
), associd
, tid
);
2557 RT2870_SOFTC_LOCK(sc
);
2559 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_WCID(wcid
) + 4);
2561 tmp
&= ~(0x10000 << tid
);
2563 rt2870_io_mac_write(sc
, RT2870_REG_WCID(wcid
) + 4, tmp
);
2565 RT2870_SOFTC_UNLOCK(sc
);
2573 * rt2870_send_action
2575 static int rt2870_send_action(struct ieee80211_node
*ni
,
2576 int cat
, int act
, void *sa
)
2578 struct rt2870_softc
*sc
;
2579 struct ieee80211com
*ic
;
2581 uint16_t associd
, *args
, baparamset
;
2590 ret
= sc
->send_action(ni
, cat
, act
, sa
);
2592 if (cat
!= IEEE80211_ACTION_CAT_BA
)
2595 associd
= (ni
!= NULL
) ? ni
->ni_associd
: 0;
2596 wcid
= RT2870_AID2WCID(associd
);
2601 /* IEEE80211_ACTION_BA_DELBA */
2602 case IEEE80211_ACTION_BA_DELBA
:
2603 baparamset
= RT2870_SM(args
[0], IEEE80211_DELBAPS_TID
) | args
[1];
2605 tid
= RT2870_MS(baparamset
, IEEE80211_DELBAPS_TID
);
2607 RT2870_DPRINTF(sc
, RT2870_DEBUG_BA
,
2608 "%s: sending DELBA request: associd=0x%04x, tid=%d\n",
2609 device_get_nameunit(sc
->dev
), associd
, tid
);
2611 RT2870_SOFTC_LOCK(sc
);
2613 if (RT2870_MS(baparamset
, IEEE80211_DELBAPS_INIT
) != IEEE80211_DELBAPS_INIT
)
2615 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_WCID(wcid
) + 4);
2617 tmp
&= ~(0x10000 << tid
);
2619 rt2870_io_mac_write(sc
, RT2870_REG_WCID(wcid
) + 4, tmp
);
2623 sc
->tx_ampdu_sessions
--;
2625 rt2870_asic_updateprot(sc
);
2628 RT2870_SOFTC_UNLOCK(sc
);
2636 * rt2870_amrr_update_iter_func
2638 static void rt2870_amrr_update_iter_func(void *arg
, struct ieee80211_node
*ni
)
2640 struct rt2870_softc
*sc
;
2641 struct ieee80211com
*ic
;
2643 struct ieee80211vap
*vap
;
2644 struct rt2870_softc_vap
*rvap
;
2651 rvap
= (struct rt2870_softc_vap
*) vap
;
2653 /* only associated stations */
2655 if ((ni
->ni_vap
== vap
) && (ni
->ni_associd
!= 0))
2657 wcid
= RT2870_AID2WCID(ni
->ni_associd
);
2659 RT2870_DPRINTF(sc
, RT2870_DEBUG_RATE
,
2660 "%s: AMRR node: wcid=0x%02x, txcnt=%d, success=%d, retrycnt=%d\n",
2661 device_get_nameunit(sc
->dev
),
2662 wcid
, sc
->amrr_node
[wcid
].txcnt
, sc
->amrr_node
[wcid
].success
, sc
->amrr_node
[wcid
].retrycnt
);
2664 rt2870_amrr_choose(ni
, &sc
->amrr_node
[wcid
]);
2666 RT2870_DPRINTF(sc
, RT2870_DEBUG_RATE
,
2667 "%s:%s node Tx rate: associd=0x%04x, rate=0x%02x, max rate=0x%02x\n",
2668 device_get_nameunit(sc
->dev
),
2669 (ni
->ni_flags
& IEEE80211_NODE_HT
) ? " HT" : "",
2670 ni
->ni_associd
, ni
->ni_txrate
,
2671 (ni
->ni_flags
& IEEE80211_NODE_HT
) ?
2672 (ni
->ni_htrates
.rs_rates
[ni
->ni_htrates
.rs_nrates
- 1] | IEEE80211_RATE_MCS
) :
2673 (ni
->ni_rates
.rs_rates
[ni
->ni_rates
.rs_nrates
- 1] & IEEE80211_RATE_VAL
));
2680 static void rt2870_periodic(void *arg
)
2682 struct rt2870_softc
*sc
;
2688 RT2870_DPRINTF(sc
, RT2870_DEBUG_PERIODIC
,
2690 device_get_nameunit(sc
->dev
));
2692 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
2695 taskqueue_enqueue(sc
->taskqueue
, &sc
->periodic_task
);
2699 * rt2870_tx_watchdog
2701 static void rt2870_tx_watchdog(void *arg
)
2703 struct rt2870_softc
*sc
;
2709 if (sc
->tx_timer
== 0)
2712 if (--sc
->tx_timer
== 0)
2714 printf("%s: Tx watchdog timeout: resetting\n",
2715 device_get_nameunit(sc
->dev
));
2717 rt2870_stop_locked(sc
);
2718 rt2870_init_locked(sc
);
2722 sc
->tx_watchdog_timeouts
++;
2725 callout_reset(&sc
->tx_watchdog_ch
, hz
, rt2870_tx_watchdog
, sc
);
2731 static int rt2870_do_async(struct rt2870_softc
*sc
,
2732 void (*cb
)(struct rt2870_softc
*sc
, void *arg
),
2736 struct rt2870_softc_cmd_ring
*ring
;
2737 struct rt2870_softc_cmd
*cmd
;
2741 ring
= &sc
->cmd_ring
;
2743 RT2870_SOFTC_LOCK(sc
);
2745 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
2747 RT2870_SOFTC_UNLOCK(sc
);
2751 if (ring
->queued
>= RT2870_SOFTC_CMD_RING_CMD_COUNT
)
2753 RT2870_SOFTC_UNLOCK(sc
);
2757 cmd
= STAILQ_FIRST(&ring
->inactive
);
2758 STAILQ_REMOVE_HEAD(&ring
->inactive
, next
);
2763 memcpy(cmd
->data
, arg
, len
);
2765 STAILQ_INSERT_TAIL(&ring
->active
, cmd
, next
);
2768 run_cmd_task
= (ring
->queued
== 1);
2770 RT2870_SOFTC_UNLOCK(sc
);
2773 taskqueue_enqueue(sc
->taskqueue
, &sc
->cmd_task
);
2779 * rt2870_updateslot_cb
2781 static void rt2870_updateslot_cb(struct rt2870_softc
*sc
, void *arg
)
2783 RT2870_SOFTC_LOCK(sc
);
2785 rt2870_asic_updateslot(sc
);
2787 RT2870_SOFTC_UNLOCK(sc
);
2791 * rt2870_wme_update_cb
2793 static void rt2870_wme_update_cb(struct rt2870_softc
*sc
, void *arg
)
2795 RT2870_SOFTC_LOCK(sc
);
2797 rt2870_asic_wme_update(sc
);
2799 RT2870_SOFTC_UNLOCK(sc
);
2803 * rt2870_vap_key_delete_cb
2805 static void rt2870_vap_key_delete_cb(struct rt2870_softc
*sc
, void *arg
)
2807 struct ieee80211_key
*k
;
2808 struct rt2870_cmd_argv_keydelete
*cmd_argv
;
2810 uint8_t vapid
, wcid
;
2815 associd
= cmd_argv
->associd
;
2817 RT2870_SOFTC_LOCK(sc
);
2819 if (!(k
->wk_flags
& IEEE80211_KEY_GROUP
))
2821 /* remove pairwise key */
2824 wcid
= RT2870_AID2WCID(associd
);
2826 tmp
= ((vapid
& RT2870_REG_VAP_MASK
) << RT2870_REG_VAP_SHIFT
) |
2827 (RT2870_REG_CIPHER_MODE_NONE
<< RT2870_REG_CIPHER_MODE_SHIFT
) | RT2870_REG_PKEY_ENABLE
;
2829 rt2870_io_mac_write(sc
, RT2870_REG_WCID_ATTR(wcid
), tmp
);
2833 /* remove group key */
2837 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_SKEY_MODE(vapid
));
2839 tmp
&= ~(0xf << (k
->wk_keyix
* 4 + 16 * (vapid
% 2)));
2840 tmp
|= (RT2870_REG_CIPHER_MODE_NONE
<< (k
->wk_keyix
* 4 + 16 * (vapid
% 2)));
2842 rt2870_io_mac_write(sc
, RT2870_REG_SKEY_MODE(vapid
), tmp
);
2845 RT2870_SOFTC_UNLOCK(sc
);
2849 * rt2870_vap_update_beacon_cb
2851 static void rt2870_vap_update_beacon_cb(struct rt2870_softc
*sc
, void *arg
)
2854 struct ieee80211com
*ic
;
2855 struct ieee80211vap
*vap
;
2859 vap
= TAILQ_FIRST(&ic
->ic_vaps
);
2864 RT2870_SOFTC_LOCK(sc
);
2866 rt2870_asic_update_beacon(sc
, vap
);
2868 RT2870_SOFTC_UNLOCK(sc
);
2872 * rt2870_asic_set_bssid
2874 static void rt2870_asic_set_bssid(struct rt2870_softc
*sc
,
2875 const uint8_t *bssid
)
2879 RT2870_DPRINTF(sc
, RT2870_DEBUG_STATE
,
2880 "%s: set bssid: bssid=%s\n",
2881 device_get_nameunit(sc
->dev
),
2882 ether_sprintf(bssid
));
2884 tmp
= bssid
[0] | (bssid
[1]) << 8 | (bssid
[2] << 16) | (bssid
[3] << 24);
2886 rt2870_io_mac_write(sc
, RT2870_REG_BSSID_DW0
, tmp
);
2888 tmp
= bssid
[4] | (bssid
[5] << 8);
2890 rt2870_io_mac_write(sc
, RT2870_REG_BSSID_DW1
, tmp
);
2894 * rt2870_asic_set_macaddr
2896 static void rt2870_asic_set_macaddr(struct rt2870_softc
*sc
,
2897 const uint8_t *addr
)
2901 tmp
= addr
[0] | (addr
[1] << 8) | (addr
[2] << 16) | (addr
[3] << 24);
2903 rt2870_io_mac_write(sc
, RT2870_REG_ADDR_DW0
, tmp
);
2905 tmp
= addr
[4] | (addr
[5] << 8);
2907 rt2870_io_mac_write(sc
, RT2870_REG_ADDR_DW1
, tmp
);
2911 * rt2870_asic_enable_tsf_sync
2913 static void rt2870_asic_enable_tsf_sync(struct rt2870_softc
*sc
)
2916 struct ieee80211com
*ic
;
2917 struct ieee80211vap
*vap
;
2922 vap
= TAILQ_FIRST(&ic
->ic_vaps
);
2924 RT2870_DPRINTF(sc
, RT2870_DEBUG_BEACON
,
2925 "%s: enabling TSF\n",
2926 device_get_nameunit(sc
->dev
));
2928 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_BCN_TIME_CFG
);
2931 tmp
|= vap
->iv_bss
->ni_intval
* 16;
2932 tmp
|= (RT2870_REG_TSF_TIMER_ENABLE
| RT2870_REG_TBTT_TIMER_ENABLE
);
2934 if (vap
->iv_opmode
== IEEE80211_M_STA
)
2936 tmp
|= (RT2870_REG_TSF_SYNC_MODE_STA
<< RT2870_REG_TSF_SYNC_MODE_SHIFT
);
2938 else if (vap
->iv_opmode
== IEEE80211_M_IBSS
)
2940 tmp
|= RT2870_REG_BCN_TX_ENABLE
;
2941 tmp
|= (RT2870_REG_TSF_SYNC_MODE_IBSS
<< RT2870_REG_TSF_SYNC_MODE_SHIFT
);
2943 else if (vap
->iv_opmode
== IEEE80211_M_HOSTAP
)
2945 tmp
|= RT2870_REG_BCN_TX_ENABLE
;
2946 tmp
|= (RT2870_REG_TSF_SYNC_MODE_HOSTAP
<< RT2870_REG_TSF_SYNC_MODE_SHIFT
);
2949 rt2870_io_mac_write(sc
, RT2870_REG_BCN_TIME_CFG
, tmp
);
2953 * rt2870_asic_disable_tsf_sync
2955 static void rt2870_asic_disable_tsf_sync(struct rt2870_softc
*sc
)
2959 RT2870_DPRINTF(sc
, RT2870_DEBUG_BEACON
,
2960 "%s: disabling TSF\n",
2961 device_get_nameunit(sc
->dev
));
2963 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_BCN_TIME_CFG
);
2965 tmp
&= ~(RT2870_REG_BCN_TX_ENABLE
|
2966 RT2870_REG_TSF_TIMER_ENABLE
|
2967 RT2870_REG_TBTT_TIMER_ENABLE
);
2969 tmp
&= ~(RT2870_REG_TSF_SYNC_MODE_MASK
<< RT2870_REG_TSF_SYNC_MODE_SHIFT
);
2970 tmp
|= (RT2870_REG_TSF_SYNC_MODE_DISABLE
<< RT2870_REG_TSF_SYNC_MODE_SHIFT
);
2972 rt2870_io_mac_write(sc
, RT2870_REG_BCN_TIME_CFG
, tmp
);
2976 * rt2870_asic_enable_mrr
2978 static void rt2870_asic_enable_mrr(struct rt2870_softc
*sc
)
2980 #define CCK(mcs) (mcs)
2981 #define OFDM(mcs) ((1 << 3) | (mcs))
2982 #define HT(mcs) (mcs)
2984 rt2870_io_mac_write(sc
, RT2870_REG_TX_LG_FBK_CFG0
,
2985 (OFDM(6) << 28) | /* 54 -> 48 */
2986 (OFDM(5) << 24) | /* 48 -> 36 */
2987 (OFDM(4) << 20) | /* 36 -> 24 */
2988 (OFDM(3) << 16) | /* 24 -> 18 */
2989 (OFDM(2) << 12) | /* 18 -> 12 */
2990 (OFDM(1) << 8) | /* 12 -> 9 */
2991 (OFDM(0) << 4) | /* 9 -> 6 */
2992 OFDM(0)); /* 6 -> 6 */
2994 rt2870_io_mac_write(sc
, RT2870_REG_TX_LG_FBK_CFG1
,
2995 (CCK(2) << 12) | /* 11 -> 5.5 */
2996 (CCK(1) << 8) | /* 5.5 -> 2 */
2997 (CCK(0) << 4) | /* 2 -> 1 */
2998 CCK(0)); /* 1 -> 1 */
3000 rt2870_io_mac_write(sc
, RT2870_REG_TX_HT_FBK_CFG0
,
3010 rt2870_io_mac_write(sc
, RT2870_REG_TX_HT_FBK_CFG1
,
3026 * rt2870_asic_set_txpreamble
3028 static void rt2870_asic_set_txpreamble(struct rt2870_softc
*sc
)
3031 struct ieee80211com
*ic
;
3037 RT2870_DPRINTF(sc
, RT2870_DEBUG_STATE
,
3038 "%s: %s short Tx preamble\n",
3039 device_get_nameunit(sc
->dev
),
3040 (ic
->ic_flags
& IEEE80211_F_SHPREAMBLE
) ? "enabling" : "disabling");
3042 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_AUTO_RSP_CFG
);
3044 tmp
&= ~RT2870_REG_CCK_SHORT_ENABLE
;
3046 if (ic
->ic_flags
& IEEE80211_F_SHPREAMBLE
)
3047 tmp
|= RT2870_REG_CCK_SHORT_ENABLE
;
3049 rt2870_io_mac_write(sc
, RT2870_REG_AUTO_RSP_CFG
, tmp
);
3053 * rt2870_asic_set_basicrates
3055 static void rt2870_asic_set_basicrates(struct rt2870_softc
*sc
)
3058 struct ieee80211com
*ic
;
3063 if (ic
->ic_curmode
== IEEE80211_MODE_11B
)
3064 rt2870_io_mac_write(sc
, RT2870_REG_LEGACY_BASIC_RATE
, 0x3);
3065 else if (ic
->ic_curmode
== IEEE80211_MODE_11A
)
3066 rt2870_io_mac_write(sc
, RT2870_REG_LEGACY_BASIC_RATE
, 0x150);
3068 rt2870_io_mac_write(sc
, RT2870_REG_LEGACY_BASIC_RATE
, 0x15f);
3072 * rt2870_asic_update_rtsthreshold
3074 static void rt2870_asic_update_rtsthreshold(struct rt2870_softc
*sc
)
3077 struct ieee80211com
*ic
;
3078 struct ieee80211vap
*vap
;
3084 vap
= TAILQ_FIRST(&ic
->ic_vaps
);
3086 RT2870_DPRINTF(sc
, RT2870_DEBUG_PROT
,
3087 "%s: updating RTS threshold: %d\n",
3088 device_get_nameunit(sc
->dev
), vap
->iv_rtsthreshold
);
3090 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_TX_RTS_CFG
);
3092 tmp
&= ~(RT2870_REG_TX_RTS_THRESHOLD_MASK
<< RT2870_REG_TX_RTS_THRESHOLD_SHIFT
);
3094 threshold
= (vap
->iv_rtsthreshold
< IEEE80211_RTS_MAX
) ?
3095 vap
->iv_rtsthreshold
: 0x1000;
3097 tmp
|= ((threshold
& RT2870_REG_TX_RTS_THRESHOLD_MASK
) <<
3098 RT2870_REG_TX_RTS_THRESHOLD_SHIFT
);
3100 rt2870_io_mac_write(sc
, RT2870_REG_TX_RTS_CFG
, tmp
);
3104 * rt2870_asic_update_txpower
3106 static void rt2870_asic_update_txpower(struct rt2870_softc
*sc
)
3109 struct ieee80211com
*ic
;
3110 uint32_t *txpow_rate
;
3119 RT2870_DPRINTF(sc
, RT2870_DEBUG_STATE
,
3120 "%s: updating Tx power: %d\n",
3121 device_get_nameunit(sc
->dev
), ic
->ic_txpowlimit
);
3123 if (!IEEE80211_IS_CHAN_HT40(ic
->ic_curchan
))
3125 txpow_rate
= sc
->txpow_rate_20mhz
;
3129 if (IEEE80211_IS_CHAN_2GHZ(ic
->ic_curchan
))
3130 txpow_rate
= sc
->txpow_rate_40mhz_2ghz
;
3132 txpow_rate
= sc
->txpow_rate_40mhz_5ghz
;
3137 val
= rt2870_io_bbp_read(sc
, 1);
3140 if (ic
->ic_txpowlimit
> 90)
3144 else if (ic
->ic_txpowlimit
> 60)
3148 else if (ic
->ic_txpowlimit
> 30)
3152 else if (ic
->ic_txpowlimit
> 15)
3156 else if (ic
->ic_txpowlimit
> 9)
3166 rt2870_io_bbp_write(sc
, 1, val
);
3168 for (i
= 0; i
< RT2870_SOFTC_TXPOW_RATE_COUNT
; i
++)
3170 if (txpow_rate
[i
] == 0xffffffff)
3173 tmp
= rt2870_read_eeprom_txpow_rate_add_delta(txpow_rate
[i
], delta
);
3175 rt2870_io_mac_write(sc
, RT2870_REG_TX_PWR_CFG(i
), tmp
);
3180 * rt2870_asic_update_promisc
3182 static void rt2870_asic_update_promisc(struct rt2870_softc
*sc
)
3189 printf("%s: %s promiscuous mode\n",
3190 device_get_nameunit(sc
->dev
),
3191 (ifp
->if_flags
& IFF_PROMISC
) ? "entering" : "leaving");
3193 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_RX_FILTER_CFG
);
3195 tmp
&= ~RT2870_REG_RX_FILTER_DROP_UC_NOME
;
3197 if (!(ifp
->if_flags
& IFF_PROMISC
))
3198 tmp
|= RT2870_REG_RX_FILTER_DROP_UC_NOME
;
3200 rt2870_io_mac_write(sc
, RT2870_REG_RX_FILTER_CFG
, tmp
);
3204 * rt2870_asic_updateprot
3206 static void rt2870_asic_updateprot(struct rt2870_softc
*sc
)
3209 struct ieee80211com
*ic
;
3210 struct ieee80211vap
*vap
;
3211 uint32_t cck_prot
, ofdm_prot
, mm20_prot
, mm40_prot
, gf20_prot
, gf40_prot
;
3213 enum ieee80211_protmode htprotmode
;
3217 vap
= TAILQ_FIRST(&ic
->ic_vaps
);
3219 /* CCK frame protection */
3221 cck_prot
= RT2870_REG_RTSTH_ENABLE
| RT2870_REG_PROT_NAV_SHORT
|
3222 RT2870_REG_TXOP_ALLOW_ALL
| RT2870_REG_PROT_CTRL_NONE
;
3224 /* set up protection frame phy mode and rate (MCS code) */
3226 if (ic
->ic_curmode
== IEEE80211_MODE_11A
)
3227 cck_prot
|= (RT2870_REG_PROT_PHYMODE_OFDM
<< RT2870_REG_PROT_PHYMODE_SHIFT
) |
3228 (0 << RT2870_REG_PROT_MCS_SHIFT
);
3230 cck_prot
|= ((RT2870_REG_PROT_PHYMODE_CCK
<< RT2870_REG_PROT_PHYMODE_SHIFT
) |
3231 (3 << RT2870_REG_PROT_MCS_SHIFT
));
3233 rt2870_io_mac_write(sc
, RT2870_REG_TX_CCK_PROT_CFG
, cck_prot
);
3235 /* OFDM frame protection */
3237 ofdm_prot
= RT2870_REG_RTSTH_ENABLE
| RT2870_REG_PROT_NAV_SHORT
|
3238 RT2870_REG_TXOP_ALLOW_ALL
;
3240 if (ic
->ic_flags
& IEEE80211_F_USEPROT
)
3242 RT2870_DPRINTF(sc
, RT2870_DEBUG_PROT
,
3243 "%s: updating protection mode: b/g protection mode=%s\n",
3244 device_get_nameunit(sc
->dev
),
3245 (ic
->ic_protmode
== IEEE80211_PROT_RTSCTS
) ? "RTS/CTS" :
3246 ((ic
->ic_protmode
== IEEE80211_PROT_CTSONLY
) ? "CTS-to-self" : "none"));
3248 if (ic
->ic_protmode
== IEEE80211_PROT_RTSCTS
)
3249 ofdm_prot
|= RT2870_REG_PROT_CTRL_RTS_CTS
;
3250 else if (ic
->ic_protmode
== IEEE80211_PROT_CTSONLY
)
3251 ofdm_prot
|= RT2870_REG_PROT_CTRL_CTS
;
3253 ofdm_prot
|= RT2870_REG_PROT_CTRL_NONE
;
3257 RT2870_DPRINTF(sc
, RT2870_DEBUG_PROT
,
3258 "%s: updating protection mode: b/g protection mode=%s\n",
3259 device_get_nameunit(sc
->dev
), "none");
3261 ofdm_prot
|= RT2870_REG_PROT_CTRL_NONE
;
3264 rt2870_io_mac_write(sc
, RT2870_REG_TX_OFDM_PROT_CFG
, ofdm_prot
);
3266 /* HT frame protection */
3268 if ((vap
->iv_opmode
== IEEE80211_M_STA
) && (vap
->iv_state
== IEEE80211_S_RUN
))
3269 htopmode
= vap
->iv_bss
->ni_htopmode
;
3271 htopmode
= ic
->ic_curhtprotmode
;
3273 htprotmode
= ic
->ic_htprotmode
;
3275 /* force HT mixed mode and RTS/CTS protection if A-MPDU Tx aggregation is enabled */
3277 if (sc
->tx_ampdu_sessions
> 0)
3279 RT2870_DPRINTF(sc
, RT2870_DEBUG_PROT
,
3280 "%s: updating protection mode: forcing HT mixed mode and RTS/CTS protection\n",
3281 device_get_nameunit(sc
->dev
));
3283 htopmode
= IEEE80211_HTINFO_OPMODE_MIXED
;
3284 htprotmode
= IEEE80211_PROT_RTSCTS
;
3287 RT2870_DPRINTF(sc
, RT2870_DEBUG_PROT
,
3288 "%s: updating protection mode: HT operation mode=0x%02x, protection mode=%s\n",
3289 device_get_nameunit(sc
->dev
),
3290 htopmode
& IEEE80211_HTINFO_OPMODE
,
3291 (htprotmode
== IEEE80211_PROT_RTSCTS
) ? "RTS/CTS" :
3292 ((htprotmode
== IEEE80211_PROT_CTSONLY
) ? "CTS-to-self" : "none"));
3294 switch (htopmode
& IEEE80211_HTINFO_OPMODE
)
3296 /* IEEE80211_HTINFO_OPMODE_HT20PR */
3297 case IEEE80211_HTINFO_OPMODE_HT20PR
:
3298 mm20_prot
= RT2870_REG_PROT_NAV_SHORT
| RT2870_REG_PROT_CTRL_NONE
|
3299 RT2870_REG_TXOP_ALLOW_CCK
| RT2870_REG_TXOP_ALLOW_OFDM
|
3300 RT2870_REG_TXOP_ALLOW_MM20
| RT2870_REG_TXOP_ALLOW_GF20
|
3301 (RT2870_REG_PROT_PHYMODE_OFDM
<< RT2870_REG_PROT_PHYMODE_SHIFT
) |
3302 (4 << RT2870_REG_PROT_MCS_SHIFT
);
3304 gf20_prot
= mm20_prot
;
3306 mm40_prot
= RT2870_REG_PROT_NAV_SHORT
| RT2870_REG_PROT_CTRL_NONE
|
3307 RT2870_REG_TXOP_ALLOW_ALL
|
3308 (RT2870_REG_PROT_PHYMODE_OFDM
<< RT2870_REG_PROT_PHYMODE_SHIFT
) |
3309 (0x84 << RT2870_REG_PROT_MCS_SHIFT
);
3311 if (htprotmode
== IEEE80211_PROT_RTSCTS
)
3312 mm40_prot
|= RT2870_REG_PROT_CTRL_RTS_CTS
;
3313 else if (htprotmode
== IEEE80211_PROT_CTSONLY
)
3314 mm40_prot
|= RT2870_REG_PROT_CTRL_CTS
;
3316 mm40_prot
|= RT2870_REG_PROT_CTRL_NONE
;
3318 gf40_prot
= mm40_prot
;
3321 /* IEEE80211_HTINFO_OPMODE_MIXED */
3322 case IEEE80211_HTINFO_OPMODE_MIXED
:
3323 mm20_prot
= RT2870_REG_PROT_NAV_SHORT
|
3324 RT2870_REG_TXOP_ALLOW_CCK
| RT2870_REG_TXOP_ALLOW_OFDM
|
3325 RT2870_REG_TXOP_ALLOW_MM20
| RT2870_REG_TXOP_ALLOW_GF20
;
3327 if (ic
->ic_flags
& IEEE80211_F_USEPROT
)
3328 mm20_prot
|= (RT2870_REG_PROT_PHYMODE_CCK
<< RT2870_REG_PROT_PHYMODE_SHIFT
) |
3329 (3 << RT2870_REG_PROT_MCS_SHIFT
);
3331 mm20_prot
|= (RT2870_REG_PROT_PHYMODE_OFDM
<< RT2870_REG_PROT_PHYMODE_SHIFT
) |
3332 (4 << RT2870_REG_PROT_MCS_SHIFT
);
3334 if (htprotmode
== IEEE80211_PROT_RTSCTS
)
3335 mm20_prot
|= RT2870_REG_PROT_CTRL_RTS_CTS
;
3336 else if (htprotmode
== IEEE80211_PROT_CTSONLY
)
3337 mm20_prot
|= RT2870_REG_PROT_CTRL_CTS
;
3339 mm20_prot
|= RT2870_REG_PROT_CTRL_NONE
;
3341 gf20_prot
= mm20_prot
;
3343 mm40_prot
= RT2870_REG_PROT_NAV_SHORT
| RT2870_REG_TXOP_ALLOW_ALL
;
3345 if (ic
->ic_flags
& IEEE80211_F_USEPROT
)
3346 mm40_prot
|= (RT2870_REG_PROT_PHYMODE_CCK
<< RT2870_REG_PROT_PHYMODE_SHIFT
) |
3347 (3 << RT2870_REG_PROT_MCS_SHIFT
);
3349 mm40_prot
|= (RT2870_REG_PROT_PHYMODE_OFDM
<< RT2870_REG_PROT_PHYMODE_SHIFT
) |
3350 (0x84 << RT2870_REG_PROT_MCS_SHIFT
);
3352 if (htprotmode
== IEEE80211_PROT_RTSCTS
)
3353 mm40_prot
|= RT2870_REG_PROT_CTRL_RTS_CTS
;
3354 else if (htprotmode
== IEEE80211_PROT_CTSONLY
)
3355 mm40_prot
|= RT2870_REG_PROT_CTRL_CTS
;
3357 mm40_prot
|= RT2870_REG_PROT_CTRL_NONE
;
3359 gf40_prot
= mm40_prot
;
3363 * IEEE80211_HTINFO_OPMODE_PURE
3364 * IEEE80211_HTINFO_OPMODE_PROTOPT
3366 case IEEE80211_HTINFO_OPMODE_PURE
:
3367 case IEEE80211_HTINFO_OPMODE_PROTOPT
:
3369 mm20_prot
= RT2870_REG_PROT_NAV_SHORT
| RT2870_REG_PROT_CTRL_NONE
|
3370 RT2870_REG_TXOP_ALLOW_CCK
| RT2870_REG_TXOP_ALLOW_OFDM
|
3371 RT2870_REG_TXOP_ALLOW_MM20
| RT2870_REG_TXOP_ALLOW_GF20
|
3372 (RT2870_REG_PROT_PHYMODE_OFDM
<< RT2870_REG_PROT_PHYMODE_SHIFT
) |
3373 (4 << RT2870_REG_PROT_MCS_SHIFT
);
3375 gf20_prot
= mm20_prot
;
3377 mm40_prot
= RT2870_REG_PROT_NAV_SHORT
| RT2870_REG_PROT_CTRL_NONE
|
3378 RT2870_REG_TXOP_ALLOW_ALL
|
3379 (RT2870_REG_PROT_PHYMODE_OFDM
<< RT2870_REG_PROT_PHYMODE_SHIFT
) |
3380 (0x84 << RT2870_REG_PROT_MCS_SHIFT
);
3382 gf40_prot
= mm40_prot
;
3386 rt2870_io_mac_write(sc
, RT2870_REG_TX_MM20_PROT_CFG
, mm20_prot
);
3387 rt2870_io_mac_write(sc
, RT2870_REG_TX_MM40_PROT_CFG
, mm40_prot
);
3388 rt2870_io_mac_write(sc
, RT2870_REG_TX_GF20_PROT_CFG
, gf20_prot
);
3389 rt2870_io_mac_write(sc
, RT2870_REG_TX_GF40_PROT_CFG
, gf40_prot
);
3393 * rt2870_asic_updateslot
3395 static void rt2870_asic_updateslot(struct rt2870_softc
*sc
)
3398 struct ieee80211com
*ic
;
3404 RT2870_DPRINTF(sc
, RT2870_DEBUG_STATE
,
3405 "%s: %s short slot time\n",
3406 device_get_nameunit(sc
->dev
),
3407 (ic
->ic_flags
& IEEE80211_F_SHSLOT
) ? "enabling" : "disabling");
3409 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_BKOFF_SLOT_CFG
);
3412 tmp
|= (ic
->ic_flags
& IEEE80211_F_SHSLOT
) ? 9 : 20;
3414 rt2870_io_mac_write(sc
, RT2870_REG_BKOFF_SLOT_CFG
, tmp
);
3418 * rt2870_asic_wme_update
3420 static void rt2870_asic_wme_update(struct rt2870_softc
*sc
)
3423 struct ieee80211com
*ic
;
3424 struct ieee80211_wme_state
*wme
;
3425 const struct wmeParams
*wmep
;
3431 wmep
= wme
->wme_chanParams
.cap_wmeParams
;
3433 RT2870_DPRINTF(sc
, RT2870_DEBUG_WME
,
3434 "%s: wme update: WME_AC_VO=%d/%d/%d/%d, WME_AC_VI=%d/%d/%d/%d, "
3435 "WME_AC_BK=%d/%d/%d/%d, WME_AC_BE=%d/%d/%d/%d\n",
3436 device_get_nameunit(sc
->dev
),
3437 wmep
[WME_AC_VO
].wmep_aifsn
,
3438 wmep
[WME_AC_VO
].wmep_logcwmin
, wmep
[WME_AC_VO
].wmep_logcwmax
,
3439 wmep
[WME_AC_VO
].wmep_txopLimit
,
3440 wmep
[WME_AC_VI
].wmep_aifsn
,
3441 wmep
[WME_AC_VI
].wmep_logcwmin
, wmep
[WME_AC_VI
].wmep_logcwmax
,
3442 wmep
[WME_AC_VI
].wmep_txopLimit
,
3443 wmep
[WME_AC_BK
].wmep_aifsn
,
3444 wmep
[WME_AC_BK
].wmep_logcwmin
, wmep
[WME_AC_BK
].wmep_logcwmax
,
3445 wmep
[WME_AC_BK
].wmep_txopLimit
,
3446 wmep
[WME_AC_BE
].wmep_aifsn
,
3447 wmep
[WME_AC_BE
].wmep_logcwmin
, wmep
[WME_AC_BE
].wmep_logcwmax
,
3448 wmep
[WME_AC_BE
].wmep_txopLimit
);
3450 for (i
= 0; i
< WME_NUM_AC
; i
++)
3451 rt2870_io_mac_write(sc
, RT2870_REG_TX_EDCA_AC_CFG(i
),
3452 (wmep
[i
].wmep_logcwmax
<< 16) | (wmep
[i
].wmep_logcwmin
<< 12) |
3453 (wmep
[i
].wmep_aifsn
<< 8) | wmep
[i
].wmep_txopLimit
);
3455 rt2870_io_mac_write(sc
, RT2870_REG_SCHDMA_WMM_AIFSN_CFG
,
3456 (wmep
[WME_AC_VO
].wmep_aifsn
<< 12) | (wmep
[WME_AC_VI
].wmep_aifsn
<< 8) |
3457 (wmep
[WME_AC_BK
].wmep_aifsn
<< 4) | wmep
[WME_AC_BE
].wmep_aifsn
);
3459 rt2870_io_mac_write(sc
, RT2870_REG_SCHDMA_WMM_CWMIN_CFG
,
3460 (wmep
[WME_AC_VO
].wmep_logcwmin
<< 12) | (wmep
[WME_AC_VI
].wmep_logcwmin
<< 8) |
3461 (wmep
[WME_AC_BK
].wmep_logcwmin
<< 4) | wmep
[WME_AC_BE
].wmep_logcwmin
);
3463 rt2870_io_mac_write(sc
, RT2870_REG_SCHDMA_WMM_CWMAX_CFG
,
3464 (wmep
[WME_AC_VO
].wmep_logcwmax
<< 12) | (wmep
[WME_AC_VI
].wmep_logcwmax
<< 8) |
3465 (wmep
[WME_AC_BK
].wmep_logcwmax
<< 4) | wmep
[WME_AC_BE
].wmep_logcwmax
);
3467 rt2870_io_mac_write(sc
, RT2870_REG_SCHDMA_WMM_TXOP0_CFG
,
3468 (wmep
[WME_AC_BK
].wmep_txopLimit
<< 16) | wmep
[WME_AC_BE
].wmep_txopLimit
);
3470 rt2870_io_mac_write(sc
, RT2870_REG_SCHDMA_WMM_TXOP1_CFG
,
3471 (wmep
[WME_AC_VO
].wmep_txopLimit
<< 16) | wmep
[WME_AC_VI
].wmep_txopLimit
);
3475 * rt2870_asic_update_beacon
3477 static int rt2870_asic_update_beacon(struct rt2870_softc
*sc
,
3478 struct ieee80211vap
*vap
)
3481 struct ieee80211com
*ic
;
3482 struct rt2870_softc_vap
*rvap
;
3483 const struct ieee80211_txparam
*tp
;
3485 struct rt2870_txwi txwi
;
3491 rvap
= (struct rt2870_softc_vap
*) vap
;
3492 tp
= &vap
->iv_txparms
[ieee80211_chan2mode(ic
->ic_bsschan
)];
3494 m
= ieee80211_beacon_alloc(vap
->iv_bss
, &rvap
->beacon_offsets
);
3498 rate
= tp
->mgmtrate
;
3499 mcs
= rt2870_rate2mcs(rate
);
3501 memset(&txwi
, 0, sizeof(struct rt2870_txwi
));
3504 txwi
.pid_mpdu_len
= ((htole16(m
->m_pkthdr
.len
) & RT2870_TXWI_MPDU_LEN_MASK
) <<
3505 RT2870_TXWI_MPDU_LEN_SHIFT
);
3506 txwi
.txop
= (RT2870_TXWI_TXOP_HT
<< RT2870_TXWI_TXOP_SHIFT
);
3507 txwi
.mpdu_density_flags
|=
3508 (RT2870_TXWI_FLAGS_TS
<< RT2870_TXWI_FLAGS_SHIFT
);
3509 txwi
.bawin_size_xflags
|=
3510 (RT2870_TXWI_XFLAGS_NSEQ
<< RT2870_TXWI_XFLAGS_SHIFT
);
3512 if (ieee80211_rate2phytype(ic
->ic_rt
, rate
) != IEEE80211_T_OFDM
)
3514 txwi
.phymode_ifs_stbc_shortgi
=
3515 (RT2870_TXWI_PHYMODE_CCK
<< RT2870_TXWI_PHYMODE_SHIFT
);
3517 if (rate
!= 2 && (ic
->ic_flags
& IEEE80211_F_SHPREAMBLE
))
3518 mcs
|= RT2870_TXWI_MCS_SHOTPRE
;
3522 txwi
.phymode_ifs_stbc_shortgi
=
3523 (RT2870_TXWI_PHYMODE_OFDM
<< RT2870_TXWI_PHYMODE_SHIFT
);
3526 txwi
.bw_mcs
= (RT2870_TXWI_BW_20
<< RT2870_TXWI_BW_SHIFT
) |
3527 ((mcs
& RT2870_TXWI_MCS_MASK
) << RT2870_TXWI_MCS_SHIFT
);
3529 /* disable temporarily TSF sync */
3531 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_BCN_TIME_CFG
);
3533 tmp
&= ~(RT2870_REG_BCN_TX_ENABLE
|
3534 RT2870_REG_TSF_TIMER_ENABLE
|
3535 RT2870_REG_TBTT_TIMER_ENABLE
);
3537 rt2870_io_mac_write(sc
, RT2870_REG_BCN_TIME_CFG
, tmp
);
3539 /* write Tx wireless info and beacon frame to on-chip memory */
3541 rt2870_io_mac_write_multi(sc
, RT2870_REG_BEACON_BASE(0),
3542 &txwi
, sizeof(struct rt2870_txwi
));
3544 rt2870_io_mac_write_multi(sc
, RT2870_REG_BEACON_BASE(0) + sizeof(struct rt2870_txwi
),
3545 mtod(m
, uint8_t *), m
->m_pkthdr
.len
);
3547 /* enable again TSF sync */
3549 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_BCN_TIME_CFG
);
3551 tmp
|= (RT2870_REG_BCN_TX_ENABLE
|
3552 RT2870_REG_TSF_TIMER_ENABLE
|
3553 RT2870_REG_TBTT_TIMER_ENABLE
);
3555 rt2870_io_mac_write(sc
, RT2870_REG_BCN_TIME_CFG
, tmp
);
3563 * rt2870_asic_clear_keytables
3565 static void rt2870_asic_clear_keytables(struct rt2870_softc
*sc
)
3569 /* clear Rx WCID search table (entries = 256, entry size = 8) */
3571 for (i
= 0; i
< 256; i
++)
3573 rt2870_io_mac_write(sc
, RT2870_REG_WCID(i
), 0xffffffff);
3574 rt2870_io_mac_write(sc
, RT2870_REG_WCID(i
) + 4, 0x0000ffff);
3577 /* clear WCID attribute table (entries = 256, entry size = 4) */
3579 rt2870_io_mac_set_region_4(sc
, RT2870_REG_WCID_ATTR(0), 0, 256);
3581 /* clear IV/EIV table (entries = 256, entry size = 8) */
3583 rt2870_io_mac_set_region_4(sc
, RT2870_REG_IVEIV(0), 0, 2 * 256);
3585 /* clear pairwise key table (entries = 256, entry size = 32) */
3587 rt2870_io_mac_set_region_4(sc
, RT2870_REG_PKEY(0), 0, 8 * 256);
3589 /* clear shared key table (entries = 32, entry size = 32) */
3591 rt2870_io_mac_set_region_4(sc
, RT2870_REG_SKEY(0, 0), 0, 8 * 32);
3593 /* clear shared key mode (entries = 32, entry size = 2) */
3595 rt2870_io_mac_set_region_4(sc
, RT2870_REG_SKEY_MODE(0), 0, 16);
3601 static uint8_t rt2870_rxrate(struct rt2870_rxwi
*rxwi
)
3603 uint8_t mcs
, phymode
;
3606 mcs
= (rxwi
->bw_mcs
>> RT2870_RXWI_MCS_SHIFT
) & RT2870_RXWI_MCS_MASK
;
3607 phymode
= (rxwi
->phymode_stbc_shortgi
>> RT2870_RXWI_PHYMODE_SHIFT
) &
3608 RT2870_RXWI_PHYMODE_MASK
;
3614 case RT2870_RXWI_PHYMODE_CCK
:
3615 switch (mcs
& ~RT2870_RXWI_MCS_SHOTPRE
)
3617 case 0: rate
= 2; break; /* 1 Mbps */
3618 case 1: rate
= 4; break; /* 2 MBps */
3619 case 2: rate
= 11; break; /* 5.5 Mbps */
3620 case 3: rate
= 22; break; /* 11 Mbps */
3624 case RT2870_RXWI_PHYMODE_OFDM
:
3627 case 0: rate
= 12; break; /* 6 Mbps */
3628 case 1: rate
= 18; break; /* 9 Mbps */
3629 case 2: rate
= 24; break; /* 12 Mbps */
3630 case 3: rate
= 36; break; /* 18 Mbps */
3631 case 4: rate
= 48; break; /* 24 Mbps */
3632 case 5: rate
= 72; break; /* 36 Mbps */
3633 case 6: rate
= 96; break; /* 48 Mbps */
3634 case 7: rate
= 108; break; /* 54 Mbps */
3638 case RT2870_RXWI_PHYMODE_HT_MIXED
:
3639 case RT2870_RXWI_PHYMODE_HT_GF
:
3647 * rt2870_maxrssi_rxpath
3649 static uint8_t rt2870_maxrssi_rxpath(struct rt2870_softc
*sc
,
3650 const struct rt2870_rxwi
*rxwi
)
3656 if (sc
->nrxpath
> 1)
3657 if (rxwi
->rssi
[1] > rxwi
->rssi
[rxpath
])
3660 if (sc
->nrxpath
> 2)
3661 if (rxwi
->rssi
[2] > rxwi
->rssi
[rxpath
])
3670 static int8_t rt2870_rssi2dbm(struct rt2870_softc
*sc
,
3671 uint8_t rssi
, uint8_t rxpath
)
3674 struct ieee80211com
*ic
;
3675 struct ieee80211_channel
*c
;
3677 int8_t rssi_off
, lna_gain
;
3685 chan
= ieee80211_chan2ieee(ic
, c
);
3687 if (IEEE80211_IS_CHAN_5GHZ(c
))
3689 rssi_off
= sc
->rssi_off_5ghz
[rxpath
];
3692 lna_gain
= sc
->lna_gain
[1];
3693 else if (chan
<= 128)
3694 lna_gain
= sc
->lna_gain
[2];
3696 lna_gain
= sc
->lna_gain
[3];
3700 rssi_off
= sc
->rssi_off_2ghz
[rxpath
];
3701 lna_gain
= sc
->lna_gain
[0];
3704 return (-12 - rssi_off
- lna_gain
- rssi
);
3710 static uint8_t rt2870_rate2mcs(uint8_t rate
)
3737 static void rt2870_rx_frame(struct rt2870_softc
*sc
,
3738 uint8_t *buf
, uint32_t dmalen
)
3741 struct ieee80211com
*ic
;
3742 struct ieee80211_frame
*wh
;
3743 struct ieee80211_node
*ni
;
3744 struct rt2870_softc_rx_radiotap_header
*tap
;
3745 struct rt2870_rxwi
*rxwi
;
3746 struct rt2870_rxinfo
*rxinfo
;
3748 uint32_t rxinfo_flags
;
3749 uint8_t cipher_err
, rssi
, ant
, phymode
, bw
, shortgi
, mcs
;
3751 int len
, ampdu
, amsdu
, rssi_dbm_rel
;
3756 /* get Rx wireless info */
3758 rxwi
= (struct rt2870_rxwi
*) buf
;
3759 len
= (le16toh(rxwi
->tid_size
) >> RT2870_RXWI_SIZE_SHIFT
) &
3760 RT2870_RXWI_SIZE_MASK
;
3764 RT2870_DPRINTF(sc
, RT2870_DEBUG_RX
,
3765 "%s: bad rxwi len: DMA len=%d, rxwi len=%d\n",
3766 device_get_nameunit(sc
->dev
), dmalen
, len
);
3772 rxinfo
= (struct rt2870_rxinfo
*) ((caddr_t
) rxwi
+ dmalen
);
3773 rxinfo_flags
= le32toh(rxinfo
->flags
);
3775 RT2870_DPRINTF(sc
, RT2870_DEBUG_RX
,
3776 "%s: Rx frame: DMA len=%d, len=%d, rxinfo flags=0x%08x\n",
3777 device_get_nameunit(sc
->dev
), dmalen
, len
, rxinfo_flags
);
3779 /* check for crc errors */
3781 if (rxinfo_flags
& RT2870_RXINFO_FLAGS_CRC_ERR
)
3783 RT2870_DPRINTF(sc
, RT2870_DEBUG_RX
,
3784 "%s: rxinfo: crc error\n",
3785 device_get_nameunit(sc
->dev
));
3789 if (!(ifp
->if_flags
& IFF_PROMISC
))
3793 wh
= (struct ieee80211_frame
*) (rxwi
+ 1);
3795 /* check for L2 padding between IEEE 802.11 frame header and body */
3797 if (rxinfo_flags
& RT2870_RXINFO_FLAGS_L2PAD
)
3799 RT2870_DPRINTF(sc
, RT2870_DEBUG_RX
,
3800 "%s: L2 padding: DMA len=%d, len=%d\n",
3801 device_get_nameunit(sc
->dev
), dmalen
, len
);
3806 m
= m_getjcl(M_DONTWAIT
, MT_DATA
, M_PKTHDR
, MJUMPAGESIZE
);
3809 sc
->rx_mbuf_alloc_errors
++;
3814 m
->m_pkthdr
.rcvif
= ifp
;
3815 m
->m_pkthdr
.len
= m
->m_len
= len
;
3817 m_copyback(m
, 0, len
, (caddr_t
) wh
);
3819 wh
= mtod(m
, struct ieee80211_frame
*);
3821 /* check for cipher errors */
3823 if (rxinfo_flags
& RT2870_RXINFO_FLAGS_DECRYPTED
)
3825 cipher_err
= ((rxinfo_flags
>> RT2870_RXINFO_FLAGS_CIPHER_ERR_SHIFT
) &
3826 RT2870_RXINFO_FLAGS_CIPHER_ERR_MASK
);
3827 if (cipher_err
== RT2870_RXINFO_FLAGS_CIPHER_ERR_NONE
)
3829 if (wh
->i_fc
[1] & IEEE80211_FC1_WEP
)
3830 wh
->i_fc
[1] &= ~IEEE80211_FC1_WEP
;
3832 m
->m_flags
|= M_WEP
;
3836 RT2870_DPRINTF(sc
, RT2870_DEBUG_RX
,
3837 "%s: rxinfo: cipher error=0x%02x\n",
3838 device_get_nameunit(sc
->dev
), cipher_err
);
3842 if (!(ifp
->if_flags
& IFF_PROMISC
))
3851 if (wh
->i_fc
[1] & IEEE80211_FC1_WEP
)
3855 if (!(ifp
->if_flags
& IFF_PROMISC
))
3863 /* check for A-MPDU */
3865 if (rxinfo_flags
& RT2870_RXINFO_FLAGS_AMPDU
)
3867 m
->m_flags
|= M_AMPDU
;
3878 /* check for A-MSDU */
3880 if (rxinfo_flags
& RT2870_RXINFO_FLAGS_AMSDU
)
3891 ant
= rt2870_maxrssi_rxpath(sc
, rxwi
);
3892 rssi
= rxwi
->rssi
[ant
];
3893 rssi_dbm
= rt2870_rssi2dbm(sc
, rssi
, ant
);
3894 phymode
= ((rxwi
->phymode_stbc_shortgi
>> RT2870_RXWI_PHYMODE_SHIFT
) &
3895 RT2870_RXWI_PHYMODE_MASK
);
3896 bw
= ((rxwi
->bw_mcs
>> RT2870_RXWI_BW_SHIFT
) & RT2870_RXWI_BW_MASK
);
3897 shortgi
= ((rxwi
->phymode_stbc_shortgi
>> RT2870_RXWI_SHORTGI_SHIFT
) &
3898 RT2870_RXWI_SHORTGI_MASK
);
3899 mcs
= ((rxwi
->bw_mcs
>> RT2870_RXWI_MCS_SHIFT
) & RT2870_RXWI_MCS_MASK
);
3901 if (ieee80211_radiotap_active(ic
))
3905 tap
->flags
= (rxinfo_flags
& RT2870_RXINFO_FLAGS_L2PAD
) ? IEEE80211_RADIOTAP_F_DATAPAD
: 0;
3906 tap
->dbm_antsignal
= rssi_dbm
;
3907 tap
->dbm_antnoise
= RT2870_NOISE_FLOOR
;
3909 tap
->antsignal
= rssi
;
3910 tap
->chan_flags
= htole32(ic
->ic_curchan
->ic_flags
);
3911 tap
->chan_freq
= htole16(ic
->ic_curchan
->ic_freq
);
3912 tap
->chan_ieee
= ic
->ic_curchan
->ic_ieee
;
3913 tap
->chan_maxpow
= 0;
3915 if (phymode
== RT2870_RXWI_PHYMODE_CCK
|| phymode
== RT2870_RXWI_PHYMODE_OFDM
)
3916 tap
->rate
= rt2870_rxrate(rxwi
);
3918 tap
->rate
= mcs
| IEEE80211_RATE_MCS
;
3920 if (rxwi
->bw_mcs
& RT2870_RXWI_MCS_SHOTPRE
)
3921 tap
->flags
|= IEEE80211_RADIOTAP_F_SHORTPRE
;
3924 tap
->flags
|= IEEE80211_RADIOTAP_F_SHORTGI
;
3928 * net80211 assumes that RSSI data are in the range [-127..127] and
3929 * in .5 dBm units relative to the current noise floor
3932 rssi_dbm_rel
= (rssi_dbm
- RT2870_NOISE_FLOOR
) * 2;
3933 if (rssi_dbm_rel
> 127)
3936 RT2870_DPRINTF(sc
, RT2870_DEBUG_RX
,
3937 "%s: received frame: len=%d, phymode=%d, bw=%d, shortgi=%d, mcs=%d, "
3938 "ant=%d, rssi=%d/%d/%d, snr=%d/%d, wcid=0x%02x, ampdu=%d, amsdu=%d, "
3939 "rssi_dbm=%d, rssi_dbm_rel=%d\n",
3940 device_get_nameunit(sc
->dev
),
3941 len
, phymode
, bw
, shortgi
, mcs
,
3942 ant
, rxwi
->rssi
[0], rxwi
->rssi
[1], rxwi
->rssi
[2],
3943 rxwi
->snr
[0], rxwi
->snr
[1],
3944 rxwi
->wcid
, ampdu
, amsdu
, rssi_dbm
, rssi_dbm_rel
);
3946 ni
= ieee80211_find_rxnode(ic
, (struct ieee80211_frame_min
*) wh
);
3949 ieee80211_input(ni
, m
, rssi_dbm_rel
, RT2870_NOISE_FLOOR
);
3950 ieee80211_free_node(ni
);
3954 ieee80211_input_all(ic
, m
, rssi_dbm_rel
, RT2870_NOISE_FLOOR
);
3961 static int rt2870_tx_mgmt(struct rt2870_softc
*sc
,
3962 struct mbuf
*m
, struct ieee80211_node
*ni
, int qid
)
3965 struct ieee80211com
*ic
;
3966 struct ieee80211vap
*vap
;
3967 const struct ieee80211_txparam
*tp
;
3968 struct rt2870_softc_node
*rni
;
3969 struct rt2870_softc_tx_ring
*ring
;
3970 struct rt2870_softc_tx_data
*data
;
3971 struct rt2870_txinfo
*txinfo
;
3972 struct rt2870_txwi
*txwi
;
3973 struct ieee80211_frame
*wh
;
3974 struct rt2870_softc_tx_radiotap_header
*tap
;
3975 u_int hdrsize
, hdrspace
;
3976 uint8_t rate
, stbc
, shortgi
, mcs
, pid
;
3977 uint16_t len
, dmalen
, mpdu_len
, dur
;
3979 KASSERT(qid
>= 0 && qid
< (sc
->usb_endpoints
- 1),
3980 ("%s: Tx MGMT: invalid qid=%d\n",
3981 device_get_nameunit(sc
->dev
), qid
));
3986 rni
= (struct rt2870_softc_node
*) ni
;
3987 tp
= &vap
->iv_txparms
[ieee80211_chan2mode(ic
->ic_curchan
)];
3989 ring
= &sc
->tx_ring
[qid
];
3990 data
= STAILQ_FIRST(&ring
->inactive
);
3991 STAILQ_REMOVE_HEAD(&ring
->inactive
, next
);
3992 txinfo
= (struct rt2870_txinfo
*) data
->buf
;
3993 txwi
= (struct rt2870_txwi
*) (txinfo
+ 1);
3995 wh
= mtod(m
, struct ieee80211_frame
*);
3997 rate
= tp
->mgmtrate
& IEEE80211_RATE_VAL
;
3999 len
= sizeof(struct rt2870_txinfo
) + sizeof(struct rt2870_txwi
) + m
->m_pkthdr
.len
;
4001 /* align end on a 4-bytes boundary */
4003 dmalen
= (len
+ 3) & ~3;
4007 memset(txinfo
, 0, sizeof(struct rt2870_txinfo
));
4009 txinfo
->len
= htole16(dmalen
- sizeof(struct rt2870_txinfo
));
4011 txinfo
->qsel_flags
= (RT2870_TXINFO_QSEL_EDCA
<< RT2870_TXINFO_QSEL_SHIFT
);
4015 memset((caddr_t
) txinfo
+ len
, 0, dmalen
- len
);
4017 /* fill Tx wireless info */
4019 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
4022 mcs
= rt2870_rate2mcs(rate
);
4026 /* calculate MPDU length without padding */
4028 hdrsize
= ieee80211_hdrsize(wh
);
4029 hdrspace
= ieee80211_hdrspace(ic
, wh
);
4030 mpdu_len
= m
->m_pkthdr
.len
- hdrspace
+ hdrsize
;
4032 memset(txwi
, 0, sizeof(struct rt2870_txwi
));
4034 /* management frames do not need encryption */
4038 txwi
->pid_mpdu_len
= ((htole16(pid
) & RT2870_TXWI_PID_MASK
) <<
4039 RT2870_TXWI_PID_SHIFT
) | ((htole16(mpdu_len
) & RT2870_TXWI_MPDU_LEN_MASK
) <<
4040 RT2870_TXWI_MPDU_LEN_SHIFT
);
4042 stbc
= (ni
->ni_htcap
& IEEE80211_HTCAP_RXSTBC
) ? 1 : 0;
4044 shortgi
= (vap
->iv_flags_ht
& (IEEE80211_FHT_SHORTGI20
| IEEE80211_FHT_SHORTGI40
)) &&
4045 (ni
->ni_flags
& IEEE80211_NODE_HT
) && (ni
->ni_flags
& (IEEE80211_NODE_SGI20
| IEEE80211_NODE_SGI40
));
4047 txwi
->phymode_ifs_stbc_shortgi
|=
4048 ((stbc
& RT2870_TXWI_STBC_MASK
) << RT2870_TXWI_STBC_SHIFT
) |
4049 ((shortgi
& RT2870_TXWI_SHORTGI_MASK
) << RT2870_TXWI_SHORTGI_SHIFT
);
4051 txwi
->phymode_ifs_stbc_shortgi
|=
4052 ((shortgi
& RT2870_TXWI_SHORTGI_MASK
) << RT2870_TXWI_SHORTGI_SHIFT
);
4054 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
4056 txwi
->phymode_ifs_stbc_shortgi
|=
4057 (RT2870_TXWI_PHYMODE_HT_MIXED
<< RT2870_TXWI_PHYMODE_SHIFT
);
4061 if (ieee80211_rate2phytype(ic
->ic_rt
, rate
) != IEEE80211_T_OFDM
)
4063 txwi
->phymode_ifs_stbc_shortgi
|=
4064 (RT2870_TXWI_PHYMODE_CCK
<< RT2870_TXWI_PHYMODE_SHIFT
);
4066 if (rate
!= 2 && (ic
->ic_flags
& IEEE80211_F_SHPREAMBLE
))
4067 mcs
|= RT2870_TXWI_MCS_SHOTPRE
;
4071 txwi
->phymode_ifs_stbc_shortgi
|=
4072 (RT2870_TXWI_PHYMODE_OFDM
<< RT2870_TXWI_PHYMODE_SHIFT
);
4076 txwi
->bw_mcs
= (RT2870_TXWI_BW_20
<< RT2870_TXWI_BW_SHIFT
) |
4077 ((mcs
& RT2870_TXWI_MCS_MASK
) << RT2870_TXWI_MCS_SHIFT
);
4079 txwi
->txop
= (RT2870_TXWI_TXOP_BACKOFF
<< RT2870_TXWI_TXOP_SHIFT
);
4081 /* skip ACKs for multicast frames and probe responses */
4083 if (!IEEE80211_IS_MULTICAST(wh
->i_addr1
) &&
4084 ((wh
->i_fc
[0] & (IEEE80211_FC0_TYPE_MASK
| IEEE80211_FC0_SUBTYPE_MASK
)) !=
4085 (IEEE80211_FC0_TYPE_MGT
| IEEE80211_FC0_SUBTYPE_PROBE_RESP
)))
4087 txwi
->bawin_size_xflags
|=
4088 (RT2870_TXWI_XFLAGS_ACK
<< RT2870_TXWI_XFLAGS_SHIFT
);
4090 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
4092 /* preamble + plcp + signal extension */
4098 dur
= ieee80211_ack_duration(ic
->ic_rt
, rate
,
4099 ic
->ic_flags
& IEEE80211_F_SHPREAMBLE
);
4102 *(uint16_t *) wh
->i_dur
= htole16(dur
);
4105 /* ask MAC to insert timestamp into probe responses */
4107 if ((wh
->i_fc
[0] & (IEEE80211_FC0_TYPE_MASK
| IEEE80211_FC0_SUBTYPE_MASK
)) ==
4108 (IEEE80211_FC0_TYPE_MGT
| IEEE80211_FC0_SUBTYPE_PROBE_RESP
))
4109 txwi
->mpdu_density_flags
|=
4110 (RT2870_TXWI_FLAGS_TS
<< RT2870_TXWI_FLAGS_SHIFT
);
4112 if (ieee80211_radiotap_active_vap(vap
))
4116 tap
->flags
= IEEE80211_RADIOTAP_F_DATAPAD
;
4117 tap
->chan_flags
= htole32(ic
->ic_curchan
->ic_flags
);
4118 tap
->chan_freq
= htole16(ic
->ic_curchan
->ic_freq
);
4119 tap
->chan_ieee
= ic
->ic_curchan
->ic_ieee
;
4120 tap
->chan_maxpow
= 0;
4122 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
4123 tap
->rate
= mcs
| IEEE80211_RATE_MCS
;
4127 if (mcs
& RT2870_TXWI_MCS_SHOTPRE
)
4128 tap
->flags
|= IEEE80211_RADIOTAP_F_SHORTPRE
;
4131 tap
->flags
|= IEEE80211_RADIOTAP_F_SHORTGI
;
4133 if (wh
->i_fc
[1] & IEEE80211_FC1_WEP
)
4134 tap
->flags
|= IEEE80211_RADIOTAP_F_WEP
;
4136 if (wh
->i_fc
[1] & IEEE80211_FC1_WEP
)
4138 wh
->i_fc
[1] &= ~IEEE80211_FC1_WEP
;
4140 ieee80211_radiotap_tx(vap
, m
);
4142 wh
->i_fc
[1] |= IEEE80211_FC1_WEP
;
4146 ieee80211_radiotap_tx(vap
, m
);
4150 m_copydata(m
, 0, m
->m_pkthdr
.len
, (caddr_t
) (txwi
+ 1));
4152 RT2870_DPRINTF(sc
, RT2870_DEBUG_TX
,
4153 "%s: sending MGMT frame: qid=%d, hdrsize=%d, hdrspace=%d, len=%d, "
4154 "stbc=%d, shortgi=%d, mcs=%d, DMA len=%d\n",
4155 device_get_nameunit(sc
->dev
),
4156 qid
, hdrsize
, hdrspace
, m
->m_pkthdr
.len
, stbc
, shortgi
, mcs
, dmalen
);
4162 STAILQ_INSERT_TAIL(&ring
->pending
, data
, next
);
4165 usbd_transfer_start(sc
->usb_xfer
[1 + qid
]);
4173 static int rt2870_tx_data(struct rt2870_softc
*sc
,
4174 struct mbuf
*m
, struct ieee80211_node
*ni
, int qid
)
4177 struct ieee80211com
*ic
;
4178 struct ieee80211vap
*vap
;
4179 const struct ieee80211_txparam
*tp
;
4180 struct rt2870_softc_node
*rni
;
4181 struct rt2870_softc_tx_ring
*ring
;
4182 struct rt2870_softc_tx_data
*data
;
4183 struct rt2870_txinfo
*txinfo
;
4184 struct rt2870_txwi
*txwi
;
4185 struct ieee80211_frame
*wh
;
4186 struct ieee80211_tx_ampdu
*tx_ampdu
;
4187 ieee80211_seq seqno
;
4188 struct rt2870_softc_tx_radiotap_header
*tap
;
4189 u_int hdrsize
, hdrspace
;
4190 uint8_t type
, rate
, bw
, stbc
, shortgi
, mcs
, pid
, wcid
, mpdu_density
, bawin_size
;
4191 uint16_t qos
, len
, dmalen
, mpdu_len
, dur
;
4192 int hasqos
, ac
, tid
, ampdu
;
4194 KASSERT(qid
>= 0 && qid
< (sc
->usb_endpoints
- 1),
4195 ("%s: Tx data: invalid qid=%d\n",
4196 device_get_nameunit(sc
->dev
), qid
));
4201 rni
= (struct rt2870_softc_node
*) ni
;
4202 tp
= &vap
->iv_txparms
[ieee80211_chan2mode(ni
->ni_chan
)];
4204 ring
= &sc
->tx_ring
[qid
];
4205 data
= STAILQ_FIRST(&ring
->inactive
);
4206 STAILQ_REMOVE_HEAD(&ring
->inactive
, next
);
4207 txinfo
= (struct rt2870_txinfo
*) data
->buf
;
4208 txwi
= (struct rt2870_txwi
*) (txinfo
+ 1);
4210 wh
= mtod(m
, struct ieee80211_frame
*);
4212 type
= wh
->i_fc
[0] & IEEE80211_FC0_TYPE_MASK
;
4214 hasqos
= IEEE80211_QOS_HAS_SEQ(wh
);
4217 if (IEEE80211_HAS_ADDR4(wh
))
4218 qos
= le16toh(*(const uint16_t *)
4219 (((struct ieee80211_qosframe_addr4
*) wh
)->i_qos
));
4221 qos
= le16toh(*(const uint16_t *)
4222 (((struct ieee80211_qosframe
*) wh
)->i_qos
));
4229 if (IEEE80211_IS_MULTICAST(wh
->i_addr1
))
4230 rate
= tp
->mcastrate
;
4231 else if (m
->m_flags
& M_EAPOL
)
4232 rate
= tp
->mgmtrate
;
4233 else if (tp
->ucastrate
!= IEEE80211_FIXED_RATE_NONE
)
4234 rate
= tp
->ucastrate
;
4236 rate
= ni
->ni_txrate
;
4238 rate
&= IEEE80211_RATE_VAL
;
4240 len
= sizeof(struct rt2870_txinfo
) + sizeof(struct rt2870_txwi
) + m
->m_pkthdr
.len
;
4242 /* align end on a 4-bytes boundary */
4244 dmalen
= (len
+ 3) & ~3;
4248 memset(txinfo
, 0, sizeof(struct rt2870_txinfo
));
4250 txinfo
->len
= htole16(dmalen
- sizeof(struct rt2870_txinfo
));
4252 txinfo
->qsel_flags
= (RT2870_TXINFO_QSEL_EDCA
<< RT2870_TXINFO_QSEL_SHIFT
);
4256 memset((caddr_t
) txinfo
+ len
, 0, dmalen
- len
);
4258 /* fill Tx wireless info */
4260 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
4263 mcs
= rt2870_rate2mcs(rate
);
4267 wcid
= (type
== IEEE80211_FC0_TYPE_DATA
) ?
4268 RT2870_AID2WCID(ni
->ni_associd
) : 0xff;
4270 /* calculate MPDU length without padding */
4272 hdrsize
= ieee80211_hdrsize(wh
);
4273 hdrspace
= ieee80211_hdrspace(ic
, wh
);
4274 mpdu_len
= m
->m_pkthdr
.len
- hdrspace
+ hdrsize
;
4276 memset(txwi
, 0, sizeof(struct rt2870_txwi
));
4280 txwi
->pid_mpdu_len
= ((htole16(pid
) & RT2870_TXWI_PID_MASK
) <<
4281 RT2870_TXWI_PID_SHIFT
) | ((htole16(mpdu_len
) & RT2870_TXWI_MPDU_LEN_MASK
) <<
4282 RT2870_TXWI_MPDU_LEN_SHIFT
);
4284 stbc
= (ni
->ni_htcap
& IEEE80211_HTCAP_RXSTBC
) ? 1 : 0;
4286 shortgi
= (vap
->iv_flags_ht
& (IEEE80211_FHT_SHORTGI20
| IEEE80211_FHT_SHORTGI40
)) &&
4287 (ni
->ni_flags
& IEEE80211_NODE_HT
) && (ni
->ni_flags
& (IEEE80211_NODE_SGI20
| IEEE80211_NODE_SGI40
));
4289 txwi
->phymode_ifs_stbc_shortgi
|=
4290 ((stbc
& RT2870_TXWI_STBC_MASK
) << RT2870_TXWI_STBC_SHIFT
) |
4291 ((shortgi
& RT2870_TXWI_SHORTGI_MASK
) << RT2870_TXWI_SHORTGI_SHIFT
);
4293 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
4295 txwi
->phymode_ifs_stbc_shortgi
|=
4296 (RT2870_TXWI_PHYMODE_HT_MIXED
<< RT2870_TXWI_PHYMODE_SHIFT
);
4300 if (ieee80211_rate2phytype(ic
->ic_rt
, rate
) != IEEE80211_T_OFDM
)
4302 txwi
->phymode_ifs_stbc_shortgi
|=
4303 (RT2870_TXWI_PHYMODE_CCK
<< RT2870_TXWI_PHYMODE_SHIFT
);
4305 if (rate
!= 2 && (ic
->ic_flags
& IEEE80211_F_SHPREAMBLE
))
4306 mcs
|= RT2870_TXWI_MCS_SHOTPRE
;
4310 txwi
->phymode_ifs_stbc_shortgi
|=
4311 (RT2870_TXWI_PHYMODE_OFDM
<< RT2870_TXWI_PHYMODE_SHIFT
);
4315 if ((ni
->ni_flags
& IEEE80211_NODE_HT
) && (ni
->ni_chw
== 40))
4316 bw
= RT2870_TXWI_BW_40
;
4318 bw
= RT2870_TXWI_BW_20
;
4320 txwi
->bw_mcs
= ((bw
& RT2870_TXWI_BW_MASK
) << RT2870_TXWI_BW_SHIFT
) |
4321 ((mcs
& RT2870_TXWI_MCS_MASK
) << RT2870_TXWI_MCS_SHIFT
);
4323 txwi
->txop
= (RT2870_TXWI_TXOP_HT
<< RT2870_TXWI_TXOP_SHIFT
);
4325 if (!IEEE80211_IS_MULTICAST(wh
->i_addr1
) &&
4326 (!hasqos
|| (qos
& IEEE80211_QOS_ACKPOLICY
) != IEEE80211_QOS_ACKPOLICY_NOACK
))
4328 txwi
->bawin_size_xflags
|=
4329 (RT2870_TXWI_XFLAGS_ACK
<< RT2870_TXWI_XFLAGS_SHIFT
);
4331 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
4333 /* preamble + plcp + signal extension */
4339 dur
= ieee80211_ack_duration(ic
->ic_rt
, rate
,
4340 ic
->ic_flags
& IEEE80211_F_SHPREAMBLE
);
4343 *(uint16_t *) wh
->i_dur
= htole16(dur
);
4346 /* check fo A-MPDU */
4348 if (m
->m_flags
& M_AMPDU_MPDU
)
4350 ac
= M_WME_GETAC(m
);
4351 tid
= WME_AC_TO_TID(ac
);
4352 tx_ampdu
= &ni
->ni_tx_ampdu
[ac
];
4354 mpdu_density
= RT2870_MS(ni
->ni_htparam
, IEEE80211_HTCAP_MPDUDENSITY
);
4355 bawin_size
= 13; //tx_ampdu->txa_wnd;
4357 txwi
->mpdu_density_flags
|=
4358 ((mpdu_density
& RT2870_TXWI_MPDU_DENSITY_MASK
) << RT2870_TXWI_MPDU_DENSITY_SHIFT
) |
4359 (RT2870_TXWI_FLAGS_AMPDU
<< RT2870_TXWI_FLAGS_SHIFT
);
4361 txwi
->bawin_size_xflags
|=
4362 ((bawin_size
& RT2870_TXWI_BAWIN_SIZE_MASK
) << RT2870_TXWI_BAWIN_SIZE_SHIFT
);
4364 seqno
= ni
->ni_txseqs
[tid
]++;
4366 *(uint16_t *) &wh
->i_seq
[0] = htole16(seqno
<< IEEE80211_SEQ_SEQ_SHIFT
);
4375 /* ask MAC to insert timestamp into probe responses */
4377 if ((wh
->i_fc
[0] & (IEEE80211_FC0_TYPE_MASK
| IEEE80211_FC0_SUBTYPE_MASK
)) ==
4378 (IEEE80211_FC0_TYPE_MGT
| IEEE80211_FC0_SUBTYPE_PROBE_RESP
))
4379 txwi
->mpdu_density_flags
|=
4380 (RT2870_TXWI_FLAGS_TS
<< RT2870_TXWI_FLAGS_SHIFT
);
4382 if (ieee80211_radiotap_active_vap(vap
))
4386 tap
->flags
= IEEE80211_RADIOTAP_F_DATAPAD
;
4387 tap
->chan_flags
= htole32(ic
->ic_curchan
->ic_flags
);
4388 tap
->chan_freq
= htole16(ic
->ic_curchan
->ic_freq
);
4389 tap
->chan_ieee
= ic
->ic_curchan
->ic_ieee
;
4390 tap
->chan_maxpow
= 0;
4392 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
4393 tap
->rate
= mcs
| IEEE80211_RATE_MCS
;
4397 if (mcs
& RT2870_TXWI_MCS_SHOTPRE
)
4398 tap
->flags
|= IEEE80211_RADIOTAP_F_SHORTPRE
;
4401 tap
->flags
|= IEEE80211_RADIOTAP_F_SHORTGI
;
4403 if (wh
->i_fc
[1] & IEEE80211_FC1_WEP
)
4404 tap
->flags
|= IEEE80211_RADIOTAP_F_WEP
;
4406 if (wh
->i_fc
[1] & IEEE80211_FC1_WEP
)
4408 wh
->i_fc
[1] &= ~IEEE80211_FC1_WEP
;
4410 ieee80211_radiotap_tx(vap
, m
);
4412 wh
->i_fc
[1] |= IEEE80211_FC1_WEP
;
4416 ieee80211_radiotap_tx(vap
, m
);
4420 m_copydata(m
, 0, m
->m_pkthdr
.len
, (caddr_t
) (txwi
+ 1));
4422 RT2870_DPRINTF(sc
, RT2870_DEBUG_TX
,
4423 "%s: sending data: qid=%d, hdrsize=%d, hdrspace=%d, len=%d, "
4424 "bw=%d, stbc=%d, shortgi=%d, mcs=%d, wcid=0x%02x, ampdu=%d, DMA len=%d\n",
4425 device_get_nameunit(sc
->dev
),
4426 qid
, hdrsize
, hdrspace
, m
->m_pkthdr
.len
,
4427 bw
, stbc
, shortgi
, mcs
, wcid
, ampdu
, dmalen
);
4433 STAILQ_INSERT_TAIL(&ring
->pending
, data
, next
);
4436 usbd_transfer_start(sc
->usb_xfer
[1 + qid
]);
4444 static int rt2870_tx_raw(struct rt2870_softc
*sc
,
4445 struct mbuf
*m
, struct ieee80211_node
*ni
,
4446 const struct ieee80211_bpf_params
*params
)
4448 RT2870_DPRINTF(sc
, RT2870_DEBUG_TX
,
4450 device_get_nameunit(sc
->dev
));
4458 static void rt2870_rx_intr(struct usb_xfer
*xfer
, usb_error_t error
)
4460 struct rt2870_softc
*sc
;
4462 struct rt2870_softc_rx_ring
*ring
;
4463 struct rt2870_softc_rx_data
*data
;
4466 sc
= usbd_xfer_softc(xfer
);
4468 ring
= &sc
->rx_ring
;
4470 RT2870_DPRINTF(sc
, RT2870_DEBUG_INTR
,
4471 "%s: Rx interrupt: state=%d, error=%s\n",
4472 device_get_nameunit(sc
->dev
),
4473 USB_GET_STATE(xfer
), usbd_errstr(error
));
4475 switch (USB_GET_STATE(xfer
))
4477 case USB_ST_TRANSFERRED
:
4479 sc
->rx_interrupts
++;
4481 data
= STAILQ_FIRST(&ring
->active
);
4485 STAILQ_REMOVE_HEAD(&ring
->active
, next
);
4487 usbd_xfer_status(xfer
, &len
, NULL
, NULL
, NULL
);
4491 STAILQ_INSERT_TAIL(&ring
->done
, data
, next
);
4493 taskqueue_enqueue(sc
->taskqueue
, &sc
->rx_done_task
);
4500 data
= STAILQ_FIRST(&ring
->inactive
);
4504 STAILQ_REMOVE_HEAD(&ring
->inactive
, next
);
4506 STAILQ_INSERT_TAIL(&ring
->active
, data
, next
);
4508 usbd_xfer_set_frame_data(xfer
, 0, data
->buf
, usbd_xfer_max_len(xfer
));
4509 usbd_transfer_submit(xfer
);
4514 sc
->rx_interrupts
++;
4516 data
= STAILQ_FIRST(&ring
->active
);
4519 STAILQ_REMOVE_HEAD(&ring
->active
, next
);
4520 STAILQ_INSERT_TAIL(&ring
->inactive
, data
, next
);
4523 if (error
!= USB_ERR_CANCELLED
)
4527 usbd_xfer_set_stall(xfer
);
4538 static void rt2870_tx_intr(struct usb_xfer
*xfer
, usb_error_t error
)
4540 struct rt2870_softc
*sc
;
4542 struct rt2870_softc_tx_ring
*ring
;
4543 struct rt2870_softc_tx_data
*data
;
4545 sc
= usbd_xfer_softc(xfer
);
4547 ring
= usbd_xfer_get_priv(xfer
);
4549 usbd_xfer_status(xfer
, NULL
, NULL
, NULL
, NULL
);
4551 RT2870_DPRINTF(sc
, RT2870_DEBUG_INTR
,
4552 "%s: Tx interrupt: state=%d, error=%s\n",
4553 device_get_nameunit(sc
->dev
),
4554 USB_GET_STATE(xfer
), usbd_errstr(error
));
4556 switch (USB_GET_STATE(xfer
))
4558 case USB_ST_TRANSFERRED
:
4560 sc
->tx_interrupts
[ring
->qid
]++;
4562 data
= STAILQ_FIRST(&ring
->active
);
4566 STAILQ_REMOVE_HEAD(&ring
->active
, next
);
4568 STAILQ_INSERT_TAIL(&ring
->done
, data
, next
);
4570 sc
->tx_qid_pending_mask
|= (1 << ring
->qid
);
4572 taskqueue_enqueue(sc
->taskqueue
, &sc
->tx_done_task
);
4579 data
= STAILQ_FIRST(&ring
->pending
);
4583 STAILQ_REMOVE_HEAD(&ring
->pending
, next
);
4584 STAILQ_INSERT_TAIL(&ring
->active
, data
, next
);
4586 usbd_xfer_set_frame_data(xfer
, 0, data
->buf
, data
->len
);
4587 usbd_transfer_submit(xfer
);
4589 RT2870_SOFTC_UNLOCK(sc
);
4593 RT2870_SOFTC_LOCK(sc
);
4598 sc
->tx_interrupts
[ring
->qid
]++;
4600 data
= STAILQ_FIRST(&ring
->active
);
4603 STAILQ_REMOVE_HEAD(&ring
->active
, next
);
4605 printf("%s: could not transmit buffer: qid=%d, error=%s\n",
4606 device_get_nameunit(sc
->dev
), ring
->qid
, usbd_errstr(error
));
4608 if (data
->m
!= NULL
)
4614 if (data
->ni
!= NULL
)
4616 ieee80211_free_node(data
->ni
);
4620 STAILQ_INSERT_TAIL(&ring
->inactive
, data
, next
);
4625 if (error
!= USB_ERR_CANCELLED
)
4628 ifp
->if_drv_flags
&= ~IFF_DRV_OACTIVE
;
4630 usbd_xfer_set_stall(xfer
);
4639 * rt2870_rx_done_task
4641 static void rt2870_rx_done_task(void *context
, int pending
)
4643 struct rt2870_softc
*sc
;
4649 RT2870_DPRINTF(sc
, RT2870_DEBUG_RX
,
4650 "%s: Rx done task\n",
4651 device_get_nameunit(sc
->dev
));
4653 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
4656 if (rt2870_rx_eof(sc
, sc
->rx_process_limit
) != 0)
4658 RT2870_DPRINTF(sc
, RT2870_DEBUG_RX
,
4659 "%s: Rx done task: scheduling again\n",
4660 device_get_nameunit(sc
->dev
));
4662 taskqueue_enqueue(sc
->taskqueue
, &sc
->rx_done_task
);
4667 * rt2870_tx_done_task
4669 static void rt2870_tx_done_task(void *context
, int pending
)
4671 struct rt2870_softc
*sc
;
4678 RT2870_DPRINTF(sc
, RT2870_DEBUG_TX
,
4679 "%s: Tx done task\n",
4680 device_get_nameunit(sc
->dev
));
4682 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
4685 for (i
= sc
->usb_endpoints
- 2; i
>= 0; i
--)
4687 if (sc
->tx_qid_pending_mask
& (1 << i
))
4689 sc
->tx_qid_pending_mask
&= ~(1 << i
);
4691 rt2870_tx_eof(sc
, &sc
->tx_ring
[i
]);
4695 if (sc
->tx_qid_pending_mask
!= 0)
4697 RT2870_DPRINTF(sc
, RT2870_DEBUG_TX
,
4698 "%s: Tx done task: scheduling again\n",
4699 device_get_nameunit(sc
->dev
));
4701 taskqueue_enqueue(sc
->taskqueue
, &sc
->tx_done_task
);
4706 ifp
->if_drv_flags
&= ~IFF_DRV_OACTIVE
;
4710 * rt2870_periodic_task
4712 static void rt2870_periodic_task(void *context
, int pending
)
4714 struct rt2870_softc
*sc
;
4716 struct ieee80211com
*ic
;
4717 struct ieee80211vap
*vap
;
4722 vap
= TAILQ_FIRST(&ic
->ic_vaps
);
4724 RT2870_DPRINTF(sc
, RT2870_DEBUG_PERIODIC
,
4725 "%s: periodic task: round=%lu\n",
4726 device_get_nameunit(sc
->dev
), sc
->periodic_round
);
4728 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
4731 RT2870_SOFTC_LOCK(sc
);
4733 sc
->periodic_round
++;
4735 rt2870_update_stats(sc
);
4737 if ((sc
->periodic_round
% 10) == 0)
4739 rt2870_bbp_tuning(sc
);
4741 rt2870_update_raw_counters(sc
);
4743 rt2870_watchdog(sc
);
4745 if (vap
!= NULL
&& vap
->iv_opmode
!= IEEE80211_M_MONITOR
&& vap
->iv_state
== IEEE80211_S_RUN
)
4747 if (vap
->iv_opmode
== IEEE80211_M_STA
)
4748 rt2870_amrr_update_iter_func(vap
, vap
->iv_bss
);
4750 ieee80211_iterate_nodes(&ic
->ic_sta
, rt2870_amrr_update_iter_func
, vap
);
4754 RT2870_SOFTC_UNLOCK(sc
);
4756 callout_reset(&sc
->periodic_ch
, hz
/ 10, rt2870_periodic
, sc
);
4762 static void rt2870_cmd_task(void *context
, int pending
)
4764 struct rt2870_softc
*sc
;
4765 struct rt2870_softc_cmd_ring
*ring
;
4766 struct rt2870_softc_cmd
*cmd
;
4769 ring
= &sc
->cmd_ring
;
4773 RT2870_SOFTC_LOCK(sc
);
4775 cmd
= STAILQ_FIRST(&ring
->active
);
4778 RT2870_SOFTC_UNLOCK(sc
);
4782 STAILQ_REMOVE_HEAD(&ring
->active
, next
);
4784 RT2870_SOFTC_UNLOCK(sc
);
4786 cmd
->cb(sc
, cmd
->data
);
4788 RT2870_SOFTC_LOCK(sc
);
4790 STAILQ_INSERT_TAIL(&ring
->inactive
, cmd
, next
);
4793 RT2870_SOFTC_UNLOCK(sc
);
4800 static int rt2870_rx_eof(struct rt2870_softc
*sc
, int limit
)
4803 struct rt2870_softc_rx_ring
*ring
;
4804 struct rt2870_softc_rx_data
*data
;
4810 ring
= &sc
->rx_ring
;
4816 RT2870_SOFTC_LOCK(sc
);
4818 data
= STAILQ_FIRST(&ring
->done
);
4821 RT2870_SOFTC_UNLOCK(sc
);
4825 STAILQ_REMOVE_HEAD(&ring
->done
, next
);
4827 RT2870_SOFTC_UNLOCK(sc
);
4832 if (len
< RT2870_RX_DESC_SIZE
)
4838 while (len
> (sizeof(uint32_t) + sizeof(struct rt2870_rxinfo
)))
4840 dmalen
= (le32toh(*(uint32_t *) buf
) & 0xffff);
4842 if (dmalen
== 0 || (dmalen
& 3) != 0)
4844 RT2870_DPRINTF(sc
, RT2870_DEBUG_RX
,
4845 "%s: bad DMA len=%u\n",
4846 device_get_nameunit(sc
->dev
), dmalen
);
4850 if ((dmalen
+ sizeof(uint32_t) + sizeof(struct rt2870_rxinfo
)) > len
)
4852 RT2870_DPRINTF(sc
, RT2870_DEBUG_RX
,
4853 "%s: bad DMA len: DMA len=%u, USB len=%d\n",
4854 device_get_nameunit(sc
->dev
),
4855 (unsigned int) (dmalen
+ sizeof(uint32_t) + sizeof(struct rt2870_rxinfo
)), len
);
4861 rt2870_rx_frame(sc
, buf
+ sizeof(uint32_t), dmalen
);
4863 buf
+= (dmalen
+ sizeof(uint32_t) + sizeof(struct rt2870_rxinfo
));
4864 len
-= (dmalen
+ sizeof(uint32_t) + sizeof(struct rt2870_rxinfo
));
4869 RT2870_SOFTC_LOCK(sc
);
4871 STAILQ_INSERT_TAIL(&ring
->inactive
, data
, next
);
4873 usbd_transfer_start(sc
->usb_xfer
[0]);
4875 RT2870_SOFTC_UNLOCK(sc
);
4880 RT2870_DPRINTF(sc
, RT2870_DEBUG_RX
,
4881 "%s: Rx eof: nframes=%d\n",
4882 device_get_nameunit(sc
->dev
), nframes
);
4884 sc
->rx_packets
+= nframes
;
4886 return (limit
== 0);
4892 static void rt2870_tx_eof(struct rt2870_softc
*sc
,
4893 struct rt2870_softc_tx_ring
*ring
)
4896 struct rt2870_softc_tx_data
*data
;
4905 RT2870_SOFTC_LOCK(sc
);
4907 data
= STAILQ_FIRST(&ring
->done
);
4910 RT2870_SOFTC_UNLOCK(sc
);
4914 STAILQ_REMOVE_HEAD(&ring
->done
, next
);
4916 RT2870_SOFTC_UNLOCK(sc
);
4920 if (data
->m
->m_flags
& M_TXCB
)
4921 ieee80211_process_callback(data
->ni
, data
->m
, 0);
4925 ieee80211_free_node(data
->ni
);
4930 RT2870_SOFTC_LOCK(sc
);
4932 STAILQ_INSERT_TAIL(&ring
->inactive
, data
, next
);
4937 RT2870_SOFTC_UNLOCK(sc
);
4940 RT2870_DPRINTF(sc
, RT2870_DEBUG_TX
,
4941 "%s: Tx eof: qid=%d, nframes=%d\n",
4942 device_get_nameunit(sc
->dev
), ring
->qid
, nframes
);
4946 * rt2870_update_stats
4948 static void rt2870_update_stats(struct rt2870_softc
*sc
)
4951 struct ieee80211com
*ic
;
4952 struct ieee80211vap
*vap
;
4953 struct ieee80211_node
*ni
;
4955 int beacons
, noretryok
, retryok
, failed
;
4961 vap
= TAILQ_FIRST(&ic
->ic_vaps
);
4963 RT2870_DPRINTF(sc
, RT2870_DEBUG_STATS
,
4964 "%s: update statistic\n",
4965 device_get_nameunit(sc
->dev
));
4967 rt2870_drain_fifo_stats(sc
);
4969 /* read and clear Tx statistic registers */
4971 rt2870_io_mac_read_multi(sc
, RT2870_REG_TX_STA_CNT0
,
4972 stacnt
, sizeof(stacnt
));
4974 stacnt
[0] = le32toh(stacnt
[0]);
4975 stacnt
[1] = le32toh(stacnt
[1]);
4976 stacnt
[2] = le32toh(stacnt
[2]);
4978 beacons
= stacnt
[0] >> 16;
4979 noretryok
= stacnt
[1] & 0xffff;
4980 retryok
= stacnt
[1] >> 16;
4981 failed
= stacnt
[0] & 0xffff;
4983 RT2870_DPRINTF(sc
, RT2870_DEBUG_STATS
,
4984 "%s: update statistic: beacons=%d, noretryok=%d, retryok=%d, failed=%d\n",
4985 device_get_nameunit(sc
->dev
),
4986 beacons
, noretryok
, retryok
, failed
);
4988 ifp
->if_oerrors
+= failed
;
4990 sc
->tx_beacons
+= beacons
;
4991 sc
->tx_noretryok
+= noretryok
;
4992 sc
->tx_retryok
+= retryok
;
4993 sc
->tx_failed
+= failed
;
4995 if (vap
!= NULL
&& vap
->iv_opmode
== IEEE80211_M_STA
&& vap
->iv_state
== IEEE80211_S_RUN
)
4999 associd
= (ni
!= NULL
) ? ni
->ni_associd
: 0;
5000 wcid
= RT2870_AID2WCID(associd
);
5002 rt2870_amrr_tx_update(&sc
->amrr_node
[wcid
],
5003 noretryok
+ retryok
+ failed
, noretryok
+ retryok
, retryok
+ failed
);
5010 static void rt2870_bbp_tuning(struct rt2870_softc
*sc
)
5013 struct ieee80211com
*ic
;
5014 struct ieee80211vap
*vap
;
5015 struct ieee80211_node
*ni
;
5017 int8_t rssi
, old
, new;
5019 /* RT2860C does not support BBP tuning */
5021 if (sc
->mac_rev
== 0x28600100)
5026 vap
= TAILQ_FIRST(&ic
->ic_vaps
);
5028 if ((ic
->ic_flags
& IEEE80211_F_SCAN
) || vap
== NULL
||
5029 vap
->iv_opmode
!= IEEE80211_M_STA
|| vap
->iv_state
!= IEEE80211_S_RUN
)
5034 chan
= ieee80211_chan2ieee(ic
, ni
->ni_chan
);
5038 else if (chan
<= 64)
5040 else if (chan
<= 128)
5045 rssi
= ieee80211_getrssi(vap
);
5047 if (IEEE80211_IS_CHAN_2GHZ(ni
->ni_chan
))
5049 new = 0x2e + sc
->lna_gain
[group
];
5053 if (!IEEE80211_IS_CHAN_HT40(ni
->ni_chan
))
5054 new = 0x32 + sc
->lna_gain
[group
] * 5 / 3;
5056 new = 0x3a + sc
->lna_gain
[group
] * 5 / 3;
5059 /* Tune if absolute average RSSI is greater than -80 */
5064 old
= rt2870_io_bbp_read(sc
, 66);
5067 rt2870_io_bbp_write(sc
, 66, new);
5073 static void rt2870_watchdog(struct rt2870_softc
*sc
)
5078 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_PBF_TXRXQ_PCNT
);
5080 RT2870_DPRINTF(sc
, RT2870_DEBUG_WATCHDOG
,
5081 "%s: watchdog: TXRXQ_PCNT=0x%08x\n",
5082 device_get_nameunit(sc
->dev
), tmp
);
5084 if (((tmp
>> RT2870_REG_TX0Q_PCNT_SHIFT
) & RT2870_REG_TX0Q_PCNT_MASK
) != 0)
5086 sc
->tx_queue_not_empty
[0]++;
5088 rt2870_io_mac_write(sc
, RT2870_REG_PBF_CFG
, 0xf40012);
5090 for (ntries
= 0; ntries
< 10; ntries
++)
5092 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_PBF_TXRXQ_PCNT
);
5093 if (((tmp
>> RT2870_REG_TX0Q_PCNT_SHIFT
) & RT2870_REG_TX0Q_PCNT_MASK
) == 0)
5099 rt2870_io_mac_write(sc
, RT2870_REG_PBF_CFG
, 0xf40006);
5102 if (((tmp
>> RT2870_REG_TX1Q_PCNT_SHIFT
) & RT2870_REG_TX1Q_PCNT_MASK
) != 0)
5104 sc
->tx_queue_not_empty
[1]++;
5106 rt2870_io_mac_write(sc
, RT2870_REG_PBF_CFG
, 0xf4000a);
5108 for (ntries
= 0; ntries
< 10; ntries
++)
5110 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_PBF_TXRXQ_PCNT
);
5111 if (((tmp
>> RT2870_REG_TX1Q_PCNT_SHIFT
) & RT2870_REG_TX1Q_PCNT_MASK
) == 0)
5117 rt2870_io_mac_write(sc
, RT2870_REG_PBF_CFG
, 0xf40006);
5122 * rt2870_drain_fifo_stats
5124 static void rt2870_drain_fifo_stats(struct rt2870_softc
*sc
)
5128 uint8_t wcid
, mcs
, pid
;
5129 int ok
, agg
, retrycnt
;
5133 /* drain Tx status FIFO (maxsize = 16) */
5135 while ((stats
= rt2870_io_mac_read(sc
, RT2870_REG_TX_STA_FIFO
)) &
5136 RT2870_REG_TX_STA_FIFO_VALID
)
5138 wcid
= (stats
>> RT2870_REG_TX_STA_FIFO_WCID_SHIFT
) &
5139 RT2870_REG_TX_STA_FIFO_WCID_MASK
;
5141 /* if no ACK was requested, no feedback is available */
5143 if (!(stats
& RT2870_REG_TX_STA_FIFO_ACK_REQ
) || wcid
== 0xff)
5146 /* update AMRR statistic */
5148 ok
= (stats
& RT2870_REG_TX_STA_FIFO_TX_OK
) ? 1 : 0;
5149 agg
= (stats
& RT2870_REG_TX_STA_FIFO_AGG
) ? 1 : 0;
5150 mcs
= (stats
>> RT2870_REG_TX_STA_FIFO_MCS_SHIFT
) &
5151 RT2870_REG_TX_STA_FIFO_MCS_MASK
;
5152 pid
= (stats
>> RT2870_REG_TX_STA_FIFO_PID_SHIFT
) &
5153 RT2870_REG_TX_STA_FIFO_PID_MASK
;
5154 retrycnt
= pid
- mcs
;
5156 RT2870_DPRINTF(sc
, RT2870_DEBUG_STATS
,
5157 "%s: FIFO statistic: wcid=0x%02x, ok=%d, agg=%d, mcs=0x%02x, pid=0x%02x, retrycnt=%d\n",
5158 device_get_nameunit(sc
->dev
),
5159 wcid
, ok
, agg
, mcs
, pid
, retrycnt
);
5161 rt2870_amrr_tx_complete(&sc
->amrr_node
[wcid
], ok
, retrycnt
);
5169 * rt2870_update_raw_counters
5171 static void rt2870_update_raw_counters(struct rt2870_softc
*sc
)
5175 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_TX_AGG_CNT
);
5177 sc
->tx_nonagg
+= tmp
& 0xffff;
5178 sc
->tx_agg
+= tmp
>> 16;
5180 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_TX_AGG_CNT0
);
5182 sc
->tx_ampdu
+= (tmp
& 0xffff) / 1 + (tmp
>> 16) / 2;
5184 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_TX_AGG_CNT1
);
5186 sc
->tx_ampdu
+= (tmp
& 0xffff) / 3 + (tmp
>> 16) / 4;
5188 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_TX_AGG_CNT2
);
5190 sc
->tx_ampdu
+= (tmp
& 0xffff) / 5 + (tmp
>> 16) / 6;
5192 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_TX_AGG_CNT3
);
5194 sc
->tx_ampdu
+= (tmp
& 0xffff) / 7 + (tmp
>> 16) / 8;
5196 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_TX_AGG_CNT4
);
5198 sc
->tx_ampdu
+= (tmp
& 0xffff) / 9 + (tmp
>> 16) / 10;
5200 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_TX_AGG_CNT5
);
5202 sc
->tx_ampdu
+= (tmp
& 0xffff) / 11 + (tmp
>> 16) / 12;
5204 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_TX_AGG_CNT6
);
5206 sc
->tx_ampdu
+= (tmp
& 0xffff) / 13 + (tmp
>> 16) / 14;
5208 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_TX_AGG_CNT7
);
5210 sc
->tx_ampdu
+= (tmp
& 0xffff) / 15 + (tmp
>> 16) / 16;
5212 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_RX_STA_CNT0
);
5214 sc
->rx_crc_errors
+= tmp
& 0xffff;
5215 sc
->rx_phy_errors
+= tmp
>> 16;
5217 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_RX_STA_CNT1
);
5219 sc
->rx_false_ccas
+= tmp
& 0xffff;
5220 sc
->rx_plcp_errors
+= tmp
>> 16;
5222 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_RX_STA_CNT2
);
5224 sc
->rx_dup_packets
+= tmp
& 0xffff;
5225 sc
->rx_fifo_overflows
+= tmp
>> 16;
5229 * rt2870_txrx_enable
5231 static int rt2870_txrx_enable(struct rt2870_softc
*sc
)
5233 struct ieee80211com
*ic
;
5241 /* enable Tx/Rx DMA engine */
5243 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_SCHDMA_USB_CYC_CFG
);
5248 rt2870_io_mac_write(sc
, RT2870_REG_SCHDMA_USB_CYC_CFG
, tmp
);
5250 if ((sc
->mac_rev
& 0xffff) != 0x0101)
5251 rt2870_io_mac_write(sc
, RT2870_REG_TX_TXOP_CTRL_CFG
, 0x583f);
5253 rt2870_io_mac_write(sc
, RT2870_REG_SYS_CTRL
, RT2870_REG_TX_ENABLE
);
5255 for (ntries
= 0; ntries
< 200; ntries
++)
5257 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_SCHDMA_WPDMA_GLO_CFG
);
5258 if (!(tmp
& (RT2870_REG_TX_DMA_BUSY
| RT2870_REG_RX_DMA_BUSY
)))
5266 printf("%s: timeout waiting for DMA engine\n",
5267 device_get_nameunit(sc
->dev
));
5273 rt2870_io_mac_write(sc
, RT2870_REG_SCHDMA_WMM_TXOP0_CFG
, 0);
5274 rt2870_io_mac_write(sc
, RT2870_REG_SCHDMA_WMM_TXOP1_CFG
,
5277 tmp
|= RT2870_REG_TX_WB_DDONE
|
5278 RT2870_REG_RX_DMA_ENABLE
|
5279 RT2870_REG_TX_DMA_ENABLE
;
5281 rt2870_io_mac_write(sc
, RT2870_REG_SCHDMA_WPDMA_GLO_CFG
, tmp
);
5283 tmp
= RT2870_REG_USB_DMA_TX_ENABLE
|
5284 RT2870_REG_USB_DMA_RX_ENABLE
|
5285 RT2870_REG_USB_DMA_RX_AGG_ENABLE
|
5286 /* Rx agg limit in unit of 1024 byte */
5287 ((RT2870_USB_RX_BULK_BUFLEN
/ 1024 - 3) << RT2870_REG_USB_DMA_RX_AGG_LIMIT_SHIFT
) |
5288 /* Rx agg timeout in unit of 33ns */
5291 rt2870_io_mac_write(sc
, RT2870_REG_SCHDMA_USB_DMA_CFG
, tmp
);
5295 tmp
= RT2870_REG_RX_FILTER_DROP_CRC_ERR
|
5296 RT2870_REG_RX_FILTER_DROP_PHY_ERR
;
5298 if (ic
->ic_opmode
!= IEEE80211_M_MONITOR
)
5300 tmp
|= RT2870_REG_RX_FILTER_DROP_DUPL
|
5301 RT2870_REG_RX_FILTER_DROP_CTS
|
5302 RT2870_REG_RX_FILTER_DROP_BA
|
5303 RT2870_REG_RX_FILTER_DROP_ACK
|
5304 RT2870_REG_RX_FILTER_DROP_VER_ERR
|
5305 RT2870_REG_RX_FILTER_DROP_CTRL_RSV
|
5306 RT2870_REG_RX_FILTER_DROP_CFACK
|
5307 RT2870_REG_RX_FILTER_DROP_CFEND
;
5309 if (ic
->ic_opmode
== IEEE80211_M_STA
)
5310 tmp
|= RT2870_REG_RX_FILTER_DROP_RTS
|
5311 RT2870_REG_RX_FILTER_DROP_PSPOLL
;
5313 if (!(ifp
->if_flags
& IFF_PROMISC
))
5314 tmp
|= RT2870_REG_RX_FILTER_DROP_UC_NOME
;
5317 rt2870_io_mac_write(sc
, RT2870_REG_RX_FILTER_CFG
, tmp
);
5319 rt2870_io_mac_write(sc
, RT2870_REG_SYS_CTRL
,
5320 RT2870_REG_RX_ENABLE
| RT2870_REG_TX_ENABLE
);
5326 * rt2870_alloc_rx_ring
5328 static int rt2870_alloc_rx_ring(struct rt2870_softc
*sc
,
5329 struct rt2870_softc_rx_ring
*ring
)
5331 struct rt2870_softc_rx_data
*data
;
5334 STAILQ_INIT(&ring
->inactive
);
5335 STAILQ_INIT(&ring
->active
);
5336 STAILQ_INIT(&ring
->done
);
5338 for (i
= 0; i
< RT2870_SOFTC_RX_RING_DATA_COUNT
; i
++)
5340 data
= &ring
->data
[i
];
5342 data
->buf
= malloc(RT2870_USB_RX_BULK_BUFLEN
, M_USBDEV
, M_NOWAIT
);
5343 if (data
->buf
== NULL
)
5345 printf("%s: could not allocate Rx buffer\n",
5346 device_get_nameunit(sc
->dev
));
5351 STAILQ_INSERT_TAIL(&ring
->inactive
, data
, next
);
5358 rt2870_free_rx_ring(sc
, ring
);
5364 * rt2870_reset_rx_ring
5366 static void rt2870_reset_rx_ring(struct rt2870_softc
*sc
,
5367 struct rt2870_softc_rx_ring
*ring
)
5369 struct rt2870_softc_rx_data
*data
;
5372 STAILQ_INIT(&ring
->inactive
);
5373 STAILQ_INIT(&ring
->active
);
5374 STAILQ_INIT(&ring
->done
);
5376 for (i
= 0; i
< RT2870_SOFTC_RX_RING_DATA_COUNT
; i
++)
5378 data
= &ring
->data
[i
];
5380 STAILQ_INSERT_TAIL(&ring
->inactive
, data
, next
);
5385 * rt2870_free_rx_ring
5387 static void rt2870_free_rx_ring(struct rt2870_softc
*sc
,
5388 struct rt2870_softc_rx_ring
*ring
)
5390 struct rt2870_softc_rx_data
*data
;
5393 for (i
= 0; i
< RT2870_SOFTC_RX_RING_DATA_COUNT
; i
++)
5395 data
= &ring
->data
[i
];
5397 if (data
->buf
!= NULL
)
5399 free(data
->buf
, M_USBDEV
);
5406 * rt2870_alloc_tx_ring
5408 static int rt2870_alloc_tx_ring(struct rt2870_softc
*sc
,
5409 struct rt2870_softc_tx_ring
*ring
, int qid
)
5411 struct rt2870_softc_tx_data
*data
;
5414 STAILQ_INIT(&ring
->inactive
);
5415 STAILQ_INIT(&ring
->pending
);
5416 STAILQ_INIT(&ring
->active
);
5417 STAILQ_INIT(&ring
->done
);
5422 for (i
= 0; i
< RT2870_SOFTC_TX_RING_DATA_COUNT
; i
++)
5424 data
= &ring
->data
[i
];
5426 data
->buf
= malloc(RT2870_TX_DESC_SIZE
+ MJUMPAGESIZE
, M_USBDEV
, M_NOWAIT
);
5427 if (data
->buf
== NULL
)
5429 printf("%s: could not allocate Tx buffer\n",
5430 device_get_nameunit(sc
->dev
));
5435 memset(data
->buf
, 0, RT2870_TX_DESC_SIZE
);
5437 STAILQ_INSERT_TAIL(&ring
->inactive
, data
, next
);
5444 rt2870_free_tx_ring(sc
, ring
);
5450 * rt2870_reset_tx_ring
5452 static void rt2870_reset_tx_ring(struct rt2870_softc
*sc
,
5453 struct rt2870_softc_tx_ring
*ring
)
5455 struct rt2870_softc_tx_data
*data
;
5458 STAILQ_INIT(&ring
->inactive
);
5459 STAILQ_INIT(&ring
->pending
);
5460 STAILQ_INIT(&ring
->active
);
5461 STAILQ_INIT(&ring
->done
);
5465 for (i
= 0; i
< RT2870_SOFTC_TX_RING_DATA_COUNT
; i
++)
5467 data
= &ring
->data
[i
];
5469 if (data
->m
!= NULL
)
5475 if (data
->ni
!= NULL
)
5477 ieee80211_free_node(data
->ni
);
5481 STAILQ_INSERT_TAIL(&ring
->inactive
, data
, next
);
5486 * rt2870_free_tx_ring
5488 static void rt2870_free_tx_ring(struct rt2870_softc
*sc
,
5489 struct rt2870_softc_tx_ring
*ring
)
5491 struct rt2870_softc_tx_data
*data
;
5494 for (i
= 0; i
< RT2870_SOFTC_TX_RING_DATA_COUNT
; i
++)
5496 data
= &ring
->data
[i
];
5498 if (data
->buf
!= NULL
)
5500 free(data
->buf
, M_USBDEV
);
5504 if (data
->m
!= NULL
)
5510 if (data
->ni
!= NULL
)
5512 ieee80211_free_node(data
->ni
);
5519 * rt2870_reset_cmd_ring
5521 static void rt2870_reset_cmd_ring(struct rt2870_softc
*sc
,
5522 struct rt2870_softc_cmd_ring
*ring
)
5524 struct rt2870_softc_cmd
*cmd
;
5527 STAILQ_INIT(&ring
->inactive
);
5528 STAILQ_INIT(&ring
->active
);
5532 for (i
= 0; i
< RT2870_SOFTC_CMD_RING_CMD_COUNT
; i
++)
5534 cmd
= &ring
->cmd
[i
];
5536 STAILQ_INSERT_TAIL(&ring
->inactive
, cmd
, next
);
5541 * rt2870_sysctl_attach
5543 static void rt2870_sysctl_attach(struct rt2870_softc
*sc
)
5545 struct sysctl_ctx_list
*ctx
;
5546 struct sysctl_oid
*tree
;
5547 struct sysctl_oid
*stats
;
5549 ctx
= device_get_sysctl_ctx(sc
->dev
);
5550 tree
= device_get_sysctl_tree(sc
->dev
);
5552 stats
= SYSCTL_ADD_NODE(ctx
, SYSCTL_CHILDREN(tree
), OID_AUTO
,
5553 "stats", CTLFLAG_RD
, 0, "statistic");
5555 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5556 "interrupts", CTLFLAG_RD
, &sc
->interrupts
, 0,
5559 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5560 "rx_interrupts", CTLFLAG_RD
, &sc
->rx_interrupts
, 0,
5563 if (sc
->usb_endpoints
== RT2870_SOFTC_USB_XFER_COUNT
)
5565 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5566 "tx_mgmt_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[5], 0,
5567 "Tx MGMT interrupts");
5569 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5570 "tx_hcca_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[4], 0,
5571 "Tx HCCA interrupts");
5574 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5575 "tx_ac3_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[3], 0,
5576 "Tx AC3 interrupts");
5578 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5579 "tx_ac2_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[2], 0,
5580 "Tx AC2 interrupts");
5582 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5583 "tx_ac1_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[1], 0,
5584 "Tx AC1 interrupts");
5586 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5587 "tx_ac0_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[0], 0,
5588 "Tx AC0 interrupts");
5590 if (sc
->usb_endpoints
== RT2870_SOFTC_USB_XFER_COUNT
)
5592 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5593 "tx_mgmt_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[5].queued
, 0,
5594 "Tx MGMT data queued");
5596 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5597 "tx_hcca_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[4].queued
, 0,
5598 "Tx HCCA data queued");
5601 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5602 "tx_ac3_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[3].queued
, 0,
5603 "Tx AC3 data queued");
5605 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5606 "tx_ac2_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[2].queued
, 0,
5607 "Tx AC2 data queued");
5609 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5610 "tx_ac1_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[1].queued
, 0,
5611 "Tx AC1 data queued");
5613 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5614 "tx_ac0_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[0].queued
, 0,
5615 "Tx AC0 data queued");
5617 if (sc
->usb_endpoints
== RT2870_SOFTC_USB_XFER_COUNT
)
5619 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5620 "tx_mgmt_data_queue_full", CTLFLAG_RD
, &sc
->tx_data_queue_full
[5], 0,
5621 "Tx MGMT data queue full");
5623 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5624 "tx_hcca_data_queue_full", CTLFLAG_RD
, &sc
->tx_data_queue_full
[4], 0,
5625 "Tx HCCA data queue full");
5628 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5629 "tx_ac3_data_queue_full", CTLFLAG_RD
, &sc
->tx_data_queue_full
[3], 0,
5630 "Tx AC3 data queue full");
5632 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5633 "tx_ac2_data_queue_full", CTLFLAG_RD
, &sc
->tx_data_queue_full
[2], 0,
5634 "Tx AC2 data queue full");
5636 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5637 "tx_ac1_data_queue_full", CTLFLAG_RD
, &sc
->tx_data_queue_full
[1], 0,
5638 "Tx AC1 data queue full");
5640 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5641 "tx_ac0_data_queue_full", CTLFLAG_RD
, &sc
->tx_data_queue_full
[0], 0,
5642 "Tx AC0 data queue full");
5644 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5645 "tx_watchdog_timeouts", CTLFLAG_RD
, &sc
->tx_watchdog_timeouts
, 0,
5646 "Tx watchdog timeouts");
5648 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5649 "rx_mbuf_alloc_errors", CTLFLAG_RD
, &sc
->rx_mbuf_alloc_errors
, 0,
5650 "Rx mbuf allocation errors");
5652 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5653 "tx_queue_0_not_empty", CTLFLAG_RD
, &sc
->tx_queue_not_empty
[0], 0,
5654 "Tx queue 0 not empty");
5656 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5657 "tx_queue_1_not_empty", CTLFLAG_RD
, &sc
->tx_queue_not_empty
[1], 0,
5658 "Tx queue 1 not empty");
5660 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5661 "tx_beacons", CTLFLAG_RD
, &sc
->tx_beacons
, 0,
5664 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5665 "tx_noretryok", CTLFLAG_RD
, &sc
->tx_noretryok
, 0,
5666 "Tx successfull without retries");
5668 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5669 "tx_retryok", CTLFLAG_RD
, &sc
->tx_retryok
, 0,
5670 "Tx successfull with retries");
5672 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5673 "tx_failed", CTLFLAG_RD
, &sc
->tx_failed
, 0,
5676 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5677 "tx_nonagg", CTLFLAG_RD
, &sc
->tx_nonagg
, 0,
5678 "Tx non-aggregated");
5680 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5681 "tx_agg", CTLFLAG_RD
, &sc
->tx_agg
, 0,
5684 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5685 "tx_ampdu", CTLFLAG_RD
, &sc
->tx_ampdu
, 0,
5688 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5689 "rx_packets", CTLFLAG_RD
, &sc
->rx_packets
, 0,
5692 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5693 "rx_ampdu", CTLFLAG_RD
, &sc
->rx_ampdu
, 0,
5696 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5697 "rx_amsdu", CTLFLAG_RD
, &sc
->rx_amsdu
, 0,
5700 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5701 "rx_crc_errors", CTLFLAG_RD
, &sc
->rx_crc_errors
, 0,
5704 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5705 "rx_phy_errors", CTLFLAG_RD
, &sc
->rx_phy_errors
, 0,
5708 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5709 "rx_false_ccas", CTLFLAG_RD
, &sc
->rx_false_ccas
, 0,
5712 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5713 "rx_plcp_errors", CTLFLAG_RD
, &sc
->rx_plcp_errors
, 0,
5716 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5717 "rx_dup_packets", CTLFLAG_RD
, &sc
->rx_dup_packets
, 0,
5718 "Rx duplicate packets");
5720 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5721 "rx_fifo_overflows", CTLFLAG_RD
, &sc
->rx_fifo_overflows
, 0,
5722 "Rx FIFO overflows");
5725 static device_method_t rt2870_dev_methods
[] =
5727 DEVMETHOD(device_probe
, rt2870_probe
),
5728 DEVMETHOD(device_attach
, rt2870_attach
),
5729 DEVMETHOD(device_detach
, rt2870_detach
),
5733 static driver_t rt2870_driver
=
5737 sizeof(struct rt2870_softc
),
5740 static devclass_t rt2870_dev_class
;
5742 DRIVER_MODULE(rt2870
, uhub
, rt2870_driver
, rt2870_dev_class
,
5745 MODULE_DEPEND(rt2870
, usb
, 1, 1, 1);
5746 MODULE_DEPEND(rt2870
, wlan
, 1, 1, 1);