Skip to main content

nv_redfish/oem/nvidia/bluefield/
nvidia_computer_system.rs

1// SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2// SPDX-License-Identifier: Apache-2.0
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16//! Support NVIDIA Bluefield ComputerSystem OEM extension.
17
18use crate::oem::nvidia::bluefield::schema::redfish::nvidia_computer_system::NvidiaComputerSystem as NvidiaComputerSystemSchema;
19use crate::schema::redfish::resource::Oem as ResourceOemSchema;
20use crate::Error;
21use crate::NvBmc;
22use nv_redfish_core::Bmc;
23use nv_redfish_core::NavProperty;
24use serde::Deserialize;
25use std::marker::PhantomData;
26use std::sync::Arc;
27use tagged_types::TaggedType;
28
29#[derive(Deserialize)]
30struct Oem {
31    #[serde(rename = "Nvidia")]
32    nvidia: Option<NavProperty<NvidiaComputerSystemSchema>>,
33}
34
35#[doc(inline)]
36pub use crate::oem::nvidia::bluefield::schema::redfish::nvidia_computer_system::Mode;
37
38/// Base MAC address of the Bluefield DPU as reported by the device.
39pub type BaseMac<T> = TaggedType<T, BaseMacTag>;
40#[doc(hidden)]
41#[derive(tagged_types::Tag)]
42#[implement(Clone, Hash, PartialEq, Eq, PartialOrd, Ord)]
43#[transparent(Debug, Display, FromStr, Serialize, Deserialize)]
44#[capability(inner_access, cloned)]
45pub enum BaseMacTag {}
46
47/// Represents a NVIDIA extension of computer system in the BMC.
48///
49/// Provides access to system information and sub-resources such as processors.
50pub struct NvidiaComputerSystem<B: Bmc> {
51    data: Arc<NvidiaComputerSystemSchema>,
52    _marker: PhantomData<B>,
53}
54
55impl<B: Bmc> NvidiaComputerSystem<B> {
56    /// Create a new computer system handle.
57    pub(crate) async fn new(
58        bmc: &NvBmc<B>,
59        oem: &ResourceOemSchema,
60    ) -> Result<Option<Self>, Error<B>> {
61        let oem: Oem =
62            serde_json::from_value(oem.additional_properties.clone()).map_err(Error::Json)?;
63        if let Some(p) = oem.nvidia {
64            p.get(bmc.as_ref()).await.map_err(Error::Bmc).map(|data| {
65                Some(Self {
66                    data,
67                    _marker: PhantomData,
68                })
69            })
70        } else {
71            Ok(None)
72        }
73    }
74
75    /// Get the raw schema data for this NVIDIA computer system.
76    ///
77    /// Returns an `Arc` to the underlying schema, allowing cheap cloning
78    /// and sharing of the data.
79    #[must_use]
80    pub fn raw(&self) -> Arc<NvidiaComputerSystemSchema> {
81        self.data.clone()
82    }
83
84    /// Get base MAC address of the device.
85    #[must_use]
86    pub fn base_mac(&self) -> Option<BaseMac<&str>> {
87        self.data.base_mac.as_deref().map(BaseMac::new)
88    }
89
90    /// Get mode of the Bluefield device.
91    ///
92    /// Getting mode from directly from OEM extension is supported
93    /// only by Bluefield 3.
94    #[must_use]
95    pub fn mode(&self) -> Option<Mode> {
96        self.data.mode
97    }
98}