[PATCH net v3] virtio_net: fix virtnet_open and virtnet_probe competing for try_fill_recv

2016-05-30 Thread Yunjian Wang
In function virtnet_open() and virtnet_probe(), func try_fill_recv() may
be executed at the same time. VQ in virtqueue_add() has not been protected
well and BUG_ON will be triggered when virito_net.ko being removed.

Signed-off-by: Yunjian Wang 
Acked-by: Jason Wang 
Acked-by: Michael S. Tsirkin 
---
 drivers/net/virtio_net.c | 18 ++
 1 file changed, 2 insertions(+), 16 deletions(-)

diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index 49d84e5..e0638e5 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -1925,24 +1925,11 @@ static int virtnet_probe(struct virtio_device *vdev)
 
virtio_device_ready(vdev);
 
-   /* Last of all, set up some receive buffers. */
-   for (i = 0; i < vi->curr_queue_pairs; i++) {
-   try_fill_recv(vi, >rq[i], GFP_KERNEL);
-
-   /* If we didn't even get one input buffer, we're useless. */
-   if (vi->rq[i].vq->num_free ==
-   virtqueue_get_vring_size(vi->rq[i].vq)) {
-   free_unused_bufs(vi);
-   err = -ENOMEM;
-   goto free_recv_bufs;
-   }
-   }
-
vi->nb.notifier_call = _cpu_callback;
err = register_hotcpu_notifier(>nb);
if (err) {
pr_debug("virtio_net: registering cpu notifier failed\n");
-   goto free_recv_bufs;
+   goto free_unregister_netdev;
}
 
/* Assume link up if device can't report link status,
@@ -1960,10 +1947,9 @@ static int virtnet_probe(struct virtio_device *vdev)
 
return 0;
 
-free_recv_bufs:
+free_unregister_netdev:
vi->vdev->config->reset(vdev);
 
-   free_receive_bufs(vi);
unregister_netdev(dev);
 free_vqs:
cancel_delayed_work_sync(>refill);
-- 
1.7.12.4




Re: [PATCH] vxlan: Accept user specified MTU value when create new vxlan link

2016-05-30 Thread Cong Wang
On Sat, May 28, 2016 at 8:22 AM, oc  wrote:
> 1. vxlan_dev_configure function check conf->mtu to determine if it need to
> change value of dev->mtu.
> The logical looks better to get conf->mtu from IFLA_MTU directly.

Fair enough,

Acked-by: Cong Wang 


Re: [PATCH V2 2/2] vhost_net: conditionally enable tx polling

2016-05-30 Thread Jason Wang



On 2016年05月30日 23:55, Michael S. Tsirkin wrote:

On Mon, May 30, 2016 at 02:47:54AM -0400, Jason Wang wrote:

We always poll tx for socket, this is sub optimal since:

- it will be only used when we exceed the sndbuf of the socket.
- since we use two independent polls for tx and vq, this will slightly
   increase the waitqueue traversing time and more important, vhost
   could not benefit from commit
   9e641bdcfa4ef4d6e2fbaa59c1be0ad5d1551fd5 ("net-tun: restructure
   tun_do_read for better sleep/wakeup efficiency") even if we've
   stopped rx polling during handle_rx since tx poll were still left in
   the waitqueue.

Why is this an issue?
sock_def_write_space only wakes up when queue is half empty,
not on each packet.
 if ((atomic_read(>sk_wmem_alloc) << 1) <= sk->sk_sndbuf)

I suspect the issue is with your previous patch,
it now pokes at the spinlock on data path
where it used not to.

Is that right?


The problem is not tx wake up but still rx wake up. Patch 1 removes rx 
poll, but still left tx poll. So in sock_def_readable(), 
skwq_has_sleeper() returns true, we still need to traverse waitqueue and 
touch spinlocks. With this patch, unless a heavy tx load, tx poll were 
disabled, sock_def_readable() can return finish very soon.






Fix this by conditionally enable tx polling only when -EAGAIN were
met.

Test shows about 8% improvement on guest rx pps.

Before: ~135
After:  ~146

Signed-off-by: Jason Wang 
---
  drivers/vhost/net.c | 3 +++
  1 file changed, 3 insertions(+)

diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c
index e91603b..5a05fa0 100644
--- a/drivers/vhost/net.c
+++ b/drivers/vhost/net.c
@@ -378,6 +378,7 @@ static void handle_tx(struct vhost_net *net)
goto out;
  
  	vhost_disable_notify(>dev, vq);

+   vhost_net_disable_vq(net, vq);
  
  	hdr_size = nvq->vhost_hlen;

zcopy = nvq->ubufs;
@@ -459,6 +460,8 @@ static void handle_tx(struct vhost_net *net)
% UIO_MAXIOV;
}
vhost_discard_vq_desc(vq, 1);
+   if (err == -EAGAIN)
+   vhost_net_enable_vq(net, vq);
break;
}
if (err != len)
--
1.8.3.1




Re: [PATCH V2 1/2] vhost_net: stop polling socket during rx processing

2016-05-30 Thread Jason Wang



On 2016年05月30日 23:47, Michael S. Tsirkin wrote:

On Mon, May 30, 2016 at 02:47:53AM -0400, Jason Wang wrote:

We don't stop rx polling socket during rx processing, this will lead
unnecessary wakeups from under layer net devices (E.g
sock_def_readable() form tun). Rx will be slowed down in this
way. This patch avoids this by stop polling socket during rx
processing. A small drawback is that this introduces some overheads in
light load case because of the extra start/stop polling, but single
netperf TCP_RR does not notice any change. In a super heavy load case,
e.g using pktgen to inject packet to guest, we get about ~8.8%
improvement on pps:

before: ~124 pkt/s
after:  ~135 pkt/s

Signed-off-by: Jason Wang 
---
  drivers/vhost/net.c | 56 +++--
  1 file changed, 29 insertions(+), 27 deletions(-)

diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c
index 10ff494..e91603b 100644
--- a/drivers/vhost/net.c
+++ b/drivers/vhost/net.c
@@ -301,6 +301,32 @@ static bool vhost_can_busy_poll(struct vhost_dev *dev,
   !vhost_has_work(dev);
  }
  
+static void vhost_net_disable_vq(struct vhost_net *n,

+struct vhost_virtqueue *vq)
+{
+   struct vhost_net_virtqueue *nvq =
+   container_of(vq, struct vhost_net_virtqueue, vq);
+   struct vhost_poll *poll = n->poll + (nvq - n->vqs);
+   if (!vq->private_data)
+   return;
+   vhost_poll_stop(poll);
+}
+
+static int vhost_net_enable_vq(struct vhost_net *n,
+   struct vhost_virtqueue *vq)
+{
+   struct vhost_net_virtqueue *nvq =
+   container_of(vq, struct vhost_net_virtqueue, vq);
+   struct vhost_poll *poll = n->poll + (nvq - n->vqs);
+   struct socket *sock;
+
+   sock = vq->private_data;
+   if (!sock)
+   return 0;
+
+   return vhost_poll_start(poll, sock->file);
+}
+
  static int vhost_net_tx_get_vq_desc(struct vhost_net *net,
struct vhost_virtqueue *vq,
struct iovec iov[], unsigned int iov_size,

BTW we might want to rename these functions, name no longer
reflects function ...


Do you mean adding something reflect busy polling in the name? Then the 
name may be too long or have suggestion on the name?






@@ -627,6 +653,7 @@ static void handle_rx(struct vhost_net *net)
if (!sock)
goto out;
vhost_disable_notify(>dev, vq);
+   vhost_net_disable_vq(net, vq);
  
  	vhost_hlen = nvq->vhost_hlen;

sock_hlen = nvq->sock_hlen;
@@ -715,9 +742,10 @@ static void handle_rx(struct vhost_net *net)
total_len += vhost_len;
if (unlikely(total_len >= VHOST_NET_WEIGHT)) {
vhost_poll_queue(>poll);
-   break;
+   goto out;
}
}
+   vhost_net_enable_vq(net, vq);

OK so if sock is readable but RX VQ is empty, this will
immediately schedule another round of handle_rx and so ad
infinitum,

Looks like a bug.


Yes it is, will change the above headcount check to:

/* OK, now we need to know about added descriptors. */
if (!headcount) {
if (unlikely(vhost_enable_notify(>dev, vq))) {
/* They have slipped one in as we were
 * doing that: check again. */
vhost_disable_notify(>dev, vq);
continue;
}
/* Nothing new?  Wait for eventfd to tell us
 * they refilled. */
goto out;
}






  out:
mutex_unlock(>mutex);
  }
@@ -796,32 +824,6 @@ static int vhost_net_open(struct inode *inode, struct file 
*f)
return 0;
  }
  
-static void vhost_net_disable_vq(struct vhost_net *n,

-struct vhost_virtqueue *vq)
-{
-   struct vhost_net_virtqueue *nvq =
-   container_of(vq, struct vhost_net_virtqueue, vq);
-   struct vhost_poll *poll = n->poll + (nvq - n->vqs);
-   if (!vq->private_data)
-   return;
-   vhost_poll_stop(poll);
-}
-
-static int vhost_net_enable_vq(struct vhost_net *n,
-   struct vhost_virtqueue *vq)
-{
-   struct vhost_net_virtqueue *nvq =
-   container_of(vq, struct vhost_net_virtqueue, vq);
-   struct vhost_poll *poll = n->poll + (nvq - n->vqs);
-   struct socket *sock;
-
-   sock = vq->private_data;
-   if (!sock)
-   return 0;
-
-   return vhost_poll_start(poll, sock->file);
-}
-
  static struct socket *vhost_net_stop_vq(struct vhost_net *n,
struct vhost_virtqueue *vq)
  {
--
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to 

Re: [PATCH v5 0/2] skb_array: array based FIFO for skbs

2016-05-30 Thread Jason Wang



On 2016年05月30日 23:37, Michael S. Tsirkin wrote:

On Mon, May 30, 2016 at 05:59:33PM +0800, Jason Wang wrote:


On 2016年05月23日 18:43, Michael S. Tsirkin wrote:

This is in response to the proposal by Jason to make tun
rx packet queue lockless using a circular buffer.
My testing seems to show that at least for the common usecase
in networking, which isn't lockless, circular buffer
with indices does not perform that well, because
each index access causes a cache line to bounce between
CPUs, and index access causes stalls due to the dependency.

I change tun to use skb array, looks like it can give about 5% more faster
than skb ring.

OK and skb ring is 9% faster than the linked list, so together
this is a 14% speedup?


Right.




And we usually don't need touch bhs during consume and produce (e.g for the
case of tun).

Thanks

Maybe I'll drop it in v6 then ...
Could you post the full tun patchset please?



Since it needs no bh versions of produce/consume, maybe you can post v6 
first, then I can post the tun patches?


Re: [PATCH v2] fib_rules: Added NLM_F_EXCL support to fib_nl_newrule

2016-05-30 Thread David Ahern

On 5/30/16 3:17 AM, Mateusz Bajorski wrote:

When adding rule with NLM_F_EXCL flag then check if the same rule exist.
If yes then exit with -EEXIST.

This is already implemented in iproute2:
if (cmd == RTM_NEWRULE) {
req.n.nlmsg_flags |= NLM_F_CREATE|NLM_F_EXCL;
req.r.rtm_type = RTN_UNICAST;
}

Tested ipv4 and ipv6 with net-next linux on qemu x86

expected behavior after patch:
localhost ~ # ip rule
0:from all lookup local
32766:from all lookup main
32767:from all lookup default
localhost ~ # ip rule add from 10.46.177.97 lookup 104 pref 1005
localhost ~ # ip rule add from 10.46.177.97 lookup 104 pref 1005
RTNETLINK answers: File exists
localhost ~ # ip rule
0:from all lookup local
1005:from 10.46.177.97 lookup 104
32766:from all lookup main
32767:from all lookup default

There was already topic regarding this but I don't see any changes
merged and problem still occurs.
https://lkml.kernel.org/r/1135778809.5944.7.camel+%28%29+localhost+%21+localdomain

Signed-off-by: Mateusz Bajorski 
---
Changes in v2: section moved to new place where new rule is already built

 net/core/fib_rules.c | 34 ++
 1 file changed, 34 insertions(+)

diff --git a/net/core/fib_rules.c b/net/core/fib_rules.c
index 840aceb..5bc1d27 100644
--- a/net/core/fib_rules.c
+++ b/net/core/fib_rules.c
@@ -371,6 +371,40 @@ static int fib_nl_newrule(struct sk_buff *skb, struct 
nlmsghdr* nlh)
} else if (rule->action == FR_ACT_GOTO)
goto errout_free;

+   if (nlh->nlmsg_flags & NLM_F_EXCL) {
+   list_for_each_entry(r, >rules_list, list) {


missing a namespace (fr_net) compare. Everything else is relative to it.

I suggest making the rule compare a helper function.

Also, this is going to be one of those pain points as new rule 
attributes are added - new attributes are not added to the compare. 
Perhaps a note above the fib_rule definition in net/fib_rules.h to add 
new attributes to the fib_rule compare function?




+   if (r->action != rule->action)
+   continue;
+
+   if (r->table != rule->table)
+   continue;
+
+   if (r->pref != rule->pref)
+   continue;
+
+   if (memcmp(r->iifname, rule->iifname, IFNAMSIZ))
+   continue;
+
+   if (memcmp(r->oifname, rule->oifname, IFNAMSIZ))
+   continue;
+
+   if (r->mark != rule->mark)
+   continue;
+
+   if (r->mark_mask != rule->mark_mask)
+   continue;
+
+   if (r->tun_id != rule->tun_id)
+   continue;
+
+   if (!ops->compare(r, frh, tb))
+   continue;
+
+   err = -EEXIST;
+   goto errout_free;
+   }
+   }
+
err = ops->configure(rule, skb, frh, tb);
if (err < 0)
goto errout_free;





[PATCH iproute2 net-next v2 3/5] bridge: add json support for bridge fdb show

2016-05-30 Thread Roopa Prabhu
From: Anuradha Karuppiah 

Sample output:
$bridge -j fdb show
[{
"mac": "44:38:39:00:69:88",
"dev": "swp2s0",
"vlan": 2,
"master": "br0",
"state": "permanent"
},{
"mac": "00:02:00:00:00:01",
"dev": "swp2s0",
"vlan": 2,
"master": "br0"
},{
"mac": "00:02:00:00:00:02",
"dev": "swp2s1",
"vlan": 2,
"master": "br0"
},{
"mac": "44:38:39:00:69:89",
"dev": "swp2s1",
"master": "br0",
"state": "permanent"
},{
"mac": "44:38:39:00:69:89",
"dev": "swp2s1",
"vlan": 2,
"master": "br0",
"state": "permanent"
},{
"mac": "44:38:39:00:69:88",
"dev": "br0",
"master": "br0",
"state": "permanent"
}
]

Signed-off-by: Anuradha Karuppiah 
Signed-off-by: Roopa Prabhu 
---
 bridge/fdb.c | 207 ++-
 1 file changed, 164 insertions(+), 43 deletions(-)

diff --git a/bridge/fdb.c b/bridge/fdb.c
index be849f9..c2bfeb2 100644
--- a/bridge/fdb.c
+++ b/bridge/fdb.c
@@ -21,6 +21,8 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 
 #include "libnetlink.h"
 #include "br_common.h"
@@ -29,6 +31,8 @@
 
 static unsigned int filter_index, filter_vlan;
 
