From patchwork Mon Aug 19 00:53:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: FUJITA Tomonori X-Patchwork-Id: 13767696 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8A978D2F5; Mon, 19 Aug 2024 01:00:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724029235; cv=none; b=Rl41TlodZN0o5JX5R2VwbpqqIM22LiD8SDFXKdkPaIge3Pb2lGG1C65DlYYndlb/rZJsL68JCnpxuKTV9A/rad2R10GKpC2Hctp9jDI24JWQaOcLnh8fTV5wJGz6znZeAa6Bkq9/liFlDUCSjGo7iIWVPmCevS2I9CmwHKIuVCo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724029235; c=relaxed/simple; bh=RILoisfnGBbOpWeCATqosphpuf8tPEXjX4axWzXpG/w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bTKiM50baTx6WfVCwqqlcLV5bvci4YD5AZ7TPpEp/Xh752owtwZuibBo1JCD9QiOeqr9+D+L4cm+cSYRFr6rGz2pH4cdBQCbX4P0S20bd2wISkaLWXJGyacrVEtWHveQx1JhtdqACZOxiqTCxYFF1zFJa30DeO/fgXlBtzGQe54= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=juqeIyGl; arc=none smtp.client-ip=209.85.210.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="juqeIyGl" Received: by mail-pf1-f179.google.com with SMTP id d2e1a72fcca58-70d19bfdabbso100381b3a.2; Sun, 18 Aug 2024 18:00:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724029233; x=1724634033; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Q1hypnzEtFF41K4hUiN7kQ5KHZD5MuFGpfmnmIufdSM=; b=juqeIyGlxvecj9DBuTCNOm6ahAg8FGpk/or0gYV6e6SCbfx4NH2vyk73TVgf4R8KF/ TZ+12TXCIF/Jl7LFnNQHt9vnGPovs1xyP8kSJCUgs+vEMKdCp1hGHLj1kHrV7UzEDItC d8lydrBaJtcS9VDnqziKm0Qitvpuple2u6Yv88NhUWvQP9mIXDIjko7OJeVUk5BBfCi1 DfTayEReQ8oWdN3fUs9hGrHaXYOHv9s/vVLBo8cbdqztyh8pER2euQGKXT4tShxSKbaZ jGcBZ5u6D5PEdsjSUx497olOMC68SyECK1CBnbMUKggMQNBJccOiRXoGSLJFdrCZf/Q2 vhkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724029233; x=1724634033; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Q1hypnzEtFF41K4hUiN7kQ5KHZD5MuFGpfmnmIufdSM=; b=Yxpg8o49mkBhi7P84J/yoPGz7LNdgBsk3Vc2pOLOtJH0XDMrPCH8WE20dJKAtjG1/Z SiNlzOdhS9+hdkXR6vk0eQEurmg+37sFODK1shqAsAKFEewjC8BLnJn6u+cVoBMVJ8Gl msvRl+0fl//460WJlK1rmQMX6/x1TQ3JoYI+I5dZIG/MdXiS8A5tK+y0GnjqLUVvF/8n YSBSTXMaqSHkTfgFtb6UgHsHBo45W8tcURybZG2KYxRBm7ywcChUe6hNK3QVL5pS2zQa L+oTn3oUUtlqYJNSWn0rDfTlEGDnjremMoebkCm2KON8CNyqe01/XQBq6kbNbZO+0WI6 jStQ== X-Gm-Message-State: AOJu0Yw6IQNMnF1bDtgnLNn2ULMhtyj/hWblX9Hfu1isi5XZ6C4qw6cp To3SWJ1NnX3gycWPpU2CUN6kZu3GSMjyjI0n/nmHc/wBtt0aNaQEKOJYFt2e X-Google-Smtp-Source: AGHT+IHB9Zz2I8FO/a02tFKjlRvD/n0kK/a8ZcST3swTLiu3NjMXxaM9KxK4giOsnIOnTSOq7+h+Xw== X-Received: by 2002:a05:6a00:9146:b0:706:32d1:f6c9 with SMTP id d2e1a72fcca58-713c559c92amr7129543b3a.2.1724029232611; Sun, 18 Aug 2024 18:00:32 -0700 (PDT) Received: from localhost.localdomain (p4468007-ipxg23001hodogaya.kanagawa.ocn.ne.jp. [153.204.200.7]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7127af3c4a7sm5718732b3a.193.2024.08.18.18.00.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Aug 2024 18:00:32 -0700 (PDT) From: FUJITA Tomonori To: netdev@vger.kernel.org Cc: rust-for-linux@vger.kernel.org, andrew@lunn.ch, tmgross@umich.edu, miguel.ojeda.sandonis@gmail.com, benno.lossin@proton.me, aliceryhl@google.com Subject: [PATCH net-next v5 1/6] rust: sizes: add commonly used constants Date: Mon, 19 Aug 2024 00:53:40 +0000 Message-ID: <20240819005345.84255-2-fujita.tomonori@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240819005345.84255-1-fujita.tomonori@gmail.com> References: <20240819005345.84255-1-fujita.tomonori@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Add rust equivalent to include/linux/sizes.h, makes code more readable. Reviewed-by: Alice Ryhl Reviewed-by: Andrew Lunn Reviewed-by: Benno Lossin Signed-off-by: FUJITA Tomonori Reviewed-by: Trevor Gross --- rust/kernel/lib.rs | 1 + rust/kernel/sizes.rs | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 rust/kernel/sizes.rs diff --git a/rust/kernel/lib.rs b/rust/kernel/lib.rs index 274bdc1b0a82..58ed400198bf 100644 --- a/rust/kernel/lib.rs +++ b/rust/kernel/lib.rs @@ -43,6 +43,7 @@ pub mod page; pub mod prelude; pub mod print; +pub mod sizes; mod static_assert; #[doc(hidden)] pub mod std_vendor; diff --git a/rust/kernel/sizes.rs b/rust/kernel/sizes.rs new file mode 100644 index 000000000000..834c343e4170 --- /dev/null +++ b/rust/kernel/sizes.rs @@ -0,0 +1,26 @@ +// SPDX-License-Identifier: GPL-2.0 + +//! Commonly used sizes. +//! +//! C headers: [`include/linux/sizes.h`](srctree/include/linux/sizes.h). + +/// 0x00000400 +pub const SZ_1K: usize = bindings::SZ_1K as usize; +/// 0x00000800 +pub const SZ_2K: usize = bindings::SZ_2K as usize; +/// 0x00001000 +pub const SZ_4K: usize = bindings::SZ_4K as usize; +/// 0x00002000 +pub const SZ_8K: usize = bindings::SZ_8K as usize; +/// 0x00004000 +pub const SZ_16K: usize = bindings::SZ_16K as usize; +/// 0x00008000 +pub const SZ_32K: usize = bindings::SZ_32K as usize; +/// 0x00010000 +pub const SZ_64K: usize = bindings::SZ_64K as usize; +/// 0x00020000 +pub const SZ_128K: usize = bindings::SZ_128K as usize; +/// 0x00040000 +pub const SZ_256K: usize = bindings::SZ_256K as usize; +/// 0x00080000 +pub const SZ_512K: usize = bindings::SZ_512K as usize; From patchwork Mon Aug 19 00:53:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: FUJITA Tomonori X-Patchwork-Id: 13767697 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pj1-f46.google.com (mail-pj1-f46.google.com [209.85.216.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6BCED208A0; Mon, 19 Aug 2024 01:00:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724029237; cv=none; b=ar2S/FGund1aqCUrUaMB7FNqOjwONZAovfQC9blEbTxF77BH6hOEcdB5IE83s+bGJvWnSlYfc3Tsz8+eVPyNnY4OMydgl89XQeXUFlKABHvy8CY3zQ1pBmwGlUe/dg/aNpPMhcAJMFOWUdnEQ0oe/GpOyzpef5Rldx/EMVus9ys= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724029237; c=relaxed/simple; bh=vUIxXGv09GRc5aBu/neSNb1GummZ9qZKEeeQN0wo22A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jwcCSIqSzh8OsSKTLuPqnHuMsfF7jvJ2usRE7FQQXtQYeee1lHlefuGEmkqn4d/aKbc2RwLhIjBH9tyRqpIJ6CWlOpwsps8duc2iTAqC1qkeJ02KzZe5GXULULoZnli+eTRYQlz9t/FNXG9EUiOaLLufkgrM98qWSYfaYovVTLk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=jDkRtaEs; arc=none smtp.client-ip=209.85.216.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="jDkRtaEs" Received: by mail-pj1-f46.google.com with SMTP id 98e67ed59e1d1-2d3f39e7155so466154a91.0; Sun, 18 Aug 2024 18:00:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724029235; x=1724634035; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=XazJ8mTlycGs5dNR+W4h8gQItndR+sDYEfDvhQ5CokM=; b=jDkRtaEsUfnM2aj6CZd0hTO0EbrB1AEQXtKYEqqCNIbFvkKPoOTbfPBKLll+5WDnwa ClB/mxlTU3UVUqC7MIn3YErCBuv3K2CNpRTMjmpgxG2C52f4tkUdYMSmWByV4HdWFY96 izURF2NVXFBkwQ/fwHJ6r97Wh4hr2lrj9rtEq9OAUCKsNvGwYmWCbpqCda3Z7RFjrgtB T66ZQGoFpuS1a0PSdk2q6trIMLGq7FhQnrh0ggjgxlhKi35Yskzm3sLoJC4qrD2aBncs 4rxKsC75Rzjm4Z8JILji4XAAYPiTxFHoWKGCMBPC0yg9Qr/cPsmV2u9W0W2iSULHtt5l OO7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724029235; x=1724634035; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=XazJ8mTlycGs5dNR+W4h8gQItndR+sDYEfDvhQ5CokM=; b=TFyWKw486WnGbAvGEic09a6wK/bfHBmW2Ydohbe1w9KzM+vNAk9mTX3cxWdQxYzZVo khaLUPThhdVpssPWJqkECCN8PpF6R0dwCq1F7MQkhRiV0j9NzLLw4TiyXDNGQKRsXfqh Skkem+JHDgwkFPImCazmj0iTr1sYejJJx1vGZka9LhnMBESBLVomrdFoYPEOMuVyGprl WSI/y+DzrkbNSWQX0f6ddxC6FQcS49wcex7ALby7hb/dxuz6/YN01ZYZOV9q8Zd+lXeG q5w8p49xu5/APvG7UDQuf5GLJ56DfnR6AvyBVl60x2H2LS5Bls3r5FVv06Zsjnhmu0b9 /Y1g== X-Gm-Message-State: AOJu0Ywzg49wr7zkJi2OIUCv/YSnK2VtRQY5/kk80oyq7thwFrmASCeK 0Y726PLA71PcvUdahk2Wz7y/0gTvTIN28FOh/zmNM8YMI1BL+GTl/U/Fx99m X-Google-Smtp-Source: AGHT+IHJEFDYL6xCYegZiVOw7O5OID8ZCfuLy8lrRNDqIrjpd8qx34ThaBBtGZP4h7U+Fdbr7XEO8w== X-Received: by 2002:a05:6a20:12cb:b0:1c6:bed1:bbd0 with SMTP id adf61e73a8af0-1c97beeffc0mr8608877637.0.1724029235068; Sun, 18 Aug 2024 18:00:35 -0700 (PDT) Received: from localhost.localdomain (p4468007-ipxg23001hodogaya.kanagawa.ocn.ne.jp. [153.204.200.7]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7127af3c4a7sm5718732b3a.193.2024.08.18.18.00.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Aug 2024 18:00:34 -0700 (PDT) From: FUJITA Tomonori To: netdev@vger.kernel.org Cc: rust-for-linux@vger.kernel.org, andrew@lunn.ch, tmgross@umich.edu, miguel.ojeda.sandonis@gmail.com, benno.lossin@proton.me, aliceryhl@google.com Subject: [PATCH net-next v5 2/6] rust: net::phy support probe callback Date: Mon, 19 Aug 2024 00:53:41 +0000 Message-ID: <20240819005345.84255-3-fujita.tomonori@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240819005345.84255-1-fujita.tomonori@gmail.com> References: <20240819005345.84255-1-fujita.tomonori@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Support phy_driver probe callback, used to set up device-specific structures. Reviewed-by: Alice Ryhl Reviewed-by: Andrew Lunn Reviewed-by: Benno Lossin Signed-off-by: FUJITA Tomonori Reviewed-by: Trevor Gross --- rust/kernel/net/phy.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/rust/kernel/net/phy.rs b/rust/kernel/net/phy.rs index fd40b703d224..5e8137a1972f 100644 --- a/rust/kernel/net/phy.rs +++ b/rust/kernel/net/phy.rs @@ -338,6 +338,21 @@ impl Adapter { }) } + /// # Safety + /// + /// `phydev` must be passed by the corresponding callback in `phy_driver`. + unsafe extern "C" fn probe_callback(phydev: *mut bindings::phy_device) -> core::ffi::c_int { + from_result(|| { + // SAFETY: This callback is called only in contexts + // where we can exclusively access `phy_device` because + // it's not published yet, so the accessors on `Device` are okay + // to call. + let dev = unsafe { Device::from_raw(phydev) }; + T::probe(dev)?; + Ok(0) + }) + } + /// # Safety /// /// `phydev` must be passed by the corresponding callback in `phy_driver`. @@ -511,6 +526,11 @@ pub const fn create_phy_driver() -> DriverVTable { } else { None }, + probe: if T::HAS_PROBE { + Some(Adapter::::probe_callback) + } else { + None + }, get_features: if T::HAS_GET_FEATURES { Some(Adapter::::get_features_callback) } else { @@ -583,6 +603,11 @@ fn soft_reset(_dev: &mut Device) -> Result { kernel::build_error(VTABLE_DEFAULT_ERROR) } + /// Sets up device-specific structures during discovery. + fn probe(_dev: &mut Device) -> Result { + kernel::build_error(VTABLE_DEFAULT_ERROR) + } + /// Probes the hardware to determine what abilities it has. fn get_features(_dev: &mut Device) -> Result { kernel::build_error(VTABLE_DEFAULT_ERROR) From patchwork Mon Aug 19 00:53:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: FUJITA Tomonori X-Patchwork-Id: 13767698 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pj1-f47.google.com (mail-pj1-f47.google.com [209.85.216.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DE06F225D6; Mon, 19 Aug 2024 01:00:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724029240; cv=none; b=UpQMLjCS8pQkxGaPnHCdygSkUIx/82SzdCMCkvYiPk9Zl/mmr72ztmbLjPsWVgB1bJDwJSoKWbtwBo2K/vS3LR/ossWCnVlqpuU33vwxJobJLB6/IJZaeoDg8k4DSjYzGsrqGY/bcgI8W2GjCfuJNH1LUYBXmX6i6TGxOQ2o4sw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724029240; c=relaxed/simple; bh=hO8jaPoe8Z8KfyUx9xcnRBOH6nmrdlSVRLp7CB+itpI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RiQUkQQoNINFNTaHpwfgVULjNwK7DarPHk4QT0XVGu7XFE/zMao0Wl9ccL7JMTDo6EkoWcI3rSGo4f2w4qV9l9QUEJlkfagLrTS4AYq7yXm4KUL7dUwcOpyuJUpvw87MInUt2bmcf919xANCKofEkmqMFDeAGslYz0gzc0IboDc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Goye6Rjr; arc=none smtp.client-ip=209.85.216.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Goye6Rjr" Received: by mail-pj1-f47.google.com with SMTP id 98e67ed59e1d1-2d3e6fd744fso516501a91.3; Sun, 18 Aug 2024 18:00:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724029238; x=1724634038; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=LZYPHOtPx499jxXDsFggcgwM/32QfaN5aB36q4eX0TE=; b=Goye6RjrRf0wXZFySvYYGCnCSaWHn338IrOMefvdhLQvt6GLSTj+QZp/mhu6dejn7I wCj9thpqbb1HQZJJLAEoEAZ3N6YxdkGiHUinq4byQ+Sj1NWCpQQAXzfyD3ScCymGpqH8 3kzwFIHFrJdsSorrX2U76xeAgOG4kAFVjyBNCCrPHUoRHJbPu0wb8x8qa3KRoxiegnXd PwUbyxkJGHmpKOw9vP/Ri26DIT3z9owkijEMle4r72DBtu7Ye4mobNDW2/31h8X+4/xi fnCAfc9KBlBck0AtshzuFrB+uGQlplQ0PJnq7CIFrhCGOI+wr8rWDRhc/OuRGj2Fczhz GFIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724029238; x=1724634038; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=LZYPHOtPx499jxXDsFggcgwM/32QfaN5aB36q4eX0TE=; b=KOObjw5YVL2+m5FyqKSS7r7z6XvjBOFrNouTilIySNkIWlJKj280eSnnD+Qcl2OFSl oqLEmuGomXVTQnytc3EiGVRGTRGTWWReWAlmcrgoVKZO4gUUs04GIqGErNtdxKcQzhU6 Ro5dXS0YypZJWLqlOn2B8wSGEvj9meyIiPwqdVNRNUCEYg8mWW+lp131YcnQa/VEHY+p WzYtzrZqhg7Bf+4kjsLQxPHb3UYChJ4l750QOz5oJEMRvjroQAIfAUr/rXdnrt8tjeJO 2DIbGF4Kn8AemlKqN1Ndt/f2UkakOZgNq4q183bmAhowt1BEtxlaZNEIuooI6Q3VfLqE DJ7A== X-Gm-Message-State: AOJu0YwyFLSSrKsT8BNjJxj4PiXRqtDw1o5FeTwpmBi5q3X4N98Pi0il Ng5EnijgvfXU6z+BCMY7+qO0xgfMPtFmteU1JaEIwf/XSu2rrxOYD5r4xlGN X-Google-Smtp-Source: AGHT+IGAZe+EWkE7wSRPBqFNaDEznu42gvDVmAKTD4JQZEvoQmR66oE7TIrhnTZiMciVhE5YXe4lZg== X-Received: by 2002:a05:6a00:9446:b0:710:5d44:5fe6 with SMTP id d2e1a72fcca58-713c557a36amr7082330b3a.1.1724029237585; Sun, 18 Aug 2024 18:00:37 -0700 (PDT) Received: from localhost.localdomain (p4468007-ipxg23001hodogaya.kanagawa.ocn.ne.jp. [153.204.200.7]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7127af3c4a7sm5718732b3a.193.2024.08.18.18.00.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Aug 2024 18:00:37 -0700 (PDT) From: FUJITA Tomonori To: netdev@vger.kernel.org Cc: rust-for-linux@vger.kernel.org, andrew@lunn.ch, tmgross@umich.edu, miguel.ojeda.sandonis@gmail.com, benno.lossin@proton.me, aliceryhl@google.com Subject: [PATCH net-next v5 3/6] rust: net::phy implement AsRef trait Date: Mon, 19 Aug 2024 00:53:42 +0000 Message-ID: <20240819005345.84255-4-fujita.tomonori@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240819005345.84255-1-fujita.tomonori@gmail.com> References: <20240819005345.84255-1-fujita.tomonori@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Implement AsRef trait for Device. A PHY driver needs a reference to device::Device to call the firmware API. Reviewed-by: Alice Ryhl Reviewed-by: Andrew Lunn Reviewed-by: Benno Lossin Signed-off-by: FUJITA Tomonori Reviewed-by: Trevor Gross --- rust/kernel/net/phy.rs | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/rust/kernel/net/phy.rs b/rust/kernel/net/phy.rs index 5e8137a1972f..ec337cbd391b 100644 --- a/rust/kernel/net/phy.rs +++ b/rust/kernel/net/phy.rs @@ -7,8 +7,7 @@ //! C headers: [`include/linux/phy.h`](srctree/include/linux/phy.h). use crate::{error::*, prelude::*, types::Opaque}; - -use core::marker::PhantomData; +use core::{marker::PhantomData, ptr::addr_of_mut}; /// PHY state machine states. /// @@ -58,8 +57,9 @@ pub enum DuplexMode { /// /// # Invariants /// -/// Referencing a `phy_device` using this struct asserts that you are in -/// a context where all methods defined on this struct are safe to call. +/// - Referencing a `phy_device` using this struct asserts that you are in +/// a context where all methods defined on this struct are safe to call. +/// - This struct always has a valid `self.0.mdio.dev`. /// /// [`struct phy_device`]: srctree/include/linux/phy.h // During the calls to most functions in [`Driver`], the C side (`PHYLIB`) holds a lock that is @@ -76,9 +76,11 @@ impl Device { /// /// # Safety /// - /// For the duration of 'a, the pointer must point at a valid `phy_device`, - /// and the caller must be in a context where all methods defined on this struct - /// are safe to call. + /// For the duration of 'a, + /// - the pointer must point at a valid `phy_device`, and the caller + /// must be in a context where all methods defined on this struct + /// are safe to call. + /// - `(*ptr).mdio.dev` must be a valid. unsafe fn from_raw<'a>(ptr: *mut bindings::phy_device) -> &'a mut Self { // CAST: `Self` is a `repr(transparent)` wrapper around `bindings::phy_device`. let ptr = ptr.cast::(); @@ -302,6 +304,14 @@ pub fn genphy_read_abilities(&mut self) -> Result { } } +impl AsRef for Device { + fn as_ref(&self) -> &kernel::device::Device { + let phydev = self.0.get(); + // SAFETY: The struct invariant ensures that `mdio.dev` is valid. + unsafe { kernel::device::Device::as_ref(addr_of_mut!((*phydev).mdio.dev)) } + } +} + /// Defines certain other features this PHY supports (like interrupts). /// /// These flag values are used in [`Driver::FLAGS`]. From patchwork Mon Aug 19 00:53:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: FUJITA Tomonori X-Patchwork-Id: 13767699 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-oa1-f45.google.com (mail-oa1-f45.google.com [209.85.160.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8B335288B1; Mon, 19 Aug 2024 01:00:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724029243; cv=none; b=f67WKATFJjD6UMt4MZdAC2RCYoudnV+K0e8EUBaV2L2N35Ff9emISnXQuUmEWvTQbGkCRahOyVyfnKhIB9e1CkD/lFToXNaluyfUFmzOE+qzYla8qxySYdEY1YXxgnn1qWGOYifrLoSb8A9+j6gDknWSkbfiV7x9rJLnEKFcEFQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724029243; c=relaxed/simple; bh=q/Bgt6hS8651i2+d8zy9jVVMWniaa0gU7wMEUHs3wpI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=V4LowlOY7q3zmJRM8x/PEhKK+al9MNakzukCEKkWtgTT4uiysYd8i6zfgDT37PCjIr6HkuZxtsCJ0pab4ReUd3wpzKgC3Nbr3Rl9bCRblPyCrHqC173N2zIrqVB3aHEJsxLntqIoc4PwSZNonDmn6rJVxMzKmTUrrwEOOJaNrHY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=cZV03Jcn; arc=none smtp.client-ip=209.85.160.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="cZV03Jcn" Received: by mail-oa1-f45.google.com with SMTP id 586e51a60fabf-25075f3f472so976180fac.2; Sun, 18 Aug 2024 18:00:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724029240; x=1724634040; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=c009J6ru/lcfwRxwS73u3FAW9qnNCYMrQg1B+fvluGw=; b=cZV03JcndTX5SSQVh3z/AdS1vkDXFzrWfE/zIzStpwXyEngCz2lmCypbarg1Z4F42L nejqD1raENC1U+UBI8pJIX/mkFhaRVIDCyGuQBlNRB1dLRzj2UBW6GwqgryGi0m3zCn/ R67mwoQSB1zb4D+fCigzKh4c1SL/8JOjEpkpGHNkEFxY4rQPncIZe5qIB+JJ96dXoN81 rTgwM0potkLMdAX1/w/ra9hbx7oM45tuN33Sm0LXRXrs7uBCaoU8ehsBgi2uPPdFHfpr TC2M2DmQJ1mZJLSFnwmsop+vgjLlJhkASy0bqra3znk4Er/7BWoTPSAclwfe8DYyc0VG v9ug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724029240; x=1724634040; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=c009J6ru/lcfwRxwS73u3FAW9qnNCYMrQg1B+fvluGw=; b=w8UKCeaqH/mOnm18U2kM8h8UeqVagwJBLP956GdegJ8MhheQ3r+3EigoBPlXU/dNw+ PKb1JKJzKtviyj+t5vmbxIxzzZpvv5/jE+jK1FceeMpdgzEQZ6JJFrox5vMXO8t339Lw Ryggd0F6WzD0OmM3I0DpJUbNJdm5CUr9O1umxZRtQPVy8wP9zI/D0YD/wtEdCpF2ZyKg dmlLZHhSbTkqS5WADAQqVo33/gT0o9mQNzI6T7z4mlmyPpuCB5WpfzhQzWsyDGvSrvLv w1MP5GvqrXYlzYSGne6t1YHWBGXOKAYNQEbqY+yq62A0Jl/X2A2XiggrohnSKW8aZKda DXnA== X-Gm-Message-State: AOJu0YwrCkngye5dpfSfPwSvARvSIbhr6pt+OlkvnplQabtqqmw9N3VX 1U/ybhvhoBZd2Xgv8xUsriErVxj6oZkE9y+sr9ybNt86j+L4LNDzT3OIHgjm X-Google-Smtp-Source: AGHT+IGc/lgMi4mfe4/uDzGtUOJdubjwwLKncTexL2PsyUGADUwRjTEOKXoJcwZ+3SsNae2f3ZJ3qA== X-Received: by 2002:a05:6870:c112:b0:254:d417:351f with SMTP id 586e51a60fabf-2701c35054bmr5498717fac.1.1724029240190; Sun, 18 Aug 2024 18:00:40 -0700 (PDT) Received: from localhost.localdomain (p4468007-ipxg23001hodogaya.kanagawa.ocn.ne.jp. [153.204.200.7]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7127af3c4a7sm5718732b3a.193.2024.08.18.18.00.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Aug 2024 18:00:39 -0700 (PDT) From: FUJITA Tomonori To: netdev@vger.kernel.org Cc: rust-for-linux@vger.kernel.org, andrew@lunn.ch, tmgross@umich.edu, miguel.ojeda.sandonis@gmail.com, benno.lossin@proton.me, aliceryhl@google.com Subject: [PATCH net-next v5 4/6] rust: net::phy unified read/write API for C22 and C45 registers Date: Mon, 19 Aug 2024 00:53:43 +0000 Message-ID: <20240819005345.84255-5-fujita.tomonori@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240819005345.84255-1-fujita.tomonori@gmail.com> References: <20240819005345.84255-1-fujita.tomonori@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Add the unified read/write API for C22 and C45 registers. The abstractions support access to only C22 registers now. Instead of adding read/write_c45 methods specifically for C45, a new reg module supports the unified API to access C22 and C45 registers with trait, by calling an appropriate phylib functions. Reviewed-by: Trevor Gross Reviewed-by: Benno Lossin Reviewed-by: Andrew Lunn Signed-off-by: FUJITA Tomonori --- MAINTAINERS | 1 + drivers/net/phy/ax88796b_rust.rs | 7 +- rust/kernel/net/phy.rs | 31 ++--- rust/kernel/net/phy/reg.rs | 194 +++++++++++++++++++++++++++++++ rust/uapi/uapi_helper.h | 1 + 5 files changed, 207 insertions(+), 27 deletions(-) create mode 100644 rust/kernel/net/phy/reg.rs diff --git a/MAINTAINERS b/MAINTAINERS index 5dbf23cf11c8..9dbfcf77acb2 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -8354,6 +8354,7 @@ L: netdev@vger.kernel.org L: rust-for-linux@vger.kernel.org S: Maintained F: rust/kernel/net/phy.rs +F: rust/kernel/net/phy/reg.rs EXEC & BINFMT API, ELF R: Eric Biederman diff --git a/drivers/net/phy/ax88796b_rust.rs b/drivers/net/phy/ax88796b_rust.rs index 5c92572962dc..8c7eb009d9fc 100644 --- a/drivers/net/phy/ax88796b_rust.rs +++ b/drivers/net/phy/ax88796b_rust.rs @@ -6,7 +6,7 @@ //! C version of this driver: [`drivers/net/phy/ax88796b.c`](./ax88796b.c) use kernel::{ c_str, - net::phy::{self, DeviceId, Driver}, + net::phy::{self, reg::C22, DeviceId, Driver}, prelude::*, uapi, }; @@ -24,7 +24,6 @@ license: "GPL", } -const MII_BMCR: u16 = uapi::MII_BMCR as u16; const BMCR_SPEED100: u16 = uapi::BMCR_SPEED100 as u16; const BMCR_FULLDPLX: u16 = uapi::BMCR_FULLDPLX as u16; @@ -33,7 +32,7 @@ // Toggle BMCR_RESET bit off to accommodate broken AX8796B PHY implementation // such as used on the Individual Computers' X-Surf 100 Zorro card. fn asix_soft_reset(dev: &mut phy::Device) -> Result { - dev.write(uapi::MII_BMCR as u16, 0)?; + dev.write(C22::BMCR, 0)?; dev.genphy_soft_reset() } @@ -55,7 +54,7 @@ fn read_status(dev: &mut phy::Device) -> Result { } // If MII_LPA is 0, phy_resolve_aneg_linkmode() will fail to resolve // linkmode so use MII_BMCR as default values. - let ret = dev.read(MII_BMCR)?; + let ret = dev.read(C22::BMCR)?; if ret & BMCR_SPEED100 != 0 { dev.set_speed(uapi::SPEED_100); diff --git a/rust/kernel/net/phy.rs b/rust/kernel/net/phy.rs index ec337cbd391b..c07accb08434 100644 --- a/rust/kernel/net/phy.rs +++ b/rust/kernel/net/phy.rs @@ -9,6 +9,8 @@ use crate::{error::*, prelude::*, types::Opaque}; use core::{marker::PhantomData, ptr::addr_of_mut}; +pub mod reg; + /// PHY state machine states. /// /// Corresponds to the kernel's [`enum phy_state`]. @@ -177,32 +179,15 @@ pub fn set_duplex(&mut self, mode: DuplexMode) { unsafe { (*phydev).duplex = v }; } - /// Reads a given C22 PHY register. + /// Reads a PHY register. // This function reads a hardware register and updates the stats so takes `&mut self`. - pub fn read(&mut self, regnum: u16) -> Result { - let phydev = self.0.get(); - // SAFETY: `phydev` is pointing to a valid object by the type invariant of `Self`. - // So it's just an FFI call, open code of `phy_read()` with a valid `phy_device` pointer - // `phydev`. - let ret = unsafe { - bindings::mdiobus_read((*phydev).mdio.bus, (*phydev).mdio.addr, regnum.into()) - }; - if ret < 0 { - Err(Error::from_errno(ret)) - } else { - Ok(ret as u16) - } + pub fn read(&mut self, reg: R) -> Result { + reg.read(self) } - /// Writes a given C22 PHY register. - pub fn write(&mut self, regnum: u16, val: u16) -> Result { - let phydev = self.0.get(); - // SAFETY: `phydev` is pointing to a valid object by the type invariant of `Self`. - // So it's just an FFI call, open code of `phy_write()` with a valid `phy_device` pointer - // `phydev`. - to_result(unsafe { - bindings::mdiobus_write((*phydev).mdio.bus, (*phydev).mdio.addr, regnum.into(), val) - }) + /// Writes a PHY register. + pub fn write(&mut self, reg: R, val: u16) -> Result { + reg.write(self, val) } /// Reads a paged register. diff --git a/rust/kernel/net/phy/reg.rs b/rust/kernel/net/phy/reg.rs new file mode 100644 index 000000000000..5fb05b79a956 --- /dev/null +++ b/rust/kernel/net/phy/reg.rs @@ -0,0 +1,194 @@ +// SPDX-License-Identifier: GPL-2.0 + +// Copyright (C) 2024 FUJITA Tomonori + +//! PHY register interfaces. +//! +//! This module provides support for accessing PHY registers in the +//! Ethernet management interface clauses 22 and 45 register namespaces, as +//! defined in IEEE 802.3. + +use super::Device; +use crate::build_assert; +use crate::error::*; +use crate::uapi; + +mod private { + /// Marker that a trait cannot be implemented outside of this crate + pub trait Sealed {} +} + +/// Accesses PHY registers. +/// +/// This trait is used to implement the unified interface to access +/// C22 and C45 PHY registers. +/// +/// # Examples +/// +/// ```ignore +/// fn link_change_notify(dev: &mut Device) { +/// // read C22 BMCR register +/// dev.read(C22::BMCR); +/// // read C45 PMA/PMD control 1 register +/// dev.read(C45::new(Mmd::PMAPMD, 0)); +/// } +/// ``` +pub trait Register: private::Sealed { + /// Reads a PHY register. + fn read(&self, dev: &mut Device) -> Result; + + /// Writes a PHY register. + fn write(&self, dev: &mut Device, val: u16) -> Result; +} + +/// A single MDIO clause 22 register address (5 bits). +pub struct C22(u8); + +impl C22 { + /// Basic mode control. + pub const BMCR: Self = C22(0x00); + /// Basic mode status. + pub const BMSR: Self = C22(0x01); + /// PHY identifier 1. + pub const PHYSID1: Self = C22(0x02); + /// PHY identifier 2. + pub const PHYSID2: Self = C22(0x03); + /// Auto-negotiation advertisement. + pub const ADVERTISE: Self = C22(0x04); + /// Auto-negotiation link partner base page ability. + pub const LPA: Self = C22(0x05); + /// Auto-negotiation expansion. + pub const EXPANSION: Self = C22(0x06); + /// Auto-negotiation next page transmit. + pub const NEXT_PAGE_TRANSMIT: Self = C22(0x07); + /// Auto-negotiation link partner received next page. + pub const LP_RECEIVED_NEXT_PAGE: Self = C22(0x08); + /// Master-slave control. + pub const MASTER_SLAVE_CONTROL: Self = C22(0x09); + /// Master-slave status. + pub const MASTER_SLAVE_STATUS: Self = C22(0x0a); + /// PSE Control. + pub const PSE_CONTROL: Self = C22(0x0b); + /// PSE Status. + pub const PSE_STATUS: Self = C22(0x0c); + /// MMD Register control. + pub const MMD_CONTROL: Self = C22(0x0d); + /// MMD Register address data. + pub const MMD_DATA: Self = C22(0x0e); + /// Extended status. + pub const EXTENDED_STATUS: Self = C22(0x0f); + + /// Creates a new instance of `C22` with a vendor specific register. + pub const fn vendor_specific() -> Self { + build_assert!( + N > 0x0f && N < 0x20, + "Vendor-specific register address must be between 16 and 31" + ); + C22(N) + } +} + +impl private::Sealed for C22 {} + +impl Register for C22 { + fn read(&self, dev: &mut Device) -> Result { + let phydev = dev.0.get(); + // SAFETY: `phydev` is pointing to a valid object by the type invariant of `Device`. + // So it's just an FFI call, open code of `phy_read()` with a valid `phy_device` pointer + // `phydev`. + let ret = unsafe { + bindings::mdiobus_read((*phydev).mdio.bus, (*phydev).mdio.addr, self.0.into()) + }; + to_result(ret)?; + Ok(ret as u16) + } + + fn write(&self, dev: &mut Device, val: u16) -> Result { + let phydev = dev.0.get(); + // SAFETY: `phydev` is pointing to a valid object by the type invariant of `Device`. + // So it's just an FFI call, open code of `phy_write()` with a valid `phy_device` pointer + // `phydev`. + to_result(unsafe { + bindings::mdiobus_write((*phydev).mdio.bus, (*phydev).mdio.addr, self.0.into(), val) + }) + } +} + +/// A single MDIO clause 45 register device and address. +pub struct Mmd(u8); + +impl Mmd { + /// Physical Medium Attachment/Dependent. + pub const PMAPMD: Self = Mmd(uapi::MDIO_MMD_PMAPMD as u8); + /// WAN interface sublayer. + pub const WIS: Self = Mmd(uapi::MDIO_MMD_WIS as u8); + /// Physical coding sublayer. + pub const PCS: Self = Mmd(uapi::MDIO_MMD_PCS as u8); + /// PHY Extender sublayer. + pub const PHYXS: Self = Mmd(uapi::MDIO_MMD_PHYXS as u8); + /// DTE Extender sublayer. + pub const DTEXS: Self = Mmd(uapi::MDIO_MMD_DTEXS as u8); + /// Transmission convergence. + pub const TC: Self = Mmd(uapi::MDIO_MMD_TC as u8); + /// Auto negotiation. + pub const AN: Self = Mmd(uapi::MDIO_MMD_AN as u8); + /// Separated PMA (1). + pub const SEPARATED_PMA1: Self = Mmd(8); + /// Separated PMA (2). + pub const SEPARATED_PMA2: Self = Mmd(9); + /// Separated PMA (3). + pub const SEPARATED_PMA3: Self = Mmd(10); + /// Separated PMA (4). + pub const SEPARATED_PMA4: Self = Mmd(11); + /// OFDM PMA/PMD. + pub const OFDM_PMAPMD: Self = Mmd(12); + /// Power unit. + pub const POWER_UNIT: Self = Mmd(13); + /// Clause 22 extension. + pub const C22_EXT: Self = Mmd(uapi::MDIO_MMD_C22EXT as u8); + /// Vendor specific 1. + pub const VEND1: Self = Mmd(uapi::MDIO_MMD_VEND1 as u8); + /// Vendor specific 2. + pub const VEND2: Self = Mmd(uapi::MDIO_MMD_VEND2 as u8); +} + +/// A single MDIO clause 45 register device and address. +/// +/// Clause 45 uses a 5-bit device address to access a specific MMD within +/// a port, then a 16-bit register address to access a location within +/// that device. `C45` represents this by storing a [`Mmd`] and +/// a register number. +pub struct C45 { + devad: Mmd, + regnum: u16, +} + +impl C45 { + /// Creates a new instance of `C45`. + pub fn new(devad: Mmd, regnum: u16) -> Self { + Self { devad, regnum } + } +} + +impl private::Sealed for C45 {} + +impl Register for C45 { + fn read(&self, dev: &mut Device) -> Result { + let phydev = dev.0.get(); + // SAFETY: `phydev` is pointing to a valid object by the type invariant of `Device`. + // So it's just an FFI call. + let ret = + unsafe { bindings::phy_read_mmd(phydev, self.devad.0.into(), self.regnum.into()) }; + to_result(ret)?; + Ok(ret as u16) + } + + fn write(&self, dev: &mut Device, val: u16) -> Result { + let phydev = dev.0.get(); + // SAFETY: `phydev` is pointing to a valid object by the type invariant of `Device`. + // So it's just an FFI call. + to_result(unsafe { + bindings::phy_write_mmd(phydev, self.devad.0.into(), self.regnum.into(), val) + }) + } +} diff --git a/rust/uapi/uapi_helper.h b/rust/uapi/uapi_helper.h index 08f5e9334c9e..76d3f103e764 100644 --- a/rust/uapi/uapi_helper.h +++ b/rust/uapi/uapi_helper.h @@ -7,5 +7,6 @@ */ #include +#include #include #include From patchwork Mon Aug 19 00:53:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: FUJITA Tomonori X-Patchwork-Id: 13767700 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-oo1-f50.google.com (mail-oo1-f50.google.com [209.85.161.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DE2E62941B; Mon, 19 Aug 2024 01:00:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724029245; cv=none; b=dWsmXoLQSRRIPe9zVWWhAMyn4rSI9Jo6OwKgwzVG9+LB03gCFgoSGjeRG1xhJlMyTMei9a5L5BWbLgFz7z0VRZ1Q5ZqHqUVg8OJpOKsu8fG4S71dy5F0shEi2W+cf1g0SLWwrZYIqJ6lxZJxDXAE0/ArKoIwf/QN20S+150GBVQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724029245; c=relaxed/simple; bh=RtVxmQiE2amUT37c5dYO/3pNWoIJF7gMSCNvWJHSwjQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=B18VN55bRP/Ty/cBfYcArBUAdPNB6TQ4ZGj0gVDURrpUginSLmth+cMTWysbAtjDlCEoi2GNazSWiZ4vPrAJUb1ABb/jpFKZG4oFyFpZgp4YvM0M+EOdQ39YZWtVDp4ZSNWz32a208biPHaQoCrWCtM1Ld1mIZdjLh6xHQ72p2A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=NffpODzL; arc=none smtp.client-ip=209.85.161.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="NffpODzL" Received: by mail-oo1-f50.google.com with SMTP id 006d021491bc7-5da8c4a88fbso97141eaf.1; Sun, 18 Aug 2024 18:00:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724029243; x=1724634043; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ccx12vLZCXZwR8/v5RNHblIUI8DVfBbUOP+jn6uBVsw=; b=NffpODzL1WTzpTh61/FFGJ75Vskekpn0dn7sDirwEA0pVXoXTFv099rGKGo/GTu4da FTFuynDChDVgjX5k7yuFitSjYTGd2/MKPzdRIIt9SyvDbfVjbpZRS68Zuv6tfgoGEShJ 0tT19FELNNVB2SkSqhtxjWlIVavVrTiycUNJpf7LeavrVTUGv/nVKZMjjkkusEATPQPJ r9zL7OZLrNzviE0BCRQzV9ppfhUdqfgiNnPnW7PWvZ6WwvJ+8UywJOmeW6gvdsr4/Mus Dkc7BpwU2b2zuKz8yUe4/f5JltGXJnqQ8NtXrEHi247wEWOM+K21uIHK1tiqkWEdF0gl F7Qg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724029243; x=1724634043; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ccx12vLZCXZwR8/v5RNHblIUI8DVfBbUOP+jn6uBVsw=; b=Ya1OYNtCmAlw9bqqxPSqcz8xCM34Z7qp/nCcRTTDNJqRjCfnaJ7U/hEcG9f0FYtCP2 6/Z7fHccyYS4qm0qPeDPyFb5EqrVGwgomICoNrFdiRVH6k6TeU1YvDcmAyy5siZspPNp cDVexzbsOcXKzP+pu8ViIImqoJxYf3QjiiqNrwuejGTRpes90kWANjsqiFeg6feXxDkr Qr6/Egq5fWCcFcr+K9VYe5Nw3n8BYktM84PFvuBgjeeovvYyxODvn60EP7ATM/88HBFr YZDwPwLFNHEPK/E3OZu+gt0kfeQdePvF8yMtmDgJ8nDN84DWiCuyKa6mb32tSUcw2Y2k OkrQ== X-Gm-Message-State: AOJu0YyVG5K5BX5I6xjHHIhg2FZKL0B/o1JLdFq1ZaWmY6SG/r8jOiz5 ULqpPS2jeSx9JDHbKMxsWcupZuYf58t9vC/ajVmQ8eeFaH/bVbJj7PEbYbdP X-Google-Smtp-Source: AGHT+IFi350co4BEF0R5n8NXnG7JEueqWv5JywdtHPu5mNgc1r/z8bMojI5Jij24tCwtiSNGuLnIlQ== X-Received: by 2002:a05:6870:d6a5:b0:268:afc3:64cb with SMTP id 586e51a60fabf-2701c575f2emr5190954fac.8.1724029242686; Sun, 18 Aug 2024 18:00:42 -0700 (PDT) Received: from localhost.localdomain (p4468007-ipxg23001hodogaya.kanagawa.ocn.ne.jp. [153.204.200.7]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7127af3c4a7sm5718732b3a.193.2024.08.18.18.00.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Aug 2024 18:00:42 -0700 (PDT) From: FUJITA Tomonori To: netdev@vger.kernel.org Cc: rust-for-linux@vger.kernel.org, andrew@lunn.ch, tmgross@umich.edu, miguel.ojeda.sandonis@gmail.com, benno.lossin@proton.me, aliceryhl@google.com Subject: [PATCH net-next v5 5/6] rust: net::phy unified genphy_read_status function for C22 and C45 registers Date: Mon, 19 Aug 2024 00:53:44 +0000 Message-ID: <20240819005345.84255-6-fujita.tomonori@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240819005345.84255-1-fujita.tomonori@gmail.com> References: <20240819005345.84255-1-fujita.tomonori@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Add unified genphy_read_status function for C22 and C45 registers. Instead of having genphy_c22 and genphy_c45 methods, this unifies genphy_read_status functions for C22 and C45. Reviewed-by: Trevor Gross Reviewed-by: Benno Lossin Reviewed-by: Andrew Lunn Signed-off-by: FUJITA Tomonori --- rust/kernel/net/phy.rs | 12 ++---------- rust/kernel/net/phy/reg.rs | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/rust/kernel/net/phy.rs b/rust/kernel/net/phy.rs index c07accb08434..a74ce9f30ce7 100644 --- a/rust/kernel/net/phy.rs +++ b/rust/kernel/net/phy.rs @@ -252,16 +252,8 @@ pub fn genphy_suspend(&mut self) -> Result { } /// Checks the link status and updates current link state. - pub fn genphy_read_status(&mut self) -> Result { - let phydev = self.0.get(); - // SAFETY: `phydev` is pointing to a valid object by the type invariant of `Self`. - // So it's just an FFI call. - let ret = unsafe { bindings::genphy_read_status(phydev) }; - if ret < 0 { - Err(Error::from_errno(ret)) - } else { - Ok(ret as u16) - } + pub fn genphy_read_status(&mut self) -> Result { + R::read_status(self) } /// Updates the link status. diff --git a/rust/kernel/net/phy/reg.rs b/rust/kernel/net/phy/reg.rs index 5fb05b79a956..7edb5d494e0a 100644 --- a/rust/kernel/net/phy/reg.rs +++ b/rust/kernel/net/phy/reg.rs @@ -31,6 +31,13 @@ pub trait Sealed {} /// dev.read(C22::BMCR); /// // read C45 PMA/PMD control 1 register /// dev.read(C45::new(Mmd::PMAPMD, 0)); +/// +/// // Checks the link status as reported by registers in the C22 namespace +/// // and updates current link state. +/// dev.genphy_read_status::(); +/// // Checks the link status as reported by registers in the C45 namespace +/// // and updates current link state. +/// dev.genphy_read_status::(); /// } /// ``` pub trait Register: private::Sealed { @@ -39,6 +46,9 @@ pub trait Register: private::Sealed { /// Writes a PHY register. fn write(&self, dev: &mut Device, val: u16) -> Result; + + /// Checks the link status and updates current link state. + fn read_status(dev: &mut Device) -> Result; } /// A single MDIO clause 22 register address (5 bits). @@ -112,6 +122,15 @@ fn write(&self, dev: &mut Device, val: u16) -> Result { bindings::mdiobus_write((*phydev).mdio.bus, (*phydev).mdio.addr, self.0.into(), val) }) } + + fn read_status(dev: &mut Device) -> Result { + let phydev = dev.0.get(); + // SAFETY: `phydev` is pointing to a valid object by the type invariant of `Self`. + // So it's just an FFI call. + let ret = unsafe { bindings::genphy_read_status(phydev) }; + to_result(ret)?; + Ok(ret as u16) + } } /// A single MDIO clause 45 register device and address. @@ -191,4 +210,13 @@ fn write(&self, dev: &mut Device, val: u16) -> Result { bindings::phy_write_mmd(phydev, self.devad.0.into(), self.regnum.into(), val) }) } + + fn read_status(dev: &mut Device) -> Result { + let phydev = dev.0.get(); + // SAFETY: `phydev` is pointing to a valid object by the type invariant of `Self`. + // So it's just an FFI call. + let ret = unsafe { bindings::genphy_c45_read_status(phydev) }; + to_result(ret)?; + Ok(ret as u16) + } } From patchwork Mon Aug 19 00:53:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: FUJITA Tomonori X-Patchwork-Id: 13767701 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pg1-f177.google.com (mail-pg1-f177.google.com [209.85.215.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 912A238DE4; Mon, 19 Aug 2024 01:00:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724029248; cv=none; b=RBc4ByNFIkIWeFOTJFHdFaEU2l00Gx6MBXVB4Bs9isn5+c2WnarfVztkusUIYPdViWIXxj1Jch6MmjLN+5xTUhr8/FrRiwXmolr3h4i2CAD9XZogBmMNnHUwyxnp7HAZLoN8QMYgfdswZTUvpRcK4zwMuxZdFAsM++mxD0QgOWo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724029248; c=relaxed/simple; bh=y2cjxgBXC3a5osoIOO65GeJzqCEOLHSshPNJxJevB4M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=N43yMGwVTaL4PUuhqj8EiJc/nGzrx+kWvEahZB7Bj+hE3fX9dgUsWQQgFbKqp9UFF0108xVCXXUQ8LUhETslyOxTn5+grmbpAmga8bTpjQm2dmAXgdnHbhxIBYuze5y0CSOAw7J5n6+we+fQdnjFzDlVHbfRiWFC/h0sIE8jd+Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=dl+N6kQD; arc=none smtp.client-ip=209.85.215.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="dl+N6kQD" Received: by mail-pg1-f177.google.com with SMTP id 41be03b00d2f7-7a0ed32c0ebso88026a12.2; Sun, 18 Aug 2024 18:00:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724029246; x=1724634046; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=6cR6d3z4dkTkVOajgyHKENK0hKflSKn8qrA5cqnIiTY=; b=dl+N6kQDvB21V1ew1jvWhzikqeE2eZ7bFUrTeEv15FFUJSCvFHeUpG1zEhdRIvmedQ mB9r8RqjLN4xnyOb3IqDg1ydwKfeWojeYuq+IEN3umCvpek8N43/XxCg0I/zr0gU2gOU H94EllcpJZOUf5It+iEjsPPDaXtErvmsx8kaLACYtbnuqfaR50uDUR7yjEuZ0Gc7iSFW 8oUtDz9OHiI3F6wIIUDIURWsJoYO+pBVlg2F9gll4HAEfalBro0F56j0tf14jjxPxMZg Kp2jsdTsbgQkSgCqbOznj3yLfU0il0cDQU65K7lX1nWEjx1zfulqeFa47W/4l/w2Hq+W lI1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724029246; x=1724634046; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6cR6d3z4dkTkVOajgyHKENK0hKflSKn8qrA5cqnIiTY=; b=t9/KZ9aK6Dt1hD9XWopuEr529+IyEQzj6PRs+FoNpRNlcujfEDrgefxyZvH6g0o+Ia 2boTvP46iRAWeBebAo/j2FBzMDtaYsTYvf2nMqTMCWbTrd4qJUL824AjkWc8EnPuANCe clGOUmQ7LduKQXAvOOlaB81xqiSj7Gg9dUqBb8xRQx0LJbw0wuuBvKyWXG4iI5rEMzTw H/WQruELoSQmNBo4eLZU0X9SYrLzwfeawdz/huB9aju2W6Ap9pJAWmO3Ihem5lbMSsmP it91yXaK15m5IcCB2dfUwOXxfUGm5/JqdPvjOz52naxxSToYNVLzhCwMxD4aLLxVC1hd KAXQ== X-Gm-Message-State: AOJu0Yxp5lyFgCuYnkE2736rdEflnSCRYM/0T3Zi65TcNaW7tRGJJ3sD htNuWW+YHCCJnBevRjPULfQGQNDZBxpNXn9lXHoIY/V3VquQCJlMLHqpaNM0 X-Google-Smtp-Source: AGHT+IHkkUfwBXVysgu6t48MlL1RFYx61x7yrrl88/Ul6rtn+YBspySf88hrEbKVozQsjFJ3RYkujQ== X-Received: by 2002:a05:6a00:2d17:b0:70d:1048:d4eb with SMTP id d2e1a72fcca58-713c5222e10mr7345653b3a.3.1724029245320; Sun, 18 Aug 2024 18:00:45 -0700 (PDT) Received: from localhost.localdomain (p4468007-ipxg23001hodogaya.kanagawa.ocn.ne.jp. [153.204.200.7]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7127af3c4a7sm5718732b3a.193.2024.08.18.18.00.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Aug 2024 18:00:45 -0700 (PDT) From: FUJITA Tomonori To: netdev@vger.kernel.org Cc: rust-for-linux@vger.kernel.org, andrew@lunn.ch, tmgross@umich.edu, miguel.ojeda.sandonis@gmail.com, benno.lossin@proton.me, aliceryhl@google.com Subject: [PATCH net-next v5 6/6] net: phy: add Applied Micro QT2025 PHY driver Date: Mon, 19 Aug 2024 00:53:45 +0000 Message-ID: <20240819005345.84255-7-fujita.tomonori@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240819005345.84255-1-fujita.tomonori@gmail.com> References: <20240819005345.84255-1-fujita.tomonori@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org This driver supports Applied Micro Circuits Corporation QT2025 PHY, based on a driver for Tehuti Networks TN40xx chips. The original driver for TN40xx chips supports multiple PHY hardware (AMCC QT2025, TI TLK10232, Aqrate AQR105, and Marvell 88X3120, 88X3310, and MV88E2010). This driver is extracted from the original driver and modified to a PHY driver in Rust. This has been tested with Edimax EN-9320SFP+ 10G network adapter. Signed-off-by: FUJITA Tomonori --- MAINTAINERS | 7 +++ drivers/net/phy/Kconfig | 7 +++ drivers/net/phy/Makefile | 1 + drivers/net/phy/qt2025.rs | 90 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 105 insertions(+) create mode 100644 drivers/net/phy/qt2025.rs diff --git a/MAINTAINERS b/MAINTAINERS index 9dbfcf77acb2..d4464e59dfea 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1609,6 +1609,13 @@ F: Documentation/admin-guide/perf/xgene-pmu.rst F: Documentation/devicetree/bindings/perf/apm-xgene-pmu.txt F: drivers/perf/xgene_pmu.c +APPLIED MICRO QT2025 PHY DRIVER +M: FUJITA Tomonori +L: netdev@vger.kernel.org +L: rust-for-linux@vger.kernel.org +S: Maintained +F: drivers/net/phy/qt2025.rs + APTINA CAMERA SENSOR PLL M: Laurent Pinchart L: linux-media@vger.kernel.org diff --git a/drivers/net/phy/Kconfig b/drivers/net/phy/Kconfig index f530fcd092fe..01b235b3bb7e 100644 --- a/drivers/net/phy/Kconfig +++ b/drivers/net/phy/Kconfig @@ -112,6 +112,13 @@ config ADIN1100_PHY Currently supports the: - ADIN1100 - Robust,Industrial, Low Power 10BASE-T1L Ethernet PHY +config AMCC_QT2025_PHY + tristate "AMCC QT2025 PHY" + depends on RUST_PHYLIB_ABSTRACTIONS + depends on RUST_FW_LOADER_ABSTRACTIONS + help + Adds support for the Applied Micro Circuits Corporation QT2025 PHY. + source "drivers/net/phy/aquantia/Kconfig" config AX88796B_PHY diff --git a/drivers/net/phy/Makefile b/drivers/net/phy/Makefile index f086a606a87e..669d71959be4 100644 --- a/drivers/net/phy/Makefile +++ b/drivers/net/phy/Makefile @@ -37,6 +37,7 @@ obj-$(CONFIG_ADIN_PHY) += adin.o obj-$(CONFIG_ADIN1100_PHY) += adin1100.o obj-$(CONFIG_AIR_EN8811H_PHY) += air_en8811h.o obj-$(CONFIG_AMD_PHY) += amd.o +obj-$(CONFIG_AMCC_QT2025_PHY) += qt2025.o obj-$(CONFIG_AQUANTIA_PHY) += aquantia/ ifdef CONFIG_AX88796B_RUST_PHY obj-$(CONFIG_AX88796B_PHY) += ax88796b_rust.o diff --git a/drivers/net/phy/qt2025.rs b/drivers/net/phy/qt2025.rs new file mode 100644 index 000000000000..45864a7e1120 --- /dev/null +++ b/drivers/net/phy/qt2025.rs @@ -0,0 +1,90 @@ +// SPDX-License-Identifier: GPL-2.0 +// Copyright (C) Tehuti Networks Ltd. +// Copyright (C) 2024 FUJITA Tomonori + +//! Applied Micro Circuits Corporation QT2025 PHY driver +use kernel::c_str; +use kernel::error::code; +use kernel::firmware::Firmware; +use kernel::net::phy::{ + self, + reg::{Mmd, C45}, + DeviceId, Driver, +}; +use kernel::prelude::*; +use kernel::sizes::{SZ_16K, SZ_32K, SZ_8K}; + +kernel::module_phy_driver! { + drivers: [PhyQT2025], + device_table: [ + DeviceId::new_with_driver::(), + ], + name: "qt2025_phy", + author: "FUJITA Tomonori ", + description: "AMCC QT2025 PHY driver", + license: "GPL", + firmware: ["qt2025-2.0.3.3.fw"], +} + +struct PhyQT2025; + +#[vtable] +impl Driver for PhyQT2025 { + const NAME: &'static CStr = c_str!("QT2025 10Gpbs SFP+"); + const PHY_DEVICE_ID: phy::DeviceId = phy::DeviceId::new_with_exact_mask(0x0043A400); + + fn probe(dev: &mut phy::Device) -> Result<()> { + // The vendor driver does the following checking but we have no idea why. + let hw_id = dev.read(C45::new(Mmd::PMAPMD, 0xd001))?; + if (hw_id >> 8) & 0xff != 0xb3 { + return Err(code::ENODEV); + } + + // The 8051 will remain in the reset state. + dev.write(C45::new(Mmd::PMAPMD, 0xC300), 0x0000)?; + // Configure the 8051 clock frequency. + dev.write(C45::new(Mmd::PMAPMD, 0xC302), 0x0004)?; + // Non loopback mode. + dev.write(C45::new(Mmd::PMAPMD, 0xC319), 0x0038)?; + // Global control bit to select between LAN and WAN (WIS) mode. + dev.write(C45::new(Mmd::PMAPMD, 0xC31A), 0x0098)?; + dev.write(C45::new(Mmd::PCS, 0x0026), 0x0E00)?; + dev.write(C45::new(Mmd::PCS, 0x0027), 0x0893)?; + dev.write(C45::new(Mmd::PCS, 0x0028), 0xA528)?; + dev.write(C45::new(Mmd::PCS, 0x0029), 0x0003)?; + // Configure transmit and recovered clock. + dev.write(C45::new(Mmd::PMAPMD, 0xC30A), 0x06E1)?; + // The 8051 will finish the reset state. + dev.write(C45::new(Mmd::PMAPMD, 0xC300), 0x0002)?; + // The 8051 will start running from the boot ROM. + dev.write(C45::new(Mmd::PCS, 0xE854), 0x00C0)?; + + let fw = Firmware::request(c_str!("qt2025-2.0.3.3.fw"), dev.as_ref())?; + if fw.data().len() > SZ_16K + SZ_8K { + return Err(code::EFBIG); + } + + // The 24kB of program memory space is accessible by MDIO. + // The first 16kB of memory is located in the address range 3.8000h - 3.BFFFh. + // The next 8kB of memory is located at 4.8000h - 4.9FFFh. + let mut j = SZ_32K; + for (i, val) in fw.data().iter().enumerate() { + if i == SZ_16K { + j = SZ_32K; + } + + let mmd = if i < SZ_16K { Mmd::PCS } else { Mmd::PHYXS }; + dev.write(C45::new(mmd, j as u16), (*val).into())?; + + j += 1; + } + // The 8051 will start running from SRAM. + dev.write(C45::new(Mmd::PCS, 0xE854), 0x0040)?; + + Ok(()) + } + + fn read_status(dev: &mut phy::Device) -> Result { + dev.genphy_read_status::() + } +}