Home | History | Annotate | Line # | Download | only in usb
if_urtwnvar.h revision 1.9
      1 /*	$NetBSD: if_urtwnvar.h,v 1.9 2016/04/23 10:15:32 skrll Exp $	*/
      2 /*	$OpenBSD: if_urtwnreg.h,v 1.3 2010/11/16 18:02:59 damien Exp $	*/
      3 
      4 /*-
      5  * Copyright (c) 2010 Damien Bergamini <damien.bergamini (at) free.fr>
      6  *
      7  * Permission to use, copy, modify, and distribute this software for any
      8  * purpose with or without fee is hereby granted, provided that the above
      9  * copyright notice and this permission notice appear in all copies.
     10  *
     11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
     12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
     13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
     14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
     15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
     16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
     17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
     18  */
     19 #ifndef _IF_URTWNVAR_H_
     20 #define _IF_URTWNVAR_H_
     21 
     22 /*
     23  * Driver definitions.
     24  */
     25 #define URTWN_RX_LIST_COUNT		1
     26 #define URTWN_TX_LIST_COUNT		8
     27 
     28 #define URTWN_HOST_CMD_RING_COUNT	32
     29 
     30 #define URTWN_RXBUFSZ	(16 * 1024)
     31 #define URTWN_TXBUFSZ	(sizeof(struct r92c_tx_desc) + IEEE80211_MAX_LEN + 8)
     32 
     33 #define URTWN_RIDX_COUNT	28
     34 
     35 #define URTWN_TX_TIMEOUT	5000	/* ms */
     36 
     37 #define URTWN_LED_LINK	0
     38 #define URTWN_LED_DATA	1
     39 
     40 struct urtwn_rx_radiotap_header {
     41 	struct ieee80211_radiotap_header wr_ihdr;
     42 	uint8_t		wr_flags;
     43 	uint8_t		wr_rate;
     44 	uint16_t	wr_chan_freq;
     45 	uint16_t	wr_chan_flags;
     46 	uint8_t		wr_dbm_antsignal;
     47 } __packed;
     48 
     49 #define URTWN_RX_RADIOTAP_PRESENT			\
     50 	(1 << IEEE80211_RADIOTAP_FLAGS |		\
     51 	 1 << IEEE80211_RADIOTAP_RATE |			\
     52 	 1 << IEEE80211_RADIOTAP_CHANNEL |		\
     53 	 1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL)
     54 
     55 struct urtwn_tx_radiotap_header {
     56 	struct ieee80211_radiotap_header wt_ihdr;
     57 	uint8_t		wt_flags;
     58 	uint16_t	wt_chan_freq;
     59 	uint16_t	wt_chan_flags;
     60 } __packed;
     61 
     62 #define URTWN_TX_RADIOTAP_PRESENT			\
     63 	(1 << IEEE80211_RADIOTAP_FLAGS |		\
     64 	 1 << IEEE80211_RADIOTAP_CHANNEL)
     65 
     66 struct urtwn_softc;
     67 
     68 struct urtwn_rx_data {
     69 	struct urtwn_softc	*sc;
     70 	struct usbd_xfer	*xfer;
     71 	uint8_t			*buf;
     72 };
     73 
     74 struct urtwn_tx_data {
     75 	struct urtwn_softc		*sc;
     76 	size_t				pidx;
     77 	struct usbd_xfer		*xfer;
     78 	uint8_t				*buf;
     79 	TAILQ_ENTRY(urtwn_tx_data)	next;
     80 };
     81 
     82 struct urtwn_host_cmd {
     83 	void	(*cb)(struct urtwn_softc *, void *);
     84 	uint8_t	data[256];
     85 };
     86 
     87 struct urtwn_cmd_newstate {
     88 	enum ieee80211_state	state;
     89 	int			arg;
     90 };
     91 
     92 struct urtwn_host_cmd_ring {
     93 	struct urtwn_host_cmd	cmd[URTWN_HOST_CMD_RING_COUNT];
     94 	int			cur;
     95 	int			next;
     96 	int			queued;
     97 };
     98 
     99 #if 1	/* XXX: sys/net80211/ieee80211.h */
    100 
    101 #define	IEEE80211_HTINFO_2NDCHAN	0x03	/* secondary/ext chan offset */
    102 #define	IEEE80211_HTINFO_2NDCHAN_S	0
    103 #define	IEEE80211_HTINFO_2NDCHAN_NONE	0x00	/* no secondary/ext channel */
    104 #define	IEEE80211_HTINFO_2NDCHAN_ABOVE	0x01	/* above private channel */
    105 /* NB: 2 is reserved */
    106 #define	IEEE80211_HTINFO_2NDCHAN_BELOW	0x03	/* below primary channel */
    107 #endif	/* XXX: 1 */
    108 
    109 struct urtwn_softc {
    110 	device_t			sc_dev;
    111 	struct ieee80211com		sc_ic;
    112 	struct ethercom			sc_ec;
    113 #define sc_if   sc_ec.ec_if
    114 	int				(*sc_newstate)(struct ieee80211com *,
    115 					    enum ieee80211_state, int);
    116 
    117 	struct usbd_device *		sc_udev;
    118 	struct usbd_interface *		sc_iface;
    119 	u_int				sc_flags;
    120 #define URTWN_FLAG_CCK_HIPWR	__BIT(0)
    121 #define	URTWN_FLAG_ATTACHED	__BIT(1)
    122 #define	URTWN_FLAG_FWREADY	__BIT(2)
    123 	int				sc_dying;
    124 
    125 	struct usb_task			sc_task;
    126 	callout_t			sc_scan_to;
    127 	callout_t			sc_calib_to;
    128 
    129 	kmutex_t			sc_task_mtx;
    130 	kmutex_t			sc_fwcmd_mtx;
    131 	kmutex_t			sc_tx_mtx;
    132 	kmutex_t			sc_write_mtx;
    133 
    134 	struct usbd_pipe *		rx_pipe;
    135 	int				rx_npipe;
    136 	struct usbd_pipe *		tx_pipe[R92C_MAX_EPOUT];
    137 	int				tx_npipe;
    138 	int				ac2idx[WME_NUM_AC];
    139 
    140 	u_int				chip;
    141 #define URTWN_CHIP_92C		0x01
    142 #define URTWN_CHIP_92C_1T2R	0x02
    143 #define URTWN_CHIP_UMC		0x04
    144 #define URTWN_CHIP_UMC_A_CUT	0x08
    145 #define URTWN_CHIP_88E		0x10
    146 
    147 	void				(*sc_rf_write)(struct urtwn_softc *,
    148 					    int, uint8_t, uint32_t);
    149 	int				(*sc_power_on)(struct urtwn_softc *);
    150 	int				(*sc_dma_init)(struct urtwn_softc *);
    151 
    152 	uint8_t				board_type;
    153 	uint8_t				regulatory;
    154 	uint8_t				pa_setting;
    155 	int				avg_pwdb;
    156 	int				thcal_state;
    157 	int				thcal_lctemp;
    158 	size_t				ntxchains;
    159 	size_t				nrxchains;
    160 	int				ledlink;
    161 	bool				iqk_inited;
    162 
    163 	int				tx_timer;
    164 
    165 	struct urtwn_host_cmd_ring	cmdq;
    166 	int				fwcur;
    167 	struct urtwn_rx_data		rx_data[URTWN_RX_LIST_COUNT];
    168 	struct urtwn_tx_data		tx_data[R92C_MAX_EPOUT][URTWN_TX_LIST_COUNT];
    169 	TAILQ_HEAD(, urtwn_tx_data)	tx_free_list[R92C_MAX_EPOUT];
    170 
    171 	struct r92c_rom			rom;
    172 	uint8_t				r88e_rom[512];
    173 	uint8_t				cck_tx_pwr[6];
    174 	uint8_t				ht40_tx_pwr[5];
    175 	int8_t				bw20_tx_pwr_diff;
    176 	int8_t				ofdm_tx_pwr_diff;
    177 
    178 	uint32_t			rf_chnlbw[R92C_MAX_CHAINS];
    179 
    180 	struct bpf_if *			sc_drvbpf;
    181 	union {
    182 		struct urtwn_rx_radiotap_header th;
    183 		uint8_t	pad[64];
    184 	}				sc_rxtapu;
    185 #define sc_rxtap	sc_rxtapu.th
    186 	int				sc_rxtap_len;
    187 	union {
    188 		struct urtwn_tx_radiotap_header th;
    189 		uint8_t	pad[64];
    190 	}				sc_txtapu;
    191 #define sc_txtap	sc_txtapu.th
    192 	int				sc_txtap_len;
    193 };
    194 
    195 #endif /* _IF_URTWNVAR_H_ */
    196