Re: [RFC/RFT PATCH 4/4] [debug] ARM: am335x: illustrate hwstamp

2017-06-13 Thread Tony Lindgren
* Grygorii Strashko  [170613 16:20]:
> This patch allows to test CPTS HW_TS_PUSH functionality on am335x boards
> 
> below sequence of commands will enable Timer7 to trigger 1sec
> periodic pulses on CPTS HW4_TS_PUSH input pin:
> 
>  # echo 10 > /sys/class/pwm/pwmchip0/pwm0/period
>  # echo 5 > /sys/class/pwm/pwmchip0/pwm0/duty_cycle
>  # echo 1 > /sys/class/pwm/pwmchip0/pwm0/enable
>  # ./ptp/testptp -e 10 -i 3
> external time stamp request okay
> event index 3 at 1493259028.376600798
> event index 3 at 1493259029.377170898
> event index 3 at 1493259030.377741039
> event index 3 at 1493259031.378311139
> event index 3 at 1493259032.378881279
> event index 3 at 1493259033.379451424
> event index 3 at 1493259034.380021520
> event index 3 at 1493259035.380591660
> event index 3 at 1493259036.381161765
> event index 3 at 1493259037.381731909

Cool :)

Acked-by: Tony Lindgren 


Re: [PATCH] ip6_tunnel: Correct tos value in collect_md mode

2017-06-13 Thread Peter Dawson
On Wed, 14 Jun 2017 10:54:31 +0800
严海双  wrote:


> > Changes since v2:
> >  * mask key->tos with RT_TOS() suggested by Daniel

Can you help me understand the rationale for this change? Is there are bug 
introduced by dsfield = ip6_tclass(key->label); ?

The RT_TOS masks out 4bits of the 8bit tos field in accordance with RFC1349 
(obsoleted by RFC2474). IPv6 does not have a TOS field. So it dosen't make 
sense to apply a TOS value to the outer header of an IPv6 tunnel.



Re: [PATCH v2 net-next 8/9] bpf: nfp: Report bpf_prog ID during XDP_QUERY_PROG

2017-06-13 Thread Jakub Kicinski
On Tue, 13 Jun 2017 20:19:53 -0700, Martin KaFai Lau wrote:
> On Tue, Jun 13, 2017 at 07:19:50PM -0700, Jakub Kicinski wrote:
> > On Tue, 13 Jun 2017 17:37:50 -0700, Martin KaFai Lau wrote:  
> > > On Tue, Jun 13, 2017 at 04:52:32PM -0700, Jakub Kicinski wrote:  
> > > > On Tue, 13 Jun 2017 14:08:40 -0700, Martin KaFai Lau wrote:  
> > > > > - case XDP_QUERY_PROG:
> > > > > - xdp->prog_attached = !!nn->dp.xdp_prog;
> > > > > + case XDP_QUERY_PROG: {
> > > > > + const struct bpf_prog *xdp_prog;
> > > > > +
> > > > > + xdp_prog = nn->dp.xdp_prog;
> > > > > + if (xdp_prog) {
> > > > > + xdp->prog_id = xdp_prog->aux->id;
> > > > > + xdp->prog_attached = true;
> > > > > + } else {
> > > > > + xdp->prog_id = 0;
> > > > > + xdp->prog_attached = false;
> > > > > + }
> > > > >   return 0;
> > > > > + }  
> > > >
> > > > I'm sorry to nit pick but it could be done on a single line:
> > > >
> > > > case XDP_QUERY_PROG:
> > > > xdp->prog_attached = !!nn->dp.xdp_prog;
> > > > +   xdp->prog_id = nn->dp.xdp_prog ? 
> > > > nn->dp.xdp_prog->aux->id : 0;
> > > > return 0;
> > > > default:
> > > > return -EINVAL;  
> > > OK...
> > >  
> > > >
> > > >
> > > > What would be even cooler is a helper like this:
> > > >
> > > > static inline u32 bpf_prog_id(struct bpf_prog *prog)
> > > > {
> > > > if (!prog)
> > > > return 0;
> > > > return prog->aux->id;
> > > > }
> > > >
> > > > in linux/bpf.h.  
> > > Good idea.  
> >
> > You may actually have to add that into a source file, because bpf.h
> > does not know the definition of struct bpf_prog :(  
> Yeah. filter.h seems not working well either.
> It looks good to me at the first thought.  After a second thought,
> in the future, I am not so sure having a getter for every fields
> in bpf_prog.

Yes, if it's not a static inline it's far less appealing...
 
> I can put bpf_prog_id() in nfp_net_common.c only.
> or do 'xdp->prog_id = nn->dp.xdp_prog ? nn->dp.xdp_prog->aux->id : 0;'
> as you suggested earlier also.
> I am fine either way.  Your call ;)

OK, let's do the ternary operator version then :)  Sorry for leading you
into this dead end.


Re: [PATCH v2 net-next 8/9] bpf: nfp: Report bpf_prog ID during XDP_QUERY_PROG

2017-06-13 Thread Martin KaFai Lau
On Tue, Jun 13, 2017 at 07:19:50PM -0700, Jakub Kicinski wrote:
> On Tue, 13 Jun 2017 17:37:50 -0700, Martin KaFai Lau wrote:
> > On Tue, Jun 13, 2017 at 04:52:32PM -0700, Jakub Kicinski wrote:
> > > On Tue, 13 Jun 2017 14:08:40 -0700, Martin KaFai Lau wrote:
> > > > -   case XDP_QUERY_PROG:
> > > > -   xdp->prog_attached = !!nn->dp.xdp_prog;
> > > > +   case XDP_QUERY_PROG: {
> > > > +   const struct bpf_prog *xdp_prog;
> > > > +
> > > > +   xdp_prog = nn->dp.xdp_prog;
> > > > +   if (xdp_prog) {
> > > > +   xdp->prog_id = xdp_prog->aux->id;
> > > > +   xdp->prog_attached = true;
> > > > +   } else {
> > > > +   xdp->prog_id = 0;
> > > > +   xdp->prog_attached = false;
> > > > +   }
> > > > return 0;
> > > > +   }
> > >
> > > I'm sorry to nit pick but it could be done on a single line:
> > >
> > >   case XDP_QUERY_PROG:
> > >   xdp->prog_attached = !!nn->dp.xdp_prog;
> > > + xdp->prog_id = nn->dp.xdp_prog ? nn->dp.xdp_prog->aux->id : 0;
> > >   return 0;
> > >   default:
> > >   return -EINVAL;
> > OK...
> >
> > >
> > >
> > > What would be even cooler is a helper like this:
> > >
> > > static inline u32 bpf_prog_id(struct bpf_prog *prog)
> > > {
> > >   if (!prog)
> > >   return 0;
> > >   return prog->aux->id;
> > > }
> > >
> > > in linux/bpf.h.
> > Good idea.
>
> You may actually have to add that into a source file, because bpf.h
> does not know the definition of struct bpf_prog :(
Yeah. filter.h seems not working well either.
It looks good to me at the first thought.  After a second thought,
in the future, I am not so sure having a getter for every fields
in bpf_prog.

I can put bpf_prog_id() in nfp_net_common.c only.
or do 'xdp->prog_id = nn->dp.xdp_prog ? nn->dp.xdp_prog->aux->id : 0;'
as you suggested earlier also.
I am fine either way.  Your call ;)

>
> > I had been thinking I may not need to change all the
> > drivers now.  I did that in v1 because I wanted to remove
> > prog_attached which is redundant.  With prog_attached reserved,
> > prog_id is optional.
> >
> > Considering I don't have all the hardwares to test it,  I think
> > it may make more sense for me to only change the HW that I have?
>
> Coccinelle to the rescue?
>
> @@
> expression ex;
> @@
>   xdp->prog_attached = !!(ex);
> + xdp->prog_id = bpf_prog_id(ex);
Good to know Coccinelle.  First hit in my browser ;)

Changing it is fine.  I meant I cannot test it without the HW but
they are at least compiler tested now.

Regardless, I think I will give it one more try in v3.


Re: [PATCH V2 net-next 6/8] net: hns3: Add MDIO support to HNS3 Ethernet driver for hip08 SoC

2017-06-13 Thread Andrew Lunn
> + if (le16_to_cpu(HCLGE_MDIO_STA_VAL(mdio_cmd->sta))) {
> + dev_err(>pdev->dev, "mdio read data error\n");
> + return -ENOMEM;
> + }

If it is not zero, it is an error. !0 is always !0, big or little
endian, so there is no point doing the le16_to_cpu().

Where is the memory allocation which failed?

  Andrew


Re: [PATCH] ip6_tunnel: Correct tos value in collect_md mode

2017-06-13 Thread 严海双


