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