linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next 1/5] net: gemini: Look up L3 maxlen from table
@ 2018-06-30 16:18 Linus Walleij
  2018-06-30 16:18 ` [PATCH net-next 2/5] net: gemini: Improve connection prints Linus Walleij
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Linus Walleij @ 2018-06-30 16:18 UTC (permalink / raw)
  To: linux-arm-kernel

The code to calculate the hardware register enumerator
for the maximum L3 length isn't entirely simple to read.
Use the existing defines and rewrite the function into a
table look-up.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
 drivers/net/ethernet/cortina/gemini.c | 61 ++++++++++++++++++++-------
 1 file changed, 46 insertions(+), 15 deletions(-)

diff --git a/drivers/net/ethernet/cortina/gemini.c b/drivers/net/ethernet/cortina/gemini.c
index 6d7404f66f84..8fc31723f700 100644
--- a/drivers/net/ethernet/cortina/gemini.c
+++ b/drivers/net/ethernet/cortina/gemini.c
@@ -401,26 +401,57 @@ static int gmac_setup_phy(struct net_device *netdev)
 	return 0;
 }
 
-static int gmac_pick_rx_max_len(int max_l3_len)
-{
-	/* index = CONFIG_MAXLEN_XXX values */
-	static const int max_len[8] = {
-		1536, 1518, 1522, 1542,
-		9212, 10236, 1518, 1518
-	};
-	int i, n = 5;
+/* The maximum frame length is not logically enumerated in the
+ * hardware, so we do a table lookup to find the applicable max
+ * frame length.
+ */
+struct gmac_max_framelen {
+	unsigned int max_l3_len;
+	u8 val;
+};
 
-	max_l3_len += ETH_HLEN + VLAN_HLEN;
+static const struct gmac_max_framelen gmac_maxlens[] = {
+	{
+		.max_l3_len = 1518,
+		.val = CONFIG0_MAXLEN_1518,
+	},
+	{
+		.max_l3_len = 1522,
+		.val = CONFIG0_MAXLEN_1522,
+	},
+	{
+		.max_l3_len = 1536,
+		.val = CONFIG0_MAXLEN_1536,
+	},
+	{
+		.max_l3_len = 1542,
+		.val = CONFIG0_MAXLEN_1542,
+	},
+	{
+		.max_l3_len = 9212,
+		.val = CONFIG0_MAXLEN_9k,
+	},
+	{
+		.max_l3_len = 10236,
+		.val = CONFIG0_MAXLEN_10k,
+	},
+};
+
+static int gmac_pick_rx_max_len(unsigned int max_l3_len)
+{
+	const struct gmac_max_framelen *maxlen;
+	int maxtot;
+	int i;
 
-	if (max_l3_len > max_len[n])
-		return -1;
+	maxtot = max_l3_len + ETH_HLEN + VLAN_HLEN;
 
-	for (i = 0; i < 5; i++) {
-		if (max_len[i] >= max_l3_len && max_len[i] < max_len[n])
-			n = i;
+	for (i = 0; i < ARRAY_SIZE(gmac_maxlens); i++) {
+		maxlen = &gmac_maxlens[i];
+		if (maxtot <= maxlen->max_l3_len)
+			return maxlen->val;
 	}
 
-	return n;
+	return -1;
 }
 
 static int gmac_init(struct net_device *netdev)
-- 
2.17.1

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

* [PATCH net-next 2/5] net: gemini: Improve connection prints
  2018-06-30 16:18 [PATCH net-next 1/5] net: gemini: Look up L3 maxlen from table Linus Walleij
@ 2018-06-30 16:18 ` Linus Walleij
  2018-07-01  7:54   ` Andrew Lunn
  2018-06-30 16:18 ` [PATCH net-next 3/5] net: gemini: Allow multiple ports to instantiate Linus Walleij
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 7+ messages in thread
From: Linus Walleij @ 2018-06-30 16:18 UTC (permalink / raw)
  To: linux-arm-kernel

Instead of just specify that a PHY is connected at some
speed, also specify which one. This is helpful with several
PHYs on the system.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
 drivers/net/ethernet/cortina/gemini.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/drivers/net/ethernet/cortina/gemini.c b/drivers/net/ethernet/cortina/gemini.c
