All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net-next 0/3] nfp: MTU changes and other fixes
@ 2016-01-04 16:03 Jakub Kicinski
  2016-01-04 16:03 ` [PATCH net-next 1/3] nfp: free buffers before changing MTU Jakub Kicinski
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Jakub Kicinski @ 2016-01-04 16:03 UTC (permalink / raw)
  To: netdev; +Cc: simon.horman, rolf.neugebauer, Jakub Kicinski

Hi!

Three small fixes around RX buffer sizing.  First one corrects
the length used for unmapping DMA buffers when MTU is changed,
second makes sure buffers are big enough to meet FW's expectations.
Third change corrects packet length validation on RX.


Jakub Kicinski (3):
  nfp: free buffers before changing MTU
  nfp: correct RX buffer length calculation
  nfp: fix RX buffer length validation

 .../net/ethernet/netronome/nfp/nfp_net_common.c    | 37 +++++++++-------------
 1 file changed, 15 insertions(+), 22 deletions(-)

-- 
1.9.1

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH net-next 1/3] nfp: free buffers before changing MTU
  2016-01-04 16:03 [PATCH net-next 0/3] nfp: MTU changes and other fixes Jakub Kicinski
@ 2016-01-04 16:03 ` Jakub Kicinski
  2016-01-05  3:46   ` David Miller
  2016-01-04 16:03 ` [PATCH net-next 2/3] nfp: correct RX buffer length calculation Jakub Kicinski
  2016-01-04 16:03 ` [PATCH net-next 3/3] nfp: fix RX buffer length validation Jakub Kicinski
  2 siblings, 1 reply; 5+ messages in thread
From: Jakub Kicinski @ 2016-01-04 16:03 UTC (permalink / raw)
  To: netdev; +Cc: simon.horman, rolf.neugebauer, Jakub Kicinski

For freeing DMA buffers we depend on nfp_net.fl_bufsz having the same
value as during allocation therefore in .ndo_change_mtu we must first
free the buffers and then change the setting.

Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Reviewed-by: Rolf Neugebauer <rolf.neugebauer@netronome.com>
---
 drivers/net/ethernet/netronome/nfp/nfp_net_common.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/net/ethernet/netronome/nfp/nfp_net_common.c b/drivers/net/ethernet/netronome/nfp/nfp_net_common.c
index 43c618bafdb6..2826166547fd 100644
--- a/drivers/net/ethernet/netronome/nfp/nfp_net_common.c
+++ b/drivers/net/ethernet/netronome/nfp/nfp_net_common.c
@@ -1920,17 +1920,17 @@ static int nfp_net_change_mtu(struct net_device *netdev, int new_mtu)
 		return -EINVAL;
 	}
 
+	if (netif_running(netdev))
+		nfp_net_netdev_close(netdev);
+
 	netdev->mtu = new_mtu;
 
 	/* Freelist buffer size rounded up to the nearest 1K */
 	tmp = new_mtu + ETH_HLEN + VLAN_HLEN + NFP_NET_MAX_PREPEND;
 	nn->fl_bufsz = roundup(tmp, 1024);
 
-	/* restart if running */
-	if (netif_running(netdev)) {
-		nfp_net_netdev_close(netdev);
+	if (netif_running(netdev))
 		nfp_net_netdev_open(netdev);
-	}
 
 	return 0;
 }
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH net-next 2/3] nfp: correct RX buffer length calculation
  2016-01-04 16:03 [PATCH net-next 0/3] nfp: MTU changes and other fixes Jakub Kicinski
  2016-01-04 16:03 ` [PATCH net-next 1/3] nfp: free buffers before changing MTU Jakub Kicinski
@ 2016-01-04 16:03 ` Jakub Kicinski
  2016-01-04 16:03 ` [PATCH net-next 3/3] nfp: fix RX buffer length validation Jakub Kicinski
  2 siblings, 0 replies; 5+ messages in thread
From: Jakub Kicinski @ 2016-01-04 16:03 UTC (permalink / raw)
  To: netdev; +Cc: simon.horman, rolf.neugebauer, Jakub Kicinski

When calculating the RX buffer length we need to account for
up to 2 VLAN tags and up to 8 MPLS labels.  Rounding up to 1k
is an relic of a distant past and can be removed.  While at
it also remove trivial print statement.

Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Reviewed-by: Rolf Neugebauer <rolf.neugebauer@netronome.com>
---
 drivers/net/ethernet/netronome/nfp/nfp_net_common.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/drivers/net/ethernet/netronome/nfp/nfp_net_common.c b/drivers/net/ethernet/netronome/nfp/nfp_net_common.c
index 2826166547fd..bfc522474820 100644
--- a/drivers/net/ethernet/netronome/nfp/nfp_net_common.c
+++ b/drivers/net/ethernet/netronome/nfp/nfp_net_common.c
@@ -61,6 +61,7 @@
 
 #include <linux/ktime.h>
 
+#include <net/mpls.h>
 #include <net/vxlan.h>
 
 #include "nfp_net_ctrl.h"
