1d172a5efSJohannes Berg /******************************************************************************
2d172a5efSJohannes Berg  *
3d172a5efSJohannes Berg  * This file is provided under a dual BSD/GPLv2 license.  When using or
4d172a5efSJohannes Berg  * redistributing this file, you may do so under either license.
5d172a5efSJohannes Berg  *
6d172a5efSJohannes Berg  * GPL LICENSE SUMMARY
7d172a5efSJohannes Berg  *
8d172a5efSJohannes Berg  * Copyright(c) 2013 - 2014 Intel Corporation. All rights reserved.
9d172a5efSJohannes Berg  * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH
10d172a5efSJohannes Berg  * Copyright(c) 2017        Intel Deutschland GmbH
11d172a5efSJohannes Berg  *
12d172a5efSJohannes Berg  * This program is free software; you can redistribute it and/or modify
13d172a5efSJohannes Berg  * it under the terms of version 2 of the GNU General Public License as
14d172a5efSJohannes Berg  * published by the Free Software Foundation.
15d172a5efSJohannes Berg  *
16d172a5efSJohannes Berg  * This program is distributed in the hope that it will be useful, but
17d172a5efSJohannes Berg  * WITHOUT ANY WARRANTY; without even the implied warranty of
18d172a5efSJohannes Berg  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19d172a5efSJohannes Berg  * General Public License for more details.
20d172a5efSJohannes Berg  *
21d172a5efSJohannes Berg  * The full GNU General Public License is included in this distribution
22d172a5efSJohannes Berg  * in the file called COPYING.
23d172a5efSJohannes Berg  *
24d172a5efSJohannes Berg  * Contact Information:
25d172a5efSJohannes Berg  *  Intel Linux Wireless <linuxwifi@intel.com>
26d172a5efSJohannes Berg  * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27d172a5efSJohannes Berg  *
28d172a5efSJohannes Berg  * BSD LICENSE
29d172a5efSJohannes Berg  *
30d172a5efSJohannes Berg  * Copyright(c) 2013 - 2014 Intel Corporation. All rights reserved.
31d172a5efSJohannes Berg  * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH
32d172a5efSJohannes Berg  * Copyright(c) 2017        Intel Deutschland GmbH
33d172a5efSJohannes Berg  * All rights reserved.
34d172a5efSJohannes Berg  *
35d172a5efSJohannes Berg  * Redistribution and use in source and binary forms, with or without
36d172a5efSJohannes Berg  * modification, are permitted provided that the following conditions
37d172a5efSJohannes Berg  * are met:
38d172a5efSJohannes Berg  *
39d172a5efSJohannes Berg  *  * Redistributions of source code must retain the above copyright
40d172a5efSJohannes Berg  *    notice, this list of conditions and the following disclaimer.
41d172a5efSJohannes Berg  *  * Redistributions in binary form must reproduce the above copyright
42d172a5efSJohannes Berg  *    notice, this list of conditions and the following disclaimer in
43d172a5efSJohannes Berg  *    the documentation and/or other materials provided with the
44d172a5efSJohannes Berg  *    distribution.
45d172a5efSJohannes Berg  *  * Neither the name Intel Corporation nor the names of its
46d172a5efSJohannes Berg  *    contributors may be used to endorse or promote products derived
47d172a5efSJohannes Berg  *    from this software without specific prior written permission.
48d172a5efSJohannes Berg  *
49d172a5efSJohannes Berg  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
50d172a5efSJohannes Berg  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
51d172a5efSJohannes Berg  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
52d172a5efSJohannes Berg  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
53d172a5efSJohannes Berg  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
54d172a5efSJohannes Berg  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
55d172a5efSJohannes Berg  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
56d172a5efSJohannes Berg  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
57d172a5efSJohannes Berg  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
58d172a5efSJohannes Berg  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
59d172a5efSJohannes Berg  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
60d172a5efSJohannes Berg  *****************************************************************************/
61d172a5efSJohannes Berg 
62d172a5efSJohannes Berg #ifndef __iwl_fw_api_coex_h__
63d172a5efSJohannes Berg #define __iwl_fw_api_coex_h__
64d172a5efSJohannes Berg 
65d172a5efSJohannes Berg #include <linux/types.h>
66d172a5efSJohannes Berg #include <linux/bitops.h>
67d172a5efSJohannes Berg 
68d172a5efSJohannes Berg #define BITS(nb) (BIT(nb) - 1)
69d172a5efSJohannes Berg 
70d172a5efSJohannes Berg enum iwl_bt_coex_lut_type {
71d172a5efSJohannes Berg 	BT_COEX_TIGHT_LUT = 0,
72d172a5efSJohannes Berg 	BT_COEX_LOOSE_LUT,
73d172a5efSJohannes Berg 	BT_COEX_TX_DIS_LUT,
74d172a5efSJohannes Berg 
75d172a5efSJohannes Berg 	BT_COEX_MAX_LUT,
76d172a5efSJohannes Berg 	BT_COEX_INVALID_LUT = 0xff,
77d172a5efSJohannes Berg }; /* BT_COEX_DECISION_LUT_INDEX_API_E_VER_1 */
78d172a5efSJohannes Berg 
79d172a5efSJohannes Berg #define BT_REDUCED_TX_POWER_BIT BIT(7)
80d172a5efSJohannes Berg 
81d172a5efSJohannes Berg enum iwl_bt_coex_mode {
82d172a5efSJohannes Berg 	BT_COEX_DISABLE			= 0x0,
83d172a5efSJohannes Berg 	BT_COEX_NW			= 0x1,
84d172a5efSJohannes Berg 	BT_COEX_BT			= 0x2,
85d172a5efSJohannes Berg 	BT_COEX_WIFI			= 0x3,
86d172a5efSJohannes Berg }; /* BT_COEX_MODES_E */
87d172a5efSJohannes Berg 
88d172a5efSJohannes Berg enum iwl_bt_coex_enabled_modules {
89d172a5efSJohannes Berg 	BT_COEX_MPLUT_ENABLED		= BIT(0),
90d172a5efSJohannes Berg 	BT_COEX_MPLUT_BOOST_ENABLED	= BIT(1),
91d172a5efSJohannes Berg 	BT_COEX_SYNC2SCO_ENABLED	= BIT(2),
92d172a5efSJohannes Berg 	BT_COEX_CORUN_ENABLED		= BIT(3),
93d172a5efSJohannes Berg 	BT_COEX_HIGH_BAND_RET		= BIT(4),
94d172a5efSJohannes Berg }; /* BT_COEX_MODULES_ENABLE_E_VER_1 */
95d172a5efSJohannes Berg 
96d172a5efSJohannes Berg /**
97d172a5efSJohannes Berg  * struct iwl_bt_coex_cmd - bt coex configuration command
98d172a5efSJohannes Berg  * @mode: &enum iwl_bt_coex_mode
99d172a5efSJohannes Berg  * @enabled_modules: &enum iwl_bt_coex_enabled_modules
100d172a5efSJohannes Berg  *
101d172a5efSJohannes Berg  * The structure is used for the BT_COEX command.
102d172a5efSJohannes Berg  */
103d172a5efSJohannes Berg struct iwl_bt_coex_cmd {
104d172a5efSJohannes Berg 	__le32 mode;
105d172a5efSJohannes Berg 	__le32 enabled_modules;
106d172a5efSJohannes Berg } __packed; /* BT_COEX_CMD_API_S_VER_6 */
107d172a5efSJohannes Berg 
108d172a5efSJohannes Berg /**
109d172a5efSJohannes Berg  * struct iwl_bt_coex_reduced_txp_update_cmd
110d172a5efSJohannes Berg  * @reduced_txp: bit BT_REDUCED_TX_POWER_BIT to enable / disable, rest of the
111d172a5efSJohannes Berg  *	bits are the sta_id (value)
112d172a5efSJohannes Berg  */
113d172a5efSJohannes Berg struct iwl_bt_coex_reduced_txp_update_cmd {
114d172a5efSJohannes Berg 	__le32 reduced_txp;
115d172a5efSJohannes Berg } __packed; /* BT_COEX_UPDATE_REDUCED_TX_POWER_API_S_VER_1 */
116d172a5efSJohannes Berg 
117d172a5efSJohannes Berg /**
118d172a5efSJohannes Berg  * struct iwl_bt_coex_ci_cmd - bt coex channel inhibition command
119d172a5efSJohannes Berg  * @bt_primary_ci: primary channel inhibition bitmap
120d172a5efSJohannes Berg  * @primary_ch_phy_id: primary channel PHY ID
121d172a5efSJohannes Berg  * @bt_secondary_ci: secondary channel inhibition bitmap
122d172a5efSJohannes Berg  * @secondary_ch_phy_id: secondary channel PHY ID
123d172a5efSJohannes Berg  *
124d172a5efSJohannes Berg  * Used for BT_COEX_CI command
125d172a5efSJohannes Berg  */
126d172a5efSJohannes Berg struct iwl_bt_coex_ci_cmd {
127d172a5efSJohannes Berg 	__le64 bt_primary_ci;
128d172a5efSJohannes Berg 	__le32 primary_ch_phy_id;
129d172a5efSJohannes Berg 
130d172a5efSJohannes Berg 	__le64 bt_secondary_ci;
131d172a5efSJohannes Berg 	__le32 secondary_ch_phy_id;
132d172a5efSJohannes Berg } __packed; /* BT_CI_MSG_API_S_VER_2 */
133d172a5efSJohannes Berg 
134d172a5efSJohannes Berg #define BT_MBOX(n_dw, _msg, _pos, _nbits)	\
135d172a5efSJohannes Berg 	BT_MBOX##n_dw##_##_msg##_POS = (_pos),	\
136d172a5efSJohannes Berg 	BT_MBOX##n_dw##_##_msg = BITS(_nbits) << BT_MBOX##n_dw##_##_msg##_POS
137d172a5efSJohannes Berg 
138d172a5efSJohannes Berg enum iwl_bt_mxbox_dw0 {
139d172a5efSJohannes Berg 	BT_MBOX(0, LE_SLAVE_LAT, 0, 3),
140d172a5efSJohannes Berg 	BT_MBOX(0, LE_PROF1, 3, 1),
141d172a5efSJohannes Berg 	BT_MBOX(0, LE_PROF2, 4, 1),
142d172a5efSJohannes Berg 	BT_MBOX(0, LE_PROF_OTHER, 5, 1),
143d172a5efSJohannes Berg 	BT_MBOX(0, CHL_SEQ_N, 8, 4),
144d172a5efSJohannes Berg 	BT_MBOX(0, INBAND_S, 13, 1),
145d172a5efSJohannes Berg 	BT_MBOX(0, LE_MIN_RSSI, 16, 4),
146d172a5efSJohannes Berg 	BT_MBOX(0, LE_SCAN, 20, 1),
147d172a5efSJohannes Berg 	BT_MBOX(0, LE_ADV, 21, 1),
148d172a5efSJohannes Berg 	BT_MBOX(0, LE_MAX_TX_POWER, 24, 4),
149d172a5efSJohannes Berg 	BT_MBOX(0, OPEN_CON_1, 28, 2),
150d172a5efSJohannes Berg };
151d172a5efSJohannes Berg 
152d172a5efSJohannes Berg enum iwl_bt_mxbox_dw1 {
153d172a5efSJohannes Berg 	BT_MBOX(1, BR_MAX_TX_POWER, 0, 4),
154d172a5efSJohannes Berg 	BT_MBOX(1, IP_SR, 4, 1),
155d172a5efSJohannes Berg 	BT_MBOX(1, LE_MSTR, 5, 1),
156d172a5efSJohannes Berg 	BT_MBOX(1, AGGR_TRFC_LD, 8, 6),
157d172a5efSJohannes Berg 	BT_MBOX(1, MSG_TYPE, 16, 3),
158d172a5efSJohannes Berg 	BT_MBOX(1, SSN, 19, 2),
159d172a5efSJohannes Berg };
160d172a5efSJohannes Berg 
161d172a5efSJohannes Berg enum iwl_bt_mxbox_dw2 {
162d172a5efSJohannes Berg 	BT_MBOX(2, SNIFF_ACT, 0, 3),
163d172a5efSJohannes Berg 	BT_MBOX(2, PAG, 3, 1),
164d172a5efSJohannes Berg 	BT_MBOX(2, INQUIRY, 4, 1),
165d172a5efSJohannes Berg 	BT_MBOX(2, CONN, 5, 1),
166d172a5efSJohannes Berg 	BT_MBOX(2, SNIFF_INTERVAL, 8, 5),
167d172a5efSJohannes Berg 	BT_MBOX(2, DISC, 13, 1),
168d172a5efSJohannes Berg 	BT_MBOX(2, SCO_TX_ACT, 16, 2),
169d172a5efSJohannes Berg 	BT_MBOX(2, SCO_RX_ACT, 18, 2),
170d172a5efSJohannes Berg 	BT_MBOX(2, ESCO_RE_TX, 20, 2),
171d172a5efSJohannes Berg 	BT_MBOX(2, SCO_DURATION, 24, 6),
172d172a5efSJohannes Berg };
173d172a5efSJohannes Berg 
174d172a5efSJohannes Berg enum iwl_bt_mxbox_dw3 {
175d172a5efSJohannes Berg 	BT_MBOX(3, SCO_STATE, 0, 1),
176d172a5efSJohannes Berg 	BT_MBOX(3, SNIFF_STATE, 1, 1),
177d172a5efSJohannes Berg 	BT_MBOX(3, A2DP_STATE, 2, 1),
178d172a5efSJohannes Berg 	BT_MBOX(3, ACL_STATE, 3, 1),
179d172a5efSJohannes Berg 	BT_MBOX(3, MSTR_STATE, 4, 1),
180d172a5efSJohannes Berg 	BT_MBOX(3, OBX_STATE, 5, 1),
181fbfe378fSEmmanuel Grumbach 	BT_MBOX(3, A2DP_SRC, 6, 1),
182d172a5efSJohannes Berg 	BT_MBOX(3, OPEN_CON_2, 8, 2),
183d172a5efSJohannes Berg 	BT_MBOX(3, TRAFFIC_LOAD, 10, 2),
184d172a5efSJohannes Berg 	BT_MBOX(3, CHL_SEQN_LSB, 12, 1),
185d172a5efSJohannes Berg 	BT_MBOX(3, INBAND_P, 13, 1),
186d172a5efSJohannes Berg 	BT_MBOX(3, MSG_TYPE_2, 16, 3),
187d172a5efSJohannes Berg 	BT_MBOX(3, SSN_2, 19, 2),
188d172a5efSJohannes Berg 	BT_MBOX(3, UPDATE_REQUEST, 21, 1),
189d172a5efSJohannes Berg };
190d172a5efSJohannes Berg 
191fbfe378fSEmmanuel Grumbach enum iwl_bt_mxbox_dw4 {
192fbfe378fSEmmanuel Grumbach 	BT_MBOX(4, ATS_BT_INTERVAL, 0, 7),
193fbfe378fSEmmanuel Grumbach 	BT_MBOX(4, ATS_BT_ACTIVE_MAX_TH, 7, 7),
194fbfe378fSEmmanuel Grumbach };
195fbfe378fSEmmanuel Grumbach 
196d172a5efSJohannes Berg #define BT_MBOX_MSG(_notif, _num, _field)				     \
197d172a5efSJohannes Berg 	((le32_to_cpu((_notif)->mbox_msg[(_num)]) & BT_MBOX##_num##_##_field)\
198d172a5efSJohannes Berg 	>> BT_MBOX##_num##_##_field##_POS)
199d172a5efSJohannes Berg 
200d91c3fd0SLuca Coelho #define BT_MBOX_PRINT(_num, _field, _end)				    \
201d91c3fd0SLuca Coelho 			pos += scnprintf(buf + pos, bufsz - pos,	    \
202d91c3fd0SLuca Coelho 					 "\t%s: %d%s",			    \
203d91c3fd0SLuca Coelho 					 #_field,			    \
204d91c3fd0SLuca Coelho 					 BT_MBOX_MSG(notif, _num, _field),  \
205d91c3fd0SLuca Coelho 					 true ? "\n" : ", ");
206d172a5efSJohannes Berg enum iwl_bt_activity_grading {
207d172a5efSJohannes Berg 	BT_OFF			= 0,
208d172a5efSJohannes Berg 	BT_ON_NO_CONNECTION	= 1,
209d172a5efSJohannes Berg 	BT_LOW_TRAFFIC		= 2,
210d172a5efSJohannes Berg 	BT_HIGH_TRAFFIC		= 3,
211d172a5efSJohannes Berg 
212d172a5efSJohannes Berg 	BT_MAX_AG,
213d172a5efSJohannes Berg }; /* BT_COEX_BT_ACTIVITY_GRADING_API_E_VER_1 */
214d172a5efSJohannes Berg 
215d172a5efSJohannes Berg enum iwl_bt_ci_compliance {
216d172a5efSJohannes Berg 	BT_CI_COMPLIANCE_NONE		= 0,
217d172a5efSJohannes Berg 	BT_CI_COMPLIANCE_PRIMARY	= 1,
218d172a5efSJohannes Berg 	BT_CI_COMPLIANCE_SECONDARY	= 2,
219d172a5efSJohannes Berg 	BT_CI_COMPLIANCE_BOTH		= 3,
220d172a5efSJohannes Berg }; /* BT_COEX_CI_COMPLIENCE_E_VER_1 */
221d172a5efSJohannes Berg 
222d172a5efSJohannes Berg /**
223d172a5efSJohannes Berg  * struct iwl_bt_coex_profile_notif - notification about BT coex
224d172a5efSJohannes Berg  * @mbox_msg: message from BT to WiFi
225d172a5efSJohannes Berg  * @msg_idx: the index of the message
226d172a5efSJohannes Berg  * @bt_ci_compliance: enum %iwl_bt_ci_compliance
227d172a5efSJohannes Berg  * @primary_ch_lut: LUT used for primary channel &enum iwl_bt_coex_lut_type
228d172a5efSJohannes Berg  * @secondary_ch_lut: LUT used for secondary channel &enum iwl_bt_coex_lut_type
229d172a5efSJohannes Berg  * @bt_activity_grading: the activity of BT &enum iwl_bt_activity_grading
23088c5f476SEmmanuel Grumbach  * @ttc_status: is TTC enabled - one bit per PHY
23188c5f476SEmmanuel Grumbach  * @rrc_status: is RRC enabled - one bit per PHY
232d172a5efSJohannes Berg  * @reserved: reserved
233d172a5efSJohannes Berg  */
234d172a5efSJohannes Berg struct iwl_bt_coex_profile_notif {
235fbfe378fSEmmanuel Grumbach 	__le32 mbox_msg[8];
236fbfe378fSEmmanuel Grumbach 	__le32 msg_idx;
237fbfe378fSEmmanuel Grumbach 	__le32 bt_ci_compliance;
238fbfe378fSEmmanuel Grumbach 
239fbfe378fSEmmanuel Grumbach 	__le32 primary_ch_lut;
240fbfe378fSEmmanuel Grumbach 	__le32 secondary_ch_lut;
241fbfe378fSEmmanuel Grumbach 	__le32 bt_activity_grading;
242fbfe378fSEmmanuel Grumbach 	u8 ttc_status;
243fbfe378fSEmmanuel Grumbach 	u8 rrc_status;
244fbfe378fSEmmanuel Grumbach 	__le16 reserved;
245fbfe378fSEmmanuel Grumbach } __packed; /* BT_COEX_PROFILE_NTFY_API_S_VER_5 */
246fbfe378fSEmmanuel Grumbach 
247fbfe378fSEmmanuel Grumbach /**
248fbfe378fSEmmanuel Grumbach  * struct iwl_bt_coex_profile_notif - notification about BT coex
249fbfe378fSEmmanuel Grumbach  * @mbox_msg: message from BT to WiFi
250fbfe378fSEmmanuel Grumbach  * @msg_idx: the index of the message
251fbfe378fSEmmanuel Grumbach  * @bt_ci_compliance: enum %iwl_bt_ci_compliance
252fbfe378fSEmmanuel Grumbach  * @primary_ch_lut: LUT used for primary channel &enum iwl_bt_coex_lut_type
253fbfe378fSEmmanuel Grumbach  * @secondary_ch_lut: LUT used for secondary channel &enum iwl_bt_coex_lut_type
254fbfe378fSEmmanuel Grumbach  * @bt_activity_grading: the activity of BT &enum iwl_bt_activity_grading
255fbfe378fSEmmanuel Grumbach  * @ttc_status: is TTC enabled - one bit per PHY
256fbfe378fSEmmanuel Grumbach  * @rrc_status: is RRC enabled - one bit per PHY
257fbfe378fSEmmanuel Grumbach  * @reserved: reserved
258fbfe378fSEmmanuel Grumbach  */
259fbfe378fSEmmanuel Grumbach struct iwl_bt_coex_profile_notif_v4 {
260d172a5efSJohannes Berg 	__le32 mbox_msg[4];
261d172a5efSJohannes Berg 	__le32 msg_idx;
262d172a5efSJohannes Berg 	__le32 bt_ci_compliance;
263d172a5efSJohannes Berg 
264d172a5efSJohannes Berg 	__le32 primary_ch_lut;
265d172a5efSJohannes Berg 	__le32 secondary_ch_lut;
266d172a5efSJohannes Berg 	__le32 bt_activity_grading;
26788c5f476SEmmanuel Grumbach 	u8 ttc_status;
26888c5f476SEmmanuel Grumbach 	u8 rrc_status;
26988c5f476SEmmanuel Grumbach 	__le16 reserved;
270d172a5efSJohannes Berg } __packed; /* BT_COEX_PROFILE_NTFY_API_S_VER_4 */
271d172a5efSJohannes Berg 
272d172a5efSJohannes Berg #endif /* __iwl_fw_api_coex_h__ */
273