From owner-p4-projects@FreeBSD.ORG Wed Jan 13 08:29:24 2010 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 57DE4106568B; Wed, 13 Jan 2010 08:29:24 +0000 (UTC) Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 1AB651065672 for ; Wed, 13 Jan 2010 08:29:24 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id 077FE8FC1D for ; Wed, 13 Jan 2010 08:29:24 +0000 (UTC) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.3/8.14.3) with ESMTP id o0D8TNRg014348 for ; Wed, 13 Jan 2010 08:29:23 GMT (envelope-from hselasky@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.3/8.14.3/Submit) id o0D8TNhK014346 for perforce@freebsd.org; Wed, 13 Jan 2010 08:29:23 GMT (envelope-from hselasky@FreeBSD.org) Date: Wed, 13 Jan 2010 08:29:23 GMT Message-Id: <201001130829.o0D8TNhK014346@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to hselasky@FreeBSD.org using -f From: Hans Petter Selasky To: Perforce Change Reviews Precedence: bulk Cc: Subject: PERFORCE change 173060 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 13 Jan 2010 08:29:24 -0000 http://p4web.freebsd.org/chv.cgi?CH=173060 Change 173060 by hselasky@hselasky_laptop001 on 2010/01/13 08:28:28 USB wlan: - patch for RUN driver - patch done by: Akinori Affected files ... .. //depot/projects/usb/src/sys/dev/usb/wlan/if_run.c#3 edit Differences ... ==== //depot/projects/usb/src/sys/dev/usb/wlan/if_run.c#3 (text+ko) ==== @@ -701,10 +701,6 @@ ieee80211_vap_setup(ic, vap, name, unit, opmode, flags | IEEE80211_CLONE_NOBEACONS, bssid, mac); - /* - * I couldn't make these func work. - * Let me know if you can. - */ vap->iv_key_update_begin = run_key_update_begin; vap->iv_key_update_end = run_key_update_end; vap->iv_key_delete = run_key_delete; @@ -869,7 +865,7 @@ return error; if (tmp & RT2860_MCU_READY) break; - run_delay(sc, 1000); + run_delay(sc, 10); } if (ntries == 1000) { printf("%s: timeout waiting for MCU to initialize\n", @@ -1726,11 +1722,10 @@ /* map net80211 cipher to RT2860 security mode */ switch (k->wk_cipher->ic_cipher) { case IEEE80211_CIPHER_WEP: - if(k->wk_keylen < 8){ + if(k->wk_keylen < 8) mode = RT2860_MODE_WEP40; - }else{ + else mode = RT2860_MODE_WEP104; - } break; case IEEE80211_CIPHER_TKIP: mode = RT2860_MODE_TKIP; @@ -1908,11 +1903,26 @@ struct run_vap *rvp = arg; struct ieee80211vap *vap = &rvp->vap; struct ieee80211com *ic = vap->iv_ic; + struct run_softc *sc = ic->ic_ifp->if_softc; if (ic->ic_opmode == IEEE80211_M_STA) run_iter_func(rvp, vap->iv_bss); - else + else { + /* + * run_reset_livelock() doesn't do anything with AMRR, + * but Ralink wants us to call it every 1 sec. So, we + * piggyback here rather than creating another callout. + * Livelock may occur only in HOSTAP or IBSS mode + * (when h/w is sending beacons). + */ + RUN_LOCK(sc); + run_reset_livelock(sc); + RUN_UNLOCK(sc); ieee80211_iterate_nodes(&ic->ic_sta, run_iter_func, rvp); + } + + if(rvp->amrr_run == RUN_AMRR_ON) + usb_callout_reset(&rvp->amrr_ch, hz, run_amrr_to, rvp); } @@ -1936,7 +1946,7 @@ if(ic->ic_opmode != IEEE80211_M_STA){ /* drain Tx status FIFO (maxsize = 16) */ - run_read_region_1(sc, RT2860_TX_STAT_FIFO, (uint8_t *)&stat, sizeof stat); + run_read(sc, RT2860_TX_STAT_FIFO, &stat); while (stat & RT2860_TXQ_VLD) { DPRINTFN(4, "tx stat 0x%08x\n", stat); @@ -2002,9 +2012,6 @@ ieee80211_amrr_choose(ni, amn); skip:; - if(rvp->amrr_run == RUN_AMRR_ON) - usb_callout_reset(&rvp->amrr_ch, hz, run_amrr_to, rvp); - RUN_UNLOCK(sc); if(ic->ic_opmode != IEEE80211_M_STA) @@ -2335,7 +2342,9 @@ struct mbuf *m; usb_frlength_t size; unsigned int len; - int actlen, sumlen; + int actlen; + int sumlen; + int timeout; usbd_xfer_status(xfer, &actlen, &sumlen, NULL, NULL); @@ -2347,6 +2356,7 @@ data = usbd_xfer_get_priv(xfer); run_tx_free(pq, data, 0); + ifp->if_drv_flags &= ~IFF_DRV_OACTIVE; usbd_xfer_set_priv(xfer, NULL); @@ -2404,10 +2414,19 @@ usbd_transfer_submit(xfer); + /* avoid doing the USB timeout from this function */ + + timeout = sc->sc_usb_timeout; + sc->sc_usb_timeout = 0; + RUN_UNLOCK(sc); + run_start(ifp); + RUN_LOCK(sc); + sc->sc_usb_timeout = timeout; + break; default: @@ -2429,9 +2448,6 @@ /* defer until later */ sc->sc_usb_timeout = 1; - - /* XXX this should be in a separate task! */ - run_usb_timeout(sc); } /* @@ -2625,7 +2641,7 @@ /* reserve slots for mgmt packets, just in case */ if (sc->sc_epq[qid].tx_nfree < 3) { - DPRINTF("tx ring %d is full\n", qid); + DPRINTFN(10, "tx ring %d is full\n", qid); return (-1); } @@ -2766,7 +2782,8 @@ mprot = ieee80211_alloc_cts(ic, ni->ni_vap->iv_myaddr, dur); } if (mprot == NULL) { - /* XXX stat + msg */ + sc->sc_ifp->if_oerrors++; + DPRINTF("could not allocate mbuf\n"); return (ENOBUFS); } @@ -2884,6 +2901,10 @@ goto bad; } + /* Device is in trouble. Fix it before sending more frame. */ + if(sc->sc_usb_timeout == 1) + run_usb_timeout(sc); + if (params == NULL) { /* tx mgt packet */ if ((error = run_tx_mgt(sc, m, ni)) != 0){ @@ -2930,6 +2951,10 @@ } for (;;) { + /* Device is in trouble. Fix it before sending more frame. */ + if(sc->sc_usb_timeout == 1) + run_usb_timeout(sc); + /* send data frames */ IFQ_DRV_DEQUEUE(&ifp->if_snd, m); if (m == NULL) @@ -3082,14 +3107,14 @@ run_rt2870_rf_write(sc, RT2860_RF3, r3); run_rt2870_rf_write(sc, RT2860_RF4, r4); - run_delay(sc, 200); + run_delay(sc, 10); run_rt2870_rf_write(sc, RT2860_RF1, rfprog[i].r1); run_rt2870_rf_write(sc, RT2860_RF2, r2); run_rt2870_rf_write(sc, RT2860_RF3, r3 | 1); run_rt2870_rf_write(sc, RT2860_RF4, r4); - run_delay(sc, 200); + run_delay(sc, 10); run_rt2870_rf_write(sc, RT2860_RF1, rfprog[i].r1); run_rt2870_rf_write(sc, RT2860_RF2, r2); @@ -3201,7 +3226,7 @@ /* XXX necessary only when group has changed! */ run_select_chan_group(sc, group); - run_delay(sc, 1000); + run_delay(sc, 10); return 0; } @@ -3359,18 +3384,21 @@ sc->sc_usb_timeout = 0; - if(vap->iv_state == IEEE80211_S_SCAN){ + if(vap->iv_state == IEEE80211_S_RUN && + vap->iv_opmode != IEEE80211_M_STA) + run_reset_livelock(sc); + else if(vap->iv_state == IEEE80211_S_SCAN){ DPRINTF("timeout caused by scan\n"); /* cancel bgscan */ ieee80211_cancel_scan(vap); - } else if(vap->iv_state == IEEE80211_S_RUN) - run_reset_livelock(sc); + } else + DPRINTF("timeout by unknown cause\n"); } static void run_reset_livelock(struct run_softc *sc) { - struct ieee80211vap *vap = &sc->sc_rvp->vap; + uint32_t tmp; /* * In IBSS or HostAP modes (when the hardware sends beacons), the @@ -3378,10 +3406,11 @@ * like crazy if protection is enabled. * Reset MAC/BBP for a while */ - if (vap->iv_opmode != IEEE80211_M_STA) { + run_read(sc, RT2860_DEBUG, &tmp); + if((tmp & (1 << 29)) && (tmp & (1 << 7 | 1 << 5))){ DPRINTF("CTS-to-self livelock detected\n"); run_write(sc, RT2860_MAC_SYS_CTRL, RT2860_MAC_SRST); - run_delay(sc, 4); + run_delay(sc, 1); run_write(sc, RT2860_MAC_SYS_CTRL, RT2860_MAC_RX_EN | RT2860_MAC_TX_EN); } @@ -3623,7 +3652,7 @@ run_rt3070_rf_read(sc, 30, &rf); /* toggle RF R30 bit 7 */ run_rt3070_rf_write(sc, 30, rf | 0x80); - run_delay(sc, 1000); + run_delay(sc, 10); run_rt3070_rf_write(sc, 30, rf & ~0x80); /* initialize RF registers to default value */ @@ -3747,7 +3776,7 @@ for (ntries = 0; ntries < 100; ntries++) { /* transmit test tone */ run_bbp_write(sc, 25, 0x90); - run_delay(sc, 1000); + run_delay(sc, 10); /* read received power */ run_bbp_read(sc, 55, &bbp55_pb); if (bbp55_pb != 0) @@ -3761,7 +3790,7 @@ for (ntries = 0; ntries < 100; ntries++) { /* transmit test tone */ run_bbp_write(sc, 25, 0x90); - run_delay(sc, 1000); + run_delay(sc, 10); /* read received power */ run_bbp_read(sc, 55, &bbp55_sb); @@ -3803,7 +3832,7 @@ return error; if ((tmp & (RT2860_TX_DMA_BUSY | RT2860_RX_DMA_BUSY)) == 0) break; - run_delay(sc, 1000); + run_delay(sc, 50); } if (ntries == 200) return ETIMEDOUT; @@ -3870,7 +3899,7 @@ goto fail; if ((tmp & (RT2860_TX_DMA_BUSY | RT2860_RX_DMA_BUSY)) == 0) break; - run_delay(sc, 1000); + run_delay(sc, 10); } if (ntries == 100) { printf("%s: timeout waiting for DMA engine\n", @@ -3924,7 +3953,7 @@ goto fail; if (!(tmp & (RT2860_RX_STATUS_BUSY | RT2860_TX_STATUS_BUSY))) break; - run_delay(sc, 1000); + run_delay(sc, 10); } if (ntries == 100) goto fail; @@ -3932,7 +3961,7 @@ /* clear Host to MCU mailbox */ run_write(sc, RT2860_H2M_BBPAGENT, 0); run_write(sc, RT2860_H2M_MAILBOX, 0); - run_delay(sc, 1000); + run_delay(sc, 10); if (run_bbp_init(sc) != 0) { printf("%s: could not initialize BBP\n", @@ -4094,11 +4123,11 @@ DPRINTF("All Tx cleared\n"); break; } - run_delay(sc, 1000); + run_delay(sc, 10); } if(ntries >= 100) DPRINTF("There are still pending Tx\n"); - run_delay(sc, 1000); + run_delay(sc, 10); run_write(sc, RT2860_USB_DMA_CFG, 0); run_write(sc, RT2860_MAC_SYS_CTRL, RT2860_BBP_HRST | RT2860_MAC_SRST);