btintel.h 9.4 KB

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