xref: /dflybsd-src/sys/dev/netif/ral/rt2560var.h (revision 93d249f7c46ee64628768dd449f435c6ae641ed0)
191b30d50SMatthew Dillon /*	$FreeBSD$	*/
2feb94d24SRui Paulo 
3feb94d24SRui Paulo /*-
45fdff524SSepherosa Ziehau  * Copyright (c) 2005, 2006
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 rt2560_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 	uint8_t		wr_antenna;
305fdff524SSepherosa Ziehau };
315fdff524SSepherosa Ziehau 
325fdff524SSepherosa Ziehau #define RT2560_RX_RADIOTAP_PRESENT					\
335fdff524SSepherosa Ziehau 	((1 << IEEE80211_RADIOTAP_TSFT) |				\
345fdff524SSepherosa Ziehau 	 (1 << IEEE80211_RADIOTAP_FLAGS) |				\
355fdff524SSepherosa Ziehau 	 (1 << IEEE80211_RADIOTAP_RATE) |				\
365fdff524SSepherosa Ziehau 	 (1 << IEEE80211_RADIOTAP_CHANNEL) |				\
375fdff524SSepherosa Ziehau 	 (1 << IEEE80211_RADIOTAP_ANTENNA) |				\
38feb94d24SRui Paulo 	 (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) |			\
39feb94d24SRui Paulo 	 (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE))
405fdff524SSepherosa Ziehau 
415fdff524SSepherosa Ziehau struct rt2560_tx_radiotap_header {
425fdff524SSepherosa Ziehau 	struct ieee80211_radiotap_header wt_ihdr;
435fdff524SSepherosa Ziehau 	uint8_t		wt_flags;
445fdff524SSepherosa Ziehau 	uint8_t		wt_rate;
455fdff524SSepherosa Ziehau 	uint16_t	wt_chan_freq;
465fdff524SSepherosa Ziehau 	uint16_t	wt_chan_flags;
475fdff524SSepherosa Ziehau 	uint8_t		wt_antenna;
485fdff524SSepherosa Ziehau };
495fdff524SSepherosa Ziehau 
505fdff524SSepherosa Ziehau #define RT2560_TX_RADIOTAP_PRESENT					\
515fdff524SSepherosa Ziehau 	((1 << IEEE80211_RADIOTAP_FLAGS) |				\
525fdff524SSepherosa Ziehau 	 (1 << IEEE80211_RADIOTAP_RATE) |				\
535fdff524SSepherosa Ziehau 	 (1 << IEEE80211_RADIOTAP_CHANNEL) |				\
545fdff524SSepherosa Ziehau 	 (1 << IEEE80211_RADIOTAP_ANTENNA))
555fdff524SSepherosa Ziehau 
565fdff524SSepherosa Ziehau struct rt2560_tx_data {
575fdff524SSepherosa Ziehau 	bus_dmamap_t			map;
585fdff524SSepherosa Ziehau 	struct mbuf			*m;
595fdff524SSepherosa Ziehau 	struct ieee80211_node		*ni;
60feb94d24SRui Paulo 	uint8_t				rix;
61feb94d24SRui Paulo 	int8_t				rssi;
625fdff524SSepherosa Ziehau };
635fdff524SSepherosa Ziehau 
645fdff524SSepherosa Ziehau struct rt2560_tx_ring {
655fdff524SSepherosa Ziehau 	bus_dma_tag_t		desc_dmat;
665fdff524SSepherosa Ziehau 	bus_dma_tag_t		data_dmat;
675fdff524SSepherosa Ziehau 	bus_dmamap_t		desc_map;
685fdff524SSepherosa Ziehau 	bus_addr_t		physaddr;
695fdff524SSepherosa Ziehau 	struct rt2560_tx_desc	*desc;
705fdff524SSepherosa Ziehau 	struct rt2560_tx_data	*data;
715fdff524SSepherosa Ziehau 	int			count;
725fdff524SSepherosa Ziehau 	int			queued;
735fdff524SSepherosa Ziehau 	int			cur;
745fdff524SSepherosa Ziehau 	int			next;
755fdff524SSepherosa Ziehau 	int			cur_encrypt;
765fdff524SSepherosa Ziehau 	int			next_encrypt;
775fdff524SSepherosa Ziehau };
785fdff524SSepherosa Ziehau 
795fdff524SSepherosa Ziehau struct rt2560_rx_data {
805fdff524SSepherosa Ziehau 	bus_dmamap_t	map;
815fdff524SSepherosa Ziehau 	struct mbuf	*m;
825fdff524SSepherosa Ziehau 	int		drop;
835fdff524SSepherosa Ziehau };
845fdff524SSepherosa Ziehau 
855fdff524SSepherosa Ziehau struct rt2560_rx_ring {
865fdff524SSepherosa Ziehau 	bus_dma_tag_t		desc_dmat;
875fdff524SSepherosa Ziehau 	bus_dma_tag_t		data_dmat;
885fdff524SSepherosa Ziehau 	bus_dmamap_t		desc_map;
895fdff524SSepherosa Ziehau 	bus_addr_t		physaddr;
905fdff524SSepherosa Ziehau 	struct rt2560_rx_desc	*desc;
915fdff524SSepherosa Ziehau 	struct rt2560_rx_data	*data;
925fdff524SSepherosa Ziehau 	int			count;
935fdff524SSepherosa Ziehau 	int			cur;
945fdff524SSepherosa Ziehau 	int			next;
955fdff524SSepherosa Ziehau 	int			cur_decrypt;
965fdff524SSepherosa Ziehau };
975fdff524SSepherosa Ziehau 
98feb94d24SRui Paulo struct rt2560_vap {
99feb94d24SRui Paulo 	struct ieee80211vap	ral_vap;
100feb94d24SRui Paulo 
101feb94d24SRui Paulo 	int			(*ral_newstate)(struct ieee80211vap *,
102feb94d24SRui Paulo 				    enum ieee80211_state, int);
103feb94d24SRui Paulo };
104feb94d24SRui Paulo #define	RT2560_VAP(vap)		((struct rt2560_vap *)(vap))
105feb94d24SRui Paulo 
1065fdff524SSepherosa Ziehau struct rt2560_softc {
10791b30d50SMatthew Dillon 	struct ieee80211com	sc_ic;
108*93d249f7SMatthew Dillon #if defined(__DragonFly__)
109*93d249f7SMatthew Dillon 	struct lock		sc_mtx;
110*93d249f7SMatthew Dillon #else
11191b30d50SMatthew Dillon 	struct mtx		sc_mtx;
112*93d249f7SMatthew Dillon #endif
11391b30d50SMatthew Dillon 	struct mbufq		sc_snd;
114feb94d24SRui Paulo 	device_t		sc_dev;
1155fdff524SSepherosa Ziehau 	bus_space_tag_t		sc_st;
1165fdff524SSepherosa Ziehau 	bus_space_handle_t	sc_sh;
1175fdff524SSepherosa Ziehau 
118feb94d24SRui Paulo 	struct callout		watchdog_ch;
1195fdff524SSepherosa Ziehau 
1205fdff524SSepherosa Ziehau 	int			sc_tx_timer;
121feb94d24SRui Paulo 	int                     sc_invalid;
122feb94d24SRui Paulo 	int			sc_debug;
123feb94d24SRui Paulo /*
124feb94d24SRui Paulo  * The same in both up to here
125feb94d24SRui Paulo  * ------------------------------------------------
126feb94d24SRui Paulo  */
127feb94d24SRui Paulo 	uint32_t		asic_rev;
1285fdff524SSepherosa Ziehau 	uint32_t		eeprom_rev;
1295fdff524SSepherosa Ziehau 	uint8_t			rf_rev;
130a5c68736SSepherosa Ziehau 	uint8_t			rssi_corr;
1315fdff524SSepherosa Ziehau 
1325fdff524SSepherosa Ziehau 	struct rt2560_tx_ring	txq;
1335fdff524SSepherosa Ziehau 	struct rt2560_tx_ring	prioq;
1345fdff524SSepherosa Ziehau 	struct rt2560_tx_ring	atimq;
1355fdff524SSepherosa Ziehau 	struct rt2560_tx_ring	bcnq;
1365fdff524SSepherosa Ziehau 	struct rt2560_rx_ring	rxq;
1375fdff524SSepherosa Ziehau 
1385fdff524SSepherosa Ziehau 	uint32_t		rf_regs[4];
1395fdff524SSepherosa Ziehau 	uint8_t			txpow[14];
1405fdff524SSepherosa Ziehau 
1415fdff524SSepherosa Ziehau 	struct {
1425fdff524SSepherosa Ziehau 		uint8_t	reg;
1435fdff524SSepherosa Ziehau 		uint8_t	val;
1445fdff524SSepherosa Ziehau 	}			bbp_prom[16];
1455fdff524SSepherosa Ziehau 
1465fdff524SSepherosa Ziehau 	int			led_mode;
1475fdff524SSepherosa Ziehau 	int			hw_radio;
1485fdff524SSepherosa Ziehau 	int			rx_ant;
1495fdff524SSepherosa Ziehau 	int			tx_ant;
1505fdff524SSepherosa Ziehau 	int			nb_ant;
1515fdff524SSepherosa Ziehau 
152feb94d24SRui Paulo 	struct rt2560_rx_radiotap_header sc_rxtap;
153feb94d24SRui Paulo 	struct rt2560_tx_radiotap_header sc_txtap;
15491b30d50SMatthew Dillon 
155feb94d24SRui Paulo #define RT2560_F_INPUT_RUNNING	0x1
15691b30d50SMatthew Dillon #define RT2560_F_RUNNING	0x2
157feb94d24SRui Paulo 	int			sc_flags;
1585fdff524SSepherosa Ziehau };
1595fdff524SSepherosa Ziehau 
1605fdff524SSepherosa Ziehau int	rt2560_attach(device_t, int);
1615fdff524SSepherosa Ziehau int	rt2560_detach(void *);
162feb94d24SRui Paulo void	rt2560_stop(void *);
1635fdff524SSepherosa Ziehau void	rt2560_resume(void *);
164feb94d24SRui Paulo void	rt2560_intr(void *);
16591b30d50SMatthew Dillon 
166*93d249f7SMatthew Dillon #if defined(__DragonFly__)
167*93d249f7SMatthew Dillon 
168*93d249f7SMatthew Dillon #define RAL_LOCK(sc)		lockmgr(&(sc)->sc_mtx, LK_EXCLUSIVE)
169*93d249f7SMatthew Dillon #define RAL_LOCK_ASSERT(sc)	KKASSERT(lockstatus(&(sc)->sc_mtx, curthread) == LK_EXCLUSIVE)
170*93d249f7SMatthew Dillon #define RAL_UNLOCK(sc)		lockmgr(&(sc)->sc_mtx, LK_RELEASE)
171*93d249f7SMatthew Dillon 
172*93d249f7SMatthew Dillon #else
173*93d249f7SMatthew Dillon 
17491b30d50SMatthew Dillon #define RAL_LOCK(sc)		mtx_lock(&(sc)->sc_mtx)
17591b30d50SMatthew Dillon #define RAL_LOCK_ASSERT(sc)	mtx_assert(&(sc)->sc_mtx, MA_OWNED)
17691b30d50SMatthew Dillon #define RAL_UNLOCK(sc)		mtx_unlock(&(sc)->sc_mtx)
177*93d249f7SMatthew Dillon 
178*93d249f7SMatthew Dillon #endif
179