RE: [PATCH V4 net-next 7/8] net: hns3: Add Ethtool support to HNS3 driver

2017-07-27 Thread Salil Mehta
Hi Florian,

> -Original Message-
> From: Florian Fainelli [mailto:f.faine...@gmail.com]
> Sent: Thursday, July 27, 2017 7:05 PM
> To: Salil Mehta; da...@davemloft.net
> Cc: Zhuangyuzeng (Yisen); huangdaode; lipeng (Y);
> mehta.salil@gmail.com; net...@vger.kernel.org; linux-
> ker...@vger.kernel.org; linux-r...@vger.kernel.org; Linuxarm
> Subject: Re: [PATCH V4 net-next 7/8] net: hns3: Add Ethtool support to
> HNS3 driver
> 
> On 07/27/2017 11:01 AM, Salil Mehta wrote:
> > Hi Florian,
> >
> >> -Original Message-
> >> From: Florian Fainelli [mailto:f.faine...@gmail.com]
> >> Sent: Sunday, July 23, 2017 6:05 PM
> >> To: Salil Mehta; da...@davemloft.net
> >> Cc: Zhuangyuzeng (Yisen); huangdaode; lipeng (Y);
> >> mehta.salil@gmail.com; net...@vger.kernel.org; linux-
> >> ker...@vger.kernel.org; linux-r...@vger.kernel.org; Linuxarm
> >> Subject: Re: [PATCH V4 net-next 7/8] net: hns3: Add Ethtool support
> to
> >> HNS3 driver
> >>
> >>
> >>
> >> On 07/22/2017 03:09 PM, Salil Mehta wrote:
> >>> This patch adds the support of the Ethtool interface to
> >>> the HNS3 Ethernet driver. Various commands to read the
> >>> statistics, configure the offloading, loopback selftest etc.
> >>> are supported.
> >>>
> >>> Signed-off-by: Daode Huang <huangda...@hisilicon.com>
> >>> Signed-off-by: lipeng <lipeng...@huawei.com>
> >>> Signed-off-by: Salil Mehta <salil.me...@huawei.com>
> >>> Signed-off-by: Yisen Zhuang <yisen.zhu...@huawei.com>
> >>> ---
> >>> Patch V4: addressed below comments
> >>>  1. Andrew Lunn
> >>> Removed the support of loop PHY back for now
> >>> Patch V3: Address below comments
> >>>  1. Stephen Hemminger
> >>> https://lkml.org/lkml/2017/6/13/974
> >>>  2. Andrew Lunn
> >>> https://lkml.org/lkml/2017/6/13/1037
> >>> Patch V2: No change
> >>> Patch V1: Initial Submit
> >>> ---
> >>>  .../ethernet/hisilicon/hns3/hns3pf/hns3_ethtool.c  | 543
> >> +
> >>>  1 file changed, 543 insertions(+)
> >>>  create mode 100644
> >> drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_ethtool.c
> >>>
> >>> diff --git
> >> a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_ethtool.c
> >> b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_ethtool.c
> >>> new file mode 100644
> >>> index ..82b0d4d829f8
> >>> --- /dev/null
> >>> +++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_ethtool.c
> >>> @@ -0,0 +1,543 @@
> >>> +/*
> >>> + * Copyright (c) 2016~2017 Hisilicon Limited.
> >>> + *
> >>> + * This program is free software; you can redistribute it and/or
> >> modify
> >>> + * it under the terms of the GNU General Public License as
> published
> >> by
> >>> + * the Free Software Foundation; either version 2 of the License,
> or
> >>> + * (at your option) any later version.
> >>> + */
> >>> +
> >>> +#include 
> >>> +#include "hns3_enet.h"
> >>> +
> >>> +struct hns3_stats {
> >>> + char stats_string[ETH_GSTRING_LEN];
> >>> + int stats_size;
> >>> + int stats_offset;
> >>> +};
> >>> +
> >>> +/* netdev related stats */
> >>> +#define HNS3_NETDEV_STAT(_string, _member)   \
> >>> + { _string,  \
> >>> +   FIELD_SIZEOF(struct rtnl_link_stats64, _member),  \
> >>> +   offsetof(struct rtnl_link_stats64, _member),  \
> >>> + }
> >>
> >> Can you make this macro use named initializers?
> > Can you please explain bit more or point out some
> > example. This would be very handy.
> 
>   .stat_string = _string,
>   .stats_size = FIELD_SIZEOF(struct rtnl_link_stat64, _member),
>   .stats_offset = offsetof(struct rtnl_link_stats64, _member),
> 
> https://gcc.gnu.org/onlinedocs/gcc/Designated-Inits.html

Ok got it, thanks!

> --
> Florian


RE: [PATCH V4 net-next 7/8] net: hns3: Add Ethtool support to HNS3 driver

2017-07-27 Thread Salil Mehta
Hi Florian,

> -Original Message-
> From: Florian Fainelli [mailto:f.faine...@gmail.com]
> Sent: Thursday, July 27, 2017 7:05 PM
> To: Salil Mehta; da...@davemloft.net
> Cc: Zhuangyuzeng (Yisen); huangdaode; lipeng (Y);
> mehta.salil@gmail.com; net...@vger.kernel.org; linux-
> ker...@vger.kernel.org; linux-r...@vger.kernel.org; Linuxarm
> Subject: Re: [PATCH V4 net-next 7/8] net: hns3: Add Ethtool support to
> HNS3 driver
> 
> On 07/27/2017 11:01 AM, Salil Mehta wrote:
> > Hi Florian,
> >
> >> -Original Message-
> >> From: Florian Fainelli [mailto:f.faine...@gmail.com]
> >> Sent: Sunday, July 23, 2017 6:05 PM
> >> To: Salil Mehta; da...@davemloft.net
> >> Cc: Zhuangyuzeng (Yisen); huangdaode; lipeng (Y);
> >> mehta.salil@gmail.com; net...@vger.kernel.org; linux-
> >> ker...@vger.kernel.org; linux-r...@vger.kernel.org; Linuxarm
> >> Subject: Re: [PATCH V4 net-next 7/8] net: hns3: Add Ethtool support
> to
> >> HNS3 driver
> >>
> >>
> >>
> >> On 07/22/2017 03:09 PM, Salil Mehta wrote:
> >>> This patch adds the support of the Ethtool interface to
> >>> the HNS3 Ethernet driver. Various commands to read the
> >>> statistics, configure the offloading, loopback selftest etc.
> >>> are supported.
> >>>
> >>> Signed-off-by: Daode Huang 
> >>> Signed-off-by: lipeng 
> >>> Signed-off-by: Salil Mehta 
> >>> Signed-off-by: Yisen Zhuang 
> >>> ---
> >>> Patch V4: addressed below comments
> >>>  1. Andrew Lunn
> >>> Removed the support of loop PHY back for now
> >>> Patch V3: Address below comments
> >>>  1. Stephen Hemminger
> >>> https://lkml.org/lkml/2017/6/13/974
> >>>  2. Andrew Lunn
> >>> https://lkml.org/lkml/2017/6/13/1037
> >>> Patch V2: No change
> >>> Patch V1: Initial Submit
> >>> ---
> >>>  .../ethernet/hisilicon/hns3/hns3pf/hns3_ethtool.c  | 543
> >> +
> >>>  1 file changed, 543 insertions(+)
> >>>  create mode 100644
> >> drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_ethtool.c
> >>>
> >>> diff --git
> >> a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_ethtool.c
> >> b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_ethtool.c
> >>> new file mode 100644
> >>> index ..82b0d4d829f8
> >>> --- /dev/null
> >>> +++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_ethtool.c
> >>> @@ -0,0 +1,543 @@
> >>> +/*
> >>> + * Copyright (c) 2016~2017 Hisilicon Limited.
> >>> + *
> >>> + * This program is free software; you can redistribute it and/or
> >> modify
> >>> + * it under the terms of the GNU General Public License as
> published
> >> by
> >>> + * the Free Software Foundation; either version 2 of the License,
> or
> >>> + * (at your option) any later version.
> >>> + */
> >>> +
> >>> +#include 
> >>> +#include "hns3_enet.h"
> >>> +
> >>> +struct hns3_stats {
> >>> + char stats_string[ETH_GSTRING_LEN];
> >>> + int stats_size;
> >>> + int stats_offset;
> >>> +};
> >>> +
> >>> +/* netdev related stats */
> >>> +#define HNS3_NETDEV_STAT(_string, _member)   \
> >>> + { _string,  \
> >>> +   FIELD_SIZEOF(struct rtnl_link_stats64, _member),  \
> >>> +   offsetof(struct rtnl_link_stats64, _member),  \
> >>> + }
> >>
> >> Can you make this macro use named initializers?
> > Can you please explain bit more or point out some
> > example. This would be very handy.
> 
>   .stat_string = _string,
>   .stats_size = FIELD_SIZEOF(struct rtnl_link_stat64, _member),
>   .stats_offset = offsetof(struct rtnl_link_stats64, _member),
> 
> https://gcc.gnu.org/onlinedocs/gcc/Designated-Inits.html

