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 */
10enum {
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};
47
48struct intel_tlv {
49	u8 type;
50	u8 len;
51	u8 val[];
52} __packed;
53
54#define BTINTEL_CNVI_BLAZARI		0x900
55
56#define BTINTEL_IMG_BOOTLOADER		0x01	/* Bootloader image */
57#define BTINTEL_IMG_IML			0x02	/* Intermediate image */
58#define BTINTEL_IMG_OP			0x03	/* Operational image */
59
60struct intel_version_tlv {
61	u32	cnvi_top;
62	u32	cnvr_top;
63	u32	cnvi_bt;
64	u32	cnvr_bt;
65	u16	dev_rev_id;
66	u8	img_type;
67	u16	timestamp;
68	u8	build_type;
69	u32	build_num;
70	u8	secure_boot;
71	u8	otp_lock;
72	u8	api_lock;
73	u8	debug_lock;
74	u8	min_fw_build_nn;
75	u8	min_fw_build_cw;
76	u8	min_fw_build_yy;
77	u8	limited_cce;
78	u8	sbe_type;
79	u32	git_sha1;
80	bdaddr_t otp_bd_addr;
81};
82
83struct intel_version {
84	u8 status;
85	u8 hw_platform;
86	u8 hw_variant;
87	u8 hw_revision;
88	u8 fw_variant;
89	u8 fw_revision;
90	u8 fw_build_num;
91	u8 fw_build_ww;
92	u8 fw_build_yy;
93	u8 fw_patch_num;
94} __packed;
95
96struct intel_boot_params {
97	__u8     status;
98	__u8     otp_format;
99	__u8     otp_content;
100	__u8     otp_patch;
101	__le16   dev_revid;
102	__u8     secure_boot;
103	__u8     key_from_hdr;
104	__u8     key_type;
105	__u8     otp_lock;
106	__u8     api_lock;
107	__u8     debug_lock;
108	bdaddr_t otp_bdaddr;
109	__u8     min_fw_build_nn;
110	__u8     min_fw_build_cw;
111	__u8     min_fw_build_yy;
112	__u8     limited_cce;
113	__u8     unlocked_state;
114} __packed;
115
116struct intel_bootup {
117	__u8     zero;
118	__u8     num_cmds;
119	__u8     source;
120	__u8     reset_type;
121	__u8     reset_reason;
122	__u8     ddc_status;
123} __packed;
124
125struct intel_secure_send_result {
126	__u8     result;
127	__le16   opcode;
128	__u8     status;
129} __packed;
130
131struct intel_reset {
132	__u8     reset_type;
133	__u8     patch_enable;
134	__u8     ddc_reload;
135	__u8     boot_option;
136	__le32   boot_param;
137} __packed;
138
139struct intel_debug_features {
140	__u8    page1[16];
141} __packed;
142
143struct intel_offload_use_cases {
144	__u8	status;
145	__u8	preset[8];
146} __packed;
147
148#define INTEL_OP_PPAG_CMD		0xFE0B
149struct hci_ppag_enable_cmd {
150	__le32	ppag_enable_flags;
151} __packed;
152
153#define INTEL_TLV_TYPE_ID		0x01
154
155#define INTEL_TLV_SYSTEM_EXCEPTION	0x00
156#define INTEL_TLV_FATAL_EXCEPTION	0x01
157#define INTEL_TLV_DEBUG_EXCEPTION	0x02
158#define INTEL_TLV_TEST_EXCEPTION	0xDE
159
160#define INTEL_HW_PLATFORM(cnvx_bt)	((u8)(((cnvx_bt) & 0x0000ff00) >> 8))
161#define INTEL_HW_VARIANT(cnvx_bt)	((u8)(((cnvx_bt) & 0x003f0000) >> 16))
162#define INTEL_CNVX_TOP_TYPE(cnvx_top)	((cnvx_top) & 0x00000fff)
163#define INTEL_CNVX_TOP_STEP(cnvx_top)	(((cnvx_top) & 0x0f000000) >> 24)
164#define INTEL_CNVX_TOP_PACK_SWAB(t, s)	__swab16(((__u16)(((t) << 4) | (s))))
165
166enum {
167	INTEL_BOOTLOADER,
168	INTEL_DOWNLOADING,
169	INTEL_FIRMWARE_LOADED,
170	INTEL_FIRMWARE_FAILED,
171	INTEL_BOOTING,
172	INTEL_BROKEN_INITIAL_NCMD,
173	INTEL_BROKEN_SHUTDOWN_LED,
174	INTEL_ROM_LEGACY,
175	INTEL_ROM_LEGACY_NO_WBS_SUPPORT,
176	INTEL_ACPI_RESET_ACTIVE,
177
178	__INTEL_NUM_FLAGS,
179};
180
181struct btintel_data {
182	DECLARE_BITMAP(flags, __INTEL_NUM_FLAGS);
183	int (*acpi_reset_method)(struct hci_dev *hdev);
184};
185
186#define btintel_set_flag(hdev, nr)					\
187	do {								\
188		struct btintel_data *intel = hci_get_priv((hdev));	\
189		set_bit((nr), intel->flags);				\
190	} while (0)
191
192#define btintel_clear_flag(hdev, nr)					\
193	do {								\
194		struct btintel_data *intel = hci_get_priv((hdev));	\
195		clear_bit((nr), intel->flags);				\
196	} while (0)
197
198#define btintel_wake_up_flag(hdev, nr)					\
199	do {								\
200		struct btintel_data *intel = hci_get_priv((hdev));	\
201		wake_up_bit(intel->flags, (nr));			\
202	} while (0)
203
204#define btintel_get_flag(hdev)						\
205	(((struct btintel_data *)hci_get_priv(hdev))->flags)
206
207#define btintel_test_flag(hdev, nr)	test_bit((nr), btintel_get_flag(hdev))
208#define btintel_test_and_clear_flag(hdev, nr) test_and_clear_bit((nr), btintel_get_flag(hdev))
209#define btintel_wait_on_flag_timeout(hdev, nr, m, to)			\
210		wait_on_bit_timeout(btintel_get_flag(hdev), (nr), m, to)
211
212#if IS_ENABLED(CONFIG_BT_INTEL) || IS_ENABLED(CONFIG_BT_INTEL_PCIE)
213
214int btintel_check_bdaddr(struct hci_dev *hdev);
215int btintel_enter_mfg(struct hci_dev *hdev);
216int btintel_exit_mfg(struct hci_dev *hdev, bool reset, bool patched);
217int btintel_set_bdaddr(struct hci_dev *hdev, const bdaddr_t *bdaddr);
218int btintel_set_diag(struct hci_dev *hdev, bool enable);
219
220int btintel_version_info(struct hci_dev *hdev, struct intel_version *ver);
221int btintel_load_ddc_config(struct hci_dev *hdev, const char *ddc_name);
222int btintel_set_event_mask_mfg(struct hci_dev *hdev, bool debug);
223int btintel_read_version(struct hci_dev *hdev, struct intel_version *ver);
224struct regmap *btintel_regmap_init(struct hci_dev *hdev, u16 opcode_read,
225				   u16 opcode_write);
226int btintel_send_intel_reset(struct hci_dev *hdev, u32 boot_param);
227int btintel_read_boot_params(struct hci_dev *hdev,
228			     struct intel_boot_params *params);
229int btintel_download_firmware(struct hci_dev *dev, struct intel_version *ver,
230			      const struct firmware *fw, u32 *boot_param);
231int btintel_configure_setup(struct hci_dev *hdev, const char *driver_name);
232int btintel_recv_event(struct hci_dev *hdev, struct sk_buff *skb);
233void btintel_bootup(struct hci_dev *hdev, const void *ptr, unsigned int len);
234void btintel_secure_send_result(struct hci_dev *hdev,
235				const void *ptr, unsigned int len);
236int btintel_set_quality_report(struct hci_dev *hdev, bool enable);
237int btintel_version_info_tlv(struct hci_dev *hdev,
238			     struct intel_version_tlv *version);
239int btintel_parse_version_tlv(struct hci_dev *hdev,
240			      struct intel_version_tlv *version,
241			      struct sk_buff *skb);
242void btintel_set_msft_opcode(struct hci_dev *hdev, u8 hw_variant);
243int btintel_bootloader_setup_tlv(struct hci_dev *hdev,
244				 struct intel_version_tlv *ver);
245int btintel_shutdown_combined(struct hci_dev *hdev);
246void btintel_hw_error(struct hci_dev *hdev, u8 code);
247#else
248
249static inline int btintel_check_bdaddr(struct hci_dev *hdev)
250{
251	return -EOPNOTSUPP;
252}
253
254static inline int btintel_enter_mfg(struct hci_dev *hdev)
255{
256	return -EOPNOTSUPP;
257}
258
259static inline int btintel_exit_mfg(struct hci_dev *hdev, bool reset, bool patched)
260{
261	return -EOPNOTSUPP;
262}
263
264static inline int btintel_set_bdaddr(struct hci_dev *hdev, const bdaddr_t *bdaddr)
265{
266	return -EOPNOTSUPP;
267}
268
269static inline int btintel_set_diag(struct hci_dev *hdev, bool enable)
270{
271	return -EOPNOTSUPP;
272}
273
274static inline int btintel_version_info(struct hci_dev *hdev,
275				       struct intel_version *ver)
276{
277	return -EOPNOTSUPP;
278}
279
280static inline int btintel_load_ddc_config(struct hci_dev *hdev,
281					  const char *ddc_name)
282{
283	return -EOPNOTSUPP;
284}
285
286static inline int btintel_set_event_mask_mfg(struct hci_dev *hdev, bool debug)
287{
288	return -EOPNOTSUPP;
289}
290
291static inline int btintel_read_version(struct hci_dev *hdev,
292				       struct intel_version *ver)
293{
294	return -EOPNOTSUPP;
295}
296
297static inline struct regmap *btintel_regmap_init(struct hci_dev *hdev,
298						 u16 opcode_read,
299						 u16 opcode_write)
300{
301	return ERR_PTR(-EINVAL);
302}
303
304static inline int btintel_send_intel_reset(struct hci_dev *hdev,
305					   u32 reset_param)
306{
307	return -EOPNOTSUPP;
308}
309
310static inline int btintel_read_boot_params(struct hci_dev *hdev,
311					   struct intel_boot_params *params)
312{
313	return -EOPNOTSUPP;
314}
315
316static inline int btintel_download_firmware(struct hci_dev *dev,
317					    const struct firmware *fw,
318					    u32 *boot_param)
319{
320	return -EOPNOTSUPP;
321}
322
323static inline int btintel_configure_setup(struct hci_dev *hdev,
324					  const char *driver_name)
325{
326	return -ENODEV;
327}
328
329static inline void btintel_bootup(struct hci_dev *hdev,
330				  const void *ptr, unsigned int len)
331{
332}
333
334static inline void btintel_secure_send_result(struct hci_dev *hdev,
335				const void *ptr, unsigned int len)
336{
337}
338
339static inline int btintel_set_quality_report(struct hci_dev *hdev, bool enable)
340{
341	return -ENODEV;
342}
343
344static inline int btintel_version_info_tlv(struct hci_dev *hdev,
345					   struct intel_version_tlv *version)
346{
347	return -EOPNOTSUPP;
348}
349
350static inline int btintel_parse_version_tlv(struct hci_dev *hdev,
351					    struct intel_version_tlv *version,
352					    struct sk_buff *skb)
353{
354	return -EOPNOTSUPP;
355}
356
357static inline void btintel_set_msft_opcode(struct hci_dev *hdev, u8 hw_variant)
358
359{
360}
361
362static inline int btintel_bootloader_setup_tlv(struct hci_dev *hdev,
363					       struct intel_version_tlv *ver)
364{
365	return -ENODEV;
366}
367
368static inline int btintel_shutdown_combined(struct hci_dev *hdev)
369{
370	return -ENODEV;
371}
372
373static inline void btintel_hw_error(struct hci_dev *hdev, u8 code)
374{
375}
376#endif
377