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