zfcp_dbf.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  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. u32 data_dir;
  103. } fcp;
  104. struct {
  105. u64 wwpn;
  106. u32 d_id;
  107. u32 port_handle;
  108. } port;
  109. struct {
  110. u64 wwpn;
  111. u64 fcp_lun;
  112. u32 port_handle;
  113. u32 lun_handle;
  114. } unit;
  115. struct {
  116. u32 d_id;
  117. } els;
  118. } u;
  119. } __attribute__ ((packed));
  120. struct zfcp_dbf_hba_record_status {
  121. u8 failed;
  122. u32 status_type;
  123. u32 status_subtype;
  124. struct fsf_queue_designator
  125. queue_designator;
  126. u32 payload_size;
  127. #define ZFCP_DBF_UNSOL_PAYLOAD 80
  128. #define ZFCP_DBF_UNSOL_PAYLOAD_SENSE_DATA_AVAIL 32
  129. #define ZFCP_DBF_UNSOL_PAYLOAD_BIT_ERROR_THRESHOLD 56
  130. #define ZFCP_DBF_UNSOL_PAYLOAD_FEATURE_UPDATE_ALERT 2 * sizeof(u32)
  131. u8 payload[ZFCP_DBF_UNSOL_PAYLOAD];
  132. } __attribute__ ((packed));
  133. struct zfcp_dbf_hba_record_qdio {
  134. u32 qdio_error;
  135. u8 sbal_index;
  136. u8 sbal_count;
  137. } __attribute__ ((packed));
  138. struct zfcp_dbf_hba_record {
  139. u8 tag[ZFCP_DBF_TAG_SIZE];
  140. u8 tag2[ZFCP_DBF_TAG_SIZE];
  141. union {
  142. struct zfcp_dbf_hba_record_response response;
  143. struct zfcp_dbf_hba_record_status status;
  144. struct zfcp_dbf_hba_record_qdio qdio;
  145. struct fsf_bit_error_payload berr;
  146. } u;
  147. } __attribute__ ((packed));
  148. struct zfcp_dbf_san_record_ct_request {
  149. u16 cmd_req_code;
  150. u8 revision;
  151. u8 gs_type;
  152. u8 gs_subtype;
  153. u8 options;
  154. u16 max_res_size;
  155. u32 len;
  156. u32 d_id;
  157. } __attribute__ ((packed));
  158. struct zfcp_dbf_san_record_ct_response {
  159. u16 cmd_rsp_code;
  160. u8 revision;
  161. u8 reason_code;
  162. u8 expl;
  163. u8 vendor_unique;
  164. u16 max_res_size;
  165. u32 len;
  166. } __attribute__ ((packed));
  167. struct zfcp_dbf_san_record_els {
  168. u32 d_id;
  169. } __attribute__ ((packed));
  170. struct zfcp_dbf_san_record {
  171. u8 tag[ZFCP_DBF_TAG_SIZE];
  172. u64 fsf_reqid;
  173. u32 fsf_seqno;
  174. union {
  175. struct zfcp_dbf_san_record_ct_request ct_req;
  176. struct zfcp_dbf_san_record_ct_response ct_resp;
  177. struct zfcp_dbf_san_record_els els;
  178. } u;
  179. } __attribute__ ((packed));
  180. #define ZFCP_DBF_SAN_MAX_PAYLOAD 1024
  181. struct zfcp_dbf_scsi_record {
  182. u8 tag[ZFCP_DBF_TAG_SIZE];
  183. u8 tag2[ZFCP_DBF_TAG_SIZE];
  184. u32 scsi_id;
  185. u32 scsi_lun;
  186. u32 scsi_result;
  187. u64 scsi_cmnd;
  188. u64 scsi_serial;
  189. #define ZFCP_DBF_SCSI_OPCODE 16
  190. u8 scsi_opcode[ZFCP_DBF_SCSI_OPCODE];
  191. u8 scsi_retries;
  192. u8 scsi_allowed;
  193. u64 fsf_reqid;
  194. u32 fsf_seqno;
  195. u64 fsf_issued;
  196. u64 old_fsf_reqid;
  197. u8 rsp_validity;
  198. u8 rsp_scsi_status;
  199. u32 rsp_resid;
  200. u8 rsp_code;
  201. #define ZFCP_DBF_SCSI_FCP_SNS_INFO 16
  202. #define ZFCP_DBF_SCSI_MAX_FCP_SNS_INFO 256
  203. u32 sns_info_len;
  204. u8 sns_info[ZFCP_DBF_SCSI_FCP_SNS_INFO];
  205. } __attribute__ ((packed));
  206. struct zfcp_dbf {
  207. debug_info_t *rec;
  208. debug_info_t *hba;
  209. debug_info_t *san;
  210. debug_info_t *scsi;
  211. spinlock_t rec_lock;
  212. spinlock_t hba_lock;
  213. spinlock_t san_lock;
  214. spinlock_t scsi_lock;
  215. struct zfcp_dbf_rec_record rec_buf;
  216. struct zfcp_dbf_hba_record hba_buf;
  217. struct zfcp_dbf_san_record san_buf;
  218. struct zfcp_dbf_scsi_record scsi_buf;
  219. struct zfcp_adapter *adapter;
  220. };
  221. static inline
  222. void zfcp_dbf_hba_fsf_resp(const char *tag2, int level,
  223. struct zfcp_fsf_req *req, struct zfcp_dbf *dbf)
  224. {
  225. if (level <= dbf->hba->level)
  226. _zfcp_dbf_hba_fsf_response(tag2, level, req, dbf);
  227. }
  228. /**
  229. * zfcp_dbf_hba_fsf_response - trace event for request completion
  230. * @fsf_req: request that has been completed
  231. */
  232. static inline void zfcp_dbf_hba_fsf_response(struct zfcp_fsf_req *req)
  233. {
  234. struct zfcp_dbf *dbf = req->adapter->dbf;
  235. struct fsf_qtcb *qtcb = req->qtcb;
  236. if ((qtcb->prefix.prot_status != FSF_PROT_GOOD) &&
  237. (qtcb->prefix.prot_status != FSF_PROT_FSF_STATUS_PRESENTED)) {
  238. zfcp_dbf_hba_fsf_resp("perr", 1, req, dbf);
  239. } else if (qtcb->header.fsf_status != FSF_GOOD) {
  240. zfcp_dbf_hba_fsf_resp("ferr", 1, req, dbf);
  241. } else if ((req->fsf_command == FSF_QTCB_OPEN_PORT_WITH_DID) ||
  242. (req->fsf_command == FSF_QTCB_OPEN_LUN)) {
  243. zfcp_dbf_hba_fsf_resp("open", 4, req, dbf);
  244. } else if (qtcb->header.log_length) {
  245. zfcp_dbf_hba_fsf_resp("qtcb", 5, req, dbf);
  246. } else {
  247. zfcp_dbf_hba_fsf_resp("norm", 6, req, dbf);
  248. }
  249. }
  250. /**
  251. * zfcp_dbf_hba_fsf_unsol - trace event for an unsolicited status buffer
  252. * @tag: tag indicating which kind of unsolicited status has been received
  253. * @dbf: reference to dbf structure
  254. * @status_buffer: buffer containing payload of unsolicited status
  255. */
  256. static inline
  257. void zfcp_dbf_hba_fsf_unsol(const char *tag, struct zfcp_dbf *dbf,
  258. struct fsf_status_read_buffer *buf)
  259. {
  260. int level = 2;
  261. if (level <= dbf->hba->level)
  262. _zfcp_dbf_hba_fsf_unsol(tag, level, dbf, buf);
  263. }
  264. static inline
  265. void zfcp_dbf_scsi(const char *tag, const char *tag2, int level,
  266. struct zfcp_dbf *dbf, struct scsi_cmnd *scmd,
  267. struct zfcp_fsf_req *req, unsigned long old_id)
  268. {
  269. if (level <= dbf->scsi->level)
  270. _zfcp_dbf_scsi(tag, tag2, level, dbf, scmd, req, old_id);
  271. }
  272. /**
  273. * zfcp_dbf_scsi_result - trace event for SCSI command completion
  274. * @dbf: adapter dbf trace
  275. * @scmd: SCSI command pointer
  276. * @req: FSF request used to issue SCSI command
  277. */
  278. static inline
  279. void zfcp_dbf_scsi_result(struct zfcp_dbf *dbf, struct scsi_cmnd *scmd,
  280. struct zfcp_fsf_req *req)
  281. {
  282. if (scmd->result != 0)
  283. zfcp_dbf_scsi("rslt", "erro", 3, dbf, scmd, req, 0);
  284. else if (scmd->retries > 0)
  285. zfcp_dbf_scsi("rslt", "retr", 4, dbf, scmd, req, 0);
  286. else
  287. zfcp_dbf_scsi("rslt", "norm", 6, dbf, scmd, req, 0);
  288. }
  289. /**
  290. * zfcp_dbf_scsi_fail_send - trace event for failure to send SCSI command
  291. * @dbf: adapter dbf trace
  292. * @scmd: SCSI command pointer
  293. */
  294. static inline
  295. void zfcp_dbf_scsi_fail_send(struct zfcp_dbf *dbf, struct scsi_cmnd *scmd)
  296. {
  297. zfcp_dbf_scsi("rslt", "fail", 4, dbf, scmd, NULL, 0);
  298. }
  299. /**
  300. * zfcp_dbf_scsi_abort - trace event for SCSI command abort
  301. * @tag: tag indicating success or failure of abort operation
  302. * @adapter: adapter thas has been used to issue SCSI command to be aborted
  303. * @scmd: SCSI command to be aborted
  304. * @new_req: request containing abort (might be NULL)
  305. * @old_id: identifier of request containg SCSI command to be aborted
  306. */
  307. static inline
  308. void zfcp_dbf_scsi_abort(const char *tag, struct zfcp_dbf *dbf,
  309. struct scsi_cmnd *scmd, struct zfcp_fsf_req *new_req,
  310. unsigned long old_id)
  311. {
  312. zfcp_dbf_scsi("abrt", tag, 1, dbf, scmd, new_req, old_id);
  313. }
  314. /**
  315. * zfcp_dbf_scsi_devreset - trace event for Logical Unit or Target Reset
  316. * @tag: tag indicating success or failure of reset operation
  317. * @flag: indicates type of reset (Target Reset, Logical Unit Reset)
  318. * @unit: unit that needs reset
  319. * @scsi_cmnd: SCSI command which caused this error recovery
  320. */
  321. static inline
  322. void zfcp_dbf_scsi_devreset(const char *tag, u8 flag, struct zfcp_unit *unit,
  323. struct scsi_cmnd *scsi_cmnd)
  324. {
  325. zfcp_dbf_scsi(flag == FCP_TMF_TGT_RESET ? "trst" : "lrst", tag, 1,
  326. unit->port->adapter->dbf, scsi_cmnd, NULL, 0);
  327. }
  328. #endif /* ZFCP_DBF_H */