main.h 12 KB

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