Harshit Aghera | 560e6af | 2025-04-21 20:04:56 +0530 | [diff] [blame^] | 1 | /* |
| 2 | * SPDX-FileCopyrightText: Copyright (c) 2024-2025 NVIDIA CORPORATION & |
| 3 | * AFFILIATES. All rights reserved. |
| 4 | * SPDX-License-Identifier: Apache-2.0 |
| 5 | */ |
| 6 | |
| 7 | #pragma once |
| 8 | |
| 9 | #include <cstdint> |
| 10 | #include <span> |
| 11 | |
| 12 | namespace ocp |
| 13 | { |
| 14 | namespace accelerator_management |
| 15 | { |
| 16 | |
| 17 | constexpr uint8_t messageType = 0x7E; |
| 18 | |
| 19 | constexpr uint8_t ocpType = 8; |
| 20 | constexpr uint8_t ocpVersion = 9; |
| 21 | constexpr uint8_t ocpTypeBitOffset = 4; |
| 22 | constexpr uint8_t ocpTypeBitMask = 0b11110000; |
| 23 | constexpr uint8_t ocpVersionBitMask = 0b00001111; |
| 24 | constexpr uint8_t instanceIdBitMask = 0b00011111; |
| 25 | constexpr uint8_t instanceIdReservedBitMask = 0b00100000; |
| 26 | constexpr uint8_t datagramBitMask = 0b01000000; |
| 27 | constexpr uint8_t requestBitMask = 0b10000000; |
| 28 | |
| 29 | constexpr uint8_t instanceMin = 0; |
| 30 | constexpr uint8_t instanceMax = 31; |
| 31 | |
| 32 | enum class CompletionCode : uint8_t |
| 33 | { |
| 34 | SUCCESS = 0x00, |
| 35 | ERROR = 0x01, |
| 36 | ERR_INVALID_DATA = 0x02, |
| 37 | ERR_INVALID_DATA_LENGTH = 0x03, |
| 38 | ERR_NOT_READY = 0x04, |
| 39 | ERR_UNSUPPORTED_COMMAND_CODE = 0x05, |
| 40 | ERR_UNSUPPORTED_MSG_TYPE = 0x06, |
| 41 | ERR_BUS_ACCESS = 0x7f, |
| 42 | ERR_NULL = 0x80, |
| 43 | }; |
| 44 | |
| 45 | enum class ReasonCode : uint16_t |
| 46 | { |
| 47 | REASON_NONE = 0x00, |
| 48 | }; |
| 49 | |
| 50 | enum class MessageType : uint8_t |
| 51 | { |
| 52 | RESPONSE = 0, //!< OCP MCTP VDM response message |
| 53 | REQUEST = 2, //!< OCP MCTP VDM request message |
| 54 | }; |
| 55 | |
| 56 | struct BindingPciVid |
| 57 | { |
| 58 | uint16_t pci_vendor_id; //!< PCI defined vendor ID |
| 59 | uint8_t instance_id; //!< Instance ID |
| 60 | uint8_t ocp_version; //!< OCP version |
| 61 | uint8_t ocp_accelerator_management_msg_type; //!< Message Type |
| 62 | } __attribute__((packed)); |
| 63 | |
| 64 | struct Message |
| 65 | { |
| 66 | BindingPciVid hdr; //!< OCP MCTP VDM message header |
| 67 | } __attribute__((packed)); |
| 68 | |
| 69 | struct BindingPciVidInfo |
| 70 | { |
| 71 | uint8_t ocp_accelerator_management_msg_type; |
| 72 | uint8_t instance_id; |
| 73 | uint8_t msg_type; |
| 74 | }; |
| 75 | |
| 76 | struct CommonRequest |
| 77 | { |
| 78 | Message msgHdr; |
| 79 | uint8_t command; |
| 80 | uint8_t data_size; |
| 81 | } __attribute__((packed)); |
| 82 | |
| 83 | struct CommonResponse |
| 84 | { |
| 85 | Message msgHdr; |
| 86 | uint8_t command; |
| 87 | uint8_t completion_code; |
| 88 | uint16_t reserved; |
| 89 | uint16_t data_size; |
| 90 | } __attribute__((packed)); |
| 91 | |
| 92 | struct CommonNonSuccessResponse |
| 93 | { |
| 94 | Message msgHdr; |
| 95 | uint8_t command; |
| 96 | uint8_t completion_code; |
| 97 | uint16_t reason_code; |
| 98 | } __attribute__((packed)); |
| 99 | |
| 100 | int packHeader(uint16_t pciVendorId, const BindingPciVidInfo& hdr, |
| 101 | BindingPciVid& msg); |
| 102 | |
| 103 | int decodeReasonCodeAndCC(std::span<const uint8_t> buf, CompletionCode& cc, |
| 104 | uint16_t& reasonCode); |
| 105 | |
| 106 | } // namespace accelerator_management |
| 107 | } // namespace ocp |