| 1 | |
| 2 | |
| 3 |
|
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 |
|
| 10 | use kernel::{
|
| 11 | bitfield,
|
| 12 | pci::Vendor,
|
| 13 | prelude::*, |
| 14 | };
|
| 15 |
|
| 16 | use crate::{
|
| 17 | bounded_enum,
|
| 18 | num, |
| 19 | };
|
| 20 |
|
| 21 | bounded_enum! {
|
| 22 | |
| 23 | #[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
| 24 | pub(crate) enum NvdmType with TryFrom<Bounded<u32, 8>> {
|
| 25 | |
| 26 | Prc = 0x13,
|
| 27 | |
| 28 | Cot = 0x14,
|
| 29 | |
| 30 | FspResponse = 0x15,
|
| 31 | }
|
| 32 | }
|
| 33 |
|
| 34 | bitfield! {
|
| 35 | |
| 36 | pub(crate) struct MctpHeader(u32) {
|
| 37 | |
| 38 | 31:31 som;
|
| 39 | |
| 40 | 30:30 eom;
|
| 41 | |
| 42 | 29:28 seq;
|
| 43 | |
| 44 | 23:16 seid;
|
| 45 | }
|
| 46 | }
|
| 47 |
|
| 48 | impl MctpHeader {
|
| 49 | |
| 50 | pub(crate) fn single_packet() -> Self {
|
| 51 | Self::zeroed().with_som(true).with_eom(true)
|
| 52 | }
|
| 53 |
|
| 54 | |
| 55 | pub(crate) fn is_single_packet(self) -> bool {
|
| 56 | self.som().into_bool() && self.eom().into_bool()
|
| 57 | }
|
| 58 | }
|
| 59 |
|
| 60 | |
| 61 | const MSG_TYPE_VENDOR_PCI: u8 = 0x7e;
|
| 62 |
|
| 63 | bitfield! {
|
| 64 | |
| 65 | pub(crate) struct NvdmHeader(u32) {
|
| 66 | |
| 67 | 31:24 nvdm_type ?=> NvdmType;
|
| 68 | |
| 69 | 23:8 vendor_id;
|
| 70 | |
| 71 | 6:0 msg_type;
|
| 72 | }
|
| 73 | }
|
| 74 |
|
| 75 | impl NvdmHeader {
|
| 76 | |
| 77 | pub(crate) fn new(nvdm_type: NvdmType) -> Self {
|
| 78 | Self::zeroed()
|
| 79 | .with_const_msg_type::<{ num::u8_as_u32(MSG_TYPE_VENDOR_PCI) }>()
|
| 80 | .with_vendor_id(Vendor::NVIDIA.as_raw())
|
| 81 | .with_nvdm_type(nvdm_type)
|
| 82 | }
|
| 83 |
|
| 84 | |
| 85 | pub(crate) fn validate(self, expected_type: NvdmType) -> bool {
|
| 86 | u8::from(self.msg_type()) == MSG_TYPE_VENDOR_PCI
|
| 87 | && u16::from(self.vendor_id()) == Vendor::NVIDIA.as_raw()
|
| 88 | && matches!(self.nvdm_type(), Ok(nvdm_type) if nvdm_type == expected_type)
|
| 89 | }
|
| 90 | }
|