main.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2017-2020, 2021, The Linux Foundation. All rights reserved.
  4. * Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved.
  5. */
  6. #ifndef __MAIN_H__
  7. #define __MAIN_H__
  8. #include <linux/irqreturn.h>
  9. #include <linux/kobject.h>
  10. #include <linux/platform_device.h>
  11. #include <linux/ipc_logging.h>
  12. #include <linux/power_supply.h>
  13. #ifdef CONFIG_CNSS_OUT_OF_TREE
  14. #include "icnss2.h"
  15. #else
  16. #include <soc/qcom/icnss2.h>
  17. #endif
  18. #include "wlan_firmware_service_v01.h"
  19. #include <linux/mailbox_client.h>
  20. #define WCN6750_DEVICE_ID 0x6750
  21. #define ADRASTEA_DEVICE_ID 0xabcd
  22. #define THERMAL_NAME_LENGTH 20
  23. #define ICNSS_SMEM_VALUE_MASK 0xFFFFFFFF
  24. #define ICNSS_SMEM_SEQ_NO_POS 16
  25. #define QCA6750_PATH_PREFIX "qca6750/"
  26. #define ADRASTEA_PATH_PREFIX "adrastea/"
  27. #define ICNSS_MAX_FILE_NAME 35
  28. #define ICNSS_PCI_EP_WAKE_OFFSET 4
  29. #define ICNSS_DISABLE_M3_SSR 0
  30. #define ICNSS_ENABLE_M3_SSR 1
  31. #define WLAN_RF_SLATE 0
  32. #define WLAN_RF_APACHE 1
  33. extern uint64_t dynamic_feature_mask;
  34. enum icnss_bdf_type {
  35. ICNSS_BDF_BIN,
  36. ICNSS_BDF_ELF,
  37. ICNSS_BDF_REGDB = 4,
  38. };
  39. struct icnss_control_params {
  40. unsigned long quirks;
  41. unsigned int qmi_timeout;
  42. unsigned int bdf_type;
  43. };
  44. enum icnss_driver_event_type {
  45. ICNSS_DRIVER_EVENT_SERVER_ARRIVE,
  46. ICNSS_DRIVER_EVENT_SERVER_EXIT,
  47. ICNSS_DRIVER_EVENT_FW_READY_IND,
  48. ICNSS_DRIVER_EVENT_REGISTER_DRIVER,
  49. ICNSS_DRIVER_EVENT_UNREGISTER_DRIVER,
  50. ICNSS_DRIVER_EVENT_PD_SERVICE_DOWN,
  51. ICNSS_DRIVER_EVENT_FW_EARLY_CRASH_IND,
  52. ICNSS_DRIVER_EVENT_IDLE_SHUTDOWN,
  53. ICNSS_DRIVER_EVENT_IDLE_RESTART,
  54. ICNSS_DRIVER_EVENT_FW_INIT_DONE_IND,
  55. ICNSS_DRIVER_EVENT_QDSS_TRACE_REQ_MEM,
  56. ICNSS_DRIVER_EVENT_QDSS_TRACE_SAVE,
  57. ICNSS_DRIVER_EVENT_QDSS_TRACE_FREE,
  58. ICNSS_DRIVER_EVENT_M3_DUMP_UPLOAD_REQ,
  59. ICNSS_DRIVER_EVENT_QDSS_TRACE_REQ_DATA,
  60. ICNSS_DRIVER_EVENT_SUBSYS_RESTART_LEVEL,
  61. ICNSS_DRIVER_EVENT_MAX,
  62. };
  63. enum icnss_soc_wake_event_type {
  64. ICNSS_SOC_WAKE_REQUEST_EVENT,
  65. ICNSS_SOC_WAKE_RELEASE_EVENT,
  66. ICNSS_SOC_WAKE_EVENT_MAX,
  67. };
  68. struct icnss_event_server_arrive_data {
  69. unsigned int node;
  70. unsigned int port;
  71. };
  72. struct icnss_event_pd_service_down_data {
  73. bool crashed;
  74. bool fw_rejuvenate;
  75. };
  76. struct icnss_driver_event {
  77. struct list_head list;
  78. enum icnss_driver_event_type type;
  79. bool sync;
  80. struct completion complete;
  81. int ret;
  82. void *data;
  83. };
  84. struct icnss_soc_wake_event {
  85. struct list_head list;
  86. enum icnss_soc_wake_event_type type;
  87. bool sync;
  88. struct completion complete;
  89. int ret;
  90. void *data;
  91. };
  92. enum icnss_driver_state {
  93. ICNSS_WLFW_CONNECTED,
  94. ICNSS_POWER_ON,
  95. ICNSS_FW_READY,
  96. ICNSS_DRIVER_PROBED,
  97. ICNSS_FW_TEST_MODE,
  98. ICNSS_PM_SUSPEND,
  99. ICNSS_PM_SUSPEND_NOIRQ,
  100. ICNSS_SSR_REGISTERED,
  101. ICNSS_PDR_REGISTERED,
  102. ICNSS_PD_RESTART,
  103. ICNSS_WLFW_EXISTS,
  104. ICNSS_SHUTDOWN_DONE,
  105. ICNSS_HOST_TRIGGERED_PDR,
  106. ICNSS_FW_DOWN,
  107. ICNSS_DRIVER_UNLOADING,
  108. ICNSS_REJUVENATE,
  109. ICNSS_MODE_ON,
  110. ICNSS_BLOCK_SHUTDOWN,
  111. ICNSS_PDR,
  112. ICNSS_DEL_SERVER,
  113. ICNSS_COLD_BOOT_CAL,
  114. ICNSS_QMI_DMS_CONNECTED,
  115. ICNSS_SLATE_SSR_REGISTERED,
  116. ICNSS_SLATE_UP,
  117. };
  118. struct ce_irq_list {
  119. int irq;
  120. irqreturn_t (*handler)(int irq, void *priv);
  121. };
  122. struct icnss_vreg_cfg {
  123. const char *name;
  124. u32 min_uv;
  125. u32 max_uv;
  126. u32 load_ua;
  127. u32 delay_us;
  128. u32 need_unvote;
  129. bool required;
  130. bool is_supported;
  131. };
  132. struct icnss_vreg_info {
  133. struct list_head list;
  134. struct regulator *reg;
  135. struct icnss_vreg_cfg cfg;
  136. u32 enabled;
  137. };
  138. struct icnss_cpr_info {
  139. const char *vreg_ol_cpr;
  140. u32 voltage;
  141. };
  142. enum icnss_vreg_type {
  143. ICNSS_VREG_PRIM,
  144. };
  145. struct icnss_clk_cfg {
  146. const char *name;
  147. u32 freq;
  148. u32 required;
  149. };
  150. struct icnss_battery_level {
  151. int lower_battery_threshold;
  152. int ldo_voltage;
  153. };
  154. struct icnss_clk_info {
  155. struct list_head list;
  156. struct clk *clk;
  157. struct icnss_clk_cfg cfg;
  158. u32 enabled;
  159. };
  160. struct icnss_fw_mem {
  161. size_t size;
  162. void *va;
  163. phys_addr_t pa;
  164. u8 valid;
  165. u32 type;
  166. unsigned long attrs;
  167. };
  168. enum icnss_smp2p_msg_id {
  169. ICNSS_RESET_MSG,
  170. ICNSS_POWER_SAVE_ENTER,
  171. ICNSS_POWER_SAVE_EXIT,
  172. ICNSS_TRIGGER_SSR,
  173. ICNSS_SOC_WAKE_REQ,
  174. ICNSS_SOC_WAKE_REL,
  175. ICNSS_PCI_EP_POWER_SAVE_ENTER,
  176. ICNSS_PCI_EP_POWER_SAVE_EXIT,
  177. };
  178. struct icnss_subsys_restart_level_data {
  179. uint8_t restart_level;
  180. };
  181. struct icnss_stats {
  182. struct {
  183. uint32_t posted;
  184. uint32_t processed;
  185. } events[ICNSS_DRIVER_EVENT_MAX];
  186. struct {
  187. u32 posted;
  188. u32 processed;
  189. } soc_wake_events[ICNSS_SOC_WAKE_EVENT_MAX];
  190. struct {
  191. uint32_t request;
  192. uint32_t free;
  193. uint32_t enable;
  194. uint32_t disable;
  195. } ce_irqs[ICNSS_MAX_IRQ_REGISTRATIONS];
  196. struct {
  197. uint32_t pdr_fw_crash;
  198. uint32_t pdr_host_error;
  199. uint32_t root_pd_crash;
  200. uint32_t root_pd_shutdown;
  201. } recovery;
  202. uint32_t pm_suspend;
  203. uint32_t pm_suspend_err;
  204. uint32_t pm_resume;
  205. uint32_t pm_resume_err;
  206. uint32_t pm_suspend_noirq;
  207. uint32_t pm_suspend_noirq_err;
  208. uint32_t pm_resume_noirq;
  209. uint32_t pm_resume_noirq_err;
  210. uint32_t pm_stay_awake;
  211. uint32_t pm_relax;
  212. uint32_t ind_register_req;
  213. uint32_t ind_register_resp;
  214. uint32_t ind_register_err;
  215. uint32_t msa_info_req;
  216. uint32_t msa_info_resp;
  217. uint32_t msa_info_err;
  218. uint32_t msa_ready_req;
  219. uint32_t msa_ready_resp;
  220. uint32_t msa_ready_err;
  221. uint32_t msa_ready_ind;
  222. uint32_t cap_req;
  223. uint32_t cap_resp;
  224. uint32_t cap_err;
  225. uint32_t pin_connect_result;
  226. uint32_t cfg_req;
  227. uint32_t cfg_resp;
  228. uint32_t cfg_req_err;
  229. uint32_t mode_req;
  230. uint32_t mode_resp;
  231. uint32_t mode_req_err;
  232. uint32_t ini_req;
  233. uint32_t ini_resp;
  234. uint32_t ini_req_err;
  235. u32 rejuvenate_ind;
  236. uint32_t rejuvenate_ack_req;
  237. uint32_t rejuvenate_ack_resp;
  238. uint32_t rejuvenate_ack_err;
  239. uint32_t device_info_req;
  240. uint32_t device_info_resp;
  241. uint32_t device_info_err;
  242. u32 exit_power_save_req;
  243. u32 exit_power_save_resp;
  244. u32 exit_power_save_err;
  245. u32 enter_power_save_req;
  246. u32 enter_power_save_resp;
  247. u32 enter_power_save_err;
  248. u32 soc_wake_req;
  249. u32 soc_wake_resp;
  250. u32 soc_wake_err;
  251. u32 restart_level_req;
  252. u32 restart_level_resp;
  253. u32 restart_level_err;
  254. };
  255. #define WLFW_MAX_TIMESTAMP_LEN 32
  256. #define WLFW_MAX_BUILD_ID_LEN 128
  257. #define WLFW_MAX_NUM_MEMORY_REGIONS 2
  258. #define WLFW_FUNCTION_NAME_LEN 129
  259. #define WLFW_MAX_DATA_SIZE 6144
  260. #define WLFW_MAX_STR_LEN 16
  261. #define WLFW_MAX_NUM_CE 12
  262. #define WLFW_MAX_NUM_SVC 24
  263. #define WLFW_MAX_NUM_SHADOW_REG 24
  264. #define WLFW_MAX_HANG_EVENT_DATA_SIZE 400
  265. struct wlfw_rf_chip_info {
  266. uint32_t chip_id;
  267. uint32_t chip_family;
  268. };
  269. struct wlfw_rf_board_info {
  270. uint32_t board_id;
  271. };
  272. struct wlfw_fw_version_info {
  273. uint32_t fw_version;
  274. char fw_build_timestamp[WLFW_MAX_TIMESTAMP_LEN + 1];
  275. };
  276. struct icnss_mem_region_info {
  277. uint64_t reg_addr;
  278. uint32_t size;
  279. uint8_t secure_flag;
  280. };
  281. struct icnss_msi_user {
  282. char *name;
  283. int num_vectors;
  284. u32 base_vector;
  285. };
  286. struct icnss_msi_config {
  287. int total_vectors;
  288. int total_users;
  289. struct icnss_msi_user *users;
  290. };
  291. struct icnss_thermal_cdev {
  292. struct list_head tcdev_list;
  293. int tcdev_id;
  294. unsigned long curr_thermal_state;
  295. unsigned long max_thermal_state;
  296. struct device_node *dev_node;
  297. struct thermal_cooling_device *tcdev;
  298. };
  299. enum smp2p_out_entry {
  300. ICNSS_SMP2P_OUT_POWER_SAVE,
  301. ICNSS_SMP2P_OUT_SOC_WAKE,
  302. ICNSS_SMP2P_OUT_EP_POWER_SAVE,
  303. ICNSS_SMP2P_OUT_MAX
  304. };
  305. static const char * const icnss_smp2p_str[] = {
  306. [ICNSS_SMP2P_OUT_POWER_SAVE] = "wlan-smp2p-out",
  307. [ICNSS_SMP2P_OUT_SOC_WAKE] = "wlan-soc-wake-smp2p-out",
  308. [ICNSS_SMP2P_OUT_EP_POWER_SAVE] = "wlan-ep-powersave-smp2p-out",
  309. };
  310. struct smp2p_out_info {
  311. unsigned short seq;
  312. unsigned int smem_bit;
  313. struct qcom_smem_state *smem_state;
  314. };
  315. struct icnss_dms_data {
  316. u8 mac_valid;
  317. u8 nv_mac_not_prov;
  318. u8 mac[QMI_WLFW_MAC_ADDR_SIZE_V01];
  319. };
  320. struct icnss_ramdump_info {
  321. int minor;
  322. char name[32];
  323. struct device *dev;
  324. };
  325. struct icnss_priv {
  326. uint32_t magic;
  327. struct platform_device *pdev;
  328. struct icnss_driver_ops *ops;
  329. struct ce_irq_list ce_irq_list[ICNSS_MAX_IRQ_REGISTRATIONS];
  330. struct list_head vreg_list;
  331. struct list_head clk_list;
  332. struct icnss_cpr_info cpr_info;
  333. unsigned long device_id;
  334. struct icnss_msi_config *msi_config;
  335. u32 msi_base_data;
  336. struct icnss_control_params ctrl_params;
  337. u8 cal_done;
  338. u8 use_prefix_path;
  339. u32 ce_irqs[ICNSS_MAX_IRQ_REGISTRATIONS];
  340. u32 srng_irqs[IWCN_MAX_IRQ_REGISTRATIONS];
  341. phys_addr_t mem_base_pa;
  342. void __iomem *mem_base_va;
  343. u32 mem_base_size;
  344. phys_addr_t mhi_state_info_pa;
  345. void __iomem *mhi_state_info_va;
  346. u32 mhi_state_info_size;
  347. struct iommu_domain *iommu_domain;
  348. dma_addr_t smmu_iova_start;
  349. size_t smmu_iova_len;
  350. dma_addr_t smmu_iova_ipa_start;
  351. dma_addr_t smmu_iova_ipa_current;
  352. size_t smmu_iova_ipa_len;
  353. struct qmi_handle qmi;
  354. struct qmi_handle qmi_dms;
  355. struct list_head event_list;
  356. struct list_head soc_wake_msg_list;
  357. spinlock_t event_lock;
  358. spinlock_t soc_wake_msg_lock;
  359. struct work_struct event_work;
  360. struct work_struct fw_recv_msg_work;
  361. struct work_struct soc_wake_msg_work;
  362. struct workqueue_struct *event_wq;
  363. struct workqueue_struct *soc_wake_wq;
  364. phys_addr_t msa_pa;
  365. phys_addr_t msi_addr_pa;
  366. dma_addr_t msi_addr_iova;
  367. uint32_t msa_mem_size;
  368. void *msa_va;
  369. unsigned long state;
  370. struct wlfw_rf_chip_info chip_info;
  371. uint32_t board_id;
  372. uint32_t soc_id;
  373. struct wlfw_fw_version_info fw_version_info;
  374. char fw_build_id[WLFW_MAX_BUILD_ID_LEN + 1];
  375. u32 pwr_pin_result;
  376. u32 phy_io_pin_result;
  377. u32 rf_pin_result;
  378. uint32_t nr_mem_region;
  379. struct icnss_mem_region_info
  380. mem_region[WLFW_MAX_NUM_MEMORY_REGIONS];
  381. struct dentry *root_dentry;
  382. spinlock_t on_off_lock;
  383. struct icnss_stats stats;
  384. void *modem_notify_handler;
  385. void *wpss_notify_handler;
  386. void *wpss_early_notify_handler;
  387. struct notifier_block modem_ssr_nb;
  388. struct notifier_block wpss_ssr_nb;
  389. struct notifier_block wpss_early_ssr_nb;
  390. void *slate_notify_handler;
  391. struct notifier_block slate_ssr_nb;
  392. uint32_t diag_reg_read_addr;
  393. uint32_t diag_reg_read_mem_type;
  394. uint32_t diag_reg_read_len;
  395. uint8_t *diag_reg_read_buf;
  396. atomic_t pm_count;
  397. struct icnss_ramdump_info *msa0_dump_dev;
  398. struct icnss_ramdump_info *m3_dump_phyareg;
  399. struct icnss_ramdump_info *m3_dump_phydbg;
  400. struct icnss_ramdump_info *m3_dump_wmac0reg;
  401. struct icnss_ramdump_info *m3_dump_wcssdbg;
  402. struct icnss_ramdump_info *m3_dump_phyapdmem;
  403. bool force_err_fatal;
  404. bool allow_recursive_recovery;
  405. bool early_crash_ind;
  406. u8 cause_for_rejuvenation;
  407. u8 requesting_sub_system;
  408. u16 line_number;
  409. struct mutex dev_lock;
  410. uint32_t fw_error_fatal_irq;
  411. uint32_t fw_early_crash_irq;
  412. struct smp2p_out_info smp2p_info[ICNSS_SMP2P_OUT_MAX];
  413. struct completion unblock_shutdown;
  414. char function_name[WLFW_FUNCTION_NAME_LEN + 1];
  415. bool is_ssr;
  416. bool smmu_s1_enable;
  417. struct kobject *icnss_kobject;
  418. struct rproc *rproc;
  419. atomic_t is_shutdown;
  420. u32 qdss_mem_seg_len;
  421. struct icnss_fw_mem qdss_mem[QMI_WLFW_MAX_NUM_MEM_SEG_V01];
  422. void *get_info_cb_ctx;
  423. int (*get_info_cb)(void *ctx, void *event, int event_len);
  424. atomic_t soc_wake_ref_count;
  425. phys_addr_t hang_event_data_pa;
  426. void __iomem *hang_event_data_va;
  427. uint16_t hang_event_data_len;
  428. void *hang_event_data;
  429. struct list_head icnss_tcdev_list;
  430. struct mutex tcdev_lock;
  431. bool is_chain1_supported;
  432. bool chain_reg_info_updated;
  433. u32 hw_trc_override;
  434. struct icnss_dms_data dms;
  435. u8 use_nv_mac;
  436. struct pdr_handle *pdr_handle;
  437. struct pdr_service *pdr_service;
  438. bool root_pd_shutdown;
  439. struct mbox_client mbox_client_data;
  440. struct mbox_chan *mbox_chan;
  441. u32 wlan_en_delay_ms;
  442. u32 wlan_en_delay_ms_user;
  443. struct class *icnss_ramdump_class;
  444. dev_t icnss_ramdump_dev;
  445. struct completion smp2p_soc_wake_wait;
  446. uint32_t fw_soc_wake_ack_irq;
  447. char foundry_name;
  448. bool bdf_download_support;
  449. bool psf_supported;
  450. struct notifier_block psf_nb;
  451. struct power_supply *batt_psy;
  452. int last_updated_voltage;
  453. struct work_struct soc_update_work;
  454. struct workqueue_struct *soc_update_wq;
  455. unsigned long device_config;
  456. bool wpss_supported;
  457. bool is_rf_subtype_valid;
  458. u32 rf_subtype;
  459. u8 is_slate_rfa;
  460. struct completion slate_boot_complete;
  461. };
  462. struct icnss_reg_info {
  463. uint32_t mem_type;
  464. uint32_t reg_offset;
  465. uint32_t data_len;
  466. };
  467. void icnss_free_qdss_mem(struct icnss_priv *priv);
  468. char *icnss_driver_event_to_str(enum icnss_driver_event_type type);
  469. int icnss_call_driver_uevent(struct icnss_priv *priv,
  470. enum icnss_uevent uevent, void *data);
  471. int icnss_driver_event_post(struct icnss_priv *priv,
  472. enum icnss_driver_event_type type,
  473. u32 flags, void *data);
  474. void icnss_allow_recursive_recovery(struct device *dev);
  475. void icnss_disallow_recursive_recovery(struct device *dev);
  476. char *icnss_soc_wake_event_to_str(enum icnss_soc_wake_event_type type);
  477. int icnss_soc_wake_event_post(struct icnss_priv *priv,
  478. enum icnss_soc_wake_event_type type,
  479. u32 flags, void *data);
  480. int icnss_get_iova(struct icnss_priv *priv, u64 *addr, u64 *size);
  481. int icnss_get_iova_ipa(struct icnss_priv *priv, u64 *addr, u64 *size);
  482. int icnss_update_cpr_info(struct icnss_priv *priv);
  483. void icnss_add_fw_prefix_name(struct icnss_priv *priv, char *prefix_name,
  484. char *name);
  485. int icnss_aop_mbox_init(struct icnss_priv *priv);
  486. #endif