From patchwork Thu Nov 16 13:54:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Raju Rangoju X-Patchwork-Id: 13457927 X-Patchwork-Delegate: kuba@kernel.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="NAEkW7U8" Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2068.outbound.protection.outlook.com [40.107.243.68]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CFF59A0 for ; Thu, 16 Nov 2023 05:55:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=T/XiKGQQjMImROH3gWQeLvLLeYxWztwBvxTM1TwaboumRs3KaWfDCVkniWw0adc0cil+F5LCVUoxGq5P413VzYz1mm0CSDOVrQbIJICWA5mh+Qi0qT4DQTsrGu2TCz2L1riQycdK68G5/tL/VjXO4qQJaQT/1I9znQeD/UKE+2YFEFuV33HfloqlaYwGvwmZLJWe1qGfn7qSmLFCKEcLqEpkCd0B8CQRAL/5PaPy1x3EHjvHcigtNm2rvsec34dhA4XWBXataT/s2Iudh4+dIYIXlRIF8YHHLxYa+0DY3UhR+WC0GE0yr7Myi2YbGleI+P36hiAMkwBYWtWt5pQFDw== 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=5DC9SX0PvfrZHW7Bktp4cX9Rg50QGsmhjoC2NYay1lQ=; b=ERd3Ns1xCgCaLPC5Vg+oDqjfOnG7M7NGqaSz9bbJIHiV19Cw3k4xY7jHENvXRDdGyVmfmuBajTMW4IrLZNybyg1YjX0ZmdS2/yobIQ8aOlnNCLCGCUqxIztyRBcMBd/tDyvAJ874IxS388el8Qru47wq9VbjtAMiXK+ypy0OyQiJrobnJMl/xgFOjiWUbcNr3gHCM3SdOaFHbELsJQJsJcRkWYSQe2oZ+4Z2u1lSm17hLqTGxtzo2MzbElLuQJHraAhqvGjsKt9d2oM4Tdg/MZUCwXgSYwSdQI1iAxFd7R8c5lo37rwr4EQv9gSfJwQ4wZUn2/A5N7+GUkjxKNVN1w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.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 (0) 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=5DC9SX0PvfrZHW7Bktp4cX9Rg50QGsmhjoC2NYay1lQ=; b=NAEkW7U8puPilT59Di4PYmND1P0q+qKfiaczzVSvi0qiwn3vGTbOk+YHxsu6v99seZu1a0th+2hwaY27rlWMFVs8FpHBxcNBEAhiGyI/dc92/V1lGDjE/AusRF/KKdxkgXBnZYUc2YTW+Lq62x+i/Nl+9WGSOhtN8AmsO1W/jxg= Received: from SJ0PR13CA0172.namprd13.prod.outlook.com (2603:10b6:a03:2c7::27) by BY5PR12MB4934.namprd12.prod.outlook.com (2603:10b6:a03:1db::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7002.21; Thu, 16 Nov 2023 13:55:28 +0000 Received: from CO1PEPF000042AA.namprd03.prod.outlook.com (2603:10b6:a03:2c7:cafe::a6) by SJ0PR13CA0172.outlook.office365.com (2603:10b6:a03:2c7::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7002.14 via Frontend Transport; Thu, 16 Nov 2023 13:55:28 +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 CO1PEPF000042AA.mail.protection.outlook.com (10.167.243.39) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7002.20 via Frontend Transport; Thu, 16 Nov 2023 13:55:28 +0000 Received: from jatayu.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.32; Thu, 16 Nov 2023 07:55:21 -0600 From: Raju Rangoju To: CC: , , , , , Raju Rangoju Subject: [PATCH v2 net-next 1/4] amd-xgbe: reorganize the code of XPCS access Date: Thu, 16 Nov 2023 19:24:13 +0530 Message-ID: <20231116135416.3371367-2-Raju.Rangoju@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231116135416.3371367-1-Raju.Rangoju@amd.com> References: <20231116135416.3371367-1-Raju.Rangoju@amd.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: CO1PEPF000042AA:EE_|BY5PR12MB4934:EE_ X-MS-Office365-Filtering-Correlation-Id: 0ed8fefd-4385-46cc-b9dd-08dbe6abb117 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 4ZgieTEwwtclPXiPH4qU3rUDQC1f9unTJ+xOCENRjoZsD6bQqLIODJ6ZvmpCekyvuOq0w/TwcN/oD/4FUcLI+OVtaovr88/3vuPlyWcLpyWD8+9XXsudszfHNmHTNohw/zjTtLKthm42L3asKpCrrxdfQXEAEIWBTAHyQTYTemx6cxhQyvmZZOZwRUnYStxWTIPyyT1MAK5gOtDh88msZufgZoDoDnbunsN8dB8U4EvxlroupXOFBibt0IFb9kju2J24ZOo+7Bnwma6Wqi5zm496ESUOrvLzsWfMFba/Gl11/IYG9t/QRHMUez61Kbk0UE/SGqz3tuDz6vn676/uYOBWe4/tgnjsOMxZ2fUnNSjXlG5rhrZY33Rs2AQlXhbkTnqkfmUcfYnu3zMvBRYXztJFgCVnvPX4LKdnBZ1II4D1odQyl0UKunZQEWsryVPfbEKE7KU9KzyFlMbfLlFiLkCtefOveItaihi2UQOOBz7ngRD7NmoIripfJMehh6hmqtV1yz4nTzemBqtChB2bmUazFSZbynt/n8nPHUlA/DJXZJMSGz7Ur5+KoKinaR51u7oORXD+W9rn6sGqsZo8K7zr1qXMkJCsDbTRtxxmETdKuDW3jjlew/RtN+/vChoZJSDJ5agoJFvBqQVZVZuNlS/TMOtbdeXdf9RjiJww3lbmU9JlX5WBdjn/GA5s5zTE/Kuw1Fer2aTvWJXHJNroG7Dm5JMSo9BOT1NcvboIHBYQa5VzEcTXdrSyAqa1U7DHWLFggEECHwfUnO/jruy7pw== 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)(396003)(376002)(39860400002)(136003)(346002)(230922051799003)(451199024)(1800799009)(82310400011)(186009)(64100799003)(40470700004)(46966006)(36840700001)(40460700003)(336012)(82740400003)(426003)(83380400001)(7696005)(26005)(16526019)(6666004)(2616005)(1076003)(316002)(6916009)(54906003)(4326008)(70206006)(8676002)(70586007)(36756003)(8936002)(36860700001)(40480700001)(2906002)(41300700001)(86362001)(5660300002)(81166007)(356005)(47076005)(478600001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Nov 2023 13:55:28.5162 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0ed8fefd-4385-46cc-b9dd-08dbe6abb117 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: CO1PEPF000042AA.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB4934 X-Patchwork-Delegate: kuba@kernel.org The xgbe_{read/write}_mmd_regs_v* functions have common code which can be moved to helper functions. Also, the xgbe_pci_probe() needs reorganization. Add new helper functions to calculate the mmd_address for v1/v2 of xpcs access. And, convert if/else statements in xgbe_pci_probe() to switch case. This helps code look cleaner. Signed-off-by: Raju Rangoju --- drivers/net/ethernet/amd/xgbe/xgbe-dev.c | 43 ++++++++++++------------ drivers/net/ethernet/amd/xgbe/xgbe-pci.c | 16 ++++++--- 2 files changed, 32 insertions(+), 27 deletions(-) diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-dev.c b/drivers/net/ethernet/amd/xgbe/xgbe-dev.c index f393228d41c7..6cd003c24a64 100644 --- a/drivers/net/ethernet/amd/xgbe/xgbe-dev.c +++ b/drivers/net/ethernet/amd/xgbe/xgbe-dev.c @@ -1150,6 +1150,21 @@ static int xgbe_set_gpio(struct xgbe_prv_data *pdata, unsigned int gpio) return 0; } +static unsigned int get_mmd_address(struct xgbe_prv_data *pdata, int mmd_reg) +{ + return (mmd_reg & XGBE_ADDR_C45) ? + mmd_reg & ~XGBE_ADDR_C45 : + (pdata->mdio_mmd << 16) | (mmd_reg & 0xffff); +} + +static unsigned int get_index_offset(struct xgbe_prv_data *pdata, unsigned int mmd_address, + unsigned int *index) +{ + mmd_address <<= 1; + *index = mmd_address & ~pdata->xpcs_window_mask; + return pdata->xpcs_window + (mmd_address & pdata->xpcs_window_mask); +} + static int xgbe_read_mmd_regs_v2(struct xgbe_prv_data *pdata, int prtad, int mmd_reg) { @@ -1157,10 +1172,7 @@ static int xgbe_read_mmd_regs_v2(struct xgbe_prv_data *pdata, int prtad, unsigned int mmd_address, index, offset; int mmd_data; - if (mmd_reg & XGBE_ADDR_C45) - mmd_address = mmd_reg & ~XGBE_ADDR_C45; - else - mmd_address = (pdata->mdio_mmd << 16) | (mmd_reg & 0xffff); + mmd_address = get_mmd_address(pdata, mmd_reg); /* The PCS registers are accessed using mmio. The underlying * management interface uses indirect addressing to access the MMD @@ -1171,9 +1183,7 @@ static int xgbe_read_mmd_regs_v2(struct xgbe_prv_data *pdata, int prtad, * register offsets must therefore be adjusted by left shifting the * offset 1 bit and reading 16 bits of data. */ - mmd_address <<= 1; - index = mmd_address & ~pdata->xpcs_window_mask; - offset = pdata->xpcs_window + (mmd_address & pdata->xpcs_window_mask); + offset = get_index_offset(pdata, mmd_address, &index); spin_lock_irqsave(&pdata->xpcs_lock, flags); XPCS32_IOWRITE(pdata, pdata->xpcs_window_sel_reg, index); @@ -1189,10 +1199,7 @@ static void xgbe_write_mmd_regs_v2(struct xgbe_prv_data *pdata, int prtad, unsigned long flags; unsigned int mmd_address, index, offset; - if (mmd_reg & XGBE_ADDR_C45) - mmd_address = mmd_reg & ~XGBE_ADDR_C45; - else - mmd_address = (pdata->mdio_mmd << 16) | (mmd_reg & 0xffff); + mmd_address = get_mmd_address(pdata, mmd_reg); /* The PCS registers are accessed using mmio. The underlying * management interface uses indirect addressing to access the MMD @@ -1203,9 +1210,7 @@ static void xgbe_write_mmd_regs_v2(struct xgbe_prv_data *pdata, int prtad, * register offsets must therefore be adjusted by left shifting the * offset 1 bit and writing 16 bits of data. */ - mmd_address <<= 1; - index = mmd_address & ~pdata->xpcs_window_mask; - offset = pdata->xpcs_window + (mmd_address & pdata->xpcs_window_mask); + offset = get_index_offset(pdata, mmd_address, &index); spin_lock_irqsave(&pdata->xpcs_lock, flags); XPCS32_IOWRITE(pdata, pdata->xpcs_window_sel_reg, index); @@ -1220,10 +1225,7 @@ static int xgbe_read_mmd_regs_v1(struct xgbe_prv_data *pdata, int prtad, unsigned int mmd_address; int mmd_data; - if (mmd_reg & XGBE_ADDR_C45) - mmd_address = mmd_reg & ~XGBE_ADDR_C45; - else - mmd_address = (pdata->mdio_mmd << 16) | (mmd_reg & 0xffff); + mmd_address = get_mmd_address(pdata, mmd_reg); /* The PCS registers are accessed using mmio. The underlying APB3 * management interface uses indirect addressing to access the MMD @@ -1248,10 +1250,7 @@ static void xgbe_write_mmd_regs_v1(struct xgbe_prv_data *pdata, int prtad, unsigned int mmd_address; unsigned long flags; - if (mmd_reg & XGBE_ADDR_C45) - mmd_address = mmd_reg & ~XGBE_ADDR_C45; - else - mmd_address = (pdata->mdio_mmd << 16) | (mmd_reg & 0xffff); + mmd_address = get_mmd_address(pdata, mmd_reg); /* The PCS registers are accessed using mmio. The underlying APB3 * management interface uses indirect addressing to access the MMD diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-pci.c b/drivers/net/ethernet/amd/xgbe/xgbe-pci.c index f409d7bd1f1e..d6071f34b7db 100644 --- a/drivers/net/ethernet/amd/xgbe/xgbe-pci.c +++ b/drivers/net/ethernet/amd/xgbe/xgbe-pci.c @@ -274,12 +274,16 @@ static int xgbe_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) /* Set the PCS indirect addressing definition registers */ rdev = pci_get_domain_bus_and_slot(0, 0, PCI_DEVFN(0, 0)); - if (rdev && - (rdev->vendor == PCI_VENDOR_ID_AMD) && (rdev->device == 0x15d0)) { + + if (!(rdev && rdev->vendor == PCI_VENDOR_ID_AMD)) + goto err_pci_enable; + + switch (rdev->device) { + case 0x15d0: pdata->xpcs_window_def_reg = PCS_V2_RV_WINDOW_DEF; pdata->xpcs_window_sel_reg = PCS_V2_RV_WINDOW_SELECT; - } else if (rdev && (rdev->vendor == PCI_VENDOR_ID_AMD) && - (rdev->device == 0x14b5)) { + break; + case 0x14b5: pdata->xpcs_window_def_reg = PCS_V2_YC_WINDOW_DEF; pdata->xpcs_window_sel_reg = PCS_V2_YC_WINDOW_SELECT; @@ -288,9 +292,11 @@ static int xgbe_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) /* Yellow Carp devices do not need rrc */ pdata->vdata->enable_rrc = 0; - } else { + break; + default: pdata->xpcs_window_def_reg = PCS_V2_WINDOW_DEF; pdata->xpcs_window_sel_reg = PCS_V2_WINDOW_SELECT; + break; } pci_dev_put(rdev); From patchwork Thu Nov 16 13:54:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Raju Rangoju X-Patchwork-Id: 13457928 X-Patchwork-Delegate: kuba@kernel.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="WMBKwser" Received: from NAM04-DM6-obe.outbound.protection.outlook.com (mail-dm6nam04on2048.outbound.protection.outlook.com [40.107.102.48]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 76DE4A9 for ; Thu, 16 Nov 2023 05:55:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Rp2ba3PlL+agVno0VjAfI/cikG/jDMMQv202IPRWH/p5hXJ9EwmENxqNDZ3v039i59r0FM9ZGuRejpKkDTjScYfJ9N1kfZoWp9z9pjSbkT4Feen12mH2jw0kzcLsr2WTH0jOyRXcKPlujQQZ6Shk0Hm0hnKvWBWrRfpt6iNJbIqCAw2qUaG9AMZuqtZPC0P/g9ZgFQM7pH8HzU50AoccsJgpeGoPv/7KDx+4COAA5FyvrH1DgTKgOJczKDzjjsRRrTLMkhu/cYJWb+NS3f4hEZ3xJI3+OgeI99ZvBsmEw93lQzZlw2GEcrDJgFIpCh2Yz1HA+4YlMCYjq78mUJCChA== 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=s7jrRgcd/HjIoI8WYLwz2gXw195xM6IxUxyClPMWOBY=; b=fgArs83RRDeq9jXZGcfixo5artgR3099bvLh2/lgqAPtJyr5VxnYNrRWhq0W0WqFR9CcQEnVu/hlw9a/7in8hnkrImFR9DDln1liuqr4T3LC5tcDVAWlzRvKaUpiwkoq+IC7jfYCmFPBxDi6YlgknxGhCWCRPeR/seSTakvH8S+OBsKNGuywtFKoWQdBwqXm9Xd+FNOvXq6s+ZV43uKXaGAnSPZltgyLcRYqvm4xTm/W2A/BKX3n+x7fhfdVCclQYpYqsEU2hNDmRw/IeWSdG9n5VAZzbpE0Df+XGt76cDblB5b6PZum1ZP2XZ73k4yEkPwGU+Y+e18lA74d/T2UwA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.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 (0) 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=s7jrRgcd/HjIoI8WYLwz2gXw195xM6IxUxyClPMWOBY=; b=WMBKwserjoTZZED0Lb/7doWTnbLELj9kAxEkIXYDPQUpsAVOgIG0lAE4lf27ZnIX0+zipakws2Hm1D1HTayma1g+bOGv/56ktLpwsCAw0xuqTT6trgLQXD0SxBviFbxPfg+9gewoYoJVW6Iu4Lel1+0GLF8ffMZdrkIN6bvK4Ac= Received: from MW4PR04CA0108.namprd04.prod.outlook.com (2603:10b6:303:83::23) by SA1PR12MB8096.namprd12.prod.outlook.com (2603:10b6:806:326::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7002.21; Thu, 16 Nov 2023 13:55:33 +0000 Received: from CO1PEPF000042AC.namprd03.prod.outlook.com (2603:10b6:303:83:cafe::95) by MW4PR04CA0108.outlook.office365.com (2603:10b6:303:83::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7002.21 via Frontend Transport; Thu, 16 Nov 2023 13:55:33 +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 CO1PEPF000042AC.mail.protection.outlook.com (10.167.243.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7002.20 via Frontend Transport; Thu, 16 Nov 2023 13:55:33 +0000 Received: from jatayu.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.32; Thu, 16 Nov 2023 07:55:29 -0600 From: Raju Rangoju To: CC: , , , , , Raju Rangoju , Sudheesh Mavila Subject: [PATCH v2 net-next 2/4] amd-xgbe: add support for Crater ethernet device Date: Thu, 16 Nov 2023 19:24:14 +0530 Message-ID: <20231116135416.3371367-3-Raju.Rangoju@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231116135416.3371367-1-Raju.Rangoju@amd.com> References: <20231116135416.3371367-1-Raju.Rangoju@amd.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: CO1PEPF000042AC:EE_|SA1PR12MB8096:EE_ X-MS-Office365-Filtering-Correlation-Id: 566906fd-1225-4e4f-6c7e-08dbe6abb3de X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Kf76Iowdtd/mTmTFJFdQ2wGmS50MlOMpJgAtOz8sQYTg1lX1xLGfnGomnNKiH3XuqCUlF0DpBLC8GnARK+yv6DHrjNQwkaPfTMonPwqmEpJCSjU4pMqKnCArV5eQC5KEcQiFFgbt5gvWpQg+5x0peZJhBW0NWWABeqhOwKMxhhvt7REIDZ1u9P9vMKpEchZpXME2pmCcvMjWGuOg1nT3D1zicvFTQgy+TgLIVTxBmbKuUMUdXaFNhb0z2TGcxAHiMIlFkcvayirD2sZQ+o9h1l1JwYMHpfdnQ/LnLHcPdaT6vyNvaplI1mBS0hVJD2z2pYv3ImJUdjSAkruugLYuhBz1rf4k8KVoXoTg5SkVtrSCa0O+m/J5tGqHsQHm11DIvqkY83a6ePm2ktZQTa7pQtaQRVA5h2C06YoSsuiVoacvLxoTX2nTrxz6DoI/UuWQ70dabKsQ0XtYPrUax0jz0OCk4zGyvgzZQhGaExTbL9n2fupuweCO5lABR70p7rirEtYEutcb0cYdqzje1Qd9rMOz4/3Tf9Y6GwirmwXuL3g0Fegov/P03O2iN8YVVn8b4+pGLKVg0heuOzocjCOTScoUCb54nbfDmJ8dTUQKZFAeo46nyVzZToQLqlyfzKDRX6bsg5c82yvVfN1Laa9N2/aELyVfRMAv1H3CHR/YmGT93xeaRUfj/NiMAb2kN9x9kFRRPEC5GSMNnqouQmeMRLI4guQcFvqbt/Rf+WZ9XjkR6iT3Cd90cBHVSSFt5owz7Utyi4e8T/yuX36/pGGqsA== 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)(136003)(396003)(346002)(376002)(230922051799003)(451199024)(82310400011)(1800799009)(186009)(64100799003)(46966006)(36840700001)(40470700004)(426003)(336012)(6666004)(83380400001)(2616005)(1076003)(40460700003)(7696005)(82740400003)(16526019)(26005)(6916009)(316002)(54906003)(70586007)(70206006)(86362001)(5660300002)(41300700001)(2906002)(8936002)(8676002)(4326008)(36756003)(356005)(81166007)(40480700001)(36860700001)(478600001)(47076005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Nov 2023 13:55:33.1270 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 566906fd-1225-4e4f-6c7e-08dbe6abb3de 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: CO1PEPF000042AC.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB8096 X-Patchwork-Delegate: kuba@kernel.org Add the necessary support to enable Crater ethernet device. Since the BAR1 address cannot be used to access the XPCS registers on Crater, use the pci_{read/write}_config_dword calls. Co-developed-by: Sudheesh Mavila Signed-off-by: Sudheesh Mavila Signed-off-by: Raju Rangoju --- Changes since v1: - New XGBE_XPCS_ACCESS_V3 type has been introduced along with the xgbe_{read/write}_mmd_regs_v3 functions to do the Crater device XPCS handling - Used FIELD_GET() and FIELD_PREP() helpers drivers/net/ethernet/amd/xgbe/xgbe-common.h | 5 ++ drivers/net/ethernet/amd/xgbe/xgbe-dev.c | 93 +++++++++++++++++++++ drivers/net/ethernet/amd/xgbe/xgbe-pci.c | 33 +++++++- drivers/net/ethernet/amd/xgbe/xgbe.h | 6 ++ 4 files changed, 135 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-common.h b/drivers/net/ethernet/amd/xgbe/xgbe-common.h index 3b70f6737633..e1f70f0528ef 100644 --- a/drivers/net/ethernet/amd/xgbe/xgbe-common.h +++ b/drivers/net/ethernet/amd/xgbe/xgbe-common.h @@ -900,6 +900,11 @@ #define PCS_V2_RV_WINDOW_SELECT 0x1064 #define PCS_V2_YC_WINDOW_DEF 0x18060 #define PCS_V2_YC_WINDOW_SELECT 0x18064 +#define PCS_V2_RN_WINDOW_DEF 0xF8078 +#define PCS_V2_RN_WINDOW_SELECT 0xF807c + +#define PCS_RN_SMN_BASE_ADDR 0x11E00000 +#define PCS_RN_PORT_ADDR_SIZE 0x100000 /* PCS register entry bit positions and sizes */ #define PCS_V2_WINDOW_DEF_OFFSET_INDEX 6 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-dev.c b/drivers/net/ethernet/amd/xgbe/xgbe-dev.c index 6cd003c24a64..a9eb2ffa9f73 100644 --- a/drivers/net/ethernet/amd/xgbe/xgbe-dev.c +++ b/drivers/net/ethernet/amd/xgbe/xgbe-dev.c @@ -120,6 +120,7 @@ #include #include #include +#include #include "xgbe.h" #include "xgbe-common.h" @@ -1165,6 +1166,92 @@ static unsigned int get_index_offset(struct xgbe_prv_data *pdata, unsigned int m return pdata->xpcs_window + (mmd_address & pdata->xpcs_window_mask); } +static int xgbe_read_mmd_regs_v3(struct xgbe_prv_data *pdata, int prtad, + int mmd_reg) +{ + unsigned int mmd_address, index, offset; + struct pci_dev *rdev; + unsigned long flags; + int mmd_data; + + rdev = pci_get_domain_bus_and_slot(0, 0, PCI_DEVFN(0, 0)); + if (!rdev) + return 0; + + mmd_address = get_mmd_address(pdata, mmd_reg); + + /* The PCS registers are accessed using mmio. The underlying + * management interface uses indirect addressing to access the MMD + * register sets. This requires accessing of the PCS register in two + * phases, an address phase and a data phase. + * + * The mmio interface is based on 16-bit offsets and values. All + * register offsets must therefore be adjusted by left shifting the + * offset 1 bit and reading 16 bits of data. + */ + offset = get_index_offset(pdata, mmd_address, &index); + + spin_lock_irqsave(&pdata->xpcs_lock, flags); + pci_write_config_dword(rdev, 0x60, (pdata->xphy_base + pdata->xpcs_window_sel_reg)); + pci_write_config_dword(rdev, 0x64, index); + pci_write_config_dword(rdev, 0x60, pdata->xphy_base + offset); + pci_read_config_dword(rdev, 0x64, &mmd_data); + mmd_data = (offset % 4) ? FIELD_GET(XGBE_GEN_HI_MASK, mmd_data) : + FIELD_GET(XGBE_GEN_LO_MASK, mmd_data); + pci_dev_put(rdev); + + spin_unlock_irqrestore(&pdata->xpcs_lock, flags); + + return mmd_data; +} + +static void xgbe_write_mmd_regs_v3(struct xgbe_prv_data *pdata, int prtad, + int mmd_reg, int mmd_data) +{ + unsigned int mmd_address, index, offset, ctr_mmd_data; + struct pci_dev *rdev; + unsigned long flags; + + rdev = pci_get_domain_bus_and_slot(0, 0, PCI_DEVFN(0, 0)); + if (!rdev) + return; + + mmd_address = get_mmd_address(pdata, mmd_reg); + + /* The PCS registers are accessed using mmio. The underlying + * management interface uses indirect addressing to access the MMD + * register sets. This requires accessing of the PCS register in two + * phases, an address phase and a data phase. + * + * The mmio interface is based on 16-bit offsets and values. All + * register offsets must therefore be adjusted by left shifting the + * offset 1 bit and writing 16 bits of data. + */ + offset = get_index_offset(pdata, mmd_address, &index); + + spin_lock_irqsave(&pdata->xpcs_lock, flags); + pci_write_config_dword(rdev, 0x60, (pdata->xphy_base + pdata->xpcs_window_sel_reg)); + pci_write_config_dword(rdev, 0x64, index); + pci_write_config_dword(rdev, 0x60, pdata->xphy_base + offset); + pci_read_config_dword(rdev, 0x64, &ctr_mmd_data); + if (offset % 4) { + ctr_mmd_data = FIELD_PREP(XGBE_GEN_HI_MASK, mmd_data) | + FIELD_GET(XGBE_GEN_LO_MASK, ctr_mmd_data); + } else { + ctr_mmd_data = FIELD_PREP(XGBE_GEN_HI_MASK, + FIELD_GET(XGBE_GEN_HI_MASK, ctr_mmd_data)) | + FIELD_GET(XGBE_GEN_LO_MASK, mmd_data); + } + + pci_write_config_dword(rdev, 0x60, (pdata->xphy_base + pdata->xpcs_window_sel_reg)); + pci_write_config_dword(rdev, 0x64, index); + pci_write_config_dword(rdev, 0x60, (pdata->xphy_base + offset)); + pci_write_config_dword(rdev, 0x64, ctr_mmd_data); + pci_dev_put(rdev); + + spin_unlock_irqrestore(&pdata->xpcs_lock, flags); +} + static int xgbe_read_mmd_regs_v2(struct xgbe_prv_data *pdata, int prtad, int mmd_reg) { @@ -1274,6 +1361,9 @@ static int xgbe_read_mmd_regs(struct xgbe_prv_data *pdata, int prtad, case XGBE_XPCS_ACCESS_V1: return xgbe_read_mmd_regs_v1(pdata, prtad, mmd_reg); + case XGBE_XPCS_ACCESS_V3: + return xgbe_read_mmd_regs_v3(pdata, prtad, mmd_reg); + case XGBE_XPCS_ACCESS_V2: default: return xgbe_read_mmd_regs_v2(pdata, prtad, mmd_reg); @@ -1287,6 +1377,9 @@ static void xgbe_write_mmd_regs(struct xgbe_prv_data *pdata, int prtad, case XGBE_XPCS_ACCESS_V1: return xgbe_write_mmd_regs_v1(pdata, prtad, mmd_reg, mmd_data); + case XGBE_XPCS_ACCESS_V3: + return xgbe_write_mmd_regs_v3(pdata, prtad, mmd_reg, mmd_data); + case XGBE_XPCS_ACCESS_V2: default: return xgbe_write_mmd_regs_v2(pdata, prtad, mmd_reg, mmd_data); diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-pci.c b/drivers/net/ethernet/amd/xgbe/xgbe-pci.c index d6071f34b7db..22b771057cb8 100644 --- a/drivers/net/ethernet/amd/xgbe/xgbe-pci.c +++ b/drivers/net/ethernet/amd/xgbe/xgbe-pci.c @@ -293,15 +293,28 @@ static int xgbe_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) /* Yellow Carp devices do not need rrc */ pdata->vdata->enable_rrc = 0; break; + case 0x1630: + pdata->xpcs_window_def_reg = PCS_V2_RN_WINDOW_DEF; + pdata->xpcs_window_sel_reg = PCS_V2_RN_WINDOW_SELECT; + break; default: pdata->xpcs_window_def_reg = PCS_V2_WINDOW_DEF; pdata->xpcs_window_sel_reg = PCS_V2_WINDOW_SELECT; break; } - pci_dev_put(rdev); /* Configure the PCS indirect addressing support */ - reg = XPCS32_IOREAD(pdata, pdata->xpcs_window_def_reg); + if (pdata->vdata->xpcs_access == XGBE_XPCS_ACCESS_V3) { + reg = XP_IOREAD(pdata, XP_PROP_0); + pdata->xphy_base = PCS_RN_SMN_BASE_ADDR + + (PCS_RN_PORT_ADDR_SIZE * XP_GET_BITS(reg, XP_PROP_0, PORT_ID)); + pci_write_config_dword(rdev, 0x60, pdata->xphy_base + (pdata->xpcs_window_def_reg)); + pci_read_config_dword(rdev, 0x64, ®); + } else { + reg = XPCS32_IOREAD(pdata, pdata->xpcs_window_def_reg); + } + pci_dev_put(rdev); + pdata->xpcs_window = XPCS_GET_BITS(reg, PCS_V2_WINDOW_DEF, OFFSET); pdata->xpcs_window <<= 6; pdata->xpcs_window_size = XPCS_GET_BITS(reg, PCS_V2_WINDOW_DEF, SIZE); @@ -479,6 +492,22 @@ static int __maybe_unused xgbe_pci_resume(struct device *dev) return ret; } +static struct xgbe_version_data xgbe_v3 = { + .init_function_ptrs_phy_impl = xgbe_init_function_ptrs_phy_v2, + .xpcs_access = XGBE_XPCS_ACCESS_V3, + .mmc_64bit = 1, + .tx_max_fifo_size = 65536, + .rx_max_fifo_size = 65536, + .tx_tstamp_workaround = 1, + .ecc_support = 1, + .i2c_support = 1, + .irq_reissue_support = 1, + .tx_desc_prefetch = 5, + .rx_desc_prefetch = 5, + .an_cdr_workaround = 0, + .enable_rrc = 0, +}; + static struct xgbe_version_data xgbe_v2a = { .init_function_ptrs_phy_impl = xgbe_init_function_ptrs_phy_v2, .xpcs_access = XGBE_XPCS_ACCESS_V2, diff --git a/drivers/net/ethernet/amd/xgbe/xgbe.h b/drivers/net/ethernet/amd/xgbe/xgbe.h index ad136ed493ed..dbb1faaf6185 100644 --- a/drivers/net/ethernet/amd/xgbe/xgbe.h +++ b/drivers/net/ethernet/amd/xgbe/xgbe.h @@ -347,6 +347,10 @@ (_src)->link_modes._sname, \ __ETHTOOL_LINK_MODE_MASK_NBITS) +/* Generic low and high masks */ +#define XGBE_GEN_HI_MASK GENMASK(31, 16) +#define XGBE_GEN_LO_MASK GENMASK(15, 0) + struct xgbe_prv_data; struct xgbe_packet_data { @@ -565,6 +569,7 @@ enum xgbe_speed { enum xgbe_xpcs_access { XGBE_XPCS_ACCESS_V1 = 0, XGBE_XPCS_ACCESS_V2, + XGBE_XPCS_ACCESS_V3, }; enum xgbe_an_mode { @@ -1056,6 +1061,7 @@ struct xgbe_prv_data { struct device *dev; struct platform_device *phy_platdev; struct device *phy_dev; + unsigned int xphy_base; /* Version related data */ struct xgbe_version_data *vdata; From patchwork Thu Nov 16 13:54:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Raju Rangoju X-Patchwork-Id: 13457929 X-Patchwork-Delegate: kuba@kernel.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="Kmc5CgSA" Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2078.outbound.protection.outlook.com [40.107.237.78]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 41623A9 for ; Thu, 16 Nov 2023 05:55:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=oaVyPrRdQcFEgJP5/F+w6bbfvnz/ewWEwcprdHfsFVFYHk0t2RFO/8jz/RcuBOoY2dhsK7qhgypWRrcTHIGPpiJsGZCUaGK9969tNjNbyJ6HpBO0MhLFaBkdU2LWCQRXv4nmoL8/HtvmtXh3kl3gr+bWTWZQ3/Oi5DRjE6wSdA7Mhw5ejsqYl0T7l+GLwa4gkXa7GUKuH6lc2ppktCJpbBvfgs+cG7FBdwmmMep9AOcLBUZFclResxol83KCcU10RgbCcw+7vThgYXSWUy6FCrT4MEZonwN3srazyoFbizunTRWuri3IBfFispqwA+Zqm2GFNvl2EWEnnNcuFPXPVw== 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=fQ8mb5ca+vRt3S/qckE9enOqxOf1BTDR78NMejyB/7k=; b=YZqKoo1LgNck2B3J8e4tKE9iUXY1J3tVQa6rUbt6qN/OaokvTjio0eYjW6RnYoeu8xcOgfma6NgtVZsOdp/qMQVUNrElkPJH/uXfco5J3ELndO9n7EJubcsuQ5yrxJCs1ltaJl/b0A7r9/mxxEOakpt0djX7b3WbZB5IP4+a1tBElLMnK5XVFu3aQ0RLYaZIVQeVeGszGFoJ7JkcdURDhd89gDMHHXyNn/y1o0n1q5zVx89JbC5sXRILkHIZlfuh85ySwW/z44WQpowd972XJfLT+nZ9xwk1A9X1Tlonb+n0RXpVKkwmHtNHTzuz6WBjV6SiWkto5opdztHBBHT2EA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.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 (0) 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=fQ8mb5ca+vRt3S/qckE9enOqxOf1BTDR78NMejyB/7k=; b=Kmc5CgSAz1gzr7U5JC+SJ7GwROgl4bsPK98SVB/zTJdQqoI5fUS5WW+4UVf+e4Qk2IjjclepVsJliOKAeM+9YDDauaA43PHWX7xpcu703QFlwVASmnxrvoSJznQlt4piiVnPmcixHv7pRi3oXHiJNHcykloevgOu/2uAFohdzic= Received: from MW4P221CA0025.NAMP221.PROD.OUTLOOK.COM (2603:10b6:303:8b::30) by CY8PR12MB7193.namprd12.prod.outlook.com (2603:10b6:930:5b::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6977.31; Thu, 16 Nov 2023 13:55:40 +0000 Received: from CO1PEPF000042AD.namprd03.prod.outlook.com (2603:10b6:303:8b:cafe::98) by MW4P221CA0025.outlook.office365.com (2603:10b6:303:8b::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7002.21 via Frontend Transport; Thu, 16 Nov 2023 13:55:40 +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 CO1PEPF000042AD.mail.protection.outlook.com (10.167.243.42) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7002.20 via Frontend Transport; Thu, 16 Nov 2023 13:55:40 +0000 Received: from jatayu.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.32; Thu, 16 Nov 2023 07:55:36 -0600 From: Raju Rangoju To: CC: , , , , , Raju Rangoju , Sudheesh Mavila Subject: [PATCH v2 net-next 3/4] amd-xgbe: add support for new pci device id 0x1641 Date: Thu, 16 Nov 2023 19:24:15 +0530 Message-ID: <20231116135416.3371367-4-Raju.Rangoju@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231116135416.3371367-1-Raju.Rangoju@amd.com> References: <20231116135416.3371367-1-Raju.Rangoju@amd.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: CO1PEPF000042AD:EE_|CY8PR12MB7193:EE_ X-MS-Office365-Filtering-Correlation-Id: 4fbeef52-17f1-4a82-ee9a-08dbe6abb822 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: uABTtcJ74rzF3v1AqNJzWgFGuTI3zqA7Lmb2hUP8YntOx9McyoXW11OSgcqcZ2cHkINpoM5goadHtYfAOCqekJ4VWNWVJKy8pB+aNNyDplt1QXy6/eC9LvVKPN5VEi6CGKbKCYEd5b8Vqzj2qguvaVAMn1nHryFwd7KadbpEONZojjFyhTBWklpC3S2eb/4xpmbQZul/xf7w0qikGT2T5LmbYD4h9qOXe76Yb87AK8RigZ5DOZaUNIC9VqcgdCm1FAe3x+GFggYpeEtcuE7zqMqhdVjptRMSSZ7JgLvYCjhUpHmNJFnuPj1ObG1MNm0yEggPTl+P1w6jETQycuAcyhKxE57XIOgYdS5pZ/oUplM3oE1MqCL2diK6UYAhQL93KkAdzw7FR0XGCN98d5lNQJZTO+ymR6aMlS5Xldp+MOn11imF7gSjIsOvWy7LsOkZtNdYoJFAJgS3CMGfJJfcFriYobHOZRDwregi3J+Co9o8eVn0n+ItgoK0LTzYOyN+L7rTjGGVRXywgpFPdwdcFnv+xc7hZiWzhu6/1hOtzG0m4QOTVk942iwZKL3m18bgJrbCW//m8T0eYWXb42kuAkQBwQlTS/4UOgkEC2aIyi9Q+NosZBHKj4IMykZTUwKppTSJtYQ+XHv3p4y4xodVsaZiPhzBSrFwTpzBGClvil5W9ZNao8lsjdCXOWcjrXsoA0mHFjK27nfmjuJavsnn+0gt6VhuTn9ft+9ArEKxoiQXor7oVPrx7IpLI/HYaICVDxw3M44kTd+/cP2u1cOvfA== 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)(136003)(346002)(396003)(376002)(230922051799003)(82310400011)(451199024)(186009)(64100799003)(1800799009)(46966006)(36840700001)(40470700004)(47076005)(316002)(70206006)(70586007)(2906002)(54906003)(6916009)(40480700001)(36756003)(36860700001)(16526019)(2616005)(356005)(41300700001)(336012)(26005)(426003)(81166007)(40460700003)(478600001)(82740400003)(5660300002)(86362001)(1076003)(7696005)(4744005)(8676002)(8936002)(6666004)(4326008)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Nov 2023 13:55:40.3181 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4fbeef52-17f1-4a82-ee9a-08dbe6abb822 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: CO1PEPF000042AD.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR12MB7193 X-Patchwork-Delegate: kuba@kernel.org Add support for new pci device id 0x1641 to register Crater device with PCIe. Co-developed-by: Sudheesh Mavila Signed-off-by: Sudheesh Mavila Signed-off-by: Raju Rangoju --- drivers/net/ethernet/amd/xgbe/xgbe-pci.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-pci.c b/drivers/net/ethernet/amd/xgbe/xgbe-pci.c index 22b771057cb8..5496980e1cc7 100644 --- a/drivers/net/ethernet/amd/xgbe/xgbe-pci.c +++ b/drivers/net/ethernet/amd/xgbe/xgbe-pci.c @@ -545,6 +545,8 @@ static const struct pci_device_id xgbe_pci_table[] = { .driver_data = (kernel_ulong_t)&xgbe_v2a }, { PCI_VDEVICE(AMD, 0x1459), .driver_data = (kernel_ulong_t)&xgbe_v2b }, + { PCI_VDEVICE(AMD, 0x1641), + .driver_data = (kernel_ulong_t)&xgbe_v3 }, /* Last entry must be zero */ { 0, } }; From patchwork Thu Nov 16 13:54:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Raju Rangoju X-Patchwork-Id: 13457930 X-Patchwork-Delegate: kuba@kernel.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="f33fZSXU" Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2085.outbound.protection.outlook.com [40.107.223.85]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D73AFAF for ; Thu, 16 Nov 2023 05:55:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=b+U2yqOcEjcB973w1JMAUIykdTATIyu+/nABi6+hJ9vx0uaT/mNEMV6n5B+d8ug1GuiBG5AYi3WjCYO0L8Ax0XnjkDo2U1Vy0gne4HMuySvOZiEGycy2oxbe8FyGFwPeEUnoyaCo2jLuWcgXRy+lY2jVWtsfi2vB5ilxaRCKiaiyr9ltTl+FA4ROpMXz9A2ow9ZhpwRU4IZ59TI3YQ8PbJU6mHjgK4k9KGbX9hVAu96m+IgJN1I6kOj3T/v0U/YRJR58EhTO+7jPT32s0l6BFDNzOHDch97XCPKVPO49EPalnX46vbEaEoLux3+dHBdmAP1RDKLSDFekjxplbUzjmA== 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=B3K3iMB5M26DcsU5imyaC6mQPTuFGkiGuE4tiAeGmAI=; b=lVwoW14Z0Qsh6jo9GEKb1o+q+3mcVLIESh+rrtcYTH8WUQjzStTK5/kKb13TrWj8MPDE01ZEkg8Et3Cf4PyUEvSaY+wyn5URJSkeAt+PMSnbmI1wYhND0rh0suwlSVnhk++vCIESo8XN+YVoIXBYAS4pbPaMlGy44e9h4f0AqkOaD33bicMeJcjXqxwKSG2Oe2RHJKCm2TMyKC2U52T62jiii2ajqFTFrAuDhKIm2GagH7oqDvJwN1wP6wKbVsRdMW/B0qVKugl/Rh71gzHkdAjPYLc+NnZyytMwvLZd28SGxpVZJfdt5b5ExA6+PO98DD85ACCS1bcDhlfelQbEsw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.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 (0) 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=B3K3iMB5M26DcsU5imyaC6mQPTuFGkiGuE4tiAeGmAI=; b=f33fZSXUKBM9MKoJxfIwytwDtTUlyV9BNJ9J8eUuuwNbcdeAG2UBaUgXcxdvyBKvfjapGC+PkvbkeaeHKw+AQSBdRh1zJ3m7WjpjbAzRAlgNGQ2tA+CNMd1J4hSSRBudUQCBai8pdVGw2gE36afSorfoigiVyHpbhZkI/CMALd0= Received: from MW4P223CA0022.NAMP223.PROD.OUTLOOK.COM (2603:10b6:303:80::27) by SN7PR12MB7251.namprd12.prod.outlook.com (2603:10b6:806:2ab::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7002.21; Thu, 16 Nov 2023 13:55:46 +0000 Received: from CO1PEPF000042A8.namprd03.prod.outlook.com (2603:10b6:303:80:cafe::7c) by MW4P223CA0022.outlook.office365.com (2603:10b6:303:80::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7002.21 via Frontend Transport; Thu, 16 Nov 2023 13:55:46 +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 CO1PEPF000042A8.mail.protection.outlook.com (10.167.243.37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7002.20 via Frontend Transport; Thu, 16 Nov 2023 13:55:45 +0000 Received: from jatayu.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.32; Thu, 16 Nov 2023 07:55:42 -0600 From: Raju Rangoju To: CC: , , , , , Raju Rangoju Subject: [PATCH v2 net-next 4/4] amd-xgbe: use smn functions to avoid race Date: Thu, 16 Nov 2023 19:24:16 +0530 Message-ID: <20231116135416.3371367-5-Raju.Rangoju@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231116135416.3371367-1-Raju.Rangoju@amd.com> References: <20231116135416.3371367-1-Raju.Rangoju@amd.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: CO1PEPF000042A8:EE_|SN7PR12MB7251:EE_ X-MS-Office365-Filtering-Correlation-Id: 3c370c28-be3d-4a02-2ac6-08dbe6abbb8f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Fl48Uf/oFrBh3PI8B8p3mFCAG0B2h5LLEXyjXHRElYJU+MH1vBmgv4ClH7dzKclWXgfgYGcZZ586IlVageCaVTf1t7yvrRgy/Tke5/Gb2vXEVQfjv9ULrqYiCymj3X752aRLefEVKt4tFVKAuPk7aOi3NrQxWjE7utWdVgDGsTxmUa/O4/TvHe3wmtWyPammh7vwb8EywXTPLL/MnBoSzlWTlyzFMyO3aNlRNoTxx9cOEThwEawoZ67aUgyWQ5T0cTDsFekIr6GDmZIluWBEe/AP5ysgm3+vntOEkAidW5OOBdZrAGT/v0+jUpdYsZeUtzFVHRTR7TZUJVJksiSfjglJbRo2KebNaDHSkbzf/X3AXJxjhrqLDnMB8lPTCjfX0S1IVIetZ23wYFDHyW5I6J4nqchvJi79wedrImOgl2ICMZzc4KOyKI2L5k/4wMOUXxM+fF2C6JkasbkuHFy5HgwuoUzzdifRY4k3tQ9eqmflrB7C38pBE6R64tYEW1YM4zStOfoD4dIYuCr9wERysVamExi+hTLZuXAQB5+Rn+S1pf3PncrT4t7uVTx3ay9ifeWDR/nEexWSuXl06PnTu3P6FmMYK/IAVMuVaBV0HuDsYCCgJqT6RpUR27CbWG7LSc+FbBOlloszFAlCOL177H7Jql7gJLPXcOD4PiSWowLOSIvO+9TudTO1vYxKB/IgElpN3aWifkVH2GlAwtG9v8KzFgFF26Jd8YcpBl0XuPU+2f0cD0KK4b1NT5EGuVauOlpbZAq5UL5puZMznFXg+Q== 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)(396003)(376002)(39860400002)(136003)(346002)(230922051799003)(82310400011)(64100799003)(451199024)(1800799009)(186009)(36840700001)(46966006)(40470700004)(2906002)(5660300002)(86362001)(40460700003)(36860700001)(81166007)(356005)(7696005)(6666004)(47076005)(41300700001)(8936002)(4326008)(8676002)(1076003)(426003)(54906003)(70206006)(70586007)(6916009)(316002)(336012)(2616005)(82740400003)(83380400001)(478600001)(16526019)(26005)(36756003)(40480700001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Nov 2023 13:55:45.9981 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3c370c28-be3d-4a02-2ac6-08dbe6abbb8f 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: CO1PEPF000042A8.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB7251 X-Patchwork-Delegate: kuba@kernel.org Some of the ethernet add-in-cards have dual PHY but share a single MDIO line (between the ports). In such cases, link inconsistencies are noticed during the heavy traffic and during reboot stress tests. So, use the SMN calls to avoid the race conditions. Signed-off-by: Raju Rangoju --- drivers/net/ethernet/amd/xgbe/xgbe-dev.c | 36 ++++++++---------------- drivers/net/ethernet/amd/xgbe/xgbe-pci.c | 13 +++++---- drivers/net/ethernet/amd/xgbe/xgbe.h | 2 +- 3 files changed, 20 insertions(+), 31 deletions(-) diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-dev.c b/drivers/net/ethernet/amd/xgbe/xgbe-dev.c index a9eb2ffa9f73..1f43456442e5 100644 --- a/drivers/net/ethernet/amd/xgbe/xgbe-dev.c +++ b/drivers/net/ethernet/amd/xgbe/xgbe-dev.c @@ -125,6 +125,10 @@ #include "xgbe.h" #include "xgbe-common.h" +#ifdef CONFIG_X86 +#include +#endif + static inline unsigned int xgbe_get_max_frame(struct xgbe_prv_data *pdata) { return pdata->netdev->mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN; @@ -1170,14 +1174,9 @@ static int xgbe_read_mmd_regs_v3(struct xgbe_prv_data *pdata, int prtad, int mmd_reg) { unsigned int mmd_address, index, offset; - struct pci_dev *rdev; unsigned long flags; int mmd_data; - rdev = pci_get_domain_bus_and_slot(0, 0, PCI_DEVFN(0, 0)); - if (!rdev) - return 0; - mmd_address = get_mmd_address(pdata, mmd_reg); /* The PCS registers are accessed using mmio. The underlying @@ -1192,13 +1191,10 @@ static int xgbe_read_mmd_regs_v3(struct xgbe_prv_data *pdata, int prtad, offset = get_index_offset(pdata, mmd_address, &index); spin_lock_irqsave(&pdata->xpcs_lock, flags); - pci_write_config_dword(rdev, 0x60, (pdata->xphy_base + pdata->xpcs_window_sel_reg)); - pci_write_config_dword(rdev, 0x64, index); - pci_write_config_dword(rdev, 0x60, pdata->xphy_base + offset); - pci_read_config_dword(rdev, 0x64, &mmd_data); + amd_smn_write(0, (pdata->smn_base + pdata->xpcs_window_sel_reg), index); + amd_smn_read(0, pdata->smn_base + offset, &mmd_data); mmd_data = (offset % 4) ? FIELD_GET(XGBE_GEN_HI_MASK, mmd_data) : FIELD_GET(XGBE_GEN_LO_MASK, mmd_data); - pci_dev_put(rdev); spin_unlock_irqrestore(&pdata->xpcs_lock, flags); @@ -1209,13 +1205,8 @@ static void xgbe_write_mmd_regs_v3(struct xgbe_prv_data *pdata, int prtad, int mmd_reg, int mmd_data) { unsigned int mmd_address, index, offset, ctr_mmd_data; - struct pci_dev *rdev; unsigned long flags; - rdev = pci_get_domain_bus_and_slot(0, 0, PCI_DEVFN(0, 0)); - if (!rdev) - return; - mmd_address = get_mmd_address(pdata, mmd_reg); /* The PCS registers are accessed using mmio. The underlying @@ -1230,10 +1221,9 @@ static void xgbe_write_mmd_regs_v3(struct xgbe_prv_data *pdata, int prtad, offset = get_index_offset(pdata, mmd_address, &index); spin_lock_irqsave(&pdata->xpcs_lock, flags); - pci_write_config_dword(rdev, 0x60, (pdata->xphy_base + pdata->xpcs_window_sel_reg)); - pci_write_config_dword(rdev, 0x64, index); - pci_write_config_dword(rdev, 0x60, pdata->xphy_base + offset); - pci_read_config_dword(rdev, 0x64, &ctr_mmd_data); + amd_smn_write(0, (pdata->smn_base + pdata->xpcs_window_sel_reg), index); + amd_smn_read(0, pdata->smn_base + offset, &ctr_mmd_data); + if (offset % 4) { ctr_mmd_data = FIELD_PREP(XGBE_GEN_HI_MASK, mmd_data) | FIELD_GET(XGBE_GEN_LO_MASK, ctr_mmd_data); @@ -1243,12 +1233,8 @@ static void xgbe_write_mmd_regs_v3(struct xgbe_prv_data *pdata, int prtad, FIELD_GET(XGBE_GEN_LO_MASK, mmd_data); } - pci_write_config_dword(rdev, 0x60, (pdata->xphy_base + pdata->xpcs_window_sel_reg)); - pci_write_config_dword(rdev, 0x64, index); - pci_write_config_dword(rdev, 0x60, (pdata->xphy_base + offset)); - pci_write_config_dword(rdev, 0x64, ctr_mmd_data); - pci_dev_put(rdev); - + amd_smn_write(0, (pdata->smn_base + pdata->xpcs_window_sel_reg), index); + amd_smn_write(0, (pdata->smn_base + offset), ctr_mmd_data); spin_unlock_irqrestore(&pdata->xpcs_lock, flags); } diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-pci.c b/drivers/net/ethernet/amd/xgbe/xgbe-pci.c index 5496980e1cc7..3e2a5bb694e7 100644 --- a/drivers/net/ethernet/amd/xgbe/xgbe-pci.c +++ b/drivers/net/ethernet/amd/xgbe/xgbe-pci.c @@ -122,6 +122,10 @@ #include "xgbe.h" #include "xgbe-common.h" +#ifdef CONFIG_X86 +#include +#endif + static int xgbe_config_multi_msi(struct xgbe_prv_data *pdata) { unsigned int vector_count; @@ -302,18 +306,17 @@ static int xgbe_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) pdata->xpcs_window_sel_reg = PCS_V2_WINDOW_SELECT; break; } + pci_dev_put(rdev); /* Configure the PCS indirect addressing support */ if (pdata->vdata->xpcs_access == XGBE_XPCS_ACCESS_V3) { reg = XP_IOREAD(pdata, XP_PROP_0); - pdata->xphy_base = PCS_RN_SMN_BASE_ADDR + - (PCS_RN_PORT_ADDR_SIZE * XP_GET_BITS(reg, XP_PROP_0, PORT_ID)); - pci_write_config_dword(rdev, 0x60, pdata->xphy_base + (pdata->xpcs_window_def_reg)); - pci_read_config_dword(rdev, 0x64, ®); + pdata->smn_base = PCS_RN_SMN_BASE_ADDR + + (PCS_RN_PORT_ADDR_SIZE * XP_GET_BITS(reg, XP_PROP_0, PORT_ID)); + amd_smn_read(0, pdata->smn_base + (pdata->xpcs_window_def_reg), ®); } else { reg = XPCS32_IOREAD(pdata, pdata->xpcs_window_def_reg); } - pci_dev_put(rdev); pdata->xpcs_window = XPCS_GET_BITS(reg, PCS_V2_WINDOW_DEF, OFFSET); pdata->xpcs_window <<= 6; diff --git a/drivers/net/ethernet/amd/xgbe/xgbe.h b/drivers/net/ethernet/amd/xgbe/xgbe.h index dbb1faaf6185..ba45ab0adb8c 100644 --- a/drivers/net/ethernet/amd/xgbe/xgbe.h +++ b/drivers/net/ethernet/amd/xgbe/xgbe.h @@ -1061,7 +1061,7 @@ struct xgbe_prv_data { struct device *dev; struct platform_device *phy_platdev; struct device *phy_dev; - unsigned int xphy_base; + unsigned int smn_base; /* Version related data */ struct xgbe_version_data *vdata;