generic: 6.1: backport qca808x LED support patch
[openwrt/openwrt.git] / target / linux / generic / backport-6.1 / 770-net-introduce-napi_is_scheduled-helper.patch
1 From 7f3eb2174512fe6c9c0f062e96eccb0d3cc6d5cd Mon Sep 17 00:00:00 2001
2 From: Christian Marangi <ansuelsmth@gmail.com>
3 Date: Wed, 18 Oct 2023 14:35:47 +0200
4 Subject: [PATCH] net: introduce napi_is_scheduled helper
5
6 We currently have napi_if_scheduled_mark_missed that can be used to
7 check if napi is scheduled but that does more thing than simply checking
8 it and return a bool. Some driver already implement custom function to
9 check if napi is scheduled.
10
11 Drop these custom function and introduce napi_is_scheduled that simply
12 check if napi is scheduled atomically.
13
14 Update any driver and code that implement a similar check and instead
15 use this new helper.
16
17 Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
18 Signed-off-by: Paolo Abeni <pabeni@redhat.com>
19 ---
20 drivers/net/ethernet/chelsio/cxgb3/sge.c | 8 --------
21 drivers/net/wireless/realtek/rtw89/core.c | 2 +-
22 include/linux/netdevice.h | 23 +++++++++++++++++++++++
23 net/core/dev.c | 2 +-
24 4 files changed, 25 insertions(+), 10 deletions(-)
25
26 --- a/drivers/net/ethernet/chelsio/cxgb3/sge.c
27 +++ b/drivers/net/ethernet/chelsio/cxgb3/sge.c
28 @@ -2507,14 +2507,6 @@ static int napi_rx_handler(struct napi_s
29 return work_done;
30 }
31
32 -/*
33 - * Returns true if the device is already scheduled for polling.
34 - */
35 -static inline int napi_is_scheduled(struct napi_struct *napi)
36 -{
37 - return test_bit(NAPI_STATE_SCHED, &napi->state);
38 -}
39 -
40 /**
41 * process_pure_responses - process pure responses from a response queue
42 * @adap: the adapter
43 --- a/drivers/net/wireless/realtek/rtw89/core.c
44 +++ b/drivers/net/wireless/realtek/rtw89/core.c
45 @@ -1479,7 +1479,7 @@ static void rtw89_core_rx_to_mac80211(st
46 struct napi_struct *napi = &rtwdev->napi;
47
48 /* In low power mode, napi isn't scheduled. Receive it to netif. */
49 - if (unlikely(!test_bit(NAPI_STATE_SCHED, &napi->state)))
50 + if (unlikely(!napi_is_scheduled(napi)))
51 napi = NULL;
52
53 rtw89_core_hw_to_sband_rate(rx_status);
54 --- a/include/linux/netdevice.h
55 +++ b/include/linux/netdevice.h
56 @@ -468,6 +468,29 @@ static inline bool napi_prefer_busy_poll
57 return test_bit(NAPI_STATE_PREFER_BUSY_POLL, &n->state);
58 }
59
60 +/**
61 + * napi_is_scheduled - test if NAPI is scheduled
62 + * @n: NAPI context
63 + *
64 + * This check is "best-effort". With no locking implemented,
65 + * a NAPI can be scheduled or terminate right after this check
66 + * and produce not precise results.
67 + *
68 + * NAPI_STATE_SCHED is an internal state, napi_is_scheduled
69 + * should not be used normally and napi_schedule should be
70 + * used instead.
71 + *
72 + * Use only if the driver really needs to check if a NAPI
73 + * is scheduled for example in the context of delayed timer
74 + * that can be skipped if a NAPI is already scheduled.
75 + *
76 + * Return True if NAPI is scheduled, False otherwise.
77 + */
78 +static inline bool napi_is_scheduled(struct napi_struct *n)
79 +{
80 + return test_bit(NAPI_STATE_SCHED, &n->state);
81 +}
82 +
83 bool napi_schedule_prep(struct napi_struct *n);
84
85 /**
86 --- a/net/core/dev.c
87 +++ b/net/core/dev.c
88 @@ -6533,7 +6533,7 @@ static int __napi_poll(struct napi_struc
89 * accidentally calling ->poll() when NAPI is not scheduled.
90 */
91 work = 0;
92 - if (test_bit(NAPI_STATE_SCHED, &n->state)) {
93 + if (napi_is_scheduled(n)) {
94 work = n->poll(n, weight);
95 trace_napi_poll(n, work, weight);
96 }