Kai Liu | 4cf2139 | 2017-12-15 21:14:08 +0800 | [diff] [blame] | 1 | /* Copyright (c) 2013-2018, The Linux Foundation. All rights reserved. |
| 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License version 2 and |
| 5 | * only version 2 as published by the Free Software Foundation. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | */ |
| 12 | #ifndef _NET_CNSS_H_ |
| 13 | #define _NET_CNSS_H_ |
| 14 | |
| 15 | #include <linux/device.h> |
| 16 | #include <linux/skbuff.h> |
| 17 | #include <linux/pci.h> |
| 18 | #include <linux/mmc/sdio_func.h> |
| 19 | #include <linux/interrupt.h> |
| 20 | |
| 21 | #ifdef CONFIG_CNSS |
| 22 | #define MAX_FIRMWARE_SIZE (1 * 1024 * 1024) |
| 23 | #define CNSS_MAX_FILE_NAME 20 |
| 24 | #define PINCTRL_SLEEP 0 |
| 25 | #define PINCTRL_ACTIVE 1 |
| 26 | |
| 27 | enum cnss_bus_width_type { |
| 28 | CNSS_BUS_WIDTH_NONE, |
| 29 | CNSS_BUS_WIDTH_LOW, |
| 30 | CNSS_BUS_WIDTH_MEDIUM, |
| 31 | CNSS_BUS_WIDTH_HIGH |
| 32 | }; |
| 33 | |
| 34 | enum cnss_cc_src { |
| 35 | CNSS_SOURCE_CORE, |
| 36 | CNSS_SOURCE_11D, |
| 37 | CNSS_SOURCE_USER |
| 38 | }; |
| 39 | |
| 40 | /* FW image files */ |
| 41 | struct cnss_fw_files { |
| 42 | char image_file[CNSS_MAX_FILE_NAME]; |
| 43 | char board_data[CNSS_MAX_FILE_NAME]; |
| 44 | char otp_data[CNSS_MAX_FILE_NAME]; |
| 45 | char utf_file[CNSS_MAX_FILE_NAME]; |
| 46 | char utf_board_data[CNSS_MAX_FILE_NAME]; |
| 47 | char epping_file[CNSS_MAX_FILE_NAME]; |
| 48 | char evicted_data[CNSS_MAX_FILE_NAME]; |
| 49 | }; |
| 50 | |
| 51 | struct cnss_wlan_runtime_ops { |
| 52 | int (*runtime_suspend)(struct pci_dev *pdev); |
| 53 | int (*runtime_resume)(struct pci_dev *pdev); |
| 54 | }; |
| 55 | |
| 56 | struct cnss_wlan_driver { |
| 57 | char *name; |
| 58 | int (*probe)(struct pci_dev *pdev, const struct pci_device_id *id); |
| 59 | void (*remove)(struct pci_dev *pdev); |
| 60 | int (*reinit)(struct pci_dev *pdev, const struct pci_device_id *id); |
| 61 | void (*shutdown)(struct pci_dev *pdev); |
| 62 | void (*crash_shutdown)(struct pci_dev *pdev); |
| 63 | int (*suspend)(struct pci_dev *pdev, pm_message_t state); |
| 64 | int (*resume)(struct pci_dev *pdev); |
| 65 | void (*modem_status)(struct pci_dev *, int state); |
| 66 | void (*update_status)(struct pci_dev *pdev, uint32_t status); |
| 67 | struct cnss_wlan_runtime_ops *runtime_ops; |
| 68 | const struct pci_device_id *id_table; |
| 69 | }; |
| 70 | |
| 71 | /* |
| 72 | * codeseg_total_bytes: Total bytes across all the codesegment blocks |
| 73 | * num_codesegs: No of Pages used |
| 74 | * codeseg_size: Size of each segment. Should be power of 2 and multiple of 4K |
| 75 | * codeseg_size_log2: log2(codeseg_size) |
| 76 | * codeseg_busaddr: Physical address of the DMAble memory;4K aligned |
| 77 | */ |
| 78 | |
| 79 | #define CODESWAP_MAX_CODESEGS 16 |
| 80 | struct codeswap_codeseg_info { |
| 81 | u32 codeseg_total_bytes; |
| 82 | u32 num_codesegs; |
| 83 | u32 codeseg_size; |
| 84 | u32 codeseg_size_log2; |
| 85 | void *codeseg_busaddr[CODESWAP_MAX_CODESEGS]; |
| 86 | }; |
| 87 | |
| 88 | struct image_desc_info { |
| 89 | dma_addr_t fw_addr; |
| 90 | u32 fw_size; |
| 91 | dma_addr_t bdata_addr; |
| 92 | u32 bdata_size; |
| 93 | }; |
| 94 | |
| 95 | /* platform capabilities */ |
| 96 | enum cnss_platform_cap_flag { |
| 97 | CNSS_HAS_EXTERNAL_SWREG = 0x01, |
| 98 | CNSS_HAS_UART_ACCESS = 0x02, |
| 99 | }; |
| 100 | |
| 101 | struct cnss_platform_cap { |
| 102 | u32 cap_flag; |
| 103 | }; |
| 104 | |
Yu Wang | e1d64b8 | 2017-12-26 14:43:21 +0800 | [diff] [blame] | 105 | /* WLAN driver status, keep it aligned with cnss2 */ |
Kai Liu | 4cf2139 | 2017-12-15 21:14:08 +0800 | [diff] [blame] | 106 | enum cnss_driver_status { |
| 107 | CNSS_UNINITIALIZED, |
| 108 | CNSS_INITIALIZED, |
Yu Wang | e1d64b8 | 2017-12-26 14:43:21 +0800 | [diff] [blame] | 109 | CNSS_LOAD_UNLOAD, |
| 110 | CNSS_RECOVERY, |
| 111 | CNSS_FW_DOWN, |
| 112 | CNSS_SSR_FAIL, |
Kai Liu | 4cf2139 | 2017-12-15 21:14:08 +0800 | [diff] [blame] | 113 | }; |
| 114 | |
| 115 | enum cnss_runtime_request { |
| 116 | CNSS_PM_RUNTIME_GET, |
| 117 | CNSS_PM_RUNTIME_PUT, |
| 118 | CNSS_PM_RUNTIME_MARK_LAST_BUSY, |
| 119 | CNSS_PM_RUNTIME_RESUME, |
| 120 | CNSS_PM_RUNTIME_PUT_NOIDLE, |
| 121 | CNSS_PM_REQUEST_RESUME, |
| 122 | CNSS_PM_RUNTIME_PUT_AUTO, |
| 123 | CNSS_PM_GET_NORESUME, |
| 124 | }; |
| 125 | |
Tang Yingying | a154fba | 2018-03-07 17:27:19 +0800 | [diff] [blame] | 126 | extern struct dma_iommu_mapping *cnss_smmu_get_mapping(void); |
| 127 | extern int cnss_smmu_map(phys_addr_t paddr, uint32_t *iova_addr, size_t size); |
Kai Liu | 4cf2139 | 2017-12-15 21:14:08 +0800 | [diff] [blame] | 128 | extern int cnss_get_fw_image(struct image_desc_info *image_desc_info); |
| 129 | extern void cnss_runtime_init(struct device *dev, int auto_delay); |
| 130 | extern void cnss_runtime_exit(struct device *dev); |
| 131 | extern void cnss_wlan_pci_link_down(void); |
| 132 | extern int cnss_pcie_shadow_control(struct pci_dev *dev, bool enable); |
| 133 | extern int cnss_wlan_register_driver(struct cnss_wlan_driver *driver); |
| 134 | extern void cnss_wlan_unregister_driver(struct cnss_wlan_driver *driver); |
| 135 | extern int cnss_get_fw_files(struct cnss_fw_files *pfw_files); |
| 136 | extern int cnss_get_fw_files_for_target(struct cnss_fw_files *pfw_files, |
| 137 | u32 target_type, u32 target_version); |
| 138 | extern void cnss_get_qca9377_fw_files(struct cnss_fw_files *pfw_files, |
| 139 | u32 size, u32 tufello_dual_fw); |
| 140 | |
| 141 | extern int cnss_request_bus_bandwidth(int bandwidth); |
| 142 | |
| 143 | #ifdef CONFIG_CNSS_SECURE_FW |
| 144 | extern int cnss_get_sha_hash(const u8 *data, u32 data_len, |
| 145 | u8 *hash_idx, u8 *out); |
| 146 | extern void *cnss_get_fw_ptr(void); |
| 147 | #endif |
| 148 | |
| 149 | extern int cnss_get_codeswap_struct(struct codeswap_codeseg_info *swap_seg); |
| 150 | extern int cnss_get_bmi_setup(void); |
| 151 | |
| 152 | #ifdef CONFIG_PCI_MSM |
| 153 | extern int cnss_wlan_pm_control(bool vote); |
| 154 | #endif |
| 155 | extern void cnss_lock_pm_sem(void); |
| 156 | extern void cnss_release_pm_sem(void); |
| 157 | |
| 158 | extern void cnss_request_pm_qos_type(int latency_type, u32 qos_val); |
| 159 | extern void cnss_request_pm_qos(u32 qos_val); |
| 160 | extern void cnss_remove_pm_qos(void); |
| 161 | |
| 162 | extern void cnss_pci_request_pm_qos_type(int latency_type, u32 qos_val); |
| 163 | extern void cnss_pci_request_pm_qos(u32 qos_val); |
| 164 | extern void cnss_pci_remove_pm_qos(void); |
| 165 | |
| 166 | extern void cnss_sdio_request_pm_qos_type(int latency_type, u32 qos_val); |
| 167 | extern void cnss_sdio_request_pm_qos(u32 qos_val); |
| 168 | extern void cnss_sdio_remove_pm_qos(void); |
| 169 | |
| 170 | extern int cnss_get_platform_cap(struct cnss_platform_cap *cap); |
| 171 | extern void cnss_set_driver_status(enum cnss_driver_status driver_status); |
| 172 | |
| 173 | #ifndef CONFIG_WCNSS_MEM_PRE_ALLOC |
| 174 | static inline int wcnss_pre_alloc_reset(void) { return 0; } |
| 175 | #endif |
| 176 | |
| 177 | extern int msm_pcie_enumerate(u32 rc_idx); |
| 178 | extern int cnss_auto_suspend(void); |
| 179 | extern int cnss_auto_resume(void); |
| 180 | extern int cnss_prevent_auto_suspend(const char *caller_func); |
| 181 | extern int cnss_allow_auto_suspend(const char *caller_func); |
| 182 | extern int cnss_is_auto_suspend_allowed(const char *caller_func); |
| 183 | |
| 184 | extern int cnss_pm_runtime_request(struct device *dev, enum |
| 185 | cnss_runtime_request request); |
| 186 | extern void cnss_set_cc_source(enum cnss_cc_src cc_source); |
| 187 | extern enum cnss_cc_src cnss_get_cc_source(void); |
| 188 | #endif |
| 189 | |
| 190 | extern void cnss_pm_wake_lock_init(struct wakeup_source *ws, const char *name); |
| 191 | extern void cnss_pm_wake_lock(struct wakeup_source *ws); |
| 192 | |
| 193 | extern void cnss_device_crashed(void); |
| 194 | extern void cnss_device_self_recovery(void); |
| 195 | extern void *cnss_get_virt_ramdump_mem(unsigned long *size); |
| 196 | |
| 197 | extern void cnss_schedule_recovery_work(void); |
| 198 | extern int cnss_pcie_set_wlan_mac_address(const u8 *in, uint32_t len); |
| 199 | extern u8 *cnss_get_wlan_mac_address(struct device *dev, uint32_t *num); |
| 200 | extern int cnss_sdio_set_wlan_mac_address(const u8 *in, uint32_t len); |
| 201 | |
| 202 | enum { |
| 203 | CNSS_RESET_SOC = 0, |
| 204 | CNSS_RESET_SUBSYS_COUPLED, |
| 205 | CNSS_RESET_LEVEL_MAX |
| 206 | }; |
| 207 | extern int cnss_get_restart_level(void); |
| 208 | |
| 209 | struct cnss_sdio_wlan_driver { |
| 210 | const char *name; |
| 211 | const struct sdio_device_id *id_table; |
| 212 | int (*probe)(struct sdio_func *, const struct sdio_device_id *); |
| 213 | void (*remove)(struct sdio_func *); |
| 214 | int (*reinit)(struct sdio_func *, const struct sdio_device_id *); |
| 215 | void (*shutdown)(struct sdio_func *); |
| 216 | void (*crash_shutdown)(struct sdio_func *); |
| 217 | int (*suspend)(struct device *); |
| 218 | int (*resume)(struct device *); |
| 219 | }; |
| 220 | |
| 221 | extern int cnss_sdio_wlan_register_driver( |
| 222 | struct cnss_sdio_wlan_driver *driver); |
| 223 | extern void cnss_sdio_wlan_unregister_driver( |
| 224 | struct cnss_sdio_wlan_driver *driver); |
| 225 | |
| 226 | typedef void (*oob_irq_handler_t)(void *dev_para); |
| 227 | extern int cnss_wlan_query_oob_status(void); |
| 228 | extern int cnss_wlan_register_oob_irq_handler(oob_irq_handler_t handler, |
| 229 | void *pm_oob); |
| 230 | extern int cnss_wlan_unregister_oob_irq_handler(void *pm_oob); |
| 231 | |
| 232 | |
| 233 | extern void cnss_dump_stack(struct task_struct *task); |
| 234 | extern u8 *cnss_common_get_wlan_mac_address(struct device *dev, uint32_t *num); |
| 235 | extern void cnss_init_work(struct work_struct *work, work_func_t func); |
| 236 | extern void cnss_flush_delayed_work(void *dwork); |
| 237 | extern void cnss_flush_work(void *work); |
| 238 | extern void cnss_pm_wake_lock_timeout(struct wakeup_source *ws, ulong msec); |
| 239 | extern void cnss_pm_wake_lock_release(struct wakeup_source *ws); |
| 240 | extern void cnss_pm_wake_lock_destroy(struct wakeup_source *ws); |
| 241 | extern void cnss_get_monotonic_boottime(struct timespec *ts); |
| 242 | extern void cnss_get_boottime(struct timespec *ts); |
| 243 | extern void cnss_init_delayed_work(struct delayed_work *work, work_func_t |
| 244 | func); |
| 245 | extern int cnss_vendor_cmd_reply(struct sk_buff *skb); |
| 246 | extern int cnss_set_cpus_allowed_ptr(struct task_struct *task, ulong cpu); |
| 247 | extern int cnss_set_wlan_unsafe_channel(u16 *unsafe_ch_list, u16 ch_count); |
| 248 | extern int cnss_get_wlan_unsafe_channel(u16 *unsafe_ch_list, u16 *ch_count, |
| 249 | u16 buf_len); |
| 250 | extern int cnss_wlan_set_dfs_nol(const void *info, u16 info_len); |
| 251 | extern int cnss_wlan_get_dfs_nol(void *info, u16 info_len); |
| 252 | extern int cnss_common_request_bus_bandwidth(struct device *dev, int |
| 253 | bandwidth); |
| 254 | extern void cnss_common_device_crashed(struct device *dev); |
| 255 | extern void cnss_common_device_self_recovery(struct device *dev); |
| 256 | extern void *cnss_common_get_virt_ramdump_mem(struct device *dev, unsigned long |
| 257 | *size); |
| 258 | extern void cnss_common_schedule_recovery_work(struct device *dev); |
| 259 | extern int cnss_common_set_wlan_mac_address(struct device *dev, const u8 *in, |
| 260 | uint32_t len); |
| 261 | extern u8 *cnss_common_get_wlan_mac_address(struct device *dev, uint32_t *num); |
| 262 | extern int cnss_power_up(struct device *dev); |
| 263 | extern int cnss_power_down(struct device *dev); |
| 264 | extern int cnss_sdio_configure_spdt(bool state); |
| 265 | |
| 266 | extern int cnss_common_register_tsf_captured_handler(struct device *dev, |
| 267 | irq_handler_t handler, |
| 268 | void *ctx); |
| 269 | extern int cnss_common_unregister_tsf_captured_handler(struct device *dev, |
| 270 | void *ctx); |
| 271 | #endif /* _NET_CNSS_H_ */ |