xref: /linux-6.15/drivers/bluetooth/btintel.h (revision d154b0ff)
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3  *
4  *  Bluetooth support for Intel devices
5  *
6  *  Copyright (C) 2015  Intel Corporation
7  */
8 
9 /* List of tlv type */
10 enum {
11 	INTEL_TLV_CNVI_TOP = 0x10,
12 	INTEL_TLV_CNVR_TOP,
13 	INTEL_TLV_CNVI_BT,
14 	INTEL_TLV_CNVR_BT,
15 	INTEL_TLV_CNVI_OTP,
16 	INTEL_TLV_CNVR_OTP,
17 	INTEL_TLV_DEV_REV_ID,
18 	INTEL_TLV_USB_VENDOR_ID,
19 	INTEL_TLV_USB_PRODUCT_ID,
20 	INTEL_TLV_PCIE_VENDOR_ID,
21 	INTEL_TLV_PCIE_DEVICE_ID,
22 	INTEL_TLV_PCIE_SUBSYSTEM_ID,
23 	INTEL_TLV_IMAGE_TYPE,
24 	INTEL_TLV_TIME_STAMP,
25 	INTEL_TLV_BUILD_TYPE,
26 	INTEL_TLV_BUILD_NUM,
27 	INTEL_TLV_FW_BUILD_PRODUCT,
28 	INTEL_TLV_FW_BUILD_HW,
29 	INTEL_TLV_FW_STEP,
30 	INTEL_TLV_BT_SPEC,
31 	INTEL_TLV_MFG_NAME,
32 	INTEL_TLV_HCI_REV,
33 	INTEL_TLV_LMP_SUBVER,
34 	INTEL_TLV_OTP_PATCH_VER,
35 	INTEL_TLV_SECURE_BOOT,
36 	INTEL_TLV_KEY_FROM_HDR,
37 	INTEL_TLV_OTP_LOCK,
38 	INTEL_TLV_API_LOCK,
39 	INTEL_TLV_DEBUG_LOCK,
40 	INTEL_TLV_MIN_FW,
41 	INTEL_TLV_LIMITED_CCE,
42 	INTEL_TLV_SBE_TYPE,
43 	INTEL_TLV_OTP_BDADDR,
44 	INTEL_TLV_UNLOCKED_STATE,
45 	INTEL_TLV_GIT_SHA1,
46 	INTEL_TLV_FW_ID = 0x50
47 };
48 
49 struct intel_tlv {
50 	u8 type;
51 	u8 len;
52 	u8 val[];
53 } __packed;
54 
55 #define BTINTEL_CNVI_BLAZARI		0x900
56 #define BTINTEL_CNVI_BLAZARIW		0x901
57 #define BTINTEL_CNVI_GAP		0x910
58 #define BTINTEL_CNVI_BLAZARU		0x930
59  #define BTINTEL_CNVI_SCP		0xA00
60 
61 #define BTINTEL_IMG_BOOTLOADER		0x01	/* Bootloader image */
62 #define BTINTEL_IMG_IML			0x02	/* Intermediate image */
63 #define BTINTEL_IMG_OP			0x03	/* Operational image */
64 
65 #define BTINTEL_FWID_MAXLEN 64
66 
67 struct intel_version_tlv {
68 	u32	cnvi_top;
69 	u32	cnvr_top;
70 	u32	cnvi_bt;
71 	u32	cnvr_bt;
72 	u16	dev_rev_id;
73 	u8	img_type;
74 	u16	timestamp;
75 	u8	build_type;
76 	u32	build_num;
77 	u8	secure_boot;
78 	u8	otp_lock;
79 	u8	api_lock;
80 	u8	debug_lock;
81 	u8	min_fw_build_nn;
82 	u8	min_fw_build_cw;
83 	u8	min_fw_build_yy;
84 	u8	limited_cce;
85 	u8	sbe_type;
86 	u32	git_sha1;
87 	u8	fw_id[BTINTEL_FWID_MAXLEN];
88 	bdaddr_t otp_bd_addr;
89 };
90 
91 struct intel_version {
92 	u8 status;
93 	u8 hw_platform;
94 	u8 hw_variant;
95 	u8 hw_revision;
96 	u8 fw_variant;
97 	u8 fw_revision;
98 	u8 fw_build_num;
99 	u8 fw_build_ww;
100 	u8 fw_build_yy;
101 	u8 fw_patch_num;
102 } __packed;
103 
104 struct intel_boot_params {
105 	__u8     status;
106 	__u8     otp_format;
107 	__u8     otp_content;
108 	__u8     otp_patch;
109 	__le16   dev_revid;
110 	__u8     secure_boot;
111 	__u8     key_from_hdr;
112 	__u8     key_type;
113 	__u8     otp_lock;
114 	__u8     api_lock;
115 	__u8     debug_lock;
116 	bdaddr_t otp_bdaddr;
117 	__u8     min_fw_build_nn;
118 	__u8     min_fw_build_cw;
119 	__u8     min_fw_build_yy;
120 	__u8     limited_cce;
121 	__u8     unlocked_state;
122 } __packed;
123 
124 struct intel_bootup {
125 	__u8     zero;
126 	__u8     num_cmds;
127 	__u8     source;
128 	__u8     reset_type;
129 	__u8     reset_reason;
130 	__u8     ddc_status;
131 } __packed;
132 
133 struct intel_secure_send_result {
134 	__u8     result;
135 	__le16   opcode;
136 	__u8     status;
137 } __packed;
138 
139 struct intel_reset {
140 	__u8     reset_type;
141 	__u8     patch_enable;
142 	__u8     ddc_reload;
143 	__u8     boot_option;
144 	__le32   boot_param;
145 } __packed;
146 
147 struct intel_debug_features {
148 	__u8    page1[16];
149 } __packed;
150 
151 struct intel_offload_use_cases {
152 	__u8	status;
153 	__u8	preset[8];
154 } __packed;
155 
156 #define INTEL_OP_PPAG_CMD		0xFE0B
157 struct hci_ppag_enable_cmd {
158 	__le32	ppag_enable_flags;
159 } __packed;
160 
161 #define INTEL_TLV_TYPE_ID		0x01
162 
163 #define INTEL_TLV_SYSTEM_EXCEPTION	0x00
164 #define INTEL_TLV_FATAL_EXCEPTION	0x01
165 #define INTEL_TLV_DEBUG_EXCEPTION	0x02
166 #define INTEL_TLV_TEST_EXCEPTION	0xDE
167 
168 #define INTEL_HW_PLATFORM(cnvx_bt)	((u8)(((cnvx_bt) & 0x0000ff00) >> 8))
169 #define INTEL_HW_VARIANT(cnvx_bt)	((u8)(((cnvx_bt) & 0x003f0000) >> 16))
170 #define INTEL_CNVX_TOP_TYPE(cnvx_top)	((cnvx_top) & 0x00000fff)
171 #define INTEL_CNVX_TOP_STEP(cnvx_top)	(((cnvx_top) & 0x0f000000) >> 24)
172 #define INTEL_CNVX_TOP_PACK_SWAB(t, s)	__swab16(((__u16)(((t) << 4) | (s))))
173 
174 enum {
175 	INTEL_BOOTLOADER,
176 	INTEL_DOWNLOADING,
177 	INTEL_FIRMWARE_LOADED,
178 	INTEL_FIRMWARE_FAILED,
179 	INTEL_BOOTING,
180 	INTEL_BROKEN_INITIAL_NCMD,
181 	INTEL_BROKEN_SHUTDOWN_LED,
182 	INTEL_ROM_LEGACY,
183 	INTEL_ROM_LEGACY_NO_WBS_SUPPORT,
184 	INTEL_ACPI_RESET_ACTIVE,
185 	INTEL_WAIT_FOR_D0,
186 
187 	__INTEL_NUM_FLAGS,
188 };
189 
190 struct btintel_data {
191 	DECLARE_BITMAP(flags, __INTEL_NUM_FLAGS);
192 	int (*acpi_reset_method)(struct hci_dev *hdev);
193 };
194 
195 #define btintel_set_flag(hdev, nr)					\
196 	do {								\
197 		struct btintel_data *intel = hci_get_priv((hdev));	\
198 		set_bit((nr), intel->flags);				\
199 	} while (0)
200 
201 #define btintel_clear_flag(hdev, nr)					\
202 	do {								\
203 		struct btintel_data *intel = hci_get_priv((hdev));	\
204 		clear_bit((nr), intel->flags);				\
205 	} while (0)
206 
207 #define btintel_wake_up_flag(hdev, nr)					\
208 	do {								\
209 		struct btintel_data *intel = hci_get_priv((hdev));	\
210 		wake_up_bit(intel->flags, (nr));			\
211 	} while (0)
212 
213 #define btintel_get_flag(hdev)						\
214 	(((struct btintel_data *)hci_get_priv(hdev))->flags)
215 
216 #define btintel_test_flag(hdev, nr)	test_bit((nr), btintel_get_flag(hdev))
217 #define btintel_test_and_clear_flag(hdev, nr) test_and_clear_bit((nr), btintel_get_flag(hdev))
218 #define btintel_wait_on_flag_timeout(hdev, nr, m, to)			\
219 		wait_on_bit_timeout(btintel_get_flag(hdev), (nr), m, to)
220 
221 #if IS_ENABLED(CONFIG_BT_INTEL) || IS_ENABLED(CONFIG_BT_INTEL_PCIE)
222 
223 int btintel_check_bdaddr(struct hci_dev *hdev);
224 int btintel_enter_mfg(struct hci_dev *hdev);
225 int btintel_exit_mfg(struct hci_dev *hdev, bool reset, bool patched);
226 int btintel_set_bdaddr(struct hci_dev *hdev, const bdaddr_t *bdaddr);
227 int btintel_set_diag(struct hci_dev *hdev, bool enable);
228 
229 int btintel_version_info(struct hci_dev *hdev, struct intel_version *ver);
230 int btintel_load_ddc_config(struct hci_dev *hdev, const char *ddc_name);
231 int btintel_set_event_mask_mfg(struct hci_dev *hdev, bool debug);
232 int btintel_read_version(struct hci_dev *hdev, struct intel_version *ver);
233 struct regmap *btintel_regmap_init(struct hci_dev *hdev, u16 opcode_read,
234 				   u16 opcode_write);
235 int btintel_send_intel_reset(struct hci_dev *hdev, u32 boot_param);
236 int btintel_read_boot_params(struct hci_dev *hdev,
237 			     struct intel_boot_params *params);
238 int btintel_download_firmware(struct hci_dev *dev, struct intel_version *ver,
239 			      const struct firmware *fw, u32 *boot_param);
240 int btintel_configure_setup(struct hci_dev *hdev, const char *driver_name);
241 int btintel_recv_event(struct hci_dev *hdev, struct sk_buff *skb);
242 void btintel_bootup(struct hci_dev *hdev, const void *ptr, unsigned int len);
243 void btintel_secure_send_result(struct hci_dev *hdev,
244 				const void *ptr, unsigned int len);
245 int btintel_set_quality_report(struct hci_dev *hdev, bool enable);
246 int btintel_version_info_tlv(struct hci_dev *hdev,
247 			     struct intel_version_tlv *version);
248 int btintel_parse_version_tlv(struct hci_dev *hdev,
249 			      struct intel_version_tlv *version,
250 			      struct sk_buff *skb);
251 void btintel_set_msft_opcode(struct hci_dev *hdev, u8 hw_variant);
252 int btintel_bootloader_setup_tlv(struct hci_dev *hdev,
253 				 struct intel_version_tlv *ver);
254 int btintel_shutdown_combined(struct hci_dev *hdev);
255 void btintel_hw_error(struct hci_dev *hdev, u8 code);
256 void btintel_print_fseq_info(struct hci_dev *hdev);
257 int btintel_diagnostics(struct hci_dev *hdev, struct sk_buff *skb);
258 #else
259 
260 static inline int btintel_check_bdaddr(struct hci_dev *hdev)
261 {
262 	return -EOPNOTSUPP;
263 }
264 
265 static inline int btintel_enter_mfg(struct hci_dev *hdev)
266 {
267 	return -EOPNOTSUPP;
268 }
269 
270 static inline int btintel_exit_mfg(struct hci_dev *hdev, bool reset, bool patched)
271 {
272 	return -EOPNOTSUPP;
273 }
274 
275 static inline int btintel_set_bdaddr(struct hci_dev *hdev, const bdaddr_t *bdaddr)
276 {
277 	return -EOPNOTSUPP;
278 }
279 
280 static inline int btintel_set_diag(struct hci_dev *hdev, bool enable)
281 {
282 	return -EOPNOTSUPP;
283 }
284 
285 static inline int btintel_version_info(struct hci_dev *hdev,
286 				       struct intel_version *ver)
287 {
288 	return -EOPNOTSUPP;
289 }
290 
291 static inline int btintel_load_ddc_config(struct hci_dev *hdev,
292 					  const char *ddc_name)
293 {
294 	return -EOPNOTSUPP;
295 }
296 
297 static inline int btintel_set_event_mask_mfg(struct hci_dev *hdev, bool debug)
298 {
299 	return -EOPNOTSUPP;
300 }
301 
302 static inline int btintel_read_version(struct hci_dev *hdev,
303 				       struct intel_version *ver)
304 {
305 	return -EOPNOTSUPP;
306 }
307 
308 static inline struct regmap *btintel_regmap_init(struct hci_dev *hdev,
309 						 u16 opcode_read,
310 						 u16 opcode_write)
311 {
312 	return ERR_PTR(-EINVAL);
313 }
314 
315 static inline int btintel_send_intel_reset(struct hci_dev *hdev,
316 					   u32 reset_param)
317 {
318 	return -EOPNOTSUPP;
319 }
320 
321 static inline int btintel_read_boot_params(struct hci_dev *hdev,
322 					   struct intel_boot_params *params)
323 {
324 	return -EOPNOTSUPP;
325 }
326 
327 static inline int btintel_download_firmware(struct hci_dev *dev,
328 					    const struct firmware *fw,
329 					    u32 *boot_param)
330 {
331 	return -EOPNOTSUPP;
332 }
333 
334 static inline int btintel_configure_setup(struct hci_dev *hdev,
335 					  const char *driver_name)
336 {
337 	return -ENODEV;
338 }
339 
340 static inline void btintel_bootup(struct hci_dev *hdev,
341 				  const void *ptr, unsigned int len)
342 {
343 }
344 
345 static inline void btintel_secure_send_result(struct hci_dev *hdev,
346 				const void *ptr, unsigned int len)
347 {
348 }
349 
350 static inline int btintel_set_quality_report(struct hci_dev *hdev, bool enable)
351 {
352 	return -ENODEV;
353 }
354 
355 static inline int btintel_version_info_tlv(struct hci_dev *hdev,
356 					   struct intel_version_tlv *version)
357 {
358 	return -EOPNOTSUPP;
359 }
360 
361 static inline int btintel_parse_version_tlv(struct hci_dev *hdev,
362 					    struct intel_version_tlv *version,
363 					    struct sk_buff *skb)
364 {
365 	return -EOPNOTSUPP;
366 }
367 
368 static inline void btintel_set_msft_opcode(struct hci_dev *hdev, u8 hw_variant)
369 
370 {
371 }
372 
373 static inline int btintel_bootloader_setup_tlv(struct hci_dev *hdev,
374 					       struct intel_version_tlv *ver)
375 {
376 	return -ENODEV;
377 }
378 
379 static inline int btintel_shutdown_combined(struct hci_dev *hdev)
380 {
381 	return -ENODEV;
382 }
383 
384 static inline void btintel_hw_error(struct hci_dev *hdev, u8 code)
385 {
386 }
387 
388 static inline void btintel_print_fseq_info(struct hci_dev *hdev)
389 {
390 }
391 
392 static inline int btintel_diagnostics(struct hci_dev *hdev, struct sk_buff *skb)
393 {
394 	return -EOPNOTSUPP;
395 }
396 #endif
397