From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: mx.groups.io; dkim=pass header.i=@semihalf-com.20150623.gappssmtp.com header.s=20150623 header.b=KwUPjTzW; spf=none, err=SPF record not found (domain: semihalf.com, ip: 209.85.208.193, mailfrom: mw@semihalf.com) Received: from mail-lj1-f193.google.com (mail-lj1-f193.google.com [209.85.208.193]) by groups.io with SMTP; Thu, 02 May 2019 16:50:38 -0700 Received: by mail-lj1-f193.google.com with SMTP id s7so3808746ljh.1 for ; Thu, 02 May 2019 16:50:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=semihalf-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ksuQOhr0RVGlRPocZ/zDazLR7gCv5Y49gjcRvF5m5Kg=; b=KwUPjTzWDOrL+8svNDasPqi8UsBa5qqBVndUo7i/S17zSeNBur044Q7D9R0LXkMN3B tHCaMfAdrXxfaQvTuUJvAa1LVx3XXhNYHiXpfag23MbZW84u/Z5XG20ewO2S7MrjnVys +YpD9Nwzeh3Ujvny7G7I8Yu4qfOY7490Mdd8EJqRXivXAJDxoVpr/1+fyqL8iuXu1jpQ XhvZABoKL0O427vAmUqHlxOwXh1Cr6sN/OX+ZACD4WbgR7OjZNBhebjfGhNU7EhZWSHP tNYz/uQ3GJtpuNh3ertINayjnHTjlH3Igorh/9k9yL2uh6ee4IqB5tT13cU4TdfAxeTC 1J2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ksuQOhr0RVGlRPocZ/zDazLR7gCv5Y49gjcRvF5m5Kg=; b=niPbHoVjRr73vm/CinAzj/m4js/Wa8SBFOuwOSHdCtMKL5Oiv42M+j7ohcckIsswNB boxeLyjiv0MGlVw9zWwwhUyfQDAwMyfyuC+kCyWTjgEmDxzYT9ImvZE0JfGbf7cFDzA3 rziMpyD+Pxay7EonQjmdWqfXZhyrXl/dhyw1UM0Mfzi46CFk0yIIWaIhyBBgXznhH1YF xQzL2eLZ3xe7VEdE8dKXpVQbB+ZtY/62mmBph90TD4G6Der4lkWNssX/7umYS0pz8wvX pqJo22m78tZg/YhWlooumsuAVeg8eqIXwE0mURYLA+j58r19hY8vcCMdUTSDlyzhzIrr ZOgQ== X-Gm-Message-State: APjAAAUFWvFgQ63Nu9VHa0nykhlU1/17C6VATlUpPELCK0HtLIqgD1fT hVsITIHwcmqxMB1ksdgqLnGFxLM2aNU1iA== X-Google-Smtp-Source: APXvYqxs5cNmOdayr8xgTw1o99hnanU+vM68mdWsGxVFwP89G/ghi+ey7LSCz3/3T4PRhVwi9ifslw== X-Received: by 2002:a2e:81d3:: with SMTP id s19mr3715029ljg.43.1556841035548; Thu, 02 May 2019 16:50:35 -0700 (PDT) Return-Path: Received: from gilgamesh.semihalf.com (31-172-191-173.noc.fibertech.net.pl. [31.172.191.173]) by smtp.gmail.com with ESMTPSA id o17sm74078lji.23.2019.05.02.16.50.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 02 May 2019 16:50:34 -0700 (PDT) From: "Marcin Wojtas" To: devel@edk2.groups.io Cc: leif.lindholm@linaro.org, ard.biesheuvel@linaro.org, mw@semihalf.com, jsd@semihalf.com, jaz@semihalf.com, kostap@marvell.com, Jici.Gao@arm.com Subject: [edk2-platforms: PATCH 2/4] Marvell/Drivers: MvPhyDxe: Improve 88E1510 initialization Date: Fri, 3 May 2019 01:50:14 +0200 Message-Id: <1556841016-10342-3-git-send-email-mw@semihalf.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1556841016-10342-1-git-send-email-mw@semihalf.com> References: <1556841016-10342-1-git-send-email-mw@semihalf.com> This patch adds only a non-functional change, extracting common startup autonegotiation configuration into a separate routine. It will be re-used in 88E1112 PHY support addition in a following patch. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Marcin Wojtas --- Silicon/Marvell/Drivers/Net/MvPhyDxe/MvPhyDxe.c | 86 +++++++++++++------- 1 file changed, 57 insertions(+), 29 deletions(-) diff --git a/Silicon/Marvell/Drivers/Net/MvPhyDxe/MvPhyDxe.c b/Silicon/Marvell/Drivers/Net/MvPhyDxe/MvPhyDxe.c index 9be0489..780e8bd 100644 --- a/Silicon/Marvell/Drivers/Net/MvPhyDxe/MvPhyDxe.c +++ b/Silicon/Marvell/Drivers/Net/MvPhyDxe/MvPhyDxe.c @@ -251,6 +251,58 @@ MvPhyParseStatus ( return EFI_SUCCESS; } +/** + Configure PHY device autonegotiation. + + @param[in out] *PhyDevice A pointer to configured PHY device structure. + +**/ +STATIC +EFI_STATUS +MvPhyConfigureAutonegotiation ( + IN OUT PHY_DEVICE *PhyDevice + ) +{ + UINT32 Data; + INTN Index; + + /* Read BMSR register in order to check autoneg capabilities and status. */ + Mdio->Read (Mdio, PhyDevice->Addr, PhyDevice->MdioIndex, MII_BMSR, &Data); + + if ((Data & BMSR_ANEGCAPABLE) && !(Data & BMSR_ANEGCOMPLETE)) { + + DEBUG ((DEBUG_INFO, + "%a: Waiting for PHY auto negotiation...", + __FUNCTION__)); + + /* Wait for autonegotiation to complete and read media status */ + for (Index = 0; !(Data & BMSR_ANEGCOMPLETE); Index++) { + if (Index > PHY_AUTONEGOTIATE_TIMEOUT) { + DEBUG ((DEBUG_ERROR, "%a: Timeout\n", __FUNCTION__)); + PhyDevice->LinkUp = FALSE; + return EFI_TIMEOUT; + } + gBS->Stall(1000); /* 1 ms */ + Mdio->Read (Mdio, PhyDevice->Addr, PhyDevice->MdioIndex, MII_BMSR, &Data); + } + + PhyDevice->LinkUp = TRUE; + DEBUG ((DEBUG_INFO, "%a: link up\n", __FUNCTION__)); + } else { + Mdio->Read (Mdio, PhyDevice->Addr, PhyDevice->MdioIndex, MII_BMSR, &Data); + + if (Data & BMSR_LSTATUS) { + PhyDevice->LinkUp = TRUE; + DEBUG ((DEBUG_INFO, "%a: link up\n", __FUNCTION__)); + } else { + PhyDevice->LinkUp = FALSE; + DEBUG ((DEBUG_INFO, "%a: link down\n", __FUNCTION__)); + } + } + + return EFI_SUCCESS; +} + STATIC VOID MvPhy1512WriteBits ( @@ -282,8 +334,7 @@ MvPhyInit1512 ( IN OUT PHY_DEVICE *PhyDev ) { - UINT32 Data; - INTN i; + EFI_STATUS Status; if (PhyDev->Connection == PHY_CONNECTION_SGMII) { /* Select page 0xff and update configuration registers according to @@ -321,34 +372,11 @@ MvPhyInit1512 ( if (!PcdGetBool (PcdPhyStartupAutoneg)) return EFI_SUCCESS; - Mdio->Read (Mdio, PhyDev->Addr, PhyDev->MdioIndex, MII_BMSR, &Data); - - if ((Data & BMSR_ANEGCAPABLE) && !(Data & BMSR_ANEGCOMPLETE)) { - - DEBUG((DEBUG_ERROR, "MvPhyDxe: Waiting for PHY auto negotiation... ")); - for (i = 0; !(Data & BMSR_ANEGCOMPLETE); i++) { - if (i > PHY_AUTONEGOTIATE_TIMEOUT) { - DEBUG((DEBUG_ERROR, "timeout\n")); - PhyDev->LinkUp = FALSE; - return EFI_TIMEOUT; - } - - gBS->Stall(1000); /* 1 ms */ - Mdio->Read (Mdio, PhyDev->Addr, PhyDev->MdioIndex, MII_BMSR, &Data); - } - PhyDev->LinkUp = TRUE; - DEBUG((DEBUG_INFO, "MvPhyDxe: link up\n")); - } else { - Mdio->Read (Mdio, PhyDev->Addr, PhyDev->MdioIndex, MII_BMSR, &Data); - - if (Data & BMSR_LSTATUS) { - PhyDev->LinkUp = TRUE; - DEBUG((DEBUG_INFO, "MvPhyDxe: link up\n")); - } else { - PhyDev->LinkUp = FALSE; - DEBUG((DEBUG_INFO, "MvPhyDxe: link down\n")); - } + Status = MvPhyConfigureAutonegotiation (PhyDev); + if (EFI_ERROR (Status)) { + return Status; } + MvPhyParseStatus (PhyDev); return EFI_SUCCESS; -- 2.7.4