1f58ca841SWeongyo Jeong 2f58ca841SWeongyo Jeong /*- 3f58ca841SWeongyo Jeong * Copyright (c) 2008 Weongyo Jeong <weongyo@FreeBSD.org> 4f58ca841SWeongyo Jeong * 5f58ca841SWeongyo Jeong * Permission to use, copy, modify, and distribute this software for any 6f58ca841SWeongyo Jeong * purpose with or without fee is hereby granted, provided that the above 7f58ca841SWeongyo Jeong * copyright notice and this permission notice appear in all copies. 8f58ca841SWeongyo Jeong * 9f58ca841SWeongyo Jeong * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10f58ca841SWeongyo Jeong * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11f58ca841SWeongyo Jeong * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12f58ca841SWeongyo Jeong * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13f58ca841SWeongyo Jeong * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14f58ca841SWeongyo Jeong * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15f58ca841SWeongyo Jeong * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16f58ca841SWeongyo Jeong */ 17f58ca841SWeongyo Jeong 18f58ca841SWeongyo Jeong enum { 19f58ca841SWeongyo Jeong URTW_8187B_BULK_RX, 20a0585a14SWeongyo Jeong URTW_8187B_BULK_TX_STATUS, 21f58ca841SWeongyo Jeong URTW_8187B_BULK_TX_BE, 22f58ca841SWeongyo Jeong URTW_8187B_BULK_TX_BK, 23f58ca841SWeongyo Jeong URTW_8187B_BULK_TX_VI, 24f58ca841SWeongyo Jeong URTW_8187B_BULK_TX_VO, 25f58ca841SWeongyo Jeong URTW_8187B_BULK_TX_EP12, 26a0585a14SWeongyo Jeong URTW_8187B_N_XFERS = 7 27f58ca841SWeongyo Jeong }; 28f58ca841SWeongyo Jeong 29f58ca841SWeongyo Jeong enum { 30f58ca841SWeongyo Jeong URTW_8187L_BULK_RX, 31f58ca841SWeongyo Jeong URTW_8187L_BULK_TX_LOW, 32f58ca841SWeongyo Jeong URTW_8187L_BULK_TX_NORMAL, 33f58ca841SWeongyo Jeong URTW_8187L_N_XFERS = 3 34f58ca841SWeongyo Jeong }; 35f58ca841SWeongyo Jeong 36f58ca841SWeongyo Jeong /* XXX no definition at net80211? */ 37f58ca841SWeongyo Jeong #define URTW_MAX_CHANNELS 15 38f58ca841SWeongyo Jeong 39f58ca841SWeongyo Jeong struct urtw_data { 40f58ca841SWeongyo Jeong struct urtw_softc *sc; 41f58ca841SWeongyo Jeong uint8_t *buf; 42f58ca841SWeongyo Jeong uint16_t buflen; 43f58ca841SWeongyo Jeong struct mbuf *m; 44f58ca841SWeongyo Jeong struct ieee80211_node *ni; /* NB: tx only */ 45f58ca841SWeongyo Jeong STAILQ_ENTRY(urtw_data) next; 46f58ca841SWeongyo Jeong }; 47f58ca841SWeongyo Jeong typedef STAILQ_HEAD(, urtw_data) urtw_datahead; 48f58ca841SWeongyo Jeong 49f58ca841SWeongyo Jeong #define URTW_RX_DATA_LIST_COUNT 4 50f58ca841SWeongyo Jeong #define URTW_TX_DATA_LIST_COUNT 16 51f58ca841SWeongyo Jeong #define URTW_RX_MAXSIZE 0x9c4 52f58ca841SWeongyo Jeong #define URTW_TX_MAXSIZE 0x9c4 53a0585a14SWeongyo Jeong #define URTW_TX_MAXRETRY 11 54f58ca841SWeongyo Jeong 55f58ca841SWeongyo Jeong struct urtw_rx_radiotap_header { 56f58ca841SWeongyo Jeong struct ieee80211_radiotap_header wr_ihdr; 57cb5d2742SAndriy Voskoboinyk uint64_t wr_tsf; 58f58ca841SWeongyo Jeong uint8_t wr_flags; 59786ac703SAndriy Voskoboinyk uint8_t wr_pad; 60f58ca841SWeongyo Jeong uint16_t wr_chan_freq; 61f58ca841SWeongyo Jeong uint16_t wr_chan_flags; 62f58ca841SWeongyo Jeong int8_t wr_dbm_antsignal; 63e8353a7aSHans Petter Selasky } __packed __aligned(8); 64f58ca841SWeongyo Jeong 65f58ca841SWeongyo Jeong #define URTW_RX_RADIOTAP_PRESENT \ 66cb5d2742SAndriy Voskoboinyk ((1 << IEEE80211_RADIOTAP_TSFT) | \ 67cb5d2742SAndriy Voskoboinyk (1 << IEEE80211_RADIOTAP_FLAGS) | \ 68f58ca841SWeongyo Jeong (1 << IEEE80211_RADIOTAP_CHANNEL) | \ 69f58ca841SWeongyo Jeong (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL)) 70f58ca841SWeongyo Jeong 71f58ca841SWeongyo Jeong struct urtw_tx_radiotap_header { 72f58ca841SWeongyo Jeong struct ieee80211_radiotap_header wt_ihdr; 73f58ca841SWeongyo Jeong uint8_t wt_flags; 74786ac703SAndriy Voskoboinyk uint8_t wt_pad; 75f58ca841SWeongyo Jeong uint16_t wt_chan_freq; 76f58ca841SWeongyo Jeong uint16_t wt_chan_flags; 77786ac703SAndriy Voskoboinyk } __packed; 78f58ca841SWeongyo Jeong 79f58ca841SWeongyo Jeong #define URTW_TX_RADIOTAP_PRESENT \ 80f58ca841SWeongyo Jeong ((1 << IEEE80211_RADIOTAP_FLAGS) | \ 81f58ca841SWeongyo Jeong (1 << IEEE80211_RADIOTAP_CHANNEL)) 82f58ca841SWeongyo Jeong 831d3d5952SWeongyo Jeong struct urtw_stats { 84*62d42655SHans Petter Selasky unsigned txrates[12]; 851d3d5952SWeongyo Jeong }; 861d3d5952SWeongyo Jeong 87f58ca841SWeongyo Jeong struct urtw_vap { 88f58ca841SWeongyo Jeong struct ieee80211vap vap; 89f58ca841SWeongyo Jeong int (*newstate)(struct ieee80211vap *, 90f58ca841SWeongyo Jeong enum ieee80211_state, int); 91f58ca841SWeongyo Jeong }; 92f58ca841SWeongyo Jeong #define URTW_VAP(vap) ((struct urtw_vap *)(vap)) 93f58ca841SWeongyo Jeong 94f58ca841SWeongyo Jeong struct urtw_softc { 957a79cebfSGleb Smirnoff struct ieee80211com sc_ic; 967a79cebfSGleb Smirnoff struct mbufq sc_snd; 97f58ca841SWeongyo Jeong device_t sc_dev; 98760bc48eSAndrew Thompson struct usb_device *sc_udev; 99f58ca841SWeongyo Jeong struct mtx sc_mtx; 100c180b398SHans Petter Selasky void *sc_tx_dma_buf; 101f58ca841SWeongyo Jeong 102f58ca841SWeongyo Jeong int sc_debug; 103f58ca841SWeongyo Jeong int sc_flags; 104f58ca841SWeongyo Jeong #define URTW_INIT_ONCE (1 << 1) 105f58ca841SWeongyo Jeong #define URTW_RTL8187B (1 << 2) 106f58ca841SWeongyo Jeong #define URTW_RTL8187B_REV_B (1 << 3) 107f58ca841SWeongyo Jeong #define URTW_RTL8187B_REV_D (1 << 4) 108f58ca841SWeongyo Jeong #define URTW_RTL8187B_REV_E (1 << 5) 109645e4d17SHans Petter Selasky #define URTW_DETACHED (1 << 6) 1107a79cebfSGleb Smirnoff #define URTW_RUNNING (1 << 7) 111f58ca841SWeongyo Jeong enum ieee80211_state sc_state; 112f58ca841SWeongyo Jeong 113f58ca841SWeongyo Jeong int sc_epromtype; 114f58ca841SWeongyo Jeong #define URTW_EEPROM_93C46 0 115f58ca841SWeongyo Jeong #define URTW_EEPROM_93C56 1 116f58ca841SWeongyo Jeong uint8_t sc_crcmon; 117f58ca841SWeongyo Jeong 118f58ca841SWeongyo Jeong struct ieee80211_channel *sc_curchan; 119f58ca841SWeongyo Jeong 120f58ca841SWeongyo Jeong /* for RF */ 121e0a69b51SAndrew Thompson usb_error_t (*sc_rf_init)(struct urtw_softc *); 122e0a69b51SAndrew Thompson usb_error_t (*sc_rf_set_chan)(struct urtw_softc *, 123f58ca841SWeongyo Jeong int); 124e0a69b51SAndrew Thompson usb_error_t (*sc_rf_set_sens)(struct urtw_softc *, 125f58ca841SWeongyo Jeong int); 126e0a69b51SAndrew Thompson usb_error_t (*sc_rf_stop)(struct urtw_softc *); 127f58ca841SWeongyo Jeong uint8_t sc_rfchip; 128f58ca841SWeongyo Jeong uint32_t sc_max_sens; 129f58ca841SWeongyo Jeong uint32_t sc_sens; 130f58ca841SWeongyo Jeong /* for LED */ 131760bc48eSAndrew Thompson struct usb_callout sc_led_ch; 132f58ca841SWeongyo Jeong struct task sc_led_task; 133f58ca841SWeongyo Jeong uint8_t sc_psr; 134f58ca841SWeongyo Jeong uint8_t sc_strategy; 135f58ca841SWeongyo Jeong #define URTW_LED_GPIO 1 136f58ca841SWeongyo Jeong uint8_t sc_gpio_ledon; 137f58ca841SWeongyo Jeong uint8_t sc_gpio_ledinprogress; 138f58ca841SWeongyo Jeong uint8_t sc_gpio_ledstate; 139f58ca841SWeongyo Jeong uint8_t sc_gpio_ledpin; 140f58ca841SWeongyo Jeong uint8_t sc_gpio_blinktime; 141f58ca841SWeongyo Jeong uint8_t sc_gpio_blinkstate; 142f58ca841SWeongyo Jeong /* RX/TX */ 143760bc48eSAndrew Thompson struct usb_xfer *sc_xfer[URTW_8187B_N_XFERS]; 144f58ca841SWeongyo Jeong #define URTW_PRIORITY_LOW 0 145f58ca841SWeongyo Jeong #define URTW_PRIORITY_NORMAL 1 146f58ca841SWeongyo Jeong #define URTW_DATA_TIMEOUT 10000 /* 10 sec */ 147f58ca841SWeongyo Jeong #define URTW_8187B_TXPIPE_BE 0x6 /* best effort */ 148f58ca841SWeongyo Jeong #define URTW_8187B_TXPIPE_BK 0x7 /* background */ 149f58ca841SWeongyo Jeong #define URTW_8187B_TXPIPE_VI 0x5 /* video */ 150f58ca841SWeongyo Jeong #define URTW_8187B_TXPIPE_VO 0x4 /* voice */ 151f58ca841SWeongyo Jeong #define URTW_8187B_TXPIPE_MAX 4 152f58ca841SWeongyo Jeong struct urtw_data sc_rx[URTW_RX_DATA_LIST_COUNT]; 153f58ca841SWeongyo Jeong urtw_datahead sc_rx_active; 154f58ca841SWeongyo Jeong urtw_datahead sc_rx_inactive; 155f58ca841SWeongyo Jeong struct urtw_data sc_tx[URTW_TX_DATA_LIST_COUNT]; 156f58ca841SWeongyo Jeong urtw_datahead sc_tx_active; 157f58ca841SWeongyo Jeong urtw_datahead sc_tx_inactive; 158f58ca841SWeongyo Jeong urtw_datahead sc_tx_pending; 159f58ca841SWeongyo Jeong uint8_t sc_rts_retry; 160f58ca841SWeongyo Jeong uint8_t sc_tx_retry; 161f58ca841SWeongyo Jeong uint8_t sc_preamble_mode; 162f58ca841SWeongyo Jeong #define URTW_PREAMBLE_MODE_SHORT 1 163f58ca841SWeongyo Jeong #define URTW_PREAMBLE_MODE_LONG 2 164f58ca841SWeongyo Jeong struct callout sc_watchdog_ch; 165f58ca841SWeongyo Jeong int sc_txtimer; 166f58ca841SWeongyo Jeong int sc_currate; 167f58ca841SWeongyo Jeong /* TX power */ 168f58ca841SWeongyo Jeong uint8_t sc_txpwr_cck[URTW_MAX_CHANNELS]; 169f58ca841SWeongyo Jeong uint8_t sc_txpwr_cck_base; 170f58ca841SWeongyo Jeong uint8_t sc_txpwr_ofdm[URTW_MAX_CHANNELS]; 171f58ca841SWeongyo Jeong uint8_t sc_txpwr_ofdm_base; 172f58ca841SWeongyo Jeong 173a0585a14SWeongyo Jeong uint8_t sc_acmctl; 174a0585a14SWeongyo Jeong uint64_t sc_txstatus; /* only for 8187B */ 175a0585a14SWeongyo Jeong struct task sc_updateslot_task; 176a0585a14SWeongyo Jeong 1771d3d5952SWeongyo Jeong struct urtw_stats sc_stats; 1781d3d5952SWeongyo Jeong 179f58ca841SWeongyo Jeong struct urtw_rx_radiotap_header sc_rxtap; 180f58ca841SWeongyo Jeong struct urtw_tx_radiotap_header sc_txtap; 181f58ca841SWeongyo Jeong }; 182f58ca841SWeongyo Jeong 183f58ca841SWeongyo Jeong #define URTW_LOCK(sc) mtx_lock(&(sc)->sc_mtx) 184f58ca841SWeongyo Jeong #define URTW_UNLOCK(sc) mtx_unlock(&(sc)->sc_mtx) 185f58ca841SWeongyo Jeong #define URTW_ASSERT_LOCKED(sc) mtx_assert(&(sc)->sc_mtx, MA_OWNED) 186