From: Benjamin Herrenschmidt <benh@kernel.crashing.org>
To: netdev@vger.kernel.org
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Subject: [PATCH v2 05/13] ftgmac100: Cleanup speed/duplex tracking and fix duplex config
Date: Wed, 5 Apr 2017 12:28:45 +1000 [thread overview]
Message-ID: <20170405022853.8238-6-benh@kernel.crashing.org> (raw)
In-Reply-To: <20170405022853.8238-1-benh@kernel.crashing.org>
Keep track of both the current speed and duplex settings
instead of only speed and properly apply the duplex setting
to the HW.
This reworks the adjust_link() function to also avoid trying
to reconfigure the HW when there is no link and to display
the link state to the user.
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
--
v2. Use phy_print_status()
Only bail out on link down *after* updating priv->cur_speed
---
drivers/net/ethernet/faraday/ftgmac100.c | 52 +++++++++++++++++++++++++++-----
1 file changed, 44 insertions(+), 8 deletions(-)
diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
index cc2271b..cc6e971 100644
--- a/drivers/net/ethernet/faraday/ftgmac100.c
+++ b/drivers/net/ethernet/faraday/ftgmac100.c
@@ -77,7 +77,8 @@ struct ftgmac100 {
struct mii_bus *mii_bus;
/* Link management */
- int old_speed;
+ int cur_speed;
+ int cur_duplex;
bool use_ncsi;
/* Misc */
@@ -210,16 +211,15 @@ static void ftgmac100_init_hw(struct ftgmac100 *priv)
FTGMAC100_MACCR_RXDMA_EN | \
FTGMAC100_MACCR_TXMAC_EN | \
FTGMAC100_MACCR_RXMAC_EN | \
- FTGMAC100_MACCR_FULLDUP | \
FTGMAC100_MACCR_CRC_APD | \
FTGMAC100_MACCR_RX_RUNT | \
FTGMAC100_MACCR_RX_BROADPKT)
-static void ftgmac100_start_hw(struct ftgmac100 *priv, int speed)
+static void ftgmac100_start_hw(struct ftgmac100 *priv)
{
int maccr = MACCR_ENABLE_ALL;
- switch (speed) {
+ switch (priv->cur_speed) {
default:
case 10:
break;
@@ -233,6 +233,9 @@ static void ftgmac100_start_hw(struct ftgmac100 *priv, int speed)
break;
}
+ if (priv->cur_duplex == DUPLEX_FULL)
+ maccr |= FTGMAC100_MACCR_FULLDUP;
+
iowrite32(maccr, priv->base + FTGMAC100_OFFSET_MACCR);
}
@@ -852,12 +855,31 @@ static void ftgmac100_adjust_link(struct net_device *netdev)
{
struct ftgmac100 *priv = netdev_priv(netdev);
struct phy_device *phydev = netdev->phydev;
+ int new_speed;
int ier;
- if (phydev->speed == priv->old_speed)
+ /* We store "no link" as speed 0 */
+ if (!phydev->link)
+ new_speed = 0;
+ else
+ new_speed = phydev->speed;
+
+ if (phydev->speed == priv->cur_speed &&
+ phydev->duplex == priv->cur_duplex)
return;
- priv->old_speed = phydev->speed;
+ /* Print status if we have a link or we had one and just lost it,
+ * don't print otherwise.
+ */
+ if (new_speed || priv->cur_speed)
+ phy_print_status(phydev);
+
+ priv->cur_speed = new_speed;
+ priv->cur_duplex = phydev->duplex;
+
+ /* Link is down, do nothing else */
+ if (!new_speed)
+ return;
ier = ioread32(priv->base + FTGMAC100_OFFSET_IER);
@@ -869,7 +891,7 @@ static void ftgmac100_adjust_link(struct net_device *netdev)
netif_start_queue(netdev);
ftgmac100_init_hw(priv);
- ftgmac100_start_hw(priv, phydev->speed);
+ ftgmac100_start_hw(priv);
/* re-enable interrupts */
iowrite32(ier, priv->base + FTGMAC100_OFFSET_IER);
@@ -1089,6 +1111,20 @@ static int ftgmac100_open(struct net_device *netdev)
goto err_irq;
}
+ /* When using NC-SI we force the speed to 100Mbit/s full duplex,
+ *
+ * Otherwise we leave it set to 0 (no link), the link
+ * message from the PHY layer will handle setting it up to
+ * something else if needed.
+ */
+ if (priv->use_ncsi) {
+ priv->cur_duplex = DUPLEX_FULL;
+ priv->cur_speed = SPEED_100;
+ } else {
+ priv->cur_duplex = 0;
+ priv->cur_speed = 0;
+ }
+
priv->rx_pointer = 0;
priv->tx_clean_pointer = 0;
priv->tx_pointer = 0;
@@ -1099,7 +1135,7 @@ static int ftgmac100_open(struct net_device *netdev)
goto err_hw;
ftgmac100_init_hw(priv);
- ftgmac100_start_hw(priv, priv->use_ncsi ? 100 : 10);
+ ftgmac100_start_hw(priv);
/* Clear stale interrupts */
status = ioread32(priv->base + FTGMAC100_OFFSET_ISR);
--
2.9.3
next prev parent reply other threads:[~2017-04-05 2:30 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-04-05 2:28 [PATCH v2 00/13] ftgmac100: Rework batch 1 - Link & Interrupts Benjamin Herrenschmidt
2017-04-05 2:28 ` [PATCH v2 01/13] ftgmac100: Use netdev->irq instead of private copy Benjamin Herrenschmidt
2017-04-05 2:28 ` [PATCH v2 02/13] ftgmac100: Remove "banner" comments Benjamin Herrenschmidt
2017-04-05 2:28 ` [PATCH v2 03/13] ftgmac100: Reorder struct fields and comment Benjamin Herrenschmidt
2017-04-05 2:28 ` [PATCH v2 04/13] ftgmac100: Remove "enabled" flags Benjamin Herrenschmidt
2017-04-05 2:28 ` Benjamin Herrenschmidt [this message]
2017-04-05 14:58 ` [PATCH v2 05/13] ftgmac100: Cleanup speed/duplex tracking and fix duplex config Andrew Lunn
2017-04-05 2:28 ` [PATCH v2 06/13] ftgmac100: Split ring alloc, init and rx buffer alloc Benjamin Herrenschmidt
2017-04-05 2:28 ` [PATCH v2 07/13] ftgmac100: Move napi_add/del to open/close Benjamin Herrenschmidt
2017-04-05 2:28 ` [PATCH v2 08/13] ftgmac100: Request the interrupt only after HW is reset Benjamin Herrenschmidt
2017-04-05 2:28 ` [PATCH v2 09/13] ftgmac100: Move the bulk of inits to a separate function Benjamin Herrenschmidt
2017-04-05 2:28 ` [PATCH v2 10/13] ftgmac100: Add a reset task and use it for link changes Benjamin Herrenschmidt
2017-04-05 15:00 ` Andrew Lunn
2017-04-05 2:28 ` [PATCH v2 11/13] ftgmac100: Rework MAC reset and init Benjamin Herrenschmidt
2017-04-05 2:28 ` [PATCH v2 12/13] ftgmac100: Remove useless tests in interrupt handler Benjamin Herrenschmidt
2017-04-05 2:28 ` [PATCH v2 13/13] ftgmac100: Rework NAPI & interrupts handling Benjamin Herrenschmidt
2017-04-05 4:21 ` [PATCH v2 00/13] ftgmac100: Rework batch 1 - Link & Interrupts Florian Fainelli
2017-04-05 5:53 ` Benjamin Herrenschmidt
2017-04-05 6:02 ` Florian Fainelli
2017-04-05 6:31 ` Benjamin Herrenschmidt
2017-04-06 19:46 ` Florian Fainelli
2017-04-06 21:46 ` Benjamin Herrenschmidt
2017-04-06 19:38 ` David Miller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170405022853.8238-6-benh@kernel.crashing.org \
--to=benh@kernel.crashing.org \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).