Home | History | Annotate | Line # | Download | only in usb
if_urtwnvar.h revision 1.10.16.6
      1 /*	$NetBSD: if_urtwnvar.h,v 1.10.16.6 2020/04/16 15:32:24 nat 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 #include <sys/rndsource.h>
     23 
     24 /*
     25  * Driver definitions.
     26  */
     27 #define URTWN_RX_LIST_COUNT		1
     28 #define URTWN_TX_LIST_COUNT		8
     29 
     30 #define URTWN_HOST_CMD_RING_COUNT	32
     31 
     32 #define URTWN_RXBUFSZ	(16 * 1024)
     33 #define URTWN_TXBUFSZ	(sizeof(struct r92c_tx_desc_usb) + IEEE80211_MAX_LEN + 8)
     34 
     35 #define URTWN_RIDX_COUNT	28
     36 
     37 #define URTWN_TX_TIMEOUT	5000	/* ms */
     38 
     39 #define URTWN_LED_LINK	0
     40 #define URTWN_LED_DATA	1
     41 
     42 struct urtwn_rx_radiotap_header {
     43 	struct ieee80211_radiotap_header wr_ihdr;
     44 	uint8_t		wr_flags;
     45 	uint8_t		wr_rate;
     46 	uint16_t	wr_chan_freq;
     47 	uint16_t	wr_chan_flags;
     48 	uint8_t		wr_dbm_antsignal;
     49 };
     50 
     51 #define URTWN_RX_RADIOTAP_PRESENT			\
     52 	(1 << IEEE80211_RADIOTAP_FLAGS |		\
     53 	 1 << IEEE80211_RADIOTAP_RATE |			\
     54 	 1 << IEEE80211_RADIOTAP_CHANNEL |		\
     55 	 1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL)
     56 
     57 struct urtwn_tx_radiotap_header {
     58 	struct ieee80211_radiotap_header wt_ihdr;
     59 	uint8_t		wt_flags;
     60 	uint16_t	wt_chan_freq;
     61 	uint16_t	wt_chan_flags;
     62 };
     63 
     64 #define URTWN_TX_RADIOTAP_PRESENT			\
     65 	(1 << IEEE80211_RADIOTAP_FLAGS |		\
     66 	 1 << IEEE80211_RADIOTAP_CHANNEL)
     67 
     68 struct urtwn_softc;
     69 
     70 struct urtwn_rx_data {
     71 	struct urtwn_softc		*sc;
     72 	size_t				pidx;
     73 	struct usbd_xfer		*xfer;
     74 	uint8_t				*buf;
     75 	TAILQ_ENTRY(urtwn_rx_data)	next;
     76 };
     77 
     78 struct urtwn_tx_data {
     79 	struct urtwn_softc		*sc;
     80 	size_t				pidx;
     81 	struct usbd_xfer		*xfer;
     82 	uint8_t				*buf;
     83 	TAILQ_ENTRY(urtwn_tx_data)	next;
     84 };
     85 
     86 struct urtwn_host_cmd {
     87 	void	(*cb)(struct urtwn_softc *, void *);
     88 	uint8_t	data[256];
     89 };
     90 
     91 struct urtwn_cmd_newstate {
     92 	enum ieee80211_state	state;
     93 	int			arg;
     94 };
     95 
     96 struct urtwn_host_cmd_ring {
     97 	struct urtwn_host_cmd	cmd[URTWN_HOST_CMD_RING_COUNT];
     98 	int			cur;
     99 	int			next;
    100 	int			queued;
    101 };
    102 
    103 #if 1	/* XXX: sys/net80211/ieee80211.h */
    104 
    105 #define	IEEE80211_HTINFO_2NDCHAN	0x03	/* secondary/ext chan offset */
    106 #define	IEEE80211_HTINFO_2NDCHAN_S	0
    107 #define	IEEE80211_HTINFO_2NDCHAN_NONE	0x00	/* no secondary/ext channel */
    108 #define	IEEE80211_HTINFO_2NDCHAN_ABOVE	0x01	/* above private channel */
    109 /* NB: 2 is reserved */
    110 #define	IEEE80211_HTINFO_2NDCHAN_BELOW	0x03	/* below primary channel */
    111 #endif	/* XXX: 1 */
    112 
    113 struct urtwn_softc {
    114 	device_t			sc_dev;
    115 	struct ieee80211com		sc_ic;
    116 	struct ifqueue			sc_sendq;
    117 	int				(*sc_newstate)(struct ieee80211vap *,
    118 					    enum ieee80211_state, int);
    119 
    120 	struct usbd_device *		sc_udev;
    121 	struct usbd_interface *		sc_iface;
    122 	u_int				sc_flags;
    123 #define URTWN_FLAG_CCK_HIPWR	__BIT(0)
    124 #define	URTWN_FLAG_ATTACHED	__BIT(1)
    125 #define	URTWN_FLAG_FWREADY	__BIT(2)
    126 	int				sc_dying;
    127 
    128 	struct usb_task			sc_task;
    129 	callout_t			sc_scan_to;
    130 	callout_t			sc_calib_to;
    131 
    132 	kcondvar_t			sc_task_cv;
    133 	kmutex_t			sc_task_mtx;
    134 	kmutex_t			sc_fwcmd_mtx;
    135 	kmutex_t			sc_tx_mtx;
    136 	kmutex_t			sc_rx_mtx;
    137 	kmutex_t			sc_write_mtx;
    138 	kmutex_t			sc_media_mtx;	/* XXX */
    139 
    140 	struct usbd_pipe *		rx_pipe[R92C_MAX_EPIN];
    141 	int				rx_npipe;
    142 	struct usbd_pipe *		tx_pipe[R92C_MAX_EPOUT];
    143 	int				tx_npipe;
    144 	int				ac2idx[WME_NUM_AC];
    145 
    146 	u_int				chip;
    147 #define URTWN_CHIP_92C		0x01
    148 #define URTWN_CHIP_92C_1T2R	0x02
    149 #define URTWN_CHIP_UMC		0x04
    150 #define URTWN_CHIP_UMC_A_CUT	0x08
    151 #define URTWN_CHIP_88E		0x10
    152 #define URTWN_CHIP_92EU		0x20
    153 
    154 	void				(*sc_rf_write)(struct urtwn_softc *,
    155 					    int, uint8_t, uint32_t);
    156 	int				(*sc_power_on)(struct urtwn_softc *);
    157 	int				(*sc_dma_init)(struct urtwn_softc *);
    158 
    159 	uint8_t				board_type;
    160 	uint8_t				regulatory;
    161 	uint8_t				pa_setting;
    162 	int				avg_pwdb;
    163 	int				thcal_state;
    164 	int				thcal_lctemp;
    165 	size_t				ntxchains;
    166 	size_t				nrxchains;
    167 	int				ledlink;
    168 	bool				iqk_inited;
    169 
    170 	int				tx_timer;
    171 
    172 	struct urtwn_host_cmd_ring	cmdq;
    173 	int				fwcur;
    174 	struct urtwn_rx_data		rx_data[R92C_MAX_EPIN][URTWN_RX_LIST_COUNT];
    175 	struct urtwn_tx_data		tx_data[R92C_MAX_EPOUT][URTWN_TX_LIST_COUNT];
    176 	TAILQ_HEAD(, urtwn_tx_data)	tx_free_list[R92C_MAX_EPOUT];
    177 	TAILQ_HEAD(, urtwn_rx_data)	rx_free_list[R92C_MAX_EPIN];
    178 
    179 	struct r92c_rom			rom;
    180 	uint8_t				r88e_rom[4096];
    181 	uint8_t				cck_tx_pwr[6];
    182 	uint8_t				ht40_tx_pwr[5];
    183 	int8_t				bw20_tx_pwr_diff;
    184 	int8_t				ofdm_tx_pwr_diff;
    185 
    186 	uint32_t			rf_chnlbw[R92C_MAX_CHAINS];
    187 
    188 	struct bpf_if *			sc_drvbpf;
    189 	union {
    190 		struct urtwn_rx_radiotap_header th;
    191 		uint8_t	pad[64];
    192 	}				sc_rxtapu;
    193 #define sc_rxtap	sc_rxtapu.th
    194 	int				sc_rxtap_len;
    195 	union {
    196 		struct urtwn_tx_radiotap_header th;
    197 		uint8_t	pad[64];
    198 	}				sc_txtapu;
    199 #define sc_txtap	sc_txtapu.th
    200 	int				sc_txtap_len;
    201 	bool				sc_running;
    202 
    203 	struct ieee80211_beacon_offsets sc_bo;
    204 	krndsource_t rnd_source;	/* random source */
    205 };
    206 
    207 #endif /* _IF_URTWNVAR_H_ */
    208