Deleted Added
full compact
1/*-
2 * Copyright (c) 2007-2010 Damien Bergamini <damien.bergamini@free.fr>
3 * Copyright (c) 2012 Bernhard Schmidt <bschmidt@FreeBSD.org>
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *

--- 4 unchanged lines hidden (view full) ---

13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 *
17 * $OpenBSD: rt2860.c,v 1.65 2010/10/23 14:24:54 damien Exp $
18 */
19
20#include <sys/cdefs.h>
21__FBSDID("$FreeBSD: head/sys/dev/ral/rt2860.c 286437 2015-08-08 01:10:17Z adrian $");
21__FBSDID("$FreeBSD: head/sys/dev/ral/rt2860.c 287197 2015-08-27 08:56:39Z glebius $");
22
23/*-
24 * Ralink Technology RT2860/RT3090/RT3390/RT3562/RT5390/RT5392 chipset driver
25 * http://www.ralinktech.com/
26 */
27
28#include <sys/param.h>
29#include <sys/sysctl.h>

--- 87 unchanged lines hidden (view full) ---

117static void rt2860_gp_intr(struct rt2860_softc *);
118static int rt2860_tx(struct rt2860_softc *, struct mbuf *,
119 struct ieee80211_node *);
120static int rt2860_raw_xmit(struct ieee80211_node *, struct mbuf *,
121 const struct ieee80211_bpf_params *);
122static int rt2860_tx_raw(struct rt2860_softc *, struct mbuf *,
123 struct ieee80211_node *,
124 const struct ieee80211_bpf_params *params);
125static void rt2860_start(struct ifnet *);
126static void rt2860_start_locked(struct ifnet *);
125static int rt2860_transmit(struct ieee80211com *, struct mbuf *);
126static void rt2860_start(struct rt2860_softc *);
127static void rt2860_watchdog(void *);
128static int rt2860_ioctl(struct ifnet *, u_long, caddr_t);
128static void rt2860_parent(struct ieee80211com *);
129static void rt2860_mcu_bbp_write(struct rt2860_softc *, uint8_t, uint8_t);
130static uint8_t rt2860_mcu_bbp_read(struct rt2860_softc *, uint8_t);
131static void rt2860_rf_write(struct rt2860_softc *, uint8_t, uint32_t);
132static uint8_t rt3090_rf_read(struct rt2860_softc *, uint8_t);
133static void rt3090_rf_write(struct rt2860_softc *, uint8_t, uint8_t);
134static int rt2860_mcu_cmd(struct rt2860_softc *, uint8_t, uint16_t, int);
135static void rt2860_enable_mrr(struct rt2860_softc *);
136static void rt2860_set_txpreamble(struct rt2860_softc *);

--- 14 unchanged lines hidden (view full) ---

151 uint8_t *);
152static void rt3090_rf_setup(struct rt2860_softc *);
153static void rt2860_set_leds(struct rt2860_softc *, uint16_t);
154static void rt2860_set_gp_timer(struct rt2860_softc *, int);
155static void rt2860_set_bssid(struct rt2860_softc *, const uint8_t *);
156static void rt2860_set_macaddr(struct rt2860_softc *, const uint8_t *);
157static void rt2860_update_promisc(struct ieee80211com *);
158static void rt2860_updateslot(struct ieee80211com *);
159static void rt2860_updateprot(struct ifnet *);
159static void rt2860_updateprot(struct rt2860_softc *);
160static int rt2860_updateedca(struct ieee80211com *);
161#ifdef HW_CRYPTO
162static int rt2860_set_key(struct ieee80211com *, struct ieee80211_node *,
163 struct ieee80211_key *);
164static void rt2860_delete_key(struct ieee80211com *,
165 struct ieee80211_node *, struct ieee80211_key *);
166#endif
167static int8_t rt2860_rssi2dbm(struct rt2860_softc *, uint8_t, uint8_t);

--- 57 unchanged lines hidden (view full) ---

