zfcp_dbf.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  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_SIZE 4
  28. #define ZFCP_DBF_ID_SIZE 7
  29. #define ZFCP_DBF_INVALID_LUN 0xFFFFFFFFFFFFFFFFull
  30. struct zfcp_dbf_dump {
  31. u8 tag[ZFCP_DBF_TAG_SIZE];
  32. u32 total_size; /* size of total dump data */
  33. u32 offset; /* how much data has being already dumped */
  34. u32 size; /* how much data comes with this record */
  35. u8 data[]; /* dump data */
  36. } __attribute__ ((packed));
  37. struct zfcp_dbf_rec_record_thread {
  38. u32 total;
  39. u32 ready;
  40. u32 running;
  41. };
  42. struct zfcp_dbf_rec_record_target {
  43. u64 ref;
  44. u32 status;
  45. u32 d_id;
  46. u64 wwpn;
  47. u64 fcp_lun;
  48. u32 erp_count;
  49. };
  50. struct zfcp_dbf_rec_record_trigger {
  51. u8 want;
  52. u8 need;
  53. u32 as;
  54. u32 ps;
  55. u32 us;
  56. u64 ref;
  57. u64 action;
  58. u64 wwpn;
  59. u64 fcp_lun;
  60. };
  61. struct zfcp_dbf_rec_record_action {
  62. u32 status;
  63. u32 step;
  64. u64 action;
  65. u64 fsf_req;
  66. };
  67. struct zfcp_dbf_rec_record {
  68. u8 id;
  69. char id2[7];
  70. union {
  71. struct zfcp_dbf_rec_record_action action;
  72. struct zfcp_dbf_rec_record_thread thread;
  73. struct zfcp_dbf_rec_record_target target;
  74. struct zfcp_dbf_rec_record_trigger trigger;
  75. } u;
  76. };
  77. enum {
  78. ZFCP_REC_DBF_ID_ACTION,
  79. ZFCP_REC_DBF_ID_THREAD,
  80. ZFCP_REC_DBF_ID_TARGET,
  81. ZFCP_REC_DBF_ID_TRIGGER,
  82. };
  83. struct zfcp_dbf_hba_record_response {
  84. u32 fsf_command;
  85. u64 fsf_reqid;
  86. u32 fsf_seqno;
  87. u64 fsf_issued;
  88. u32 fsf_prot_status;
  89. u32 fsf_status;
  90. u8 fsf_prot_status_qual[FSF_PROT_STATUS_QUAL_SIZE];
  91. u8 fsf_status_qual[FSF_STATUS_QUALIFIER_SIZE];
  92. u32 fsf_req_status;
  93. u8 sbal_first;
  94. u8 sbal_last;
  95. u8 sbal_response;
  96. u8 pool;
  97. u64 erp_action;
  98. union {
  99. struct {
  100. u64 cmnd;
  101. u64 serial;
  102. } fcp;
  103. struct {
  104. u64 wwpn;
  105. u32 d_id;
  106. u32 port_handle;
  107. } port;
  108. struct {
  109. u64 wwpn;
  110. u64 fcp_lun;
  111. u32 port_handle;
  112. u32 lun_handle;
  113. } unit;
  114. struct {
  115. u32 d_id;
  116. } els;
  117. } u;
  118. } __attribute__ ((packed));
  119. struct zfcp_dbf_hba_record_status {
  120. u8 failed;
  121. u32 status_type;
  122. u32 status_subtype;
  123. struct fsf_queue_designator
  124. queue_designator;
  125. u32 payload_size;
  126. #define ZFCP_DBF_UNSOL_PAYLOAD 80
  127. #define ZFCP_DBF_UNSOL_PAYLOAD_SENSE_DATA_AVAIL 32
  128. #define ZFCP_DBF_UNSOL_PAYLOAD_BIT_ERROR_THRESHOLD 56
  129. #define ZFCP_DBF_UNSOL_PAYLOAD_FEATURE_UPDATE_ALERT 2 * sizeof(u32)
  130. u8 payload[ZFCP_DBF_UNSOL_PAYLOAD];
  131. } __attribute__ ((packed));
  132. struct zfcp_dbf_hba_record_qdio {
  133. u32 qdio_error;
  134. u8 sbal_index;
  135. u8 sbal_count;
  136. } __attribute__ ((packed));
  137. struct zfcp_dbf_hba_record {
  138. u8 tag[ZFCP_DBF_TAG_SIZE];
  139. u8 tag2[ZFCP_DBF_TAG_SIZE];
  140. union {
  141. struct zfcp_dbf_hba_record_response response;
  142. struct zfcp_dbf_hba_record_status status;
  143. struct zfcp_dbf_hba_record_qdio qdio;
  144. struct fsf_bit_error_payload berr;
  145. } u;
  146. } __attribute__ ((packed));
  147. struct zfcp_dbf_san_record_ct_request {
  148. u16 cmd_req_code;
  149. u8 revision;
  150. u8 gs_type;
  151. u8 gs_subtype;
  152. u8 options;
  153. u16 max_res_size;
  154. u32 len;
  155. u32 d_id;
  156. } __attribute__ ((packed));
  157. struct zfcp_dbf_san_record_ct_response {
  158. u16 cmd_rsp_code;
  159. u8 revision;
  160. u8 reason_code;
  161. u8 expl;
  162. u8 vendor_unique;
  163. u16 max_res_size;
  164. u32 len;
  165. } __attribute__ ((packed));
  166. struct zfcp_dbf_san_record_els {
  167. u32 d_id;
  168. } __attribute__ ((packed));
  169. struct zfcp_dbf_san_record {
  170. u8 tag[ZFCP_DBF_TAG_SIZE];
  171. u64 fsf_reqid;
  172. u32 fsf_seqno;
  173. union {
  174. struct zfcp_dbf_san_record_ct_request ct_req;
  175. struct zfcp_dbf_san_record_ct_response ct_resp;
  176. struct zfcp_dbf_san_record_els els;
  177. } u;
  178. } __attribute__ ((packed));
  179. #define ZFCP_DBF_SAN_MAX_PAYLOAD 1024
  180. struct zfcp_dbf_scsi_record {
  181. u8 tag[ZFCP_DBF_TAG_SIZE];
  182. u8 tag2[ZFCP_DBF_TAG_SIZE];
  183. u32 scsi_id;
  184. u32 scsi_lun;
  185. u32 scsi_result;
  186. u64 scsi_cmnd;
  187. u64 scsi_serial;
  188. #define ZFCP_DBF_SCSI_OPCODE 16
  189. u8 scsi_opcode[ZFCP_DBF_SCSI_OPCODE];
  190. u8 scsi_retries;
  191. u8 scsi_allowed;
  192. u64 fsf_reqid;
  193. u32 fsf_seqno;
  194. u64 fsf_issued;
  195. u64 old_fsf_reqid;
  196. u8 rsp_validity;
  197. u8 rsp_scsi_status;
  198. u32 rsp_resid;
  199. u8 rsp_code;
  200. #define ZFCP_DBF_SCSI_FCP_SNS_INFO 16
  201. #define ZFCP_DBF_SCSI_MAX_FCP_SNS_INFO 256
  202. u32 sns_info_len;
  203. u8 sns_info[ZFCP_DBF_SCSI_FCP_SNS_INFO];
  204. } __attribute__ ((packed));
  205. struct zfcp_dbf {
  206. debug_info_t *rec;
  207. debug_info_t *hba;
  208. debug_info_t *san;
  209. debug_info_t *scsi;
  210. spinlock_t rec_lock;
  211. spinlock_t hba_lock;
  212. spinlock_t san_lock;
  213. spinlock_t scsi_lock;
  214. struct zfcp_dbf_rec_record rec_buf;
  215. struct zfcp_dbf_hba_record hba_buf;
  216. struct zfcp_dbf_san_record san_buf;
  217. struct zfcp_dbf_scsi_record scsi_buf;
  218. struct zfcp_adapter *adapter;
  219. };
  220. static inline
  221. void zfcp_dbf_hba_fsf_resp(const char *tag2, int level,
  222. struct zfcp_fsf_req *req, struct zfcp_dbf *dbf)
  223. {
  224. if (level <= dbf->hba->level)
  225. _zfcp_dbf_hba_fsf_response(tag2, level, req, dbf);
  226. }
  227. /**
  228. * zfcp_dbf_hba_fsf_response - trace event for request completion
  229. * @fsf_req: request that has been completed
  230. */
  231. static inline void zfcp_dbf_hba_fsf_response(struct zfcp_fsf_req *req)
  232. {
  233. struct zfcp_dbf *dbf = req->adapter->dbf;
  234. struct fsf_qtcb *qtcb = req->qtcb;
  235. if ((qtcb->prefix.prot_status != FSF_PROT_GOOD) &&
  236. (qtcb->prefix.prot_status != FSF_PROT_FSF_STATUS_PRESENTED)) {
  237. zfcp_dbf_hba_fsf_resp("perr", 1, req, dbf);
  238. } else if (qtcb->header.fsf_status != FSF_GOOD) {
  239. zfcp_dbf_hba_fsf_resp("ferr", 1, req, dbf);
  240. } else if ((req->fsf_command == FSF_QTCB_OPEN_PORT_WITH_DID) ||
  241. (req->fsf_command == FSF_QTCB_OPEN_LUN)) {
  242. zfcp_dbf_hba_fsf_resp("open", 4, req, dbf);
  243. } else if (qtcb->header.log_length) {
  244. zfcp_dbf_hba_fsf_resp("qtcb", 5, req, dbf);
  245. } else {
  246. zfcp_dbf_hba_fsf_resp("norm", 6, req, dbf);
  247. }
  248. }
  249. /**
  250. * zfcp_dbf_hba_fsf_unsol - trace event for an unsolicited status buffer
  251. * @tag: tag indicating which kind of unsolicited status has been received
  252. * @dbf: reference to dbf structure
  253. * @status_buffer: buffer containing payload of unsolicited status
  254. */
  255. static inline
  256. void zfcp_dbf_hba_fsf_unsol(const char *tag, struct zfcp_dbf *dbf,
  257. struct fsf_status_read_buffer *buf)
  258. {
  259. int level = 2;
  260. if (level <= dbf->hba->level)
  261. _zfcp_dbf_hba_fsf_unsol(tag, level, dbf, buf);
  262. }
  263. static inline
  264. void zfcp_dbf_scsi(const char *tag, const char *tag2, int level,
  265. struct zfcp_dbf *dbf, struct scsi_cmnd *scmd,
  266. struct zfcp_fsf_req *req, unsigned long old_id)
  267. {
  268. if (level <= dbf->scsi->level)
  269. _zfcp_dbf_scsi(tag, tag2, level, dbf, scmd, req, old_id);
  270. }
  271. /**
  272. * zfcp_dbf_scsi_result - trace event for SCSI command completion
  273. * @dbf: adapter dbf trace
  274. * @scmd: SCSI command pointer
  275. * @req: FSF request used to issue SCSI command
  276. */
  277. static inline
  278. void zfcp_dbf_scsi_result(struct zfcp_dbf *dbf, struct scsi_cmnd *scmd,
  279. struct zfcp_fsf_req *req)
  280. {
  281. if (scmd->result != 0)
  282. zfcp_dbf_scsi("rslt", "erro", 3, dbf, scmd, req, 0);
  283. else if (scmd->retries > 0)
  284. zfcp_dbf_scsi("rslt", "retr", 4, dbf, scmd, req, 0);
  285. else
  286. zfcp_dbf_scsi("rslt", "norm", 6, dbf, scmd, req, 0);
  287. }
  288. /**
  289. * zfcp_dbf_scsi_fail_send - trace event for failure to send SCSI command
  290. * @dbf: adapter dbf trace
  291. * @scmd: SCSI command pointer
  292. */
  293. static inline
  294. void zfcp_dbf_scsi_fail_send(struct zfcp_dbf *dbf, struct scsi_cmnd *scmd)
  295. {
  296. zfcp_dbf_scsi("rslt", "fail", 4, dbf, scmd, NULL, 0);
  297. }
  298. /**
  299. * zfcp_dbf_scsi_abort - trace event for SCSI command abort
  300. * @tag: tag indicating success or failure of abort operation
  301. * @adapter: adapter thas has been used to issue SCSI command to be aborted
  302. * @scmd: SCSI command to be aborted
  303. * @new_req: request containing abort (might be NULL)
  304. * @old_id: identifier of request containg SCSI command to be aborted
  305. */
  306. static inline
  307. void zfcp_dbf_scsi_abort(const char *tag, struct zfcp_dbf *dbf,
  308. struct scsi_cmnd *scmd, struct zfcp_fsf_req *new_req,
  309. unsigned long old_id)
  310. {
  311. zfcp_dbf_scsi("abrt", tag, 1, dbf, scmd, new_req, old_id);
  312. }
  313. /**
  314. * zfcp_dbf_scsi_devreset - trace event for Logical Unit or Target Reset
  315. * @tag: tag indicating success or failure of reset operation
  316. * @flag: indicates type of reset (Target Reset, Logical Unit Reset)
  317. * @unit: unit that needs reset
  318. * @scsi_cmnd: SCSI command which caused this error recovery
  319. */
  320. static inline
  321. void zfcp_dbf_scsi_devreset(const char *tag, u8 flag, struct zfcp_unit *unit,
  322. struct scsi_cmnd *scsi_cmnd)
  323. {
  324. zfcp_dbf_scsi(flag == FCP_TMF_TGT_RESET ? "trst" : "lrst", tag, 1,
  325. unit->port->adapter->dbf, scsi_cmnd, NULL, 0);
  326. }
  327. #endif /* ZFCP_DBF_H */