1*57a8187dShastings /* $OpenBSD: if_mtwvar.h,v 1.1 2021/12/20 13:59:02 hastings Exp $ */ 2*57a8187dShastings /* 3*57a8187dShastings * Copyright (c) 2008,2009 Damien Bergamini <damien.bergamini@free.fr> 4*57a8187dShastings * 5*57a8187dShastings * Permission to use, copy, modify, and distribute this software for any 6*57a8187dShastings * purpose with or without fee is hereby granted, provided that the above 7*57a8187dShastings * copyright notice and this permission notice appear in all copies. 8*57a8187dShastings * 9*57a8187dShastings * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10*57a8187dShastings * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11*57a8187dShastings * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12*57a8187dShastings * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13*57a8187dShastings * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14*57a8187dShastings * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15*57a8187dShastings * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16*57a8187dShastings */ 17*57a8187dShastings 18*57a8187dShastings #define MTW_MAX_RXSZ \ 19*57a8187dShastings 4096 20*57a8187dShastings #if 0 21*57a8187dShastings (sizeof (uint32_t) + \ 22*57a8187dShastings sizeof (struct mtw_rxwi) + \ 23*57a8187dShastings sizeof (uint16_t) + \ 24*57a8187dShastings MCLBYTES + \ 25*57a8187dShastings sizeof (struct mtw_rxd)) 26*57a8187dShastings #endif 27*57a8187dShastings /* NB: "11" is the maximum number of padding bytes needed for Tx */ 28*57a8187dShastings #define MTW_MAX_TXSZ \ 29*57a8187dShastings (sizeof (struct mtw_txd) + \ 30*57a8187dShastings sizeof (struct mtw_txwi) + \ 31*57a8187dShastings MCLBYTES + 11) 32*57a8187dShastings 33*57a8187dShastings #define MTW_TX_TIMEOUT 5000 /* ms */ 34*57a8187dShastings 35*57a8187dShastings #define MTW_RX_RING_COUNT 1 36*57a8187dShastings #define MTW_TX_RING_COUNT 8 37*57a8187dShastings 38*57a8187dShastings #define MTW_RXQ_COUNT 2 39*57a8187dShastings #define MTW_TXQ_COUNT 6 40*57a8187dShastings 41*57a8187dShastings #define MTW_WCID_MAX 8 42*57a8187dShastings #define MTW_AID2WCID(aid) (1 + ((aid) & 0x7)) 43*57a8187dShastings 44*57a8187dShastings struct mtw_rx_radiotap_header { 45*57a8187dShastings struct ieee80211_radiotap_header wr_ihdr; 46*57a8187dShastings uint8_t wr_flags; 47*57a8187dShastings uint8_t wr_rate; 48*57a8187dShastings uint16_t wr_chan_freq; 49*57a8187dShastings uint16_t wr_chan_flags; 50*57a8187dShastings uint8_t wr_dbm_antsignal; 51*57a8187dShastings uint8_t wr_antenna; 52*57a8187dShastings uint8_t wr_antsignal; 53*57a8187dShastings } __packed; 54*57a8187dShastings 55*57a8187dShastings #define MTW_RX_RADIOTAP_PRESENT \ 56*57a8187dShastings (1 << IEEE80211_RADIOTAP_FLAGS | \ 57*57a8187dShastings 1 << IEEE80211_RADIOTAP_RATE | \ 58*57a8187dShastings 1 << IEEE80211_RADIOTAP_CHANNEL | \ 59*57a8187dShastings 1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL | \ 60*57a8187dShastings 1 << IEEE80211_RADIOTAP_ANTENNA | \ 61*57a8187dShastings 1 << IEEE80211_RADIOTAP_DB_ANTSIGNAL) 62*57a8187dShastings 63*57a8187dShastings struct mtw_tx_radiotap_header { 64*57a8187dShastings struct ieee80211_radiotap_header wt_ihdr; 65*57a8187dShastings uint8_t wt_flags; 66*57a8187dShastings uint8_t wt_rate; 67*57a8187dShastings uint16_t wt_chan_freq; 68*57a8187dShastings uint16_t wt_chan_flags; 69*57a8187dShastings } __packed; 70*57a8187dShastings 71*57a8187dShastings #define MTW_TX_RADIOTAP_PRESENT \ 72*57a8187dShastings (1 << IEEE80211_RADIOTAP_FLAGS | \ 73*57a8187dShastings 1 << IEEE80211_RADIOTAP_RATE | \ 74*57a8187dShastings 1 << IEEE80211_RADIOTAP_CHANNEL) 75*57a8187dShastings 76*57a8187dShastings struct mtw_softc; 77*57a8187dShastings 78*57a8187dShastings struct mtw_tx_data { 79*57a8187dShastings struct mtw_softc *sc; 80*57a8187dShastings struct usbd_xfer *xfer; 81*57a8187dShastings uint8_t *buf; 82*57a8187dShastings uint8_t qid; 83*57a8187dShastings }; 84*57a8187dShastings 85*57a8187dShastings struct mtw_rx_data { 86*57a8187dShastings struct mtw_softc *sc; 87*57a8187dShastings struct usbd_xfer *xfer; 88*57a8187dShastings uint8_t *buf; 89*57a8187dShastings }; 90*57a8187dShastings 91*57a8187dShastings struct mtw_tx_ring { 92*57a8187dShastings struct mtw_tx_data data[MTW_TX_RING_COUNT]; 93*57a8187dShastings struct usbd_pipe *pipeh; 94*57a8187dShastings int cur; 95*57a8187dShastings int queued; 96*57a8187dShastings uint8_t pipe_no; 97*57a8187dShastings }; 98*57a8187dShastings 99*57a8187dShastings struct mtw_rx_ring { 100*57a8187dShastings struct mtw_rx_data data[MTW_RX_RING_COUNT]; 101*57a8187dShastings struct usbd_pipe *pipeh; 102*57a8187dShastings uint8_t pipe_no; 103*57a8187dShastings }; 104*57a8187dShastings 105*57a8187dShastings struct mtw_host_cmd { 106*57a8187dShastings void (*cb)(struct mtw_softc *, void *); 107*57a8187dShastings uint8_t data[256]; 108*57a8187dShastings }; 109*57a8187dShastings 110*57a8187dShastings struct mtw_cmd_newstate { 111*57a8187dShastings enum ieee80211_state state; 112*57a8187dShastings int arg; 113*57a8187dShastings }; 114*57a8187dShastings 115*57a8187dShastings struct mtw_cmd_key { 116*57a8187dShastings struct ieee80211_key key; 117*57a8187dShastings struct ieee80211_node *ni; 118*57a8187dShastings }; 119*57a8187dShastings 120*57a8187dShastings #define MTW_HOST_CMD_RING_COUNT 32 121*57a8187dShastings struct mtw_host_cmd_ring { 122*57a8187dShastings struct mtw_host_cmd cmd[MTW_HOST_CMD_RING_COUNT]; 123*57a8187dShastings int cur; 124*57a8187dShastings int next; 125*57a8187dShastings int queued; 126*57a8187dShastings }; 127*57a8187dShastings 128*57a8187dShastings struct mtw_node { 129*57a8187dShastings struct ieee80211_node ni; 130*57a8187dShastings struct ieee80211_ra_node rn; 131*57a8187dShastings uint8_t ridx[IEEE80211_RATE_MAXSIZE]; 132*57a8187dShastings uint8_t ctl_ridx[IEEE80211_RATE_MAXSIZE]; 133*57a8187dShastings }; 134*57a8187dShastings 135*57a8187dShastings struct mtw_mcu_tx { 136*57a8187dShastings struct mtw_softc *sc; 137*57a8187dShastings struct usbd_xfer *xfer; 138*57a8187dShastings struct usbd_pipe *pipeh; 139*57a8187dShastings uint8_t pipe_no; 140*57a8187dShastings uint8_t *buf; 141*57a8187dShastings uint8_t seq; 142*57a8187dShastings }; 143*57a8187dShastings 144*57a8187dShastings #define MTW_MCU_IVB_LEN 0x40 145*57a8187dShastings struct mtw_ucode_hdr { 146*57a8187dShastings uint32_t ilm_len; 147*57a8187dShastings uint32_t dlm_len; 148*57a8187dShastings uint16_t build_ver; 149*57a8187dShastings uint16_t fw_ver; 150*57a8187dShastings uint8_t pad[4]; 151*57a8187dShastings char build_time[16]; 152*57a8187dShastings } __packed; 153*57a8187dShastings 154*57a8187dShastings struct mtw_ucode { 155*57a8187dShastings struct mtw_ucode_hdr hdr; 156*57a8187dShastings uint8_t ivb[MTW_MCU_IVB_LEN]; 157*57a8187dShastings uint8_t data[]; 158*57a8187dShastings } __packed; 159*57a8187dShastings 160*57a8187dShastings struct mtw_softc { 161*57a8187dShastings struct device sc_dev; 162*57a8187dShastings struct ieee80211com sc_ic; 163*57a8187dShastings int (*sc_newstate)(struct ieee80211com *, 164*57a8187dShastings enum ieee80211_state, int); 165*57a8187dShastings int (*sc_srom_read)(struct mtw_softc *, 166*57a8187dShastings uint16_t, uint16_t *); 167*57a8187dShastings 168*57a8187dShastings struct usbd_device *sc_udev; 169*57a8187dShastings struct usbd_interface *sc_iface; 170*57a8187dShastings 171*57a8187dShastings uint16_t asic_ver; 172*57a8187dShastings uint16_t asic_rev; 173*57a8187dShastings uint16_t mac_ver; 174*57a8187dShastings uint16_t mac_rev; 175*57a8187dShastings uint16_t rf_rev; 176*57a8187dShastings uint8_t freq; 177*57a8187dShastings uint8_t ntxchains; 178*57a8187dShastings uint8_t nrxchains; 179*57a8187dShastings int fixed_ridx; 180*57a8187dShastings 181*57a8187dShastings uint8_t rfswitch; 182*57a8187dShastings uint8_t ext_2ghz_lna; 183*57a8187dShastings uint8_t ext_5ghz_lna; 184*57a8187dShastings uint8_t calib_2ghz; 185*57a8187dShastings uint8_t calib_5ghz; 186*57a8187dShastings uint8_t txmixgain_2ghz; 187*57a8187dShastings uint8_t txmixgain_5ghz; 188*57a8187dShastings int8_t txpow1[54]; 189*57a8187dShastings int8_t txpow2[54]; 190*57a8187dShastings int8_t txpow3[54]; 191*57a8187dShastings int8_t rssi_2ghz[3]; 192*57a8187dShastings int8_t rssi_5ghz[3]; 193*57a8187dShastings uint8_t lna[4]; 194*57a8187dShastings 195*57a8187dShastings uint8_t leds; 196*57a8187dShastings uint16_t led[3]; 197*57a8187dShastings uint32_t txpow20mhz[5]; 198*57a8187dShastings uint32_t txpow40mhz_2ghz[5]; 199*57a8187dShastings uint32_t txpow40mhz_5ghz[5]; 200*57a8187dShastings 201*57a8187dShastings int8_t bbp_temp; 202*57a8187dShastings uint8_t rf_freq_offset; 203*57a8187dShastings uint32_t rf_pa_mode[2]; 204*57a8187dShastings int sc_rf_calibrated; 205*57a8187dShastings int sc_bw_calibrated; 206*57a8187dShastings int sc_chan_group; 207*57a8187dShastings 208*57a8187dShastings struct usb_task sc_task; 209*57a8187dShastings 210*57a8187dShastings struct ieee80211_amrr amrr; 211*57a8187dShastings struct ieee80211_amrr_node amn; 212*57a8187dShastings 213*57a8187dShastings struct timeout scan_to; 214*57a8187dShastings struct timeout calib_to; 215*57a8187dShastings 216*57a8187dShastings uint8_t cmd_seq; 217*57a8187dShastings 218*57a8187dShastings struct mtw_tx_ring sc_mcu; 219*57a8187dShastings struct mtw_rx_ring rxq[MTW_RXQ_COUNT]; 220*57a8187dShastings struct mtw_tx_ring txq[MTW_TXQ_COUNT]; 221*57a8187dShastings struct mtw_host_cmd_ring cmdq; 222*57a8187dShastings uint8_t qfullmsk; 223*57a8187dShastings int sc_tx_timer; 224*57a8187dShastings 225*57a8187dShastings #if NBPFILTER > 0 226*57a8187dShastings caddr_t sc_drvbpf; 227*57a8187dShastings 228*57a8187dShastings union { 229*57a8187dShastings struct mtw_rx_radiotap_header th; 230*57a8187dShastings uint8_t pad[64]; 231*57a8187dShastings } sc_rxtapu; 232*57a8187dShastings #define sc_rxtap sc_rxtapu.th 233*57a8187dShastings int sc_rxtap_len; 234*57a8187dShastings 235*57a8187dShastings union { 236*57a8187dShastings struct mtw_tx_radiotap_header th; 237*57a8187dShastings uint8_t pad[64]; 238*57a8187dShastings } sc_txtapu; 239*57a8187dShastings #define sc_txtap sc_txtapu.th 240*57a8187dShastings int sc_txtap_len; 241*57a8187dShastings #endif 242*57a8187dShastings int sc_key_tasks; 243*57a8187dShastings }; 244