iosm_ipc_devlink.h 6.0 KB

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