From mboxrd@z Thu Jan  1 00:00:00 1970
Received: from EUR03-VE1-obe.outbound.protection.outlook.com (EUR03-VE1-obe.outbound.protection.outlook.com [])
 by mx.groups.io with SMTP id smtpd.web12.7254.1591535768843178203
 for <devel@edk2.groups.io>;
 Sun, 07 Jun 2020 06:16:11 -0700
Authentication-Results: mx.groups.io;
 dkim=fail reason="body hash did not verify" header.i=@nxp1.onmicrosoft.com header.s=selector2-nxp1-onmicrosoft-com header.b=P+jwYtp/;
 spf=fail (domain: oss.nxp.com, ip: <nil>, mailfrom: wasim.khan@oss.nxp.com)
ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none;
 b=H+jFPSmh/qYEhR+lxR8tWofhVILndXKnoeaM+x5hpoYxN0HdXH7F9K/FnQtmDW6ieGtWtp7MdC3Y4NASpJ3aQHQpwHjj1YcoSbn4n17pJUni5qxZL/EoK03h+t6hCbwnl6qt5kvJmkO64WL32kPTqpXMUgzQWxF9fmbPmfOXrO2WAw8stT0iZ/VsduXXPR4NGu09QeXBKmWznlgQgJzjjwxzeTAfInrPmvb4G5QAUEJrVVvGDd2boxQG1EWqkBhaJHM6GsKr96Vg2uO88adm/xSXqwYJbS97fkUl5SaTd1s3OiR7oaFXu14deRc+c7lBgni5ZvG1tOKeGuOwnAKm9Q==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com;
 s=arcselector9901;
 h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck;
 bh=9YhpOcNMbAUCfgejqxE3PmA0I5X/F7ZMRiVCepcjc8w=;
 b=WCb+vfgyTVioXHHsXIO8qJPoB6cr7wtf+SeH+pwUzYtfNfdXPBvnhPtuvz0h/fyAIuiDTCPoXQ1iQN3q0JjEytgNUSKJGyFeCUndl1mebzu+KjugC+Wsr0UIH/HSFz6Yb3FlAlWWOyvn6o8Cg0n+SSHGCJN7ZF/+dikudVHZFWbpA0WyoNIUmA7gUOxGwOpiZqxzSll2N3UDI7gdEbCs81MKM/wX3SF+fDZDiWtQYC8b6TZ2prbT6IxN/boI1hMKDTxn8gwgEyqwlWdGmgz1j61+eUBqj5/ppUrHfsJPrtKD3zbloM5+sPsHXEGq4Vw/oTGZ1fAMUERARbxAE0JpIg==
ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass
 smtp.mailfrom=oss.nxp.com; dmarc=pass action=none header.from=oss.nxp.com;
 dkim=pass header.d=oss.nxp.com; arc=none
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=NXP1.onmicrosoft.com;
 s=selector2-NXP1-onmicrosoft-com;
 h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck;
 bh=9YhpOcNMbAUCfgejqxE3PmA0I5X/F7ZMRiVCepcjc8w=;
 b=P+jwYtp/iEYM0gj+kJ2CpcJ3k5LSpF5dGHwmduvdN3+UXJ+krwARJ4BG/ZQqQknqDy0mxpWRUBLyTsrjJrb4wyJK7H5THfno6hYtbCe3sRIb8Dd37lJjLs5V/W+5OUeh7GLvXW6k/eiW8XeoFnWMHJjzv4bzve9ilbqjvR4SrhU=
Authentication-Results: edk2.groups.io; dkim=none (message not signed)
 header.d=none;edk2.groups.io; dmarc=none action=none header.from=oss.nxp.com;
Received: from VE1PR04MB6702.eurprd04.prod.outlook.com (2603:10a6:803:123::13)
 by VE1PR04MB6493.eurprd04.prod.outlook.com (2603:10a6:803:11f::11) with
 Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3066.20; Sun, 7 Jun
 2020 13:16:09 +0000
Received: from VE1PR04MB6702.eurprd04.prod.outlook.com
 ([fe80::81c4:97a6:7592:f225]) by VE1PR04MB6702.eurprd04.prod.outlook.com
 ([fe80::81c4:97a6:7592:f225%7]) with mapi id 15.20.3066.023; Sun, 7 Jun 2020
 13:16:09 +0000
From: Wasim Khan <wasim.khan@oss.nxp.com>
To: devel@edk2.groups.io,
	meenakshi.aggarwal@nxp.com,
	V.Sethi@nxp.com,
	ard.biesheuvel@arm.com,
	leif@nuviainc.com
