blob: 35b6c35393e72215e0a7e67e597ba6069e918c0c [file] [log] [blame]
Yuanyuan Liud9f7a362016-01-22 14:27:12 -08001/*
Yue Ma502a28f2017-01-03 16:38:44 -08002 * Copyright (c) 2016-2017 The Linux Foundation. All rights reserved.
Yuanyuan Liud9f7a362016-01-22 14:27:12 -08003 *
4 * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
5 *
6 *
7 * Permission to use, copy, modify, and/or distribute this software for
8 * any purpose with or without fee is hereby granted, provided that the
9 * above copyright notice and this permission notice appear in all
10 * copies.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
13 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
14 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
15 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
16 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
17 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
18 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19 * PERFORMANCE OF THIS SOFTWARE.
20 */
21
22/*
23 * This file was originally distributed by Qualcomm Atheros, Inc.
24 * under proprietary terms before Copyright ownership was assigned
25 * to the Linux Foundation.
26 */
27
28#ifndef __PLD_COMMON_H__
29#define __PLD_COMMON_H__
30
31#include <linux/device.h>
32#include <linux/interrupt.h>
33#include <linux/pm.h>
Yu Wang66e4ff22017-02-15 19:09:24 +080034#include <osapi_linux.h>
Yuanyuan Liud9f7a362016-01-22 14:27:12 -080035
Yuanyuan Liu6a313dc2016-05-10 14:19:10 -070036#define PLD_IMAGE_FILE "athwlan.bin"
37#define PLD_UTF_FIRMWARE_FILE "utf.bin"
38#define PLD_BOARD_DATA_FILE "fakeboar.bin"
39#define PLD_OTP_FILE "otp.bin"
40#define PLD_SETUP_FILE "athsetup.bin"
41#define PLD_EPPING_FILE "epping.bin"
42#define PLD_EVICTED_FILE ""
43
Yuanyuan Liud9f7a362016-01-22 14:27:12 -080044/**
45 * enum pld_bus_type - bus type
46 * @PLD_BUS_TYPE_NONE: invalid bus type, only return in error cases
47 * @PLD_BUS_TYPE_PCIE: PCIE bus
48 * @PLD_BUS_TYPE_SNOC: SNOC bus
49 */
50enum pld_bus_type {
51 PLD_BUS_TYPE_NONE = -1,
52 PLD_BUS_TYPE_PCIE = 0,
Govind Singh6a2fe032016-05-13 14:09:37 +053053 PLD_BUS_TYPE_SNOC,
Mohit Khanna1d531c42016-05-12 21:35:50 -070054 PLD_BUS_TYPE_SDIO,
55 PLD_BUS_TYPE_USB
Yuanyuan Liud9f7a362016-01-22 14:27:12 -080056};
57
58#define PLD_MAX_FIRMWARE_SIZE (1 * 1024 * 1024)
59
60/**
61 * enum pld_bus_width_type - bus bandwith
62 * @PLD_BUS_WIDTH_NONE: don't vote for bus bandwidth
63 * @PLD_BUS_WIDTH_LOW: vote for low bus bandwidth
64 * @PLD_BUS_WIDTH_MEDIUM: vote for medium bus bandwidth
65 * @PLD_BUS_WIDTH_HIGH: vote for high bus bandwidth
66 */
67enum pld_bus_width_type {
68 PLD_BUS_WIDTH_NONE,
69 PLD_BUS_WIDTH_LOW,
70 PLD_BUS_WIDTH_MEDIUM,
71 PLD_BUS_WIDTH_HIGH
72};
73
Yu Wang66e4ff22017-02-15 19:09:24 +080074#define PLD_MAX_FILE_NAME NAME_MAX
Yuanyuan Liud9f7a362016-01-22 14:27:12 -080075
76/**
77 * struct pld_fw_file - WLAN FW file names
78 * @image_file: WLAN FW image file
79 * @board_data: WLAN FW board data file
80 * @otp_data: WLAN FW OTP file
81 * @utf_file: WLAN FW UTF file
82 * @utf_board_data: WLAN FW UTF board data file
83 * @epping_file: WLAN FW EPPING mode file
84 * @evicted_data: WLAN FW evicted file
Yuanyuan Liu6a313dc2016-05-10 14:19:10 -070085 * @setup_file: WLAN FW setup file
Yuanyuan Liud9f7a362016-01-22 14:27:12 -080086 *
87 * pld_fw_files is used to store WLAN FW file names
88 */
89struct pld_fw_files {
90 char image_file[PLD_MAX_FILE_NAME];
91 char board_data[PLD_MAX_FILE_NAME];
92 char otp_data[PLD_MAX_FILE_NAME];
93 char utf_file[PLD_MAX_FILE_NAME];
94 char utf_board_data[PLD_MAX_FILE_NAME];
95 char epping_file[PLD_MAX_FILE_NAME];
96 char evicted_data[PLD_MAX_FILE_NAME];
Yuanyuan Liu6a313dc2016-05-10 14:19:10 -070097 char setup_file[PLD_MAX_FILE_NAME];
Frank Liuab70c842016-10-20 10:02:18 +080098 char ibss_image_file[PLD_MAX_FILE_NAME];
Yuanyuan Liud9f7a362016-01-22 14:27:12 -080099};
100
Yuanyuan Liud9f7a362016-01-22 14:27:12 -0800101/**
102 * enum pld_platform_cap_flag - platform capability flag
103 * @PLD_HAS_EXTERNAL_SWREG: has external regulator
104 * @PLD_HAS_UART_ACCESS: has UART access
105 */
106enum pld_platform_cap_flag {
107 PLD_HAS_EXTERNAL_SWREG = 0x01,
108 PLD_HAS_UART_ACCESS = 0x02,
109};
110
111/**
112 * struct pld_platform_cap - platform capabilities
113 * @cap_flag: capabilities flag
114 *
115 * pld_platform_cap provides platform capabilities which are
116 * extracted from DTS.
117 */
118struct pld_platform_cap {
119 u32 cap_flag;
120};
121
122/**
123 * enum pld_driver_status - WLAN driver status
124 * @PLD_UNINITIALIZED: driver is uninitialized
125 * @PLD_INITIALIZED: driver is initialized
126 * @PLD_LOAD_UNLOADL: driver is in load-unload status
127 */
128enum pld_driver_status {
129 PLD_UNINITIALIZED,
130 PLD_INITIALIZED,
Yuanyuan Liu06a342f2017-01-12 16:48:19 -0800131 PLD_LOAD_UNLOAD,
132 PLD_RECOVERY,
Yuanyuan Liud9f7a362016-01-22 14:27:12 -0800133};
134
135/**
136 * struct pld_ce_tgt_pipe_cfg - copy engine target pipe configuration
137 * @pipe_num: pipe number
138 * @pipe_dir: pipe direction
139 * @nentries: number of entries
140 * @nbytes_max: max number of bytes
141 * @flags: flags
142 * @reserved: reserved
143 *
144 * pld_ce_tgt_pipe_cfg is used to store copy engine target pipe
145 * configuration.
146 */
147struct pld_ce_tgt_pipe_cfg {
148 u32 pipe_num;
149 u32 pipe_dir;
150 u32 nentries;
151 u32 nbytes_max;
152 u32 flags;
153 u32 reserved;
154};
155
156/**
157 * struct pld_ce_svc_pipe_cfg - copy engine service pipe configuration
158 * @service_id: service ID
159 * @pipe_dir: pipe direction
160 * @pipe_num: pipe number
161 *
162 * pld_ce_svc_pipe_cfg is used to store copy engine service pipe
163 * configuration.
164 */
165struct pld_ce_svc_pipe_cfg {
166 u32 service_id;
167 u32 pipe_dir;
168 u32 pipe_num;
169};
170
171/**
172 * struct pld_shadow_reg_cfg - shadow register configuration
173 * @ce_id: copy engine ID
174 * @reg_offset: register offset
175 *
176 * pld_shadow_reg_cfg is used to store shadow register configuration.
177 */
178struct pld_shadow_reg_cfg {
179 u16 ce_id;
180 u16 reg_offset;
181};
182
183/**
Yue Ma502a28f2017-01-03 16:38:44 -0800184 * struct pld_shadow_reg_v2_cfg - shadow register version 2 configuration
185 * @addr: shadow register physical address
186 *
187 * pld_shadow_reg_v2_cfg is used to store shadow register version 2
188 * configuration.
189 */
190struct pld_shadow_reg_v2_cfg {
191 u32 addr;
192};
193
194/**
Yuanyuan Liud9f7a362016-01-22 14:27:12 -0800195 * struct pld_wlan_enable_cfg - WLAN FW configuration
196 * @num_ce_tgt_cfg: number of CE target configuration
197 * @ce_tgt_cfg: CE target configuration
198 * @num_ce_svc_pipe_cfg: number of CE service configuration
199 * @ce_svc_cfg: CE service configuration
200 * @num_shadow_reg_cfg: number of shadow register configuration
201 * @shadow_reg_cfg: shadow register configuration
Yue Ma502a28f2017-01-03 16:38:44 -0800202 * @num_shadow_reg_v2_cfg: number of shadow register version 2 configuration
203 * @shadow_reg_v2_cfg: shadow register version 2 configuration
Yuanyuan Liud9f7a362016-01-22 14:27:12 -0800204 *
205 * pld_wlan_enable_cfg stores WLAN FW configurations. It will be
206 * passed to WLAN FW when WLAN host driver calls wlan_enable.
207 */
208struct pld_wlan_enable_cfg {
209 u32 num_ce_tgt_cfg;
210 struct pld_ce_tgt_pipe_cfg *ce_tgt_cfg;
211 u32 num_ce_svc_pipe_cfg;
212 struct pld_ce_svc_pipe_cfg *ce_svc_cfg;
213 u32 num_shadow_reg_cfg;
214 struct pld_shadow_reg_cfg *shadow_reg_cfg;
Yue Ma502a28f2017-01-03 16:38:44 -0800215 u32 num_shadow_reg_v2_cfg;
216 struct pld_shadow_reg_v2_cfg *shadow_reg_v2_cfg;
Yuanyuan Liud9f7a362016-01-22 14:27:12 -0800217};
218
219/**
220 * enum pld_driver_mode - WLAN host driver mode
221 * @PLD_MISSION: mission mode
222 * @PLD_FTM: FTM mode
223 * @PLD_EPPING: EPPING mode
224 * @PLD_WALTEST: WAL test mode, FW standalone test mode
225 * @PLD_OFF: OFF mode
226 */
227enum pld_driver_mode {
228 PLD_MISSION,
229 PLD_FTM,
230 PLD_EPPING,
231 PLD_WALTEST,
232 PLD_OFF
233};
234
Yuanyuan Liu0de344f2016-07-27 10:26:30 -0700235#define PLD_MAX_TIMESTAMP_LEN 32
236
Yuanyuan Liud9f7a362016-01-22 14:27:12 -0800237/**
238 * struct pld_soc_info - SOC information
239 * @v_addr: virtual address of preallocated memory
240 * @p_addr: physical address of preallcoated memory
Yuanyuan Liu0de344f2016-07-27 10:26:30 -0700241 * @chip_id: chip ID
242 * @chip_family: chip family
243 * @board_id: board ID
244 * @soc_id: SOC ID
245 * @fw_version: FW version
246 * @fw_build_timestamp: FW build timestamp
Yuanyuan Liud9f7a362016-01-22 14:27:12 -0800247 *
248 * pld_soc_info is used to store WLAN SOC information.
249 */
250struct pld_soc_info {
251 void __iomem *v_addr;
252 phys_addr_t p_addr;
Yuanyuan Liu0de344f2016-07-27 10:26:30 -0700253 u32 chip_id;
254 u32 chip_family;
255 u32 board_id;
256 u32 soc_id;
257 u32 fw_version;
258 char fw_build_timestamp[PLD_MAX_TIMESTAMP_LEN + 1];
Yuanyuan Liud9f7a362016-01-22 14:27:12 -0800259};
260
261/**
Yuanyuan Liu10fc3d32017-01-12 15:32:06 -0800262 * enum pld_recovery_reason - WLAN host driver recovery reason
263 * @PLD_REASON_DEFAULT: default
264 * @PLD_REASON_LINK_DOWN: PCIe link down
265 */
266enum pld_recovery_reason {
267 PLD_REASON_DEFAULT,
268 PLD_REASON_LINK_DOWN
269};
270
271/**
Yuanyuan Liud9f7a362016-01-22 14:27:12 -0800272 * struct pld_driver_ops - driver callback functions
273 * @probe: required operation, will be called when device is detected
274 * @remove: required operation, will be called when device is removed
275 * @shutdown: optional operation, will be called during SSR
276 * @reinit: optional operation, will be called during SSR
277 * @crash_shutdown: optional operation, will be called when a crash is
278 * detected
279 * @suspend: required operation, will be called for power management
280 * is enabled
281 * @resume: required operation, will be called for power management
282 * is enabled
283 * @modem_status: optional operation, will be called when platform driver
284 * sending modem power status to WLAN FW
Yuanyuan Liu06a342f2017-01-12 16:48:19 -0800285 * @update_status: optional operation, will be called when platform driver
286 * updating driver status
Yuanyuan Liud698eb62016-04-11 11:43:30 -0700287 * @runtime_suspend: optional operation, prepare the device for a condition
288 * in which it won't be able to communicate with the CPU(s)
289 * and RAM due to power management.
290 * @runtime_resume: optional operation, put the device into the fully
291 * active state in response to a wakeup event generated by
292 * hardware or at the request of software.
Yuanyuan Liu22896aa2016-08-29 12:17:20 -0700293 * @suspend_noirq: optional operation, complete the actions started by suspend().
294 * @resume_noirq: optional operation, prepare for the execution of resume()
Yuanyuan Liud9f7a362016-01-22 14:27:12 -0800295 */
296struct pld_driver_ops {
297 int (*probe)(struct device *dev,
298 enum pld_bus_type bus_type,
299 void *bdev, void *id);
300 void (*remove)(struct device *dev,
301 enum pld_bus_type bus_type);
302 void (*shutdown)(struct device *dev,
303 enum pld_bus_type bus_type);
304 int (*reinit)(struct device *dev,
305 enum pld_bus_type bus_type,
306 void *bdev, void *id);
307 void (*crash_shutdown)(struct device *dev,
308 enum pld_bus_type bus_type);
309 int (*suspend)(struct device *dev,
310 enum pld_bus_type bus_type,
311 pm_message_t state);
312 int (*resume)(struct device *dev,
313 enum pld_bus_type bus_type);
Mohit Khanna1d531c42016-05-12 21:35:50 -0700314 int (*reset_resume)(struct device *dev,
315 enum pld_bus_type bus_type);
Yuanyuan Liud9f7a362016-01-22 14:27:12 -0800316 void (*modem_status)(struct device *dev,
317 enum pld_bus_type bus_type,
318 int state);
Yuanyuan Liu06a342f2017-01-12 16:48:19 -0800319 void (*update_status)(struct device *dev, uint32_t status);
Yuanyuan Liud698eb62016-04-11 11:43:30 -0700320 int (*runtime_suspend)(struct device *dev,
321 enum pld_bus_type bus_type);
322 int (*runtime_resume)(struct device *dev,
323 enum pld_bus_type bus_type);
Yuanyuan Liu22896aa2016-08-29 12:17:20 -0700324 int (*suspend_noirq)(struct device *dev,
325 enum pld_bus_type bus_type);
326 int (*resume_noirq)(struct device *dev,
327 enum pld_bus_type bus_type);
Yuanyuan Liud9f7a362016-01-22 14:27:12 -0800328};
329
330int pld_init(void);
331void pld_deinit(void);
332
333int pld_register_driver(struct pld_driver_ops *ops);
334void pld_unregister_driver(void);
335
336int pld_wlan_enable(struct device *dev, struct pld_wlan_enable_cfg *config,
337 enum pld_driver_mode mode, const char *host_version);
338int pld_wlan_disable(struct device *dev, enum pld_driver_mode mode);
Yuanyuan Liu7a97b8f2017-01-27 10:42:52 -0800339int pld_set_fw_log_mode(struct device *dev, u8 fw_log_mode);
Yuanyuan Liu6a313dc2016-05-10 14:19:10 -0700340void pld_get_default_fw_files(struct pld_fw_files *pfw_files);
Yuanyuan Liud9f7a362016-01-22 14:27:12 -0800341int pld_get_fw_files_for_target(struct device *dev,
342 struct pld_fw_files *pfw_files,
343 u32 target_type, u32 target_version);
Yuanyuan Liud9f7a362016-01-22 14:27:12 -0800344void pld_is_pci_link_down(struct device *dev);
Yuanyuan Liu59f81e02016-05-19 16:17:38 -0700345int pld_shadow_control(struct device *dev, bool enable);
Yuanyuan Liud9f7a362016-01-22 14:27:12 -0800346int pld_set_wlan_unsafe_channel(struct device *dev, u16 *unsafe_ch_list,
347 u16 ch_count);
348int pld_get_wlan_unsafe_channel(struct device *dev, u16 *unsafe_ch_list,
349 u16 *ch_count, u16 buf_len);
350int pld_wlan_set_dfs_nol(struct device *dev, void *info, u16 info_len);
351int pld_wlan_get_dfs_nol(struct device *dev, void *info, u16 info_len);
Yuanyuan Liu10fc3d32017-01-12 15:32:06 -0800352void pld_schedule_recovery_work(struct device *dev,
353 enum pld_recovery_reason reason);
Yuanyuan Liud9f7a362016-01-22 14:27:12 -0800354int pld_wlan_pm_control(struct device *dev, bool vote);
355void *pld_get_virt_ramdump_mem(struct device *dev, unsigned long *size);
356void pld_device_crashed(struct device *dev);
Yuanyuan Liu10fc3d32017-01-12 15:32:06 -0800357void pld_device_self_recovery(struct device *dev,
358 enum pld_recovery_reason reason);
Yuanyuan Liud9f7a362016-01-22 14:27:12 -0800359void pld_intr_notify_q6(struct device *dev);
360void pld_request_pm_qos(struct device *dev, u32 qos_val);
361void pld_remove_pm_qos(struct device *dev);
362int pld_request_bus_bandwidth(struct device *dev, int bandwidth);
363int pld_get_platform_cap(struct device *dev, struct pld_platform_cap *cap);
364void pld_set_driver_status(struct device *dev, enum pld_driver_status status);
Yuanyuan Liud9f7a362016-01-22 14:27:12 -0800365int pld_get_sha_hash(struct device *dev, const u8 *data,
366 u32 data_len, u8 *hash_idx, u8 *out);
367void *pld_get_fw_ptr(struct device *dev);
368int pld_auto_suspend(struct device *dev);
369int pld_auto_resume(struct device *dev);
370
371int pld_ce_request_irq(struct device *dev, unsigned int ce_id,
372 irqreturn_t (*handler)(int, void *),
373 unsigned long flags, const char *name, void *ctx);
374int pld_ce_free_irq(struct device *dev, unsigned int ce_id, void *ctx);
375void pld_enable_irq(struct device *dev, unsigned int ce_id);
376void pld_disable_irq(struct device *dev, unsigned int ce_id);
377int pld_get_soc_info(struct device *dev, struct pld_soc_info *info);
378int pld_get_ce_id(struct device *dev, int irq);
Yuanyuan Liuf2ee05f2016-07-27 16:52:52 -0700379int pld_get_irq(struct device *dev, int ce_id);
Yuanyuan Liu44c44772016-04-11 11:11:27 -0700380void pld_lock_pm_sem(struct device *dev);
381void pld_release_pm_sem(struct device *dev);
Arun Khandavalli1496fcb2016-07-25 16:53:00 +0530382int pld_power_on(struct device *dev);
383int pld_power_off(struct device *dev);
Yuanyuan Liu5ef6bfe2016-06-16 14:13:07 -0700384int pld_athdiag_read(struct device *dev, uint32_t offset, uint32_t memtype,
385 uint32_t datalen, uint8_t *output);
386int pld_athdiag_write(struct device *dev, uint32_t offset, uint32_t memtype,
387 uint32_t datalen, uint8_t *input);
Yuanyuan Liu137755f2016-08-16 13:39:17 -0700388void *pld_smmu_get_mapping(struct device *dev);
389int pld_smmu_map(struct device *dev, phys_addr_t paddr,
390 uint32_t *iova_addr, size_t size);
Yue Mafd418ea2016-11-21 16:47:13 -0800391int pld_get_user_msi_assignment(struct device *dev, char *user_name,
392 int *num_vectors, uint32_t *user_base_data,
393 uint32_t *base_vector);
394int pld_get_msi_irq(struct device *dev, unsigned int vector);
395void pld_get_msi_address(struct device *dev, uint32_t *msi_addr_low,
396 uint32_t *msi_addr_high);
Yuanyuan Liuf97e8222016-09-21 10:31:38 -0700397unsigned int pld_socinfo_get_serial_number(struct device *dev);
Yuanyuan Liu7145eb22016-12-01 10:59:29 -0800398uint8_t *pld_get_wlan_mac_address(struct device *dev, uint32_t *num);
Hardik Kantilal Patel9689e932016-10-18 19:02:39 +0530399int pld_is_qmi_disable(struct device *dev);
400
Yuanyuan Liud9f7a362016-01-22 14:27:12 -0800401#endif