index 8fc31723f700..b49ed8964026 100644
--- a/drivers/net/ethernet/cortina/gemini.c
+++ b/drivers/net/ethernet/cortina/gemini.c
@@ -300,23 +300,26 @@ static void gmac_speed_set(struct net_device *netdev)
 		status.bits.speed = GMAC_SPEED_1000;
 		if (phydev->interface == PHY_INTERFACE_MODE_RGMII)
 			status.bits.mii_rmii = GMAC_PHY_RGMII_1000;
-		netdev_info(netdev, "connect to RGMII @ 1Gbit\n");
+		netdev_info(netdev, "connect %s to RGMII @ 1Gbit\n",
+			    phydev_name(phydev));
 		break;
 	case 100:
 		status.bits.speed = GMAC_SPEED_100;
 		if (phydev->interface == PHY_INTERFACE_MODE_RGMII)
 			status.bits.mii_rmii = GMAC_PHY_RGMII_100_10;
-		netdev_info(netdev, "connect to RGMII @ 100 Mbit\n");
+		netdev_info(netdev, "connect %s to RGMII @ 100 Mbit\n",
+			    phydev_name(phydev));
 		break;
 	case 10:
 		status.bits.speed = GMAC_SPEED_10;
 		if (phydev->interface == PHY_INTERFACE_MODE_RGMII)
 			status.bits.mii_rmii = GMAC_PHY_RGMII_100_10;
-		netdev_info(netdev, "connect to RGMII @ 10 Mbit\n");
+		netdev_info(netdev, "connect %s to RGMII @ 10 Mbit\n",
+			    phydev_name(phydev));
 		break;
 	default:
