Priority of HTB class on 10GbE

2016-11-20 Thread jipan yang
Hello,

Have been using htb with 1Gbe nic for traffic control of three classes
of traffic with priority 1,2 & 3,  the configuration worked perfectly.
The ceil of  higher priority traffic gets filled before that of lower
priority.

"
tc qdisc del dev enp1s0f1 root

# This line sets a HTB qdisc on the root of enp1s0f1, and it specifies
that the class 1:30 is used by default.
# It sets the name of the root as 1:, for future references.
tc qdisc add dev enp1s0f1 root handle 1: htb default 30

# This creates a class called 1:1, which is direct descendant of root
(the parent is 1:),
# this class gets assigned also an HTB qdisc, and then it sets a max
rate of 6mbits, with a burst of 15k
tc class add dev enp1s0f1 parent 1: classid 1:1  htb rate 1000mbit
ceil 1000mbit  burst 15k

# Class 1:10, which has a rate of 200mbit, ceil 800mbit
tc class add dev enp1s0f1 parent 1:1 classid 1:10 htb  rate 200mbit
ceil 800mbit  burst 15k  cburst 15k prio 1


# Class 1:20, which has a rate of 200 mbit, ceil 500mbit
tc class add dev enp1s0f1 parent 1:1  classid 1:20  htb  rate 200mbit
ceil 500mbit burst 15k cburst 15k  prio 2

# Class 1:30, which has a rate of 1mbit. This one is the default class.
tc class add dev enp1s0f1 parent 1:1 classid 1:30  htb rate 10mbit
ceil 1000mbit burst 15k cburst 15k prio 3

#sfq
tc qdisc add dev enp1s0f1 parent 1:10 handle 10: sfq perturb 10
tc qdisc add dev enp1s0f1 parent 1:20 handle 20: sfq perturb 10
tc qdisc add dev enp1s0f1 parent 1:30 handle 30: sfq perturb 10

tc filter add dev enp1s0f1 parent 1:  protocol ip prio 100 handle 100: cgroup
"


While moving to 10G nic on the same host,  I assumed same
configuration with the rate and ceil number timed 10 would also work,
but it turned out things started to fall apart.The priority
setting doesn't seem to work, with 3 tcp connection, one on each
class, the iperf testing data doesn't make much sense, also the
throughput fluctuated a lot. I have tried to change parameters like
quantum, burst, cburst and etc. but none of them fixes the problem.

I'm wondering if this is known issue for HTB on 10G nic, if it is,
anyone already working on it?

Priority 1: class 1:10
[  4] 7362.00-7363.00 sec   518 MBytes  4.34 Gbits/sec  8825
538:339:391:3127:3891:281:223:35

[  4] 7363.00-7364.00 sec   507 MBytes  4.25 Gbits/sec  8809
540:321:486:3251:3904:174:121:12

[  4] 7364.00-7365.00 sec   496 MBytes  4.16 Gbits/sec  8793
585:264:530:3533:3694:114:67:6

[  4] 7365.00-7366.00 sec   481 MBytes  4.03 Gbits/sec  8761
552:242:747:3873:3304:27:14:2

[  4] 7366.00-7367.00 sec   484 MBytes  4.06 Gbits/sec  8783
596:239:650:3828:3462:6:2:0



Priority 2: class 1:20

[  4] 7401.00-7402.00 sec   488 MBytes  4.10 Gbits/sec  10151
1681:937:861:3046:3610:5:6:5

[  4] 7402.00-7403.00 sec   490 MBytes  4.11 Gbits/sec  10186
1688:979:857:3003:3646:6:3:4

[  4] 7403.00-7404.00 sec   454 MBytes  3.81 Gbits/sec  10499
2110:1103:1427:3639:2186:9:14:11

[  4] 7404.00-7405.00 sec   454 MBytes  3.81 Gbits/sec  10476
2118:1078:1400:3626:2210:10:22:12



Prority 3: class 1:30

  4] 7425.00-7426.00 sec   123 MBytes  1.03 Gbits/sec  5374
2926:521:622:1295:3:3:2:2

[  4] 7426.00-7427.00 sec   120 MBytes  1.01 Gbits/sec  5224
2782:580:609:1242:8:1:0:2

[  4] 7427.00-7428.00 sec   118 MBytes   989 Mbits/sec  5167
2764:577:594:1225:4:2:0:1

[  4] 7428.00-7429.00 sec   108 MBytes   906 Mbits/sec  4595
2331:594:562:1103:3:1:1:0

[  4] 7429.00-7430.00 sec   102 MBytes   856 Mbits/sec  4434
2262:601:550:1017:4:0:0:0

[  4] 7430.00-7431.00 sec   130 MBytes  1.09 Gbits/sec  5573
3006:535:626:1392:9:2:2:1

[  4] 7431.00-7432.00 sec   148 MBytes  1.25 Gbits/sec  6466
3500:633:762:1550:11:5:4:1



"
[root@dockerhost3 ~]# tc -s qdisc ls dev enp7s0f1

qdisc htb 1: root refcnt 65 r2q 10 default 30 direct_packets_stat 1425

 Sent 387791599974 bytes 256137127 pkt (dropped 32, overlimits
16471645 requeues 40)

 backlog 0b 5p requeues 40

qdisc sfq 10: parent 1:10 limit 127p quantum 1514b depth 127 divisor
1024 perturb 10sec

 Sent 170422902810 bytes 112564665 pkt (dropped 0, overlimits 0 requeues 0)

 backlog 68130b 1p requeues 0

qdisc sfq 20: parent 1:20 limit 127p quantum 1514b depth 127 divisor
1024 perturb 10sec

 Sent 164903555250 bytes 108919125 pkt (dropped 0, overlimits 0 requeues 0)

 backlog 68130b 1p requeues 0

qdisc sfq 30: parent 1:30 limit 127p quantum 1514b depth 127 divisor
1024 perturb 10sec

 Sent 52344279294 bytes 34573507 pkt (dropped 26, overlimits 0 requeues 0)

 backlog 204390b 3p requeues 0

[root@dockerhost3 ~]# tc -s filter  ls dev enp7s0f1

filter parent 1: protocol ip pref 100 cgroup handle 0x64

filter parent 1: protocol ip pref 100 cgroup handle 0x64

[root@dockerhost3 ~]# tc -s -d class show dev  enp7s0f1

class htb 1:1 root rate 1Mbit ceil 1Mbit burst 13750b/1 mpu 0b
overhead 0b cburst 0b/1 mpu 0b overhead 0b level 7

 Sent 387743091414 bytes 256105087 pkt (dropped 0, overlimits 0 requeues 0)

 rate 9862Mbit 828299pps backlog 0b 0p requeues 0

 lended: 828299 

Re: [PATCH 4.9.0-rc5] AR9300 calibration problems with antenna selected

2016-11-20 Thread miaoqing


I would prefer that you didn't submit this.



I recently tried to select a single antenna on AR9300 and it works for
30 seconds only. The subsequent calibration makes the RX signal level
to drop from the usual -30/-40 dBm to -70/-80 dBm, and the
transmission practically stops.

With the attached patch it works, though selecting the antenna doesn't
seem to have any visible effect, at least with "iw wlanX station dump"
(perhaps it works for TX).

I'm using ad-hoc mode:

rmmod ath9k
modprobe ath9k
iw dev wlan0 set type ibss
iw phy phyX set antenna 2


2 is a bad mask. We use bitmap, the valid masks are 1, 3, 7.

--
Miaoqing




Re: Synopsys Ethernet QoS Driver

2016-11-20 Thread Rayagond Kokatanur
On Sat, Nov 19, 2016 at 7:26 PM, Rabin Vincent  wrote:
> On Fri, Nov 18, 2016 at 02:20:27PM +, Joao Pinto wrote:
>> For now we are interesting in improving the synopsys QoS driver under
>> /nect/ethernet/synopsys. For now the driver structure consists of a single 
>> file
>> called dwc_eth_qos.c, containing synopsys ethernet qos common ops and 
>> platform
>> related stuff.
>>
>> Our strategy would be:
>>
>> a) Implement a platform glue driver (dwc_eth_qos_pltfm.c)
>> b) Implement a pci glue driver (dwc_eth_qos_pci.c)
>> c) Implement a "core driver" (dwc_eth_qos.c) that would only have Ethernet 
>> QoS
>> related stuff to be reused by the platform / pci drivers
>> d) Add a set of features to the "core driver" that we have available 
>> internally
>
> Note that there are actually two drivers in mainline for this hardware:
>
>  drivers/net/ethernet/synopsis/
>  drivers/net/ethernet/stmicro/stmmac/

Yes the later driver (drivers/net/ethernet/stmicro/stmmac/) supports
both 3.x and 4.x. It has glue layer for pci, platform, core etc,
please refer this driver once before you start.

You can start adding missing feature of 4.x in stmmac driver.

>
> (See http://lists.openwall.net/netdev/2016/02/29/127)
>
> The former only supports 4.x of the hardware.
>
> The later supports 4.x and 3.x and already has a platform glue driver
> with support for several platforms, a PCI glue driver, and a core driver
> with several features not present in the former (for example: TX/RX
> interrupt coalescing, EEE, PTP).
>
> Have you evaluated both drivers?  Why have you decided to work on the
> former rather than the latter?



-- 
wwr
Rayagond


RE: [net-next] rtnl: fix the loop index update error in rtnl_dump_ifinfo()

2016-11-20 Thread 张胜举
> -Original Message-
> From: David Miller [mailto:da...@davemloft.net]
> Sent: Sunday, November 20, 2016 11:15 AM
> To: zhangshen...@cmss.chinamobile.com
> Cc: netdev@vger.kernel.org; d...@cumulusnetworks.com
> Subject: Re: [net-next] rtnl: fix the loop index update error in
> rtnl_dump_ifinfo()
> 
> From: Zhang Shengju 
> Date: Sat, 19 Nov 2016 23:28:32 +0800
> 
> > If the link is filtered out, loop index should also be updated. If
> > not, loop index will not be correct.
> >
> > Signed-off-by: Zhang Shengju 
> 
> Applied to 'net' and queued up for -stable.
> 
> Bug fixes should always be targetted at 'net' not 'net-next'.

Thanks David, I will pay attention to this next time.

BRs,
Zhang Shengju





Re: [PATCH net-next] bridge: add igmpv3 and mldv2 query support

2016-11-20 Thread Hangbin Liu
2016-11-18 18:31 GMT+08:00 Nikolay Aleksandrov :
> On 18/11/16 11:09, Nikolay Aleksandrov wrote:
>>
>> On 18/11/16 11:04, Nikolay Aleksandrov wrote:
>>>
>>> (+CC Roopa)
>>> Hi Hangbin,
>>> This patch is not correct, you should not use the net device IGMP config
>>> in the bridge.
>>
>> * bridge net device, sorry not port

Hi Nikolay,

Thanks for the comments. You are right. I was just thinking to make the IGMP/MLD
version configurable and use existing variables directly. But we
should control it
per-bridge basis.

>>
>>> These packets may never make it to the host and they may not be
>>> reflected, even more the
>>> host may have very different igmp config for the port net device than the
>>> bridge does.
>>
>> * again bridge net device, not port
>>
>>> Also your current implementation switches to V3 only if it is globally
>>> set, and that should
>>> be controlled on a per-bridge basis, even per-vlan later.
>>
>> * it is per-bridge, you use the global net device IGMP config, but it
>> should be in the bridge
>> mcast control options, so we can do it per-vlan later and also be able to
>> do the compat parts
>> of the RFC and in general, the bridge is configured via its own options
>> not the host net device
>> because as I said these packets may never be received locally
>
>
> Having the host netdev options affect the bridge-specific config is really
> undesirable and confusing.
>
>>
>>> One more thing, if someone does a V2 leave for a group, you can end up
>>> sending them V3
>>> group-specific query.
>>>
>>> I have been working on an implementation for IGMPv3/MLDv2 querier for the
>>> bridge device, it re-uses
>>> most of the current code and allows you to configure it per-bridge (and
>>> later per-vlan). The only
>>> reason I've not yet sent it to upstream is that we (at Cumulus) are
>>> working out the compatibility
>>> parts (e.g. RFC3376 sec 7, sec 8) of the RFC since it has some unclear
>>> cases.

Yeah, even in the host igmp/mld code we have some vague areas and different
handles.

>
>
> Err, RFC3376 sec 7.3.1, 7.3.2, and RFC3810 sec 8.3.1, 8.3.2
>
> I really should get coffee.. sorry for the multiple emails :-)
>
>
>>> But I can rip the compatibility out and send it early for review if you'd
>>> like, we can add the
>>> compat code later.

OK, then I will wait for your patch.

Thanks
Hangbin


Re: [PATCH v2 net-next 0/6] Fixes for the MV88e6xxx interrupt code

2016-11-20 Thread David Miller
From: Andrew Lunn 
Date: Sun, 20 Nov 2016 20:14:13 +0100

> The interrupt code was never tested with a board who's probing
> resulted in an -EPROBE_DEFFERED. So the clean up paths never got
> tested. I now do have -EPROBE_DEFFERED, and things break badly during
> cleanup. These are the fixes.
> 
> This is fixing code in net-next.
> 
> v2:
> Fix typo pointed out by David Miller

Series applied, thanks Andrew.


[PATCH net 1/1] net: l2tp: Treat NET_XMIT_CN as success in l2tp_eth_dev_xmit

2016-11-20 Thread fgao
From: Gao Feng 

The tc could return NET_XMIT_CN as one congestion notification, but
it does not mean the packe is lost. Other modules like ipvlan,
macvlan, and others treat NET_XMIT_CN as success too.
So l2tp_eth_dev_xmit should add the NET_XMIT_CN check.

Signed-off-by: Gao Feng 
---
 net/l2tp/l2tp_eth.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/l2tp/l2tp_eth.c b/net/l2tp/l2tp_eth.c
index 965f7e3..3dc97b4 100644
--- a/net/l2tp/l2tp_eth.c
+++ b/net/l2tp/l2tp_eth.c
@@ -97,7 +97,7 @@ static int l2tp_eth_dev_xmit(struct sk_buff *skb, struct 
net_device *dev)
unsigned int len = skb->len;
int ret = l2tp_xmit_skb(session, skb, session->hdr_len);
 
