Home | History | Annotate | Line # | Download | only in usb
if_otusvar.h revision 1.4
      1 /*	$NetBSD: if_otusvar.h,v 1.4 2013/01/20 21:50:41 christos 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 #ifdef EDCA_NUM_AC
     24 #define HAVE_EDCA
     25 #endif
     26 
     27 #ifndef HAVE_EDCA
     28 /************************************************************
     29  * XXX: This block belongs in sys/net80211/ieee80211_var.h.
     30  */
     31 /*
     32  * EDCA AC parameters.
     33  */
     34 struct ieee80211_edca_ac_params {
     35 	u_int8_t	ac_ecwmin;	/* CWmin = 2^ECWmin - 1 */
     36 	u_int8_t	ac_ecwmax;	/* CWmax = 2^ECWmax - 1 */
     37 	u_int8_t	ac_aifsn;
     38 	u_int16_t	ac_txoplimit;	/* 32TU */
     39 	u_int8_t	ac_acm;
     40 };
     41 /************************************************************/
     42 #endif /* ! HAVE_EDCA */
     43 
     44 #ifndef HAVE_EDCA
     45 /************************************************************
     46  * XXX: This block belongs in sys/net80211/ieee80211.h.
     47  */
     48 
     49 /*
     50  * EDCA Access Categories.
     51  */
     52 enum ieee80211_edca_ac {
     53 	EDCA_AC_BK  = 1,	/* Background */
     54 	EDCA_AC_BE  = 0,	/* Best Effort */
     55 	EDCA_AC_VI  = 2,	/* Video */
     56 	EDCA_AC_VO  = 3		/* Voice */
     57 };
     58 #define EDCA_NUM_AC	4
     59 
     60 /* XXX: OpenBSD has more of these defined with the standard referenced */
     61 #define IEEE80211_QOS_ACK_POLICY_NOACK		0x0020
     62 #define IEEE80211_QOS_ACK_POLICY_MASK		0x0060
     63 
     64 static __inline int
     65 ieee80211_has_addr4(const struct ieee80211_frame *wh)
     66 {
     67 	return (wh->i_fc[1] & IEEE80211_FC1_DIR_MASK) ==
     68 	    IEEE80211_FC1_DIR_DSTODS;
     69 }
     70 
     71 static __inline int
     72 ieee80211_has_qos(const struct ieee80211_frame *wh)
     73 {
     74 	return (wh->i_fc[0] &
     75 	    (IEEE80211_FC0_TYPE_MASK | IEEE80211_FC0_SUBTYPE_QOS)) ==
     76 	    (IEEE80211_FC0_TYPE_DATA | IEEE80211_FC0_SUBTYPE_QOS);
     77 }
     78 
     79 static __inline u_int16_t
     80 ieee80211_get_qos(const struct ieee80211_frame *wh)
     81 {
     82 	const u_int8_t *frm;
     83 
     84 	if (ieee80211_has_addr4(wh))
     85 		frm = ((const struct ieee80211_qosframe_addr4 *)wh)->i_qos;
     86 	else
     87 		frm = ((const struct ieee80211_qosframe *)wh)->i_qos;
     88 
     89 	return le16toh(*(const u_int16_t *)frm);
     90 }
     91 /************************************************************/
     92 #endif /* ! HAVE_EDCA */
     93 
     94 /* Default EDCA parameters for when QoS is disabled. */
     95 static const struct ieee80211_edca_ac_params otus_edca_def[] = {
     96 	{ 4, 10, 3,  0, 0 },
     97 	{ 4, 10, 7,  0, 0 },
     98 	{ 3,  4, 2, 94, 0 },
     99 	{ 2,  3, 2, 47, 0 }
    100 };
    101 
    102 #define OTUS_TX_DATA_LIST_COUNT	8
    103 #define OTUS_RX_DATA_LIST_COUNT	1
    104 
    105 #define OTUS_CMD_TIMEOUT	1000
    106 #define OTUS_TX_TIMEOUT		1000
    107 
    108 #define OTUS_UID(aid)		(IEEE80211_AID(aid) + 4)
    109 
    110 #define OTUS_MAX_TXCMDSZ	64
    111 #define OTUS_RXBUFSZ		(8 * 1024)
    112 #define OTUS_TXBUFSZ		(4 * 1024)
    113 
    114 #define OTUS_RIDX_CCK1		 0
    115 #define OTUS_RIDX_OFDM6		 4
    116 #define OTUS_RIDX_OFDM24	 8
    117 #define OTUS_RIDX_MAX		11
    118 static const struct otus_rate {
    119 	uint8_t	rate;
    120 	uint8_t	mcs;
    121 } otus_rates[] = {
    122 	{   2, 0x0 },
    123 	{   4, 0x1 },
    124 	{  11, 0x2 },
    125 	{  22, 0x3 },
    126 	{  12, 0xb },
    127 	{  18, 0xf },
    128 	{  24, 0xa },
    129 	{  36, 0xe },
    130 	{  48, 0x9 },
    131 	{  72, 0xd },
    132 	{  96, 0x8 },
    133 	{ 108, 0xc }
    134 };
    135 
    136 struct otus_rx_radiotap_header {
    137 	struct ieee80211_radiotap_header wr_ihdr;
    138 	uint8_t		wr_flags;
    139 	uint8_t		wr_rate;
    140 	uint16_t	wr_chan_freq;
    141 	uint16_t	wr_chan_flags;
    142 	uint8_t		wr_antsignal;
    143 } __packed;
    144 
    145 #define OTUS_RX_RADIOTAP_PRESENT			\
    146 	(1 << IEEE80211_RADIOTAP_FLAGS |		\
    147 	 1 << IEEE80211_RADIOTAP_RATE |			\
    148 	 1 << IEEE80211_RADIOTAP_CHANNEL |		\
    149 	 1 << IEEE80211_RADIOTAP_DB_ANTSIGNAL)
    150 
    151 struct otus_tx_radiotap_header {
    152 	struct ieee80211_radiotap_header wt_ihdr;
    153 	uint8_t		wt_flags;
    154 	uint8_t		wt_rate;
    155 	uint16_t	wt_chan_freq;
    156 	uint16_t	wt_chan_flags;
    157 } __packed;
    158 
    159 #define OTUS_TX_RADIOTAP_PRESENT			\
    160 	(1 << IEEE80211_RADIOTAP_FLAGS |		\
    161 	 1 << IEEE80211_RADIOTAP_RATE |			\
    162 	 1 << IEEE80211_RADIOTAP_CHANNEL)
    163 
    164 
    165 struct otus_softc;
    166 
    167 struct otus_tx_cmd {
    168 	usbd_xfer_handle	xfer;
    169 	uint8_t			*buf;
    170 	void			*odata;
    171 	uint16_t		token;
    172 	uint8_t			done;
    173 };
    174 
    175 struct otus_rx_data {
    176 	struct otus_softc	*sc;
    177 	usbd_xfer_handle	xfer;
    178 	uint8_t			*buf;
    179 };
    180 
    181 struct otus_tx_data {
    182 	struct otus_softc		*sc;
    183 	usbd_xfer_handle		xfer;
    184 	uint8_t				*buf;
    185 	TAILQ_ENTRY(otus_tx_data)	next;
    186 };
    187 
    188 struct otus_host_cmd {
    189 	void	(*cb)(struct otus_softc *, void *);
    190 	uint8_t	data[256];
    191 };
    192 
    193 #define OTUS_HOST_CMD_RING_COUNT	32
    194 struct otus_host_cmd_ring {
    195 	struct otus_host_cmd	cmd[OTUS_HOST_CMD_RING_COUNT];
    196 	int			cur;
    197 	int			next;
    198 	int			queued;
    199 };
    200 
    201 struct otus_node {
    202 	struct ieee80211_node		ni;	/* must be first */
    203 	struct ieee80211_amrr_node	amn;
    204 	uint8_t				ridx[IEEE80211_RATE_MAXSIZE];
    205 };
    206 
    207 struct otus_cmd_newstate {
    208 	enum ieee80211_state	state;
    209 	int			arg;
    210 };
    211 
    212 struct otus_cmd_key {
    213 	struct ieee80211_key	key;
    214 	uint16_t		associd;
    215 };
    216 
    217 struct otus_softc {
    218 	device_t			sc_dev;
    219 	struct ieee80211com		sc_ic;
    220 	struct ethercom			sc_ec;
    221 #define sc_if	sc_ec.ec_if
    222 	int				(*sc_newstate)(struct ieee80211com *,
    223 					    enum ieee80211_state, int);
    224 	void				(*sc_led_newstate)(struct otus_softc *);
    225 
    226 	usbd_device_handle		sc_udev;
    227 	usbd_interface_handle		sc_iface;
    228 
    229 	struct ar5416eeprom		sc_eeprom;
    230 	uint8_t				sc_capflags;
    231 	uint8_t				sc_rxmask;
    232 	uint8_t				sc_txmask;
    233 
    234 	usbd_pipe_handle		sc_data_tx_pipe;
    235 	usbd_pipe_handle		sc_data_rx_pipe;
    236 	usbd_pipe_handle		sc_cmd_tx_pipe;
    237 	usbd_pipe_handle		sc_cmd_rx_pipe;
    238 	uint8_t 			*sc_ibuf;
    239 
    240 	int				sc_if_flags;
    241 	int				sc_tx_timer;
    242 	int				sc_fixed_ridx;
    243 	int				sc_bb_reset;
    244 
    245 	struct ieee80211_channel	*sc_curchan;
    246 
    247 	struct usb_task			sc_task;
    248 	callout_t			sc_scan_to;
    249 	callout_t			sc_calib_to;
    250 	struct ieee80211_amrr		sc_amrr;
    251 
    252 	unsigned int			sc_write_idx;
    253 	uint32_t			sc_led_state;
    254 
    255 	kmutex_t			sc_cmd_mtx;
    256 	kmutex_t			sc_task_mtx;
    257 	kmutex_t			sc_write_mtx;
    258 	kmutex_t			sc_tx_mtx;
    259 
    260 	const uint32_t			*sc_phy_vals;
    261 
    262 	struct {
    263 		uint32_t	reg;
    264 		uint32_t	val;
    265 	} __packed			sc_write_buf[AR_FW_MAX_WRITES];
    266 
    267 	struct otus_host_cmd_ring	sc_cmdq;
    268 	struct otus_tx_cmd		sc_tx_cmd;
    269 	struct otus_tx_data		sc_tx_data[OTUS_TX_DATA_LIST_COUNT];
    270 	TAILQ_HEAD(, otus_tx_data)	sc_tx_free_list;
    271 	struct otus_rx_data		sc_rx_data[OTUS_RX_DATA_LIST_COUNT];
    272 
    273 	struct bpf_if *			sc_drvbpf;
    274 	union {
    275 		struct otus_rx_radiotap_header th;
    276 		uint8_t	pad[64];
    277 	}				sc_rxtapu;
    278 #define sc_rxtap	sc_rxtapu.th
    279 	int				sc_rxtap_len;
    280 	union {
    281 		struct otus_tx_radiotap_header th;
    282 		uint8_t	pad[64];
    283 	}				sc_txtapu;
    284 #define sc_txtap	sc_txtapu.th
    285 	int				sc_txtap_len;
    286 
    287 	uint8_t				sc_rx_error_msk;
    288 	int				sc_dying;
    289 
    290 #if IEEE80211_INJECTION	/* XXX: ljt */
    291 	int	(*sc_if_output)		/* ether output routine */
    292 		    (struct ifnet *, struct mbuf *, const struct sockaddr *,
    293 		    struct rtentry *);
    294 #endif
    295 };
    296 
    297 #endif /* _IF_OTUSVAR_H_ */
    298 
    299