From patchwork Tue Aug 20 22:57:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: FUJITA Tomonori X-Patchwork-Id: 13770618 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-oi1-f177.google.com (mail-oi1-f177.google.com [209.85.167.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0A5851C824C; Tue, 20 Aug 2024 22:59:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724194750; cv=none; b=F8cZqF3t/3v1/L46H8FADKvMdvdEHcI/pxtPAE1VMfbH5qxrgiDWrbqe9+nJDt4cgHYpPXJNZmYifrl8WqLZs0kSpYleSWLDXvP8sMFw9B8/BprroOx7HDK3QFLVb9f980fQewstugEQXw3SBLcKMK/wJxp5Qv10S8LnU71MV2U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724194750; c=relaxed/simple; bh=VZlZ5qQFEmyWTZ6qnTB3byvaBMUGoBK0XqjE8w0Zoy4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=U8f0pWB1yvNg6Y8gQNgfiIpgt5J2nx4N+pLH261NmF8NBGC5VOMEOTt2hBcMtU7ClJHi7TtJsLM4s25eu/nhBs9rRrqzTdxaHGnwDLjwGq6kp9XTRlJ0vcd9Mil/JN2TeH/93SDQy5Zyl3igOJpTpd39yEczydp2qMPsZDDrB6s= 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=gizoj3zP; arc=none smtp.client-ip=209.85.167.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="gizoj3zP" Received: by mail-oi1-f177.google.com with SMTP id 5614622812f47-3db130a872fso3763595b6e.2; Tue, 20 Aug 2024 15:59:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724194748; x=1724799548; 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=ncHo+Yl1BU/0RbHH50b50H5vuYVQz7/skUGRmr1iIUI=; b=gizoj3zPPENmYLRPROvjoeXeh+rQFW/SIlugXD1mGCt7l7btK2R5ZtSBmNVr+0nsic UVRvpPBCRQxe+FbHHU9HPT1WjkUPVqIwkRRuE6Re58rn8mi258qh+pEEpn0C4N3FT6Cs mtYcTO49xhFEvTdjgi+jShbE/aOAi6PenUX0Ez2ax/O1jMY1Qbb7kB7BBvTTj0BnHeOI fHkykwkE5clsh/qhYILXA1CjUqczIK8O54n4i/NPIFkPMyoHXcY4E5PHYLrnI5ievuSJ bH0037N9XhfXAa3+6eSVRDtLqWZVESYHaVqaztCTRcMFKxEq5aGMOnX+9qeMms1hYe+r CRNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724194748; x=1724799548; 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=ncHo+Yl1BU/0RbHH50b50H5vuYVQz7/skUGRmr1iIUI=; b=jau7VeSsMXGHhRFrVZm4CnObQdnltsYNeBNT6QimnG7ur4ddrIJDQHZ7QYuaP9eyM2 FDwPlSh959OAi0+NwOEYelaGXIq7RHAUgzAgFlEwVfNqhm+PwJ+wyK9skYgf7omTnQIP VP/j8ycaQoDjk1/Z4pi+7xCcMBeb0NtONcb7Ku0EjNHRWMcnaX9YY0oi9IJSqmIQ6M78 E3AenUmq5T4ghHgpNrmJjsi3VmS+1dgXiqUj/oC1SDg4zSaroAn2iIK4uWjYOZhOW3nl cgzDxjAh9E9LqltPtjVUQYlss20yFBN9zzEZcJfGIZezmwGz6hwWCb/TCMaa9dI8J3OE wKiw== X-Gm-Message-State: AOJu0YznVgNqo6qgqRr3YopFvRBBS9h6/8foiv68bQQ2ewiKObrhJhfS JT3IT+qHw0gb/mj331MxQ7+qtXK06Kh4xqFHRbVfJD6Xvr5Eyyp2SEvsjP5l X-Google-Smtp-Source: AGHT+IGMht80K6Aq3Azms6dTMx9RTSXYfH7h/8IXLGLjZGkx1vPGWq2ojPoJ0cxkQGHSjP8hd+ltsA== X-Received: by 2002:a05:6808:ec1:b0:3d9:303a:fc6d with SMTP id 5614622812f47-3de1958fccemr876055b6e.41.1724194747914; Tue, 20 Aug 2024 15:59:07 -0700 (PDT) Received: from localhost.localdomain (p4468007-ipxg23001hodogaya.kanagawa.ocn.ne.jp. [153.204.200.7]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7c6b61d5045sm9922076a12.38.2024.08.20.15.59.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Aug 2024 15:59:07 -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 v6 1/6] rust: sizes: add commonly used constants Date: Tue, 20 Aug 2024 22:57:14 +0000 Message-ID: <20240820225719.91410-2-fujita.tomonori@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240820225719.91410-1-fujita.tomonori@gmail.com> References: <20240820225719.91410-1-fujita.tomonori@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Add rust equivalent to include/linux/sizes.h, makes code more readable. Reviewed-by: Alice Ryhl Reviewed-by: Andrew Lunn Reviewed-by: Benno Lossin Reviewed-by: Trevor Gross Signed-off-by: FUJITA Tomonori --- 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 Tue Aug 20 22:57:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: FUJITA Tomonori X-Patchwork-Id: 13770619 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-oi1-f173.google.com (mail-oi1-f173.google.com [209.85.167.173]) (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 539BF1C8FB2; Tue, 20 Aug 2024 22:59:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724194752; cv=none; b=NCekvlzbLof1x2VkyVyf+nanyIdOGz40btG+YQ+1UoTcVQqNdghRHNmQS09JzYkNkvrKxcsXDEYQK8Ry7/xVwqwybAdftsnAASczZekPTGFf86ZGiQDyhprsrpgEAsDN9/R+ip7MumFHefjo3RFHhQcXEicn3+13eZaEVfq6rvA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724194752; c=relaxed/simple; bh=Z+3W+TjB/+akxnGD/81jh9rFeSs5dXy3N237wOpbV+M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZKJS/LiNM4r0i1//te05q/DaoLjqoA7LkrOZTcohR0NpVh9+Ke5li1803ss14v1LukfBb+lJ/9Uv/CbsHdWqJLbIPkLymqKQM2lv3NJvWuMX10yjJ8YOBQv2MfHDPjW6xrnqqrHsUQnLZw2W/C+Mr+ncdfc6sO9SABrRt7W0494= 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=eSWG40Du; arc=none smtp.client-ip=209.85.167.173 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="eSWG40Du" Received: by mail-oi1-f173.google.com with SMTP id 5614622812f47-3db2315d7ceso3395294b6e.1; Tue, 20 Aug 2024 15:59:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724194750; x=1724799550; 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=rEn+T3edq3AlPKEeI8Gs8XwEjBjg6OpikVH3BRZII5Q=; b=eSWG40DulNhp7lbKOjvE8xRp6LsEKrk7SFFxbtmZ+Vg0hhvn2ErJ7jJEXRo+IsHDb+ M6yBsPjUrL4FJEAjOYifWvecXcxfr8/hkmDsckkODt8D/PYnVIP5ocATa9iJCWmQIXto p0pMQZ3BOfUkMHbs85WpqqlrtiK9RKO/45OJKNeJ4zhzv5qryl6zw0zIwZzJx/t7bZPm YtMRjee6Raq+VzWHgxG03dE+qBiqUcKCW+pd9Ex1nlTvMapj67VtJjI0l41uKLBYPnQ7 s6nHCHzgBQvwRx1pwGP+w5+/9oK1nzcTQZvktpESlvoki3zJsrBoO2kV+ksHZDHWUJhK i9yA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724194750; x=1724799550; 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=rEn+T3edq3AlPKEeI8Gs8XwEjBjg6OpikVH3BRZII5Q=; b=CfoDBB/sRPQW8E0rshf/H6CJcOF3l247fN1uYs42wfGGZ7YcIcY4XQYiPW1v3FIua0 WUKJM2CLY9WdTXCb7Ud9ObK6RD8Bq5J/WXMSiVkZWlwfhKGfcLVU5eb+JI3aIPc18No/ T2Y9ObCWoawnPf11YxJtd9bSWlVTTtlAxfwFOQ+i/osBG2rVzSI+LT10DUQR87uUSUA3 ihKVn1HYvsDgC2a2Z/lvPXgrgjtG6q+vfqKynU//uoiEFta2LYBjw0AgSsQkicoUUj1S DcYlQ3C6ft4+tgS2GtoNPV7E0iXNKu30WRvhWMzUlGrQN524Xo0th2/6L3EwDgQ7DwQN 5MBA== X-Gm-Message-State: AOJu0Yw0xJpeoehg4EwgBkFQfUMOh9/9ZGjx9kWvDLM/O/1xBDirRmVM cxsikeCE9hCcGxCqxbPswUPZkjZsReMwlhwAIK9EbCp77e32tnAEnHZrvlLw X-Google-Smtp-Source: AGHT+IHU6k1OH2U2QpMmPC0J/hjEHPnvHiWDulna0liDaDjOWrAtuSC2PTrt0VL4YmkL0JHks0yKdA== X-Received: by 2002:a05:6808:bcc:b0:3da:4c28:6697 with SMTP id 5614622812f47-3de19576b4emr799559b6e.38.1724194750170; Tue, 20 Aug 2024 15:59:10 -0700 (PDT) Received: from localhost.localdomain (p4468007-ipxg23001hodogaya.kanagawa.ocn.ne.jp. [153.204.200.7]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7c6b61d5045sm9922076a12.38.2024.08.20.15.59.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Aug 2024 15:59:09 -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 v6 2/6] rust: net::phy support probe callback Date: Tue, 20 Aug 2024 22:57:15 +0000 Message-ID: <20240820225719.91410-3-fujita.tomonori@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240820225719.91410-1-fujita.tomonori@gmail.com> References: <20240820225719.91410-1-fujita.tomonori@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Support phy_driver probe callback, used to set up device-specific structures. Reviewed-by: Alice Ryhl Reviewed-by: Andrew Lunn Reviewed-by: Benno Lossin Reviewed-by: Trevor Gross Signed-off-by: FUJITA Tomonori --- rust/kernel/net/phy.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/rust/kernel/net/phy.rs b/rust/kernel/net/phy.rs index fd40b703d224..5e8137a1972f 100644 --- a/rust/kernel/net/phy.rs +++ b/rust/kernel/net/phy.rs @@ -338,6 +338,21 @@ impl Adapter { }) } + /// # Safety + /// + /// `phydev` must be passed by the corresponding callback in `phy_driver`. + unsafe extern "C" fn probe_callback(phydev: *mut bindings::phy_device) -> core::ffi::c_int { + from_result(|| { + // SAFETY: This callback is called only in contexts + // where we can exclusively access `phy_device` because + // it's not published yet, so the accessors on `Device` are okay + // to call. + let dev = unsafe { Device::from_raw(phydev) }; + T::probe(dev)?; + Ok(0) + }) + } + /// # Safety /// /// `phydev` must be passed by the corresponding callback in `phy_driver`. @@ -511,6 +526,11 @@ pub const fn create_phy_driver() -> DriverVTable { } else { None }, + probe: if T::HAS_PROBE { + Some(Adapter::::probe_callback) + } else { + None + }, get_features: if T::HAS_GET_FEATURES { Some(Adapter::::get_features_callback) } else { @@ -583,6 +603,11 @@ fn soft_reset(_dev: &mut Device) -> Result { kernel::build_error(VTABLE_DEFAULT_ERROR) } + /// Sets up device-specific structures during discovery. + fn probe(_dev: &mut Device) -> Result { + kernel::build_error(VTABLE_DEFAULT_ERROR) + } + /// Probes the hardware to determine what abilities it has. fn get_features(_dev: &mut Device) -> Result { kernel::build_error(VTABLE_DEFAULT_ERROR) From patchwork Tue Aug 20 22:57:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: FUJITA Tomonori X-Patchwork-Id: 13770620 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pf1-f182.google.com (mail-pf1-f182.google.com [209.85.210.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 81F821C8FC6; Tue, 20 Aug 2024 22:59:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724194755; cv=none; b=W/PHzRJ8bmRFHJnGvIOvRudqOHgH4K9WQ+5vNDg3RUMa6HD1kNw1EV1nWL+Lhjg0X1ek4hPgDo0nLE0Y9HGSU39BWZRcXo65EQLu20KwoG0zT3aHWoMcmBbwlH5h79hKj6gp5z5559fi3toa3yJI/AXoJL/z3p5PoIcnC9EKnlo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724194755; c=relaxed/simple; bh=aHiVGhRwYAsQczP9WqvPUI9lvDsw7q7yZyu98J4LwcI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EtcWyHvt3WUoeBz65mgKsWl73bUEfBaCPz0UuDqSF9fDIGmiUhCeML6UTTbo95qMz+5xLpvRkJ4KOrbxHxBUGEf0NOITGGQ4y9luFv9FX+v/IdANr1X8EdZtcf4s9vcEsgtLUuQ41YTJjkSmNdpd4Ntz9MM/AAC9NDsBYmBUgzE= 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=QdWDdPB3; arc=none smtp.client-ip=209.85.210.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="QdWDdPB3" Received: by mail-pf1-f182.google.com with SMTP id d2e1a72fcca58-70d1d6369acso160525b3a.0; Tue, 20 Aug 2024 15:59:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724194753; x=1724799553; 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=7Mrcl7Z+31Fhv7Hq2xBCP13+zdTE4Tg47VezA00ALMk=; b=QdWDdPB3rgz5oaQOuh6pCLadecbo8O8nFuGc3Kte9CwMTYMmnGRqqw3rW5WaQ8zp1m tgsvH/I4K8+QACUiwnu06eh5B0NoSvMoKcoKvBJxNV70nSMdpoYoAMlhJeOMkPiyLFIx svm068i1kUv+KaUD+yX7MY3SOh7O+qiR1WB4v19g3XUAr/N+NiLAkjx6wFQO4lmUC2m7 F4AbIyy40eByi/jCb+jwgyLsPzToKMNqmijdfHfO70OSln8o+pI3WAWpOTdo2uQSEGlv 0Kmav00vDplQIYYrDrUFAGMrkSgJi5uSRIbDIB34vM/+f1vMlXDycfm5Fyu4i5C5tifF J1Gw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724194753; x=1724799553; 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=7Mrcl7Z+31Fhv7Hq2xBCP13+zdTE4Tg47VezA00ALMk=; b=VPxtRub539triWrb57YEUs6O3y1LMA+0bD5eb2IhdHAxLHTRKviYK5LY7iKPWIwRii wg9NDoIKU7j2Wpwk9DkRk7VH8SbxWB9JY94bRDBGnsX+ieSCWBFmVaha24GrI/nil4nB whcwWrBsFMPRMwLjgtti0efokBtzjBI/ENDHVSVDLYPJXvWjot/m6v7TmF5ZtbjvAvux SUmxSDWRWCLuRS+pzp9Hl7XR+YGeCLSj9mo36itDtNGiip8beEFJRVlCJhy5TzDpAIHm oq5CeeRQxGTMiyP/ODW1yhkcqL0AvbeYNzGFUvM/WmKy3g8mAEseixbPZYJoayijFXxN gMmg== X-Gm-Message-State: AOJu0YwnmupXQWcQVURVxgrcTfkhBTz8ZSNuzrO8sfYRnzScIzoGsJK6 euZDDaqf7a0a707cw0K2jFwIwXCR/7kkfXDg0zUP9XS2hVrsC+N8pk00UvgC X-Google-Smtp-Source: AGHT+IFg8WIKWd2W59nve96c3TvLZk2eWL2mQdTlkW1xQH37KgGlWKc8MdsyigLup+q16lAb82zY0w== X-Received: by 2002:a05:6a21:4581:b0:1c4:85a2:9958 with SMTP id adf61e73a8af0-1cada298244mr640875637.25.1724194752387; Tue, 20 Aug 2024 15:59:12 -0700 (PDT) Received: from localhost.localdomain (p4468007-ipxg23001hodogaya.kanagawa.ocn.ne.jp. [153.204.200.7]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7c6b61d5045sm9922076a12.38.2024.08.20.15.59.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Aug 2024 15:59:12 -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 v6 3/6] rust: net::phy implement AsRef trait Date: Tue, 20 Aug 2024 22:57:16 +0000 Message-ID: <20240820225719.91410-4-fujita.tomonori@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240820225719.91410-1-fujita.tomonori@gmail.com> References: <20240820225719.91410-1-fujita.tomonori@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Implement AsRef trait for Device. A PHY driver needs a reference to device::Device to call the firmware API. Reviewed-by: Alice Ryhl Reviewed-by: Andrew Lunn Reviewed-by: Benno Lossin Reviewed-by: Trevor Gross Signed-off-by: FUJITA Tomonori --- rust/kernel/net/phy.rs | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/rust/kernel/net/phy.rs b/rust/kernel/net/phy.rs index 5e8137a1972f..b16e8c10a0a2 100644 --- a/rust/kernel/net/phy.rs +++ b/rust/kernel/net/phy.rs @@ -7,8 +7,7 @@ //! C headers: [`include/linux/phy.h`](srctree/include/linux/phy.h). use crate::{error::*, prelude::*, types::Opaque}; - -use core::marker::PhantomData; +use core::{marker::PhantomData, ptr::addr_of_mut}; /// PHY state machine states. /// @@ -58,8 +57,9 @@ pub enum DuplexMode { /// /// # Invariants /// -/// Referencing a `phy_device` using this struct asserts that you are in -/// a context where all methods defined on this struct are safe to call. +/// - Referencing a `phy_device` using this struct asserts that you are in +/// a context where all methods defined on this struct are safe to call. +/// - This struct always has a valid `self.0.mdio.dev`. /// /// [`struct phy_device`]: srctree/include/linux/phy.h // During the calls to most functions in [`Driver`], the C side (`PHYLIB`) holds a lock that is @@ -76,9 +76,11 @@ impl Device { /// /// # Safety /// - /// For the duration of 'a, the pointer must point at a valid `phy_device`, - /// and the caller must be in a context where all methods defined on this struct - /// are safe to call. + /// For the duration of `'a`, + /// - the pointer must point at a valid `phy_device`, and the caller + /// must be in a context where all methods defined on this struct + /// are safe to call. + /// - `(*ptr).mdio.dev` must be a valid. unsafe fn from_raw<'a>(ptr: *mut bindings::phy_device) -> &'a mut Self { // CAST: `Self` is a `repr(transparent)` wrapper around `bindings::phy_device`. let ptr = ptr.cast::(); @@ -302,6 +304,14 @@ pub fn genphy_read_abilities(&mut self) -> Result { } } +impl AsRef for Device { + fn as_ref(&self) -> &kernel::device::Device { + let phydev = self.0.get(); + // SAFETY: The struct invariant ensures that `mdio.dev` is valid. + unsafe { kernel::device::Device::as_ref(addr_of_mut!((*phydev).mdio.dev)) } + } +} + /// Defines certain other features this PHY supports (like interrupts). /// /// These flag values are used in [`Driver::FLAGS`]. From patchwork Tue Aug 20 22:57:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: FUJITA Tomonori X-Patchwork-Id: 13770621 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 CDCB41C8FDE; Tue, 20 Aug 2024 22:59:15 +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=1724194757; cv=none; b=pKCgEOKe//nuJo4M9NAwwGjYxjyM4KXbWzbHQIQrCvYgz9rMgZ/4fWmc61RAMMtFAqkZxBbUsitipxsskTMIc8IUbdcJ/xakUaQS/l+lTAatzUND8UCGQAFojWKFsCUR34GosGtGLKPyUR/SdgD7IaJFeo28467O9DG0eBQCGF4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724194757; c=relaxed/simple; bh=S5zkxpATFwetTi9bWfpFFdeUxKyFSKs+AMtNz4KCZV8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=V3l6Ct+/DiZrdw1jL/YvmeeSec/zbnMFhTVHrw5kQ2ZoUTnt8REh9PJWfECndmm4xU8vNM1Ww9q4cZSJLyzijaBhG6Ba0OH2dqVYCW1ZVknBuTgKXuIQ/48vQDjkyY7fGKTHSieAk3gf01INrMp6U78L3vmvV4e9vLhAUpCZZF0= 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=Bcbz0KLs; 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="Bcbz0KLs" Received: by mail-pg1-f182.google.com with SMTP id 41be03b00d2f7-7c6aee8e8daso4193081a12.0; Tue, 20 Aug 2024 15:59:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724194755; x=1724799555; 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=XXUuOruEl2gk6u3o0am5+Sa5un4jX2I2MrYZDBAKn70=; b=Bcbz0KLsWGiOwL8fRe0RL0SpUZ7kpvEVp0+m/Y8D64ivvGFoeJV8vJPN5slp7yWAAM aiAs3Dj95vPqVLl+FZJqXgNu24xLvUrCZo+VGFK5ugqPrQH+Cf951nsI2q2jaP8rod0p O+YEgXuCe1T0npOB5ZCFKt8qzxjnDqAKU6/uA6uM/8tQRp5SdMg3N5xIuKm+5QVQu6oi 0/UKShUBYcf86SR0YU2/3CUzhMkzuLCJYjIWp9sYspelPyc3rJTH+eVakdgxscT+9Pw2 nBpMDsRCywCSKP/B0nnibJAMguRQX+Gz8nxQ2e4CFN6rjz+taegDG3YRlroXnVO3MlFV RiCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724194755; x=1724799555; 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=XXUuOruEl2gk6u3o0am5+Sa5un4jX2I2MrYZDBAKn70=; b=TYkCLc1rYMQJaiyWFY3Bz1VguqZqAYWifNh039fipYIPSs565F+GhqUVcOAym9g0Vl /QGo1gK67tfQS5XYB4sqGbywt44csU0bam6xhIhmgHbLNMoDXf69EqYGdDw3ZJiFL5+K duiMtTsNzym3XLzH18o/oQBNztxtqfcDR7MwAPQ8PhjKmOZZ93Aj7PloOkrMLaEalgLG YKMu4PcE9N8LMG21ms0vxYPw+uPgFYph0bCP8dxjW/y/drStIochDMyiKCvpWZlsgfLL Y8RsX+J1HnmWCzjEbEbvZjkrllxe+fzle2QlSqVuSOQ8RaFxAtlcWO/g8FQu8rfXjM3A WBSA== X-Gm-Message-State: AOJu0YxS7GNvkX9bykRhypkwZFO6/IEkKqVinAQ+LSRZX1jPhqyJWzpQ nRH4Pg/bLC36v+vfG/4HUC2ZW7VZJf0aO8Zdk0/2iDEbUe2arZCgicg0Slcq X-Google-Smtp-Source: AGHT+IFRaTP+pypxnjOPwGEGth/XUUKgWAJslcHcHW6tNzouiQPV+gObttE1bWvvyvnIcy/UNB+0Ng== X-Received: by 2002:a05:6a21:3482:b0:1c4:8291:e94e with SMTP id adf61e73a8af0-1cad818534emr1248675637.45.1724194754633; Tue, 20 Aug 2024 15:59:14 -0700 (PDT) Received: from localhost.localdomain (p4468007-ipxg23001hodogaya.kanagawa.ocn.ne.jp. [153.204.200.7]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7c6b61d5045sm9922076a12.38.2024.08.20.15.59.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Aug 2024 15:59:14 -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 v6 4/6] rust: net::phy unified read/write API for C22 and C45 registers Date: Tue, 20 Aug 2024 22:57:17 +0000 Message-ID: <20240820225719.91410-5-fujita.tomonori@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240820225719.91410-1-fujita.tomonori@gmail.com> References: <20240820225719.91410-1-fujita.tomonori@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Add the unified read/write API for C22 and C45 registers. The abstractions support access to only C22 registers now. Instead of adding read/write_c45 methods specifically for C45, a new reg module supports the unified API to access C22 and C45 registers with trait, by calling an appropriate phylib functions. Reviewed-by: Trevor Gross Reviewed-by: Benno Lossin Reviewed-by: Andrew Lunn Signed-off-by: FUJITA Tomonori --- MAINTAINERS | 1 + drivers/net/phy/ax88796b_rust.rs | 7 +- rust/kernel/net/phy.rs | 31 ++--- rust/kernel/net/phy/reg.rs | 196 +++++++++++++++++++++++++++++++ rust/uapi/uapi_helper.h | 1 + 5 files changed, 209 insertions(+), 27 deletions(-) create mode 100644 rust/kernel/net/phy/reg.rs diff --git a/MAINTAINERS b/MAINTAINERS index 5dbf23cf11c8..9dbfcf77acb2 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -8354,6 +8354,7 @@ L: netdev@vger.kernel.org L: rust-for-linux@vger.kernel.org S: Maintained F: rust/kernel/net/phy.rs +F: rust/kernel/net/phy/reg.rs EXEC & BINFMT API, ELF R: Eric Biederman diff --git a/drivers/net/phy/ax88796b_rust.rs b/drivers/net/phy/ax88796b_rust.rs index 5c92572962dc..8c7eb009d9fc 100644 --- a/drivers/net/phy/ax88796b_rust.rs +++ b/drivers/net/phy/ax88796b_rust.rs @@ -6,7 +6,7 @@ //! C version of this driver: [`drivers/net/phy/ax88796b.c`](./ax88796b.c) use kernel::{ c_str, - net::phy::{self, DeviceId, Driver}, + net::phy::{self, reg::C22, DeviceId, Driver}, prelude::*, uapi, }; @@ -24,7 +24,6 @@ license: "GPL", } -const MII_BMCR: u16 = uapi::MII_BMCR as u16; const BMCR_SPEED100: u16 = uapi::BMCR_SPEED100 as u16; const BMCR_FULLDPLX: u16 = uapi::BMCR_FULLDPLX as u16; @@ -33,7 +32,7 @@ // Toggle BMCR_RESET bit off to accommodate broken AX8796B PHY implementation // such as used on the Individual Computers' X-Surf 100 Zorro card. fn asix_soft_reset(dev: &mut phy::Device) -> Result { - dev.write(uapi::MII_BMCR as u16, 0)?; + dev.write(C22::BMCR, 0)?; dev.genphy_soft_reset() } @@ -55,7 +54,7 @@ fn read_status(dev: &mut phy::Device) -> Result { } // If MII_LPA is 0, phy_resolve_aneg_linkmode() will fail to resolve // linkmode so use MII_BMCR as default values. - let ret = dev.read(MII_BMCR)?; + let ret = dev.read(C22::BMCR)?; if ret & BMCR_SPEED100 != 0 { dev.set_speed(uapi::SPEED_100); diff --git a/rust/kernel/net/phy.rs b/rust/kernel/net/phy.rs index b16e8c10a0a2..45866db14c76 100644 --- a/rust/kernel/net/phy.rs +++ b/rust/kernel/net/phy.rs @@ -9,6 +9,8 @@ use crate::{error::*, prelude::*, types::Opaque}; use core::{marker::PhantomData, ptr::addr_of_mut}; +pub mod reg; + /// PHY state machine states. /// /// Corresponds to the kernel's [`enum phy_state`]. @@ -177,32 +179,15 @@ pub fn set_duplex(&mut self, mode: DuplexMode) { unsafe { (*phydev).duplex = v }; } - /// Reads a given C22 PHY register. + /// Reads a PHY register. // This function reads a hardware register and updates the stats so takes `&mut self`. - pub fn read(&mut self, regnum: u16) -> Result { - let phydev = self.0.get(); - // SAFETY: `phydev` is pointing to a valid object by the type invariant of `Self`. - // So it's just an FFI call, open code of `phy_read()` with a valid `phy_device` pointer - // `phydev`. - let ret = unsafe { - bindings::mdiobus_read((*phydev).mdio.bus, (*phydev).mdio.addr, regnum.into()) - }; - if ret < 0 { - Err(Error::from_errno(ret)) - } else { - Ok(ret as u16) - } + pub fn read(&mut self, reg: R) -> Result { + reg.read(self) } - /// Writes a given C22 PHY register. - pub fn write(&mut self, regnum: u16, val: u16) -> Result { - let phydev = self.0.get(); - // SAFETY: `phydev` is pointing to a valid object by the type invariant of `Self`. - // So it's just an FFI call, open code of `phy_write()` with a valid `phy_device` pointer - // `phydev`. - to_result(unsafe { - bindings::mdiobus_write((*phydev).mdio.bus, (*phydev).mdio.addr, regnum.into(), val) - }) + /// Writes a PHY register. + pub fn write(&mut self, reg: R, val: u16) -> Result { + reg.write(self, val) } /// Reads a paged register. diff --git a/rust/kernel/net/phy/reg.rs b/rust/kernel/net/phy/reg.rs new file mode 100644 index 000000000000..191b96a524f5 --- /dev/null +++ b/rust/kernel/net/phy/reg.rs @@ -0,0 +1,196 @@ +// SPDX-License-Identifier: GPL-2.0 + +// Copyright (C) 2024 FUJITA Tomonori + +//! PHY register interfaces. +//! +//! This module provides support for accessing PHY registers in the +//! Ethernet management interface clauses 22 and 45 register namespaces, as +//! defined in IEEE 802.3. + +use super::Device; +use crate::build_assert; +use crate::error::*; +use crate::uapi; + +mod private { + /// Marker that a trait cannot be implemented outside of this crate + pub trait Sealed {} +} + +/// Accesses PHY registers. +/// +/// This trait is used to implement the unified interface to access +/// C22 and C45 PHY registers. +/// +/// # Examples +/// +/// ```ignore +/// fn link_change_notify(dev: &mut Device) { +/// // read C22 BMCR register +/// dev.read(C22::BMCR); +/// // read C45 PMA/PMD control 1 register +/// dev.read(C45::new(Mmd::PMAPMD, 0)); +/// } +/// ``` +pub trait Register: private::Sealed { + /// Reads a PHY register. + fn read(&self, dev: &mut Device) -> Result; + + /// Writes a PHY register. + fn write(&self, dev: &mut Device, val: u16) -> Result; +} + +/// A single MDIO clause 22 register address (5 bits). +#[derive(Copy, Clone)] +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. +#[derive(Copy, Clone)] +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 Tue Aug 20 22:57:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: FUJITA Tomonori X-Patchwork-Id: 13770622 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-oi1-f169.google.com (mail-oi1-f169.google.com [209.85.167.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 EC93E1C9DC4; Tue, 20 Aug 2024 22:59:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724194759; cv=none; b=KeSfGP637aqZhDdKyUyKK8bxpbJsga2MjyNhctv9H6raGj3Bq9vt7EybePDB8ltLnV4JrOrbsK0Egpuxuarg3o8hCzo5CLWCnz6WIgLpwaX64rNaapESvjYTndBvPuqNfkps7FVXd+4uixTOG8qT0UCjVVazhaZ6bkEe+vZfmuA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724194759; c=relaxed/simple; bh=yW56BZHZUfncLkfqi94dO6YFbJLn0EcSIdANOSc40eo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BDaxfCv5OStpgdtJ/bSxpmqTU3M/OQiPZ6l/xImSDnuTE2XEtpVc2XZCFLdhlXTiLK8upnI/L742LxrcTugVvoafdlNJdWGvxYHWi1tD3ge/z96tEqQ3HUHWt32coojm+cXIcQksmb+VJ+SoWhPsXtkM0uzvhGOQCn9q/Im7rbg= 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=YfTJGIxJ; arc=none smtp.client-ip=209.85.167.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="YfTJGIxJ" Received: by mail-oi1-f169.google.com with SMTP id 5614622812f47-3db1d0fca58so3649398b6e.3; Tue, 20 Aug 2024 15:59:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724194757; x=1724799557; 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=O2CZcdR/DCR2N+rA9DR4gVTG5pOnDP4T1vaCkucmKOE=; b=YfTJGIxJ+L8xig1NFnZrO16c5D9kG79qJikCgnoDBS1/G6rPyL1I7V0vNcsrIw64nb BXORhIwiYnHpeJZzcoGDQz4INrAuMw7fAflKbk6uiu9HC54VtDB7y6ttOi2funKgteRn INnvugcsk37mRghs8lhrwjB210pA5zfoh/LoZcRQDCiA1+2ihrrsLs8iGPq5O80gKNMH 9n+HDpSng8K+eRTyNdHWbwtRVFaGYGwS/JzqtrpE4awTyclvu53vY1iir9a1K9mkeW8s kktvP1FaY+Z2uafbgDnS9tEc7xM2/0xSragfzKMfDXQNjKNzChgMVkIU8SuN8Av81JKM P7ng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724194757; x=1724799557; 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=O2CZcdR/DCR2N+rA9DR4gVTG5pOnDP4T1vaCkucmKOE=; b=pQGty6crj0+TpsF0luGV2YBXyodsHtbMujaTgCja4CRiY3yXeaXlIwdc+ulhSnZF/k SGinlCuGtijwIM63UhIPiLdq01CKF8VHgheNhBHK5bihrOXSOX97g15EWvrKZtxS1YuM wcMNEeEfVannE/pbsEf3imdknz9qRNx/LZVbV0X+oGi/0jVnDyf7lwMIpVOl91A9N68b wDTnxH57EQK0K1zvnzaJGlwZOLlz0/QRFgW0hjIXFtHozj/TfxGO1uJev5FBnZ8eBpvr qmeRzBLj6NusYRp6WQVvcn5RTZ5e9OJAIGUvxpivFFNp/UPEju7oAtPHm3Or4fbF7IKj Yj2Q== X-Gm-Message-State: AOJu0YxdK2cSyZLkJmZQI+30NtvvSPbdc8V8Nay0L0Y1CvYtF2WfxZTA 6AfLoK1YOWTgpjj8y+v8oVbzxTPuFpTjM8eK0EBZPsaWzeZOjRJBMqPPJIc4 X-Google-Smtp-Source: AGHT+IHIkbG5wC/Qgkp+TnPpi4ceyUYf4D6xLq1hFyrYW3qqL0nUfdP7L3iaVgNcXuax8kTM47LRTg== X-Received: by 2002:a05:6808:14ce:b0:3d9:2b45:1585 with SMTP id 5614622812f47-3de195591a1mr1018151b6e.22.1724194756845; Tue, 20 Aug 2024 15:59:16 -0700 (PDT) Received: from localhost.localdomain (p4468007-ipxg23001hodogaya.kanagawa.ocn.ne.jp. [153.204.200.7]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7c6b61d5045sm9922076a12.38.2024.08.20.15.59.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Aug 2024 15:59:16 -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 v6 5/6] rust: net::phy unified genphy_read_status function for C22 and C45 registers Date: Tue, 20 Aug 2024 22:57:18 +0000 Message-ID: <20240820225719.91410-6-fujita.tomonori@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240820225719.91410-1-fujita.tomonori@gmail.com> References: <20240820225719.91410-1-fujita.tomonori@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Add unified genphy_read_status function for C22 and C45 registers. Instead of having genphy_c22 and genphy_c45 methods, this unifies genphy_read_status functions for C22 and C45. Reviewed-by: Trevor Gross Reviewed-by: Benno Lossin Reviewed-by: Andrew Lunn Signed-off-by: FUJITA Tomonori --- rust/kernel/net/phy.rs | 12 ++---------- rust/kernel/net/phy/reg.rs | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/rust/kernel/net/phy.rs b/rust/kernel/net/phy.rs index 45866db14c76..1d47884aa3cf 100644 --- a/rust/kernel/net/phy.rs +++ b/rust/kernel/net/phy.rs @@ -252,16 +252,8 @@ pub fn genphy_suspend(&mut self) -> Result { } /// Checks the link status and updates current link state. - pub fn genphy_read_status(&mut self) -> Result { - let phydev = self.0.get(); - // SAFETY: `phydev` is pointing to a valid object by the type invariant of `Self`. - // So it's just an FFI call. - let ret = unsafe { bindings::genphy_read_status(phydev) }; - if ret < 0 { - Err(Error::from_errno(ret)) - } else { - Ok(ret as u16) - } + pub fn genphy_read_status(&mut self) -> Result { + R::read_status(self) } /// Updates the link status. diff --git a/rust/kernel/net/phy/reg.rs b/rust/kernel/net/phy/reg.rs index 191b96a524f5..c784e6834bfa 100644 --- a/rust/kernel/net/phy/reg.rs +++ b/rust/kernel/net/phy/reg.rs @@ -31,6 +31,13 @@ pub trait Sealed {} /// dev.read(C22::BMCR); /// // read C45 PMA/PMD control 1 register /// dev.read(C45::new(Mmd::PMAPMD, 0)); +/// +/// // Checks the link status as reported by registers in the C22 namespace +/// // and updates current link state. +/// dev.genphy_read_status::(); +/// // Checks the link status as reported by registers in the C45 namespace +/// // and updates current link state. +/// dev.genphy_read_status::(); /// } /// ``` pub trait Register: private::Sealed { @@ -39,6 +46,9 @@ pub trait Register: private::Sealed { /// Writes a PHY register. fn write(&self, dev: &mut Device, val: u16) -> Result; + + /// Checks the link status and updates current link state. + fn read_status(dev: &mut Device) -> Result; } /// A single MDIO clause 22 register address (5 bits). @@ -113,6 +123,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. @@ -193,4 +212,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 Tue Aug 20 22:57:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: FUJITA Tomonori X-Patchwork-Id: 13770623 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 387691C9DD7; Tue, 20 Aug 2024 22:59:20 +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=1724194761; cv=none; b=h6hoiVh4kiMIwZ0p2dUe533hi/yPTVaBPx9YIXVPqQNGBtHai/oVyP8kLr3E78SbkygZDeWQ0Gsd1ZiAQ10mphvSdFYkW4box7MNhOZvYZawfh36oa5ZLVRaVXc1nErIXvPA/X6necuFowVAVtVuZeGqsfHe9Pzh4q7cdZ4NeTE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724194761; c=relaxed/simple; bh=SYB1bYt/I9pbgcrV03oLTHLBqJQvuECjyVQk2wzkJ1A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=H9JlrANHFm/gIrdIWZelV6nKJJwcxiFzBbYcoLl82/LLVJesK3uW1Kxan9V0uMWYmqhp9ZST8LxP6VAOuId4hhwXlstXUwQoLBYTTE4HiuCUxvdwci/2OzWoYOOZg9W3++U3XdEvih5Zxm+xykix8wME8SSYPHtVxPvspEzm6oY= 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=aQOb8Ba4; 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="aQOb8Ba4" Received: by mail-pf1-f176.google.com with SMTP id d2e1a72fcca58-713f3b4c9f7so2065084b3a.2; Tue, 20 Aug 2024 15:59:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724194759; x=1724799559; 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=Vk6cenPh8mXerZDJZXHKSIJxmQKegqpbUXCJEqMtXGo=; b=aQOb8Ba4lRrhu6g2PP5CgYqItnPngOJh+ShxEdxEoXI8+B3NNnoPNDpGeN974Cq0Br 8/buu/UW/DvJduxp0elXHEMpkcn1wOOVOBm4P7jzOf0nkUCtLNJeQhSqinACxrkp53d7 am/YYWqdiUwhQ8YTnxOwgp8bp77AzDKvrSDx4U9tw9kqUOQ6z/L22bXmvRYErkWhDMLC ZsKayDbdmfemIYETL+XRO7u/OAU6TzWTY1S+AOKjZW88QxoIVgd1uM4Ny0PPXCX5IAGl WpDLdSo4ICslSwTtFm6LZBeBjz6Y7T2N1sZ5gBXmjwZ43syzGWtaSvEcye8nWdS4kiG1 ltQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724194759; x=1724799559; 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=Vk6cenPh8mXerZDJZXHKSIJxmQKegqpbUXCJEqMtXGo=; b=kzoqFCsZebV/Dct5jmZzruWBnVeIw8whoZTr8V6pczJL4IeZbSKCzP/Cq1veuFk7AS U0R7bFmQV+771TW1ul0YECuXCfxa/SGz2HVSrWcHx+ho455ReylPBZIuN39hBXcmLsOQ YNDEGf0f9E1hX5j/7suuwEFO083fI7ZijMteIP1WOYPxGVZcZWrt0fUEEqaoEYVfr31T ixUQ+uluVIYDFdUuQA7Lk9SpsrtffeGcQmBOlhPBq6p3rMmGJKoQ0cw2Mpj4TlP92aY0 JefKDdGZaLAtCFYqykOwf1IZKcZnP+ykLc+wh94Y8gzkBcFMcWH2B+O3siz/Ph30Ic5p /Uow== X-Gm-Message-State: AOJu0YzQg8dDk/Wzvqu4BQSHZxr0LpwmC1xVhytri/fWYoiFBj4cea8d CTYhKoWRWzEi/ztE0b/SyL/mrTIKCht/Ls6LPqZLtfPgoCffB5aQMXxMj7gj X-Google-Smtp-Source: AGHT+IHljW+8ipi10Rh9i8Rv2nwtaG7zl0rlwr9s65wUL4AOd2s4gBbwpl+LiwLtlafo5waOFsrJCw== X-Received: by 2002:a05:6a20:c78e:b0:1c4:919f:3677 with SMTP id adf61e73a8af0-1cada1488c8mr750933637.42.1724194759047; Tue, 20 Aug 2024 15:59:19 -0700 (PDT) Received: from localhost.localdomain (p4468007-ipxg23001hodogaya.kanagawa.ocn.ne.jp. [153.204.200.7]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7c6b61d5045sm9922076a12.38.2024.08.20.15.59.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Aug 2024 15:59:18 -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 v6 6/6] net: phy: add Applied Micro QT2025 PHY driver Date: Tue, 20 Aug 2024 22:57:19 +0000 Message-ID: <20240820225719.91410-7-fujita.tomonori@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240820225719.91410-1-fujita.tomonori@gmail.com> References: <20240820225719.91410-1-fujita.tomonori@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org This driver supports Applied Micro Circuits Corporation QT2025 PHY, based on a driver for Tehuti Networks TN40xx chips. The original driver for TN40xx chips supports multiple PHY hardware (AMCC QT2025, TI TLK10232, Aqrate AQR105, and Marvell 88X3120, 88X3310, and MV88E2010). This driver is extracted from the original driver and modified to a PHY driver in Rust. This has been tested with Edimax EN-9320SFP+ 10G network adapter. Signed-off-by: FUJITA Tomonori --- MAINTAINERS | 7 +++ drivers/net/phy/Kconfig | 7 +++ drivers/net/phy/Makefile | 1 + drivers/net/phy/qt2025.rs | 98 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 113 insertions(+) create mode 100644 drivers/net/phy/qt2025.rs diff --git a/MAINTAINERS b/MAINTAINERS index 9dbfcf77acb2..d4464e59dfea 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1609,6 +1609,13 @@ F: Documentation/admin-guide/perf/xgene-pmu.rst F: Documentation/devicetree/bindings/perf/apm-xgene-pmu.txt F: drivers/perf/xgene_pmu.c +APPLIED MICRO QT2025 PHY DRIVER +M: FUJITA Tomonori +L: netdev@vger.kernel.org +L: rust-for-linux@vger.kernel.org +S: Maintained +F: drivers/net/phy/qt2025.rs + APTINA CAMERA SENSOR PLL M: Laurent Pinchart L: linux-media@vger.kernel.org diff --git a/drivers/net/phy/Kconfig b/drivers/net/phy/Kconfig index f530fcd092fe..01b235b3bb7e 100644 --- a/drivers/net/phy/Kconfig +++ b/drivers/net/phy/Kconfig @@ -112,6 +112,13 @@ config ADIN1100_PHY Currently supports the: - ADIN1100 - Robust,Industrial, Low Power 10BASE-T1L Ethernet PHY +config AMCC_QT2025_PHY + tristate "AMCC QT2025 PHY" + depends on RUST_PHYLIB_ABSTRACTIONS + depends on RUST_FW_LOADER_ABSTRACTIONS + help + Adds support for the Applied Micro Circuits Corporation QT2025 PHY. + source "drivers/net/phy/aquantia/Kconfig" config AX88796B_PHY diff --git a/drivers/net/phy/Makefile b/drivers/net/phy/Makefile index f086a606a87e..669d71959be4 100644 --- a/drivers/net/phy/Makefile +++ b/drivers/net/phy/Makefile @@ -37,6 +37,7 @@ obj-$(CONFIG_ADIN_PHY) += adin.o obj-$(CONFIG_ADIN1100_PHY) += adin1100.o obj-$(CONFIG_AIR_EN8811H_PHY) += air_en8811h.o obj-$(CONFIG_AMD_PHY) += amd.o +obj-$(CONFIG_AMCC_QT2025_PHY) += qt2025.o obj-$(CONFIG_AQUANTIA_PHY) += aquantia/ ifdef CONFIG_AX88796B_RUST_PHY obj-$(CONFIG_AX88796B_PHY) += ax88796b_rust.o diff --git a/drivers/net/phy/qt2025.rs b/drivers/net/phy/qt2025.rs new file mode 100644 index 000000000000..a1505ffca9f5 --- /dev/null +++ b/drivers/net/phy/qt2025.rs @@ -0,0 +1,98 @@ +// SPDX-License-Identifier: GPL-2.0 +// Copyright (C) Tehuti Networks Ltd. +// Copyright (C) 2024 FUJITA Tomonori + +//! Applied Micro Circuits Corporation QT2025 PHY driver +//! +//! This driver is based on the vendor driver `QT2025_phy.c`. This source +//! and firmware can be downloaded on the EN-9320SFP+ support site. +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_8K}; + +kernel::module_phy_driver! { + drivers: [PhyQT2025], + device_table: [ + DeviceId::new_with_driver::(), + ], + name: "qt2025_phy", + author: "FUJITA Tomonori ", + description: "AMCC QT2025 PHY driver", + license: "GPL", + firmware: ["qt2025-2.0.3.3.fw"], +} + +struct PhyQT2025; + +#[vtable] +impl Driver for PhyQT2025 { + const NAME: &'static CStr = c_str!("QT2025 10Gpbs SFP+"); + const PHY_DEVICE_ID: phy::DeviceId = phy::DeviceId::new_with_exact_mask(0x0043A400); + + fn probe(dev: &mut phy::Device) -> Result<()> { + // The vendor driver does the following checking but we have no idea why. + let hw_id = dev.read(C45::new(Mmd::PMAPMD, 0xd001))?; + if (hw_id >> 8) & 0xff != 0xb3 { + return Err(code::ENODEV); + } + + // The Intel 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)?; + // The following writes use standardized registers (3.38 through + // 3.41 5/10/25GBASE-R PCS test pattern seed B) for something else. + // We don't know what. + 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 dst_offset = 0; + let mut dst_mmd = Mmd::PCS; + for (src_idx, val) in fw.data().iter().enumerate() { + if src_idx == SZ_16K { + // Start writing to the next register with no offset + dst_offset = 0; + dst_mmd = Mmd::PHYXS; + } + + dev.write(C45::new(dst_mmd, 0x8000 + dst_offset), (*val).into())?; + + dst_offset += 1; + } + // The Intel 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::() + } +}