btintel.h 9.5 KB

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