[PATCHv2 net-next 1/1] net: rds: use memset to optimize the recv

2018-09-16 Thread Zhu Yanjun
The function rds_inc_init is in recv process. To use memset can optimize
the function rds_inc_init.
The test result:

 Before:
 1) + 24.950 us   |rds_inc_init [rds]();
 After:
 1) + 10.990 us   |rds_inc_init [rds]();

Acked-by: Santosh Shilimkar 
Signed-off-by: Zhu Yanjun 
---
V1->V2: a new patch for net-next
---
 net/rds/recv.c | 5 +
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/net/rds/recv.c b/net/rds/recv.c
index 12719653188a..727639dac8a7 100644
--- a/net/rds/recv.c
+++ b/net/rds/recv.c
@@ -43,8 +43,6 @@
 void rds_inc_init(struct rds_incoming *inc, struct rds_connection *conn,
 struct in6_addr *saddr)
 {
-   int i;
-
refcount_set(>i_refcount, 1);
INIT_LIST_HEAD(>i_item);
inc->i_conn = conn;
@@ -52,8 +50,7 @@ void rds_inc_init(struct rds_incoming *inc, struct 
rds_connection *conn,
inc->i_rdma_cookie = 0;
inc->i_rx_tstamp = ktime_set(0, 0);
 
-   for (i = 0; i < RDS_RX_MAX_TRACES; i++)
-   inc->i_rx_lat_trace[i] = 0;
+   memset(inc->i_rx_lat_trace, 0, sizeof(inc->i_rx_lat_trace));
 }
 EXPORT_SYMBOL_GPL(rds_inc_init);
 
-- 
2.17.1



[PATCH 1/1] net: rds: use memset to optimize the recv

2018-09-14 Thread Zhu Yanjun
The function rds_inc_init is in recv process. To use memset can optimize
the function rds_inc_init.
The test result:

Before:
1) + 24.950 us   |rds_inc_init [rds]();
After:
1) + 10.990 us   |rds_inc_init [rds]();

