From patchwork Wed Jul 31 04:21: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: 13748060 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.174]) (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 72CC51BC2F; Wed, 31 Jul 2024 04:22:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722399737; cv=none; b=ePTZeSZtRSHhmIcz+rNygoDDdzUPZD+30ZuamnQWAfx0jOK5qVyeWpQpph5L8kvoLywMNMn4w5vqdCm4BW2XINqPraM9ac9bH8tJqgcW8uFlES3YjWjVyGhEPnY1mzQYSjrI/DdRKJfHGGw+alWOvTbLNUWhdd0mYHBh9zuy2Vo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722399737; c=relaxed/simple; bh=u6x2RbCFPVeM+mpRyOnx37NMTKi8eStfFxkcFAoGOIg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=O/ma9JqOmpTiCM0k9PEUIl46yuitZOSbnQ31JTa7OjwB+l420JB61JmaxonTbj1VxekCepIK+jaIbkXMl7PWM6iWHJAnG/qbhZRv/kEJDjstF/w0O+PRv0BpXwHglCek8XXKOHLv6vriSwWm8+Y+8dxhsOLy/h4ejf+zhAYJDm8= 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=H3rdmy/N; arc=none smtp.client-ip=209.85.210.174 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="H3rdmy/N" Received: by mail-pf1-f174.google.com with SMTP id d2e1a72fcca58-70d1876e748so593566b3a.1; Tue, 30 Jul 2024 21:22:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722399735; x=1723004535; 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=RSEvqBNPkZucSUo+If8vG9EYTsL60DjHY8zUoaiuJlI=; b=H3rdmy/NGRynYyJTNaJgJdYIa7LVUwNIMquEDMzsBT9sr4B6DLWFuu3kZaJ+7v7xN/ cN7VEZlY9yMdfHljjp1DpR3ESII9JOJIMSke+YyHbVg6LDj1MLWRn5KqCjHWR2uwWRbf uHbtvlCJ2Spfm96MHRo1E0RJ5t9Zkap2u2R7YCEEkhCBtjS0iRmlGxxY1XB8Rxv659NK P8iIpqhuG5RNZeqdjpitdq5ej/GL0ZWwxDT0sQXTd9tAmnx4IAELoUIBrxvnRmOY2Fm+ mK6IHjgtAlNh3PReA/WhAqpcmEcBeGJSGKccnedi0bOChQzyxIlUUV+bug45mp1GU4sW ye/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722399735; x=1723004535; 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=RSEvqBNPkZucSUo+If8vG9EYTsL60DjHY8zUoaiuJlI=; b=xKzmi3Jtbcq0fst4EV7IkdWNk8obiQ+ZVyuQRSqwbzrOVE+8o6Wqod4zj34TAmb+mE 5HuUKCIvQfscZ61u4vZb/AG1nX4zTOrXhRdIEeDxTgZvc2YwcqqEln/o6kGPGRboMI64 d1LpanRbT0s+qzysE3Z3JkI3lsaEOg/uvixOKXuDvbe/iYTlWbLeI+BMGF6g5MIPCbAs 7a/mWKaayg1chsldqIyINgkv7/fLTEEU+28f5e6HHz7Xa/HaExfe4vf3kl63wJdY1+H0 ocwBUKI0IxOvB4520+ORnasMFPlpYhY2nQOtE/VJFTg78Ttrv+2rhBZ/nzj3k4D1LZFP YJhQ== X-Gm-Message-State: AOJu0YyXcf9y/B5NeopRg8rFhiGZXhFEVVQYwIWnNeWsIDCQqiAKAE4X +dCWHmhQ785JoDUs9KmZRfpbZH//KK3YL7Wkm8brfnMi6gwMIxShv5yY/Z1H X-Google-Smtp-Source: AGHT+IHY/6NRoT7XbYwXJCKgXKDyrhku6w27jNf/ZsVXBkI8TwKBCTBtSQz5XuE7pvQ7TBntt20UPg== X-Received: by 2002:a05:6a21:329e:b0:1c4:c4cc:fa49 with SMTP id adf61e73a8af0-1c4c4cd043bmr6950858637.7.1722399735254; Tue, 30 Jul 2024 21:22:15 -0700 (PDT) Received: from rpi.. (p4456016-ipxg23001hodogaya.kanagawa.ocn.ne.jp. [153.204.172.16]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fed7c8d376sm110815145ad.18.2024.07.30.21.22.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jul 2024 21:22:15 -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 Subject: [PATCH net-next v2 1/6] rust: sizes: add commonly used constants Date: Wed, 31 Jul 2024 13:21:31 +0900 Message-Id: <20240731042136.201327-2-fujita.tomonori@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240731042136.201327-1-fujita.tomonori@gmail.com> References: <20240731042136.201327-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. This adds only SZ_*K, which mostly used. Signed-off-by: FUJITA Tomonori Reviewed-by: Alice Ryhl --- 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 e6b7d3a80bbc..ba2ba996678d 100644 --- a/rust/kernel/lib.rs +++ b/rust/kernel/lib.rs @@ -42,6 +42,7 @@ pub mod net; 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 Wed Jul 31 04:21: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: 13748061 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 73DE6210EE; Wed, 31 Jul 2024 04:22:18 +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=1722399739; cv=none; b=B/+biST6Eqkoh8/WSINsvZSGohgi2ZHj51/h92bD3xbMTNqx0L+qMzcqi/MLgOEEZnISFWob8TY9kuelrEJsP6nfAdOkaCo206M9QG+0LV45GowRFLR4g2OWFjiG5QqexHIt5gGg0X3axrSxJyXTRc67rnBRKAfHuWx89LNo8lk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722399739; c=relaxed/simple; bh=VlMnWbOHgbB7/irsZJPQNTVbW+F3ocIi5Pat2kw6khw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=AOpzx5HTlebXk+VCN/AHt3xn5dN9d5FPUi1/q5moLf+kfCgB8vitfJwvAebKE1QxyxfF5BxAQPq8yEVwVIooHLkpJMt0UWiz+2q0IOiLvTKojYinfFze4QwsXsXK/9AKcq/AiT4yr8b41wl2pqH8c5KPv5Vx8nISZRwhUkEk/6A= 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=PmocLhk9; 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="PmocLhk9" Received: by mail-pj1-f47.google.com with SMTP id 98e67ed59e1d1-2cdba658093so958536a91.1; Tue, 30 Jul 2024 21:22:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722399737; x=1723004537; 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=ME4S6g3J7hg1K2EVmi4NiVpdfefWhzcKB/jHmW+Ol90=; b=PmocLhk90s5ebQGG3zJPgMNDBLE3NpQyc7uo9XQeNMuJIXLfWtTviad5tbM2wSFICp Bw1toCrvs/+uxj9f+qL32RcDQJ8jgLE82FgE5b+9Ut8wzibYTMQ2NhQt6JbQPtq6GMmZ mWSkPkd56UOw8ps+thCO3B3SNV2GUiFruXDmNH7Ojl2FejXEMu0qSsLlQ9n2firbGFRR VXhUsy3YeBYl2mIbPOLuz7nCikHV/8jZ892fXy2oSq+mcrTnHkGfcSV5Z1MxGnLSL67p Gpjch1ZPXkdF5RSfSeyFKX+KV9Cgcc3hXZ9QF1G8PJu0VhFg5w+WWEVgtzIv6gRaWrMY rapQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722399737; x=1723004537; 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=ME4S6g3J7hg1K2EVmi4NiVpdfefWhzcKB/jHmW+Ol90=; b=ouJ6HCBcVwbRHfO+mRyBGTcDNkuHi7Gp0mQsvxInVkTDZwEAldOi3jP63kwgBEunCT bZ9Lt+c230ZbAatPNcLVGfTF8c6zTns6Rf9ltRibSyfEcvvW/b2PTyL97Wz2171V6UN8 PtjAd+SeugGcDcOnjuiiS7YT/1tmmM65f92sDK1GeT3kq75oLsNxZLqi0QVWSYJf+pjA AodfQV8/rnRAP24Pg+ULWg6WTEMGmzOxZw1XV2eZJSyVXH3ZZCDJ+jJzvNU5g2WRIdce wv3yVhWtSI5C2748Itt5gL1+N2lVTf3GWVxLYODChKUBteQX0CcuFxzkQ2GNON4lAAcG gubQ== X-Gm-Message-State: AOJu0YyEjGQ9HcztwZ6JFs8K6h5Iw/Iwy2YAeDlfZWJq8Yu77v1tAGt8 25hcml0f7QFMXjq0BhG63spQ0lJ6ND5z7gurkyLsxmB31grHZ/dGkJR64g/4 X-Google-Smtp-Source: AGHT+IHewVmxmUwKVd6Dx7Xk5ho3fPN8cpGBHyRpLjZ+OG8FN/fBvcAOBRdBEP1Lk1ZIcAweSNKoew== X-Received: by 2002:a17:902:c402:b0:1fc:7180:f4af with SMTP id d9443c01a7336-1fed6bdd52amr128713805ad.1.1722399737313; Tue, 30 Jul 2024 21:22:17 -0700 (PDT) Received: from rpi.. (p4456016-ipxg23001hodogaya.kanagawa.ocn.ne.jp. [153.204.172.16]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fed7c8d376sm110815145ad.18.2024.07.30.21.22.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jul 2024 21:22:17 -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 Subject: [PATCH net-next v2 2/6] rust: net::phy support probe callback Date: Wed, 31 Jul 2024 13:21:32 +0900 Message-Id: <20240731042136.201327-3-fujita.tomonori@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240731042136.201327-1-fujita.tomonori@gmail.com> References: <20240731042136.201327-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 --- rust/kernel/net/phy.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/rust/kernel/net/phy.rs b/rust/kernel/net/phy.rs index fd40b703d224..99a142348a34 100644 --- a/rust/kernel/net/phy.rs +++ b/rust/kernel/net/phy.rs @@ -338,6 +338,20 @@ 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`, 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 +525,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 +602,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 Wed Jul 31 04:21: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: 13748062 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.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 7F6362837A; Wed, 31 Jul 2024 04:22:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722399741; cv=none; b=Mht6ApiUodGHM0kh7hgpj6wfuvdIsxA5CPNFfq6+qbIqPj+5L3w+hJ+VbTKNPRZOuo9C8Rt91Jby8JDa4+pW2y5e2g8tZXqZo1p9fz1hPw6lqb0e2lKHbkgeL33W2RrpSKL9gnRjeeQ2/Vwf7d9XIVNh5DS5ZiVxjaRCyUK642U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722399741; c=relaxed/simple; bh=ahSIr+s+HFafuqHmFomDqxGTzxgQjRqCJVh28Ds8if4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=hqfYpOLwSNnnWhFCN6a/V2XXSybNV3VXKUDYnak+Mn9VVihsT/km2j9TUrPOpPOMt+45rC1GuCsm3YSIosD3BdFAY6H4ELIgHUwgqq+NE8TY6J7vuuOHuLm7obah9M2m5FUz1N2R9MBB//oZ38VzvhKtOPIFAufbSG06nrdEjiI= 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=K7zcXt3b; arc=none smtp.client-ip=209.85.214.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="K7zcXt3b" Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-1fc4c33e746so2198975ad.2; Tue, 30 Jul 2024 21:22:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722399740; x=1723004540; 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=++YyWS0ASZfx5tTOkdNTrEJa6dMsI1hcaYHiGUePSXg=; b=K7zcXt3bO+fNHymk+a2WGdVgH2hwpssNBEXKViSh7svtdxpNIsjMgIfwmAXvvYTYWv 4eGHksHE23mphgfPkPlxYC4VjD+D//o4Q/Yodqwu9HK4yGJi7Aww3t7L85In/LZ27MtR OH/n5ocwtA3mxZyfEkaUfJSd1LMW3DQMkNJELeiHW2x60jtrwyUp7XnKdB0mqcygaD9i nkt6W7nAjGDKJ1jVDMgxkV5P9DfIkSl9CZFYtun7ytUzRAF58fTxoRgCGzu3p6B37ttV 9gwwPORPzJvIToh0rIkRA45I6m8KEB/0FmnyaoD+Rx2SJDrvHQIeSz4Y0uUrzZkQeBRB ZuHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722399740; x=1723004540; 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=++YyWS0ASZfx5tTOkdNTrEJa6dMsI1hcaYHiGUePSXg=; b=sR77xB1ifrMeYLrOubiBHSm0TC02DXnOIq04KCLOa29Zc9BYiIUuu4mkT7YHI8XI4a jotqOq0fhDEDf3ZasUWPTOxefm6uyrd66jQSSMFc5TlKYvSbTUGgK3JEhEYLqvvtt0Q1 T90e5BN4AD5KKjulALqR0RFbb5PKEIt5VOaUhjOOLHZlgccFjfEXj1vvDc/324aRMAQQ X8GrM74pxEH1mZhoz9gQxZmS4cQ1prjoE2JYfWNfe64h2xXOBwN0RoyciJnJb799UN2p /4emSOt2CoRxjxw7g82KElKDlTkLnto79PUgX3JNjDmWhH32lcTqgZ2RWOlpBzGZ+3BQ qxqA== X-Gm-Message-State: AOJu0YzyYCNQKHo8UI17vBGEj1lyIzWRYDhKRPM+/CUyBu4TzP0u0dzJ R3J0OTgRi3ptj5BPDDrx/5JsQ8DjnOor+ncFeNW4f5YzRykflkr+XDUnnWvr X-Google-Smtp-Source: AGHT+IGHwGPvLHH4EPv5bTuhQpCPmX8p8qUUcDO+WODWObp7QX54XRv5jlqqHIrSNjQT8/4yvWzo7g== X-Received: by 2002:a17:902:e546:b0:1f2:f9b9:8796 with SMTP id d9443c01a7336-1fed6bdd93dmr122477485ad.2.1722399739559; Tue, 30 Jul 2024 21:22:19 -0700 (PDT) Received: from rpi.. (p4456016-ipxg23001hodogaya.kanagawa.ocn.ne.jp. [153.204.172.16]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fed7c8d376sm110815145ad.18.2024.07.30.21.22.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jul 2024 21:22:19 -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 Subject: [PATCH net-next v2 3/6] rust: net::phy implement AsRef trait Date: Wed, 31 Jul 2024 13:21:33 +0900 Message-Id: <20240731042136.201327-4-fujita.tomonori@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240731042136.201327-1-fujita.tomonori@gmail.com> References: <20240731042136.201327-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 --- rust/kernel/net/phy.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/rust/kernel/net/phy.rs b/rust/kernel/net/phy.rs index 99a142348a34..561f0e357f31 100644 --- a/rust/kernel/net/phy.rs +++ b/rust/kernel/net/phy.rs @@ -302,6 +302,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(&mut (*phydev).mdio.dev) } + } +} + /// Defines certain other features this PHY supports (like interrupts). /// /// These flag values are used in [`Driver::FLAGS`]. From patchwork Wed Jul 31 04:21: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: 13748063 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pj1-f49.google.com (mail-pj1-f49.google.com [209.85.216.49]) (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 CE5DF2E62C; Wed, 31 Jul 2024 04:22:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722399744; cv=none; b=kUXiVnrML2W/JYX/Nc8YJTXCxwaeVhoKB26zpkwwY3URBCfjNysANIG05MjOG35gRwQ5exCNm9z8zI4eTw5lV/0quxgIlv0bPsyhkYC9adznUxpj6+zsopXeQn8Rj+m5vnmdvV+1kYyaYx43gxNrawJYxW78qjepcovlijS1Jp0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722399744; c=relaxed/simple; bh=brAXsZwdaCPpMphHTqbjgObKUlNZIvAgrHh7Hr8xtzg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=F/k0aMVXknVKnAFkuw3ZtxYDAgWXnfJokQfjrAJREyzTt/ZbNExyh65OocGT08XA+ZLWz7Y2zU3uI2X3PsopoI48aZKp3ys7TPMrhaGvn0sV6h0OiBsOUyn1AfTMwGtAuCQ9zr4iG3nn3szqitX5u972TOGYJba//GfZmuiQ9eA= 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=ZERVrB5Q; arc=none smtp.client-ip=209.85.216.49 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="ZERVrB5Q" Received: by mail-pj1-f49.google.com with SMTP id 98e67ed59e1d1-2cb6b247db0so913484a91.2; Tue, 30 Jul 2024 21:22:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722399742; x=1723004542; 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=zqp7RU5NjGqF6r9+1ttQs0jeWqmQS94MecYHa/XG+D0=; b=ZERVrB5Qw2W82QRon3f8Aw/OamTI0tycCEhdCKqDkinagSQtM2henv1+1nDr/q3CCy zbhPAOIZCcV+YJ2G4+xC2hvbFIcBvimdJhoKEhymRMAOHs8UgH+QkpeFKRvSbGgg6Du/ YqNFVq3YLsSs6OI6yJXyU6rIoyY80Nt1mr1DSaIH6jIdxKnsbMXJCtE26IwDfCttYi0K 6jASgutpWXvIMpZlqwcMJg/VmNM62hz3d3rMD8dyxWsocYMrWp+gVvt/oV3i04D/2U/f 07AZFav/pSTMjviaVWKQCpBWKeDmjvTO+/a2wQ4M20Uh+d606Wf5n5tv061eDDyI5Kjy yysg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722399742; x=1723004542; 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=zqp7RU5NjGqF6r9+1ttQs0jeWqmQS94MecYHa/XG+D0=; b=QsEVwR6vpr4N66EhxHP97TpaZPWNnKvzZA+/5qRIjKCcIS8OawjHyTcwck7DY9+A+6 zk8Hm277V2CAJCSIHKQD6Pn4yEeBd+UWNOrnQO8tEBLdikipwJ7AD9dTNVMi3SuUDMbv b9u8Fzy32swHLooq86dWiMMMTNBOrmy78oE7a058qUPalWsa5x8A7O21HTqt0TG0tx8Z Cc3I3i0tmkm4d+H0J1urUaUSxHc0YtzMGCuWhiHEoearQrZD9nLd0eifmkNw2bseGtqG bCM+A6zHQkn9dLXbwbjXkDERLrsPr8zuFHOsMsv6xTKHaXHxJJgE2ZTebuhHsZ7H+25n MXfw== X-Gm-Message-State: AOJu0YyYcGWRsMAB6MZ230Hvd+OF9O/CxM2D+mTWEA9zo8sbcndB5rHZ Io4oVc8mTITFfK5vO+NQ950RuOywnQQrM++JscUpjvPBirxtQigihA9oJYah X-Google-Smtp-Source: AGHT+IF7ktFCSOq1np7COQcf6zugMgf3B+HY62uB9RNqUq3vDCEUF5cVbQJ/reE9we660oL1DPdwWA== X-Received: by 2002:a17:902:b7ca:b0:1f7:3ed:e7b2 with SMTP id d9443c01a7336-1fed67424e9mr123318645ad.0.1722399741650; Tue, 30 Jul 2024 21:22:21 -0700 (PDT) Received: from rpi.. (p4456016-ipxg23001hodogaya.kanagawa.ocn.ne.jp. [153.204.172.16]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fed7c8d376sm110815145ad.18.2024.07.30.21.22.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jul 2024 21:22:21 -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 Subject: [PATCH net-next v2 4/6] rust: net::phy unified read/write API for C22 and C45 registers Date: Wed, 31 Jul 2024 13:21:34 +0900 Message-Id: <20240731042136.201327-5-fujita.tomonori@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240731042136.201327-1-fujita.tomonori@gmail.com> References: <20240731042136.201327-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 | 32 ++--- rust/kernel/net/phy/reg.rs | 193 +++++++++++++++++++++++++++++++ rust/uapi/uapi_helper.h | 1 + 5 files changed, 206 insertions(+), 28 deletions(-) create mode 100644 rust/kernel/net/phy/reg.rs diff --git a/MAINTAINERS b/MAINTAINERS index c0a3d9e93689..2f85fad3b939 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -8353,6 +8353,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 561f0e357f31..7ee06dd5a1b1 100644 --- a/rust/kernel/net/phy.rs +++ b/rust/kernel/net/phy.rs @@ -7,9 +7,10 @@ //! C headers: [`include/linux/phy.h`](srctree/include/linux/phy.h). use crate::{error::*, prelude::*, types::Opaque}; - use core::marker::PhantomData; +pub mod reg; + /// PHY state machine states. /// /// Corresponds to the kernel's [`enum phy_state`]. @@ -175,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 Wed Jul 31 04:21: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: 13748065 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pj1-f50.google.com (mail-pj1-f50.google.com [209.85.216.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 E552731A60; Wed, 31 Jul 2024 04:22:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722399749; cv=none; b=p6dYpgO+DJz4QUnK8PeOXDP9SovpltoEsglKN5HglPzTUCFyOv5/13aNXr8Bh+jtghKUHnb6n15TZmzvib8rjWgtHqSGFTmkz8HZTaMuNjhymTV/BsBqdgj97/jWvvM3g9MJF2thW8HIylE+i5HRLW1LizqkDiGPDdc9s2fGVIY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722399749; c=relaxed/simple; bh=EElCyadeekEfno3mu9oVNwL8HZSElxozh54kmrj1XyE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=dSYXnGpirEXepij51wQCaXfmApkaGZD8QrQBY1gLoxJ8h+sHqCKdP5ddrHhRf0WjgK8VVDsAPOYktmyiCjrUJnDQk7qpA49qQwlUyjUUO0JAAKj4ymQy69qtFdO4fYZs16byx9gk7lPEtydaEjIzdRX+uUBZte6WLnsgZV2rn9E= 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=Cx7bQ1AS; arc=none smtp.client-ip=209.85.216.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="Cx7bQ1AS" Received: by mail-pj1-f50.google.com with SMTP id 98e67ed59e1d1-2cdba9c71ebso957490a91.2; Tue, 30 Jul 2024 21:22:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722399744; x=1723004544; 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=NkpEiKThjKWf5IvvvkusNDCDk2uO0uXuRG0X4aMvshk=; b=Cx7bQ1AS5cPiJ+utKq0jPyHjVztf4PPA2mXT2Gn2FQSbU+U71R+WFbA3r0V/pwkaZH XBZfUgqa4B7q6AH/IS2ss9RA9fah0ingQ4wOkt+tlV3vWRE8Yng5fD08A7nf3w11vPxx UgK5YOG1QNWwwlTxv6tKB51orLefhFBy+2hG4o0rIX9jCDZQeCZAXbTqPx92Gjs7UoM0 4kBG7edGEfY0TmZ5D6swaZEOFooKLNltB8a44qTNodz8tNPjEmtRwbU0peQL/eCEWltY W7b6X/Zhz+wJqt+v/JEuW8sDbU4fGpE7GhghaSC7eQ6F3Pa4iv217u1MQ5xFyCcmAMvt bRNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722399744; x=1723004544; 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=NkpEiKThjKWf5IvvvkusNDCDk2uO0uXuRG0X4aMvshk=; b=pecuLE03ZRXTkrtWIraJKENI1E4Zp0RfMcolYBPwZ6IAd3x+5Yr8x2g3BSXN4sO8+F 4WRYGYN8nX9b2QBlBzdsa0VYC7/t+zVfcBPMsn1wd/tWk+qL44HYqIEZPaC0ibg86dOS j1qfJZrdfQIlnLfSuzyEFE0vi2bfo0Oa3Kag/u+8dt5EHTVvpZvw/ToJdVKi5jywdBwy 1bj6nbiKoos760wLGaSsXA6MmeOwEEv0TVWIe9DFH3J+9aRXJFH5pzw4vGrNUwMgpa3f HfNJGZ4hjjeVSyYW7mzOaG+JiXSuhBDFGoPSrjrvhisS40yDGyZY+4SGIJRrd/MOZy+N fyRQ== X-Gm-Message-State: AOJu0Yycitq+uni/osCt7BpMSrKJNJCBXhX/MigdJT2IhJ6KP1Ak83SI J1r9kxQwshJbkzy2TlWOUzv/pH/V5PCQpMqgAOz42l8Ma/HkRX6tK6YY1VVz X-Google-Smtp-Source: AGHT+IHudcVQDvhWWHYOtc7xwBlwpUj/gWnbH60BNTegIVXrzUaWi3u2wW3GpmNZ6hdeMUgsr5tf3w== X-Received: by 2002:a17:902:bc81:b0:1fb:1ff1:89d2 with SMTP id d9443c01a7336-1fed6cca0d9mr130489795ad.6.1722399743807; Tue, 30 Jul 2024 21:22:23 -0700 (PDT) Received: from rpi.. (p4456016-ipxg23001hodogaya.kanagawa.ocn.ne.jp. [153.204.172.16]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fed7c8d376sm110815145ad.18.2024.07.30.21.22.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jul 2024 21:22:23 -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 Subject: [PATCH net-next v2 5/6] rust: net::phy unified genphy_read_status function for C22 and C45 registers Date: Wed, 31 Jul 2024 13:21:35 +0900 Message-Id: <20240731042136.201327-6-fujita.tomonori@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240731042136.201327-1-fujita.tomonori@gmail.com> References: <20240731042136.201327-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 7ee06dd5a1b1..938820704aca 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 Wed Jul 31 04:21:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: FUJITA Tomonori X-Patchwork-Id: 13748064 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pj1-f45.google.com (mail-pj1-f45.google.com [209.85.216.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 DC4F01BC4E; Wed, 31 Jul 2024 04:22:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722399748; cv=none; b=W0whGKHTs30T7WI3LMXrew9/FLpi8j2jamonK6+rZWrgPcybU9vm64y8PYJAZRXLunh4UThu6+dJmhAOKnaSFt2D7fqmO4IkiLFiYVab0zySGT4OzmaaAnEz6aoL/EsNb1jIQRcrY4LrWoroXyUdUAUi0ITrQ63ntNd+H7tacDA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722399748; c=relaxed/simple; bh=F6VQPDZkMiHUYry4mcCki7rp4ojrRPWnc1ymCkC+lAo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=f1g/H/B3RcQutyIuXS3em5xO5ANp/h1lWMQM3wIZgEu0EyRwv4k0EriQ4B0Jfo5bAiEOGmzGqzhODIlkCkjTwSqTDAshS3bhCx1rWe2y56zyS5E2nivzD3Z6RmEyhfuty1x1fPqdK8M29IvhfJOUCHEB08PC3yww4JX/wJiPx1s= 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=dC+A5ltc; arc=none smtp.client-ip=209.85.216.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="dC+A5ltc" Received: by mail-pj1-f45.google.com with SMTP id 98e67ed59e1d1-2cb6b247db0so913496a91.2; Tue, 30 Jul 2024 21:22:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722399746; x=1723004546; 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=vLlIPpgwDeHsVYKfjp5eQYx/g1IrCkH7XRUUc5epW9c=; b=dC+A5ltcEbBWz4DU3mcHhtmocCEwskf5i5kTco7CCLluhi1eWnaeVYgc8/KNLE/Lxu 4XkwY8dxt42JtXqmblAP7BeLLsLGlitVGGKI6jyJNeUyB1K3+yfgA19fcilXJ0Es5fK0 wD646yAxitbLPIlg27rX7FrCKsGoQPakHSk/sBYvkCdn1KMDOO+vKtRGsmC7xs2XlWYU xcny8o8Zv1RcZzziCrAR1A0/VuU9jrqbuB8YSilTZs8B3dOW8rW78nFmCorAzrsAoG/f Og2UE+omR9iFB0Foycb548zLkKnYj8knQjYGbcfsajlRqsFDDKb0kxz64EDB20oWU5dH QFAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722399746; x=1723004546; 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=vLlIPpgwDeHsVYKfjp5eQYx/g1IrCkH7XRUUc5epW9c=; b=NQIJaYJahZ9EQhToyET/bYgVxmGO0+tb/etpRTPUtJs6dE2SyYSbJOowh/nWqgqJ62 n4v6DO4Mzh5KO912Vb7c2+tm8O+244AYys81Susy+qnxNGNRnJCmJa7RtDXzpFpPKLBX YaxUiV7zayCIJMsjbM7K7RJaBBHT8AZCETuW+IdBpm3bOfX/AvG48ZI1xtK2v9fXyZx0 8vZruTq0QOE6LC1MYk9k9QceEMfhiTuZs+jpgrVdTKEcRjT7KtFP9lstBkgLT4ofzPyr VXCZrnkDN6MVDSvU3Y8PIhDhEhzPmG75/rW+z5Nz01BwLWGyUInD/NW1UGegRUqugg7C rrLA== X-Gm-Message-State: AOJu0YwTD4iNgY4T4KSp27RREj8jeVfDF9VsPbzHBp39InElc9CbIRcr dEYR3/jQGOVV8Se+EKWb7hhl44GNlD8LOQMnefjQ5EpFewPRPjwt7relSx0S X-Google-Smtp-Source: AGHT+IEcEjzFO5S3E/UFcjaL1FrhMmR1DelX9uRyAZ7pzBqV+YTM+8794AR0dYWDLY/wFgf31OPRoA== X-Received: by 2002:a05:6a21:3a46:b0:1c0:f5fa:db13 with SMTP id adf61e73a8af0-1c477199be3mr12111597637.2.1722399745864; Tue, 30 Jul 2024 21:22:25 -0700 (PDT) Received: from rpi.. (p4456016-ipxg23001hodogaya.kanagawa.ocn.ne.jp. [153.204.172.16]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fed7c8d376sm110815145ad.18.2024.07.30.21.22.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jul 2024 21:22:25 -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 Subject: [PATCH net-next v2 6/6] net: phy: add Applied Micro QT2025 PHY driver Date: Wed, 31 Jul 2024 13:21:36 +0900 Message-Id: <20240731042136.201327-7-fujita.tomonori@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240731042136.201327-1-fujita.tomonori@gmail.com> References: <20240731042136.201327-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 | 92 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 106 insertions(+) create mode 100644 drivers/net/phy/qt2025.rs diff --git a/MAINTAINERS b/MAINTAINERS index 2f85fad3b939..b8fda7e0343c 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..b93472865bde --- /dev/null +++ b/drivers/net/phy/qt2025.rs @@ -0,0 +1,92 @@ +// 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", +} + +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::() + } +}