From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8EE3F322C93; Mon, 18 Aug 2025 16:06:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755533208; cv=none; b=niozqpDCejFzGV7iFhgkshWe1SDqCJtSEot8Ca2vq3FkKE9PVt2uX+7bhJHc2sPiUyulhXGLeMQD5SP0vq4kce5X8vjCFRfNJwS09zBOdSkzYPr8864X26GvlIxeDVY7WjdtJfuXvQmOIthK5RTjbMBx4uR7RFzwtvXt+Rmm/rk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755533208; c=relaxed/simple; bh=8v0DGj5nN7LXQV4s3kH37ZEpxqadMxuWtRA9XKaDv9Y=; h=Mime-Version:Content-Type:Date:Message-Id:Subject:Cc:To:From: References:In-Reply-To; b=mKbauO4SyZTHlp4sCByrIhm+FUZV2ttSWKNFYiJ28SnvKii5fEYgetITU+5Svzh2KcBH51T958RPJNhJRNO3bopG8Z5Hv1j6VL5Wdmv0XkQdaHNScSYWDLi8VhQY7DcvNxrTrHFjumjPgPUH/tt1mAIEeQHbLc+QwGiYnlwmsqE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=nLhkO/I5; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="nLhkO/I5" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 06318C4CEEB; Mon, 18 Aug 2025 16:06:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1755533208; bh=8v0DGj5nN7LXQV4s3kH37ZEpxqadMxuWtRA9XKaDv9Y=; h=Date:Subject:Cc:To:From:References:In-Reply-To:From; b=nLhkO/I5LOKz8LcXkJw6s406OXNSXyb2a8ICLRCrn0YxIbTmVUchl9L0VOnJ1hNzm h+UKxqH0PksQediircWskG1IV4nc3tC4Tiq4BRaP9Tvjg0OeTS0o4M4zg5HcNNp5el chwhjTzmvI//dfy5Y1A+B41xCDfte+A6e+4ZXH8JzMTLmI4PeWMWms3UvQsSrt+y36 33dFrnFPfHFZiAHxD5NVSVt+sQCfUjJNcLOo1ChgIuHgJdaqVXo2oXSe3VmZKgbVEw SGqBH9NzwKYyGE/DWsLuRBEqnkmKRvE5bBj4HNMszv9S/0UdGUGbU8TZi/rQQGYQQk DMdojNV4K+e2w== Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Mon, 18 Aug 2025 18:06:42 +0200 Message-Id: Subject: Re: [PATCH v2 3/3] rust: pci: provide access to PCI Vendor values Cc: "Alexandre Courbot" , "Joel Fernandes" , "Timur Tabi" , "Alistair Popple" , "David Airlie" , "Simona Vetter" , "Bjorn Helgaas" , =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , "Miguel Ojeda" , "Alex Gaynor" , "Boqun Feng" , "Gary Guo" , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , "Benno Lossin" , "Andreas Hindborg" , "Alice Ryhl" , "Trevor Gross" , , , , "LKML" To: "John Hubbard" From: "Danilo Krummrich" References: <20250818013305.1089446-1-jhubbard@nvidia.com> <20250818013305.1089446-4-jhubbard@nvidia.com> In-Reply-To: <20250818013305.1089446-4-jhubbard@nvidia.com> On Mon Aug 18, 2025 at 3:33 AM CEST, John Hubbard wrote: > + /// Create a `Vendor` from the raw vendor ID value, or `None= ` if the value doesn't > + /// match any known vendor. > + pub fn from_u32(value: u32) -> Option { > + match value { > + $(x if x =3D=3D Self::$variant.0 =3D> Some(Self::$va= riant),)+ > + _ =3D> None, > + } > + } Same here, I think this should be `impl TryFrom for Vendor`. > + > + /// Get the raw 16-bit vendor ID value. > + pub const fn as_u32(self) -> u32 { > + self.0 > + } > + } > + }; > +} > /// An adapter for the registration of PCI drivers. > pub struct Adapter(T); > =20 > @@ -335,9 +656,9 @@ pub const fn from_class(class: u32, class_mask: u32) = -> Self { > /// > /// This is more targeted than [`DeviceId::from_class`]: in addition= to matching by Vendor, it > /// also matches the PCI Class (up to the entire 24 bits, depending = on the mask). > - pub const fn from_class_and_vendor(class: Class, class_mask: u32, ve= ndor: u32) -> Self { > + pub const fn from_class_and_vendor(class: Class, class_mask: u32, ve= ndor: Vendor) -> Self { > Self(bindings::pci_device_id { > - vendor, > + vendor: vendor.as_u32(), > device: DeviceId::PCI_ANY_ID, > subvendor: DeviceId::PCI_ANY_ID, > subdevice: DeviceId::PCI_ANY_ID, > @@ -396,7 +717,7 @@ macro_rules! pci_device_table { > /// ::IdInfo, > /// [ > /// ( > -/// pci::DeviceId::from_id(bindings::PCI_VENDOR_ID_REDHAT, b= indings::PCI_ANY_ID as u32), > +/// pci::DeviceId::from_id(pci::Vendor::REDHAT.as_u32(), bin= dings::PCI_ANY_ID as u32), We should change DeviceId::from_id() to consume a pci::Vendor value directl= y.