btintel.h 9.9 KB

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