main.h 12 KB

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