1 /* SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2020-2021 Intel Corporation.
6 #ifndef _IOSM_IPC_DEVLINK_H_
7 #define _IOSM_IPC_DEVLINK_H_
9 #include <net/devlink.h>
11 #include "iosm_ipc_imem.h"
12 #include "iosm_ipc_imem_ops.h"
13 #include "iosm_ipc_pcie.h"
15 /* Image ext max len */
16 #define IOSM_DEVLINK_MAX_IMG_LEN 3
18 #define IOSM_DEVLINK_MAGIC_HEADER "IOSM_DEVLINK_HEADER"
19 /* Magic Header len */
20 #define IOSM_DEVLINK_MAGIC_HEADER_LEN 20
21 /* Devlink image type */
22 #define IOSM_DEVLINK_IMG_TYPE 4
23 /* Reserve header size */
24 #define IOSM_DEVLINK_RESERVED 34
25 /* Devlink Image Header size */
26 #define IOSM_DEVLINK_HDR_SIZE sizeof(struct iosm_devlink_image)
27 /* MAX file name length */
28 #define IOSM_MAX_FILENAME_LEN 32
29 /* EBL response size */
30 #define IOSM_EBL_RSP_SIZE 76
31 /* MAX number of regions supported */
32 #define IOSM_NOF_CD_REGION 6
33 /* MAX number of SNAPSHOTS supported */
34 #define MAX_SNAPSHOTS 1
35 /* Default Coredump file size */
36 #define REPORT_JSON_SIZE 0x800
37 #define COREDUMP_FCD_SIZE 0x10E00000
38 #define CDD_LOG_SIZE 0x30000
39 #define EEPROM_BIN_SIZE 0x10000
40 #define BOOTCORE_TRC_BIN_SIZE 0x8000
41 #define BOOTCORE_PREV_TRC_BIN_SIZE 0x20000
44 * enum iosm_devlink_param_id - Enum type to different devlink params
45 * @IOSM_DEVLINK_PARAM_ID_BASE: Devlink param base ID
46 * @IOSM_DEVLINK_PARAM_ID_ERASE_FULL_FLASH: Set if full erase required
49 enum iosm_devlink_param_id {
50 IOSM_DEVLINK_PARAM_ID_BASE = DEVLINK_PARAM_GENERIC_ID_MAX,
51 IOSM_DEVLINK_PARAM_ID_ERASE_FULL_FLASH,
55 * enum iosm_rpsi_cmd_code - Enum type for RPSI command list
56 * @rpsi_cmd_code_ebl: Command to load ebl
57 * @rpsi_cmd_coredump_start: Command to get list of files and
58 * file size info from PSI
59 * @rpsi_cmd_coredump_get: Command to get the coredump data
60 * @rpsi_cmd_coredump_end: Command to stop receiving the coredump
62 enum iosm_rpsi_cmd_code {
63 rpsi_cmd_code_ebl = 0x02,
64 rpsi_cmd_coredump_start = 0x10,
65 rpsi_cmd_coredump_get = 0x11,
66 rpsi_cmd_coredump_end = 0x12,
70 * enum iosm_flash_comp_type - Enum for different flash component types
71 * @FLASH_COMP_TYPE_PSI: PSI flash comp type
72 * @FLASH_COMP_TYPE_EBL: EBL flash comp type
73 * @FLASH_COMP_TYPE_FLS: FLS flash comp type
74 * @FLASH_COMP_TYPE_INVAL: Invalid flash comp type
76 enum iosm_flash_comp_type {
80 FLASH_COMP_TYPE_INVAL,
84 * struct iosm_devlink_sio - SIO instance
85 * @rx_list: Downlink skbuf list received from CP
86 * @read_sem: Needed for the blocking read or downlink transfer
87 * @channel_id: Reserved channel id for flashing/CD collection to RAM
88 * @channel: Channel instance for flashing and coredump
89 * @devlink_read_pend: Check if read is pending
91 struct iosm_devlink_sio {
92 struct sk_buff_head rx_list;
93 struct completion read_sem;
95 struct ipc_mem_channel *channel;
96 u32 devlink_read_pend;
100 * struct iosm_flash_params - List of flash params required for flashing
101 * @erase_full_flash: To set the flashing mode
102 * erase_full_flash = 1; full erase
103 * erase_full_flash = 0; no erase
104 * @erase_full_flash_done: Flag to check if it is a full erase
106 struct iosm_flash_params {
108 u8 erase_full_flash_done;
112 * struct iosm_devlink_image - Structure with Fls file header info
113 * @magic_header: Header of the firmware image
114 * @image_type: Firmware image type
115 * @region_address: Address of the region to be flashed
116 * @download_region: Field to identify if it is a region
117 * @last_region: Field to identify if it is last region
118 * @reserved: Reserved field
120 struct iosm_devlink_image {
121 char magic_header[IOSM_DEVLINK_MAGIC_HEADER_LEN];
122 char image_type[IOSM_DEVLINK_IMG_TYPE];
123 __le32 region_address;
126 u8 reserved[IOSM_DEVLINK_RESERVED];
130 * struct iosm_ebl_ctx_data - EBL ctx data used during flashing
131 * @ebl_sw_info_version: SWID version info obtained from EBL
132 * @m_ebl_resp: Buffer used to read and write the ebl data
134 struct iosm_ebl_ctx_data {
135 u8 ebl_sw_info_version;
136 u8 m_ebl_resp[IOSM_EBL_RSP_SIZE];
140 * struct iosm_coredump_file_info - Coredump file info
141 * @filename: Name of coredump file
142 * @default_size: Default size of coredump file
143 * @actual_size: Actual size of coredump file
144 * @entry: Index of the coredump file
146 struct iosm_coredump_file_info {
147 char filename[IOSM_MAX_FILENAME_LEN];
154 * struct iosm_devlink - IOSM Devlink structure
155 * @devlink_sio: SIO instance for read/write functionality
156 * @pcie: Pointer to PCIe component
157 * @dev: Pointer to device struct
158 * @devlink_ctx: Pointer to devlink context
159 * @param: Params required for flashing
160 * @ebl_ctx: Data to be read and written to Modem
161 * @cd_file_info: coredump file info
162 * @iosm_devlink_mdm_coredump: region ops for coredump collection
163 * @cd_regions: coredump regions
165 struct iosm_devlink {
166 struct iosm_devlink_sio devlink_sio;
167 struct iosm_pcie *pcie;
169 struct devlink *devlink_ctx;
170 struct iosm_flash_params param;
171 struct iosm_ebl_ctx_data ebl_ctx;
172 struct iosm_coredump_file_info *cd_file_info;
173 struct devlink_region_ops iosm_devlink_mdm_coredump[IOSM_NOF_CD_REGION];
174 struct devlink_region *cd_regions[IOSM_NOF_CD_REGION];
178 * union iosm_rpsi_param_u - RPSI cmd param for CRC calculation
179 * @word: Words member used in CRC calculation
180 * @dword: Actual data
182 union iosm_rpsi_param_u {
188 * struct iosm_rpsi_cmd - Structure for RPSI Command
189 * @param: Used to calculate CRC
190 * @cmd: Stores the RPSI command
191 * @crc: Stores the CRC value
193 struct iosm_rpsi_cmd {
194 union iosm_rpsi_param_u param;
199 struct iosm_devlink *ipc_devlink_init(struct iosm_imem *ipc_imem);
201 void ipc_devlink_deinit(struct iosm_devlink *ipc_devlink);
203 int ipc_devlink_send_cmd(struct iosm_devlink *ipc_devlink, u16 cmd, u32 entry);
205 #endif /* _IOSM_IPC_DEVLINK_H */