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(bmc: &NvBmc<B>, oem: &ResourceOemSchema) -> Result<Self, Error<B>> {
58        let oem: Oem =
59            serde_json::from_value(oem.additional_properties.clone()).map_err(Error::Json)?;
60        oem.nvidia
61            .ok_or(Error::NvidiaComputerSystemNotAvailable)?
62            .get(bmc.as_ref())
63            .await
64            .map_err(Error::Bmc)
65            .map(|data| Self {
66                data,
67                _marker: PhantomData,
68            })
69    }
70
71    /// Get the raw schema data for this NVIDIA computer system.
72    ///
73    /// Returns an `Arc` to the underlying schema, allowing cheap cloning
74    /// and sharing of the data.
75    #[must_use]
76    pub fn raw(&self) -> Arc<NvidiaComputerSystemSchema> {
77        self.data.clone()
78    }
79
80    /// Get base MAC address of the device.
81    #[must_use]
82    pub fn base_mac(&self) -> Option<BaseMac<&String>> {
83        self.data.base_mac.as_ref().map(BaseMac::new)
84    }
85
86    /// Get mode of the Bluefield device.
87    ///
88    /// Getting mode from directly from OEM extension is supported
89    /// only by Bluefield 3.
90    #[must_use]
91    pub fn mode(&self) -> Option<Mode> {
92        self.data.mode
93    }
94}