bwfmvar.h revision 1.14 1 1.14 mlelstv /* $NetBSD: bwfmvar.h,v 1.14 2022/12/03 16:06:20 mlelstv Exp $ */
2 1.1 jmcneill /* $OpenBSD: bwfmvar.h,v 1.1 2017/10/11 17:19:50 patrick Exp $ */
3 1.1 jmcneill /*
4 1.1 jmcneill * Copyright (c) 2010-2016 Broadcom Corporation
5 1.1 jmcneill * Copyright (c) 2016,2017 Patrick Wildt <patrick (at) blueri.se>
6 1.1 jmcneill *
7 1.1 jmcneill * Permission to use, copy, modify, and/or distribute this software for any
8 1.1 jmcneill * purpose with or without fee is hereby granted, provided that the above
9 1.1 jmcneill * copyright notice and this permission notice appear in all copies.
10 1.1 jmcneill *
11 1.1 jmcneill * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 1.1 jmcneill * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 1.1 jmcneill * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 1.1 jmcneill * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 1.1 jmcneill * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 1.1 jmcneill * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 1.1 jmcneill * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 1.1 jmcneill */
19 1.1 jmcneill
20 1.11 riastrad #ifndef _DEV_IC_BWFMVAR_H
21 1.11 riastrad #define _DEV_IC_BWFMVAR_H
22 1.11 riastrad
23 1.11 riastrad #include <sys/types.h>
24 1.11 riastrad
25 1.11 riastrad #include <sys/cdefs.h>
26 1.11 riastrad #include <sys/device_if.h>
27 1.11 riastrad #include <sys/queue.h>
28 1.11 riastrad #include <sys/workqueue.h>
29 1.11 riastrad
30 1.11 riastrad #include <net/if_ether.h>
31 1.11 riastrad
32 1.11 riastrad #include <net80211/ieee80211.h>
33 1.11 riastrad #include <net80211/ieee80211_proto.h>
34 1.11 riastrad #include <net80211/ieee80211_var.h>
35 1.11 riastrad
36 1.11 riastrad struct ieee80211_key;
37 1.11 riastrad struct mbuf;
38 1.12 riastrad struct pool_cache;
39 1.2 maya
40 1.1 jmcneill /* Chipcommon Core Chip IDs */
41 1.1 jmcneill #define BRCM_CC_43143_CHIP_ID 43143
42 1.1 jmcneill #define BRCM_CC_43235_CHIP_ID 43235
43 1.1 jmcneill #define BRCM_CC_43236_CHIP_ID 43236
44 1.1 jmcneill #define BRCM_CC_43238_CHIP_ID 43238
45 1.1 jmcneill #define BRCM_CC_43241_CHIP_ID 0x4324
46 1.1 jmcneill #define BRCM_CC_43242_CHIP_ID 43242
47 1.1 jmcneill #define BRCM_CC_4329_CHIP_ID 0x4329
48 1.1 jmcneill #define BRCM_CC_4330_CHIP_ID 0x4330
49 1.1 jmcneill #define BRCM_CC_4334_CHIP_ID 0x4334
50 1.1 jmcneill #define BRCM_CC_43340_CHIP_ID 43340
51 1.6 thorpej #define BRCM_CC_43341_CHIP_ID 43341
52 1.1 jmcneill #define BRCM_CC_43362_CHIP_ID 43362
53 1.13 mlelstv #define BRCM_CC_43364_CHIP_ID 43364
54 1.1 jmcneill #define BRCM_CC_4335_CHIP_ID 0x4335
55 1.1 jmcneill #define BRCM_CC_4339_CHIP_ID 0x4339
56 1.1 jmcneill #define BRCM_CC_43430_CHIP_ID 43430
57 1.1 jmcneill #define BRCM_CC_4345_CHIP_ID 0x4345
58 1.2 maya #define BRCM_CC_43465_CHIP_ID 43465
59 1.1 jmcneill #define BRCM_CC_4350_CHIP_ID 0x4350
60 1.2 maya #define BRCM_CC_43525_CHIP_ID 43525
61 1.1 jmcneill #define BRCM_CC_4354_CHIP_ID 0x4354
62 1.1 jmcneill #define BRCM_CC_4356_CHIP_ID 0x4356
63 1.1 jmcneill #define BRCM_CC_43566_CHIP_ID 43566
64 1.1 jmcneill #define BRCM_CC_43567_CHIP_ID 43567
65 1.1 jmcneill #define BRCM_CC_43569_CHIP_ID 43569
66 1.1 jmcneill #define BRCM_CC_43570_CHIP_ID 43570
67 1.1 jmcneill #define BRCM_CC_4358_CHIP_ID 0x4358
68 1.1 jmcneill #define BRCM_CC_4359_CHIP_ID 0x4359
69 1.1 jmcneill #define BRCM_CC_43602_CHIP_ID 43602
70 1.1 jmcneill #define BRCM_CC_4365_CHIP_ID 0x4365
71 1.1 jmcneill #define BRCM_CC_4366_CHIP_ID 0x4366
72 1.6 thorpej #define BRCM_CC_43664_CHIP_ID 43664
73 1.1 jmcneill #define BRCM_CC_4371_CHIP_ID 0x4371
74 1.2 maya #define CY_CC_4373_CHIP_ID 0x4373
75 1.6 thorpej #define CY_CC_43012_CHIP_ID 43012
76 1.1 jmcneill
77 1.1 jmcneill /* Defaults */
78 1.1 jmcneill #define BWFM_DEFAULT_SCAN_CHANNEL_TIME 40
79 1.1 jmcneill #define BWFM_DEFAULT_SCAN_UNASSOC_TIME 40
80 1.1 jmcneill #define BWFM_DEFAULT_SCAN_PASSIVE_TIME 120
81 1.1 jmcneill
82 1.4 mlelstv #define BWFM_TASK_COUNT 256
83 1.1 jmcneill
84 1.7 thorpej struct bwfm_softc;
85 1.1 jmcneill
86 1.7 thorpej struct bwfm_firmware_selector {
87 1.7 thorpej uint32_t fwsel_chip; /* chip ID */
88 1.7 thorpej uint32_t fwsel_revmask; /* mask of applicable chip revs */
89 1.7 thorpej const char *fwsel_basename;/* firmware file base name */
90 1.7 thorpej };
91 1.7 thorpej #define BWFM_FW_ENTRY(c, r, b) \
92 1.7 thorpej { .fwsel_chip = (c), \
93 1.7 thorpej .fwsel_revmask = (r), \
94 1.7 thorpej .fwsel_basename = b }
95 1.7 thorpej
96 1.7 thorpej #define BWFM_FW_ENTRY_END \
97 1.7 thorpej { .fwsel_basename = NULL }
98 1.7 thorpej
99 1.7 thorpej #define BWFM_FWSEL_REV_EQ(x) __BIT(x)
100 1.7 thorpej #define BWFM_FWSEL_REV_LE(x) __BITS(0,x)
101 1.7 thorpej #define BWFM_FWSEL_REV_GE(x) __BITS(x,31)
102 1.7 thorpej #define BWFM_FWSEL_ALLREVS __BITS(0,31)
103 1.7 thorpej
104 1.7 thorpej #define BWFM_FILETYPE_UCODE 0
105 1.7 thorpej #define BWFM_FILETYPE_NVRAM 1
106 1.8 thorpej #define BWFM_FILETYPE_CLM 2
107 1.13 mlelstv #define BWFM_FILETYPE_TXCAP 3
108 1.13 mlelstv #define BWFM_FILETYPE_CAL 4
109 1.13 mlelstv #define BWFM_NFILETYPES 5
110 1.7 thorpej
111 1.7 thorpej struct bwfm_firmware_context {
112 1.7 thorpej /* inputs */
113 1.7 thorpej uint32_t ctx_chip;
114 1.7 thorpej uint32_t ctx_chiprev;
115 1.7 thorpej const char * ctx_model;
116 1.7 thorpej uint32_t ctx_req;
117 1.7 thorpej
118 1.7 thorpej #define BWFM_FWREQ(x) __BIT(x)
119 1.7 thorpej #define BWFM_FWOPT(x) __BIT((x)+16)
120 1.7 thorpej
121 1.7 thorpej /* outputs */
122 1.7 thorpej struct {
123 1.7 thorpej void * ctx_f_data;
124 1.7 thorpej size_t ctx_f_size;
125 1.7 thorpej } ctx_file[BWFM_NFILETYPES];
126 1.7 thorpej };
127 1.1 jmcneill
128 1.1 jmcneill struct bwfm_core {
129 1.1 jmcneill uint16_t co_id;
130 1.1 jmcneill uint16_t co_rev;
131 1.1 jmcneill uint32_t co_base;
132 1.1 jmcneill uint32_t co_wrapbase;
133 1.1 jmcneill LIST_ENTRY(bwfm_core) co_link;
134 1.1 jmcneill };
135 1.1 jmcneill
136 1.1 jmcneill struct bwfm_chip {
137 1.1 jmcneill uint32_t ch_chip;
138 1.1 jmcneill uint32_t ch_chiprev;
139 1.1 jmcneill uint32_t ch_cc_caps;
140 1.1 jmcneill uint32_t ch_cc_caps_ext;
141 1.1 jmcneill uint32_t ch_pmucaps;
142 1.1 jmcneill uint32_t ch_pmurev;
143 1.1 jmcneill uint32_t ch_rambase;
144 1.1 jmcneill uint32_t ch_ramsize;
145 1.1 jmcneill uint32_t ch_srsize;
146 1.1 jmcneill char ch_name[8];
147 1.1 jmcneill LIST_HEAD(,bwfm_core) ch_list;
148 1.1 jmcneill int (*ch_core_isup)(struct bwfm_softc *, struct bwfm_core *);
149 1.1 jmcneill void (*ch_core_disable)(struct bwfm_softc *, struct bwfm_core *,
150 1.1 jmcneill uint32_t prereset, uint32_t reset);
151 1.1 jmcneill void (*ch_core_reset)(struct bwfm_softc *, struct bwfm_core *,
152 1.1 jmcneill uint32_t prereset, uint32_t reset, uint32_t postreset);
153 1.1 jmcneill };
154 1.1 jmcneill
155 1.1 jmcneill struct bwfm_bus_ops {
156 1.1 jmcneill void (*bs_init)(struct bwfm_softc *);
157 1.1 jmcneill void (*bs_stop)(struct bwfm_softc *);
158 1.2 maya int (*bs_txcheck)(struct bwfm_softc *);
159 1.3 riastrad int (*bs_txdata)(struct bwfm_softc *, struct mbuf **);
160 1.1 jmcneill int (*bs_txctl)(struct bwfm_softc *, char *, size_t);
161 1.1 jmcneill int (*bs_rxctl)(struct bwfm_softc *, char *, size_t *);
162 1.1 jmcneill };
163 1.1 jmcneill
164 1.1 jmcneill struct bwfm_buscore_ops {
165 1.1 jmcneill uint32_t (*bc_read)(struct bwfm_softc *, uint32_t);
166 1.1 jmcneill void (*bc_write)(struct bwfm_softc *, uint32_t, uint32_t);
167 1.1 jmcneill int (*bc_prepare)(struct bwfm_softc *);
168 1.1 jmcneill int (*bc_reset)(struct bwfm_softc *);
169 1.1 jmcneill int (*bc_setup)(struct bwfm_softc *);
170 1.2 maya void (*bc_activate)(struct bwfm_softc *, const uint32_t);
171 1.1 jmcneill };
172 1.1 jmcneill
173 1.1 jmcneill struct bwfm_proto_ops {
174 1.1 jmcneill int (*proto_query_dcmd)(struct bwfm_softc *, int, int,
175 1.1 jmcneill char *, size_t *);
176 1.1 jmcneill int (*proto_set_dcmd)(struct bwfm_softc *, int, int,
177 1.1 jmcneill char *, size_t);
178 1.1 jmcneill };
179 1.9 jdolecek extern const struct bwfm_proto_ops bwfm_proto_bcdc_ops;
180 1.1 jmcneill
181 1.1 jmcneill enum bwfm_task_cmd {
182 1.1 jmcneill BWFM_TASK_NEWSTATE,
183 1.1 jmcneill BWFM_TASK_KEY_SET,
184 1.1 jmcneill BWFM_TASK_KEY_DELETE,
185 1.4 mlelstv BWFM_TASK_RX_EVENT,
186 1.1 jmcneill };
187 1.1 jmcneill
188 1.1 jmcneill struct bwfm_cmd_newstate {
189 1.1 jmcneill enum ieee80211_state state;
190 1.1 jmcneill int arg;
191 1.1 jmcneill };
192 1.1 jmcneill
193 1.1 jmcneill struct bwfm_cmd_key {
194 1.1 jmcneill const struct ieee80211_key *key;
195 1.1 jmcneill uint8_t mac[IEEE80211_ADDR_LEN];
196 1.1 jmcneill };
197 1.1 jmcneill
198 1.1 jmcneill struct bwfm_task {
199 1.1 jmcneill struct work t_work;
200 1.1 jmcneill struct bwfm_softc *t_sc;
201 1.1 jmcneill enum bwfm_task_cmd t_cmd;
202 1.1 jmcneill union {
203 1.1 jmcneill struct bwfm_cmd_newstate newstate;
204 1.1 jmcneill struct bwfm_cmd_key key;
205 1.4 mlelstv struct mbuf *mbuf;
206 1.1 jmcneill } t_u;
207 1.1 jmcneill #define t_newstate t_u.newstate
208 1.1 jmcneill #define t_key t_u.key
209 1.4 mlelstv #define t_mbuf t_u.mbuf
210 1.1 jmcneill };
211 1.1 jmcneill
212 1.1 jmcneill struct bwfm_softc {
213 1.1 jmcneill device_t sc_dev;
214 1.1 jmcneill struct ieee80211com sc_ic;
215 1.1 jmcneill struct ethercom sc_ec;
216 1.1 jmcneill #define sc_if sc_ec.ec_if
217 1.1 jmcneill
218 1.9 jdolecek const struct bwfm_bus_ops *sc_bus_ops;
219 1.9 jdolecek const struct bwfm_buscore_ops *sc_buscore_ops;
220 1.9 jdolecek const struct bwfm_proto_ops *sc_proto_ops;
221 1.1 jmcneill struct bwfm_chip sc_chip;
222 1.1 jmcneill uint8_t sc_io_type;
223 1.1 jmcneill #define BWFM_IO_TYPE_D11N 1
224 1.1 jmcneill #define BWFM_IO_TYPE_D11AC 2
225 1.1 jmcneill
226 1.1 jmcneill int sc_tx_timer;
227 1.1 jmcneill
228 1.1 jmcneill bool sc_if_attached;
229 1.12 riastrad struct pool_cache *sc_freetask;
230 1.1 jmcneill struct workqueue *sc_taskq;
231 1.1 jmcneill
232 1.1 jmcneill int (*sc_newstate)(struct ieee80211com *,
233 1.1 jmcneill enum ieee80211_state, int);
234 1.5 mlelstv
235 1.5 mlelstv int sc_bcdc_reqid;
236 1.10 jdolecek
237 1.10 jdolecek union {
238 1.10 jdolecek struct bwfm_bss_info bss_info;
239 1.10 jdolecek uint8_t padding[BWFM_BSS_INFO_BUFLEN];
240 1.10 jdolecek } sc_bss_buf;
241 1.13 mlelstv
242 1.13 mlelstv uint8_t *sc_clm;
243 1.13 mlelstv size_t sc_clmsize;
244 1.13 mlelstv uint8_t *sc_txcap;
245 1.13 mlelstv size_t sc_txcapsize;
246 1.13 mlelstv uint8_t *sc_cal;
247 1.13 mlelstv size_t sc_calsize;
248 1.14 mlelstv
249 1.14 mlelstv int sc_pm;
250 1.14 mlelstv bool sc_setpm;
251 1.1 jmcneill };
252 1.1 jmcneill
253 1.1 jmcneill void bwfm_attach(struct bwfm_softc *);
254 1.2 maya void bwfm_chip_socram_ramsize(struct bwfm_softc *, struct bwfm_core *);
255 1.2 maya void bwfm_chip_sysmem_ramsize(struct bwfm_softc *, struct bwfm_core *);
256 1.2 maya void bwfm_chip_tcm_ramsize(struct bwfm_softc *, struct bwfm_core *);
257 1.2 maya void bwfm_chip_tcm_rambase(struct bwfm_softc *);
258 1.2 maya void bwfm_start(struct ifnet *);
259 1.1 jmcneill int bwfm_detach(struct bwfm_softc *, int);
260 1.1 jmcneill int bwfm_chip_attach(struct bwfm_softc *);
261 1.2 maya int bwfm_chip_set_active(struct bwfm_softc *, uint32_t);
262 1.2 maya void bwfm_chip_set_passive(struct bwfm_softc *);
263 1.4 mlelstv int bwfm_chip_sr_capable(struct bwfm_softc *);
264 1.1 jmcneill struct bwfm_core *bwfm_chip_get_core(struct bwfm_softc *, int);
265 1.1 jmcneill struct bwfm_core *bwfm_chip_get_pmu(struct bwfm_softc *);
266 1.2 maya void bwfm_rx(struct bwfm_softc *, struct mbuf *m);
267 1.7 thorpej
268 1.7 thorpej void bwfm_firmware_context_init(struct bwfm_firmware_context *,
269 1.7 thorpej uint32_t, uint32_t, const char *, uint32_t);
270 1.7 thorpej bool bwfm_firmware_open(struct bwfm_softc *,
271 1.7 thorpej const struct bwfm_firmware_selector *,
272 1.7 thorpej struct bwfm_firmware_context *);
273 1.7 thorpej void bwfm_firmware_close(struct bwfm_firmware_context *);
274 1.7 thorpej void * bwfm_firmware_data(struct bwfm_firmware_context *,
275 1.7 thorpej unsigned int, size_t *);
276 1.7 thorpej const char *bwfm_firmware_description(unsigned int);
277 1.11 riastrad
278 1.11 riastrad #endif /* _DEV_IC_BWFMVAR_H */
279