> On 14 Jun 2017, at 10:48 AM, Haishuang Yan 
>  wrote:
> 
> Same as ip_gre, geneve and vxlan, use key->tos as tos value.
> 
> CC: Peter Dawson 
> Fixes: 0e9a709560db ("ip6_tunnel, ip6_gre: fix setting of DSCP on
> encapsulated packets”)
> Suggested-by: Daniel Borkmann 
> Signed-off-by: Haishuang Yan 
> 
> ---
> Changes since v2:
>  * Add fixes information
>  * mask key->tos with RT_TOS() suggested by Daniel
> ---
> net/ipv6/ip6_tunnel.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
> index ef99d59..6400726 100644
> --- a/net/ipv6/ip6_tunnel.c
> +++ b/net/ipv6/ip6_tunnel.c
> @@ -1249,7 +1249,7 @@ int ip6_tnl_xmit(struct sk_buff *skb, struct net_device 
> *dev, __u8 dsfield,
>   fl6.flowi6_proto = IPPROTO_IPIP;
>   fl6.daddr = key->u.ipv6.dst;
>   fl6.flowlabel = key->label;
> - dsfield = ip6_tclass(key->label);
> + dsfield =  RT_TOS(key->tos);
>   } else {
>   if (!(t->parms.flags & IP6_TNL_F_IGN_ENCAP_LIMIT))
>   encap_limit = t->parms.encap_limit;
> @@ -1320,7 +1320,7 @@ int ip6_tnl_xmit(struct sk_buff *skb, struct net_device 
> *dev, __u8 dsfield,
>   fl6.flowi6_proto = IPPROTO_IPV6;
>   fl6.daddr = key->u.ipv6.dst;
>   fl6.flowlabel = key->label;
> - dsfield = ip6_tclass(key->label);
> + dsfield = RT_TOS(key->tos);
>   } else {
>   offset = ip6_tnl_parse_tlv_enc_lim(skb, 
> skb_network_header(skb));
>   /* ip6_tnl_parse_tlv_enc_lim() might have reallocated skb->head 
> */
> -- 
> 1.8.3.1
> 
> 

Sorry, I forgot to add subject prefix, please ignore this patch.





[PATCH] of: update ePAPR references to point to Devicetree Specification

2017-06-13 Thread frowand . list
From: Frank Rowand 

The Devicetree Specification has superseded the ePAPR as the
base specification for bindings.  Update files in Documentation
to reference the new document.

Some files are not updated because there is no hypervisor chapter
in the Devicetree Specification:
   Documentation/devicetree/bindings/powerpc/fsl/msi-pic.txt
   Documenation/virtual/kvm/api.txt
   Documenation/virtual/kvm/ppc-pv.txt

Signed-off-by: Frank Rowand 
---
 Documentation/devicetree/bindings/arm/cci.txt   | 12 ++--
 Documentation/devicetree/bindings/arm/cpus.txt  | 13 +++--
 Documentation/devicetree/bindings/arm/idle-states.txt   |  4 ++--
 Documentation/devicetree/bindings/arm/l2c2x0.txt|  4 ++--
 Documentation/devicetree/bindings/arm/topology.txt  |  4 ++--
 Documentation/devicetree/bindings/bus/simple-pm-bus.txt |  2 +-
 Documentation/devicetree/bindings/chosen.txt|  3 ++-
 Documentation/devicetree/bindings/common-properties.txt |  2 +-
 Documentation/devicetree/bindings/crypto/fsl-sec4.txt   |  4 ++--
 Documentation/devicetree/bindings/crypto/fsl-sec6.txt   |  4 ++--
 .../devicetree/bindings/interrupt-controller/open-pic.txt   |  5 ++---
 Documentation/devicetree/bindings/net/ethernet.txt  |  9 ++---
 Documentation/devicetree/bindings/powerpc/fsl/cpus.txt  |  6 +++---
 Documentation/devicetree/bindings/powerpc/fsl/l2cache.txt   |  2 +-
 Documentation/devicetree/bindings/powerpc/fsl/srio-rmu.txt  |  4 ++--
 Documentation/devicetree/bindings/powerpc/fsl/srio.txt  |  3 ++-
 Documentation/devicetree/booting-without-of.txt |  2 +-
 Documentation/devicetree/usage-model.txt|  2 +-
 Documentation/xtensa/mmu.txt|  6 +++---
 19 files changed, 48 insertions(+), 43 deletions(-)

diff --git a/Documentation/devicetree/bindings/arm/cci.txt 
b/Documentation/devicetree/bindings/arm/cci.txt
index 0f2153e8fa7e..cc7621b204f4 100644
--- a/Documentation/devicetree/bindings/arm/cci.txt
+++ b/Documentation/devicetree/bindings/arm/cci.txt
@@ -11,9 +11,9 @@ clusters, through memory mapped interface, with a global 
control register
 space and multiple sets of interface control registers, one per slave
 interface.
 
-Bindings for the CCI node follow the ePAPR standard, available from:
+Bindings for the CCI node follow the Devicetree Specification, available from:
 
-www.power.org/documentation/epapr-version-1-1/
+https://www.devicetree.org/specifications/
 
 with the addition of the bindings described in this document which are
 specific to ARM.
@@ -50,10 +50,10 @@ specific to ARM.
as a tuple of cells, containing child address,
parent address and the size of the region in the
child address space.
-   Definition: A standard property. Follow rules in the ePAPR for
-   hierarchical bus addressing. CCI interfaces
-   addresses refer to the parent node addressing
-   scheme to declare their register bases.
+   Definition: A standard property. Follow rules in the Devicetree
+   Specification for hierarchical bus addressing. CCI
+   interfaces addresses refer to the parent node
+   addressing scheme to declare their register bases.
 
CCI interconnect node can define the following child nodes:
 
diff --git a/Documentation/devicetree/bindings/arm/cpus.txt 
b/Documentation/devicetree/bindings/arm/cpus.txt
index 1030f5f50207..283c520a2224 100644
--- a/Documentation/devicetree/bindings/arm/cpus.txt
+++ b/Documentation/devicetree/bindings/arm/cpus.txt
@@ -6,9 +6,9 @@ The device tree allows to describe the layout of CPUs in a 
system through
 the "cpus" node, which in turn contains a number of subnodes (ie "cpu")
 defining properties for every cpu.
 
-Bindings for CPU nodes follow the ePAPR v1.1 standard, available from:
+Bindings for CPU nodes follow the Devicetree Specification, available from:
 
-https://www.power.org/documentation/epapr-version-1-1/
+https://www.devicetree.org/specifications/
 
 with updates for 32-bit and 64-bit ARM systems provided in this document.
 
@@ -16,8 +16,8 @@ with updates for 32-bit and 64-bit ARM systems provided in 
this document.
 Convention used in this document
 
 
-This document follows the conventions described in the ePAPR v1.1, with
-the addition:
+This document follows the conventions described in the Devicetree
+Specification, with the addition:
 
 - square brackets define bitfields, eg reg[7:0] value of the bitfield in
   the reg property contained in bits 7 down to 0
@@ -26,8 +26,9 @@ the addition:
 cpus and cpu node bindings definition
 =
 
-The ARM architecture, in 

[PATCH] ip6_tunnel: Correct tos value in collect_md mode

2017-06-13 Thread Haishuang Yan
Same as ip_gre, geneve and vxlan, use key->tos as tos value.

CC: Peter Dawson 
Fixes: 0e9a709560db ("ip6_tunnel, ip6_gre: fix setting of DSCP on
encapsulated packets”)
Suggested-by: Daniel Borkmann 
Signed-off-by: Haishuang Yan 

---
Changes since v2:
  * Add fixes information
  * mask key->tos with RT_TOS() suggested by Daniel
---
 net/ipv6/ip6_tunnel.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
index ef99d59..6400726 100644
--- a/net/ipv6/ip6_tunnel.c
+++ b/net/ipv6/ip6_tunnel.c
@@ -1249,7 +1249,7 @@ int ip6_tnl_xmit(struct sk_buff *skb, struct net_device 
*dev, __u8 dsfield,
fl6.flowi6_proto = IPPROTO_IPIP;
fl6.daddr = key->u.ipv6.dst;
fl6.flowlabel = key->label;
-   dsfield = ip6_tclass(key->label);
+   dsfield =  RT_TOS(key->tos);
} else {
if (!(t->parms.flags & IP6_TNL_F_IGN_ENCAP_LIMIT))
encap_limit = t->parms.encap_limit;
@@ -1320,7 +1320,7 @@ int ip6_tnl_xmit(struct sk_buff *skb, struct net_device 
*dev, __u8 dsfield,
fl6.flowi6_proto = IPPROTO_IPV6;
fl6.daddr = key->u.ipv6.dst;
fl6.flowlabel = key->label;
-   dsfield = ip6_tclass(key->label);
+   dsfield = RT_TOS(key->tos);
} else {
offset = ip6_tnl_parse_tlv_enc_lim(skb, 
skb_network_header(skb));
/* ip6_tnl_parse_tlv_enc_lim() might have reallocated skb->head 
*/
-- 
1.8.3.1





Re: [PATCH V2 net-next 6/8] net: hns3: Add MDIO support to HNS3 Ethernet driver for hip08 SoC

2017-06-13 Thread Andrew Lunn
> +struct hclge_mdio_cfg_cmd {
> + u8 ctrl_bit;
> + u8 prtad;   /* The external port address */
> + u8 devad;   /* The external device address */
> + u8 rsvd;
> + __le16 addr_c45;/* Only valid for c45 */
> + __le16 data_wr;
> + __le16 data_rd;
> + __le16 sta;
> +};
> +
> +static int hclge_mdio_write(struct mii_bus *bus, int phy_id, int regnum,
> + u16 data)
> +{
> + struct hclge_dev *hdev = (struct hclge_dev *)bus->priv;
> + struct hclge_mdio_cfg_cmd *mdio_cmd;
> + enum hclge_cmd_status status;
> + struct hclge_desc desc;
> + u8 is_c45, devad;
> + u16 reg;
> +
> + if (!bus)
> + return -EINVAL;
> +
> + is_c45 = !!(regnum & MII_ADDR_C45);
> + devad = ((regnum >> 16) & 0x1f);
> + reg = (u16)(regnum & 0x);
> +
> + hclge_cmd_setup_basic_desc(, HCLGE_OPC_MDIO_CONFIG, false);
> +
> + mdio_cmd = (struct hclge_mdio_cfg_cmd *)desc.data;
> +
> + mdio_cmd->ctrl_bit |= HCLGE_MDIO_CTRL_START_BIT;
> + mdio_cmd->prtad = phy_id & HCLGE_MDIO_CTRL_PRTAD_MSK;
> + mdio_cmd->data_wr = cpu_to_le16(data);
> + mdio_cmd->devad = devad & HCLGE_MDIO_CTRL_DEVAD_MSK;
> +
> + if (is_c45) {
> + /* Set phy addr */
> + mdio_cmd->addr_c45 = cpu_to_le16(reg);
> + } else {
> + /* C22 write reg and data */
> + mdio_cmd->ctrl_bit = HCLGE_MDIO_IS_C22(!is_c45);
> + mdio_cmd->ctrl_bit |= HCLGE_MDIO_CTRL_OP(HCLGE_MDIO_C22_WRITE);
> + }

When doing C22, i don't see you putting the reg into mdio_cmd anywhere?

Also

mdio_cmd->ctrl_bit = HCLGE_MDIO_IS_C22(!is_c45);

can be pulled of the if/then/else since it takes is_c45 as a
parameter, or simplified.

 Andrew


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

2017-06-13 Thread Andrew Lunn
> +static const struct hns3_link_mode_mapping hns3_lm_map[] = {
> + {HNS3_LM_FIBRE_BIT, ETHTOOL_LINK_MODE_FIBRE_BIT},
> + {HNS3_LM_AUTONEG_BIT, ETHTOOL_LINK_MODE_Autoneg_BIT},
> + {HNS3_LM_TP_BIT, ETHTOOL_LINK_MODE_TP_BIT},
> + {HNS3_LM_PAUSE_BIT, ETHTOOL_LINK_MODE_Pause_BIT},
> + {HNS3_LM_BACKPLANE_BIT, ETHTOOL_LINK_MODE_Backplane_BIT},
> + {HNS3_LM_10BASET_HALF_BIT, ETHTOOL_LINK_MODE_10baseT_Half_BIT},
> + {HNS3_LM_10BASET_FULL_BIT, ETHTOOL_LINK_MODE_10baseT_Full_BIT},
> + {HNS3_LM_100BASET_HALF_BIT, ETHTOOL_LINK_MODE_100baseT_Half_BIT},
> + {HNS3_LM_100BASET_FULL_BIT, ETHTOOL_LINK_MODE_100baseT_Full_BIT},
> + {HNS3_LM_1000BASET_FULL_BIT, ETHTOOL_LINK_MODE_1000baseT_Full_BIT},
> + {HNS3_LM_1BASEKR_FULL_BIT, ETHTOOL_LINK_MODE_1baseKR_Full_BIT},
> + {HNS3_LM_25000BASEKR_FULL_BIT, ETHTOOL_LINK_MODE_25000baseKR_Full_BIT},
> + {HNS3_LM_4BASELR4_FULL_BIT,
> +  ETHTOOL_LINK_MODE_4baseLR4_Full_BIT},
> + {HNS3_LM_5BASEKR2_FULL_BIT,
> +  ETHTOOL_LINK_MODE_5baseKR2_Full_BIT},
> + {HNS3_LM_10BASEKR4_FULL_BIT,
> +  ETHTOOL_LINK_MODE_10baseKR4_Full_BIT},
> +};

I don't see anywhere your HNS3_LM_ enum's get used by the hardware. So
it would be better to just use the Linux values and avoid this translation 
macro:

> +
> +#define HNS3_DRV_TO_ETHTOOL_CAPS(caps, lk_ksettings, name)   \
> +{\
> + int i;  \
> + \
> + for (i = 0; i < ARRAY_SIZE(hns3_lm_map); i++) { \
> + if ((caps) & hns3_lm_map[i].hns3_link_mode) \
> + __set_bit(hns3_lm_map[i].ethtool_link_mode,\
> +   (lk_ksettings)->link_modes.name); \
> + }   \
> +}

Andrew


Re: Repeatable inet6_dump_fib crash in stock 4.12.0-rc4+

2017-06-13 Thread David Ahern
On 6/13/17 3:42 PM, Cong Wang wrote:
> On Tue, Jun 13, 2017 at 1:16 PM, Ben Greear  wrote:
>> On 06/09/2017 02:25 PM, Eric Dumazet wrote:
>>>
>>> On Fri, 2017-06-09 at 07:27 -0600, David Ahern wrote:

 On 6/8/17 11:55 PM, Cong Wang wrote:
> Apparently fn->parent is NULL here for some reason, but
> I don't know if that is expected or not. If a simple NULL check
> is not enough here, we have to trace why it is NULL.


 From my understanding, parent should not be null hence the attempts to
 fix access to table nodes under a lock. ie., figuring out why it is null
 here.
>>
>>
>> If someone has more suggestions, I'll be happy to test.
> 
> Can you enable RT6_TRACE() by changing RT6_DEBUG
> from 2 to 3? We may collect some useful log with it.
> 
> diff --git a/net/ipv6/ip6_fib.c b/net/ipv6/ip6_fib.c
> index d4bf2c6..1941595 100644
> --- a/net/ipv6/ip6_fib.c
> +++ b/net/ipv6/ip6_fib.c
> @@ -37,7 +37,7 @@
>  #include 
>  #include 
> 
> -#define RT6_DEBUG 2
> +#define RT6_DEBUG 3
> 
>  #if RT6_DEBUG >= 3
>  #define RT6_TRACE(x...) pr_debug(x)
> 

Let's try a targeted debug patch. See attached
diff --git a/net/ipv6/ip6_fib.c b/net/ipv6/ip6_fib.c
index deea901746c8..367f1284f05b 100644
--- a/net/ipv6/ip6_fib.c
+++ b/net/ipv6/ip6_fib.c
@@ -1396,6 +1396,8 @@ static struct fib6_node *fib6_repair_tree(struct net *net,
RT6_TRACE("W %p adjusted by 
delnode 2, s=%d\n", w, w->state);
w->state = w->state >= FWS_C ? 
FWS_U : FWS_INIT;
}
+   if (w->state == FWS_U)
+   pr_warn("fib6_repair_tree: W %p 
adjusted by delnode 2, state FWS_U\n", w, w->state);
}
}
}
@@ -1447,8 +1449,10 @@ static void fib6_del_route(struct fib6_node *fn, struct 
rt6_info **rtp,
if (w->state == FWS_C && w->leaf == rt) {
RT6_TRACE("walker %p adjusted by delroute\n", w);
w->leaf = rt->dst.rt6_next;
-   if (!w->leaf)
+   if (!w->leaf) {
+   pr_warn("fib6_del_route: walker %p adjusted by 
delroute - state FWS_U\n", w);
w->state = FWS_U;
+   }
}
}
read_unlock(>ipv6.fib6_walker_lock);
@@ -1591,6 +1595,7 @@ static int fib6_walk_continue(struct fib6_walker *w)
continue;
}
 skip:
+   pr_warn("fib6_walk_continue: set state to FWS_U\n");
w->state = FWS_U;
case FWS_U:
if (fn == w->root)


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

2017-06-13 Thread Andrew Lunn
> + switch (media_type) {
> + case HNAE3_MEDIA_TYPE_FIBER:
> + cmd->base.port = PORT_FIBRE;
> + supported_caps = HNS3_LM_FIBRE_BIT | HNS3_LM_AUTONEG_BIT |
> + HNS3_LM_PAUSE_BIT | HNS3_LM_4BASELR4_FULL_BIT |
> + HNS3_LM_1BASEKR_FULL_BIT |
> + HNS3_LM_1000BASET_FULL_BIT;
> + /* TODO: add speed 100G/50G/25G when ethtool and linux kernel
> +  * is ready to support.

Linux already has:

linux/ethtool.h:ETHTOOL_LINK_MODE_25000baseCR_Full_BIT  = 31,
linux/ethtool.h:ETHTOOL_LINK_MODE_25000baseKR_Full_BIT  = 32,
linux/ethtool.h:ETHTOOL_LINK_MODE_25000baseSR_Full_BIT  = 33,
linux/ethtool.h:ETHTOOL_LINK_MODE_5baseCR2_Full_BIT = 34,
linux/ethtool.h:ETHTOOL_LINK_MODE_5baseKR2_Full_BIT = 35,
linux/ethtool.h:ETHTOOL_LINK_MODE_10baseKR4_Full_BIT  = 36,
linux/ethtool.h:ETHTOOL_LINK_MODE_10baseSR4_Full_BIT  = 37,
linux/ethtool.h:ETHTOOL_LINK_MODE_10baseCR4_Full_BIT  = 38,
linux/ethtool.h:ETHTOOL_LINK_MODE_10baseLR4_ER4_Full_BIT= 39,

Andrew


Re: [PATCH v2 net-next 8/9] bpf: nfp: Report bpf_prog ID during XDP_QUERY_PROG

2017-06-13 Thread Jakub Kicinski
On Tue, 13 Jun 2017 17:37:50 -0700, Martin KaFai Lau wrote:
> On Tue, Jun 13, 2017 at 04:52:32PM -0700, Jakub Kicinski wrote:
> > On Tue, 13 Jun 2017 14:08:40 -0700, Martin KaFai Lau wrote:  
> > > - case XDP_QUERY_PROG:
> > > - xdp->prog_attached = !!nn->dp.xdp_prog;
> > > + case XDP_QUERY_PROG: {
> > > + const struct bpf_prog *xdp_prog;
> > > +
> > > + xdp_prog = nn->dp.xdp_prog;
> > > + if (xdp_prog) {
> > > + xdp->prog_id = xdp_prog->aux->id;
> > > + xdp->prog_attached = true;
> > > + } else {
> > > + xdp->prog_id = 0;
> > > + xdp->prog_attached = false;
> > > + }
> > >   return 0;
> > > + }  
> >
> > I'm sorry to nit pick but it could be done on a single line:
> >
> > case XDP_QUERY_PROG:
> > xdp->prog_attached = !!nn->dp.xdp_prog;
> > +   xdp->prog_id = nn->dp.xdp_prog ? nn->dp.xdp_prog->aux->id : 0;
> > return 0;
> > default:
> > return -EINVAL;  
> OK...
> 
> >
> >
> > What would be even cooler is a helper like this:
> >
> > static inline u32 bpf_prog_id(struct bpf_prog *prog)
> > {
> > if (!prog)
> > return 0;
> > return prog->aux->id;
> > }
> >
> > in linux/bpf.h.
> Good idea.

You may actually have to add that into a source file, because bpf.h
does not know the definition of struct bpf_prog :(

> I had been thinking I may not need to change all the
> drivers now.  I did that in v1 because I wanted to remove
> prog_attached which is redundant.  With prog_attached reserved,
> prog_id is optional.
> 
> Considering I don't have all the hardwares to test it,  I think
> it may make more sense for me to only change the HW that I have?

Coccinelle to the rescue?

@@
expression ex;
@@
xdp->prog_attached = !!(ex);
+   xdp->prog_id = bpf_prog_id(ex);

> > In patch 1 I would be tempted to add a new command for getting the prog
> > id, instead of muxing through query to avoid the output parameter?  But
> > I'm OK with the code as is, its just a preference rather than an objection 
> > :)  
> Have one command to query a new field?  I think it is overkilled.

Perhaps.  I was just trying to come up with a way of avoiding the
output parameter.  It seems hard to do unless we stop using
__dev_xdp_attached() for filling in the netlink attributes.  I'm OK
with leaving the code as is..


Re: [PATCH V2 net-next 2/8] net: hns3: Add support of the HNAE3 framework

2017-06-13 Thread Andrew Lunn
On Wed, Jun 14, 2017 at 12:10:29AM +0100, Salil Mehta wrote:
> +static int __init hnae3_init(void)
> +{
> + return 0;
> +}
> +

..

> +subsys_initcall(hnae3_init);

And the point of this is?

Andrew


Re: [PATCH V2 net-next 2/8] net: hns3: Add support of the HNAE3 framework

2017-06-13 Thread Andrew Lunn
On Wed, Jun 14, 2017 at 12:10:29AM +0100, Salil Mehta wrote:
> This patch adds the support of the HNAE3 (Hisilicon Network
> Acceleration Engine 3) framework support to the HNS3 driver.
> 
> Framework facilitates clients like ENET(HNS3 Ethernet Driver), RoCE
> and user-space Ethernet drivers (like ODP etc.) to register with HNAE3
> devices and their associated operations.
> 
> Signed-off-by: Daode Huang 
> Signed-off-by: lipeng 
> Signed-off-by: Salil Mehta 
> Signed-off-by: Yisen Zhuang 
> ---
>  drivers/net/ethernet/hisilicon/hns3/hnae3.c | 305 +++
>  drivers/net/ethernet/hisilicon/hns3/hnae3.h | 449 
> 
>  2 files changed, 754 insertions(+)
>  create mode 100644 drivers/net/ethernet/hisilicon/hns3/hnae3.c
>  create mode 100644 drivers/net/ethernet/hisilicon/hns3/hnae3.h
> 
> diff --git a/drivers/net/ethernet/hisilicon/hns3/hnae3.c 
> b/drivers/net/ethernet/hisilicon/hns3/hnae3.c
> new file mode 100644
> index 000..f133e1d
> --- /dev/null
> +++ b/drivers/net/ethernet/hisilicon/hns3/hnae3.c
> @@ -0,0 +1,305 @@
> +/*
> + * 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 
> +#include 
> +
> +#include "hnae3.h"
> +
> +static LIST_HEAD(hnae3_ae_algo_list);
> +static LIST_HEAD(hnae3_client_list);
> +static LIST_HEAD(hnae3_ae_dev_list);
> +
> +static DEFINE_SPINLOCK(hnae3_list_ae_algo_lock);
> +static DEFINE_SPINLOCK(hnae3_list_client_lock);
> +static DEFINE_SPINLOCK(hnae3_list_ae_dev_lock);
> +
> +static void hnae3_list_add(spinlock_t *lock, struct list_head *node,
> +struct list_head *head)
> +{
> + unsigned long flags;
> +
> + spin_lock_irqsave(lock, flags);
> + list_add_tail_rcu(node, head);
> + spin_unlock_irqrestore(lock, flags);
> +}
> +
> +static void hnae3_list_del(spinlock_t *lock, struct list_head *node)
> +{
> + unsigned long flags;
> +
> + spin_lock_irqsave(lock, flags);
> + list_del_rcu(node);
> + spin_unlock_irqrestore(lock, flags);
> +}


You have these two _rcu operations here, and no others. I don't see
any rcu_read_lock(), or call_rcu(), etc.

I'm not an RCU expert, but this looks odd to me.

Andrew


Re: [PATCH net-next 6/9] net: hns3: Add MDIO support to HNS3 Ethernet driver for hip08 SoC

2017-06-13 Thread Andrew Lunn
> Since I would be touching the core, lots of drivers will get impacted and will
> have to wait till everyone gives clean signal. This will impact our internal
> deadlines. But as I said I am eager to cooperate & contribute :)

Just as an FYI.

Your internal deadlines are irrelevant. We will reject your patches
until we are happy with it. We probably won't accept a hack around a
core feature limitation. We will want you to fix the core limitation
and then do it right in the driver.

Andrew


[net-next 9/9] ixgbe: pci_set_drvdata must be called before register_netdev

2017-06-13 Thread Jeff Kirsher
From: Jeff Mahoney 

We call pci_set_drvdata immediately after calling register_netdev,
which leaves a window where tasks writing to the sriov_numvfs sysfs
attribute can sneak in and crash the kernel.  register_netdev cleans
up after itself so placing pci_set_drvdata immediately before it
should preserve the intent of commit 0fb6a55cc31f ("ixgbe: fix crash
on rmmod after probe fail").

Fixes: 0fb6a55cc31f ("ixgbe: fix crash on rmmod after probe fail")
Signed-off-by: Jeff Mahoney 
Tested-by: Andrew Bowers 
Signed-off-by: Jeff Kirsher 
---
 drivers/net/ethernet/intel/ixgbe/ixgbe_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c 
b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
index c17c8317e001..f3dc5dea9300 100644
--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
@@ -10372,11 +10372,11 @@ static int ixgbe_probe(struct pci_dev *pdev, const 
struct pci_device_id *ent)
   "hardware.\n");
}
strcpy(netdev->name, "eth%d");
+   pci_set_drvdata(pdev, adapter);
err = register_netdev(netdev);
if (err)
goto err_register;
 
-   pci_set_drvdata(pdev, adapter);
 
/* power down the optics for 82599 SFP+ fiber */
if (hw->mac.ops.disable_tx_laser)
-- 
2.12.2



[net-next 7/9] ixgbe: fix writes to PFQDE

2017-06-13 Thread Jeff Kirsher
From: Emil Tantilov 

ixgbe_write_qde() was ignoring the qde parameter which resulted
in PFQDE.HIDE_VLAN not being set for X550.

Signed-off-by: Emil Tantilov 
Tested-by: Andrew Bowers 
Signed-off-by: Jeff Kirsher 
---
 drivers/net/ethernet/intel/ixgbe/ixgbe_sriov.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_sriov.c 
b/drivers/net/ethernet/intel/ixgbe/ixgbe_sriov.c
index e2766da5fe02..0760bd7eeb01 100644
--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_sriov.c
+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_sriov.c
@@ -818,7 +818,7 @@ static inline void ixgbe_write_qde(struct ixgbe_adapter 
*adapter, u32 vf,
IXGBE_WRITE_FLUSH(hw);
 
/* indicate to hardware that we want to set drop enable */
-   reg = IXGBE_QDE_WRITE | IXGBE_QDE_ENABLE;
+   reg = IXGBE_QDE_WRITE | qde;
reg |= i <<  IXGBE_QDE_IDX_SHIFT;
IXGBE_WRITE_REG(hw, IXGBE_QDE, reg);
}
-- 
2.12.2



[net-next 8/9] ixgbe: Resolve cppcheck format string warning

2017-06-13 Thread Jeff Kirsher
From: Tony Nguyen 

cppcheck warns that the format string is incorrect in the function
ixgbe_get_strings().  Since the value cannot be negative, change the
variable to unsigned which matches the format specifier.

Signed-off-by: Tony Nguyen 
Tested-by: Andrew Bowers 
Signed-off-by: Jeff Kirsher 
---
 drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c 
b/drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c
index 2890e926b498..72c565712a5f 100644
--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c
+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c
@@ -1277,7 +1277,7 @@ static void ixgbe_get_strings(struct net_device *netdev, 
u32 stringset,
  u8 *data)
 {
char *p = (char *)data;
-   int i;
+   unsigned int i;
 
switch (stringset) {
case ETH_SS_TEST:
-- 
2.12.2



[net-next 6/9] ixgbevf: Bump version number

2017-06-13 Thread Jeff Kirsher
From: Tony Nguyen 

Update ixgbevf version number.

Signed-off-by: Tony Nguyen 
Tested-by: Andrew Bowers 
Signed-off-by: Jeff Kirsher 
---
 drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c 
b/drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c
index aced91c9c034..084c53582793 100644
--- a/drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c
+++ b/drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c
@@ -57,7 +57,7 @@ const char ixgbevf_driver_name[] = "ixgbevf";
 static const char ixgbevf_driver_string[] =
"Intel(R) 10 Gigabit PCI Express Virtual Function Network Driver";
 
-#define DRV_VERSION "3.2.2-k"
+#define DRV_VERSION "4.1.0-k"
 const char ixgbevf_driver_version[] = DRV_VERSION;
 static char ixgbevf_copyright[] =
"Copyright (c) 2009 - 2015 Intel Corporation.";
-- 
2.12.2



[net-next 5/9] ixgbe: Bump version number

2017-06-13 Thread Jeff Kirsher
From: Tony Nguyen 

Update ixgbe version number.

Signed-off-by: Tony Nguyen 
Tested-by: Andrew Bowers 
Signed-off-by: Jeff Kirsher 
---
 drivers/net/ethernet/intel/ixgbe/ixgbe_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c 
b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
index 3ed212f5a43e..c17c8317e001 100644
--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
@@ -76,7 +76,7 @@ char ixgbe_default_device_descr[] =
 static char ixgbe_default_device_descr[] =
  "Intel(R) 10 Gigabit Network Connection";
 #endif
-#define DRV_VERSION "5.0.0-k"
+#define DRV_VERSION "5.1.0-k"
 const char ixgbe_driver_version[] = DRV_VERSION;
 static const char ixgbe_copyright[] =
"Copyright (c) 1999-2016 Intel Corporation.";
-- 
2.12.2



[net-next 2/9] ixgbe: avoid permanent lock of *_PTP_TX_IN_PROGRESS

2017-06-13 Thread Jeff Kirsher
From: Jacob Keller 

The ixgbe driver uses a state bit lock to avoid handling more than one Tx
timestamp request at once. This is required because hardware is limited
to a single set of registers for Tx timestamps.

The state bit lock is not properly cleaned up during
ixgbe_xmit_frame_ring() if the transmit fails such as due to DMA or TSO
failure. In some hardware this results in blocking timestamps until the
service task times out. In other hardware this results in a permanent
lock of the timestamp bit because we never receive an interrupt
indicating the timestamp occurred, since indeed the packet was never
transmitted.

Fix this by checking for DMA and TSO errors in ixgbe_xmit_frame_ring() and
properly cleaning up after ourselves when these occur.

Reported-by: Reported-by: David Mirabito 
Signed-off-by: Jacob Keller 
Tested-by: Andrew Bowers 
Signed-off-by: Jeff Kirsher 
---
 drivers/net/ethernet/intel/ixgbe/ixgbe_main.c | 20 +++-
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c 
b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
index 812319ab77db..5773df248360 100644
--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
@@ -7875,9 +7875,9 @@ static inline int ixgbe_maybe_stop_tx(struct ixgbe_ring 
*tx_ring, u16 size)
 #define IXGBE_TXD_CMD (IXGBE_TXD_CMD_EOP | \
   IXGBE_TXD_CMD_RS)
 
-static void ixgbe_tx_map(struct ixgbe_ring *tx_ring,
-struct ixgbe_tx_buffer *first,
-const u8 hdr_len)
+static int ixgbe_tx_map(struct ixgbe_ring *tx_ring,
+   struct ixgbe_tx_buffer *first,
+   const u8 hdr_len)
 {
struct sk_buff *skb = first->skb;
struct ixgbe_tx_buffer *tx_buffer;
@@ -8004,7 +8004,7 @@ static void ixgbe_tx_map(struct ixgbe_ring *tx_ring,
mmiowb();
}
 
-   return;
+   return 0;
 dma_error:
dev_err(tx_ring->dev, "TX DMA map failed\n");
tx_buffer = _ring->tx_buffer_info[i];
@@ -8034,6 +8034,8 @@ static void ixgbe_tx_map(struct ixgbe_ring *tx_ring,
first->skb = NULL;
 
tx_ring->next_to_use = i;
+
+   return -1;
 }
 
 static void ixgbe_atr(struct ixgbe_ring *ring,
@@ -8407,13 +8409,21 @@ netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb,
 #ifdef IXGBE_FCOE
 xmit_fcoe:
 #endif /* IXGBE_FCOE */
-   ixgbe_tx_map(tx_ring, first, hdr_len);
+   if (ixgbe_tx_map(tx_ring, first, hdr_len))
+   goto cleanup_tx_timestamp;
 
return NETDEV_TX_OK;
 
 out_drop:
dev_kfree_skb_any(first->skb);
first->skb = NULL;
+cleanup_tx_timestamp:
+   if (unlikely(tx_flags & IXGBE_TX_FLAGS_TSTAMP)) {
+   dev_kfree_skb_any(adapter->ptp_tx_skb);
+   adapter->ptp_tx_skb = NULL;
+   cancel_work_sync(>ptp_tx_work);
+   clear_bit_unlock(__IXGBE_PTP_TX_IN_PROGRESS, >state);
+   }
 
return NETDEV_TX_OK;
 }
-- 
2.12.2



[net-next 3/9] ixgbe: add statistic indicating number of skipped Tx timestamps

2017-06-13 Thread Jeff Kirsher
From: Jacob Keller 

The ixgbe driver can only handle one Tx timestamp request at a time.
This means it is possible for an application timestamp request to be
ignored.

There is no easy way for an administrator to determine if this occurred.
Add a new statistic which tracks this, tx_hwtstamp_skipped.

Signed-off-by: Jacob Keller 
Tested-by: Andrew Bowers 
Signed-off-by: Jeff Kirsher 
---
 drivers/net/ethernet/intel/ixgbe/ixgbe.h |  1 +
 drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c |  3 +++
 drivers/net/ethernet/intel/ixgbe/ixgbe_main.c| 23 +--
 3 files changed, 17 insertions(+), 10 deletions(-)

diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe.h 
b/drivers/net/ethernet/intel/ixgbe/ixgbe.h
index 76263762bea1..eb36106218ad 100644
--- a/drivers/net/ethernet/intel/ixgbe/ixgbe.h
+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe.h
@@ -733,6 +733,7 @@ struct ixgbe_adapter {
struct timecounter hw_tc;
u32 base_incval;
u32 tx_hwtstamp_timeouts;
+   u32 tx_hwtstamp_skipped;
u32 rx_hwtstamp_cleared;
void (*ptp_setup_sdp)(struct ixgbe_adapter *);
 
diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c 
b/drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c
index 9113e8099b03..2890e926b498 100644
--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c
+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c
@@ -111,6 +111,9 @@ static const struct ixgbe_stats ixgbe_gstrings_stats[] = {
{"os2bmc_tx_by_bmc", IXGBE_STAT(stats.b2ospc)},
{"os2bmc_tx_by_host", IXGBE_STAT(stats.o2bspc)},
{"os2bmc_rx_by_host", IXGBE_STAT(stats.b2ogprc)},
+   {"tx_hwtstamp_timeouts", IXGBE_STAT(tx_hwtstamp_timeouts)},
+   {"tx_hwtstamp_skipped", IXGBE_STAT(tx_hwtstamp_skipped)},
+   {"rx_hwtstamp_cleared", IXGBE_STAT(rx_hwtstamp_cleared)},
 #ifdef IXGBE_FCOE
{"fcoe_bad_fccrc", IXGBE_STAT(stats.fccrc)},
{"rx_fcoe_dropped", IXGBE_STAT(stats.fcoerpdc)},
diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c 
b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
index 5773df248360..4ea1137ea23f 100644
--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
@@ -8337,16 +8337,19 @@ netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb,
protocol = vlan_get_protocol(skb);
 
if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) &&
-   adapter->ptp_clock &&
-   !test_and_set_bit_lock(__IXGBE_PTP_TX_IN_PROGRESS,
-  >state)) {
-   skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
-   tx_flags |= IXGBE_TX_FLAGS_TSTAMP;
-
-   /* schedule check for Tx timestamp */
-   adapter->ptp_tx_skb = skb_get(skb);
-   adapter->ptp_tx_start = jiffies;
-   schedule_work(>ptp_tx_work);
+   adapter->ptp_clock) {
+   if (!test_and_set_bit_lock(__IXGBE_PTP_TX_IN_PROGRESS,
+  >state)) {
+   skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
+   tx_flags |= IXGBE_TX_FLAGS_TSTAMP;
+
+   /* schedule check for Tx timestamp */
+   adapter->ptp_tx_skb = skb_get(skb);
+   adapter->ptp_tx_start = jiffies;
+   schedule_work(>ptp_tx_work);
+   } else {
+   adapter->tx_hwtstamp_skipped++;
+   }
}
 
skb_tx_timestamp(skb);
-- 
2.12.2



[net-next 4/9] ixgbe: check for Tx timestamp timeouts during watchdog

2017-06-13 Thread Jeff Kirsher
From: Jacob Keller 

The ixgbe driver has logic to handle only one Tx timestamp at a time,
using a state bit lock to avoid multiple requests at once.

It may be possible, if incredibly unlikely, that a Tx timestamp event is
requested but never completes. Since we use an interrupt scheme to
determine when the Tx timestamp occurred we would never clear the state
bit in this case.

Add an ixgbe_ptp_tx_hang() function similar to the already existing
ixgbe_ptp_rx_hang() function. This function runs in the watchdog routine
and makes sure we eventually recover from this case instead of
permanently disabling Tx timestamps.

Note: there is no currently known way to cause this without hacking the
driver code to force it.

Signed-off-by: Jacob Keller 
Tested-by: Andrew Bowers 
Signed-off-by: Jeff Kirsher 
---
 drivers/net/ethernet/intel/ixgbe/ixgbe.h  |  1 +
 drivers/net/ethernet/intel/ixgbe/ixgbe_main.c |  1 +
 drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c  | 27 +++
 3 files changed, 29 insertions(+)

diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe.h 
b/drivers/net/ethernet/intel/ixgbe/ixgbe.h
index eb36106218ad..dd5578756ae0 100644
--- a/drivers/net/ethernet/intel/ixgbe/ixgbe.h
+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe.h
@@ -961,6 +961,7 @@ void ixgbe_ptp_suspend(struct ixgbe_adapter *adapter);
 void ixgbe_ptp_stop(struct ixgbe_adapter *adapter);
 void ixgbe_ptp_overflow_check(struct ixgbe_adapter *adapter);
 void ixgbe_ptp_rx_hang(struct ixgbe_adapter *adapter);
+void ixgbe_ptp_tx_hang(struct ixgbe_adapter *adapter);
 void ixgbe_ptp_rx_pktstamp(struct ixgbe_q_vector *, struct sk_buff *);
 void ixgbe_ptp_rx_rgtstamp(struct ixgbe_q_vector *, struct sk_buff *skb);
 static inline void ixgbe_ptp_rx_hwtstamp(struct ixgbe_ring *rx_ring,
diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c 
b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
index 4ea1137ea23f..3ed212f5a43e 100644
--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
@@ -7635,6 +7635,7 @@ static void ixgbe_service_task(struct work_struct *work)
if (test_bit(__IXGBE_PTP_RUNNING, >state)) {
ixgbe_ptp_overflow_check(adapter);
ixgbe_ptp_rx_hang(adapter);
+   ixgbe_ptp_tx_hang(adapter);
}
 
ixgbe_service_event_complete(adapter);
diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c 
b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
index 4a2000bfd4ae..86d6924a2b71 100644
--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
@@ -663,6 +663,33 @@ static void ixgbe_ptp_clear_tx_timestamp(struct 
ixgbe_adapter *adapter)
 }
 
 /**
+ * ixgbe_ptp_tx_hang - detect error case where Tx timestamp never finishes
+ * @adapter: private network adapter structure
+ */
+void ixgbe_ptp_tx_hang(struct ixgbe_adapter *adapter)
+{
+   bool timeout = time_is_before_jiffies(adapter->ptp_tx_start +
+ IXGBE_PTP_TX_TIMEOUT);
+
+   if (!adapter->ptp_tx_skb)
+   return;
+
+   if (!test_bit(__IXGBE_PTP_TX_IN_PROGRESS, >state))
+   return;
+
+   /* If we haven't received a timestamp within the timeout, it is
+* reasonable to assume that it will never occur, so we can unlock the
+* timestamp bit when this occurs.
+*/
+   if (timeout) {
+   cancel_work_sync(>ptp_tx_work);
+   ixgbe_ptp_clear_tx_timestamp(adapter);
+   adapter->tx_hwtstamp_timeouts++;
+   e_warn(drv, "clearing Tx timestamp hang\n");
+   }
+}
+
+/**
  * ixgbe_ptp_tx_hwtstamp - utility function which checks for TX time stamp
  * @adapter: the private adapter struct
  *
-- 
2.12.2



[net-next 1/9] ixgbe: fix race condition with PTP_TX_IN_PROGRESS bits

2017-06-13 Thread Jeff Kirsher
From: Jacob Keller 

Hardware related to the ixgbe driver is limited to handling a single Tx
timestamp request at a time. Thus, the driver ignores requests for Tx
timestamp while waiting for the current request to finish. It uses
a state bit lock which enforces that only one timestamp request is
honored at a time.

Unfortunately this suffers from a simple race condition. The bit lock is
not cleared until after skb_tstamp_tx() is called notifying applications
of a new Tx timestamp. Even a well behaved application sending only one
packet at a time and waiting for a response can wake up and send a new
packet before the bit lock is cleared. This results in needlessly
dropping some Tx timestamp requests.

We can fix this by unlocking the state bit as soon as we read the
Timestamp register, as this is the first point at which it is safe to
unlock.

To avoid issues with the skb pointer, we'll use a copy of the pointer
and set the global variable in the driver structure to NULL first. This
ensures that the next timestamp request does not modify our local copy
of the skb pointer.

This ensures that well behaved applications do not accidentally race
with the unlock bit. Obviously an application which sends multiple Tx
timestamp requests at once will still only timestamp one packet at
a time. Unfortunately there is nothing we can do about this.

Reported-by: David Mirabito 
Signed-off-by: Jacob Keller 
Tested-by: Andrew Bowers 
Signed-off-by: Jeff Kirsher 
---
 drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c | 15 ---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c 
b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
index d44c728fdc0b..4a2000bfd4ae 100644
--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
@@ -672,17 +672,26 @@ static void ixgbe_ptp_clear_tx_timestamp(struct 
ixgbe_adapter *adapter)
  */
 static void ixgbe_ptp_tx_hwtstamp(struct ixgbe_adapter *adapter)
 {
+   struct sk_buff *skb = adapter->ptp_tx_skb;
struct ixgbe_hw *hw = >hw;
struct skb_shared_hwtstamps shhwtstamps;
u64 regval = 0;
 
regval |= (u64)IXGBE_READ_REG(hw, IXGBE_TXSTMPL);
regval |= (u64)IXGBE_READ_REG(hw, IXGBE_TXSTMPH) << 32;
-
ixgbe_ptp_convert_to_hwtstamp(adapter, , regval);
-   skb_tstamp_tx(adapter->ptp_tx_skb, );
 
-   ixgbe_ptp_clear_tx_timestamp(adapter);
+   /* Handle cleanup of the ptp_tx_skb ourselves, and unlock the state
+* bit prior to notifying the stack via skb_tstamp_tx(). This prevents
+* well behaved applications from attempting to timestamp again prior
+* to the lock bit being clear.
+*/
+   adapter->ptp_tx_skb = NULL;
+   clear_bit_unlock(__IXGBE_PTP_TX_IN_PROGRESS, >state);
+
+   /* Notify the stack and then free the skb after we've unlocked */
+   skb_tstamp_tx(skb, );
+   dev_kfree_skb_any(skb);
 }
 
 /**
-- 
2.12.2



Re: [PATCH v2 net-next 8/9] bpf: nfp: Report bpf_prog ID during XDP_QUERY_PROG

2017-06-13 Thread Martin KaFai Lau
On Tue, Jun 13, 2017 at 04:52:32PM -0700, Jakub Kicinski wrote:
> On Tue, 13 Jun 2017 14:08:40 -0700, Martin KaFai Lau wrote:
> > -   case XDP_QUERY_PROG:
> > -   xdp->prog_attached = !!nn->dp.xdp_prog;
> > +   case XDP_QUERY_PROG: {
> > +   const struct bpf_prog *xdp_prog;
> > +
> > +   xdp_prog = nn->dp.xdp_prog;
> > +   if (xdp_prog) {
> > +   xdp->prog_id = xdp_prog->aux->id;
> > +   xdp->prog_attached = true;
> > +   } else {
> > +   xdp->prog_id = 0;
> > +   xdp->prog_attached = false;
> > +   }
> > return 0;
> > +   }
>
> I'm sorry to nit pick but it could be done on a single line:
>
>   case XDP_QUERY_PROG:
>   xdp->prog_attached = !!nn->dp.xdp_prog;
> + xdp->prog_id = nn->dp.xdp_prog ? nn->dp.xdp_prog->aux->id : 0;
>   return 0;
>   default:
>   return -EINVAL;
OK...

>
>
> What would be even cooler is a helper like this:
>
> static inline u32 bpf_prog_id(struct bpf_prog *prog)
> {
>   if (!prog)
>   return 0;
>   return prog->aux->id;
> }
>
> in linux/bpf.h.
Good idea.



I had been thinking I may not need to change all the
drivers now.  I did that in v1 because I wanted to remove
prog_attached which is redundant.  With prog_attached reserved,
prog_id is optional.

Considering I don't have all the hardwares to test it,  I think
it may make more sense for me to only change the HW that I have?

>
> In patch 1 I would be tempted to add a new command for getting the prog
> id, instead of muxing through query to avoid the output parameter?  But
> I'm OK with the code as is, its just a preference rather than an objection :)
Have one command to query a new field?  I think it is overkilled.


[net-next 0/9][pull request] 10GbE Intel Wired LAN Driver Updates 2017-06-13

2017-06-13 Thread Jeff Kirsher
This series contains updates to ixgbe and ixgbevf only.

Jake completes his fix ups for our drivers with the ixgbe changes to
resolve a race condition in processing timestamp requests.  These fixes
are the same fixes Jake applied earlier to the other drivers, including
the added statistic to help administrators know when an application
timestamp request is ignored.

With all the recent ixgbe/ixgbevf changes and fixes, Tony bumps the
the driver versions.  Then Tony provides a fix to resolve a static
analysis warning by changing a variable to unsigned integer since the
value can never be negative. 

Emil fixes an issue for X550 devices where the qde parameter was being
ignored, so PFQDE.HIDE_VLAN was not being set.

Jeff Mahoney from SuSE fixes a possible kernel crash, where there was
a small window where tasks writing to the sriov_numvfs sysfs attribute
can sneak in after we call register_netdev().  So we need to call
pci_set_drvdata() before and not after register_netdev() to preserve the
intent of commit 0fb6a55cc31f ("ixgbe: fix crash on rmmod after probe
fail").

The following are changes since commit b217566a525ff24334d17635a865f44b68c2c583:
  Merge branch 'net-dsa-Multi-CPU-ground-work'
and are available in the git repository at:
  git://git.kernel.org/pub/scm/linux/kernel/git/jkirsher/next-queue 10GbE

Emil Tantilov (1):
  ixgbe: fix writes to PFQDE

Jacob Keller (4):
  ixgbe: fix race condition with PTP_TX_IN_PROGRESS bits
  ixgbe: avoid permanent lock of *_PTP_TX_IN_PROGRESS
  ixgbe: add statistic indicating number of skipped Tx timestamps
  ixgbe: check for Tx timestamp timeouts during watchdog

Jeff Mahoney (1):
  ixgbe: pci_set_drvdata must be called before register_netdev

Tony Nguyen (3):
  ixgbe: Bump version number
  ixgbevf: Bump version number
  ixgbe: Resolve cppcheck format string warning

 drivers/net/ethernet/intel/ixgbe/ixgbe.h  |  2 +
 drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c  |  5 ++-
 drivers/net/ethernet/intel/ixgbe/ixgbe_main.c | 48 +++
 drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c  | 42 ++--
 drivers/net/ethernet/intel/ixgbe/ixgbe_sriov.c|  2 +-
 drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c |  2 +-
 6 files changed, 78 insertions(+), 23 deletions(-)

-- 
2.12.2



linux-next: manual merge of the net-next tree with the net tree

2017-06-13 Thread Stephen Rothwell
Hi all,

Today's linux-next merge of the net-next tree got a conflict in:

  net/batman-adv/routing.c

between commit:

  a1a745ef980a ("batman-adv: fix memory leak when dropping packet from other 
gateway")

from the net tree and commit:

  22f0502ed9f3 ("batman-adv: Print correct function names in dbg messages")

from the net-next tree.

I fixed it up (see below) and can carry the fix as necessary. This
is now fixed as far as linux-next is concerned, but any non trivial
conflicts should be mentioned to your upstream maintainer when your tree
is submitted for merging.  You may also want to consider cooperating
with the maintainer of the conflicting tree to minimise any particularly
complex conflicts.

-- 
Cheers,
Stephen Rothwell

diff --cc net/batman-adv/routing.c
index ae9f4d37d34f,1338b9221613..
--- a/net/batman-adv/routing.c
+++ b/net/batman-adv/routing.c
@@@ -985,9 -985,9 +985,9 @@@ int batadv_recv_unicast_packet(struct s
batadv_orig_node_put(orig_node_gw);
if (is_gw) {
batadv_dbg(BATADV_DBG_BLA, bat_priv,
-  "recv_unicast_packet(): Dropped 
unicast pkt received from another backbone gw %pM.\n",
-  orig_addr_gw);
+  "%s(): Dropped unicast pkt received 
from another backbone gw %pM.\n",
+  __func__, orig_addr_gw);
 -  return NET_RX_DROP;
 +  goto free_skb;
}
}
  


Re: [PATCH 0/4] bpf: Changes needed (or desired) for MIPS support

2017-06-13 Thread Daniel Borkmann

On 06/14/2017 01:49 AM, David Daney wrote:

This is a grab bag of changes to the bpf testing infrastructure I
developed working on MIPS eBPF JIT support.  The change to
bpf_jit_disasm is probably universally beneficial, the others are more
MIPS specific.


I think these could go independently through net-next tree?

Thanks,
Daniel


David Daney (4):
   tools: bpf_jit_disasm:  Handle large images.
   test_bpf: Add test to make conditional jump cross a large number of
 insns.
   bpf: Add MIPS support to samples/bpf.
   samples/bpf: Fix tracex5 to work with MIPS syscalls.

  lib/test_bpf.c | 32 
  samples/bpf/Makefile   | 13 +
  samples/bpf/bpf_helpers.h  | 13 +
  samples/bpf/syscall_nrs.c  | 12 
  samples/bpf/tracex5_kern.c | 11 ---
  tools/net/bpf_jit_disasm.c | 37 ++---
  6 files changed, 104 insertions(+), 14 deletions(-)
  create mode 100644 samples/bpf/syscall_nrs.c





Re: [PATCH 4/4] samples/bpf: Fix tracex5 to work with MIPS syscalls.

2017-06-13 Thread Daniel Borkmann

On 06/14/2017 01:49 AM, David Daney wrote:

There are two problems:

1) In MIPS the __NR_* macros expand to an expression, this causes the
sections of the object file to be named like:

   .
   .
   .
   [ 5] kprobe/(5000 + 1) PROGBITS 000160 ...
   [ 6] kprobe/(5000 + 0) PROGBITS 000258 ...
   [ 7] kprobe/(5000 + 9) PROGBITS 000348 ...
   .
   .
   .

The fix here is to use the "asm_offsets" trick to evaluate the macros
in the C compiler and generate a header file with a usable form of the
macros.

2) MIPS syscall numbers start at 5000, so we need a bigger map to hold
the sub-programs.

Signed-off-by: David Daney 


Acked-by: Daniel Borkmann 


Re: [PATCH 3/4] bpf: Add MIPS support to samples/bpf.

2017-06-13 Thread Daniel Borkmann

On 06/14/2017 01:49 AM, David Daney wrote:

Signed-off-by: David Daney 


Acked-by: Daniel Borkmann 


linux-next: manual merge of the net-next tree with the net tree

2017-06-13 Thread Stephen Rothwell
Hi all,

Today's linux-next merge of the net-next tree got a conflict in:

  drivers/net/ethernet/qlogic/qed/qed_debug.c

between commit:

  ace17c369295 ("qed: fix dump of context data")

from the net tree and commit:

  7b6859fbdcc4 ("qed: Utilize FW 8.20.0.0")

from the net-next tree.

I fixed it up (the latter incorporated the former) and can carry the
fix as necessary. This is now fixed as far as linux-next is concerned,
but any non trivial conflicts should be mentioned to your upstream
maintainer when your tree is submitted for merging.  You may also want
to consider cooperating with the maintainer of the conflicting tree to
minimise any particularly complex conflicts.

-- 
Cheers,
Stephen Rothwell


Re: [PATCH 2/4] test_bpf: Add test to make conditional jump cross a large number of insns.

2017-06-13 Thread Daniel Borkmann

On 06/14/2017 01:49 AM, David Daney wrote:

On MIPS, conditional branches can only span 32k instructions.  To
exceed this limit in the JIT with the BPF maximum of 4k insns, we need
to choose eBPF insns that expand to more than 8 machine instructions.
Use BPF_LD_ABS as it is quite complex.  This forces the JIT to invert
the sense of the branch to branch around a long jump to the end.

This (somewhat) verifies that the branch inversion logic and target
address calculation of the long jumps are done correctly.

Signed-off-by: David Daney 


Acked-by: Daniel Borkmann 


Re: [PATCH 1/4] tools: bpf_jit_disasm: Handle large images.

2017-06-13 Thread Daniel Borkmann

On 06/14/2017 01:49 AM, David Daney wrote:

Dynamically allocate memory so that JIT images larger than the size of
the statically allocated array can be handled.

Signed-off-by: David Daney 


Acked-by: Daniel Borkmann 


Re: [PATCH v2 4/5] MIPS: Add support for eBPF JIT.

2017-06-13 Thread Daniel Borkmann

On 06/14/2017 12:28 AM, David Daney wrote:

Since the eBPF machine has 64-bit registers, we only support this in
64-bit kernels.  As of the writing of this commit log test-bpf is showing:

   test_bpf: Summary: 316 PASSED, 0 FAILED, [308/308 JIT'ed]

All current test cases are successfully compiled.

Many examples in samples/bpf are usable, specifically tracex5 which
uses tail calls works.

Signed-off-by: David Daney 


Awesome work, David! The bits interacting with core BPF look
good to me.

Fyi, when Ralf merges this and it goes later on to Linus, there
will be two minor (silent) merge conflicts with net-next tree
(depending which one gets there first):

1) In bpf_int_jit_compile(), below the jited = 1 assignment, there
   needs to come a prog->jited_len = image_size.

2) The internal tail call opcode changed from BPF_JMP | BPF_CALL | BPF_X
   into BPF_JMP | BPF_TAIL_CALL.

Cheers,
Daniel


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

2017-06-13 Thread Stephen Hemminger
On Wed, 14 Jun 2017 00:10:34 +0100
Salil Mehta  wrote:

> +/* 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),
> +

Ethtool statistics should be reserved for device specific values and
should not be used just to clone statistics that already exist in
the network device.


Re: [PATCH V2 net-next 1/8] net: hns3: Add support of HNS3 Ethernet Driver for hip08 SoC

2017-06-13 Thread Stephen Hemminger
On Wed, 14 Jun 2017 00:10:28 +0100
Salil Mehta  wrote:

> +static irqreturn_t hns3_irq_handle(int irq, void *dev)
> +{
> + struct hns3_enet_tqp_vector *tqp_vector = dev;
> +
> + napi_schedule(_vector->napi);

In order to do NAPI correctly, the IRQ must be disabled.
If you are using MSI, then hardware will do it for you.

But I don't see you ever enable MSI or MSI-x in this driver.
Are you just assuming that the driver only works on one platform
and that platform has PCI MSI-X?


Re: [PATCH v2 net-next 8/9] bpf: nfp: Report bpf_prog ID during XDP_QUERY_PROG

2017-06-13 Thread Jakub Kicinski
On Tue, 13 Jun 2017 14:08:40 -0700, Martin KaFai Lau wrote:
> - case XDP_QUERY_PROG:
> - xdp->prog_attached = !!nn->dp.xdp_prog;
> + case XDP_QUERY_PROG: {
> + const struct bpf_prog *xdp_prog;
> +
> + xdp_prog = nn->dp.xdp_prog;
> + if (xdp_prog) {
> + xdp->prog_id = xdp_prog->aux->id;
> + xdp->prog_attached = true;
> + } else {
> + xdp->prog_id = 0;
> + xdp->prog_attached = false;
> + }
>   return 0;
> + }

I'm sorry to nit pick but it could be done on a single line:

case XDP_QUERY_PROG:
xdp->prog_attached = !!nn->dp.xdp_prog;
+   xdp->prog_id = nn->dp.xdp_prog ? nn->dp.xdp_prog->aux->id : 0;
return 0;
default:
return -EINVAL;


What would be even cooler is a helper like this:

static inline u32 bpf_prog_id(struct bpf_prog *prog)
{
if (!prog)
return 0;
return prog->aux->id;
}

in linux/bpf.h.  

In patch 1 I would be tempted to add a new command for getting the prog
id, instead of muxing through query to avoid the output parameter?  But
I'm OK with the code as is, its just a preference rather than an objection :)


[PATCH 2/4] test_bpf: Add test to make conditional jump cross a large number of insns.

2017-06-13 Thread David Daney
On MIPS, conditional branches can only span 32k instructions.  To
exceed this limit in the JIT with the BPF maximum of 4k insns, we need
to choose eBPF insns that expand to more than 8 machine instructions.
Use BPF_LD_ABS as it is quite complex.  This forces the JIT to invert
the sense of the branch to branch around a long jump to the end.

This (somewhat) verifies that the branch inversion logic and target
address calculation of the long jumps are done correctly.

Signed-off-by: David Daney 
---
 lib/test_bpf.c | 32 
 1 file changed, 32 insertions(+)

diff --git a/lib/test_bpf.c b/lib/test_bpf.c
index be88cba..9ecbf47 100644
--- a/lib/test_bpf.c
+++ b/lib/test_bpf.c
@@ -434,6 +434,30 @@ static int bpf_fill_ld_abs_vlan_push_pop(struct bpf_test 
*self)
return 0;
 }
 
+static int bpf_fill_jump_around_ld_abs(struct bpf_test *self)
+{
+   unsigned int len = BPF_MAXINSNS;
+   struct bpf_insn *insn;
+   int i = 0;
+
+   insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
+   if (!insn)
+   return -ENOMEM;
+
+   insn[i++] = BPF_MOV64_REG(R6, R1);
+   insn[i++] = BPF_LD_ABS(BPF_B, 0);
+   insn[i] = BPF_JMP_IMM(BPF_JEQ, R0, 10, len - i - 2);
+   i++;
+   while (i < len - 1)
+   insn[i++] = BPF_LD_ABS(BPF_B, 1);
+   insn[i] = BPF_EXIT_INSN();
+
+   self->u.ptr.insns = insn;
+   self->u.ptr.len = len;
+
+   return 0;
+}
+
 static int __bpf_fill_stxdw(struct bpf_test *self, int size)
 {
unsigned int len = BPF_MAXINSNS;
@@ -5022,6 +5046,14 @@ static struct bpf_test tests[] = {
{ { ETH_HLEN, 0xbef } },
.fill_helper = bpf_fill_ld_abs_vlan_push_pop,
},
+   {
+   "BPF_MAXINSNS: jump around ld_abs",
+   { },
+   INTERNAL,
+   { 10, 11 },
+   { { 2, 10 } },
+   .fill_helper = bpf_fill_jump_around_ld_abs,
+   },
/*
 * LD_IND / LD_ABS on fragmented SKBs
 */
-- 
2.9.4



[PATCH 0/4] bpf: Changes needed (or desired) for MIPS support

2017-06-13 Thread David Daney
This is a grab bag of changes to the bpf testing infrastructure I
developed working on MIPS eBPF JIT support.  The change to
bpf_jit_disasm is probably universally beneficial, the others are more
MIPS specific.

David Daney (4):
  tools: bpf_jit_disasm:  Handle large images.
  test_bpf: Add test to make conditional jump cross a large number of
insns.
  bpf: Add MIPS support to samples/bpf.
  samples/bpf: Fix tracex5 to work with MIPS syscalls.

 lib/test_bpf.c | 32 
 samples/bpf/Makefile   | 13 +
 samples/bpf/bpf_helpers.h  | 13 +
 samples/bpf/syscall_nrs.c  | 12 
 samples/bpf/tracex5_kern.c | 11 ---
 tools/net/bpf_jit_disasm.c | 37 ++---
 6 files changed, 104 insertions(+), 14 deletions(-)
 create mode 100644 samples/bpf/syscall_nrs.c

-- 
2.9.4



[PATCH 1/4] tools: bpf_jit_disasm: Handle large images.

2017-06-13 Thread David Daney
Dynamically allocate memory so that JIT images larger than the size of
the statically allocated array can be handled.

Signed-off-by: David Daney 
---
 tools/net/bpf_jit_disasm.c | 37 ++---
 1 file changed, 26 insertions(+), 11 deletions(-)

diff --git a/tools/net/bpf_jit_disasm.c b/tools/net/bpf_jit_disasm.c
index ad572e6..422d9abd 100644
--- a/tools/net/bpf_jit_disasm.c
+++ b/tools/net/bpf_jit_disasm.c
@@ -159,8 +159,8 @@ static void put_log_buff(char *buff)
free(buff);
 }
 
-static unsigned int get_last_jit_image(char *haystack, size_t hlen,
-  uint8_t *image, size_t ilen)
+static uint8_t *get_last_jit_image(char *haystack, size_t hlen,
+  unsigned int *ilen)
 {
char *ptr, *pptr, *tmp;
off_t off = 0;
@@ -168,9 +168,10 @@ static unsigned int get_last_jit_image(char *haystack, 
size_t hlen,
regmatch_t pmatch[1];
unsigned long base;
regex_t regex;
+   uint8_t *image;
 
if (hlen == 0)
-   return 0;
+   return NULL;
 
ret = regcomp(, "flen=[[:alnum:]]+ proglen=[[:digit:]]+ "
  "pass=[[:digit:]]+ image=[[:xdigit:]]+", REG_EXTENDED);
@@ -194,11 +195,22 @@ static unsigned int get_last_jit_image(char *haystack, 
size_t hlen,
 , , , );
if (ret != 4) {
regfree();
-   return 0;
+   return NULL;
+   }
+   if (proglen > 100) {
+   printf("proglen of %d too big, stopping\n", proglen);
+   return NULL;
}
 
+   image = malloc(proglen);
+   if (!image) {
+   printf("Out of memory\n");
+   return NULL;
+   }
+   memset(image, 0, proglen);
+
tmp = ptr = haystack + off;
-   while ((ptr = strtok(tmp, "\n")) != NULL && ulen < ilen) {
+   while ((ptr = strtok(tmp, "\n")) != NULL && ulen < proglen) {
tmp = NULL;
if (!strstr(ptr, "JIT code"))
continue;
@@ -208,10 +220,12 @@ static unsigned int get_last_jit_image(char *haystack, 
size_t hlen,
ptr = pptr;
do {
image[ulen++] = (uint8_t) strtoul(pptr, , 16);
-   if (ptr == pptr || ulen >= ilen) {
+   if (ptr == pptr) {
ulen--;
break;
}
+   if (ulen >= proglen)
+   break;
ptr = pptr;
} while (1);
}
@@ -222,7 +236,8 @@ static unsigned int get_last_jit_image(char *haystack, 
size_t hlen,
printf("%lx + :\n", base);
 
regfree();
-   return ulen;
+   *ilen = ulen;
+   return image;
 }
 
 static void usage(void)
@@ -237,12 +252,12 @@ static void usage(void)
 int main(int argc, char **argv)
 {
unsigned int len, klen, opt, opcodes = 0;
-   static uint8_t image[32768];
char *kbuff, *file = NULL;
char *ofile = NULL;
int ofd;
ssize_t nr;
uint8_t *pos;
+   uint8_t *image = NULL;
 
while ((opt = getopt(argc, argv, "of:O:")) != -1) {
switch (opt) {
@@ -262,7 +277,6 @@ int main(int argc, char **argv)
}
 
bfd_init();
-   memset(image, 0, sizeof(image));
 
kbuff = get_log_buff(file, );
if (!kbuff) {
@@ -270,8 +284,8 @@ int main(int argc, char **argv)
return -1;
}
 
-   len = get_last_jit_image(kbuff, klen, image, sizeof(image));
-   if (len <= 0) {
+   image = get_last_jit_image(kbuff, klen, );
+   if (!image) {
fprintf(stderr, "No JIT image found!\n");
goto done;
}
@@ -301,5 +315,6 @@ int main(int argc, char **argv)
 
 done:
put_log_buff(kbuff);
+   free(image);
return 0;
 }
-- 
2.9.4



[PATCH 4/4] samples/bpf: Fix tracex5 to work with MIPS syscalls.

2017-06-13 Thread David Daney
There are two problems:

1) In MIPS the __NR_* macros expand to an expression, this causes the
   sections of the object file to be named like:

  .
  .
  .
  [ 5] kprobe/(5000 + 1) PROGBITS 000160 ...
  [ 6] kprobe/(5000 + 0) PROGBITS 000258 ...
  [ 7] kprobe/(5000 + 9) PROGBITS 000348 ...
  .
  .
  .

The fix here is to use the "asm_offsets" trick to evaluate the macros
in the C compiler and generate a header file with a usable form of the
macros.

2) MIPS syscall numbers start at 5000, so we need a bigger map to hold
the sub-programs.

Signed-off-by: David Daney 
---
 samples/bpf/Makefile   | 13 +
 samples/bpf/syscall_nrs.c  | 12 
 samples/bpf/tracex5_kern.c | 11 ---
 3 files changed, 33 insertions(+), 3 deletions(-)
 create mode 100644 samples/bpf/syscall_nrs.c

diff --git a/samples/bpf/Makefile b/samples/bpf/Makefile
index 6c7468e..a0561dc 100644
--- a/samples/bpf/Makefile
+++ b/samples/bpf/Makefile
@@ -160,6 +160,17 @@ clean:
$(MAKE) -C ../../ M=$(CURDIR) clean
@rm -f *~
 
+$(obj)/syscall_nrs.s:  $(src)/syscall_nrs.c
+   $(call if_changed_dep,cc_s_c)
+
+$(obj)/syscall_nrs.h:  $(obj)/syscall_nrs.s FORCE
+   $(call filechk,offsets,__SYSCALL_NRS_H__)
+
+clean-files += syscall_nrs.h
+
+FORCE:
+
+
 # Verify LLVM compiler tools are available and bpf target is supported by llc
 .PHONY: verify_cmds verify_target_bpf $(CLANG) $(LLC)
 
@@ -180,6 +191,8 @@ verify_target_bpf: verify_cmds
 
 $(src)/*.c: verify_target_bpf
 
+$(obj)/tracex5_kern.o: $(obj)/syscall_nrs.h
+
 # asm/sysreg.h - inline assembly used by it is incompatible with llvm.
 # But, there is no easy way to fix it, so just exclude it since it is
 # useless for BPF samples.
diff --git a/samples/bpf/syscall_nrs.c b/samples/bpf/syscall_nrs.c
new file mode 100644
index 000..ce2a30b
--- /dev/null
+++ b/samples/bpf/syscall_nrs.c
@@ -0,0 +1,12 @@
+#include 
+#include 
+
+#define SYSNR(_NR) DEFINE(SYS ## _NR, _NR)
+
+void syscall_defines(void)
+{
+   COMMENT("Linux system call numbers.");
+   SYSNR(__NR_write);
+   SYSNR(__NR_read);
+   SYSNR(__NR_mmap);
+}
diff --git a/samples/bpf/tracex5_kern.c b/samples/bpf/tracex5_kern.c
index 7e4cf74..f57f4e1 100644
--- a/samples/bpf/tracex5_kern.c
+++ b/samples/bpf/tracex5_kern.c
@@ -9,6 +9,7 @@
 #include 
 #include 
 #include 
+#include "syscall_nrs.h"
 #include "bpf_helpers.h"
 
 #define PROG(F) SEC("kprobe/"__stringify(F)) int bpf_func_##F
@@ -17,7 +18,11 @@ struct bpf_map_def SEC("maps") progs = {
.type = BPF_MAP_TYPE_PROG_ARRAY,
.key_size = sizeof(u32),
.value_size = sizeof(u32),
+#ifdef __mips__
+   .max_entries = 6000, /* MIPS n64 syscalls start at 5000 */
+#else
.max_entries = 1024,
+#endif
 };
 
 SEC("kprobe/__seccomp_filter")
@@ -37,7 +42,7 @@ int bpf_prog1(struct pt_regs *ctx)
 }
 
 /* we jump here when syscall number == __NR_write */
-PROG(__NR_write)(struct pt_regs *ctx)
+PROG(SYS__NR_write)(struct pt_regs *ctx)
 {
struct seccomp_data sd;
 
@@ -50,7 +55,7 @@ PROG(__NR_write)(struct pt_regs *ctx)
return 0;
 }
 
-PROG(__NR_read)(struct pt_regs *ctx)
+PROG(SYS__NR_read)(struct pt_regs *ctx)
 {
struct seccomp_data sd;
 
@@ -63,7 +68,7 @@ PROG(__NR_read)(struct pt_regs *ctx)
return 0;
 }
 
-PROG(__NR_mmap)(struct pt_regs *ctx)
+PROG(SYS__NR_mmap)(struct pt_regs *ctx)
 {
char fmt[] = "mmap\n";
bpf_trace_printk(fmt, sizeof(fmt));
-- 
2.9.4



[PATCH 3/4] bpf: Add MIPS support to samples/bpf.

2017-06-13 Thread David Daney
Signed-off-by: David Daney 
---
 samples/bpf/bpf_helpers.h | 13 +
 1 file changed, 13 insertions(+)

diff --git a/samples/bpf/bpf_helpers.h b/samples/bpf/bpf_helpers.h
index 9a9c95f..76526da 100644
--- a/samples/bpf/bpf_helpers.h
+++ b/samples/bpf/bpf_helpers.h
@@ -135,6 +135,19 @@ static int (*bpf_skb_change_head)(void *, int len, int 
flags) =
 #define PT_REGS_SP(x) ((x)->sp)
 #define PT_REGS_IP(x) ((x)->pc)
 
+#elif defined(__mips__)
+
+#define PT_REGS_PARM1(x) ((x)->regs[4])
+#define PT_REGS_PARM2(x) ((x)->regs[5])
+#define PT_REGS_PARM3(x) ((x)->regs[6])
+#define PT_REGS_PARM4(x) ((x)->regs[7])
+#define PT_REGS_PARM5(x) ((x)->regs[8])
+#define PT_REGS_RET(x) ((x)->regs[31])
+#define PT_REGS_FP(x) ((x)->regs[30]) /* Works only with CONFIG_FRAME_POINTER 
*/
+#define PT_REGS_RC(x) ((x)->regs[1])
+#define PT_REGS_SP(x) ((x)->regs[29])
+#define PT_REGS_IP(x) ((x)->cp0_epc)
+
 #elif defined(__powerpc__)
 
 #define PT_REGS_PARM1(x) ((x)->gpr[3])
-- 
2.9.4



Re: [PATCH V2 net-next 6/8] net: hns3: Add MDIO support to HNS3 Ethernet driver for hip08 SoC

2017-06-13 Thread Florian Fainelli
On 06/13/2017 04:10 PM, Salil Mehta wrote:
> This patch adds the support of MDIO bus interface for HNS3 driver.
> Code provides various interfaces to start and stop the PHY layer
> and to read and write the MDIO bus or PHY.
> 
> Signed-off-by: Daode Huang 
> Signed-off-by: lipeng 
> Signed-off-by: Salil Mehta 
> Signed-off-by: Yisen Zhuang 
> ---

> + phy = get_phy_device(mdio_bus, mac->phy_addr, mac->is_c45);
> + if (!phy || IS_ERR(phy)) {
> + dev_err(mdio_bus->parent, "Failed to get phy device\n");
> + ret = -EIO;
> + goto err_mdio_register;
> + }
> +
> + phy->irq = mdio_bus->irq[mac->phy_addr];
> +
> + /* All data is now stored in the phy struct;
> +  * register it
> +  */
> + ret = phy_device_register(phy);
> + if (ret) {
> + ret = -ENODEV;
> + goto err_phy_register;
> + }

Until this gets fixed in the core PHY library, it's okay to do that, but
please fix the

> +
> + mac->phy_dev = phy;
> +
> + return 0;
> +
> +err_phy_register:
> + phy_device_free(phy);
> +
> +err_mdio_register:
> + mdiobus_unregister(mdio_bus);
> + mdiobus_free(mdio_bus);
> +err_miibus_alloc:
> + return ret;
> +}
> +
> +static void hclge_mac_adjust_link(struct net_device *net_dev)
> +{
> + int duplex;
> + int speed;
> + struct hclge_mac *hw_mac;
> + struct hclge_hw *hw;
> + struct hclge_dev *hdev;
> +
> + if (!net_dev)
> + return;
> +
> + hw_mac = container_of(net_dev, struct hclge_mac, ndev);
> + hw = container_of(hw_mac, struct hclge_hw, mac);
> + hdev = hw->back;
> +
> + speed = hw_mac->phy_dev->speed;
> + duplex = hw_mac->phy_dev->duplex;
> +
> + /* update antoneg. */
> + hw_mac->autoneg = hw_mac->phy_dev->autoneg;
> +
> + if ((hw_mac->speed != speed) || (hw_mac->duplex != duplex))
> + (void)hclge_cfg_mac_speed_dup(hdev, speed, !!duplex);
> +}
> +
> +int hclge_mac_start_phy(struct hclge_dev *hdev)
> +{
> + struct hclge_mac *mac = >hw.mac;
> + struct phy_device *phy_dev = mac->phy_dev;
> + int ret;
> +
> + if (!phy_dev)
> + return 0;
> +
> + if (mac->phy_if != PHY_INTERFACE_MODE_XGMII) {
> + phy_dev->dev_flags = 0;
> +
> + ret = phy_connect_direct(>ndev, phy_dev,
> +  hclge_mac_adjust_link,
> +  mac->phy_if);
> + phy_dev->supported = SUPPORTED_10baseT_Half |
> + SUPPORTED_10baseT_Full |
> + SUPPORTED_100baseT_Half |
> + SUPPORTED_100baseT_Full |
> + SUPPORTED_Autoneg |
> + SUPPORTED_1000baseT_Full;
> +
> + phy_dev->autoneg = false;
> + } else {
> + ret = phy_attach_direct(>ndev, phy_dev, 0, mac->phy_if);
> + phy_dev->supported = SUPPORTED_1baseR_FEC |
> + SUPPORTED_1baseKR_Full;
> + }

I really don't see why you don't take the exact same path whether it's
XGMII or not, just like you are not masking with that the PHY driver
already supports, this needs fixing.

> + if (unlikely(ret))
> + return -ENODEV;
> +
> + phy_start(phy_dev);
> +
> + return 0;
> +}
> +
> +void hclge_mac_stop_phy(struct hclge_dev *hdev)
> +{
> + struct hclge_mac *mac = >hw.mac;
> + struct phy_device *phy_dev = mac->phy_dev;
> +
> + if (!phy_dev)
> + return;
> +
> + phy_stop(phy_dev);
> +
> + if (mac->phy_if != PHY_INTERFACE_MODE_XGMII)
> + phy_disconnect(phy_dev);
> + else
> + phy_detach(phy_dev);

Same here.
-- 
Florian


[RFC/RFT PATCH 4/4] [debug] ARM: am335x: illustrate hwstamp

2017-06-13 Thread Grygorii Strashko
This patch allows to test CPTS HW_TS_PUSH functionality on am335x boards

below sequence of commands will enable Timer7 to trigger 1sec
periodic pulses on CPTS HW4_TS_PUSH input pin:

 # echo 10 > /sys/class/pwm/pwmchip0/pwm0/period
 # echo 5 > /sys/class/pwm/pwmchip0/pwm0/duty_cycle
 # echo 1 > /sys/class/pwm/pwmchip0/pwm0/enable
 # ./ptp/testptp -e 10 -i 3
external time stamp request okay
event index 3 at 1493259028.376600798
event index 3 at 1493259029.377170898
event index 3 at 1493259030.377741039
event index 3 at 1493259031.378311139
event index 3 at 1493259032.378881279
event index 3 at 1493259033.379451424
event index 3 at 1493259034.380021520
event index 3 at 1493259035.380591660
event index 3 at 1493259036.381161765
event index 3 at 1493259037.381731909

Signed-off-by: Grygorii Strashko 
---
 arch/arm/boot/dts/am335x-boneblack.dts | 6 ++
 arch/arm/boot/dts/am335x-evm.dts   | 7 +++
 arch/arm/boot/dts/am33xx.dtsi  | 1 +
 arch/arm/configs/omap2plus_defconfig   | 2 +-
 4 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/arch/arm/boot/dts/am335x-boneblack.dts 
b/arch/arm/boot/dts/am335x-boneblack.dts
index 935ed17..997f5b4 100644
--- a/arch/arm/boot/dts/am335x-boneblack.dts
+++ b/arch/arm/boot/dts/am335x-boneblack.dts
@@ -25,4 +25,10 @@
oppnitro@10 {
opp-supported-hw = <0x06 0x0100>;
};
+
+   pwm7: dmtimer-pwm {
+   compatible = "ti,omap-dmtimer-pwm";
+   ti,timers = <>;
+   #pwm-cells = <3>;
+   };
 };
diff --git a/arch/arm/boot/dts/am335x-evm.dts b/arch/arm/boot/dts/am335x-evm.dts
index 1c37a7c..ec36197 100644
--- a/arch/arm/boot/dts/am335x-evm.dts
+++ b/arch/arm/boot/dts/am335x-evm.dts
@@ -164,6 +164,13 @@
system-clock-frequency = <1200>;
};
};
+
+   pwm7: dmtimer-pwm {
+   compatible = "ti,omap-dmtimer-pwm";
+   ti,timers = <>;
+   #pwm-cells = <3>;
+   };
+
 };
 
 _pinmux {
diff --git a/arch/arm/boot/dts/am33xx.dtsi b/arch/arm/boot/dts/am33xx.dtsi
index 9e24294..1a64b80 100644
--- a/arch/arm/boot/dts/am33xx.dtsi
+++ b/arch/arm/boot/dts/am33xx.dtsi
@@ -864,6 +864,7 @@
ranges;
syscon = <_conf>;
status = "disabled";
+   cpts-ext-ts-inputs = <4>;
 
davinci_mdio: mdio@4a101000 {
compatible = "ti,cpsw-mdio","ti,davinci_mdio";
diff --git a/arch/arm/configs/omap2plus_defconfig 
b/arch/arm/configs/omap2plus_defconfig
index a120ae8..6d3dcbc 100644
--- a/arch/arm/configs/omap2plus_defconfig
+++ b/arch/arm/configs/omap2plus_defconfig
@@ -459,7 +459,7 @@ CONFIG_CPCAP_ADC=m
 CONFIG_TI_AM335X_ADC=m
 CONFIG_BMP280=m
 CONFIG_PWM=y
-CONFIG_PWM_OMAP_DMTIMER=m
+CONFIG_PWM_OMAP_DMTIMER=y
 CONFIG_PWM_TIECAP=m
 CONFIG_PWM_TIEHRPWM=m
 CONFIG_PWM_TWL=m
-- 
2.10.1



[RFC/RFT PATCH 0/4] net: ethernat: ti: cpts: enable irq and HW_TS_PUSH

2017-06-13 Thread Grygorii Strashko
Intention of this post is to get some early review and wider testing.

This series adds CPTS IRQ support, which allows to fix TX timestamping issue
and add support for HW_TS_PUSH events.

The idea of using CPTS IRQ for proper support of HW_TS_PUSH events
was originally discussed in [1].

Further TX timestamping issue was discovered and enabling of CPTS IRQ allows to
fix it also.
 - TX timestamp can be missed with the low Ethernet link connection speed.
In this case CPDMA notification about packet processing can be received before
CPTS TX timestamp event, which is sent when packet actually left CPSW while
cpdma notification is sent when packet pushed in CPSW fifo. 
As result, when connection is slow and CPU is fast enough TX timestamping is not
working properly. Issue was discovered on am57x boards with Ethernet link
connection speed forced to 100M and on am335x-evm with thernet link
connection speed forced to 10M using timestamping tool.

PATCH 4: provided to illustrate how HW_TS_PUSH can be used.

I've tested it on am57/dra7 and am335.

!!! Unfortunatelly, I still trying to enable CPTS IRQ on Keystone 2 and
this is blocker for now.

Series based on top of net-next tree,
commit a1fa1a0 net: phy: marvell: Show complete link partner advertising.

[1] https://www.mail-archive.com/netdev@vger.kernel.org/msg141466.html

Grygorii Strashko (4):
  net: ethernet: ti: cpts: use own highpri workqueue
  net: ethernat: ti: cpts: enable irq
  net: ethernet: ti: cpts: add support of cpts HW_TS_PUSH
  [debug] ARM: am335x: illustrate hwstamp

 Documentation/devicetree/bindings/net/cpsw.txt |   4 +
 .../devicetree/bindings/net/keystone-netcp.txt |   6 +
 arch/arm/boot/dts/am335x-boneblack.dts |   6 +
 arch/arm/boot/dts/am335x-evm.dts   |   7 +
 arch/arm/boot/dts/am33xx.dtsi  |   1 +
 arch/arm/configs/omap2plus_defconfig   |   2 +-
 drivers/net/ethernet/ti/cpsw.c |  42 +-
 drivers/net/ethernet/ti/cpts.c | 432 -
 drivers/net/ethernet/ti/cpts.h |  23 +-
 9 files changed, 409 insertions(+), 114 deletions(-)

-- 
2.10.1



[RFC/RFT PATCH 1/4] net: ethernet: ti: cpts: use own highpri workqueue

2017-06-13 Thread Grygorii Strashko
There could be significant delay in CPTS work schedule under high system
load and on -RT which could cause CPTS misbehavior due to internal counter
overflow. Usage of own highpri ordered workqueue allows to avoid such kind
of issues and makes it possible to tune priority of CPTS workqueue thread
on -RT.

Signed-off-by: Grygorii Strashko 
---
 drivers/net/ethernet/ti/cpts.c | 11 +--
 drivers/net/ethernet/ti/cpts.h |  1 +
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/ti/cpts.c b/drivers/net/ethernet/ti/cpts.c
index 32279d2..f35d950 100644
--- a/drivers/net/ethernet/ti/cpts.c
+++ b/drivers/net/ethernet/ti/cpts.c
@@ -245,7 +245,8 @@ static void cpts_overflow_check(struct work_struct *work)
 
cpts_ptp_gettime(>info, );
pr_debug("cpts overflow check at %lld.%09lu\n", ts.tv_sec, ts.tv_nsec);
-   schedule_delayed_work(>overflow_work, cpts->ov_check_period);
+   queue_delayed_work(cpts->workwq, >overflow_work,
+  cpts->ov_check_period);
 }
 
 static int cpts_match(struct sk_buff *skb, unsigned int ptp_class,
@@ -378,7 +379,8 @@ int cpts_register(struct cpts *cpts)
}
cpts->phc_index = ptp_clock_index(cpts->clock);
 
-   schedule_delayed_work(>overflow_work, cpts->ov_check_period);
+   queue_delayed_work(cpts->workwq, >overflow_work,
+  cpts->ov_check_period);
return 0;
 
 err_ptp:
@@ -477,6 +479,11 @@ struct cpts *cpts_create(struct device *dev, void __iomem 
*regs,
cpts->reg = (struct cpsw_cpts __iomem *)regs;
spin_lock_init(>lock);
INIT_DELAYED_WORK(>overflow_work, cpts_overflow_check);
+   cpts->workwq = alloc_ordered_workqueue("cpts_ptp",
+  WQ_MEM_RECLAIM | WQ_HIGHPRI);
+   if (!cpts->workwq)
+   return ERR_PTR(-ENOMEM);
+
 
ret = cpts_of_parse(cpts, node);
if (ret)
diff --git a/drivers/net/ethernet/ti/cpts.h b/drivers/net/ethernet/ti/cpts.h
index c96eca2..3eae01c 100644
--- a/drivers/net/ethernet/ti/cpts.h
+++ b/drivers/net/ethernet/ti/cpts.h
@@ -125,6 +125,7 @@ struct cpts {
struct list_head pool;
struct cpts_event pool_data[CPTS_MAX_EVENTS];
unsigned long ov_check_period;
+   struct workqueue_struct *workwq;
 };
 
 void cpts_rx_timestamp(struct cpts *cpts, struct sk_buff *skb);
-- 
2.10.1



[RFC/RFT PATCH 2/4] net: ethernat: ti: cpts: enable irq

2017-06-13 Thread Grygorii Strashko
There are two reasons for this change:
1) enabling of HW_TS_PUSH events as suggested by Richard Cochran and
discussed in [1]
2) fixing an TX timestamping miss issue which happens with low speed
ethernet connections and was reproduced on am57xx and am335x boards.
Issue description: With the low Ethernet connection speed CPDMA notification
about packet processing can be received before CPTS TX timestamp event,
which is sent when packet actually left CPSW while cpdma notification is
sent when packet pushed in CPSW fifo.  As result, when connection is slow
and CPU is fast enough TX timestamp can be missed and not working properly.

This patch converts CPTS driver to use IRQ instead of polling in the
following way:

 - CPTS_EV_PUSH: CPTS_EV_PUSH is used to get current CPTS counter value and
triggered from PTP callbacks and cpts_overflow_check() work. With this
change current CPTS counter value will be read in IRQ handler and saved in
CPTS context "cur_timestamp" field. The compeltion event will be signalled to 
the
requestor. The timecounter->read() will just read saved value. Access to
the "cur_timestamp" is protected by mutex "ptp_clk_mutex".

cpts_get_time:
  reinit_completion(>ts_push_complete);
  cpts_write32(cpts, TS_PUSH, ts_push);
  wait_for_completion_interruptible_timeout(>ts_push_complete, HZ);
  ns = timecounter_read(>tc);

cpts_irq:
  case CPTS_EV_PUSH:
cpts->cur_timestamp = lo;
complete(>ts_push_complete);

- CPTS_EV_TX: signals when CPTS timestamp is ready for valid TX PTP
packets. The TX timestamp is requested from cpts_tx_timestamp() which is
called for each transmitted packet from NAPI cpsw_tx_poll() callback. With
this change, CPTS event queue will be checked for existing CPTS_EV_TX
event, corresponding to the current TX packet, and if event is not found - 
packet
will be placed in CPTS TX packet queue for later processing. CPTS TX packet
queue will be processed from hi-priority cpts_ts_work() work which is scheduled
as from cpts_tx_timestamp() as from CPTS IRQ handler when CPTS_EV_TX event
is received.

cpts_tx_timestamp:
 check if packet is PTP packet
 try to find corresponding CPTS_EV_TX event
   if found: report timestamp
   if not found: put packet in TX queue, schedule cpts_ts_work()

cpts_irq:
 case CPTS_EV_TX:
 put event in CPTS event queue
 schedule cpts_ts_work()

cpts_ts_work:
   for each packet in  CPTS TX packet queue
   try to find corresponding CPTS_EV_TX event
   if found: report timestamp
   if timeout: drop packet

- CPTS_EV_RX: signals when CPTS timestamp is ready for valid RX PTP
packets. The RX timestamp is requested from cpts_rx_timestamp() which is
called for each received packet from NAPI cpsw_rx_poll() callback. With
this change, CPTS event queue will be checked for existing CPTS_EV_RX
event, corresponding to the current RX packet, and if event is not found - 
packet
will be placed in CPTS RX packet queue for later processing. CPTS RX packet
queue will be processed from hi-priority cpts_ts_work() work which is scheduled
as from cpts_rx_timestamp() as from CPTS IRQ handler when CPTS_EV_RX event
is received. cpts_rx_timestamp() has been updated to return failure in case
of RX timestamp processing delaying and, in such cases, caller of
cpts_rx_timestamp() should not call netif_receive_skb().

cpts_rx_timestamp:
 check if packet is PTP packet
 try to find corresponding CPTS_EV_RX event
   if found: report timestamp, return success
   if not found: put packet in RX queue, schedule cpts_ts_work(),
 return failure

cpts_irq:
 case CPTS_EV_RX:
 put event in CPTS event queue
 schedule cpts_ts_work()

cpts_ts_work:
   for each packet in  CPTS RX packet queue
   try to find corresponding CPTS_EV_RX event
   if found: add timestamp and report packet netif_receive_skb()
   if timeout: drop packet

there are some statistic added in cpsw_get_strings() for debug purposes.

User space tools (like ptp4l) might require to take into account possible
delay in timestamp reception (for example ptp4l works with
tx_timestamp_timeout=100) as TX timestamp genaration can be delayed till
cpts_ts_work() executuion.

[1] https://www.mail-archive.com/netdev@vger.kernel.org/msg141466.html

Signed-off-by: Grygorii Strashko 
---
 drivers/net/ethernet/ti/cpsw.c |  42 -
 drivers/net/ethernet/ti/cpts.c | 364 +
 drivers/net/ethernet/ti/cpts.h |  18 +-
 3 files changed, 314 insertions(+), 110 deletions(-)

diff --git a/drivers/net/ethernet/ti/cpsw.c b/drivers/net/ethernet/ti/cpsw.c
index b6a0d92..f845926 100644
--- a/drivers/net/ethernet/ti/cpsw.c
+++ b/drivers/net/ethernet/ti/cpsw.c
@@ -143,7 +143,7 @@ do {
\
 #define cpsw_slave_index(cpsw, priv)   \
((cpsw->data.dual_emac) ? priv->emac_port : \
cpsw->data.active_slave)
-#define IRQ_NUM 

[RFC/RFT PATCH 3/4] net: ethernet: ti: cpts: add support of cpts HW_TS_PUSH

2017-06-13 Thread Grygorii Strashko
This patch adds support of the CPTS HW_TS_PUSH events which are generated
by external low frequency time stamp channels on TI's OMAP CPSW[ and
Keystone 2 platforms]. It supports up to 8 external time stamp channels for
HW_TS_PUSH input pins (the number of supported channel is different for
different SoCs and CPTS versions, check corresponding Data maual before
enabling it). Therefore, new DT property "cpts-ext-ts-inputs" is introduced
for specifying number of available external timestamp channels.

The PTP external timestamp (extts) infrastructure can be used for
HW_TS_PUSH timestamp controlling and reporting.

Signed-off-by: Grygorii Strashko 
---
 Documentation/devicetree/bindings/net/cpsw.txt |  4 ++
 .../devicetree/bindings/net/keystone-netcp.txt |  6 +++
 drivers/net/ethernet/ti/cpts.c | 57 +-
 drivers/net/ethernet/ti/cpts.h |  4 ++
 4 files changed, 70 insertions(+), 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/net/cpsw.txt 
b/Documentation/devicetree/bindings/net/cpsw.txt
index 7cc15c9..7b2d14d 100644
--- a/Documentation/devicetree/bindings/net/cpsw.txt
+++ b/Documentation/devicetree/bindings/net/cpsw.txt
@@ -37,6 +37,10 @@ Optional properties:
  Mult and shift will be calculated basing on CPTS
  rftclk frequency if both cpts_clock_shift and
  cpts_clock_mult properties are not provided.
+- cpts-ext-ts-inputs   : The number of external time stamp channels.
+ The different CPTS versions might support up 8
+ external time stamp channels.
+ if absent - unsupported.
 
 Slave Properties:
 Required properties:
diff --git a/Documentation/devicetree/bindings/net/keystone-netcp.txt 
b/Documentation/devicetree/bindings/net/keystone-netcp.txt
index 04ba1dc..1460da5 100644
--- a/Documentation/devicetree/bindings/net/keystone-netcp.txt
+++ b/Documentation/devicetree/bindings/net/keystone-netcp.txt
@@ -113,6 +113,12 @@ Optional properties:
will only initialize these ports and attach PHY
driver to them if needed.
 
+ Properties related to cpts configurations.
+   - cpts-ext-ts-inputs:
+   The number of external time stamp channels.
+   The different CPTS versions might support up 8
+   external time stamp channels. if absent - unsupported.
+
 NetCP interface properties: Interface specification for NetCP sub-modules.
 Required properties:
 - rx-channel:  the navigator packet dma channel name for rx.
diff --git a/drivers/net/ethernet/ti/cpts.c b/drivers/net/ethernet/ti/cpts.c
index 25191e9..e6f1383 100644
--- a/drivers/net/ethernet/ti/cpts.c
+++ b/drivers/net/ethernet/ti/cpts.c
@@ -39,6 +39,11 @@ struct cpts_skb_cb_data {
 #define cpts_read32(c, r)  readl_relaxed(>reg->r)
 #define cpts_write32(c, v, r)  writel_relaxed(v, >reg->r)
 
+static int cpts_event_port(struct cpts_event *event)
+{
+   return (event->high >> PORT_NUMBER_SHIFT) & PORT_NUMBER_MASK;
+}
+
 static int event_expired(struct cpts_event *event)
 {
return time_after(jiffies, event->tmo);
@@ -181,9 +186,46 @@ static int cpts_ptp_settime(struct ptp_clock_info *ptp,
return 0;
 }
 
+/* HW TS */
+static int cpts_extts_enable(struct cpts *cpts, u32 index, int on)
+{
+   u32 v;
+
+   if (index >= cpts->info.n_ext_ts)
+   return -ENXIO;
+
+   if (((cpts->hw_ts_enable & BIT(index)) >> index) == on)
+   return 0;
+
+   mutex_lock(>ptp_clk_mutex);
+
+   v = cpts_read32(cpts, control);
+   if (on) {
+   v |= BIT(8 + index);
+   cpts->hw_ts_enable |= BIT(index);
+   } else {
+   v &= ~BIT(8 + index);
+   cpts->hw_ts_enable &= ~BIT(index);
+   }
+   cpts_write32(cpts, v, control);
+
+   mutex_unlock(>ptp_clk_mutex);
+
+   return 0;
+}
+
 static int cpts_ptp_enable(struct ptp_clock_info *ptp,
   struct ptp_clock_request *rq, int on)
 {
+   struct cpts *cpts = container_of(ptp, struct cpts, info);
+
+   switch (rq->type) {
+   case PTP_CLK_REQ_EXTTS:
+   return cpts_extts_enable(cpts, rq->extts.index, on);
+   default:
+   break;
+   }
+
return -EOPNOTSUPP;
 }
 
@@ -203,12 +245,12 @@ static struct ptp_clock_info cpts_info = {
 
 static void cpts_overflow_check(struct work_struct *work)
 {
-   struct timespec64 ts;
struct cpts *cpts = container_of(work, struct cpts, overflow_work.work);
struct timespec64 ts;
unsigned long flags;
 
cpts_ptp_gettime(>info, );
+
pr_debug("cpts overflow check at %lld.%09lu\n", ts.tv_sec, ts.tv_nsec);
queue_delayed_work(cpts->workwq, >overflow_work,
   cpts->ov_check_period);
@@ -222,6 +264,7 @@ static 

[PATCH V2 net-next 0/8] Hisilicon Network Subsystem 3 Ethernet Driver

2017-06-13 Thread Salil Mehta
This patch-set contains the support of the HNS3 (Hisilicon Network Subsystem 3)
Ethernet driver for hip08 family of SoCs and future upcoming SoCs.

Hisilicon's new hip08 SoCs have integrated ethernet based on PCI Express and
hence there was a need of new driver over the previous HNS driver which is 
already part of the Linux mainline. This new driver is NOT backward
compatible with HNS.

This current driver is meant to control the Physical Function and there would
soon be a support of a separate driver for Virtual Function once this base PF
driver has been accepted. Also, this driver is the ongoing development work and
HNS3 Ethernet driver would be incrementally enhanced with more new features.

High Level Architecture:

[ Ethtool ]
   ^  |
   |  | 
   [Ethernet Client]  [RoCE Client] . . . [ Ethernet Client ] 
- |
 ||
 [ HNAE3 Framework (Register/unregister) ]|
 ||
- |
   [ HNAE Device ]|
 ||
   [ HCLGE Layer] |
 |_   |
|| |  |
[ MDIO ][ Scheduler/Shaper ]  [ Debugfs ] |
|| |  |
||_|  | 
 ||
 [ IMP command Interface ]|
- |
  HIP08  H A R D W A R E  *


Current patch-set broadly adds the support of the following PF functionality:
 1. Basic Rx and Tx functionality 
 2. TSO support
 3. Ethtool support
 4. Debugfs support 
 5. HNAE framework and hardware compatability layer
 6. Scheduler and Shaper support in transmit function
 7. MDIO support

Change Log:
V1->V2: Addressed some comments by kbuild, Yuval MIntz, Andrew Lunn &
Florian Fainelli in the following patches:
  * Add support of HNS3 Ethernet Driver for hip08 SoC
  * Add MDIO support to HNS3 Ethernet driver for hip08 SoC
  * Add support of debugfs interface to HNS3 driver

Salil Mehta (8):
  net: hns3: Add support of HNS3 Ethernet Driver for hip08 SoC
  net: hns3: Add support of the HNAE3 framework
  net: hns3: Add HNS3 IMP(Integrated Mgmt Proc) Cmd Interface Support
  net: hns3: Add HNS3 Acceleration Engine & Compatibility Layer Support
  net: hns3: Add support of TX Scheduler & Shaper to HNS3 driver
  net: hns3: Add MDIO support to HNS3 Ethernet driver for hip08 SoC
  net: hns3: Add Ethtool support to HNS3 driver
  net: hns3: Add HNS3 driver to kernel build framework & MAINTAINERS

 MAINTAINERS|8 +
 drivers/net/ethernet/hisilicon/Kconfig |   24 +
 drivers/net/ethernet/hisilicon/Makefile|1 +
 drivers/net/ethernet/hisilicon/hns3/Makefile   |7 +
 drivers/net/ethernet/hisilicon/hns3/hnae3.c|  305 ++
 drivers/net/ethernet/hisilicon/hns3/hnae3.h|  449 +++
 .../net/ethernet/hisilicon/hns3/hns3pf/Makefile|   11 +
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.c |  347 ++
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h |  743 
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.c| 4255 
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.h|  495 +++
 .../ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c|  295 ++
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.c  | 1018 +
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.h  |  108 +
 .../net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.c | 2842 +
 .../net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.h |  585 +++
 .../ethernet/hisilicon/hns3/hns3pf/hns3_ethtool.c  |  894 
 17 files changed, 12387 insertions(+)
 create mode 100644 drivers/net/ethernet/hisilicon/hns3/Makefile
 create mode 100644 drivers/net/ethernet/hisilicon/hns3/hnae3.c
 create mode 100644 drivers/net/ethernet/hisilicon/hns3/hnae3.h
 create mode 100644 drivers/net/ethernet/hisilicon/hns3/hns3pf/Makefile
 create mode 100644 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.c
 create mode 100644 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
 create mode 100644 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
 create mode 100644 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h
 create mode 100644 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c
 create mode 100644 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.c
 create mode 100644 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.h
 create mode 100644 drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.c
 create mode 100644 drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.h
 

[PATCH V2 net-next 1/8] net: hns3: Add support of HNS3 Ethernet Driver for hip08 SoC

2017-06-13 Thread Salil Mehta
This patch adds the support of Hisilicon Network Subsystem 3
Ethernet driver to hip08 family of SoCs.

This driver includes basic Rx/Tx functionality. It also includes
the client registration code with the HNAE3(Hisilicon Network
Acceleration Engine 3) framework.

This work provides the initial support to the hip08 SoC and
would incrementally add features or enhancements.

Signed-off-by: Daode Huang 
Signed-off-by: lipeng 
Signed-off-by: Salil Mehta 
Signed-off-by: Yisen Zhuang 
---
Patch V2: Addressed below comments:
  1. Kbuild: https://lkml.org/lkml/2017/6/11/73
  2. Yuval Mintz: https://lkml.org/lkml/2017/6/10/78
Patch V1: Initial Submit
---
 .../net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.c | 2842 
 .../net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.h |  585 
 2 files changed, 3427 insertions(+)
 create mode 100644 drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.c
 create mode 100644 drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.h

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.c
new file mode 100644
index 000..ceb08f8
--- /dev/null
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.c
@@ -0,0 +1,2842 @@
+/*
+ * 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 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "hnae3.h"
+#include "hns3_enet.h"
+
+const char hns3_driver_name[] = "hns3";
+static const char hns3_driver_string[] =
+   "Hisilicon Ethernet Network Driver for Hi162x Family";
+static const char hns3_copyright[] = "Copyright (c) 2017 Huawei Corporation.";
+
+/* hns3_pci_tbl - PCI Device ID Table
+ *
+ * Last entry must be all 0s
+ *
+ * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
+ *   Class, Class Mask, private data (not used) }
+ */
+static const struct pci_device_id hns3_pci_tbl[] = {
+   {PCI_VDEVICE(HUAWEI, HNAE3_DEV_ID_GE), 0},
+   {PCI_VDEVICE(HUAWEI, HNAE3_DEV_ID_25GE), 0},
+   {PCI_VDEVICE(HUAWEI, HNAE3_DEV_ID_25GE_RDMA), 0},
+   {PCI_VDEVICE(HUAWEI, HNAE3_DEV_ID_25GE_RDMA_MACSEC), 0},
+   {PCI_VDEVICE(HUAWEI, HNAE3_DEV_ID_50GE_RDMA), 0},
+   {PCI_VDEVICE(HUAWEI, HNAE3_DEV_ID_50GE_RDMA_MACSEC), 0},
+   {PCI_VDEVICE(HUAWEI, HNAE3_DEV_ID_100G_RDMA_MACSEC), 0},
+   /* required last entry */
+   {0, }
+};
+MODULE_DEVICE_TABLE(pci, hns3_pci_tbl);
+
+static irqreturn_t hns3_irq_handle(int irq, void *dev)
+{
+   struct hns3_enet_tqp_vector *tqp_vector = dev;
+
+   napi_schedule(_vector->napi);
+
+   return IRQ_HANDLED;
+}
+
+static int hns3_nic_init_irq(struct hns3_nic_priv *priv)
+{
+   struct pci_dev *pdev = priv->ae_handle->pdev;
+   struct hns3_enet_tqp_vector *tqp_vectors;
+   int txrx_int_idx = 0;
+   int rx_int_idx = 0;
+   int tx_int_idx = 0;
+   int ret;
+   int i;
+
+   for (i = 0; i < priv->vector_num; i++) {
+   tqp_vectors = >tqp_vector[i];
+
+   if (tqp_vectors->irq_init_flag == HNS3_VEVTOR_INITED)
+   continue;
+
+   if (tqp_vectors->tx_group.ring && tqp_vectors->rx_group.ring) {
+   snprintf(tqp_vectors->name, HNAE3_INT_NAME_LEN - 1,
+"%s-%s-%d", priv->netdev->name, "TxRx",
+txrx_int_idx++);
+   txrx_int_idx++;
+   } else if (tqp_vectors->rx_group.ring) {
+   snprintf(tqp_vectors->name, HNAE3_INT_NAME_LEN - 1,
+"%s-%s-%d", priv->netdev->name, "Rx",
+rx_int_idx++);
+   } else if (tqp_vectors->tx_group.ring) {
+   snprintf(tqp_vectors->name, HNAE3_INT_NAME_LEN - 1,
+"%s-%s-%d", priv->netdev->name, "Tx",
+tx_int_idx++);
+   } else {
+   /* Skip this unused q_vector */
+   continue;
+   }
+
+   tqp_vectors->name[HNAE3_INT_NAME_LEN - 1] = '\0';
+
+   ret = devm_request_irq(>dev, tqp_vectors->vector_irq,
+  hns3_irq_handle, 0, tqp_vectors->name,
+  tqp_vectors);
+   if (ret) {
+   netdev_err(priv->netdev, "request irq(%d) fail\n",
+  tqp_vectors->vector_irq);
+   return ret;
+   }
+   

[PATCH V2 net-next 3/8] net: hns3: Add HNS3 IMP(Integrated Mgmt Proc) Cmd Interface Support

2017-06-13 Thread Salil Mehta
This patch adds the support of IMP (Integrated Management Processor)
command interface to the HNS3 driver.

Each PF/VF has support of CQP(Command Queue Pair) ring interface.
Each CQP consis of send queue CSQ and receive queue CRQ.
There are various commands a PF/VF may support, like for Flow Table
manipulation, Device management, Packet buffer allocation, Forwarding,
VLANs config, Tunneling/Overlays etc.

This patch contains code to initialize the command queue, manage the
command queue descriptors and Rx/Tx protocol with the command processor
in the form of various commands/results and acknowledgements.

Signed-off-by: Daode Huang 
Signed-off-by: lipeng 
Signed-off-by: Salil Mehta 
Signed-off-by: Yisen Zhuang 
---
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.c | 347 ++
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h | 743 +
 2 files changed, 1090 insertions(+)
 create mode 100644 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.c
 create mode 100644 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.c
new file mode 100644
index 000..ec20ec4
--- /dev/null
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.c
@@ -0,0 +1,347 @@
+/*
+ * 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 
+#include 
+#include 
+#include 
+#include 
+#include "hclge_cmd.h"
+#include "hnae3.h"
+#include "hclge_main.h"
+
+#define hclge_is_csq(ring) ((ring)->flag & HCLGE_TYPE_CSQ)
+#define hclge_ring_to_dma_dir(ring) (hclge_is_csq(ring) ? \
+   DMA_TO_DEVICE : DMA_FROM_DEVICE)
+#define cmq_ring_to_dev(ring)   (&(ring)->dev->pdev->dev)
+
+static int hclge_ring_space(struct hclge_cmq_ring *ring)
+{
+   int ntu = ring->next_to_use;
+   int ntc = ring->next_to_clean;
+   int used = (ntu - ntc + ring->desc_num) % ring->desc_num;
+
+   return ring->desc_num - used - 1;
+}
+
+static int hclge_alloc_cmd_desc(struct hclge_cmq_ring *ring)
+{
+   int size  = ring->desc_num * sizeof(struct hclge_desc);
+
+   ring->desc = kzalloc(size, GFP_KERNEL);
+   if (!ring->desc)
+   return -ENOMEM;
+
+   ring->desc_dma_addr = dma_map_single(cmq_ring_to_dev(ring), ring->desc,
+size, DMA_BIDIRECTIONAL);
+   if (dma_mapping_error(cmq_ring_to_dev(ring), ring->desc_dma_addr)) {
+   ring->desc_dma_addr = 0;
+   kfree(ring->desc);
+   ring->desc = NULL;
+   return -ENOMEM;
+   }
+
+   return 0;
+}
+
+static void hclge_free_cmd_desc(struct hclge_cmq_ring *ring)
+{
+   dma_unmap_single(cmq_ring_to_dev(ring), ring->desc_dma_addr,
+ring->desc_num * sizeof(ring->desc[0]),
+DMA_BIDIRECTIONAL);
+
+   ring->desc_dma_addr = 0;
+   kfree(ring->desc);
+   ring->desc = NULL;
+}
+
+static int hclge_init_cmd_queue(struct hclge_dev *hdev, int ring_type)
+{
+   struct hclge_hw *hw = >hw;
+   struct hclge_cmq_ring *ring =
+   (ring_type == HCLGE_TYPE_CSQ) ? >cmq.csq : >cmq.crq;
+   int ret;
+
+   ring->flag = ring_type;
+   ring->dev = hdev;
+
+   ret = hclge_alloc_cmd_desc(ring);
+   if (ret) {
+   dev_err(>pdev->dev, "descriptor %s alloc error %d\n",
+   (ring_type == HCLGE_TYPE_CSQ) ? "CSQ" : "CRQ", ret);
+   return ret;
+   }
+
+   ring->next_to_clean = 0;
+   ring->next_to_use = 0;
+
+   return 0;
+}
+
+void hclge_cmd_reuse_desc(struct hclge_desc *desc, bool is_read)
+{
+   desc->flag = cpu_to_le16(HCLGE_CMD_FLAG_NO_INTR | HCLGE_CMD_FLAG_IN);
+   if (is_read)
+   desc->flag |= cpu_to_le16(HCLGE_CMD_FLAG_WR);
+   else
+   desc->flag &= cpu_to_le16(~HCLGE_CMD_FLAG_WR);
+}
+
+void hclge_cmd_setup_basic_desc(struct hclge_desc *desc,
+   enum hclge_opcode_type opcode, bool is_read)
+{
+   memset((void *)desc, 0, sizeof(struct hclge_desc));
+   desc->opcode = cpu_to_le16(opcode);
+   desc->flag = cpu_to_le16(HCLGE_CMD_FLAG_NO_INTR | HCLGE_CMD_FLAG_IN);
+
+   if (is_read)
+   desc->flag |= cpu_to_le16(HCLGE_CMD_FLAG_WR);
+   else
+   desc->flag &= cpu_to_le16(~HCLGE_CMD_FLAG_WR);
+}
+
+static void hclge_cmd_config_regs(struct hclge_cmq_ring *ring)
+{
+   dma_addr_t dma = ring->desc_dma_addr;
+   struct hclge_dev *hdev = ring->dev;
+   struct hclge_hw *hw = >hw;
+
+   if (ring->flag == 

[PATCH V2 net-next 2/8] net: hns3: Add support of the HNAE3 framework

2017-06-13 Thread Salil Mehta
This patch adds the support of the HNAE3 (Hisilicon Network
Acceleration Engine 3) framework support to the HNS3 driver.

Framework facilitates clients like ENET(HNS3 Ethernet Driver), RoCE
and user-space Ethernet drivers (like ODP etc.) to register with HNAE3
devices and their associated operations.

Signed-off-by: Daode Huang 
Signed-off-by: lipeng 
Signed-off-by: Salil Mehta 
Signed-off-by: Yisen Zhuang 
---
 drivers/net/ethernet/hisilicon/hns3/hnae3.c | 305 +++
 drivers/net/ethernet/hisilicon/hns3/hnae3.h | 449 
 2 files changed, 754 insertions(+)
 create mode 100644 drivers/net/ethernet/hisilicon/hns3/hnae3.c
 create mode 100644 drivers/net/ethernet/hisilicon/hns3/hnae3.h

diff --git a/drivers/net/ethernet/hisilicon/hns3/hnae3.c 
b/drivers/net/ethernet/hisilicon/hns3/hnae3.c
new file mode 100644
index 000..f133e1d
--- /dev/null
+++ b/drivers/net/ethernet/hisilicon/hns3/hnae3.c
@@ -0,0 +1,305 @@
+/*
+ * 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 
+#include 
+
+#include "hnae3.h"
+
+static LIST_HEAD(hnae3_ae_algo_list);
+static LIST_HEAD(hnae3_client_list);
+static LIST_HEAD(hnae3_ae_dev_list);
+
+static DEFINE_SPINLOCK(hnae3_list_ae_algo_lock);
+static DEFINE_SPINLOCK(hnae3_list_client_lock);
+static DEFINE_SPINLOCK(hnae3_list_ae_dev_lock);
+
+static void hnae3_list_add(spinlock_t *lock, struct list_head *node,
+  struct list_head *head)
+{
+   unsigned long flags;
+
+   spin_lock_irqsave(lock, flags);
+   list_add_tail_rcu(node, head);
+   spin_unlock_irqrestore(lock, flags);
+}
+
+static void hnae3_list_del(spinlock_t *lock, struct list_head *node)
+{
+   unsigned long flags;
+
+   spin_lock_irqsave(lock, flags);
+   list_del_rcu(node);
+   spin_unlock_irqrestore(lock, flags);
+}
+
+static bool hnae3_client_match(enum hnae3_client_type client_type,
+  enum hnae3_dev_type dev_type)
+{
+   if (dev_type == HNAE3_DEV_KNIC) {
+   switch (client_type) {
+   case HNAE3_CLIENT_KNIC:
+   case HNAE3_CLIENT_ROCE:
+   return true;
+   default:
+   return false;
+   }
+   } else if (dev_type == HNAE3_DEV_UNIC) {
+   switch (client_type) {
+   case HNAE3_CLIENT_UNIC:
+   return true;
+   default:
+   return false;
+   }
+   } else {
+   return false;
+   }
+}
+
+int hnae3_register_client(struct hnae3_client *client)
+{
+   struct hnae3_client *client_tmp;
+   struct hnae3_ae_dev *ae_dev;
+   int ret;
+
+   /* One system should only have one client for every type */
+   list_for_each_entry(client_tmp, _client_list, node) {
+   if (client_tmp->type == client->type)
+   return 0;
+   }
+
+   hnae3_list_add(_list_client_lock, >node,
+  _client_list);
+
+   /* Check if there are matched ae_dev */
+   list_for_each_entry(ae_dev, _ae_dev_list, node) {
+   if (hnae3_client_match(client->type, ae_dev->dev_type) &&
+   hnae_get_bit(ae_dev->flag, HNAE3_DEV_INITED_B)) {
+   if (ae_dev->ops && ae_dev->ops->register_client) {
+   ret = ae_dev->ops->register_client(client,
+  ae_dev);
+   if (ret) {
+   dev_err(_dev->pdev->dev,
+   "init ae_dev error.\n");
+   return ret;
+   }
+   }
+   }
+   }
+
+   return 0;
+}
+EXPORT_SYMBOL(hnae3_register_client);
+
+void hnae3_unregister_client(struct hnae3_client *client)
+{
+   struct hnae3_ae_dev *ae_dev;
+
+   /* Check if there are matched ae_dev */
+   list_for_each_entry(ae_dev, _ae_dev_list, node) {
+   if (hnae3_client_match(client->type, ae_dev->dev_type) &&
+   hnae_get_bit(ae_dev->flag, HNAE3_DEV_INITED_B))
+   if (ae_dev->ops && ae_dev->ops->unregister_client)
+   ae_dev->ops->unregister_client(client, ae_dev);
+   }
+   hnae3_list_del(_list_client_lock, >node);
+}
+EXPORT_SYMBOL(hnae3_unregister_client);
+
+/* hnae_ae_register - register a AE engine to hnae framework
+ * @hdev: the hnae ae engine device
+ * @owner:  the module who 

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

2017-06-13 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 
---
 .../ethernet/hisilicon/hns3/hns3pf/hns3_ethtool.c  | 894 +
 1 file changed, 894 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 000..83fde08
--- /dev/null
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_ethtool.c
@@ -0,0 +1,894 @@
+/*
+ * 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),
+};
+
+#define HNS3_RXQ_STATS_COUNT ARRAY_SIZE(hns3_rxq_stats)
+
+#define HNS3_TQP_STATS_COUNT (HNS3_TXQ_STATS_COUNT + HNS3_RXQ_STATS_COUNT)
+
+struct hns3_link_mode_mapping {
+   u32 hns3_link_mode;
+   

Re: [PATCH] Add printk for bonding module packets_per_slave parameter

2017-06-13 Thread kbuild test robot
Hi Michael,

[auto build test WARNING on net-next/master]
[also build test WARNING on v4.12-rc5 next-20170613]
[if your patch is applied to the wrong git tree, please drop us a note to help 
improve the system]

url:
https://github.com/0day-ci/linux/commits/Michael-Dilmore/Add-printk-for-bonding-module-packets_per_slave-parameter/20170614-045412
config: tile-tilegx_defconfig (attached as .config)
compiler: tilegx-linux-gcc (GCC) 4.6.2
reproduce:
wget 
https://raw.githubusercontent.com/01org/lkp-tests/master/sbin/make.cross -O 
~/bin/make.cross
chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=tile 

All warnings (new ones prefixed by >>):

   drivers/net/bonding/bond_options.c: In function 'bond_option_pps_set':
>> drivers/net/bonding/bond_options.c:1260:7: warning: format '%d' expects 
>> argument of type 'int', but argument 3 has type 'u64' [-Wformat]

vim +1260 drivers/net/bonding/bond_options.c

  1244  
  1245  return 0;
  1246  }
  1247  
  1248  static int bond_option_lp_interval_set(struct bonding *bond,
  1249 const struct bond_opt_value 
*newval)
  1250  {
  1251  bond->params.lp_interval = newval->value;
  1252  
  1253  return 0;
  1254  }
  1255  
  1256  static int bond_option_pps_set(struct bonding *bond,
  1257 const struct bond_opt_value *newval)
  1258  {
  1259  netdev_info(bond->dev, "Setting packets per slave to %d\n",
> 1260  newval->value);
  1261  bond->params.packets_per_slave = newval->value;
  1262  if (newval->value > 0) {
  1263  bond->params.reciprocal_packets_per_slave =
  1264  reciprocal_value(newval->value);
  1265  } else {
  1266  /* reciprocal_packets_per_slave is unused if
  1267   * packets_per_slave is 0 or 1, just initialize it
  1268   */

---
0-DAY kernel test infrastructureOpen Source Technology Center
https://lists.01.org/pipermail/kbuild-all   Intel Corporation


.config.gz
Description: application/gzip


[PATCH V2 net-next 6/8] net: hns3: Add MDIO support to HNS3 Ethernet driver for hip08 SoC

2017-06-13 Thread Salil Mehta
This patch adds the support of MDIO bus interface for HNS3 driver.
Code provides various interfaces to start and stop the PHY layer
and to read and write the MDIO bus or PHY.

Signed-off-by: Daode Huang 
Signed-off-by: lipeng 
Signed-off-by: Salil Mehta 
Signed-off-by: Yisen Zhuang 
---
Patch V2: Addresses below selective comments(*some remaining*)
 1. Florian Fainelli: https://lkml.org/lkml/2017/6/10/130
 2. Andrew Lunn: https://lkml.org/lkml/2017/6/10/168
Patch V1: Initial Submit
---
 .../ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c| 295 +
 1 file changed, 295 insertions(+)
 create mode 100644 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c
new file mode 100644
index 000..4d3a32b
--- /dev/null
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c
@@ -0,0 +1,295 @@
+/*
+ * 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 
+
+#include "hclge_cmd.h"
+#include "hclge_main.h"
+
+enum hclge_mdio_c22_op_seq {
+   HCLGE_MDIO_C22_WRITE = 1,
+   HCLGE_MDIO_C22_READ = 2
+};
+
+enum hclge_mdio_c45_op_seq {
+   HCLGE_MDIO_C45_WRITE_ADDR = 0,
+   HCLGE_MDIO_C45_WRITE_DATA,
+   HCLGE_MDIO_C45_READ_INCREMENT,
+   HCLGE_MDIO_C45_READ
+};
+
+#define HCLGE_MDIO_CTRL_START_BIT   BIT(0)
+#define HCLGE_MDIO_CTRL_ST_MSK  GENMASK(2, 1)
+#define HCLGE_MDIO_CTRL_ST_LSH  1
+#define HCLGE_MDIO_IS_C22(c22)  (((c22) << HCLGE_MDIO_CTRL_ST_LSH) & \
+   HCLGE_MDIO_CTRL_ST_MSK)
+
+#define HCLGE_MDIO_CTRL_OP_MSK  GENMASK(4, 3)
+#define HCLGE_MDIO_CTRL_OP_LSH  3
+#define HCLGE_MDIO_CTRL_OP(access) \
+   (((access) << HCLGE_MDIO_CTRL_OP_LSH) & HCLGE_MDIO_CTRL_OP_MSK)
+#define HCLGE_MDIO_CTRL_PRTAD_MSK   GENMASK(4, 0)
+#define HCLGE_MDIO_CTRL_DEVAD_MSK   GENMASK(4, 0)
+
+#define HCLGE_MDIO_STA_VAL(val)((val) & BIT(0))
+
+struct hclge_mdio_cfg_cmd {
+   u8 ctrl_bit;
+   u8 prtad;   /* The external port address */
+   u8 devad;   /* The external device address */
+   u8 rsvd;
+   __le16 addr_c45;/* Only valid for c45 */
+   __le16 data_wr;
+   __le16 data_rd;
+   __le16 sta;
+};
+
+static int hclge_mdio_write(struct mii_bus *bus, int phy_id, int regnum,
+   u16 data)
+{
+   struct hclge_dev *hdev = (struct hclge_dev *)bus->priv;
+   struct hclge_mdio_cfg_cmd *mdio_cmd;
+   enum hclge_cmd_status status;
+   struct hclge_desc desc;
+   u8 is_c45, devad;
+   u16 reg;
+
+   if (!bus)
+   return -EINVAL;
+
+   is_c45 = !!(regnum & MII_ADDR_C45);
+   devad = ((regnum >> 16) & 0x1f);
+   reg = (u16)(regnum & 0x);
+
+   hclge_cmd_setup_basic_desc(, HCLGE_OPC_MDIO_CONFIG, false);
+
+   mdio_cmd = (struct hclge_mdio_cfg_cmd *)desc.data;
+
+   mdio_cmd->ctrl_bit |= HCLGE_MDIO_CTRL_START_BIT;
+   mdio_cmd->prtad = phy_id & HCLGE_MDIO_CTRL_PRTAD_MSK;
+   mdio_cmd->data_wr = cpu_to_le16(data);
+   mdio_cmd->devad = devad & HCLGE_MDIO_CTRL_DEVAD_MSK;
+
+   if (is_c45) {
+   /* Set phy addr */
+   mdio_cmd->addr_c45 = cpu_to_le16(reg);
+   } else {
+   /* C22 write reg and data */
+   mdio_cmd->ctrl_bit = HCLGE_MDIO_IS_C22(!is_c45);
+   mdio_cmd->ctrl_bit |= HCLGE_MDIO_CTRL_OP(HCLGE_MDIO_C22_WRITE);
+   }
+
+   status = hclge_cmd_send(>hw, , 1);
+   if (status) {
+   dev_err(>pdev->dev,
+   "mdio write fail when sending cmd, status is %d.\n",
+   status);
+   return -EIO;
+   }
+
+   return 0;
+}
+
+static int hclge_mdio_read(struct mii_bus *bus, int phy_id, int regnum)
+{
+   struct hclge_dev *hdev = (struct hclge_dev *)bus->priv;
+   struct hclge_mdio_cfg_cmd *mdio_cmd;
+   enum hclge_cmd_status status;
+   struct hclge_desc desc;
+   u8 is_c45, devad;
+   u16 reg;
+
+   if (!bus)
+   return -EINVAL;
+
+   is_c45 = !!(regnum & MII_ADDR_C45);
+   devad = ((regnum >> 16) & GENMASK(4, 0));
+   reg = (u16)(regnum & GENMASK(15, 0));
+
+   hclge_cmd_setup_basic_desc(, HCLGE_OPC_MDIO_CONFIG, true);
+
+   mdio_cmd = (struct hclge_mdio_cfg_cmd *)desc.data;
+
+   dev_dbg(>dev, "phy id=%d, is_c45=%d, devad=%d, reg=%#x!\n",
+   phy_id, is_c45, devad, reg);
+
+   mdio_cmd->ctrl_bit |= HCLGE_MDIO_CTRL_START_BIT;
+   mdio_cmd->prtad = phy_id & HCLGE_MDIO_CTRL_PRTAD_MSK;
+   mdio_cmd->devad = devad & 

[PATCH V2 net-next 5/8] net: hns3: Add support of TX Scheduler & Shaper to HNS3 driver

2017-06-13 Thread Salil Mehta
THis patch adds the support of the Scheduling and Shaping
functionalities during the transmit leg. This also adds the
support of Pause at MAC level. (Pause at per-priority level
shall be added later along with the DCB feature).

Hardware as such consists of two types of cofiguration of 6 level
schedulers. Algorithms varies according to the level and type
of scheduler being used. Current patch is used to initialize
the mapping, algorithms(like SP, DWRR etc) and shaper(CIR, PIR etc)
being used.

Signed-off-by: Daode Huang 
Signed-off-by: lipeng 
Signed-off-by: Salil Mehta 
Signed-off-by: Yisen Zhuang 
---
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.c  | 1018 
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.h  |  108 +++
 2 files changed, 1126 insertions(+)
 create mode 100644 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.c
 create mode 100644 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.h

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.c
new file mode 100644
index 000..2b66a0e
--- /dev/null
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.c
@@ -0,0 +1,1018 @@
+/*
+ * 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 "hclge_cmd.h"
+#include "hclge_main.h"
+#include "hclge_tm.h"
+
+enum hclge_shaper_level {
+   HCLGE_SHAPER_LVL_PRI= 0,
+   HCLGE_SHAPER_LVL_PG = 1,
+   HCLGE_SHAPER_LVL_PORT   = 2,
+   HCLGE_SHAPER_LVL_QSET   = 3,
+   HCLGE_SHAPER_LVL_CNT= 4,
+   HCLGE_SHAPER_LVL_VF = 0,
+   HCLGE_SHAPER_LVL_PF = 1,
+};
+
+#define HCLGE_SHAPER_BS_U_DEF  1
+#define HCLGE_SHAPER_BS_S_DEF  4
+
+#define HCLGE_ETHER_MAX_RATE   10
+
+/* hclge_shaper_para_calc: calculate ir parameter for the shaper
+ * @ir: Rate to be config, its unit is Mbps
+ * @shaper_level: the shaper level. eg: port, pg, priority, queueset
+ * @ir_b: IR_B parameter of IR shaper
+ * @ir_u: IR_U parameter of IR shaper
+ * @ir_s: IR_S parameter of IR shaper
+ *
+ * the formula:
+ *
+ * IR_b * (2 ^ IR_u) * 8
+ * IR(Mbps) = -  *  CLOCK(1000Mbps)
+ * Tick * (2 ^ IR_s)
+ *
+ * @return: 0: calculate sucessful, negative: fail
+ */
+static int hclge_shaper_para_calc(u32 ir, u8 shaper_level,
+ u8 *ir_b, u8 *ir_u, u8 *ir_s)
+{
+   const u16 tick_array[HCLGE_SHAPER_LVL_CNT] = {
+   6 * 256,/* Prioriy level */
+   6 * 32, /* Prioriy group level */
+   6 * 8,  /* Port level */
+   6 * 256 /* Qset level */
+   };
+   u8 ir_u_calc = 0, ir_s_calc = 0;
+   u32 ir_calc;
+   u32 tick;
+
+   /* Calc tick */
+   if (shaper_level >= HCLGE_SHAPER_LVL_CNT)
+   return -ENOMEM;
+
+   tick = tick_array[shaper_level];
+
+   /**
+* Calc the speed if ir_b = 126, ir_u = 0 and ir_s = 0
+* the formula is changed to:
+*  126 * 1 * 8
+* ir_calc =  * 1000
+*  tick * 1
+*/
+   ir_calc = (1008000 + (tick >> 1) - 1) / tick;
+
+   if (ir_calc == ir) {
+   *ir_b = 126;
+   *ir_u = 0;
+   *ir_s = 0;
+
+   return 0;
+   } else if (ir_calc > ir) {
+   /* Increasing the denominator to select ir_s value */
+   while (ir_calc > ir) {
+   ir_s_calc++;
+   ir_calc = 1008000 / (tick * (1 << ir_s_calc));
+   }
+
+   if (ir_calc == ir)
+   *ir_b = 126;
+   else
+   *ir_b = (ir * tick * (1 << ir_s_calc) + 4000) / 8000;
+   } else {
+   /* Increasing the numerator to select ir_u value */
+   u32 numerator;
+
+   while (ir_calc < ir) {
+   ir_u_calc++;
+   numerator = 1008000 * (1 << ir_u_calc);
+   ir_calc = (numerator + (tick >> 1)) / tick;
+   }
+
+   if (ir_calc == ir) {
+   *ir_b = 126;
+   } else {
+   u32 denominator = (8000 * (1 << --ir_u_calc));
+   *ir_b = (ir * tick + (denominator >> 1)) / denominator;
+   }
+   }
+
+   *ir_u = ir_u_calc;
+   *ir_s = ir_s_calc;
+
+   return 0;
+}
+
+static int hclge_mac_pause_en_cfg(struct hclge_dev *hdev, bool tx, bool rx)
+{
+   struct hclge_desc desc;
+
+   hclge_cmd_setup_basic_desc(, 

[PATCH V2 net-next 4/8] net: hns3: Add HNS3 Acceleration Engine & Compatibility Layer Support

2017-06-13 Thread Salil Mehta
This patch adds the support of Hisilicon Network Subsystem Accceleration
Engine and common operations to access it. This layer provides access to the
hardware configuration, hardware statistics. This layer is also
responsible for triggering the initialization of the PHY layer through
the below MDIO layer.

Signed-off-by: Daode Huang 
Signed-off-by: lipeng 
Signed-off-by: Salil Mehta 
Signed-off-by: Yisen Zhuang 
---
Patch V2: Addressed below comments:
 1. Andrew Lunn: https://lkml.org/lkml/2017/6/10/168
 2. Andrew Lunn: https://lkml.org/lkml/2017/6/10/118
 3. Yuval Mintz: https://lkml.org/lkml/2017/6/10/82
Patch V1: Initial Submit
---
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.c| 4255 
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.h|  495 +++
 2 files changed, 4750 insertions(+)
 create mode 100644 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
 create mode 100644 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
new file mode 100644
index 000..bf7761e
--- /dev/null
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -0,0 +1,4255 @@
+/*
+ * 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 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "hclge_cmd.h"
+#include "hclge_main.h"
+#include "hclge_tm.h"
+#include "hnae3.h"
+
+#define HCLGE_NAME "hclge"
+#define HCLGE_STATS_READ(p, offset) (*((u64 *)((u8 *)(p) + (offset
+#define HCLGE_MAC_STATS_FIELD_OFF(f) (offsetof(struct hclge_mac_stats, f))
+#define HCLGE_64BIT_STATS_FIELD_OFF(f) (offsetof(struct hclge_64_bit_stats, f))
+#define HCLGE_32BIT_STATS_FIELD_OFF(f) (offsetof(struct hclge_32_bit_stats, f))
+
+static int hclge_rss_init_hw(struct hclge_dev *hdev);
+static int hclge_set_mta_filter_mode(struct hclge_dev *hdev,
+enum hclge_mta_dmac_sel_type mta_mac_sel,
+bool enable);
+static int hclge_init_vlan_config(struct hclge_dev *hdev);
+
+struct hnae3_ae_algo ae_algo;
+
+static const struct pci_device_id ae_algo_pci_tbl[] = {
+   {PCI_VDEVICE(HUAWEI, HNAE3_DEV_ID_GE), 0},
+   {PCI_VDEVICE(HUAWEI, HNAE3_DEV_ID_25GE), 0},
+   {PCI_VDEVICE(HUAWEI, HNAE3_DEV_ID_25GE_RDMA), 0},
+   {PCI_VDEVICE(HUAWEI, HNAE3_DEV_ID_25GE_RDMA_MACSEC), 0},
+   {PCI_VDEVICE(HUAWEI, HNAE3_DEV_ID_50GE_RDMA), 0},
+   {PCI_VDEVICE(HUAWEI, HNAE3_DEV_ID_50GE_RDMA_MACSEC), 0},
+   {PCI_VDEVICE(HUAWEI, HNAE3_DEV_ID_100G_RDMA_MACSEC), 0},
+   /* Required last entry */
+   {0, }
+};
+
+static const struct pci_device_id roce_pci_tbl[] = {
+   {PCI_VDEVICE(HUAWEI, HNAE3_DEV_ID_25GE_RDMA), 0},
+   {PCI_VDEVICE(HUAWEI, HNAE3_DEV_ID_25GE_RDMA_MACSEC), 0},
+   {PCI_VDEVICE(HUAWEI, HNAE3_DEV_ID_50GE_RDMA), 0},
+   {PCI_VDEVICE(HUAWEI, HNAE3_DEV_ID_50GE_RDMA_MACSEC), 0},
+   {PCI_VDEVICE(HUAWEI, HNAE3_DEV_ID_100G_RDMA_MACSEC), 0},
+   /* Required last entry */
+   {0, }
+};
+
+static const char hns3_nic_test_strs[][ETH_GSTRING_LEN] = {
+   "MacLoopback test",
+   "Serdes Loopback test",
+   "PhyLoopback test"
+};
+
+static const struct hclge_comm_stats_str g_all_64bit_stats_string[] = {
+   {"igu_rx_oversize_pkt",
+   HCLGE_64BIT_STATS_FIELD_OFF(igu_rx_oversize_pkt)},
+   {"igu_rx_undersize_pkt",
+   HCLGE_64BIT_STATS_FIELD_OFF(igu_rx_undersize_pkt)},
+   {"igu_rx_out_all_pkt",
+   HCLGE_64BIT_STATS_FIELD_OFF(igu_rx_out_all_pkt)},
+   {"igu_rx_uni_pkt",
+   HCLGE_64BIT_STATS_FIELD_OFF(igu_rx_uni_pkt)},
+   {"igu_rx_multi_pkt",
+   HCLGE_64BIT_STATS_FIELD_OFF(igu_rx_multi_pkt)},
+   {"igu_rx_broad_pkt",
+   HCLGE_64BIT_STATS_FIELD_OFF(igu_rx_broad_pkt)},
+   {"egu_tx_out_all_pkt",
+   HCLGE_64BIT_STATS_FIELD_OFF(egu_tx_out_all_pkt)},
+   {"egu_tx_uni_pkt",
+   HCLGE_64BIT_STATS_FIELD_OFF(egu_tx_uni_pkt)},
+   {"egu_tx_multi_pkt",
+   HCLGE_64BIT_STATS_FIELD_OFF(egu_tx_multi_pkt)},
+   {"egu_tx_broad_pkt",
+   HCLGE_64BIT_STATS_FIELD_OFF(egu_tx_broad_pkt)},
+   {"ssu_ppp_mac_key_num",
+   HCLGE_64BIT_STATS_FIELD_OFF(ssu_ppp_mac_key_num)},
+   {"ssu_ppp_host_key_num",
+   HCLGE_64BIT_STATS_FIELD_OFF(ssu_ppp_host_key_num)},
+   {"ppp_ssu_mac_rlt_num",
+   

[PATCH V2 net-next 8/8] net: hns3: Add HNS3 driver to kernel build framework & MAINTAINERS

2017-06-13 Thread Salil Mehta
This patch updates the MAINTAINERS file with HNS3 Ethernet driver
maintainers names and other details. This also introduces the new
Makefiles required to build the HNS3 Ethernet driver and updates
the existing Kconfig file in the hisilicon folder.

Signed-off-by: Salil Mehta 
---
Patch V2: Addresses below comments:
 1. Yuval Mintz: https://lkml.org/lkml/2017/6/10/82
 2. Andrew Lunn: https://lkml.org/lkml/2017/6/10/118
Patch V1: Initial Submit
---
 MAINTAINERS|  8 
 drivers/net/ethernet/hisilicon/Kconfig | 24 ++
 drivers/net/ethernet/hisilicon/Makefile|  1 +
 drivers/net/ethernet/hisilicon/hns3/Makefile   |  7 +++
 .../net/ethernet/hisilicon/hns3/hns3pf/Makefile| 11 ++
 5 files changed, 51 insertions(+)
 create mode 100644 drivers/net/ethernet/hisilicon/hns3/Makefile
 create mode 100644 drivers/net/ethernet/hisilicon/hns3/hns3pf/Makefile

diff --git a/MAINTAINERS b/MAINTAINERS
index 8b8249b..cda0e80 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -6070,6 +6070,14 @@ S:   Maintained
 F: drivers/net/ethernet/hisilicon/
 F: Documentation/devicetree/bindings/net/hisilicon*.txt
 
+HISILICON NETWORK SUBSYSTEM 3 DRIVER (HNS3)
+M: Yisen Zhuang 
+M: Salil Mehta 
+L: netdev@vger.kernel.org
+W: http://www.hisilicon.com
+S: Maintained
+F: drivers/net/ethernet/hisilicon/hns3/
+
 HISILICON ROCE DRIVER
 M: Lijun Ou 
 M: Wei Hu(Xavier) 
diff --git a/drivers/net/ethernet/hisilicon/Kconfig 
b/drivers/net/ethernet/hisilicon/Kconfig
index d11287e..2c48fce 100644
--- a/drivers/net/ethernet/hisilicon/Kconfig
+++ b/drivers/net/ethernet/hisilicon/Kconfig
@@ -76,4 +76,28 @@ config HNS_ENET
  This selects the general ethernet driver for HNS.  This module make
  use of any HNS AE driver, such as HNS_DSAF
 
+config HNS3
+   tristate "Hisilicon Network Subsystem Support HNS3 (Framework)"
+   ---help---
+ This selects the framework support for Hisilicon Network Subsystem 3.
+ This layer facilitates clients like ENET, RoCE and user-space ethernet
+ drivers(like ODP)to register with HNAE devices and their associated
+ operations.
+
+config HNS3_HCLGE
+   tristate "Hisilicon HNS3 HCLGE Acceleration Engine & Compatibility 
Layer Support"
+   select HNS3
+   ---help---
+ This selects the HNS3_HCLGE network acceleration engine & its hardware
+ compatibility layer. The engine would be used in Hisilicon hip08 
family of
+ SoCs and further upcoming SoCs.
+
+config HNS3_ENET
+   tristate "Hisilicon HNS3 Ethernet Device Support"
+   select HNS3
+   ---help---
+ This selects the Ethernet Driver for Hisilicon Network Subsystem 3 
for hip08
+ family of SoCs. This module depends upon HNAE3 driver to access the 
HNAE3
+ devices and their associated operations.
+
 endif # NET_VENDOR_HISILICON
diff --git a/drivers/net/ethernet/hisilicon/Makefile 
b/drivers/net/ethernet/hisilicon/Makefile
index 8661695..3828c43 100644
--- a/drivers/net/ethernet/hisilicon/Makefile
+++ b/drivers/net/ethernet/hisilicon/Makefile
@@ -6,4 +6,5 @@ obj-$(CONFIG_HIX5HD2_GMAC) += hix5hd2_gmac.o
 obj-$(CONFIG_HIP04_ETH) += hip04_eth.o
 obj-$(CONFIG_HNS_MDIO) += hns_mdio.o
 obj-$(CONFIG_HNS) += hns/
+obj-$(CONFIG_HNS3) += hns3/
 obj-$(CONFIG_HISI_FEMAC) += hisi_femac.o
diff --git a/drivers/net/ethernet/hisilicon/hns3/Makefile 
b/drivers/net/ethernet/hisilicon/hns3/Makefile
new file mode 100644
index 000..5e53735
--- /dev/null
+++ b/drivers/net/ethernet/hisilicon/hns3/Makefile
@@ -0,0 +1,7 @@
+#
+# Makefile for the HISILICON network device drivers.
+#
+
+obj-$(CONFIG_HNS3) += hns3pf/
+
+obj-$(CONFIG_HNS3) +=hnae3.o
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/Makefile 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/Makefile
new file mode 100644
index 000..c0a92b5
--- /dev/null
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/Makefile
@@ -0,0 +1,11 @@
+#
+# Makefile for the HISILICON network device drivers.
+#
+
+ccflags-y := -Idrivers/net/ethernet/hisilicon/hns3
+
+obj-$(CONFIG_HNS3_HCLGE) += hclge.o
+hclge-objs =hclge_main.o hclge_cmd.o hclge_mdio.o hclge_tm.o
+
+obj-$(CONFIG_HNS3_ENET) += hns3.o
+hns3-objs = hns3_enet.o hns3_ethtool.o
-- 
2.7.4




RE: [PATCH net-next 6/9] net: hns3: Add MDIO support to HNS3 Ethernet driver for hip08 SoC

2017-06-13 Thread Salil Mehta
Hi Andrew,

> -Original Message-
> From: Andrew Lunn [mailto:and...@lunn.ch]
> Sent: Tuesday, June 13, 2017 11:41 PM
> To: Salil Mehta
> Cc: Florian Fainelli; da...@davemloft.net; Zhuangyuzeng (Yisen);
> huangdaode; lipeng (Y); mehta.salil@gmail.com;
> netdev@vger.kernel.org; linux-ker...@vger.kernel.org; Linuxarm
> Subject: Re: [PATCH net-next 6/9] net: hns3: Add MDIO support to HNS3
> Ethernet driver for hip08 SoC
> 
> > > Hum why do you do this? mdiobus_register() will scan through your
> bus
> > > provided that you set an appropriate phy_mask value (here you tell
> it
> > > not to) and you already provide the PHY address to scan for
> > >
> > I know this looks weird but the reason why it appears as it is in
> code is:
> >
> > mdiobus_register() calls mdiobus_scan(). If you see below code leg
> function
> > get_phy_device() assumes to be having supporting Clause 22 so its
> input
> > parameter 'is_c45' is always 'false'.
> >
> > struct phy_device *mdiobus_scan(struct mii_bus *bus, int addr)
> > {
> > struct phy_device *phydev;
> > int err;
> >
> > phydev = get_phy_device(bus, addr, false);
> > if (IS_ERR(phydev))^
> > return phydev;
> > [...]
> > }
> >
> > Therefore, to support C45 device we did below:
> >
> > * disabled the autoscan/mdiobus_scan() Of the PHY devices using the
> >   phy_mask(= ~0)
> > * Now, did almost the same thing what mdiobus_scan does i.e.
> > * get_phy_device but with is_c45 (=true/false)
> > * register the above phy device with phy_device_register()
> >
> > There could be some gap in my understanding, please help to correct
> this?
> 
> So this is the question i was asking Florian
> 
> Rather than hack around limitations of the core, you should fix the
> core. I think we should make the core first try probing using c45. If
> that comes back with an error, or does not find a device, try the
> probe using c22.
I can take this activity but please allow me to do this as a separate activity
and not part of this driver Up-streaming activity.

Since I would be touching the core, lots of drivers will get impacted and will
have to wait till everyone gives clean signal. This will impact our internal
deadlines. But as I said I am eager to cooperate & contribute :)

Thanks
Salil
> 
>   Andrew


[PATCH 0/2] bpf: permit bpf program narrower loads for ctx fields

2017-06-13 Thread Yonghong Song
Today, if users try to access a ctx field through a narrower load, e.g.,
__be16 prot = __sk_buff->protocol, verifier will fail.
This set contains the verifier change to permit such loads for
certain ctx fields as well as the new test cases in selftests/bpf.

Yonghong Song (2):
  bpf: permits narrower load from bpf program context fields
  selftests/bpf: Add test cases to test narrower ctx field loads

 include/linux/bpf.h  |   2 +-
 include/linux/bpf_verifier.h |   1 +
 kernel/bpf/verifier.c|  71 +---
 kernel/trace/bpf_trace.c |  21 ++-
 net/core/filter.c|  56 +--
 tools/testing/selftests/bpf/Makefile |   3 +-
 tools/testing/selftests/bpf/test_pkt_md_access.c |  35 
 tools/testing/selftests/bpf/test_progs.c |  21 +++
 tools/testing/selftests/bpf/test_verifier.c  | 200 ++-
 9 files changed, 324 insertions(+), 86 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/test_pkt_md_access.c

-- 
2.9.3



[PATCH 1/2] bpf: permits narrower load from bpf program context fields

2017-06-13 Thread Yonghong Song
Currently, verifier will reject a program if it contains an
narrower load from the bpf context structure. For example,
__u8 h = __sk_buff->hash, or
__u16 p = __sk_buff->protocol
__u32 sample_period = bpf_perf_event_data->sample_period
which are narrower loads of 4-byte or 8-byte field.

This patch solves the issue by:
  . Introduce a new parameter ctx_field_size to carry the
field size of narrower load from prog type
specific *__is_valid_access validator back to verifier.
  . The non-zero ctx_field_size for a memory access indicates
(1). underlying prog type specific convert_ctx_accesses
 supporting non-whole-field access
(2). the current insn is a narrower or whole field access.
  . In verifier, for such loads where load memory size is
less than ctx_field_size, verifier transforms it
to a full field load followed by proper masking.
  . Currently, __sk_buff and bpf_perf_event_data->sample_period
are supporting narrowing loads.
  . Narrower stores are still not allowed as typical ctx stores
are just normal stores.

Because of this change, some tests in verifier will fail and
these tests are removed. As a bonus, rename some out of bound
__sk_buff->cb access to proper field name and remove two
redundant "skb cb oob" tests.

Acked-by: Daniel Borkmann 
Signed-off-by: Yonghong Song 
---
 include/linux/bpf.h |  2 +-
 include/linux/bpf_verifier.h|  1 +
 kernel/bpf/verifier.c   | 71 --
 kernel/trace/bpf_trace.c| 21 +--
 net/core/filter.c   | 56 +-
 tools/testing/selftests/bpf/test_verifier.c | 92 -
 6 files changed, 124 insertions(+), 119 deletions(-)

diff --git a/include/linux/bpf.h b/include/linux/bpf.h
index c32bace..1bcbf0a 100644
--- a/include/linux/bpf.h
+++ b/include/linux/bpf.h
@@ -157,7 +157,7 @@ struct bpf_verifier_ops {
 * with 'type' (read or write) is allowed
 */
bool (*is_valid_access)(int off, int size, enum bpf_access_type type,
-   enum bpf_reg_type *reg_type);
+   enum bpf_reg_type *reg_type, int 
*ctx_field_size);
int (*gen_prologue)(struct bpf_insn *insn, bool direct_write,
const struct bpf_prog *prog);
u32 (*convert_ctx_access)(enum bpf_access_type type,
diff --git a/include/linux/bpf_verifier.h b/include/linux/bpf_verifier.h
index d5093b5..189741c 100644
--- a/include/linux/bpf_verifier.h
+++ b/include/linux/bpf_verifier.h
@@ -73,6 +73,7 @@ struct bpf_insn_aux_data {
enum bpf_reg_type ptr_type; /* pointer type for load/store 
insns */
struct bpf_map *map_ptr;/* pointer for call insn into 
lookup_elem */
};
+   int ctx_field_size; /* the ctx field size for load/store insns, maybe 0 
*/
 };
 
 #define MAX_USED_MAPS 64 /* max number of maps accessed by one eBPF program */
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index 519a614..44b97d9 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -758,15 +758,26 @@ static int check_packet_access(struct bpf_verifier_env 
*env, u32 regno, int off,
 }
 
 /* check access to 'struct bpf_context' fields */
-static int check_ctx_access(struct bpf_verifier_env *env, int off, int size,
+static int check_ctx_access(struct bpf_verifier_env *env, int insn_idx, int 
off, int size,
enum bpf_access_type t, enum bpf_reg_type *reg_type)
 {
+   int ctx_field_size = 0;
+
/* for analyzer ctx accesses are already validated and converted */
if (env->analyzer_ops)
return 0;
 
if (env->prog->aux->ops->is_valid_access &&
-   env->prog->aux->ops->is_valid_access(off, size, t, reg_type)) {
+   env->prog->aux->ops->is_valid_access(off, size, t, reg_type, 
_field_size)) {
+   /* a non zero ctx_field_size indicates:
+* . For this field, the prog type specific ctx conversion 
algorithm
+*   only supports whole field access.
+* . This ctx access is a candiate for later verifier 
transformation
+*   to load the whole field and then apply a mask to get 
correct result.
+*/
+   if (ctx_field_size)
+   env->insn_aux_data[insn_idx].ctx_field_size = 
ctx_field_size;
+
/* remember the offset of last byte accessed in ctx */
if (env->prog->aux->max_ctx_offset < off + size)
env->prog->aux->max_ctx_offset = off + size;
@@ -868,7 +879,7 @@ static int check_ptr_alignment(struct bpf_verifier_env *env,
  * if t==write && value_regno==-1, some unknown value is stored into memory
  * if t==read && value_regno==-1, don't care what we read from memory
  */
-static int 

[PATCH 2/2] selftests/bpf: Add test cases to test narrower ctx field loads

2017-06-13 Thread Yonghong Song
Add test cases in test_verifier and test_progs.
Negative tests are added in test_verifier as well.
The test in test_progs will compare the value of narrower ctx field
load result vs. the masked value of normal full-field load result,
and will fail if they are not the same.

Acked-by: Daniel Borkmann 
Signed-off-by: Yonghong Song 
---
 tools/testing/selftests/bpf/Makefile |   3 +-
 tools/testing/selftests/bpf/test_pkt_md_access.c |  35 +
 tools/testing/selftests/bpf/test_progs.c |  21 +++
 tools/testing/selftests/bpf/test_verifier.c  | 176 +++
 4 files changed, 234 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/bpf/test_pkt_md_access.c

diff --git a/tools/testing/selftests/bpf/Makefile 
b/tools/testing/selftests/bpf/Makefile
index 9f0e07b..2ca51a8 100644
--- a/tools/testing/selftests/bpf/Makefile
+++ b/tools/testing/selftests/bpf/Makefile
@@ -14,7 +14,8 @@ LDLIBS += -lcap -lelf
 TEST_GEN_PROGS = test_verifier test_tag test_maps test_lru_map test_lpm_map 
test_progs \
test_align
 
-TEST_GEN_FILES = test_pkt_access.o test_xdp.o test_l4lb.o test_tcp_estats.o 
test_obj_id.o
+TEST_GEN_FILES = test_pkt_access.o test_xdp.o test_l4lb.o test_tcp_estats.o 
test_obj_id.o \
+   test_pkt_md_access.o
 
 TEST_PROGS := test_kmod.sh
 
diff --git a/tools/testing/selftests/bpf/test_pkt_md_access.c 
b/tools/testing/selftests/bpf/test_pkt_md_access.c
new file mode 100644
index 000..71729d4
--- /dev/null
+++ b/tools/testing/selftests/bpf/test_pkt_md_access.c
@@ -0,0 +1,35 @@
+/* Copyright (c) 2017 Facebook
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public
+ * License as published by the Free Software Foundation.
+ */
+#include 
+#include 
+#include 
+#include 
+#include "bpf_helpers.h"
+
+int _version SEC("version") = 1;
+
+#define TEST_FIELD(TYPE, FIELD, MASK)  \
+   {   \
+   TYPE tmp = *(volatile TYPE *)>FIELD;   \
+   if (tmp != ((*(volatile __u32 *)>FIELD) & MASK))   \
+   return TC_ACT_SHOT; \
+   }
+
+SEC("test1")
+int process(struct __sk_buff *skb)
+{
+   TEST_FIELD(__u8,  len, 0xFF);
+   TEST_FIELD(__u16, len, 0x);
+   TEST_FIELD(__u32, len, 0x);
+   TEST_FIELD(__u16, protocol, 0x);
+   TEST_FIELD(__u32, protocol, 0x);
+   TEST_FIELD(__u8,  hash, 0xFF);
+   TEST_FIELD(__u16, hash, 0x);
+   TEST_FIELD(__u32, hash, 0x);
+
+   return TC_ACT_OK;
+}
diff --git a/tools/testing/selftests/bpf/test_progs.c 
b/tools/testing/selftests/bpf/test_progs.c
index f10493d..5855cd3 100644
--- a/tools/testing/selftests/bpf/test_progs.c
+++ b/tools/testing/selftests/bpf/test_progs.c
@@ -484,6 +484,26 @@ static void test_bpf_obj_id(void)
bpf_object__close(objs[i]);
 }
 
+static void test_pkt_md_access(void)
+{
+   const char *file = "./test_pkt_md_access.o";
+   struct bpf_object *obj;
+   __u32 duration, retval;
+   int err, prog_fd;
+
+   err = bpf_prog_load(file, BPF_PROG_TYPE_SCHED_CLS, , _fd);
+   if (err)
+   return;
+
+   err = bpf_prog_test_run(prog_fd, 10, _v4, sizeof(pkt_v4),
+   NULL, NULL, , );
+   CHECK(err || retval, "",
+ "err %d errno %d retval %d duration %d\n",
+ err, errno, retval, duration);
+
+   bpf_object__close(obj);
+}
+
 int main(void)
 {
struct rlimit rinf = { RLIM_INFINITY, RLIM_INFINITY };
@@ -495,6 +515,7 @@ int main(void)
test_l4lb();
test_tcp_estats();
test_bpf_obj_id();
+   test_pkt_md_access();
 
printf("Summary: %d PASSED, %d FAILED\n", pass_cnt, error_cnt);
return error_cnt ? EXIT_FAILURE : EXIT_SUCCESS;
diff --git a/tools/testing/selftests/bpf/test_verifier.c 
b/tools/testing/selftests/bpf/test_verifier.c
index 1334170..c0af019 100644
--- a/tools/testing/selftests/bpf/test_verifier.c
+++ b/tools/testing/selftests/bpf/test_verifier.c
@@ -1095,6 +1095,59 @@ static struct bpf_test tests[] = {
.result = REJECT,
},
{
+   "check skb->hash byte load permitted",
+   .insns = {
+   BPF_MOV64_IMM(BPF_REG_0, 0),
+#ifdef __LITTLE_ENDIAN
+   BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_1,
+   offsetof(struct __sk_buff, hash)),
+#else
+   BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_1,
+   offsetof(struct __sk_buff, hash) + 3),
+#endif
+   BPF_EXIT_INSN(),
+   },
+   .result = ACCEPT,
+   },
+   {
+   "check skb->hash byte load not permitted 1",
+   

Re: [PATCH net-next 6/9] net: hns3: Add MDIO support to HNS3 Ethernet driver for hip08 SoC

2017-06-13 Thread Andrew Lunn
> > Hum why do you do this? mdiobus_register() will scan through your bus
> > provided that you set an appropriate phy_mask value (here you tell it
> > not to) and you already provide the PHY address to scan for
> >
> I know this looks weird but the reason why it appears as it is in code is:
>  
> mdiobus_register() calls mdiobus_scan(). If you see below code leg function
> get_phy_device() assumes to be having supporting Clause 22 so its input
> parameter 'is_c45' is always 'false'.
> 
> struct phy_device *mdiobus_scan(struct mii_bus *bus, int addr)
> {
>   struct phy_device *phydev;
>   int err;
> 
>   phydev = get_phy_device(bus, addr, false);
>   if (IS_ERR(phydev))^
>   return phydev;
>   [...]
> }
> 
> Therefore, to support C45 device we did below:
> 
> * disabled the autoscan/mdiobus_scan() Of the PHY devices using the
>   phy_mask(= ~0) 
> * Now, did almost the same thing what mdiobus_scan does i.e.
> * get_phy_device but with is_c45 (=true/false)
> * register the above phy device with phy_device_register()
> 
> There could be some gap in my understanding, please help to correct this?

So this is the question i was asking Florian

Rather than hack around limitations of the core, you should fix the
core. I think we should make the core first try probing using c45. If
that comes back with an error, or does not find a device, try the
probe using c22.

  Andrew


[PATCH v2 1/5] MIPS: Optimize uasm insn lookup.

2017-06-13 Thread David Daney
Instead of doing a linear search through the insn_table for each
instruction, use the opcode as direct index into the table.  This will
give constant time lookup performance as the number of supported
opcodes increases.  Make the tables const as they are only ever read.
For uasm-mips.c sort the table alphabetically, and remove duplicate
entries, uasm-micromips.c was already sorted and duplicate free.
There is a small savings in object size as struct insn loses a field:

$ size arch/mips/mm/uasm-mips.o arch/mips/mm/uasm-mips.o.save
   textdata bss dec hex filename
  10040   0   0   100402738 arch/mips/mm/uasm-mips.o
   92401120   0   103602878 arch/mips/mm/uasm-mips.o.save

Signed-off-by: David Daney 
---
 arch/mips/mm/uasm-micromips.c | 188 ++--
 arch/mips/mm/uasm-mips.c  | 217 +-
 arch/mips/mm/uasm.c   |   3 +-
 3 files changed, 199 insertions(+), 209 deletions(-)

diff --git a/arch/mips/mm/uasm-micromips.c b/arch/mips/mm/uasm-micromips.c
index 277cf52..c28ff53 100644
--- a/arch/mips/mm/uasm-micromips.c
+++ b/arch/mips/mm/uasm-micromips.c
@@ -40,93 +40,92 @@
 
 #include "uasm.c"
 
-static struct insn insn_table_MM[] = {
-   { insn_addu, M(mm_pool32a_op, 0, 0, 0, 0, mm_addu32_op), RT | RS | RD },
-   { insn_addiu, M(mm_addiu32_op, 0, 0, 0, 0, 0), RT | RS | SIMM },
-   { insn_and, M(mm_pool32a_op, 0, 0, 0, 0, mm_and_op), RT | RS | RD },
-   { insn_andi, M(mm_andi32_op, 0, 0, 0, 0, 0), RT | RS | UIMM },
-   { insn_beq, M(mm_beq32_op, 0, 0, 0, 0, 0), RS | RT | BIMM },
-   { insn_beql, 0, 0 },
-   { insn_bgez, M(mm_pool32i_op, mm_bgez_op, 0, 0, 0, 0), RS | BIMM },
-   { insn_bgezl, 0, 0 },
-   { insn_bltz, M(mm_pool32i_op, mm_bltz_op, 0, 0, 0, 0), RS | BIMM },
-   { insn_bltzl, 0, 0 },
-   { insn_bne, M(mm_bne32_op, 0, 0, 0, 0, 0), RT | RS | BIMM },
-   { insn_cache, M(mm_pool32b_op, 0, 0, mm_cache_func, 0, 0), RT | RS | 
SIMM },
-   { insn_cfc1, M(mm_pool32f_op, 0, 0, 0, mm_cfc1_op, mm_32f_73_op), RT | 
RS },
-   { insn_cfcmsa, M(mm_pool32s_op, 0, msa_cfc_op, 0, 0, mm_32s_elm_op), RD 
| RE },
-   { insn_ctc1, M(mm_pool32f_op, 0, 0, 0, mm_ctc1_op, mm_32f_73_op), RT | 
RS },
-   { insn_ctcmsa, M(mm_pool32s_op, 0, msa_ctc_op, 0, 0, mm_32s_elm_op), RD 
| RE },
-   { insn_daddu, 0, 0 },
-   { insn_daddiu, 0, 0 },
-   { insn_di, M(mm_pool32a_op, 0, 0, 0, mm_di_op, mm_pool32axf_op), RS },
-   { insn_divu, M(mm_pool32a_op, 0, 0, 0, mm_divu_op, mm_pool32axf_op), RT 
| RS },
-   { insn_dmfc0, 0, 0 },
-   { insn_dmtc0, 0, 0 },
-   { insn_dsll, 0, 0 },
-   { insn_dsll32, 0, 0 },
-   { insn_dsra, 0, 0 },
-   { insn_dsrl, 0, 0 },
-   { insn_dsrl32, 0, 0 },
-   { insn_drotr, 0, 0 },
-   { insn_drotr32, 0, 0 },
-   { insn_dsubu, 0, 0 },
-   { insn_eret, M(mm_pool32a_op, 0, 0, 0, mm_eret_op, mm_pool32axf_op), 0 
},
-   { insn_ins, M(mm_pool32a_op, 0, 0, 0, 0, mm_ins_op), RT | RS | RD | RE 
},
-   { insn_ext, M(mm_pool32a_op, 0, 0, 0, 0, mm_ext_op), RT | RS | RD | RE 
},
-   { insn_j, M(mm_j32_op, 0, 0, 0, 0, 0), JIMM },
-   { insn_jal, M(mm_jal32_op, 0, 0, 0, 0, 0), JIMM },
-   { insn_jalr, M(mm_pool32a_op, 0, 0, 0, mm_jalr_op, mm_pool32axf_op), RT 
| RS },
-   { insn_jr, M(mm_pool32a_op, 0, 0, 0, mm_jalr_op, mm_pool32axf_op), RS },
-   { insn_lb, M(mm_lb32_op, 0, 0, 0, 0, 0), RT | RS | SIMM },
-   { insn_ld, 0, 0 },
-   { insn_lh, M(mm_lh32_op, 0, 0, 0, 0, 0), RS | RS | SIMM },
-   { insn_ll, M(mm_pool32c_op, 0, 0, (mm_ll_func << 1), 0, 0), RS | RT | 
SIMM },
-   { insn_lld, 0, 0 },
-   { insn_lui, M(mm_pool32i_op, mm_lui_op, 0, 0, 0, 0), RS | SIMM },
-   { insn_lw, M(mm_lw32_op, 0, 0, 0, 0, 0), RT | RS | SIMM },
-   { insn_mfc0, M(mm_pool32a_op, 0, 0, 0, mm_mfc0_op, mm_pool32axf_op), RT 
| RS | RD },
-   { insn_mfhi, M(mm_pool32a_op, 0, 0, 0, mm_mfhi32_op, mm_pool32axf_op), 
RS },
-   { insn_mflo, M(mm_pool32a_op, 0, 0, 0, mm_mflo32_op, mm_pool32axf_op), 
RS },
-   { insn_mtc0, M(mm_pool32a_op, 0, 0, 0, mm_mtc0_op, mm_pool32axf_op), RT 
| RS | RD },
-   { insn_mthi, M(mm_pool32a_op, 0, 0, 0, mm_mthi32_op, mm_pool32axf_op), 
RS },
-   { insn_mtlo, M(mm_pool32a_op, 0, 0, 0, mm_mtlo32_op, mm_pool32axf_op), 
RS },
-   { insn_mul, M(mm_pool32a_op, 0, 0, 0, 0, mm_mul_op), RT | RS | RD },
-   { insn_or, M(mm_pool32a_op, 0, 0, 0, 0, mm_or32_op), RT | RS | RD },
-   { insn_ori, M(mm_ori32_op, 0, 0, 0, 0, 0), RT | RS | UIMM },
-   { insn_pref, M(mm_pool32c_op, 0, 0, (mm_pref_func << 1), 0, 0), RT | RS 
| SIMM },
-   { insn_rfe, 0, 0 },
-   { insn_sc, M(mm_pool32c_op, 0, 0, (mm_sc_func << 1), 0, 0), RT | RS | 
SIMM },
-   { insn_scd, 0, 0 },
-   { insn_sd, 0, 0 },
-   { insn_sll, M(mm_pool32a_op, 0, 0, 0, 0, mm_sll32_op), RT | RS | RD },
-   { 

[PATCH v2 0/5] MIPS: Implement eBPF JIT.

2017-06-13 Thread David Daney
Changes in v2:

  - Squash a couple of the uasm cleanups.

  - Make insn_table_MM const (suggested by Matt Redfearn)

  - Put the eBPF in its own source file (should fix build
warnings/errors on 32-bit kernel builds).

  - Use bpf_jit_binary_alloc() (suggested by Daniel Borkmann)

  - Implement tail calls.

  - Fix system call tracing to extract arguments for
kprobe/__seccomp_filter() tracing (perhaps not really part the the
JIT, but necessary to have fun with the samples/bpf programs).

Most things in samples/bpf work, still working on the incantations to
build tools/testing/selftests/bpf/ ... 


>From v1:

The first three patches improve MIPS uasm in preparation for use by
the JIT.  Then the eBPF JIT implementation.

I am CCing netdev@ and the BPF maintainers for their comments, but
would expect Ralf to merge via the MIPS tree if and when it all looks
good.


David Daney (5):
  MIPS: Optimize uasm insn lookup.
  MIPS: Correctly define DBSHFL type instruction opcodes.
  MIPS: Add some instructions to uasm.
  MIPS: Add support for eBPF JIT.
  MIPS: Give __secure_computing() access to syscall arguments.

 arch/mips/Kconfig |   12 +-
 arch/mips/include/asm/uasm.h  |   30 +
 arch/mips/include/uapi/asm/inst.h |9 +-
 arch/mips/kernel/ptrace.c |   22 +-
 arch/mips/mm/uasm-micromips.c |  188 ++--
 arch/mips/mm/uasm-mips.c  |  238 ++---
 arch/mips/mm/uasm.c   |   61 +-
 arch/mips/net/Makefile|3 +-
 arch/mips/net/ebpf_jit.c  | 1949 +
 9 files changed, 2285 insertions(+), 227 deletions(-)
 create mode 100644 arch/mips/net/ebpf_jit.c

-- 
2.9.4



[PATCH v2 2/5] MIPS: Correctly define DBSHFL type instruction opcodes.

2017-06-13 Thread David Daney
DSHD was incorrectly classified as being BSHFL, and DSHD was missing
altogether.

Signed-off-by: David Daney 
---
 arch/mips/include/uapi/asm/inst.h | 9 -
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/arch/mips/include/uapi/asm/inst.h 
b/arch/mips/include/uapi/asm/inst.h
index b5e46ae..e5f5385 100644
--- a/arch/mips/include/uapi/asm/inst.h
+++ b/arch/mips/include/uapi/asm/inst.h
@@ -276,12 +276,19 @@ enum lx_func {
  */
 enum bshfl_func {
wsbh_op = 0x2,
-   dshd_op = 0x5,
seb_op  = 0x10,
seh_op  = 0x18,
 };
 
 /*
+ * DBSHFL opcodes
+ */
+enum dbshfl_func {
+   dsbh_op = 0x2,
+   dshd_op = 0x5,
+};
+
+/*
  * MSA minor opcodes.
  */
 enum msa_func {
-- 
2.9.4



[PATCH v2 5/5] MIPS: Give __secure_computing() access to syscall arguments.

2017-06-13 Thread David Daney
KProbes of __seccomp_filter() are not very useful without access to
the syscall arguments.

Do what x86 does, and populate a struct seccomp_data to be passed to
__secure_computing().  This allows samples/bpf/tracex5 to extract a
sensible trace.

Signed-off-by: David Daney 
---
 arch/mips/kernel/ptrace.c | 22 --
 1 file changed, 20 insertions(+), 2 deletions(-)

diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
index 6931fe7..ba3b1f7 100644
--- a/arch/mips/kernel/ptrace.c
+++ b/arch/mips/kernel/ptrace.c
@@ -868,8 +868,26 @@ asmlinkage long syscall_trace_enter(struct pt_regs *regs, 
long syscall)
tracehook_report_syscall_entry(regs))
return -1;
 
-   if (secure_computing(NULL) == -1)
-   return -1;
+#ifdef CONFIG_SECCOMP
+   if (unlikely(test_thread_flag(TIF_SECCOMP))) {
+   int ret, i;
+   struct seccomp_data sd;
+
+   sd.nr = syscall;
+   sd.arch = syscall_get_arch();
+   for (i = 0; i < 6; i++) {
+   unsigned long v, r;
+
+   r = mips_get_syscall_arg(, current, regs, i);
+   sd.args[i] = r ? 0 : v;
+   }
+   sd.instruction_pointer = KSTK_EIP(current);
+
+   ret = __secure_computing();
+   if (ret == -1)
+   return ret;
+   }
+#endif
 
if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
trace_sys_enter(regs, regs->regs[2]);
-- 
2.9.4



[PATCH v2 4/5] MIPS: Add support for eBPF JIT.

2017-06-13 Thread David Daney
Since the eBPF machine has 64-bit registers, we only support this in
64-bit kernels.  As of the writing of this commit log test-bpf is showing:

  test_bpf: Summary: 316 PASSED, 0 FAILED, [308/308 JIT'ed]

All current test cases are successfully compiled.

Many examples in samples/bpf are usable, specifically tracex5 which
uses tail calls works.

Signed-off-by: David Daney 
---
 arch/mips/Kconfig|   12 +-
 arch/mips/net/Makefile   |3 +-
 arch/mips/net/ebpf_jit.c | 1949 ++
 3 files changed, 1962 insertions(+), 2 deletions(-)
 create mode 100644 arch/mips/net/ebpf_jit.c

diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
index 2828ecd..f4cf11e 100644
--- a/arch/mips/Kconfig
+++ b/arch/mips/Kconfig
@@ -18,7 +18,8 @@ config MIPS
select HAVE_ARCH_MMAP_RND_COMPAT_BITS if MMU && COMPAT
select HAVE_ARCH_SECCOMP_FILTER
select HAVE_ARCH_TRACEHOOK
-   select HAVE_CBPF_JIT if !CPU_MICROMIPS
+   select HAVE_CBPF_JIT if (!64BIT && !CPU_MICROMIPS)
+   select HAVE_EBPF_JIT if (64BIT && !CPU_MICROMIPS)
select HAVE_FUNCTION_TRACER
select HAVE_DYNAMIC_FTRACE
select HAVE_FTRACE_MCOUNT_RECORD
@@ -1178,6 +1179,15 @@ config SYS_SUPPORTS_RELOCATABLE
 The platform must provide plat_get_fdt() if it selects CONFIG_USE_OF
 to allow access to command line and entropy sources.
 
+config MIPS_CBPF_JIT
+   def_bool y
+   depends on BPF_JIT && HAVE_CBPF_JIT
+
+config MIPS_EBPF_JIT
+   def_bool y
+   depends on BPF_JIT && HAVE_EBPF_JIT
+
+
 #
 # Endianness selection.  Sufficiently obscure so many users don't know what to
 # answer,so we try hard to limit the available choices.  Also the use of a
diff --git a/arch/mips/net/Makefile b/arch/mips/net/Makefile
index 8c27714..47d6784 100644
--- a/arch/mips/net/Makefile
+++ b/arch/mips/net/Makefile
@@ -1,3 +1,4 @@
 # MIPS networking code
 
-obj-$(CONFIG_BPF_JIT) += bpf_jit.o bpf_jit_asm.o
+obj-$(CONFIG_MIPS_CBPF_JIT) += bpf_jit.o bpf_jit_asm.o
+obj-$(CONFIG_MIPS_EBPF_JIT) += ebpf_jit.o
diff --git a/arch/mips/net/ebpf_jit.c b/arch/mips/net/ebpf_jit.c
new file mode 100644
index 000..19af13f
--- /dev/null
+++ b/arch/mips/net/ebpf_jit.c
@@ -0,0 +1,1949 @@
+/*
+ * Just-In-Time compiler for eBPF filters on MIPS
+ *
+ * Copyright (c) 2017 Cavium, Inc.
+ *
+ * Based on code from:
+ *
+ * Copyright (c) 2014 Imagination Technologies Ltd.
+ * Author: Markos Chandras 
+ *
+ * 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; version 2 of the License.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* Registers used by JIT */
+#define MIPS_R_ZERO0
+#define MIPS_R_AT  1
+#define MIPS_R_V0  2   /* BPF_R0 */
+#define MIPS_R_V1  3
+#define MIPS_R_A0  4   /* BPF_R1 */
+#define MIPS_R_A1  5   /* BPF_R2 */
+#define MIPS_R_A2  6   /* BPF_R3 */
+#define MIPS_R_A3  7   /* BPF_R4 */
+#define MIPS_R_A4  8   /* BPF_R5 */
+#define MIPS_R_T4  12  /* BPF_AX */
+#define MIPS_R_T5  13
+#define MIPS_R_T6  14
+#define MIPS_R_T7  15
+#define MIPS_R_S0  16  /* BPF_R6 */
+#define MIPS_R_S1  17  /* BPF_R7 */
+#define MIPS_R_S2  18  /* BPF_R8 */
+#define MIPS_R_S3  19  /* BPF_R9 */
+#define MIPS_R_S4  20  /* BPF_TCC */
+#define MIPS_R_S5  21
+#define MIPS_R_S6  22
+#define MIPS_R_S7  23
+#define MIPS_R_T8  24
+#define MIPS_R_T9  25
+#define MIPS_R_SP  29
+#define MIPS_R_RA  31
+
+/* eBPF flags */
+#define EBPF_SAVE_S0   BIT(0)
+#define EBPF_SAVE_S1   BIT(1)
+#define EBPF_SAVE_S2   BIT(2)
+#define EBPF_SAVE_S3   BIT(3)
+#define EBPF_SAVE_S4   BIT(4)
+#define EBPF_SAVE_RA   BIT(5)
+#define EBPF_SEEN_FP   BIT(6)
+#define EBPF_SEEN_TC   BIT(7)
+#define EBPF_TCC_IN_V1 BIT(8)
+
+/*
+ * For the mips64 ISA, we need to track the value range or type for
+ * each JIT register.  The BPF machine requires zero extended 32-bit
+ * values, but the mips64 ISA requires sign extended 32-bit values.
+ * At each point in the BPF program we track the state of every
+ * register so that we can zero extend or sign extend as the BPF
+ * semantics require.
+ */
+enum reg_val_type {
+   /* uninitialized */
+   REG_UNKNOWN,
+   /* not known to be 32-bit compatible. */
+   REG_64BIT,
+   /* 32-bit compatible, no truncation needed for 64-bit ops. */
+   REG_64BIT_32BIT,
+   /* 32-bit compatible, need truncation for 64-bit ops. */
+   REG_32BIT,
+   /* 32-bit zero extended. */
+   REG_32BIT_ZERO_EX,
+   /* 32-bit no sign/zero extension needed. */
+   REG_32BIT_POS
+};
+
+/*
+ * high bit of offsets indicates if long branch conversion done at
+ * this insn.
+ */
+#define 

[PATCH v2 3/5] MIPS: Add some instructions to uasm.

2017-06-13 Thread David Daney
Follow on patches for eBPF JIT require these additional instructions:

   insn_bgtz, insn_blez, insn_break, insn_ddivu, insn_dmultu,
   insn_dsbh, insn_dshd, insn_dsllv, insn_dsra32, insn_dsrav,
   insn_dsrlv, insn_lbu, insn_movn, insn_movz, insn_multu, insn_nor,
   insn_sb, insn_sh, insn_slti, insn_dinsu, insn_lwu

... so, add them.

Sort the insn_* enumeration values alphabetically.

Signed-off-by: David Daney 
---
 arch/mips/include/asm/uasm.h | 30 +++
 arch/mips/mm/uasm-mips.c | 21 
 arch/mips/mm/uasm.c  | 58 ++--
 3 files changed, 96 insertions(+), 13 deletions(-)

diff --git a/arch/mips/include/asm/uasm.h b/arch/mips/include/asm/uasm.h
index 3748f4d..59dae37 100644
--- a/arch/mips/include/asm/uasm.h
+++ b/arch/mips/include/asm/uasm.h
@@ -72,9 +72,12 @@ Ip_u1u2s3(_beq);
 Ip_u1u2s3(_beql);
 Ip_u1s2(_bgez);
 Ip_u1s2(_bgezl);
+Ip_u1s2(_bgtz);
+Ip_u1s2(_blez);
 Ip_u1s2(_bltz);
 Ip_u1s2(_bltzl);
 Ip_u1u2s3(_bne);
+Ip_u1(_break);
 Ip_u2s3u1(_cache);
 Ip_u1u2(_cfc1);
 Ip_u2u1(_cfcmsa);
@@ -82,19 +85,28 @@ Ip_u1u2(_ctc1);
 Ip_u2u1(_ctcmsa);
 Ip_u2u1s3(_daddiu);
 Ip_u3u1u2(_daddu);
+Ip_u1u2(_ddivu);
 Ip_u1(_di);
 Ip_u2u1msbu3(_dins);
 Ip_u2u1msbu3(_dinsm);
+Ip_u2u1msbu3(_dinsu);
 Ip_u1u2(_divu);
 Ip_u1u2u3(_dmfc0);
 Ip_u1u2u3(_dmtc0);
+Ip_u1u2(_dmultu);
 Ip_u2u1u3(_drotr);
 Ip_u2u1u3(_drotr32);
+Ip_u2u1(_dsbh);
+Ip_u2u1(_dshd);
 Ip_u2u1u3(_dsll);
 Ip_u2u1u3(_dsll32);
+Ip_u3u2u1(_dsllv);
 Ip_u2u1u3(_dsra);
+Ip_u2u1u3(_dsra32);
+Ip_u3u2u1(_dsrav);
 Ip_u2u1u3(_dsrl);
 Ip_u2u1u3(_dsrl32);
+Ip_u3u2u1(_dsrlv);
 Ip_u3u1u2(_dsubu);
 Ip_0(_eret);
 Ip_u2u1msbu3(_ext);
@@ -104,6 +116,7 @@ Ip_u1(_jal);
 Ip_u2u1(_jalr);
 Ip_u1(_jr);
 Ip_u2s3u1(_lb);
+Ip_u2s3u1(_lbu);
 Ip_u2s3u1(_ld);
 Ip_u3u1u2(_ldx);
 Ip_u2s3u1(_lh);
@@ -112,27 +125,35 @@ Ip_u2s3u1(_ll);
 Ip_u2s3u1(_lld);
 Ip_u1s2(_lui);
 Ip_u2s3u1(_lw);
+Ip_u2s3u1(_lwu);
 Ip_u3u1u2(_lwx);
 Ip_u1u2u3(_mfc0);
 Ip_u1u2u3(_mfhc0);
 Ip_u1(_mfhi);
 Ip_u1(_mflo);
+Ip_u3u1u2(_movn);
+Ip_u3u1u2(_movz);
 Ip_u1u2u3(_mtc0);
 Ip_u1u2u3(_mthc0);
 Ip_u1(_mthi);
 Ip_u1(_mtlo);
 Ip_u3u1u2(_mul);
+Ip_u1u2(_multu);
+Ip_u3u1u2(_nor);
 Ip_u3u1u2(_or);
 Ip_u2u1u3(_ori);
 Ip_u2s3u1(_pref);
 Ip_0(_rfe);
 Ip_u2u1u3(_rotr);
+Ip_u2s3u1(_sb);
 Ip_u2s3u1(_sc);
 Ip_u2s3u1(_scd);
 Ip_u2s3u1(_sd);
+Ip_u2s3u1(_sh);
 Ip_u2u1u3(_sll);
 Ip_u3u2u1(_sllv);
 Ip_s3s1s2(_slt);
+Ip_u2u1s3(_slti);
 Ip_u2u1s3(_sltiu);
 Ip_u3u1u2(_sltu);
 Ip_u2u1u3(_sra);
@@ -248,6 +269,15 @@ static inline void uasm_i_dsrl_safe(u32 **p, unsigned int 
a1,
uasm_i_dsrl32(p, a1, a2, a3 - 32);
 }
 
+static inline void uasm_i_dsra_safe(u32 **p, unsigned int a1,
+   unsigned int a2, unsigned int a3)
+{
+   if (a3 < 32)
+   uasm_i_dsra(p, a1, a2, a3);
+   else
+   uasm_i_dsra32(p, a1, a2, a3 - 32);
+}
+
 /* Handle relocations. */
 struct uasm_reloc {
u32 *addr;
diff --git a/arch/mips/mm/uasm-mips.c b/arch/mips/mm/uasm-mips.c
index f3937e3..3f74f6c 100644
--- a/arch/mips/mm/uasm-mips.c
+++ b/arch/mips/mm/uasm-mips.c
@@ -59,9 +59,12 @@ static const struct insn const insn_table[insn_invalid] = {
[insn_beql] = {M(beql_op, 0, 0, 0, 0, 0), RS | RT | BIMM},
[insn_bgez] = {M(bcond_op, 0, bgez_op, 0, 0, 0), RS | BIMM},
[insn_bgezl]= {M(bcond_op, 0, bgezl_op, 0, 0, 0), RS | BIMM},
+   [insn_bgtz] = {M(bgtz_op, 0, 0, 0, 0, 0), RS | BIMM},
+   [insn_blez] = {M(blez_op, 0, 0, 0, 0, 0), RS | BIMM},
[insn_bltz] = {M(bcond_op, 0, bltz_op, 0, 0, 0), RS | BIMM},
[insn_bltzl]= {M(bcond_op, 0, bltzl_op, 0, 0, 0), RS | BIMM},
[insn_bne]  = {M(bne_op, 0, 0, 0, 0, 0), RS | RT | BIMM},
+   [insn_break]= {M(spec_op, 0, 0, 0, 0, break_op), SCIMM},
 #ifndef CONFIG_CPU_MIPSR6
[insn_cache]= {M(cache_op, 0, 0, 0, 0, 0),  RS | RT | SIMM},
 #else
@@ -73,19 +76,28 @@ static const struct insn const insn_table[insn_invalid] = {
[insn_ctcmsa]   = {M(msa_op, 0, msa_ctc_op, 0, 0, msa_elm_op), RD | RE},
[insn_daddiu]   = {M(daddiu_op, 0, 0, 0, 0, 0), RS | RT | SIMM},
[insn_daddu]= {M(spec_op, 0, 0, 0, 0, daddu_op), RS | RT | RD},
+   [insn_ddivu]= {M(spec_op, 0, 0, 0, 0, ddivu_op), RS | RT},
[insn_di]   = {M(cop0_op, mfmc0_op, 0, 12, 0, 0), RT},
[insn_dins] = {M(spec3_op, 0, 0, 0, 0, dins_op), RS | RT | RD | RE},
[insn_dinsm]= {M(spec3_op, 0, 0, 0, 0, dinsm_op), RS | RT | RD | 
RE},
+   [insn_dinsu]= {M(spec3_op, 0, 0, 0, 0, dinsu_op), RS | RT | RD | 
RE},
[insn_divu] = {M(spec_op, 0, 0, 0, 0, divu_op), RS | RT},
[insn_dmfc0]= {M(cop0_op, dmfc_op, 0, 0, 0, 0), RT | RD | SET},
[insn_dmtc0]= {M(cop0_op, dmtc_op, 0, 0, 0, 0), RT | RD | SET},
+   [insn_dmultu]   = {M(spec_op, 0, 0, 0, 0, dmultu_op), RS | RT},
[insn_drotr]= {M(spec_op, 1, 0, 0, 0, 

Re: [PATCH RFC net-next 4/4] net/mlx5: Add CONFIG_MLX5_ESWITCH Kconfig

2017-06-13 Thread Saeed Mahameed
On Tue, Jun 13, 2017 at 9:21 PM, Jes Sorensen  wrote:
> On 06/13/2017 01:58 PM, Saeed Mahameed wrote:
>>
>> On Mon, Jun 12, 2017 at 9:20 PM, Jes Sorensen  wrote:
>>>
>>> On 06/07/2017 07:42 PM, Saeed Mahameed wrote:


 This patch gives the option to chose whether to compile the driver with
 or
 without eswitch/eswitch_offloads(switchdev mode)/en_rep(VF representors)
 and en_tc offloads.

 It also removes most of the above modules headers declarations and stubs
 out the API functions which are used outside these modules.

 Signed-off-by: Saeed Mahameed 
 ---
drivers/net/ethernet/mellanox/mlx5/core/Kconfig   |  7 +
drivers/net/ethernet/mellanox/mlx5/core/Makefile  |  6 +++--
drivers/net/ethernet/mellanox/mlx5/core/en_main.c | 33
 +++
drivers/net/ethernet/mellanox/mlx5/core/en_rep.h  |  8 ++
drivers/net/ethernet/mellanox/mlx5/core/en_rx.c   |  2 ++
drivers/net/ethernet/mellanox/mlx5/core/en_tc.h   |  7 +
drivers/net/ethernet/mellanox/mlx5/core/eswitch.h | 23
 +++-
drivers/net/ethernet/mellanox/mlx5/core/main.c| 10 +--
8 files changed, 68 insertions(+), 28 deletions(-)
>>>
>>>
>>>
>>> Overall good, a few nits
>>>
>>>
 @@ -3316,6 +3317,7 @@ static int mlx5e_ioctl(struct net_device *dev,
 struct ifreq *ifr, int cmd)
  }
}
+#ifdef CONFIG_MLX5_ESWITCH
static int mlx5e_set_vf_mac(struct net_device *dev, int vf, u8 *mac)
{
  struct mlx5e_priv *priv = netdev_priv(dev);
 @@ -3418,6 +3420,7 @@ static int mlx5e_get_vf_stats(struct net_device
 *dev,
  return mlx5_eswitch_get_vport_stats(mdev->priv.eswitch, vf + 1,
  vf_stats);
}
 +#endif
  static void mlx5e_add_vxlan_port(struct net_device *netdev,
   struct udp_tunnel_info *ti)
 @@ -3659,6 +3662,7 @@ static const struct net_device_ops
 mlx5e_netdev_ops_basic = {
#endif
};
+#ifdef CONFIG_MLX5_ESWITCH
static const struct net_device_ops mlx5e_netdev_ops_sriov = {
  .ndo_open= mlx5e_open,
  .ndo_stop= mlx5e_close,
 @@ -3697,6 +3701,7 @@ static const struct net_device_ops
 mlx5e_netdev_ops_sriov = {
  .ndo_has_offload_stats   = mlx5e_has_offload_stats,
  .ndo_get_offload_stats   = mlx5e_get_offload_stats,
};
 +#endif
  static int mlx5e_check_required_hca_cap(struct mlx5_core_dev *mdev)
{
 @@ -3923,9 +3928,11 @@ static void mlx5e_set_netdev_dev_addr(struct
 net_device *netdev)
  }
}
+#if IS_ENABLED(CONFIG_NET_SWITCHDEV) &&
 IS_ENABLED(CONFIG_MLX5_ESWITCH)
static const struct switchdev_ops mlx5e_switchdev_ops = {
  .switchdev_port_attr_get= mlx5e_attr_get,
};
 +#endif
  static void mlx5e_build_nic_netdev(struct net_device *netdev)
{
>>>
>>>
>>>
>>> Why not move these functions and the struct into one of the files that is
>>> being compiled out. The less #ifdefs we leave in the code the better.
>>>
>>
>> eswitch is independent from netdev, and we want to keep netdev ndos
>> local to netdev files.
>
>
> Not the end of the World then.
>
>
 @@ -3936,15 +3943,17 @@ static void mlx5e_build_nic_netdev(struct
 net_device *netdev)
  SET_NETDEV_DEV(netdev, >pdev->dev);
- if (MLX5_CAP_GEN(mdev, vport_group_manager)) {
 -   netdev->netdev_ops = _netdev_ops_sriov;
#ifdef CONFIG_MLX5_CORE_EN_DCB
 -   if (MLX5_CAP_GEN(mdev, qos))
 -   netdev->dcbnl_ops = _dcbnl_ops;
 +   if (MLX5_CAP_GEN(mdev, vport_group_manager) &&
 MLX5_CAP_GEN(mdev,
 qos))
 +   netdev->dcbnl_ops = _dcbnl_ops;
 +#endif
 +
 +#ifdef CONFIG_MLX5_ESWITCH
 +   if (MLX5_CAP_GEN(mdev, vport_group_manager))
 +   netdev->netdev_ops = _netdev_ops_sriov;
 +   else
#endif
 -   } else {
  netdev->netdev_ops = _netdev_ops_basic;
 -   }
  netdev->watchdog_timeo= 15 * HZ;
>>>
>>>
>>>
>>> This kind of #ifdef is always bad, it's hard to read and easy to get
>>> wrong.
>>> Why not have MLX5_CAP_GEN return 0 if MLX5_ESWITCH is not enabled and
>>> have a
>>> dummy pointer?
>>>
>>
>> i know ifdef is ugly, but we have to provide basic ndos (not dummy
>> pointers) when eswitch is not avaialbe, also we want the code to be as
>> much as free from empty functions that all they do is to return
>> -EOPNOTSUPP;
>>
>> for my taste this way is cleaner and more readable, from these line
>> you can understand when SRIOV/Eswitch is not supported. you don't need
>> 

Odd use of %14pM in net/batman-adv/distributed-arp-table.c

2017-06-13 Thread Joe Perches
An output mac address is 17 bytes

 1
12345678901234567
00:11:22:33:44:55

but in net/batman-adv/distributed-arp-table.c

int batadv_dat_cache_seq_print_text(struct seq_file *seq, void *offset)
{
[...]
seq_printf(seq, " * %15pI4 %14pM %4i %6i:%02i\n",
   _entry->ip, dat_entry->mac_addr,
   batadv_print_vid(dat_entry->vid),
   last_seen_mins, last_seen_secs);

%14pM is odd as this should not emit the last byte of the
mac address.  So given the example above, it would output
00:11:22:33:44

Is that what's really desired?

If so, I'd suggest using something more obvious like %5phC



Re: Repeatable inet6_dump_fib crash in stock 4.12.0-rc4+

2017-06-13 Thread Cong Wang
On Tue, Jun 13, 2017 at 1:16 PM, Ben Greear  wrote:
> On 06/09/2017 02:25 PM, Eric Dumazet wrote:
>>
>> On Fri, 2017-06-09 at 07:27 -0600, David Ahern wrote:
>>>
>>> On 6/8/17 11:55 PM, Cong Wang wrote:
 Apparently fn->parent is NULL here for some reason, but
 I don't know if that is expected or not. If a simple NULL check
 is not enough here, we have to trace why it is NULL.
>>>
>>>
>>> From my understanding, parent should not be null hence the attempts to
>>> fix access to table nodes under a lock. ie., figuring out why it is null
>>> here.
>
>
> If someone has more suggestions, I'll be happy to test.

Can you enable RT6_TRACE() by changing RT6_DEBUG
from 2 to 3? We may collect some useful log with it.

diff --git a/net/ipv6/ip6_fib.c b/net/ipv6/ip6_fib.c
index d4bf2c6..1941595 100644
--- a/net/ipv6/ip6_fib.c
+++ b/net/ipv6/ip6_fib.c
@@ -37,7 +37,7 @@
 #include 
 #include 

-#define RT6_DEBUG 2
+#define RT6_DEBUG 3

 #if RT6_DEBUG >= 3
 #define RT6_TRACE(x...) pr_debug(x)


RE: [PATCH net-next 6/9] net: hns3: Add MDIO support to HNS3 Ethernet driver for hip08 SoC

2017-06-13 Thread Salil Mehta
Hi Florian,

> -Original Message-
> From: Florian Fainelli [mailto:f.faine...@gmail.com]
> Sent: Saturday, June 10, 2017 8:04 PM
> To: Salil Mehta; da...@davemloft.net
> Cc: Zhuangyuzeng (Yisen); huangdaode; lipeng (Y);
> mehta.salil@gmail.com; netdev@vger.kernel.org; linux-
> ker...@vger.kernel.org; Linuxarm; Andrew Lunn
> Subject: Re: [PATCH net-next 6/9] net: hns3: Add MDIO support to HNS3
> Ethernet driver for hip08 SoC
> 
> Le 06/09/17 à 20:46, Salil Mehta a écrit :
> > This patch adds the support of MDIO bus interface for HNS3 driver.
> > Code provides various interfaces to start and stop the PHY layer
> > and to read and write the MDIO bus or PHY.
> >
> > Signed-off-by: Daode Huang 
> > Signed-off-by: lipeng 
> > Signed-off-by: Salil Mehta 
> > Signed-off-by: Yisen Zhuang 
> > ---
> >  .../ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c| 310
> +
> >  1 file changed, 310 insertions(+)
> >  create mode 100644
> drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c
> >
> > diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c
> b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c
> > new file mode 100644
> > index 000..c6812d2
> > --- /dev/null
> > +++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c
> > @@ -0,0 +1,310 @@
> > +/*
> > + * 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 
> > +
> > +#include "hclge_cmd.h"
> > +#include "hclge_main.h"
> > +
> > +enum hclge_mdio_c22_op_seq {
> > +   HCLGE_MDIO_C22_WRITE = 1,
> > +   HCLGE_MDIO_C22_READ = 2
> > +};
> > +
> > +enum hclge_mdio_c45_op_seq {
> > +   HCLGE_MDIO_C45_WRITE_ADDR = 0,
> > +   HCLGE_MDIO_C45_WRITE_DATA,
> > +   HCLGE_MDIO_C45_READ_INCREMENT,
> > +   HCLGE_MDIO_C45_READ
> > +};
> > +
> > +#define HCLGE_MDIO_CTRL_START_BIT   BIT(0)
> > +#define HCLGE_MDIO_CTRL_ST_MSK  GENMASK(2, 1)
> > +#define HCLGE_MDIO_CTRL_ST_LSH  1
> > +#define HCLGE_MDIO_IS_C22(c22)  (((c22) << HCLGE_MDIO_CTRL_ST_LSH) &
> \
> > +   HCLGE_MDIO_CTRL_ST_MSK)
> > +
> > +#define HCLGE_MDIO_CTRL_OP_MSK  GENMASK(4, 3)
> > +#define HCLGE_MDIO_CTRL_OP_LSH  3
> > +#define HCLGE_MDIO_CTRL_OP(access) \
> > +   (((access) << HCLGE_MDIO_CTRL_OP_LSH) & HCLGE_MDIO_CTRL_OP_MSK)
> > +#define HCLGE_MDIO_CTRL_PRTAD_MSK   GENMASK(4, 0)
> > +#define HCLGE_MDIO_CTRL_DEVAD_MSK   GENMASK(4, 0)
> > +
> > +#define HCLGE_MDIO_STA_VAL(val)((val) & BIT(0))
> > +
> > +struct hclge_mdio_cfg_cmd {
> > +   u8 ctrl_bit;
> > +   u8 prtad;   /* The external port address */
> > +   u8 devad;   /* The external device address */
> > +   u8 rsvd;
> > +   __le16 addr_c45;/* Only valid for c45 */
> > +   __le16 data_wr;
> > +   __le16 data_rd;
> > +   __le16 sta;> +};
> > +
> > +static int hclge_mdio_write(struct mii_bus *bus, int phy_id, int
> regnum,
> > +   u16 data)
> > +{
> > +   struct hclge_dev *hdev = (struct hclge_dev *)bus->priv;
> > +   struct hclge_mdio_cfg_cmd *mdio_cmd;
> > +   enum hclge_cmd_status status;
> > +   struct hclge_desc desc;
> > +   u8 is_c45, devad;
> > +   u16 reg;
> > +
> > +   if (!bus)
> > +   return -EINVAL;
> > +
> > +   is_c45 = !!(regnum & MII_ADDR_C45);
> > +   devad = ((regnum >> 16) & 0x1f);
> > +   reg = (u16)(regnum & 0x);
> > +
> > +   hclge_cmd_setup_basic_desc(, HCLGE_OPC_MDIO_CONFIG, false);
> > +
> > +   mdio_cmd = (struct hclge_mdio_cfg_cmd *)desc.data;
> > +
> > +   if (!is_c45) {
> 
> It would be more readable with positive logic: if (is_c45) { } else { }
Fine, will change.

Thanks
Salil
> 
> > +   /* C22 write reg and data */
> > +   mdio_cmd->ctrl_bit = HCLGE_MDIO_IS_C22(!is_c45);
> > +   mdio_cmd->ctrl_bit |=
> HCLGE_MDIO_CTRL_OP(HCLGE_MDIO_C22_WRITE);
> > +   mdio_cmd->ctrl_bit |= HCLGE_MDIO_CTRL_START_BIT;
> > +   mdio_cmd->data_wr = cpu_to_le16(data);
> > +   mdio_cmd->devad = devad & HCLGE_MDIO_CTRL_DEVAD_MSK;
> > +   mdio_cmd->prtad = phy_id & HCLGE_MDIO_CTRL_PRTAD_MSK;
> > +   } else {
> > +   /* Set phy addr */
> > +   mdio_cmd->ctrl_bit |= HCLGE_MDIO_CTRL_START_BIT;
> > +   mdio_cmd->addr_c45 = cpu_to_le16(reg);
> > +   mdio_cmd->data_wr = cpu_to_le16(data);
> > +   mdio_cmd->devad = devad & HCLGE_MDIO_CTRL_DEVAD_MSK;
> > +   mdio_cmd->prtad = phy_id & HCLGE_MDIO_CTRL_PRTAD_MSK;
> > +   }
> 
> There is some common initialization that you could probably extracted
> out of the C22/C45 clause here.
Yes, I agree. Will remove the redundancy and take out the common part.

Thanks
Salil
> 
> > +
> > +   status = 

[PATCH] rtlwifi: rtl8821ae: remove unused variable

2017-06-13 Thread Gustavo A. R. Silva
Remove unused variable rtlhal.

Addresses-Coverity-ID: 1248810
Signed-off-by: Gustavo A. R. Silva 
---
 drivers/net/wireless/realtek/rtlwifi/rtl8821ae/hw.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8821ae/hw.c 
b/drivers/net/wireless/realtek/rtlwifi/rtl8821ae/hw.c
index 2bc6bac..d158e34 100644
--- a/drivers/net/wireless/realtek/rtlwifi/rtl8821ae/hw.c
+++ b/drivers/net/wireless/realtek/rtlwifi/rtl8821ae/hw.c
@@ -1360,7 +1360,6 @@ static bool _rtl8821ae_reset_pcie_interface_dma(struct 
ieee80211_hw *hw,
 static void _rtl8821ae_get_wakeup_reason(struct ieee80211_hw *hw)
 {
struct rtl_priv *rtlpriv = rtl_priv(hw);
-   struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
struct rtl_ps_ctl *ppsc = rtl_psc(rtlpriv);
u8 fw_reason = 0;
struct timeval ts;
@@ -1372,8 +1371,6 @@ static void _rtl8821ae_get_wakeup_reason(struct 
ieee80211_hw *hw)
 
ppsc->wakeup_reason = 0;
 
-   rtlhal->last_suspend_sec = ts.tv_sec;
-
switch (fw_reason) {
case FW_WOW_V2_PTK_UPDATE_EVENT:
ppsc->wakeup_reason = WOL_REASON_PTK_UPDATE;
-- 
2.5.0



Re: [PATCH] via-rhine: add support for changing MTU

2017-06-13 Thread David Miller
From: Magnus Damm 
Date: Wed, 14 Jun 2017 02:18:27 +0900

> From: Magnus Damm 
> 
> Allow adjusting the MTU for via-rhine devices in case of no TX alignment
> buffer is used.
> 
> Lightly tested on ALIX2D13 hardware by making use of VXLAN with MTU set
> to 1500 on top of via-rhine devices with 1550 MTU. Without this patch
> the VXLAN MTU is limited to less than 1500.
> 
> Signed-off-by: Magnus Damm 

Why is the TX alignment buffer such an obstacle?

It would be so much nicer if this could be supported for all chip
variants instead of some certain subset which users have no idea
of figuring out.  It's a really bad user experience to set them
up for failure like this.


Re: [RFC PATCH net-next 15/15] bpf: Sample bpf program to set sndcwnd clamp

2017-06-13 Thread David Miller
From: Lawrence Brakmo 
Date: Tue, 13 Jun 2017 11:00:04 -0700

> +SEC("sockops")
> +int bpf_clamp(struct __sk_buff *skb)
> +{
> + struct bpf_socket_ops *skops = (struct bpf_socket_ops *) skb;
> + char fmt1[] = "BPF command: %d\n";
> + char fmt2[] = "  Returning %d\n";
> + int op;
> + int rv = 0;
> + int bufsize = 15;
> + int clamp = 100;
> + int to_init = 10;
> +
> + // For testing purposes, only execute rest of BPF program
> + // if neither port numberis 55601
> + if (skops->remote_port != 55601 && skops->local_port != 55601)
> + return -1;

Local variable ordering and C++ comments.


Re: [RFC PATCH net-next 13/15] bpf: Sample BPF program to set initial cwnd

2017-06-13 Thread David Miller
From: Lawrence Brakmo 
Date: Tue, 13 Jun 2017 11:00:02 -0700

> +SEC("sockops")
> +int bpf_iw(struct __sk_buff *skb)
> +{
> + struct bpf_socket_ops *skops = (struct bpf_socket_ops *) skb;
> + char fmt1[] = "BPF command: %d\n";
> + char fmt2[] = "  Returning %d\n";
> + int op;
> + int rv = 0;
> + int rwnd_init = 40;
> + int iw = 40;
> + int bufsize = 150;
> +
> + // For testing purposes, only execute rest of BPF program
> + // if neither port numberis 55601

Local variable ordering and C++ comments.


Re: [RFC PATCH net-next 11/15] bpf: Sample BPF program to set congestion control

2017-06-13 Thread David Miller
From: Lawrence Brakmo 
Date: Tue, 13 Jun 2017 11:00:00 -0700

> +SEC("sockops")
> +int bpf_cong(struct __sk_buff *skb)
> +{
> + struct bpf_socket_ops *skops = (struct bpf_socket_ops *) skb;
> + char fmt1[] = "BPF command: %d\n";
> + char fmt2[] = "  Returning %d\n";
> + int op;
> + int rv = 0;
> + char cong[] = "dctcp";
> +
> + // For testing purposes, only execute rest of BPF program
> + // if neither port numberis 55601

Local variable ordering and C++ comments.


Re: [PATCH] Add printk for bonding module packets_per_slave parameter

2017-06-13 Thread kbuild test robot
Hi Michael,

[auto build test WARNING on net-next/master]
[also build test WARNING on v4.12-rc5 next-20170613]
[if your patch is applied to the wrong git tree, please drop us a note to help 
improve the system]

url:
https://github.com/0day-ci/linux/commits/Michael-Dilmore/Add-printk-for-bonding-module-packets_per_slave-parameter/20170614-045412
config: i386-randconfig-x014-06122022 (attached as .config)
compiler: gcc-6 (Debian 6.2.0-3) 6.2.0 20160901
reproduce:
# save the attached .config to linux build tree
make ARCH=i386 

All warnings (new ones prefixed by >>):

   drivers/net//bonding/bond_options.c: In function 'bond_option_pps_set':
>> drivers/net//bonding/bond_options.c:1259:56: warning: format '%d' expects 
>> argument of type 'int', but argument 3 has type 'u64 {aka const long long 
>> unsigned int}' [-Wformat=]
 netdev_info(bond->dev, "Setting packets per slave to %d\n",
   ^

vim +1259 drivers/net//bonding/bond_options.c

  1243  bond_set_carrier(bond);
  1244  
  1245  return 0;
  1246  }
  1247  
  1248  static int bond_option_lp_interval_set(struct bonding *bond,
  1249 const struct bond_opt_value 
*newval)
  1250  {
  1251  bond->params.lp_interval = newval->value;
  1252  
  1253  return 0;
  1254  }
  1255  
  1256  static int bond_option_pps_set(struct bonding *bond,
  1257 const struct bond_opt_value *newval)
  1258  {
> 1259  netdev_info(bond->dev, "Setting packets per slave to %d\n",
  1260  newval->value);
  1261  bond->params.packets_per_slave = newval->value;
  1262  if (newval->value > 0) {
  1263  bond->params.reciprocal_packets_per_slave =
  1264  reciprocal_value(newval->value);
  1265  } else {
  1266  /* reciprocal_packets_per_slave is unused if
  1267   * packets_per_slave is 0 or 1, just initialize it

---
0-DAY kernel test infrastructureOpen Source Technology Center
https://lists.01.org/pipermail/kbuild-all   Intel Corporation


.config.gz
Description: application/gzip


Re: [RFC PATCH net-next 10/15] bpf: Add support for changing congestion control

2017-06-13 Thread David Miller
From: Lawrence Brakmo 
Date: Tue, 13 Jun 2017 10:59:59 -0700

> @@ -2698,8 +2698,15 @@ BPF_CALL_5(bpf_setsockopt, struct bpf_socket_ops_kern 
> *, bpf_socket,
>   }
>   } else if (level == SOL_TCP &&
>  bpf_socket->sk->sk_prot->setsockopt == tcp_setsockopt) {
> - // Place holder
> - ret = -EINVAL;

I missed these C++ comments in an earlier patch, definitely don't use
them in kernel code.

Thanks.


Re: [RFC PATCH net-next 09/15] bpf: Sample BPF program to set buffer sizes

2017-06-13 Thread David Miller
From: Lawrence Brakmo 
Date: Tue, 13 Jun 2017 10:59:58 -0700

> diff --git a/samples/bpf/tcp_bufs_kern.c b/samples/bpf/tcp_bufs_kern.c
> new file mode 100644
> index 000..a407b73
> --- /dev/null
> +++ b/samples/bpf/tcp_bufs_kern.c
...
> +SEC("sockops")
> +int bpf_bufs(struct __sk_buff *skb)
> +{
> + struct bpf_socket_ops *skops = (struct bpf_socket_ops *) skb;
> + char fmt1[] = "BPF command: %d\n";
> + char fmt2[] = "  Returning %d\n";
> + int op;
> + int rv = 0;
> + int rwnd_init = 40;
> + int bufsize = 150;
> +
> + // For testing purposes, only execute rest of BPF program
> + // if neither port numberis 55601

Local variable ordering and C++ comments.

Thanks.


Re: [PATCH nf-next] netns: add and use net_ns_barrier

2017-06-13 Thread Cong Wang
On Tue, Jun 13, 2017 at 11:07 AM, Florian Westphal  wrote:
> Historically it wasn't needed because we just clear out the helper area
> in the affected conntracks (i.e, future packets are not inspected by
> the helper anymore).
>
> When conntracks were made per-netns this problem was added as we're not
> guaranteed to see all net namespace because module_exit and netns cleanup
> can run concurrently.
>
> We can still use the "old" model if we guarantee that we wait for
> netns cleanup to finish (which is what this patch does).
>
> The alternative, as you pointed out, is to take a module reference for
> each conntrack that uses the helper (and put again when connection is
> destroyed).

Yeah, this is exactly what I am suggesting and I fully expect this could
need more work than this barrier.

>
> I don't really care that much except that if we go for the latter
> solution users cannot "just rmmod" the module anymore but might have
> to manually remove the affected connections first.

This is not bad because the module is indeed being used in this scenario
so EBUSY is expected, or do we need to guarantee conntrack modules
are not held by existing connections?


Re: [RFC PATCH net-next 07/15] bpf: Add setsockopt helper function to bpf

2017-06-13 Thread David Miller
From: Lawrence Brakmo 
Date: Tue, 13 Jun 2017 10:59:56 -0700

> +BPF_CALL_5(bpf_setsockopt, struct bpf_socket_ops_kern *, bpf_socket,
> +int, level, int, optname, char *, optval, int, optlen)
> +{
> + int val;
> + int ret = 0;
> + struct sock *sk = bpf_socket->sk;

Longest to shortest line for variable declarations please.

Also, throughout your submission make sure you indent multi-line
function declarations and definitions properly.  It needs to be:

return_type function_name(type1 arg1, type2 arg2, type3 arg3,
  type4 arg4, type5 arg5)

such that "type4 arg4" starts precisely at the first column after
the openning parenthesis of the first line.  You must use the
appropriate number of TAB then SPACE characters necessary to
achieve this.

Thank you.


Re: [PATCH net-next 6/9] net: hns3: Add MDIO support to HNS3 Ethernet driver for hip08 SoC

2017-06-13 Thread Andrew Lunn
> You are correct is_c45 should not be derived from the type of PHY like
> it is being done here. I have changed this code and now we are getting this
> information from the IMP(Integrated Management Processor) which handles
> the NIC commands and also maintains Ethernet specific configuration.

Florian

With c22, registering the MDIO bus is enough to cause all c22
addresses to be probed and the PHYs found. If you are not using device
tree, you can then use phy_find_first() to get the first phy on the
bus.

As far as i remember, this does not work for c45. mdiobus_scan() is
only looking for c22 PHYs. Maybe we should be making mdiobus_scan()
look first for a c45 and then try c22?

 Andrew


Re: [RFC PATCH net-next 05/15] bpf: Support for setting initial receive window

2017-06-13 Thread David Miller
From: Lawrence Brakmo 
Date: Tue, 13 Jun 2017 10:59:54 -0700

> diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
> index d0642df..a0032ea 100644
> --- a/net/ipv4/tcp_minisocks.c
> +++ b/net/ipv4/tcp_minisocks.c
> @@ -352,6 +352,7 @@ void tcp_openreq_init_rwin(struct request_sock *req,
>   u32 window_clamp;
>   __u8 rcv_wscale;
>   int mss;
> + u32 rcv_wnd;

Please order local variables from longest to shortest line.

 ...
> diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c
> index 503e478..972a985 100644
> --- a/net/ipv4/tcp_output.c
> +++ b/net/ipv4/tcp_output.c
> @@ -3267,6 +3267,7 @@ static void tcp_connect_init(struct sock *sk)
>   const struct dst_entry *dst = __sk_dst_get(sk);
>   struct tcp_sock *tp = tcp_sk(sk);
>   __u8 rcv_wscale;
> + u32 rcv_wnd;

Likewise.


Re: [RFC PATCH net-next 06/15] bpf: Sample bpf program to set initial window

2017-06-13 Thread David Miller
From: Lawrence Brakmo 
Date: Tue, 13 Jun 2017 10:59:55 -0700

> +SEC("sockops")
> +int bpf_rwnd(struct __sk_buff *skb)
> +{
> + struct bpf_socket_ops *skops = (struct bpf_socket_ops *) skb;
> + char fmt1[] = "BPF command: %d\n";
> + char fmt2[] = "  Returning %d\n";
> + int op;
> + int rv = -1;

Longest to shortest line for local variable declarations please.

> +
> + // For testing purposes, only execute rest of BPF program
> + // if neither port numberis 55601

Again, please use non-C++ comments.

Thank you.


Re: [RFC PATCH net-next 04/15] bpf: Sample bpf program to set SYN/SYN-ACK RTOs

2017-06-13 Thread David Miller
From: Lawrence Brakmo 
Date: Tue, 13 Jun 2017 10:59:53 -0700

> +
> + // Check for TIMEOUT_INIT operation and IPv6 addresses
> + if (op == BPF_SOCKET_OPS_TIMEOUT_INIT &&
> + skops->family == AF_INET6) {
> +
> + // If the first 5.5 bytes of the IPv6 address are the same
> + // then both hosts are in the same datacenter
> + // so use an RTO of 10ms
> + if (skops->local_ip6[0] == skops->remote_ip6[0] &&
> + (skops->local_ip6[1] & 0xfff0) ==
> + (skops->remote_ip6[1] & 0xfff0))
> + rv = 10;
> + }

I know this is just a sample program, but please do not use C++ comments
in C code.

Thank you.


Re: [RFC PATCH net-next 01/15] net: BPF support for socket ops

2017-06-13 Thread David Miller
From: Lawrence Brakmo 
Date: Tue, 13 Jun 2017 10:59:50 -0700

> diff --git a/include/linux/filter.h b/include/linux/filter.h
> index a20ba40..8f69b8b 100644
> --- a/include/linux/filter.h
> +++ b/include/linux/filter.h
> @@ -899,4 +899,14 @@ static inline int bpf_tell_extensions(void)
>   return SKF_AD_MAX;
>  }
>  
> +struct bpf_socket_ops_kern {
> + struct  sock *sk;
> + __u32   is_req_sock:1;
> + __u32   op;
> + union {
> + __u32 reply;
> + __u32 replylong[4];
> + };
> +};
> +
>  #endif /* __LINUX_FILTER_H__ */

In non-UAPI headers, "u32", "u16", "u8", etc. without leading underscores
shoudl be used.


[PATCH v2 net-next 8/9] bpf: nfp: Report bpf_prog ID during XDP_QUERY_PROG

2017-06-13 Thread Martin KaFai Lau
Add support to nfp to report bpf_prog ID during XDP_QUERY_PROG.

Signed-off-by: Martin KaFai Lau 
Cc: Jakub Kicinski 
Acked-by: Alexei Starovoitov 
Acked-by: Daniel Borkmann 
---
 drivers/net/ethernet/netronome/nfp/nfp_net_common.c | 14 --
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/netronome/nfp/nfp_net_common.c 
b/drivers/net/ethernet/netronome/nfp/nfp_net_common.c
index 49d1756d6a8e..272354fb0f13 100644
--- a/drivers/net/ethernet/netronome/nfp/nfp_net_common.c
+++ b/drivers/net/ethernet/netronome/nfp/nfp_net_common.c
@@ -3254,9 +3254,19 @@ static int nfp_net_xdp(struct net_device *netdev, struct 
netdev_xdp *xdp)
switch (xdp->command) {
case XDP_SETUP_PROG:
return nfp_net_xdp_setup(nn, xdp);
-   case XDP_QUERY_PROG:
-   xdp->prog_attached = !!nn->dp.xdp_prog;
+   case XDP_QUERY_PROG: {
+   const struct bpf_prog *xdp_prog;
+
+   xdp_prog = nn->dp.xdp_prog;
+   if (xdp_prog) {
+   xdp->prog_id = xdp_prog->aux->id;
+   xdp->prog_attached = true;
+   } else {
+   xdp->prog_id = 0;
+   xdp->prog_attached = false;
+   }
return 0;
+   }
default:
return -EINVAL;
}
-- 
2.9.3



[PATCH v2 net-next 3/9] bpf: mlx5e: Report bpf_prog ID during XDP_QUERY_PROG

2017-06-13 Thread Martin KaFai Lau
Add support to mlx5e to report bpf_prog ID during XDP_QUERY_PROG.

Signed-off-by: Martin KaFai Lau 
Cc: Tariq Toukan 
Cc: Saeed Mahameed 
Acked-by: Alexei Starovoitov 
Acked-by: Daniel Borkmann 
Acked-by: Saeed Mahameed 
---
 drivers/net/ethernet/mellanox/mlx5/core/en_main.c | 15 ---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c 
b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c
index 5afec0f4a658..1efbb1e1f78f 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c
@@ -3599,11 +3599,19 @@ static int mlx5e_xdp_set(struct net_device *netdev, 
struct bpf_prog *prog)
return err;
 }
 
-static bool mlx5e_xdp_attached(struct net_device *dev)
+static u32 mlx5e_xdp_query(struct net_device *dev)
 {
+   const struct bpf_prog *xdp_prog;
struct mlx5e_priv *priv = netdev_priv(dev);
+   u32 prog_id = 0;
 
-   return !!priv->channels.params.xdp_prog;
+   mutex_lock(>state_lock);
+   xdp_prog = priv->channels.params.xdp_prog;
+   if (xdp_prog)
+   prog_id = xdp_prog->aux->id;
+   mutex_unlock(>state_lock);
+
+   return prog_id;
 }
 
 static int mlx5e_xdp(struct net_device *dev, struct netdev_xdp *xdp)
@@ -3612,7 +3620,8 @@ static int mlx5e_xdp(struct net_device *dev, struct 
netdev_xdp *xdp)
case XDP_SETUP_PROG:
return mlx5e_xdp_set(dev, xdp->prog);
case XDP_QUERY_PROG:
-   xdp->prog_attached = mlx5e_xdp_attached(dev);
+   xdp->prog_id = mlx5e_xdp_query(dev);
+   xdp->prog_attached = !!xdp->prog_id;
return 0;
default:
return -EINVAL;
-- 
2.9.3



[PATCH v2 net-next 5/9] bpf: bnxt: Report bpf_prog ID during XDP_QUERY_PROG

2017-06-13 Thread Martin KaFai Lau
Add support to bnxt to report bpf_prog ID during XDP_QUERY_PROG.

Signed-off-by: Martin KaFai Lau 
Cc: Michael Chan 
Acked-by: Alexei Starovoitov 
Acked-by: Daniel Borkmann 
---
 drivers/net/ethernet/broadcom/bnxt/bnxt_xdp.c | 14 --
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt_xdp.c 
b/drivers/net/ethernet/broadcom/bnxt/bnxt_xdp.c
index 8ce793a0d030..841bc9df65b1 100644
--- a/drivers/net/ethernet/broadcom/bnxt/bnxt_xdp.c
+++ b/drivers/net/ethernet/broadcom/bnxt/bnxt_xdp.c
@@ -216,10 +216,20 @@ int bnxt_xdp(struct net_device *dev, struct netdev_xdp 
*xdp)
case XDP_SETUP_PROG:
rc = bnxt_xdp_set(bp, xdp->prog);
break;
-   case XDP_QUERY_PROG:
-   xdp->prog_attached = !!bp->xdp_prog;
+   case XDP_QUERY_PROG: {
+   const struct bpf_prog *xdp_prog;
+
+   xdp_prog = bp->xdp_prog;
+   if (xdp_prog) {
+   xdp->prog_id = xdp_prog->aux->id;
+   xdp->prog_attached = true;
+   } else {
+   xdp->prog_id = 0;
+   xdp->prog_attached = false;
+   }
rc = 0;
break;
+   }
default:
rc = -EINVAL;
break;
-- 
2.9.3



[PATCH v2 net-next 9/9] bpf: qede: Report bpf_prog ID during XDP_QUERY_PROG

2017-06-13 Thread Martin KaFai Lau
Add support to qede to report bpf_prog ID during XDP_QUERY_PROG.

Signed-off-by: Martin KaFai Lau 
Cc: Mintz Yuval 
Acked-by: Alexei Starovoitov 
Acked-by: Daniel Borkmann 
---
 drivers/net/ethernet/qlogic/qede/qede_filter.c | 14 --
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/qlogic/qede/qede_filter.c 
b/drivers/net/ethernet/qlogic/qede/qede_filter.c
index 13955a3bd3b3..d91555ae2936 100644
--- a/drivers/net/ethernet/qlogic/qede/qede_filter.c
+++ b/drivers/net/ethernet/qlogic/qede/qede_filter.c
@@ -1035,9 +1035,19 @@ int qede_xdp(struct net_device *dev, struct netdev_xdp 
*xdp)
switch (xdp->command) {
case XDP_SETUP_PROG:
return qede_xdp_set(edev, xdp->prog);
-   case XDP_QUERY_PROG:
-   xdp->prog_attached = !!edev->xdp_prog;
+   case XDP_QUERY_PROG: {
+   const struct bpf_prog *xdp_prog;
+
+   xdp_prog = edev->xdp_prog;
+   if (xdp_prog) {
+   xdp->prog_id = xdp_prog->aux->id;
+   xdp->prog_attached = true;
+   } else {
+   xdp->prog_id = 0;
+   xdp->prog_attached = false;
+   }
return 0;
+   }
default:
return -EINVAL;
}
-- 
2.9.3



[PATCH v2 net-next 1/9] net: Add IFLA_XDP_PROG_ID

2017-06-13 Thread Martin KaFai Lau
Expose prog_id through IFLA_XDP_PROG_ID.  This patch
makes modification to generic_xdp.  The later patches will
modify other xdp-supported drivers.

prog_id is added to struct net_dev_xdp.

iproute2 patch will be followed. Here is how the 'ip link'
will look like:
> ip link show eth0
3: eth0:  mtu 1500 xdp(prog_id:1) qdisc 
fq_codel state UP mode DEFAULT group default qlen 1000

Signed-off-by: Martin KaFai Lau 
Acked-by: Alexei Starovoitov 
Acked-by: Daniel Borkmann 
---
 include/linux/netdevice.h|  7 +--
 include/uapi/linux/if_link.h |  1 +
 net/core/dev.c   | 24 
 net/core/rtnetlink.c | 27 +--
 4 files changed, 43 insertions(+), 16 deletions(-)

diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index 524c7776ce96..6dc242f29eac 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -824,7 +824,10 @@ struct netdev_xdp {
struct netlink_ext_ack *extack;
};
/* XDP_QUERY_PROG */
-   bool prog_attached;
+   struct {
+   bool prog_attached;
+   u32 prog_id;
+   };
};
 };
 
@@ -3302,7 +3305,7 @@ struct sk_buff *dev_hard_start_xmit(struct sk_buff *skb, 
struct net_device *dev,
 typedef int (*xdp_op_t)(struct net_device *dev, struct netdev_xdp *xdp);
 int dev_change_xdp_fd(struct net_device *dev, struct netlink_ext_ack *extack,
  int fd, u32 flags);
-bool __dev_xdp_attached(struct net_device *dev, xdp_op_t xdp_op);
+bool __dev_xdp_attached(struct net_device *dev, xdp_op_t xdp_op, u32 *prog_id);
 
 int __dev_forward_skb(struct net_device *dev, struct sk_buff *skb);
 int dev_forward_skb(struct net_device *dev, struct sk_buff *skb);
diff --git a/include/uapi/linux/if_link.h b/include/uapi/linux/if_link.h
index 8ed679fe603f..dd88375a6580 100644
--- a/include/uapi/linux/if_link.h
+++ b/include/uapi/linux/if_link.h
@@ -907,6 +907,7 @@ enum {
IFLA_XDP_FD,
IFLA_XDP_ATTACHED,
IFLA_XDP_FLAGS,
+   IFLA_XDP_PROG_ID,
__IFLA_XDP_MAX,
 };
 
diff --git a/net/core/dev.c b/net/core/dev.c
index 8f72f4a9c6ac..aa2dcb81f320 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -4341,13 +4341,12 @@ static struct static_key generic_xdp_needed 
__read_mostly;
 
 static int generic_xdp_install(struct net_device *dev, struct netdev_xdp *xdp)
 {
+   struct bpf_prog *old = rtnl_dereference(dev->xdp_prog);
struct bpf_prog *new = xdp->prog;
int ret = 0;
 
switch (xdp->command) {
-   case XDP_SETUP_PROG: {
-   struct bpf_prog *old = rtnl_dereference(dev->xdp_prog);
-
+   case XDP_SETUP_PROG:
rcu_assign_pointer(dev->xdp_prog, new);
if (old)
bpf_prog_put(old);
@@ -4359,10 +4358,15 @@ static int generic_xdp_install(struct net_device *dev, 
struct netdev_xdp *xdp)
dev_disable_lro(dev);
}
break;
-   }
 
case XDP_QUERY_PROG:
-   xdp->prog_attached = !!rcu_access_pointer(dev->xdp_prog);
+   if (old) {
+   xdp->prog_attached = true;
+   xdp->prog_id = old->aux->id;
+   } else {
+   xdp->prog_attached = false;
+   xdp->prog_id = 0;
+   }
break;
 
default:
@@ -6930,7 +6934,8 @@ int dev_change_proto_down(struct net_device *dev, bool 
proto_down)
 }
 EXPORT_SYMBOL(dev_change_proto_down);
 
-bool __dev_xdp_attached(struct net_device *dev, xdp_op_t xdp_op)
+bool __dev_xdp_attached(struct net_device *dev, xdp_op_t xdp_op,
+   u32 *prog_id)
 {
struct netdev_xdp xdp;
 
@@ -6939,6 +6944,9 @@ bool __dev_xdp_attached(struct net_device *dev, xdp_op_t 
xdp_op)
 
/* Query must always succeed. */
WARN_ON(xdp_op(dev, ) < 0);
+   if (prog_id)
+   *prog_id = xdp.prog_id;
+
return xdp.prog_attached;
 }
 
@@ -6984,10 +6992,10 @@ int dev_change_xdp_fd(struct net_device *dev, struct 
netlink_ext_ack *extack,
xdp_chk = generic_xdp_install;
 
if (fd >= 0) {
-   if (xdp_chk && __dev_xdp_attached(dev, xdp_chk))
+   if (xdp_chk && __dev_xdp_attached(dev, xdp_chk, NULL))
return -EEXIST;
if ((flags & XDP_FLAGS_UPDATE_IF_NOEXIST) &&
-   __dev_xdp_attached(dev, xdp_op))
+   __dev_xdp_attached(dev, xdp_op, NULL))
return -EBUSY;
 
prog = bpf_prog_get_type(fd, BPF_PROG_TYPE_XDP);
diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
index 7084f1db2446..f25a53b1fb92 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -39,6 +39,7 @@
 #include 
 #include 

[PATCH v2 net-next 6/9] bpf: thunderx: Report bpf_prog ID during XDP_QUERY_PROG

2017-06-13 Thread Martin KaFai Lau
Add support to thunderx to report bpf_prog ID during XDP_QUERY_PROG.

Signed-off-by: Martin KaFai Lau 
Cc: Sunil Goutham 
Acked-by: Alexei Starovoitov 
Acked-by: Daniel Borkmann 
---
 drivers/net/ethernet/cavium/thunder/nicvf_main.c | 14 --
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/cavium/thunder/nicvf_main.c 
b/drivers/net/ethernet/cavium/thunder/nicvf_main.c
index d6477af88085..77096527ad06 100644
--- a/drivers/net/ethernet/cavium/thunder/nicvf_main.c
+++ b/drivers/net/ethernet/cavium/thunder/nicvf_main.c
@@ -1761,9 +1761,19 @@ static int nicvf_xdp(struct net_device *netdev, struct 
netdev_xdp *xdp)
switch (xdp->command) {
case XDP_SETUP_PROG:
return nicvf_xdp_setup(nic, xdp->prog);
-   case XDP_QUERY_PROG:
-   xdp->prog_attached = !!nic->xdp_prog;
+   case XDP_QUERY_PROG: {
+   const struct bpf_prog *xdp_prog;
+
+   xdp_prog = nic->xdp_prog;
+   if (xdp_prog) {
+   xdp->prog_id = xdp_prog->aux->id;
+   xdp->prog_attached = true;
+   } else {
+   xdp->prog_id = 0;
+   xdp->prog_attached = false;
+   }
return 0;
+   }
default:
return -EINVAL;
}
-- 
2.9.3



[PATCH v2 net-next 7/9] bpf: ixgbe: Report bpf_prog ID during XDP_QUERY_PROG

2017-06-13 Thread Martin KaFai Lau
Add support to ixgbe to report bpf_prog ID during XDP_QUERY_PROG.

Signed-off-by: Martin KaFai Lau 
Cc: Alexander Duyck 
Cc: John Fastabend 
Acked-by: Alexei Starovoitov 
Acked-by: Daniel Borkmann 
---
 drivers/net/ethernet/intel/ixgbe/ixgbe_main.c | 14 --
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c 
b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
index 812319ab77db..37b0e5a741d8 100644
--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
@@ -9799,9 +9799,19 @@ static int ixgbe_xdp(struct net_device *dev, struct 
netdev_xdp *xdp)
switch (xdp->command) {
case XDP_SETUP_PROG:
return ixgbe_xdp_setup(dev, xdp->prog);
-   case XDP_QUERY_PROG:
-   xdp->prog_attached = !!(adapter->xdp_prog);
+   case XDP_QUERY_PROG: {
+   const struct bpf_prog *xdp_prog;
+
+   xdp_prog = adapter->xdp_prog;
+   if (xdp_prog) {
+   xdp->prog_id = xdp_prog->aux->id;
+   xdp->prog_attached = true;
+   } else {
+   xdp->prog_id = 0;
+   xdp->prog_attached = false;
+   }
return 0;
+   }
default:
return -EINVAL;
}
-- 
2.9.3



[PATCH v2 net-next 0/9] bpf: xdp: Report bpf_prog ID in IFLA_XDP

2017-06-13 Thread Martin KaFai Lau
This is the first usage of the new bpf_prog ID.  It is for
reporting the ID of a xdp_prog through netlink.

It rides on the existing IFLA_XDP.  This patch adds IFLA_XDP_PROG_ID
for the bpf_prog ID reporting.

It starts with changing the generic_xdp first.  After that,
the hardware driver is changed one by one.  Jakub Kicinski mentioned
that he will soon introduce XDP_ATTACHED_HW (on top of the existing
XDP_ATTACHED_DRV and XDP_ATTACHED_SKB)
and he is going to reuse the prog_attached for this purpose.
Hence, this patch set keeps the prog_attached even though
!!prog_id also implies there is xdp_prog attached.

I have tested with generic_xdp, mlx4 and mlx5.

v2:
1. Remove READ_ONCE since it is alredy under rtnl lock
2. Keep prog_attached in 'struct netdev_xdp' as
   requested by Jakub Kicinski.  The existing prog_attached
   and the new prog_id are put under a struct for XDP_QUERY_PROG.

Martin KaFai Lau (9):
  net: Add IFLA_XDP_PROG_ID
  bpf: mlx4: Report bpf_prog ID during XDP_QUERY_PROG
  bpf: mlx5e: Report bpf_prog ID during XDP_QUERY_PROG
  bpf: virtio_net: Report bpf_prog ID during XDP_QUERY_PROG
  bpf: bnxt: Report bpf_prog ID during XDP_QUERY_PROG
  bpf: thunderx: Report bpf_prog ID during XDP_QUERY_PROG
  bpf: ixgbe: Report bpf_prog ID during XDP_QUERY_PROG
  bpf: nfp: Report bpf_prog ID during XDP_QUERY_PROG
  bpf: qede: Report bpf_prog ID during XDP_QUERY_PROG

 drivers/net/ethernet/broadcom/bnxt/bnxt_xdp.c  | 14 +--
 drivers/net/ethernet/cavium/thunder/nicvf_main.c   | 14 +--
 drivers/net/ethernet/intel/ixgbe/ixgbe_main.c  | 14 +--
 drivers/net/ethernet/mellanox/mlx4/en_netdev.c | 21 ++---
 drivers/net/ethernet/mellanox/mlx5/core/en_main.c  | 15 +---
 .../net/ethernet/netronome/nfp/nfp_net_common.c| 14 +--
 drivers/net/ethernet/qlogic/qede/qede_filter.c | 14 +--
 drivers/net/virtio_net.c   | 13 +++
 include/linux/netdevice.h  |  7 --
 include/uapi/linux/if_link.h   |  1 +
 net/core/dev.c | 24 ---
 net/core/rtnetlink.c   | 27 +-
 12 files changed, 141 insertions(+), 37 deletions(-)

-- 
2.9.3



[PATCH v2 net-next 4/9] bpf: virtio_net: Report bpf_prog ID during XDP_QUERY_PROG

2017-06-13 Thread Martin KaFai Lau
Add support to virtio_net to report bpf_prog ID during XDP_QUERY_PROG.

Signed-off-by: Martin KaFai Lau 
Cc: John Fastabend 
Cc: Jason Wang 
Acked-by: Alexei Starovoitov 
Acked-by: Daniel Borkmann 
---
 drivers/net/virtio_net.c | 13 -
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index 1f8c15cb63b0..deecd24f2db8 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -1955,16 +1955,18 @@ static int virtnet_xdp_set(struct net_device *dev, 
struct bpf_prog *prog,
return err;
 }
 
-static bool virtnet_xdp_query(struct net_device *dev)
+static u32 virtnet_xdp_query(struct net_device *dev)
 {
+   const struct bpf_prog *xdp_prog;
struct virtnet_info *vi = netdev_priv(dev);
int i;
 
for (i = 0; i < vi->max_queue_pairs; i++) {
-   if (vi->rq[i].xdp_prog)
-   return true;
+   xdp_prog = rtnl_dereference(vi->rq[i].xdp_prog);
+   if (xdp_prog)
+   return xdp_prog->aux->id;
}
-   return false;
+   return 0;
 }
 
 static int virtnet_xdp(struct net_device *dev, struct netdev_xdp *xdp)
@@ -1973,7 +1975,8 @@ static int virtnet_xdp(struct net_device *dev, struct 
netdev_xdp *xdp)
case XDP_SETUP_PROG:
return virtnet_xdp_set(dev, xdp->prog, xdp->extack);
case XDP_QUERY_PROG:
-   xdp->prog_attached = virtnet_xdp_query(dev);
+   xdp->prog_id = virtnet_xdp_query(dev);
+   xdp->prog_attached = !!xdp->prog_id;
return 0;
default:
return -EINVAL;
-- 
2.9.3



[PATCH v2 net-next 2/9] bpf: mlx4: Report bpf_prog ID during XDP_QUERY_PROG

2017-06-13 Thread Martin KaFai Lau
Add support to mlx4 to report bpf_prog ID during XDP_QUERY_PROG.

Signed-off-by: Martin KaFai Lau 
Cc: Tariq Toukan 
Cc: Saeed Mahameed 
Acked-by: Alexei Starovoitov 
Acked-by: Daniel Borkmann 
---
 drivers/net/ethernet/mellanox/mlx4/en_netdev.c | 21 ++---
 1 file changed, 18 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx4/en_netdev.c 
b/drivers/net/ethernet/mellanox/mlx4/en_netdev.c
index c1de75fc399a..ba6ecdd505b6 100644
--- a/drivers/net/ethernet/mellanox/mlx4/en_netdev.c
+++ b/drivers/net/ethernet/mellanox/mlx4/en_netdev.c
@@ -2821,11 +2821,25 @@ static int mlx4_xdp_set(struct net_device *dev, struct 
bpf_prog *prog)
return err;
 }
 
-static bool mlx4_xdp_attached(struct net_device *dev)
+static u32 mlx4_xdp_query(struct net_device *dev)
 {
+   const struct bpf_prog *xdp_prog;
struct mlx4_en_priv *priv = netdev_priv(dev);
+   struct mlx4_en_dev *mdev = priv->mdev;
+   u32 prog_id = 0;
+
+   if (!priv->tx_ring_num[TX_XDP])
+   return prog_id;
+
+   mutex_lock(>state_lock);
+   xdp_prog = rcu_dereference_protected(
+   priv->rx_ring[0]->xdp_prog,
+   lockdep_is_held(>state_lock));
+   if (xdp_prog)
+   prog_id = xdp_prog->aux->id;
+   mutex_unlock(>state_lock);
 
-   return !!priv->tx_ring_num[TX_XDP];
+   return prog_id;
 }
 
 static int mlx4_xdp(struct net_device *dev, struct netdev_xdp *xdp)
@@ -2834,7 +2848,8 @@ static int mlx4_xdp(struct net_device *dev, struct 
netdev_xdp *xdp)
case XDP_SETUP_PROG:
return mlx4_xdp_set(dev, xdp->prog);
case XDP_QUERY_PROG:
-   xdp->prog_attached = mlx4_xdp_attached(dev);
+   xdp->prog_id = mlx4_xdp_query(dev);
+   xdp->prog_attached = !!xdp->prog_id;
return 0;
default:
return -EINVAL;
-- 
2.9.3



Re: [PATCH net-next] networking: use skb_put_zero()

2017-06-13 Thread David Miller

These are bogus reports I think.

Johannes's changes depends upon the wireless GIT tree I pulled in
right before I applied his patch.


  1   2   3   >