xref: /openbsd/sys/dev/ic/bwfmvar.h (revision 905646f0)
1 /* $OpenBSD: bwfmvar.h,v 1.20 2020/05/15 14:09:14 patrick 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 CY_CC_4373_CHIP_ID		0x4373
52 
53 /* Defaults */
54 #define BWFM_DEFAULT_SCAN_CHANNEL_TIME	40
55 #define BWFM_DEFAULT_SCAN_UNASSOC_TIME	40
56 #define BWFM_DEFAULT_SCAN_PASSIVE_TIME	120
57 
58 
59 struct bwfm_softc;
60 
61 struct bwfm_core {
62 	uint16_t	 co_id;
63 	uint16_t	 co_rev;
64 	uint32_t	 co_base;
65 	uint32_t	 co_wrapbase;
66 	LIST_ENTRY(bwfm_core) co_link;
67 };
68 
69 struct bwfm_chip {
70 	uint32_t	 ch_chip;
71 	uint32_t	 ch_chiprev;
72 	uint32_t	 ch_cc_caps;
73 	uint32_t	 ch_cc_caps_ext;
74 	uint32_t	 ch_pmucaps;
75 	uint32_t	 ch_pmurev;
76 	uint32_t	 ch_rambase;
77 	uint32_t	 ch_ramsize;
78 	uint32_t	 ch_srsize;
79 	char		 ch_name[8];
80 	LIST_HEAD(,bwfm_core) ch_list;
81 	int (*ch_core_isup)(struct bwfm_softc *, struct bwfm_core *);
82 	void (*ch_core_disable)(struct bwfm_softc *, struct bwfm_core *,
83 	    uint32_t prereset, uint32_t reset);
84 	void (*ch_core_reset)(struct bwfm_softc *, struct bwfm_core *,
85 	    uint32_t prereset, uint32_t reset, uint32_t postreset);
86 };
87 
88 struct bwfm_bus_ops {
89 	int (*bs_preinit)(struct bwfm_softc *);
90 	void (*bs_stop)(struct bwfm_softc *);
91 	int (*bs_txcheck)(struct bwfm_softc *);
92 	int (*bs_txdata)(struct bwfm_softc *, struct mbuf *);
93 	int (*bs_txctl)(struct bwfm_softc *, void *);
94 };
95 
96 struct bwfm_buscore_ops {
97 	uint32_t (*bc_read)(struct bwfm_softc *, uint32_t);
98 	void (*bc_write)(struct bwfm_softc *, uint32_t, uint32_t);
99 	int (*bc_prepare)(struct bwfm_softc *);
100 	int (*bc_reset)(struct bwfm_softc *);
101 	int (*bc_setup)(struct bwfm_softc *);
102 	void (*bc_activate)(struct bwfm_softc *, uint32_t);
103 };
104 
105 struct bwfm_proto_ops {
106 	int (*proto_query_dcmd)(struct bwfm_softc *, int, int,
107 	    char *, size_t *);
108 	int (*proto_set_dcmd)(struct bwfm_softc *, int, int,
109 	    char *, size_t);
110 	void (*proto_rx)(struct bwfm_softc *, struct mbuf *,
111 	    struct mbuf_list *);
112 	void (*proto_rxctl)(struct bwfm_softc *, char *, size_t);
113 };
114 extern struct bwfm_proto_ops bwfm_proto_bcdc_ops;
115 
116 struct bwfm_host_cmd {
117 	void	 (*cb)(struct bwfm_softc *, void *);
118 	uint8_t	 data[256];
119 };
120 
121 struct bwfm_cmd_key {
122 	struct ieee80211_node	 *ni;
123 	struct ieee80211_key	 *k;
124 };
125 
126 struct bwfm_cmd_flowring_create {
127 	struct mbuf		*m;
128 	int			 flowid;
129 	int			 prio;
130 };
131 
132 struct bwfm_host_cmd_ring {
133 #define BWFM_HOST_CMD_RING_COUNT	32
134 	struct bwfm_host_cmd	 cmd[BWFM_HOST_CMD_RING_COUNT];
135 	int			 cur;
136 	int			 next;
137 	int			 queued;
138 };
139 
140 struct bwfm_proto_bcdc_ctl {
141 	int				 reqid;
142 	char				*buf;
143 	size_t				 len;
144 	int				 done;
145 	TAILQ_ENTRY(bwfm_proto_bcdc_ctl) next;
146 };
147 
148 struct bwfm_softc {
149 	struct device		 sc_dev;
150 	struct ieee80211com	 sc_ic;
151 	struct ifmedia		 sc_media;
152 	struct bwfm_bus_ops	*sc_bus_ops;
153 	struct bwfm_buscore_ops	*sc_buscore_ops;
154 	struct bwfm_proto_ops	*sc_proto_ops;
155 	struct bwfm_chip	 sc_chip;
156 	uint8_t			 sc_io_type;
157 #define		BWFM_IO_TYPE_D11N		1
158 #define		BWFM_IO_TYPE_D11AC		2
159 
160 	int			 sc_initialized;
161 	int			 sc_tx_timer;
162 
163 	int			 (*sc_newstate)(struct ieee80211com *,
164 				     enum ieee80211_state, int);
165 	struct bwfm_host_cmd_ring sc_cmdq;
166 	struct taskq		*sc_taskq;
167 	struct task		 sc_task;
168 	struct mbuf_list	 sc_evml;
169 
170 	int			 sc_bcdc_reqid;
171 	TAILQ_HEAD(, bwfm_proto_bcdc_ctl) sc_bcdc_rxctlq;
172 
173 	u_char			*sc_clm;
174 	size_t			 sc_clmsize;
175 };
176 
177 void bwfm_attach(struct bwfm_softc *);
178 void bwfm_attachhook(struct device *);
179 int bwfm_preinit(struct bwfm_softc *);
180 int bwfm_detach(struct bwfm_softc *, int);
181 int bwfm_chip_attach(struct bwfm_softc *);
182 int bwfm_chip_set_active(struct bwfm_softc *, uint32_t);
183 void bwfm_chip_set_passive(struct bwfm_softc *);
184 int bwfm_chip_sr_capable(struct bwfm_softc *);
185 struct bwfm_core *bwfm_chip_get_core(struct bwfm_softc *, int);
186 struct bwfm_core *bwfm_chip_get_pmu(struct bwfm_softc *);
187 void bwfm_rx(struct bwfm_softc *, struct mbuf *, struct mbuf_list *);
188 void bwfm_do_async(struct bwfm_softc *, void (*)(struct bwfm_softc *, void *),
189     void *, int);
190 int bwfm_nvram_convert(u_char *, size_t, size_t *);
191