From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id B098041FDE for ; Thu, 31 Aug 2023 14:32:43 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id AFC0840297; Thu, 31 Aug 2023 14:32:43 +0200 (CEST) Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam04on2049.outbound.protection.outlook.com [40.107.100.49]) by mails.dpdk.org (Postfix) with ESMTP id F035640279; Thu, 31 Aug 2023 14:32:40 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Dp5q84VVD22908BR2inEK5plQU9xThMAdJUR5S70ZXhvVCa/mqShhH4I+4vCitnzACi2gmCuKUXcTRIAqvIENQZiQp6pdByO0nKZG0+PHs7mCjWy53XvMSE/cgt8XK8IiZkW8OfZdSHxJAxBUnrW+D3IT+PnD2/LZW0s2aXSqiTps7uzwqSw2tkDCCkSYdyWRkR8PPNDCnxyP4nyWIKAEZvEybrRRc0btbs/M7YA4ATsX1AUSmUyD/bMee+k6A2gqsTAgUWsA4Nbe6c1Hslfsa+AlVAbEl8L0AM1PeZN0Itzcg8OsOG6X1rSto3K6vWNK0kUl+EYBXx8m/SnwIQgHA== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=njha9s4++/QeUlQM1nckC7IDlukwubOma4Voia0PstU=; b=MeuqUQJZwk44+BqKGxtH2vPR/MnlPDnJ+Q59obHf4nSzrNCHRp+PTmDVHWYdiy0WHBO2q5vIYZ4vFd/HyNjnQq6JqkUxzZ2YO4xl/M33fOpy0pQrn3uYlKKgGXgeZjbPTmHDLt80BGdYIpf0s6vKh6Z7YQmoH9vXYUTLAP+lSWRJoR+GGAHKnFjVKN2F/kamyxa7idiY/enqbJ4ReA7+uAxdegW3jvjSu4uONir0iDMf2BMxRHxo3RZPhYXu2Kgp7jLoHp/ojRzB4PDazhj1NcEKQhRxIJJFRSKT6BYc2Ky59ZKeKuGi5NNjpQAzGlOD7C2qJOVfDsCX1lvP2kQ/Zg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=dpdk.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=njha9s4++/QeUlQM1nckC7IDlukwubOma4Voia0PstU=; b=r4+Ro7C2iPmdttyJ6sbzoR9gWDazsPPVIGlhW9JHtMIyNmKf3IAh0ozKazUnxciGyzWkZTuijcnCJD1vTJSEeBE7RSRksVMlK8vdEbQkjT2J7bVA3Bz2lEVurNf8G0vbvAdg/h2uUuL/pbXlzRNBL6FqkHIvZA/aNBh75nd6aJA= Received: from MW4PR04CA0151.namprd04.prod.outlook.com (2603:10b6:303:85::6) by DS7PR12MB8274.namprd12.prod.outlook.com (2603:10b6:8:da::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.20; Thu, 31 Aug 2023 12:32:10 +0000 Received: from CO1PEPF000044F7.namprd21.prod.outlook.com (2603:10b6:303:85:cafe::30) by MW4PR04CA0151.outlook.office365.com (2603:10b6:303:85::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.20 via Frontend Transport; Thu, 31 Aug 2023 12:32:10 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1PEPF000044F7.mail.protection.outlook.com (10.167.241.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6768.2 via Frontend Transport; Thu, 31 Aug 2023 12:32:09 +0000 Received: from cae-fox.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Thu, 31 Aug 2023 07:32:07 -0500 From: Selwin Sebastian To: CC: , Selwin Sebastian , Subject: [PATCH v1] net/axgbe: use CPUID to identify cpu Date: Thu, 31 Aug 2023 18:01:31 +0530 Message-ID: <20230831123131.4787-1-selwin.sebastian@amd.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1PEPF000044F7:EE_|DS7PR12MB8274:EE_ X-MS-Office365-Filtering-Correlation-Id: 69dad5b3-e5d4-41ab-e940-08dbaa1e4bd6 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: hxbmzjuFoUTb0fgB8MLe46jYbIPqu+tIlmlVPfwzHHsNuNGM8qp4KDKKdEi6BEqjsAOvOJrjbUA+PXW7mf0V3xnIqySYATeLkN8RTTwn7FHOl/wYIGdJFjQqzkbRpVh52xc85WplRsY2PlknvA8uE+pwN2ktPxjgczOajWq1a4x6M1Nj9dK6xNcyYdUH/4Kfkw0BOoKsLWOgUu+8UnMgwLsjC4cPK5b3qFpa0zwW85PLAQMjph7tKlPCZmhCR9SK/2R96vgETlnMFlRgqn9xHSxlBNDVIl2ZawM6IqJi21HdNqCfldhSPBDpP7/QT2Icg8IfrfueEnFuHxoLSDOZ9oJx82Mc54uwH0YErJRj1n2PDe4t7e62ZEhjl/ux3UQYTra/ay6ttI95TEcU3NM0TByaX6UPjDv6oT7tDdl9mePuVKhXWNz0b/mRkNdJ1EUzcuUPp5+exJ65iMXWjvM9f7AKpXhkLePnigndYVOXRJDSn9af6rLRduwx614oOJUIoacnViyCU+RvdPg1Jnm/ba5ybbFbkvXKaKeKBVSxO0tY9Gd1UlHeFBt44xA+YP44nOtZAZcDqW37iOqMOywO0zx8AnBhUtg00JaPggNLn1M0MTLJ93cBbGeV40qI0bH1djNS5UjETKhPWKcHXTBmcnwpQcQ2KELrvKROpCnen1cOIc4G0f5qWad4OGWLg+TxVVYMiCnrSWTLSLtkQ4YkFzocfC5PaXlszfawRXMFp4sNVvVaHOOb0HTD2lta+AgmY1HacMj+a6MXXVlIDZbwZQ== X-Forefront-Antispam-Report: CIP:165.204.84.17; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:SATLEXMB04.amd.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230031)(4636009)(39860400002)(346002)(136003)(376002)(396003)(186009)(1800799009)(451199024)(82310400011)(40470700004)(46966006)(36840700001)(40480700001)(83380400001)(40460700003)(81166007)(70206006)(6916009)(316002)(54906003)(70586007)(478600001)(356005)(82740400003)(2906002)(4326008)(5660300002)(450100002)(1076003)(8676002)(7696005)(8936002)(86362001)(44832011)(47076005)(16526019)(336012)(6666004)(26005)(36860700001)(2616005)(426003)(41300700001)(36756003)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Aug 2023 12:32:09.9767 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 69dad5b3-e5d4-41ab-e940-08dbaa1e4bd6 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1PEPF000044F7.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR12MB8274 X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org Using root complex to identify cpu will not work for vm passthrough. CPUID is used to get family and modelid to identify cpu Fixes: b0db927b5eba ("net/axgbe: use PCI root complex device to distinguish device") Cc: stable@dpdk.org Signed-off-by: Selwin Sebastian --- drivers/net/axgbe/axgbe_ethdev.c | 102 ++++++++++++++++++------------- 1 file changed, 59 insertions(+), 43 deletions(-) diff --git a/drivers/net/axgbe/axgbe_ethdev.c b/drivers/net/axgbe/axgbe_ethdev.c index 48714eebe6..59f5d713d0 100644 --- a/drivers/net/axgbe/axgbe_ethdev.c +++ b/drivers/net/axgbe/axgbe_ethdev.c @@ -12,6 +12,8 @@ #include "eal_filesystem.h" +#include + static int eth_axgbe_dev_init(struct rte_eth_dev *eth_dev); static int axgbe_dev_configure(struct rte_eth_dev *dev); static int axgbe_dev_start(struct rte_eth_dev *dev); @@ -172,9 +174,14 @@ static const struct axgbe_xstats axgbe_xstats_strings[] = { /* The set of PCI devices this driver supports */ #define AMD_PCI_VENDOR_ID 0x1022 -#define AMD_PCI_RV_ROOT_COMPLEX_ID 0x15d0 -#define AMD_PCI_YC_ROOT_COMPLEX_ID 0x14b5 -#define AMD_PCI_SNOWY_ROOT_COMPLEX_ID 0x1450 + +#define Fam17h 0x17 +#define Fam19h 0x19 + +#define CPUID_VENDOR_AuthenticAMD_ebx 0x68747541 +#define CPUID_VENDOR_AuthenticAMD_ecx 0x444d4163 +#define CPUID_VENDOR_AuthenticAMD_edx 0x69746e65 + #define AMD_PCI_AXGBE_DEVICE_V2A 0x1458 #define AMD_PCI_AXGBE_DEVICE_V2B 0x1459 @@ -2111,29 +2118,6 @@ static void axgbe_default_config(struct axgbe_port *pdata) pdata->power_down = 0; } -/* - * Return PCI root complex device id on success else 0 - */ -static uint16_t -get_pci_rc_devid(void) -{ - char pci_sysfs[PATH_MAX]; - const struct rte_pci_addr pci_rc_addr = {0, 0, 0, 0}; - unsigned long device_id; - - snprintf(pci_sysfs, sizeof(pci_sysfs), "%s/" PCI_PRI_FMT "/device", - rte_pci_get_sysfs_path(), pci_rc_addr.domain, - pci_rc_addr.bus, pci_rc_addr.devid, pci_rc_addr.function); - - /* get device id */ - if (eal_parse_sysfs_value(pci_sysfs, &device_id) < 0) { - PMD_INIT_LOG(ERR, "Error in reading PCI sysfs\n"); - return 0; - } - - return (uint16_t)device_id; -} - /* Used in dev_start by primary process and then * in dev_init by secondary process when attaching to an existing ethdev. */ @@ -2186,6 +2170,9 @@ eth_axgbe_dev_init(struct rte_eth_dev *eth_dev) uint32_t len; int ret; + unsigned int eax = 0, ebx = 0, ecx = 0, edx = 0; + unsigned char cpu_family = 0, cpu_model = 0; + eth_dev->dev_ops = &axgbe_eth_dev_ops; eth_dev->rx_descriptor_status = axgbe_dev_rx_descriptor_status; @@ -2230,26 +2217,55 @@ eth_axgbe_dev_init(struct rte_eth_dev *eth_dev) pdata->vdata = &axgbe_v2b; /* - * Use PCI root complex device ID to identify the CPU + * Use CPUID to get Family and model ID to identify the CPU */ - switch (get_pci_rc_devid()) { - case AMD_PCI_RV_ROOT_COMPLEX_ID: - pdata->xpcs_window_def_reg = PCS_V2_RV_WINDOW_DEF; - pdata->xpcs_window_sel_reg = PCS_V2_RV_WINDOW_SELECT; - break; - case AMD_PCI_YC_ROOT_COMPLEX_ID: - pdata->xpcs_window_def_reg = PCS_V2_YC_WINDOW_DEF; - pdata->xpcs_window_sel_reg = PCS_V2_YC_WINDOW_SELECT; - /* Yellow Carp devices do not need cdr workaround */ - pdata->vdata->an_cdr_workaround = 0; + __cpuid(0x0, eax, ebx, ecx, edx); + + if (ebx == CPUID_VENDOR_AuthenticAMD_ebx && + edx == CPUID_VENDOR_AuthenticAMD_edx && + ecx == CPUID_VENDOR_AuthenticAMD_ecx) { + int unknown_cpu = 0; + eax = 0, ebx = 0, ecx = 0, edx = 0; + + __cpuid(0x1, eax, ebx, ecx, edx); + + cpu_family = ((GET_BITS(eax, 8, 4)) + (GET_BITS(eax, 20, 8))); + cpu_model = ((GET_BITS(eax, 4, 4)) | (((GET_BITS(eax, 16, 4)) << 4) & 0xF0)); + + switch (cpu_family) { + case Fam17h: + /* V1000/R1000 */ + if (cpu_model >= 0x10 && cpu_model <= 0x1F) { + pdata->xpcs_window_def_reg = PCS_V2_RV_WINDOW_DEF; + pdata->xpcs_window_sel_reg = PCS_V2_RV_WINDOW_SELECT; + /* EPYC 3000 */ + } else if (cpu_model >= 0x01 && cpu_model <= 0x0F) { + pdata->xpcs_window_def_reg = PCS_V2_WINDOW_DEF; + pdata->xpcs_window_sel_reg = PCS_V2_WINDOW_SELECT; + } else { + unknown_cpu = 1; + } break; - case AMD_PCI_SNOWY_ROOT_COMPLEX_ID: - pdata->xpcs_window_def_reg = PCS_V2_WINDOW_DEF; - pdata->xpcs_window_sel_reg = PCS_V2_WINDOW_SELECT; + case Fam19h: + /* V3000 (Yellow Carp) */ + if (cpu_model >= 0x44 && cpu_model <= 0x47) { + pdata->xpcs_window_def_reg = PCS_V2_YC_WINDOW_DEF; + pdata->xpcs_window_sel_reg = PCS_V2_YC_WINDOW_SELECT; + + /* Yellow Carp devices do not need cdr workaround */ + pdata->vdata->an_cdr_workaround = 0; + } else { + unknown_cpu = 1; + } break; - default: - PMD_DRV_LOG(ERR, "No supported devices found\n"); - return -ENODEV; + default: + unknown_cpu = 1; + break; + } + if (unknown_cpu) { + PMD_DRV_LOG(ERR, "Unknown CPU family, no supported axgbe device found\n"); + return -ENODEV; + } } /* Configure the PCS indirect addressing support */ -- 2.34.1