zfcp_dbf.h 8.7 KB

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