zfcp_dbf.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  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. } els;
  116. } u;
  117. } __attribute__ ((packed));
  118. struct zfcp_dbf_hba_record_status {
  119. u8 failed;
  120. u32 status_type;
  121. u32 status_subtype;
  122. struct fsf_queue_designator
  123. queue_designator;
  124. u32 payload_size;
  125. #define ZFCP_DBF_UNSOL_PAYLOAD 80
  126. #define ZFCP_DBF_UNSOL_PAYLOAD_SENSE_DATA_AVAIL 32
  127. #define ZFCP_DBF_UNSOL_PAYLOAD_BIT_ERROR_THRESHOLD 56
  128. #define ZFCP_DBF_UNSOL_PAYLOAD_FEATURE_UPDATE_ALERT 2 * sizeof(u32)
  129. u8 payload[ZFCP_DBF_UNSOL_PAYLOAD];
  130. } __attribute__ ((packed));
  131. struct zfcp_dbf_hba_record_qdio {
  132. u32 qdio_error;
  133. u8 sbal_index;
  134. u8 sbal_count;
  135. } __attribute__ ((packed));
  136. struct zfcp_dbf_hba_record {
  137. u8 tag[ZFCP_DBF_TAG_SIZE];
  138. u8 tag2[ZFCP_DBF_TAG_SIZE];
  139. union {
  140. struct zfcp_dbf_hba_record_response response;
  141. struct zfcp_dbf_hba_record_status status;
  142. struct zfcp_dbf_hba_record_qdio qdio;
  143. struct fsf_bit_error_payload berr;
  144. } u;
  145. } __attribute__ ((packed));
  146. struct zfcp_dbf_san_record_ct_request {
  147. u16 cmd_req_code;
  148. u8 revision;
  149. u8 gs_type;
  150. u8 gs_subtype;
  151. u8 options;
  152. u16 max_res_size;
  153. u32 len;
  154. u32 d_id;
  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. u32 d_id;
  167. } __attribute__ ((packed));
  168. struct zfcp_dbf_san_record {
  169. u8 tag[ZFCP_DBF_TAG_SIZE];
  170. u64 fsf_reqid;
  171. u32 fsf_seqno;
  172. union {
  173. struct zfcp_dbf_san_record_ct_request ct_req;
  174. struct zfcp_dbf_san_record_ct_response ct_resp;
  175. struct zfcp_dbf_san_record_els els;
  176. } u;
  177. #define ZFCP_DBF_SAN_MAX_PAYLOAD 1024
  178. u8 payload[32];
  179. } __attribute__ ((packed));
  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. * @tag: tag indicating success or failure of SCSI command
  274. * @level: trace level applicable for this event
  275. * @adapter: adapter that has been used to issue the SCSI command
  276. * @scmd: SCSI command pointer
  277. * @fsf_req: request used to issue SCSI command (might be NULL)
  278. */
  279. static inline
  280. void zfcp_dbf_scsi_result(const char *tag, int level, struct zfcp_dbf *dbf,
  281. struct scsi_cmnd *scmd, struct zfcp_fsf_req *fsf_req)
  282. {
  283. zfcp_dbf_scsi("rslt", tag, level, dbf, scmd, fsf_req, 0);
  284. }
  285. /**
  286. * zfcp_dbf_scsi_abort - trace event for SCSI command abort
  287. * @tag: tag indicating success or failure of abort operation
  288. * @adapter: adapter thas has been used to issue SCSI command to be aborted
  289. * @scmd: SCSI command to be aborted
  290. * @new_req: request containing abort (might be NULL)
  291. * @old_id: identifier of request containg SCSI command to be aborted
  292. */
  293. static inline
  294. void zfcp_dbf_scsi_abort(const char *tag, struct zfcp_dbf *dbf,
  295. struct scsi_cmnd *scmd, struct zfcp_fsf_req *new_req,
  296. unsigned long old_id)
  297. {
  298. zfcp_dbf_scsi("abrt", tag, 1, dbf, scmd, new_req, old_id);
  299. }
  300. /**
  301. * zfcp_dbf_scsi_devreset - trace event for Logical Unit or Target Reset
  302. * @tag: tag indicating success or failure of reset operation
  303. * @flag: indicates type of reset (Target Reset, Logical Unit Reset)
  304. * @unit: unit that needs reset
  305. * @scsi_cmnd: SCSI command which caused this error recovery
  306. */
  307. static inline
  308. void zfcp_dbf_scsi_devreset(const char *tag, u8 flag, struct zfcp_unit *unit,
  309. struct scsi_cmnd *scsi_cmnd)
  310. {
  311. zfcp_dbf_scsi(flag == FCP_TMF_TGT_RESET ? "trst" : "lrst", tag, 1,
  312. unit->port->adapter->dbf, scsi_cmnd, NULL, 0);
  313. }
  314. #endif /* ZFCP_DBF_H */