bwfmvar.h revision 1.6 1 /* $NetBSD: bwfmvar.h,v 1.6 2020/03/22 23:38:47 thorpej 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
22 /* Chipcommon Core Chip IDs */
23 #define BRCM_CC_43143_CHIP_ID 43143
24 #define BRCM_CC_43235_CHIP_ID 43235
25 #define BRCM_CC_43236_CHIP_ID 43236
26 #define BRCM_CC_43238_CHIP_ID 43238
27 #define BRCM_CC_43241_CHIP_ID 0x4324
28 #define BRCM_CC_43242_CHIP_ID 43242
29 #define BRCM_CC_4329_CHIP_ID 0x4329
30 #define BRCM_CC_4330_CHIP_ID 0x4330
31 #define BRCM_CC_4334_CHIP_ID 0x4334
32 #define BRCM_CC_43340_CHIP_ID 43340
33 #define BRCM_CC_43341_CHIP_ID 43341
34 #define BRCM_CC_43362_CHIP_ID 43362
35 #define BRCM_CC_4335_CHIP_ID 0x4335
36 #define BRCM_CC_4339_CHIP_ID 0x4339
37 #define BRCM_CC_43430_CHIP_ID 43430
38 #define BRCM_CC_4345_CHIP_ID 0x4345
39 #define BRCM_CC_43465_CHIP_ID 43465
40 #define BRCM_CC_4350_CHIP_ID 0x4350
41 #define BRCM_CC_43525_CHIP_ID 43525
42 #define BRCM_CC_4354_CHIP_ID 0x4354
43 #define BRCM_CC_4356_CHIP_ID 0x4356
44 #define BRCM_CC_43566_CHIP_ID 43566
45 #define BRCM_CC_43567_CHIP_ID 43567
46 #define BRCM_CC_43569_CHIP_ID 43569
47 #define BRCM_CC_43570_CHIP_ID 43570
48 #define BRCM_CC_4358_CHIP_ID 0x4358
49 #define BRCM_CC_4359_CHIP_ID 0x4359
50 #define BRCM_CC_43602_CHIP_ID 43602
51 #define BRCM_CC_4365_CHIP_ID 0x4365
52 #define BRCM_CC_4366_CHIP_ID 0x4366
53 #define BRCM_CC_43664_CHIP_ID 43664
54 #define BRCM_CC_4371_CHIP_ID 0x4371
55 #define CY_CC_4373_CHIP_ID 0x4373
56 #define CY_CC_43012_CHIP_ID 43012
57
58 /* Defaults */
59 #define BWFM_DEFAULT_SCAN_CHANNEL_TIME 40
60 #define BWFM_DEFAULT_SCAN_UNASSOC_TIME 40
61 #define BWFM_DEFAULT_SCAN_PASSIVE_TIME 120
62
63 #define BWFM_TASK_COUNT 256
64
65
66 struct bwfm_softc;
67
68 struct bwfm_core {
69 uint16_t co_id;
70 uint16_t co_rev;
71 uint32_t co_base;
72 uint32_t co_wrapbase;
73 LIST_ENTRY(bwfm_core) co_link;
74 };
75
76 struct bwfm_chip {
77 uint32_t ch_chip;
78 uint32_t ch_chiprev;
79 uint32_t ch_cc_caps;
80 uint32_t ch_cc_caps_ext;
81 uint32_t ch_pmucaps;
82 uint32_t ch_pmurev;
83 uint32_t ch_rambase;
84 uint32_t ch_ramsize;
85 uint32_t ch_srsize;
86 char ch_name[8];
87 LIST_HEAD(,bwfm_core) ch_list;
88 int (*ch_core_isup)(struct bwfm_softc *, struct bwfm_core *);
89 void (*ch_core_disable)(struct bwfm_softc *, struct bwfm_core *,
90 uint32_t prereset, uint32_t reset);
91 void (*ch_core_reset)(struct bwfm_softc *, struct bwfm_core *,
92 uint32_t prereset, uint32_t reset, uint32_t postreset);
93 };
94
95 struct bwfm_bus_ops {
96 void (*bs_init)(struct bwfm_softc *);
97 void (*bs_stop)(struct bwfm_softc *);
98 int (*bs_txcheck)(struct bwfm_softc *);
99 int (*bs_txdata)(struct bwfm_softc *, struct mbuf **);
100 int (*bs_txctl)(struct bwfm_softc *, char *, size_t);
101 int (*bs_rxctl)(struct bwfm_softc *, char *, size_t *);
102 };
103
104 struct bwfm_buscore_ops {
105 uint32_t (*bc_read)(struct bwfm_softc *, uint32_t);
106 void (*bc_write)(struct bwfm_softc *, uint32_t, uint32_t);
107 int (*bc_prepare)(struct bwfm_softc *);
108 int (*bc_reset)(struct bwfm_softc *);
109 int (*bc_setup)(struct bwfm_softc *);
110 void (*bc_activate)(struct bwfm_softc *, const uint32_t);
111 };
112
113 struct bwfm_proto_ops {
114 int (*proto_query_dcmd)(struct bwfm_softc *, int, int,
115 char *, size_t *);
116 int (*proto_set_dcmd)(struct bwfm_softc *, int, int,
117 char *, size_t);
118 };
119 extern struct bwfm_proto_ops bwfm_proto_bcdc_ops;
120
121 enum bwfm_task_cmd {
122 BWFM_TASK_NEWSTATE,
123 BWFM_TASK_KEY_SET,
124 BWFM_TASK_KEY_DELETE,
125 BWFM_TASK_RX_EVENT,
126 };
127
128 struct bwfm_cmd_newstate {
129 enum ieee80211_state state;
130 int arg;
131 };
132
133 struct bwfm_cmd_key {
134 const struct ieee80211_key *key;
135 uint8_t mac[IEEE80211_ADDR_LEN];
136 };
137
138 struct bwfm_task {
139 struct work t_work;
140 struct bwfm_softc *t_sc;
141 enum bwfm_task_cmd t_cmd;
142 union {
143 struct bwfm_cmd_newstate newstate;
144 struct bwfm_cmd_key key;
145 struct mbuf *mbuf;
146 } t_u;
147 #define t_newstate t_u.newstate
148 #define t_key t_u.key
149 #define t_mbuf t_u.mbuf
150 };
151
152 struct bwfm_softc {
153 device_t sc_dev;
154 struct ieee80211com sc_ic;
155 struct ethercom sc_ec;
156 #define sc_if sc_ec.ec_if
157
158 struct bwfm_bus_ops *sc_bus_ops;
159 struct bwfm_buscore_ops *sc_buscore_ops;
160 struct bwfm_proto_ops *sc_proto_ops;
161 struct bwfm_chip sc_chip;
162 uint8_t sc_io_type;
163 #define BWFM_IO_TYPE_D11N 1
164 #define BWFM_IO_TYPE_D11AC 2
165
166 int sc_tx_timer;
167
168 bool sc_if_attached;
169 struct bwfm_task sc_task[BWFM_TASK_COUNT];
170 pcq_t *sc_freetask;
171 struct workqueue *sc_taskq;
172
173 int (*sc_newstate)(struct ieee80211com *,
174 enum ieee80211_state, int);
175
176 int sc_bcdc_reqid;
177 };
178
179 void bwfm_attach(struct bwfm_softc *);
180 void bwfm_chip_socram_ramsize(struct bwfm_softc *, struct bwfm_core *);
181 void bwfm_chip_sysmem_ramsize(struct bwfm_softc *, struct bwfm_core *);
182 void bwfm_chip_tcm_ramsize(struct bwfm_softc *, struct bwfm_core *);
183 void bwfm_chip_tcm_rambase(struct bwfm_softc *);
184 void bwfm_start(struct ifnet *);
185 int bwfm_detach(struct bwfm_softc *, int);
186 int bwfm_chip_attach(struct bwfm_softc *);
187 int bwfm_chip_set_active(struct bwfm_softc *, uint32_t);
188 void bwfm_chip_set_passive(struct bwfm_softc *);
189 int bwfm_chip_sr_capable(struct bwfm_softc *);
190 struct bwfm_core *bwfm_chip_get_core(struct bwfm_softc *, int);
191 struct bwfm_core *bwfm_chip_get_pmu(struct bwfm_softc *);
192 void bwfm_rx(struct bwfm_softc *, struct mbuf *m);
193