[Openvpn-devel,v2] ovpn-dco: fix kernel 6.1 compile issue in ovpn_peer_create

Message ID 20221022083842.4093941-1-git@johnthomson.fastmail.com.au
State Accepted
Headers show
Series [Openvpn-devel,v2] ovpn-dco: fix kernel 6.1 compile issue in ovpn_peer_create | expand

Commit Message

John Thomson Oct. 21, 2022, 9:38 p.m. UTC
Linux 5.19 replaces netif_tx_napi_add, but maintains a definition to the
new function in: 58caed3dacb4 ("netdev: reshuffle netif_napi_add() APIs
to allow dropping weigh") [0]

Linux 6.1 removes netif_tx_napi_add in c3f760ef1287 ("net: remove
netif_tx_napi_add()") [1]

[0]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=58caed3dacb4354a25a1aa8d2febc3e9648ba1f4
[1]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=c3f760ef128789252e7c4f10d3c1721422dceba9

Signed-off-by: John Thomson <git@johnthomson.fastmail.com.au>
---
v2: Do not throw ifdefs into the middle of the code

compile tested only: openwrt toolchain aarch64: kernel v6.1rc1, kernel 5.10
---
 drivers/net/ovpn-dco/peer.c | 2 +-
 linux-compat.h              | 8 ++++++++
 2 files changed, 9 insertions(+), 1 deletion(-)

Comments

Antonio Quartulli Oct. 22, 2022, 2:38 a.m. UTC | #1
Hi,

On 22/10/2022 10:38, John Thomson wrote:
> Linux 5.19 replaces netif_tx_napi_add, but maintains a definition to the
> new function in: 58caed3dacb4 ("netdev: reshuffle netif_napi_add() APIs
> to allow dropping weigh") [0]
> 
> Linux 6.1 removes netif_tx_napi_add in c3f760ef1287 ("net: remove
> netif_tx_napi_add()") [1]
> 
> [0]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=58caed3dacb4354a25a1aa8d2febc3e9648ba1f4
> [1]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=c3f760ef128789252e7c4f10d3c1721422dceba9
> 
> Signed-off-by: John Thomson <git@johnthomson.fastmail.com.au>

Thanks a lot for this!
Your patch has been applied to the master branch with a few minor style 
fixes.

> ---
> v2: Do not throw ifdefs into the middle of the code
> 
> compile tested only: openwrt toolchain aarch64: kernel v6.1rc1, kernel 5.10

Out of curiosity: are you using the openvpn-dev feed for openwqrt? 
(https://github.com/OpenVPN/openvpn-dev-openwrt)

Cheers,
John Thomson Oct. 22, 2022, 10:53 a.m. UTC | #2
On Sat, 22 Oct 2022, at 13:38, Antonio Quartulli wrote:
> Hi,
>
> On 22/10/2022 10:38, John Thomson wrote:
>> Linux 5.19 replaces netif_tx_napi_add, but maintains a definition to the
>> new function in: 58caed3dacb4 ("netdev: reshuffle netif_napi_add() APIs
>> to allow dropping weigh") [0]
>> 
>> Linux 6.1 removes netif_tx_napi_add in c3f760ef1287 ("net: remove
>> netif_tx_napi_add()") [1]
>> 
>> [0]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=58caed3dacb4354a25a1aa8d2febc3e9648ba1f4
>> [1]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=c3f760ef128789252e7c4f10d3c1721422dceba9
>> 
>> Signed-off-by: John Thomson <git@johnthomson.fastmail.com.au>
>
> Thanks a lot for this!
> Your patch has been applied to the master branch with a few minor style 
> fixes.

Thank you for the help and quick turnaround.
I really should have found all the #if LINUX_VERSION_CODE in linux-compat myself the first timeā€¦ Sorry

>
>> ---
>> v2: Do not throw ifdefs into the middle of the code
>> 
>> compile tested only: openwrt toolchain aarch64: kernel v6.1rc1, kernel 5.10
>
> Out of curiosity: are you using the openvpn-dev feed for openwqrt? 
> (https://github.com/OpenVPN/openvpn-dev-openwrt)

Not yet, only just learned of it.
I was walking through building all the Openwrt kernel modules with kernel 6.1rc1 and came across ovpn-dco in the Openwrt packages feed.


Cheers,

Patch

diff --git a/drivers/net/ovpn-dco/peer.c b/drivers/net/ovpn-dco/peer.c
index 5838286..8fc619c 100644
--- a/drivers/net/ovpn-dco/peer.c
+++ b/drivers/net/ovpn-dco/peer.c
@@ -88,7 +88,7 @@  static struct ovpn_peer *ovpn_peer_create(struct ovpn_struct *ovpn, u32 id)
 	}
 
 	/* configure and start NAPI */
-	netif_tx_napi_add(ovpn->dev, &peer->napi, ovpn_napi_poll,
+	netif_napi_add_tx_weight(ovpn->dev, &peer->napi, ovpn_napi_poll,
 			  NAPI_POLL_WEIGHT);
 	napi_enable(&peer->napi);
 
diff --git a/linux-compat.h b/linux-compat.h
index 3fb0208..b5af7e9 100644
--- a/linux-compat.h
+++ b/linux-compat.h
@@ -104,4 +104,12 @@  static inline void dev_sw_netstats_rx_add(struct net_device *dev, unsigned int l
 
 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(5, 2, 0) */
 
+#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 19, 0)
+/**
+ * commit 58caed3dacb4 renamed to netif_napi_add_tx_weight,
+ * commit c3f760ef1287 removed netif_tx_napi_add
+ */
+#define netif_napi_add_tx_weight netif_tx_napi_add
+#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(5, 19, 0) */
+
 #endif /* _NET_OVPN_DCO_LINUX_COMPAT_H_ */