blob: 5dc0b414cf28e33ce0c60a280e4a4081e1749f59 [file] [log] [blame]
Christof Schmitt2b604c92008-03-31 11:15:28 +02001/*
Swen Schilliga54ca0f2010-12-02 15:16:14 +01002 * zfcp device driver
3 * debug feature declarations
Christof Schmitt2b604c92008-03-31 11:15:28 +02004 *
Swen Schilliga54ca0f2010-12-02 15:16:14 +01005 * Copyright IBM Corp. 2008, 2010
Christof Schmitt2b604c92008-03-31 11:15:28 +02006 */
7
8#ifndef ZFCP_DBF_H
9#define ZFCP_DBF_H
10
Christof Schmitt4318e082009-11-24 16:54:08 +010011#include <scsi/fc/fc_fcp.h>
Christof Schmittdcd20e22009-08-18 15:43:08 +020012#include "zfcp_ext.h"
Christof Schmitt2b604c92008-03-31 11:15:28 +020013#include "zfcp_fsf.h"
Christof Schmittdcd20e22009-08-18 15:43:08 +020014#include "zfcp_def.h"
Christof Schmitt2b604c92008-03-31 11:15:28 +020015
Swen Schilligae0904f2010-12-02 15:16:12 +010016#define ZFCP_DBF_TAG_LEN 7
Christof Schmitt2b604c92008-03-31 11:15:28 +020017#define ZFCP_DBF_TAG_SIZE 4
Swen Schillig5ffd51a2009-03-02 13:09:04 +010018#define ZFCP_DBF_ID_SIZE 7
Christof Schmitt2b604c92008-03-31 11:15:28 +020019
Christof Schmittd21e9da2010-02-17 11:18:54 +010020#define ZFCP_DBF_INVALID_LUN 0xFFFFFFFFFFFFFFFFull
21
Christof Schmitt2b604c92008-03-31 11:15:28 +020022struct zfcp_dbf_dump {
23 u8 tag[ZFCP_DBF_TAG_SIZE];
24 u32 total_size; /* size of total dump data */
25 u32 offset; /* how much data has being already dumped */
26 u32 size; /* how much data comes with this record */
27 u8 data[]; /* dump data */
28} __attribute__ ((packed));
29
Swen Schilligae0904f2010-12-02 15:16:12 +010030/**
31 * struct zfcp_dbf_rec_trigger - trace record for triggered recovery action
32 * @ready: number of ready recovery actions
33 * @running: number of running recovery actions
34 * @want: wanted recovery action
35 * @need: needed recovery action
36 */
37struct zfcp_dbf_rec_trigger {
Christof Schmitt2b604c92008-03-31 11:15:28 +020038 u32 ready;
39 u32 running;
Christof Schmitt2b604c92008-03-31 11:15:28 +020040 u8 want;
41 u8 need;
Swen Schilligae0904f2010-12-02 15:16:12 +010042} __packed;
43
44/**
45 * struct zfcp_dbf_rec_running - trace record for running recovery
46 * @fsf_req_id: request id for fsf requests
47 * @rec_status: status of the fsf request
48 * @rec_step: current step of the recovery action
49 * rec_count: recovery counter
50 */
51struct zfcp_dbf_rec_running {
52 u64 fsf_req_id;
53 u32 rec_status;
54 u16 rec_step;
55 u8 rec_action;
56 u8 rec_count;
57} __packed;
58
59/**
60 * enum zfcp_dbf_rec_id - recovery trace record id
61 * @ZFCP_DBF_REC_TRIG: triggered recovery identifier
62 * @ZFCP_DBF_REC_RUN: running recovery identifier
63 */
64enum zfcp_dbf_rec_id {
65 ZFCP_DBF_REC_TRIG = 1,
66 ZFCP_DBF_REC_RUN = 2,
Martin Peschke73378912008-05-19 12:17:46 +020067};
Christof Schmitt2b604c92008-03-31 11:15:28 +020068
Swen Schilligae0904f2010-12-02 15:16:12 +010069/**
70 * struct zfcp_dbf_rec - trace record for error recovery actions
71 * @id: unique number of recovery record type
72 * @tag: identifier string specifying the location of initiation
73 * @lun: logical unit number
74 * @wwpn: word wide port number
75 * @d_id: destination ID
76 * @adapter_status: current status of the adapter
77 * @port_status: current status of the port
78 * @lun_status: current status of the lun
79 * @u.trig: structure zfcp_dbf_rec_trigger
80 * @u.run: structure zfcp_dbf_rec_running
81 */
82struct zfcp_dbf_rec {
Christof Schmitt2b604c92008-03-31 11:15:28 +020083 u8 id;
Swen Schilligae0904f2010-12-02 15:16:12 +010084 char tag[ZFCP_DBF_TAG_LEN];
85 u64 lun;
86 u64 wwpn;
87 u32 d_id;
88 u32 adapter_status;
89 u32 port_status;
90 u32 lun_status;
Christof Schmitt2b604c92008-03-31 11:15:28 +020091 union {
Swen Schilligae0904f2010-12-02 15:16:12 +010092 struct zfcp_dbf_rec_trigger trig;
93 struct zfcp_dbf_rec_running run;
Christof Schmitt2b604c92008-03-31 11:15:28 +020094 } u;
Swen Schilligae0904f2010-12-02 15:16:12 +010095} __packed;
Christof Schmitt2b604c92008-03-31 11:15:28 +020096
Swen Schillig2c55b752010-12-02 15:16:13 +010097/**
98 * enum zfcp_dbf_san_id - SAN trace record identifier
99 * @ZFCP_DBF_SAN_REQ: request trace record id
100 * @ZFCP_DBF_SAN_RES: response trace record id
101 * @ZFCP_DBF_SAN_ELS: extended link service record id
102 */
103enum zfcp_dbf_san_id {
104 ZFCP_DBF_SAN_REQ = 1,
105 ZFCP_DBF_SAN_RES = 2,
106 ZFCP_DBF_SAN_ELS = 3,
107};
108
109/** struct zfcp_dbf_san - trace record for SAN requests and responses
110 * @id: unique number of recovery record type
111 * @tag: identifier string specifying the location of initiation
112 * @fsf_req_id: request id for fsf requests
113 * @payload: unformatted information related to request/response
114 * @d_id: destination id
115 */
116struct zfcp_dbf_san {
117 u8 id;
118 char tag[ZFCP_DBF_TAG_LEN];
119 u64 fsf_req_id;
120 u32 d_id;
121#define ZFCP_DBF_SAN_MAX_PAYLOAD (FC_CT_HDR_LEN + 32)
122 char payload[ZFCP_DBF_SAN_MAX_PAYLOAD];
123} __packed;
124
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100125/**
126 * struct zfcp_dbf_hba_res - trace record for hba responses
127 * @req_issued: timestamp when request was issued
128 * @prot_status: protocol status
129 * @prot_status_qual: protocol status qualifier
130 * @fsf_status: fsf status
131 * @fsf_status_qual: fsf status qualifier
132 */
133struct zfcp_dbf_hba_res {
134 u64 req_issued;
135 u32 prot_status;
136 u8 prot_status_qual[FSF_PROT_STATUS_QUAL_SIZE];
Christof Schmitt2b604c92008-03-31 11:15:28 +0200137 u32 fsf_status;
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100138 u8 fsf_status_qual[FSF_STATUS_QUALIFIER_SIZE];
139} __packed;
Christof Schmitt2b604c92008-03-31 11:15:28 +0200140
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100141/**
142 * struct zfcp_dbf_hba_uss - trace record for unsolicited status
143 * @status_type: type of unsolicited status
144 * @status_subtype: subtype of unsolicited status
145 * @d_id: destination ID
146 * @lun: logical unit number
147 * @queue_designator: queue designator
148 */
149struct zfcp_dbf_hba_uss {
Christof Schmitt2b604c92008-03-31 11:15:28 +0200150 u32 status_type;
151 u32 status_subtype;
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100152 u32 d_id;
153 u64 lun;
154 u64 queue_designator;
155} __packed;
Christof Schmitt2b604c92008-03-31 11:15:28 +0200156
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100157/**
158 * enum zfcp_dbf_hba_id - HBA trace record identifier
159 * @ZFCP_DBF_HBA_RES: response trace record
160 * @ZFCP_DBF_HBA_USS: unsolicited status trace record
161 * @ZFCP_DBF_HBA_BIT: bit error trace record
162 */
163enum zfcp_dbf_hba_id {
164 ZFCP_DBF_HBA_RES = 1,
165 ZFCP_DBF_HBA_USS = 2,
166 ZFCP_DBF_HBA_BIT = 3,
167};
Christof Schmitt2b604c92008-03-31 11:15:28 +0200168
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100169/**
170 * struct zfcp_dbf_hba - common trace record for HBA records
171 * @id: unique number of recovery record type
172 * @tag: identifier string specifying the location of initiation
173 * @fsf_req_id: request id for fsf requests
174 * @fsf_req_status: status of fsf request
175 * @fsf_cmd: fsf command
176 * @fsf_seq_no: fsf sequence number
177 * @pl_len: length of payload stored as zfcp_dbf_pay
178 * @u: record type specific data
179 */
180struct zfcp_dbf_hba {
181 u8 id;
182 char tag[ZFCP_DBF_TAG_LEN];
183 u64 fsf_req_id;
184 u32 fsf_req_status;
185 u32 fsf_cmd;
186 u32 fsf_seq_no;
187 u16 pl_len;
Christof Schmitt2b604c92008-03-31 11:15:28 +0200188 union {
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100189 struct zfcp_dbf_hba_res res;
190 struct zfcp_dbf_hba_uss uss;
191 struct fsf_bit_error_payload be;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200192 } u;
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100193} __packed;
194
195/**
196 * struct zfcp_dbf_pay - trace record for unformatted payload information
197 * @area: area this record is originated from
198 * @counter: ascending record number
199 * @fsf_req_id: request id of fsf request
200 * @data: unformatted data
201 */
202struct zfcp_dbf_pay {
203 char area[ZFCP_DBF_TAG_LEN];
204 char counter;
205 u64 fsf_req_id;
206#define ZFCP_DBF_PAY_MAX_REC 0x100
207 char data[ZFCP_DBF_PAY_MAX_REC];
208} __packed;
Christof Schmitt2b604c92008-03-31 11:15:28 +0200209
Swen Schillig57717102009-08-18 15:43:21 +0200210struct zfcp_dbf_scsi_record {
Christof Schmitt2b604c92008-03-31 11:15:28 +0200211 u8 tag[ZFCP_DBF_TAG_SIZE];
212 u8 tag2[ZFCP_DBF_TAG_SIZE];
213 u32 scsi_id;
214 u32 scsi_lun;
215 u32 scsi_result;
216 u64 scsi_cmnd;
Christof Schmitt2b604c92008-03-31 11:15:28 +0200217#define ZFCP_DBF_SCSI_OPCODE 16
218 u8 scsi_opcode[ZFCP_DBF_SCSI_OPCODE];
219 u8 scsi_retries;
220 u8 scsi_allowed;
221 u64 fsf_reqid;
222 u32 fsf_seqno;
223 u64 fsf_issued;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200224 u64 old_fsf_reqid;
225 u8 rsp_validity;
226 u8 rsp_scsi_status;
227 u32 rsp_resid;
228 u8 rsp_code;
Christof Schmitt2b604c92008-03-31 11:15:28 +0200229#define ZFCP_DBF_SCSI_FCP_SNS_INFO 16
230#define ZFCP_DBF_SCSI_MAX_FCP_SNS_INFO 256
Martin Peschke6bc473d2008-03-31 11:15:29 +0200231 u32 sns_info_len;
232 u8 sns_info[ZFCP_DBF_SCSI_FCP_SNS_INFO];
Christof Schmitt2b604c92008-03-31 11:15:28 +0200233} __attribute__ ((packed));
234
Christof Schmittd46f3842009-08-18 15:43:07 +0200235struct zfcp_dbf {
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100236 debug_info_t *pay;
Swen Schillig57717102009-08-18 15:43:21 +0200237 debug_info_t *rec;
238 debug_info_t *hba;
239 debug_info_t *san;
240 debug_info_t *scsi;
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100241 spinlock_t pay_lock;
Swen Schillig57717102009-08-18 15:43:21 +0200242 spinlock_t rec_lock;
243 spinlock_t hba_lock;
244 spinlock_t san_lock;
245 spinlock_t scsi_lock;
Swen Schilligae0904f2010-12-02 15:16:12 +0100246 struct zfcp_dbf_rec rec_buf;
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100247 struct zfcp_dbf_hba hba_buf;
Swen Schillig2c55b752010-12-02 15:16:13 +0100248 struct zfcp_dbf_san san_buf;
Swen Schillig57717102009-08-18 15:43:21 +0200249 struct zfcp_dbf_scsi_record scsi_buf;
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100250 struct zfcp_dbf_pay pay_buf;
Swen Schillig57717102009-08-18 15:43:21 +0200251 struct zfcp_adapter *adapter;
Christof Schmittd46f3842009-08-18 15:43:07 +0200252};
253
Christof Schmittdcd20e22009-08-18 15:43:08 +0200254static inline
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100255void zfcp_dbf_hba_fsf_resp(char *tag, int level, struct zfcp_fsf_req *req)
Christof Schmitt2e261af2009-08-18 15:43:09 +0200256{
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100257 if (level <= req->adapter->dbf->hba->level)
258 zfcp_dbf_hba_fsf_res(tag, req);
Christof Schmitt2e261af2009-08-18 15:43:09 +0200259}
260
261/**
Swen Schillig57717102009-08-18 15:43:21 +0200262 * zfcp_dbf_hba_fsf_response - trace event for request completion
Christof Schmitt2e261af2009-08-18 15:43:09 +0200263 * @fsf_req: request that has been completed
264 */
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100265static inline
266void zfcp_dbf_hba_fsf_response(struct zfcp_fsf_req *req)
Christof Schmitt2e261af2009-08-18 15:43:09 +0200267{
Christof Schmitt2e261af2009-08-18 15:43:09 +0200268 struct fsf_qtcb *qtcb = req->qtcb;
269
270 if ((qtcb->prefix.prot_status != FSF_PROT_GOOD) &&
271 (qtcb->prefix.prot_status != FSF_PROT_FSF_STATUS_PRESENTED)) {
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100272 zfcp_dbf_hba_fsf_resp("fs_perr", 1, req);
Christof Schmitt2e261af2009-08-18 15:43:09 +0200273
274 } else if (qtcb->header.fsf_status != FSF_GOOD) {
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100275 zfcp_dbf_hba_fsf_resp("fs_ferr", 1, req);
Christof Schmitt2e261af2009-08-18 15:43:09 +0200276
277 } else if ((req->fsf_command == FSF_QTCB_OPEN_PORT_WITH_DID) ||
278 (req->fsf_command == FSF_QTCB_OPEN_LUN)) {
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100279 zfcp_dbf_hba_fsf_resp("fs_open", 4, req);
Christof Schmitt2e261af2009-08-18 15:43:09 +0200280
281 } else if (qtcb->header.log_length) {
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100282 zfcp_dbf_hba_fsf_resp("fs_qtcb", 5, req);
Christof Schmitt2e261af2009-08-18 15:43:09 +0200283
284 } else {
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100285 zfcp_dbf_hba_fsf_resp("fs_norm", 6, req);
Christof Schmitt2e261af2009-08-18 15:43:09 +0200286 }
Christof Schmitt2e261af2009-08-18 15:43:09 +0200287}
288
289static inline
Swen Schillig57717102009-08-18 15:43:21 +0200290void zfcp_dbf_scsi(const char *tag, const char *tag2, int level,
291 struct zfcp_dbf *dbf, struct scsi_cmnd *scmd,
292 struct zfcp_fsf_req *req, unsigned long old_id)
Christof Schmittdcd20e22009-08-18 15:43:08 +0200293{
Swen Schillig57717102009-08-18 15:43:21 +0200294 if (level <= dbf->scsi->level)
295 _zfcp_dbf_scsi(tag, tag2, level, dbf, scmd, req, old_id);
Christof Schmittdcd20e22009-08-18 15:43:08 +0200296}
297
298/**
Swen Schillig57717102009-08-18 15:43:21 +0200299 * zfcp_dbf_scsi_result - trace event for SCSI command completion
Christof Schmittab725282010-02-17 11:18:57 +0100300 * @dbf: adapter dbf trace
Christof Schmittdcd20e22009-08-18 15:43:08 +0200301 * @scmd: SCSI command pointer
Christof Schmittab725282010-02-17 11:18:57 +0100302 * @req: FSF request used to issue SCSI command
Christof Schmittdcd20e22009-08-18 15:43:08 +0200303 */
304static inline
Christof Schmittab725282010-02-17 11:18:57 +0100305void zfcp_dbf_scsi_result(struct zfcp_dbf *dbf, struct scsi_cmnd *scmd,
306 struct zfcp_fsf_req *req)
Christof Schmittdcd20e22009-08-18 15:43:08 +0200307{
Christof Schmittab725282010-02-17 11:18:57 +0100308 if (scmd->result != 0)
309 zfcp_dbf_scsi("rslt", "erro", 3, dbf, scmd, req, 0);
310 else if (scmd->retries > 0)
311 zfcp_dbf_scsi("rslt", "retr", 4, dbf, scmd, req, 0);
312 else
313 zfcp_dbf_scsi("rslt", "norm", 6, dbf, scmd, req, 0);
314}
315
316/**
317 * zfcp_dbf_scsi_fail_send - trace event for failure to send SCSI command
318 * @dbf: adapter dbf trace
319 * @scmd: SCSI command pointer
320 */
321static inline
322void zfcp_dbf_scsi_fail_send(struct zfcp_dbf *dbf, struct scsi_cmnd *scmd)
323{
324 zfcp_dbf_scsi("rslt", "fail", 4, dbf, scmd, NULL, 0);
Christof Schmittdcd20e22009-08-18 15:43:08 +0200325}
326
327/**
Swen Schillig57717102009-08-18 15:43:21 +0200328 * zfcp_dbf_scsi_abort - trace event for SCSI command abort
Christof Schmittdcd20e22009-08-18 15:43:08 +0200329 * @tag: tag indicating success or failure of abort operation
330 * @adapter: adapter thas has been used to issue SCSI command to be aborted
331 * @scmd: SCSI command to be aborted
332 * @new_req: request containing abort (might be NULL)
333 * @old_id: identifier of request containg SCSI command to be aborted
334 */
335static inline
Swen Schillig57717102009-08-18 15:43:21 +0200336void zfcp_dbf_scsi_abort(const char *tag, struct zfcp_dbf *dbf,
337 struct scsi_cmnd *scmd, struct zfcp_fsf_req *new_req,
338 unsigned long old_id)
Christof Schmittdcd20e22009-08-18 15:43:08 +0200339{
Swen Schillig57717102009-08-18 15:43:21 +0200340 zfcp_dbf_scsi("abrt", tag, 1, dbf, scmd, new_req, old_id);
Christof Schmittdcd20e22009-08-18 15:43:08 +0200341}
342
343/**
Swen Schillig57717102009-08-18 15:43:21 +0200344 * zfcp_dbf_scsi_devreset - trace event for Logical Unit or Target Reset
Christof Schmittdcd20e22009-08-18 15:43:08 +0200345 * @tag: tag indicating success or failure of reset operation
Christof Schmittb62a8d92010-09-08 14:39:55 +0200346 * @scmnd: SCSI command which caused this error recovery
Christof Schmittdcd20e22009-08-18 15:43:08 +0200347 * @flag: indicates type of reset (Target Reset, Logical Unit Reset)
Christof Schmittdcd20e22009-08-18 15:43:08 +0200348 */
349static inline
Christof Schmittb62a8d92010-09-08 14:39:55 +0200350void zfcp_dbf_scsi_devreset(const char *tag, struct scsi_cmnd *scmnd, u8 flag)
Christof Schmittdcd20e22009-08-18 15:43:08 +0200351{
Christof Schmittb62a8d92010-09-08 14:39:55 +0200352 struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(scmnd->device);
353
Christof Schmitt4318e082009-11-24 16:54:08 +0100354 zfcp_dbf_scsi(flag == FCP_TMF_TGT_RESET ? "trst" : "lrst", tag, 1,
Christof Schmittb62a8d92010-09-08 14:39:55 +0200355 zfcp_sdev->port->adapter->dbf, scmnd, NULL, 0);
Christof Schmittdcd20e22009-08-18 15:43:08 +0200356}
357
Christof Schmitt2b604c92008-03-31 11:15:28 +0200358#endif /* ZFCP_DBF_H */