xref: /dflybsd-src/sys/dev/netif/ral/rt2661var.h (revision 93d249f7c46ee64628768dd449f435c6ae641ed0)
191b30d50SMatthew Dillon /*	$FreeBSD$	*/
2feb94d24SRui Paulo 
3feb94d24SRui Paulo /*-
45fdff524SSepherosa Ziehau  * Copyright (c) 2005
55fdff524SSepherosa Ziehau  *	Damien Bergamini <damien.bergamini@free.fr>
65fdff524SSepherosa Ziehau  *
75fdff524SSepherosa Ziehau  * Permission to use, copy, modify, and distribute this software for any
85fdff524SSepherosa Ziehau  * purpose with or without fee is hereby granted, provided that the above
95fdff524SSepherosa Ziehau  * copyright notice and this permission notice appear in all copies.
105fdff524SSepherosa Ziehau  *
115fdff524SSepherosa Ziehau  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
125fdff524SSepherosa Ziehau  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
135fdff524SSepherosa Ziehau  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
145fdff524SSepherosa Ziehau  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
155fdff524SSepherosa Ziehau  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
165fdff524SSepherosa Ziehau  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
175fdff524SSepherosa Ziehau  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
185fdff524SSepherosa Ziehau  */
195fdff524SSepherosa Ziehau 
205fdff524SSepherosa Ziehau struct rt2661_rx_radiotap_header {
215fdff524SSepherosa Ziehau 	struct ieee80211_radiotap_header wr_ihdr;
225fdff524SSepherosa Ziehau 	uint64_t	wr_tsf;
235fdff524SSepherosa Ziehau 	uint8_t		wr_flags;
245fdff524SSepherosa Ziehau 	uint8_t		wr_rate;
255fdff524SSepherosa Ziehau 	uint16_t	wr_chan_freq;
265fdff524SSepherosa Ziehau 	uint16_t	wr_chan_flags;
27feb94d24SRui Paulo 	int8_t		wr_antsignal;
28feb94d24SRui Paulo 	int8_t		wr_antnoise;
295fdff524SSepherosa Ziehau } __packed;
305fdff524SSepherosa Ziehau 
315fdff524SSepherosa Ziehau #define RT2661_RX_RADIOTAP_PRESENT					\
325fdff524SSepherosa Ziehau 	((1 << IEEE80211_RADIOTAP_TSFT) |				\
335fdff524SSepherosa Ziehau 	 (1 << IEEE80211_RADIOTAP_FLAGS) |				\
345fdff524SSepherosa Ziehau 	 (1 << IEEE80211_RADIOTAP_RATE) |				\
355fdff524SSepherosa Ziehau 	 (1 << IEEE80211_RADIOTAP_CHANNEL) |				\
36feb94d24SRui Paulo 	 (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) |			\
37feb94d24SRui Paulo 	 (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE))
385fdff524SSepherosa Ziehau 
395fdff524SSepherosa Ziehau struct rt2661_tx_radiotap_header {
405fdff524SSepherosa Ziehau 	struct ieee80211_radiotap_header wt_ihdr;
415fdff524SSepherosa Ziehau 	uint8_t		wt_flags;
425fdff524SSepherosa Ziehau 	uint8_t		wt_rate;
435fdff524SSepherosa Ziehau 	uint16_t	wt_chan_freq;
445fdff524SSepherosa Ziehau 	uint16_t	wt_chan_flags;
455fdff524SSepherosa Ziehau } __packed;
465fdff524SSepherosa Ziehau 
475fdff524SSepherosa Ziehau #define RT2661_TX_RADIOTAP_PRESENT					\
485fdff524SSepherosa Ziehau 	((1 << IEEE80211_RADIOTAP_FLAGS) |				\
495fdff524SSepherosa Ziehau 	 (1 << IEEE80211_RADIOTAP_RATE) |				\
505fdff524SSepherosa Ziehau 	 (1 << IEEE80211_RADIOTAP_CHANNEL))
515fdff524SSepherosa Ziehau 
52feb94d24SRui Paulo struct rt2661_tx_data {
539dd87f8aSSepherosa Ziehau 	bus_dmamap_t		map;
549dd87f8aSSepherosa Ziehau 	struct mbuf		*m;
55feb94d24SRui Paulo 	struct ieee80211_node	*ni;
56feb94d24SRui Paulo 	uint8_t			rix;
57feb94d24SRui Paulo 	int8_t			rssi;
585fdff524SSepherosa Ziehau };
595fdff524SSepherosa Ziehau 
605fdff524SSepherosa Ziehau struct rt2661_tx_ring {
615fdff524SSepherosa Ziehau 	bus_dma_tag_t		desc_dmat;
625fdff524SSepherosa Ziehau 	bus_dma_tag_t		data_dmat;
635fdff524SSepherosa Ziehau 	bus_dmamap_t		desc_map;
645fdff524SSepherosa Ziehau 	bus_addr_t		physaddr;
655fdff524SSepherosa Ziehau 	struct rt2661_tx_desc	*desc;
66feb94d24SRui Paulo 	struct rt2661_tx_data	*data;
675fdff524SSepherosa Ziehau 	int			count;
685fdff524SSepherosa Ziehau 	int			queued;
695fdff524SSepherosa Ziehau 	int			cur;
705fdff524SSepherosa Ziehau 	int			next;
71feb94d24SRui Paulo 	int			stat;
72feb94d24SRui Paulo };
73feb94d24SRui Paulo 
74feb94d24SRui Paulo struct rt2661_rx_data {
75feb94d24SRui Paulo 	bus_dmamap_t	map;
76feb94d24SRui Paulo 	struct mbuf	*m;
775fdff524SSepherosa Ziehau };
785fdff524SSepherosa Ziehau 
795fdff524SSepherosa Ziehau struct rt2661_rx_ring {
805fdff524SSepherosa Ziehau 	bus_dma_tag_t		desc_dmat;
815fdff524SSepherosa Ziehau 	bus_dma_tag_t		data_dmat;
825fdff524SSepherosa Ziehau 	bus_dmamap_t		desc_map;
835fdff524SSepherosa Ziehau 	bus_addr_t		physaddr;
845fdff524SSepherosa Ziehau 	struct rt2661_rx_desc	*desc;
85feb94d24SRui Paulo 	struct rt2661_rx_data	*data;
865fdff524SSepherosa Ziehau 	int			count;
875fdff524SSepherosa Ziehau 	int			cur;
885fdff524SSepherosa Ziehau 	int			next;
895fdff524SSepherosa Ziehau };
905fdff524SSepherosa Ziehau 
91feb94d24SRui Paulo struct rt2661_vap {
92feb94d24SRui Paulo 	struct ieee80211vap	ral_vap;
93feb94d24SRui Paulo 
94feb94d24SRui Paulo 	int			(*ral_newstate)(struct ieee80211vap *,
95feb94d24SRui Paulo 				    enum ieee80211_state, int);
9699fda2c4SSepherosa Ziehau };
97feb94d24SRui Paulo #define	RT2661_VAP(vap)		((struct rt2661_vap *)(vap))
9899fda2c4SSepherosa Ziehau 
995fdff524SSepherosa Ziehau struct rt2661_softc {
10091b30d50SMatthew Dillon 	struct ieee80211com		sc_ic;
101*93d249f7SMatthew Dillon #if defined(__DragonFly__)
102*93d249f7SMatthew Dillon 	struct lock			sc_mtx;
103*93d249f7SMatthew Dillon #else
10491b30d50SMatthew Dillon 	struct mtx			sc_mtx;
105*93d249f7SMatthew Dillon #endif
10691b30d50SMatthew Dillon 	struct mbufq			sc_snd;
107feb94d24SRui Paulo 	device_t			sc_dev;
1085fdff524SSepherosa Ziehau 	bus_space_tag_t			sc_st;
1095fdff524SSepherosa Ziehau 	bus_space_handle_t		sc_sh;
1105fdff524SSepherosa Ziehau 
111feb94d24SRui Paulo 	struct callout			watchdog_ch;
1125fdff524SSepherosa Ziehau 
1135fdff524SSepherosa Ziehau 	int				sc_tx_timer;
114feb94d24SRui Paulo 	int                             sc_invalid;
115feb94d24SRui Paulo 	int				sc_debug;
116feb94d24SRui Paulo /*
117feb94d24SRui Paulo  * The same in both up to here
118feb94d24SRui Paulo  * ------------------------------------------------
119feb94d24SRui Paulo  */
1205fdff524SSepherosa Ziehau 
121feb94d24SRui Paulo 	int                             sc_flags;
122feb94d24SRui Paulo #define	RAL_FW_LOADED		0x1
123feb94d24SRui Paulo #define	RAL_INPUT_RUNNING	0x2
12491b30d50SMatthew Dillon #define	RAL_RUNNING		0x4
125feb94d24SRui Paulo 	int				sc_id;
1265fdff524SSepherosa Ziehau 	struct ieee80211_channel	*sc_curchan;
1275fdff524SSepherosa Ziehau 
1285fdff524SSepherosa Ziehau 	uint8_t				rf_rev;
1295fdff524SSepherosa Ziehau 
130feb94d24SRui Paulo 	uint8_t				rfprog;
1315fdff524SSepherosa Ziehau 	uint8_t				rffreq;
1325fdff524SSepherosa Ziehau 
1335fdff524SSepherosa Ziehau 	struct rt2661_tx_ring		txq[4];
1345fdff524SSepherosa Ziehau 	struct rt2661_tx_ring		mgtq;
1355fdff524SSepherosa Ziehau 	struct rt2661_rx_ring		rxq;
1365fdff524SSepherosa Ziehau 
1375fdff524SSepherosa Ziehau 	uint32_t			rf_regs[4];
138feb94d24SRui Paulo 	int8_t				txpow[38];
1395fdff524SSepherosa Ziehau 
1405fdff524SSepherosa Ziehau 	struct {
1415fdff524SSepherosa Ziehau 		uint8_t	reg;
1425fdff524SSepherosa Ziehau 		uint8_t	val;
1435fdff524SSepherosa Ziehau 	}				bbp_prom[16];
1445fdff524SSepherosa Ziehau 
1455fdff524SSepherosa Ziehau 	int				hw_radio;
1465fdff524SSepherosa Ziehau 	int				rx_ant;
1475fdff524SSepherosa Ziehau 	int				tx_ant;
1485fdff524SSepherosa Ziehau 	int				nb_ant;
1495fdff524SSepherosa Ziehau 	int				ext_2ghz_lna;
1505fdff524SSepherosa Ziehau 	int				ext_5ghz_lna;
151feb94d24SRui Paulo 	int				rssi_2ghz_corr;
1525fdff524SSepherosa Ziehau 	int				rssi_5ghz_corr;
1535fdff524SSepherosa Ziehau 
1545fdff524SSepherosa Ziehau 	uint8_t				bbp18;
1555fdff524SSepherosa Ziehau 	uint8_t				bbp21;
1565fdff524SSepherosa Ziehau 	uint8_t				bbp22;
1575fdff524SSepherosa Ziehau 	uint8_t				bbp16;
1585fdff524SSepherosa Ziehau 	uint8_t				bbp17;
1595fdff524SSepherosa Ziehau 	uint8_t				bbp64;
1605fdff524SSepherosa Ziehau 
161feb94d24SRui Paulo 	int				dwelltime;
1629dd87f8aSSepherosa Ziehau 
163feb94d24SRui Paulo 	struct rt2661_rx_radiotap_header sc_rxtap;
164feb94d24SRui Paulo 	struct rt2661_tx_radiotap_header sc_txtap;
1655fdff524SSepherosa Ziehau };
1665fdff524SSepherosa Ziehau 
1675fdff524SSepherosa Ziehau int	rt2661_attach(device_t, int);
1685fdff524SSepherosa Ziehau int	rt2661_detach(void *);
1695fdff524SSepherosa Ziehau void	rt2661_shutdown(void *);
1705fdff524SSepherosa Ziehau void	rt2661_suspend(void *);
1715fdff524SSepherosa Ziehau void	rt2661_resume(void *);
172feb94d24SRui Paulo void	rt2661_intr(void *);
17391b30d50SMatthew Dillon 
174*93d249f7SMatthew Dillon #if defined(__DragonFly__)
175*93d249f7SMatthew Dillon 
176*93d249f7SMatthew Dillon #define RAL_LOCK(sc)		lockmgr(&(sc)->sc_mtx, LK_EXCLUSIVE)
177*93d249f7SMatthew Dillon #define RAL_LOCK_ASSERT(sc)	KKASSERT(lockstatus(&(sc)->sc_mtx, curthread) == LK_EXCLUSIVE)
178*93d249f7SMatthew Dillon #define RAL_UNLOCK(sc)		lockmgr(&(sc)->sc_mtx, LK_RELEASE)
179*93d249f7SMatthew Dillon 
180*93d249f7SMatthew Dillon #else
181*93d249f7SMatthew Dillon 
18291b30d50SMatthew Dillon #define RAL_LOCK(sc)		mtx_lock(&(sc)->sc_mtx)
18391b30d50SMatthew Dillon #define RAL_LOCK_ASSERT(sc)	mtx_assert(&(sc)->sc_mtx, MA_OWNED)
18491b30d50SMatthew Dillon #define RAL_UNLOCK(sc)		mtx_unlock(&(sc)->sc_mtx)
185*93d249f7SMatthew Dillon 
186*93d249f7SMatthew Dillon #endif
187