hif_napi.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  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. void *hif_napi_get_lro_info(struct hif_opaque_softc *hif_hdl, int napi_id);
  91. #ifdef FEATURE_NAPI
  92. /**
  93. * NAPI HIF API
  94. *
  95. * the declarations below only apply to the case
  96. * where FEATURE_NAPI is defined
  97. */
  98. int hif_napi_create(struct hif_opaque_softc *hif,
  99. int (*poll)(struct napi_struct *, int),
  100. int budget,
  101. int scale,
  102. uint8_t flags);
  103. int hif_napi_destroy(struct hif_opaque_softc *hif,
  104. uint8_t id,
  105. int force);
  106. struct qca_napi_data *hif_napi_get_all(struct hif_opaque_softc *hif);
  107. int hif_napi_event(struct hif_opaque_softc *hif,
  108. enum qca_napi_event event,
  109. void *data);
  110. /* called from the ISR within hif, so, ce is known */
  111. int hif_napi_enabled(struct hif_opaque_softc *hif, int ce);
  112. /* called from hdd (napi_poll), using napi id as a selector */
  113. void hif_napi_enable_irq(struct hif_opaque_softc *hif, int id);
  114. /* called by ce_tasklet.c::ce_dispatch_interrupt*/
  115. int hif_napi_schedule(struct hif_opaque_softc *scn, int ce_id);
  116. /* called by hdd_napi, which is called by kernel */
  117. int hif_napi_poll(struct hif_opaque_softc *hif_ctx,
  118. struct napi_struct *napi, int budget);
  119. #ifdef HELIUMPLUS
  120. /* called to retrieve NAPI CPU statistics */
  121. void hif_napi_stats(struct qca_napi_data *napid);
  122. void hif_napi_update_yield_stats(struct CE_state *ce_state,
  123. bool time_limit_reached,
  124. bool rxpkt_thresh_reached);
  125. #else
  126. static inline void hif_napi_stats(struct qca_napi_data *napid) { }
  127. static inline void hif_napi_update_yield_stats(struct CE_state *ce_state,
  128. bool time_limit_reached,
  129. bool rxpkt_thresh_reached) { }
  130. #endif
  131. #ifdef FEATURE_NAPI_DEBUG
  132. #define NAPI_DEBUG(fmt, ...) \
  133. qdf_print("wlan: NAPI: %s:%d "fmt, __func__, __LINE__, ##__VA_ARGS__)
  134. #else
  135. #define NAPI_DEBUG(fmt, ...) /* NO-OP */
  136. #endif /* FEATURE NAPI_DEBUG */
  137. #define HNC_ANY_CPU (-1)
  138. #define HNC_ACT_RELOCATE (0)
  139. #define HNC_ACT_COLLAPSE (1)
  140. #define HNC_ACT_DISPERSE (-1)
  141. enum qca_blacklist_op {
  142. BLACKLIST_QUERY,
  143. BLACKLIST_OFF,
  144. BLACKLIST_ON
  145. };
  146. int hif_napi_cpu_blacklist(struct qca_napi_data *napid,
  147. enum qca_blacklist_op op);
  148. /**
  149. * Local interface to HIF implemented functions of NAPI CPU affinity management.
  150. * Note:
  151. * 1- The symbols in this file are NOT supposed to be used by any
  152. * entity other than hif_napi.c
  153. * 2- The symbols are valid only if HELIUMPLUS is defined. They are otherwise
  154. * mere wrappers.
  155. *
  156. */
  157. #ifndef HELIUMPLUS
  158. /**
  159. * stub functions
  160. */
  161. /* fw-declare to make compiler happy */
  162. struct qca_napi_data;
  163. static inline int hif_napi_cpu_init(struct hif_opaque_softc *hif)
  164. { return 0; }
  165. static inline int hif_napi_cpu_deinit(struct hif_opaque_softc *hif)
  166. { return 0; }
  167. static inline int hif_napi_serialize(struct hif_opaque_softc *hif, int is_on)
  168. { return -EPERM; }
  169. #else /* HELIUMPLUS - NAPI CPU symbols are valid */
  170. /*
  171. * prototype signatures
  172. */
  173. int hif_napi_cpu_init(struct hif_opaque_softc *hif);
  174. int hif_napi_cpu_deinit(struct hif_opaque_softc *hif);
  175. int hif_napi_cpu_migrate(struct qca_napi_data *napid, int cpu, int action);
  176. int hif_napi_serialize(struct hif_opaque_softc *hif, int is_on);
  177. #endif /* HELIUMPLUS */
  178. #else /* ! defined(FEATURE_NAPI) */
  179. /**
  180. * Stub API
  181. *
  182. * The declarations in this section are valid only
  183. * when FEATURE_NAPI has *not* been defined.
  184. */
  185. #define NAPI_DEBUG(fmt, ...) /* NO-OP */
  186. static inline int hif_napi_create(struct hif_opaque_softc *hif,
  187. uint8_t pipe_id,
  188. int (*poll)(struct napi_struct *, int),
  189. int budget,
  190. int scale,
  191. uint8_t flags)
  192. { return -EPERM; }
  193. static inline int hif_napi_destroy(struct hif_opaque_softc *hif,
  194. uint8_t id,
  195. int force)
  196. { return -EPERM; }
  197. static inline struct qca_napi_data *hif_napi_get_all(
  198. struct hif_opaque_softc *hif)
  199. { return NULL; }
  200. static inline int hif_napi_event(struct hif_opaque_softc *hif,
  201. enum qca_napi_event event,
  202. void *data)
  203. { return -EPERM; }
  204. /* called from the ISR within hif, so, ce is known */
  205. static inline int hif_napi_enabled(struct hif_opaque_softc *hif, int ce)
  206. { return 0; }
  207. /* called from hdd (napi_poll), using napi id as a selector */
  208. static inline void hif_napi_enable_irq(struct hif_opaque_softc *hif, int id)
  209. { return; }
  210. static inline int hif_napi_schedule(struct hif_opaque_softc *hif, int ce_id)
  211. { return 0; }
  212. static inline int hif_napi_poll(struct napi_struct *napi, int budget)
  213. { return -EPERM; }
  214. static inline void hif_napi_stats(struct qca_napi_data *napid) { }
  215. static inline void hif_napi_update_yield_stats(struct CE_state *ce_state,
  216. bool time_limit_reached,
  217. bool rxpkt_thresh_reached) { }
  218. #endif /* FEATURE_NAPI */
  219. static inline int hif_ext_napi_enabled(struct hif_opaque_softc *hif, int ce)
  220. { return 0; }
  221. static inline int hif_napi_schedule_grp(struct hif_opaque_softc *hif,
  222. uint32_t grp_id)
  223. { return 0; }
  224. #endif /* __HIF_NAPI_H__ */