Ok got it, thanks!

> --
> Florian


Re: [PATCH V4 net-next 7/8] net: hns3: Add Ethtool support to HNS3 driver

2017-07-27 Thread Florian Fainelli
On 07/27/2017 11:01 AM, Salil Mehta wrote:
> Hi Florian,
> 
>> -Original Message-
>> From: Florian Fainelli [mailto:f.faine...@gmail.com]
>> Sent: Sunday, July 23, 2017 6:05 PM
>> To: Salil Mehta; da...@davemloft.net
>> Cc: Zhuangyuzeng (Yisen); huangdaode; lipeng (Y);
>> mehta.salil@gmail.com; net...@vger.kernel.org; linux-
>> ker...@vger.kernel.org; linux-r...@vger.kernel.org; Linuxarm
>> Subject: Re: [PATCH V4 net-next 7/8] net: hns3: Add Ethtool support to
>> HNS3 driver
>>
>>
>>
>> On 07/22/2017 03:09 PM, Salil Mehta wrote:
>>> This patch adds the support of the Ethtool interface to
>>> the HNS3 Ethernet driver. Various commands to read the
>>> statistics, configure the offloading, loopback selftest etc.
>>> are supported.
>>>
>>> Signed-off-by: Daode Huang <huangda...@hisilicon.com>
>>> Signed-off-by: lipeng <lipeng...@huawei.com>
>>> Signed-off-by: Salil Mehta <salil.me...@huawei.com>
>>> Signed-off-by: Yisen Zhuang <yisen.zhu...@huawei.com>
>>> ---
>>> Patch V4: addressed below comments
>>>  1. Andrew Lunn
>>> Removed the support of loop PHY back for now
>>> Patch V3: Address below comments
>>>  1. Stephen Hemminger
>>> https://lkml.org/lkml/2017/6/13/974
>>>  2. Andrew Lunn
>>> https://lkml.org/lkml/2017/6/13/1037
>>> Patch V2: No change
>>> Patch V1: Initial Submit
>>> ---
>>>  .../ethernet/hisilicon/hns3/hns3pf/hns3_ethtool.c  | 543
>> +
>>>  1 file changed, 543 insertions(+)
>>>  create mode 100644
>> drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_ethtool.c
>>>
>>> diff --git
>> a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_ethtool.c
>> b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_ethtool.c
>>> new file mode 100644
>>> index ..82b0d4d829f8
>>> --- /dev/null
>>> +++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_ethtool.c
>>> @@ -0,0 +1,543 @@
>>> +/*
>>> + * Copyright (c) 2016~2017 Hisilicon Limited.
>>> + *
>>> + * This program is free software; you can redistribute it and/or
>> modify
>>> + * it under the terms of the GNU General Public License as published
>> by
>>> + * the Free Software Foundation; either version 2 of the License, or
>>> + * (at your option) any later version.
>>> + */
>>> +
>>> +#include 
>>> +#include "hns3_enet.h"
>>> +
>>> +struct hns3_stats {
>>> +   char stats_string[ETH_GSTRING_LEN];
>>> +   int stats_size;
>>> +   int stats_offset;
>>> +};
>>> +
>>> +/* netdev related stats */
>>> +#define HNS3_NETDEV_STAT(_string, _member) \
>>> +   { _string,  \
>>> + FIELD_SIZEOF(struct rtnl_link_stats64, _member),  \
>>> + offsetof(struct rtnl_link_stats64, _member),  \
>>> +   }
>>
>> Can you make this macro use named initializers?
> Can you please explain bit more or point out some
> example. This would be very handy. 

.stat_string = _string,
.stats_size = FIELD_SIZEOF(struct rtnl_link_stat64, _member),
.stats_offset = offsetof(struct rtnl_link_stats64, _member),

https://gcc.gnu.org/onlinedocs/gcc/Designated-Inits.html
-- 
Florian


Re: [PATCH V4 net-next 7/8] net: hns3: Add Ethtool support to HNS3 driver

2017-07-27 Thread Florian Fainelli
On 07/27/2017 11:01 AM, Salil Mehta wrote:
> Hi Florian,
> 
>> -Original Message-
>> From: Florian Fainelli [mailto:f.faine...@gmail.com]
>> Sent: Sunday, July 23, 2017 6:05 PM
>> To: Salil Mehta; da...@davemloft.net
>> Cc: Zhuangyuzeng (Yisen); huangdaode; lipeng (Y);
>> mehta.salil@gmail.com; net...@vger.kernel.org; linux-
>> ker...@vger.kernel.org; linux-r...@vger.kernel.org; Linuxarm
>> Subject: Re: [PATCH V4 net-next 7/8] net: hns3: Add Ethtool support to
>> HNS3 driver
>>
>>
>>
>> On 07/22/2017 03:09 PM, Salil Mehta wrote:
>>> This patch adds the support of the Ethtool interface to
>>> the HNS3 Ethernet driver. Various commands to read the
>>> statistics, configure the offloading, loopback selftest etc.
>>> are supported.
>>>
>>> Signed-off-by: Daode Huang 
>>> Signed-off-by: lipeng 
>>> Signed-off-by: Salil Mehta 
>>> Signed-off-by: Yisen Zhuang 
>>> ---
>>> Patch V4: addressed below comments
>>>  1. Andrew Lunn
>>> Removed the support of loop PHY back for now
>>> Patch V3: Address below comments
>>>  1. Stephen Hemminger
>>> https://lkml.org/lkml/2017/6/13/974
>>>  2. Andrew Lunn
>>> https://lkml.org/lkml/2017/6/13/1037
>>> Patch V2: No change
>>> Patch V1: Initial Submit
>>> ---
>>>  .../ethernet/hisilicon/hns3/hns3pf/hns3_ethtool.c  | 543
>> +
>>>  1 file changed, 543 insertions(+)
>>>  create mode 100644
>> drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_ethtool.c
>>>
>>> diff --git
>> a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_ethtool.c
>> b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_ethtool.c
>>> new file mode 100644
>>> index ..82b0d4d829f8
>>> --- /dev/null
>>> +++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_ethtool.c
>>> @@ -0,0 +1,543 @@
>>> +/*
>>> + * Copyright (c) 2016~2017 Hisilicon Limited.
>>> + *
>>> + * This program is free software; you can redistribute it and/or
>> modify
>>> + * it under the terms of the GNU General Public License as published
>> by
>>> + * the Free Software Foundation; either version 2 of the License, or
>>> + * (at your option) any later version.
>>> + */
>>> +
>>> +#include 
>>> +#include "hns3_enet.h"
>>> +
>>> +struct hns3_stats {
>>> +   char stats_string[ETH_GSTRING_LEN];
>>> +   int stats_size;
>>> +   int stats_offset;
>>> +};
>>> +
>>> +/* netdev related stats */
>>> +#define HNS3_NETDEV_STAT(_string, _member) \
>>> +   { _string,  \
>>> + FIELD_SIZEOF(struct rtnl_link_stats64, _member),  \
>>> + offsetof(struct rtnl_link_stats64, _member),  \
>>> +   }
>>
>> Can you make this macro use named initializers?
> Can you please explain bit more or point out some
> example. This would be very handy. 

