xref: /openbsd/sys/dev/ic/rtwnvar.h (revision 067851b1)
1 /*	$OpenBSD: rtwnvar.h,v 1.16 2023/04/28 01:24:14 kevlo Exp $	*/
2 
3 /*-
4  * Copyright (c) 2010 Damien Bergamini <damien.bergamini@free.fr>
5  * Copyright (c) 2015 Stefan Sperling <stsp@openbsd.org>
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 /* Operations provided by bus-specific attachment drivers. */
21 struct rtwn_ops {
22 	void		*cookie; /* Attachment driver's private data. */
23 
24 	uint8_t		(*read_1)(void *, uint16_t);
25 	uint16_t	(*read_2)(void *, uint16_t);
26 	uint32_t	(*read_4)(void *, uint16_t);
27 	void		(*write_1)(void *, uint16_t, uint8_t);
28 	void		(*write_2)(void *, uint16_t, uint16_t);
29 	void		(*write_4)(void *, uint16_t, uint32_t);
30 	int		(*tx)(void *, struct mbuf *, struct ieee80211_node *);
31 	int		(*power_on)(void *);
32 	int		(*dma_init)(void *);
33 	int		(*fw_loadpage)(void *, int, uint8_t *, int);
34 	int		(*load_firmware)(void *, u_char **fw, size_t *);
35 	void		(*aggr_init)(void *);
36 	void		(*mac_init)(void *);
37 	void		(*bb_init)(void *);
38 	int		(*alloc_buffers)(void *);
39 	int		(*init)(void *);
40 	void		(*stop)(void *);
41 	int		(*is_oactive)(void *);
42 	void		(*next_calib)(void *);
43 	void		(*cancel_calib)(void *);
44 	void		(*next_scan)(void *);
45 	void		(*cancel_scan)(void *);
46 	void		(*wait_async)(void *);
47 };
48 
49 #define RTWN_LED_LINK	0
50 #define RTWN_LED_DATA	1
51 
52 #define RTWN_92C_INT_ENABLE (R92C_IMR_ROK | R92C_IMR_VODOK | R92C_IMR_VIDOK | \
53 			R92C_IMR_BEDOK | R92C_IMR_BKDOK | R92C_IMR_MGNTDOK | \
54 			R92C_IMR_HIGHDOK | R92C_IMR_BDOK | R92C_IMR_RDU | \
55 			R92C_IMR_RXFOVW)
56 #define RTWN_88E_INT_ENABLE (R88E_HIMR_PSTIMEOUT | R88E_HIMR_HSISR_IND_ON_INT | \
57 			R88E_HIMR_C2HCMD | R88E_HIMR_ROK | R88E_HIMR_VODOK | \
58 			R88E_HIMR_VIDOK | R88E_HIMR_BEDOK | R88E_HIMR_BKDOK | \
59 			R88E_HIMR_MGNTDOK | R88E_HIMR_HIGHDOK | R88E_HIMR_RDU)
60 
61 struct rtwn_softc {
62 	/* sc_ops must be initialized by the attachment driver! */
63 	struct rtwn_ops			sc_ops;
64 
65 	struct device			*sc_pdev;
66 	struct ieee80211com		sc_ic;
67 	int				(*sc_newstate)(struct ieee80211com *,
68 					    enum ieee80211_state, int);
69 	struct task			init_task;
70 	int				ac2idx[EDCA_NUM_AC];
71 	uint32_t			sc_flags;
72 #define RTWN_FLAG_CCK_HIPWR		0x01
73 #define RTWN_FLAG_BUSY			0x02
74 #define RTWN_FLAG_FORCE_RAID_11B	0x04
75 #define RTWN_FLAG_EXT_HDR		0x08
76 
77 	uint32_t		chip;
78 #define RTWN_CHIP_92C		0x00000001
79 #define RTWN_CHIP_92C_1T2R	0x00000002
80 #define RTWN_CHIP_UMC		0x00000004
81 #define RTWN_CHIP_UMC_A_CUT	0x00000008
82 #define RTWN_CHIP_88C		0x00000010
83 #define RTWN_CHIP_88E		0x00000020
84 #define RTWN_CHIP_92E		0x00000040
85 #define RTWN_CHIP_23A		0x00000080
86 #define RTWN_CHIP_23B		0x00000100
87 #define RTWN_CHIP_88F		0x00000200
88 
89 #define RTWN_CHIP_PCI		0x40000000
90 #define RTWN_CHIP_USB		0x80000000
91 
92 	uint8_t				board_type;
93 	uint8_t				crystal_cap;
94 	uint8_t				regulatory;
95 	uint8_t				pa_setting;
96 	int				avg_pwdb;
97 	int				thcal_state;
98 	int				thcal_lctemp;
99 	int				ntxchains;
100 	int				nrxchains;
101 	int				ledlink;
102 
103 	int				sc_tx_timer;
104 	int				fwcur;
105 	union {
106 		struct r92c_rom		r92c_rom;
107 		struct r92e_rom		r92e_rom;
108 		struct r88e_rom		r88e_rom;
109 		struct r88f_rom		r88f_rom;
110 		struct r23a_rom		r23a_rom;
111 	} u;
112 #define sc_r92c_rom	u.r92c_rom
113 #define sc_r92e_rom	u.r92e_rom
114 #define sc_r88e_rom	u.r88e_rom
115 #define sc_r88f_rom	u.r88f_rom
116 #define sc_r23a_rom	u.r23a_rom
117 
118 	uint32_t			rf_chnlbw[R92C_MAX_CHAINS];
119 };
120 
121 int		rtwn_attach(struct device *, struct rtwn_softc *);
122 int		rtwn_detach(struct rtwn_softc *, int);
123 int		rtwn_activate(struct rtwn_softc *, int);
124 int8_t		rtwn_get_rssi(struct rtwn_softc *, int, void *);
125 void		rtwn_update_avgrssi(struct rtwn_softc *, int, int8_t);
126 void		rtwn_calib(struct rtwn_softc *);
127 void		rtwn_next_scan(struct rtwn_softc *);
128 int		rtwn_newstate(struct ieee80211com *, enum ieee80211_state, int);
129 void		rtwn_updateslot(struct ieee80211com *);
130 void		rtwn_updateedca(struct ieee80211com *);
131 int		rtwn_set_key(struct ieee80211com *, struct ieee80211_node *,
132 		    struct ieee80211_key *);
133 void		rtwn_delete_key(struct ieee80211com *,
134 		    struct ieee80211_node *, struct ieee80211_key *);
135 int		rtwn_ioctl(struct ifnet *, u_long, caddr_t);
136 void		rtwn_start(struct ifnet *);
137 void		rtwn_fw_reset(struct rtwn_softc *);
138