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