Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1 | /* |
Houston Hoffman | ebc6814 | 2016-01-18 15:38:27 -0800 | [diff] [blame] | 2 | * Copyright (c) 2013-2016 The Linux Foundation. All rights reserved. |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 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 _HIF_H_ |
| 29 | #define _HIF_H_ |
| 30 | |
| 31 | #ifdef __cplusplus |
| 32 | extern "C" { |
| 33 | #endif /* __cplusplus */ |
| 34 | |
| 35 | /* Header files */ |
| 36 | #include "athdefs.h" |
| 37 | #include "a_types.h" |
| 38 | #include "osapi_linux.h" |
| 39 | #include "cdf_status.h" |
| 40 | #include "cdf_nbuf.h" |
| 41 | #include "ol_if_athvar.h" |
| 42 | #include <linux/platform_device.h> |
| 43 | #ifdef HIF_PCI |
| 44 | #include <linux/pci.h> |
| 45 | #endif /* HIF_PCI */ |
| 46 | |
| 47 | #define ENABLE_MBOX_DUMMY_SPACE_FEATURE 1 |
| 48 | |
| 49 | typedef struct htc_callbacks HTC_CALLBACKS; |
| 50 | typedef void __iomem *A_target_id_t; |
| 51 | |
| 52 | #define HIF_TYPE_AR6002 2 |
| 53 | #define HIF_TYPE_AR6003 3 |
| 54 | #define HIF_TYPE_AR6004 5 |
| 55 | #define HIF_TYPE_AR9888 6 |
| 56 | #define HIF_TYPE_AR6320 7 |
| 57 | #define HIF_TYPE_AR6320V2 8 |
| 58 | /* For attaching Peregrine 2.0 board host_reg_tbl only */ |
| 59 | #define HIF_TYPE_AR9888V2 8 |
| 60 | #define HIF_TYPE_QCA6180 9 |
| 61 | #define HIF_TYPE_ADRASTEA 10 |
| 62 | |
| 63 | #define TARGET_TYPE_UNKNOWN 0 |
| 64 | #define TARGET_TYPE_AR6001 1 |
| 65 | #define TARGET_TYPE_AR6002 2 |
| 66 | #define TARGET_TYPE_AR6003 3 |
| 67 | #define TARGET_TYPE_AR6004 5 |
| 68 | #define TARGET_TYPE_AR6006 6 |
| 69 | #define TARGET_TYPE_AR9888 7 |
| 70 | #define TARGET_TYPE_AR6320 8 |
| 71 | #define TARGET_TYPE_AR900B 9 |
| 72 | /* For attach Peregrine 2.0 board target_reg_tbl only */ |
| 73 | #define TARGET_TYPE_AR9888V2 10 |
| 74 | /* For attach Rome1.0 target_reg_tbl only*/ |
| 75 | #define TARGET_TYPE_AR6320V1 11 |
| 76 | /* For Rome2.0/2.1 target_reg_tbl ID*/ |
| 77 | #define TARGET_TYPE_AR6320V2 12 |
| 78 | /* For Rome3.0 target_reg_tbl ID*/ |
| 79 | #define TARGET_TYPE_AR6320V3 13 |
| 80 | /* For Tufello1.0 target_reg_tbl ID*/ |
| 81 | #define TARGET_TYPE_QCA9377V1 14 |
| 82 | /* For QCA6180 target */ |
| 83 | #define TARGET_TYPE_QCA6180 15 |
| 84 | /* For Adrastea target */ |
| 85 | #define TARGET_TYPE_ADRASTEA 16 |
| 86 | |
| 87 | struct CE_state; |
Sanjay Devnani | 9ce1577 | 2015-11-12 14:08:57 -0800 | [diff] [blame] | 88 | #ifdef QCA_WIFI_3_0_ADRASTEA |
| 89 | #define CE_COUNT_MAX 12 |
| 90 | #else |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 91 | #define CE_COUNT_MAX 8 |
Sanjay Devnani | 9ce1577 | 2015-11-12 14:08:57 -0800 | [diff] [blame] | 92 | #endif |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 93 | |
| 94 | /* These numbers are selected so that the product is close to current |
| 95 | higher limit of packets HIF services at one shot (1000) */ |
| 96 | #define QCA_NAPI_BUDGET 64 |
| 97 | #define QCA_NAPI_DEF_SCALE 16 |
| 98 | /* NOTE: This is to adapt non-NAPI solution to use |
| 99 | the same "budget" as NAPI. Will be removed |
| 100 | `once decision about NAPI is made */ |
| 101 | #define HIF_NAPI_MAX_RECEIVES (QCA_NAPI_BUDGET * QCA_NAPI_DEF_SCALE) |
| 102 | |
| 103 | /* NOTE: "napi->scale" can be changed, |
| 104 | but this does not change the number of buckets */ |
| 105 | #define QCA_NAPI_NUM_BUCKETS (QCA_NAPI_BUDGET / QCA_NAPI_DEF_SCALE) |
| 106 | struct qca_napi_stat { |
| 107 | uint32_t napi_schedules; |
| 108 | uint32_t napi_polls; |
| 109 | uint32_t napi_completes; |
| 110 | uint32_t napi_workdone; |
| 111 | uint32_t napi_budget_uses[QCA_NAPI_NUM_BUCKETS]; |
| 112 | }; |
| 113 | |
| 114 | /** |
| 115 | * per NAPI instance data structure |
| 116 | * This data structure holds stuff per NAPI instance. |
| 117 | * Note that, in the current implementation, though scale is |
| 118 | * an instance variable, it is set to the same value for all |
| 119 | * instances. |
| 120 | */ |
| 121 | struct qca_napi_info { |
| 122 | struct napi_struct napi; /* one NAPI Instance per CE in phase I */ |
| 123 | uint8_t scale; /* currently same on all instances */ |
| 124 | uint8_t id; |
| 125 | struct qca_napi_stat stats[NR_CPUS]; |
| 126 | }; |
| 127 | |
| 128 | /** |
| 129 | * NAPI data-sructure common to all NAPI instances. |
| 130 | * |
| 131 | * A variable of this type will be stored in hif module context. |
| 132 | */ |
| 133 | |
| 134 | struct qca_napi_data { |
| 135 | /* NOTE: make sure the mutex is inited only at the very beginning |
| 136 | once for the lifetime of the driver. For now, granularity of one |
| 137 | is OK, but we might want to have a better granularity later */ |
| 138 | struct mutex mutex; |
| 139 | uint32_t state; |
| 140 | uint32_t ce_map; /* bitmap of created/registered NAPI |
| 141 | instances, indexed by pipe_id, |
| 142 | not used by clients (clients use an |
| 143 | id returned by create) */ |
| 144 | struct net_device netdev; /* dummy net_dev */ |
| 145 | struct qca_napi_info napis[CE_COUNT_MAX]; |
| 146 | }; |
| 147 | |
Komal Seelam | 91553ce | 2016-01-27 18:57:10 +0530 | [diff] [blame] | 148 | /** |
| 149 | * struct hif_config_info - Place Holder for hif configuration |
| 150 | * @enable_uart_print: UART Print |
| 151 | * @enable_self_recovery: Self Recovery |
| 152 | * @enable_fw_log: To Enable FW LOG |
| 153 | * @enable_lpass_support: LPASS support |
| 154 | * @enable_ramdump_collection: Ramdump Collection |
| 155 | * @max_no_of_peers: Max Number of Peers |
| 156 | * |
| 157 | * Structure for holding ini parameters. |
| 158 | */ |
| 159 | struct hif_config_info { |
| 160 | bool enable_uart_print; |
| 161 | bool enable_self_recovery; |
| 162 | bool enable_fw_log; |
| 163 | bool enable_lpass_support; |
| 164 | bool enable_ramdump_collection; |
| 165 | uint8_t max_no_of_peers; |
| 166 | }; |
| 167 | |
| 168 | /** |
| 169 | * struct hif_target_info - Target Information |
| 170 | * @target_version: Target Version |
| 171 | * @target_type: Target Type |
| 172 | * @target_revision: Target Revision |
| 173 | * @soc_version: SOC Version |
| 174 | * |
| 175 | * Structure to hold target information. |
| 176 | */ |
| 177 | struct hif_target_info { |
| 178 | uint32_t target_version; |
| 179 | uint32_t target_type; |
| 180 | uint32_t target_revision; |
| 181 | uint32_t soc_version; |
| 182 | }; |
| 183 | |
Komal Seelam | b3a3bdf | 2016-02-01 19:22:17 +0530 | [diff] [blame] | 184 | struct bmi_info { |
| 185 | uint8_t *bmi_cmd_buff; |
| 186 | uint8_t *bmi_rsp_buff; |
| 187 | dma_addr_t bmi_cmd_da; |
| 188 | dma_addr_t bmi_rsp_da; |
| 189 | uint8_t *cal_in_flash; |
| 190 | bool bmi_done; |
| 191 | #ifdef CONFIG_CNSS |
| 192 | struct cnss_fw_files fw_files; |
| 193 | #endif |
| 194 | }; |
| 195 | |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 196 | struct ol_softc { |
| 197 | void __iomem *mem; /* IO mapped memory base address */ |
| 198 | cdf_dma_addr_t mem_pa; |
Komal Seelam | 91553ce | 2016-01-27 18:57:10 +0530 | [diff] [blame] | 199 | struct hif_config_info hif_config; |
| 200 | struct hif_target_info target_info; |
Komal Seelam | b3a3bdf | 2016-02-01 19:22:17 +0530 | [diff] [blame] | 201 | struct bmi_info bmi_ctx; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 202 | /* |
| 203 | * handle for code that uses the osdep.h version of OS |
| 204 | * abstraction primitives |
| 205 | */ |
| 206 | struct _NIC_DEV aps_osdev; |
| 207 | enum ath_hal_bus_type bus_type; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 208 | bool request_irq_done; |
| 209 | /* |
| 210 | * handle for code that uses cdf version of OS |
| 211 | * abstraction primitives |
| 212 | */ |
| 213 | cdf_device_t cdf_dev; |
| 214 | |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 215 | /* Packet statistics */ |
| 216 | struct ol_ath_stats pkt_stats; |
| 217 | |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 218 | ol_target_status target_status; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 219 | /* calibration data is stored in flash */ |
| 220 | uint8_t *cal_in_flash; |
| 221 | /* virtual address for the calibration data on the flash */ |
| 222 | void *cal_mem; |
| 223 | /* status of target init */ |
| 224 | WLAN_INIT_STATUS wlan_init_status; |
| 225 | |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 226 | /* Handles for Lower Layers : filled in at init time */ |
| 227 | hif_handle_t hif_hdl; |
| 228 | #ifdef HIF_PCI |
| 229 | struct hif_pci_softc *hif_sc; |
| 230 | #endif |
| 231 | |
| 232 | #ifdef WLAN_FEATURE_FASTPATH |
| 233 | int fastpath_mode_on; /* Duplicating this for data path efficiency */ |
| 234 | #endif /* WLAN_FEATURE_FASTPATH */ |
| 235 | |
| 236 | /* HTC handles */ |
| 237 | void *htc_handle; |
| 238 | |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 239 | uint8_t vow_extstats; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 240 | struct targetdef_s *targetdef; |
| 241 | struct ce_reg_def *target_ce_def; |
| 242 | struct hostdef_s *hostdef; |
| 243 | struct host_shadow_regs_s *host_shadow_regs; |
| 244 | bool athdiag_procfs_inited; |
| 245 | /* |
| 246 | * Guard changes to Target HW state and to software |
| 247 | * structures that track hardware state. |
| 248 | */ |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 249 | unsigned int ce_count; /* Number of Copy Engines supported */ |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 250 | struct CE_state *ce_id_to_state[CE_COUNT_MAX]; /* CE id to CE_state */ |
| 251 | #ifdef FEATURE_NAPI |
| 252 | struct qca_napi_data napi_data; |
| 253 | #endif /* FEATURE_NAPI */ |
| 254 | int htc_endpoint; |
| 255 | bool recovery; |
| 256 | bool hif_init_done; |
| 257 | int linkstate_vote; |
| 258 | atomic_t link_suspended; |
| 259 | atomic_t wow_done; |
| 260 | atomic_t tasklet_from_intr; |
| 261 | atomic_t active_tasklet_cnt; |
| 262 | bool notice_send; |
| 263 | #ifdef HIF_PCI |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 264 | uint32_t ce_irq_summary; |
| 265 | #endif |
Sanjay Devnani | b925d7e | 2015-11-12 14:43:58 -0800 | [diff] [blame] | 266 | uint32_t *vaddr_rri_on_ddr; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 267 | }; |
| 268 | |
| 269 | typedef enum { |
| 270 | HIF_DEVICE_POWER_UP, /* HIF layer should power up interface |
| 271 | * and/or module */ |
| 272 | HIF_DEVICE_POWER_DOWN, /* HIF layer should initiate bus-specific |
| 273 | * measures to minimize power */ |
| 274 | HIF_DEVICE_POWER_CUT /* HIF layer should initiate bus-specific |
| 275 | * AND/OR platform-specific measures |
| 276 | * to completely power-off the module and |
| 277 | * associated hardware (i.e. cut power |
| 278 | * supplies) */ |
| 279 | } HIF_DEVICE_POWER_CHANGE_TYPE; |
| 280 | |
| 281 | /** |
| 282 | * enum hif_enable_type: what triggered the enabling of hif |
| 283 | * |
| 284 | * @HIF_ENABLE_TYPE_PROBE: probe triggered enable |
| 285 | * @HIF_ENABLE_TYPE_REINIT: reinit triggered enable |
| 286 | */ |
| 287 | enum hif_enable_type { |
| 288 | HIF_ENABLE_TYPE_PROBE, |
| 289 | HIF_ENABLE_TYPE_REINIT, |
| 290 | HIF_ENABLE_TYPE_MAX |
| 291 | }; |
| 292 | |
| 293 | /** |
| 294 | * enum hif_disable_type: what triggered the disabling of hif |
| 295 | * |
| 296 | * @HIF_DISABLE_TYPE_PROBE_ERROR: probe error triggered disable |
| 297 | * @HIF_DISABLE_TYPE_REINIT_ERROR: reinit error triggered |
| 298 | * disable |
| 299 | * @HIF_DISABLE_TYPE_REMOVE: remove triggered disable |
| 300 | * @HIF_DISABLE_TYPE_SHUTDOWN: shutdown triggered disable |
| 301 | */ |
| 302 | enum hif_disable_type { |
| 303 | HIF_DISABLE_TYPE_PROBE_ERROR, |
| 304 | HIF_DISABLE_TYPE_REINIT_ERROR, |
| 305 | HIF_DISABLE_TYPE_REMOVE, |
| 306 | HIF_DISABLE_TYPE_SHUTDOWN, |
| 307 | HIF_DISABLE_TYPE_MAX |
| 308 | }; |
| 309 | |
| 310 | #ifdef CONFIG_ATH_PCIE_ACCESS_DEBUG |
| 311 | typedef struct _HID_ACCESS_LOG { |
| 312 | uint32_t seqnum; |
| 313 | bool is_write; |
| 314 | void *addr; |
| 315 | uint32_t value; |
| 316 | } HIF_ACCESS_LOG; |
| 317 | #endif |
| 318 | |
| 319 | #define HIF_MAX_DEVICES 1 |
| 320 | |
| 321 | struct htc_callbacks { |
| 322 | void *context; /* context to pass to the dsrhandler |
| 323 | * note : rwCompletionHandler is provided |
| 324 | * the context passed to hif_read_write */ |
| 325 | int (*rwCompletionHandler)(void *rwContext, int status); |
| 326 | int (*dsrHandler)(void *context); |
| 327 | }; |
| 328 | |
| 329 | typedef struct osdrv_callbacks { |
| 330 | void *context; /* context to pass for all callbacks |
| 331 | * except deviceRemovedHandler |
| 332 | * the deviceRemovedHandler is only |
| 333 | * called if the device is claimed */ |
| 334 | int (*deviceInsertedHandler)(void *context, void *hif_handle); |
| 335 | int (*deviceRemovedHandler)(void *claimedContext, |
| 336 | void *hif_handle); |
| 337 | int (*deviceSuspendHandler)(void *context); |
| 338 | int (*deviceResumeHandler)(void *context); |
| 339 | int (*deviceWakeupHandler)(void *context); |
| 340 | int (*devicePowerChangeHandler)(void *context, |
| 341 | HIF_DEVICE_POWER_CHANGE_TYPE |
| 342 | config); |
| 343 | } OSDRV_CALLBACKS; |
| 344 | |
| 345 | /* |
| 346 | * This API is used to perform any global initialization of the HIF layer |
| 347 | * and to set OS driver callbacks (i.e. insertion/removal) to the HIF layer |
| 348 | * |
| 349 | */ |
| 350 | int hif_init(OSDRV_CALLBACKS *callbacks); |
| 351 | |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 352 | /* This API detaches the HTC layer from the HIF device */ |
| 353 | void hif_detach_htc(struct ol_softc *scn); |
| 354 | |
| 355 | /****************************************************************/ |
| 356 | /* BMI and Diag window abstraction */ |
| 357 | /****************************************************************/ |
| 358 | |
| 359 | #define HIF_BMI_EXCHANGE_NO_TIMEOUT ((uint32_t)(0)) |
| 360 | |
| 361 | #define DIAG_TRANSFER_LIMIT 2048U /* maximum number of bytes that can be |
| 362 | * handled atomically by |
| 363 | * DiagRead/DiagWrite */ |
| 364 | |
| 365 | /* |
| 366 | * API to handle HIF-specific BMI message exchanges, this API is synchronous |
| 367 | * and only allowed to be called from a context that can block (sleep) */ |
| 368 | CDF_STATUS hif_exchange_bmi_msg(struct ol_softc *scn, |
| 369 | uint8_t *pSendMessage, |
| 370 | uint32_t Length, |
| 371 | uint8_t *pResponseMessage, |
| 372 | uint32_t *pResponseLength, uint32_t TimeoutMS); |
| 373 | |
| 374 | /* |
| 375 | * APIs to handle HIF specific diagnostic read accesses. These APIs are |
| 376 | * synchronous and only allowed to be called from a context that |
| 377 | * can block (sleep). They are not high performance APIs. |
| 378 | * |
| 379 | * hif_diag_read_access reads a 4 Byte aligned/length value from a |
| 380 | * Target register or memory word. |
| 381 | * |
| 382 | * hif_diag_read_mem reads an arbitrary length of arbitrarily aligned memory. |
| 383 | */ |
| 384 | CDF_STATUS hif_diag_read_access(struct ol_softc *scn, uint32_t address, |
| 385 | uint32_t *data); |
| 386 | CDF_STATUS hif_diag_read_mem(struct ol_softc *scn, uint32_t address, |
| 387 | uint8_t *data, int nbytes); |
| 388 | void hif_dump_target_memory(struct ol_softc *scn, void *ramdump_base, |
| 389 | uint32_t address, uint32_t size); |
| 390 | /* |
| 391 | * APIs to handle HIF specific diagnostic write accesses. These APIs are |
| 392 | * synchronous and only allowed to be called from a context that |
| 393 | * can block (sleep). |
| 394 | * They are not high performance APIs. |
| 395 | * |
| 396 | * hif_diag_write_access writes a 4 Byte aligned/length value to a |
| 397 | * Target register or memory word. |
| 398 | * |
| 399 | * hif_diag_write_mem writes an arbitrary length of arbitrarily aligned memory. |
| 400 | */ |
| 401 | CDF_STATUS hif_diag_write_access(struct ol_softc *scn, uint32_t address, |
| 402 | uint32_t data); |
| 403 | CDF_STATUS hif_diag_write_mem(struct ol_softc *scn, uint32_t address, |
| 404 | uint8_t *data, int nbytes); |
| 405 | |
| 406 | /* |
| 407 | * Set the FASTPATH_mode_on flag in sc, for use by data path |
| 408 | */ |
| 409 | #ifdef WLAN_FEATURE_FASTPATH |
| 410 | void hif_enable_fastpath(struct ol_softc *hif_dev); |
| 411 | #endif |
| 412 | |
| 413 | #if defined(HIF_PCI) && !defined(A_SIMOS_DEVHOST) |
| 414 | /* |
| 415 | * This API allows the Host to access Target registers of a given |
| 416 | * A_target_id_t directly and relatively efficiently over PCIe. |
| 417 | * This allows the Host to avoid extra overhead associated with |
| 418 | * sending a message to firmware and waiting for a response message |
| 419 | * from firmware, as is done on other interconnects. |
| 420 | * |
| 421 | * Yet there is some complexity with direct accesses because the |
| 422 | * Target's power state is not known a priori. The Host must issue |
| 423 | * special PCIe reads/writes in order to explicitly wake the Target |
| 424 | * and to verify that it is awake and will remain awake. |
| 425 | * |
| 426 | * NB: Host endianness conversion is left for the caller to handle. |
| 427 | * These interfaces handle access; not interpretation. |
| 428 | * |
| 429 | * Usage: |
| 430 | * During initialization, use A_TARGET_ID to obtain an 'target ID' |
| 431 | * for use with these interfaces. |
| 432 | * |
| 433 | * Use A_TARGET_READ and A_TARGET_WRITE to access Target space. |
| 434 | * These calls must be bracketed by A_TARGET_ACCESS_BEGIN and |
| 435 | * A_TARGET_ACCESS_END. A single BEGIN/END pair is adequate for |
| 436 | * multiple READ/WRITE operations. |
| 437 | * |
| 438 | * Use A_TARGET_ACCESS_BEGIN to put the Target in a state in |
| 439 | * which it is legal for the Host to directly access it. This |
| 440 | * may involve waking the Target from a low power state, which |
| 441 | * may take up to 2Ms! |
| 442 | * |
| 443 | * Use A_TARGET_ACCESS_END to tell the Target that as far as |
| 444 | * this code path is concerned, it no longer needs to remain |
| 445 | * directly accessible. BEGIN/END is under a reference counter; |
| 446 | * multiple code paths may issue BEGIN/END on a single targid. |
| 447 | * |
| 448 | * For added efficiency, the Host may use A_TARGET_ACCESS_LIKELY. |
| 449 | * The LIKELY interface works just like A_TARGET_ACCESS_BEGIN, |
| 450 | * except that it may return before the Target is actually |
| 451 | * available. It's a vague indication that some Target accesses |
| 452 | * are expected "soon". When the LIKELY API is used, |
| 453 | * A_TARGET_ACCESS_BEGIN must be used before any access. |
| 454 | * |
| 455 | * There are several uses for the LIKELY/UNLIKELY API: |
| 456 | * -If there is some potential time before Target accesses |
| 457 | * and we want to get a head start on waking the Target |
| 458 | * (e.g. to overlap Target wake with Host-side malloc) |
| 459 | * -High-level code knows that it will call low-level |
| 460 | * functions that will use BEGIN/END, and we don't want |
| 461 | * to allow the Target to sleep until the entire sequence |
| 462 | * has completed. |
| 463 | * |
| 464 | * A_TARGET_ACCESS_OK verifies that the Target can be |
| 465 | * accessed. In general, this should not be needed, but it |
| 466 | * may be useful for debugging or for special uses. |
| 467 | * |
| 468 | * Note that there must be a matching END for each BEGIN |
| 469 | * AND there must be a matching UNLIKELY for each LIKELY! |
| 470 | * |
| 471 | * NB: This API is designed to allow some flexibility in tradeoffs |
| 472 | * between Target power utilization and Host efficiency and |
| 473 | * system performance. |
| 474 | */ |
| 475 | |
| 476 | /* |
| 477 | * Enable/disable CDC max performance workaround |
| 478 | * For max-performace set this to 0 |
| 479 | * To allow SoC to enter sleep set this to 1 |
| 480 | */ |
| 481 | #define CONFIG_DISABLE_CDC_MAX_PERF_WAR 0 |
| 482 | #endif |
| 483 | |
| 484 | #ifdef IPA_OFFLOAD |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 485 | void hif_ipa_get_ce_resource(struct ol_softc *scn, |
Leo Chang | d85f78d | 2015-11-13 10:55:34 -0800 | [diff] [blame] | 486 | cdf_dma_addr_t *ce_sr_base_paddr, |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 487 | uint32_t *ce_sr_ring_size, |
| 488 | cdf_dma_addr_t *ce_reg_paddr); |
| 489 | #else |
Leo Chang | d85f78d | 2015-11-13 10:55:34 -0800 | [diff] [blame] | 490 | /** |
| 491 | * hif_ipa_get_ce_resource() - get uc resource on hif |
| 492 | * @scn: bus context |
| 493 | * @ce_sr_base_paddr: copyengine source ring base physical address |
| 494 | * @ce_sr_ring_size: copyengine source ring size |
| 495 | * @ce_reg_paddr: copyengine register physical address |
| 496 | * |
| 497 | * IPA micro controller data path offload feature enabled, |
| 498 | * HIF should release copy engine related resource information to IPA UC |
| 499 | * IPA UC will access hardware resource with released information |
| 500 | * |
| 501 | * Return: None |
| 502 | */ |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 503 | static inline void hif_ipa_get_ce_resource(struct ol_softc *scn, |
Leo Chang | d85f78d | 2015-11-13 10:55:34 -0800 | [diff] [blame] | 504 | cdf_dma_addr_t *ce_sr_base_paddr, |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 505 | uint32_t *ce_sr_ring_size, |
| 506 | cdf_dma_addr_t *ce_reg_paddr) |
| 507 | { |
| 508 | return; |
| 509 | } |
| 510 | #endif /* IPA_OFFLOAD */ |
| 511 | |
| 512 | |
| 513 | void hif_read_phy_mem_base(struct ol_softc *scn, |
| 514 | cdf_dma_addr_t *bar_value); |
| 515 | |
| 516 | /** |
| 517 | * @brief List of callbacks - filled in by HTC. |
| 518 | */ |
| 519 | struct hif_msg_callbacks { |
| 520 | void *Context; |
| 521 | /**< context meaningful to HTC */ |
| 522 | CDF_STATUS (*txCompletionHandler)(void *Context, cdf_nbuf_t wbuf, |
| 523 | uint32_t transferID, |
| 524 | uint32_t toeplitz_hash_result); |
| 525 | CDF_STATUS (*rxCompletionHandler)(void *Context, cdf_nbuf_t wbuf, |
| 526 | uint8_t pipeID); |
| 527 | void (*txResourceAvailHandler)(void *context, uint8_t pipe); |
| 528 | void (*fwEventHandler)(void *context, CDF_STATUS status); |
| 529 | }; |
| 530 | |
| 531 | #define HIF_DATA_ATTR_SET_TX_CLASSIFY(attr, v) \ |
| 532 | (attr |= (v & 0x01) << 5) |
| 533 | #define HIF_DATA_ATTR_SET_ENCAPSULATION_TYPE(attr, v) \ |
| 534 | (attr |= (v & 0x03) << 6) |
| 535 | #define HIF_DATA_ATTR_SET_ADDR_X_SEARCH_DISABLE(attr, v) \ |
| 536 | (attr |= (v & 0x01) << 13) |
| 537 | #define HIF_DATA_ATTR_SET_ADDR_Y_SEARCH_DISABLE(attr, v) \ |
| 538 | (attr |= (v & 0x01) << 14) |
| 539 | #define HIF_DATA_ATTR_SET_TOEPLITZ_HASH_ENABLE(attr, v) \ |
| 540 | (attr |= (v & 0x01) << 15) |
| 541 | #define HIF_DATA_ATTR_SET_PACKET_OR_RESULT_OFFSET(attr, v) \ |
| 542 | (attr |= (v & 0x0FFF) << 16) |
| 543 | #define HIF_DATA_ATTR_SET_ENABLE_11H(attr, v) \ |
| 544 | (attr |= (v & 0x01) << 30) |
| 545 | |
| 546 | #ifdef HIF_PCI |
| 547 | typedef struct pci_device_id hif_bus_id; |
| 548 | #else |
| 549 | typedef struct device hif_bus_id; |
| 550 | #endif |
| 551 | |
| 552 | void hif_post_init(struct ol_softc *scn, void *hHTC, |
| 553 | struct hif_msg_callbacks *callbacks); |
| 554 | CDF_STATUS hif_start(struct ol_softc *scn); |
| 555 | void hif_stop(struct ol_softc *scn); |
| 556 | void hif_flush_surprise_remove(struct ol_softc *scn); |
| 557 | void hif_dump(struct ol_softc *scn, uint8_t CmdId, bool start); |
| 558 | CDF_STATUS hif_send_head(struct ol_softc *scn, uint8_t PipeID, |
| 559 | uint32_t transferID, uint32_t nbytes, |
| 560 | cdf_nbuf_t wbuf, uint32_t data_attr); |
| 561 | void hif_send_complete_check(struct ol_softc *scn, uint8_t PipeID, |
| 562 | int force); |
| 563 | void hif_cancel_deferred_target_sleep(struct ol_softc *scn); |
| 564 | void hif_get_default_pipe(struct ol_softc *scn, uint8_t *ULPipe, |
| 565 | uint8_t *DLPipe); |
Sanjay Devnani | c319c82 | 2015-11-06 16:44:28 -0800 | [diff] [blame] | 566 | int hif_map_service_to_pipe(struct ol_softc *scn, uint16_t svc_id, |
| 567 | uint8_t *ul_pipe, uint8_t *dl_pipe, int *ul_is_polled, |
| 568 | int *dl_is_polled); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 569 | uint16_t hif_get_free_queue_number(struct ol_softc *scn, uint8_t PipeID); |
| 570 | void *hif_get_targetdef(struct ol_softc *scn); |
| 571 | void hi_fsuspendwow(struct ol_softc *scn); |
| 572 | uint32_t hif_hia_item_address(uint32_t target_type, uint32_t item_offset); |
| 573 | void hif_set_target_sleep(struct ol_softc *scn, bool sleep_ok, |
| 574 | bool wait_for_it); |
| 575 | int hif_check_fw_reg(struct ol_softc *scn); |
| 576 | int hif_check_soc_status(struct ol_softc *scn); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 577 | void hif_disable_isr(void *scn); |
| 578 | void hif_reset_soc(void *scn); |
Komal Seelam | f860068 | 2016-02-02 18:17:13 +0530 | [diff] [blame^] | 579 | void hif_disable_aspm(void *); |
| 580 | void hif_save_htc_htt_config_endpoint(void *hif_ctx, int htc_endpoint); |
| 581 | CDF_STATUS hif_open(cdf_device_t cdf_ctx, enum ath_hal_bus_type bus_type); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 582 | void hif_close(void *hif_ctx); |
| 583 | CDF_STATUS hif_enable(void *hif_ctx, struct device *dev, void *bdev, |
| 584 | const hif_bus_id *bid, enum ath_hal_bus_type bus_type, |
| 585 | enum hif_enable_type type); |
| 586 | void hif_disable(void *hif_ctx, enum hif_disable_type type); |
| 587 | void hif_enable_power_gating(void *hif_ctx); |
Houston Hoffman | 9078a15 | 2015-11-02 16:15:02 -0800 | [diff] [blame] | 588 | |
| 589 | #ifdef FEATURE_RUNTIME_PM |
| 590 | struct hif_pm_runtime_lock; |
| 591 | int hif_pm_runtime_get(void *hif_ctx); |
Houston Hoffman | f460785 | 2015-12-17 17:14:40 -0800 | [diff] [blame] | 592 | void hif_pm_runtime_get_noresume(void *hif_ctx); |
Houston Hoffman | 9078a15 | 2015-11-02 16:15:02 -0800 | [diff] [blame] | 593 | int hif_pm_runtime_put(void *hif_ctx); |
| 594 | struct hif_pm_runtime_lock *hif_runtime_lock_init(const char *name); |
Komal Seelam | f860068 | 2016-02-02 18:17:13 +0530 | [diff] [blame^] | 595 | void hif_runtime_lock_deinit(void *hif_ctx, struct hif_pm_runtime_lock *lock); |
Houston Hoffman | 9078a15 | 2015-11-02 16:15:02 -0800 | [diff] [blame] | 596 | int hif_pm_runtime_prevent_suspend(void *ol_sc, |
| 597 | struct hif_pm_runtime_lock *lock); |
| 598 | int hif_pm_runtime_allow_suspend(void *ol_sc, |
| 599 | struct hif_pm_runtime_lock *lock); |
| 600 | int hif_pm_runtime_prevent_suspend_timeout(void *ol_sc, |
| 601 | struct hif_pm_runtime_lock *lock, unsigned int delay); |
| 602 | #else |
| 603 | struct hif_pm_runtime_lock { |
| 604 | const char *name; |
| 605 | }; |
Houston Hoffman | f460785 | 2015-12-17 17:14:40 -0800 | [diff] [blame] | 606 | |
| 607 | static inline void hif_pm_runtime_get_noresume(void *hif_ctx) |
| 608 | {} |
| 609 | |
Houston Hoffman | 9078a15 | 2015-11-02 16:15:02 -0800 | [diff] [blame] | 610 | static inline int hif_pm_runtime_get(void *hif_ctx) |
| 611 | { return 0; } |
| 612 | static inline int hif_pm_runtime_put(void *hif_ctx) |
| 613 | { return 0; } |
| 614 | static inline struct hif_pm_runtime_lock *hif_runtime_lock_init( |
| 615 | const char *name) |
| 616 | { return NULL; } |
Komal Seelam | f860068 | 2016-02-02 18:17:13 +0530 | [diff] [blame^] | 617 | static inline void |
| 618 | hif_runtime_lock_deinit(void *hif_ctx, struct hif_pm_runtime_lock *lock) {} |
Houston Hoffman | 9078a15 | 2015-11-02 16:15:02 -0800 | [diff] [blame] | 619 | |
| 620 | static inline int hif_pm_runtime_prevent_suspend(void *ol_sc, |
| 621 | struct hif_pm_runtime_lock *lock) |
| 622 | { return 0; } |
| 623 | static inline int hif_pm_runtime_allow_suspend(void *ol_sc, |
| 624 | struct hif_pm_runtime_lock *lock) |
| 625 | { return 0; } |
| 626 | static inline int hif_pm_runtime_prevent_suspend_timeout(void *ol_sc, |
| 627 | struct hif_pm_runtime_lock *lock, unsigned int delay) |
| 628 | { return 0; } |
| 629 | #endif |
| 630 | |
Houston Hoffman | 62aa58d | 2015-11-02 21:14:55 -0800 | [diff] [blame] | 631 | void hif_enable_power_management(void *hif_ctx); |
Houston Hoffman | 53b34c4 | 2015-11-18 15:51:32 -0800 | [diff] [blame] | 632 | void hif_disable_power_management(void *hif_ctx); |
Houston Hoffman | 78467a8 | 2016-01-05 20:08:56 -0800 | [diff] [blame] | 633 | |
Komal Seelam | f860068 | 2016-02-02 18:17:13 +0530 | [diff] [blame^] | 634 | void hif_vote_link_down(void *); |
| 635 | void hif_vote_link_up(void *); |
| 636 | bool hif_can_suspend_link(void *); |
Houston Hoffman | 78467a8 | 2016-01-05 20:08:56 -0800 | [diff] [blame] | 637 | |
Komal Seelam | f860068 | 2016-02-02 18:17:13 +0530 | [diff] [blame^] | 638 | int hif_bus_resume(void *); |
| 639 | int hif_bus_suspend(void *); |
Houston Hoffman | 692cc05 | 2015-11-10 18:42:47 -0800 | [diff] [blame] | 640 | |
| 641 | #ifdef FEATURE_RUNTIME_PM |
Komal Seelam | f860068 | 2016-02-02 18:17:13 +0530 | [diff] [blame^] | 642 | int hif_pre_runtime_suspend(void *hif_ctx); |
| 643 | void hif_pre_runtime_resume(void *hif_ctx); |
| 644 | int hif_runtime_suspend(void *hif_ctx); |
| 645 | int hif_runtime_resume(void *hif_ctx); |
| 646 | void hif_process_runtime_suspend_success(void *); |
| 647 | void hif_process_runtime_suspend_failure(void *); |
| 648 | void hif_process_runtime_resume_success(void *); |
Houston Hoffman | 692cc05 | 2015-11-10 18:42:47 -0800 | [diff] [blame] | 649 | #endif |
| 650 | |
Govind Singh | 2443fb3 | 2016-01-13 17:44:48 +0530 | [diff] [blame] | 651 | int hif_dump_registers(struct ol_softc *scn); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 652 | int ol_copy_ramdump(struct ol_softc *scn); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 653 | void hif_crash_shutdown(void *hif_ctx); |
Komal Seelam | 91553ce | 2016-01-27 18:57:10 +0530 | [diff] [blame] | 654 | void hif_get_hw_info(struct ol_softc *scn, u32 *version, u32 *revision, |
| 655 | const char **target_name); |
| 656 | struct hif_target_info *hif_get_target_info_handle(struct ol_softc *scn); |
| 657 | struct hif_config_info *hif_get_ini_handle(struct ol_softc *scn); |
Komal Seelam | b3a3bdf | 2016-02-01 19:22:17 +0530 | [diff] [blame] | 658 | struct bmi_info *hif_get_bmi_ctx(void *hif_ctx); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 659 | #ifdef __cplusplus |
| 660 | } |
| 661 | #endif |
| 662 | #endif /* _HIF_H_ */ |