RE: [net-next 2/6] fm10k: reduce duplicate fm10k_stat macro code

2018-05-08 Thread Keller, Jacob E
> -Original Message-
> From: netdev-ow...@vger.kernel.org [mailto:netdev-ow...@vger.kernel.org]
> On Behalf Of Joe Perches
> Sent: Tuesday, May 08, 2018 10:00 AM
> To: Kirsher, Jeffrey T ; da...@davemloft.net
> Cc: Keller, Jacob E ; netdev@vger.kernel.org;
> nhor...@redhat.com; sassm...@redhat.com; jogre...@redhat.com
> Subject: Re: [net-next 2/6] fm10k: reduce duplicate fm10k_stat macro code
> 
> On Mon, 2018-05-07 at 07:45 -0700, Jeff Kirsher wrote:
> > Share some of the code for setting up fm10k_stat macros by implementing
> > an FM10K_STAT_FIELDS macro which we can use when setting up the type
> > specific macros.
> []
> > diff --git a/drivers/net/ethernet/intel/fm10k/fm10k_ethtool.c
> b/drivers/net/ethernet/intel/fm10k/fm10k_ethtool.c
> []
> > @@ -11,12 +11,16 @@ struct fm10k_stats {
> > int stat_offset;
> >  };o
> >
> > -#define FM10K_NETDEV_STAT(_net_stat) { \
> > -   .stat_string = #_net_stat, \
> > -   .sizeof_stat = FIELD_SIZEOF(struct net_device_stats, _net_stat), \
> > -   .stat_offset = offsetof(struct net_device_stats, _net_stat) \
> > +#define FM10K_STAT_FIELDS(_type, _name, _stat) { \
> > +   .stat_string = _name, \
> > +   .sizeof_stat = FIELD_SIZEOF(_type, _stat), \
> > +   .stat_offset = offsetof(_type, _stat) \
> >  }
> >
> > +/* netdevice statistics */
> > +#define FM10K_NETDEV_STAT(_net_stat) \
> > +   FM10K_STAT_FIELDS(struct net_device_stats, #_net_stat, _net_stat)
> 
> trivia:
> 
> It's somewhat unusual to use # in a macro argument.
> Perhaps this would be slightly easier to understand using __stringify
> 
> #define FM10K_NETDEV_STAT(_net_stat) \
>   FM10K_STAT_FIELDS(struct net_device_stats, __stringify(_net_stat),
> _net_stat)

Makes sense. Will change.

Thanks,
Jake


Re: [net-next 2/6] fm10k: reduce duplicate fm10k_stat macro code

2018-05-08 Thread Joe Perches
On Mon, 2018-05-07 at 07:45 -0700, Jeff Kirsher wrote:
> Share some of the code for setting up fm10k_stat macros by implementing
> an FM10K_STAT_FIELDS macro which we can use when setting up the type
> specific macros.
[]
> diff --git a/drivers/net/ethernet/intel/fm10k/fm10k_ethtool.c 
> b/drivers/net/ethernet/intel/fm10k/fm10k_ethtool.c
[]
> @@ -11,12 +11,16 @@ struct fm10k_stats {
>   int stat_offset;
>  };o 
>  
> -#define FM10K_NETDEV_STAT(_net_stat) { \
> - .stat_string = #_net_stat, \
> - .sizeof_stat = FIELD_SIZEOF(struct net_device_stats, _net_stat), \
> - .stat_offset = offsetof(struct net_device_stats, _net_stat) \
> +#define FM10K_STAT_FIELDS(_type, _name, _stat) { \
> + .stat_string = _name, \
> + .sizeof_stat = FIELD_SIZEOF(_type, _stat), \
> + .stat_offset = offsetof(_type, _stat) \
>  }
>  
> +/* netdevice statistics */
> +#define FM10K_NETDEV_STAT(_net_stat) \
> + FM10K_STAT_FIELDS(struct net_device_stats, #_net_stat, _net_stat)

trivia:

It's somewhat unusual to use # in a macro argument.
Perhaps this would be slightly easier to understand using __stringify

#define FM10K_NETDEV_STAT(_net_stat) \
FM10K_STAT_FIELDS(struct net_device_stats, __stringify(_net_stat), 
_net_stat)



[net-next 2/6] fm10k: reduce duplicate fm10k_stat macro code

2018-05-07 Thread Jeff Kirsher
From: Jacob Keller 

Share some of the code for setting up fm10k_stat macros by implementing
an FM10K_STAT_FIELDS macro which we can use when setting up the type
specific macros.

Signed-off-by: Jacob Keller 
Tested-by: Krishneil Singh 
Signed-off-by: Jeff Kirsher 
---
 drivers/net/ethernet/intel/fm10k/fm10k_ethtool.c | 28 
 1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/drivers/net/ethernet/intel/fm10k/fm10k_ethtool.c 
b/drivers/net/ethernet/intel/fm10k/fm10k_ethtool.c
index eeac2b75a195..f4cad9ffdc79 100644
--- a/drivers/net/ethernet/intel/fm10k/fm10k_ethtool.c
+++ b/drivers/net/ethernet/intel/fm10k/fm10k_ethtool.c
@@ -11,12 +11,16 @@ struct fm10k_stats {
int stat_offset;
 };
 
-#define FM10K_NETDEV_STAT(_net_stat) { \
-   .stat_string = #_net_stat, \
-   .sizeof_stat = FIELD_SIZEOF(struct net_device_stats, _net_stat), \
-   .stat_offset = offsetof(struct net_device_stats, _net_stat) \
+#define FM10K_STAT_FIELDS(_type, _name, _stat) { \
+   .stat_string = _name, \
+   .sizeof_stat = FIELD_SIZEOF(_type, _stat), \
+   .stat_offset = offsetof(_type, _stat) \
 }
 
