xref: /openbsd-src/sys/dev/pci/if_wpivar.h (revision 51a6fb1415e6c6a7e23a1a3570ef662a511c3773)
1 /*	$OpenBSD: if_wpivar.h,v 1.29 2020/10/11 07:05:29 mpi Exp $	*/
2 
3 /*-
4  * Copyright (c) 2006-2008
5  *	Damien Bergamini <damien.bergamini@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 
20 struct wpi_rx_radiotap_header {
21 	struct ieee80211_radiotap_header wr_ihdr;
22 	uint64_t	wr_tsft;
23 	uint8_t		wr_flags;
24 	uint8_t		wr_rate;
25 	uint16_t	wr_chan_freq;
26 	uint16_t	wr_chan_flags;
27 	int8_t		wr_dbm_antsignal;
28 	int8_t		wr_dbm_antnoise;
29 	uint8_t		wr_antenna;
30 } __packed;
31 
32 #define WPI_RX_RADIOTAP_PRESENT						\
33 	((1 << IEEE80211_RADIOTAP_TSFT) |				\
34 	 (1 << IEEE80211_RADIOTAP_FLAGS) |				\
35 	 (1 << IEEE80211_RADIOTAP_RATE) |				\
36 	 (1 << IEEE80211_RADIOTAP_CHANNEL) |				\
37 	 (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) |			\
38 	 (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) |			\
39 	 (1 << IEEE80211_RADIOTAP_ANTENNA))
40 
41 struct wpi_tx_radiotap_header {
42 	struct ieee80211_radiotap_header wt_ihdr;
43 	uint8_t		wt_flags;
44 	uint8_t		wt_rate;
45 	uint16_t	wt_chan_freq;
46 	uint16_t	wt_chan_flags;
47 } __packed;
48 
49 #define WPI_TX_RADIOTAP_PRESENT						\
50 	((1 << IEEE80211_RADIOTAP_FLAGS) |				\
51 	 (1 << IEEE80211_RADIOTAP_RATE) |				\
52 	 (1 << IEEE80211_RADIOTAP_CHANNEL))
53 
54 struct wpi_dma_info {
55 	bus_dma_tag_t		tag;
56 	bus_dmamap_t		map;
57 	bus_dma_segment_t	seg;
58 	bus_addr_t		paddr;
59 	caddr_t			vaddr;
60 	bus_size_t		size;
61 };
62 
63 struct wpi_tx_data {
64 	bus_dmamap_t		map;
65 	bus_addr_t		cmd_paddr;
66 	struct mbuf		*m;
67 	struct ieee80211_node	*ni;
68 };
69 
70 struct wpi_tx_ring {
71 	struct wpi_dma_info	desc_dma;
72 	struct wpi_dma_info	cmd_dma;
73 	struct wpi_tx_desc	*desc;
74 	struct wpi_tx_cmd	*cmd;
75 	struct wpi_tx_data	data[WPI_TX_RING_COUNT];
76 	int			qid;
77 	int			queued;
78 	int			cur;
79 };
80 
81 struct wpi_softc;
82 
83 struct wpi_rx_data {
84 	struct mbuf	*m;
85 	bus_dmamap_t	map;
86 };
87 
88 struct wpi_rx_ring {
89 	struct wpi_dma_info	desc_dma;
90 	uint32_t		*desc;
91 	struct wpi_rx_data	data[WPI_RX_RING_COUNT];
92 	int			cur;
93 };
94 
95 struct wpi_node {
96 	struct	ieee80211_node		ni;	/* must be the first */
97 	struct	ieee80211_amrr_node	amn;
98 	uint8_t				id;
99 	uint8_t				ridx[IEEE80211_RATE_MAXSIZE];
100 };
101 
102 struct wpi_power_sample {
103 	uint8_t	index;
104 	int8_t	power;
105 };
106 
107 struct wpi_power_group {
108 #define WPI_SAMPLES_COUNT	5
109 	struct	wpi_power_sample samples[WPI_SAMPLES_COUNT];
110 	uint8_t	chan;
111 	int8_t	maxpwr;
112 	int16_t	temp;
113 };
114 
115 struct wpi_fw_part {
116 	const uint8_t	*text;
117 	uint32_t	textsz;
118 	const uint8_t	*data;
119 	uint32_t	datasz;
120 };
121 
122 struct wpi_fw_info {
123 	u_char			*data;
124 	size_t			datalen;
125 	struct wpi_fw_part	init;
126 	struct wpi_fw_part	main;
127 	struct wpi_fw_part	boot;
128 };
129 
130 struct wpi_softc {
131 	struct device		sc_dev;
132 
133 	struct ieee80211com	sc_ic;
134 	int			(*sc_newstate)(struct ieee80211com *,
135 				    enum ieee80211_state, int);
136 
137 	struct ieee80211_amrr	amrr;
138 	uint8_t			fixed_ridx;
139 
140 	bus_dma_tag_t		sc_dmat;
141 
142 	struct rwlock		sc_rwlock;
143 	u_int			sc_flags;
144 #define WPI_FLAG_HAS_5GHZ	(1 << 0)
145 
146 	/* Shared area. */
147 	struct wpi_dma_info	shared_dma;
148 	struct wpi_shared	*shared;
149 
150 	/* Firmware DMA transfer. */
151 	struct wpi_dma_info	fw_dma;
152 
153 	/* TX/RX rings. */
154 	struct wpi_tx_ring	txq[WPI_NTXQUEUES];
155 	struct wpi_rx_ring	rxq;
156 
157 	bus_space_tag_t		sc_st;
158 	bus_space_handle_t	sc_sh;
159 	void 			*sc_ih;
160 	pci_chipset_tag_t	sc_pct;
161 	pcitag_t		sc_pcitag;
162 	bus_size_t		sc_sz;
163 	int			sc_cap_off;	/* PCIe Capabilities. */
164 
165 	struct timeout		calib_to;
166 	int			calib_cnt;
167 
168 	struct task		init_task;
169 
170 	struct wpi_fw_info	fw;
171 	uint32_t		errptr;
172 
173 	struct wpi_rxon		rxon;
174 	int			temp;
175 	uint32_t		qfullmsk;
176 
177 	uint8_t			cap;
178 	uint16_t		rev;
179 	uint8_t			type;
180 	struct wpi_power_group	groups[WPI_POWER_GROUPS_COUNT];
181 	int8_t			maxpwr[IEEE80211_CHAN_MAX];
182 
183 	int			sc_tx_timer;
184 
185 #if NBPFILTER > 0
186 	caddr_t			sc_drvbpf;
187 
188 	union {
189 		struct wpi_rx_radiotap_header th;
190 		uint8_t	pad[IEEE80211_RADIOTAP_HDRLEN];
191 	} sc_rxtapu;
192 #define sc_rxtap	sc_rxtapu.th
193 	int			sc_rxtap_len;
194 
195 	union {
196 		struct wpi_tx_radiotap_header th;
197 		uint8_t	pad[IEEE80211_RADIOTAP_HDRLEN];
198 	} sc_txtapu;
199 #define sc_txtap	sc_txtapu.th
200 	int			sc_txtap_len;
201 #endif
202 };
203