Home | History | Annotate | Line # | Download | only in usb
      1 /*	$NetBSD: if_otusvar.h,v 1.12 2020/03/15 23:04:50 thorpej Exp $	*/
      2 /*	$OpenBSD: if_otusreg.h,v 1.6 2009/04/06 18:17:01 damien Exp $	*/
      3 
      4 /*-
      5  * Copyright (c) 2009 Damien Bergamini <damien.bergamini (at) free.fr>
      6  * Copyright (c) 2007-2008 Atheros Communications, Inc.
      7  *
      8  * Permission to use, copy, modify, and distribute this software for any
      9  * purpose with or without fee is hereby granted, provided that the above
     10  * copyright notice and this permission notice appear in all copies.
     11  *
     12  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
     13  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
     14  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
     15  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
     16  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
     17  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
     18  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
     19  */
     20 #ifndef _IF_OTUSVAR_H_
     21 #define _IF_OTUSVAR_H_
     22 
     23 #ifndef HAVE_EDCA
     24 /************************************************************
     25  * XXX: This block belongs in sys/net80211/ieee80211_var.h.
     26  */
     27 /*
     28  * EDCA AC parameters.
     29  */
     30 struct ieee80211_edca_ac_params {
     31 	uint8_t		ac_ecwmin;	/* CWmin = 2^ECWmin - 1 */
     32 	uint8_t		ac_ecwmax;	/* CWmax = 2^ECWmax - 1 */
     33 	uint8_t		ac_aifsn;
     34 	uint16_t	ac_txoplimit;	/* 32TU */
     35 	uint8_t		ac_acm;
     36 };
     37 /************************************************************/
     38 #endif /* ! HAVE_EDCA */
     39 
     40 /* Default EDCA parameters for when QoS is disabled. */
     41 static const struct ieee80211_edca_ac_params otus_edca_def[] = {
     42 	{ 4, 10, 3,  0, 0 },
     43 	{ 4, 10, 7,  0, 0 },
     44 	{ 3,  4, 2, 94, 0 },
     45 	{ 2,  3, 2, 47, 0 }
     46 };
     47 
     48 #define OTUS_TX_DATA_LIST_COUNT	8
     49 #define OTUS_RX_DATA_LIST_COUNT	1
     50 
     51 #define OTUS_CMD_TIMEOUT	1000
     52 #define OTUS_TX_TIMEOUT		1000
     53 
     54 #define OTUS_UID(aid)		(IEEE80211_AID(aid) + 4)
     55 
     56 #define OTUS_MAX_TXCMDSZ	64
     57 #define OTUS_RXBUFSZ		(8 * 1024)
     58 #define OTUS_TXBUFSZ		(4 * 1024)
     59 
     60 #define OTUS_RIDX_CCK1		 0
     61 #define OTUS_RIDX_OFDM6		 4
     62 #define OTUS_RIDX_OFDM24	 8
     63 #define OTUS_RIDX_MAX		11
     64 static const struct otus_rate {
     65 	uint8_t	rate;
     66 	uint8_t	mcs;
     67 } otus_rates[] = {
     68 	{   2, 0x0 },
     69 	{   4, 0x1 },
     70 	{  11, 0x2 },
     71 	{  22, 0x3 },
     72 	{  12, 0xb },
     73 	{  18, 0xf },
     74 	{  24, 0xa },
     75 	{  36, 0xe },
     76 	{  48, 0x9 },
     77 	{  72, 0xd },
     78 	{  96, 0x8 },
     79 	{ 108, 0xc }
     80 };
     81 
     82 struct otus_rx_radiotap_header {
     83 	struct ieee80211_radiotap_header wr_ihdr;
     84 	uint8_t		wr_flags;
     85 	uint8_t		wr_rate;
     86 	uint16_t	wr_chan_freq;
     87 	uint16_t	wr_chan_flags;
     88 	uint8_t		wr_antsignal;
     89 };
     90 
     91 #define OTUS_RX_RADIOTAP_PRESENT			\
     92 	(1 << IEEE80211_RADIOTAP_FLAGS |		\
     93 	 1 << IEEE80211_RADIOTAP_RATE |			\
     94 	 1 << IEEE80211_RADIOTAP_CHANNEL |		\
     95 	 1 << IEEE80211_RADIOTAP_DB_ANTSIGNAL)
     96 
     97 struct otus_tx_radiotap_header {
     98 	struct ieee80211_radiotap_header wt_ihdr;
     99 	uint8_t		wt_flags;
    100 	uint8_t		wt_rate;
    101 	uint16_t	wt_chan_freq;
    102 	uint16_t	wt_chan_flags;
    103 };
    104 
    105 #define OTUS_TX_RADIOTAP_PRESENT			\
    106 	(1 << IEEE80211_RADIOTAP_FLAGS |		\
    107 	 1 << IEEE80211_RADIOTAP_RATE |			\
    108 	 1 << IEEE80211_RADIOTAP_CHANNEL)
    109 
    110 
    111 struct otus_softc;
    112 
    113 struct otus_tx_cmd {
    114 	struct usbd_xfer	*xfer;
    115 	uint8_t			*buf;
    116 	void			*odata;
    117 	uint16_t		token;
    118 	uint8_t			done;
    119 };
    120 
    121 struct otus_rx_data {
    122 	struct otus_softc	*sc;
    123 	struct usbd_xfer	*xfer;
    124 	uint8_t			*buf;
    125 };
    126 
    127 struct otus_tx_data {
    128 	struct otus_softc		*sc;
    129 	struct usbd_xfer		*xfer;
    130 	uint8_t				*buf;
    131 	TAILQ_ENTRY(otus_tx_data)	next;
    132 };
    133 
    134 struct otus_host_cmd {
    135 	void	(*cb)(struct otus_softc *, void *);
    136 	uint8_t	data[256];
    137 };
    138 
    139 #define OTUS_HOST_CMD_RING_COUNT	32
    140 struct otus_host_cmd_ring {
    141 	struct otus_host_cmd	cmd[OTUS_HOST_CMD_RING_COUNT];
    142 	int			cur;
    143 	int			next;
    144 	int			queued;
    145 };
    146 
    147 struct otus_node {
    148 	struct ieee80211_node		ni;	/* must be first */
    149 	struct ieee80211_amrr_node	amn;
    150 	uint8_t				ridx[IEEE80211_RATE_MAXSIZE];
    151 };
    152 
    153 struct otus_cmd_newstate {
    154 	enum ieee80211_state	state;
    155 	int			arg;
    156 };
    157 
    158 struct otus_cmd_key {
    159 	struct ieee80211_key	key;
    160 	uint16_t		associd;
    161 };
    162 
    163 struct otus_softc {
    164 	device_t			sc_dev;
    165 	struct ieee80211com		sc_ic;
    166 	struct ethercom			sc_ec;
    167 #define sc_if	sc_ec.ec_if
    168 	int				(*sc_newstate)(struct ieee80211com *,
    169 					    enum ieee80211_state, int);
    170 	void				(*sc_led_newstate)(struct otus_softc *);
    171 
    172 	struct usbd_device *		sc_udev;
    173 	struct usbd_interface *		sc_iface;
    174 
    175 	struct ar5416eeprom		sc_eeprom;
    176 	uint8_t				sc_capflags;
    177 	uint8_t				sc_rxmask;
    178 	uint8_t				sc_txmask;
    179 
    180 	struct usbd_pipe *		sc_data_tx_pipe;
    181 	struct usbd_pipe *		sc_data_rx_pipe;
    182 	struct usbd_pipe *		sc_cmd_tx_pipe;
    183 	struct usbd_pipe *		sc_cmd_rx_pipe;
    184 	uint8_t 			*sc_ibuf;
    185 	size_t				sc_ibuf_size;
    186 
    187 	unsigned short			sc_if_flags;
    188 	int				sc_tx_timer;
    189 	int				sc_fixed_ridx;
    190 	int				sc_bb_reset;
    191 
    192 	struct ieee80211_channel	*sc_curchan;
    193 
    194 	struct usb_task			sc_task;
    195 	callout_t			sc_scan_to;
    196 	callout_t			sc_calib_to;
    197 	struct ieee80211_amrr		sc_amrr;
    198 
    199 	unsigned int			sc_write_idx;
    200 	uint32_t			sc_led_state;
    201 
    202 	kcondvar_t			sc_task_cv;
    203 	kcondvar_t			sc_cmd_cv;
    204 	kmutex_t			sc_cmd_mtx;
    205 	kmutex_t			sc_task_mtx;
    206 	kmutex_t			sc_write_mtx;
    207 	kmutex_t			sc_tx_mtx;
    208 	kmutex_t			sc_media_mtx;	/* XXX */
    209 
    210 	const uint32_t			*sc_phy_vals;
    211 
    212 	struct {
    213 		uint32_t	reg;
    214 		uint32_t	val;
    215 	} __packed			sc_write_buf[AR_FW_MAX_WRITES];
    216 
    217 	struct otus_host_cmd_ring	sc_cmdq;
    218 	struct otus_tx_cmd		sc_tx_cmd;
    219 	struct otus_tx_data		sc_tx_data[OTUS_TX_DATA_LIST_COUNT];
    220 	TAILQ_HEAD(, otus_tx_data)	sc_tx_free_list;
    221 	struct otus_rx_data		sc_rx_data[OTUS_RX_DATA_LIST_COUNT];
    222 
    223 	struct bpf_if *			sc_drvbpf;
    224 	union {
    225 		struct otus_rx_radiotap_header th;
    226 		uint8_t	pad[64];
    227 	}				sc_rxtapu;
    228 #define sc_rxtap	sc_rxtapu.th
    229 	int				sc_rxtap_len;
    230 	union {
    231 		struct otus_tx_radiotap_header th;
    232 		uint8_t	pad[64];
    233 	}				sc_txtapu;
    234 #define sc_txtap	sc_txtapu.th
    235 	int				sc_txtap_len;
    236 
    237 	uint8_t				sc_rx_error_msk;
    238 	int				sc_dying;
    239 };
    240 
    241 #endif /* _IF_OTUSVAR_H_ */
    242