blob: 9345eaffe7e7b22afe5719beb769c3ebcd22d4ec [file] [log] [blame]
Yuanyuan Liud9f7a362016-01-22 14:27:12 -08001/*
2 * Copyright (c) 2016 The Linux Foundation. All rights reserved.
3 *
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>
34
35/**
36 * enum pld_bus_type - bus type
37 * @PLD_BUS_TYPE_NONE: invalid bus type, only return in error cases
38 * @PLD_BUS_TYPE_PCIE: PCIE bus
39 * @PLD_BUS_TYPE_SNOC: SNOC bus
40 */
41enum pld_bus_type {
42 PLD_BUS_TYPE_NONE = -1,
43 PLD_BUS_TYPE_PCIE = 0,
44 PLD_BUS_TYPE_SNOC
45};
46
47#define PLD_MAX_FIRMWARE_SIZE (1 * 1024 * 1024)
48
49/**
50 * enum pld_bus_width_type - bus bandwith
51 * @PLD_BUS_WIDTH_NONE: don't vote for bus bandwidth
52 * @PLD_BUS_WIDTH_LOW: vote for low bus bandwidth
53 * @PLD_BUS_WIDTH_MEDIUM: vote for medium bus bandwidth
54 * @PLD_BUS_WIDTH_HIGH: vote for high bus bandwidth
55 */
56enum pld_bus_width_type {
57 PLD_BUS_WIDTH_NONE,
58 PLD_BUS_WIDTH_LOW,
59 PLD_BUS_WIDTH_MEDIUM,
60 PLD_BUS_WIDTH_HIGH
61};
62
63#define PLD_MAX_FILE_NAME 20
64
65/**
66 * struct pld_fw_file - WLAN FW file names
67 * @image_file: WLAN FW image file
68 * @board_data: WLAN FW board data file
69 * @otp_data: WLAN FW OTP file
70 * @utf_file: WLAN FW UTF file
71 * @utf_board_data: WLAN FW UTF board data file
72 * @epping_file: WLAN FW EPPING mode file
73 * @evicted_data: WLAN FW evicted file
74 *
75 * pld_fw_files is used to store WLAN FW file names
76 */
77struct pld_fw_files {
78 char image_file[PLD_MAX_FILE_NAME];
79 char board_data[PLD_MAX_FILE_NAME];
80 char otp_data[PLD_MAX_FILE_NAME];
81 char utf_file[PLD_MAX_FILE_NAME];
82 char utf_board_data[PLD_MAX_FILE_NAME];
83 char epping_file[PLD_MAX_FILE_NAME];
84 char evicted_data[PLD_MAX_FILE_NAME];
85};
86
87/**
88 * struct pld_image_desc_info - FW image description
89 * @fw_addr: FW image address
90 * @fw_size: FW image size
91 * @bdata_addr: FW board data address
92 * @bdata_size: FW board data size
93 *
94 * pld_image_desc_info is used to store FW image description
95 * information.
96 */
97struct pld_image_desc_info {
98 dma_addr_t fw_addr;
99 u32 fw_size;
100 dma_addr_t bdata_addr;
101 u32 bdata_size;
102};
103
104#define PLD_CODESWAP_MAX_CODESEGS 16
105
106/**
107 * struct pld_codeswap_codeseg_info - code swap segment information
108 * @codeseg_total_bytes: total bytes of segments
109 * @num_codesegs: number of code segments
110 * @codeseg_size: code segment size
111 * @codeseg_size_log2: log2 of code segment size
112 * @codeseg_busaddr: array of addresses of each code segment
113 *
114 * pld_codeswap_codeseg_info is used to store code swap segment
115 * information.
116 */
117struct pld_codeswap_codeseg_info {
118 u32 codeseg_total_bytes;
119 u32 num_codesegs;
120 u32 codeseg_size;
121 u32 codeseg_size_log2;
122 void *codeseg_busaddr[PLD_CODESWAP_MAX_CODESEGS];
123};
124
125/**
126 * enum pld_platform_cap_flag - platform capability flag
127 * @PLD_HAS_EXTERNAL_SWREG: has external regulator
128 * @PLD_HAS_UART_ACCESS: has UART access
129 */
130enum pld_platform_cap_flag {
131 PLD_HAS_EXTERNAL_SWREG = 0x01,
132 PLD_HAS_UART_ACCESS = 0x02,
133};
134
135/**
136 * struct pld_platform_cap - platform capabilities
137 * @cap_flag: capabilities flag
138 *
139 * pld_platform_cap provides platform capabilities which are
140 * extracted from DTS.
141 */
142struct pld_platform_cap {
143 u32 cap_flag;
144};
145
146/**
147 * enum pld_driver_status - WLAN driver status
148 * @PLD_UNINITIALIZED: driver is uninitialized
149 * @PLD_INITIALIZED: driver is initialized
150 * @PLD_LOAD_UNLOADL: driver is in load-unload status
151 */
152enum pld_driver_status {
153 PLD_UNINITIALIZED,
154 PLD_INITIALIZED,
155 PLD_LOAD_UNLOAD
156};
157
158/**
159 * struct pld_ce_tgt_pipe_cfg - copy engine target pipe configuration
160 * @pipe_num: pipe number
161 * @pipe_dir: pipe direction
162 * @nentries: number of entries
163 * @nbytes_max: max number of bytes
164 * @flags: flags
165 * @reserved: reserved
166 *
167 * pld_ce_tgt_pipe_cfg is used to store copy engine target pipe
168 * configuration.
169 */
170struct pld_ce_tgt_pipe_cfg {
171 u32 pipe_num;
172 u32 pipe_dir;
173 u32 nentries;
174 u32 nbytes_max;
175 u32 flags;
176 u32 reserved;
177};
178
179/**
180 * struct pld_ce_svc_pipe_cfg - copy engine service pipe configuration
181 * @service_id: service ID
182 * @pipe_dir: pipe direction
183 * @pipe_num: pipe number
184 *
185 * pld_ce_svc_pipe_cfg is used to store copy engine service pipe
186 * configuration.
187 */
188struct pld_ce_svc_pipe_cfg {
189 u32 service_id;
190 u32 pipe_dir;
191 u32 pipe_num;
192};
193
194/**
195 * struct pld_shadow_reg_cfg - shadow register configuration
196 * @ce_id: copy engine ID
197 * @reg_offset: register offset
198 *
199 * pld_shadow_reg_cfg is used to store shadow register configuration.
200 */
201struct pld_shadow_reg_cfg {
202 u16 ce_id;
203 u16 reg_offset;
204};
205
206/**
207 * struct pld_wlan_enable_cfg - WLAN FW configuration
208 * @num_ce_tgt_cfg: number of CE target configuration
209 * @ce_tgt_cfg: CE target configuration
210 * @num_ce_svc_pipe_cfg: number of CE service configuration
211 * @ce_svc_cfg: CE service configuration
212 * @num_shadow_reg_cfg: number of shadow register configuration
213 * @shadow_reg_cfg: shadow register configuration
214 *
215 * pld_wlan_enable_cfg stores WLAN FW configurations. It will be
216 * passed to WLAN FW when WLAN host driver calls wlan_enable.
217 */
218struct pld_wlan_enable_cfg {
219 u32 num_ce_tgt_cfg;
220 struct pld_ce_tgt_pipe_cfg *ce_tgt_cfg;
221 u32 num_ce_svc_pipe_cfg;
222 struct pld_ce_svc_pipe_cfg *ce_svc_cfg;
223 u32 num_shadow_reg_cfg;
224 struct pld_shadow_reg_cfg *shadow_reg_cfg;
225};
226
227/**
228 * enum pld_driver_mode - WLAN host driver mode
229 * @PLD_MISSION: mission mode
230 * @PLD_FTM: FTM mode
231 * @PLD_EPPING: EPPING mode
232 * @PLD_WALTEST: WAL test mode, FW standalone test mode
233 * @PLD_OFF: OFF mode
234 */
235enum pld_driver_mode {
236 PLD_MISSION,
237 PLD_FTM,
238 PLD_EPPING,
239 PLD_WALTEST,
240 PLD_OFF
241};
242
243/**
244 * struct pld_soc_info - SOC information
245 * @v_addr: virtual address of preallocated memory
246 * @p_addr: physical address of preallcoated memory
247 * @version: version number
248 *
249 * pld_soc_info is used to store WLAN SOC information.
250 */
251struct pld_soc_info {
252 void __iomem *v_addr;
253 phys_addr_t p_addr;
254 u32 version;
255};
256
257/**
258 * struct pld_driver_ops - driver callback functions
259 * @probe: required operation, will be called when device is detected
260 * @remove: required operation, will be called when device is removed
261 * @shutdown: optional operation, will be called during SSR
262 * @reinit: optional operation, will be called during SSR
263 * @crash_shutdown: optional operation, will be called when a crash is
264 * detected
265 * @suspend: required operation, will be called for power management
266 * is enabled
267 * @resume: required operation, will be called for power management
268 * is enabled
269 * @modem_status: optional operation, will be called when platform driver
270 * sending modem power status to WLAN FW
271 */
272struct pld_driver_ops {
273 int (*probe)(struct device *dev,
274 enum pld_bus_type bus_type,
275 void *bdev, void *id);
276 void (*remove)(struct device *dev,
277 enum pld_bus_type bus_type);
278 void (*shutdown)(struct device *dev,
279 enum pld_bus_type bus_type);
280 int (*reinit)(struct device *dev,
281 enum pld_bus_type bus_type,
282 void *bdev, void *id);
283 void (*crash_shutdown)(struct device *dev,
284 enum pld_bus_type bus_type);
285 int (*suspend)(struct device *dev,
286 enum pld_bus_type bus_type,
287 pm_message_t state);
288 int (*resume)(struct device *dev,
289 enum pld_bus_type bus_type);
290 void (*modem_status)(struct device *dev,
291 enum pld_bus_type bus_type,
292 int state);
293};
294
295int pld_init(void);
296void pld_deinit(void);
297
298int pld_register_driver(struct pld_driver_ops *ops);
299void pld_unregister_driver(void);
300
301int pld_wlan_enable(struct device *dev, struct pld_wlan_enable_cfg *config,
302 enum pld_driver_mode mode, const char *host_version);
303int pld_wlan_disable(struct device *dev, enum pld_driver_mode mode);
304int pld_set_fw_debug_mode(struct device *dev, bool enablefwlog);
305int pld_get_fw_files_for_target(struct device *dev,
306 struct pld_fw_files *pfw_files,
307 u32 target_type, u32 target_version);
308int pld_get_fw_image(struct device *dev,
309 struct pld_image_desc_info *image_desc_info);
310void pld_is_pci_link_down(struct device *dev);
311int pld_pcie_shadow_control(struct device *dev, bool enable);
312int pld_get_codeswap_struct(struct device *dev,
313 struct pld_codeswap_codeseg_info *swap_seg);
314int pld_set_wlan_unsafe_channel(struct device *dev, u16 *unsafe_ch_list,
315 u16 ch_count);
316int pld_get_wlan_unsafe_channel(struct device *dev, u16 *unsafe_ch_list,
317 u16 *ch_count, u16 buf_len);
318int pld_wlan_set_dfs_nol(struct device *dev, void *info, u16 info_len);
319int pld_wlan_get_dfs_nol(struct device *dev, void *info, u16 info_len);
320int pld_wlan_pm_control(struct device *dev, bool vote);
321void *pld_get_virt_ramdump_mem(struct device *dev, unsigned long *size);
322void pld_device_crashed(struct device *dev);
323void pld_device_self_recovery(struct device *dev);
324void pld_intr_notify_q6(struct device *dev);
325void pld_request_pm_qos(struct device *dev, u32 qos_val);
326void pld_remove_pm_qos(struct device *dev);
327int pld_request_bus_bandwidth(struct device *dev, int bandwidth);
328int pld_get_platform_cap(struct device *dev, struct pld_platform_cap *cap);
329void pld_set_driver_status(struct device *dev, enum pld_driver_status status);
330int pld_get_bmi_setup(struct device *dev);
331int pld_get_sha_hash(struct device *dev, const u8 *data,
332 u32 data_len, u8 *hash_idx, u8 *out);
333void *pld_get_fw_ptr(struct device *dev);
334int pld_auto_suspend(struct device *dev);
335int pld_auto_resume(struct device *dev);
336
337int pld_ce_request_irq(struct device *dev, unsigned int ce_id,
338 irqreturn_t (*handler)(int, void *),
339 unsigned long flags, const char *name, void *ctx);
340int pld_ce_free_irq(struct device *dev, unsigned int ce_id, void *ctx);
341void pld_enable_irq(struct device *dev, unsigned int ce_id);
342void pld_disable_irq(struct device *dev, unsigned int ce_id);
343int pld_get_soc_info(struct device *dev, struct pld_soc_info *info);
344int pld_get_ce_id(struct device *dev, int irq);
345
346#endif