main.h 12 KB

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