zfcp_dbf.h 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  1. /*
  2. * This file is part of the zfcp device driver for
  3. * FCP adapters for IBM System z9 and zSeries.
  4. *
  5. * Copyright IBM Corp. 2008, 2009
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2, or (at your option)
  10. * any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. */
  21. #ifndef ZFCP_DBF_H
  22. #define ZFCP_DBF_H
  23. #include <scsi/fc/fc_fcp.h>
  24. #include "zfcp_ext.h"
  25. #include "zfcp_fsf.h"
  26. #include "zfcp_def.h"
  27. #define ZFCP_DBF_TAG_LEN 7
  28. #define ZFCP_DBF_TAG_SIZE 4
  29. #define ZFCP_DBF_ID_SIZE 7
  30. #define ZFCP_DBF_INVALID_LUN 0xFFFFFFFFFFFFFFFFull
  31. struct zfcp_dbf_dump {
  32. u8 tag[ZFCP_DBF_TAG_SIZE];
  33. u32 total_size; /* size of total dump data */
  34. u32 offset; /* how much data has being already dumped */
  35. u32 size; /* how much data comes with this record */
  36. u8 data[]; /* dump data */
  37. } __attribute__ ((packed));
  38. /**
  39. * struct zfcp_dbf_rec_trigger - trace record for triggered recovery action
  40. * @ready: number of ready recovery actions
  41. * @running: number of running recovery actions
  42. * @want: wanted recovery action
  43. * @need: needed recovery action
  44. */
  45. struct zfcp_dbf_rec_trigger {
  46. u32 ready;
  47. u32 running;
  48. u8 want;
  49. u8 need;
  50. } __packed;
  51. /**
  52. * struct zfcp_dbf_rec_running - trace record for running recovery
  53. * @fsf_req_id: request id for fsf requests
  54. * @rec_status: status of the fsf request
  55. * @rec_step: current step of the recovery action
  56. * rec_count: recovery counter
  57. */
  58. struct zfcp_dbf_rec_running {
  59. u64 fsf_req_id;
  60. u32 rec_status;
  61. u16 rec_step;
  62. u8 rec_action;
  63. u8 rec_count;
  64. } __packed;
  65. /**
  66. * enum zfcp_dbf_rec_id - recovery trace record id
  67. * @ZFCP_DBF_REC_TRIG: triggered recovery identifier
  68. * @ZFCP_DBF_REC_RUN: running recovery identifier
  69. */
  70. enum zfcp_dbf_rec_id {
  71. ZFCP_DBF_REC_TRIG = 1,
  72. ZFCP_DBF_REC_RUN = 2,
  73. };
  74. /**
  75. * struct zfcp_dbf_rec - trace record for error recovery actions
  76. * @id: unique number of recovery record type
  77. * @tag: identifier string specifying the location of initiation
  78. * @lun: logical unit number
  79. * @wwpn: word wide port number
  80. * @d_id: destination ID
  81. * @adapter_status: current status of the adapter
  82. * @port_status: current status of the port
  83. * @lun_status: current status of the lun
  84. * @u.trig: structure zfcp_dbf_rec_trigger
  85. * @u.run: structure zfcp_dbf_rec_running
  86. */
  87. struct zfcp_dbf_rec {
  88. u8 id;
  89. char tag[ZFCP_DBF_TAG_LEN];
  90. u64 lun;
  91. u64 wwpn;
  92. u32 d_id;
  93. u32 adapter_status;
  94. u32 port_status;
  95. u32 lun_status;
  96. union {
  97. struct zfcp_dbf_rec_trigger trig;
  98. struct zfcp_dbf_rec_running run;
  99. } u;
  100. } __packed;
  101. struct zfcp_dbf_hba_record_response {
  102. u32 fsf_command;
  103. u64 fsf_reqid;
  104. u32 fsf_seqno;
  105. u64 fsf_issued;
  106. u32 fsf_prot_status;
  107. u32 fsf_status;
  108. u8 fsf_prot_status_qual[FSF_PROT_STATUS_QUAL_SIZE];
  109. u8 fsf_status_qual[FSF_STATUS_QUALIFIER_SIZE];
  110. u32 fsf_req_status;
  111. u8 sbal_first;
  112. u8 sbal_last;
  113. u8 sbal_response;
  114. u8 pool;
  115. u64 erp_action;
  116. union {
  117. struct {
  118. u64 cmnd;
  119. u32 data_dir;
  120. } fcp;
  121. struct {
  122. u64 wwpn;
  123. u32 d_id;
  124. u32 port_handle;
  125. } port;
  126. struct {
  127. u64 wwpn;
  128. u64 fcp_lun;
  129. u32 port_handle;
  130. u32 lun_handle;
  131. } unit;
  132. struct {
  133. u32 d_id;
  134. } els;
  135. } u;
  136. } __attribute__ ((packed));
  137. struct zfcp_dbf_hba_record_status {
  138. u8 failed;
  139. u32 status_type;
  140. u32 status_subtype;
  141. struct fsf_queue_designator
  142. queue_designator;
  143. u32 payload_size;
  144. #define ZFCP_DBF_UNSOL_PAYLOAD 80
  145. #define ZFCP_DBF_UNSOL_PAYLOAD_SENSE_DATA_AVAIL 32
  146. #define ZFCP_DBF_UNSOL_PAYLOAD_BIT_ERROR_THRESHOLD 56
  147. #define ZFCP_DBF_UNSOL_PAYLOAD_FEATURE_UPDATE_ALERT 2 * sizeof(u32)
  148. u8 payload[ZFCP_DBF_UNSOL_PAYLOAD];
  149. } __attribute__ ((packed));
  150. struct zfcp_dbf_hba_record_qdio {
  151. u32 qdio_error;
  152. u8 sbal_index;
  153. u8 sbal_count;
  154. } __attribute__ ((packed));
  155. struct zfcp_dbf_hba_record {
  156. u8 tag[ZFCP_DBF_TAG_SIZE];
  157. u8 tag2[ZFCP_DBF_TAG_SIZE];
  158. union {
  159. struct zfcp_dbf_hba_record_response response;
  160. struct zfcp_dbf_hba_record_status status;
  161. struct zfcp_dbf_hba_record_qdio qdio;
  162. struct fsf_bit_error_payload berr;
  163. } u;
  164. } __attribute__ ((packed));
  165. struct zfcp_dbf_san_record_ct_request {
  166. u16 cmd_req_code;
  167. u8 revision;
  168. u8 gs_type;
  169. u8 gs_subtype;
  170. u8 options;
  171. u16 max_res_size;
  172. u32 len;
  173. u32 d_id;
  174. } __attribute__ ((packed));
  175. struct zfcp_dbf_san_record_ct_response {
  176. u16 cmd_rsp_code;
  177. u8 revision;
  178. u8 reason_code;
  179. u8 expl;
  180. u8 vendor_unique;
  181. u16 max_res_size;
  182. u32 len;
  183. } __attribute__ ((packed));
  184. struct zfcp_dbf_san_record_els {
  185. u32 d_id;
  186. } __attribute__ ((packed));
  187. struct zfcp_dbf_san_record {
  188. u8 tag[ZFCP_DBF_TAG_SIZE];
  189. u64 fsf_reqid;
  190. u32 fsf_seqno;
  191. union {
  192. struct zfcp_dbf_san_record_ct_request ct_req;
  193. struct zfcp_dbf_san_record_ct_response ct_resp;
  194. struct zfcp_dbf_san_record_els els;
  195. } u;
  196. } __attribute__ ((packed));
  197. #define ZFCP_DBF_SAN_MAX_PAYLOAD 1024
  198. struct zfcp_dbf_scsi_record {
  199. u8 tag[ZFCP_DBF_TAG_SIZE];
  200. u8 tag2[ZFCP_DBF_TAG_SIZE];
  201. u32 scsi_id;
  202. u32 scsi_lun;
  203. u32 scsi_result;
  204. u64 scsi_cmnd;
  205. #define ZFCP_DBF_SCSI_OPCODE 16
  206. u8 scsi_opcode[ZFCP_DBF_SCSI_OPCODE];
  207. u8 scsi_retries;
  208. u8 scsi_allowed;
  209. u64 fsf_reqid;
  210. u32 fsf_seqno;
  211. u64 fsf_issued;
  212. u64 old_fsf_reqid;
  213. u8 rsp_validity;
  214. u8 rsp_scsi_status;
  215. u32 rsp_resid;
  216. u8 rsp_code;
  217. #define ZFCP_DBF_SCSI_FCP_SNS_INFO 16
  218. #define ZFCP_DBF_SCSI_MAX_FCP_SNS_INFO 256
  219. u32 sns_info_len;
  220. u8 sns_info[ZFCP_DBF_SCSI_FCP_SNS_INFO];
  221. } __attribute__ ((packed));
  222. struct zfcp_dbf {
  223. debug_info_t *rec;
  224. debug_info_t *hba;
  225. debug_info_t *san;
  226. debug_info_t *scsi;
  227. spinlock_t rec_lock;
  228. spinlock_t hba_lock;
  229. spinlock_t san_lock;
  230. spinlock_t scsi_lock;
  231. struct zfcp_dbf_rec rec_buf;
  232. struct zfcp_dbf_hba_record hba_buf;
  233. struct zfcp_dbf_san_record san_buf;
  234. struct zfcp_dbf_scsi_record scsi_buf;
  235. struct zfcp_adapter *adapter;
  236. };
  237. static inline
  238. void zfcp_dbf_hba_fsf_resp(const char *tag2, int level,
  239. struct zfcp_fsf_req *req, struct zfcp_dbf *dbf)
  240. {
  241. if (level <= dbf->hba->level)
  242. _zfcp_dbf_hba_fsf_response(tag2, level, req, dbf);
  243. }
  244. /**
  245. * zfcp_dbf_hba_fsf_response - trace event for request completion
  246. * @fsf_req: request that has been completed
  247. */
  248. static inline void zfcp_dbf_hba_fsf_response(struct zfcp_fsf_req *req)
  249. {
  250. struct zfcp_dbf *dbf = req->adapter->dbf;
  251. struct fsf_qtcb *qtcb = req->qtcb;
  252. if ((qtcb->prefix.prot_status != FSF_PROT_GOOD) &&
  253. (qtcb->prefix.prot_status != FSF_PROT_FSF_STATUS_PRESENTED)) {
  254. zfcp_dbf_hba_fsf_resp("perr", 1, req, dbf);
  255. } else if (qtcb->header.fsf_status != FSF_GOOD) {
  256. zfcp_dbf_hba_fsf_resp("ferr", 1, req, dbf);
  257. } else if ((req->fsf_command == FSF_QTCB_OPEN_PORT_WITH_DID) ||
  258. (req->fsf_command == FSF_QTCB_OPEN_LUN)) {
  259. zfcp_dbf_hba_fsf_resp("open", 4, req, dbf);
  260. } else if (qtcb->header.log_length) {
  261. zfcp_dbf_hba_fsf_resp("qtcb", 5, req, dbf);
  262. } else {
  263. zfcp_dbf_hba_fsf_resp("norm", 6, req, dbf);
  264. }
  265. }
  266. /**
  267. * zfcp_dbf_hba_fsf_unsol - trace event for an unsolicited status buffer
  268. * @tag: tag indicating which kind of unsolicited status has been received
  269. * @dbf: reference to dbf structure
  270. * @status_buffer: buffer containing payload of unsolicited status
  271. */
  272. static inline
  273. void zfcp_dbf_hba_fsf_unsol(const char *tag, struct zfcp_dbf *dbf,
  274. struct fsf_status_read_buffer *buf)
  275. {
  276. int level = 2;
  277. if (level <= dbf->hba->level)
  278. _zfcp_dbf_hba_fsf_unsol(tag, level, dbf, buf);
  279. }
  280. static inline
  281. void zfcp_dbf_scsi(const char *tag, const char *tag2, int level,
  282. struct zfcp_dbf *dbf, struct scsi_cmnd *scmd,
  283. struct zfcp_fsf_req *req, unsigned long old_id)
  284. {
  285. if (level <= dbf->scsi->level)
  286. _zfcp_dbf_scsi(tag, tag2, level, dbf, scmd, req, old_id);
  287. }
  288. /**
  289. * zfcp_dbf_scsi_result - trace event for SCSI command completion
  290. * @dbf: adapter dbf trace
  291. * @scmd: SCSI command pointer
  292. * @req: FSF request used to issue SCSI command
  293. */
  294. static inline
  295. void zfcp_dbf_scsi_result(struct zfcp_dbf *dbf, struct scsi_cmnd *scmd,
  296. struct zfcp_fsf_req *req)
  297. {
  298. if (scmd->result != 0)
  299. zfcp_dbf_scsi("rslt", "erro", 3, dbf, scmd, req, 0);
  300. else if (scmd->retries > 0)
  301. zfcp_dbf_scsi("rslt", "retr", 4, dbf, scmd, req, 0);
  302. else
  303. zfcp_dbf_scsi("rslt", "norm", 6, dbf, scmd, req, 0);
  304. }
  305. /**
  306. * zfcp_dbf_scsi_fail_send - trace event for failure to send SCSI command
  307. * @dbf: adapter dbf trace
  308. * @scmd: SCSI command pointer
  309. */
  310. static inline
  311. void zfcp_dbf_scsi_fail_send(struct zfcp_dbf *dbf, struct scsi_cmnd *scmd)
  312. {
  313. zfcp_dbf_scsi("rslt", "fail", 4, dbf, scmd, NULL, 0);
  314. }
  315. /**
  316. * zfcp_dbf_scsi_abort - trace event for SCSI command abort
  317. * @tag: tag indicating success or failure of abort operation
  318. * @adapter: adapter thas has been used to issue SCSI command to be aborted
  319. * @scmd: SCSI command to be aborted
  320. * @new_req: request containing abort (might be NULL)
  321. * @old_id: identifier of request containg SCSI command to be aborted
  322. */
  323. static inline
  324. void zfcp_dbf_scsi_abort(const char *tag, struct zfcp_dbf *dbf,
  325. struct scsi_cmnd *scmd, struct zfcp_fsf_req *new_req,
  326. unsigned long old_id)
  327. {
  328. zfcp_dbf_scsi("abrt", tag, 1, dbf, scmd, new_req, old_id);
  329. }
  330. /**
  331. * zfcp_dbf_scsi_devreset - trace event for Logical Unit or Target Reset
  332. * @tag: tag indicating success or failure of reset operation
  333. * @scmnd: SCSI command which caused this error recovery
  334. * @flag: indicates type of reset (Target Reset, Logical Unit Reset)
  335. */
  336. static inline
  337. void zfcp_dbf_scsi_devreset(const char *tag, struct scsi_cmnd *scmnd, u8 flag)
  338. {
  339. struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(scmnd->device);
  340. zfcp_dbf_scsi(flag == FCP_TMF_TGT_RESET ? "trst" : "lrst", tag, 1,
  341. zfcp_sdev->port->adapter->dbf, scmnd, NULL, 0);
  342. }
  343. #endif /* ZFCP_DBF_H */