.stat_string = _string,
.stats_size = FIELD_SIZEOF(struct rtnl_link_stat64, _member),
.stats_offset = offsetof(struct rtnl_link_stats64, _member),

https://gcc.gnu.org/onlinedocs/gcc/Designated-Inits.html
-- 
Florian


RE: [PATCH V4 net-next 7/8] net: hns3: Add Ethtool support to HNS3 driver

2017-07-27 Thread Salil Mehta
Hi Florian,

> -Original Message-
> From: Florian Fainelli [mailto:f.faine...@gmail.com]
> Sent: Sunday, July 23, 2017 6:05 PM
> To: Salil Mehta; da...@davemloft.net
> Cc: Zhuangyuzeng (Yisen); huangdaode; lipeng (Y);
> mehta.salil@gmail.com; net...@vger.kernel.org; linux-
> ker...@vger.kernel.org; linux-r...@vger.kernel.org; Linuxarm
> Subject: Re: [PATCH V4 net-next 7/8] net: hns3: Add Ethtool support to
> HNS3 driver
> 
> 
> 
> On 07/22/2017 03:09 PM, Salil Mehta wrote:
> > This patch adds the support of the Ethtool interface to
> > the HNS3 Ethernet driver. Various commands to read the
> > statistics, configure the offloading, loopback selftest etc.
> > are supported.
> >
> > Signed-off-by: Daode Huang <huangda...@hisilicon.com>
> > Signed-off-by: lipeng <lipeng...@huawei.com>
> > Signed-off-by: Salil Mehta <salil.me...@huawei.com>
> > Signed-off-by: Yisen Zhuang <yisen.zhu...@huawei.com>
> > ---
> > Patch V4: addressed below comments
> >  1. Andrew Lunn
> > Removed the support of loop PHY back for now
> > Patch V3: Address below comments
> >  1. Stephen Hemminger
> > https://lkml.org/lkml/2017/6/13/974
> >  2. Andrew Lunn
> > https://lkml.org/lkml/2017/6/13/1037
> > Patch V2: No change
> > Patch V1: Initial Submit
> > ---
> >  .../ethernet/hisilicon/hns3/hns3pf/hns3_ethtool.c  | 543
> +
> >  1 file changed, 543 insertions(+)
> >  create mode 100644
> drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_ethtool.c
> >
> > diff --git
> a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_ethtool.c
> b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_ethtool.c
> > new file mode 100644
> > index ..82b0d4d829f8
> > --- /dev/null
> > +++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_ethtool.c
> > @@ -0,0 +1,543 @@
> > +/*
> > + * Copyright (c) 2016~2017 Hisilicon Limited.
> > + *
> > + * This program is free software; you can redistribute it and/or
> modify
> > + * it under the terms of the GNU General Public License as published
> by
> > + * the Free Software Foundation; either version 2 of the License, or
> > + * (at your option) any later version.
> > + */
> > +
> > +#include 
> > +#include "hns3_enet.h"
> > +
> > +struct hns3_stats {
> > +   char stats_string[ETH_GSTRING_LEN];
> > +   int stats_size;
> > +   int stats_offset;
> > +};
> > +
> > +/* netdev related stats */
> > +#define HNS3_NETDEV_STAT(_string, _member) \
> > +   { _string,  \
> > + FIELD_SIZEOF(struct rtnl_link_stats64, _member),  \
> > + offsetof(struct rtnl_link_stats64, _member),  \
> > +   }
> 
> Can you make this macro use named initializers?
Can you please explain bit more or point out some
example. This would be very handy. 

Thanks

