hif_napi.h 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. /*
  2. * Copyright (c) 2015-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_NAPI_H__
  27. #define __HIF_NAPI_H__
  28. /**
  29. * DOC: hif_napi.h
  30. *
  31. * Interface to HIF implemented functions of NAPI.
  32. * These are used by hdd_napi.
  33. */
  34. /* CLD headers */
  35. #include <hif.h> /* struct hif_opaque_softc; */
  36. /**
  37. * common stuff
  38. * The declarations until #ifdef FEATURE_NAPI below
  39. * are valid whether or not FEATURE_NAPI has been
  40. * defined.
  41. */
  42. /**
  43. * NAPI manages the following states:
  44. * NAPI state: per NAPI instance, ENABLED/DISABLED
  45. * CPU state: per CPU, DOWN/UP
  46. * TPUT state: global, LOW/HI
  47. *
  48. * "Dynamic" changes to state of various NAPI structures are
  49. * managed by NAPI events. The events may be produced by
  50. * various detection points. With each event, some data is
  51. * sent. The main event handler in hif_napi handles and makes
  52. * the state changes.
  53. *
  54. * event : data : generated
  55. * ---------------:------------------:------------------
  56. * EVT_INI_FILE : cfg->napi_enable : after ini file processed
  57. * EVT_CMD_STATE : cmd arg : by the vendor cmd
  58. * EVT_INT_STATE : 0 : internal - shut off/disable
  59. * EVT_CPU_STATE : (cpu << 16)|state: CPU hotplug events
  60. * EVT_TPUT_STATE : (high/low) : tput trigger
  61. * EVT_USR_SERIAL : num-serial_calls : WMA/ROAMING-START/IND
  62. * EVT_USR_NORMAL : N/A : WMA/ROAMING-END
  63. */
  64. enum qca_napi_event {
  65. NAPI_EVT_INVALID,
  66. NAPI_EVT_INI_FILE,
  67. NAPI_EVT_CMD_STATE,
  68. NAPI_EVT_INT_STATE,
  69. NAPI_EVT_CPU_STATE,
  70. NAPI_EVT_TPUT_STATE,
  71. NAPI_EVT_USR_SERIAL,
  72. NAPI_EVT_USR_NORMAL
  73. };
  74. /**
  75. * Following are some of NAPI related features controlled using feature flag
  76. * These flags need to be enabled in the qca_napi_data->flags variable for the
  77. * feature to kick in.
  78. .* QCA_NAPI_FEATURE_CPU_CORRECTION - controls CPU correction logic
  79. .* QCA_NAPI_FEATURE_IRQ_BLACKLISTING - controls call to irq_blacklist_on API
  80. .* QCA_NAPI_FEATURE_CORE_CTL_BOOST - controls call to core_ctl_set_boost API
  81. */
  82. #define QCA_NAPI_FEATURE_CPU_CORRECTION BIT(1)
  83. #define QCA_NAPI_FEATURE_IRQ_BLACKLISTING BIT(2)
  84. #define QCA_NAPI_FEATURE_CORE_CTL_BOOST BIT(3)
  85. /**
  86. * Macros to map ids -returned by ...create()- to pipes and vice versa
  87. */
  88. #define NAPI_ID2PIPE(i) ((i)-1)
  89. #define NAPI_PIPE2ID(p) ((p)+1)
  90. int hif_napi_lro_flush_cb_register(struct hif_opaque_softc *hif_hdl,
  91. void (lro_flush_handler)(void *),
  92. void *(lro_init_handler)(void));
  93. void hif_napi_lro_flush_cb_deregister(struct hif_opaque_softc *hif_hdl,
  94. void (lro_deinit_cb)(void *));
  95. void *hif_napi_get_lro_info(struct hif_opaque_softc *hif_hdl, int napi_id);
  96. #ifdef FEATURE_NAPI
  97. /**
  98. * NAPI HIF API
  99. *
  100. * the declarations below only apply to the case
  101. * where FEATURE_NAPI is defined
  102. */
  103. int hif_napi_create(struct hif_opaque_softc *hif,
  104. int (*poll)(struct napi_struct *, int),
  105. int budget,
  106. int scale,
  107. uint8_t flags);
  108. int hif_napi_destroy(struct hif_opaque_softc *hif,
  109. uint8_t id,
  110. int force);
  111. struct qca_napi_data *hif_napi_get_all(struct hif_opaque_softc *hif);
  112. int hif_napi_event(struct hif_opaque_softc *hif,
  113. enum qca_napi_event event,
  114. void *data);
  115. /* called from the ISR within hif, so, ce is known */
  116. int hif_napi_enabled(struct hif_opaque_softc *hif, int ce);
  117. /* called from hdd (napi_poll), using napi id as a selector */
  118. void hif_napi_enable_irq(struct hif_opaque_softc *hif, int id);
  119. /* called by ce_tasklet.c::ce_dispatch_interrupt*/
  120. int hif_napi_schedule(struct hif_opaque_softc *scn, int ce_id);
  121. /* called by hdd_napi, which is called by kernel */
  122. int hif_napi_poll(struct hif_opaque_softc *hif_ctx,
  123. struct napi_struct *napi, int budget);
  124. #ifdef HELIUMPLUS
  125. /* called to retrieve NAPI CPU statistics */
  126. void hif_napi_stats(struct qca_napi_data *napid);
  127. void hif_napi_update_yield_stats(struct CE_state *ce_state,
  128. bool time_limit_reached,
  129. bool rxpkt_thresh_reached);
  130. #else
  131. static inline void hif_napi_stats(struct qca_napi_data *napid) { }
  132. static inline void hif_napi_update_yield_stats(struct CE_state *ce_state,
  133. bool time_limit_reached,
  134. bool rxpkt_thresh_reached) { }
  135. #endif
  136. #ifdef FEATURE_NAPI_DEBUG
  137. #define NAPI_DEBUG(fmt, ...) \
  138. qdf_print("wlan: NAPI: %s:%d "fmt, __func__, __LINE__, ##__VA_ARGS__);
  139. #else
  140. #define NAPI_DEBUG(fmt, ...) /* NO-OP */
  141. #endif /* FEATURE NAPI_DEBUG */
  142. #define HNC_ANY_CPU (-1)
  143. #define HNC_ACT_RELOCATE (0)
  144. #define HNC_ACT_COLLAPSE (1)
  145. #define HNC_ACT_DISPERSE (-1)
  146. enum qca_blacklist_op {
  147. BLACKLIST_QUERY,
  148. BLACKLIST_OFF,
  149. BLACKLIST_ON
  150. };
  151. int hif_napi_cpu_blacklist(uint8_t flags, enum qca_blacklist_op op);
  152. /**
  153. * Local interface to HIF implemented functions of NAPI CPU affinity management.
  154. * Note:
  155. * 1- The symbols in this file are NOT supposed to be used by any
  156. * entity other than hif_napi.c
  157. * 2- The symbols are valid only if HELIUMPLUS is defined. They are otherwise
  158. * mere wrappers.
  159. *
  160. */
  161. #ifndef HELIUMPLUS
  162. /**
  163. * stub functions
  164. */
  165. /* fw-declare to make compiler happy */
  166. struct qca_napi_data;
  167. static inline int hif_napi_cpu_init(struct hif_opaque_softc *hif)
  168. { return 0; }
  169. static inline int hif_napi_cpu_deinit(struct hif_opaque_softc *hif)
  170. { return 0; }
  171. static inline int hif_napi_serialize(struct hif_opaque_softc *hif, int is_on)
  172. { return -EPERM; }
  173. #else /* HELIUMPLUS - NAPI CPU symbols are valid */
  174. /*
  175. * prototype signatures
  176. */
  177. int hif_napi_cpu_init(struct hif_opaque_softc *hif);
  178. int hif_napi_cpu_deinit(struct hif_opaque_softc *hif);
  179. int hif_napi_cpu_migrate(struct qca_napi_data *napid, int cpu, int action);
  180. int hif_napi_serialize(struct hif_opaque_softc *hif, int is_on);
  181. #endif /* HELIUMPLUS */
  182. #else /* ! defined(FEATURE_NAPI) */
  183. /**
  184. * Stub API
  185. *
  186. * The declarations in this section are valid only
  187. * when FEATURE_NAPI has *not* been defined.
  188. */
  189. #define NAPI_DEBUG(fmt, ...) /* NO-OP */
  190. static inline int hif_napi_create(struct hif_opaque_softc *hif,
  191. uint8_t pipe_id,
  192. int (*poll)(struct napi_struct *, int),
  193. int budget,
  194. int scale,
  195. uint8_t flags)
  196. { return -EPERM; }
  197. static inline int hif_napi_destroy(struct hif_opaque_softc *hif,
  198. uint8_t id,
  199. int force)
  200. { return -EPERM; }
  201. static inline struct qca_napi_data *hif_napi_get_all(
  202. struct hif_opaque_softc *hif)
  203. { return NULL; }
  204. static inline int hif_napi_event(struct hif_opaque_softc *hif,
  205. enum qca_napi_event event,
  206. void *data)
  207. { return -EPERM; }
  208. /* called from the ISR within hif, so, ce is known */
  209. static inline int hif_napi_enabled(struct hif_opaque_softc *hif, int ce)
  210. { return 0; }
  211. /* called from hdd (napi_poll), using napi id as a selector */
  212. static inline void hif_napi_enable_irq(struct hif_opaque_softc *hif, int id)
  213. { return; }
  214. static inline int hif_napi_schedule(struct hif_opaque_softc *hif, int ce_id)
  215. { return 0; }
  216. static inline int hif_napi_poll(struct napi_struct *napi, int budget)
  217. { return -EPERM; }
  218. static inline void hif_napi_stats(struct qca_napi_data *napid) { }
  219. static inline void hif_napi_update_yield_stats(struct CE_state *ce_state,
  220. bool time_limit_reached,
  221. bool rxpkt_thresh_reached) { }
  222. #endif /* FEATURE_NAPI */
  223. static inline int hif_ext_napi_enabled(struct hif_opaque_softc *hif, int ce)
  224. { return 0; }
  225. static inline int hif_napi_schedule_grp(struct hif_opaque_softc *hif,
  226. uint32_t grp_id)
  227. { return 0; }
  228. #endif /* __HIF_NAPI_H__ */