From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f67.google.com (mail-wm1-f67.google.com [209.85.128.67]) by mx.groups.io with SMTP id smtpd.web12.9665.1591359977076478872 for ; Fri, 05 Jun 2020 05:26:17 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@nuviainc-com.20150623.gappssmtp.com header.s=20150623 header.b=sf7JOa1g; spf=pass (domain: nuviainc.com, ip: 209.85.128.67, mailfrom: leif@nuviainc.com) Received: by mail-wm1-f67.google.com with SMTP id j198so9009279wmj.0 for ; Fri, 05 Jun 2020 05:26:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nuviainc-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=7EkakdBzbhjANComnjAyyjpt5NCydRBEwV+PdkMc7JQ=; b=sf7JOa1gUiHDEM6i2hiwF788AD9wRKlrRKzSH+qdHNammtkKNX41Qn7ej/qVzRnCkO ym7uIeco3aFK6V9KZbsuC0dO83tMc5EXXTtwAFtIPo2aXd1aun3RitnU+nOZBbVKhm5/ u81kx/KaHpqWJJBlQlFBJK9Ze3nHb8JgGloqbf0fTyyuNMDAeGLZk+sCmmrsRe+V78Cx Y0WZASR0YamDFmqpSWCfljxIABW7WsYrtjWozdatA5axmBA/NosunRORXyg1Q0PstluT Dv6z+V7oBZg5WQp7H4AVlVxRChuxu4U2wG+AAeyhCKDgxvzfYWJa9DyuZOhqD/Xj63QO DUiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=7EkakdBzbhjANComnjAyyjpt5NCydRBEwV+PdkMc7JQ=; b=DBOoVYz4GqwE+usIxu0plEaMknYI0MYJb4kYL+mjkqXaiRih7ArTl+Tnu5CfX78V41 S13RVBNJ2GhX4rIcMiuAehxekahxhnGB5AsMtbcOQvy8r+EBgawdSkTEW1T6wii0kH4D fECGx0t5Mm6c77CP/HyxlQ9XpwCV2sC/osnuXDWiE6r5shM6f1oK+IpPHSx6+cGL98Sx FqwmAQYbb3XstRSvtSTZiXi4R0pevS+F7Cmr3vq1NUvCH8/WRgL1Whug4Gjch3QZjLuR xKkt6602XkVQ6OqBYgqq9A5OL5Mmkfk4zUp3gUnCRrpnqtDHU97CRXu9XqDCuDl0qVmb tahw== X-Gm-Message-State: AOAM5304Ntws8cSwjXWD8rB8AIavxcE9eHQumJ1UYTK5/8vt7+hi7q2X okt23RI6P/hgqeLvOgTlV1oPMw== X-Google-Smtp-Source: ABdhPJzUKX1oaVqhbjmN5d04a2d315dnFCm3hMVWyJew8GYkhU3bjM/EoA+eqXYyRiiDX4LCctd2NQ== X-Received: by 2002:a1c:4d0a:: with SMTP id o10mr514786wmh.150.1591359975519; Fri, 05 Jun 2020 05:26:15 -0700 (PDT) Return-Path: Received: from vanye ([2001:470:1f09:12f0:b26e:bfff:fea9:f1b8]) by smtp.gmail.com with ESMTPSA id v27sm12514270wrv.81.2020.06.05.05.26.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jun 2020 05:26:14 -0700 (PDT) Date: Fri, 5 Jun 2020 13:26:12 +0100 From: "Leif Lindholm" To: Wasim Khan Cc: devel@edk2.groups.io, meenakshi.aggarwal@nxp.com, V.Sethi@nxp.com, ard.biesheuvel@arm.com, Wasim Khan Subject: Re: [PATCH edk2-platforms 1/3] Silicon/NXP/Library: Implement SerDesHelperLib Message-ID: <20200605122612.GD28566@vanye> References: <1591039658-18541-1-git-send-email-wasim.khan@oss.nxp.com> <1591039658-18541-2-git-send-email-wasim.khan@oss.nxp.com> MIME-Version: 1.0 In-Reply-To: <1591039658-18541-2-git-send-email-wasim.khan@oss.nxp.com> User-Agent: Mutt/1.10.1 (2018-07-13) Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Tue, Jun 02, 2020 at 00:57:36 +0530, Wasim Khan wrote: > From: Wasim Khan > > Implement SerDesHelperLib to provide helper functions which > can be used for SoC specific serdes configuration. > > Signed-off-by: Wasim Khan > --- > Silicon/NXP/NxpQoriqLs.dec | 1 + > Silicon/NXP/Library/SerDesHelperLib/SerDesHelperLib.inf | 28 ++++ > Silicon/NXP/Include/Library/SerDesHelperLib.h | 64 ++++++++ > Silicon/NXP/Library/SerDesHelperLib/SerDesHelperLib.c | 165 ++++++++++++++++++++ > 4 files changed, 258 insertions(+) > > diff --git a/Silicon/NXP/NxpQoriqLs.dec b/Silicon/NXP/NxpQoriqLs.dec > index d4d3057af509..720bb5794960 100644 > --- a/Silicon/NXP/NxpQoriqLs.dec > +++ b/Silicon/NXP/NxpQoriqLs.dec > @@ -35,6 +35,7 @@ [PcdsFixedAtBuild.common] > gNxpQoriqLsTokenSpaceGuid.PcdNumPciController|0|UINT32|0x00000501 > gNxpQoriqLsTokenSpaceGuid.PcdPcieLutBase|0x0|UINT32|0x00000502 > gNxpQoriqLsTokenSpaceGuid.PcdPcieLutDbg|0x0|UINT32|0x00000503 > + gNxpQoriqLsTokenSpaceGuid.PcdSerdesLanes|0x0|UINT8|0x00000504 > > [PcdsDynamic.common] > gNxpQoriqLsTokenSpaceGuid.PcdPciCfgShiftEnable|FALSE|BOOLEAN|0x00000600 > diff --git a/Silicon/NXP/Library/SerDesHelperLib/SerDesHelperLib.inf b/Silicon/NXP/Library/SerDesHelperLib/SerDesHelperLib.inf > new file mode 100644 > index 000000000000..05814c986393 > --- /dev/null > +++ b/Silicon/NXP/Library/SerDesHelperLib/SerDesHelperLib.inf > @@ -0,0 +1,28 @@ > +## @file > +# > +# Copyright 2020 NXP > +# > +# SPDX-License-Identifier: BSD-2-Clause-Patent > +## > + > +[Defines] > + INF_VERSION = 0x0001001A > + BASE_NAME = SocHelperLib I'm not saying BASE_NAME needs to fully match LIBRARY_CLASS or the name of the directory the file is in, but there is usually a connection with one of them... > + FILE_GUID = 2930e932-a700-41e8-80f9-f1a2dedd2c4f > + MODULE_TYPE = BASE > + VERSION_STRING = 1.0 > + LIBRARY_CLASS = SerDesHelperLib > + > +[Packages] > + MdePkg/MdePkg.dec > + Silicon/NXP/NxpQoriqLs.dec > + > +[LibraryClasses] > + DebugLib > + PcdLib > + > +[Sources.common] > + SerDesHelperLib.c > + > +[FixedPcd] > + gNxpQoriqLsTokenSpaceGuid.PcdSerdesLanes > diff --git a/Silicon/NXP/Include/Library/SerDesHelperLib.h b/Silicon/NXP/Include/Library/SerDesHelperLib.h > new file mode 100644 > index 000000000000..ef08c3edc30a > --- /dev/null > +++ b/Silicon/NXP/Include/Library/SerDesHelperLib.h > @@ -0,0 +1,64 @@ > +/** SerDesHelperLib.h > + The Header file for SerdesHelperLib > + > + Copyright 2020 NXP > + > + SPDX-License-Identifier: BSD-2-Clause-Patent > +**/ > + > +#ifndef SERDES_HELPER_LIB_H > +#define SERDES_HELPER_LIB_H > + > +#include > +#include > + > +typedef struct { > + UINT16 Protocol; > + UINT8 SrdsLane[FixedPcdGet8 (PcdSerdesLanes)]; Please write out Serdes fully. Also, please use consistent capitalisation (including file names) - this patch has a mix of Serdes and SerDes. > +} SERDES_CONFIG; > + > +typedef enum { > + SRDS_1 = 0, SERDES > + SRDS_2, > + SRDS_3, > + SRDS_MAX_NUM > +} SERDES_NUMBER; > + > +UINT32 > +GetSerDesPrtcl ( > + IN INTN SerDes, > + IN INTN Cfg, > + IN INTN Lane, > + IN UINT32 SerdesMaxProtocol, > + IN SERDES_CONFIG *Config > + ); > + > +EFI_STATUS > +CheckSerDesPrtclValid ( Protocol (search/replace globally) > + IN INTN SerDes, > + IN UINT32 Prtcl, > + IN UINT8 SerdesLanes, > + IN SERDES_CONFIG *Config > + ); > + > +EFI_STATUS > +GetSerDesMap ( > + IN UINT32 Srds, > + IN UINT32 SrdsProt, > + IN UINT8 SerdesLanes, > + IN UINT32 SerdesMaxProtocol, > + IN SERDES_CONFIG *Config, > + OUT UINT64 *SerDesPrtclMap > + ); > + > +VOID > +SerDesInstanceProbeLanes ( > + IN UINT32 Srds, > + IN UINT32 SrdsProt, > + IN UINT8 SerdesLanes, > + IN UINT32 SerdesMaxProtocol, > + IN SERDES_CONFIG *Config, > + IN SERDES_PROBE_LANES_CALLBACK SerDesLaneProbeCallback, > + IN VOID *Arg > + ); > +#endif > diff --git a/Silicon/NXP/Library/SerDesHelperLib/SerDesHelperLib.c b/Silicon/NXP/Library/SerDesHelperLib/SerDesHelperLib.c > new file mode 100644 > index 000000000000..54d0a6181707 > --- /dev/null > +++ b/Silicon/NXP/Library/SerDesHelperLib/SerDesHelperLib.c > @@ -0,0 +1,165 @@ > +/** SerDes.c > + Provides SoC specific serdes interface > + > + Copyright 2020 NXP > + > + SPDX-License-Identifier: BSD-2-Clause-Patent > +**/ > + > +#include > +#include > + > +/** > + Function to get serdes Lane protocol corresponding to > + serdes protocol. > + > + @param SerDes Serdes number. > + @param Cfg Serdes Protocol. > + @param Lane Serdes Lane number. > + @param SerdesMaxProtocol Max Serdes protocol number. > + @param Config Serdes Configuration. > + > + @return Serdes Lane protocol. > + > +**/ > +UINT32 > +GetSerDesPrtcl ( > + IN INTN SerDes, > + IN INTN Cfg, > + IN INTN Lane, > + IN UINT32 SerdesMaxProtocol, > + IN SERDES_CONFIG *Config This function has one input called Cfg and one called Config. Cfg is an abbreviation that should be avoided, and when expanded it becomes Config. Please rename the variables in a way that describes what they contain. > + ) > +{ > + while (Config->Protocol) { > + if (Config->Protocol == Cfg) { > + return Config->SrdsLane[Lane]; > + } > + Config++; > + } > + > + return SerdesMaxProtocol; > +} > + > +/** > + Function to validate input serdes protocol. > + > + @param SerDes Serdes number. > + @param Prtcl Serdes Protocol to be verified. > + @param SerdesLanes Number of Serdes Lanes > + @param Config Serdes Configuration. > + > + @return EFI_NOT_FOUND Serdes Protocol not a valid protocol. > + @return EFI_SUCCESS Serdes Protocol is a valid protocol. > + > +**/ > +EFI_STATUS > +CheckSerDesPrtclValid ( > + IN INTN SerDes, > + IN UINT32 Prtcl, > + IN UINT8 SerdesLanes, > + IN SERDES_CONFIG *Config > + ) > +{ > + UINT8 Cnt; Count > + > + while (Config->Protocol) { > + if (Config->Protocol == Prtcl) { > + DEBUG ((DEBUG_INFO, "Protocol: %x Matched with the one in Table\n", Prtcl)); > + break; > + } > + Config++; > + } > + > + if (!Config->Protocol) { > + return EFI_NOT_FOUND; > + } > + > + for (Cnt = 0; Cnt < SerdesLanes; Cnt++) { > + if (Config->SrdsLane[Cnt] != 0) { > + return EFI_SUCCESS; > + } > + } > + > + return EFI_NOT_FOUND; > +} > + > +/** > + Get lane protocol on provided serdes lane and execute callback function. > + > + @param Srds Serdes number. > + @param SrdsProt Serdes protocol number. > + @param SerdesLanes Number of Serdes Lanes > + @param SerdesMaxProtocol Max Serdes protocol number. > + @param Config Serdes Configuration. > + @param SerDesLaneProbeCallback Pointer Callback function to be called for Lane protocol > + @param Arg Pointer to Arguments to be passed to callback function. > + > +**/ > +VOID > +SerDesInstanceProbeLanes ( > + IN UINT32 Srds, > + IN UINT32 SrdsProt, > + IN UINT8 SerdesLanes, > + IN UINT32 SerdesMaxProtocol, > + IN SERDES_CONFIG *Config, > + IN SERDES_PROBE_LANES_CALLBACK SerDesLaneProbeCallback, > + IN VOID *Arg > + ) > +{ > + INT8 Lane; > + UINT32 LanePrtcl; > + > + // Invoke callback for all lanes in the SerDes instance: > + for (Lane = 0; Lane < SerdesLanes; Lane++) { > + LanePrtcl = GetSerDesPrtcl (Srds, SrdsProt, Lane, SerdesMaxProtocol, Config); > + ASSERT (LanePrtcl < SerdesMaxProtocol); > + if (LanePrtcl != 0x0) { > + SerDesLaneProbeCallback (LanePrtcl, Arg); > + } > + } > +} > + > +/** > + Function to fill serdes map information. > + > + @param Srds Serdes number. > + @param SrdsProt Serdes protocol number. > + @param SerdesLanes Number of Serdes Lanes. > + @param SerdesMaxProtocol Max Serdes protocol number. > + @param Config Serdes Configuration. > + @param SerDesPrtclMap Output Serdes protocol map of enabled devices. > + > +**/ > +EFI_STATUS > +GetSerDesMap ( > + IN UINT32 Srds, > + IN UINT32 SrdsProt, > + IN UINT8 SerdesLanes, > + IN UINT32 SerdesMaxProtocol, > + IN SERDES_CONFIG *Config, > + OUT UINT64 *SerDesPrtclMap > + ) > +{ > + INTN Lane; > + EFI_STATUS Status; > + UINT32 LanePrtcl; > + > + Status = CheckSerDesPrtclValid (Srds, SrdsProt, SerdesLanes, Config); > + if (EFI_ERROR (Status)) { > + DEBUG ((DEBUG_ERROR, "%a: SERDES%d[PRTCL] = 0x%x is not valid, Status = %r \n", > + __FUNCTION__, Srds + 1, SrdsProt, Status)); > + return Status; > + } > + > + for (Lane = 0; Lane < SerdesLanes; Lane++) { > + LanePrtcl = GetSerDesPrtcl (Srds, SrdsProt, Lane, SerdesMaxProtocol, Config); > + if (LanePrtcl >= SerdesMaxProtocol) { > + DEBUG ((DEBUG_ERROR, "Unknown SerDes lane protocol %d\n", LanePrtcl)); > + return EFI_NO_MAPPING; > + } > + *SerDesPrtclMap |= (0x1u << (LanePrtcl)); BIT0, or just 1. / Leif > + } > + > + return EFI_SUCCESS; > +} > -- > 2.7.4 >