-   if (likely(ret == NET_XMIT_SUCCESS)) {
+   if (likely(ret == NET_XMIT_SUCCESS || ret == NET_XMIT_CN)) {
atomic_long_add(len, >tx_bytes);
atomic_long_inc(>tx_packets);
} else {
-- 
1.9.1




Re: [PATCH net-next 1/1] driver: macvlan: Remove duplicated IFF_UP condition check in macvlan_forward_source

2016-11-20 Thread Feng Gao
On Mon, Nov 21, 2016 at 8:26 AM,   wrote:
> From: Gao Feng 
>
> The function macvlan_forward_source_one has already checked the flag
> IFF_UP, so needn't check it outside in macvlan_forward_source too.
>
> Signed-off-by: Gao Feng 
> ---
>  v2: Remove the IFF_UP check in macvlan_forward_source instead of 
> macvlan_forward_source_one
>  v1: Initial patch
>
>  drivers/net/macvlan.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
> index 13b7e0b..7ddfd2c 100644
> --- a/drivers/net/macvlan.c
> +++ b/drivers/net/macvlan.c
> @@ -400,8 +400,7 @@ static void macvlan_forward_source(struct sk_buff *skb,
>
> hlist_for_each_entry_rcu(entry, h, hlist) {
> if (ether_addr_equal_64bits(entry->addr, addr))
> -   if (entry->vlan->dev->flags & IFF_UP)
> -   macvlan_forward_source_one(skb, entry->vlan);
> +   macvlan_forward_source_one(skb, entry->vlan);
> }
>  }
>
> --
> 1.9.1
>
>

Sorry, I forget add the "v2" in the title.

Regards
Feng


[PATCH net 1/1] net: batman-adv: Treat NET_XMIT_CN as transmit successfully

2016-11-20 Thread fgao
From: Gao Feng 

The tc could return NET_XMIT_CN as one congestion notification, but
it does not mean the packe is lost. Other modules like ipvlan,
macvlan, and others treat NET_XMIT_CN as success too.

So batman-adv should add the NET_XMIT_CN check.

Signed-off-by: Gao Feng 
---
 net/batman-adv/distributed-arp-table.c | 2 +-
 net/batman-adv/fragmentation.c | 2 +-
 net/batman-adv/routing.c   | 2 +-
 net/batman-adv/tp_meter.c  | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/net/batman-adv/distributed-arp-table.c 
b/net/batman-adv/distributed-arp-table.c
index e257efd..4bf0622 100644
--- a/net/batman-adv/distributed-arp-table.c
+++ b/net/batman-adv/distributed-arp-table.c
@@ -660,7 +660,7 @@ static bool batadv_dat_send_data(struct batadv_priv 
*bat_priv,
}
 
send_status = batadv_send_unicast_skb(tmp_skb, neigh_node);
-   if (send_status == NET_XMIT_SUCCESS) {
+   if (send_status == NET_XMIT_SUCCESS || send_status == 
NET_XMIT_CN) {
/* count the sent packet */
switch (packet_subtype) {
case BATADV_P_DAT_DHT_GET:
diff --git a/net/batman-adv/fragmentation.c b/net/batman-adv/fragmentation.c
index 0934730..4714b8f 100644
--- a/net/batman-adv/fragmentation.c
+++ b/net/batman-adv/fragmentation.c
@@ -495,7 +495,7 @@ int batadv_frag_send_packet(struct sk_buff *skb,
batadv_add_counter(bat_priv, BATADV_CNT_FRAG_TX_BYTES,
   skb_fragment->len + ETH_HLEN);
ret = batadv_send_unicast_skb(skb_fragment, neigh_node);
-   if (ret != NET_XMIT_SUCCESS) {
+   if (ret != NET_XMIT_SUCCESS && ret != NET_XMIT_CN) {
/* return -1 so that the caller can free the original
 * skb
 */
diff --git a/net/batman-adv/routing.c b/net/batman-adv/routing.c
index 7e8dc64..8edd324 100644
--- a/net/batman-adv/routing.c
+++ b/net/batman-adv/routing.c
@@ -706,7 +706,7 @@ static int batadv_route_unicast_packet(struct sk_buff *skb,
goto out;
 
/* translate transmit result into receive result */
-   if (res == NET_XMIT_SUCCESS) {
+   if (res == NET_XMIT_SUCCESS || ret == NET_XMIT_CN) {
/* skb was transmitted and consumed */
batadv_inc_counter(bat_priv, BATADV_CNT_FORWARD);
batadv_add_counter(bat_priv, BATADV_CNT_FORWARD_BYTES,
diff --git a/net/batman-adv/tp_meter.c b/net/batman-adv/tp_meter.c
index 8af1611..461dbad 100644
--- a/net/batman-adv/tp_meter.c
+++ b/net/batman-adv/tp_meter.c
@@ -618,7 +618,7 @@ static int batadv_tp_send_msg(struct batadv_tp_vars 
*tp_vars, const u8 *src,
if (r == -1)
kfree_skb(skb);
 
-   if (r == NET_XMIT_SUCCESS)
+   if (r == NET_XMIT_SUCCESS || r == NET_XMIT_CN)
return 0;
 
return BATADV_TP_REASON_CANT_SEND;
-- 
1.9.1




[PATCH net-next 1/1] driver: macvlan: Remove duplicated IFF_UP condition check in macvlan_forward_source

2016-11-20 Thread fgao
From: Gao Feng 

The function macvlan_forward_source_one has already checked the flag
IFF_UP, so needn't check it outside in macvlan_forward_source too.

Signed-off-by: Gao Feng 
---
 v2: Remove the IFF_UP check in macvlan_forward_source instead of 
macvlan_forward_source_one
 v1: Initial patch

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

diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
index 13b7e0b..7ddfd2c 100644
--- a/drivers/net/macvlan.c
+++ b/drivers/net/macvlan.c
@@ -400,8 +400,7 @@ static void macvlan_forward_source(struct sk_buff *skb,
 
hlist_for_each_entry_rcu(entry, h, hlist) {
if (ether_addr_equal_64bits(entry->addr, addr))
-   if (entry->vlan->dev->flags & IFF_UP)
-   macvlan_forward_source_one(skb, entry->vlan);
+   macvlan_forward_source_one(skb, entry->vlan);
}
 }
 
-- 
1.9.1




Re: [RFC PATCH v2 2/2] macb: Enable 1588 support in SAMA5D2 platform.

2016-11-20 Thread Richard Cochran
On Fri, Nov 18, 2016 at 03:21:52PM +0100, Andrei Pistirica wrote:
> diff --git a/drivers/net/ethernet/cadence/macb.c 
> b/drivers/net/ethernet/cadence/macb.c
> index d975882..eb66b76 100644
> --- a/drivers/net/ethernet/cadence/macb.c
> +++ b/drivers/net/ethernet/cadence/macb.c
> @@ -697,6 +697,8 @@ static void macb_tx_interrupt(struct macb_queue *queue)
>  
>   /* First, update TX stats if needed */
>   if (skb) {
> + macb_ptp_do_txstamp(bp, skb);

This is in the hot path, and so you should have an inline wrapper that
tests (bp->hwts_tx_en) and THEN calls into macb_ptp.c

In case PTP isn't configured, then the inline wrapper should be empty.

>   netdev_vdbg(bp->dev, "skb %u (data %p) TX 
> complete\n",
>   macb_tx_ring_wrap(tail), skb->data);
>   bp->stats.tx_packets++;
> @@ -853,6 +855,8 @@ static int gem_rx(struct macb *bp, int budget)
>   GEM_BFEXT(RX_CSUM, ctrl) & GEM_RX_CSUM_CHECKED_MASK)
>   skb->ip_summed = CHECKSUM_UNNECESSARY;
>  
> + macb_ptp_do_rxstamp(bp, skb);

Same here.

>   bp->stats.rx_packets++;
>   bp->stats.rx_bytes += skb->len;
>  
> @@ -1946,6 +1950,8 @@ static int macb_open(struct net_device *dev)
>  
>   netif_tx_start_all_queues(dev);
>  
> + macb_ptp_init(dev);

This leaks PHC instances starting the second time that the interface goes up!

>   return 0;
>  }
>  
> @@ -2204,7 +2210,7 @@ static const struct ethtool_ops gem_ethtool_ops = {
>   .get_regs_len   = macb_get_regs_len,
>   .get_regs   = macb_get_regs,
>   .get_link   = ethtool_op_get_link,
> - .get_ts_info= ethtool_op_get_ts_info,
> + .get_ts_info= macb_get_ts_info,

You enable the time stamping logic unconditionally here ...

>   .get_ethtool_stats  = gem_get_ethtool_stats,
>   .get_strings= gem_get_ethtool_strings,
>   .get_sset_count = gem_get_sset_count,
> @@ -2221,7 +2227,14 @@ static int macb_ioctl(struct net_device *dev, struct 
> ifreq *rq, int cmd)
>   if (!phydev)
>   return -ENODEV;
>  
> - return phy_mii_ioctl(phydev, rq, cmd);
> + switch (cmd) {
> + case SIOCSHWTSTAMP:
> + return macb_hwtst_set(dev, rq, cmd);
> + case SIOCGHWTSTAMP:
> + return macb_hwtst_get(dev, rq);

and here.

Is that logic always available on every MACB device?  If so, is the
implementation also identical?

Thanks,
Richard


Re: [RFC PATCH v2 1/2] macb: Add 1588 support in Cadence GEM.

2016-11-20 Thread Richard Cochran
On Fri, Nov 18, 2016 at 03:21:51PM +0100, Andrei Pistirica wrote:
> +#ifdef CONFIG_MACB_USE_HWSTAMP
> +void macb_ptp_init(struct net_device *ndev);
> +#else
> +void macb_ptp_init(struct net_device *ndev) { }

static inline ^^^

> +#endif


> +void macb_ptp_init(struct net_device *ndev)
> +{
> + struct macb *bp = netdev_priv(ndev);
> + struct timespec64 now;
> + u32 rem = 0;
> +
> + if (!(bp->caps | MACB_CAPS_GEM_HAS_PTP)){
> + netdev_vdbg(bp->dev, "Platform does not support PTP!\n");
> + return;
> + }

You would have needed '&' and not '|' here.

Also, using a flag limits the code to your platform.  This works for
you, but it is short sighted.  The other MACB PTP blocks have
different register layouts, and this patch does not lay the ground
work for the others.

The driver needs to be designed to support the other platforms.

Thanks,
Richard


Re: [RFC PATCH v2 1/2] macb: Add 1588 support in Cadence GEM.

2016-11-20 Thread Richard Cochran
On Fri, Nov 18, 2016 at 03:21:51PM +0100, Andrei Pistirica wrote:
> - Frequency adjustment is not directly supported by this IP.

This statement still makes no sense.  Doesn't the following text...

>   addend is the initial value ns increment and similarly addendesub.
>   The ppb (parts per billion) provided is used as
>   ns_incr = addend +/- (ppb/rate).
>   Similarly the remainder of the above is used to populate subns increment.

describe how frequency adjustment is in fact supported?

> +config MACB_USE_HWSTAMP
> + bool "Use IEEE 1588 hwstamp"
> + depends on MACB
> + default y
> + select PTP_1588_CLOCK

This "select" pattern is going to be replaced with "imply" soon.

   http://www.mail-archive.com/linux-kernel@vger.kernel.org/msg1269181.html

You should use the new "imply" key word and reference that series in
your change log.

> diff --git a/drivers/net/ethernet/cadence/macb.h 
> b/drivers/net/ethernet/cadence/macb.h
> index 3f385ab..2ee9af8 100644
> --- a/drivers/net/ethernet/cadence/macb.h
> +++ b/drivers/net/ethernet/cadence/macb.h
> @@ -10,6 +10,10 @@
>  #ifndef _MACB_H
>  #define _MACB_H
>  
> +#include 
> +#include 
> +#include 

Don't need net_tstamp.h here.  Move it into the .c file please.

> @@ -840,8 +902,26 @@ struct macb {
>  
>   unsigned intrx_frm_len_mask;
>   unsigned intjumbo_max_len;
> +
> +#ifdef CONFIG_MACB_USE_HWSTAMP
> + unsigned inthwts_tx_en;
> + unsigned inthwts_rx_en;

These two can be bool'eans.

> + spinlock_t  tsu_clk_lock;
> + unsigned inttsu_rate;
> +
> + struct ptp_clock*ptp_clock;
> + struct ptp_clock_info   ptp_caps;
> + unsigned intns_incr;
> + unsigned intsubns_incr;

These two are 32 bit register values, right?  Then use the u32 type.

> +#endif
>  };

> +static inline void macb_tsu_set_time(struct macb *bp,
> +  const struct timespec64 *ts)
> +{
> + u32 ns, sech, secl;
> + s64 word_mask = 0x;
> +
> + sech = (u32)ts->tv_sec;
> + secl = (u32)ts->tv_sec;
> + ns = ts->tv_nsec;
> + if (ts->tv_sec > word_mask)
> + sech = (ts->tv_sec >> 32);
> +
> + spin_lock(>tsu_clk_lock);
> +
> + /* TSH doesn't latch the time and no atomicity! */
> + gem_writel(bp, TSH, sech);
> + gem_writel(bp, TSL, secl);

If TN overflows here then the clock will be off by one whole second!
Why not clear TN first?

> + gem_writel(bp, TN, ns);
> +
> + spin_unlock(>tsu_clk_lock);
> +}
> +
> +static int macb_ptp_adjfreq(struct ptp_clock_info *ptp, s32 ppb)
> +{
> + struct macb *bp = container_of(ptp, struct macb, ptp_caps);
> + u32 addend, addend_frac, rem;
> + u64 drift_tmr, diff, diff_frac = 0;
> + int neg_adj = 0;
> +
> + if (ppb < 0) {
> + neg_adj = 1;
> + ppb = -ppb;
> + }
> +
> + /* drift/period */
> + drift_tmr = (bp->ns_incr * ppb) +
> + ((bp->subns_incr * ppb) >> 16);

What?  Why the 16 bit shift?  Last time your said it was 24 bits.

> + /* drift/cycle */
> + diff = div_u64_rem(drift_tmr, 10ULL, );
> +
> + /* drift fraction/cycle, if necessary */
> + if (rem) {
> + u64 fraction = rem;
> + fraction = fraction << 16;
> +
> + diff_frac = div_u64(fraction, 10ULL);

If you use a combined tuning word like I explained last time, then you
will not need a second division.

Also, please use the new adjfine() PHC method, as adjfreq() is now deprecated.

> + }
> +
> + /* adjustmets */
> + addend = neg_adj ? (bp->ns_incr - diff) : (bp->ns_incr + diff);
> + addend_frac = neg_adj ? (bp->subns_incr - diff_frac) :
> + (bp->subns_incr + diff_frac);
> +
> + spin_lock(>tsu_clk_lock);
> +
> + gem_writel(bp, TISUBN, GEM_BF(SUBNSINCR, addend_frac));
> + gem_writel(bp, TI, GEM_BF(NSINCR, addend));
> +
> + spin_unlock(>tsu_clk_lock);
> + return 0;
> +}

> +void macb_ptp_init(struct net_device *ndev)
> +{
> + struct macb *bp = netdev_priv(ndev);
> + struct timespec64 now;
> + u32 rem = 0;
> +
> + if (!(bp->caps | MACB_CAPS_GEM_HAS_PTP)){
> + netdev_vdbg(bp->dev, "Platform does not support PTP!\n");
> + return;
> + }
> +
> + spin_lock_init(>tsu_clk_lock);
> +
> + bp->ptp_caps = macb_ptp_caps;
> + bp->tsu_rate = clk_get_rate(bp->pclk);
> +
> + getnstimeofday64();
> + macb_tsu_set_time(bp, (const struct timespec64 *));
> +
> + bp->ns_incr = div_u64_rem(NSEC_PER_SEC, bp->tsu_rate, );
> + if (rem) {
> + u64 adj = rem;
> + /* Multiply by 2^16 as subns register is 16 bits */

Last time you said:
> + /* Multiple by 2^24 as subns field is 24 bits */

> + adj <<= 16;
> + bp->subns_incr = div_u64(adj, bp->tsu_rate);
> + } else {
> + 

[PATCH v2 net-next 2/6] net: dsa: mv88e6xxx: Fix unconditional irq freeing

2016-11-20 Thread Andrew Lunn
Trying to remove an IRQ domain that was not created results in an
Opps. Add the necessary checks that the irqs were created before
freeing them.

Signed-off-by: Andrew Lunn 
---
 drivers/net/dsa/mv88e6xxx/chip.c | 13 -
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/drivers/net/dsa/mv88e6xxx/chip.c b/drivers/net/dsa/mv88e6xxx/chip.c
index 6aa81d2d8f63..b843052d32bd 100644
--- a/drivers/net/dsa/mv88e6xxx/chip.c
+++ b/drivers/net/dsa/mv88e6xxx/chip.c
@@ -3897,10 +3897,11 @@ static int mv88e6xxx_probe(struct mdio_device *mdiodev)
 out_mdio:
mv88e6xxx_mdio_unregister(chip);
 out_g2_irq:
-   if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_INT))
+   if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_INT) && chip->irq > 0)
mv88e6xxx_g2_irq_free(chip);
 out_g1_irq:
-   mv88e6xxx_g1_irq_free(chip);
+   if (chip->irq > 0)
+   mv88e6xxx_g1_irq_free(chip);
 out:
return err;
 }
@@ -3914,9 +3915,11 @@ static void mv88e6xxx_remove(struct mdio_device *mdiodev)
mv88e6xxx_unregister_switch(chip);
mv88e6xxx_mdio_unregister(chip);
 
-   if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_INT))
-   mv88e6xxx_g2_irq_free(chip);
-   mv88e6xxx_g1_irq_free(chip);
+   if (chip->irq > 0) {
+   if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_INT))
+   mv88e6xxx_g2_irq_free(chip);
+   mv88e6xxx_g1_irq_free(chip);
+   }
 }
 
 static const struct of_device_id mv88e6xxx_of_match[] = {
-- 
2.10.2



[PATCH v2 net-next 0/6] Fixes for the MV88e6xxx interrupt code

2016-11-20 Thread Andrew Lunn
The interrupt code was never tested with a board who's probing
resulted in an -EPROBE_DEFFERED. So the clean up paths never got
tested. I now do have -EPROBE_DEFFERED, and things break badly during
cleanup. These are the fixes.

This is fixing code in net-next.

v2:
Fix typo pointed out by David Miller


Andrew Lunn (6):
  net: dsa: mv88e6xxx: Fix typos when removing g1 interrupts
  net: dsa: mv88e6xxx: Fix unconditional irq freeing
  net: dsa: mv88e6xxx: Mask g1 interrupts and free interrupt
  net: dsa: mv88e6xxx: Fix cleanup on error for g1 interrupt setup
  net: dsa: mv88e6xxx: Fix releasing for the global2 interrupts
  net: dsa: mv88e6xxx: Hold the mutex while freeing g1 interrupts

 drivers/net/dsa/mv88e6xxx/chip.c  | 58 ---
 drivers/net/dsa/mv88e6xxx/global2.c   | 28 +++--
 drivers/net/dsa/mv88e6xxx/mv88e6xxx.h |  1 +
 3 files changed, 59 insertions(+), 28 deletions(-)

-- 
2.10.2



[PATCH v2 net-next 6/6] net: dsa: mv88e6xxx: Hold the mutex while freeing g1 interrupts

2016-11-20 Thread Andrew Lunn
Freeing interrupts requires switch register access to mask the
interrupts. Hence we must hold the register mutex.

Signed-off-by: Andrew Lunn 
---
 drivers/net/dsa/mv88e6xxx/chip.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/net/dsa/mv88e6xxx/chip.c b/drivers/net/dsa/mv88e6xxx/chip.c
index 614b2f68d401..e30d0eaf2b5f 100644
--- a/drivers/net/dsa/mv88e6xxx/chip.c
+++ b/drivers/net/dsa/mv88e6xxx/chip.c
@@ -3916,8 +3916,11 @@ static int mv88e6xxx_probe(struct mdio_device *mdiodev)
if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_INT) && chip->irq > 0)
mv88e6xxx_g2_irq_free(chip);
 out_g1_irq:
-   if (chip->irq > 0)
+   if (chip->irq > 0) {
+   mutex_lock(>reg_lock);
mv88e6xxx_g1_irq_free(chip);
+   mutex_unlock(>reg_lock);
+   }
 out:
return err;
 }
-- 
2.10.2



[PATCH v2 net-next 3/6] net: dsa: mv88e6xxx: Mask g1 interrupts and free interrupt

2016-11-20 Thread Andrew Lunn
Fix the g1 interrupt free code such that is masks any further
interrupts, and then releases the interrupt.

Signed-off-by: Andrew Lunn 
---
 drivers/net/dsa/mv88e6xxx/chip.c | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/drivers/net/dsa/mv88e6xxx/chip.c b/drivers/net/dsa/mv88e6xxx/chip.c
index b843052d32bd..8fcef7e0d3ba 100644
--- a/drivers/net/dsa/mv88e6xxx/chip.c
+++ b/drivers/net/dsa/mv88e6xxx/chip.c
@@ -413,6 +413,13 @@ static const struct irq_domain_ops 
mv88e6xxx_g1_irq_domain_ops = {
 static void mv88e6xxx_g1_irq_free(struct mv88e6xxx_chip *chip)
 {
int irq, virq;
+   u16 mask;
+
+   mv88e6xxx_g1_read(chip, GLOBAL_CONTROL, );
+   mask |= GENMASK(chip->g1_irq.nirqs, 0);
+   mv88e6xxx_g1_write(chip, GLOBAL_CONTROL, mask);
+
+   free_irq(chip->irq, chip);
 
for (irq = 0; irq < 16; irq++) {
virq = irq_find_mapping(chip->g1_irq.domain, irq);
-- 
2.10.2



[PATCH v2 net-next 1/6] net: dsa: mv88e6xxx: Fix typos when removing g1 interrupts

2016-11-20 Thread Andrew Lunn
Simple typos, s/g2/g1/

Signed-off-by: Andrew Lunn 
---
 drivers/net/dsa/mv88e6xxx/chip.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/dsa/mv88e6xxx/chip.c b/drivers/net/dsa/mv88e6xxx/chip.c
index d6d9d66b81ce..6aa81d2d8f63 100644
--- a/drivers/net/dsa/mv88e6xxx/chip.c
+++ b/drivers/net/dsa/mv88e6xxx/chip.c
@@ -415,11 +415,11 @@ static void mv88e6xxx_g1_irq_free(struct mv88e6xxx_chip 
*chip)
int irq, virq;
 
for (irq = 0; irq < 16; irq++) {
-   virq = irq_find_mapping(chip->g2_irq.domain, irq);
+   virq = irq_find_mapping(chip->g1_irq.domain, irq);
irq_dispose_mapping(virq);
}
 
-   irq_domain_remove(chip->g2_irq.domain);
+   irq_domain_remove(chip->g1_irq.domain);
 }
 
 static int mv88e6xxx_g1_irq_setup(struct mv88e6xxx_chip *chip)
-- 
2.10.2



[PATCH v2 net-next 5/6] net: dsa: mv88e6xxx: Fix releasing for the global2 interrupts

2016-11-20 Thread Andrew Lunn
It is not possible to use devm_request_threaded_irq() because we have
two stacked interrupt controllers in one device. The lower interrupt
controller cannot be removed until the upper is fully removed. This
happens too late with the devm API, resulting in error messages about
removing a domain while there is still an active interrupt. Swap to
using request_threaded_irq() and manage the release of the interrupt
manually.

Signed-off-by: Andrew Lunn 
---
v2: Fix device_irq typo spotted by David Miller.
---
 drivers/net/dsa/mv88e6xxx/global2.c   | 28 ++--
 drivers/net/dsa/mv88e6xxx/mv88e6xxx.h |  1 +
 2 files changed, 19 insertions(+), 10 deletions(-)

diff --git a/drivers/net/dsa/mv88e6xxx/global2.c 
b/drivers/net/dsa/mv88e6xxx/global2.c
index 1a0b13521d13..536a27c9735f 100644
--- a/drivers/net/dsa/mv88e6xxx/global2.c
+++ b/drivers/net/dsa/mv88e6xxx/global2.c
@@ -507,6 +507,9 @@ void mv88e6xxx_g2_irq_free(struct mv88e6xxx_chip *chip)
 {
int irq, virq;
 
+   free_irq(chip->device_irq, chip);
+   irq_dispose_mapping(chip->device_irq);
+
for (irq = 0; irq < 16; irq++) {
virq = irq_find_mapping(chip->g2_irq.domain, irq);
irq_dispose_mapping(virq);
@@ -517,8 +520,7 @@ void mv88e6xxx_g2_irq_free(struct mv88e6xxx_chip *chip)
 
 int mv88e6xxx_g2_irq_setup(struct mv88e6xxx_chip *chip)
 {
-   int device_irq;
-   int err, irq;
+   int err, irq, virq;
 
if (!chip->dev->of_node)
return -EINVAL;
@@ -534,22 +536,28 @@ int mv88e6xxx_g2_irq_setup(struct mv88e6xxx_chip *chip)
chip->g2_irq.chip = mv88e6xxx_g2_irq_chip;
chip->g2_irq.masked = ~0;
 
-   device_irq = irq_find_mapping(chip->g1_irq.domain,
- GLOBAL_STATUS_IRQ_DEVICE);
-   if (device_irq < 0) {
-   err = device_irq;
+   chip->device_irq = irq_find_mapping(chip->g1_irq.domain,
+   GLOBAL_STATUS_IRQ_DEVICE);
+   if (chip->device_irq < 0) {
+   err = chip->device_irq;
goto out;
}
 
-   err = devm_request_threaded_irq(chip->dev, device_irq, NULL,
-   mv88e6xxx_g2_irq_thread_fn,
-   IRQF_ONESHOT, "mv88e6xxx-g1", chip);
+   err = request_threaded_irq(chip->device_irq, NULL,
+  mv88e6xxx_g2_irq_thread_fn,
+  IRQF_ONESHOT, "mv88e6xxx-g1", chip);
if (err)
goto out;
 
return 0;
+
 out:
-   mv88e6xxx_g2_irq_free(chip);
+   for (irq = 0; irq < 16; irq++) {
+   virq = irq_find_mapping(chip->g2_irq.domain, irq);
+   irq_dispose_mapping(virq);
+   }
+
+   irq_domain_remove(chip->g2_irq.domain);
 
return err;
 }
diff --git a/drivers/net/dsa/mv88e6xxx/mv88e6xxx.h 
b/drivers/net/dsa/mv88e6xxx/mv88e6xxx.h
index 929613021eff..a3869504f881 100644
--- a/drivers/net/dsa/mv88e6xxx/mv88e6xxx.h
+++ b/drivers/net/dsa/mv88e6xxx/mv88e6xxx.h
@@ -714,6 +714,7 @@ struct mv88e6xxx_chip {
struct mv88e6xxx_irq g1_irq;
struct mv88e6xxx_irq g2_irq;
int irq;
+   int device_irq;
 };
 
 struct mv88e6xxx_bus_ops {
-- 
2.10.2



[PATCH v2 net-next 4/6] net: dsa: mv88e6xxx: Fix cleanup on error for g1 interrupt setup

2016-11-20 Thread Andrew Lunn
On error, remask the interrupts, release all maps, and remove the
domain. This cannot be done using the mv88e6xxx_g1_irq_free() because
some of these actions are not idempotent.

Signed-off-by: Andrew Lunn 
---
 drivers/net/dsa/mv88e6xxx/chip.c | 31 ---
 1 file changed, 20 insertions(+), 11 deletions(-)

diff --git a/drivers/net/dsa/mv88e6xxx/chip.c b/drivers/net/dsa/mv88e6xxx/chip.c
index 8fcef7e0d3ba..614b2f68d401 100644
--- a/drivers/net/dsa/mv88e6xxx/chip.c
+++ b/drivers/net/dsa/mv88e6xxx/chip.c
@@ -431,8 +431,8 @@ static void mv88e6xxx_g1_irq_free(struct mv88e6xxx_chip 
*chip)
 
 static int mv88e6xxx_g1_irq_setup(struct mv88e6xxx_chip *chip)
 {
-   int err, irq;
-   u16 reg;
+   int err, irq, virq;
+   u16 reg, mask;
 
chip->g1_irq.nirqs = chip->info->g1_irqs;
chip->g1_irq.domain = irq_domain_add_simple(
@@ -447,32 +447,41 @@ static int mv88e6xxx_g1_irq_setup(struct mv88e6xxx_chip 
*chip)
chip->g1_irq.chip = mv88e6xxx_g1_irq_chip;
chip->g1_irq.masked = ~0;
 
-   err = mv88e6xxx_g1_read(chip, GLOBAL_CONTROL, );
+   err = mv88e6xxx_g1_read(chip, GLOBAL_CONTROL, );
if (err)
-   goto out;
+   goto out_mapping;
 
-   reg &= ~GENMASK(chip->g1_irq.nirqs, 0);
+   mask &= ~GENMASK(chip->g1_irq.nirqs, 0);
 
-   err = mv88e6xxx_g1_write(chip, GLOBAL_CONTROL, reg);
+   err = mv88e6xxx_g1_write(chip, GLOBAL_CONTROL, mask);
if (err)
-   goto out;
+   goto out_disable;
 
/* Reading the interrupt status clears (most of) them */
err = mv88e6xxx_g1_read(chip, GLOBAL_STATUS, );
if (err)
-   goto out;
+   goto out_disable;
 
err = request_threaded_irq(chip->irq, NULL,
   mv88e6xxx_g1_irq_thread_fn,
   IRQF_ONESHOT | IRQF_TRIGGER_FALLING,
   dev_name(chip->dev), chip);
if (err)
-   goto out;
+   goto out_disable;
 
return 0;
 
-out:
-   mv88e6xxx_g1_irq_free(chip);
+out_disable:
+   mask |= GENMASK(chip->g1_irq.nirqs, 0);
+   mv88e6xxx_g1_write(chip, GLOBAL_CONTROL, mask);
+
+out_mapping:
+   for (irq = 0; irq < 16; irq++) {
+   virq = irq_find_mapping(chip->g1_irq.domain, irq);
+   irq_dispose_mapping(virq);
+   }
+
+   irq_domain_remove(chip->g1_irq.domain);
 
return err;
 }
-- 
2.10.2



Re: [PATCH net 07/18] net/ena: refactor ena_get_stats64 to be atomic context safe

2016-11-20 Thread Netanel Belgazal
This warning isn't a real issue since adapter->num_queues can't be zero.
Anyway, I'll use the adapter's syncp in V2 to avoid this warning.

On 11/20/2016 12:09 PM, kbuild test robot wrote:
> Hi Netanel,
>
> [auto build test WARNING on net/master]
>
> url:
> https://github.com/0day-ci/linux/commits/Netanel-Belgazal/Update-ENA-driver-to-version-1-1-2/20161120-165649
> config: i386-randconfig-x009-201647 (attached as .config)
> compiler: gcc-6 (Debian 6.2.0-3) 6.2.0 20160901
> reproduce:
> # save the attached .config to linux build tree
> make ARCH=i386 
>
> 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 >>):
>
>Cyclomatic Complexity 2 
> drivers/net/ethernet/amazon/ena/ena_netdev.c:ena_napi_enable_all
>Cyclomatic Complexity 1 include/linux/dma-mapping.h:dma_map_single_attrs
>Cyclomatic Complexity 1 include/linux/dynamic_queue_limits.h:dql_queued
>Cyclomatic Complexity 3 include/linux/netdevice.h:netdev_tx_sent_queue
>Cyclomatic Complexity 1 include/linux/netdevice.h:dev_kfree_skb_any
>Cyclomatic Complexity 1 include/linux/netdevice.h:netdev_tx_reset_queue
>Cyclomatic Complexity 6 
> drivers/net/ethernet/amazon/ena/ena_netdev.c:ena_free_tx_bufs
>Cyclomatic Complexity 2 
> drivers/net/ethernet/amazon/ena/ena_netdev.c:ena_free_all_tx_bufs
>Cyclomatic Complexity 3 
> drivers/net/ethernet/amazon/ena/ena_netdev.c:ena_free_rx_page
>Cyclomatic Complexity 3 
> drivers/net/ethernet/amazon/ena/ena_netdev.c:ena_free_rx_bufs
>Cyclomatic Complexity 2 
> drivers/net/ethernet/amazon/ena/ena_netdev.c:ena_free_all_rx_bufs
>Cyclomatic Complexity 2 
> drivers/net/ethernet/amazon/ena/ena_netdev.c:ena_down
>Cyclomatic Complexity 4 
> drivers/net/ethernet/amazon/ena/ena_netdev.c:ena_close
>Cyclomatic Complexity 3 
> drivers/net/ethernet/amazon/ena/ena_netdev.c:ena_update_on_link_change
>Cyclomatic Complexity 2 include/linux/netdevice.h:napi_schedule_irqoff
>Cyclomatic Complexity 1 
> drivers/net/ethernet/amazon/ena/ena_netdev.c:ena_intr_msix_io
>Cyclomatic Complexity 4 include/linux/cpumask.h:cpumask_check
>Cyclomatic Complexity 1 include/linux/cpumask.h:cpumask_set_cpu
>Cyclomatic Complexity 2 
> drivers/net/ethernet/amazon/ena/ena_netdev.c:ena_setup_io_intr
>Cyclomatic Complexity 1 include/linux/interrupt.h:request_irq
>Cyclomatic Complexity 9 
> drivers/net/ethernet/amazon/ena/ena_netdev.c:ena_request_io_irq
>Cyclomatic Complexity 5 
> drivers/net/ethernet/amazon/ena/ena_netdev.c:ena_request_mgmnt_irq
>Cyclomatic Complexity 8 
> drivers/net/ethernet/amazon/ena/ena_netdev.c:ena_setup_tx_resources
>Cyclomatic Complexity 5 
> drivers/net/ethernet/amazon/ena/ena_netdev.c:ena_setup_all_tx_resources
>Cyclomatic Complexity 5 
> drivers/net/ethernet/amazon/ena/ena_netdev.c:ena_setup_rx_resources
>Cyclomatic Complexity 5 
> drivers/net/ethernet/amazon/ena/ena_netdev.c:ena_setup_all_rx_resources
>Cyclomatic Complexity 5 
> drivers/net/ethernet/amazon/ena/ena_netdev.c:ena_create_io_tx_queue
>Cyclomatic Complexity 4 
> drivers/net/ethernet/amazon/ena/ena_netdev.c:ena_create_all_io_tx_queues
>Cyclomatic Complexity 5 
> drivers/net/ethernet/amazon/ena/ena_netdev.c:ena_create_io_rx_queue
>Cyclomatic Complexity 4 
> drivers/net/ethernet/amazon/ena/ena_netdev.c:ena_create_all_io_rx_queues
>Cyclomatic Complexity 2 
> drivers/net/ethernet/amazon/ena/ena_netdev.c:ena_init_napi
>Cyclomatic Complexity 4 
> drivers/net/ethernet/amazon/ena/ena_eth_com.h:ena_com_update_dev_comp_head
>Cyclomatic Complexity 2 
> drivers/net/ethernet/amazon/ena/ena_eth_com.h:ena_com_write_sq_doorbell
>Cyclomatic Complexity 4 include/linux/netdevice.h:netdev_tx_completed_queue
>Cyclomatic Complexity 14 
> drivers/net/ethernet/amazon/ena/ena_netdev.c:ena_clean_tx_irq
>Cyclomatic Complexity 2 include/linux/netdevice.h:netif_tx_unlock
>Cyclomatic Complexity 1 include/linux/skbuff.h:__netdev_alloc_skb_ip_align
>Cyclomatic Complexity 1 include/linux/skbuff.h:netdev_alloc_skb_ip_align
>Cyclomatic Complexity 16 
> drivers/net/ethernet/amazon/ena/ena_netdev.c:ena_rx_skb
>Cyclomatic Complexity 1 include/linux/gfp.h:__alloc_pages
>Cyclomatic Complexity 1 include/linux/gfp.h:__alloc_pages_node
>Cyclomatic Complexity 2 include/linux/gfp.h:alloc_pages_node
>Cyclomatic Complexity 6 
> drivers/net/ethernet/amazon/ena/ena_netdev.c:ena_alloc_rx_page
>Cyclomatic Complexity 8 
> drivers/net/ethernet/amazon/ena/ena_netdev.c:ena_refill_rx_bufs
>Cyclomatic Complexity 11 
> drivers/net/ethernet/a

Re: [PATCH net 00/18] Update ENA driver to version 1.1.2

2016-11-20 Thread Netanel Belgazal
Hi David,

Sorry for not being clear on my first patch set.

Those changes introduce some bug fixes, new features and some cleanups that 
matching the driver to the upstream standard.

Bug Fixes:
*net/ena: remove RFS support from device feature list
*net/ena: fix queues number calculation
*net/ena: fix ethtool RSS flow configuration
*net/ena: refactor ena_get_stats64 to be atomic context safe
*net/ena: fix potential access to freed memory during device reset
*net/ena: remove redundant logic in napi callback for busy poll mode
*net/ena: fix error handling when probe fails
*net/ena: fix NULL dereference when removing the driver after device
reset faild
*net/ena: change driver's default timeouts and increase driver version

New Features:
*net/ena: add hardware hints capability to the driver
*net/ena: change condition for host attribute configuration
*net/ena: add IPv6 extended protocols to ena_admin_flow_hash_proto
*net/ena: remove affinity hint from the driver

Clean ups:
*net/ena: use napi_schedule_irqoff when possible
*net/ena: reduce the severity of ena printouts
*net/ena: change sizeof() argument to be the type pointer
*net/ena: use READ_ONCE to access completion descriptors
*net/ena: refactor skb allocation

I'll add the above description in V2 (I would like to wait a couple of days to 
collect more feedback about those patches).

Regards,
Netanel

On 11/20/2016 05:24 PM, David Miller wrote:
> From: Netanel Belgazal 
> Date: Sun, 20 Nov 2016 10:45:29 +0200
>
>> Update Amazon's Elastic Network Adapter (ENA) driver version from 1.0.2 to 
>> 1.1.2
> This is insufficient.
>
> You must explain what this patch series is doing, how it is doing it,
> and why it is doing it that way.
>
> This is the message that people will look at to learn what is
> contained in this series of patches, and they might be looking for
> keywords or explanations as to why a decision was made to add a
> feature, turn a feature off, or make some other important high level
> change to the driver.



[PATCH v2] ethernet: stmmac: make DWMAC_STM32 depend on it's associated SoC

2016-11-20 Thread Peter Robinson
There's not much point, except compile test, enabling the stmmac
platform drivers unless the STM32 SoC is enabled. It's not
useful without it.

Signed-off-by: Peter Robinson 
---
 drivers/net/ethernet/stmicro/stmmac/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/Kconfig 
b/drivers/net/ethernet/stmicro/stmmac/Kconfig
index 3818c5e..4b78168 100644
--- a/drivers/net/ethernet/stmicro/stmmac/Kconfig
+++ b/drivers/net/ethernet/stmicro/stmmac/Kconfig
@@ -107,7 +107,7 @@ config DWMAC_STI
 config DWMAC_STM32
tristate "STM32 DWMAC support"
default ARCH_STM32
-   depends on OF && HAS_IOMEM
+   depends on OF && HAS_IOMEM && (ARCH_STM32 || COMPILE_TEST)
select MFD_SYSCON
---help---
  Support for ethernet controller on STM32 SOCs.
-- 
2.9.3



Re: [PATCH net-next 1/1] driver: macvlan: Remove duplicated IFF_UP condition check in macvlan_forward_source_one

2016-11-20 Thread Eric Dumazet
On Sun, 2016-11-20 at 19:21 +0800, f...@ikuai8.com wrote:
> From: Gao Feng 
> 
> The condition check "dev->flags & IFF_UP" is duplicated in
> macvlan_forward_source_one, because its caller macvlan_forward_source
> has already checked this flag.
> 
> Signed-off-by: Gao Feng 
> ---
>  drivers/net/macvlan.c | 3 ---
>  1 file changed, 3 deletions(-)
> 
> diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
> index 13b7e0b..95a5ffc 100644
> --- a/drivers/net/macvlan.c
> +++ b/drivers/net/macvlan.c
> @@ -375,9 +375,6 @@ static void macvlan_forward_source_one(struct sk_buff 
> *skb,
>   int ret;
>  
>   dev = vlan->dev;
> - if (unlikely(!(dev->flags & IFF_UP)))
> - return;
> -
>   nskb = skb_clone(skb, GFP_ATOMIC);
>   if (!nskb)
>   return;

If you don't mind, I would rather remove the test in the caller and
leave it here. It is likely compiler inlines the function anyway, so
there is no performance change.




Re: [PATCH] [v2] net: phy: phy drivers should not set SUPPORTED_[Asym_]Pause

2016-11-20 Thread Florian Fainelli


On 11/20/2016 08:08 AM, Timur Tabi wrote:
> On Mon, Nov 14, 2016 at 12:35 PM, Florian Fainelli  
> wrote:
>> if (!(drv->features & (SUPPORTED_Pause | SUPPORTED_AsymPause))
>> phydev->supported |= SUPPORTED_Pause | SUPPORTED_AsymPause;
> 
> How about, if either bit is set in drv->features, then assume the phy
> driver really knows what it's doing, and just copy those bits to
> phydev->supported?

Yes, that seems completely reasonable to me. Thanks!

> 
> if (drv->features & (SUPPORTED_Pause | SUPPORTED_AsymPause)) {
> phydev->supported &= ~(SUPPORTED_Pause | SUPPORTED_AsymPause);
> phydev->supported |= drv->features & (SUPPORTED_Pause |
> SUPPORTED_AsymPause);
> } else
> phydev->supported |= SUPPORTED_Pause | SUPPORTED_AsymPause;
> 

-- 
Florian


Re: [PATCH v2 net-next] mlx4: avoid unnecessary dirtying of critical fields

2016-11-20 Thread Eric Dumazet
On Sun, 2016-11-20 at 09:24 -0800, Eric Dumazet wrote:

>   /* Current cpu is not according to smp_irq_affinity -
> -  * probably affinity changed. need to stop this NAPI
> -  * poll, and restart it on the right CPU
> +  * probably affinity changed. Need to stop this NAPI
> +  * poll, and restart it on the right CPU.
> +  * Try to avoid returning a too small value (like 0),
> +  * to not fool net_rx_action() and its netdev_budget
>*/
> - done = 0;
> + if (done)
> + done--;


Note : This could have been a net candidate, but bug is minor and I
prefer to avoid a merge conflict, since net-next has the additional if
around the napi_complete_done() call.


>   }
>   /* Done for now */
>   if (napi_complete_done(napi, done))
> 





[PATCH v2 net-next] mlx4: avoid unnecessary dirtying of critical fields

2016-11-20 Thread Eric Dumazet
From: Eric Dumazet 

While stressing a 40Gbit mlx4 NIC with busy polling, I found false
sharing in mlx4 driver that can be easily avoided.

This patch brings an additional 7 % performance improvement in UDP_RR
workload.

1) If we received no frame during one mlx4_en_process_rx_cq()
   invocation, no need to call mlx4_cq_set_ci() and/or dirty ring->cons

2) Do not refill rx buffers if we have plenty of them.
   This avoids false sharing and allows some bulk/batch optimizations.
   Page allocator and its locks will thank us.

Finally, mlx4_en_poll_rx_cq() should not return 0 if it determined
cpu handling NIC IRQ should be changed. We should return budget-1
instead, to not fool net_rx_action() and its netdev_budget.


v2: keep AVG_PERF_COUNTER(... polled) even if polled is 0

Signed-off-by: Eric Dumazet 
Cc: Tariq Toukan 
---
 drivers/net/ethernet/mellanox/mlx4/en_rx.c |   47 ---
 1 file changed, 30 insertions(+), 17 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx4/en_rx.c 
b/drivers/net/ethernet/mellanox/mlx4/en_rx.c
index 
22f08f9ef4645869359783823127c0432fc7a591..6562f78b07f4370b5c1ea2c5e3a4221d7ebaeba8
 100644
--- a/drivers/net/ethernet/mellanox/mlx4/en_rx.c
+++ b/drivers/net/ethernet/mellanox/mlx4/en_rx.c
@@ -688,18 +688,23 @@ static void validate_loopback(struct mlx4_en_priv *priv, 
struct sk_buff *skb)
dev_kfree_skb_any(skb);
 }
 
-static void mlx4_en_refill_rx_buffers(struct mlx4_en_priv *priv,
-struct mlx4_en_rx_ring *ring)
+static bool mlx4_en_refill_rx_buffers(struct mlx4_en_priv *priv,
+ struct mlx4_en_rx_ring *ring)
 {
-   int index = ring->prod & ring->size_mask;
+   u32 missing = ring->actual_size - (ring->prod - ring->cons);
 
-   while ((u32) (ring->prod - ring->cons) < ring->actual_size) {
-   if (mlx4_en_prepare_rx_desc(priv, ring, index,
+   /* Try to batch allocations, but not too much. */
+   if (missing < 8)
+   return false;
+   do {
+   if (mlx4_en_prepare_rx_desc(priv, ring,
+   ring->prod & ring->size_mask,
GFP_ATOMIC | __GFP_COLD))
break;
ring->prod++;
-   index = ring->prod & ring->size_mask;
-   }
+   } while (--missing);
+
+   return true;
 }
 
 /* When hardware doesn't strip the vlan, we need to calculate the checksum
@@ -1081,15 +1086,20 @@ int mlx4_en_process_rx_cq(struct net_device *dev, 
struct mlx4_en_cq *cq, int bud
 
 out:
rcu_read_unlock();
-   if (doorbell_pending)
-   mlx4_en_xmit_doorbell(priv->tx_ring[TX_XDP][cq->ring]);
 
+   if (polled) {
+   if (doorbell_pending)
+   mlx4_en_xmit_doorbell(priv->tx_ring[TX_XDP][cq->ring]);
+
+   mlx4_cq_set_ci(>mcq);
+   wmb(); /* ensure HW sees CQ consumer before we post new buffers 
*/
+   ring->cons = cq->mcq.cons_index;
+   }
AVG_PERF_COUNTER(priv->pstats.rx_coal_avg, polled);
-   mlx4_cq_set_ci(>mcq);
-   wmb(); /* ensure HW sees CQ consumer before we post new buffers */
-   ring->cons = cq->mcq.cons_index;
-   mlx4_en_refill_rx_buffers(priv, ring);
-   mlx4_en_update_rx_prod_db(ring);
+
+   if (mlx4_en_refill_rx_buffers(priv, ring))
+   mlx4_en_update_rx_prod_db(ring);
+
return polled;
 }
 
@@ -1131,10 +1141,13 @@ int mlx4_en_poll_rx_cq(struct napi_struct *napi, int 
budget)
return budget;
 
/* Current cpu is not according to smp_irq_affinity -
-* probably affinity changed. need to stop this NAPI
-* poll, and restart it on the right CPU
+* probably affinity changed. Need to stop this NAPI
+* poll, and restart it on the right CPU.
+* Try to avoid returning a too small value (like 0),
+* to not fool net_rx_action() and its netdev_budget
 */
-   done = 0;
+   if (done)
+   done--;
}
/* Done for now */
if (napi_complete_done(napi, done))




Re: [PATCH net-next] mlx4: avoid unnecessary dirtying of critical fields

2016-11-20 Thread Eric Dumazet
On Sun, 2016-11-20 at 17:14 +0200, Tariq Toukan wrote:
> Hi Eric,
> 
> Thanks for your patch.
> 
> On 18/11/2016 10:15 PM, Eric Dumazet wrote:
> > +
> > +   AVG_PERF_COUNTER(priv->pstats.rx_coal_avg, polled);
> Keep this perf stats update out of the if block.

This perf stat would be useless then with busy polling.

And this would be the the only source of false sharing in the driver.

Not that I particularly care, since AVG_PERF_COUNTER can not be enabled
without modifying / recompiling the driver.







Re: [PATCH] [v2] net: phy: phy drivers should not set SUPPORTED_[Asym_]Pause

2016-11-20 Thread Timur Tabi
On Mon, Nov 14, 2016 at 12:35 PM, Florian Fainelli  wrote:
> if (!(drv->features & (SUPPORTED_Pause | SUPPORTED_AsymPause))
> phydev->supported |= SUPPORTED_Pause | SUPPORTED_AsymPause;

How about, if either bit is set in drv->features, then assume the phy
driver really knows what it's doing, and just copy those bits to
phydev->supported?

if (drv->features & (SUPPORTED_Pause | SUPPORTED_AsymPause)) {
phydev->supported &= ~(SUPPORTED_Pause | SUPPORTED_AsymPause);
phydev->supported |= drv->features & (SUPPORTED_Pause |
SUPPORTED_AsymPause);
} else
phydev->supported |= SUPPORTED_Pause | SUPPORTED_AsymPause;

-- 
Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project.


Re: [PATCH net-next] mlx4: avoid unnecessary dirtying of critical fields

2016-11-20 Thread Tariq Toukan

Hi Eric,

Thanks for your patch.

On 18/11/2016 10:15 PM, Eric Dumazet wrote:

From: Eric Dumazet 

While stressing a 40Gbit mlx4 NIC with busy polling, I found false
sharing in mlx4 driver that can be easily avoided.

This patch brings an additional 7 % performance improvement in UDP_RR
workload.

1) If we received no frame during one mlx4_en_process_rx_cq()
invocation, no need to call mlx4_cq_set_ci() and/or dirty ring->cons

2) Do not refill rx buffers if we have plenty of them.
This avoids false sharing and allows some bulk/batch optimizations.
Page allocator and its locks will thank us.

Finally, mlx4_en_poll_rx_cq() should not return 0 if it determined
cpu handling NIC IRQ should be changed. We should return budget-1
instead, to not fool net_rx_action() and its netdev_budget.

Signed-off-by: Eric Dumazet 
Cc: Tariq Toukan 
---
  drivers/net/ethernet/mellanox/mlx4/en_rx.c |   51 +++
  1 file changed, 32 insertions(+), 19 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx4/en_rx.c 
b/drivers/net/ethernet/mellanox/mlx4/en_rx.c
index 22f08f9ef464..2112494ff43b 100644
--- a/drivers/net/ethernet/mellanox/mlx4/en_rx.c
+++ b/drivers/net/ethernet/mellanox/mlx4/en_rx.c
@@ -688,18 +688,23 @@ static void validate_loopback(struct mlx4_en_priv *priv, 
struct sk_buff *skb)
dev_kfree_skb_any(skb);
  }
  
-static void mlx4_en_refill_rx_buffers(struct mlx4_en_priv *priv,

-struct mlx4_en_rx_ring *ring)
+static bool mlx4_en_refill_rx_buffers(struct mlx4_en_priv *priv,
+ struct mlx4_en_rx_ring *ring)
  {
-   int index = ring->prod & ring->size_mask;
+   u32 missing = ring->actual_size - (ring->prod - ring->cons);
  
-	while ((u32) (ring->prod - ring->cons) < ring->actual_size) {

-   if (mlx4_en_prepare_rx_desc(priv, ring, index,
+   /* Try to batch allocations, but not too much. */
+   if (missing < 8)
+   return false;
+   do {
+   if (mlx4_en_prepare_rx_desc(priv, ring,
+   ring->prod & ring->size_mask,
GFP_ATOMIC | __GFP_COLD))
break;
ring->prod++;
-   index = ring->prod & ring->size_mask;
-   }
+   } while (--missing);
+
+   return true;
  }
  
  /* When hardware doesn't strip the vlan, we need to calculate the checksum

@@ -1081,15 +1086,20 @@ int mlx4_en_process_rx_cq(struct net_device *dev, 
struct mlx4_en_cq *cq, int bud
  
  out:

rcu_read_unlock();
-   if (doorbell_pending)
-   mlx4_en_xmit_doorbell(priv->tx_ring[TX_XDP][cq->ring]);
-
-   AVG_PERF_COUNTER(priv->pstats.rx_coal_avg, polled);
-   mlx4_cq_set_ci(>mcq);
-   wmb(); /* ensure HW sees CQ consumer before we post new buffers */
-   ring->cons = cq->mcq.cons_index;
-   mlx4_en_refill_rx_buffers(priv, ring);
-   mlx4_en_update_rx_prod_db(ring);
+
+   if (polled) {
+   if (doorbell_pending)
+   mlx4_en_xmit_doorbell(priv->tx_ring[TX_XDP][cq->ring]);
+
+   AVG_PERF_COUNTER(priv->pstats.rx_coal_avg, polled);

Keep this perf stats update out of the if block.

+   mlx4_cq_set_ci(>mcq);
+   wmb(); /* ensure HW sees CQ consumer before we post new buffers 
*/
+   ring->cons = cq->mcq.cons_index;
+   }
+
+   if (mlx4_en_refill_rx_buffers(priv, ring))
+   mlx4_en_update_rx_prod_db(ring);
+
return polled;
  }
  
@@ -1131,10 +1141,13 @@ int mlx4_en_poll_rx_cq(struct napi_struct *napi, int budget)

return budget;
  
  		/* Current cpu is not according to smp_irq_affinity -

-* probably affinity changed. need to stop this NAPI
-* poll, and restart it on the right CPU
+* probably affinity changed. Need to stop this NAPI
+* poll, and restart it on the right CPU.
+* Try to avoid returning a too small value (like 0),
+* to not fool net_rx_action() and its netdev_budget
 */
-   done = 0;
+   if (done)
+   done--;
}
/* Done for now */
if (napi_complete_done(napi, done))



It looks good to me, just the one comment aforementioned.

Regards,
Tariq


Re: [PATCH net 00/18] Update ENA driver to version 1.1.2

2016-11-20 Thread David Miller
From: Netanel Belgazal 
Date: Sun, 20 Nov 2016 10:45:29 +0200

> Update Amazon's Elastic Network Adapter (ENA) driver version from 1.0.2 to 
> 1.1.2

This is insufficient.

You must explain what this patch series is doing, how it is doing it,
and why it is doing it that way.

This is the message that people will look at to learn what is
contained in this series of patches, and they might be looking for
keywords or explanations as to why a decision was made to add a
feature, turn a feature off, or make some other important high level
change to the driver.


Re: net/sctp: BUG: KASAN: stack-out-of-bounds in memcmp

2016-11-20 Thread Xin Long
On Sat, Nov 12, 2016 at 6:12 PM, Baozeng Ding  wrote:
>
>
> On 2016/11/10 13:48, Xin Long wrote:
>> On Sat, Oct 15, 2016 at 4:28 PM, Baozeng Ding  wrote:
>>> Hello Xin Long,
>>>
>>> On 2016/10/14 19:13, Xin Long wrote:
 On Sat, Aug 20, 2016 at 3:51 PM, Baozeng Ding  wrote:
> Hello all,
> The following program triggers  stack-out-of-bounds in memcmp. The kernel 
> version is 4.8.0-rc1+ (on Aug 13 commit 
> 118253a593bd1c57de2d1193df1ccffe1abe745b). Thanks.
 ...
>
> #define _GNU_SOURCE
> #include 
> #include 
> #include 
> #include 
> #include 
> #include 
> #include 
> #include 
>
> int main()
> {
> int fd;
> mmap((void *)0x2000ul, 0xff2000ul, 0x3ul, 0x32ul, -1, 0x0ul);
> fd = socket(AF_INET6, SOCK_STREAM, IPPROTO_SCTP);
> memcpy((void*)0x20f82f80, 
> "\x0a\x00\xab\x12\x72\xd4\x19\x9a\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x85\xda\x00\xa0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
>  128);
> bind(fd, (struct sockaddr*)0x20f82f80ul, 0x80ul);
> *(uint64_t*)0x202e1fc8 = (uint64_t)0x20f77f80;
> *(uint32_t*)0x202e1fd0 = (uint32_t)0x80;
> *(uint64_t*)0x202e1fd8 = (uint64_t)0x20f7dfe0;
> *(uint64_t*)0x202e1fe0 = (uint64_t)0x2;
> *(uint64_t*)0x202e1fe8 = (uint64_t)0x20f77000;
> *(uint64_t*)0x202e1ff0 = (uint64_t)0x3;
> *(uint32_t*)0x202e1ff8 = (uint32_t)0x80;
> memcpy((void*)0x20f77f80, 
> "\x0a\x00\xab\x12\xb0\xb3\x20\x7b\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\xc2\xc2\x0b\xb2\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
>  128);
> *(uint64_t*)0x20f7dfe0 = (uint64_t)0x20f77fc5;
> *(uint64_t*)0x20f7dfe8 = (uint64_t)0x3b;
> *(uint64_t*)0x20f7dff0 = (uint64_t)0x20f77fac;
> *(uint64_t*)0x20f7dff8 = (uint64_t)0x54;
> memcpy((void*)0x20f77fc5, 
> "\xa5\x7d\xf3\xc4\xfe\xd3\xfd\x44\x63\x00\x8c\x1e\x4c\x2e\x8d\x8d\x9a\x9c\x9c\x9d\x5b\x7c\xe1\x06\xf7\x15\x16\xed\x68\xd1\xfc\xf4\xa4\x3a\xe4\x69\x51\x16\x74\xf4\x1a\xcf\x0e\x99\xc3\xa3\x87\xe7\x81\x6c\x10\x78\x75\x17\x69\x9d\x11\x0c\xc7",
>  59);
> memcpy((void*)0x20f77fac, 
> "\x86\x08\x89\x3c\xf3\x58\xea\xe7\x64\x6a\xfb\xb5\xe8\xdd\x5f\x69\xa5\xd4\xdc\xd9\xe7\x71\x95\x07\x78\x7b\x21\xda\x43\x9c\x62\x4d\xca\x64\xb5\x6e\x96\x55\xe9\x58\x76\x66\x1d\xb9\x7b\xe6\x20\xc1\xa9\xed\x70\xc1\x2b\x7c\x86\x8c\xba\x28\xb3\x2c\xb9\x64\xb7\x84\x65\x0d\x7f\xa6\x98\x6f\x49\xcb\x35\xad\x5a\xdf\x13\x75\x99\x57\x7e\xbb\x38\x89",
>  84);
> *(uint64_t*)0x20f77000 = (uint64_t)0x15;
> *(uint32_t*)0x20f77008 = (uint32_t)0x1;
> *(uint32_t*)0x20f7700c = (uint32_t)0xfffe;
> *(uint8_t*)0x20f77010 = (uint8_t)0xbb;
> *(uint8_t*)0x20f77011 = (uint8_t)0x2;
> *(uint8_t*)0x20f77012 = (uint8_t)0x5;
> *(uint8_t*)0x20f77013 = (uint8_t)0x2;
> *(uint8_t*)0x20f77014 = (uint8_t)0x8000;
> *(uint64_t*)0x20f77015 = (uint64_t)0x10;
> *(uint32_t*)0x20f7701d = (uint32_t)0x;
> *(uint32_t*)0x20f77021 = (uint32_t)0x1;
> *(uint64_t*)0x20f77025 = (uint64_t)0x13;
> *(uint32_t*)0x20f7702d = (uint32_t)0x6;
> *(uint32_t*)0x20f77031 = (uint32_t)0xfe00;
> *(uint8_t*)0x20f77035 = (uint8_t)0x8000;
> *(uint8_t*)0x20f77036 = (uint8_t)0xfff8;
> sendmmsg(fd, (struct mmsghdr *)0x202e1fc8ul, 0x1ul, 0x1ul);
> return 0;
> }
>
 Hi, Baozeng, I couldn't reproduce this issue with this script,
 even in 118253a593bd1c57de2d1193df1ccffe1abe745b
 do I need to do some extra config for this ?

>>> You need config KASAN.
>>> CONFIG_HAVE_ARCH_KASAN=y
>>> CONFIG_KASAN=y
>>> CONFIG_KASAN_INLINE=y
>>> CONFIG_KASAN_SHADOW_OFFSET=0xdc00
>>>
>>> I justed tested with b67be92feb486f800d80d72c67fd87b47b79b18e(Octor 12),
>>> it sitll exits. If you still cannot reproduce it, i will send the .config 
>>> to you privately. 

[PATCH net-next 1/1] driver: macvlan: Remove duplicated IFF_UP condition check in macvlan_forward_source_one

2016-11-20 Thread fgao
From: Gao Feng 

The condition check "dev->flags & IFF_UP" is duplicated in
macvlan_forward_source_one, because its caller macvlan_forward_source
has already checked this flag.

Signed-off-by: Gao Feng 
---
 drivers/net/macvlan.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
index 13b7e0b..95a5ffc 100644
--- a/drivers/net/macvlan.c
+++ b/drivers/net/macvlan.c
@@ -375,9 +375,6 @@ static void macvlan_forward_source_one(struct sk_buff *skb,
int ret;
 
dev = vlan->dev;
-   if (unlikely(!(dev->flags & IFF_UP)))
-   return;
-
nskb = skb_clone(skb, GFP_ATOMIC);
if (!nskb)
return;
-- 
1.9.1




STRICTLY CONFIDENTIAL

2016-11-20 Thread Acct. Dept.
I have important transaction for you as next of kin to claim US$18.37m  Mail me 
on my private email:   chimwia...@gmail.com
 so I can send you more details

Thanks

Mr.Chim Wai Kim










MOVE TO INBOX===

DISCLAIMER: This email and any files it contains are confidential and intended 
for the use of the recipient(s) only. If you are not the intended recipient you 
should notify the sender immediately and destroy the material from your system. 





Re: [PATCH net 07/18] net/ena: refactor ena_get_stats64 to be atomic context safe

2016-11-20 Thread kbuild test robot
Hi Netanel,

[auto build test WARNING on net/master]

url:
https://github.com/0day-ci/linux/commits/Netanel-Belgazal/Update-ENA-driver-to-version-1-1-2/20161120-165649
config: i386-randconfig-x009-201647 (attached as .config)
compiler: gcc-6 (Debian 6.2.0-3) 6.2.0 20160901
reproduce:
# save the attached .config to linux build tree
make ARCH=i386 

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 >>):

   Cyclomatic Complexity 2 
drivers/net/ethernet/amazon/ena/ena_netdev.c:ena_napi_enable_all
   Cyclomatic Complexity 1 include/linux/dma-mapping.h:dma_map_single_attrs
   Cyclomatic Complexity 1 include/linux/dynamic_queue_limits.h:dql_queued
   Cyclomatic Complexity 3 include/linux/netdevice.h:netdev_tx_sent_queue
   Cyclomatic Complexity 1 include/linux/netdevice.h:dev_kfree_skb_any
   Cyclomatic Complexity 1 include/linux/netdevice.h:netdev_tx_reset_queue
   Cyclomatic Complexity 6 
drivers/net/ethernet/amazon/ena/ena_netdev.c:ena_free_tx_bufs
   Cyclomatic Complexity 2 
drivers/net/ethernet/amazon/ena/ena_netdev.c:ena_free_all_tx_bufs
   Cyclomatic Complexity 3 
drivers/net/ethernet/amazon/ena/ena_netdev.c:ena_free_rx_page
   Cyclomatic Complexity 3 
drivers/net/ethernet/amazon/ena/ena_netdev.c:ena_free_rx_bufs
   Cyclomatic Complexity 2 
drivers/net/ethernet/amazon/ena/ena_netdev.c:ena_free_all_rx_bufs
   Cyclomatic Complexity 2 drivers/net/ethernet/amazon/ena/ena_netdev.c:ena_down
   Cyclomatic Complexity 4 
drivers/net/ethernet/amazon/ena/ena_netdev.c:ena_close
   Cyclomatic Complexity 3 
drivers/net/ethernet/amazon/ena/ena_netdev.c:ena_update_on_link_change
   Cyclomatic Complexity 2 include/linux/netdevice.h:napi_schedule_irqoff
   Cyclomatic Complexity 1 
drivers/net/ethernet/amazon/ena/ena_netdev.c:ena_intr_msix_io
   Cyclomatic Complexity 4 include/linux/cpumask.h:cpumask_check
   Cyclomatic Complexity 1 include/linux/cpumask.h:cpumask_set_cpu
   Cyclomatic Complexity 2 
drivers/net/ethernet/amazon/ena/ena_netdev.c:ena_setup_io_intr
   Cyclomatic Complexity 1 include/linux/interrupt.h:request_irq
   Cyclomatic Complexity 9 
drivers/net/ethernet/amazon/ena/ena_netdev.c:ena_request_io_irq
   Cyclomatic Complexity 5 
drivers/net/ethernet/amazon/ena/ena_netdev.c:ena_request_mgmnt_irq
   Cyclomatic Complexity 8 
drivers/net/ethernet/amazon/ena/ena_netdev.c:ena_setup_tx_resources
   Cyclomatic Complexity 5 
drivers/net/ethernet/amazon/ena/ena_netdev.c:ena_setup_all_tx_resources
   Cyclomatic Complexity 5 
drivers/net/ethernet/amazon/ena/ena_netdev.c:ena_setup_rx_resources
   Cyclomatic Complexity 5 
drivers/net/ethernet/amazon/ena/ena_netdev.c:ena_setup_all_rx_resources
   Cyclomatic Complexity 5 
drivers/net/ethernet/amazon/ena/ena_netdev.c:ena_create_io_tx_queue
   Cyclomatic Complexity 4 
drivers/net/ethernet/amazon/ena/ena_netdev.c:ena_create_all_io_tx_queues
   Cyclomatic Complexity 5 
drivers/net/ethernet/amazon/ena/ena_netdev.c:ena_create_io_rx_queue
   Cyclomatic Complexity 4 
drivers/net/ethernet/amazon/ena/ena_netdev.c:ena_create_all_io_rx_queues
   Cyclomatic Complexity 2 
drivers/net/ethernet/amazon/ena/ena_netdev.c:ena_init_napi
   Cyclomatic Complexity 4 
drivers/net/ethernet/amazon/ena/ena_eth_com.h:ena_com_update_dev_comp_head
   Cyclomatic Complexity 2 
drivers/net/ethernet/amazon/ena/ena_eth_com.h:ena_com_write_sq_doorbell
   Cyclomatic Complexity 4 include/linux/netdevice.h:netdev_tx_completed_queue
   Cyclomatic Complexity 14 
drivers/net/ethernet/amazon/ena/ena_netdev.c:ena_clean_tx_irq
   Cyclomatic Complexity 2 include/linux/netdevice.h:netif_tx_unlock
   Cyclomatic Complexity 1 include/linux/skbuff.h:__netdev_alloc_skb_ip_align
   Cyclomatic Complexity 1 include/linux/skbuff.h:netdev_alloc_skb_ip_align
   Cyclomatic Complexity 16 
drivers/net/ethernet/amazon/ena/ena_netdev.c:ena_rx_skb
   Cyclomatic Complexity 1 include/linux/gfp.h:__alloc_pages
   Cyclomatic Complexity 1 include/linux/gfp.h:__alloc_pages_node
   Cyclomatic Complexity 2 include/linux/gfp.h:alloc_pages_node
   Cyclomatic Complexity 6 
drivers/net/ethernet/amazon/ena/ena_netdev.c:ena_alloc_rx_page
   Cyclomatic Complexity 8 
drivers/net/ethernet/amazon/ena/ena_netdev.c:ena_refill_rx_bufs
   Cyclomatic Complexity 11 
drivers/net/ethernet/amazon/ena/ena_netdev.c:ena_clean_rx_irq
   Cyclomatic Complexity 4 
drivers/net/ethernet/amazon/ena/ena_netdev.c:ena_refill_all_rx_bufs
   Cyclomatic Complexity 5 
drivers/net/ethernet/amazon/ena/ena_netdev.c:ena_update_ring_numa_node
   Cyclomatic Complexity 8 
drivers/net/ethernet/amazon/ena/ena_netdev.c:ena_change_mtu
   Cyclomatic Complexity 2 include/linux/netdevice.h:napi_schedule
   Cyclomatic Complexity 1 
drivers/net/ethernet/amazon/ena/ena_netdev.c:ena_device_io_resume
   Cyclomatic Complexity 1 
drivers/net/ethernet/amazon/ena/ena_netdev.c:ena_device_io_suspend
   Cyclomatic Complexity 2 
include

QUICK LOAN OFFER

2016-11-20 Thread Sky Finance
Do You Need A Loan Of Any Kind ? If Yes Email Now For More Info Contact us on: 
skyfinance...@gmail.com

---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus



[PATCH net 14/18] net/ena: add IPv6 extended protocols to ena_admin_flow_hash_proto

2016-11-20 Thread Netanel Belgazal
We intend to use those fields in the future.

Signed-off-by: Netanel Belgazal 
---
 drivers/net/ethernet/amazon/ena/ena_admin_defs.h | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/drivers/net/ethernet/amazon/ena/ena_admin_defs.h 
b/drivers/net/ethernet/amazon/ena/ena_admin_defs.h
index 35ae511..92bba08 100644
--- a/drivers/net/ethernet/amazon/ena/ena_admin_defs.h
+++ b/drivers/net/ethernet/amazon/ena/ena_admin_defs.h
@@ -627,6 +627,12 @@ enum ena_admin_flow_hash_proto {
 
ENA_ADMIN_RSS_NOT_IP= 7,
 
+   /* TCPv6 with extension header */
+   ENA_ADMIN_RSS_TCP6_EX   = 8,
+
+   /* IPv6 with extension header */
+   ENA_ADMIN_RSS_IP6_EX= 9,
+
ENA_ADMIN_RSS_PROTO_NUM = 16,
 };
 
-- 
1.9.1



[PATCH net 09/18] net/ena: change condition for host attribute configuration

2016-11-20 Thread Netanel Belgazal
Move the host info config to be the first admin command that is executed.
This change require the driver to remove the 'feature check'
from host info configuration flow.
The check is removed since the supported features bitmask field
is retrieved only after calling ENA_ADMIN_DEVICE_ATTRIBUTES admin command.

If set host info is not supported an error will be returned by the device.

Signed-off-by: Netanel Belgazal 
---
 drivers/net/ethernet/amazon/ena/ena_com.c| 8 +++-
 drivers/net/ethernet/amazon/ena/ena_netdev.c | 5 +++--
 2 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/drivers/net/ethernet/amazon/ena/ena_com.c 
b/drivers/net/ethernet/amazon/ena/ena_com.c
index edb2e81..b2891f9 100644
--- a/drivers/net/ethernet/amazon/ena/ena_com.c
+++ b/drivers/net/ethernet/amazon/ena/ena_com.c
@@ -2474,11 +2474,9 @@ int ena_com_set_host_attributes(struct ena_com_dev 
*ena_dev)
 
int ret;
 
-   if (!ena_com_check_supported_feature_id(ena_dev,
-   ENA_ADMIN_HOST_ATTR_CONFIG)) {
-   pr_warn("Set host attribute isn't supported\n");
-   return -EPERM;
-   }
+   /* Host attribute config is called before ena_com_get_dev_attr_feat
+* so ena_com can't check if the feature is supported.
+*/
 
memset(, 0x0, sizeof(cmd));
admin_queue = _dev->admin_queue;
diff --git a/drivers/net/ethernet/amazon/ena/ena_netdev.c 
b/drivers/net/ethernet/amazon/ena/ena_netdev.c
index 44dc298..dd7c74b 100644
--- a/drivers/net/ethernet/amazon/ena/ena_netdev.c
+++ b/drivers/net/ethernet/amazon/ena/ena_netdev.c
@@ -2387,6 +2387,8 @@ static int ena_device_init(struct ena_com_dev *ena_dev, 
struct pci_dev *pdev,
 */
ena_com_set_admin_polling_mode(ena_dev, true);
 
+   ena_config_host_info(ena_dev);
+
/* Get Device Attributes*/
rc = ena_com_get_dev_attr_feat(ena_dev, get_feat_ctx);
if (rc) {
@@ -2411,11 +2413,10 @@ static int ena_device_init(struct ena_com_dev *ena_dev, 
struct pci_dev *pdev,
 
*wd_state = !!(aenq_groups & BIT(ENA_ADMIN_KEEP_ALIVE));
 
-   ena_config_host_info(ena_dev);
-
return 0;
 
 err_admin_init:
+   ena_com_delete_host_info(ena_dev);
ena_com_admin_destroy(ena_dev);
 err_mmio_read_less:
ena_com_mmio_reg_read_request_destroy(ena_dev);
-- 
1.9.1



[PATCH net 00/18] Update ENA driver to version 1.1.2

2016-11-20 Thread Netanel Belgazal
Update Amazon's Elastic Network Adapter (ENA) driver version from 1.0.2 to 1.1.2

Netanel Belgazal (18):
  net/ena: remove RFS support from device feature list
  net/ena: fix queues number calculation
  net/ena: use napi_schedule_irqoff when possible
  net/ena: reduce the severity of ena printouts
  net/ena: add hardware hints capability to the driver
  net/ena: fix ethtool RSS flow configuration
  net/ena: refactor ena_get_stats64 to be atomic context safe
  net/ena: change sizeof() argument to be the type pointer
  net/ena: change condition for host attribute configuration
  net/ena: use READ_ONCE to access completion descriptors
  net/ena: fix potential access to freed memory during device reset
  net/ena: refactor skb allocation
  net/ena: remove redundant logic in napi callback for busy poll mode
  net/ena: add IPv6 extended protocols to ena_admin_flow_hash_proto
  net/ena: remove affinity hint from the driver
  net/ena: fix error handling when probe fails
  net/ena: fix NULL dereference when removing the driver after device
reset faild
  net/ena: change driver's default timeouts and increase driver version

 drivers/net/ethernet/amazon/ena/ena_admin_defs.h |  57 +++-
 drivers/net/ethernet/amazon/ena/ena_com.c|  96 ---
 drivers/net/ethernet/amazon/ena/ena_com.h|   6 +
 drivers/net/ethernet/amazon/ena/ena_eth_com.c|   8 +-
 drivers/net/ethernet/amazon/ena/ena_ethtool.c|   1 -
 drivers/net/ethernet/amazon/ena/ena_netdev.c | 326 ---
 drivers/net/ethernet/amazon/ena/ena_netdev.h |  30 ++-
 drivers/net/ethernet/amazon/ena/ena_regs_defs.h  |   2 +
 8 files changed, 384 insertions(+), 142 deletions(-)

-- 
1.9.1



[PATCH net 11/18] net/ena: fix potential access to freed memory during device reset

2016-11-20 Thread Netanel Belgazal
If the ena driver detects that the device is not behave as expected,
it tries to reset the device.
The reset flow calls ena_down, which will frees all the resources
the driver allocates and then it will reset the device.

This flow can cause memory corruption if the device is still writes
to the driver's memory space.
To overcome this potential race, move the reset before the device
resources are freed.

Signed-off-by: Netanel Belgazal 
---
 drivers/net/ethernet/amazon/ena/ena_netdev.c | 56 +---
 1 file changed, 43 insertions(+), 13 deletions(-)

diff --git a/drivers/net/ethernet/amazon/ena/ena_netdev.c 
b/drivers/net/ethernet/amazon/ena/ena_netdev.c
index dd7c74b..3bc8f43 100644
--- a/drivers/net/ethernet/amazon/ena/ena_netdev.c
+++ b/drivers/net/ethernet/amazon/ena/ena_netdev.c
@@ -80,14 +80,18 @@ static void ena_tx_timeout(struct net_device *dev)
 {
struct ena_adapter *adapter = netdev_priv(dev);
 
+   /* Change the state of the device to trigger reset
+* Check that we are not in the middle or a trigger already
+*/
+
+   if (test_and_set_bit(ENA_FLAG_TRIGGER_RESET, >flags))
+   return;
+
u64_stats_update_begin(>syncp);
adapter->dev_stats.tx_timeout++;
u64_stats_update_end(>syncp);
 
netif_err(adapter, tx_err, dev, "Transmit time out\n");
-
-   /* Change the state of the device to trigger reset */
-   set_bit(ENA_FLAG_TRIGGER_RESET, >flags);
 }
 
 static void update_rx_ring_mtu(struct ena_adapter *adapter, int mtu)
@@ -1124,7 +1128,8 @@ static int ena_io_poll(struct napi_struct *napi, int 
budget)
 
tx_budget = tx_ring->ring_size / ENA_TX_POLL_BUDGET_DIVIDER;
 
-   if (!test_bit(ENA_FLAG_DEV_UP, _ring->adapter->flags)) {
+   if (!test_bit(ENA_FLAG_DEV_UP, _ring->adapter->flags) ||
+   test_bit(ENA_FLAG_TRIGGER_RESET, _ring->adapter->flags)) {
napi_complete_done(napi, 0);
return 0;
}
@@ -1713,12 +1718,22 @@ static void ena_down(struct ena_adapter *adapter)
adapter->dev_stats.interface_down++;
u64_stats_update_end(>syncp);
 
-   /* After this point the napi handler won't enable the tx queue */
-   ena_napi_disable_all(adapter);
netif_carrier_off(adapter->netdev);
netif_tx_disable(adapter->netdev);
 
+   /* After this point the napi handler won't enable the tx queue */
+   ena_napi_disable_all(adapter);
+
/* After destroy the queue there won't be any new interrupts */
+
+   if (test_bit(ENA_FLAG_TRIGGER_RESET, >flags)) {
+   int rc;
+
+   rc = ena_com_dev_reset(adapter->ena_dev);
+   if (rc)
+   dev_err(>pdev->dev, "Device reset failed\n");
+   }
+
ena_destroy_all_io_queues(adapter);
 
ena_disable_io_intr_sync(adapter);
@@ -2081,6 +2096,14 @@ static void ena_netpoll(struct net_device *netdev)
struct ena_adapter *adapter = netdev_priv(netdev);
int i;
 
+   /* Dont schedule NAPI if the driver is in the middle of reset
+* or netdev is down.
+*/
+
+   if (!test_bit(ENA_FLAG_DEV_UP, >flags) ||
+   test_bit(ENA_FLAG_TRIGGER_RESET, >flags))
+   return;
+
for (i = 0; i < adapter->num_queues; i++)
napi_schedule(>ena_napi[i].napi);
 }
@@ -2468,6 +2491,14 @@ static void ena_fw_reset_device(struct work_struct *work)
bool dev_up, wd_state;
int rc;
 
+   if (unlikely(!test_bit(ENA_FLAG_TRIGGER_RESET, >flags))) {
+   dev_err(>dev,
+   "device reset schedule while reset bit is off\n");
+   return;
+   }
+
+   netif_carrier_off(netdev);
+
del_timer_sync(>timer_service);
 
rtnl_lock();
@@ -2481,12 +2512,6 @@ static void ena_fw_reset_device(struct work_struct *work)
 */
ena_close(netdev);
 
-   rc = ena_com_dev_reset(ena_dev);
-   if (rc) {
-   dev_err(>dev, "Device reset failed\n");
-   goto err;
-   }
-
ena_free_mgmnt_irq(adapter);
 
ena_disable_msix(adapter);
@@ -2499,6 +2524,8 @@ static void ena_fw_reset_device(struct work_struct *work)
 
ena_com_mmio_reg_read_request_destroy(ena_dev);
 
+   clear_bit(ENA_FLAG_TRIGGER_RESET, >flags);
+
/* Finish with the destroy part. Start the init part */
 
rc = ena_device_init(ena_dev, adapter->pdev, _feat_ctx, _state);
@@ -2562,6 +2589,9 @@ static void check_for_missing_tx_completions(struct 
ena_adapter *adapter)
if (!test_bit(ENA_FLAG_DEV_UP, >flags))
return;
 
+   if (test_bit(ENA_FLAG_TRIGGER_RESET, >flags))
+   return;
+
if (adapter->missing_tx_completion_to == ENA_HW_HINTS_NO_TIMEOUT)
return;
 
@@ -2703,7 +2733,7 @@ static void ena_timer_service(unsigned long data)
if (host_info)

[PATCH net 13/18] net/ena: remove redundant logic in napi callback for busy poll mode

2016-11-20 Thread Netanel Belgazal
sk_busy_loop can call the napi callback few million times a sec.
For each call there is unmask interrupt.
We want to reduce the number of unmasks.

Add an atomic variable that will tell the napi handler if
it was called from irq context or not.
Unmask the interrupt only from irq context.

A schenario where the driver left with missed unmask isn't feasible.
when ena_intr_msix_io is called the driver have 2 options:
1)Before napi completes and call napi_complete_done
2)After calling napi_complete_done

In the former case the napi will unmask the interrupt as needed.
In the latter case napi_complete_done will remove napi from the schedule
list so napi will be rescheduled (by ena_intr_msix_io) and interrupt
will be unmasked as desire in the 2nd napi call.

Signed-off-by: Netanel Belgazal 
---
 drivers/net/ethernet/amazon/ena/ena_netdev.c | 46 +++-
 drivers/net/ethernet/amazon/ena/ena_netdev.h |  1 +
 2 files changed, 32 insertions(+), 15 deletions(-)

diff --git a/drivers/net/ethernet/amazon/ena/ena_netdev.c 
b/drivers/net/ethernet/amazon/ena/ena_netdev.c
index b478c61..eda5fb5 100644
--- a/drivers/net/ethernet/amazon/ena/ena_netdev.c
+++ b/drivers/net/ethernet/amazon/ena/ena_netdev.c
@@ -1145,26 +1145,41 @@ static int ena_io_poll(struct napi_struct *napi, int 
budget)
tx_work_done = ena_clean_tx_irq(tx_ring, tx_budget);
rx_work_done = ena_clean_rx_irq(rx_ring, napi, budget);
 
-   if ((budget > rx_work_done) && (tx_budget > tx_work_done)) {
+   /* If the device is about to reset or down, avoid unmask
+* the interrupt and return 0 so NAPI won't reschedule
+*/
+   if (unlikely(!test_bit(ENA_FLAG_DEV_UP, _ring->adapter->flags) ||
+test_bit(ENA_FLAG_TRIGGER_RESET, 
_ring->adapter->flags))) {
+   napi_complete_done(napi, 0);
+   ret = 0;
+
+   } else if ((budget > rx_work_done) && (tx_budget > tx_work_done)) {
napi_complete_done(napi, rx_work_done);
 
napi_comp_call = 1;
-   /* Tx and Rx share the same interrupt vector */
-   if (ena_com_get_adaptive_moderation_enabled(rx_ring->ena_dev))
-   ena_adjust_intr_moderation(rx_ring, tx_ring);
-
-   /* Update intr register: rx intr delay, tx intr delay and
-* interrupt unmask
+   /* Update numa and unmask the interrupt only when schedule
+* from the interrupt context (vs from sk_busy_loop)
 */
-   ena_com_update_intr_reg(_reg,
-   rx_ring->smoothed_interval,
-   tx_ring->smoothed_interval,
-   true);
+   if (atomic_cmpxchg(_napi->unmask_interrupt, 1, 0)) {
+   /* Tx and Rx share the same interrupt vector */
+   if 
(ena_com_get_adaptive_moderation_enabled(rx_ring->ena_dev))
+   ena_adjust_intr_moderation(rx_ring, tx_ring);
+
+   /* Update intr register: rx intr delay,
+* tx intr delay and interrupt unmask
+*/
+   ena_com_update_intr_reg(_reg,
+   rx_ring->smoothed_interval,
+   tx_ring->smoothed_interval,
+   true);
+
+   /* It is a shared MSI-X.
+* Tx and Rx CQ have pointer to it.
+* So we use one of them to reach the intr reg
+*/
+   ena_com_unmask_intr(rx_ring->ena_com_io_cq, _reg);
+   }
 
-   /* It is a shared MSI-X. Tx and Rx CQ have pointer to it.
-* So we use one of them to reach the intr reg
-*/
-   ena_com_unmask_intr(rx_ring->ena_com_io_cq, _reg);
 
ena_update_ring_numa_node(tx_ring, rx_ring);
 
@@ -1202,6 +1217,7 @@ static irqreturn_t ena_intr_msix_io(int irq, void *data)
 {
struct ena_napi *ena_napi = data;
 
+   atomic_set(_napi->unmask_interrupt, 1);
napi_schedule_irqoff(_napi->napi);
 
return IRQ_HANDLED;
diff --git a/drivers/net/ethernet/amazon/ena/ena_netdev.h 
b/drivers/net/ethernet/amazon/ena/ena_netdev.h
index 2897fab..c081fd3 100644
--- a/drivers/net/ethernet/amazon/ena/ena_netdev.h
+++ b/drivers/net/ethernet/amazon/ena/ena_netdev.h
@@ -135,6 +135,7 @@ struct ena_napi {
struct napi_struct napi cacheline_aligned;
struct ena_ring *tx_ring;
struct ena_ring *rx_ring;
+   atomic_t unmask_interrupt;
u32 qid;
 };
 
-- 
1.9.1



[PATCH net 15/18] net/ena: remove affinity hint from the driver

2016-11-20 Thread Netanel Belgazal
To allow irqbalance to better distribute the napi handler,
remove the smp affinity hint from the driver.

Signed-off-by: Netanel Belgazal 
---
 drivers/net/ethernet/amazon/ena/ena_netdev.c | 4 
 1 file changed, 4 deletions(-)

diff --git a/drivers/net/ethernet/amazon/ena/ena_netdev.c 
b/drivers/net/ethernet/amazon/ena/ena_netdev.c
index eda5fb5..bff082a 100644
--- a/drivers/net/ethernet/amazon/ena/ena_netdev.c
+++ b/drivers/net/ethernet/amazon/ena/ena_netdev.c
@@ -1331,8 +1331,6 @@ static int ena_request_mgmnt_irq(struct ena_adapter 
*adapter)
  "set affinity hint of mgmnt irq.to 0x%lx (irq vector: %d)\n",
  irq->affinity_hint_mask.bits[0], irq->vector);
 
-   irq_set_affinity_hint(irq->vector, >affinity_hint_mask);
-
return rc;
 }
 
@@ -1362,8 +1360,6 @@ static int ena_request_io_irq(struct ena_adapter *adapter)
netif_dbg(adapter, ifup, adapter->netdev,
  "set affinity hint of irq. index %d to 0x%lx (irq 
vector: %d)\n",
  i, irq->affinity_hint_mask.bits[0], irq->vector);
-
-   irq_set_affinity_hint(irq->vector, >affinity_hint_mask);
}
 
return rc;
-- 
1.9.1



[PATCH net 01/18] net/ena: remove RFS support from device feature list

2016-11-20 Thread Netanel Belgazal
Remove NETIF_F_NTUPLE from netdev->features.
The ENA device driver does not support RFS acceleration.

Signed-off-by: Netanel Belgazal 
---
 drivers/net/ethernet/amazon/ena/ena_netdev.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/net/ethernet/amazon/ena/ena_netdev.c 
b/drivers/net/ethernet/amazon/ena/ena_netdev.c
index bfeaec5..33a760e 100644
--- a/drivers/net/ethernet/amazon/ena/ena_netdev.c
+++ b/drivers/net/ethernet/amazon/ena/ena_netdev.c
@@ -2729,7 +2729,6 @@ static void ena_set_dev_offloads(struct 
ena_com_dev_get_features_ctx *feat,
netdev->features =
dev_features |
NETIF_F_SG |
-   NETIF_F_NTUPLE |
NETIF_F_RXHASH |
NETIF_F_HIGHDMA;
 
-- 
1.9.1



[PATCH net 02/18] net/ena: fix queues number calculation

2016-11-20 Thread Netanel Belgazal
The ENA driver tries to open a queue per vCPU.
To determine how many vCPUs the instance have it uses num_possible_cpus
while it should have use num_online_cpus instead.

Signed-off-by: Netanel Belgazal 
---
 drivers/net/ethernet/amazon/ena/ena_netdev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/amazon/ena/ena_netdev.c 
b/drivers/net/ethernet/amazon/ena/ena_netdev.c
index 33a760e..8815217 100644
--- a/drivers/net/ethernet/amazon/ena/ena_netdev.c
+++ b/drivers/net/ethernet/amazon/ena/ena_netdev.c
@@ -2667,7 +2667,7 @@ static int ena_calc_io_queue_num(struct pci_dev *pdev,
io_sq_num = get_feat_ctx->max_queues.max_sq_num;
}
 
-   io_queue_num = min_t(int, num_possible_cpus(), ENA_MAX_NUM_IO_QUEUES);
+   io_queue_num = min_t(int, num_online_cpus(), ENA_MAX_NUM_IO_QUEUES);
io_queue_num = min_t(int, io_queue_num, io_sq_num);
io_queue_num = min_t(int, io_queue_num,
 get_feat_ctx->max_queues.max_cq_num);
-- 
1.9.1



[PATCH net 04/18] net/ena: reduce the severity of ena printouts

2016-11-20 Thread Netanel Belgazal
Signed-off-by: Netanel Belgazal 
---
 drivers/net/ethernet/amazon/ena/ena_com.c| 27 +--
 drivers/net/ethernet/amazon/ena/ena_netdev.c | 14 +++---
 2 files changed, 28 insertions(+), 13 deletions(-)

diff --git a/drivers/net/ethernet/amazon/ena/ena_com.c 
b/drivers/net/ethernet/amazon/ena/ena_com.c
index 3066d9c..6bd2b9b 100644
--- a/drivers/net/ethernet/amazon/ena/ena_com.c
+++ b/drivers/net/ethernet/amazon/ena/ena_com.c
@@ -784,7 +784,7 @@ static int ena_com_get_feature_ex(struct ena_com_dev 
*ena_dev,
int ret;
 
if (!ena_com_check_supported_feature_id(ena_dev, feature_id)) {
-   pr_info("Feature %d isn't supported\n", feature_id);
+   pr_debug("Feature %d isn't supported\n", feature_id);
return -EPERM;
}
 
@@ -1126,7 +1126,13 @@ int ena_com_execute_admin_command(struct 
ena_com_admin_queue *admin_queue,
comp_ctx = ena_com_submit_admin_cmd(admin_queue, cmd, cmd_size,
comp, comp_size);
if (unlikely(IS_ERR(comp_ctx))) {
-   pr_err("Failed to submit command [%ld]\n", PTR_ERR(comp_ctx));
+   if (comp_ctx == ERR_PTR(-ENODEV))
+   pr_debug("Failed to submit command [%ld]\n",
+PTR_ERR(comp_ctx));
+   else
+   pr_err("Failed to submit command [%ld]\n",
+  PTR_ERR(comp_ctx));
+
return PTR_ERR(comp_ctx);
}
 
@@ -1895,7 +1901,7 @@ int ena_com_set_dev_mtu(struct ena_com_dev *ena_dev, int 
mtu)
int ret;
 
if (!ena_com_check_supported_feature_id(ena_dev, ENA_ADMIN_MTU)) {
-   pr_info("Feature %d isn't supported\n", ENA_ADMIN_MTU);
+   pr_debug("Feature %d isn't supported\n", ENA_ADMIN_MTU);
return -EPERM;
}
 
@@ -1948,8 +1954,8 @@ int ena_com_set_hash_function(struct ena_com_dev *ena_dev)
 
if (!ena_com_check_supported_feature_id(ena_dev,
ENA_ADMIN_RSS_HASH_FUNCTION)) {
-   pr_info("Feature %d isn't supported\n",
-   ENA_ADMIN_RSS_HASH_FUNCTION);
+   pr_debug("Feature %d isn't supported\n",
+ENA_ADMIN_RSS_HASH_FUNCTION);
return -EPERM;
}
 
@@ -2112,7 +2118,8 @@ int ena_com_set_hash_ctrl(struct ena_com_dev *ena_dev)
 
if (!ena_com_check_supported_feature_id(ena_dev,
ENA_ADMIN_RSS_HASH_INPUT)) {
-   pr_info("Feature %d isn't supported\n", 
ENA_ADMIN_RSS_HASH_INPUT);
+   pr_debug("Feature %d isn't supported\n",
+ENA_ADMIN_RSS_HASH_INPUT);
return -EPERM;
}
 
@@ -2270,8 +2277,8 @@ int ena_com_indirect_table_set(struct ena_com_dev 
*ena_dev)
 
if (!ena_com_check_supported_feature_id(
ena_dev, ENA_ADMIN_RSS_REDIRECTION_TABLE_CONFIG)) {
-   pr_info("Feature %d isn't supported\n",
-   ENA_ADMIN_RSS_REDIRECTION_TABLE_CONFIG);
+   pr_debug("Feature %d isn't supported\n",
+ENA_ADMIN_RSS_REDIRECTION_TABLE_CONFIG);
return -EPERM;
}
 
@@ -2542,8 +2549,8 @@ int ena_com_init_interrupt_moderation(struct ena_com_dev 
*ena_dev)
 
if (rc) {
if (rc == -EPERM) {
-   pr_info("Feature %d isn't supported\n",
-   ENA_ADMIN_INTERRUPT_MODERATION);
+   pr_debug("Feature %d isn't supported\n",
+ENA_ADMIN_INTERRUPT_MODERATION);
rc = 0;
} else {
pr_err("Failed to get interrupt moderation admin cmd. 
rc: %d\n",
diff --git a/drivers/net/ethernet/amazon/ena/ena_netdev.c 
b/drivers/net/ethernet/amazon/ena/ena_netdev.c
index e3acf76..7247abb 100644
--- a/drivers/net/ethernet/amazon/ena/ena_netdev.c
+++ b/drivers/net/ethernet/amazon/ena/ena_netdev.c
@@ -566,6 +566,7 @@ static void ena_free_all_rx_bufs(struct ena_adapter 
*adapter)
  */
 static void ena_free_tx_bufs(struct ena_ring *tx_ring)
 {
+   bool print_once = true;
u32 i;
 
for (i = 0; i < tx_ring->ring_size; i++) {
@@ -577,9 +578,16 @@ static void ena_free_tx_bufs(struct ena_ring *tx_ring)
if (!tx_info->skb)
continue;
 
-   netdev_notice(tx_ring->netdev,
- "free uncompleted tx skb qid %d idx 0x%x\n",
- tx_ring->qid, i);
+   if (print_once) {
+   netdev_notice(tx_ring->netdev,
+ "free uncompleted tx skb qid %d idx 
0x%x\n",
+ tx_ring->qid, i);
+   print_once = false;
+  

[PATCH net 05/18] net/ena: add hardware hints capability to the driver

2016-11-20 Thread Netanel Belgazal
The ENA device can update the ena driver about the desire timeouts.
The hardware hints are transmitted as Asynchronous event to the driver.

In case the device does not support this capability, the driver
will use its own defines.

Signed-off-by: Netanel Belgazal 
---
 drivers/net/ethernet/amazon/ena/ena_admin_defs.h | 31 +
 drivers/net/ethernet/amazon/ena/ena_com.c| 41 ---
 drivers/net/ethernet/amazon/ena/ena_com.h|  5 ++
 drivers/net/ethernet/amazon/ena/ena_ethtool.c|  1 -
 drivers/net/ethernet/amazon/ena/ena_netdev.c | 86 +++-
 drivers/net/ethernet/amazon/ena/ena_netdev.h | 19 +-
 drivers/net/ethernet/amazon/ena/ena_regs_defs.h  |  2 +
 7 files changed, 157 insertions(+), 28 deletions(-)

diff --git a/drivers/net/ethernet/amazon/ena/ena_admin_defs.h 
b/drivers/net/ethernet/amazon/ena/ena_admin_defs.h
index a46e749..51b2a92 100644
--- a/drivers/net/ethernet/amazon/ena/ena_admin_defs.h
+++ b/drivers/net/ethernet/amazon/ena/ena_admin_defs.h
@@ -70,6 +70,8 @@ enum ena_admin_aq_feature_id {
 
ENA_ADMIN_MAX_QUEUES_NUM= 2,
 
+   ENA_ADMIN_HW_HINTS  = 3,
+
ENA_ADMIN_RSS_HASH_FUNCTION = 10,
 
ENA_ADMIN_STATELESS_OFFLOAD_CONFIG  = 11,
@@ -749,6 +751,31 @@ struct ena_admin_feature_rss_ind_table {
struct ena_admin_rss_ind_table_entry inline_entry;
 };
 
+/* When hint value is 0, driver should use it's own predefined value */
+struct ena_admin_ena_hw_hints {
+   /* value in ms */
+   u16 mmio_read_timeout;
+
+   /* value in ms */
+   u16 driver_watchdog_timeout;
+
+   /* Per packet tx completion timeout. value in ms */
+   u16 missing_tx_completion_timeout;
+
+   u16 missed_tx_completion_count_threshold_to_reset;
+
+   /* value in ms */
+   u16 admin_completion_tx_timeout;
+
+   u16 netdev_wd_timeout;
+
+   u16 max_tx_sgl_size;
+
+   u16 max_rx_sgl_size;
+
+   u16 reserved[8];
+};
+
 struct ena_admin_get_feat_cmd {
struct ena_admin_aq_common_desc aq_common_descriptor;
 
@@ -782,6 +809,8 @@ struct ena_admin_get_feat_resp {
struct ena_admin_feature_rss_ind_table ind_table;
 
struct ena_admin_feature_intr_moder_desc intr_moderation;
+
+   struct ena_admin_ena_hw_hints hw_hints;
} u;
 };
 
@@ -857,6 +886,8 @@ enum ena_admin_aenq_notification_syndrom {
ENA_ADMIN_SUSPEND   = 0,
 
ENA_ADMIN_RESUME= 1,
+
+   ENA_ADMIN_UPDATE_HINTS  = 2,
 };
 
 struct ena_admin_aenq_entry {
diff --git a/drivers/net/ethernet/amazon/ena/ena_com.c 
b/drivers/net/ethernet/amazon/ena/ena_com.c
index 6bd2b9b..366c2c5 100644
--- a/drivers/net/ethernet/amazon/ena/ena_com.c
+++ b/drivers/net/ethernet/amazon/ena/ena_com.c
@@ -508,15 +508,13 @@ static int ena_com_comp_status_to_errno(u8 comp_status)
 static int ena_com_wait_and_process_admin_cq_polling(struct ena_comp_ctx 
*comp_ctx,
 struct ena_com_admin_queue 
*admin_queue)
 {
-   unsigned long flags;
-   u32 start_time;
+   unsigned long flags, timeout;
int ret;
 
-   start_time = ((u32)jiffies_to_usecs(jiffies));
+   timeout = jiffies + usecs_to_jiffies(admin_queue->completion_timeout);
 
while (comp_ctx->status == ENA_CMD_SUBMITTED) {
-   if u32)jiffies_to_usecs(jiffies)) - start_time) >
-   ADMIN_CMD_TIMEOUT_US) {
+   if (time_is_before_jiffies(timeout)) {
pr_err("Wait for completion (polling) timeout\n");
/* ENA didn't have any completion */
spin_lock_irqsave(_queue->q_lock, flags);
@@ -560,7 +558,8 @@ static int 
ena_com_wait_and_process_admin_cq_interrupts(struct ena_comp_ctx *com
int ret;
 
wait_for_completion_timeout(_ctx->wait_event,
-   usecs_to_jiffies(ADMIN_CMD_TIMEOUT_US));
+   usecs_to_jiffies(
+   admin_queue->completion_timeout));
 
/* In case the command wasn't completed find out the root cause.
 * There might be 2 kinds of errors
@@ -600,12 +599,14 @@ static u32 ena_com_reg_bar_read32(struct ena_com_dev 
*ena_dev, u16 offset)
struct ena_com_mmio_read *mmio_read = _dev->mmio_read;
volatile struct ena_admin_ena_mmio_req_read_less_resp *read_resp =
mmio_read->read_resp;
-   u32 mmio_read_reg, ret;
+   u32 mmio_read_reg, timeout, ret;
unsigned long flags;
int i;
 
might_sleep();
 
+   timeout = mmio_read->reg_read_to ? : ENA_REG_READ_TIMEOUT;
+
/* If readless is disabled, perform regular read */
if (!mmio_read->readless_supported)
return readl(ena_dev->reg_bar + offset);
@@ -626,14 +627,14 @@ static u32 ena_com_reg_bar_read32(struct 

[PATCH net 07/18] net/ena: refactor ena_get_stats64 to be atomic context safe

2016-11-20 Thread Netanel Belgazal
ndo_get_stat64 can be called from atomic context.
However the current implementation sends an admin command to retrieve
the statistics from the device.
This admin commands uses sleep.

Refactor the implementation of ena_get_stats64 to take the
{rx,tx}bytes/cnt from the driver's inner counters
and to take the rx drops counter
from the asynchronous keep alive (heart bit) event.

Signed-off-by: Netanel Belgazal 
---
 drivers/net/ethernet/amazon/ena/ena_admin_defs.h |  8 
 drivers/net/ethernet/amazon/ena/ena_netdev.c | 57 +---
 drivers/net/ethernet/amazon/ena/ena_netdev.h |  1 +
 3 files changed, 51 insertions(+), 15 deletions(-)

diff --git a/drivers/net/ethernet/amazon/ena/ena_admin_defs.h 
b/drivers/net/ethernet/amazon/ena/ena_admin_defs.h
index c78f0b2..35ae511 100644
--- a/drivers/net/ethernet/amazon/ena/ena_admin_defs.h
+++ b/drivers/net/ethernet/amazon/ena/ena_admin_defs.h
@@ -904,6 +904,14 @@ struct ena_admin_aenq_link_change_desc {
u32 flags;
 };
 
+struct ena_admin_aenq_keep_alive_desc {
+   struct ena_admin_aenq_common_desc aenq_common_desc;
+
+   u32 rx_drops_low;
+
+   u32 rx_drops_high;
+};
+
 struct ena_admin_ena_mmio_req_read_less_resp {
u16 req_id;
 
diff --git a/drivers/net/ethernet/amazon/ena/ena_netdev.c 
b/drivers/net/ethernet/amazon/ena/ena_netdev.c
index e7dda8b..44dc298 100644
--- a/drivers/net/ethernet/amazon/ena/ena_netdev.c
+++ b/drivers/net/ethernet/amazon/ena/ena_netdev.c
@@ -2185,28 +2185,46 @@ static struct rtnl_link_stats64 *ena_get_stats64(struct 
net_device *netdev,
 struct rtnl_link_stats64 
*stats)
 {
struct ena_adapter *adapter = netdev_priv(netdev);
-   struct ena_admin_basic_stats ena_stats;
-   int rc;
+   struct ena_ring *rx_ring, *tx_ring;
+   unsigned int start;
+   u64 rx_drops;
+   int i;
 
if (!test_bit(ENA_FLAG_DEV_UP, >flags))
return NULL;
 
-   rc = ena_com_get_dev_basic_stats(adapter->ena_dev, _stats);
-   if (rc)
-   return NULL;
+   for (i = 0; i < adapter->num_queues; i++) {
+   u64 bytes, packets;
+
+   tx_ring = >tx_ring[i];
+
+   do {
+   start = u64_stats_fetch_begin_irq(_ring->syncp);
+   packets = tx_ring->tx_stats.cnt;
+   bytes = tx_ring->tx_stats.bytes;
+   } while (u64_stats_fetch_retry_irq(_ring->syncp, start));
+
+   stats->tx_packets += packets;
+   stats->tx_bytes += bytes;
 
-   stats->tx_bytes = ((u64)ena_stats.tx_bytes_high << 32) |
-   ena_stats.tx_bytes_low;
-   stats->rx_bytes = ((u64)ena_stats.rx_bytes_high << 32) |
-   ena_stats.rx_bytes_low;
+   rx_ring = >rx_ring[i];
+
+   do {
+   start = u64_stats_fetch_begin_irq(_ring->syncp);
+   packets = rx_ring->rx_stats.cnt;
+   bytes = rx_ring->rx_stats.bytes;
+   } while (u64_stats_fetch_retry_irq(_ring->syncp, start));
 
-   stats->rx_packets = ((u64)ena_stats.rx_pkts_high << 32) |
-   ena_stats.rx_pkts_low;
-   stats->tx_packets = ((u64)ena_stats.tx_pkts_high << 32) |
-   ena_stats.tx_pkts_low;
+   stats->rx_packets += packets;
+   stats->rx_bytes += bytes;
+   }
+
+   do {
+   start = u64_stats_fetch_begin_irq(_ring->syncp);
+   rx_drops = adapter->dev_stats.rx_drops;
+   } while (u64_stats_fetch_retry_irq(_ring->syncp, start));
 
-   stats->rx_dropped = ((u64)ena_stats.rx_drops_high << 32) |
-   ena_stats.rx_drops_low;
+   stats->rx_dropped = rx_drops;
 
stats->multicast = 0;
stats->collisions = 0;
@@ -3272,8 +3290,17 @@ static void ena_keep_alive_wd(void *adapter_data,
  struct ena_admin_aenq_entry *aenq_e)
 {
struct ena_adapter *adapter = (struct ena_adapter *)adapter_data;
+   struct ena_admin_aenq_keep_alive_desc *desc;
+   u64 rx_drops;
 
+   desc = (struct ena_admin_aenq_keep_alive_desc *)aenq_e;
adapter->last_keep_alive_jiffies = jiffies;
+
+   rx_drops = ((u64)desc->rx_drops_high << 32) | desc->rx_drops_low;
+
+   u64_stats_update_begin(>syncp);
+   adapter->dev_stats.rx_drops = rx_drops;
+   u64_stats_update_end(>syncp);
 }
 
 static void ena_notification(void *adapter_data,
diff --git a/drivers/net/ethernet/amazon/ena/ena_netdev.h 
b/drivers/net/ethernet/amazon/ena/ena_netdev.h
index f8ef1f0..2897fab 100644
--- a/drivers/net/ethernet/amazon/ena/ena_netdev.h
+++ b/drivers/net/ethernet/amazon/ena/ena_netdev.h
@@ -251,6 +251,7 @@ struct ena_stats_dev {
u64 interface_up;
u64 interface_down;
u64 admin_q_pause;
+   u64 rx_drops;
 };
 
 enum ena_flags_t {
-- 
1.9.1



[PATCH net 03/18] net/ena: use napi_schedule_irqoff when possible

2016-11-20 Thread Netanel Belgazal
Signed-off-by: Netanel Belgazal 
---
 drivers/net/ethernet/amazon/ena/ena_netdev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/amazon/ena/ena_netdev.c 
b/drivers/net/ethernet/amazon/ena/ena_netdev.c
index 8815217..e3acf76 100644
--- a/drivers/net/ethernet/amazon/ena/ena_netdev.c
+++ b/drivers/net/ethernet/amazon/ena/ena_netdev.c
@@ -1181,7 +1181,7 @@ static irqreturn_t ena_intr_msix_io(int irq, void *data)
 {
struct ena_napi *ena_napi = data;
 
-   napi_schedule(_napi->napi);
+   napi_schedule_irqoff(_napi->napi);
 
return IRQ_HANDLED;
 }
-- 
1.9.1



[PATCH net 12/18] net/ena: refactor skb allocation

2016-11-20 Thread Netanel Belgazal
To increase readability, refactor skb allocation to dedicated function
This change does not impact the performance since the compiler optimize
the code and elimitate the if condition.

Signed-off-by: Netanel Belgazal 
---
 drivers/net/ethernet/amazon/ena/ena_netdev.c | 46 
 1 file changed, 27 insertions(+), 19 deletions(-)

diff --git a/drivers/net/ethernet/amazon/ena/ena_netdev.c 
b/drivers/net/ethernet/amazon/ena/ena_netdev.c
index 3bc8f43..b478c61 100644
--- a/drivers/net/ethernet/amazon/ena/ena_netdev.c
+++ b/drivers/net/ethernet/amazon/ena/ena_netdev.c
@@ -787,6 +787,28 @@ static int ena_clean_tx_irq(struct ena_ring *tx_ring, u32 
budget)
return tx_pkts;
 }
 
+static struct sk_buff *ena_alloc_skb(struct ena_ring *rx_ring, bool frags)
+{
+   struct sk_buff *skb;
+
+   if (frags)
+   skb = napi_get_frags(rx_ring->napi);
+   else
+   skb = netdev_alloc_skb_ip_align(rx_ring->netdev,
+   rx_ring->rx_copybreak);
+
+   if (unlikely(!skb)) {
+   u64_stats_update_begin(_ring->syncp);
+   rx_ring->rx_stats.skb_alloc_fail++;
+   u64_stats_update_end(_ring->syncp);
+   netif_err(rx_ring->adapter, rx_err, rx_ring->netdev,
+ "Failed to allocate skb. frags: %d\n", frags);
+   return NULL;
+   }
+
+   return skb;
+}
+
 static struct sk_buff *ena_rx_skb(struct ena_ring *rx_ring,
  struct ena_com_rx_buf_info *ena_bufs,
  u32 descs,
@@ -795,8 +817,7 @@ static struct sk_buff *ena_rx_skb(struct ena_ring *rx_ring,
struct sk_buff *skb;
struct ena_rx_buffer *rx_info =
_ring->rx_buffer_info[*next_to_clean];
-   u32 len;
-   u32 buf = 0;
+   u32 len, buf = 0;
void *va;
 
len = ena_bufs[0].len;
@@ -815,16 +836,9 @@ static struct sk_buff *ena_rx_skb(struct ena_ring *rx_ring,
prefetch(va + NET_IP_ALIGN);
 
if (len <= rx_ring->rx_copybreak) {
-   skb = netdev_alloc_skb_ip_align(rx_ring->netdev,
-   rx_ring->rx_copybreak);
-   if (unlikely(!skb)) {
-   u64_stats_update_begin(_ring->syncp);
-   rx_ring->rx_stats.skb_alloc_fail++;
-   u64_stats_update_end(_ring->syncp);
-   netif_err(rx_ring->adapter, rx_err, rx_ring->netdev,
- "Failed to allocate skb\n");
+   skb = ena_alloc_skb(rx_ring, false);
+   if (unlikely(!skb))
return NULL;
-   }
 
netif_dbg(rx_ring->adapter, rx_status, rx_ring->netdev,
  "rx allocated small packet. len %d. data_len %d\n",
@@ -848,15 +862,9 @@ static struct sk_buff *ena_rx_skb(struct ena_ring *rx_ring,
return skb;
}
 
-   skb = napi_get_frags(rx_ring->napi);
-   if (unlikely(!skb)) {
-   netif_dbg(rx_ring->adapter, rx_status, rx_ring->netdev,
- "Failed allocating skb\n");
-   u64_stats_update_begin(_ring->syncp);
-   rx_ring->rx_stats.skb_alloc_fail++;
-   u64_stats_update_end(_ring->syncp);
+   skb = ena_alloc_skb(rx_ring, true);
+   if (unlikely(!skb))
return NULL;
-   }
 
do {
dma_unmap_page(rx_ring->dev,
-- 
1.9.1



[PATCH net 08/18] net/ena: change sizeof() argument to be the type pointer

2016-11-20 Thread Netanel Belgazal
Instead of using:
memset(ptr, 0x0, sizeof(struct ...))
use:
memset(ptr, 0x0, sizeor(*ptr))

Signed-off-by: Netanel Belgazal 
---
 drivers/net/ethernet/amazon/ena/ena_com.c | 16 
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/drivers/net/ethernet/amazon/ena/ena_com.c 
b/drivers/net/ethernet/amazon/ena/ena_com.c
index 366c2c5..edb2e81 100644
--- a/drivers/net/ethernet/amazon/ena/ena_com.c
+++ b/drivers/net/ethernet/amazon/ena/ena_com.c
@@ -329,7 +329,7 @@ static int ena_com_init_io_sq(struct ena_com_dev *ena_dev,
size_t size;
int dev_node = 0;
 
-   memset(_sq->desc_addr, 0x0, sizeof(struct ena_com_io_desc_addr));
+   memset(_sq->desc_addr, 0x0, sizeof(io_sq->desc_addr));
 
io_sq->desc_entry_size =
(io_sq->direction == ENA_COM_IO_QUEUE_DIRECTION_TX) ?
@@ -383,7 +383,7 @@ static int ena_com_init_io_cq(struct ena_com_dev *ena_dev,
size_t size;
int prev_node = 0;
 
-   memset(_cq->cdesc_addr, 0x0, sizeof(struct ena_com_io_desc_addr));
+   memset(_cq->cdesc_addr, 0x0, sizeof(io_cq->cdesc_addr));
 
/* Use the basic completion descriptor for Rx */
io_cq->cdesc_entry_size_in_bytes =
@@ -681,7 +681,7 @@ static int ena_com_destroy_io_sq(struct ena_com_dev 
*ena_dev,
u8 direction;
int ret;
 
-   memset(_cmd, 0x0, sizeof(struct ena_admin_aq_destroy_sq_cmd));
+   memset(_cmd, 0x0, sizeof(destroy_cmd));
 
if (io_sq->direction == ENA_COM_IO_QUEUE_DIRECTION_TX)
direction = ENA_ADMIN_SQ_DIRECTION_TX;
@@ -963,7 +963,7 @@ static int ena_com_create_io_sq(struct ena_com_dev *ena_dev,
u8 direction;
int ret;
 
-   memset(_cmd, 0x0, sizeof(struct ena_admin_aq_create_sq_cmd));
+   memset(_cmd, 0x0, sizeof(create_cmd));
 
create_cmd.aq_common_descriptor.opcode = ENA_ADMIN_CREATE_SQ;
 
@@ -1155,7 +1155,7 @@ int ena_com_create_io_cq(struct ena_com_dev *ena_dev,
struct ena_admin_acq_create_cq_resp_desc cmd_completion;
int ret;
 
-   memset(_cmd, 0x0, sizeof(struct ena_admin_aq_create_cq_cmd));
+   memset(_cmd, 0x0, sizeof(create_cmd));
 
create_cmd.aq_common_descriptor.opcode = ENA_ADMIN_CREATE_CQ;
 
@@ -1263,7 +1263,7 @@ int ena_com_destroy_io_cq(struct ena_com_dev *ena_dev,
struct ena_admin_acq_destroy_cq_resp_desc destroy_resp;
int ret;
 
-   memset(_cmd, 0x0, sizeof(struct ena_admin_aq_destroy_sq_cmd));
+   memset(_cmd, 0x0, sizeof(destroy_cmd));
 
destroy_cmd.cq_idx = io_cq->idx;
destroy_cmd.aq_common_descriptor.opcode = ENA_ADMIN_DESTROY_CQ;
@@ -1613,8 +1613,8 @@ int ena_com_create_io_queue(struct ena_com_dev *ena_dev,
io_sq = _dev->io_sq_queues[ctx->qid];
io_cq = _dev->io_cq_queues[ctx->qid];
 
-   memset(io_sq, 0x0, sizeof(struct ena_com_io_sq));
-   memset(io_cq, 0x0, sizeof(struct ena_com_io_cq));
+   memset(io_sq, 0x0, sizeof(*io_sq));
+   memset(io_cq, 0x0, sizeof(*io_cq));
 
/* Init CQ */
io_cq->q_depth = ctx->queue_size;
-- 
1.9.1



[PATCH net 18/18] net/ena: change driver's default timeouts and increase driver version

2016-11-20 Thread Netanel Belgazal
Driver version was increased to 1.1.2

Signed-off-by: Netanel Belgazal 
---
 drivers/net/ethernet/amazon/ena/ena_com.c| 4 ++--
 drivers/net/ethernet/amazon/ena/ena_netdev.h | 9 +
 2 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/drivers/net/ethernet/amazon/ena/ena_com.c 
b/drivers/net/ethernet/amazon/ena/ena_com.c
index b2891f9..9b158f0 100644
--- a/drivers/net/ethernet/amazon/ena/ena_com.c
+++ b/drivers/net/ethernet/amazon/ena/ena_com.c
@@ -36,9 +36,9 @@
 /*/
 
 /* Timeout in micro-sec */
-#define ADMIN_CMD_TIMEOUT_US (100)
+#define ADMIN_CMD_TIMEOUT_US (300)
 
-#define ENA_ASYNC_QUEUE_DEPTH 4
+#define ENA_ASYNC_QUEUE_DEPTH 16
 #define ENA_ADMIN_QUEUE_DEPTH 32
 
 #define MIN_ENA_VER (((ENA_COMMON_SPEC_VERSION_MAJOR) << \
diff --git a/drivers/net/ethernet/amazon/ena/ena_netdev.h 
b/drivers/net/ethernet/amazon/ena/ena_netdev.h
index c081fd3..de1e5ac 100644
--- a/drivers/net/ethernet/amazon/ena/ena_netdev.h
+++ b/drivers/net/ethernet/amazon/ena/ena_netdev.h
@@ -39,12 +39,13 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "ena_com.h"
 #include "ena_eth_com.h"
 
 #define DRV_MODULE_VER_MAJOR   1
-#define DRV_MODULE_VER_MINOR   0
+#define DRV_MODULE_VER_MINOR   1
 #define DRV_MODULE_VER_SUBMINOR 2
 
 #define DRV_MODULE_NAME"ena"
@@ -100,7 +101,7 @@
 /* Number of queues to check for missing queues per timer service */
 #define ENA_MONITORED_TX_QUEUES4
 /* Max timeout packets before device reset */
-#define MAX_NUM_OF_TIMEOUTED_PACKETS 32
+#define MAX_NUM_OF_TIMEOUTED_PACKETS 128
 
 #define ENA_TX_RING_IDX_NEXT(idx, ring_size) (((idx) + 1) & ((ring_size) - 1))
 
@@ -116,9 +117,9 @@
 #define ENA_IO_IRQ_IDX(q)  (ENA_IO_IRQ_FIRST_IDX + (q))
 
 /* ENA device should send keep alive msg every 1 sec.
- * We wait for 3 sec just to be on the safe side.
+ * We wait for 6 sec just to be on the safe side.
  */
-#define ENA_DEVICE_KALIVE_TIMEOUT  (3 * HZ)
+#define ENA_DEVICE_KALIVE_TIMEOUT  (6 * HZ)
 
 #define ENA_MMIO_DISABLE_REG_READ  BIT(0)
 
-- 
1.9.1



[PATCH net 06/18] net/ena: fix ethtool RSS flow configuration

2016-11-20 Thread Netanel Belgazal
ena_flow_data_to_flow_hash and ena_flow_hash_to_flow_type
treat the ena_flow_hash_to_flow_type enum as power of two values.

Change the values of ena_admin_flow_hash_fields to be power of two values.

Signed-off-by: Netanel Belgazal 
---
 drivers/net/ethernet/amazon/ena/ena_admin_defs.h | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/net/ethernet/amazon/ena/ena_admin_defs.h 
b/drivers/net/ethernet/amazon/ena/ena_admin_defs.h
index 51b2a92..c78f0b2 100644
--- a/drivers/net/ethernet/amazon/ena/ena_admin_defs.h
+++ b/drivers/net/ethernet/amazon/ena/ena_admin_defs.h
@@ -633,22 +633,22 @@ enum ena_admin_flow_hash_proto {
 /* RSS flow hash fields */
 enum ena_admin_flow_hash_fields {
/* Ethernet Dest Addr */
-   ENA_ADMIN_RSS_L2_DA = 0,
+   ENA_ADMIN_RSS_L2_DA = 0x1,
 
/* Ethernet Src Addr */
-   ENA_ADMIN_RSS_L2_SA = 1,
+   ENA_ADMIN_RSS_L2_SA = 0x2,
 
/* ipv4/6 Dest Addr */
-   ENA_ADMIN_RSS_L3_DA = 2,
+   ENA_ADMIN_RSS_L3_DA = 0x4,
 
/* ipv4/6 Src Addr */
-   ENA_ADMIN_RSS_L3_SA = 5,
+   ENA_ADMIN_RSS_L3_SA = 0x8,
 
/* tcp/udp Dest Port */
-   ENA_ADMIN_RSS_L4_DP = 6,
+   ENA_ADMIN_RSS_L4_DP = 0x10,
 
/* tcp/udp Src Port */
-   ENA_ADMIN_RSS_L4_SP = 7,
+   ENA_ADMIN_RSS_L4_SP = 0x20,
 };
 
 struct ena_admin_proto_input {
-- 
1.9.1



[PATCH net 10/18] net/ena: use READ_ONCE to access completion descriptors

2016-11-20 Thread Netanel Belgazal
Completion descriptors are accessed from the driver and from the device.
To avoid reading the old value, use READ_ONCE macro.

Signed-off-by: Netanel Belgazal 
---
 drivers/net/ethernet/amazon/ena/ena_com.h | 1 +
 drivers/net/ethernet/amazon/ena/ena_eth_com.c | 8 
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/net/ethernet/amazon/ena/ena_com.h 
b/drivers/net/ethernet/amazon/ena/ena_com.h
index 6883ee5..f8cdce0 100644
--- a/drivers/net/ethernet/amazon/ena/ena_com.h
+++ b/drivers/net/ethernet/amazon/ena/ena_com.h
@@ -33,6 +33,7 @@
 #ifndef ENA_COM
 #define ENA_COM
 
+#include 
 #include 
 #include 
 #include 
diff --git a/drivers/net/ethernet/amazon/ena/ena_eth_com.c 
b/drivers/net/ethernet/amazon/ena/ena_eth_com.c
index 539c536..f999305 100644
--- a/drivers/net/ethernet/amazon/ena/ena_eth_com.c
+++ b/drivers/net/ethernet/amazon/ena/ena_eth_com.c
@@ -45,7 +45,7 @@ static inline struct ena_eth_io_rx_cdesc_base 
*ena_com_get_next_rx_cdesc(
cdesc = (struct ena_eth_io_rx_cdesc_base *)(io_cq->cdesc_addr.virt_addr
+ (head_masked * io_cq->cdesc_entry_size_in_bytes));
 
-   desc_phase = (cdesc->status & ENA_ETH_IO_RX_CDESC_BASE_PHASE_MASK) >>
+   desc_phase = (READ_ONCE(cdesc->status) & 
ENA_ETH_IO_RX_CDESC_BASE_PHASE_MASK) >>
ENA_ETH_IO_RX_CDESC_BASE_PHASE_SHIFT;
 
if (desc_phase != expected_phase)
@@ -141,7 +141,7 @@ static inline u16 ena_com_cdesc_rx_pkt_get(struct 
ena_com_io_cq *io_cq,
 
ena_com_cq_inc_head(io_cq);
count++;
-   last = (cdesc->status & ENA_ETH_IO_RX_CDESC_BASE_LAST_MASK) >>
+   last = (READ_ONCE(cdesc->status) & 
ENA_ETH_IO_RX_CDESC_BASE_LAST_MASK) >>
ENA_ETH_IO_RX_CDESC_BASE_LAST_SHIFT;
} while (!last);
 
@@ -489,13 +489,13 @@ int ena_com_tx_comp_req_id_get(struct ena_com_io_cq 
*io_cq, u16 *req_id)
 * expected, it mean that the device still didn't update
 * this completion.
 */
-   cdesc_phase = cdesc->flags & ENA_ETH_IO_TX_CDESC_PHASE_MASK;
+   cdesc_phase = READ_ONCE(cdesc->flags) & ENA_ETH_IO_TX_CDESC_PHASE_MASK;
if (cdesc_phase != expected_phase)
return -EAGAIN;
 
ena_com_cq_inc_head(io_cq);
 
-   *req_id = cdesc->req_id;
+   *req_id = READ_ONCE(cdesc->req_id);
 
return 0;
 }
-- 
1.9.1



[PATCH net 17/18] net/ena: fix NULL dereference when removing the driver after device reset faild

2016-11-20 Thread Netanel Belgazal
If for some reason the device stop responding and the device reset failed
to recover the device, the mmio register read datastructure will not be
reinitialized.
On driver removal, the driver will also tries to reset the device
but this time the mmio data structure will be NULL.

To solve this issue perform the device reset in the remove function only if
the device is runnig.

Signed-off-by: Netanel Belgazal 
---
 drivers/net/ethernet/amazon/ena/ena_netdev.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/amazon/ena/ena_netdev.c 
b/drivers/net/ethernet/amazon/ena/ena_netdev.c
index ba395aa..12d1dca 100644
--- a/drivers/net/ethernet/amazon/ena/ena_netdev.c
+++ b/drivers/net/ethernet/amazon/ena/ena_netdev.c
@@ -2591,6 +2591,8 @@ static void ena_fw_reset_device(struct work_struct *work)
 err:
rtnl_unlock();
 
+   clear_bit(ENA_FLAG_DEVICE_RUNNING, >flags);
+
dev_err(>dev,
"Reset attempt failed. Can not reset the device\n");
 }
@@ -3251,7 +3253,9 @@ static void ena_remove(struct pci_dev *pdev)
 
cancel_work_sync(>resume_io_task);
 
-   ena_com_dev_reset(ena_dev);
+   /* Reset the device only if the device is running. */
+   if (test_bit(ENA_FLAG_DEVICE_RUNNING, >flags))
+   ena_com_dev_reset(ena_dev);
 
ena_free_mgmnt_irq(adapter);
 
-- 
1.9.1



[PATCH net 16/18] net/ena: fix error handling when probe fails

2016-11-20 Thread Netanel Belgazal
When driver fails in probe, it will release all resources, including
adapter.
In case of probe failure, ena_remove should not try to free the adapter
resources.

Signed-off-by: Netanel Belgazal 
---
 drivers/net/ethernet/amazon/ena/ena_netdev.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/net/ethernet/amazon/ena/ena_netdev.c 
b/drivers/net/ethernet/amazon/ena/ena_netdev.c
index bff082a..ba395aa 100644
--- a/drivers/net/ethernet/amazon/ena/ena_netdev.c
+++ b/drivers/net/ethernet/amazon/ena/ena_netdev.c
@@ -3179,6 +3179,7 @@ static int ena_probe(struct pci_dev *pdev, const struct 
pci_device_id *ent)
 err_free_region:
ena_release_bars(ena_dev, pdev);
 err_free_ena_dev:
+   pci_set_drvdata(pdev, NULL);
vfree(ena_dev);
 err_disable_device:
pci_disable_device(pdev);
-- 
1.9.1