From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.6 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E6E52C3F2D1 for ; Thu, 5 Mar 2020 12:42:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BA6DC20848 for ; Thu, 5 Mar 2020 12:42:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=armlinux.org.uk header.i=@armlinux.org.uk header.b="g7N97tBx" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726676AbgCEMmz (ORCPT ); Thu, 5 Mar 2020 07:42:55 -0500 Received: from pandora.armlinux.org.uk ([78.32.30.218]:40000 "EHLO pandora.armlinux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725993AbgCEMmy (ORCPT ); Thu, 5 Mar 2020 07:42:54 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=armlinux.org.uk; s=pandora-2019; h=Date:Sender:Message-Id:Content-Type: Content-Transfer-Encoding:MIME-Version:Subject:Cc:To:From:References: In-Reply-To:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=ufOxf3MwJMOSG/hTPq9978ut/ioVqhnx9bPmefE5Nx4=; b=g7N97tBxAXQhTytbEVoUr62ky0 ni4CARhBlZFwAKv7QwFqf8+gX8GLzPMwbng026gbUJ5K2aaOB+ssdq33QZjZvfF+y7xj2bNyYKqcU 6gjqTlVRD7TYBRjU9uO2yq7o8hURKQ4ZysNqpAJ6FDtnTQEsSqfoHErP/M9ho31wbntdrQ7l0EtAr fZRqwZNTJ4/vOQ1202RHOZr0/Sd+60en9L0nfsbnb2JQcG28vm6D1Nas5CjMAIp/6mw146VCcOSzU DY6fGc2F3Bio/UvPqTahH59Yh2VX2PxYDqvKfMSUXOK8tPGC3eO4TbfbaecPetAvNsEWhITg+AfI9 1BHD+hNA==; Received: from e0022681537dd.dyn.armlinux.org.uk ([fd8f:7570:feb6:1:222:68ff:fe15:37dd]:58762 helo=rmk-PC.armlinux.org.uk) by pandora.armlinux.org.uk with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) (envelope-from ) id 1j9ppn-0006Rd-6b; Thu, 05 Mar 2020 12:42:39 +0000 Received: from rmk by rmk-PC.armlinux.org.uk with local (Exim 4.92) (envelope-from ) id 1j9ppk-00072U-PD; Thu, 05 Mar 2020 12:42:36 +0000 In-Reply-To: <20200305124139.GB25745@shell.armlinux.org.uk> References: <20200305124139.GB25745@shell.armlinux.org.uk> From: Russell King To: Andrew Lunn , Florian Fainelli , Heiner Kallweit Cc: "David S. Miller" , netdev@vger.kernel.org, Vivien Didelot Subject: [PATCH net-next 07/10] net: dsa: mv88e6xxx: fix Serdes link changes MIME-Version: 1.0 Content-Disposition: inline Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="utf-8" Message-Id: Date: Thu, 05 Mar 2020 12:42:36 +0000 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org phylink_mac_change() is supposed to be called with a 'false' argument if the link has gone down since it was last reported up; this is to ensure that link events along with renegotiation events are always correctly reported to userspace. Read the BMSR once when we have an interrupt, and report the link latched status to phylink via phylink_mac_change(). phylink will deal automatically with re-reading the link state once it has processed the link-down event. Signed-off-by: Russell King --- drivers/net/dsa/mv88e6xxx/serdes.c | 33 +++++++++++------------------- drivers/net/dsa/mv88e6xxx/serdes.h | 1 + 2 files changed, 13 insertions(+), 21 deletions(-) diff --git a/drivers/net/dsa/mv88e6xxx/serdes.c b/drivers/net/dsa/mv88e6xxx/serdes.c index 6c7b031e614b..2098f19b534d 100644 --- a/drivers/net/dsa/mv88e6xxx/serdes.c +++ b/drivers/net/dsa/mv88e6xxx/serdes.c @@ -340,26 +340,17 @@ int mv88e6352_serdes_get_stats(struct mv88e6xxx_chip *chip, int port, static void mv88e6352_serdes_irq_link(struct mv88e6xxx_chip *chip, int port) { - struct dsa_switch *ds = chip->ds; - u16 status; - bool up; + u16 bmsr; int err; - err = mv88e6352_serdes_read(chip, MII_BMSR, &status); - if (err) - return; - - /* Status must be read twice in order to give the current link - * status. Otherwise the change in link status since the last - * read of the register is returned. - */ - err = mv88e6352_serdes_read(chip, MII_BMSR, &status); - if (err) + /* If the link has dropped, we want to know about it. */ + err = mv88e6352_serdes_read(chip, MII_BMSR, &bmsr); + if (err) { + dev_err(chip->dev, "can't read Serdes BMSR: %d\n", err); return; + } - up = status & BMSR_LSTATUS; - - dsa_port_phylink_mac_change(ds, port, up); + dsa_port_phylink_mac_change(chip->ds, port, !!(bmsr & BMSR_LSTATUS)); } irqreturn_t mv88e6352_serdes_irq_status(struct mv88e6xxx_chip *chip, int port, @@ -833,18 +824,18 @@ int mv88e6390_serdes_pcs_link_up(struct mv88e6xxx_chip *chip, int port, static void mv88e6390_serdes_irq_link_sgmii(struct mv88e6xxx_chip *chip, int port, u8 lane) { - u16 status; + u16 bmsr; int err; + /* If the link has dropped, we want to know about it. */ err = mv88e6390_serdes_read(chip, lane, MDIO_MMD_PHYXS, - MV88E6390_SGMII_PHY_STATUS, &status); + MV88E6390_SGMII_BMSR, &bmsr); if (err) { - dev_err(chip->dev, "can't read SGMII PHY status: %d\n", err); + dev_err(chip->dev, "can't read Serdes BMSR: %d\n", err); return; } - dsa_port_phylink_mac_change(chip->ds, port, - !!(status & MV88E6390_SGMII_PHY_STATUS_LINK)); + dsa_port_phylink_mac_change(chip->ds, port, !!(bmsr & BMSR_LSTATUS)); } static int mv88e6390_serdes_irq_enable_sgmii(struct mv88e6xxx_chip *chip, diff --git a/drivers/net/dsa/mv88e6xxx/serdes.h b/drivers/net/dsa/mv88e6xxx/serdes.h index a0c95322987d..7990cadba4c2 100644 --- a/drivers/net/dsa/mv88e6xxx/serdes.h +++ b/drivers/net/dsa/mv88e6xxx/serdes.h @@ -48,6 +48,7 @@ /* 1000BASE-X and SGMII */ #define MV88E6390_SGMII_BMCR (0x2000 + MII_BMCR) +#define MV88E6390_SGMII_BMSR (0x2000 + MII_BMSR) #define MV88E6390_SGMII_ADVERTISE (0x2000 + MII_ADVERTISE) #define MV88E6390_SGMII_LPA (0x2000 + MII_LPA) #define MV88E6390_SGMII_INT_ENABLE 0xa001 -- 2.20.1