xref: /freebsd/sys/dev/ipw/if_ipwvar.h (revision 71625ec9ad2a9bc8c09784fbd23b759830e0ee5f)
1 
2 /*-
3  * SPDX-License-Identifier: BSD-2-Clause
4  *
5  * Copyright (c) 2004-2006
6  *      Damien Bergamini <damien.bergamini@free.fr>. All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice unmodified, this list of conditions, and the following
13  *    disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28  * SUCH DAMAGE.
29  */
30 
31 #define IPW_MAX_NSEG	1
32 
33 struct ipw_soft_bd {
34 	struct ipw_bd	*bd;
35 	int		type;
36 #define IPW_SBD_TYPE_NOASSOC	0
37 #define IPW_SBD_TYPE_COMMAND	1
38 #define IPW_SBD_TYPE_HEADER	2
39 #define IPW_SBD_TYPE_DATA	3
40 	void		*priv;
41 };
42 
43 struct ipw_soft_hdr {
44 	struct ipw_hdr			hdr;
45 	bus_dmamap_t			map;
46 	SLIST_ENTRY(ipw_soft_hdr)	next;
47 };
48 
49 struct ipw_soft_buf {
50 	struct mbuf			*m;
51 	struct ieee80211_node		*ni;
52 	bus_dmamap_t			map;
53 	SLIST_ENTRY(ipw_soft_buf)	next;
54 };
55 
56 struct ipw_rx_radiotap_header {
57 	struct ieee80211_radiotap_header wr_ihdr;
58 	uint8_t		wr_flags;
59 	uint8_t		wr_pad;
60 	uint16_t	wr_chan_freq;
61 	uint16_t	wr_chan_flags;
62 	int8_t		wr_antsignal;
63 	int8_t		wr_antnoise;
64 } __packed __aligned(8);
65 
66 #define IPW_RX_RADIOTAP_PRESENT						\
67 	((1 << IEEE80211_RADIOTAP_FLAGS) |				\
68 	 (1 << IEEE80211_RADIOTAP_CHANNEL) |				\
69 	 (1 << IEEE80211_RADIOTAP_DB_ANTSIGNAL) |			\
70 	 (1 << IEEE80211_RADIOTAP_DB_ANTNOISE))
71 
72 struct ipw_tx_radiotap_header {
73 	struct ieee80211_radiotap_header wt_ihdr;
74 	uint8_t		wt_flags;
75 	uint8_t		wt_pad;
76 	uint16_t	wt_chan_freq;
77 	uint16_t	wt_chan_flags;
78 } __packed;
79 
80 #define IPW_TX_RADIOTAP_PRESENT						\
81 	((1 << IEEE80211_RADIOTAP_FLAGS) |				\
82 	 (1 << IEEE80211_RADIOTAP_CHANNEL))
83 
84 struct ipw_vap {
85 	struct ieee80211vap	vap;
86 
87 	int			(*newstate)(struct ieee80211vap *,
88 				    enum ieee80211_state, int);
89 };
90 #define	IPW_VAP(vap)	((struct ipw_vap *)(vap))
91 
92 struct ipw_softc {
93 	struct ieee80211com		sc_ic;
94 	struct mbufq			sc_snd;
95 	device_t			sc_dev;
96 
97 	struct mtx			sc_mtx;
98 	struct task			sc_init_task;
99 	struct callout			sc_wdtimer;	/* watchdog timer */
100 
101 	uint32_t			flags;
102 #define IPW_FLAG_FW_INITED		0x0001
103 #define IPW_FLAG_INIT_LOCKED		0x0002
104 #define IPW_FLAG_HAS_RADIO_SWITCH	0x0004
105 #define	IPW_FLAG_HACK			0x0008
106 #define	IPW_FLAG_SCANNING		0x0010
107 #define	IPW_FLAG_ENABLED		0x0020
108 #define	IPW_FLAG_BUSY			0x0040
109 #define	IPW_FLAG_ASSOCIATING		0x0080
110 #define	IPW_FLAG_ASSOCIATED		0x0100
111 #define	IPW_FLAG_RUNNING		0x0200
112 
113 	struct resource			*irq;
114 	struct resource			*mem;
115 	bus_space_tag_t			sc_st;
116 	bus_space_handle_t		sc_sh;
117 	void 				*sc_ih;
118 	const struct firmware		*sc_firmware;
119 
120 	int				sc_tx_timer;
121 	int				sc_scan_timer;
122 
123 	bus_dma_tag_t			parent_dmat;
124 	bus_dma_tag_t			tbd_dmat;
125 	bus_dma_tag_t			rbd_dmat;
126 	bus_dma_tag_t			status_dmat;
127 	bus_dma_tag_t			cmd_dmat;
128 	bus_dma_tag_t			hdr_dmat;
129 	bus_dma_tag_t			txbuf_dmat;
130 	bus_dma_tag_t			rxbuf_dmat;
131 
132 	bus_dmamap_t			tbd_map;
133 	bus_dmamap_t			rbd_map;
134 	bus_dmamap_t			status_map;
135 	bus_dmamap_t			cmd_map;
136 
137 	bus_addr_t			tbd_phys;
138 	bus_addr_t			rbd_phys;
139 	bus_addr_t			status_phys;
140 
141 	struct ipw_bd			*tbd_list;
142 	struct ipw_bd			*rbd_list;
143 	struct ipw_status		*status_list;
144 
145 	struct ipw_cmd			cmd;
146 	struct ipw_soft_bd		stbd_list[IPW_NTBD];
147 	struct ipw_soft_buf		tx_sbuf_list[IPW_NDATA];
148 	struct ipw_soft_hdr		shdr_list[IPW_NDATA];
149 	struct ipw_soft_bd		srbd_list[IPW_NRBD];
150 	struct ipw_soft_buf		rx_sbuf_list[IPW_NRBD];
151 
152 	SLIST_HEAD(, ipw_soft_hdr)	free_shdr;
153 	SLIST_HEAD(, ipw_soft_buf)	free_sbuf;
154 
155 	uint32_t			table1_base;
156 	uint32_t			table2_base;
157 
158 	uint32_t			txcur;
159 	uint32_t			txold;
160 	uint32_t			rxcur;
161 	int				txfree;
162 
163 	uint16_t			chanmask;
164 
165 	struct ipw_rx_radiotap_header	sc_rxtap;
166 	struct ipw_tx_radiotap_header	sc_txtap;
167 };
168 
169 /*
170  * NB.: This models the only instance of async locking in ipw_init_locked
171  *	and must be kept in sync.
172  */
173 #define IPW_LOCK(sc)		mtx_lock(&sc->sc_mtx);
174 #define IPW_UNLOCK(sc)		mtx_unlock(&sc->sc_mtx);
175 #define IPW_LOCK_ASSERT(sc)	mtx_assert(&(sc)->sc_mtx, MA_OWNED)
176