1 /* $FreeBSD$ */ 2 3 /*- 4 * Copyright (c) 2008 Weongyo Jeong <weongyo@FreeBSD.org> 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 19 enum { 20 URTW_8187B_BULK_RX, 21 URTW_8187B_BULK_TX_STATUS, 22 URTW_8187B_BULK_TX_BE, 23 URTW_8187B_BULK_TX_BK, 24 URTW_8187B_BULK_TX_VI, 25 URTW_8187B_BULK_TX_VO, 26 URTW_8187B_BULK_TX_EP12, 27 URTW_8187B_N_XFERS = 7 28 }; 29 30 enum { 31 URTW_8187L_BULK_RX, 32 URTW_8187L_BULK_TX_LOW, 33 URTW_8187L_BULK_TX_NORMAL, 34 URTW_8187L_N_XFERS = 3 35 }; 36 37 /* XXX no definition at net80211? */ 38 #define URTW_MAX_CHANNELS 15 39 40 struct urtw_data { 41 struct urtw_softc *sc; 42 uint8_t *buf; 43 uint16_t buflen; 44 struct mbuf *m; 45 struct ieee80211_node *ni; /* NB: tx only */ 46 STAILQ_ENTRY(urtw_data) next; 47 }; 48 typedef STAILQ_HEAD(, urtw_data) urtw_datahead; 49 50 /* XXX not correct.. */ 51 #define URTW_MIN_RXBUFSZ \ 52 (sizeof(struct ieee80211_frame_min)) 53 54 #define URTW_RX_DATA_LIST_COUNT 4 55 #define URTW_TX_DATA_LIST_COUNT 16 56 #define URTW_RX_MAXSIZE 0x9c4 57 #define URTW_TX_MAXSIZE 0x9c4 58 #define URTW_TX_MAXRETRY 11 59 60 struct urtw_rx_radiotap_header { 61 struct ieee80211_radiotap_header wr_ihdr; 62 uint8_t wr_flags; 63 uint16_t wr_chan_freq; 64 uint16_t wr_chan_flags; 65 int8_t wr_dbm_antsignal; 66 } __packed; 67 68 #define URTW_RX_RADIOTAP_PRESENT \ 69 ((1 << IEEE80211_RADIOTAP_FLAGS) | \ 70 (1 << IEEE80211_RADIOTAP_CHANNEL) | \ 71 (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL)) 72 73 struct urtw_tx_radiotap_header { 74 struct ieee80211_radiotap_header wt_ihdr; 75 uint8_t wt_flags; 76 uint16_t wt_chan_freq; 77 uint16_t wt_chan_flags; 78 } __packed; 79 80 #define URTW_TX_RADIOTAP_PRESENT \ 81 ((1 << IEEE80211_RADIOTAP_FLAGS) | \ 82 (1 << IEEE80211_RADIOTAP_CHANNEL)) 83 84 struct urtw_vap { 85 struct ieee80211vap vap; 86 int (*newstate)(struct ieee80211vap *, 87 enum ieee80211_state, int); 88 }; 89 #define URTW_VAP(vap) ((struct urtw_vap *)(vap)) 90 91 struct urtw_softc { 92 struct ifnet *sc_ifp; 93 device_t sc_dev; 94 struct usb_device *sc_udev; 95 struct mtx sc_mtx; 96 97 int sc_debug; 98 int sc_if_flags; 99 int sc_flags; 100 #define URTW_INIT_ONCE (1 << 1) 101 #define URTW_RTL8187B (1 << 2) 102 #define URTW_RTL8187B_REV_B (1 << 3) 103 #define URTW_RTL8187B_REV_D (1 << 4) 104 #define URTW_RTL8187B_REV_E (1 << 5) 105 enum ieee80211_state sc_state; 106 107 int sc_epromtype; 108 #define URTW_EEPROM_93C46 0 109 #define URTW_EEPROM_93C56 1 110 uint8_t sc_crcmon; 111 uint8_t sc_bssid[IEEE80211_ADDR_LEN]; 112 113 struct ieee80211_channel *sc_curchan; 114 115 /* for RF */ 116 usb_error_t (*sc_rf_init)(struct urtw_softc *); 117 usb_error_t (*sc_rf_set_chan)(struct urtw_softc *, 118 int); 119 usb_error_t (*sc_rf_set_sens)(struct urtw_softc *, 120 int); 121 usb_error_t (*sc_rf_stop)(struct urtw_softc *); 122 uint8_t sc_rfchip; 123 uint32_t sc_max_sens; 124 uint32_t sc_sens; 125 /* for LED */ 126 struct usb_callout sc_led_ch; 127 struct task sc_led_task; 128 uint8_t sc_psr; 129 uint8_t sc_strategy; 130 #define URTW_LED_GPIO 1 131 uint8_t sc_gpio_ledon; 132 uint8_t sc_gpio_ledinprogress; 133 uint8_t sc_gpio_ledstate; 134 uint8_t sc_gpio_ledpin; 135 uint8_t sc_gpio_blinktime; 136 uint8_t sc_gpio_blinkstate; 137 /* RX/TX */ 138 struct usb_xfer *sc_xfer[URTW_8187B_N_XFERS]; 139 #define URTW_PRIORITY_LOW 0 140 #define URTW_PRIORITY_NORMAL 1 141 #define URTW_DATA_TIMEOUT 10000 /* 10 sec */ 142 #define URTW_8187B_TXPIPE_BE 0x6 /* best effort */ 143 #define URTW_8187B_TXPIPE_BK 0x7 /* background */ 144 #define URTW_8187B_TXPIPE_VI 0x5 /* video */ 145 #define URTW_8187B_TXPIPE_VO 0x4 /* voice */ 146 #define URTW_8187B_TXPIPE_MAX 4 147 struct urtw_data sc_rx[URTW_RX_DATA_LIST_COUNT]; 148 urtw_datahead sc_rx_active; 149 urtw_datahead sc_rx_inactive; 150 struct urtw_data sc_tx[URTW_TX_DATA_LIST_COUNT]; 151 urtw_datahead sc_tx_active; 152 urtw_datahead sc_tx_inactive; 153 urtw_datahead sc_tx_pending; 154 uint8_t sc_rts_retry; 155 uint8_t sc_tx_retry; 156 uint8_t sc_preamble_mode; 157 #define URTW_PREAMBLE_MODE_SHORT 1 158 #define URTW_PREAMBLE_MODE_LONG 2 159 struct callout sc_watchdog_ch; 160 int sc_txtimer; 161 int sc_currate; 162 /* TX power */ 163 uint8_t sc_txpwr_cck[URTW_MAX_CHANNELS]; 164 uint8_t sc_txpwr_cck_base; 165 uint8_t sc_txpwr_ofdm[URTW_MAX_CHANNELS]; 166 uint8_t sc_txpwr_ofdm_base; 167 168 uint8_t sc_acmctl; 169 uint64_t sc_txstatus; /* only for 8187B */ 170 struct task sc_updateslot_task; 171 172 struct urtw_rx_radiotap_header sc_rxtap; 173 int sc_rxtap_len; 174 struct urtw_tx_radiotap_header sc_txtap; 175 int sc_txtap_len; 176 }; 177 178 #define URTW_LOCK(sc) mtx_lock(&(sc)->sc_mtx) 179 #define URTW_UNLOCK(sc) mtx_unlock(&(sc)->sc_mtx) 180 #define URTW_ASSERT_LOCKED(sc) mtx_assert(&(sc)->sc_mtx, MA_OWNED) 181