xref: /wlan-dirver/qca-wifi-host-cmn/hif/src/hif_exec.h (revision 503663c6daafffe652fa360bde17243568cd6d2a)
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  * @evt_hist: a pointer to the DP event history
57  * @context_name: a pointer to a const string for debugging.
58  *		this should help whenever there could be ambiguity
59  *		in what type of context the void* context points to
60  * @irq: irq handle coresponding to hw block
61  * @os_irq: irq handle for irq_afinity
62  * @cpu: the cpu this context should be affined to
63  * @work_complete: Function call called when leaving the execution context to
64  *	determine if this context should reschedule or wait for an interrupt.
65  *	This function may be used as a hook for post processing.
66  *
67  * @sched_latency_stats: schdule latency stats for different latency buckets
68  * @tstamp: timestamp when napi poll happens
69  * @irq_disable: called before scheduling the context.
70  * @irq_enable: called when the context leaves polling mode
71  * @irq_name: pointer to function to return irq name/string mapped to irq number
72  * @irq_lock: spinlock used while enabling/disabling IRQs
73  * @type: type of execution context
74  * @poll_start_time: hif napi poll start time in nanoseconds
75  * @force_break: flag to indicate if HIF execution context was forced to return
76  *		 to HIF. This means there is more work to be done. Hence do not
77  *		 call napi_complete.
78  */
79 struct hif_exec_context {
80 	struct hif_execution_ops *sched_ops;
81 	struct hif_opaque_softc *hif;
82 	uint32_t numirq;
83 	uint32_t irq[HIF_MAX_GRP_IRQ];
84 	uint32_t os_irq[HIF_MAX_GRP_IRQ];
85 	cpumask_t cpumask;
86 	uint32_t grp_id;
87 	uint32_t scale_bin_shift;
88 	const char *context_name;
89 	void *context;
90 	ext_intr_handler handler;
91 	struct hif_event_history *evt_hist;
92 
93 	bool (*work_complete)(struct hif_exec_context *, int work_done);
94 	void (*irq_enable)(struct hif_exec_context *);
95 	void (*irq_disable)(struct hif_exec_context *);
96 	const char* (*irq_name)(int irq_no);
97 	uint64_t sched_latency_stats[HIF_SCHED_LATENCY_BUCKETS];
98 	uint64_t tstamp;
99 
100 	uint8_t cpu;
101 	struct qca_napi_stat stats[NR_CPUS];
102 	bool inited;
103 	bool configured;
104 	bool irq_requested;
105 	bool irq_enabled;
106 	qdf_spinlock_t irq_lock;
107 	enum hif_exec_type type;
108 	unsigned long long poll_start_time;
109 	bool force_break;
110 };
111 
112 /**
113  * struct hif_tasklet_exec_context - exec_context for tasklets
114  * @exec_ctx: inherited data type
115  * @tasklet: tasklet structure for scheduling
116  */
117 struct hif_tasklet_exec_context {
118 	struct hif_exec_context exec_ctx;
119 	struct tasklet_struct tasklet;
120 };
121 
122 /**
123  * struct hif_napi_exec_context - exec_context for NAPI
124  * @exec_ctx: inherited data type
125  * @netdev: dummy net device associated with the napi context
126  * @napi: napi structure used in scheduling
127  */
128 struct hif_napi_exec_context {
129 	struct hif_exec_context exec_ctx;
130 	struct net_device    netdev; /* dummy net_dev */
131 	struct napi_struct   napi;
132 };
133 
134 static inline struct hif_napi_exec_context*
135 	hif_exec_get_napi(struct hif_exec_context *ctx)
136 {
137 	return (struct hif_napi_exec_context *) ctx;
138 }
139 
140 static inline struct hif_tasklet_exec_context*
141 	hif_exec_get_tasklet(struct hif_exec_context *ctx)
142 {
143 	return (struct hif_tasklet_exec_context *) ctx;
144 }
145 
146 struct hif_exec_context *hif_exec_create(enum hif_exec_type type,
147 						uint32_t scale);
148 
149 void hif_exec_destroy(struct hif_exec_context *ctx);
150 
151 int hif_grp_irq_configure(struct hif_softc *scn,
152 			  struct hif_exec_context *hif_exec);
153 irqreturn_t hif_ext_group_interrupt_handler(int irq, void *context);
154 
155 struct hif_exec_context *hif_exec_get_ctx(struct hif_opaque_softc *hif,
156 					  uint8_t id);
157 void hif_exec_kill(struct hif_opaque_softc *scn);
158 #endif
159 
160