[v5,9/9] kni: add minimal ethtool
Checks
Commit Message
Some applications use ethtool so add the minimum ethtool ops.
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
kernel/linux/kni/kni_dev.h | 2 ++
kernel/linux/kni/kni_misc.c | 1 +
kernel/linux/kni/kni_net.c | 14 ++++++++++++++
3 files changed, 17 insertions(+)
Comments
Hi Stephen,
As ethtool support is restored, I think your patch #7 should be
updated to keep ethtool support in docs.
Best regards,
Igor
On Thu, Jun 20, 2019 at 10:22 PM Stephen Hemminger
<stephen@networkplumber.org> wrote:
>
> Some applications use ethtool so add the minimum ethtool ops.
>
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
> ---
> kernel/linux/kni/kni_dev.h | 2 ++
> kernel/linux/kni/kni_misc.c | 1 +
> kernel/linux/kni/kni_net.c | 14 ++++++++++++++
> 3 files changed, 17 insertions(+)
>
> diff --git a/kernel/linux/kni/kni_dev.h b/kernel/linux/kni/kni_dev.h
> index ceba5f73c1d9..c1ca6789ce12 100644
> --- a/kernel/linux/kni/kni_dev.h
> +++ b/kernel/linux/kni/kni_dev.h
> @@ -11,6 +11,8 @@
> #endif
> #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
>
> +#define KNI_VERSION "1.0"
> +
> #include "compat.h"
>
> #include <linux/if.h>
> diff --git a/kernel/linux/kni/kni_misc.c b/kernel/linux/kni/kni_misc.c
> index be45f823408f..2b75502a8b0e 100644
> --- a/kernel/linux/kni/kni_misc.c
> +++ b/kernel/linux/kni/kni_misc.c
> @@ -21,6 +21,7 @@
> #include "compat.h"
> #include "kni_dev.h"
>
> +MODULE_VERSION(KNI_VERSION);
> MODULE_LICENSE("Dual BSD/GPL");
> MODULE_AUTHOR("Intel Corporation");
> MODULE_DESCRIPTION("Kernel Module for managing kni devices");
> diff --git a/kernel/linux/kni/kni_net.c b/kernel/linux/kni/kni_net.c
> index 320d51d7fc83..319ee2dcb19a 100644
> --- a/kernel/linux/kni/kni_net.c
> +++ b/kernel/linux/kni/kni_net.c
> @@ -13,6 +13,7 @@
> #include <linux/version.h>
> #include <linux/netdevice.h>
> #include <linux/etherdevice.h> /* eth_type_trans */
> +#include <linux/ethtool.h>
> #include <linux/skbuff.h>
> #include <linux/kthread.h>
> #include <linux/delay.h>
> @@ -725,6 +726,18 @@ static const struct net_device_ops kni_net_netdev_ops = {
> #endif
> };
>
> +static void kni_get_drvinfo(struct net_device *dev,
> + struct ethtool_drvinfo *info)
> +{
> + strlcpy(info->version, KNI_VERSION, sizeof(info->version));
> + strlcpy(info->driver, "kni", sizeof(info->driver));
> +}
> +
> +static const struct ethtool_ops kni_net_ethtool_ops = {
> + .get_drvinfo = kni_get_drvinfo,
> + .get_link = ethtool_op_get_link,
> +};
> +
> void
> kni_net_init(struct net_device *dev)
> {
> @@ -736,6 +749,7 @@ kni_net_init(struct net_device *dev)
> ether_setup(dev); /* assign some of the fields */
> dev->netdev_ops = &kni_net_netdev_ops;
> dev->header_ops = &kni_net_header_ops;
> + dev->ethtool_ops = &kni_net_ethtool_ops;
> dev->watchdog_timeo = WD_TIMEOUT;
> }
>
> --
> 2.20.1
>
On Fri, 21 Jun 2019 11:26:09 +0300
Igor Ryzhov <iryzhov@nfware.com> wrote:
> Hi Stephen,
>
> As ethtool support is restored, I think your patch #7 should be
> updated to keep ethtool support in docs.
>
> Best regards,
> Igor
Good idea, I will add that. This is not like the original ethtool,
it is intentionally limited in scope and generic (unlike the original).
@@ -11,6 +11,8 @@
#endif
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+#define KNI_VERSION "1.0"
+
#include "compat.h"
#include <linux/if.h>
@@ -21,6 +21,7 @@
#include "compat.h"
#include "kni_dev.h"
+MODULE_VERSION(KNI_VERSION);
MODULE_LICENSE("Dual BSD/GPL");
MODULE_AUTHOR("Intel Corporation");
MODULE_DESCRIPTION("Kernel Module for managing kni devices");
@@ -13,6 +13,7 @@
#include <linux/version.h>
#include <linux/netdevice.h>
#include <linux/etherdevice.h> /* eth_type_trans */
+#include <linux/ethtool.h>
#include <linux/skbuff.h>
#include <linux/kthread.h>
#include <linux/delay.h>
@@ -725,6 +726,18 @@ static const struct net_device_ops kni_net_netdev_ops = {
#endif
};
+static void kni_get_drvinfo(struct net_device *dev,
+ struct ethtool_drvinfo *info)
+{
+ strlcpy(info->version, KNI_VERSION, sizeof(info->version));
+ strlcpy(info->driver, "kni", sizeof(info->driver));
+}
+
+static const struct ethtool_ops kni_net_ethtool_ops = {
+ .get_drvinfo = kni_get_drvinfo,
+ .get_link = ethtool_op_get_link,
+};
+
void
kni_net_init(struct net_device *dev)
{
@@ -736,6 +749,7 @@ kni_net_init(struct net_device *dev)
ether_setup(dev); /* assign some of the fields */
dev->netdev_ops = &kni_net_netdev_ops;
dev->header_ops = &kni_net_header_ops;
+ dev->ethtool_ops = &kni_net_ethtool_ops;
dev->watchdog_timeo = WD_TIMEOUT;
}