Home | History | Annotate | Line # | Download | only in pci
if_iwnvar.h revision 1.6
      1 /*	$OpenBSD: if_iwnvar.h,v 1.8 2008/12/03 17:17:08 damien Exp $	*/
      2 /*	$NetBSD: if_iwnvar.h,v 1.6 2009/09/11 01:28:20 christos Exp $	*/
      3 
      4 /*-
      5  * Copyright (c) 2007, 2008
      6  *	Damien Bergamini <damien.bergamini (at) free.fr>
      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 
     21 #define IEEE80211_NO_HT
     22 
     23 struct iwn_rx_radiotap_header {
     24 	struct ieee80211_radiotap_header wr_ihdr;
     25 	uint64_t	wr_tsft;
     26 	uint8_t		wr_flags;
     27 	uint8_t		wr_rate;
     28 	uint16_t	wr_chan_freq;
     29 	uint16_t	wr_chan_flags;
     30 	int8_t		wr_dbm_antsignal;
     31 	int8_t		wr_dbm_antnoise;
     32 } __packed;
     33 
     34 #define IWN_RX_RADIOTAP_PRESENT						\
     35 	((1 << IEEE80211_RADIOTAP_TSFT) |				\
     36 	 (1 << IEEE80211_RADIOTAP_FLAGS) |				\
     37 	 (1 << IEEE80211_RADIOTAP_RATE) |				\
     38 	 (1 << IEEE80211_RADIOTAP_CHANNEL) |				\
     39 	 (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) |			\
     40 	 (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE))
     41 
     42 struct iwn_tx_radiotap_header {
     43 	struct ieee80211_radiotap_header wt_ihdr;
     44 	uint8_t		wt_flags;
     45 	uint8_t		wt_rate;
     46 	uint16_t	wt_chan_freq;
     47 	uint16_t	wt_chan_flags;
     48 	uint8_t		wt_hwqueue;
     49 } __packed;
     50 
     51 #define IWN_TX_RADIOTAP_PRESENT                                      \
     52         ((1 << IEEE80211_RADIOTAP_FLAGS) |                           \
     53 	 (1 << IEEE80211_RADIOTAP_RATE) |                            \
     54 	 (1 << IEEE80211_RADIOTAP_CHANNEL))
     55 
     56 struct iwn_dma_info {
     57 	bus_dma_tag_t		tag;
     58 	bus_dmamap_t		map;
     59 	bus_dma_segment_t	seg;
     60 	bus_addr_t		paddr;
     61 	void *			vaddr;
     62 	bus_size_t		size;
     63 };
     64 
     65 struct iwn_tx_data {
     66 	bus_dmamap_t		map;
     67 	bus_addr_t		cmd_paddr;
     68 	bus_addr_t		scratch_paddr;
     69 	struct mbuf		*m;
     70 	struct ieee80211_node	*ni;
     71 };
     72 
     73 struct iwn_tx_ring {
     74 	struct iwn_dma_info	desc_dma;
     75 	struct iwn_dma_info	cmd_dma;
     76 	struct iwn_tx_desc	*desc;
     77 	struct iwn_tx_cmd	*cmd;
     78 	struct iwn_tx_data	data[IWN_TX_RING_COUNT];
     79 	int			qid;
     80 	int			queued;
     81 	int			count;
     82 	int			cur;
     83 };
     84 
     85 #define IWN_RBUF_COUNT	(IWN_RX_RING_COUNT + 32)
     86 
     87 struct iwn_softc;
     88 
     89 struct iwn_rbuf {
     90 	struct iwn_softc	*sc;
     91 	void *			vaddr;
     92 	bus_addr_t		paddr;
     93 	SLIST_ENTRY(iwn_rbuf)	next;
     94 };
     95 
     96 struct iwn_rx_data {
     97 	struct mbuf	*m;
     98 	bus_dmamap_t	map;
     99 };
    100 
    101 struct iwn_rx_ring {
    102 	struct iwn_dma_info	desc_dma;
    103 	struct iwn_dma_info	stat_dma;
    104 	struct iwn_dma_info	buf_dma;
    105 	uint32_t		*desc;
    106 	struct iwn_rx_status	*stat;
    107 	struct iwn_rx_data	data[IWN_RX_RING_COUNT];
    108 	struct iwn_rbuf		rbuf[IWN_RBUF_COUNT];
    109 	kmutex_t                freelist_mtx;
    110 	SLIST_HEAD(, iwn_rbuf)	freelist;
    111 	int			nb_free_entries;
    112 	int			cur;
    113 };
    114 
    115 struct iwn_node {
    116 	struct	ieee80211_node		ni;	/* must be the first */
    117 	struct	ieee80211_amrr_node	amn;
    118 	uint16_t			disable_tid;
    119 	uint8_t				id;
    120 	uint8_t				ridx[IEEE80211_RATE_MAXSIZE];
    121 };
    122 
    123 struct iwn_calib_state {
    124 	uint8_t		state;
    125 #define IWN_CALIB_STATE_INIT	0
    126 #define IWN_CALIB_STATE_ASSOC	1
    127 #define IWN_CALIB_STATE_RUN	2
    128 
    129 	u_int		nbeacons;
    130 	uint32_t	noise[3];
    131 	uint32_t	rssi[3];
    132 	uint32_t	ofdm_x1;
    133 	uint32_t	ofdm_mrc_x1;
    134 	uint32_t	ofdm_x4;
    135 	uint32_t	ofdm_mrc_x4;
    136 	uint32_t	cck_x4;
    137 	uint32_t	cck_mrc_x4;
    138 	uint32_t	bad_plcp_ofdm;
    139 	uint32_t	fa_ofdm;
    140 	uint32_t	bad_plcp_cck;
    141 	uint32_t	fa_cck;
    142 	uint32_t	low_fa;
    143 	uint8_t		cck_state;
    144 #define IWN_CCK_STATE_INIT	0
    145 #define IWN_CCK_STATE_LOFA	1
    146 #define IWN_CCK_STATE_HIFA	2
    147 
    148 	uint8_t		noise_samples[20];
    149 	u_int		cur_noise_sample;
    150 	uint8_t		noise_ref;
    151 	uint32_t	energy_samples[10];
    152 	u_int		cur_energy_sample;
    153 	uint32_t	energy_cck;
    154 };
    155 
    156 struct iwn_calib_info {
    157 	uint8_t		*buf;
    158 	u_int		len;
    159 };
    160 
    161 struct iwn_fw_part {
    162 	const uint8_t	*text;
    163 	uint32_t	textsz;
    164 	const uint8_t	*data;
    165 	uint32_t	datasz;
    166 };
    167 
    168 struct iwn_fw_info {
    169 	u_char			*data;
    170 	struct iwn_fw_part	init;
    171 	struct iwn_fw_part	main;
    172 	struct iwn_fw_part	boot;
    173 };
    174 
    175 struct iwn_hal {
    176 	int		(*load_firmware)(struct iwn_softc *);
    177 	void		(*read_eeprom)(struct iwn_softc *);
    178 	int		(*post_alive)(struct iwn_softc *);
    179 	int		(*apm_init)(struct iwn_softc *);
    180 	int		(*nic_config)(struct iwn_softc *);
    181 	void		(*update_sched)(struct iwn_softc *, int, int, uint8_t,
    182 			    uint16_t);
    183 	int		(*get_temperature)(struct iwn_softc *);
    184 	int		(*get_rssi)(const struct iwn_rx_stat *);
    185 	int		(*set_txpower)(struct iwn_softc *, int);
    186 	int		(*init_gains)(struct iwn_softc *);
    187 	int		(*set_gains)(struct iwn_softc *);
    188 	int		(*add_node)(struct iwn_softc *, struct iwn_node_info *,
    189 			    int);
    190 	void		(*tx_done)(struct iwn_softc *, struct iwn_rx_desc *,
    191 			    struct iwn_rx_data *);
    192 #ifndef IEEE80211_NO_HT
    193 	void		(*ampdu_tx_start)(struct iwn_softc *,
    194 			    struct ieee80211_node *, uint8_t, uint16_t);
    195 	void		(*ampdu_tx_stop)(struct iwn_softc *, uint8_t,
    196 			    uint16_t);
    197 #endif
    198 	const struct	iwn_sensitivity_limits *limits;
    199 	int		ntxqs;
    200 	uint8_t		broadcast_id;
    201 	int		rxonsz;
    202 	int		schedsz;
    203 	uint32_t	fw_text_maxsz;
    204 	uint32_t	fw_data_maxsz;
    205 	uint32_t	fwsz;
    206 	bus_size_t	sched_txfact_addr;
    207 };
    208 
    209 struct iwn_softc {
    210 	device_t		sc_dev;
    211 
    212 	struct ethercom		sc_ec;
    213 	struct ieee80211com	sc_ic;
    214 	int			(*sc_newstate)(struct ieee80211com *,
    215 				    enum ieee80211_state, int);
    216 
    217 	struct ieee80211_amrr	amrr;
    218 	uint8_t			fixed_ridx;
    219 
    220 	bus_dma_tag_t		sc_dmat;
    221 
    222 	u_int			sc_flags;
    223 #define IWN_FLAG_HAS_5GHZ	(1 << 0)
    224 #define IWN_FLAG_FIRST_BOOT	(1 << 1)
    225 
    226 	uint8_t 		hw_type;
    227 	const struct iwn_hal	*sc_hal;
    228 	const char		*fwname;
    229 
    230 	/* TX scheduler rings. */
    231 	struct iwn_dma_info	sched_dma;
    232 	uint16_t		*sched;
    233 	uint32_t		sched_base;
    234 
    235 	/* "Keep Warm" page. */
    236 	struct iwn_dma_info	kw_dma;
    237 
    238 	/* Firmware DMA transfer. */
    239 	struct iwn_dma_info	fw_dma;
    240 
    241 	/* TX/RX rings. */
    242 	struct iwn_tx_ring	txq[IWN5000_NTXQUEUES];
    243 	struct iwn_rx_ring	rxq;
    244 
    245 	bus_space_tag_t		sc_st;
    246 	bus_space_handle_t	sc_sh;
    247 	void 			*sc_ih;
    248 	pci_chipset_tag_t	sc_pct;
    249 	pcitag_t		sc_pcitag;
    250 	bus_size_t		sc_sz;
    251 	int			sc_cap_off;	/* PCIe Capabilities. */
    252 
    253 	callout_t		calib_to;
    254 	int			calib_cnt;
    255 	struct iwn_calib_state	calib;
    256 
    257 	struct iwn_fw_info	fw;
    258 	struct iwn_calib_info	calibcmd[5];
    259 	uint32_t		errptr;
    260 
    261 	struct iwn_rx_stat	last_rx_stat;
    262 	int			last_rx_valid;
    263 	struct iwn_ucode_info	ucode_info;
    264 	struct iwn_rxon		rxon;
    265 	uint32_t		rawtemp;
    266 	int			temp;
    267 	int			noise;
    268 	uint32_t		qfullmsk;
    269 
    270 	struct iwn4965_eeprom_band
    271 				bands[IWN_NBANDS];
    272 	uint16_t		rfcfg;
    273 	char			eeprom_domain[4];
    274 	uint32_t		eeprom_crystal;
    275 	int16_t			eeprom_voltage;
    276 	int8_t			maxpwr2GHz;
    277 	int8_t			maxpwr5GHz;
    278 	int8_t			maxpwr[IEEE80211_CHAN_MAX];
    279 
    280 	uint32_t		critical_temp;
    281 	uint8_t			ntxchains;
    282 	uint8_t			nrxchains;
    283 	uint8_t			txantmsk;
    284 	uint8_t			rxantmsk;
    285 	uint8_t			antmsk;
    286 
    287 	int			sc_tx_timer;
    288 	void			*powerhook;
    289 
    290 #if NBPFILTER > 0
    291 	void *			sc_drvbpf;
    292 
    293 	union {
    294 		struct iwn_rx_radiotap_header th;
    295 		uint8_t	pad[IEEE80211_RADIOTAP_HDRLEN];
    296 	} sc_rxtapu;
    297 #define sc_rxtap	sc_rxtapu.th
    298 	int			sc_rxtap_len;
    299 
    300 	union {
    301 		struct iwn_tx_radiotap_header th;
    302 		uint8_t	pad[IEEE80211_RADIOTAP_HDRLEN];
    303 	} sc_txtapu;
    304 #define sc_txtap	sc_txtapu.th
    305 	int			sc_txtap_len;
    306 #endif
    307 	bool		is_scanning;
    308 	bool		sc_radio;
    309 };
    310