+/* netdevice statistics */
+#define FM10K_NETDEV_STAT(_net_stat) \
+   FM10K_STAT_FIELDS(struct net_device_stats, #_net_stat, _net_stat)
+
 static const struct fm10k_stats fm10k_gstrings_net_stats[] = {
FM10K_NETDEV_STAT(tx_packets),
FM10K_NETDEV_STAT(tx_bytes),
@@ -34,11 +38,9 @@ static const struct fm10k_stats fm10k_gstrings_net_stats[] = 
{
 
 #define FM10K_NETDEV_STATS_LEN ARRAY_SIZE(fm10k_gstrings_net_stats)
 
-#define FM10K_STAT(_name, _stat) { \
-   .stat_string = _name, \
-   .sizeof_stat = FIELD_SIZEOF(struct fm10k_intfc, _stat), \
-   .stat_offset = offsetof(struct fm10k_intfc, _stat) \
-}
+/* General interface statistics */
+#define FM10K_STAT(_name, _stat) \
+   FM10K_STAT_FIELDS(struct fm10k_intfc, _name, _stat)
 
 static const struct fm10k_stats fm10k_gstrings_global_stats[] = {
FM10K_STAT("tx_restart_queue", restart_queue),
@@ -75,11 +77,9 @@ static const struct fm10k_stats fm10k_gstrings_pf_stats[] = {
FM10K_STAT("nodesc_drop", stats.nodesc_drop.count),
 };
 
-#define FM10K_MBX_STAT(_name, _stat) { \
-   .stat_string = _name, \
-   .sizeof_stat = FIELD_SIZEOF(struct fm10k_mbx_info, _stat), \
-   .stat_offset = offsetof(struct fm10k_mbx_info, _stat) \
-}
+/* mailbox statistics */
+#define FM10K_MBX_STAT(_name, _stat) \
+   FM10K_STAT_FIELDS(struct fm10k_mbx_info, _name, _stat)
 
 static const struct fm10k_stats fm10k_gstrings_mbx_stats[] = {
FM10K_MBX_STAT("mbx_tx_busy", tx_busy),
-- 
2.14.3