From patchwork Sun Aug 4 23:38:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: FUJITA Tomonori X-Patchwork-Id: 13752800 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pf1-f180.google.com (mail-pf1-f180.google.com [209.85.210.180]) (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 1AAB713B787; Sun, 4 Aug 2024 23:41:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722814906; cv=none; b=s/m9sUjqd+Dl4+vHMqEa94Dyxn/0GA5B2NdQ4/bFjY0IEt63UVsySvKZgpvKXENUmC6vWZkXdZLfPTsRFXsrMyrDWwAEM+agTbHMal5FoKsWKLLd1vZpeDwOXmzbZW+43koFWCdDR3XgaOrxtaVbk7eIl/tKnoI13VfTiRSClv0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722814906; c=relaxed/simple; bh=NLZmyFwRmNrUpvp1/DY1sE6dhxHV+9KSXjfdHJoB9w8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=nBT2dTon7WEbAjwCIQ3IsVG3LD4AR16i2RpZIEduEhg8rzfk99sG+h5+xN4RcIBb+TkFMwXklsbe4kNcaTaV0lFa6MdQ4bV9sQii0NKv7Wa0nTlF1Qm7sxeApjhvm+u9emgzkomJxM3XsMisYz5D5w5sacXphSLh8BoOkcqea1E= 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=elHn9PEh; arc=none smtp.client-ip=209.85.210.180 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="elHn9PEh" Received: by mail-pf1-f180.google.com with SMTP id d2e1a72fcca58-70d19bfdabbso237165b3a.2; Sun, 04 Aug 2024 16:41:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722814904; x=1723419704; 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=wRA70TSyME+q1opiUIADckKNjk/c0WKvNY/ksIWq50M=; b=elHn9PEh5QXcl+zs9oKK8yMNAMznSFDTu37Bosslayk+jtgk6Qlw/racKp9w+M4ISq rIiz4bWSnXrW8goH+MmV7c/jtJaL0MPx2X5P70Zy1SrzjZSbsp73v8feh9BZC2AOEQ2T iVjO/C4kAZxtRNS79kYngvf/ZTZHz7mfzG6jala1wCzLf8ZTVkKHYQTcVvEKWf1+c1Nm 2EoPQ0pMlehT4SUbQwGPz69FKUO7j1TgvmJ6e5Z0c3kDhUO37UPM2V+JmgeJpy1d9hH0 PifSroODYt7ocKNZiM630bEHlou1Kwvf6vr6YYyMpWm5J/lD/j0bFeGLZgKbeUHIzueT wwvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722814904; x=1723419704; 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=wRA70TSyME+q1opiUIADckKNjk/c0WKvNY/ksIWq50M=; b=SyVStIYkaEuE7vZRQ8/lKdvuLybttlYM48xSK+MXdlFpw4yLfKWPjC5oFJsg0A3Sh0 SuyMiEYsVgf27BqGkOxh2xLQCBQvQdhI0SASdATEtQUADboMQSuaZ0oKmsTO7nb8Et1y ivOekVPFYUoPavYh5EhMnaMXAmoLBi6lA1PXZ5rNqCo64xXNias7oSf3gRTRmqDOP1kQ wTLvwMZUAC8d2Jl1SlsM/9269JibS5eIagVHwCGjUg90oH/o2ai7sUI1c0rAF8zpVyQs StOORTbIQn/xtz2uaWI1IxX5HYeO2bi1H0EIAXeBUdFYvV5SvIhQNsW59EZ27NWF0UIv zTaQ== X-Gm-Message-State: AOJu0YwabfVwerR2GWt+47CIzUgYAFEWVJe08VJbPgWMFwBUY0MWLBKO Jqei/35pK9FJcdsPLIXuGafIt6/18AZ3bFUx/XjghjJv6uNVuR/HvwcxDV1x X-Google-Smtp-Source: AGHT+IEdvtmUluYDQ0ALf48ez1BJzm3+9tPZ4s24RlZO914TTdg/hquV1C8/2shSxFe5PJc+WTiBOA== X-Received: by 2002:a05:6a00:4fca:b0:70b:705f:dda7 with SMTP id d2e1a72fcca58-7106d099268mr8341892b3a.4.1722814904021; Sun, 04 Aug 2024 16:41:44 -0700 (PDT) Received: from rpi.. (p4456016-ipxg23001hodogaya.kanagawa.ocn.ne.jp. [153.204.172.16]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7106ece3b99sm4535258b3a.98.2024.08.04.16.41.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 04 Aug 2024 16:41:43 -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 v3 1/6] rust: sizes: add commonly used constants Date: Mon, 5 Aug 2024 08:38:30 +0900 Message-Id: <20240804233835.223460-2-fujita.tomonori@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240804233835.223460-1-fujita.tomonori@gmail.com> References: <20240804233835.223460-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. Signed-off-by: FUJITA Tomonori Reviewed-by: Alice Ryhl Reviewed-by: Andrew Lunn --- 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 Sun Aug 4 23:38:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: FUJITA Tomonori X-Patchwork-Id: 13752801 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pg1-f182.google.com (mail-pg1-f182.google.com [209.85.215.182]) (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 537FC13C9B3; Sun, 4 Aug 2024 23:41:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722814908; cv=none; b=cUaor72dz85CgXVHMrUEXWcKPftP4FcF4VThhQROtBTI2g8fPA89FAW6OmHuNw1DjpR3chX4aQuUMbpKLWpqh8KDQki5DigSgXSpq368Q5cPkBmWWP7kSXY4g5oMo6KyDBzRhxLc3v4ojTYhGyjdrcv8cdZKQzaok5wDCxFnWzU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722814908; c=relaxed/simple; bh=wW29bSCtFMJibi2MzDpnRkX2jajAXNFRbqt4OAIvvbE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Xvw7GWPuCknzDri8oEn1MgkIvb3Lu3l/lE0fTVZWKeaKVv8DYZhg9M54ATurJx35Y9iyBTMX9jA1qdNXvGtHRl/cGjd/xPlN3tR86At7IctBowi5m2Bkwc8xTD6Tm5KG2zC81MQu2cwwHIRKIwYP7TfJtbLzm2Gq4ZPehKWHwig= 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=W8nxt6Iw; arc=none smtp.client-ip=209.85.215.182 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="W8nxt6Iw" Received: by mail-pg1-f182.google.com with SMTP id 41be03b00d2f7-788485dd42cso98681a12.1; Sun, 04 Aug 2024 16:41:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722814906; x=1723419706; 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=//pn9qMo06/6J2HC4egkDbIKedBmsIQb6XaD6L19e3c=; b=W8nxt6IwWHwaB8dD6ssC/xwW6LoOU+Jboj3g9/+4gHrercaSzGddkniNN1bWduVTWs Bit1nP+BXEFhlGB0b6ZEgujQnNkf20SkdUClnDqsBqp43fhAXTRnXMDyoxK+faAD76jh duTJewqqCQffnOb6frVKGzANGFxgjk8Uokx7KrWiS9pL3w7D0l66hc8gv9p/Wbm5IWW8 dfTaawCfwLvXQ6Q3rckUJf0OicGG1VcHSLBsEFkLWHc6D5x8S7ZUjPW+GE9AVf93f8Rx hEm9ZYY06UaBHcWQujzk+HEyfJrHNCeg/VBrdW+Sh4I3YzGA4Btr/by3jUSYzlGJASvQ FqZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722814906; x=1723419706; 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=//pn9qMo06/6J2HC4egkDbIKedBmsIQb6XaD6L19e3c=; b=XgoIjUsdkx1yxiVHjcEcI7BgCBPFm1DBpz1nCCmCqqc/cHkGdL2ujvHj4rN6MEDo6w pNg+8FtafLTkHiz2+ZEoVh1TgA1BbyWZO2yfXWnn+BaF8w5nCsxEt0d6FG0Me838Trb4 cPWEmob82GcmFyYcmK/skpAmzwA1UnXrgAzN2p8YV9SolFM8XCS//8Z6LNjQd3UDW4Ot B+dSvWPi+UYtdaCK2HctKWqs9YOtv5EE2iM93vJawULHO8t+pXBDh+kliVoIlyKVda0o 1b9kxIEO5uCz6X4YRQv5/kR8fBV4STYBvpF7RGqVaBxCH9Cj8BRjt1zP9wQCiEuxYUwX 08ug== X-Gm-Message-State: AOJu0YzCriLj/i/8LyvofJB1tMeEJC2CPfYcUQKY9OKUVtMdu0CsSJCP NwXyrLWDd+TTVjaw/Ayo2jhRQLjS4HZUYPDVhaiqin8aeP6FqVRVLU5BUM6p X-Google-Smtp-Source: AGHT+IHSlUgTCQXmmaheRUnYI/iE9sfvICI0gd/wF5fEa9UegOyJudnj5j24nDRiGS74FPGCa7K4eQ== X-Received: by 2002:a05:6a00:22d6:b0:70d:148e:4bad with SMTP id d2e1a72fcca58-7106cfa0c59mr8094678b3a.2.1722814906159; Sun, 04 Aug 2024 16:41:46 -0700 (PDT) Received: from rpi.. (p4456016-ipxg23001hodogaya.kanagawa.ocn.ne.jp. [153.204.172.16]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7106ece3b99sm4535258b3a.98.2024.08.04.16.41.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 04 Aug 2024 16:41: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 v3 2/6] rust: net::phy support probe callback Date: Mon, 5 Aug 2024 08:38:31 +0900 Message-Id: <20240804233835.223460-3-fujita.tomonori@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240804233835.223460-1-fujita.tomonori@gmail.com> References: <20240804233835.223460-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. Signed-off-by: FUJITA Tomonori Reviewed-by: Alice Ryhl Reviewed-by: Andrew Lunn --- 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..60d3d8f8b44f 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 to `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 Sun Aug 4 23:38:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: FUJITA Tomonori X-Patchwork-Id: 13752802 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.176]) (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 3A16813CF9C; Sun, 4 Aug 2024 23:41:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722814910; cv=none; b=e8yei8UwExKftjo04+FsFEgaUA2vzO5fUts6LcOPBcLBM1tUyaQ8/ngosA95zYd2MnbB7OqPZ6LWSvzy8o1UwVptX+SdG5kA1ElbpTWD5eMYQtC7NWAEWm3nnaRxIonJkl9dEUZIF4qAtTBOxZz3Nz5psQKJh27BG8tIDuQ+CJM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722814910; c=relaxed/simple; bh=CDfY6IkFb/pbtFZNpcTKNUsL9M+sTRdh9sP/wY4Hs8E=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=fvrCqOYDFRJ8WyZB70hXylH8OEfiFlDaWU66ZUU8VYTMG7Y7XlKxasg+2wEacUVALSuC7P6UxdmloHOnDP4lxVV0btIQi2RUtbghSneMVgZvltnpGB9iVGJ8CUP4ASWLgierdPeArNOwXICoGAiZ1V3V29hlMA6M4DtIsJM7H1w= 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=dNuAPAZT; arc=none smtp.client-ip=209.85.210.176 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="dNuAPAZT" Received: by mail-pf1-f176.google.com with SMTP id d2e1a72fcca58-70d133ad012so114310b3a.1; Sun, 04 Aug 2024 16:41:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722814908; x=1723419708; 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=pCN2W3Sl7lJRO8DMWpTdPVxW8ijvZedjxv3EDreI5jw=; b=dNuAPAZTzi17o86EUzFZFa6IMCncE11t1+orHuBrLY9fH+RJiMCyl/7GiysxnPD+HW ed3rGZ/tIlZ054PYxYwG9lticJQaEGQvrVJ7b4YfqsJY7HdGwpcJYYuipRJuX0m/aDxG rt1Qv/C2RWPalYsfsiKvxFsrATp+L7OIfEz+wvtAzNjmRwptKpr3CkrA2HprX+asl6Ld tudOnZwi4TeQvJypti3WARM2K+9Gm4QRLS0QXy1QX8jaYMrgo2Wh0pKhMrLp7flEyc39 Tktuze+qeQjF0bSoBTrXieEK/bfBHEuHKFH32mspQJx4g0ROcaKeWzW3LOjQwJgn+Jd1 DxUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722814908; x=1723419708; 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=pCN2W3Sl7lJRO8DMWpTdPVxW8ijvZedjxv3EDreI5jw=; b=XpfpNQw/gMZGgOv+lA9Jx/7tzhjYReo3THWkEDCK7OJlpFeWKsXUy41Ai00OHjv9k4 3DEoA3aNeWfPn/kPJe5QxJVrmz4tI4ouuL4p8ZrWG+OQHK0Y5BsM8raLPR86klwcub7U DImPp2RgBny1Z8/d2C52W+IEEfwCfP+Oh7HgnONxu1C9TQZqkugC2+E4Ewi3AbzuUiWS l/JfGDI8O5KxTyYayJQYWO+AdYzF2QSbh1tFTXe52hoQ8H9YS9fPzxJ2QJRm832pm5En TT/tcLPHq+S9cl0j/SKcTMdgoQfzYGev2XyfTW8tAmAhR+5j44xgbFz7NI537ziWSK8m kJoA== X-Gm-Message-State: AOJu0YzatnjQMjSjy6qR0QoqEqNQ88Q3MnshrdXaEEUf5IFovUASHuPp qwEayZ9M2Ka94hWLDTd+Q3KL+LPgbkZ2VhrDLQhihnLIjleczcZMDJT/THD0 X-Google-Smtp-Source: AGHT+IEG7WegUKGYNIKb/ZK7Dr9QS2s+EViYSCCK4Fd7DabCAMDVKADeOegrxkBwDcFRNNcqWY4kNA== X-Received: by 2002:a05:6a00:a17:b0:710:5d11:ec2f with SMTP id d2e1a72fcca58-7106cdd9fd4mr8415312b3a.0.1722814908283; Sun, 04 Aug 2024 16:41:48 -0700 (PDT) Received: from rpi.. (p4456016-ipxg23001hodogaya.kanagawa.ocn.ne.jp. [153.204.172.16]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7106ece3b99sm4535258b3a.98.2024.08.04.16.41.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 04 Aug 2024 16:41:48 -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 v3 3/6] rust: net::phy implement AsRef trait Date: Mon, 5 Aug 2024 08:38:32 +0900 Message-Id: <20240804233835.223460-4-fujita.tomonori@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240804233835.223460-1-fujita.tomonori@gmail.com> References: <20240804233835.223460-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. Signed-off-by: FUJITA Tomonori Reviewed-by: Alice Ryhl Reviewed-by: Andrew Lunn --- rust/kernel/net/phy.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/rust/kernel/net/phy.rs b/rust/kernel/net/phy.rs index 60d3d8f8b44f..bd9fc7a84cd4 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. /// @@ -302,6 +301,15 @@ 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 we may access + // this field without additional synchronization. + 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 Sun Aug 4 23:38:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: FUJITA Tomonori X-Patchwork-Id: 13752803 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) (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 98D6813D298; Sun, 4 Aug 2024 23:41:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722814913; cv=none; b=lQV6M6b9kR91Eja1EaZkd14H6CbqipASHlNTKeXmprUH9y6iivZrDadJ1DkmK4QTeEBYerfLtYzbRhMNGdWcoO/7r4JFCH+11DAbM8rf8dJVnkz5wrGyWO0tpQ6sEMu3BsstrxkpJNVR9FWIsdFAL0+cOhgk6UI1vTUFRDbN3yU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722814913; c=relaxed/simple; bh=HCpGEY8WqPG72CEkicke35aLfNi6MnQNvLPhuRL4v80=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=fJ1p+JJkD63bv3Z9w5kChF109xx/8coPgnGda9oG9veRAe08zsBBsgbuKIcdLOLbGuZwyYqgd8ECWHvFNgx190z6g1fELV7W3ga+/bhQv6ieCMfhb4Mgjibd1FYsADhGkhdtz99C3p43cZ0S1ANIAvb2Y4EOVhd7eNETGujlYuY= 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=YGBe0XsQ; arc=none smtp.client-ip=209.85.210.170 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="YGBe0XsQ" Received: by mail-pf1-f170.google.com with SMTP id d2e1a72fcca58-70d2a6e31f1so613461b3a.3; Sun, 04 Aug 2024 16:41:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722814911; x=1723419711; 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=Kyus7z7texUi//qAu7bL/7H9MhDfXDSmFE7P8mJ1fVE=; b=YGBe0XsQWCDjHuW88SOUQf1Aw6yRg1O7k5H3AFTuMKw3J+kHtWVfdSKyQjkQrU1cIW k1WUu471LczTmNPA56gchLPbKLcwQDN+Pm+SXJl5BqozZn9cmi4Lq6Tohdx/NJS9onsY ZCSo4wBAtI9BfUd05VsTb5vQTu6jW39WSOX7dP5BcD5qPvphsukevdmd2LN/MhXggKqe 3I/Fc8KfGXUQt5QUMzNAfmKOSsBLbslET5cvMLL7XXGMo6EmaA0hIhFE1GAxhbE5XzNE 5D82votdKiGEfJEY+3XQbePM6kLuGn+X23Cx4tytvTMls8WH+X/zuKEmUeO1ViD7qVuV UQrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722814911; x=1723419711; 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=Kyus7z7texUi//qAu7bL/7H9MhDfXDSmFE7P8mJ1fVE=; b=jfbEwew37QwujzGtc/mq0lddSl+druAgLKx0/wKtZO6KawHxNqUPlz5ZFMiZvioUGu vN1y1xvgYdI7ftDFE8VKyWhzFZFJzdo+UmZPm6ExR/eYtBft9zF3F20VPrOvf5L8UVXE QCo6rZS9XdtDN1xUAXGrOm96zoNZ8NSb7i+TnkwEB2vn4OAH1vP9+j75ygs66gMIH0Qq jspiczwadaHRbCocXs08gm4TvatfiJCbpH1dd1oBC5S3D8g6b/H/q5JdumcTV8bClLqT yueipNBh8YqmMFqfHc7LiM+KDAzAe7MbDyim/d9FnP/3YJ+Qpee2kTBhSxVF6mNnDAUg vs6A== X-Gm-Message-State: AOJu0Yydhw0iGwrNY4IgWW5zzqrdkc9f+dDHrP2uOY+9F8AIHdEbSDVU UZlvtJ3jQ4Oc1DtHquAga7JH5ldkz5JinUt4KdTyYDOj5XCsL5wNKwRJZz8l X-Google-Smtp-Source: AGHT+IFVHxFxnOtlt2rmUdsKNPJu4miEFcrBmFfsohylG+qZV0+qH3+6ZwfXq8pb/a/o/uJN2APWoA== X-Received: by 2002:a05:6a00:3a20:b0:706:aadc:b0a7 with SMTP id d2e1a72fcca58-7106cf94aa4mr7106664b3a.1.1722814910491; Sun, 04 Aug 2024 16:41:50 -0700 (PDT) Received: from rpi.. (p4456016-ipxg23001hodogaya.kanagawa.ocn.ne.jp. [153.204.172.16]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7106ece3b99sm4535258b3a.98.2024.08.04.16.41.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 04 Aug 2024 16:41:50 -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 v3 4/6] rust: net::phy unified read/write API for C22 and C45 registers Date: Mon, 5 Aug 2024 08:38:33 +0900 Message-Id: <20240804233835.223460-5-fujita.tomonori@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240804233835.223460-1-fujita.tomonori@gmail.com> References: <20240804233835.223460-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. Signed-off-by: FUJITA Tomonori Reviewed-by: Trevor Gross Reviewed-by: Benno Lossin --- MAINTAINERS | 1 + drivers/net/phy/ax88796b_rust.rs | 7 +- rust/kernel/net/phy.rs | 31 ++--- rust/kernel/net/phy/reg.rs | 193 +++++++++++++++++++++++++++++++ rust/uapi/uapi_helper.h | 1 + 5 files changed, 206 insertions(+), 27 deletions(-) create mode 100644 rust/kernel/net/phy/reg.rs diff --git a/MAINTAINERS b/MAINTAINERS index 8766f3e5e87e..f0639034ef96 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 bd9fc7a84cd4..60e30e7b3f41 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`]. @@ -174,32 +176,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..91f73179315e --- /dev/null +++ b/rust/kernel/net/phy/reg.rs @@ -0,0 +1,193 @@ +// SPDX-License-Identifier: GPL-2.0 + +// Copyright (C) 2024 FUJITA Tomonori + +//! PHY register interfaces. +//! +//! This module provides support for accessing PHY registers via Ethernet +//! management interface clause 22 and 45, 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 Sun Aug 4 23:38:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: FUJITA Tomonori X-Patchwork-Id: 13752804 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) (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 B15AC13D504; Sun, 4 Aug 2024 23:41:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722814915; cv=none; b=CX8Qd1WSkXl5MYxUXGfBscg5URHQWIZf9oOMIQMfYxbiE03lIGVz6C5GRZKVsX1rzLxJGTF3/YEpvu8GSoz7Hv75d0d8uz6Ay51wqrAtVQhmhxUe+7jZ3O024kCoTkNR9Tpr4wJEXKrVWL8Ung67Wbw+6/FyghHbe/yRXRD3sGU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722814915; c=relaxed/simple; bh=kKUvKq8V5yBzqCS+HfwPhHfPlHvHGM3jIIabc1FPaLc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=E3311LREgdo7rK7ysrCgzImgAD4FhzdTGQh4CVxZ2P/POftae9cw5/DpzkInj0tZebI6R0fL5N8KgLpmegiOYzuQ8pDtg3xas/RuU5hHaC5Yy/Ub+blse3m9AejFlEyZJZ/DPS/mjE9+YAtlsJlUyHYwBcOKSokLXlMLr/1/s2U= 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=BhFbjPtP; arc=none smtp.client-ip=209.85.210.169 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="BhFbjPtP" Received: by mail-pf1-f169.google.com with SMTP id d2e1a72fcca58-70d26cb8f71so582842b3a.2; Sun, 04 Aug 2024 16:41:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722814913; x=1723419713; 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=pytqjKlSRbcr90FHfsODZ5jUOTVS+nbBYnrBhQ6kFt4=; b=BhFbjPtP3oXcvE/AuNSvfWp9tn18aWN45m5sAObg3T8T9F9ewDBm46DClRyoc/f0Ic G1B33NE3wsaUxPZwFh/MaC56BEuCqo6nStBlLSE0/ErrTgfXFuN4CLBitEuXCEixdQwP D7zZhPhzNOavK3FNm26LbHMYBuQZ81LFsoCxEQq42H+zZAjXppXLijOmNzHYJ1Lx9I+p 12EzEIWu1r/MTS+fumIaj9gnTQ61HkRTmpFWnMd/QERy0QDydANObLHlnYp/KuBc7A++ KHkPdYNHsENvpXx5GyTH6K6dxxsh68YokcERw6n2MLNoWhFNcPM7q64VWZ9bbYfL6LkO +e5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722814913; x=1723419713; 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=pytqjKlSRbcr90FHfsODZ5jUOTVS+nbBYnrBhQ6kFt4=; b=HzMNM67Ld9wmiTcCjyiRvCwc3jVALYL53foEEGqtyb0JNeSJZ1HsJ/unBzJ9iOVTS6 Pi7imSBnJV29Sh0S9sx4vVe6oxYifEw+6cnHrz/viZo6SeGalitDf/M+VcxaZ8RYh9bo J1SSntUSxsqst8Ypv95OrCU7MKTw/fqdlewcFZXFSBDcj2G2tzA1RJLhybmwiRdx2Vxu cD5PS1EhK7ZSVxtOvk3drX3xsVlgFC9fFNjBCT8zhkjVFdyjU7JsrNPcrpWg7KfjFqY2 Fu78P3kSyCMYtZHXsYyi9uXNXqMLy/o4hP16PSBuECgFtk0CpwrIIM4eYlOUfjNplcFQ MCow== X-Gm-Message-State: AOJu0Yx3SIuF9sDwjA+q/48EA18+Mse0gx+My0iJBrBXRVP1hXCXraCF 9Y/zOCb4PHOTd41s5LCGV8oZa7mufoh1u0C/qaWUGOafvOP/r/Z1wPTdDBvV X-Google-Smtp-Source: AGHT+IE1NuLpqZ8ejF6eICa9w8kkYP3YmIg8T17Ix1V7MuFc0XgZZHbZidKBfOBEve+IMulH3vnDTQ== X-Received: by 2002:a05:6a00:3a20:b0:706:aadc:b0a7 with SMTP id d2e1a72fcca58-7106cf94aa4mr7106698b3a.1.1722814912674; Sun, 04 Aug 2024 16:41:52 -0700 (PDT) Received: from rpi.. (p4456016-ipxg23001hodogaya.kanagawa.ocn.ne.jp. [153.204.172.16]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7106ece3b99sm4535258b3a.98.2024.08.04.16.41.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 04 Aug 2024 16:41:52 -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 v3 5/6] rust: net::phy unified genphy_read_status function for C22 and C45 registers Date: Mon, 5 Aug 2024 08:38:34 +0900 Message-Id: <20240804233835.223460-6-fujita.tomonori@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240804233835.223460-1-fujita.tomonori@gmail.com> References: <20240804233835.223460-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. Signed-off-by: FUJITA Tomonori Reviewed-by: Trevor Gross Reviewed-by: Benno Lossin --- rust/kernel/net/phy.rs | 12 ++---------- rust/kernel/net/phy/reg.rs | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/rust/kernel/net/phy.rs b/rust/kernel/net/phy.rs index 60e30e7b3f41..6703bf288d76 100644 --- a/rust/kernel/net/phy.rs +++ b/rust/kernel/net/phy.rs @@ -249,16 +249,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 91f73179315e..4cf47335539b 100644 --- a/rust/kernel/net/phy/reg.rs +++ b/rust/kernel/net/phy/reg.rs @@ -30,6 +30,11 @@ 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 and updates current link state via C22. +/// dev.genphy_read_status::(); +/// // Checks the link status and updates current link state via C45. +/// dev.genphy_read_status::(); /// } /// ``` pub trait Register: private::Sealed { @@ -38,6 +43,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). @@ -111,6 +119,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. @@ -190,4 +207,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 Sun Aug 4 23:38:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: FUJITA Tomonori X-Patchwork-Id: 13752805 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pf1-f180.google.com (mail-pf1-f180.google.com [209.85.210.180]) (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 E49B213D53B; Sun, 4 Aug 2024 23:41:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722814917; cv=none; b=h+0YBvrIOnV8cvedG9LQD8eSdqmpdbISy911ae2kiFlRceRSkC3UdFRF7WneE1UFP20NIB1+e4ibLS6PCb7sRuau/LnaYHKXRfPP1Vm4wyWI3/E1uO6uKenzu2hfugMv7YhIjWBIBBVFXwIyAPDbDaQOWNLyYmzOhKGAOE/Xmv0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722814917; c=relaxed/simple; bh=R+SCPgLKjhjBEoPE2r+XCuSsCjzJ5EtNXsF/tYzmNqA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=nQK2RO/w6D2/jNdf9sLl0WVeSuaZYKB276IL9wolSDljAscVpu0vjkhWAIIYcmhcZ5IstEsbLB/LQ0/l75exOfDulGbx3z8HbCMxXXGFPtM0IGHBGyGvM1E6gR9Dcr/2Ncf6GNxEVYMtCarvFatro/TV4oAl7/Bi5wMDjpK3bAk= 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=md0os4y+; arc=none smtp.client-ip=209.85.210.180 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="md0os4y+" Received: by mail-pf1-f180.google.com with SMTP id d2e1a72fcca58-70d1876e748so1242653b3a.1; Sun, 04 Aug 2024 16:41:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722814915; x=1723419715; 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=YfGilcpk4OcPcAuhOSUGgfo8hQ3NybwDByISAyYwmo0=; b=md0os4y+ssQ1MtPg6UXJfOD8XhjpXFWRRmFePbivc47pe7f319SzBnsXYxTUxwiBkS Q/ydu4ohR3v6XvhZ2kTuCz20zgGlpAtH2OogK6pDZ2bHJNTDsfA2H+GO6VXv3MIRhr3/ P2GV4zuVRKPpEIUVX7SdqYzFIdMMEoQf/pBiffLqRjllMDCieJzCicQnlEAAnIjxOvco xrHrysK9HvG/8AEsjghFvzC66DAz7w17GLUS+O1INqKla311Wyl6lJEnf27bfwWIb1fo GmnYPlkFUCZ1ANSBCuJNPWwwox5QeZLidCvG5jiV/K6eY0BKzQ+sO2J589GuEZH7ZTgU J5sQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722814915; x=1723419715; 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=YfGilcpk4OcPcAuhOSUGgfo8hQ3NybwDByISAyYwmo0=; b=eVqTZ7VykmSRY7ZzjQ/KCjWiQjGoiblNp9WwEm4E77eY8mTvLmvNOxelKFbd243RZ1 PxQxiszy/lewRd/d4SzYtXXnRj6lm+O+U76AXkkgGD20GgSp6mKEaWM3JfSlnS7njm4H vC6uHvOwlQGhKh6JSg29TvGc3NYe3K5Ld2P+9EQjmGAb6CMfXvEYzmM8Xm3FCOPE8ECr DzX2N5ggFbpyTzH6pphdv8MTyx0S/dTxj5mV16LqPICxIzvgecT4pPsDDLgvNTMyda7n j+cGho43cPPub5vYSjpa/2nPlq1feifPs1mfbWL7wnRTUp+w2kcsOdFeDrg01t3rnDRr bGDA== X-Gm-Message-State: AOJu0YzbzvHQBYg24dXwxjZIETFRCqJUYZKXxNDVc6aXhV5MFCkyXAwe IfokI4yvLatpAIEYLTIrrLvlb9RRIzd7/bOemkVtWTroTsfchbKqaCnyOw7X X-Google-Smtp-Source: AGHT+IEetRh1tZGvjxEkuwC66NE/tPNgA20zOcw71ZgmsxmySTER9OzEpailHTJXycVFlIshIc0acg== X-Received: by 2002:a05:6a00:10cb:b0:70a:efec:6b88 with SMTP id d2e1a72fcca58-7106d07469dmr7998241b3a.3.1722814914849; Sun, 04 Aug 2024 16:41:54 -0700 (PDT) Received: from rpi.. (p4456016-ipxg23001hodogaya.kanagawa.ocn.ne.jp. [153.204.172.16]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7106ece3b99sm4535258b3a.98.2024.08.04.16.41.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 04 Aug 2024 16:41:54 -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 v3 6/6] net: phy: add Applied Micro QT2025 PHY driver Date: Mon, 5 Aug 2024 08:38:35 +0900 Message-Id: <20240804233835.223460-7-fujita.tomonori@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240804233835.223460-1-fujita.tomonori@gmail.com> References: <20240804233835.223460-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 | 6 +++ drivers/net/phy/Makefile | 1 + drivers/net/phy/qt2025.rs | 93 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 107 insertions(+) create mode 100644 drivers/net/phy/qt2025.rs diff --git a/MAINTAINERS b/MAINTAINERS index f0639034ef96..d25a529f6e48 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 7fddc8306d82..e0ff386d90cd 100644 --- a/drivers/net/phy/Kconfig +++ b/drivers/net/phy/Kconfig @@ -109,6 +109,12 @@ 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 + 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 202ed7f450da..461d6a3b9997 100644 --- a/drivers/net/phy/Makefile +++ b/drivers/net/phy/Makefile @@ -36,6 +36,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..ef245e8d4161 --- /dev/null +++ b/drivers/net/phy/qt2025.rs @@ -0,0 +1,93 @@ +// 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 hardware is configurable? + let hw_id = dev.read(C45::new(Mmd::PMAPMD, 0xd001))?; + if (hw_id >> 8) & 0xff != 0xb3 { + return Ok(()); + } + + // 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), + >::into(*val).to_le(), + )?; + + 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::() + } +}