CC: Wasim Khan <wasim.khan@nxp.com>
Subject: [PATCH edk2-platforms v2 2/3] Silicon/NXP: LS1043A: Add SerDes Support
Date: Sun,  7 Jun 2020 18:45:49 +0530
Message-ID: <1591535750-15743-3-git-send-email-wasim.khan@oss.nxp.com>
X-Mailer: git-send-email 2.7.4
In-Reply-To: <1591535750-15743-1-git-send-email-wasim.khan@oss.nxp.com>
References: <1591535750-15743-1-git-send-email-wasim.khan@oss.nxp.com>
X-ClientProxiedBy: BM1PR01CA0153.INDPRD01.PROD.OUTLOOK.COM
 (2603:1096:b00:68::23) To VE1PR04MB6702.eurprd04.prod.outlook.com
 (2603:10a6:803:123::13)
Return-Path: wasim.khan@oss.nxp.com
MIME-Version: 1.0
X-MS-Exchange-MessageSentRepresentingType: 1
Received: from wasimk-VirtualBox.nxp.com (157.47.233.236) by BM1PR01CA0153.INDPRD01.PROD.OUTLOOK.COM (2603:1096:b00:68::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.20.3066.18 via Frontend Transport; Sun, 7 Jun 2020 13:16:07 +0000
X-Mailer: git-send-email 2.7.4
X-Originating-IP: [157.47.233.236]
X-MS-PublicTrafficType: Email
X-MS-Office365-Filtering-HT: Tenant
X-MS-Office365-Filtering-Correlation-Id: 99ab1adf-0239-445d-3b60-08d80ae4f170
X-MS-TrafficTypeDiagnostic: VE1PR04MB6493:
X-MS-Exchange-SharedMailbox-RoutingAgent-Processed: True
X-MS-Exchange-Transport-Forked: True
X-Microsoft-Antispam-PRVS: 
	<VE1PR04MB649306CFF9025436CA808ECCD1840@VE1PR04MB6493.eurprd04.prod.outlook.com>
X-MS-Oob-TLC-OOBClassifiers: OLM:6790;
X-Forefront-PRVS: 04270EF89C
X-MS-Exchange-SenderADCheck: 1
X-Microsoft-Antispam: BCL:0;
X-Microsoft-Antispam-Message-Info: 
	uSBmbeMpR56a4MafzSTSGJNW81bzfBVqfrpBsrTQrjkaNYOoarKWtmTFkaqf60X1mJLQ0Pp8Ot0/dJ4hpNkImW6XGmCpeo/5ubMLr2unhw2AxDgLI9n5f23SI4wXM5BVc0K0pk286I6Oh/SqWjPOahqKLWaR7sL2/AKWXNFEi/LJIsGqiaKTTON6bF1VHdG0HNiIUO7LJTLagjFB/TgC8VHiSjGdfmj4a7a9cQidDZ7zDq8QCWB+hL9lnt9eApQxkR+rkpIlgtBDBdfuQSqGDrUvEDsC0E7SgKaaiNwbtPaD9ASfPaO3JWKUZgn4Z+XX7eQzAxNsGCZpi3gdWNvxeA==
X-Forefront-Antispam-Report: 
	CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VE1PR04MB6702.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:(4636009)(346002)(39860400002)(366004)(136003)(396003)(376002)(186003)(26005)(16526019)(86362001)(478600001)(83380400001)(4326008)(8936002)(8676002)(5660300002)(44832011)(6486002)(66946007)(6666004)(66556008)(6512007)(316002)(19627235002)(6506007)(2906002)(52116002)(2616005)(956004)(66476007);DIR:OUT;SFP:1101;
X-MS-Exchange-AntiSpam-MessageData: 
	oYqWTmXAuLgwMeq3D/Y62MxA+NSWHaV6+1nk5MCmhZ02q6w9im7eKeCSv/A6WbKf6hs6xZPABpFKtpr12bkWz5iRzVdwyz7JYGfAutmJ2s0t8e/5p2JV6GMqmam5j+6X1L39bg+wNhDKdjWATPJ/4tDgcqyh/5tEumZCZiz9P2qa9CnvhFxbWNm01wVvk400r0R239B0iMROQcMl63FthOfW7AIVBtS89lQ/2tW7EOOivjL6hrukTzDcX5yedmNFNWIE/JYt166LdEhOUw7pjrmo5ysV+cg6XAgmg96uhCrHv8lBdS2r0FP3fD3im8/fszt1GrPSNDG85Wsmwbx7Q7U9f4lGc9w7d4PQgf7LpR5AKKHz9n30RrxQpxtTsuBALqnnLFWK2+H6jS3TqQjCgkwAdd0gSeHWmZ3tGt1uZnQk4GmDxIvqE32bOY+BMIJSW2ul0DeZ/KtTXOgRu7JiKCfOr6wxvxuitjDn1arUb1fBvKe1ljwo/nkaQO9U9O+s
X-OriginatorOrg: oss.nxp.com
X-MS-Exchange-CrossTenant-Network-Message-Id: 99ab1adf-0239-445d-3b60-08d80ae4f170
X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Jun 2020 13:16:09.4169
 (UTC)
X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted
X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635
X-MS-Exchange-CrossTenant-MailboxType: HOSTED
X-MS-Exchange-CrossTenant-UserPrincipalName: 1VKcBzGzUvSUpfecGycjO9mcuybUPg0akNT845fPD7N7HYrJ52Ym3PP+zC6+q+EmRyQ21Lg7kkP2DF3EckMhyw==
X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1PR04MB6493
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain

From: Wasim Khan <wasim.khan@nxp.com>

Based on SerDes protocol value in reset configuration word (RCW)
different IP blocks gets enabled in HW.
Add SoC specific SerDes configuration for LS1043A, which can be
used by different IPs to know the enabled interfaces and perform
the required initialization.

Signed-off-by: Wasim Khan <wasim.khan@nxp.com>
---

Notes:
    Changes in V2:
    - Addressed review comments for structure, variable and function names
    - Removed SocSerDes.h and moved data definitions to SerDes.c

 Silicon/NXP/LS1043A/LS1043A.dsc.inc           |   2 +
 Silicon/NXP/LS1043A/Library/SocLib/SocLib.inf |   6 +
 Silicon/NXP/Include/Library/SerDes.h          |  28 +++++
 Silicon/NXP/LS1043A/Library/SocLib/SerDes.c   | 132 ++++++++++++++++++++
 4 files changed, 168 insertions(+)

diff --git a/Silicon/NXP/LS1043A/LS1043A.dsc.inc b/Silicon/NXP/LS1043A/LS10=
43A.dsc.inc
index e023bfbc7c04..1ac7c6da7092 100644
--- a/Silicon/NXP/LS1043A/LS1043A.dsc.inc
+++ b/Silicon/NXP/LS1043A/LS1043A.dsc.inc
@@ -12,6 +12,7 @@
 [LibraryClasses.common]
   SocLib|Silicon/NXP/LS1043A/Library/SocLib/SocLib.inf
   SerialPortLib|Silicon/NXP/Library/DUartPortLib/DUartPortLib.inf
+  SerDesHelperLib|Silicon/NXP/Library/SerDesHelperLib/SerDesHelperLib.inf
=20
 ##########################################################################=
######
 #
@@ -37,4 +38,5 @@ [PcdsFixedAtBuild.common]
   gNxpQoriqLsTokenSpaceGuid.PcdNumPciController|3
   gNxpQoriqLsTokenSpaceGuid.PcdPcieLutBase|0x10000
   gNxpQoriqLsTokenSpaceGuid.PcdPcieLutDbg|0x7FC
+  gNxpQoriqLsTokenSpaceGuid.PcdSerDesLanes|0x4
 ##
diff --git a/Silicon/NXP/LS1043A/Library/SocLib/SocLib.inf b/Silicon/NXP/LS=
1043A/Library/SocLib/SocLib.inf
index 3d0f988e1c67..728e8f0c8ee1 100644
--- a/Silicon/NXP/LS1043A/Library/SocLib/SocLib.inf
+++ b/Silicon/NXP/LS1043A/Library/SocLib/SocLib.inf
@@ -22,6 +22,12 @@ [Packages]
 [LibraryClasses]
   ChassisLib
   DebugLib
+  PcdLib
+  SerDesHelperLib
=20
 [Sources.common]
+  SerDes.c
   SocLib.c
+
+[FixedPcd]
+  gNxpQoriqLsTokenSpaceGuid.PcdSerDesLanes
diff --git a/Silicon/NXP/Include/Library/SerDes.h b/Silicon/NXP/Include/Lib=
rary/SerDes.h
new file mode 100644
index 000000000000..f015b40403c5
--- /dev/null
+++ b/Silicon/NXP/Include/Library/SerDes.h
@@ -0,0 +1,28 @@
+/** SerDes.h
+  Header file for SoC specific SerDes routines
+
+  Copyright 2017-2020 NXP
+
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#ifndef SERDES_H
+#define SERDES_H
+
+VOID
+GetSerDesProtocolMap (
+  OUT UINT64               *SerDesProtocolMap
+  );
+
+typedef VOID
+(*SERDES_PROBE_LANES_CALLBACK) (
+  IN UINT32 LaneProtocol,
+  IN VOID *Arg
+  );
+
+VOID
+SerDesProbeLanes (
+  IN SERDES_PROBE_LANES_CALLBACK SerDesLaneProbeCallback,
+  IN VOID                        *Arg
+  );
+#endif
diff --git a/Silicon/NXP/LS1043A/Library/SocLib/SerDes.c b/Silicon/NXP/LS10=
43A/Library/SocLib/SerDes.c
new file mode 100644
index 000000000000..90fa7146faa7
--- /dev/null
+++ b/Silicon/NXP/LS1043A/Library/SocLib/SerDes.c
@@ -0,0 +1,132 @@
+/** SerDes.c
+  Provides SoC specific SerDes interface
+
+  Copyright 2017-2020 NXP
+
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#include <Library/ChassisLib.h>
+#include <Library/DebugLib.h>
+#include <Library/SerDesHelperLib.h>
+#include <Soc.h>
+#include <Uefi.h>
+
+// SerDes1 Protocol Mask in Reset Configuration Word (RCW) Status Register
+#define SERDES1_PROTOCOL_MASK      0xffff0000
+
+// SerDes1 Protocol Shift in Reset Configuration Word (RCW) Status Registe=
r
+#define SERDES1_PROTOCOL_SHIFT     16
+
+typedef enum {
+  NONE =3D 0,
+  PCIE1,
+  PCIE2,
+  PCIE3,
+  SATA,
+  SGMII_FM1_DTSEC1,
+  SGMII_FM1_DTSEC2,
+  SGMII_FM1_DTSEC5,
+  SGMII_FM1_DTSEC6,
+  SGMII_FM1_DTSEC9,
+  SGMII_FM1_DTSEC10,
+  QSGMII_FM1_A,
+  XFI_FM1_MAC9,
+  XFI_FM1_MAC10,
+  SGMII_2500_FM1_DTSEC2,
+  SGMII_2500_FM1_DTSEC5,
+  SGMII_2500_FM1_DTSEC9,
+  SGMII_2500_FM1_DTSEC10,
+  SERDES_PROTOCOL_COUNT
+} SERDES_PROTOCOL;
+
+SERDES_CONFIG gSerDes1ConfigTable[] =3D {
+  {0x1555, {XFI_FM1_MAC9, PCIE1, PCIE2, PCIE3 } },
+  {0x2555, {SGMII_2500_FM1_DTSEC9, PCIE1, PCIE2, PCIE3 } },
+  {0x4555, {QSGMII_FM1_A, PCIE1, PCIE2, PCIE3 } },
+  {0x4558, {QSGMII_FM1_A,  PCIE1, PCIE2, SATA } },
+  {0x1355, {XFI_FM1_MAC9, SGMII_FM1_DTSEC2, PCIE2, PCIE3 } },
+  {0x2355, {SGMII_2500_FM1_DTSEC9, SGMII_FM1_DTSEC2, PCIE2, PCIE3 } },
+  {0x3335, {SGMII_FM1_DTSEC9, SGMII_FM1_DTSEC2, SGMII_FM1_DTSEC5, PCIE3 } =
},
+  {0x3355, {SGMII_FM1_DTSEC9, SGMII_FM1_DTSEC2, PCIE2, PCIE3 } },
+  {0x3358, {SGMII_FM1_DTSEC9, SGMII_FM1_DTSEC2, PCIE2, SATA } },
+  {0x3555, {SGMII_FM1_DTSEC9, PCIE1, PCIE2, PCIE3 } },
+  {0x3558, {SGMII_FM1_DTSEC9, PCIE1, PCIE2, SATA } },
+  {0x7000, {PCIE1, PCIE1, PCIE1, PCIE1 } },
+  {0x9998, {PCIE1, PCIE2, PCIE3, SATA } },
+  {0x6058, {PCIE1, PCIE1, PCIE2, SATA } },
+  {0x1455, {XFI_FM1_MAC9, QSGMII_FM1_A, PCIE2, PCIE3 } },
+  {0x2455, {SGMII_2500_FM1_DTSEC9, QSGMII_FM1_A, PCIE2, PCIE3 } },
+  {0x2255, {SGMII_2500_FM1_DTSEC9, SGMII_2500_FM1_DTSEC2, PCIE2, PCIE3 } }=
,
+  {0x3333, {SGMII_FM1_DTSEC9, SGMII_FM1_DTSEC2, SGMII_FM1_DTSEC5, SGMII_FM=
1_DTSEC6 } },
+  {0x1460, {XFI_FM1_MAC9, QSGMII_FM1_A, PCIE3, PCIE3 } },
+  {0x2460, {SGMII_2500_FM1_DTSEC9, QSGMII_FM1_A, PCIE3, PCIE3 } },
+  {0x3460, {SGMII_FM1_DTSEC9, QSGMII_FM1_A, PCIE3, PCIE3 } },
+  {0x3455, {SGMII_FM1_DTSEC9, QSGMII_FM1_A, PCIE2, PCIE3 } },
+  {0x9960, {PCIE1, PCIE2, PCIE3, PCIE3 } },
+  {0x2233, {SGMII_2500_FM1_DTSEC9, SGMII_FM1_DTSEC2, SGMII_FM1_DTSEC5, SGM=
II_FM1_DTSEC6 } },
+  {0x2533, {SGMII_2500_FM1_DTSEC9, PCIE1, SGMII_FM1_DTSEC5, SGMII_FM1_DTSE=
C6 } },
+  {}
+};
+
+SERDES_CONFIG *gSerDesConfig[] =3D {
+  gSerDes1ConfigTable
+};
+
+/**
+  Probe all SerDes for lane protocol and execute provided callback functio=
n.
+
+  @param  SerDesLaneProbeCallback Pointer Callback function to be called f=
or Lane protocol
+  @param  Arg                     Pointer to Arguments to be passed to cal=
lback function.
+
+**/
+VOID
+SerDesProbeLanes (
+  IN SERDES_PROBE_LANES_CALLBACK SerDesLaneProbeCallback,
+  IN VOID                        *Arg
+  )
+{
+  UINT32                 SerDesProtocol;
+  LS1043A_DEVICE_CONFIG  *DeviceConfig;
+
+  DeviceConfig =3D (LS1043A_DEVICE_CONFIG  *)LS1043A_DCFG_ADDRESS;
+  SerDesProtocol =3D DcfgRead32 ((UINTN)&DeviceConfig->RcwSr[4]) & SERDES1=
_PROTOCOL_MASK;
+  SerDesProtocol >>=3D SERDES1_PROTOCOL_SHIFT;
+
+  SerDesInstanceProbeLanes (SERDES_1, SerDesProtocol,
+                                    FixedPcdGet8 (PcdSerDesLanes),
+                                    SERDES_PROTOCOL_COUNT,
+                                    gSerDesConfig[SERDES_1],
+                                    SerDesLaneProbeCallback,
+                                    Arg);
+}
+
+/**
+  Function to return SerDes protocol map for all SerDes available on board=
.
+
+  @param  SerDesProtocolMap   Pointer to SerDes protocl map.
+
+**/
+VOID
+GetSerDesProtocolMap (
+  OUT UINT64   *SerDesProtocolMap
+  )
+{
+  UINT32                 SerDesProtocol;
+  LS1043A_DEVICE_CONFIG  *DeviceConfig;
+  EFI_STATUS             Status;
+
+  *SerDesProtocolMap =3D 0;
+  DeviceConfig =3D (LS1043A_DEVICE_CONFIG  *)LS1043A_DCFG_ADDRESS;
+  SerDesProtocol =3D DcfgRead32 ((UINTN)&DeviceConfig->RcwSr[4]) & SERDES1=
_PROTOCOL_MASK;
+  SerDesProtocol >>=3D SERDES1_PROTOCOL_SHIFT;
+
+  Status =3D GetSerDesMap (SERDES_1, SerDesProtocol, FixedPcdGet8 (PcdSerD=
esLanes),
+                          SERDES_PROTOCOL_COUNT, gSerDesConfig[SERDES_1],
+                          SerDesProtocolMap);
+
+  if (Status !=3D EFI_SUCCESS) {
+    DEBUG ((DEBUG_ERROR, "%a: failed for SerDes1 \n",__FUNCTION__));
+    *SerDesProtocolMap =3D 0;
+  }
+}
--=20
2.7.4