diff mbox series

[net-next,1/2] ifb: support ethtools driver info

Message ID 20211125020155.6488-1-xiangxia.m.yue@gmail.com (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series [net-next,1/2] ifb: support ethtools driver info | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers success CCed 3 of 3 maintainers
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch warning WARNING: Prefer strscpy over strlcpy - see: https://lore.kernel.org/r/CAHk-=wgfRnXz0W3D37d01q3JFkr_i_uTL=V6A6G1oUZcprmknw@mail.gmail.com/ WARNING: line length of 81 exceeds 80 columns
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Tonghao Zhang Nov. 25, 2021, 2:01 a.m. UTC
From: Tonghao Zhang <xiangxia.m.yue@gmail.com>

ifb netdev may be created by others prefix, not ifbX.
For getting netdev driver info, add ifb ethtools callback.

Cc: Jakub Kicinski <kuba@kernel.org>
Cc: "David S. Miller" <davem@davemloft.net>
Signed-off-by: Tonghao Zhang <xiangxia.m.yue@gmail.com>
---
 drivers/net/ifb.c | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)

Comments

Tonghao Zhang Nov. 25, 2021, 7:29 a.m. UTC | #1
On Thu, Nov 25, 2021 at 10:19 AM Jakub Kicinski <kuba@kernel.org> wrote:
>
> On Thu, 25 Nov 2021 10:01:54 +0800 xiangxia.m.yue@gmail.com wrote:
> > +#define DRV_NAME     "ifb"
> > +#define DRV_VERSION  "1.0"
>
> Let's not invent meaningless driver versions.
Ok
> > +#define TX_Q_LIMIT   32
> > +
> >  struct ifb_q_private {
> >       struct net_device       *dev;
> >       struct tasklet_struct   ifb_tasklet;
> > @@ -181,6 +185,12 @@ static int ifb_dev_init(struct net_device *dev)
> >       return 0;
> >  }
> >
> > +static void ifb_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
> > +{
> > +     strlcpy(info->driver, DRV_NAME, sizeof(info->driver));
>
> Can we make core fill in driver name from rtnl_link_ops so we don't
> need to do it in each driver?
Good idea! v2 is sent out, please review.
https://patchwork.kernel.org/project/netdevbpf/patch/20211125072544.32578-1-xiangxia.m.yue@gmail.com/
> > +     strlcpy(info->version, DRV_VERSION, sizeof(info->version));
>
> Leave this field as is, core should fill it with the kernel release.
Ok
> > +}




--
Best regards, Tonghao
Leon Romanovsky Nov. 25, 2021, 1:55 p.m. UTC | #2
On Thu, Nov 25, 2021 at 10:01:54AM +0800, xiangxia.m.yue@gmail.com wrote:
> From: Tonghao Zhang <xiangxia.m.yue@gmail.com>
> 
> ifb netdev may be created by others prefix, not ifbX.
> For getting netdev driver info, add ifb ethtools callback.
> 
> Cc: Jakub Kicinski <kuba@kernel.org>
> Cc: "David S. Miller" <davem@davemloft.net>
> Signed-off-by: Tonghao Zhang <xiangxia.m.yue@gmail.com>
> ---
>  drivers/net/ifb.c | 22 +++++++++++++++++++---
>  1 file changed, 19 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/net/ifb.c b/drivers/net/ifb.c
> index 31f522b8e54e..d9078ce041c4 100644
> --- a/drivers/net/ifb.c
> +++ b/drivers/net/ifb.c
> @@ -26,6 +26,7 @@
>  
>  #include <linux/module.h>
>  #include <linux/kernel.h>
> +#include <linux/ethtool.h>
>  #include <linux/netdevice.h>
>  #include <linux/etherdevice.h>
>  #include <linux/init.h>
> @@ -35,7 +36,10 @@
>  #include <net/pkt_sched.h>
>  #include <net/net_namespace.h>
>  
> -#define TX_Q_LIMIT    32
> +#define DRV_NAME	"ifb"
> +#define DRV_VERSION	"1.0"

Please don't add this line too.

Thanks
diff mbox series

Patch

diff --git a/drivers/net/ifb.c b/drivers/net/ifb.c
index 31f522b8e54e..d9078ce041c4 100644
--- a/drivers/net/ifb.c
+++ b/drivers/net/ifb.c
@@ -26,6 +26,7 @@ 
 
 #include <linux/module.h>
 #include <linux/kernel.h>
+#include <linux/ethtool.h>
 #include <linux/netdevice.h>
 #include <linux/etherdevice.h>
 #include <linux/init.h>
@@ -35,7 +36,10 @@ 
 #include <net/pkt_sched.h>
 #include <net/net_namespace.h>
 
-#define TX_Q_LIMIT    32
+#define DRV_NAME	"ifb"
+#define DRV_VERSION	"1.0"
+#define TX_Q_LIMIT	32
+
 struct ifb_q_private {
 	struct net_device	*dev;
 	struct tasklet_struct   ifb_tasklet;
@@ -181,6 +185,12 @@  static int ifb_dev_init(struct net_device *dev)
 	return 0;
 }
 
+static void ifb_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
+{
+	strlcpy(info->driver, DRV_NAME, sizeof(info->driver));
+	strlcpy(info->version, DRV_VERSION, sizeof(info->version));
+}
+
 static const struct net_device_ops ifb_netdev_ops = {
 	.ndo_open	= ifb_open,
 	.ndo_stop	= ifb_close,
@@ -190,6 +200,10 @@  static const struct net_device_ops ifb_netdev_ops = {
 	.ndo_init	= ifb_dev_init,
 };
 
+static const struct ethtool_ops ifb_ethtool_ops = {
+	.get_drvinfo = ifb_get_drvinfo,
+};
+
 #define IFB_FEATURES (NETIF_F_HW_CSUM | NETIF_F_SG  | NETIF_F_FRAGLIST	| \
 		      NETIF_F_GSO_SOFTWARE | NETIF_F_GSO_ENCAP_ALL	| \
 		      NETIF_F_HIGHDMA | NETIF_F_HW_VLAN_CTAG_TX		| \
@@ -224,6 +238,8 @@  static void ifb_setup(struct net_device *dev)
 	dev->vlan_features |= IFB_FEATURES & ~(NETIF_F_HW_VLAN_CTAG_TX |
 					       NETIF_F_HW_VLAN_STAG_TX);
 
+	dev->ethtool_ops = &ifb_ethtool_ops;
+
 	dev->flags |= IFF_NOARP;
 	dev->flags &= ~IFF_MULTICAST;
 	dev->priv_flags &= ~IFF_TX_SKB_SHARING;
@@ -289,7 +305,7 @@  static int ifb_validate(struct nlattr *tb[], struct nlattr *data[],
 }
 
 static struct rtnl_link_ops ifb_link_ops __read_mostly = {
-	.kind		= "ifb",
+	.kind		= DRV_NAME,
 	.priv_size	= sizeof(struct ifb_dev_private),
 	.setup		= ifb_setup,
 	.validate	= ifb_validate,
@@ -359,4 +375,4 @@  module_init(ifb_init_module);
 module_exit(ifb_cleanup_module);
 MODULE_LICENSE("GPL");
 MODULE_AUTHOR("Jamal Hadi Salim");
-MODULE_ALIAS_RTNL_LINK("ifb");
+MODULE_ALIAS_RTNL_LINK(DRV_NAME);