Signed-off-by: Zhu Yanjun 
---
 net/rds/recv.c | 5 +
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/net/rds/recv.c b/net/rds/recv.c
index 504cd6bcc54c..a9399ddbb7bf 100644
--- a/net/rds/recv.c
+++ b/net/rds/recv.c
@@ -43,8 +43,6 @@
 void rds_inc_init(struct rds_incoming *inc, struct rds_connection *conn,
 struct in6_addr *saddr)
 {
-   int i;
-
refcount_set(>i_refcount, 1);
INIT_LIST_HEAD(>i_item);
inc->i_conn = conn;
@@ -53,8 +51,7 @@ void rds_inc_init(struct rds_incoming *inc, struct 
rds_connection *conn,
inc->i_rx_tstamp.tv_sec = 0;
inc->i_rx_tstamp.tv_usec = 0;
 
-   for (i = 0; i < RDS_RX_MAX_TRACES; i++)
-   inc->i_rx_lat_trace[i] = 0;
+   memset(inc->i_rx_lat_trace, 0, sizeof(inc->i_rx_lat_trace));
 }
 EXPORT_SYMBOL_GPL(rds_inc_init);
 
-- 
2.17.1



[PATCH 1/1] net/rds: Use rdma_read_gids to get connection SGID/DGID in IPv6

2018-08-25 Thread Zhu Yanjun
In IPv4, the newly introduced rdma_read_gids is used to read the SGID/DGID
for the connection which returns GID correctly for RoCE transport as well.

In IPv6, rdma_read_gids is also used. The following are why rdma_read_gids
is introduced.

rdma_addr_get_dgid() for RoCE for client side connections returns MAC
address, instead of DGID.
rdma_addr_get_sgid() for RoCE doesn't return correct SGID for IPv6 and
when more than one IP address is assigned to the netdevice.

So the transport agnostic rdma_read_gids() API is provided by rdma_cm
module.

Signed-off-by: Zhu Yanjun 
---
 net/rds/ib.c | 9 ++---
 1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/net/rds/ib.c b/net/rds/ib.c
index c1d97640c0be..eba75c1ba359 100644
--- a/net/rds/ib.c
+++ b/net/rds/ib.c
@@ -341,15 +341,10 @@ static int rds6_ib_conn_info_visitor(struct 
rds_connection *conn,
 
if (rds_conn_state(conn) == RDS_CONN_UP) {
struct rds_ib_device *rds_ibdev;
-   struct rdma_dev_addr *dev_addr;
 
ic = conn->c_transport_data;
-   dev_addr = >i_cm_id->route.addr.dev_addr;
-   rdma_addr_get_sgid(dev_addr,
-  (union ib_gid *)>src_gid);
-   rdma_addr_get_dgid(dev_addr,
-  (union ib_gid *)>dst_gid);
-
+   rdma_read_gids(ic->i_cm_id, (union ib_gid *)>src_gid,
+  (union ib_gid *)>dst_gid);
rds_ibdev = ic->rds_ibdev;
iinfo6->max_send_wr = ic->i_send_ring.w_nr;
iinfo6->max_recv_wr = ic->i_recv_ring.w_nr;
-- 
2.17.1



[PATCH 1/1] Revert "rds: ib: add error handle"

2018-04-23 Thread Zhu Yanjun
This reverts commit 3b12f73a5c2977153f28a224392fd4729b50d1dc.

After long time discussion and investigations, it seems that there
is no mem leak. So this patch is reverted.

Signed-off-by: Zhu Yanjun <yanjun@oracle.com>
---
 net/rds/ib_cm.c | 47 +++
 1 file changed, 11 insertions(+), 36 deletions(-)

diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c
index eea1d86..d64bfaf 100644
--- a/net/rds/ib_cm.c
+++ b/net/rds/ib_cm.c
@@ -443,7 +443,7 @@ static int rds_ib_setup_qp(struct rds_connection *conn)
ic->i_send_cq = NULL;
ibdev_put_vector(rds_ibdev, ic->i_scq_vector);
rdsdebug("ib_create_cq send failed: %d\n", ret);
-   goto rds_ibdev_out;
+   goto out;
}
 
ic->i_rcq_vector = ibdev_get_unused_vector(rds_ibdev);
@@ -457,19 +457,19 @@ static int rds_ib_setup_qp(struct rds_connection *conn)
ic->i_recv_cq = NULL;
ibdev_put_vector(rds_ibdev, ic->i_rcq_vector);
rdsdebug("ib_create_cq recv failed: %d\n", ret);
-   goto send_cq_out;
+   goto out;
}
 
ret = ib_req_notify_cq(ic->i_send_cq, IB_CQ_NEXT_COMP);
if (ret) {
rdsdebug("ib_req_notify_cq send failed: %d\n", ret);
-   goto recv_cq_out;
+   goto out;
}
 
ret = ib_req_notify_cq(ic->i_recv_cq, IB_CQ_SOLICITED);
if (ret) {
rdsdebug("ib_req_notify_cq recv failed: %d\n", ret);
-   goto recv_cq_out;
+   goto out;
}
 
/* XXX negotiate max send/recv with remote? */
@@ -495,7 +495,7 @@ static int rds_ib_setup_qp(struct rds_connection *conn)
ret = rdma_create_qp(ic->i_cm_id, ic->i_pd, );
if (ret) {
rdsdebug("rdma_create_qp failed: %d\n", ret);
-   goto recv_cq_out;
+   goto out;
}
 
ic->i_send_hdrs = ib_dma_alloc_coherent(dev,
@@ -505,7 +505,7 @@ static int rds_ib_setup_qp(struct rds_connection *conn)
if (!ic->i_send_hdrs) {
ret = -ENOMEM;
rdsdebug("ib_dma_alloc_coherent send failed\n");
-   goto qp_out;
+   goto out;
}
 
ic->i_recv_hdrs = ib_dma_alloc_coherent(dev,
@@ -515,7 +515,7 @@ static int rds_ib_setup_qp(struct rds_connection *conn)
if (!ic->i_recv_hdrs) {
ret = -ENOMEM;
rdsdebug("ib_dma_alloc_coherent recv failed\n");
-   goto send_hdrs_dma_out;
+   goto out;
}
 
ic->i_ack = ib_dma_alloc_coherent(dev, sizeof(struct rds_header),
@@ -523,7 +523,7 @@ static int rds_ib_setup_qp(struct rds_connection *conn)
if (!ic->i_ack) {
ret = -ENOMEM;
rdsdebug("ib_dma_alloc_coherent ack failed\n");
-   goto recv_hdrs_dma_out;
+   goto out;
}
 
ic->i_sends = vzalloc_node(ic->i_send_ring.w_nr * sizeof(struct 
rds_ib_send_work),
@@ -531,7 +531,7 @@ static int rds_ib_setup_qp(struct rds_connection *conn)
if (!ic->i_sends) {
ret = -ENOMEM;
rdsdebug("send allocation failed\n");
-   goto ack_dma_out;
+   goto out;
}
 
ic->i_recvs = vzalloc_node(ic->i_recv_ring.w_nr * sizeof(struct 
rds_ib_recv_work),
@@ -539,7 +539,7 @@ static int rds_ib_setup_qp(struct rds_connection *conn)
if (!ic->i_recvs) {
ret = -ENOMEM;
rdsdebug("recv allocation failed\n");
-   goto sends_out;
+   goto out;
}
 
rds_ib_recv_init_ack(ic);
@@ -547,33 +547,8 @@ static int rds_ib_setup_qp(struct rds_connection *conn)
rdsdebug("conn %p pd %p cq %p %p\n", conn, ic->i_pd,
 ic->i_send_cq, ic->i_recv_cq);
 
-   return ret;
-
-sends_out:
-   vfree(ic->i_sends);
-ack_dma_out:
-   ib_dma_free_coherent(dev, sizeof(struct rds_header),
-ic->i_ack, ic->i_ack_dma);
-recv_hdrs_dma_out:
-   ib_dma_free_coherent(dev, ic->i_recv_ring.w_nr *
-   sizeof(struct rds_header),
-   ic->i_recv_hdrs, ic->i_recv_hdrs_dma);
-send_hdrs_dma_out:
-   ib_dma_free_coherent(dev, ic->i_send_ring.w_nr *
-   sizeof(struct rds_header),
-   ic->i_send_hdrs, ic->i_send_hdrs_dma);
-qp_out:
-   rdma_destroy_qp(ic->i_cm_id);
-recv_cq_out:
-   if (!ib_destroy_cq(ic->i_recv_cq))
-   ic->i_recv_cq = NULL;
-send_cq_out:
-   if (!ib_destroy_cq(ic->i_send_cq))
-   ic->i_send_cq = NULL;
-rds_ibdev_out:
-   rds_ib_remove_conn(rds_ibdev, conn);
+out:
rds_ib_dev_put(rds_ibdev);
-
return ret;
 }
 
-- 
2.7.4



[PATCHv2 1/1] net/mlx4_core: avoid resetting HCA when accessing an offline device

2018-04-18 Thread Zhu Yanjun
While a faulty cable is used or HCA firmware error, HCA device will
be offline. When the driver is accessing this offline device, the
following call trace will pop out.

"
...
  [] dump_stack+0x63/0x81
  [] panic+0xcc/0x21b
  [] mlx4_enter_error_state+0xba/0xf0 [mlx4_core]
  [] mlx4_cmd_reset_flow+0x38/0x60 [mlx4_core]
  [] mlx4_cmd_poll+0xc1/0x2e0 [mlx4_core]
  [] __mlx4_cmd+0xb0/0x160 [mlx4_core]
  [] mlx4_SENSE_PORT+0x54/0xd0 [mlx4_core]
  [] mlx4_dev_cap+0x4a4/0xb50 [mlx4_core]
...
"
In the above call trace, the function mlx4_cmd_poll calls the function
mlx4_cmd_post to access the HCA while HCA is offline. Then mlx4_cmd_post
returns an error -EIO. Per -EIO, the function mlx4_cmd_poll calls
mlx4_cmd_reset_flow to reset HCA. And the above call trace pops out.

This is not reasonable. Since HCA device is offline when it is being
accessed, it should not be reset again.

In this patch, since HCA is offline, the function mlx4_cmd_post returns
an error -EINVAL. Per -EINVAL, the function mlx4_cmd_poll directly returns
instead of resetting HCA.

CC: Srinivas Eeda <srinivas.e...@oracle.com>
CC: Junxiao Bi <junxiao...@oracle.com>
Suggested-by: Håkon Bugge <haakon.bu...@oracle.com>
Suggested-by: Tariq Toukan <tar...@mellanox.com>
Signed-off-by: Zhu Yanjun <yanjun@oracle.com>
---
V1->V2: Follow Tariq's advice, avoid the disturbance from other returned errors.
Since the returned values from the function mlx4_cmd_post are -EIO and -EINVAL,
to -EIO, the HCA device should be reset. To -EINVAL, that means that the 
function
mlx4_cmd_post is accessing an offline device. It is not necessary to reset HCA.
Go to label out directly.
---
 drivers/net/ethernet/mellanox/mlx4/cmd.c | 12 ++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx4/cmd.c 
b/drivers/net/ethernet/mellanox/mlx4/cmd.c
index 6a9086d..df735b8 100644
--- a/drivers/net/ethernet/mellanox/mlx4/cmd.c
+++ b/drivers/net/ethernet/mellanox/mlx4/cmd.c
@@ -451,6 +451,8 @@ static int mlx4_cmd_post(struct mlx4_dev *dev, u64 
in_param, u64 out_param,
 * Device is going through error recovery
 * and cannot accept commands.
 */
+   mlx4_err(dev, "%s : Device is in error recovery.\n", __func__);
+   ret = -EINVAL;
goto out;
}
 
@@ -610,8 +612,11 @@ static int mlx4_cmd_poll(struct mlx4_dev *dev, u64 
in_param, u64 *out_param,
 
err = mlx4_cmd_post(dev, in_param, out_param ? *out_param : 0,
in_modifier, op_modifier, op, CMD_POLL_TOKEN, 0);
-   if (err)
+   if (err) {
+   if (err == -EINVAL)
+   goto out;
goto out_reset;
+   }
 
end = msecs_to_jiffies(timeout) + jiffies;
while (cmd_pending(dev) && time_before(jiffies, end)) {
@@ -710,8 +715,11 @@ static int mlx4_cmd_wait(struct mlx4_dev *dev, u64 
in_param, u64 *out_param,
 
err = mlx4_cmd_post(dev, in_param, out_param ? *out_param : 0,
in_modifier, op_modifier, op, context->token, 1);
-   if (err)
+   if (err) {
+   if (err == -EINVAL)
+   goto out;
goto out_reset;
+   }
 
if (op == MLX4_CMD_SENSE_PORT) {
ret_wait =
-- 
2.7.4



[PATCH 1/1] net/mlx4_core: avoid resetting HCA when accessing an offline device

2018-04-15 Thread Zhu Yanjun
While a faulty cable is used or HCA firmware error, HCA device will
be offline. When the driver is accessing this offline device, the
following call trace will pop out.

"
...
  [] dump_stack+0x63/0x81
  [] panic+0xcc/0x21b
  [] mlx4_enter_error_state+0xba/0xf0 [mlx4_core]
  [] mlx4_cmd_reset_flow+0x38/0x60 [mlx4_core]
  [] mlx4_cmd_poll+0xc1/0x2e0 [mlx4_core]
  [] __mlx4_cmd+0xb0/0x160 [mlx4_core]
  [] mlx4_SENSE_PORT+0x54/0xd0 [mlx4_core]
  [] mlx4_dev_cap+0x4a4/0xb50 [mlx4_core]
...
"
In the above call trace, the function mlx4_cmd_poll calls the function
mlx4_cmd_post to access the HCA while HCA is offline. Then mlx4_cmd_post
returns an error -EIO. Per -EIO, the function mlx4_cmd_poll calls
mlx4_cmd_reset_flow to reset HCA. And the above call trace pops out.

This is not reasonable. Since HCA device is offline when it is being
accessed, it should not be reset again.

In this patch, since HCA is offline, the function mlx4_cmd_post returns
an error -EINVAL. Per -EINVAL, the function mlx4_cmd_poll directly returns
instead of resetting HCA.

CC: Srinivas Eeda <srinivas.e...@oracle.com>
CC: Junxiao Bi <junxiao...@oracle.com>
Suggested-by: Håkon Bugge <haakon.bu...@oracle.com>
Signed-off-by: Zhu Yanjun <yanjun@oracle.com>
---
 drivers/net/ethernet/mellanox/mlx4/cmd.c | 8 
 1 file changed, 8 insertions(+)

diff --git a/drivers/net/ethernet/mellanox/mlx4/cmd.c 
b/drivers/net/ethernet/mellanox/mlx4/cmd.c
index 6a9086d..f1c8c42 100644
--- a/drivers/net/ethernet/mellanox/mlx4/cmd.c
+++ b/drivers/net/ethernet/mellanox/mlx4/cmd.c
@@ -451,6 +451,8 @@ static int mlx4_cmd_post(struct mlx4_dev *dev, u64 
in_param, u64 out_param,
 * Device is going through error recovery
 * and cannot accept commands.
 */
+   mlx4_err(dev, "%s : Device is in error recovery.\n", __func__);
+   ret = -EINVAL;
goto out;
}
 
@@ -657,6 +659,9 @@ static int mlx4_cmd_poll(struct mlx4_dev *dev, u64 
in_param, u64 *out_param,
}
 
 out_reset:
+   if (err == -EINVAL)
+   goto out;
+
if (err)
err = mlx4_cmd_reset_flow(dev, op, op_modifier, err);
 out:
@@ -766,6 +771,9 @@ static int mlx4_cmd_wait(struct mlx4_dev *dev, u64 
in_param, u64 *out_param,
*out_param = context->out_param;
 
 out_reset:
+   if (err == -EINVAL)
+   goto out;
+
if (err)
err = mlx4_cmd_reset_flow(dev, op, op_modifier, err);
 out:
-- 
2.7.4



[PATCH net-next 1/1] forcedeth: remove duplicate structure member in rx

2018-01-22 Thread Zhu Yanjun
Since both first_rx_ctx and rx_skb are the head of rx ctx, it not
necessary to use two structure members to statically indicate
the head of rx ctx. So first_rx_ctx is removed.

CC: Srinivas Eeda <srinivas.e...@oracle.com>
CC: Joe Jin <joe@oracle.com>
CC: Junxiao Bi <junxiao...@oracle.com>
Signed-off-by: Zhu Yanjun <yanjun@oracle.com>
---
 drivers/net/ethernet/nvidia/forcedeth.c | 13 +++--
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/drivers/net/ethernet/nvidia/forcedeth.c 
b/drivers/net/ethernet/nvidia/forcedeth.c
index a3f6d51..66c665d 100644
--- a/drivers/net/ethernet/nvidia/forcedeth.c
+++ b/drivers/net/ethernet/nvidia/forcedeth.c
@@ -795,7 +795,7 @@ struct fe_priv {
 */
union ring_type get_rx, put_rx, last_rx;
struct nv_skb_map *get_rx_ctx, *put_rx_ctx;
-   struct nv_skb_map *first_rx_ctx, *last_rx_ctx;
+   struct nv_skb_map *last_rx_ctx;
struct nv_skb_map *rx_skb;
 
union ring_type rx_ring;
@@ -1835,7 +1835,7 @@ static int nv_alloc_rx(struct net_device *dev)
if (unlikely(np->put_rx.orig++ == np->last_rx.orig))
np->put_rx.orig = np->rx_ring.orig;
if (unlikely(np->put_rx_ctx++ == np->last_rx_ctx))
-   np->put_rx_ctx = np->first_rx_ctx;
+   np->put_rx_ctx = np->rx_skb;
} else {
 packet_dropped:
u64_stats_update_begin(>swstats_rx_syncp);
@@ -1877,7 +1877,7 @@ static int nv_alloc_rx_optimized(struct net_device *dev)
if (unlikely(np->put_rx.ex++ == np->last_rx.ex))
np->put_rx.ex = np->rx_ring.ex;
if (unlikely(np->put_rx_ctx++ == np->last_rx_ctx))
-   np->put_rx_ctx = np->first_rx_ctx;
+   np->put_rx_ctx = np->rx_skb;
} else {
 packet_dropped:
u64_stats_update_begin(>swstats_rx_syncp);
@@ -1910,7 +1910,8 @@ static void nv_init_rx(struct net_device *dev)
np->last_rx.orig = >rx_ring.orig[np->rx_ring_size-1];
else
np->last_rx.ex = >rx_ring.ex[np->rx_ring_size-1];
-   np->get_rx_ctx = np->put_rx_ctx = np->first_rx_ctx = np->rx_skb;
+   np->get_rx_ctx = np->rx_skb;
+   np->put_rx_ctx = np->rx_skb;
np->last_rx_ctx = >rx_skb[np->rx_ring_size-1];
 
for (i = 0; i < np->rx_ring_size; i++) {
@@ -2914,7 +2915,7 @@ static int nv_rx_process(struct net_device *dev, int 
limit)
if (unlikely(np->get_rx.orig++ == np->last_rx.orig))
np->get_rx.orig = np->rx_ring.orig;
if (unlikely(np->get_rx_ctx++ == np->last_rx_ctx))
-   np->get_rx_ctx = np->first_rx_ctx;
+   np->get_rx_ctx = np->rx_skb;
 
rx_work++;
}
@@ -3003,7 +3004,7 @@ static int nv_rx_process_optimized(struct net_device 
*dev, int limit)
if (unlikely(np->get_rx.ex++ == np->last_rx.ex))
np->get_rx.ex = np->rx_ring.ex;
if (unlikely(np->get_rx_ctx++ == np->last_rx_ctx))
-   np->get_rx_ctx = np->first_rx_ctx;
+   np->get_rx_ctx = np->rx_skb;
 
rx_work++;
}
-- 
2.7.4



[PATCHv2 net-next 1/1] forcedeth: remove unused variable

2018-01-16 Thread Zhu Yanjun
The variable miistat is not used. So it is removed.

CC: Srinivas Eeda <srinivas.e...@oracle.com>
CC: Joe Jin <joe@oracle.com>
CC: Junxiao Bi <junxiao...@oracle.com>
Signed-off-by: Zhu Yanjun <yanjun@oracle.com>
---
v1->v2: Keep readl function
---
 drivers/net/ethernet/nvidia/forcedeth.c | 8 +++-
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/net/ethernet/nvidia/forcedeth.c 
b/drivers/net/ethernet/nvidia/forcedeth.c
index 21e15cb..a3f6d51 100644
--- a/drivers/net/ethernet/nvidia/forcedeth.c
+++ b/drivers/net/ethernet/nvidia/forcedeth.c
@@ -5510,11 +5510,9 @@ static int nv_open(struct net_device *dev)
/* One manual link speed update: Interrupts are enabled, future link
 * speed changes cause interrupts and are handled by nv_link_irq().
 */
-   {
-   u32 miistat;
-   miistat = readl(base + NvRegMIIStatus);
-   writel(NVREG_MIISTAT_MASK_ALL, base + NvRegMIIStatus);
-   }
+   readl(base + NvRegMIIStatus);
+   writel(NVREG_MIISTAT_MASK_ALL, base + NvRegMIIStatus);
+
/* set linkspeed to invalid value, thus force nv_update_linkspeed
 * to init hw */
np->linkspeed = 0;
-- 
2.7.4



[PATCH net-next 1/1] forcedeth: remove unused variable

2018-01-14 Thread Zhu Yanjun
The variable miistat is not used. So it is removed.

CC: Srinivas Eeda <srinivas.e...@oracle.com>
CC: Joe Jin <joe@oracle.com>
CC: Junxiao Bi <junxiao...@oracle.com>
Signed-off-by: Zhu Yanjun <yanjun@oracle.com>
---
 drivers/net/ethernet/nvidia/forcedeth.c | 7 ++-
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/drivers/net/ethernet/nvidia/forcedeth.c 
b/drivers/net/ethernet/nvidia/forcedeth.c
index 21e15cb..c518f8c 100644
--- a/drivers/net/ethernet/nvidia/forcedeth.c
+++ b/drivers/net/ethernet/nvidia/forcedeth.c
@@ -5510,11 +5510,8 @@ static int nv_open(struct net_device *dev)
/* One manual link speed update: Interrupts are enabled, future link
 * speed changes cause interrupts and are handled by nv_link_irq().
 */
-   {
-   u32 miistat;
-   miistat = readl(base + NvRegMIIStatus);
-   writel(NVREG_MIISTAT_MASK_ALL, base + NvRegMIIStatus);
-   }
+   writel(NVREG_MIISTAT_MASK_ALL, base + NvRegMIIStatus);
+
/* set linkspeed to invalid value, thus force nv_update_linkspeed
 * to init hw */
np->linkspeed = 0;
-- 
2.7.4



[PATCH NET-NEXT 1/1] forcedeth: remove duplicate structure member in rx

2018-01-04 Thread Zhu Yanjun
Since both first_rx and rx_ring are the head of rx ring, it not
necessary to use two structure members to statically indicate
the head of rx ring. So first_rx is removed.

CC: Srinivas Eeda <srinivas.e...@oracle.com>
CC: Joe Jin <joe@oracle.com>
CC: Junxiao Bi <junxiao...@oracle.com>
Signed-off-by: Zhu Yanjun <yanjun@oracle.com>
---
 drivers/net/ethernet/nvidia/forcedeth.c | 17 +
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/drivers/net/ethernet/nvidia/forcedeth.c 
b/drivers/net/ethernet/nvidia/forcedeth.c
index a79b9f8..21e15cb 100644
--- a/drivers/net/ethernet/nvidia/forcedeth.c
+++ b/drivers/net/ethernet/nvidia/forcedeth.c
@@ -793,7 +793,7 @@ struct fe_priv {
/* rx specific fields.
 * Locking: Within irq hander or disable_irq+spin_lock(>lock);
 */
-   union ring_type get_rx, put_rx, first_rx, last_rx;
+   union ring_type get_rx, put_rx, last_rx;
struct nv_skb_map *get_rx_ctx, *put_rx_ctx;
struct nv_skb_map *first_rx_ctx, *last_rx_ctx;
struct nv_skb_map *rx_skb;
@@ -1812,7 +1812,7 @@ static int nv_alloc_rx(struct net_device *dev)
struct ring_desc *less_rx;
 
less_rx = np->get_rx.orig;
-   if (less_rx-- == np->first_rx.orig)
+   if (less_rx-- == np->rx_ring.orig)
less_rx = np->last_rx.orig;
 
while (np->put_rx.orig != less_rx) {
@@ -1833,7 +1833,7 @@ static int nv_alloc_rx(struct net_device *dev)
wmb();
np->put_rx.orig->flaglen = cpu_to_le32(np->rx_buf_sz | 
NV_RX_AVAIL);
if (unlikely(np->put_rx.orig++ == np->last_rx.orig))
-   np->put_rx.orig = np->first_rx.orig;
+   np->put_rx.orig = np->rx_ring.orig;
if (unlikely(np->put_rx_ctx++ == np->last_rx_ctx))
np->put_rx_ctx = np->first_rx_ctx;
} else {
@@ -1853,7 +1853,7 @@ static int nv_alloc_rx_optimized(struct net_device *dev)
struct ring_desc_ex *less_rx;
 
less_rx = np->get_rx.ex;
-   if (less_rx-- == np->first_rx.ex)
+   if (less_rx-- == np->rx_ring.ex)
less_rx = np->last_rx.ex;
 
while (np->put_rx.ex != less_rx) {
@@ -1875,7 +1875,7 @@ static int nv_alloc_rx_optimized(struct net_device *dev)
wmb();
np->put_rx.ex->flaglen = cpu_to_le32(np->rx_buf_sz | 
NV_RX2_AVAIL);
if (unlikely(np->put_rx.ex++ == np->last_rx.ex))
-   np->put_rx.ex = np->first_rx.ex;
+   np->put_rx.ex = np->rx_ring.ex;
if (unlikely(np->put_rx_ctx++ == np->last_rx_ctx))
np->put_rx_ctx = np->first_rx_ctx;
} else {
@@ -1903,7 +1903,8 @@ static void nv_init_rx(struct net_device *dev)
struct fe_priv *np = netdev_priv(dev);
int i;
 
-   np->get_rx = np->put_rx = np->first_rx = np->rx_ring;
+   np->get_rx = np->rx_ring;
+   np->put_rx = np->rx_ring;
 
if (!nv_optimized(np))
np->last_rx.orig = >rx_ring.orig[np->rx_ring_size-1];
@@ -2911,7 +2912,7 @@ static int nv_rx_process(struct net_device *dev, int 
limit)
u64_stats_update_end(>swstats_rx_syncp);
 next_pkt:
if (unlikely(np->get_rx.orig++ == np->last_rx.orig))
-   np->get_rx.orig = np->first_rx.orig;
+   np->get_rx.orig = np->rx_ring.orig;
if (unlikely(np->get_rx_ctx++ == np->last_rx_ctx))
np->get_rx_ctx = np->first_rx_ctx;
 
@@ -3000,7 +3001,7 @@ static int nv_rx_process_optimized(struct net_device 
*dev, int limit)
}
 next_pkt:
if (unlikely(np->get_rx.ex++ == np->last_rx.ex))
-   np->get_rx.ex = np->first_rx.ex;
+   np->get_rx.ex = np->rx_ring.ex;
if (unlikely(np->get_rx_ctx++ == np->last_rx_ctx))
np->get_rx_ctx = np->first_rx_ctx;
 
-- 
2.7.4



[PATCH net-next 1/1] forcedeth: optimize the rx with likely

2017-12-25 Thread Zhu Yanjun
In the rx fastpath, the function netdev_alloc_skb rarely fails.
Therefore, a likely() optimization is added to this error check
conditional.

CC: Srinivas Eeda <srinivas.e...@oracle.com>
CC: Joe Jin <joe@oracle.com>
CC: Junxiao Bi <junxiao...@oracle.com>
Signed-off-by: Zhu Yanjun <yanjun@oracle.com>
---
 drivers/net/ethernet/nvidia/forcedeth.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/nvidia/forcedeth.c 
b/drivers/net/ethernet/nvidia/forcedeth.c
index 49d6d78..a79b9f8 100644
--- a/drivers/net/ethernet/nvidia/forcedeth.c
+++ b/drivers/net/ethernet/nvidia/forcedeth.c
@@ -1817,7 +1817,7 @@ static int nv_alloc_rx(struct net_device *dev)
 
while (np->put_rx.orig != less_rx) {
struct sk_buff *skb = netdev_alloc_skb(dev, np->rx_buf_sz + 
NV_RX_ALLOC_PAD);
-   if (skb) {
+   if (likely(skb)) {
np->put_rx_ctx->skb = skb;
np->put_rx_ctx->dma = dma_map_single(>pci_dev->dev,
 skb->data,
@@ -1858,7 +1858,7 @@ static int nv_alloc_rx_optimized(struct net_device *dev)
 
while (np->put_rx.ex != less_rx) {
struct sk_buff *skb = netdev_alloc_skb(dev, np->rx_buf_sz + 
NV_RX_ALLOC_PAD);
-   if (skb) {
+   if (likely(skb)) {
np->put_rx_ctx->skb = skb;
np->put_rx_ctx->dma = dma_map_single(>pci_dev->dev,
 skb->data,
-- 
2.7.4



[PATCH net-next 1/1] forcedeth: remove duplicate structure member in xmit

2017-12-16 Thread Zhu Yanjun
Since both first_tx_ctx and tx_skb are the head of tx ctx, it not
necessary to use two structure members to statically indicate
the head of tx ctx. So first_tx_ctx is removed.

CC: Srinivas Eeda <srinivas.e...@oracle.com>
CC: Joe Jin <joe@oracle.com>
CC: Junxiao Bi <junxiao...@oracle.com>
Signed-off-by: Zhu Yanjun <yanjun@oracle.com>
---
 drivers/net/ethernet/nvidia/forcedeth.c | 25 +
 1 file changed, 13 insertions(+), 12 deletions(-)

diff --git a/drivers/net/ethernet/nvidia/forcedeth.c 
b/drivers/net/ethernet/nvidia/forcedeth.c
index cadea67..49d6d78 100644
--- a/drivers/net/ethernet/nvidia/forcedeth.c
+++ b/drivers/net/ethernet/nvidia/forcedeth.c
@@ -824,7 +824,7 @@ struct fe_priv {
 */
union ring_type get_tx, put_tx, last_tx;
struct nv_skb_map *get_tx_ctx, *put_tx_ctx;
-   struct nv_skb_map *first_tx_ctx, *last_tx_ctx;
+   struct nv_skb_map *last_tx_ctx;
struct nv_skb_map *tx_skb;
 
union ring_type tx_ring;
@@ -1939,7 +1939,8 @@ static void nv_init_tx(struct net_device *dev)
np->last_tx.orig = >tx_ring.orig[np->tx_ring_size-1];
else
np->last_tx.ex = >tx_ring.ex[np->tx_ring_size-1];
-   np->get_tx_ctx = np->put_tx_ctx = np->first_tx_ctx = np->tx_skb;
+   np->get_tx_ctx = np->tx_skb;
+   np->put_tx_ctx = np->tx_skb;
np->last_tx_ctx = >tx_skb[np->tx_ring_size-1];
netdev_reset_queue(np->dev);
np->tx_pkts_in_progress = 0;
@@ -2251,7 +2252,7 @@ static netdev_tx_t nv_start_xmit(struct sk_buff *skb, 
struct net_device *dev)
if (unlikely(put_tx++ == np->last_tx.orig))
put_tx = np->tx_ring.orig;
if (unlikely(np->put_tx_ctx++ == np->last_tx_ctx))
-   np->put_tx_ctx = np->first_tx_ctx;
+   np->put_tx_ctx = np->tx_skb;
} while (size);
 
/* setup the fragments */
@@ -2277,7 +2278,7 @@ static netdev_tx_t nv_start_xmit(struct sk_buff *skb, 
struct net_device *dev)
do {
nv_unmap_txskb(np, start_tx_ctx);
if (unlikely(tmp_tx_ctx++ == 
np->last_tx_ctx))
-   tmp_tx_ctx = np->first_tx_ctx;
+   tmp_tx_ctx = np->tx_skb;
} while (tmp_tx_ctx != np->put_tx_ctx);
dev_kfree_skb_any(skb);
np->put_tx_ctx = start_tx_ctx;
@@ -2297,7 +2298,7 @@ static netdev_tx_t nv_start_xmit(struct sk_buff *skb, 
struct net_device *dev)
if (unlikely(put_tx++ == np->last_tx.orig))
put_tx = np->tx_ring.orig;
if (unlikely(np->put_tx_ctx++ == np->last_tx_ctx))
-   np->put_tx_ctx = np->first_tx_ctx;
+   np->put_tx_ctx = np->tx_skb;
} while (frag_size);
}
 
@@ -2306,7 +2307,7 @@ static netdev_tx_t nv_start_xmit(struct sk_buff *skb, 
struct net_device *dev)
else
prev_tx = put_tx - 1;
 
-   if (unlikely(np->put_tx_ctx == np->first_tx_ctx))
+   if (unlikely(np->put_tx_ctx == np->tx_skb))
prev_tx_ctx = np->last_tx_ctx;
else
prev_tx_ctx = np->put_tx_ctx - 1;
@@ -2409,7 +2410,7 @@ static netdev_tx_t nv_start_xmit_optimized(struct sk_buff 
*skb,
if (unlikely(put_tx++ == np->last_tx.ex))
put_tx = np->tx_ring.ex;
if (unlikely(np->put_tx_ctx++ == np->last_tx_ctx))
-   np->put_tx_ctx = np->first_tx_ctx;
+   np->put_tx_ctx = np->tx_skb;
} while (size);
 
/* setup the fragments */
@@ -2435,7 +2436,7 @@ static netdev_tx_t nv_start_xmit_optimized(struct sk_buff 
*skb,
do {
nv_unmap_txskb(np, start_tx_ctx);
if (unlikely(tmp_tx_ctx++ == 
np->last_tx_ctx))
-   tmp_tx_ctx = np->first_tx_ctx;
+   tmp_tx_ctx = np->tx_skb;
} while (tmp_tx_ctx != np->put_tx_ctx);
dev_kfree_skb_any(skb);
np->put_tx_ctx = start_tx_ctx;
@@ -2455,7 +2456,7 @@ static netdev_tx_t nv_start_xmit_optimized(struct sk_buff 
*skb,
if (unlikely(put_tx++ == np->last_tx.ex))
put_tx = np->tx_ring.ex;
if (unlikely(np->put_tx_ctx++ == np-

[PATCHv2 net-next 1/1] forcedeth: remove unnecessary structure member

2017-12-09 Thread Zhu Yanjun
Since both tx_ring and first_tx are the head of tx ring, it not
necessary to use two structure members to statically indicate
the head of tx ring. So first_tx is removed.

CC: Srinivas Eeda <srinivas.e...@oracle.com>
CC: Joe Jin <joe@oracle.com>
CC: Junxiao Bi <junxiao...@oracle.com>
Signed-off-by: Zhu Yanjun <yanjun@oracle.com>
---
 drivers/net/ethernet/nvidia/forcedeth.c | 21 +++--
 1 file changed, 11 insertions(+), 10 deletions(-)

diff --git a/drivers/net/ethernet/nvidia/forcedeth.c 
b/drivers/net/ethernet/nvidia/forcedeth.c
index 53614ed..cadea67 100644
--- a/drivers/net/ethernet/nvidia/forcedeth.c
+++ b/drivers/net/ethernet/nvidia/forcedeth.c
@@ -822,7 +822,7 @@ struct fe_priv {
/*
 * tx specific fields.
 */
-   union ring_type get_tx, put_tx, first_tx, last_tx;
+   union ring_type get_tx, put_tx, last_tx;
struct nv_skb_map *get_tx_ctx, *put_tx_ctx;
struct nv_skb_map *first_tx_ctx, *last_tx_ctx;
struct nv_skb_map *tx_skb;
@@ -1932,7 +1932,8 @@ static void nv_init_tx(struct net_device *dev)
struct fe_priv *np = netdev_priv(dev);
int i;
 
-   np->get_tx = np->put_tx = np->first_tx = np->tx_ring;
+   np->get_tx = np->tx_ring;
+   np->put_tx = np->tx_ring;
 
if (!nv_optimized(np))
np->last_tx.orig = >tx_ring.orig[np->tx_ring_size-1];
@@ -2248,7 +2249,7 @@ static netdev_tx_t nv_start_xmit(struct sk_buff *skb, 
struct net_device *dev)
offset += bcnt;
size -= bcnt;
if (unlikely(put_tx++ == np->last_tx.orig))
-   put_tx = np->first_tx.orig;
+   put_tx = np->tx_ring.orig;
if (unlikely(np->put_tx_ctx++ == np->last_tx_ctx))
np->put_tx_ctx = np->first_tx_ctx;
} while (size);
@@ -2294,13 +2295,13 @@ static netdev_tx_t nv_start_xmit(struct sk_buff *skb, 
struct net_device *dev)
offset += bcnt;
frag_size -= bcnt;
if (unlikely(put_tx++ == np->last_tx.orig))
-   put_tx = np->first_tx.orig;
+   put_tx = np->tx_ring.orig;
if (unlikely(np->put_tx_ctx++ == np->last_tx_ctx))
np->put_tx_ctx = np->first_tx_ctx;
} while (frag_size);
}
 
-   if (unlikely(put_tx == np->first_tx.orig))
+   if (unlikely(put_tx == np->tx_ring.orig))
prev_tx = np->last_tx.orig;
else
prev_tx = put_tx - 1;
@@ -2406,7 +2407,7 @@ static netdev_tx_t nv_start_xmit_optimized(struct sk_buff 
*skb,
offset += bcnt;
size -= bcnt;
if (unlikely(put_tx++ == np->last_tx.ex))
-   put_tx = np->first_tx.ex;
+   put_tx = np->tx_ring.ex;
if (unlikely(np->put_tx_ctx++ == np->last_tx_ctx))
np->put_tx_ctx = np->first_tx_ctx;
} while (size);
@@ -2452,13 +2453,13 @@ static netdev_tx_t nv_start_xmit_optimized(struct 
sk_buff *skb,
offset += bcnt;
frag_size -= bcnt;
if (unlikely(put_tx++ == np->last_tx.ex))
-   put_tx = np->first_tx.ex;
+   put_tx = np->tx_ring.ex;
if (unlikely(np->put_tx_ctx++ == np->last_tx_ctx))
np->put_tx_ctx = np->first_tx_ctx;
} while (frag_size);
}
 
-   if (unlikely(put_tx == np->first_tx.ex))
+   if (unlikely(put_tx == np->tx_ring.ex))
prev_tx = np->last_tx.ex;
else
prev_tx = put_tx - 1;
@@ -2597,7 +2598,7 @@ static int nv_tx_done(struct net_device *dev, int limit)
}
}
if (unlikely(np->get_tx.orig++ == np->last_tx.orig))
-   np->get_tx.orig = np->first_tx.orig;
+   np->get_tx.orig = np->tx_ring.orig;
if (unlikely(np->get_tx_ctx++ == np->last_tx_ctx))
np->get_tx_ctx = np->first_tx_ctx;
}
@@ -2651,7 +2652,7 @@ static int nv_tx_done_optimized(struct net_device *dev, 
int limit)
}
 
if (unlikely(np->get_tx.ex++ == np->last_tx.ex))
-   np->get_tx.ex = np->first_tx.ex;
+   np->get_tx.ex = np->tx_ring.ex;
if (unlikely(np->get_tx_ctx++ == np->last_tx_ctx))
np->get_tx_ctx = np->first_tx_ctx;
}
-- 
2.7.4



[PATCH net-next 1/1] forcedeth: remove unnecessary variable

2017-12-06 Thread Zhu Yanjun
Since both tx_ring and first_tx are the head of tx ring, it not
necessary to use two variables. So first_tx is removed.

CC: Srinivas Eeda <srinivas.e...@oracle.com>
CC: Joe Jin <joe@oracle.com>
CC: Junxiao Bi <junxiao...@oracle.com>
Signed-off-by: Zhu Yanjun <yanjun@oracle.com>
---
 drivers/net/ethernet/nvidia/forcedeth.c | 21 +++--
 1 file changed, 11 insertions(+), 10 deletions(-)

diff --git a/drivers/net/ethernet/nvidia/forcedeth.c 
b/drivers/net/ethernet/nvidia/forcedeth.c
index 53614ed..cadea67 100644
--- a/drivers/net/ethernet/nvidia/forcedeth.c
+++ b/drivers/net/ethernet/nvidia/forcedeth.c
@@ -822,7 +822,7 @@ struct fe_priv {
/*
 * tx specific fields.
 */
-   union ring_type get_tx, put_tx, first_tx, last_tx;
+   union ring_type get_tx, put_tx, last_tx;
struct nv_skb_map *get_tx_ctx, *put_tx_ctx;
struct nv_skb_map *first_tx_ctx, *last_tx_ctx;
struct nv_skb_map *tx_skb;
@@ -1932,7 +1932,8 @@ static void nv_init_tx(struct net_device *dev)
struct fe_priv *np = netdev_priv(dev);
int i;
 
-   np->get_tx = np->put_tx = np->first_tx = np->tx_ring;
+   np->get_tx = np->tx_ring;
+   np->put_tx = np->tx_ring;
 
if (!nv_optimized(np))
np->last_tx.orig = >tx_ring.orig[np->tx_ring_size-1];
@@ -2248,7 +2249,7 @@ static netdev_tx_t nv_start_xmit(struct sk_buff *skb, 
struct net_device *dev)
offset += bcnt;
size -= bcnt;
if (unlikely(put_tx++ == np->last_tx.orig))
-   put_tx = np->first_tx.orig;
+   put_tx = np->tx_ring.orig;
if (unlikely(np->put_tx_ctx++ == np->last_tx_ctx))
np->put_tx_ctx = np->first_tx_ctx;
} while (size);
@@ -2294,13 +2295,13 @@ static netdev_tx_t nv_start_xmit(struct sk_buff *skb, 
struct net_device *dev)
offset += bcnt;
frag_size -= bcnt;
if (unlikely(put_tx++ == np->last_tx.orig))
-   put_tx = np->first_tx.orig;
+   put_tx = np->tx_ring.orig;
if (unlikely(np->put_tx_ctx++ == np->last_tx_ctx))
np->put_tx_ctx = np->first_tx_ctx;
} while (frag_size);
}
 
-   if (unlikely(put_tx == np->first_tx.orig))
+   if (unlikely(put_tx == np->tx_ring.orig))
prev_tx = np->last_tx.orig;
else
prev_tx = put_tx - 1;
@@ -2406,7 +2407,7 @@ static netdev_tx_t nv_start_xmit_optimized(struct sk_buff 
*skb,
offset += bcnt;
size -= bcnt;
if (unlikely(put_tx++ == np->last_tx.ex))
-   put_tx = np->first_tx.ex;
+   put_tx = np->tx_ring.ex;
if (unlikely(np->put_tx_ctx++ == np->last_tx_ctx))
np->put_tx_ctx = np->first_tx_ctx;
} while (size);
@@ -2452,13 +2453,13 @@ static netdev_tx_t nv_start_xmit_optimized(struct 
sk_buff *skb,
offset += bcnt;
frag_size -= bcnt;
if (unlikely(put_tx++ == np->last_tx.ex))
-   put_tx = np->first_tx.ex;
+   put_tx = np->tx_ring.ex;
if (unlikely(np->put_tx_ctx++ == np->last_tx_ctx))
np->put_tx_ctx = np->first_tx_ctx;
} while (frag_size);
}
 
-   if (unlikely(put_tx == np->first_tx.ex))
+   if (unlikely(put_tx == np->tx_ring.ex))
prev_tx = np->last_tx.ex;
else
prev_tx = put_tx - 1;
@@ -2597,7 +2598,7 @@ static int nv_tx_done(struct net_device *dev, int limit)
}
}
if (unlikely(np->get_tx.orig++ == np->last_tx.orig))
-   np->get_tx.orig = np->first_tx.orig;
+   np->get_tx.orig = np->tx_ring.orig;
if (unlikely(np->get_tx_ctx++ == np->last_tx_ctx))
np->get_tx_ctx = np->first_tx_ctx;
}
@@ -2651,7 +2652,7 @@ static int nv_tx_done_optimized(struct net_device *dev, 
int limit)
}
 
if (unlikely(np->get_tx.ex++ == np->last_tx.ex))
-   np->get_tx.ex = np->first_tx.ex;
+   np->get_tx.ex = np->tx_ring.ex;
if (unlikely(np->get_tx_ctx++ == np->last_tx_ctx))
np->get_tx_ctx = np->first_tx_ctx;
}
-- 
2.7.4



[PATCH net-next 1/1] forcedeth: optimize the xmit with unlikely

2017-11-27 Thread Zhu Yanjun
In xmit, it is very impossible that TX_ERROR occurs. So using
unlikely optimizes the xmit process.

CC: Srinivas Eeda <srinivas.e...@oracle.com>
CC: Joe Jin <joe@oracle.com>
CC: Junxiao Bi <junxiao...@oracle.com>
Signed-off-by: Zhu Yanjun <yanjun@oracle.com>
---
 drivers/net/ethernet/nvidia/forcedeth.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/nvidia/forcedeth.c 
b/drivers/net/ethernet/nvidia/forcedeth.c
index ac8439c..e65276f 100644
--- a/drivers/net/ethernet/nvidia/forcedeth.c
+++ b/drivers/net/ethernet/nvidia/forcedeth.c
@@ -2563,7 +2563,7 @@ static int nv_tx_done(struct net_device *dev, int limit)
 
if (np->desc_ver == DESC_VER_1) {
if (flags & NV_TX_LASTPACKET) {
-   if (flags & NV_TX_ERROR) {
+   if (unlikely(flags & NV_TX_ERROR)) {
if ((flags & NV_TX_RETRYERROR)
&& !(flags & NV_TX_RETRYCOUNT_MASK))
nv_legacybackoff_reseed(dev);
@@ -2580,7 +2580,7 @@ static int nv_tx_done(struct net_device *dev, int limit)
}
} else {
if (flags & NV_TX2_LASTPACKET) {
-   if (flags & NV_TX2_ERROR) {
+   if (unlikely(flags & NV_TX2_ERROR)) {
if ((flags & NV_TX2_RETRYERROR)
&& !(flags & 
NV_TX2_RETRYCOUNT_MASK))
nv_legacybackoff_reseed(dev);
@@ -2626,7 +2626,7 @@ static int nv_tx_done_optimized(struct net_device *dev, 
int limit)
nv_unmap_txskb(np, np->get_tx_ctx);
 
if (flags & NV_TX2_LASTPACKET) {
-   if (flags & NV_TX2_ERROR) {
+   if (unlikely(flags & NV_TX2_ERROR)) {
if ((flags & NV_TX2_RETRYERROR)
&& !(flags & NV_TX2_RETRYCOUNT_MASK)) {
if (np->driver_data & DEV_HAS_GEAR_MODE)
-- 
2.7.4



[PATCHv2 net-next 1/1] forcedeth: replace pci_unmap_page with dma_unmap_page

2017-11-19 Thread Zhu Yanjun
The function pci_unmap_page is obsolete. So it is replaced with
the function dma_unmap_page.

CC: Srinivas Eeda <srinivas.e...@oracle.com>
CC: Joe Jin <joe@oracle.com>
CC: Junxiao Bi <junxiao...@oracle.com>
Signed-off-by: Zhu Yanjun <yanjun@oracle.com>
---
V1->V2: fix direction flag error.
---
 drivers/net/ethernet/nvidia/forcedeth.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/nvidia/forcedeth.c 
b/drivers/net/ethernet/nvidia/forcedeth.c
index ac8439c..481876b 100644
--- a/drivers/net/ethernet/nvidia/forcedeth.c
+++ b/drivers/net/ethernet/nvidia/forcedeth.c
@@ -1986,9 +1986,9 @@ static void nv_unmap_txskb(struct fe_priv *np, struct 
nv_skb_map *tx_skb)
 tx_skb->dma_len,
 DMA_TO_DEVICE);
else
-   pci_unmap_page(np->pci_dev, tx_skb->dma,
+   dma_unmap_page(>pci_dev->dev, tx_skb->dma,
   tx_skb->dma_len,
-  PCI_DMA_TODEVICE);
+  DMA_TO_DEVICE);
tx_skb->dma = 0;
}
 }
-- 
2.7.4



[PATCH net-next 1/1] forcedeth: replace pci_unmap_page with dma_unmap_page

2017-11-19 Thread Zhu Yanjun
The function pci_unmap_page is obsolete. So it is replaced with
the function dma_unmap_page.

CC: Srinivas Eeda <srinivas.e...@oracle.com>
CC: Joe Jin <joe@oracle.com>
CC: Junxiao Bi <junxiao...@oracle.com>
Signed-off-by: Zhu Yanjun <yanjun@oracle.com>
---
 drivers/net/ethernet/nvidia/forcedeth.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/nvidia/forcedeth.c 
b/drivers/net/ethernet/nvidia/forcedeth.c
index ac8439c..0febe41 100644
--- a/drivers/net/ethernet/nvidia/forcedeth.c
+++ b/drivers/net/ethernet/nvidia/forcedeth.c
@@ -1986,7 +1986,7 @@ static void nv_unmap_txskb(struct fe_priv *np, struct 
nv_skb_map *tx_skb)
 tx_skb->dma_len,
 DMA_TO_DEVICE);
else
-   pci_unmap_page(np->pci_dev, tx_skb->dma,
+   dma_unmap_page(>pci_dev->dev, tx_skb->dma,
   tx_skb->dma_len,
   PCI_DMA_TODEVICE);
tx_skb->dma = 0;
-- 
2.7.4



[PATCHv3 1/1] bnx2x: fix slowpath null crash

2017-11-11 Thread Zhu Yanjun
When "NETDEV WATCHDOG: em4 (bnx2x): transmit queue 2 timed out" occurs,
BNX2X_SP_RTNL_TX_TIMEOUT is set. In the function bnx2x_sp_rtnl_task,
bnx2x_nic_unload and bnx2x_nic_load are executed to shutdown and open
NIC. In the function bnx2x_nic_load, bnx2x_alloc_mem allocates dma
failure. The message "bnx2x: [bnx2x_alloc_mem:8399(em4)]Can't
allocate memory" pops out. The variable slowpath is set to NULL.
When shutdown the NIC, the function bnx2x_nic_unload is called. In
the function bnx2x_nic_unload, the following functions are executed.
bnx2x_chip_cleanup
bnx2x_set_storm_rx_mode
bnx2x_set_q_rx_mode
bnx2x_set_q_rx_mode
bnx2x_config_rx_mode
bnx2x_set_rx_mode_e2
In the function bnx2x_set_rx_mode_e2, the variable slowpath is operated.
Then the crash occurs.
To fix this crash, the variable slowpath is checked. And in the function
bnx2x_sp_rtnl_task, after dma memory allocation fails, another shutdown
and open NIC is executed.

CC: Joe Jin <joe@oracle.com>
CC: Junxiao Bi <junxiao...@oracle.com>
Signed-off-by: Zhu Yanjun <yanjun@oracle.com>
Acked-by: Ariel Elior <ael...@cavium.com>
---
v2->v3
Changes: fix the style of comments, add the leading space
V1->v2
Changes: add Acker and remove unnecessary brackets
---
 drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c | 13 ++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c 
b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
index c12b4d3..fbd302a 100644
--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
@@ -9332,7 +9332,7 @@ void bnx2x_chip_cleanup(struct bnx2x *bp, int 
unload_mode, bool keep_link)
/* Schedule the rx_mode command */
if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, >sp_state))
set_bit(BNX2X_FILTER_RX_MODE_SCHED, >sp_state);
-   else
+   else if (bp->slowpath)
bnx2x_set_storm_rx_mode(bp);
 
/* Cleanup multicast configuration */
@@ -10271,8 +10271,15 @@ static void bnx2x_sp_rtnl_task(struct work_struct 
*work)
smp_mb();
 
bnx2x_nic_unload(bp, UNLOAD_NORMAL, true);
-   bnx2x_nic_load(bp, LOAD_NORMAL);
-
+   /* When ret value shows failure of allocation failure,
+* the nic is rebooted again. If open still fails, a error
+* message to notify the user.
+*/
+   if (bnx2x_nic_load(bp, LOAD_NORMAL) == -ENOMEM) {
+   bnx2x_nic_unload(bp, UNLOAD_NORMAL, true);
+   if (bnx2x_nic_load(bp, LOAD_NORMAL))
+   BNX2X_ERR("Open the NIC fails again!\n");
+   }
rtnl_unlock();
return;
}
-- 
2.7.4



[PATCH net-next 1/1] forcedeth: remove redudant assignments in xmit

2017-11-10 Thread Zhu Yanjun
In xmit process, the variables are set many times. In fact,
it is enough for these variables to be set once.
After a long time test, the throughput performance is better
than before.

CC: Srinivas Eeda <srinivas.e...@oracle.com>
CC: Joe Jin <joe@oracle.com>
CC: Junxiao Bi <junxiao...@oracle.com>
Signed-off-by: Zhu Yanjun <yanjun@oracle.com>
---
 drivers/net/ethernet/nvidia/forcedeth.c | 28 
 1 file changed, 20 insertions(+), 8 deletions(-)

diff --git a/drivers/net/ethernet/nvidia/forcedeth.c 
b/drivers/net/ethernet/nvidia/forcedeth.c
index 63a9e1e..22912e7 100644
--- a/drivers/net/ethernet/nvidia/forcedeth.c
+++ b/drivers/net/ethernet/nvidia/forcedeth.c
@@ -2218,8 +2218,6 @@ static netdev_tx_t nv_start_xmit(struct sk_buff *skb, 
struct net_device *dev)
 
/* setup the header buffer */
do {
-   prev_tx = put_tx;
-   prev_tx_ctx = np->put_tx_ctx;
bcnt = (size > NV_TX2_TSO_MAX_SIZE) ? NV_TX2_TSO_MAX_SIZE : 
size;
np->put_tx_ctx->dma = dma_map_single(>pci_dev->dev,
 skb->data + offset, bcnt,
@@ -2254,8 +2252,6 @@ static netdev_tx_t nv_start_xmit(struct sk_buff *skb, 
struct net_device *dev)
offset = 0;
 
do {
-   prev_tx = put_tx;
-   prev_tx_ctx = np->put_tx_ctx;
if (!start_tx_ctx)
start_tx_ctx = tmp_tx_ctx = np->put_tx_ctx;
 
@@ -2296,6 +2292,16 @@ static netdev_tx_t nv_start_xmit(struct sk_buff *skb, 
struct net_device *dev)
} while (frag_size);
}
 
+   if (unlikely(put_tx == np->first_tx.orig))
+   prev_tx = np->last_tx.orig;
+   else
+   prev_tx = put_tx - 1;
+
+   if (unlikely(np->put_tx_ctx == np->first_tx_ctx))
+   prev_tx_ctx = np->last_tx_ctx;
+   else
+   prev_tx_ctx = np->put_tx_ctx - 1;
+
/* set last fragment flag  */
prev_tx->flaglen |= cpu_to_le32(tx_flags_extra);
 
@@ -2368,8 +2374,6 @@ static netdev_tx_t nv_start_xmit_optimized(struct sk_buff 
*skb,
 
/* setup the header buffer */
do {
-   prev_tx = put_tx;
-   prev_tx_ctx = np->put_tx_ctx;
bcnt = (size > NV_TX2_TSO_MAX_SIZE) ? NV_TX2_TSO_MAX_SIZE : 
size;
np->put_tx_ctx->dma = dma_map_single(>pci_dev->dev,
 skb->data + offset, bcnt,
@@ -2405,8 +2409,6 @@ static netdev_tx_t nv_start_xmit_optimized(struct sk_buff 
*skb,
offset = 0;
 
do {
-   prev_tx = put_tx;
-   prev_tx_ctx = np->put_tx_ctx;
bcnt = (frag_size > NV_TX2_TSO_MAX_SIZE) ? 
NV_TX2_TSO_MAX_SIZE : frag_size;
if (!start_tx_ctx)
start_tx_ctx = tmp_tx_ctx = np->put_tx_ctx;
@@ -2447,6 +2449,16 @@ static netdev_tx_t nv_start_xmit_optimized(struct 
sk_buff *skb,
} while (frag_size);
}
 
+   if (unlikely(put_tx == np->first_tx.ex))
+   prev_tx = np->last_tx.ex;
+   else
+   prev_tx = put_tx - 1;
+
+   if (unlikely(np->put_tx_ctx == np->first_tx_ctx))
+   prev_tx_ctx = np->last_tx_ctx;
+   else
+   prev_tx_ctx = np->put_tx_ctx - 1;
+
/* set last fragment flag  */
prev_tx->flaglen |= cpu_to_le32(NV_TX2_LASTPACKET);
 
-- 
2.7.4



[PATCHv2 1/1] bnx2x: fix slowpath null crash

2017-11-08 Thread Zhu Yanjun
When "NETDEV WATCHDOG: em4 (bnx2x): transmit queue 2 timed out" occurs,
BNX2X_SP_RTNL_TX_TIMEOUT is set. In the function bnx2x_sp_rtnl_task,
bnx2x_nic_unload and bnx2x_nic_load are executed to shutdown and open
NIC. In the function bnx2x_nic_load, bnx2x_alloc_mem allocates dma
failure. The message "bnx2x: [bnx2x_alloc_mem:8399(em4)]Can't
allocate memory" pops out. The variable slowpath is set to NULL.
When shutdown the NIC, the function bnx2x_nic_unload is called. In
the function bnx2x_nic_unload, the following functions are executed.
bnx2x_chip_cleanup
bnx2x_set_storm_rx_mode
bnx2x_set_q_rx_mode
bnx2x_set_q_rx_mode
bnx2x_config_rx_mode
bnx2x_set_rx_mode_e2
In the function bnx2x_set_rx_mode_e2, the variable slowpath is operated.
Then the crash occurs.
To fix this crash, the variable slowpath is checked. And in the function
bnx2x_sp_rtnl_task, after dma memory allocation fails, another shutdown
and open NIC is executed.

CC: Joe Jin <joe@oracle.com>
CC: Junxiao Bi <junxiao...@oracle.com>
Signed-off-by: Zhu Yanjun <yanjun@oracle.com>
Acked-by: Ariel Elior <ael...@cavium.com>
---
V1->v2
Changes: add Acker and remove unnecessary brackets
---
 drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c | 13 ++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c 
b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
index c12b4d3..fbd302a 100644
--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
@@ -9332,7 +9332,7 @@ void bnx2x_chip_cleanup(struct bnx2x *bp, int 
unload_mode, bool keep_link)
/* Schedule the rx_mode command */
if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, >sp_state))
set_bit(BNX2X_FILTER_RX_MODE_SCHED, >sp_state);
-   else
+   else if (bp->slowpath)
bnx2x_set_storm_rx_mode(bp);
 
/* Cleanup multicast configuration */
@@ -10271,8 +10271,15 @@ static void bnx2x_sp_rtnl_task(struct work_struct 
*work)
smp_mb();
 
bnx2x_nic_unload(bp, UNLOAD_NORMAL, true);
-   bnx2x_nic_load(bp, LOAD_NORMAL);
-
+   /*When ret value shows failure of allocation failure,
+*the nic is rebooted again. If open still fails, a error
+*message to notify the user.
+*/
+   if (bnx2x_nic_load(bp, LOAD_NORMAL) == -ENOMEM) {
+   bnx2x_nic_unload(bp, UNLOAD_NORMAL, true);
+   if (bnx2x_nic_load(bp, LOAD_NORMAL))
+   BNX2X_ERR("Open the NIC fails again!\n");
+   }
rtnl_unlock();
return;
}
-- 
2.7.4



[PATCH 1/1] bnx2x: fix slowpath null crash

2017-11-07 Thread Zhu Yanjun
When "NETDEV WATCHDOG: em4 (bnx2x): transmit queue 2 timed out" occurs,
BNX2X_SP_RTNL_TX_TIMEOUT is set. In the function bnx2x_sp_rtnl_task,
bnx2x_nic_unload and bnx2x_nic_load are executed to shutdown and open
NIC. In the function bnx2x_nic_load, bnx2x_alloc_mem allocates dma
failure. The message "bnx2x: [bnx2x_alloc_mem:8399(em4)]Can't
allocate memory" pops out. The variable slowpath is set to NULL.
When shutdown the NIC, the function bnx2x_nic_unload is called. In
the function bnx2x_nic_unload, the following functions are executed.
bnx2x_chip_cleanup
bnx2x_set_storm_rx_mode
bnx2x_set_q_rx_mode
bnx2x_set_q_rx_mode
bnx2x_config_rx_mode
bnx2x_set_rx_mode_e2
In the function bnx2x_set_rx_mode_e2, the variable slowpath is operated.
Then the crash occurs.
To fix this crash, the variable slowpath is checked. And in the function
bnx2x_sp_rtnl_task, after dma memory allocation fails, another shutdown
and open NIC is executed.

CC: Joe Jin <joe@oracle.com>
CC: Junxiao Bi <junxiao...@oracle.com>
Signed-off-by: Zhu Yanjun <yanjun@oracle.com>
---
 drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c | 14 +++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c 
b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
index c12b4d3..5929324 100644
--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
@@ -9332,7 +9332,7 @@ void bnx2x_chip_cleanup(struct bnx2x *bp, int 
unload_mode, bool keep_link)
/* Schedule the rx_mode command */
if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, >sp_state))
set_bit(BNX2X_FILTER_RX_MODE_SCHED, >sp_state);
-   else
+   else if (!bp->slowpath)
bnx2x_set_storm_rx_mode(bp);
 
/* Cleanup multicast configuration */
@@ -10271,8 +10271,16 @@ static void bnx2x_sp_rtnl_task(struct work_struct 
*work)
smp_mb();
 
bnx2x_nic_unload(bp, UNLOAD_NORMAL, true);
-   bnx2x_nic_load(bp, LOAD_NORMAL);
-
+   /*When ret value shows failure of allocation failure,
+*the nic is rebooted again. If open still fails, a error
+*message to notify the user.
+*/
+   if (bnx2x_nic_load(bp, LOAD_NORMAL) == -ENOMEM) {
+   bnx2x_nic_unload(bp, UNLOAD_NORMAL, true);
+   if (bnx2x_nic_load(bp, LOAD_NORMAL)) {
+   BNX2X_ERR("Open the NIC fails again!\n");
+   }
+   }
rtnl_unlock();
return;
}
-- 
2.7.4



[PATCH net-next 1/1] forcedeth: replace pci_alloc_consistent with dma_alloc_coherent

2017-10-28 Thread Zhu Yanjun
The functions pci_alloc_consistent is obsolete. So it is replaced
with dma_alloc_coherent

Signed-off-by: Zhu Yanjun <yanjun@oracle.com>
---
 drivers/net/ethernet/nvidia/forcedeth.c | 61 ++---
 1 file changed, 41 insertions(+), 20 deletions(-)

diff --git a/drivers/net/ethernet/nvidia/forcedeth.c 
b/drivers/net/ethernet/nvidia/forcedeth.c
index 88128ce..31a9438 100644
--- a/drivers/net/ethernet/nvidia/forcedeth.c
+++ b/drivers/net/ethernet/nvidia/forcedeth.c
@@ -1024,12 +1024,18 @@ static void free_rings(struct net_device *dev)
 
if (!nv_optimized(np)) {
if (np->rx_ring.orig)
-   pci_free_consistent(np->pci_dev, sizeof(struct 
ring_desc) * (np->rx_ring_size + np->tx_ring_size),
-   np->rx_ring.orig, np->ring_addr);
+   dma_free_coherent(>pci_dev->dev,
+ sizeof(struct ring_desc) *
+ (np->rx_ring_size +
+ np->tx_ring_size),
+ np->rx_ring.orig, np->ring_addr);
} else {
if (np->rx_ring.ex)
-   pci_free_consistent(np->pci_dev, sizeof(struct 
ring_desc_ex) * (np->rx_ring_size + np->tx_ring_size),
-   np->rx_ring.ex, np->ring_addr);
+   dma_free_coherent(>pci_dev->dev,
+ sizeof(struct ring_desc_ex) *
+ (np->rx_ring_size +
+ np->tx_ring_size),
+ np->rx_ring.ex, np->ring_addr);
}
kfree(np->rx_skb);
kfree(np->tx_skb);
@@ -4596,13 +4602,17 @@ static int nv_set_ringparam(struct net_device *dev, 
struct ethtool_ringparam* ri
 
/* allocate new rings */
if (!nv_optimized(np)) {
-   rxtx_ring = pci_alloc_consistent(np->pci_dev,
-   sizeof(struct ring_desc) * 
(ring->rx_pending + ring->tx_pending),
-   _addr);
+   rxtx_ring = dma_alloc_coherent(>pci_dev->dev,
+  sizeof(struct ring_desc) *
+  (ring->rx_pending +
+  ring->tx_pending),
+  _addr, GFP_ATOMIC);
} else {
-   rxtx_ring = pci_alloc_consistent(np->pci_dev,
-   sizeof(struct ring_desc_ex) * 
(ring->rx_pending + ring->tx_pending),
-   _addr);
+   rxtx_ring = dma_alloc_coherent(>pci_dev->dev,
+  sizeof(struct ring_desc_ex) *
+  (ring->rx_pending +
+  ring->tx_pending),
+  _addr, GFP_ATOMIC);
}
rx_skbuff = kmalloc(sizeof(struct nv_skb_map) * ring->rx_pending, 
GFP_KERNEL);
tx_skbuff = kmalloc(sizeof(struct nv_skb_map) * ring->tx_pending, 
GFP_KERNEL);
@@ -4610,12 +4620,18 @@ static int nv_set_ringparam(struct net_device *dev, 
struct ethtool_ringparam* ri
/* fall back to old rings */
if (!nv_optimized(np)) {
if (rxtx_ring)
-   pci_free_consistent(np->pci_dev, sizeof(struct 
ring_desc) * (ring->rx_pending + ring->tx_pending),
-   rxtx_ring, ring_addr);
+   dma_free_coherent(>pci_dev->dev,
+ sizeof(struct ring_desc) *
+ (ring->rx_pending +
+ ring->tx_pending),
+ rxtx_ring, ring_addr);
} else {
if (rxtx_ring)
-   pci_free_consistent(np->pci_dev, sizeof(struct 
ring_desc_ex) * (ring->rx_pending + ring->tx_pending),
-   rxtx_ring, ring_addr);
+   dma_free_coherent(>pci_dev->dev,
+ sizeof(struct ring_desc_ex) *
+ (ring->rx_pending +
+ ring->tx_pending),
+ rxtx_ring, ring_addr);
}
 
kfree(rx_skbuff);
@@ -5740,16 +5756,21 @@ s

[PATCH 1/1] forcedeth: optimize the xmit/rx with unlikely

2017-09-22 Thread Zhu Yanjun
In the xmit/rx fastpath, the function dma_map_single rarely fails.
Therefore, add an unlikely() optimization to this error check
conditional.

Signed-off-by: Zhu Yanjun <yanjun@oracle.com>
---
 drivers/net/ethernet/nvidia/forcedeth.c | 26 ++
 1 file changed, 14 insertions(+), 12 deletions(-)

diff --git a/drivers/net/ethernet/nvidia/forcedeth.c 
b/drivers/net/ethernet/nvidia/forcedeth.c
index 0a7ba3a..63a9e1e 100644
--- a/drivers/net/ethernet/nvidia/forcedeth.c
+++ b/drivers/net/ethernet/nvidia/forcedeth.c
@@ -1816,8 +1816,8 @@ static int nv_alloc_rx(struct net_device *dev)
 skb->data,
 skb_tailroom(skb),
 DMA_FROM_DEVICE);
-   if (dma_mapping_error(>pci_dev->dev,
- np->put_rx_ctx->dma)) {
+   if (unlikely(dma_mapping_error(>pci_dev->dev,
+  np->put_rx_ctx->dma))) {
kfree_skb(skb);
goto packet_dropped;
}
@@ -1857,8 +1857,8 @@ static int nv_alloc_rx_optimized(struct net_device *dev)
 skb->data,
 skb_tailroom(skb),
 DMA_FROM_DEVICE);
-   if (dma_mapping_error(>pci_dev->dev,
- np->put_rx_ctx->dma)) {
+   if (unlikely(dma_mapping_error(>pci_dev->dev,
+  np->put_rx_ctx->dma))) {
kfree_skb(skb);
goto packet_dropped;
}
@@ -2224,8 +2224,8 @@ static netdev_tx_t nv_start_xmit(struct sk_buff *skb, 
struct net_device *dev)
np->put_tx_ctx->dma = dma_map_single(>pci_dev->dev,
 skb->data + offset, bcnt,
 DMA_TO_DEVICE);
-   if (dma_mapping_error(>pci_dev->dev,
- np->put_tx_ctx->dma)) {
+   if (unlikely(dma_mapping_error(>pci_dev->dev,
+  np->put_tx_ctx->dma))) {
/* on DMA mapping error - drop the packet */
dev_kfree_skb_any(skb);
u64_stats_update_begin(>swstats_tx_syncp);
@@ -2265,7 +2265,8 @@ static netdev_tx_t nv_start_xmit(struct sk_buff *skb, 
struct net_device *dev)
frag, offset,
bcnt,
DMA_TO_DEVICE);
-   if (dma_mapping_error(>pci_dev->dev, 
np->put_tx_ctx->dma)) {
+   if (unlikely(dma_mapping_error(>pci_dev->dev,
+  np->put_tx_ctx->dma))) {
 
/* Unwind the mapped fragments */
do {
@@ -2373,8 +2374,8 @@ static netdev_tx_t nv_start_xmit_optimized(struct sk_buff 
*skb,
np->put_tx_ctx->dma = dma_map_single(>pci_dev->dev,
 skb->data + offset, bcnt,
 DMA_TO_DEVICE);
-   if (dma_mapping_error(>pci_dev->dev,
- np->put_tx_ctx->dma)) {
+   if (unlikely(dma_mapping_error(>pci_dev->dev,
+  np->put_tx_ctx->dma))) {
/* on DMA mapping error - drop the packet */
dev_kfree_skb_any(skb);
u64_stats_update_begin(>swstats_tx_syncp);
@@ -2415,7 +2416,8 @@ static netdev_tx_t nv_start_xmit_optimized(struct sk_buff 
*skb,
bcnt,
DMA_TO_DEVICE);
 
-   if (dma_mapping_error(>pci_dev->dev, 
np->put_tx_ctx->dma)) {
+   if (unlikely(dma_mapping_error(>pci_dev->dev,
+  np->put_tx_ctx->dma))) {
 
/* Unwind the mapped fragments */
do {
@@ -5070,8 +5072,8 @@ static int nv_loopback_test(struct net_device *dev)
test_dma_addr = dma_map_singl

[PATCH 1/1] forcedeth: replace pci_map_single with dma_map_single functions

2017-09-14 Thread Zhu Yanjun
pci_map_single functions are obsolete. So replace them with
dma_map_single functions.

Signed-off-by: Zhu Yanjun <yanjun@oracle.com>
---
 drivers/net/ethernet/nvidia/forcedeth.c | 70 +
 1 file changed, 36 insertions(+), 34 deletions(-)

diff --git a/drivers/net/ethernet/nvidia/forcedeth.c 
b/drivers/net/ethernet/nvidia/forcedeth.c
index e6e0de4..0a7ba3a 100644
--- a/drivers/net/ethernet/nvidia/forcedeth.c
+++ b/drivers/net/ethernet/nvidia/forcedeth.c
@@ -1812,12 +1812,12 @@ static int nv_alloc_rx(struct net_device *dev)
struct sk_buff *skb = netdev_alloc_skb(dev, np->rx_buf_sz + 
NV_RX_ALLOC_PAD);
if (skb) {
np->put_rx_ctx->skb = skb;
-   np->put_rx_ctx->dma = pci_map_single(np->pci_dev,
+   np->put_rx_ctx->dma = dma_map_single(>pci_dev->dev,
 skb->data,
 skb_tailroom(skb),
-
PCI_DMA_FROMDEVICE);
-   if (pci_dma_mapping_error(np->pci_dev,
- np->put_rx_ctx->dma)) {
+DMA_FROM_DEVICE);
+   if (dma_mapping_error(>pci_dev->dev,
+ np->put_rx_ctx->dma)) {
kfree_skb(skb);
goto packet_dropped;
}
@@ -1853,12 +1853,12 @@ static int nv_alloc_rx_optimized(struct net_device *dev)
struct sk_buff *skb = netdev_alloc_skb(dev, np->rx_buf_sz + 
NV_RX_ALLOC_PAD);
if (skb) {
np->put_rx_ctx->skb = skb;
-   np->put_rx_ctx->dma = pci_map_single(np->pci_dev,
+   np->put_rx_ctx->dma = dma_map_single(>pci_dev->dev,
 skb->data,
 skb_tailroom(skb),
-
PCI_DMA_FROMDEVICE);
-   if (pci_dma_mapping_error(np->pci_dev,
- np->put_rx_ctx->dma)) {
+DMA_FROM_DEVICE);
+   if (dma_mapping_error(>pci_dev->dev,
+ np->put_rx_ctx->dma)) {
kfree_skb(skb);
goto packet_dropped;
}
@@ -1975,9 +1975,9 @@ static void nv_unmap_txskb(struct fe_priv *np, struct 
nv_skb_map *tx_skb)
 {
if (tx_skb->dma) {
if (tx_skb->dma_single)
-   pci_unmap_single(np->pci_dev, tx_skb->dma,
+   dma_unmap_single(>pci_dev->dev, tx_skb->dma,
 tx_skb->dma_len,
-PCI_DMA_TODEVICE);
+DMA_TO_DEVICE);
else
pci_unmap_page(np->pci_dev, tx_skb->dma,
   tx_skb->dma_len,
@@ -2045,10 +2045,10 @@ static void nv_drain_rx(struct net_device *dev)
}
wmb();
if (np->rx_skb[i].skb) {
-   pci_unmap_single(np->pci_dev, np->rx_skb[i].dma,
+   dma_unmap_single(>pci_dev->dev, np->rx_skb[i].dma,
 (skb_end_pointer(np->rx_skb[i].skb) -
- np->rx_skb[i].skb->data),
-PCI_DMA_FROMDEVICE);
+np->rx_skb[i].skb->data),
+DMA_FROM_DEVICE);
dev_kfree_skb(np->rx_skb[i].skb);
np->rx_skb[i].skb = NULL;
}
@@ -2221,10 +2221,11 @@ static netdev_tx_t nv_start_xmit(struct sk_buff *skb, 
struct net_device *dev)
prev_tx = put_tx;
prev_tx_ctx = np->put_tx_ctx;
bcnt = (size > NV_TX2_TSO_MAX_SIZE) ? NV_TX2_TSO_MAX_SIZE : 
size;
-   np->put_tx_ctx->dma = pci_map_single(np->pci_dev, skb->data + 
offset, bcnt,
-   PCI_DMA_TODEVICE);
-   if (pci_dma_mapping_error(np->pci_dev,
- np->put_tx_ctx->dma)) {
+   np->put_tx_ctx->dma = dma_map_single(>pci_dev->dev,
+

[PATCH 1/1] forcedeth: remove tx_stop variable

2017-09-08 Thread Zhu Yanjun
The variable tx_stop is used to indicate the tx queue state: started
or stopped. In fact, the inline function netif_queue_stopped can do
the same work. So replace the variable tx_stop with the
function netif_queue_stopped.

Signed-off-by: Zhu Yanjun <yanjun@oracle.com>
---
 drivers/net/ethernet/nvidia/forcedeth.c | 13 -
 1 file changed, 4 insertions(+), 9 deletions(-)

diff --git a/drivers/net/ethernet/nvidia/forcedeth.c 
b/drivers/net/ethernet/nvidia/forcedeth.c
index 994a83a..e6e0de4 100644
--- a/drivers/net/ethernet/nvidia/forcedeth.c
+++ b/drivers/net/ethernet/nvidia/forcedeth.c
@@ -834,7 +834,6 @@ struct fe_priv {
u32 tx_pkts_in_progress;
struct nv_skb_map *tx_change_owner;
struct nv_skb_map *tx_end_flip;
-   int tx_stop;
 
/* TX software stats */
struct u64_stats_sync swstats_tx_syncp;
@@ -1939,7 +1938,6 @@ static void nv_init_tx(struct net_device *dev)
np->tx_pkts_in_progress = 0;
np->tx_change_owner = NULL;
np->tx_end_flip = NULL;
-   np->tx_stop = 0;
 
for (i = 0; i < np->tx_ring_size; i++) {
if (!nv_optimized(np)) {
@@ -2211,7 +2209,6 @@ static netdev_tx_t nv_start_xmit(struct sk_buff *skb, 
struct net_device *dev)
empty_slots = nv_get_empty_tx_slots(np);
if (unlikely(empty_slots <= entries)) {
netif_stop_queue(dev);
-   np->tx_stop = 1;
spin_unlock_irqrestore(>lock, flags);
return NETDEV_TX_BUSY;
}
@@ -2359,7 +2356,6 @@ static netdev_tx_t nv_start_xmit_optimized(struct sk_buff 
*skb,
empty_slots = nv_get_empty_tx_slots(np);
if (unlikely(empty_slots <= entries)) {
netif_stop_queue(dev);
-   np->tx_stop = 1;
spin_unlock_irqrestore(>lock, flags);
return NETDEV_TX_BUSY;
}
@@ -2583,8 +2579,8 @@ static int nv_tx_done(struct net_device *dev, int limit)
 
netdev_completed_queue(np->dev, tx_work, bytes_compl);
 
-   if (unlikely((np->tx_stop == 1) && (np->get_tx.orig != orig_get_tx))) {
-   np->tx_stop = 0;
+   if (unlikely(netif_queue_stopped(dev) &&
+(np->get_tx.orig != orig_get_tx))) {
netif_wake_queue(dev);
}
return tx_work;
@@ -2637,8 +2633,8 @@ static int nv_tx_done_optimized(struct net_device *dev, 
int limit)
 
netdev_completed_queue(np->dev, tx_work, bytes_cleaned);
 
-   if (unlikely((np->tx_stop == 1) && (np->get_tx.ex != orig_get_tx))) {
-   np->tx_stop = 0;
+   if (unlikely(netif_queue_stopped(dev) &&
+(np->get_tx.ex != orig_get_tx))) {
netif_wake_queue(dev);
}
return tx_work;
@@ -2724,7 +2720,6 @@ static void nv_tx_timeout(struct net_device *dev)
/* 2) complete any outstanding tx and do not give HW any limited tx 
pkts */
saved_tx_limit = np->tx_limit;
np->tx_limit = 0; /* prevent giving HW any limited pkts */
-   np->tx_stop = 0;  /* prevent waking tx queue */
if (!nv_optimized(np))
nv_tx_done(dev, np->tx_ring_size);
else
-- 
2.7.4



[PATCH 2/2] mlx5: remove unnecessary pci_set_drvdata()

2017-08-15 Thread Zhu Yanjun
The driver core clears the driver data to NULL after device_release
or on probe failure. Thus, it is not necessary to manually clear the
device driver data to NULL.

Cc: Joe Jin <joe@oracle.com>
Cc: Junxiao Bi <junxiao...@oracle.com>
Signed-off-by: Zhu Yanjun <yanjun@oracle.com>
---
 drivers/net/ethernet/mellanox/mlx5/core/main.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/main.c 
b/drivers/net/ethernet/mellanox/mlx5/core/main.c
index c065132..2cafbdc 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/main.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/main.c
@@ -1407,7 +1407,6 @@ static int init_one(struct pci_dev *pdev,
cleanup_srcu_struct(>pfault_srcu);
 clean_dev:
 #endif
-   pci_set_drvdata(pdev, NULL);
devlink_free(devlink);
 
return err;
@@ -1434,7 +1433,6 @@ static void remove_one(struct pci_dev *pdev)
 #ifdef CONFIG_INFINIBAND_ON_DEMAND_PAGING
cleanup_srcu_struct(>pfault_srcu);
 #endif
-   pci_set_drvdata(pdev, NULL);
devlink_free(devlink);
 }
 
-- 
2.7.4



[PATCH 1/2] mlx4: remove unnecessary pci_set_drvdata()

2017-08-15 Thread Zhu Yanjun
The driver core clears the driver data to NULL after device_release
or on probe failure. Thus, it is not necessary to manually clear the
device driver data to NULL.

Cc: Joe Jin <joe@oracle.com>
Cc: Junxiao Bi <junxiao...@oracle.com>
Signed-off-by: Zhu Yanjun <yanjun@oracle.com>
---
 drivers/net/ethernet/mellanox/mlx4/main.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx4/main.c 
b/drivers/net/ethernet/mellanox/mlx4/main.c
index 09b9bc1..df9b0ef 100644
--- a/drivers/net/ethernet/mellanox/mlx4/main.c
+++ b/drivers/net/ethernet/mellanox/mlx4/main.c
@@ -3782,7 +3782,6 @@ static int __mlx4_init_one(struct pci_dev *pdev, int 
pci_dev_data,
 
 err_disable_pdev:
mlx4_pci_disable_device(>dev);
-   pci_set_drvdata(pdev, NULL);
return err;
 }
 
@@ -3997,7 +3996,6 @@ static void mlx4_remove_one(struct pci_dev *pdev)
devlink_unregister(devlink);
kfree(dev->persist);
devlink_free(devlink);
-   pci_set_drvdata(pdev, NULL);
 }
 
 static int restore_current_port_types(struct mlx4_dev *dev,
-- 
2.7.4



[PATCH 1/1] forcedeth: replace init_timer_deferrable with setup_deferrable_timer

2017-08-10 Thread Zhu Yanjun
Replace init_timer_deferrable with setup_deferrable_timer to simplify
the source code.

Signed-off-by: Zhu Yanjun <yanjun@oracle.com>
---
 drivers/net/ethernet/nvidia/forcedeth.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/nvidia/forcedeth.c 
b/drivers/net/ethernet/nvidia/forcedeth.c
index aa912f4..bdbfe8f 100644
--- a/drivers/net/ethernet/nvidia/forcedeth.c
+++ b/drivers/net/ethernet/nvidia/forcedeth.c
@@ -5629,9 +5629,8 @@ static int nv_probe(struct pci_dev *pci_dev, const struct 
pci_device_id *id)
 
setup_timer(>oom_kick, nv_do_rx_refill, (unsigned long)dev);
setup_timer(>nic_poll, nv_do_nic_poll, (unsigned long)dev);
-   init_timer_deferrable(>stats_poll);
-   np->stats_poll.data = (unsigned long) dev;
-   np->stats_poll.function = nv_do_stats_poll; /* timer handler */
+   setup_deferrable_timer(>stats_poll, nv_do_stats_poll,
+  (unsigned long)dev);
 
err = pci_enable_device(pci_dev);
if (err)
-- 
2.7.4



[PATCH 1/1] mlx4_en: remove unnecessary error check

2017-07-24 Thread Zhu Yanjun
The function mlx4_en_get_profile always return zero. So it is not
necessary to check its return value.

CC: Joe Jin <joe@oracle.com>
CC: Junxiao Bi <junxiao...@oracle.com>
Signed-off-by: Zhu Yanjun <yanjun@oracle.com>
---
 drivers/net/ethernet/mellanox/mlx4/en_main.c | 9 ++---
 1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx4/en_main.c 
b/drivers/net/ethernet/mellanox/mlx4/en_main.c
index 2b0cbca..686e18d 100644
--- a/drivers/net/ethernet/mellanox/mlx4/en_main.c
+++ b/drivers/net/ethernet/mellanox/mlx4/en_main.c
@@ -147,7 +147,7 @@ void mlx4_en_update_loopback_state(struct net_device *dev,
mutex_unlock(>mdev->state_lock);
 }
 
-static int mlx4_en_get_profile(struct mlx4_en_dev *mdev)
+static void mlx4_en_get_profile(struct mlx4_en_dev *mdev)
 {
struct mlx4_en_profile *params = >profile;
int i;
@@ -176,8 +176,6 @@ static int mlx4_en_get_profile(struct mlx4_en_dev *mdev)
params->prof[i].rss_rings = 0;
params->prof[i].inline_thold = inline_thold;
}
-
-   return 0;
 }
 
 static void *mlx4_en_get_netdev(struct mlx4_dev *dev, void *ctx, u8 port)
@@ -309,10 +307,7 @@ static void *mlx4_en_add(struct mlx4_dev *dev)
}
 
/* Build device profile according to supplied module parameters */
-   if (mlx4_en_get_profile(mdev)) {
-   mlx4_err(mdev, "Bad module parameters, aborting\n");
-   goto err_mr;
-   }
+   mlx4_en_get_profile(mdev);
 
/* Configure which ports to start according to module parameters */
mdev->port_cnt = 0;
-- 
2.7.4



[PATCH 1/1] mlx4_en: remove unnecessary returned value

2017-07-23 Thread Zhu Yanjun
The function mlx4_en_arm_cq always returns zero. So change the
return type of the function mlx4_en_arm_cq to void.

CC: Joe Jin <joe@oracle.com>
CC: Junxiao Bi <junxiao...@oracle.com>
Signed-off-by: Zhu Yanjun <yanjun@oracle.com>
---
 drivers/net/ethernet/mellanox/mlx4/en_cq.c   | 4 +---
 drivers/net/ethernet/mellanox/mlx4/mlx4_en.h | 2 +-
 2 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx4/en_cq.c 
b/drivers/net/ethernet/mellanox/mlx4/en_cq.c
index 85fe17e..87d1f4d 100644
--- a/drivers/net/ethernet/mellanox/mlx4/en_cq.c
+++ b/drivers/net/ethernet/mellanox/mlx4/en_cq.c
@@ -208,12 +208,10 @@ int mlx4_en_set_cq_moder(struct mlx4_en_priv *priv, 
struct mlx4_en_cq *cq)
  cq->moder_cnt, cq->moder_time);
 }
 
-int mlx4_en_arm_cq(struct mlx4_en_priv *priv, struct mlx4_en_cq *cq)
+void mlx4_en_arm_cq(struct mlx4_en_priv *priv, struct mlx4_en_cq *cq)
 {
mlx4_cq_arm(>mcq, MLX4_CQ_DB_REQ_NOT, priv->mdev->uar_map,
>mdev->uar_lock);
-
-   return 0;
 }
 
 
diff --git a/drivers/net/ethernet/mellanox/mlx4/mlx4_en.h 
b/drivers/net/ethernet/mellanox/mlx4/mlx4_en.h
index d350b21..fdb3ad0 100644
--- a/drivers/net/ethernet/mellanox/mlx4/mlx4_en.h
+++ b/drivers/net/ethernet/mellanox/mlx4/mlx4_en.h
@@ -685,7 +685,7 @@ int mlx4_en_activate_cq(struct mlx4_en_priv *priv, struct 
mlx4_en_cq *cq,
int cq_idx);
 void mlx4_en_deactivate_cq(struct mlx4_en_priv *priv, struct mlx4_en_cq *cq);
 int mlx4_en_set_cq_moder(struct mlx4_en_priv *priv, struct mlx4_en_cq *cq);
-int mlx4_en_arm_cq(struct mlx4_en_priv *priv, struct mlx4_en_cq *cq);
+void mlx4_en_arm_cq(struct mlx4_en_priv *priv, struct mlx4_en_cq *cq);
 
 void mlx4_en_tx_irq(struct mlx4_cq *mcq);
 u16 mlx4_en_select_queue(struct net_device *dev, struct sk_buff *skb,
-- 
2.7.4



[PATCHv2 1/1] mlx4_en: remove unnecessary returned value check

2017-07-13 Thread Zhu Yanjun
The function __mlx4_zone_remove_one_entry always returns zero. So
it is not necessary to check it.

Cc: Joe Jin <joe@oracle.com>
Cc: Junxiao Bi <junxiao...@oracle.com>
Signed-off-by: Zhu Yanjun <yanjun@oracle.com>
Reviewed-by: Yuval Shaia <yuval.sh...@oracle.com>
---
Change from v1 to v2:
 Initialization is moved to variable declaration.

 drivers/net/ethernet/mellanox/mlx4/alloc.c | 8 +++-
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx4/alloc.c 
b/drivers/net/ethernet/mellanox/mlx4/alloc.c
index 249a458..710d6c6 100644
--- a/drivers/net/ethernet/mellanox/mlx4/alloc.c
+++ b/drivers/net/ethernet/mellanox/mlx4/alloc.c
@@ -283,7 +283,7 @@ int mlx4_zone_add_one(struct mlx4_zone_allocator 
*zone_alloc,
 }
 
 /* Should be called under a lock */
-static int __mlx4_zone_remove_one_entry(struct mlx4_zone_entry *entry)
+static void __mlx4_zone_remove_one_entry(struct mlx4_zone_entry *entry)
 {
struct mlx4_zone_allocator *zone_alloc = entry->allocator;
 
@@ -315,8 +315,6 @@ static int __mlx4_zone_remove_one_entry(struct 
mlx4_zone_entry *entry)
}
zone_alloc->mask = mask;
}
-
-   return 0;
 }
 
 void mlx4_zone_allocator_destroy(struct mlx4_zone_allocator *zone_alloc)
@@ -457,7 +455,7 @@ struct mlx4_bitmap *mlx4_zone_get_bitmap(struct 
mlx4_zone_allocator *zones, u32
 int mlx4_zone_remove_one(struct mlx4_zone_allocator *zones, u32 uid)
 {
struct mlx4_zone_entry *zone;
-   int res;
+   int res = 0;
 
spin_lock(>lock);
 
@@ -468,7 +466,7 @@ int mlx4_zone_remove_one(struct mlx4_zone_allocator *zones, 
u32 uid)
goto out;
}
 
-   res = __mlx4_zone_remove_one_entry(zone);
+   __mlx4_zone_remove_one_entry(zone);
 
 out:
spin_unlock(>lock);
-- 
2.7.4



[PATCH 1/1] mlx4_en: remove unnecessary returned value check

2017-07-12 Thread Zhu Yanjun
The function __mlx4_zone_remove_one_entry always returns zero. So
it is not necessary to check it.

Cc: Joe Jin <joe@oracle.com>
Cc: Junxiao Bi <junxiao...@oracle.com>
Signed-off-by: Zhu Yanjun <yanjun@oracle.com>
---
 drivers/net/ethernet/mellanox/mlx4/alloc.c | 7 +++
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx4/alloc.c 
b/drivers/net/ethernet/mellanox/mlx4/alloc.c
index 249a458..bfb185d 100644
--- a/drivers/net/ethernet/mellanox/mlx4/alloc.c
+++ b/drivers/net/ethernet/mellanox/mlx4/alloc.c
@@ -283,7 +283,7 @@ int mlx4_zone_add_one(struct mlx4_zone_allocator 
*zone_alloc,
 }
 
 /* Should be called under a lock */
-static int __mlx4_zone_remove_one_entry(struct mlx4_zone_entry *entry)
+static void __mlx4_zone_remove_one_entry(struct mlx4_zone_entry *entry)
 {
struct mlx4_zone_allocator *zone_alloc = entry->allocator;
 
@@ -315,8 +315,6 @@ static int __mlx4_zone_remove_one_entry(struct 
mlx4_zone_entry *entry)
}
zone_alloc->mask = mask;
}
-
-   return 0;
 }
 
 void mlx4_zone_allocator_destroy(struct mlx4_zone_allocator *zone_alloc)
@@ -468,7 +466,8 @@ int mlx4_zone_remove_one(struct mlx4_zone_allocator *zones, 
u32 uid)
goto out;
}
 
-   res = __mlx4_zone_remove_one_entry(zone);
+   __mlx4_zone_remove_one_entry(zone);
+   res = 0;
 
 out:
spin_unlock(>lock);
-- 
2.7.4



[PATCH 1/1] mlx4_en: make mlx4_log_num_mgm_entry_size static

2017-07-02 Thread Zhu Yanjun
The variable mlx4_log_num_mgm_entry_size is only called in main.c.

CC: Joe Jin <joe@oracle.com>
CC: Junxiao Bi <junxiao...@oracle.com>
Signed-off-by: Zhu Yanjun <yanjun@oracle.com>
---
 drivers/net/ethernet/mellanox/mlx4/main.c | 2 +-
 drivers/net/ethernet/mellanox/mlx4/mlx4.h | 1 -
 2 files changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx4/main.c 
b/drivers/net/ethernet/mellanox/mlx4/main.c
index 83aab1e..4b67277 100644
--- a/drivers/net/ethernet/mellanox/mlx4/main.c
+++ b/drivers/net/ethernet/mellanox/mlx4/main.c
@@ -91,7 +91,7 @@ module_param_array(probe_vf, byte, _vfs_argc, 0444);
 MODULE_PARM_DESC(probe_vf, "number of vfs to probe by pf driver (num_vfs > 
0)\n"
   "probe_vf=port1,port2,port1+2");
 
-int mlx4_log_num_mgm_entry_size = MLX4_DEFAULT_MGM_LOG_ENTRY_SIZE;
+static int mlx4_log_num_mgm_entry_size = MLX4_DEFAULT_MGM_LOG_ENTRY_SIZE;
 module_param_named(log_num_mgm_entry_size,
mlx4_log_num_mgm_entry_size, int, 0444);
 MODULE_PARM_DESC(log_num_mgm_entry_size, "log mgm size, that defines the num"
diff --git a/drivers/net/ethernet/mellanox/mlx4/mlx4.h 
b/drivers/net/ethernet/mellanox/mlx4/mlx4.h
index b4f1bc5..a3f5edb 100644
--- a/drivers/net/ethernet/mellanox/mlx4/mlx4.h
+++ b/drivers/net/ethernet/mellanox/mlx4/mlx4.h
@@ -231,7 +231,6 @@ do {
\
 #define mlx4_warn(mdev, format, ...)   \
dev_warn(&(mdev)->persist->pdev->dev, format, ##__VA_ARGS__)
 
-extern int mlx4_log_num_mgm_entry_size;
 extern int log_mtts_per_seg;
 extern int mlx4_internal_err_reset;
 
-- 
2.7.4



[PATCH 1/1] forcedeth: remove unnecessary carrier status check

2017-05-02 Thread Zhu Yanjun
Since netif_carrier_on() will do nothing if device's
carrier is already on, so it's unnecessary to do
carrier status check.

It's the same for netif_carrier_off().

Signed-off-by: Zhu Yanjun <yanjun@oracle.com>
---
 drivers/net/ethernet/nvidia/forcedeth.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/net/ethernet/nvidia/forcedeth.c 
b/drivers/net/ethernet/nvidia/forcedeth.c
index 978d329..aa912f4 100644
--- a/drivers/net/ethernet/nvidia/forcedeth.c
+++ b/drivers/net/ethernet/nvidia/forcedeth.c
@@ -4248,11 +4248,9 @@ static int nv_get_link_ksettings(struct net_device *dev,
/* We do not track link speed / duplex setting if the
 * interface is disabled. Force a link check */
if (nv_update_linkspeed(dev)) {
-   if (!netif_carrier_ok(dev))
-   netif_carrier_on(dev);
+   netif_carrier_on(dev);
} else {
-   if (netif_carrier_ok(dev))
-   netif_carrier_off(dev);
+   netif_carrier_off(dev);
}
}
 
-- 
2.7.4



[PATCH 1/1] bonding: use 'M' or 'G' based on the speed

2017-04-20 Thread Zhu Yanjun
If the speed of the slave netdev is more than 1000M,
it is better to use 'G' instead of 'M'.

Signed-off-by: Zhu Yanjun <yanjun@oracle.com>
---
 drivers/net/bonding/bond_main.c   | 8 ++--
 drivers/net/bonding/bond_procfs.c | 6 +-
 2 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index af9f0ce..1aad13d 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -2147,9 +2147,13 @@ static void bond_miimon_commit(struct bonding *bond)
bond_set_backup_slave(slave);
}
 
-   netdev_info(bond->dev, "link status definitely up for 
interface %s, %u Mbps %s duplex\n",
+   netdev_info(bond->dev, "link status definitely up for 
interface %s, %u%sbps %s duplex\n",
slave->dev->name,
-   slave->speed == SPEED_UNKNOWN ? 0 : 
slave->speed,
+   slave->speed == SPEED_UNKNOWN ? 0 :
+   (slave->speed > 1000 ?
+   slave->speed / 1000 : slave->speed),
+   slave->speed > 1000 ?
+   slave->speed % 1000 ? ".5 G" : " G" : " M",
slave->duplex ? "full" : "half");
 
/* notify ad that the link status has changed */
diff --git a/drivers/net/bonding/bond_procfs.c 
b/drivers/net/bonding/bond_procfs.c
index f514fe5..4c31055 100644
--- a/drivers/net/bonding/bond_procfs.c
+++ b/drivers/net/bonding/bond_procfs.c
@@ -173,7 +173,11 @@ static void bond_info_show_slave(struct seq_file *seq,
if (slave->speed == SPEED_UNKNOWN)
seq_printf(seq, "Speed: %s\n", "Unknown");
else
-   seq_printf(seq, "Speed: %d Mbps\n", slave->speed);
+   seq_printf(seq, "Speed: %d%sbps\n",
+  slave->speed > 1000 ?
+  slave->speed / 1000 : slave->speed,
+  slave->speed > 1000 ?
+  (slave->speed % 1000 ? ".5 G" : " G") : " M");
 
if (slave->duplex == DUPLEX_UNKNOWN)
seq_printf(seq, "Duplex: %s\n", "Unknown");
-- 
2.7.4



[PATCH 1/1] bonding: remove unnecessary return

2017-04-19 Thread Zhu Yanjun
The type of the function bond_update_speed_duplex is void.
So the return in the end of the function should be removed.

Signed-off-by: Zhu Yanjun <yanjun@oracle.com>
---
 drivers/net/bonding/bond_main.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index 8a4ba8b..af9f0ce 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -399,8 +399,6 @@ static void bond_update_speed_duplex(struct slave *slave)
 
slave->speed = ecmd.base.speed;
slave->duplex = ecmd.base.duplex;
-
-   return;
 }
 
 const char *bond_slave_link_status(s8 link)
-- 
2.7.4



[PATCH 2/5] rds: rdma: fix memory leak error

2017-03-27 Thread Zhu Yanjun
In the function __rds_rdma_map, the allocated memory and other
resources should be freed when some error occurs.

Signed-off-by: Zhu Yanjun <yanjun@oracle.com>
---
 net/rds/rdma.c | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/net/rds/rdma.c b/net/rds/rdma.c
index f06fac4..ad9b6bd 100644
--- a/net/rds/rdma.c
+++ b/net/rds/rdma.c
@@ -253,6 +253,8 @@ static int __rds_rdma_map(struct rds_sock *rs, struct 
rds_get_mr_args *args,
sg = kcalloc(nents, sizeof(*sg), GFP_KERNEL);
if (!sg) {
ret = -ENOMEM;
+   for (i = 0; i < nents; i++)
+   put_page(pages[i]);
goto out;
}
WARN_ON(!nents);
@@ -293,6 +295,11 @@ static int __rds_rdma_map(struct rds_sock *rs, struct 
rds_get_mr_args *args,
*cookie_ret = cookie;
 
if (args->cookie_addr && put_user(cookie, (u64 __user *)(unsigned long) 
args->cookie_addr)) {
+   for (i = 0; i < nents; i++)
+   put_page(sg_page([i]));
+   kfree(sg);
+   mr->r_trans->free_mr(mr->r_trans_private, 1);
+   mr->r_trans_private = NULL;
ret = -EFAULT;
goto out;
}
-- 
2.7.4



[PATCH 0/5] rds: trivial patches

2017-03-27 Thread Zhu Yanjun
Hi, all 

The 5 patches are trivial patches.

Thanks a lot.

Zhu Yanjun (5):
  rds: tcp: release the created connection
  rds: rdma: fix memory leak error
  rds: remove unnecessary returned value check
  rds: remove the unused variable
  rds: ib: add the static type to the functions

 net/rds/af_rds.c |  5 +
 net/rds/ib_mr.h  |  2 --
 net/rds/ib_rdma.c| 12 +---
 net/rds/ib_recv.c|  3 +--
 net/rds/rdma.c   |  7 +++
 net/rds/rds.h|  2 +-
 net/rds/stats.c  |  3 +--
 net/rds/tcp_listen.c |  1 +
 8 files changed, 17 insertions(+), 18 deletions(-)

-- 
2.7.4



[PATCH 1/5] rds: tcp: release the created connection

2017-03-27 Thread Zhu Yanjun
When some error occurs, the created connection should be destroyed.

Signed-off-by: Zhu Yanjun <yanjun@oracle.com>
---
 net/rds/tcp_listen.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/net/rds/tcp_listen.c b/net/rds/tcp_listen.c
index 5076788..58aa5bc 100644
--- a/net/rds/tcp_listen.c
+++ b/net/rds/tcp_listen.c
@@ -196,6 +196,7 @@ int rds_tcp_accept_one(struct socket *sock)
 rst_nsk:
/* reset the newly returned accept sock and bail */
kernel_sock_shutdown(new_sock, SHUT_RDWR);
+   rds_conn_destroy(conn);
ret = 0;
 out:
if (rs_tcp)
-- 
2.7.4



[PATCH 4/5] rds: remove the unused variable

2017-03-27 Thread Zhu Yanjun
In the function rds_ib_recv_path, the variable ret is not used.

Signed-off-by: Zhu Yanjun <yanjun@oracle.com>
---
 net/rds/ib_recv.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/net/rds/ib_recv.c b/net/rds/ib_recv.c
index e10624a..be8d2f2 100644
--- a/net/rds/ib_recv.c
+++ b/net/rds/ib_recv.c
@@ -1023,7 +1023,6 @@ int rds_ib_recv_path(struct rds_conn_path *cp)
 {
struct rds_connection *conn = cp->cp_conn;
struct rds_ib_connection *ic = conn->c_transport_data;
-   int ret = 0;
 
rdsdebug("conn %p\n", conn);
if (rds_conn_up(conn)) {
@@ -1031,7 +1030,7 @@ int rds_ib_recv_path(struct rds_conn_path *cp)
rds_ib_recv_refill(conn, 0, GFP_KERNEL);
}
 
-   return ret;
+   return 0;
 }
 
 int rds_ib_recv_init(void)
-- 
2.7.4



[PATCH 3/5] rds: remove unnecessary returned value check

2017-03-27 Thread Zhu Yanjun
In the function rds_stats_init, the returned value
is always zero. As such, it is not necessary to check it.
And change the return type to void.

Signed-off-by: Zhu Yanjun <yanjun@oracle.com>
---
 net/rds/af_rds.c | 5 +
 net/rds/rds.h| 2 +-
 net/rds/stats.c  | 3 +--
 3 files changed, 3 insertions(+), 7 deletions(-)

diff --git a/net/rds/af_rds.c b/net/rds/af_rds.c
index b405f77..a696096 100644
--- a/net/rds/af_rds.c
+++ b/net/rds/af_rds.c
@@ -658,9 +658,7 @@ static int rds_init(void)
ret = rds_sysctl_init();
if (ret)
goto out_threads;
-   ret = rds_stats_init();
-   if (ret)
-   goto out_sysctl;
+   rds_stats_init();
ret = proto_register(_proto, 1);
if (ret)
goto out_stats;
@@ -677,7 +675,6 @@ static int rds_init(void)
proto_unregister(_proto);
 out_stats:
rds_stats_exit();
-out_sysctl:
rds_sysctl_exit();
 out_threads:
rds_threads_exit();
diff --git a/net/rds/rds.h b/net/rds/rds.h
index 82d38cc..82a8856 100644
--- a/net/rds/rds.h
+++ b/net/rds/rds.h
@@ -870,7 +870,7 @@ DECLARE_PER_CPU_SHARED_ALIGNED(struct rds_statistics, 
rds_stats);
put_cpu();  \
 } while (0)
 #define rds_stats_add(member, count) rds_stats_add_which(rds_stats, member, 
count)
-int rds_stats_init(void);
+void rds_stats_init(void);
 void rds_stats_exit(void);
 void rds_stats_info_copy(struct rds_info_iterator *iter,
 uint64_t *values, const char *const *names,
diff --git a/net/rds/stats.c b/net/rds/stats.c
index 73be187..e83b4bb 100644
--- a/net/rds/stats.c
+++ b/net/rds/stats.c
@@ -145,8 +145,7 @@ void rds_stats_exit(void)
rds_info_deregister_func(RDS_INFO_COUNTERS, rds_stats_info);
 }
 
-int rds_stats_init(void)
+void rds_stats_init(void)
 {
rds_info_register_func(RDS_INFO_COUNTERS, rds_stats_info);
-   return 0;
 }
-- 
2.7.4



[PATCH 5/5] rds: ib: add the static type to the functions

2017-03-27 Thread Zhu Yanjun
The functions rds_ib_flush_mr_pool and rds_ib_reuse_mr
are called in the local file. As such, the static type
is added to limit them in the local file.

And the function rds_ib_flush_mr_pool always returns zero.
As such, change the return type to void.

Signed-off-by: Zhu Yanjun <yanjun@oracle.com>
---
 net/rds/ib_mr.h   |  2 --
 net/rds/ib_rdma.c | 12 +---
 2 files changed, 5 insertions(+), 9 deletions(-)

diff --git a/net/rds/ib_mr.h b/net/rds/ib_mr.h
index 0ea4ab0..a3a9676 100644
--- a/net/rds/ib_mr.h
+++ b/net/rds/ib_mr.h
@@ -125,8 +125,6 @@ void rds_ib_mr_exit(void);
 void __rds_ib_teardown_mr(struct rds_ib_mr *);
 void rds_ib_teardown_mr(struct rds_ib_mr *);
 struct rds_ib_mr *rds_ib_alloc_fmr(struct rds_ib_device *, int);
-struct rds_ib_mr *rds_ib_reuse_mr(struct rds_ib_mr_pool *);
-int rds_ib_flush_mr_pool(struct rds_ib_mr_pool *, int, struct rds_ib_mr **);
 struct rds_ib_mr *rds_ib_reg_fmr(struct rds_ib_device *, struct scatterlist *,
 unsigned long, u32 *);
 struct rds_ib_mr *rds_ib_try_reuse_ibmr(struct rds_ib_mr_pool *);
diff --git a/net/rds/ib_rdma.c b/net/rds/ib_rdma.c
index 977f698..1bd3aba 100644
--- a/net/rds/ib_rdma.c
+++ b/net/rds/ib_rdma.c
@@ -179,7 +179,7 @@ void rds_ib_get_mr_info(struct rds_ib_device *rds_ibdev, 
struct rds_info_rdma_co
iinfo->rdma_mr_size = pool_1m->fmr_attr.max_pages;
 }
 
-struct rds_ib_mr *rds_ib_reuse_mr(struct rds_ib_mr_pool *pool)
+static struct rds_ib_mr *rds_ib_reuse_mr(struct rds_ib_mr_pool *pool)
 {
struct rds_ib_mr *ibmr = NULL;
struct llist_node *ret;
@@ -336,8 +336,8 @@ static void list_to_llist_nodes(struct rds_ib_mr_pool *pool,
  * If the number of MRs allocated exceeds the limit, we also try
  * to free as many MRs as needed to get back to this limit.
  */
-int rds_ib_flush_mr_pool(struct rds_ib_mr_pool *pool,
-int free_all, struct rds_ib_mr **ibmr_ret)
+static void rds_ib_flush_mr_pool(struct rds_ib_mr_pool *pool,
+int free_all, struct rds_ib_mr **ibmr_ret)
 {
struct rds_ib_mr *ibmr;
struct llist_node *clean_nodes;
@@ -358,7 +358,7 @@ int rds_ib_flush_mr_pool(struct rds_ib_mr_pool *pool,
if (ibmr) {
*ibmr_ret = ibmr;
finish_wait(>flush_wait, );
-   goto out_nolock;
+   return;
}
 
prepare_to_wait(>flush_wait, ,
@@ -370,7 +370,7 @@ int rds_ib_flush_mr_pool(struct rds_ib_mr_pool *pool,
if (ibmr) {
*ibmr_ret = ibmr;
finish_wait(>flush_wait, );
-   goto out_nolock;
+   return;
}
}
finish_wait(>flush_wait, );
@@ -433,8 +433,6 @@ int rds_ib_flush_mr_pool(struct rds_ib_mr_pool *pool,
mutex_unlock(>flush_lock);
if (waitqueue_active(>flush_wait))
wake_up(>flush_wait);
-out_nolock:
-   return 0;
 }
 
 struct rds_ib_mr *rds_ib_try_reuse_ibmr(struct rds_ib_mr_pool *pool)
-- 
2.7.4



[PATCHv3 4/4] rds: ib: unmap the scatter/gather list when error

2017-03-12 Thread Zhu Yanjun
When some errors occur, the scatter/gather list mapped to DMA addresses
should be handled.

Cc: Joe Jin <joe@oracle.com>
Cc: Junxiao Bi <junxiao...@oracle.com>
Acked-by: Santosh Shilimkar <santosh.shilim...@oracle.com>
Signed-off-by: Zhu Yanjun <yanjun@oracle.com>
---
 net/rds/ib_fmr.c | 26 +++---
 1 file changed, 19 insertions(+), 7 deletions(-)

diff --git a/net/rds/ib_fmr.c b/net/rds/ib_fmr.c
index c936b0d..86ef907 100644
--- a/net/rds/ib_fmr.c
+++ b/net/rds/ib_fmr.c
@@ -112,29 +112,39 @@ static int rds_ib_map_fmr(struct rds_ib_device *rds_ibdev,
u64 dma_addr = ib_sg_dma_address(dev, [i]);
 
if (dma_addr & ~PAGE_MASK) {
-   if (i > 0)
+   if (i > 0) {
+   ib_dma_unmap_sg(dev, sg, nents,
+   DMA_BIDIRECTIONAL);
return -EINVAL;
-   else
+   } else {
++page_cnt;
+   }
}
if ((dma_addr + dma_len) & ~PAGE_MASK) {
-   if (i < sg_dma_len - 1)
+   if (i < sg_dma_len - 1) {
+   ib_dma_unmap_sg(dev, sg, nents,
+   DMA_BIDIRECTIONAL);
return -EINVAL;
-   else
+   } else {
++page_cnt;
+   }
}
 
len += dma_len;
}
 
page_cnt += len >> PAGE_SHIFT;
-   if (page_cnt > ibmr->pool->fmr_attr.max_pages)
+   if (page_cnt > ibmr->pool->fmr_attr.max_pages) {
+   ib_dma_unmap_sg(dev, sg, nents, DMA_BIDIRECTIONAL);
return -EINVAL;
+   }
 
dma_pages = kmalloc_node(sizeof(u64) * page_cnt, GFP_ATOMIC,
 rdsibdev_to_node(rds_ibdev));
-   if (!dma_pages)
+   if (!dma_pages) {
+   ib_dma_unmap_sg(dev, sg, nents, DMA_BIDIRECTIONAL);
return -ENOMEM;
+   }
 
page_cnt = 0;
for (i = 0; i < sg_dma_len; ++i) {
@@ -147,8 +157,10 @@ static int rds_ib_map_fmr(struct rds_ib_device *rds_ibdev,
}
 
ret = ib_map_phys_fmr(fmr->fmr, dma_pages, page_cnt, io_addr);
-   if (ret)
+   if (ret) {
+   ib_dma_unmap_sg(dev, sg, nents, DMA_BIDIRECTIONAL);
goto out;
+   }
 
/* Success - we successfully remapped the MR, so we can
 * safely tear down the old mapping.
-- 
2.7.4



[PATCHv3 3/4] rds: ib: add the static type to the function

2017-03-12 Thread Zhu Yanjun
The function rds_ib_map_fmr is used only in the ib_fmr.c
file. As such, the static type is added to limit it in this file.

Cc: Joe Jin <joe@oracle.com>
Cc: Junxiao Bi <junxiao...@oracle.com>
Acked-by: Santosh Shilimkar <santosh.shilim...@oracle.com>
Signed-off-by: Zhu Yanjun <yanjun@oracle.com>
---
 net/rds/ib_fmr.c | 5 +++--
 net/rds/ib_mr.h  | 2 --
 2 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/net/rds/ib_fmr.c b/net/rds/ib_fmr.c
index 249ae1c..c936b0d 100644
--- a/net/rds/ib_fmr.c
+++ b/net/rds/ib_fmr.c
@@ -84,8 +84,9 @@ struct rds_ib_mr *rds_ib_alloc_fmr(struct rds_ib_device 
*rds_ibdev, int npages)
return ERR_PTR(err);
 }
 
-int rds_ib_map_fmr(struct rds_ib_device *rds_ibdev, struct rds_ib_mr *ibmr,
-  struct scatterlist *sg, unsigned int nents)
+static int rds_ib_map_fmr(struct rds_ib_device *rds_ibdev,
+ struct rds_ib_mr *ibmr, struct scatterlist *sg,
+ unsigned int nents)
 {
struct ib_device *dev = rds_ibdev->dev;
struct rds_ib_fmr *fmr = >u.fmr;
diff --git a/net/rds/ib_mr.h b/net/rds/ib_mr.h
index 5d6e98a..0ea4ab0 100644
--- a/net/rds/ib_mr.h
+++ b/net/rds/ib_mr.h
@@ -125,8 +125,6 @@ void rds_ib_mr_exit(void);
 void __rds_ib_teardown_mr(struct rds_ib_mr *);
 void rds_ib_teardown_mr(struct rds_ib_mr *);
 struct rds_ib_mr *rds_ib_alloc_fmr(struct rds_ib_device *, int);
-int rds_ib_map_fmr(struct rds_ib_device *, struct rds_ib_mr *,
-  struct scatterlist *, unsigned int);
 struct rds_ib_mr *rds_ib_reuse_mr(struct rds_ib_mr_pool *);
 int rds_ib_flush_mr_pool(struct rds_ib_mr_pool *, int, struct rds_ib_mr **);
 struct rds_ib_mr *rds_ib_reg_fmr(struct rds_ib_device *, struct scatterlist *,
-- 
2.7.4



[PATCHv3 1/4] rds: ib: drop unnecessary rdma_reject

2017-03-12 Thread Zhu Yanjun
When rdma_accept fails, rdma_reject is called in it. As such, it is
not necessary to execute rdma_reject again.

Cc: Joe Jin <joe@oracle.com>
Cc: Junxiao Bi <junxiao...@oracle.com>
Acked-by: Santosh Shilimkar <santosh.shilim...@oracle.com>
Signed-off-by: Zhu Yanjun <yanjun@oracle.com>
---
 net/rds/ib_cm.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c
index ce3775a..4b9405c 100644
--- a/net/rds/ib_cm.c
+++ b/net/rds/ib_cm.c
@@ -677,9 +677,8 @@ int rds_ib_cm_handle_connect(struct rdma_cm_id *cm_id,
event->param.conn.initiator_depth);
 
/* rdma_accept() calls rdma_reject() internally if it fails */
-   err = rdma_accept(cm_id, _param);
-   if (err)
-   rds_ib_conn_error(conn, "rdma_accept failed (%d)\n", err);
+   if (rdma_accept(cm_id, _param))
+   rds_ib_conn_error(conn, "rdma_accept failed\n");
 
 out:
if (conn)
-- 
2.7.4



[PATCHv3 0/4] rds: ib: trivial patches

2017-03-12 Thread Zhu Yanjun
v2 -> v3
remove err from messages.

Zhu Yanjun (4):
  rds: ib: drop unnecessary rdma_reject
  rds: ib: remove redundant ib_dealloc_fmr
  rds: ib: add the static type to the function
  rds: ib: unmap the scatter/gather list when error

 net/rds/ib_cm.c  |  5 ++---
 net/rds/ib_fmr.c | 38 --
 net/rds/ib_mr.h  |  2 --
 3 files changed, 26 insertions(+), 19 deletions(-)

-- 
2.7.4



[PATCHv3 2/4] rds: ib: remove redundant ib_dealloc_fmr

2017-03-12 Thread Zhu Yanjun
The function ib_dealloc_fmr will never be called. As such, it should
be removed.

Cc: Joe Jin <joe@oracle.com>
Cc: Junxiao Bi <junxiao...@oracle.com>
Reviewed-by: Yuval Shaia <yuval.sh...@oracle.com>
Reviewed-by: Johannes Thumshirn <jthumsh...@suse.de>
Acked-by: Santosh Shilimkar <santosh.shilim...@oracle.com>
Signed-off-by: Zhu Yanjun <yanjun@oracle.com>
---
 net/rds/ib_fmr.c | 7 ++-
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/net/rds/ib_fmr.c b/net/rds/ib_fmr.c
index 4fe8f4f..249ae1c 100644
--- a/net/rds/ib_fmr.c
+++ b/net/rds/ib_fmr.c
@@ -78,12 +78,9 @@ struct rds_ib_mr *rds_ib_alloc_fmr(struct rds_ib_device 
*rds_ibdev, int npages)
return ibmr;
 
 out_no_cigar:
-   if (ibmr) {
-   if (fmr->fmr)
-   ib_dealloc_fmr(fmr->fmr);
-   kfree(ibmr);
-   }
+   kfree(ibmr);
atomic_dec(>item_count);
+
return ERR_PTR(err);
 }
 
-- 
2.7.4



[PATCH 1/1] r8169: replace init_timer with setup_timer

2017-03-12 Thread Zhu Yanjun
Replace init_timer with setup_timer to simplify the source code.

Signed-off-by: Zhu Yanjun <yanjun@oracle.com>
---
 drivers/net/ethernet/realtek/r8169.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/realtek/r8169.c 
b/drivers/net/ethernet/realtek/r8169.c
index 81f18a8..44cc422 100644
--- a/drivers/net/ethernet/realtek/r8169.c
+++ b/drivers/net/ethernet/realtek/r8169.c
@@ -8444,9 +8444,7 @@ static int rtl_init_one(struct pci_dev *pdev, const 
struct pci_device_id *ent)
tp->opts1_mask = (tp->mac_version != RTL_GIGA_MAC_VER_01) ?
~(RxBOVF | RxFOVF) : ~0;
 
-   init_timer(>timer);
-   tp->timer.data = (unsigned long) dev;
-   tp->timer.function = rtl8169_phy_timer;
+   setup_timer(>timer, rtl8169_phy_timer, (unsigned long)dev);
 
tp->rtl_fw = RTL_FIRMWARE_UNKNOWN;
 
-- 
2.7.4



[PATCHv2 1/4] rds: ib: drop unnecessary rdma_reject

2017-03-12 Thread Zhu Yanjun
When rdma_accept fails, rdma_reject is called in it. As such, it is
not necessary to execute rdma_reject again.

Cc: Joe Jin <joe@oracle.com>
Cc: Junxiao Bi <junxiao...@oracle.com>
Acked-by: Santosh Shilimkar <santosh.shilim...@oracle.com>
Signed-off-by: Zhu Yanjun <yanjun@oracle.com>
---
Change from v1 to v2:
  Add the acker.

 net/rds/ib_cm.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c
index ce3775a..eca3d5f 100644
--- a/net/rds/ib_cm.c
+++ b/net/rds/ib_cm.c
@@ -677,8 +677,7 @@ int rds_ib_cm_handle_connect(struct rdma_cm_id *cm_id,
event->param.conn.initiator_depth);
 
/* rdma_accept() calls rdma_reject() internally if it fails */
-   err = rdma_accept(cm_id, _param);
-   if (err)
+   if (rdma_accept(cm_id, _param))
rds_ib_conn_error(conn, "rdma_accept failed (%d)\n", err);
 
 out:
-- 
2.7.4



[PATCHv2 2/4] rds: ib: remove redundant ib_dealloc_fmr

2017-03-12 Thread Zhu Yanjun
The function ib_dealloc_fmr will never be called. As such, it should
be removed.

Cc: Joe Jin <joe@oracle.com>
Cc: Junxiao Bi <junxiao...@oracle.com>
Reviewed-by: Yuval Shaia <yuval.sh...@oracle.com>
Reviewed-by: Johannes Thumshirn <jthumsh...@suse.de>
Acked-by: Santosh Shilimkar <santosh.shilim...@oracle.com>
Signed-off-by: Zhu Yanjun <yanjun@oracle.com>
---
Change from v1 to v2:
  Add the reviewer and acker.
  Remove ibmr NULL test.

 net/rds/ib_fmr.c | 7 ++-
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/net/rds/ib_fmr.c b/net/rds/ib_fmr.c
index 4fe8f4f..249ae1c 100644
--- a/net/rds/ib_fmr.c
+++ b/net/rds/ib_fmr.c
@@ -78,12 +78,9 @@ struct rds_ib_mr *rds_ib_alloc_fmr(struct rds_ib_device 
*rds_ibdev, int npages)
return ibmr;
 
 out_no_cigar:
-   if (ibmr) {
-   if (fmr->fmr)
-   ib_dealloc_fmr(fmr->fmr);
-   kfree(ibmr);
-   }
+   kfree(ibmr);
atomic_dec(>item_count);
+
return ERR_PTR(err);
 }
 
-- 
2.7.4



[PATCHv2 3/4] rds: ib: add the static type to the function

2017-03-12 Thread Zhu Yanjun
The function rds_ib_map_fmr is used only in the ib_fmr.c
file. As such, the static type is added to limit it in this file.

Cc: Joe Jin <joe@oracle.com>
Cc: Junxiao Bi <junxiao...@oracle.com>
Acked-by: Santosh Shilimkar <santosh.shilim...@oracle.com>
Signed-off-by: Zhu Yanjun <yanjun@oracle.com>
---
Change from v1 to v2:
  Add the acker.

 net/rds/ib_fmr.c | 5 +++--
 net/rds/ib_mr.h  | 2 --
 2 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/net/rds/ib_fmr.c b/net/rds/ib_fmr.c
index 249ae1c..c936b0d 100644
--- a/net/rds/ib_fmr.c
+++ b/net/rds/ib_fmr.c
@@ -84,8 +84,9 @@ struct rds_ib_mr *rds_ib_alloc_fmr(struct rds_ib_device 
*rds_ibdev, int npages)
return ERR_PTR(err);
 }
 
-int rds_ib_map_fmr(struct rds_ib_device *rds_ibdev, struct rds_ib_mr *ibmr,
-  struct scatterlist *sg, unsigned int nents)
+static int rds_ib_map_fmr(struct rds_ib_device *rds_ibdev,
+ struct rds_ib_mr *ibmr, struct scatterlist *sg,
+ unsigned int nents)
 {
struct ib_device *dev = rds_ibdev->dev;
struct rds_ib_fmr *fmr = >u.fmr;
diff --git a/net/rds/ib_mr.h b/net/rds/ib_mr.h
index 5d6e98a..0ea4ab0 100644
--- a/net/rds/ib_mr.h
+++ b/net/rds/ib_mr.h
@@ -125,8 +125,6 @@ void rds_ib_mr_exit(void);
 void __rds_ib_teardown_mr(struct rds_ib_mr *);
 void rds_ib_teardown_mr(struct rds_ib_mr *);
 struct rds_ib_mr *rds_ib_alloc_fmr(struct rds_ib_device *, int);
-int rds_ib_map_fmr(struct rds_ib_device *, struct rds_ib_mr *,
-  struct scatterlist *, unsigned int);
 struct rds_ib_mr *rds_ib_reuse_mr(struct rds_ib_mr_pool *);
 int rds_ib_flush_mr_pool(struct rds_ib_mr_pool *, int, struct rds_ib_mr **);
 struct rds_ib_mr *rds_ib_reg_fmr(struct rds_ib_device *, struct scatterlist *,
-- 
2.7.4



[PATCHv2 4/4] rds: ib: unmap the scatter/gather list when error

2017-03-12 Thread Zhu Yanjun
When some errors occur, the scatter/gather list mapped to DMA addresses
should be handled.

Cc: Joe Jin <joe@oracle.com>
Cc: Junxiao Bi <junxiao...@oracle.com>
Acked-by: Santosh Shilimkar <santosh.shilim...@oracle.com>
Signed-off-by: Zhu Yanjun <yanjun@oracle.com>
---
Change from v1 to v2:
  Add the acker.

 net/rds/ib_fmr.c | 26 +++---
 1 file changed, 19 insertions(+), 7 deletions(-)

diff --git a/net/rds/ib_fmr.c b/net/rds/ib_fmr.c
index c936b0d..86ef907 100644
--- a/net/rds/ib_fmr.c
+++ b/net/rds/ib_fmr.c
@@ -112,29 +112,39 @@ static int rds_ib_map_fmr(struct rds_ib_device *rds_ibdev,
u64 dma_addr = ib_sg_dma_address(dev, [i]);
 
if (dma_addr & ~PAGE_MASK) {
-   if (i > 0)
+   if (i > 0) {
+   ib_dma_unmap_sg(dev, sg, nents,
+   DMA_BIDIRECTIONAL);
return -EINVAL;
-   else
+   } else {
++page_cnt;
+   }
}
if ((dma_addr + dma_len) & ~PAGE_MASK) {
-   if (i < sg_dma_len - 1)
+   if (i < sg_dma_len - 1) {
+   ib_dma_unmap_sg(dev, sg, nents,
+   DMA_BIDIRECTIONAL);
return -EINVAL;
-   else
+   } else {
++page_cnt;
+   }
}
 
len += dma_len;
}
 
page_cnt += len >> PAGE_SHIFT;
-   if (page_cnt > ibmr->pool->fmr_attr.max_pages)
+   if (page_cnt > ibmr->pool->fmr_attr.max_pages) {
+   ib_dma_unmap_sg(dev, sg, nents, DMA_BIDIRECTIONAL);
return -EINVAL;
+   }
 
dma_pages = kmalloc_node(sizeof(u64) * page_cnt, GFP_ATOMIC,
 rdsibdev_to_node(rds_ibdev));
-   if (!dma_pages)
+   if (!dma_pages) {
+   ib_dma_unmap_sg(dev, sg, nents, DMA_BIDIRECTIONAL);
return -ENOMEM;
+   }
 
page_cnt = 0;
for (i = 0; i < sg_dma_len; ++i) {
@@ -147,8 +157,10 @@ static int rds_ib_map_fmr(struct rds_ib_device *rds_ibdev,
}
 
ret = ib_map_phys_fmr(fmr->fmr, dma_pages, page_cnt, io_addr);
-   if (ret)
+   if (ret) {
+   ib_dma_unmap_sg(dev, sg, nents, DMA_BIDIRECTIONAL);
goto out;
+   }
 
/* Success - we successfully remapped the MR, so we can
 * safely tear down the old mapping.
-- 
2.7.4



[PATCHv2 3/5] rds: ib: remove redundant ib_dealloc_fmr

2017-03-09 Thread Zhu Yanjun
The function ib_dealloc_fmr will never be called. As such, it should
be removed.

Cc: Joe Jin <joe@oracle.com>
Cc: Junxiao Bi <junxiao...@oracle.com>
Signed-off-by: Zhu Yanjun <yanjun@oracle.com>
---
Change from v1 to v2:
  remove ibmr NULL test.

 net/rds/ib_fmr.c | 7 ++-
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/net/rds/ib_fmr.c b/net/rds/ib_fmr.c
index 4fe8f4f..249ae1c 100644
--- a/net/rds/ib_fmr.c
+++ b/net/rds/ib_fmr.c
@@ -78,12 +78,9 @@ struct rds_ib_mr *rds_ib_alloc_fmr(struct rds_ib_device 
*rds_ibdev, int npages)
return ibmr;
 
 out_no_cigar:
-   if (ibmr) {
-   if (fmr->fmr)
-   ib_dealloc_fmr(fmr->fmr);
-   kfree(ibmr);
-   }
+   kfree(ibmr);
atomic_dec(>item_count);
+
return ERR_PTR(err);
 }
 
-- 
2.7.4



[PATCH 2/5] rds: ib: replace spin_lock_irq with spin_lock_irqsave

2017-03-08 Thread Zhu Yanjun
It is difficult to make sure the state of the interrupt when this
function is called. As such, it is safer to use spin_lock_irqsave
than spin_lock_irq.

Cc: Joe Jin <joe@oracle.com>
Cc: Junxiao Bi <junxiao...@oracle.com>
Signed-off-by: Zhu Yanjun <yanjun@oracle.com>
---
 net/rds/ib_cm.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c
index eca3d5f..87ec4dd 100644
--- a/net/rds/ib_cm.c
+++ b/net/rds/ib_cm.c
@@ -963,6 +963,7 @@ void rds_ib_conn_free(void *arg)
 {
struct rds_ib_connection *ic = arg;
spinlock_t  *lock_ptr;
+   unsigned long   flags;
 
rdsdebug("ic %p\n", ic);
 
@@ -973,9 +974,9 @@ void rds_ib_conn_free(void *arg)
 */
lock_ptr = ic->rds_ibdev ? >rds_ibdev->spinlock : 
_nodev_conns_lock;
 
-   spin_lock_irq(lock_ptr);
+   spin_lock_irqsave(lock_ptr, flags);
list_del(>ib_node);
-   spin_unlock_irq(lock_ptr);
+   spin_unlock_irqrestore(lock_ptr, flags);
 
rds_ib_recv_free_caches(ic);
 
-- 
2.7.4



[PATCH 3/5] rds: ib: remove redundant ib_dealloc_fmr

2017-03-08 Thread Zhu Yanjun
The function ib_dealloc_fmr will never be called. As such, it should
be removed.

Cc: Joe Jin <joe@oracle.com>
Cc: Junxiao Bi <junxiao...@oracle.com>
Signed-off-by: Zhu Yanjun <yanjun@oracle.com>
---
 net/rds/ib_fmr.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/net/rds/ib_fmr.c b/net/rds/ib_fmr.c
index 4fe8f4f..b807df6 100644
--- a/net/rds/ib_fmr.c
+++ b/net/rds/ib_fmr.c
@@ -78,12 +78,10 @@ struct rds_ib_mr *rds_ib_alloc_fmr(struct rds_ib_device 
*rds_ibdev, int npages)
return ibmr;
 
 out_no_cigar:
-   if (ibmr) {
-   if (fmr->fmr)
-   ib_dealloc_fmr(fmr->fmr);
+   if (ibmr)
kfree(ibmr);
-   }
atomic_dec(>item_count);
+
return ERR_PTR(err);
 }
 
-- 
2.7.4



[PATCH 4/5] rds: ib: add the static type to the function

2017-03-08 Thread Zhu Yanjun
The function rds_ib_map_fmr is used only in the ib_fmr.c
file. As such, the static type is added to limit it in this file.

Cc: Joe Jin <joe@oracle.com>
Cc: Junxiao Bi <junxiao...@oracle.com>
Signed-off-by: Zhu Yanjun <yanjun@oracle.com>
---
 net/rds/ib_fmr.c | 5 +++--
 net/rds/ib_mr.h  | 2 --
 2 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/net/rds/ib_fmr.c b/net/rds/ib_fmr.c
index b807df6..1e00371 100644
--- a/net/rds/ib_fmr.c
+++ b/net/rds/ib_fmr.c
@@ -85,8 +85,9 @@ struct rds_ib_mr *rds_ib_alloc_fmr(struct rds_ib_device 
*rds_ibdev, int npages)
return ERR_PTR(err);
 }
 
-int rds_ib_map_fmr(struct rds_ib_device *rds_ibdev, struct rds_ib_mr *ibmr,
-  struct scatterlist *sg, unsigned int nents)
+static int rds_ib_map_fmr(struct rds_ib_device *rds_ibdev,
+ struct rds_ib_mr *ibmr, struct scatterlist *sg,
+ unsigned int nents)
 {
struct ib_device *dev = rds_ibdev->dev;
struct rds_ib_fmr *fmr = >u.fmr;
diff --git a/net/rds/ib_mr.h b/net/rds/ib_mr.h
index 5d6e98a..0ea4ab0 100644
--- a/net/rds/ib_mr.h
+++ b/net/rds/ib_mr.h
@@ -125,8 +125,6 @@ void rds_ib_mr_exit(void);
 void __rds_ib_teardown_mr(struct rds_ib_mr *);
 void rds_ib_teardown_mr(struct rds_ib_mr *);
 struct rds_ib_mr *rds_ib_alloc_fmr(struct rds_ib_device *, int);
-int rds_ib_map_fmr(struct rds_ib_device *, struct rds_ib_mr *,
-  struct scatterlist *, unsigned int);
 struct rds_ib_mr *rds_ib_reuse_mr(struct rds_ib_mr_pool *);
 int rds_ib_flush_mr_pool(struct rds_ib_mr_pool *, int, struct rds_ib_mr **);
 struct rds_ib_mr *rds_ib_reg_fmr(struct rds_ib_device *, struct scatterlist *,
-- 
2.7.4



[PATCH 1/5] rds: ib: drop unnecessary rdma_reject

2017-03-08 Thread Zhu Yanjun
When rdma_accept fails, rdma_reject is called in it. As such, it is
not necessary to execute rdma_reject again.

Cc: Joe Jin <joe@oracle.com>
Cc: Junxiao Bi <junxiao...@oracle.com>
Signed-off-by: Zhu Yanjun <yanjun@oracle.com>
---
 net/rds/ib_cm.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c
index ce3775a..eca3d5f 100644
--- a/net/rds/ib_cm.c
+++ b/net/rds/ib_cm.c
@@ -677,8 +677,7 @@ int rds_ib_cm_handle_connect(struct rdma_cm_id *cm_id,
event->param.conn.initiator_depth);
 
/* rdma_accept() calls rdma_reject() internally if it fails */
-   err = rdma_accept(cm_id, _param);
-   if (err)
+   if (rdma_accept(cm_id, _param))
rds_ib_conn_error(conn, "rdma_accept failed (%d)\n", err);
 
 out:
-- 
2.7.4



[PATCH 5/5] rds: ib: unmap the scatter/gather list when error

2017-03-08 Thread Zhu Yanjun
When some errors occur, the scatter/gather list mapped to DMA addresses
should be handled.

Cc: Joe Jin <joe@oracle.com>
Cc: Junxiao Bi <junxiao...@oracle.com>
Signed-off-by: Zhu Yanjun <yanjun@oracle.com>
---
 net/rds/ib_fmr.c | 26 +++---
 1 file changed, 19 insertions(+), 7 deletions(-)

diff --git a/net/rds/ib_fmr.c b/net/rds/ib_fmr.c
index 1e00371..c60247f 100644
--- a/net/rds/ib_fmr.c
+++ b/net/rds/ib_fmr.c
@@ -113,29 +113,39 @@ static int rds_ib_map_fmr(struct rds_ib_device *rds_ibdev,
u64 dma_addr = ib_sg_dma_address(dev, [i]);
 
if (dma_addr & ~PAGE_MASK) {
-   if (i > 0)
+   if (i > 0) {
+   ib_dma_unmap_sg(dev, sg, nents,
+   DMA_BIDIRECTIONAL);
return -EINVAL;
-   else
+   } else {
++page_cnt;
+   }
}
if ((dma_addr + dma_len) & ~PAGE_MASK) {
-   if (i < sg_dma_len - 1)
+   if (i < sg_dma_len - 1) {
+   ib_dma_unmap_sg(dev, sg, nents,
+   DMA_BIDIRECTIONAL);
return -EINVAL;
-   else
+   } else {
++page_cnt;
+   }
}
 
len += dma_len;
}
 
page_cnt += len >> PAGE_SHIFT;
-   if (page_cnt > ibmr->pool->fmr_attr.max_pages)
+   if (page_cnt > ibmr->pool->fmr_attr.max_pages) {
+   ib_dma_unmap_sg(dev, sg, nents, DMA_BIDIRECTIONAL);
return -EINVAL;
+   }
 
dma_pages = kmalloc_node(sizeof(u64) * page_cnt, GFP_ATOMIC,
 rdsibdev_to_node(rds_ibdev));
-   if (!dma_pages)
+   if (!dma_pages) {
+   ib_dma_unmap_sg(dev, sg, nents, DMA_BIDIRECTIONAL);
return -ENOMEM;
+   }
 
page_cnt = 0;
for (i = 0; i < sg_dma_len; ++i) {
@@ -148,8 +158,10 @@ static int rds_ib_map_fmr(struct rds_ib_device *rds_ibdev,
}
 
ret = ib_map_phys_fmr(fmr->fmr, dma_pages, page_cnt, io_addr);
-   if (ret)
+   if (ret) {
+   ib_dma_unmap_sg(dev, sg, nents, DMA_BIDIRECTIONAL);
goto out;
+   }
 
/* Success - we successfully remapped the MR, so we can
 * safely tear down the old mapping.
-- 
2.7.4



[PATCH 1/1] rds: ib: add error handle

2017-03-06 Thread Zhu Yanjun
In the function rds_ib_setup_qp, the error handle is missing. When some
error occurs, it is possible that memory leak occurs. As such, error
handle is added.

Cc: Joe Jin <joe@oracle.com>
Reviewed-by: Junxiao Bi <junxiao...@oracle.com>
Reviewed-by: Guanglei Li <guanglei...@oracle.com>
Signed-off-by: Zhu Yanjun <yanjun@oracle.com>
---
 net/rds/ib_cm.c | 47 ---
 1 file changed, 36 insertions(+), 11 deletions(-)

diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c
index ce3775a..d47ae0f 100644
--- a/net/rds/ib_cm.c
+++ b/net/rds/ib_cm.c
@@ -442,7 +442,7 @@ static int rds_ib_setup_qp(struct rds_connection *conn)
ic->i_send_cq = NULL;
ibdev_put_vector(rds_ibdev, ic->i_scq_vector);
rdsdebug("ib_create_cq send failed: %d\n", ret);
-   goto out;
+   goto rds_ibdev_out;
}
 
ic->i_rcq_vector = ibdev_get_unused_vector(rds_ibdev);
@@ -456,19 +456,19 @@ static int rds_ib_setup_qp(struct rds_connection *conn)
ic->i_recv_cq = NULL;
ibdev_put_vector(rds_ibdev, ic->i_rcq_vector);
rdsdebug("ib_create_cq recv failed: %d\n", ret);
-   goto out;
+   goto send_cq_out;
}
 
ret = ib_req_notify_cq(ic->i_send_cq, IB_CQ_NEXT_COMP);
if (ret) {
rdsdebug("ib_req_notify_cq send failed: %d\n", ret);
-   goto out;
+   goto recv_cq_out;
}
 
ret = ib_req_notify_cq(ic->i_recv_cq, IB_CQ_SOLICITED);
if (ret) {
rdsdebug("ib_req_notify_cq recv failed: %d\n", ret);
-   goto out;
+   goto recv_cq_out;
}
 
/* XXX negotiate max send/recv with remote? */
@@ -494,7 +494,7 @@ static int rds_ib_setup_qp(struct rds_connection *conn)
ret = rdma_create_qp(ic->i_cm_id, ic->i_pd, );
if (ret) {
rdsdebug("rdma_create_qp failed: %d\n", ret);
-   goto out;
+   goto recv_cq_out;
}
 
ic->i_send_hdrs = ib_dma_alloc_coherent(dev,
@@ -504,7 +504,7 @@ static int rds_ib_setup_qp(struct rds_connection *conn)
if (!ic->i_send_hdrs) {
ret = -ENOMEM;
rdsdebug("ib_dma_alloc_coherent send failed\n");
-   goto out;
+   goto qp_out;
}
 
ic->i_recv_hdrs = ib_dma_alloc_coherent(dev,
@@ -514,7 +514,7 @@ static int rds_ib_setup_qp(struct rds_connection *conn)
if (!ic->i_recv_hdrs) {
ret = -ENOMEM;
rdsdebug("ib_dma_alloc_coherent recv failed\n");
-   goto out;
+   goto send_hdrs_dma_out;
}
 
ic->i_ack = ib_dma_alloc_coherent(dev, sizeof(struct rds_header),
@@ -522,7 +522,7 @@ static int rds_ib_setup_qp(struct rds_connection *conn)
if (!ic->i_ack) {
ret = -ENOMEM;
rdsdebug("ib_dma_alloc_coherent ack failed\n");
-   goto out;
+   goto recv_hdrs_dma_out;
}
 
ic->i_sends = vzalloc_node(ic->i_send_ring.w_nr * sizeof(struct 
rds_ib_send_work),
@@ -530,7 +530,7 @@ static int rds_ib_setup_qp(struct rds_connection *conn)
if (!ic->i_sends) {
ret = -ENOMEM;
rdsdebug("send allocation failed\n");
-   goto out;
+   goto ack_dma_out;
}
 
ic->i_recvs = vzalloc_node(ic->i_recv_ring.w_nr * sizeof(struct 
rds_ib_recv_work),
@@ -538,7 +538,7 @@ static int rds_ib_setup_qp(struct rds_connection *conn)
if (!ic->i_recvs) {
ret = -ENOMEM;
rdsdebug("recv allocation failed\n");
-   goto out;
+   goto sends_out;
}
 
rds_ib_recv_init_ack(ic);
@@ -546,8 +546,33 @@ static int rds_ib_setup_qp(struct rds_connection *conn)
rdsdebug("conn %p pd %p cq %p %p\n", conn, ic->i_pd,
 ic->i_send_cq, ic->i_recv_cq);
 
-out:
+   return ret;
+
+sends_out:
+   vfree(ic->i_sends);
+ack_dma_out:
+   ib_dma_free_coherent(dev, sizeof(struct rds_header),
+ic->i_ack, ic->i_ack_dma);
+recv_hdrs_dma_out:
+   ib_dma_free_coherent(dev, ic->i_recv_ring.w_nr *
+   sizeof(struct rds_header),
+   ic->i_recv_hdrs, ic->i_recv_hdrs_dma);
+send_hdrs_dma_out:
+   ib_dma_free_coherent(dev, ic->i_send_ring.w_nr *
+   sizeof(struct rds_header),
+   ic->i_send_hdrs, ic->i_send_hdrs_dma);
+qp_out:
+   rdma_destroy_qp(ic->i_cm_id);
+recv_cq_out:
+   if (!ib_destroy_cq(ic->i_recv_cq))
+ 

[PATCH 1/1] rds: remove unnecessary returned value check

2017-03-02 Thread Zhu Yanjun
The function rds_trans_register always returns 0. As such, it is not
necessary to check the returned value.

Cc: Joe Jin <joe@oracle.com>
Cc: Junxiao Bi <junxiao...@oracle.com>
Signed-off-by: Zhu Yanjun <yanjun@oracle.com>
---
 net/rds/ib.c| 6 +-
 net/rds/rds.h   | 2 +-
 net/rds/tcp.c   | 6 +-
 net/rds/transport.c | 4 +---
 4 files changed, 4 insertions(+), 14 deletions(-)

diff --git a/net/rds/ib.c b/net/rds/ib.c
index 0f557b2..7a64c8d 100644
--- a/net/rds/ib.c
+++ b/net/rds/ib.c
@@ -438,16 +438,12 @@ int rds_ib_init(void)
if (ret)
goto out_sysctl;
 
-   ret = rds_trans_register(_ib_transport);
-   if (ret)
-   goto out_recv;
+   rds_trans_register(_ib_transport);
 
rds_info_register_func(RDS_INFO_IB_CONNECTIONS, rds_ib_ic_info);
 
goto out;
 
-out_recv:
-   rds_ib_recv_exit();
 out_sysctl:
rds_ib_sysctl_exit();
 out_ibreg:
diff --git a/net/rds/rds.h b/net/rds/rds.h
index 966d2ee..39518ef 100644
--- a/net/rds/rds.h
+++ b/net/rds/rds.h
@@ -903,7 +903,7 @@ void rds_connect_path_complete(struct rds_conn_path *conn, 
int curr);
 void rds_connect_complete(struct rds_connection *conn);
 
 /* transport.c */
-int rds_trans_register(struct rds_transport *trans);
+void rds_trans_register(struct rds_transport *trans);
 void rds_trans_unregister(struct rds_transport *trans);
 struct rds_transport *rds_trans_get_preferred(struct net *net, __be32 addr);
 void rds_trans_put(struct rds_transport *trans);
diff --git a/net/rds/tcp.c b/net/rds/tcp.c
index 5438f67..a973d3b 100644
--- a/net/rds/tcp.c
+++ b/net/rds/tcp.c
@@ -652,16 +652,12 @@ static int rds_tcp_init(void)
if (ret)
goto out_pernet;
 
-   ret = rds_trans_register(_tcp_transport);
-   if (ret)
-   goto out_recv;
+   rds_trans_register(_tcp_transport);
 
rds_info_register_func(RDS_INFO_TCP_SOCKETS, rds_tcp_tc_info);
 
goto out;
 
-out_recv:
-   rds_tcp_recv_exit();
 out_pernet:
unregister_pernet_subsys(_tcp_net_ops);
 out_notifier:
diff --git a/net/rds/transport.c b/net/rds/transport.c
index 2ffd3e3..0b188dd 100644
--- a/net/rds/transport.c
+++ b/net/rds/transport.c
@@ -40,7 +40,7 @@
 static struct rds_transport *transports[RDS_TRANS_COUNT];
 static DECLARE_RWSEM(rds_trans_sem);
 
-int rds_trans_register(struct rds_transport *trans)
+void rds_trans_register(struct rds_transport *trans)
 {
BUG_ON(strlen(trans->t_name) + 1 > TRANSNAMSIZ);
 
@@ -55,8 +55,6 @@ int rds_trans_register(struct rds_transport *trans)
}
 
up_write(_trans_sem);
-
-   return 0;
 }
 EXPORT_SYMBOL_GPL(rds_trans_register);
 
-- 
2.7.4



[PATCH 1/1] rds: ib: add the static type to the variables

2017-02-28 Thread Zhu Yanjun
The variables rds_ib_mr_1m_pool_size and rds_ib_mr_8k_pool_size
are used only in the ib.c file. As such, the static type is
added to limit them in this file.

Cc: Joe Jin <joe@oracle.com>
Cc: Junxiao Bi <junxiao...@oracle.com>
Signed-off-by: Zhu Yanjun <yanjun@oracle.com>
---
 net/rds/ib.c| 4 ++--
 net/rds/ib_mr.h | 2 --
 2 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/net/rds/ib.c b/net/rds/ib.c
index 8d70884..ecff01b 100644
--- a/net/rds/ib.c
+++ b/net/rds/ib.c
@@ -45,8 +45,8 @@
 #include "ib.h"
 #include "ib_mr.h"
 
-unsigned int rds_ib_mr_1m_pool_size = RDS_MR_1M_POOL_SIZE;
-unsigned int rds_ib_mr_8k_pool_size = RDS_MR_8K_POOL_SIZE;
+static unsigned int rds_ib_mr_1m_pool_size = RDS_MR_1M_POOL_SIZE;
+static unsigned int rds_ib_mr_8k_pool_size = RDS_MR_8K_POOL_SIZE;
 unsigned int rds_ib_retry_count = RDS_IB_DEFAULT_RETRY_COUNT;
 
 module_param(rds_ib_mr_1m_pool_size, int, 0444);
diff --git a/net/rds/ib_mr.h b/net/rds/ib_mr.h
index 24c086d..5d6e98a 100644
--- a/net/rds/ib_mr.h
+++ b/net/rds/ib_mr.h
@@ -107,8 +107,6 @@ struct rds_ib_mr_pool {
 };
 
 extern struct workqueue_struct *rds_ib_mr_wq;
-extern unsigned int rds_ib_mr_1m_pool_size;
-extern unsigned int rds_ib_mr_8k_pool_size;
 extern bool prefer_frmr;
 
 struct rds_ib_mr_pool *rds_ib_create_mr_pool(struct rds_ib_device *rds_dev,
-- 
2.7.4



[PATCH 1/1] rds: fix memory leak error

2017-02-24 Thread Zhu Yanjun
When the function register_netdevice_notifier fails, the memory
allocated by kmem_cache_create should be freed by the function
kmem_cache_destroy.

Cc: Joe Jin <joe@oracle.com>
Cc: Junxiao Bi <junxiao...@oracle.com>
Signed-off-by: Zhu Yanjun <yanjun@oracle.com>
---
 net/rds/tcp.c | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/net/rds/tcp.c b/net/rds/tcp.c
index 57bb523..5438f67 100644
--- a/net/rds/tcp.c
+++ b/net/rds/tcp.c
@@ -641,12 +641,12 @@ static int rds_tcp_init(void)
ret = register_netdevice_notifier(_tcp_dev_notifier);
if (ret) {
pr_warn("could not register rds_tcp_dev_notifier\n");
-   goto out;
+   goto out_slab;
}
 
ret = register_pernet_subsys(_tcp_net_ops);
if (ret)
-   goto out_slab;
+   goto out_notifier;
 
ret = rds_tcp_recv_init();
if (ret)
@@ -664,9 +664,10 @@ static int rds_tcp_init(void)
rds_tcp_recv_exit();
 out_pernet:
unregister_pernet_subsys(_tcp_net_ops);
-out_slab:
+out_notifier:
if (unregister_netdevice_notifier(_tcp_dev_notifier))
pr_warn("could not unregister rds_tcp_dev_notifier\n");
+out_slab:
kmem_cache_destroy(rds_tcp_conn_slab);
 out:
return ret;
-- 
2.7.4



[PATCH 1/1] forcedeth: Remove return from a void function

2017-02-23 Thread Zhu Yanjun
In a void function, it is not necessary to append a return statement in it.

Signed-off-by: Zhu Yanjun <yanjun@oracle.com>
---
 drivers/net/ethernet/nvidia/forcedeth.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/net/ethernet/nvidia/forcedeth.c 
b/drivers/net/ethernet/nvidia/forcedeth.c
index 3913f07..a992595 100644
--- a/drivers/net/ethernet/nvidia/forcedeth.c
+++ b/drivers/net/ethernet/nvidia/forcedeth.c
@@ -3274,8 +3274,6 @@ static void nv_force_linkspeed(struct net_device *dev, 
int speed, int duplex)
pci_push(base);
writel(np->linkspeed, base + NvRegLinkSpeed);
pci_push(base);
-
-   return;
 }
 
 /**
-- 
2.7.4



[PATCHv2 1/1] rds:Remove unnecessary ib_ring unalloc

2017-02-17 Thread Zhu Yanjun
In the function rds_ib_xmit_atomic, ib_ring is not allocated
successfully. As such, it is not necessary to unalloc it.

Cc: Joe Jin <joe@oracle.com>
Cc: Junxiao Bi <junxiao...@oracle.com>
Signed-off-by: Zhu Yanjun <yanjun@oracle.com>
---
Change from v1 to v2:
  fix the word errors in the short log.

 net/rds/ib_send.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/net/rds/ib_send.c b/net/rds/ib_send.c
index 84d90c9..84b34cc 100644
--- a/net/rds/ib_send.c
+++ b/net/rds/ib_send.c
@@ -765,7 +765,6 @@ int rds_ib_xmit_atomic(struct rds_connection *conn, struct 
rm_atomic_op *op)
 
work_alloc = rds_ib_ring_alloc(>i_send_ring, 1, );
if (work_alloc != 1) {
-   rds_ib_ring_unalloc(>i_send_ring, work_alloc);
rds_ib_stats_inc(s_ib_tx_ring_full);
ret = -ENOMEM;
goto out;
-- 
2.7.4



[PATCH 1/1] rds:Remove unnecessary ib_ring unalloc

2017-02-17 Thread Zhu Yanjun
In the function rds_ib_xmit_atomic, ib_ring is not successfully.
As such, it is not necessary to unalloc it.

Cc: Joe Jin <joe@oracle.com>
Cc: Junxiao Bi <junxiao...@oracle.com>
Signed-off-by: Zhu Yanjun <yanjun@oracle.com>
---
 net/rds/ib_send.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/net/rds/ib_send.c b/net/rds/ib_send.c
index 84d90c9..84b34cc 100644
--- a/net/rds/ib_send.c
+++ b/net/rds/ib_send.c
@@ -765,7 +765,6 @@ int rds_ib_xmit_atomic(struct rds_connection *conn, struct 
rm_atomic_op *op)
 
work_alloc = rds_ib_ring_alloc(>i_send_ring, 1, );
if (work_alloc != 1) {
-   rds_ib_ring_unalloc(>i_send_ring, work_alloc);
rds_ib_stats_inc(s_ib_tx_ring_full);
ret = -ENOMEM;
goto out;
-- 
2.7.4



[PATCH 1/1] ixgbe: add the external ixgbe fiber transceiver status

2017-02-08 Thread Zhu Yanjun
When the ixgbe fiber transceiver is external, it is necessary to get
the present/absent status of this external ixgbe fiber transceiver.

The steps to get the present/absent status:
The enp1s0f0 is an external ixgbe fiber NIC.

ethtool enp1s0f0

...
Port: FIBRE
PHYAD: 0
Transceiver: external(present) <---The transceiver is present.
Auto-negotiation: on
Supports Wake-on: d
...

Or
...
Port: FIBRE
PHYAD: 0
Transceiver: external(absent) <---The transceiver is absent
Auto-negotiation: on
Supports Wake-on: d
...

Signed-off-by: Zhu Yanjun <yanjun@oracle.com>
---
 drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c | 15 +++
 include/uapi/linux/ethtool.h |  4 
 2 files changed, 19 insertions(+)

diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c 
b/drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c
index fd192bf..b3f86f4 100644
--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c
+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c
@@ -313,6 +313,21 @@ static int ixgbe_get_settings(struct net_device *netdev,
break;
}
 
+   /* When the tranceiver is external, the following is meaningful.
+* ecmd->reserved[0] has 3 values:
+* 0x0: tranceiver absent
+* 0x4: tranceiver present
+* others: not support
+*/
+   if (ecmd->port == PORT_FIBRE) {
+   u32 status = IXGBE_READ_REG(hw, IXGBE_ESDP) & IXGBE_ESDP_SDP2;
+
+   if (status == 0x4)
+   ecmd->transceiver = XCVR_EXTERNAL_PRESENT;
+   if (status == 0x0)
+   ecmd->transceiver = XCVR_EXTERNAL_ABSENT;
+   }
+
/* Indicate pause support */
ecmd->supported |= SUPPORTED_Pause;
 
diff --git a/include/uapi/linux/ethtool.h b/include/uapi/linux/ethtool.h
index 3dc91a4..8e8225a 100644
--- a/include/uapi/linux/ethtool.h
+++ b/include/uapi/linux/ethtool.h
@@ -1541,6 +1541,10 @@ static inline int ethtool_validate_duplex(__u8 duplex)
 #define XCVR_DUMMY20x03
 #define XCVR_DUMMY30x04
 
+/* The fiber transceiver status */
+#define XCVR_EXTERNAL_ABSENT   0x05
+#define XCVR_EXTERNAL_PRESENT  0x06
+
 /* Enable or disable autonegotiation. */
 #define AUTONEG_DISABLE0x00
 #define AUTONEG_ENABLE 0x01
-- 
2.7.4



[PATCH 1/1] ethtool: add the external transceiver status of the ixgbe fiber

2017-02-08 Thread Zhu Yanjun
When the the fiber transceiver of the ixgbe NIC is external, sometimes
it is necessary to get the present/absent status of the fiber transceiver
of the ixgbe NIC.

The steps to get the present/absent status:
The NIC enp1s0f0 is an external ixgbe fiber NIC.

ethtool enp1s0f0

...
Port: FIBRE
PHYAD: 0
Transceiver: external(present) <---The transceiver is present.
Auto-negotiation: on
Supports Wake-on: d
...

Or
...
Port: FIBRE
PHYAD: 0
Transceiver: external(absent) <---The transceiver is absent
Auto-negotiation: on
Supports Wake-on: d
...
Signed-off-by: Zhu Yanjun <yanjun@oracle.com>
---
 ethtool-copy.h | 2 ++
 ethtool.c  | 6 ++
 2 files changed, 8 insertions(+)

diff --git a/ethtool-copy.h b/ethtool-copy.h
index 3d299e3..1c6db9a 100644
--- a/ethtool-copy.h
+++ b/ethtool-copy.h
@@ -1536,6 +1536,8 @@ static __inline__ int ethtool_validate_duplex(__u8 duplex)
 #define XCVR_DUMMY10x02
 #define XCVR_DUMMY20x03
 #define XCVR_DUMMY30x04
+#define XCVR_EXTERNAL_ABSENT   0x05
+#define XCVR_EXTERNAL_PRESENT  0x06
 
 /* Enable or disable autonegotiation. */
 #define AUTONEG_DISABLE0x00
diff --git a/ethtool.c b/ethtool.c
index 7af039e..85cf5a2 100644
--- a/ethtool.c
+++ b/ethtool.c
@@ -811,6 +811,12 @@ dump_link_usettings(const struct ethtool_link_usettings 
*link_usettings)
case XCVR_EXTERNAL:
fprintf(stdout, "external\n");
break;
+   case XCVR_EXTERNAL_PRESENT:
+   fprintf(stdout, "external(present)\n");
+   break;
+   case XCVR_EXTERNAL_ABSENT:
+   fprintf(stdout, "external(absent)\n");
+   break;
default:
fprintf(stdout, "Unknown!\n");
break;
-- 
2.7.4



[PATCH 1/1] bonding: Remove unnecessary returned value check

2017-02-02 Thread Zhu Yanjun
The function bond_info_query alwarys returns 0. As such, in the function
bond_do_ioctl, it is not necessary to check the returned value. So the
interface type of the function bond_info_query is changed to void. The
redundant check is removed.

Signed-off-by: Zhu Yanjun <yanjun@oracle.com>
---
 drivers/net/bonding/bond_main.c | 10 --
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index 8029dd4..6732225 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -1993,11 +1993,10 @@ static int  bond_release_and_destroy(struct net_device 
*bond_dev,
return ret;
 }
 
-static int bond_info_query(struct net_device *bond_dev, struct ifbond *info)
+static void bond_info_query(struct net_device *bond_dev, struct ifbond *info)
 {
struct bonding *bond = netdev_priv(bond_dev);
bond_fill_ifbond(bond, info);
-   return 0;
 }
 
 static int bond_slave_info_query(struct net_device *bond_dev, struct ifslave 
*info)
@@ -3411,12 +3410,11 @@ static int bond_do_ioctl(struct net_device *bond_dev, 
struct ifreq *ifr, int cmd
if (copy_from_user(_binfo, u_binfo, sizeof(ifbond)))
return -EFAULT;
 
-   res = bond_info_query(bond_dev, _binfo);
-   if (res == 0 &&
-   copy_to_user(u_binfo, _binfo, sizeof(ifbond)))
+   bond_info_query(bond_dev, _binfo);
+   if (copy_to_user(u_binfo, _binfo, sizeof(ifbond)))
return -EFAULT;
 
-   return res;
+   return 0;
case BOND_SLAVE_INFO_QUERY_OLD:
case SIOCBONDSLAVEINFOQUERY:
u_sinfo = (struct ifslave __user *)ifr->ifr_data;
-- 
2.7.4



[PATCHv2 1/1] r8169: fix the typo in the comment

2017-01-05 Thread Zhu Yanjun
>From the realtek data sheet, the PID0 should be bit 0.

Signed-off-by: Zhu Yanjun <yanjun@oracle.com>
---
Change from v1 to v2:
 change the commit header. 

 drivers/net/ethernet/realtek/r8169.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/realtek/r8169.c 
b/drivers/net/ethernet/realtek/r8169.c
index 44389c9..8f1623b 100644
--- a/drivers/net/ethernet/realtek/r8169.c
+++ b/drivers/net/ethernet/realtek/r8169.c
@@ -696,7 +696,7 @@ enum rtl_tx_desc_bit_1 {
 enum rtl_rx_desc_bit {
/* Rx private */
PID1= (1 << 18), /* Protocol ID bit 1/2 */
-   PID0= (1 << 17), /* Protocol ID bit 2/2 */
+   PID0= (1 << 17), /* Protocol ID bit 0/2 */
 
 #define RxProtoUDP (PID1)
 #define RxProtoTCP (PID0)
-- 
2.7.4



[PATCH 1/1] ixgbevf: replace integer number with bool value

2016-07-28 Thread Zhu Yanjun
The variable get_mac_status is a bool variable. So a bool value is
better than an integer number.

Signed-off-by: Zhu Yanjun <zyjzyj2...@gmail.com>
---
 drivers/net/ethernet/intel/ixgbevf/ethtool.c  | 2 +-
 drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/intel/ixgbevf/ethtool.c 
b/drivers/net/ethernet/intel/ixgbevf/ethtool.c
index 508e72c..ce221d1 100644
--- a/drivers/net/ethernet/intel/ixgbevf/ethtool.c
+++ b/drivers/net/ethernet/intel/ixgbevf/ethtool.c
@@ -104,7 +104,7 @@ static int ixgbevf_get_settings(struct net_device *netdev,
ecmd->transceiver = XCVR_DUMMY1;
ecmd->port = -1;
 
-   hw->mac.get_link_status = 1;
+   hw->mac.get_link_status = true;
hw->mac.ops.check_link(hw, _speed, _up, false);
 
if (link_up) {
diff --git a/drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c 
b/drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c
index acc2401..a98e7c2 100644
--- a/drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c
+++ b/drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c
@@ -1285,7 +1285,7 @@ static irqreturn_t ixgbevf_msix_other(int irq, void *data)
struct ixgbevf_adapter *adapter = data;
struct ixgbe_hw *hw = >hw;
 
-   hw->mac.get_link_status = 1;
+   hw->mac.get_link_status = true;
 
ixgbevf_service_event_schedule(adapter);
 
@@ -2109,7 +2109,7 @@ static void ixgbevf_up_complete(struct ixgbevf_adapter 
*adapter)
ixgbevf_save_reset_stats(adapter);
ixgbevf_init_last_counter_stats(adapter);
 
-   hw->mac.get_link_status = 1;
+   hw->mac.get_link_status = true;
mod_timer(>service_timer, jiffies);
 }
 
-- 
2.7.4



[PATCH 1/1] bonding: restrict the data protected by rcu_read_lock

2016-07-12 Thread Zhu Yanjun
In this function, origin is a pointer to struct aggregator.
No matter what agg is changed to, it has nothing to do with origin.

CC: Jay Vosburgh <jay.vosbu...@canonical.com>
Signed-off-by: Zhu Yanjun <zyjzyj2...@gmail.com>
---
 drivers/net/bonding/bond_3ad.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/bonding/bond_3ad.c b/drivers/net/bonding/bond_3ad.c
index edc70ff..20afee3 100644
--- a/drivers/net/bonding/bond_3ad.c
+++ b/drivers/net/bonding/bond_3ad.c
@@ -1624,8 +1624,8 @@ static void ad_agg_selection_logic(struct aggregator *agg,
struct slave *slave;
struct port *port;
 
-   rcu_read_lock();
origin = agg;
+   rcu_read_lock();
active = __get_active_agg(agg);
best = (active && agg_device_up(active)) ? active : NULL;
 
-- 
1.7.9.5



[RFC PATCH 1/1] net namespace: dynamically configure new net namespace inherit net config

2016-03-09 Thread Zhu Yanjun
Sometimes the system engineer and application expect a new net namespace
to inherit config from the base net config. Sometimes the current net config
is expected by the system engineer and application. So it is necessary that
the system engineer and application can choose a new net namespace to inherit
from the base net config, or the current net config.

For example, the value of /proc/sys/net/ipv4/ip_forward is taken as
an example. The value of /proc/sys/net/ipv4/ip_forward in the base net
config is 0 while the value of /proc/sys/net/ipv4/ip_forward is changed
to 1 in the current net config. The system engineer and application can choose
a new net namespace to inherit the value of /proc/sys/net/ipv4/ip_forward from
the base or the current settings.

Test case:

1. % cat /proc/sys/net/ipv4/net_ns_inherit
   1

2. Set ip forwarding in the "base namespace"

   % echo 1 > /proc/sys/net/ipv4/ip_forward

   % cat /proc/sys/net/ipv4/ip_forward
   1

3. Create a new namespace

   % ip netns add mynewns

4. Check ip forwarding in the new namespace

   % ip netns exec mynewns cat /proc/sys/net/ipv4/ip_forward
   1

5. % echo 0 > /proc/sys/net/ipv4/net_ns_inherit

   % cat /proc/sys/net/ipv4/net_ns_inherit
   0

6. Set ip forwarding in the "base namespace"

   % echo 1 > /proc/sys/net/ipv4/ip_forward

   % cat /proc/sys/net/ipv4/ip_forward
   1

7. Create a new namespace

   % ip netns add mynewns_new

8. Check ip forwarding in the new namespace

   % ip netns exec mynewns_new cat /proc/sys/net/ipv4/ip_forward
   0

Suggested-by: Bruce Ashfield <bruce.ashfi...@windriver.com>
Signed-off-by: Zhu Yanjun <yanjun@windriver.com>
CC: David S. Miller  <da...@davemloft.net>
CC: Alexey Kuznetsov <kuz...@ms2.inr.ac.ru>
CC: James Morris <jmor...@namei.org>
CC: Hideaki YOSHIFUJI <yoshf...@linux-ipv6.org>
CC: Patrick McHardy <ka...@trash.net>

---
 include/linux/inetdevice.h  |2 +-
 include/net/ip.h|3 +++
 include/uapi/linux/sysctl.h |1 +
 net/ipv4/devinet.c  |   58 ---
 net/ipv4/sysctl_net_ipv4.c  |7 ++
 5 files changed, 61 insertions(+), 10 deletions(-)

diff --git a/include/linux/inetdevice.h b/include/linux/inetdevice.h
index ee971f3..1c0ae93 100644
--- a/include/linux/inetdevice.h
+++ b/include/linux/inetdevice.h
@@ -164,7 +164,7 @@ static inline struct net_device *ip_dev_find(struct net 
*net, __be32 addr)
 
 int inet_addr_onlink(struct in_device *in_dev, __be32 a, __be32 b);
 int devinet_ioctl(struct net *net, unsigned int cmd, void __user *);
-void devinet_init(void);
+int devinet_init(void);
 struct in_device *inetdev_by_index(struct net *, int);
 __be32 inet_select_addr(const struct net_device *dev, __be32 dst, int scope);
 __be32 inet_confirm_addr(struct net *net, struct in_device *in_dev, __be32 dst,
diff --git a/include/net/ip.h b/include/net/ip.h
index 1a98f1c..0ad4a7d 100644
--- a/include/net/ip.h
+++ b/include/net/ip.h
@@ -245,6 +245,9 @@ extern int inet_peer_threshold;
 extern int inet_peer_minttl;
 extern int inet_peer_maxttl;
 
+/* From devinet.c */
+extern int net_ns_inherit;
+
 /* From ip_input.c */
 extern int sysctl_ip_early_demux;
 
diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
index 0956373..350c3ce 100644
--- a/include/uapi/linux/sysctl.h
+++ b/include/uapi/linux/sysctl.h
@@ -426,6 +426,7 @@ enum
NET_TCP_ALLOWED_CONG_CONTROL=123,
NET_TCP_MAX_SSTHRESH=124,
NET_TCP_FRTO_RESPONSE=125,
+   NET_IPV4_NET_NS_INHERIT = 126,
 };
 
 enum {
diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
index cebd9d3..b68d7fa 100644
--- a/net/ipv4/devinet.c
+++ b/net/ipv4/devinet.c
@@ -2277,28 +2277,31 @@ static struct ctl_table ctl_forward_entry[] = {
 };
 #endif
 
+#define NET_NS_INIT_DEFAULT0
+#define NET_NS_INIT_MODIFIED   1
+
+/* net ns initialized from current */
+int net_ns_inherit __read_mostly = NET_NS_INIT_MODIFIED;
+static struct ipv4_devconf *all_backup, *dflt_backup;
+
 static __net_init int devinet_init_net(struct net *net)
 {
int err;
-   struct ipv4_devconf *all, *dflt;
+   struct ipv4_devconf *all = NULL, *dflt = NULL;
 #ifdef CONFIG_SYSCTL
struct ctl_table *tbl = ctl_forward_entry;
struct ctl_table_header *forw_hdr;
 #endif
-
err = -ENOMEM;
-   all = _devconf;
-   dflt = _devconf_dflt;
 
-   if (!net_eq(net, _net)) {
-   all = kmemdup(all, sizeof(ipv4_devconf), GFP_KERNEL);
+   if (net_ns_inherit == NET_NS_INIT_DEFAULT) {
+   all = kmemdup(all_backup, sizeof(ipv4_devconf), GFP_KERNEL);
if (!all)
goto err_alloc_all;
 
-   dflt = kmemdup(dflt, sizeof(ipv4_devconf_dflt), GFP_KERNEL);
+   dflt = kmemdup(dflt_backup, sizeof(ipv4_devconf_dflt), 
GFP_KERNEL);
if (!dflt)
goto err_alloc_dflt;
-
 #ifdef CONFIG_SYSCTL
 

[PATCH 1/1] net: bonding: remove redudant brackets

2015-12-03 Thread Zhu Yanjun
It is not necessary to use two brackets. As such, the redudant brackets
are removed.

CC: Jay Vosburgh <j.vosbu...@gmail.com>
CC: Veaceslav Falico <vfal...@gmail.com>
CC: Andy Gospodarek <go...@cumulusnetworks.com>
Signed-off-by: Zhu Yanjun <yanjun@windriver.com>
---
 drivers/net/bonding/bond_main.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index 9e0f8a7..09f8a48 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -1351,7 +1351,7 @@ int bond_enslave(struct net_device *bond_dev, struct 
net_device *slave_dev)
 * the current ifenslave will set the interface down prior to
 * enslaving it; the old ifenslave will not.
 */
-   if ((slave_dev->flags & IFF_UP)) {
+   if (slave_dev->flags & IFF_UP) {
netdev_err(bond_dev, "%s is up - this may be due to an out of 
date ifenslave\n",
   slave_dev->name);
res = -EPERM;
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 1/1] net namespace: dynamically configure new net namespace inherit net config

2015-06-26 Thread Zhu Yanjun
The new net namespace can inherit from the original net config, or
the current net config. As such, a config is needed to decide where
the new namespace inherit from.

Signed-off-by: Zhu Yanjun yanjun@windriver.com
---
 init/Kconfig   |  9 +
 net/ipv4/devinet.c | 13 +
 2 files changed, 22 insertions(+)

diff --git a/init/Kconfig b/init/Kconfig
index dc24dec..fab8c41 100644
--- a/init/Kconfig
+++ b/init/Kconfig
@@ -1212,6 +1212,15 @@ config NET_NS
  Allow user space to create what appear to be multiple instances
  of the network stack.
 
+config NET_NS_INHERIT_ORIGINAL
+   bool New network namespace inherits from original net config
+   depends on NET_NS
+   default n
+   help
+ Allow new network namespace inherit from original net config.
+ If no, the new network namespace inherits from the current net
+ config including the modified net config.
+
 endif # NAMESPACES
 
 config SCHED_AUTOGROUP
diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
index 419d23c..cf635e4 100644
--- a/net/ipv4/devinet.c
+++ b/net/ipv4/devinet.c
@@ -2271,6 +2271,7 @@ static __net_init int devinet_init_net(struct net *net)
 #endif
 
err = -ENOMEM;
+#ifndef CONFIG_NET_NS_INHERIT_ORIGINAL
all = ipv4_devconf;
dflt = ipv4_devconf_dflt;
 
@@ -2282,6 +2283,15 @@ static __net_init int devinet_init_net(struct net *net)
dflt = kmemdup(dflt, sizeof(ipv4_devconf_dflt), GFP_KERNEL);
if (!dflt)
goto err_alloc_dflt;
+#else
+   all = kmemdup(ipv4_devconf, sizeof(ipv4_devconf), GFP_KERNEL);
+   if (!all)
+   goto err_alloc_all;
+
+   dflt = kmemdup(ipv4_devconf_dflt, sizeof(ipv4_devconf_dflt), 
GFP_KERNEL);
+   if (!dflt)
+   goto err_alloc_dflt;
+#endif
 
 #ifdef CONFIG_SYSCTL
tbl = kmemdup(tbl, sizeof(ctl_forward_entry), GFP_KERNEL);
@@ -2292,7 +2302,10 @@ static __net_init int devinet_init_net(struct net *net)
tbl[0].extra1 = all;
tbl[0].extra2 = net;
 #endif
+
+#ifndef CONFIG_NET_NS_INHERIT_ORIGINAL
}
+#endif
 
 #ifdef CONFIG_SYSCTL
err = __devinet_sysctl_register(net, all, all);
-- 
1.9.1

--
To unsubscribe from this list: send the line unsubscribe netdev in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html