xref: /wlan-dirver/qca-wifi-host-cmn/hif/src/hif_exec.h (revision 1397a33f48ea6455be40871470b286e535820eb8)
1 /*
2  * Copyright (c) 2017-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 
19 #ifndef __HIF_EXEC_H__
20 #define __HIF_EXEC_H__
21 
22 #include <hif.h>
23 #include <linux/cpumask.h>
24 
25 struct hif_exec_context;
26 
27 struct hif_execution_ops {
28 	char *context_type;
29 	void (*schedule)(struct hif_exec_context *);
30 	void (*reschedule)(struct hif_exec_context *);
31 	void (*kill)(struct hif_exec_context *);
32 };
33 
34 /**
35  * hif_exec_context: only ever allocated as a subtype eg.
36  *					hif_tasklet_exec_context
37  *
38  * @context: context for the handler function to use.
39  * @context_name: a pointer to a const string for debugging.
40  *		this should help whenever there could be ambiguity
41  *		in what type of context the void* context points to
42  * @irq: irq handle coresponding to hw block
43  * @os_irq: irq handle for irq_afinity
44  * @cpu: the cpu this context should be affined to
45  * @work_complete: Function call called when leaving the execution context to
46  *	determine if this context should reschedule or wait for an interrupt.
47  *	This function may be used as a hook for post processing.
48  *
49  * @irq_disable: called before scheduling the context.
50  * @irq_enable: called when the context leaves polling mode
51  */
52 struct hif_exec_context {
53 	struct hif_execution_ops *sched_ops;
54 	struct hif_opaque_softc *hif;
55 	uint32_t numirq;
56 	uint32_t irq[HIF_MAX_GRP_IRQ];
57 	uint32_t os_irq[HIF_MAX_GRP_IRQ];
58 	cpumask_t cpumask;
59 	uint32_t grp_id;
60 	uint32_t scale_bin_shift;
61 	const char *context_name;
62 	void *context;
63 	ext_intr_handler handler;
64 
65 	bool (*work_complete)(struct hif_exec_context *, int work_done);
66 	void (*irq_enable)(struct hif_exec_context *);
67 	void (*irq_disable)(struct hif_exec_context *);
68 
69 	uint8_t cpu;
70 	struct qca_napi_stat stats[NR_CPUS];
71 	bool inited;
72 	bool configured;
73 	bool irq_requested;
74 	bool irq_enabled;
75 	qdf_spinlock_t irq_lock;
76 };
77 
78 /**
79  * struct hif_tasklet_exec_context - exec_context for tasklets
80  * @exec_ctx: inherited data type
81  * @tasklet: tasklet structure for scheduling
82  */
83 struct hif_tasklet_exec_context {
84 	struct hif_exec_context exec_ctx;
85 	struct tasklet_struct tasklet;
86 };
87 
88 /**
89  * struct hif_napi_exec_context - exec_context for tasklets
90  * @exec_ctx: inherited data type
91  * @netdev: dummy net device associated with the napi context
92  * @napi: napi structure used in scheduling
93  */
94 struct hif_napi_exec_context {
95 	struct hif_exec_context exec_ctx;
96 	struct net_device    netdev; /* dummy net_dev */
97 	struct napi_struct   napi;
98 };
99 
100 static inline struct hif_napi_exec_context*
101 	hif_exec_get_napi(struct hif_exec_context *ctx)
102 {
103 	return (struct hif_napi_exec_context *) ctx;
104 }
105 
106 static inline struct hif_tasklet_exec_context*
107 	hif_exec_get_tasklet(struct hif_exec_context *ctx)
108 {
109 	return (struct hif_tasklet_exec_context *) ctx;
110 }
111 
112 struct hif_exec_context *hif_exec_create(enum hif_exec_type type,
113 						uint32_t scale);
114 
115 void hif_exec_destroy(struct hif_exec_context *ctx);
116 
117 int hif_grp_irq_configure(struct hif_softc *scn,
118 			  struct hif_exec_context *hif_exec);
119 irqreturn_t hif_ext_group_interrupt_handler(int irq, void *context);
120 
121 struct hif_exec_context *hif_exec_get_ctx(struct hif_opaque_softc *hif,
122 					  uint8_t id);
123 void hif_exec_kill(struct hif_opaque_softc *scn);
124 
125 #endif
126 
127