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_HTCAP_MAXAMSDU_3839
| /* max. A-MSDU Rx length */
657 IEEE80211_HTCAP_CHWIDTH40
| /* HT 40MHz channel width */
658 IEEE80211_HTCAP_GREENFIELD
| /* HT greenfield */
659 IEEE80211_HTCAP_SHORTGI20
| /* HT 20MHz short GI */
660 IEEE80211_HTCAP_SHORTGI40
| /* HT 40MHz short GI */
661 IEEE80211_HTCAP_DSSSCCK40
; /* HT 40MHz DSSS/CCK modulation */
663 /* spatial streams */
665 if (sc
->nrxpath
== 2)
666 ic
->ic_htcaps
|= IEEE80211_HTCAP_RXSTBC_2STREAM
;
667 else if (sc
->nrxpath
== 3)
668 ic
->ic_htcaps
|= IEEE80211_HTCAP_RXSTBC_3STREAM
;
670 ic
->ic_htcaps
|= IEEE80211_HTCAP_RXSTBC_1STREAM
;
673 ic
->ic_htcaps
|= IEEE80211_HTCAP_TXSTBC
;
677 if (sc
->mac_rev
!= 0x28600100)
678 ic
->ic_htcaps
|= IEEE80211_HTCAP_DELBA
;
684 rt2870_init_channels(sc
);
686 rt2870_init_channels_ht40(sc
);
688 ieee80211_ifattach(ic
, sc
->mac_addr
);
690 ic
->ic_vap_create
= rt2870_vap_create
;
691 ic
->ic_vap_delete
= rt2870_vap_delete
;
693 ic
->ic_node_alloc
= rt2870_node_alloc
;
694 ic
->ic_setregdomain
= rt2870_setregdomain
;
695 ic
->ic_getradiocaps
= rt2870_getradiocaps
;
696 ic
->ic_scan_start
= rt2870_scan_start
;
697 ic
->ic_scan_end
= rt2870_scan_end
;
698 ic
->ic_set_channel
= rt2870_set_channel
;
699 ic
->ic_newassoc
= rt2870_newassoc
;
700 ic
->ic_updateslot
= rt2870_updateslot
;
701 ic
->ic_update_promisc
= rt2870_update_promisc
;
702 ic
->ic_update_mcast
= rt2870_update_mcast
;
703 ic
->ic_wme
.wme_update
= rt2870_wme_update
;
704 ic
->ic_raw_xmit
= rt2870_raw_xmit
;
706 sc
->recv_action
= ic
->ic_recv_action
;
707 ic
->ic_recv_action
= rt2870_recv_action
;
709 sc
->send_action
= ic
->ic_send_action
;
710 ic
->ic_send_action
= rt2870_send_action
;
712 /* hardware requires padding between 802.11 frame header and body */
714 ic
->ic_flags
|= IEEE80211_F_DATAPAD
| IEEE80211_F_DOTH
;
716 ic
->ic_flags_ext
|= IEEE80211_FEXT_SWBMISS
;
718 ieee80211_radiotap_attach(ic
,
719 &sc
->txtap
.ihdr
, sizeof(sc
->txtap
),
720 RT2870_SOFTC_TX_RADIOTAP_PRESENT
,
721 &sc
->rxtap
.ihdr
, sizeof(sc
->rxtap
),
722 RT2870_SOFTC_RX_RADIOTAP_PRESENT
);
724 /* init task queue */
726 TASK_INIT(&sc
->rx_done_task
, 0, rt2870_rx_done_task
, sc
);
727 TASK_INIT(&sc
->tx_done_task
, 0, rt2870_tx_done_task
, sc
);
728 TASK_INIT(&sc
->periodic_task
, 0, rt2870_periodic_task
, sc
);
729 TASK_INIT(&sc
->cmd_task
, 0, rt2870_cmd_task
, sc
);
731 sc
->rx_process_limit
= 100;
733 sc
->taskqueue
= taskqueue_create("rt2870_taskq", M_NOWAIT
,
734 taskqueue_thread_enqueue
, &sc
->taskqueue
);
736 taskqueue_start_threads(&sc
->taskqueue
, 1, PI_NET
, "%s taskq",
737 device_get_nameunit(sc
->dev
));
739 rt2870_sysctl_attach(sc
);
742 ieee80211_announce(ic
);
748 /* stop all USB transfers */
750 usbd_transfer_unsetup(sc
->usb_xfer
, sc
->usb_endpoints
);
752 /* free Tx and Rx rings */
754 for (i
= 0; i
< sc
->usb_endpoints
- 1; i
++)
755 rt2870_free_tx_ring(sc
, &sc
->tx_ring
[i
]);
757 rt2870_free_rx_ring(sc
, &sc
->rx_ring
);
759 mtx_destroy(&sc
->lock
);
767 static int rt2870_detach(device_t dev
)
769 struct rt2870_softc
*sc
;
770 struct ieee80211com
*ic
;
774 if (!device_is_attached(dev
))
777 sc
= device_get_softc(dev
);
781 RT2870_DPRINTF(sc
, RT2870_DEBUG_ANY
,
783 device_get_nameunit(sc
->dev
));
785 RT2870_SOFTC_LOCK(sc
);
789 ifp
->if_drv_flags
&= ~(IFF_DRV_RUNNING
| IFF_DRV_OACTIVE
);
791 callout_stop(&sc
->periodic_ch
);
792 callout_stop(&sc
->tx_watchdog_ch
);
794 RT2870_SOFTC_UNLOCK(sc
);
796 taskqueue_block(sc
->taskqueue
);
798 taskqueue_drain(sc
->taskqueue
, &sc
->rx_done_task
);
799 taskqueue_drain(sc
->taskqueue
, &sc
->tx_done_task
);
800 taskqueue_drain(sc
->taskqueue
, &sc
->periodic_task
);
801 taskqueue_drain(sc
->taskqueue
, &sc
->cmd_task
);
803 /* stop all USB transfers */
805 usbd_transfer_unsetup(sc
->usb_xfer
, sc
->usb_endpoints
);
807 RT2870_SOFTC_LOCK(sc
);
809 /* free Tx and Rx rings */
811 for (i
= 0; i
< sc
->usb_endpoints
- 1; i
++)
812 rt2870_free_tx_ring(sc
, &sc
->tx_ring
[i
]);
814 rt2870_free_rx_ring(sc
, &sc
->rx_ring
);
816 RT2870_SOFTC_UNLOCK(sc
);
818 ieee80211_ifdetach(ic
);
822 taskqueue_free(sc
->taskqueue
);
824 mtx_destroy(&sc
->lock
);
830 * rt2870_init_channels
832 static void rt2870_init_channels(struct rt2870_softc
*sc
)
835 struct ieee80211com
*ic
;
836 struct ieee80211_channel
*c
;
842 /* set supported channels for 2GHz band */
844 for (i
= 1; i
<= 14; i
++)
846 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
847 flags
= IEEE80211_CHAN_B
;
849 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
853 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
854 flags
= IEEE80211_CHAN_B
| IEEE80211_CHAN_HT20
;
856 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
860 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
861 flags
= IEEE80211_CHAN_G
;
863 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
867 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
868 flags
= IEEE80211_CHAN_G
| IEEE80211_CHAN_HT20
;
870 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
875 /* set supported channels for 5GHz band */
877 if (sc
->rf_rev
== RT2870_EEPROM_RF_2850
||
878 sc
->rf_rev
== RT2870_EEPROM_RF_2750
)
880 for (i
= 36; i
<= 64; i
+= 4)
882 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
883 flags
= IEEE80211_CHAN_A
;
885 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
889 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
890 flags
= IEEE80211_CHAN_A
| IEEE80211_CHAN_HT20
;
892 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
897 for (i
= 100; i
<= 140; i
+= 4)
899 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
900 flags
= IEEE80211_CHAN_A
;
902 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
906 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
907 flags
= IEEE80211_CHAN_A
| IEEE80211_CHAN_HT20
;
909 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
914 for (i
= 149; i
<= 165; i
+= 4)
916 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
917 flags
= IEEE80211_CHAN_A
;
919 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
923 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
924 flags
= IEEE80211_CHAN_A
| IEEE80211_CHAN_HT20
;
926 c
->ic_freq
= ieee80211_ieee2mhz(i
, flags
);
934 * rt2870_init_channels_ht40
936 static void rt2870_init_channels_ht40(struct rt2870_softc
*sc
)
939 struct ieee80211com
*ic
;
940 struct ieee80211_channel
*c
, *cent
, *ext
;
946 /* set supported channels for 2GHz band */
948 for (i
= 1; i
<= 14; i
++)
950 flags
= IEEE80211_CHAN_G
| IEEE80211_CHAN_HT40
;
952 /* find the center channel */
954 cent
= ieee80211_find_channel_byieee(ic
, i
,
955 flags
& ~IEEE80211_CHAN_HT
);
958 printf("%s: skip channel %d, could not find center channel\n",
959 device_get_nameunit(sc
->dev
), i
);
963 /* find the extension channel */
965 ext
= ieee80211_find_channel(ic
, cent
->ic_freq
+ 20,
966 flags
& ~IEEE80211_CHAN_HT
);
969 printf("%s: skip channel %d, could not find extension channel\n",
970 device_get_nameunit(sc
->dev
), i
);
974 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
977 c
->ic_extieee
= ext
->ic_ieee
;
978 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
979 c
->ic_flags
|= IEEE80211_CHAN_HT40U
;
981 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
984 c
->ic_extieee
= cent
->ic_ieee
;
985 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
986 c
->ic_flags
|= IEEE80211_CHAN_HT40D
;
989 /* set supported channels for 5GHz band */
991 if (sc
->rf_rev
== RT2870_EEPROM_RF_2850
||
992 sc
->rf_rev
== RT2870_EEPROM_RF_2750
)
994 for (i
= 36; i
<= 64; i
+= 4)
996 flags
= IEEE80211_CHAN_A
| IEEE80211_CHAN_HT40
;
998 /* find the center channel */
1000 cent
= ieee80211_find_channel_byieee(ic
, i
,
1001 flags
& ~IEEE80211_CHAN_HT
);
1004 printf("%s: skip channel %d, could not find center channel\n",
1005 device_get_nameunit(sc
->dev
), i
);
1009 /* find the extension channel */
1011 ext
= ieee80211_find_channel(ic
, cent
->ic_freq
+ 20,
1012 flags
& ~IEEE80211_CHAN_HT
);
1015 printf("%s: skip channel %d, could not find extension channel\n",
1016 device_get_nameunit(sc
->dev
), i
);
1020 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1023 c
->ic_extieee
= ext
->ic_ieee
;
1024 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1025 c
->ic_flags
|= IEEE80211_CHAN_HT40U
;
1027 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1030 c
->ic_extieee
= cent
->ic_ieee
;
1031 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1032 c
->ic_flags
|= IEEE80211_CHAN_HT40D
;
1035 for (i
= 100; i
<= 140; i
+= 4)
1037 flags
= IEEE80211_CHAN_A
| IEEE80211_CHAN_HT40
;
1039 /* find the center channel */
1041 cent
= ieee80211_find_channel_byieee(ic
, i
,
1042 flags
& ~IEEE80211_CHAN_HT
);
1045 printf("%s: skip channel %d, could not find center channel\n",
1046 device_get_nameunit(sc
->dev
), i
);
1050 /* find the extension channel */
1052 ext
= ieee80211_find_channel(ic
, cent
->ic_freq
+ 20,
1053 flags
& ~IEEE80211_CHAN_HT
);
1056 printf("%s: skip channel %d, could not find extension channel\n",
1057 device_get_nameunit(sc
->dev
), i
);
1061 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1064 c
->ic_extieee
= ext
->ic_ieee
;
1065 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1066 c
->ic_flags
|= IEEE80211_CHAN_HT40U
;
1068 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1071 c
->ic_extieee
= cent
->ic_ieee
;
1072 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1073 c
->ic_flags
|= IEEE80211_CHAN_HT40D
;
1076 for (i
= 149; i
<= 165; i
+= 4)
1078 flags
= IEEE80211_CHAN_A
| IEEE80211_CHAN_HT40
;
1080 /* find the center channel */
1082 cent
= ieee80211_find_channel_byieee(ic
, i
,
1083 flags
& ~IEEE80211_CHAN_HT
);
1086 printf("%s: skip channel %d, could not find center channel\n",
1087 device_get_nameunit(sc
->dev
), i
);
1091 /* find the extension channel */
1093 ext
= ieee80211_find_channel(ic
, cent
->ic_freq
+ 20,
1094 flags
& ~IEEE80211_CHAN_HT
);
1097 printf("%s: skip channel %d, could not find extension channel\n",
1098 device_get_nameunit(sc
->dev
), i
);
1102 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1105 c
->ic_extieee
= ext
->ic_ieee
;
1106 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1107 c
->ic_flags
|= IEEE80211_CHAN_HT40U
;
1109 c
= &ic
->ic_channels
[ic
->ic_nchans
++];
1112 c
->ic_extieee
= cent
->ic_ieee
;
1113 c
->ic_flags
&= ~IEEE80211_CHAN_HT
;
1114 c
->ic_flags
|= IEEE80211_CHAN_HT40D
;
1120 * rt2870_init_locked
1122 static void rt2870_init_locked(void *priv
)
1124 struct rt2870_softc
*sc
;
1126 struct ieee80211com
*ic
;
1127 int ntries
, error
, i
;
1128 uint32_t tmp
, stacnt
[6];
1134 RT2870_DPRINTF(sc
, RT2870_DEBUG_ANY
,
1135 "%s: initializing\n",
1136 device_get_nameunit(sc
->dev
));
1138 RT2870_SOFTC_ASSERT_LOCKED(sc
);
1140 if (!(sc
->flags
& RT2870_SOFTC_FLAGS_UCODE_LOADED
))
1142 RT2870_DPRINTF(sc
, RT2870_DEBUG_ANY
,
1143 "%s: loading 8051 microcode\n",
1144 device_get_nameunit(sc
->dev
));
1146 error
= rt2870_io_mcu_load_ucode(sc
, rt2870_ucode
, sizeof(rt2870_ucode
));
1149 printf("%s: could not load 8051 microcode\n",
1150 device_get_nameunit(sc
->dev
));
1154 RT2870_DPRINTF(sc
, RT2870_DEBUG_ANY
,
1155 "%s: 8051 microcode was successfully loaded\n",
1156 device_get_nameunit(sc
->dev
));
1158 sc
->flags
|= RT2870_SOFTC_FLAGS_UCODE_LOADED
;
1161 /* wait while DMA engine is busy */
1163 for (ntries
= 0; ntries
< 100; ntries
++)
1165 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_SCHDMA_WPDMA_GLO_CFG
);
1166 if (!(tmp
& (RT2870_REG_TX_DMA_BUSY
| RT2870_REG_RX_DMA_BUSY
)))
1174 printf("%s: timeout waiting for DMA engine\n",
1175 device_get_nameunit(sc
->dev
));
1180 tmp
|= RT2870_REG_TX_WB_DDONE
;
1182 rt2870_io_mac_write(sc
, RT2870_REG_SCHDMA_WPDMA_GLO_CFG
, tmp
);
1184 /* PBF hardware reset */
1186 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_PBF_SYS_CTRL
);
1190 rt2870_io_mac_write(sc
, RT2870_REG_PBF_SYS_CTRL
, tmp
);
1192 rt2870_io_mac_write(sc
, RT2870_REG_SYS_CTRL
,
1193 RT2870_REG_MAC_SRST
| RT2870_REG_BBP_HRST
);
1195 rt2870_io_mac_write(sc
, RT2870_REG_SCHDMA_USB_DMA_CFG
, 0);
1197 rt2870_io_mcu_reset(sc
);
1199 rt2870_io_mac_write(sc
, RT2870_REG_SYS_CTRL
, 0);
1201 /* init Tx power per rate */
1203 for (i
= 0; i
< RT2870_SOFTC_TXPOW_RATE_COUNT
; i
++)
1205 if (sc
->txpow_rate_20mhz
[i
] == 0xffffffff)
1208 rt2870_io_mac_write(sc
, RT2870_REG_TX_PWR_CFG(i
),
1209 sc
->txpow_rate_20mhz
[i
]);
1212 for (i
= 0; i
< RT2870_DEF_MAC_SIZE
; i
++)
1213 rt2870_io_mac_write(sc
, rt2870_def_mac
[i
].reg
,
1214 rt2870_def_mac
[i
].val
);
1216 /* wait while MAC is busy */
1218 for (ntries
= 0; ntries
< 100; ntries
++)
1220 if (!(rt2870_io_mac_read(sc
, RT2870_REG_STATUS_CFG
) &
1221 (RT2870_REG_STATUS_TX_BUSY
| RT2870_REG_STATUS_RX_BUSY
)))
1229 printf("%s: timeout waiting for MAC\n",
1230 device_get_nameunit(sc
->dev
));
1234 /* clear Host to MCU mailbox */
1236 rt2870_io_mac_write(sc
, RT2870_REG_H2M_MAILBOX_BBP_AGENT
, 0);
1237 rt2870_io_mac_write(sc
, RT2870_REG_H2M_MAILBOX
, 0);
1241 error
= rt2870_init_bbp(sc
);
1245 /* set up maximum buffer sizes */
1247 tmp
= (1 << 12) | RT2870_MAX_AGG_SIZE
;
1249 rt2870_io_mac_write(sc
, RT2870_REG_MAX_LEN_CFG
, tmp
);
1251 if (sc
->mac_rev
== 0x28720200)
1253 /* set max. PSDU length from 16K to 32K bytes */
1255 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_MAX_LEN_CFG
);
1260 rt2870_io_mac_write(sc
, RT2870_REG_MAX_LEN_CFG
, tmp
);
1263 if (sc
->mac_rev
>= 0x28720200 && sc
->mac_rev
< 0x30700200)
1265 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_MAX_LEN_CFG
);
1270 rt2870_io_mac_write(sc
, RT2870_REG_MAX_LEN_CFG
, tmp
);
1273 /* set mac address */
1275 rt2870_asic_set_macaddr(sc
, IF_LLADDR(ifp
));
1277 /* clear statistic registers */
1279 rt2870_io_mac_read_multi(sc
, RT2870_REG_RX_STA_CNT0
,
1280 stacnt
, sizeof(stacnt
));
1282 /* send LEDs operating mode to microcontroller */
1284 rt2870_io_mcu_cmd(sc
, RT2870_IO_MCU_CMD_LED1
,
1285 RT2870_REG_H2M_TOKEN_NO_INTR
, sc
->led_off
[0]);
1286 rt2870_io_mcu_cmd(sc
, RT2870_IO_MCU_CMD_LED2
,
1287 RT2870_REG_H2M_TOKEN_NO_INTR
, sc
->led_off
[1]);
1288 rt2870_io_mcu_cmd(sc
, RT2870_IO_MCU_CMD_LED3
,
1289 RT2870_REG_H2M_TOKEN_NO_INTR
, sc
->led_off
[2]);
1291 /* write vendor-specific BBP values (from EEPROM) */
1293 for (i
= 0; i
< RT2870_SOFTC_BBP_EEPROM_COUNT
; i
++)
1295 if (sc
->bbp_eeprom
[i
].reg
== 0x00 ||
1296 sc
->bbp_eeprom
[i
].reg
== 0xff)
1299 rt2870_io_bbp_write(sc
, sc
->bbp_eeprom
[i
].reg
,
1300 sc
->bbp_eeprom
[i
].val
);
1303 /* disable non-existing Rx chains */
1305 tmp
= rt2870_io_bbp_read(sc
, 3);
1307 tmp
&= ~((1 << 4) | (1 << 3));
1309 if (sc
->nrxpath
== 3)
1311 else if (sc
->nrxpath
== 2)
1314 rt2870_io_bbp_write(sc
, 3, tmp
);
1316 /* disable non-existing Tx chains */
1318 tmp
= rt2870_io_bbp_read(sc
, 1);
1320 tmp
&= ~((1 << 4) | (1 << 3));
1322 if (sc
->ntxpath
== 2)
1325 rt2870_io_bbp_write(sc
, 1, tmp
);
1327 /* set current channel */
1329 rt2870_rf_set_chan(sc
, ic
->ic_curchan
);
1331 /* turn radio LED on */
1333 rt2870_led_cmd(sc
, RT2870_LED_CMD_RADIO_ON
);
1335 rt2870_io_mcu_cmd(sc
, RT2870_IO_MCU_CMD_BOOT
,
1336 RT2870_REG_H2M_TOKEN_NO_INTR
, 0);
1338 /* set RTS threshold */
1340 rt2870_asic_update_rtsthreshold(sc
);
1344 rt2870_asic_update_txpower(sc
);
1346 /* set up protection mode */
1348 rt2870_asic_updateprot(sc
);
1350 /* clear key tables */
1352 rt2870_asic_clear_keytables(sc
);
1354 /* clear beacon frame space (entries = 8, entry size = 512) */
1356 rt2870_io_mac_set_region_4(sc
, RT2870_REG_BEACON_BASE(0), 0, 1024);
1358 if (rt2870_txrx_enable(sc
) != 0)
1361 /* clear garbage interrupts */
1363 tmp
= rt2870_io_mac_read(sc
, 0x1300);
1365 taskqueue_unblock(sc
->taskqueue
);
1367 /* init Tx and Rx rings */
1369 for(i
= 0; i
< sc
->usb_endpoints
- 1; i
++)
1370 rt2870_reset_tx_ring(sc
, &sc
->tx_ring
[i
]);
1372 rt2870_reset_rx_ring(sc
, &sc
->rx_ring
);
1374 rt2870_reset_cmd_ring(sc
, &sc
->cmd_ring
);
1376 for(i
= 0; i
< sc
->usb_endpoints
- 1; i
++)
1378 usbd_xfer_set_priv(sc
->usb_xfer
[i
+ 1], &sc
->tx_ring
[i
]);
1379 usbd_xfer_set_stall(sc
->usb_xfer
[i
+ 1]);
1382 /* start up the receive pipe */
1384 for(i
= 0; i
< RT2870_SOFTC_RX_RING_DATA_COUNT
; i
++)
1385 usbd_transfer_start(sc
->usb_xfer
[0]);
1387 ifp
->if_drv_flags
&= ~IFF_DRV_OACTIVE
;
1388 ifp
->if_drv_flags
|= IFF_DRV_RUNNING
;
1390 sc
->periodic_round
= 0;
1392 callout_reset(&sc
->periodic_ch
, hz
/ 10, rt2870_periodic
, sc
);
1398 rt2870_stop_locked(sc
);
1404 static void rt2870_init(void *priv
)
1406 struct rt2870_softc
*sc
;
1410 RT2870_SOFTC_LOCK(sc
);
1412 rt2870_init_locked(sc
);
1414 RT2870_SOFTC_UNLOCK(sc
);
1420 static int rt2870_init_bbp(struct rt2870_softc
*sc
)
1425 for (ntries
= 0; ntries
< 20; ntries
++)
1427 tmp
= rt2870_io_bbp_read(sc
, 0);
1428 if (tmp
!= 0x00 && tmp
!= 0xff)
1432 if (tmp
== 0x00 || tmp
== 0xff)
1434 printf("%s: timeout waiting for BBP to wakeup\n",
1435 device_get_nameunit(sc
->dev
));
1439 for (i
= 0; i
< RT2870_DEF_BBP_SIZE
; i
++)
1440 rt2870_io_bbp_write(sc
, rt2870_def_bbp
[i
].reg
,
1441 rt2870_def_bbp
[i
].val
);
1443 if ((sc
->mac_rev
& 0xffff) != 0x0101)
1444 rt2870_io_bbp_write(sc
, 84, 0x19);
1446 if (sc
->mac_rev
== 0x28600100)
1448 rt2870_io_bbp_write(sc
, 69, 0x16);
1449 rt2870_io_bbp_write(sc
, 73, 0x12);
1456 * rt2870_stop_locked
1458 static void rt2870_stop_locked(void *priv
)
1460 struct rt2870_softc
*sc
;
1462 struct ieee80211com
*ic
;
1470 RT2870_DPRINTF(sc
, RT2870_DEBUG_ANY
,
1472 device_get_nameunit(sc
->dev
));
1474 RT2870_SOFTC_ASSERT_LOCKED(sc
);
1478 if (ifp
->if_drv_flags
& IFF_DRV_RUNNING
)
1479 rt2870_led_cmd(sc
, RT2870_LED_CMD_RADIO_OFF
);
1481 ifp
->if_drv_flags
&= ~(IFF_DRV_RUNNING
| IFF_DRV_OACTIVE
);
1483 callout_stop(&sc
->periodic_ch
);
1484 callout_stop(&sc
->tx_watchdog_ch
);
1486 RT2870_SOFTC_UNLOCK(sc
);
1488 taskqueue_block(sc
->taskqueue
);
1490 taskqueue_drain(sc
->taskqueue
, &sc
->rx_done_task
);
1491 taskqueue_drain(sc
->taskqueue
, &sc
->tx_done_task
);
1492 taskqueue_drain(sc
->taskqueue
, &sc
->periodic_task
);
1493 taskqueue_drain(sc
->taskqueue
, &sc
->cmd_task
);
1495 RT2870_SOFTC_LOCK(sc
);
1497 /* clear key tables */
1499 rt2870_asic_clear_keytables(sc
);
1503 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_SYS_CTRL
);
1505 tmp
&= ~(RT2870_REG_RX_ENABLE
| RT2870_REG_TX_ENABLE
);
1507 rt2870_io_mac_write(sc
, RT2870_REG_SYS_CTRL
, tmp
);
1509 rt2870_io_mac_write(sc
, RT2870_REG_SCHDMA_USB_DMA_CFG
, 0);
1513 rt2870_io_mac_write(sc
, RT2870_REG_SYS_CTRL
,
1514 RT2870_REG_MAC_SRST
| RT2870_REG_BBP_HRST
);
1515 rt2870_io_mac_write(sc
, RT2870_REG_SYS_CTRL
, 0);
1517 /* abort any pending transfers */
1519 for (i
= 0; i
< sc
->usb_endpoints
; i
++)
1520 usbd_transfer_stop(sc
->usb_xfer
[i
]);
1526 static void rt2870_stop(void *priv
)
1528 struct rt2870_softc
*sc
;
1532 RT2870_SOFTC_LOCK(sc
);
1534 rt2870_stop_locked(sc
);
1536 RT2870_SOFTC_UNLOCK(sc
);
1542 static void rt2870_start(struct ifnet
*ifp
)
1544 struct rt2870_softc
*sc
;
1545 struct ieee80211_node
*ni
;
1551 RT2870_SOFTC_LOCK(sc
);
1553 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
1555 RT2870_SOFTC_UNLOCK(sc
);
1561 IF_POLL(&ifp
->if_snd
, m
);
1565 IFQ_DRV_DEQUEUE(&ifp
->if_snd
, m
);
1567 ni
= (struct ieee80211_node
*) m
->m_pkthdr
.rcvif
;
1569 qid
= M_WME_GETAC(m
);
1571 if (sc
->tx_ring
[qid
].queued
>= RT2870_SOFTC_TX_RING_DATA_COUNT
)
1573 RT2870_DPRINTF(sc
, RT2870_DEBUG_TX
,
1574 "%s: if_start: Tx ring with qid=%d is full\n",
1575 device_get_nameunit(sc
->dev
), qid
);
1578 ieee80211_free_node(ni
);
1580 ifp
->if_drv_flags
|= IFF_DRV_OACTIVE
;
1583 sc
->tx_data_queue_full
[qid
]++;
1588 if (rt2870_tx_data(sc
, m
, ni
, qid
) != 0)
1590 ieee80211_free_node(ni
);
1595 sc
->tx_timer
= RT2870_TX_WATCHDOG_TIMEOUT
;
1597 callout_reset(&sc
->tx_watchdog_ch
, hz
, rt2870_tx_watchdog
, sc
);
1600 RT2870_SOFTC_UNLOCK(sc
);
1606 static int rt2870_ioctl(struct ifnet
*ifp
, u_long cmd
, caddr_t data
)
1608 struct rt2870_softc
*sc
;
1609 struct ieee80211com
*ic
;
1611 int error
, startall
;
1615 ifr
= (struct ifreq
*) data
;
1624 RT2870_SOFTC_LOCK(sc
);
1626 if (ifp
->if_flags
& IFF_UP
)
1628 if (ifp
->if_drv_flags
& IFF_DRV_RUNNING
)
1630 if ((ifp
->if_flags
^ sc
->if_flags
) & IFF_PROMISC
)
1631 rt2870_asic_update_promisc(sc
);
1635 rt2870_init_locked(sc
);
1641 if (ifp
->if_drv_flags
& IFF_DRV_RUNNING
)
1642 rt2870_stop_locked(sc
);
1645 sc
->if_flags
= ifp
->if_flags
;
1647 RT2870_SOFTC_UNLOCK(sc
);
1650 ieee80211_start_all(ic
);
1655 error
= ifmedia_ioctl(ifp
, ifr
, &ic
->ic_media
, cmd
);
1659 error
= ether_ioctl(ifp
, cmd
, data
);
1673 static struct ieee80211vap
*rt2870_vap_create(struct ieee80211com
*ic
,
1674 const char name
[IFNAMSIZ
], int unit
, int opmode
, int flags
,
1675 const uint8_t bssid
[IEEE80211_ADDR_LEN
],
1676 const uint8_t mac
[IEEE80211_ADDR_LEN
])
1678 struct rt2870_softc
*sc
;
1680 struct rt2870_softc_vap
*rvap
;
1681 struct ieee80211vap
*vap
;
1686 RT2870_DPRINTF(sc
, RT2870_DEBUG_STATE
,
1687 "%s: VAP create: opmode=%s\n",
1688 device_get_nameunit(sc
->dev
),
1689 ieee80211_opmode_name
[opmode
]);
1693 case IEEE80211_M_MONITOR
:
1694 case IEEE80211_M_IBSS
:
1695 case IEEE80211_M_STA
:
1696 case IEEE80211_M_AHDEMO
:
1697 case IEEE80211_M_HOSTAP
:
1698 case IEEE80211_M_MBSS
:
1699 if (!TAILQ_EMPTY(&ic
->ic_vaps
))
1701 if_printf(ifp
, "only 1 VAP supported\n");
1705 if (opmode
== IEEE80211_M_STA
)
1706 flags
|= IEEE80211_CLONE_NOBEACONS
;
1709 case IEEE80211_M_WDS
:
1710 if (TAILQ_EMPTY(&ic
->ic_vaps
) || ic
->ic_opmode
!= IEEE80211_M_HOSTAP
)
1712 if_printf(ifp
, "WDS only supported in AP mode\n");
1716 flags
&= ~IEEE80211_CLONE_BSSID
;
1720 if_printf(ifp
, "unknown opmode %d\n", opmode
);
1724 rvap
= (struct rt2870_softc_vap
*) malloc(sizeof(struct rt2870_softc_vap
),
1725 M_80211_VAP
, M_NOWAIT
| M_ZERO
);
1731 ieee80211_vap_setup(ic
, vap
, name
, unit
, opmode
, flags
, bssid
, mac
);
1733 rvap
->newstate
= vap
->iv_newstate
;
1734 vap
->iv_newstate
= rt2870_vap_newstate
;
1736 vap
->iv_reset
= rt2870_vap_reset
;
1737 vap
->iv_key_update_begin
= rt2870_vap_key_update_begin
;
1738 vap
->iv_key_update_end
= rt2870_vap_key_update_end
;
1739 vap
->iv_key_set
= rt2870_vap_key_set
;
1740 vap
->iv_key_delete
= rt2870_vap_key_delete
;
1741 vap
->iv_update_beacon
= rt2870_vap_update_beacon
;
1743 rt2870_amrr_init(&rvap
->amrr
, vap
,
1744 RT2870_AMRR_MIN_SUCCESS_THRESHOLD
,
1745 RT2870_AMRR_MAX_SUCCESS_THRESHOLD
,
1748 ieee80211_vap_attach(vap
, ieee80211_media_change
, ieee80211_media_status
);
1750 ic
->ic_opmode
= opmode
;
1758 static void rt2870_vap_delete(struct ieee80211vap
*vap
)
1760 struct rt2870_softc
*sc
;
1761 struct ieee80211com
*ic
;
1763 struct rt2870_softc_vap
*rvap
;
1768 rvap
= (struct rt2870_softc_vap
*) vap
;
1770 RT2870_DPRINTF(sc
, RT2870_DEBUG_STATE
,
1771 "%s: VAP delete: opmode=%s\n",
1772 device_get_nameunit(sc
->dev
),
1773 ieee80211_opmode_name
[vap
->iv_opmode
]);
1775 rt2870_amrr_cleanup(&rvap
->amrr
);
1777 ieee80211_vap_detach(vap
);
1779 free(rvap
, M_80211_VAP
);
1785 static int rt2870_vap_reset(struct ieee80211vap
*vap
, u_long cmd
)
1787 struct rt2870_softc
*sc
;
1788 struct ieee80211com
*ic
;
1790 struct rt2870_softc_vap
*rvap
;
1796 rvap
= (struct rt2870_softc_vap
*) vap
;
1798 RT2870_DPRINTF(sc
, RT2870_DEBUG_STATE
,
1799 "%s: VAP reset: cmd=%lu\n",
1800 device_get_nameunit(sc
->dev
), cmd
);
1804 RT2870_SOFTC_LOCK(sc
);
1808 case IEEE80211_IOC_RTSTHRESHOLD
:
1809 rt2870_asic_update_rtsthreshold(sc
);
1812 case IEEE80211_IOC_PROTMODE
:
1813 case IEEE80211_IOC_HTPROTMODE
:
1814 rt2870_asic_updateprot(sc
);
1817 case IEEE80211_IOC_TXPOWER
:
1818 rt2870_asic_update_txpower(sc
);
1821 case IEEE80211_IOC_SHORTGI
:
1822 case IEEE80211_IOC_AMPDU_DENSITY
:
1830 RT2870_SOFTC_UNLOCK(sc
);
1836 * rt2870_vap_newstate
1838 static int rt2870_vap_newstate(struct ieee80211vap
*vap
,
1839 enum ieee80211_state nstate
, int arg
)
1841 struct rt2870_softc
*sc
;
1842 struct ieee80211com
*ic
;
1844 struct rt2870_softc_vap
*rvap
;
1845 struct ieee80211_node
*ni
;
1851 rvap
= (struct rt2870_softc_vap
*) vap
;
1853 RT2870_DPRINTF(sc
, RT2870_DEBUG_STATE
,
1854 "%s: VAP newstate: %s -> %s\n",
1855 device_get_nameunit(sc
->dev
),
1856 ieee80211_state_name
[vap
->iv_state
], ieee80211_state_name
[nstate
]);
1858 error
= rvap
->newstate(vap
, nstate
, arg
);
1862 IEEE80211_UNLOCK(ic
);
1864 RT2870_SOFTC_LOCK(sc
);
1866 /* turn link LED off */
1868 if (nstate
!= IEEE80211_S_RUN
)
1869 rt2870_led_cmd(sc
, RT2870_LED_CMD_RADIO_OFF
);
1873 case IEEE80211_S_INIT
:
1874 rt2870_asic_disable_tsf_sync(sc
);
1877 case IEEE80211_S_RUN
:
1880 rt2870_rf_set_chan(sc
, ni
->ni_chan
);
1882 if (vap
->iv_opmode
!= IEEE80211_M_MONITOR
)
1884 rt2870_asic_enable_mrr(sc
);
1885 rt2870_asic_set_txpreamble(sc
);
1886 rt2870_asic_set_basicrates(sc
);
1887 rt2870_asic_update_txpower(sc
);
1888 rt2870_asic_set_bssid(sc
, ni
->ni_bssid
);
1891 if (vap
->iv_opmode
== IEEE80211_M_HOSTAP
||
1892 vap
->iv_opmode
== IEEE80211_M_IBSS
||
1893 vap
->iv_opmode
== IEEE80211_M_MBSS
)
1895 error
= rt2870_asic_update_beacon(sc
, vap
);
1900 if (vap
->iv_opmode
!= IEEE80211_M_MONITOR
)
1901 rt2870_asic_enable_tsf_sync(sc
);
1903 /* turn link LED on */
1905 if (vap
->iv_opmode
!= IEEE80211_M_MONITOR
)
1907 rt2870_led_cmd(sc
, RT2870_LED_CMD_RADIO_ON
|
1908 (IEEE80211_IS_CHAN_2GHZ(ni
->ni_chan
) ?
1909 RT2870_LED_CMD_LINK_2GHZ
: RT2870_LED_CMD_LINK_5GHZ
));
1917 RT2870_SOFTC_UNLOCK(sc
);
1925 * rt2870_vap_key_update_begin
1927 static void rt2870_vap_key_update_begin(struct ieee80211vap
*vap
)
1929 struct rt2870_softc
*sc
;
1930 struct ieee80211com
*ic
;
1937 RT2870_DPRINTF(sc
, RT2870_DEBUG_KEY
,
1938 "%s: VAP key update begin\n",
1939 device_get_nameunit(sc
->dev
));
1941 taskqueue_block(sc
->taskqueue
);
1943 IF_LOCK(&ifp
->if_snd
);
1947 * rt2870_vap_key_update_end
1949 static void rt2870_vap_key_update_end(struct ieee80211vap
*vap
)
1951 struct rt2870_softc
*sc
;
1952 struct ieee80211com
*ic
;
1959 RT2870_DPRINTF(sc
, RT2870_DEBUG_KEY
,
1960 "%s: VAP key update end\n",
1961 device_get_nameunit(sc
->dev
));
1963 IF_UNLOCK(&ifp
->if_snd
);
1965 taskqueue_unblock(sc
->taskqueue
);
1969 * rt2870_vap_key_set
1971 static int rt2870_vap_key_set(struct ieee80211vap
*vap
,
1972 const struct ieee80211_key
*k
, const uint8_t mac
[IEEE80211_ADDR_LEN
])
1974 struct rt2870_softc
*sc
;
1975 struct ieee80211com
*ic
;
1977 struct ieee80211_node
*ni
;
1978 uint16_t associd
, key_base
, keymode_base
;
1979 uint8_t mode
, vapid
, wcid
, iv
[8];
1982 if (k
->wk_cipher
->ic_cipher
!= IEEE80211_CIPHER_WEP
&&
1983 k
->wk_cipher
->ic_cipher
!= IEEE80211_CIPHER_TKIP
&&
1984 k
->wk_cipher
->ic_cipher
!= IEEE80211_CIPHER_AES_CCM
)
1991 if (vap
->iv_opmode
!= IEEE80211_M_HOSTAP
)
1994 ni
= ieee80211_find_vap_node(&ic
->ic_sta
, vap
, mac
);
1996 associd
= (ni
!= NULL
) ? ni
->ni_associd
: 0;
1998 if ((vap
->iv_opmode
== IEEE80211_M_HOSTAP
) && (ni
!= NULL
))
1999 ieee80211_free_node(ni
);
2001 switch (k
->wk_cipher
->ic_cipher
)
2003 case IEEE80211_CIPHER_WEP
:
2004 if(k
->wk_keylen
< 8)
2005 mode
= RT2870_REG_CIPHER_MODE_WEP40
;
2007 mode
= RT2870_REG_CIPHER_MODE_WEP104
;
2010 case IEEE80211_CIPHER_TKIP
:
2011 mode
= RT2870_REG_CIPHER_MODE_TKIP
;
2014 case IEEE80211_CIPHER_AES_CCM
:
2015 mode
= RT2870_REG_CIPHER_MODE_AES_CCMP
;
2022 RT2870_DPRINTF(sc
, RT2870_DEBUG_KEY
,
2023 "%s: VAP key set: keyix=%d, keylen=%d, associd=0x%04x, mode=%d, group=%d\n",
2024 device_get_nameunit(sc
->dev
), k
->wk_keyix
, k
->wk_keylen
, associd
, mode
,
2025 (k
->wk_flags
& IEEE80211_KEY_GROUP
) ? 1 : 0);
2027 RT2870_SOFTC_LOCK(sc
);
2029 if (!(k
->wk_flags
& IEEE80211_KEY_GROUP
))
2031 /* install pairwise key */
2034 wcid
= RT2870_AID2WCID(associd
);
2035 key_base
= RT2870_REG_PKEY(wcid
);
2037 if (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_WEP
)
2041 iv
[3] = (k
->wk_keyix
<< 6);
2045 if (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_TKIP
)
2047 iv
[0] = (k
->wk_keytsc
>> 8);
2048 iv
[1] = ((iv
[0] | 0x20) & 0x7f);
2049 iv
[2] = k
->wk_keytsc
;
2055 iv
[0] = k
->wk_keytsc
;
2056 iv
[1] = k
->wk_keytsc
>> 8;
2060 iv
[3] = ((k
->wk_keyix
<< 6) | IEEE80211_WEP_EXTIV
);
2061 iv
[4] = (k
->wk_keytsc
>> 16);
2062 iv
[5] = (k
->wk_keytsc
>> 24);
2063 iv
[6] = (k
->wk_keytsc
>> 32);
2064 iv
[7] = (k
->wk_keytsc
>> 40);
2066 RT2870_DPRINTF(sc
, RT2870_DEBUG_KEY
,
2067 "%s: set key: iv=%02x %02x %02x %02x %02x %02x %02x %02x\n",
2068 device_get_nameunit(sc
->dev
),
2069 iv
[0], iv
[1], iv
[2], iv
[3], iv
[4], iv
[5], iv
[6], iv
[7]);
2072 rt2870_io_mac_write_multi(sc
, RT2870_REG_IVEIV(wcid
), iv
, 8);
2074 if (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_TKIP
)
2076 rt2870_io_mac_write_multi(sc
, key_base
, k
->wk_key
, 16);
2078 if (vap
->iv_opmode
!= IEEE80211_M_HOSTAP
)
2080 rt2870_io_mac_write_multi(sc
, key_base
+ 16, &k
->wk_key
[16], 8);
2081 rt2870_io_mac_write_multi(sc
, key_base
+ 24, &k
->wk_key
[24], 8);
2085 rt2870_io_mac_write_multi(sc
, key_base
+ 16, &k
->wk_key
[24], 8);
2086 rt2870_io_mac_write_multi(sc
, key_base
+ 24, &k
->wk_key
[16], 8);
2091 rt2870_io_mac_write_multi(sc
, key_base
, k
->wk_key
, k
->wk_keylen
);
2094 tmp
= ((vapid
& RT2870_REG_VAP_MASK
) << RT2870_REG_VAP_SHIFT
) |
2095 (mode
<< RT2870_REG_CIPHER_MODE_SHIFT
) | RT2870_REG_PKEY_ENABLE
;
2097 rt2870_io_mac_write(sc
, RT2870_REG_WCID_ATTR(wcid
), tmp
);
2100 if ((k
->wk_flags
& IEEE80211_KEY_GROUP
) ||
2101 (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_WEP
))
2103 /* install group key */
2106 key_base
= RT2870_REG_SKEY(vapid
, k
->wk_keyix
);
2107 keymode_base
= RT2870_REG_SKEY_MODE(vapid
);
2109 if (k
->wk_cipher
->ic_cipher
== IEEE80211_CIPHER_TKIP
)
2111 rt2870_io_mac_write_multi(sc
, key_base
, k
->wk_key
, 16);
2113 if (vap
->iv_opmode
!= IEEE80211_M_HOSTAP
)
2115 rt2870_io_mac_write_multi(sc
, key_base
+ 16, &k
->wk_key
[16], 8);
2116 rt2870_io_mac_write_multi(sc
, key_base
+ 24, &k
->wk_key
[24], 8);
2120 rt2870_io_mac_write_multi(sc
, key_base
+ 16, &k
->wk_key
[24], 8);
2121 rt2870_io_mac_write_multi(sc
, key_base
+ 24, &k
->wk_key
[16], 8);
2126 rt2870_io_mac_write_multi(sc
, key_base
, k
->wk_key
, k
->wk_keylen
);
2129 tmp
= rt2870_io_mac_read(sc
, keymode_base
);
2131 tmp
&= ~(0xf << (k
->wk_keyix
* 4 + 16 * (vapid
% 2)));
2132 tmp
|= (mode
<< (k
->wk_keyix
* 4 + 16 * (vapid
% 2)));
2134 rt2870_io_mac_write(sc
, keymode_base
, tmp
);
2137 RT2870_SOFTC_UNLOCK(sc
);
2143 * rt2870_vap_key_delete
2145 static int rt2870_vap_key_delete(struct ieee80211vap
*vap
,
2146 const struct ieee80211_key
*k
)
2148 struct rt2870_softc
*sc
;
2149 struct ieee80211com
*ic
;
2151 struct ieee80211_node
*ni
;
2152 struct rt2870_cmd_argv_keydelete cmd_argv
;
2159 associd
= (ni
!= NULL
) ? ni
->ni_associd
: 0;
2161 RT2870_DPRINTF(sc
, RT2870_DEBUG_KEY
,
2162 "%s: VAP key delete: keyix=%d, keylen=%d, associd=0x%04x, group=%d\n",
2163 device_get_nameunit(sc
->dev
), k
->wk_keyix
, k
->wk_keylen
, associd
,
2164 (k
->wk_flags
& IEEE80211_KEY_GROUP
) ? 1 : 0);
2166 memcpy(&cmd_argv
.key
, k
, sizeof(struct ieee80211_key
));
2167 cmd_argv
.associd
= associd
;
2169 rt2870_do_async(sc
, rt2870_vap_key_delete_cb
,
2170 &cmd_argv
, sizeof(struct rt2870_cmd_argv_keydelete
));
2176 * rt2870_vap_update_beacon
2178 static void rt2870_vap_update_beacon(struct ieee80211vap
*vap
, int what
)
2180 struct rt2870_softc
*sc
;
2181 struct ieee80211com
*ic
;
2188 RT2870_DPRINTF(sc
, RT2870_DEBUG_BEACON
,
2189 "%s: VAP update beacon\n",
2190 device_get_nameunit(sc
->dev
));
2192 rt2870_do_async(sc
, rt2870_vap_update_beacon_cb
, NULL
, 0);
2198 static struct ieee80211_node
*rt2870_node_alloc(struct ieee80211vap
*vap
,
2199 const uint8_t mac
[IEEE80211_ADDR_LEN
])
2201 return malloc(sizeof(struct rt2870_softc_node
),
2202 M_80211_NODE
, M_NOWAIT
| M_ZERO
);
2206 * rt2870_setregdomain
2208 static int rt2870_setregdomain(struct ieee80211com
*ic
,
2209 struct ieee80211_regdomain
*reg
,
2210 int nchans
, struct ieee80211_channel chans
[])
2212 struct rt2870_softc
*sc
;
2218 RT2870_DPRINTF(sc
, RT2870_DEBUG_STATE
,
2219 "%s: set regulatory domain: country=%d, country code string=%c%c, location=%c\n",
2220 device_get_nameunit(sc
->dev
),
2221 reg
->country
, reg
->isocc
[0], reg
->isocc
[1], reg
->location
);
2227 * rt2870_getradiocaps
2229 static void rt2870_getradiocaps(struct ieee80211com
*ic
,
2230 int maxchans
, int *nchans
, struct ieee80211_channel chans
[])
2232 *nchans
= (ic
->ic_nchans
>= maxchans
) ? maxchans
: ic
->ic_nchans
;
2234 memcpy(chans
, ic
->ic_channels
, (*nchans
) * sizeof(struct ieee80211_channel
));
2240 static void rt2870_scan_start(struct ieee80211com
*ic
)
2242 struct rt2870_softc
*sc
;
2248 RT2870_SOFTC_LOCK(sc
);
2250 rt2870_asic_disable_tsf_sync(sc
);
2252 RT2870_SOFTC_UNLOCK(sc
);
2258 static void rt2870_scan_end(struct ieee80211com
*ic
)
2260 struct rt2870_softc
*sc
;
2266 RT2870_SOFTC_LOCK(sc
);
2268 rt2870_asic_enable_tsf_sync(sc
);
2270 RT2870_SOFTC_UNLOCK(sc
);
2274 * rt2870_set_channel
2276 static void rt2870_set_channel(struct ieee80211com
*ic
)
2278 struct rt2870_softc
*sc
;
2284 RT2870_DPRINTF(sc
, RT2870_DEBUG_CHAN
,
2285 "%s: set channel: channel=%u, HT%s%s\n",
2286 device_get_nameunit(sc
->dev
),
2287 ieee80211_chan2ieee(ic
, ic
->ic_curchan
),
2288 !IEEE80211_IS_CHAN_HT(ic
->ic_curchan
) ? " disabled" :
2289 IEEE80211_IS_CHAN_HT20(ic
->ic_curchan
) ? "20":
2290 IEEE80211_IS_CHAN_HT40U(ic
->ic_curchan
) ? "40U" : "40D",
2291 (ic
->ic_flags
& IEEE80211_F_SCAN
) ? ", scanning" : "");
2293 RT2870_SOFTC_LOCK(sc
);
2295 rt2870_rf_set_chan(sc
, ic
->ic_curchan
);
2297 RT2870_SOFTC_UNLOCK(sc
);
2303 static void rt2870_newassoc(struct ieee80211_node
*ni
, int isnew
)
2305 struct rt2870_softc
*sc
;
2306 struct ieee80211com
*ic
;
2308 struct ieee80211vap
*vap
;
2309 struct rt2870_softc_vap
*rvap
;
2317 rvap
= (struct rt2870_softc_vap
*) vap
;
2319 associd
= (ni
!= NULL
) ? ni
->ni_associd
: 0;
2320 wcid
= RT2870_AID2WCID(associd
);
2322 RT2870_DPRINTF(sc
, RT2870_DEBUG_NODE
,
2323 "%s: new association: wcid=0x%02x, "
2324 "mac addr=%s, QoS %s, ERP %s, HT %s\n",
2325 device_get_nameunit(sc
->dev
), wcid
,
2326 ether_sprintf(ni
->ni_macaddr
),
2327 (ni
->ni_flags
& IEEE80211_NODE_QOS
) ? "enabled" : "disabled",
2328 (ni
->ni_flags
& IEEE80211_NODE_ERP
) ? "enabled" : "disabled",
2329 (ni
->ni_flags
& IEEE80211_NODE_HT
) ? "enabled" : "disabled");
2331 RT2870_SOFTC_LOCK(sc
);
2333 rt2870_io_mac_write_multi(sc
, RT2870_REG_WCID(wcid
),
2334 ni
->ni_macaddr
, IEEE80211_ADDR_LEN
);
2336 rt2870_amrr_node_init(&rvap
->amrr
, &sc
->amrr_node
[wcid
], ni
);
2338 RT2870_DPRINTF(sc
, RT2870_DEBUG_RATE
,
2339 "%s: initial%s node Tx rate: associd=0x%04x, rate=0x%02x, max rate=0x%02x\n",
2340 device_get_nameunit(sc
->dev
),
2341 (ni
->ni_flags
& IEEE80211_NODE_HT
) ? " HT" : "",
2342 ni
->ni_associd
, ni
->ni_txrate
,
2343 (ni
->ni_flags
& IEEE80211_NODE_HT
) ?
2344 (ni
->ni_htrates
.rs_rates
[ni
->ni_htrates
.rs_nrates
- 1] | IEEE80211_RATE_MCS
) :
2345 (ni
->ni_rates
.rs_rates
[ni
->ni_rates
.rs_nrates
- 1] & IEEE80211_RATE_VAL
));
2347 rt2870_asic_updateprot(sc
);
2348 rt2870_asic_updateslot(sc
);
2349 rt2870_asic_set_txpreamble(sc
);
2351 RT2870_SOFTC_UNLOCK(sc
);
2357 static void rt2870_updateslot(struct ifnet
*ifp
)
2359 struct rt2870_softc
*sc
;
2363 rt2870_do_async(sc
, rt2870_updateslot_cb
, NULL
, 0);
2367 * rt2870_update_promisc
2369 static void rt2870_update_promisc(struct ifnet
*ifp
)
2371 struct rt2870_softc
*sc
;
2375 RT2870_SOFTC_LOCK(sc
);
2377 rt2870_asic_update_promisc(sc
);
2379 RT2870_SOFTC_UNLOCK(sc
);
2383 * rt2870_update_mcast
2385 static void rt2870_update_mcast(struct ifnet
*ifp
)
2387 struct rt2870_softc
*sc
;
2395 static int rt2870_wme_update(struct ieee80211com
*ic
)
2397 struct rt2870_softc
*sc
;
2403 rt2870_do_async(sc
, rt2870_wme_update_cb
, NULL
, 0);
2411 static int rt2870_raw_xmit(struct ieee80211_node
*ni
, struct mbuf
*m
,
2412 const struct ieee80211_bpf_params
*params
)
2414 struct rt2870_softc
*sc
;
2415 struct ieee80211com
*ic
;
2422 RT2870_SOFTC_LOCK(sc
);
2424 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
2426 RT2870_SOFTC_UNLOCK(sc
);
2429 ieee80211_free_node(ni
);
2434 if (sc
->tx_ring
[sc
->tx_ring_mgtqid
].queued
>= RT2870_SOFTC_TX_RING_DATA_COUNT
)
2436 RT2870_DPRINTF(sc
, RT2870_DEBUG_TX
,
2437 "%s: raw xmit: Tx ring with qid=%d is full\n",
2438 device_get_nameunit(sc
->dev
), sc
->tx_ring_mgtqid
);
2440 ifp
->if_drv_flags
|= IFF_DRV_OACTIVE
;
2442 RT2870_SOFTC_UNLOCK(sc
);
2445 ieee80211_free_node(ni
);
2447 sc
->tx_data_queue_full
[sc
->tx_ring_mgtqid
]++;
2452 if (rt2870_tx_mgmt(sc
, m
, ni
, sc
->tx_ring_mgtqid
) != 0)
2456 RT2870_SOFTC_UNLOCK(sc
);
2458 ieee80211_free_node(ni
);
2463 sc
->tx_timer
= RT2870_TX_WATCHDOG_TIMEOUT
;
2465 RT2870_SOFTC_UNLOCK(sc
);
2471 * rt2870_recv_action
2473 static int rt2870_recv_action(struct ieee80211_node
*ni
,
2474 const struct ieee80211_frame
*wh
,
2475 const uint8_t *frm
, const uint8_t *efrm
)
2477 struct rt2870_softc
*sc
;
2478 struct ieee80211com
*ic
;
2480 const struct ieee80211_action
*ia
;
2481 uint16_t associd
, baparamset
;
2483 int ret
, tid
, bufsize
;
2490 ia
= (const struct ieee80211_action
*) frm
;
2492 ret
= sc
->recv_action(ni
, wh
, frm
, efrm
);
2494 if (ia
->ia_category
!= IEEE80211_ACTION_CAT_BA
)
2497 associd
= (ni
!= NULL
) ? ni
->ni_associd
: 0;
2498 wcid
= RT2870_AID2WCID(associd
);
2500 switch (ia
->ia_action
)
2502 /* IEEE80211_ACTION_BA_ADDBA_REQUEST */
2503 case IEEE80211_ACTION_BA_ADDBA_REQUEST
:
2504 baparamset
= LE_READ_2(frm
+ 3);
2505 tid
= RT2870_MS(baparamset
, IEEE80211_BAPS_TID
);
2506 bufsize
= RT2870_MS(baparamset
, IEEE80211_BAPS_BUFSIZ
);
2508 RT2870_DPRINTF(sc
, RT2870_DEBUG_BA
,
2509 "%s: received ADDBA: associd=0x%04x, tid=%d, bufsize=%d\n",
2510 device_get_nameunit(sc
->dev
), associd
, tid
, bufsize
);
2512 RT2870_SOFTC_LOCK(sc
);
2514 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_WCID(wcid
) + 4);
2516 tmp
|= (0x10000 << tid
);
2518 rt2870_io_mac_write(sc
, RT2870_REG_WCID(wcid
) + 4, tmp
);
2520 RT2870_SOFTC_UNLOCK(sc
);
2523 /* IEEE80211_ACTION_BA_DELBA */
2524 case IEEE80211_ACTION_BA_DELBA
:
2525 baparamset
= LE_READ_2(frm
+ 2);
2526 tid
= RT2870_MS(baparamset
, IEEE80211_BAPS_TID
);
2528 RT2870_DPRINTF(sc
, RT2870_DEBUG_BA
,
2529 "%s: received DELBA: associd=0x%04x, tid=%d\n",
2530 device_get_nameunit(sc
->dev
), associd
, tid
);
2532 RT2870_SOFTC_LOCK(sc
);
2534 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_WCID(wcid
) + 4);
2536 tmp
&= ~(0x10000 << tid
);
2538 rt2870_io_mac_write(sc
, RT2870_REG_WCID(wcid
) + 4, tmp
);
2540 RT2870_SOFTC_UNLOCK(sc
);
2548 * rt2870_send_action
2550 static int rt2870_send_action(struct ieee80211_node
*ni
,
2551 int cat
, int act
, void *sa
)
2553 struct rt2870_softc
*sc
;
2554 struct ieee80211com
*ic
;
2556 uint16_t associd
, *args
, baparamset
;
2565 ret
= sc
->send_action(ni
, cat
, act
, sa
);
2567 if (cat
!= IEEE80211_ACTION_CAT_BA
)
2570 associd
= (ni
!= NULL
) ? ni
->ni_associd
: 0;
2571 wcid
= RT2870_AID2WCID(associd
);
2576 /* IEEE80211_ACTION_BA_DELBA */
2577 case IEEE80211_ACTION_BA_DELBA
:
2578 baparamset
= RT2870_SM(args
[0], IEEE80211_DELBAPS_TID
) | args
[1];
2580 if (RT2870_MS(baparamset
, IEEE80211_DELBAPS_INIT
) == IEEE80211_DELBAPS_INIT
)
2583 tid
= RT2870_MS(baparamset
, IEEE80211_DELBAPS_TID
);
2585 RT2870_DPRINTF(sc
, RT2870_DEBUG_BA
,
2586 "%s: sending DELBA: associd=0x%04x, tid=%d\n",
2587 device_get_nameunit(sc
->dev
), associd
, tid
);
2589 RT2870_SOFTC_LOCK(sc
);
2591 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_WCID(wcid
) + 4);
2593 tmp
&= ~(0x10000 << tid
);
2595 rt2870_io_mac_write(sc
, RT2870_REG_WCID(wcid
) + 4, tmp
);
2597 RT2870_SOFTC_UNLOCK(sc
);
2605 * rt2870_amrr_update_iter_func
2607 static void rt2870_amrr_update_iter_func(void *arg
, struct ieee80211_node
*ni
)
2609 struct rt2870_softc
*sc
;
2610 struct ieee80211com
*ic
;
2612 struct ieee80211vap
*vap
;
2613 struct rt2870_softc_vap
*rvap
;
2620 rvap
= (struct rt2870_softc_vap
*) vap
;
2622 /* only associated stations */
2624 if ((ni
->ni_vap
== vap
) && (ni
->ni_associd
!= 0))
2626 wcid
= RT2870_AID2WCID(ni
->ni_associd
);
2628 RT2870_DPRINTF(sc
, RT2870_DEBUG_RATE
,
2629 "%s: AMRR node: wcid=0x%02x, txcnt=%d, success=%d, retrycnt=%d\n",
2630 device_get_nameunit(sc
->dev
),
2631 wcid
, sc
->amrr_node
[wcid
].txcnt
, sc
->amrr_node
[wcid
].success
, sc
->amrr_node
[wcid
].retrycnt
);
2633 rt2870_amrr_choose(ni
, &sc
->amrr_node
[wcid
]);
2635 RT2870_DPRINTF(sc
, RT2870_DEBUG_RATE
,
2636 "%s:%s node Tx rate: associd=0x%04x, rate=0x%02x, max rate=0x%02x\n",
2637 device_get_nameunit(sc
->dev
),
2638 (ni
->ni_flags
& IEEE80211_NODE_HT
) ? " HT" : "",
2639 ni
->ni_associd
, ni
->ni_txrate
,
2640 (ni
->ni_flags
& IEEE80211_NODE_HT
) ?
2641 (ni
->ni_htrates
.rs_rates
[ni
->ni_htrates
.rs_nrates
- 1] | IEEE80211_RATE_MCS
) :
2642 (ni
->ni_rates
.rs_rates
[ni
->ni_rates
.rs_nrates
- 1] & IEEE80211_RATE_VAL
));
2649 static void rt2870_periodic(void *arg
)
2651 struct rt2870_softc
*sc
;
2657 RT2870_DPRINTF(sc
, RT2870_DEBUG_PERIODIC
,
2659 device_get_nameunit(sc
->dev
));
2661 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
2664 taskqueue_enqueue(sc
->taskqueue
, &sc
->periodic_task
);
2668 * rt2870_tx_watchdog
2670 static void rt2870_tx_watchdog(void *arg
)
2672 struct rt2870_softc
*sc
;
2678 if (sc
->tx_timer
== 0)
2681 if (--sc
->tx_timer
== 0)
2683 printf("%s: Tx watchdog timeout: resetting\n",
2684 device_get_nameunit(sc
->dev
));
2686 rt2870_stop_locked(sc
);
2687 rt2870_init_locked(sc
);
2691 sc
->tx_watchdog_timeouts
++;
2694 callout_reset(&sc
->tx_watchdog_ch
, hz
, rt2870_tx_watchdog
, sc
);
2700 static int rt2870_do_async(struct rt2870_softc
*sc
,
2701 void (*cb
)(struct rt2870_softc
*sc
, void *arg
),
2705 struct rt2870_softc_cmd_ring
*ring
;
2706 struct rt2870_softc_cmd
*cmd
;
2710 ring
= &sc
->cmd_ring
;
2712 RT2870_SOFTC_LOCK(sc
);
2714 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
2716 RT2870_SOFTC_UNLOCK(sc
);
2720 if (ring
->queued
>= RT2870_SOFTC_CMD_RING_CMD_COUNT
)
2722 RT2870_SOFTC_UNLOCK(sc
);
2726 cmd
= STAILQ_FIRST(&ring
->inactive
);
2727 STAILQ_REMOVE_HEAD(&ring
->inactive
, next
);
2732 memcpy(cmd
->data
, arg
, len
);
2734 STAILQ_INSERT_TAIL(&ring
->active
, cmd
, next
);
2737 run_cmd_task
= (ring
->queued
== 1);
2739 RT2870_SOFTC_UNLOCK(sc
);
2742 taskqueue_enqueue(sc
->taskqueue
, &sc
->cmd_task
);
2748 * rt2870_updateslot_cb
2750 static void rt2870_updateslot_cb(struct rt2870_softc
*sc
, void *arg
)
2752 RT2870_SOFTC_LOCK(sc
);
2754 rt2870_asic_updateslot(sc
);
2756 RT2870_SOFTC_UNLOCK(sc
);
2760 * rt2870_wme_update_cb
2762 static void rt2870_wme_update_cb(struct rt2870_softc
*sc
, void *arg
)
2764 RT2870_SOFTC_LOCK(sc
);
2766 rt2870_asic_wme_update(sc
);
2768 RT2870_SOFTC_UNLOCK(sc
);
2772 * rt2870_vap_key_delete_cb
2774 static void rt2870_vap_key_delete_cb(struct rt2870_softc
*sc
, void *arg
)
2776 struct ieee80211_key
*k
;
2777 struct rt2870_cmd_argv_keydelete
*cmd_argv
;
2779 uint8_t vapid
, wcid
;
2784 associd
= cmd_argv
->associd
;
2786 RT2870_SOFTC_LOCK(sc
);
2788 if (!(k
->wk_flags
& IEEE80211_KEY_GROUP
))
2790 /* remove pairwise key */
2793 wcid
= RT2870_AID2WCID(associd
);
2795 tmp
= ((vapid
& RT2870_REG_VAP_MASK
) << RT2870_REG_VAP_SHIFT
) |
2796 (RT2870_REG_CIPHER_MODE_NONE
<< RT2870_REG_CIPHER_MODE_SHIFT
) | RT2870_REG_PKEY_ENABLE
;
2798 rt2870_io_mac_write(sc
, RT2870_REG_WCID_ATTR(wcid
), tmp
);
2802 /* remove group key */
2806 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_SKEY_MODE(vapid
));
2808 tmp
&= ~(0xf << (k
->wk_keyix
* 4 + 16 * (vapid
% 2)));
2809 tmp
|= (RT2870_REG_CIPHER_MODE_NONE
<< (k
->wk_keyix
* 4 + 16 * (vapid
% 2)));
2811 rt2870_io_mac_write(sc
, RT2870_REG_SKEY_MODE(vapid
), tmp
);
2814 RT2870_SOFTC_UNLOCK(sc
);
2818 * rt2870_vap_update_beacon_cb
2820 static void rt2870_vap_update_beacon_cb(struct rt2870_softc
*sc
, void *arg
)
2823 struct ieee80211com
*ic
;
2824 struct ieee80211vap
*vap
;
2828 vap
= TAILQ_FIRST(&ic
->ic_vaps
);
2833 RT2870_SOFTC_LOCK(sc
);
2835 rt2870_asic_update_beacon(sc
, vap
);
2837 RT2870_SOFTC_UNLOCK(sc
);
2841 * rt2870_asic_set_bssid
2843 static void rt2870_asic_set_bssid(struct rt2870_softc
*sc
,
2844 const uint8_t *bssid
)
2848 RT2870_DPRINTF(sc
, RT2870_DEBUG_STATE
,
2849 "%s: set bssid: bssid=%s\n",
2850 device_get_nameunit(sc
->dev
),
2851 ether_sprintf(bssid
));
2853 tmp
= bssid
[0] | (bssid
[1]) << 8 | (bssid
[2] << 16) | (bssid
[3] << 24);
2855 rt2870_io_mac_write(sc
, RT2870_REG_BSSID_DW0
, tmp
);
2857 tmp
= bssid
[4] | (bssid
[5] << 8);
2859 rt2870_io_mac_write(sc
, RT2870_REG_BSSID_DW1
, tmp
);
2863 * rt2870_asic_set_macaddr
2865 static void rt2870_asic_set_macaddr(struct rt2870_softc
*sc
,
2866 const uint8_t *addr
)
2870 tmp
= addr
[0] | (addr
[1] << 8) | (addr
[2] << 16) | (addr
[3] << 24);
2872 rt2870_io_mac_write(sc
, RT2870_REG_ADDR_DW0
, tmp
);
2874 tmp
= addr
[4] | (addr
[5] << 8);
2876 rt2870_io_mac_write(sc
, RT2870_REG_ADDR_DW1
, tmp
);
2880 * rt2870_asic_enable_tsf_sync
2882 static void rt2870_asic_enable_tsf_sync(struct rt2870_softc
*sc
)
2885 struct ieee80211com
*ic
;
2886 struct ieee80211vap
*vap
;
2891 vap
= TAILQ_FIRST(&ic
->ic_vaps
);
2893 RT2870_DPRINTF(sc
, RT2870_DEBUG_BEACON
,
2894 "%s: enabling TSF\n",
2895 device_get_nameunit(sc
->dev
));
2897 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_BCN_TIME_CFG
);
2900 tmp
|= vap
->iv_bss
->ni_intval
* 16;
2901 tmp
|= (RT2870_REG_TSF_TIMER_ENABLE
| RT2870_REG_TBTT_TIMER_ENABLE
);
2903 if (vap
->iv_opmode
== IEEE80211_M_STA
)
2905 tmp
|= (RT2870_REG_TSF_SYNC_MODE_STA
<< RT2870_REG_TSF_SYNC_MODE_SHIFT
);
2907 else if (vap
->iv_opmode
== IEEE80211_M_IBSS
)
2909 tmp
|= RT2870_REG_BCN_TX_ENABLE
;
2910 tmp
|= (RT2870_REG_TSF_SYNC_MODE_IBSS
<< RT2870_REG_TSF_SYNC_MODE_SHIFT
);
2912 else if (vap
->iv_opmode
== IEEE80211_M_HOSTAP
)
2914 tmp
|= RT2870_REG_BCN_TX_ENABLE
;
2915 tmp
|= (RT2870_REG_TSF_SYNC_MODE_HOSTAP
<< RT2870_REG_TSF_SYNC_MODE_SHIFT
);
2918 rt2870_io_mac_write(sc
, RT2870_REG_BCN_TIME_CFG
, tmp
);
2922 * rt2870_asic_disable_tsf_sync
2924 static void rt2870_asic_disable_tsf_sync(struct rt2870_softc
*sc
)
2928 RT2870_DPRINTF(sc
, RT2870_DEBUG_BEACON
,
2929 "%s: disabling TSF\n",
2930 device_get_nameunit(sc
->dev
));
2932 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_BCN_TIME_CFG
);
2934 tmp
&= ~(RT2870_REG_BCN_TX_ENABLE
|
2935 RT2870_REG_TSF_TIMER_ENABLE
|
2936 RT2870_REG_TBTT_TIMER_ENABLE
);
2938 tmp
&= ~(RT2870_REG_TSF_SYNC_MODE_MASK
<< RT2870_REG_TSF_SYNC_MODE_SHIFT
);
2939 tmp
|= (RT2870_REG_TSF_SYNC_MODE_DISABLE
<< RT2870_REG_TSF_SYNC_MODE_SHIFT
);
2941 rt2870_io_mac_write(sc
, RT2870_REG_BCN_TIME_CFG
, tmp
);
2945 * rt2870_asic_enable_mrr
2947 static void rt2870_asic_enable_mrr(struct rt2870_softc
*sc
)
2949 #define CCK(mcs) (mcs)
2950 #define OFDM(mcs) ((1 << 3) | (mcs))
2951 #define HT(mcs) (mcs)
2953 rt2870_io_mac_write(sc
, RT2870_REG_TX_LG_FBK_CFG0
,
2954 (OFDM(6) << 28) | /* 54 -> 48 */
2955 (OFDM(5) << 24) | /* 48 -> 36 */
2956 (OFDM(4) << 20) | /* 36 -> 24 */
2957 (OFDM(3) << 16) | /* 24 -> 18 */
2958 (OFDM(2) << 12) | /* 18 -> 12 */
2959 (OFDM(1) << 8) | /* 12 -> 9 */
2960 (OFDM(0) << 4) | /* 9 -> 6 */
2961 OFDM(0)); /* 6 -> 6 */
2963 rt2870_io_mac_write(sc
, RT2870_REG_TX_LG_FBK_CFG1
,
2964 (CCK(2) << 12) | /* 11 -> 5.5 */
2965 (CCK(1) << 8) | /* 5.5 -> 2 */
2966 (CCK(0) << 4) | /* 2 -> 1 */
2967 CCK(0)); /* 1 -> 1 */
2969 rt2870_io_mac_write(sc
, RT2870_REG_TX_HT_FBK_CFG0
,
2979 rt2870_io_mac_write(sc
, RT2870_REG_TX_HT_FBK_CFG1
,
2995 * rt2870_asic_set_txpreamble
2997 static void rt2870_asic_set_txpreamble(struct rt2870_softc
*sc
)
3000 struct ieee80211com
*ic
;
3006 RT2870_DPRINTF(sc
, RT2870_DEBUG_STATE
,
3007 "%s: %s short Tx preamble\n",
3008 device_get_nameunit(sc
->dev
),
3009 (ic
->ic_flags
& IEEE80211_F_SHPREAMBLE
) ? "enabling" : "disabling");
3011 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_AUTO_RSP_CFG
);
3013 tmp
&= ~RT2870_REG_CCK_SHORT_ENABLE
;
3015 if (ic
->ic_flags
& IEEE80211_F_SHPREAMBLE
)
3016 tmp
|= RT2870_REG_CCK_SHORT_ENABLE
;
3018 rt2870_io_mac_write(sc
, RT2870_REG_AUTO_RSP_CFG
, tmp
);
3022 * rt2870_asic_set_basicrates
3024 static void rt2870_asic_set_basicrates(struct rt2870_softc
*sc
)
3027 struct ieee80211com
*ic
;
3032 if (ic
->ic_curmode
== IEEE80211_MODE_11B
)
3033 rt2870_io_mac_write(sc
, RT2870_REG_LEGACY_BASIC_RATE
, 0x3);
3034 else if (ic
->ic_curmode
== IEEE80211_MODE_11A
)
3035 rt2870_io_mac_write(sc
, RT2870_REG_LEGACY_BASIC_RATE
, 0x150);
3037 rt2870_io_mac_write(sc
, RT2870_REG_LEGACY_BASIC_RATE
, 0x15f);
3041 * rt2870_asic_update_rtsthreshold
3043 static void rt2870_asic_update_rtsthreshold(struct rt2870_softc
*sc
)
3046 struct ieee80211com
*ic
;
3047 struct ieee80211vap
*vap
;
3053 vap
= TAILQ_FIRST(&ic
->ic_vaps
);
3055 RT2870_DPRINTF(sc
, RT2870_DEBUG_PROT
,
3056 "%s: updating RTS threshold: %d\n",
3057 device_get_nameunit(sc
->dev
), vap
->iv_rtsthreshold
);
3059 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_TX_RTS_CFG
);
3061 tmp
&= ~(RT2870_REG_TX_RTS_THRESHOLD_MASK
<< RT2870_REG_TX_RTS_THRESHOLD_SHIFT
);
3063 threshold
= (vap
->iv_rtsthreshold
< IEEE80211_RTS_MAX
) ?
3064 vap
->iv_rtsthreshold
: 0x1000;
3066 tmp
|= ((threshold
& RT2870_REG_TX_RTS_THRESHOLD_MASK
) <<
3067 RT2870_REG_TX_RTS_THRESHOLD_SHIFT
);
3069 rt2870_io_mac_write(sc
, RT2870_REG_TX_RTS_CFG
, tmp
);
3073 * rt2870_asic_update_txpower
3075 static void rt2870_asic_update_txpower(struct rt2870_softc
*sc
)
3078 struct ieee80211com
*ic
;
3079 uint32_t *txpow_rate
;
3088 RT2870_DPRINTF(sc
, RT2870_DEBUG_STATE
,
3089 "%s: updating Tx power: %d\n",
3090 device_get_nameunit(sc
->dev
), ic
->ic_txpowlimit
);
3092 if (!IEEE80211_IS_CHAN_HT40(ic
->ic_curchan
))
3094 txpow_rate
= sc
->txpow_rate_20mhz
;
3098 if (IEEE80211_IS_CHAN_2GHZ(ic
->ic_curchan
))
3099 txpow_rate
= sc
->txpow_rate_40mhz_2ghz
;
3101 txpow_rate
= sc
->txpow_rate_40mhz_5ghz
;
3106 val
= rt2870_io_bbp_read(sc
, 1);
3109 if (ic
->ic_txpowlimit
> 90)
3113 else if (ic
->ic_txpowlimit
> 60)
3117 else if (ic
->ic_txpowlimit
> 30)
3121 else if (ic
->ic_txpowlimit
> 15)
3125 else if (ic
->ic_txpowlimit
> 9)
3135 rt2870_io_bbp_write(sc
, 1, val
);
3137 for (i
= 0; i
< RT2870_SOFTC_TXPOW_RATE_COUNT
; i
++)
3139 if (txpow_rate
[i
] == 0xffffffff)
3142 tmp
= rt2870_read_eeprom_txpow_rate_add_delta(txpow_rate
[i
], delta
);
3144 rt2870_io_mac_write(sc
, RT2870_REG_TX_PWR_CFG(i
), tmp
);
3149 * rt2870_asic_update_promisc
3151 static void rt2870_asic_update_promisc(struct rt2870_softc
*sc
)
3158 printf("%s: %s promiscuous mode\n",
3159 device_get_nameunit(sc
->dev
),
3160 (ifp
->if_flags
& IFF_PROMISC
) ? "entering" : "leaving");
3162 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_RX_FILTER_CFG
);
3164 tmp
&= ~RT2870_REG_RX_FILTER_DROP_UC_NOME
;
3166 if (!(ifp
->if_flags
& IFF_PROMISC
))
3167 tmp
|= RT2870_REG_RX_FILTER_DROP_UC_NOME
;
3169 rt2870_io_mac_write(sc
, RT2870_REG_RX_FILTER_CFG
, tmp
);
3173 * rt2870_asic_updateprot
3175 static void rt2870_asic_updateprot(struct rt2870_softc
*sc
)
3178 struct ieee80211com
*ic
;
3179 struct ieee80211vap
*vap
;
3180 uint32_t cck_prot
, ofdm_prot
, mm20_prot
, mm40_prot
, gf20_prot
, gf40_prot
;
3185 vap
= TAILQ_FIRST(&ic
->ic_vaps
);
3187 /* CCK frame protection */
3189 cck_prot
= RT2870_REG_RTSTH_ENABLE
| RT2870_REG_PROT_NAV_SHORT
|
3190 RT2870_REG_TXOP_ALLOW_ALL
| RT2870_REG_PROT_CTRL_NONE
;
3192 /* set up protection frame phy mode and rate (MCS code) */
3194 if (ic
->ic_curmode
== IEEE80211_MODE_11A
)
3195 cck_prot
|= (RT2870_REG_PROT_PHYMODE_OFDM
<< RT2870_REG_PROT_PHYMODE_SHIFT
) |
3196 (0 << RT2870_REG_PROT_MCS_SHIFT
);
3198 cck_prot
|= ((RT2870_REG_PROT_PHYMODE_CCK
<< RT2870_REG_PROT_PHYMODE_SHIFT
) |
3199 (3 << RT2870_REG_PROT_MCS_SHIFT
));
3201 rt2870_io_mac_write(sc
, RT2870_REG_TX_CCK_PROT_CFG
, cck_prot
);
3203 /* OFDM frame protection */
3205 ofdm_prot
= RT2870_REG_RTSTH_ENABLE
| RT2870_REG_PROT_NAV_SHORT
|
3206 RT2870_REG_TXOP_ALLOW_ALL
;
3208 if (ic
->ic_flags
& IEEE80211_F_USEPROT
)
3210 RT2870_DPRINTF(sc
, RT2870_DEBUG_PROT
,
3211 "%s: updating protection mode: b/g protection mode=%s\n",
3212 device_get_nameunit(sc
->dev
),
3213 (ic
->ic_protmode
== IEEE80211_PROT_RTSCTS
) ? "RTS/CTS" :
3214 ((ic
->ic_protmode
== IEEE80211_PROT_CTSONLY
) ? "CTS-to-self" : "none"));
3216 if (ic
->ic_protmode
== IEEE80211_PROT_RTSCTS
)
3217 ofdm_prot
|= RT2870_REG_PROT_CTRL_RTS_CTS
;
3218 else if (ic
->ic_protmode
== IEEE80211_PROT_CTSONLY
)
3219 ofdm_prot
|= RT2870_REG_PROT_CTRL_CTS
;
3221 ofdm_prot
|= RT2870_REG_PROT_CTRL_NONE
;
3225 RT2870_DPRINTF(sc
, RT2870_DEBUG_PROT
,
3226 "%s: updating protection mode: b/g protection mode=%s\n",
3227 device_get_nameunit(sc
->dev
), "none");
3229 ofdm_prot
|= RT2870_REG_PROT_CTRL_NONE
;
3232 rt2870_io_mac_write(sc
, RT2870_REG_TX_OFDM_PROT_CFG
, ofdm_prot
);
3234 /* HT frame protection */
3236 if ((vap
->iv_opmode
== IEEE80211_M_STA
) && (vap
->iv_state
== IEEE80211_S_RUN
))
3237 htopmode
= vap
->iv_bss
->ni_htopmode
;
3239 htopmode
= ic
->ic_curhtprotmode
;
3241 RT2870_DPRINTF(sc
, RT2870_DEBUG_PROT
,
3242 "%s: updating protection mode: HT operation mode=0x%02x, protection mode=%s\n",
3243 device_get_nameunit(sc
->dev
),
3244 htopmode
& IEEE80211_HTINFO_OPMODE
,
3245 (ic
->ic_htprotmode
== IEEE80211_PROT_RTSCTS
) ? "RTS/CTS" :
3246 ((ic
->ic_htprotmode
== IEEE80211_PROT_CTSONLY
) ? "CTS-to-self" : "none"));
3248 switch (htopmode
& IEEE80211_HTINFO_OPMODE
)
3250 /* IEEE80211_HTINFO_OPMODE_HT20PR */
3251 case IEEE80211_HTINFO_OPMODE_HT20PR
:
3252 mm20_prot
= RT2870_REG_PROT_NAV_SHORT
| RT2870_REG_PROT_CTRL_NONE
|
3253 RT2870_REG_TXOP_ALLOW_CCK
| RT2870_REG_TXOP_ALLOW_OFDM
|
3254 RT2870_REG_TXOP_ALLOW_MM20
| RT2870_REG_TXOP_ALLOW_GF20
|
3255 (RT2870_REG_PROT_PHYMODE_OFDM
<< RT2870_REG_PROT_PHYMODE_SHIFT
) |
3256 (4 << RT2870_REG_PROT_MCS_SHIFT
);
3258 gf20_prot
= mm20_prot
;
3260 mm40_prot
= RT2870_REG_PROT_NAV_SHORT
| RT2870_REG_PROT_CTRL_NONE
|
3261 RT2870_REG_TXOP_ALLOW_ALL
|
3262 (RT2870_REG_PROT_PHYMODE_OFDM
<< RT2870_REG_PROT_PHYMODE_SHIFT
) |
3263 (0x84 << RT2870_REG_PROT_MCS_SHIFT
);
3265 if (ic
->ic_htprotmode
== IEEE80211_PROT_RTSCTS
)
3266 mm40_prot
|= RT2870_REG_PROT_CTRL_RTS_CTS
;
3267 else if (ic
->ic_htprotmode
== IEEE80211_PROT_CTSONLY
)
3268 mm40_prot
|= RT2870_REG_PROT_CTRL_CTS
;
3270 mm40_prot
|= RT2870_REG_PROT_CTRL_NONE
;
3272 gf40_prot
= mm40_prot
;
3275 /* IEEE80211_HTINFO_OPMODE_MIXED */
3276 case IEEE80211_HTINFO_OPMODE_MIXED
:
3277 mm20_prot
= RT2870_REG_PROT_NAV_SHORT
|
3278 RT2870_REG_TXOP_ALLOW_CCK
| RT2870_REG_TXOP_ALLOW_OFDM
|
3279 RT2870_REG_TXOP_ALLOW_MM20
| RT2870_REG_TXOP_ALLOW_GF20
;
3281 if (ic
->ic_flags
& IEEE80211_F_USEPROT
)
3282 mm20_prot
|= (RT2870_REG_PROT_PHYMODE_CCK
<< RT2870_REG_PROT_PHYMODE_SHIFT
) |
3283 (3 << RT2870_REG_PROT_MCS_SHIFT
);
3285 mm20_prot
|= (RT2870_REG_PROT_PHYMODE_OFDM
<< RT2870_REG_PROT_PHYMODE_SHIFT
) |
3286 (4 << RT2870_REG_PROT_MCS_SHIFT
);
3288 if (ic
->ic_htprotmode
== IEEE80211_PROT_RTSCTS
)
3289 mm20_prot
|= RT2870_REG_PROT_CTRL_RTS_CTS
;
3290 else if (ic
->ic_htprotmode
== IEEE80211_PROT_CTSONLY
)
3291 mm20_prot
|= RT2870_REG_PROT_CTRL_CTS
;
3293 mm20_prot
|= RT2870_REG_PROT_CTRL_NONE
;
3295 gf20_prot
= mm20_prot
;
3297 mm40_prot
= RT2870_REG_PROT_NAV_SHORT
| RT2870_REG_TXOP_ALLOW_ALL
;
3299 if (ic
->ic_flags
& IEEE80211_F_USEPROT
)
3300 mm40_prot
|= (RT2870_REG_PROT_PHYMODE_CCK
<< RT2870_REG_PROT_PHYMODE_SHIFT
) |
3301 (3 << RT2870_REG_PROT_MCS_SHIFT
);
3303 mm40_prot
|= (RT2870_REG_PROT_PHYMODE_OFDM
<< RT2870_REG_PROT_PHYMODE_SHIFT
) |
3304 (0x84 << RT2870_REG_PROT_MCS_SHIFT
);
3306 if (ic
->ic_htprotmode
== IEEE80211_PROT_RTSCTS
)
3307 mm40_prot
|= RT2870_REG_PROT_CTRL_RTS_CTS
;
3308 else if (ic
->ic_htprotmode
== IEEE80211_PROT_CTSONLY
)
3309 mm40_prot
|= RT2870_REG_PROT_CTRL_CTS
;
3311 mm40_prot
|= RT2870_REG_PROT_CTRL_NONE
;
3313 gf40_prot
= mm40_prot
;
3317 * IEEE80211_HTINFO_OPMODE_PURE
3318 * IEEE80211_HTINFO_OPMODE_PROTOPT
3320 case IEEE80211_HTINFO_OPMODE_PURE
:
3321 case IEEE80211_HTINFO_OPMODE_PROTOPT
:
3323 mm20_prot
= RT2870_REG_PROT_NAV_SHORT
| RT2870_REG_PROT_CTRL_NONE
|
3324 RT2870_REG_TXOP_ALLOW_CCK
| RT2870_REG_TXOP_ALLOW_OFDM
|
3325 RT2870_REG_TXOP_ALLOW_MM20
| RT2870_REG_TXOP_ALLOW_GF20
|
3326 (RT2870_REG_PROT_PHYMODE_OFDM
<< RT2870_REG_PROT_PHYMODE_SHIFT
) |
3327 (4 << RT2870_REG_PROT_MCS_SHIFT
);
3329 gf20_prot
= mm20_prot
;
3331 mm40_prot
= RT2870_REG_PROT_NAV_SHORT
| RT2870_REG_PROT_CTRL_NONE
|
3332 RT2870_REG_TXOP_ALLOW_ALL
|
3333 (RT2870_REG_PROT_PHYMODE_OFDM
<< RT2870_REG_PROT_PHYMODE_SHIFT
) |
3334 (0x84 << RT2870_REG_PROT_MCS_SHIFT
);
3336 gf40_prot
= mm40_prot
;
3340 rt2870_io_mac_write(sc
, RT2870_REG_TX_MM20_PROT_CFG
, mm20_prot
);
3341 rt2870_io_mac_write(sc
, RT2870_REG_TX_MM40_PROT_CFG
, mm40_prot
);
3342 rt2870_io_mac_write(sc
, RT2870_REG_TX_GF20_PROT_CFG
, gf20_prot
);
3343 rt2870_io_mac_write(sc
, RT2870_REG_TX_GF40_PROT_CFG
, gf40_prot
);
3347 * rt2870_asic_updateslot
3349 static void rt2870_asic_updateslot(struct rt2870_softc
*sc
)
3352 struct ieee80211com
*ic
;
3358 RT2870_DPRINTF(sc
, RT2870_DEBUG_STATE
,
3359 "%s: %s short slot time\n",
3360 device_get_nameunit(sc
->dev
),
3361 (ic
->ic_flags
& IEEE80211_F_SHSLOT
) ? "enabling" : "disabling");
3363 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_BKOFF_SLOT_CFG
);
3366 tmp
|= (ic
->ic_flags
& IEEE80211_F_SHSLOT
) ? 9 : 20;
3368 rt2870_io_mac_write(sc
, RT2870_REG_BKOFF_SLOT_CFG
, tmp
);
3372 * rt2870_asic_wme_update
3374 static void rt2870_asic_wme_update(struct rt2870_softc
*sc
)
3377 struct ieee80211com
*ic
;
3378 struct ieee80211_wme_state
*wme
;
3379 const struct wmeParams
*wmep
;
3385 wmep
= wme
->wme_chanParams
.cap_wmeParams
;
3387 RT2870_DPRINTF(sc
, RT2870_DEBUG_WME
,
3388 "%s: wme update: WME_AC_VO=%d/%d/%d/%d, WME_AC_VI=%d/%d/%d/%d, "
3389 "WME_AC_BK=%d/%d/%d/%d, WME_AC_BE=%d/%d/%d/%d\n",
3390 device_get_nameunit(sc
->dev
),
3391 wmep
[WME_AC_VO
].wmep_aifsn
,
3392 wmep
[WME_AC_VO
].wmep_logcwmin
, wmep
[WME_AC_VO
].wmep_logcwmax
,
3393 wmep
[WME_AC_VO
].wmep_txopLimit
,
3394 wmep
[WME_AC_VI
].wmep_aifsn
,
3395 wmep
[WME_AC_VI
].wmep_logcwmin
, wmep
[WME_AC_VI
].wmep_logcwmax
,
3396 wmep
[WME_AC_VI
].wmep_txopLimit
,
3397 wmep
[WME_AC_BK
].wmep_aifsn
,
3398 wmep
[WME_AC_BK
].wmep_logcwmin
, wmep
[WME_AC_BK
].wmep_logcwmax
,
3399 wmep
[WME_AC_BK
].wmep_txopLimit
,
3400 wmep
[WME_AC_BE
].wmep_aifsn
,
3401 wmep
[WME_AC_BE
].wmep_logcwmin
, wmep
[WME_AC_BE
].wmep_logcwmax
,
3402 wmep
[WME_AC_BE
].wmep_txopLimit
);
3404 for (i
= 0; i
< WME_NUM_AC
; i
++)
3405 rt2870_io_mac_write(sc
, RT2870_REG_TX_EDCA_AC_CFG(i
),
3406 (wmep
[i
].wmep_logcwmax
<< 16) | (wmep
[i
].wmep_logcwmin
<< 12) |
3407 (wmep
[i
].wmep_aifsn
<< 8) | wmep
[i
].wmep_txopLimit
);
3409 rt2870_io_mac_write(sc
, RT2870_REG_SCHDMA_WMM_AIFSN_CFG
,
3410 (wmep
[WME_AC_VO
].wmep_aifsn
<< 12) | (wmep
[WME_AC_VI
].wmep_aifsn
<< 8) |
3411 (wmep
[WME_AC_BK
].wmep_aifsn
<< 4) | wmep
[WME_AC_BE
].wmep_aifsn
);
3413 rt2870_io_mac_write(sc
, RT2870_REG_SCHDMA_WMM_CWMIN_CFG
,
3414 (wmep
[WME_AC_VO
].wmep_logcwmin
<< 12) | (wmep
[WME_AC_VI
].wmep_logcwmin
<< 8) |
3415 (wmep
[WME_AC_BK
].wmep_logcwmin
<< 4) | wmep
[WME_AC_BE
].wmep_logcwmin
);
3417 rt2870_io_mac_write(sc
, RT2870_REG_SCHDMA_WMM_CWMAX_CFG
,
3418 (wmep
[WME_AC_VO
].wmep_logcwmax
<< 12) | (wmep
[WME_AC_VI
].wmep_logcwmax
<< 8) |
3419 (wmep
[WME_AC_BK
].wmep_logcwmax
<< 4) | wmep
[WME_AC_BE
].wmep_logcwmax
);
3421 rt2870_io_mac_write(sc
, RT2870_REG_SCHDMA_WMM_TXOP0_CFG
,
3422 (wmep
[WME_AC_BK
].wmep_txopLimit
<< 16) | wmep
[WME_AC_BE
].wmep_txopLimit
);
3424 rt2870_io_mac_write(sc
, RT2870_REG_SCHDMA_WMM_TXOP1_CFG
,
3425 (wmep
[WME_AC_VO
].wmep_txopLimit
<< 16) | wmep
[WME_AC_VI
].wmep_txopLimit
);
3429 * rt2870_asic_update_beacon
3431 static int rt2870_asic_update_beacon(struct rt2870_softc
*sc
,
3432 struct ieee80211vap
*vap
)
3435 struct ieee80211com
*ic
;
3436 struct rt2870_softc_vap
*rvap
;
3437 const struct ieee80211_txparam
*tp
;
3439 struct rt2870_txwi txwi
;
3445 rvap
= (struct rt2870_softc_vap
*) vap
;
3446 tp
= &vap
->iv_txparms
[ieee80211_chan2mode(ic
->ic_bsschan
)];
3448 m
= ieee80211_beacon_alloc(vap
->iv_bss
, &rvap
->beacon_offsets
);
3452 rate
= tp
->mgmtrate
;
3453 mcs
= rt2870_rate2mcs(rate
);
3455 memset(&txwi
, 0, sizeof(struct rt2870_txwi
));
3458 txwi
.pid_mpdu_len
= ((htole16(m
->m_pkthdr
.len
) & RT2870_TXWI_MPDU_LEN_MASK
) <<
3459 RT2870_TXWI_MPDU_LEN_SHIFT
);
3460 txwi
.txop
= (RT2870_TXWI_TXOP_HT
<< RT2870_TXWI_TXOP_SHIFT
);
3461 txwi
.mpdu_density_flags
|=
3462 (RT2870_TXWI_FLAGS_TS
<< RT2870_TXWI_FLAGS_SHIFT
);
3463 txwi
.bawin_size_xflags
|=
3464 (RT2870_TXWI_XFLAGS_NSEQ
<< RT2870_TXWI_XFLAGS_SHIFT
);
3466 if (ieee80211_rate2phytype(ic
->ic_rt
, rate
) != IEEE80211_T_OFDM
)
3468 txwi
.phymode_ifs_stbc_shortgi
=
3469 (RT2870_TXWI_PHYMODE_CCK
<< RT2870_TXWI_PHYMODE_SHIFT
);
3471 if (rate
!= 2 && (ic
->ic_flags
& IEEE80211_F_SHPREAMBLE
))
3472 mcs
|= RT2870_TXWI_MCS_SHOTPRE
;
3476 txwi
.phymode_ifs_stbc_shortgi
=
3477 (RT2870_TXWI_PHYMODE_OFDM
<< RT2870_TXWI_PHYMODE_SHIFT
);
3480 txwi
.bw_mcs
= (RT2870_TXWI_BW_20
<< RT2870_TXWI_BW_SHIFT
) |
3481 ((mcs
& RT2870_TXWI_MCS_MASK
) << RT2870_TXWI_MCS_SHIFT
);
3483 /* disable temporarily TSF sync */
3485 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_BCN_TIME_CFG
);
3487 tmp
&= ~(RT2870_REG_BCN_TX_ENABLE
|
3488 RT2870_REG_TSF_TIMER_ENABLE
|
3489 RT2870_REG_TBTT_TIMER_ENABLE
);
3491 rt2870_io_mac_write(sc
, RT2870_REG_BCN_TIME_CFG
, tmp
);
3493 /* write Tx wireless info and beacon frame to on-chip memory */
3495 rt2870_io_mac_write_multi(sc
, RT2870_REG_BEACON_BASE(0),
3496 &txwi
, sizeof(struct rt2870_txwi
));
3498 rt2870_io_mac_write_multi(sc
, RT2870_REG_BEACON_BASE(0) + sizeof(struct rt2870_txwi
),
3499 mtod(m
, uint8_t *), m
->m_pkthdr
.len
);
3501 /* enable again TSF sync */
3503 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_BCN_TIME_CFG
);
3505 tmp
|= (RT2870_REG_BCN_TX_ENABLE
|
3506 RT2870_REG_TSF_TIMER_ENABLE
|
3507 RT2870_REG_TBTT_TIMER_ENABLE
);
3509 rt2870_io_mac_write(sc
, RT2870_REG_BCN_TIME_CFG
, tmp
);
3517 * rt2870_asic_clear_keytables
3519 static void rt2870_asic_clear_keytables(struct rt2870_softc
*sc
)
3523 /* clear Rx WCID search table (entries = 256, entry size = 8) */
3525 for (i
= 0; i
< 256; i
++)
3527 rt2870_io_mac_write(sc
, RT2870_REG_WCID(i
), 0xffffffff);
3528 rt2870_io_mac_write(sc
, RT2870_REG_WCID(i
) + 4, 0x0000ffff);
3531 /* clear WCID attribute table (entries = 256, entry size = 4) */
3533 rt2870_io_mac_set_region_4(sc
, RT2870_REG_WCID_ATTR(0), 0, 256);
3535 /* clear IV/EIV table (entries = 256, entry size = 8) */
3537 rt2870_io_mac_set_region_4(sc
, RT2870_REG_IVEIV(0), 0, 2 * 256);
3539 /* clear pairwise key table (entries = 256, entry size = 32) */
3541 rt2870_io_mac_set_region_4(sc
, RT2870_REG_PKEY(0), 0, 8 * 256);
3543 /* clear shared key table (entries = 32, entry size = 32) */
3545 rt2870_io_mac_set_region_4(sc
, RT2870_REG_SKEY(0, 0), 0, 8 * 32);
3547 /* clear shared key mode (entries = 32, entry size = 2) */
3549 rt2870_io_mac_set_region_4(sc
, RT2870_REG_SKEY_MODE(0), 0, 16);
3555 static uint8_t rt2870_rxrate(struct rt2870_rxwi
*rxwi
)
3557 uint8_t mcs
, phymode
;
3560 mcs
= (rxwi
->bw_mcs
>> RT2870_RXWI_MCS_SHIFT
) & RT2870_RXWI_MCS_MASK
;
3561 phymode
= (rxwi
->phymode_stbc_shortgi
>> RT2870_RXWI_PHYMODE_SHIFT
) &
3562 RT2870_RXWI_PHYMODE_MASK
;
3568 case RT2870_RXWI_PHYMODE_CCK
:
3569 switch (mcs
& ~RT2870_RXWI_MCS_SHOTPRE
)
3571 case 0: rate
= 2; break; /* 1 Mbps */
3572 case 1: rate
= 4; break; /* 2 MBps */
3573 case 2: rate
= 11; break; /* 5.5 Mbps */
3574 case 3: rate
= 22; break; /* 11 Mbps */
3578 case RT2870_RXWI_PHYMODE_OFDM
:
3581 case 0: rate
= 12; break; /* 6 Mbps */
3582 case 1: rate
= 18; break; /* 9 Mbps */
3583 case 2: rate
= 24; break; /* 12 Mbps */
3584 case 3: rate
= 36; break; /* 18 Mbps */
3585 case 4: rate
= 48; break; /* 24 Mbps */
3586 case 5: rate
= 72; break; /* 36 Mbps */
3587 case 6: rate
= 96; break; /* 48 Mbps */
3588 case 7: rate
= 108; break; /* 54 Mbps */
3592 case RT2870_RXWI_PHYMODE_HT_MIXED
:
3593 case RT2870_RXWI_PHYMODE_HT_GF
:
3601 * rt2870_maxrssi_rxpath
3603 static uint8_t rt2870_maxrssi_rxpath(struct rt2870_softc
*sc
,
3604 const struct rt2870_rxwi
*rxwi
)
3610 if (sc
->nrxpath
> 1)
3611 if (rxwi
->rssi
[1] > rxwi
->rssi
[rxpath
])
3614 if (sc
->nrxpath
> 2)
3615 if (rxwi
->rssi
[2] > rxwi
->rssi
[rxpath
])
3624 static int8_t rt2870_rssi2dbm(struct rt2870_softc
*sc
,
3625 uint8_t rssi
, uint8_t rxpath
)
3628 struct ieee80211com
*ic
;
3629 struct ieee80211_channel
*c
;
3631 int8_t rssi_off
, lna_gain
;
3639 chan
= ieee80211_chan2ieee(ic
, c
);
3641 if (IEEE80211_IS_CHAN_5GHZ(c
))
3643 rssi_off
= sc
->rssi_off_5ghz
[rxpath
];
3646 lna_gain
= sc
->lna_gain
[1];
3647 else if (chan
<= 128)
3648 lna_gain
= sc
->lna_gain
[2];
3650 lna_gain
= sc
->lna_gain
[3];
3654 rssi_off
= sc
->rssi_off_2ghz
[rxpath
];
3655 lna_gain
= sc
->lna_gain
[0];
3658 return (-12 - rssi_off
- lna_gain
- rssi
);
3664 static uint8_t rt2870_rate2mcs(uint8_t rate
)
3691 static void rt2870_rx_frame(struct rt2870_softc
*sc
,
3692 uint8_t *buf
, uint32_t dmalen
)
3695 struct ieee80211com
*ic
;
3696 struct ieee80211_frame
*wh
;
3697 struct ieee80211_node
*ni
;
3698 struct rt2870_softc_rx_radiotap_header
*tap
;
3699 struct rt2870_rxwi
*rxwi
;
3700 struct rt2870_rxinfo
*rxinfo
;
3702 uint32_t rxinfo_flags
;
3703 uint8_t cipher_err
, rssi
, ant
, phymode
, bw
, shortgi
, mcs
;
3705 int len
, ampdu
, amsdu
, rssi_dbm_rel
;
3710 /* get Rx wireless info */
3712 rxwi
= (struct rt2870_rxwi
*) buf
;
3713 len
= (le16toh(rxwi
->tid_size
) >> RT2870_RXWI_SIZE_SHIFT
) &
3714 RT2870_RXWI_SIZE_MASK
;
3718 RT2870_DPRINTF(sc
, RT2870_DEBUG_RX
,
3719 "%s: bad rxwi len: DMA len=%d, rxwi len=%d\n",
3720 device_get_nameunit(sc
->dev
), dmalen
, len
);
3726 rxinfo
= (struct rt2870_rxinfo
*) ((caddr_t
) rxwi
+ dmalen
);
3727 rxinfo_flags
= le32toh(rxinfo
->flags
);
3729 RT2870_DPRINTF(sc
, RT2870_DEBUG_RX
,
3730 "%s: Rx frame: DMA len=%d, len=%d, rxinfo flags=0x%08x\n",
3731 device_get_nameunit(sc
->dev
), dmalen
, len
, rxinfo_flags
);
3733 /* check for crc errors */
3735 if (rxinfo_flags
& RT2870_RXINFO_FLAGS_CRC_ERR
)
3737 RT2870_DPRINTF(sc
, RT2870_DEBUG_RX
,
3738 "%s: rxinfo: crc error\n",
3739 device_get_nameunit(sc
->dev
));
3743 if (!(ifp
->if_flags
& IFF_PROMISC
))
3747 wh
= (struct ieee80211_frame
*) (rxwi
+ 1);
3749 /* check for L2 padding between IEEE 802.11 frame header and body */
3751 if (rxinfo_flags
& RT2870_RXINFO_FLAGS_L2PAD
)
3753 RT2870_DPRINTF(sc
, RT2870_DEBUG_RX
,
3754 "%s: L2 padding: DMA len=%d, len=%d\n",
3755 device_get_nameunit(sc
->dev
), dmalen
, len
);
3760 m
= m_getjcl(M_DONTWAIT
, MT_DATA
, M_PKTHDR
, MJUMPAGESIZE
);
3763 sc
->rx_mbuf_alloc_errors
++;
3768 m
->m_pkthdr
.rcvif
= ifp
;
3769 m
->m_pkthdr
.len
= m
->m_len
= len
;
3771 m_copyback(m
, 0, len
, (caddr_t
) wh
);
3773 wh
= mtod(m
, struct ieee80211_frame
*);
3775 /* check for cipher errors */
3777 if (rxinfo_flags
& RT2870_RXINFO_FLAGS_DECRYPTED
)
3779 cipher_err
= ((rxinfo_flags
>> RT2870_RXINFO_FLAGS_CIPHER_ERR_SHIFT
) &
3780 RT2870_RXINFO_FLAGS_CIPHER_ERR_MASK
);
3781 if (cipher_err
== RT2870_RXINFO_FLAGS_CIPHER_ERR_NONE
)
3783 if (wh
->i_fc
[1] & IEEE80211_FC1_WEP
)
3784 wh
->i_fc
[1] &= ~IEEE80211_FC1_WEP
;
3786 m
->m_flags
|= M_WEP
;
3790 RT2870_DPRINTF(sc
, RT2870_DEBUG_RX
,
3791 "%s: rxinfo: cipher error=0x%02x\n",
3792 device_get_nameunit(sc
->dev
), cipher_err
);
3796 if (!(ifp
->if_flags
& IFF_PROMISC
))
3805 if (wh
->i_fc
[1] & IEEE80211_FC1_WEP
)
3809 if (!(ifp
->if_flags
& IFF_PROMISC
))
3817 /* check for A-MPDU */
3819 if (rxinfo_flags
& RT2870_RXINFO_FLAGS_AMPDU
)
3821 m
->m_flags
|= M_AMPDU
;
3832 /* check for A-MSDU */
3834 if (rxinfo_flags
& RT2870_RXINFO_FLAGS_AMSDU
)
3845 ant
= rt2870_maxrssi_rxpath(sc
, rxwi
);
3846 rssi
= rxwi
->rssi
[ant
];
3847 rssi_dbm
= rt2870_rssi2dbm(sc
, rssi
, ant
);
3848 phymode
= ((rxwi
->phymode_stbc_shortgi
>> RT2870_RXWI_PHYMODE_SHIFT
) &
3849 RT2870_RXWI_PHYMODE_MASK
);
3850 bw
= ((rxwi
->bw_mcs
>> RT2870_RXWI_BW_SHIFT
) & RT2870_RXWI_BW_MASK
);
3851 shortgi
= ((rxwi
->phymode_stbc_shortgi
>> RT2870_RXWI_SHORTGI_SHIFT
) &
3852 RT2870_RXWI_SHORTGI_MASK
);
3853 mcs
= ((rxwi
->bw_mcs
>> RT2870_RXWI_MCS_SHIFT
) & RT2870_RXWI_MCS_MASK
);
3855 if (ieee80211_radiotap_active(ic
))
3859 tap
->flags
= (rxinfo_flags
& RT2870_RXINFO_FLAGS_L2PAD
) ? IEEE80211_RADIOTAP_F_DATAPAD
: 0;
3860 tap
->dbm_antsignal
= rssi_dbm
;
3861 tap
->dbm_antnoise
= RT2870_NOISE_FLOOR
;
3863 tap
->antsignal
= rssi
;
3864 tap
->chan_flags
= htole32(ic
->ic_curchan
->ic_flags
);
3865 tap
->chan_freq
= htole16(ic
->ic_curchan
->ic_freq
);
3866 tap
->chan_ieee
= ic
->ic_curchan
->ic_ieee
;
3867 tap
->chan_maxpow
= 0;
3869 if (phymode
== RT2870_RXWI_PHYMODE_CCK
|| phymode
== RT2870_RXWI_PHYMODE_OFDM
)
3870 tap
->rate
= rt2870_rxrate(rxwi
);
3872 tap
->rate
= mcs
| IEEE80211_RATE_MCS
;
3874 if (rxwi
->bw_mcs
& RT2870_RXWI_MCS_SHOTPRE
)
3875 tap
->flags
|= IEEE80211_RADIOTAP_F_SHORTPRE
;
3878 tap
->flags
|= IEEE80211_RADIOTAP_F_SHORTGI
;
3882 * net80211 assumes that RSSI data are in the range [-127..127] and
3883 * in .5 dBm units relative to the current noise floor
3886 rssi_dbm_rel
= (rssi_dbm
- RT2870_NOISE_FLOOR
) * 2;
3887 if (rssi_dbm_rel
> 127)
3890 RT2870_DPRINTF(sc
, RT2870_DEBUG_RX
,
3891 "%s: received frame: len=%d, phymode=%d, bw=%d, shortgi=%d, mcs=%d, "
3892 "ant=%d, rssi=%d/%d/%d, snr=%d/%d, wcid=0x%02x, ampdu=%d, amsdu=%d, "
3893 "rssi_dbm=%d, rssi_dbm_rel=%d\n",
3894 device_get_nameunit(sc
->dev
),
3895 len
, phymode
, bw
, shortgi
, mcs
,
3896 ant
, rxwi
->rssi
[0], rxwi
->rssi
[1], rxwi
->rssi
[2],
3897 rxwi
->snr
[0], rxwi
->snr
[1],
3898 rxwi
->wcid
, ampdu
, amsdu
, rssi_dbm
, rssi_dbm_rel
);
3900 ni
= ieee80211_find_rxnode(ic
, (struct ieee80211_frame_min
*) wh
);
3903 ieee80211_input(ni
, m
, rssi_dbm_rel
, RT2870_NOISE_FLOOR
);
3904 ieee80211_free_node(ni
);
3908 ieee80211_input_all(ic
, m
, rssi_dbm_rel
, RT2870_NOISE_FLOOR
);
3915 static int rt2870_tx_mgmt(struct rt2870_softc
*sc
,
3916 struct mbuf
*m
, struct ieee80211_node
*ni
, int qid
)
3919 struct ieee80211com
*ic
;
3920 struct ieee80211vap
*vap
;
3921 const struct ieee80211_txparam
*tp
;
3922 struct rt2870_softc_node
*rni
;
3923 struct rt2870_softc_tx_ring
*ring
;
3924 struct rt2870_softc_tx_data
*data
;
3925 struct rt2870_txinfo
*txinfo
;
3926 struct rt2870_txwi
*txwi
;
3927 struct ieee80211_frame
*wh
;
3928 struct rt2870_softc_tx_radiotap_header
*tap
;
3929 u_int hdrsize
, hdrspace
;
3930 uint8_t rate
, stbc
, shortgi
, mcs
, pid
;
3931 uint16_t len
, dmalen
, mpdu_len
, dur
;
3933 KASSERT(qid
>= 0 && qid
< (sc
->usb_endpoints
- 1),
3934 ("%s: Tx MGMT: invalid qid=%d\n",
3935 device_get_nameunit(sc
->dev
), qid
));
3940 rni
= (struct rt2870_softc_node
*) ni
;
3941 tp
= &vap
->iv_txparms
[ieee80211_chan2mode(ic
->ic_curchan
)];
3943 ring
= &sc
->tx_ring
[qid
];
3944 data
= STAILQ_FIRST(&ring
->inactive
);
3945 STAILQ_REMOVE_HEAD(&ring
->inactive
, next
);
3946 txinfo
= (struct rt2870_txinfo
*) data
->buf
;
3947 txwi
= (struct rt2870_txwi
*) (txinfo
+ 1);
3949 wh
= mtod(m
, struct ieee80211_frame
*);
3951 rate
= tp
->mgmtrate
& IEEE80211_RATE_VAL
;
3953 len
= sizeof(struct rt2870_txinfo
) + sizeof(struct rt2870_txwi
) + m
->m_pkthdr
.len
;
3955 /* align end on a 4-bytes boundary */
3957 dmalen
= (len
+ 3) & ~3;
3961 memset(txinfo
, 0, sizeof(struct rt2870_txinfo
));
3963 txinfo
->len
= htole16(dmalen
- sizeof(struct rt2870_txinfo
));
3965 txinfo
->qsel_flags
= (RT2870_TXINFO_QSEL_EDCA
<< RT2870_TXINFO_QSEL_SHIFT
);
3969 memset((caddr_t
) txinfo
+ len
, 0, dmalen
- len
);
3971 /* fill Tx wireless info */
3973 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
3976 mcs
= rt2870_rate2mcs(rate
);
3980 /* calculate MPDU length without padding */
3982 hdrsize
= ieee80211_hdrsize(wh
);
3983 hdrspace
= ieee80211_hdrspace(ic
, wh
);
3984 mpdu_len
= m
->m_pkthdr
.len
- hdrspace
+ hdrsize
;
3986 memset(txwi
, 0, sizeof(struct rt2870_txwi
));
3988 /* management frames do not need encryption */
3992 txwi
->pid_mpdu_len
= ((htole16(pid
) & RT2870_TXWI_PID_MASK
) <<
3993 RT2870_TXWI_PID_SHIFT
) | ((htole16(mpdu_len
) & RT2870_TXWI_MPDU_LEN_MASK
) <<
3994 RT2870_TXWI_MPDU_LEN_SHIFT
);
3996 stbc
= (ni
->ni_htcap
& IEEE80211_HTCAP_RXSTBC
) ? 1 : 0;
3998 shortgi
= (vap
->iv_flags_ht
& (IEEE80211_FHT_SHORTGI20
| IEEE80211_FHT_SHORTGI40
)) &&
3999 (ni
->ni_flags
& IEEE80211_NODE_HT
);
4001 txwi
->phymode_ifs_stbc_shortgi
|=
4002 ((stbc
& RT2870_TXWI_STBC_MASK
) << RT2870_TXWI_STBC_SHIFT
) |
4003 ((shortgi
& RT2870_TXWI_SHORTGI_MASK
) << RT2870_TXWI_SHORTGI_SHIFT
);
4005 txwi
->phymode_ifs_stbc_shortgi
|=
4006 ((shortgi
& RT2870_TXWI_SHORTGI_MASK
) << RT2870_TXWI_SHORTGI_SHIFT
);
4008 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
4010 txwi
->phymode_ifs_stbc_shortgi
|=
4011 (RT2870_TXWI_PHYMODE_HT_MIXED
<< RT2870_TXWI_PHYMODE_SHIFT
);
4015 if (ieee80211_rate2phytype(ic
->ic_rt
, rate
) != IEEE80211_T_OFDM
)
4017 txwi
->phymode_ifs_stbc_shortgi
|=
4018 (RT2870_TXWI_PHYMODE_CCK
<< RT2870_TXWI_PHYMODE_SHIFT
);
4020 if (rate
!= 2 && (ic
->ic_flags
& IEEE80211_F_SHPREAMBLE
))
4021 mcs
|= RT2870_TXWI_MCS_SHOTPRE
;
4025 txwi
->phymode_ifs_stbc_shortgi
|=
4026 (RT2870_TXWI_PHYMODE_OFDM
<< RT2870_TXWI_PHYMODE_SHIFT
);
4030 txwi
->bw_mcs
= (RT2870_TXWI_BW_20
<< RT2870_TXWI_BW_SHIFT
) |
4031 ((mcs
& RT2870_TXWI_MCS_MASK
) << RT2870_TXWI_MCS_SHIFT
);
4033 txwi
->txop
= (RT2870_TXWI_TXOP_BACKOFF
<< RT2870_TXWI_TXOP_SHIFT
);
4035 /* skip ACKs for multicast frames and probe responses */
4037 if (!IEEE80211_IS_MULTICAST(wh
->i_addr1
) &&
4038 ((wh
->i_fc
[0] & (IEEE80211_FC0_TYPE_MASK
| IEEE80211_FC0_SUBTYPE_MASK
)) !=
4039 (IEEE80211_FC0_TYPE_MGT
| IEEE80211_FC0_SUBTYPE_PROBE_RESP
)))
4041 txwi
->bawin_size_xflags
|=
4042 (RT2870_TXWI_XFLAGS_ACK
<< RT2870_TXWI_XFLAGS_SHIFT
);
4044 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
4046 /* preamble + plcp + signal extension */
4052 dur
= ieee80211_ack_duration(ic
->ic_rt
, rate
,
4053 ic
->ic_flags
& IEEE80211_F_SHPREAMBLE
);
4056 *(uint16_t *) wh
->i_dur
= htole16(dur
);
4059 /* ask MAC to insert timestamp into probe responses */
4061 if ((wh
->i_fc
[0] & (IEEE80211_FC0_TYPE_MASK
| IEEE80211_FC0_SUBTYPE_MASK
)) ==
4062 (IEEE80211_FC0_TYPE_MGT
| IEEE80211_FC0_SUBTYPE_PROBE_RESP
))
4063 txwi
->mpdu_density_flags
|=
4064 (RT2870_TXWI_FLAGS_TS
<< RT2870_TXWI_FLAGS_SHIFT
);
4066 if (ieee80211_radiotap_active_vap(vap
))
4070 tap
->flags
= IEEE80211_RADIOTAP_F_DATAPAD
;
4071 tap
->chan_flags
= htole32(ic
->ic_curchan
->ic_flags
);
4072 tap
->chan_freq
= htole16(ic
->ic_curchan
->ic_freq
);
4073 tap
->chan_ieee
= ic
->ic_curchan
->ic_ieee
;
4074 tap
->chan_maxpow
= 0;
4076 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
4077 tap
->rate
= mcs
| IEEE80211_RATE_MCS
;
4081 if (mcs
& RT2870_TXWI_MCS_SHOTPRE
)
4082 tap
->flags
|= IEEE80211_RADIOTAP_F_SHORTPRE
;
4085 tap
->flags
|= IEEE80211_RADIOTAP_F_SHORTGI
;
4087 if (wh
->i_fc
[1] & IEEE80211_FC1_WEP
)
4088 tap
->flags
|= IEEE80211_RADIOTAP_F_WEP
;
4090 if (wh
->i_fc
[1] & IEEE80211_FC1_WEP
)
4092 wh
->i_fc
[1] &= ~IEEE80211_FC1_WEP
;
4094 ieee80211_radiotap_tx(vap
, m
);
4096 wh
->i_fc
[1] |= IEEE80211_FC1_WEP
;
4100 ieee80211_radiotap_tx(vap
, m
);
4104 m_copydata(m
, 0, m
->m_pkthdr
.len
, (caddr_t
) (txwi
+ 1));
4106 RT2870_DPRINTF(sc
, RT2870_DEBUG_TX
,
4107 "%s: sending MGMT frame: qid=%d, hdrsize=%d, hdrspace=%d, len=%d, "
4108 "stbc=%d, shortgi=%d, mcs=%d, DMA len=%d\n",
4109 device_get_nameunit(sc
->dev
),
4110 qid
, hdrsize
, hdrspace
, m
->m_pkthdr
.len
, stbc
, shortgi
, mcs
, dmalen
);
4116 STAILQ_INSERT_TAIL(&ring
->pending
, data
, next
);
4119 usbd_transfer_start(sc
->usb_xfer
[1 + qid
]);
4127 static int rt2870_tx_data(struct rt2870_softc
*sc
,
4128 struct mbuf
*m
, struct ieee80211_node
*ni
, int qid
)
4131 struct ieee80211com
*ic
;
4132 struct ieee80211vap
*vap
;
4133 const struct ieee80211_txparam
*tp
;
4134 struct rt2870_softc_node
*rni
;
4135 struct rt2870_softc_tx_ring
*ring
;
4136 struct rt2870_softc_tx_data
*data
;
4137 struct rt2870_txinfo
*txinfo
;
4138 struct rt2870_txwi
*txwi
;
4139 struct ieee80211_frame
*wh
;
4140 struct rt2870_softc_tx_radiotap_header
*tap
;
4141 u_int hdrsize
, hdrspace
;
4142 uint8_t type
, rate
, bw
, stbc
, shortgi
, mcs
, pid
, wcid
;
4143 uint16_t qos
, len
, dmalen
, mpdu_len
, dur
;
4146 KASSERT(qid
>= 0 && qid
< (sc
->usb_endpoints
- 1),
4147 ("%s: Tx data: invalid qid=%d\n",
4148 device_get_nameunit(sc
->dev
), qid
));
4153 rni
= (struct rt2870_softc_node
*) ni
;
4154 tp
= &vap
->iv_txparms
[ieee80211_chan2mode(ni
->ni_chan
)];
4156 ring
= &sc
->tx_ring
[qid
];
4157 data
= STAILQ_FIRST(&ring
->inactive
);
4158 STAILQ_REMOVE_HEAD(&ring
->inactive
, next
);
4159 txinfo
= (struct rt2870_txinfo
*) data
->buf
;
4160 txwi
= (struct rt2870_txwi
*) (txinfo
+ 1);
4162 wh
= mtod(m
, struct ieee80211_frame
*);
4164 type
= wh
->i_fc
[0] & IEEE80211_FC0_TYPE_MASK
;
4166 hasqos
= IEEE80211_QOS_HAS_SEQ(wh
);
4169 if (IEEE80211_HAS_ADDR4(wh
))
4170 qos
= le16toh(*(const uint16_t *)
4171 (((struct ieee80211_qosframe_addr4
*) wh
)->i_qos
));
4173 qos
= le16toh(*(const uint16_t *)
4174 (((struct ieee80211_qosframe
*) wh
)->i_qos
));
4181 if (IEEE80211_IS_MULTICAST(wh
->i_addr1
))
4182 rate
= tp
->mcastrate
;
4183 else if (m
->m_flags
& M_EAPOL
)
4184 rate
= tp
->mgmtrate
;
4185 else if (tp
->ucastrate
!= IEEE80211_FIXED_RATE_NONE
)
4186 rate
= tp
->ucastrate
;
4188 rate
= ni
->ni_txrate
;
4190 rate
&= IEEE80211_RATE_VAL
;
4192 len
= sizeof(struct rt2870_txinfo
) + sizeof(struct rt2870_txwi
) + m
->m_pkthdr
.len
;
4194 /* align end on a 4-bytes boundary */
4196 dmalen
= (len
+ 3) & ~3;
4200 memset(txinfo
, 0, sizeof(struct rt2870_txinfo
));
4202 txinfo
->len
= htole16(dmalen
- sizeof(struct rt2870_txinfo
));
4204 txinfo
->qsel_flags
= (RT2870_TXINFO_QSEL_EDCA
<< RT2870_TXINFO_QSEL_SHIFT
);
4208 memset((caddr_t
) txinfo
+ len
, 0, dmalen
- len
);
4210 /* fill Tx wireless info */
4212 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
4215 mcs
= rt2870_rate2mcs(rate
);
4219 wcid
= (type
== IEEE80211_FC0_TYPE_DATA
) ?
4220 RT2870_AID2WCID(ni
->ni_associd
) : 0xff;
4222 /* calculate MPDU length without padding */
4224 hdrsize
= ieee80211_hdrsize(wh
);
4225 hdrspace
= ieee80211_hdrspace(ic
, wh
);
4226 mpdu_len
= m
->m_pkthdr
.len
- hdrspace
+ hdrsize
;
4228 memset(txwi
, 0, sizeof(struct rt2870_txwi
));
4232 txwi
->pid_mpdu_len
= ((htole16(pid
) & RT2870_TXWI_PID_MASK
) <<
4233 RT2870_TXWI_PID_SHIFT
) | ((htole16(mpdu_len
) & RT2870_TXWI_MPDU_LEN_MASK
) <<
4234 RT2870_TXWI_MPDU_LEN_SHIFT
);
4236 stbc
= (ni
->ni_htcap
& IEEE80211_HTCAP_RXSTBC
) ? 1 : 0;
4238 shortgi
= (vap
->iv_flags_ht
& (IEEE80211_FHT_SHORTGI20
| IEEE80211_FHT_SHORTGI40
)) &&
4239 (ni
->ni_flags
& IEEE80211_NODE_HT
);
4241 txwi
->phymode_ifs_stbc_shortgi
|=
4242 ((stbc
& RT2870_TXWI_STBC_MASK
) << RT2870_TXWI_STBC_SHIFT
) |
4243 ((shortgi
& RT2870_TXWI_SHORTGI_MASK
) << RT2870_TXWI_SHORTGI_SHIFT
);
4245 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
4247 txwi
->phymode_ifs_stbc_shortgi
|=
4248 (RT2870_TXWI_PHYMODE_HT_MIXED
<< RT2870_TXWI_PHYMODE_SHIFT
);
4252 if (ieee80211_rate2phytype(ic
->ic_rt
, rate
) != IEEE80211_T_OFDM
)
4254 txwi
->phymode_ifs_stbc_shortgi
|=
4255 (RT2870_TXWI_PHYMODE_CCK
<< RT2870_TXWI_PHYMODE_SHIFT
);
4257 if (rate
!= 2 && (ic
->ic_flags
& IEEE80211_F_SHPREAMBLE
))
4258 mcs
|= RT2870_TXWI_MCS_SHOTPRE
;
4262 txwi
->phymode_ifs_stbc_shortgi
|=
4263 (RT2870_TXWI_PHYMODE_OFDM
<< RT2870_TXWI_PHYMODE_SHIFT
);
4267 if ((ni
->ni_flags
& IEEE80211_NODE_HT
) &&
4268 (ni
->ni_htcap
& IEEE80211_HTCAP_CHWIDTH40
))
4269 bw
= RT2870_TXWI_BW_40
;
4271 bw
= RT2870_TXWI_BW_20
;
4273 txwi
->bw_mcs
= ((bw
& RT2870_TXWI_BW_MASK
) << RT2870_TXWI_BW_SHIFT
) |
4274 ((mcs
& RT2870_TXWI_MCS_MASK
) << RT2870_TXWI_MCS_SHIFT
);
4276 txwi
->txop
= (RT2870_TXWI_TXOP_HT
<< RT2870_TXWI_TXOP_SHIFT
);
4278 if (!IEEE80211_IS_MULTICAST(wh
->i_addr1
) &&
4279 (!hasqos
|| (qos
& IEEE80211_QOS_ACKPOLICY
) != IEEE80211_QOS_ACKPOLICY_NOACK
))
4281 txwi
->bawin_size_xflags
|=
4282 (RT2870_TXWI_XFLAGS_ACK
<< RT2870_TXWI_XFLAGS_SHIFT
);
4284 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
4286 /* preamble + plcp + signal extension */
4292 dur
= ieee80211_ack_duration(ic
->ic_rt
, rate
,
4293 ic
->ic_flags
& IEEE80211_F_SHPREAMBLE
);
4296 *(uint16_t *) wh
->i_dur
= htole16(dur
);
4299 /* ask MAC to insert timestamp into probe responses */
4301 if ((wh
->i_fc
[0] & (IEEE80211_FC0_TYPE_MASK
| IEEE80211_FC0_SUBTYPE_MASK
)) ==
4302 (IEEE80211_FC0_TYPE_MGT
| IEEE80211_FC0_SUBTYPE_PROBE_RESP
))
4303 txwi
->mpdu_density_flags
|=
4304 (RT2870_TXWI_FLAGS_TS
<< RT2870_TXWI_FLAGS_SHIFT
);
4306 if (ieee80211_radiotap_active_vap(vap
))
4310 tap
->flags
= IEEE80211_RADIOTAP_F_DATAPAD
;
4311 tap
->chan_flags
= htole32(ic
->ic_curchan
->ic_flags
);
4312 tap
->chan_freq
= htole16(ic
->ic_curchan
->ic_freq
);
4313 tap
->chan_ieee
= ic
->ic_curchan
->ic_ieee
;
4314 tap
->chan_maxpow
= 0;
4316 if (ni
->ni_flags
& IEEE80211_NODE_HT
)
4317 tap
->rate
= mcs
| IEEE80211_RATE_MCS
;
4321 if (mcs
& RT2870_TXWI_MCS_SHOTPRE
)
4322 tap
->flags
|= IEEE80211_RADIOTAP_F_SHORTPRE
;
4325 tap
->flags
|= IEEE80211_RADIOTAP_F_SHORTGI
;
4327 if (wh
->i_fc
[1] & IEEE80211_FC1_WEP
)
4328 tap
->flags
|= IEEE80211_RADIOTAP_F_WEP
;
4330 if (wh
->i_fc
[1] & IEEE80211_FC1_WEP
)
4332 wh
->i_fc
[1] &= ~IEEE80211_FC1_WEP
;
4334 ieee80211_radiotap_tx(vap
, m
);
4336 wh
->i_fc
[1] |= IEEE80211_FC1_WEP
;
4340 ieee80211_radiotap_tx(vap
, m
);
4344 m_copydata(m
, 0, m
->m_pkthdr
.len
, (caddr_t
) (txwi
+ 1));
4346 RT2870_DPRINTF(sc
, RT2870_DEBUG_TX
,
4347 "%s: sending data: qid=%d, hdrsize=%d, hdrspace=%d, len=%d, "
4348 "bw=%d, stbc=%d, shortgi=%d, mcs=%d, wcid=0x%02x, DMA len=%d\n",
4349 device_get_nameunit(sc
->dev
),
4350 qid
, hdrsize
, hdrspace
, m
->m_pkthdr
.len
,
4351 bw
, stbc
, shortgi
, mcs
, wcid
, dmalen
);
4357 STAILQ_INSERT_TAIL(&ring
->pending
, data
, next
);
4360 usbd_transfer_start(sc
->usb_xfer
[1 + qid
]);
4368 static int rt2870_tx_raw(struct rt2870_softc
*sc
,
4369 struct mbuf
*m
, struct ieee80211_node
*ni
,
4370 const struct ieee80211_bpf_params
*params
)
4372 RT2870_DPRINTF(sc
, RT2870_DEBUG_TX
,
4374 device_get_nameunit(sc
->dev
));
4382 static void rt2870_rx_intr(struct usb_xfer
*xfer
, usb_error_t error
)
4384 struct rt2870_softc
*sc
;
4386 struct rt2870_softc_rx_ring
*ring
;
4387 struct rt2870_softc_rx_data
*data
;
4390 sc
= usbd_xfer_softc(xfer
);
4392 ring
= &sc
->rx_ring
;
4394 RT2870_DPRINTF(sc
, RT2870_DEBUG_INTR
,
4395 "%s: Rx interrupt: state=%d, error=%s\n",
4396 device_get_nameunit(sc
->dev
),
4397 USB_GET_STATE(xfer
), usbd_errstr(error
));
4399 switch (USB_GET_STATE(xfer
))
4401 case USB_ST_TRANSFERRED
:
4403 sc
->rx_interrupts
++;
4405 data
= STAILQ_FIRST(&ring
->active
);
4409 STAILQ_REMOVE_HEAD(&ring
->active
, next
);
4411 usbd_xfer_status(xfer
, &len
, NULL
, NULL
, NULL
);
4415 STAILQ_INSERT_TAIL(&ring
->done
, data
, next
);
4417 taskqueue_enqueue(sc
->taskqueue
, &sc
->rx_done_task
);
4424 data
= STAILQ_FIRST(&ring
->inactive
);
4428 STAILQ_REMOVE_HEAD(&ring
->inactive
, next
);
4430 STAILQ_INSERT_TAIL(&ring
->active
, data
, next
);
4432 usbd_xfer_set_frame_data(xfer
, 0, data
->buf
, usbd_xfer_max_len(xfer
));
4433 usbd_transfer_submit(xfer
);
4438 sc
->rx_interrupts
++;
4440 data
= STAILQ_FIRST(&ring
->active
);
4443 STAILQ_REMOVE_HEAD(&ring
->active
, next
);
4444 STAILQ_INSERT_TAIL(&ring
->inactive
, data
, next
);
4447 if (error
!= USB_ERR_CANCELLED
)
4451 usbd_xfer_set_stall(xfer
);
4462 static void rt2870_tx_intr(struct usb_xfer
*xfer
, usb_error_t error
)
4464 struct rt2870_softc
*sc
;
4466 struct rt2870_softc_tx_ring
*ring
;
4467 struct rt2870_softc_tx_data
*data
;
4469 sc
= usbd_xfer_softc(xfer
);
4471 ring
= usbd_xfer_get_priv(xfer
);
4473 usbd_xfer_status(xfer
, NULL
, NULL
, NULL
, NULL
);
4475 RT2870_DPRINTF(sc
, RT2870_DEBUG_INTR
,
4476 "%s: Tx interrupt: state=%d, error=%s\n",
4477 device_get_nameunit(sc
->dev
),
4478 USB_GET_STATE(xfer
), usbd_errstr(error
));
4480 switch (USB_GET_STATE(xfer
))
4482 case USB_ST_TRANSFERRED
:
4484 sc
->tx_interrupts
[ring
->qid
]++;
4486 data
= STAILQ_FIRST(&ring
->active
);
4490 STAILQ_REMOVE_HEAD(&ring
->active
, next
);
4492 STAILQ_INSERT_TAIL(&ring
->done
, data
, next
);
4494 sc
->tx_qid_pending_mask
|= (1 << ring
->qid
);
4496 taskqueue_enqueue(sc
->taskqueue
, &sc
->tx_done_task
);
4503 data
= STAILQ_FIRST(&ring
->pending
);
4507 STAILQ_REMOVE_HEAD(&ring
->pending
, next
);
4508 STAILQ_INSERT_TAIL(&ring
->active
, data
, next
);
4510 usbd_xfer_set_frame_data(xfer
, 0, data
->buf
, data
->len
);
4511 usbd_transfer_submit(xfer
);
4513 RT2870_SOFTC_UNLOCK(sc
);
4517 RT2870_SOFTC_LOCK(sc
);
4522 sc
->tx_interrupts
[ring
->qid
]++;
4524 data
= STAILQ_FIRST(&ring
->active
);
4527 STAILQ_REMOVE_HEAD(&ring
->active
, next
);
4529 printf("%s: could not transmit buffer: qid=%d, error=%s\n",
4530 device_get_nameunit(sc
->dev
), ring
->qid
, usbd_errstr(error
));
4532 if (data
->m
!= NULL
)
4538 if (data
->ni
!= NULL
)
4540 ieee80211_free_node(data
->ni
);
4544 STAILQ_INSERT_TAIL(&ring
->inactive
, data
, next
);
4549 if (error
!= USB_ERR_CANCELLED
)
4552 ifp
->if_drv_flags
&= ~IFF_DRV_OACTIVE
;
4554 usbd_xfer_set_stall(xfer
);
4563 * rt2870_rx_done_task
4565 static void rt2870_rx_done_task(void *context
, int pending
)
4567 struct rt2870_softc
*sc
;
4573 RT2870_DPRINTF(sc
, RT2870_DEBUG_RX
,
4574 "%s: Rx done task\n",
4575 device_get_nameunit(sc
->dev
));
4577 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
4580 if (rt2870_rx_eof(sc
, sc
->rx_process_limit
) != 0)
4582 RT2870_DPRINTF(sc
, RT2870_DEBUG_RX
,
4583 "%s: Rx done task: scheduling again\n",
4584 device_get_nameunit(sc
->dev
));
4586 taskqueue_enqueue(sc
->taskqueue
, &sc
->rx_done_task
);
4591 * rt2870_tx_done_task
4593 static void rt2870_tx_done_task(void *context
, int pending
)
4595 struct rt2870_softc
*sc
;
4602 RT2870_DPRINTF(sc
, RT2870_DEBUG_TX
,
4603 "%s: Tx done task\n",
4604 device_get_nameunit(sc
->dev
));
4606 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
4609 for (i
= sc
->usb_endpoints
- 2; i
>= 0; i
--)
4611 if (sc
->tx_qid_pending_mask
& (1 << i
))
4613 sc
->tx_qid_pending_mask
&= ~(1 << i
);
4615 rt2870_tx_eof(sc
, &sc
->tx_ring
[i
]);
4619 if (sc
->tx_qid_pending_mask
!= 0)
4621 RT2870_DPRINTF(sc
, RT2870_DEBUG_TX
,
4622 "%s: Tx done task: scheduling again\n",
4623 device_get_nameunit(sc
->dev
));
4625 taskqueue_enqueue(sc
->taskqueue
, &sc
->tx_done_task
);
4630 ifp
->if_drv_flags
&= ~IFF_DRV_OACTIVE
;
4634 * rt2870_periodic_task
4636 static void rt2870_periodic_task(void *context
, int pending
)
4638 struct rt2870_softc
*sc
;
4640 struct ieee80211com
*ic
;
4641 struct ieee80211vap
*vap
;
4646 vap
= TAILQ_FIRST(&ic
->ic_vaps
);
4648 RT2870_DPRINTF(sc
, RT2870_DEBUG_PERIODIC
,
4649 "%s: periodic task: round=%lu\n",
4650 device_get_nameunit(sc
->dev
), sc
->periodic_round
);
4652 if (!(ifp
->if_drv_flags
& IFF_DRV_RUNNING
))
4655 RT2870_SOFTC_LOCK(sc
);
4657 sc
->periodic_round
++;
4659 rt2870_update_stats(sc
);
4661 if ((sc
->periodic_round
% 10) == 0)
4663 rt2870_bbp_tuning(sc
);
4665 rt2870_update_raw_counters(sc
);
4667 rt2870_watchdog(sc
);
4669 if (vap
!= NULL
&& vap
->iv_opmode
!= IEEE80211_M_MONITOR
&& vap
->iv_state
== IEEE80211_S_RUN
)
4671 if (vap
->iv_opmode
== IEEE80211_M_STA
)
4672 rt2870_amrr_update_iter_func(vap
, vap
->iv_bss
);
4674 ieee80211_iterate_nodes(&ic
->ic_sta
, rt2870_amrr_update_iter_func
, vap
);
4678 RT2870_SOFTC_UNLOCK(sc
);
4680 callout_reset(&sc
->periodic_ch
, hz
/ 10, rt2870_periodic
, sc
);
4686 static void rt2870_cmd_task(void *context
, int pending
)
4688 struct rt2870_softc
*sc
;
4689 struct rt2870_softc_cmd_ring
*ring
;
4690 struct rt2870_softc_cmd
*cmd
;
4693 ring
= &sc
->cmd_ring
;
4697 RT2870_SOFTC_LOCK(sc
);
4699 cmd
= STAILQ_FIRST(&ring
->active
);
4702 RT2870_SOFTC_UNLOCK(sc
);
4706 STAILQ_REMOVE_HEAD(&ring
->active
, next
);
4708 RT2870_SOFTC_UNLOCK(sc
);
4710 cmd
->cb(sc
, cmd
->data
);
4712 RT2870_SOFTC_LOCK(sc
);
4714 STAILQ_INSERT_TAIL(&ring
->inactive
, cmd
, next
);
4717 RT2870_SOFTC_UNLOCK(sc
);
4724 static int rt2870_rx_eof(struct rt2870_softc
*sc
, int limit
)
4727 struct rt2870_softc_rx_ring
*ring
;
4728 struct rt2870_softc_rx_data
*data
;
4734 ring
= &sc
->rx_ring
;
4740 RT2870_SOFTC_LOCK(sc
);
4742 data
= STAILQ_FIRST(&ring
->done
);
4745 RT2870_SOFTC_UNLOCK(sc
);
4749 STAILQ_REMOVE_HEAD(&ring
->done
, next
);
4751 RT2870_SOFTC_UNLOCK(sc
);
4756 if (len
< RT2870_RX_DESC_SIZE
)
4762 while (len
> (sizeof(uint32_t) + sizeof(struct rt2870_rxinfo
)))
4764 dmalen
= (le32toh(*(uint32_t *) buf
) & 0xffff);
4766 if (dmalen
== 0 || (dmalen
& 3) != 0)
4768 RT2870_DPRINTF(sc
, RT2870_DEBUG_RX
,
4769 "%s: bad DMA len=%u\n",
4770 device_get_nameunit(sc
->dev
), dmalen
);
4774 if ((dmalen
+ sizeof(uint32_t) + sizeof(struct rt2870_rxinfo
)) > len
)
4776 RT2870_DPRINTF(sc
, RT2870_DEBUG_RX
,
4777 "%s: bad DMA len: DMA len=%u, USB len=%d\n",
4778 device_get_nameunit(sc
->dev
),
4779 (unsigned int) (dmalen
+ sizeof(uint32_t) + sizeof(struct rt2870_rxinfo
)), len
);
4785 rt2870_rx_frame(sc
, buf
+ sizeof(uint32_t), dmalen
);
4787 buf
+= (dmalen
+ sizeof(uint32_t) + sizeof(struct rt2870_rxinfo
));
4788 len
-= (dmalen
+ sizeof(uint32_t) + sizeof(struct rt2870_rxinfo
));
4793 RT2870_SOFTC_LOCK(sc
);
4795 STAILQ_INSERT_TAIL(&ring
->inactive
, data
, next
);
4797 usbd_transfer_start(sc
->usb_xfer
[0]);
4799 RT2870_SOFTC_UNLOCK(sc
);
4804 RT2870_DPRINTF(sc
, RT2870_DEBUG_RX
,
4805 "%s: Rx eof: nframes=%d\n",
4806 device_get_nameunit(sc
->dev
), nframes
);
4808 sc
->rx_packets
+= nframes
;
4810 return (limit
== 0);
4816 static void rt2870_tx_eof(struct rt2870_softc
*sc
,
4817 struct rt2870_softc_tx_ring
*ring
)
4820 struct rt2870_softc_tx_data
*data
;
4829 RT2870_SOFTC_LOCK(sc
);
4831 data
= STAILQ_FIRST(&ring
->done
);
4834 RT2870_SOFTC_UNLOCK(sc
);
4838 STAILQ_REMOVE_HEAD(&ring
->done
, next
);
4840 RT2870_SOFTC_UNLOCK(sc
);
4844 if (data
->m
->m_flags
& M_TXCB
)
4845 ieee80211_process_callback(data
->ni
, data
->m
, 0);
4849 ieee80211_free_node(data
->ni
);
4854 RT2870_SOFTC_LOCK(sc
);
4856 STAILQ_INSERT_TAIL(&ring
->inactive
, data
, next
);
4861 RT2870_SOFTC_UNLOCK(sc
);
4864 RT2870_DPRINTF(sc
, RT2870_DEBUG_TX
,
4865 "%s: Tx eof: qid=%d, nframes=%d\n",
4866 device_get_nameunit(sc
->dev
), ring
->qid
, nframes
);
4870 * rt2870_update_stats
4872 static void rt2870_update_stats(struct rt2870_softc
*sc
)
4875 struct ieee80211com
*ic
;
4876 struct ieee80211vap
*vap
;
4877 struct ieee80211_node
*ni
;
4879 int beacons
, noretryok
, retryok
, failed
;
4885 vap
= TAILQ_FIRST(&ic
->ic_vaps
);
4887 RT2870_DPRINTF(sc
, RT2870_DEBUG_STATS
,
4888 "%s: update statistic\n",
4889 device_get_nameunit(sc
->dev
));
4891 rt2870_drain_fifo_stats(sc
);
4893 /* read and clear Tx statistic registers */
4895 rt2870_io_mac_read_multi(sc
, RT2870_REG_TX_STA_CNT0
,
4896 stacnt
, sizeof(stacnt
));
4898 stacnt
[0] = le32toh(stacnt
[0]);
4899 stacnt
[1] = le32toh(stacnt
[1]);
4900 stacnt
[2] = le32toh(stacnt
[2]);
4902 beacons
= stacnt
[0] >> 16;
4903 noretryok
= stacnt
[1] & 0xffff;
4904 retryok
= stacnt
[1] >> 16;
4905 failed
= stacnt
[0] & 0xffff;
4907 RT2870_DPRINTF(sc
, RT2870_DEBUG_STATS
,
4908 "%s: update statistic: beacons=%d, noretryok=%d, retryok=%d, failed=%d\n",
4909 device_get_nameunit(sc
->dev
),
4910 beacons
, noretryok
, retryok
, failed
);
4912 ifp
->if_oerrors
+= failed
;
4914 sc
->tx_beacons
+= beacons
;
4915 sc
->tx_noretryok
+= noretryok
;
4916 sc
->tx_retryok
+= retryok
;
4917 sc
->tx_failed
+= failed
;
4919 if (vap
!= NULL
&& vap
->iv_opmode
== IEEE80211_M_STA
&& vap
->iv_state
== IEEE80211_S_RUN
)
4923 associd
= (ni
!= NULL
) ? ni
->ni_associd
: 0;
4924 wcid
= RT2870_AID2WCID(associd
);
4926 rt2870_amrr_tx_update(&sc
->amrr_node
[wcid
],
4927 noretryok
+ retryok
+ failed
, noretryok
+ retryok
, retryok
+ failed
);
4934 static void rt2870_bbp_tuning(struct rt2870_softc
*sc
)
4937 struct ieee80211com
*ic
;
4938 struct ieee80211vap
*vap
;
4939 struct ieee80211_node
*ni
;
4941 int8_t rssi
, old
, new;
4943 /* RT2860C does not support BBP tuning */
4945 if (sc
->mac_rev
== 0x28600100)
4950 vap
= TAILQ_FIRST(&ic
->ic_vaps
);
4952 if ((ic
->ic_flags
& IEEE80211_F_SCAN
) || vap
== NULL
||
4953 vap
->iv_opmode
!= IEEE80211_M_STA
|| vap
->iv_state
!= IEEE80211_S_RUN
)
4958 chan
= ieee80211_chan2ieee(ic
, ni
->ni_chan
);
4962 else if (chan
<= 64)
4964 else if (chan
<= 128)
4969 rssi
= ieee80211_getrssi(vap
);
4971 if (IEEE80211_IS_CHAN_2GHZ(ni
->ni_chan
))
4973 new = 0x2e + sc
->lna_gain
[group
];
4977 if (!IEEE80211_IS_CHAN_HT40(ni
->ni_chan
))
4978 new = 0x32 + sc
->lna_gain
[group
] * 5 / 3;
4980 new = 0x3a + sc
->lna_gain
[group
] * 5 / 3;
4983 /* Tune if absolute average RSSI is greater than -80 */
4988 old
= rt2870_io_bbp_read(sc
, 66);
4991 rt2870_io_bbp_write(sc
, 66, new);
4997 static void rt2870_watchdog(struct rt2870_softc
*sc
)
5002 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_PBF_TXRXQ_PCNT
);
5004 RT2870_DPRINTF(sc
, RT2870_DEBUG_WATCHDOG
,
5005 "%s: watchdog: TXRXQ_PCNT=0x%08x\n",
5006 device_get_nameunit(sc
->dev
), tmp
);
5008 if (((tmp
>> RT2870_REG_TX0Q_PCNT_SHIFT
) & RT2870_REG_TX0Q_PCNT_MASK
) != 0)
5010 sc
->tx_queue_not_empty
[0]++;
5012 rt2870_io_mac_write(sc
, RT2870_REG_PBF_CFG
, 0xf40012);
5014 for (ntries
= 0; ntries
< 10; ntries
++)
5016 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_PBF_TXRXQ_PCNT
);
5017 if (((tmp
>> RT2870_REG_TX0Q_PCNT_SHIFT
) & RT2870_REG_TX0Q_PCNT_MASK
) == 0)
5023 rt2870_io_mac_write(sc
, RT2870_REG_PBF_CFG
, 0xf40006);
5026 if (((tmp
>> RT2870_REG_TX1Q_PCNT_SHIFT
) & RT2870_REG_TX1Q_PCNT_MASK
) != 0)
5028 sc
->tx_queue_not_empty
[1]++;
5030 rt2870_io_mac_write(sc
, RT2870_REG_PBF_CFG
, 0xf4000a);
5032 for (ntries
= 0; ntries
< 10; ntries
++)
5034 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_PBF_TXRXQ_PCNT
);
5035 if (((tmp
>> RT2870_REG_TX1Q_PCNT_SHIFT
) & RT2870_REG_TX1Q_PCNT_MASK
) == 0)
5041 rt2870_io_mac_write(sc
, RT2870_REG_PBF_CFG
, 0xf40006);
5046 * rt2870_drain_fifo_stats
5048 static void rt2870_drain_fifo_stats(struct rt2870_softc
*sc
)
5052 uint8_t wcid
, mcs
, pid
;
5057 /* drain Tx status FIFO (maxsize = 16) */
5059 while ((stats
= rt2870_io_mac_read(sc
, RT2870_REG_TX_STA_FIFO
)) &
5060 RT2870_REG_TX_STA_FIFO_VALID
)
5062 wcid
= (stats
>> RT2870_REG_TX_STA_FIFO_WCID_SHIFT
) &
5063 RT2870_REG_TX_STA_FIFO_WCID_MASK
;
5065 /* if no ACK was requested, no feedback is available */
5067 if (!(stats
& RT2870_REG_TX_STA_FIFO_ACK_REQ
) || wcid
== 0xff)
5070 /* update AMRR statistic */
5072 ok
= (stats
& RT2870_REG_TX_STA_FIFO_TX_OK
) ? 1 : 0;
5073 mcs
= (stats
>> RT2870_REG_TX_STA_FIFO_MCS_SHIFT
) &
5074 RT2870_REG_TX_STA_FIFO_MCS_MASK
;
5075 pid
= (stats
>> RT2870_REG_TX_STA_FIFO_PID_SHIFT
) &
5076 RT2870_REG_TX_STA_FIFO_PID_MASK
;
5077 retrycnt
= pid
- mcs
;
5079 RT2870_DPRINTF(sc
, RT2870_DEBUG_STATS
,
5080 "%s: FIFO statistic: wcid=0x%02x, ok=%d, mcs=0x%02x, pid=0x%02x, retrycnt=%d\n",
5081 device_get_nameunit(sc
->dev
),
5082 wcid
, ok
, mcs
, pid
, retrycnt
);
5084 rt2870_amrr_tx_complete(&sc
->amrr_node
[wcid
], ok
, retrycnt
);
5092 * rt2870_update_raw_counters
5094 static void rt2870_update_raw_counters(struct rt2870_softc
*sc
)
5098 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_TX_AGG_CNT
);
5100 sc
->tx_nonagg
+= tmp
& 0xffff;
5101 sc
->tx_agg
+= tmp
>> 16;
5103 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_TX_AGG_CNT0
);
5105 sc
->tx_ampdu
+= (tmp
& 0xffff) / 1 + (tmp
>> 16) / 2;
5107 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_TX_AGG_CNT1
);
5109 sc
->tx_ampdu
+= (tmp
& 0xffff) / 3 + (tmp
>> 16) / 4;
5111 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_TX_AGG_CNT2
);
5113 sc
->tx_ampdu
+= (tmp
& 0xffff) / 5 + (tmp
>> 16) / 6;
5115 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_TX_AGG_CNT3
);
5117 sc
->tx_ampdu
+= (tmp
& 0xffff) / 7 + (tmp
>> 16) / 8;
5119 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_TX_AGG_CNT4
);
5121 sc
->tx_ampdu
+= (tmp
& 0xffff) / 9 + (tmp
>> 16) / 10;
5123 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_TX_AGG_CNT5
);
5125 sc
->tx_ampdu
+= (tmp
& 0xffff) / 11 + (tmp
>> 16) / 12;
5127 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_TX_AGG_CNT6
);
5129 sc
->tx_ampdu
+= (tmp
& 0xffff) / 13 + (tmp
>> 16) / 14;
5131 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_TX_AGG_CNT7
);
5133 sc
->tx_ampdu
+= (tmp
& 0xffff) / 15 + (tmp
>> 16) / 16;
5135 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_RX_STA_CNT0
);
5137 sc
->rx_crc_errors
+= tmp
& 0xffff;
5138 sc
->rx_phy_errors
+= tmp
>> 16;
5140 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_RX_STA_CNT1
);
5142 sc
->rx_false_ccas
+= tmp
& 0xffff;
5143 sc
->rx_plcp_errors
+= tmp
>> 16;
5145 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_RX_STA_CNT2
);
5147 sc
->rx_dup_packets
+= tmp
& 0xffff;
5148 sc
->rx_fifo_overflows
+= tmp
>> 16;
5152 * rt2870_txrx_enable
5154 static int rt2870_txrx_enable(struct rt2870_softc
*sc
)
5156 struct ieee80211com
*ic
;
5164 /* enable Tx/Rx DMA engine */
5166 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_SCHDMA_USB_CYC_CFG
);
5171 rt2870_io_mac_write(sc
, RT2870_REG_SCHDMA_USB_CYC_CFG
, tmp
);
5173 if ((sc
->mac_rev
& 0xffff) != 0x0101)
5174 rt2870_io_mac_write(sc
, RT2870_REG_TX_TXOP_CTRL_CFG
, 0x583f);
5176 rt2870_io_mac_write(sc
, RT2870_REG_SYS_CTRL
, RT2870_REG_TX_ENABLE
);
5178 for (ntries
= 0; ntries
< 200; ntries
++)
5180 tmp
= rt2870_io_mac_read(sc
, RT2870_REG_SCHDMA_WPDMA_GLO_CFG
);
5181 if (!(tmp
& (RT2870_REG_TX_DMA_BUSY
| RT2870_REG_RX_DMA_BUSY
)))
5189 printf("%s: timeout waiting for DMA engine\n",
5190 device_get_nameunit(sc
->dev
));
5196 rt2870_io_mac_write(sc
, RT2870_REG_SCHDMA_WMM_TXOP0_CFG
, 0);
5197 rt2870_io_mac_write(sc
, RT2870_REG_SCHDMA_WMM_TXOP1_CFG
,
5200 tmp
|= RT2870_REG_TX_WB_DDONE
|
5201 RT2870_REG_RX_DMA_ENABLE
|
5202 RT2870_REG_TX_DMA_ENABLE
;
5204 rt2870_io_mac_write(sc
, RT2870_REG_SCHDMA_WPDMA_GLO_CFG
, tmp
);
5206 tmp
= RT2870_REG_USB_DMA_TX_ENABLE
|
5207 RT2870_REG_USB_DMA_RX_ENABLE
|
5208 RT2870_REG_USB_DMA_RX_AGG_ENABLE
|
5209 /* Rx agg limit in unit of 1024 byte */
5210 ((RT2870_USB_RX_BULK_BUFLEN
/ 1024 - 3) << RT2870_REG_USB_DMA_RX_AGG_LIMIT_SHIFT
) |
5211 /* Rx agg timeout in unit of 33ns */
5214 rt2870_io_mac_write(sc
, RT2870_REG_SCHDMA_USB_DMA_CFG
, tmp
);
5218 tmp
= RT2870_REG_RX_FILTER_DROP_CRC_ERR
|
5219 RT2870_REG_RX_FILTER_DROP_PHY_ERR
;
5221 if (ic
->ic_opmode
!= IEEE80211_M_MONITOR
)
5223 tmp
|= RT2870_REG_RX_FILTER_DROP_DUPL
|
5224 RT2870_REG_RX_FILTER_DROP_CTS
|
5225 RT2870_REG_RX_FILTER_DROP_BA
|
5226 RT2870_REG_RX_FILTER_DROP_ACK
|
5227 RT2870_REG_RX_FILTER_DROP_VER_ERR
|
5228 RT2870_REG_RX_FILTER_DROP_CTRL_RSV
|
5229 RT2870_REG_RX_FILTER_DROP_CFACK
|
5230 RT2870_REG_RX_FILTER_DROP_CFEND
;
5232 if (ic
->ic_opmode
== IEEE80211_M_STA
)
5233 tmp
|= RT2870_REG_RX_FILTER_DROP_RTS
|
5234 RT2870_REG_RX_FILTER_DROP_PSPOLL
;
5236 if (!(ifp
->if_flags
& IFF_PROMISC
))
5237 tmp
|= RT2870_REG_RX_FILTER_DROP_UC_NOME
;
5240 rt2870_io_mac_write(sc
, RT2870_REG_RX_FILTER_CFG
, tmp
);
5242 rt2870_io_mac_write(sc
, RT2870_REG_SYS_CTRL
,
5243 RT2870_REG_RX_ENABLE
| RT2870_REG_TX_ENABLE
);
5249 * rt2870_alloc_rx_ring
5251 static int rt2870_alloc_rx_ring(struct rt2870_softc
*sc
,
5252 struct rt2870_softc_rx_ring
*ring
)
5254 struct rt2870_softc_rx_data
*data
;
5257 STAILQ_INIT(&ring
->inactive
);
5258 STAILQ_INIT(&ring
->active
);
5259 STAILQ_INIT(&ring
->done
);
5261 for (i
= 0; i
< RT2870_SOFTC_RX_RING_DATA_COUNT
; i
++)
5263 data
= &ring
->data
[i
];
5265 data
->buf
= malloc(RT2870_USB_RX_BULK_BUFLEN
, M_USBDEV
, M_NOWAIT
);
5266 if (data
->buf
== NULL
)
5268 printf("%s: could not allocate Rx buffer\n",
5269 device_get_nameunit(sc
->dev
));
5274 STAILQ_INSERT_TAIL(&ring
->inactive
, data
, next
);
5281 rt2870_free_rx_ring(sc
, ring
);
5287 * rt2870_reset_rx_ring
5289 static void rt2870_reset_rx_ring(struct rt2870_softc
*sc
,
5290 struct rt2870_softc_rx_ring
*ring
)
5292 struct rt2870_softc_rx_data
*data
;
5295 STAILQ_INIT(&ring
->inactive
);
5296 STAILQ_INIT(&ring
->active
);
5297 STAILQ_INIT(&ring
->done
);
5299 for (i
= 0; i
< RT2870_SOFTC_RX_RING_DATA_COUNT
; i
++)
5301 data
= &ring
->data
[i
];
5303 STAILQ_INSERT_TAIL(&ring
->inactive
, data
, next
);
5308 * rt2870_free_rx_ring
5310 static void rt2870_free_rx_ring(struct rt2870_softc
*sc
,
5311 struct rt2870_softc_rx_ring
*ring
)
5313 struct rt2870_softc_rx_data
*data
;
5316 for (i
= 0; i
< RT2870_SOFTC_RX_RING_DATA_COUNT
; i
++)
5318 data
= &ring
->data
[i
];
5320 if (data
->buf
!= NULL
)
5322 free(data
->buf
, M_USBDEV
);
5329 * rt2870_alloc_tx_ring
5331 static int rt2870_alloc_tx_ring(struct rt2870_softc
*sc
,
5332 struct rt2870_softc_tx_ring
*ring
, int qid
)
5334 struct rt2870_softc_tx_data
*data
;
5337 STAILQ_INIT(&ring
->inactive
);
5338 STAILQ_INIT(&ring
->pending
);
5339 STAILQ_INIT(&ring
->active
);
5340 STAILQ_INIT(&ring
->done
);
5345 for (i
= 0; i
< RT2870_SOFTC_TX_RING_DATA_COUNT
; i
++)
5347 data
= &ring
->data
[i
];
5349 data
->buf
= malloc(RT2870_TX_DESC_SIZE
+ MJUMPAGESIZE
, M_USBDEV
, M_NOWAIT
);
5350 if (data
->buf
== NULL
)
5352 printf("%s: could not allocate Tx buffer\n",
5353 device_get_nameunit(sc
->dev
));
5358 memset(data
->buf
, 0, RT2870_TX_DESC_SIZE
);
5360 STAILQ_INSERT_TAIL(&ring
->inactive
, data
, next
);
5367 rt2870_free_tx_ring(sc
, ring
);
5373 * rt2870_reset_tx_ring
5375 static void rt2870_reset_tx_ring(struct rt2870_softc
*sc
,
5376 struct rt2870_softc_tx_ring
*ring
)
5378 struct rt2870_softc_tx_data
*data
;
5381 STAILQ_INIT(&ring
->inactive
);
5382 STAILQ_INIT(&ring
->pending
);
5383 STAILQ_INIT(&ring
->active
);
5384 STAILQ_INIT(&ring
->done
);
5388 for (i
= 0; i
< RT2870_SOFTC_TX_RING_DATA_COUNT
; i
++)
5390 data
= &ring
->data
[i
];
5392 if (data
->m
!= NULL
)
5398 if (data
->ni
!= NULL
)
5400 ieee80211_free_node(data
->ni
);
5404 STAILQ_INSERT_TAIL(&ring
->inactive
, data
, next
);
5409 * rt2870_free_tx_ring
5411 static void rt2870_free_tx_ring(struct rt2870_softc
*sc
,
5412 struct rt2870_softc_tx_ring
*ring
)
5414 struct rt2870_softc_tx_data
*data
;
5417 for (i
= 0; i
< RT2870_SOFTC_TX_RING_DATA_COUNT
; i
++)
5419 data
= &ring
->data
[i
];
5421 if (data
->buf
!= NULL
)
5423 free(data
->buf
, M_USBDEV
);
5427 if (data
->m
!= NULL
)
5433 if (data
->ni
!= NULL
)
5435 ieee80211_free_node(data
->ni
);
5442 * rt2870_reset_cmd_ring
5444 static void rt2870_reset_cmd_ring(struct rt2870_softc
*sc
,
5445 struct rt2870_softc_cmd_ring
*ring
)
5447 struct rt2870_softc_cmd
*cmd
;
5450 STAILQ_INIT(&ring
->inactive
);
5451 STAILQ_INIT(&ring
->active
);
5455 for (i
= 0; i
< RT2870_SOFTC_CMD_RING_CMD_COUNT
; i
++)
5457 cmd
= &ring
->cmd
[i
];
5459 STAILQ_INSERT_TAIL(&ring
->inactive
, cmd
, next
);
5464 * rt2870_sysctl_attach
5466 static void rt2870_sysctl_attach(struct rt2870_softc
*sc
)
5468 struct sysctl_ctx_list
*ctx
;
5469 struct sysctl_oid
*tree
;
5470 struct sysctl_oid
*stats
;
5472 ctx
= device_get_sysctl_ctx(sc
->dev
);
5473 tree
= device_get_sysctl_tree(sc
->dev
);
5475 stats
= SYSCTL_ADD_NODE(ctx
, SYSCTL_CHILDREN(tree
), OID_AUTO
,
5476 "stats", CTLFLAG_RD
, 0, "statistic");
5478 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5479 "interrupts", CTLFLAG_RD
, &sc
->interrupts
, 0,
5482 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5483 "rx_interrupts", CTLFLAG_RD
, &sc
->rx_interrupts
, 0,
5486 if (sc
->usb_endpoints
== RT2870_SOFTC_USB_XFER_COUNT
)
5488 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5489 "tx_mgmt_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[5], 0,
5490 "Tx MGMT interrupts");
5492 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5493 "tx_hcca_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[4], 0,
5494 "Tx HCCA interrupts");
5497 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5498 "tx_ac3_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[3], 0,
5499 "Tx AC3 interrupts");
5501 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5502 "tx_ac2_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[2], 0,
5503 "Tx AC2 interrupts");
5505 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5506 "tx_ac1_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[1], 0,
5507 "Tx AC1 interrupts");
5509 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5510 "tx_ac0_interrupts", CTLFLAG_RD
, &sc
->tx_interrupts
[0], 0,
5511 "Tx AC0 interrupts");
5513 if (sc
->usb_endpoints
== RT2870_SOFTC_USB_XFER_COUNT
)
5515 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5516 "tx_mgmt_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[5].queued
, 0,
5517 "Tx MGMT data queued");
5519 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5520 "tx_hcca_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[4].queued
, 0,
5521 "Tx HCCA data queued");
5524 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5525 "tx_ac3_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[3].queued
, 0,
5526 "Tx AC3 data queued");
5528 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5529 "tx_ac2_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[2].queued
, 0,
5530 "Tx AC2 data queued");
5532 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5533 "tx_ac1_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[1].queued
, 0,
5534 "Tx AC1 data queued");
5536 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5537 "tx_ac0_data_queued", CTLFLAG_RD
, &sc
->tx_ring
[0].queued
, 0,
5538 "Tx AC0 data queued");
5540 if (sc
->usb_endpoints
== RT2870_SOFTC_USB_XFER_COUNT
)
5542 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5543 "tx_mgmt_data_queue_full", CTLFLAG_RD
, &sc
->tx_data_queue_full
[5], 0,
5544 "Tx MGMT data queue full");
5546 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5547 "tx_hcca_data_queue_full", CTLFLAG_RD
, &sc
->tx_data_queue_full
[4], 0,
5548 "Tx HCCA data queue full");
5551 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5552 "tx_ac3_data_queue_full", CTLFLAG_RD
, &sc
->tx_data_queue_full
[3], 0,
5553 "Tx AC3 data queue full");
5555 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5556 "tx_ac2_data_queue_full", CTLFLAG_RD
, &sc
->tx_data_queue_full
[2], 0,
5557 "Tx AC2 data queue full");
5559 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5560 "tx_ac1_data_queue_full", CTLFLAG_RD
, &sc
->tx_data_queue_full
[1], 0,
5561 "Tx AC1 data queue full");
5563 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5564 "tx_ac0_data_queue_full", CTLFLAG_RD
, &sc
->tx_data_queue_full
[0], 0,
5565 "Tx AC0 data queue full");
5567 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5568 "tx_watchdog_timeouts", CTLFLAG_RD
, &sc
->tx_watchdog_timeouts
, 0,
5569 "Tx watchdog timeouts");
5571 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5572 "rx_mbuf_alloc_errors", CTLFLAG_RD
, &sc
->rx_mbuf_alloc_errors
, 0,
5573 "Rx mbuf allocation errors");
5575 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5576 "tx_queue_0_not_empty", CTLFLAG_RD
, &sc
->tx_queue_not_empty
[0], 0,
5577 "Tx queue 0 not empty");
5579 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5580 "tx_queue_1_not_empty", CTLFLAG_RD
, &sc
->tx_queue_not_empty
[1], 0,
5581 "Tx queue 1 not empty");
5583 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5584 "tx_beacons", CTLFLAG_RD
, &sc
->tx_beacons
, 0,
5587 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5588 "tx_noretryok", CTLFLAG_RD
, &sc
->tx_noretryok
, 0,
5589 "Tx successfull without retries");
5591 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5592 "tx_retryok", CTLFLAG_RD
, &sc
->tx_retryok
, 0,
5593 "Tx successfull with retries");
5595 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5596 "tx_failed", CTLFLAG_RD
, &sc
->tx_failed
, 0,
5599 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5600 "tx_nonagg", CTLFLAG_RD
, &sc
->tx_nonagg
, 0,
5601 "Tx non-aggregated");
5603 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5604 "tx_agg", CTLFLAG_RD
, &sc
->tx_agg
, 0,
5607 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5608 "tx_ampdu", CTLFLAG_RD
, &sc
->tx_ampdu
, 0,
5611 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5612 "rx_packets", CTLFLAG_RD
, &sc
->rx_packets
, 0,
5615 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5616 "rx_ampdu", CTLFLAG_RD
, &sc
->rx_ampdu
, 0,
5619 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5620 "rx_amsdu", CTLFLAG_RD
, &sc
->rx_amsdu
, 0,
5623 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5624 "rx_crc_errors", CTLFLAG_RD
, &sc
->rx_crc_errors
, 0,
5627 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5628 "rx_phy_errors", CTLFLAG_RD
, &sc
->rx_phy_errors
, 0,
5631 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5632 "rx_false_ccas", CTLFLAG_RD
, &sc
->rx_false_ccas
, 0,
5635 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5636 "rx_plcp_errors", CTLFLAG_RD
, &sc
->rx_plcp_errors
, 0,
5639 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5640 "rx_dup_packets", CTLFLAG_RD
, &sc
->rx_dup_packets
, 0,
5641 "Rx duplicate packets");
5643 SYSCTL_ADD_INT(ctx
, SYSCTL_CHILDREN(stats
), OID_AUTO
,
5644 "rx_fifo_overflows", CTLFLAG_RD
, &sc
->rx_fifo_overflows
, 0,
5645 "Rx FIFO overflows");
5648 static device_method_t rt2870_dev_methods
[] =
5650 DEVMETHOD(device_probe
, rt2870_probe
),
5651 DEVMETHOD(device_attach
, rt2870_attach
),
5652 DEVMETHOD(device_detach
, rt2870_detach
),
5656 static driver_t rt2870_driver
=
5660 sizeof(struct rt2870_softc
),
5663 static devclass_t rt2870_dev_class
;
5665 DRIVER_MODULE(rt2870
, uhub
, rt2870_driver
, rt2870_dev_class
,
5668 MODULE_DEPEND(rt2870
, usb
, 1, 1, 1);
5669 MODULE_DEPEND(rt2870
, wlan
, 1, 1, 1);