zfcp_dbf.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  1. /*
  2. * zfcp device driver
  3. * debug feature declarations
  4. *
  5. * Copyright IBM Corp. 2008, 2017
  6. */
  7. #ifndef ZFCP_DBF_H
  8. #define ZFCP_DBF_H
  9. #include <scsi/fc/fc_fcp.h>
  10. #include "zfcp_ext.h"
  11. #include "zfcp_fsf.h"
  12. #include "zfcp_def.h"
  13. #define ZFCP_DBF_TAG_LEN 7
  14. #define ZFCP_DBF_INVALID_LUN 0xFFFFFFFFFFFFFFFFull
  15. enum zfcp_dbf_pseudo_erp_act_type {
  16. ZFCP_PSEUDO_ERP_ACTION_RPORT_ADD = 0xff,
  17. ZFCP_PSEUDO_ERP_ACTION_RPORT_DEL = 0xfe,
  18. };
  19. /**
  20. * struct zfcp_dbf_rec_trigger - trace record for triggered recovery action
  21. * @ready: number of ready recovery actions
  22. * @running: number of running recovery actions
  23. * @want: wanted recovery action
  24. * @need: needed recovery action
  25. */
  26. struct zfcp_dbf_rec_trigger {
  27. u32 ready;
  28. u32 running;
  29. u8 want;
  30. u8 need;
  31. } __packed;
  32. /**
  33. * struct zfcp_dbf_rec_running - trace record for running recovery
  34. * @fsf_req_id: request id for fsf requests
  35. * @rec_status: status of the fsf request
  36. * @rec_step: current step of the recovery action
  37. * rec_count: recovery counter
  38. */
  39. struct zfcp_dbf_rec_running {
  40. u64 fsf_req_id;
  41. u32 rec_status;
  42. u16 rec_step;
  43. u8 rec_action;
  44. u8 rec_count;
  45. } __packed;
  46. /**
  47. * enum zfcp_dbf_rec_id - recovery trace record id
  48. * @ZFCP_DBF_REC_TRIG: triggered recovery identifier
  49. * @ZFCP_DBF_REC_RUN: running recovery identifier
  50. */
  51. enum zfcp_dbf_rec_id {
  52. ZFCP_DBF_REC_TRIG = 1,
  53. ZFCP_DBF_REC_RUN = 2,
  54. };
  55. /**
  56. * struct zfcp_dbf_rec - trace record for error recovery actions
  57. * @id: unique number of recovery record type
  58. * @tag: identifier string specifying the location of initiation
  59. * @lun: logical unit number
  60. * @wwpn: word wide port number
  61. * @d_id: destination ID
  62. * @adapter_status: current status of the adapter
  63. * @port_status: current status of the port
  64. * @lun_status: current status of the lun
  65. * @u.trig: structure zfcp_dbf_rec_trigger
  66. * @u.run: structure zfcp_dbf_rec_running
  67. */
  68. struct zfcp_dbf_rec {
  69. u8 id;
  70. char tag[ZFCP_DBF_TAG_LEN];
  71. u64 lun;
  72. u64 wwpn;
  73. u32 d_id;
  74. u32 adapter_status;
  75. u32 port_status;
  76. u32 lun_status;
  77. union {
  78. struct zfcp_dbf_rec_trigger trig;
  79. struct zfcp_dbf_rec_running run;
  80. } u;
  81. } __packed;
  82. /**
  83. * enum zfcp_dbf_san_id - SAN trace record identifier
  84. * @ZFCP_DBF_SAN_REQ: request trace record id
  85. * @ZFCP_DBF_SAN_RES: response trace record id
  86. * @ZFCP_DBF_SAN_ELS: extended link service record id
  87. */
  88. enum zfcp_dbf_san_id {
  89. ZFCP_DBF_SAN_REQ = 1,
  90. ZFCP_DBF_SAN_RES = 2,
  91. ZFCP_DBF_SAN_ELS = 3,
  92. };
  93. /** struct zfcp_dbf_san - trace record for SAN requests and responses
  94. * @id: unique number of recovery record type
  95. * @tag: identifier string specifying the location of initiation
  96. * @fsf_req_id: request id for fsf requests
  97. * @payload: unformatted information related to request/response
  98. * @d_id: destination id
  99. */
  100. struct zfcp_dbf_san {
  101. u8 id;
  102. char tag[ZFCP_DBF_TAG_LEN];
  103. u64 fsf_req_id;
  104. u32 d_id;
  105. #define ZFCP_DBF_SAN_MAX_PAYLOAD (FC_CT_HDR_LEN + 32)
  106. char payload[ZFCP_DBF_SAN_MAX_PAYLOAD];
  107. u16 pl_len;
  108. } __packed;
  109. /**
  110. * struct zfcp_dbf_hba_res - trace record for hba responses
  111. * @req_issued: timestamp when request was issued
  112. * @prot_status: protocol status
  113. * @prot_status_qual: protocol status qualifier
  114. * @fsf_status: fsf status
  115. * @fsf_status_qual: fsf status qualifier
  116. */
  117. struct zfcp_dbf_hba_res {
  118. u64 req_issued;
  119. u32 prot_status;
  120. u8 prot_status_qual[FSF_PROT_STATUS_QUAL_SIZE];
  121. u32 fsf_status;
  122. u8 fsf_status_qual[FSF_STATUS_QUALIFIER_SIZE];
  123. u32 port_handle;
  124. u32 lun_handle;
  125. } __packed;
  126. /**
  127. * struct zfcp_dbf_hba_uss - trace record for unsolicited status
  128. * @status_type: type of unsolicited status
  129. * @status_subtype: subtype of unsolicited status
  130. * @d_id: destination ID
  131. * @lun: logical unit number
  132. * @queue_designator: queue designator
  133. */
  134. struct zfcp_dbf_hba_uss {
  135. u32 status_type;
  136. u32 status_subtype;
  137. u32 d_id;
  138. u64 lun;
  139. u64 queue_designator;
  140. } __packed;
  141. /**
  142. * enum zfcp_dbf_hba_id - HBA trace record identifier
  143. * @ZFCP_DBF_HBA_RES: response trace record
  144. * @ZFCP_DBF_HBA_USS: unsolicited status trace record
  145. * @ZFCP_DBF_HBA_BIT: bit error trace record
  146. */
  147. enum zfcp_dbf_hba_id {
  148. ZFCP_DBF_HBA_RES = 1,
  149. ZFCP_DBF_HBA_USS = 2,
  150. ZFCP_DBF_HBA_BIT = 3,
  151. ZFCP_DBF_HBA_BASIC = 4,
  152. };
  153. /**
  154. * struct zfcp_dbf_hba - common trace record for HBA records
  155. * @id: unique number of recovery record type
  156. * @tag: identifier string specifying the location of initiation
  157. * @fsf_req_id: request id for fsf requests
  158. * @fsf_req_status: status of fsf request
  159. * @fsf_cmd: fsf command
  160. * @fsf_seq_no: fsf sequence number
  161. * @pl_len: length of payload stored as zfcp_dbf_pay
  162. * @u: record type specific data
  163. */
  164. struct zfcp_dbf_hba {
  165. u8 id;
  166. char tag[ZFCP_DBF_TAG_LEN];
  167. u64 fsf_req_id;
  168. u32 fsf_req_status;
  169. u32 fsf_cmd;
  170. u32 fsf_seq_no;
  171. u16 pl_len;
  172. union {
  173. struct zfcp_dbf_hba_res res;
  174. struct zfcp_dbf_hba_uss uss;
  175. struct fsf_bit_error_payload be;
  176. } u;
  177. } __packed;
  178. /**
  179. * enum zfcp_dbf_scsi_id - scsi trace record identifier
  180. * @ZFCP_DBF_SCSI_CMND: scsi command trace record
  181. */
  182. enum zfcp_dbf_scsi_id {
  183. ZFCP_DBF_SCSI_CMND = 1,
  184. };
  185. /**
  186. * struct zfcp_dbf_scsi - common trace record for SCSI records
  187. * @id: unique number of recovery record type
  188. * @tag: identifier string specifying the location of initiation
  189. * @scsi_id: scsi device id
  190. * @scsi_lun: scsi device logical unit number, low part of 64 bit, old 32 bit
  191. * @scsi_result: scsi result
  192. * @scsi_retries: current retry number of scsi request
  193. * @scsi_allowed: allowed retries
  194. * @fcp_rsp_info: FCP response info
  195. * @scsi_opcode: scsi opcode
  196. * @fsf_req_id: request id of fsf request
  197. * @host_scribble: LLD specific data attached to SCSI request
  198. * @pl_len: length of paload stored as zfcp_dbf_pay
  199. * @fsf_rsp: response for fsf request
  200. * @scsi_lun_64_hi: scsi device logical unit number, high part of 64 bit
  201. */
  202. struct zfcp_dbf_scsi {
  203. u8 id;
  204. char tag[ZFCP_DBF_TAG_LEN];
  205. u32 scsi_id;
  206. u32 scsi_lun;
  207. u32 scsi_result;
  208. u8 scsi_retries;
  209. u8 scsi_allowed;
  210. u8 fcp_rsp_info;
  211. #define ZFCP_DBF_SCSI_OPCODE 16
  212. u8 scsi_opcode[ZFCP_DBF_SCSI_OPCODE];
  213. u64 fsf_req_id;
  214. u64 host_scribble;
  215. u16 pl_len;
  216. struct fcp_resp_with_ext fcp_rsp;
  217. u32 scsi_lun_64_hi;
  218. } __packed;
  219. /**
  220. * struct zfcp_dbf_pay - trace record for unformatted payload information
  221. * @area: area this record is originated from
  222. * @counter: ascending record number
  223. * @fsf_req_id: request id of fsf request
  224. * @data: unformatted data
  225. */
  226. struct zfcp_dbf_pay {
  227. u8 counter;
  228. char area[ZFCP_DBF_TAG_LEN];
  229. u64 fsf_req_id;
  230. #define ZFCP_DBF_PAY_MAX_REC 0x100
  231. char data[ZFCP_DBF_PAY_MAX_REC];
  232. } __packed;
  233. /**
  234. * struct zfcp_dbf - main dbf trace structure
  235. * @pay: reference to payload trace area
  236. * @rec: reference to recovery trace area
  237. * @hba: reference to hba trace area
  238. * @san: reference to san trace area
  239. * @scsi: reference to scsi trace area
  240. * @pay_lock: lock protecting payload trace buffer
  241. * @rec_lock: lock protecting recovery trace buffer
  242. * @hba_lock: lock protecting hba trace buffer
  243. * @san_lock: lock protecting san trace buffer
  244. * @scsi_lock: lock protecting scsi trace buffer
  245. * @pay_buf: pre-allocated buffer for payload
  246. * @rec_buf: pre-allocated buffer for recovery
  247. * @hba_buf: pre-allocated buffer for hba
  248. * @san_buf: pre-allocated buffer for san
  249. * @scsi_buf: pre-allocated buffer for scsi
  250. */
  251. struct zfcp_dbf {
  252. debug_info_t *pay;
  253. debug_info_t *rec;
  254. debug_info_t *hba;
  255. debug_info_t *san;
  256. debug_info_t *scsi;
  257. spinlock_t pay_lock;
  258. spinlock_t rec_lock;
  259. spinlock_t hba_lock;
  260. spinlock_t san_lock;
  261. spinlock_t scsi_lock;
  262. struct zfcp_dbf_pay pay_buf;
  263. struct zfcp_dbf_rec rec_buf;
  264. struct zfcp_dbf_hba hba_buf;
  265. struct zfcp_dbf_san san_buf;
  266. struct zfcp_dbf_scsi scsi_buf;
  267. };
  268. /**
  269. * zfcp_dbf_hba_fsf_resp_suppress - true if we should not trace by default
  270. * @req: request that has been completed
  271. *
  272. * Returns true if FCP response with only benign residual under count.
  273. */
  274. static inline
  275. bool zfcp_dbf_hba_fsf_resp_suppress(struct zfcp_fsf_req *req)
  276. {
  277. struct fsf_qtcb *qtcb = req->qtcb;
  278. u32 fsf_stat = qtcb->header.fsf_status;
  279. struct fcp_resp *fcp_rsp;
  280. u8 rsp_flags, fr_status;
  281. if (qtcb->prefix.qtcb_type != FSF_IO_COMMAND)
  282. return false; /* not an FCP response */
  283. fcp_rsp = (struct fcp_resp *)&qtcb->bottom.io.fcp_rsp;
  284. rsp_flags = fcp_rsp->fr_flags;
  285. fr_status = fcp_rsp->fr_status;
  286. return (fsf_stat == FSF_FCP_RSP_AVAILABLE) &&
  287. (rsp_flags == FCP_RESID_UNDER) &&
  288. (fr_status == SAM_STAT_GOOD);
  289. }
  290. static inline
  291. void zfcp_dbf_hba_fsf_resp(char *tag, int level, struct zfcp_fsf_req *req)
  292. {
  293. if (debug_level_enabled(req->adapter->dbf->hba, level))
  294. zfcp_dbf_hba_fsf_res(tag, level, req);
  295. }
  296. /**
  297. * zfcp_dbf_hba_fsf_response - trace event for request completion
  298. * @req: request that has been completed
  299. */
  300. static inline
  301. void zfcp_dbf_hba_fsf_response(struct zfcp_fsf_req *req)
  302. {
  303. struct fsf_qtcb *qtcb = req->qtcb;
  304. if (unlikely(req->status & (ZFCP_STATUS_FSFREQ_DISMISSED |
  305. ZFCP_STATUS_FSFREQ_ERROR))) {
  306. zfcp_dbf_hba_fsf_resp("fs_rerr", 3, req);
  307. } else if ((qtcb->prefix.prot_status != FSF_PROT_GOOD) &&
  308. (qtcb->prefix.prot_status != FSF_PROT_FSF_STATUS_PRESENTED)) {
  309. zfcp_dbf_hba_fsf_resp("fs_perr", 1, req);
  310. } else if (qtcb->header.fsf_status != FSF_GOOD) {
  311. zfcp_dbf_hba_fsf_resp("fs_ferr",
  312. zfcp_dbf_hba_fsf_resp_suppress(req)
  313. ? 5 : 1, req);
  314. } else if ((req->fsf_command == FSF_QTCB_OPEN_PORT_WITH_DID) ||
  315. (req->fsf_command == FSF_QTCB_OPEN_LUN)) {
  316. zfcp_dbf_hba_fsf_resp("fs_open", 4, req);
  317. } else if (qtcb->header.log_length) {
  318. zfcp_dbf_hba_fsf_resp("fs_qtcb", 5, req);
  319. } else {
  320. zfcp_dbf_hba_fsf_resp("fs_norm", 6, req);
  321. }
  322. }
  323. static inline
  324. void _zfcp_dbf_scsi(char *tag, int level, struct scsi_cmnd *scmd,
  325. struct zfcp_fsf_req *req)
  326. {
  327. struct zfcp_adapter *adapter = (struct zfcp_adapter *)
  328. scmd->device->host->hostdata[0];
  329. if (debug_level_enabled(adapter->dbf->scsi, level))
  330. zfcp_dbf_scsi(tag, level, scmd, req);
  331. }
  332. /**
  333. * zfcp_dbf_scsi_result - trace event for SCSI command completion
  334. * @scmd: SCSI command pointer
  335. * @req: FSF request used to issue SCSI command
  336. */
  337. static inline
  338. void zfcp_dbf_scsi_result(struct scsi_cmnd *scmd, struct zfcp_fsf_req *req)
  339. {
  340. if (scmd->result != 0)
  341. _zfcp_dbf_scsi("rsl_err", 3, scmd, req);
  342. else if (scmd->retries > 0)
  343. _zfcp_dbf_scsi("rsl_ret", 4, scmd, req);
  344. else
  345. _zfcp_dbf_scsi("rsl_nor", 6, scmd, req);
  346. }
  347. /**
  348. * zfcp_dbf_scsi_fail_send - trace event for failure to send SCSI command
  349. * @scmd: SCSI command pointer
  350. */
  351. static inline
  352. void zfcp_dbf_scsi_fail_send(struct scsi_cmnd *scmd)
  353. {
  354. _zfcp_dbf_scsi("rsl_fai", 4, scmd, NULL);
  355. }
  356. /**
  357. * zfcp_dbf_scsi_abort - trace event for SCSI command abort
  358. * @tag: tag indicating success or failure of abort operation
  359. * @scmd: SCSI command to be aborted
  360. * @fsf_req: request containing abort (might be NULL)
  361. */
  362. static inline
  363. void zfcp_dbf_scsi_abort(char *tag, struct scsi_cmnd *scmd,
  364. struct zfcp_fsf_req *fsf_req)
  365. {
  366. _zfcp_dbf_scsi(tag, 1, scmd, fsf_req);
  367. }
  368. /**
  369. * zfcp_dbf_scsi_devreset - trace event for Logical Unit or Target Reset
  370. * @tag: tag indicating success or failure of reset operation
  371. * @scmnd: SCSI command which caused this error recovery
  372. * @flag: indicates type of reset (Target Reset, Logical Unit Reset)
  373. */
  374. static inline
  375. void zfcp_dbf_scsi_devreset(char *tag, struct scsi_cmnd *scmnd, u8 flag,
  376. struct zfcp_fsf_req *fsf_req)
  377. {
  378. char tmp_tag[ZFCP_DBF_TAG_LEN];
  379. if (flag == FCP_TMF_TGT_RESET)
  380. memcpy(tmp_tag, "tr_", 3);
  381. else
  382. memcpy(tmp_tag, "lr_", 3);
  383. memcpy(&tmp_tag[3], tag, 4);
  384. _zfcp_dbf_scsi(tmp_tag, 1, scmnd, fsf_req);
  385. }
  386. /**
  387. * zfcp_dbf_scsi_nullcmnd() - trace NULLify of SCSI command in dev/tgt-reset.
  388. * @scmnd: SCSI command that was NULLified.
  389. * @fsf_req: request that owned @scmnd.
  390. */
  391. static inline void zfcp_dbf_scsi_nullcmnd(struct scsi_cmnd *scmnd,
  392. struct zfcp_fsf_req *fsf_req)
  393. {
  394. _zfcp_dbf_scsi("scfc__1", 3, scmnd, fsf_req);
  395. }
  396. #endif /* ZFCP_DBF_H */