hif.h 31 KB

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