git: 649f21d4d7a8 - stable/13 - LinuxKPI: add (skeleton) functions to make drivers compile

From: Bjoern A. Zeeb <bz_at_FreeBSD.org>
Date: Wed, 18 Jan 2023 16:25:07 UTC
The branch stable/13 has been updated by bz:

URL: https://cgit.FreeBSD.org/src/commit/?id=649f21d4d7a838acfa36925c717ce99df33c9c9f

commit 649f21d4d7a838acfa36925c717ce99df33c9c9f
Author:     Bjoern A. Zeeb <bz@FreeBSD.org>
AuthorDate: 2022-12-03 23:00:04 +0000
Commit:     Bjoern A. Zeeb <bz@FreeBSD.org>
CommitDate: 2023-01-18 13:26:55 +0000

    LinuxKPI: add (skeleton) functions to make drivers compile
    
    Add more functions to netdevice.h (netif_napi_add_tx() being the only
    one implemented) and add platform_device.h and netlink.h in order to
    make driver code compile.
    The skeleton functions are used only in very limited scope and not at
    all in our usage so far but add (invasive) #ifdef if removed.
    Add pr_debug() calls to each of them in order to log a TODO (if DEBUG
    compiled in) and someone should hit them in the future.
    
    Commented on by: hselasky (earlier version)
    Differential Revision: https://reviews.freebsd.org/D37599
    
    (cherry picked from commit 75388b9ca5e566fb7cbd62a37cea1f66d8203fc6)
---
 .../linuxkpi/common/include/linux/netdevice.h      | 132 +++++++++++++++++++++
 .../common/include/linux/platform_device.h         |  79 ++++++++++++
 sys/compat/linuxkpi/common/include/net/netlink.h   |  53 +++++++++
 3 files changed, 264 insertions(+)

diff --git a/sys/compat/linuxkpi/common/include/linux/netdevice.h b/sys/compat/linuxkpi/common/include/linux/netdevice.h
index fdfd650a55e5..8653b5df68bd 100644
--- a/sys/compat/linuxkpi/common/include/linux/netdevice.h
+++ b/sys/compat/linuxkpi/common/include/linux/netdevice.h
@@ -53,6 +53,7 @@
 #include <net/if_var.h>
 #include <net/if_dl.h>
 
+#include <linux/kernel.h>
 #include <linux/bitops.h>
 #include <linux/list.h>
 #include <linux/device.h>
@@ -134,6 +135,7 @@ struct net_device {
 	/* Not properly typed as-of now. */
 	int	flags, type;
 	int	name_assign_type, needed_headroom;
+	int	threaded;
 
 	void (*priv_destructor)(struct net_device *);
 
@@ -266,6 +268,15 @@ void linuxkpi_napi_synchronize(struct napi_struct *);
 #define	napi_synchronize(_n)						\
 	linuxkpi_napi_synchronize(_n)
 
+
+static inline void
+netif_napi_add_tx(struct net_device *dev, struct napi_struct *napi,
+    int(*napi_poll)(struct napi_struct *, int))
+{
+
+	netif_napi_add(dev, napi, napi_poll);
+}
+
 /* -------------------------------------------------------------------------- */
 
 static inline void
@@ -308,6 +319,126 @@ synchronize_net(void)
 	synchronize_rcu();
 }
 