@@ -1911,9 +1912,6 @@ static void nfp_net_set_rx_mode(struct net_device *netdev)
 static int nfp_net_change_mtu(struct net_device *netdev, int new_mtu)
 {
 	struct nfp_net *nn = netdev_priv(netdev);
-	u32 tmp;
-
-	nn_dbg(nn, "New MTU = %d\n", new_mtu);
 
 	if (new_mtu < 68 || new_mtu > nn->max_mtu) {
 		nn_err(nn, "New MTU (%d) is not valid\n", new_mtu);
@@ -1924,10 +1922,8 @@ static int nfp_net_change_mtu(struct net_device *netdev, int new_mtu)
 		nfp_net_netdev_close(netdev);
 
 	netdev->mtu = new_mtu;
-
-	/* Freelist buffer size rounded up to the nearest 1K */
-	tmp = new_mtu + ETH_HLEN + VLAN_HLEN + NFP_NET_MAX_PREPEND;
-	nn->fl_bufsz = roundup(tmp, 1024);
+	nn->fl_bufsz = NFP_NET_MAX_PREPEND + ETH_HLEN + VLAN_HLEN * 2 +
+		MPLS_HLEN * 8 + new_mtu;
 
 	if (netif_running(netdev))
 		nfp_net_netdev_open(netdev);
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH net-next 3/3] nfp: fix RX buffer length validation
  2016-01-04 16:03 [PATCH net-next 0/3] nfp: MTU changes and other fixes Jakub Kicinski
  2016-01-04 16:03 ` [PATCH net-next 1/3] nfp: free buffers before changing MTU Jakub Kicinski
  2016-01-04 16:03 ` [PATCH net-next 2/3] nfp: correct RX buffer length calculation Jakub Kicinski
@ 2016-01-04 16:03 ` Jakub Kicinski
  2 siblings, 0 replies; 5+ messages in thread
From: Jakub Kicinski @ 2016-01-04 16:03 UTC (permalink / raw)
  To: netdev; +Cc: simon.horman, rolf.neugebauer, Jakub Kicinski

Meaning of data_len and meta_len RX WB descriptor fields depend
slightly on whether rx_offset is dynamic or not.  For dynamic
offsets data_len includes mata_len.  This makes the code harder
to follow, in fact our RX buffer length check is incorrect -
we are comparing allocation length to data_len while we should
also account for meta_len.

Let's adjust the values of data_len and meta_len to their natural
meaning and simplify the logic.

Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Reviewed-by: Rolf Neugebauer <rolf.neugebauer@netronome.com>
---
 drivers/net/ethernet/netronome/nfp/nfp_net_common.c | 19 ++++++++-----------
 1 file changed, 8 insertions(+), 11 deletions(-)

diff --git a/drivers/net/ethernet/netronome/nfp/nfp_net_common.c b/drivers/net/ethernet/netronome/nfp/nfp_net_common.c
index bfc522474820..ee4b99373e33 100644
--- a/drivers/net/ethernet/netronome/nfp/nfp_net_common.c
+++ b/drivers/net/ethernet/netronome/nfp/nfp_net_common.c
@@ -1259,22 +1259,19 @@ static int nfp_net_rx(struct nfp_net_rx_ring *rx_ring, int budget)
 
 		meta_len = rxd->rxd.meta_len_dd & PCIE_DESC_RX_META_LEN_MASK;
 		data_len = le16_to_cpu(rxd->rxd.data_len);
+		/* For dynamic offset data_len includes meta_len, adjust */
+		if (nn->rx_offset == NFP_NET_CFG_RX_OFFSET_DYNAMIC)
+			data_len -= meta_len;
+		else
+			meta_len = nn->rx_offset;
 
-		if (WARN_ON_ONCE(data_len > nn->fl_bufsz)) {
+		if (WARN_ON_ONCE(meta_len + data_len > nn->fl_bufsz)) {
 			dev_kfree_skb_any(skb);
 			continue;
 		}
 
-		if (nn->rx_offset == NFP_NET_CFG_RX_OFFSET_DYNAMIC) {
-			/* The packet data starts after the metadata */
-			skb_reserve(skb, meta_len);
-		} else {
-			/* The packet data starts at a fixed offset */
-			skb_reserve(skb, nn->rx_offset);
-		}
-
-		/* Adjust the SKB for the dynamic meta data pre-pended */
-		skb_put(skb, data_len - meta_len);
+		skb_reserve(skb, meta_len);
+		skb_put(skb, data_len);
 
 		nfp_net_set_hash(nn->netdev, skb, rxd);
 
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH net-next 1/3] nfp: free buffers before changing MTU
  2016-01-04 16:03 ` [PATCH net-next 1/3] nfp: free buffers before changing MTU Jakub Kicinski
@ 2016-01-05  3:46   ` David Miller
  0 siblings, 0 replies; 5+ messages in thread
From: David Miller @ 2016-01-05  3:46 UTC (permalink / raw)
  To: jakub.kicinski; +Cc: netdev, simon.horman, rolf.neugebauer

From: Jakub Kicinski <jakub.kicinski@netronome.com>
Date: Mon,  4 Jan 2016 16:03:13 +0000

> For freeing DMA buffers we depend on nfp_net.fl_bufsz having the same
> value as during allocation therefore in .ndo_change_mtu we must first
> free the buffers and then change the setting.
> 
> Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
> Reviewed-by: Rolf Neugebauer <rolf.neugebauer@netronome.com>

The behavior implemented by this patch is not acceptable.

If an error occurs reopenning the device after the MTU
change, the user is left with an inoperable interface and
zero feedback about what happened or why.

You MUST, therefore, specifically try to allocate the new memory and
resources that correspond to the new MTU value.

And if you can successfully allocate everything and be guarateed to
succeed, only then can you change the MTU and commit to the new
resources.

Otherwise you must leave the interface in exactly the state it was
in prior to the MTU change call and return an error to the caller.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2016-01-05  3:46 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-04 16:03 [PATCH net-next 0/3] nfp: MTU changes and other fixes Jakub Kicinski
2016-01-04 16:03 ` [PATCH net-next 1/3] nfp: free buffers before changing MTU Jakub Kicinski
2016-01-05  3:46   ` David Miller
2016-01-04 16:03 ` [PATCH net-next 2/3] nfp: correct RX buffer length calculation Jakub Kicinski
2016-01-04 16:03 ` [PATCH net-next 3/3] nfp: fix RX buffer length validation Jakub Kicinski

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.