+json_writer_t *jw_global;
+
 static void usage(void)
 {
fprintf(stderr, "Usage: bridge fdb { add | append | del | replace } 
ADDR dev DEV\n"
@@ -59,6 +63,15 @@ static const char *state_n2a(unsigned int s)
return buf;
 }
 
+static void start_json_fdb_flags_array(bool *fdb_flags)
+{
+   if (*fdb_flags)
+   return;
+   jsonw_name(jw_global, "flags");
+   jsonw_start_array(jw_global);
+   *fdb_flags = true;
+}
+
 int print_fdb(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
 {
FILE *fp = arg;
@@ -66,11 +79,12 @@ int print_fdb(const struct sockaddr_nl *who, struct 
nlmsghdr *n, void *arg)
int len = n->nlmsg_len;
struct rtattr *tb[NDA_MAX+1];
__u16 vid = 0;
+   bool fdb_flags = false;
+   const char *state_s;
 
if (n->nlmsg_type != RTM_NEWNEIGH && n->nlmsg_type != RTM_DELNEIGH) {
fprintf(stderr, "Not RTM_NEWNEIGH: %08x %08x %08x\n",
n->nlmsg_len, n->nlmsg_type, n->nlmsg_flags);
-
return 0;
}
 
@@ -86,6 +100,11 @@ int print_fdb(const struct sockaddr_nl *who, struct 
nlmsghdr *n, void *arg)
if (filter_index && filter_index != r->ndm_ifindex)
return 0;
 
+   if (jw_global) {
+   jsonw_pretty(jw_global, 1);
+   jsonw_start_object(jw_global);
+   }
+
parse_rtattr(tb, NDA_MAX, NDA_RTA(r),
 n->nlmsg_len - NLMSG_LENGTH(sizeof(*r)));
 
@@ -95,40 +114,75 @@ int print_fdb(const struct sockaddr_nl *who, struct 
nlmsghdr *n, void *arg)
if (filter_vlan && filter_vlan != vid)
return 0;
 
-   if (n->nlmsg_type == RTM_DELNEIGH)
-   fprintf(fp, "Deleted ");
+   if (n->nlmsg_type == RTM_DELNEIGH) {
+   if (jw_global)
+   jsonw_string_field(jw_global, "opCode", "deleted");
+   else
+   fprintf(fp, "Deleted ");
+   }
 
if (tb[NDA_LLADDR]) {
SPRINT_BUF(b1);
-   fprintf(fp, "%s ",
-   ll_addr_n2a(RTA_DATA(tb[NDA_LLADDR]),
-   RTA_PAYLOAD(tb[NDA_LLADDR]),
-   ll_index_to_type(r->ndm_ifindex),
-   b1, sizeof(b1)));
+   ll_addr_n2a(RTA_DATA(tb[NDA_LLADDR]),
+   RTA_PAYLOAD(tb[NDA_LLADDR]),
+   ll_index_to_type(r->ndm_ifindex),
+   b1, sizeof(b1));
+   if (jw_global)
+   jsonw_string_field(jw_global, "mac", b1);
+   else
+   fprintf(fp, "%s ", b1);
}
 
-   if (!filter_index && r->ndm_ifindex)
-   fprintf(fp, "dev %s ", ll_index_to_name(r->ndm_ifindex));
+   if (!filter_index && r->ndm_ifindex) {
+   if (jw_global)
+   jsonw_string_field(jw_global, "dev",
+  ll_index_to_name(r->ndm_ifindex));
+   else
+   fprintf(fp, "dev %s ",
+   ll_index_to_name(r->ndm_ifindex));
+   }
 
if (tb[NDA_DST]) {
int family = AF_INET;
+   const char *abuf_s;
 
if (RTA_PAYLOAD(tb[NDA_DST]) == sizeof(struct in6_addr))
family = AF_INET6;
 
-   fprintf(fp, "dst %s ",
-   format_host(family,
-   RTA_PAYLOAD(tb[NDA_DST]),
-

[PATCH iproute2 net-next v2 1/5] json_writer: allow base json data type to be array or object

2016-05-30 Thread Roopa Prabhu
From: Anuradha Karuppiah 

This patch adds a type qualifier to json_writer. Type can be a
json object or array. This can be extended to other types like
json-string, json-number etc in the future.

Signed-off-by: Anuradha Karuppiah 
---
 include/json_writer.h |  5 +++--
 lib/json_writer.c | 39 +++
 misc/ifstat.c |  6 +++---
 misc/lnstat.c |  2 +-
 misc/nstat.c  |  4 ++--
 5 files changed, 44 insertions(+), 12 deletions(-)

diff --git a/include/json_writer.h b/include/json_writer.h
index ab9a008..e04a40a 100644
--- a/include/json_writer.h
+++ b/include/json_writer.h
@@ -21,8 +21,9 @@
 /* Opaque class structure */
 typedef struct json_writer json_writer_t;
 
-/* Create a new JSON stream */
-json_writer_t *jsonw_new(FILE *f);
+/* Create a new JSON stream with data type */
+json_writer_t *jsonw_new_object(FILE *f);
+json_writer_t *jsonw_new_array(FILE *f);
 /* End output to JSON stream */
 void jsonw_destroy(json_writer_t **self_p);
 
diff --git a/lib/json_writer.c b/lib/json_writer.c
index 2af16e1..420cd87 100644
--- a/lib/json_writer.c
+++ b/lib/json_writer.c
@@ -22,11 +22,17 @@
 
 #include "json_writer.h"
 
+enum jsonw_data_type {
+   JSONW_TYPE_OBJECT,
+   JSONW_TYPE_ARRAY
+};
+
 struct json_writer {
FILE*out;   /* output file */
unsigneddepth;  /* nesting */
boolpretty; /* optional whitepace */
charsep;/* either nul or comma */
+   int type;   /* currently either object or array */
 };
 
 /* indentation for pretty print */
@@ -94,7 +100,7 @@ static void jsonw_puts(json_writer_t *self, const char *str)
 }
 
 /* Create a new JSON stream */
-json_writer_t *jsonw_new(FILE *f)
+static json_writer_t *jsonw_new(FILE *f, int type)
 {
json_writer_t *self = malloc(sizeof(*self));
if (self) {
@@ -102,11 +108,29 @@ json_writer_t *jsonw_new(FILE *f)
self->depth = 0;
self->pretty = false;
self->sep = '\0';
-   putc('{', self->out);
+   self->type = type;
+   switch (self->type) {
+   case JSONW_TYPE_OBJECT:
+   putc('{', self->out);
+   break;
+   case JSONW_TYPE_ARRAY:
+   putc('[', self->out);
+   break;
+   }
}
return self;
 }
 
+json_writer_t *jsonw_new_object(FILE *f)
+{
+   return jsonw_new(f, JSONW_TYPE_OBJECT);
+}
+
+json_writer_t *jsonw_new_array(FILE *f)
+{
+   return jsonw_new(f, JSONW_TYPE_ARRAY);
+}
+
 /* End output to JSON stream */
 void jsonw_destroy(json_writer_t **self_p)
 {
@@ -114,7 +138,14 @@ void jsonw_destroy(json_writer_t **self_p)
 
assert(self->depth == 0);
jsonw_eol(self);
-   fputs("}\n", self->out);
+   switch (self->type) {
+   case JSONW_TYPE_OBJECT:
+   fputs("}\n", self->out);
+   break;
+   case JSONW_TYPE_ARRAY:
+   fputs("]\n", self->out);
+   break;
+   }
fflush(self->out);
free(self);
*self_p = NULL;
@@ -267,7 +298,7 @@ void jsonw_null_field(json_writer_t *self, const char *prop)
 #ifdef TEST
 int main(int argc, char **argv)
 {
-   json_writer_t *wr = jsonw_new(stdout);
+   json_writer_t *wr = jsonw_new_object(stdout);
 
jsonw_pretty(wr, true);
jsonw_name(wr, "Vyatta");
diff --git a/misc/ifstat.c b/misc/ifstat.c
index abbb4e7..29aa63c 100644
--- a/misc/ifstat.c
+++ b/misc/ifstat.c
@@ -240,7 +240,7 @@ static void load_raw_table(FILE *fp)
 
 static void dump_raw_db(FILE *fp, int to_hist)
 {
-   json_writer_t *jw = json_output ? jsonw_new(fp) : NULL;
+   json_writer_t *jw = json_output ? jsonw_new_object(fp) : NULL;
struct ifstat_ent *n, *h;
 
h = hist_db;
@@ -447,7 +447,7 @@ static void print_one_if(FILE *fp, const struct ifstat_ent 
*n,
 
 static void dump_kern_db(FILE *fp)
 {
-   json_writer_t *jw = json_output ? jsonw_new(fp) : NULL;
+   json_writer_t *jw = json_output ? jsonw_new_object(fp) : NULL;
struct ifstat_ent *n;
 
if (jw) {
@@ -473,7 +473,7 @@ static void dump_kern_db(FILE *fp)
 static void dump_incr_db(FILE *fp)
 {
struct ifstat_ent *n, *h;
-   json_writer_t *jw = json_output ? jsonw_new(fp) : NULL;
+   json_writer_t *jw = json_output ? jsonw_new_object(fp) : NULL;
 
h = hist_db;
if (jw) {
diff --git a/misc/lnstat.c b/misc/lnstat.c
index 659a01b..2988e9e 100644
--- a/misc/lnstat.c
+++ b/misc/lnstat.c
@@ -110,7 +110,7 @@ static void print_line(FILE *of, const struct lnstat_file 
*lnstat_files,
 static void print_json(FILE *of, const struct lnstat_file *lnstat_files,
   const struct field_params *fp)
 {
-   json_writer_t *jw = jsonw_new(of);
+   json_writer_t *jw = 

[PATCH iproute2 net-next v2 4/5] bridge: add json schema for bridge fdb show

2016-05-30 Thread Roopa Prabhu
From: Anuradha Karuppiah 

we think storing the schema file for the json
format will be useful.

Signed-off-by: Anuradha Karuppiah 
---
 schema/bridge_fdb_schema.json | 62 +++
 1 file changed, 62 insertions(+)
 create mode 100644 schema/bridge_fdb_schema.json

diff --git a/schema/bridge_fdb_schema.json b/schema/bridge_fdb_schema.json
new file mode 100644
index 000..3e5be8d
--- /dev/null
+++ b/schema/bridge_fdb_schema.json
@@ -0,0 +1,62 @@
+{
+"$schema": "http://json-schema.org/draft-04/schema#;,
+"description": "bridge fdb show",
+"type": "array",
+"items": {
+"type": "object",
+"properties": {
+"dev": {
+"type": "string"
+},
+"dst": {
+"description" : "host name or ip address",
+"type": "string"
+},
+"flags": {
+"type": "array",
+"items": {
+"enum": ["self", "master", "router", "offload"]
+},
+"uniqueItems": true
+},
+"linkNetNsId": {
+"type": "integer"
+},
+"mac": {
+"type": "string"
+},
+"master": {
+"type": "string"
+},
+"opCode": {
+"description" : "used to indicate fdb entry del",
+"enum": ["deleted"]
+},
+"port": {
+"type": "integer"
+},
+"state": {
+"description" : "permanent, static, stale, state=#x",
+"type": "string"
+},
+"updated": {
+"type": "integer"
+},
+"used": {
+"type": "integer"
+},
+"viaIf": {
+"type": "string"
+},
+"viaIfIndex": {
+"type": "integer"
+},
+"vlan": {
+"type": "integer"
+},
+"vni": {
+"type": "integer"
+}
+}
+}
+}
-- 
1.9.1



[PATCH iproute2 net-next v2 0/5] bridge: json support for fdb and vlan show

2016-05-30 Thread Roopa Prabhu
From: Roopa Prabhu 

This patch series adds json support for a few bridge show commands.
We plan to follow up with json support for additional commands soon.

Anuradha Karuppiah (3):
  json_writer: allow base json data type to be array or object
  bridge: add json support for bridge fdb show
  bridge: add json schema for bridge fdb show

Roopa Prabhu (2):
  bridge: add json support for bridge vlan show
  bridge: update man page

v2 - change vlan flags to an array as suggested by toshiaki

 bridge/br_common.h|   1 +
 bridge/bridge.c   |   3 +
 bridge/fdb.c  | 201 +-
 bridge/vlan.c |  93 ++-
 include/json_writer.h |   5 +-
 lib/json_writer.c |  39 +++-
 man/man8/bridge.8 |   9 +-
 misc/ifstat.c |   6 +-
 misc/lnstat.c |   2 +-
 misc/nstat.c  |   4 +-
 schema/bridge_fdb_schema.json |  62 +
 11 files changed, 365 insertions(+), 60 deletions(-)
 create mode 100644 schema/bridge_fdb_schema.json

-- 
1.9.1



[PATCH iproute2 net-next v2 2/5] bridge: add json support for bridge vlan show

2016-05-30 Thread Roopa Prabhu
From: Roopa Prabhu 

$bridge -c vlan show
portvlan ids
swp1 1 PVID Egress Untagged
 10-13

swp2 1 PVID Egress Untagged
 10-13

br0  1 PVID Egress Untagged

$bridge  -json vlan show
{
"swp1": [{
"vlan": 1,
"flags": ["PVID","Egress Untagged"
]
},{
"vlan": 10
},{
"vlan": 11
},{
"vlan": 12
},{
"vlan": 13
}
],
"swp2": [{
"vlan": 1,
"flags": ["PVID","Egress Untagged"
]
},{
"vlan": 10
},{
"vlan": 11
},{
"vlan": 12
},{
"vlan": 13
}
],
"br0": [{
"vlan": 1,
"flags": ["PVID","Egress Untagged"
]
}
]
}

$bridge -c -json vlan show
{
"swp1": [{
"vlan": 1,
"flags": ["PVID","Egress Untagged"
]
},{
"vlan": 10,
"vlanEnd": 13
}
],
"swp2": [{
"vlan": 1,
"flags": ["PVID","Egress Untagged"
]
},{
"vlan": 10,
"vlanEnd": 13
}
],
"br0": [{
"vlan": 1,
"flags": ["PVID","Egress Untagged"
]
}
]
}

Signed-off-by: Roopa Prabhu 
---
 bridge/br_common.h |   1 +
 bridge/bridge.c|   5 ++-
 bridge/vlan.c  | 106 ++---
 3 files changed, 97 insertions(+), 15 deletions(-)

diff --git a/bridge/br_common.h b/bridge/br_common.h
index 5ea45c9..c649e7d 100644
--- a/bridge/br_common.h
+++ b/bridge/br_common.h
@@ -23,4 +23,5 @@ extern int show_stats;
 extern int show_details;
 extern int timestamp;
 extern int compress_vlans;
+extern int json_output;
 extern struct rtnl_handle rth;
diff --git a/bridge/bridge.c b/bridge/bridge.c
index 72f153f..5ff038d 100644
--- a/bridge/bridge.c
+++ b/bridge/bridge.c
@@ -23,6 +23,7 @@ int oneline;
 int show_stats;
 int show_details;
 int compress_vlans;
+int json_output;
 int timestamp;
 char *batch_file;
 int force;
@@ -38,7 +39,7 @@ static void usage(void)
 "where OBJECT := { link | fdb | mdb | vlan | monitor }\n"
 "  OPTIONS := { -V[ersion] | -s[tatistics] | -d[etails] |\n"
 "   -o[neline] | -t[imestamp] | -n[etns] name |\n"
-"   -c[ompressvlans] }\n");
+"   -c[ompressvlans] -j{son} }\n");
exit(-1);
 }
 
@@ -173,6 +174,8 @@ main(int argc, char **argv)
++compress_vlans;
} else if (matches(opt, "-force") == 0) {
++force;
+   } else if (matches(opt, "-json") == 0) {
+   ++json_output;
} else if (matches(opt, "-batch") == 0) {
argc--;
argv++;
diff --git a/bridge/vlan.c b/bridge/vlan.c
index 717025a..fbf14c8 100644
--- a/bridge/vlan.c
+++ b/bridge/vlan.c
@@ -7,6 +7,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #include "libnetlink.h"
@@ -15,6 +16,8 @@
 
 static unsigned int filter_index, filter_vlan;
 
+json_writer_t *jw_global = NULL;
+
 static void usage(void)
 {
fprintf(stderr, "Usage: bridge vlan { add | del } vid VLAN_ID dev DEV [ 
pvid] [ untagged ]\n");
@@ -158,6 +161,28 @@ static int filter_vlan_check(struct bridge_vlan_info 
*vinfo)
return 1;
 }
 
+static void print_vlan_port(FILE *fp, int ifi_index)
+{
+   if (jw_global) {
+   jsonw_pretty(jw_global, 1);
+   jsonw_name(jw_global,
+  ll_index_to_name(ifi_index));
+   jsonw_start_array(jw_global);
+   } else {
+   fprintf(fp, "%s",
+   ll_index_to_name(ifi_index));
+   }
+}
+
+static void start_json_vlan_flags_array(bool *vlan_flags)
+{
+   if (*vlan_flags)
+   return;
+   jsonw_name(jw_global, "flags");
+   jsonw_start_array(jw_global);
+   *vlan_flags = true;
+}
+
 static int print_vlan(const struct sockaddr_nl *who,
  struct nlmsghdr *n,
  void *arg)
@@ -166,6 +191,8 @@ static int print_vlan(const struct sockaddr_nl *who,
struct ifinfomsg *ifm = NLMSG_DATA(n);
int len = n->nlmsg_len;
struct rtattr *tb[IFLA_MAX+1];
+   bool vlan_flags;
+   char flags[80];
 
if (n->nlmsg_type != RTM_NEWLINK) {
fprintf(stderr, "Not RTM_NEWLINK: %08x %08x %08x\n",
@@ -199,7 +226,8 @@ static int print_vlan(const struct sockaddr_nl *who,
__u16 last_vid_start = 0;
 
if (!filter_vlan)
-   fprintf(fp, "%s", ll_index_to_name(ifm->ifi_index));
+   print_vlan_port(fp, ifm->ifi_index);
+
for (i = RTA_DATA(list); RTA_OK(i, rem); i = RTA_NEXT(i, rem)) {
 

[PATCH iproute2 net-next v2 5/5] bridge: update man page

2016-05-30 Thread Roopa Prabhu
From: Roopa Prabhu 

Signed-off-by: Roopa Prabhu 
---
 man/man8/bridge.8 | 9 +++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/man/man8/bridge.8 b/man/man8/bridge.8
index 08e8a5b..abaee63 100644
--- a/man/man8/bridge.8
+++ b/man/man8/bridge.8
@@ -20,8 +20,9 @@ bridge \- show / manipulate bridge addresses and devices
 .IR OPTIONS " := { "
 \fB\-V\fR[\fIersion\fR] |
 \fB\-s\fR[\fItatistics\fR] |
-\fB\-n\fR[\fIetns\fR] name }
-\fB\-b\fR[\fIatch\fR] filename }
+\fB\-n\fR[\fIetns\fR] name |
+\fB\-b\fR[\fIatch\fR] filename |
+\fB\-j\fR[\fIson\fR] }
 
 .ti -8
 .BR "bridge link set"
@@ -153,6 +154,10 @@ Don't terminate bridge command on errors in batch mode.
 If there were any errors during execution of the commands, the application
 return code will be non zero.
 
+.TP
+.BR "\-json"
+Display results in JSON format. Currently available for vlan and fdb.
+
 .SH BRIDGE - COMMAND SYNTAX
 
 .SS
-- 
1.9.1



Re: [PATCH iproute2 net-next 2/5] bridge: add json support for bridge vlan show

2016-05-30 Thread Roopa Prabhu
On 5/29/16, 5:43 PM, Toshiaki Makita wrote:
> On 2016/05/28 13:37, Roopa Prabhu wrote:
>> From: Roopa Prabhu 
>>
>> $bridge -c vlan show
>> port vlan ids
>> swp1  1 PVID Egress Untagged
>>   10-13
>>
>> swp2  1 PVID Egress Untagged
>>   10-13
>>
>> br0   1 PVID Egress Untagged
>>
>> $bridge -j vlan show
>> {
>> "swp1": [{
>> "vlan": 1,
>> "flags": "PVID Egress Untagged"
> Shouldn't we split flags?

yes, of-course. v2 coming...


Re: [PATCH 0/2] macvlan: Avoid unnecessary multicast cloning

2016-05-30 Thread Herbert Xu
On Mon, May 30, 2016 at 07:27:59PM +0300, Lennert Buytenhek wrote:
>
> That and stack switches to kworker threads and serialisation on
> the bc_queue queue lock.

My patch should resolve these problems too since the packet is
discarded if nobody is interested in it.

Cheers,
-- 
Email: Herbert Xu 
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt


[PATCH 4.4 18/86] asix: Fix offset calculation in asix_rx_fixup() causing slow transmissions

2016-05-30 Thread Greg Kroah-Hartman
4.4-stable review patch.  If anyone has any objections, please let me know.

--

From: John Stultz 

commit cd9e2e5d3ff148be9ea210f622ce3e8e8292fcd6 upstream.

In testing with HiKey, we found that since
commit 3f30b158eba5 ("asix: On RX avoid creating bad Ethernet
frames"),
we're seeing lots of noise during network transfers:

[  239.027993] asix 1-1.1:1.0 eth0: asix_rx_fixup() Data Header synchronisation 
was lost, remaining 988
[  239.037310] asix 1-1.1:1.0 eth0: asix_rx_fixup() Bad Header Length 
0x54ebb5ec, offset 4
[  239.045519] asix 1-1.1:1.0 eth0: asix_rx_fixup() Bad Header Length 
0xcdffe7a2, offset 4
[  239.275044] asix 1-1.1:1.0 eth0: asix_rx_fixup() Data Header synchronisation 
was lost, remaining 988
[  239.284355] asix 1-1.1:1.0 eth0: asix_rx_fixup() Bad Header Length 
0x1d36f59d, offset 4
[  239.292541] asix 1-1.1:1.0 eth0: asix_rx_fixup() Bad Header Length 
0xaef3c1e9, offset 4
[  239.518996] asix 1-1.1:1.0 eth0: asix_rx_fixup() Data Header synchronisation 
was lost, remaining 988
[  239.528300] asix 1-1.1:1.0 eth0: asix_rx_fixup() Bad Header Length 
0x2881912, offset 4
[  239.536413] asix 1-1.1:1.0 eth0: asix_rx_fixup() Bad Header Length 
0x5638f7e2, offset 4

And network throughput ends up being pretty bursty and slow with
a overall throughput of at best ~30kB/s (where as previously we
got 1.1MB/s with the slower USB1.1 "full speed" host).

We found the issue also was reproducible on a x86_64 system,
using a "high-speed" USB2.0 port but the throughput did not
measurably drop (possibly due to the scp transfer being cpu
bound on my slow test hardware).

After lots of debugging, I found the check added in the
problematic commit seems to be calculating the offset
incorrectly.

In the normal case, in the main loop of the function, we do:
(where offset is zero, or set to "offset += (copy_length + 1) &
0xfffe" in the previous loop)
rx->header = get_unaligned_le32(skb->data +
offset);
offset += sizeof(u32);

But the problematic patch calculates:
offset = ((rx->remaining + 1) & 0xfffe) + sizeof(u32);
rx->header = get_unaligned_le32(skb->data + offset);

Adding some debug logic to check those offset calculation used
to find rx->header, the one in problematic code is always too
large by sizeof(u32).

Thus, this patch removes the incorrect " + sizeof(u32)" addition
in the problematic calculation, and resolves the issue.

Cc: Dean Jenkins 
Cc: "David B. Robins" 
Cc: Mark Craske 
Cc: Emil Goode 
Cc: "David S. Miller" 
Cc: YongQin Liu 
Cc: Guodong Xu 
Cc: Ivan Vecera 
Cc: linux-...@vger.kernel.org
Cc: netdev@vger.kernel.org
Reported-by: Yongqin Liu 
Signed-off-by: John Stultz 
Signed-off-by: David S. Miller 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/net/usb/asix_common.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- a/drivers/net/usb/asix_common.c
+++ b/drivers/net/usb/asix_common.c
@@ -66,7 +66,7 @@ int asix_rx_fixup_internal(struct usbnet
 * buffer.
 */
if (rx->remaining && (rx->remaining + sizeof(u32) <= skb->len)) {
-   offset = ((rx->remaining + 1) & 0xfffe) + sizeof(u32);
+   offset = ((rx->remaining + 1) & 0xfffe);
rx->header = get_unaligned_le32(skb->data + offset);
offset = 0;
 




[PATCH 4.5 15/87] asix: Fix offset calculation in asix_rx_fixup() causing slow transmissions

2016-05-30 Thread Greg Kroah-Hartman
4.5-stable review patch.  If anyone has any objections, please let me know.

--

From: John Stultz 

commit cd9e2e5d3ff148be9ea210f622ce3e8e8292fcd6 upstream.

In testing with HiKey, we found that since
commit 3f30b158eba5 ("asix: On RX avoid creating bad Ethernet
frames"),
we're seeing lots of noise during network transfers:

[  239.027993] asix 1-1.1:1.0 eth0: asix_rx_fixup() Data Header synchronisation 
was lost, remaining 988
[  239.037310] asix 1-1.1:1.0 eth0: asix_rx_fixup() Bad Header Length 
0x54ebb5ec, offset 4
[  239.045519] asix 1-1.1:1.0 eth0: asix_rx_fixup() Bad Header Length 
0xcdffe7a2, offset 4
[  239.275044] asix 1-1.1:1.0 eth0: asix_rx_fixup() Data Header synchronisation 
was lost, remaining 988
[  239.284355] asix 1-1.1:1.0 eth0: asix_rx_fixup() Bad Header Length 
0x1d36f59d, offset 4
[  239.292541] asix 1-1.1:1.0 eth0: asix_rx_fixup() Bad Header Length 
0xaef3c1e9, offset 4
[  239.518996] asix 1-1.1:1.0 eth0: asix_rx_fixup() Data Header synchronisation 
was lost, remaining 988
[  239.528300] asix 1-1.1:1.0 eth0: asix_rx_fixup() Bad Header Length 
0x2881912, offset 4
[  239.536413] asix 1-1.1:1.0 eth0: asix_rx_fixup() Bad Header Length 
0x5638f7e2, offset 4

And network throughput ends up being pretty bursty and slow with
a overall throughput of at best ~30kB/s (where as previously we
got 1.1MB/s with the slower USB1.1 "full speed" host).

We found the issue also was reproducible on a x86_64 system,
using a "high-speed" USB2.0 port but the throughput did not
measurably drop (possibly due to the scp transfer being cpu
bound on my slow test hardware).

After lots of debugging, I found the check added in the
problematic commit seems to be calculating the offset
incorrectly.

In the normal case, in the main loop of the function, we do:
(where offset is zero, or set to "offset += (copy_length + 1) &
0xfffe" in the previous loop)
rx->header = get_unaligned_le32(skb->data +
offset);
offset += sizeof(u32);

But the problematic patch calculates:
offset = ((rx->remaining + 1) & 0xfffe) + sizeof(u32);
rx->header = get_unaligned_le32(skb->data + offset);

Adding some debug logic to check those offset calculation used
to find rx->header, the one in problematic code is always too
large by sizeof(u32).

Thus, this patch removes the incorrect " + sizeof(u32)" addition
in the problematic calculation, and resolves the issue.

Cc: Dean Jenkins 
Cc: "David B. Robins" 
Cc: Mark Craske 
Cc: Emil Goode 
Cc: "David S. Miller" 
Cc: YongQin Liu 
Cc: Guodong Xu 
Cc: Ivan Vecera 
Cc: linux-...@vger.kernel.org
Cc: netdev@vger.kernel.org
Reported-by: Yongqin Liu 
Signed-off-by: John Stultz 
Signed-off-by: David S. Miller 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/net/usb/asix_common.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- a/drivers/net/usb/asix_common.c
+++ b/drivers/net/usb/asix_common.c
@@ -66,7 +66,7 @@ int asix_rx_fixup_internal(struct usbnet
 * buffer.
 */
if (rx->remaining && (rx->remaining + sizeof(u32) <= skb->len)) {
-   offset = ((rx->remaining + 1) & 0xfffe) + sizeof(u32);
+   offset = ((rx->remaining + 1) & 0xfffe);
rx->header = get_unaligned_le32(skb->data + offset);
offset = 0;
 




Re: [PATCH v2] ethernet:arc: Fix racing of TX ring buffer

2016-05-30 Thread Lino Sanfilippo
Hi Shuyu,

On 28.05.2016 08:43, Shuyu Wei wrote:
> 
> After some stress testing, it worked well most of the time.
> But there is a chance that it may get stuck when I use 2 nc process
> to send TCP packects at full speed.  Only when a new rx packet 
> arrive can trigger it to run again. This happens only once per several
> hours. No problem in UDP mode.  I'm not sure if it's related to tx code in
> the driver.
> 

This sounds strange. One reason I could imagine for such an issue is that 
occassionally tx completion interrupts get lost: 
In this case skbs may not be freed (or be freed too late) which may result in a 
TCP
stream getting stuck, because each skb belongs to a socket and there is a limit 
for
the allowed number of skbs per socket. TCP would only proceed if the number of 
pending 
skbs falls under this limit again but since the tx completion irq is lost, the 
only thing 
that could trigger the tx completion handler is another irq, e.g for a received 
packet.
At least this could explain what you observed.

Did you see the same issues with the patch before (the one that, as you wrote,
survived a whole night of stress testing)?

Lino


Re: [PATCH net-next] ravb: Add ESF in RCR for enabling separation filter

2016-05-30 Thread Sergei Shtylyov

On 05/30/2016 05:30 PM, Sergei Shtylyov wrote:


From: Masaru Nagai 

This patch adds enabling separation filter(ESF) is setting value of B'11.
This setting filter for separating AVB stream frames from non-AVB stream
frames is enabled. Non-matching frames from a stream are processed in
queue 0(best effort). H/W manual recommends B'11 or B'10.
When B'10 is setting, Non-mating frames are discarded.


   It was somewhat hard for me to parse that...


   Forgot about s/Non-mating/Non-matching/.


Signed-off-by: Masaru Nagai 
Signed-off-by: Kazuya Mizuguchi 
Signed-off-by: Yoshihiro Kaneko 


Acked-by: Sergei Shtylyov 


MBR, Sergei



[PATCH 4.6 014/100] asix: Fix offset calculation in asix_rx_fixup() causing slow transmissions

2016-05-30 Thread Greg Kroah-Hartman
4.6-stable review patch.  If anyone has any objections, please let me know.

--

From: John Stultz 

commit cd9e2e5d3ff148be9ea210f622ce3e8e8292fcd6 upstream.

In testing with HiKey, we found that since
commit 3f30b158eba5 ("asix: On RX avoid creating bad Ethernet
frames"),
we're seeing lots of noise during network transfers:

[  239.027993] asix 1-1.1:1.0 eth0: asix_rx_fixup() Data Header synchronisation 
was lost, remaining 988
[  239.037310] asix 1-1.1:1.0 eth0: asix_rx_fixup() Bad Header Length 
0x54ebb5ec, offset 4
[  239.045519] asix 1-1.1:1.0 eth0: asix_rx_fixup() Bad Header Length 
0xcdffe7a2, offset 4
[  239.275044] asix 1-1.1:1.0 eth0: asix_rx_fixup() Data Header synchronisation 
was lost, remaining 988
[  239.284355] asix 1-1.1:1.0 eth0: asix_rx_fixup() Bad Header Length 
0x1d36f59d, offset 4
[  239.292541] asix 1-1.1:1.0 eth0: asix_rx_fixup() Bad Header Length 
0xaef3c1e9, offset 4
[  239.518996] asix 1-1.1:1.0 eth0: asix_rx_fixup() Data Header synchronisation 
was lost, remaining 988
[  239.528300] asix 1-1.1:1.0 eth0: asix_rx_fixup() Bad Header Length 
0x2881912, offset 4
[  239.536413] asix 1-1.1:1.0 eth0: asix_rx_fixup() Bad Header Length 
0x5638f7e2, offset 4

And network throughput ends up being pretty bursty and slow with
a overall throughput of at best ~30kB/s (where as previously we
got 1.1MB/s with the slower USB1.1 "full speed" host).

We found the issue also was reproducible on a x86_64 system,
using a "high-speed" USB2.0 port but the throughput did not
measurably drop (possibly due to the scp transfer being cpu
bound on my slow test hardware).

After lots of debugging, I found the check added in the
problematic commit seems to be calculating the offset
incorrectly.

In the normal case, in the main loop of the function, we do:
(where offset is zero, or set to "offset += (copy_length + 1) &
0xfffe" in the previous loop)
rx->header = get_unaligned_le32(skb->data +
offset);
offset += sizeof(u32);

But the problematic patch calculates:
offset = ((rx->remaining + 1) & 0xfffe) + sizeof(u32);
rx->header = get_unaligned_le32(skb->data + offset);

Adding some debug logic to check those offset calculation used
to find rx->header, the one in problematic code is always too
large by sizeof(u32).

Thus, this patch removes the incorrect " + sizeof(u32)" addition
in the problematic calculation, and resolves the issue.

Cc: Dean Jenkins 
Cc: "David B. Robins" 
Cc: Mark Craske 
Cc: Emil Goode 
Cc: "David S. Miller" 
Cc: YongQin Liu 
Cc: Guodong Xu 
Cc: Ivan Vecera 
Cc: linux-...@vger.kernel.org
Cc: netdev@vger.kernel.org
Reported-by: Yongqin Liu 
Signed-off-by: John Stultz 
Signed-off-by: David S. Miller 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/net/usb/asix_common.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- a/drivers/net/usb/asix_common.c
+++ b/drivers/net/usb/asix_common.c
@@ -66,7 +66,7 @@ int asix_rx_fixup_internal(struct usbnet
 * buffer.
 */
if (rx->remaining && (rx->remaining + sizeof(u32) <= skb->len)) {
-   offset = ((rx->remaining + 1) & 0xfffe) + sizeof(u32);
+   offset = ((rx->remaining + 1) & 0xfffe);
rx->header = get_unaligned_le32(skb->data + offset);
offset = 0;
 




Re: [PATCH] iwlwifi: mvm: avoid harmless -Wmaybe-uninialized warning

2016-05-30 Thread Coelho, Luciano
On Fri, 2016-05-27 at 15:07 +0200, Arnd Bergmann wrote:
> gcc is apparently unablel to track the state of the local 'resp_v2'
> variable across the kzalloc() function, and warns about the response
> variable being used without an initialization:
> 
> drivers/net/wireless/intel/iwlwifi/mvm/nvm.c: In function
> ‘iwl_mvm_update_mcc’:
> drivers/net/wireless/intel/iwlwifi/mvm/nvm.c:727:36: warning:
> ‘mcc_resp_v1’ may be used uninitialized in this function [-Wmaybe-
> uninitialized]
>    resp_cp->n_channels = mcc_resp_v1->n_channels;
> drivers/net/wireless/intel/iwlwifi/mvm/nvm.c:721:3: warning:
> ‘mcc_resp’ may be used uninitialized in this function [-Wmaybe-
> uninitialized]
>    memcpy(resp_cp, mcc_resp, resp_len);
> 
> The warning showed up in x86 allmodconfig after my patch to
> unhide -Wmaybe-uninitialized warnings by default was merged,
> though it always existed in randconfig builds. I did not
> catch the warning earlier because I was testing on ARM, which
> never produced the warning.
> 
> This rearranges the code in a way that improves readability for
> both humans and the compiler, and that avoids the warning.
> 
> Signed-off-by: Arnd Bergmann 
> Fixes: 6fa52430f0b3 ("iwlwifi: mvm: change mcc update API")
> ---

Thanks, Arnd! I queued this via our internal tree.

--
Cheers,
Luca.

Re: usbnet: smsc95xx: fix link detection for disabled autonegotiation

2016-05-30 Thread Christoph Fritz
On Sun, 2016-05-29 at 22:30 -0700, David Miller wrote:
> From: Christoph Fritz 
> Date: Thu, 26 May 2016 04:06:47 +0200
> 
> > @@ -1695,6 +1745,7 @@ static int smsc95xx_resume(struct usb_interface *intf)
> >  
> > /* do this first to ensure it's cleared even in error case */
> > pdata->suspend_flags = 0;
> > +   schedule_delayed_work(>carrier_check, CARRIER_CHECK_DELAY);
> 
> Why are you not cancelling this delayed work in the suspend routine of
> the driver?

I'm doing this:
+   if (pdata->suspend_flags != 0)
+   return;

inside the "worker-function" so that schedule_delayed_work() is not
called again.

Should I explicitly cancel_delayed_work() inside suspend() too?



[iproute PATCH] man: ip, ip-link: Fix ip option location

2016-05-30 Thread Phil Sutter
This patch drops the redundant description of some of ip's options in
ip-link.8's description of the 'show' subcommand, preserving the
description of -iec (but appending it to the list in ip.8 with minor
fixes).

Signed-off-by: Phil Sutter 
---
 man/man8/ip-link.8.in | 21 -
 man/man8/ip.8 |  4 
 2 files changed, 4 insertions(+), 21 deletions(-)

diff --git a/man/man8/ip-link.8.in b/man/man8/ip-link.8.in
index 984fb2eb0d63a..d3881e55d73c0 100644
--- a/man/man8/ip-link.8.in
+++ b/man/man8/ip-link.8.in
@@ -1119,27 +1119,6 @@ specifies the master device which enslaves devices to 
show.
 .I TYPE
 specifies the type of devices to show.
 
-.TP
-The show command has additional formatting options:
-
-.RS
-.TP
-.BR "\-s" , " \-stats", " \-statistics"
-output more statistics about packet usage.
-
-.TP
-.BR "\-d", " \-details"
-output more detailed information.
-
-.TP
-.BR "\-h", " \-human", " \-human-readable"
-output statistics with human readable values number followed by suffix
-
-.TP
-.BR "\-iec"
-print human readable rates in IEC units (ie. 1K = 1024).
-.RE
-
 .SS  ip link help - display help
 
 .PP
diff --git a/man/man8/ip.8 b/man/man8/ip.8
index aa2bc68c81ab6..f11fc0b9cf444 100644
--- a/man/man8/ip.8
+++ b/man/man8/ip.8
@@ -201,6 +201,10 @@ but use shorter format.
 .BR "\-rc" , " \-rcvbuf" 
 Set the netlink socket receive buffer size, defaults to 1MB.
 
+.TP
+.BR "\-iec"
+print human readable rates in IEC units (e.g. 1Ki = 1024).
+
 .SH IP - COMMAND SYNTAX
 
 .SS
-- 
2.8.2



Re: linux-next: Tree for May 30

2016-05-30 Thread Sudip Mukherjee

On Monday 30 May 2016 08:52 AM, Stephen Rothwell wrote:

Hi all,

Changes since 20160527:


Hi All,
I have just built and booted with next-20160530 and my dmesg is full of 
warnings from ath9k. Last kernel tested was v4.6 and there was no 
problem with that.


The traces are like:
Call Trace:
 [] dump_stack+0x63/0x87
 [] __warn+0xd1/0xf0
 [] warn_slowpath_null+0x1d/0x20
 [] ath9k_hw_gpio_request+0x6f/0x320 [ath9k_hw]
 [] ath9k_hw_reset+0xfe4/0x12e0 [ath9k_hw]
 [] ath_reset_internal+0x104/0x1f0 [ath9k]
 [] ath_reset+0x3d/0x60 [ath9k]
 [] ath_chanctx_set_channel+0x1b6/0x300 [ath9k]
 [] ath9k_config+0xc6/0x1f0 [ath9k]
 [] ? mutex_lock+0x12/0x2f
 [] ieee80211_hw_config+0x63/0x350 [mac80211]
 [] ieee80211_scan_work+0x161/0x480 [mac80211]
 [] process_one_work+0x153/0x3f0
 [] worker_thread+0x12b/0x4b0
 [] ? rescuer_thread+0x340/0x340
 [] kthread+0xc9/0xe0
 [] ret_from_fork+0x1f/0x40
 [] ? kthread_park+0x60/0x60
---[ end trace 27eb5094a52869ea ]---

Call Trace:
 [] dump_stack+0x63/0x87
 [] __warn+0xd1/0xf0
 [] warn_slowpath_null+0x1d/0x20
 [] ath9k_hw_gpio_get+0x1a9/0x1b0 [ath9k_hw]
 [] ath9k_rfkill_poll_state+0x34/0x60 [ath9k]
 [] ieee80211_rfkill_poll+0x33/0x40 [mac80211]
 [] cfg80211_rfkill_poll+0x2a/0xc0 [cfg80211]
 [] rfkill_poll+0x24/0x50
 [] process_one_work+0x153/0x3f0
 [] worker_thread+0x12b/0x4b0
 [] ? rescuer_thread+0x340/0x340
 [] kthread+0xc9/0xe0
 [] ret_from_fork+0x1f/0x40
 [] ? kthread_park+0x60/0x60
---[ end trace 27eb5094a5286a3d ]---


If it is a known problem then great.. else i can debug and see what the 
problem is. There are only few patches added for GPIO, so should not be 
a problem to find out what is causing the error.


Regards
Sudip



Re: [PATCHv2 net] sctp: sctp_diag should dump sctp socket type

2016-05-30 Thread Marcelo Ricardo Leitner
On Sun, May 29, 2016 at 05:42:13PM +0800, Xin Long wrote:
> Now we cannot distinguish that one sk is a udp or sctp style when
> we use ss to dump sctp_info. it's necessary to dump it as well.
> 
> For sctp_diag, ss support is not officially available, thus there
> are no official users of this yet, so we can add this field in the
> middle of sctp_info without breaking user API.
> 
> v1->v2:
>   - move 'sctpi_s_type' field to the end of struct sctp_info, so
> that it won't cause incompatibility with applications already
> built.
>   - add __reserved3 in sctp_info to make sure sctp_info is 8-byte
> alignment.
> 
> Signed-off-by: Xin Long 

Acked-by: Marcelo Ricardo Leitner 

> ---
>  include/linux/sctp.h | 2 ++
>  net/sctp/socket.c| 1 +
>  2 files changed, 3 insertions(+)
> 
> diff --git a/include/linux/sctp.h b/include/linux/sctp.h
> index dacb5e7..de1f643 100644
> --- a/include/linux/sctp.h
> +++ b/include/linux/sctp.h
> @@ -765,6 +765,8 @@ struct sctp_info {
>   __u8sctpi_s_disable_fragments;
>   __u8sctpi_s_v4mapped;
>   __u8sctpi_s_frag_interleave;
> + __u32   sctpi_s_type;
> + __u32   __reserved3;
>  };
>  
>  struct sctp_infox {
> diff --git a/net/sctp/socket.c b/net/sctp/socket.c
> index 777d032..67154b8 100644
> --- a/net/sctp/socket.c
> +++ b/net/sctp/socket.c
> @@ -4220,6 +4220,7 @@ int sctp_get_sctp_info(struct sock *sk, struct 
> sctp_association *asoc,
>   info->sctpi_s_disable_fragments = sp->disable_fragments;
>   info->sctpi_s_v4mapped = sp->v4mapped;
>   info->sctpi_s_frag_interleave = sp->frag_interleave;
> + info->sctpi_s_type = sp->type;
>  
>   return 0;
>   }
> -- 
> 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: [PATCH] qed: fix qed_fill_link() error handling

2016-05-30 Thread Yuval Mintz
> + if (IS_ENABLED(CONFIG_QED_SRIOV) && !IS_PF(hwfn->cdev)) {
> + qed_vf_get_link_params(hwfn, params);
> + qed_vf_get_link_state(hwfn, link);
> + qed_vf_get_link_caps(hwfn, link_caps);
> +
> + return 0;
> + }

The IS_ENABLED here seems a bit wasteful to me - we have empty implementation
under qed_vf.h just for this case [I.e., that SRIOV isn't enabled for qed].
If all we're trying achieve is removing these gcc warnings, I think we can 
simply
memset the structs in the currently-empty qed_vf_get_link_* functions.


Re: [PATCH 0/2] macvlan: Avoid unnecessary multicast cloning

2016-05-30 Thread Lennert Buytenhek
On Mon, May 30, 2016 at 04:17:52PM +0800, Herbert Xu wrote:

> > Commit 412ca1550cbecb2c ("macvlan: Move broadcasts into a work queue")
> > moved processing of all macvlan multicasts into a work queue.  This
> > causes a noticable performance regression when there is heavy multicast
> > traffic on the underlying interface for multicast groups that the
> > macvlan subinterfaces are not members of, in which case we end up
> > cloning all those packets and then freeing them again from a work queue
> > without really doing any useful work with them in between.
> 
> OK so your motivation is to get rid of the unnecessary memory
> allocation, right?

That and stack switches to kworker threads and serialisation on
the bc_queue queue lock.


Re: [net v3] veth: advertise peer link once both links are tied together

2016-05-30 Thread Nicolas Dichtel
Le 30/05/2016 18:01, Vincent Bernat a écrit :
>  ❦ 30 mai 2016 17:58 CEST, Vincent Bernat  :
> 
>> +
>> +rtmsg_ifinfo(RTM_NEWLINK, peer, IFF_SLAVE, GFP_KERNEL);
> 
> Maybe ~0U would be better than hijacking IFF_SLAVE?
IFF_SLAVE is wrong. It's a flag here, that will be put in the ifi_change field
not an attribute number.


Re: [PATCH] rtlwifi: fix error handling in *_read_adapter_info()

2016-05-30 Thread Larry Finger

On 05/30/2016 10:26 AM, Arnd Bergmann wrote:

There are nine copies of the _rtl88ee_read_adapter_info() function,
and most but not all of them cause a build warning in some configurations:

rtl8192de/hw.c: In function '_rtl92de_read_adapter_info':
rtl8192de/hw.c:1767:12: error: 'hwinfo' may be used uninitialized in this 
function [-Werror=maybe-uninitialized]
rtl8723ae/hw.c: In function '_rtl8723e_read_adapter_info.constprop':
rtlwifi/rtl8723ae/hw.c:1654:12: error: 'hwinfo' may be used uninitialized in 
this function [-Werror=maybe-uninitialized]

The problem is that when rtlefuse->epromtype is something other than
EEPROM_BOOT_EFUSE, the rest of the function uses undefined data, resulting
in random behavior later.

Apparently, in some drivers, the problem was already found and fixed
but the fix did not make it into the others.

This picks one approach to deal with the problem and applies identical
code to all 9 files, to simplify the later consolidation of those.

Signed-off-by: Arnd Bergmann 
---
  drivers/net/wireless/realtek/rtlwifi/rtl8188ee/hw.c | 12 +++-
  drivers/net/wireless/realtek/rtlwifi/rtl8192ce/hw.c | 17 -
  drivers/net/wireless/realtek/rtlwifi/rtl8192cu/hw.c | 16 +++-
  drivers/net/wireless/realtek/rtlwifi/rtl8192de/hw.c | 16 +++-
  drivers/net/wireless/realtek/rtlwifi/rtl8192ee/hw.c | 12 +++-
  drivers/net/wireless/realtek/rtlwifi/rtl8192se/hw.c | 20 ++--
  drivers/net/wireless/realtek/rtlwifi/rtl8723ae/hw.c | 13 +
  drivers/net/wireless/realtek/rtlwifi/rtl8723be/hw.c | 16 
  drivers/net/wireless/realtek/rtlwifi/rtl8821ae/hw.c | 15 +++
  9 files changed, 94 insertions(+), 43 deletions(-)

diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8188ee/hw.c 
b/drivers/net/wireless/realtek/rtlwifi/rtl8188ee/hw.c
index 8ee83b093c0d..e26a233684bb 100644
--- a/drivers/net/wireless/realtek/rtlwifi/rtl8188ee/hw.c
+++ b/drivers/net/wireless/realtek/rtlwifi/rtl8188ee/hw.c
@@ -1839,20 +1839,22 @@ static void _rtl88ee_read_adapter_info(struct 
ieee80211_hw *hw)
u8 hwinfo[HWSET_MAX_SIZE];
u16 eeprom_id;

-   if (rtlefuse->epromtype == EEPROM_BOOT_EFUSE) {
+   switch (rtlefuse->epromtype) {
+   case EEPROM_BOOT_EFUSE:
rtl_efuse_shadow_map_update(hw);
+   break;

-   memcpy(hwinfo, >efuse_map[EFUSE_INIT_MAP][0],
-  HWSET_MAX_SIZE);
-   } else if (rtlefuse->epromtype == EEPROM_93C46) {
+   case EEPROM_93C46:
RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
 "RTL819X Not boot from eeprom, check it !!");
return;
-   } else {
+
+   default:
RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
 "boot from neither eeprom nor efuse, check it !!");
return;
}
+   memcpy(hwinfo, >efuse_map[EFUSE_INIT_MAP][0], HWSET_MAX_SIZE);

RT_PRINT_DATA(rtlpriv, COMP_INIT, DBG_DMESG, "MAP\n",
  hwinfo, HWSET_MAX_SIZE);
diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8192ce/hw.c 
b/drivers/net/wireless/realtek/rtlwifi/rtl8192ce/hw.c
index 04eb5c3f8464..58b7ac6899ef 100644
--- a/drivers/net/wireless/realtek/rtlwifi/rtl8192ce/hw.c
+++ b/drivers/net/wireless/realtek/rtlwifi/rtl8192ce/hw.c
@@ -1680,21 +1680,28 @@ static void _rtl92ce_read_adapter_info(struct 
ieee80211_hw *hw)
struct rtl_priv *rtlpriv = rtl_priv(hw);
struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
+   struct device *dev = _pcipriv(hw)->dev.pdev->dev;
u16 i, usvalue;
u8 hwinfo[HWSET_MAX_SIZE];
u16 eeprom_id;

-   if (rtlefuse->epromtype == EEPROM_BOOT_EFUSE) {
+   switch (rtlefuse->epromtype) {
+   case EEPROM_BOOT_EFUSE:
rtl_efuse_shadow_map_update(hw);
+   break;

-   memcpy((void *)hwinfo,
-  (void *)>efuse_map[EFUSE_INIT_MAP][0],
-  HWSET_MAX_SIZE);
-   } else if (rtlefuse->epromtype == EEPROM_93C46) {
+   case EEPROM_93C46:
RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
 "RTL819X Not boot from eeprom, check it !!");
+   return;
+
+   default:
+   dev_warn(dev, "no efuse data\n");
+   return;
}

+   memcpy(hwinfo, >efuse_map[EFUSE_INIT_MAP][0], HWSET_MAX_SIZE);
+
RT_PRINT_DATA(rtlpriv, COMP_INIT, DBG_DMESG, "MAP",
  hwinfo, HWSET_MAX_SIZE);

diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8192cu/hw.c 
b/drivers/net/wireless/realtek/rtlwifi/rtl8192cu/hw.c
index 34ce06441d1b..ae1129f916d5 100644
--- a/drivers/net/wireless/realtek/rtlwifi/rtl8192cu/hw.c
+++ b/drivers/net/wireless/realtek/rtlwifi/rtl8192cu/hw.c
@@ -351,15 +351,21 @@ static void _rtl92cu_read_adapter_info(struct 
ieee80211_hw 

Re: [net v3] veth: advertise peer link once both links are tied together

2016-05-30 Thread Vincent Bernat
 ❦ 30 mai 2016 17:58 CEST, Vincent Bernat  :

> +
> + rtmsg_ifinfo(RTM_NEWLINK, peer, IFF_SLAVE, GFP_KERNEL);

Maybe ~0U would be better than hijacking IFF_SLAVE?
-- 
Anyone who has had a bull by the tail knows five or six more things
than someone who hasn't.
-- Mark Twain


[net v3] veth: advertise peer link once both links are tied together

2016-05-30 Thread Vincent Bernat
When the peer link is created, its "iflink" information is not
advertised through Netlink. Once created, the local device is advertised
with this information but if a user is maintaining a cache from all
updates, it will still miss the iflink for the peer link:

2: veth0@NONE:  mtu 1500 qdisc noop state DOWN group 
default
link/ether ae:0e:08:af:fb:a0 brd ff:ff:ff:ff:ff:ff
3: veth1@veth0:  mtu 1500 qdisc noop state DOWN 
group default
link/ether 3a:31:f1:36:2e:e5 brd ff:ff:ff:ff:ff:ff

With this patch, we advertise again the peer link to let any user pick
the appropriate iflink information:

3: veth0@NONE:  mtu 1500 qdisc noop state DOWN group 
default
link/ether fa:ba:12:26:99:00 brd ff:ff:ff:ff:ff:ff
3: veth0@veth1:  mtu 1500 qdisc noop state DOWN group 
default
link/ether fa:ba:12:26:99:00 brd ff:ff:ff:ff:ff:ff
4: veth1@veth0:  mtu 1500 qdisc noop state DOWN 
group default
link/ether ea:e4:e2:26:3c:87 brd ff:ff:ff:ff:ff:ff

Signed-off-by: Vincent Bernat 
---
v3:
 - send an additional netlink messages once the peer link is tied to
   avoid any chicken/egg problem

v2:
 - ensure the device is unregistered in case of link configuration failure

 drivers/net/veth.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/net/veth.c b/drivers/net/veth.c
index f37a6e61d4ad..2376d17b8f53 100644
--- a/drivers/net/veth.c
+++ b/drivers/net/veth.c
@@ -466,6 +466,8 @@ static int veth_newlink(struct net *src_net, struct 
net_device *dev,
 
priv = netdev_priv(peer);
rcu_assign_pointer(priv->peer, dev);
+
+   rtmsg_ifinfo(RTM_NEWLINK, peer, IFF_SLAVE, GFP_KERNEL);
return 0;
 
 err_register_dev:
-- 
2.8.1



Re: [PATCH V2 2/2] vhost_net: conditionally enable tx polling

2016-05-30 Thread Michael S. Tsirkin
On Mon, May 30, 2016 at 02:47:54AM -0400, Jason Wang wrote:
> We always poll tx for socket, this is sub optimal since:
> 
> - it will be only used when we exceed the sndbuf of the socket.
> - since we use two independent polls for tx and vq, this will slightly
>   increase the waitqueue traversing time and more important, vhost
>   could not benefit from commit
>   9e641bdcfa4ef4d6e2fbaa59c1be0ad5d1551fd5 ("net-tun: restructure
>   tun_do_read for better sleep/wakeup efficiency") even if we've
>   stopped rx polling during handle_rx since tx poll were still left in
>   the waitqueue.

Why is this an issue?
sock_def_write_space only wakes up when queue is half empty,
not on each packet.
if ((atomic_read(>sk_wmem_alloc) << 1) <= sk->sk_sndbuf)

I suspect the issue is with your previous patch,
it now pokes at the spinlock on data path
where it used not to.

Is that right?


> 
> Fix this by conditionally enable tx polling only when -EAGAIN were
> met.
> 
> Test shows about 8% improvement on guest rx pps.
> 
> Before: ~135
> After:  ~146
> 
> Signed-off-by: Jason Wang 
> ---
>  drivers/vhost/net.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c
> index e91603b..5a05fa0 100644
> --- a/drivers/vhost/net.c
> +++ b/drivers/vhost/net.c
> @@ -378,6 +378,7 @@ static void handle_tx(struct vhost_net *net)
>   goto out;
>  
>   vhost_disable_notify(>dev, vq);
> + vhost_net_disable_vq(net, vq);
>  
>   hdr_size = nvq->vhost_hlen;
>   zcopy = nvq->ubufs;
> @@ -459,6 +460,8 @@ static void handle_tx(struct vhost_net *net)
>   % UIO_MAXIOV;
>   }
>   vhost_discard_vq_desc(vq, 1);
> + if (err == -EAGAIN)
> + vhost_net_enable_vq(net, vq);
>   break;
>   }
>   if (err != len)
> -- 
> 1.8.3.1


Re: [PATCH V2 1/2] vhost_net: stop polling socket during rx processing

2016-05-30 Thread Michael S. Tsirkin
On Mon, May 30, 2016 at 02:47:53AM -0400, Jason Wang wrote:
> We don't stop rx polling socket during rx processing, this will lead
> unnecessary wakeups from under layer net devices (E.g
> sock_def_readable() form tun). Rx will be slowed down in this
> way. This patch avoids this by stop polling socket during rx
> processing. A small drawback is that this introduces some overheads in
> light load case because of the extra start/stop polling, but single
> netperf TCP_RR does not notice any change. In a super heavy load case,
> e.g using pktgen to inject packet to guest, we get about ~8.8%
> improvement on pps:
> 
> before: ~124 pkt/s
> after:  ~135 pkt/s
> 
> Signed-off-by: Jason Wang 
> ---
>  drivers/vhost/net.c | 56 
> +++--
>  1 file changed, 29 insertions(+), 27 deletions(-)
> 
> diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c
> index 10ff494..e91603b 100644
> --- a/drivers/vhost/net.c
> +++ b/drivers/vhost/net.c
> @@ -301,6 +301,32 @@ static bool vhost_can_busy_poll(struct vhost_dev *dev,
>  !vhost_has_work(dev);
>  }
>  
> +static void vhost_net_disable_vq(struct vhost_net *n,
> +  struct vhost_virtqueue *vq)
> +{
> + struct vhost_net_virtqueue *nvq =
> + container_of(vq, struct vhost_net_virtqueue, vq);
> + struct vhost_poll *poll = n->poll + (nvq - n->vqs);
> + if (!vq->private_data)
> + return;
> + vhost_poll_stop(poll);
> +}
> +
> +static int vhost_net_enable_vq(struct vhost_net *n,
> + struct vhost_virtqueue *vq)
> +{
> + struct vhost_net_virtqueue *nvq =
> + container_of(vq, struct vhost_net_virtqueue, vq);
> + struct vhost_poll *poll = n->poll + (nvq - n->vqs);
> + struct socket *sock;
> +
> + sock = vq->private_data;
> + if (!sock)
> + return 0;
> +
> + return vhost_poll_start(poll, sock->file);
> +}
> +
>  static int vhost_net_tx_get_vq_desc(struct vhost_net *net,
>   struct vhost_virtqueue *vq,
>   struct iovec iov[], unsigned int iov_size,

BTW we might want to rename these functions, name no longer
reflects function ...


> @@ -627,6 +653,7 @@ static void handle_rx(struct vhost_net *net)
>   if (!sock)
>   goto out;
>   vhost_disable_notify(>dev, vq);
> + vhost_net_disable_vq(net, vq);
>  
>   vhost_hlen = nvq->vhost_hlen;
>   sock_hlen = nvq->sock_hlen;
> @@ -715,9 +742,10 @@ static void handle_rx(struct vhost_net *net)
>   total_len += vhost_len;
>   if (unlikely(total_len >= VHOST_NET_WEIGHT)) {
>   vhost_poll_queue(>poll);
> - break;
> + goto out;
>   }
>   }
> + vhost_net_enable_vq(net, vq);

OK so if sock is readable but RX VQ is empty, this will
immediately schedule another round of handle_rx and so ad
infinitum,

Looks like a bug.


>  out:
>   mutex_unlock(>mutex);
>  }
> @@ -796,32 +824,6 @@ static int vhost_net_open(struct inode *inode, struct 
> file *f)
>   return 0;
>  }
>  
> -static void vhost_net_disable_vq(struct vhost_net *n,
> -  struct vhost_virtqueue *vq)
> -{
> - struct vhost_net_virtqueue *nvq =
> - container_of(vq, struct vhost_net_virtqueue, vq);
> - struct vhost_poll *poll = n->poll + (nvq - n->vqs);
> - if (!vq->private_data)
> - return;
> - vhost_poll_stop(poll);
> -}
> -
> -static int vhost_net_enable_vq(struct vhost_net *n,
> - struct vhost_virtqueue *vq)
> -{
> - struct vhost_net_virtqueue *nvq =
> - container_of(vq, struct vhost_net_virtqueue, vq);
> - struct vhost_poll *poll = n->poll + (nvq - n->vqs);
> - struct socket *sock;
> -
> - sock = vq->private_data;
> - if (!sock)
> - return 0;
> -
> - return vhost_poll_start(poll, sock->file);
> -}
> -
>  static struct socket *vhost_net_stop_vq(struct vhost_net *n,
>   struct vhost_virtqueue *vq)
>  {
> -- 
> 1.8.3.1


Re: [PATCH] veth: delay peer link configuration after interfaces are tied

2016-05-30 Thread Nicolas Dichtel
Le 30/05/2016 17:26, Vincent Bernat a écrit :
>  ❦ 30 mai 2016 17:19 CEST, Nicolas Dichtel  :
> 
>   priv = netdev_priv(peer);
>   rcu_assign_pointer(priv->peer, dev);
> +
> + err = rtnl_configure_link(peer, ifmp);
> + if (err < 0)
> + goto err_configure_peer;
>>>
 You should fix the error path. 'unregister_netdevice(dev)' is missing.
>>>
>>> I am sending another patch to fix that. I am quite unsure if I do the
>>> right thing here.
>>>
>> A less intrusive fix is to call 'rtmsg_ifinfo(RTM_NEWLINK, peer, ~0U,
>> GFP_KERNEL);' a the end of veth_newlink().
> 
> I did that at first. Maybe this would make more sense to do
> that. Otherwise, the first message contains an iflink value that we
> cannot resolve with just the received netlink messages (since the
> information is in the next netlink message). "ip monitor" seems to be
> able to get the info, but I suppose it does an additional
> lookup.
> 
Yes, it's a chicken and egg problem ;-)
I think that the first message with an iflink set to '0' is not a problem if a
second one update this value. Daemons that listen to those rtnl messages must
always update their caches. When the peer is put in another netns, its ifindex
may change again.


[PATCH] qed: fix qed_fill_link() error handling

2016-05-30 Thread Arnd Bergmann
gcc warns about qed_fill_link possibly accessing uninitialized data:

drivers/net/ethernet/qlogic/qed/qed_main.c: In function 'qed_fill_link':
drivers/net/ethernet/qlogic/qed/qed_main.c:1170:35: error: 'link_caps' may be 
used uninitialized in this function [-Werror=maybe-uninitialized]

While this warning is only about the specific case of CONFIG_QED_SRIOV
being disabled but the function getting called for a VF (which should
never happen), another possibility is that qed_mcp_get_*() fails without
returning data.

This rearranges the code so we bail out in either of the two cases
and print a warning instead of accessing the uninitialized data.

The qed_link_output structure remains untouched in this case, but
all callers first call memset() on it, so at least we are not leaking
stack data then.

Signed-off-by: Arnd Bergmann 
---
 drivers/net/ethernet/qlogic/qed/qed_main.c | 45 --
 1 file changed, 36 insertions(+), 9 deletions(-)

diff --git a/drivers/net/ethernet/qlogic/qed/qed_main.c 
b/drivers/net/ethernet/qlogic/qed/qed_main.c
index 753064679bde..68f87a4f9316 100644
--- a/drivers/net/ethernet/qlogic/qed/qed_main.c
+++ b/drivers/net/ethernet/qlogic/qed/qed_main.c
@@ -1105,6 +1105,39 @@ static int qed_get_port_type(u32 media_type)
return port_type;
 }
 
+static int qed_get_link_data(struct qed_hwfn *hwfn,
+struct qed_mcp_link_params *params,
+struct qed_mcp_link_state *link,
+struct qed_mcp_link_capabilities *link_caps)
+{
+   void *p;
+
+   if (IS_ENABLED(CONFIG_QED_SRIOV) && !IS_PF(hwfn->cdev)) {
+   qed_vf_get_link_params(hwfn, params);
+   qed_vf_get_link_state(hwfn, link);
+   qed_vf_get_link_caps(hwfn, link_caps);
+
+   return 0;
+   }
+
+   p = qed_mcp_get_link_params(hwfn);
+   if (!p)
+   return -ENXIO;
+   memcpy(params, p, sizeof(*params));
+
+   p = qed_mcp_get_link_state(hwfn);
+   if (!p)
+   return -ENXIO;
+   memcpy(link, p, sizeof(*link));
+
+   p = qed_mcp_get_link_capabilities(hwfn);
+   if (!p)
+   return -ENXIO;
+   memcpy(link_caps, p, sizeof(*link_caps));
+
+   return 0;
+}
+
 static void qed_fill_link(struct qed_hwfn *hwfn,
  struct qed_link_output *if_link)
 {
@@ -1116,15 +1149,9 @@ static void qed_fill_link(struct qed_hwfn *hwfn,
memset(if_link, 0, sizeof(*if_link));
 
/* Prepare source inputs */
-   if (IS_PF(hwfn->cdev)) {
-   memcpy(, qed_mcp_get_link_params(hwfn), sizeof(params));
-   memcpy(, qed_mcp_get_link_state(hwfn), sizeof(link));
-   memcpy(_caps, qed_mcp_get_link_capabilities(hwfn),
-  sizeof(link_caps));
-   } else {
-   qed_vf_get_link_params(hwfn, );
-   qed_vf_get_link_state(hwfn, );
-   qed_vf_get_link_caps(hwfn, _caps);
+   if (qed_get_link_data(hwfn, , , _caps)) {
+   dev_warn(>cdev->pdev->dev, "no link data available\n");
+   return;
}
 
/* Set the link parameters to pass to protocol driver */
-- 
2.7.0



[PATCH] rtlwifi: fix error handling in *_read_adapter_info()

2016-05-30 Thread Arnd Bergmann
There are nine copies of the _rtl88ee_read_adapter_info() function,
and most but not all of them cause a build warning in some configurations:

rtl8192de/hw.c: In function '_rtl92de_read_adapter_info':
rtl8192de/hw.c:1767:12: error: 'hwinfo' may be used uninitialized in this 
function [-Werror=maybe-uninitialized]
rtl8723ae/hw.c: In function '_rtl8723e_read_adapter_info.constprop':
rtlwifi/rtl8723ae/hw.c:1654:12: error: 'hwinfo' may be used uninitialized in 
this function [-Werror=maybe-uninitialized]

The problem is that when rtlefuse->epromtype is something other than
EEPROM_BOOT_EFUSE, the rest of the function uses undefined data, resulting
in random behavior later.

Apparently, in some drivers, the problem was already found and fixed
but the fix did not make it into the others.

This picks one approach to deal with the problem and applies identical
code to all 9 files, to simplify the later consolidation of those.

Signed-off-by: Arnd Bergmann 
---
 drivers/net/wireless/realtek/rtlwifi/rtl8188ee/hw.c | 12 +++-
 drivers/net/wireless/realtek/rtlwifi/rtl8192ce/hw.c | 17 -
 drivers/net/wireless/realtek/rtlwifi/rtl8192cu/hw.c | 16 +++-
 drivers/net/wireless/realtek/rtlwifi/rtl8192de/hw.c | 16 +++-
 drivers/net/wireless/realtek/rtlwifi/rtl8192ee/hw.c | 12 +++-
 drivers/net/wireless/realtek/rtlwifi/rtl8192se/hw.c | 20 ++--
 drivers/net/wireless/realtek/rtlwifi/rtl8723ae/hw.c | 13 +
 drivers/net/wireless/realtek/rtlwifi/rtl8723be/hw.c | 16 
 drivers/net/wireless/realtek/rtlwifi/rtl8821ae/hw.c | 15 +++
 9 files changed, 94 insertions(+), 43 deletions(-)

diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8188ee/hw.c 
b/drivers/net/wireless/realtek/rtlwifi/rtl8188ee/hw.c
index 8ee83b093c0d..e26a233684bb 100644
--- a/drivers/net/wireless/realtek/rtlwifi/rtl8188ee/hw.c
+++ b/drivers/net/wireless/realtek/rtlwifi/rtl8188ee/hw.c
@@ -1839,20 +1839,22 @@ static void _rtl88ee_read_adapter_info(struct 
ieee80211_hw *hw)
u8 hwinfo[HWSET_MAX_SIZE];
u16 eeprom_id;
 
-   if (rtlefuse->epromtype == EEPROM_BOOT_EFUSE) {
+   switch (rtlefuse->epromtype) {
+   case EEPROM_BOOT_EFUSE:
rtl_efuse_shadow_map_update(hw);
+   break;
 
-   memcpy(hwinfo, >efuse_map[EFUSE_INIT_MAP][0],
-  HWSET_MAX_SIZE);
-   } else if (rtlefuse->epromtype == EEPROM_93C46) {
+   case EEPROM_93C46:
RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
 "RTL819X Not boot from eeprom, check it !!");
return;
-   } else {
+
+   default:
RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
 "boot from neither eeprom nor efuse, check it !!");
return;
}
+   memcpy(hwinfo, >efuse_map[EFUSE_INIT_MAP][0], HWSET_MAX_SIZE);
 
RT_PRINT_DATA(rtlpriv, COMP_INIT, DBG_DMESG, "MAP\n",
  hwinfo, HWSET_MAX_SIZE);
diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8192ce/hw.c 
b/drivers/net/wireless/realtek/rtlwifi/rtl8192ce/hw.c
index 04eb5c3f8464..58b7ac6899ef 100644
--- a/drivers/net/wireless/realtek/rtlwifi/rtl8192ce/hw.c
+++ b/drivers/net/wireless/realtek/rtlwifi/rtl8192ce/hw.c
@@ -1680,21 +1680,28 @@ static void _rtl92ce_read_adapter_info(struct 
ieee80211_hw *hw)
struct rtl_priv *rtlpriv = rtl_priv(hw);
struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
+   struct device *dev = _pcipriv(hw)->dev.pdev->dev;
u16 i, usvalue;
u8 hwinfo[HWSET_MAX_SIZE];
u16 eeprom_id;
 
-   if (rtlefuse->epromtype == EEPROM_BOOT_EFUSE) {
+   switch (rtlefuse->epromtype) {
+   case EEPROM_BOOT_EFUSE:
rtl_efuse_shadow_map_update(hw);
+   break;
 
-   memcpy((void *)hwinfo,
-  (void *)>efuse_map[EFUSE_INIT_MAP][0],
-  HWSET_MAX_SIZE);
-   } else if (rtlefuse->epromtype == EEPROM_93C46) {
+   case EEPROM_93C46:
RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
 "RTL819X Not boot from eeprom, check it !!");
+   return;
+
+   default:
+   dev_warn(dev, "no efuse data\n");
+   return;
}
 
+   memcpy(hwinfo, >efuse_map[EFUSE_INIT_MAP][0], HWSET_MAX_SIZE);
+
RT_PRINT_DATA(rtlpriv, COMP_INIT, DBG_DMESG, "MAP",
  hwinfo, HWSET_MAX_SIZE);
 
diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8192cu/hw.c 
b/drivers/net/wireless/realtek/rtlwifi/rtl8192cu/hw.c
index 34ce06441d1b..ae1129f916d5 100644
--- a/drivers/net/wireless/realtek/rtlwifi/rtl8192cu/hw.c
+++ b/drivers/net/wireless/realtek/rtlwifi/rtl8192cu/hw.c
@@ -351,15 +351,21 @@ static void _rtl92cu_read_adapter_info(struct 
ieee80211_hw *hw)
u8 hwinfo[HWSET_MAX_SIZE] = {0};
   

Re: [PATCH v5 0/2] skb_array: array based FIFO for skbs

2016-05-30 Thread Michael S. Tsirkin
On Mon, May 30, 2016 at 05:59:33PM +0800, Jason Wang wrote:
> 
> 
> On 2016年05月23日 18:43, Michael S. Tsirkin wrote:
> >This is in response to the proposal by Jason to make tun
> >rx packet queue lockless using a circular buffer.
> >My testing seems to show that at least for the common usecase
> >in networking, which isn't lockless, circular buffer
> >with indices does not perform that well, because
> >each index access causes a cache line to bounce between
> >CPUs, and index access causes stalls due to the dependency.
> 
> I change tun to use skb array, looks like it can give about 5% more faster
> than skb ring.

OK and skb ring is 9% faster than the linked list, so together
this is a 14% speedup?

> And we usually don't need touch bhs during consume and produce (e.g for the
> case of tun).
> 
> Thanks

Maybe I'll drop it in v6 then ...
Could you post the full tun patchset please?

-- 
MST


Re: [PATCH] veth: delay peer link configuration after interfaces are tied

2016-05-30 Thread Vincent Bernat
 ❦ 30 mai 2016 17:19 CEST, Nicolas Dichtel  :

priv = netdev_priv(peer);
rcu_assign_pointer(priv->peer, dev);
 +
 +  err = rtnl_configure_link(peer, ifmp);
 +  if (err < 0)
 +  goto err_configure_peer;
>> 
>>> You should fix the error path. 'unregister_netdevice(dev)' is missing.
>> 
>> I am sending another patch to fix that. I am quite unsure if I do the
>> right thing here.
>> 
> A less intrusive fix is to call 'rtmsg_ifinfo(RTM_NEWLINK, peer, ~0U,
> GFP_KERNEL);' a the end of veth_newlink().

I did that at first. Maybe this would make more sense to do
that. Otherwise, the first message contains an iflink value that we
cannot resolve with just the received netlink messages (since the
information is in the next netlink message). "ip monitor" seems to be
able to get the info, but I suppose it does an additional
lookup.
-- 
Make sure every module hides something.
- The Elements of Programming Style (Kernighan & Plauger)


Re: [PATCH 3/7] binding: mdio-mux: Add DT binding doc for Broadcom MDIO bus mutiplexer

2016-05-30 Thread Andrew Lunn
On Mon, May 30, 2016 at 12:40:47PM +0530, Pramod Kumar wrote:
> Add DT binding doc for Broadcom MDIO bus mutiplexer driver.
> 
> Signed-off-by: Pramod Kumar 
> ---
>  .../bindings/net/brcm,mdio-mux-iproc.txt   | 64 
> ++
>  1 file changed, 64 insertions(+)
>  create mode 100644 
> Documentation/devicetree/bindings/net/brcm,mdio-mux-iproc.txt
> 
> diff --git a/Documentation/devicetree/bindings/net/brcm,mdio-mux-iproc.txt 
> b/Documentation/devicetree/bindings/net/brcm,mdio-mux-iproc.txt
> new file mode 100644
> index 000..dd74ee0
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/net/brcm,mdio-mux-iproc.txt
> @@ -0,0 +1,64 @@
> +Properties for an MDIO bus mutiplexer found in Broadcom iProc based SoCs.
> +
> +This MDIO bus multiplexer defines buses that could be internal as well as
> +external to SoCs and could accept MDIO transaction compatible to C-22 or
> +C-45 Clause. When Child bus is selected, one need to select these two
> +properties as well to generate desired MDIO trascation on appropriate bus.
> +
> +Required properties in addition to the generic multiplexer properties:
> +
> +MDIO multiplexer node:
> +- complatible: brcm,mdio-mux-iproc.
> +
> +Child bus node:
> +-brcm,is-c45: Boolean property indicating PHYs attached to this bus supports
> +   C-45 mdio transaction.

This is-c45 seems to be at the wrong level. As far as i know, you can
mix C22 and C45 devices on a bus. It is a property of the individual
MDIO device if it uses C45 or not.

I would expect your MDIO device PHY drivers to logically OR
MII_ADDR_C45 into the address when doing an MDIO read/write using C45.

 Andrew


Re: [PATCH] veth: delay peer link configuration after interfaces are tied

2016-05-30 Thread Nicolas Dichtel
Le 30/05/2016 12:13, Vincent Bernat a écrit :
> When the peer link is created, its "iflink" information is not
> advertised through netlink. If a user is maintaining a cache from all
> updates, it will miss this information:
> 
> 2: veth0@NONE:  mtu 1500 qdisc noop state DOWN group 
> default
> link/ether ae:0e:08:af:fb:a0 brd ff:ff:ff:ff:ff:ff
> 3: veth1@veth0:  mtu 1500 qdisc noop state 
> DOWN group default
> link/ether 3a:31:f1:36:2e:e5 brd ff:ff:ff:ff:ff:ff
> 
> To avoid this situation, the peer link is only configured after both
> interfaces are tied together:
> 
> 3: veth0@veth1:  mtu 1500 qdisc noop state DOWN 
> group default
> link/ether ee:0d:80:46:36:fe brd ff:ff:ff:ff:ff:ff
> 4: veth1@veth0:  mtu 1500 qdisc noop state 
> DOWN group default
> link/ether ba:25:bc:7a:0d:c8 brd ff:ff:ff:ff:ff:ff
> 
> Signed-off-by: Vincent Bernat 
> ---
Please specify the version in the title (something like '[PATCH net v3]' here,
see --subject-prefix).

Also add the changelog after the '---' (see --annotate).


Re: [PATCH] veth: delay peer link configuration after interfaces are tied

2016-05-30 Thread Nicolas Dichtel
Le 30/05/2016 12:11, Vincent Bernat a écrit :
>  ❦ 30 mai 2016 11:23 CEST, Nicolas Dichtel  :
> 
>>> @@ -466,6 +462,10 @@ static int veth_newlink(struct net *src_net, struct 
>>> net_device *dev,
>>>  
>>> priv = netdev_priv(peer);
>>> rcu_assign_pointer(priv->peer, dev);
>>> +
>>> +   err = rtnl_configure_link(peer, ifmp);
>>> +   if (err < 0)
>>> +   goto err_configure_peer;
> 
>> You should fix the error path. 'unregister_netdevice(dev)' is missing.
> 
> I am sending another patch to fix that. I am quite unsure if I do the
> right thing here.
> 
A less intrusive fix is to call 'rtmsg_ifinfo(RTM_NEWLINK, peer, ~0U,
GFP_KERNEL);' a the end of veth_newlink().



Re: [PATCH 1/4] base: soc: introduce soc_device_match() interface

2016-05-30 Thread Arnd Bergmann
On Monday, May 30, 2016 3:14:38 PM CEST Arnd Bergmann wrote:
> We keep running into cases where device drivers want to know the exact
> version of the SoC a they are currently running on. In the past, this
> has usually been done through a vendor specific API that can be called
> by a driver, or by directly accessing some kind of version register
> that is not part of the device itself but that belongs to a global
> register area of the chip.
> 
> Common reasons for doing this include:
> 
> - A machine is not using devicetree or similar for passing data
>   about on-chip devices, but just announces their presence using
>   boot-time platform devices, and the machine code itself does
>   not care about the revision.
> 
> - There is existing firmware or boot loaders with existing DT
>   binaries with generic compatible strings that do not identify
>   the particular revision of each device, but the driver knows
>   which SoC revisions include which part
> 
> - A prerelease version of a chip has some quirks and we are
>   using the same version of the bootloader and the DT blob
>   on both the prerelease and the final version. An update of
>   the DT binding seems inappropriate because that would involve
>   maintaining multiple copies of the dts and/or bootloader.
> 
> This introduces the soc_device_match() interface that is meant
> to work like of_match_node() but instead of identifying the
> version of a device, it identifies the SoC itself using a
> vendor-agnostic interface.
> 
> Unlike soc_device_match(), we do not do an exact string compare
> but instead use glob_match() to allow wildcards in strings.

I'm sorry the series introduced build failures (I had done some changes
after testing), here is a quick fixup. I'll resend the whole thing
after someone has looked at it as none of the changes below should
have any influence on the review.

Arnd

diff --git a/drivers/base/soc.c b/drivers/base/soc.c
index e9623c6674a5..c38573249777 100644
--- a/drivers/base/soc.c
+++ b/drivers/base/soc.c
@@ -173,7 +173,7 @@ module_exit(soc_bus_unregister);
 static int soc_device_match_one(struct device *dev, void *arg)
 {
struct soc_device *soc_dev = container_of(dev, struct soc_device, dev);
-   struct soc_device_attribute *match = arg;
+   const struct soc_device_attribute *match = arg;
 
if (match->machine && !glob_match(match->machine, 
soc_dev->attr->machine))
return 0;
@@ -208,7 +208,7 @@ static int soc_device_match_one(struct device *dev, void 
*arg)
  * soc_device_attribute to pass a structure or function pointer for
  * each entry.
  */
-struct soc_device_attribute *soc_device_match(struct soc_device_attribute 
*matches)
+const struct soc_device_attribute *soc_device_match(const struct 
soc_device_attribute *matches)
 {
struct device *dev;
int ret;
@@ -219,7 +219,7 @@ struct soc_device_attribute *soc_device_match(struct 
soc_device_attribute *match
return NULL;
 
dev = NULL;
-   ret = bus_for_each_dev(_bus_type, dev, matches,
+   ret = bus_for_each_dev(_bus_type, dev, (void *)matches,
 soc_device_match_one);
}
 
diff --git a/drivers/mmc/host/sdhci-of-esdhc.c 
b/drivers/mmc/host/sdhci-of-esdhc.c
index 1d4814fe4cb2..a7b8b05a13e8 100644
--- a/drivers/mmc/host/sdhci-of-esdhc.c
+++ b/drivers/mmc/host/sdhci-of-esdhc.c
@@ -19,6 +19,8 @@
 #include 
 #include 
 #include 
+#include 
+
 #include "sdhci-pltfm.h"
 #include "sdhci-esdhc.h"
 
@@ -75,7 +77,6 @@ static u16 esdhc_readw_fixup(struct sdhci_host *host,
 {
struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
struct sdhci_esdhc *esdhc = sdhci_pltfm_priv(pltfm_host);
-   u16 ret;
int shift = (spec_reg & 0x2) * 8;
 
if (spec_reg == SDHCI_HOST_VERSION)
@@ -565,7 +566,7 @@ static const struct sdhci_pltfm_data sdhci_esdhc_le_pdata = 
{
 };
 
 #define T4240_HOST_VER ((VENDOR_V_23 << SDHCI_VENDOR_VER_SHIFT) | 
SDHCI_SPEC_200)
-static const struct soc_device_attribute esdhc_t4240_quirk = {
+static const struct soc_device_attribute esdhc_t4240_quirk[] = {
/* T4240 revision < 0x20 uses vendor version 23, SDHCI version 200 */
{ .soc_id = "T4*(0x824000)", .revision = "0x[01]?",
  .data = (void *)(uintptr_t)(T4240_HOST_VER) },
@@ -576,6 +577,7 @@ static void esdhc_init(struct platform_device *pdev, struct 
sdhci_host *host)
 {
struct sdhci_pltfm_host *pltfm_host;
struct sdhci_esdhc *esdhc;
+   u32 host_ver;
 
pltfm_host = sdhci_priv(host);
esdhc = sdhci_pltfm_priv(pltfm_host);
@@ -583,9 +585,9 @@ static void esdhc_init(struct platform_device *pdev, struct 
sdhci_host *host)
host_ver = sdhci_readw(host, SDHCI_HOST_VERSION);
 
if (of_device_is_compatible(pdev->dev.of_node, "fsl,t4240-esdhc")) {
-   struct soc_device_attribute *match;
+   const struct soc_device_attribute 

Re: [PATCH RFT 1/2] phylib: add device reset GPIO support

2016-05-30 Thread Linus Walleij
On Thu, May 26, 2016 at 9:00 PM, Uwe Kleine-König
 wrote:
> On Thu, May 26, 2016 at 11:00:55AM +0200, Linus Walleij wrote:
>> On Thu, May 12, 2016 at 8:42 PM, Uwe Kleine-König
>>  wrote:
>>
>> > [added Linus Walleij to Cc, there is a question for you/him below]
>> (...)
>> >> +void mdio_device_reset(struct mdio_device *mdiodev, int value)
>> >> +{
>> >> + if (mdiodev->reset)
>> >> + gpiod_set_value(mdiodev->reset, value);
>> >
>> > Before v4.6-rc1~108^2~91 it was not necessary to check for the first
>> > parameter being non-NULL before calling gpiod_set_value. Linus, did you
>> > change this on purpose?
>>
>> Not really. And AFAICT it is still not necessary: what changed is that
>> an error message will be printed by VALIDATE_DESC() if you do that.
>> And that is proper I guess? I think it's sloppy code to randomly pass in
>> NULL to a call and just expect it to bail out, it seems more like
>> exercising the error path than something you'd normally rely on.
>>
>> Or am I getting things wrong?
>
> is the following sloppy?:
>
> somegpio = gpiod_get_optional(dev, "some", GPIOD_OUT_LOW);
> if (IS_ERR(somegpio))
> return PTR_ERR(somegpio);
> gpiod_set_value(somegpio, 1);

Grrr OK I see, it's explicit from the _optional() call that it may be NULL
and then it should be ignored. So subsequent functions should ignore
that and bail out. My bad, sorry.

> If not (as I assume) you really changed something as this might trigger
> the warning.

Making a patch.

Yours,
Linus Walleij


RE: [PATCH 5/7] net:mdio-mux: Add MDIO mux driver for iProc SoCs

2016-05-30 Thread Pramod Kumar
Hi Andrew,

Thanks for reviewing. Please see my comment inline.

> -Original Message-
> From: Andrew Lunn [mailto:and...@lunn.ch]
> Sent: 30 May 2016 19:05
> To: Pramod Kumar
> Cc: Rob Herring; Pawel Moll; Mark Rutland; Ian Campbell; Kumar Gala;
Catalin
> Marinas; Will Deacon; Kishon Vijay Abraham I; David S. Miller;
> devicet...@vger.kernel.org; netdev@vger.kernel.org; linux-
> ker...@vger.kernel.org; bcm-kernel-feedback-l...@broadcom.com;
linux-arm-
> ker...@lists.infradead.org
> Subject: Re: [PATCH 5/7] net:mdio-mux: Add MDIO mux driver for iProc
SoCs
>
> On Mon, May 30, 2016 at 12:40:49PM +0530, Pramod Kumar wrote:
> > iProc based SoCs supports the integrated mdio multiplexer which has
> > the bus selection as well as mdio transaction generation logic inside.
>
> Hi Pramod
>
> Great to see you using the existing MDIO framework. Thanks.
>
> > +static int mdio_mux_iproc_switch_fn(int current_child, int
desired_child,
> > +   void *data)
> > +{
> > +   struct iproc_mdiomux_desc *md = data;
> > +   struct mdiomux_bus_param *bp = >bus_param[desired_child];
> > +   u32 param, bus_id;
> > +   bool bus_dir;
> > +
> > +   /* select bus and its properties */
> > +   bus_dir = (desired_child < EXT_BUS_START_ADDR);
> > +   bus_id = bus_dir ? desired_child : (desired_child -
> > +EXT_BUS_START_ADDR);
> > +
> > +   param = (bus_dir ? 1 : 0) << MDIO_PARAM_INTERNAL_SEL;
> > +   param |= (bp->is_c45 ? 1 : 0) << MDIO_PARAM_C45_SEL;
> > +   param |= (bus_id << MDIO_PARAM_BUS_ID);
> > +
> > +   writel(param, md->base + MDIO_PARAM_OFFSET);
> > +   return 0;
> > +}
>
> What i don't yet see is why you went for the concept of an integrated
MDIO and
> MUX. This function above is the mux function, and it looks like it could
be used
> to implement a standard mdio-mux driver.
>

iProc based SoCs Integrated MDIO Multiplexer has both logic in a hardware.
MDIO transaction and Child bus selection logic share the same address
space.
For ex-

In above mux function- Register-MDIO_PARAM_OFFSET is used for bus,
direction and transaction type. Same register
Is used for programming the PHY Ids and write data values in MDIO parent
bus transaction.

Writing MDIO bus driver and mux driver separately gives a notion of being
two separate device/address space, obviously it is not our use case.
Even if we used syscon for accessing the shared register, this does not
appears good for writing separate drivers for a single device.


> Thanks
>  Andrew

Regards,
Pramod


Re: [PATCH net-next] ravb: Add ESF in RCR for enabling separation filter

2016-05-30 Thread Sergei Shtylyov

On 05/29/2016 11:25 PM, Yoshihiro Kaneko wrote:


From: Masaru Nagai 

This patch adds enabling separation filter(ESF) is setting value of B'11.
This setting filter for separating AVB stream frames from non-AVB stream
frames is enabled. Non-matching frames from a stream are processed in
queue 0(best effort). H/W manual recommends B'11 or B'10.
When B'10 is setting, Non-mating frames are discarded.


   It was somewhat hard for me to parse that...


Signed-off-by: Masaru Nagai 
Signed-off-by: Kazuya Mizuguchi 
Signed-off-by: Yoshihiro Kaneko 


Acked-by: Sergei Shtylyov 

MBR, Sergei



Re: [PATCH net-next] ravb: Add SET_RUNTIME_PM_OPS macro

2016-05-30 Thread Sergei Shtylyov

Hello.

On 05/29/2016 11:25 PM, Yoshihiro Kaneko wrote:


From: Kazuya Mizuguchi 

Use SET_RUNTIME_PM_OPS macro instead of assigning a member of
dev_pm_ops directly.

Signed-off-by: Kazuya Mizuguchi 
Signed-off-by: Yoshihiro Kaneko 


Acked-by: Sergei Shtylyov 

MBR, Sergei



Re: [PATCH net] net: dsa: mv88e6xxx: Fix port forwarding mask

2016-05-30 Thread Vivien Didelot
Hi Wojciech, David,

Wojciech Dubowik  writes:

> Port's vlan table is specified by bit mask and not by number.
> Only 4.4.x kernels are affected.
>
> Signed-off-by: Wojciech Dubowik 
> ---
>  drivers/net/dsa/mv88e6xxx.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/net/dsa/mv88e6xxx.c b/drivers/net/dsa/mv88e6xxx.c
> index 2dea39b..3e074d4 100644
> --- a/drivers/net/dsa/mv88e6xxx.c
> +++ b/drivers/net/dsa/mv88e6xxx.c
> @@ -2150,7 +2150,7 @@ static int mv88e6xxx_setup_port(struct dsa_switch *ds, 
> int port)
>* database, and allow every port to egress frames on all other ports.
>*/
>   reg = BIT(ps->num_ports) - 1; /* all ports */
> - ret = _mv88e6xxx_port_vlan_map_set(ds, port, reg & ~port);
> + ret = _mv88e6xxx_port_vlan_map_set(ds, port, reg & ~BIT(port));
>   if (ret)
>   goto abort;

Commit be1faa92e83b ("net: dsa: mv88e6xxx: fix port VLAN maps") in
net/master already fixes this.

But indeed v4.5 contains be1faa92e83b but not v4.4.

Thanks,

Vivien


[PATCH iproute2] Added support for selection of new HSR version

2016-05-30 Thread Peter Heise
A new HSR version was added in 4.7 that can be enabled
via iproute2. Per default the old version is selected,
however, with "ip link add [..] type hsr [..] version 1"
the newer version can be enabled.

Signed-off-by: Peter Heise 
---
 ip/iplink_hsr.c | 13 +++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/ip/iplink_hsr.c b/ip/iplink_hsr.c
index 65fbec8..84d3a65 100644
--- a/ip/iplink_hsr.c
+++ b/ip/iplink_hsr.c
@@ -25,7 +25,7 @@ static void print_usage(FILE *f)
 {
fprintf(f,
 "Usage:\tip link add name NAME type hsr slave1 SLAVE1-IF slave2 SLAVE2-IF\n"
-"\t[ supervision ADDR-BYTE ]\n"
+"\t[ supervision ADDR-BYTE ] [version VERSION]\n"
 "\n"
 "NAME\n"
 "  name of new hsr device (e.g. hsr0)\n"
@@ -33,7 +33,9 @@ static void print_usage(FILE *f)
 "  the two slave devices bound to the HSR device\n"
 "ADDR-BYTE\n"
 "  0-255; the last byte of the multicast address used for HSR 
supervision\n"
-"  frames (default = 0)\n");
+"  frames (default = 0)\n"
+"VERSION\n"
+"  0,1; the protocol version to be used. (default = 0)\n");
 }
 
 static void usage(void)
@@ -46,6 +48,7 @@ static int hsr_parse_opt(struct link_util *lu, int argc, char 
**argv,
 {
int ifindex;
unsigned char multicast_spec;
+   unsigned char protocol_version;
 
while (argc > 0) {
if (matches(*argv, "supervision") == 0) {
@@ -54,6 +57,12 @@ static int hsr_parse_opt(struct link_util *lu, int argc, 
char **argv,
invarg("ADDR-BYTE is invalid", *argv);
addattr_l(n, 1024, IFLA_HSR_MULTICAST_SPEC,
  _spec, 1);
+   } else if (matches(*argv, "version") == 0) {
+   NEXT_ARG();
+   if (!(get_u8(_version, *argv, 0) == 0 
|| get_u8(_version, *argv, 0) == 1))
+   invarg("VERSION is invalid", *argv);
+   addattr_l(n, 1024, IFLA_HSR_VERSION,
+ _version, 1);
} else if (matches(*argv, "slave1") == 0) {
NEXT_ARG();
ifindex = ll_name_to_index(*argv);
-- 
2.7.4



Re: [PATCH 5/7] net:mdio-mux: Add MDIO mux driver for iProc SoCs

2016-05-30 Thread Andrew Lunn
On Mon, May 30, 2016 at 12:40:49PM +0530, Pramod Kumar wrote:
> iProc based SoCs supports the integrated mdio multiplexer which
> has the bus selection as well as mdio transaction generation logic
> inside.

Hi Pramod

Great to see you using the existing MDIO framework. Thanks.

> +static int mdio_mux_iproc_switch_fn(int current_child, int desired_child,
> + void *data)
> +{
> + struct iproc_mdiomux_desc *md = data;
> + struct mdiomux_bus_param *bp = >bus_param[desired_child];
> + u32 param, bus_id;
> + bool bus_dir;
> +
> + /* select bus and its properties */
> + bus_dir = (desired_child < EXT_BUS_START_ADDR);
> + bus_id = bus_dir ? desired_child : (desired_child - EXT_BUS_START_ADDR);
> +
> + param = (bus_dir ? 1 : 0) << MDIO_PARAM_INTERNAL_SEL;
> + param |= (bp->is_c45 ? 1 : 0) << MDIO_PARAM_C45_SEL;
> + param |= (bus_id << MDIO_PARAM_BUS_ID);
> +
> + writel(param, md->base + MDIO_PARAM_OFFSET);
> + return 0;
> +}

What i don't yet see is why you went for the concept of an integrated
MDIO and MUX. This function above is the mux function, and it looks
like it could be used to implement a standard mdio-mux driver.

Thanks
 Andrew


[PATCH 4/4] Revert "powerpc/fsl: Move fsl_guts.h out of arch/powerpc"

2016-05-30 Thread Arnd Bergmann
All users of this driver are PowerPC specific and the header file
has no business in the global include/linux/ hierarchy, so move
it back before anyone starts using it on ARM.

This reverts commit 948486544713492f00ac8a9572909101ea892cb0.

Signed-off-by: Arnd Bergmann 
---
This part of the series is not required for the eSDHC quirk,
but it restores the asm/fsl_guts.h header so it doesn't accidentally
get abused for this in the future. I found two drivers outside of
arch/powerpc that already accessed the registers directly, but the
functions look fairly contained, and can be easily hidden in an
#ifdef CONFIG_PPC

diff --git a/include/linux/fsl/guts.h b/arch/powerpc/include/asm/fsl_guts.h
similarity index 99%
rename from include/linux/fsl/guts.h
rename to arch/powerpc/include/asm/fsl_guts.h
index 649e9171a9b3..a67413c52701 100644
--- a/include/linux/fsl/guts.h
+++ b/arch/powerpc/include/asm/fsl_guts.h
@@ -12,10 +12,9 @@
  * option) any later version.
  */
 
-#ifndef __FSL_GUTS_H__
-#define __FSL_GUTS_H__
-
-#include 
+#ifndef __ASM_POWERPC_FSL_GUTS_H__
+#define __ASM_POWERPC_FSL_GUTS_H__
+#ifdef __KERNEL__
 
 /**
  * Global Utility Registers.
@@ -295,3 +294,4 @@ struct ccsr_rcpm_v2 {
 };
 
 #endif
+#endif
diff --git a/arch/powerpc/platforms/85xx/mpc85xx_mds.c 
b/arch/powerpc/platforms/85xx/mpc85xx_mds.c
index f61cbe235581..00f052e9f2a2 100644
--- a/arch/powerpc/platforms/85xx/mpc85xx_mds.c
+++ b/arch/powerpc/platforms/85xx/mpc85xx_mds.c
@@ -34,7 +34,6 @@
 #include 
 #include 
 #include 
-#include 
 
 #include 
 #include 
@@ -52,6 +51,7 @@
 #include 
 #include 
 #include 
+#include 
 #include "smp.h"
 
 #include "mpc85xx.h"
diff --git a/arch/powerpc/platforms/85xx/mpc85xx_pm_ops.c 
b/arch/powerpc/platforms/85xx/mpc85xx_pm_ops.c
index f05325f0cc03..a812c0511252 100644
--- a/arch/powerpc/platforms/85xx/mpc85xx_pm_ops.c
+++ b/arch/powerpc/platforms/85xx/mpc85xx_pm_ops.c
@@ -14,8 +14,8 @@
 #include 
 #include 
 #include 
-#include 
 
+#include 
 #include 
 #include 
 
diff --git a/arch/powerpc/platforms/85xx/mpc85xx_rdb.c 
b/arch/powerpc/platforms/85xx/mpc85xx_rdb.c
index 3f4dad18..453ddda00fce 100644
--- a/arch/powerpc/platforms/85xx/mpc85xx_rdb.c
+++ b/arch/powerpc/platforms/85xx/mpc85xx_rdb.c
@@ -17,7 +17,6 @@
 #include 
 #include 
 #include 
-#include 
 
 #include 
 #include 
@@ -28,6 +27,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
diff --git a/arch/powerpc/platforms/85xx/p1022_ds.c 
b/arch/powerpc/platforms/85xx/p1022_ds.c
index 371df822e88e..6ac986d3f8a3 100644
--- a/arch/powerpc/platforms/85xx/p1022_ds.c
+++ b/arch/powerpc/platforms/85xx/p1022_ds.c
@@ -16,7 +16,6 @@
  * kind, whether express or implied.
  */
 
-#include 
 #include 
 #include 
 #include 
@@ -26,6 +25,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include "smp.h"
 
diff --git a/arch/powerpc/platforms/85xx/p1022_rdk.c 
b/arch/powerpc/platforms/85xx/p1022_rdk.c
index 5087becaa8bc..680232d6ba48 100644
--- a/arch/powerpc/platforms/85xx/p1022_rdk.c
+++ b/arch/powerpc/platforms/85xx/p1022_rdk.c
@@ -12,7 +12,6 @@
  * kind, whether express or implied.
  */
 
-#include 
 #include 
 #include 
 #include 
@@ -22,6 +21,7 @@
 #include 
 #include 
 #include 
+#include 
 #include "smp.h"
 
 #include "mpc85xx.h"
diff --git a/arch/powerpc/platforms/85xx/smp.c 
b/arch/powerpc/platforms/85xx/smp.c
index fe9f19e5e935..6bd3a292e790 100644
--- a/arch/powerpc/platforms/85xx/smp.c
+++ b/arch/powerpc/platforms/85xx/smp.c
@@ -18,7 +18,6 @@
 #include 
 #include 
 #include 
-#include 
 
 #include 
 #include 
@@ -26,6 +25,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/arch/powerpc/platforms/85xx/twr_p102x.c 
b/arch/powerpc/platforms/85xx/twr_p102x.c
index 71bc255b4324..2cac45f72d24 100644
--- a/arch/powerpc/platforms/85xx/twr_p102x.c
+++ b/arch/powerpc/platforms/85xx/twr_p102x.c
@@ -15,7 +15,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 
@@ -24,6 +23,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
diff --git a/arch/powerpc/platforms/86xx/mpc8610_hpcd.c 
b/arch/powerpc/platforms/86xx/mpc8610_hpcd.c
index 957473e5c8e5..761c81476957 100644
--- a/arch/powerpc/platforms/86xx/mpc8610_hpcd.c
+++ b/arch/powerpc/platforms/86xx/mpc8610_hpcd.c
@@ -24,7 +24,6 @@
 #include 
 #include 
 #include 
-#include 
 
 #include 
 #include 
@@ -39,6 +38,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "mpc86xx.h"
 
diff --git a/arch/powerpc/sysdev/fsl_rcpm.c b/arch/powerpc/sysdev/fsl_rcpm.c
index 9259a94f70e1..8af22187cb25 100644
--- a/arch/powerpc/sysdev/fsl_rcpm.c
+++ b/arch/powerpc/sysdev/fsl_rcpm.c
@@ -19,7 +19,7 @@
 #include 
 
 #include 
-#include 
+#include 
 #include 
 #include 
 #include 
diff --git a/drivers/clk/clk-qoriq.c b/drivers/clk/clk-qoriq.c
index 58566a17944a..f311bd399672 100644
--- a/drivers/clk/clk-qoriq.c
+++ b/drivers/clk/clk-qoriq.c
@@ -12,7 +12,6 @@
 
 #include 
 #include 
-#include 
 #include 
 

[PATCH 3/4] mmc: sdhci-of-esdhc: fix host version for T4240-R1.0-R2.0

2016-05-30 Thread Arnd Bergmann
This is a rewrite of an earlier patch from Yangbo Lu, adding a quirk
for the NXP QorIQ T4240 in the detection of the host device version.

Unfortunately, this device cannot be detected using the compatible
string, as we have to support existing DTS files that use the generic
"fsl,t4240-esdhc" identifier but that have other host versions that
are correctly detected.

Signed-off-by: Arnd Bergmann 

diff --git a/drivers/mmc/host/sdhci-of-esdhc.c 
b/drivers/mmc/host/sdhci-of-esdhc.c
index 3f34d354f1fc..1d4814fe4cb2 100644
--- a/drivers/mmc/host/sdhci-of-esdhc.c
+++ b/drivers/mmc/host/sdhci-of-esdhc.c
@@ -73,14 +73,16 @@ static u32 esdhc_readl_fixup(struct sdhci_host *host,
 static u16 esdhc_readw_fixup(struct sdhci_host *host,
 int spec_reg, u32 value)
 {
+   struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
+   struct sdhci_esdhc *esdhc = sdhci_pltfm_priv(pltfm_host);
u16 ret;
int shift = (spec_reg & 0x2) * 8;
 
if (spec_reg == SDHCI_HOST_VERSION)
-   ret = value & 0x;
-   else
-   ret = (value >> shift) & 0x;
-   return ret;
+   return esdhc->vendor_ver << SDHCI_VENDOR_VER_SHIFT |
+  esdhc->spec_ver;
+
+   return (value >> shift) & 0x;
 }
 
 static u8 esdhc_readb_fixup(struct sdhci_host *host,
@@ -562,16 +564,32 @@ static const struct sdhci_pltfm_data sdhci_esdhc_le_pdata 
= {
.ops = _esdhc_le_ops,
 };
 
+#define T4240_HOST_VER ((VENDOR_V_23 << SDHCI_VENDOR_VER_SHIFT) | 
SDHCI_SPEC_200)
+static const struct soc_device_attribute esdhc_t4240_quirk = {
+   /* T4240 revision < 0x20 uses vendor version 23, SDHCI version 200 */
+   { .soc_id = "T4*(0x824000)", .revision = "0x[01]?",
+ .data = (void *)(uintptr_t)(T4240_HOST_VER) },
+   { },
+};
+
 static void esdhc_init(struct platform_device *pdev, struct sdhci_host *host)
 {
struct sdhci_pltfm_host *pltfm_host;
struct sdhci_esdhc *esdhc;
-   u16 host_ver;
 
pltfm_host = sdhci_priv(host);
esdhc = sdhci_pltfm_priv(pltfm_host);
 
host_ver = sdhci_readw(host, SDHCI_HOST_VERSION);
+
+   if (of_device_is_compatible(pdev->dev.of_node, "fsl,t4240-esdhc")) {
+   struct soc_device_attribute *match;
+
+   match = soc_device_match(_t4240_quirk);
+   if (match)
+   host_ver = (uintptr_t)match->data;
+   }
+
esdhc->vendor_ver = (host_ver & SDHCI_VENDOR_VER_MASK) >>
 SDHCI_VENDOR_VER_SHIFT;
esdhc->spec_ver = host_ver & SDHCI_SPEC_VER_MASK;



[PATCH 2/4] soc: fsl: add GUTS driver for QorIQ platforms

2016-05-30 Thread Arnd Bergmann
From: Yangbo Lu 

The global utilities block controls power management, I/O device
enabling, power-onreset(POR) configuration monitoring, alternate
function selection for multiplexed signals,and clock control.

This patch adds GUTS driver to manage and access global utilities
block.

[arnd turned this into a platform_driver registering a soc_device
 rather than providing an ad-hoc interface for soc-id]

Signed-off-by: Yangbo Lu 
Signed-off-by: Arnd Bergmann 

diff --git a/drivers/soc/Kconfig b/drivers/soc/Kconfig
index cb58ef0d9b2c..7106463f118e 100644
--- a/drivers/soc/Kconfig
+++ b/drivers/soc/Kconfig
@@ -2,7 +2,7 @@ menu "SOC (System On Chip) specific Drivers"
 
 source "drivers/soc/bcm/Kconfig"
 source "drivers/soc/brcmstb/Kconfig"
-source "drivers/soc/fsl/qe/Kconfig"
+source "drivers/soc/fsl/Kconfig"
 source "drivers/soc/mediatek/Kconfig"
 source "drivers/soc/qcom/Kconfig"
 source "drivers/soc/rockchip/Kconfig"
diff --git a/drivers/soc/fsl/Kconfig b/drivers/soc/fsl/Kconfig
new file mode 100644
index ..33d331cac8d6
--- /dev/null
+++ b/drivers/soc/fsl/Kconfig
@@ -0,0 +1,15 @@
+#
+# Freescale SOC drivers
+#
+
+source "drivers/soc/fsl/qe/Kconfig"
+
+config FSL_GUTS
+   bool "NXP Layerscale SoC identification"
+   depends on PPC_FSL || SOC_LS1021A || ARCH_LAYERSCAPE || COMPILE_TEST
+   default PPC_FSL || SOC_LS1021A || ARCH_LAYERSCAPE
+   select SOC_BUS
+   help
+ This registers a SoC device for NXP (formerly Freescale)
+ Layerscape devices, making information about the system
+ available in /sys/devices/soc/
diff --git a/drivers/soc/fsl/Makefile b/drivers/soc/fsl/Makefile
index 203307fd92c1..02afb7f980f6 100644
--- a/drivers/soc/fsl/Makefile
+++ b/drivers/soc/fsl/Makefile
@@ -4,3 +4,4 @@
 
 obj-$(CONFIG_QUICC_ENGINE) += qe/
 obj-$(CONFIG_CPM)  += qe/
+obj-$(CONFIG_FSL_GUTS) += guts.o
diff --git a/drivers/soc/fsl/guts.c b/drivers/soc/fsl/guts.c
new file mode 100644
index ..2f30698f5bcf
--- /dev/null
+++ b/drivers/soc/fsl/guts.c
@@ -0,0 +1,130 @@
+/*
+ * Freescale QorIQ Platforms GUTS Driver
+ *
+ * Copyright (C) 2016 Freescale Semiconductor, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define GUTS_PVR   0x0a0
+#define GUTS_SVR   0x0a4
+
+struct guts {
+   void __iomem *regs;
+   bool little_endian;
+   struct soc_device_attribute soc;
+};
+
+static u32 fsl_guts_get_svr(struct guts *guts)
+{
+   if (guts->little_endian)
+   return ioread32(guts->regs + GUTS_SVR);
+   else
+   return ioread32be(guts->regs + GUTS_SVR);
+}
+
+static u32 fsl_guts_get_pvr(struct guts *guts)
+{
+   if (guts->little_endian)
+   return ioread32(guts->regs + GUTS_PVR);
+   else
+   return ioread32be(guts->regs + GUTS_PVR);
+}
+
+/*
+ * Table for matching compatible strings, for device tree
+ * guts node, for Freescale QorIQ SOCs.
+ */
+static const struct of_device_id fsl_guts_of_match[] = {
+   /* For T4 & B4 Series SOCs */
+   { .compatible = "fsl,qoriq-device-config-1.0", .data = "T4/B4 series" },
+   /* For P Series SOCs */
+   { .compatible = "fsl,p1010-guts", .data = "P1010/P1014" },
+   { .compatible = "fsl,p1020-guts", .data = "P1020/P1011" },
+   { .compatible = "fsl,p1021-guts", .data = "P1021/P1012" },
+   { .compatible = "fsl,p1022-guts", .data = "P1022/P1013" },
+   { .compatible = "fsl,p1023-guts", .data = "P1013/P1017" },
+   { .compatible = "fsl,p2020-guts", .data = "P2010/P2020" },
+   { .compatible = "fsl,qoriq-device-config-2.0", .data = "P series" },
+   /* For BSC Series SOCs */
+   { .compatible = "fsl,bsc9131-guts", .data = "BSC9131 Qonverge" },
+   { .compatible = "fsl,bsc9132-guts", .data = "BSC9132 Qonverge" },
+   /* For MPC85xx Series SOCs */
+   { .compatible = "fsl,mpc8536-guts", .data = "PowerPC MPC8536" },
+   { .compatible = "fsl,mpc8544-guts", .data = "PowerPC MPC8544" },
+   { .compatible = "fsl,mpc8548-guts", .data = "PowerPC MPC8548" },
+   { .compatible = "fsl,mpc8568-guts", .data = "PowerPC MPC8568" },
+   { .compatible = "fsl,mpc8569-guts", .data = "PowerPC MPC8569" },
+   { .compatible = "fsl,mpc8572-guts", .data = "PowerPC MPC8572" },
+   /* For Layerscape Series SOCs */
+   { .compatible = "fsl,ls1021a-dcfg", .data = "Layerscape LS1021A" },
+   { .compatible = "fsl,ls1043a-dcfg", .data = "Layerscape LS1043A" },
+   { .compatible = "fsl,ls2080a-dcfg", .data = "Layerscape LS2080A" },
+   {}
+};
+
+static void fsl_guts_init(struct device *dev, 

[PATCH 1/4] base: soc: introduce soc_device_match() interface

2016-05-30 Thread Arnd Bergmann
We keep running into cases where device drivers want to know the exact
version of the SoC a they are currently running on. In the past, this
has usually been done through a vendor specific API that can be called
by a driver, or by directly accessing some kind of version register
that is not part of the device itself but that belongs to a global
register area of the chip.

Common reasons for doing this include:

- A machine is not using devicetree or similar for passing data
  about on-chip devices, but just announces their presence using
  boot-time platform devices, and the machine code itself does
  not care about the revision.

- There is existing firmware or boot loaders with existing DT
  binaries with generic compatible strings that do not identify
  the particular revision of each device, but the driver knows
  which SoC revisions include which part

- A prerelease version of a chip has some quirks and we are
  using the same version of the bootloader and the DT blob
  on both the prerelease and the final version. An update of
  the DT binding seems inappropriate because that would involve
  maintaining multiple copies of the dts and/or bootloader.

This introduces the soc_device_match() interface that is meant
to work like of_match_node() but instead of identifying the
version of a device, it identifies the SoC itself using a
vendor-agnostic interface.

Unlike soc_device_match(), we do not do an exact string compare
but instead use glob_match() to allow wildcards in strings.

Signed-off-by: Arnd Bergmann 

diff --git a/drivers/base/Kconfig b/drivers/base/Kconfig
index 246acdafedb6..fc7613cc7fd5 100644
--- a/drivers/base/Kconfig
+++ b/drivers/base/Kconfig
@@ -225,6 +225,7 @@ config GENERIC_CPU_AUTOPROBE
 
 config SOC_BUS
bool
+   select GLOB
 
 source "drivers/base/regmap/Kconfig"
 
diff --git a/drivers/base/soc.c b/drivers/base/soc.c
index 75b98aad6faf..e9623c6674a5 100644
--- a/drivers/base/soc.c
+++ b/drivers/base/soc.c
@@ -14,6 +14,7 @@
 #include 
 #include 
 #include 
+#include 
 
 static DEFINE_IDA(soc_ida);
 
@@ -168,3 +169,60 @@ static void __exit soc_bus_unregister(void)
bus_unregister(_bus_type);
 }
 module_exit(soc_bus_unregister);
+
+static int soc_device_match_one(struct device *dev, void *arg)
+{
+   struct soc_device *soc_dev = container_of(dev, struct soc_device, dev);
+   struct soc_device_attribute *match = arg;
+
+   if (match->machine && !glob_match(match->machine, 
soc_dev->attr->machine))
+   return 0;
+
+   if (match->family && !glob_match(match->family, soc_dev->attr->family))
+   return 0;
+
+   if (match->revision && !glob_match(match->revision, 
soc_dev->attr->revision))
+   return 0;
+
+   if (match->soc_id && !glob_match(match->soc_id, 
soc_dev->attr->revision))
+   return 0;
+
+   return 1;
+}
+
+/*
+ * soc_device_match - identify the SoC in the machine
+ * @matches: zero-terminated array of possible matches
+ *
+ * returns the first matching entry of the argument array, or NULL
+ * if none of them match.
+ *
+ * This function is meant as a helper in place of of_match_node()
+ * in cases where either no device tree is available or the information
+ * in a device node is insufficient to identify a particular variant
+ * by its compatible strings or other properties. For new devices,
+ * the DT binding should always provide unique compatible strings
+ * that allow the use of of_match_node() instead.
+ *
+ * The calling function can use the .data entry of the
+ * soc_device_attribute to pass a structure or function pointer for
+ * each entry.
+ */
+struct soc_device_attribute *soc_device_match(struct soc_device_attribute 
*matches)
+{
+   struct device *dev;
+   int ret;
+
+   for (ret = 0; ret == 0; matches++) {
+   if (matches->machine || matches->family ||
+   matches->revision || matches->soc_id)
+   return NULL;
+
+   dev = NULL;
+   ret = bus_for_each_dev(_bus_type, dev, matches,
+soc_device_match_one);
+   }
+
+   return matches;
+}
+EXPORT_SYMBOL_GPL(soc_device_match);
diff --git a/include/linux/sys_soc.h b/include/linux/sys_soc.h
index 2739ccb69571..02c48c76052b 100644
--- a/include/linux/sys_soc.h
+++ b/include/linux/sys_soc.h
@@ -13,6 +13,8 @@ struct soc_device_attribute {
const char *family;
const char *revision;
const char *soc_id;
+
+   const void *data;
 };
 
 /**
@@ -34,4 +36,6 @@ void soc_device_unregister(struct soc_device *soc_dev);
  */
 struct device *soc_device_to_device(struct soc_device *soc);
 
+struct soc_device_attribute *soc_device_match(struct soc_device_attribute 
*matches);
+
 #endif /* __SOC_BUS_H */



Re: [v10, 7/7] mmc: sdhci-of-esdhc: fix host version for T4240-R1.0-R2.0

2016-05-30 Thread Arnd Bergmann
On Thursday, May 26, 2016 9:44:10 AM CEST Ulf Hansson wrote:
> On 26 May 2016 at 06:05, Yangbo Lu  wrote:
> > Hi Uffe,
> >
> > Could we merge this patchset? ...
> > It has been a long time to wait for Arnd's response...
> >
> > Thanks a lot.
> >
> >
> 
> As we are still in the merge window I won't queue anything but fixes.
> Let's give Arnd another week or so to respond.

I've got a patch series now that implements a method for matching
the soc ID, see the following emails.

Arnd



[PATCH net] bnx2x: avoid leaking memory on bnx2x_init_one() failures

2016-05-30 Thread Vitaly Kuznetsov
bnx2x_init_bp() allocates memory with bnx2x_alloc_mem_bp() so if we
fail later in bnx2x_init_one() we need to free this memory
with bnx2x_free_mem_bp() to avoid leakages. E.g. I'm observing memory
leaks reported by kmemleak when a failure (unrelated) happens in
bnx2x_vfpf_acquire().

Signed-off-by: Vitaly Kuznetsov 
---
 drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c | 17 ++---
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c 
b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
index 0a5b770..c5fe9158 100644
--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
@@ -13941,14 +13941,14 @@ static int bnx2x_init_one(struct pci_dev *pdev,
bp->doorbells = bnx2x_vf_doorbells(bp);
rc = bnx2x_vf_pci_alloc(bp);
if (rc)
-   goto init_one_exit;
+   goto init_one_freemem;
} else {
doorbell_size = BNX2X_L2_MAX_CID(bp) * (1 << BNX2X_DB_SHIFT);
if (doorbell_size > pci_resource_len(pdev, 2)) {
dev_err(>pdev->dev,
"Cannot map doorbells, bar size too small, 
aborting\n");
rc = -ENOMEM;
-   goto init_one_exit;
+   goto init_one_freemem;
}
bp->doorbells = ioremap_nocache(pci_resource_start(pdev, 2),
doorbell_size);
@@ -13957,19 +13957,19 @@ static int bnx2x_init_one(struct pci_dev *pdev,
dev_err(>pdev->dev,
"Cannot map doorbell space, aborting\n");
rc = -ENOMEM;
-   goto init_one_exit;
+   goto init_one_freemem;
}
 
if (IS_VF(bp)) {
rc = bnx2x_vfpf_acquire(bp, tx_count, rx_count);
if (rc)
-   goto init_one_exit;
+   goto init_one_freemem;
}
 
/* Enable SRIOV if capability found in configuration space */
rc = bnx2x_iov_init_one(bp, int_mode, BNX2X_MAX_NUM_OF_VFS);
if (rc)
-   goto init_one_exit;
+   goto init_one_freemem;
 
/* calc qm_cid_count */
bp->qm_cid_count = bnx2x_set_qm_cid_count(bp);
@@ -13988,7 +13988,7 @@ static int bnx2x_init_one(struct pci_dev *pdev,
rc = bnx2x_set_int_mode(bp);
if (rc) {
dev_err(>dev, "Cannot set interrupts\n");
-   goto init_one_exit;
+   goto init_one_freemem;
}
BNX2X_DEV_INFO("set interrupts successfully\n");
 
@@ -13996,7 +13996,7 @@ static int bnx2x_init_one(struct pci_dev *pdev,
rc = register_netdev(dev);
if (rc) {
dev_err(>dev, "Cannot register net device\n");
-   goto init_one_exit;
+   goto init_one_freemem;
}
BNX2X_DEV_INFO("device name after netdev register %s\n", dev->name);
 
@@ -14029,6 +14029,9 @@ static int bnx2x_init_one(struct pci_dev *pdev,
 
return 0;
 
+init_one_freemem:
+   bnx2x_free_mem_bp(bp);
+
 init_one_exit:
bnx2x_disable_pcie_error_reporting(bp);
 
-- 
2.5.5



[PATCH v3 net-next 10/13] net: hns: dsaf adds support of acpi

2016-05-30 Thread Yisen Zhuang
From: Kejian Yan 

Dsaf needs to get configuration parameter by ACPI, so this patch add
support of ACPI.

Signed-off-by: Kejian Yan 
Reviewed-by: Andy Shevchenko 
Signed-off-by: Yisen Zhuang 
---
change log:
 v3:
  add Reviewed-by: Andy Shevchenko

 v2:
  1. use dev_of_node() instead of IS_ENABLED() to check if it is in
DT case,
  2. split a new patch to implement misc operation method,
  3. use acpi_dev_found() instead of acpi_match_device_ids() to
check which hw version it is,
  4. use is_acpi_node instead of ACPI_COMPANION to check if it is
work in ACPI case.
  link: https://lkml.org/lkml/2016/5/29/181

 v1: first submit
  link: https://lkml.org/lkml/2016/5/13/108
---
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c  | 80 ++--
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c | 85 +++---
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c | 32 
 3 files changed, 114 insertions(+), 83 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c 
b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c
index 2ebf14a..3ef0c9b 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c
@@ -689,9 +689,7 @@ static int  hns_mac_get_info(struct hns_mac_cb *mac_cb)
return 0;
}
 
-   if (!is_of_node(mac_cb->fw_port))
-   return -EINVAL;
-
+   if (is_of_node(mac_cb->fw_port)) {
/* parse property from port subnode in dsaf */
np = of_parse_phandle(to_of_node(mac_cb->fw_port), "phy-handle", 0);
mac_cb->phy_dev = of_phy_find_device(np);
@@ -701,47 +699,49 @@ static int  hns_mac_get_info(struct hns_mac_cb *mac_cb)
mac_cb->mac_id, np->name);
}
 
-   syscon = syscon_node_to_regmap(
-   of_parse_phandle(to_of_node(mac_cb->fw_port),
-"serdes-syscon", 0));
-   if (IS_ERR_OR_NULL(syscon)) {
-   dev_err(mac_cb->dev, "serdes-syscon is needed!\n");
-   return -EINVAL;
-   }
-   mac_cb->serdes_ctrl = syscon;
-
-   ret = fwnode_property_read_u32(mac_cb->fw_port,
-  "port-rst-offset",
-  _cb->port_rst_off);
-   if (ret) {
-   dev_dbg(mac_cb->dev,
-   "mac%d port-rst-offset not found, use default value.\n",
-   mac_cb->mac_id);
-   }
+   syscon = syscon_node_to_regmap(
+   of_parse_phandle(to_of_node(mac_cb->fw_port),
+"serdes-syscon", 0));
+   if (IS_ERR_OR_NULL(syscon)) {
+   dev_err(mac_cb->dev, "serdes-syscon is needed!\n");
+   return -EINVAL;
+   }
+   mac_cb->serdes_ctrl = syscon;
 
-   ret = fwnode_property_read_u32(mac_cb->fw_port,
-  "port-mode-offset",
-  _cb->port_mode_off);
-   if (ret) {
-   dev_dbg(mac_cb->dev,
-   "mac%d port-mode-offset not found, use default 
value.\n",
-   mac_cb->mac_id);
-   }
+   ret = fwnode_property_read_u32(mac_cb->fw_port,
+  "port-rst-offset",
+  _cb->port_rst_off);
+   if (ret) {
+   dev_dbg(mac_cb->dev,
+   "mac%d port-rst-offset not found, use default 
value.\n",
+   mac_cb->mac_id);
+   }
 
-   ret = of_parse_phandle_with_fixed_args(to_of_node(mac_cb->fw_port),
-  "cpld-syscon", 1, 0, _args);
-   if (ret) {
-   dev_dbg(mac_cb->dev, "mac%d no cpld-syscon found.\n",
-   mac_cb->mac_id);
-   mac_cb->cpld_ctrl = NULL;
-   } else {
-   syscon = syscon_node_to_regmap(cpld_args.np);
-   if (IS_ERR_OR_NULL(syscon)) {
-   dev_dbg(mac_cb->dev, "no cpld-syscon found!\n");
+   ret = fwnode_property_read_u32(mac_cb->fw_port,
+  "port-mode-offset",
+  _cb->port_mode_off);
+   if (ret) {
+   dev_dbg(mac_cb->dev,
+   "mac%d port-mode-offset not found, use default 
value.\n",
+   mac_cb->mac_id);
+   }
+
+   ret = of_parse_phandle_with_fixed_args(
+   to_of_node(mac_cb->fw_port), "cpld-syscon", 1, 0,
+   _args);
+   if (ret) {
+   

[PATCH v3 net-next 00/13] net: hns: add support of ACPI

2016-05-30 Thread Yisen Zhuang
From: Kejian Yan 

This series adds HNS support of acpi. The routine will call some ACPI
helper functions, like acpi_dev_found() and acpi_evaluate_dsm(), which
are not included in other cases. In order to make system compile
successfully in other cases except ACPI, it needs to add relative stub
functions to linux/acpi.h. And we use device property functions instead
of serial helper functions to suport both DT and ACPI cases. And then
add the supports of ACPI for HNS.

change log:
 v2->v3:
 1. add Review-by: Andy Shevchenko
 2. fix the potential memory leak

 v1 -> v2:
 1. use acpi_dev_found() instead of acpi_match_device_ids() to check if
it is a acpi node.
 2. use is_of_node() instead of IS_ENABLED() to check if it is a DT node.
 3. split the patch("add support of acpi for hns-mdio") into two patches:
3.1 Move to use fwnode_handle
3.2 Add ACPI
 4. add the patch which subject is dsaf misc operation method
 5. fix the comments by Andy Shevchenko

Kejian Yan (13):
  ACPI: bus: add stub acpi_dev_found() to linux/acpi.h
  ACPI: bus: add stub acpi_evaluate_dsm() to linux/acpi.h
  net: hisilicon: cleanup to prepare for other cases
  net: hisilicon: add support of acpi for hns-mdio
  net: hns: use device_* APIs instead of of_* APIs
  net: hns: use platform_get_irq instead of irq_of_parse_and_map
  net: hns: enet specify a reference to dsaf by fwnode_handle
  net: hns: add uniform interface for phy connection
  net: hns: add dsaf misc operation method
  net: hns: dsaf adds support of acpi
  net: hns: register phy device in each mac initial sequence
  net: hns: implement the miscellaneous operation by asl
  net: hns: net: hns: enet adds support of acpi

 drivers/net/ethernet/hisilicon/hns/hnae.c  |  18 +-
 drivers/net/ethernet/hisilicon/hns/hnae.h  |   5 +-
 drivers/net/ethernet/hisilicon/hns/hns_ae_adapt.c  |   6 +-
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_gmac.c |   6 +-
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c  | 247 +++-
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.h  |   4 +-
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c | 105 ++---
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.h |  33 ++-
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c | 254 ++---
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.h |   7 +-
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_ppe.c  |  15 +-
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_rcb.c  |   5 +-
 .../net/ethernet/hisilicon/hns/hns_dsaf_xgmac.c|  10 +-
 drivers/net/ethernet/hisilicon/hns/hns_enet.c  |  90 +---
 drivers/net/ethernet/hisilicon/hns/hns_enet.h  |   2 +-
 drivers/net/ethernet/hisilicon/hns/hns_ethtool.c   |   2 +-
 drivers/net/ethernet/hisilicon/hns_mdio.c  | 147 +++-
 include/linux/acpi.h   |  13 ++
 18 files changed, 714 insertions(+), 255 deletions(-)

-- 
1.9.1



[PATCH v3 net-next 01/13] ACPI: bus: add stub acpi_dev_found() to linux/acpi.h

2016-05-30 Thread Yisen Zhuang
From: Kejian Yan 

acpi_dev_found() will be used to detect if a given ACPI device is in the
system. It will be compiled in non-ACPI case, but the function is in
acpi_bus.h and acpi_bus.h can only be used in ACPI case, so this patch add
the stub function to linux/acpi.h to make compiled successfully in
non-ACPI cases.

Cc: Rafael J. Wysocki 
Signed-off-by: Kejian Yan 
Signed-off-by: Yisen Zhuang 
---
 include/linux/acpi.h | 5 +
 1 file changed, 5 insertions(+)

diff --git a/include/linux/acpi.h b/include/linux/acpi.h
index 288fac5..3025d19 100644
--- a/include/linux/acpi.h
+++ b/include/linux/acpi.h
@@ -543,6 +543,11 @@ struct platform_device *acpi_create_platform_device(struct 
acpi_device *);
 
 struct fwnode_handle;
 
+static inline bool acpi_dev_found(const char *hid)
+{
+   return false;
+}
+
 static inline bool is_acpi_node(struct fwnode_handle *fwnode)
 {
return false;
-- 
1.9.1



[PATCH v3 net-next 08/13] net: hns: add uniform interface for phy connection

2016-05-30 Thread Yisen Zhuang
From: Kejian Yan 

As device_node is only used by DT case, HNS needs to treat the other
cases including ACPI. It needs to use uniform ways to handle both of
DT and ACPI. This patch chooses phy_device, and of_phy_connect and
of_phy_attach are only used by DT case. It needs to use uniform interface
to handle that sequence by both DT and ACPI.

Signed-off-by: Kejian Yan 
Reviewed-by: Andy Shevchenko 
Signed-off-by: Yisen Zhuang 
---
change log:
 v3:
   add Reviewed-by: Andy Shevchenko

 v2:
  1. remove the redundant functions, and
  2. adds fwnode match method beside DT and ACPI.
  link: https://lkml.org/lkml/2016/5/29/175

 v1: first submit
  link: https://lkml.org/lkml/2016/5/13/100
---
 drivers/net/ethernet/hisilicon/hns/hnae.c  |  8 -
 drivers/net/ethernet/hisilicon/hns/hnae.h  |  3 +-
 drivers/net/ethernet/hisilicon/hns/hns_ae_adapt.c  |  2 +-
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c  | 34 +++---
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.h  |  2 +-
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c |  2 +-
 drivers/net/ethernet/hisilicon/hns/hns_enet.c  | 21 +++--
 drivers/net/ethernet/hisilicon/hns/hns_ethtool.c   |  2 +-
 8 files changed, 49 insertions(+), 25 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns/hnae.c 
b/drivers/net/ethernet/hisilicon/hns/hnae.c
index d630acd..5d3047c 100644
--- a/drivers/net/ethernet/hisilicon/hns/hnae.c
+++ b/drivers/net/ethernet/hisilicon/hns/hnae.c
@@ -96,7 +96,13 @@ static int __ae_match(struct device *dev, const void *data)
 {
struct hnae_ae_dev *hdev = cls_to_ae_dev(dev);
 
-   return (data == >dev->of_node->fwnode);
+   if (dev_of_node(hdev->dev))
+   return (data == >dev->of_node->fwnode);
+   else if (is_acpi_node(hdev->dev->fwnode))
+   return (data == hdev->dev->fwnode);
+
+   dev_err(dev, "__ae_match cannot read cfg data from OF or acpi\n");
+   return 0;
 }
 
 static struct hnae_ae_dev *find_ae(const struct fwnode_handle *fwnode)
diff --git a/drivers/net/ethernet/hisilicon/hns/hnae.h 
b/drivers/net/ethernet/hisilicon/hns/hnae.h
index f5f8140..529cb13 100644
--- a/drivers/net/ethernet/hisilicon/hns/hnae.h
+++ b/drivers/net/ethernet/hisilicon/hns/hnae.h
@@ -27,6 +27,7 @@
  * "cb" means control block
  */
 
+#include 
 #include 
 #include 
 #include 
@@ -512,7 +513,7 @@ struct hnae_ae_dev {
 struct hnae_handle {
struct device *owner_dev; /* the device which make use of this handle */
struct hnae_ae_dev *dev;  /* the device who provides this handle */
-   struct device_node *phy_node;
+   struct phy_device *phy_dev;
phy_interface_t phy_if;
u32 if_support;
int q_num;
diff --git a/drivers/net/ethernet/hisilicon/hns/hns_ae_adapt.c 
b/drivers/net/ethernet/hisilicon/hns/hns_ae_adapt.c
index 7a757e8..8e009f4 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_ae_adapt.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_ae_adapt.c
@@ -131,7 +131,7 @@ struct hnae_handle *hns_ae_get_handle(struct hnae_ae_dev 
*dev,
vf_cb->mac_cb = dsaf_dev->mac_cb[port_id];
 
ae_handle->phy_if = vf_cb->mac_cb->phy_if;
-   ae_handle->phy_node = vf_cb->mac_cb->phy_node;
+   ae_handle->phy_dev = vf_cb->mac_cb->phy_dev;
ae_handle->if_support = vf_cb->mac_cb->if_support;
ae_handle->port_type = vf_cb->mac_cb->mac_type;
ae_handle->dport_id = port_id;
diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c 
b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c
index 611581f..527b49d 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c
@@ -15,7 +15,8 @@
 #include 
 #include 
 #include 
-#include 
+#include 
+#include 
 #include 
 
 #include "hns_dsaf_main.h"
@@ -645,7 +646,7 @@ free_mac_drv:
  */
 static int  hns_mac_get_info(struct hns_mac_cb *mac_cb)
 {
-   struct device_node *np = mac_cb->dev->of_node;
+   struct device_node *np;
struct regmap *syscon;
struct of_phandle_args cpld_args;
u32 ret;
@@ -672,21 +673,34 @@ static int  hns_mac_get_info(struct hns_mac_cb *mac_cb)
 * from dsaf node
 */
if (!mac_cb->fw_port) {
-   mac_cb->phy_node = of_parse_phandle(np, "phy-handle",
-   mac_cb->mac_id);
-   if (mac_cb->phy_node)
+   np = of_parse_phandle(mac_cb->dev->of_node, "phy-handle",
+ mac_cb->mac_id);
+   mac_cb->phy_dev = of_phy_find_device(np);
+   if (mac_cb->phy_dev) {
+   /* refcount is held by of_phy_find_device()
+* if the phy_dev is found
+*/
+   put_device(_cb->phy_dev->mdio.dev);
+

[PATCH v3 net-next 02/13] ACPI: bus: add stub acpi_evaluate_dsm() to linux/acpi.h

2016-05-30 Thread Yisen Zhuang
From: Kejian Yan 

acpi_evaluate_dsm() will be used to handle the _DSM method in ACPI case.
It will be compiled in non-ACPI case, but the function is in acpi_bus.h
and acpi_bus.h can only be used in ACPI case, so this patch add the stub
function to linux/acpi.h to make compiled successfully in non-ACPI cases.

Cc: Rafael J. Wysocki 
Signed-off-by: Kejian Yan 
Signed-off-by: Yisen Zhuang 
---
 include/linux/acpi.h | 8 
 1 file changed, 8 insertions(+)

diff --git a/include/linux/acpi.h b/include/linux/acpi.h
index 3025d19..4d4bb49 100644
--- a/include/linux/acpi.h
+++ b/include/linux/acpi.h
@@ -659,6 +659,14 @@ static inline bool acpi_driver_match_device(struct device 
*dev,
return false;
 }
 
+static inline union acpi_object *acpi_evaluate_dsm(acpi_handle handle,
+  const u8 *uuid,
+  int rev, int func,
+  union acpi_object *argv4)
+{
+   return NULL;
+}
+
 static inline int acpi_device_uevent_modalias(struct device *dev,
struct kobj_uevent_env *env)
 {
-- 
1.9.1



[PATCH v3 net-next 06/13] net: hns: use platform_get_irq instead of irq_of_parse_and_map

2016-05-30 Thread Yisen Zhuang
From: Kejian Yan 

As irq_of_parse_and_map is only used by DT case, it is excepted to use
a uniform interface. So it is used platform_get_irq() instead.

Signed-off-by: Kejian Yan 
Signed-off-by: Yisen Zhuang 
---
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_rcb.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_rcb.c 
b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_rcb.c
index 4ef6d23..3ce2409 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_rcb.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_rcb.c
@@ -458,7 +458,6 @@ void hns_rcb_get_cfg(struct rcb_common_cb *rcb_common)
u32 i;
u32 ring_num = rcb_common->ring_num;
int base_irq_idx = hns_rcb_get_base_irq_idx(rcb_common);
-   struct device_node *np = rcb_common->dsaf_dev->dev->of_node;
struct platform_device *pdev =
to_platform_device(rcb_common->dsaf_dev->dev);
bool is_ver1 = AE_IS_VER1(rcb_common->dsaf_dev->dsaf_ver);
@@ -473,10 +472,10 @@ void hns_rcb_get_cfg(struct rcb_common_cb *rcb_common)
ring_pair_cb->port_id_in_comm =
hns_rcb_get_port_in_comm(rcb_common, i);
ring_pair_cb->virq[HNS_RCB_IRQ_IDX_TX] =
-   is_ver1 ? irq_of_parse_and_map(np, base_irq_idx + i * 2) :
+   is_ver1 ? platform_get_irq(pdev, base_irq_idx + i * 2) :
  platform_get_irq(pdev, base_irq_idx + i * 3 + 1);
ring_pair_cb->virq[HNS_RCB_IRQ_IDX_RX] =
-   is_ver1 ? irq_of_parse_and_map(np, base_irq_idx + i * 2 + 1) :
+   is_ver1 ? platform_get_irq(pdev, base_irq_idx + i * 2 + 1) :
  platform_get_irq(pdev, base_irq_idx + i * 3);
ring_pair_cb->q.phy_base =
RCB_COMM_BASE_TO_RING_BASE(rcb_common->phy_base, i);
-- 
1.9.1



[PATCH v3 net-next 04/13] net: hisilicon: add support of acpi for hns-mdio

2016-05-30 Thread Yisen Zhuang
From: Kejian Yan 

hns-mdio needs to register itself to mii-bus. The info of the device can
be read by both DT and ACPI.
HNS tries to call Linux PHY driver to help access PHY-devices, the HNS
hardware topology is as below. The MDIO controller may control several
PHY-devices, and each PHY-device connects to a MAC device. The MDIO will
be registered to mdiobus, then PHY-devices will register when each mac
find PHY device.
   cpu
|
|
 ---
|   |   |
|   |   |
|  dsaf |
   MDIO |  MDIO
|  ---  |
| | | |   | |
| | | |   | |
|MAC   MAC   MAC MAC|
| | | |   | |
  | | |   | 
 ||||||   ||
 PHY   PHY   PHY PHY

And the driver can handle reset sequence by _RST method in DSDT in ACPI
case.

Signed-off-by: Kejian Yan 
Reviewed-by: Andy Shevchenko 
Signed-off-by: Yisen Zhuang 
---
change log:
 v3:
add Reviewed-by: Andy Shevchenko
 v2:
1. use dev_of_node instead of IS_ENABLED macro
2. Add ACPI bits
Link: https://lkml.org/lkml/2016/5/29/185

 v1: first submit
Link: https://lkml.org/lkml/2016/5/13/93
---
 drivers/net/ethernet/hisilicon/hns_mdio.c | 107 +++---
 1 file changed, 69 insertions(+), 38 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns_mdio.c 
b/drivers/net/ethernet/hisilicon/hns_mdio.c
index 381cf0a..f78286c 100644
--- a/drivers/net/ethernet/hisilicon/hns_mdio.c
+++ b/drivers/net/ethernet/hisilicon/hns_mdio.c
@@ -7,6 +7,7 @@
  * (at your option) any later version.
  */
 
+#include 
 #include 
 #include 
 #include 
@@ -354,48 +355,60 @@ static int hns_mdio_reset(struct mii_bus *bus)
struct hns_mdio_device *mdio_dev = (struct hns_mdio_device *)bus->priv;
int ret;
 
-   if (!dev_of_node(bus->parent))
-   return -ENOTSUPP;
+   if (dev_of_node(bus->parent)) {
+   if (!mdio_dev->subctrl_vbase) {
+   dev_err(>dev, "mdio sys ctl reg has not maped\n");
+   return -ENODEV;
+   }
 
-   if (!mdio_dev->subctrl_vbase) {
-   dev_err(>dev, "mdio sys ctl reg has not maped\n");
-   return -ENODEV;
-   }
+   /* 1. reset req, and read reset st check */
+   ret = mdio_sc_cfg_reg_write(mdio_dev, MDIO_SC_RESET_REQ, 0x1,
+   MDIO_SC_RESET_ST, 0x1,
+   MDIO_CHECK_SET_ST);
+   if (ret) {
+   dev_err(>dev, "MDIO reset fail\n");
+   return ret;
+   }
 
-   /*1. reset req, and read reset st check*/
-   ret = mdio_sc_cfg_reg_write(mdio_dev, MDIO_SC_RESET_REQ, 0x1,
-   MDIO_SC_RESET_ST, 0x1,
-   MDIO_CHECK_SET_ST);
-   if (ret) {
-   dev_err(>dev, "MDIO reset fail\n");
-   return ret;
-   }
+   /* 2. dis clk, and read clk st check */
+   ret = mdio_sc_cfg_reg_write(mdio_dev, MDIO_SC_CLK_DIS,
+   0x1, MDIO_SC_CLK_ST, 0x1,
+   MDIO_CHECK_CLR_ST);
+   if (ret) {
+   dev_err(>dev, "MDIO dis clk fail\n");
+   return ret;
+   }
 
-   /*2. dis clk, and read clk st check*/
-   ret = mdio_sc_cfg_reg_write(mdio_dev, MDIO_SC_CLK_DIS,
-   0x1, MDIO_SC_CLK_ST, 0x1,
-   MDIO_CHECK_CLR_ST);
-   if (ret) {
-   dev_err(>dev, "MDIO dis clk fail\n");
-   return ret;
-   }
+   /* 3. reset dreq, and read reset st check */
+   ret = mdio_sc_cfg_reg_write(mdio_dev, MDIO_SC_RESET_DREQ, 0x1,
+   MDIO_SC_RESET_ST, 0x1,
+   MDIO_CHECK_CLR_ST);
+   if (ret) {
+   dev_err(>dev, "MDIO dis clk fail\n");
+   return ret;
+   }
 
-   /*3. reset dreq, and read reset st check*/
-   ret = mdio_sc_cfg_reg_write(mdio_dev, MDIO_SC_RESET_DREQ, 0x1,
-   MDIO_SC_RESET_ST, 0x1,
-   MDIO_CHECK_CLR_ST);
-   if (ret) {
-   dev_err(>dev, "MDIO dis clk fail\n");
-   return ret;

[PATCH v3 net-next 11/13] net: hns: register phy device in each mac initial sequence

2016-05-30 Thread Yisen Zhuang
From: Kejian Yan 

In ACPI case, there is no interface to register phy device to mdio-bus.
Phy device has to be registered itself to mdio-bus, and then enet can
get the phy device's info so that it can config the phy-device to help
to trasmit and receive data.
HNS hardware topology is as below. The MDIO controller may control several
PHY-devices, and each PHY-device connects to a MAC device. PHY-devices
will register when each mac find PHY device in initial sequence.

   cpu
|
|
 ---
|   |   |
|   |   |
|  dsaf |
   MDIO |  MDIO
|  ---  |
| | | |   | |
| | | |   | |
|MAC   MAC   MAC MAC|
| | | |   | |
  | | |   | 
 ||||||   ||
 PHY   PHY   PHY PHY

Signed-off-by: Kejian Yan 
Signed-off-by: Yisen Zhuang 
---
change log:
 v2: fix the build error by kbuild test robot

 v1: first submit
  link: https://lkml.org/lkml/2016/5/13/97
---
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c | 133 --
 1 file changed, 126 insertions(+), 7 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c 
b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c
index 3ef0c9b..c526558 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c
@@ -7,6 +7,7 @@
  * (at your option) any later version.
  */
 
+#include 
 #include 
 #include 
 #include 
@@ -638,6 +639,115 @@ free_mac_drv:
return ret;
 }
 
+static int
+hns_mac_phy_parse_addr(struct device *dev, struct fwnode_handle *fwnode)
+{
+   u32 addr;
+   int ret;
+
+   ret = fwnode_property_read_u32(fwnode, "phy-addr", );
+   if (ret) {
+   dev_err(dev, "has invalid PHY address ret:%d\n", ret);
+   return ret;
+   }
+
+   if (addr >= PHY_MAX_ADDR) {
+   dev_err(dev, "PHY address %i is too large\n", addr);
+   return -EINVAL;
+   }
+
+   return addr;
+}
+
+static int hns_mac_phydev_match(struct device *dev, void *fwnode)
+{
+   return dev->fwnode == fwnode;
+}
+
+static struct
+platform_device *hns_mac_find_platform_device(struct fwnode_handle *fwnode)
+{
+   struct device *dev;
+
+   dev = bus_find_device(_bus_type, NULL,
+ fwnode, hns_mac_phydev_match);
+   return dev ? to_platform_device(dev) : NULL;
+}
+
+static int
+hns_mac_register_phydev(struct mii_bus *mdio, struct hns_mac_cb *mac_cb,
+   u32 addr)
+{
+   struct phy_device *phy;
+   const char *phy_type;
+   bool is_c45;
+   int rc;
+
+   rc = fwnode_property_read_string(mac_cb->fw_port,
+"phy-mode", _type);
+   if (rc < 0)
+   return rc;
+
+   if (!strcmp(phy_type, phy_modes(PHY_INTERFACE_MODE_XGMII)))
+   is_c45 = 1;
+   else if (!strcmp(phy_type, phy_modes(PHY_INTERFACE_MODE_SGMII)))
+   is_c45 = 0;
+   else
+   return -ENODATA;
+
+   phy = get_phy_device(mdio, addr, is_c45);
+   if (!phy || IS_ERR(phy))
+   return -EIO;
+
+   if (mdio->irq)
+   phy->irq = mdio->irq[addr];
+
+   /* All data is now stored in the phy struct;
+* register it
+*/
+   rc = phy_device_register(phy);
+   if (rc) {
+   phy_device_free(phy);
+   return -ENODEV;
+   }
+
+   mac_cb->phy_dev = phy;
+
+   dev_dbg(>dev, "registered phy at address %i\n", addr);
+
+   return 0;
+}
+
+static void hns_mac_register_phy(struct hns_mac_cb *mac_cb)
+{
+   struct acpi_reference_args args;
+   struct platform_device *pdev;
+   struct mii_bus *mii_bus;
+   int rc;
+   int addr;
+
+   /* Loop over the child nodes and register a phy_device for each one */
+   if (!to_acpi_device_node(mac_cb->fw_port))
+   return;
+
+   rc = acpi_node_get_property_reference(
+   mac_cb->fw_port, "mdio-node", 0, );
+   if (rc)
+   return;
+
+   addr = hns_mac_phy_parse_addr(mac_cb->dev, mac_cb->fw_port);
+   if (addr < 0)
+   return;
+
+   /* dev address in adev */
+   pdev = hns_mac_find_platform_device(acpi_fwnode_handle(args.adev));
+   mii_bus = platform_get_drvdata(pdev);
+   rc = hns_mac_register_phydev(mii_bus, mac_cb, addr);
+   if (!rc)
+   dev_dbg(mac_cb->dev, "mac%d register phy addr:%d\n",

[PATCH v3 net-next 05/13] net: hns: use device_* APIs instead of of_* APIs

2016-05-30 Thread Yisen Zhuang
From: Kejian Yan 

OF series functions can be used only for DT case. Use unified
device property function instead to support both DT and ACPI.

Signed-off-by: Kejian Yan 
Signed-off-by: Yisen Zhuang 
---
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c |  9 +
 drivers/net/ethernet/hisilicon/hns/hns_enet.c  | 11 +++
 2 files changed, 8 insertions(+), 12 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c 
b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c
index 1c2ddb2..9afc5e6 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c
@@ -50,7 +50,7 @@ int hns_dsaf_get_cfg(struct dsaf_device *dsaf_dev)
else
dsaf_dev->dsaf_ver = AE_VERSION_2;
 
-   ret = of_property_read_string(np, "mode", _str);
+   ret = device_property_read_string(dsaf_dev->dev, "mode", _str);
if (ret) {
dev_err(dsaf_dev->dev, "get dsaf mode fail, ret=%d!\n", ret);
return ret;
@@ -142,7 +142,7 @@ int hns_dsaf_get_cfg(struct dsaf_device *dsaf_dev)
}
}
 
-   ret = of_property_read_u32(np, "desc-num", _num);
+   ret = device_property_read_u32(dsaf_dev->dev, "desc-num", _num);
if (ret < 0 || desc_num < HNS_DSAF_MIN_DESC_CNT ||
desc_num > HNS_DSAF_MAX_DESC_CNT) {
dev_err(dsaf_dev->dev, "get desc-num(%d) fail, ret=%d!\n",
@@ -151,14 +151,15 @@ int hns_dsaf_get_cfg(struct dsaf_device *dsaf_dev)
}
dsaf_dev->desc_num = desc_num;
 
-   ret = of_property_read_u32(np, "reset-field-offset", _offset);
+   ret = device_property_read_u32(dsaf_dev->dev, "reset-field-offset",
+  _offset);
if (ret < 0) {
dev_dbg(dsaf_dev->dev,
"get reset-field-offset fail, ret=%d!\r\n", ret);
}
dsaf_dev->reset_offset = reset_offset;
 
-   ret = of_property_read_u32(np, "buf-size", _size);
+   ret = device_property_read_u32(dsaf_dev->dev, "buf-size", _size);
if (ret < 0) {
dev_err(dsaf_dev->dev,
"get buf-size fail, ret=%d!\r\n", ret);
diff --git a/drivers/net/ethernet/hisilicon/hns/hns_enet.c 
b/drivers/net/ethernet/hisilicon/hns/hns_enet.c
index e621636..8851420 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_enet.c
@@ -1067,13 +1067,8 @@ void hns_nic_update_stats(struct net_device *netdev)
 static void hns_init_mac_addr(struct net_device *ndev)
 {
struct hns_nic_priv *priv = netdev_priv(ndev);
-   struct device_node *node = priv->dev->of_node;
-   const void *mac_addr_temp;
 
-   mac_addr_temp = of_get_mac_address(node);
-   if (mac_addr_temp && is_valid_ether_addr(mac_addr_temp)) {
-   memcpy(ndev->dev_addr, mac_addr_temp, ndev->addr_len);
-   } else {
+   if (!device_get_mac_address(priv->dev, ndev->dev_addr, ETH_ALEN)) {
eth_hw_addr_random(ndev);
dev_warn(priv->dev, "No valid mac, use random mac %pM",
 ndev->dev_addr);
@@ -1898,10 +1893,10 @@ static int hns_nic_dev_probe(struct platform_device 
*pdev)
goto out_read_prop_fail;
}
/* try to find port-idx-in-ae first */
-   ret = of_property_read_u32(node, "port-idx-in-ae", _id);
+   ret = device_property_read_u32(dev, "port-idx-in-ae", _id);
if (ret) {
/* only for old code compatible */
-   ret = of_property_read_u32(node, "port-id", _id);
+   ret = device_property_read_u32(dev, "port-id", _id);
if (ret)
goto out_read_prop_fail;
/* for old dts, we need to caculate the port offset */
-- 
1.9.1



[PATCH v3 net-next 13/13] net: hns: net: hns: enet adds support of acpi

2016-05-30 Thread Yisen Zhuang
From: Kejian Yan 

Enet needs to get configration parameter by acpi. This patch
adds support of ACPI for enet. The configuration parameter will
be configed in BIOS.

Signed-off-by: Kejian Yan 
Signed-off-by: Yisen Zhuang 
---
change log:
 v2:
 1. use acpi_dev_found() instead of acpi_match_device_ids()
 2. use is_acpi_node() to check if it works by ACPI case
 3. use dev_of_node() to check if it works by DT case

 v1: first submit
  link: https://lkml.org/lkml/2016/5/13/99
---
 drivers/net/ethernet/hisilicon/hns/hns_enet.c | 56 +--
 1 file changed, 44 insertions(+), 12 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns/hns_enet.c 
b/drivers/net/ethernet/hisilicon/hns/hns_enet.c
index 3ec3c27..ad742a6 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_enet.c
@@ -132,6 +132,13 @@ static void fill_v2_desc(struct hnae_ring *ring, void 
*priv,
ring_ptr_move_fw(ring, next_to_use);
 }
 
+static const struct acpi_device_id hns_enet_acpi_match[] = {
+   { "HISI00C1", 0 },
+   { "HISI00C2", 0 },
+   { },
+};
+MODULE_DEVICE_TABLE(acpi, hns_enet_acpi_match);
+
 static void fill_desc(struct hnae_ring *ring, void *priv,
  int size, dma_addr_t dma, int frag_end,
  int buf_num, enum hns_desc_type type, int mtu)
@@ -1870,7 +1877,6 @@ static int hns_nic_dev_probe(struct platform_device *pdev)
struct device *dev = >dev;
struct net_device *ndev;
struct hns_nic_priv *priv;
-   struct device_node *ae_node;
u32 port_id;
int ret;
 
@@ -1884,20 +1890,45 @@ static int hns_nic_dev_probe(struct platform_device 
*pdev)
priv->dev = dev;
priv->netdev = ndev;
 
-   if (of_device_is_compatible(dev->of_node, "hisilicon,hns-nic-v1"))
-   priv->enet_ver = AE_VERSION_1;
-   else
-   priv->enet_ver = AE_VERSION_2;
+   if (dev_of_node(dev)) {
+   struct device_node *ae_node;
 
-   ae_node = of_parse_phandle(dev->of_node, "ae-handle", 0);
-   if (IS_ERR_OR_NULL(ae_node)) {
-   ret = PTR_ERR(ae_node);
-   dev_err(dev, "not find ae-handle\n");
-   goto out_read_prop_fail;
+   if (of_device_is_compatible(dev->of_node,
+   "hisilicon,hns-nic-v1"))
+   priv->enet_ver = AE_VERSION_1;
+   else
+   priv->enet_ver = AE_VERSION_2;
+
+   ae_node = of_parse_phandle(dev->of_node, "ae-handle", 0);
+   if (IS_ERR_OR_NULL(ae_node)) {
+   ret = PTR_ERR(ae_node);
+   dev_err(dev, "not find ae-handle\n");
+   goto out_read_prop_fail;
+   }
+   priv->fwnode = _node->fwnode;
+   } else if (is_acpi_node(dev->fwnode)) {
+   struct acpi_reference_args args;
+
+   if (acpi_dev_found(hns_enet_acpi_match[0].id))
+   priv->enet_ver = AE_VERSION_1;
+   else if (acpi_dev_found(hns_enet_acpi_match[1].id))
+   priv->enet_ver = AE_VERSION_2;
+   else
+   return -ENXIO;
+
+   /* try to find port-idx-in-ae first */
+   ret = acpi_node_get_property_reference(dev->fwnode,
+  "ae-handle", 0, );
+   if (ret) {
+   dev_err(dev, "not find ae-handle\n");
+   goto out_read_prop_fail;
+   }
+   priv->fwnode = acpi_fwnode_handle(args.adev);
+   } else {
+   dev_err(dev, "cannot read cfg data from OF or acpi\n");
+   return -ENXIO;
}
-   priv->fwnode = _node->fwnode;
 
-   /* try to find port-idx-in-ae first */
ret = device_property_read_u32(dev, "port-idx-in-ae", _id);
if (ret) {
/* only for old code compatible */
@@ -2014,6 +2045,7 @@ static struct platform_driver hns_nic_dev_driver = {
.driver = {
.name = "hns-nic",
.of_match_table = hns_enet_of_match,
+   .acpi_match_table = ACPI_PTR(hns_enet_acpi_match),
},
.probe = hns_nic_dev_probe,
.remove = hns_nic_dev_remove,
-- 
1.9.1



[PATCH v3 net-next 07/13] net: hns: enet specify a reference to dsaf by fwnode_handle

2016-05-30 Thread Yisen Zhuang
From: Kejian Yan 

As device_node is only used by DT case, it is expected to find uniform
ways. So fwnode_handle is the suitable method.

Signed-off-by: Kejian Yan 
Reviewed-by: Andy Shevchenko 
Signed-off-by: Yisen Zhuang 
---
change log:
 v3: add Reviewed-by: Andy Shevchenko

 v2: remove the redundant line
  Link: https://lkml.org/lkml/2016/5/29/178

 v1: first submit
 link: https://lkml.org/lkml/2016/5/13/98
---
 drivers/net/ethernet/hisilicon/hns/hnae.c | 12 ++--
 drivers/net/ethernet/hisilicon/hns/hnae.h |  2 +-
 drivers/net/ethernet/hisilicon/hns/hns_enet.c | 14 --
 drivers/net/ethernet/hisilicon/hns/hns_enet.h |  2 +-
 4 files changed, 16 insertions(+), 14 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns/hnae.c 
b/drivers/net/ethernet/hisilicon/hns/hnae.c
index 3bfe36f..d630acd 100644
--- a/drivers/net/ethernet/hisilicon/hns/hnae.c
+++ b/drivers/net/ethernet/hisilicon/hns/hnae.c
@@ -96,16 +96,16 @@ static int __ae_match(struct device *dev, const void *data)
 {
struct hnae_ae_dev *hdev = cls_to_ae_dev(dev);
 
-   return hdev->dev->of_node == data;
+   return (data == >dev->of_node->fwnode);
 }
 
-static struct hnae_ae_dev *find_ae(const struct device_node *ae_node)
+static struct hnae_ae_dev *find_ae(const struct fwnode_handle *fwnode)
 {
struct device *dev;
 
-   WARN_ON(!ae_node);
+   WARN_ON(!fwnode);
 
-   dev = class_find_device(hnae_class, NULL, ae_node, __ae_match);
+   dev = class_find_device(hnae_class, NULL, fwnode, __ae_match);
 
return dev ? cls_to_ae_dev(dev) : NULL;
 }
@@ -312,7 +312,7 @@ EXPORT_SYMBOL(hnae_reinit_handle);
  * return handle ptr or ERR_PTR
  */
 struct hnae_handle *hnae_get_handle(struct device *owner_dev,
-   const struct device_node *ae_node,
+   const struct fwnode_handle  *fwnode,
u32 port_id,
struct hnae_buf_ops *bops)
 {
@@ -321,7 +321,7 @@ struct hnae_handle *hnae_get_handle(struct device 
*owner_dev,
int i, j;
int ret;
 
-   dev = find_ae(ae_node);
+   dev = find_ae(fwnode);
if (!dev)
return ERR_PTR(-ENODEV);
 
diff --git a/drivers/net/ethernet/hisilicon/hns/hnae.h 
b/drivers/net/ethernet/hisilicon/hns/hnae.h
index e8d36aa..f5f8140 100644
--- a/drivers/net/ethernet/hisilicon/hns/hnae.h
+++ b/drivers/net/ethernet/hisilicon/hns/hnae.h
@@ -528,7 +528,7 @@ struct hnae_handle {
 #define ring_to_dev(ring) ((ring)->q->dev->dev)
 
 struct hnae_handle *hnae_get_handle(struct device *owner_dev,
-   const struct device_node *ae_node,
+   const struct fwnode_handle  *fwnode,
u32 port_id,
struct hnae_buf_ops *bops);
 
diff --git a/drivers/net/ethernet/hisilicon/hns/hns_enet.c 
b/drivers/net/ethernet/hisilicon/hns/hns_enet.c
index 8851420..93f6ccb 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_enet.c
@@ -1807,7 +1807,7 @@ static int hns_nic_try_get_ae(struct net_device *ndev)
int ret;
 
h = hnae_get_handle(>netdev->dev,
-   priv->ae_node, priv->port_id, NULL);
+   priv->fwnode, priv->port_id, NULL);
if (IS_ERR_OR_NULL(h)) {
ret = -ENODEV;
dev_dbg(priv->dev, "has not handle, register notifier!\n");
@@ -1867,7 +1867,7 @@ static int hns_nic_dev_probe(struct platform_device *pdev)
struct device *dev = >dev;
struct net_device *ndev;
struct hns_nic_priv *priv;
-   struct device_node *node = dev->of_node;
+   struct device_node *ae_node;
u32 port_id;
int ret;
 
@@ -1881,17 +1881,19 @@ static int hns_nic_dev_probe(struct platform_device 
*pdev)
priv->dev = dev;
priv->netdev = ndev;
 
-   if (of_device_is_compatible(node, "hisilicon,hns-nic-v1"))
+   if (of_device_is_compatible(dev->of_node, "hisilicon,hns-nic-v1"))
priv->enet_ver = AE_VERSION_1;
else
priv->enet_ver = AE_VERSION_2;
 
-   priv->ae_node = (void *)of_parse_phandle(node, "ae-handle", 0);
-   if (IS_ERR_OR_NULL(priv->ae_node)) {
-   ret = PTR_ERR(priv->ae_node);
+   ae_node = of_parse_phandle(dev->of_node, "ae-handle", 0);
+   if (IS_ERR_OR_NULL(ae_node)) {
+   ret = PTR_ERR(ae_node);
dev_err(dev, "not find ae-handle\n");
goto out_read_prop_fail;
}
+   priv->fwnode = _node->fwnode;
+
/* try to find port-idx-in-ae first */
ret = device_property_read_u32(dev, "port-idx-in-ae", _id);
if (ret) {
diff --git 

[PATCH v3 net-next 12/13] net: hns: implement the miscellaneous operation by asl

2016-05-30 Thread Yisen Zhuang
From: Kejian Yan 

The miscellaneous operation is implemented in BIOS, the kernel can call
_DSM method help to call the implementation in ACPI case. Here is a patch
to do that.

Signed-off-by: Kejian Yan 
Reviewed-by: Andy Shevchenko 
Signed-off-by: Yisen Zhuang 
---
change log:
 v3: fix potential memory leak
 add Reviewed-by: Andy Shevchenko

 v2: use a serial function to implement the reset sequence
  link: https://lkml.org/lkml/2016/5/29/186

 v1: first submit
  link: https://lkml.org/lkml/2016/5/13/94
---
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c | 171 +
 1 file changed, 171 insertions(+)

diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c 
b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c
index f21177b..6a75d81 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c
@@ -12,6 +12,27 @@
 #include "hns_dsaf_ppe.h"
 #include "hns_dsaf_reg.h"
 
+enum _dsm_op_index {
+   HNS_OP_RESET_FUNC   = 0x1,
+   HNS_OP_SERDES_LP_FUNC   = 0x2,
+   HNS_OP_LED_SET_FUNC = 0x3,
+   HNS_OP_GET_PORT_TYPE_FUNC   = 0x4,
+   HNS_OP_GET_SFP_STAT_FUNC= 0x5,
+};
+
+enum _dsm_rst_type {
+   HNS_DSAF_RESET_FUNC = 0x1,
+   HNS_PPE_RESET_FUNC  = 0x2,
+   HNS_XGE_CORE_RESET_FUNC = 0x3,
+   HNS_XGE_RESET_FUNC  = 0x4,
+   HNS_GE_RESET_FUNC   = 0x5,
+};
+
+const u8 hns_dsaf_acpi_dsm_uuid[] = {
+   0x1A, 0xAA, 0x85, 0x1A, 0x93, 0xE2, 0x5E, 0x41,
+   0x8E, 0x28, 0x8D, 0x69, 0x0A, 0x0F, 0x82, 0x0A
+};
+
 static void dsaf_write_sub(struct dsaf_device *dsaf_dev, u32 reg, u32 val)
 {
if (dsaf_dev->sub_ctrl)
@@ -109,6 +130,34 @@ static int cpld_set_led_id(struct hns_mac_cb *mac_cb,
 
 #define RESET_REQ_OR_DREQ 1
 
+static void hns_dsaf_acpi_srst_by_port(struct dsaf_device *dsaf_dev, u8 
op_type,
+  u32 port_type, u32 port, u32 val)
+{
+   union acpi_object *obj;
+   union acpi_object obj_args[3], argv4;
+
+   obj_args[0].integer.type = ACPI_TYPE_INTEGER;
+   obj_args[0].integer.value = port_type;
+   obj_args[1].integer.type = ACPI_TYPE_INTEGER;
+   obj_args[1].integer.value = port;
+   obj_args[2].integer.type = ACPI_TYPE_INTEGER;
+   obj_args[2].integer.value = val;
+
+   argv4.type = ACPI_TYPE_PACKAGE;
+   argv4.package.count = 3;
+   argv4.package.elements = obj_args;
+
+   obj = acpi_evaluate_dsm(ACPI_HANDLE(dsaf_dev->dev),
+   hns_dsaf_acpi_dsm_uuid, 0, op_type, );
+   if (!obj) {
+   dev_warn(dsaf_dev->dev, "reset port_type%d port%d fail!",
+port_type, port);
+   return;
+   }
+
+   ACPI_FREE(obj);
+}
+
 static void hns_dsaf_rst(struct dsaf_device *dsaf_dev, bool dereset)
 {
u32 xbar_reg_addr;
@@ -126,6 +175,13 @@ static void hns_dsaf_rst(struct dsaf_device *dsaf_dev, 
bool dereset)
dsaf_write_sub(dsaf_dev, nt_reg_addr, RESET_REQ_OR_DREQ);
 }
 
+static void hns_dsaf_rst_acpi(struct dsaf_device *dsaf_dev, bool dereset)
+{
+   hns_dsaf_acpi_srst_by_port(dsaf_dev, HNS_OP_RESET_FUNC,
+  HNS_DSAF_RESET_FUNC,
+  0, dereset);
+}
+
 static void hns_dsaf_xge_srst_by_port(struct dsaf_device *dsaf_dev, u32 port,
  bool dereset)
 {
@@ -146,6 +202,13 @@ static void hns_dsaf_xge_srst_by_port(struct dsaf_device 
*dsaf_dev, u32 port,
dsaf_write_sub(dsaf_dev, reg_addr, reg_val);
 }
 
+static void hns_dsaf_xge_srst_by_port_acpi(struct dsaf_device *dsaf_dev,
+  u32 port, bool dereset)
+{
+   hns_dsaf_acpi_srst_by_port(dsaf_dev, HNS_OP_RESET_FUNC,
+  HNS_XGE_RESET_FUNC, port, dereset);
+}
+
 static void hns_dsaf_xge_core_srst_by_port(struct dsaf_device *dsaf_dev,
   u32 port, bool dereset)
 {
@@ -166,6 +229,14 @@ static void hns_dsaf_xge_core_srst_by_port(struct 
dsaf_device *dsaf_dev,
dsaf_write_sub(dsaf_dev, reg_addr, reg_val);
 }
 
+static void
+hns_dsaf_xge_core_srst_by_port_acpi(struct dsaf_device *dsaf_dev,
+   u32 port, bool dereset)
+{
+   hns_dsaf_acpi_srst_by_port(dsaf_dev, HNS_OP_RESET_FUNC,
+  HNS_XGE_CORE_RESET_FUNC, port, dereset);
+}
+
 static void hns_dsaf_ge_srst_by_port(struct dsaf_device *dsaf_dev, u32 port,
 bool dereset)
 {
@@ -218,6 +289,13 @@ static void hns_dsaf_ge_srst_by_port(struct dsaf_device 
*dsaf_dev, u32 port,
}
 }
 
+static void hns_dsaf_ge_srst_by_port_acpi(struct dsaf_device *dsaf_dev,
+ u32 port, bool dereset)
+{
+   

[PATCH v3 net-next 09/13] net: hns: add dsaf misc operation method

2016-05-30 Thread Yisen Zhuang
From: Kejian Yan 

The misc operation for different hw platform may be different, if using
current implementation, it will add a new branch on each function for
every new hw platform, so we add a method for this operation.

Signed-off-by: Kejian Yan 
Signed-off-by: Yisen Zhuang 
---
 drivers/net/ethernet/hisilicon/hns/hns_ae_adapt.c  |  4 +-
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_gmac.c |  6 +-
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c  | 14 ++--
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.h  |  2 -
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c | 11 ++-
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.h | 33 ++---
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c | 79 +++---
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.h |  7 +-
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_ppe.c  | 15 ++--
 .../net/ethernet/hisilicon/hns/hns_dsaf_xgmac.c| 10 +--
 10 files changed, 111 insertions(+), 70 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns/hns_ae_adapt.c 
b/drivers/net/ethernet/hisilicon/hns/hns_ae_adapt.c
index 8e009f4..d37b778 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_ae_adapt.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_ae_adapt.c
@@ -637,13 +637,15 @@ static int hns_ae_config_loopback(struct hnae_handle 
*handle,
int ret;
struct hnae_vf_cb *vf_cb = hns_ae_get_vf_cb(handle);
struct hns_mac_cb *mac_cb = hns_get_mac_cb(handle);
+   struct dsaf_device *dsaf_dev = mac_cb->dsaf_dev;
 
switch (loop) {
case MAC_INTERNALLOOP_PHY:
ret = 0;
break;
case MAC_INTERNALLOOP_SERDES:
-   ret = hns_mac_config_sds_loopback(vf_cb->mac_cb, en);
+   ret = dsaf_dev->misc_op->cfg_serdes_loopback(vf_cb->mac_cb,
+!!en);
break;
case MAC_INTERNALLOOP_MAC:
ret = hns_mac_config_mac_loopback(vf_cb->mac_cb, loop, en);
diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_gmac.c 
b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_gmac.c
index 44abb08..1235c7f 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_gmac.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_gmac.c
@@ -110,7 +110,7 @@ static void hns_gmac_free(void *mac_drv)
 
u32 mac_id = drv->mac_id;
 
-   hns_dsaf_ge_srst_by_port(dsaf_dev, mac_id, 0);
+   dsaf_dev->misc_op->ge_srst(dsaf_dev, mac_id, 0);
 }
 
 static void hns_gmac_set_tx_auto_pause_frames(void *mac_drv, u16 newval)
@@ -317,9 +317,9 @@ static void hns_gmac_init(void *mac_drv)
 
port = drv->mac_id;
 
-   hns_dsaf_ge_srst_by_port(dsaf_dev, port, 0);
+   dsaf_dev->misc_op->ge_srst(dsaf_dev, port, 0);
mdelay(10);
-   hns_dsaf_ge_srst_by_port(dsaf_dev, port, 1);
+   dsaf_dev->misc_op->ge_srst(dsaf_dev, port, 1);
mdelay(10);
hns_gmac_disable(mac_drv, MAC_COMM_MODE_RX_AND_TX);
hns_gmac_tx_loop_pkt_dis(mac_drv);
diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c 
b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c
index 527b49d..2ebf14a 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c
@@ -95,7 +95,7 @@ void hns_mac_get_link_status(struct hns_mac_cb *mac_cb, u32 
*link_status)
else
*link_status = 0;
 
-   ret = hns_mac_get_sfp_prsnt(mac_cb, _prsnt);
+   ret = mac_cb->dsaf_dev->misc_op->get_sfp_prsnt(mac_cb, _prsnt);
if (!ret)
*link_status = *link_status && sfp_prsnt;
 
@@ -512,7 +512,7 @@ void hns_mac_stop(struct hns_mac_cb *mac_cb)
 
mac_ctrl_drv->mac_en_flg = 0;
mac_cb->link = 0;
-   cpld_led_reset(mac_cb);
+   mac_cb->dsaf_dev->misc_op->cpld_reset_led(mac_cb);
 }
 
 /**
@@ -804,7 +804,7 @@ int hns_mac_get_cfg(struct dsaf_device *dsaf_dev, struct 
hns_mac_cb *mac_cb)
else
mac_cb->mac_type = HNAE_PORT_DEBUG;
 
-   mac_cb->phy_if = hns_mac_get_phy_if(mac_cb);
+   mac_cb->phy_if = dsaf_dev->misc_op->get_phy_if(mac_cb);
 
ret = hns_mac_get_mode(mac_cb->phy_if);
if (ret < 0) {
@@ -819,7 +819,7 @@ int hns_mac_get_cfg(struct dsaf_device *dsaf_dev, struct 
hns_mac_cb *mac_cb)
if (ret)
return ret;
 
-   cpld_led_reset(mac_cb);
+   mac_cb->dsaf_dev->misc_op->cpld_reset_led(mac_cb);
mac_cb->vaddr = hns_mac_get_vaddr(dsaf_dev, mac_cb, mac_mode_idx);
 
return 0;
@@ -906,7 +906,7 @@ void hns_mac_uninit(struct dsaf_device *dsaf_dev)
int max_port_num = hns_mac_get_max_port_num(dsaf_dev);
 
for (i = 0; i < max_port_num; i++) {
-   cpld_led_reset(dsaf_dev->mac_cb[i]);
+   dsaf_dev->misc_op->cpld_reset_led(dsaf_dev->mac_cb[i]);
dsaf_dev->mac_cb[i] = NULL;
}
 }
@@ -989,7 +989,7 @@ void 

[PATCH v3 net-next 03/13] net: hisilicon: cleanup to prepare for other cases

2016-05-30 Thread Yisen Zhuang
From: Kejian Yan 

Hns-mdio only supports DT case now. do some cleanup to prepare
for introducing other cases later, no functional change.

Signed-off-by: Kejian Yan 
Signed-off-by: Yisen Zhuang 
---
 drivers/net/ethernet/hisilicon/hns_mdio.c | 46 +++
 1 file changed, 23 insertions(+), 23 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns_mdio.c 
b/drivers/net/ethernet/hisilicon/hns_mdio.c
index 765ddb3..381cf0a 100644
--- a/drivers/net/ethernet/hisilicon/hns_mdio.c
+++ b/drivers/net/ethernet/hisilicon/hns_mdio.c
@@ -354,6 +354,9 @@ static int hns_mdio_reset(struct mii_bus *bus)
struct hns_mdio_device *mdio_dev = (struct hns_mdio_device *)bus->priv;
int ret;
 
+   if (!dev_of_node(bus->parent))
+   return -ENOTSUPP;
+
if (!mdio_dev->subctrl_vbase) {
dev_err(>dev, "mdio sys ctl reg has not maped\n");
return -ENODEV;
@@ -399,19 +402,12 @@ static int hns_mdio_reset(struct mii_bus *bus)
 /**
  * hns_mdio_bus_name - get mdio bus name
  * @name: mdio bus name
- * @np: mdio device node pointer
+ * @addr: mdio physical address
  */
-static void hns_mdio_bus_name(char *name, struct device_node *np)
+static void hns_mdio_bus_name(char *name, phys_addr_t addr)
 {
-   const u32 *addr;
-   u64 taddr = OF_BAD_ADDR;
-
-   addr = of_get_address(np, 0, NULL, NULL);
-   if (addr)
-   taddr = of_translate_address(np, addr);
-
-   snprintf(name, MII_BUS_ID_SIZE, "%s@%llx", np->name,
-(unsigned long long)taddr);
+   snprintf(name, MII_BUS_ID_SIZE,
+"hns-mdio@%llx", (unsigned long long)addr);
 }
 
 /**
@@ -422,17 +418,16 @@ static void hns_mdio_bus_name(char *name, struct 
device_node *np)
  */
 static int hns_mdio_probe(struct platform_device *pdev)
 {
-   struct device_node *np;
struct hns_mdio_device *mdio_dev;
struct mii_bus *new_bus;
struct resource *res;
-   int ret;
+   int ret = -ENODEV;
 
if (!pdev) {
dev_err(NULL, "pdev is NULL!\r\n");
return -ENODEV;
}
-   np = pdev->dev.of_node;
+
mdio_dev = devm_kzalloc(>dev, sizeof(*mdio_dev), GFP_KERNEL);
if (!mdio_dev)
return -ENOMEM;
@@ -448,7 +443,7 @@ static int hns_mdio_probe(struct platform_device *pdev)
new_bus->write = hns_mdio_write;
new_bus->reset = hns_mdio_reset;
new_bus->priv = mdio_dev;
-   hns_mdio_bus_name(new_bus->id, np);
+   new_bus->parent = >dev;
 
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
mdio_dev->vbase = devm_ioremap_resource(>dev, res);
@@ -457,18 +452,23 @@ static int hns_mdio_probe(struct platform_device *pdev)
return ret;
}
 
-   mdio_dev->subctrl_vbase =
-   syscon_node_to_regmap(of_parse_phandle(np, "subctrl-vbase", 0));
-   if (IS_ERR(mdio_dev->subctrl_vbase)) {
-   dev_warn(>dev, "no syscon hisilicon,peri-c-subctrl\n");
-   mdio_dev->subctrl_vbase = NULL;
-   }
-   new_bus->parent = >dev;
platform_set_drvdata(pdev, new_bus);
 
-   ret = of_mdiobus_register(new_bus, np);
+   hns_mdio_bus_name(new_bus->id, res->start);
+   if (dev_of_node(>dev)) {
+   mdio_dev->subctrl_vbase = syscon_node_to_regmap(
+   of_parse_phandle(pdev->dev.of_node,
+"subctrl-vbase", 0));
+   if (IS_ERR(mdio_dev->subctrl_vbase)) {
+   dev_warn(>dev, "no syscon 
hisilicon,peri-c-subctrl\n");
+   mdio_dev->subctrl_vbase = NULL;
+   }
+   ret = of_mdiobus_register(new_bus, pdev->dev.of_node);
+   }
+
if (ret) {
dev_err(>dev, "Cannot register as MDIO bus!\n");
+
platform_set_drvdata(pdev, NULL);
return ret;
}
-- 
1.9.1



Re: [PATCH] veth: delay peer link configuration after interfaces are tied

2016-05-30 Thread Vincent Bernat
 ❦ 30 mai 2016 12:12 CEST, Vincent Bernat  :

> When the peer link is created, its "iflink" information is not
[...]

And that's the wrong patch... Please, ignore this one.
-- 
Don't stop with your first draft.
- The Elements of Programming Style (Kernighan & Plauger)


Re: [PATCH] veth: delay peer link configuration after interfaces are tied

2016-05-30 Thread Vincent Bernat
 ❦ 30 mai 2016 11:23 CEST, Nicolas Dichtel  :

>> @@ -466,6 +462,10 @@ static int veth_newlink(struct net *src_net, struct 
>> net_device *dev,
>>  
>>  priv = netdev_priv(peer);
>>  rcu_assign_pointer(priv->peer, dev);
>> +
>> +err = rtnl_configure_link(peer, ifmp);
>> +if (err < 0)
>> +goto err_configure_peer;

> You should fix the error path. 'unregister_netdevice(dev)' is missing.

I am sending another patch to fix that. I am quite unsure if I do the
right thing here.
-- 
Don't stop with your first draft.
- The Elements of Programming Style (Kernighan & Plauger)


[PATCH] veth: delay peer link configuration after interfaces are tied

2016-05-30 Thread Vincent Bernat
When the peer link is created, its "iflink" information is not
advertised through netlink. If a user is maintaining a cache from all
updates, it will miss this information:

2: veth0@NONE:  mtu 1500 qdisc noop state DOWN group 
default
link/ether ae:0e:08:af:fb:a0 brd ff:ff:ff:ff:ff:ff
3: veth1@veth0:  mtu 1500 qdisc noop state DOWN 
group default
link/ether 3a:31:f1:36:2e:e5 brd ff:ff:ff:ff:ff:ff

To avoid this situation, the peer link is only configured after both
interfaces are tied together:

3: veth0@veth1:  mtu 1500 qdisc noop state DOWN group 
default
link/ether ee:0d:80:46:36:fe brd ff:ff:ff:ff:ff:ff
4: veth1@veth0:  mtu 1500 qdisc noop state DOWN 
group default
link/ether ba:25:bc:7a:0d:c8 brd ff:ff:ff:ff:ff:ff

Signed-off-by: Vincent Bernat 
---
 drivers/net/veth.c | 13 +
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/drivers/net/veth.c b/drivers/net/veth.c
index f37a6e61d4ad..7580f6765948 100644
--- a/drivers/net/veth.c
+++ b/drivers/net/veth.c
@@ -432,10 +432,6 @@ static int veth_newlink(struct net *src_net, struct 
net_device *dev,
 
netif_carrier_off(peer);
 
-   err = rtnl_configure_link(peer, ifmp);
-   if (err < 0)
-   goto err_configure_peer;
-
/*
 * register dev last
 *
@@ -466,8 +462,17 @@ static int veth_newlink(struct net *src_net, struct 
net_device *dev,
 
priv = netdev_priv(peer);
rcu_assign_pointer(priv->peer, dev);
+
+   err = rtnl_configure_link(peer, ifmp);
+   if (err < 0)
+   goto err_configure_link;
return 0;
 
+err_configure_link:
+   RCU_INIT_POINTER(priv->peer, NULL);
+   priv = netdev_priv(dev);
+   RCU_INIT_POINTER(priv->peer, NULL);
+   unregister_netdevice(dev);
 err_register_dev:
/* nothing to do */
 err_configure_peer:
-- 
2.8.1



[PATCH] veth: delay peer link configuration after interfaces are tied

2016-05-30 Thread Vincent Bernat
When the peer link is created, its "iflink" information is not
advertised through netlink. If a user is maintaining a cache from all
updates, it will miss this information:

2: veth0@NONE:  mtu 1500 qdisc noop state DOWN group 
default
link/ether ae:0e:08:af:fb:a0 brd ff:ff:ff:ff:ff:ff
3: veth1@veth0:  mtu 1500 qdisc noop state DOWN 
group default
link/ether 3a:31:f1:36:2e:e5 brd ff:ff:ff:ff:ff:ff

To avoid this situation, the peer link is only configured after both
interfaces are tied together:

3: veth0@veth1:  mtu 1500 qdisc noop state DOWN group 
default
link/ether ee:0d:80:46:36:fe brd ff:ff:ff:ff:ff:ff
4: veth1@veth0:  mtu 1500 qdisc noop state DOWN 
group default
link/ether ba:25:bc:7a:0d:c8 brd ff:ff:ff:ff:ff:ff

Signed-off-by: Vincent Bernat 
---
 drivers/net/veth.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/net/veth.c b/drivers/net/veth.c
index f37a6e61d4ad..9726c4dbf659 100644
--- a/drivers/net/veth.c
+++ b/drivers/net/veth.c
@@ -432,10 +432,6 @@ static int veth_newlink(struct net *src_net, struct 
net_device *dev,
 
netif_carrier_off(peer);
 
-   err = rtnl_configure_link(peer, ifmp);
-   if (err < 0)
-   goto err_configure_peer;
-
/*
 * register dev last
 *
@@ -466,6 +462,10 @@ static int veth_newlink(struct net *src_net, struct 
net_device *dev,
 
priv = netdev_priv(peer);
rcu_assign_pointer(priv->peer, dev);
+
+   err = rtnl_configure_link(peer, ifmp);
+   if (err < 0)
+   goto err_configure_peer;
return 0;
 
 err_register_dev:
-- 
2.8.1



Re: [PATCH v5 0/2] skb_array: array based FIFO for skbs

2016-05-30 Thread Jason Wang



On 2016年05月23日 18:43, Michael S. Tsirkin wrote:

This is in response to the proposal by Jason to make tun
rx packet queue lockless using a circular buffer.
My testing seems to show that at least for the common usecase
in networking, which isn't lockless, circular buffer
with indices does not perform that well, because
each index access causes a cache line to bounce between
CPUs, and index access causes stalls due to the dependency.

By comparison, an array of pointers where NULL means invalid
and !NULL means valid, can be updated without messing up barriers
at all and does not have this issue.

On the flip side, cache pressure may be caused by using large queues.
tun has a queue of 1000 entries by default and that's 8K.
At this point I'm not sure this can be solved efficiently.
The correct solution might be sizing the queues appropriately.

Here's an implementation of this idea: it can be used more
or less whenever sk_buff_head can be used, except you need
to know the queue size in advance.

It's using skb pointers but we switching to void * would be easy at cost
of type safety, though it appears that people want lockless  push
etc so I'm not sure of the value.

I didn't implement resizing but it's possible by holding
both consumer and producer locks.

I think this code works fine without any extra memory barriers since we
always read and write the same location, so the accesses can not be
reordered.
Multiple writes of the same value into memory would mess things up
for us, I don't think compilers would do it though.
But if people feel it's better to be safe wrt compiler optimizations,
specifying queue as volatile would probably do it in a cleaner way
than converting all accesses to READ_ONCE/WRITE_ONCE. Thoughts?

The only issue is with calls within a loop using the __skb_array_XXX
accessors - in theory compiler could hoist accesses out of the loop.

Following volatile-considered-harmful.txt I merely
documented that callers that busy-poll should invoke cpu_relax().
Most people will use the external skb_array_XXX APIs with a spinlock,
so this should not be an issue for them.

changes since v4 (v3 was never posted)
documentation
dropped SKB_ARRAY_MIN_SIZE heuristic
unit test (in userspace, included as patch 2)

changes since v2:
 fixed integer overflow pointed out by Eric.
 added some comments.

changes since v1:
 fixed bug pointed out by Eric.


Michael S. Tsirkin (2):
   skb_array: array based FIFO for skbs
   skb_array: ring test

  include/linux/skb_array.h | 127 +
  tools/virtio/ringtest/skb_array.c | 167 ++
  tools/virtio/ringtest/Makefile|   4 +-
  3 files changed, 297 insertions(+), 1 deletion(-)
  create mode 100644 include/linux/skb_array.h
  create mode 100644 tools/virtio/ringtest/skb_array.c



I change tun to use skb array, looks like it can give about 5% more 
faster than skb ring.


And we usually don't need touch bhs during consume and produce (e.g for 
the case of tun).


Thanks


Re: [PATCH 0/8] mwifiex: Fix some error handling issues in mwifiex_sdio_probe() function

2016-05-30 Thread Enric Balletbo Serra
Hi Javier,

2016-05-27 16:18 GMT+02:00 Javier Martinez Canillas :
> Hello,
>
> While booting a system with a mwifiex WiFi card, I noticed the following
> missleading error message:
>
> [  12.480042] mwifiex_sdio mmc2:0001:1: sdio platform data not available
>
> This error only applies to platforms that define a child node for the SDIO
> device, but it's currently shown even in platforms that don't have a child
> node defined.
>
> So this series fixes this issue and others I found in the .probe function
> (mostly related to error handling and the error path) while looking at it.
>

The patches looks good to me and tested on my Veyron Chromebook, so
for all this series:

Tested-by: Enric Balletbo i Serra 

Thanks,
  Enric

> Best regards,
> Javier
>
>
> Javier Martinez Canillas (8):
>   mwifiex: only call mwifiex_sdio_probe_of() if dev has an OF node
>   mwifiex: propagate sdio_enable_func() errno code in
> mwifiex_sdio_probe()
>   mwifiex: propagate mwifiex_add_card() errno code in
> mwifiex_sdio_probe()
>   mwifiex: consolidate mwifiex_sdio_probe() error paths
>   mwifiex: use dev_err() instead of pr_err() in mwifiex_sdio_probe()
>   mwifiex: check if mwifiex_sdio_probe_of() fails and return error
>   mwifiex: don't print an error if an optional DT property is missing
>   mwifiex: use better message and error code when OF node doesn't match
>
>  drivers/net/wireless/marvell/mwifiex/sdio.c | 46 
> ++---
>  1 file changed, 28 insertions(+), 18 deletions(-)
>
> --
> 2.5.5
>


[PATCH net] net: dsa: mv88e6xxx: Fix port forwarding mask

2016-05-30 Thread Wojciech Dubowik
Port's vlan table is specified by bit mask and not by number.
Only 4.4.x kernels are affected.

Signed-off-by: Wojciech Dubowik 
---
 drivers/net/dsa/mv88e6xxx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/dsa/mv88e6xxx.c b/drivers/net/dsa/mv88e6xxx.c
index 2dea39b..3e074d4 100644
--- a/drivers/net/dsa/mv88e6xxx.c
+++ b/drivers/net/dsa/mv88e6xxx.c
@@ -2150,7 +2150,7 @@ static int mv88e6xxx_setup_port(struct dsa_switch *ds, 
int port)
 * database, and allow every port to egress frames on all other ports.
 */
reg = BIT(ps->num_ports) - 1; /* all ports */
-   ret = _mv88e6xxx_port_vlan_map_set(ds, port, reg & ~port);
+   ret = _mv88e6xxx_port_vlan_map_set(ds, port, reg & ~BIT(port));
if (ret)
goto abort;
 
-- 
1.9.1



Re: [PATCH] nf_queue: Make the queue_handler pernet

2016-05-30 Thread Pablo Neira Ayuso
On Fri, May 13, 2016 at 09:18:52PM -0500, Eric W. Biederman wrote:
> 
> Florian Weber reported:
> > Under full load (unshare() in loop -> OOM conditions) we can
> > get kernel panic:
> >
> > BUG: unable to handle kernel NULL pointer dereference at 0008
> > IP: [] nfqnl_nf_hook_drop+0x35/0x70
> > [..]
> > task: 88012dfa3840 ti: 88012dffc000 task.ti: 88012dffc000
> > RIP: 0010:[]  [] 
> > nfqnl_nf_hook_drop+0x35/0x70
> > RSP: :88012dfffd80  EFLAGS: 00010206
> > RAX: 0008 RBX: 81add0c0 RCX: 88013fd8
> > [..]
> > Call Trace:
> >  [] nf_queue_nf_hook_drop+0x18/0x20
> >  [] nf_unregister_net_hook+0xdb/0x150
> >  [] netfilter_net_exit+0x2f/0x60
> >  [] ops_exit_list.isra.4+0x38/0x60
> >  [] setup_net+0xc2/0x120
> >  [] copy_net_ns+0x79/0x120
> >  [] create_new_namespaces+0x11b/0x1e0
> >  [] unshare_nsproxy_namespaces+0x57/0xa0
> >  [] SyS_unshare+0x1b2/0x340
> >  [] entry_SYSCALL_64_fastpath+0x1e/0xa8
> > Code: 65 00 48 89 e5 41 56 41 55 41 54 53 83 e8 01 48 8b 97 70 12 00 00 48 
> > 98 49 89 f4 4c 8b 74 c2 18 4d 8d 6e 08 49 81 c6 88 00 00 00 <49> 8b 5d 00 
> > 48 85 db 74 1a 48 89 df 4c 89 e2 48 c7 c6 90 68 47
> >
> 
> The simple fix for this requires a new pernet variable for struct
> nf_queue that indicates when it is safe to use the dynamically
> allocated nf_queue state.
> 
> As we need a variable anyway make nf_register_queue_handler and
> nf_unregister_queue_handler pernet.  This allows the existing logic of
> when it is safe to use the state from the nfnetlink_queue module to be
> reused with no changes except for making it per net.
> 
> The syncrhonize_rcu from nf_unregister_queue_handler is moved to a new
> function nfnl_queue_net_exit_batch so that the worst case of having a
> syncrhonize_rcu in the pernet exit path is not experienced in batch
> mode.

Applied, thanks.


Re: [PATCH] veth: delay peer link configuration after interfaces are tied

2016-05-30 Thread Nicolas Dichtel
Le 29/05/2016 13:17, Vincent Bernat a écrit :
[snip]
> diff --git a/drivers/net/veth.c b/drivers/net/veth.c
> index f37a6e61d4ad..9726c4dbf659 100644
> --- a/drivers/net/veth.c
> +++ b/drivers/net/veth.c
> @@ -432,10 +432,6 @@ static int veth_newlink(struct net *src_net, struct 
> net_device *dev,
>  
>   netif_carrier_off(peer);
>  
> - err = rtnl_configure_link(peer, ifmp);
> - if (err < 0)
> - goto err_configure_peer;
> -
>   /*
>* register dev last
>*
> @@ -466,6 +462,10 @@ static int veth_newlink(struct net *src_net, struct 
> net_device *dev,
>  
>   priv = netdev_priv(peer);
>   rcu_assign_pointer(priv->peer, dev);
> +
> + err = rtnl_configure_link(peer, ifmp);
> + if (err < 0)
> + goto err_configure_peer;
You should fix the error path. 'unregister_netdevice(dev)' is missing.


[PATCH v2] fib_rules: Added NLM_F_EXCL support to fib_nl_newrule

2016-05-30 Thread Mateusz Bajorski
When adding rule with NLM_F_EXCL flag then check if the same rule exist.
If yes then exit with -EEXIST.

This is already implemented in iproute2:
if (cmd == RTM_NEWRULE) {
req.n.nlmsg_flags |= NLM_F_CREATE|NLM_F_EXCL;
req.r.rtm_type = RTN_UNICAST;
}

Tested ipv4 and ipv6 with net-next linux on qemu x86

expected behavior after patch:
localhost ~ # ip rule
0:from all lookup local
32766:from all lookup main
32767:from all lookup default
localhost ~ # ip rule add from 10.46.177.97 lookup 104 pref 1005
localhost ~ # ip rule add from 10.46.177.97 lookup 104 pref 1005
RTNETLINK answers: File exists
localhost ~ # ip rule
0:from all lookup local
1005:from 10.46.177.97 lookup 104
32766:from all lookup main
32767:from all lookup default

There was already topic regarding this but I don't see any changes
merged and problem still occurs.
https://lkml.kernel.org/r/1135778809.5944.7.camel+%28%29+localhost+%21+localdomain

Signed-off-by: Mateusz Bajorski 
---
Changes in v2: section moved to new place where new rule is already built

 net/core/fib_rules.c | 34 ++
 1 file changed, 34 insertions(+)

diff --git a/net/core/fib_rules.c b/net/core/fib_rules.c
index 840aceb..5bc1d27 100644
--- a/net/core/fib_rules.c
+++ b/net/core/fib_rules.c
@@ -371,6 +371,40 @@ static int fib_nl_newrule(struct sk_buff *skb, struct 
nlmsghdr* nlh)
} else if (rule->action == FR_ACT_GOTO)
goto errout_free;
 
+   if (nlh->nlmsg_flags & NLM_F_EXCL) {
+   list_for_each_entry(r, >rules_list, list) {
+   if (r->action != rule->action)
+   continue;
+
+   if (r->table != rule->table)
+   continue;
+
+   if (r->pref != rule->pref)
+   continue;
+
+   if (memcmp(r->iifname, rule->iifname, IFNAMSIZ))
+   continue;
+
+   if (memcmp(r->oifname, rule->oifname, IFNAMSIZ))
+   continue;
+
+   if (r->mark != rule->mark)
+   continue;
+
+   if (r->mark_mask != rule->mark_mask)
+   continue;
+
+   if (r->tun_id != rule->tun_id)
+   continue;
+
+   if (!ops->compare(r, frh, tb))
+   continue;
+
+   err = -EEXIST;
+   goto errout_free;
+   }
+   }
+
err = ops->configure(rule, skb, frh, tb);
if (err < 0)
goto errout_free;
-- 
2.6.4


[PATCH 2/2] macvlan: Avoid unnecessary multicast cloning

2016-05-30 Thread Herbert Xu
Currently we always queue a multicast packet for further processing,
even if none of the macvlan devices are subscribed to the address.

This patch optimises this by adding a global multicast filter for
a macvlan_port.

Note that this patch doesn't handle the broadcast addresses of the
individual macvlan devices correctly, if they are not all identical.
However, this is already broken because there is no mechanism in
place to update the individual multicast filters when you change
the broadcast address.

If someone cares enough they should fix this by collecting all
broadcast addresses for a macvlan as we do for multicast and unicast.

Signed-off-by: Herbert Xu 

diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
index f55fe21..9fa4532 100644
--- a/drivers/net/macvlan.c
+++ b/drivers/net/macvlan.c
@@ -49,6 +49,7 @@ struct macvlan_port {
boolpassthru;
int count;
struct hlist_head   vlan_source_hash[MACVLAN_HASH_SIZE];
+   DECLARE_BITMAP(mc_filter, MACVLAN_MC_FILTER_SZ);
 };
 
 struct macvlan_source_entry {
@@ -418,6 +419,8 @@ static rx_handler_result_t macvlan_handle_frame(struct 
sk_buff **pskb)
 
port = macvlan_port_get_rcu(skb->dev);
if (is_multicast_ether_addr(eth->h_dest)) {
+   unsigned int hash;
+
skb = ip_check_defrag(dev_net(skb->dev), skb, 
IP_DEFRAG_MACVLAN);
if (!skb)
return RX_HANDLER_CONSUMED;
@@ -435,7 +438,9 @@ static rx_handler_result_t macvlan_handle_frame(struct 
sk_buff **pskb)
goto out;
}
 
-   macvlan_broadcast_enqueue(port, src, skb);
+   hash = mc_hash(NULL, eth->h_dest);
+   if (test_bit(hash, port->mc_filter))
+   macvlan_broadcast_enqueue(port, src, skb);
 
return RX_HANDLER_PASS;
}
@@ -725,6 +730,8 @@ static void macvlan_set_mac_lists(struct net_device *dev)
 {
struct macvlan_dev *vlan = netdev_priv(dev);
 
+   dev_uc_sync(vlan->lowerdev, dev);
+   dev_mc_sync(vlan->lowerdev, dev);
if (dev->flags & (IFF_PROMISC | IFF_ALLMULTI)) {
bitmap_fill(vlan->mc_filter, MACVLAN_MC_FILTER_SZ);
} else {
@@ -739,9 +746,31 @@ static void macvlan_set_mac_lists(struct net_device *dev)
__set_bit(mc_hash(vlan, dev->broadcast), filter);
 
bitmap_copy(vlan->mc_filter, filter, MACVLAN_MC_FILTER_SZ);
+
+   /* This is slightly inaccurate as we're including
+* the subscription list of vlan->lowerdev too.
+*/
+   bitmap_zero(filter, MACVLAN_MC_FILTER_SZ);
+   netdev_for_each_mc_addr(ha, vlan->lowerdev) {
+   __set_bit(mc_hash(NULL, ha->addr), filter);
+   }
+
+   /* Bug alert: This only works if everyone has the
+* same broadcast address.  As soon as someone
+* changes theirs this will break.
+*
+* However, this is already broken as when you
+* change your broadcast address we don't get
+* called.
+*
+* The solution is to maintain a list of broadcast
+* addresses like we do for uc/mc, if you care.
+*/
+   __set_bit(mc_hash(NULL, dev->broadcast), filter);
+
+   bitmap_copy(vlan->port->mc_filter, filter,
+   MACVLAN_MC_FILTER_SZ);
}
-   dev_uc_sync(vlan->lowerdev, dev);
-   dev_mc_sync(vlan->lowerdev, dev);
 }
 
 static int macvlan_change_mtu(struct net_device *dev, int new_mtu)
-- 
Email: Herbert Xu 
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt


Re: [patch v2 net-next 00/13] net: hns: add support of ACPI

2016-05-30 Thread Andy Shevchenko
On Mon, 2016-05-30 at 10:10 +0800, Kejian Yan wrote:
> This series adds HNS support of acpi. The routine will call some ACPI
> helper functions, like acpi_dev_found() and acpi_evaluate_dsm(), which
> are not included in other cases. In order to make system compile
> successfully in other cases except ACPI, it needs to add relative stub
> functions to linux/acpi.h. And we use device property functions
> instead
> of serial helper functions to suport both DT and ACPI cases. And then
> add the supports of ACPI for HNS.

Looks better. I have only kinda bikeshedding comments in mind, which I
didn't put here, though there is one you perhaps need to address.

Otherwise FWIW:
Reviewed-by: Andy Shevchenko 

> 
> change log:
>  v1 -> v2:
>  1. use acpi_dev_found() instead of acpi_match_device_ids() to check
> if
> it is a acpi node.
>  2. use is_of_node() instead of IS_ENABLED() to check if it is a DT
> node.
>  3. split the patch("add support of acpi for hns-mdio") into two
> patches:
> 3.1 Move to use fwnode_handle
> 3.2 Add ACPI
>  4. add the patch which subject is dsaf misc operation method
>  5. fix the comments by Andy Shevchenko
> 
> Kejian Yan (13):
>   ACPI: bus: add stub acpi_dev_found() to linux/acpi.h
>   ACPI: bus: add stub acpi_evaluate_dsm() to linux/acpi.h
>   net: hisilicon: cleanup to prepare for other cases
>   net: hisilicon: add support of acpi for hns-mdio
>   net: hns: use device_* APIs instead of of_* APIs
>   net: hns: use platform_get_irq instead of irq_of_parse_and_map
>   net: hns: enet specify a reference to dsaf by fwnode_handle
>   net: hns: add uniform interface for phy connection
>   net: hns: add dsaf misc operation method
>   net: hns: dsaf adds support of acpi
>   net: hns: register phy device in each mac initial sequence
>   net: hns: implement the miscellaneous operation by asl
>   net: hns: net: hns: enet adds support of acpi
> 
>  drivers/net/ethernet/hisilicon/hns/hnae.c  |  18 +-
>  drivers/net/ethernet/hisilicon/hns/hnae.h  |   5 +-
>  drivers/net/ethernet/hisilicon/hns/hns_ae_adapt.c  |   6 +-
>  drivers/net/ethernet/hisilicon/hns/hns_dsaf_gmac.c |   6 +-
>  drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c  | 247
> +++-
>  drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.h  |   4 +-
>  drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c | 105 ++---
>  drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.h |  33 ++-
>  drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c | 250
> ++---
>  drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.h |   7 +-
>  drivers/net/ethernet/hisilicon/hns/hns_dsaf_ppe.c  |  15 +-
>  drivers/net/ethernet/hisilicon/hns/hns_dsaf_rcb.c  |   5 +-
>  .../net/ethernet/hisilicon/hns/hns_dsaf_xgmac.c|  10 +-
>  drivers/net/ethernet/hisilicon/hns/hns_enet.c  |  90 +---
>  drivers/net/ethernet/hisilicon/hns/hns_enet.h  |   2 +-
>  drivers/net/ethernet/hisilicon/hns/hns_ethtool.c   |   2 +-
>  drivers/net/ethernet/hisilicon/hns_mdio.c  | 147 +++-
>  include/linux/acpi.h   |  13 ++
>  18 files changed, 710 insertions(+), 255 deletions(-)
> 

-- 
Andy Shevchenko 
Intel Finland Oy


Re: [patch v2 net-next 12/13] net: hns: implement the miscellaneous operation by asl

2016-05-30 Thread Andy Shevchenko
On Mon, 2016-05-30 at 10:10 +0800, Kejian Yan wrote:
> The miscellaneous operation is implemented in BIOS, the kernel can
> call
> _DSM method help to call the implementation in ACPI case. Here is a
> patch
> to do that.
> 


> +static phy_interface_t hns_mac_get_phy_if_acpi(struct hns_mac_cb
> *mac_cb)
> +{
> + phy_interface_t phy_if = PHY_INTERFACE_MODE_NA;
> + union acpi_object *obj;
> + union acpi_object obj_args, argv4;
> +
> + obj_args.integer.type = ACPI_TYPE_INTEGER;
> + obj_args.integer.value = mac_cb->mac_id;
> +
> + argv4.type = ACPI_TYPE_PACKAGE,
> + argv4.package.count = 1,
> + argv4.package.elements = _args,
> +
> + obj = acpi_evaluate_dsm(ACPI_HANDLE(mac_cb->dev),
> + hns_dsaf_acpi_dsm_uuid, 0,
> + HNS_OP_GET_PORT_TYPE_FUNC, );
> +
> + if (!obj || obj->type != ACPI_TYPE_INTEGER)

Seems you have potential memory leak here

if (!obj)
 return phy_if;

if (obj->...)
 goto exit_free;


> + return phy_if;
> +
> + phy_if = obj->integer.value ?
> + PHY_INTERFACE_MODE_XGMII : PHY_INTERFACE_MODE_SGMII;
> +
> + dev_dbg(mac_cb->dev, "mac_id=%d, phy_if=%d\n", mac_cb-
> >mac_id, phy_if);
> +

+ exit_free:

> + ACPI_FREE(obj);
> +
> + return phy_if;
> +}
> 

-- 
Andy Shevchenko 
Intel Finland Oy


[PATCH 1/2] macvlan: Fix potential use-after free for broadcasts

2016-05-30 Thread Herbert Xu
When we postpone a broadcast packet we save the source port in
the skb if it is local.  However, the source port can disappear
before we get a chance to process the packet.

This patch fixes this by holding a ref count on the netdev.

It also delays the skb->cb modification until after we allocate
the new skb as you should not modify shared skbs.

Fixes: 412ca1550cbe ("macvlan: Move broadcasts into a work queue")
Signed-off-by: Herbert Xu 

diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
index 2bcf1f3..78a00e3 100644
--- a/drivers/net/macvlan.c
+++ b/drivers/net/macvlan.c
@@ -305,11 +305,14 @@ static void macvlan_process_broadcast(struct work_struct 
*w)
 
rcu_read_unlock();
 
+   if (src)
+   dev_put(src->dev);
kfree_skb(skb);
}
 }
 
 static void macvlan_broadcast_enqueue(struct macvlan_port *port,
+ const struct macvlan_dev *src,
  struct sk_buff *skb)
 {
struct sk_buff *nskb;
@@ -319,8 +322,12 @@ static void macvlan_broadcast_enqueue(struct macvlan_port 
*port,
if (!nskb)
goto err;
 
+   MACVLAN_SKB_CB(nskb)->src = src;
+
spin_lock(>bc_queue.lock);
if (skb_queue_len(>bc_queue) < MACVLAN_BC_QUEUE_LEN) {
+   if (src)
+   dev_hold(src->dev);
__skb_queue_tail(>bc_queue, nskb);
err = 0;
}
@@ -429,8 +436,7 @@ static rx_handler_result_t macvlan_handle_frame(struct 
sk_buff **pskb)
goto out;
}
 
-   MACVLAN_SKB_CB(skb)->src = src;
-   macvlan_broadcast_enqueue(port, skb);
+   macvlan_broadcast_enqueue(port, src, skb);
 
return RX_HANDLER_PASS;
}
-- 
Email: Herbert Xu 
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt


[PATCH 0/2] macvlan: Avoid unnecessary multicast cloning

2016-05-30 Thread Herbert Xu
On Fri, May 27, 2016 at 02:44:33AM +0300, Lennert Buytenhek wrote:
> Commit 412ca1550cbecb2c ("macvlan: Move broadcasts into a work queue")
> moved processing of all macvlan multicasts into a work queue.  This
> causes a noticable performance regression when there is heavy multicast
> traffic on the underlying interface for multicast groups that the
> macvlan subinterfaces are not members of, in which case we end up
> cloning all those packets and then freeing them again from a work queue
> without really doing any useful work with them in between.

OK so your motivation is to get rid of the unnecessary memory
allocation, right?

Here's my totally untested patch, it tries to resolve your problem
by maintaining a filter hash at the macvlan_port level so that we
can quickly determine whether a given packet is needed or not.

It is preceded by a patch that fixes a potential use-after-free
bug that I discovered while looking over this.

Thanks,
-- 
Email: Herbert Xu 
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt


linux-4.7-rc1/drivers/isdn/capi/capidrv.c:1707]: (style) Redundant condition

2016-05-30 Thread David Binderman
Hello there,

linux-4.7-rc1/drivers/isdn/capi/capidrv.c:1707]: (style) Redundant
condition: If 'EXPR == ' '', the comparison 'EXPR' is always true.

Source code is

   while (*s && *s == ' ') s++;

Suggest new code

   while (*s == ' ') s++;


Regards

David Binderman


Re: [PATCH v1 5/6] dtb: xgene: Remove clock nodes

2016-05-30 Thread Matthias Brugger



On 27/05/16 09:22, Iyappan Subramanian wrote:

Since the MDIO will be responsible for clock reset, removing the clock
nodes from shadowcat xge0 and storm sgenet1.

Signed-off-by: Iyappan Subramanian 
Tested-by: Fushen Chen 
Tested-by: Toan Le 
---
  arch/arm64/boot/dts/apm/apm-shadowcat.dtsi | 12 
  arch/arm64/boot/dts/apm/apm-storm.dtsi | 18 --
  2 files changed, 4 insertions(+), 26 deletions(-)

diff --git a/arch/arm64/boot/dts/apm/apm-shadowcat.dtsi 
b/arch/arm64/boot/dts/apm/apm-shadowcat.dtsi
index 8106957..f27563d 100644
--- a/arch/arm64/boot/dts/apm/apm-shadowcat.dtsi
+++ b/arch/arm64/boot/dts/apm/apm-shadowcat.dtsi
@@ -299,17 +299,6 @@
clock-output-names = "pcie1clk";
};

-   xge0clk: xge0clk@1f61c000 {
-   compatible = "apm,xgene-device-clock";
-   #clock-cells = <1>;
-   clocks = < 0>;
-   reg = <0x0 0x1f61c000 0x0 0x1000>;
-   reg-names = "csr-reg";
-   enable-mask = <0x3>;
-   csr-mask = <0x3>;
-   clock-output-names = "xge0clk";
-   };
-


mdio@0x1f61 has xge0clk as input (patch 4), so deleting the node 
here will break the device tree. I suppose the mdio consumes the 
menetclk as in apm-storm.dtsi.


Regards,
Matthias


xge1clk: xge1clk@1f62c000 {
compatible = "apm,xgene-device-clock";
#clock-cells = <1>;
@@ -643,7 +632,6 @@
interrupts = <0 96 4>,
 <0 97 4>;
dma-coherent;
-   clocks = < 0>;
local-mac-address = [00 01 73 00 00 01];
phy-connection-type = "sgmii";
phy-handle = <>;
diff --git a/arch/arm64/boot/dts/apm/apm-storm.dtsi 
b/arch/arm64/boot/dts/apm/apm-storm.dtsi
index 18f694ea..f631fe4 100644
--- a/arch/arm64/boot/dts/apm/apm-storm.dtsi
+++ b/arch/arm64/boot/dts/apm/apm-storm.dtsi
@@ -237,20 +237,11 @@
clocks = < 0>;
reg = <0x0 0x1f21c000 0x0 0x1000>;
reg-names = "csr-reg";
-   csr-mask = <0x3>;
+   csr-mask = <0xa>;
+   enable-mask = <0xf>;
clock-output-names = "sge0clk";
};

-   sge1clk: sge1clk@1f21c000 {
-   compatible = "apm,xgene-device-clock";
-   #clock-cells = <1>;
-   clocks = < 0>;
-   reg = <0x0 0x1f21c000 0x0 0x1000>;
-   reg-names = "csr-reg";
-   csr-mask = <0xc>;
-   clock-output-names = "sge1clk";
-   };
-
xge0clk: xge0clk@1f61c000 {
compatible = "apm,xgene-device-clock";
#clock-cells = <1>;
@@ -938,9 +929,9 @@
reg-names = "enet_csr", "ring_csr", "ring_cmd";
interrupts = <0x0 0x3c 0x4>;
dma-coherent;
-   clocks = < 0>;
/* mac address will be overwritten by the bootloader */
local-mac-address = [00 00 00 00 00 00];
+   clocks = < 0>;
phy-connection-type = "rgmii";
phy-handle = <>;
};
@@ -955,8 +946,8 @@
interrupts = <0x0 0xA0 0x4>,
 <0x0 0xA1 0x4>;
dma-coherent;
-   clocks = < 0>;
local-mac-address = [00 00 00 00 00 00];
+   clocks = < 0>;
phy-connection-type = "sgmii";
phy-handle = <>;
};
@@ -972,7 +963,6 @@
 <0x0 0xAD 0x4>;
port-id = <1>;
dma-coherent;
-   clocks = < 0>;
local-mac-address = [00 00 00 00 00 00];
phy-connection-type = "sgmii";
phy-handle = <>;



[PATCH 5/7] net:mdio-mux: Add MDIO mux driver for iProc SoCs

2016-05-30 Thread Pramod Kumar
iProc based SoCs supports the integrated mdio multiplexer which
has the bus selection as well as mdio transaction generation logic
inside.

This mutiplexer has child buses for PCIe, SATA, USB and ETH. These
buses could be internal or external to SOC where PHYs are attached.
These buses could use C-45 or C-22 mdio transaction.

Signed-off-by: Pramod Kumar 
---
 drivers/net/phy/Kconfig  |  11 ++
 drivers/net/phy/Makefile |   1 +
 drivers/net/phy/mdio-mux-bcm-iproc.c | 263 +++
 3 files changed, 275 insertions(+)
 create mode 100644 drivers/net/phy/mdio-mux-bcm-iproc.c

diff --git a/drivers/net/phy/Kconfig b/drivers/net/phy/Kconfig
index 6dad9a9..38faecf 100644
--- a/drivers/net/phy/Kconfig
+++ b/drivers/net/phy/Kconfig
@@ -254,6 +254,17 @@ config MDIO_BUS_MUX_MMIOREG
 
  Currently, only 8-bit registers are supported.
 
+config MDIO_BUS_MUX_BCM_IPROC
+   tristate "Support for iProc based MDIO bus multiplexers"
+   depends on OF && OF_MDIO && (ARCH_BCM_IPROC || COMPILE_TEST)
+   select MDIO_BUS_MUX
+   default ARCH_BCM_IPROC
+   help
+ This module provides a driver for MDIO bus multiplexers found in
+ iProc based Broadcom SoCs. This mulitplexer connects one of several
+ child MDIO bus to a parent bus. Buses could be interal as well as
+ external and selection logic lies inside the same multiplexer.
+
 config MDIO_BCM_UNIMAC
tristate "Broadcom UniMAC MDIO bus controller"
depends on HAS_IOMEM
diff --git a/drivers/net/phy/Makefile b/drivers/net/phy/Makefile
index fcdbb92..f5951d5a 100644
--- a/drivers/net/phy/Makefile
+++ b/drivers/net/phy/Makefile
@@ -39,6 +39,7 @@ obj-$(CONFIG_AMD_PHY) += amd.o
 obj-$(CONFIG_MDIO_BUS_MUX) += mdio-mux.o
 obj-$(CONFIG_MDIO_BUS_MUX_GPIO)+= mdio-mux-gpio.o
 obj-$(CONFIG_MDIO_BUS_MUX_MMIOREG) += mdio-mux-mmioreg.o
+obj-$(CONFIG_MDIO_BUS_MUX_BCM_IPROC)   += mdio-mux-bcm-iproc.o
 obj-$(CONFIG_MDIO_SUN4I)   += mdio-sun4i.o
 obj-$(CONFIG_MDIO_MOXART)  += mdio-moxart.o
 obj-$(CONFIG_MDIO_BCM_UNIMAC)  += mdio-bcm-unimac.o
diff --git a/drivers/net/phy/mdio-mux-bcm-iproc.c 
b/drivers/net/phy/mdio-mux-bcm-iproc.c
new file mode 100644
index 000..40c32ee
--- /dev/null
+++ b/drivers/net/phy/mdio-mux-bcm-iproc.c
@@ -0,0 +1,263 @@
+/*
+ * Copyright 2016 Broadcom
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation (the "GPL").
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License version 2 (GPLv2) for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * version 2 (GPLv2) along with this source code.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define MDIO_PARAM_OFFSET  0x00
+#define MDIO_PARAM_MIIM_CYCLE  29
+#define MDIO_PARAM_INTERNAL_SEL25
+#define MDIO_PARAM_BUS_ID  22
+#define MDIO_PARAM_C45_SEL 21
+#define MDIO_PARAM_PHY_ID  16
+#define MDIO_PARAM_PHY_DATA0
+
+#define MDIO_READ_OFFSET   0x04
+#define MDIO_READ_DATA_MASK0x
+#define MDIO_ADDR_OFFSET   0x08
+
+#define MDIO_CTRL_OFFSET   0x0C
+#define MDIO_CTRL_WRITE_OP 0x1
+#define MDIO_CTRL_READ_OP  0x2
+
+#define MDIO_STAT_OFFSET   0x10
+#define MDIO_STAT_DONE 1
+
+#define BUS_MAX_ADDR   32
+#define EXT_BUS_START_ADDR 16
+
+struct mdiomux_bus_param {
+   bool is_c45;
+};
+
+struct iproc_mdiomux_desc {
+   void *mux_handle;
+   void __iomem *base;
+   struct device *dev;
+   struct mii_bus *mii_bus;
+   struct mdiomux_bus_param bus_param[BUS_MAX_ADDR];
+};
+
+static int iproc_mdio_wait_for_idle(void __iomem *base, bool result)
+{
+   u32 val;
+   unsigned int timeout = 1000; /* loop for 1s */
+
+   do {
+   val = readl(base + MDIO_STAT_OFFSET);
+   if ((val & MDIO_STAT_DONE) == result)
+   return 0;
+
+   usleep_range(1000, 2000);
+   } while (timeout--);
+
+   return -ETIMEDOUT;
+}
+
+/* start_miim_ops- Program and start MDIO transaction over mdio bus.
+ * @base: Base address
+ * @phyid: phyid of the selected bus.
+ * @reg: register offset to be read/written.
+ * @val :0 if read op else value to be written in @reg;
+ * @op: Operation that need to be carried out.
+ *  MDIO_CTRL_READ_OP: Read transaction.
+ *  MDIO_CTRL_WRITE_OP: Write transaction.
+ *
+ * Return value: Successful Read operation returns read reg values and write
+ *  

[PATCH 3/7] binding: mdio-mux: Add DT binding doc for Broadcom MDIO bus mutiplexer

2016-05-30 Thread Pramod Kumar
Add DT binding doc for Broadcom MDIO bus mutiplexer driver.

Signed-off-by: Pramod Kumar 
---
 .../bindings/net/brcm,mdio-mux-iproc.txt   | 64 ++
 1 file changed, 64 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/net/brcm,mdio-mux-iproc.txt

diff --git a/Documentation/devicetree/bindings/net/brcm,mdio-mux-iproc.txt 
b/Documentation/devicetree/bindings/net/brcm,mdio-mux-iproc.txt
new file mode 100644
index 000..dd74ee0
--- /dev/null
+++ b/Documentation/devicetree/bindings/net/brcm,mdio-mux-iproc.txt
@@ -0,0 +1,64 @@
+Properties for an MDIO bus mutiplexer found in Broadcom iProc based SoCs.
+
+This MDIO bus multiplexer defines buses that could be internal as well as
+external to SoCs and could accept MDIO transaction compatible to C-22 or
+C-45 Clause. When Child bus is selected, one need to select these two
+properties as well to generate desired MDIO trascation on appropriate bus.
+
+Required properties in addition to the generic multiplexer properties:
+
+MDIO multiplexer node:
+- complatible: brcm,mdio-mux-iproc.
+
+Child bus node:
+-brcm,is-c45: Boolean property indicating PHYs attached to this bus supports
+ C-45 mdio transaction.
+
+Every non-ethernet PHY requires a compatible so that it could be probed based
+on this compatible string.
+
+Additional information regarding generic multiplexer properties could be found
+at- Documentation/devicetree/bindings/net/mdio-mux.txt
+
+
+for example:
+   mdio_mux_iproc: mdio_mux_iproc@6602023c {
+   compatible = "brcm,mdio-mux-iproc";
+   reg = <0x6602023c 0x14>;
+   #address-cells = <1>;
+   #size-cells = <0>;
+   mdio-integrated-mux;
+
+   mdio@0 {
+   reg = <0x0>;
+   #address-cells = <1>;
+   #size-cells = <0>;
+
+   pci_phy0: pci-phy@0 {
+   compatible = "brcm,ns2-pcie-phy";
+   reg = <0x0>;
+   #phy-cells = <0>;
+   };
+   };
+
+   mdio@7 {
+   reg = <0x7>;
+   #address-cells = <1>;
+   #size-cells = <0>;
+
+   pci_phy1: pci-phy@0 {
+   compatible = "brcm,ns2-pcie-phy";
+   reg = <0x0>;
+   #phy-cells = <0>;
+   };
+   };
+   mdio@10 {
+   reg = <0x10>;
+   #address-cells = <1>;
+   #size-cells = <0>;
+
+   gphy0: eth-phy@10 {
+   reg = <0x10>;
+   };
+   };
+   };
-- 
1.9.1



[PATCH 4/7] DT:mdio-mux: Add mdio multiplexer driver node

2016-05-30 Thread Pramod Kumar
Add integrated MDIO multiplexer driver node which contains
two mux PCIe bus and one ethernet bus along with phys
lying on these bus.

Signed-off-by: Pramod Kumar 
---
 arch/arm64/boot/dts/broadcom/ns2-svk.dts | 12 
 arch/arm64/boot/dts/broadcom/ns2.dtsi| 32 
 2 files changed, 44 insertions(+)

diff --git a/arch/arm64/boot/dts/broadcom/ns2-svk.dts 
b/arch/arm64/boot/dts/broadcom/ns2-svk.dts
index ce0ab84..8f6a6cc 100644
--- a/arch/arm64/boot/dts/broadcom/ns2-svk.dts
+++ b/arch/arm64/boot/dts/broadcom/ns2-svk.dts
@@ -87,3 +87,15 @@
#size-cells = <1>;
};
 };
+
+_mux_iproc {
+   mdio@10 {
+   reg = <0x10>;
+   #address-cells = <1>;
+   #size-cells = <0>;
+
+   gphy0: eth-phy@10 {
+   reg = <0x10>;
+   };
+   };
+};
diff --git a/arch/arm64/boot/dts/broadcom/ns2.dtsi 
b/arch/arm64/boot/dts/broadcom/ns2.dtsi
index 6f81c9d..efc320a 100644
--- a/arch/arm64/boot/dts/broadcom/ns2.dtsi
+++ b/arch/arm64/boot/dts/broadcom/ns2.dtsi
@@ -330,6 +330,38 @@
  <0x6526 0x1000>;
};
 
+   mdio_mux_iproc: mdio_mux_iproc@6602023c {
+   compatible = "brcm,mdio-mux-iproc";
+   reg = <0x6602023c 0x14>;
+   #address-cells = <1>;
+   #size-cells = <0>;
+   mdio-integrated-mux;
+
+   mdio@0 {
+   reg = <0x0>;
+   #address-cells = <1>;
+   #size-cells = <0>;
+
+   pci_phy0: pci-phy@0 {
+   compatible = "brcm,ns2-pcie-phy";
+   reg = <0x0>;
+   #phy-cells = <0>;
+   };
+   };
+
+   mdio@7 {
+   reg = <0x7>;
+   #address-cells = <1>;
+   #size-cells = <0>;
+
+   pci_phy1: pci-phy@0 {
+   compatible = "brcm,ns2-pcie-phy";
+   reg = <0x0>;
+   #phy-cells = <0>;
+   };
+   };
+   };
+
timer0: timer@6603 {
compatible = "arm,sp804", "arm,primecell";
reg = <0x6603 0x1000>;
-- 
1.9.1



[PATCH 6/7] Binding:PHY: Binding doc for NS2 PCIe PHYs.

2016-05-30 Thread Pramod Kumar
Binding doc for NS2 PCIe PHYs.

Signed-off-by: Jon Mason 
Signed-off-by: Pramod Kumar 
---
 .../bindings/phy/brcm,mdio-mux-bus-pci.txt | 27 ++
 1 file changed, 27 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/phy/brcm,mdio-mux-bus-pci.txt

diff --git a/Documentation/devicetree/bindings/phy/brcm,mdio-mux-bus-pci.txt 
b/Documentation/devicetree/bindings/phy/brcm,mdio-mux-bus-pci.txt
new file mode 100644
index 000..5b51007
--- /dev/null
+++ b/Documentation/devicetree/bindings/phy/brcm,mdio-mux-bus-pci.txt
@@ -0,0 +1,27 @@
+* Broadcom NS2 PCIe PHY binding document
+
+Required bus properties:
+- reg: MDIO Bus number for the MDIO interface
+- #address-cells: must be 1
+- #size-cells: must be 0
+
+Required PHY properties:
+- compatible: should be "brcm,ns2-pcie-phy"
+- reg: MDIO Phy ID for the MDIO interface
+- #phy-cells: must be 0
+
+This is a child bus node of "brcm,mdio-mux-iproc" node.
+
+Example:
+
+mdio@0 {
+   reg = <0x0>;
+   #address-cells = <1>;
+   #size-cells = <0>;
+
+   pci_phy0: pci-phy@0 {
+   compatible = "brcm,ns2-pcie-phy";
+   reg = <0x0>;
+   #phy-cells = <0>;
+   };
+};
-- 
1.9.1



[PATCH 0/7] Add MDIO bus multiplexer support for iProc SoCs

2016-05-30 Thread Pramod Kumar
Broadcom iProc based SoCs use a MDIO bus multiplexer where child buses
could be internal as well external to SoCs. These buses could supports
MDIO transaction compatible to C-22/C-45.

Broadcom MDIO bus mulitplexer is an integrated multiplexer where child bus
selection and mdio transaction logic lies inside multiplexer itself.
To accommodate this multiplexer in existing mux framework below changes
were required-

1. Passed MDIO parent bus via mdio_mux_init to MDIO mux framework.

2. Defined one new boolean property named "mdio-integrated-mux". Integrated
   bus Multiplexer node defines this so when parent bus is registered
   by calling "of_mdiobus_register", this api will not scan for child
   nodes. Child node of integrated multiplexer will be muxed nodes not
   PHYs one hence should not be scanned.

This patch set includes MDIO bus multiplexer driver along with above
framework changes. It includes one external bus node having Ethernet PHY
attached and two internal bus node holding PCIe PHYs.

This patch series is based on v4.6.0-rc1 and is available from github-
repo: https://github.com/Broadcom/arm64-linux.git
branch:mdio-mux-v1

Pramod Kumar (7):
  mdio:mux: Enhanced MDIO mux framework for integrated multiplexers
  DT: phy.txt: Add mdio-integrated-mux property
  binding: mdio-mux: Add DT binding doc for Broadcom MDIO bus mutiplexer
  DT:mdio-mux: Add mdio multiplexer driver node
  net:mdio-mux: Add MDIO mux driver for iProc SoCs
  Binding:PHY: Binding doc for NS2 PCIe PHYs.
  phy: Add Northstar2 PCI Phy support

 .../bindings/net/brcm,mdio-mux-iproc.txt   |  64 +
 Documentation/devicetree/bindings/net/mdio-mux.txt |   9 +-
 .../bindings/phy/brcm,mdio-mux-bus-pci.txt |  27 +++
 arch/arm64/boot/dts/broadcom/ns2-svk.dts   |  12 +
 arch/arm64/boot/dts/broadcom/ns2.dtsi  |  32 +++
 drivers/net/phy/Kconfig|  11 +
 drivers/net/phy/Makefile   |   1 +
 drivers/net/phy/mdio-mux-bcm-iproc.c   | 263 +
 drivers/net/phy/mdio-mux-gpio.c|   2 +-
 drivers/net/phy/mdio-mux-mmioreg.c |   2 +-
 drivers/net/phy/mdio-mux.c |  28 ++-
 drivers/of/of_mdio.c   |   3 +
 drivers/phy/Kconfig|   8 +
 drivers/phy/Makefile   |   1 +
 drivers/phy/phy-bcm-ns2-pcie.c | 115 +
 include/linux/mdio-mux.h   |   4 +-
 16 files changed, 568 insertions(+), 14 deletions(-)
 create mode 100644 
Documentation/devicetree/bindings/net/brcm,mdio-mux-iproc.txt
 create mode 100644 
Documentation/devicetree/bindings/phy/brcm,mdio-mux-bus-pci.txt
 create mode 100644 drivers/net/phy/mdio-mux-bcm-iproc.c
 create mode 100644 drivers/phy/phy-bcm-ns2-pcie.c

-- 
1.9.1



[PATCH 7/7] phy: Add Northstar2 PCI Phy support

2016-05-30 Thread Pramod Kumar
Add PCI Phy support for Broadcom Northstar2 SoCs.  This driver uses the
interface from the iproc mdio mux driver to enable the devices
respective phys.

Signed-off-by: Jon Mason 
Signed-off-by: Pramod Kumar 
---
 drivers/phy/Kconfig|   8 +++
 drivers/phy/Makefile   |   1 +
 drivers/phy/phy-bcm-ns2-pcie.c | 115 +
 3 files changed, 124 insertions(+)
 create mode 100644 drivers/phy/phy-bcm-ns2-pcie.c

diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig
index 26566db..5ff60b2 100644
--- a/drivers/phy/Kconfig
+++ b/drivers/phy/Kconfig
@@ -421,4 +421,12 @@ config PHY_CYGNUS_PCIE
  Enable this to support the Broadcom Cygnus PCIe PHY.
  If unsure, say N.
 
+config PHY_NS2_PCIE
+   tristate "Broadcom Northstar2 PCIe PHY driver"
+   depends on OF && MDIO_BUS_MUX_BCM_IPROC
+   select GENERIC_PHY
+   default ARCH_BCM_IPROC
+   help
+ Enable this to support the Broadcom Northstar2 PCIe PHY.
+ If unsure, say N.
 endmenu
diff --git a/drivers/phy/Makefile b/drivers/phy/Makefile
index 24596a9..77d51ff 100644
--- a/drivers/phy/Makefile
+++ b/drivers/phy/Makefile
@@ -52,3 +52,4 @@ obj-$(CONFIG_PHY_TUSB1210)+= phy-tusb1210.o
 obj-$(CONFIG_PHY_BRCMSTB_SATA) += phy-brcmstb-sata.o
 obj-$(CONFIG_PHY_PISTACHIO_USB)+= phy-pistachio-usb.o
 obj-$(CONFIG_PHY_CYGNUS_PCIE)  += phy-bcm-cygnus-pcie.o
+obj-$(CONFIG_PHY_NS2_PCIE) += phy-bcm-ns2-pcie.o
diff --git a/drivers/phy/phy-bcm-ns2-pcie.c b/drivers/phy/phy-bcm-ns2-pcie.c
new file mode 100644
index 000..65c3870
--- /dev/null
+++ b/drivers/phy/phy-bcm-ns2-pcie.c
@@ -0,0 +1,115 @@
+/*
+ * Copyright (C) 2016 Broadcom
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation version 2.
+ *
+ * This program is distributed "as is" WITHOUT ANY WARRANTY of any
+ * kind, whether express or implied; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+struct ns2_pci_phy {
+   struct mdio_device *mdiodev;
+   struct phy *phy;
+};
+
+#define BLK_ADDR_REG_OFFSET0x1f
+#define PLL_AFE1_100MHZ_BLK0x2100
+#define PLL_CLK_AMP_OFFSET 0x03
+#define PLL_CLK_AMP_2P05V  0x2b18
+
+static int ns2_pci_phy_init(struct phy *p)
+{
+   struct ns2_pci_phy *phy = phy_get_drvdata(p);
+   int rc;
+
+   /* select the AFE 100MHz block page */
+   rc = mdiobus_write(phy->mdiodev->bus, phy->mdiodev->addr,
+  BLK_ADDR_REG_OFFSET, PLL_AFE1_100MHZ_BLK);
+   if (rc)
+   goto err;
+
+   /* set the 100 MHz reference clock amplitude to 2.05 v */
+   rc = mdiobus_write(phy->mdiodev->bus, phy->mdiodev->addr,
+  PLL_CLK_AMP_OFFSET, PLL_CLK_AMP_2P05V);
+   if (rc)
+   goto err;
+
+   return 0;
+
+err:
+   dev_err(>mdiodev->dev, "Error %d writing to phy\n", rc);
+   return rc;
+}
+
+static struct phy_ops ns2_pci_phy_ops = {
+   .init = ns2_pci_phy_init,
+};
+
+static int ns2_pci_phy_probe(struct mdio_device *mdiodev)
+{
+   struct device *dev = >dev;
+   struct phy_provider *provider;
+   struct ns2_pci_phy *p;
+   struct phy *phy;
+
+   phy = devm_phy_create(dev, dev->of_node, _pci_phy_ops);
+   if (IS_ERR_OR_NULL(phy)) {
+   dev_err(dev, "failed to create Phy\n");
+   return PTR_ERR(phy);
+   }
+
+   p = devm_kmalloc(dev, sizeof(struct ns2_pci_phy),
+GFP_KERNEL);
+   if (!p)
+   return -ENOMEM;
+
+   p->mdiodev = mdiodev;
+   dev_set_drvdata(dev, p);
+
+   p->phy = phy;
+   phy_set_drvdata(phy, p);
+
+   provider = devm_of_phy_provider_register(>dev,
+of_phy_simple_xlate);
+   if (IS_ERR(provider)) {
+   dev_err(dev, "failed to register Phy provider\n");
+   return PTR_ERR(provider);
+   }
+
+   dev_info(dev, "%s PHY registered\n", dev_name(dev));
+
+   return 0;
+}
+
+static const struct of_device_id ns2_pci_phy_of_match[] = {
+   { .compatible = "brcm,ns2-pcie-phy", },
+   { /* sentinel */ },
+};
+MODULE_DEVICE_TABLE(of, ns2_pci_phy_of_match);
+
+static struct mdio_driver ns2_pci_phy_driver = {
+   .mdiodrv = {
+   .driver = {
+   .name = "phy-bcm-ns2-pci",
+   .of_match_table = ns2_pci_phy_of_match,
+   },
+   },
+   .probe = ns2_pci_phy_probe,
+};
+mdio_module_driver(ns2_pci_phy_driver);
+
+MODULE_AUTHOR("Broadcom");
+MODULE_DESCRIPTION("Broadcom Northstar2 PCI Phy driver");

[PATCH 2/7] DT: phy.txt: Add mdio-integrated-mux property

2016-05-30 Thread Pramod Kumar
This property is used by integrated MDIO multiplexer
which has bus selection and mdio transaction generation logic,
integrated inside.

Signed-off-by: Pramod Kumar 
---
 Documentation/devicetree/bindings/net/mdio-mux.txt | 9 -
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/net/mdio-mux.txt 
b/Documentation/devicetree/bindings/net/mdio-mux.txt
index 491f5bd..b5ad83e 100644
--- a/Documentation/devicetree/bindings/net/mdio-mux.txt
+++ b/Documentation/devicetree/bindings/net/mdio-mux.txt
@@ -5,13 +5,20 @@ numbered uniquely in a device dependent manner.  The nodes 
for an MDIO
 bus multiplexer/switch will have one child node for each child bus.
 
 Required properties:
-- mdio-parent-bus : phandle to the parent MDIO bus.
 - #address-cells = <1>;
 - #size-cells = <0>;
 
 Optional properties:
+- mdio-parent-bus : phandle to the parent MDIO bus. Should be used
+   if parent mdio bus is not part of multiplexer.
+- mdio-integrated-mux: boolean property indicateing that the hardware
+   is an integrated multiplex supporting muxed bus selection
+   and MDIO transaction logic generation.
 - Other properties specific to the multiplexer/switch hardware.
 
+Note: one of mdio-parent-bus and mdio-integrated-mux is mandatory to
+get parent bus regsitered.
+
 Required properties for child nodes:
 - #address-cells = <1>;
 - #size-cells = <0>;
-- 
1.9.1



[PATCH 1/7] mdio:mux: Enhanced MDIO mux framework for integrated multiplexers

2016-05-30 Thread Pramod Kumar
An integrated multiplexer uses same address space for
"muxed bus selection" and "generation of mdio transaction"
hence its good to register parent bus from mux driver.

Hence added a mechanism where mux driver could register a
parent bus and pass it down to framework via mdio_mux_init api.

Below changes are required to make this happen-

1. When mdio-mux parent bus is registered, mdio framework should not
parse for child as it will be muxed bus node not PHYs.

-created a new property "mdio-mux-bus-parent". if this property is present,
of_mdiobus_register will not scan for phys.

2. Passed down parent bus to mdio mux framework via mdio-mux-init api.

Signed-off-by: Pramod Kumar 
---
 drivers/net/phy/mdio-mux-gpio.c|  2 +-
 drivers/net/phy/mdio-mux-mmioreg.c |  2 +-
 drivers/net/phy/mdio-mux.c | 28 ++--
 drivers/of/of_mdio.c   |  3 +++
 include/linux/mdio-mux.h   |  4 +++-
 5 files changed, 26 insertions(+), 13 deletions(-)

diff --git a/drivers/net/phy/mdio-mux-gpio.c b/drivers/net/phy/mdio-mux-gpio.c
index 7ddb1ab..9199499 100644
--- a/drivers/net/phy/mdio-mux-gpio.c
+++ b/drivers/net/phy/mdio-mux-gpio.c
@@ -55,7 +55,7 @@ static int mdio_mux_gpio_probe(struct platform_device *pdev)
return PTR_ERR(s->gpios);
 
r = mdio_mux_init(>dev,
- mdio_mux_gpio_switch_fn, >mux_handle, s);
+ mdio_mux_gpio_switch_fn, >mux_handle, s, NULL);
 
if (r != 0) {
gpiod_put_array(s->gpios);
diff --git a/drivers/net/phy/mdio-mux-mmioreg.c 
b/drivers/net/phy/mdio-mux-mmioreg.c
index 7fde454..d0bed52 100644
--- a/drivers/net/phy/mdio-mux-mmioreg.c
+++ b/drivers/net/phy/mdio-mux-mmioreg.c
@@ -126,7 +126,7 @@ static int mdio_mux_mmioreg_probe(struct platform_device 
*pdev)
}
 
ret = mdio_mux_init(>dev, mdio_mux_mmioreg_switch_fn,
-   >mux_handle, s);
+   >mux_handle, s, NULL);
if (ret) {
dev_err(>dev, "failed to register mdio-mux bus %s\n",
np->full_name);
diff --git a/drivers/net/phy/mdio-mux.c b/drivers/net/phy/mdio-mux.c
index 308ade0..521ab90 100644
--- a/drivers/net/phy/mdio-mux.c
+++ b/drivers/net/phy/mdio-mux.c
@@ -95,7 +95,8 @@ static int parent_count;
 int mdio_mux_init(struct device *dev,
  int (*switch_fn)(int cur, int desired, void *data),
  void **mux_handle,
- void *data)
+ void *data,
+ struct mii_bus *mux_bus)
 {
struct device_node *parent_bus_node;
struct device_node *child_bus_node;
@@ -107,10 +108,21 @@ int mdio_mux_init(struct device *dev,
if (!dev->of_node)
return -ENODEV;
 
-   parent_bus_node = of_parse_phandle(dev->of_node, "mdio-parent-bus", 0);
+   if (!mux_bus) {
+   parent_bus_node = of_parse_phandle(dev->of_node,
+  "mdio-parent-bus", 0);
 
-   if (!parent_bus_node)
-   return -ENODEV;
+   if (!parent_bus_node)
+   return -ENODEV;
+
+   parent_bus = of_mdio_find_bus(parent_bus_node);
+   if (!parent_bus) {
+   ret_val = -EPROBE_DEFER;
+   goto err_parent_bus;
+   }
+   } else {
+   parent_bus = mux_bus;
+   }
 
pb = devm_kzalloc(dev, sizeof(*pb), GFP_KERNEL);
if (pb == NULL) {
@@ -118,11 +130,6 @@ int mdio_mux_init(struct device *dev,
goto err_parent_bus;
}
 
-   parent_bus = of_mdio_find_bus(parent_bus_node);
-   if (parent_bus == NULL) {
-   ret_val = -EPROBE_DEFER;
-   goto err_parent_bus;
-   }
 
pb->switch_data = data;
pb->switch_fn = switch_fn;
@@ -183,7 +190,8 @@ int mdio_mux_init(struct device *dev,
put_device(>mii_bus->dev);
 
 err_parent_bus:
-   of_node_put(parent_bus_node);
+   if (!mux_bus)
+   of_node_put(parent_bus_node);
return ret_val;
 }
 EXPORT_SYMBOL_GPL(mdio_mux_init);
diff --git a/drivers/of/of_mdio.c b/drivers/of/of_mdio.c
index 8453f08..cf40e7a 100644
--- a/drivers/of/of_mdio.c
+++ b/drivers/of/of_mdio.c
@@ -225,6 +225,9 @@ int of_mdiobus_register(struct mii_bus *mdio, struct 
device_node *np)
if (rc)
return rc;
 
+   if (of_property_read_bool(np, "mdio-integrated-mux"))
+   return 0;
+
/* Loop over the child nodes and register a phy_device for each phy */
for_each_available_child_of_node(np, child) {
addr = of_mdio_parse_addr(>dev, child);
diff --git a/include/linux/mdio-mux.h b/include/linux/mdio-mux.h
index a243dbb..61f5b21 100644
--- a/include/linux/mdio-mux.h
+++ b/include/linux/mdio-mux.h
@@ -10,11 +10,13 @@
 #ifndef __LINUX_MDIO_MUX_H
 #define __LINUX_MDIO_MUX_H
 

Re: [PATCH] net: l2tp: Make l2tp_ip6 namespace aware

2016-05-30 Thread David Miller
From: Shmulik Ladkani 
Date: Thu, 26 May 2016 20:16:36 +0300

> l2tp_ip6 tunnel and session lookups were still using init_net, although
> the l2tp core infrastructure already supports lookups keyed by 'net'.
> 
> As a result, l2tp_ip6_recv discarded packets for tunnels/sessions
> created in namespaces other than the init_net.
> 
> Fix, by using dev_net(skb->dev) or sock_net(sk) where appropriate.
> 
> Signed-off-by: Shmulik Ladkani 

Applied.


Re: [PATCH v2] net: alx: use custom skb allocator

2016-05-30 Thread Feng Tang
Hi Eric,

On Thu, May 26, 2016 at 06:08:22AM -0700, Eric Dumazet wrote:
> On Thu, 2016-05-26 at 16:41 +0800, Feng Tang wrote:
> > On Wed, May 25, 2016 at 07:53:41PM -0400, David Miller wrote:
> 
> > > 
> > > But now that we have at least two instances of this code we really
> > > need to put a common version somewhere. :-/
> > 
> > I agree, and furthermore I noticed there are some similar routines
> > in the 4 individual Atheros drivers atlx/alx/atl1c/atl1e, which may
> > be unified by a simple framework for them all. Maybe the driver
> > maintainer from Atheros could take a look, as they can reach all
> > the real HWs :)
> 
> Note that you could also use the napi_get_frags() API that other drivers
> use, and you attach page frags to the skb.
> 
> (Ie use small skb->head allocations where the stack will pull the
> headers, but use your own page based allocations for the frames)
> 
> This might allow you to use the page reuse trick that some Intel drivers
> use.
> 
> Look for igb_can_reuse_rx_page() for an example.

Thanks for the detail hints.

When working on unifying the 2 same fixes in atl1c and alx driver, I gave
the problem a second thought. As the problem is due to a HW problem
(most likely), which is just about the DMA RX address, that if the addr is
close to the page boundary: 0x...f80(raw skb->data, and actual DMA
addr set to HW is 0x...fc0), the dma will fail with RX overflow error. And
this is really not the fault of current skb allocation APIs.

Maybe we can simply drop the skb with 0x...f80 address, and re-apply a new
one. This is a workaroun of HW issue of some Atheros devices, and it has
some advantages:
1. We don't need to create a custom skb allocator.
2. The performance effect is small. First the 0x..f80 skb only happens with
some MTU. Secondly even for where the 0x..f80 could happen, it will only get
about 1/16 chance, as the __netdev_alloc_dev will make 16 2KB skb for each
32KB batch buffer allocation

This workaround works fine on my Y580, and I will send it to bugzlla for
others' try.

Thanks,
Feng


Re: [PATCH v2 03/10] nl80211: Prefer ether_addr_copy

2016-05-30 Thread Kirtika Ruchandani
> This looks right to me, but doesn't ether_addr_copy() have alignment
> requirements? Could someone more familiar with that review these
> changes to ensure they're met?

Thanks for catching this.
The requirement is to be __aligned(2). I've added 4 instances of
ether_addr_copy with 8 addresses as arguments.  Of these, the 4
src arguments are really the same type (i.e. nla_data acting on a
const nlattr*), so I'll try to reason about the 5 total cases below -
1. cfg->dst_mac should be 16-bit aligned due to the layout of
struct cfg80211_wowlan_tcp. Its offset is 10 or 12 bytes in the
structure depending on the system.
2 and 3. For mac_addr and mac_addr_mask, nl80211_parse_random_mac
takes these in as u8* (and hence does not guarantee alignment?)
Both the callers of this function today pass in arguments that are
explicitly __aligned(2). But this cannot be said of future potential callers
- so perhaps my patch introduces a bug?
4. Based on struct cfg80211_acl_data, acl->mac_addrs[i] should be not
guaranteed to be __aligned(2).
5. For all the nla_data src arguments, the nla_data function returns
((char*) foo + 5) for pointer foo. So likely not __aligned(2).

Based on 3, 4 and 5, this patch should be revoked, but it would be nice
to have a confirmation from someone else.


[PATCH V2 0/2] vhost_net polling optimization

2016-05-30 Thread Jason Wang
Hi:

This series tries to optimize vhost_net polling at two points:

- Stop rx polling for reduicng the unnecessary wakeups during
  handle_rx().
- Conditonally enable tx polling for reducing the unnecessary
  traversing and spinlock touching.

Test shows about 17% improvement on rx pps.

Please review

Changes from V1:
- use vhost_net_disable_vq()/vhost_net_enable_vq() instead of open
  coding.
- Add a new patch for conditionally enable tx polling.

Jason Wang (2):
  vhost_net: stop polling socket during rx processing
  vhost_net: conditionally enable tx polling

 drivers/vhost/net.c | 59 +
 1 file changed, 32 insertions(+), 27 deletions(-)

-- 
1.8.3.1



[PATCH V2 2/2] vhost_net: conditionally enable tx polling

2016-05-30 Thread Jason Wang
We always poll tx for socket, this is sub optimal since:

- it will be only used when we exceed the sndbuf of the socket.
- since we use two independent polls for tx and vq, this will slightly
  increase the waitqueue traversing time and more important, vhost
  could not benefit from commit
  9e641bdcfa4ef4d6e2fbaa59c1be0ad5d1551fd5 ("net-tun: restructure
  tun_do_read for better sleep/wakeup efficiency") even if we've
  stopped rx polling during handle_rx since tx poll were still left in
  the waitqueue.

Fix this by conditionally enable tx polling only when -EAGAIN were
met.

Test shows about 8% improvement on guest rx pps.

Before: ~135
After:  ~146

Signed-off-by: Jason Wang 
---
 drivers/vhost/net.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c
index e91603b..5a05fa0 100644
--- a/drivers/vhost/net.c
+++ b/drivers/vhost/net.c
@@ -378,6 +378,7 @@ static void handle_tx(struct vhost_net *net)
goto out;
 
vhost_disable_notify(>dev, vq);
+   vhost_net_disable_vq(net, vq);
 
hdr_size = nvq->vhost_hlen;
zcopy = nvq->ubufs;
@@ -459,6 +460,8 @@ static void handle_tx(struct vhost_net *net)
% UIO_MAXIOV;
}
vhost_discard_vq_desc(vq, 1);
+   if (err == -EAGAIN)
+   vhost_net_enable_vq(net, vq);
break;
}
if (err != len)
-- 
1.8.3.1



[PATCH V2 1/2] vhost_net: stop polling socket during rx processing

2016-05-30 Thread Jason Wang
We don't stop rx polling socket during rx processing, this will lead
unnecessary wakeups from under layer net devices (E.g
sock_def_readable() form tun). Rx will be slowed down in this
way. This patch avoids this by stop polling socket during rx
processing. A small drawback is that this introduces some overheads in
light load case because of the extra start/stop polling, but single
netperf TCP_RR does not notice any change. In a super heavy load case,
e.g using pktgen to inject packet to guest, we get about ~8.8%
improvement on pps:

before: ~124 pkt/s
after:  ~135 pkt/s

Signed-off-by: Jason Wang 
---
 drivers/vhost/net.c | 56 +++--
 1 file changed, 29 insertions(+), 27 deletions(-)

diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c
index 10ff494..e91603b 100644
--- a/drivers/vhost/net.c
+++ b/drivers/vhost/net.c
@@ -301,6 +301,32 @@ static bool vhost_can_busy_poll(struct vhost_dev *dev,
   !vhost_has_work(dev);
 }
 
+static void vhost_net_disable_vq(struct vhost_net *n,
+struct vhost_virtqueue *vq)
+{
+   struct vhost_net_virtqueue *nvq =
+   container_of(vq, struct vhost_net_virtqueue, vq);
+   struct vhost_poll *poll = n->poll + (nvq - n->vqs);
+   if (!vq->private_data)
+   return;
+   vhost_poll_stop(poll);
+}
+
+static int vhost_net_enable_vq(struct vhost_net *n,
+   struct vhost_virtqueue *vq)
+{
+   struct vhost_net_virtqueue *nvq =
+   container_of(vq, struct vhost_net_virtqueue, vq);
+   struct vhost_poll *poll = n->poll + (nvq - n->vqs);
+   struct socket *sock;
+
+   sock = vq->private_data;
+   if (!sock)
+   return 0;
+
+   return vhost_poll_start(poll, sock->file);
+}
+
 static int vhost_net_tx_get_vq_desc(struct vhost_net *net,
struct vhost_virtqueue *vq,
struct iovec iov[], unsigned int iov_size,
@@ -627,6 +653,7 @@ static void handle_rx(struct vhost_net *net)
if (!sock)
goto out;
vhost_disable_notify(>dev, vq);
+   vhost_net_disable_vq(net, vq);
 
vhost_hlen = nvq->vhost_hlen;
sock_hlen = nvq->sock_hlen;
@@ -715,9 +742,10 @@ static void handle_rx(struct vhost_net *net)
total_len += vhost_len;
if (unlikely(total_len >= VHOST_NET_WEIGHT)) {
vhost_poll_queue(>poll);
-   break;
+   goto out;
}
}
+   vhost_net_enable_vq(net, vq);
 out:
mutex_unlock(>mutex);
 }
@@ -796,32 +824,6 @@ static int vhost_net_open(struct inode *inode, struct file 
*f)
return 0;
 }
 
-static void vhost_net_disable_vq(struct vhost_net *n,
-struct vhost_virtqueue *vq)
-{
-   struct vhost_net_virtqueue *nvq =
-   container_of(vq, struct vhost_net_virtqueue, vq);
-   struct vhost_poll *poll = n->poll + (nvq - n->vqs);
-   if (!vq->private_data)
-   return;
-   vhost_poll_stop(poll);
-}
-
-static int vhost_net_enable_vq(struct vhost_net *n,
-   struct vhost_virtqueue *vq)
-{
-   struct vhost_net_virtqueue *nvq =
-   container_of(vq, struct vhost_net_virtqueue, vq);
-   struct vhost_poll *poll = n->poll + (nvq - n->vqs);
-   struct socket *sock;
-
-   sock = vq->private_data;
-   if (!sock)
-   return 0;
-
-   return vhost_poll_start(poll, sock->file);
-}
-
 static struct socket *vhost_net_stop_vq(struct vhost_net *n,
struct vhost_virtqueue *vq)
 {
-- 
1.8.3.1



Re: [PATCH v2 06/10] nl80211: Various checkpatch.pl spacing fixes

2016-05-30 Thread Julian Calaby
Hi All,

On Mon, May 30, 2016 at 12:53 PM, Kirtika Ruchandani
 wrote:
> This patch fixes the following spacing issues reported
> by checkpatch.pl -
> - space preferred around that 
> - no space needed after cast.
> - Alignment should match open parenthesis
> - suspect code indent for conditional statements
> - Statements should start on a tabstop
>
> This patch also contains two hunks to fix 'line over 80 characters',
> that are spacing related.
> All other instances of that warning have been ignored.
>
> Signed-off-by: Kirtika Ruchandani 

With Kirtika's explanation, this is:

Reviewed-by: Julian Calaby 

Thanks,

Julian Calaby


> ---
>  net/wireless/nl80211.c | 103 
> ++---
>  1 file changed, 54 insertions(+), 49 deletions(-)
>
> diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c
> index 11cbf0b..ad7cdce 100644
> --- a/net/wireless/nl80211.c
> +++ b/net/wireless/nl80211.c
> @@ -39,10 +39,10 @@ static void nl80211_post_doit(const struct genl_ops *ops, 
> struct sk_buff *skb,
>
>  /* the netlink family */
>  static struct genl_family nl80211_fam = {
> -   .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */
> -   .name = NL80211_GENL_NAME,  /* have users key off the name 
> instead */
> -   .hdrsize = 0,   /* no private header */
> -   .version = 1,   /* no particular meaning now */
> +   .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */
> +   .name = NL80211_GENL_NAME,  /* have users key off the name instead */
> +   .hdrsize = 0,   /* no private header */
> +   .version = 1,   /* no particular meaning now */
> .maxattr = NL80211_ATTR_MAX,
> .netnsok = true,
> .pre_doit = nl80211_pre_doit,
> @@ -213,7 +213,7 @@ cfg80211_get_dev_from_info(struct net *netns, struct 
> genl_info *info)
>  static const struct nla_policy nl80211_policy[NUM_NL80211_ATTR] = {
> [NL80211_ATTR_WIPHY] = { .type = NLA_U32 },
> [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING,
> - .len = 20-1 },
> + .len = 20 - 1 },
> [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED },
>
> [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 },
> @@ -231,7 +231,7 @@ static const struct nla_policy 
> nl80211_policy[NUM_NL80211_ATTR] = {
>
> [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 },
> [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 },
> -   [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 },
> +   [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ - 1 
> },
>
> [NL80211_ATTR_MAC] = { .len = ETH_ALEN },
> [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN },
> @@ -967,7 +967,7 @@ static int nl80211_put_iface_combinations(struct wiphy 
> *wiphy,
> int i, j;
>
> nl_combis = nla_nest_start(msg,
> -   NL80211_ATTR_INTERFACE_COMBINATIONS);
> +  NL80211_ATTR_INTERFACE_COMBINATIONS);
> if (!nl_combis)
> goto nla_put_failure;
>
> @@ -1012,9 +1012,9 @@ static int nl80211_put_iface_combinations(struct wiphy 
> *wiphy,
> goto nla_put_failure;
> if (large &&
> (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS,
> -   c->radar_detect_widths) ||
> +c->radar_detect_widths) ||
>  nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS,
> -   c->radar_detect_regions)))
> +c->radar_detect_regions)))
> goto nla_put_failure;
>
> nla_nest_end(msg, nl_combi);
> @@ -1493,7 +1493,7 @@ static int nl80211_send_wiphy(struct 
> cfg80211_registered_device *rdev,
>
> i = 0;
>  #define CMD(op, n) \
> -do {   \
> +   do {\
> if (rdev->ops->op) {\
> i++;\
> if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
> @@ -1735,8 +1735,9 @@ static int nl80211_send_wiphy(struct 
> cfg80211_registered_device *rdev,
>rdev->wiphy.max_num_csa_counters))
> goto nla_put_failure;
>
> -   if (rdev->wiphy.regulatory_flags & 
> REGULATORY_WIPHY_SELF_MANAGED &&
> -   nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
> +   if ((rdev->wiphy.regulatory_flags &
> +  

  1   2   >