xref: /openbsd-src/sys/dev/ic/rtwnvar.h (revision 067851b1c94ccaee6836135b40bde6ba4cb62f43)
1*067851b1Skevlo /*	$OpenBSD: rtwnvar.h,v 1.16 2023/04/28 01:24:14 kevlo Exp $	*/
28b9da0f5Sstsp 
38b9da0f5Sstsp /*-
48b9da0f5Sstsp  * Copyright (c) 2010 Damien Bergamini <damien.bergamini@free.fr>
58b9da0f5Sstsp  * Copyright (c) 2015 Stefan Sperling <stsp@openbsd.org>
68b9da0f5Sstsp  *
78b9da0f5Sstsp  * Permission to use, copy, modify, and distribute this software for any
88b9da0f5Sstsp  * purpose with or without fee is hereby granted, provided that the above
98b9da0f5Sstsp  * copyright notice and this permission notice appear in all copies.
108b9da0f5Sstsp  *
118b9da0f5Sstsp  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
128b9da0f5Sstsp  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
138b9da0f5Sstsp  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
148b9da0f5Sstsp  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
158b9da0f5Sstsp  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
168b9da0f5Sstsp  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
178b9da0f5Sstsp  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
188b9da0f5Sstsp  */
198b9da0f5Sstsp 
208b9da0f5Sstsp /* Operations provided by bus-specific attachment drivers. */
218b9da0f5Sstsp struct rtwn_ops {
228b9da0f5Sstsp 	void		*cookie; /* Attachment driver's private data. */
238b9da0f5Sstsp 
248b9da0f5Sstsp 	uint8_t		(*read_1)(void *, uint16_t);
258b9da0f5Sstsp 	uint16_t	(*read_2)(void *, uint16_t);
268b9da0f5Sstsp 	uint32_t	(*read_4)(void *, uint16_t);
278b9da0f5Sstsp 	void		(*write_1)(void *, uint16_t, uint8_t);
288b9da0f5Sstsp 	void		(*write_2)(void *, uint16_t, uint16_t);
298b9da0f5Sstsp 	void		(*write_4)(void *, uint16_t, uint32_t);
308b9da0f5Sstsp 	int		(*tx)(void *, struct mbuf *, struct ieee80211_node *);
315fda900fSstsp 	int		(*power_on)(void *);
32b81d0ffeSstsp 	int		(*dma_init)(void *);
3323340becSstsp 	int		(*fw_loadpage)(void *, int, uint8_t *, int);
345fda900fSstsp 	int		(*load_firmware)(void *, u_char **fw, size_t *);
352d2a7e26Skevlo 	void		(*aggr_init)(void *);
365fda900fSstsp 	void		(*mac_init)(void *);
375fda900fSstsp 	void		(*bb_init)(void *);
3823340becSstsp 	int		(*alloc_buffers)(void *);
3923340becSstsp 	int		(*init)(void *);
408b9da0f5Sstsp 	void		(*stop)(void *);
418b9da0f5Sstsp 	int		(*is_oactive)(void *);
42e9f037d1Sstsp 	void		(*next_calib)(void *);
43e9f037d1Sstsp 	void		(*cancel_calib)(void *);
44e9f037d1Sstsp 	void		(*next_scan)(void *);
45e9f037d1Sstsp 	void		(*cancel_scan)(void *);
4623340becSstsp 	void		(*wait_async)(void *);
478b9da0f5Sstsp };
488b9da0f5Sstsp 
4923340becSstsp #define RTWN_LED_LINK	0
5023340becSstsp #define RTWN_LED_DATA	1
5123340becSstsp 
52d8e41173Sjmatthew #define RTWN_92C_INT_ENABLE (R92C_IMR_ROK | R92C_IMR_VODOK | R92C_IMR_VIDOK | \
5323340becSstsp 			R92C_IMR_BEDOK | R92C_IMR_BKDOK | R92C_IMR_MGNTDOK | \
5423340becSstsp 			R92C_IMR_HIGHDOK | R92C_IMR_BDOK | R92C_IMR_RDU | \
5523340becSstsp 			R92C_IMR_RXFOVW)
56d8e41173Sjmatthew #define RTWN_88E_INT_ENABLE (R88E_HIMR_PSTIMEOUT | R88E_HIMR_HSISR_IND_ON_INT | \
57d8e41173Sjmatthew 			R88E_HIMR_C2HCMD | R88E_HIMR_ROK | R88E_HIMR_VODOK | \
58d8e41173Sjmatthew 			R88E_HIMR_VIDOK | R88E_HIMR_BEDOK | R88E_HIMR_BKDOK | \
59d8e41173Sjmatthew 			R88E_HIMR_MGNTDOK | R88E_HIMR_HIGHDOK | R88E_HIMR_RDU)
6023340becSstsp 
618b9da0f5Sstsp struct rtwn_softc {
628b9da0f5Sstsp 	/* sc_ops must be initialized by the attachment driver! */
638b9da0f5Sstsp 	struct rtwn_ops			sc_ops;
648b9da0f5Sstsp 
658b9da0f5Sstsp 	struct device			*sc_pdev;
668b9da0f5Sstsp 	struct ieee80211com		sc_ic;
678b9da0f5Sstsp 	int				(*sc_newstate)(struct ieee80211com *,
688b9da0f5Sstsp 					    enum ieee80211_state, int);
698b9da0f5Sstsp 	struct task			init_task;
708b9da0f5Sstsp 	int				ac2idx[EDCA_NUM_AC];
71799517fdSstsp 	uint32_t			sc_flags;
728b9da0f5Sstsp #define RTWN_FLAG_CCK_HIPWR		0x01
738b9da0f5Sstsp #define RTWN_FLAG_BUSY			0x02
745fda900fSstsp #define RTWN_FLAG_FORCE_RAID_11B	0x04
7534a2cadeSkevlo #define RTWN_FLAG_EXT_HDR		0x08
768b9da0f5Sstsp 
77799517fdSstsp 	uint32_t		chip;
7823340becSstsp #define RTWN_CHIP_92C		0x00000001
7923340becSstsp #define RTWN_CHIP_92C_1T2R	0x00000002
8023340becSstsp #define RTWN_CHIP_UMC		0x00000004
8123340becSstsp #define RTWN_CHIP_UMC_A_CUT	0x00000008
8223340becSstsp #define RTWN_CHIP_88C		0x00000010
8323340becSstsp #define RTWN_CHIP_88E		0x00000020
84600882e8Sjmatthew #define RTWN_CHIP_92E		0x00000040
85600882e8Sjmatthew #define RTWN_CHIP_23A		0x00000080
86600882e8Sjmatthew #define RTWN_CHIP_23B		0x00000100
87*067851b1Skevlo #define RTWN_CHIP_88F		0x00000200
8823340becSstsp 
8923340becSstsp #define RTWN_CHIP_PCI		0x40000000
9023340becSstsp #define RTWN_CHIP_USB		0x80000000
918b9da0f5Sstsp 
928b9da0f5Sstsp 	uint8_t				board_type;
9334a2cadeSkevlo 	uint8_t				crystal_cap;
948b9da0f5Sstsp 	uint8_t				regulatory;
958b9da0f5Sstsp 	uint8_t				pa_setting;
968b9da0f5Sstsp 	int				avg_pwdb;
978b9da0f5Sstsp 	int				thcal_state;
988b9da0f5Sstsp 	int				thcal_lctemp;
998b9da0f5Sstsp 	int				ntxchains;
1008b9da0f5Sstsp 	int				nrxchains;
1018b9da0f5Sstsp 	int				ledlink;
1028b9da0f5Sstsp 
1038b9da0f5Sstsp 	int				sc_tx_timer;
1048b9da0f5Sstsp 	int				fwcur;
10534a2cadeSkevlo 	union {
10634a2cadeSkevlo 		struct r92c_rom		r92c_rom;
10790540544Sjmatthew 		struct r92e_rom		r92e_rom;
10834a2cadeSkevlo 		struct r88e_rom		r88e_rom;
109*067851b1Skevlo 		struct r88f_rom		r88f_rom;
110600882e8Sjmatthew 		struct r23a_rom		r23a_rom;
11134a2cadeSkevlo 	} u;
11234a2cadeSkevlo #define sc_r92c_rom	u.r92c_rom
11390540544Sjmatthew #define sc_r92e_rom	u.r92e_rom
114626433d9Skevlo #define sc_r88e_rom	u.r88e_rom
115*067851b1Skevlo #define sc_r88f_rom	u.r88f_rom
116600882e8Sjmatthew #define sc_r23a_rom	u.r23a_rom
1175fda900fSstsp 
1188b9da0f5Sstsp 	uint32_t			rf_chnlbw[R92C_MAX_CHAINS];
1198b9da0f5Sstsp };
1208b9da0f5Sstsp 
12134a2cadeSkevlo int		rtwn_attach(struct device *, struct rtwn_softc *);
1228b9da0f5Sstsp int		rtwn_detach(struct rtwn_softc *, int);
1238b9da0f5Sstsp int		rtwn_activate(struct rtwn_softc *, int);
1248b9da0f5Sstsp int8_t		rtwn_get_rssi(struct rtwn_softc *, int, void *);
1258b9da0f5Sstsp void		rtwn_update_avgrssi(struct rtwn_softc *, int, int8_t);
126e9f037d1Sstsp void		rtwn_calib(struct rtwn_softc *);
127e9f037d1Sstsp void		rtwn_next_scan(struct rtwn_softc *);
12823340becSstsp int		rtwn_newstate(struct ieee80211com *, enum ieee80211_state, int);
129fb1f57eeSstsp void		rtwn_updateslot(struct ieee80211com *);
13023340becSstsp void		rtwn_updateedca(struct ieee80211com *);
13123340becSstsp int		rtwn_set_key(struct ieee80211com *, struct ieee80211_node *,
13223340becSstsp 		    struct ieee80211_key *);
13323340becSstsp void		rtwn_delete_key(struct ieee80211com *,
13423340becSstsp 		    struct ieee80211_node *, struct ieee80211_key *);
13523340becSstsp int		rtwn_ioctl(struct ifnet *, u_long, caddr_t);
13623340becSstsp void		rtwn_start(struct ifnet *);
13723340becSstsp void		rtwn_fw_reset(struct rtwn_softc *);
138