> 
> > +
> > +static const struct hns3_stats hns3_netdev_stats[] = {
> > +   /* misc. Rx/Tx statistics */
> > +   HNS3_NETDEV_STAT("rx_packets", rx_packets),
> > +   HNS3_NETDEV_STAT("tx_packets", tx_packets),
> > +   HNS3_NETDEV_STAT("rx_bytes", rx_bytes),
> > +   HNS3_NETDEV_STAT("tx_bytes", tx_bytes),
> > +   HNS3_NETDEV_STAT("rx_errors", rx_errors),
> > +   HNS3_NETDEV_STAT("tx_errors", tx_errors),
> > +   HNS3_NETDEV_STAT("rx_dropped", rx_dropped),
> > +   HNS3_NETDEV_STAT("tx_dropped", tx_dropped),
> > +   HNS3_NETDEV_STAT("multicast", multicast),
> > +   HNS3_NETDEV_STAT("collisions", collisions),
> > +
> > +   /* detailed Rx errors */
> > +   HNS3_NETDEV_STAT("rx_length_errors", rx_length_errors),
> > +   HNS3_NETDEV_STAT("rx_over_errors", rx_over_errors),
> > +   HNS3_NETDEV_STAT("rx_crc_errors", rx_crc_errors),
> > +   HNS3_NETDEV_STAT("rx_frame_errors", rx_frame_errors),
> > +   HNS3_NETDEV_STAT("rx_fifo_errors", rx_fifo_errors),
> > +   HNS3_NETDEV_STAT("rx_missed_errors", rx_missed_errors),
> > +
> > +   /* detailed Tx errors */
> > +   HNS3_NETDEV_STAT("tx_aborted_errors", tx_aborted_errors),
> > +   HNS3_NETDEV_STAT("tx_carrier_errors", tx_carrier_errors),
> > +   HNS3_NETDEV_STAT("tx_fifo_errors", tx_fifo_errors),
> > +   HNS3_NETDEV_STAT("tx_heartbeat_errors", tx_heartbeat_errors),
> > +   HNS3_NETDEV_STAT("tx_window_errors", tx_window_errors),
> > +

RE: [PATCH V4 net-next 7/8] net: hns3: Add Ethtool support to HNS3 driver

2017-07-27 Thread Salil Mehta
Hi Florian,

> -Original Message-
> From: Florian Fainelli [mailto:f.faine...@gmail.com]
> Sent: Sunday, July 23, 2017 6:05 PM
> To: Salil Mehta; da...@davemloft.net
> Cc: Zhuangyuzeng (Yisen); huangdaode; lipeng (Y);
> mehta.salil@gmail.com; net...@vger.kernel.org; linux-
> ker...@vger.kernel.org; linux-r...@vger.kernel.org; Linuxarm
> Subject: Re: [PATCH V4 net-next 7/8] net: hns3: Add Ethtool support to
> HNS3 driver
> 
> 
> 
> On 07/22/2017 03:09 PM, Salil Mehta wrote:
> > This patch adds the support of the Ethtool interface to
> > the HNS3 Ethernet driver. Various commands to read the
> > statistics, configure the offloading, loopback selftest etc.
> > are supported.
> >
> > Signed-off-by: Daode Huang 
> > Signed-off-by: lipeng 
> > Signed-off-by: Salil Mehta 
> > Signed-off-by: Yisen Zhuang 
> > ---
> > Patch V4: addressed below comments
> >  1. Andrew Lunn
> > Removed the support of loop PHY back for now
> > Patch V3: Address below comments
> >  1. Stephen Hemminger
> > https://lkml.org/lkml/2017/6/13/974
> >  2. Andrew Lunn
> > https://lkml.org/lkml/2017/6/13/1037
> > Patch V2: No change
> > Patch V1: Initial Submit
> > ---
> >  .../ethernet/hisilicon/hns3/hns3pf/hns3_ethtool.c  | 543
> +
> >  1 file changed, 543 insertions(+)
> >  create mode 100644
> drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_ethtool.c
> >
> > diff --git
> a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_ethtool.c
> b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_ethtool.c
> > new file mode 100644
> > index ..82b0d4d829f8
> > --- /dev/null
> > +++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_ethtool.c
> > @@ -0,0 +1,543 @@
> > +/*
> > + * Copyright (c) 2016~2017 Hisilicon Limited.
> > + *
> > + * This program is free software; you can redistribute it and/or
> modify
> > + * it under the terms of the GNU General Public License as published
> by
> > + * the Free Software Foundation; either version 2 of the License, or
> > + * (at your option) any later version.
> > + */
> > +
> > +#include 
> > +#include "hns3_enet.h"
> > +
> > +struct hns3_stats {
> > +   char stats_string[ETH_GSTRING_LEN];
> > +   int stats_size;
> > +   int stats_offset;
> > +};
> > +
> > +/* netdev related stats */
> > +#define HNS3_NETDEV_STAT(_string, _member) \
> > +   { _string,  \
> > + FIELD_SIZEOF(struct rtnl_link_stats64, _member),  \
> > + offsetof(struct rtnl_link_stats64, _member),  \
> > +   }
> 
> Can you make this macro use named initializers?
Can you please explain bit more or point out some
example. This would be very handy. 

Thanks

> 
> > +
> > +static const struct hns3_stats hns3_netdev_stats[] = {
> > +   /* misc. Rx/Tx statistics */
> > +   HNS3_NETDEV_STAT("rx_packets", rx_packets),
> > +   HNS3_NETDEV_STAT("tx_packets", tx_packets),
> > +   HNS3_NETDEV_STAT("rx_bytes", rx_bytes),
> > +   HNS3_NETDEV_STAT("tx_bytes", tx_bytes),
> > +   HNS3_NETDEV_STAT("rx_errors", rx_errors),
> > +   HNS3_NETDEV_STAT("tx_errors", tx_errors),
> > +   HNS3_NETDEV_STAT("rx_dropped", rx_dropped),
> > +   HNS3_NETDEV_STAT("tx_dropped", tx_dropped),
> > +   HNS3_NETDEV_STAT("multicast", multicast),
> > +   HNS3_NETDEV_STAT("collisions", collisions),
> > +
> > +   /* detailed Rx errors */
> > +   HNS3_NETDEV_STAT("rx_length_errors", rx_length_errors),
> > +   HNS3_NETDEV_STAT("rx_over_errors", rx_over_errors),
> > +   HNS3_NETDEV_STAT("rx_crc_errors", rx_crc_errors),
> > +   HNS3_NETDEV_STAT("rx_frame_errors", rx_frame_errors),
> > +   HNS3_NETDEV_STAT("rx_fifo_errors", rx_fifo_errors),
> > +   HNS3_NETDEV_STAT("rx_missed_errors", rx_missed_errors),
> > +
> > +   /* detailed Tx errors */
> > +   HNS3_NETDEV_STAT("tx_aborted_errors", tx_aborted_errors),
> > +   HNS3_NETDEV_STAT("tx_carrier_errors", tx_carrier_errors),
> > +   HNS3_NETDEV_STAT("tx_fifo_errors", tx_fifo_errors),
> > +   HNS3_NETDEV_STAT("tx_heartbeat_errors", tx_heartbeat_errors),
> > +   HNS3_NETDEV_STAT("tx_window_errors", tx_window_errors),
> > +
> > +   /* for cslip etc */
> > +   HNS3_NETDEV_STAT("rx_compressed", rx_compressed),
>

RE: [PATCH V4 net-next 7/8] net: hns3: Add Ethtool support to HNS3 driver

2017-07-27 Thread Salil Mehta
Hi Stephen,

> -Original Message-
> From: Stephen Hemminger [mailto:step...@networkplumber.org]
> Sent: Sunday, July 23, 2017 6:26 PM
> To: Salil Mehta
> Cc: da...@davemloft.net; Zhuangyuzeng (Yisen); huangdaode; lipeng (Y);
> mehta.salil@gmail.com; net...@vger.kernel.org; linux-
> ker...@vger.kernel.org; linux-r...@vger.kernel.org; Linuxarm
> Subject: Re: [PATCH V4 net-next 7/8] net: hns3: Add Ethtool support to
> HNS3 driver
> 
> On Sat, 22 Jul 2017 23:09:41 +0100
> Salil Mehta <salil.me...@huawei.com> wrote:
> 
> > +   HNS3_NETDEV_STAT("rx_packets", rx_packets),
> > +   HNS3_NETDEV_STAT("tx_packets", tx_packets),
> > +   HNS3_NETDEV_STAT("rx_bytes", rx_bytes),
> > +   HNS3_NETDEV_STAT("tx_bytes", tx_bytes),
> > +   HNS3_NETDEV_STAT("rx_errors", rx_errors),
> > +   HNS3_NETDEV_STAT("tx_errors", tx_errors),
> > +   HNS3_NETDEV_STAT("rx_dropped", rx_dropped),
> > +   HNS3_NETDEV_STAT("tx_dropped", tx_dropped),
> > +   HNS3_NETDEV_STAT("multicast", multicast),
> > +   HNS3_NETDEV_STAT("collisions", collisions),
> > +
> > +   /* detailed Rx errors */
> 
> Do not put network statistics in ethtool statistics.
> This is redundant and unnecessary. Yes some other drivers may do it
> but it is not best practice.

Ok sure, will remove netdev stats from the ethtool.

Thanks
Salil


RE: [PATCH V4 net-next 7/8] net: hns3: Add Ethtool support to HNS3 driver

2017-07-27 Thread Salil Mehta
Hi Stephen,

> -Original Message-
> From: Stephen Hemminger [mailto:step...@networkplumber.org]
> Sent: Sunday, July 23, 2017 6:26 PM
> To: Salil Mehta
> Cc: da...@davemloft.net; Zhuangyuzeng (Yisen); huangdaode; lipeng (Y);
> mehta.salil@gmail.com; net...@vger.kernel.org; linux-
> ker...@vger.kernel.org; linux-r...@vger.kernel.org; Linuxarm
> Subject: Re: [PATCH V4 net-next 7/8] net: hns3: Add Ethtool support to
> HNS3 driver
> 
> On Sat, 22 Jul 2017 23:09:41 +0100
> Salil Mehta  wrote:
> 
> > +   HNS3_NETDEV_STAT("rx_packets", rx_packets),
> > +   HNS3_NETDEV_STAT("tx_packets", tx_packets),
> > +   HNS3_NETDEV_STAT("rx_bytes", rx_bytes),
> > +   HNS3_NETDEV_STAT("tx_bytes", tx_bytes),
> > +   HNS3_NETDEV_STAT("rx_errors", rx_errors),
> > +   HNS3_NETDEV_STAT("tx_errors", tx_errors),
> > +   HNS3_NETDEV_STAT("rx_dropped", rx_dropped),
> > +   HNS3_NETDEV_STAT("tx_dropped", tx_dropped),
> > +   HNS3_NETDEV_STAT("multicast", multicast),
> > +   HNS3_NETDEV_STAT("collisions", collisions),
> > +
> > +   /* detailed Rx errors */
> 
> Do not put network statistics in ethtool statistics.
> This is redundant and unnecessary. Yes some other drivers may do it
> but it is not best practice.

Ok sure, will remove netdev stats from the ethtool.

Thanks
Salil


RE: [PATCH V4 net-next 7/8] net: hns3: Add Ethtool support to HNS3 driver

2017-07-25 Thread David Laight
From: Rustad, Mark D
> Sent: 24 July 2017 21:32
> > On Jul 23, 2017, at 10:05 AM, Florian Fainelli  wrote:
> >> +
> >> +  strncpy(drvinfo->version, HNAE_DRIVER_VERSION,
> >> +  sizeof(drvinfo->version));
> >> +  drvinfo->version[sizeof(drvinfo->version) - 1] = '\0';
> >
> > strlcpy() would probably do that for you.
> 
> You need to be careful about strlcpy - it does not completely write the 
> destination buffer as strncpy
> does, and so can result in a kernel memory leak if the destination is not 
> known to already be cleared.

Not only that, strlcpy() is defined to return the size of the
source string.
So if the source buffers isn't '\0' terminated it can fault.
(Not a problem above.)

Neither function is the one you were looking for.

David



RE: [PATCH V4 net-next 7/8] net: hns3: Add Ethtool support to HNS3 driver

2017-07-25 Thread David Laight
From: Rustad, Mark D
> Sent: 24 July 2017 21:32
> > On Jul 23, 2017, at 10:05 AM, Florian Fainelli  wrote:
> >> +
> >> +  strncpy(drvinfo->version, HNAE_DRIVER_VERSION,
> >> +  sizeof(drvinfo->version));
> >> +  drvinfo->version[sizeof(drvinfo->version) - 1] = '\0';
> >
> > strlcpy() would probably do that for you.
> 
> You need to be careful about strlcpy - it does not completely write the 
> destination buffer as strncpy
> does, and so can result in a kernel memory leak if the destination is not 
> known to already be cleared.

Not only that, strlcpy() is defined to return the size of the
source string.
So if the source buffers isn't '\0' terminated it can fault.
(Not a problem above.)

Neither function is the one you were looking for.

David



Re: [PATCH V4 net-next 7/8] net: hns3: Add Ethtool support to HNS3 driver

2017-07-24 Thread Rustad, Mark D

> On Jul 23, 2017, at 10:05 AM, Florian Fainelli  wrote:
>> +
>> +strncpy(drvinfo->version, HNAE_DRIVER_VERSION,
>> +sizeof(drvinfo->version));
>> +drvinfo->version[sizeof(drvinfo->version) - 1] = '\0';
> 
> strlcpy() would probably do that for you.

You need to be careful about strlcpy - it does not completely write the 
destination buffer as strncpy does, and so can result in a kernel memory leak 
if the destination is not known to already be cleared.

>> +
>> +strncpy(drvinfo->driver, HNAE_DRIVER_NAME, sizeof(drvinfo->driver));
>> +drvinfo->driver[sizeof(drvinfo->driver) - 1] = '\0';
> 
> Same here

Same here

>> +
>> +strncpy(drvinfo->bus_info, priv->dev->bus->name,
>> +sizeof(drvinfo->bus_info));> +  
>> drvinfo->bus_info[ETHTOOL_BUSINFO_LEN - 1] = '\0';
> 
> And here.

And here too. I haven't looked at this deeply enough to know whether a leak 
could be created by strlcpy here, but I wanted to raise it as something to be 
considered before switching to it. Blindly adopting strlcpy is hazardous as are 
tools that unconditionally recommend it.

--
Mark Rustad, Networking Division, Intel Corporation



signature.asc
Description: Message signed with OpenPGP


Re: [PATCH V4 net-next 7/8] net: hns3: Add Ethtool support to HNS3 driver

2017-07-24 Thread Rustad, Mark D

> On Jul 23, 2017, at 10:05 AM, Florian Fainelli  wrote:
>> +
>> +strncpy(drvinfo->version, HNAE_DRIVER_VERSION,
>> +sizeof(drvinfo->version));
>> +drvinfo->version[sizeof(drvinfo->version) - 1] = '\0';
> 
> strlcpy() would probably do that for you.

You need to be careful about strlcpy - it does not completely write the 
destination buffer as strncpy does, and so can result in a kernel memory leak 
if the destination is not known to already be cleared.

>> +
>> +strncpy(drvinfo->driver, HNAE_DRIVER_NAME, sizeof(drvinfo->driver));
>> +drvinfo->driver[sizeof(drvinfo->driver) - 1] = '\0';
> 
> Same here

Same here

>> +
>> +strncpy(drvinfo->bus_info, priv->dev->bus->name,
>> +sizeof(drvinfo->bus_info));> +  
>> drvinfo->bus_info[ETHTOOL_BUSINFO_LEN - 1] = '\0';
> 
> And here.

And here too. I haven't looked at this deeply enough to know whether a leak 
could be created by strlcpy here, but I wanted to raise it as something to be 
considered before switching to it. Blindly adopting strlcpy is hazardous as are 
tools that unconditionally recommend it.

--
Mark Rustad, Networking Division, Intel Corporation



signature.asc
Description: Message signed with OpenPGP


Re: [PATCH V4 net-next 7/8] net: hns3: Add Ethtool support to HNS3 driver

2017-07-23 Thread Stephen Hemminger
On Sat, 22 Jul 2017 23:09:41 +0100
Salil Mehta  wrote:

> + HNS3_NETDEV_STAT("rx_packets", rx_packets),
> + HNS3_NETDEV_STAT("tx_packets", tx_packets),
> + HNS3_NETDEV_STAT("rx_bytes", rx_bytes),
> + HNS3_NETDEV_STAT("tx_bytes", tx_bytes),
> + HNS3_NETDEV_STAT("rx_errors", rx_errors),
> + HNS3_NETDEV_STAT("tx_errors", tx_errors),
> + HNS3_NETDEV_STAT("rx_dropped", rx_dropped),
> + HNS3_NETDEV_STAT("tx_dropped", tx_dropped),
> + HNS3_NETDEV_STAT("multicast", multicast),
> + HNS3_NETDEV_STAT("collisions", collisions),
> +
> + /* detailed Rx errors */

Do not put network statistics in ethtool statistics.
This is redundant and unnecessary. Yes some other drivers may do it
but it is not best practice.


Re: [PATCH V4 net-next 7/8] net: hns3: Add Ethtool support to HNS3 driver

2017-07-23 Thread Stephen Hemminger
On Sat, 22 Jul 2017 23:09:41 +0100
Salil Mehta  wrote:

> + HNS3_NETDEV_STAT("rx_packets", rx_packets),
> + HNS3_NETDEV_STAT("tx_packets", tx_packets),
> + HNS3_NETDEV_STAT("rx_bytes", rx_bytes),
> + HNS3_NETDEV_STAT("tx_bytes", tx_bytes),
> + HNS3_NETDEV_STAT("rx_errors", rx_errors),
> + HNS3_NETDEV_STAT("tx_errors", tx_errors),
> + HNS3_NETDEV_STAT("rx_dropped", rx_dropped),
> + HNS3_NETDEV_STAT("tx_dropped", tx_dropped),
> + HNS3_NETDEV_STAT("multicast", multicast),
> + HNS3_NETDEV_STAT("collisions", collisions),
> +
> + /* detailed Rx errors */

Do not put network statistics in ethtool statistics.
This is redundant and unnecessary. Yes some other drivers may do it
but it is not best practice.


Re: [PATCH V4 net-next 7/8] net: hns3: Add Ethtool support to HNS3 driver

2017-07-23 Thread Florian Fainelli


On 07/22/2017 03:09 PM, Salil Mehta wrote:
> This patch adds the support of the Ethtool interface to
> the HNS3 Ethernet driver. Various commands to read the
> statistics, configure the offloading, loopback selftest etc.
> are supported.
> 
> Signed-off-by: Daode Huang 
> Signed-off-by: lipeng 
> Signed-off-by: Salil Mehta 
> Signed-off-by: Yisen Zhuang 
> ---
> Patch V4: addressed below comments
>  1. Andrew Lunn
> Removed the support of loop PHY back for now
> Patch V3: Address below comments
>  1. Stephen Hemminger
> https://lkml.org/lkml/2017/6/13/974
>  2. Andrew Lunn
> https://lkml.org/lkml/2017/6/13/1037
> Patch V2: No change
> Patch V1: Initial Submit
> ---
>  .../ethernet/hisilicon/hns3/hns3pf/hns3_ethtool.c  | 543 
> +
>  1 file changed, 543 insertions(+)
>  create mode 100644 drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_ethtool.c
> 
> diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_ethtool.c 
> b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_ethtool.c
> new file mode 100644
> index ..82b0d4d829f8
> --- /dev/null
> +++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_ethtool.c
> @@ -0,0 +1,543 @@
> +/*
> + * Copyright (c) 2016~2017 Hisilicon Limited.
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation; either version 2 of the License, or
> + * (at your option) any later version.
> + */
> +
> +#include 
> +#include "hns3_enet.h"
> +
> +struct hns3_stats {
> + char stats_string[ETH_GSTRING_LEN];
> + int stats_size;
> + int stats_offset;
> +};
> +
> +/* netdev related stats */
> +#define HNS3_NETDEV_STAT(_string, _member)   \
> + { _string,  \
> +   FIELD_SIZEOF(struct rtnl_link_stats64, _member),  \
> +   offsetof(struct rtnl_link_stats64, _member),  \
> + }

Can you make this macro use named initializers?

> +
> +static const struct hns3_stats hns3_netdev_stats[] = {
> + /* misc. Rx/Tx statistics */
> + HNS3_NETDEV_STAT("rx_packets", rx_packets),
> + HNS3_NETDEV_STAT("tx_packets", tx_packets),
> + HNS3_NETDEV_STAT("rx_bytes", rx_bytes),
> + HNS3_NETDEV_STAT("tx_bytes", tx_bytes),
> + HNS3_NETDEV_STAT("rx_errors", rx_errors),
> + HNS3_NETDEV_STAT("tx_errors", tx_errors),
> + HNS3_NETDEV_STAT("rx_dropped", rx_dropped),
> + HNS3_NETDEV_STAT("tx_dropped", tx_dropped),
> + HNS3_NETDEV_STAT("multicast", multicast),
> + HNS3_NETDEV_STAT("collisions", collisions),
> +
> + /* detailed Rx errors */
> + HNS3_NETDEV_STAT("rx_length_errors", rx_length_errors),
> + HNS3_NETDEV_STAT("rx_over_errors", rx_over_errors),
> + HNS3_NETDEV_STAT("rx_crc_errors", rx_crc_errors),
> + HNS3_NETDEV_STAT("rx_frame_errors", rx_frame_errors),
> + HNS3_NETDEV_STAT("rx_fifo_errors", rx_fifo_errors),
> + HNS3_NETDEV_STAT("rx_missed_errors", rx_missed_errors),
> +
> + /* detailed Tx errors */
> + HNS3_NETDEV_STAT("tx_aborted_errors", tx_aborted_errors),
> + HNS3_NETDEV_STAT("tx_carrier_errors", tx_carrier_errors),
> + HNS3_NETDEV_STAT("tx_fifo_errors", tx_fifo_errors),
> + HNS3_NETDEV_STAT("tx_heartbeat_errors", tx_heartbeat_errors),
> + HNS3_NETDEV_STAT("tx_window_errors", tx_window_errors),
> +
> + /* for cslip etc */
> + HNS3_NETDEV_STAT("rx_compressed", rx_compressed),
> + HNS3_NETDEV_STAT("tx_compressed", tx_compressed),
> +};
> +
> +#define HNS3_NETDEV_STATS_COUNT ARRAY_SIZE(hns3_netdev_stats)
> +
> +/* tqp related stats */
> +#define HNS3_TQP_STAT(_string, _member)  \
> + { _string,  \
> +   FIELD_SIZEOF(struct ring_stats, _member), \
> +   offsetof(struct hns3_enet_ring, stats),   \
> + }
> +

Same here.

> +static const struct hns3_stats hns3_txq_stats[] = {
> + /* Tx per-queue statistics */
> + HNS3_TQP_STAT("tx_io_err_cnt", io_err_cnt),
> + HNS3_TQP_STAT("tx_sw_err_cnt", sw_err_cnt),
> + HNS3_TQP_STAT("tx_seg_pkt_cnt", seg_pkt_cnt),
> + HNS3_TQP_STAT("tx_pkts", tx_pkts),
> + HNS3_TQP_STAT("tx_bytes", tx_bytes),
> + HNS3_TQP_STAT("tx_err_cnt", tx_err_cnt),
> + HNS3_TQP_STAT("tx_restart_queue", restart_queue),
> + HNS3_TQP_STAT("tx_busy", tx_busy),
> +};
> +
> +#define HNS3_TXQ_STATS_COUNT ARRAY_SIZE(hns3_txq_stats)
> +
> +static const struct hns3_stats hns3_rxq_stats[] = {
> + /* Rx per-queue statistics */
> + HNS3_TQP_STAT("rx_io_err_cnt", io_err_cnt),
> + HNS3_TQP_STAT("rx_sw_err_cnt", sw_err_cnt),
> + HNS3_TQP_STAT("rx_seg_pkt_cnt", seg_pkt_cnt),
> + HNS3_TQP_STAT("rx_pkts", rx_pkts),
> + HNS3_TQP_STAT("rx_bytes", rx_bytes),
> + 

Re: [PATCH V4 net-next 7/8] net: hns3: Add Ethtool support to HNS3 driver

2017-07-23 Thread Florian Fainelli


On 07/22/2017 03:09 PM, Salil Mehta wrote:
> This patch adds the support of the Ethtool interface to
> the HNS3 Ethernet driver. Various commands to read the
> statistics, configure the offloading, loopback selftest etc.
> are supported.
> 
> Signed-off-by: Daode Huang 
> Signed-off-by: lipeng 
> Signed-off-by: Salil Mehta 
> Signed-off-by: Yisen Zhuang 
> ---
> Patch V4: addressed below comments
>  1. Andrew Lunn
> Removed the support of loop PHY back for now
> Patch V3: Address below comments
>  1. Stephen Hemminger
> https://lkml.org/lkml/2017/6/13/974
>  2. Andrew Lunn
> https://lkml.org/lkml/2017/6/13/1037
> Patch V2: No change
> Patch V1: Initial Submit
> ---
>  .../ethernet/hisilicon/hns3/hns3pf/hns3_ethtool.c  | 543 
> +
>  1 file changed, 543 insertions(+)
>  create mode 100644 drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_ethtool.c
> 
> diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_ethtool.c 
> b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_ethtool.c
> new file mode 100644
> index ..82b0d4d829f8
> --- /dev/null
> +++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_ethtool.c
> @@ -0,0 +1,543 @@
> +/*
> + * Copyright (c) 2016~2017 Hisilicon Limited.
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation; either version 2 of the License, or
> + * (at your option) any later version.
> + */
> +
> +#include 
> +#include "hns3_enet.h"
> +
> +struct hns3_stats {
> + char stats_string[ETH_GSTRING_LEN];
> + int stats_size;
> + int stats_offset;
> +};
> +
> +/* netdev related stats */
> +#define HNS3_NETDEV_STAT(_string, _member)   \
> + { _string,  \
> +   FIELD_SIZEOF(struct rtnl_link_stats64, _member),  \
> +   offsetof(struct rtnl_link_stats64, _member),  \
> + }

Can you make this macro use named initializers?

> +
> +static const struct hns3_stats hns3_netdev_stats[] = {
> + /* misc. Rx/Tx statistics */
> + HNS3_NETDEV_STAT("rx_packets", rx_packets),
> + HNS3_NETDEV_STAT("tx_packets", tx_packets),
> + HNS3_NETDEV_STAT("rx_bytes", rx_bytes),
> + HNS3_NETDEV_STAT("tx_bytes", tx_bytes),
> + HNS3_NETDEV_STAT("rx_errors", rx_errors),
> + HNS3_NETDEV_STAT("tx_errors", tx_errors),
> + HNS3_NETDEV_STAT("rx_dropped", rx_dropped),
> + HNS3_NETDEV_STAT("tx_dropped", tx_dropped),
> + HNS3_NETDEV_STAT("multicast", multicast),
> + HNS3_NETDEV_STAT("collisions", collisions),
> +
> + /* detailed Rx errors */
> + HNS3_NETDEV_STAT("rx_length_errors", rx_length_errors),
> + HNS3_NETDEV_STAT("rx_over_errors", rx_over_errors),
> + HNS3_NETDEV_STAT("rx_crc_errors", rx_crc_errors),
> + HNS3_NETDEV_STAT("rx_frame_errors", rx_frame_errors),
> + HNS3_NETDEV_STAT("rx_fifo_errors", rx_fifo_errors),
> + HNS3_NETDEV_STAT("rx_missed_errors", rx_missed_errors),
> +
> + /* detailed Tx errors */
> + HNS3_NETDEV_STAT("tx_aborted_errors", tx_aborted_errors),
> + HNS3_NETDEV_STAT("tx_carrier_errors", tx_carrier_errors),
> + HNS3_NETDEV_STAT("tx_fifo_errors", tx_fifo_errors),
> + HNS3_NETDEV_STAT("tx_heartbeat_errors", tx_heartbeat_errors),
> + HNS3_NETDEV_STAT("tx_window_errors", tx_window_errors),
> +
> + /* for cslip etc */
> + HNS3_NETDEV_STAT("rx_compressed", rx_compressed),
> + HNS3_NETDEV_STAT("tx_compressed", tx_compressed),
> +};
> +
> +#define HNS3_NETDEV_STATS_COUNT ARRAY_SIZE(hns3_netdev_stats)
> +
> +/* tqp related stats */
> +#define HNS3_TQP_STAT(_string, _member)  \
> + { _string,  \
> +   FIELD_SIZEOF(struct ring_stats, _member), \
> +   offsetof(struct hns3_enet_ring, stats),   \
> + }
> +

Same here.

> +static const struct hns3_stats hns3_txq_stats[] = {
> + /* Tx per-queue statistics */
> + HNS3_TQP_STAT("tx_io_err_cnt", io_err_cnt),
> + HNS3_TQP_STAT("tx_sw_err_cnt", sw_err_cnt),
> + HNS3_TQP_STAT("tx_seg_pkt_cnt", seg_pkt_cnt),
> + HNS3_TQP_STAT("tx_pkts", tx_pkts),
> + HNS3_TQP_STAT("tx_bytes", tx_bytes),
> + HNS3_TQP_STAT("tx_err_cnt", tx_err_cnt),
> + HNS3_TQP_STAT("tx_restart_queue", restart_queue),
> + HNS3_TQP_STAT("tx_busy", tx_busy),
> +};
> +
> +#define HNS3_TXQ_STATS_COUNT ARRAY_SIZE(hns3_txq_stats)
> +
> +static const struct hns3_stats hns3_rxq_stats[] = {
> + /* Rx per-queue statistics */
> + HNS3_TQP_STAT("rx_io_err_cnt", io_err_cnt),
> + HNS3_TQP_STAT("rx_sw_err_cnt", sw_err_cnt),
> + HNS3_TQP_STAT("rx_seg_pkt_cnt", seg_pkt_cnt),
> + HNS3_TQP_STAT("rx_pkts", rx_pkts),
> + HNS3_TQP_STAT("rx_bytes", rx_bytes),
> + HNS3_TQP_STAT("rx_err_cnt", rx_err_cnt),
> + HNS3_TQP_STAT("rx_reuse_pg_cnt", reuse_pg_cnt),
> + 

[PATCH V4 net-next 7/8] net: hns3: Add Ethtool support to HNS3 driver

2017-07-22 Thread Salil Mehta
This patch adds the support of the Ethtool interface to
the HNS3 Ethernet driver. Various commands to read the
statistics, configure the offloading, loopback selftest etc.
are supported.

Signed-off-by: Daode Huang 
Signed-off-by: lipeng 
Signed-off-by: Salil Mehta 
Signed-off-by: Yisen Zhuang 
---
Patch V4: addressed below comments
 1. Andrew Lunn
Removed the support of loop PHY back for now
Patch V3: Address below comments
 1. Stephen Hemminger
https://lkml.org/lkml/2017/6/13/974
 2. Andrew Lunn
https://lkml.org/lkml/2017/6/13/1037
Patch V2: No change
Patch V1: Initial Submit
---
 .../ethernet/hisilicon/hns3/hns3pf/hns3_ethtool.c  | 543 +
 1 file changed, 543 insertions(+)
 create mode 100644 drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_ethtool.c

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_ethtool.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_ethtool.c
new file mode 100644
index ..82b0d4d829f8
--- /dev/null
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_ethtool.c
@@ -0,0 +1,543 @@
+/*
+ * Copyright (c) 2016~2017 Hisilicon Limited.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+#include 
+#include "hns3_enet.h"
+
+struct hns3_stats {
+   char stats_string[ETH_GSTRING_LEN];
+   int stats_size;
+   int stats_offset;
+};
+
+/* netdev related stats */
+#define HNS3_NETDEV_STAT(_string, _member) \
+   { _string,  \
+ FIELD_SIZEOF(struct rtnl_link_stats64, _member),  \
+ offsetof(struct rtnl_link_stats64, _member),  \
+   }
+
+static const struct hns3_stats hns3_netdev_stats[] = {
+   /* misc. Rx/Tx statistics */
+   HNS3_NETDEV_STAT("rx_packets", rx_packets),
+   HNS3_NETDEV_STAT("tx_packets", tx_packets),
+   HNS3_NETDEV_STAT("rx_bytes", rx_bytes),
+   HNS3_NETDEV_STAT("tx_bytes", tx_bytes),
+   HNS3_NETDEV_STAT("rx_errors", rx_errors),
+   HNS3_NETDEV_STAT("tx_errors", tx_errors),
+   HNS3_NETDEV_STAT("rx_dropped", rx_dropped),
+   HNS3_NETDEV_STAT("tx_dropped", tx_dropped),
+   HNS3_NETDEV_STAT("multicast", multicast),
+   HNS3_NETDEV_STAT("collisions", collisions),
+
+   /* detailed Rx errors */
+   HNS3_NETDEV_STAT("rx_length_errors", rx_length_errors),
+   HNS3_NETDEV_STAT("rx_over_errors", rx_over_errors),
+   HNS3_NETDEV_STAT("rx_crc_errors", rx_crc_errors),
+   HNS3_NETDEV_STAT("rx_frame_errors", rx_frame_errors),
+   HNS3_NETDEV_STAT("rx_fifo_errors", rx_fifo_errors),
+   HNS3_NETDEV_STAT("rx_missed_errors", rx_missed_errors),
+
+   /* detailed Tx errors */
+   HNS3_NETDEV_STAT("tx_aborted_errors", tx_aborted_errors),
+   HNS3_NETDEV_STAT("tx_carrier_errors", tx_carrier_errors),
+   HNS3_NETDEV_STAT("tx_fifo_errors", tx_fifo_errors),
+   HNS3_NETDEV_STAT("tx_heartbeat_errors", tx_heartbeat_errors),
+   HNS3_NETDEV_STAT("tx_window_errors", tx_window_errors),
+
+   /* for cslip etc */
+   HNS3_NETDEV_STAT("rx_compressed", rx_compressed),
+   HNS3_NETDEV_STAT("tx_compressed", tx_compressed),
+};
+
+#define HNS3_NETDEV_STATS_COUNT ARRAY_SIZE(hns3_netdev_stats)
+
+/* tqp related stats */
+#define HNS3_TQP_STAT(_string, _member)\
+   { _string,  \
+ FIELD_SIZEOF(struct ring_stats, _member), \
+ offsetof(struct hns3_enet_ring, stats),   \
+   }
+
+static const struct hns3_stats hns3_txq_stats[] = {
+   /* Tx per-queue statistics */
+   HNS3_TQP_STAT("tx_io_err_cnt", io_err_cnt),
+   HNS3_TQP_STAT("tx_sw_err_cnt", sw_err_cnt),
+   HNS3_TQP_STAT("tx_seg_pkt_cnt", seg_pkt_cnt),
+   HNS3_TQP_STAT("tx_pkts", tx_pkts),
+   HNS3_TQP_STAT("tx_bytes", tx_bytes),
+   HNS3_TQP_STAT("tx_err_cnt", tx_err_cnt),
+   HNS3_TQP_STAT("tx_restart_queue", restart_queue),
+   HNS3_TQP_STAT("tx_busy", tx_busy),
+};
+
+#define HNS3_TXQ_STATS_COUNT ARRAY_SIZE(hns3_txq_stats)
+
+static const struct hns3_stats hns3_rxq_stats[] = {
+   /* Rx per-queue statistics */
+   HNS3_TQP_STAT("rx_io_err_cnt", io_err_cnt),
+   HNS3_TQP_STAT("rx_sw_err_cnt", sw_err_cnt),
+   HNS3_TQP_STAT("rx_seg_pkt_cnt", seg_pkt_cnt),
+   HNS3_TQP_STAT("rx_pkts", rx_pkts),
+   HNS3_TQP_STAT("rx_bytes", rx_bytes),
+   HNS3_TQP_STAT("rx_err_cnt", rx_err_cnt),
+   HNS3_TQP_STAT("rx_reuse_pg_cnt", reuse_pg_cnt),
+   HNS3_TQP_STAT("rx_err_pkt_len", err_pkt_len),
+   HNS3_TQP_STAT("rx_non_vld_descs", non_vld_descs),
+   HNS3_TQP_STAT("rx_err_bd_num", err_bd_num),
+ 

[PATCH V4 net-next 7/8] net: hns3: Add Ethtool support to HNS3 driver

2017-07-22 Thread Salil Mehta
This patch adds the support of the Ethtool interface to
the HNS3 Ethernet driver. Various commands to read the
statistics, configure the offloading, loopback selftest etc.
are supported.

Signed-off-by: Daode Huang 
Signed-off-by: lipeng 
Signed-off-by: Salil Mehta 
Signed-off-by: Yisen Zhuang 
---
Patch V4: addressed below comments
 1. Andrew Lunn
Removed the support of loop PHY back for now
Patch V3: Address below comments
 1. Stephen Hemminger
https://lkml.org/lkml/2017/6/13/974
 2. Andrew Lunn
https://lkml.org/lkml/2017/6/13/1037
Patch V2: No change
Patch V1: Initial Submit
---
 .../ethernet/hisilicon/hns3/hns3pf/hns3_ethtool.c  | 543 +
 1 file changed, 543 insertions(+)
 create mode 100644 drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_ethtool.c

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_ethtool.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_ethtool.c
new file mode 100644
index ..82b0d4d829f8
--- /dev/null
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_ethtool.c
@@ -0,0 +1,543 @@
+/*
+ * Copyright (c) 2016~2017 Hisilicon Limited.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+#include 
+#include "hns3_enet.h"
+
+struct hns3_stats {
+   char stats_string[ETH_GSTRING_LEN];
+   int stats_size;
+   int stats_offset;
+};
+
+/* netdev related stats */
+#define HNS3_NETDEV_STAT(_string, _member) \
+   { _string,  \
+ FIELD_SIZEOF(struct rtnl_link_stats64, _member),  \
+ offsetof(struct rtnl_link_stats64, _member),  \
+   }
+
+static const struct hns3_stats hns3_netdev_stats[] = {
+   /* misc. Rx/Tx statistics */
+   HNS3_NETDEV_STAT("rx_packets", rx_packets),
+   HNS3_NETDEV_STAT("tx_packets", tx_packets),
+   HNS3_NETDEV_STAT("rx_bytes", rx_bytes),
+   HNS3_NETDEV_STAT("tx_bytes", tx_bytes),
+   HNS3_NETDEV_STAT("rx_errors", rx_errors),
+   HNS3_NETDEV_STAT("tx_errors", tx_errors),
+   HNS3_NETDEV_STAT("rx_dropped", rx_dropped),
+   HNS3_NETDEV_STAT("tx_dropped", tx_dropped),
+   HNS3_NETDEV_STAT("multicast", multicast),
+   HNS3_NETDEV_STAT("collisions", collisions),
+
+   /* detailed Rx errors */
+   HNS3_NETDEV_STAT("rx_length_errors", rx_length_errors),
+   HNS3_NETDEV_STAT("rx_over_errors", rx_over_errors),
+   HNS3_NETDEV_STAT("rx_crc_errors", rx_crc_errors),
+   HNS3_NETDEV_STAT("rx_frame_errors", rx_frame_errors),
+   HNS3_NETDEV_STAT("rx_fifo_errors", rx_fifo_errors),
+   HNS3_NETDEV_STAT("rx_missed_errors", rx_missed_errors),
+
+   /* detailed Tx errors */
+   HNS3_NETDEV_STAT("tx_aborted_errors", tx_aborted_errors),
+   HNS3_NETDEV_STAT("tx_carrier_errors", tx_carrier_errors),
+   HNS3_NETDEV_STAT("tx_fifo_errors", tx_fifo_errors),
+   HNS3_NETDEV_STAT("tx_heartbeat_errors", tx_heartbeat_errors),
+   HNS3_NETDEV_STAT("tx_window_errors", tx_window_errors),
+
+   /* for cslip etc */
+   HNS3_NETDEV_STAT("rx_compressed", rx_compressed),
+   HNS3_NETDEV_STAT("tx_compressed", tx_compressed),
+};
+
+#define HNS3_NETDEV_STATS_COUNT ARRAY_SIZE(hns3_netdev_stats)
+
+/* tqp related stats */
+#define HNS3_TQP_STAT(_string, _member)\
+   { _string,  \
+ FIELD_SIZEOF(struct ring_stats, _member), \
+ offsetof(struct hns3_enet_ring, stats),   \
+   }
+
+static const struct hns3_stats hns3_txq_stats[] = {
+   /* Tx per-queue statistics */
+   HNS3_TQP_STAT("tx_io_err_cnt", io_err_cnt),
+   HNS3_TQP_STAT("tx_sw_err_cnt", sw_err_cnt),
+   HNS3_TQP_STAT("tx_seg_pkt_cnt", seg_pkt_cnt),
+   HNS3_TQP_STAT("tx_pkts", tx_pkts),
+   HNS3_TQP_STAT("tx_bytes", tx_bytes),
+   HNS3_TQP_STAT("tx_err_cnt", tx_err_cnt),
+   HNS3_TQP_STAT("tx_restart_queue", restart_queue),
+   HNS3_TQP_STAT("tx_busy", tx_busy),
+};
+
+#define HNS3_TXQ_STATS_COUNT ARRAY_SIZE(hns3_txq_stats)
+
+static const struct hns3_stats hns3_rxq_stats[] = {
+   /* Rx per-queue statistics */
+   HNS3_TQP_STAT("rx_io_err_cnt", io_err_cnt),
+   HNS3_TQP_STAT("rx_sw_err_cnt", sw_err_cnt),
+   HNS3_TQP_STAT("rx_seg_pkt_cnt", seg_pkt_cnt),
+   HNS3_TQP_STAT("rx_pkts", rx_pkts),
+   HNS3_TQP_STAT("rx_bytes", rx_bytes),
+   HNS3_TQP_STAT("rx_err_cnt", rx_err_cnt),
+   HNS3_TQP_STAT("rx_reuse_pg_cnt", reuse_pg_cnt),
+   HNS3_TQP_STAT("rx_err_pkt_len", err_pkt_len),
+   HNS3_TQP_STAT("rx_non_vld_descs", non_vld_descs),
+   HNS3_TQP_STAT("rx_err_bd_num", err_bd_num),
+   HNS3_TQP_STAT("rx_l2_err", l2_err),
+   HNS3_TQP_STAT("rx_l3l4_csum_err", l3l4_csum_err),