1*5113495bSYour Name /*
2*5113495bSYour Name * Copyright (c) 2015-2021 The Linux Foundation. All rights reserved.
3*5113495bSYour Name * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved.
4*5113495bSYour Name *
5*5113495bSYour Name * Permission to use, copy, modify, and/or distribute this software for
6*5113495bSYour Name * any purpose with or without fee is hereby granted, provided that the
7*5113495bSYour Name * above copyright notice and this permission notice appear in all
8*5113495bSYour Name * copies.
9*5113495bSYour Name *
10*5113495bSYour Name * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
11*5113495bSYour Name * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
12*5113495bSYour Name * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
13*5113495bSYour Name * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
14*5113495bSYour Name * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
15*5113495bSYour Name * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
16*5113495bSYour Name * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17*5113495bSYour Name * PERFORMANCE OF THIS SOFTWARE.
18*5113495bSYour Name */
19*5113495bSYour Name
20*5113495bSYour Name /**
21*5113495bSYour Name * DOC: hif_irq_affinity.c
22*5113495bSYour Name *
23*5113495bSYour Name * This irq affinity implementation is os dependent, so this can be treated as
24*5113495bSYour Name * an abstraction layer... Should this be moved into a /linux folder?
25*5113495bSYour Name */
26*5113495bSYour Name
27*5113495bSYour Name #include <linux/string.h> /* memset */
28*5113495bSYour Name
29*5113495bSYour Name /* Linux headers */
30*5113495bSYour Name #include <linux/cpumask.h>
31*5113495bSYour Name #include <linux/cpufreq.h>
32*5113495bSYour Name #include <linux/cpu.h>
33*5113495bSYour Name #include <linux/topology.h>
34*5113495bSYour Name #include <linux/interrupt.h>
35*5113495bSYour Name #include <linux/pm.h>
36*5113495bSYour Name #include <hif_napi.h>
37*5113495bSYour Name #include <hif_irq_affinity.h>
38*5113495bSYour Name #include <hif_exec.h>
39*5113495bSYour Name #include <hif_main.h>
40*5113495bSYour Name #include "qdf_irq.h"
41*5113495bSYour Name
42*5113495bSYour Name #if defined(FEATURE_NAPI_DEBUG) && defined(HIF_IRQ_AFFINITY)
43*5113495bSYour Name /*
44*5113495bSYour Name * Local functions
45*5113495bSYour Name * - no argument checks, all internal/trusted callers
46*5113495bSYour Name */
hnc_dump_cpus(struct qca_napi_data * napid)47*5113495bSYour Name static void hnc_dump_cpus(struct qca_napi_data *napid)
48*5113495bSYour Name {
49*5113495bSYour Name hif_napi_stats(napid);
50*5113495bSYour Name }
51*5113495bSYour Name #else
hnc_dump_cpus(struct qca_napi_data * napid)52*5113495bSYour Name static void hnc_dump_cpus(struct qca_napi_data *napid) { /* no-op */ };
53*5113495bSYour Name #endif /* FEATURE_NAPI_DEBUG */
54*5113495bSYour Name
55*5113495bSYour Name #ifdef HIF_IRQ_AFFINITY
56*5113495bSYour Name /**
57*5113495bSYour Name * hif_exec_event() - reacts to events that impact irq affinity
58*5113495bSYour Name * @hif_ctx: pointer to hif context
59*5113495bSYour Name * @event: event that has been detected
60*5113495bSYour Name * @data: more data regarding the event
61*5113495bSYour Name *
62*5113495bSYour Name * Description:
63*5113495bSYour Name * This function handles two types of events:
64*5113495bSYour Name * 1- Events that change the state of NAPI (enabled/disabled):
65*5113495bSYour Name * {NAPI_EVT_INI_FILE, NAPI_EVT_CMD_STATE}
66*5113495bSYour Name * The state is retrievable by "hdd_napi_enabled(-1)"
67*5113495bSYour Name * - NAPI will be on if either INI file is on and it has not been disabled
68*5113495bSYour Name * by a subsequent vendor CMD,
69*5113495bSYour Name * or it has been enabled by a vendor CMD.
70*5113495bSYour Name * 2- Events that change the CPU affinity of a NAPI instance/IRQ:
71*5113495bSYour Name * {NAPI_EVT_TPUT_STATE, NAPI_EVT_CPU_STATE}
72*5113495bSYour Name * - NAPI will support a throughput mode (HI/LO), kept at napid->napi_mode
73*5113495bSYour Name * - NAPI will switch throughput mode based on hdd_napi_throughput_policy()
74*5113495bSYour Name * - In LO tput mode, NAPI will yield control if its interrupts to the system
75*5113495bSYour Name * management functions. However in HI throughput mode, NAPI will actively
76*5113495bSYour Name * manage its interrupts/instances (by trying to disperse them out to
77*5113495bSYour Name * separate performance cores).
78*5113495bSYour Name * - CPU eligibility is kept up-to-date by NAPI_EVT_CPU_STATE events.
79*5113495bSYour Name *
80*5113495bSYour Name * + In some cases (roaming peer management is the only case so far), a
81*5113495bSYour Name * a client can trigger a "SERIALIZE" event. Basically, this means that the
82*5113495bSYour Name * users is asking NAPI to go into a truly single execution context state.
83*5113495bSYour Name * So, NAPI indicates to msm-irqbalancer that it wants to be denylisted,
84*5113495bSYour Name * (if called for the first time) and then moves all IRQs (for NAPI
85*5113495bSYour Name * instances) to be collapsed to a single core. If called multiple times,
86*5113495bSYour Name * it will just re-collapse the CPUs. This is because denylist-on() API
87*5113495bSYour Name * is reference-counted, and because the API has already been called.
88*5113495bSYour Name *
89*5113495bSYour Name * Such a user, should call "DESERIALIZE" (NORMAL) event, to set NAPI to go
90*5113495bSYour Name * to its "normal" operation. Optionally, they can give a timeout value (in
91*5113495bSYour Name * multiples of BusBandwidthCheckPeriod -- 100 msecs by default). In this
92*5113495bSYour Name * case, NAPI will just set the current throughput state to uninitialized
93*5113495bSYour Name * and set the delay period. Once policy handler is called, it would skip
94*5113495bSYour Name * applying the policy delay period times, and otherwise apply the policy.
95*5113495bSYour Name *
96*5113495bSYour Name * Return:
97*5113495bSYour Name * < 0: some error
98*5113495bSYour Name * = 0: event handled successfully
99*5113495bSYour Name */
hif_exec_event(struct hif_opaque_softc * hif_ctx,enum qca_napi_event event,void * data)100*5113495bSYour Name int hif_exec_event(struct hif_opaque_softc *hif_ctx, enum qca_napi_event event,
101*5113495bSYour Name void *data)
102*5113495bSYour Name {
103*5113495bSYour Name int rc = 0;
104*5113495bSYour Name uint32_t prev_state;
105*5113495bSYour Name struct hif_softc *hif = HIF_GET_SOFTC(hif_ctx);
106*5113495bSYour Name struct qca_napi_data *napid = &(hif->napi_data);
107*5113495bSYour Name enum qca_napi_tput_state tput_mode = QCA_NAPI_TPUT_UNINITIALIZED;
108*5113495bSYour Name enum {
109*5113495bSYour Name DENYLIST_NOT_PENDING,
110*5113495bSYour Name DENYLIST_ON_PENDING,
111*5113495bSYour Name DENYLIST_OFF_PENDING
112*5113495bSYour Name } denylist_pending = DENYLIST_NOT_PENDING;
113*5113495bSYour Name
114*5113495bSYour Name NAPI_DEBUG("%s: -->(event=%d, aux=%pK)", __func__, event, data);
115*5113495bSYour Name
116*5113495bSYour Name qdf_spin_lock_bh(&(napid->lock));
117*5113495bSYour Name prev_state = napid->state;
118*5113495bSYour Name switch (event) {
119*5113495bSYour Name case NAPI_EVT_INI_FILE:
120*5113495bSYour Name case NAPI_EVT_CMD_STATE:
121*5113495bSYour Name case NAPI_EVT_INT_STATE:
122*5113495bSYour Name /* deprecated */
123*5113495bSYour Name break;
124*5113495bSYour Name
125*5113495bSYour Name case NAPI_EVT_CPU_STATE: {
126*5113495bSYour Name int cpu = ((unsigned long int)data >> 16);
127*5113495bSYour Name int val = ((unsigned long int)data & 0x0ff);
128*5113495bSYour Name
129*5113495bSYour Name NAPI_DEBUG("%s: evt=CPU_STATE on CPU %d value=%d",
130*5113495bSYour Name __func__, cpu, val);
131*5113495bSYour Name
132*5113495bSYour Name /* state has already been set by hnc_cpu_notify_cb */
133*5113495bSYour Name if ((val == QCA_NAPI_CPU_DOWN) &&
134*5113495bSYour Name (napid->napi_mode == QCA_NAPI_TPUT_HI) && /* we manage */
135*5113495bSYour Name (napid->napi_cpu[cpu].napis != 0)) {
136*5113495bSYour Name NAPI_DEBUG("%s: Migrating NAPIs out of cpu %d",
137*5113495bSYour Name __func__, cpu);
138*5113495bSYour Name rc = hif_exec_cpu_migrate(napid,
139*5113495bSYour Name cpu,
140*5113495bSYour Name HNC_ACT_RELOCATE);
141*5113495bSYour Name napid->napi_cpu[cpu].napis = 0;
142*5113495bSYour Name }
143*5113495bSYour Name /* in QCA_NAPI_TPUT_LO case, napis MUST == 0 */
144*5113495bSYour Name break;
145*5113495bSYour Name }
146*5113495bSYour Name
147*5113495bSYour Name case NAPI_EVT_TPUT_STATE: {
148*5113495bSYour Name tput_mode = (enum qca_napi_tput_state)data;
149*5113495bSYour Name if (tput_mode == QCA_NAPI_TPUT_LO) {
150*5113495bSYour Name /* from TPUT_HI -> TPUT_LO */
151*5113495bSYour Name NAPI_DEBUG("%s: Moving to napi_tput_LO state",
152*5113495bSYour Name __func__);
153*5113495bSYour Name denylist_pending = DENYLIST_OFF_PENDING;
154*5113495bSYour Name /*
155*5113495bSYour Name * Ideally we should "collapse" interrupts here, since
156*5113495bSYour Name * we are "dispersing" interrupts in the "else" case.
157*5113495bSYour Name * This allows the possibility that our interrupts may
158*5113495bSYour Name * still be on the perf cluster the next time we enter
159*5113495bSYour Name * high tput mode. However, the irq_balancer is free
160*5113495bSYour Name * to move our interrupts to power cluster once
161*5113495bSYour Name * denylisting has been turned off in the "else" case.
162*5113495bSYour Name */
163*5113495bSYour Name } else {
164*5113495bSYour Name /* from TPUT_LO -> TPUT->HI */
165*5113495bSYour Name NAPI_DEBUG("%s: Moving to napi_tput_HI state",
166*5113495bSYour Name __func__);
167*5113495bSYour Name rc = hif_exec_cpu_migrate(napid,
168*5113495bSYour Name HNC_ANY_CPU,
169*5113495bSYour Name HNC_ACT_DISPERSE);
170*5113495bSYour Name
171*5113495bSYour Name denylist_pending = DENYLIST_ON_PENDING;
172*5113495bSYour Name }
173*5113495bSYour Name napid->napi_mode = tput_mode;
174*5113495bSYour Name break;
175*5113495bSYour Name }
176*5113495bSYour Name
177*5113495bSYour Name case NAPI_EVT_USR_SERIAL: {
178*5113495bSYour Name unsigned long users = (unsigned long)data;
179*5113495bSYour Name
180*5113495bSYour Name NAPI_DEBUG("%s: User forced SERIALIZATION; users=%ld",
181*5113495bSYour Name __func__, users);
182*5113495bSYour Name
183*5113495bSYour Name rc = hif_exec_cpu_migrate(napid,
184*5113495bSYour Name HNC_ANY_CPU,
185*5113495bSYour Name HNC_ACT_COLLAPSE);
186*5113495bSYour Name if ((users == 0) && (rc == 0))
187*5113495bSYour Name denylist_pending = DENYLIST_ON_PENDING;
188*5113495bSYour Name break;
189*5113495bSYour Name }
190*5113495bSYour Name case NAPI_EVT_USR_NORMAL: {
191*5113495bSYour Name NAPI_DEBUG("%s: User forced DE-SERIALIZATION", __func__);
192*5113495bSYour Name if (!napid->user_cpu_affin_mask)
193*5113495bSYour Name denylist_pending = DENYLIST_OFF_PENDING;
194*5113495bSYour Name /*
195*5113495bSYour Name * Deserialization timeout is handled at hdd layer;
196*5113495bSYour Name * just mark current mode to uninitialized to ensure
197*5113495bSYour Name * it will be set when the delay is over
198*5113495bSYour Name */
199*5113495bSYour Name napid->napi_mode = QCA_NAPI_TPUT_UNINITIALIZED;
200*5113495bSYour Name break;
201*5113495bSYour Name }
202*5113495bSYour Name default: {
203*5113495bSYour Name hif_err("Unknown event: %d (data=0x%0lx)",
204*5113495bSYour Name event, (unsigned long) data);
205*5113495bSYour Name break;
206*5113495bSYour Name } /* default */
207*5113495bSYour Name }; /* switch */
208*5113495bSYour Name
209*5113495bSYour Name
210*5113495bSYour Name switch (denylist_pending) {
211*5113495bSYour Name case DENYLIST_ON_PENDING:
212*5113495bSYour Name /* assume the control of WLAN IRQs */
213*5113495bSYour Name hif_napi_cpu_denylist(napid, DENYLIST_ON);
214*5113495bSYour Name break;
215*5113495bSYour Name case DENYLIST_OFF_PENDING:
216*5113495bSYour Name /* yield the control of WLAN IRQs */
217*5113495bSYour Name hif_napi_cpu_denylist(napid, DENYLIST_OFF);
218*5113495bSYour Name break;
219*5113495bSYour Name default: /* nothing to do */
220*5113495bSYour Name break;
221*5113495bSYour Name } /* switch denylist_pending */
222*5113495bSYour Name
223*5113495bSYour Name qdf_spin_unlock_bh(&(napid->lock));
224*5113495bSYour Name
225*5113495bSYour Name NAPI_DEBUG("<--[rc=%d]", rc);
226*5113495bSYour Name return rc;
227*5113495bSYour Name }
228*5113495bSYour Name
229*5113495bSYour Name #endif
230*5113495bSYour Name
231*5113495bSYour Name /**
232*5113495bSYour Name * hncm_exec_migrate_to() - migrates a NAPI to a CPU
233*5113495bSYour Name * @napid: pointer to NAPI block
234*5113495bSYour Name * @ctx_id: CE_id of the NAPI instance
235*5113495bSYour Name * @didx: index in the CPU topology table for the CPU to migrate to
236*5113495bSYour Name *
237*5113495bSYour Name * Migrates NAPI (identified by the CE_id) to the destination core
238*5113495bSYour Name * Updates the napi_map of the destination entry
239*5113495bSYour Name *
240*5113495bSYour Name * Return:
241*5113495bSYour Name * =0 : success
242*5113495bSYour Name * <0 : error
243*5113495bSYour Name */
hncm_exec_migrate_to(struct qca_napi_data * napid,uint8_t ctx_id,int didx)244*5113495bSYour Name static int hncm_exec_migrate_to(struct qca_napi_data *napid, uint8_t ctx_id,
245*5113495bSYour Name int didx)
246*5113495bSYour Name {
247*5113495bSYour Name struct hif_exec_context *exec_ctx;
248*5113495bSYour Name struct qdf_cpu_mask *cpumask;
249*5113495bSYour Name int rc = 0;
250*5113495bSYour Name int status = 0;
251*5113495bSYour Name int ind;
252*5113495bSYour Name
253*5113495bSYour Name NAPI_DEBUG("-->%s(napi_cd=%d, didx=%d)", __func__, ctx_id, didx);
254*5113495bSYour Name
255*5113495bSYour Name exec_ctx = hif_exec_get_ctx(&napid->hif_softc->osc, ctx_id);
256*5113495bSYour Name if (!exec_ctx)
257*5113495bSYour Name return -EINVAL;
258*5113495bSYour Name
259*5113495bSYour Name exec_ctx->cpumask.bits[0] = (1 << didx);
260*5113495bSYour Name
261*5113495bSYour Name for (ind = 0; ind < exec_ctx->numirq; ind++) {
262*5113495bSYour Name if (exec_ctx->os_irq[ind]) {
263*5113495bSYour Name qdf_dev_modify_irq_status(exec_ctx->os_irq[ind],
264*5113495bSYour Name QDF_IRQ_NO_BALANCING, 0);
265*5113495bSYour Name cpumask = (struct qdf_cpu_mask *)&exec_ctx->cpumask;
266*5113495bSYour Name rc = qdf_dev_set_irq_affinity(exec_ctx->os_irq[ind],
267*5113495bSYour Name cpumask);
268*5113495bSYour Name if (rc)
269*5113495bSYour Name status = rc;
270*5113495bSYour Name }
271*5113495bSYour Name }
272*5113495bSYour Name
273*5113495bSYour Name /* unmark the napis bitmap in the cpu table */
274*5113495bSYour Name napid->napi_cpu[exec_ctx->cpu].napis &= ~(0x01 << ctx_id);
275*5113495bSYour Name /* mark the napis bitmap for the new designated cpu */
276*5113495bSYour Name napid->napi_cpu[didx].napis |= (0x01 << ctx_id);
277*5113495bSYour Name exec_ctx->cpu = didx;
278*5113495bSYour Name
279*5113495bSYour Name NAPI_DEBUG("<--%s[%d]", __func__, rc);
280*5113495bSYour Name return status;
281*5113495bSYour Name }
282*5113495bSYour Name
283*5113495bSYour Name /**
284*5113495bSYour Name * hncm_dest_cpu() - finds a destination CPU for NAPI
285*5113495bSYour Name * @napid: pointer to NAPI block
286*5113495bSYour Name * @act : RELOCATE | COLLAPSE | DISPERSE
287*5113495bSYour Name *
288*5113495bSYour Name * Finds the designated destination for the next IRQ.
289*5113495bSYour Name * RELOCATE: translated to either COLLAPSE or DISPERSE based
290*5113495bSYour Name * on napid->napi_mode (throughput state)
291*5113495bSYour Name * COLLAPSE: All have the same destination: the first online CPU in lilcl
292*5113495bSYour Name * DISPERSE: One of the CPU in bigcl, which has the smallest number of
293*5113495bSYour Name * NAPIs on it
294*5113495bSYour Name *
295*5113495bSYour Name * Return: >=0 : index in the cpu topology table
296*5113495bSYour Name * : < 0 : error
297*5113495bSYour Name */
hncm_dest_cpu(struct qca_napi_data * napid,int act)298*5113495bSYour Name static int hncm_dest_cpu(struct qca_napi_data *napid, int act)
299*5113495bSYour Name {
300*5113495bSYour Name int destidx = -1;
301*5113495bSYour Name int head, i;
302*5113495bSYour Name
303*5113495bSYour Name NAPI_DEBUG("-->%s(act=%d)", __func__, act);
304*5113495bSYour Name if (act == HNC_ACT_RELOCATE) {
305*5113495bSYour Name if (napid->napi_mode == QCA_NAPI_TPUT_LO)
306*5113495bSYour Name act = HNC_ACT_COLLAPSE;
307*5113495bSYour Name else
308*5113495bSYour Name act = HNC_ACT_DISPERSE;
309*5113495bSYour Name NAPI_DEBUG("%s: act changed from HNC_ACT_RELOCATE to %d",
310*5113495bSYour Name __func__, act);
311*5113495bSYour Name }
312*5113495bSYour Name if (act == HNC_ACT_COLLAPSE) {
313*5113495bSYour Name head = i = napid->lilcl_head;
314*5113495bSYour Name retry_collapse:
315*5113495bSYour Name while (i >= 0) {
316*5113495bSYour Name if (napid->napi_cpu[i].state == QCA_NAPI_CPU_UP) {
317*5113495bSYour Name destidx = i;
318*5113495bSYour Name break;
319*5113495bSYour Name }
320*5113495bSYour Name i = napid->napi_cpu[i].cluster_nxt;
321*5113495bSYour Name }
322*5113495bSYour Name if ((destidx < 0) && (head == napid->lilcl_head)) {
323*5113495bSYour Name NAPI_DEBUG("%s: COLLAPSE: no lilcl dest, try bigcl",
324*5113495bSYour Name __func__);
325*5113495bSYour Name head = i = napid->bigcl_head;
326*5113495bSYour Name goto retry_collapse;
327*5113495bSYour Name }
328*5113495bSYour Name } else { /* HNC_ACT_DISPERSE */
329*5113495bSYour Name int smallest = 99; /* all 32 bits full */
330*5113495bSYour Name int smallidx = -1;
331*5113495bSYour Name
332*5113495bSYour Name head = i = napid->bigcl_head;
333*5113495bSYour Name retry_disperse:
334*5113495bSYour Name while (i >= 0) {
335*5113495bSYour Name if ((napid->napi_cpu[i].state == QCA_NAPI_CPU_UP) &&
336*5113495bSYour Name (hweight32(napid->napi_cpu[i].napis) <= smallest)) {
337*5113495bSYour Name smallest = napid->napi_cpu[i].napis;
338*5113495bSYour Name smallidx = i;
339*5113495bSYour Name }
340*5113495bSYour Name i = napid->napi_cpu[i].cluster_nxt;
341*5113495bSYour Name }
342*5113495bSYour Name destidx = smallidx;
343*5113495bSYour Name if ((destidx < 0) && (head == napid->bigcl_head)) {
344*5113495bSYour Name NAPI_DEBUG("%s: DISPERSE: no bigcl dest, try lilcl",
345*5113495bSYour Name __func__);
346*5113495bSYour Name head = i = napid->lilcl_head;
347*5113495bSYour Name goto retry_disperse;
348*5113495bSYour Name }
349*5113495bSYour Name }
350*5113495bSYour Name NAPI_DEBUG("<--%s[dest=%d]", __func__, destidx);
351*5113495bSYour Name return destidx;
352*5113495bSYour Name }
353*5113495bSYour Name
354*5113495bSYour Name /**
355*5113495bSYour Name * hif_exec_cpu_migrate() - migrate IRQs away
356*5113495bSYour Name * @napid: pointer to qca_napi_data structure
357*5113495bSYour Name * @cpu: -1: all CPUs <n> specific CPU
358*5113495bSYour Name * @action: COLLAPSE | DISPERSE
359*5113495bSYour Name *
360*5113495bSYour Name * Moves IRQs/NAPIs from specific or all CPUs (specified by @cpu) to eligible
361*5113495bSYour Name * cores. Eligible cores are:
362*5113495bSYour Name * act=COLLAPSE -> the first online core of the little cluster
363*5113495bSYour Name * act=DISPERSE -> separate cores of the big cluster, so that each core will
364*5113495bSYour Name * host minimum number of NAPIs/IRQs (napid->cpus[cpu].napis)
365*5113495bSYour Name *
366*5113495bSYour Name * Note that this function is called with a spinlock acquired already.
367*5113495bSYour Name *
368*5113495bSYour Name * Return: =0: success
369*5113495bSYour Name * <0: error
370*5113495bSYour Name */
hif_exec_cpu_migrate(struct qca_napi_data * napid,int cpu,int action)371*5113495bSYour Name int hif_exec_cpu_migrate(struct qca_napi_data *napid, int cpu, int action)
372*5113495bSYour Name {
373*5113495bSYour Name int rc = 0;
374*5113495bSYour Name struct qca_napi_cpu *cpup;
375*5113495bSYour Name int i, dind;
376*5113495bSYour Name uint32_t napis;
377*5113495bSYour Name
378*5113495bSYour Name
379*5113495bSYour Name NAPI_DEBUG("-->%s(.., cpu=%d, act=%d)",
380*5113495bSYour Name __func__, cpu, action);
381*5113495bSYour Name
382*5113495bSYour Name if (napid->exec_map == 0) {
383*5113495bSYour Name NAPI_DEBUG("%s: datapath contexts to disperse", __func__);
384*5113495bSYour Name goto hncm_return;
385*5113495bSYour Name }
386*5113495bSYour Name cpup = napid->napi_cpu;
387*5113495bSYour Name
388*5113495bSYour Name switch (action) {
389*5113495bSYour Name case HNC_ACT_RELOCATE:
390*5113495bSYour Name case HNC_ACT_DISPERSE:
391*5113495bSYour Name case HNC_ACT_COLLAPSE: {
392*5113495bSYour Name /* first find the src napi set */
393*5113495bSYour Name if (cpu == HNC_ANY_CPU)
394*5113495bSYour Name napis = napid->exec_map;
395*5113495bSYour Name else
396*5113495bSYour Name napis = cpup[cpu].napis;
397*5113495bSYour Name /* then clear the napi bitmap on each CPU */
398*5113495bSYour Name for (i = 0; i < NR_CPUS; i++)
399*5113495bSYour Name cpup[i].napis = 0;
400*5113495bSYour Name /* then for each of the NAPIs to disperse: */
401*5113495bSYour Name for (i = 0; i < HIF_MAX_GROUP; i++)
402*5113495bSYour Name if (napis & (1 << i)) {
403*5113495bSYour Name /* find a destination CPU */
404*5113495bSYour Name dind = hncm_dest_cpu(napid, action);
405*5113495bSYour Name if (dind >= 0) {
406*5113495bSYour Name rc = hncm_exec_migrate_to(napid, i,
407*5113495bSYour Name dind);
408*5113495bSYour Name } else {
409*5113495bSYour Name NAPI_DEBUG("No dest for NAPI ce%d", i);
410*5113495bSYour Name hnc_dump_cpus(napid);
411*5113495bSYour Name rc = -1;
412*5113495bSYour Name }
413*5113495bSYour Name }
414*5113495bSYour Name break;
415*5113495bSYour Name }
416*5113495bSYour Name default: {
417*5113495bSYour Name NAPI_DEBUG("%s: bad action: %d\n", __func__, action);
418*5113495bSYour Name QDF_BUG(0);
419*5113495bSYour Name break;
420*5113495bSYour Name }
421*5113495bSYour Name } /* switch action */
422*5113495bSYour Name
423*5113495bSYour Name hncm_return:
424*5113495bSYour Name hnc_dump_cpus(napid);
425*5113495bSYour Name return rc;
426*5113495bSYour Name }
427*5113495bSYour Name
428*5113495bSYour Name
429*5113495bSYour Name /**
430*5113495bSYour Name * hif_exec_dl_irq() - calls irq_modify_status to enable/disable denylisting
431*5113495bSYour Name * @napid: pointer to qca_napi_data structure
432*5113495bSYour Name * @dl_flag: denylist flag to enable/disable denylisting
433*5113495bSYour Name *
434*5113495bSYour Name * The function enables/disables denylisting for all the copy engine
435*5113495bSYour Name * interrupts on which NAPI is enabled.
436*5113495bSYour Name *
437*5113495bSYour Name * Return: None
438*5113495bSYour Name */
hif_exec_dl_irq(struct qca_napi_data * napid,bool dl_flag)439*5113495bSYour Name static inline void hif_exec_dl_irq(struct qca_napi_data *napid, bool dl_flag)
440*5113495bSYour Name {
441*5113495bSYour Name int i, j;
442*5113495bSYour Name struct hif_exec_context *exec_ctx;
443*5113495bSYour Name
444*5113495bSYour Name for (i = 0; i < HIF_MAX_GROUP; i++) {
445*5113495bSYour Name /* check if NAPI is enabled on the CE */
446*5113495bSYour Name if (!(napid->exec_map & (0x01 << i)))
447*5113495bSYour Name continue;
448*5113495bSYour Name
449*5113495bSYour Name /*double check that NAPI is allocated for the CE */
450*5113495bSYour Name exec_ctx = hif_exec_get_ctx(&napid->hif_softc->osc, i);
451*5113495bSYour Name if (!(exec_ctx))
452*5113495bSYour Name continue;
453*5113495bSYour Name
454*5113495bSYour Name if (dl_flag == true)
455*5113495bSYour Name for (j = 0; j < exec_ctx->numirq; j++)
456*5113495bSYour Name qdf_dev_modify_irq_status(exec_ctx->os_irq[j],
457*5113495bSYour Name 0,
458*5113495bSYour Name QDF_IRQ_NO_BALANCING);
459*5113495bSYour Name else
460*5113495bSYour Name for (j = 0; j < exec_ctx->numirq; j++)
461*5113495bSYour Name qdf_dev_modify_irq_status(exec_ctx->os_irq[j],
462*5113495bSYour Name QDF_IRQ_NO_BALANCING,
463*5113495bSYour Name 0);
464*5113495bSYour Name hif_debug("dl_flag %d CE %d", dl_flag, i);
465*5113495bSYour Name }
466*5113495bSYour Name }
467*5113495bSYour Name
468*5113495bSYour Name /**
469*5113495bSYour Name * hif_exec_cpu_denylist() - en(dis)ables denylisting for NAPI RX interrupts.
470*5113495bSYour Name * @napid: pointer to qca_napi_data structure
471*5113495bSYour Name * @op: denylist operation to perform
472*5113495bSYour Name *
473*5113495bSYour Name * The function enables/disables/queries denylisting for all CE RX
474*5113495bSYour Name * interrupts with NAPI enabled. Besides denylisting, it also enables/disables
475*5113495bSYour Name * core_ctl_set_boost.
476*5113495bSYour Name * Once denylisting is enabled, the interrupts will not be managed by the IRQ
477*5113495bSYour Name * balancer.
478*5113495bSYour Name *
479*5113495bSYour Name * Return: -EINVAL, in case IRQ_DENYLISTING and CORE_CTL_BOOST is not enabled
480*5113495bSYour Name * for DENYLIST_QUERY op - denylist refcount
481*5113495bSYour Name * for DENYLIST_ON op - return value from core_ctl_set_boost API
482*5113495bSYour Name * for DENYLIST_OFF op - return value from core_ctl_set_boost API
483*5113495bSYour Name */
hif_exec_cpu_denylist(struct qca_napi_data * napid,enum qca_denylist_op op)484*5113495bSYour Name int hif_exec_cpu_denylist(struct qca_napi_data *napid,
485*5113495bSYour Name enum qca_denylist_op op)
486*5113495bSYour Name {
487*5113495bSYour Name int rc = 0;
488*5113495bSYour Name static int ref_count; /* = 0 by the compiler */
489*5113495bSYour Name uint8_t flags = napid->flags;
490*5113495bSYour Name bool dl_en = flags & QCA_NAPI_FEATURE_IRQ_BLACKLISTING;
491*5113495bSYour Name bool ccb_en = flags & QCA_NAPI_FEATURE_CORE_CTL_BOOST;
492*5113495bSYour Name
493*5113495bSYour Name NAPI_DEBUG("-->%s(%d %d)", __func__, flags, op);
494*5113495bSYour Name
495*5113495bSYour Name if (!(dl_en && ccb_en)) {
496*5113495bSYour Name rc = -EINVAL;
497*5113495bSYour Name goto out;
498*5113495bSYour Name }
499*5113495bSYour Name
500*5113495bSYour Name switch (op) {
501*5113495bSYour Name case DENYLIST_QUERY:
502*5113495bSYour Name rc = ref_count;
503*5113495bSYour Name break;
504*5113495bSYour Name case DENYLIST_ON:
505*5113495bSYour Name ref_count++;
506*5113495bSYour Name rc = 0;
507*5113495bSYour Name if (ref_count == 1) {
508*5113495bSYour Name rc = hif_napi_core_ctl_set_boost(true);
509*5113495bSYour Name NAPI_DEBUG("boost_on() returns %d - refcnt=%d",
510*5113495bSYour Name rc, ref_count);
511*5113495bSYour Name hif_exec_dl_irq(napid, true);
512*5113495bSYour Name }
513*5113495bSYour Name break;
514*5113495bSYour Name case DENYLIST_OFF:
515*5113495bSYour Name if (ref_count)
516*5113495bSYour Name ref_count--;
517*5113495bSYour Name rc = 0;
518*5113495bSYour Name if (ref_count == 0) {
519*5113495bSYour Name rc = hif_napi_core_ctl_set_boost(false);
520*5113495bSYour Name NAPI_DEBUG("boost_off() returns %d - refcnt=%d",
521*5113495bSYour Name rc, ref_count);
522*5113495bSYour Name hif_exec_dl_irq(napid, false);
523*5113495bSYour Name }
524*5113495bSYour Name break;
525*5113495bSYour Name default:
526*5113495bSYour Name NAPI_DEBUG("Invalid denylist op: %d", op);
527*5113495bSYour Name rc = -EINVAL;
528*5113495bSYour Name } /* switch */
529*5113495bSYour Name out:
530*5113495bSYour Name NAPI_DEBUG("<--%s[%d]", __func__, rc);
531*5113495bSYour Name return rc;
532*5113495bSYour Name }
533*5113495bSYour Name
534