-		netdev_warn(netdev, "Not supported PHY speed (%d)\n",
-			    phydev->speed);
+		netdev_warn(netdev, "Unsupported PHY speed (%d) on %s\n",
+			    phydev->speed, phydev_name(phydev));
 	}
 
 	if (phydev->duplex == DUPLEX_FULL) {
-- 
2.17.1

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

* [PATCH net-next 3/5] net: gemini: Allow multiple ports to instantiate
  2018-06-30 16:18 [PATCH net-next 1/5] net: gemini: Look up L3 maxlen from table Linus Walleij
  2018-06-30 16:18 ` [PATCH net-next 2/5] net: gemini: Improve connection prints Linus Walleij
@ 2018-06-30 16:18 ` Linus Walleij
  2018-06-30 16:18 ` [PATCH net-next 4/5] net: gemini: Move main init to port Linus Walleij
  2018-06-30 16:18 ` [PATCH net-next 5/5] net: gemini: Indicate that we can handle jumboframes Linus Walleij
  3 siblings, 0 replies; 7+ messages in thread
From: Linus Walleij @ 2018-06-30 16:18 UTC (permalink / raw)
  To: linux-arm-kernel

The code was not tested with two ports actually in use at
the same time. (I blame this on lack of actual hardware using
that feature.) Now after locating a system using both ports,
add necessary fix to make both ports come up.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
 drivers/net/ethernet/cortina/gemini.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/cortina/gemini.c b/drivers/net/ethernet/cortina/gemini.c
index b49ed8964026..8d192fcd51c8 100644
--- a/drivers/net/ethernet/cortina/gemini.c
+++ b/drivers/net/ethernet/cortina/gemini.c
@@ -1787,7 +1787,10 @@ static int gmac_open(struct net_device *netdev)
 	phy_start(netdev->phydev);
 
 	err = geth_resize_freeq(port);
-	if (err) {
+	/* It's fine if it's just busy, the other port has set up
+	 * the freeq in that case.
+	 */
+	if (err && (err != -EBUSY)) {
 		netdev_err(netdev, "could not resize freeq\n");
 		goto err_stop_phy;
 	}
-- 
2.17.1

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

* [PATCH net-next 4/5] net: gemini: Move main init to port
  2018-06-30 16:18 [PATCH net-next 1/5] net: gemini: Look up L3 maxlen from table Linus Walleij
  2018-06-30 16:18 ` [PATCH net-next 2/5] net: gemini: Improve connection prints Linus Walleij
  2018-06-30 16:18 ` [PATCH net-next 3/5] net: gemini: Allow multiple ports to instantiate Linus Walleij
@ 2018-06-30 16:18 ` Linus Walleij
  2018-06-30 16:18 ` [PATCH net-next 5/5] net: gemini: Indicate that we can handle jumboframes Linus Walleij
  3 siblings, 0 replies; 7+ messages in thread
From: Linus Walleij @ 2018-06-30 16:18 UTC (permalink / raw)
  To: linux-arm-kernel

The initialization sequence for the ethernet, setting up
interrupt routing and such things, need to be done after
both the ports are clocked and reset. Before this the
config will not "take". Move the initialization to the
port probe function and keep track of init status in
the state.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
 drivers/net/ethernet/cortina/gemini.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/cortina/gemini.c b/drivers/net/ethernet/cortina/gemini.c
index 8d192fcd51c8..79324bbfd768 100644
--- a/drivers/net/ethernet/cortina/gemini.c
+++ b/drivers/net/ethernet/cortina/gemini.c
@@ -146,6 +146,7 @@ struct gemini_ethernet {
 	void __iomem *base;
 	struct gemini_ethernet_port *port0;
 	struct gemini_ethernet_port *port1;
+	bool initialized;
 
 	spinlock_t	irq_lock; /* Locks IRQ-related registers */
 	unsigned int	freeq_order;
@@ -2301,6 +2302,14 @@ static void gemini_port_remove(struct gemini_ethernet_port *port)
 
 static void gemini_ethernet_init(struct gemini_ethernet *geth)
 {
+	/* Only do this once both ports are online */
+	if (geth->initialized)
+		return;
+	if (geth->port0 && geth->port1)
+		geth->initialized = true;
+	else
+		return;
+
 	writel(0, geth->base + GLOBAL_INTERRUPT_ENABLE_0_REG);
 	writel(0, geth->base + GLOBAL_INTERRUPT_ENABLE_1_REG);
 	writel(0, geth->base + GLOBAL_INTERRUPT_ENABLE_2_REG);
@@ -2447,6 +2456,10 @@ static int gemini_ethernet_port_probe(struct platform_device *pdev)
 		geth->port0 = port;
 	else
 		geth->port1 = port;
+
+	/* This will just be done once both ports are up and reset */
+	gemini_ethernet_init(geth);
+
 	platform_set_drvdata(pdev, port);
 
 	/* Set up and register the netdev */
@@ -2564,7 +2577,6 @@ static int gemini_ethernet_probe(struct platform_device *pdev)
 
 	spin_lock_init(&geth->irq_lock);
 	spin_lock_init(&geth->freeq_lock);
-	gemini_ethernet_init(geth);
 
 	/* The children will use this */
 	platform_set_drvdata(pdev, geth);
@@ -2577,8 +2589,8 @@ static int gemini_ethernet_remove(struct platform_device *pdev)
 {
 	struct gemini_ethernet *geth = platform_get_drvdata(pdev);
 
-	gemini_ethernet_init(geth);
 	geth_cleanup_freeq(geth);
+	geth->initialized = false;
 
 	return 0;
 }
-- 
2.17.1

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

* [PATCH net-next 5/5] net: gemini: Indicate that we can handle jumboframes
  2018-06-30 16:18 [PATCH net-next 1/5] net: gemini: Look up L3 maxlen from table Linus Walleij
                   ` (2 preceding siblings ...)
  2018-06-30 16:18 ` [PATCH net-next 4/5] net: gemini: Move main init to port Linus Walleij
@ 2018-06-30 16:18 ` Linus Walleij
  2018-07-01  7:58   ` Andrew Lunn
  3 siblings, 1 reply; 7+ messages in thread
From: Linus Walleij @ 2018-06-30 16:18 UTC (permalink / raw)
  To: linux-arm-kernel

The hardware supposedly handles frames up to 10236 bytes and
implements .ndo_change_mtu() so accept 10236 minus the ethernet
header for a VLAN tagged frame on the netdevices.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
 drivers/net/ethernet/cortina/gemini.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/net/ethernet/cortina/gemini.c b/drivers/net/ethernet/cortina/gemini.c
index 79324bbfd768..ae475393e4ac 100644
--- a/drivers/net/ethernet/cortina/gemini.c
+++ b/drivers/net/ethernet/cortina/gemini.c
@@ -2473,6 +2473,11 @@ static int gemini_ethernet_port_probe(struct platform_device *pdev)
 
 	netdev->hw_features = GMAC_OFFLOAD_FEATURES;
 	netdev->features |= GMAC_OFFLOAD_FEATURES | NETIF_F_GRO;
+	/* We can handle jumbo frames up to 10236 bytes so, let's accept
+	 * payloads of 10236 bytes minus VLAN and ethernet header
+	 */
+	netdev->min_mtu = 256;
+	netdev->max_mtu = 10236 - VLAN_ETH_HLEN;
 
 	port->freeq_refill = 0;
 	netif_napi_add(netdev, &port->napi, gmac_napi_poll,
-- 
2.17.1

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

* [PATCH net-next 2/5] net: gemini: Improve connection prints
  2018-06-30 16:18 ` [PATCH net-next 2/5] net: gemini: Improve connection prints Linus Walleij
@ 2018-07-01  7:54   ` Andrew Lunn
  0 siblings, 0 replies; 7+ messages in thread
From: Andrew Lunn @ 2018-07-01  7:54 UTC (permalink / raw)
  To: linux-arm-kernel

On Sat, Jun 30, 2018 at 06:18:03PM +0200, Linus Walleij wrote:
> Instead of just specify that a PHY is connected at some
> speed, also specify which one. This is helpful with several
> PHYs on the system.

Hi Linus

Could you just use phy_print_status()

      Andrew

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

* [PATCH net-next 5/5] net: gemini: Indicate that we can handle jumboframes
  2018-06-30 16:18 ` [PATCH net-next 5/5] net: gemini: Indicate that we can handle jumboframes Linus Walleij
@ 2018-07-01  7:58   ` Andrew Lunn
  0 siblings, 0 replies; 7+ messages in thread
From: Andrew Lunn @ 2018-07-01  7:58 UTC (permalink / raw)
  To: linux-arm-kernel

On Sat, Jun 30, 2018 at 06:18:06PM +0200, Linus Walleij wrote:
> The hardware supposedly handles frames up to 10236 bytes and
> implements .ndo_change_mtu() so accept 10236 minus the ethernet
> header for a VLAN tagged frame on the netdevices.
> 
> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
> ---
>  drivers/net/ethernet/cortina/gemini.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/drivers/net/ethernet/cortina/gemini.c b/drivers/net/ethernet/cortina/gemini.c
> index 79324bbfd768..ae475393e4ac 100644
> --- a/drivers/net/ethernet/cortina/gemini.c
> +++ b/drivers/net/ethernet/cortina/gemini.c
> @@ -2473,6 +2473,11 @@ static int gemini_ethernet_port_probe(struct platform_device *pdev)
>  
>  	netdev->hw_features = GMAC_OFFLOAD_FEATURES;
>  	netdev->features |= GMAC_OFFLOAD_FEATURES | NETIF_F_GRO;
> +	/* We can handle jumbo frames up to 10236 bytes so, let's accept
> +	 * payloads of 10236 bytes minus VLAN and ethernet header
> +	 */
> +	netdev->min_mtu = 256;
> +	netdev->max_mtu = 10236 - VLAN_ETH_HLEN;

Hi Linus

The commit message does not mention the min mtu you set here. Where
does 256 come from?

Thanks
     Andrew

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

end of thread, other threads:[~2018-07-01  7:58 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-06-30 16:18 [PATCH net-next 1/5] net: gemini: Look up L3 maxlen from table Linus Walleij
2018-06-30 16:18 ` [PATCH net-next 2/5] net: gemini: Improve connection prints Linus Walleij
2018-07-01  7:54   ` Andrew Lunn
2018-06-30 16:18 ` [PATCH net-next 3/5] net: gemini: Allow multiple ports to instantiate Linus Walleij
2018-06-30 16:18 ` [PATCH net-next 4/5] net: gemini: Move main init to port Linus Walleij
2018-06-30 16:18 ` [PATCH net-next 5/5] net: gemini: Indicate that we can handle jumboframes Linus Walleij
2018-07-01  7:58   ` Andrew Lunn

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).