if_rsu.c (288049) | if_rsu.c (288051) |
---|---|
1/* $OpenBSD: if_rsu.c,v 1.17 2013/04/15 09:23:01 mglocker Exp $ */ 2 3/*- 4 * Copyright (c) 2010 Damien Bergamini <damien.bergamini@free.fr> 5 * 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. 9 * 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. 17 */ 18#include <sys/cdefs.h> | 1/* $OpenBSD: if_rsu.c,v 1.17 2013/04/15 09:23:01 mglocker Exp $ */ 2 3/*- 4 * Copyright (c) 2010 Damien Bergamini <damien.bergamini@free.fr> 5 * 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. 9 * 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. 17 */ 18#include <sys/cdefs.h> |
19__FBSDID("$FreeBSD: head/sys/dev/usb/wlan/if_rsu.c 288049 2015-09-20 22:52:40Z adrian $"); | 19__FBSDID("$FreeBSD: head/sys/dev/usb/wlan/if_rsu.c 288051 2015-09-21 02:12:01Z adrian $"); |
20 21/* 22 * Driver for Realtek RTL8188SU/RTL8191SU/RTL8192SU. 23 * 24 * TODO: 25 * o 11n support 26 * o h/w crypto 27 * o hostap / ibss / mesh --- 475 unchanged lines hidden (view full) --- 503{ 504 struct rsu_softc *sc = device_get_softc(self); 505 struct ieee80211com *ic = &sc->sc_ic; 506 507 RSU_LOCK(sc); 508 rsu_stop(sc); 509 RSU_UNLOCK(sc); 510 usbd_transfer_unsetup(sc->sc_xfer, RSU_N_TRANSFER); | 20 21/* 22 * Driver for Realtek RTL8188SU/RTL8191SU/RTL8192SU. 23 * 24 * TODO: 25 * o 11n support 26 * o h/w crypto 27 * o hostap / ibss / mesh --- 475 unchanged lines hidden (view full) --- 503{ 504 struct rsu_softc *sc = device_get_softc(self); 505 struct ieee80211com *ic = &sc->sc_ic; 506 507 RSU_LOCK(sc); 508 rsu_stop(sc); 509 RSU_UNLOCK(sc); 510 usbd_transfer_unsetup(sc->sc_xfer, RSU_N_TRANSFER); |
511 512 /* Frames are freed; detach from net80211 */ |
|
511 ieee80211_ifdetach(ic); 512 513 taskqueue_drain_timeout(taskqueue_thread, &sc->calib_task); 514 515 /* Free Tx/Rx buffers. */ 516 rsu_free_tx_list(sc); 517 rsu_free_rx_list(sc); 518 | 513 ieee80211_ifdetach(ic); 514 515 taskqueue_drain_timeout(taskqueue_thread, &sc->calib_task); 516 517 /* Free Tx/Rx buffers. */ 518 rsu_free_tx_list(sc); 519 rsu_free_rx_list(sc); 520 |
519 mbufq_drain(&sc->sc_snd); | |
520 mtx_destroy(&sc->sc_mtx); 521 522 return (0); 523} 524 525static usb_error_t 526rsu_do_request(struct rsu_softc *sc, struct usb_device_request *req, 527 void *data) --- 226 unchanged lines hidden (view full) --- 754static struct rsu_data * 755rsu_getbuf(struct rsu_softc *sc) 756{ 757 struct rsu_data *bf; 758 759 RSU_ASSERT_LOCKED(sc); 760 761 bf = _rsu_getbuf(sc); | 521 mtx_destroy(&sc->sc_mtx); 522 523 return (0); 524} 525 526static usb_error_t 527rsu_do_request(struct rsu_softc *sc, struct usb_device_request *req, 528 void *data) --- 226 unchanged lines hidden (view full) --- 755static struct rsu_data * 756rsu_getbuf(struct rsu_softc *sc) 757{ 758 struct rsu_data *bf; 759 760 RSU_ASSERT_LOCKED(sc); 761 762 bf = _rsu_getbuf(sc); |
763 if (bf == NULL) { 764 RSU_DPRINTF(sc, RSU_DEBUG_TX, "%s: no buffers\n", __func__); 765 } |
|
762 return (bf); 763} 764 765static void 766rsu_freebuf(struct rsu_softc *sc, struct rsu_data *bf) 767{ 768 769 RSU_ASSERT_LOCKED(sc); --- 1222 unchanged lines hidden (view full) --- 1992 1993 RSU_LOCK(sc); 1994 if (!sc->sc_running) { 1995 RSU_UNLOCK(sc); 1996 return (ENXIO); 1997 } 1998 error = mbufq_enqueue(&sc->sc_snd, m); 1999 if (error) { | 766 return (bf); 767} 768 769static void 770rsu_freebuf(struct rsu_softc *sc, struct rsu_data *bf) 771{ 772 773 RSU_ASSERT_LOCKED(sc); --- 1222 unchanged lines hidden (view full) --- 1996 1997 RSU_LOCK(sc); 1998 if (!sc->sc_running) { 1999 RSU_UNLOCK(sc); 2000 return (ENXIO); 2001 } 2002 error = mbufq_enqueue(&sc->sc_snd, m); 2003 if (error) { |
2004 RSU_DPRINTF(sc, RSU_DEBUG_TX, 2005 "%s: mbufq_enable: failed (%d)\n", 2006 __func__, 2007 error); |
|
2000 RSU_UNLOCK(sc); 2001 return (error); 2002 } 2003 rsu_start(sc); 2004 RSU_UNLOCK(sc); 2005 2006 return (0); 2007} 2008 2009static void | 2008 RSU_UNLOCK(sc); 2009 return (error); 2010 } 2011 rsu_start(sc); 2012 RSU_UNLOCK(sc); 2013 2014 return (0); 2015} 2016 2017static void |
2018rsu_drain_mbufq(struct rsu_softc *sc) 2019{ 2020 struct mbuf *m; 2021 struct ieee80211_node *ni; 2022 2023 RSU_ASSERT_LOCKED(sc); 2024 while ((m = mbufq_dequeue(&sc->sc_snd)) != NULL) { 2025 ni = (struct ieee80211_node *)m->m_pkthdr.rcvif; 2026 m->m_pkthdr.rcvif = NULL; 2027 ieee80211_free_node(ni); 2028 m_freem(m); 2029 } 2030} 2031 2032static void |
|
2010rsu_start(struct rsu_softc *sc) 2011{ 2012 struct ieee80211_node *ni; 2013 struct rsu_data *bf; 2014 struct mbuf *m; 2015 2016 RSU_ASSERT_LOCKED(sc); 2017 2018 while ((m = mbufq_dequeue(&sc->sc_snd)) != NULL) { 2019 bf = rsu_getbuf(sc); 2020 if (bf == NULL) { | 2033rsu_start(struct rsu_softc *sc) 2034{ 2035 struct ieee80211_node *ni; 2036 struct rsu_data *bf; 2037 struct mbuf *m; 2038 2039 RSU_ASSERT_LOCKED(sc); 2040 2041 while ((m = mbufq_dequeue(&sc->sc_snd)) != NULL) { 2042 bf = rsu_getbuf(sc); 2043 if (bf == NULL) { |
2044 RSU_DPRINTF(sc, RSU_DEBUG_TX, 2045 "%s: failed to get buffer\n", __func__); |
|
2021 mbufq_prepend(&sc->sc_snd, m); 2022 break; 2023 } 2024 2025 ni = (struct ieee80211_node *)m->m_pkthdr.rcvif; 2026 m->m_pkthdr.rcvif = NULL; 2027 2028 if (rsu_tx_start(sc, ni, m, bf) != 0) { | 2046 mbufq_prepend(&sc->sc_snd, m); 2047 break; 2048 } 2049 2050 ni = (struct ieee80211_node *)m->m_pkthdr.rcvif; 2051 m->m_pkthdr.rcvif = NULL; 2052 2053 if (rsu_tx_start(sc, ni, m, bf) != 0) { |
2054 RSU_DPRINTF(sc, RSU_DEBUG_TX, 2055 "%s: failed to transmit\n", __func__); |
|
2029 if_inc_counter(ni->ni_vap->iv_ifp, 2030 IFCOUNTER_OERRORS, 1); 2031 rsu_freebuf(sc, bf); 2032 ieee80211_free_node(ni); 2033 break; 2034 } 2035 } 2036} --- 509 unchanged lines hidden (view full) --- 2546 struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps); 2547 uint8_t macaddr[IEEE80211_ADDR_LEN]; 2548 struct r92s_set_pwr_mode cmd; 2549 int error; 2550 int i; 2551 2552 RSU_ASSERT_LOCKED(sc); 2553 | 2056 if_inc_counter(ni->ni_vap->iv_ifp, 2057 IFCOUNTER_OERRORS, 1); 2058 rsu_freebuf(sc, bf); 2059 ieee80211_free_node(ni); 2060 break; 2061 } 2062 } 2063} --- 509 unchanged lines hidden (view full) --- 2573 struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps); 2574 uint8_t macaddr[IEEE80211_ADDR_LEN]; 2575 struct r92s_set_pwr_mode cmd; 2576 int error; 2577 int i; 2578 2579 RSU_ASSERT_LOCKED(sc); 2580 |
2581 /* Ensure the mbuf queue is drained */ 2582 rsu_drain_mbufq(sc); 2583 |
|
2554 /* Init host async commands ring. */ 2555 sc->cmdq.cur = sc->cmdq.next = sc->cmdq.queued = 0; 2556 2557 /* Power on adapter. */ 2558 if (sc->cut == 1) 2559 rsu_power_on_acut(sc); 2560 else 2561 rsu_power_on_bcut(sc); --- 93 unchanged lines hidden (view full) --- 2655 sc->sc_calibrating = 0; 2656 taskqueue_cancel_timeout(taskqueue_thread, &sc->calib_task, NULL); 2657 2658 /* Power off adapter. */ 2659 rsu_power_off(sc); 2660 2661 for (i = 0; i < RSU_N_TRANSFER; i++) 2662 usbd_transfer_stop(sc->sc_xfer[i]); | 2584 /* Init host async commands ring. */ 2585 sc->cmdq.cur = sc->cmdq.next = sc->cmdq.queued = 0; 2586 2587 /* Power on adapter. */ 2588 if (sc->cut == 1) 2589 rsu_power_on_acut(sc); 2590 else 2591 rsu_power_on_bcut(sc); --- 93 unchanged lines hidden (view full) --- 2685 sc->sc_calibrating = 0; 2686 taskqueue_cancel_timeout(taskqueue_thread, &sc->calib_task, NULL); 2687 2688 /* Power off adapter. */ 2689 rsu_power_off(sc); 2690 2691 for (i = 0; i < RSU_N_TRANSFER; i++) 2692 usbd_transfer_stop(sc->sc_xfer[i]); |
2693 2694 /* Ensure the mbuf queue is drained */ 2695 rsu_drain_mbufq(sc); |
|
2663} 2664 2665/* 2666 * Note: usb_pause_mtx() actually releases the mutex before calling pause(), 2667 * which breaks any kind of driver serialisation. 2668 */ 2669static void 2670rsu_ms_delay(struct rsu_softc *sc, int ms) 2671{ 2672 2673 //usb_pause_mtx(&sc->sc_mtx, hz / 1000); 2674 DELAY(ms * 1000); 2675} | 2696} 2697 2698/* 2699 * Note: usb_pause_mtx() actually releases the mutex before calling pause(), 2700 * which breaks any kind of driver serialisation. 2701 */ 2702static void 2703rsu_ms_delay(struct rsu_softc *sc, int ms) 2704{ 2705 2706 //usb_pause_mtx(&sc->sc_mtx, hz / 1000); 2707 DELAY(ms * 1000); 2708} |