xref: /openbsd/sys/dev/ic/bwfmvar.h (revision db31205a)
1 /* $OpenBSD: bwfmvar.h,v 1.25 2021/10/23 12:48:17 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_4356_CHIP_ID		0x4356
41 #define BRCM_CC_43566_CHIP_ID		43566
42 #define BRCM_CC_43567_CHIP_ID		43567
43 #define BRCM_CC_43569_CHIP_ID		43569
44 #define BRCM_CC_43570_CHIP_ID		43570
45 #define BRCM_CC_4358_CHIP_ID		0x4358
46 #define BRCM_CC_4359_CHIP_ID		0x4359
47 #define BRCM_CC_43602_CHIP_ID		43602
48 #define BRCM_CC_4365_CHIP_ID		0x4365
49 #define BRCM_CC_4366_CHIP_ID		0x4366
50 #define BRCM_CC_4371_CHIP_ID		0x4371
51 #define BRCM_CC_4378_CHIP_ID		0x4378
52 #define CY_CC_4373_CHIP_ID		0x4373
53 
54 /* Defaults */
55 #define BWFM_DEFAULT_SCAN_CHANNEL_TIME	40
56 #define BWFM_DEFAULT_SCAN_UNASSOC_TIME	40
57 #define BWFM_DEFAULT_SCAN_PASSIVE_TIME	120
58 
59 
60 struct bwfm_softc;
61 
62 struct bwfm_core {
63 	uint16_t	 co_id;
64 	uint16_t	 co_rev;
65 	uint32_t	 co_base;
66 	uint32_t	 co_wrapbase;
67 	LIST_ENTRY(bwfm_core) co_link;
68 };
69 
70 struct bwfm_chip {
71 	uint32_t	 ch_chip;
72 	uint32_t	 ch_chiprev;
73 	uint32_t	 ch_cc_caps;
74 	uint32_t	 ch_cc_caps_ext;
75 	uint32_t	 ch_pmucaps;
76 	uint32_t	 ch_pmurev;
77 	uint32_t	 ch_rambase;
78 	uint32_t	 ch_ramsize;
79 	uint32_t	 ch_srsize;
80 	char		 ch_name[8];
81 	LIST_HEAD(,bwfm_core) ch_list;
82 	int (*ch_core_isup)(struct bwfm_softc *, struct bwfm_core *);
83 	void (*ch_core_disable)(struct bwfm_softc *, struct bwfm_core *,
84 	    uint32_t prereset, uint32_t reset);
85 	void (*ch_core_reset)(struct bwfm_softc *, struct bwfm_core *,
86 	    uint32_t prereset, uint32_t reset, uint32_t postreset);
87 };
88 
89 struct bwfm_bus_ops {
90 	int (*bs_preinit)(struct bwfm_softc *);
91 	void (*bs_stop)(struct bwfm_softc *);
92 	int (*bs_txcheck)(struct bwfm_softc *);
93 	int (*bs_txdata)(struct bwfm_softc *, struct mbuf *);
94 	int (*bs_txctl)(struct bwfm_softc *, void *);
95 };
96 
97 struct bwfm_buscore_ops {
98 	uint32_t (*bc_read)(struct bwfm_softc *, uint32_t);
99 	void (*bc_write)(struct bwfm_softc *, uint32_t, uint32_t);
100 	int (*bc_prepare)(struct bwfm_softc *);
101 	int (*bc_reset)(struct bwfm_softc *);
102 	int (*bc_setup)(struct bwfm_softc *);
103 	void (*bc_activate)(struct bwfm_softc *, uint32_t);
104 };
105 
106 struct bwfm_proto_ops {
107 	int (*proto_query_dcmd)(struct bwfm_softc *, int, int,
108 	    char *, size_t *);
109 	int (*proto_set_dcmd)(struct bwfm_softc *, int, int,
110 	    char *, size_t);
111 	void (*proto_rx)(struct bwfm_softc *, struct mbuf *,
112 	    struct mbuf_list *);
113 	void (*proto_rxctl)(struct bwfm_softc *, char *, size_t);
114 };
115 extern struct bwfm_proto_ops bwfm_proto_bcdc_ops;
116 
117 struct bwfm_host_cmd {
118 	void	 (*cb)(struct bwfm_softc *, void *);
119 	uint8_t	 data[256];
120 };
121 
122 struct bwfm_cmd_key {
123 	struct ieee80211_node	 *ni;
124 	struct ieee80211_key	 *k;
125 };
126 
127 struct bwfm_cmd_flowring_create {
128 	struct mbuf		*m;
129 	int			 flowid;
130 	int			 prio;
131 };
132 
133 struct bwfm_host_cmd_ring {
134 #define BWFM_HOST_CMD_RING_COUNT	32
135 	struct bwfm_host_cmd	 cmd[BWFM_HOST_CMD_RING_COUNT];
136 	int			 cur;
137 	int			 next;
138 	int			 queued;
139 };
140 
141 struct bwfm_proto_bcdc_ctl {
142 	int				 reqid;
143 	char				*buf;
144 	size_t				 len;
145 	int				 done;
146 	TAILQ_ENTRY(bwfm_proto_bcdc_ctl) next;
147 };
148 
149 struct bwfm_softc {
150 	struct device		 sc_dev;
151 	struct ieee80211com	 sc_ic;
152 	struct ifmedia		 sc_media;
153 	struct bwfm_bus_ops	*sc_bus_ops;
154 	struct bwfm_buscore_ops	*sc_buscore_ops;
155 	struct bwfm_proto_ops	*sc_proto_ops;
156 	struct bwfm_chip	 sc_chip;
157 	uint8_t			 sc_io_type;
158 #define		BWFM_IO_TYPE_D11N		1
159 #define		BWFM_IO_TYPE_D11AC		2
160 
161 	int			 sc_node;
162 	int			 sc_initialized;
163 	int			 sc_tx_timer;
164 
165 	int			 (*sc_newstate)(struct ieee80211com *,
166 				     enum ieee80211_state, int);
167 	struct bwfm_host_cmd_ring sc_cmdq;
168 	struct taskq		*sc_taskq;
169 	struct task		 sc_task;
170 	struct mbuf_list	 sc_evml;
171 
172 	int			 sc_bcdc_reqid;
173 	TAILQ_HEAD(, bwfm_proto_bcdc_ctl) sc_bcdc_rxctlq;
174 
175 	u_char			*sc_clm;
176 	size_t			 sc_clmsize;
177 	int			 sc_key_tasks;
178 };
179 
180 void bwfm_attach(struct bwfm_softc *);
181 void bwfm_attachhook(struct device *);
182 int bwfm_preinit(struct bwfm_softc *);
183 void bwfm_cleanup(struct bwfm_softc *);
184 int bwfm_detach(struct bwfm_softc *, int);
185 int bwfm_activate(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 *, struct mbuf_list *);
193 void bwfm_do_async(struct bwfm_softc *, void (*)(struct bwfm_softc *, void *),
194     void *, int);
195 int bwfm_nvram_convert(int, u_char **, size_t *, size_t *);
196 int bwfm_loadfirmware(struct bwfm_softc *, const char *, const char *,
197     u_char **, size_t *, u_char **, size_t *, size_t *);
198