Re: [PATCH net] ipv6: no need to return rt->dst.error if it is not null entry.

2017-07-22 Thread Roopa Prabhu
On Thu, Jul 20, 2017 at 7:51 AM, Hangbin Liu  wrote:
> After commit 18c3a61c4264 ("net: ipv6: RTM_GETROUTE: return matched fib
> result when requested"). When we get a prohibit ertry, we will return
> -EACCES directly.
>
> Before:
> + ip netns exec client ip -6 route get 2003::1
> prohibit 2003::1 dev lo table unspec proto kernel src 2001::1 metric
> 4294967295 error -13
>
> After:
> + ip netns exec server ip -6 route get 2002::1
> RTNETLINK answers: Network is unreachable
>
> Since we will check the ip6_null_entry later. There is not sense
> to check the dst.error after get rt.
>
> Fixes: 18c3a61c4264 ("net: ipv6: RTM_GETROUTE: return matched fib...")
> Signed-off-by: Hangbin Liu 
> ---

Acked-by: Roopa Prabhu 


thanks.


Re: [PATCH net] ipv6: no need to return rt->dst.error if it is not null entry.

2017-07-22 Thread Roopa Prabhu
On Fri, Jul 21, 2017 at 2:53 PM, Roopa Prabhu  wrote:
> On Fri, Jul 21, 2017 at 11:42 AM, Cong Wang  wrote:
>> On Thu, Jul 20, 2017 at 8:23 AM, Hangbin Liu  wrote:
>>> 2017-07-20 23:06 GMT+08:00 Hangbin Liu :
> +++ b/net/ipv6/route.c
> @@ -3637,12 +3637,6 @@ static int inet6_rtm_getroute(struct sk_buff 
> *in_skb, struct nlmsghdr *nlh,
> dst = ip6_route_lookup(net, , 0);
>
> rt = container_of(dst, struct rt6_info, dst);
> -   if (rt->dst.error) {
> -   err = rt->dst.error;
> -   ip6_rt_put(rt);
> -   goto errout;
> -   }

 hmm... or instead of remove this check, should we check all the entry? Like
 if ((rt->dst.error && rt != net->ipv6.ip6_null_entry && rt !=
>>> ^^ mistake here
 net->ipv6.ip6_blk_hole_entry) ||
  rt == net->ipv6.ip6_null_entry )
>>>
>>> Sorry,  there should be no need to check ip6_null_entry since the
>>> error is already
>>> -ENETUNREACH. So how about
>>
>> Hmm? All of these 3 entries have error set, right??
>> So we should only check dst.error...
>
> removing the check seems ok to me. We can also make the check
> conditional to fibmatch code only
> to eliminate any change in behavior introduced by fibmatch.
>
> ie if (fibmatch && rt->dst.error).
>
> Hangbin, can you also pls check that fibmatch works ok for such routes
> with your patch applied ?.
>
> ip netns exec client ip -6 route get fibmatch 2003::1 (with latest 
> iproute2)
>
> thank you.

I tried this with your patch and this works for the fibmatch case as well.


Re: af_packet: use after free in prb_retire_rx_blk_timer_expired

2017-07-22 Thread Ding Tianhong


On 2017/7/23 3:02, Cong Wang wrote:
> Hello,
> 
> On Sat, Jul 22, 2017 at 2:55 AM, liujian (CE)  wrote:
>> I also hit this issue with trinity test:
>>
>> The call trace:
>>   [exception RIP: prb_retire_rx_blk_timer_expired+70]
>> RIP: 81633be6  RSP: 8801bec03dc0  RFLAGS: 00010246
>> RAX:   RBX: 8801b49d0948  RCX: 
>> RDX: 8801b31057a0  RSI: a56b6b6b6b6b6b6b  RDI: 8801b49d09ec
>> RBP: 8801bec03dd8   R8: 0001   R9: 83e1bf80
>> R10: 0002  R11: 0005  R12: 8801b49d09ec
>> R13: 0100  R14: 81633ba0  R15: 8801b49d0948
>> ORIG_RAX:   CS: 0010  SS: 0018
>>  #7 [8801bec03de0] call_timer_fn at 8108cb76
>>  #8 [8801bec03e18] run_timer_softirq at 8108f87c
>>  #9 [8801bec03e90] __do_softirq at 8108629f
>> #10 [8801bec03f00] call_softirq at 8166a01c
>> #11 [8801bec03f18] do_softirq at 810172ad
>> #12 [8801bec03f30] irq_exit at 81086655
>> #13 [8801bec03f48] msa_irq_exit at 810b1ab3
>> #14 [8801bec03f88] smp_apic_timer_interrupt at 8166aeae
>> #15 [8801bec03fb0] apic_timer_interrupt at 816692dd
>> ---  ---
>>
>> And from vmcore, I can see the pointer GET_CURR_PBLOCK_DESC_FROM_CORE(pkc); 
>> is a56b6b6b6b6b6b6b
>>
> 
> Does the following quick fix help?
> 
> 
> diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
> index 008bb34ee324..09ec1640e5f7 100644
> --- a/net/packet/af_packet.c
> +++ b/net/packet/af_packet.c
> @@ -4264,6 +4264,7 @@ static int packet_set_ring(struct sock *sk,
> union tpacket_req_u *req_u,
> /* Block transmit is not supported yet */
> if (!tx_ring) {
> init_prb_bdqc(po, rb, pg_vec, req_u);
> +   pg_vec = NULL;
> } else {
> struct tpacket_req3 *req3 = _u->req3;
> 

Hi, Cong:

Thanks for your quirk solution, but I still has some doubts about it,
it looks like fix the problem in the packet_setsockopt->packet_set_ring 
processing,
but when in packet_release processing, it may could not release the
real pg_vec for the TPACKET_V3 ring, and then cause the mem leak,
maybe I miss something here, nice to hear from your feedback. :)

what about fix it this way:
--- a/net/packet/af_packet.c
+++ b/net/packet/af_packet.c
@@ -4335,9 +4335,13 @@ static int packet_set_ring(struct sock *sk, union 
tpacket_req_u *req_u,
/* Because we don't support block-based V3 on tx-ring */
if (!tx_ring)
prb_shutdown_retire_blk_timer(po, rb_queue);
+
+   if (pg_vec)
+   free_pg_vec(pg_vec, order, req->tp_block_nr);
+
}

-   if (pg_vec)
+   if (pg_vec && (po->tp_version < TPACKET_V3))
free_pg_vec(pg_vec, order, req->tp_block_nr);
 out:
release_sock(sk);


Regards
Ding

> .
> 



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

2017-07-22 Thread Xin Long
This patch is to remove the typedef sctp_abort_chunk_t, and
replace with struct sctp_abort_chunk in the places where it's
using this typedef.

Signed-off-by: Xin Long 
---
 include/linux/sctp.h| 4 ++--
 net/sctp/sm_statefuns.c | 8 
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/include/linux/sctp.h b/include/linux/sctp.h
index bfda7c6..ba00716 100644
--- a/include/linux/sctp.h
+++ b/include/linux/sctp.h
@@ -408,9 +408,9 @@ struct sctp_heartbeat_chunk {
  * common header. Just the common header is all that is needed with a
  * chunk descriptor.
  */
-typedef struct sctp_abort_chunk {
+struct sctp_abort_chunk {
struct sctp_chunkhdr uh;
-} sctp_abort_chunk_t;
+};
 
 
 /* For the graceful shutdown we must carry the tag (in common header)
diff --git a/net/sctp/sm_statefuns.c b/net/sctp/sm_statefuns.c
index 7bbee08..dc0c2c4 100644
--- a/net/sctp/sm_statefuns.c
+++ b/net/sctp/sm_statefuns.c
@@ -2164,7 +2164,7 @@ sctp_disposition_t sctp_sf_shutdown_pending_abort(
 * as we do not know its true length.  So, to be safe, discard the
 * packet.
 */
-   if (!sctp_chunk_length_valid(chunk, sizeof(sctp_abort_chunk_t)))
+   if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_abort_chunk)))
return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
 
/* ADD-IP: Special case for ABORT chunks
@@ -2206,7 +2206,7 @@ sctp_disposition_t sctp_sf_shutdown_sent_abort(struct net 
*net,
 * as we do not know its true length.  So, to be safe, discard the
 * packet.
 */
-   if (!sctp_chunk_length_valid(chunk, sizeof(sctp_abort_chunk_t)))
+   if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_abort_chunk)))
return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
 
/* ADD-IP: Special case for ABORT chunks
@@ -2470,7 +2470,7 @@ sctp_disposition_t sctp_sf_do_9_1_abort(struct net *net,
 * as we do not know its true length.  So, to be safe, discard the
 * packet.
 */
-   if (!sctp_chunk_length_valid(chunk, sizeof(sctp_abort_chunk_t)))
+   if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_abort_chunk)))
return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
 
/* ADD-IP: Special case for ABORT chunks
@@ -2546,7 +2546,7 @@ sctp_disposition_t sctp_sf_cookie_wait_abort(struct net 
*net,
 * as we do not know its true length.  So, to be safe, discard the
 * packet.
 */
-   if (!sctp_chunk_length_valid(chunk, sizeof(sctp_abort_chunk_t)))
+   if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_abort_chunk)))
return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
 
/* See if we have an error cause code in the chunk.  */
-- 
2.1.0



[PATCH net-next 09/11] sctp: remove the typedef sctp_heartbeathdr_t

2017-07-22 Thread Xin Long
This patch is to remove the typedef sctp_heartbeathdr_t, and
replace with struct sctp_heartbeathdr in the places where it's
using this typedef.

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

diff --git a/include/linux/sctp.h b/include/linux/sctp.h
index 48f6560..6e26b86 100644
--- a/include/linux/sctp.h
+++ b/include/linux/sctp.h
@@ -394,13 +394,13 @@ struct sctp_sack_chunk {
  *  the present association.
  */
 
-typedef struct sctp_heartbeathdr {
+struct sctp_heartbeathdr {
struct sctp_paramhdr info;
-} sctp_heartbeathdr_t;
+};
 
 typedef struct sctp_heartbeat_chunk {
struct sctp_chunkhdr chunk_hdr;
-   sctp_heartbeathdr_t hb_hdr;
+   struct sctp_heartbeathdr hb_hdr;
 } sctp_heartbeat_chunk_t;
 
 
diff --git a/net/sctp/sm_statefuns.c b/net/sctp/sm_statefuns.c
index 08ebe8c..32ac90b 100644
--- a/net/sctp/sm_statefuns.c
+++ b/net/sctp/sm_statefuns.c
@@ -1096,7 +1096,7 @@ sctp_disposition_t sctp_sf_beat_8_3(struct net *net,
 * respond with a HEARTBEAT ACK that contains the Heartbeat
 * Information field copied from the received HEARTBEAT chunk.
 */
-   chunk->subh.hb_hdr = (sctp_heartbeathdr_t *)chunk->skb->data;
+   chunk->subh.hb_hdr = (struct sctp_heartbeathdr *)chunk->skb->data;
param_hdr = (struct sctp_paramhdr *)chunk->subh.hb_hdr;
paylen = ntohs(chunk->chunk_hdr->length) - sizeof(struct sctp_chunkhdr);
 
-- 
2.1.0



[PATCH net-next 10/11] sctp: remove the typedef sctp_heartbeat_chunk_t

2017-07-22 Thread Xin Long
This patch is to remove the typedef sctp_heartbeat_chunk_t, and
replace with struct sctp_heartbeat_chunk in the places where it's
using this typedef.

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

diff --git a/include/linux/sctp.h b/include/linux/sctp.h
index 6e26b86..bfda7c6 100644
--- a/include/linux/sctp.h
+++ b/include/linux/sctp.h
@@ -398,10 +398,10 @@ struct sctp_heartbeathdr {
struct sctp_paramhdr info;
 };
 
-typedef struct sctp_heartbeat_chunk {
+struct sctp_heartbeat_chunk {
struct sctp_chunkhdr chunk_hdr;
struct sctp_heartbeathdr hb_hdr;
-} sctp_heartbeat_chunk_t;
+};
 
 
 /* For the abort and shutdown ACK we must carry the init tag in the
diff --git a/net/sctp/sm_statefuns.c b/net/sctp/sm_statefuns.c
index 32ac90b..7bbee08 100644
--- a/net/sctp/sm_statefuns.c
+++ b/net/sctp/sm_statefuns.c
@@ -1088,7 +1088,8 @@ sctp_disposition_t sctp_sf_beat_8_3(struct net *net,
return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
 
/* Make sure that the HEARTBEAT chunk has a valid length. */
-   if (!sctp_chunk_length_valid(chunk, sizeof(sctp_heartbeat_chunk_t)))
+   if (!sctp_chunk_length_valid(chunk,
+sizeof(struct sctp_heartbeat_chunk)))
return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
  commands);
 
-- 
2.1.0



[PATCH net-next 07/11] sctp: remove the typedef sctp_sackhdr_t

2017-07-22 Thread Xin Long
This patch is to remove the typedef sctp_sackhdr_t, and replace
with struct sctp_sackhdr in the places where it's using this
typedef.

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

diff --git a/include/linux/sctp.h b/include/linux/sctp.h
index 8df6ac5..a2e4312 100644
--- a/include/linux/sctp.h
+++ b/include/linux/sctp.h
@@ -373,17 +373,17 @@ union sctp_sack_variable {
__be32 dup;
 };
 
-typedef struct sctp_sackhdr {
+struct sctp_sackhdr {
__be32 cum_tsn_ack;
__be32 a_rwnd;
__be16 num_gap_ack_blocks;
__be16 num_dup_tsns;
union sctp_sack_variable variable[0];
-} sctp_sackhdr_t;
+};
 
 typedef struct sctp_sack_chunk {
struct sctp_chunkhdr chunk_hdr;
-   sctp_sackhdr_t sack_hdr;
+   struct sctp_sackhdr sack_hdr;
 } sctp_sack_chunk_t;
 
 
diff --git a/include/net/sctp/command.h b/include/net/sctp/command.h
index d4679e7..1d5f6ff 100644
--- a/include/net/sctp/command.h
+++ b/include/net/sctp/command.h
@@ -135,7 +135,7 @@ typedef union {
struct sctp_init_chunk *init;
struct sctp_ulpevent *ulpevent;
struct sctp_packet *packet;
-   sctp_sackhdr_t *sackh;
+   struct sctp_sackhdr *sackh;
struct sctp_datamsg *msg;
 } sctp_arg_t;
 
@@ -176,7 +176,7 @@ SCTP_ARG_CONSTRUCTOR(BA,struct sctp_bind_addr *, bp)
 SCTP_ARG_CONSTRUCTOR(PEER_INIT,struct sctp_init_chunk *, init)
 SCTP_ARG_CONSTRUCTOR(ULPEVENT,  struct sctp_ulpevent *, ulpevent)
 SCTP_ARG_CONSTRUCTOR(PACKET,   struct sctp_packet *, packet)
-SCTP_ARG_CONSTRUCTOR(SACKH,sctp_sackhdr_t *, sackh)
+SCTP_ARG_CONSTRUCTOR(SACKH,struct sctp_sackhdr *, sackh)
 SCTP_ARG_CONSTRUCTOR(DATAMSG,  struct sctp_datamsg *, msg)
 
 static inline sctp_arg_t SCTP_FORCE(void)
diff --git a/net/sctp/sm_statefuns.c b/net/sctp/sm_statefuns.c
index 7f85239..c09dfe6 100644
--- a/net/sctp/sm_statefuns.c
+++ b/net/sctp/sm_statefuns.c
@@ -3187,7 +3187,7 @@ sctp_disposition_t sctp_sf_eat_sack_6_2(struct net *net,
sctp_cmd_seq_t *commands)
 {
struct sctp_chunk *chunk = arg;
-   sctp_sackhdr_t *sackh;
+   struct sctp_sackhdr *sackh;
__u32 ctsn;
 
if (!sctp_vtag_verify(chunk, asoc))
-- 
2.1.0



[PATCH net-next 08/11] sctp: remove the typedef sctp_sack_chunk_t

2017-07-22 Thread Xin Long
This patch is to remove the typedef sctp_sack_chunk_t, and
replace with struct sctp_sack_chunk in the places where it's
using this typedef.

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

diff --git a/include/linux/sctp.h b/include/linux/sctp.h
index a2e4312..48f6560 100644
--- a/include/linux/sctp.h
+++ b/include/linux/sctp.h
@@ -381,10 +381,10 @@ struct sctp_sackhdr {
union sctp_sack_variable variable[0];
 };
 
-typedef struct sctp_sack_chunk {
+struct sctp_sack_chunk {
struct sctp_chunkhdr chunk_hdr;
struct sctp_sackhdr sack_hdr;
-} sctp_sack_chunk_t;
+};
 
 
 /* RFC 2960.  Section 3.3.5 Heartbeat Request (HEARTBEAT) (4):
diff --git a/net/sctp/chunk.c b/net/sctp/chunk.c
index 1323d41..681b181 100644
--- a/net/sctp/chunk.c
+++ b/net/sctp/chunk.c
@@ -221,7 +221,7 @@ struct sctp_datamsg *sctp_datamsg_from_user(struct 
sctp_association *asoc,
asoc->outqueue.out_qlen == 0 &&
list_empty(>outqueue.retransmit) &&
msg_len > max_data)
-   first_len -= SCTP_PAD4(sizeof(sctp_sack_chunk_t));
+   first_len -= SCTP_PAD4(sizeof(struct sctp_sack_chunk));
 
/* Encourage Cookie-ECHO bundling. */
if (asoc->state < SCTP_STATE_COOKIE_ECHOED)
diff --git a/net/sctp/sm_statefuns.c b/net/sctp/sm_statefuns.c
index c09dfe6..08ebe8c 100644
--- a/net/sctp/sm_statefuns.c
+++ b/net/sctp/sm_statefuns.c
@@ -3194,7 +3194,7 @@ sctp_disposition_t sctp_sf_eat_sack_6_2(struct net *net,
return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
 
/* Make sure that the SACK chunk has a valid length. */
-   if (!sctp_chunk_length_valid(chunk, sizeof(sctp_sack_chunk_t)))
+   if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_sack_chunk)))
return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
  commands);
 
