xref: /openbsd/sys/dev/ic/bwfmvar.h (revision ec9994a1)
1 /* $OpenBSD: bwfmvar.h,v 1.31 2022/03/06 18:52:47 kettenis Exp $ */
2 /*
3  * Copyright (c) 2010-2016 Broadcom Corporation
4  * Copyright (c) 2016,2017 Patrick Wildt <patrick@blueri.se>
5  *
6  * Permission to use, copy, modify, and/or distribute this software for any
7  * purpose with or without fee is hereby granted, provided that the above
8  * copyright notice and this permission notice appear in all copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17  */
18 
19 /* Chipcommon Core Chip IDs */
20 #define BRCM_CC_43143_CHIP_ID		43143
21 #define BRCM_CC_43235_CHIP_ID		43235
22 #define BRCM_CC_43236_CHIP_ID		43236
23 #define BRCM_CC_43238_CHIP_ID		43238
24 #define BRCM_CC_43241_CHIP_ID		0x4324
25 #define BRCM_CC_43242_CHIP_ID		43242
26 #define BRCM_CC_4329_CHIP_ID		0x4329
27 #define BRCM_CC_4330_CHIP_ID		0x4330
28 #define BRCM_CC_4334_CHIP_ID		0x4334
29 #define BRCM_CC_43340_CHIP_ID		43340
30 #define BRCM_CC_43341_CHIP_ID		43341
31 #define BRCM_CC_43362_CHIP_ID		43362
32 #define BRCM_CC_4335_CHIP_ID		0x4335
33 #define BRCM_CC_4339_CHIP_ID		0x4339
34 #define BRCM_CC_43430_CHIP_ID		43430
35 #define BRCM_CC_4345_CHIP_ID		0x4345
36 #define BRCM_CC_43465_CHIP_ID		43465
37 #define BRCM_CC_4350_CHIP_ID		0x4350
38 #define BRCM_CC_43525_CHIP_ID		43525
39 #define BRCM_CC_4354_CHIP_ID		0x4354
40 #define BRCM_CC_4355_CHIP_ID		0x4355
41 #define BRCM_CC_4356_CHIP_ID		0x4356
42 #define BRCM_CC_43566_CHIP_ID		43566
43 #define BRCM_CC_43567_CHIP_ID		43567
44 #define BRCM_CC_43569_CHIP_ID		43569
45 #define BRCM_CC_43570_CHIP_ID		43570
46 #define BRCM_CC_4358_CHIP_ID		0x4358
47 #define BRCM_CC_4359_CHIP_ID		0x4359
48 #define BRCM_CC_43602_CHIP_ID		43602
49 #define BRCM_CC_4364_CHIP_ID		0x4364
50 #define BRCM_CC_4365_CHIP_ID		0x4365
51 #define BRCM_CC_4366_CHIP_ID		0x4366
52 #define BRCM_CC_43664_CHIP_ID		43664
53 #define BRCM_CC_43666_CHIP_ID		43666
54 #define BRCM_CC_4371_CHIP_ID		0x4371
55 #define BRCM_CC_4377_CHIP_ID		0x4377
56 #define BRCM_CC_4378_CHIP_ID		0x4378
57 #define BRCM_CC_4387_CHIP_ID		0x4387
58 #define CY_CC_4373_CHIP_ID		0x4373
59 #define CY_CC_43012_CHIP_ID		43012
60 #define CY_CC_43752_CHIP_ID		43752
61 
62 /* Defaults */
63 #define BWFM_DEFAULT_SCAN_CHANNEL_TIME	40
64 #define BWFM_DEFAULT_SCAN_UNASSOC_TIME	40
65 #define BWFM_DEFAULT_SCAN_PASSIVE_TIME	120
66 
67 
68 struct bwfm_softc;
69 
70 struct bwfm_core {
71 	uint16_t	 co_id;
72 	uint16_t	 co_rev;
73 	uint32_t	 co_base;
74 	uint32_t	 co_wrapbase;
75 	LIST_ENTRY(bwfm_core) co_link;
76 };
77 
78 struct bwfm_chip {
79 	uint32_t	 ch_chip;
80 	uint32_t	 ch_chiprev;
81 	uint32_t	 ch_cc_caps;
82 	uint32_t	 ch_cc_caps_ext;
83 	uint32_t	 ch_pmucaps;
84 	uint32_t	 ch_pmurev;
85 	uint32_t	 ch_rambase;
86 	uint32_t	 ch_ramsize;
87 	uint32_t	 ch_srsize;
88 	char		 ch_name[8];
89 	LIST_HEAD(,bwfm_core) ch_list;
90 	int (*ch_core_isup)(struct bwfm_softc *, struct bwfm_core *);
91 	void (*ch_core_disable)(struct bwfm_softc *, struct bwfm_core *,
92 	    uint32_t prereset, uint32_t reset);
93 	void (*ch_core_reset)(struct bwfm_softc *, struct bwfm_core *,
94 	    uint32_t prereset, uint32_t reset, uint32_t postreset);
95 };
96 
97 struct bwfm_bus_ops {
98 	int (*bs_preinit)(struct bwfm_softc *);
99 	void (*bs_stop)(struct bwfm_softc *);
100 	int (*bs_txcheck)(struct bwfm_softc *);
101 	int (*bs_txdata)(struct bwfm_softc *, struct mbuf *);
102 	int (*bs_txctl)(struct bwfm_softc *, void *);
103 };
104 
105 struct bwfm_buscore_ops {
106 	uint32_t (*bc_read)(struct bwfm_softc *, uint32_t);
107 	void (*bc_write)(struct bwfm_softc *, uint32_t, uint32_t);
108 	int (*bc_prepare)(struct bwfm_softc *);
109 	int (*bc_reset)(struct bwfm_softc *);
110 	int (*bc_setup)(struct bwfm_softc *);
111 	void (*bc_activate)(struct bwfm_softc *, uint32_t);
112 };
113 
114 struct bwfm_proto_ops {
115 	int (*proto_query_dcmd)(struct bwfm_softc *, int, int,
116 	    char *, size_t *);
117 	int (*proto_set_dcmd)(struct bwfm_softc *, int, int,
118 	    char *, size_t);
119 	void (*proto_rx)(struct bwfm_softc *, struct mbuf *,
120 	    struct mbuf_list *);
121 	void (*proto_rxctl)(struct bwfm_softc *, char *, size_t);
122 };
123 extern struct bwfm_proto_ops bwfm_proto_bcdc_ops;
124 
125 struct bwfm_host_cmd {
126 	void	 (*cb)(struct bwfm_softc *, void *);
127 	uint8_t	 data[256];
128 };
129 
130 struct bwfm_cmd_key {
131 	struct ieee80211_node	 *ni;
132 	struct ieee80211_key	 *k;
133 };
134 
135 struct bwfm_cmd_flowring_create {
136 	struct mbuf		*m;
137 	int			 flowid;
138 	int			 prio;
139 };
140 
141 struct bwfm_cmd_flowring_delete {
142 	int			 flowid;
143 };
144 
145 struct bwfm_host_cmd_ring {
146 #define BWFM_HOST_CMD_RING_COUNT	32
147 	struct bwfm_host_cmd	 cmd[BWFM_HOST_CMD_RING_COUNT];
148 	int			 cur;
149 	int			 next;
150 	int			 queued;
151 };
152 
153 struct bwfm_proto_bcdc_ctl {
154 	int				 reqid;
155 	char				*buf;
156 	size_t				 len;
157 	int				 done;
158 	TAILQ_ENTRY(bwfm_proto_bcdc_ctl) next;
159 };
160 
161 struct bwfm_softc {
162 	struct device		 sc_dev;
163 	struct ieee80211com	 sc_ic;
164 	struct ifmedia		 sc_media;
165 	struct bwfm_bus_ops	*sc_bus_ops;
166 	struct bwfm_buscore_ops	*sc_buscore_ops;
167 	struct bwfm_proto_ops	*sc_proto_ops;
168 	struct bwfm_chip	 sc_chip;
169 	uint8_t			 sc_io_type;
170 #define		BWFM_IO_TYPE_D11N		1
171 #define		BWFM_IO_TYPE_D11AC		2
172 
173 	int			 sc_node;
174 	int			 sc_initialized;
175 	int			 sc_tx_timer;
176 
177 	int			 sc_scan_ver;
178 
179 	int			 (*sc_newstate)(struct ieee80211com *,
180 				     enum ieee80211_state, int);
181 	struct bwfm_host_cmd_ring sc_cmdq;
182 	struct taskq		*sc_taskq;
183 	struct task		 sc_task;
184 	struct mbuf_list	 sc_evml;
185 
186 	int			 sc_bcdc_reqid;
187 	TAILQ_HEAD(, bwfm_proto_bcdc_ctl) sc_bcdc_rxctlq;
188 
189 	char			 sc_fwdir[16];
190 	u_char			*sc_clm;
191 	size_t			 sc_clmsize;
192 	u_char			*sc_txcap;
193 	size_t			 sc_txcapsize;
194 	u_char			*sc_cal;
195 	size_t			 sc_calsize;
196 	int			 sc_key_tasks;
197 
198 	char			 sc_board_type[128];
199 	char			 sc_module[8];
200 	char			 sc_vendor[8];
201 	char			 sc_modrev[8];
202 };
203 
204 void bwfm_attach(struct bwfm_softc *);
205 void bwfm_attachhook(struct device *);
206 int bwfm_preinit(struct bwfm_softc *);
207 void bwfm_cleanup(struct bwfm_softc *);
208 int bwfm_detach(struct bwfm_softc *, int);
209 int bwfm_activate(struct bwfm_softc *, int);
210 int bwfm_chip_attach(struct bwfm_softc *);
211 int bwfm_chip_set_active(struct bwfm_softc *, uint32_t);
212 void bwfm_chip_set_passive(struct bwfm_softc *);
213 int bwfm_chip_sr_capable(struct bwfm_softc *);
214 struct bwfm_core *bwfm_chip_get_core(struct bwfm_softc *, int);
215 struct bwfm_core *bwfm_chip_get_pmu(struct bwfm_softc *);
216 void bwfm_rx(struct bwfm_softc *, struct mbuf *, struct mbuf_list *);
217 void bwfm_do_async(struct bwfm_softc *, void (*)(struct bwfm_softc *, void *),
218     void *, int);
219 int bwfm_nvram_convert(int, u_char **, size_t *, size_t *);
220 int bwfm_loadfirmware(struct bwfm_softc *, const char *, const char *,
221     u_char **, size_t *, u_char **, size_t *, size_t *);
222