aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/wireless/ath/ath6kl/cfg80211_btcoex.c
blob: 399ffd7c71e33cf907ea8d131b482db3acdb4eb8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
/*
 * Copyright (c) 2004-2011 Atheros Communications Inc.
 *
 * Permission to use, copy, modify, and/or distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#include <linux/moduleparam.h>
#include <linux/inetdevice.h>

#ifdef CONFIG_HAS_WAKELOCK
#include <linux/wakelock.h>
#endif

#include "core.h"
#include "cfg80211.h"
#include "debug.h"
#include "hif-ops.h"
#include "testmode.h"
#include "cfg80211_btcoex.h"

bool ath6kl_btcoex_cfg80211_ready(struct ath6kl_vif *vif)
{
	struct ath6kl *ar = vif->ar;

	if (!test_bit(WMI_READY, &ar->flag)) {
		ath6kl_err("wmi is not ready\n");
		return false;
	}

	if (!test_bit(WLAN_ENABLED, &vif->flags)) {
		ath6kl_err("wlan disabled\n");
		return false;
	}

	return true;
}
#define OP_TYPE_SCO	0x01
#define OP_TYPE_A2DP	0x02
#define OP_TYPE_INQUIRY	0x03
#define OP_TYPE_ESCO	0x04

int ath6kl_notify_btcoex_inq_status(struct wiphy *wiphy, bool status)
{
	struct ath6kl *ar = (struct ath6kl *)wiphy_priv(wiphy);
	struct ath6kl_vif *vif;

	vif = ath6kl_vif_first(ar);
	if (!vif)
		return -EIO;

	ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "BT coex scan status:%d\n", status);

	if (!ath6kl_btcoex_cfg80211_ready(vif))
		return -EIO;

	return ath6kl_wmi_set_btcoex_bt_op_status(ar->wmi, OP_TYPE_INQUIRY,
						   status);
}

int ath6kl_notify_btcoex_sco_status(struct wiphy *wiphy,  bool status,
				    bool esco, u32 tx_interval,
				    u32 tx_pkt_len)
{
	struct ath6kl *ar = (struct ath6kl *)wiphy_priv(wiphy);
	struct ath6kl_vif *vif;

	vif = ath6kl_vif_first(ar);
	if (!vif)
		return -EIO;

	if (!ath6kl_btcoex_cfg80211_ready(vif))
		return -EIO;

	ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
		   "BT Coex sco status:%d sco type %s tx interval %d tx pk len %d\n",
		   status, esco ? "ESCO" : "SCO", tx_interval, tx_pkt_len);

	if (status)
		ath6kl_wmi_set_btcoex_sco_op(ar->wmi, esco, tx_interval,
					     tx_pkt_len);

	return ath6kl_wmi_set_btcoex_bt_op_status(ar->wmi, OP_TYPE_SCO,
						  status);
}

int ath6kl_notify_btcoex_a2dp_status(struct wiphy *wiphy, bool status)
{
	struct ath6kl *ar = (struct ath6kl *)wiphy_priv(wiphy);
	struct ath6kl_vif *vif;

	vif = ath6kl_vif_first(ar);
	if (!vif)
		return -EIO;

	if (!ath6kl_btcoex_cfg80211_ready(vif))
		return -EIO;

	ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "BT coex A2DP status:%d\n", status);

	if (status)
		ath6kl_wmi_set_btcoex_a2dp_op(ar->wmi,
					      ar->btcoex_info.acl_role,
					      ar->btcoex_info.remote_lmp_ver,
					      ar->btcoex_info.bt_vendor);

	return ath6kl_wmi_set_btcoex_bt_op_status(ar->wmi, OP_TYPE_A2DP,
						  status);
}

#define MAX_LMP_VER	6
int ath6kl_notify_btcoex_acl_info(struct wiphy *wiphy,
				  enum nl80211_btcoex_acl_role role,
				  u32 lmp_ver)
{
	struct ath6kl *ar = (struct ath6kl *)wiphy_priv(wiphy);

	if (lmp_ver > MAX_LMP_VER)
		return -EINVAL;

	if (role > NL80211_BTCOEX_ACL_ROLE_SLAVE)
		return -EINVAL;

	ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "BT coex ACL role:%d Lmp ver %d\n",
		   role, lmp_ver);

	ar->btcoex_info.acl_role = role;
	ar->btcoex_info.remote_lmp_ver = lmp_ver;

	return 0;
}

#define BTCOEX_COLOCATED_BT_DEFAULT	1
#define BTCOEX_COLOCATED_BT_QCOM	2

inline int get_bt_vendor_id(enum nl80211_btcoex_vendor_list vendor)
{
	switch (vendor) {
	case NL80211_BTCOEX_VENDOR_DEFAULT:
		return BTCOEX_COLOCATED_BT_DEFAULT;
	case NL80211_BTCOEX_VENDOR_QCOM:
		return BTCOEX_COLOCATED_BT_QCOM;
	}

	return BTCOEX_COLOCATED_BT_DEFAULT;
}

int ath6kl_notify_btcoex_antenna_config(struct wiphy *wiphy,
				enum nl80211_btcoex_antenna_config config)
{
	struct ath6kl *ar = (struct ath6kl *)wiphy_priv(wiphy);

	if (config > NL80211_BTCOEX_ANTENNA_SA)
		return -EINVAL;

	ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "BT coex Antenna configuration:%d\n",
		   config);
	ath6kl_wmi_set_btcoex_set_colocated_bt(ar->wmi,
					       get_bt_vendor_id
					       (ar->btcoex_info.bt_vendor));

	return ath6kl_wmi_set_btcoex_set_fe_antenna(ar->wmi, config);
}
int ath6kl_notify_btcoex_bt_vendor(struct wiphy *wiphy,
				   enum nl80211_btcoex_vendor_list vendor)
{
	struct ath6kl *ar = (struct ath6kl *)wiphy_priv(wiphy);

	if (vendor > NL80211_BTCOEX_VENDOR_QCOM)
		return -EINVAL;

	ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "vendor :%d\n", vendor);

	ar->btcoex_info.bt_vendor = vendor;

	return 0;
}

int ath6kl_notify_btcoex(struct wiphy *wiphy, u8 *buf,
					int len)
{
	struct ath6kl *ar = (struct ath6kl *)wiphy_priv(wiphy);
	struct ath6kl_vif *vif;

	vif = ath6kl_vif_first(ar);
	if (!vif)
		return -EIO;

	ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "BT coex wmi command:%p\n", buf);

	if (!ath6kl_btcoex_cfg80211_ready(vif))
		return -EIO;

	return ath6kl_wmi_send_btcoex_cmd(ar->wmi, buf,
			len);
}