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
,
1745 RT2870_AMRR_MIN_SUCCESS_THRESHOLD
,
1746 RT2870_AMRR_MAX_SUCCESS_THRESHOLD
,
1749 ieee80211_vap_attach(vap
, ieee80211_media_change
, ieee80211_media_status
);
1751 ic
->ic_opmode
= opmode
;
1759 static void rt2870_vap_delete(struct ieee80211vap
*vap
)
1761 struct rt2870_softc
*sc
;
1762 struct ieee80211com
*ic
;
1764 struct rt2870_softc_vap
*rvap
;
1769 rvap
= (struct rt2870_softc_vap
*) vap
;
1771 RT2870_DPRINTF(sc
, RT2870_DEBUG_STATE
,
1772 "%s: VAP delete: opmode=%s\n",
1773 device_get_nameunit(sc
->dev
),
1774 ieee80211_opmode_name
[vap
->iv_opmode
]);
1776 rt2870_amrr_cleanup(&rvap
->amrr
);
1778 ieee80211_vap_detach(vap
);
1780 free(rvap
, M_80211_VAP
);
1786 static int rt2870_vap_reset(struct ieee80211vap
*vap
, u_long cmd
)
1788 struct rt2870_softc
*sc
;
1789 struct ieee80211com
*ic
;
1791 struct rt2870_softc_vap
*rvap
;
1797 rvap
= (struct rt2870_softc_vap
*) vap
;
1799 RT2870_DPRINTF(sc
, RT2870_DEBUG_STATE
,
1800 "%s: VAP reset: cmd=%lu\n",
1801 device_get_nameunit(sc
->dev
), cmd
);
1805 RT2870_SOFTC_LOCK(sc
);
1809 case IEEE80211_IOC_RTSTHRESHOLD
:
1810 rt2870_asic_update_rtsthreshold(sc
);
1813 case IEEE80211_IOC_PROTMODE
:
1814 case IEEE80211_IOC_HTPROTMODE
:
1815 rt2870_asic_updateprot(sc
);
1818 case IEEE80211_IOC_TXPOWER
:
1819 rt2870_asic_update_txpower(sc
);
1822 case IEEE80211_IOC_SHORTGI
:
1823 case IEEE80211_IOC_AMPDU_DENSITY
:
1831 RT2870_SOFTC_UNLOCK(sc
);
1837 * rt2870_vap_newstate
1839 static int rt2870_vap_newstate(struct ieee80211vap
*vap
,
1840 enum ieee80211_state nstate
, int arg
)
1842 struct rt2870_softc
*sc
;
1843 struct ieee80211com
*ic
;
1845 struct rt2870_softc_vap
*rvap
;
1846 struct ieee80211_node
*ni
;
1852 rvap
= (struct rt2870_softc_vap
*) vap
;
1854 RT2870_DPRINTF(sc
, RT2870_DEBUG_STATE
,
1855 "%s: VAP newstate: %s -> %s\n",
1856 device_get_nameunit(sc
->dev
),
1857 ieee80211_state_name
[vap
->iv_state
], ieee80211_state_name
[nstate
]);
1859 error
= rvap
->newstate(vap
, nstate
, arg
);
1863 IEEE80211_UNLOCK(ic
);
1865 RT2870_SOFTC_LOCK(sc
);
1867 /* turn link LED off */
1869 if (nstate
!= IEEE80211_S_RUN
)
1870 rt2870_led_cmd(sc
, RT2870_LED_CMD_RADIO_OFF
);
1874 case IEEE80211_S_INIT
:
1875 rt2870_asic_disable_tsf_sync(sc
);
1878 case IEEE80211_S_RUN
:
1881 rt2870_rf_set_chan(sc
, ni
->ni_chan
);
1883 if (vap
->iv_opmode
!= IEEE80211_M_MONITOR
)
1885 rt2870_asic_enable_mrr(sc
);
1886 rt2870_asic_set_txpreamble(sc
);
1887 rt2870_asic_set_basicrates(sc
);
1888 rt2870_asic_update_txpower(sc
);
1889 rt2870_asic_set_bssid(sc
, ni
->ni_bssid
);
1892 if (vap
->iv_opmode
== IEEE80211_M_HOSTAP
||
1893 vap
->iv_opmode
== IEEE80211_M_IBSS
||
1894 vap
->iv_opmode
== IEEE80211_M_MBSS
)
1896 error
= rt2870_asic_update_beacon(sc
, vap
);
1901 if (vap
->iv_opmode
!= IEEE80211_M_MONITOR
)
1902 rt2870_asic_enable_tsf_sync(sc
);
1904 /* turn link LED on */
1906 if (vap
->iv_opmode
!= IEEE80211_M_MONITOR
)
1908 rt2870_led_cmd(sc
, RT2870_LED_CMD_RADIO_ON
|
1909 (IEEE80211_IS_CHAN_2GHZ(ni
->ni_chan
) ?
1910 RT2870_LED_CMD_LINK_2GHZ
: RT2870_LED_CMD_LINK_5GHZ
));
1918 RT2870_SOFTC_UNLOCK(sc
);
1926 * rt2870_vap_key_update_begin
1928 static void rt2870_vap_key_update_begin(struct ieee80211vap
*vap
)
1930 struct rt2870_softc
*sc
;
1931 struct ieee80211com
*ic
;
1938 RT2870_DPRINTF(sc
, RT2870_DEBUG_KEY
,
1939 "%s: VAP key update begin\n",
1940 device_get_nameunit(sc
->dev
));
1942 taskqueue_block(sc
->taskqueue
);
1944 IF_LOCK(&ifp
->if_snd
);
1948 * rt2870_vap_key_update_end
1950 static void rt2870_vap_key_update_end(struct ieee80211vap
*vap
)
1952 struct rt2870_softc
*sc
;
1953 struct ieee80211com
*ic
;
1960 RT2870_DPRINTF(sc
, RT2870_DEBUG_KEY
,
1961 "%s: VAP key update end\n",
1962 device_get_nameunit(sc
->dev
));
1964 IF_UNLOCK(&ifp
->if_snd
);
1966 taskqueue_unblock(sc
->taskqueue
);
1970 * rt2870_vap_key_set
1972 static int rt2870_vap_key_set(struct ieee80211vap
*vap
,
1973 const struct ieee80211_key
*k
, const uint8_t mac
[IEEE80211_ADDR_LEN
])
1975 struct rt2870_softc
*sc
;
1976 struct ieee80211com
*ic
;
1978 struct ieee80211_node
*ni
;
1979 uint16_t associd
, key_base
, keymode_base
;
1980 uint8_t mode
, vapid
, wcid
, iv
[8];
1983 if (k
->wk_cipher
->ic_cipher
!= IEEE80211_CIPHER_WEP
&&
1984 k
->wk_cipher
->ic_cipher
!= IEEE80211_CIPHER_TKIP
&&
1985 k
->wk_cipher
->ic_cipher
!= IEEE80211_CIPHER_AES_CCM
)
1992 if (vap
->iv_opmode
!= IEEE80211_M_HOSTAP
)
1995 ni
= ieee80211_find_vap_node(&ic
->ic_sta
, vap
, mac
);
1997 associd
= (ni
!= NULL
) ? ni
->ni_associd
: 0;
1999 if ((vap
->iv_opmode
== IEEE80211_M_HOSTAP
) && (ni
!= NULL
))
2000 ieee80211_free_node(ni
);
2002 switch (k
->wk_cipher
->ic_cipher
)
2004 case IEEE80211_CIPHER_WEP
:
2005 if(k
->wk_keylen
< 8)
2006 mode
= RT2870_REG_CIPHER_MODE_WEP40
;
2008 mode
= RT2870_REG_CIPHER_MODE_WEP104
;
2011 case IEEE80211_CIPHER_TKIP
:
2012 mode
= RT2870_REG_CIPHER_MODE_TKIP
;
2015 case IEEE80211_CIPHER_AES_CCM
:
2016 mode
= RT2870_REG_CIPHER_MODE_AES_CCMP
;
2023 RT2870_DPRINTF(sc
, RT2870_DEBUG_KEY
,
2024 "%s: VAP key set: keyix=%d, keylen=%d, associd=0x%04x, mode=%d, group=%d\n",
2025 device_get_nameunit(sc
->dev
), k
->wk_keyix
, k
->wk_keylen
, associd
, mode
,
2026 (k
->wk_flags
& IEEE80211_KEY_GROUP
) ? 1 : 0);
2028 RT2870_SOFTC_LOCK(sc
);
2030 if (!(k
->wk_flags
& IEEE80211_KEY_GROUP
))
2032 /* install pairwise key */
2035 wcid
= RT2870_AID2WCID(associd
);
2036 key_base
= RT2870_REG_PKEY(wcid
);
2038 if (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_WEP
)
2042 iv
[3] = (k
->wk_keyix
<< 6);
2046 if (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_TKIP
)
2048 iv
[0] = (k
->wk_keytsc
>> 8);
2049 iv
[1] = ((iv
[0] | 0x20) & 0x7f);
2050 iv
[2] = k
->wk_keytsc
;
2056 iv
[0] = k
->wk_keytsc
;
2057 iv
[1] = k
->wk_keytsc
>> 8;
2061 iv
[3] = ((k
->wk_keyix
<< 6) | IEEE80211_WEP_EXTIV
);
2062 iv
[4] = (k
->wk_keytsc
>> 16);
2063 iv
[5] = (k
->wk_keytsc
>> 24);
2064 iv
[6] = (k
->wk_keytsc
>> 32);
2065 iv
[7] = (k
->wk_keytsc
>> 40);
2067 RT2870_DPRINTF(sc
, RT2870_DEBUG_KEY
,
2068 "%s: set key: iv=%02x %02x %02x %02x %02x %02x %02x %02x\n",
2069 device_get_nameunit(sc
->dev
),
2070 iv
[0], iv
[1], iv
[2], iv
[3], iv
[4], iv
[5], iv
[6], iv
[7]);
2073 rt2870_io_mac_write_multi(sc
, RT2870_REG_IVEIV(wcid
), iv
, 8);
2075 if (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_TKIP
)
2077 rt2870_io_mac_write_multi(sc
, key_base
, k
->wk_key
, 16);
2079 if (vap
->iv_opmode
!= IEEE80211_M_HOSTAP
)
2081 rt2870_io_mac_write_multi(sc
, key_base
+ 16, &k
->wk_key
[16], 8);
2082 rt2870_io_mac_write_multi(sc
, key_base
+ 24, &k
->wk_key
[24], 8);
2086 rt2870_io_mac_write_multi(sc
, key_base
+ 16, &k
->wk_key
[24], 8);
2087 rt2870_io_mac_write_multi(sc
, key_base
+ 24, &k
->wk_key
[16], 8);
2092 rt2870_io_mac_write_multi(sc
, key_base
, k
->wk_key
, k
->wk_keylen
);
2095 tmp
= ((vapid
& RT2870_REG_VAP_MASK
) << RT2870_REG_VAP_SHIFT
) |
2096 (mode
<< RT2870_REG_CIPHER_MODE_SHIFT
) | RT2870_REG_PKEY_ENABLE
;
2098 rt2870_io_mac_write(sc
, RT2870_REG_WCID_ATTR(wcid
), tmp
);
2101 if ((k
->wk_flags
& IEEE80211_KEY_GROUP
) ||
2102 (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_WEP
))
2104 /* install group key */
2107 key_base
= RT2870_REG_SKEY(vapid
, k
->wk_keyix
);
2108 keymode_base
= RT2870_REG_SKEY_MODE(vapid
);
2110 if (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_TKIP
)
2112 rt2870_io_mac_write_multi(sc
, key_base
, k
->wk_key
, 16);
2114 if (vap
->iv_opmode
!= IEEE80211_M_HOSTAP
)
2116 rt2870_io_mac_write_multi(sc
, key_base
+ 16, &k
->wk_key
[16], 8);
2117 rt2870_io_mac_write_multi(sc
, key_base
+ 24, &k
->wk_key
[24], 8);
2121 rt2870_io_mac_write_multi(sc
, key_base
+ 16, &k
->wk_key
[24], 8);
2122 rt2870_io_mac_write_multi(sc
, key_base
+ 24, &k
->wk_key
[16], 8);
2127 rt2870_io_mac_write_multi(sc
, key_base
, k
->wk_key
, k
->wk_keylen
);
2130 tmp
= rt2870_io_mac_read(sc
, keymode_base
);
2132 tmp
&= ~(0xf << (k
->wk_keyix
* 4 + 16 * (vapid
% 2)));
2133 tmp
|= (mode
<< (k
->wk_keyix
* 4 + 16 * (vapid
% 2)));
2135 rt2870_io_mac_write(sc
, keymode_base
, tmp
);
2138 RT2870_SOFTC_UNLOCK(sc
);
2144 * rt2870_vap_key_delete
2146 static int rt2870_vap_key_delete(struct ieee80211vap
*vap
,
2147 const struct ieee80211_key
*k
)
2149 struct rt2870_softc
*sc
;
2150 struct ieee80211com
*ic
;
2152 struct ieee80211_node
*ni
;
2153 struct rt2870_cmd_argv_keydelete cmd_argv
;
2160 associd
= (ni
!= NULL
) ? ni
->ni_associd
: 0;
2162 RT2870_DPRINTF(sc
, RT2870_DEBUG_KEY
,
2163 "%s: VAP key delete: keyix=%d, keylen=%d, associd=0x%04x, group=%d\n",
2164 device_get_nameunit(sc
->dev
), k
->wk_keyix
, k
->wk_keylen
, associd
,
2165 (k
->wk_flags
& IEEE80211_KEY_GROUP
) ? 1 : 0);
2167 memcpy(&cmd_argv
.key
, k
, sizeof(struct ieee80211_key
));
2168 cmd_argv
.associd
= associd
;
2170 rt2870_do_async(sc
, rt2870_vap_key_delete_cb
,
2171 &cmd_argv
, sizeof(struct rt2870_cmd_argv_keydelete
));
2177 * rt2870_vap_update_beacon
2179 static void rt2870_vap_update_beacon(struct ieee80211vap
*vap
, int what
)
2181 struct rt2870_softc
*sc
;
2182 struct ieee80211com
*ic
;
2189 RT2870_DPRINTF(sc
, RT2870_DEBUG_BEACON
,
2190 "%s: VAP update beacon\n",
2191 device_get_nameunit(sc
->dev
));
2193 rt2870_do_async(sc
, rt2870_vap_update_beacon_cb
, NULL
, 0);
2199 static struct ieee80211_node
*rt2870_node_alloc(struct ieee80211vap
*vap
,
2200 const uint8_t mac
[IEEE80211_ADDR_LEN
])
2202 return malloc(sizeof(struct rt2870_softc_node
),
2203 M_80211_NODE
, M_NOWAIT
| M_ZERO
);
2207 * rt2870_setregdomain
2209 static int rt2870_setregdomain(struct ieee80211com
*ic
,
2210 struct ieee80211_regdomain
*reg
,
2211 int nchans
, struct ieee80211_channel chans
[])
2213 struct rt2870_softc
*sc
;
2219 RT2870_DPRINTF(sc
, RT2870_DEBUG_STATE
,
2220 "%s: set regulatory domain: country=%d, country code string=%c%c, location=%c\n",
2221 device_get_nameunit(sc
->dev
),
2222 reg
->country
, reg
->isocc
[0], reg
->isocc
[1], reg
->location
);
2228 * rt2870_getradiocaps
2230 static void rt2870_getradiocaps(struct ieee80211com
*ic
,
2231 int maxchans
, int *nchans
, struct ieee80211_channel chans
[])
2233 *nchans
= (ic
->ic_nchans
>= maxchans
) ? maxchans
: ic
->ic_nchans
;
2235 memcpy(chans
, ic
->ic_channels
, (*nchans
) * sizeof(struct ieee80211_channel
));
2241 static void rt2870_scan_start(struct ieee80211com
*ic
)
2243 struct rt2870_softc
*sc
;
2249 RT2870_SOFTC_LOCK(sc
);
2251 rt2870_asic_disable_tsf_sync(sc
);
2253 RT2870_SOFTC_UNLOCK(sc
);
2259 static void rt2870_scan_end(struct ieee80211com
*ic
)
2261 struct rt2870_softc
*sc
;
2267 RT2870_SOFTC_LOCK(sc
);
2269 rt2870_asic_enable_tsf_sync(sc
);
2271 RT2870_SOFTC_UNLOCK(sc
);
2275 * rt2870_set_channel
2277 static void rt2870_set_channel(struct ieee80211com
*ic
)
2279 struct rt2870_softc
*sc
;
2285 RT2870_DPRINTF(sc
, RT2870_DEBUG_CHAN
,
2286 "%s: set channel: channel=%u, HT%s%s\n",
2287 device_get_nameunit(sc
->dev
),
2288 ieee80211_chan2ieee(ic
, ic
->ic_curchan
),
2289 !IEEE80211_IS_CHAN_HT(ic
->ic_curchan
) ? " disabled" :
2290 IEEE80211_IS_CHAN_HT20(ic
->ic_curchan
) ? "20":
2291 IEEE80211_IS_CHAN_HT40U(ic
->ic_curchan
) ? "40U" : "40D",
2292 (ic
->ic_flags
& IEEE80211_F_SCAN
) ? ", scanning" : "");
2294 RT2870_SOFTC_LOCK(sc
);
2296 rt2870_rf_set_chan(sc
, ic
->ic_curchan
);
2298 RT2870_SOFTC_UNLOCK(sc
);
2304 static void rt2870_newassoc(struct ieee80211_node
*ni
, int isnew
)
2306 struct rt2870_softc
*sc
;
2307 struct ieee80211com
*ic
;
2309 struct ieee80211vap
*vap
;
2310 struct rt2870_softc_vap
*rvap
;
2318 rvap
= (struct rt2870_softc_vap
*) vap
;
2320 associd
= (ni
!= NULL
) ? ni
->ni_associd
: 0;
2321 wcid
= RT2870_AID2WCID(associd
);
2323 RT2870_DPRINTF(sc
, RT2870_DEBUG_NODE
,
2324 "%s: new association: wcid=0x%02x, "
2325 "mac addr=%s, QoS %s, ERP %s, HT %s\n",
2326 device_get_nameunit(sc
->dev
), wcid
,
2327 ether_sprintf(ni
->ni_macaddr
),
2328 (ni
->ni_flags
& IEEE80211_NODE_QOS
) ? "enabled" : "disabled",
2329 (ni
->ni_flags
& IEEE80211_NODE_ERP
) ? "enabled" : "disabled",
2330 (ni
->ni_flags
& IEEE80211_NODE_HT
) ? "enabled" : "disabled");
2332 RT2870_SOFTC_LOCK(sc
);
2334 rt2870_io_mac_write_multi(sc
, RT2870_REG_WCID(wcid
),
2335 ni
->ni_macaddr
, IEEE80211_ADDR_LEN
);
2337 rt2870_amrr_node_init(&rvap
->amrr
, &sc
->amrr_node
[wcid
], ni
);
2339 RT2870_DPRINTF(sc
, RT2870_DEBUG_RATE
,
2340 "%s: initial%s node Tx rate: associd=0x%04x, rate=0x%02x, max rate=0x%02x\n",
2341 device_get_nameunit(sc
->dev
),
2342 (ni
->ni_flags
& IEEE80211_NODE_HT
) ? " HT" : "",
2343 ni
->ni_associd
, ni
->ni_txrate
,
2344 (ni
->ni_flags
& IEEE80211_NODE_HT
) ?
2345 (ni
->ni_htrates
.rs_rates
[ni
->ni_htrates
.rs_nrates
- 1] | IEEE80211_RATE_MCS
) :
2346 (ni
->ni_rates
.rs_rates
[ni
->ni_rates
.rs_nrates
- 1] & IEEE80211_RATE_VAL
));
2348 rt2870_asic_updateprot(sc
);
2349 rt2870_asic_updateslot(sc
);
2350 rt2870_asic_set_txpreamble(sc
);
2352 RT2870_SOFTC_UNLOCK(sc
);
2358 static void rt2870_updateslot(struct ifnet
*ifp
)
2360 struct rt2870_softc
*sc
;
2364 rt2870_do_async(sc
, rt2870_updateslot_cb
, NULL
, 0);
2368 * rt2870_update_promisc
2370 static void rt2870_update_promisc(struct ifnet
*ifp
)
2372 struct rt2870_softc
*sc
;
2376 RT2870_SOFTC_LOCK(sc
);
2378 rt2870_asic_update_promisc(sc
);
2380 RT2870_SOFTC_UNLOCK(sc
);
2384 * rt2870_update_mcast
2386 static void rt2870_update_mcast(struct ifnet
*ifp
)
2388 struct rt2870_softc
*sc
;
2396 static int rt2870_wme_update(struct ieee80211com
*ic
)
2398 struct rt2870_softc
*sc
;
2404 rt2870_do_async(sc
, rt2870_wme_update_cb
, NULL
, 0);
2412 static int rt2870_raw_xmit(struct ieee80211_node
*ni
, struct mbuf
*m
,
2413 const struct ieee80211_bpf_params
*params
)
2415 struct rt2870_softc
*sc
;
2416 struct ieee80211com
*ic
;
2423 RT2870_SOFTC_LOCK(sc
);
2425 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
2427 RT2870_SOFTC_UNLOCK(sc
);
2430 ieee80211_free_node(ni
);
2435 if (sc
->tx_ring
[sc
->tx_ring_mgtqid
].queued
>= RT2870_SOFTC_TX_RING_DATA_COUNT
)
2437 RT2870_DPRINTF(sc
, RT2870_DEBUG_TX
,
2438 "%s: raw xmit: Tx ring with qid=%d is full\n",
2439 device_get_nameunit(sc
->dev
), sc
->tx_ring_mgtqid
);
2441 ifp
->if_drv_flags
|= IFF_DRV_OACTIVE
;
2443 RT2870_SOFTC_UNLOCK(sc
);
2446 ieee80211_free_node(ni
);
2448 sc
->tx_data_queue_full
[sc
->tx_ring_mgtqid
]++;
2453 if (rt2870_tx_mgmt(sc
, m
, ni
, sc
->tx_ring_mgtqid
) != 0)
2457 RT2870_SOFTC_UNLOCK(sc
);
2459 ieee80211_free_node(ni
);
2464 sc
->tx_timer
= RT2870_TX_WATCHDOG_TIMEOUT
;
2466 RT2870_SOFTC_UNLOCK(sc
);
2472 * rt2870_recv_action
2474 static int rt2870_recv_action(struct ieee80211_node
*ni
,
2475 const struct ieee80211_frame
*wh
,
2476 const uint8_t *frm
, const uint8_t *efrm
)
2478 struct rt2870_softc
*sc
;
2479 struct ieee80211com
*ic
;
2481 const struct ieee80211_action
*ia
;
2482 uint16_t associd
, status
, baparamset
;
2484 int ret
, tid
, bufsize
;
2491 ia
= (const struct ieee80211_action
*) frm
;
2493 ret
= sc
->recv_action(ni
, wh
, frm
, efrm
);
2495 if (ia
->ia_category
!= IEEE80211_ACTION_CAT_BA
)
2498 associd
= (ni
!= NULL
) ? ni
->ni_associd
: 0;
2499 wcid
= RT2870_AID2WCID(associd
);
2501 switch (ia
->ia_action
)
2503 /* IEEE80211_ACTION_BA_ADDBA_REQUEST */
2504 case IEEE80211_ACTION_BA_ADDBA_REQUEST
:
2505 baparamset
= LE_READ_2(frm
+ 3);
2506 tid
= RT2870_MS(baparamset
, IEEE80211_BAPS_TID
);
2507 bufsize
= RT2870_MS(baparamset
, IEEE80211_BAPS_BUFSIZ
);
2509 RT2870_DPRINTF(sc
, RT2870_DEBUG_BA
,
2510 "%s: received ADDBA request: associd=0x%04x, tid=%d, bufsize=%d\n",
2511 device_get_nameunit(sc
->dev
), associd
, tid
, bufsize
);
2513 RT2870_SOFTC_LOCK(sc
);
2515 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_WCID(wcid
) + 4);
2517 tmp
|= (0x10000 << tid
);
2519 rt2870_io_mac_write(sc
, RT2870_REG_WCID(wcid
) + 4, tmp
);
2521 RT2870_SOFTC_UNLOCK(sc
);
2524 /* IEEE80211_ACTION_BA_ADDBA_RESPONSE */
2525 case IEEE80211_ACTION_BA_ADDBA_RESPONSE
:
2526 status
= LE_READ_2(frm
+ 3);
2527 baparamset
= LE_READ_2(frm
+ 4);
2528 tid
= RT2870_MS(baparamset
, IEEE80211_BAPS_TID
);
2529 bufsize
= RT2870_MS(baparamset
, IEEE80211_BAPS_BUFSIZ
);
2531 RT2870_DPRINTF(sc
, RT2870_DEBUG_BA
,
2532 "%s: received ADDBA response: associd=0x%04x, status=%d, tid=%d, bufsize=%d\n",
2533 device_get_nameunit(sc
->dev
), associd
, status
, tid
, bufsize
);
2535 if (status
== IEEE80211_STATUS_SUCCESS
)
2537 sc
->tx_ampdu_sessions
++;
2539 RT2870_SOFTC_LOCK(sc
);
2541 rt2870_asic_updateprot(sc
);
2543 RT2870_SOFTC_UNLOCK(sc
);
2547 /* IEEE80211_ACTION_BA_DELBA */
2548 case IEEE80211_ACTION_BA_DELBA
:
2549 baparamset
= LE_READ_2(frm
+ 2);
2550 tid
= RT2870_MS(baparamset
, IEEE80211_BAPS_TID
);
2552 RT2870_DPRINTF(sc
, RT2870_DEBUG_BA
,
2553 "%s: received DELBA request: associd=0x%04x, tid=%d\n",
2554 device_get_nameunit(sc
->dev
), associd
, tid
);
2556 RT2870_SOFTC_LOCK(sc
);
2558 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_WCID(wcid
) + 4);
2560 tmp
&= ~(0x10000 << tid
);
2562 rt2870_io_mac_write(sc
, RT2870_REG_WCID(wcid
) + 4, tmp
);
2564 RT2870_SOFTC_UNLOCK(sc
);
2572 * rt2870_send_action
2574 static int rt2870_send_action(struct ieee80211_node
*ni
,
2575 int cat
, int act
, void *sa
)
2577 struct rt2870_softc
*sc
;
2578 struct ieee80211com
*ic
;
2580 uint16_t associd
, *args
, baparamset
;
2589 ret
= sc
->send_action(ni
, cat
, act
, sa
);
2591 if (cat
!= IEEE80211_ACTION_CAT_BA
)
2594 associd
= (ni
!= NULL
) ? ni
->ni_associd
: 0;
2595 wcid
= RT2870_AID2WCID(associd
);
2600 /* IEEE80211_ACTION_BA_DELBA */
2601 case IEEE80211_ACTION_BA_DELBA
:
2602 baparamset
= RT2870_SM(args
[0], IEEE80211_DELBAPS_TID
) | args
[1];
2604 tid
= RT2870_MS(baparamset
, IEEE80211_DELBAPS_TID
);
2606 RT2870_DPRINTF(sc
, RT2870_DEBUG_BA
,
2607 "%s: sending DELBA request: associd=0x%04x, tid=%d\n",
2608 device_get_nameunit(sc
->dev
), associd
, tid
);
2610 RT2870_SOFTC_LOCK(sc
);
2612 if (RT2870_MS(baparamset
, IEEE80211_DELBAPS_INIT
) != IEEE80211_DELBAPS_INIT
)
2614 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_WCID(wcid
) + 4);
2616 tmp
&= ~(0x10000 << tid
);
2618 rt2870_io_mac_write(sc
, RT2870_REG_WCID(wcid
) + 4, tmp
);
2622 sc
->tx_ampdu_sessions
--;
2624 rt2870_asic_updateprot(sc
);
2627 RT2870_SOFTC_UNLOCK(sc
);
2635 * rt2870_amrr_update_iter_func
2637 static void rt2870_amrr_update_iter_func(void *arg
, struct ieee80211_node
*ni
)
2639 struct rt2870_softc
*sc
;
2640 struct ieee80211com
*ic
;
2642 struct ieee80211vap
*vap
;
2643 struct rt2870_softc_vap
*rvap
;
2650 rvap
= (struct rt2870_softc_vap
*) vap
;
2652 /* only associated stations */
2654 if ((ni
->ni_vap
== vap
) && (ni
->ni_associd
!= 0))
2656 wcid
= RT2870_AID2WCID(ni
->ni_associd
);
2658 RT2870_DPRINTF(sc
, RT2870_DEBUG_RATE
,
2659 "%s: AMRR node: wcid=0x%02x, txcnt=%d, success=%d, retrycnt=%d\n",
2660 device_get_nameunit(sc
->dev
),
2661 wcid
, sc
->amrr_node
[wcid
].txcnt
, sc
->amrr_node
[wcid
].success
, sc
->amrr_node
[wcid
].retrycnt
);
2663 rt2870_amrr_choose(ni
, &sc
->amrr_node
[wcid
]);
2665 RT2870_DPRINTF(sc
, RT2870_DEBUG_RATE
,
2666 "%s:%s node Tx rate: associd=0x%04x, rate=0x%02x, max rate=0x%02x\n",
2667 device_get_nameunit(sc
->dev
),
2668 (ni
->ni_flags
& IEEE80211_NODE_HT
) ? " HT" : "",
2669 ni
->ni_associd
, ni
->ni_txrate
,
2670 (ni
->ni_flags
& IEEE80211_NODE_HT
) ?
2671 (ni
->ni_htrates
.rs_rates
[ni
->ni_htrates
.rs_nrates
- 1] | IEEE80211_RATE_MCS
) :
2672 (ni
->ni_rates
.rs_rates
[ni
->ni_rates
.rs_nrates
- 1] & IEEE80211_RATE_VAL
));
2679 static void rt2870_periodic(void *arg
)
2681 struct rt2870_softc
*sc
;
2687 RT2870_DPRINTF(sc
, RT2870_DEBUG_PERIODIC
,
2689 device_get_nameunit(sc
->dev
));
2691 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
2694 taskqueue_enqueue(sc
->taskqueue
, &sc
->periodic_task
);
2698 * rt2870_tx_watchdog
2700 static void rt2870_tx_watchdog(void *arg
)
2702 struct rt2870_softc
*sc
;
2708 if (sc
->tx_timer
== 0)
2711 if (--sc
->tx_timer
== 0)
2713 printf("%s: Tx watchdog timeout: resetting\n",
2714 device_get_nameunit(sc
->dev
));
2716 rt2870_stop_locked(sc
);
2717 rt2870_init_locked(sc
);
2721 sc
->tx_watchdog_timeouts
++;
2724 callout_reset(&sc
->tx_watchdog_ch
, hz
, rt2870_tx_watchdog
, sc
);
2730 static int rt2870_do_async(struct rt2870_softc
*sc
,
2731 void (*cb
)(struct rt2870_softc
*sc
, void *arg
),
2735 struct rt2870_softc_cmd_ring
*ring
;
2736 struct rt2870_softc_cmd
*cmd
;
2740 ring
= &sc
->cmd_ring
;
2742 RT2870_SOFTC_LOCK(sc
);
2744 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
2746 RT2870_SOFTC_UNLOCK(sc
);
2750 if (ring
->queued
>= RT2870_SOFTC_CMD_RING_CMD_COUNT
)
2752 RT2870_SOFTC_UNLOCK(sc
);
2756 cmd
= STAILQ_FIRST(&ring
->inactive
);
2757 STAILQ_REMOVE_HEAD(&ring
->inactive
, next
);
2762 memcpy(cmd
->data
, arg
, len
);
2764 STAILQ_INSERT_TAIL(&ring
->active
, cmd
, next
);
2767 run_cmd_task
= (ring
->queued
== 1);
2769 RT2870_SOFTC_UNLOCK(sc
);
2772 taskqueue_enqueue(sc
->taskqueue
, &sc
->cmd_task
);
2778 * rt2870_updateslot_cb
2780 static void rt2870_updateslot_cb(struct rt2870_softc
*sc
, void *arg
)
2782 RT2870_SOFTC_LOCK(sc
);
2784 rt2870_asic_updateslot(sc
);
2786 RT2870_SOFTC_UNLOCK(sc
);
2790 * rt2870_wme_update_cb
2792 static void rt2870_wme_update_cb(struct rt2870_softc
*sc
, void *arg
)
2794 RT2870_SOFTC_LOCK(sc
);
2796 rt2870_asic_wme_update(sc
);
2798 RT2870_SOFTC_UNLOCK(sc
);
2802 * rt2870_vap_key_delete_cb
2804 static void rt2870_vap_key_delete_cb(struct rt2870_softc
*sc
, void *arg
)
2806 struct ieee80211_key
*k
;
2807 struct rt2870_cmd_argv_keydelete
*cmd_argv
;
2809 uint8_t vapid
, wcid
;
2814 associd
= cmd_argv
->associd
;
2816 RT2870_SOFTC_LOCK(sc
);
2818 if (!(k
->wk_flags
& IEEE80211_KEY_GROUP
))
2820 /* remove pairwise key */
2823 wcid
= RT2870_AID2WCID(associd
);
2825 tmp
= ((vapid
& RT2870_REG_VAP_MASK
) << RT2870_REG_VAP_SHIFT
) |
2826 (RT2870_REG_CIPHER_MODE_NONE
<< RT2870_REG_CIPHER_MODE_SHIFT
) | RT2870_REG_PKEY_ENABLE
;
2828 rt2870_io_mac_write(sc
, RT2870_REG_WCID_ATTR(wcid
), tmp
);
2832 /* remove group key */
2836 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_SKEY_MODE(vapid
));
2838 tmp
&= ~(0xf << (k
->wk_keyix
* 4 + 16 * (vapid
% 2)));
2839 tmp
|= (RT2870_REG_CIPHER_MODE_NONE
<< (k
->wk_keyix
* 4 + 16 * (vapid
% 2)));
2841 rt2870_io_mac_write(sc
, RT2870_REG_SKEY_MODE(vapid
), tmp
);
2844 RT2870_SOFTC_UNLOCK(sc
);
2848 * rt2870_vap_update_beacon_cb
2850 static void rt2870_vap_update_beacon_cb(struct rt2870_softc
*sc
, void *arg
)
2853 struct ieee80211com
*ic
;
2854 struct ieee80211vap
*vap
;
2858 vap
= TAILQ_FIRST(&ic
->ic_vaps
);
2863 RT2870_SOFTC_LOCK(sc
);
2865 rt2870_asic_update_beacon(sc
, vap
);
2867 RT2870_SOFTC_UNLOCK(sc
);
2871 * rt2870_asic_set_bssid
2873 static void rt2870_asic_set_bssid(struct rt2870_softc
*sc
,
2874 const uint8_t *bssid
)
2878 RT2870_DPRINTF(sc
, RT2870_DEBUG_STATE
,
2879 "%s: set bssid: bssid=%s\n",
2880 device_get_nameunit(sc
->dev
),
2881 ether_sprintf(bssid
));
2883 tmp
= bssid
[0] | (bssid
[1]) << 8 | (bssid
[2] << 16) | (bssid
[3] << 24);
2885 rt2870_io_mac_write(sc
, RT2870_REG_BSSID_DW0
, tmp
);
2887 tmp
= bssid
[4] | (bssid
[5] << 8);
2889 rt2870_io_mac_write(sc
, RT2870_REG_BSSID_DW1
, tmp
);
2893 * rt2870_asic_set_macaddr
2895 static void rt2870_asic_set_macaddr(struct rt2870_softc
*sc
,
2896 const uint8_t *addr
)
2900 tmp
= addr
[0] | (addr
[1] << 8) | (addr
[2] << 16) | (addr
[3] << 24);
2902 rt2870_io_mac_write(sc
, RT2870_REG_ADDR_DW0
, tmp
);
2904 tmp
= addr
[4] | (addr
[5] << 8);
2906 rt2870_io_mac_write(sc
, RT2870_REG_ADDR_DW1
, tmp
);
2910 * rt2870_asic_enable_tsf_sync
2912 static void rt2870_asic_enable_tsf_sync(struct rt2870_softc
*sc
)
2915 struct ieee80211com
*ic
;
2916 struct ieee80211vap
*vap
;
2921 vap
= TAILQ_FIRST(&ic
->ic_vaps
);
2923 RT2870_DPRINTF(sc
, RT2870_DEBUG_BEACON
,
2924 "%s: enabling TSF\n",
2925 device_get_nameunit(sc
->dev
));
2927 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_BCN_TIME_CFG
);
2930 tmp
|= vap
->iv_bss
->ni_intval
* 16;
2931 tmp
|= (RT2870_REG_TSF_TIMER_ENABLE
| RT2870_REG_TBTT_TIMER_ENABLE
);
2933 if (vap
->iv_opmode
== IEEE80211_M_STA
)
2935 tmp
|= (RT2870_REG_TSF_SYNC_MODE_STA
<< RT2870_REG_TSF_SYNC_MODE_SHIFT
);
2937 else if (vap
->iv_opmode
== IEEE80211_M_IBSS
)
2939 tmp
|= RT2870_REG_BCN_TX_ENABLE
;
2940 tmp
|= (RT2870_REG_TSF_SYNC_MODE_IBSS
<< RT2870_REG_TSF_SYNC_MODE_SHIFT
);
2942 else if (vap
->iv_opmode
== IEEE80211_M_HOSTAP
)
2944 tmp
|= RT2870_REG_BCN_TX_ENABLE
;
2945 tmp
|= (RT2870_REG_TSF_SYNC_MODE_HOSTAP
<< RT2870_REG_TSF_SYNC_MODE_SHIFT
);
2948 rt2870_io_mac_write(sc
, RT2870_REG_BCN_TIME_CFG
, tmp
);
2952 * rt2870_asic_disable_tsf_sync
2954 static void rt2870_asic_disable_tsf_sync(struct rt2870_softc
*sc
)
2958 RT2870_DPRINTF(sc
, RT2870_DEBUG_BEACON
,
2959 "%s: disabling TSF\n",
2960 device_get_nameunit(sc
->dev
));
2962 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_BCN_TIME_CFG
);
2964 tmp
&= ~(RT2870_REG_BCN_TX_ENABLE
|
2965 RT2870_REG_TSF_TIMER_ENABLE
|
2966 RT2870_REG_TBTT_TIMER_ENABLE
);
2968 tmp
&= ~(RT2870_REG_TSF_SYNC_MODE_MASK
<< RT2870_REG_TSF_SYNC_MODE_SHIFT
);
2969 tmp
|= (RT2870_REG_TSF_SYNC_MODE_DISABLE
<< RT2870_REG_TSF_SYNC_MODE_SHIFT
);
2971 rt2870_io_mac_write(sc
, RT2870_REG_BCN_TIME_CFG
, tmp
);
2975 * rt2870_asic_enable_mrr
2977 static void rt2870_asic_enable_mrr(struct rt2870_softc
*sc
)
2979 #define CCK(mcs) (mcs)
2980 #define OFDM(mcs) ((1 << 3) | (mcs))
2981 #define HT(mcs) (mcs)
2983 rt2870_io_mac_write(sc
, RT2870_REG_TX_LG_FBK_CFG0
,
2984 (OFDM(6) << 28) | /* 54 -> 48 */
2985 (OFDM(5) << 24) | /* 48 -> 36 */
2986 (OFDM(4) << 20) | /* 36 -> 24 */
2987 (OFDM(3) << 16) | /* 24 -> 18 */
2988 (OFDM(2) << 12) | /* 18 -> 12 */
2989 (OFDM(1) << 8) | /* 12 -> 9 */
2990 (OFDM(0) << 4) | /* 9 -> 6 */
2991 OFDM(0)); /* 6 -> 6 */
2993 rt2870_io_mac_write(sc
, RT2870_REG_TX_LG_FBK_CFG1
,
2994 (CCK(2) << 12) | /* 11 -> 5.5 */
2995 (CCK(1) << 8) | /* 5.5 -> 2 */
2996 (CCK(0) << 4) | /* 2 -> 1 */
2997 CCK(0)); /* 1 -> 1 */
2999 rt2870_io_mac_write(sc
, RT2870_REG_TX_HT_FBK_CFG0
,
3009 rt2870_io_mac_write(sc
, RT2870_REG_TX_HT_FBK_CFG1
,
3025 * rt2870_asic_set_txpreamble
3027 static void rt2870_asic_set_txpreamble(struct rt2870_softc
*sc
)
3030 struct ieee80211com
*ic
;
3036 RT2870_DPRINTF(sc
, RT2870_DEBUG_STATE
,
3037 "%s: %s short Tx preamble\n",
3038 device_get_nameunit(sc
->dev
),
3039 (ic
->ic_flags
& IEEE80211_F_SHPREAMBLE
) ? "enabling" : "disabling");
3041 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_AUTO_RSP_CFG
);
3043 tmp
&= ~RT2870_REG_CCK_SHORT_ENABLE
;
3045 if (ic
->ic_flags
& IEEE80211_F_SHPREAMBLE
)
3046 tmp
|= RT2870_REG_CCK_SHORT_ENABLE
;
3048 rt2870_io_mac_write(sc
, RT2870_REG_AUTO_RSP_CFG
, tmp
);
3052 * rt2870_asic_set_basicrates
3054 static void rt2870_asic_set_basicrates(struct rt2870_softc
*sc
)
3057 struct ieee80211com
*ic
;
3062 if (ic
->ic_curmode
== IEEE80211_MODE_11B
)
3063 rt2870_io_mac_write(sc
, RT2870_REG_LEGACY_BASIC_RATE
, 0x3);
3064 else if (ic
->ic_curmode
== IEEE80211_MODE_11A
)
3065 rt2870_io_mac_write(sc
, RT2870_REG_LEGACY_BASIC_RATE
, 0x150);
3067 rt2870_io_mac_write(sc
, RT2870_REG_LEGACY_BASIC_RATE
, 0x15f);
3071 * rt2870_asic_update_rtsthreshold
3073 static void rt2870_asic_update_rtsthreshold(struct rt2870_softc
*sc
)
3076 struct ieee80211com
*ic
;
3077 struct ieee80211vap
*vap
;
3083 vap
= TAILQ_FIRST(&ic
->ic_vaps
);
3085 RT2870_DPRINTF(sc
, RT2870_DEBUG_PROT
,
3086 "%s: updating RTS threshold: %d\n",
3087 device_get_nameunit(sc
->dev
), vap
->iv_rtsthreshold
);
3089 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_TX_RTS_CFG
);
3091 tmp
&= ~(RT2870_REG_TX_RTS_THRESHOLD_MASK
<< RT2870_REG_TX_RTS_THRESHOLD_SHIFT
);
3093 threshold
= (vap
->iv_rtsthreshold
< IEEE80211_RTS_MAX
) ?
3094 vap
->iv_rtsthreshold
: 0x1000;
3096 tmp
|= ((threshold
& RT2870_REG_TX_RTS_THRESHOLD_MASK
) <<
3097 RT2870_REG_TX_RTS_THRESHOLD_SHIFT
);
3099 rt2870_io_mac_write(sc
, RT2870_REG_TX_RTS_CFG
, tmp
);
3103 * rt2870_asic_update_txpower
3105 static void rt2870_asic_update_txpower(struct rt2870_softc
*sc
)
3108 struct ieee80211com
*ic
;
3109 uint32_t *txpow_rate
;
3118 RT2870_DPRINTF(sc
, RT2870_DEBUG_STATE
,
3119 "%s: updating Tx power: %d\n",
3120 device_get_nameunit(sc
->dev
), ic
->ic_txpowlimit
);
3122 if (!IEEE80211_IS_CHAN_HT40(ic
->ic_curchan
))
3124 txpow_rate
= sc
->txpow_rate_20mhz
;
3128 if (IEEE80211_IS_CHAN_2GHZ(ic
->ic_curchan
))
3129 txpow_rate
= sc
->txpow_rate_40mhz_2ghz
;
3131 txpow_rate
= sc
->txpow_rate_40mhz_5ghz
;
3136 val
= rt2870_io_bbp_read(sc
, 1);
3139 if (ic
->ic_txpowlimit
> 90)
3143 else if (ic
->ic_txpowlimit
> 60)
3147 else if (ic
->ic_txpowlimit
> 30)
3151 else if (ic
->ic_txpowlimit
> 15)
3155 else if (ic
->ic_txpowlimit
> 9)
3165 rt2870_io_bbp_write(sc
, 1, val
);
3167 for (i
= 0; i
< RT2870_SOFTC_TXPOW_RATE_COUNT
; i
++)
3169 if (txpow_rate
[i
] == 0xffffffff)
3172 tmp
= rt2870_read_eeprom_txpow_rate_add_delta(txpow_rate
[i
], delta
);
3174 rt2870_io_mac_write(sc
, RT2870_REG_TX_PWR_CFG(i
), tmp
);
3179 * rt2870_asic_update_promisc
3181 static void rt2870_asic_update_promisc(struct rt2870_softc
*sc
)
3188 printf("%s: %s promiscuous mode\n",
3189 device_get_nameunit(sc
->dev
),
3190 (ifp
->if_flags
& IFF_PROMISC
) ? "entering" : "leaving");
3192 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_RX_FILTER_CFG
);
3194 tmp
&= ~RT2870_REG_RX_FILTER_DROP_UC_NOME
;
3196 if (!(ifp
->if_flags
& IFF_PROMISC
))
3197 tmp
|= RT2870_REG_RX_FILTER_DROP_UC_NOME
;
3199 rt2870_io_mac_write(sc
, RT2870_REG_RX_FILTER_CFG
, tmp
);
3203 * rt2870_asic_updateprot
3205 static void rt2870_asic_updateprot(struct rt2870_softc
*sc
)
3208 struct ieee80211com
*ic
;
3209 struct ieee80211vap
*vap
;
3210 uint32_t cck_prot
, ofdm_prot
, mm20_prot
, mm40_prot
, gf20_prot
, gf40_prot
;
3212 enum ieee80211_protmode htprotmode
;
3216 vap
= TAILQ_FIRST(&ic
->ic_vaps
);
3218 /* CCK frame protection */
3220 cck_prot
= RT2870_REG_RTSTH_ENABLE
| RT2870_REG_PROT_NAV_SHORT
|
3221 RT2870_REG_TXOP_ALLOW_ALL
| RT2870_REG_PROT_CTRL_NONE
;
3223 /* set up protection frame phy mode and rate (MCS code) */
3225 if (ic
->ic_curmode
== IEEE80211_MODE_11A
)
3226 cck_prot
|= (RT2870_REG_PROT_PHYMODE_OFDM
<< RT2870_REG_PROT_PHYMODE_SHIFT
) |
3227 (0 << RT2870_REG_PROT_MCS_SHIFT
);
3229 cck_prot
|= ((RT2870_REG_PROT_PHYMODE_CCK
<< RT2870_REG_PROT_PHYMODE_SHIFT
) |
3230 (3 << RT2870_REG_PROT_MCS_SHIFT
));
3232 rt2870_io_mac_write(sc
, RT2870_REG_TX_CCK_PROT_CFG
, cck_prot
);
3234 /* OFDM frame protection */
3236 ofdm_prot
= RT2870_REG_RTSTH_ENABLE
| RT2870_REG_PROT_NAV_SHORT
|
3237 RT2870_REG_TXOP_ALLOW_ALL
;
3239 if (ic
->ic_flags
& IEEE80211_F_USEPROT
)
3241 RT2870_DPRINTF(sc
, RT2870_DEBUG_PROT
,
3242 "%s: updating protection mode: b/g protection mode=%s\n",
3243 device_get_nameunit(sc
->dev
),
3244 (ic
->ic_protmode
== IEEE80211_PROT_RTSCTS
) ? "RTS/CTS" :
3245 ((ic
->ic_protmode
== IEEE80211_PROT_CTSONLY
) ? "CTS-to-self" : "none"));
3247 if (ic
->ic_protmode
== IEEE80211_PROT_RTSCTS
)
3248 ofdm_prot
|= RT2870_REG_PROT_CTRL_RTS_CTS
;
3249 else if (ic
->ic_protmode
== IEEE80211_PROT_CTSONLY
)
3250 ofdm_prot
|= RT2870_REG_PROT_CTRL_CTS
;
3252 ofdm_prot
|= RT2870_REG_PROT_CTRL_NONE
;
3256 RT2870_DPRINTF(sc
, RT2870_DEBUG_PROT
,
3257 "%s: updating protection mode: b/g protection mode=%s\n",
3258 device_get_nameunit(sc
->dev
), "none");
3260 ofdm_prot
|= RT2870_REG_PROT_CTRL_NONE
;
3263 rt2870_io_mac_write(sc
, RT2870_REG_TX_OFDM_PROT_CFG
, ofdm_prot
);
3265 /* HT frame protection */
3267 if ((vap
->iv_opmode
== IEEE80211_M_STA
) && (vap
->iv_state
== IEEE80211_S_RUN
))
3268 htopmode
= vap
->iv_bss
->ni_htopmode
;
3270 htopmode
= ic
->ic_curhtprotmode
;
3272 htprotmode
= ic
->ic_htprotmode
;
3274 /* force HT mixed mode and RTS/CTS protection if A-MPDU Tx aggregation is enabled */
3276 if (sc
->tx_ampdu_sessions
> 0)
3278 RT2870_DPRINTF(sc
, RT2870_DEBUG_PROT
,
3279 "%s: updating protection mode: forcing HT mixed mode and RTS/CTS protection\n",
3280 device_get_nameunit(sc
->dev
));
3282 htopmode
= IEEE80211_HTINFO_OPMODE_MIXED
;
3283 htprotmode
= IEEE80211_PROT_RTSCTS
;
3286 RT2870_DPRINTF(sc
, RT2870_DEBUG_PROT
,
3287 "%s: updating protection mode: HT operation mode=0x%02x, protection mode=%s\n",
3288 device_get_nameunit(sc
->dev
),
3289 htopmode
& IEEE80211_HTINFO_OPMODE
,
3290 (htprotmode
== IEEE80211_PROT_RTSCTS
) ? "RTS/CTS" :
3291 ((htprotmode
== IEEE80211_PROT_CTSONLY
) ? "CTS-to-self" : "none"));
3293 switch (htopmode
& IEEE80211_HTINFO_OPMODE
)
3295 /* IEEE80211_HTINFO_OPMODE_HT20PR */
3296 case IEEE80211_HTINFO_OPMODE_HT20PR
:
3297 mm20_prot
= RT2870_REG_PROT_NAV_SHORT
| RT2870_REG_PROT_CTRL_NONE
|
3298 RT2870_REG_TXOP_ALLOW_CCK
| RT2870_REG_TXOP_ALLOW_OFDM
|
3299 RT2870_REG_TXOP_ALLOW_MM20
| RT2870_REG_TXOP_ALLOW_GF20
|
3300 (RT2870_REG_PROT_PHYMODE_OFDM
<< RT2870_REG_PROT_PHYMODE_SHIFT
) |
3301 (4 << RT2870_REG_PROT_MCS_SHIFT
);
3303 gf20_prot
= mm20_prot
;
3305 mm40_prot
= RT2870_REG_PROT_NAV_SHORT
| RT2870_REG_PROT_CTRL_NONE
|
3306 RT2870_REG_TXOP_ALLOW_ALL
|
3307 (RT2870_REG_PROT_PHYMODE_OFDM
<< RT2870_REG_PROT_PHYMODE_SHIFT
) |
3308 (0x84 << RT2870_REG_PROT_MCS_SHIFT
);
3310 if (htprotmode
== IEEE80211_PROT_RTSCTS
)
3311 mm40_prot
|= RT2870_REG_PROT_CTRL_RTS_CTS
;
3312 else if (htprotmode
== IEEE80211_PROT_CTSONLY
)
3313 mm40_prot
|= RT2870_REG_PROT_CTRL_CTS
;
3315 mm40_prot
|= RT2870_REG_PROT_CTRL_NONE
;
3317 gf40_prot
= mm40_prot
;
3320 /* IEEE80211_HTINFO_OPMODE_MIXED */
3321 case IEEE80211_HTINFO_OPMODE_MIXED
:
3322 mm20_prot
= RT2870_REG_PROT_NAV_SHORT
|
3323 RT2870_REG_TXOP_ALLOW_CCK
| RT2870_REG_TXOP_ALLOW_OFDM
|
3324 RT2870_REG_TXOP_ALLOW_MM20
| RT2870_REG_TXOP_ALLOW_GF20
;
3326 if (ic
->ic_flags
& IEEE80211_F_USEPROT
)
3327 mm20_prot
|= (RT2870_REG_PROT_PHYMODE_CCK
<< RT2870_REG_PROT_PHYMODE_SHIFT
) |
3328 (3 << RT2870_REG_PROT_MCS_SHIFT
);
3330 mm20_prot
|= (RT2870_REG_PROT_PHYMODE_OFDM
<< RT2870_REG_PROT_PHYMODE_SHIFT
) |
3331 (4 << RT2870_REG_PROT_MCS_SHIFT
);
3333 if (htprotmode
== IEEE80211_PROT_RTSCTS
)
3334 mm20_prot
|= RT2870_REG_PROT_CTRL_RTS_CTS
;
3335 else if (htprotmode
== IEEE80211_PROT_CTSONLY
)
3336 mm20_prot
|= RT2870_REG_PROT_CTRL_CTS
;
3338 mm20_prot
|= RT2870_REG_PROT_CTRL_NONE
;
3340 gf20_prot
= mm20_prot
;
3342 mm40_prot
= RT2870_REG_PROT_NAV_SHORT
| RT2870_REG_TXOP_ALLOW_ALL
;
3344 if (ic
->ic_flags
& IEEE80211_F_USEPROT
)
3345 mm40_prot
|= (RT2870_REG_PROT_PHYMODE_CCK
<< RT2870_REG_PROT_PHYMODE_SHIFT
) |
3346 (3 << RT2870_REG_PROT_MCS_SHIFT
);
3348 mm40_prot
|= (RT2870_REG_PROT_PHYMODE_OFDM
<< RT2870_REG_PROT_PHYMODE_SHIFT
) |
3349 (0x84 << RT2870_REG_PROT_MCS_SHIFT
);
3351 if (htprotmode
== IEEE80211_PROT_RTSCTS
)
3352 mm40_prot
|= RT2870_REG_PROT_CTRL_RTS_CTS
;
3353 else if (htprotmode
== IEEE80211_PROT_CTSONLY
)
3354 mm40_prot
|= RT2870_REG_PROT_CTRL_CTS
;
3356 mm40_prot
|= RT2870_REG_PROT_CTRL_NONE
;
3358 gf40_prot
= mm40_prot
;
3362 * IEEE80211_HTINFO_OPMODE_PURE
3363 * IEEE80211_HTINFO_OPMODE_PROTOPT
3365 case IEEE80211_HTINFO_OPMODE_PURE
:
3366 case IEEE80211_HTINFO_OPMODE_PROTOPT
:
3368 mm20_prot
= RT2870_REG_PROT_NAV_SHORT
| RT2870_REG_PROT_CTRL_NONE
|
3369 RT2870_REG_TXOP_ALLOW_CCK
| RT2870_REG_TXOP_ALLOW_OFDM
|
3370 RT2870_REG_TXOP_ALLOW_MM20
| RT2870_REG_TXOP_ALLOW_GF20
|
3371 (RT2870_REG_PROT_PHYMODE_OFDM
<< RT2870_REG_PROT_PHYMODE_SHIFT
) |
3372 (4 << RT2870_REG_PROT_MCS_SHIFT
);
3374 gf20_prot
= mm20_prot
;
3376 mm40_prot
= RT2870_REG_PROT_NAV_SHORT
| RT2870_REG_PROT_CTRL_NONE
|
3377 RT2870_REG_TXOP_ALLOW_ALL
|
3378 (RT2870_REG_PROT_PHYMODE_OFDM
<< RT2870_REG_PROT_PHYMODE_SHIFT
) |
3379 (0x84 << RT2870_REG_PROT_MCS_SHIFT
);
3381 gf40_prot
= mm40_prot
;
3385 rt2870_io_mac_write(sc
, RT2870_REG_TX_MM20_PROT_CFG
, mm20_prot
);
3386 rt2870_io_mac_write(sc
, RT2870_REG_TX_MM40_PROT_CFG
, mm40_prot
);
3387 rt2870_io_mac_write(sc
, RT2870_REG_TX_GF20_PROT_CFG
, gf20_prot
);
3388 rt2870_io_mac_write(sc
, RT2870_REG_TX_GF40_PROT_CFG
, gf40_prot
);
3392 * rt2870_asic_updateslot
3394 static void rt2870_asic_updateslot(struct rt2870_softc
*sc
)
3397 struct ieee80211com
*ic
;
3403 RT2870_DPRINTF(sc
, RT2870_DEBUG_STATE
,
3404 "%s: %s short slot time\n",
3405 device_get_nameunit(sc
->dev
),
3406 (ic
->ic_flags
& IEEE80211_F_SHSLOT
) ? "enabling" : "disabling");
3408 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_BKOFF_SLOT_CFG
);
3411 tmp
|= (ic
->ic_flags
& IEEE80211_F_SHSLOT
) ? 9 : 20;
3413 rt2870_io_mac_write(sc
, RT2870_REG_BKOFF_SLOT_CFG
, tmp
);
3417 * rt2870_asic_wme_update
3419 static void rt2870_asic_wme_update(struct rt2870_softc
*sc
)
3422 struct ieee80211com
*ic
;
3423 struct ieee80211_wme_state
*wme
;
3424 const struct wmeParams
*wmep
;
3430 wmep
= wme
->wme_chanParams
.cap_wmeParams
;
3432 RT2870_DPRINTF(sc
, RT2870_DEBUG_WME
,
3433 "%s: wme update: WME_AC_VO=%d/%d/%d/%d, WME_AC_VI=%d/%d/%d/%d, "
3434 "WME_AC_BK=%d/%d/%d/%d, WME_AC_BE=%d/%d/%d/%d\n",
3435 device_get_nameunit(sc
->dev
),
3436 wmep
[WME_AC_VO
].wmep_aifsn
,
3437 wmep
[WME_AC_VO
].wmep_logcwmin
, wmep
[WME_AC_VO
].wmep_logcwmax
,
3438 wmep
[WME_AC_VO
].wmep_txopLimit
,
3439 wmep
[WME_AC_VI
].wmep_aifsn
,
3440 wmep
[WME_AC_VI
].wmep_logcwmin
, wmep
[WME_AC_VI
].wmep_logcwmax
,
3441 wmep
[WME_AC_VI
].wmep_txopLimit
,
3442 wmep
[WME_AC_BK
].wmep_aifsn
,
3443 wmep
[WME_AC_BK
].wmep_logcwmin
, wmep
[WME_AC_BK
].wmep_logcwmax
,
3444 wmep
[WME_AC_BK
].wmep_txopLimit
,
3445 wmep
[WME_AC_BE
].wmep_aifsn
,
3446 wmep
[WME_AC_BE
].wmep_logcwmin
, wmep
[WME_AC_BE
].wmep_logcwmax
,
3447 wmep
[WME_AC_BE
].wmep_txopLimit
);
3449 for (i
= 0; i
< WME_NUM_AC
; i
++)
3450 rt2870_io_mac_write(sc
, RT2870_REG_TX_EDCA_AC_CFG(i
),
3451 (wmep
[i
].wmep_logcwmax
<< 16) | (wmep
[i
].wmep_logcwmin
<< 12) |
3452 (wmep
[i
].wmep_aifsn
<< 8) | wmep
[i
].wmep_txopLimit
);
3454 rt2870_io_mac_write(sc
, RT2870_REG_SCHDMA_WMM_AIFSN_CFG
,
3455 (wmep
[WME_AC_VO
].wmep_aifsn
<< 12) | (wmep
[WME_AC_VI
].wmep_aifsn
<< 8) |
3456 (wmep
[WME_AC_BK
].wmep_aifsn
<< 4) | wmep
[WME_AC_BE
].wmep_aifsn
);
3458 rt2870_io_mac_write(sc
, RT2870_REG_SCHDMA_WMM_CWMIN_CFG
,
3459 (wmep
[WME_AC_VO
].wmep_logcwmin
<< 12) | (wmep
[WME_AC_VI
].wmep_logcwmin
<< 8) |
3460 (wmep
[WME_AC_BK
].wmep_logcwmin
<< 4) | wmep
[WME_AC_BE
].wmep_logcwmin
);
3462 rt2870_io_mac_write(sc
, RT2870_REG_SCHDMA_WMM_CWMAX_CFG
,
3463 (wmep
[WME_AC_VO
].wmep_logcwmax
<< 12) | (wmep
[WME_AC_VI
].wmep_logcwmax
<< 8) |
3464 (wmep
[WME_AC_BK
].wmep_logcwmax
<< 4) | wmep
[WME_AC_BE
].wmep_logcwmax
);
3466 rt2870_io_mac_write(sc
, RT2870_REG_SCHDMA_WMM_TXOP0_CFG
,
3467 (wmep
[WME_AC_BK
].wmep_txopLimit
<< 16) | wmep
[WME_AC_BE
].wmep_txopLimit
);
3469 rt2870_io_mac_write(sc
, RT2870_REG_SCHDMA_WMM_TXOP1_CFG
,
3470 (wmep
[WME_AC_VO
].wmep_txopLimit
<< 16) | wmep
[WME_AC_VI
].wmep_txopLimit
);
3474 * rt2870_asic_update_beacon
3476 static int rt2870_asic_update_beacon(struct rt2870_softc
*sc
,
3477 struct ieee80211vap
*vap
)
3480 struct ieee80211com
*ic
;
3481 struct rt2870_softc_vap
*rvap
;
3482 const struct ieee80211_txparam
*tp
;
3484 struct rt2870_txwi txwi
;
3490 rvap
= (struct rt2870_softc_vap
*) vap
;
3491 tp
= &vap
->iv_txparms
[ieee80211_chan2mode(ic
->ic_bsschan
)];
3493 m
= ieee80211_beacon_alloc(vap
->iv_bss
, &rvap
->beacon_offsets
);
3497 rate
= tp
->mgmtrate
;
3498 mcs
= rt2870_rate2mcs(rate
);
3500 memset(&txwi
, 0, sizeof(struct rt2870_txwi
));
3503 txwi
.pid_mpdu_len
= ((htole16(m
->m_pkthdr
.len
) & RT2870_TXWI_MPDU_LEN_MASK
) <<
3504 RT2870_TXWI_MPDU_LEN_SHIFT
);
3505 txwi
.txop
= (RT2870_TXWI_TXOP_HT
<< RT2870_TXWI_TXOP_SHIFT
);
3506 txwi
.mpdu_density_flags
|=
3507 (RT2870_TXWI_FLAGS_TS
<< RT2870_TXWI_FLAGS_SHIFT
);
3508 txwi
.bawin_size_xflags
|=
3509 (RT2870_TXWI_XFLAGS_NSEQ
<< RT2870_TXWI_XFLAGS_SHIFT
);
3511 if (ieee80211_rate2phytype(ic
->ic_rt
, rate
) != IEEE80211_T_OFDM
)
3513 txwi
.phymode_ifs_stbc_shortgi
=
3514 (RT2870_TXWI_PHYMODE_CCK
<< RT2870_TXWI_PHYMODE_SHIFT
);
3516 if (rate
!= 2 && (ic
->ic_flags
& IEEE80211_F_SHPREAMBLE
))
3517 mcs
|= RT2870_TXWI_MCS_SHOTPRE
;
3521 txwi
.phymode_ifs_stbc_shortgi
=
3522 (RT2870_TXWI_PHYMODE_OFDM
<< RT2870_TXWI_PHYMODE_SHIFT
);
3525 txwi
.bw_mcs
= (RT2870_TXWI_BW_20
<< RT2870_TXWI_BW_SHIFT
) |
3526 ((mcs
& RT2870_TXWI_MCS_MASK
) << RT2870_TXWI_MCS_SHIFT
);
3528 /* disable temporarily TSF sync */
3530 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_BCN_TIME_CFG
);
3532 tmp
&= ~(RT2870_REG_BCN_TX_ENABLE
|
3533 RT2870_REG_TSF_TIMER_ENABLE
|
3534 RT2870_REG_TBTT_TIMER_ENABLE
);
3536 rt2870_io_mac_write(sc
, RT2870_REG_BCN_TIME_CFG
, tmp
);
3538 /* write Tx wireless info and beacon frame to on-chip memory */
3540 rt2870_io_mac_write_multi(sc
, RT2870_REG_BEACON_BASE(0),
3541 &txwi
, sizeof(struct rt2870_txwi
));
3543 rt2870_io_mac_write_multi(sc
, RT2870_REG_BEACON_BASE(0) + sizeof(struct rt2870_txwi
),
3544 mtod(m
, uint8_t *), m
->m_pkthdr
.len
);
3546 /* enable again TSF sync */
3548 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_BCN_TIME_CFG
);
3550 tmp
|= (RT2870_REG_BCN_TX_ENABLE
|
3551 RT2870_REG_TSF_TIMER_ENABLE
|
3552 RT2870_REG_TBTT_TIMER_ENABLE
);
3554 rt2870_io_mac_write(sc
, RT2870_REG_BCN_TIME_CFG
, tmp
);
3562 * rt2870_asic_clear_keytables
3564 static void rt2870_asic_clear_keytables(struct rt2870_softc
*sc
)
3568 /* clear Rx WCID search table (entries = 256, entry size = 8) */
3570 for (i
= 0; i
< 256; i
++)
3572 rt2870_io_mac_write(sc
, RT2870_REG_WCID(i
), 0xffffffff);
3573 rt2870_io_mac_write(sc
, RT2870_REG_WCID(i
) + 4, 0x0000ffff);
3576 /* clear WCID attribute table (entries = 256, entry size = 4) */
3578 rt2870_io_mac_set_region_4(sc
, RT2870_REG_WCID_ATTR(0), 0, 256);
3580 /* clear IV/EIV table (entries = 256, entry size = 8) */
3582 rt2870_io_mac_set_region_4(sc
, RT2870_REG_IVEIV(0), 0, 2 * 256);
3584 /* clear pairwise key table (entries = 256, entry size = 32) */
3586 rt2870_io_mac_set_region_4(sc
, RT2870_REG_PKEY(0), 0, 8 * 256);
3588 /* clear shared key table (entries = 32, entry size = 32) */
3590 rt2870_io_mac_set_region_4(sc
, RT2870_REG_SKEY(0, 0), 0, 8 * 32);
3592 /* clear shared key mode (entries = 32, entry size = 2) */
3594 rt2870_io_mac_set_region_4(sc
, RT2870_REG_SKEY_MODE(0), 0, 16);
3600 static uint8_t rt2870_rxrate(struct rt2870_rxwi
*rxwi
)
3602 uint8_t mcs
, phymode
;
3605 mcs
= (rxwi
->bw_mcs
>> RT2870_RXWI_MCS_SHIFT
) & RT2870_RXWI_MCS_MASK
;
3606 phymode
= (rxwi
->phymode_stbc_shortgi
>> RT2870_RXWI_PHYMODE_SHIFT
) &
3607 RT2870_RXWI_PHYMODE_MASK
;
3613 case RT2870_RXWI_PHYMODE_CCK
:
3614 switch (mcs
& ~RT2870_RXWI_MCS_SHOTPRE
)
3616 case 0: rate
= 2; break; /* 1 Mbps */
3617 case 1: rate
= 4; break; /* 2 MBps */
3618 case 2: rate
= 11; break; /* 5.5 Mbps */
3619 case 3: rate
= 22; break; /* 11 Mbps */
3623 case RT2870_RXWI_PHYMODE_OFDM
:
3626 case 0: rate
= 12; break; /* 6 Mbps */
3627 case 1: rate
= 18; break; /* 9 Mbps */
3628 case 2: rate
= 24; break; /* 12 Mbps */
3629 case 3: rate
= 36; break; /* 18 Mbps */
3630 case 4: rate
= 48; break; /* 24 Mbps */
3631 case 5: rate
= 72; break; /* 36 Mbps */
3632 case 6: rate
= 96; break; /* 48 Mbps */
3633 case 7: rate
= 108; break; /* 54 Mbps */
3637 case RT2870_RXWI_PHYMODE_HT_MIXED
:
3638 case RT2870_RXWI_PHYMODE_HT_GF
:
3646 * rt2870_maxrssi_rxpath
3648 static uint8_t rt2870_maxrssi_rxpath(struct rt2870_softc
*sc
,
3649 const struct rt2870_rxwi
*rxwi
)
3655 if (sc
->nrxpath
> 1)
3656 if (rxwi
->rssi
[1] > rxwi
->rssi
[rxpath
])
3659 if (sc
->nrxpath
> 2)
3660 if (rxwi
->rssi
[2] > rxwi
->rssi
[rxpath
])
3669 static int8_t rt2870_rssi2dbm(struct rt2870_softc
*sc
,
3670 uint8_t rssi
, uint8_t rxpath
)
3673 struct ieee80211com
*ic
;
3674 struct ieee80211_channel
*c
;
3676 int8_t rssi_off
, lna_gain
;
3684 chan
= ieee80211_chan2ieee(ic
, c
);
3686 if (IEEE80211_IS_CHAN_5GHZ(c
))
3688 rssi_off
= sc
->rssi_off_5ghz
[rxpath
];
3691 lna_gain
= sc
->lna_gain
[1];
3692 else if (chan
<= 128)
3693 lna_gain
= sc
->lna_gain
[2];
3695 lna_gain
= sc
->lna_gain
[3];
3699 rssi_off
= sc
->rssi_off_2ghz
[rxpath
];
3700 lna_gain
= sc
->lna_gain
[0];
3703 return (-12 - rssi_off
- lna_gain
- rssi
);
3709 static uint8_t rt2870_rate2mcs(uint8_t rate
)
3736 static void rt2870_rx_frame(struct rt2870_softc
*sc
,
3737 uint8_t *buf
, uint32_t dmalen
)
3740 struct ieee80211com
*ic
;
3741 struct ieee80211_frame
*wh
;
3742 struct ieee80211_node
*ni
;
3743 struct rt2870_softc_rx_radiotap_header
*tap
;
3744 struct rt2870_rxwi
*rxwi
;
3745 struct rt2870_rxinfo
*rxinfo
;
3747 uint32_t rxinfo_flags
;
3748 uint8_t cipher_err
, rssi
, ant
, phymode
, bw
, shortgi
, mcs
;
3750 int len
, ampdu
, amsdu
, rssi_dbm_rel
;
3755 /* get Rx wireless info */
3757 rxwi
= (struct rt2870_rxwi
*) buf
;
3758 len
= (le16toh(rxwi
->tid_size
) >> RT2870_RXWI_SIZE_SHIFT
) &
3759 RT2870_RXWI_SIZE_MASK
;
3763 RT2870_DPRINTF(sc
, RT2870_DEBUG_RX
,
3764 "%s: bad rxwi len: DMA len=%d, rxwi len=%d\n",
3765 device_get_nameunit(sc
->dev
), dmalen
, len
);
3771 rxinfo
= (struct rt2870_rxinfo
*) ((caddr_t
) rxwi
+ dmalen
);
3772 rxinfo_flags
= le32toh(rxinfo
->flags
);
3774 RT2870_DPRINTF(sc
, RT2870_DEBUG_RX
,
3775 "%s: Rx frame: DMA len=%d, len=%d, rxinfo flags=0x%08x\n",
3776 device_get_nameunit(sc
->dev
), dmalen
, len
, rxinfo_flags
);
3778 /* check for crc errors */
3780 if (rxinfo_flags
& RT2870_RXINFO_FLAGS_CRC_ERR
)
3782 RT2870_DPRINTF(sc
, RT2870_DEBUG_RX
,
3783 "%s: rxinfo: crc error\n",
3784 device_get_nameunit(sc
->dev
));
3788 if (!(ifp
->if_flags
& IFF_PROMISC
))
3792 wh
= (struct ieee80211_frame
*) (rxwi
+ 1);
3794 /* check for L2 padding between IEEE 802.11 frame header and body */
3796 if (rxinfo_flags
& RT2870_RXINFO_FLAGS_L2PAD
)
3798 RT2870_DPRINTF(sc
, RT2870_DEBUG_RX
,
3799 "%s: L2 padding: DMA len=%d, len=%d\n",
3800 device_get_nameunit(sc
->dev
), dmalen
, len
);
3805 m
= m_getjcl(M_DONTWAIT
, MT_DATA
, M_PKTHDR
, MJUMPAGESIZE
);
3808 sc
->rx_mbuf_alloc_errors
++;
3813 m
->m_pkthdr
.rcvif
= ifp
;
3814 m
->m_pkthdr
.len
= m
->m_len
= len
;
3816 m_copyback(m
, 0, len
, (caddr_t
) wh
);
3818 wh
= mtod(m
, struct ieee80211_frame
*);
3820 /* check for cipher errors */
3822 if (rxinfo_flags
& RT2870_RXINFO_FLAGS_DECRYPTED
)
3824 cipher_err
= ((rxinfo_flags
>> RT2870_RXINFO_FLAGS_CIPHER_ERR_SHIFT
) &
3825 RT2870_RXINFO_FLAGS_CIPHER_ERR_MASK
);
3826 if (cipher_err
== RT2870_RXINFO_FLAGS_CIPHER_ERR_NONE
)
3828 if (wh
->i_fc
[1] & IEEE80211_FC1_WEP
)
3829 wh
->i_fc
[1] &= ~IEEE80211_FC1_WEP
;
3831 m
->m_flags
|= M_WEP
;
3835 RT2870_DPRINTF(sc
, RT2870_DEBUG_RX
,
3836 "%s: rxinfo: cipher error=0x%02x\n",
3837 device_get_nameunit(sc
->dev
), cipher_err
);
3841 if (!(ifp
->if_flags
& IFF_PROMISC
))
3850 if (wh
->i_fc
[1] & IEEE80211_FC1_WEP
)
3854 if (!(ifp
->if_flags
& IFF_PROMISC
))
3862 /* check for A-MPDU */
3864 if (rxinfo_flags
& RT2870_RXINFO_FLAGS_AMPDU
)
3866 m
->m_flags
|= M_AMPDU
;
3877 /* check for A-MSDU */
3879 if (rxinfo_flags
& RT2870_RXINFO_FLAGS_AMSDU
)
3890 ant
= rt2870_maxrssi_rxpath(sc
, rxwi
);
3891 rssi
= rxwi
->rssi
[ant
];
3892 rssi_dbm
= rt2870_rssi2dbm(sc
, rssi
, ant
);
3893 phymode
= ((rxwi
->phymode_stbc_shortgi
>> RT2870_RXWI_PHYMODE_SHIFT
) &
3894 RT2870_RXWI_PHYMODE_MASK
);
3895 bw
= ((rxwi
->bw_mcs
>> RT2870_RXWI_BW_SHIFT
) & RT2870_RXWI_BW_MASK
);
3896 shortgi
= ((rxwi
->phymode_stbc_shortgi
>> RT2870_RXWI_SHORTGI_SHIFT
) &
3897 RT2870_RXWI_SHORTGI_MASK
);
3898 mcs
= ((rxwi
->bw_mcs
>> RT2870_RXWI_MCS_SHIFT
) & RT2870_RXWI_MCS_MASK
);
3900 if (ieee80211_radiotap_active(ic
))
3904 tap
->flags
= (rxinfo_flags
& RT2870_RXINFO_FLAGS_L2PAD
) ? IEEE80211_RADIOTAP_F_DATAPAD
: 0;
3905 tap
->dbm_antsignal
= rssi_dbm
;
3906 tap
->dbm_antnoise
= RT2870_NOISE_FLOOR
;
3908 tap
->antsignal
= rssi
;
3909 tap
->chan_flags
= htole32(ic
->ic_curchan
->ic_flags
);
3910 tap
->chan_freq
= htole16(ic
->ic_curchan
->ic_freq
);
3911 tap
->chan_ieee
= ic
->ic_curchan
->ic_ieee
;
3912 tap
->chan_maxpow
= 0;
3914 if (phymode
== RT2870_RXWI_PHYMODE_CCK
|| phymode
== RT2870_RXWI_PHYMODE_OFDM
)
3915 tap
->rate
= rt2870_rxrate(rxwi
);
3917 tap
->rate
= mcs
| IEEE80211_RATE_MCS
;
3919 if (rxwi
->bw_mcs
& RT2870_RXWI_MCS_SHOTPRE
)
3920 tap
->flags
|= IEEE80211_RADIOTAP_F_SHORTPRE
;
3923 tap
->flags
|= IEEE80211_RADIOTAP_F_SHORTGI
;
3927 * net80211 assumes that RSSI data are in the range [-127..127] and
3928 * in .5 dBm units relative to the current noise floor
3931 rssi_dbm_rel
= (rssi_dbm
- RT2870_NOISE_FLOOR
) * 2;
3932 if (rssi_dbm_rel
> 127)
3935 RT2870_DPRINTF(sc
, RT2870_DEBUG_RX
,
3936 "%s: received frame: len=%d, phymode=%d, bw=%d, shortgi=%d, mcs=%d, "
3937 "ant=%d, rssi=%d/%d/%d, snr=%d/%d, wcid=0x%02x, ampdu=%d, amsdu=%d, "
3938 "rssi_dbm=%d, rssi_dbm_rel=%d\n",
3939 device_get_nameunit(sc
->dev
),
3940 len
, phymode
, bw
, shortgi
, mcs
,
3941 ant
, rxwi
->rssi
[0], rxwi
->rssi
[1], rxwi
->rssi
[2],
3942 rxwi
->snr
[0], rxwi
->snr
[1],
3943 rxwi
->wcid
, ampdu
, amsdu
, rssi_dbm
, rssi_dbm_rel
);
3945 ni
= ieee80211_find_rxnode(ic
, (struct ieee80211_frame_min
*) wh
);
3948 ieee80211_input(ni
, m
, rssi_dbm_rel
, RT2870_NOISE_FLOOR
);
3949 ieee80211_free_node(ni
);
3953 ieee80211_input_all(ic
, m
, rssi_dbm_rel
, RT2870_NOISE_FLOOR
);
3960 static int rt2870_tx_mgmt(struct rt2870_softc
*sc
,
3961 struct mbuf
*m
, struct ieee80211_node
*ni
, int qid
)
3964 struct ieee80211com
*ic
;
3965 struct ieee80211vap
*vap
;
3966 const struct ieee80211_txparam
*tp
;
3967 struct rt2870_softc_node
*rni
;
3968 struct rt2870_softc_tx_ring
*ring
;
3969 struct rt2870_softc_tx_data
*data
;
3970 struct rt2870_txinfo
*txinfo
;
3971 struct rt2870_txwi
*txwi
;
3972 struct ieee80211_frame
*wh
;
3973 struct rt2870_softc_tx_radiotap_header
*tap
;
3974 u_int hdrsize
, hdrspace
;
3975 uint8_t rate
, stbc
, shortgi
, mcs
, pid
;
3976 uint16_t len
, dmalen
, mpdu_len
, dur
;
3978 KASSERT(qid
>= 0 && qid
< (sc
->usb_endpoints
- 1),
3979 ("%s: Tx MGMT: invalid qid=%d\n",
3980 device_get_nameunit(sc
->dev
), qid
));
3985 rni
= (struct rt2870_softc_node
*) ni
;
3986 tp
= &vap
->iv_txparms
[ieee80211_chan2mode(ic
->ic_curchan
)];
3988 ring
= &sc
->tx_ring
[qid
];
3989 data
= STAILQ_FIRST(&ring
->inactive
);
3990 STAILQ_REMOVE_HEAD(&ring
->inactive
, next
);
3991 txinfo
= (struct rt2870_txinfo
*) data
->buf
;
3992 txwi
= (struct rt2870_txwi
*) (txinfo
+ 1);
3994 wh
= mtod(m
, struct ieee80211_frame
*);
3996 rate
= tp
->mgmtrate
& IEEE80211_RATE_VAL
;
3998 len
= sizeof(struct rt2870_txinfo
) + sizeof(struct rt2870_txwi
) + m
->m_pkthdr
.len
;
4000 /* align end on a 4-bytes boundary */
4002 dmalen
= (len
+ 3) & ~3;
4006 memset(txinfo
, 0, sizeof(struct rt2870_txinfo
));
4008 txinfo
->len
= htole16(dmalen
- sizeof(struct rt2870_txinfo
));
4010 txinfo
->qsel_flags
= (RT2870_TXINFO_QSEL_EDCA
<< RT2870_TXINFO_QSEL_SHIFT
);
4014 memset((caddr_t
) txinfo
+ len
, 0, dmalen
- len
);
4016 /* fill Tx wireless info */
4018 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
4021 mcs
= rt2870_rate2mcs(rate
);
4025 /* calculate MPDU length without padding */
4027 hdrsize
= ieee80211_hdrsize(wh
);
4028 hdrspace
= ieee80211_hdrspace(ic
, wh
);
4029 mpdu_len
= m
->m_pkthdr
.len
- hdrspace
+ hdrsize
;
4031 memset(txwi
, 0, sizeof(struct rt2870_txwi
));
4033 /* management frames do not need encryption */
4037 txwi
->pid_mpdu_len
= ((htole16(pid
) & RT2870_TXWI_PID_MASK
) <<
4038 RT2870_TXWI_PID_SHIFT
) | ((htole16(mpdu_len
) & RT2870_TXWI_MPDU_LEN_MASK
) <<
4039 RT2870_TXWI_MPDU_LEN_SHIFT
);
4041 stbc
= (ni
->ni_htcap
& IEEE80211_HTCAP_RXSTBC
) ? 1 : 0;
4043 shortgi
= (vap
->iv_flags_ht
& (IEEE80211_FHT_SHORTGI20
| IEEE80211_FHT_SHORTGI40
)) &&
4044 (ni
->ni_flags
& IEEE80211_NODE_HT
);
4046 txwi
->phymode_ifs_stbc_shortgi
|=
4047 ((stbc
& RT2870_TXWI_STBC_MASK
) << RT2870_TXWI_STBC_SHIFT
) |
4048 ((shortgi
& RT2870_TXWI_SHORTGI_MASK
) << RT2870_TXWI_SHORTGI_SHIFT
);
4050 txwi
->phymode_ifs_stbc_shortgi
|=
4051 ((shortgi
& RT2870_TXWI_SHORTGI_MASK
) << RT2870_TXWI_SHORTGI_SHIFT
);
4053 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
4055 txwi
->phymode_ifs_stbc_shortgi
|=
4056 (RT2870_TXWI_PHYMODE_HT_MIXED
<< RT2870_TXWI_PHYMODE_SHIFT
);
4060 if (ieee80211_rate2phytype(ic
->ic_rt
, rate
) != IEEE80211_T_OFDM
)
4062 txwi
->phymode_ifs_stbc_shortgi
|=
4063 (RT2870_TXWI_PHYMODE_CCK
<< RT2870_TXWI_PHYMODE_SHIFT
);
4065 if (rate
!= 2 && (ic
->ic_flags
& IEEE80211_F_SHPREAMBLE
))
4066 mcs
|= RT2870_TXWI_MCS_SHOTPRE
;
4070 txwi
->phymode_ifs_stbc_shortgi
|=
4071 (RT2870_TXWI_PHYMODE_OFDM
<< RT2870_TXWI_PHYMODE_SHIFT
);
4075 txwi
->bw_mcs
= (RT2870_TXWI_BW_20
<< RT2870_TXWI_BW_SHIFT
) |
4076 ((mcs
& RT2870_TXWI_MCS_MASK
) << RT2870_TXWI_MCS_SHIFT
);
4078 txwi
->txop
= (RT2870_TXWI_TXOP_BACKOFF
<< RT2870_TXWI_TXOP_SHIFT
);
4080 /* skip ACKs for multicast frames and probe responses */
4082 if (!IEEE80211_IS_MULTICAST(wh
->i_addr1
) &&
4083 ((wh
->i_fc
[0] & (IEEE80211_FC0_TYPE_MASK
| IEEE80211_FC0_SUBTYPE_MASK
)) !=
4084 (IEEE80211_FC0_TYPE_MGT
| IEEE80211_FC0_SUBTYPE_PROBE_RESP
)))
4086 txwi
->bawin_size_xflags
|=
4087 (RT2870_TXWI_XFLAGS_ACK
<< RT2870_TXWI_XFLAGS_SHIFT
);
4089 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
4091 /* preamble + plcp + signal extension */
4097 dur
= ieee80211_ack_duration(ic
->ic_rt
, rate
,
4098 ic
->ic_flags
& IEEE80211_F_SHPREAMBLE
);
4101 *(uint16_t *) wh
->i_dur
= htole16(dur
);
4104 /* ask MAC to insert timestamp into probe responses */
4106 if ((wh
->i_fc
[0] & (IEEE80211_FC0_TYPE_MASK
| IEEE80211_FC0_SUBTYPE_MASK
)) ==
4107 (IEEE80211_FC0_TYPE_MGT
| IEEE80211_FC0_SUBTYPE_PROBE_RESP
))
4108 txwi
->mpdu_density_flags
|=
4109 (RT2870_TXWI_FLAGS_TS
<< RT2870_TXWI_FLAGS_SHIFT
);
4111 if (ieee80211_radiotap_active_vap(vap
))
4115 tap
->flags
= IEEE80211_RADIOTAP_F_DATAPAD
;
4116 tap
->chan_flags
= htole32(ic
->ic_curchan
->ic_flags
);
4117 tap
->chan_freq
= htole16(ic
->ic_curchan
->ic_freq
);
4118 tap
->chan_ieee
= ic
->ic_curchan
->ic_ieee
;
4119 tap
->chan_maxpow
= 0;
4121 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
4122 tap
->rate
= mcs
| IEEE80211_RATE_MCS
;
4126 if (mcs
& RT2870_TXWI_MCS_SHOTPRE
)
4127 tap
->flags
|= IEEE80211_RADIOTAP_F_SHORTPRE
;
4130 tap
->flags
|= IEEE80211_RADIOTAP_F_SHORTGI
;
4132 if (wh
->i_fc
[1] & IEEE80211_FC1_WEP
)
4133 tap
->flags
|= IEEE80211_RADIOTAP_F_WEP
;
4135 if (wh
->i_fc
[1] & IEEE80211_FC1_WEP
)
4137 wh
->i_fc
[1] &= ~IEEE80211_FC1_WEP
;
4139 ieee80211_radiotap_tx(vap
, m
);
4141 wh
->i_fc
[1] |= IEEE80211_FC1_WEP
;
4145 ieee80211_radiotap_tx(vap
, m
);
4149 m_copydata(m
, 0, m
->m_pkthdr
.len
, (caddr_t
) (txwi
+ 1));
4151 RT2870_DPRINTF(sc
, RT2870_DEBUG_TX
,
4152 "%s: sending MGMT frame: qid=%d, hdrsize=%d, hdrspace=%d, len=%d, "
4153 "stbc=%d, shortgi=%d, mcs=%d, DMA len=%d\n",
4154 device_get_nameunit(sc
->dev
),
4155 qid
, hdrsize
, hdrspace
, m
->m_pkthdr
.len
, stbc
, shortgi
, mcs
, dmalen
);
4161 STAILQ_INSERT_TAIL(&ring
->pending
, data
, next
);
4164 usbd_transfer_start(sc
->usb_xfer
[1 + qid
]);
4172 static int rt2870_tx_data(struct rt2870_softc
*sc
,
4173 struct mbuf
*m
, struct ieee80211_node
*ni
, int qid
)
4176 struct ieee80211com
*ic
;
4177 struct ieee80211vap
*vap
;
4178 const struct ieee80211_txparam
*tp
;
4179 struct rt2870_softc_node
*rni
;
4180 struct rt2870_softc_tx_ring
*ring
;
4181 struct rt2870_softc_tx_data
*data
;
4182 struct rt2870_txinfo
*txinfo
;
4183 struct rt2870_txwi
*txwi
;
4184 struct ieee80211_frame
*wh
;
4185 struct ieee80211_tx_ampdu
*tx_ampdu
;
4186 ieee80211_seq seqno
;
4187 struct rt2870_softc_tx_radiotap_header
*tap
;
4188 u_int hdrsize
, hdrspace
;
4189 uint8_t type
, rate
, bw
, stbc
, shortgi
, mcs
, pid
, wcid
, mpdu_density
, bawin_size
;
4190 uint16_t qos
, len
, dmalen
, mpdu_len
, dur
;
4191 int hasqos
, ac
, tid
, ampdu
;
4193 KASSERT(qid
>= 0 && qid
< (sc
->usb_endpoints
- 1),
4194 ("%s: Tx data: invalid qid=%d\n",
4195 device_get_nameunit(sc
->dev
), qid
));
4200 rni
= (struct rt2870_softc_node
*) ni
;
4201 tp
= &vap
->iv_txparms
[ieee80211_chan2mode(ni
->ni_chan
)];
4203 ring
= &sc
->tx_ring
[qid
];
4204 data
= STAILQ_FIRST(&ring
->inactive
);
4205 STAILQ_REMOVE_HEAD(&ring
->inactive
, next
);
4206 txinfo
= (struct rt2870_txinfo
*) data
->buf
;
4207 txwi
= (struct rt2870_txwi
*) (txinfo
+ 1);
4209 wh
= mtod(m
, struct ieee80211_frame
*);
4211 type
= wh
->i_fc
[0] & IEEE80211_FC0_TYPE_MASK
;
4213 hasqos
= IEEE80211_QOS_HAS_SEQ(wh
);
4216 if (IEEE80211_HAS_ADDR4(wh
))
4217 qos
= le16toh(*(const uint16_t *)
4218 (((struct ieee80211_qosframe_addr4
*) wh
)->i_qos
));
4220 qos
= le16toh(*(const uint16_t *)
4221 (((struct ieee80211_qosframe
*) wh
)->i_qos
));
4228 if (IEEE80211_IS_MULTICAST(wh
->i_addr1
))
4229 rate
= tp
->mcastrate
;
4230 else if (m
->m_flags
& M_EAPOL
)
4231 rate
= tp
->mgmtrate
;
4232 else if (tp
->ucastrate
!= IEEE80211_FIXED_RATE_NONE
)
4233 rate
= tp
->ucastrate
;
4235 rate
= ni
->ni_txrate
;
4237 rate
&= IEEE80211_RATE_VAL
;
4239 len
= sizeof(struct rt2870_txinfo
) + sizeof(struct rt2870_txwi
) + m
->m_pkthdr
.len
;
4241 /* align end on a 4-bytes boundary */
4243 dmalen
= (len
+ 3) & ~3;
4247 memset(txinfo
, 0, sizeof(struct rt2870_txinfo
));
4249 txinfo
->len
= htole16(dmalen
- sizeof(struct rt2870_txinfo
));
4251 txinfo
->qsel_flags
= (RT2870_TXINFO_QSEL_EDCA
<< RT2870_TXINFO_QSEL_SHIFT
);
4255 memset((caddr_t
) txinfo
+ len
, 0, dmalen
- len
);
4257 /* fill Tx wireless info */
4259 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
4262 mcs
= rt2870_rate2mcs(rate
);
4266 wcid
= (type
== IEEE80211_FC0_TYPE_DATA
) ?
4267 RT2870_AID2WCID(ni
->ni_associd
) : 0xff;
4269 /* calculate MPDU length without padding */
4271 hdrsize
= ieee80211_hdrsize(wh
);
4272 hdrspace
= ieee80211_hdrspace(ic
, wh
);
4273 mpdu_len
= m
->m_pkthdr
.len
- hdrspace
+ hdrsize
;
4275 memset(txwi
, 0, sizeof(struct rt2870_txwi
));
4279 txwi
->pid_mpdu_len
= ((htole16(pid
) & RT2870_TXWI_PID_MASK
) <<
4280 RT2870_TXWI_PID_SHIFT
) | ((htole16(mpdu_len
) & RT2870_TXWI_MPDU_LEN_MASK
) <<
4281 RT2870_TXWI_MPDU_LEN_SHIFT
);
4283 stbc
= (ni
->ni_htcap
& IEEE80211_HTCAP_RXSTBC
) ? 1 : 0;
4285 shortgi
= (vap
->iv_flags_ht
& (IEEE80211_FHT_SHORTGI20
| IEEE80211_FHT_SHORTGI40
)) &&
4286 (ni
->ni_flags
& IEEE80211_NODE_HT
);
4288 txwi
->phymode_ifs_stbc_shortgi
|=
4289 ((stbc
& RT2870_TXWI_STBC_MASK
) << RT2870_TXWI_STBC_SHIFT
) |
4290 ((shortgi
& RT2870_TXWI_SHORTGI_MASK
) << RT2870_TXWI_SHORTGI_SHIFT
);
4292 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
4294 txwi
->phymode_ifs_stbc_shortgi
|=
4295 (RT2870_TXWI_PHYMODE_HT_MIXED
<< RT2870_TXWI_PHYMODE_SHIFT
);
4299 if (ieee80211_rate2phytype(ic
->ic_rt
, rate
) != IEEE80211_T_OFDM
)
4301 txwi
->phymode_ifs_stbc_shortgi
|=
4302 (RT2870_TXWI_PHYMODE_CCK
<< RT2870_TXWI_PHYMODE_SHIFT
);
4304 if (rate
!= 2 && (ic
->ic_flags
& IEEE80211_F_SHPREAMBLE
))
4305 mcs
|= RT2870_TXWI_MCS_SHOTPRE
;
4309 txwi
->phymode_ifs_stbc_shortgi
|=
4310 (RT2870_TXWI_PHYMODE_OFDM
<< RT2870_TXWI_PHYMODE_SHIFT
);
4314 if ((ni
->ni_flags
& IEEE80211_NODE_HT
) &&
4315 (ni
->ni_htcap
& IEEE80211_HTCAP_CHWIDTH40
))
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
;
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 mcs
= (stats
>> RT2870_REG_TX_STA_FIFO_MCS_SHIFT
) &
5150 RT2870_REG_TX_STA_FIFO_MCS_MASK
;
5151 pid
= (stats
>> RT2870_REG_TX_STA_FIFO_PID_SHIFT
) &
5152 RT2870_REG_TX_STA_FIFO_PID_MASK
;
5153 retrycnt
= pid
- mcs
;
5155 RT2870_DPRINTF(sc
, RT2870_DEBUG_STATS
,
5156 "%s: FIFO statistic: wcid=0x%02x, ok=%d, mcs=0x%02x, pid=0x%02x, retrycnt=%d\n",
5157 device_get_nameunit(sc
->dev
),
5158 wcid
, ok
, mcs
, pid
, retrycnt
);
5160 rt2870_amrr_tx_complete(&sc
->amrr_node
[wcid
], ok
, retrycnt
);
5168 * rt2870_update_raw_counters
5170 static void rt2870_update_raw_counters(struct rt2870_softc
*sc
)
5174 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_TX_AGG_CNT
);
5176 sc
->tx_nonagg
+= tmp
& 0xffff;
5177 sc
->tx_agg
+= tmp
>> 16;
5179 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_TX_AGG_CNT0
);
5181 sc
->tx_ampdu
+= (tmp
& 0xffff) / 1 + (tmp
>> 16) / 2;
5183 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_TX_AGG_CNT1
);
5185 sc
->tx_ampdu
+= (tmp
& 0xffff) / 3 + (tmp
>> 16) / 4;
5187 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_TX_AGG_CNT2
);
5189 sc
->tx_ampdu
+= (tmp
& 0xffff) / 5 + (tmp
>> 16) / 6;
5191 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_TX_AGG_CNT3
);
5193 sc
->tx_ampdu
+= (tmp
& 0xffff) / 7 + (tmp
>> 16) / 8;
5195 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_TX_AGG_CNT4
);
5197 sc
->tx_ampdu
+= (tmp
& 0xffff) / 9 + (tmp
>> 16) / 10;
5199 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_TX_AGG_CNT5
);
5201 sc
->tx_ampdu
+= (tmp
& 0xffff) / 11 + (tmp
>> 16) / 12;
5203 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_TX_AGG_CNT6
);
5205 sc
->tx_ampdu
+= (tmp
& 0xffff) / 13 + (tmp
>> 16) / 14;
5207 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_TX_AGG_CNT7
);
5209 sc
->tx_ampdu
+= (tmp
& 0xffff) / 15 + (tmp
>> 16) / 16;
5211 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_RX_STA_CNT0
);
5213 sc
->rx_crc_errors
+= tmp
& 0xffff;
5214 sc
->rx_phy_errors
+= tmp
>> 16;
5216 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_RX_STA_CNT1
);
5218 sc
->rx_false_ccas
+= tmp
& 0xffff;
5219 sc
->rx_plcp_errors
+= tmp
>> 16;
5221 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_RX_STA_CNT2
);
5223 sc
->rx_dup_packets
+= tmp
& 0xffff;
5224 sc
->rx_fifo_overflows
+= tmp
>> 16;
5228 * rt2870_txrx_enable
5230 static int rt2870_txrx_enable(struct rt2870_softc
*sc
)
5232 struct ieee80211com
*ic
;
5240 /* enable Tx/Rx DMA engine */
5242 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_SCHDMA_USB_CYC_CFG
);
5247 rt2870_io_mac_write(sc
, RT2870_REG_SCHDMA_USB_CYC_CFG
, tmp
);
5249 if ((sc
->mac_rev
& 0xffff) != 0x0101)
5250 rt2870_io_mac_write(sc
, RT2870_REG_TX_TXOP_CTRL_CFG
, 0x583f);
5252 rt2870_io_mac_write(sc
, RT2870_REG_SYS_CTRL
, RT2870_REG_TX_ENABLE
);
5254 for (ntries
= 0; ntries
< 200; ntries
++)
5256 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_SCHDMA_WPDMA_GLO_CFG
);
5257 if (!(tmp
& (RT2870_REG_TX_DMA_BUSY
| RT2870_REG_RX_DMA_BUSY
)))
5265 printf("%s: timeout waiting for DMA engine\n",
5266 device_get_nameunit(sc
->dev
));
5272 rt2870_io_mac_write(sc
, RT2870_REG_SCHDMA_WMM_TXOP0_CFG
, 0);
5273 rt2870_io_mac_write(sc
, RT2870_REG_SCHDMA_WMM_TXOP1_CFG
,
5276 tmp
|= RT2870_REG_TX_WB_DDONE
|
5277 RT2870_REG_RX_DMA_ENABLE
|
5278 RT2870_REG_TX_DMA_ENABLE
;
5280 rt2870_io_mac_write(sc
, RT2870_REG_SCHDMA_WPDMA_GLO_CFG
, tmp
);
5282 tmp
= RT2870_REG_USB_DMA_TX_ENABLE
|
5283 RT2870_REG_USB_DMA_RX_ENABLE
|
5284 RT2870_REG_USB_DMA_RX_AGG_ENABLE
|
5285 /* Rx agg limit in unit of 1024 byte */
5286 ((RT2870_USB_RX_BULK_BUFLEN
/ 1024 - 3) << RT2870_REG_USB_DMA_RX_AGG_LIMIT_SHIFT
) |
5287 /* Rx agg timeout in unit of 33ns */
5290 rt2870_io_mac_write(sc
, RT2870_REG_SCHDMA_USB_DMA_CFG
, tmp
);
5294 tmp
= RT2870_REG_RX_FILTER_DROP_CRC_ERR
|
5295 RT2870_REG_RX_FILTER_DROP_PHY_ERR
;
5297 if (ic
->ic_opmode
!= IEEE80211_M_MONITOR
)
5299 tmp
|= RT2870_REG_RX_FILTER_DROP_DUPL
|
5300 RT2870_REG_RX_FILTER_DROP_CTS
|
5301 RT2870_REG_RX_FILTER_DROP_BA
|
5302 RT2870_REG_RX_FILTER_DROP_ACK
|
5303 RT2870_REG_RX_FILTER_DROP_VER_ERR
|
5304 RT2870_REG_RX_FILTER_DROP_CTRL_RSV
|
5305 RT2870_REG_RX_FILTER_DROP_CFACK
|
5306 RT2870_REG_RX_FILTER_DROP_CFEND
;
5308 if (ic
->ic_opmode
== IEEE80211_M_STA
)
5309 tmp
|= RT2870_REG_RX_FILTER_DROP_RTS
|
5310 RT2870_REG_RX_FILTER_DROP_PSPOLL
;
5312 if (!(ifp
->if_flags
& IFF_PROMISC
))
5313 tmp
|= RT2870_REG_RX_FILTER_DROP_UC_NOME
;
5316 rt2870_io_mac_write(sc
, RT2870_REG_RX_FILTER_CFG
, tmp
);
5318 rt2870_io_mac_write(sc
, RT2870_REG_SYS_CTRL
,
5319 RT2870_REG_RX_ENABLE
| RT2870_REG_TX_ENABLE
);
5325 * rt2870_alloc_rx_ring
5327 static int rt2870_alloc_rx_ring(struct rt2870_softc
*sc
,
5328 struct rt2870_softc_rx_ring
*ring
)
5330 struct rt2870_softc_rx_data
*data
;
5333 STAILQ_INIT(&ring
->inactive
);
5334 STAILQ_INIT(&ring
->active
);
5335 STAILQ_INIT(&ring
->done
);
5337 for (i
= 0; i
< RT2870_SOFTC_RX_RING_DATA_COUNT
; i
++)
5339 data
= &ring
->data
[i
];
5341 data
->buf
= malloc(RT2870_USB_RX_BULK_BUFLEN
, M_USBDEV
, M_NOWAIT
);
5342 if (data
->buf
== NULL
)
5344 printf("%s: could not allocate Rx buffer\n",
5345 device_get_nameunit(sc
->dev
));
5350 STAILQ_INSERT_TAIL(&ring
->inactive
, data
, next
);
5357 rt2870_free_rx_ring(sc
, ring
);
5363 * rt2870_reset_rx_ring
5365 static void rt2870_reset_rx_ring(struct rt2870_softc
*sc
,
5366 struct rt2870_softc_rx_ring
*ring
)
5368 struct rt2870_softc_rx_data
*data
;
5371 STAILQ_INIT(&ring
->inactive
);
5372 STAILQ_INIT(&ring
->active
);
5373 STAILQ_INIT(&ring
->done
);
5375 for (i
= 0; i
< RT2870_SOFTC_RX_RING_DATA_COUNT
; i
++)
5377 data
= &ring
->data
[i
];
5379 STAILQ_INSERT_TAIL(&ring
->inactive
, data
, next
);
5384 * rt2870_free_rx_ring
5386 static void rt2870_free_rx_ring(struct rt2870_softc
*sc
,
5387 struct rt2870_softc_rx_ring
*ring
)
5389 struct rt2870_softc_rx_data
*data
;
5392 for (i
= 0; i
< RT2870_SOFTC_RX_RING_DATA_COUNT
; i
++)
5394 data
= &ring
->data
[i
];
5396 if (data
->buf
!= NULL
)
5398 free(data
->buf
, M_USBDEV
);
5405 * rt2870_alloc_tx_ring
5407 static int rt2870_alloc_tx_ring(struct rt2870_softc
*sc
,
5408 struct rt2870_softc_tx_ring
*ring
, int qid
)
5410 struct rt2870_softc_tx_data
*data
;
5413 STAILQ_INIT(&ring
->inactive
);
5414 STAILQ_INIT(&ring
->pending
);
5415 STAILQ_INIT(&ring
->active
);
5416 STAILQ_INIT(&ring
->done
);
5421 for (i
= 0; i
< RT2870_SOFTC_TX_RING_DATA_COUNT
; i
++)
5423 data
= &ring
->data
[i
];
5425 data
->buf
= malloc(RT2870_TX_DESC_SIZE
+ MJUMPAGESIZE
, M_USBDEV
, M_NOWAIT
);
5426 if (data
->buf
== NULL
)
5428 printf("%s: could not allocate Tx buffer\n",
5429 device_get_nameunit(sc
->dev
));
5434 memset(data
->buf
, 0, RT2870_TX_DESC_SIZE
);
5436 STAILQ_INSERT_TAIL(&ring
->inactive
, data
, next
);
5443 rt2870_free_tx_ring(sc
, ring
);
5449 * rt2870_reset_tx_ring
5451 static void rt2870_reset_tx_ring(struct rt2870_softc
*sc
,
5452 struct rt2870_softc_tx_ring
*ring
)
5454 struct rt2870_softc_tx_data
*data
;
5457 STAILQ_INIT(&ring
->inactive
);
5458 STAILQ_INIT(&ring
->pending
);
5459 STAILQ_INIT(&ring
->active
);
5460 STAILQ_INIT(&ring
->done
);
5464 for (i
= 0; i
< RT2870_SOFTC_TX_RING_DATA_COUNT
; i
++)
5466 data
= &ring
->data
[i
];
5468 if (data
->m
!= NULL
)
5474 if (data
->ni
!= NULL
)
5476 ieee80211_free_node(data
->ni
);
5480 STAILQ_INSERT_TAIL(&ring
->inactive
, data
, next
);
5485 * rt2870_free_tx_ring
5487 static void rt2870_free_tx_ring(struct rt2870_softc
*sc
,
5488 struct rt2870_softc_tx_ring
*ring
)
5490 struct rt2870_softc_tx_data
*data
;
5493 for (i
= 0; i
< RT2870_SOFTC_TX_RING_DATA_COUNT
; i
++)
5495 data
= &ring
->data
[i
];
5497 if (data
->buf
!= NULL
)
5499 free(data
->buf
, M_USBDEV
);
5503 if (data
->m
!= NULL
)
5509 if (data
->ni
!= NULL
)
5511 ieee80211_free_node(data
->ni
);
5518 * rt2870_reset_cmd_ring
5520 static void rt2870_reset_cmd_ring(struct rt2870_softc
*sc
,
5521 struct rt2870_softc_cmd_ring
*ring
)
5523 struct rt2870_softc_cmd
*cmd
;
5526 STAILQ_INIT(&ring
->inactive
);
5527 STAILQ_INIT(&ring
->active
);
5531 for (i
= 0; i
< RT2870_SOFTC_CMD_RING_CMD_COUNT
; i
++)
5533 cmd
= &ring
->cmd
[i
];
5535 STAILQ_INSERT_TAIL(&ring
->inactive
, cmd
, next
);
5540 * rt2870_sysctl_attach
5542 static void rt2870_sysctl_attach(struct rt2870_softc
*sc
)
5544 struct sysctl_ctx_list
*ctx
;
5545 struct sysctl_oid
*tree
;
5546 struct sysctl_oid
*stats
;
5548 ctx
= device_get_sysctl_ctx(sc
->dev
);
5549 tree
= device_get_sysctl_tree(sc
->dev
);
5551 stats
= SYSCTL_ADD_NODE(ctx
, SYSCTL_CHILDREN(tree
), OID_AUTO
,
5552 "stats", CTLFLAG_RD
, 0, "statistic");
5554 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5555 "interrupts", CTLFLAG_RD
, &sc
->interrupts
, 0,
5558 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5559 "rx_interrupts", CTLFLAG_RD
, &sc
->rx_interrupts
, 0,
5562 if (sc
->usb_endpoints
== RT2870_SOFTC_USB_XFER_COUNT
)
5564 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5565 "tx_mgmt_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[5], 0,
5566 "Tx MGMT interrupts");
5568 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5569 "tx_hcca_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[4], 0,
5570 "Tx HCCA interrupts");
5573 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5574 "tx_ac3_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[3], 0,
5575 "Tx AC3 interrupts");
5577 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5578 "tx_ac2_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[2], 0,
5579 "Tx AC2 interrupts");
5581 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5582 "tx_ac1_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[1], 0,
5583 "Tx AC1 interrupts");
5585 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5586 "tx_ac0_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[0], 0,
5587 "Tx AC0 interrupts");
5589 if (sc
->usb_endpoints
== RT2870_SOFTC_USB_XFER_COUNT
)
5591 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5592 "tx_mgmt_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[5].queued
, 0,
5593 "Tx MGMT data queued");
5595 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5596 "tx_hcca_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[4].queued
, 0,
5597 "Tx HCCA data queued");
5600 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5601 "tx_ac3_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[3].queued
, 0,
5602 "Tx AC3 data queued");
5604 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5605 "tx_ac2_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[2].queued
, 0,
5606 "Tx AC2 data queued");
5608 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5609 "tx_ac1_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[1].queued
, 0,
5610 "Tx AC1 data queued");
5612 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5613 "tx_ac0_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[0].queued
, 0,
5614 "Tx AC0 data queued");
5616 if (sc
->usb_endpoints
== RT2870_SOFTC_USB_XFER_COUNT
)
5618 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5619 "tx_mgmt_data_queue_full", CTLFLAG_RD
, &sc
->tx_data_queue_full
[5], 0,
5620 "Tx MGMT data queue full");
5622 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5623 "tx_hcca_data_queue_full", CTLFLAG_RD
, &sc
->tx_data_queue_full
[4], 0,
5624 "Tx HCCA data queue full");
5627 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5628 "tx_ac3_data_queue_full", CTLFLAG_RD
, &sc
->tx_data_queue_full
[3], 0,
5629 "Tx AC3 data queue full");
5631 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5632 "tx_ac2_data_queue_full", CTLFLAG_RD
, &sc
->tx_data_queue_full
[2], 0,
5633 "Tx AC2 data queue full");
5635 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5636 "tx_ac1_data_queue_full", CTLFLAG_RD
, &sc
->tx_data_queue_full
[1], 0,
5637 "Tx AC1 data queue full");
5639 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5640 "tx_ac0_data_queue_full", CTLFLAG_RD
, &sc
->tx_data_queue_full
[0], 0,
5641 "Tx AC0 data queue full");
5643 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5644 "tx_watchdog_timeouts", CTLFLAG_RD
, &sc
->tx_watchdog_timeouts
, 0,
5645 "Tx watchdog timeouts");
5647 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5648 "rx_mbuf_alloc_errors", CTLFLAG_RD
, &sc
->rx_mbuf_alloc_errors
, 0,
5649 "Rx mbuf allocation errors");
5651 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5652 "tx_queue_0_not_empty", CTLFLAG_RD
, &sc
->tx_queue_not_empty
[0], 0,
5653 "Tx queue 0 not empty");
5655 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5656 "tx_queue_1_not_empty", CTLFLAG_RD
, &sc
->tx_queue_not_empty
[1], 0,
5657 "Tx queue 1 not empty");
5659 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5660 "tx_beacons", CTLFLAG_RD
, &sc
->tx_beacons
, 0,
5663 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5664 "tx_noretryok", CTLFLAG_RD
, &sc
->tx_noretryok
, 0,
5665 "Tx successfull without retries");
5667 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5668 "tx_retryok", CTLFLAG_RD
, &sc
->tx_retryok
, 0,
5669 "Tx successfull with retries");
5671 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5672 "tx_failed", CTLFLAG_RD
, &sc
->tx_failed
, 0,
5675 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5676 "tx_nonagg", CTLFLAG_RD
, &sc
->tx_nonagg
, 0,
5677 "Tx non-aggregated");
5679 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5680 "tx_agg", CTLFLAG_RD
, &sc
->tx_agg
, 0,
5683 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5684 "tx_ampdu", CTLFLAG_RD
, &sc
->tx_ampdu
, 0,
5687 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5688 "rx_packets", CTLFLAG_RD
, &sc
->rx_packets
, 0,
5691 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5692 "rx_ampdu", CTLFLAG_RD
, &sc
->rx_ampdu
, 0,
5695 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5696 "rx_amsdu", CTLFLAG_RD
, &sc
->rx_amsdu
, 0,
5699 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5700 "rx_crc_errors", CTLFLAG_RD
, &sc
->rx_crc_errors
, 0,
5703 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5704 "rx_phy_errors", CTLFLAG_RD
, &sc
->rx_phy_errors
, 0,
5707 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5708 "rx_false_ccas", CTLFLAG_RD
, &sc
->rx_false_ccas
, 0,
5711 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5712 "rx_plcp_errors", CTLFLAG_RD
, &sc
->rx_plcp_errors
, 0,
5715 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5716 "rx_dup_packets", CTLFLAG_RD
, &sc
->rx_dup_packets
, 0,
5717 "Rx duplicate packets");
5719 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5720 "rx_fifo_overflows", CTLFLAG_RD
, &sc
->rx_fifo_overflows
, 0,
5721 "Rx FIFO overflows");
5724 static device_method_t rt2870_dev_methods
[] =
5726 DEVMETHOD(device_probe
, rt2870_probe
),
5727 DEVMETHOD(device_attach
, rt2870_attach
),
5728 DEVMETHOD(device_detach
, rt2870_detach
),
5732 static driver_t rt2870_driver
=
5736 sizeof(struct rt2870_softc
),
5739 static devclass_t rt2870_dev_class
;
5741 DRIVER_MODULE(rt2870
, uhub
, rt2870_driver
, rt2870_dev_class
,
5744 MODULE_DEPEND(rt2870
, usb
, 1, 1, 1);
5745 MODULE_DEPEND(rt2870
, wlan
, 1, 1, 1);