[SCSI] zfcp: Redesign of the debug tracing for HBA records.
[pandora-kernel.git] / drivers / s390 / scsi / zfcp_dbf.h
1 /*
2  * zfcp device driver
3  * debug feature declarations
4  *
5  * Copyright IBM Corp. 2008, 2010
6  */
7
8 #ifndef ZFCP_DBF_H
9 #define ZFCP_DBF_H
10
11 #include <scsi/fc/fc_fcp.h>
12 #include "zfcp_ext.h"
13 #include "zfcp_fsf.h"
14 #include "zfcp_def.h"
15
16 #define ZFCP_DBF_TAG_LEN       7
17 #define ZFCP_DBF_TAG_SIZE      4
18 #define ZFCP_DBF_ID_SIZE       7
19
20 #define ZFCP_DBF_INVALID_LUN    0xFFFFFFFFFFFFFFFFull
21
22 struct 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
30 /**
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  */
37 struct zfcp_dbf_rec_trigger {
38         u32 ready;
39         u32 running;
40         u8 want;
41         u8 need;
42 } __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  */
51 struct 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  */
64 enum zfcp_dbf_rec_id {
65         ZFCP_DBF_REC_TRIG       = 1,
66         ZFCP_DBF_REC_RUN        = 2,
67 };
68
69 /**
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  */
82 struct zfcp_dbf_rec {
83         u8 id;
84         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;
91         union {
92                 struct zfcp_dbf_rec_trigger trig;
93                 struct zfcp_dbf_rec_running run;
94         } u;
95 } __packed;
96
97 /**
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  */
103 enum 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  */
116 struct 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
125 /**
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  */
133 struct zfcp_dbf_hba_res {
134         u64 req_issued;
135         u32 prot_status;
136         u8  prot_status_qual[FSF_PROT_STATUS_QUAL_SIZE];
137         u32 fsf_status;
138         u8  fsf_status_qual[FSF_STATUS_QUALIFIER_SIZE];
139 } __packed;
140
141 /**
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  */
149 struct zfcp_dbf_hba_uss {
150         u32 status_type;
151         u32 status_subtype;
152         u32 d_id;
153         u64 lun;
154         u64 queue_designator;
155 } __packed;
156
157 /**
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  */
163 enum zfcp_dbf_hba_id {
164         ZFCP_DBF_HBA_RES        = 1,
165         ZFCP_DBF_HBA_USS        = 2,
166         ZFCP_DBF_HBA_BIT        = 3,
167 };
168
169 /**
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  */
180 struct 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;
188         union {
189                 struct zfcp_dbf_hba_res res;
190                 struct zfcp_dbf_hba_uss uss;
191                 struct fsf_bit_error_payload be;
192         } u;
193 } __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  */
202 struct 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;
209
210 struct zfcp_dbf_scsi_record {
211         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;
217 #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;
224         u64 old_fsf_reqid;
225         u8 rsp_validity;
226         u8 rsp_scsi_status;
227         u32 rsp_resid;
228         u8 rsp_code;
229 #define ZFCP_DBF_SCSI_FCP_SNS_INFO      16
230 #define ZFCP_DBF_SCSI_MAX_FCP_SNS_INFO  256
231         u32 sns_info_len;
232         u8 sns_info[ZFCP_DBF_SCSI_FCP_SNS_INFO];
233 } __attribute__ ((packed));
234
235 struct zfcp_dbf {
236         debug_info_t                    *pay;
237         debug_info_t                    *rec;
238         debug_info_t                    *hba;
239         debug_info_t                    *san;
240         debug_info_t                    *scsi;
241         spinlock_t                      pay_lock;
242         spinlock_t                      rec_lock;
243         spinlock_t                      hba_lock;
244         spinlock_t                      san_lock;
245         spinlock_t                      scsi_lock;
246         struct zfcp_dbf_rec             rec_buf;
247         struct zfcp_dbf_hba             hba_buf;
248         struct zfcp_dbf_san             san_buf;
249         struct zfcp_dbf_scsi_record     scsi_buf;
250         struct zfcp_dbf_pay             pay_buf;
251         struct zfcp_adapter             *adapter;
252 };
253
254 static inline
255 void zfcp_dbf_hba_fsf_resp(char *tag, int level, struct zfcp_fsf_req *req)
256 {
257         if (level <= req->adapter->dbf->hba->level)
258                 zfcp_dbf_hba_fsf_res(tag, req);
259 }
260
261 /**
262  * zfcp_dbf_hba_fsf_response - trace event for request completion
263  * @fsf_req: request that has been completed
264  */
265 static inline
266 void zfcp_dbf_hba_fsf_response(struct zfcp_fsf_req *req)
267 {
268         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)) {
272                 zfcp_dbf_hba_fsf_resp("fs_perr", 1, req);
273
274         } else if (qtcb->header.fsf_status != FSF_GOOD) {
275                 zfcp_dbf_hba_fsf_resp("fs_ferr", 1, req);
276
277         } else if ((req->fsf_command == FSF_QTCB_OPEN_PORT_WITH_DID) ||
278                    (req->fsf_command == FSF_QTCB_OPEN_LUN)) {
279                 zfcp_dbf_hba_fsf_resp("fs_open", 4, req);
280
281         } else if (qtcb->header.log_length) {
282                 zfcp_dbf_hba_fsf_resp("fs_qtcb", 5, req);
283
284         } else {
285                 zfcp_dbf_hba_fsf_resp("fs_norm", 6, req);
286         }
287 }
288
289 static inline
290 void 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)
293 {
294         if (level <= dbf->scsi->level)
295                 _zfcp_dbf_scsi(tag, tag2, level, dbf, scmd, req, old_id);
296 }
297
298 /**
299  * zfcp_dbf_scsi_result - trace event for SCSI command completion
300  * @dbf: adapter dbf trace
301  * @scmd: SCSI command pointer
302  * @req: FSF request used to issue SCSI command
303  */
304 static inline
305 void zfcp_dbf_scsi_result(struct zfcp_dbf *dbf, struct scsi_cmnd *scmd,
306                           struct zfcp_fsf_req *req)
307 {
308         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  */
321 static inline
322 void 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);
325 }
326
327 /**
328  * zfcp_dbf_scsi_abort - trace event for SCSI command abort
329  * @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  */
335 static inline
336 void 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)
339 {
340         zfcp_dbf_scsi("abrt", tag, 1, dbf, scmd, new_req, old_id);
341 }
342
343 /**
344  * zfcp_dbf_scsi_devreset - trace event for Logical Unit or Target Reset
345  * @tag: tag indicating success or failure of reset operation
346  * @scmnd: SCSI command which caused this error recovery
347  * @flag: indicates type of reset (Target Reset, Logical Unit Reset)
348  */
349 static inline
350 void zfcp_dbf_scsi_devreset(const char *tag, struct scsi_cmnd *scmnd, u8 flag)
351 {
352         struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(scmnd->device);
353
354         zfcp_dbf_scsi(flag == FCP_TMF_TGT_RESET ? "trst" : "lrst", tag, 1,
355                       zfcp_sdev->port->adapter->dbf, scmnd, NULL, 0);
356 }
357
358 #endif /* ZFCP_DBF_H */