Fw: [Bug 196595] New: Regression IGMP sysctl init values if not IP_MULTICAST

2017-08-05 Thread Stephen Hemminger


Begin forwarded message:

Date: Sat, 05 Aug 2017 23:57:48 +
From: bugzilla-dae...@bugzilla.kernel.org
To: step...@networkplumber.org
Subject: [Bug 196595] New: Regression IGMP sysctl init values if not 
IP_MULTICAST


https://bugzilla.kernel.org/show_bug.cgi?id=196595

Bug ID: 196595
   Summary: Regression IGMP sysctl init values if not IP_MULTICAST
   Product: Networking
   Version: 2.5
Kernel Version: 4.5 - 4.12
  Hardware: All
OS: Linux
  Tree: Mainline
Status: NEW
  Severity: normal
  Priority: P1
 Component: IPV4
  Assignee: step...@networkplumber.org
  Reporter: vmlinuz...@gmail.com
Regression: No

I just upgraded from 4.4.x to 4.12.x and detected that igmp related settings
are not set to default values (1, 20, 10):

net.ipv4.igmp_link_local_mcast_reports = 0
net.ipv4.igmp_max_memberships = 0
net.ipv4.igmp_max_msf = 0

This is fixed if I enable IP_MULTICAST. Looks like a regression since some
changes made to "Namespaceify" commit dcd87999d415d39cf2ae510bfed6b8206d778e1c 
and related commits.

-- 
You are receiving this mail because:
You are the assignee for the bug.


[PATCH net-next v2 3/3] net: dsa: remove useless args of dsa_slave_create

2017-08-05 Thread Vivien Didelot
dsa_slave_create currently takes 4 arguments while it only needs the
related dsa_port and its name. Remove all other arguments.

Signed-off-by: Vivien Didelot 
---
 net/dsa/dsa2.c |  2 +-
 net/dsa/dsa_priv.h |  3 +--
 net/dsa/legacy.c   |  2 +-
 net/dsa/slave.c| 14 +++---
 4 files changed, 10 insertions(+), 11 deletions(-)

diff --git a/net/dsa/dsa2.c b/net/dsa/dsa2.c
index 2a0120493cf1..cceaa4dd9f53 100644
--- a/net/dsa/dsa2.c
+++ b/net/dsa/dsa2.c
@@ -275,7 +275,7 @@ static int dsa_user_port_apply(struct dsa_port *port)
if (!name)
name = "eth%d";
 
