2 * Copyright (c) 2013 Adrian Chadd <adrian@FreeBSD.org>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer,
10 * without modification.
11 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
12 * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
13 * redistribution must be conditioned upon including a substantially
14 * similar Disclaimer requirement for further binary redistribution.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTABILITY
20 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
21 * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
22 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
27 * THE POSSIBILITY OF SUCH DAMAGES.
31 #include <sys/cdefs.h>
32 __FBSDID("$FreeBSD$");
35 * This implements some very basic bluetooth coexistence methods for
36 * the ath(4) hardware.
42 #include <sys/param.h>
43 #include <sys/systm.h>
44 #include <sys/sysctl.h>
45 #include <sys/kernel.h>
47 #include <sys/malloc.h>
48 #include <sys/errno.h>
50 #if defined(__DragonFly__)
53 #include <machine/bus.h>
54 #include <machine/resource.h>
58 #include <sys/socket.h>
61 #include <net/if_var.h>
62 #include <net/if_media.h>
63 #include <net/if_arp.h>
64 #include <net/ethernet.h> /* XXX for ether_sprintf */
66 #include <netproto/802_11/ieee80211_var.h>
71 #include <netinet/in.h>
72 #include <netinet/if_ether.h>
75 #include <dev/netif/ath/ath/if_athvar.h>
76 #include <dev/netif/ath/ath/if_ath_btcoex.h>
79 * Initial AR9285 / (WB195) bluetooth coexistence settings,
80 * just for experimentation.
82 * Return 0 for OK; errno for error.
84 * XXX TODO: There needs to be a PCIe workaround to disable ASPM if
85 * bluetooth coexistence is enabled.
88 ath_btcoex_cfg_wb195(struct ath_softc *sc)
90 HAL_BT_COEX_INFO btinfo;
91 HAL_BT_COEX_CONFIG btconfig;
92 struct ath_hal *ah = sc->sc_ah;
94 if (! ath_hal_btcoex_supported(ah))
97 bzero(&btinfo, sizeof(btinfo));
98 bzero(&btconfig, sizeof(btconfig));
100 device_printf(sc->sc_dev, "Enabling WB195 BTCOEX\n");
102 btinfo.bt_module = HAL_BT_MODULE_JANUS;
103 btinfo.bt_coex_config = HAL_BT_COEX_CFG_3WIRE;
105 * These are the three GPIO pins hooked up between the AR9285 and
108 btinfo.bt_gpio_bt_active = 6;
109 btinfo.bt_gpio_bt_priority = 7;
110 btinfo.bt_gpio_wlan_active = 5;
111 btinfo.bt_active_polarity = 1; /* XXX not used */
112 btinfo.bt_single_ant = 1; /* 1 antenna on ar9285 ? */
113 btinfo.bt_isolation = 0; /* in dB, not used */
115 ath_hal_btcoex_set_info(ah, &btinfo);
117 btconfig.bt_time_extend = 0;
118 btconfig.bt_txstate_extend = 1; /* true */
119 btconfig.bt_txframe_extend = 1; /* true */
120 btconfig.bt_mode = HAL_BT_COEX_MODE_SLOTTED;
121 btconfig.bt_quiet_collision = 1; /* true */
122 btconfig.bt_rxclear_polarity = 1; /* true */
123 btconfig.bt_priority_time = 2;
124 btconfig.bt_first_slot_time = 5;
125 btconfig.bt_hold_rxclear = 1; /* true */
127 ath_hal_btcoex_set_config(ah, &btconfig);
130 * Enable antenna diversity.
132 ath_hal_btcoex_set_parameter(ah, HAL_BT_COEX_ANTENNA_DIVERSITY, 1);
138 * Initial AR9485 / (WB225) bluetooth coexistence settings,
139 * just for experimentation.
141 * Return 0 for OK; errno for error.
144 ath_btcoex_cfg_wb225(struct ath_softc *sc)
146 HAL_BT_COEX_INFO btinfo;
147 HAL_BT_COEX_CONFIG btconfig;
148 struct ath_hal *ah = sc->sc_ah;
150 if (! ath_hal_btcoex_supported(ah))
153 bzero(&btinfo, sizeof(btinfo));
154 bzero(&btconfig, sizeof(btconfig));
156 device_printf(sc->sc_dev, "Enabling WB225 BTCOEX\n");
158 btinfo.bt_module = HAL_BT_MODULE_JANUS; /* XXX not used? */
159 btinfo.bt_coex_config = HAL_BT_COEX_CFG_3WIRE;
161 * These are the three GPIO pins hooked up between the AR9485 and
162 * the bluetooth module.
164 btinfo.bt_gpio_bt_active = 4;
165 btinfo.bt_gpio_bt_priority = 8;
166 btinfo.bt_gpio_wlan_active = 5;
168 btinfo.bt_active_polarity = 1; /* XXX not used */
169 btinfo.bt_single_ant = 1; /* 1 antenna on ar9285 ? */
170 btinfo.bt_isolation = 0; /* in dB, not used */
172 ath_hal_btcoex_set_info(ah, &btinfo);
174 btconfig.bt_time_extend = 0;
175 btconfig.bt_txstate_extend = 1; /* true */
176 btconfig.bt_txframe_extend = 1; /* true */
177 btconfig.bt_mode = HAL_BT_COEX_MODE_SLOTTED;
178 btconfig.bt_quiet_collision = 1; /* true */
179 btconfig.bt_rxclear_polarity = 1; /* true */
180 btconfig.bt_priority_time = 2;
181 btconfig.bt_first_slot_time = 5;
182 btconfig.bt_hold_rxclear = 1; /* true */
184 ath_hal_btcoex_set_config(ah, &btconfig);
187 * Enable antenna diversity.
189 ath_hal_btcoex_set_parameter(ah, HAL_BT_COEX_ANTENNA_DIVERSITY, 1);
195 * Initial AR9462 / (WB222) bluetooth coexistence settings,
196 * just for experimentation.
198 * Return 0 for OK; errno for error.
201 ath_btcoex_cfg_wb222(struct ath_softc *sc)
203 HAL_BT_COEX_INFO btinfo;
204 HAL_BT_COEX_CONFIG btconfig;
205 struct ath_hal *ah = sc->sc_ah;
207 if (! ath_hal_btcoex_supported(ah))
210 bzero(&btinfo, sizeof(btinfo));
211 bzero(&btconfig, sizeof(btconfig));
213 device_printf(sc->sc_dev, "Enabling WB222 BTCOEX\n");
215 btinfo.bt_module = HAL_BT_MODULE_JANUS; /* XXX not used? */
216 btinfo.bt_coex_config = HAL_BT_COEX_CFG_MCI;
219 * MCI uses a completely different interface to speak
220 * to the bluetooth module - it's a command based
221 * thing over a serial line, rather than
222 * state pins to/from the bluetooth module.
224 * So, the GPIO configuration, polarity, etc
225 * doesn't matter on MCI devices; it's just
226 * completely ignored by the HAL.
228 btinfo.bt_gpio_bt_active = 4;
229 btinfo.bt_gpio_bt_priority = 8;
230 btinfo.bt_gpio_wlan_active = 5;
232 btinfo.bt_active_polarity = 1; /* XXX not used */
233 btinfo.bt_single_ant = 0; /* 2 antenna on WB222 */
234 btinfo.bt_isolation = 0; /* in dB, not used */
236 ath_hal_btcoex_set_info(ah, &btinfo);
238 btconfig.bt_time_extend = 0;
239 btconfig.bt_txstate_extend = 1; /* true */
240 btconfig.bt_txframe_extend = 1; /* true */
241 btconfig.bt_mode = HAL_BT_COEX_MODE_SLOTTED;
242 btconfig.bt_quiet_collision = 1; /* true */
243 btconfig.bt_rxclear_polarity = 1; /* true */
244 btconfig.bt_priority_time = 2;
245 btconfig.bt_first_slot_time = 5;
246 btconfig.bt_hold_rxclear = 1; /* true */
248 ath_hal_btcoex_set_config(ah, &btconfig);
251 * Enable antenna diversity.
253 ath_hal_btcoex_set_parameter(ah, HAL_BT_COEX_ANTENNA_DIVERSITY, 1);
263 * When using bluetooth coexistence, ASPM needs to be disabled
264 * otherwise the sleeping interferes with the bluetooth (USB)
265 * operation and the MAC sleep/wakeup hardware.
267 * The PCIe powersave routine also needs to not be called
268 * by the driver during suspend/resume, else things will get
269 * a little odd. Check Linux ath9k for more details.
272 ath_btcoex_aspm_wb195(struct ath_softc *sc)
275 /* XXX TODO: clear device ASPM L0S and L1 */
276 /* XXX TODO: clear _parent_ ASPM L0S and L1 */
281 * Methods which are required
285 * Attach btcoex to the given interface
288 ath_btcoex_attach(struct ath_softc *sc)
291 struct ath_hal *ah = sc->sc_ah;
292 const char *profname;
295 * No chipset bluetooth coexistence? Then do nothing.
297 if (! ath_hal_btcoex_supported(ah))
301 * Look at the hints to determine which bluetooth
302 * profile to configure.
304 ret = resource_string_value(device_get_name(sc->sc_dev),
305 device_get_unit(sc->sc_dev),
313 if (strncmp(profname, "wb195", 5) == 0) {
314 ret = ath_btcoex_cfg_wb195(sc);
315 } else if (strncmp(profname, "wb222", 5) == 0) {
316 ret = ath_btcoex_cfg_wb222(sc);
317 } else if (strncmp(profname, "wb225", 5) == 0) {
318 ret = ath_btcoex_cfg_wb225(sc);
324 * Propagate up failure from the actual attach phase.
333 * Detach btcoex from the given interface
336 ath_btcoex_detach(struct ath_softc *sc)
343 * Configure or disable bluetooth coexistence on the given channel.
345 * For AR9285/AR9287/AR9485, we'll never see a 5GHz channel, so we just
346 * assume bluetooth coexistence is always on.
348 * For AR9462, we may see a 5GHz channel; bluetooth coexistence should
349 * not be enabled on those channels.
352 ath_btcoex_enable(struct ath_softc *sc, const struct ieee80211_channel *chan)
359 * Handle ioctl requests from the diagnostic interface.
361 * The initial part of this code resembles ath_ioctl_diag();
362 * it's likely a good idea to reduce duplication between
363 * these two routines.
366 ath_btcoex_ioctl(struct ath_softc *sc, struct ath_diag *ad)
368 unsigned int id = ad->ad_id & ATH_DIAG_ID;
370 void *outdata = NULL;
371 u_int32_t insize = ad->ad_in_size;
372 u_int32_t outsize = ad->ad_out_size;
376 if (ad->ad_id & ATH_DIAG_IN) {
380 indata = kmalloc(insize, M_TEMP, M_INTWAIT);
381 if (indata == NULL) {
385 error = copyin(ad->ad_in_data, indata, insize);
389 if (ad->ad_id & ATH_DIAG_DYN) {
391 * Allocate a buffer for the results (otherwise the HAL
392 * returns a pointer to a buffer where we can read the
393 * results). Note that we depend on the HAL leaving this
394 * pointer for us to use below in reclaiming the buffer;
395 * may want to be more defensive.
397 outdata = kmalloc(outsize, M_TEMP, M_INTWAIT);
398 if (outdata == NULL) {
407 if (outsize < ad->ad_out_size)
408 ad->ad_out_size = outsize;
409 if (outdata && copyout(outdata, ad->ad_out_data, ad->ad_out_size))
412 if ((ad->ad_id & ATH_DIAG_IN) && indata != NULL)
413 kfree(indata, M_TEMP);
414 if ((ad->ad_id & ATH_DIAG_DYN) && outdata != NULL)
415 kfree(outdata, M_TEMP);