1 /* SPDX-License-Identifier: GPL-2.0-only 2 * 3 * Copyright (C) 2020-2021 Intel Corporation. 4 */ 5 6 #ifndef _IOSM_IPC_DEVLINK_H_ 7 #define _IOSM_IPC_DEVLINK_H_ 8 9 #include <net/devlink.h> 10 11 #include "iosm_ipc_imem.h" 12 #include "iosm_ipc_imem_ops.h" 13 #include "iosm_ipc_pcie.h" 14 15 /* MAX file name length */ 16 #define IOSM_MAX_FILENAME_LEN 32 17 /* EBL response size */ 18 #define IOSM_EBL_RSP_SIZE 76 19 /* MAX number of regions supported */ 20 #define IOSM_NOF_CD_REGION 6 21 /* MAX number of SNAPSHOTS supported */ 22 #define MAX_SNAPSHOTS 1 23 /* Default Coredump file size */ 24 #define REPORT_JSON_SIZE 0x800 25 #define COREDUMP_FCD_SIZE 0x10E00000 26 #define CDD_LOG_SIZE 0x30000 27 #define EEPROM_BIN_SIZE 0x10000 28 #define BOOTCORE_TRC_BIN_SIZE 0x8000 29 #define BOOTCORE_PREV_TRC_BIN_SIZE 0x20000 30 31 /** 32 * enum iosm_devlink_param_id - Enum type to different devlink params 33 * @IOSM_DEVLINK_PARAM_ID_BASE: Devlink param base ID 34 * @IOSM_DEVLINK_PARAM_ID_ERASE_FULL_FLASH: Set if full erase required 35 * @IOSM_DEVLINK_PARAM_ID_DOWNLOAD_REGION: Set if fls file to be 36 * flashed is Loadmap/region file 37 * @IOSM_DEVLINK_PARAM_ID_ADDRESS: Address of the region to be 38 * flashed 39 * @IOSM_DEVLINK_PARAM_ID_REGION_COUNT: Max region count 40 */ 41 42 enum iosm_devlink_param_id { 43 IOSM_DEVLINK_PARAM_ID_BASE = DEVLINK_PARAM_GENERIC_ID_MAX, 44 IOSM_DEVLINK_PARAM_ID_ERASE_FULL_FLASH, 45 IOSM_DEVLINK_PARAM_ID_DOWNLOAD_REGION, 46 IOSM_DEVLINK_PARAM_ID_ADDRESS, 47 IOSM_DEVLINK_PARAM_ID_REGION_COUNT, 48 }; 49 50 /** 51 * enum iosm_rpsi_cmd_code - Enum type for RPSI command list 52 * @rpsi_cmd_code_ebl: Command to load ebl 53 * @rpsi_cmd_coredump_start: Command to get list of files and 54 * file size info from PSI 55 * @rpsi_cmd_coredump_get: Command to get the coredump data 56 * @rpsi_cmd_coredump_end: Command to stop receiving the coredump 57 */ 58 enum iosm_rpsi_cmd_code { 59 rpsi_cmd_code_ebl = 0x02, 60 rpsi_cmd_coredump_start = 0x10, 61 rpsi_cmd_coredump_get = 0x11, 62 rpsi_cmd_coredump_end = 0x12, 63 }; 64 65 /** 66 * enum iosm_flash_comp_type - Enum for different flash component types 67 * @FLASH_COMP_TYPE_PSI: PSI flash comp type 68 * @FLASH_COMP_TYPE_EBL: EBL flash comp type 69 * @FLASH_COMP_TYPE_FLS: FLS flash comp type 70 * @FLASH_COMP_TYPE_INVAL: Invalid flash comp type 71 */ 72 enum iosm_flash_comp_type { 73 FLASH_COMP_TYPE_PSI, 74 FLASH_COMP_TYPE_EBL, 75 FLASH_COMP_TYPE_FLS, 76 FLASH_COMP_TYPE_INVAL, 77 }; 78 79 /** 80 * struct iosm_devlink_sio - SIO instance 81 * @rx_list: Downlink skbuf list received from CP 82 * @read_sem: Needed for the blocking read or downlink transfer 83 * @channel_id: Reserved channel id for flashing/CD collection to RAM 84 * @channel: Channel instance for flashing and coredump 85 * @devlink_read_pend: Check if read is pending 86 */ 87 struct iosm_devlink_sio { 88 struct sk_buff_head rx_list; 89 struct completion read_sem; 90 int channel_id; 91 struct ipc_mem_channel *channel; 92 u32 devlink_read_pend; 93 }; 94 95 /** 96 * struct iosm_flash_params - List of flash params required for flashing 97 * @address: Address of the region file to be flashed 98 * @region_count: Maximum no of regions for each fls file 99 * @download_region: To be set if region is being flashed 100 * @erase_full_flash: To set the flashing mode 101 * erase_full_flash = 1; full erase 102 * erase_full_flash = 0; no erase 103 * @erase_full_flash_done: Flag to check if it is a full erase 104 */ 105 struct iosm_flash_params { 106 u32 address; 107 u8 region_count; 108 u8 download_region; 109 u8 erase_full_flash; 110 u8 erase_full_flash_done; 111 }; 112 113 /** 114 * struct iosm_ebl_ctx_data - EBL ctx data used during flashing 115 * @ebl_sw_info_version: SWID version info obtained from EBL 116 * @m_ebl_resp: Buffer used to read and write the ebl data 117 */ 118 struct iosm_ebl_ctx_data { 119 u8 ebl_sw_info_version; 120 u8 m_ebl_resp[IOSM_EBL_RSP_SIZE]; 121 }; 122 123 /** 124 * struct iosm_coredump_file_info - Coredump file info 125 * @filename: Name of coredump file 126 * @default_size: Default size of coredump file 127 * @actual_size: Actual size of coredump file 128 * @entry: Index of the coredump file 129 */ 130 struct iosm_coredump_file_info { 131 char filename[IOSM_MAX_FILENAME_LEN]; 132 u32 default_size; 133 u32 actual_size; 134 u32 entry; 135 }; 136 137 /** 138 * struct iosm_devlink - IOSM Devlink structure 139 * @devlink_sio: SIO instance for read/write functionality 140 * @pcie: Pointer to PCIe component 141 * @dev: Pointer to device struct 142 * @devlink_ctx: Pointer to devlink context 143 * @param: Params required for flashing 144 * @ebl_ctx: Data to be read and written to Modem 145 * @cd_file_info: coredump file info 146 * @iosm_devlink_mdm_coredump: region ops for coredump collection 147 * @cd_regions: coredump regions 148 */ 149 struct iosm_devlink { 150 struct iosm_devlink_sio devlink_sio; 151 struct iosm_pcie *pcie; 152 struct device *dev; 153 struct devlink *devlink_ctx; 154 struct iosm_flash_params param; 155 struct iosm_ebl_ctx_data ebl_ctx; 156 struct iosm_coredump_file_info *cd_file_info; 157 struct devlink_region_ops iosm_devlink_mdm_coredump[IOSM_NOF_CD_REGION]; 158 struct devlink_region *cd_regions[IOSM_NOF_CD_REGION]; 159 }; 160 161 /** 162 * union iosm_rpsi_param_u - RPSI cmd param for CRC calculation 163 * @word: Words member used in CRC calculation 164 * @dword: Actual data 165 */ 166 union iosm_rpsi_param_u { 167 __le16 word[2]; 168 __le32 dword; 169 }; 170 171 /** 172 * struct iosm_rpsi_cmd - Structure for RPSI Command 173 * @param: Used to calculate CRC 174 * @cmd: Stores the RPSI command 175 * @crc: Stores the CRC value 176 */ 177 struct iosm_rpsi_cmd { 178 union iosm_rpsi_param_u param; 179 __le16 cmd; 180 __le16 crc; 181 }; 182 183 struct iosm_devlink *ipc_devlink_init(struct iosm_imem *ipc_imem); 184 185 void ipc_devlink_deinit(struct iosm_devlink *ipc_devlink); 186 187 int ipc_devlink_send_cmd(struct iosm_devlink *ipc_devlink, u16 cmd, u32 entry); 188 189 #endif /* _IOSM_IPC_DEVLINK_H */ 190