+static __inline void
+netif_receive_skb_list(struct list_head *head)
+{
+
+	pr_debug("%s: TODO\n", __func__);
+}
+
+static __inline int
+napi_gro_receive(struct napi_struct *napi, struct sk_buff *skb)
+{
+
+	pr_debug("%s: TODO\n", __func__);
+	return (-1);
+}
+
+static __inline void
+ether_setup(struct net_device *ndev)
+{
+
+	pr_debug("%s: TODO\n", __func__);
+}
+
+static __inline void
+dev_net_set(struct net_device *dev, void *p)
+{
+
+	pr_debug("%s: TODO\n", __func__);
+}
+
+/* -------------------------------------------------------------------------- */
+
+static __inline bool
+netif_carrier_ok(struct net_device *ndev)
+{
+	pr_debug("%s: TODO\n", __func__);
+	return (false);
+}
+
+static __inline void
+netif_carrier_off(struct net_device *ndev)
+{
+	pr_debug("%s: TODO\n", __func__);
+}
+
+static __inline void
+netif_carrier_on(struct net_device *ndev)
+{
+	pr_debug("%s: TODO\n", __func__);
+}
+
+/* -------------------------------------------------------------------------- */
+
+static __inline bool
+netif_queue_stopped(struct net_device *ndev)
+{
+	pr_debug("%s: TODO\n", __func__);
+	return (false);
+}
+
+static __inline void
+netif_stop_queue(struct net_device *ndev)
+{
+	pr_debug("%s: TODO\n", __func__);
+}
+
+static __inline void
+netif_wake_queue(struct net_device *ndev)
+{
+	pr_debug("%s: TODO\n", __func__);
+}
+
+/* -------------------------------------------------------------------------- */
+
+static __inline int
+register_netdevice(struct net_device *ndev)
+{
+
+	/* assert rtnl_locked? */
+	pr_debug("%s: TODO\n", __func__);
+	return (0);
+}
+
+static __inline int
+register_netdev(struct net_device *ndev)
+{
+	int error;
+
+	/* lock */
+	error = register_netdevice(ndev);
+	/* unlock */
+	pr_debug("%s: TODO\n", __func__);
+	return (error);
+}
+
+static __inline void
+unregister_netdev(struct net_device *ndev)
+{
+	pr_debug("%s: TODO\n", __func__);
+}
+
+static __inline void
+unregister_netdevice(struct net_device *ndev)
+{
+	pr_debug("%s: TODO\n", __func__);
+}
+
+/* -------------------------------------------------------------------------- */
+
+static __inline void
+netif_rx(struct sk_buff *skb)
+{
+	pr_debug("%s: TODO\n", __func__);
+}
+
+static __inline void
+netif_rx_ni(struct sk_buff *skb)
+{
+	pr_debug("%s: TODO\n", __func__);
+}
+
 /* -------------------------------------------------------------------------- */
 
 struct net_device *linuxkpi_alloc_netdev(size_t, const char *, uint32_t,
@@ -331,5 +462,6 @@ netdev_priv(const struct net_device *ndev)
 
 #define	rtnl_lock()		do { } while(0)
 #define	rtnl_unlock()		do { } while(0)
+#define	rcu_dereference_rtnl(x)	READ_ONCE(x)
 
 #endif	/* _LINUXKPI_LINUX_NETDEVICE_H */
diff --git a/sys/compat/linuxkpi/common/include/linux/platform_device.h b/sys/compat/linuxkpi/common/include/linux/platform_device.h
new file mode 100644
index 000000000000..f07b5aac967b
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/linux/platform_device.h
@@ -0,0 +1,79 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2020-2022 Bjoern A. Zeeb
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef	_LINUXKPI_LINUX_PLATFORM_DEVICE_H
+#define	_LINUXKPI_LINUX_PLATFORM_DEVICE_H
+
+#include <linux/kernel.h>
+#include <linux/device.h>
+
+struct platform_device {
+	struct device			dev;
+};
+
+struct platform_driver {
+	int				(*remove)(struct platform_device *);
+	struct device_driver		driver;
+};
+
+
+static __inline int
+platform_driver_register(struct platform_driver *pdrv)
+{
+
+	pr_debug("%s: TODO\n", __func__);
+	return (-ENXIO);
+}
+
+static __inline void *
+dev_get_platdata(struct device *dev)
+{
+
+	pr_debug("%s: TODO\n", __func__);
+	return (NULL);
+}
+
+static __inline int
+platform_driver_probe(struct platform_driver *pdrv,
+    int(*pd_probe_f)(struct platform_device *))
+{
+
+	pr_debug("%s: TODO\n", __func__);
+	return (-ENODEV);
+}
+
+static __inline void
+platform_driver_unregister(struct platform_driver *pdrv)
+{
+
+	pr_debug("%s: TODO\n", __func__);
+	return;
+}
+
+#endif	/* _LINUXKPI_LINUX_PLATFORM_DEVICE_H */
diff --git a/sys/compat/linuxkpi/common/include/net/netlink.h b/sys/compat/linuxkpi/common/include/net/netlink.h
new file mode 100644
index 000000000000..ae250177d18b
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/net/netlink.h
@@ -0,0 +1,53 @@
+/*-
+ * Copyright (c) 2020,2022 Bjoern A. Zeeb
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef	_LINUXKPI_NET_NETLINK_H
+#define	_LINUXKPI_NET_NETLINK_H
+
+#include <netlink/netlink.h>
+
+struct nla_policy {
+};
+
+struct netlink_callback {
+	int		args[8];
+};
+
+static __inline int
+nla_put(struct sk_buff *skb, int attr, size_t len, void *data)
+{
+
+	pr_debug("%s: TODO -- now native?\n", __func__);
+	return (-ENXIO);
+}
+
+static __inline int
+nla_put_u16(struct sk_buff *skb, int attr, uint32_t val)
+{
+
+	return (nla_put(skb, attr, sizeof(uint32_t), &val));
+}
+
+#endif	/* _LINUXKPI_NET_NETLINK_H */