hif.h 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943
  1. /*
  2. * Copyright (c) 2013-2017 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. * This file was originally distributed by Qualcomm Atheros, Inc.
  23. * under proprietary terms before Copyright ownership was assigned
  24. * to the Linux Foundation.
  25. */
  26. #ifndef _HIF_H_
  27. #define _HIF_H_
  28. #ifdef __cplusplus
  29. extern "C" {
  30. #endif /* __cplusplus */
  31. /* Header files */
  32. #include <qdf_status.h>
  33. #include "qdf_nbuf.h"
  34. #include "qdf_lro.h"
  35. #include "ol_if_athvar.h"
  36. #include <linux/platform_device.h>
  37. #ifdef HIF_PCI
  38. #include <linux/pci.h>
  39. #endif /* HIF_PCI */
  40. #ifdef HIF_USB
  41. #include <linux/usb.h>
  42. #endif /* HIF_USB */
  43. #ifdef IPA_OFFLOAD
  44. #include <linux/ipa.h>
  45. #endif
  46. #define ENABLE_MBOX_DUMMY_SPACE_FEATURE 1
  47. typedef void __iomem *A_target_id_t;
  48. typedef void *hif_handle_t;
  49. #define HIF_DBG_PRINT_RATE 1000
  50. #define HIF_TYPE_AR6002 2
  51. #define HIF_TYPE_AR6003 3
  52. #define HIF_TYPE_AR6004 5
  53. #define HIF_TYPE_AR9888 6
  54. #define HIF_TYPE_AR6320 7
  55. #define HIF_TYPE_AR6320V2 8
  56. /* For attaching Peregrine 2.0 board host_reg_tbl only */
  57. #define HIF_TYPE_AR9888V2 9
  58. #define HIF_TYPE_ADRASTEA 10
  59. #define HIF_TYPE_AR900B 11
  60. #define HIF_TYPE_QCA9984 12
  61. #define HIF_TYPE_IPQ4019 13
  62. #define HIF_TYPE_QCA9888 14
  63. #define HIF_TYPE_QCA8074 15
  64. #define HIF_TYPE_QCA6290 16
  65. /* TARGET definition needs to be abstracted in fw common
  66. * header files, below is the placeholder till WIN codebase
  67. * moved to latest copy of fw common header files.
  68. */
  69. #ifdef CONFIG_WIN
  70. #if ENABLE_10_4_FW_HDR
  71. #define TARGET_TYPE_UNKNOWN 0
  72. #define TARGET_TYPE_AR6001 1
  73. #define TARGET_TYPE_AR6002 2
  74. #define TARGET_TYPE_AR6003 3
  75. #define TARGET_TYPE_AR6004 5
  76. #define TARGET_TYPE_AR6006 6
  77. #define TARGET_TYPE_AR9888 7
  78. #define TARGET_TYPE_AR6320 8
  79. #define TARGET_TYPE_AR900B 9
  80. #define TARGET_TYPE_QCA9984 10
  81. #define TARGET_TYPE_IPQ4019 11
  82. #define TARGET_TYPE_QCA9888 12
  83. /* For attach Peregrine 2.0 board target_reg_tbl only */
  84. #define TARGET_TYPE_AR9888V2 13
  85. /* For attach Rome1.0 target_reg_tbl only*/
  86. #define TARGET_TYPE_AR6320V1 14
  87. /* For Rome2.0/2.1 target_reg_tbl ID*/
  88. #define TARGET_TYPE_AR6320V2 15
  89. /* For Rome3.0 target_reg_tbl ID*/
  90. #define TARGET_TYPE_AR6320V3 16
  91. /* For Tufello1.0 target_reg_tbl ID*/
  92. #define TARGET_TYPE_QCA9377V1 17
  93. #endif /* ENABLE_10_4_FW_HDR */
  94. #endif /* CONFIG_WIN */
  95. /* For Adrastea target */
  96. #define TARGET_TYPE_ADRASTEA 19
  97. #ifndef TARGET_TYPE_QCA8074
  98. #define TARGET_TYPE_QCA8074 20
  99. #endif
  100. #ifndef TARGET_TYPE_QCA6290
  101. #define TARGET_TYPE_QCA6290 21
  102. #endif
  103. #ifdef IPA_OFFLOAD
  104. #define DMA_COHERENT_MASK_IPA_VER_3_AND_ABOVE 37
  105. #define DMA_COHERENT_MASK_BELOW_IPA_VER_3 32
  106. #endif
  107. /* enum hif_ic_irq - enum defining integrated chip irq numbers
  108. * defining irq nubers that can be used by external modules like datapath
  109. */
  110. enum hif_ic_irq {
  111. host2wbm_desc_feed = 18,
  112. host2reo_re_injection,
  113. host2reo_command,
  114. host2rxdma_monitor_ring3,
  115. host2rxdma_monitor_ring2,
  116. host2rxdma_monitor_ring1,
  117. reo2host_exception,
  118. wbm2host_rx_release,
  119. reo2host_status,
  120. reo2host_destination_ring4,
  121. reo2host_destination_ring3,
  122. reo2host_destination_ring2,
  123. reo2host_destination_ring1,
  124. rxdma2host_monitor_destination_mac3,
  125. rxdma2host_monitor_destination_mac2,
  126. rxdma2host_monitor_destination_mac1,
  127. ppdu_end_interrupts_mac3,
  128. ppdu_end_interrupts_mac2,
  129. ppdu_end_interrupts_mac1,
  130. rxdma2host_monitor_status_ring_mac3,
  131. rxdma2host_monitor_status_ring_mac2,
  132. rxdma2host_monitor_status_ring_mac1,
  133. host2rxdma_host_buf_ring_mac3,
  134. host2rxdma_host_buf_ring_mac2,
  135. host2rxdma_host_buf_ring_mac1,
  136. rxdma2host_destination_ring_mac3,
  137. rxdma2host_destination_ring_mac2,
  138. rxdma2host_destination_ring_mac1,
  139. host2tcl_input_ring4,
  140. host2tcl_input_ring3,
  141. host2tcl_input_ring2,
  142. host2tcl_input_ring1,
  143. wbm2host_tx_completions_ring3,
  144. wbm2host_tx_completions_ring2,
  145. wbm2host_tx_completions_ring1,
  146. tcl2host_status_ring,
  147. };
  148. struct CE_state;
  149. #define CE_COUNT_MAX 12
  150. #define HIF_MAX_GRP_IRQ 16
  151. #define HIF_MAX_GROUP 8
  152. #ifdef CONFIG_SLUB_DEBUG_ON
  153. #ifndef CONFIG_WIN
  154. #define HIF_CONFIG_SLUB_DEBUG_ON
  155. #endif
  156. #endif
  157. #ifndef NAPI_YIELD_BUDGET_BASED
  158. #ifdef HIF_CONFIG_SLUB_DEBUG_ON
  159. #define QCA_NAPI_DEF_SCALE_BIN_SHIFT 1
  160. #else /* PERF build */
  161. #ifdef CONFIG_WIN
  162. #define QCA_NAPI_DEF_SCALE_BIN_SHIFT 1
  163. #else
  164. #define QCA_NAPI_DEF_SCALE_BIN_SHIFT 4
  165. #endif /* CONFIG_WIN */
  166. #endif /* SLUB_DEBUG_ON */
  167. #else /* NAPI_YIELD_BUDGET_BASED */
  168. #define QCA_NAPI_DEF_SCALE_BIN_SHIFT 2
  169. #endif /* NAPI_YIELD_BUDGET_BASED */
  170. #define QCA_NAPI_BUDGET 64
  171. #define QCA_NAPI_DEF_SCALE \
  172. (1 << QCA_NAPI_DEF_SCALE_BIN_SHIFT)
  173. #define HIF_NAPI_MAX_RECEIVES (QCA_NAPI_BUDGET * QCA_NAPI_DEF_SCALE)
  174. /* NOTE: "napi->scale" can be changed,
  175. * but this does not change the number of buckets
  176. */
  177. #define QCA_NAPI_NUM_BUCKETS 4
  178. /**
  179. * qca_napi_stat - stats structure for execution contexts
  180. * @napi_schedules - number of times the schedule function is called
  181. * @napi_polls - number of times the execution context runs
  182. * @napi_completes - number of times that the generating interrupt is reenabled
  183. * @napi_workdone - cumulative of all work done reported by handler
  184. * @cpu_corrected - incremented when execution context runs on a different core
  185. * than the one that its irq is affined to.
  186. * @napi_budget_uses - histogram of work done per execution run
  187. * @time_limit_reache - count of yields due to time limit threshholds
  188. * @rxpkt_thresh_reached - count of yields due to a work limit
  189. *
  190. * needs to be renamed
  191. */
  192. struct qca_napi_stat {
  193. uint32_t napi_schedules;
  194. uint32_t napi_polls;
  195. uint32_t napi_completes;
  196. uint32_t napi_workdone;
  197. uint32_t cpu_corrected;
  198. uint32_t napi_budget_uses[QCA_NAPI_NUM_BUCKETS];
  199. uint32_t time_limit_reached;
  200. uint32_t rxpkt_thresh_reached;
  201. };
  202. /**
  203. * per NAPI instance data structure
  204. * This data structure holds stuff per NAPI instance.
  205. * Note that, in the current implementation, though scale is
  206. * an instance variable, it is set to the same value for all
  207. * instances.
  208. */
  209. struct qca_napi_info {
  210. struct net_device netdev; /* dummy net_dev */
  211. void *hif_ctx;
  212. struct napi_struct napi;
  213. uint8_t scale; /* currently same on all instances */
  214. uint8_t id;
  215. uint8_t cpu;
  216. int irq;
  217. struct qca_napi_stat stats[NR_CPUS];
  218. /* will only be present for data rx CE's */
  219. void (*lro_flush_cb)(void *);
  220. qdf_lro_ctx_t lro_ctx;
  221. };
  222. enum qca_napi_tput_state {
  223. QCA_NAPI_TPUT_UNINITIALIZED,
  224. QCA_NAPI_TPUT_LO,
  225. QCA_NAPI_TPUT_HI
  226. };
  227. enum qca_napi_cpu_state {
  228. QCA_NAPI_CPU_UNINITIALIZED,
  229. QCA_NAPI_CPU_DOWN,
  230. QCA_NAPI_CPU_UP };
  231. /**
  232. * struct qca_napi_cpu - an entry of the napi cpu table
  233. * @core_id: physical core id of the core
  234. * @cluster_id: cluster this core belongs to
  235. * @core_mask: mask to match all core of this cluster
  236. * @thread_mask: mask for this core within the cluster
  237. * @max_freq: maximum clock this core can be clocked at
  238. * same for all cpus of the same core.
  239. * @napis: bitmap of napi instances on this core
  240. * @execs: bitmap of execution contexts on this core
  241. * cluster_nxt: chain to link cores within the same cluster
  242. *
  243. * This structure represents a single entry in the napi cpu
  244. * table. The table is part of struct qca_napi_data.
  245. * This table is initialized by the init function, called while
  246. * the first napi instance is being created, updated by hotplug
  247. * notifier and when cpu affinity decisions are made (by throughput
  248. * detection), and deleted when the last napi instance is removed.
  249. */
  250. struct qca_napi_cpu {
  251. enum qca_napi_cpu_state state;
  252. int core_id;
  253. int cluster_id;
  254. cpumask_t core_mask;
  255. cpumask_t thread_mask;
  256. unsigned int max_freq;
  257. uint32_t napis;
  258. uint32_t execs;
  259. int cluster_nxt; /* index, not pointer */
  260. };
  261. /**
  262. * struct qca_napi_data - collection of napi data for a single hif context
  263. * @hif_softc: pointer to the hif context
  264. * @lock: spinlock used in the event state machine
  265. * @state: state variable used in the napi stat machine
  266. * @ce_map: bit map indicating which ce's have napis running
  267. * @exec_map: bit map of instanciated exec contexts
  268. * @napi_cpu: cpu info for irq affinty
  269. * @lilcl_head:
  270. * @bigcl_head:
  271. * @napi_mode: irq affinity & clock voting mode
  272. * @cpuhp_handler: CPU hotplug event registration handle
  273. */
  274. struct qca_napi_data {
  275. struct hif_softc *hif_softc;
  276. qdf_spinlock_t lock;
  277. uint32_t state;
  278. /* bitmap of created/registered NAPI instances, indexed by pipe_id,
  279. * not used by clients (clients use an id returned by create)
  280. */
  281. uint32_t ce_map;
  282. uint32_t exec_map;
  283. struct qca_napi_info *napis[CE_COUNT_MAX];
  284. struct qca_napi_cpu napi_cpu[NR_CPUS];
  285. int lilcl_head, bigcl_head;
  286. enum qca_napi_tput_state napi_mode;
  287. struct qdf_cpuhp_handler *cpuhp_handler;
  288. uint8_t flags;
  289. };
  290. /**
  291. * struct hif_config_info - Place Holder for hif confiruation
  292. * @enable_self_recovery: Self Recovery
  293. *
  294. * Structure for holding hif ini parameters.
  295. */
  296. struct hif_config_info {
  297. bool enable_self_recovery;
  298. #ifdef FEATURE_RUNTIME_PM
  299. bool enable_runtime_pm;
  300. u_int32_t runtime_pm_delay;
  301. #endif
  302. };
  303. /**
  304. * struct hif_target_info - Target Information
  305. * @target_version: Target Version
  306. * @target_type: Target Type
  307. * @target_revision: Target Revision
  308. * @soc_version: SOC Version
  309. *
  310. * Structure to hold target information.
  311. */
  312. struct hif_target_info {
  313. uint32_t target_version;
  314. uint32_t target_type;
  315. uint32_t target_revision;
  316. uint32_t soc_version;
  317. char *hw_name;
  318. };
  319. struct hif_opaque_softc {
  320. };
  321. /**
  322. * enum HIF_DEVICE_POWER_CHANGE_TYPE: Device Power change type
  323. *
  324. * @HIF_DEVICE_POWER_UP: HIF layer should power up interface and/or module
  325. * @HIF_DEVICE_POWER_DOWN: HIF layer should initiate bus-specific measures to
  326. * minimize power
  327. * @HIF_DEVICE_POWER_CUT: HIF layer should initiate bus-specific AND/OR
  328. * platform-specific measures to completely power-off
  329. * the module and associated hardware (i.e. cut power
  330. * supplies)
  331. */
  332. enum HIF_DEVICE_POWER_CHANGE_TYPE {
  333. HIF_DEVICE_POWER_UP,
  334. HIF_DEVICE_POWER_DOWN,
  335. HIF_DEVICE_POWER_CUT
  336. };
  337. /**
  338. * enum hif_enable_type: what triggered the enabling of hif
  339. *
  340. * @HIF_ENABLE_TYPE_PROBE: probe triggered enable
  341. * @HIF_ENABLE_TYPE_REINIT: reinit triggered enable
  342. */
  343. enum hif_enable_type {
  344. HIF_ENABLE_TYPE_PROBE,
  345. HIF_ENABLE_TYPE_REINIT,
  346. HIF_ENABLE_TYPE_MAX
  347. };
  348. /**
  349. * enum hif_disable_type: what triggered the disabling of hif
  350. *
  351. * @HIF_DISABLE_TYPE_PROBE_ERROR: probe error triggered disable
  352. * @HIF_DISABLE_TYPE_REINIT_ERROR: reinit error triggered disable
  353. * @HIF_DISABLE_TYPE_REMOVE: remove triggered disable
  354. * @HIF_DISABLE_TYPE_SHUTDOWN: shutdown triggered disable
  355. */
  356. enum hif_disable_type {
  357. HIF_DISABLE_TYPE_PROBE_ERROR,
  358. HIF_DISABLE_TYPE_REINIT_ERROR,
  359. HIF_DISABLE_TYPE_REMOVE,
  360. HIF_DISABLE_TYPE_SHUTDOWN,
  361. HIF_DISABLE_TYPE_MAX
  362. };
  363. /**
  364. * enum hif_device_config_opcode: configure mode
  365. *
  366. * @HIF_DEVICE_POWER_STATE: device power state
  367. * @HIF_DEVICE_GET_MBOX_BLOCK_SIZE: get mbox block size
  368. * @HIF_DEVICE_GET_MBOX_ADDR: get mbox block address
  369. * @HIF_DEVICE_GET_PENDING_EVENTS_FUNC: get pending events functions
  370. * @HIF_DEVICE_GET_IRQ_PROC_MODE: get irq proc mode
  371. * @HIF_DEVICE_GET_RECV_EVENT_MASK_UNMASK_FUNC: receive event function
  372. * @HIF_DEVICE_POWER_STATE_CHANGE: change power state
  373. * @HIF_DEVICE_GET_IRQ_YIELD_PARAMS: get yield params
  374. * @HIF_CONFIGURE_QUERY_SCATTER_REQUEST_SUPPORT: configure scatter request
  375. * @HIF_DEVICE_GET_OS_DEVICE: get OS device
  376. * @HIF_DEVICE_DEBUG_BUS_STATE: debug bus state
  377. * @HIF_BMI_DONE: bmi done
  378. * @HIF_DEVICE_SET_TARGET_TYPE: set target type
  379. * @HIF_DEVICE_SET_HTC_CONTEXT: set htc context
  380. * @HIF_DEVICE_GET_HTC_CONTEXT: get htc context
  381. */
  382. enum hif_device_config_opcode {
  383. HIF_DEVICE_POWER_STATE = 0,
  384. HIF_DEVICE_GET_MBOX_BLOCK_SIZE,
  385. HIF_DEVICE_GET_MBOX_ADDR,
  386. HIF_DEVICE_GET_PENDING_EVENTS_FUNC,
  387. HIF_DEVICE_GET_IRQ_PROC_MODE,
  388. HIF_DEVICE_GET_RECV_EVENT_MASK_UNMASK_FUNC,
  389. HIF_DEVICE_POWER_STATE_CHANGE,
  390. HIF_DEVICE_GET_IRQ_YIELD_PARAMS,
  391. HIF_CONFIGURE_QUERY_SCATTER_REQUEST_SUPPORT,
  392. HIF_DEVICE_GET_OS_DEVICE,
  393. HIF_DEVICE_DEBUG_BUS_STATE,
  394. HIF_BMI_DONE,
  395. HIF_DEVICE_SET_TARGET_TYPE,
  396. HIF_DEVICE_SET_HTC_CONTEXT,
  397. HIF_DEVICE_GET_HTC_CONTEXT,
  398. };
  399. #ifdef CONFIG_ATH_PCIE_ACCESS_DEBUG
  400. struct HID_ACCESS_LOG {
  401. uint32_t seqnum;
  402. bool is_write;
  403. void *addr;
  404. uint32_t value;
  405. };
  406. #endif
  407. void hif_reg_write(struct hif_opaque_softc *hif_ctx, uint32_t offset,
  408. uint32_t value);
  409. uint32_t hif_reg_read(struct hif_opaque_softc *hif_ctx, uint32_t offset);
  410. #define HIF_MAX_DEVICES 1
  411. /**
  412. * struct htc_callbacks - Structure for HTC Callbacks methods
  413. * @context: context to pass to the dsrhandler
  414. * note : rwCompletionHandler is provided the context
  415. * passed to hif_read_write
  416. * @rwCompletionHandler: Read / write completion handler
  417. * @dsrHandler: DSR Handler
  418. */
  419. struct htc_callbacks {
  420. void *context;
  421. QDF_STATUS(*rwCompletionHandler)(void *rwContext, QDF_STATUS status);
  422. QDF_STATUS(*dsrHandler)(void *context);
  423. };
  424. /**
  425. * struct hif_driver_state_callbacks - Callbacks for HIF to query Driver state
  426. * @context: Private data context
  427. * @set_recovery_in_progress: To Set Driver state for recovery in progress
  428. * @is_recovery_in_progress: Query if driver state is recovery in progress
  429. * @is_load_unload_in_progress: Query if driver state Load/Unload in Progress
  430. * @is_driver_unloading: Query if driver is unloading.
  431. *
  432. * This Structure provides callback pointer for HIF to query hdd for driver
  433. * states.
  434. */
  435. struct hif_driver_state_callbacks {
  436. void *context;
  437. void (*set_recovery_in_progress)(void *context, uint8_t val);
  438. bool (*is_recovery_in_progress)(void *context);
  439. bool (*is_load_unload_in_progress)(void *context);
  440. bool (*is_driver_unloading)(void *context);
  441. bool (*is_target_ready)(void *context);
  442. };
  443. /* This API detaches the HTC layer from the HIF device */
  444. void hif_detach_htc(struct hif_opaque_softc *hif_ctx);
  445. /****************************************************************/
  446. /* BMI and Diag window abstraction */
  447. /****************************************************************/
  448. #define HIF_BMI_EXCHANGE_NO_TIMEOUT ((uint32_t)(0))
  449. #define DIAG_TRANSFER_LIMIT 2048U /* maximum number of bytes that can be
  450. * handled atomically by
  451. * DiagRead/DiagWrite
  452. */
  453. /*
  454. * API to handle HIF-specific BMI message exchanges, this API is synchronous
  455. * and only allowed to be called from a context that can block (sleep)
  456. */
  457. QDF_STATUS hif_exchange_bmi_msg(struct hif_opaque_softc *hif_ctx,
  458. qdf_dma_addr_t cmd, qdf_dma_addr_t rsp,
  459. uint8_t *pSendMessage, uint32_t Length,
  460. uint8_t *pResponseMessage,
  461. uint32_t *pResponseLength, uint32_t TimeoutMS);
  462. /*
  463. * APIs to handle HIF specific diagnostic read accesses. These APIs are
  464. * synchronous and only allowed to be called from a context that
  465. * can block (sleep). They are not high performance APIs.
  466. *
  467. * hif_diag_read_access reads a 4 Byte aligned/length value from a
  468. * Target register or memory word.
  469. *
  470. * hif_diag_read_mem reads an arbitrary length of arbitrarily aligned memory.
  471. */
  472. QDF_STATUS hif_diag_read_access(struct hif_opaque_softc *hif_ctx,
  473. uint32_t address, uint32_t *data);
  474. QDF_STATUS hif_diag_read_mem(struct hif_opaque_softc *hif_ctx, uint32_t address,
  475. uint8_t *data, int nbytes);
  476. void hif_dump_target_memory(struct hif_opaque_softc *hif_ctx,
  477. void *ramdump_base, uint32_t address, uint32_t size);
  478. /*
  479. * APIs to handle HIF specific diagnostic write accesses. These APIs are
  480. * synchronous and only allowed to be called from a context that
  481. * can block (sleep).
  482. * They are not high performance APIs.
  483. *
  484. * hif_diag_write_access writes a 4 Byte aligned/length value to a
  485. * Target register or memory word.
  486. *
  487. * hif_diag_write_mem writes an arbitrary length of arbitrarily aligned memory.
  488. */
  489. QDF_STATUS hif_diag_write_access(struct hif_opaque_softc *hif_ctx,
  490. uint32_t address, uint32_t data);
  491. QDF_STATUS hif_diag_write_mem(struct hif_opaque_softc *hif_ctx,
  492. uint32_t address, uint8_t *data, int nbytes);
  493. typedef void (*fastpath_msg_handler)(void *, qdf_nbuf_t *, uint32_t);
  494. /*
  495. * Set the FASTPATH_mode_on flag in sc, for use by data path
  496. */
  497. #ifdef WLAN_FEATURE_FASTPATH
  498. void hif_enable_fastpath(struct hif_opaque_softc *hif_ctx);
  499. bool hif_is_fastpath_mode_enabled(struct hif_opaque_softc *hif_ctx);
  500. void *hif_get_ce_handle(struct hif_opaque_softc *hif_ctx, int ret);
  501. int hif_ce_fastpath_cb_register(struct hif_opaque_softc *hif_ctx,
  502. fastpath_msg_handler handler, void *context);
  503. #else
  504. static inline int hif_ce_fastpath_cb_register(struct hif_opaque_softc *hif_ctx,
  505. fastpath_msg_handler handler,
  506. void *context)
  507. {
  508. return QDF_STATUS_E_FAILURE;
  509. }
  510. static inline void *hif_get_ce_handle(struct hif_opaque_softc *hif_ctx, int ret)
  511. {
  512. return NULL;
  513. }
  514. #endif
  515. /*
  516. * Enable/disable CDC max performance workaround
  517. * For max-performace set this to 0
  518. * To allow SoC to enter sleep set this to 1
  519. */
  520. #define CONFIG_DISABLE_CDC_MAX_PERF_WAR 0
  521. void hif_ipa_get_ce_resource(struct hif_opaque_softc *hif_ctx,
  522. qdf_dma_addr_t *ce_sr_base_paddr,
  523. uint32_t *ce_sr_ring_size,
  524. qdf_dma_addr_t *ce_reg_paddr);
  525. /**
  526. * @brief List of callbacks - filled in by HTC.
  527. */
  528. struct hif_msg_callbacks {
  529. void *Context;
  530. /**< context meaningful to HTC */
  531. QDF_STATUS (*txCompletionHandler)(void *Context, qdf_nbuf_t wbuf,
  532. uint32_t transferID,
  533. uint32_t toeplitz_hash_result);
  534. QDF_STATUS (*rxCompletionHandler)(void *Context, qdf_nbuf_t wbuf,
  535. uint8_t pipeID);
  536. void (*txResourceAvailHandler)(void *context, uint8_t pipe);
  537. void (*fwEventHandler)(void *context, QDF_STATUS status);
  538. };
  539. enum hif_target_status {
  540. TARGET_STATUS_CONNECTED = 0, /* target connected */
  541. TARGET_STATUS_RESET, /* target got reset */
  542. TARGET_STATUS_EJECT, /* target got ejected */
  543. TARGET_STATUS_SUSPEND /*target got suspend */
  544. };
  545. /**
  546. * enum hif_attribute_flags: configure hif
  547. *
  548. * @HIF_LOWDESC_CE_CFG: Configure HIF with Low descriptor CE
  549. * @HIF_LOWDESC_CE_NO_PKTLOG_CFG: Configure HIF with Low descriptor
  550. * + No pktlog CE
  551. */
  552. enum hif_attribute_flags {
  553. HIF_LOWDESC_CE_CFG = 1,
  554. HIF_LOWDESC_CE_NO_PKTLOG_CFG
  555. };
  556. #define HIF_DATA_ATTR_SET_TX_CLASSIFY(attr, v) \
  557. (attr |= (v & 0x01) << 5)
  558. #define HIF_DATA_ATTR_SET_ENCAPSULATION_TYPE(attr, v) \
  559. (attr |= (v & 0x03) << 6)
  560. #define HIF_DATA_ATTR_SET_ADDR_X_SEARCH_DISABLE(attr, v) \
  561. (attr |= (v & 0x01) << 13)
  562. #define HIF_DATA_ATTR_SET_ADDR_Y_SEARCH_DISABLE(attr, v) \
  563. (attr |= (v & 0x01) << 14)
  564. #define HIF_DATA_ATTR_SET_TOEPLITZ_HASH_ENABLE(attr, v) \
  565. (attr |= (v & 0x01) << 15)
  566. #define HIF_DATA_ATTR_SET_PACKET_OR_RESULT_OFFSET(attr, v) \
  567. (attr |= (v & 0x0FFF) << 16)
  568. #define HIF_DATA_ATTR_SET_ENABLE_11H(attr, v) \
  569. (attr |= (v & 0x01) << 30)
  570. struct hif_ul_pipe_info {
  571. unsigned int nentries;
  572. unsigned int nentries_mask;
  573. unsigned int sw_index;
  574. unsigned int write_index; /* cached copy */
  575. unsigned int hw_index; /* cached copy */
  576. void *base_addr_owner_space; /* Host address space */
  577. qdf_dma_addr_t base_addr_CE_space; /* CE address space */
  578. };
  579. struct hif_dl_pipe_info {
  580. unsigned int nentries;
  581. unsigned int nentries_mask;
  582. unsigned int sw_index;
  583. unsigned int write_index; /* cached copy */
  584. unsigned int hw_index; /* cached copy */
  585. void *base_addr_owner_space; /* Host address space */
  586. qdf_dma_addr_t base_addr_CE_space; /* CE address space */
  587. };
  588. struct hif_pipe_addl_info {
  589. uint32_t pci_mem;
  590. uint32_t ctrl_addr;
  591. struct hif_ul_pipe_info ul_pipe;
  592. struct hif_dl_pipe_info dl_pipe;
  593. };
  594. struct hif_bus_id;
  595. void hif_claim_device(struct hif_opaque_softc *hif_ctx);
  596. QDF_STATUS hif_get_config_item(struct hif_opaque_softc *hif_ctx,
  597. int opcode, void *config, uint32_t config_len);
  598. void hif_set_mailbox_swap(struct hif_opaque_softc *hif_ctx);
  599. void hif_mask_interrupt_call(struct hif_opaque_softc *hif_ctx);
  600. void hif_post_init(struct hif_opaque_softc *hif_ctx, void *hHTC,
  601. struct hif_msg_callbacks *callbacks);
  602. QDF_STATUS hif_start(struct hif_opaque_softc *hif_ctx);
  603. void hif_stop(struct hif_opaque_softc *hif_ctx);
  604. void hif_flush_surprise_remove(struct hif_opaque_softc *hif_ctx);
  605. void hif_dump(struct hif_opaque_softc *hif_ctx, uint8_t CmdId, bool start);
  606. void hif_trigger_dump(struct hif_opaque_softc *hif_ctx,
  607. uint8_t cmd_id, bool start);
  608. QDF_STATUS hif_send_head(struct hif_opaque_softc *hif_ctx, uint8_t PipeID,
  609. uint32_t transferID, uint32_t nbytes,
  610. qdf_nbuf_t wbuf, uint32_t data_attr);
  611. void hif_send_complete_check(struct hif_opaque_softc *hif_ctx, uint8_t PipeID,
  612. int force);
  613. void hif_shut_down_device(struct hif_opaque_softc *hif_ctx);
  614. void hif_get_default_pipe(struct hif_opaque_softc *hif_ctx, uint8_t *ULPipe,
  615. uint8_t *DLPipe);
  616. int hif_map_service_to_pipe(struct hif_opaque_softc *hif_ctx, uint16_t svc_id,
  617. uint8_t *ul_pipe, uint8_t *dl_pipe, int *ul_is_polled,
  618. int *dl_is_polled);
  619. uint16_t
  620. hif_get_free_queue_number(struct hif_opaque_softc *hif_ctx, uint8_t PipeID);
  621. void *hif_get_targetdef(struct hif_opaque_softc *hif_ctx);
  622. uint32_t hif_hia_item_address(uint32_t target_type, uint32_t item_offset);
  623. void hif_set_target_sleep(struct hif_opaque_softc *hif_ctx, bool sleep_ok,
  624. bool wait_for_it);
  625. int hif_check_fw_reg(struct hif_opaque_softc *hif_ctx);
  626. #ifndef HIF_PCI
  627. static inline int hif_check_soc_status(struct hif_opaque_softc *hif_ctx)
  628. {
  629. return 0;
  630. }
  631. #else
  632. int hif_check_soc_status(struct hif_opaque_softc *hif_ctx);
  633. #endif
  634. void hif_get_hw_info(struct hif_opaque_softc *hif_ctx, u32 *version,
  635. u32 *revision, const char **target_name);
  636. void hif_disable_isr(struct hif_opaque_softc *hif_ctx);
  637. void hif_reset_soc(struct hif_opaque_softc *hif_ctx);
  638. void hif_save_htc_htt_config_endpoint(struct hif_opaque_softc *hif_ctx,
  639. int htc_htt_tx_endpoint);
  640. struct hif_opaque_softc *hif_open(qdf_device_t qdf_ctx, uint32_t mode,
  641. enum qdf_bus_type bus_type,
  642. struct hif_driver_state_callbacks *cbk);
  643. void hif_close(struct hif_opaque_softc *hif_ctx);
  644. QDF_STATUS hif_enable(struct hif_opaque_softc *hif_ctx, struct device *dev,
  645. void *bdev, const struct hif_bus_id *bid,
  646. enum qdf_bus_type bus_type,
  647. enum hif_enable_type type);
  648. void hif_disable(struct hif_opaque_softc *hif_ctx, enum hif_disable_type type);
  649. void hif_display_stats(struct hif_opaque_softc *hif_ctx);
  650. void hif_clear_stats(struct hif_opaque_softc *hif_ctx);
  651. #ifdef FEATURE_RUNTIME_PM
  652. struct hif_pm_runtime_lock;
  653. void hif_fastpath_resume(struct hif_opaque_softc *hif_ctx);
  654. int hif_pm_runtime_get(struct hif_opaque_softc *hif_ctx);
  655. void hif_pm_runtime_get_noresume(struct hif_opaque_softc *hif_ctx);
  656. int hif_pm_runtime_put(struct hif_opaque_softc *hif_ctx);
  657. int hif_runtime_lock_init(qdf_runtime_lock_t *lock, const char *name);
  658. void hif_runtime_lock_deinit(struct hif_opaque_softc *hif_ctx,
  659. struct hif_pm_runtime_lock *lock);
  660. int hif_pm_runtime_prevent_suspend(struct hif_opaque_softc *ol_sc,
  661. struct hif_pm_runtime_lock *lock);
  662. int hif_pm_runtime_allow_suspend(struct hif_opaque_softc *ol_sc,
  663. struct hif_pm_runtime_lock *lock);
  664. int hif_pm_runtime_prevent_suspend_timeout(struct hif_opaque_softc *ol_sc,
  665. struct hif_pm_runtime_lock *lock, unsigned int delay);
  666. #else
  667. struct hif_pm_runtime_lock {
  668. const char *name;
  669. };
  670. static inline void hif_fastpath_resume(struct hif_opaque_softc *hif_ctx) {}
  671. static inline void hif_pm_runtime_get_noresume(struct hif_opaque_softc *hif_ctx)
  672. {}
  673. static inline int hif_pm_runtime_get(struct hif_opaque_softc *hif_ctx)
  674. { return 0; }
  675. static inline int hif_pm_runtime_put(struct hif_opaque_softc *hif_ctx)
  676. { return 0; }
  677. static inline int hif_runtime_lock_init(qdf_runtime_lock_t *lock,
  678. const char *name)
  679. { return 0; }
  680. static inline void
  681. hif_runtime_lock_deinit(struct hif_opaque_softc *hif_ctx,
  682. struct hif_pm_runtime_lock *lock) {}
  683. static inline int hif_pm_runtime_prevent_suspend(struct hif_opaque_softc *ol_sc,
  684. struct hif_pm_runtime_lock *lock)
  685. { return 0; }
  686. static inline int hif_pm_runtime_allow_suspend(struct hif_opaque_softc *ol_sc,
  687. struct hif_pm_runtime_lock *lock)
  688. { return 0; }
  689. static inline int
  690. hif_pm_runtime_prevent_suspend_timeout(struct hif_opaque_softc *ol_sc,
  691. struct hif_pm_runtime_lock *lock, unsigned int delay)
  692. { return 0; }
  693. #endif
  694. void hif_enable_power_management(struct hif_opaque_softc *hif_ctx,
  695. bool is_packet_log_enabled);
  696. void hif_disable_power_management(struct hif_opaque_softc *hif_ctx);
  697. void hif_vote_link_down(struct hif_opaque_softc *hif_ctx);
  698. void hif_vote_link_up(struct hif_opaque_softc *hif_ctx);
  699. bool hif_can_suspend_link(struct hif_opaque_softc *hif_ctx);
  700. #ifdef IPA_OFFLOAD
  701. /**
  702. * hif_get_ipa_hw_type() - get IPA hw type
  703. *
  704. * This API return the IPA hw type.
  705. *
  706. * Return: IPA hw type
  707. */
  708. static inline
  709. enum ipa_hw_type hif_get_ipa_hw_type(void)
  710. {
  711. return ipa_get_hw_type();
  712. }
  713. /**
  714. * hif_get_ipa_present() - get IPA hw status
  715. *
  716. * This API return the IPA hw status.
  717. *
  718. * Return: true if IPA is present or false otherwise
  719. */
  720. static inline
  721. bool hif_get_ipa_present(void)
  722. {
  723. if (ipa_uc_reg_rdyCB(NULL) != -EPERM)
  724. return true;
  725. else
  726. return false;
  727. }
  728. #endif
  729. int hif_bus_resume(struct hif_opaque_softc *hif_ctx);
  730. /**
  731. * hif_bus_ealry_suspend() - stop non wmi tx traffic
  732. * @context: hif context
  733. */
  734. int hif_bus_early_suspend(struct hif_opaque_softc *hif_ctx);
  735. /**
  736. * hif_bus_late_resume() - resume non wmi traffic
  737. * @context: hif context
  738. */
  739. int hif_bus_late_resume(struct hif_opaque_softc *hif_ctx);
  740. int hif_bus_suspend(struct hif_opaque_softc *hif_ctx);
  741. int hif_bus_resume_noirq(struct hif_opaque_softc *hif_ctx);
  742. int hif_bus_suspend_noirq(struct hif_opaque_softc *hif_ctx);
  743. /**
  744. * hif_apps_irqs_enable() - Enables all irqs from the APPS side
  745. * @hif_ctx: an opaque HIF handle to use
  746. *
  747. * As opposed to the standard hif_irq_enable, this function always applies to
  748. * the APPS side kernel interrupt handling.
  749. *
  750. * Return: errno
  751. */
  752. int hif_apps_irqs_enable(struct hif_opaque_softc *hif_ctx);
  753. /**
  754. * hif_apps_irqs_disable() - Disables all irqs from the APPS side
  755. * @hif_ctx: an opaque HIF handle to use
  756. *
  757. * As opposed to the standard hif_irq_disable, this function always applies to
  758. * the APPS side kernel interrupt handling.
  759. *
  760. * Return: errno
  761. */
  762. int hif_apps_irqs_disable(struct hif_opaque_softc *hif_ctx);
  763. /**
  764. * hif_apps_wake_irq_enable() - Enables the wake irq from the APPS side
  765. * @hif_ctx: an opaque HIF handle to use
  766. *
  767. * As opposed to the standard hif_irq_enable, this function always applies to
  768. * the APPS side kernel interrupt handling.
  769. *
  770. * Return: errno
  771. */
  772. int hif_apps_wake_irq_enable(struct hif_opaque_softc *hif_ctx);
  773. /**
  774. * hif_apps_wake_irq_disable() - Disables the wake irq from the APPS side
  775. * @hif_ctx: an opaque HIF handle to use
  776. *
  777. * As opposed to the standard hif_irq_disable, this function always applies to
  778. * the APPS side kernel interrupt handling.
  779. *
  780. * Return: errno
  781. */
  782. int hif_apps_wake_irq_disable(struct hif_opaque_softc *hif_ctx);
  783. #ifdef FEATURE_RUNTIME_PM
  784. int hif_pre_runtime_suspend(struct hif_opaque_softc *hif_ctx);
  785. void hif_pre_runtime_resume(struct hif_opaque_softc *hif_ctx);
  786. int hif_runtime_suspend(struct hif_opaque_softc *hif_ctx);
  787. int hif_runtime_resume(struct hif_opaque_softc *hif_ctx);
  788. void hif_process_runtime_suspend_success(struct hif_opaque_softc *hif_ctx);
  789. void hif_process_runtime_suspend_failure(struct hif_opaque_softc *hif_ctx);
  790. void hif_process_runtime_resume_success(struct hif_opaque_softc *hif_ctx);
  791. #endif
  792. int hif_get_irq_num(struct hif_opaque_softc *scn, int *irq, uint32_t size);
  793. int hif_dump_registers(struct hif_opaque_softc *scn);
  794. int ol_copy_ramdump(struct hif_opaque_softc *scn);
  795. void hif_crash_shutdown(struct hif_opaque_softc *hif_ctx);
  796. void hif_get_hw_info(struct hif_opaque_softc *hif_ctx, u32 *version,
  797. u32 *revision, const char **target_name);
  798. void hif_lro_flush_cb_register(struct hif_opaque_softc *hif_ctx,
  799. void (lro_flush_handler)(void *arg),
  800. void *(lro_init_handler)(void));
  801. void hif_lro_flush_cb_deregister(struct hif_opaque_softc *hif_ctx,
  802. void (lro_deinit_cb)(void *arg));
  803. bool hif_needs_bmi(struct hif_opaque_softc *hif_ctx);
  804. enum qdf_bus_type hif_get_bus_type(struct hif_opaque_softc *hif_hdl);
  805. struct hif_target_info *hif_get_target_info_handle(struct hif_opaque_softc *
  806. scn);
  807. struct hif_config_info *hif_get_ini_handle(struct hif_opaque_softc *hif_ctx);
  808. struct ramdump_info *hif_get_ramdump_ctx(struct hif_opaque_softc *hif_ctx);
  809. enum hif_target_status hif_get_target_status(struct hif_opaque_softc *hif_ctx);
  810. void hif_set_target_status(struct hif_opaque_softc *hif_ctx, enum
  811. hif_target_status);
  812. void hif_init_ini_config(struct hif_opaque_softc *hif_ctx,
  813. struct hif_config_info *cfg);
  814. void hif_update_tx_ring(struct hif_opaque_softc *osc, u_int32_t num_htt_cmpls);
  815. qdf_nbuf_t hif_batch_send(struct hif_opaque_softc *osc, qdf_nbuf_t msdu,
  816. uint32_t transfer_id, u_int32_t len, uint32_t sendhead);
  817. int hif_send_single(struct hif_opaque_softc *osc, qdf_nbuf_t msdu, uint32_t
  818. transfer_id, u_int32_t len);
  819. int hif_send_fast(struct hif_opaque_softc *osc, qdf_nbuf_t nbuf,
  820. uint32_t transfer_id, uint32_t download_len);
  821. void hif_pkt_dl_len_set(void *hif_sc, unsigned int pkt_download_len);
  822. void hif_ce_war_disable(void);
  823. void hif_ce_war_enable(void);
  824. void hif_disable_interrupt(struct hif_opaque_softc *osc, uint32_t pipe_num);
  825. #ifdef QCA_NSS_WIFI_OFFLOAD_SUPPORT
  826. struct hif_pipe_addl_info *hif_get_addl_pipe_info(struct hif_opaque_softc *osc,
  827. struct hif_pipe_addl_info *hif_info, uint32_t pipe_number);
  828. uint32_t hif_set_nss_wifiol_mode(struct hif_opaque_softc *osc,
  829. uint32_t pipe_num);
  830. int32_t hif_get_nss_wifiol_bypass_nw_process(struct hif_opaque_softc *osc);
  831. #endif /* QCA_NSS_WIFI_OFFLOAD_SUPPORT */
  832. void hif_set_bundle_mode(struct hif_opaque_softc *hif_ctx, bool enabled,
  833. int rx_bundle_cnt);
  834. int hif_bus_reset_resume(struct hif_opaque_softc *hif_ctx);
  835. void hif_set_attribute(struct hif_opaque_softc *osc, uint8_t hif_attrib);
  836. void *hif_get_lro_info(int ctx_id, struct hif_opaque_softc *hif_hdl);
  837. enum hif_exec_type {
  838. HIF_EXEC_NAPI_TYPE,
  839. HIF_EXEC_TASKLET_TYPE,
  840. };
  841. typedef uint32_t (*ext_intr_handler)(void *, uint32_t);
  842. uint32_t hif_configure_ext_group_interrupts(struct hif_opaque_softc *hif_ctx);
  843. uint32_t hif_register_ext_group(struct hif_opaque_softc *hif_ctx,
  844. uint32_t numirq, uint32_t irq[], ext_intr_handler handler,
  845. void *cb_ctx, const char *context_name,
  846. enum hif_exec_type type, uint32_t scale);
  847. void hif_deregister_exec_group(struct hif_opaque_softc *hif_ctx,
  848. const char *context_name);
  849. void hif_update_pipe_callback(struct hif_opaque_softc *osc,
  850. u_int8_t pipeid,
  851. struct hif_msg_callbacks *callbacks);
  852. void hif_print_napi_stats(struct hif_opaque_softc *hif_ctx);
  853. #ifdef __cplusplus
  854. }
  855. #endif
  856. void *hif_get_dev_ba(struct hif_opaque_softc *hif_handle);
  857. /**
  858. * hif_set_initial_wakeup_cb() - set the initial wakeup event handler function
  859. * @hif_ctx - the HIF context to assign the callback to
  860. * @callback - the callback to assign
  861. * @priv - the private data to pass to the callback when invoked
  862. *
  863. * Return: None
  864. */
  865. void hif_set_initial_wakeup_cb(struct hif_opaque_softc *hif_ctx,
  866. void (*callback)(void *),
  867. void *priv);
  868. #endif /* _HIF_H_ */