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