@@ -4515,7 +4515,7 @@ static sctp_disposition_t sctp_sf_abort_violation(
  * Handle a protocol violation when the chunk length is invalid.
  * "Invalid" length is identified as smaller than the minimal length a
  * given chunk can be.  For example, a SACK chunk has invalid length
- * if its length is set to be smaller than the size of sctp_sack_chunk_t.
+ * if its length is set to be smaller than the size of struct sctp_sack_chunk.
  *
  * We inform the other end by sending an ABORT with a Protocol Violation
  * error code.
-- 
2.1.0



[PATCH net-next 02/11] sctp: remove the typedef sctp_cookie_param_t

2017-07-22 Thread Xin Long
This patch is to remove the typedef sctp_cookie_param_t, and
replace with struct sctp_cookie_param in the places where it's
using this typedef.

Signed-off-by: Xin Long 
---
 include/linux/sctp.h |  4 ++--
 net/sctp/sm_make_chunk.c | 18 ++
 2 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/include/linux/sctp.h b/include/linux/sctp.h
index 05c2099..9e77abd 100644
--- a/include/linux/sctp.h
+++ b/include/linux/sctp.h
@@ -342,10 +342,10 @@ struct sctp_initack_chunk {
 };
 
 /* Section 3.3.3.1 State Cookie (7) */
-typedef struct sctp_cookie_param {
+struct sctp_cookie_param {
struct sctp_paramhdr p;
__u8 body[0];
-} sctp_cookie_param_t;
+};
 
 /* Section 3.3.3.1 Unrecognized Parameters (8) */
 typedef struct sctp_unrecognized_param {
diff --git a/net/sctp/sm_make_chunk.c b/net/sctp/sm_make_chunk.c
index 0b36e96..163004e 100644
--- a/net/sctp/sm_make_chunk.c
+++ b/net/sctp/sm_make_chunk.c
@@ -69,7 +69,8 @@ static struct sctp_chunk *sctp_make_data(const struct 
sctp_association *asoc,
 static struct sctp_chunk *_sctp_make_chunk(const struct sctp_association *asoc,
   __u8 type, __u8 flags, int paylen,
   gfp_t gfp);
-static sctp_cookie_param_t *sctp_pack_cookie(const struct sctp_endpoint *ep,
+static struct sctp_cookie_param *sctp_pack_cookie(
+   const struct sctp_endpoint *ep,
const struct sctp_association *asoc,
const struct sctp_chunk *init_chunk,
int *cookie_len,
@@ -387,7 +388,7 @@ struct sctp_chunk *sctp_make_init_ack(const struct 
sctp_association *asoc,
union sctp_params addrs;
struct sctp_sock *sp;
int addrs_len;
-   sctp_cookie_param_t *cookie;
+   struct sctp_cookie_param *cookie;
int cookie_len;
size_t chunksize;
struct sctp_adaptation_ind_param aiparam;
@@ -1595,14 +1596,15 @@ struct sctp_association *sctp_make_temp_asoc(const 
struct sctp_endpoint *ep,
 /* Build a cookie representing asoc.
  * This INCLUDES the param header needed to put the cookie in the INIT ACK.
  */
-static sctp_cookie_param_t *sctp_pack_cookie(const struct sctp_endpoint *ep,
- const struct sctp_association *asoc,
- const struct sctp_chunk *init_chunk,
- int *cookie_len,
- const __u8 *raw_addrs, int addrs_len)
+static struct sctp_cookie_param *sctp_pack_cookie(
+   const struct sctp_endpoint *ep,
+   const struct sctp_association *asoc,
+   const struct sctp_chunk *init_chunk,
+   int *cookie_len,
+   const __u8 *raw_addrs, int addrs_len)
 {
-   sctp_cookie_param_t *retval;
struct sctp_signed_cookie *cookie;
+   struct sctp_cookie_param *retval;
int headersize, bodysize;
 
/* Header size is static data prior to the actual cookie, including
-- 
2.1.0



[PATCH net-next 06/11] sctp: remove the typedef sctp_sack_variable_t

2017-07-22 Thread Xin Long
This patch is to remove the typedef sctp_sack_variable_t, and
replace with union sctp_sack_variable in the places where it's
using this typedef.

It is also to fix some indents in sctp_acked().

Signed-off-by: Xin Long 
---
 include/linux/sctp.h |  6 +++---
 net/sctp/outqueue.c  | 10 +-
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/include/linux/sctp.h b/include/linux/sctp.h
index 8faf74e..8df6ac5 100644
--- a/include/linux/sctp.h
+++ b/include/linux/sctp.h
@@ -368,17 +368,17 @@ struct sctp_gap_ack_block {
__be16 end;
 };
 
-typedef union {
+union sctp_sack_variable {
struct sctp_gap_ack_block gab;
__be32 dup;
-} sctp_sack_variable_t;
+};
 
 typedef struct sctp_sackhdr {
__be32 cum_tsn_ack;
__be32 a_rwnd;
__be16 num_gap_ack_blocks;
__be16 num_dup_tsns;
-   sctp_sack_variable_t variable[0];
+   union sctp_sack_variable variable[0];
 } sctp_sackhdr_t;
 
 typedef struct sctp_sack_chunk {
diff --git a/net/sctp/outqueue.c b/net/sctp/outqueue.c
index e876270..d2a8adf 100644
--- a/net/sctp/outqueue.c
+++ b/net/sctp/outqueue.c
@@ -1197,7 +1197,7 @@ static void sctp_outq_flush(struct sctp_outq *q, int 
rtx_timeout, gfp_t gfp)
 static void sctp_sack_update_unack_data(struct sctp_association *assoc,
struct sctp_sackhdr *sack)
 {
-   sctp_sack_variable_t *frags;
+   union sctp_sack_variable *frags;
__u16 unack_data;
int i;
 
@@ -1224,7 +1224,7 @@ int sctp_outq_sack(struct sctp_outq *q, struct sctp_chunk 
*chunk)
struct sctp_transport *transport;
struct sctp_chunk *tchunk = NULL;
struct list_head *lchunk, *transport_list, *temp;
-   sctp_sack_variable_t *frags = sack->variable;
+   union sctp_sack_variable *frags = sack->variable;
__u32 sack_ctsn, ctsn, tsn;
__u32 highest_tsn, highest_new_tsn;
__u32 sack_a_rwnd;
@@ -1736,10 +1736,10 @@ static void sctp_mark_missing(struct sctp_outq *q,
 /* Is the given TSN acked by this packet?  */
 static int sctp_acked(struct sctp_sackhdr *sack, __u32 tsn)
 {
-   int i;
-   sctp_sack_variable_t *frags;
-   __u16 tsn_offset, blocks;
__u32 ctsn = ntohl(sack->cum_tsn_ack);
+   union sctp_sack_variable *frags;
+   __u16 tsn_offset, blocks;
+   int i;
 
if (TSN_lte(tsn, ctsn))
goto pass;
-- 
2.1.0



[PATCH net-next 05/11] sctp: remove the typedef sctp_dup_tsn_t

2017-07-22 Thread Xin Long
This patch is to remove the typedef sctp_dup_tsn_t, and replace
with __be32 in the places where it's using this typedef.

Signed-off-by: Xin Long 
---
 include/linux/sctp.h | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/include/linux/sctp.h b/include/linux/sctp.h
index b84b8e8..8faf74e 100644
--- a/include/linux/sctp.h
+++ b/include/linux/sctp.h
@@ -368,11 +368,9 @@ struct sctp_gap_ack_block {
__be16 end;
 };
 
-typedef __be32 sctp_dup_tsn_t;
-
 typedef union {
struct sctp_gap_ack_block gab;
-   sctp_dup_tsn_t dup;
+   __be32 dup;
 } sctp_sack_variable_t;
 
 typedef struct sctp_sackhdr {
-- 
2.1.0



[PATCH net-next 01/11] sctp: remove the typedef sctp_initack_chunk_t

2017-07-22 Thread Xin Long
This patch is to remove the typedef sctp_initack_chunk_t, and
replace with struct sctp_initack_chunk in the places where it's
using this typedef.

It is also to use sizeof(variable) instead of sizeof(type).

Signed-off-by: Xin Long 
---
 include/linux/sctp.h|  5 -
 net/sctp/sm_statefuns.c | 13 ++---
 2 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/include/linux/sctp.h b/include/linux/sctp.h
index 913474d..05c2099 100644
--- a/include/linux/sctp.h
+++ b/include/linux/sctp.h
@@ -336,7 +336,10 @@ struct sctp_hmac_algo_param {
  *   The INIT ACK chunk is used to acknowledge the initiation of an SCTP
  *   association.
  */
-typedef struct sctp_init_chunk sctp_initack_chunk_t;
+struct sctp_initack_chunk {
+   struct sctp_chunkhdr chunk_hdr;
+   struct sctp_inithdr init_hdr;
+};
 
 /* Section 3.3.3.1 State Cookie (7) */
 typedef struct sctp_cookie_param {
diff --git a/net/sctp/sm_statefuns.c b/net/sctp/sm_statefuns.c
index ae4c48c..6568fc3 100644
--- a/net/sctp/sm_statefuns.c
+++ b/net/sctp/sm_statefuns.c
@@ -518,7 +518,7 @@ sctp_disposition_t sctp_sf_do_5_1C_ack(struct net *net,
return sctp_sf_violation_chunk(net, ep, asoc, type, arg, 
commands);
 
/* Make sure that the INIT-ACK chunk has a valid length */
-   if (!sctp_chunk_length_valid(chunk, sizeof(sctp_initack_chunk_t)))
+   if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_initack_chunk)))
return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
  commands);
/* Grab the INIT header.  */
@@ -4453,11 +4453,10 @@ static sctp_disposition_t sctp_sf_abort_violation(
/* Treat INIT-ACK as a special case during COOKIE-WAIT. */
if (chunk->chunk_hdr->type == SCTP_CID_INIT_ACK &&
!asoc->peer.i.init_tag) {
-   sctp_initack_chunk_t *initack;
+   struct sctp_initack_chunk *initack;
 
-   initack = (sctp_initack_chunk_t *)chunk->chunk_hdr;
-   if (!sctp_chunk_length_valid(chunk,
-
sizeof(sctp_initack_chunk_t)))
+   initack = (struct sctp_initack_chunk *)chunk->chunk_hdr;
+   if (!sctp_chunk_length_valid(chunk, sizeof(*initack)))
abort->chunk_hdr->flags |= SCTP_CHUNK_FLAG_T;
else {
unsigned int inittag;
@@ -6106,9 +6105,9 @@ static struct sctp_packet *sctp_ootb_pkt_new(struct net 
*net,
switch (chunk->chunk_hdr->type) {
case SCTP_CID_INIT_ACK:
{
-   sctp_initack_chunk_t *initack;
+   struct sctp_initack_chunk *initack;
 
-   initack = (sctp_initack_chunk_t *)chunk->chunk_hdr;
+   initack = (struct sctp_initack_chunk *)chunk->chunk_hdr;
vtag = ntohl(initack->init_hdr.init_tag);
break;
}
-- 
2.1.0



[PATCH net-next 00/11] sctp: remove typedefs from structures part 3

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

All this kind of typedef's using should be removed. This patchset is the
part 3 to remove it for another 11 basic structures from linux/sctp.h.

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

Xin Long (11):
  sctp: remove the typedef sctp_initack_chunk_t
  sctp: remove the typedef sctp_cookie_param_t
  sctp: remove the typedef sctp_unrecognized_param_t
  sctp: remove the typedef sctp_gap_ack_block_t
  sctp: remove the typedef sctp_dup_tsn_t
  sctp: remove the typedef sctp_sack_variable_t
  sctp: remove the typedef sctp_sackhdr_t
  sctp: remove the typedef sctp_sack_chunk_t
  sctp: remove the typedef sctp_heartbeathdr_t
  sctp: remove the typedef sctp_heartbeat_chunk_t
  sctp: remove the typedef sctp_abort_chunk_t

 include/linux/sctp.h   | 53 +++---
 include/net/sctp/command.h |  4 ++--
 net/sctp/chunk.c   |  2 +-
 net/sctp/outqueue.c| 10 -
 net/sctp/sm_make_chunk.c   | 18 +---
 net/sctp/sm_statefuns.c| 50 ---
 6 files changed, 68 insertions(+), 69 deletions(-)

-- 
2.1.0



[PATCH net-next 03/11] sctp: remove the typedef sctp_unrecognized_param_t

2017-07-22 Thread Xin Long
This patch is to remove the typedef sctp_unrecognized_param_t, and
replace with struct sctp_unrecognized_param in the places where it's
using this typedef.

It is also to fix some indents in sctp_sf_do_unexpected_init() and
sctp_sf_do_5_1B_init().

Signed-off-by: Xin Long 
---
 include/linux/sctp.h|  4 ++--
 net/sctp/sm_statefuns.c | 18 +++---
 2 files changed, 9 insertions(+), 13 deletions(-)

diff --git a/include/linux/sctp.h b/include/linux/sctp.h
index 9e77abd..c323b3e 100644
--- a/include/linux/sctp.h
+++ b/include/linux/sctp.h
@@ -348,10 +348,10 @@ struct sctp_cookie_param {
 };
 
 /* Section 3.3.3.1 Unrecognized Parameters (8) */
-typedef struct sctp_unrecognized_param {
+struct sctp_unrecognized_param {
struct sctp_paramhdr param_hdr;
struct sctp_paramhdr unrecognized;
-} sctp_unrecognized_param_t;
+};
 
 
 
diff --git a/net/sctp/sm_statefuns.c b/net/sctp/sm_statefuns.c
index 6568fc3..7f85239 100644
--- a/net/sctp/sm_statefuns.c
+++ b/net/sctp/sm_statefuns.c
@@ -306,12 +306,10 @@ sctp_disposition_t sctp_sf_do_5_1B_init(struct net *net,
void *arg,
sctp_cmd_seq_t *commands)
 {
-   struct sctp_chunk *chunk = arg;
-   struct sctp_chunk *repl;
+   struct sctp_chunk *chunk = arg, *repl, *err_chunk;
+   struct sctp_unrecognized_param *unk_param;
struct sctp_association *new_asoc;
-   struct sctp_chunk *err_chunk;
struct sctp_packet *packet;
-   sctp_unrecognized_param_t *unk_param;
int len;
 
/* 6.10 Bundling
@@ -435,7 +433,7 @@ sctp_disposition_t sctp_sf_do_5_1B_init(struct net *net,
 * construct the parameters in INIT ACK by copying the
 * ERROR causes over.
 */
-   unk_param = (sctp_unrecognized_param_t *)
+   unk_param = (struct sctp_unrecognized_param *)
((__u8 *)(err_chunk->chunk_hdr) +
sizeof(struct sctp_chunkhdr));
/* Replace the cause code with the "Unrecognized parameter"
@@ -1419,13 +1417,11 @@ static sctp_disposition_t sctp_sf_do_unexpected_init(
const sctp_subtype_t type,
void *arg, sctp_cmd_seq_t *commands)
 {
-   sctp_disposition_t retval;
-   struct sctp_chunk *chunk = arg;
-   struct sctp_chunk *repl;
+   struct sctp_chunk *chunk = arg, *repl, *err_chunk;
+   struct sctp_unrecognized_param *unk_param;
struct sctp_association *new_asoc;
-   struct sctp_chunk *err_chunk;
struct sctp_packet *packet;
-   sctp_unrecognized_param_t *unk_param;
+   sctp_disposition_t retval;
int len;
 
/* 6.10 Bundling
@@ -1555,7 +1551,7 @@ static sctp_disposition_t sctp_sf_do_unexpected_init(
 * construct the parameters in INIT ACK by copying the
 * ERROR causes over.
 */
-   unk_param = (sctp_unrecognized_param_t *)
+   unk_param = (struct sctp_unrecognized_param *)
((__u8 *)(err_chunk->chunk_hdr) +
sizeof(struct sctp_chunkhdr));
/* Replace the cause code with the "Unrecognized parameter"
-- 
2.1.0



[PATCH net-next 04/11] sctp: remove the typedef sctp_gap_ack_block_t

2017-07-22 Thread Xin Long
This patch is to remove the typedef sctp_gap_ack_block_t, and
replace with struct sctp_gap_ack_block in the places where it's
using this typedef.

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

diff --git a/include/linux/sctp.h b/include/linux/sctp.h
index c323b3e..b84b8e8 100644
--- a/include/linux/sctp.h
+++ b/include/linux/sctp.h
@@ -363,16 +363,16 @@ struct sctp_unrecognized_param {
  *  subsequences of DATA chunks as represented by their TSNs.
  */
 
-typedef struct sctp_gap_ack_block {
+struct sctp_gap_ack_block {
__be16 start;
__be16 end;
-} sctp_gap_ack_block_t;
+};
 
 typedef __be32 sctp_dup_tsn_t;
 
 typedef union {
-   sctp_gap_ack_block_tgab;
-sctp_dup_tsn_t dup;
+   struct sctp_gap_ack_block gab;
+   sctp_dup_tsn_t dup;
 } sctp_sack_variable_t;
 
 typedef struct sctp_sackhdr {
-- 
2.1.0



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

2017-07-22 Thread Salil Mehta
Hi Stephen,

> -Original Message-
> From: Stephen Hemminger [mailto:step...@networkplumber.org]
> Sent: Monday, June 19, 2017 5:59 PM
> To: Salil Mehta
> Cc: da...@davemloft.net; Zhuangyuzeng (Yisen); huangdaode; lipeng (Y);
> mehta.salil@gmail.com; netdev@vger.kernel.org; linux-
> ker...@vger.kernel.org; Linuxarm
> Subject: Re: [PATCH V3 net-next 2/8] net: hns3: Add support of the
> HNAE3 framework
> 
> On Sat, 17 Jun 2017 18:24:25 +0100
> Salil Mehta  wrote:
> 
> > +
> > +/* This struct defines the operation on the handle.
> > + *
> > + * init_ae_dev(): (mandatory)
> > + *   Get PF configure from pci_dev and initialize PF hardware
> > + * uninit_ae_dev()
> > + *   Disable PF device and release PF resource
> > + * register_client
> > + *   Register client to ae_dev
> > + * unregister_client()
> > + *   Unregister client from ae_dev
> > + * start()
> > + *   Enable the hardware
> > + * stop()
> > + *   Disable the hardware
> > + * get_status()
> > + *   Get the carrier state of the back channel of the handle, 1 for
> ok, 0 for
> > + *   non-ok
> > + * get_ksettings_an_result()
> > + *   Get negotiation status,speed and duplex
> > + * update_speed_duplex_h()
> > + *   Update hardware speed and duplex
> > + * get_media_type()
> > + *   Get media type of MAC
> > + * adjust_link()
> > + *   Adjust link status
> > + * set_loopback()
> > + *   Set loopback
> > + * set_promisc_mode
> > + *   Set promisc mode
> > + * set_mtu()
> > + *   set mtu
> > + * get_pauseparam()
> > + *   get tx and rx of pause frame use
> > + * set_pauseparam()
> > + *   set tx and rx of pause frame use
> > + * set_autoneg()
> > + *   set auto autonegotiation of pause frame use
> > + * get_autoneg()
> > + *   get auto autonegotiation of pause frame use
> > + * get_coalesce_usecs()
> > + *   get usecs to delay a TX interrupt after a packet is sent
> > + * get_rx_max_coalesced_frames()
> > + *   get Maximum number of packets to be sent before a TX interrupt.
> > + * set_coalesce_usecs()
> > + *   set usecs to delay a TX interrupt after a packet is sent
> > + * set_coalesce_frames()
> > + *   set Maximum number of packets to be sent before a TX interrupt.
> > + * get_mac_addr()
> > + *   get mac address
> > + * set_mac_addr()
> > + *   set mac address
> > + * add_uc_addr
> > + *   Add unicast addr to mac table
> > + * rm_uc_addr
> > + *   Remove unicast addr from mac table
> > + * set_mc_addr()
> > + *   Set multicast address
> > + * add_mc_addr
> > + *   Add multicast address to mac table
> > + * rm_mc_addr
> > + *   Remove multicast address from mac table
> > + * update_stats()
> > + *   Update Old network device statistics
> > + * get_ethtool_stats()
> > + *   Get ethtool network device statistics
> > + * get_strings()
> > + *   Get a set of strings that describe the requested objects
> > + * get_sset_count()
> > + *   Get number of strings that @get_strings will write
> > + * update_led_status()
> > + *   Update the led status
> > + * set_led_id()
> > + *   Set led id
> > + * get_regs()
> > + *   Get regs dump
> > + * get_regs_len()
> > + *   Get the len of the regs dump
> > + * get_rss_key_size()
> > + *   Get rss key size
> > + * get_rss_indir_size()
> > + *   Get rss indirection table size
> > + * get_rss()
> > + *   Get rss table
> > + * set_rss()
> > + *   Set rss table
> > + * get_tc_size()
> > + *   Get tc size of handle
> > + * get_vector()
> > + *   Get vector number and vector infomation
> > + * map_ring_to_vector()
> > + *   Map rings to vector
> > + * unmap_ring_from_vector()
> > + *   Unmap rings from vector
> > + * add_tunnel_udp()
> > + *   Add tunnel information to hardware
> > + * del_tunnel_udp()
> > + *   Delete tunnel information from hardware
> > + * reset_queue()
> > + *   Reset queue
> > + * get_fw_version()
> > + *   Get firmware version
> > + * get_mdix_mode()
> > + *   Get media typr of phy
> > + * set_vlan_filter()
> > + *   Set vlan filter config of Ports
> > + * set_vf_vlan_filter()
> > + *   Set vlan filter config of vf
> > + */
> > +struct hnae3_ae_ops {
> > +   int (*init_ae_dev)(struct hnae3_ae_dev *ae_dev);
> > +   void (*uninit_ae_dev)(struct hnae3_ae_dev *ae_dev);
> > +
> > +   int (*register_client)(struct hnae3_client *client,
> > +  struct hnae3_ae_dev *ae_dev);
> > +   void (*unregister_client)(struct hnae3_client *client,
> > + struct hnae3_ae_dev *ae_dev);
> > +   int (*start)(struct hnae3_handle *handle);
> > +   void (*stop)(struct hnae3_handle *handle);
> > +   int (*get_status)(struct hnae3_handle *handle);
> > +   void (*get_ksettings_an_result)(struct hnae3_handle *handle,
> > +   u8 *auto_neg, u32 *speed, u8 *duplex);
> > +
> > +   int (*update_speed_duplex_h)(struct hnae3_handle *handle);
> > +   int (*cfg_mac_speed_dup_h)(struct hnae3_handle *handle, int
> speed,
> > +  u8 duplex);
> > +
> > +   void (*get_media_type)(struct hnae3_handle 

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

2017-07-22 Thread Salil Mehta
Hi Stephen,

> -Original Message-
> From: Stephen Hemminger [mailto:step...@networkplumber.org]
> Sent: Monday, June 19, 2017 4:48 PM
> To: Salil Mehta
> Cc: da...@davemloft.net; Zhuangyuzeng (Yisen); huangdaode; lipeng (Y);
> mehta.salil@gmail.com; netdev@vger.kernel.org; linux-
> ker...@vger.kernel.org; Linuxarm
> Subject: Re: [PATCH V2 net-next 1/8] net: hns3: Add support of HNS3
> Ethernet Driver for hip08 SoC
> 
> On Wed, 14 Jun 2017 00:10:28 +0100
> Salil Mehta  wrote:
> 
> > +hns3_nic_get_stats64(struct net_device *ndev, struct
> rtnl_link_stats64 *stats)
> > +{
> > +   struct hns3_nic_priv *priv = netdev_priv(ndev);
> > +   int queue_num = priv->ae_handle->kinfo.num_tqps;
> > +   u64 tx_bytes = 0;
> > +   u64 rx_bytes = 0;
> > +   u64 tx_pkts = 0;
> > +   u64 rx_pkts = 0;
> > +   int idx = 0;
> unnecessary initialization
> 
> > +
> > +   for (idx = 0; idx < queue_num; idx++) {
> > +   tx_bytes += priv->ring_data[idx].ring->stats.tx_bytes;
> > +   tx_pkts += priv->ring_data[idx].ring->stats.tx_pkts;
> > +   rx_bytes +=
> > +   priv->ring_data[idx + queue_num].ring-
> >stats.rx_bytes;
> > +   rx_pkts += priv->ring_data[idx + queue_num].ring-
> >stats.rx_pkts;
> > +   }
> > +
> 
> Since rx_bytes and other statistics are 64 bit values. You need to use
> something to ensure that updates to these values are atomic on 32 bit
> platforms.  The most common way to handle this is with the
> u64_stats_sync
> mechanism which is a nop on 64 bit architectures, and uses a seqcount
> to do updates on 32 bit CPU's.
Sure good point. This has changed in the V4 patch.

Thanks for guiding.
Salil

> 
> 


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

2017-07-22 Thread Salil Mehta
Hi Andrew,

> -Original Message-
> From: Andrew Lunn [mailto:and...@lunn.ch]
> Sent: Monday, June 19, 2017 4:53 AM
> To: Salil Mehta
> Cc: da...@davemloft.net; Zhuangyuzeng (Yisen); huangdaode; lipeng (Y);
> mehta.salil@gmail.com; netdev@vger.kernel.org; linux-
> ker...@vger.kernel.org; Linuxarm
> Subject: Re: [PATCH V3 net-next 6/8] net: hns3: Add MDIO support to
> HNS3 Ethernet driver for hip08 SoC
> 
> On Sat, Jun 17, 2017 at 06:24:29PM +0100, Salil Mehta wrote:
> > This patch adds the support of MDIO bus interface for HNS3 driver.
> > Code provides various interfaces to start and stop the PHY layer
> > and to read and write the MDIO bus or PHY.
> >
> > Signed-off-by: Daode Huang 
> > Signed-off-by: lipeng 
> > Signed-off-by: Salil Mehta 
> > Signed-off-by: Yisen Zhuang 
> > ---
> > Patch V3: Addressed Below comments:
> >  1. Florian Fainelli: https://lkml.org/lkml/2017/6/13/963
> >  2. Andrew Lunn: https://lkml.org/lkml/2017/6/13/1039
> 
> It is normal to say what you actually changed.
> 
> > Patch V2: Addressed below comments:
> >  1. Florian Fainelli: https://lkml.org/lkml/2017/6/10/130
> >  2. Andrew Lunn: https://lkml.org/lkml/2017/6/10/168
> > Patch V1: Initial Submit
> > ---
> >  .../ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c| 249
> +
> >  1 file changed, 249 insertions(+)
> >  create mode 100644
> drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c
> >
> > diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c
> b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c
> > new file mode 100644
> > index 000..5b21c50
> > --- /dev/null
> > +++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c
> > @@ -0,0 +1,249 @@
> > +/*
> > + * Copyright (c) 2016~2017 Hisilicon Limited.
> > + *
> > + * This program is free software; you can redistribute it and/or
> modify
> > + * it under the terms of the GNU General Public License as published
> by
> > + * the Free Software Foundation; either version 2 of the License, or
> > + * (at your option) any later version.
> > + */
> > +
> > +#include 
> > +#include 
> > +
> > +#include "hclge_cmd.h"
> > +#include "hclge_main.h"
> > +
> > +enum hclge_mdio_c22_op_seq {
> > +   HCLGE_MDIO_C22_WRITE = 1,
> > +   HCLGE_MDIO_C22_READ = 2
> > +};
> > +
> > +#define HCLGE_MDIO_CTRL_START_BIT   BIT(0)
> > +#define HCLGE_MDIO_CTRL_ST_MSK  GENMASK(2, 1)
> > +#define HCLGE_MDIO_CTRL_ST_LSH  1
> > +#define HCLGE_MDIO_IS_C22(c22)  (((c22) << HCLGE_MDIO_CTRL_ST_LSH) &
> \
> > +   HCLGE_MDIO_CTRL_ST_MSK)
> > +
> > +#define HCLGE_MDIO_CTRL_OP_MSK  GENMASK(4, 3)
> > +#define HCLGE_MDIO_CTRL_OP_LSH  3
> > +#define HCLGE_MDIO_CTRL_OP(access) \
> > +   (((access) << HCLGE_MDIO_CTRL_OP_LSH) & HCLGE_MDIO_CTRL_OP_MSK)
> > +#define HCLGE_MDIO_CTRL_PRTAD_MSK   GENMASK(4, 0)
> > +#define HCLGE_MDIO_CTRL_DEVAD_MSK   GENMASK(4, 0)
> 
> This all seems overly complex. How about
> 
> #define HCLGE_MDIO_CTRL_START_BIT   BIT(0)
> #define HCLGE_MDIO_C22BIT(1)
> #define HCLGE_MDIO_WRITE  (1 << 3)
> #define HCLGE_MDIO_READ   (2 << 3)
> #define HCLGE_MDIO_C22_WRITE  (HCLGE_MDIO_CTRL_START_BIT |
> HCLGE_MDIO_C22 | HCLGE_MDIO_WRITE)
> #define HCLGE_MDIO_C22_READ   (HCLGE_MDIO_CTRL_START_BIT |
> HCLGE_MDIO_C22 | HCLGE_MDIO_READ)
> #define HCLGE_MDIO_C45_WRITE  (HCLGE_MDIO_CTRL_START_BIT |
> HCLGE_MDIO_WRITE)
> #define HCLGE_MDIO_C45_READ   (HCLGE_MDIO_CTRL_START_BIT |
> HCLGE_MDIO_READ)
> 
> #define HCLGE_MDIO_STATUS_ERROR   BIT(0)
> 
> Keep it simple, don't have more defines than what you need.
Sure, changed in V4 Patch, Thanks!

Salil
> 
> > +static int hclge_mdio_write(struct mii_bus *bus, int phy_id, int
> regnum,
> > +   u16 data)
> > +{
> > +   struct hclge_dev *hdev = (struct hclge_dev *)bus->priv;
> > +   struct hclge_mdio_cfg_cmd *mdio_cmd;
> > +   enum hclge_cmd_status status;
> > +   struct hclge_desc desc;
> > +   u8 devad;
> > +
> > +   if (!bus)
> > +   return -EINVAL;
> > +
> > +   devad = ((regnum >> 16) & 0x1f);
> 
> So you have changed this to only support C22. Which means devad is not
> needed, since that is c45 only.
Thanks for catching. Removed this from MDIO file.

Best regards
Salil
> 
> > +
> > +   dev_dbg(>dev, "phy id=%d, devad=%d\n", phy_id, devad);
> > +
> > +   hclge_cmd_setup_basic_desc(, HCLGE_OPC_MDIO_CONFIG, false);
> > +
> > +   mdio_cmd = (struct hclge_mdio_cfg_cmd *)desc.data;
> > +
> > +   mdio_cmd->prtad = phy_id & HCLGE_MDIO_CTRL_PRTAD_MSK;
> > +   mdio_cmd->data_wr = cpu_to_le16(data);
> > +   mdio_cmd->devad = devad & HCLGE_MDIO_CTRL_DEVAD_MSK;
> > +
> > +   /* Write reg and data */
> > +   mdio_cmd->ctrl_bit = HCLGE_MDIO_IS_C22(1);
> 
> Passing the parameter is now pointless if you are only doing C22.
Sure, changed.

> 
> > +   mdio_cmd->ctrl_bit |= 

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

2017-07-22 Thread Salil Mehta
Hi Bo Yu,

> -Original Message-
> From: Bo Yu [mailto:tsu.y...@gmail.com]
> Sent: Monday, June 19, 2017 1:57 AM
> To: Salil Mehta
> Cc: da...@davemloft.net; Zhuangyuzeng (Yisen); huangdaode; lipeng (Y);
> mehta.salil@gmail.com; netdev@vger.kernel.org; linux-
> ker...@vger.kernel.org; Linuxarm
> Subject: Re: [PATCH V3 net-next 1/8] net: hns3: Add support of HNS3
> Ethernet Driver for hip08 SoC
> 
> Hi,
> On Sat, Jun 17, 2017 at 06:24:24PM +0100, Salil Mehta wrote:
> >+struct notifier_block notifier_block;
> >+/* Vxlan/Geneve information */
> >+struct hns3_udp_tunnel udp_tnl[HNS3_UDP_TNL_MAX];
> >+};
> >+
> >+/* the distance between [begin, end) in a ring buffer
> >+ * note: there is a unuse slot between the begin and the end
> >+ */
> >+static inline int ring_dist(struct hns3_enet_ring *ring, int begin,
> int end)
> >+{
> >+return (end - begin + ring->desc_num) % ring->desc_num;
> >+}
> >+
> >+static inline int ring_space(struct hns3_enet_ring *ring)
> >+{
> >+return ring->desc_num -
> >+ring_dist(ring, ring->next_to_clean, ring->next_to_use) -
> 1;
> >+}
> >+
> >+static inline int is_ring_empty(struct hns3_enet_ring *ring)
> >+{
> >+return ring->next_to_use == ring->next_to_clean;
> >+}
> >+
> >+static inline void hns3_write_reg(void __iomem *base, u32 reg, u32
> value)
> >+{
> >+u8 __iomem *reg_addr = READ_ONCE(base);
> >+
> >+writel(value, reg_addr + reg);
> >+}
> >+
> >+#define hns3_write_dev(a, reg, value) \
> >+hns3_write_reg((a)->io_base, (reg), (value))
> >+
> >+#define hnae_queue_xmit(tqp, buf_num) writel_relaxed(buf_num, \
> >+(tqp)->io_base + HNS3_RING_TX_RING_TAIL_REG)
> >+
> >+#define ring_to_dev(ring) (&(ring)->tqp->handle->pdev->dev)
> >+
> >+#define ring_to_dma_dir(ring) (HNAE3_IS_TX_RING(ring) ? \
> >+DMA_TO_DEVICE : DMA_FROM_DEVICE)
> >+
> >+#define tx_ring_data(priv, idx) ((priv)->ring_data[idx])
> >+
> >+#define hnae_buf_size(_ring) ((_ring)->buf_size)
> >+#define hnae_page_order(_ring) (get_order(hnae_buf_size(_ring)))
> >+#define hnae_page_size(_ring) (PAGE_SIZE << hnae_page_order(_ring))
> >+
> >+/* iterator for handling rings in ring group */
> >+#define hns3_for_each_ring(pos, head) \
> >+for (pos = (head).ring; pos != NULL; pos = pos->next)
> 
> Only a pos? Comparsion to NULL could be written "pos" noticed by
> checkpatch.
Fixed in patch V4. Thanks!

Salil
> 
> 
> >+
> >+void hns3_ethtool_set_ops(struct net_device *ndev);
> >+
> >+int hns3_nic_net_xmit_hw(
> >+struct net_device *ndev,
> >+struct sk_buff *skb,
> >+struct hns3_nic_ring_data *ring_data);
> >+int hns3_clean_tx_ring(struct hns3_enet_ring *ring, int budget);
> >+int hns3_clean_rx_ring_ex(
> >+struct hns3_enet_ring *ring,
> >+struct sk_buff **skb_ex,
> >+int budget);
> >+#endif
> >--
> >2.7.4
> >
> >


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

2017-07-22 Thread Salil Mehta
Hi Richard,

> -Original Message-
> From: Richard Cochran [mailto:richardcoch...@gmail.com]
> Sent: Sunday, June 18, 2017 5:45 PM
> To: Salil Mehta
> Cc: da...@davemloft.net; Zhuangyuzeng (Yisen); huangdaode; lipeng (Y);
> mehta.salil@gmail.com; netdev@vger.kernel.org; linux-
> ker...@vger.kernel.org; Linuxarm
> Subject: Re: [PATCH V3 net-next 5/8] net: hns3: Add support of TX
> Scheduler & Shaper to HNS3 driver
> 
> On Sat, Jun 17, 2017 at 06:24:28PM +0100, Salil Mehta wrote:
> > +
> > +int hclge_tm_schd_init(struct hclge_dev *hdev);
> > +int hclge_tm_setup_tc(struct hclge_dev *hdev);
> 
> The definition of this function DNE.
Sorry, I did not get what DNE means? Does Not Exist ?
If yes, the I can see the definition of both the functions.

Best regards
Salil
> 
> > +int hclge_pause_setup_hw(struct hclge_dev *hdev);
> > +
> > +#endif
> > --
> > 2.7.4
> 
> Thanks,
> Richard


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

2017-07-22 Thread Salil Mehta
Hi Bo Yu,

> -Original Message-
> From: Bo Yu [mailto:tsu.y...@gmail.com]
> Sent: Monday, June 19, 2017 1:40 AM
> To: Salil Mehta
> Cc: da...@davemloft.net; Zhuangyuzeng (Yisen); huangdaode; lipeng (Y);
> mehta.salil@gmail.com; netdev@vger.kernel.org; linux-
> ker...@vger.kernel.org; Linuxarm
> Subject: Re: [PATCH V3 net-next 2/8] net: hns3: Add support of the
> HNAE3 framework
> 
> Hi,
> On Sat, Jun 17, 2017 at 06:24:25PM +0100, Salil Mehta wrote:
> >+ *   Unregister client from ae_dev
> >+ * start()
> >+ *   Enable the hardware
> >+ * stop()
> >+ *   Disable the hardware
> >+ * get_status()
> >+ *   Get the carrier state of the back channel of the handle, 1 for
> ok, 0 for
> >+ *   non-ok
> >+ * get_ksettings_an_result()
> >+ *   Get negotiation status,speed and duplex
> >+ * update_speed_duplex_h()
> >+ *   Update hardware speed and duplex
> >+ * get_media_type()
> >+ *   Get media type of MAC
> >+ * adjust_link()
> >+ *   Adjust link status
> >+ * set_loopback()
> >+ *   Set loopback
> >+ * set_promisc_mode
> >+ *   Set promisc mode
> >+ * set_mtu()
> >+ *   set mtu
> >+ * get_pauseparam()
> >+ *   get tx and rx of pause frame use
> >+ * set_pauseparam()
> >+ *   set tx and rx of pause frame use
> >+ * set_autoneg()
> >+ *   set auto autonegotiation of pause frame use
> >+ * get_autoneg()
> >+ *   get auto autonegotiation of pause frame use
> >+ * get_coalesce_usecs()
> >+ *   get usecs to delay a TX interrupt after a packet is sent
> >+ * get_rx_max_coalesced_frames()
> >+ *   get Maximum number of packets to be sent before a TX interrupt.
> >+ * set_coalesce_usecs()
> >+ *   set usecs to delay a TX interrupt after a packet is sent
> >+ * set_coalesce_frames()
> >+ *   set Maximum number of packets to be sent before a TX interrupt.
> >+ * get_mac_addr()
> >+ *   get mac address
> >+ * set_mac_addr()
> >+ *   set mac address
> >+ * add_uc_addr
> >+ *   Add unicast addr to mac table
> >+ * rm_uc_addr
> >+ *   Remove unicast addr from mac table
> >+ * set_mc_addr()
> >+ *   Set multicast address
> >+ * add_mc_addr
> >+ *   Add multicast address to mac table
> >+ * rm_mc_addr
> >+ *   Remove multicast address from mac table
> >+ * update_stats()
> >+ *   Update Old network device statistics
> >+ * get_ethtool_stats()
> >+ *   Get ethtool network device statistics
> >+ * get_strings()
> >+ *   Get a set of strings that describe the requested objects
> >+ * get_sset_count()
> >+ *   Get number of strings that @get_strings will write
> >+ * update_led_status()
> >+ *   Update the led status
> >+ * set_led_id()
> >+ *   Set led id
> >+ * get_regs()
> >+ *   Get regs dump
> >+ * get_regs_len()
> >+ *   Get the len of the regs dump
> >+ * get_rss_key_size()
> >+ *   Get rss key size
> >+ * get_rss_indir_size()
> >+ *   Get rss indirection table size
> >+ * get_rss()
> >+ *   Get rss table
> >+ * set_rss()
> >+ *   Set rss table
> >+ * get_tc_size()
> >+ *   Get tc size of handle
> >+ * get_vector()
> >+ *   Get vector number and vector infomation
> 
> Just another spealling : information
> 
> Checkpatch will report it also.
Fixed it. As far as I know chechkpatch.pl depends upon its dictionary
for it to be able to catch such mistakes. Have you prepared your own?

Thanks
Salil
> 
> >+ * map_ring_to_vector()
> >+ *   Map rings to vector
> >+ * unmap_ring_from_vector()
> >+ *   Unmap rings from vector
> >+ * add_tunnel_udp()
> >+ *   Add tunnel information to hardware
> >+ * del_tunnel_udp()
> >+ *   Delete tunnel information from hardware
> >+ * reset_queue()
> >+ *   Reset queue
> >+ * get_fw_version()
> >+ *   Get firmware version
> >+ * get_mdix_mode()
> >+ *   Get media typr of phy
> >+ * set_vlan_filter()
> >+ *   Set vlan filter config of Ports
> >+ * set_vf_vlan_filter()
> >+ *   Set vlan filter config of vf
> >+ */
> >+struct hnae3_ae_ops {
> >+int (*init_ae_dev)(struct hnae3_ae_dev *ae_dev);
> >+void (*uninit_ae_dev)(struct hnae3_ae_dev *ae_dev);
> >+
> >+int (*register_client)(struct hnae3_client *client,
> >+   struct hnae3_ae_dev *ae_dev);
> >+void (*unregister_client)(struct hnae3_client *client,
> >+  struct hnae3_ae_dev *ae_dev);
> >+int (*start)(struct hnae3_handle *handle);
> >+void (*stop)(struct hnae3_handle *handle);
> >+int (*get_status)(struct hnae3_handle *handle);
> >+void (*get_ksettings_an_result)(struct hnae3_handle *handle,
> >+u8 *auto_neg, u32 *speed, u8 *duplex);
> >+
> >+int (*update_speed_duplex_h)(struct hnae3_handle *handle);
> >+int (*cfg_mac_speed_dup_h)(struct hnae3_handle *handle, int
> speed,
> >+   u8 duplex);
> >+
> >+void (*get_media_type)(struct hnae3_handle *handle, u8
> *media_type);
> >+void (*adjust_link)(struct hnae3_handle *handle, int speed, int
> duplex);
> >+int (*set_loopback)(struct hnae3_handle *handle,
> >+enum hnae3_loop loop_mode, bool en);
> >+
> >+

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

2017-07-22 Thread Salil Mehta
Hi Bo Yu,

> -Original Message-
> From: Bo Yu [mailto:tsu.y...@gmail.com]
> Sent: Monday, June 19, 2017 1:18 AM
> To: Salil Mehta
> Cc: da...@davemloft.net; Zhuangyuzeng (Yisen); huangdaode; lipeng (Y);
> mehta.salil@gmail.com; netdev@vger.kernel.org; linux-
> ker...@vger.kernel.org; Linuxarm
> Subject: Re: [PATCH V3 net-next 1/8] net: hns3: Add support of HNS3
> Ethernet Driver for hip08 SoC
> 
> Hi,
> On Sat, Jun 17, 2017 at 06:24:24PM +0100, Salil Mehta wrote:
> >+static int hns3_fill_desc(struct hns3_enet_ring *ring, void *priv,
> >+  int size, dma_addr_t dma, int frag_end,
> >+  enum hns_desc_type type)
> >+{
> >+struct hns3_desc_cb *desc_cb = >desc_cb[ring->next_to_use];
> >+struct hns3_desc *desc = >desc[ring->next_to_use];
> >+u32 ol_type_vlan_len_msec = 0;
> >+u16 bdtp_fe_sc_vld_ra_ri = 0;
> >+u32 type_cs_vlan_tso = 0;
> >+struct sk_buff *skb;
> >+u32 paylen = 0;
> >+u16 mss = 0;
> >+__be16 protocol;
> >+u8 ol4_proto;
> >+u8 il4_proto;
> >+int ret;
> >+
> >+/* The txbd's baseinfo of DESC_TYPE_PAGE & DESC_TYPE_SKB */
> >+desc_cb->priv = priv;
> >+desc_cb->length = size;
> >+desc_cb->dma = dma;
> >+desc_cb->type = type;
> >+
> >+/* now, fill the descriptor */
> >+desc->addr = cpu_to_le64(dma);
> >+desc->tx.send_size = cpu_to_le16((u16)size);
> >+hns3_set_txbd_baseinfo(_fe_sc_vld_ra_ri, frag_end);
> >+desc->tx.bdtp_fe_sc_vld_ra_ri =
> cpu_to_le16(bdtp_fe_sc_vld_ra_ri);
> >+
> >+if (type == DESC_TYPE_SKB) {
> >+skb = (struct sk_buff *)priv;
> >+paylen = cpu_to_le16(skb->len);
> >+
> >+if (skb->ip_summed == CHECKSUM_PARTIAL) {
> >+skb_reset_mac_len(skb);
> >+protocol = skb->protocol;
> >+
> >+/* vlan packe t*/
> 
> Just a spealling:   /* vlan packet */
Fixed in V4 patch. Thanks!

Salil
> 
> >+if (protocol == htons(ETH_P_8021Q)) {
> >+protocol = vlan_get_protocol(skb);
> >+skb->protocol = protocol;
> >+}
> >+hns3_get_l4_protocol(skb, _proto, _proto);
> >+hns3_set_l2l3l4_len(skb, ol4_proto, il4_proto,
> >+_cs_vlan_tso,
> >+_type_vlan_len_msec);
> >+ret = hns3_set_l3l4_type_csum(skb, ol4_proto,
> il4_proto,
> >+  _cs_vlan_tso,
> >+  _type_vlan_len_msec);
> >+if (ret)
> >+return ret;
> >+
> >+ret = hns3_set_tso(skb, , ,
> >+   _cs_vlan_tso);
> >+if (ret)
> >+return ret;
> >+}
> >+
> >+/* Set txbd */
> >+desc->tx.ol_type_vlan_len_msec =
> >+cpu_to_le32(ol_type_vlan_len_msec);
> >+desc->tx.type_cs_vlan_tso_len =
> >+cpu_to_le32(type_cs_vlan_tso);
> >+desc->tx.paylen = cpu_to_le16(paylen);
> >+desc->tx.mss = cpu_to_le16(mss);
> >+}
> >+
> >+/* move ring pointer to next.*/
> >+ring_ptr_move_fw(ring, next_to_use);
> >+
> >+return 0;
> >+}
> >+
> >+static int hns3_fill_desc_tso(struct hns3_enet_ring *ring, void
> *priv,
> >+  int size, dma_addr_t dma, int frag_end,
> >+  enum hns_desc_type type)
> >+{
> >+int frag_buf_num;
> >+int sizeoflast;
> >+int ret, k;
> >+
> >+frag_buf_num = (size + HNS3_MAX_BD_SIZE - 1) / HNS3_MAX_BD_SIZE;
> >+sizeoflast = size % HNS3_MAX_BD_SIZE;
> >+sizeoflast = sizeoflast ? sizeoflast : HNS3_MAX_BD_SIZE;
> >+
> >+/* When the frag size is bigger than hardware, split this frag */
> >+for (k = 0; k < frag_buf_num; k++) {
> >+ret = hns3_fill_desc(ring, priv,
> >+ (k == frag_buf_num - 1) ?
> >+sizeoflast : HNS3_MAX_BD_SIZE,
> >+dma + HNS3_MAX_BD_SIZE * k,
> >+frag_end && (k == frag_buf_num - 1) ? 1 : 0,
> >+(type == DESC_TYPE_SKB && !k) ?
> >+DESC_TYPE_SKB : DESC_TYPE_PAGE);
> >+if (ret)
> >+return ret;
> >+}
> >+
> >+return 0;
> >+}
> >+
> >+static int hns3_nic_maybe_stop_tso(struct sk_buff **out_skb, int
> *bnum,
> >+   struct hns3_enet_ring *ring)
> >+{
> >+struct sk_buff *skb = *out_skb;
> >+struct skb_frag_struct *frag;
> >+int bdnum_for_frag;
> >+int frag_num;
> >+int buf_num;
> >+int size;
> >+int i;
> >+
> >+size = skb_headlen(skb);
> >+buf_num = (size + HNS3_MAX_BD_SIZE - 

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

2017-07-22 Thread Salil Mehta
Hi Andrew,
> -Original Message-
> From: Andrew Lunn [mailto:and...@lunn.ch]
> Sent: Sunday, June 18, 2017 4:02 PM
> To: Salil Mehta
> Cc: da...@davemloft.net; Zhuangyuzeng (Yisen); huangdaode; lipeng (Y);
> mehta.salil@gmail.com; netdev@vger.kernel.org; linux-
> ker...@vger.kernel.org; Linuxarm
> Subject: Re: [PATCH V3 net-next 2/8] net: hns3: Add support of the
> HNAE3 framework
> 
> > +static int __init hnae3_init(void)
> > +{
> > +   return 0;
> > +}
> > +
> > +static void __exit hnae3_exit(void)
> > +{
> > +}
> > +
> > +module_init(hnae3_init);
> > +module_exit(hnae3_exit);
> 
> I think init and exit functions are optional. Since your's don't do
> anything useful, please try without them.
Yes, you were right. Removed in V4 patch. 

Thanks
Salil
> 
>Andrew


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

2017-07-22 Thread Salil Mehta


> -Original Message-
> From: Andrew Lunn [mailto:and...@lunn.ch]
> Sent: Sunday, June 18, 2017 3:53 PM
> To: Salil Mehta
> Cc: da...@davemloft.net; Zhuangyuzeng (Yisen); huangdaode; lipeng (Y);
> mehta.salil@gmail.com; netdev@vger.kernel.org; linux-
> ker...@vger.kernel.org; Linuxarm
> Subject: Re: [PATCH V2 net-next 2/8] net: hns3: Add support of the
> HNAE3 framework
> 
> On Wed, Jun 14, 2017 at 12:10:29AM +0100, Salil Mehta wrote:
> > This patch adds the support of the HNAE3 (Hisilicon Network
> > Acceleration Engine 3) framework support to the HNS3 driver.
> >
> > Framework facilitates clients like ENET(HNS3 Ethernet Driver), RoCE
> > and user-space Ethernet drivers (like ODP etc.) to register with
> HNAE3
> > devices and their associated operations.
> 
> checkpatch throws out one warning in this file
> 
> CHECK: Comparison to NULL could be written "pos"
> #3508: FILE:
> drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.h:572:
> +  for (pos = (head).ring; pos != NULL; pos = pos->next)
> 
> This one seems valid. Not all checkpatch warnings are.
Agreed and fixed in V4 patch.

Thanks
Salil
> 
>  Andrew


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

2017-07-22 Thread Salil Mehta
Hi Andrew,

> -Original Message-
> From: Andrew Lunn [mailto:and...@lunn.ch]
> Sent: Saturday, June 17, 2017 8:46 PM
> To: Salil Mehta
> Cc: da...@davemloft.net; Zhuangyuzeng (Yisen); huangdaode; lipeng (Y);
> mehta.salil@gmail.com; netdev@vger.kernel.org; linux-
> ker...@vger.kernel.org; Linuxarm
> Subject: Re: [PATCH V3 net-next 2/8] net: hns3: Add support of the
> HNAE3 framework
> 
> > +static void hnae3_list_add(spinlock_t *lock, struct list_head *node,
> > +  struct list_head *head)
> > +{
> > +   unsigned long flags;
> > +
> > +   spin_lock_irqsave(lock, flags);
> > +   list_add_tail(node, head);
> > +   spin_unlock_irqrestore(lock, flags);
> > +}
> > +
> > +static void hnae3_list_del(spinlock_t *lock, struct list_head *node)
> > +{
> > +   unsigned long flags;
> > +
> > +   spin_lock_irqsave(lock, flags);
> > +   list_del(node);
> > +   spin_unlock_irqrestore(lock, flags);
> > +}
> > +
> 
> > +int hnae3_register_client(struct hnae3_client *client)
> > +{
> > +   struct hnae3_client *client_tmp;
> > +   struct hnae3_ae_dev *ae_dev;
> > +   int ret;
> > +
> > +   /* One system should only have one client for every type */
> > +   list_for_each_entry(client_tmp, _client_list, node) {
> > +   if (client_tmp->type == client->type)
> > +   return 0;
> > +   }
> > +
> > +   hnae3_list_add(_list_client_lock, >node,
> > +  _client_list);
> 
> Please could you explain your locking scheme. I don't get it.
> 
>Thanks
>   Andrew
Locking scheme has been fixed in the V4 patch. Please review it.

Thanks
Salil


[PATCH iproute2 master v2 0/2] Minor BPF updates

2017-07-22 Thread Daniel Borkmann
Two minor updates to the BPF code, first one makes use of the
recently exposed owner_jited in fdinfo to report whether a
load issue related to tail calls occured, and second one fixes
up custom mount of bpf fs when passed via env.

Thanks!

v1 -> v2:
  - Moved bpf_derive_prog_from_fdinfo() under HAVE_ELF.
  - Rest as is.

Daniel Borkmann (2):
  bpf: improve error reporting around tail calls
  bpf: fix mnt path when from env

 lib/bpf.c | 281 +++---
 1 file changed, 214 insertions(+), 67 deletions(-)

-- 
2.9.3



[PATCH iproute2 master v2 1/2] bpf: improve error reporting around tail calls

2017-07-22 Thread Daniel Borkmann
Currently, it's still quite hard to figure out if a prog passed the
verifier, but later gets rejected due to different tail call ownership.
Figure out whether that is the case and provide appropriate error
messages to the user.

Signed-off-by: Daniel Borkmann 
---
 lib/bpf.c | 226 ++
 1 file changed, 169 insertions(+), 57 deletions(-)

diff --git a/lib/bpf.c b/lib/bpf.c
index 7eb5cd9..5d9f0a5 100644
--- a/lib/bpf.c
+++ b/lib/bpf.c
@@ -344,15 +344,24 @@ static void bpf_map_pin_report(const struct bpf_elf_map 
*pin,
fprintf(stderr, "\n");
 }
 
-static int bpf_map_selfcheck_pinned(int fd, const struct bpf_elf_map *map,
-   int length, enum bpf_prog_type type)
+struct bpf_prog_data {
+   unsigned int type;
+   unsigned int jited;
+};
+
+struct bpf_map_ext {
+   struct bpf_prog_data owner;
+};
+
+static int bpf_derive_elf_map_from_fdinfo(int fd, struct bpf_elf_map *map,
+ struct bpf_map_ext *ext)
 {
+   unsigned int val, owner_type = 0, owner_jited = 0;
char file[PATH_MAX], buff[4096];
-   struct bpf_elf_map tmp = {}, zero = {};
-   unsigned int val, owner_type = 0;
FILE *fp;
 
snprintf(file, sizeof(file), "/proc/%d/fdinfo/%d", getpid(), fd);
+   memset(map, 0, sizeof(*map));
 
fp = fopen(file, "r");
if (!fp) {
@@ -362,27 +371,48 @@ static int bpf_map_selfcheck_pinned(int fd, const struct 
bpf_elf_map *map,
 
while (fgets(buff, sizeof(buff), fp)) {
if (sscanf(buff, "map_type:\t%u", ) == 1)
-   tmp.type = val;
+   map->type = val;
else if (sscanf(buff, "key_size:\t%u", ) == 1)
-   tmp.size_key = val;
+   map->size_key = val;
else if (sscanf(buff, "value_size:\t%u", ) == 1)
-   tmp.size_value = val;
+   map->size_value = val;
else if (sscanf(buff, "max_entries:\t%u", ) == 1)
-   tmp.max_elem = val;
+   map->max_elem = val;
else if (sscanf(buff, "map_flags:\t%i", ) == 1)
-   tmp.flags = val;
+   map->flags = val;
else if (sscanf(buff, "owner_prog_type:\t%i", ) == 1)
owner_type = val;
+   else if (sscanf(buff, "owner_jited:\t%i", ) == 1)
+   owner_jited = val;
}
 
fclose(fp);
+   if (ext) {
+   memset(ext, 0, sizeof(*ext));
+   ext->owner.type  = owner_type;
+   ext->owner.jited = owner_jited;
+   }
+
+   return 0;
+}
+
+static int bpf_map_selfcheck_pinned(int fd, const struct bpf_elf_map *map,
+   struct bpf_map_ext *ext, int length,
+   enum bpf_prog_type type)
+{
+   struct bpf_elf_map tmp, zero = {};
+   int ret;
+
+   ret = bpf_derive_elf_map_from_fdinfo(fd, , ext);
+   if (ret < 0)
+   return ret;
 
/* The decision to reject this is on kernel side eventually, but
 * at least give the user a chance to know what's wrong.
 */
-   if (owner_type && owner_type != type)
+   if (ext->owner.type && ext->owner.type != type)
fprintf(stderr, "Program array map owner types differ: %u (obj) 
!= %u (pin)\n",
-   type, owner_type);
+   type, ext->owner.type);
 
if (!memcmp(, map, length)) {
return 0;
@@ -882,6 +912,7 @@ int bpf_graft_map(const char *map_path, uint32_t *key, int 
argc, char **argv)
.argc   = argc,
.argv   = argv,
};
+   struct bpf_map_ext ext = {};
int ret, prog_fd, map_fd;
enum bpf_mode mode;
uint32_t map_key;
@@ -908,7 +939,7 @@ int bpf_graft_map(const char *map_path, uint32_t *key, int 
argc, char **argv)
goto out_prog;
}
 
-   ret = bpf_map_selfcheck_pinned(map_fd, ,
+   ret = bpf_map_selfcheck_pinned(map_fd, , ,
   offsetof(struct bpf_elf_map, max_elem),
   type);
if (ret < 0) {
@@ -981,7 +1012,12 @@ struct bpf_hash_entry {
struct bpf_hash_entry   *next;
 };
 
+struct bpf_config {
+   unsigned intjit_enabled;
+};
+
 struct bpf_elf_ctx {
+   struct bpf_config   cfg;
Elf *elf_fd;
GElf_Ehdr   elf_hdr;
Elf_Data*sym_tab;
@@ -989,6 +1025,7 @@ struct bpf_elf_ctx {
int obj_fd;
int map_fds[ELF_MAX_MAPS];
struct bpf_elf_map  maps[ELF_MAX_MAPS];
+   struct bpf_map_ext  maps_ext[ELF_MAX_MAPS];

[PATCH iproute2 master v2 2/2] bpf: fix mnt path when from env

2017-07-22 Thread Daniel Borkmann
When bpf fs mount path is from env, behavior is currently broken as
we continue to search in default paths, thus fix this up.

Signed-off-by: Daniel Borkmann 
---
 lib/bpf.c | 55 +--
 1 file changed, 45 insertions(+), 10 deletions(-)

diff --git a/lib/bpf.c b/lib/bpf.c
index 5d9f0a5..e7a4d12 100644
--- a/lib/bpf.c
+++ b/lib/bpf.c
@@ -459,6 +459,24 @@ static int bpf_mnt_fs(const char *target)
return 0;
 }
 
+static int bpf_mnt_check_target(const char *target)
+{
+   struct stat sb = {};
+   int ret;
+
+   ret = stat(target, );
+   if (ret) {
+   ret = mkdir(target, S_IRWXU);
+   if (ret) {
+   fprintf(stderr, "mkdir %s failed: %s\n", target,
+   strerror(errno));
+   return ret;
+   }
+   }
+
+   return 0;
+}
+
 static int bpf_valid_mntpt(const char *mnt, unsigned long magic)
 {
struct statfs st_fs;
@@ -471,6 +489,21 @@ static int bpf_valid_mntpt(const char *mnt, unsigned long 
magic)
return 0;
 }
 
+static const char *bpf_find_mntpt_single(unsigned long magic, char *mnt,
+int len, const char *mntpt)
+{
+   int ret;
+
+   ret = bpf_valid_mntpt(mntpt, magic);
+   if (!ret) {
+   strncpy(mnt, mntpt, len - 1);
+   mnt[len - 1] = 0;
+   return mnt;
+   }
+
+   return NULL;
+}
+
 static const char *bpf_find_mntpt(const char *fstype, unsigned long magic,
  char *mnt, int len,
  const char * const *known_mnts)
@@ -482,11 +515,8 @@ static const char *bpf_find_mntpt(const char *fstype, 
unsigned long magic,
if (known_mnts) {
ptr = known_mnts;
while (*ptr) {
-   if (bpf_valid_mntpt(*ptr, magic) == 0) {
-   strncpy(mnt, *ptr, len - 1);
-   mnt[len - 1] = 0;
+   if (bpf_find_mntpt_single(magic, mnt, len, *ptr))
return mnt;
-   }
ptr++;
}
}
@@ -664,6 +694,7 @@ static const char *bpf_get_work_dir(enum bpf_prog_type type)
static char bpf_wrk_dir[PATH_MAX];
static const char *mnt;
static bool bpf_mnt_cached;
+   const char *mnt_env = getenv(BPF_ENV_MNT);
static const char * const bpf_known_mnts[] = {
BPF_DIR_MNT,
"/bpf",
@@ -682,13 +713,17 @@ static const char *bpf_get_work_dir(enum bpf_prog_type 
type)
return out;
}
 
-   mnt = bpf_find_mntpt("bpf", BPF_FS_MAGIC, bpf_tmp, sizeof(bpf_tmp),
-bpf_known_mnts);
+   if (mnt_env)
+   mnt = bpf_find_mntpt_single(BPF_FS_MAGIC, bpf_tmp,
+   sizeof(bpf_tmp), mnt_env);
+   else
+   mnt = bpf_find_mntpt("bpf", BPF_FS_MAGIC, bpf_tmp,
+sizeof(bpf_tmp), bpf_known_mnts);
if (!mnt) {
-   mnt = getenv(BPF_ENV_MNT);
-   if (!mnt)
-   mnt = BPF_DIR_MNT;
-   ret = bpf_mnt_fs(mnt);
+   mnt = mnt_env ? : BPF_DIR_MNT;
+   ret = bpf_mnt_check_target(mnt);
+   if (!ret)
+   ret = bpf_mnt_fs(mnt);
if (ret) {
mnt = NULL;
goto out;
-- 
2.9.3



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

2017-07-22 Thread Salil Mehta
Hi Andrew

> -Original Message-
> From: Andrew Lunn [mailto:and...@lunn.ch]
> Sent: Saturday, June 17, 2017 6:54 PM
> To: Salil Mehta
> Cc: da...@davemloft.net; Zhuangyuzeng (Yisen); huangdaode; lipeng (Y);
> mehta.salil@gmail.com; netdev@vger.kernel.org; linux-
> ker...@vger.kernel.org; Linuxarm
> Subject: Re: [PATCH V3 net-next 1/8] net: hns3: Add support of HNS3
> Ethernet Driver for hip08 SoC
> 
> > +static int hns3_nic_net_up(struct net_device *ndev)
> > +{
> > +   struct hns3_nic_priv *priv = netdev_priv(ndev);
> > +   struct hnae3_handle *h = priv->ae_handle;
> > +   int i, j;
> > +   int ret;
> > +
> > +   ret = hns3_nic_init_irq(priv);
> > +   if (ret != 0) {
> 
>   if (ret)
> 
> No need to compare with zero.
Sure, changed in V4 patch. 

Thanks
Salil
> 
> > +   netdev_err(ndev, "hns init irq failed! ret=%d\n", ret);
> > +   return ret;
> 
> > +static int hns3_nic_net_open(struct net_device *ndev)
> > +{
> > +   struct hns3_nic_priv *priv = netdev_priv(ndev);
> > +   struct hnae3_handle *h = priv->ae_handle;
> > +   int ret;
> > +
> > +   netif_carrier_off(ndev);
> > +
> > +   ret = netif_set_real_num_tx_queues(ndev, h->kinfo.num_tqps);
> > +   if (ret < 0) {
> > +   netdev_err(ndev, "netif_set_real_num_tx_queues fail,
> ret=%d!\n",
> > +  ret);
> > +   return ret;
> > +   }
> 
> In general, functions return 0 for success, and something else for an
> error. So there is no need to do a comparison. Please remove all
> comparisons, unless it is really needed. It also makes the code look
> consistent. At the moment you sometime have < 0, sometime !=0, and
> sometimes no comparison at all.
Acknowledged, scanned and have changed in V4 patch. Please have a look.

Thanks
Salil
> 
> Andrew



[PATCH] ip route: replace exits with returns

2017-07-22 Thread elie
From: Élie Bouttier 

This patch replaces exits with returns in ip route
commands.

Allows to continue when invoked with ip -batch.

Signed-off-by: Élie Bouttier 
---
 ip/iproute.c | 47 ++-
 1 file changed, 26 insertions(+), 21 deletions(-)

diff --git a/ip/iproute.c b/ip/iproute.c
index a735d281..cb695ad4 100644
--- a/ip/iproute.c
+++ b/ip/iproute.c
@@ -137,7 +137,7 @@ static int flush_update(void)
 {
if (rtnl_send_check(, filter.flushb, filter.flushp) < 0) {
perror("Failed to send flush request");
-   return -1;
+   return -2;
}
filter.flushp = 0;
return 0;
@@ -319,6 +319,7 @@ int print_route(const struct sockaddr_nl *who, struct 
nlmsghdr *n, void *arg)
struct rtattr *tb[RTA_MAX+1];
int host_len, family;
__u32 table;
+   int ret;
 
SPRINT_BUF(b1);
static int hz;
@@ -348,8 +349,8 @@ int print_route(const struct sockaddr_nl *who, struct 
nlmsghdr *n, void *arg)
struct nlmsghdr *fn;
 
if (NLMSG_ALIGN(filter.flushp) + n->nlmsg_len > filter.flushe) {
-   if (flush_update())
-   return -1;
+   if ((ret = flush_update()) < 0)
+   return ret;
}
fn = (struct nlmsghdr *)(filter.flushb + 
NLMSG_ALIGN(filter.flushp));
memcpy(fn, n, n->nlmsg_len);
@@ -764,7 +765,7 @@ static int parse_one_nh(struct nlmsghdr *n, struct rtmsg *r,
NEXT_ARG();
if ((rtnh->rtnh_ifindex = ll_name_to_index(*argv)) == 
0) {
fprintf(stderr, "Cannot find device \"%s\"\n", 
*argv);
-   exit(1);
+   return -1;
}
} else if (strcmp(*argv, "weight") == 0) {
unsigned int w;
@@ -1396,6 +1397,7 @@ static int iproute_list_flush_or_save(int argc, char 
**argv, int action)
char *od = NULL;
unsigned int mark = 0;
rtnl_filter_t filter_fn;
+   int ret;
 
if (action == IPROUTE_SAVE) {
if (save_route_prep())
@@ -1604,12 +1606,12 @@ static int iproute_list_flush_or_save(int argc, char 
**argv, int action)
for (;;) {
if (rtnl_wilddump_request(, do_ipv6, RTM_GETROUTE) 
< 0) {
perror("Cannot send dump request");
-   exit(1);
+   return -2;
}
filter.flushed = 0;
if (rtnl_dump_filter(, filter_fn, stdout) < 0) {
fprintf(stderr, "Flush terminated\n");
-   exit(1);
+   return -2;
}
if (filter.flushed == 0) {
if (show_stats) {
@@ -1622,13 +1624,13 @@ static int iproute_list_flush_or_save(int argc, char 
**argv, int action)
return 0;
}
round++;
-   if (flush_update() < 0)
-   exit(1);
+   if ((ret = flush_update()) < 0)
+   return ret;
 
if (time(0) - start > 30) {
printf("\n*** Flush not completed after %ld 
seconds, %d entries remain ***\n",
   (long)(time(0) - start), filter.flushed);
-   exit(1);
+   return -1;
}
 
if (show_stats) {
@@ -1641,21 +1643,21 @@ static int iproute_list_flush_or_save(int argc, char 
**argv, int action)
if (!filter.cloned) {
if (rtnl_wilddump_request(, do_ipv6, RTM_GETROUTE) < 0) {
perror("Cannot send dump request");
-   exit(1);
+   return -2;
}
} else {
if (rtnl_rtcache_request(, do_ipv6) < 0) {
perror("Cannot send dump request");
-   exit(1);
+   return -2;
}
}
 
if (rtnl_dump_filter(, filter_fn, stdout) < 0) {
fprintf(stderr, "Dump terminated\n");
-   exit(1);
+   return -2;
}
 
-   exit(0);
+   return 0;
 }
 
 
@@ -1761,7 +1763,7 @@ static int iproute_get(int argc, char **argv)
 
if (req.r.rtm_dst_len == 0) {
fprintf(stderr, "need at least a destination address\n");
-   exit(1);
+   return -1;
}
 
if (idev || odev)  {
@@ -1918,12 +1920,12 @@ static int 

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

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

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

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

High Level Architecture:

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


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

Change Log:
V3->V4: Addressed below comments:
* Andrew Lunn: Various comments on MDIO, ethtool, ENET driver etc,
* Stephen Hemminger: change access and updation to 64 but statistics
* Bo You: some spelling mistakes and checkpatch.pl errors.
V2->V3: Addressed comments
* Yuval Mintz: Removal of redundant userprio-to-tc code
* Stephen Hemminger: Ethtool & interuupt enable
* Andrew Lunn: On C45/C22 PHy support, HNAE, ethtool
* Florian Fainelli: C45/C22 and phy_connect/attach
* Intel kbuild errors
V1->V2: Addressed some comments by kbuild, Yuval MIntz, Andrew Lunn &
Florian Fainelli in the following patches:
* Add support of HNS3 Ethernet Driver for hip08 SoC
* Add MDIO support to HNS3 Ethernet driver for hip08 SoC
* Add support of debugfs interface to HNS3 driver

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

 MAINTAINERS|8 +
 drivers/net/ethernet/hisilicon/Kconfig |   27 +
 drivers/net/ethernet/hisilicon/Makefile|1 +
 drivers/net/ethernet/hisilicon/hns3/Makefile   |7 +
 drivers/net/ethernet/hisilicon/hns3/hnae3.c|  319 ++
 drivers/net/ethernet/hisilicon/hns3/hnae3.h|  449 +++
 .../net/ethernet/hisilicon/hns3/hns3pf/Makefile|   11 +
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.c |  347 ++
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h |  742 
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.c| 4240 
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.h|  494 +++
 .../ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c|  230 ++
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.c  | 1018 +
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.h  |  108 +
 .../net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.c | 2894 +
 .../net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.h |  598 +++
 .../ethernet/hisilicon/hns3/hns3pf/hns3_ethtool.c  |  543 +++
 17 files changed, 12036 insertions(+)
 create mode 100644 drivers/net/ethernet/hisilicon/hns3/Makefile
 create mode 100644 drivers/net/ethernet/hisilicon/hns3/hnae3.c
 create mode 100644 drivers/net/ethernet/hisilicon/hns3/hnae3.h
 create mode 100644 

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

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

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

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

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

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.c
new file mode 100644
index ..ec20ec4a5939
--- /dev/null
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.c
@@ -0,0 +1,347 @@
+/*
+ * Copyright (c) 2016~2017 Hisilicon Limited.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "hclge_cmd.h"
+#include "hnae3.h"
+#include "hclge_main.h"
+
+#define hclge_is_csq(ring) ((ring)->flag & HCLGE_TYPE_CSQ)
+#define hclge_ring_to_dma_dir(ring) (hclge_is_csq(ring) ? \
+   DMA_TO_DEVICE : DMA_FROM_DEVICE)
+#define cmq_ring_to_dev(ring)   (&(ring)->dev->pdev->dev)
+
+static int hclge_ring_space(struct hclge_cmq_ring *ring)
+{
+   int ntu = ring->next_to_use;
+   int ntc = ring->next_to_clean;
+   int used = (ntu - ntc + ring->desc_num) % ring->desc_num;
+
+   return ring->desc_num - used - 1;
+}
+
+static int hclge_alloc_cmd_desc(struct hclge_cmq_ring *ring)
+{
+   int size  = ring->desc_num * sizeof(struct hclge_desc);
+
+   ring->desc = kzalloc(size, GFP_KERNEL);
+   if (!ring->desc)
+   return -ENOMEM;
+
+   ring->desc_dma_addr = dma_map_single(cmq_ring_to_dev(ring), ring->desc,
+size, DMA_BIDIRECTIONAL);
+   if (dma_mapping_error(cmq_ring_to_dev(ring), ring->desc_dma_addr)) {
+   ring->desc_dma_addr = 0;
+   kfree(ring->desc);
+   ring->desc = NULL;
+   return -ENOMEM;
+   }
+
+   return 0;
+}
+
+static void hclge_free_cmd_desc(struct hclge_cmq_ring *ring)
+{
+   dma_unmap_single(cmq_ring_to_dev(ring), ring->desc_dma_addr,
+ring->desc_num * sizeof(ring->desc[0]),
+DMA_BIDIRECTIONAL);
+
+   ring->desc_dma_addr = 0;
+   kfree(ring->desc);
+   ring->desc = NULL;
+}
+
+static int hclge_init_cmd_queue(struct hclge_dev *hdev, int ring_type)
+{
+   struct hclge_hw *hw = >hw;
+   struct hclge_cmq_ring *ring =
+   (ring_type == HCLGE_TYPE_CSQ) ? >cmq.csq : >cmq.crq;
+   int ret;
+
+   ring->flag = ring_type;
+   ring->dev = hdev;
+
+   ret = hclge_alloc_cmd_desc(ring);
+   if (ret) {
+   dev_err(>pdev->dev, "descriptor %s alloc error %d\n",
+   (ring_type == HCLGE_TYPE_CSQ) ? "CSQ" : "CRQ", ret);
+   return ret;
+   }
+
+   ring->next_to_clean = 0;
+   ring->next_to_use = 0;
+
+   return 0;
+}
+
+void hclge_cmd_reuse_desc(struct hclge_desc *desc, bool is_read)
+{
+   desc->flag = cpu_to_le16(HCLGE_CMD_FLAG_NO_INTR | HCLGE_CMD_FLAG_IN);
+   if (is_read)
+   desc->flag |= cpu_to_le16(HCLGE_CMD_FLAG_WR);
+   else
+   desc->flag &= cpu_to_le16(~HCLGE_CMD_FLAG_WR);
+}
+
+void hclge_cmd_setup_basic_desc(struct hclge_desc *desc,
+   enum hclge_opcode_type opcode, bool is_read)
+{
+   memset((void *)desc, 0, sizeof(struct hclge_desc));
+   desc->opcode = cpu_to_le16(opcode);
+   desc->flag = cpu_to_le16(HCLGE_CMD_FLAG_NO_INTR | HCLGE_CMD_FLAG_IN);
+
+   if (is_read)
+   desc->flag |= cpu_to_le16(HCLGE_CMD_FLAG_WR);
+   else
+   desc->flag &= cpu_to_le16(~HCLGE_CMD_FLAG_WR);
+}
+
+static void hclge_cmd_config_regs(struct hclge_cmq_ring *ring)
+{
+   dma_addr_t dma = ring->desc_dma_addr;
+   struct hclge_dev *hdev = ring->dev;
+   struct hclge_hw *hw = >hw;
+
+   if (ring->flag == 

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

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

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

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

Signed-off-by: Daode Huang 
Signed-off-by: lipeng 
Signed-off-by: Salil Mehta 
Signed-off-by: Yisen Zhuang 
---
Patch V4: addressed comments by:
  1. Andrew Lunn:
 https://lkml.org/lkml/2017/6/17/222
 https://lkml.org/lkml/2017/6/17/232
  2. Bo Yu:
 https://lkml.org/lkml/2017/6/18/110
 https://lkml.org/lkml/2017/6/18/115
Patch V3: Addresed below comments:
  1. Stephen Hemminger:
 https://lkml.org/lkml/2017/6/13/972
  2. Yuval Mintz:
 https://lkml.org/lkml/2017/6/14/151
Patch V2: Addressed below comments:
  1. Kbuild:
 https://lkml.org/lkml/2017/6/11/73
  2. Yuval Mintz:
 https://lkml.org/lkml/2017/6/10/78
Patch V1: Initial Submit
---
 .../net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.c | 2894 
 .../net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.h |  598 
 2 files changed, 3492 insertions(+)
 create mode 100644 drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.c
 create mode 100644 drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.h

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.c
new file mode 100644
index ..6e0e2967db42
--- /dev/null
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.c
@@ -0,0 +1,2894 @@
+/*
+ * Copyright (c) 2016~2017 Hisilicon Limited.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "hnae3.h"
+#include "hns3_enet.h"
+
+const char hns3_driver_name[] = "hns3";
+static const char hns3_driver_string[] =
+   "Hisilicon Ethernet Network Driver for Hi162x Family";
+static const char hns3_copyright[] = "Copyright (c) 2017 Huawei Corporation.";
+static struct hnae3_client client;
+
+/* hns3_pci_tbl - PCI Device ID Table
+ *
+ * Last entry must be all 0s
+ *
+ * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
+ *   Class, Class Mask, private data (not used) }
+ */
+static const struct pci_device_id hns3_pci_tbl[] = {
+   {PCI_VDEVICE(HUAWEI, HNAE3_DEV_ID_GE), 0},
+   {PCI_VDEVICE(HUAWEI, HNAE3_DEV_ID_25GE), 0},
+   {PCI_VDEVICE(HUAWEI, HNAE3_DEV_ID_25GE_RDMA), 0},
+   {PCI_VDEVICE(HUAWEI, HNAE3_DEV_ID_25GE_RDMA_MACSEC), 0},
+   {PCI_VDEVICE(HUAWEI, HNAE3_DEV_ID_50GE_RDMA), 0},
+   {PCI_VDEVICE(HUAWEI, HNAE3_DEV_ID_50GE_RDMA_MACSEC), 0},
+   {PCI_VDEVICE(HUAWEI, HNAE3_DEV_ID_100G_RDMA_MACSEC), 0},
+   /* required last entry */
+   {0, }
+};
+MODULE_DEVICE_TABLE(pci, hns3_pci_tbl);
+
+static irqreturn_t hns3_irq_handle(int irq, void *dev)
+{
+   struct hns3_enet_tqp_vector *tqp_vector = dev;
+
+   napi_schedule(_vector->napi);
+
+   return IRQ_HANDLED;
+}
+
+static int hns3_nic_init_irq(struct hns3_nic_priv *priv)
+{
+   struct pci_dev *pdev = priv->ae_handle->pdev;
+   struct hns3_enet_tqp_vector *tqp_vectors;
+   int txrx_int_idx = 0;
+   int rx_int_idx = 0;
+   int tx_int_idx = 0;
+   int ret;
+   int i;
+
+   for (i = 0; i < priv->vector_num; i++) {
+   tqp_vectors = >tqp_vector[i];
+
+   if (tqp_vectors->irq_init_flag == HNS3_VECTOR_INITED)
+   continue;
+
+   if (tqp_vectors->tx_group.ring && tqp_vectors->rx_group.ring) {
+   snprintf(tqp_vectors->name, HNAE3_INT_NAME_LEN - 1,
+"%s-%s-%d", priv->netdev->name, "TxRx",
+txrx_int_idx++);
+   txrx_int_idx++;
+   } else if (tqp_vectors->rx_group.ring) {
+   snprintf(tqp_vectors->name, HNAE3_INT_NAME_LEN - 1,
+"%s-%s-%d", priv->netdev->name, "Rx",
+rx_int_idx++);
+   } else if (tqp_vectors->tx_group.ring) {
+   snprintf(tqp_vectors->name, HNAE3_INT_NAME_LEN - 1,
+"%s-%s-%d", priv->netdev->name, "Tx",
+tx_int_idx++);
+   } else {
+   /* Skip this unused q_vector */
+   continue;
+   }
+
+   tqp_vectors->name[HNAE3_INT_NAME_LEN - 1] = '\0';
+
+   

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

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

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

Signed-off-by: Daode Huang 
Signed-off-by: lipeng 
Signed-off-by: Salil Mehta 
Signed-off-by: Yisen Zhuang 
---
Patch V4: Addressed following comments
  1. Andrew Lunn:
 https://lkml.org/lkml/2017/6/17/233
 https://lkml.org/lkml/2017/6/18/105
  2. Bo Yu:
 https://lkml.org/lkml/2017/6/18/112
  3. Stephen Hamminger:
 https://lkml.org/lkml/2017/6/19/778
Patch V3: Addressed below comments
  1. Andrew Lunn:
 https://lkml.org/lkml/2017/6/13/1025
Patch V2: No change
Patch V1: Initial Submit
---
 drivers/net/ethernet/hisilicon/hns3/hnae3.c | 319 
 drivers/net/ethernet/hisilicon/hns3/hnae3.h | 449 
 2 files changed, 768 insertions(+)
 create mode 100644 drivers/net/ethernet/hisilicon/hns3/hnae3.c
 create mode 100644 drivers/net/ethernet/hisilicon/hns3/hnae3.h

diff --git a/drivers/net/ethernet/hisilicon/hns3/hnae3.c 
b/drivers/net/ethernet/hisilicon/hns3/hnae3.c
new file mode 100644
index ..7a11aaff0a23
--- /dev/null
+++ b/drivers/net/ethernet/hisilicon/hns3/hnae3.c
@@ -0,0 +1,319 @@
+/*
+ * Copyright (c) 2016-2017 Hisilicon Limited.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+#include 
+#include 
+#include 
+
+#include "hnae3.h"
+
+static LIST_HEAD(hnae3_ae_algo_list);
+static LIST_HEAD(hnae3_client_list);
+static LIST_HEAD(hnae3_ae_dev_list);
+
+/* we are keeping things simple and using single lock for all the
+ * list. This is a non-critical code so other updations, if happen
+ * in parallel, can wait.
+ */
+static DEFINE_MUTEX(hnae3_common_lock);
+
+static bool hnae3_client_match(enum hnae3_client_type client_type,
+  enum hnae3_dev_type dev_type)
+{
+   if (dev_type == HNAE3_DEV_KNIC) {
+   switch (client_type) {
+   case HNAE3_CLIENT_KNIC:
+   case HNAE3_CLIENT_ROCE:
+   return true;
+   default:
+   return false;
+   }
+   } else if (dev_type == HNAE3_DEV_UNIC) {
+   switch (client_type) {
+   case HNAE3_CLIENT_UNIC:
+   return true;
+   default:
+   return false;
+   }
+   } else {
+   return false;
+   }
+}
+
+static int hnae3_match_n_instantiate(struct hnae3_client *client,
+struct hnae3_ae_dev *ae_dev,
+bool is_reg, bool *matched)
+{
+   int ret;
+
+   *matched = false;
+
+   /* check if this client matches the type of ae_dev */
+   if (!(hnae3_client_match(client->type, ae_dev->dev_type) &&
+ hnae_get_bit(ae_dev->flag, HNAE3_DEV_INITED_B))) {
+   return 0;
+   }
+   /* there is a match of client and dev */
+   *matched = true;
+
+   if (!(ae_dev->ops && ae_dev->ops->init_client_instance &&
+ ae_dev->ops->uninit_client_instance)) {
+   dev_err(_dev->pdev->dev,
+   "ae_dev or client init/uninit ops are null\n");
+   return -EOPNOTSUPP;
+   }
+
+   /* now, (un-)instantiate client by calling lower layer */
+   if (is_reg) {
+   ret = ae_dev->ops->init_client_instance(client, ae_dev);
+   if (ret)
+   dev_err(_dev->pdev->dev,
+   "fail to instantiate client\n");
+   return ret;
+   }
+
+   ae_dev->ops->uninit_client_instance(client, ae_dev);
+   return 0;
+}
+
+int hnae3_register_client(struct hnae3_client *client)
+{
+   struct hnae3_client *client_tmp;
+   struct hnae3_ae_dev *ae_dev;
+   bool matched;
+   int ret = 0;
+
+   mutex_lock(_common_lock);
+   /* one system should only have one client for every type */
+   list_for_each_entry(client_tmp, _client_list, node) {
+   if (client_tmp->type == client->type)
+   goto exit;
+   }
+
+   list_add_tail(>node, _client_list);
+
+   /* initialize the client on every matched port */
+   list_for_each_entry(ae_dev, _ae_dev_list, node) {
+   /* if the client could not be initialized on current port, for
+* any error reasons, move on to next available port
+*/
+   ret = hnae3_match_n_instantiate(client, ae_dev, true, 

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

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

Signed-off-by: Daode Huang 
Signed-off-by: lipeng 
Signed-off-by: Salil Mehta 
Signed-off-by: Yisen Zhuang 
---
Patch V4:
 1. removed register_client/unregister_client wrapper functions
 2. name inconsistencies, changed variable name from phy_dev->phydev
at some places
Patch V1: Initial Submit
---
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.c| 4240 
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.h|  494 +++
 2 files changed, 4734 insertions(+)
 create mode 100644 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
 create mode 100644 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
new file mode 100644
index ..fb28511ad4a1
--- /dev/null
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -0,0 +1,4240 @@
+/*
+ * Copyright (c) 2016-2017 Hisilicon Limited.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "hclge_cmd.h"
+#include "hclge_main.h"
+#include "hclge_tm.h"
+#include "hnae3.h"
+
+#define HCLGE_NAME "hclge"
+#define HCLGE_STATS_READ(p, offset) (*((u64 *)((u8 *)(p) + (offset
+#define HCLGE_MAC_STATS_FIELD_OFF(f) (offsetof(struct hclge_mac_stats, f))
+#define HCLGE_64BIT_STATS_FIELD_OFF(f) (offsetof(struct hclge_64_bit_stats, f))
+#define HCLGE_32BIT_STATS_FIELD_OFF(f) (offsetof(struct hclge_32_bit_stats, f))
+
+static int hclge_rss_init_hw(struct hclge_dev *hdev);
+static int hclge_set_mta_filter_mode(struct hclge_dev *hdev,
+enum hclge_mta_dmac_sel_type mta_mac_sel,
+bool enable);
+static int hclge_init_vlan_config(struct hclge_dev *hdev);
+
+struct hnae3_ae_algo ae_algo;
+
+static const struct pci_device_id ae_algo_pci_tbl[] = {
+   {PCI_VDEVICE(HUAWEI, HNAE3_DEV_ID_GE), 0},
+   {PCI_VDEVICE(HUAWEI, HNAE3_DEV_ID_25GE), 0},
+   {PCI_VDEVICE(HUAWEI, HNAE3_DEV_ID_25GE_RDMA), 0},
+   {PCI_VDEVICE(HUAWEI, HNAE3_DEV_ID_25GE_RDMA_MACSEC), 0},
+   {PCI_VDEVICE(HUAWEI, HNAE3_DEV_ID_50GE_RDMA), 0},
+   {PCI_VDEVICE(HUAWEI, HNAE3_DEV_ID_50GE_RDMA_MACSEC), 0},
+   {PCI_VDEVICE(HUAWEI, HNAE3_DEV_ID_100G_RDMA_MACSEC), 0},
+   /* Required last entry */
+   {0, }
+};
+
+static const struct pci_device_id roce_pci_tbl[] = {
+   {PCI_VDEVICE(HUAWEI, HNAE3_DEV_ID_25GE_RDMA), 0},
+   {PCI_VDEVICE(HUAWEI, HNAE3_DEV_ID_25GE_RDMA_MACSEC), 0},
+   {PCI_VDEVICE(HUAWEI, HNAE3_DEV_ID_50GE_RDMA), 0},
+   {PCI_VDEVICE(HUAWEI, HNAE3_DEV_ID_50GE_RDMA_MACSEC), 0},
+   {PCI_VDEVICE(HUAWEI, HNAE3_DEV_ID_100G_RDMA_MACSEC), 0},
+   /* Required last entry */
+   {0, }
+};
+
+static const char hns3_nic_test_strs[][ETH_GSTRING_LEN] = {
+   "MacLoopback test",
+   "Serdes Loopback test",
+   "PhyLoopback test"
+};
+
+static const struct hclge_comm_stats_str g_all_64bit_stats_string[] = {
+   {"igu_rx_oversize_pkt",
+   HCLGE_64BIT_STATS_FIELD_OFF(igu_rx_oversize_pkt)},
+   {"igu_rx_undersize_pkt",
+   HCLGE_64BIT_STATS_FIELD_OFF(igu_rx_undersize_pkt)},
+   {"igu_rx_out_all_pkt",
+   HCLGE_64BIT_STATS_FIELD_OFF(igu_rx_out_all_pkt)},
+   {"igu_rx_uni_pkt",
+   HCLGE_64BIT_STATS_FIELD_OFF(igu_rx_uni_pkt)},
+   {"igu_rx_multi_pkt",
+   HCLGE_64BIT_STATS_FIELD_OFF(igu_rx_multi_pkt)},
+   {"igu_rx_broad_pkt",
+   HCLGE_64BIT_STATS_FIELD_OFF(igu_rx_broad_pkt)},
+   {"egu_tx_out_all_pkt",
+   HCLGE_64BIT_STATS_FIELD_OFF(egu_tx_out_all_pkt)},
+   {"egu_tx_uni_pkt",
+   HCLGE_64BIT_STATS_FIELD_OFF(egu_tx_uni_pkt)},
+   {"egu_tx_multi_pkt",
+   HCLGE_64BIT_STATS_FIELD_OFF(egu_tx_multi_pkt)},
+   {"egu_tx_broad_pkt",
+   HCLGE_64BIT_STATS_FIELD_OFF(egu_tx_broad_pkt)},
+   {"ssu_ppp_mac_key_num",
+   HCLGE_64BIT_STATS_FIELD_OFF(ssu_ppp_mac_key_num)},
+   {"ssu_ppp_host_key_num",
+   HCLGE_64BIT_STATS_FIELD_OFF(ssu_ppp_host_key_num)},
+   {"ppp_ssu_mac_rlt_num",
+   

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

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

Signed-off-by: Daode Huang 
Signed-off-by: lipeng 
Signed-off-by: Salil Mehta 
Signed-off-by: Yisen Zhuang 
---
Patch V4: Addressed following comments:
 1. Andrew Lunn:
https://lkml.org/lkml/2017/6/17/208
Patch V3: Addressed Below comments:
 1. Florian Fainelli:
https://lkml.org/lkml/2017/6/13/963
 2. Andrew Lunn:
https://lkml.org/lkml/2017/6/13/1039
Patch V2: Addressed below comments:
 1. Florian Fainelli:
https://lkml.org/lkml/2017/6/10/130
 2. Andrew Lunn:
https://lkml.org/lkml/2017/6/10/168
Patch V1: Initial Submit
---
 .../ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c| 230 +
 1 file changed, 230 insertions(+)
 create mode 100644 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c
new file mode 100644
index ..6036a97f7de5
--- /dev/null
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c
@@ -0,0 +1,230 @@
+/*
+ * Copyright (c) 2016~2017 Hisilicon Limited.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+#include 
+#include 
+
+#include "hclge_cmd.h"
+#include "hclge_main.h"
+
+enum hclge_mdio_c22_op_seq {
+   HCLGE_MDIO_C22_WRITE = 1,
+   HCLGE_MDIO_C22_READ = 2
+};
+
+#define HCLGE_MDIO_CTRL_START_B0
+#define HCLGE_MDIO_CTRL_ST_S   1
+#define HCLGE_MDIO_CTRL_ST_M   (0x3 << HCLGE_MDIO_CTRL_ST_S)
+#define HCLGE_MDIO_CTRL_OP_S   3
+#define HCLGE_MDIO_CTRL_OP_M   (0x3 << HCLGE_MDIO_CTRL_OP_S)
+
+#define HCLGE_MDIO_PHYID_S 0
+#define HCLGE_MDIO_PHYID_M (0x1f << HCLGE_MDIO_PHYID_S)
+
+#define HCLGE_MDIO_PHYREG_S0
+#define HCLGE_MDIO_PHYREG_M(0x1f << HCLGE_MDIO_PHYREG_S)
+
+#define HCLGE_MDIO_STA_B   0
+
+struct hclge_mdio_cfg_cmd {
+   u8 ctrl_bit;
+   u8 phyid;
+   u8 phyad;
+   u8 rsvd;
+   __le16 reserve;
+   __le16 data_wr;
+   __le16 data_rd;
+   __le16 sta;
+};
+
+static int hclge_mdio_write(struct mii_bus *bus, int phyid, int regnum,
+   u16 data)
+{
+   struct hclge_dev *hdev = (struct hclge_dev *)bus->priv;
+   struct hclge_mdio_cfg_cmd *mdio_cmd;
+   enum hclge_cmd_status status;
+   struct hclge_desc desc;
+
+   if (!bus)
+   return -EINVAL;
+
+   hclge_cmd_setup_basic_desc(, HCLGE_OPC_MDIO_CONFIG, false);
+
+   mdio_cmd = (struct hclge_mdio_cfg_cmd *)desc.data;
+
+   hnae_set_field(mdio_cmd->phyid, HCLGE_MDIO_PHYID_M,
+  HCLGE_MDIO_PHYID_S, phyid);
+   hnae_set_field(mdio_cmd->phyad, HCLGE_MDIO_PHYREG_M,
+  HCLGE_MDIO_PHYREG_S, regnum);
+
+   hnae_set_bit(mdio_cmd->ctrl_bit, HCLGE_MDIO_CTRL_START_B, 1);
+   hnae_set_field(mdio_cmd->ctrl_bit, HCLGE_MDIO_CTRL_ST_M,
+  HCLGE_MDIO_CTRL_ST_S, 1);
+   hnae_set_field(mdio_cmd->ctrl_bit, HCLGE_MDIO_CTRL_OP_M,
+  HCLGE_MDIO_CTRL_OP_S, HCLGE_MDIO_C22_WRITE);
+
+   mdio_cmd->data_wr = cpu_to_le16(data);
+
+   status = hclge_cmd_send(>hw, , 1);
+   if (status) {
+   dev_err(>pdev->dev,
+   "mdio write fail when sending cmd, status is %d.\n",
+   status);
+   return -EIO;
+   }
+
+   return 0;
+}
+
+static int hclge_mdio_read(struct mii_bus *bus, int phyid, int regnum)
+{
+   struct hclge_dev *hdev = (struct hclge_dev *)bus->priv;
+   struct hclge_mdio_cfg_cmd *mdio_cmd;
+   enum hclge_cmd_status status;
+   struct hclge_desc desc;
+
+   if (!bus)
+   return -EINVAL;
+
+   hclge_cmd_setup_basic_desc(, HCLGE_OPC_MDIO_CONFIG, true);
+
+   mdio_cmd = (struct hclge_mdio_cfg_cmd *)desc.data;
+
+   hnae_set_field(mdio_cmd->phyid, HCLGE_MDIO_PHYID_M,
+  HCLGE_MDIO_PHYID_S, phyid);
+   hnae_set_field(mdio_cmd->phyad, HCLGE_MDIO_PHYREG_M,
+  HCLGE_MDIO_PHYREG_S, regnum);
+
+   hnae_set_bit(mdio_cmd->ctrl_bit, HCLGE_MDIO_CTRL_START_B, 1);
+   hnae_set_field(mdio_cmd->ctrl_bit, HCLGE_MDIO_CTRL_ST_M,
+  HCLGE_MDIO_CTRL_ST_S, 1);
+   hnae_set_field(mdio_cmd->ctrl_bit, HCLGE_MDIO_CTRL_OP_M,
+  HCLGE_MDIO_CTRL_OP_S, HCLGE_MDIO_C22_READ);
+
+   /* Read out phy data */
+   status = hclge_cmd_send(>hw, , 1);
+   if (status) {
+   dev_err(>pdev->dev,
+ 

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

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

Signed-off-by: Salil Mehta 
---
Patch V3: Addressed below errors:
 1. Intel kbuild: https://lkml.org/lkml/2017/6/14/313
 2. Intel Kbuild: https://lkml.org/lkml/2017/6/14/636
Patch V2: No change
Patch V1: Initial Submit
---
 MAINTAINERS|  8 +++
 drivers/net/ethernet/hisilicon/Kconfig | 27 ++
 drivers/net/ethernet/hisilicon/Makefile|  1 +
 drivers/net/ethernet/hisilicon/hns3/Makefile   |  7 ++
 .../net/ethernet/hisilicon/hns3/hns3pf/Makefile| 11 +
 5 files changed, 54 insertions(+)
 create mode 100644 drivers/net/ethernet/hisilicon/hns3/Makefile
 create mode 100644 drivers/net/ethernet/hisilicon/hns3/hns3pf/Makefile

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




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

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

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

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

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.c
new file mode 100644
index ..2b66a0e63aec
--- /dev/null
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.c
@@ -0,0 +1,1018 @@
+/*
+ * Copyright (c) 2016~2017 Hisilicon Limited.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+#include 
+
+#include "hclge_cmd.h"
+#include "hclge_main.h"
+#include "hclge_tm.h"
+
+enum hclge_shaper_level {
+   HCLGE_SHAPER_LVL_PRI= 0,
+   HCLGE_SHAPER_LVL_PG = 1,
+   HCLGE_SHAPER_LVL_PORT   = 2,
+   HCLGE_SHAPER_LVL_QSET   = 3,
+   HCLGE_SHAPER_LVL_CNT= 4,
+   HCLGE_SHAPER_LVL_VF = 0,
+   HCLGE_SHAPER_LVL_PF = 1,
+};
+
+#define HCLGE_SHAPER_BS_U_DEF  1
+#define HCLGE_SHAPER_BS_S_DEF  4
+
+#define HCLGE_ETHER_MAX_RATE   10
+
+/* hclge_shaper_para_calc: calculate ir parameter for the shaper
+ * @ir: Rate to be config, its unit is Mbps
+ * @shaper_level: the shaper level. eg: port, pg, priority, queueset
+ * @ir_b: IR_B parameter of IR shaper
+ * @ir_u: IR_U parameter of IR shaper
+ * @ir_s: IR_S parameter of IR shaper
+ *
+ * the formula:
+ *
+ * IR_b * (2 ^ IR_u) * 8
+ * IR(Mbps) = -  *  CLOCK(1000Mbps)
+ * Tick * (2 ^ IR_s)
+ *
+ * @return: 0: calculate sucessful, negative: fail
+ */
+static int hclge_shaper_para_calc(u32 ir, u8 shaper_level,
+ u8 *ir_b, u8 *ir_u, u8 *ir_s)
+{
+   const u16 tick_array[HCLGE_SHAPER_LVL_CNT] = {
+   6 * 256,/* Prioriy level */
+   6 * 32, /* Prioriy group level */
+   6 * 8,  /* Port level */
+   6 * 256 /* Qset level */
+   };
+   u8 ir_u_calc = 0, ir_s_calc = 0;
+   u32 ir_calc;
+   u32 tick;
+
+   /* Calc tick */
+   if (shaper_level >= HCLGE_SHAPER_LVL_CNT)
+   return -ENOMEM;
+
+   tick = tick_array[shaper_level];
+
+   /**
+* Calc the speed if ir_b = 126, ir_u = 0 and ir_s = 0
+* the formula is changed to:
+*  126 * 1 * 8
+* ir_calc =  * 1000
+*  tick * 1
+*/
+   ir_calc = (1008000 + (tick >> 1) - 1) / tick;
+
+   if (ir_calc == ir) {
+   *ir_b = 126;
+   *ir_u = 0;
+   *ir_s = 0;
+
+   return 0;
+   } else if (ir_calc > ir) {
+   /* Increasing the denominator to select ir_s value */
+   while (ir_calc > ir) {
+   ir_s_calc++;
+   ir_calc = 1008000 / (tick * (1 << ir_s_calc));
+   }
+
+   if (ir_calc == ir)
+   *ir_b = 126;
+   else
+   *ir_b = (ir * tick * (1 << ir_s_calc) + 4000) / 8000;
+   } else {
+   /* Increasing the numerator to select ir_u value */
+   u32 numerator;
+
+   while (ir_calc < ir) {
+   ir_u_calc++;
+   numerator = 1008000 * (1 << ir_u_calc);
+   ir_calc = (numerator + (tick >> 1)) / tick;
+   }
+
+   if (ir_calc == ir) {
+   *ir_b = 126;
+   } else {
+   u32 denominator = (8000 * (1 << --ir_u_calc));
+   *ir_b = (ir * tick + (denominator >> 1)) / denominator;
+   }
+   }
+
+   *ir_u = ir_u_calc;
+   *ir_s = ir_s_calc;
+
+   return 0;
+}
+
+static int hclge_mac_pause_en_cfg(struct hclge_dev *hdev, bool tx, bool rx)
+{
+   struct hclge_desc desc;
+
+   

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

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

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

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

Re: [PATCH net-next] bpf: dev_map_alloc() shouldn't return NULL

2017-07-22 Thread John Fastabend
On 07/22/2017 12:40 AM, Dan Carpenter wrote:
> We forgot to set the error code on two error paths which means that we
> return ERR_PTR(0) which is NULL.  The caller, find_and_alloc_map(), is
> not expecting that and will have a NULL dereference.
> 
> Fixes: 546ac1ffb70d ("bpf: add devmap, a map for storing net device 
> references")
> Signed-off-by: Dan Carpenter 
> 
> diff --git a/kernel/bpf/devmap.c b/kernel/bpf/devmap.c
> index 899364d097f5..d439ee0eadb1 100644
> --- a/kernel/bpf/devmap.c
> +++ b/kernel/bpf/devmap.c
> @@ -114,6 +114,7 @@ static struct bpf_map *dev_map_alloc(union bpf_attr *attr)
>   if (err)
>   goto free_dtab;
>  
> + err = -ENOMEM;
>   /* A per cpu bitfield with a bit per possible net device */
>   dtab->flush_needed = __alloc_percpu(
>   BITS_TO_LONGS(attr->max_entries) *
> 

Thanks.

Acked-by: John Fastabend 


Re: af_packet: use after free in prb_retire_rx_blk_timer_expired

2017-07-22 Thread Cong Wang
Hello,

On Sat, Jul 22, 2017 at 2:55 AM, liujian (CE)  wrote:
> I also hit this issue with trinity test:
>
> The call trace:
>   [exception RIP: prb_retire_rx_blk_timer_expired+70]
> RIP: 81633be6  RSP: 8801bec03dc0  RFLAGS: 00010246
> RAX:   RBX: 8801b49d0948  RCX: 
> RDX: 8801b31057a0  RSI: a56b6b6b6b6b6b6b  RDI: 8801b49d09ec
> RBP: 8801bec03dd8   R8: 0001   R9: 83e1bf80
> R10: 0002  R11: 0005  R12: 8801b49d09ec
> R13: 0100  R14: 81633ba0  R15: 8801b49d0948
> ORIG_RAX:   CS: 0010  SS: 0018
>  #7 [8801bec03de0] call_timer_fn at 8108cb76
>  #8 [8801bec03e18] run_timer_softirq at 8108f87c
>  #9 [8801bec03e90] __do_softirq at 8108629f
> #10 [8801bec03f00] call_softirq at 8166a01c
> #11 [8801bec03f18] do_softirq at 810172ad
> #12 [8801bec03f30] irq_exit at 81086655
> #13 [8801bec03f48] msa_irq_exit at 810b1ab3
> #14 [8801bec03f88] smp_apic_timer_interrupt at 8166aeae
> #15 [8801bec03fb0] apic_timer_interrupt at 816692dd
> ---  ---
>
> And from vmcore, I can see the pointer GET_CURR_PBLOCK_DESC_FROM_CORE(pkc); 
> is a56b6b6b6b6b6b6b
>

Does the following quick fix help?


diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
index 008bb34ee324..09ec1640e5f7 100644
--- a/net/packet/af_packet.c
+++ b/net/packet/af_packet.c
@@ -4264,6 +4264,7 @@ static int packet_set_ring(struct sock *sk,
union tpacket_req_u *req_u,
/* Block transmit is not supported yet */
if (!tx_ring) {
init_prb_bdqc(po, rb, pg_vec, req_u);
+   pg_vec = NULL;
} else {
struct tpacket_req3 *req3 = _u->req3;


[IRDA PATCH] mcs7780: Fix initialization when CONFIG_VMAP_STACK is enabled

2017-07-22 Thread Thomas Jarosch
DMA transfers are not allowed to buffers that are on the stack.
Therefore allocate a buffer to store the result of usb_control_message().

Fixes these bugreports:
https://bugzilla.kernel.org/show_bug.cgi?id=195217

https://bugzilla.redhat.com/show_bug.cgi?id=1421387
https://bugzilla.redhat.com/show_bug.cgi?id=1427398


Shortened kernel backtrace from 4.11.9-200.fc25.x86_64:
kernel: [ cut here ]
kernel: WARNING: CPU: 3 PID: 2957 at drivers/usb/core/hcd.c:1587
kernel: transfer buffer not dma capable
kernel: Call Trace:
kernel: dump_stack+0x63/0x86
kernel: __warn+0xcb/0xf0
kernel: warn_slowpath_fmt+0x5a/0x80
kernel: usb_hcd_map_urb_for_dma+0x37f/0x570
kernel: ? try_to_del_timer_sync+0x53/0x80
kernel: usb_hcd_submit_urb+0x34e/0xb90
kernel: ? schedule_timeout+0x17e/0x300
kernel: ? del_timer_sync+0x50/0x50
kernel: ? __slab_free+0xa9/0x300
kernel: usb_submit_urb+0x2f4/0x560
kernel: ? urb_destroy+0x24/0x30
kernel: usb_start_wait_urb+0x6e/0x170
kernel: usb_control_msg+0xdc/0x120
kernel: mcs_get_reg+0x36/0x40 [mcs7780]
kernel: mcs_net_open+0xb5/0x5c0 [mcs7780]
...

Regression goes back to 4.9, so it's a good candidate for -stable.
Though it's the decision of the maintainer.

Thanks to Dan Williams for adding the "transfer buffer not dma capable"
warning in the first place. It instantly pointed me in the right direction.

Patch has been tested with transferring data from a Polar watch.

Signed-off-by: Thomas Jarosch 
---
 drivers/net/irda/mcs7780.c | 16 +---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/drivers/net/irda/mcs7780.c b/drivers/net/irda/mcs7780.c
index 6f6ed75b63c9..765de3bedb88 100644
--- a/drivers/net/irda/mcs7780.c
+++ b/drivers/net/irda/mcs7780.c
@@ -141,9 +141,19 @@ static int mcs_set_reg(struct mcs_cb *mcs, __u16 reg, 
__u16 val)
 static int mcs_get_reg(struct mcs_cb *mcs, __u16 reg, __u16 * val)
 {
struct usb_device *dev = mcs->usbdev;
-   int ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), MCS_RDREQ,
- MCS_RD_RTYPE, 0, reg, val, 2,
- msecs_to_jiffies(MCS_CTRL_TIMEOUT));
+   void *dmabuf;
+   int ret;
+
+   dmabuf = kmalloc(sizeof(__u16), GFP_KERNEL);
+   if (!dmabuf)
+   return -ENOMEM;
+
+   ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), MCS_RDREQ,
+ MCS_RD_RTYPE, 0, reg, dmabuf, 2,
+ msecs_to_jiffies(MCS_CTRL_TIMEOUT));
+
+   memcpy(val, dmabuf, sizeof(__u16));
+   kfree(dmabuf);
 
return ret;
 }
-- 
2.11.1



Re: [PATCH] NFC: fix device-allocation error return

2017-07-22 Thread Johan Hovold
On Sun, Jul 09, 2017 at 01:08:58PM +0200, Johan Hovold wrote:
> A recent change fixing NFC device allocation itself introduced an
> error-handling bug by returning an error pointer in case device-id
> allocation failed. This is clearly broken as the callers still expected
> NULL to be returned on errors as detected by Dan's static checker.
> 
> Fix this up by returning NULL in the event that we've run out of memory
> when allocating a new device id.
> 
> Note that the offending commit is marked for stable (3.8) so this fix
> needs to be backported along with it.
> 
> Fixes: 20777bc57c34 ("NFC: fix broken device allocation")
> Cc: stable    # 3.8
> Reported-by: Dan Carpenter 
> Signed-off-by: Johan Hovold 

Samuel or David,

Could you apply this follow-up fix so that it can be backported along
with the offending commit (which was just added to the stable queues)?

We would only hit this error path if an ida allocation fails due to OOM;
so while this is not critical, it would still be nice to get it fixed.

Thanks,
Johan


[PATCH v2 net] net: ethernet: mediatek: avoid potential invalid memory access

2017-07-22 Thread sean.wang
From: Sean Wang 

Potential dangerous invalid memory might be accessed if invalid mac value
reflected from the forward port field in rxd4 caused by possible potential
hardware defects. So added a simple sanity checker to avoid the kind of
situation happening.

Signed-off-by: Sean Wang 
Acked-by: John Crispin 
---
 drivers/net/ethernet/mediatek/mtk_eth_soc.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c 
b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
index c1dc08c..e69524c 100644
--- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
+++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
@@ -999,6 +999,10 @@ static int mtk_poll_rx(struct napi_struct *napi, int 
budget,
  RX_DMA_FPORT_MASK;
mac--;
 
+   if (unlikely(mac < 0 || mac >= MTK_MAC_COUNT ||
+!eth->netdev[mac]))
+   goto release_desc;
+
netdev = eth->netdev[mac];
 
if (unlikely(test_bit(MTK_RESETTING, >state)))
-- 
2.7.4



Re: [PATCH net] net: ethernet: mediatek: avoid potential invalid memory access

2017-07-22 Thread kbuild test robot
Hi Sean,

[auto build test WARNING on net/master]

url:
https://github.com/0day-ci/linux/commits/sean-wang-mediatek-com/net-ethernet-mediatek-avoid-potential-invalid-memory-access/20170722-155541
config: arm-allmodconfig (attached as .config)
compiler: arm-linux-gnueabi-gcc (Debian 6.1.1-9) 6.1.1 20160705
reproduce:
wget 
https://raw.githubusercontent.com/01org/lkp-tests/master/sbin/make.cross -O 
~/bin/make.cross
chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=arm 

Note: it may well be a FALSE warning. FWIW you are at least aware of it now.
http://gcc.gnu.org/wiki/Better_Uninitialized_Warnings

All warnings (new ones prefixed by >>):

   drivers/net//ethernet/mediatek/mtk_eth_soc.c: In function 'mtk_napi_rx':
>> drivers/net//ethernet/mediatek/mtk_eth_soc.c:952:28: warning: 'netdev' may 
>> be used uninitialized in this function [-Wmaybe-uninitialized]
   netdev->stats.rx_dropped++;
   ^~
   drivers/net//ethernet/mediatek/mtk_eth_soc.c:928:22: note: 'netdev' was 
declared here
  struct net_device *netdev;
 ^~

vim +/netdev +952 drivers/net//ethernet/mediatek/mtk_eth_soc.c

   916  
   917  static int mtk_poll_rx(struct napi_struct *napi, int budget,
   918 struct mtk_eth *eth)
   919  {
   920  struct mtk_rx_ring *ring;
   921  int idx;
   922  struct sk_buff *skb;
   923  u8 *data, *new_data;
   924  struct mtk_rx_dma *rxd, trxd;
   925  int done = 0;
   926  
   927  while (done < budget) {
   928  struct net_device *netdev;
   929  unsigned int pktlen;
   930  dma_addr_t dma_addr;
   931  int mac = 0;
   932  
   933  ring = mtk_get_rx_ring(eth);
   934  if (unlikely(!ring))
   935  goto rx_done;
   936  
   937  idx = NEXT_RX_DESP_IDX(ring->calc_idx, ring->dma_size);
   938  rxd = >dma[idx];
   939  data = ring->data[idx];
   940  
   941  mtk_rx_get_desc(, rxd);
   942  if (!(trxd.rxd2 & RX_DMA_DONE))
   943  break;
   944  
   945  /* find out which mac the packet come from. values 
start at 1 */
   946  mac = (trxd.rxd4 >> RX_DMA_FPORT_SHIFT) &
   947RX_DMA_FPORT_MASK;
   948  mac--;
   949  
   950  if (unlikely(mac < 0 || mac >= MTK_MAC_COUNT ||
   951   !eth->netdev[mac])) {
 > 952  netdev->stats.rx_dropped++;
   953  goto release_desc;
   954  }
   955  
   956  netdev = eth->netdev[mac];
   957  
   958  if (unlikely(test_bit(MTK_RESETTING, >state)))
   959  goto release_desc;
   960  
   961  /* alloc new buffer */
   962  new_data = napi_alloc_frag(ring->frag_size);
   963  if (unlikely(!new_data)) {
   964  netdev->stats.rx_dropped++;
   965  goto release_desc;
   966  }
   967  dma_addr = dma_map_single(eth->dev,
   968new_data + NET_SKB_PAD,
   969ring->buf_size,
   970DMA_FROM_DEVICE);
   971  if (unlikely(dma_mapping_error(eth->dev, dma_addr))) {
   972  skb_free_frag(new_data);
   973  netdev->stats.rx_dropped++;
   974  goto release_desc;
   975  }
   976  
   977  /* receive data */
   978  skb = build_skb(data, ring->frag_size);
   979  if (unlikely(!skb)) {
   980  skb_free_frag(new_data);
   981  netdev->stats.rx_dropped++;
   982  goto release_desc;
   983  }
   984  skb_reserve(skb, NET_SKB_PAD + NET_IP_ALIGN);
   985  
   986  dma_unmap_single(eth->dev, trxd.rxd1,
   987   ring->buf_size, DMA_FROM_DEVICE);
   988  pktlen = RX_DMA_GET_PLEN0(trxd.rxd2);
   989  skb->dev = netdev;
   990  skb_put(skb, pktlen);
   991  if (trxd.rxd4 & RX_DMA_L4_VALID)
   992  skb->ip_summed = CHECKSUM_UNNECESSARY;
   993  else
   994  skb_checksum_none_assert(skb);
   995  skb->protocol = eth_

Re: [PATCH net-next] bpf: dev_map_alloc() shouldn't return NULL

2017-07-22 Thread Daniel Borkmann

On 07/22/2017 09:40 AM, Dan Carpenter wrote:

We forgot to set the error code on two error paths which means that we
return ERR_PTR(0) which is NULL.  The caller, find_and_alloc_map(), is
not expecting that and will have a NULL dereference.

Fixes: 546ac1ffb70d ("bpf: add devmap, a map for storing net device references")
Signed-off-by: Dan Carpenter 


Thanks!

Acked-by: Daniel Borkmann 


RE: af_packet: use after free in prb_retire_rx_blk_timer_expired

2017-07-22 Thread liujian (CE)
I also hit this issue with trinity test:

The call trace:
  [exception RIP: prb_retire_rx_blk_timer_expired+70]
RIP: 81633be6  RSP: 8801bec03dc0  RFLAGS: 00010246
RAX:   RBX: 8801b49d0948  RCX: 
RDX: 8801b31057a0  RSI: a56b6b6b6b6b6b6b  RDI: 8801b49d09ec
RBP: 8801bec03dd8   R8: 0001   R9: 83e1bf80
R10: 0002  R11: 0005  R12: 8801b49d09ec
R13: 0100  R14: 81633ba0  R15: 8801b49d0948
ORIG_RAX:   CS: 0010  SS: 0018
 #7 [8801bec03de0] call_timer_fn at 8108cb76
 #8 [8801bec03e18] run_timer_softirq at 8108f87c
 #9 [8801bec03e90] __do_softirq at 8108629f
#10 [8801bec03f00] call_softirq at 8166a01c
#11 [8801bec03f18] do_softirq at 810172ad
#12 [8801bec03f30] irq_exit at 81086655
#13 [8801bec03f48] msa_irq_exit at 810b1ab3
#14 [8801bec03f88] smp_apic_timer_interrupt at 8166aeae
#15 [8801bec03fb0] apic_timer_interrupt at 816692dd
---  ---

And from vmcore, I can see the pointer GET_CURR_PBLOCK_DESC_FROM_CORE(pkc); is 
a56b6b6b6b6b6b6b 


struct packet_ring_buffer  rx_ring = {
pg_vec = 0x0, 
head = 0x0, 
frames_per_block = 0x400, 
frame_size = 0x0, 
frame_max = 0x, 
pg_vec_order = 0x0, 
pg_vec_pages = 0x0, 
pg_vec_len = 0x0, 
pending_refcnt = 0x0, 
prb_bdqc = {
  pkbdq = 0x8801b31057a0, 
  feature_req_word = 0x1, 
  hdrlen = 0x44, 
  reset_pending_on_curr_blk = 0x1, 
  delete_blk_timer = 0x0, 
  kactive_blk_num = 0x0, 
  blk_sizeof_priv = 0x0, 
  last_kactive_blk_num = 0x0, 
  pkblk_start = 0x8800a700 struct: page excluded: kernel virtual 
address: 8800a700  type: "gdb_readmem_callback"
struct: page excluded: kernel virtual address: 8800a700  type: 
"gdb_readmem_callback"
, 
  pkblk_end = 0x8800a720 "\002", 
  kblk_size = 0x20, 
  max_frame_len = 0x1fffd0, 
  knum_blocks = 0x1, 
  knxt_seq_num = 0x2, 
  prev = 0x8800a730 struct: page excluded: kernel virtual address: 
8800a730  type: "gdb_readmem_callback"
struct: page excluded: kernel virtual address: 8800a730  type: 
"gdb_readmem_callback"
, 
  nxt_offset = 0x8800a730 struct: page excluded: kernel virtual 
address: 8800a730  type: "gdb_readmem_callback"
struct: page excluded: kernel virtual address: 8800a730  type: 
"gdb_readmem_callback"
, 
  skb = 0x0, 
  blk_fill_in_prog = {
counter = 0x0

crash> struct pgv 0x8801b31057a0
struct pgv {
  buffer = 0xa56b6b6b6b6b6b6b 
}


Best Regards,
liujian


> -Original Message-
> From: netdev-ow...@vger.kernel.org [mailto:netdev-ow...@vger.kernel.org]
> On Behalf Of Willem de Bruijn
> Sent: Wednesday, April 12, 2017 7:23 AM
> To: Dave Jones; alexander.le...@verizon.com; da...@davemloft.net;
> eduma...@google.com; will...@google.com; dan...@iogearbox.net;
> netdev@vger.kernel.org; linux-ker...@vger.kernel.org
> Subject: Re: af_packet: use after free in prb_retire_rx_blk_timer_expired
> 
> On Mon, Apr 10, 2017 at 3:23 PM, Dave Jones 
> wrote:
> > On Mon, Apr 10, 2017 at 07:03:30PM +, alexander.le...@verizon.com
> wrote:
> >  > Hi all,
> >  >
> >  > I seem to be hitting this use-after-free on a -next kernel using trinity:
> >  >
> >  > [  531.036054] BUG: KASAN: use-after-free in
> > prb_retire_rx_blk_timer_expired (net/packet/af_packet.c:688)
> 
> The retire_blk_timer is called after the pg_vec struct for this ring was 
> freed.
> This should not happen. packet_set_ring stops the timer with del_timer_sync
> when tearing down the ring before freeing that
> struct:
> 
> if (closing && (po->tp_version > TPACKET_V2)) {
> /* Because we don't support block-based V3 on tx-ring */
> if (!tx_ring)
> prb_shutdown_retire_blk_timer(po, rb_queue);
> }
> 
> if (pg_vec)
> free_pg_vec(pg_vec, order, req->tp_block_nr);
> 
> This is a similar race to the use-after-free fixed by 84ac7260236a
> ("packet: fix race condition in packet_set_ring"). The previous race was
> triggered by a call to setsockopt PACKET_VERSION changing tp_version while
> the ring is active. It is not immediately obvious what is the cause now. I
> suppose trinity does not give a trace of such system calls on this file 
> descriptor?
> That would be helpful.
> 
> The bug report shows both a timer firing after the packet_set_ring call that
> freed the pg_vec, and later a CONFIG_DEBUG_OBJECTS_FREE warning that
> the timer is still active when the socket is closed on release of the last 
> file
> descriptor.


Re: [PATCH iproute2 master 1/2] bpf: improve error reporting around tail calls

2017-07-22 Thread Daniel Borkmann

On 07/22/2017 01:28 AM, Stephen Hemminger wrote:

On Fri, 21 Jul 2017 21:13:06 +0200
Daniel Borkmann  wrote:


Currently, it's still quite hard to figure out if a prog passed the
verifier, but later gets rejected due to different tail call ownership.
Figure out whether that is the case and provide appropriate error
messages to the user.

Signed-off-by: Daniel Borkmann 


Sorry, dead code. Please fix and resubmit.

bpf.c:356:12: warning: ‘bpf_derive_prog_from_fdinfo’ defined but not used 
[-Wunused-function]
  static int bpf_derive_prog_from_fdinfo(int fd, struct bpf_prog_data *prog)


Yeah, v2 coming later today. I didn't compile with !HAVE_ELF,
where it's not in use indeed. Thanks!


[PATCH net-next] bpf: dev_map_alloc() shouldn't return NULL

2017-07-22 Thread Dan Carpenter
We forgot to set the error code on two error paths which means that we
return ERR_PTR(0) which is NULL.  The caller, find_and_alloc_map(), is
not expecting that and will have a NULL dereference.

Fixes: 546ac1ffb70d ("bpf: add devmap, a map for storing net device references")
Signed-off-by: Dan Carpenter 

diff --git a/kernel/bpf/devmap.c b/kernel/bpf/devmap.c
index 899364d097f5..d439ee0eadb1 100644
--- a/kernel/bpf/devmap.c
+++ b/kernel/bpf/devmap.c
@@ -114,6 +114,7 @@ static struct bpf_map *dev_map_alloc(union bpf_attr *attr)
if (err)
goto free_dtab;
 
+   err = -ENOMEM;
/* A per cpu bitfield with a bit per possible net device */
dtab->flush_needed = __alloc_percpu(
BITS_TO_LONGS(attr->max_entries) *


Re: [PATCH net-next 1/3] bluetooth: 6lowpan dev_close never returns error

2017-07-22 Thread Marcel Holtmann
Hi Stephen,

> [auto build test WARNING on net-next/master]
> 
> url:
> https://github.com/0day-ci/linux/commits/Stephen-Hemminger/net-make-dev_close-void/20170720-090123
> config: x86_64-randconfig-a0-07211734 (attached as .config)
> compiler: gcc-4.4 (Debian 4.4.7-8) 4.4.7
> reproduce:
># save the attached .config to linux build tree
>make ARCH=x86_64 
> 
> All warnings (new ones prefixed by >>):
> 
>   net/bluetooth/6lowpan.c: In function 'ifdown':
>>> net/bluetooth/6lowpan.c:621: warning: unused variable 'err'
> 
> vim +/err +621 net/bluetooth/6lowpan.c
> 
> 18722c24 Jukka Rissanen2013-12-11  618  
> 7f118253 Jukka Rissanen2014-06-18  619  static void ifdown(struct 
> net_device *netdev)
> 7f118253 Jukka Rissanen2014-06-18  620  {
> 7f118253 Jukka Rissanen2014-06-18 @621int err;
> 7f118253 Jukka Rissanen2014-06-18  622  
> 7f118253 Jukka Rissanen2014-06-18  623rtnl_lock();
> ca74f73e Stephen Hemminger 2017-07-18  624dev_close(netdev);
> 7f118253 Jukka Rissanen2014-06-18  625rtnl_unlock();
> 7f118253 Jukka Rissanen2014-06-18  626  }
> 7f118253 Jukka Rissanen2014-06-18  627  
> 
> :: The code at line 621 was first introduced by commit
> :: 7f118253820fc3ad38659485adb3ebdfe64820e1 Bluetooth: 6LoWPAN: Remove 
> network devices when unloading
> 
> :: TO: Jukka Rissanen 
> :: CC: Marcel Holtmann 

are you going to send a fix for this?

Regards

Marcel