From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=40.107.167.84 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796139700; b=EPIvUXkUZBQihGh9Mfe38Nhb64j+PxDTbNF2Vs36EyjO82fpv6txc7mdg8HZ9HBS9A/1 zEKhBojT2qqbMric7smF0UX38eKh2fuS51pmBJSfzS2sLtP1SSNCBLLZ0SjGEGmtlCmk0 0w9gWtS36wxLwu1vvaH2/ACAx2ZocuLPPCZNkx1tU3tRfSDKs4b1k2sojslRGl+S8MK7t UxHsljsPDQjm+5F0zgQjYjYc5rHqThwWpMyIeZ+ZOqxD1Qfi880wXD6Ozp1Xbv3MUg9LE +HvmPA8Zcn63OdHFiqo0OeRxpNgvxrtNJ3s5I5SQaqmqQft31bla2XdmsyPBIleIimA== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796139700; h=DMARC-Filter:DKIM-Signature:Received:Received: X-MS-Exchange-Authentication-Results:Received-SPF:Received:Received: Received:X-SEPP-Suspect:Received:Received:Received:Received:Received: Received:X-MS-Exchange-Authentication-Results:Received-SPF:Received: Received:Authentication-Results-Original:Received:Received:From:To:CC: Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: Content-Transfer-Encoding:Content-Type:X-ClientProxiedBy:MIME-Version: X-MS-TrafficTypeDiagnostic:X-MS-Office365-Filtering-Correlation-Id: X-MS-Exchange-SenderADCheck:X-MS-Exchange-AntiSpam-Relay: X-Microsoft-Antispam-Untrusted: X-Microsoft-Antispam-Message-Info-Original: X-Forefront-Antispam-Report-Untrusted:X-Exchange-RoutingPolicyChecked: X-MS-Exchange-Transport-CrossTenantHeadersStamped:X-CodeTwo-MessageID: X-CodeTwoProcessed:X-EOPAttributedMessage: X-MS-Exchange-Transport-CrossTenantHeadersStripped: X-MS-Office365-Filtering-Correlation-Id-Prvs: X-Microsoft-Antispam-Untrusted: X-Microsoft-Antispam-Message-Info-Original: X-Forefront-Antispam-Report-Untrusted: X-MS-Exchange-Transport-CrossTenantHeadersStamped:X-SEPP-CCCVersion: X-MS-Exchange-SkipListedInternetSender: X-MS-Exchange-ExternalOriginalInternetSender: X-MS-Exchange-Transport-CrossTenantHeadersStripped: X-MS-PublicTrafficType:X-MS-Office365-Filtering-Correlation-Id-Prvs: X-SM-ruleversion:X-Microsoft-Antispam: X-Microsoft-Antispam-Message-Info:X-Forefront-Antispam-Report: X-MS-Exchange-AntiSpam-MessageData-ChunkCount: X-MS-Exchange-AntiSpam-MessageData-0:X-OriginatorOrg: X-MS-Exchange-CrossTenant-OriginalArrivalTime: X-MS-Exchange-CrossTenant-Network-Message-Id: X-MS-Exchange-CrossTenant-Id: X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: X-MS-Exchange-CrossTenant-AuthSource:X-MS-Exchange-CrossTenant-AuthAs: X-MS-Exchange-CrossTenant-FromEntityHeader: X-MS-Exchange-Transport-CrossTenantHeadersStamped; bh=kZoo9dCnUCRIcSr8NqJWExDARD+kel2lDrHzsAibV7A=; b=ck1M9sS+mRjLjruRCwzajZDax9lti1g9yFjBjZIM/6hrsMi9tQsh1LQez7LNWuUeT4xd 757NqHYYPpfMg4wF7L83vA1pojj2imIwK+f/YVR6pQMn43aPmntVX0iW/WO0PNzgHa8IN uy+tERHv1vo/ByfYtAK88wkXd5z8yAaAsdrWeAZzNpJwqazIyuzztEu0rhpPRiGNc3UTi S7m8EwojaJl3uTgzRPgD3VmOJUeeAQDFy/COMHJi12O9od5v3g1N9800CY+NVXgo53Ggd apVZaB676K5re0mEEjYgNdNaRgCwv83f/R2Tl45kFS05fBE783enxJNYC/qeOKFCXnw== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass header.from=duagon.com; spf=pass smtp.mailfrom=duagon.com; dkim=pass header.d=duagon.com header.i=@duagon.com header.a=rsa-sha256 header.s=selector1 header.b=T6UiK3wv; arc=pass header.oldest-pass=0 smtp.remote-ip=40.107.167.84 Received: from ZRZP278CU001.outbound.protection.outlook.com (mail-switzerlandnorthazon11021084.outbound.protection.outlook.com [40.107.167.84]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (secp384r1) server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 24D6B606A320; Tue, 1 Dec 2026 15:41:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 24D6B606A320 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=duagon.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=duagon.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=duagon.com header.i=@duagon.com header.a=rsa-sha256 header.s=selector1 header.b=T6UiK3wv ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ogAiceD+heC51G1Ca5CiiRMeDMQEJpWRKHv2mHbZKMu1exvhR2TLR80o0X36yzl++sktjuBFIfWQkMhjYY0Pw5n+DarRcCTmLVQDQMHiBPYWVjKlYtwXH0UJA6ozGxZqpB+iNg5XCAc+gtg9fgD0XXjprDgAu8NzA66jRE4yqD6Jq4kj269lkNkOqZaNXqmZsWu7IBpXE2c+xVmDascqnd655FKkmCvrSaxserdv6Sija2r6QNT1u74cq6QzJIcGAifkWgN/vJsQWF5T476dpPY4jahP9ssZFqqJhY0mUbFJwupnkCPGXkodvznZjlAfJggQeBDbkvS8xFhBYsRUnQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=kZoo9dCnUCRIcSr8NqJWExDARD+kel2lDrHzsAibV7A=; b=pqx95X33jFP1FLvYGiV9lqeK08TNsElbsQ5a76KsMeI+fO2+xLKQkrWzaQ0afGg1t4BxMSfum5T7qiI1BHv3uPSQsN4gpPX+XVw/SEvNmMRQ3cUUz4CPktcRxQinnMHYemjuEIFlEBvYYIbG3CoRWq6QXrURQ36UaspLnbybDwBnKQCYeG+Du1ixbpQa5CAHw6nQ7xxgWlWvFe49Mmp9cRxJslf9WGlrQZoY3FHoCBNDABAitVsXjfqcHfvBz+TmlslyuBkZFF7nziR8cB/HOKdcOAf6fasBpCfwIJ+FZhQjrL6ECBy94aQ37YPVTY82tCjkHui2/TFRrJ4b6uZCug== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 40.93.86.0) smtp.rcpttodomain=davemloft.net smtp.mailfrom=duagon.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=duagon.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=duagon.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=kZoo9dCnUCRIcSr8NqJWExDARD+kel2lDrHzsAibV7A=; b=T6UiK3wvOA9s2pObLxB/ydagMDwfYXccdRaepxHqnWRiGa09VFbkTvqv8TI5YepFdokEnEQlayEaayx2Pv+mAtAMt5dT2WQWtI4/xeGjsPnPpzgCJGBNfEvHKXDOCdPpjOkaDGSrSbl63HaVE9K7Nqsz28ab+FZpFnKJEtIO9lk= Received: from PAZP264CA0249.FRAP264.PROD.OUTLOOK.COM (2603:10a6:102:239::6) by ZR4P278MB548269.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:301::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.662.13; Tue, 1 Dec 2026 15:41:33 +0000 Received: from MI3PEPF0000848D.eurprd03.prod.outlook.com (2603:10a6:102:239:cafe::63) by PAZP264CA0249.outlook.office365.com (2603:10a6:102:239::6) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.688.10 via Frontend Transport; Tue, 1 Dec 2026 15:41:33 +0000 X-MS-Exchange-Authentication-Results: mx.microsoft.com 1; spf=pass (sender IP is 40.93.86.0) smtp.mailfrom=duagon.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=duagon.com; Received-SPF: Pass (protection.outlook.com: domain of duagon.com designates 40.93.86.0 as permitted sender) receiver=protection.outlook.com; client-ip=40.93.86.0; helo=GVAP278CU002.outbound.protection.outlook.com; pr=C Received: from sy-deliver01.de.seppmail.cloud (2a04:d480:4400:11:f816:3eff:fe57:da56) by MI3PEPF0000848D.mail.protection.outlook.com (2603:10a6:298:1::54) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.662.3 via Frontend Transport; Tue, 1 Dec 2026 15:41:31 +0000 Received: from hz-glue03.de.seppmail.cloud (unknown [10.11.0.9]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by sy-deliver01.de.seppmail.cloud (Postfix) with ESMTPS id 4jf4qv3VFSz2yfW; Tue, 1 Dec 2026 16:41:31 +0100 (CET) Received: from hz-glue03.de.seppmail.cloud (unknown [172.18.0.3]) by hz-glue03.de.seppmail.cloud (Postfix) with SMTP id 4jf4qv2mQ5z1yy7; Tue, 1 Dec 2026 16:41:31 +0100 (CET) X-SEPP-Suspect: 7301ba162a8a4d1db8b91dd40638817e Received: from hz-scan09.de.seppmail.cloud (unknown [10.11.0.50]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by hz-glue01.de.seppmail.cloud (Postfix) with ESMTPS id 4jf4qv1jzPz25Nq; Tue, 1 Dec 2026 16:41:31 +0100 (CET) Received: from hz-scan09 (localhost [127.0.0.1]) by hz-scan09.de.seppmail.cloud (Postfix) with SMTP id 4jf4qv16wsz19wD; Tue, 01 Dec 2026 16:41:31 +0100 (CET) Received: from hz-m365gate01.de.seppmail.cloud (unknown [10.11.0.27]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by hz-scan09.de.seppmail.cloud (Postfix) with ESMTPS; Tue, 01 Dec 2026 16:41:30 +0100 (CET) Received: from GVAP278CU002.outbound.protection.outlook.com (mail-switzerlandwestazlp17010000.outbound.protection.outlook.com [40.93.86.0]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (secp384r1) server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "mail.protection.outlook.com", Issuer "DigiCert SHA2 Secure Server CA" (not verified)) by hz-m365gate01.de.seppmail.cloud (Postfix) with ESMTPS id 4jf4qq3016z2y2s; Tue, 1 Dec 2026 16:41:27 +0100 (CET) Received: from DUZP195CA0030.EURP195.PROD.OUTLOOK.COM (2603:10a6:10:5bb::36) by ZR3P278MB022095.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:bd::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.688.10; Tue, 1 Dec 2026 15:41:22 +0000 Received: from DB3PEPF0000885A.eurprd02.prod.outlook.com (2603:10a6:10:5bb:cafe::68) by DUZP195CA0030.outlook.office365.com (2603:10a6:10:5bb::36) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.688.10 via Frontend Transport; Tue, 1 Dec 2026 15:41:22 +0000 X-MS-Exchange-Authentication-Results: mx.microsoft.com 1; spf=pass (sender IP is 20.79.222.204) smtp.mailfrom=duagon.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=duagon.com; Received-SPF: Pass (protection.outlook.com: domain of duagon.com designates 20.79.222.204 as permitted sender) receiver=protection.outlook.com; client-ip=20.79.222.204; helo=de2-emailsignatures-cloud.codetwo.com; pr=C Received: from de2-emailsignatures-cloud.codetwo.com (20.79.222.204) by DB3PEPF0000885A.mail.protection.outlook.com (10.167.242.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.688.5 via Frontend Transport; Tue, 1 Dec 2026 15:41:22 +0000 Received: from ZRZP278CU001.outbound.protection.outlook.com (40.93.85.25) by de2-emailsignatures-cloud.codetwo.com with CodeTwo SMTP Server (TLS12) via SMTP; Tue, 01 Dec 2026 15:41:21 +0000 Authentication-Results-Original: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=duagon.com; Received: from ZR0P278MB0523.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:34::6) by GV0P278MB1606.CHEP278.PROD.OUTLOOK.COM (2603:10a6:710:69::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.688.10; Tue, 1 Dec 2026 15:41:19 +0000 Received: from ZR0P278MB0523.CHEP278.PROD.OUTLOOK.COM ([fe80::30b2:3be9:48ab:c354]) by ZR0P278MB0523.CHEP278.PROD.OUTLOOK.COM ([fe80::30b2:3be9:48ab:c354%3]) with mapi id 15.21.0662.012; Tue, 1 Dec 2026 15:41:19 +0000 From: Jose Javier Rodriguez Barbarin To: netdev@vger.kernel.org CC: andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com, linux-kernel@vger.kernel.org, Jose Javier Rodriguez Barbarin , Filip Jensen Subject: [RFC net-next 1/2] net: ethernet: add MEN Z87 driver Date: Tue, 1 Dec 2026 16:40:08 +0100 Message-ID: <20261201154009.83819-2-dev-josejavier.rodriguez@duagon.com> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261201154009.83819-1-dev-josejavier.rodriguez@duagon.com> References: <20261201154009.83819-1-dev-josejavier.rodriguez@duagon.com> Content-Transfer-Encoding: quoted-printable Content-Type: text/plain X-ClientProxiedBy: MR1P264CA0160.FRAP264.PROD.OUTLOOK.COM (2603:10a6:501:55::11) To ZR0P278MB0523.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:34::6) X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 X-MS-TrafficTypeDiagnostic: ZR0P278MB0523:EE_|GV0P278MB1606:EE_|DB3PEPF0000885A:EE_|ZR3P278MB022095:EE_|MI3PEPF0000848D:EE_|ZR4P278MB548269:EE_ X-MS-Office365-Filtering-Correlation-Id: 96d3428b-a037-4ad2-681a-08df4fc192bc X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0;ARA:13230040|52116014|376014|366016|1800799024|23010399003|38350700014|10067099003|56012099006|11063799006|261021135927099003|261021130227099003|261021123027099003|261022113327099003|261022075727099003|261022105027099003|261021121427099003|261021133027099003|261009223027099003|261022115727099003|261102123227099003|261026121527099003|261026130827099003|261026140227099003|261026135527099003|261028144727099003|18002099003|22082099003|6133799003|3023799007; X-Microsoft-Antispam-Message-Info-Original: bPEKb4v49WcCy0Ntg2LwFIzpr5Cf6a/aQhzNEL0PkrJjiACg6APswGhdtDOY2pAt83v/rVKloh2neDYgO1W3cuZxmlciCWNRSBbVVPL4tC1Eo/Gg9o30U0U2tJL/W7aVnchfvTdKaombazj74PinkTFr2P4tHBzWzG1t+moUl8ryBkQY4hGekn+Hj2OGAjaQhl/TbnHS/x0VVmcTGFKvpr7R5Oip+ztpP+kUwn7AQOrKjBmGC1nNbAM4/3ySo2+lXZdJLt5oC360qcuNtCm0kZSrXMik006N+BT8sFlktwye607UypaPfRfw7QvOc2/OKauV/KTPOqt9RQIiP6WotCO8FKhECyBPMof8mSUBDOnNDdhfE6bGkyAM7uw0C3+YdQ/Xp+7mJ5bXyy9rUHKawZyHX666EHbbOmQ2rQYFEQ7sMAXFmNnEUSJn15oXga5MYlZkbqap7AzY7Ocz9twCA3+XVs0PFPBa8H2ljsPo3O9UvNy/yMAzPRgNfJNFOBFHGuv7Xb+2YpjtRkBcaprnC4/Wxa5EzOsmMTxgeaCrdSuWABQbUIhaq1NWwEoaTyoi0vN6TUvUxt5pXxwnehyro2fK3OOu02D9+Aik5gKqRFh8Ene5Hn+UBC7gAL1QZ5bwIPhLhn3ub63cHimTz3YiHEQDwyB1TWa0/h/J7Hw5ElVzoLP2wBrZcSNzCfWoLtvk98EaOMdQBxhZl9/e/SPE+tzXDX+bgxJn9iCIFJkxTa8= X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:ZR0P278MB0523.CHEP278.PROD.OUTLOOK.COM;PTR:;CAT:NONE;SFS:(13230040)(52116014)(376014)(366016)(1800799024)(23010399003)(38350700014)(10067099003)(56012099006)(11063799006)(261021135927099003)(261021130227099003)(261021123027099003)(261022113327099003)(261022075727099003)(261022105027099003)(261021121427099003)(261021133027099003)(261009223027099003)(261022115727099003)(261102123227099003)(261026121527099003)(261026130827099003)(261026140227099003)(261026135527099003)(261028144727099003)(18002099003)(22082099003)(6133799003)(3023799007);DIR:OUT;SFP:1102; X-Exchange-RoutingPolicyChecked: Vxip26UM47064H6eK39aOm4fKnjZPB2WqTVGWcrqU4aGj0mDgzi6eEwxMg7eE3p81JH6pIqDET2cyRxsxbDJMRfqupQ+PuoApXbEqLVkY5HRBejdFQo2v2RtMZbfcYMfl588ETMdE/A1/3uQuEMGp/1asOYVGxbphhHgTKtazaI3a6sf8TJXO5AtvZRH0nPBrB4uH2rw9QzZ6QKBbIMt2DItISjX3qWdjh3uFplj4HrokTAupNng7y/whN5Rrj6LEGPteqUhvxV5JEwun6GAq5jw5L3PoHAmMgN03HqcJcR6E49nUKuONuyaQ8jRk6bfQLd13SaV4PywBH1Pzj20mA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: GV0P278MB1606 X-CodeTwo-MessageID: d9300f5e-590e-4aa8-89b3-e808791a7474.20261201154121@de2-emailsignatures-cloud.codetwo.com X-CodeTwoProcessed: true X-EOPAttributedMessage: 1 X-MS-Exchange-Transport-CrossTenantHeadersStripped: DB3PEPF0000885A.eurprd02.prod.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: 263a161d-613c-44b8-c9c1-08df4fc18af9 X-Microsoft-Antispam-Untrusted: BCL:0;ARA:13230040|14060799003|23010399003|82310400026|36860700016|35042699022|1800799024|376014|11063799006|6133799003|261009223027099003|18002099003|22082099003|3023799007|10067099003|56012099006|261021123027099003|261021135927099003|261021133027099003|261021130227099003|261028144727099003|261102123227099003|261021121427099003|261022115727099003|261022075727099003|261022113327099003|261022105027099003|261026135527099003|261026121527099003|261026140227099003|261026130827099003; X-Microsoft-Antispam-Message-Info-Original: /FlXQSpnZapK2ygWPXT4VSAze9ajmexQvlnKV7roWUTzIAWj/zFY4+3qSj7Nek5TU08wGwA3l9Ak0TCOlNho7u57fWYEkAemGD+G/koCCqXR++z1bDPt2sI7Fj1r7TDnFmfryYhCV3dHQJi2AUnVhRBOMdYeAnhyp7A2qJ4vdg2K2o6ppB6mt2hI+tWGc9u/Wuw3K3ykwoa9ELHpm6SzP3K7i1n0zri4dYNDlde+YFLIdiJ6vKCcC0F7sn8sEShfQL8bH9HWctFKkCGJpQ/7GXPCIfSv7jHHao2HJLaFN4wGg9quVLquh4c6uqy8dGVmOmoj5AzU4GgJYpAGaAqSRlNr3CYFH3xVYsjAp+gFEbj8wCBTdtMaZtnyqWjm2D9YfORn4dLcvEKrpisXZ040c1ixgOegH4dBeXc5g9xkypMbk/VhM3tUHqHSe4BFTTw24bOYmp/cqahQzT7xXrdq/5QXW/QzzSGrAjq6iIKlllKy8LYUuKqpM4ArULUomxsWRREZwBHSbV2SncuJ2BgzHaz4iZdkL2XcyUQ0tKR9cYvVIF5zZ4sbLBYpzfN1rSdbYERSiuqRZnEa81esWBkFkzjHkoYiigMVKzIeq7Jtt18kfuu0PMffi5pf/BFEeQuo2l/jIlukqJyuGlyJtnSA6QaKtmKZZo1PemP2d0kI9tEKKWFYq/naHlIgRF5BwuAuA1JkBIg9w7MIUTw/UPPu3w== X-Forefront-Antispam-Report-Untrusted: CIP:20.79.222.204;CTRY:DE;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:de2-emailsignatures-cloud.codetwo.com;PTR:de2-emailsignatures-cloud.codetwo.com;CAT:NONE;SFS:(13230040)(14060799003)(23010399003)(82310400026)(36860700016)(35042699022)(1800799024)(376014)(11063799006)(6133799003)(261009223027099003)(18002099003)(22082099003)(3023799007)(10067099003)(56012099006)(261021123027099003)(261021135927099003)(261021133027099003)(261021130227099003)(261028144727099003)(261102123227099003)(261021121427099003)(261022115727099003)(261022075727099003)(261022113327099003)(261022105027099003)(261026135527099003)(261026121527099003)(261026140227099003)(261026130827099003);DIR:OUT;SFP:1102; X-MS-Exchange-Transport-CrossTenantHeadersStamped: ZR3P278MB022095 X-SEPP-CCCVersion: 2026-11-17T09:39:28+01:00 93ee4c03 X-MS-Exchange-SkipListedInternetSender: ip=[40.93.86.0];domain=GVAP278CU002.outbound.protection.outlook.com X-MS-Exchange-ExternalOriginalInternetSender: ip=[40.93.86.0];domain=GVAP278CU002.outbound.protection.outlook.com X-MS-Exchange-Transport-CrossTenantHeadersStripped: MI3PEPF0000848D.eurprd03.prod.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: ea94e24b-c845-4949-a3db-08df4fc18d3b X-SM-ruleversion: 2.1.0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|82310400026|36860700016|10070799003|35042699022|23010399003|1800799024|11063799006|6133799003|261009223027099003|22082099003|18002099003|3023799007|10067099003|261026130827099003|5063699009|56012099006|261021133027099003|261026135527099003|261028144727099003|261026121527099003|261026140227099003|261021121427099003|261021135927099003|261022075727099003|261022115727099003|261102123227099003|261022105027099003|261021130227099003|261021123027099003|261022113327099003; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?RirCWlwZwx/zb716n+qGDzhKhywkmoWyfWPO6D97s1TFfPgUyyGA2BdoZ7Ev?= =?us-ascii?Q?Rv35iRh7AeArp+NRzyAHrkHl3xYYKmLQBUyefpRg4MvyakGe5l4ZpuZh6Uxx?= =?us-ascii?Q?DKrw4keC6RSs78Ye41WxPXcAqwNSxQ83bUhzhr9xrmr8CRoLBMunRxwNqIm2?= =?us-ascii?Q?ZdhGBPf+dejg2a/NXRV7cpqSX78yYZHa3WvVfxjLcRhzbY9SztocFCVjyhOg?= =?us-ascii?Q?4GhJ5jVPZPtF1Da+G8nuSNREjDd8i0ttN31p3NJVSMSxckQF7BfONYobnZr3?= =?us-ascii?Q?7BcPy9rYeFSHrtlQKxrBemDTviH47Rb9j0289qfACT+UInyQPntb/wgJHm8+?= =?us-ascii?Q?2UYaB+CZo6FO1EKETHXJBi620D90nNfaWCPhrkOwVw4KcFIPekJ+LUY0MWh1?= =?us-ascii?Q?a2q5BwW44FOlrcTY1LwKixCxkLBr+A+VqPXjMWW1sQ2nPp8/RRmlAkLMgHO1?= =?us-ascii?Q?kjXPkYG7VsOb+7QErXJfUfX2ryL1rT5pUtCgUCRIOocGeRbj9vw3jLpvX6bB?= =?us-ascii?Q?WsibDbwVsXw1iBu/VPpaSJircjmFmQC1x1xi1q6bZ1ooCCqLusY8bSz/W/rS?= =?us-ascii?Q?g9ckz4c74yHYrxRCIEyu04fr8JPxjBBkRdlFWKIlpbiMpIcxw3HL5+G4UhD+?= =?us-ascii?Q?4vlrn2PgH5DW90SQ63OOD+bL9Q3Yzz2XaMKGZeKK23bK6Dc/OToEXTa8ovIV?= =?us-ascii?Q?4p6u3CwU6P+4GBAfOUr6BAv2gZtekFljbXB9qyYPfnkVk229tl5BnwFgrtiq?= =?us-ascii?Q?gxCkeBq5IrjGUHBd9SdPMRHA1IfXv7hOfgJRYkNdCwqi9IHYUaHAyIoEsFji?= =?us-ascii?Q?Hjypc3dzN3EjzhNy8IegOdZJxKBWqYaCEdXh7rQhWzprBLy3r8sFGQydnMdV?= =?us-ascii?Q?wVhcyo/uTXfN5V9ePjEMVORH5i7P/wATDUUU5lvb+Vy8lk9Ff6irnwtbiN67?= =?us-ascii?Q?A2698yletQWO8dkKFDHjcFuhxP8sPr059xYAhIo3P1I=3D?= X-Forefront-Antispam-Report: CIP:2a04:d480:4400:11:f816:3eff:fe57:da56;CTRY:CH;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:GVAP278CU002.outbound.protection.outlook.com;PTR:mail-switzerlandwestazlp17010000.outbound.protection.outlook.com;CAT:NONE;SFS:(13230040)(376014)(82310400026)(36860700016)(10070799003)(35042699022)(23010399003)(1800799024)(11063799006)(6133799003)(261009223027099003)(22082099003)(18002099003)(3023799007)(10067099003)(261026130827099003)(5063699009)(56012099006)(261021133027099003)(261026135527099003)(261028144727099003)(261026121527099003)(261026140227099003)(261021121427099003)(261021135927099003)(261022075727099003)(261022115727099003)(261102123227099003)(261022105027099003)(261021130227099003)(261021123027099003)(261022113327099003);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Xkiybtk2jcsZiDpN+aFepKcMzgaVKENk5bqi0fKnv+zsrgf8VT6Z0/n1sXtxRjgWi/hHlMvFW9b8f7bjhkTMFKs2DoUTiQ9wHOkuFENSd7UREvfNOpVrg8DRSlENpBgw5t58dHny79C+Hq9XiZCV34dVIhOZsbUOn+fhQPPA525MgWWzdZTSLL5vVqHi9WyXTm5FWismvCeX3S4KH9/FXU2eeiiGtNMcLPu+3X8xB82v8jlpuBOuM8etCWSOJSx0R20vNUJhsWimHZABPETSrMweeTd6c9lNuFU5EeyozAxKSBsC6dkBB0LxZzdRt1H3D0gjNOm3V0F+WIXL95snI86w2cRhnYtITc/ILEdj/nhdPcG/EbTU2kOuzts9VfYSrtnbji2SSARCaY3S+Y2kRvaDz3Y+qkL3JHdqf7VkTc+wG6/6Zdn86w34ORA/dfV3 X-OriginatorOrg: duagon.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Dec 2026 15:41:31.8120 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 96d3428b-a037-4ad2-681a-08df4fc192bc X-MS-Exchange-CrossTenant-Id: e5e7e96e-8a28-45d6-9093-a40dd5b51a57 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=e5e7e96e-8a28-45d6-9093-a40dd5b51a57;Ip=[2a04:d480:4400:11:f816:3eff:fe57:da56];Helo=[sy-deliver01.de.seppmail.cloud] X-MS-Exchange-CrossTenant-AuthSource: MI3PEPF0000848D.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: ZR4P278MB548269 Add support for 16Z087 Ethernet core on MCB devices. The MAC is based on the OpenCores design and connects to the PHY over MII. It supports 10/100 Mbps operation and half/full duplex with link management handled by phylib. Reviewed-by: Filip Jensen Signed-off-by: Jose Javier Rodriguez Barbarin --- MAINTAINERS | 9 + drivers/net/ethernet/men/Kconfig | 33 + drivers/net/ethernet/men/Makefile | 5 + drivers/net/ethernet/men/z87/Makefile | 7 + .../net/ethernet/men/z87/men_z87_ethtool.c | 63 + drivers/net/ethernet/men/z87/men_z87_hw.h | 227 +++ drivers/net/ethernet/men/z87/men_z87_i2c.c | 240 +++ drivers/net/ethernet/men/z87/men_z87_i2c.h | 17 + drivers/net/ethernet/men/z87/men_z87_main.c | 1539 +++++++++++++++++ drivers/net/ethernet/men/z87/men_z87_main.h | 133 ++ drivers/net/ethernet/men/z87/men_z87_phy.c | 673 +++++++ drivers/net/ethernet/men/z87/men_z87_phy.h | 27 + drivers/net/ethernet/men/z87/men_z87_regs.h | 98 ++ 13 files changed, 3071 insertions(+) create mode 100644 drivers/net/ethernet/men/Kconfig create mode 100644 drivers/net/ethernet/men/Makefile create mode 100644 drivers/net/ethernet/men/z87/Makefile create mode 100644 drivers/net/ethernet/men/z87/men_z87_ethtool.c create mode 100644 drivers/net/ethernet/men/z87/men_z87_hw.h create mode 100644 drivers/net/ethernet/men/z87/men_z87_i2c.c create mode 100644 drivers/net/ethernet/men/z87/men_z87_i2c.h create mode 100644 drivers/net/ethernet/men/z87/men_z87_main.c create mode 100644 drivers/net/ethernet/men/z87/men_z87_main.h create mode 100644 drivers/net/ethernet/men/z87/men_z87_phy.c create mode 100644 drivers/net/ethernet/men/z87/men_z87_phy.h create mode 100644 drivers/net/ethernet/men/z87/men_z87_regs.h diff --git a/MAINTAINERS b/MAINTAINERS index 9336fa93ce38..8ca64c2670dc 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -18070,6 +18070,15 @@ L: linux-watchdog@vger.kernel.org S: Maintained F: drivers/watchdog/menz69_wdt.c =20 +MEN Z087 ETHERNET ADAPTER DRIVER +M: Jose Javier Rodriguez Barbarin +R: Filip Jensen +L: netdev@vger.kernel.org +S: Maintained +F: drivers/net/ethernet/men/Kconfig +F: drivers/net/ethernet/men/Makefile +F: drivers/net/ethernet/men/z87/* + MESON AO CEC DRIVER FOR AMLOGIC SOCS M: Neil Armstrong L: linux-media@vger.kernel.org diff --git a/drivers/net/ethernet/men/Kconfig b/drivers/net/ethernet/men/Kc= onfig new file mode 100644 index 000000000000..34579c86e772 --- /dev/null +++ b/drivers/net/ethernet/men/Kconfig @@ -0,0 +1,33 @@ +# +# MEN MCB network device configuration +# + +config NET_VENDOR_MEN + bool "MEN MCB ethernet devices" + depends on I2C && MCB + help + If you have a network (Ethernet) chipset belonging to this class, + say Y. + + Note that the answer to this question does not directly affect + the kernel: saying N will just cause the configurator to skip all + the questions regarding MEN ip cores. If you say Y, you will be asked + for your specific ip core/driver in the following questions. + +if NET_VENDOR_MEN + +config NET_MEN_Z087 + tristate "Z087 ethernet devices" + depends on I2C + depends on MCB + select PHYLIB + select MII + select I2C_ALGOBIT + help + If you have a Z087 ethernet network (Ethernet) card, + answer Y here. + + To compile this driver as a module, choose M here. The module + will be called men_z87_eth. + +endif #NET_VENDOR_MEN diff --git a/drivers/net/ethernet/men/Makefile b/drivers/net/ethernet/men/M= akefile new file mode 100644 index 000000000000..b9dd16a1d9c6 --- /dev/null +++ b/drivers/net/ethernet/men/Makefile @@ -0,0 +1,5 @@ +# +# Makefile for the MEN MCB network device drivers. +# + +obj-$(CONFIG_NET_MEN_Z087) +=3D z87/ diff --git a/drivers/net/ethernet/men/z87/Makefile b/drivers/net/ethernet/m= en/z87/Makefile new file mode 100644 index 000000000000..d10fe4f6508e --- /dev/null +++ b/drivers/net/ethernet/men/z87/Makefile @@ -0,0 +1,7 @@ +# +# Makefile for the MEN Z087 network device driver. +# + +obj-$(CONFIG_NET_MEN_Z087) +=3D men_z87_eth.o + +men_z87_eth-y :=3D men_z87_phy.o men_z87_ethtool.o men_z87_i2c.o men_z87_m= ain.o diff --git a/drivers/net/ethernet/men/z87/men_z87_ethtool.c b/drivers/net/e= thernet/men/z87/men_z87_ethtool.c new file mode 100644 index 000000000000..32598960db84 --- /dev/null +++ b/drivers/net/ethernet/men/z87/men_z87_ethtool.c @@ -0,0 +1,63 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2026 duagon Germany GmbH + * + * See MAINTAINERS file for support contact information. + */ + +#include + +#include "men_z87_main.h" + +#define Z87_DEF_MSG_ENABLE \ + (NETIF_MSG_DRV | \ + NETIF_MSG_PROBE | \ + NETIF_MSG_LINK | \ + NETIF_MSG_TIMER | \ + NETIF_MSG_IFDOWN | \ + NETIF_MSG_IFUP | \ + NETIF_MSG_RX_ERR | \ + NETIF_MSG_TX_ERR) + +static void z87_ethtool_get_drvinfo(struct net_device *dev, + struct ethtool_drvinfo *info) +{ + struct z87_private *np =3D netdev_priv(dev); + unsigned long flags; + + raw_spin_lock_irqsave(&np->lock, flags); + + strscpy(info->driver, np->model_name, sizeof(info->driver)); + strscpy(info->bus_info, dev_name(&dev->dev), sizeof(info->bus_info)); + + raw_spin_unlock_irqrestore(&np->lock, flags); +} + +static u32 z87_ethtool_get_msglevel(struct net_device *dev) +{ + struct z87_private *np =3D netdev_priv(dev); + + return READ_ONCE(np->msg_enable); +} + +static void z87_ethtool_set_msglevel(struct net_device *dev, u32 v) +{ + struct z87_private *np =3D netdev_priv(dev); + + WRITE_ONCE(np->msg_enable, v); +} + +static const struct ethtool_ops men_z87_ethtool_ops =3D { + .get_drvinfo =3D z87_ethtool_get_drvinfo, + .get_link_ksettings =3D phy_ethtool_get_link_ksettings, + .set_link_ksettings =3D phy_ethtool_set_link_ksettings, + .nway_reset =3D phy_ethtool_nway_reset, + .get_link =3D ethtool_op_get_link, + .get_msglevel =3D z87_ethtool_get_msglevel, + .set_msglevel =3D z87_ethtool_set_msglevel, +}; + +const struct ethtool_ops *z87_get_ethtool_ops(void) +{ + return &men_z87_ethtool_ops; +} diff --git a/drivers/net/ethernet/men/z87/men_z87_hw.h b/drivers/net/ethern= et/men/z87/men_z87_hw.h new file mode 100644 index 000000000000..120db08d07e2 --- /dev/null +++ b/drivers/net/ethernet/men/z87/men_z87_hw.h @@ -0,0 +1,227 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Copyright (c) 2026 duagon Germany GmbH + * + * See MAINTAINERS file for support contact information. + */ + +#ifndef _MEN_Z87_HW_H_ +#define _MEN_Z87_HW_H_ + +#include +#include +#include + +#include "men_z87_regs.h" +#include "men_z87_main.h" + +#define Z087_TBD_FLAGS_MASK GENMASK(15, 0) +#define Z087_TBD_LEN_MASK GENMASK(31, 16) +#define Z087_TBD_LEN_SHIFT 16 + +static inline u32 z87_mmio_read32(unsigned long base, u32 reg) +{ + return readl((void __iomem *)(base + reg)); +} + +static inline void z87_mmio_write32(unsigned long base, u32 reg, u32 val) +{ + writel(val, (void __iomem *)(base + reg)); +} + +static inline u32 z87_read32(const struct net_device *dev, u32 reg) +{ + return z87_mmio_read32(dev->base_addr, reg); +} + +static inline void z87_write32(const struct net_device *dev, u32 reg, u32 = val) +{ + z87_mmio_write32(dev->base_addr, reg, val); +} + +static inline void z87_set_mode_flags(const struct net_device *dev, u32 fl= ags) +{ + z87_write32(dev, Z087_REG_MODER, + z87_read32(dev, Z087_REG_MODER) | flags); +} + +static inline void z87_clear_mode_flags(const struct net_device *dev, u32 = flags) +{ + z87_write32(dev, Z087_REG_MODER, + z87_read32(dev, Z087_REG_MODER) & ~flags); +} + +static inline void z87_enable_irqs(const struct net_device *dev, u32 mask) +{ + z87_write32(dev, Z087_REG_INT_MASK, + z87_read32(dev, Z087_REG_INT_MASK) | mask); +} + +static inline void z87_disable_irqs(const struct net_device *dev, u32 mask= ) +{ + z87_write32(dev, Z087_REG_INT_MASK, + z87_read32(dev, Z087_REG_INT_MASK) & ~mask); +} + +/* Generic BD accessors */ + +static inline void z87_bd_set_addr(const struct z87_private *np, struct z8= 7_desc *desc, u32 addr) +{ + WRITE_ONCE(desc->addr, cpu_to_le32(addr)); + /* ensure DMA ordering */ + dma_wmb(); +} + +static inline u32 z87_bd_get_addr(const struct z87_private *np, struct z87= _desc *desc) +{ + return le32_to_cpu(READ_ONCE(desc->addr)); +} + +static inline void z87_bd_set_flags(const struct z87_private *np, struct z= 87_desc *desc, u16 f) +{ + u32 flags =3D le32_to_cpu(READ_ONCE(desc->flags)); + + flags |=3D FIELD_PREP(Z087_TBD_FLAGS_MASK, f); + + WRITE_ONCE(desc->flags, cpu_to_le32(flags)); + /* ensure DMA ordering */ + dma_wmb(); +} + +static inline u16 z87_bd_get_flags(const struct z87_private *np, struct z8= 7_desc *desc, u16 f) +{ + u32 flags =3D le32_to_cpu(READ_ONCE(desc->flags)); + + return FIELD_GET(Z087_TBD_FLAGS_MASK, flags) & f; +} + +static inline void z87_bd_clear_flags(const struct z87_private *np, struct= z87_desc *desc, u16 f) +{ + u32 flags =3D le32_to_cpu(READ_ONCE(desc->flags)); + + flags &=3D ~FIELD_PREP(Z087_TBD_FLAGS_MASK, f); + + WRITE_ONCE(desc->flags, cpu_to_le32(flags)); + /* ensure DMA ordering */ + dma_wmb(); +} + +static inline void z87_bd_set_len(const struct z87_private *np, struct z87= _desc *desc, u16 l) +{ + u32 len =3D le32_to_cpu(READ_ONCE(desc->flags)); + + len &=3D ~Z087_TBD_LEN_MASK; + len |=3D FIELD_PREP(Z087_TBD_LEN_MASK, l); + + WRITE_ONCE(desc->flags, cpu_to_le32(len)); + /* ensure DMA ordering */ + dma_wmb(); +} + +static inline u16 z87_bd_get_len(const struct z87_private *np, struct z87_= desc *desc) +{ + u32 len =3D le32_to_cpu(READ_ONCE(desc->flags)); + + return FIELD_GET(Z087_TBD_LEN_MASK, len); +} + +static inline void z87_bd_clear_len(const struct z87_private *np, struct z= 87_desc *desc) +{ + u32 len =3D le32_to_cpu(READ_ONCE(desc->flags)); + + len &=3D ~Z087_TBD_LEN_MASK; + + WRITE_ONCE(desc->flags, cpu_to_le32(len)); + /* ensure DMA ordering */ + dma_wmb(); +} + +/* BD offset helpers */ +static inline struct z87_desc *z87_tbd_base(const struct z87_private *np, = u32 n) +{ + return np->tx_desc + n; +} + +static inline struct z87_desc *z87_rbd_base(const struct z87_private *np, = u32 n) +{ + return np->rx_desc + n; +} + +/* TBD accessors */ +static inline void z87_tbd_set_addr(const struct z87_private *np, u32 n, u= 32 addr) +{ + z87_bd_set_addr(np, z87_tbd_base(np, n), addr); +} + +static inline u32 z87_tbd_get_addr(const struct z87_private *np, u32 n) +{ + return z87_bd_get_addr(np, z87_tbd_base(np, n)); +} + +static inline void z87_tbd_set_flags(const struct z87_private *np, u32 n, = u16 f) +{ + z87_bd_set_flags(np, z87_tbd_base(np, n), f); +} + +static inline void z87_tbd_clear_flags(const struct z87_private *np, u32 n= , u16 f) +{ + z87_bd_clear_flags(np, z87_tbd_base(np, n), f); +} + +static inline u16 z87_tbd_get_flags(const struct z87_private *np, u32 n, u= 16 f) +{ + return z87_bd_get_flags(np, z87_tbd_base(np, n), f); +} + +static inline void z87_tbd_set_len(const struct z87_private *np, u32 n, u1= 6 l) +{ + z87_bd_set_len(np, z87_tbd_base(np, n), l); +} + +static inline u16 z87_tbd_get_len(const struct z87_private *np, u32 n) +{ + return z87_bd_get_len(np, z87_tbd_base(np, n)); +} + +/* RBD accessors */ +static inline void z87_rbd_set_addr(const struct z87_private *np, u32 n, u= 32 addr) +{ + z87_bd_set_addr(np, z87_rbd_base(np, n), addr); +} + +static inline u32 z87_rbd_get_addr(const struct z87_private *np, u32 n) +{ + return z87_bd_get_addr(np, z87_rbd_base(np, n)); +} + +static inline void z87_rbd_set_flags(const struct z87_private *np, u32 n, = u16 f) +{ + z87_bd_set_flags(np, z87_rbd_base(np, n), f); +} + +static inline void z87_rbd_clear_flags(const struct z87_private *np, u32 n= , u16 f) +{ + z87_bd_clear_flags(np, z87_rbd_base(np, n), f); +} + +static inline u16 z87_rbd_get_flags(const struct z87_private *np, u32 n, u= 16 f) +{ + return z87_bd_get_flags(np, z87_rbd_base(np, n), f); +} + +static inline u16 z87_rbd_get_len(const struct z87_private *np, u32 n) +{ + return z87_bd_get_len(np, z87_rbd_base(np, n)); +} + +static inline void z87_rbd_clear_len(const struct z87_private *np, u32 n) +{ + z87_bd_set_len(np, z87_rbd_base(np, n), 0); +} + +static inline bool z87_rbd_is_empty(const struct z87_private *np, u32 n) +{ + return z87_rbd_get_flags(np, n, OETH_RX_BD_EMPTY) !=3D 0; +} + +#endif /* _MEN_Z87_HW_H_ */ diff --git a/drivers/net/ethernet/men/z87/men_z87_i2c.c b/drivers/net/ether= net/men/z87/men_z87_i2c.c new file mode 100644 index 000000000000..1604553f295e --- /dev/null +++ b/drivers/net/ethernet/men/z87/men_z87_i2c.c @@ -0,0 +1,240 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2026 duagon Germany GmbH + * + * See MAINTAINERS file for support contact information. + */ + +#include +#include +#include + +#include "men_z87_main.h" +#include "men_z87_hw.h" +#include "men_z87_i2c.h" + +#define BRDID_EE_I2C_ADDR 0x57 /* CPU EEPROM I2C address */ +#define BRDID_EE_NAME_OFFSET 9 /* board name offset in ID EEPROM */ +#define BRDID_EE_MAC_OFFSET 0x90 /* begin of MAC(s) in Board ID EEPROM */ +#define MAC_EE_MAGIC_NUM 0xB0 /* MAC EEPROM MAGIC number */ +#define MAC_EE_BUF_SIZE 7 /* MAC EEPROM buffer size (6 + 1 for MAGIC Numb= er) */ +#define MAC_EE_I2C_ADDR 0x50 /* Device MAC EEPROM I2C address */ +#define MAC_EE_ADDR_OFFSET 0x00 /* Device MAC EEPROM I2C address offset */ +#define MAC_ADDR_SIZE 6 /* MAC address size (in bytes) */ +#define ID_EE_NAME_LEN 6 /* length of name in ID EEPROM */ + +#define SMB_REG_SCL 0x01 +#define SMB_REG_SDA 0x02 +#define MAC_EE_LEGACY_PARITY 0x00 + +static void z87_set_sda(void *i2c_priv, int pinval) +{ + struct z87_i2c *i2c =3D i2c_priv; + unsigned int tmp; + + tmp =3D z87_mmio_read32(i2c->base_addr, Z087_REG_SMBCTRL); + + if (pinval) + tmp |=3D SMB_REG_SDA; + else + tmp &=3D ~SMB_REG_SDA; + + z87_mmio_write32(i2c->base_addr, Z087_REG_SMBCTRL, tmp); +} + +static int z87_get_sda(void *i2c_priv) +{ + struct z87_i2c *i2c =3D i2c_priv; + unsigned int tmp =3D 0; + + /* Read SDA */ + tmp =3D z87_mmio_read32(i2c->base_addr, Z087_REG_SMBCTRL); + + return (tmp & SMB_REG_SDA) ? 1 : 0; +} + +static void z87_set_scl(void *i2c_priv, int pinval) +{ + struct z87_i2c *i2c =3D i2c_priv; + unsigned int tmp; + + tmp =3D z87_mmio_read32(i2c->base_addr, Z087_REG_SMBCTRL); + + if (pinval) + tmp |=3D SMB_REG_SCL; + else + tmp &=3D ~SMB_REG_SCL; + + z87_mmio_write32(i2c->base_addr, Z087_REG_SMBCTRL, tmp); + + /** + * Seems to be a bug on certain hardware while trying to read + * the byte on i2c_inb() placed on i2c_algo_bit.c + * + * The solution found on other driver also works here and + * consists on moving SDA line to high after the transition + * of SCL from high to low immediately. This only happens during + * the bit reading cycle. + * + * The workaround: + * drivers/media/pci/pluto2/pluto2.c#L171 + */ + if (pinval && i2c->i2c_bug =3D=3D 0) { + i2c->i2c_bug =3D 1; + } else { + if (!pinval && i2c->i2c_bug =3D=3D 1) + z87_set_sda(i2c, 1); + + i2c->i2c_bug =3D 0; + } +} + +static int z87_get_scl(void *i2c_priv) +{ + struct z87_i2c *i2c =3D i2c_priv; + unsigned int tmp =3D 0; + + /* Read SCL */ + tmp =3D z87_mmio_read32(i2c->base_addr, Z087_REG_SMBCTRL); + + return (tmp & SMB_REG_SCL) ? 1 : 0; +} + +static u8 z87_calc_mac_parity(u8 *ptr) +{ + u32 len =3D ETH_ALEN; + u8 parity =3D 0xF; + + while (len--) { + parity ^=3D (*ptr >> 4); + parity ^=3D (*ptr & 0xf); + ptr++; + } + + return parity; +} + +struct z87_i2c *z87_i2c_alloc(struct device *dev, unsigned long addr) +{ + struct z87_i2c *i2c; + int ret; + + i2c =3D kzalloc_obj(struct z87_i2c); + + if (!i2c) + return ERR_PTR(-ENOMEM); + + // Initialize z87_i2c stuff + i2c->base_addr =3D addr; + i2c->i2c_bug =3D 0; + + // Prepare i2c adapter + i2c->adapter.owner =3D THIS_MODULE; + i2c->adapter.dev.parent =3D dev; + i2c->adapter.algo_data =3D &i2c->algo_bit; + snprintf(i2c->adapter.name, sizeof(i2c->adapter.name), + "I2C adapter at %s", dev_name(dev)); + + // Prepare i2c bit-banging functions, parameters and private data. + i2c->algo_bit.setsda =3D z87_set_sda; + i2c->algo_bit.setscl =3D z87_set_scl; + i2c->algo_bit.getsda =3D z87_get_sda; + i2c->algo_bit.getscl =3D z87_get_scl; + i2c->algo_bit.udelay =3D 10; /* Recommended for SMBus */ + i2c->algo_bit.timeout =3D usecs_to_jiffies(1000); + i2c->algo_bit.data =3D i2c; + + i2c_set_adapdata(&i2c->adapter, i2c); + + ret =3D i2c_bit_add_bus(&i2c->adapter); + if (ret < 0) { + dev_err(dev, "unable to create i2c adapter error: %d\n", ret); + goto end_free; + } + + dev_info(dev, "I2C initialized OK. Nr: %d name: %s", i2c->adapter.nr, i2c= ->adapter.name); + + return i2c; + +end_free: + kfree(i2c); + return ERR_PTR(ret); +} + +void z87_i2c_free(struct z87_i2c *priv_data) +{ + struct z87_i2c *i2c =3D priv_data; + + i2c_del_adapter(&i2c->adapter); + kfree(i2c); +} + +int z87_i2c_load_mac_from_eeprom(struct z87_i2c *i2c, u8 *mac) +{ + u8 msgbuf[MAC_EE_BUF_SIZE] =3D {0}; + bool legacy_parity =3D false; + struct i2c_msg i2cmes[2]; + u8 parity; + int res; + + if (!i2c || !mac) + return -EINVAL; + + msgbuf[0] =3D MAC_EE_ADDR_OFFSET; + + // Write offset in the EEPROM + i2cmes[0].addr =3D MAC_EE_I2C_ADDR; + i2cmes[0].buf =3D msgbuf; + i2cmes[0].flags =3D 0; + i2cmes[0].len =3D 1; + + // Read magic/parity + 6 Byte MAC + i2cmes[1].addr =3D MAC_EE_I2C_ADDR; + i2cmes[1].buf =3D msgbuf; + i2cmes[1].flags =3D I2C_M_RD; + i2cmes[1].len =3D MAC_EE_BUF_SIZE; + + res =3D i2c_transfer(&i2c->adapter, i2cmes, ARRAY_SIZE(i2cmes)); + if (res !=3D ARRAY_SIZE(i2cmes)) { + dev_err(&i2c->adapter.dev, + "unable to load MAC address from EEPROM. result: %d\n", res); + return -EIO; + } + + dev_dbg(&i2c->adapter.dev, + "Read from i2c. Magic [%02x] MAC [%02x:%02x:%02x:%02x:%02x:%02x]\n", + msgbuf[0], msgbuf[1], msgbuf[2], msgbuf[3], msgbuf[4], msgbuf[5], msgbuf= [6]); + + /* + * Check the data read is actually the MAC. + * So check in offset =3D 0 the magic number. + */ + if ((msgbuf[0] & 0xF0) !=3D MAC_EE_MAGIC_NUM) { + dev_err(&i2c->adapter.dev, + "Incorrect magic number. expected: 0x%02X found: 0x%02X", + (msgbuf[0] & 0xF0), MAC_EE_MAGIC_NUM); + return -EINVAL; + } + + parity =3D z87_calc_mac_parity(((u8 *)msgbuf) + 1); + if ((msgbuf[0] & 0x0F) !=3D parity) { + if ((msgbuf[0] & 0x0F) =3D=3D MAC_EE_LEGACY_PARITY) { + legacy_parity =3D true; + } else { + dev_err(&i2c->adapter.dev, + "Incorrect MAC parity. expected: 0x%01x found: 0x%01x\n", + parity, msgbuf[0] & 0x0F); + return -EINVAL; + } + } + + /* Accept legacy parity without rewriting EEPROM; the caller validates th= e MAC. */ + memcpy(mac, ((u8 *)msgbuf) + 1, MAC_ADDR_SIZE); + + dev_info(&i2c->adapter.dev, + "MAC %02x:%02x:%02x:%02x:%02x:%02x read OK from MAC EEPROM. Parity chec= k: %s\n", + mac[0], mac[1], mac[2], mac[3], mac[4], mac[5], + legacy_parity ? "legacy (accepted)" : "OK"); + + return 0; +} diff --git a/drivers/net/ethernet/men/z87/men_z87_i2c.h b/drivers/net/ether= net/men/z87/men_z87_i2c.h new file mode 100644 index 000000000000..691ac3c96f86 --- /dev/null +++ b/drivers/net/ethernet/men/z87/men_z87_i2c.h @@ -0,0 +1,17 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Copyright (c) 2026 duagon Germany GmbH + * + * See MAINTAINERS file for support contact information. + */ + +#ifndef _MEN_Z87_ETH_I2C_ +#define _MEN_Z87_ETH_I2C_ + +#include + +struct z87_i2c *z87_i2c_alloc(struct device *dev, unsigned long addr); +void z87_i2c_free(struct z87_i2c *priv_data); +int z87_i2c_load_mac_from_eeprom(struct z87_i2c *i2c, u8 *mac); + +#endif //_MEN_Z87_ETH_I2C_ diff --git a/drivers/net/ethernet/men/z87/men_z87_main.c b/drivers/net/ethe= rnet/men/z87/men_z87_main.c new file mode 100644 index 000000000000..d6d43e8ec8ab --- /dev/null +++ b/drivers/net/ethernet/men/z87/men_z87_main.c @@ -0,0 +1,1539 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* men_z87_main.c: MEN Z087 ethernet driver. + * + * Copyright (c) 2026 duagon Germany GmbH + * + * See MAINTAINERS file for support contact information. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "men_z87_main.h" +#include "men_z87_hw.h" +#include "men_z87_i2c.h" +#include "men_z87_phy.h" + +/* Typedefs */ +static int z87_open(struct net_device *dev); +static int z87_start_xmit(struct sk_buff *skb, struct net_device *dev); +static irqreturn_t z87_irq(int irq, void *dev_id); +static int z87_close(struct net_device *dev); +static void z87_tx_timeout(struct net_device *dev, unsigned int txqueue); +static int z87_poll(struct napi_struct *napi, int budget); +static void z87_pass_packet(struct napi_struct *napi, unsigned int idx); +static int z87_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd); +static void z87_hash_table_setup(struct net_device *dev); +static int z87_ether_gen_crc(const u8 *data); +static const struct board_config *z87_get_board_config(struct mcb_device *= mdev); +static void z87_load_mac_addr(struct net_device *dev); +static int z87_alloc_rx_bd(struct net_device *dev); +static void z87_free_rx_bd(struct net_device *dev); +static int z87_hw_stop(struct net_device *dev); +static int z87_hw_start(struct net_device *dev); + +/* common driver defines */ +#define MAX_DEVS_PER_BOARD 2 +#define UNDEF 0xff +#define MEN_ETH_ID_Z087 0x57 +#define TX_TIMER_INTERVAL_NSEC 10000 +#define ETH_SA_DA_MAC_HLEN 12 /* combined length or source and dest MAC ad= dr */ +#define Z087_IDLE_POLL_US 10 +#define Z087_IDLE_TIMEOUT_US 10000 + +/* MCAST defines */ +#define MCAST_MULT_SHFT 26 /* bit shift to calculate hash bin */ +#define MCAST_HASH_MASK 0x3f /* pass up only lower 6 bit */ + +/* IRQ defines */ +#define Z087_IRQ_TX (OETH_INT_TXF | OETH_INT_TXE) +#define Z087_IRQ_RX (OETH_INT_RXF | OETH_INT_RXE) +#define Z087_IRQ_ALL (Z087_IRQ_TX | Z087_IRQ_RX) + +struct board_config { + u8 board_id; + char board_name[10]; + u8 num_devs; + u8 dev_phy_mode[MAX_DEVS_PER_BOARD]; + u8 dev_phy_addr[MAX_DEVS_PER_BOARD]; +}; + +/** + * Set of prefixed boards with specific + * configuration of phyadr and mode + */ +static const struct board_config supported_boards[] =3D { + { + .board_id =3D F218, + .board_name =3D "F218", + .num_devs =3D 1, + .dev_phy_mode =3D { phymode_100fd, UNDEF }, + .dev_phy_addr =3D { 0, UNDEF }, + }, + { + .board_id =3D F301, + .board_name =3D "F301", + .num_devs =3D 1, + .dev_phy_mode =3D { phymode_auto, UNDEF }, + .dev_phy_addr =3D { 0, UNDEF }, + }, + { + .board_id =3D F614, + .board_name =3D "F614", + .num_devs =3D 2, + .dev_phy_mode =3D { phymode_auto, phymode_auto }, + .dev_phy_addr =3D { 1, 2 }, + } +}; + +/* + * helper structs for more comfortable dumping of Registers\n + * used to maintain info about the current PHY settings + */ +struct z087_reg_info { + const char *name; /* clear Register name */ + unsigned int addr; /* offset of the Register */ +}; + +/* helper to keep Register descriptions in a comfortable struct */ +static const struct z087_reg_info z87_reginfo[] =3D { + {"MODER ", Z087_REG_MODER }, + {"INT_SRC ", Z087_REG_INT_SRC }, + {"INT_MASK ", Z087_REG_INT_MASK }, + {"PACKLEN ", Z087_REG_PACKLEN }, + {"COLLCONF ", Z087_REG_COLLCONF }, + {"CTRLMODER ", Z087_REG_CTRLMODER }, + {"MIIMODER ", Z087_REG_MIIMODER }, + {"MIICMD ", Z087_REG_MIICMD }, + {"MIIADR ", Z087_REG_MIIADR }, + {"MIITX_DATA", Z087_REG_MIITX_DATA }, + {"MIIRX_DATA", Z087_REG_MIIRX_DATA }, + {"MIISTATUS ", Z087_REG_MIISTATUS }, + {"MAC_ADDR0 ", Z087_REG_MAC_ADDR0 }, + {"MAC_ADDR1 ", Z087_REG_MAC_ADDR1 }, + {"HASH_ADDR0", Z087_REG_HASH_ADDR0 }, + {"HASH_ADDR1", Z087_REG_HASH_ADDR1 }, + {"TXCTRL ", Z087_REG_TXCTRL }, + {"BD_START ", Z087_REG_BDSTART }, + {"RX_EMPTY0 ", Z087_REG_RXEMPTY0 }, + {"RX_EMPTY1 ", Z087_REG_RXEMPTY1 }, + {"TX_EMPTY0 ", Z087_REG_TXEMPTY0 }, + {"TX_EMPTY1 ", Z087_REG_TXEMPTY1 }, + {"RX_BDSTAT ", Z087_REG_RXBDSTAT }, + {"SMBCTRL ", Z087_REG_SMBCTRL }, + {"COREREV ", Z087_REG_COREREV }, + {"RXERRCNT1 ", Z087_REG_RXERRCNT1 }, + {"RXERRCNT2 ", Z087_REG_RXERRCNT2 }, + {"TXERRCNT1 ", Z087_REG_TXERRCNT1 }, + {"TXERRCNT2 ", Z087_REG_TXERRCNT2 }, + {NULL, 0xffff} /* end mark */ +}; + +static void z87_save_mac(struct net_device *dev, const u8 *mac) +{ + z87_write32(dev, Z087_REG_MAC_ADDR0, + mac[2] << 24 | + mac[3] << 16 | + mac[4] << 8 | + mac[5] + ); + + z87_write32(dev, Z087_REG_MAC_ADDR1, mac[0] << 8 | mac[1]); +} + +static void z87_load_mac(struct net_device *dev, u8 *mac) +{ + u32 mac0_reg =3D 0, mac1_reg =3D 0; + + mac0_reg =3D z87_read32(dev, Z087_REG_MAC_ADDR0); + mac1_reg =3D z87_read32(dev, Z087_REG_MAC_ADDR1); + + mac[0] =3D (mac1_reg >> 8) & 0xff; + mac[1] =3D (mac1_reg >> 0) & 0xff; + mac[2] =3D (mac0_reg >> 24) & 0xff; + mac[3] =3D (mac0_reg >> 16) & 0xff; + mac[4] =3D (mac0_reg >> 8) & 0xff; + mac[5] =3D (mac0_reg >> 0) & 0xff; +} + +static void z87_set_rx_mode(struct net_device *dev) +{ + struct z87_private *np =3D netdev_priv(dev); + unsigned long flags; + + raw_spin_lock_irqsave(&np->lock, flags); + + if (dev->flags & IFF_PROMISC) { + if (!(z87_read32(dev, Z087_REG_MODER) & OETH_MODER_PRO)) + z87_set_mode_flags(dev, OETH_MODER_PRO); + } else { + if (z87_read32(dev, Z087_REG_MODER) & OETH_MODER_PRO) + z87_clear_mode_flags(dev, OETH_MODER_PRO); + } + + z87_hash_table_setup(dev); + + raw_spin_unlock_irqrestore(&np->lock, flags); +} + +static int z87_ether_gen_crc(const u8 *data) +{ + u32 crc; + + if (!data) + return -1; + + crc =3D ether_crc(ETH_ALEN, data); + + return (int)((crc >> MCAST_MULT_SHFT) & MCAST_HASH_MASK); +} + +static void z87_hash_table_setup(struct net_device *dev) +{ + struct netdev_hw_addr *ha =3D NULL; + u32 bin_pos =3D 0; + u32 hash0 =3D 0; + u32 hash1 =3D 0; + + if (dev->flags & IFF_ALLMULTI) { + /* Every multicast hash bin must match in all-multicast mode. */ + hash0 =3D 0xffffffff; + hash1 =3D 0xffffffff; + } else { + netdev_for_each_mc_addr(ha, dev) { + bin_pos =3D z87_ether_gen_crc(ha->addr); + + if (bin_pos > 31) + hash1 |=3D BIT(bin_pos - 32); + else + hash0 |=3D BIT(bin_pos); + } + } + + z87_write32(dev, Z087_REG_HASH_ADDR0, hash0); + z87_write32(dev, Z087_REG_HASH_ADDR1, hash1); +} + +static inline int z87_tx_full(struct net_device *dev, int idx) +{ + if (idx < 32) + return ~z87_read32(dev, Z087_REG_TXEMPTY0) & (BIT(idx)); + else + return ~z87_read32(dev, Z087_REG_TXEMPTY1) & (BIT(idx - 32)); +} + +static inline void z87_tx_doorbell(struct net_device *dev, int idx) +{ + if (idx < 32) + z87_write32(dev, Z087_REG_TXEMPTY0, BIT(idx)); + else + z87_write32(dev, Z087_REG_TXEMPTY1, BIT(idx - 32)); +} + +static inline void z87_rx_complete(struct net_device *dev, int idx) +{ + if (idx < 32) + z87_write32(dev, Z087_REG_RXEMPTY0, BIT(idx)); + else + z87_write32(dev, Z087_REG_RXEMPTY1, BIT(idx - 32)); +} + +static int z87_set_mac_address(struct net_device *dev, void *p) +{ + struct sockaddr *addr =3D p; + int res; + + res =3D eth_prepare_mac_addr_change(dev, p); + if (res < 0) { + netdev_err(dev, "Failed to prepare MAC address change\n"); + return res; + } + + z87_save_mac(dev, addr->sa_data); + + eth_commit_mac_addr_change(dev, p); + + return 0; +} + +static int z87_change_mtu(struct net_device *netdev, int new_mtu) +{ + if (new_mtu < ETH_MIN_MTU || new_mtu > ETH_DATA_LEN) + return -EINVAL; + + netdev->mtu =3D new_mtu; + + return 0; +} + +static const struct net_device_ops z87_netdev_ops =3D { + .ndo_open =3D z87_open, + .ndo_stop =3D z87_close, + .ndo_start_xmit =3D z87_start_xmit, + .ndo_eth_ioctl =3D z87_ioctl, + .ndo_tx_timeout =3D z87_tx_timeout, + .ndo_set_rx_mode =3D z87_set_rx_mode, + .ndo_change_mtu =3D z87_change_mtu, + .ndo_validate_addr =3D eth_validate_addr, + .ndo_set_mac_address =3D z87_set_mac_address, + .ndo_get_stats64 =3D dev_get_tstats64, +}; + +static void z87_regdump(struct net_device *dev) +{ + struct z87_private *np =3D netdev_priv(dev); + struct z87_desc tx_desc[Z087_TBD_NUM]; + u32 cur_tx, dty_tx, cur_rx; + unsigned long i =3D 0; + u32 tmp =3D 0; + + /* Snapshot software TX state; hardware may still update descriptors. */ + spin_lock_bh(&np->tx_lock); + cur_tx =3D np->cur_tx; + dty_tx =3D np->dty_tx; + cur_rx =3D READ_ONCE(np->cur_rx); + + spin_unlock_bh(&np->tx_lock); + + netdev_info(dev, "(netdevice '%s') base Addr: 0x%08lx\n", + dev->name, dev->base_addr); + + while (z87_reginfo[i].addr !=3D 0xffff) { + tmp =3D z87_read32(dev, z87_reginfo[i].addr); + netdev_info(dev, "%s 0x%08x\n", z87_reginfo[i].name, tmp); + i++; + } + + z87_phy_regdump(dev); + + netdev_info(dev, "cur_tx 0x%02x, dty_tx 0x%02x, cur_rx 0x%02x\n", + cur_tx, dty_tx, cur_rx); + + if (READ_ONCE(np->msg_enable) > 0) { + netdev_info(dev, + "------------------ TX BDs: -------------------\n"); + for (i =3D 0; i < Z087_TBD_NUM; i++) { + tx_desc[i].flags =3D READ_ONCE(np->tx_desc[i].flags); + tx_desc[i].addr =3D READ_ONCE(np->tx_desc[i].addr); + + netdev_info(dev, + "%02lx STAT: 0x%04x LEN: 0x%04x ADR 0x%08x\n", + i, + z87_bd_get_flags(np, &tx_desc[i], 0xffff), + z87_bd_get_len(np, &tx_desc[i]), + z87_bd_get_addr(np, &tx_desc[i])); + } + + netdev_info(dev, + "------------------ RX BDs: -------------------\n"); + for (i =3D 0; i < Z087_RBD_NUM; i++) { + netdev_info(dev, + "%02lx STAT: 0x%04x LEN: 0x%04x ADR 0x%08x\n", + i, + z87_rbd_get_flags(np, i, 0xffff), + z87_rbd_get_len(np, i), + z87_rbd_get_addr(np, i)); + } + } +} + +static int z87_alloc_rx_bd(struct net_device *dev) +{ + struct z87_private *np =3D netdev_priv(dev); + u32 i =3D 0, failed_idx =3D 0; + dma_addr_t mem_hw_dma =3D 0; + void *mem_virt_dma =3D NULL; + + /* Setup Receive BDs */ + for (i =3D 0; i < Z087_RBD_NUM; i++) { + mem_virt_dma =3D dma_alloc_coherent(np->dma_dev, Z087_ETHBUF_SIZE, + &mem_hw_dma, GFP_KERNEL); + if (!mem_virt_dma) { + failed_idx =3D i; + netdev_err(dev, "Failed to allocate Rx buffer %d\n", i); + goto free_previous_rx_bd; + } + + np->rx_bd[i].addr =3D mem_virt_dma; + np->rx_bd[i].dma =3D mem_hw_dma; + + z87_rbd_set_addr(np, i, mem_hw_dma); + } + + return 0; + +free_previous_rx_bd: + /* free all previous allocated BDs */ + for (i =3D 0; i < failed_idx; i++) { + if (np->rx_bd[i].addr) { + dma_free_coherent(np->dma_dev, Z087_ETHBUF_SIZE, + (void *)np->rx_bd[i].addr, np->rx_bd[i].dma); + np->rx_bd[i].addr =3D NULL; + np->rx_bd[i].dma =3D 0; + } + } + + return -ENOMEM; +} + +static void z87_free_rx_bd(struct net_device *dev) +{ + struct z87_private *np =3D netdev_priv(dev); + u32 i =3D 0; + + for (i =3D 0; i < Z087_RBD_NUM; i++) { + /* Complete any pending RX for this BD */ + z87_rx_complete(dev, i); + z87_rbd_set_addr(np, i, 0); + if (np->rx_bd[i].addr) { + dma_free_coherent(np->dma_dev, Z087_ETHBUF_SIZE, + (void *)np->rx_bd[i].addr, np->rx_bd[i].dma); + np->rx_bd[i].addr =3D NULL; + np->rx_bd[i].dma =3D 0; + } + } + /* Ensure all previous writes are visible before continuing */ + wmb(); +} + +static int z87_bd_setup(struct net_device *dev) +{ + struct z87_private *np =3D netdev_priv(dev); + int res; + + memset((char *)np->bd_base, 0x00, Z087_BD_AREA_SIZE); + + /* Alloc Receive BDs */ + res =3D z87_alloc_rx_bd(dev); + if (res < 0) { + netdev_err(dev, "Failed to allocate Rx BDs\n"); + return res; + } + + return 0; +} + +static int z87_dev_register(struct net_device *dev) +{ + struct z87_private *np =3D netdev_priv(dev); + int res; + + /* Tell the stack that the hardware handles the FCS */ + dev->hw_features |=3D NETIF_F_RXFCS; + + /* Tell explicitly the stack not support SG, FRAGLIST, and GSO */ + dev->hw_features &=3D ~(NETIF_F_SG | NETIF_F_FRAGLIST | NETIF_F_GSO_MASK)= ; + dev->vlan_features |=3D dev->hw_features; + dev->features |=3D (dev->hw_features & ~NETIF_F_RXFCS); + + dev->watchdog_timeo =3D WD_TX_TIMEOUT; + + /* Tell the stack the maximum number of segments for TSO */ + netif_set_tso_max_segs(dev, 1); + + res =3D register_netdev(dev); + if (res < 0) + return res; + + netdev_info(dev, + "register %s as %s mode %d phys.addr 0x%08x irq 0x%x\n", + np->model_name, dev->name, np->phy_mode, (u32)np->mem->start, dev->i= rq); + + return 0; +} + +static void z87_reset_task(struct work_struct *work) +{ + struct z87_private *np =3D container_of(work, + struct z87_private, + reset_task); + struct net_device *dev =3D np->dev; + bool queue_stopped, tx_full; + + /* On contention, the next watchdog timeout calls us again */ + if (!rtnl_trylock()) + return; + + if (!netif_running(dev) || !netif_carrier_ok(dev)) + goto unlock; + + spin_lock_bh(&np->tx_lock); + queue_stopped =3D netif_queue_stopped(dev); + tx_full =3D z87_tx_full(dev, np->cur_tx & (Z087_TBD_NUM - 1)); + spin_unlock_bh(&np->tx_lock); + + netdev_info(dev, "%s: NETDEV WATCHDOG timeout! (queue %s, %s)\n", + dev->name, + queue_stopped ? "stopped" : "running", + tx_full ? "full" : "empty"); + + if (READ_ONCE(np->msg_enable)) { + netdev_warn(dev, + "Current register settings before restart:\n"); + + z87_regdump(dev); + } + + if (z87_hw_stop(dev) < 0) { + netdev_err(dev, "Failed to stop hardware safely, aborting restart\n"); + netif_carrier_off(dev); + goto unlock; + } + if (z87_hw_start(dev) < 0) { + netdev_err(dev, "Failed to restart hardware after watchdog timeout\n"); + netif_carrier_off(dev); + goto unlock; + } + + spin_lock_bh(&np->tx_lock); + DEV_STATS_INC(dev, tx_errors); + spin_unlock_bh(&np->tx_lock); + + if (netif_queue_stopped(dev)) + netif_wake_queue(dev); + +unlock: + rtnl_unlock(); +} + +static void z87_tx_timeout(struct net_device *dev, unsigned int txqueue) +{ + struct z87_private *np =3D netdev_priv(dev); + + schedule_work(&np->reset_task); +} + +static inline bool z87_rx_bd_is_full(u32 rx0, u32 rx1, unsigned int pos) +{ + return (pos < 32) ? !!(rx0 & BIT(pos)) : !!(rx1 & BIT(pos - 32)); +} + +static inline int z87_next_bd(int pos, int width) +{ + return (pos + 1) % width; +} + +static int z87_process_rx(struct napi_struct *napi, int weight) +{ + struct z87_private *np =3D container_of(napi, struct z87_private, napi); + u32 cur_rx =3D READ_ONCE(np->cur_rx); + struct net_device *dev =3D np->dev; + unsigned int rx0, rx1; + int i, frames =3D 0; + u64 rx_reg; + + rx0 =3D z87_read32(dev, Z087_REG_RXEMPTY0); + rx1 =3D z87_read32(dev, Z087_REG_RXEMPTY1); + rx_reg =3D ((u64)rx1 << 32) | rx0; + + if (rx_reg & BIT_ULL(cur_rx)) + return 0; + + for (i =3D 0; i < weight; i++) { + z87_pass_packet(napi, cur_rx); + frames++; + + cur_rx =3D z87_next_bd(cur_rx, Z087_RBD_NUM); + WRITE_ONCE(np->cur_rx, cur_rx); + + /* are we done ? */ + if (rx_reg & BIT_ULL(cur_rx)) + break; + } + + return frames; +} + +static void z87_tx_bd_errors(struct net_device *dev, int idx) +{ + const u16 tx_err_mask =3D OETH_TX_BD_DEFER | OETH_TX_BD_CARRIER | + OETH_TX_BD_UNDERRUN | OETH_TX_BD_RETLIM | + OETH_TX_BD_LATECOL | OETH_TX_BD_RETRY; + struct z87_private *np =3D netdev_priv(dev); + u16 tx_bd_flags; + + tx_bd_flags =3D z87_tbd_get_flags(np, idx, tx_err_mask); + if (!tx_bd_flags) + return; + + if (tx_bd_flags & OETH_TX_BD_DEFER) + netdev_warn(dev, "*** TX: defered frame[%d]\n", idx); + + if (tx_bd_flags & OETH_TX_BD_CARRIER) { + netdev_warn(dev, "*** TX: Carrier lost[%d]\n", idx); + DEV_STATS_INC(dev, tx_carrier_errors); + } + + if (tx_bd_flags & OETH_TX_BD_UNDERRUN) { + netdev_warn(dev, "*** TX: underrun[%d]\n", idx); + DEV_STATS_INC(dev, tx_fifo_errors); + } + + if (tx_bd_flags & OETH_TX_BD_RETLIM) { + netdev_warn(dev, "*** TX: retrans limit[%d]\n", idx); + DEV_STATS_INC(dev, tx_aborted_errors); + } + + if (tx_bd_flags & OETH_TX_BD_LATECOL) { + netdev_warn(dev, "*** TX: late coll[%d]\n", idx); + DEV_STATS_INC(dev, tx_window_errors); + } + + DEV_STATS_INC(dev, tx_errors); + DEV_STATS_ADD(dev, collisions, (tx_bd_flags & OETH_TX_BD_RETRY) >> 4); + + z87_tbd_clear_flags(np, idx, tx_err_mask); +} + +static int z87_release_tx(struct net_device *dev, int idx, int budget) +{ + struct z87_private *np =3D netdev_priv(dev); + struct sk_buff *skb; + int bytes =3D 0; + + /* + * Ensure that all previous DMA writes are + * visible before checking TX BD errors + */ + dma_rmb(); + + z87_tx_bd_errors(dev, idx); + + skb =3D np->tx_bd[idx].skb; + + if (likely(skb)) { + dma_unmap_single(np->dma_dev, np->tx_bd[idx].dma, + (size_t)skb->len, DMA_TO_DEVICE); + bytes =3D skb->len; + np->tx_bd[idx].skb =3D NULL; + napi_consume_skb(skb, budget); + } + + return bytes; +} + +static void z87_reclaim_tx(struct net_device *dev, int budget) +{ + struct z87_private *np =3D netdev_priv(dev); + unsigned int tx0, tx1; + int released =3D 0; + int bytes =3D 0; + u64 tx_reg; + + spin_lock_bh(&np->tx_lock); + + /* read the current state of the Tx BDs */ + tx0 =3D z87_read32(dev, Z087_REG_TXEMPTY0); + tx1 =3D z87_read32(dev, Z087_REG_TXEMPTY1); + + tx_reg =3D ((u64)tx1 << 32) | tx0; + + while (np->dty_tx !=3D READ_ONCE(np->cur_tx)) { + unsigned int entry =3D np->dty_tx & (Z087_TBD_NUM - 1); + + if (!(tx_reg & BIT_ULL(entry))) + break; + + bytes +=3D z87_release_tx(dev, entry, budget); + released++; + np->dty_tx++; + } + + if (released) + netdev_completed_queue(dev, released, bytes); + + if (!test_bit(__Z87_DOWN, &np->state) && netif_queue_stopped(dev) && + (READ_ONCE(np->cur_tx) - np->dty_tx) <=3D (Z087_TBD_NUM / 2)) + netif_wake_queue(dev); + + spin_unlock_bh(&np->tx_lock); +} + +static void z87_clean_tx_ring(struct net_device *dev) +{ + struct z87_private *np =3D netdev_priv(dev); + int i; + + spin_lock_bh(&np->tx_lock); + + for (i =3D 0; i < Z087_TBD_NUM; i++) { + if (np->tx_bd[i].skb) { + dma_unmap_single(np->dma_dev, np->tx_bd[i].dma, + (size_t)np->tx_bd[i].skb->len, DMA_TO_DEVICE); + dev_kfree_skb_any(np->tx_bd[i].skb); + np->tx_bd[i].skb =3D NULL; + np->tx_bd[i].dma =3D 0; + DEV_STATS_INC(dev, tx_dropped); + } + } + + np->cur_tx =3D 0; + np->dty_tx =3D 0; + + netdev_reset_queue(dev); + + spin_unlock_bh(&np->tx_lock); +} + +static int z87_poll(struct napi_struct *napi, int budget) +{ + struct z87_private *np =3D container_of(napi, struct z87_private, napi); + struct net_device *dev =3D np->dev; + unsigned long flags; + int npackets =3D 0; + + z87_reclaim_tx(dev, budget); + + npackets =3D z87_process_rx(napi, budget); + + if (npackets < budget && napi_complete_done(napi, npackets)) { + raw_spin_lock_irqsave(&np->lock, flags); + if (!test_bit(__Z87_DOWN, &np->state)) + z87_enable_irqs(dev, Z087_IRQ_ALL); + raw_spin_unlock_irqrestore(&np->lock, flags); + } + + return npackets; +} + +static int z87_open(struct net_device *dev) +{ + struct z87_private *np =3D netdev_priv(dev); + int res; + + netif_carrier_off(dev); + + res =3D request_irq(dev->irq, z87_irq, IRQF_SHARED, np->model_name, dev); + if (res < 0) { + netdev_err(dev, "*** unable to get IRQ %d.\n", dev->irq); + return res; + } + + res =3D z87_hw_start(dev); + if (res < 0) { + netdev_err(dev, "*** hardware start failed!\n"); + goto release_irq; + } + + return 0; + +release_irq: + free_irq(dev->irq, dev); + return res; +} + +static int z87_start_xmit(struct sk_buff *skb, struct net_device *dev) +{ + struct z87_private *np =3D netdev_priv(dev); + dma_addr_t dma_hndler =3D 0; + unsigned int tx_idx =3D 0; + + spin_lock_bh(&np->tx_lock); + + if (unlikely(test_bit(__Z87_DOWN, &np->state))) { + netif_stop_queue(dev); + spin_unlock_bh(&np->tx_lock); + return NETDEV_TX_BUSY; + } + + if (unlikely(np->cur_tx - np->dty_tx >=3D Z087_TBD_NUM)) { + netdev_warn(dev, "tx ring full, stopping queue\n"); + netif_stop_queue(dev); + spin_unlock_bh(&np->tx_lock); + return NETDEV_TX_BUSY; + } + + tx_idx =3D np->cur_tx & (Z087_TBD_NUM - 1); + + if (unlikely(skb->len > Z087_ETHBUF_SIZE)) { + netdev_warn(dev, "tx frame too long (%d bytes)\n", skb->len); + goto drop; + } + + if (skb_put_padto(skb, ETH_ZLEN)) + goto unlock; + + dma_hndler =3D dma_map_single(np->dma_dev, skb->data, skb->len, DMA_TO_DE= VICE); + if (unlikely(dma_mapping_error(np->dma_dev, dma_hndler))) { + netdev_err(dev, "DMA mapping error for tx buffer %d\n", tx_idx); + goto drop; + } + + z87_tbd_set_addr(np, tx_idx, dma_hndler); + z87_tbd_set_len(np, tx_idx, skb->len); + + /* Ensure descriptor updates are visible before ringing the doorbell */ + dma_wmb(); + + skb_tx_timestamp(skb); + + z87_tx_doorbell(dev, tx_idx); + + /* Update net statistics */ + dev_sw_netstats_tx_add(dev, 1, skb->len); + + np->tx_bd[tx_idx].skb =3D skb; + np->tx_bd[tx_idx].dma =3D dma_hndler; + + netdev_sent_queue(dev, skb->len); + + WRITE_ONCE(np->cur_tx, np->cur_tx + 1); + + /* congestion: is tx ring full now? */ + if (unlikely(np->cur_tx - np->dty_tx >=3D Z087_TBD_NUM)) + netif_stop_queue(dev); + + spin_unlock_bh(&np->tx_lock); + + return NETDEV_TX_OK; + +drop: + dev_kfree_skb_any(skb); +unlock: + DEV_STATS_INC(dev, tx_dropped); + spin_unlock_bh(&np->tx_lock); + return NETDEV_TX_OK; +} + +static void z87_load_mac_addr(struct net_device *dev) +{ + struct z87_private *np =3D netdev_priv(dev); + u8 mac[ETH_ALEN] =3D {0, 0, 0, 0, 0, 0}; + struct sockaddr addr; + int res; + + z87_load_mac(dev, mac); + + if (is_valid_ether_addr(mac)) { + netdev_info(dev, + "using MAC %02x:%02x:%02x:%02x:%02x:%02x from registers.\n", + mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); + memcpy(addr.sa_data, mac, ETH_ALEN); + goto end; + } + + res =3D z87_i2c_load_mac_from_eeprom(np->i2c, mac); + if (!res && is_valid_ether_addr(mac)) { + netdev_info(dev, + "using MAC %02x:%02x:%02x:%02x:%02x:%02x from MAC EEPROM.\n", + mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); + memcpy(addr.sa_data, mac, ETH_ALEN); + goto end; + } + + eth_hw_addr_random(dev); + + netdev_info(dev, + "using random MAC %02x:%02x:%02x:%02x:%02x:%02x\n", + dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2], + dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5]); + memcpy(addr.sa_data, dev->dev_addr, ETH_ALEN); + +end: + z87_set_mac_address(dev, &addr); +} + +static int z87_wait_core_idle(struct net_device *dev) +{ + const u32 idle_mask =3D OETH_MODER_RX_IDLE | OETH_MODER_TX_IDLE; + u32 status; + int res; + + res =3D read_poll_timeout(z87_read32, status, + (status & idle_mask) =3D=3D idle_mask, + Z087_IDLE_POLL_US, Z087_IDLE_TIMEOUT_US, + false, dev, Z087_REG_MODER); + if (res) + netdev_err(dev, "Core idle timeout: MODER=3D0x%08x\n", status); + + return res; +} + +static int z87_core_reset(struct net_device *dev) +{ + struct z87_private *np =3D netdev_priv(dev); + unsigned long flags; + int res; + + /* + * Clearing RXEN/TXEN resets the RX/TX areas. Both IDLE bits must + * be set before the Wishbone area can safely be reconfigured. + * Pending descriptors need not be consumed while reset is asserted. + */ + raw_spin_lock_irqsave(&np->lock, flags); + z87_clear_mode_flags(dev, OETH_MODER_RXEN | OETH_MODER_TXEN); + raw_spin_unlock_irqrestore(&np->lock, flags); + + res =3D z87_wait_core_idle(dev); + if (res < 0) + return res; + + z87_write32(dev, Z087_REG_BDSTART, 0); + + /* Flush the descriptor-table detach before releasing DMA memory. */ + z87_read32(dev, Z087_REG_BDSTART); + + /* Confirm both engines are still idle after the table detach. */ + return z87_wait_core_idle(dev); +} + +static int z87_chipset_init(struct net_device *dev) +{ + struct z87_private *np =3D netdev_priv(dev); + unsigned long flags; + int res; + + res =3D z87_core_reset(dev); + if (res < 0) { + netdev_err(dev, "Failed to reset core\n"); + return res; + } + + raw_spin_lock_irqsave(&np->lock, flags); + + z87_set_mode_flags(dev, np->features); + + z87_write32(dev, Z087_REG_PACKLEN, Z87_PACKLEN_DEFAULT); + + /* attach BD desc table address to hardware */ + z87_write32(dev, Z087_REG_BDSTART, np->bd_hw); + + /* initialize all 64 Rx BDs as empty (ready for hardware) */ + z87_write32(dev, Z087_REG_RXEMPTY0, 0xffffffff); + z87_write32(dev, Z087_REG_RXEMPTY1, 0xffffffff); + + raw_spin_unlock_irqrestore(&np->lock, flags); + + /* set management indices */ + np->cur_tx =3D 0; + np->dty_tx =3D 0; + np->cur_rx =3D 0; + + return 0; +} + +static bool z87_rx_bd_errors(struct net_device *dev, unsigned int idx) +{ + const u16 rx_err_mask =3D OETH_RX_BD_OVERRUN | OETH_RX_BD_INVSYMB | + OETH_RX_BD_DRIBBLE | OETH_RX_BD_TOOLONG | + OETH_RX_BD_SHORT | OETH_RX_BD_CRCERR | + OETH_RX_BD_LATECOL; + struct z87_private *np =3D netdev_priv(dev); + u16 rx_err_flags; + + rx_err_flags =3D z87_rbd_get_flags(np, idx, rx_err_mask); + if (!rx_err_flags) + return false; + + if (rx_err_flags & OETH_RX_BD_OVERRUN) { + netdev_warn(dev, "*** RX: overrun[%u]\n", idx); + DEV_STATS_INC(dev, rx_over_errors); + } + + if (rx_err_flags & OETH_RX_BD_INVSYMB) { + netdev_warn(dev, "*** RX: inv symbol[%u]\n", idx); + DEV_STATS_INC(dev, rx_frame_errors); + } + + if (rx_err_flags & OETH_RX_BD_DRIBBLE) { + netdev_warn(dev, "*** RX: dribble[%u]\n", idx); + DEV_STATS_INC(dev, rx_frame_errors); + } + + if (rx_err_flags & OETH_RX_BD_TOOLONG) { + netdev_warn(dev, "*** RX: too long[%u]\n", idx); + DEV_STATS_INC(dev, rx_length_errors); + } + + if (rx_err_flags & OETH_RX_BD_SHORT) { + netdev_warn(dev, "*** RX: too short[%u]\n", idx); + DEV_STATS_INC(dev, rx_length_errors); + } + + if (rx_err_flags & OETH_RX_BD_CRCERR) { + netdev_warn(dev, "*** RX: CRC err[%u]\n", idx); + DEV_STATS_INC(dev, rx_crc_errors); + } + + if (rx_err_flags & OETH_RX_BD_LATECOL) { + netdev_warn(dev, "*** RX: late coll[%u]\n", idx); + DEV_STATS_INC(dev, collisions); + } + + DEV_STATS_INC(dev, rx_errors); + + z87_rbd_clear_flags(np, idx, rx_err_mask); + + return true; +} + +static void z87_pass_packet(struct napi_struct *napi, unsigned int idx) +{ + struct z87_private *np =3D container_of(napi, struct z87_private, napi); + struct net_device *dev =3D np->dev; + struct sk_buff *skb =3D NULL; + u32 pkt_len =3D 0; + + /* Ensure packet data and BD length written by HW DMA are visible */ + dma_rmb(); + + if (unlikely(z87_rx_bd_errors(dev, idx))) + goto out_err; + + pkt_len =3D z87_rbd_get_len(np, idx); + + if (unlikely(!np->rx_bd[idx].addr)) { + if (net_ratelimit()) + netdev_warn(dev, "invalid rx_bd[%d] buffer\n", idx); + + DEV_STATS_INC(dev, rx_errors); + goto out_err; + } + + if (likely(!(dev->features & NETIF_F_RXFCS))) { + if (unlikely(pkt_len <=3D ETH_FCS_LEN)) { + if (net_ratelimit()) + netdev_warn(dev, "invalid length of pkt %d (len=3D%u)!\n", + idx, pkt_len); + + DEV_STATS_INC(dev, rx_length_errors); + DEV_STATS_INC(dev, rx_errors); + goto out_err; + } + pkt_len -=3D ETH_FCS_LEN; + } + + if (unlikely(pkt_len < ETH_HLEN) || + unlikely(pkt_len > Z087_ETHBUF_SIZE)) { + if (net_ratelimit()) + netdev_warn(dev, "invalid length of pkt %d (len=3D%u)!\n", + idx, pkt_len); + + DEV_STATS_INC(dev, rx_length_errors); + DEV_STATS_INC(dev, rx_errors); + goto out_err; + } + + skb =3D dev_alloc_skb(pkt_len + NET_IP_ALIGN); + + if (unlikely(!skb)) { + netdev_warn(dev, "*** Mem squeeze! drop packet\n"); + DEV_STATS_INC(dev, rx_dropped); + goto out_err; + } + + skb->dev =3D dev; + + /* 16 byte align the IP fields. */ + skb_reserve(skb, NET_IP_ALIGN); + skb_copy_to_linear_data(skb, (np->rx_bd[idx].addr), pkt_len); + + skb_put(skb, pkt_len); + skb->protocol =3D eth_type_trans(skb, dev); + + /* tell network stack... */ + dev_sw_netstats_rx_add(dev, pkt_len); + napi_gro_receive(napi, skb); + +out_err: + /* clean processed Rx BD nonempty Flag */ + z87_rx_complete(dev, idx); +} + +static int z87_hw_stop(struct net_device *dev) +{ + struct z87_private *np =3D netdev_priv(dev); + unsigned long flags; + int res; + + /* already stopped by a previous failed attempt (napi disabled, phy stopp= ed) */ + if (test_bit(__Z87_HW_DEAD, &np->state)) + return -EIO; + + spin_lock_bh(&np->tx_lock); + set_bit(__Z87_DOWN, &np->state); + spin_unlock_bh(&np->tx_lock); + netif_tx_disable(dev); + + netif_carrier_off(dev); + + if (dev->phydev) + phy_stop(dev->phydev); + + raw_spin_lock_irqsave(&np->lock, flags); + + /* disable all IRQs */ + z87_disable_irqs(dev, Z087_IRQ_ALL); + z87_read32(dev, Z087_REG_INT_MASK); + + /* clean spurious left IRQs */ + z87_write32(dev, Z087_REG_INT_SRC, 0x7f); + + raw_spin_unlock_irqrestore(&np->lock, flags); + + synchronize_irq(dev->irq); + napi_disable(&np->napi); + + /* reset the core, leave DMA engine idle prior to freeing buffers */ + res =3D z87_core_reset(dev); + if (res < 0) { + netdev_err(dev, "Hardware failed to enter idle state! Retaining DMA buff= ers to prevent memory corruption.\n"); + set_bit(__Z87_HW_DEAD, &np->state); + + /* Do not free DMA memory: hardware might still be accessing it */ + return res; + } + + /* reclaim any completed Tx BDs */ + z87_reclaim_tx(dev, 0); + + /* clean and free any uncompleted Tx BDs */ + z87_clean_tx_ring(dev); + + /* free all Rx buffers */ + z87_free_rx_bd(dev); + + return 0; +} + +/* Retry quiescing a core that failed to stop; release retained DMA buffer= s on success */ +static int z87_hw_recover(struct net_device *dev) +{ + struct z87_private *np =3D netdev_priv(dev); + int res; + + if (!test_bit(__Z87_HW_DEAD, &np->state)) + return 0; + + res =3D z87_core_reset(dev); + if (res < 0) + return res; + + z87_clean_tx_ring(dev); + z87_free_rx_bd(dev); + + clear_bit(__Z87_HW_DEAD, &np->state); + + return 0; +} + +static int z87_hw_start(struct net_device *dev) +{ + struct z87_private *np =3D netdev_priv(dev); + unsigned long flags; + int res; + + res =3D z87_hw_recover(dev); + if (res < 0) { + netdev_err(dev, "Hardware still not idle, refusing to start\n"); + return res; + } + + res =3D z87_phy_init(dev); + if (res < 0) { + netdev_err(dev, "*** PHY Initialization failed!\n"); + return res; + } + + phy_start(dev->phydev); + + res =3D z87_chipset_init(dev); + if (res < 0) { + netdev_err(dev, "Failed to initialize chipset\n"); + goto err_stop_phy; + } + + /* setup the Tx/Rx buffer descriptors */ + res =3D z87_bd_setup(dev); + if (res < 0) { + netdev_err(dev, "Failed to setup BDs\n"); + goto err_stop_phy; + } + + napi_enable(&np->napi); + + raw_spin_lock_irqsave(&np->lock, flags); + clear_bit(__Z87_DOWN, &np->state); + + /* clear any pending spurious IRQs */ + z87_write32(dev, Z087_REG_INT_SRC, Z087_IRQ_ALL); + z87_enable_irqs(dev, Z087_IRQ_ALL); + + /* tell hardware we are ready */ + z87_set_mode_flags(dev, OETH_MODER_RXEN | OETH_MODER_TXEN); + + raw_spin_unlock_irqrestore(&np->lock, flags); + + netif_start_queue(dev); + + return 0; + +err_stop_phy: + phy_stop(dev->phydev); + return res; +} + +static int z87_close(struct net_device *dev) +{ + struct z87_private *np =3D netdev_priv(dev); + + cancel_work_sync(&np->reset_task); + + z87_hw_stop(dev); + + free_irq(dev->irq, dev); + + return 0; +} + +/*******************************************************************/ +/** central IRQ handler + * + * \param irq \IN INTB interrupt + * \param dev_id \IN unique identifier + * + * \return if IRQ was handled or not + */ +static irqreturn_t z87_irq(int irq, void *dev_id) +{ + struct net_device *dev =3D (struct net_device *)dev_id; + struct z87_private *np =3D netdev_priv(dev); + u32 status, mask; + + raw_spin_lock(&np->lock); + + status =3D z87_read32(dev, Z087_REG_INT_SRC) & Z087_IRQ_ALL; + mask =3D z87_read32(dev, Z087_REG_INT_MASK); + + status &=3D mask; + + if (unlikely(!status)) { + raw_spin_unlock(&np->lock); + return IRQ_NONE; + } + + /* acknowledge interrupts */ + z87_write32(dev, Z087_REG_INT_SRC, status); + + /* disable interrupts */ + z87_disable_irqs(dev, Z087_IRQ_ALL); + + if (likely(!test_bit(__Z87_DOWN, &np->state) && + napi_schedule_prep(&np->napi))) + __napi_schedule(&np->napi); + + raw_spin_unlock(&np->lock); + + return IRQ_HANDLED; +} + +static int z87_probe(struct mcb_device *mdev, + const struct mcb_device_id *id) +{ + const struct board_config *cfg =3D NULL; + struct net_device *dev =3D NULL; + struct z87_private *np =3D NULL; + void *mem_virt_dma =3D NULL; + dma_addr_t mem_hw_dma; + struct resource *mem; + int res =3D -ENXIO; + + cfg =3D z87_get_board_config(mdev); + if (!cfg) + return -EOPNOTSUPP; + + /** + * mdev->inst is defined in a per-board basis, so lets check + * if there are more devices that defined for the board. In that + * case, something is wrong. + */ + if (mdev->inst >=3D cfg->num_devs) { + return dev_err_probe(&mdev->dev, -EINVAL, + "detected more devices than configured for board: %s", + cfg->board_name); + } + + mem =3D mcb_request_mem(mdev, dev_name(&mdev->dev)); + if (IS_ERR(mem)) + return PTR_ERR(mem); + + dev =3D devm_alloc_etherdev(&mdev->dev, sizeof(struct z87_private)); + if (!dev) { + res =3D -ENOMEM; + goto err_mem; + } + + dev->tstats =3D devm_netdev_alloc_pcpu_stats(&mdev->dev, struct pcpu_sw_n= etstats); + if (!dev->tstats) { + res =3D -ENOMEM; + goto err_mem; + } + + if (dma_set_mask_and_coherent(mdev->dma_dev, DMA_BIT_MASK(32))) { + netdev_err(dev, "can't set 32bit DMA mask, aborting\n"); + res =3D -ENOMEM; + goto err_mem; + } + + dev->base_addr =3D (unsigned long)devm_ioremap(&mdev->dev, mem->start, Z0= 87_CFGREG_SIZE); + if (!dev->base_addr) { + res =3D -ENOMEM; + goto err_mem; + } + + dev->irq =3D mcb_get_irq(mdev); + + /* + * if more than one Z87 ethernet core is implemented in one PCI function + * on one chameleon FPGA, the device port is important for distinct ether= net + * device identification during interface renaming via systemd/udev. We s= tart + * counting at 1 to have a constant naming scheme; 0 is omitted during re= naming + */ + dev->dev_port =3D mdev->inst + 1; + + SET_NETDEV_DEV(dev, &mdev->dev); + + dev->netdev_ops =3D &z87_netdev_ops; + dev->ethtool_ops =3D z87_get_ethtool_ops(); + + /* setup the phy Info within the private z87_private struct */ + np =3D netdev_priv(dev); + np->parent =3D &mdev->dev; + np->mem =3D mem; + np->dma_dev =3D mdev->dma_dev; + + raw_spin_lock_init(&np->lock); + spin_lock_init(&np->tx_lock); + set_bit(__Z87_DOWN, &np->state); + + /* Ensure core is in a quiescent state and IRQs disabled from the start *= / + z87_disable_irqs(dev, Z087_IRQ_ALL); + z87_write32(dev, Z087_REG_INT_SRC, 0x7f); + + res =3D z87_core_reset(dev); + if (res < 0) { + netdev_err(dev, "unable to perform core reset on probe: %d\n", res); + goto err_mem; + } + + mcb_set_drvdata(mdev, dev); + + netif_napi_add(dev, &np->napi, z87_poll); + + np->dev =3D dev; + np->board =3D cfg->board_id; + np->instance =3D mdev->inst; + np->phy_mode =3D cfg->dev_phy_mode[mdev->inst]; + np->phy.phy_addr =3D cfg->dev_phy_addr[mdev->inst]; + np->phy.phy_interface =3D PHY_INTERFACE_MODE_MII; + + /* set the default features for the Z87 device */ + np->features =3D OETH_MODER_IFG | OETH_MODER_EXDFREN | OETH_MODER_CRCEN | + OETH_MODER_BRO | OETH_MODER_PAD | OETH_MODER_RECSMALL; + + np->phy.hf_supported =3D z87_read32(dev, Z087_REG_MODER) & OETH_MODER_HD_= AVAL; + + /* pass initial debug level */ + np->msg_enable =3D 0; + + /* + * get a coherent DMAable memory region for the BDs to have + * the 64 Rx/Tx BD static in sync with IP core + */ + mem_virt_dma =3D dma_alloc_coherent(mdev->dma_dev, + Z087_BD_AREA_SIZE, &mem_hw_dma, GFP_KERNEL); + if (!mem_virt_dma) { + res =3D -ENOMEM; + goto err_napi; + } + + /* store for dma_free_coherent at module remove */ + np->bd_base =3D (unsigned long)mem_virt_dma; + np->rx_desc =3D (struct z87_desc *)np->bd_base; + np->tx_desc =3D np->rx_desc + Z087_RBD_NUM; + np->bd_hw =3D mem_hw_dma; + + /* clean BD Area */ + memset((void *)np->bd_base, 0, Z087_BD_AREA_SIZE); + snprintf(np->model_name, MODELNAME_LEN, "16Z%03u", id->device); + + /* force new interrupt behavior */ + z87_write32(dev, Z087_REG_COREREV, + z87_read32(dev, Z087_REG_COREREV) | REG_COREREV_IRQNEWEN); + + if (!(z87_read32(dev, Z087_REG_COREREV) + & REG_COREREV_IRQNEWEN)) { + netdev_info(dev, "%s: Couldn't set to new IRQ behavior\n", __func__); + } + + /* init the process context work queue function to restart Z87 */ + INIT_WORK(&np->reset_task, z87_reset_task); + + /* Initialize i2c core */ + np->i2c =3D z87_i2c_alloc(&mdev->dev, dev->base_addr); + if (IS_ERR(np->i2c)) { + res =3D PTR_ERR(np->i2c); + goto err_dma; + } + + z87_load_mac_addr(dev); + + res =3D z87_phy_register_mdio(dev); + if (res < 0) { + netdev_err(dev, "Unable to register MDIO bus\n"); + goto err_i2c; + } + + res =3D z87_phy_connect(dev); + if (res < 0) { + netdev_err(dev, "Unable to connect PHY\n"); + goto err_unregister_mdio; + } + + res =3D z87_dev_register(dev); + if (res < 0) { + netdev_err(dev, "Unable to register netdev\n"); + goto err_disconnect_phy; + } + + return 0; + +err_disconnect_phy: + z87_phy_disconnect(dev); +err_unregister_mdio: + z87_phy_unregister_mdio(dev); +err_i2c: + z87_i2c_free(np->i2c); +err_dma: + dma_free_coherent(mdev->dma_dev, Z087_BD_AREA_SIZE, (void *)np->bd_base, = np->bd_hw); +err_napi: + netif_napi_del(&np->napi); +err_mem: + mcb_set_drvdata(mdev, NULL); + mcb_release_mem(mem); + + return res; +} + +static void z87_remove(struct mcb_device *mdev) +{ + struct net_device *dev =3D mcb_get_drvdata(mdev); + struct z87_private *np =3D netdev_priv(dev); + + /* disable reset task first */ + cancel_work_sync(&np->reset_task); + unregister_netdev(dev); + z87_phy_disconnect(dev); + z87_phy_unregister_mdio(dev); + netif_napi_del(&np->napi); + z87_i2c_free(np->i2c); + mcb_set_drvdata(mdev, NULL); + + if (z87_hw_recover(dev) < 0) { + /* + * The reset could not be confirmed and no hardware reset + * mechanism is available through MCB. DMA may still be active, + * so intentionally leak the DMA allocations until reboot. + * Release the MMIO reservation so a later probe can retry + * quiescing the core before allocating new DMA memory. + */ + dev_err(&mdev->dev, "Hardware still not idle, leaking DMA buffers\n"); + } else { + dma_free_coherent(mdev->dma_dev, Z087_BD_AREA_SIZE, + (void *)np->bd_base, np->bd_hw); + } + + mcb_release_mem(np->mem); +} + +static void z87_shutdown(struct mcb_device *mdev) +{ + struct net_device *dev =3D mcb_get_drvdata(mdev); + struct z87_private *np =3D netdev_priv(dev); + + netdev_info(dev, "Shutting down\n"); + cancel_work_sync(&np->reset_task); + + rtnl_lock(); + netif_device_detach(dev); + dev_close(dev); + if (z87_hw_recover(dev) < 0) + netdev_err(dev, "Hardware still not idle at shutdown, retaining DMA buff= ers\n"); + rtnl_unlock(); +} + +static int z87_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) +{ + switch (cmd) { + case SIOCGMIIPHY: + case SIOCGMIIREG: + case SIOCSMIIREG: + return z87_phy_ioctl(dev, ifr, cmd); + default: + break; + } + + return -EOPNOTSUPP; +} + +static const struct board_config *z87_get_board_config(struct mcb_device *= mdev) +{ + int i; + + dev_info(&mdev->dev, "%s on board %s\n", dev_name(&mdev->dev), mdev->bus-= >name); + + for (i =3D 0; i < ARRAY_SIZE(supported_boards); i++) + if (strstr(mdev->bus->name, supported_boards[i].board_name)) + return &supported_boards[i]; + + dev_err(&mdev->dev, "board %s not supported\n", mdev->bus->name); + return NULL; +} + +static const struct mcb_device_id men_z87_ids[] =3D { + { .device =3D MEN_ETH_ID_Z087 }, + { } +}; +MODULE_DEVICE_TABLE(mcb, men_z87_ids); + +static struct mcb_driver mcb_driver =3D { + .driver =3D { + .name =3D "z087-eth", + }, + .probe =3D z87_probe, + .remove =3D z87_remove, + .shutdown =3D z87_shutdown, + .id_table =3D men_z87_ids, +}; +module_mcb_driver(mcb_driver); + +MODULE_LICENSE("GPL"); +MODULE_DESCRIPTION("duagon Ethernet IP Core driver"); +MODULE_AUTHOR("Thomas Schnuerer"); +MODULE_AUTHOR("Javier Rodriguez"); +MODULE_IMPORT_NS("MCB"); diff --git a/drivers/net/ethernet/men/z87/men_z87_main.h b/drivers/net/ethe= rnet/men/z87/men_z87_main.h new file mode 100644 index 000000000000..cd7ec47b1432 --- /dev/null +++ b/drivers/net/ethernet/men/z87/men_z87_main.h @@ -0,0 +1,133 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* men_z87_main.h: MEN Z087 ethernet driver. + * + * Copyright (c) 2026 duagon Germany GmbH + * + * See MAINTAINERS file for support contact information. + */ + +#ifndef _MEN_Z87_MAIN_ +#define _MEN_Z87_MAIN_ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define MODELNAME_LEN 12 + +#define Z087_ETHBUF_SIZE 0x1000 /* size of 1 BD, PAGESZ aligned */ +#define Z087_CFGREG_SIZE 0x800 /* all from MODER to last Rx BD */ +#define WD_TX_TIMEOUT (5 * HZ) /* 5 seconds TX wait timeout */ +#define Z87_PACKLEN_DEFAULT 0x003c05fc /* packet length defaults (without = FCS) */ + +/* BDDEF Buffer Descriptor defines + * Buffer Descriptor defines. ETH MAC can maintain up to 128 BDs in total. + * (0x80) BD location =3D base + 0x400 - base + 0x7ff ( =3D0x400 ) + */ +#define Z087_BDSIZE 0x8 /* size in bytes of one BD */ +#define Z087_TBD_NUM 0x40 /* default number of TBDs */ +#define Z087_RBD_NUM 0x40 /* Z087_TBD_NUM make both equal */ + +/* BDAREA address defines within one Buffer descriptor */ +#define Z087_BD_OFFS_LEN 0x2 /* offset of length within BD */ +#define Z087_BD_OFFS_ADR 0x4 /* offset of Tx/Rx frame within this BD */ + +enum boards { + F218, /* 0 */ + F301, /* 1 */ + F614 /* 2 */ +}; + +enum z87_state { + __Z87_DOWN, /* block TX and NAPI IRQ rearming while down */ + __Z87_HW_DEAD, /* core failed to idle, DMA buffers retained */ +}; + +/* + * TX/RX Buffer Descriptors + * located between z87_base+0x400 and z87_base+0x800 + */ +struct z87_bd { + void *addr; /* pointer to buffer (cpu addr) */ + dma_addr_t dma; /* dma handle from dma_map_single or dma_alloc_coherent = */ + struct sk_buff *skb; /* pointer to skb for this BD */ +}; + +/* + * z87_i2c: structure for i2c core + */ +struct z87_i2c { + unsigned long base_addr; + struct i2c_adapter adapter; + struct i2c_algo_bit_data algo_bit; + unsigned int i2c_bug; +}; + +/* + * z87_desc: structure for a single buffer descriptor used by the hardware= . + * They are located between z87_base+0x400 and z87_base+0x800. + * This structure represents a single buffer descriptor used by the Z87 ha= rdware. + * It contains the flags and the address of the buffer associated with thi= s descriptor. + * It is used by the driver to manage the transmission and reception of ne= twork packets. + */ +struct z87_desc { + __le32 flags; /* flags for the buffer descriptor */ + __le32 addr; /* address of the buffer */ +}; + +#define Z087_BD_AREA_SIZE ((Z087_TBD_NUM + Z087_RBD_NUM) * sizeof(struct z= 87_desc)) + +struct z87_phy { + struct mii_bus *mdiobus; + struct phy_device *phydev; + phy_interface_t phy_interface; + int phy_addr; + bool link; + int speed; + int duplex; + bool hf_supported; /* half/full duplex capability */ +}; + +/* + * z087_private: main data struct for the driver + */ +struct z87_private { + u32 cur_rx; /* current position of the Rx Bd */ + u32 instance; /* chameleon instance if more Z87 */ + u32 phy_mode; /* phy_mode */ + u32 phy_addr; /* phy_addr */ + u32 cur_tx; /* next Tx BD to be filled */ + u32 dty_tx; /* oldest dirty Tx BD */ + unsigned long bd_base; /* start address of BDs in RAM */ + dma_addr_t bd_hw; /* DMA address of BDs in RAM */ + u32 board; /* board identifier of this eth */ + u32 features; /* feature flags for the driver */ + struct work_struct reset_task; /* process context resetting (ndo_tx_time= out) */ + struct z87_bd tx_bd[Z087_TBD_NUM]; /* Tx Buffer Descriptor address */ + struct z87_bd rx_bd[Z087_RBD_NUM]; /* Rx Buffer Descriptor address */ + struct z87_desc *tx_desc; /* pointer to Tx descriptors */ + struct z87_desc *rx_desc; /* pointer to Rx descriptors */ + raw_spinlock_t lock; /* main lock, taken in hardirq */ + spinlock_t tx_lock; /* lock for TX */ + struct device *dma_dev; /* the device we belong to */ + struct device *parent; /* parent device */ + struct z87_phy phy; /* PHY device information */ + u32 msg_enable; /* debug message level */ + struct napi_struct napi; /* NAPI struct */ + struct net_device *dev; /* net device */ + struct z87_i2c *i2c; /* i2c private data */ + char model_name[MODELNAME_LEN]; /* model_name */ + struct resource *mem; /* memory resource */ + unsigned long state; +}; + +const struct ethtool_ops *z87_get_ethtool_ops(void); + +#endif /* _MEN_Z87_MAIN_ */ diff --git a/drivers/net/ethernet/men/z87/men_z87_phy.c b/drivers/net/ether= net/men/z87/men_z87_phy.c new file mode 100644 index 000000000000..355eca9a3409 --- /dev/null +++ b/drivers/net/ethernet/men/z87/men_z87_phy.c @@ -0,0 +1,673 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (c) 2026 duagon Germany GmbH + * + * See MAINTAINERS file for support contact information. + */ + +#include +#include "men_z87_main.h" +#include "men_z87_hw.h" +#include "men_z87_phy.h" + +/* timeout to wait for reply from MII */ +#define MII_ACCESS_TIMEOUT 10000 + +/* The expected values for a Micrel KSZ8041 PHY in the PHY Identifier Regi= ster #2 (PHYIDR2). */ +#define PHY_ID2_KSZ8041_1 0x1512 +#define PHY_ID2_KSZ8041_2 0x1513 + +/* The expected value for a TI DP83822 PHY in the PHY Identifier Register = #1 (PHYIDR1). */ +#define PHY_DP83822_PHY_ID1 0x2000 + +/* + * The device address to be set in the REGCR register of a a TI DP83822 PH= Y to direct any + * accesses of the ADDAR register to MMD. + */ +#define PHY_DP83822_DEVAD_MMD 0x1f + +/* TI DP83822 PHY specific MII registers */ +#define PHY_DP83822_MII_MLEDCR 0x25 /* The Multi-LED Control Register addr= ess */ +#define PHY_DP83822_MII_LEDCFG1 0x460 /* The LEDs Configuration Register #= 1 address */ +#define PHY_DP83822_MII_IOCTRL1 0x462 /* The IO MUX GPIO Control Register = #1 address */ + +#define Z087_PHY_IDLE_POLL_US 10 +#define Z087_PHY_IDLE_TOUT_US 10000 + +static int z87_phy_reset(struct net_device *dev); +static int z87_phy_set_defaults(struct net_device *dev); +static int z87_phy_init_mode(struct net_device *dev); +static int __mdio_read(struct net_device *dev, int phy_id, int location); +static int __mdio_write(struct net_device *dev, int phy_id, int location, = int val); +static int z87_wait_status_busy_change(struct net_device *dev); + +static int z87_wait_status_busy_change(struct net_device *dev) +{ + u32 miival; + int res; + + res =3D read_poll_timeout_atomic(z87_read32, miival, + !(miival & OETH_MIISTATUS_BUSY), + Z087_PHY_IDLE_POLL_US, Z087_PHY_IDLE_TOUT_US, + false, dev, Z087_REG_MIISTATUS); + + if (res) { + netdev_err(dev, "*** MII Read timeout!\n"); + return -ETIMEDOUT; + } + + return 0; +} + +static int __mdio_read(struct net_device *dev, int phy_id, int location) +{ + int res; + + /* wait until a previous BUSY disappears */ + res =3D z87_wait_status_busy_change(dev); + if (res < 0) + goto mdio_read_out; + + /* + * set up combined PHY and Register within Phy, + * then kick off read cmd + */ + z87_write32(dev, Z087_REG_MIIADR, (location & 0xff) << 8 | phy_id); + z87_write32(dev, Z087_REG_MIICMD, OETH_MIICMD_RSTAT); + + /* wait until the PHY finished */ + res =3D z87_wait_status_busy_change(dev); + if (res < 0) + goto mdio_read_out; + + /* fetch read Value from MIIRX_DATA */ + res =3D z87_read32(dev, Z087_REG_MIIRX_DATA); + +mdio_read_out: + return res; +} + +static int __mdio_write(struct net_device *dev, int phy_id, int location, = int val) +{ + int res; + + /* wait until a previous BUSY disappears */ + res =3D z87_wait_status_busy_change(dev); + if (res < 0) + goto mdio_write_out; + + z87_write32(dev, Z087_REG_MIIADR, (location & 0xff) << 8 | phy_id); + z87_write32(dev, Z087_REG_MIITX_DATA, val); + z87_write32(dev, Z087_REG_MIICMD, OETH_MIICMD_WCTRLDATA); + + /* wait until a previous BUSY disappears */ + res =3D z87_wait_status_busy_change(dev); + +mdio_write_out: + return res; +} + +static int z87_mdio_read(struct mii_bus *bus, int addr, int regnum) +{ + struct net_device *dev =3D bus->priv; + + return __mdio_read(dev, addr, regnum); +} + +static int z87_mdio_write(struct mii_bus *bus, int addr, int regnum, u16 v= al) +{ + struct net_device *dev =3D bus->priv; + + return __mdio_write(dev, addr, regnum, val); +} + +static int dp83822_conf_led(struct net_device *dev, u16 val) +{ + int res; + + res =3D phy_write(dev->phydev, MII_MMD_CTRL, MII_MMD_CTRL_ADDR | PHY_DP83= 822_DEVAD_MMD); + if (res < 0) + return res; + + res =3D phy_write(dev->phydev, MII_MMD_DATA, val); + if (res < 0) + return res; + + res =3D phy_write(dev->phydev, MII_MMD_CTRL, MII_MMD_CTRL_NOINCR | PHY_DP= 83822_DEVAD_MMD); + if (res < 0) + return res; + + return 0; +} + +static int dp83822_conf_leds(struct net_device *dev) +{ + struct z87_private *np =3D netdev_priv(dev); + int reg_val, res; + + netdev_info(dev, "configure leds of dp83822 phy @ 0x%04x\n", np->phy.phy_= addr); + + /* + * LED 0 configuration + * Reference manual table 8-44: Multi-LED Control Register (MLEDCR) + * Bits 1:0 =3D 0b11 (MLED routed to LED_0), bits 6:3 =3D 0b0001 (RX/TX A= ctivity), + * bit 9 =3D 0b1 (MLED Polarity Swap active high) + */ + + res =3D dp83822_conf_led(dev, PHY_DP83822_MII_MLEDCR); + if (res < 0) + return res; + + reg_val =3D phy_read(dev->phydev, MII_MMD_DATA); + if (reg_val < 0) { + netdev_err(dev, "unable to read MLEDCR phy register\n"); + return reg_val; + } + + res =3D phy_write(dev->phydev, MII_MMD_DATA, ((u16)reg_val & 0xfd84) | 0x= 020b); + if (res < 0) + return res; + + /* + * LED 1 configuration + * Reference manual table 8-92: LEDs Configuration Register #1 (LEDCFG1) + * Bits 11:8 =3D 0000 (LINK OK) + */ + res =3D dp83822_conf_led(dev, PHY_DP83822_MII_LEDCFG1); + if (res < 0) + return res; + + reg_val =3D phy_read(dev->phydev, MII_MMD_DATA); + if (reg_val < 0) { + netdev_err(dev, "unable to read LEDCFG1 phy register\n"); + return reg_val; + } + + res =3D phy_write(dev->phydev, MII_MMD_DATA, (u16)reg_val & 0xf0ff); + if (res < 0) + return res; + + /* + * Reference manual table 8-94: IO MUX GPIO Control Register #1 (IOCTRL1) + * Bits 2:0 =3D 001 (LED_1) + */ + res =3D dp83822_conf_led(dev, PHY_DP83822_MII_IOCTRL1); + if (res < 0) + return res; + + /* + * The dp83822_conf_led function already handles + * the MMD address and control writes + */ + reg_val =3D phy_read(dev->phydev, MII_MMD_DATA); + if (reg_val < 0) { + netdev_err(dev, "unable to read IOCTRL1 phy register\n"); + return reg_val; + } + + res =3D phy_write(dev->phydev, MII_MMD_DATA, ((u16)reg_val & 0xfff8) | 0x= 0001); + if (res < 0) + return res; + + return 0; +} + +static int ksz8041_disable_leds(struct net_device *dev) +{ + s16 reg_val; + + reg_val =3D phy_read(dev->phydev, 0x1e); + if (reg_val >=3D 0) { + /* just set bit14, bit 15 is reserved (datasheet p.29) */ + reg_val |=3D BIT(14); + return phy_write(dev->phydev, 0x1e, (u16)reg_val); + } + + return reg_val; +} + +static inline void z87_phy_up(struct net_device *dev) +{ + struct z87_private *np =3D netdev_priv(dev); + + spin_lock_bh(&np->tx_lock); + if (!test_bit(__Z87_DOWN, &np->state)) + netif_wake_queue(dev); + spin_unlock_bh(&np->tx_lock); + netif_carrier_on(dev); +} + +static inline void z87_phy_down(struct net_device *dev) +{ + netif_stop_queue(dev); + netif_carrier_off(dev); +} + +static int z87_set_duplex(struct net_device *dev, int duplex) +{ + struct z87_private *np =3D netdev_priv(dev); + unsigned long flags; + int res =3D 0; + + raw_spin_lock_irqsave(&np->lock, flags); + + if (duplex =3D=3D DUPLEX_FULL) + z87_set_mode_flags(dev, OETH_MODER_FULLD); + else if (np->phy.hf_supported) + z87_clear_mode_flags(dev, OETH_MODER_FULLD); + else + res =3D -EOPNOTSUPP; + + raw_spin_unlock_irqrestore(&np->lock, flags); + + return res; +} + +static void z87_adjust_link(struct net_device *dev) +{ + struct z87_private *np =3D netdev_priv(dev); + struct phy_device *phydev; + bool changed; + int res; + + phydev =3D np->phy.phydev; + + if (!phydev) + return; + + changed =3D (np->phy.link !=3D phydev->link); + + if (phydev->link) { + if (changed || + np->phy.speed !=3D phydev->speed || + np->phy.duplex !=3D phydev->duplex) { + /* + * Reconfigure the MAC when relevant parameters change. + */ + np->phy.speed =3D phydev->speed; + np->phy.duplex =3D phydev->duplex; + res =3D z87_set_duplex(dev, phydev->duplex); + if (res < 0) { + netdev_warn(dev, "half duplex not supported. link down\n"); + z87_phy_down(dev); + return; + } + + netdev_info(dev, "link up, %d Mbps, %s duplex\n", + phydev->speed, + phydev->duplex =3D=3D DUPLEX_FULL ? + "full" : "half"); + } + if (changed) + z87_phy_up(dev); + + } else if (changed) { + z87_phy_down(dev); + netdev_info(dev, "link down\n"); + } + + np->phy.link =3D phydev->link; +} + +int z87_phy_register_mdio(struct net_device *dev) +{ + struct z87_private *np =3D netdev_priv(dev); + struct mii_bus *bus; + int ret; + + bus =3D mdiobus_alloc(); + if (!bus) + return -ENOMEM; + + bus->name =3D "men-z87-mdio"; + bus->read =3D z87_mdio_read; + bus->write =3D z87_mdio_write; + bus->parent =3D np->parent; + bus->priv =3D dev; + + snprintf(bus->id, MII_BUS_ID_SIZE, "phy-%s", dev_name(np->parent)); + + if (np->phy.phy_addr >=3D 0 && np->phy.phy_addr < 32) + bus->phy_mask =3D ~BIT(np->phy.phy_addr); + + ret =3D mdiobus_register(bus); + if (ret) { + dev_err(np->parent, "Unable to register MDIO: %d\n", ret); + mdiobus_free(bus); + return ret; + } + + dev_info(np->parent, "MDIO bus registered with ID: %s\n", bus->id); + + np->phy.mdiobus =3D bus; + + return 0; +} + +int z87_phy_unregister_mdio(struct net_device *dev) +{ + struct z87_private *np =3D netdev_priv(dev); + + if (np->phy.mdiobus) { + mdiobus_unregister(np->phy.mdiobus); + mdiobus_free(np->phy.mdiobus); + np->phy.mdiobus =3D NULL; + } + + return 0; +} + +int z87_phy_connect(struct net_device *dev) +{ + struct z87_private *np =3D netdev_priv(dev); + struct phy_device *phydev; + int ret; + + phydev =3D mdiobus_get_phy(np->phy.mdiobus, np->phy.phy_addr); + if (!phydev) { + netdev_err(dev, "PHY not found at MDIO address: %d\n", + np->phy.phy_addr); + return -ENODEV; + } + + ret =3D phy_connect_direct(dev, phydev, + z87_adjust_link, + np->phy.phy_interface); + if (ret) { + netdev_err(dev, "Unable to connect PHY: %d\n", ret); + return ret; + } + + np->phy.phydev =3D phydev; + + /* Limit to the actual MAC capability */ + phy_set_max_speed(phydev, SPEED_100); + + if (!np->phy.hf_supported) { + phy_remove_link_mode(phydev, ETHTOOL_LINK_MODE_10baseT_Half_BIT); + phy_remove_link_mode(phydev, ETHTOOL_LINK_MODE_100baseT_Half_BIT); + } + + /* Set board defaults before users can configure the link through phylib.= */ + ret =3D z87_phy_set_defaults(dev); + if (ret) { + z87_phy_disconnect(dev); + return ret; + } + + return 0; +} + +int z87_phy_disconnect(struct net_device *dev) +{ + struct z87_private *np =3D netdev_priv(dev); + + if (np->phy.phydev) { + phy_disconnect(np->phy.phydev); + np->phy.phydev =3D NULL; + } + + return 0; +} + +int z87_phy_init(struct net_device *dev) +{ + struct z87_private *np =3D netdev_priv(dev); + struct phy_device *phydev =3D dev->phydev; + u8 phy_addr =3D np->phy.phy_addr; + u16 dat =3D 0; + int reg_val; + int res; + + if (!phydev) + return -ENODEV; + + /* reset the PHY */ + res =3D z87_phy_reset(dev); + if (res < 0) + return res; + + netdev_dbg(dev, "init PHY %s (ID 0x%08x) @ 0x%04x\n", + phydev_name(phydev), phydev->phy_id, phy_addr); + + switch (np->board) { + case F614: + if ((phydev->phy_id >> 16) =3D=3D PHY_DP83822_PHY_ID1) { + res =3D dp83822_conf_leds(dev); + if (res < 0) { + netdev_warn(dev, "Failed to configure DP83822 LEDs: %d\n", res); + return res; + } + } + break; + case F218: + dat =3D phydev->phy_id & 0xffff; + + /* on F218 revert the Link and activity LED */ + if (dat =3D=3D PHY_ID2_KSZ8041_1 || dat =3D=3D PHY_ID2_KSZ8041_2) { + res =3D ksz8041_disable_leds(dev); + if (res < 0) { + netdev_warn(dev, "Failed to disable KSZ8041 LEDs: %d\n", res); + return res; + } + } + } + + /* disable powerdown mode */ + reg_val =3D phy_read(dev->phydev, MII_100_BASE_TX_PHY); + if (reg_val >=3D 0) { + reg_val &=3D ~(MII_100BASE_PWR); + res =3D phy_write(dev->phydev, MII_100_BASE_TX_PHY, reg_val); + if (res < 0) { + netdev_warn(dev, "Failed to write PHY powerdown register: %d\n", res); + return res; + } + } else { + netdev_warn(dev, "Failed to read PHY powerdown register: %d\n", reg_val)= ; + return reg_val; + } + + /* Reapply the current phylib settings after the PHY reset. */ + return z87_phy_init_mode(dev); +} + +static int z87_phy_reset(struct net_device *dev) +{ + struct z87_private *np =3D netdev_priv(dev); + u8 phy_addr =3D np->phy.phy_addr; + unsigned int wait_cnt =3D 1000; + s16 reg_val; + int res; + + phy_read(dev->phydev, MII_BMCR); + z87_read32(dev, Z087_REG_MIISTATUS); + res =3D phy_write(dev->phydev, MII_BMCR, BMCR_RESET); + if (res < 0) { + netdev_err(dev, "PHY %d reset failed!\n", phy_addr); + return res; + } + + msleep(300); + + while (--wait_cnt > 0) { + reg_val =3D phy_read(dev->phydev, MII_BMCR); + if (reg_val >=3D 0 && (reg_val & BMCR_RESET) =3D=3D 0) + break; + + usleep_range(10, 20); + } + + if (wait_cnt =3D=3D 0) { + netdev_err(dev, "PHY %d reset never completed!\n", phy_addr); + return -EIO; + } + + usleep_range(40, 50); + + phy_read(dev->phydev, MII_BMCR); + + return 0; +} + +static int z87_phy_set_defaults(struct net_device *dev) +{ + struct z87_private *np =3D netdev_priv(dev); + struct phy_device *phydev =3D dev->phydev; + + if (!phydev) + return -ENODEV; + + switch (np->phy_mode) { + case phymode_10hd: + phydev->autoneg =3D AUTONEG_DISABLE; + phydev->speed =3D SPEED_10; + phydev->duplex =3D DUPLEX_HALF; + break; + + case phymode_10fd: + phydev->autoneg =3D AUTONEG_DISABLE; + phydev->speed =3D SPEED_10; + phydev->duplex =3D DUPLEX_FULL; + break; + + case phymode_100hd: + phydev->autoneg =3D AUTONEG_DISABLE; + phydev->speed =3D SPEED_100; + phydev->duplex =3D DUPLEX_HALF; + break; + + case phymode_100fd: + phydev->autoneg =3D AUTONEG_DISABLE; + phydev->speed =3D SPEED_100; + phydev->duplex =3D DUPLEX_FULL; + break; + + case phymode_auto: + phydev->autoneg =3D AUTONEG_ENABLE; + break; + + default: + netdev_err(dev, "invalid PHY mode parameter %d\n", + np->phy_mode); + return -EINVAL; + } + + return 0; +} + +static int z87_phy_init_mode(struct net_device *dev) +{ + struct z87_private *np =3D netdev_priv(dev); + struct phy_device *phydev =3D dev->phydev; + int ret; + + if (!phydev) + return -ENODEV; + + if (phydev->duplex =3D=3D DUPLEX_HALF && !np->phy.hf_supported) { + netdev_warn(dev, "Half-duplex not supported by hardware, aborting\n"); + return -EOPNOTSUPP; + } + + /* + * Tell phylib to apply the configured autoneg, speed, and duplex setting= s. + */ + ret =3D phy_start_aneg(phydev); + if (ret) + netdev_err(dev, "could not configure PHY mode: %d\n", ret); + + return ret; +} + +int z87_phy_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) +{ + if (!dev->phydev) + return -ENODEV; + + return phy_mii_ioctl(dev->phydev, ifr, cmd); +} + +void z87_phy_regdump(struct net_device *dev) +{ + struct z87_private *np =3D netdev_priv(dev); + const char *link_type; + s16 dat =3D 0; + + netdev_info(dev, "----- MII Registers -----\n"); + netdev_info(dev, "instance\t\t\t0x%02x\n", np->instance); + netdev_info(dev, "PHY ADR\t\t\t0x%02x\n", np->phy.phy_addr); + + dat =3D phy_read(dev->phydev, MII_BMCR); + if (dat >=3D 0) + netdev_info(dev, "MII_BMCR\t\t\t0x%04x\n", dat); + else + netdev_info(dev, "MII_BMCR\t\t\tError (%d)\n", dat); + + /* initially the link status isn't up to date, read it twice.. */ + dat =3D phy_read(dev->phydev, MII_BMSR); + dat =3D phy_read(dev->phydev, MII_BMSR); + + if (dat >=3D 0) + netdev_info(dev, "MII_BMSR\t\t0x%04x\tLink: %s\n", + dat, (dat & BMSR_LSTATUS) ? "up" : "down"); + else + netdev_info(dev, "MII_BMSR\t\tError (%d)\n", dat); + + dat =3D phy_read(dev->phydev, MII_PHYSID1); + if (dat >=3D 0) + netdev_info(dev, "MII_PHYSID1\t\t0x%04x\n", dat); + else + netdev_info(dev, "MII_PHYSID1\t\tError (%d)\n", dat); + + dat =3D phy_read(dev->phydev, MII_PHYSID2); + if (dat >=3D 0) + netdev_info(dev, "MII_PHYSID2\t\t0x%04x\n", dat); + else + netdev_info(dev, "MII_PHYSID2\t\tError (%d)\n", dat); + + dat =3D phy_read(dev->phydev, MII_ADVERTISE); + if (dat >=3D 0) + netdev_info(dev, "MII_ADVERTISE\t\t0x%04x\n", dat); + else + netdev_info(dev, "MII_ADVERTISE\t\tError (%d)\n", dat); + + dat =3D phy_read(dev->phydev, MII_LPA); + if (dat >=3D 0) + netdev_info(dev, "MII_LPA\t\t\t0x%04x\n", dat); + else + netdev_info(dev, "MII_LPA\t\t\tError (%d)\n", dat); + + dat =3D phy_read(dev->phydev, MII_100_BASE_TX_PHY); + if (dat >=3D 0) { + /* dump PHY Op Mode Indication Reg. Bits [4..2] */ + switch ((dat & 0x1c) >> 2) { + case 0x0: + link_type =3D "Autoneg"; + break; + case 0x1: + link_type =3D "10MB HD"; + break; + case 0x2: + link_type =3D "100MB HD"; + break; + case 0x3: + link_type =3D "Default"; + break; + case 0x5: + link_type =3D "10MB FD"; + break; + case 0x6: + link_type =3D "100MB FD"; + break; + case 0x7: + link_type =3D "PHY Isolated"; + break; + default: + link_type =3D "unknown"; + break; + } + netdev_info(dev, "MII_100_BASE_TX_PHY\t0x%04x (%s)\n", dat, link_type); + } else { + netdev_info(dev, "MII_100_BASE_TX_PHY\tError (%d)\n", dat); + } +} diff --git a/drivers/net/ethernet/men/z87/men_z87_phy.h b/drivers/net/ether= net/men/z87/men_z87_phy.h new file mode 100644 index 000000000000..0f6fe68b3510 --- /dev/null +++ b/drivers/net/ethernet/men/z87/men_z87_phy.h @@ -0,0 +1,27 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Copyright (c) 2026 duagon Germany GmbH + * + * See MAINTAINERS file for support contact information. + */ + +#ifndef _MEN_Z87_PHY_ +#define _MEN_Z87_PHY_ + +enum phymodes { + phymode_auto, /* 0 */ + phymode_10hd, /* 1 */ + phymode_10fd, /* 2 */ + phymode_100hd, /* 3 */ + phymode_100fd /* 4 */ +}; + +int z87_phy_register_mdio(struct net_device *dev); +int z87_phy_unregister_mdio(struct net_device *dev); +int z87_phy_connect(struct net_device *dev); +int z87_phy_disconnect(struct net_device *dev); +int z87_phy_init(struct net_device *dev); +int z87_phy_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd); +void z87_phy_regdump(struct net_device *dev); + +#endif /* _MEN_Z87_PHY_ */ diff --git a/drivers/net/ethernet/men/z87/men_z87_regs.h b/drivers/net/ethe= rnet/men/z87/men_z87_regs.h new file mode 100644 index 000000000000..681b62ced243 --- /dev/null +++ b/drivers/net/ethernet/men/z87/men_z87_regs.h @@ -0,0 +1,98 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Copyright (c) 2026 duagon Germany GmbH + * + * See MAINTAINERS file for support contact information. + */ + +#ifndef _MEN_Z87_REGS_H_ +#define _MEN_Z87_REGS_H_ + +#include + +/* Z087_REGISTERS */ +#define Z087_REG_MODER 0x00 /* Mode control */ +#define Z087_REG_INT_SRC 0x04 /* IRQ source */ +#define Z087_REG_INT_MASK 0x08 /* IRQ Masking */ +#define Z087_REG_PACKLEN 0x18 /* Packet Len (min/max) */ +#define Z087_REG_COLLCONF 0x1c /* Collision/Retry Conf */ +#define Z087_REG_CTRLMODER 0x24 /* Control Module Mode */ +#define Z087_REG_MIIMODER 0x28 /* MII Mode Register */ +#define Z087_REG_MIICMD 0x2c /* MII command */ +#define Z087_REG_MIIADR 0x30 /* MII Address */ +#define Z087_REG_MIITX_DATA 0x34 /* MII Transmit Data */ +#define Z087_REG_MIIRX_DATA 0x38 /* MII Receive Data */ +#define Z087_REG_MIISTATUS 0x3c /* MII Status */ +#define Z087_REG_MAC_ADDR0 0x40 /* MAC Addr[0-3] */ +#define Z087_REG_MAC_ADDR1 0x44 /* MAC Addr[4-5] */ +#define Z087_REG_HASH_ADDR0 0x48 /* Hash Reg 0 */ +#define Z087_REG_HASH_ADDR1 0x4c /* Hash Reg 1 */ +#define Z087_REG_TXCTRL 0x50 /* TX control */ +#define Z087_REG_BDSTART 0x5c /* Startaddr of TxRx BDs */ +#define Z087_REG_RXEMPTY0 0x60 /* RxBD[31:0] empty Flag */ +#define Z087_REG_RXEMPTY1 0x64 /* RxBD[63:32]empty Flag */ +#define Z087_REG_TXEMPTY0 0x68 /* TxBD[31:0] empty Flag */ +#define Z087_REG_TXEMPTY1 0x6c /* TxBD[63:32]empty Flag */ +#define Z087_REG_RXBDSTAT 0x70 /* RxBD count and status */ +#define Z087_REG_SMBCTRL 0x74 /* SMBus bitbang interface */ +#define Z087_REG_COREREV 0x78 /* core revision register */ +#define Z087_REG_RXERRCNT1 0x7c /* Symbol/CRC errors count */ +#define Z087_REG_RXERRCNT2 0x80 /* # of rcvd Frames/busy Err count */ +#define Z087_REG_TXERRCNT1 0x84 /* FIFO underrun/Late coll. count */ +#define Z087_REG_TXERRCNT2 0x88 /* # of sent frames/TxBD full count */ + +/* TXDB Tx Buffer Descriptor Bits */ +#define OETH_TX_BD_UNDERRUN BIT(8) /* Tx BD Underrun Status */ +#define OETH_TX_BD_RETRY GENMASK(7, 4) /* Tx BD Retry Status */ +#define OETH_TX_BD_RETLIM BIT(3) /* Tx BD Retransm Limit Stat */ +#define OETH_TX_BD_LATECOL BIT(2) /* Tx BD Late Collision Stat */ +#define OETH_TX_BD_DEFER BIT(1) /* Tx BD Defer Status */ +#define OETH_TX_BD_CARRIER BIT(0) /* Tx BD Carrier Sense Lost Status */ + +/* RXDB Rx Buffer Descriptor Bits */ +#define OETH_RX_BD_EMPTY BIT(15) /* Rx BD Empty */ +#define OETH_RX_BD_OVERRUN BIT(6) /* Rx BD Overrun Status */ +#define OETH_RX_BD_INVSYMB BIT(5) /* Rx BD Invalid Symbol Status */ +#define OETH_RX_BD_DRIBBLE BIT(4) /* Rx BD Dribble Nibble Status */ +#define OETH_RX_BD_TOOLONG BIT(3) /* Rx BD Too Long Status */ +#define OETH_RX_BD_SHORT BIT(2) /* Rx BD Too Short Frame Status */ +#define OETH_RX_BD_CRCERR BIT(1) /* Rx BD CRC Error Status */ +#define OETH_RX_BD_LATECOL BIT(0) /* Rx BD Late Collision Status */ + +/* COREREV Core Revision Bits */ +#define REG_COREREV_IRQNEWEN BIT(8) /* Enable new interrupt behavior */ + +/* MODER Register bits description */ +#define OETH_MODER_RXEN BIT(0) /* Receive Enable */ +#define OETH_MODER_TXEN BIT(1) /* Transmit Enable */ +#define OETH_MODER_BRO BIT(3) /* Broadcast Enable*/ +#define OETH_MODER_IAM BIT(4) /* Use Individual Hash */ +#define OETH_MODER_PRO BIT(5) /* Promisc Mode */ +#define OETH_MODER_IFG BIT(6) /* Min. IFG not required REV01:NA */ +#define OETH_MODER_EXDFREN BIT(9) /* Excess Defer REV01:NA */ +#define OETH_MODER_FULLD BIT(10) /* Full Duplex */ +#define OETH_MODER_CRCEN BIT(13) /* CRC Enable */ +#define OETH_MODER_PAD BIT(15) /* Pad Enable */ +#define OETH_MODER_RECSMALL BIT(16) /* Receive Small REV01:NA */ +#define OETH_MODER_RX_IDLE BIT(17) /* RX Idle Status */ +#define OETH_MODER_TX_IDLE BIT(18) /* TX Idle Status */ +#define OETH_MODER_HD_AVAL BIT(19) /* Half duplex available */ + +/* INTS Interrupt Source Register bits description */ +#define OETH_INT_TXF BIT(0) /* Transmit Frame IRQ */ +#define OETH_INT_TXE BIT(1) /* Transmit Error IRQ */ +#define OETH_INT_RXF BIT(2) /* Receive Frame IRQ */ +#define OETH_INT_RXE BIT(3) /* Receive Error IRQ */ + +/* CMDR MII Command Register */ +#define OETH_MIICMD_RSTAT BIT(1) /* Read Status */ +#define OETH_MIICMD_WCTRLDATA BIT(2) /* Write Control Data */ + +/* MIISR MII Status Register */ +#define OETH_MIISTATUS_BUSY BIT(1) /* MII Busy */ + +/* MISCR Misc defines */ +#define MII_100_BASE_TX_PHY 0x1f +#define MII_100BASE_PWR BIT(10) + +#endif /* _MEN_Z87_REGS_H_ */ --=20 2.56.1