ufs-sec-sysfs.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Samsung Specific feature : sysfs-nodes
  4. *
  5. * Copyright (C) 2023 Samsung Electronics Co., Ltd.
  6. *
  7. * Authors:
  8. * Storage Driver <[email protected]>
  9. */
  10. #ifndef __UFS_SEC_SYSFS_H__
  11. #define __UFS_SEC_SYSFS_H__
  12. #include "ufs-sec-feature.h"
  13. #include <linux/sec_class.h>
  14. #include <linux/sec_debug.h>
  15. void ufs_sec_add_sysfs_nodes(struct ufs_hba *hba);
  16. void ufs_sec_remove_sysfs_nodes(struct ufs_hba *hba);
  17. extern struct ufs_sec_feature_info ufs_sec_features;
  18. /* SEC error info : begin */
  19. /* UFSHCD UIC layer error flags : in ufshcd.c */
  20. enum {
  21. UFSHCD_UIC_DL_PA_INIT_ERROR = (1 << 0), /* Data link layer error */
  22. UFSHCD_UIC_DL_NAC_RECEIVED_ERROR = (1 << 1), /* Data link layer error */
  23. UFSHCD_UIC_DL_TCx_REPLAY_ERROR = (1 << 2), /* Data link layer error */
  24. UFSHCD_UIC_NL_ERROR = (1 << 3), /* Network layer error */
  25. UFSHCD_UIC_TL_ERROR = (1 << 4), /* Transport Layer error */
  26. UFSHCD_UIC_DME_ERROR = (1 << 5), /* DME error */
  27. UFSHCD_UIC_PA_GENERIC_ERROR = (1 << 6), /* Generic PA error */
  28. };
  29. struct SEC_UFS_op_cnt {
  30. unsigned int HW_RESET_cnt;
  31. unsigned int link_startup_cnt;
  32. unsigned int Hibern8_enter_cnt;
  33. unsigned int Hibern8_exit_cnt;
  34. unsigned int AH8_err_cnt;
  35. unsigned int op_err;
  36. };
  37. struct SEC_UFS_UIC_cmd_cnt {
  38. u8 DME_GET_err;
  39. u8 DME_SET_err;
  40. u8 DME_PEER_GET_err;
  41. u8 DME_PEER_SET_err;
  42. u8 DME_POWERON_err;
  43. u8 DME_POWEROFF_err;
  44. u8 DME_ENABLE_err;
  45. u8 DME_RESET_err;
  46. u8 DME_END_PT_RST_err;
  47. u8 DME_LINK_STARTUP_err;
  48. u8 DME_HIBER_ENTER_err;
  49. u8 DME_HIBER_EXIT_err;
  50. u8 DME_TEST_MODE_err;
  51. unsigned int UIC_cmd_err;
  52. };
  53. struct SEC_UFS_UIC_err_cnt {
  54. u8 PAERR_cnt;
  55. u8 DL_PA_INIT_ERR_cnt;
  56. u8 DL_NAC_RCVD_ERR_cnt;
  57. u8 DL_TC_REPLAY_ERR_cnt;
  58. u8 DL_FC_PROTECT_ERR_cnt;
  59. u8 NLERR_cnt;
  60. u8 TLERR_cnt;
  61. u8 DMEERR_cnt;
  62. unsigned int DLERR_cnt;
  63. unsigned int UIC_err;
  64. unsigned int PAERR_linereset;
  65. unsigned int PAERR_lane[3];
  66. };
  67. struct SEC_UFS_Fatal_err_cnt {
  68. u8 DFE; // Device_Fatal
  69. u8 CFE; // Controller_Fatal
  70. u8 SBFE; // System_Bus_Fatal
  71. u8 CEFE; // Crypto_Engine_Fatal
  72. u8 LLE; // Link Lost
  73. unsigned int Fatal_err;
  74. };
  75. struct SEC_UFS_UTP_cnt {
  76. u8 UTMR_query_task_cnt;
  77. u8 UTMR_abort_task_cnt;
  78. u8 UTMR_logical_reset_cnt;
  79. u8 UTR_read_err;
  80. u8 UTR_write_err;
  81. u8 UTR_sync_cache_err;
  82. u8 UTR_unmap_err;
  83. u8 UTR_etc_err;
  84. unsigned int UTP_err;
  85. };
  86. struct SEC_UFS_QUERY_cnt {
  87. u8 NOP_err;
  88. u8 R_Desc_err;
  89. u8 W_Desc_err;
  90. u8 R_Attr_err;
  91. u8 W_Attr_err;
  92. u8 R_Flag_err;
  93. u8 Set_Flag_err;
  94. u8 Clear_Flag_err;
  95. u8 Toggle_Flag_err;
  96. unsigned int Query_err;
  97. };
  98. struct SEC_SCSI_SENSE_cnt {
  99. unsigned int scsi_medium_err;
  100. unsigned int scsi_hw_err;
  101. };
  102. struct ufs_sec_err_info {
  103. struct SEC_UFS_op_cnt op_cnt;
  104. struct SEC_UFS_UIC_cmd_cnt UIC_cmd_cnt;
  105. struct SEC_UFS_UIC_err_cnt UIC_err_cnt;
  106. struct SEC_UFS_Fatal_err_cnt Fatal_err_cnt;
  107. struct SEC_UFS_UTP_cnt UTP_cnt;
  108. struct SEC_UFS_QUERY_cnt Query_cnt;
  109. struct SEC_SCSI_SENSE_cnt sense_cnt;
  110. };
  111. #define get_err_member(member) ufs_sec_features.ufs_err->member
  112. #define get_err_backup_member(member) ufs_sec_features.ufs_err_backup->member
  113. #define get_err_hist_member(member) ufs_sec_features.ufs_err_hist->member
  114. #define get_vdi_member(member) ufs_sec_features.vdi->member
  115. #define SEC_UFS_ERR_INFO_BACKUP(err_cnt, member) ({ \
  116. get_err_backup_member(err_cnt).member += get_err_member(err_cnt).member; \
  117. get_err_member(err_cnt).member = 0; })
  118. /* Get the sum of error count about current booting */
  119. #define SEC_UFS_ERR_INFO_GET_VALUE(err_cnt, member) \
  120. (get_err_backup_member(err_cnt).member + get_err_member(err_cnt).member)
  121. /* Get the sum of error count about current and previous booting */
  122. #define SEC_UFS_ERR_INFO_HIST_SUM_GET_VALUE(err_cnt, member) \
  123. (SEC_UFS_ERR_INFO_GET_VALUE(err_cnt, member) + get_err_hist_member(err_cnt).member)
  124. #define SEC_UFS_ERR_INFO_HIST_SET_VALUE(err_cnt, member, value) \
  125. (get_err_hist_member(err_cnt).member = (value - '0'))
  126. #define SEC_UFS_DATA_ATTR_RO(name, fmt, args...) \
  127. static ssize_t name##_show(struct device *dev, struct device_attribute *attr, char *buf) \
  128. { \
  129. return sprintf(buf, fmt, args); \
  130. } \
  131. static DEVICE_ATTR_RO(name)
  132. /* store function has to be defined */
  133. #define SEC_UFS_DATA_ATTR_RW(name, fmt, args...) \
  134. static ssize_t name##_show(struct device *dev, struct device_attribute *attr, char *buf) \
  135. { \
  136. return sprintf(buf, fmt, args); \
  137. } \
  138. static DEVICE_ATTR(name, 0664, name##_show, name##_store)
  139. #define SEC_UFS_ERR_CNT_INC(count, max) ((count) += ((count) < (max)) ? 1 : 0)
  140. #define SEC_UFS_OP_ERR_CNT_INC(member, max) ({ \
  141. struct SEC_UFS_op_cnt *op_cnt = &get_err_member(op_cnt); \
  142. \
  143. SEC_UFS_ERR_CNT_INC(op_cnt->member, max); \
  144. SEC_UFS_ERR_CNT_INC(op_cnt->op_err, UINT_MAX); \
  145. })
  146. #define SEC_UFS_ERR_CNT_ADD(count, value, max) \
  147. ((count) += (count < max) ? (((count + value) < (max)) ? value : (max - count)) : 0)
  148. #define get_min_errinfo(type, min_val, err_cnt, member) \
  149. min_t(type, min_val, SEC_UFS_ERR_INFO_GET_VALUE(err_cnt, member))
  150. #define get_min_errinfo_hist(type, min_val, err_cnt, member) \
  151. min_t(type, min_val, SEC_UFS_ERR_INFO_HIST_SUM_GET_VALUE(err_cnt, member))
  152. #define ERR_SUM_SIZE 25
  153. #define ERR_HIST_SUM_SIZE 26
  154. /**
  155. * UFS Error Information
  156. *
  157. * Format : U0I0H0L0X0Q0R0W0F0SM0SH0
  158. * U : UTP cmd error count
  159. * I : UIC error count
  160. * H : HWRESET count
  161. * L : Link startup failure count
  162. * X : Link Lost Error count
  163. * Q : UTMR QUERY_TASK error count
  164. * R : READ error count
  165. * W : WRITE error count
  166. * F : Device Fatal Error count
  167. * SM : Sense Medium error count
  168. * SH : Sense Hardware error count
  169. **/
  170. #define SEC_UFS_ERR_SUM(buf) \
  171. sprintf(buf, "U%uI%uH%uL%uX%uQ%uR%uW%uF%uSM%uSH%u", \
  172. get_min_errinfo(u32, 9, UTP_cnt, UTP_err), \
  173. get_min_errinfo(u32, 9, UIC_err_cnt, UIC_err), \
  174. get_min_errinfo(u32, 9, op_cnt, HW_RESET_cnt), \
  175. get_min_errinfo(u32, 9, op_cnt, link_startup_cnt), \
  176. get_min_errinfo(u8, 9, Fatal_err_cnt, LLE), \
  177. get_min_errinfo(u8, 9, UTP_cnt, UTMR_query_task_cnt), \
  178. get_min_errinfo(u8, 9, UTP_cnt, UTR_read_err), \
  179. get_min_errinfo(u8, 9, UTP_cnt, UTR_write_err), \
  180. get_min_errinfo(u8, 9, Fatal_err_cnt, DFE), \
  181. get_min_errinfo(u32, 9, sense_cnt, scsi_medium_err), \
  182. get_min_errinfo(u32, 9, sense_cnt, scsi_hw_err))
  183. /**
  184. * UFS Error Information
  185. * previous boot's error count + current boot's error count
  186. **/
  187. #define SEC_UFS_ERR_HIST_SUM(buf) \
  188. sprintf(buf, "U%uI%uH%uL%uX%uQ%uR%uW%uF%uSM%uSH%u\n", \
  189. get_min_errinfo_hist(u32, 9, UTP_cnt, UTP_err), \
  190. get_min_errinfo_hist(u32, 9, UIC_err_cnt, UIC_err), \
  191. get_min_errinfo_hist(u32, 9, op_cnt, HW_RESET_cnt), \
  192. get_min_errinfo_hist(u32, 9, op_cnt, link_startup_cnt), \
  193. get_min_errinfo_hist(u8, 9, Fatal_err_cnt, LLE), \
  194. get_min_errinfo_hist(u8, 9, UTP_cnt, UTMR_query_task_cnt), \
  195. get_min_errinfo_hist(u8, 9, UTP_cnt, UTR_read_err), \
  196. get_min_errinfo_hist(u8, 9, UTP_cnt, UTR_write_err), \
  197. get_min_errinfo_hist(u8, 9, Fatal_err_cnt, DFE), \
  198. get_min_errinfo_hist(u32, 9, sense_cnt, scsi_medium_err), \
  199. get_min_errinfo_hist(u32, 9, sense_cnt, scsi_hw_err))
  200. /* SEC error info : end */
  201. /* SEC next WB : begin */
  202. #define SEC_UFS_WB_INFO_BACKUP(member) ({ \
  203. ufs_sec_features.ufs_wb_backup->member += ufs_sec_features.ufs_wb->member; \
  204. ufs_sec_features.ufs_wb->member = 0; })
  205. /* SEC next WB : end */
  206. #endif