main.h 12 KB

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