225}, rt5392_def_rf[] = {
226 RT5392_DEF_RF
227};
228
229int
230rt2860_attach(device_t dev, int id)
231{
232 struct rt2860_softc *sc = device_get_softc(dev);
233 struct ieee80211com *ic;
234 struct ifnet *ifp;
233 struct ieee80211com *ic = &sc->sc_ic;
234 uint32_t tmp;
235 int error, ntries, qid;
236 uint8_t bands;
238 uint8_t macaddr[IEEE80211_ADDR_LEN];
237
238 sc->sc_dev = dev;
239 sc->sc_debug = 0;
240
243 ifp = sc->sc_ifp = if_alloc(IFT_IEEE80211);
244 if (ifp == NULL) {
245 device_printf(sc->sc_dev, "can not if_alloc()\n");
246 return ENOMEM;
247 }
248 ic = ifp->if_l2com;
249
241 mtx_init(&sc->sc_mtx, device_get_nameunit(dev), MTX_NETWORK_LOCK,
242 MTX_DEF | MTX_RECURSE);
243
244 callout_init_mtx(&sc->watchdog_ch, &sc->sc_mtx, 0);
245 mbufq_init(&sc->sc_snd, ifqmaxlen);
246
247 /* wait for NIC to initialize */
248 for (ntries = 0; ntries < 100; ntries++) {
249 tmp = RAL_READ(sc, RT2860_ASIC_VER_ID);
250 if (tmp != 0 && tmp != 0xffffffff)
251 break;
252 DELAY(10);
253 }

--- 6 unchanged lines hidden (view full) ---

260 sc->mac_ver = tmp >> 16;
261 sc->mac_rev = tmp & 0xffff;
262
263 if (sc->mac_ver != 0x2860 &&
264 (id == 0x0681 || id == 0x0781 || id == 0x1059))
265 sc->sc_flags |= RT2860_ADVANCED_PS;
266
267 /* retrieve RF rev. no and various other things from EEPROM */
276 rt2860_read_eeprom(sc, macaddr);
268 rt2860_read_eeprom(sc, ic->ic_macaddr);
269 device_printf(sc->sc_dev, "MAC/BBP RT%X (rev 0x%04X), "
270 "RF %s (MIMO %dT%dR), address %6D\n",
271 sc->mac_ver, sc->mac_rev, rt2860_get_rf(sc->rf_rev),
280 sc->ntxchains, sc->nrxchains, macaddr, ":");
272 sc->ntxchains, sc->nrxchains, ic->ic_macaddr, ":");
273
274 /*
275 * Allocate Tx (4 EDCAs + HCCA + Mgt) and Rx rings.
276 */
277 for (qid = 0; qid < 6; qid++) {
278 if ((error = rt2860_alloc_tx_ring(sc, &sc->txq[qid])) != 0) {
279 device_printf(sc->sc_dev,
280 "could not allocate Tx ring %d\n", qid);

--- 10 unchanged lines hidden (view full) ---

291 device_printf(sc->sc_dev, "could not allocate Tx pool\n");
292 goto fail3;
293 }
294
295 /* mgmt ring is broken on RT2860C, use EDCA AC VO ring instead */
296 sc->mgtqid = (sc->mac_ver == 0x2860 && sc->mac_rev == 0x0100) ?
297 WME_AC_VO : 5;
298
307 ifp->if_softc = sc;
308 if_initname(ifp, device_get_name(dev), device_get_unit(dev));
309 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
310 ifp->if_init = rt2860_init;
311 ifp->if_ioctl = rt2860_ioctl;
312 ifp->if_start = rt2860_start;
313 IFQ_SET_MAXLEN(&ifp->if_snd, ifqmaxlen);
314 ifp->if_snd.ifq_drv_maxlen = ifqmaxlen;
315 IFQ_SET_READY(&ifp->if_snd);
316
317 ic->ic_ifp = ifp;
299 ic->ic_softc = sc;
300 ic->ic_name = device_get_nameunit(dev);
301 ic->ic_opmode = IEEE80211_M_STA;
302 ic->ic_phytype = IEEE80211_T_OFDM; /* not only, but not used */
303
304 /* set device capabilities */
305 ic->ic_caps =
306 IEEE80211_C_STA /* station mode */

--- 14 unchanged lines hidden (view full) ---

321
322 bands = 0;
323 setbit(&bands, IEEE80211_MODE_11B);
324 setbit(&bands, IEEE80211_MODE_11G);
325 if (sc->rf_rev == RT2860_RF_2750 || sc->rf_rev == RT2860_RF_2850)
326 setbit(&bands, IEEE80211_MODE_11A);
327 ieee80211_init_channels(ic, NULL, &bands);
328
348 ieee80211_ifattach(ic, macaddr);
329 ieee80211_ifattach(ic);
330
331 ic->ic_wme.wme_update = rt2860_updateedca;
332 ic->ic_scan_start = rt2860_scan_start;
333 ic->ic_scan_end = rt2860_scan_end;
334 ic->ic_set_channel = rt2860_set_channel;
335 ic->ic_updateslot = rt2860_updateslot;
336 ic->ic_update_promisc = rt2860_update_promisc;
337 ic->ic_raw_xmit = rt2860_raw_xmit;
338 sc->sc_node_free = ic->ic_node_free;
339 ic->ic_node_free = rt2860_node_free;
340 ic->ic_newassoc = rt2860_newassoc;
360
341 ic->ic_transmit = rt2860_transmit;
342 ic->ic_parent = rt2860_parent;
343 ic->ic_vap_create = rt2860_vap_create;
344 ic->ic_vap_delete = rt2860_vap_delete;
345
346 ieee80211_radiotap_attach(ic,
347 &sc->sc_txtap.wt_ihdr, sizeof(sc->sc_txtap),
348 RT2860_TX_RADIOTAP_PRESENT,
349 &sc->sc_rxtap.wr_ihdr, sizeof(sc->sc_rxtap),
350 RT2860_RX_RADIOTAP_PRESENT);

--- 7 unchanged lines hidden (view full) ---

358 ieee80211_announce(ic);
359
360 return 0;
361
362fail3: rt2860_free_rx_ring(sc, &sc->rxq);
363fail2: while (--qid >= 0)
364 rt2860_free_tx_ring(sc, &sc->txq[qid]);
365fail1: mtx_destroy(&sc->sc_mtx);
384 if_free(ifp);
366 return error;
367}
368
369int
370rt2860_detach(void *xsc)
371{
372 struct rt2860_softc *sc = xsc;
392 struct ifnet *ifp = sc->sc_ifp;
393 struct ieee80211com *ic = ifp->if_l2com;
373 struct ieee80211com *ic = &sc->sc_ic;
374 int qid;
375
376 RAL_LOCK(sc);
377 rt2860_stop_locked(sc);
378 RAL_UNLOCK(sc);
379
380 ieee80211_ifdetach(ic);
401
381 mbufq_drain(&sc->sc_snd);
382 for (qid = 0; qid < 6; qid++)
383 rt2860_free_tx_ring(sc, &sc->txq[qid]);
384 rt2860_free_rx_ring(sc, &sc->rxq);
385 rt2860_free_tx_pool(sc);
386
407 if_free(ifp);
408
387 mtx_destroy(&sc->sc_mtx);
388
389 return 0;
390}
391
392void
393rt2860_shutdown(void *xsc)
394{

--- 9 unchanged lines hidden (view full) ---

404
405 rt2860_stop(sc);
406}
407
408void
409rt2860_resume(void *xsc)
410{
411 struct rt2860_softc *sc = xsc;
434 struct ifnet *ifp = sc->sc_ifp;
412
436 if (ifp->if_flags & IFF_UP)
413 if (sc->sc_ic.ic_nrunning > 0)
414 rt2860_init(sc);
415}
416
417static struct ieee80211vap *
418rt2860_vap_create(struct ieee80211com *ic, const char name[IFNAMSIZ], int unit,
419 enum ieee80211_opmode opmode, int flags,
420 const uint8_t bssid[IEEE80211_ADDR_LEN],
421 const uint8_t mac[IEEE80211_ADDR_LEN])
422{
446 struct ifnet *ifp = ic->ic_ifp;
423 struct rt2860_softc *sc = ic->ic_softc;
424 struct rt2860_vap *rvp;
425 struct ieee80211vap *vap;
426
427 switch (opmode) {
428 case IEEE80211_M_STA:
429 case IEEE80211_M_IBSS:
430 case IEEE80211_M_AHDEMO:
431 case IEEE80211_M_MONITOR:
432 case IEEE80211_M_HOSTAP:
433 case IEEE80211_M_MBSS:
434 /* XXXRP: TBD */
435 if (!TAILQ_EMPTY(&ic->ic_vaps)) {
459 if_printf(ifp, "only 1 vap supported\n");
436 device_printf(sc->sc_dev, "only 1 vap supported\n");
437 return NULL;
438 }
439 if (opmode == IEEE80211_M_STA)
440 flags |= IEEE80211_CLONE_NOBEACONS;
441 break;
442 case IEEE80211_M_WDS:
443 if (TAILQ_EMPTY(&ic->ic_vaps) ||
444 ic->ic_opmode != IEEE80211_M_HOSTAP) {
468 if_printf(ifp, "wds only supported in ap mode\n");
445 device_printf(sc->sc_dev,
446 "wds only supported in ap mode\n");
447 return NULL;
448 }
449 /*
450 * Silently remove any request for a unique
451 * bssid; WDS vap's always share the local
452 * mac address.
453 */
454 flags &= ~IEEE80211_CLONE_BSSID;
455 break;
456 default:
479 if_printf(ifp, "unknown opmode %d\n", opmode);
457 device_printf(sc->sc_dev, "unknown opmode %d\n", opmode);
458 return NULL;
459 }
482 rvp = malloc(sizeof(struct rt2860_vap), M_80211_VAP, M_NOWAIT | M_ZERO);
483 if (rvp == NULL)
484 return NULL;
460 rvp = malloc(sizeof(struct rt2860_vap), M_80211_VAP, M_WAITOK | M_ZERO);
461 vap = &rvp->ral_vap;
486 ieee80211_vap_setup(ic, vap, name, unit, opmode, flags, bssid, mac);
462 ieee80211_vap_setup(ic, vap, name, unit, opmode, flags, bssid);
463
464 /* override state transition machine */
465 rvp->ral_newstate = vap->iv_newstate;
466 vap->iv_newstate = rt2860_newstate;
467#if 0
468 vap->iv_update_beacon = rt2860_beacon_update;
469#endif
470
471 /* HW supports up to 255 STAs (0-254) in HostAP and IBSS modes */
472 vap->iv_max_aid = min(IEEE80211_AID_MAX, RT2860_WCID_MAX);
473
474 ieee80211_ratectl_init(vap);
475 /* complete setup */
500 ieee80211_vap_attach(vap, ieee80211_media_change, ieee80211_media_status);
476 ieee80211_vap_attach(vap, ieee80211_media_change,
477 ieee80211_media_status, mac);
478 if (TAILQ_FIRST(&ic->ic_vaps) == vap)
479 ic->ic_opmode = opmode;
480 return vap;
481}
482
483static void
484rt2860_vap_delete(struct ieee80211vap *vap)
485{

--- 315 unchanged lines hidden (view full) ---

801 }
802 if (ring->data_dmat != NULL)
803 bus_dma_tag_destroy(ring->data_dmat);
804}
805
806static void
807rt2860_updatestats(struct rt2860_softc *sc)
808{
832 struct ieee80211com *ic = sc->sc_ifp->if_l2com;
809 struct ieee80211com *ic = &sc->sc_ic;
810
811 /*
812 * In IBSS or HostAP modes (when the hardware sends beacons), the
813 * MAC can run into a livelock and start sending CTS-to-self frames
814 * like crazy if protection is enabled. Fortunately, we can detect
815 * when such a situation occurs and reset the MAC.
816 */
817 if (ic->ic_curmode != IEEE80211_M_STA) {

--- 10 unchanged lines hidden (view full) ---

828 }
829 }
830}
831
832static void
833rt2860_newassoc(struct ieee80211_node *ni, int isnew)
834{
835 struct ieee80211com *ic = ni->ni_ic;
859 struct rt2860_softc *sc = ic->ic_ifp->if_softc;
836 struct rt2860_softc *sc = ic->ic_softc;
837 uint8_t wcid;
838
839 wcid = IEEE80211_AID(ni->ni_associd);
840 if (isnew && ni->ni_associd != 0) {
841 sc->wcid2ni[wcid] = ni;
842
843 /* init WCID table entry */
844 RAL_WRITE_REGION_1(sc, RT2860_WCID_ENTRY(wcid),
845 ni->ni_macaddr, IEEE80211_ADDR_LEN);
846 }
847 DPRINTF(("new assoc isnew=%d addr=%s WCID=%d\n",
848 isnew, ether_sprintf(ni->ni_macaddr), wcid));
849}
850
851static void
852rt2860_node_free(struct ieee80211_node *ni)
853{
854 struct ieee80211com *ic = ni->ni_ic;
878 struct rt2860_softc *sc = ic->ic_ifp->if_softc;
855 struct rt2860_softc *sc = ic->ic_softc;
856 uint8_t wcid;
857
858 if (ni->ni_associd != 0) {
859 wcid = IEEE80211_AID(ni->ni_associd);
860
861 /* clear Rx WCID search table entry */
862 RAL_SET_REGION_4(sc, RT2860_WCID_ENTRY(wcid), 0, 2);
863 }

--- 31 unchanged lines hidden (view full) ---

895}
896#endif
897
898int
899rt2860_newstate(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg)
900{
901 struct rt2860_vap *rvp = RT2860_VAP(vap);
902 struct ieee80211com *ic = vap->iv_ic;
926 struct rt2860_softc *sc = ic->ic_ifp->if_softc;
903 struct rt2860_softc *sc = ic->ic_softc;
904 uint32_t tmp;
905 int error;
906
907 if (vap->iv_state == IEEE80211_S_RUN) {
908 /* turn link LED off */
909 rt2860_set_leds(sc, RT2860_LED_RADIO);
910 }
911

--- 161 unchanged lines hidden (view full) ---

1073 RAL_WRITE(sc, RT2860_WPDMA_GLO_CFG, tmp);
1074
1075 (void)rt2860_txrx_enable(sc);
1076}
1077
1078static void
1079rt2860_drain_stats_fifo(struct rt2860_softc *sc)
1080{
1104 struct ifnet *ifp = sc->sc_ifp;
1081 struct ieee80211_node *ni;
1082 uint32_t stat;
1083 int retrycnt;
1084 uint8_t wcid, mcs, pid;
1085
1086 /* drain Tx status FIFO (maxsize = 16) */
1087 while ((stat = RAL_READ(sc, RT2860_TX_STAT_FIFO)) & RT2860_TXQ_VLD) {
1088 DPRINTFN(4, ("tx stat 0x%08x\n", stat));

--- 19 unchanged lines hidden (view full) ---

1108 retrycnt = 1;
1109 else
1110 retrycnt = 0;
1111 ieee80211_ratectl_tx_complete(ni->ni_vap, ni,
1112 IEEE80211_RATECTL_TX_SUCCESS, &retrycnt, NULL);
1113 } else {
1114 ieee80211_ratectl_tx_complete(ni->ni_vap, ni,
1115 IEEE80211_RATECTL_TX_FAILURE, &retrycnt, NULL);
1140 if_inc_counter(ifp, IFCOUNTER_OERRORS, 1);
1116 if_inc_counter(ni->ni_vap->iv_ifp,
1117 IFCOUNTER_OERRORS, 1);
1118 }
1119 }
1120}
1121
1122static void
1123rt2860_tx_intr(struct rt2860_softc *sc, int qid)
1124{
1148 struct ifnet *ifp = sc->sc_ifp;
1125 struct rt2860_tx_ring *ring = &sc->txq[qid];
1126 uint32_t hw;
1127
1128 rt2860_drain_stats_fifo(sc);
1129
1130 hw = RAL_READ(sc, RT2860_TX_DTX_IDX(qid));
1131 while (ring->next != hw) {
1132 struct rt2860_tx_data *data = ring->data[ring->next];
1133
1134 if (data != NULL) {
1135 bus_dmamap_sync(sc->txwi_dmat, data->map,
1136 BUS_DMASYNC_POSTWRITE);
1137 bus_dmamap_unload(sc->txwi_dmat, data->map);
1138 if (data->m->m_flags & M_TXCB) {
1139 ieee80211_process_callback(data->ni, data->m,
1140 0);
1141 }
1166 m_freem(data->m);
1167 ieee80211_free_node(data->ni);
1168 data->m = NULL;
1142 ieee80211_tx_complete(data->ni, data->m, 0);
1143 data->ni = NULL;
1170
1144 data->m = NULL;
1145 SLIST_INSERT_HEAD(&sc->data_pool, data, next);
1146 ring->data[ring->next] = NULL;
1173
1174 if_inc_counter(ifp, IFCOUNTER_OPACKETS, 1);
1147 }
1148 ring->queued--;
1149 ring->next = (ring->next + 1) % RT2860_TX_RING_COUNT;
1150 }
1151
1152 sc->sc_tx_timer = 0;
1153 if (ring->queued < RT2860_TX_RING_COUNT)
1154 sc->qfullmsk &= ~(1 << qid);
1183 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
1184 rt2860_start_locked(ifp);
1155 rt2860_start(sc);
1156}
1157
1158/*
1159 * Return the Rx chain with the highest RSSI for a given frame.
1160 */
1161static __inline uint8_t
1162rt2860_maxrssi_chain(struct rt2860_softc *sc, const struct rt2860_rxwi *rxwi)
1163{

--- 8 unchanged lines hidden (view full) ---

1172 }
1173 return rxchain;
1174}
1175
1176static void
1177rt2860_rx_intr(struct rt2860_softc *sc)
1178{
1179 struct rt2860_rx_radiotap_header *tap;
1209 struct ifnet *ifp = sc->sc_ifp;
1210 struct ieee80211com *ic = ifp->if_l2com;
1180 struct ieee80211com *ic = &sc->sc_ic;
1181 struct ieee80211_frame *wh;
1182 struct ieee80211_node *ni;
1183 struct mbuf *m, *m1;
1184 bus_addr_t physaddr;
1185 uint32_t hw;
1186 uint16_t phy;
1187 uint8_t ant;
1188 int8_t rssi, nf;

--- 10 unchanged lines hidden (view full) ---

1199
1200 if (__predict_false(!(rxd->sdl0 & htole16(RT2860_RX_DDONE)))) {
1201 DPRINTF(("RXD DDONE bit not set!\n"));
1202 break; /* should not happen */
1203 }
1204
1205 if (__predict_false(rxd->flags &
1206 htole32(RT2860_RX_CRCERR | RT2860_RX_ICVERR))) {
1237 if_inc_counter(ifp, IFCOUNTER_IERRORS, 1);
1207 counter_u64_add(ic->ic_ierrors, 1);
1208 goto skip;
1209 }
1210
1211#ifdef HW_CRYPTO
1212 if (__predict_false(rxd->flags & htole32(RT2860_RX_MICERR))) {
1213 /* report MIC failures to net80211 for TKIP */
1214 ic->ic_stats.is_rx_locmicfail++;
1215 ieee80211_michael_mic_failure(ic, 0/* XXX */);
1246 if_inc_counter(ifp, IFCOUNTER_IERRORS, 1);
1216 counter_u64_add(ic->ic_ierrors, 1);
1217 goto skip;
1218 }
1219#endif
1220
1221 m1 = m_getcl(M_NOWAIT, MT_DATA, M_PKTHDR);
1222 if (__predict_false(m1 == NULL)) {
1253 if_inc_counter(ifp, IFCOUNTER_IERRORS, 1);
1223 counter_u64_add(ic->ic_ierrors, 1);
1224 goto skip;
1225 }
1226
1227 bus_dmamap_sync(sc->rxq.data_dmat, data->map,
1228 BUS_DMASYNC_POSTREAD);
1229 bus_dmamap_unload(sc->rxq.data_dmat, data->map);
1230
1231 error = bus_dmamap_load(sc->rxq.data_dmat, data->map,

--- 7 unchanged lines hidden (view full) ---

1239 mtod(data->m, void *), MCLBYTES,
1240 rt2860_dma_map_addr, &physaddr, 0);
1241 if (__predict_false(error != 0)) {
1242 panic("%s: could not load old rx mbuf",
1243 device_get_name(sc->sc_dev));
1244 }
1245 /* physical address may have changed */
1246 rxd->sdp0 = htole32(physaddr);
1277 if_inc_counter(ifp, IFCOUNTER_IERRORS, 1);
1247 counter_u64_add(ic->ic_ierrors, 1);
1248 goto skip;
1249 }
1250
1251 /*
1252 * New mbuf successfully loaded, update Rx ring and continue
1253 * processing.
1254 */
1255 m = data->m;
1256 data->m = m1;
1257 rxd->sdp0 = htole32(physaddr);
1258
1259 rxwi = mtod(m, struct rt2860_rxwi *);
1260
1261 /* finalize mbuf */
1292 m->m_pkthdr.rcvif = ifp;
1262 m->m_data = (caddr_t)(rxwi + 1);
1263 m->m_pkthdr.len = m->m_len = le16toh(rxwi->len) & 0xfff;
1264
1265 wh = mtod(m, struct ieee80211_frame *);
1266#ifdef HW_CRYPTO
1267 if (wh->i_fc[1] & IEEE80211_FC1_PROTECTED) {
1268 /* frame is decrypted by hardware */
1269 wh->i_fc[1] &= ~IEEE80211_FC1_PROTECTED;

--- 93 unchanged lines hidden (view full) ---

1363
1364 /* flush buffered multicast frames */
1365 if (ic->ic_dtim_count == 0)
1366 ieee80211_notify_dtim(ic);
1367 }
1368#endif
1369 /* check if protection mode has changed */
1370 if ((sc->sc_ic_flags ^ ic->ic_flags) & IEEE80211_F_USEPROT) {
1402 rt2860_updateprot(ic);
1371 rt2860_updateprot(sc);
1372 sc->sc_ic_flags = ic->ic_flags;
1373 }
1374#endif
1375}
1376
1377static void
1378rt2860_gp_intr(struct rt2860_softc *sc)
1379{
1411 struct ieee80211com *ic = sc->sc_ifp->if_l2com;
1380 struct ieee80211com *ic = &sc->sc_ic;
1381 struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps);
1382
1383 DPRINTFN(2, ("GP timeout state=%d\n", vap->iv_state));
1384
1385 if (vap->iv_state == IEEE80211_S_RUN)
1386 rt2860_updatestats(sc);
1387}
1388

