hif_napi.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. /*
  2. * Copyright (c) 2015-2018 The Linux Foundation. All rights reserved.
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for
  5. * any purpose with or without fee is hereby granted, provided that the
  6. * above copyright notice and this permission notice appear in all
  7. * copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
  10. * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
  11. * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
  12. * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  13. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  14. * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  15. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  16. * PERFORMANCE OF THIS SOFTWARE.
  17. */
  18. #ifndef __HIF_NAPI_H__
  19. #define __HIF_NAPI_H__
  20. /**
  21. * DOC: hif_napi.h
  22. *
  23. * Interface to HIF implemented functions of NAPI.
  24. * These are used by hdd_napi.
  25. */
  26. /* CLD headers */
  27. #include <hif.h> /* struct hif_opaque_softc; */
  28. /**
  29. * common stuff
  30. * The declarations until #ifdef FEATURE_NAPI below
  31. * are valid whether or not FEATURE_NAPI has been
  32. * defined.
  33. */
  34. /**
  35. * NAPI manages the following states:
  36. * NAPI state: per NAPI instance, ENABLED/DISABLED
  37. * CPU state: per CPU, DOWN/UP
  38. * TPUT state: global, LOW/HI
  39. *
  40. * "Dynamic" changes to state of various NAPI structures are
  41. * managed by NAPI events. The events may be produced by
  42. * various detection points. With each event, some data is
  43. * sent. The main event handler in hif_napi handles and makes
  44. * the state changes.
  45. *
  46. * event : data : generated
  47. * ---------------:------------------:------------------
  48. * EVT_INI_FILE : cfg->napi_enable : after ini file processed
  49. * EVT_CMD_STATE : cmd arg : by the vendor cmd
  50. * EVT_INT_STATE : 0 : internal - shut off/disable
  51. * EVT_CPU_STATE : (cpu << 16)|state: CPU hotplug events
  52. * EVT_TPUT_STATE : (high/low) : tput trigger
  53. * EVT_USR_SERIAL : num-serial_calls : WMA/ROAMING-START/IND
  54. * EVT_USR_NORMAL : N/A : WMA/ROAMING-END
  55. */
  56. enum qca_napi_event {
  57. NAPI_EVT_INVALID,
  58. NAPI_EVT_INI_FILE,
  59. NAPI_EVT_CMD_STATE,
  60. NAPI_EVT_INT_STATE,
  61. NAPI_EVT_CPU_STATE,
  62. NAPI_EVT_TPUT_STATE,
  63. NAPI_EVT_USR_SERIAL,
  64. NAPI_EVT_USR_NORMAL
  65. };
  66. /**
  67. * Following are some of NAPI related features controlled using feature flag
  68. * These flags need to be enabled in the qca_napi_data->flags variable for the
  69. * feature to kick in.
  70. .* QCA_NAPI_FEATURE_CPU_CORRECTION - controls CPU correction logic
  71. .* QCA_NAPI_FEATURE_IRQ_BLACKLISTING - controls call to irq_blacklist_on API
  72. .* QCA_NAPI_FEATURE_CORE_CTL_BOOST - controls call to core_ctl_set_boost API
  73. */
  74. #define QCA_NAPI_FEATURE_CPU_CORRECTION BIT(1)
  75. #define QCA_NAPI_FEATURE_IRQ_BLACKLISTING BIT(2)
  76. #define QCA_NAPI_FEATURE_CORE_CTL_BOOST BIT(3)
  77. /**
  78. * Macros to map ids -returned by ...create()- to pipes and vice versa
  79. */
  80. #define NAPI_ID2PIPE(i) ((i)-1)
  81. #define NAPI_PIPE2ID(p) ((p)+1)
  82. #ifdef RECEIVE_OFFLOAD
  83. /**
  84. * hif_napi_rx_offld_flush_cb_register() - Register flush callback for Rx offld
  85. * @hif_hdl: pointer to hif context
  86. * @offld_flush_handler: register offld flush callback
  87. *
  88. * Return: None
  89. */
  90. void hif_napi_rx_offld_flush_cb_register(struct hif_opaque_softc *hif_hdl,
  91. void (rx_ol_flush_handler)(void *arg));
  92. /**
  93. * hif_napi_rx_offld_flush_cb_deregister() - Degregister offld flush_cb
  94. * @hif_hdl: pointer to hif context
  95. *
  96. * Return: NONE
  97. */
  98. void hif_napi_rx_offld_flush_cb_deregister(struct hif_opaque_softc *hif_hdl);
  99. #endif /* RECEIVE_OFFLOAD */
  100. /**
  101. * hif_napi_get_lro_info() - returns the address LRO data for napi_id
  102. * @hif: pointer to hif context
  103. * @napi_id: napi instance
  104. *
  105. * Description:
  106. * Returns the address of the LRO structure
  107. *
  108. * Return:
  109. * <addr>: address of the LRO structure
  110. */
  111. void *hif_napi_get_lro_info(struct hif_opaque_softc *hif_hdl, int napi_id);
  112. enum qca_blacklist_op {
  113. BLACKLIST_QUERY,
  114. BLACKLIST_OFF,
  115. BLACKLIST_ON
  116. };
  117. #ifdef FEATURE_NAPI
  118. /**
  119. * NAPI HIF API
  120. *
  121. * the declarations below only apply to the case
  122. * where FEATURE_NAPI is defined
  123. */
  124. int hif_napi_create(struct hif_opaque_softc *hif,
  125. int (*poll)(struct napi_struct *, int),
  126. int budget,
  127. int scale,
  128. uint8_t flags);
  129. int hif_napi_destroy(struct hif_opaque_softc *hif,
  130. uint8_t id,
  131. int force);
  132. struct qca_napi_data *hif_napi_get_all(struct hif_opaque_softc *hif);
  133. /**
  134. * hif_get_napi() - get NAPI corresponding to napi_id
  135. * @napi_id: NAPI instance
  136. * @napid: Handle NAPI
  137. *
  138. * Return: napi corresponding napi_id
  139. */
  140. struct qca_napi_info *hif_get_napi(int napi_id, struct qca_napi_data *napid);
  141. int hif_napi_event(struct hif_opaque_softc *hif,
  142. enum qca_napi_event event,
  143. void *data);
  144. /* called from the ISR within hif, so, ce is known */
  145. int hif_napi_enabled(struct hif_opaque_softc *hif, int ce);
  146. bool hif_napi_created(struct hif_opaque_softc *hif, int ce);
  147. /* called from hdd (napi_poll), using napi id as a selector */
  148. void hif_napi_enable_irq(struct hif_opaque_softc *hif, int id);
  149. /* called by ce_tasklet.c::ce_dispatch_interrupt*/
  150. bool hif_napi_schedule(struct hif_opaque_softc *scn, int ce_id);
  151. /* called by hdd_napi, which is called by kernel */
  152. int hif_napi_poll(struct hif_opaque_softc *hif_ctx,
  153. struct napi_struct *napi, int budget);
  154. #ifdef FEATURE_NAPI_DEBUG
  155. #define NAPI_DEBUG(fmt, ...) \
  156. qdf_debug("wlan: NAPI: %s:%d "fmt, __func__, __LINE__, ##__VA_ARGS__)
  157. #else
  158. #define NAPI_DEBUG(fmt, ...) /* NO-OP */
  159. #endif /* FEATURE NAPI_DEBUG */
  160. #define HNC_ANY_CPU (-1)
  161. #define HNC_ACT_RELOCATE (0)
  162. #define HNC_ACT_COLLAPSE (1)
  163. #define HNC_ACT_DISPERSE (-1)
  164. /**
  165. * hif_update_napi_max_poll_time() - updates NAPI max poll time
  166. * @ce_state: ce state
  167. * @ce_id: Copy engine ID
  168. * @cpu_id: cpu id
  169. *
  170. * This API updates NAPI max poll time per CE per SPU.
  171. *
  172. * Return: void
  173. */
  174. void hif_update_napi_max_poll_time(struct CE_state *ce_state,
  175. int ce_id,
  176. int cpu_id);
  177. /**
  178. * Local interface to HIF implemented functions of NAPI CPU affinity management.
  179. * Note:
  180. * 1- The symbols in this file are NOT supposed to be used by any
  181. * entity other than hif_napi.c
  182. * 2- The symbols are valid only if HELIUMPLUS is defined. They are otherwise
  183. * mere wrappers.
  184. *
  185. */
  186. #else /* ! defined(FEATURE_NAPI) */
  187. /**
  188. * Stub API
  189. *
  190. * The declarations in this section are valid only
  191. * when FEATURE_NAPI has *not* been defined.
  192. */
  193. #define NAPI_DEBUG(fmt, ...) /* NO-OP */
  194. static inline int hif_napi_create(struct hif_opaque_softc *hif,
  195. uint8_t pipe_id,
  196. int (*poll)(struct napi_struct *, int),
  197. int budget,
  198. int scale,
  199. uint8_t flags)
  200. { return -EPERM; }
  201. static inline int hif_napi_destroy(struct hif_opaque_softc *hif,
  202. uint8_t id,
  203. int force)
  204. { return -EPERM; }
  205. static inline struct qca_napi_data *hif_napi_get_all(
  206. struct hif_opaque_softc *hif)
  207. { return NULL; }
  208. static inline int hif_napi_event(struct hif_opaque_softc *hif,
  209. enum qca_napi_event event,
  210. void *data)
  211. { return -EPERM; }
  212. /* called from the ISR within hif, so, ce is known */
  213. static inline int hif_napi_enabled(struct hif_opaque_softc *hif, int ce)
  214. { return 0; }
  215. static inline bool hif_napi_created(struct hif_opaque_softc *hif, int ce)
  216. { return false; }
  217. /* called from hdd (napi_poll), using napi id as a selector */
  218. static inline void hif_napi_enable_irq(struct hif_opaque_softc *hif, int id)
  219. { return; }
  220. static inline bool hif_napi_schedule(struct hif_opaque_softc *hif, int ce_id)
  221. { return false; }
  222. static inline int hif_napi_poll(struct napi_struct *napi, int budget)
  223. { return -EPERM; }
  224. /**
  225. * hif_update_napi_max_poll_time() - updates NAPI max poll time
  226. * @ce_state: ce state
  227. * @ce_id: Copy engine ID
  228. * @cpu_id: cpu id
  229. *
  230. * This API updates NAPI max poll time per CE per SPU.
  231. *
  232. * Return: void
  233. */
  234. static inline void hif_update_napi_max_poll_time(struct CE_state *ce_state,
  235. int ce_id,
  236. int cpu_id)
  237. { return; }
  238. #endif /* FEATURE_NAPI */
  239. #if defined(HIF_IRQ_AFFINITY) && defined(FEATURE_NAPI)
  240. /*
  241. * prototype signatures
  242. */
  243. int hif_napi_cpu_init(struct hif_opaque_softc *hif);
  244. int hif_napi_cpu_deinit(struct hif_opaque_softc *hif);
  245. int hif_napi_cpu_migrate(struct qca_napi_data *napid, int cpu, int action);
  246. int hif_napi_serialize(struct hif_opaque_softc *hif, int is_on);
  247. int hif_napi_cpu_blacklist(struct qca_napi_data *napid,
  248. enum qca_blacklist_op op);
  249. /* not directly related to irq affinity, but oh well */
  250. void hif_napi_stats(struct qca_napi_data *napid);
  251. void hif_napi_update_yield_stats(struct CE_state *ce_state,
  252. bool time_limit_reached,
  253. bool rxpkt_thresh_reached);
  254. #else
  255. struct qca_napi_data;
  256. static inline int hif_napi_cpu_init(struct hif_opaque_softc *hif)
  257. { return 0; }
  258. static inline int hif_napi_cpu_deinit(struct hif_opaque_softc *hif)
  259. { return 0; }
  260. static inline int hif_napi_cpu_migrate(struct qca_napi_data *napid, int cpu,
  261. int action)
  262. { return 0; }
  263. static inline int hif_napi_serialize(struct hif_opaque_softc *hif, int is_on)
  264. { return -EPERM; }
  265. static inline void hif_napi_stats(struct qca_napi_data *napid) { }
  266. static inline void hif_napi_update_yield_stats(struct CE_state *ce_state,
  267. bool time_limit_reached,
  268. bool rxpkt_thresh_reached) { }
  269. static inline int hif_napi_cpu_blacklist(struct qca_napi_data *napid,
  270. enum qca_blacklist_op op)
  271. { return 0; }
  272. #endif /* HIF_IRQ_AFFINITY */
  273. #endif /* __HIF_NAPI_H__ */