hif_exec.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /*
  2. * Copyright (c) 2017-2019 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_EXEC_H__
  19. #define __HIF_EXEC_H__
  20. #include <hif.h>
  21. #include <linux/cpumask.h>
  22. /*Number of buckets for latency*/
  23. #define HIF_SCHED_LATENCY_BUCKETS 8
  24. /*Buckets for latency between 0 to 2 ms*/
  25. #define HIF_SCHED_LATENCY_BUCKET_0_2 2
  26. /*Buckets for latency between 3 to 10 ms*/
  27. #define HIF_SCHED_LATENCY_BUCKET_3_10 10
  28. /*Buckets for latency between 11 to 20 ms*/
  29. #define HIF_SCHED_LATENCY_BUCKET_11_20 20
  30. /*Buckets for latency between 21 to 50 ms*/
  31. #define HIF_SCHED_LATENCY_BUCKET_21_50 50
  32. /*Buckets for latency between 50 to 100 ms*/
  33. #define HIF_SCHED_LATENCY_BUCKET_51_100 100
  34. /*Buckets for latency between 100 to 250 ms*/
  35. #define HIF_SCHED_LATENCY_BUCKET_101_250 250
  36. /*Buckets for latency between 250 to 500 ms*/
  37. #define HIF_SCHED_LATENCY_BUCKET_251_500 500
  38. struct hif_exec_context;
  39. struct hif_execution_ops {
  40. char *context_type;
  41. void (*schedule)(struct hif_exec_context *);
  42. void (*reschedule)(struct hif_exec_context *);
  43. void (*kill)(struct hif_exec_context *);
  44. };
  45. /**
  46. * hif_exec_context: only ever allocated as a subtype eg.
  47. * hif_tasklet_exec_context
  48. *
  49. * @context: context for the handler function to use.
  50. * @evt_hist: a pointer to the DP event history
  51. * @context_name: a pointer to a const string for debugging.
  52. * this should help whenever there could be ambiguity
  53. * in what type of context the void* context points to
  54. * @irq: irq handle coresponding to hw block
  55. * @os_irq: irq handle for irq_afinity
  56. * @cpu: the cpu this context should be affined to
  57. * @work_complete: Function call called when leaving the execution context to
  58. * determine if this context should reschedule or wait for an interrupt.
  59. * This function may be used as a hook for post processing.
  60. *
  61. * @sched_latency_stats: schdule latency stats for different latency buckets
  62. * @tstamp: timestamp when napi poll happens
  63. * @irq_disable: called before scheduling the context.
  64. * @irq_enable: called when the context leaves polling mode
  65. * @irq_name: pointer to function to return irq name/string mapped to irq number
  66. * @irq_lock: spinlock used while enabling/disabling IRQs
  67. * @type: type of execution context
  68. * @poll_start_time: hif napi poll start time in nanoseconds
  69. * @force_break: flag to indicate if HIF execution context was forced to return
  70. * to HIF. This means there is more work to be done. Hence do not
  71. * call napi_complete.
  72. */
  73. struct hif_exec_context {
  74. struct hif_execution_ops *sched_ops;
  75. struct hif_opaque_softc *hif;
  76. uint32_t numirq;
  77. uint32_t irq[HIF_MAX_GRP_IRQ];
  78. uint32_t os_irq[HIF_MAX_GRP_IRQ];
  79. cpumask_t cpumask;
  80. uint32_t grp_id;
  81. uint32_t scale_bin_shift;
  82. const char *context_name;
  83. void *context;
  84. ext_intr_handler handler;
  85. struct hif_event_history *evt_hist;
  86. bool (*work_complete)(struct hif_exec_context *, int work_done);
  87. void (*irq_enable)(struct hif_exec_context *);
  88. void (*irq_disable)(struct hif_exec_context *);
  89. const char* (*irq_name)(int irq_no);
  90. uint64_t sched_latency_stats[HIF_SCHED_LATENCY_BUCKETS];
  91. uint64_t tstamp;
  92. uint8_t cpu;
  93. struct qca_napi_stat stats[NR_CPUS];
  94. bool inited;
  95. bool configured;
  96. bool irq_requested;
  97. bool irq_enabled;
  98. qdf_spinlock_t irq_lock;
  99. enum hif_exec_type type;
  100. unsigned long long poll_start_time;
  101. bool force_break;
  102. };
  103. /**
  104. * struct hif_tasklet_exec_context - exec_context for tasklets
  105. * @exec_ctx: inherited data type
  106. * @tasklet: tasklet structure for scheduling
  107. */
  108. struct hif_tasklet_exec_context {
  109. struct hif_exec_context exec_ctx;
  110. struct tasklet_struct tasklet;
  111. };
  112. /**
  113. * struct hif_napi_exec_context - exec_context for NAPI
  114. * @exec_ctx: inherited data type
  115. * @netdev: dummy net device associated with the napi context
  116. * @napi: napi structure used in scheduling
  117. */
  118. struct hif_napi_exec_context {
  119. struct hif_exec_context exec_ctx;
  120. struct net_device netdev; /* dummy net_dev */
  121. struct napi_struct napi;
  122. };
  123. static inline struct hif_napi_exec_context*
  124. hif_exec_get_napi(struct hif_exec_context *ctx)
  125. {
  126. return (struct hif_napi_exec_context *) ctx;
  127. }
  128. static inline struct hif_tasklet_exec_context*
  129. hif_exec_get_tasklet(struct hif_exec_context *ctx)
  130. {
  131. return (struct hif_tasklet_exec_context *) ctx;
  132. }
  133. struct hif_exec_context *hif_exec_create(enum hif_exec_type type,
  134. uint32_t scale);
  135. void hif_exec_destroy(struct hif_exec_context *ctx);
  136. int hif_grp_irq_configure(struct hif_softc *scn,
  137. struct hif_exec_context *hif_exec);
  138. irqreturn_t hif_ext_group_interrupt_handler(int irq, void *context);
  139. struct hif_exec_context *hif_exec_get_ctx(struct hif_opaque_softc *hif,
  140. uint8_t id);
  141. void hif_exec_kill(struct hif_opaque_softc *scn);
  142. #endif