--- 55 unchanged lines hidden (view full) ---

1444 rt2860_gp_intr(sc);
1445
1446 RAL_UNLOCK(sc);
1447}
1448
1449static int
1450rt2860_tx(struct rt2860_softc *sc, struct mbuf *m, struct ieee80211_node *ni)
1451{
1483 struct ifnet *ifp = sc->sc_ifp;
1484 struct ieee80211com *ic = ifp->if_l2com;
1452 struct ieee80211com *ic = &sc->sc_ic;
1453 struct ieee80211vap *vap = ni->ni_vap;
1454 struct rt2860_tx_ring *ring;
1455 struct rt2860_tx_data *data;
1456 struct rt2860_txd *txd;
1457 struct rt2860_txwi *txwi;
1458 struct ieee80211_frame *wh;
1459 const struct ieee80211_txparam *tp;
1460 struct ieee80211_key *k;

--- 227 unchanged lines hidden (view full) ---

1688 return 0;
1689}
1690
1691static int
1692rt2860_raw_xmit(struct ieee80211_node *ni, struct mbuf *m,
1693 const struct ieee80211_bpf_params *params)
1694{
1695 struct ieee80211com *ic = ni->ni_ic;
1728 struct ifnet *ifp = ic->ic_ifp;
1729 struct rt2860_softc *sc = ifp->if_softc;
1696 struct rt2860_softc *sc = ic->ic_softc;
1697 int error;
1698
1699 RAL_LOCK(sc);
1700
1701 /* prevent management frames from being sent if we're not ready */
1735 if (!(ifp->if_drv_flags & IFF_DRV_RUNNING)) {
1702 if (!(sc->sc_flags & RT2860_RUNNNING)) {
1703 RAL_UNLOCK(sc);
1704 m_freem(m);
1705 ieee80211_free_node(ni);
1706 return ENETDOWN;
1707 }
1708 if (params == NULL) {
1709 /*
1710 * Legacy path; interpret frame contents to decide

--- 5 unchanged lines hidden (view full) ---

1716 * Caller supplied explicit parameters to use in
1717 * sending the frame.
1718 */
1719 error = rt2860_tx_raw(sc, m, ni, params);
1720 }
1721 if (error != 0) {
1722 /* NB: m is reclaimed on tx failure */
1723 ieee80211_free_node(ni);
1757 if_inc_counter(ifp, IFCOUNTER_OERRORS, 1);
1724 }
1725 sc->sc_tx_timer = 5;
1726 RAL_UNLOCK(sc);
1727 return error;
1728}
1729
1730static int
1731rt2860_tx_raw(struct rt2860_softc *sc, struct mbuf *m,
1732 struct ieee80211_node *ni, const struct ieee80211_bpf_params *params)
1733{
1768 struct ifnet *ifp = sc->sc_ifp;
1769 struct ieee80211com *ic = ifp->if_l2com;
1734 struct ieee80211com *ic = &sc->sc_ic;
1735 struct ieee80211vap *vap = ni->ni_vap;
1736 struct rt2860_tx_ring *ring;
1737 struct rt2860_tx_data *data;
1738 struct rt2860_txd *txd;
1739 struct rt2860_txwi *txwi;
1740 struct ieee80211_frame *wh;
1741 struct mbuf *m1;
1742 bus_dma_segment_t segs[RT2860_MAX_SCATTER];

--- 190 unchanged lines hidden (view full) ---

1933 sc->qfullmsk |= 1 << qid;
1934
1935 /* kick Tx */
1936 RAL_WRITE(sc, RT2860_TX_CTX_IDX(qid), ring->cur);
1937
1938 return 0;
1939}
1940
1976static void
1977rt2860_start(struct ifnet *ifp)
1941static int
1942rt2860_transmit(struct ieee80211com *ic, struct mbuf *m)
1943{
1979 struct rt2860_softc *sc = ifp->if_softc;
1944 struct rt2860_softc *sc = ic->ic_softc;
1945 int error;
1946
1947 RAL_LOCK(sc);
1982 rt2860_start_locked(ifp);
1948 if ((sc->sc_flags & RT2860_RUNNNING) == 0) {
1949 RAL_UNLOCK(sc);
1950 return (ENXIO);
1951 }
1952 error = mbufq_enqueue(&sc->sc_snd, m);
1953 if (error) {
1954 RAL_UNLOCK(sc);
1955 return (error);
1956 }
1957 rt2860_start(sc);
1958 RAL_UNLOCK(sc);
1959
1960 return (0);
1961}
1962
1963static void
1987rt2860_start_locked(struct ifnet *ifp)
1964rt2860_start(struct rt2860_softc *sc)
1965{
1989 struct rt2860_softc *sc = ifp->if_softc;
1966 struct ieee80211_node *ni;
1967 struct mbuf *m;
1968
1969 RAL_LOCK_ASSERT(sc);
1970
1995 if ((ifp->if_drv_flags & IFF_DRV_RUNNING) == 0 ||
1996 (ifp->if_drv_flags & IFF_DRV_OACTIVE))
1971 if ((sc->sc_flags & RT2860_RUNNNING) == 0)
1972 return;
1973
1999 for (;;) {
2000 if (SLIST_EMPTY(&sc->data_pool) || sc->qfullmsk != 0) {
2001 ifp->if_drv_flags |= IFF_DRV_OACTIVE;
2002 break;
2003 }
2004 IFQ_DRV_DEQUEUE(&ifp->if_snd, m);
2005 if (m == NULL)
2006 break;
1974 while (!SLIST_EMPTY(&sc->data_pool) && sc->qfullmsk == 0 &&
1975 (m = mbufq_dequeue(&sc->sc_snd)) != NULL) {
1976 ni = (struct ieee80211_node *)m->m_pkthdr.rcvif;
1977 if (rt2860_tx(sc, m, ni) != 0) {
1978 if_inc_counter(ni->ni_vap->iv_ifp,
1979 IFCOUNTER_OERRORS, 1);
1980 ieee80211_free_node(ni);
2010 if_inc_counter(ifp, IFCOUNTER_OERRORS, 1);
1981 continue;
1982 }
1983 sc->sc_tx_timer = 5;
1984 }
1985}
1986
1987static void
1988rt2860_watchdog(void *arg)
1989{
1990 struct rt2860_softc *sc = arg;
2021 struct ifnet *ifp = sc->sc_ifp;
1991
1992 RAL_LOCK_ASSERT(sc);
1993
2025 KASSERT(ifp->if_drv_flags & IFF_DRV_RUNNING, ("not running"));
1994 KASSERT(sc->sc_flags & RT2860_RUNNNING, ("not running"));
1995
1996 if (sc->sc_invalid) /* card ejected */
1997 return;
1998
1999 if (sc->sc_tx_timer > 0 && --sc->sc_tx_timer == 0) {
2031 if_printf(ifp, "device timeout\n");
2000 device_printf(sc->sc_dev, "device timeout\n");
2001 rt2860_stop_locked(sc);
2002 rt2860_init_locked(sc);
2034 if_inc_counter(ifp, IFCOUNTER_OERRORS, 1);
2003 counter_u64_add(sc->sc_ic.ic_oerrors, 1);
2004 return;
2005 }
2006 callout_reset(&sc->watchdog_ch, hz, rt2860_watchdog, sc);
2007}
2008
2040static int
2041rt2860_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
2009static void
2010rt2860_parent(struct ieee80211com *ic)
2011{
2043 struct rt2860_softc *sc = ifp->if_softc;
2044 struct ieee80211com *ic = ifp->if_l2com;
2045 struct ifreq *ifr = (struct ifreq *)data;
2046 int error = 0, startall = 0;
2012 struct rt2860_softc *sc = ic->ic_softc;
2013 int startall = 0;
2014
2048 switch (cmd) {
2049 case SIOCSIFFLAGS:
2050 RAL_LOCK(sc);
2051 if (ifp->if_flags & IFF_UP) {
2052 if (!(ifp->if_drv_flags & IFF_DRV_RUNNING)) {
2053 rt2860_init_locked(sc);
2054 startall = 1;
2055 } else
2056 rt2860_update_promisc(ic);
2057 } else {
2058 if (ifp->if_drv_flags & IFF_DRV_RUNNING)
2059 rt2860_stop_locked(sc);
2060 }
2061 RAL_UNLOCK(sc);
2062 if (startall)
2063 ieee80211_start_all(ic);
2064 break;
2065 case SIOCGIFMEDIA:
2066 error = ifmedia_ioctl(ifp, ifr, &ic->ic_media, cmd);
2067 break;
2068 case SIOCSIFADDR:
2069 error = ether_ioctl(ifp, cmd, data);
2070 break;
2071 default:
2072 error = EINVAL;
2073 break;
2074 }
2075 return error;
2015 RAL_LOCK(sc);
2016 if (ic->ic_nrunning> 0) {
2017 if (!(sc->sc_flags & RT2860_RUNNNING)) {
2018 rt2860_init_locked(sc);
2019 startall = 1;
2020 } else
2021 rt2860_update_promisc(ic);
2022 } else if (sc->sc_flags & RT2860_RUNNNING)
2023 rt2860_stop_locked(sc);
2024 RAL_UNLOCK(sc);
2025 if (startall)
2026 ieee80211_start_all(ic);
2027}
2028
2029/*
2030 * Reading and writing from/to the BBP is different from RT2560 and RT2661.
2031 * We access the BBP through the 8051 microcontroller unit which means that
2032 * the microcode must be loaded first.
2033 */
2034void

--- 206 unchanged lines hidden (view full) ---

2241 CCK(0)); /* 1-> 1 */
2242#undef OFDM
2243#undef CCK
2244}
2245
2246static void
2247rt2860_set_txpreamble(struct rt2860_softc *sc)
2248{
2298 struct ifnet *ifp = sc->sc_ifp;
2299 struct ieee80211com *ic = ifp->if_l2com;
2249 struct ieee80211com *ic = &sc->sc_ic;
2250 uint32_t tmp;
2251
2252 tmp = RAL_READ(sc, RT2860_AUTO_RSP_CFG);
2253 tmp &= ~RT2860_CCK_SHORT_EN;
2254 if (ic->ic_flags & IEEE80211_F_SHPREAMBLE)
2255 tmp |= RT2860_CCK_SHORT_EN;
2256 RAL_WRITE(sc, RT2860_AUTO_RSP_CFG, tmp);
2257}
2258
2259void
2260rt2860_set_basicrates(struct rt2860_softc *sc,
2261 const struct ieee80211_rateset *rs)
2262{
2263#define RV(r) ((r) & IEEE80211_RATE_VAL)
2314 struct ifnet *ifp = sc->sc_ifp;
2315 struct ieee80211com *ic = ifp->if_l2com;
2264 struct ieee80211com *ic = &sc->sc_ic;
2265 uint32_t mask = 0;
2266 uint8_t rate;
2267 int i;
2268
2269 for (i = 0; i < rs->rs_nrates; i++) {
2270 rate = rs->rs_rates[i];
2271
2272 if (!(rate & IEEE80211_RATE_BASIC))

--- 4 unchanged lines hidden (view full) ---

2277
2278 RAL_WRITE(sc, RT2860_LEGACY_BASIC_RATE, mask);
2279#undef RV
2280}
2281
2282static void
2283rt2860_scan_start(struct ieee80211com *ic)
2284{
2336 struct ifnet *ifp = ic->ic_ifp;
2337 struct rt2860_softc *sc = ifp->if_softc;
2285 struct rt2860_softc *sc = ic->ic_softc;
2286 uint32_t tmp;
2287
2288 tmp = RAL_READ(sc, RT2860_BCN_TIME_CFG);
2289 RAL_WRITE(sc, RT2860_BCN_TIME_CFG,
2290 tmp & ~(RT2860_BCN_TX_EN | RT2860_TSF_TIMER_EN |
2291 RT2860_TBTT_TIMER_EN));
2292 rt2860_set_gp_timer(sc, 0);
2293}
2294
2295static void
2296rt2860_scan_end(struct ieee80211com *ic)
2297{
2350 struct ifnet *ifp = ic->ic_ifp;
2351 struct rt2860_softc *sc = ifp->if_softc;
2298 struct rt2860_softc *sc = ic->ic_softc;
2299 struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps);
2300
2301 if (vap->iv_state == IEEE80211_S_RUN) {
2302 rt2860_enable_tsf_sync(sc);
2303 rt2860_set_gp_timer(sc, 500);
2304 }
2305}
2306
2307static void
2308rt2860_set_channel(struct ieee80211com *ic)
2309{
2363 struct ifnet *ifp = ic->ic_ifp;
2364 struct rt2860_softc *sc = ifp->if_softc;
2310 struct rt2860_softc *sc = ic->ic_softc;
2311
2312 RAL_LOCK(sc);
2313 rt2860_switch_chan(sc, ic->ic_curchan);
2314 RAL_UNLOCK(sc);
2315}
2316
2317static void
2318rt2860_select_chan_group(struct rt2860_softc *sc, int group)

