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