-   err = dsa_slave_create(ds, ds->dev, port->index, name);
+   err = dsa_slave_create(port, name);
if (err) {
dev_warn(ds->dev, "Failed to create slave %d: %d\n",
 port->index, err);
diff --git a/net/dsa/dsa_priv.h b/net/dsa/dsa_priv.h
index 46851c91c7fe..73426f9c2cca 100644
--- a/net/dsa/dsa_priv.h
+++ b/net/dsa/dsa_priv.h
@@ -148,8 +148,7 @@ int dsa_port_vlan_dump(struct dsa_port *dp,
 extern const struct dsa_device_ops notag_netdev_ops;
 void dsa_slave_mii_bus_init(struct dsa_switch *ds);
 void dsa_cpu_port_ethtool_init(struct ethtool_ops *ops);
-int dsa_slave_create(struct dsa_switch *ds, struct device *parent,
-int port, const char *name);
+int dsa_slave_create(struct dsa_port *port, const char *name);
 void dsa_slave_destroy(struct net_device *slave_dev);
 int dsa_slave_suspend(struct net_device *slave_dev);
 int dsa_slave_resume(struct net_device *slave_dev);
diff --git a/net/dsa/legacy.c b/net/dsa/legacy.c
index 903e8d70c792..612acf16d573 100644
--- a/net/dsa/legacy.c
+++ b/net/dsa/legacy.c
@@ -194,7 +194,7 @@ static int dsa_switch_setup_one(struct dsa_switch *ds,
if (!(ds->enabled_port_mask & (1 << i)))
continue;
 
-   ret = dsa_slave_create(ds, ds->dev, i, cd->port_names[i]);
+   ret = dsa_slave_create(>ports[i], cd->port_names[i]);
if (ret < 0)
netdev_err(master, "[%d]: can't create dsa slave device 
for port %d(%s): %d\n",
   index, i, cd->port_names[i], ret);
diff --git a/net/dsa/slave.c b/net/dsa/slave.c
index 83252e8426d7..8e25ca412672 100644
--- a/net/dsa/slave.c
+++ b/net/dsa/slave.c
@@ -1165,9 +1165,9 @@ int dsa_slave_resume(struct net_device *slave_dev)
return 0;
 }
 
-int dsa_slave_create(struct dsa_switch *ds, struct device *parent,
-int port, const char *name)
+int dsa_slave_create(struct dsa_port *port, const char *name)
 {
+   struct dsa_switch *ds = port->ds;
struct dsa_switch_tree *dst = ds->dst;
struct net_device *master;
struct net_device *slave_dev;
@@ -1197,13 +1197,13 @@ int dsa_slave_create(struct dsa_switch *ds, struct 
device *parent,
netdev_for_each_tx_queue(slave_dev, dsa_slave_set_lockdep_class_one,
 NULL);
 
-   SET_NETDEV_DEV(slave_dev, parent);
-   slave_dev->dev.of_node = ds->ports[port].dn;
+   SET_NETDEV_DEV(slave_dev, port->ds->dev);
+   slave_dev->dev.of_node = port->dn;
slave_dev->vlan_features = master->vlan_features;
 
p = netdev_priv(slave_dev);
u64_stats_init(>stats64.syncp);
-   p->dp = >ports[port];
+   p->dp = port;
INIT_LIST_HEAD(>mall_tc_list);
p->xmit = dst->tag_ops->xmit;
 
@@ -1211,12 +1211,12 @@ int dsa_slave_create(struct dsa_switch *ds, struct 
device *parent,
p->old_link = -1;
p->old_duplex = -1;
 
-   ds->ports[port].netdev = slave_dev;
+   port->netdev = slave_dev;
ret = register_netdev(slave_dev);
if (ret) {
netdev_err(master, "error %d registering interface %s\n",
   ret, slave_dev->name);
-   ds->ports[port].netdev = NULL;
+   port->netdev = NULL;
free_netdev(slave_dev);
return ret;
}
-- 
2.13.3



[PATCH net-next v2 0/3] net: dsa: remove useless arguments

2017-08-05 Thread Vivien Didelot
Several DSA core setup functions take many arguments, mostly because of
the legacy code. This patch series removes the useless args of these
functions, where either the dsa_switch or dsa_port argument is enough.

Changes in v2:
  - ds->dev is already assigned by dsa_switch_alloc

Vivien Didelot (3):
  net: dsa: remove useless argument in legacy setup
  net: dsa: remove useless args of dsa_cpu_dsa_setup
  net: dsa: remove useless args of dsa_slave_create

 net/dsa/dsa.c  | 10 +-
 net/dsa/dsa2.c |  6 +++---
 net/dsa/dsa_priv.h |  6 ++
 net/dsa/legacy.c   | 18 --
 net/dsa/slave.c| 14 +++---
 5 files changed, 25 insertions(+), 29 deletions(-)

-- 
2.13.3



[PATCH net-next v2 1/3] net: dsa: remove useless argument in legacy setup

2017-08-05 Thread Vivien Didelot
dsa_switch_alloc() already assigns ds-dev, which can be used in
dsa_switch_setup_one and dsa_cpu_dsa_setups instead of requiring an
additional struct device argument.

Signed-off-by: Vivien Didelot 
---
 net/dsa/legacy.c | 16 
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/net/dsa/legacy.c b/net/dsa/legacy.c
index 1d7a3282f2a7..fa162030a69c 100644
--- a/net/dsa/legacy.c
+++ b/net/dsa/legacy.c
@@ -78,7 +78,7 @@ dsa_switch_probe(struct device *parent, struct device 
*host_dev, int sw_addr,
 }
 
 /* basic switch operations **/
-static int dsa_cpu_dsa_setups(struct dsa_switch *ds, struct device *dev)
+static int dsa_cpu_dsa_setups(struct dsa_switch *ds)
 {
struct dsa_port *dport;
int ret, port;
@@ -88,15 +88,15 @@ static int dsa_cpu_dsa_setups(struct dsa_switch *ds, struct 
device *dev)
continue;
 
dport = >ports[port];
-   ret = dsa_cpu_dsa_setup(ds, dev, dport, port);
+   ret = dsa_cpu_dsa_setup(ds, ds->dev, dport, port);
if (ret)
return ret;
}
return 0;
 }
 
-static int dsa_switch_setup_one(struct dsa_switch *ds, struct net_device 
*master,
-   struct device *parent)
+static int dsa_switch_setup_one(struct dsa_switch *ds,
+   struct net_device *master)
 {
const struct dsa_switch_ops *ops = ds->ops;
struct dsa_switch_tree *dst = ds->dst;
@@ -176,7 +176,7 @@ static int dsa_switch_setup_one(struct dsa_switch *ds, 
struct net_device *master
}
 
if (!ds->slave_mii_bus && ops->phy_read) {
-   ds->slave_mii_bus = devm_mdiobus_alloc(parent);
+   ds->slave_mii_bus = devm_mdiobus_alloc(ds->dev);
if (!ds->slave_mii_bus)
return -ENOMEM;
dsa_slave_mii_bus_init(ds);
@@ -196,14 +196,14 @@ static int dsa_switch_setup_one(struct dsa_switch *ds, 
struct net_device *master
if (!(ds->enabled_port_mask & (1 << i)))
continue;
 
-   ret = dsa_slave_create(ds, parent, i, cd->port_names[i]);
+   ret = dsa_slave_create(ds, ds->dev, i, cd->port_names[i]);
if (ret < 0)
netdev_err(master, "[%d]: can't create dsa slave device 
for port %d(%s): %d\n",
   index, i, cd->port_names[i], ret);
}
 
/* Perform configuration of the CPU and DSA ports */
-   ret = dsa_cpu_dsa_setups(ds, parent);
+   ret = dsa_cpu_dsa_setups(ds);
if (ret < 0)
netdev_err(master, "[%d] : can't configure CPU and DSA ports\n",
   index);
@@ -252,7 +252,7 @@ dsa_switch_setup(struct dsa_switch_tree *dst, struct 
net_device *master,
ds->ops = ops;
ds->priv = priv;
 
-   ret = dsa_switch_setup_one(ds, master, parent);
+   ret = dsa_switch_setup_one(ds, master);
if (ret)
return ERR_PTR(ret);
 
-- 
2.13.3



[PATCH net-next v2 2/3] net: dsa: remove useless args of dsa_cpu_dsa_setup

2017-08-05 Thread Vivien Didelot
dsa_cpu_dsa_setup currently takes 4 arguments but they are all available
from the dsa_port argument. Remove all others.

Signed-off-by: Vivien Didelot 
---
 net/dsa/dsa.c  | 10 +-
 net/dsa/dsa2.c |  4 ++--
 net/dsa/dsa_priv.h |  3 +--
 net/dsa/legacy.c   |  4 +---
 4 files changed, 9 insertions(+), 12 deletions(-)

diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c
index 0ba842c08dd3..64db6eece3c1 100644
--- a/net/dsa/dsa.c
+++ b/net/dsa/dsa.c
@@ -67,17 +67,17 @@ const struct dsa_device_ops *dsa_device_ops[DSA_TAG_LAST] = 
{
[DSA_TAG_PROTO_NONE] = _ops,
 };
 
-int dsa_cpu_dsa_setup(struct dsa_switch *ds, struct device *dev,
- struct dsa_port *dport, int port)
+int dsa_cpu_dsa_setup(struct dsa_port *port)
 {
-   struct device_node *port_dn = dport->dn;
+   struct device_node *port_dn = port->dn;
+   struct dsa_switch *ds = port->ds;
struct phy_device *phydev;
int ret, mode;
 
if (of_phy_is_fixed_link(port_dn)) {
ret = of_phy_register_fixed_link(port_dn);
if (ret) {
-   dev_err(dev, "failed to register fixed PHY\n");
+   dev_err(ds->dev, "failed to register fixed PHY\n");
return ret;
}
phydev = of_phy_find_device(port_dn);
@@ -90,7 +90,7 @@ int dsa_cpu_dsa_setup(struct dsa_switch *ds, struct device 
*dev,
genphy_config_init(phydev);
genphy_read_status(phydev);
if (ds->ops->adjust_link)
-   ds->ops->adjust_link(ds, port, phydev);
+   ds->ops->adjust_link(ds, port->index, phydev);
 
put_device(>mdio.dev);
}
diff --git a/net/dsa/dsa2.c b/net/dsa/dsa2.c
index c442051d5a55..2a0120493cf1 100644
--- a/net/dsa/dsa2.c
+++ b/net/dsa/dsa2.c
@@ -219,7 +219,7 @@ static int dsa_dsa_port_apply(struct dsa_port *port)
struct dsa_switch *ds = port->ds;
int err;
 
-   err = dsa_cpu_dsa_setup(ds, ds->dev, port, port->index);
+   err = dsa_cpu_dsa_setup(port);
if (err) {
dev_warn(ds->dev, "Failed to setup dsa port %d: %d\n",
 port->index, err);
@@ -243,7 +243,7 @@ static int dsa_cpu_port_apply(struct dsa_port *port)
struct dsa_switch *ds = port->ds;
int err;
 
-   err = dsa_cpu_dsa_setup(ds, ds->dev, port, port->index);
+   err = dsa_cpu_dsa_setup(port);
if (err) {
dev_warn(ds->dev, "Failed to setup cpu port %d: %d\n",
 port->index, err);
diff --git a/net/dsa/dsa_priv.h b/net/dsa/dsa_priv.h
index 7aa0656296c2..46851c91c7fe 100644
--- a/net/dsa/dsa_priv.h
+++ b/net/dsa/dsa_priv.h
@@ -101,8 +101,7 @@ struct dsa_slave_priv {
 };
 
 /* dsa.c */
-int dsa_cpu_dsa_setup(struct dsa_switch *ds, struct device *dev,
- struct dsa_port *dport, int port);
+int dsa_cpu_dsa_setup(struct dsa_port *port);
 void dsa_cpu_dsa_destroy(struct dsa_port *dport);
 const struct dsa_device_ops *dsa_resolve_tag_protocol(int tag_protocol);
 int dsa_cpu_port_ethtool_setup(struct dsa_port *cpu_dp);
diff --git a/net/dsa/legacy.c b/net/dsa/legacy.c
index fa162030a69c..903e8d70c792 100644
--- a/net/dsa/legacy.c
+++ b/net/dsa/legacy.c
@@ -80,15 +80,13 @@ dsa_switch_probe(struct device *parent, struct device 
*host_dev, int sw_addr,
 /* basic switch operations **/
 static int dsa_cpu_dsa_setups(struct dsa_switch *ds)
 {
-   struct dsa_port *dport;
int ret, port;
 
for (port = 0; port < ds->num_ports; port++) {
if (!(dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port)))
continue;
 
-   dport = >ports[port];
-   ret = dsa_cpu_dsa_setup(ds, ds->dev, dport, port);
+   ret = dsa_cpu_dsa_setup(>ports[port]);
if (ret)
return ret;
}
-- 
2.13.3



Re: [PATCH net-next 1/3] net: dsa: assign switch device in legacy code

2017-08-05 Thread Vivien Didelot
Hi Andrew,

Andrew Lunn  writes:

>> @@ -251,8 +251,9 @@ dsa_switch_setup(struct dsa_switch_tree *dst, struct 
>> net_device *master,
>>  ds->cd = cd;
>>  ds->ops = ops;
>>  ds->priv = priv;
>> +ds->dev = parent;
>
> Is this even needed? dsa_switch_alloc() does ds->dev = dev.

You are correct! Respinning.


Thanks,

Vivien


Re: [PATCH] samples/bpf: Fix cross compiler error with bpf sample

2017-08-05 Thread Joel Fernandes
Hi Daniel,


>>>
>>> So the only arch that sets __ARCH_WANT_SYSCALL_DEPRECATED
>>> is score:
>>>
>>>$ git grep -n __ARCH_WANT_SYSCALL_DEPRECATED
>>>arch/score/include/uapi/asm/unistd.h:7:#define
>>> __ARCH_WANT_SYSCALL_DEPRECATED
>>>include/uapi/asm-generic/unistd.h:837:#ifdef
>>> __ARCH_WANT_SYSCALL_DEPRECATED
>>>include/uapi/asm-generic/unistd.h:899:#endif /*
>>> __ARCH_WANT_SYSCALL_DEPRECATED */
>>>
>>> But even if this would make aarch64 compile, the syscall
>>> numbers don't match up:
>>>
>>>$ git grep -n __NR_getpgrp include/uapi/asm-generic/unistd.h
>>>include/uapi/asm-generic/unistd.h:841:#define __NR_getpgrp 1060
>>>include/uapi/asm-generic/unistd.h:843:__SYSCALL(__NR_getpgrp,
>>> sys_getpgrp)
>>>
>>> The only thing that can be found on arm64 is:
>>>
>>>$ git grep -n __NR_getpgrp arch/arm64/
>>>arch/arm64/include/asm/unistd32.h:154:#define __NR_getpgrp 65
>>>arch/arm64/include/asm/unistd32.h:155:__SYSCALL(__NR_getpgrp,
>>> sys_getpgrp)
>>>
>>> In arch/arm64/include/asm/unistd.h, it does include the
>>> uapi/asm/unistd.h when compat is not set, but without the
>>> __ARCH_WANT_SYSCALL_DEPRECATED. That doesn't look correct
>>> unless I'm missing something, hmm, can't we just attach the
>>> kprobes to a different syscall, one that is not deprecated,
>>> so that we don't run into this in the first place?
>>
>>
>> Yes, I agree that's better. I think we can use getpgid. I'll try to
>> whip something today and send it out.

So switching to getppid fixes it, however most of the _kern.o BPF
samples still don't build on aarch64 for me.

The trouble is with inline assembler statements in the ARM64 asm
include headers (which I think upsets LLVM/clang when building for the
BPF target).

Also about skipping headers to fix this, currently we pass
-D__ASM_SYSREG_H from samples/bpf/Makefile so that inline assembler
statements are skipped (this was added in 2015 to this file). However,
not including this causes build errors at the moment. So as sysreg.h
isn't included, the SYS_MIDR_EL1 macro from
arch/arm64/include/asm/sysreg.h is missing causing this build error.
This caused by an include originating from skbuff.h :

In file included from samples/bpf/map_perf_test_kern.c:7:
In file included from ./include/linux/skbuff.h:17:
In file included from ./include/linux/kernel.h:13:
In file included from ./include/linux/printk.h:8:
In file included from ./include/linux/cache.h:5:
In file included from ./arch/arm64/include/asm/cache.h:19:
./arch/arm64/include/asm/cputype.h:119:9: error: use of undeclared
identifier 'SYS_MPIDR_EL1'
return read_cpuid(MPIDR_EL1);
   ^

There are other paths too like mm.h including asm/pgtable.h which
breaks because of the inline assembler issues.

In file included from samples/bpf/map_perf_test_kern.c:7:
In file included from ./include/linux/skbuff.h:34:
In file included from ./include/linux/dma-mapping.h:10:
In file included from ./include/linux/scatterlist.h:7:
In file included from ./include/linux/mm.h:70:
./arch/arm64/include/asm/pgtable.h:607:9: error: value
'18446744073709550591' out of range for constraint 'L'
: "L" (~PTE_AF), "I" (ilog2(PTE_AF)));


I believe the main problem here is we are trying to build for BPF
target while including ARM64 asm headers (which I think we can't
avoid?). I was thinking of just setting ARCH to x86 when compiling the
_kern.o parts of the bpf samples. However that doesn't make sense as
we probably need to be arch aware in the samples?

I am at a loss at the moment for ideas. I would love to get any other
ideas - how does x86 solve this issue?. I tried doing something like:
skip as many asm headers using the -D trick,  passing "-include
" and defining as many things as I can in stubs.h as noops.
However I got stuck with that idea when I hit the above mm build
error.

I am also CC'ing some ARM64 folks as well for any thoughts, I am
looking forward to getting the samples working on my arm64 platform.

Thanks!

Best,

-Joel




>
> Ok, cool. Please make sure that this doesn't clash with anything
> else attached to map_perf_test_kern.c already given the obj file
> is loaded first with the attachment points.
>
>> I also wanted to fix something else, HOSTCC is set to gcc, but I want
>> the boostrap part of the sample to run an ARM so I have to make HOSTCC
>> my cross-compiler. Right now I'm hacking it to point to the arm64 gcc
>> however I think I'd like to add a 'cross compile mode' or something
>> whether HOSTCC points to CROSS_COMPILE instead. I'm happy to discuss
>> any ideas to get this fixed too.
>
>
> Yeah, sounds like a good idea to add such possibility. In case of
> cross compiling to a target arch with different endianess, you might
> also need to specifically select bpfeb (big endian) resp. bpfel
> (little endian) as clang target. (Just bpf target uses host endianess.)
>
> Thanks, Joel!


Re: [PATCH net] sctp: use __GFP_NOWARN for sctpw.fifo allocation

2017-08-05 Thread Marcelo Ricardo Leitner
On Sat, Aug 05, 2017 at 08:31:09PM +0800, Xin Long wrote:
> Chen Wei found a kernel call trace when modprobe sctp_probe with
> bufsize set with a huge value.
> 
> It's because in sctpprobe_init when alloc memory for sctpw.fifo,
> the size is got from userspace. If it is too large, kernel will
> fail and give a warning.

Yes but sctp_probe can only be loaded by an admin and it would happen
only during modprobe. It's different from the commit mentioned below, on
which any user could trigger it.

> 
> As there will be a fallback allocation later, this patch is just
> to fail silently and return ret, just as commit 0ccc22f425e5
> ("sit: use __GFP_NOWARN for user controlled allocation") did.
> 
> Reported-by: Chen Wei 
> Signed-off-by: Xin Long 
> ---
>  net/sctp/probe.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/net/sctp/probe.c b/net/sctp/probe.c
> index 6cc2152..5bf3164 100644
> --- a/net/sctp/probe.c
> +++ b/net/sctp/probe.c
> @@ -210,7 +210,7 @@ static __init int sctpprobe_init(void)
>  
>   init_waitqueue_head();
>   spin_lock_init();
> - if (kfifo_alloc(, bufsize, GFP_KERNEL))
> + if (kfifo_alloc(, bufsize, GFP_KERNEL | __GFP_NOWARN))
>   return ret;
>  
>   if (!proc_create(procname, S_IRUSR, init_net.proc_net,
> -- 
> 2.1.0
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-sctp" in
> the body of a message to majord...@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 


Re: Performance comparision / qdisc / no qdisc / queueing linux kernel 4.12

2017-08-05 Thread Paweł Staszewski

With

4.13-rc3 have kernel panic when deleting qdisc - will try to get panic trace


W dniu 2017-08-05 o 18:38, Paweł Staszewski pisze:

Hi


Want to send some comparisions about poor performance of kernel when 
simple queueing is enabled



So first - kernel performance for forwarded udp packets generated from 
pktgen:


UDP stream ~10Mpps - random destination from network 172.16.0.0/12 + 
random udp port



Forwarding performance with 8x RSS queues

  enp216s0f0:  9772859.00 P/s 0.00 P/s 9772859.00 P/s
   enp216s0f1:0.00 P/s   9772883.00 P/s 9772883.00 
P/s
-- 

total:  9772863.00 P/s   9772886.00 P/s 
19545750.00 P/s


mpstat -P ALL 1 10

Average: CPU%usr   %nice%sys %iowait%irq   %soft 
%steal  %guest  %gnice   %idle
Average: all0.000.000.000.000.00 11.89 0.00
0.000.00   88.11
Average:   00.000.000.000.000.00 0.10 0.00
0.000.00   99.90
Average:   10.000.000.000.000.00 0.00 0.00
0.000.00  100.00
Average:   20.000.000.000.000.00 0.00 0.00
0.000.00  100.00
Average:   30.000.000.000.000.00 0.00 0.00
0.000.00  100.00
Average:   40.000.000.000.000.00 0.00 0.00
0.000.00  100.00
Average:   50.000.000.000.000.00 0.00 0.00
0.000.00  100.00
Average:   60.000.000.000.000.00 0.00 0.00
0.000.00  100.00
Average:   70.000.000.000.000.00 0.00 0.00
0.000.00  100.00
Average:   80.000.000.000.000.00 0.00 0.00
0.000.00  100.00
Average:   90.000.000.000.000.00 0.00 0.00
0.000.00  100.00
Average:  100.000.000.000.000.00 0.00 0.00
0.000.00  100.00
Average:  110.000.000.000.000.00 0.00 0.00
0.000.00  100.00
Average:  120.000.000.000.000.00 0.00 0.00
0.000.00  100.00
Average:  130.000.000.000.000.00 0.00 0.00
0.000.00  100.00
Average:  140.000.000.000.000.00 0.00 0.00
0.000.00  100.00
Average:  150.000.000.000.000.00 0.00 0.00
0.000.00  100.00
Average:  160.000.000.000.000.00 0.00 0.00
0.000.00  100.00
Average:  170.000.000.000.000.00 0.00 0.00
0.000.00  100.00
Average:  180.000.000.000.000.00 0.00 0.00
0.000.00  100.00
Average:  190.000.000.000.000.00 0.00 0.00
0.000.00  100.00
Average:  200.000.000.000.000.00 0.00 0.00
0.000.00  100.00
Average:  210.000.000.000.000.00 0.00 0.00
0.000.00  100.00
Average:  220.000.000.000.000.00 0.00 0.00
0.000.00  100.00
Average:  230.000.000.000.000.00 0.00 0.00
0.000.00  100.00
Average:  240.000.000.000.000.00 0.00 0.00
0.000.00  100.00
Average:  250.000.000.000.000.00 0.00 0.00
0.000.00  100.00
Average:  260.000.000.000.000.00 0.00 0.00
0.000.00  100.00
Average:  270.000.000.000.000.00 0.00 0.00
0.000.00  100.00
Average:  280.000.000.000.000.00 0.00 0.00
0.000.00  100.00
Average:  290.000.000.000.000.00 0.00 0.00
0.000.00  100.00
Average:  300.000.000.000.000.00 0.00 0.00
0.000.00  100.00
Average:  310.000.000.000.000.00 0.00 0.00
0.000.00  100.00
Average:  320.000.000.000.000.00 0.00 0.00
0.000.00  100.00
Average:  330.000.000.000.000.00 0.00 0.00
0.000.00  100.00
Average:  340.000.000.000.000.00 0.00 0.00
0.000.00  100.00
Average:  350.000.000.000.000.00 0.00 0.00
0.000.00  100.00
Average:  360.000.000.000.000.00 0.00 0.00
0.000.00  100.00
Average:  370.000.000.000.000.00 0.00 0.00
0.000.00  100.00
Average:  380.000.000.000.000.00 0.00 0.00
0.000.00  100.00
Average:  390.000.000.000.000.00 0.00 0.00
0.000.00  100.00
Average:  400.000.000.000.000.00 0.00 0.00
0.000.00  100.00
Average:  410.000.000.000.000.00 0.00 0.00
0.000.00  100.00
Average:  420.000.000.000.000.00 0.00 0.00
0.000.00  100.00
Average:  430.000.000.000.000.00 0.00 

Performance comparision / qdisc / no qdisc / queueing linux kernel 4.12

2017-08-05 Thread Paweł Staszewski

Hi


Want to send some comparisions about poor performance of kernel when 
simple queueing is enabled



So first - kernel performance for forwarded udp packets generated from 
pktgen:


UDP stream ~10Mpps - random destination from network 172.16.0.0/12 + 
random udp port



Forwarding performance with 8x RSS queues

  enp216s0f0:  9772859.00 P/s 0.00 P/s 9772859.00 P/s
   enp216s0f1:0.00 P/s   9772883.00 P/s 9772883.00 P/s
--
total:  9772863.00 P/s   9772886.00 P/s 19545750.00 P/s

mpstat -P ALL 1 10

Average: CPU%usr   %nice%sys %iowait%irq   %soft %steal  
%guest  %gnice   %idle
Average: all0.000.000.000.000.00 11.89
0.000.000.00   88.11
Average:   00.000.000.000.000.00 0.100.00
0.000.00   99.90
Average:   10.000.000.000.000.00 0.000.00
0.000.00  100.00
Average:   20.000.000.000.000.00 0.000.00
0.000.00  100.00
Average:   30.000.000.000.000.00 0.000.00
0.000.00  100.00
Average:   40.000.000.000.000.00 0.000.00
0.000.00  100.00
Average:   50.000.000.000.000.00 0.000.00
0.000.00  100.00
Average:   60.000.000.000.000.00 0.000.00
0.000.00  100.00
Average:   70.000.000.000.000.00 0.000.00
0.000.00  100.00
Average:   80.000.000.000.000.00 0.000.00
0.000.00  100.00
Average:   90.000.000.000.000.00 0.000.00
0.000.00  100.00
Average:  100.000.000.000.000.00 0.000.00
0.000.00  100.00
Average:  110.000.000.000.000.00 0.000.00
0.000.00  100.00
Average:  120.000.000.000.000.00 0.000.00
0.000.00  100.00
Average:  130.000.000.000.000.00 0.000.00
0.000.00  100.00
Average:  140.000.000.000.000.00 0.000.00
0.000.00  100.00
Average:  150.000.000.000.000.00 0.000.00
0.000.00  100.00
Average:  160.000.000.000.000.00 0.000.00
0.000.00  100.00
Average:  170.000.000.000.000.00 0.000.00
0.000.00  100.00
Average:  180.000.000.000.000.00 0.000.00
0.000.00  100.00
Average:  190.000.000.000.000.00 0.000.00
0.000.00  100.00
Average:  200.000.000.000.000.00 0.000.00
0.000.00  100.00
Average:  210.000.000.000.000.00 0.000.00
0.000.00  100.00
Average:  220.000.000.000.000.00 0.000.00
0.000.00  100.00
Average:  230.000.000.000.000.00 0.000.00
0.000.00  100.00
Average:  240.000.000.000.000.00 0.000.00
0.000.00  100.00
Average:  250.000.000.000.000.00 0.000.00
0.000.00  100.00
Average:  260.000.000.000.000.00 0.000.00
0.000.00  100.00
Average:  270.000.000.000.000.00 0.000.00
0.000.00  100.00
Average:  280.000.000.000.000.00 0.000.00
0.000.00  100.00
Average:  290.000.000.000.000.00 0.000.00
0.000.00  100.00
Average:  300.000.000.000.000.00 0.000.00
0.000.00  100.00
Average:  310.000.000.000.000.00 0.000.00
0.000.00  100.00
Average:  320.000.000.000.000.00 0.000.00
0.000.00  100.00
Average:  330.000.000.000.000.00 0.000.00
0.000.00  100.00
Average:  340.000.000.000.000.00 0.000.00
0.000.00  100.00
Average:  350.000.000.000.000.00 0.000.00
0.000.00  100.00
Average:  360.000.000.000.000.00 0.000.00
0.000.00  100.00
Average:  370.000.000.000.000.00 0.000.00
0.000.00  100.00
Average:  380.000.000.000.000.00 0.000.00
0.000.00  100.00
Average:  390.000.000.000.000.00 0.000.00
0.000.00  100.00
Average:  400.000.000.000.000.00 0.000.00
0.000.00  100.00
Average:  410.000.000.000.000.00 0.000.00
0.000.00  100.00
Average:  420.000.000.000.000.00 0.000.00
0.000.00  100.00
Average:  430.000.000.000.000.00 0.000.00

[patch net-next 10/15] dsa: push cls_matchall setup_tc processing into a separate function

2017-08-05 Thread Jiri Pirko
From: Jiri Pirko 

Let dsa_slave_setup_tc be a splitter for specific setup_tc types and
push out cls_matchall specific code into a separate function.

Signed-off-by: Jiri Pirko 
---
 net/dsa/slave.c | 33 +
 1 file changed, 21 insertions(+), 12 deletions(-)

diff --git a/net/dsa/slave.c b/net/dsa/slave.c
index a02d22b..f041c9e 100644
--- a/net/dsa/slave.c
+++ b/net/dsa/slave.c
@@ -850,26 +850,35 @@ static void dsa_slave_del_cls_matchall(struct net_device 
*dev,
kfree(mall_tc_entry);
 }
 
-static int dsa_slave_setup_tc(struct net_device *dev, enum tc_setup_type type,
- u32 handle, u32 chain_index, __be16 protocol,
- struct tc_to_netdev *tc)
+static int dsa_slave_setup_tc_cls_matchall(struct net_device *dev,
+  u32 handle, u32 chain_index,
+  __be16 protocol,
+  struct tc_cls_matchall_offload *cls)
 {
bool ingress = TC_H_MAJ(handle) == TC_H_MAJ(TC_H_INGRESS);
 
if (chain_index)
return -EOPNOTSUPP;
 
+   switch (cls->command) {
+   case TC_CLSMATCHALL_REPLACE:
+   return dsa_slave_add_cls_matchall(dev, protocol, cls, ingress);
+   case TC_CLSMATCHALL_DESTROY:
+   dsa_slave_del_cls_matchall(dev, cls);
+   return 0;
+   default:
+   return -EOPNOTSUPP;
+   }
+}
+
+static int dsa_slave_setup_tc(struct net_device *dev, enum tc_setup_type type,
+ u32 handle, u32 chain_index, __be16 protocol,
+ struct tc_to_netdev *tc)
+{
switch (type) {
case TC_SETUP_CLSMATCHALL:
-   switch (tc->cls_mall->command) {
-   case TC_CLSMATCHALL_REPLACE:
-   return dsa_slave_add_cls_matchall(dev, protocol,
- tc->cls_mall,
- ingress);
-   case TC_CLSMATCHALL_DESTROY:
-   dsa_slave_del_cls_matchall(dev, tc->cls_mall);
-   return 0;
-   }
+   return dsa_slave_setup_tc_cls_matchall(dev, handle, chain_index,
+  protocol, tc->cls_mall);
default:
return -EOPNOTSUPP;
}
-- 
2.9.3



[patch net-next 06/15] mlx5e: push cls_flower and mqprio setup_tc processing into separate functions

2017-08-05 Thread Jiri Pirko
From: Jiri Pirko 

Let mlx5e_setup_tc (former mlx5e_ndo_setup_tc) be a splitter for specific
setup_tc types and push out cls_flower and mqprio specific codes into
separate functions. Also change the return values so they are the same
as in the rest of the drivers.

Signed-off-by: Jiri Pirko 
---
 drivers/net/ethernet/mellanox/mlx5/core/en_main.c | 56 +--
 1 file changed, 31 insertions(+), 25 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c 
b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c
index 4052e225f..adf35da 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c
@@ -2998,12 +2998,16 @@ static int mlx5e_modify_channels_vsd(struct 
mlx5e_channels *chs, bool vsd)
return 0;
 }
 
-static int mlx5e_setup_tc(struct net_device *netdev, u8 tc)
+static int mlx5e_setup_tc_mqprio(struct net_device *netdev,
+struct tc_mqprio_qopt *mqprio)
 {
struct mlx5e_priv *priv = netdev_priv(netdev);
struct mlx5e_channels new_channels = {};
+   u8 tc = mqprio->num_tc;
int err = 0;
 
+   mqprio->hw = TC_MQPRIO_HW_OFFLOAD_TCS;
+
if (tc && tc != MLX5E_MAX_NUM_TC)
return -EINVAL;
 
@@ -3027,39 +3031,41 @@ static int mlx5e_setup_tc(struct net_device *netdev, u8 
tc)
return err;
 }
 
-static int mlx5e_ndo_setup_tc(struct net_device *dev, enum tc_setup_type type,
- u32 handle, u32 chain_index, __be16 proto,
- struct tc_to_netdev *tc)
+static int mlx5e_setup_tc_cls_flower(struct net_device *dev,
+u32 handle, u32 chain_index, __be16 proto,
+struct tc_cls_flower_offload *cls_flower)
 {
struct mlx5e_priv *priv = netdev_priv(dev);
 
-   if (TC_H_MAJ(handle) != TC_H_MAJ(TC_H_INGRESS))
-   goto mqprio;
+   if (TC_H_MAJ(handle) != TC_H_MAJ(TC_H_INGRESS) ||
+   chain_index)
+   return -EOPNOTSUPP;
 
-   if (chain_index)
+   switch (cls_flower->command) {
+   case TC_CLSFLOWER_REPLACE:
+   return mlx5e_configure_flower(priv, proto, cls_flower);
+   case TC_CLSFLOWER_DESTROY:
+   return mlx5e_delete_flower(priv, cls_flower);
+   case TC_CLSFLOWER_STATS:
+   return mlx5e_stats_flower(priv, cls_flower);
+   default:
return -EOPNOTSUPP;
+   }
+}
 
+static int mlx5e_setup_tc(struct net_device *dev, enum tc_setup_type type,
+ u32 handle, u32 chain_index, __be16 proto,
+ struct tc_to_netdev *tc)
+{
switch (type) {
case TC_SETUP_CLSFLOWER:
-   switch (tc->cls_flower->command) {
-   case TC_CLSFLOWER_REPLACE:
-   return mlx5e_configure_flower(priv, proto, 
tc->cls_flower);
-   case TC_CLSFLOWER_DESTROY:
-   return mlx5e_delete_flower(priv, tc->cls_flower);
-   case TC_CLSFLOWER_STATS:
-   return mlx5e_stats_flower(priv, tc->cls_flower);
-   }
+   return mlx5e_setup_tc_cls_flower(dev, handle, chain_index,
+proto, tc->cls_flower);
+   case TC_SETUP_MQPRIO:
+   return mlx5e_setup_tc_mqprio(dev, tc->mqprio);
default:
return -EOPNOTSUPP;
}
-
-mqprio:
-   if (type != TC_SETUP_MQPRIO)
-   return -EINVAL;
-
-   tc->mqprio->hw = TC_MQPRIO_HW_OFFLOAD_TCS;
-
-   return mlx5e_setup_tc(dev, tc->mqprio->num_tc);
 }
 
 static void
@@ -3695,7 +3701,7 @@ static const struct net_device_ops mlx5e_netdev_ops_basic 
= {
.ndo_open= mlx5e_open,
.ndo_stop= mlx5e_close,
.ndo_start_xmit  = mlx5e_xmit,
-   .ndo_setup_tc= mlx5e_ndo_setup_tc,
+   .ndo_setup_tc= mlx5e_setup_tc,
.ndo_select_queue= mlx5e_select_queue,
.ndo_get_stats64 = mlx5e_get_stats,
.ndo_set_rx_mode = mlx5e_set_rx_mode,
@@ -3720,7 +3726,7 @@ static const struct net_device_ops mlx5e_netdev_ops_sriov 
= {
.ndo_open= mlx5e_open,
.ndo_stop= mlx5e_close,
.ndo_start_xmit  = mlx5e_xmit,
-   .ndo_setup_tc= mlx5e_ndo_setup_tc,
+   .ndo_setup_tc= mlx5e_setup_tc,
.ndo_select_queue= mlx5e_select_queue,
.ndo_get_stats64 = mlx5e_get_stats,
.ndo_set_rx_mode = mlx5e_set_rx_mode,
-- 
2.9.3



[patch net-next 09/15] mlxsw: spectrum: rename cls arg in matchall processing

2017-08-05 Thread Jiri Pirko
From: Jiri Pirko 

To sync-up with the naming in the rest of the driver, rename the cls arg.

Signed-off-by: Jiri Pirko 
---
 drivers/net/ethernet/mellanox/mlxsw/spectrum.c | 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum.c 
b/drivers/net/ethernet/mellanox/mlxsw/spectrum.c
index 9f8ba37..f333d08 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum.c
@@ -1618,7 +1618,7 @@ mlxsw_sp_port_del_cls_matchall_sample(struct 
mlxsw_sp_port *mlxsw_sp_port)
 
 static int mlxsw_sp_port_add_cls_matchall(struct mlxsw_sp_port *mlxsw_sp_port,
  __be16 protocol,
- struct tc_cls_matchall_offload *cls,
+ struct tc_cls_matchall_offload *f,
  bool ingress)
 {
struct mlxsw_sp_port_mall_tc_entry *mall_tc_entry;
@@ -1626,7 +1626,7 @@ static int mlxsw_sp_port_add_cls_matchall(struct 
mlxsw_sp_port *mlxsw_sp_port,
LIST_HEAD(actions);
int err;
 
-   if (!tcf_exts_has_one_action(cls->exts)) {
+   if (!tcf_exts_has_one_action(f->exts)) {
netdev_err(mlxsw_sp_port->dev, "only singular actions are 
supported\n");
return -EOPNOTSUPP;
}
@@ -1634,9 +1634,9 @@ static int mlxsw_sp_port_add_cls_matchall(struct 
mlxsw_sp_port *mlxsw_sp_port,
mall_tc_entry = kzalloc(sizeof(*mall_tc_entry), GFP_KERNEL);
if (!mall_tc_entry)
return -ENOMEM;
-   mall_tc_entry->cookie = cls->cookie;
+   mall_tc_entry->cookie = f->cookie;
 
-   tcf_exts_to_list(cls->exts, );
+   tcf_exts_to_list(f->exts, );
a = list_first_entry(, struct tc_action, list);
 
if (is_tcf_mirred_egress_mirror(a) && protocol == htons(ETH_P_ALL)) {
@@ -1648,7 +1648,7 @@ static int mlxsw_sp_port_add_cls_matchall(struct 
mlxsw_sp_port *mlxsw_sp_port,
mirror, a, ingress);
} else if (is_tcf_sample(a) && protocol == htons(ETH_P_ALL)) {
mall_tc_entry->type = MLXSW_SP_PORT_MALL_SAMPLE;
-   err = mlxsw_sp_port_add_cls_matchall_sample(mlxsw_sp_port, cls,
+   err = mlxsw_sp_port_add_cls_matchall_sample(mlxsw_sp_port, f,
a, ingress);
} else {
err = -EOPNOTSUPP;
@@ -1666,12 +1666,12 @@ static int mlxsw_sp_port_add_cls_matchall(struct 
mlxsw_sp_port *mlxsw_sp_port,
 }
 
 static void mlxsw_sp_port_del_cls_matchall(struct mlxsw_sp_port *mlxsw_sp_port,
-  struct tc_cls_matchall_offload *cls)
+  struct tc_cls_matchall_offload *f)
 {
struct mlxsw_sp_port_mall_tc_entry *mall_tc_entry;
 
mall_tc_entry = mlxsw_sp_port_mall_tc_entry_find(mlxsw_sp_port,
-cls->cookie);
+f->cookie);
if (!mall_tc_entry) {
netdev_dbg(mlxsw_sp_port->dev, "tc entry not found on port\n");
return;
-- 
2.9.3



[patch net-next 05/15] ixgbe: push cls_u32 and mqprio setup_tc processing into separate functions

2017-08-05 Thread Jiri Pirko
From: Jiri Pirko 

Let __ixgbe_setup_tc be a splitter for specific setup_tc types and push out
cls_u32 and mqprio specific codes into separate functions. Also change
the return values so they are the same as in the rest of the drivers.

Signed-off-by: Jiri Pirko 
---
 drivers/net/ethernet/intel/ixgbe/ixgbe_main.c | 67 ---
 1 file changed, 39 insertions(+), 28 deletions(-)

diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c 
b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
index d39db97..35db198 100644
--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
@@ -9226,42 +9226,53 @@ static int ixgbe_configure_clsu32(struct ixgbe_adapter 
*adapter,
return err;
 }
 
-static int __ixgbe_setup_tc(struct net_device *dev, enum tc_setup_type type,
-   u32 handle, u32 chain_index, __be16 proto,
-   struct tc_to_netdev *tc)
+static int ixgbe_setup_tc_cls_u32(struct net_device *dev,
+ u32 handle, u32 chain_index, __be16 proto,
+ struct tc_cls_u32_offload *cls_u32)
 {
struct ixgbe_adapter *adapter = netdev_priv(dev);
 
-   if (chain_index)
+   if (TC_H_MAJ(handle) != TC_H_MAJ(TC_H_INGRESS) ||
+   chain_index)
return -EOPNOTSUPP;
 
-   if (TC_H_MAJ(handle) == TC_H_MAJ(TC_H_INGRESS) &&
-   type == TC_SETUP_CLSU32) {
-   switch (tc->cls_u32->command) {
-   case TC_CLSU32_NEW_KNODE:
-   case TC_CLSU32_REPLACE_KNODE:
-   return ixgbe_configure_clsu32(adapter,
- proto, tc->cls_u32);
-   case TC_CLSU32_DELETE_KNODE:
-   return ixgbe_delete_clsu32(adapter, tc->cls_u32);
-   case TC_CLSU32_NEW_HNODE:
-   case TC_CLSU32_REPLACE_HNODE:
-   return ixgbe_configure_clsu32_add_hnode(adapter, proto,
-   tc->cls_u32);
-   case TC_CLSU32_DELETE_HNODE:
-   return ixgbe_configure_clsu32_del_hnode(adapter,
-   tc->cls_u32);
-   default:
-   return -EINVAL;
-   }
+   switch (cls_u32->command) {
+   case TC_CLSU32_NEW_KNODE:
+   case TC_CLSU32_REPLACE_KNODE:
+   return ixgbe_configure_clsu32(adapter, proto, cls_u32);
+   case TC_CLSU32_DELETE_KNODE:
+   return ixgbe_delete_clsu32(adapter, cls_u32);
+   case TC_CLSU32_NEW_HNODE:
+   case TC_CLSU32_REPLACE_HNODE:
+   return ixgbe_configure_clsu32_add_hnode(adapter, proto,
+   cls_u32);
+   case TC_CLSU32_DELETE_HNODE:
+   return ixgbe_configure_clsu32_del_hnode(adapter, cls_u32);
+   default:
+   return -EOPNOTSUPP;
}
+}
 
-   if (type != TC_SETUP_MQPRIO)
-   return -EINVAL;
-
-   tc->mqprio->hw = TC_MQPRIO_HW_OFFLOAD_TCS;
+static int ixgbe_setup_tc_mqprio(struct net_device *dev,
+struct tc_mqprio_qopt *mqprio)
+{
+   mqprio->hw = TC_MQPRIO_HW_OFFLOAD_TCS;
+   return ixgbe_setup_tc(dev, mqprio->num_tc);
+}
 
-   return ixgbe_setup_tc(dev, tc->mqprio->num_tc);
+static int __ixgbe_setup_tc(struct net_device *dev, enum tc_setup_type type,
+   u32 handle, u32 chain_index, __be16 proto,
+   struct tc_to_netdev *tc)
+{
+   switch (type) {
+   case TC_SETUP_CLSU32:
+   return ixgbe_setup_tc_cls_u32(dev, handle, chain_index, proto,
+ tc->cls_u32);
+   case TC_SETUP_MQPRIO:
+   return ixgbe_setup_tc_mqprio(dev, tc->mqprio);
+   default:
+   return -EOPNOTSUPP;
+   }
 }
 
 #ifdef CONFIG_PCI_IOV
-- 
2.9.3



[patch net-next 07/15] mlx5e_rep: push cls_flower setup_tc processing into a separate function

2017-08-05 Thread Jiri Pirko
From: Jiri Pirko 

Let mlx5e_rep_setup_tc (former mlx5e_rep_ndo_setup_tc) be a splitter for
specific setup_tc types and push out cls_flower specific code into
a separate function.

Signed-off-by: Jiri Pirko 
---
 drivers/net/ethernet/mellanox/mlx5/core/en_rep.c | 49 ++--
 1 file changed, 29 insertions(+), 20 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c 
b/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c
index 0e6bab1..e6cc642 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c
@@ -651,38 +651,47 @@ static int mlx5e_rep_get_phys_port_name(struct net_device 
*dev,
return 0;
 }
 
-static int mlx5e_rep_ndo_setup_tc(struct net_device *dev,
- enum tc_setup_type type, u32 handle,
- u32 chain_index, __be16 proto,
- struct tc_to_netdev *tc)
+static int mlx5e_rep_setup_tc_cls_flower(struct net_device *dev,
+u32 handle, u32 chain_index,
+__be16 proto,
+struct tc_to_netdev *tc)
 {
+   struct tc_cls_flower_offload *cls_flower = tc->cls_flower;
struct mlx5e_priv *priv = netdev_priv(dev);
 
-   if (TC_H_MAJ(handle) != TC_H_MAJ(TC_H_INGRESS))
+   if (TC_H_MAJ(handle) != TC_H_MAJ(TC_H_INGRESS) ||
+   chain_index)
return -EOPNOTSUPP;
 
-   if (type == TC_SETUP_CLSFLOWER && tc->cls_flower->egress_dev) {
+   if (cls_flower->egress_dev) {
struct mlx5_eswitch *esw = priv->mdev->priv.eswitch;
-   struct net_device *uplink_dev = 
mlx5_eswitch_get_uplink_netdev(esw);
 
-   return uplink_dev->netdev_ops->ndo_setup_tc(uplink_dev, type,
-   handle, chain_index,
-   proto, tc);
+   dev = mlx5_eswitch_get_uplink_netdev(esw);
+   return dev->netdev_ops->ndo_setup_tc(dev, TC_SETUP_CLSFLOWER,
+handle, chain_index,
+proto, tc);
}
 
-   if (chain_index)
+   switch (cls_flower->command) {
+   case TC_CLSFLOWER_REPLACE:
+   return mlx5e_configure_flower(priv, proto, cls_flower);
+   case TC_CLSFLOWER_DESTROY:
+   return mlx5e_delete_flower(priv, cls_flower);
+   case TC_CLSFLOWER_STATS:
+   return mlx5e_stats_flower(priv, cls_flower);
+   default:
return -EOPNOTSUPP;
+   }
+}
 
+static int mlx5e_rep_setup_tc(struct net_device *dev, enum tc_setup_type type,
+ u32 handle, u32 chain_index, __be16 proto,
+ struct tc_to_netdev *tc)
+{
switch (type) {
case TC_SETUP_CLSFLOWER:
-   switch (tc->cls_flower->command) {
-   case TC_CLSFLOWER_REPLACE:
-   return mlx5e_configure_flower(priv, proto, 
tc->cls_flower);
-   case TC_CLSFLOWER_DESTROY:
-   return mlx5e_delete_flower(priv, tc->cls_flower);
-   case TC_CLSFLOWER_STATS:
-   return mlx5e_stats_flower(priv, tc->cls_flower);
-   }
+   return mlx5e_rep_setup_tc_cls_flower(dev, handle, chain_index,
+proto, tc);
default:
return -EOPNOTSUPP;
}
@@ -774,7 +783,7 @@ static const struct net_device_ops mlx5e_netdev_ops_rep = {
.ndo_stop= mlx5e_rep_close,
.ndo_start_xmit  = mlx5e_xmit,
.ndo_get_phys_port_name  = mlx5e_rep_get_phys_port_name,
-   .ndo_setup_tc= mlx5e_rep_ndo_setup_tc,
+   .ndo_setup_tc= mlx5e_rep_setup_tc,
.ndo_get_stats64 = mlx5e_rep_get_stats,
.ndo_has_offload_stats   = mlx5e_has_offload_stats,
.ndo_get_offload_stats   = mlx5e_get_offload_stats,
-- 
2.9.3



[patch net-next 04/15] cxgb4: push cls_u32 setup_tc processing into a separate function

2017-08-05 Thread Jiri Pirko
From: Jiri Pirko 

Let cxgb_setup_tc be a splitter for specific setup_tc types and push out
cls_u32 specific code into a separate function.

Signed-off-by: Jiri Pirko 
---
 drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c | 42 +++--
 1 file changed, 26 insertions(+), 16 deletions(-)

diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c 
b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
index 89d2b0c..6512290 100644
--- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
+++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
@@ -2889,6 +2889,26 @@ static int cxgb_set_tx_maxrate(struct net_device *dev, 
int index, u32 rate)
return err;
 }
 
+static int cxgb_setup_tc_cls_u32(struct net_device *dev,
+enum tc_setup_type type,
+u32 handle, u32 chain_index, __be16 proto,
+struct tc_cls_u32_offload *cls_u32)
+{
+   if (TC_H_MAJ(handle) != TC_H_MAJ(TC_H_INGRESS) ||
+   chain_index)
+   return -EOPNOTSUPP;
+
+   switch (cls_u32->command) {
+   case TC_CLSU32_NEW_KNODE:
+   case TC_CLSU32_REPLACE_KNODE:
+   return cxgb4_config_knode(dev, proto, cls_u32);
+   case TC_CLSU32_DELETE_KNODE:
+   return cxgb4_delete_knode(dev, proto, cls_u32);
+   default:
+   return -EOPNOTSUPP;
+   }
+}
+
 static int cxgb_setup_tc(struct net_device *dev, enum tc_setup_type type,
 u32 handle, u32 chain_index, __be16 proto,
 struct tc_to_netdev *tc)
@@ -2896,9 +2916,6 @@ static int cxgb_setup_tc(struct net_device *dev, enum 
tc_setup_type type,
struct port_info *pi = netdev2pinfo(dev);
struct adapter *adap = netdev2adap(dev);
 
-   if (chain_index)
-   return -EOPNOTSUPP;
-
if (!(adap->flags & FULL_INIT_DONE)) {
dev_err(adap->pdev_dev,
"Failed to setup tc on port %d. Link Down?\n",
@@ -2906,20 +2923,13 @@ static int cxgb_setup_tc(struct net_device *dev, enum 
tc_setup_type type,
return -EINVAL;
}
 
-   if (TC_H_MAJ(handle) == TC_H_MAJ(TC_H_INGRESS) &&
-   type == TC_SETUP_CLSU32) {
-   switch (tc->cls_u32->command) {
-   case TC_CLSU32_NEW_KNODE:
-   case TC_CLSU32_REPLACE_KNODE:
-   return cxgb4_config_knode(dev, proto, tc->cls_u32);
-   case TC_CLSU32_DELETE_KNODE:
-   return cxgb4_delete_knode(dev, proto, tc->cls_u32);
-   default:
-   return -EOPNOTSUPP;
-   }
+   switch (type) {
+   case TC_SETUP_CLSU32:
+   return cxgb_setup_tc_cls_u32(dev, type, handle, chain_index,
+proto, tc->cls_u32);
+   default:
+   return -EOPNOTSUPP;
}
-
-   return -EOPNOTSUPP;
 }
 
 static netdev_features_t cxgb_fix_features(struct net_device *dev,
-- 
2.9.3



[patch net-next 01/15] net: sched: make type an argument for ndo_setup_tc

2017-08-05 Thread Jiri Pirko
From: Jiri Pirko 

Since the type is always present, push it to be a separate argument to
ndo_setup_tc. On the way, name the type enum and use it for arg type.

Signed-off-by: Jiri Pirko 
---
 drivers/net/ethernet/amd/xgbe/xgbe-drv.c|  6 +++---
 drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c |  7 ---
 drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h |  5 +++--
 drivers/net/ethernet/broadcom/bnxt/bnxt.c   |  7 ---
 drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c |  7 ---
 drivers/net/ethernet/freescale/dpaa/dpaa_eth.c  |  7 ---
 drivers/net/ethernet/intel/fm10k/fm10k_netdev.c |  7 ---
 drivers/net/ethernet/intel/i40e/i40e_main.c |  6 +++---
 drivers/net/ethernet/intel/ixgbe/ixgbe_main.c   |  9 +
 drivers/net/ethernet/mellanox/mlx4/en_netdev.c  |  6 +++---
 drivers/net/ethernet/mellanox/mlx5/core/en_main.c   |  8 
 drivers/net/ethernet/mellanox/mlx5/core/en_rep.c|  9 +
 drivers/net/ethernet/mellanox/mlxsw/spectrum.c  | 10 +-
 drivers/net/ethernet/netronome/nfp/bpf/main.c   |  5 +++--
 drivers/net/ethernet/netronome/nfp/flower/main.h|  3 ++-
 drivers/net/ethernet/netronome/nfp/flower/offload.c |  5 +++--
 drivers/net/ethernet/netronome/nfp/nfp_app.h|  6 --
 drivers/net/ethernet/netronome/nfp/nfp_port.c   |  7 ---
 drivers/net/ethernet/netronome/nfp/nfp_port.h   |  5 +++--
 drivers/net/ethernet/sfc/efx.h  |  5 +++--
 drivers/net/ethernet/sfc/falcon/efx.h   |  5 +++--
 drivers/net/ethernet/sfc/falcon/tx.c|  7 ---
 drivers/net/ethernet/sfc/tx.c   |  7 ---
 drivers/net/ethernet/ti/netcp_core.c|  7 ---
 include/linux/netdevice.h   |  9 +
 net/dsa/slave.c |  6 +++---
 net/sched/cls_bpf.c |  4 ++--
 net/sched/cls_flower.c  | 14 ++
 net/sched/cls_matchall.c| 10 --
 net/sched/cls_u32.c | 20 
 net/sched/sch_mqprio.c  | 13 ++---
 31 files changed, 122 insertions(+), 110 deletions(-)

diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-drv.c 
b/drivers/net/ethernet/amd/xgbe/xgbe-drv.c
index ecef3ee..6a6ea3b 100644
--- a/drivers/net/ethernet/amd/xgbe/xgbe-drv.c
+++ b/drivers/net/ethernet/amd/xgbe/xgbe-drv.c
@@ -1918,14 +1918,14 @@ static void xgbe_poll_controller(struct net_device 
*netdev)
 }
 #endif /* End CONFIG_NET_POLL_CONTROLLER */
 
-static int xgbe_setup_tc(struct net_device *netdev, u32 handle, u32 
chain_index,
-__be16 proto,
+static int xgbe_setup_tc(struct net_device *netdev, enum tc_setup_type type,
+u32 handle, u32 chain_index, __be16 proto,
 struct tc_to_netdev *tc_to_netdev)
 {
struct xgbe_prv_data *pdata = netdev_priv(netdev);
u8 tc;
 
-   if (tc_to_netdev->type != TC_SETUP_MQPRIO)
+   if (type != TC_SETUP_MQPRIO)
return -EINVAL;
 
tc_to_netdev->mqprio->hw = TC_MQPRIO_HW_OFFLOAD_TCS;
diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c 
b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c
index 67fe3d8..4395d1c 100644
--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c
+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c
@@ -4284,10 +4284,11 @@ int bnx2x_setup_tc(struct net_device *dev, u8 num_tc)
return 0;
 }
 
-int __bnx2x_setup_tc(struct net_device *dev, u32 handle, u32 chain_index,
-__be16 proto, struct tc_to_netdev *tc)
+int __bnx2x_setup_tc(struct net_device *dev, enum tc_setup_type type,
+u32 handle, u32 chain_index, __be16 proto,
+struct tc_to_netdev *tc)
 {
-   if (tc->type != TC_SETUP_MQPRIO)
+   if (type != TC_SETUP_MQPRIO)
return -EINVAL;
 
tc->mqprio->hw = TC_MQPRIO_HW_OFFLOAD_TCS;
diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h 
b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
index c26688d..1ac4eb0 100644
--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
@@ -486,8 +486,9 @@ netdev_tx_t bnx2x_start_xmit(struct sk_buff *skb, struct 
net_device *dev);
 
 /* setup_tc callback */
 int bnx2x_setup_tc(struct net_device *dev, u8 num_tc);
-int __bnx2x_setup_tc(struct net_device *dev, u32 handle, u32 chain_index,
-__be16 proto, struct tc_to_netdev *tc);
+int __bnx2x_setup_tc(struct net_device *dev, enum tc_setup_type type,
+u32 handle, u32 chain_index, __be16 proto,
+struct tc_to_netdev *tc);
 
 int bnx2x_get_vf_config(struct net_device *dev, int vf,
struct ifla_vf_info *ivi);
diff --git 

[patch net-next 13/15] net: sched: move prio into cls_common

2017-08-05 Thread Jiri Pirko
From: Jiri Pirko 

prio is not cls_flower specific, but it is meaningful for all
classifiers. Seems that only mlxsw cares about the value. Obviously,
cls offload in other drivers is broken.

Signed-off-by: Jiri Pirko 
---
 drivers/net/ethernet/mellanox/mlxsw/spectrum_flower.c | 2 +-
 include/net/pkt_cls.h | 3 ++-
 net/sched/cls_flower.c| 3 ---
 3 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_flower.c 
b/drivers/net/ethernet/mellanox/mlxsw/spectrum_flower.c
index 021b6c0..95428b4 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_flower.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_flower.c
@@ -270,7 +270,7 @@ static int mlxsw_sp_flower_parse(struct mlxsw_sp *mlxsw_sp,
return -EOPNOTSUPP;
}
 
-   mlxsw_sp_acl_rulei_priority(rulei, f->prio);
+   mlxsw_sp_acl_rulei_priority(rulei, f->common.prio);
 
if (dissector_uses_key(f->dissector, FLOW_DISSECTOR_KEY_CONTROL)) {
struct flow_dissector_key_control *key =
diff --git a/include/net/pkt_cls.h b/include/net/pkt_cls.h
index ffaddf7..572083a 100644
--- a/include/net/pkt_cls.h
+++ b/include/net/pkt_cls.h
@@ -409,6 +409,7 @@ struct tc_cls_common_offload {
u32 handle;
u32 chain_index;
__be16 protocol;
+   u32 prio;
 };
 
 static inline void
@@ -418,6 +419,7 @@ tc_cls_common_offload_init(struct tc_cls_common_offload 
*cls_common,
cls_common->handle = tp->q->handle;
cls_common->chain_index = tp->chain->index;
cls_common->protocol = tp->protocol;
+   cls_common->prio = tp->prio;
 }
 
 struct tc_cls_u32_knode {
@@ -515,7 +517,6 @@ enum tc_fl_command {
 struct tc_cls_flower_offload {
struct tc_cls_common_offload common;
enum tc_fl_command command;
-   u32 prio;
unsigned long cookie;
struct flow_dissector *dissector;
struct fl_flow_key *mask;
diff --git a/net/sched/cls_flower.c b/net/sched/cls_flower.c
index 1fdf288..ccdf2f5 100644
--- a/net/sched/cls_flower.c
+++ b/net/sched/cls_flower.c
@@ -234,7 +234,6 @@ static void fl_hw_destroy_filter(struct tcf_proto *tp, 
struct cls_fl_filter *f)
 
tc_cls_common_offload_init(, tp);
offload.command = TC_CLSFLOWER_DESTROY;
-   offload.prio = tp->prio;
offload.cookie = (unsigned long)f;
 
tc->cls_flower = 
@@ -266,7 +265,6 @@ static int fl_hw_replace_filter(struct tcf_proto *tp,
 
tc_cls_common_offload_init(, tp);
offload.command = TC_CLSFLOWER_REPLACE;
-   offload.prio = tp->prio;
offload.cookie = (unsigned long)f;
offload.dissector = dissector;
offload.mask = mask;
@@ -295,7 +293,6 @@ static void fl_hw_update_stats(struct tcf_proto *tp, struct 
cls_fl_filter *f)
 
tc_cls_common_offload_init(, tp);
offload.command = TC_CLSFLOWER_STATS;
-   offload.prio = tp->prio;
offload.cookie = (unsigned long)f;
offload.exts = >exts;
 
-- 
2.9.3



[patch net-next 14/15] net: sched: change return value of ndo_setup_tc for driver supporting mqprio only

2017-08-05 Thread Jiri Pirko
From: Jiri Pirko 

Change the return value from -EINVAL to -EOPNOTSUPP. The rest of the
drivers have it like that, so be aligned.

Signed-off-by: Jiri Pirko 
---
 drivers/net/ethernet/amd/xgbe/xgbe-drv.c| 2 +-
 drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c | 2 +-
 drivers/net/ethernet/broadcom/bnxt/bnxt.c   | 2 +-
 drivers/net/ethernet/freescale/dpaa/dpaa_eth.c  | 2 +-
 drivers/net/ethernet/intel/fm10k/fm10k_netdev.c | 2 +-
 drivers/net/ethernet/intel/i40e/i40e_main.c | 2 +-
 drivers/net/ethernet/mellanox/mlx4/en_netdev.c  | 2 +-
 drivers/net/ethernet/sfc/falcon/tx.c| 2 +-
 drivers/net/ethernet/sfc/tx.c   | 2 +-
 drivers/net/ethernet/ti/netcp_core.c| 2 +-
 10 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-drv.c 
b/drivers/net/ethernet/amd/xgbe/xgbe-drv.c
index bbb7bfe..37d3e5b 100644
--- a/drivers/net/ethernet/amd/xgbe/xgbe-drv.c
+++ b/drivers/net/ethernet/amd/xgbe/xgbe-drv.c
@@ -1925,7 +1925,7 @@ static int xgbe_setup_tc(struct net_device *netdev, enum 
tc_setup_type type,
u8 tc;
 
if (type != TC_SETUP_MQPRIO)
-   return -EINVAL;
+   return -EOPNOTSUPP;
 
tc_to_netdev->mqprio->hw = TC_MQPRIO_HW_OFFLOAD_TCS;
tc = tc_to_netdev->mqprio->num_tc;
diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c 
b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c
index 257cf4b..8687afc 100644
--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c
+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c
@@ -4288,7 +4288,7 @@ int __bnx2x_setup_tc(struct net_device *dev, enum 
tc_setup_type type,
 struct tc_to_netdev *tc)
 {
if (type != TC_SETUP_MQPRIO)
-   return -EINVAL;
+   return -EOPNOTSUPP;
 
tc->mqprio->hw = TC_MQPRIO_HW_OFFLOAD_TCS;
 
diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt.c 
b/drivers/net/ethernet/broadcom/bnxt/bnxt.c
index 1545b88..a78f72a 100644
--- a/drivers/net/ethernet/broadcom/bnxt/bnxt.c
+++ b/drivers/net/ethernet/broadcom/bnxt/bnxt.c
@@ -7241,7 +7241,7 @@ static int bnxt_setup_tc(struct net_device *dev, enum 
tc_setup_type type,
 struct tc_to_netdev *ntc)
 {
if (type != TC_SETUP_MQPRIO)
-   return -EINVAL;
+   return -EOPNOTSUPP;
 
ntc->mqprio->hw = TC_MQPRIO_HW_OFFLOAD_TCS;
 
diff --git a/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c 
b/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c
index 3827608..bfb44c9 100644
--- a/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c
+++ b/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c
@@ -350,7 +350,7 @@ static int dpaa_setup_tc(struct net_device *net_dev, enum 
tc_setup_type type,
int i;
 
if (type != TC_SETUP_MQPRIO)
-   return -EINVAL;
+   return -EOPNOTSUPP;
 
tc->mqprio->hw = TC_MQPRIO_HW_OFFLOAD_TCS;
num_tc = tc->mqprio->num_tc;
diff --git a/drivers/net/ethernet/intel/fm10k/fm10k_netdev.c 
b/drivers/net/ethernet/intel/fm10k/fm10k_netdev.c
index 71004b8..7088812 100644
--- a/drivers/net/ethernet/intel/fm10k/fm10k_netdev.c
+++ b/drivers/net/ethernet/intel/fm10k/fm10k_netdev.c
@@ -1269,7 +1269,7 @@ static int __fm10k_setup_tc(struct net_device *dev, enum 
tc_setup_type type,
struct tc_to_netdev *tc)
 {
if (type != TC_SETUP_MQPRIO)
-   return -EINVAL;
+   return -EOPNOTSUPP;
 
tc->mqprio->hw = TC_MQPRIO_HW_OFFLOAD_TCS;
 
diff --git a/drivers/net/ethernet/intel/i40e/i40e_main.c 
b/drivers/net/ethernet/intel/i40e/i40e_main.c
index 97d8bb2..1f46338 100644
--- a/drivers/net/ethernet/intel/i40e/i40e_main.c
+++ b/drivers/net/ethernet/intel/i40e/i40e_main.c
@@ -5660,7 +5660,7 @@ static int __i40e_setup_tc(struct net_device *netdev, 
enum tc_setup_type type,
   struct tc_to_netdev *tc)
 {
if (type != TC_SETUP_MQPRIO)
-   return -EINVAL;
+   return -EOPNOTSUPP;
 
tc->mqprio->hw = TC_MQPRIO_HW_OFFLOAD_TCS;
 
diff --git a/drivers/net/ethernet/mellanox/mlx4/en_netdev.c 
b/drivers/net/ethernet/mellanox/mlx4/en_netdev.c
index e81083e..1667e86 100644
--- a/drivers/net/ethernet/mellanox/mlx4/en_netdev.c
+++ b/drivers/net/ethernet/mellanox/mlx4/en_netdev.c
@@ -134,7 +134,7 @@ static int __mlx4_en_setup_tc(struct net_device *dev, enum 
tc_setup_type type,
  struct tc_to_netdev *tc)
 {
if (type != TC_SETUP_MQPRIO)
-   return -EINVAL;
+   return -EOPNOTSUPP;
 
if (tc->mqprio->num_tc && tc->mqprio->num_tc != MLX4_EN_NUM_UP_HIGH)
return -EINVAL;
diff --git a/drivers/net/ethernet/sfc/falcon/tx.c 
b/drivers/net/ethernet/sfc/falcon/tx.c
index 447519a..0f125e1 100644
--- a/drivers/net/ethernet/sfc/falcon/tx.c
+++ b/drivers/net/ethernet/sfc/falcon/tx.c
@@ -435,7 +435,7 @@ int ef4_setup_tc(struct 

[patch net-next 12/15] net: sched: push cls related args into cls_common structure

2017-08-05 Thread Jiri Pirko
From: Jiri Pirko 

As ndo_setup_tc is generic offload op for whole tc subsystem, does not
really make sense to have cls-specific args. So move them under
cls_common structurure which is embedded in all cls structs.

Signed-off-by: Jiri Pirko 
---
 drivers/net/ethernet/amd/xgbe/xgbe-drv.c   |  1 -
 drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c|  1 -
 drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h|  1 -
 drivers/net/ethernet/broadcom/bnxt/bnxt.c  |  1 -
 drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c| 14 +---
 drivers/net/ethernet/chelsio/cxgb4/cxgb4_tc_u32.c  |  7 +++---
 drivers/net/ethernet/chelsio/cxgb4/cxgb4_tc_u32.h  |  6 ++
 drivers/net/ethernet/freescale/dpaa/dpaa_eth.c |  1 -
 drivers/net/ethernet/intel/fm10k/fm10k_netdev.c|  1 -
 drivers/net/ethernet/intel/i40e/i40e_main.c|  1 -
 drivers/net/ethernet/intel/ixgbe/ixgbe_main.c  | 17 ++-
 drivers/net/ethernet/mellanox/mlx4/en_netdev.c |  1 -
 drivers/net/ethernet/mellanox/mlx5/core/en_main.c  | 11 --
 drivers/net/ethernet/mellanox/mlx5/core/en_rep.c   | 15 +
 drivers/net/ethernet/mellanox/mlx5/core/en_tc.c|  2 +-
 drivers/net/ethernet/mellanox/mlx5/core/en_tc.h|  2 +-
 drivers/net/ethernet/mellanox/mlxsw/spectrum.c | 25 --
 drivers/net/ethernet/mellanox/mlxsw/spectrum.h |  2 +-
 .../net/ethernet/mellanox/mlxsw/spectrum_flower.c  |  2 +-
 drivers/net/ethernet/netronome/nfp/bpf/main.c  | 10 +
 drivers/net/ethernet/netronome/nfp/flower/main.h   |  3 +--
 .../net/ethernet/netronome/nfp/flower/offload.c| 12 ++-
 drivers/net/ethernet/netronome/nfp/nfp_app.h   |  6 ++
 drivers/net/ethernet/netronome/nfp/nfp_port.c  |  6 +-
 drivers/net/ethernet/netronome/nfp/nfp_port.h  |  1 -
 drivers/net/ethernet/sfc/efx.h |  1 -
 drivers/net/ethernet/sfc/falcon/efx.h  |  1 -
 drivers/net/ethernet/sfc/falcon/tx.c   |  1 -
 drivers/net/ethernet/sfc/tx.c  |  1 -
 drivers/net/ethernet/ti/netcp_core.c   |  1 -
 include/linux/netdevice.h  |  3 ---
 include/net/pkt_cls.h  | 19 
 net/dsa/slave.c| 14 +---
 net/sched/cls_bpf.c|  7 ++
 net/sched/cls_flower.c | 13 ++-
 net/sched/cls_matchall.c   |  8 +++
 net/sched/cls_u32.c| 20 +++--
 net/sched/sch_mqprio.c |  6 ++
 38 files changed, 101 insertions(+), 143 deletions(-)

diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-drv.c 
b/drivers/net/ethernet/amd/xgbe/xgbe-drv.c
index 6a6ea3b..bbb7bfe 100644
--- a/drivers/net/ethernet/amd/xgbe/xgbe-drv.c
+++ b/drivers/net/ethernet/amd/xgbe/xgbe-drv.c
@@ -1919,7 +1919,6 @@ static void xgbe_poll_controller(struct net_device 
*netdev)
 #endif /* End CONFIG_NET_POLL_CONTROLLER */
 
 static int xgbe_setup_tc(struct net_device *netdev, enum tc_setup_type type,
-u32 handle, u32 chain_index, __be16 proto,
 struct tc_to_netdev *tc_to_netdev)
 {
struct xgbe_prv_data *pdata = netdev_priv(netdev);
diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c 
b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c
index 4395d1c..257cf4b 100644
--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c
+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c
@@ -4285,7 +4285,6 @@ int bnx2x_setup_tc(struct net_device *dev, u8 num_tc)
 }
 
 int __bnx2x_setup_tc(struct net_device *dev, enum tc_setup_type type,
-u32 handle, u32 chain_index, __be16 proto,
 struct tc_to_netdev *tc)
 {
if (type != TC_SETUP_MQPRIO)
diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h 
b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
index 1ac4eb0..04eb950 100644
--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
@@ -487,7 +487,6 @@ netdev_tx_t bnx2x_start_xmit(struct sk_buff *skb, struct 
net_device *dev);
 /* setup_tc callback */
 int bnx2x_setup_tc(struct net_device *dev, u8 num_tc);
 int __bnx2x_setup_tc(struct net_device *dev, enum tc_setup_type type,
-u32 handle, u32 chain_index, __be16 proto,
 struct tc_to_netdev *tc);
 
 int bnx2x_get_vf_config(struct net_device *dev, int vf,
diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt.c 
b/drivers/net/ethernet/broadcom/bnxt/bnxt.c
index b98d9f3..1545b88 100644
--- a/drivers/net/ethernet/broadcom/bnxt/bnxt.c
+++ b/drivers/net/ethernet/broadcom/bnxt/bnxt.c
@@ -7238,7 +7238,6 @@ int bnxt_setup_mq_tc(struct net_device *dev, u8 tc)
 }
 
 static int bnxt_setup_tc(struct net_device *dev, enum tc_setup_type type,
-  

[patch net-next 15/15] net: sched: get rid of struct tc_to_netdev

2017-08-05 Thread Jiri Pirko
From: Jiri Pirko 

Get rid of struct tc_to_netdev which is now just unnecessary container
and rather pass per-type structures down to drivers directly.
Along with that, consolidate the naming of per-type structure variables
in cls_*.

Signed-off-by: Jiri Pirko 
---
 drivers/net/ethernet/amd/xgbe/xgbe-drv.c   |  7 +-
 drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c|  8 ++-
 drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h|  2 +-
 drivers/net/ethernet/broadcom/bnxt/bnxt.c  |  8 ++-
 drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c|  4 +-
 drivers/net/ethernet/freescale/dpaa/dpaa_eth.c |  7 +-
 drivers/net/ethernet/intel/fm10k/fm10k_netdev.c|  8 ++-
 drivers/net/ethernet/intel/i40e/i40e_main.c|  8 ++-
 drivers/net/ethernet/intel/ixgbe/ixgbe_main.c  |  6 +-
 drivers/net/ethernet/mellanox/mlx4/en_netdev.c | 10 +--
 drivers/net/ethernet/mellanox/mlx5/core/en_main.c  |  6 +-
 drivers/net/ethernet/mellanox/mlx5/core/en_rep.c   | 12 ++--
 drivers/net/ethernet/mellanox/mlx5/core/en_tc.h|  2 +
 drivers/net/ethernet/mellanox/mlxsw/spectrum.c |  8 +--
 drivers/net/ethernet/netronome/nfp/bpf/main.c  |  5 +-
 drivers/net/ethernet/netronome/nfp/flower/main.h   |  4 +-
 .../net/ethernet/netronome/nfp/flower/offload.c|  4 +-
 drivers/net/ethernet/netronome/nfp/nfp_app.h   |  8 +--
 drivers/net/ethernet/netronome/nfp/nfp_port.c  |  4 +-
 drivers/net/ethernet/netronome/nfp/nfp_port.h  |  3 +-
 drivers/net/ethernet/sfc/efx.h |  2 +-
 drivers/net/ethernet/sfc/falcon/efx.h  |  2 +-
 drivers/net/ethernet/sfc/falcon/tx.c   |  7 +-
 drivers/net/ethernet/sfc/tx.c  |  7 +-
 drivers/net/ethernet/ti/netcp_core.c   |  7 +-
 include/linux/netdevice.h  | 19 +
 net/dsa/slave.c|  4 +-
 net/sched/cls_bpf.c| 21 +++---
 net/sched/cls_flower.c | 54 ++
 net/sched/cls_matchall.c   | 27 +++
 net/sched/cls_u32.c| 83 ++
 net/sched/sch_mqprio.c | 13 ++--
 32 files changed, 170 insertions(+), 200 deletions(-)

diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-drv.c 
b/drivers/net/ethernet/amd/xgbe/xgbe-drv.c
index 37d3e5b..2fd9b80 100644
--- a/drivers/net/ethernet/amd/xgbe/xgbe-drv.c
+++ b/drivers/net/ethernet/amd/xgbe/xgbe-drv.c
@@ -1919,16 +1919,17 @@ static void xgbe_poll_controller(struct net_device 
*netdev)
 #endif /* End CONFIG_NET_POLL_CONTROLLER */
 
 static int xgbe_setup_tc(struct net_device *netdev, enum tc_setup_type type,
-struct tc_to_netdev *tc_to_netdev)
+void *type_data)
 {
struct xgbe_prv_data *pdata = netdev_priv(netdev);
+   struct tc_mqprio_qopt *mqprio = type_data;
u8 tc;
 
if (type != TC_SETUP_MQPRIO)
return -EOPNOTSUPP;
 
-   tc_to_netdev->mqprio->hw = TC_MQPRIO_HW_OFFLOAD_TCS;
-   tc = tc_to_netdev->mqprio->num_tc;
+   mqprio->hw = TC_MQPRIO_HW_OFFLOAD_TCS;
+   tc = mqprio->num_tc;
 
if (tc > pdata->hw_feat.tc_cnt)
return -EINVAL;
diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c 
b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c
index 8687afc..1216c1f 100644
--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c
+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c
@@ -4285,14 +4285,16 @@ int bnx2x_setup_tc(struct net_device *dev, u8 num_tc)
 }
 
 int __bnx2x_setup_tc(struct net_device *dev, enum tc_setup_type type,
-struct tc_to_netdev *tc)
+void *type_data)
 {
+   struct tc_mqprio_qopt *mqprio = type_data;
+
if (type != TC_SETUP_MQPRIO)
return -EOPNOTSUPP;
 
-   tc->mqprio->hw = TC_MQPRIO_HW_OFFLOAD_TCS;
+   mqprio->hw = TC_MQPRIO_HW_OFFLOAD_TCS;
 
-   return bnx2x_setup_tc(dev, tc->mqprio->num_tc);
+   return bnx2x_setup_tc(dev, mqprio->num_tc);
 }
 
 /* called with rtnl_lock */
diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h 
b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
index 04eb950..a5265e1 100644
--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
@@ -487,7 +487,7 @@ netdev_tx_t bnx2x_start_xmit(struct sk_buff *skb, struct 
net_device *dev);
 /* setup_tc callback */
 int bnx2x_setup_tc(struct net_device *dev, u8 num_tc);
 int __bnx2x_setup_tc(struct net_device *dev, enum tc_setup_type type,
-struct tc_to_netdev *tc);
+void *type_data);
 
 int bnx2x_get_vf_config(struct net_device *dev, int vf,
struct ifla_vf_info *ivi);
diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt.c 
b/drivers/net/ethernet/broadcom/bnxt/bnxt.c
index 

[patch net-next 11/15] nfp: change flows in apps that offload ndo_setup_tc

2017-08-05 Thread Jiri Pirko
From: Jiri Pirko 

Change the flows a bit in preparation of follow-up changes in
ndo_setup_tc args. Also, change the error code to align with the rest of
the drivers.

Signed-off-by: Jiri Pirko 
---
 drivers/net/ethernet/netronome/nfp/bpf/main.c   | 16 ++--
 drivers/net/ethernet/netronome/nfp/flower/offload.c | 10 +++---
 2 files changed, 9 insertions(+), 17 deletions(-)

diff --git a/drivers/net/ethernet/netronome/nfp/bpf/main.c 
b/drivers/net/ethernet/netronome/nfp/bpf/main.c
index 708..d7975dc 100644
--- a/drivers/net/ethernet/netronome/nfp/bpf/main.c
+++ b/drivers/net/ethernet/netronome/nfp/bpf/main.c
@@ -126,19 +126,15 @@ static int nfp_bpf_setup_tc(struct nfp_app *app, struct 
net_device *netdev,
 {
struct nfp_net *nn = netdev_priv(netdev);
 
-   if (TC_H_MAJ(handle) != TC_H_MAJ(TC_H_INGRESS))
-   return -EOPNOTSUPP;
-   if (proto != htons(ETH_P_ALL))
+   if (type != TC_SETUP_CLSBPF || !nfp_net_ebpf_capable(nn) ||
+   TC_H_MAJ(handle) != TC_H_MAJ(TC_H_INGRESS) ||
+   proto != htons(ETH_P_ALL))
return -EOPNOTSUPP;
 
-   if (type == TC_SETUP_CLSBPF && nfp_net_ebpf_capable(nn)) {
-   if (!nn->dp.bpf_offload_xdp)
-   return nfp_net_bpf_offload(nn, tc->cls_bpf);
-   else
-   return -EBUSY;
-   }
+   if (nn->dp.bpf_offload_xdp)
+   return -EBUSY;
 
-   return -EINVAL;
+   return nfp_net_bpf_offload(nn, tc->cls_bpf);
 }
 
 static bool nfp_bpf_tc_busy(struct nfp_app *app, struct nfp_net *nn)
diff --git a/drivers/net/ethernet/netronome/nfp/flower/offload.c 
b/drivers/net/ethernet/netronome/nfp/flower/offload.c
index d045cf8..58af438 100644
--- a/drivers/net/ethernet/netronome/nfp/flower/offload.c
+++ b/drivers/net/ethernet/netronome/nfp/flower/offload.c
@@ -388,14 +388,10 @@ int nfp_flower_setup_tc(struct nfp_app *app, struct 
net_device *netdev,
enum tc_setup_type type, u32 handle, __be16 proto,
struct tc_to_netdev *tc)
 {
-   if (TC_H_MAJ(handle) != TC_H_MAJ(TC_H_INGRESS))
+   if (type != TC_SETUP_CLSFLOWER ||
+   TC_H_MAJ(handle) != TC_H_MAJ(TC_H_INGRESS) ||
+   !eth_proto_is_802_3(proto))
return -EOPNOTSUPP;
 
-   if (!eth_proto_is_802_3(proto))
-   return -EOPNOTSUPP;
-
-   if (type != TC_SETUP_CLSFLOWER)
-   return -EINVAL;
-
return nfp_flower_repr_offload(app, netdev, tc->cls_flower);
 }
-- 
2.9.3



[patch net-next 08/15] mlxsw: spectrum: push cls_flower and cls_matchall setup_tc processing into separate functions

2017-08-05 Thread Jiri Pirko
From: Jiri Pirko 

Let mlxsw_sp_setup_tc be a splitter for specific setup_tc types and push
out cls_flower and cls_matchall specific codes into separate functions.

Signed-off-by: Jiri Pirko 
---
 drivers/net/ethernet/mellanox/mlxsw/spectrum.c | 81 --
 1 file changed, 51 insertions(+), 30 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum.c 
b/drivers/net/ethernet/mellanox/mlxsw/spectrum.c
index 6438c38..9f8ba37 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum.c
@@ -1693,46 +1693,67 @@ static void mlxsw_sp_port_del_cls_matchall(struct 
mlxsw_sp_port *mlxsw_sp_port,
kfree(mall_tc_entry);
 }
 
-static int mlxsw_sp_setup_tc(struct net_device *dev, enum tc_setup_type type,
+static int mlxsw_sp_setup_tc_cls_matchall(struct mlxsw_sp_port *mlxsw_sp_port,
+ u32 handle, u32 chain_index,
+ __be16 proto,
+ struct tc_cls_matchall_offload *f)
+{
+   bool ingress = TC_H_MAJ(handle) == TC_H_MAJ(TC_H_INGRESS);
+
+   if (chain_index)
+   return -EOPNOTSUPP;
+
+   switch (f->command) {
+   case TC_CLSMATCHALL_REPLACE:
+   return mlxsw_sp_port_add_cls_matchall(mlxsw_sp_port, proto, f,
+ ingress);
+   case TC_CLSMATCHALL_DESTROY:
+   mlxsw_sp_port_del_cls_matchall(mlxsw_sp_port, f);
+   return 0;
+   default:
+   return -EOPNOTSUPP;
+   }
+}
+
+static int
+mlxsw_sp_setup_tc_cls_flower(struct mlxsw_sp_port *mlxsw_sp_port,
 u32 handle, u32 chain_index, __be16 proto,
-struct tc_to_netdev *tc)
+struct tc_cls_flower_offload *f)
 {
-   struct mlxsw_sp_port *mlxsw_sp_port = netdev_priv(dev);
bool ingress = TC_H_MAJ(handle) == TC_H_MAJ(TC_H_INGRESS);
 
if (chain_index)
return -EOPNOTSUPP;
 
+   switch (f->command) {
+   case TC_CLSFLOWER_REPLACE:
+   return mlxsw_sp_flower_replace(mlxsw_sp_port, ingress,
+  proto, f);
+   case TC_CLSFLOWER_DESTROY:
+   mlxsw_sp_flower_destroy(mlxsw_sp_port, ingress, f);
+   return 0;
+   case TC_CLSFLOWER_STATS:
+   return mlxsw_sp_flower_stats(mlxsw_sp_port, ingress, f);
+   default:
+   return -EOPNOTSUPP;
+   }
+}
+
+static int mlxsw_sp_setup_tc(struct net_device *dev, enum tc_setup_type type,
+u32 handle, u32 chain_index, __be16 proto,
+struct tc_to_netdev *tc)
+{
+   struct mlxsw_sp_port *mlxsw_sp_port = netdev_priv(dev);
+
switch (type) {
case TC_SETUP_CLSMATCHALL:
-   switch (tc->cls_mall->command) {
-   case TC_CLSMATCHALL_REPLACE:
-   return mlxsw_sp_port_add_cls_matchall(mlxsw_sp_port,
- proto,
- tc->cls_mall,
- ingress);
-   case TC_CLSMATCHALL_DESTROY:
-   mlxsw_sp_port_del_cls_matchall(mlxsw_sp_port,
-  tc->cls_mall);
-   return 0;
-   default:
-   return -EOPNOTSUPP;
-   }
+   return mlxsw_sp_setup_tc_cls_matchall(mlxsw_sp_port, handle,
+ chain_index, proto,
+ tc->cls_mall);
case TC_SETUP_CLSFLOWER:
-   switch (tc->cls_flower->command) {
-   case TC_CLSFLOWER_REPLACE:
-   return mlxsw_sp_flower_replace(mlxsw_sp_port, ingress,
-  proto, tc->cls_flower);
-   case TC_CLSFLOWER_DESTROY:
-   mlxsw_sp_flower_destroy(mlxsw_sp_port, ingress,
-   tc->cls_flower);
-   return 0;
-   case TC_CLSFLOWER_STATS:
-   return mlxsw_sp_flower_stats(mlxsw_sp_port, ingress,
-tc->cls_flower);
-   default:
-   return -EOPNOTSUPP;
-   }
+   return mlxsw_sp_setup_tc_cls_flower(mlxsw_sp_port, handle,
+   chain_index, proto,
+   tc->cls_flower);
default:
return -EOPNOTSUPP;
}
-- 
2.9.3



[patch net-next 00/15] net: sched: summer cleanup part 2, ndo_setup_tc

2017-08-05 Thread Jiri Pirko
From: Jiri Pirko 

This patchset focuses on ndo_setup_tc and its args.
Currently there are couple of things that do not make much sense.
The type is passed in struct tc_to_netdev, but as it is always
required, should be arg of the ndo. Other things are passed as args
but they are only relevant for cls offloads and not mqprio. Therefore,
they should be pushed to struct. As the tc_to_netdev struct in the end
is just a container of single pointer, we get rid of it and pass the
struct according to type. So in the end, we have:
ndo_setup_tc(dev, type, type_data_struct)

There are couple of cosmetics done on the way to make things smooth.
Also, reported error is consolidated to eopnotsupp in case the
asked offload is not supported.

Jiri Pirko (15):
  net: sched: make type an argument for ndo_setup_tc
  net: sched: rename TC_SETUP_MATCHALL to TC_SETUP_CLSMATCHALL
  net: sched: make egress_dev flag part of flower offload struct
  cxgb4: push cls_u32 setup_tc processing into a separate function
  ixgbe: push cls_u32 and mqprio setup_tc processing into separate
functions
  mlx5e: push cls_flower and mqprio setup_tc processing into separate
functions
  mlx5e_rep: push cls_flower setup_tc processing into a separate
function
  mlxsw: spectrum: push cls_flower and cls_matchall setup_tc processing
into separate functions
  mlxsw: spectrum: rename cls arg in matchall processing
  dsa: push cls_matchall setup_tc processing into a separate function
  nfp: change flows in apps that offload ndo_setup_tc
  net: sched: push cls related args into cls_common structure
  net: sched: move prio into cls_common
  net: sched: change return value of ndo_setup_tc for driver supporting
mqprio only
  net: sched: get rid of struct tc_to_netdev

 drivers/net/ethernet/amd/xgbe/xgbe-drv.c   |  14 +--
 drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c|  14 +--
 drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h|   4 +-
 drivers/net/ethernet/broadcom/bnxt/bnxt.c  |  14 +--
 drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c|  43 +
 drivers/net/ethernet/chelsio/cxgb4/cxgb4_tc_u32.c  |   7 +-
 drivers/net/ethernet/chelsio/cxgb4/cxgb4_tc_u32.h  |   6 +-
 drivers/net/ethernet/freescale/dpaa/dpaa_eth.c |  13 +--
 drivers/net/ethernet/intel/fm10k/fm10k_netdev.c|  14 +--
 drivers/net/ethernet/intel/i40e/i40e_main.c|  15 +--
 drivers/net/ethernet/intel/ixgbe/ixgbe_main.c  |  65 +++--
 drivers/net/ethernet/mellanox/mlx4/en_netdev.c |  17 ++--
 drivers/net/ethernet/mellanox/mlx5/core/en_main.c  |  55 +--
 drivers/net/ethernet/mellanox/mlx5/core/en_rep.c   |  45 +
 drivers/net/ethernet/mellanox/mlx5/core/en_tc.c|   2 +-
 drivers/net/ethernet/mellanox/mlx5/core/en_tc.h|   4 +-
 drivers/net/ethernet/mellanox/mlxsw/spectrum.c | 102 -
 drivers/net/ethernet/mellanox/mlxsw/spectrum.h |   2 +-
 .../net/ethernet/mellanox/mlxsw/spectrum_flower.c  |   4 +-
 drivers/net/ethernet/netronome/nfp/bpf/main.c  |  20 ++--
 drivers/net/ethernet/netronome/nfp/flower/main.h   |   4 +-
 .../net/ethernet/netronome/nfp/flower/offload.c|  15 ++-
 drivers/net/ethernet/netronome/nfp/nfp_app.h   |   8 +-
 drivers/net/ethernet/netronome/nfp/nfp_port.c  |   9 +-
 drivers/net/ethernet/netronome/nfp/nfp_port.h  |   5 +-
 drivers/net/ethernet/sfc/efx.h |   4 +-
 drivers/net/ethernet/sfc/falcon/efx.h  |   4 +-
 drivers/net/ethernet/sfc/falcon/tx.c   |  13 +--
 drivers/net/ethernet/sfc/tx.c  |  13 +--
 drivers/net/ethernet/ti/netcp_core.c   |  13 +--
 include/linux/netdevice.h  |  30 ++
 include/net/pkt_cls.h  |  23 -
 net/dsa/slave.c|  39 
 net/sched/cls_bpf.c|  24 ++---
 net/sched/cls_flower.c |  60 +---
 net/sched/cls_matchall.c   |  31 +++
 net/sched/cls_u32.c|  95 ---
 net/sched/sch_mqprio.c |  16 ++--
 38 files changed, 431 insertions(+), 435 deletions(-)

-- 
2.9.3



[patch net-next 02/15] net: sched: rename TC_SETUP_MATCHALL to TC_SETUP_CLSMATCHALL

2017-08-05 Thread Jiri Pirko
From: Jiri Pirko 

In order to be aligned with the rest of the types, rename
TC_SETUP_MATCHALL to TC_SETUP_CLSMATCHALL.

Signed-off-by: Jiri Pirko 
---
 drivers/net/ethernet/mellanox/mlxsw/spectrum.c | 2 +-
 include/linux/netdevice.h  | 2 +-
 net/dsa/slave.c| 2 +-
 net/sched/cls_matchall.c   | 4 ++--
 4 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum.c 
b/drivers/net/ethernet/mellanox/mlxsw/spectrum.c
index 1554242..6438c38 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum.c
@@ -1704,7 +1704,7 @@ static int mlxsw_sp_setup_tc(struct net_device *dev, enum 
tc_setup_type type,
return -EOPNOTSUPP;
 
switch (type) {
-   case TC_SETUP_MATCHALL:
+   case TC_SETUP_CLSMATCHALL:
switch (tc->cls_mall->command) {
case TC_CLSMATCHALL_REPLACE:
return mlxsw_sp_port_add_cls_matchall(mlxsw_sp_port,
diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index e4238e5..f8051a3 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -778,7 +778,7 @@ enum tc_setup_type {
TC_SETUP_MQPRIO,
TC_SETUP_CLSU32,
TC_SETUP_CLSFLOWER,
-   TC_SETUP_MATCHALL,
+   TC_SETUP_CLSMATCHALL,
TC_SETUP_CLSBPF,
 };
 
diff --git a/net/dsa/slave.c b/net/dsa/slave.c
index 2946fad..a02d22b 100644
--- a/net/dsa/slave.c
+++ b/net/dsa/slave.c
@@ -860,7 +860,7 @@ static int dsa_slave_setup_tc(struct net_device *dev, enum 
tc_setup_type type,
return -EOPNOTSUPP;
 
switch (type) {
-   case TC_SETUP_MATCHALL:
+   case TC_SETUP_CLSMATCHALL:
switch (tc->cls_mall->command) {
case TC_CLSMATCHALL_REPLACE:
return dsa_slave_add_cls_matchall(dev, protocol,
diff --git a/net/sched/cls_matchall.c b/net/sched/cls_matchall.c
index 6ffe0b8..a8853ad 100644
--- a/net/sched/cls_matchall.c
+++ b/net/sched/cls_matchall.c
@@ -63,7 +63,7 @@ static int mall_replace_hw_filter(struct tcf_proto *tp,
offload.cls_mall->exts = >exts;
offload.cls_mall->cookie = cookie;
 
-   err = dev->netdev_ops->ndo_setup_tc(dev, TC_SETUP_MATCHALL,
+   err = dev->netdev_ops->ndo_setup_tc(dev, TC_SETUP_CLSMATCHALL,
tp->q->handle, tp->chain->index,
tp->protocol, );
if (!err)
@@ -85,7 +85,7 @@ static void mall_destroy_hw_filter(struct tcf_proto *tp,
offload.cls_mall->exts = NULL;
offload.cls_mall->cookie = cookie;
 
-   dev->netdev_ops->ndo_setup_tc(dev, TC_SETUP_MATCHALL, tp->q->handle,
+   dev->netdev_ops->ndo_setup_tc(dev, TC_SETUP_CLSMATCHALL, tp->q->handle,
  tp->chain->index, tp->protocol, );
 }
 
-- 
2.9.3



[patch net-next 03/15] net: sched: make egress_dev flag part of flower offload struct

2017-08-05 Thread Jiri Pirko
From: Jiri Pirko 

Since this is specific to flower now, make it part of the flower offload
struct.

Signed-off-by: Jiri Pirko 
---
 drivers/net/ethernet/mellanox/mlx5/core/en_rep.c | 2 +-
 include/linux/netdevice.h| 1 -
 include/net/pkt_cls.h| 1 +
 net/sched/cls_flower.c   | 2 +-
 4 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c 
b/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c
index d44049e..0e6bab1 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c
@@ -661,7 +661,7 @@ static int mlx5e_rep_ndo_setup_tc(struct net_device *dev,
if (TC_H_MAJ(handle) != TC_H_MAJ(TC_H_INGRESS))
return -EOPNOTSUPP;
 
-   if (tc->egress_dev) {
+   if (type == TC_SETUP_CLSFLOWER && tc->cls_flower->egress_dev) {
struct mlx5_eswitch *esw = priv->mdev->priv.eswitch;
struct net_device *uplink_dev = 
mlx5_eswitch_get_uplink_netdev(esw);
 
diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index f8051a3..bd49dba 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -792,7 +792,6 @@ struct tc_to_netdev {
struct tc_cls_bpf_offload *cls_bpf;
struct tc_mqprio_qopt *mqprio;
};
-   bool egress_dev;
 };
 
 /* These structures hold the attributes of xdp state that are being passed
diff --git a/include/net/pkt_cls.h b/include/net/pkt_cls.h
index e0c54f1..8213acd 100644
--- a/include/net/pkt_cls.h
+++ b/include/net/pkt_cls.h
@@ -504,6 +504,7 @@ struct tc_cls_flower_offload {
struct fl_flow_key *mask;
struct fl_flow_key *key;
struct tcf_exts *exts;
+   bool egress_dev;
 };
 
 enum tc_matchall_command {
diff --git a/net/sched/cls_flower.c b/net/sched/cls_flower.c
index ddeed17..52deeed 100644
--- a/net/sched/cls_flower.c
+++ b/net/sched/cls_flower.c
@@ -259,7 +259,7 @@ static int fl_hw_replace_filter(struct tcf_proto *tp,
return tc_skip_sw(f->flags) ? -EINVAL : 0;
}
dev = f->hw_dev;
-   tc->egress_dev = true;
+   offload.egress_dev = true;
} else {
f->hw_dev = dev;
}
-- 
2.9.3



[PATCH][net-next] net: hns3: fix spelling mistake: "capabilty" -> "capability"

2017-08-05 Thread Colin King
From: Colin Ian King 

Trivial fix to spelling mistake in dev_err error message and also
split overly long line to avoid a checkpatch warning.

Signed-off-by: Colin Ian King 
---
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index 3611991689bc..770c06d80438 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -4091,7 +4091,8 @@ static int hclge_init_ae_dev(struct hnae3_ae_dev *ae_dev)
 
ret = hclge_get_cap(hdev);
if (ret) {
-   dev_err(>dev, "get hw capabilty error, ret = %d.\n", ret);
+   dev_err(>dev, "get hw capability error, ret = %d.\n",
+   ret);
return ret;
}
 
-- 
2.11.0



Re: [PATCH net-next] lwtunnel: replace EXPORT_SYMBOL with EXPORT_SYMBOL_GPL

2017-08-05 Thread kbuild test robot
Hi Roopa,

[auto build test ERROR on net-next/master]

url:
https://github.com/0day-ci/linux/commits/Roopa-Prabhu/lwtunnel-replace-EXPORT_SYMBOL-with-EXPORT_SYMBOL_GPL/20170805-212202
config: blackfin-allyesconfig (attached as .config)
compiler: bfin-uclinux-gcc (GCC) 6.2.0
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=blackfin 

All error/warnings (new ones prefixed by >>):

>> net//core/lwtunnel.c:68:1: warning: data definition has no type or storage 
>> class
EXPORT_SYMBOL_GPL_GPL(lwtunnel_state_alloc);
^
>> net//core/lwtunnel.c:68:1: error: type defaults to 'int' in declaration of 
>> 'EXPORT_SYMBOL_GPL_GPL' [-Werror=implicit-int]
>> net//core/lwtunnel.c:68:1: warning: parameter names (without types) in 
>> function declaration
   cc1: some warnings being treated as errors

vim +68 net//core/lwtunnel.c

59  
60  struct lwtunnel_state *lwtunnel_state_alloc(int encap_len)
61  {
62  struct lwtunnel_state *lws;
63  
64  lws = kzalloc(sizeof(*lws) + encap_len, GFP_ATOMIC);
65  
66  return lws;
67  }
  > 68  EXPORT_SYMBOL_GPL_GPL(lwtunnel_state_alloc);
69  

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


.config.gz
Description: application/gzip


[PATCH 4/4] atm: idt77252: Adjust ten checks for null pointers

2017-08-05 Thread SF Markus Elfring
From: Markus Elfring 
Date: Sat, 5 Aug 2017 14:04:42 +0200
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

The script “checkpatch.pl” pointed information out like the following.

Comparison to NULL could be written !…

Thus fix the affected source code places.

Signed-off-by: Markus Elfring 
---
 drivers/atm/idt77252.c | 20 ++--
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
index e26e36a934e9..184934e05193 100644
--- a/drivers/atm/idt77252.c
+++ b/drivers/atm/idt77252.c
@@ -643,7 +643,7 @@ alloc_scq(struct idt77252_dev *card, int class)
return NULL;
scq->base = dma_zalloc_coherent(>pcidev->dev, SCQ_SIZE,
>paddr, GFP_KERNEL);
-   if (scq->base == NULL) {
+   if (!scq->base) {
kfree(scq);
return NULL;
}
@@ -973,7 +973,7 @@ init_rsq(struct idt77252_dev *card)
 
card->rsq.base = dma_zalloc_coherent(>pcidev->dev, RSQSIZE,
 >rsq.paddr, GFP_KERNEL);
-   if (card->rsq.base == NULL) {
+   if (!card->rsq.base) {
printk("%s: can't allocate RSQ.\n", card->name);
return -1;
}
@@ -1026,7 +1026,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry 
*rsqe)
}
 
skb = sb_pool_skb(card, le32_to_cpu(rsqe->word_2));
-   if (skb == NULL) {
+   if (!skb) {
printk("%s: NULL skb in %s, rsqe: %08x %08x %08x %08x\n",
   card->name, __func__,
   le32_to_cpu(rsqe->word_1), le32_to_cpu(rsqe->word_2),
@@ -1242,7 +1242,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
struct vc_map   *vc;
struct sk_buff  *sb;
 
-   if (card->raw_cell_head == NULL) {
+   if (!card->raw_cell_head) {
u32 handle = le32_to_cpu(*(card->raw_cell_hnd + 1));
card->raw_cell_head = sb_pool_skb(card, handle);
}
@@ -1375,7 +1375,7 @@ init_tsq(struct idt77252_dev *card)
 
card->tsq.base = dma_alloc_coherent(>pcidev->dev, RSQSIZE,
>tsq.paddr, GFP_KERNEL);
-   if (card->tsq.base == NULL) {
+   if (!card->tsq.base) {
printk("%s: can't allocate TSQ.\n", card->name);
return -1;
}
@@ -1601,7 +1601,7 @@ __fill_tst(struct idt77252_dev *card, struct vc_map *vc,
 
avail = card->tst_size - 2;
for (e = 0; e < avail; e++) {
-   if (card->soft_tst[e].vc == NULL)
+   if (!card->soft_tst[e].vc)
break;
}
if (e >= avail) {
@@ -1624,7 +1624,7 @@ __fill_tst(struct idt77252_dev *card, struct vc_map *vc,
 * Fill Soft TST.
 */
while (r > 0) {
-   if ((cl >= avail) && (card->soft_tst[e].vc == NULL)) {
+   if ((cl >= avail) && !card->soft_tst[e].vc) {
if (vc)
card->soft_tst[e].vc = vc;
else
@@ -1948,7 +1948,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff 
*skb, int oam)
struct vc_map *vc = vcc->dev_data;
int err;
 
-   if (vc == NULL) {
+   if (!vc) {
printk("%s: NULL connection in send().\n", card->name);
atomic_inc(>stats->tx_err);
dev_kfree_skb(skb);
@@ -3429,12 +3429,12 @@ static int init_card(struct atm_dev *dev)
card->soft_tst[i].vc = NULL;
}
 
-   if (dev->phy == NULL) {
+   if (!dev->phy) {
printk("%s: No LT device defined.\n", card->name);
deinit_card(card);
return -1;
}
-   if (dev->phy->ioctl == NULL) {
+   if (!dev->phy->ioctl) {
printk("%s: LT had no IOCTL function defined.\n", card->name);
deinit_card(card);
return -1;
-- 
2.13.4



[PATCH net] sctp: use __GFP_NOWARN for sctpw.fifo allocation

2017-08-05 Thread Xin Long
Chen Wei found a kernel call trace when modprobe sctp_probe with
bufsize set with a huge value.

It's because in sctpprobe_init when alloc memory for sctpw.fifo,
the size is got from userspace. If it is too large, kernel will
fail and give a warning.

As there will be a fallback allocation later, this patch is just
to fail silently and return ret, just as commit 0ccc22f425e5
("sit: use __GFP_NOWARN for user controlled allocation") did.

Reported-by: Chen Wei 
Signed-off-by: Xin Long 
---
 net/sctp/probe.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/sctp/probe.c b/net/sctp/probe.c
index 6cc2152..5bf3164 100644
--- a/net/sctp/probe.c
+++ b/net/sctp/probe.c
@@ -210,7 +210,7 @@ static __init int sctpprobe_init(void)
 
init_waitqueue_head();
spin_lock_init();
-   if (kfifo_alloc(, bufsize, GFP_KERNEL))
+   if (kfifo_alloc(, bufsize, GFP_KERNEL | __GFP_NOWARN))
return ret;
 
if (!proc_create(procname, S_IRUSR, init_net.proc_net,
-- 
2.1.0



[PATCH 3/4] atm: idt77252: Improve seven size determinations

2017-08-05 Thread SF Markus Elfring
From: Markus Elfring 
Date: Sat, 5 Aug 2017 13:51:04 +0200

Replace the specification of data structures by pointer dereferences
as the parameter for the operator "sizeof" to make the corresponding size
determination a bit safer according to the Linux coding style convention.

Signed-off-by: Markus Elfring 
---
 drivers/atm/idt77252.c | 17 -
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
index 434dc4ee5f15..e26e36a934e9 100644
--- a/drivers/atm/idt77252.c
+++ b/drivers/atm/idt77252.c
@@ -638,7 +638,7 @@ alloc_scq(struct idt77252_dev *card, int class)
 {
struct scq_info *scq;
 
-   scq = kzalloc(sizeof(struct scq_info), GFP_KERNEL);
+   scq = kzalloc(sizeof(*scq), GFP_KERNEL);
if (!scq)
return NULL;
scq->base = dma_zalloc_coherent(>pcidev->dev, SCQ_SIZE,
@@ -2119,7 +2119,7 @@ idt77252_init_est(struct vc_map *vc, int pcr)
 {
struct rate_estimator *est;
 
-   est = kzalloc(sizeof(struct rate_estimator), GFP_KERNEL);
+   est = kzalloc(sizeof(*est), GFP_KERNEL);
if (!est)
return NULL;
est->maxcps = pcr < 0 ? -pcr : pcr;
@@ -2422,7 +2422,8 @@ idt77252_open(struct atm_vcc *vcc)
 
index = VPCI2VC(card, vpi, vci);
if (!card->vcs[index]) {
-   card->vcs[index] = kzalloc(sizeof(struct vc_map), GFP_KERNEL);
+   card->vcs[index] = kzalloc(sizeof(*card->vcs[index]),
+  GFP_KERNEL);
if (!card->vcs[index]) {
mutex_unlock(>mutex);
return -ENOMEM;
@@ -2612,8 +2613,7 @@ idt77252_change_qos(struct atm_vcc *vcc, struct atm_qos 
*qos, int flags)
goto out;
}
 
-   memcpy(>qos, qos, sizeof(struct atm_qos));
-
+   memcpy(>qos, qos, sizeof(*qos));
set_bit(ATM_VF_HASQOS, >flags);
 
 out:
@@ -2851,8 +2851,7 @@ open_card_oam(struct idt77252_dev *card)
for (vpi = 0; vpi < (1 << card->vpibits); vpi++) {
for (vci = 3; vci < 5; vci++) {
index = VPCI2VC(card, vpi, vci);
-
-   vc = kzalloc(sizeof(struct vc_map), GFP_KERNEL);
+   vc = kzalloc(sizeof(*vc), GFP_KERNEL);
if (!vc)
return -ENOMEM;
 
@@ -2918,7 +2917,7 @@ open_card_ubr0(struct idt77252_dev *card)
 {
struct vc_map *vc;
 
-   vc = kzalloc(sizeof(struct vc_map), GFP_KERNEL);
+   vc = kzalloc(sizeof(*vc), GFP_KERNEL);
if (!vc)
return -ENOMEM;
 
@@ -3605,7 +3604,7 @@ static int idt77252_init_one(struct pci_dev *pcidev,
return err;
}
 
-   card = kzalloc(sizeof(struct idt77252_dev), GFP_KERNEL);
+   card = kzalloc(sizeof(*card), GFP_KERNEL);
if (!card) {
err = -ENOMEM;
goto err_out_disable_pdev;
-- 
2.13.4



[PATCH 2/4] atm: idt77252: Delete an error message for a failed memory allocation in seven functions

2017-08-05 Thread SF Markus Elfring
From: Markus Elfring 
Date: Sat, 5 Aug 2017 12:45:34 +0200

Omit an extra message for a memory allocation failure in these functions.

This issue was detected by using the Coccinelle software.

Link: 
http://events.linuxfoundation.org/sites/events/files/slides/LCJ16-Refactor_Strings-WSang_0.pdf
Signed-off-by: Markus Elfring 
---
 drivers/atm/idt77252.c | 18 --
 1 file changed, 4 insertions(+), 14 deletions(-)

diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
index 6a051f5909d0..434dc4ee5f15 100644
--- a/drivers/atm/idt77252.c
+++ b/drivers/atm/idt77252.c
@@ -1307,8 +1307,6 @@ idt77252_rx_raw(struct idt77252_dev *card)

sb = dev_alloc_skb(64);
if (!sb) {
-   printk("%s: Can't allocate buffers for AAL0.\n",
-  card->name);
atomic_inc(>stats->rx_err);
goto drop;
}
@@ -2007,7 +2005,6 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int 
flags)
 
skb = dev_alloc_skb(64);
if (!skb) {
-   printk("%s: Out of memory in send_oam().\n", card->name);
atomic_inc(>stats->tx_err);
return -ENOMEM;
}
@@ -2427,7 +2424,6 @@ idt77252_open(struct atm_vcc *vcc)
if (!card->vcs[index]) {
card->vcs[index] = kzalloc(sizeof(struct vc_map), GFP_KERNEL);
if (!card->vcs[index]) {
-   printk("%s: can't alloc vc in open()\n", card->name);
mutex_unlock(>mutex);
return -ENOMEM;
}
@@ -2857,10 +2853,9 @@ open_card_oam(struct idt77252_dev *card)
index = VPCI2VC(card, vpi, vci);
 
vc = kzalloc(sizeof(struct vc_map), GFP_KERNEL);
-   if (!vc) {
-   printk("%s: can't alloc vc\n", card->name);
+   if (!vc)
return -ENOMEM;
-   }
+
vc->index = index;
card->vcs[index] = vc;
 
@@ -2924,10 +2919,9 @@ open_card_ubr0(struct idt77252_dev *card)
struct vc_map *vc;
 
vc = kzalloc(sizeof(struct vc_map), GFP_KERNEL);
-   if (!vc) {
-   printk("%s: can't alloc vc\n", card->name);
+   if (!vc)
return -ENOMEM;
-   }
+
card->vcs[0] = vc;
vc->class = SCHED_UBR0;
 
@@ -3410,7 +3404,6 @@ static int init_card(struct atm_dev *dev)
IPRINTK("%s: allocate %d byte for VC map.\n", card->name, size);
card->vcs = vzalloc(size);
if (!card->vcs) {
-   printk("%s: memory allocation failure.\n", card->name);
deinit_card(card);
return -1;
}
@@ -3420,7 +3413,6 @@ static int init_card(struct atm_dev *dev)
card->name, size);
card->scd2vc = vzalloc(size);
if (!card->scd2vc) {
-   printk("%s: memory allocation failure.\n", card->name);
deinit_card(card);
return -1;
}
@@ -3430,7 +3422,6 @@ static int init_card(struct atm_dev *dev)
card->name, size);
card->soft_tst = vmalloc(size);
if (!card->soft_tst) {
-   printk("%s: memory allocation failure.\n", card->name);
deinit_card(card);
return -1;
}
@@ -3616,7 +3607,6 @@ static int idt77252_init_one(struct pci_dev *pcidev,
 
card = kzalloc(sizeof(struct idt77252_dev), GFP_KERNEL);
if (!card) {
-   printk("idt77252-%d: can't allocate private data\n", index);
err = -ENOMEM;
goto err_out_disable_pdev;
}
-- 
2.13.4



[PATCH 1/4] atm: idt77252: Adjust four function calls together with a variable assignment

2017-08-05 Thread SF Markus Elfring
From: Markus Elfring 
Date: Fri, 4 Aug 2017 22:20:08 +0200

The script "checkpatch.pl" pointed information out like the following.

ERROR: do not use assignment in if condition

Thus fix the affected source code places.

Signed-off-by: Markus Elfring 
---
 drivers/atm/idt77252.c | 13 -
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
index b7a168c46692..6a051f5909d0 100644
--- a/drivers/atm/idt77252.c
+++ b/drivers/atm/idt77252.c
@@ -1070,7 +1070,8 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry 
*rsqe)
 
cell = skb->data;
for (i = (stat & SAR_RSQE_CELLCNT); i; i--) {
-   if ((sb = dev_alloc_skb(64)) == NULL) {
+   sb = dev_alloc_skb(64);
+   if (!sb) {
printk("%s: Can't allocate buffers for aal0.\n",
   card->name);
atomic_add(i, >stats->rx_drop);
@@ -1304,7 +1305,8 @@ idt77252_rx_raw(struct idt77252_dev *card)
goto drop;
}

-   if ((sb = dev_alloc_skb(64)) == NULL) {
+   sb = dev_alloc_skb(64);
+   if (!sb) {
printk("%s: Can't allocate buffers for AAL0.\n",
   card->name);
atomic_inc(>stats->rx_err);
@@ -3600,13 +3602,14 @@ static int idt77252_init_one(struct pci_dev *pcidev,
struct atm_dev *dev;
int i, err;
 
-
-   if ((err = pci_enable_device(pcidev))) {
+   err = pci_enable_device(pcidev);
+   if (err) {
printk("idt77252: can't enable PCI device at %s\n", 
pci_name(pcidev));
return err;
}
 
-   if ((err = dma_set_mask_and_coherent(>dev, DMA_BIT_MASK(32 {
+   err = dma_set_mask_and_coherent(>dev, DMA_BIT_MASK(32));
+   if (err) {
printk("idt77252: can't enable DMA for PCI device at %s\n", 
pci_name(pcidev));
return err;
}
-- 
2.13.4



[PATCH 0/4] atm: idt77252: Adjustments for some function implementations

2017-08-05 Thread SF Markus Elfring
From: Markus Elfring 
Date: Sat, 5 Aug 2017 14:22:33 +0200

Some update suggestions were taken into account
from static source code analysis.

Markus Elfring (4):
  Adjust four function calls together with a variable assignment
  Delete an error message for a failed memory allocation in seven functions
  Improve seven size determinations
  Adjust ten checks for null pointers

 drivers/atm/idt77252.c | 68 ++
 1 file changed, 30 insertions(+), 38 deletions(-)

-- 
2.13.4



[PATCH net-next 14/14] sctp: remove the typedef sctp_subtype_t

2017-08-05 Thread Xin Long
This patch is to remove the typedef sctp_subtype_t, and
replace with union sctp_subtype in the places where it's
using this typedef.

Note that it doesn't fix many indents although it should,
as sctp_disposition_t's removal would mess them up again.
So better to fix them when removing sctp_disposition_t in
later patch.

Signed-off-by: Xin Long 
---
 include/net/sctp/constants.h |  18 ++--
 include/net/sctp/sm.h|  13 +--
 net/sctp/associola.c |   2 +-
 net/sctp/debug.c |   8 +-
 net/sctp/endpointola.c   |   2 +-
 net/sctp/primitive.c |   2 +-
 net/sctp/probe.c |   2 +-
 net/sctp/sm_sideeffect.c |  16 ++--
 net/sctp/sm_statefuns.c  | 191 ++-
 net/sctp/sm_statetable.c |   9 +-
 10 files changed, 134 insertions(+), 129 deletions(-)

diff --git a/include/net/sctp/constants.h b/include/net/sctp/constants.h
index 3181e0f..deaafa9 100644
--- a/include/net/sctp/constants.h
+++ b/include/net/sctp/constants.h
@@ -124,20 +124,20 @@ enum sctp_event_primitive {
 /* We define here a utility type for manipulating subtypes.
  * The subtype constructors all work like this:
  *
- * sctp_subtype_t foo = SCTP_ST_CHUNK(SCTP_CID_INIT);
+ *   union sctp_subtype foo = SCTP_ST_CHUNK(SCTP_CID_INIT);
  */
 
-typedef union {
+union sctp_subtype {
enum sctp_cid chunk;
enum sctp_event_timeout timeout;
enum sctp_event_other other;
enum sctp_event_primitive primitive;
-} sctp_subtype_t;
+};
 
 #define SCTP_SUBTYPE_CONSTRUCTOR(_name, _type, _elt) \
-static inline sctp_subtype_t   \
+static inline union sctp_subtype   \
 SCTP_ST_## _name (_type _arg)  \
-{ sctp_subtype_t _retval; _retval._elt = _arg; return _retval; }
+{ union sctp_subtype _retval; _retval._elt = _arg; return _retval; }
 
 SCTP_SUBTYPE_CONSTRUCTOR(CHUNK,enum sctp_cid,  chunk)
 SCTP_SUBTYPE_CONSTRUCTOR(TIMEOUT,  enum sctp_event_timeout, timeout)
@@ -220,10 +220,10 @@ enum sctp_sock_state {
 };
 
 /* These functions map various type to printable names.  */
-const char *sctp_cname(const sctp_subtype_t);  /* chunk types */
-const char *sctp_oname(const sctp_subtype_t);  /* other events */
-const char *sctp_tname(const sctp_subtype_t);  /* timeouts */
-const char *sctp_pname(const sctp_subtype_t);  /* primitives */
+const char *sctp_cname(const union sctp_subtype id);   /* chunk types */
+const char *sctp_oname(const union sctp_subtype id);   /* other events */
+const char *sctp_tname(const union sctp_subtype id);   /* timeouts */
+const char *sctp_pname(const union sctp_subtype id);   /* primitives */
 
 /* This is a table of printable names of sctp_state_t's.  */
 extern const char *const sctp_state_tbl[];
diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
index 96f54cf..1e7651c 100644
--- a/include/net/sctp/sm.h
+++ b/include/net/sctp/sm.h
@@ -73,7 +73,7 @@ typedef struct {
 typedef sctp_disposition_t (sctp_state_fn_t) (struct net *,
  const struct sctp_endpoint *,
  const struct sctp_association *,
- const sctp_subtype_t type,
+ const union sctp_subtype type,
  void *arg,
  sctp_cmd_seq_t *);
 typedef void (sctp_timer_event_t) (unsigned long);
@@ -175,10 +175,11 @@ sctp_state_fn_t sctp_sf_autoclose_timer_expire;
 
 /* Prototypes for utility support functions.  */
 __u8 sctp_get_chunk_type(struct sctp_chunk *chunk);
-const sctp_sm_table_entry_t *sctp_sm_lookup_event(struct net *net,
- enum sctp_event event_type,
- enum sctp_state state,
- sctp_subtype_t event_subtype);
+const sctp_sm_table_entry_t *sctp_sm_lookup_event(
+   struct net *net,
+   enum sctp_event event_type,
+   enum sctp_state state,
+   union sctp_subtype event_subtype);
 int sctp_chunk_iif(const struct sctp_chunk *);
 struct sctp_association *sctp_make_temp_asoc(const struct sctp_endpoint *,
 struct sctp_chunk *,
@@ -313,7 +314,7 @@ struct sctp_chunk *sctp_process_strreset_resp(
 /* Prototypes for statetable processing. */
 
 int sctp_do_sm(struct net *net, enum sctp_event event_type,
-  sctp_subtype_t subtype, enum sctp_state state,
+  union sctp_subtype subtype, enum sctp_state state,
   struct sctp_endpoint *ep, struct sctp_association *asoc,
   void *event_arg, gfp_t gfp);
 
diff --git a/net/sctp/associola.c b/net/sctp/associola.c
index b53efed..dfb9651 100644
--- 

[PATCH net-next 13/14] sctp: remove the typedef sctp_event_t

2017-08-05 Thread Xin Long
This patch is to remove the typedef sctp_event_t, and
replace with enum sctp_event in the places where it's
using this typedef.

Signed-off-by: Xin Long 
---
 include/net/sctp/constants.h |  6 ++
 include/net/sctp/sm.h| 12 +---
 net/sctp/primitive.c |  2 +-
 net/sctp/sm_sideeffect.c | 20 +---
 net/sctp/sm_statetable.c |  2 +-
 5 files changed, 18 insertions(+), 24 deletions(-)

diff --git a/include/net/sctp/constants.h b/include/net/sctp/constants.h
index fb931f0..3181e0f 100644
--- a/include/net/sctp/constants.h
+++ b/include/net/sctp/constants.h
@@ -71,14 +71,12 @@ enum { SCTP_DEFAULT_INSTREAMS = SCTP_MAX_STREAM };
 SCTP_NUM_AUTH_CHUNK_TYPES)
 
 /* These are the different flavours of event.  */
-typedef enum {
-
+enum sctp_event {
SCTP_EVENT_T_CHUNK = 1,
SCTP_EVENT_T_TIMEOUT,
SCTP_EVENT_T_OTHER,
SCTP_EVENT_T_PRIMITIVE
-
-} sctp_event_t;
+};
 
 /* As a convenience for the state machine, we append SCTP_EVENT_* and
  * SCTP_ULP_* to the list of possible chunks.
diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
index 281e8d1..96f54cf 100644
--- a/include/net/sctp/sm.h
+++ b/include/net/sctp/sm.h
@@ -176,7 +176,7 @@ sctp_state_fn_t sctp_sf_autoclose_timer_expire;
 /* Prototypes for utility support functions.  */
 __u8 sctp_get_chunk_type(struct sctp_chunk *chunk);
 const sctp_sm_table_entry_t *sctp_sm_lookup_event(struct net *net,
- sctp_event_t event_type,
+ enum sctp_event event_type,
  enum sctp_state state,
  sctp_subtype_t event_subtype);
 int sctp_chunk_iif(const struct sctp_chunk *);
@@ -312,12 +312,10 @@ struct sctp_chunk *sctp_process_strreset_resp(
 
 /* Prototypes for statetable processing. */
 
-int sctp_do_sm(struct net *net, sctp_event_t event_type, sctp_subtype_t 
subtype,
-  enum sctp_state state,
-   struct sctp_endpoint *,
-   struct sctp_association *asoc,
-   void *event_arg,
-  gfp_t gfp);
+int sctp_do_sm(struct net *net, enum sctp_event event_type,
+  sctp_subtype_t subtype, enum sctp_state state,
+  struct sctp_endpoint *ep, struct sctp_association *asoc,
+  void *event_arg, gfp_t gfp);
 
 /* 2nd level prototypes */
 void sctp_generate_t3_rtx_event(unsigned long peer);
diff --git a/net/sctp/primitive.c b/net/sctp/primitive.c
index 1fb5b9b..c914166 100644
--- a/net/sctp/primitive.c
+++ b/net/sctp/primitive.c
@@ -53,7 +53,7 @@
 int sctp_primitive_ ## name(struct net *net, struct sctp_association *asoc, \
void *arg) { \
int error = 0; \
-   sctp_event_t event_type; sctp_subtype_t subtype; \
+   enum sctp_event event_type; sctp_subtype_t subtype; \
enum sctp_state state; \
struct sctp_endpoint *ep; \
\
diff --git a/net/sctp/sm_sideeffect.c b/net/sctp/sm_sideeffect.c
index 11a3448..b545c76 100644
--- a/net/sctp/sm_sideeffect.c
+++ b/net/sctp/sm_sideeffect.c
@@ -51,7 +51,7 @@
 #include 
 #include 
 
-static int sctp_cmd_interpreter(sctp_event_t event_type,
+static int sctp_cmd_interpreter(enum sctp_event event_type,
sctp_subtype_t subtype,
enum sctp_state state,
struct sctp_endpoint *ep,
@@ -60,7 +60,7 @@ static int sctp_cmd_interpreter(sctp_event_t event_type,
sctp_disposition_t status,
sctp_cmd_seq_t *commands,
gfp_t gfp);
-static int sctp_side_effects(sctp_event_t event_type, sctp_subtype_t subtype,
+static int sctp_side_effects(enum sctp_event event_type, sctp_subtype_t 
subtype,
 enum sctp_state state,
 struct sctp_endpoint *ep,
 struct sctp_association **asoc,
@@ -602,7 +602,7 @@ static void sctp_cmd_init_failed(sctp_cmd_seq_t *commands,
 /* Worker routine to handle SCTP_CMD_ASSOC_FAILED.  */
 static void sctp_cmd_assoc_failed(sctp_cmd_seq_t *commands,
  struct sctp_association *asoc,
- sctp_event_t event_type,
+ enum sctp_event event_type,
  sctp_subtype_t subtype,
  struct sctp_chunk *chunk,
  unsigned int error)
@@ -1139,12 +1139,10 @@ static void sctp_cmd_send_asconf(struct 
sctp_association *asoc)
  * If you want to understand all of lksctp, this is a
  * good place to start.
  */
-int sctp_do_sm(struct net *net, sctp_event_t event_type, sctp_subtype_t 
subtype,
-  enum sctp_state state,
-  struct 

[PATCH net-next 12/14] sctp: remove the typedef sctp_event_timeout_t

2017-08-05 Thread Xin Long
This patch is to remove the typedef sctp_event_timeout_t, and
replace with enum sctp_event_timeout in the places where it's
using this typedef.

Signed-off-by: Xin Long 
---
 include/net/sctp/command.h   | 4 ++--
 include/net/sctp/constants.h | 8 
 net/sctp/sm_sideeffect.c | 6 +++---
 3 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/include/net/sctp/command.h b/include/net/sctp/command.h
index be12ec9..376cb78 100644
--- a/include/net/sctp/command.h
+++ b/include/net/sctp/command.h
@@ -127,7 +127,7 @@ typedef union {
int error;
__be16 err;
enum sctp_state state;
-   sctp_event_timeout_t to;
+   enum sctp_event_timeout to;
struct sctp_chunk *chunk;
struct sctp_association *asoc;
struct sctp_transport *transport;
@@ -168,7 +168,7 @@ SCTP_ARG_CONSTRUCTOR(U8,__u8, u8)
 SCTP_ARG_CONSTRUCTOR(ERROR, int, error)
 SCTP_ARG_CONSTRUCTOR(PERR,  __be16, err)   /* protocol error */
 SCTP_ARG_CONSTRUCTOR(STATE,enum sctp_state, state)
-SCTP_ARG_CONSTRUCTOR(TO,   sctp_event_timeout_t, to)
+SCTP_ARG_CONSTRUCTOR(TO,   enum sctp_event_timeout, to)
 SCTP_ARG_CONSTRUCTOR(CHUNK,struct sctp_chunk *, chunk)
 SCTP_ARG_CONSTRUCTOR(ASOC, struct sctp_association *, asoc)
 SCTP_ARG_CONSTRUCTOR(TRANSPORT,struct sctp_transport *, transport)
diff --git a/include/net/sctp/constants.h b/include/net/sctp/constants.h
index fd8a80e..fb931f0 100644
--- a/include/net/sctp/constants.h
+++ b/include/net/sctp/constants.h
@@ -84,7 +84,7 @@ typedef enum {
  * SCTP_ULP_* to the list of possible chunks.
  */
 
-typedef enum {
+enum sctp_event_timeout {
SCTP_EVENT_TIMEOUT_NONE = 0,
SCTP_EVENT_TIMEOUT_T1_COOKIE,
SCTP_EVENT_TIMEOUT_T1_INIT,
@@ -96,7 +96,7 @@ typedef enum {
SCTP_EVENT_TIMEOUT_RECONF,
SCTP_EVENT_TIMEOUT_SACK,
SCTP_EVENT_TIMEOUT_AUTOCLOSE,
-} sctp_event_timeout_t;
+};
 
 #define SCTP_EVENT_TIMEOUT_MAX SCTP_EVENT_TIMEOUT_AUTOCLOSE
 #define SCTP_NUM_TIMEOUT_TYPES (SCTP_EVENT_TIMEOUT_MAX + 1)
@@ -131,7 +131,7 @@ enum sctp_event_primitive {
 
 typedef union {
enum sctp_cid chunk;
-   sctp_event_timeout_t timeout;
+   enum sctp_event_timeout timeout;
enum sctp_event_other other;
enum sctp_event_primitive primitive;
 } sctp_subtype_t;
@@ -142,7 +142,7 @@ SCTP_ST_## _name (_type _arg)   \
 { sctp_subtype_t _retval; _retval._elt = _arg; return _retval; }
 
 SCTP_SUBTYPE_CONSTRUCTOR(CHUNK,enum sctp_cid,  chunk)
-SCTP_SUBTYPE_CONSTRUCTOR(TIMEOUT,  sctp_event_timeout_t,   timeout)
+SCTP_SUBTYPE_CONSTRUCTOR(TIMEOUT,  enum sctp_event_timeout, timeout)
 SCTP_SUBTYPE_CONSTRUCTOR(OTHER,enum sctp_event_other,  other)
 SCTP_SUBTYPE_CONSTRUCTOR(PRIMITIVE,enum sctp_event_primitive, primitive)
 
diff --git a/net/sctp/sm_sideeffect.c b/net/sctp/sm_sideeffect.c
index b77a81a..11a3448 100644
--- a/net/sctp/sm_sideeffect.c
+++ b/net/sctp/sm_sideeffect.c
@@ -280,7 +280,7 @@ void sctp_generate_t3_rtx_event(unsigned long peer)
  * for timeouts which use the association as their parameter.
  */
 static void sctp_generate_timeout_event(struct sctp_association *asoc,
-   sctp_event_timeout_t timeout_type)
+   enum sctp_event_timeout timeout_type)
 {
struct sock *sk = asoc->base.sk;
struct net *net = sock_net(sk);
@@ -1052,8 +1052,8 @@ static void sctp_cmd_adaptation_ind(sctp_cmd_seq_t 
*commands,
 
 
 static void sctp_cmd_t1_timer_update(struct sctp_association *asoc,
-   sctp_event_timeout_t timer,
-   char *name)
+enum sctp_event_timeout timer,
+char *name)
 {
struct sctp_transport *t;
 
-- 
2.1.0



[PATCH net-next 11/14] sctp: remove the typedef sctp_event_other_t

2017-08-05 Thread Xin Long
This patch is to remove the typedef sctp_event_other_t, and
replace with enum sctp_event_other in the places where it's
using this typedef.

Signed-off-by: Xin Long 
---
 include/net/sctp/constants.h | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/include/net/sctp/constants.h b/include/net/sctp/constants.h
index 162ee95..fd8a80e 100644
--- a/include/net/sctp/constants.h
+++ b/include/net/sctp/constants.h
@@ -101,10 +101,10 @@ typedef enum {
 #define SCTP_EVENT_TIMEOUT_MAX SCTP_EVENT_TIMEOUT_AUTOCLOSE
 #define SCTP_NUM_TIMEOUT_TYPES (SCTP_EVENT_TIMEOUT_MAX + 1)
 
-typedef enum {
+enum sctp_event_other {
SCTP_EVENT_NO_PENDING_TSN = 0,
SCTP_EVENT_ICMP_PROTO_UNREACH,
-} sctp_event_other_t;
+};
 
 #define SCTP_EVENT_OTHER_MAX   SCTP_EVENT_ICMP_PROTO_UNREACH
 #define SCTP_NUM_OTHER_TYPES   (SCTP_EVENT_OTHER_MAX + 1)
@@ -132,7 +132,7 @@ enum sctp_event_primitive {
 typedef union {
enum sctp_cid chunk;
sctp_event_timeout_t timeout;
-   sctp_event_other_t other;
+   enum sctp_event_other other;
enum sctp_event_primitive primitive;
 } sctp_subtype_t;
 
@@ -143,7 +143,7 @@ SCTP_ST_## _name (_type _arg)   \
 
 SCTP_SUBTYPE_CONSTRUCTOR(CHUNK,enum sctp_cid,  chunk)
 SCTP_SUBTYPE_CONSTRUCTOR(TIMEOUT,  sctp_event_timeout_t,   timeout)
-SCTP_SUBTYPE_CONSTRUCTOR(OTHER,sctp_event_other_t, other)
+SCTP_SUBTYPE_CONSTRUCTOR(OTHER,enum sctp_event_other,  other)
 SCTP_SUBTYPE_CONSTRUCTOR(PRIMITIVE,enum sctp_event_primitive, primitive)
 
 
-- 
2.1.0



[PATCH net-next 10/14] sctp: remove the typedef sctp_event_primitive_t

2017-08-05 Thread Xin Long
This patch is to remove the typedef sctp_event_primitive_t, and
replace with enum sctp_event_primitive in the places where it's
using this typedef.

Signed-off-by: Xin Long 
---
 include/net/sctp/constants.h | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/include/net/sctp/constants.h b/include/net/sctp/constants.h
index db9f40b..162ee95 100644
--- a/include/net/sctp/constants.h
+++ b/include/net/sctp/constants.h
@@ -110,7 +110,7 @@ typedef enum {
 #define SCTP_NUM_OTHER_TYPES   (SCTP_EVENT_OTHER_MAX + 1)
 
 /* These are primitive requests from the ULP.  */
-typedef enum {
+enum sctp_event_primitive {
SCTP_PRIMITIVE_ASSOCIATE = 0,
SCTP_PRIMITIVE_SHUTDOWN,
SCTP_PRIMITIVE_ABORT,
@@ -118,7 +118,7 @@ typedef enum {
SCTP_PRIMITIVE_REQUESTHEARTBEAT,
SCTP_PRIMITIVE_ASCONF,
SCTP_PRIMITIVE_RECONF,
-} sctp_event_primitive_t;
+};
 
 #define SCTP_EVENT_PRIMITIVE_MAX   SCTP_PRIMITIVE_RECONF
 #define SCTP_NUM_PRIMITIVE_TYPES   (SCTP_EVENT_PRIMITIVE_MAX + 1)
@@ -133,7 +133,7 @@ typedef union {
enum sctp_cid chunk;
sctp_event_timeout_t timeout;
sctp_event_other_t other;
-   sctp_event_primitive_t primitive;
+   enum sctp_event_primitive primitive;
 } sctp_subtype_t;
 
 #define SCTP_SUBTYPE_CONSTRUCTOR(_name, _type, _elt) \
@@ -144,7 +144,7 @@ SCTP_ST_## _name (_type _arg)   \
 SCTP_SUBTYPE_CONSTRUCTOR(CHUNK,enum sctp_cid,  chunk)
 SCTP_SUBTYPE_CONSTRUCTOR(TIMEOUT,  sctp_event_timeout_t,   timeout)
 SCTP_SUBTYPE_CONSTRUCTOR(OTHER,sctp_event_other_t, other)
-SCTP_SUBTYPE_CONSTRUCTOR(PRIMITIVE,sctp_event_primitive_t, primitive)
+SCTP_SUBTYPE_CONSTRUCTOR(PRIMITIVE,enum sctp_event_primitive, primitive)
 
 
 #define sctp_chunk_is_data(a) (a->chunk_hdr->type == SCTP_CID_DATA)
-- 
2.1.0



[PATCH net-next 09/14] sctp: remove the typedef sctp_state_t

2017-08-05 Thread Xin Long
This patch is to remove the typedef sctp_state_t, and
replace with enum sctp_state in the places where it's
using this typedef.

Signed-off-by: Xin Long 
---
 include/net/sctp/command.h   |  4 ++--
 include/net/sctp/constants.h |  4 ++--
 include/net/sctp/sctp.h  |  2 +-
 include/net/sctp/sm.h| 10 +-
 include/net/sctp/structs.h   |  2 +-
 net/sctp/endpointola.c   |  2 +-
 net/sctp/primitive.c |  2 +-
 net/sctp/sm_sideeffect.c | 12 ++--
 net/sctp/sm_statetable.c | 16 +---
 9 files changed, 28 insertions(+), 26 deletions(-)

diff --git a/include/net/sctp/command.h b/include/net/sctp/command.h
index 1d5f6ff..be12ec9 100644
--- a/include/net/sctp/command.h
+++ b/include/net/sctp/command.h
@@ -126,7 +126,7 @@ typedef union {
__u8 u8;
int error;
__be16 err;
-   sctp_state_t state;
+   enum sctp_state state;
sctp_event_timeout_t to;
struct sctp_chunk *chunk;
struct sctp_association *asoc;
@@ -167,7 +167,7 @@ SCTP_ARG_CONSTRUCTOR(U16,   __u16, u16)
 SCTP_ARG_CONSTRUCTOR(U8,   __u8, u8)
 SCTP_ARG_CONSTRUCTOR(ERROR, int, error)
 SCTP_ARG_CONSTRUCTOR(PERR,  __be16, err)   /* protocol error */
-SCTP_ARG_CONSTRUCTOR(STATE,sctp_state_t, state)
+SCTP_ARG_CONSTRUCTOR(STATE,enum sctp_state, state)
 SCTP_ARG_CONSTRUCTOR(TO,   sctp_event_timeout_t, to)
 SCTP_ARG_CONSTRUCTOR(CHUNK,struct sctp_chunk *, chunk)
 SCTP_ARG_CONSTRUCTOR(ASOC, struct sctp_association *, asoc)
diff --git a/include/net/sctp/constants.h b/include/net/sctp/constants.h
index 9a69465..db9f40b 100644
--- a/include/net/sctp/constants.h
+++ b/include/net/sctp/constants.h
@@ -181,7 +181,7 @@ enum sctp_ierror {
 
 
 /* SCTP state defines for internal state machine */
-typedef enum {
+enum sctp_state {
 
SCTP_STATE_CLOSED   = 0,
SCTP_STATE_COOKIE_WAIT  = 1,
@@ -192,7 +192,7 @@ typedef enum {
SCTP_STATE_SHUTDOWN_RECEIVED= 6,
SCTP_STATE_SHUTDOWN_ACK_SENT= 7,
 
-} sctp_state_t;
+};
 
 #define SCTP_STATE_MAX SCTP_STATE_SHUTDOWN_ACK_SENT
 #define SCTP_STATE_NUM_STATES  (SCTP_STATE_MAX + 1)
diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
index 0022bc7..24ff793 100644
--- a/include/net/sctp/sctp.h
+++ b/include/net/sctp/sctp.h
@@ -558,7 +558,7 @@ static inline int __sctp_style(const struct sock *sk, 
sctp_socket_type_t style)
 /* Is the association in this state? */
 #define sctp_state(asoc, state) __sctp_state((asoc), (SCTP_STATE_##state))
 static inline int __sctp_state(const struct sctp_association *asoc,
-  sctp_state_t state)
+  enum sctp_state state)
 {
return asoc->state == state;
 }
diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
index 860f378..281e8d1 100644
--- a/include/net/sctp/sm.h
+++ b/include/net/sctp/sm.h
@@ -175,10 +175,10 @@ sctp_state_fn_t sctp_sf_autoclose_timer_expire;
 
 /* Prototypes for utility support functions.  */
 __u8 sctp_get_chunk_type(struct sctp_chunk *chunk);
-const sctp_sm_table_entry_t *sctp_sm_lookup_event(struct net *,
-   sctp_event_t,
-   sctp_state_t,
-   sctp_subtype_t);
+const sctp_sm_table_entry_t *sctp_sm_lookup_event(struct net *net,
+ sctp_event_t event_type,
+ enum sctp_state state,
+ sctp_subtype_t event_subtype);
 int sctp_chunk_iif(const struct sctp_chunk *);
 struct sctp_association *sctp_make_temp_asoc(const struct sctp_endpoint *,
 struct sctp_chunk *,
@@ -313,7 +313,7 @@ struct sctp_chunk *sctp_process_strreset_resp(
 /* Prototypes for statetable processing. */
 
 int sctp_do_sm(struct net *net, sctp_event_t event_type, sctp_subtype_t 
subtype,
-  sctp_state_t state,
+  enum sctp_state state,
struct sctp_endpoint *,
struct sctp_association *asoc,
void *event_arg,
diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
index 6fab67e..fbe6e81 100644
--- a/include/net/sctp/structs.h
+++ b/include/net/sctp/structs.h
@@ -1577,7 +1577,7 @@ struct sctp_association {
 *
 *  State takes values from SCTP_STATE_*.
 */
-   sctp_state_t state;
+   enum sctp_state state;
 
/* Overall : The overall association error count.
 * Error Count : [Clear this any time I get something.]
diff --git a/net/sctp/endpointola.c b/net/sctp/endpointola.c
index 3d506b2..4111c00 100644
--- a/net/sctp/endpointola.c
+++ b/net/sctp/endpointola.c
@@ -383,7 +383,7 @@ static void sctp_endpoint_bh_rcv(struct work_struct *work)
struct sctp_chunk *chunk;

[PATCH net-next 05/14] sctp: remove the typedef sctp_transport_cmd_t

2017-08-05 Thread Xin Long
This patch is to remove the typedef sctp_transport_cmd_t, and
replace with enum sctp_transport_cmd in the places where it's
using this typedef.

Signed-off-by: Xin Long 
---
 include/net/sctp/constants.h | 4 ++--
 include/net/sctp/structs.h   | 7 ---
 net/sctp/associola.c | 2 +-
 3 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/include/net/sctp/constants.h b/include/net/sctp/constants.h
index 0503bb7..8ce6d32 100644
--- a/include/net/sctp/constants.h
+++ b/include/net/sctp/constants.h
@@ -320,11 +320,11 @@ typedef enum {
 } sctp_xmit_t;
 
 /* These are the commands for manipulating transports.  */
-typedef enum {
+enum sctp_transport_cmd {
SCTP_TRANSPORT_UP,
SCTP_TRANSPORT_DOWN,
SCTP_TRANSPORT_PF,
-} sctp_transport_cmd_t;
+};
 
 /* These are the address scopes defined mainly for IPv4 addresses
  * based on draft of SCTP IPv4 scoping .
diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
index d771d41..d098d1c 100644
--- a/include/net/sctp/structs.h
+++ b/include/net/sctp/structs.h
@@ -1947,9 +1947,10 @@ void sctp_assoc_del_peer(struct sctp_association *asoc,
 const union sctp_addr *addr);
 void sctp_assoc_rm_peer(struct sctp_association *asoc,
 struct sctp_transport *peer);
-void sctp_assoc_control_transport(struct sctp_association *,
- struct sctp_transport *,
- sctp_transport_cmd_t, sctp_sn_error_t);
+void sctp_assoc_control_transport(struct sctp_association *asoc,
+ struct sctp_transport *transport,
+ enum sctp_transport_cmd command,
+ sctp_sn_error_t error);
 struct sctp_transport *sctp_assoc_lookup_tsn(struct sctp_association *, __u32);
 struct sctp_transport *sctp_assoc_is_match(struct sctp_association *,
   struct net *,
diff --git a/net/sctp/associola.c b/net/sctp/associola.c
index 4c1f1bb..b53efed 100644
--- a/net/sctp/associola.c
+++ b/net/sctp/associola.c
@@ -796,7 +796,7 @@ void sctp_assoc_del_nonprimary_peers(struct 
sctp_association *asoc,
  */
 void sctp_assoc_control_transport(struct sctp_association *asoc,
  struct sctp_transport *transport,
- sctp_transport_cmd_t command,
+ enum sctp_transport_cmd command,
  sctp_sn_error_t error)
 {
struct sctp_ulpevent *event;
-- 
2.1.0



[PATCH net-next 08/14] sctp: remove the typedef sctp_ierror_t

2017-08-05 Thread Xin Long
This patch is to remove the typedef sctp_ierror_t, and
replace with enum sctp_ierror in the places where it's
using this typedef.

Signed-off-by: Xin Long 
---
 include/net/sctp/constants.h |  5 ++---
 net/sctp/sm_make_chunk.c | 23 ---
 net/sctp/sm_statefuns.c  | 28 +++-
 3 files changed, 29 insertions(+), 27 deletions(-)

diff --git a/include/net/sctp/constants.h b/include/net/sctp/constants.h
index 311b2e3..9a69465 100644
--- a/include/net/sctp/constants.h
+++ b/include/net/sctp/constants.h
@@ -155,8 +155,7 @@ SCTP_SUBTYPE_CONSTRUCTOR(PRIMITIVE, sctp_event_primitive_t, 
primitive)
- sizeof(struct sctp_data_chunk)))
 
 /* Internal error codes */
-typedef enum {
-
+enum sctp_ierror {
SCTP_IERROR_NO_ERROR= 0,
SCTP_IERROR_BASE= 1000,
SCTP_IERROR_NO_COOKIE,
@@ -177,7 +176,7 @@ typedef enum {
SCTP_IERROR_PROTO_VIOLATION,
SCTP_IERROR_ERROR,
SCTP_IERROR_ABORT,
-} sctp_ierror_t;
+};
 
 
 
diff --git a/net/sctp/sm_make_chunk.c b/net/sctp/sm_make_chunk.c
index a034d84..3a8fb1d 100644
--- a/net/sctp/sm_make_chunk.c
+++ b/net/sctp/sm_make_chunk.c
@@ -2065,10 +2065,11 @@ static void sctp_process_ext_param(struct 
sctp_association *asoc,
  * SCTP_IERROR_ERROR- stop and report an error.
  * SCTP_IERROR_NOMEME   - out of memory.
  */
-static sctp_ierror_t sctp_process_unk_param(const struct sctp_association 
*asoc,
-   union sctp_params param,
-   struct sctp_chunk *chunk,
-   struct sctp_chunk **errp)
+static enum sctp_ierror sctp_process_unk_param(
+   const struct sctp_association *asoc,
+   union sctp_params param,
+   struct sctp_chunk *chunk,
+   struct sctp_chunk **errp)
 {
int retval = SCTP_IERROR_NO_ERROR;
 
@@ -2117,13 +2118,13 @@ static sctp_ierror_t sctp_process_unk_param(const 
struct sctp_association *asoc,
  * SCTP_IERROR_ERROR - stop processing, trigger an ERROR
  * SCTP_IERROR_NO_ERROR - continue with the chunk
  */
-static sctp_ierror_t sctp_verify_param(struct net *net,
-   const struct sctp_endpoint *ep,
-   const struct sctp_association *asoc,
-   union sctp_params param,
-   enum sctp_cid cid,
-   struct sctp_chunk *chunk,
-   struct sctp_chunk **err_chunk)
+static enum sctp_ierror sctp_verify_param(struct net *net,
+ const struct sctp_endpoint *ep,
+ const struct sctp_association *asoc,
+ union sctp_params param,
+ enum sctp_cid cid,
+ struct sctp_chunk *chunk,
+ struct sctp_chunk **err_chunk)
 {
struct sctp_hmac_algo_param *hmacs;
int retval = SCTP_IERROR_NO_ERROR;
diff --git a/net/sctp/sm_statefuns.c b/net/sctp/sm_statefuns.c
index 8af90a5..5381697 100644
--- a/net/sctp/sm_statefuns.c
+++ b/net/sctp/sm_statefuns.c
@@ -144,11 +144,12 @@ static sctp_disposition_t sctp_sf_violation_chunk(
 void *arg,
 sctp_cmd_seq_t *commands);
 
-static sctp_ierror_t sctp_sf_authenticate(struct net *net,
-   const struct sctp_endpoint *ep,
-   const struct sctp_association *asoc,
-   const sctp_subtype_t type,
-   struct sctp_chunk *chunk);
+static enum sctp_ierror sctp_sf_authenticate(
+   struct net *net,
+   const struct sctp_endpoint *ep,
+   const struct sctp_association *asoc,
+   const sctp_subtype_t type,
+   struct sctp_chunk *chunk);
 
 static sctp_disposition_t __sctp_sf_do_9_1_abort(struct net *net,
const struct sctp_endpoint *ep,
@@ -756,7 +757,7 @@ sctp_disposition_t sctp_sf_do_5_1D_ce(struct net *net,
 */
if (chunk->auth_chunk) {
struct sctp_chunk auth;
-   sctp_ierror_t ret;
+   enum sctp_ierror ret;
 
/* Make sure that we and the peer are AUTH capable */
if (!net->sctp.auth_enable || !new_asoc->peer.auth_capable) {
@@ -4077,11 +4078,12 @@ sctp_disposition_t sctp_sf_eat_fwd_tsn_fast(
  *
  * The return value is 

[PATCH net-next 07/14] sctp: remove the typedef sctp_xmit_t

2017-08-05 Thread Xin Long
This patch is to remove the typedef sctp_xmit_t, and
replace with enum sctp_xmit in the places where it's
using this typedef.

Signed-off-by: Xin Long 
---
 include/net/sctp/constants.h |  4 +--
 include/net/sctp/structs.h   |  9 ---
 net/sctp/output.c| 60 ++--
 net/sctp/outqueue.c  |  8 +++---
 4 files changed, 41 insertions(+), 40 deletions(-)

diff --git a/include/net/sctp/constants.h b/include/net/sctp/constants.h
index 049868e..311b2e3 100644
--- a/include/net/sctp/constants.h
+++ b/include/net/sctp/constants.h
@@ -312,12 +312,12 @@ enum { SCTP_MAX_GABS = 16 };
 /* These return values describe the success or failure of a number of
  * routines which form the lower interface to SCTP_outqueue.
  */
-typedef enum {
+enum sctp_xmit {
SCTP_XMIT_OK,
SCTP_XMIT_PMTU_FULL,
SCTP_XMIT_RWND_FULL,
SCTP_XMIT_DELAY,
-} sctp_xmit_t;
+};
 
 /* These are the commands for manipulating transports.  */
 enum sctp_transport_cmd {
diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
index d098d1c..6fab67e 100644
--- a/include/net/sctp/structs.h
+++ b/include/net/sctp/structs.h
@@ -697,10 +697,11 @@ struct sctp_packet {
 void sctp_packet_init(struct sctp_packet *, struct sctp_transport *,
  __u16 sport, __u16 dport);
 void sctp_packet_config(struct sctp_packet *, __u32 vtag, int);
-sctp_xmit_t sctp_packet_transmit_chunk(struct sctp_packet *,
-  struct sctp_chunk *, int, gfp_t);
-sctp_xmit_t sctp_packet_append_chunk(struct sctp_packet *,
- struct sctp_chunk *);
+enum sctp_xmit sctp_packet_transmit_chunk(struct sctp_packet *packet,
+ struct sctp_chunk *chunk,
+ int one_packet, gfp_t gfp);
+enum sctp_xmit sctp_packet_append_chunk(struct sctp_packet *packet,
+   struct sctp_chunk *chunk);
 int sctp_packet_transmit(struct sctp_packet *, gfp_t);
 void sctp_packet_free(struct sctp_packet *);
 
diff --git a/net/sctp/output.c b/net/sctp/output.c
index 9d85049..4a865cd 100644
--- a/net/sctp/output.c
+++ b/net/sctp/output.c
@@ -57,15 +57,15 @@
 #include 
 
 /* Forward declarations for private helpers. */
-static sctp_xmit_t __sctp_packet_append_chunk(struct sctp_packet *packet,
- struct sctp_chunk *chunk);
-static sctp_xmit_t sctp_packet_can_append_data(struct sctp_packet *packet,
-  struct sctp_chunk *chunk);
+static enum sctp_xmit __sctp_packet_append_chunk(struct sctp_packet *packet,
+struct sctp_chunk *chunk);
+static enum sctp_xmit sctp_packet_can_append_data(struct sctp_packet *packet,
+ struct sctp_chunk *chunk);
 static void sctp_packet_append_data(struct sctp_packet *packet,
-  struct sctp_chunk *chunk);
-static sctp_xmit_t sctp_packet_will_fit(struct sctp_packet *packet,
-   struct sctp_chunk *chunk,
-   u16 chunk_len);
+   struct sctp_chunk *chunk);
+static enum sctp_xmit sctp_packet_will_fit(struct sctp_packet *packet,
+  struct sctp_chunk *chunk,
+  u16 chunk_len);
 
 static void sctp_packet_reset(struct sctp_packet *packet)
 {
@@ -181,11 +181,11 @@ void sctp_packet_free(struct sctp_packet *packet)
  * as it can fit in the packet, but any more data that does not fit in this
  * packet can be sent only after receiving the COOKIE_ACK.
  */
-sctp_xmit_t sctp_packet_transmit_chunk(struct sctp_packet *packet,
-  struct sctp_chunk *chunk,
-  int one_packet, gfp_t gfp)
+enum sctp_xmit sctp_packet_transmit_chunk(struct sctp_packet *packet,
+ struct sctp_chunk *chunk,
+ int one_packet, gfp_t gfp)
 {
-   sctp_xmit_t retval;
+   enum sctp_xmit retval;
 
pr_debug("%s: packet:%p size:%zu chunk:%p size:%d\n", __func__,
 packet, packet->size, chunk, chunk->skb ? chunk->skb->len : 
-1);
@@ -218,12 +218,12 @@ sctp_xmit_t sctp_packet_transmit_chunk(struct sctp_packet 
*packet,
 }
 
 /* Try to bundle an auth chunk into the packet. */
-static sctp_xmit_t sctp_packet_bundle_auth(struct sctp_packet *pkt,
-  struct sctp_chunk *chunk)
+static enum sctp_xmit sctp_packet_bundle_auth(struct sctp_packet *pkt,
+ struct sctp_chunk *chunk)
 {
struct sctp_association *asoc = pkt->transport->asoc;
+   enum sctp_xmit retval = SCTP_XMIT_OK;

[PATCH net-next 04/14] sctp: remove the typedef sctp_scope_t

2017-08-05 Thread Xin Long
This patch is to remove the typedef sctp_scope_t, and
replace with enum sctp_scope in the places where it's
using this typedef.

Signed-off-by: Xin Long 
---
 include/net/sctp/constants.h |  4 ++--
 include/net/sctp/sctp.h  |  4 ++--
 include/net/sctp/structs.h   | 17 +
 net/sctp/associola.c | 17 -
 net/sctp/bind_addr.c | 20 ++--
 net/sctp/ipv6.c  |  6 +++---
 net/sctp/protocol.c  |  6 +++---
 net/sctp/sm_make_chunk.c |  6 +++---
 net/sctp/socket.c|  4 ++--
 9 files changed, 42 insertions(+), 42 deletions(-)

diff --git a/include/net/sctp/constants.h b/include/net/sctp/constants.h
index acb03eb..0503bb7 100644
--- a/include/net/sctp/constants.h
+++ b/include/net/sctp/constants.h
@@ -333,13 +333,13 @@ typedef enum {
  * At this point, the IPv6 scopes will be mapped to these internal scopes
  * as much as possible.
  */
-typedef enum {
+enum sctp_scope {
SCTP_SCOPE_GLOBAL,  /* IPv4 global addresses */
SCTP_SCOPE_PRIVATE, /* IPv4 private addresses */
SCTP_SCOPE_LINK,/* IPv4 link local address */
SCTP_SCOPE_LOOPBACK,/* IPv4 loopback address */
SCTP_SCOPE_UNUSABLE,/* IPv4 unusable addresses */
-} sctp_scope_t;
+};
 
 enum {
SCTP_SCOPE_POLICY_DISABLE,  /* Disable IPv4 address scoping */
diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
index 84650fe..ca66b03 100644
--- a/include/net/sctp/sctp.h
+++ b/include/net/sctp/sctp.h
@@ -94,8 +94,8 @@
 /*
  * sctp/protocol.c
  */
-int sctp_copy_local_addr_list(struct net *, struct sctp_bind_addr *,
- sctp_scope_t, gfp_t gfp, int flags);
+int sctp_copy_local_addr_list(struct net *net, struct sctp_bind_addr *addr,
+ enum sctp_scope, gfp_t gfp, int flags);
 struct sctp_pf *sctp_get_pf_specific(sa_family_t family);
 int sctp_register_pf(struct sctp_pf *, sa_family_t);
 void sctp_addr_wq_mgmt(struct net *, struct sctp_sockaddr_entry *, int);
diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
index 5e872ac..d771d41 100644
--- a/include/net/sctp/structs.h
+++ b/include/net/sctp/structs.h
@@ -449,7 +449,7 @@ struct sctp_af {
int (*addr_valid)   (union sctp_addr *,
 struct sctp_sock *,
 const struct sk_buff *);
-   sctp_scope_t(*scope) (union sctp_addr *);
+   enum sctp_scope (*scope)(union sctp_addr *);
void(*inaddr_any)   (union sctp_addr *, __be16);
int (*is_any)   (const union sctp_addr *);
int (*available)(union sctp_addr *,
@@ -,7 +,7 @@ void sctp_bind_addr_init(struct sctp_bind_addr *, __u16 
port);
 void sctp_bind_addr_free(struct sctp_bind_addr *);
 int sctp_bind_addr_copy(struct net *net, struct sctp_bind_addr *dest,
const struct sctp_bind_addr *src,
-   sctp_scope_t scope, gfp_t gfp,
+   enum sctp_scope scope, gfp_t gfp,
int flags);
 int sctp_bind_addr_dup(struct sctp_bind_addr *dest,
const struct sctp_bind_addr *src,
@@ -1135,8 +1135,9 @@ union sctp_params sctp_bind_addrs_to_raw(const struct 
sctp_bind_addr *bp,
 int sctp_raw_to_bind_addrs(struct sctp_bind_addr *bp, __u8 *raw, int len,
   __u16 port, gfp_t gfp);
 
-sctp_scope_t sctp_scope(const union sctp_addr *);
-int sctp_in_scope(struct net *net, const union sctp_addr *addr, const 
sctp_scope_t scope);
+enum sctp_scope sctp_scope(const union sctp_addr *addr);
+int sctp_in_scope(struct net *net, const union sctp_addr *addr,
+ const enum sctp_scope scope);
 int sctp_is_any(struct sock *sk, const union sctp_addr *addr);
 int sctp_is_ep_boundall(struct sock *sk);
 
@@ -1925,8 +1926,8 @@ static inline struct sctp_association *sctp_assoc(struct 
sctp_ep_common *base)
 
 
 struct sctp_association *
-sctp_association_new(const struct sctp_endpoint *, const struct sock *,
-sctp_scope_t scope, gfp_t gfp);
+sctp_association_new(const struct sctp_endpoint *ep, const struct sock *sk,
+enum sctp_scope scope, gfp_t gfp);
 void sctp_association_free(struct sctp_association *);
 void sctp_association_put(struct sctp_association *);
 void sctp_association_hold(struct sctp_association *);
@@ -1967,8 +1968,8 @@ void sctp_assoc_set_primary(struct sctp_association *,
struct sctp_transport *);
 void sctp_assoc_del_nonprimary_peers(struct sctp_association *,
struct sctp_transport *);
-int sctp_assoc_set_bind_addr_from_ep(struct sctp_association *,
-sctp_scope_t, gfp_t);
+int sctp_assoc_set_bind_addr_from_ep(struct sctp_association *asoc,
+   

[PATCH net-next 00/14] sctp: remove typedefs from structures part 5

2017-08-05 Thread Xin Long
As we know, typedef is suggested not to use in kernel, even checkpatch.pl
also gives warnings about it. Now sctp is using it for many structures.

All this kind of typedef's using should be removed. This patchset is the
part 5 to remove all typedefs in include/net/sctp/constants.h.

Just as the part 1-4, No any code's logic would be changed in these patches,
only cleaning up.

Xin Long (14):
  sctp: remove the typedef sctp_lower_cwnd_t
  sctp: remove the typedef sctp_retransmit_reason_t
  sctp: remove the typedef sctp_scope_policy_t
  sctp: remove the typedef sctp_scope_t
  sctp: remove the typedef sctp_transport_cmd_t
  sctp: remove the typedef sctp_sock_state_t
  sctp: remove the typedef sctp_xmit_t
  sctp: remove the typedef sctp_ierror_t
  sctp: remove the typedef sctp_state_t
  sctp: remove the typedef sctp_event_primitive_t
  sctp: remove the typedef sctp_event_other_t
  sctp: remove the typedef sctp_event_timeout_t
  sctp: remove the typedef sctp_event_t
  sctp: remove the typedef sctp_subtype_t

 include/net/sctp/command.h   |   8 +-
 include/net/sctp/constants.h |  89 +-
 include/net/sctp/sctp.h  |   9 +-
 include/net/sctp/sm.h|  21 ++---
 include/net/sctp/structs.h   |  42 +
 net/sctp/associola.c |  21 ++---
 net/sctp/bind_addr.c |  20 ++--
 net/sctp/debug.c |   8 +-
 net/sctp/endpointola.c   |   4 +-
 net/sctp/ipv6.c  |   6 +-
 net/sctp/output.c|  60 ++--
 net/sctp/outqueue.c  |  10 +-
 net/sctp/primitive.c |   4 +-
 net/sctp/probe.c |   2 +-
 net/sctp/protocol.c  |   6 +-
 net/sctp/sm_make_chunk.c |  29 +++---
 net/sctp/sm_sideeffect.c |  46 -
 net/sctp/sm_statefuns.c  | 215 ++-
 net/sctp/sm_statetable.c |  23 +++--
 net/sctp/socket.c|   4 +-
 net/sctp/sysctl.c|   2 +-
 net/sctp/transport.c |   2 +-
 22 files changed, 320 insertions(+), 311 deletions(-)

-- 
2.1.0



[PATCH net-next 01/14] sctp: remove the typedef sctp_lower_cwnd_t

2017-08-05 Thread Xin Long
This patch is to remove the typedef sctp_lower_cwnd_t, and
replace with enum sctp_lower_cwnd in the places where it's
using this typedef.

Signed-off-by: Xin Long 
---
 include/net/sctp/constants.h | 4 ++--
 include/net/sctp/structs.h   | 3 ++-
 net/sctp/transport.c | 2 +-
 3 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/include/net/sctp/constants.h b/include/net/sctp/constants.h
index 9b18044..761064e 100644
--- a/include/net/sctp/constants.h
+++ b/include/net/sctp/constants.h
@@ -378,12 +378,12 @@ typedef enum {
 } sctp_retransmit_reason_t;
 
 /* Reasons to lower cwnd. */
-typedef enum {
+enum sctp_lower_cwnd {
SCTP_LOWER_CWND_T3_RTX,
SCTP_LOWER_CWND_FAST_RTX,
SCTP_LOWER_CWND_ECNE,
SCTP_LOWER_CWND_INACTIVE,
-} sctp_lower_cwnd_t;
+};
 
 
 /* SCTP-AUTH Necessary constants */
diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
index 66cd763..53802d8 100644
--- a/include/net/sctp/structs.h
+++ b/include/net/sctp/structs.h
@@ -950,7 +950,8 @@ int sctp_transport_hold(struct sctp_transport *);
 void sctp_transport_put(struct sctp_transport *);
 void sctp_transport_update_rto(struct sctp_transport *, __u32);
 void sctp_transport_raise_cwnd(struct sctp_transport *, __u32, __u32);
-void sctp_transport_lower_cwnd(struct sctp_transport *, sctp_lower_cwnd_t);
+void sctp_transport_lower_cwnd(struct sctp_transport *t,
+  enum sctp_lower_cwnd reason);
 void sctp_transport_burst_limited(struct sctp_transport *);
 void sctp_transport_burst_reset(struct sctp_transport *);
 unsigned long sctp_transport_timeout(struct sctp_transport *);
diff --git a/net/sctp/transport.c b/net/sctp/transport.c
index 80a97c8..2d9bd37 100644
--- a/net/sctp/transport.c
+++ b/net/sctp/transport.c
@@ -490,7 +490,7 @@ void sctp_transport_raise_cwnd(struct sctp_transport 
*transport,
  * detected.
  */
 void sctp_transport_lower_cwnd(struct sctp_transport *transport,
-  sctp_lower_cwnd_t reason)
+  enum sctp_lower_cwnd reason)
 {
struct sctp_association *asoc = transport->asoc;
 
-- 
2.1.0



[PATCH net-next 06/14] sctp: remove the typedef sctp_sock_state_t

2017-08-05 Thread Xin Long
This patch is to remove the typedef sctp_sock_state_t, and
replace with enum sctp_sock_state in the places where it's
using this typedef.

Signed-off-by: Xin Long 
---
 include/net/sctp/constants.h | 6 +++---
 include/net/sctp/sctp.h  | 3 ++-
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/include/net/sctp/constants.h b/include/net/sctp/constants.h
index 8ce6d32..049868e 100644
--- a/include/net/sctp/constants.h
+++ b/include/net/sctp/constants.h
@@ -42,7 +42,7 @@
 
 #include 
 #include  /* For ipv6hdr. */
-#include   /* For TCP states used in sctp_sock_state_t */
+#include   /* For TCP states used in enum sctp_sock_state */
 
 /* Value used for stream negotiation. */
 enum { SCTP_MAX_STREAM = 0x };
@@ -214,13 +214,13 @@ typedef enum {
  * - A socket in SCTP_SS_ESTABLISHED state indicates that it has a single 
  *   association.
  */
-typedef enum {
+enum sctp_sock_state {
SCTP_SS_CLOSED = TCP_CLOSE,
SCTP_SS_LISTENING  = TCP_LISTEN,
SCTP_SS_ESTABLISHING   = TCP_SYN_SENT,
SCTP_SS_ESTABLISHED= TCP_ESTABLISHED,
SCTP_SS_CLOSING= TCP_CLOSE_WAIT,
-} sctp_sock_state_t;
+};
 
 /* These functions map various type to printable names.  */
 const char *sctp_cname(const sctp_subtype_t);  /* chunk types */
diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
index ca66b03..0022bc7 100644
--- a/include/net/sctp/sctp.h
+++ b/include/net/sctp/sctp.h
@@ -565,7 +565,8 @@ static inline int __sctp_state(const struct 
sctp_association *asoc,
 
 /* Is the socket in this state? */
 #define sctp_sstate(sk, state) __sctp_sstate((sk), (SCTP_SS_##state))
-static inline int __sctp_sstate(const struct sock *sk, sctp_sock_state_t state)
+static inline int __sctp_sstate(const struct sock *sk,
+   enum sctp_sock_state state)
 {
return sk->sk_state == state;
 }
-- 
2.1.0



[PATCH net-next 03/14] sctp: remove the typedef sctp_scope_policy_t

2017-08-05 Thread Xin Long
This patch is to remove the typedef sctp_scope_policy_t and keep
it's members as an anonymous enum.

It is also to define SCTP_SCOPE_POLICY_MAX to replace the num 3
in sysctl.c to make codes clear.

Signed-off-by: Xin Long 
---
 include/net/sctp/constants.h | 6 --
 net/sctp/sysctl.c| 2 +-
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/include/net/sctp/constants.h b/include/net/sctp/constants.h
index 922fba5..acb03eb 100644
--- a/include/net/sctp/constants.h
+++ b/include/net/sctp/constants.h
@@ -341,12 +341,14 @@ typedef enum {
SCTP_SCOPE_UNUSABLE,/* IPv4 unusable addresses */
 } sctp_scope_t;
 
-typedef enum {
+enum {
SCTP_SCOPE_POLICY_DISABLE,  /* Disable IPv4 address scoping */
SCTP_SCOPE_POLICY_ENABLE,   /* Enable IPv4 address scoping */
SCTP_SCOPE_POLICY_PRIVATE,  /* Follow draft but allow IPv4 private 
addresses */
SCTP_SCOPE_POLICY_LINK, /* Follow draft but allow IPv4 link 
local addresses */
-} sctp_scope_policy_t;
+};
+
+#define SCTP_SCOPE_POLICY_MAX  SCTP_SCOPE_POLICY_LINK
 
 /* Based on IPv4 scoping ,
  * SCTP IPv4 unusable addresses: 0.0.0.0/8, 224.0.0.0/4, 198.18.0.0/24,
diff --git a/net/sctp/sysctl.c b/net/sctp/sysctl.c
index 0e732f6..ef7ca44 100644
--- a/net/sctp/sysctl.c
+++ b/net/sctp/sysctl.c
@@ -46,7 +46,7 @@ static int timer_max = 8640; /* ms in one day */
 static int int_max = INT_MAX;
 static int sack_timer_min = 1;
 static int sack_timer_max = 500;
-static int addr_scope_max = 3; /* check sctp_scope_policy_t in 
include/net/sctp/constants.h for max entries */
+static int addr_scope_max = SCTP_SCOPE_POLICY_MAX;
 static int rwnd_scale_max = 16;
 static int rto_alpha_min = 0;
 static int rto_beta_min = 0;
-- 
2.1.0



[PATCH net-next 02/14] sctp: remove the typedef sctp_retransmit_reason_t

2017-08-05 Thread Xin Long
This patch is to remove the typedef sctp_retransmit_reason_t, and
replace with enum sctp_retransmit_reason in the places where it's
using this typedef.

Signed-off-by: Xin Long 
---
 include/net/sctp/constants.h | 4 ++--
 include/net/sctp/structs.h   | 4 ++--
 net/sctp/outqueue.c  | 2 +-
 3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/include/net/sctp/constants.h b/include/net/sctp/constants.h
index 761064e..922fba5 100644
--- a/include/net/sctp/constants.h
+++ b/include/net/sctp/constants.h
@@ -370,12 +370,12 @@ typedef enum {
   peer */
 
 /* Reasons to retransmit. */
-typedef enum {
+enum sctp_retransmit_reason {
SCTP_RTXR_T3_RTX,
SCTP_RTXR_FAST_RTX,
SCTP_RTXR_PMTUD,
SCTP_RTXR_T1_RTX,
-} sctp_retransmit_reason_t;
+};
 
 /* Reasons to lower cwnd. */
 enum sctp_lower_cwnd {
diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
index 53802d8..5e872ac 100644
--- a/include/net/sctp/structs.h
+++ b/include/net/sctp/structs.h
@@ -1054,8 +1054,8 @@ int sctp_outq_sack(struct sctp_outq *, struct sctp_chunk 
*);
 int sctp_outq_is_empty(const struct sctp_outq *);
 void sctp_outq_restart(struct sctp_outq *);
 
-void sctp_retransmit(struct sctp_outq *, struct sctp_transport *,
-sctp_retransmit_reason_t);
+void sctp_retransmit(struct sctp_outq *q, struct sctp_transport *transport,
+enum sctp_retransmit_reason reason);
 void sctp_retransmit_mark(struct sctp_outq *, struct sctp_transport *, __u8);
 void sctp_outq_uncork(struct sctp_outq *, gfp_t gfp);
 void sctp_prsctp_prune(struct sctp_association *asoc,
diff --git a/net/sctp/outqueue.c b/net/sctp/outqueue.c
index d2a8adf..08ee0ed 100644
--- a/net/sctp/outqueue.c
+++ b/net/sctp/outqueue.c
@@ -534,7 +534,7 @@ void sctp_retransmit_mark(struct sctp_outq *q,
  * one packet out.
  */
 void sctp_retransmit(struct sctp_outq *q, struct sctp_transport *transport,
-sctp_retransmit_reason_t reason)
+enum sctp_retransmit_reason reason)
 {
struct net *net = sock_net(q->asoc->base.sk);
 
-- 
2.1.0



[PATCH net] net: sched: fix NULL pointer dereference when action calls some targets

2017-08-05 Thread Xin Long
As we know in some target's checkentry it may dereference par.entryinfo
to check entry stuff inside. But when sched action calls xt_check_target,
par.entryinfo is set with NULL. It would cause kernel panic when calling
some targets.

It can be reproduce with:
  # tc qd add dev eth1 ingress handle :
  # tc filter add dev eth1 parent : u32 match u32 0 0 action xt \
-j ECN --ecn-tcp-remove

It could also crash kernel when using target CLUSTERIP or TPROXY.

By now there's no proper value for par.entryinfo in ipt_init_target,
but it can not be set with NULL. This patch is to void all these
panics by setting it with an ipt_entry obj with all members 0.

Signed-off-by: Xin Long 
---
 net/sched/act_ipt.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/net/sched/act_ipt.c b/net/sched/act_ipt.c
index 7c4816b..0f09f70 100644
--- a/net/sched/act_ipt.c
+++ b/net/sched/act_ipt.c
@@ -41,6 +41,7 @@ static int ipt_init_target(struct net *net, struct 
xt_entry_target *t,
 {
struct xt_tgchk_param par;
struct xt_target *target;
+   struct ipt_entry e;
int ret = 0;
 
target = xt_request_find_target(AF_INET, t->u.user.name,
@@ -48,10 +49,11 @@ static int ipt_init_target(struct net *net, struct 
xt_entry_target *t,
if (IS_ERR(target))
return PTR_ERR(target);
 
+   memset(, 0, sizeof(e));
t->u.kernel.target = target;
par.net   = net;
par.table = table;
-   par.entryinfo = NULL;
+   par.entryinfo = 
par.target= target;
par.targinfo  = t->data;
par.hook_mask = hook;
-- 
2.1.0



[PATCH net] net: sched: set xt_tgchk_param par.nft_compat with false in ipt_init_target

2017-08-05 Thread Xin Long
Commit 55917a21d0cc ("netfilter: x_tables: add context to know if
extension runs from nft_compat") introduced a member nft_compat to
xt_tgchk_param structure.

But it didn't set it's value for ipt_init_target. With unexpected
value in par.nft_compat, it may return unexpected result in some
target's checkentry.

This patch is to set par.nft_compat with false in ipt_init_target.

Fixes: 55917a21d0cc ("netfilter: x_tables: add context to know if extension 
runs from nft_compat")
Signed-off-by: Xin Long 
---
 net/sched/act_ipt.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/net/sched/act_ipt.c b/net/sched/act_ipt.c
index bb06d2ed..7c4816b 100644
--- a/net/sched/act_ipt.c
+++ b/net/sched/act_ipt.c
@@ -56,6 +56,7 @@ static int ipt_init_target(struct net *net, struct 
xt_entry_target *t,
par.targinfo  = t->data;
par.hook_mask = hook;
par.family= NFPROTO_IPV4;
+   par.nft_compat = false;
 
ret = xt_check_target(, t->u.target_size - sizeof(*t), 0, false);
if (ret < 0) {
-- 
2.1.0



[PATCH v4 net-next 2/5] net: dsa: lan9303: define LAN9303_NUM_PORTS 3

2017-08-05 Thread Egil Hjelmeland
Will be used instead of '3' in upcomming patches.

Signed-off-by: Egil Hjelmeland 
Signed-off-by: Andrew Lunn 
Reviewed-by: Florian Fainelli 
---
 drivers/net/dsa/lan9303-core.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/net/dsa/lan9303-core.c b/drivers/net/dsa/lan9303-core.c
index 77f3cee3af0d..49e3a0cb1b5b 100644
--- a/drivers/net/dsa/lan9303-core.c
+++ b/drivers/net/dsa/lan9303-core.c
@@ -20,6 +20,8 @@
 
 #include "lan9303.h"
 
+#define LAN9303_NUM_PORTS 3
+
 /* 13.2 System Control and Status Registers
  * Multiply register number by 4 to get address offset.
  */
-- 
2.11.0



[PATCH v4 net-next 1/5] net: dsa: lan9303: Change lan9303_xxx_packet_processing() port param.

2017-08-05 Thread Egil Hjelmeland
lan9303_enable_packet_processing, lan9303_disable_packet_processing()
Pass port number (0,1,2) as parameter instead of port offset.
Because other functions in the module pass port numbers.
And to enable simplifications in following patch.

Introduce lan9303_write_switch_port().

Signed-off-by: Egil Hjelmeland 
Reviewed-by: Andrew Lunn 
Reviewed-by: Florian Fainelli 
---
 drivers/net/dsa/lan9303-core.c | 46 +-
 1 file changed, 23 insertions(+), 23 deletions(-)

diff --git a/drivers/net/dsa/lan9303-core.c b/drivers/net/dsa/lan9303-core.c
index 8e430d1ee297..77f3cee3af0d 100644
--- a/drivers/net/dsa/lan9303-core.c
+++ b/drivers/net/dsa/lan9303-core.c
@@ -159,9 +159,7 @@
 # define LAN9303_BM_EGRSS_PORT_TYPE_SPECIAL_TAG_PORT1 (BIT(9) | BIT(8))
 # define LAN9303_BM_EGRSS_PORT_TYPE_SPECIAL_TAG_PORT0 (BIT(1) | BIT(0))
 
-#define LAN9303_PORT_0_OFFSET 0x400
-#define LAN9303_PORT_1_OFFSET 0x800
-#define LAN9303_PORT_2_OFFSET 0xc00
+#define LAN9303_SWITCH_PORT_REG(port, reg0) (0x400 * (port) + (reg0))
 
 /* the built-in PHYs are of type LAN911X */
 #define MII_LAN911X_SPECIAL_MODES 0x12
@@ -428,6 +426,13 @@ static int lan9303_read_switch_reg(struct lan9303 *chip, 
u16 regnum, u32 *val)
return ret;
 }
 
+static int lan9303_write_switch_port(struct lan9303 *chip, int port,
+u16 regnum, u32 val)
+{
+   return lan9303_write_switch_reg(
+   chip, LAN9303_SWITCH_PORT_REG(port, regnum), val);
+}
+
 static int lan9303_detect_phy_setup(struct lan9303 *chip)
 {
int reg;
@@ -458,22 +463,19 @@ static int lan9303_detect_phy_setup(struct lan9303 *chip)
return 0;
 }
 
-#define LAN9303_MAC_RX_CFG_OFFS (LAN9303_MAC_RX_CFG_0 - LAN9303_PORT_0_OFFSET)
-#define LAN9303_MAC_TX_CFG_OFFS (LAN9303_MAC_TX_CFG_0 - LAN9303_PORT_0_OFFSET)
-
 static int lan9303_disable_packet_processing(struct lan9303 *chip,
 unsigned int port)
 {
int ret;
 
/* disable RX, but keep register reset default values else */
-   ret = lan9303_write_switch_reg(chip, LAN9303_MAC_RX_CFG_OFFS + port,
-  LAN9303_MAC_RX_CFG_X_REJECT_MAC_TYPES);
+   ret = lan9303_write_switch_port(chip, port, LAN9303_MAC_RX_CFG_0,
+   LAN9303_MAC_RX_CFG_X_REJECT_MAC_TYPES);
if (ret)
return ret;
 
/* disable TX, but keep register reset default values else */
-   return lan9303_write_switch_reg(chip, LAN9303_MAC_TX_CFG_OFFS + port,
+   return lan9303_write_switch_port(chip, port, LAN9303_MAC_TX_CFG_0,
LAN9303_MAC_TX_CFG_X_TX_IFG_CONFIG_DEFAULT |
LAN9303_MAC_TX_CFG_X_TX_PAD_ENABLE);
 }
@@ -484,14 +486,14 @@ static int lan9303_enable_packet_processing(struct 
lan9303 *chip,
int ret;
 
/* enable RX and keep register reset default values else */
-   ret = lan9303_write_switch_reg(chip, LAN9303_MAC_RX_CFG_OFFS + port,
-  LAN9303_MAC_RX_CFG_X_REJECT_MAC_TYPES |
-  LAN9303_MAC_RX_CFG_X_RX_ENABLE);
+   ret = lan9303_write_switch_port(chip, port, LAN9303_MAC_RX_CFG_0,
+   LAN9303_MAC_RX_CFG_X_REJECT_MAC_TYPES |
+   LAN9303_MAC_RX_CFG_X_RX_ENABLE);
if (ret)
return ret;
 
/* enable TX and keep register reset default values else */
-   return lan9303_write_switch_reg(chip, LAN9303_MAC_TX_CFG_OFFS + port,
+   return lan9303_write_switch_port(chip, port, LAN9303_MAC_TX_CFG_0,
LAN9303_MAC_TX_CFG_X_TX_IFG_CONFIG_DEFAULT |
LAN9303_MAC_TX_CFG_X_TX_PAD_ENABLE |
LAN9303_MAC_TX_CFG_X_TX_ENABLE);
@@ -558,13 +560,13 @@ static int lan9303_disable_processing(struct lan9303 
*chip)
 {
int ret;
 
-   ret = lan9303_disable_packet_processing(chip, LAN9303_PORT_0_OFFSET);
+   ret = lan9303_disable_packet_processing(chip, 0);
if (ret)
return ret;
-   ret = lan9303_disable_packet_processing(chip, LAN9303_PORT_1_OFFSET);
+   ret = lan9303_disable_packet_processing(chip, 1);
if (ret)
return ret;
-   return lan9303_disable_packet_processing(chip, LAN9303_PORT_2_OFFSET);
+   return lan9303_disable_packet_processing(chip, 2);
 }
 
 static int lan9303_check_device(struct lan9303 *chip)
@@ -634,7 +636,7 @@ static int lan9303_setup(struct dsa_switch *ds)
if (ret)
dev_err(chip->dev, "failed to separate ports %d\n", ret);
 
-   ret = lan9303_enable_packet_processing(chip, LAN9303_PORT_0_OFFSET);
+   ret = lan9303_enable_packet_processing(chip, 0);
if (ret)
dev_err(chip->dev, "failed to 

[PATCH v4 net-next 0/5] Refactor lan9303_xxx_packet_processing

2017-08-05 Thread Egil Hjelmeland
This series is purely non functional. 

It changes the lan9303_enable_packet_processing,
lan9303_disable_packet_processing() to pass port number (0,1,2) as
parameter instead of port offset. This aligns them with
other functions in the module, and makes it possible to simplify the code.

The lan9303_enable_packet_processing, lan9303_disable_packet_processing
functions operate on port. Therefore rename the functions to reflect that
as well.

Reviewer pointed out lan9303_get_ethtool_stats would be better off with
the use of a lan9303_read_switch_port(). So that was added to the series.


Changes v3 -> v4:
 - Whitespace adjustments. 

Changes v2 -> v3:
 - Patch 1: Removed the change in lan9303_get_ethtool_stats
 - Added patch 4: rename lan9303_xxx_packet_processing 
 - Added patch 5: refactor lan9303_get_ethtool_stats
 
Changes v1 -> v2:
 - introduced lan9303_write_switch_port() in first patch
 - inserted LAN9303_NUM_PORTS patch
 - Use LAN9303_NUM_PORTS in last patch. Plus whitespace change.  

Egil Hjelmeland (5):
  net: dsa: lan9303: Change lan9303_xxx_packet_processing() port param.
  net: dsa: lan9303: define LAN9303_NUM_PORTS 3
  net: dsa: lan9303: Simplify lan9303_xxx_packet_processing() usage
  net: dsa: lan9303: Rename lan9303_xxx_packet_processing()
  net: dsa: lan9303: refactor lan9303_get_ethtool_stats

 drivers/net/dsa/lan9303-core.c | 96 ++
 1 file changed, 50 insertions(+), 46 deletions(-)

-- 
2.11.0



[PATCH v4 net-next 3/5] net: dsa: lan9303: Simplify lan9303_xxx_packet_processing() usage

2017-08-05 Thread Egil Hjelmeland
Simplify usage of lan9303_enable_packet_processing,
lan9303_disable_packet_processing()

Signed-off-by: Egil Hjelmeland 
Reviewed-by: Andrew Lunn 
Reviewed-by: Florian Fainelli 
---
 drivers/net/dsa/lan9303-core.c | 24 ++--
 1 file changed, 10 insertions(+), 14 deletions(-)

diff --git a/drivers/net/dsa/lan9303-core.c b/drivers/net/dsa/lan9303-core.c
index 49e3a0cb1b5b..daae267f6b05 100644
--- a/drivers/net/dsa/lan9303-core.c
+++ b/drivers/net/dsa/lan9303-core.c
@@ -560,15 +560,16 @@ static int lan9303_handle_reset(struct lan9303 *chip)
 /* stop processing packets for all ports */
 static int lan9303_disable_processing(struct lan9303 *chip)
 {
-   int ret;
+   int p;
 
-   ret = lan9303_disable_packet_processing(chip, 0);
-   if (ret)
-   return ret;
-   ret = lan9303_disable_packet_processing(chip, 1);
-   if (ret)
-   return ret;
-   return lan9303_disable_packet_processing(chip, 2);
+   for (p = 0; p < LAN9303_NUM_PORTS; p++) {
+   int ret = lan9303_disable_packet_processing(chip, p);
+
+   if (ret)
+   return ret;
+   }
+
+   return 0;
 }
 
 static int lan9303_check_device(struct lan9303 *chip)
@@ -761,7 +762,6 @@ static int lan9303_port_enable(struct dsa_switch *ds, int 
port,
/* enable internal packet processing */
switch (port) {
case 1:
-   return lan9303_enable_packet_processing(chip, port);
case 2:
return lan9303_enable_packet_processing(chip, port);
default:
@@ -780,13 +780,9 @@ static void lan9303_port_disable(struct dsa_switch *ds, 
int port,
/* disable internal packet processing */
switch (port) {
case 1:
-   lan9303_disable_packet_processing(chip, port);
-   lan9303_phy_write(ds, chip->phy_addr_sel_strap + 1,
- MII_BMCR, BMCR_PDOWN);
-   break;
case 2:
lan9303_disable_packet_processing(chip, port);
-   lan9303_phy_write(ds, chip->phy_addr_sel_strap + 2,
+   lan9303_phy_write(ds, chip->phy_addr_sel_strap + port,
  MII_BMCR, BMCR_PDOWN);
break;
default:
-- 
2.11.0



[PATCH v4 net-next 4/5] net: dsa: lan9303: Rename lan9303_xxx_packet_processing()

2017-08-05 Thread Egil Hjelmeland
The lan9303_enable_packet_processing, lan9303_disable_packet_processing
functions operate on port, so the names should reflect that.
And to align with lan9303_disable_processing(), rename:

lan9303_enable_packet_processing -> lan9303_enable_processing_port
lan9303_disable_packet_processing -> lan9303_disable_processing_port

Signed-off-by: Egil Hjelmeland 
Reviewed-by: Andrew Lunn 
Reviewed-by: Florian Fainelli 
---
 drivers/net/dsa/lan9303-core.c | 16 
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/drivers/net/dsa/lan9303-core.c b/drivers/net/dsa/lan9303-core.c
index daae267f6b05..444958bb19f6 100644
--- a/drivers/net/dsa/lan9303-core.c
+++ b/drivers/net/dsa/lan9303-core.c
@@ -465,8 +465,8 @@ static int lan9303_detect_phy_setup(struct lan9303 *chip)
return 0;
 }
 
-static int lan9303_disable_packet_processing(struct lan9303 *chip,
-unsigned int port)
+static int lan9303_disable_processing_port(struct lan9303 *chip,
+  unsigned int port)
 {
int ret;
 
@@ -482,8 +482,8 @@ static int lan9303_disable_packet_processing(struct lan9303 
*chip,
LAN9303_MAC_TX_CFG_X_TX_PAD_ENABLE);
 }
 
-static int lan9303_enable_packet_processing(struct lan9303 *chip,
-   unsigned int port)
+static int lan9303_enable_processing_port(struct lan9303 *chip,
+ unsigned int port)
 {
int ret;
 
@@ -563,7 +563,7 @@ static int lan9303_disable_processing(struct lan9303 *chip)
int p;
 
for (p = 0; p < LAN9303_NUM_PORTS; p++) {
-   int ret = lan9303_disable_packet_processing(chip, p);
+   int ret = lan9303_disable_processing_port(chip, p);
 
if (ret)
return ret;
@@ -639,7 +639,7 @@ static int lan9303_setup(struct dsa_switch *ds)
if (ret)
dev_err(chip->dev, "failed to separate ports %d\n", ret);
 
-   ret = lan9303_enable_packet_processing(chip, 0);
+   ret = lan9303_enable_processing_port(chip, 0);
if (ret)
dev_err(chip->dev, "failed to re-enable switching %d\n", ret);
 
@@ -763,7 +763,7 @@ static int lan9303_port_enable(struct dsa_switch *ds, int 
port,
switch (port) {
case 1:
case 2:
-   return lan9303_enable_packet_processing(chip, port);
+   return lan9303_enable_processing_port(chip, port);
default:
dev_dbg(chip->dev,
"Error: request to power up invalid port %d\n", port);
@@ -781,7 +781,7 @@ static void lan9303_port_disable(struct dsa_switch *ds, int 
port,
switch (port) {
case 1:
case 2:
-   lan9303_disable_packet_processing(chip, port);
+   lan9303_disable_processing_port(chip, port);
lan9303_phy_write(ds, chip->phy_addr_sel_strap + port,
  MII_BMCR, BMCR_PDOWN);
break;
-- 
2.11.0



[PATCH v4 net-next 5/5] net: dsa: lan9303: refactor lan9303_get_ethtool_stats

2017-08-05 Thread Egil Hjelmeland
In lan9303_get_ethtool_stats: Get rid of 0x400 constant magic
by using new lan9303_read_switch_reg() inside loop.
Reduced scope of two variables.

Signed-off-by: Egil Hjelmeland 
Reviewed-by: Andrew Lunn 
Reviewed-by: Florian Fainelli 
---
 drivers/net/dsa/lan9303-core.c | 26 --
 1 file changed, 16 insertions(+), 10 deletions(-)

diff --git a/drivers/net/dsa/lan9303-core.c b/drivers/net/dsa/lan9303-core.c
index 444958bb19f6..15befd155251 100644
--- a/drivers/net/dsa/lan9303-core.c
+++ b/drivers/net/dsa/lan9303-core.c
@@ -435,6 +435,13 @@ static int lan9303_write_switch_port(struct lan9303 *chip, 
int port,
chip, LAN9303_SWITCH_PORT_REG(port, regnum), val);
 }
 
+static int lan9303_read_switch_port(struct lan9303 *chip, int port,
+   u16 regnum, u32 *val)
+{
+   return lan9303_read_switch_reg(
+   chip, LAN9303_SWITCH_PORT_REG(port, regnum), val);
+}
+
 static int lan9303_detect_phy_setup(struct lan9303 *chip)
 {
int reg;
@@ -705,19 +712,18 @@ static void lan9303_get_ethtool_stats(struct dsa_switch 
*ds, int port,
  uint64_t *data)
 {
struct lan9303 *chip = ds->priv;
-   u32 reg;
-   unsigned int u, poff;
-   int ret;
-
-   poff = port * 0x400;
+   unsigned int u;
 
for (u = 0; u < ARRAY_SIZE(lan9303_mib); u++) {
-   ret = lan9303_read_switch_reg(chip,
- lan9303_mib[u].offset + poff,
- );
+   u32 reg;
+   int ret;
+
+   ret = lan9303_read_switch_port(
+   chip, port, lan9303_mib[u].offset, );
+
if (ret)
-   dev_warn(chip->dev, "Reading status reg %u failed\n",
-lan9303_mib[u].offset + poff);
+   dev_warn(chip->dev, "Reading status port %d reg %u 
failed\n",
+port, lan9303_mib[u].offset);
data[u] = reg;
}
 }
-- 
2.11.0



[PATCH net-next v2 5/5] ipv6: sr: implement several seg6local actions

2017-08-05 Thread David Lebrun
This patch implements the following seg6local actions.

- SEG6_LOCAL_ACTION_END: regular SRH processing. The DA of the packet
  is updated to the next segment and forwarded accordingly.

- SEG6_LOCAL_ACTION_END_X: same as above, except that the packet is
  forwarded to the specified IPv6 next-hop.

- SEG6_LOCAL_ACTION_END_DX6: decapsulate the packet and forward to
  inner IPv6 packet to the specified IPv6 next-hop.

- SEG6_LOCAL_ACTION_END_B6: insert the specified SRH directly after
  the IPv6 header of the packet.

- SEG6_LOCAL_ACTION_END_B6_ENCAP: encapsulate the packet within
  an outer IPv6 header, containing the specified SRH.

Signed-off-by: David Lebrun 
---
 net/ipv6/seg6_local.c | 271 ++
 1 file changed, 271 insertions(+)

diff --git a/net/ipv6/seg6_local.c b/net/ipv6/seg6_local.c
index ab1fc1b..147680e 100644
--- a/net/ipv6/seg6_local.c
+++ b/net/ipv6/seg6_local.c
@@ -58,11 +58,282 @@ static struct seg6_local_lwt *seg6_local_lwtunnel(struct 
lwtunnel_state *lwt)
return (struct seg6_local_lwt *)lwt->data;
 }
 
+static struct ipv6_sr_hdr *get_srh(struct sk_buff *skb)
+{
+   struct ipv6_sr_hdr *srh;
+   struct ipv6hdr *hdr;
+   int len;
+
+   hdr = ipv6_hdr(skb);
+   if (hdr->nexthdr != IPPROTO_ROUTING)
+   return NULL;
+
+   srh = (struct ipv6_sr_hdr *)(hdr + 1);
+   len = (srh->hdrlen + 1) << 3;
+
+   if (!pskb_may_pull(skb, sizeof(*hdr) + len))
+   return NULL;
+
+   if (!seg6_validate_srh(srh, len))
+   return NULL;
+
+   return srh;
+}
+
+static struct ipv6_sr_hdr *get_and_validate_srh(struct sk_buff *skb)
+{
+   struct ipv6_sr_hdr *srh;
+
+   srh = get_srh(skb);
+   if (!srh)
+   return NULL;
+
+   if (srh->segments_left == 0)
+   return NULL;
+
+#ifdef CONFIG_IPV6_SEG6_HMAC
+   if (!seg6_hmac_validate_skb(skb))
+   return NULL;
+#endif
+
+   return srh;
+}
+
+/* regular endpoint function */
+static int input_action_end(struct sk_buff *skb, struct seg6_local_lwt *slwt)
+{
+   struct ipv6_sr_hdr *srh;
+   struct in6_addr *addr;
+
+   srh = get_and_validate_srh(skb);
+   if (!srh)
+   goto drop;
+
+   srh->segments_left--;
+   addr = srh->segments + srh->segments_left;
+
+   ipv6_hdr(skb)->daddr = *addr;
+
+   skb_dst_drop(skb);
+   ip6_route_input(skb);
+
+   return dst_input(skb);
+
+drop:
+   kfree_skb(skb);
+   return -EINVAL;
+}
+
+/* regular endpoint, and forward to specified nexthop */
+static int input_action_end_x(struct sk_buff *skb, struct seg6_local_lwt *slwt)
+{
+   struct net *net = dev_net(skb->dev);
+   struct ipv6_sr_hdr *srh;
+   struct dst_entry *dst;
+   struct in6_addr *addr;
+   struct ipv6hdr *hdr;
+   struct flowi6 fl6;
+   int flags;
+
+   srh = get_and_validate_srh(skb);
+   if (!srh)
+   goto drop;
+
+   srh->segments_left--;
+   addr = srh->segments + srh->segments_left;
+
+   hdr = ipv6_hdr(skb);
+   hdr->daddr = *addr;
+
+   skb_dst_drop(skb);
+
+   fl6.flowi6_iif = skb->dev->ifindex;
+   fl6.daddr = slwt->nh6;
+   fl6.saddr = hdr->saddr;
+   fl6.flowlabel = ip6_flowinfo(hdr);
+   fl6.flowi6_mark = skb->mark;
+   fl6.flowi6_proto = hdr->nexthdr;
+
+   flags = RT6_LOOKUP_F_HAS_SADDR | RT6_LOOKUP_F_IFACE |
+   RT6_LOOKUP_F_REACHABLE;
+
+   dst = ip6_route_input_lookup(net, skb->dev, , flags);
+   if (dst->dev->flags & IFF_LOOPBACK)
+   goto drop;
+
+   skb_dst_set(skb, dst);
+
+   return dst_input(skb);
+
+drop:
+   kfree_skb(skb);
+   return -EINVAL;
+}
+
+/* decapsulate and forward to specified nexthop */
+static int input_action_end_dx6(struct sk_buff *skb,
+   struct seg6_local_lwt *slwt)
+{
+   struct net *net = dev_net(skb->dev);
+   struct ipv6hdr *inner_hdr;
+   struct ipv6_sr_hdr *srh;
+   struct dst_entry *dst;
+   unsigned int off = 0;
+   struct flowi6 fl6;
+   bool use_nh;
+   int flags;
+
+   /* this function accepts IPv6 encapsulated packets, with either
+* an SRH with SL=0, or no SRH.
+*/
+
+   srh = get_srh(skb);
+   if (srh && srh->segments_left > 0)
+   goto drop;
+
+#ifdef CONFIG_IPV6_SEG6_HMAC
+   if (srh && !seg6_hmac_validate_skb(skb))
+   goto drop;
+#endif
+
+   if (ipv6_find_hdr(skb, , IPPROTO_IPV6, NULL, NULL) < 0)
+   goto drop;
+
+   if (!pskb_pull(skb, off))
+   goto drop;
+
+   skb_postpull_rcsum(skb, skb_network_header(skb), off);
+
+   skb_reset_network_header(skb);
+   skb_reset_transport_header(skb);
+   skb->encapsulation = 0;
+
+   inner_hdr = ipv6_hdr(skb);
+
+   /* The inner packet is not associated to any local interface,
+* so we do 

[PATCH net-next v2 3/5] ipv6: sr: define core operations for seg6local lightweight tunnel

2017-08-05 Thread David Lebrun
This patch implements a new type of lightweight tunnel named seg6local.
A seg6local lwt is defined by a type of action and a set of parameters.
The action represents the operation to perform on the packets matching the
lwt's route, and is not necessarily an encapsulation. The set of parameters
are arguments for the processing function.

Each action is defined in a struct seg6_action_desc within
seg6_action_table[]. This structure contains the action, mandatory
attributes, the processing function, and a static headroom size required by
the action. The mandatory attributes are encoded as a bitmask field. The
static headroom is set to a non-zero value when the processing function
always add a constant number of bytes to the skb (e.g. the header size for
encapsulations).

To facilitate rtnetlink-related operations such as parsing, fill_encap,
and cmp_encap, each type of action parameter is associated to three
function pointers, in seg6_action_params[].

All actions defined in seg6_local.h are detailed in [1].

[1] 
https://tools.ietf.org/html/draft-filsfils-spring-srv6-network-programming-01

Signed-off-by: David Lebrun 
---
 include/linux/seg6_local.h  |   6 +
 include/net/seg6.h  |   2 +
 include/uapi/linux/lwtunnel.h   |   1 +
 include/uapi/linux/seg6_local.h |  68 +
 net/core/lwtunnel.c |   2 +
 net/ipv6/Kconfig|   3 +-
 net/ipv6/Makefile   |   2 +-
 net/ipv6/seg6.c |   5 +
 net/ipv6/seg6_local.c   | 320 
 9 files changed, 407 insertions(+), 2 deletions(-)
 create mode 100644 include/linux/seg6_local.h
 create mode 100644 include/uapi/linux/seg6_local.h
 create mode 100644 net/ipv6/seg6_local.c

diff --git a/include/linux/seg6_local.h b/include/linux/seg6_local.h
new file mode 100644
index 000..ee63e76
--- /dev/null
+++ b/include/linux/seg6_local.h
@@ -0,0 +1,6 @@
+#ifndef _LINUX_SEG6_LOCAL_H
+#define _LINUX_SEG6_LOCAL_H
+
+#include 
+
+#endif
diff --git a/include/net/seg6.h b/include/net/seg6.h
index a32abb0..5379f55 100644
--- a/include/net/seg6.h
+++ b/include/net/seg6.h
@@ -56,6 +56,8 @@ extern int seg6_init(void);
 extern void seg6_exit(void);
 extern int seg6_iptunnel_init(void);
 extern void seg6_iptunnel_exit(void);
+extern int seg6_local_init(void);
+extern void seg6_local_exit(void);
 
 extern bool seg6_validate_srh(struct ipv6_sr_hdr *srh, int len);
 extern int seg6_do_srh_encap(struct sk_buff *skb, struct ipv6_sr_hdr *osrh);
diff --git a/include/uapi/linux/lwtunnel.h b/include/uapi/linux/lwtunnel.h
index 92724cba..7fdd19c 100644
--- a/include/uapi/linux/lwtunnel.h
+++ b/include/uapi/linux/lwtunnel.h
@@ -11,6 +11,7 @@ enum lwtunnel_encap_types {
LWTUNNEL_ENCAP_IP6,
LWTUNNEL_ENCAP_SEG6,
LWTUNNEL_ENCAP_BPF,
+   LWTUNNEL_ENCAP_SEG6_LOCAL,
__LWTUNNEL_ENCAP_MAX,
 };
 
diff --git a/include/uapi/linux/seg6_local.h b/include/uapi/linux/seg6_local.h
new file mode 100644
index 000..ef2d8c3
--- /dev/null
+++ b/include/uapi/linux/seg6_local.h
@@ -0,0 +1,68 @@
+/*
+ *  SR-IPv6 implementation
+ *
+ *  Author:
+ *  David Lebrun 
+ *
+ *
+ *  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.
+ */
+
+#ifndef _UAPI_LINUX_SEG6_LOCAL_H
+#define _UAPI_LINUX_SEG6_LOCAL_H
+
+#include 
+
+enum {
+   SEG6_LOCAL_UNSPEC,
+   SEG6_LOCAL_ACTION,
+   SEG6_LOCAL_SRH,
+   SEG6_LOCAL_TABLE,
+   SEG6_LOCAL_NH4,
+   SEG6_LOCAL_NH6,
+   SEG6_LOCAL_IIF,
+   SEG6_LOCAL_OIF,
+   __SEG6_LOCAL_MAX,
+};
+#define SEG6_LOCAL_MAX (__SEG6_LOCAL_MAX - 1)
+
+enum {
+   SEG6_LOCAL_ACTION_UNSPEC= 0,
+   /* node segment */
+   SEG6_LOCAL_ACTION_END   = 1,
+   /* adjacency segment (IPv6 cross-connect) */
+   SEG6_LOCAL_ACTION_END_X = 2,
+   /* lookup of next seg NH in table */
+   SEG6_LOCAL_ACTION_END_T = 3,
+   /* decap and L2 cross-connect */
+   SEG6_LOCAL_ACTION_END_DX2   = 4,
+   /* decap and IPv6 cross-connect */
+   SEG6_LOCAL_ACTION_END_DX6   = 5,
+   /* decap and IPv4 cross-connect */
+   SEG6_LOCAL_ACTION_END_DX4   = 6,
+   /* decap and lookup of DA in v6 table */
+   SEG6_LOCAL_ACTION_END_DT6   = 7,
+   /* decap and lookup of DA in v4 table */
+   SEG6_LOCAL_ACTION_END_DT4   = 8,
+   /* binding segment with insertion */
+   SEG6_LOCAL_ACTION_END_B6= 9,
+   /* binding segment with encapsulation */
+   SEG6_LOCAL_ACTION_END_B6_ENCAP  = 10,
+   /* binding segment with MPLS encap */
+   SEG6_LOCAL_ACTION_END_BM= 11,
+   /* lookup last seg in table */
+   SEG6_LOCAL_ACTION_END_S = 12,
+   /* 

[PATCH net-next v2 2/5] ipv6: sr: export SRH insertion functions

2017-08-05 Thread David Lebrun
This patch exports the seg6_do_srh_encap() and seg6_do_srh_inline()
functions. It also removes the CONFIG_IPV6_SEG6_INLINE knob
that enabled the compilation of seg6_do_srh_inline(). This function
is now built-in.

Signed-off-by: David Lebrun 
---
 include/net/seg6.h   |  2 ++
 net/ipv6/Kconfig | 12 
 net/ipv6/seg6_iptunnel.c | 12 
 3 files changed, 6 insertions(+), 20 deletions(-)

diff --git a/include/net/seg6.h b/include/net/seg6.h
index 4e03575..a32abb0 100644
--- a/include/net/seg6.h
+++ b/include/net/seg6.h
@@ -58,5 +58,7 @@ extern int seg6_iptunnel_init(void);
 extern void seg6_iptunnel_exit(void);
 
 extern bool seg6_validate_srh(struct ipv6_sr_hdr *srh, int len);
+extern int seg6_do_srh_encap(struct sk_buff *skb, struct ipv6_sr_hdr *osrh);
+extern int seg6_do_srh_inline(struct sk_buff *skb, struct ipv6_sr_hdr *osrh);
 
 #endif
diff --git a/net/ipv6/Kconfig b/net/ipv6/Kconfig
index 48c4529..50181a9 100644
--- a/net/ipv6/Kconfig
+++ b/net/ipv6/Kconfig
@@ -315,18 +315,6 @@ config IPV6_SEG6_LWTUNNEL
 
  If unsure, say N.
 
-config IPV6_SEG6_INLINE
-   bool "IPv6: direct Segment Routing Header insertion "
-   depends on IPV6_SEG6_LWTUNNEL
-   ---help---
- Support for direct insertion of the Segment Routing Header,
- also known as inline mode. Be aware that direct insertion of
- extension headers (as opposed to encapsulation) may break
- multiple mechanisms such as PMTUD or IPSec AH. Use this feature
- only if you know exactly what you are doing.
-
- If unsure, say N.
-
 config IPV6_SEG6_HMAC
bool "IPv6: Segment Routing HMAC support"
depends on IPV6
diff --git a/net/ipv6/seg6_iptunnel.c b/net/ipv6/seg6_iptunnel.c
index 264d772..5012330 100644
--- a/net/ipv6/seg6_iptunnel.c
+++ b/net/ipv6/seg6_iptunnel.c
@@ -91,7 +91,7 @@ static void set_tun_src(struct net *net, struct net_device 
*dev,
 }
 
 /* encapsulate an IPv6 packet within an outer IPv6 header with a given SRH */
-static int seg6_do_srh_encap(struct sk_buff *skb, struct ipv6_sr_hdr *osrh)
+int seg6_do_srh_encap(struct sk_buff *skb, struct ipv6_sr_hdr *osrh)
 {
struct net *net = dev_net(skb_dst(skb)->dev);
struct ipv6hdr *hdr, *inner_hdr;
@@ -141,10 +141,10 @@ static int seg6_do_srh_encap(struct sk_buff *skb, struct 
ipv6_sr_hdr *osrh)
 
return 0;
 }
+EXPORT_SYMBOL_GPL(seg6_do_srh_encap);
 
 /* insert an SRH within an IPv6 packet, just after the IPv6 header */
-#ifdef CONFIG_IPV6_SEG6_INLINE
-static int seg6_do_srh_inline(struct sk_buff *skb, struct ipv6_sr_hdr *osrh)
+int seg6_do_srh_inline(struct sk_buff *skb, struct ipv6_sr_hdr *osrh)
 {
struct ipv6hdr *hdr, *oldhdr;
struct ipv6_sr_hdr *isrh;
@@ -193,7 +193,7 @@ static int seg6_do_srh_inline(struct sk_buff *skb, struct 
ipv6_sr_hdr *osrh)
 
return 0;
 }
-#endif
+EXPORT_SYMBOL_GPL(seg6_do_srh_inline);
 
 static int seg6_do_srh(struct sk_buff *skb)
 {
@@ -209,12 +209,10 @@ static int seg6_do_srh(struct sk_buff *skb)
}
 
switch (tinfo->mode) {
-#ifdef CONFIG_IPV6_SEG6_INLINE
case SEG6_IPTUN_MODE_INLINE:
err = seg6_do_srh_inline(skb, tinfo->srh);
skb_reset_inner_headers(skb);
break;
-#endif
case SEG6_IPTUN_MODE_ENCAP:
err = seg6_do_srh_encap(skb, tinfo->srh);
break;
@@ -357,10 +355,8 @@ static int seg6_build_state(struct nlattr *nla,
return -EINVAL;
 
switch (tuninfo->mode) {
-#ifdef CONFIG_IPV6_SEG6_INLINE
case SEG6_IPTUN_MODE_INLINE:
break;
-#endif
case SEG6_IPTUN_MODE_ENCAP:
break;
default:
-- 
2.10.2



[PATCH net-next v2 4/5] ipv6: sr: add rtnetlink functions for seg6local action parameters

2017-08-05 Thread David Lebrun
This patch adds the necessary functions to parse, fill, and compare
seg6local rtnetlink attributes, for all defined action parameters.

- The SRH parameter defines an SRH to be inserted or encapsulated.
- The TABLE parameter defines the table to use for the route lookup of
  the next segment or the inner decapsulated packet.
- The NH4 parameter defines the IPv4 next-hop for an inner decapsulated
  IPv4 packet.
- The NH6 parameter defines the IPv6 next-hop for the next segment or
  for an inner decapsulated IPv6 packet
- The IIF parameter defines an ingress interface index.
- The OIF parameter defines an egress interface index.

Signed-off-by: David Lebrun 
---
 net/ipv6/seg6_local.c | 211 +-
 1 file changed, 193 insertions(+), 18 deletions(-)

diff --git a/net/ipv6/seg6_local.c b/net/ipv6/seg6_local.c
index 53615d7..ab1fc1b 100644
--- a/net/ipv6/seg6_local.c
+++ b/net/ipv6/seg6_local.c
@@ -104,6 +104,181 @@ static const struct nla_policy 
seg6_local_policy[SEG6_LOCAL_MAX + 1] = {
[SEG6_LOCAL_OIF]= { .type = NLA_U32 },
 };
 
+static int parse_nla_srh(struct nlattr **attrs, struct seg6_local_lwt *slwt)
+{
+   struct ipv6_sr_hdr *srh;
+   int len;
+
+   srh = nla_data(attrs[SEG6_LOCAL_SRH]);
+   len = nla_len(attrs[SEG6_LOCAL_SRH]);
+
+   /* SRH must contain at least one segment */
+   if (len < sizeof(*srh) + sizeof(struct in6_addr))
+   return -EINVAL;
+
+   if (!seg6_validate_srh(srh, len))
+   return -EINVAL;
+
+   slwt->srh = kmalloc(len, GFP_KERNEL);
+   if (!slwt->srh)
+   return -ENOMEM;
+
+   memcpy(slwt->srh, srh, len);
+
+   slwt->headroom += len;
+
+   return 0;
+}
+
+static int put_nla_srh(struct sk_buff *skb, struct seg6_local_lwt *slwt)
+{
+   struct ipv6_sr_hdr *srh;
+   struct nlattr *nla;
+   int len;
+
+   srh = slwt->srh;
+   len = (srh->hdrlen + 1) << 3;
+
+   nla = nla_reserve(skb, SEG6_LOCAL_SRH, len);
+   if (!nla)
+   return -EMSGSIZE;
+
+   memcpy(nla_data(nla), srh, len);
+
+   return 0;
+}
+
+static int cmp_nla_srh(struct seg6_local_lwt *a, struct seg6_local_lwt *b)
+{
+   int len = (a->srh->hdrlen + 1) << 3;
+
+   if (len != ((b->srh->hdrlen + 1) << 3))
+   return 1;
+
+   return memcmp(a->srh, b->srh, len);
+}
+
+static int parse_nla_table(struct nlattr **attrs, struct seg6_local_lwt *slwt)
+{
+   slwt->table = nla_get_u32(attrs[SEG6_LOCAL_TABLE]);
+
+   return 0;
+}
+
+static int put_nla_table(struct sk_buff *skb, struct seg6_local_lwt *slwt)
+{
+   if (nla_put_u32(skb, SEG6_LOCAL_TABLE, slwt->table))
+   return -EMSGSIZE;
+
+   return 0;
+}
+
+static int cmp_nla_table(struct seg6_local_lwt *a, struct seg6_local_lwt *b)
+{
+   if (a->table != b->table)
+   return 1;
+
+   return 0;
+}
+
+static int parse_nla_nh4(struct nlattr **attrs, struct seg6_local_lwt *slwt)
+{
+   memcpy(>nh4, nla_data(attrs[SEG6_LOCAL_NH4]),
+  sizeof(struct in_addr));
+
+   return 0;
+}
+
+static int put_nla_nh4(struct sk_buff *skb, struct seg6_local_lwt *slwt)
+{
+   struct nlattr *nla;
+
+   nla = nla_reserve(skb, SEG6_LOCAL_NH4, sizeof(struct in_addr));
+   if (!nla)
+   return -EMSGSIZE;
+
+   memcpy(nla_data(nla), >nh4, sizeof(struct in_addr));
+
+   return 0;
+}
+
+static int cmp_nla_nh4(struct seg6_local_lwt *a, struct seg6_local_lwt *b)
+{
+   return memcmp(>nh4, >nh4, sizeof(struct in_addr));
+}
+
+static int parse_nla_nh6(struct nlattr **attrs, struct seg6_local_lwt *slwt)
+{
+   memcpy(>nh6, nla_data(attrs[SEG6_LOCAL_NH6]),
+  sizeof(struct in6_addr));
+
+   return 0;
+}
+
+static int put_nla_nh6(struct sk_buff *skb, struct seg6_local_lwt *slwt)
+{
+   struct nlattr *nla;
+
+   nla = nla_reserve(skb, SEG6_LOCAL_NH6, sizeof(struct in6_addr));
+   if (!nla)
+   return -EMSGSIZE;
+
+   memcpy(nla_data(nla), >nh6, sizeof(struct in6_addr));
+
+   return 0;
+}
+
+static int cmp_nla_nh6(struct seg6_local_lwt *a, struct seg6_local_lwt *b)
+{
+   return memcmp(>nh6, >nh6, sizeof(struct in6_addr));
+}
+
+static int parse_nla_iif(struct nlattr **attrs, struct seg6_local_lwt *slwt)
+{
+   slwt->iif = nla_get_u32(attrs[SEG6_LOCAL_IIF]);
+
+   return 0;
+}
+
+static int put_nla_iif(struct sk_buff *skb, struct seg6_local_lwt *slwt)
+{
+   if (nla_put_u32(skb, SEG6_LOCAL_IIF, slwt->iif))
+   return -EMSGSIZE;
+
+   return 0;
+}
+
+static int cmp_nla_iif(struct seg6_local_lwt *a, struct seg6_local_lwt *b)
+{
+   if (a->iif != b->iif)
+   return 1;
+
+   return 0;
+}
+
+static int parse_nla_oif(struct nlattr **attrs, struct seg6_local_lwt *slwt)
+{
+   slwt->oif = nla_get_u32(attrs[SEG6_LOCAL_OIF]);
+
+   return 0;
+}
+
+static int put_nla_oif(struct 

[PATCH net-next v2 0/5] ipv6: sr: add support for advanced local segment processing

2017-08-05 Thread David Lebrun
v2: use EXPORT_SYMBOL_GPL

The current implementation of IPv6 SR supports SRH insertion/encapsulation
and basic segment endpoint behavior (i.e., processing of an SRH contained in
a packet whose active segment (IPv6 DA) is routed to the local node). This
behavior simply consists of updating the DA to the next segment and forwarding
the packet accordingly. This processing is realised for all such packets,
regardless of the active segment.

The most recent specifications of IPv6 SR [1] [2] extend the SRH processing
features as follows. Each segment endpoint defines a MyLocalSID table.
This table maps segments to operations to perform. For each ingress IPv6
packet whose DA is part of a given prefix, the segment endpoint looks
up the active segment (i.e., the IPv6 DA) in the MyLocalSID table and
applies the corresponding operation. Such specifications enable to specify
arbitrary operations besides the basic SRH processing and allow for a more
fine-grained classification.

This patch series implements those extended specifications by leveraging
a new type of lightweight tunnel, seg6local. The MyLocalSID table is
simply an arbitrary routing table (using CONFIG_IPV6_MULTIPLE_TABLES). The
following commands would assign the prefix fc00::/64 to the MyLocalSID
table, map the segment fc00::42 to the regular SRH processing function
(named "End"), and drop all packets received with an undefined active
segment:

ip -6 rule add fc00::/64 lookup 100
ip -6 route add fc00::42 encap seg6local action End dev eth0 table 100
ip -6 route add blackhole default table 100

As another example, the following command would assign the segment
fc00::1234 to the regular SRH processing function, except that the
processed packet must be forwarded to the next-hop fc42::1 (this operation
is named "End.X"):

ip -6 route add fc00::1234 encap seg6local action End.X nh6 fc42::1 dev eth0 
table 100

Those two basic operations (End and End.X) are defined in [1]. A more
extensive list of advanced operations is defined in [2].

The first two patches of the series are preliminary work that remove an
assumption about initial SRH format, and export the two functions used to
insert and encapsulate an SRH onto packets. The third patch defines the
new seg6local lightweight tunnel and implement the core functions. The
fourth patch implements the operations needed to handle the newly defined
rtnetlink attributes. The fifth patch implements a few SRH processing
operations, including End and End.X.

[1] https://tools.ietf.org/html/draft-ietf-6man-segment-routing-header-07
[2] 
https://tools.ietf.org/html/draft-filsfils-spring-srv6-network-programming-01

David Lebrun (5):
  ipv6: sr: allow SRH insertion with arbitrary segments_left value
  ipv6: sr: export SRH insertion functions
  ipv6: sr: define core operations for seg6local lightweight tunnel
  ipv6: sr: add rtnetlink functions for seg6local action parameters
  ipv6: sr: implement several seg6local actions

 include/linux/seg6_local.h  |   6 +
 include/net/seg6.h  |   4 +
 include/uapi/linux/lwtunnel.h   |   1 +
 include/uapi/linux/seg6_local.h |  68 
 net/core/lwtunnel.c |   2 +
 net/ipv6/Kconfig|  15 +-
 net/ipv6/Makefile   |   2 +-
 net/ipv6/exthdrs.c  |   4 +-
 net/ipv6/seg6.c |   7 +-
 net/ipv6/seg6_iptunnel.c|  12 +-
 net/ipv6/seg6_local.c   | 766 
 11 files changed, 862 insertions(+), 25 deletions(-)
 create mode 100644 include/linux/seg6_local.h
 create mode 100644 include/uapi/linux/seg6_local.h
 create mode 100644 net/ipv6/seg6_local.c

-- 
2.10.2



[PATCH net-next v2 1/5] ipv6: sr: allow SRH insertion with arbitrary segments_left value

2017-08-05 Thread David Lebrun
The seg6_validate_srh() function only allows SRHs whose active segment is
the first segment of the path. However, an application may insert an SRH
whose active segment is not the first one. Such an application might be
for example an SR-aware Virtual Network Function.

This patch enables to insert SRHs with an arbitrary active segment.

Signed-off-by: David Lebrun 
---
 net/ipv6/exthdrs.c | 4 ++--
 net/ipv6/seg6.c| 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/net/ipv6/exthdrs.c b/net/ipv6/exthdrs.c
index 3cec529..9551613 100644
--- a/net/ipv6/exthdrs.c
+++ b/net/ipv6/exthdrs.c
@@ -882,7 +882,7 @@ static void ipv6_push_rthdr4(struct sk_buff *skb, u8 *proto,
   (hops - 1) * sizeof(struct in6_addr));
 
sr_phdr->segments[0] = **addr_p;
-   *addr_p = _ihdr->segments[hops - 1];
+   *addr_p = _ihdr->segments[sr_ihdr->segments_left];
 
 #ifdef CONFIG_IPV6_SEG6_HMAC
if (sr_has_hmac(sr_phdr)) {
@@ -1174,7 +1174,7 @@ struct in6_addr *fl6_update_dst(struct flowi6 *fl6,
{
struct ipv6_sr_hdr *srh = (struct ipv6_sr_hdr *)opt->srcrt;
 
-   fl6->daddr = srh->segments[srh->first_segment];
+   fl6->daddr = srh->segments[srh->segments_left];
break;
}
default:
diff --git a/net/ipv6/seg6.c b/net/ipv6/seg6.c
index 15fba55..81c2339 100644
--- a/net/ipv6/seg6.c
+++ b/net/ipv6/seg6.c
@@ -40,7 +40,7 @@ bool seg6_validate_srh(struct ipv6_sr_hdr *srh, int len)
if (((srh->hdrlen + 1) << 3) != len)
return false;
 
-   if (srh->segments_left != srh->first_segment)
+   if (srh->segments_left > srh->first_segment)
return false;
 
tlv_offset = sizeof(*srh) + ((srh->first_segment + 1) << 4);
-- 
2.10.2



[PATCH net] net: sched: set xt_tgchk_param par.net properly in ipt_init_target

2017-08-05 Thread Xin Long
Now xt_tgchk_param par in ipt_init_target is a local varibale,
par.net is not initialized there. Later when xt_check_target
calls target's checkentry in which it may access par.net, it
would cause kernel panic.

Jaroslav found this panic when running:

  # ip link add TestIface type dummy
  # tc qd add dev TestIface ingress handle :
  # tc filter add dev TestIface parent : u32 match u32 0 0 \
action xt -j CONNMARK --set-mark 4

This patch is to pass net param into ipt_init_target and set
par.net with it properly in there.

Reported-by: Jaroslav Aster 
Signed-off-by: Xin Long 
---
 net/sched/act_ipt.c | 18 --
 1 file changed, 8 insertions(+), 10 deletions(-)

diff --git a/net/sched/act_ipt.c b/net/sched/act_ipt.c
index 36f0ced..bb06d2ed 100644
--- a/net/sched/act_ipt.c
+++ b/net/sched/act_ipt.c
@@ -36,8 +36,8 @@ static struct tc_action_ops act_ipt_ops;
 static unsigned int xt_net_id;
 static struct tc_action_ops act_xt_ops;
 
-static int ipt_init_target(struct xt_entry_target *t, char *table,
-  unsigned int hook)
+static int ipt_init_target(struct net *net, struct xt_entry_target *t,
+  char *table, unsigned int hook)
 {
struct xt_tgchk_param par;
struct xt_target *target;
@@ -49,6 +49,7 @@ static int ipt_init_target(struct xt_entry_target *t, char 
*table,
return PTR_ERR(target);
 
t->u.kernel.target = target;
+   par.net   = net;
par.table = table;
par.entryinfo = NULL;
par.target= target;
@@ -91,10 +92,11 @@ static const struct nla_policy ipt_policy[TCA_IPT_MAX + 1] 
= {
[TCA_IPT_TARG]  = { .len = sizeof(struct xt_entry_target) },
 };
 
-static int __tcf_ipt_init(struct tc_action_net *tn, struct nlattr *nla,
+static int __tcf_ipt_init(struct net *net, struct nlattr *nla,
  struct nlattr *est, struct tc_action **a,
  const struct tc_action_ops *ops, int ovr, int bind)
 {
+   struct tc_action_net *tn = net_generic(net, xt_net_id);
struct nlattr *tb[TCA_IPT_MAX + 1];
struct tcf_ipt *ipt;
struct xt_entry_target *td, *t;
@@ -159,7 +161,7 @@ static int __tcf_ipt_init(struct tc_action_net *tn, struct 
nlattr *nla,
if (unlikely(!t))
goto err2;
 
-   err = ipt_init_target(t, tname, hook);
+   err = ipt_init_target(net, t, tname, hook);
if (err < 0)
goto err3;
 
@@ -193,18 +195,14 @@ static int tcf_ipt_init(struct net *net, struct nlattr 
*nla,
struct nlattr *est, struct tc_action **a, int ovr,
int bind)
 {
-   struct tc_action_net *tn = net_generic(net, ipt_net_id);
-
-   return __tcf_ipt_init(tn, nla, est, a, _ipt_ops, ovr, bind);
+   return __tcf_ipt_init(net, nla, est, a, _ipt_ops, ovr, bind);
 }
 
 static int tcf_xt_init(struct net *net, struct nlattr *nla,
   struct nlattr *est, struct tc_action **a, int ovr,
   int bind)
 {
-   struct tc_action_net *tn = net_generic(net, xt_net_id);
-
-   return __tcf_ipt_init(tn, nla, est, a, _xt_ops, ovr, bind);
+   return __tcf_ipt_init(net, nla, est, a, _xt_ops, ovr, bind);
 }
 
 static int tcf_ipt(struct sk_buff *skb, const struct tc_action *a,
-- 
2.1.0



[PATCH v9 4/4] net/cxgb4vf: Use new PCI_DEV_FLAGS_NO_RELAXED_ORDERING flag

2017-08-05 Thread Ding Tianhong
From: Casey Leedom 

cxgb4vf Ethernet driver now queries PCIe configuration space to
determine if it can send TLPs to it with the Relaxed Ordering
Attribute set, just like the pf did.

Signed-off-by: Casey Leedom 
Signed-off-by: Ding Tianhong 
Reviewed-by: Casey Leedom 
---
 drivers/net/ethernet/chelsio/cxgb4vf/adapter.h  |  1 +
 drivers/net/ethernet/chelsio/cxgb4vf/cxgb4vf_main.c | 18 ++
 drivers/net/ethernet/chelsio/cxgb4vf/sge.c  |  3 +++
 3 files changed, 22 insertions(+)

diff --git a/drivers/net/ethernet/chelsio/cxgb4vf/adapter.h 
b/drivers/net/ethernet/chelsio/cxgb4vf/adapter.h
index 109bc63..08c6ddb 100644
--- a/drivers/net/ethernet/chelsio/cxgb4vf/adapter.h
+++ b/drivers/net/ethernet/chelsio/cxgb4vf/adapter.h
@@ -408,6 +408,7 @@ enum { /* adapter flags */
USING_MSI  = (1UL << 1),
USING_MSIX = (1UL << 2),
QUEUES_BOUND   = (1UL << 3),
+   ROOT_NO_RELAXED_ORDERING = (1UL << 4),
 };
 
 /*
diff --git a/drivers/net/ethernet/chelsio/cxgb4vf/cxgb4vf_main.c 
b/drivers/net/ethernet/chelsio/cxgb4vf/cxgb4vf_main.c
index ac7a150..59e7639 100644
--- a/drivers/net/ethernet/chelsio/cxgb4vf/cxgb4vf_main.c
+++ b/drivers/net/ethernet/chelsio/cxgb4vf/cxgb4vf_main.c
@@ -2888,6 +2888,24 @@ static int cxgb4vf_pci_probe(struct pci_dev *pdev,
 */
adapter->name = pci_name(pdev);
adapter->msg_enable = DFLT_MSG_ENABLE;
+
+   /* If possible, we use PCIe Relaxed Ordering Attribute to deliver
+* Ingress Packet Data to Free List Buffers in order to allow for
+* chipset performance optimizations between the Root Complex and
+* Memory Controllers.  (Messages to the associated Ingress Queue
+* notifying new Packet Placement in the Free Lists Buffers will be
+* send without the Relaxed Ordering Attribute thus guaranteeing that
+* all preceding PCIe Transaction Layer Packets will be processed
+* first.)  But some Root Complexes have various issues with Upstream
+* Transaction Layer Packets with the Relaxed Ordering Attribute set.
+* The PCIe devices which under the Root Complexes will be cleared the
+* Relaxed Ordering bit in the configuration space, So we check our
+* PCIe configuration space to see if it's flagged with advice against
+* using Relaxed Ordering.
+*/
+   if (!pcie_relaxed_ordering_supported(pdev))
+   adapter->flags |= ROOT_NO_RELAXED_ORDERING;
+
err = adap_init0(adapter);
if (err)
goto err_unmap_bar;
diff --git a/drivers/net/ethernet/chelsio/cxgb4vf/sge.c 
b/drivers/net/ethernet/chelsio/cxgb4vf/sge.c
index e37dde2..05498e7 100644
--- a/drivers/net/ethernet/chelsio/cxgb4vf/sge.c
+++ b/drivers/net/ethernet/chelsio/cxgb4vf/sge.c
@@ -2205,6 +2205,7 @@ int t4vf_sge_alloc_rxq(struct adapter *adapter, struct 
sge_rspq *rspq,
struct port_info *pi = netdev_priv(dev);
struct fw_iq_cmd cmd, rpl;
int ret, iqandst, flsz = 0;
+   int relaxed = !(adapter->flags & ROOT_NO_RELAXED_ORDERING);
 
/*
 * If we're using MSI interrupts and we're not initializing the
@@ -2300,6 +2301,8 @@ int t4vf_sge_alloc_rxq(struct adapter *adapter, struct 
sge_rspq *rspq,
cpu_to_be32(
FW_IQ_CMD_FL0HOSTFCMODE_V(SGE_HOSTFCMODE_NONE) |
FW_IQ_CMD_FL0PACKEN_F |
+   FW_IQ_CMD_FL0FETCHRO_V(relaxed) |
+   FW_IQ_CMD_FL0DATARO_V(relaxed) |
FW_IQ_CMD_FL0PADEN_F);
 
/* In T6, for egress queue type FL there is internal overhead
-- 
1.8.3.1




[PATCH v9 1/4] PCI: Add new PCIe Fabric End Node flag, PCI_DEV_FLAGS_NO_RELAXED_ORDERING

2017-08-05 Thread Ding Tianhong
From: Casey Leedom 

The patch adds a new flag PCI_DEV_FLAGS_NO_RELAXED_ORDERING to indicate that
Relaxed Ordering (RO) attribute should not be used for Transaction Layer
Packets (TLP) targetted towards these affected root complexes. Current list
of affected parts include some Intel Xeon processors root complex which suffers 
from
flow control credits that result in performance issues. On these affected
parts RO can still be used for peer-2-peer traffic. AMD A1100 ARM ("SEATTLE")
Root complexes don't obey PCIe 3.0 ordering rules, hence could lead to
data-corruption.

Signed-off-by: Casey Leedom 
Signed-off-by: Ding Tianhong 
Acked-by: Ashok Raj 
---
 drivers/pci/quirks.c | 88 
 include/linux/pci.h  |  2 ++
 2 files changed, 90 insertions(+)

diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c
index 6967c6b..5c9e125 100644
--- a/drivers/pci/quirks.c
+++ b/drivers/pci/quirks.c
@@ -4016,6 +4016,94 @@ static void quirk_tw686x_class(struct pci_dev *pdev)
  quirk_tw686x_class);
 
 /*
+ * Some devices have problems with Transaction Layer Packets with the Relaxed
+ * Ordering Attribute set.  Such devices should mark themselves and other
+ * Device Drivers should check before sending TLPs with RO set.
+ */
+static void quirk_relaxedordering_disable(struct pci_dev *dev)
+{
+   dev->dev_flags |= PCI_DEV_FLAGS_NO_RELAXED_ORDERING;
+}
+
+/*
+ * Intel Xeon processors based on Broadwell/Haswell microarchitecture Root
+ * Complex has a Flow Control Credit issue which can cause performance
+ * problems with Upstream Transaction Layer Packets with Relaxed Ordering set.
+ */
+DECLARE_PCI_FIXUP_CLASS_EARLY(PCI_VENDOR_ID_INTEL, 0x6f01, 
PCI_CLASS_NOT_DEFINED, 8,
+ quirk_relaxedordering_disable);
+DECLARE_PCI_FIXUP_CLASS_EARLY(PCI_VENDOR_ID_INTEL, 0x6f02, 
PCI_CLASS_NOT_DEFINED, 8,
+ quirk_relaxedordering_disable);
+DECLARE_PCI_FIXUP_CLASS_EARLY(PCI_VENDOR_ID_INTEL, 0x6f03, 
PCI_CLASS_NOT_DEFINED, 8,
+ quirk_relaxedordering_disable);
+DECLARE_PCI_FIXUP_CLASS_EARLY(PCI_VENDOR_ID_INTEL, 0x6f04, 
PCI_CLASS_NOT_DEFINED, 8,
+ quirk_relaxedordering_disable);
+DECLARE_PCI_FIXUP_CLASS_EARLY(PCI_VENDOR_ID_INTEL, 0x6f05, 
PCI_CLASS_NOT_DEFINED, 8,
+ quirk_relaxedordering_disable);
+DECLARE_PCI_FIXUP_CLASS_EARLY(PCI_VENDOR_ID_INTEL, 0x6f06, 
PCI_CLASS_NOT_DEFINED, 8,
+ quirk_relaxedordering_disable);
+DECLARE_PCI_FIXUP_CLASS_EARLY(PCI_VENDOR_ID_INTEL, 0x6f07, 
PCI_CLASS_NOT_DEFINED, 8,
+ quirk_relaxedordering_disable);
+DECLARE_PCI_FIXUP_CLASS_EARLY(PCI_VENDOR_ID_INTEL, 0x6f08, 
PCI_CLASS_NOT_DEFINED, 8,
+ quirk_relaxedordering_disable);
+DECLARE_PCI_FIXUP_CLASS_EARLY(PCI_VENDOR_ID_INTEL, 0x6f09, 
PCI_CLASS_NOT_DEFINED, 8,
+ quirk_relaxedordering_disable);
+DECLARE_PCI_FIXUP_CLASS_EARLY(PCI_VENDOR_ID_INTEL, 0x6f0a, 
PCI_CLASS_NOT_DEFINED, 8,
+ quirk_relaxedordering_disable);
+DECLARE_PCI_FIXUP_CLASS_EARLY(PCI_VENDOR_ID_INTEL, 0x6f0b, 
PCI_CLASS_NOT_DEFINED, 8,
+ quirk_relaxedordering_disable);
+DECLARE_PCI_FIXUP_CLASS_EARLY(PCI_VENDOR_ID_INTEL, 0x6f0c, 
PCI_CLASS_NOT_DEFINED, 8,
+ quirk_relaxedordering_disable);
+DECLARE_PCI_FIXUP_CLASS_EARLY(PCI_VENDOR_ID_INTEL, 0x6f0d, 
PCI_CLASS_NOT_DEFINED, 8,
+ quirk_relaxedordering_disable);
+DECLARE_PCI_FIXUP_CLASS_EARLY(PCI_VENDOR_ID_INTEL, 0x6f0e, 
PCI_CLASS_NOT_DEFINED, 8,
+ quirk_relaxedordering_disable);
+DECLARE_PCI_FIXUP_CLASS_EARLY(PCI_VENDOR_ID_INTEL, 0x2f01, 
PCI_CLASS_NOT_DEFINED, 8,
+ quirk_relaxedordering_disable);
+DECLARE_PCI_FIXUP_CLASS_EARLY(PCI_VENDOR_ID_INTEL, 0x2f02, 
PCI_CLASS_NOT_DEFINED, 8,
+ quirk_relaxedordering_disable);
+DECLARE_PCI_FIXUP_CLASS_EARLY(PCI_VENDOR_ID_INTEL, 0x2f03, 
PCI_CLASS_NOT_DEFINED, 8,
+ quirk_relaxedordering_disable);
+DECLARE_PCI_FIXUP_CLASS_EARLY(PCI_VENDOR_ID_INTEL, 0x2f04, 
PCI_CLASS_NOT_DEFINED, 8,
+ quirk_relaxedordering_disable);
+DECLARE_PCI_FIXUP_CLASS_EARLY(PCI_VENDOR_ID_INTEL, 0x2f05, 
PCI_CLASS_NOT_DEFINED, 8,
+ quirk_relaxedordering_disable);
+DECLARE_PCI_FIXUP_CLASS_EARLY(PCI_VENDOR_ID_INTEL, 0x2f06, 
PCI_CLASS_NOT_DEFINED, 8,
+ quirk_relaxedordering_disable);
+DECLARE_PCI_FIXUP_CLASS_EARLY(PCI_VENDOR_ID_INTEL, 0x2f07, 
PCI_CLASS_NOT_DEFINED, 8,
+ quirk_relaxedordering_disable);
+DECLARE_PCI_FIXUP_CLASS_EARLY(PCI_VENDOR_ID_INTEL, 0x2f08, 
PCI_CLASS_NOT_DEFINED, 8,
+

[PATCH v9 2/4] PCI: Disable PCIe Relaxed Ordering if unsupported

2017-08-05 Thread Ding Tianhong
When bit4 is set in the PCIe Device Control register, it indicates
whether the device is permitted to use relaxed ordering.
On some platforms using relaxed ordering can have performance issues or
due to erratum can cause data-corruption. In such cases devices must avoid
using relaxed ordering.

This patch checks if there is any node in the hierarchy that indicates that
using relaxed ordering is not safe. In such cases the patch turns off the
relaxed ordering by clearing the eapability for this device. And if the
device is probably running in a guest machine, we should do nothing.

Signed-off-by: Ding Tianhong 
Acked-by: Alexander Duyck 
Acked-by: Ashok Raj 
---
 drivers/pci/pci.c   | 29 +
 drivers/pci/probe.c | 37 +
 include/linux/pci.h |  2 ++
 3 files changed, 68 insertions(+)

diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index af0cc34..4f9d7c1 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -4854,6 +4854,35 @@ int pcie_set_mps(struct pci_dev *dev, int mps)
 EXPORT_SYMBOL(pcie_set_mps);
 
 /**
+ * pcie_clear_relaxed_ordering - clear PCI Express relaxed ordering bit
+ * @dev: PCI device to query
+ *
+ * If possible clear relaxed ordering
+ */
+int pcie_clear_relaxed_ordering(struct pci_dev *dev)
+{
+   return pcie_capability_clear_word(dev, PCI_EXP_DEVCTL,
+ PCI_EXP_DEVCTL_RELAX_EN);
+}
+EXPORT_SYMBOL(pcie_clear_relaxed_ordering);
+
+/**
+ * pcie_relaxed_ordering_supported - Probe for PCIe relexed ordering support
+ * @dev: PCI device to query
+ *
+ * Returns true if the device support relaxed ordering attribute.
+ */
+bool pcie_relaxed_ordering_supported(struct pci_dev *dev)
+{
+   u16 v;
+
+   pcie_capability_read_word(dev, PCI_EXP_DEVCTL, );
+
+   return !!(v & PCI_EXP_DEVCTL_RELAX_EN);
+}
+EXPORT_SYMBOL(pcie_relaxed_ordering_supported);
+
+/**
  * pcie_get_minimum_link - determine minimum link settings of a PCI device
  * @dev: PCI device to query
  * @speed: storage for minimum speed
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index c31310d..48df012 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -1762,6 +1762,42 @@ static void pci_configure_extended_tags(struct pci_dev 
*dev)
 PCI_EXP_DEVCTL_EXT_TAG);
 }
 
+/**
+ * pci_dev_should_disable_relaxed_ordering - check if the PCI device
+ * should disable the relaxed ordering attribute.
+ * @dev: PCI device
+ *
+ * Return true if any of the PCI devices above us do not support
+ * relaxed ordering.
+ */
+static bool pci_dev_should_disable_relaxed_ordering(struct pci_dev *dev)
+{
+   while (dev) {
+   if (dev->dev_flags & PCI_DEV_FLAGS_NO_RELAXED_ORDERING)
+   return true;
+
+   dev = dev->bus->self;
+   }
+
+   return false;
+}
+
+static void pci_configure_relaxed_ordering(struct pci_dev *dev)
+{
+   /* We should not alter the relaxed ordering bit for the VF */
+   if (dev->is_virtfn)
+   return;
+
+   /* If the releaxed ordering enable bit is not set, do nothing. */
+   if (!pcie_relaxed_ordering_supported(dev))
+   return;
+
+   if (pci_dev_should_disable_relaxed_ordering(dev)) {
+   pcie_clear_relaxed_ordering(dev);
+   dev_info(>dev, "Disable Relaxed Ordering\n");
+   }
+}
+
 static void pci_configure_device(struct pci_dev *dev)
 {
struct hotplug_params hpp;
@@ -1769,6 +1805,7 @@ static void pci_configure_device(struct pci_dev *dev)
 
pci_configure_mps(dev);
pci_configure_extended_tags(dev);
+   pci_configure_relaxed_ordering(dev);
 
memset(, 0, sizeof(hpp));
ret = pci_get_hp_params(dev, );
diff --git a/include/linux/pci.h b/include/linux/pci.h
index 412ec1c..3aa23a2 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -1127,6 +1127,8 @@ int pci_add_ext_cap_save_buffer(struct pci_dev *dev,
 void pci_pme_wakeup_bus(struct pci_bus *bus);
 void pci_d3cold_enable(struct pci_dev *dev);
 void pci_d3cold_disable(struct pci_dev *dev);
+int pcie_clear_relaxed_ordering(struct pci_dev *dev);
+bool pcie_relaxed_ordering_supported(struct pci_dev *dev);
 
 /* PCI Virtual Channel */
 int pci_save_vc_state(struct pci_dev *dev);
-- 
1.8.3.1




[PATCH v9 0/4] Add new PCI_DEV_FLAGS_NO_RELAXED_ORDERING flag

2017-08-05 Thread Ding Tianhong
Some devices have problems with Transaction Layer Packets with the Relaxed
Ordering Attribute set.  This patch set adds a new PCIe Device Flag,
PCI_DEV_FLAGS_NO_RELAXED_ORDERING, a set of PCI Quirks to catch some known
devices with Relaxed Ordering issues, and a use of this new flag by the
cxgb4 driver to avoid using Relaxed Ordering with problematic Root Complex
Ports.

It's been years since I've submitted kernel.org patches, I appolgise for the
almost certain submission errors.

v2: Alexander point out that the v1 was only a part of the whole solution,
some platform which has some issues could use the new flag to indicate
that it is not safe to enable relaxed ordering attribute, then we need
to clear the relaxed ordering enable bits in the PCI configuration when
initializing the device. So add a new second patch to modify the PCI
initialization code to clear the relaxed ordering enable bit in the
event that the root complex doesn't want relaxed ordering enabled.

The third patch was base on the v1's second patch and only be changed
to query the relaxed ordering enable bit in the PCI configuration space
to allow the Chelsio NIC to send TLPs with the relaxed ordering attributes
set.

This version didn't plan to drop the defines for Intel Drivers to use the
new checking way to enable relaxed ordering because it is not the hardest
part of the moment, we could fix it in next patchset when this patches
reach the goal.

v3: Redesigned the logic for pci_configure_relaxed_ordering when configuration,
If a PCIe device didn't enable the relaxed ordering attribute default,
we should not do anything in the PCIe configuration, otherwise we
should check if any of the devices above us do not support relaxed
ordering by the PCI_DEV_FLAGS_NO_RELAXED_ORDERING flag, then base on
the result if we get a return that indicate that the relaxed ordering
is not supported we should update our device to disable relaxed ordering
in configuration space. If the device above us doesn't exist or isn't
the PCIe device, we shouldn't do anything and skip updating relaxed ordering
because we are probably running in a guest.

v4: Rename the functions pcie_get_relaxed_ordering and 
pcie_disable_relaxed_ordering
according John's suggestion, and modify the description, use the true/false
as the return value.

We shouldn't enable relaxed ordering attribute by the setting in the root
complex configuration space for PCIe device, so fix it for cxgb4.

Fix some format issues.

v5: Removed the unnecessary code for some function which only return the bool
value, and add the check for VF device.

Make this patch set base on 4.12-rc5.

v6: Fix the logic error in the need to enable the relaxed ordering attribute 
for cxgb4.

v7: The cxgb4 drivers will enable the PCIe Capability Device Control[Relaxed
Ordering Enable] in PCI Probe() routine, this will break our current
solution for some platform which has problematic when enable the relaxed
ordering attribute. According to the latest recommendations, remove the
enable_pcie_relaxed_ordering(), although it could not cover the Peer-to-Peer
scene, but we agree to leave this problem until we really trigger it.

Make this patch set base on 4.12 release version.

v8: Change the second patch title and description to make it more reasonable,
add the acked-by from Alex and Ashok.

Add a new patch to enable the Relaxed Ordering Attribute for cxgb4vf driver.

Make this patch set base on 4.13-rc2.

v9: The document (https://software.intel.com/sites/default/files/managed/9e/
bc/64-ia-32-architectures-optimization-manual.pdf) indicate that the Xeon
processors based on Broadwell/Haswell microarchitecture has the problem
with Relaxed Ordering Attribute enabled, so add the whole list Device ID
from Intel to the patch.

Casey Leedom (3):
  PCI: Add new PCIe Fabric End Node flag,
PCI_DEV_FLAGS_NO_RELAXED_ORDERING
  net/cxgb4: Use new PCI_DEV_FLAGS_NO_RELAXED_ORDERING flag
  net/cxgb4vf: Use new PCI_DEV_FLAGS_NO_RELAXED_ORDERING flag

Ding Tianhong (1):
  PCI: Disable PCIe Relaxed Ordering if unsupported

 drivers/net/ethernet/chelsio/cxgb4/cxgb4.h |  1 +
 drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c| 23 +
 drivers/net/ethernet/chelsio/cxgb4/sge.c   |  5 +--
 drivers/net/ethernet/chelsio/cxgb4vf/adapter.h |  1 +
 .../net/ethernet/chelsio/cxgb4vf/cxgb4vf_main.c| 18 ++
 drivers/net/ethernet/chelsio/cxgb4vf/sge.c |  3 ++
 drivers/pci/pci.c  | 29 +
 drivers/pci/probe.c| 37 +
 drivers/pci/quirks.c   | 88 ++
 include/linux/pci.h|  4 +++
 10 files changed, 151 insertions(+), 8 deletions(-)

-- 
1.8.3.1




[PATCH v9 3/4] net/cxgb4: Use new PCI_DEV_FLAGS_NO_RELAXED_ORDERING flag

2017-08-05 Thread Ding Tianhong
From: Casey Leedom 

cxgb4 Ethernet driver now queries PCIe configuration space to determine
if it can send TLPs to it with the Relaxed Ordering Attribute set.

Remove the enable_pcie_relaxed_ordering() to avoid enable PCIe Capability
Device Control[Relaxed Ordering Enable] at probe routine, to make sure
the driver will not send the Relaxed Ordering TLPs to the Root Complex which
could not deal the Relaxed Ordering TLPs.

Signed-off-by: Casey Leedom 
Signed-off-by: Ding Tianhong 
Reviewed-by: Casey Leedom 
---
 drivers/net/ethernet/chelsio/cxgb4/cxgb4.h  |  1 +
 drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c | 23 +--
 drivers/net/ethernet/chelsio/cxgb4/sge.c|  5 +++--
 3 files changed, 21 insertions(+), 8 deletions(-)

diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4.h 
b/drivers/net/ethernet/chelsio/cxgb4/cxgb4.h
index ef4be78..09ea62e 100644
--- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4.h
+++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4.h
@@ -529,6 +529,7 @@ enum { /* adapter flags */
USING_SOFT_PARAMS  = (1 << 6),
MASTER_PF  = (1 << 7),
FW_OFLD_CONN   = (1 << 9),
+   ROOT_NO_RELAXED_ORDERING = (1 << 10),
 };
 
 enum {
diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c 
b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
index e403fa1..391e484 100644
--- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
+++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
@@ -4654,11 +4654,6 @@ static void print_port_info(const struct net_device *dev)
dev->name, adap->params.vpd.id, adap->name, buf);
 }
 
-static void enable_pcie_relaxed_ordering(struct pci_dev *dev)
-{
-   pcie_capability_set_word(dev, PCI_EXP_DEVCTL, PCI_EXP_DEVCTL_RELAX_EN);
-}
-
 /*
  * Free the following resources:
  * - memory used for tables
@@ -4908,7 +4903,6 @@ static int init_one(struct pci_dev *pdev, const struct 
pci_device_id *ent)
}
 
pci_enable_pcie_error_reporting(pdev);
-   enable_pcie_relaxed_ordering(pdev);
pci_set_master(pdev);
pci_save_state(pdev);
 
@@ -4947,6 +4941,23 @@ static int init_one(struct pci_dev *pdev, const struct 
pci_device_id *ent)
adapter->msg_enable = DFLT_MSG_ENABLE;
memset(adapter->chan_map, 0xff, sizeof(adapter->chan_map));
 
+   /* If possible, we use PCIe Relaxed Ordering Attribute to deliver
+* Ingress Packet Data to Free List Buffers in order to allow for
+* chipset performance optimizations between the Root Complex and
+* Memory Controllers.  (Messages to the associated Ingress Queue
+* notifying new Packet Placement in the Free Lists Buffers will be
+* send without the Relaxed Ordering Attribute thus guaranteeing that
+* all preceding PCIe Transaction Layer Packets will be processed
+* first.)  But some Root Complexes have various issues with Upstream
+* Transaction Layer Packets with the Relaxed Ordering Attribute set.
+* The PCIe devices which under the Root Complexes will be cleared the
+* Relaxed Ordering bit in the configuration space, So we check our
+* PCIe configuration space to see if it's flagged with advice against
+* using Relaxed Ordering.
+*/
+   if (!pcie_relaxed_ordering_supported(pdev))
+   adapter->flags |= ROOT_NO_RELAXED_ORDERING;
+
spin_lock_init(>stats_lock);
spin_lock_init(>tid_release_lock);
spin_lock_init(>win0_lock);
diff --git a/drivers/net/ethernet/chelsio/cxgb4/sge.c 
b/drivers/net/ethernet/chelsio/cxgb4/sge.c
index ede1220..4ef68f6 100644
--- a/drivers/net/ethernet/chelsio/cxgb4/sge.c
+++ b/drivers/net/ethernet/chelsio/cxgb4/sge.c
@@ -2719,6 +2719,7 @@ int t4_sge_alloc_rxq(struct adapter *adap, struct 
sge_rspq *iq, bool fwevtq,
struct fw_iq_cmd c;
struct sge *s = >sge;
struct port_info *pi = netdev_priv(dev);
+   int relaxed = !(adap->flags & ROOT_NO_RELAXED_ORDERING);
 
/* Size needs to be multiple of 16, including status entry. */
iq->size = roundup(iq->size, 16);
@@ -2772,8 +2773,8 @@ int t4_sge_alloc_rxq(struct adapter *adap, struct 
sge_rspq *iq, bool fwevtq,
 
flsz = fl->size / 8 + s->stat_len / sizeof(struct tx_desc);
c.iqns_to_fl0congen |= htonl(FW_IQ_CMD_FL0PACKEN_F |
-FW_IQ_CMD_FL0FETCHRO_F |
-FW_IQ_CMD_FL0DATARO_F |
+FW_IQ_CMD_FL0FETCHRO_V(relaxed) |
+FW_IQ_CMD_FL0DATARO_V(relaxed) |
 FW_IQ_CMD_FL0PADEN_F);
if (cong >= 0)
c.iqns_to_fl0congen |=
-- 
1.8.3.1




Re: [PATCH v8 1/4] PCI: Add new PCIe Fabric End Node flag, PCI_DEV_FLAGS_NO_RELAXED_ORDERING

2017-08-05 Thread Ding Tianhong


On 2017/8/5 5:06, Casey Leedom wrote:
> | From: Ding Tianhong 
> | Sent: Thursday, August 3, 2017 6:44 AM
> |
> | diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c
> | index 6967c6b..1e1cdbe 100644
> | --- a/drivers/pci/quirks.c
> | +++ b/drivers/pci/quirks.c
> | @@ -4016,6 +4016,44 @@ static void quirk_tw686x_class(struct pci_dev *pdev)
> |quirk_tw686x_class);
> |
> |  /*
> | + * Some devices have problems with Transaction Layer Packets with the 
> Relaxed
> | + * Ordering Attribute set.  Such devices should mark themselves and other
> | + * Device Drivers should check before sending TLPs with RO set.
> | + */
> | +static void quirk_relaxedordering_disable(struct pci_dev *dev)
> | +{
> | +   dev->dev_flags |= PCI_DEV_FLAGS_NO_RELAXED_ORDERING;
> | +}
> | +
> | +/*
> | + * Intel E5-26xx Root Complex has a Flow Control Credit issue which can
> | + * cause performance problems with Upstream Transaction Layer Packets with
> | + * Relaxed Ordering set.
> | + */
> | +DECLARE_PCI_FIXUP_CLASS_EARLY(PCI_VENDOR_ID_INTEL, 0x6f02, 
> PCI_CLASS_NOT_DEFINED, 8,
> | + quirk_relaxedordering_disable);
> | +DECLARE_PCI_FIXUP_CLASS_EARLY(PCI_VENDOR_ID_INTEL, 0x6f04, 
> PCI_CLASS_NOT_DEFINED, 8,
> | + quirk_relaxedordering_disable);
> | +DECLARE_PCI_FIXUP_CLASS_EARLY(PCI_VENDOR_ID_INTEL, 0x6f08, 
> PCI_CLASS_NOT_DEFINED, 8,
> | + quirk_relaxedordering_disable);
> | + ...
> 
> It looks like this is missing the set of Root Complex IDs that were noted in
> the document to which Patrick Cramer sent us a reference:
> 
> https://software.intel.com/sites/default/files/managed/9e/bc/64-ia-32-architectures-optimization-manual.pdf
> 
> In section 3.9.1 we have:
> 
> 3.9.1 Optimizing PCIe Performance for Accesses Toward Coherent Memory
>   and Toward MMIO Regions (P2P)
> 
> In order to maximize performance for PCIe devices in the processors
> listed in Table 3-6 below, the soft- ware should determine whether the
> accesses are toward coherent memory (system memory) or toward MMIO
> regions (P2P access to other devices). If the access is toward MMIO
> region, then software can command HW to set the RO bit in the TLP
> header, as this would allow hardware to achieve maximum throughput for
> these types of accesses. For accesses toward coherent memory, software
> can command HW to clear the RO bit in the TLP header (no RO), as this
> would allow hardware to achieve maximum throughput for these types of
> accesses.
> 
> Table 3-6. Intel Processor CPU RP Device IDs for Processors Optimizing
>PCIe Performance
> 
> ProcessorCPU RP Device IDs
> 
> Intel Xeon processors based on   6F01H-6F0EH
> Broadwell microarchitecture
> 
> Intel Xeon processors based on   2F01H-2F0EH
> Haswell microarchitecture
> 
> The PCI Device IDs you have there are the first ones that I guessed at
> having the performance problem with Relaxed Ordering.  We now apparently
> have a complete list from Intel.
> 
> I don't want to phrase this as a "NAK" because you've gone around the
> mulberry bush a bunch of times already.  So maybe just go with what you've
> got in version 8 of your patch and then do a follow on patch to complete the
> table?
> 
Casey:

Thanks for the good catch, I found that the Ashok has notice this 3 month 
before, I am so sorry to
miss it, it was really a long discussion for this problem, but don't worry, It 
is not a big work to fix it,
I will send the v9 version. :)

Ding

> Casey
> .
>