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