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