--- 735 unchanged lines hidden (view full) ---

3054
3055 tmp = RAL_READ(sc, RT2860_BKOFF_SLOT_CFG);
3056 tmp &= ~0xff;
3057 tmp |= (ic->ic_flags & IEEE80211_F_SHSLOT) ? 9 : 20;
3058 RAL_WRITE(sc, RT2860_BKOFF_SLOT_CFG, tmp);
3059}
3060
3061static void
3116rt2860_updateprot(struct ifnet *ifp)
3062rt2860_updateprot(struct rt2860_softc *sc)
3063{
3118 struct rt2860_softc *sc = ifp->if_softc;
3119 struct ieee80211com *ic = ifp->if_l2com;
3064 struct ieee80211com *ic = &sc->sc_ic;
3065 uint32_t tmp;
3066
3067 tmp = RT2860_RTSTH_EN | RT2860_PROT_NAV_SHORT | RT2860_TXOP_ALLOW_ALL;
3068 /* setup protection frame rate (MCS code) */
3069 tmp |= IEEE80211_IS_CHAN_5GHZ(ic->ic_curchan) ?
3070 rt2860_rates[RT2860_RIDX_OFDM6].mcs :
3071 rt2860_rates[RT2860_RIDX_CCK11].mcs;
3072

--- 12 unchanged lines hidden (view full) ---

3085static void
3086rt2860_update_promisc(struct ieee80211com *ic)
3087{
3088 struct rt2860_softc *sc = ic->ic_softc;
3089 uint32_t tmp;
3090
3091 tmp = RAL_READ(sc, RT2860_RX_FILTR_CFG);
3092 tmp &= ~RT2860_DROP_NOT_MYBSS;
3148 if (!(ic->ic_ifp->if_flags & IFF_PROMISC))
3093 if (ic->ic_promisc == 0)
3094 tmp |= RT2860_DROP_NOT_MYBSS;
3095 RAL_WRITE(sc, RT2860_RX_FILTR_CFG, tmp);
3096}
3097
3098static int
3099rt2860_updateedca(struct ieee80211com *ic)
3100{
3156 struct rt2860_softc *sc = ic->ic_ifp->if_softc;
3101 struct rt2860_softc *sc = ic->ic_softc;
3102 const struct wmeParams *wmep;
3103 int aci;
3104
3105 wmep = ic->ic_wme.wme_chanParams.cap_wmeParams;
3106
3107 /* update MAC TX configuration registers */
3108 for (aci = 0; aci < WME_NUM_AC; aci++) {
3109 RAL_WRITE(sc, RT2860_EDCA_AC_CFG(aci),

--- 155 unchanged lines hidden (view full) ---

3265 RAL_WRITE(sc, RT2860_WCID_ATTR(wcid), attr);
3266 }
3267}
3268#endif
3269
3270static int8_t
3271rt2860_rssi2dbm(struct rt2860_softc *sc, uint8_t rssi, uint8_t rxchain)
3272{
3328 struct ifnet *ifp = sc->sc_ifp;
3329 struct ieee80211com *ic = ifp->if_l2com;
3273 struct ieee80211com *ic = &sc->sc_ic;
3274 struct ieee80211_channel *c = ic->ic_curchan;
3275 int delta;
3276
3277 if (IEEE80211_IS_CHAN_5GHZ(c)) {
3278 u_int chan = ieee80211_chan2ieee(ic, c);
3279 delta = sc->rssi_5ghz[rxchain];
3280
3281 /* determine channel group */

--- 458 unchanged lines hidden (view full) ---

3740 /* Disable hardware antenna diversity. */
3741 if (sc->mac_ver == 0x5390)
3742 rt2860_mcu_bbp_write(sc, 154, 0);
3743}
3744
3745static int
3746rt2860_txrx_enable(struct rt2860_softc *sc)
3747{
3804 struct ifnet *ifp = sc->sc_ifp;
3805 struct ieee80211com *ic = ifp->if_l2com;
3748 struct ieee80211com *ic = &sc->sc_ic;
3749 uint32_t tmp;
3750 int ntries;
3751
3752 /* enable Tx/Rx DMA engine */
3753 RAL_WRITE(sc, RT2860_MAC_SYS_CTRL, RT2860_MAC_TX_EN);
3754 RAL_BARRIER_READ_WRITE(sc);
3755 for (ntries = 0; ntries < 200; ntries++) {
3756 tmp = RAL_READ(sc, RT2860_WPDMA_GLO_CFG);

--- 29 unchanged lines hidden (view full) ---

3786
3787 return 0;
3788}
3789
3790static void
3791rt2860_init(void *arg)
3792{
3793 struct rt2860_softc *sc = arg;
3851 struct ifnet *ifp = sc->sc_ifp;
3852 struct ieee80211com *ic = ifp->if_l2com;
3794 struct ieee80211com *ic = &sc->sc_ic;
3795
3796 RAL_LOCK(sc);
3797 rt2860_init_locked(sc);
3798 RAL_UNLOCK(sc);
3799
3858 if (ifp->if_drv_flags & IFF_DRV_RUNNING)
3800 if (sc->sc_flags & RT2860_RUNNNING)
3801 ieee80211_start_all(ic);
3802}
3803
3804static void
3805rt2860_init_locked(struct rt2860_softc *sc)
3806{
3865 struct ifnet *ifp = sc->sc_ifp;
3866 struct ieee80211com *ic = ifp->if_l2com;
3807 struct ieee80211com *ic = &sc->sc_ic;
3808 struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps);
3809 uint32_t tmp;
3810 uint8_t bbp1, bbp3;
3811 int i, qid, ridx, ntries, error;
3812
3813 RAL_LOCK_ASSERT(sc);
3814
3815 if (sc->rfswitch) {
3816 /* hardware has a radio switch on GPIO pin 2 */

--- 19 unchanged lines hidden (view full) ---

3836 RAL_WRITE(sc, RT2860_SYS_CTRL, 0xe00);
3837
3838 if ((error = rt2860_load_microcode(sc)) != 0) {
3839 device_printf(sc->sc_dev, "could not load 8051 microcode\n");
3840 rt2860_stop_locked(sc);
3841 return;
3842 }
3843
3902 rt2860_set_macaddr(sc, IF_LLADDR(ifp));
3844 rt2860_set_macaddr(sc, vap ? vap->iv_myaddr : ic->ic_macaddr);
3845
3846 /* init Tx power for all Tx rates (from EEPROM) */
3847 for (ridx = 0; ridx < 5; ridx++) {
3848 if (sc->txpow20mhz[ridx] == 0xffffffff)
3849 continue;
3850 RAL_WRITE(sc, RT2860_TX_PWR_CFG(ridx), sc->txpow20mhz[ridx]);
3851 }
3852

--- 180 unchanged lines hidden (view full) ---

4033
4034 /* set RTS threshold */
4035 tmp = RAL_READ(sc, RT2860_TX_RTS_CFG);
4036 tmp &= ~0xffff00;
4037 tmp |= IEEE80211_RTS_DEFAULT << 8;
4038 RAL_WRITE(sc, RT2860_TX_RTS_CFG, tmp);
4039
4040 /* setup initial protection mode */
4099 rt2860_updateprot(ifp);
4041 rt2860_updateprot(sc);
4042
4043 /* turn radio LED on */
4044 rt2860_set_leds(sc, RT2860_LED_RADIO);
4045
4046 /* enable Tx/Rx DMA engine */
4047 if ((error = rt2860_txrx_enable(sc)) != 0) {
4048 rt2860_stop_locked(sc);
4049 return;
4050 }
4051
4052 /* clear pending interrupts */
4053 RAL_WRITE(sc, RT2860_INT_STATUS, 0xffffffff);
4054 /* enable interrupts */
4055 RAL_WRITE(sc, RT2860_INT_MASK, 0x3fffc);
4056
4057 if (sc->sc_flags & RT2860_ADVANCED_PS)
4058 rt2860_mcu_cmd(sc, RT2860_MCU_CMD_PSLEVEL, sc->pslevel, 0);
4059
4118 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
4119 ifp->if_drv_flags |= IFF_DRV_RUNNING;
4060 sc->sc_flags |= RT2860_RUNNNING;
4061
4062 callout_reset(&sc->watchdog_ch, hz, rt2860_watchdog, sc);
4063}
4064
4065static void
4066rt2860_stop(void *arg)
4067{
4068 struct rt2860_softc *sc = arg;
4069
4070 RAL_LOCK(sc);
4071 rt2860_stop_locked(sc);
4072 RAL_UNLOCK(sc);
4073}
4074
4075static void
4076rt2860_stop_locked(struct rt2860_softc *sc)
4077{
4137 struct ifnet *ifp = sc->sc_ifp;
4078 uint32_t tmp;
4079 int qid;
4080
4141 if (ifp->if_drv_flags & IFF_DRV_RUNNING)
4081 if (sc->sc_flags & RT2860_RUNNNING)
4082 rt2860_set_leds(sc, 0); /* turn all LEDs off */
4083
4084 callout_stop(&sc->watchdog_ch);
4085 sc->sc_tx_timer = 0;
4146 ifp->if_drv_flags &= ~(IFF_DRV_RUNNING | IFF_DRV_OACTIVE);
4086 sc->sc_flags &= ~RT2860_RUNNNING;
4087
4088 /* disable interrupts */
4089 RAL_WRITE(sc, RT2860_INT_MASK, 0);
4090
4091 /* disable GP timer */
4092 rt2860_set_gp_timer(sc, 0);
4093
4094 /* disable Rx */

--- 134 unchanged lines hidden (view full) ---

4229 RAL_WRITE(sc, RT2860_GPIO_CTRL, tmp & ~0x0808);
4230 }
4231 }
4232}
4233
4234static void
4235rt2860_switch_chan(struct rt2860_softc *sc, struct ieee80211_channel *c)
4236{
4297 struct ifnet *ifp = sc->sc_ifp;
4298 struct ieee80211com *ic = ifp->if_l2com;
4237 struct ieee80211com *ic = &sc->sc_ic;
4238 u_int chan, group;
4239
4240 chan = ieee80211_chan2ieee(ic, c);
4241 if (chan == 0 || chan == IEEE80211_CHAN_ANY)
4242 return;
4243
4244 if (sc->mac_ver >= 0x5390)
4245 rt5390_set_chan(sc, chan);

--- 52 unchanged lines hidden (view full) ---

4298 m_freem(m);
4299
4300 return 0;
4301}
4302
4303static void
4304rt2860_enable_tsf_sync(struct rt2860_softc *sc)
4305{
4367 struct ifnet *ifp = sc->sc_ifp;
4368 struct ieee80211com *ic = ifp->if_l2com;
4306 struct ieee80211com *ic = &sc->sc_ic;
4307 struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps);
4308 uint32_t tmp;
4309
4310 tmp = RAL_READ(sc, RT2860_BCN_TIME_CFG);
4311
4312 tmp &= ~0x1fffff;
4313 tmp |= vap->iv_bss->ni_intval * 16;
4314 tmp |= RT2860_TSF_TIMER_EN | RT2860_TBTT_TIMER_EN;

--- 23 unchanged lines hidden ---