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