Matt Johnston | 8c2bfb1 | 2024-11-07 15:31:32 +0800 | [diff] [blame] | 1 | /* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later */ |
| 2 | #pragma once |
| 3 | |
| 4 | #include <stdint.h> |
| 5 | #include <stdbool.h> |
| 6 | #include <string.h> |
| 7 | |
| 8 | #include <libpldm/pldm.h> |
| 9 | #include <libpldm/firmware_update.h> |
| 10 | #include <libpldm/firmware_fd.h> |
| 11 | #include <libpldm/utils.h> |
| 12 | |
| 13 | typedef uint64_t pldm_fd_time_t; |
| 14 | |
| 15 | struct pldm_fd_req { |
| 16 | enum pldm_fd_req_state { |
| 17 | // pldm_fd_req instance is unused |
| 18 | PLDM_FD_REQ_UNUSED = 0, |
| 19 | // Ready to send a request |
| 20 | PLDM_FD_REQ_READY, |
| 21 | // Waiting for a response |
| 22 | PLDM_FD_REQ_SENT, |
| 23 | // Completed and failed, will not send more requests. |
| 24 | // Waiting for a cancel from the UA. |
| 25 | PLDM_FD_REQ_FAILED, |
| 26 | } state; |
| 27 | |
| 28 | /* Set once when ready to move to next state, will return |
| 29 | * this result for TransferComplete/VerifyComplete/ApplyComplete request. */ |
| 30 | bool complete; |
| 31 | /* Only valid when complete is set */ |
| 32 | uint8_t result; |
| 33 | |
| 34 | /* Only valid in SENT state */ |
| 35 | uint8_t instance_id; |
| 36 | uint8_t command; |
| 37 | pldm_fd_time_t sent_time; |
| 38 | }; |
| 39 | |
| 40 | struct pldm_fd_download { |
| 41 | uint32_t offset; |
| 42 | }; |
| 43 | |
| 44 | struct pldm_fd_verify { |
| 45 | uint8_t progress_percent; |
| 46 | }; |
| 47 | |
| 48 | struct pldm_fd_apply { |
| 49 | uint8_t progress_percent; |
| 50 | }; |
| 51 | |
| 52 | struct pldm_fd { |
| 53 | enum pldm_firmware_device_states state; |
| 54 | enum pldm_firmware_device_states prev_state; |
| 55 | |
| 56 | /* Reason for last transition to idle state, |
| 57 | * only valid when state == PLDM_FD_STATE_IDLE */ |
| 58 | enum pldm_get_status_reason_code_values reason; |
| 59 | |
| 60 | /* State-specific content */ |
| 61 | union { |
| 62 | struct pldm_fd_download download; |
| 63 | struct pldm_fd_verify verify; |
| 64 | struct pldm_fd_apply apply; |
| 65 | } specific; |
| 66 | /* Details of the component currently being updated. |
| 67 | * Set by UpdateComponent, available during download/verify/apply. |
| 68 | * Also used as temporary storage for PassComponentTable */ |
| 69 | struct pldm_firmware_update_component update_comp; |
| 70 | bitfield32_t update_flags; |
| 71 | |
| 72 | /* Used for download/verify/apply requests */ |
| 73 | struct pldm_fd_req req; |
| 74 | |
| 75 | /* Address of the UA */ |
| 76 | pldm_tid_t ua_address; |
| 77 | bool ua_address_set; |
| 78 | |
| 79 | /* Maximum size allowed by the UA or platform implementation */ |
| 80 | uint32_t max_transfer; |
| 81 | |
| 82 | /* Timestamp for FD T1 timeout, milliseconds */ |
| 83 | pldm_fd_time_t update_timestamp_fd_t1; |
| 84 | |
| 85 | pldm_fd_time_t fd_t1_timeout; |
| 86 | pldm_fd_time_t fd_t2_retry_time; |
| 87 | |
| 88 | const struct pldm_fd_ops *ops; |
| 89 | void *ops_ctx; |
| 90 | }; |