blob: 714f087eb7a96bdf973b43665636d14df9adc7a9 [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
Christof Schmittd21e9da2010-02-17 11:18:54 +010018#define ZFCP_DBF_INVALID_LUN 0xFFFFFFFFFFFFFFFFull
19
Swen Schilligae0904f2010-12-02 15:16:12 +010020/**
21 * struct zfcp_dbf_rec_trigger - trace record for triggered recovery action
22 * @ready: number of ready recovery actions
23 * @running: number of running recovery actions
24 * @want: wanted recovery action
25 * @need: needed recovery action
26 */
27struct zfcp_dbf_rec_trigger {
Christof Schmitt2b604c92008-03-31 11:15:28 +020028 u32 ready;
29 u32 running;
Christof Schmitt2b604c92008-03-31 11:15:28 +020030 u8 want;
31 u8 need;
Swen Schilligae0904f2010-12-02 15:16:12 +010032} __packed;
33
34/**
35 * struct zfcp_dbf_rec_running - trace record for running recovery
36 * @fsf_req_id: request id for fsf requests
37 * @rec_status: status of the fsf request
38 * @rec_step: current step of the recovery action
39 * rec_count: recovery counter
40 */
41struct zfcp_dbf_rec_running {
42 u64 fsf_req_id;
43 u32 rec_status;
44 u16 rec_step;
45 u8 rec_action;
46 u8 rec_count;
47} __packed;
48
49/**
50 * enum zfcp_dbf_rec_id - recovery trace record id
51 * @ZFCP_DBF_REC_TRIG: triggered recovery identifier
52 * @ZFCP_DBF_REC_RUN: running recovery identifier
53 */
54enum zfcp_dbf_rec_id {
55 ZFCP_DBF_REC_TRIG = 1,
56 ZFCP_DBF_REC_RUN = 2,
Martin Peschke73378912008-05-19 12:17:46 +020057};
Christof Schmitt2b604c92008-03-31 11:15:28 +020058
Swen Schilligae0904f2010-12-02 15:16:12 +010059/**
60 * struct zfcp_dbf_rec - trace record for error recovery actions
61 * @id: unique number of recovery record type
62 * @tag: identifier string specifying the location of initiation
63 * @lun: logical unit number
64 * @wwpn: word wide port number
65 * @d_id: destination ID
66 * @adapter_status: current status of the adapter
67 * @port_status: current status of the port
68 * @lun_status: current status of the lun
69 * @u.trig: structure zfcp_dbf_rec_trigger
70 * @u.run: structure zfcp_dbf_rec_running
71 */
72struct zfcp_dbf_rec {
Christof Schmitt2b604c92008-03-31 11:15:28 +020073 u8 id;
Swen Schilligae0904f2010-12-02 15:16:12 +010074 char tag[ZFCP_DBF_TAG_LEN];
75 u64 lun;
76 u64 wwpn;
77 u32 d_id;
78 u32 adapter_status;
79 u32 port_status;
80 u32 lun_status;
Christof Schmitt2b604c92008-03-31 11:15:28 +020081 union {
Swen Schilligae0904f2010-12-02 15:16:12 +010082 struct zfcp_dbf_rec_trigger trig;
83 struct zfcp_dbf_rec_running run;
Christof Schmitt2b604c92008-03-31 11:15:28 +020084 } u;
Swen Schilligae0904f2010-12-02 15:16:12 +010085} __packed;
Christof Schmitt2b604c92008-03-31 11:15:28 +020086
Swen Schillig2c55b752010-12-02 15:16:13 +010087/**
88 * enum zfcp_dbf_san_id - SAN trace record identifier
89 * @ZFCP_DBF_SAN_REQ: request trace record id
90 * @ZFCP_DBF_SAN_RES: response trace record id
91 * @ZFCP_DBF_SAN_ELS: extended link service record id
92 */
93enum zfcp_dbf_san_id {
94 ZFCP_DBF_SAN_REQ = 1,
95 ZFCP_DBF_SAN_RES = 2,
96 ZFCP_DBF_SAN_ELS = 3,
97};
98
99/** struct zfcp_dbf_san - trace record for SAN requests and responses
100 * @id: unique number of recovery record type
101 * @tag: identifier string specifying the location of initiation
102 * @fsf_req_id: request id for fsf requests
103 * @payload: unformatted information related to request/response
104 * @d_id: destination id
105 */
106struct zfcp_dbf_san {
107 u8 id;
108 char tag[ZFCP_DBF_TAG_LEN];
109 u64 fsf_req_id;
110 u32 d_id;
111#define ZFCP_DBF_SAN_MAX_PAYLOAD (FC_CT_HDR_LEN + 32)
112 char payload[ZFCP_DBF_SAN_MAX_PAYLOAD];
113} __packed;
114
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100115/**
116 * struct zfcp_dbf_hba_res - trace record for hba responses
117 * @req_issued: timestamp when request was issued
118 * @prot_status: protocol status
119 * @prot_status_qual: protocol status qualifier
120 * @fsf_status: fsf status
121 * @fsf_status_qual: fsf status qualifier
122 */
123struct zfcp_dbf_hba_res {
124 u64 req_issued;
125 u32 prot_status;
126 u8 prot_status_qual[FSF_PROT_STATUS_QUAL_SIZE];
Christof Schmitt2b604c92008-03-31 11:15:28 +0200127 u32 fsf_status;
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100128 u8 fsf_status_qual[FSF_STATUS_QUALIFIER_SIZE];
129} __packed;
Christof Schmitt2b604c92008-03-31 11:15:28 +0200130
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100131/**
132 * struct zfcp_dbf_hba_uss - trace record for unsolicited status
133 * @status_type: type of unsolicited status
134 * @status_subtype: subtype of unsolicited status
135 * @d_id: destination ID
136 * @lun: logical unit number
137 * @queue_designator: queue designator
138 */
139struct zfcp_dbf_hba_uss {
Christof Schmitt2b604c92008-03-31 11:15:28 +0200140 u32 status_type;
141 u32 status_subtype;
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100142 u32 d_id;
143 u64 lun;
144 u64 queue_designator;
145} __packed;
Christof Schmitt2b604c92008-03-31 11:15:28 +0200146
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100147/**
148 * enum zfcp_dbf_hba_id - HBA trace record identifier
149 * @ZFCP_DBF_HBA_RES: response trace record
150 * @ZFCP_DBF_HBA_USS: unsolicited status trace record
151 * @ZFCP_DBF_HBA_BIT: bit error trace record
152 */
153enum zfcp_dbf_hba_id {
154 ZFCP_DBF_HBA_RES = 1,
155 ZFCP_DBF_HBA_USS = 2,
156 ZFCP_DBF_HBA_BIT = 3,
157};
Christof Schmitt2b604c92008-03-31 11:15:28 +0200158
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100159/**
160 * struct zfcp_dbf_hba - common trace record for HBA records
161 * @id: unique number of recovery record type
162 * @tag: identifier string specifying the location of initiation
163 * @fsf_req_id: request id for fsf requests
164 * @fsf_req_status: status of fsf request
165 * @fsf_cmd: fsf command
166 * @fsf_seq_no: fsf sequence number
167 * @pl_len: length of payload stored as zfcp_dbf_pay
168 * @u: record type specific data
169 */
170struct zfcp_dbf_hba {
171 u8 id;
172 char tag[ZFCP_DBF_TAG_LEN];
173 u64 fsf_req_id;
174 u32 fsf_req_status;
175 u32 fsf_cmd;
176 u32 fsf_seq_no;
177 u16 pl_len;
Christof Schmitt2b604c92008-03-31 11:15:28 +0200178 union {
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100179 struct zfcp_dbf_hba_res res;
180 struct zfcp_dbf_hba_uss uss;
181 struct fsf_bit_error_payload be;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200182 } u;
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100183} __packed;
184
185/**
Swen Schillig250a1352010-12-02 15:16:15 +0100186 * enum zfcp_dbf_scsi_id - scsi trace record identifier
187 * @ZFCP_DBF_SCSI_CMND: scsi command trace record
188 */
189enum zfcp_dbf_scsi_id {
190 ZFCP_DBF_SCSI_CMND = 1,
191};
192
193/**
194 * struct zfcp_dbf_scsi - common trace record for SCSI records
195 * @id: unique number of recovery record type
196 * @tag: identifier string specifying the location of initiation
197 * @scsi_id: scsi device id
198 * @scsi_lun: scsi device logical unit number
199 * @scsi_result: scsi result
200 * @scsi_retries: current retry number of scsi request
201 * @scsi_allowed: allowed retries
202 * @fcp_rsp_info: FCP response info
203 * @scsi_opcode: scsi opcode
204 * @fsf_req_id: request id of fsf request
205 * @host_scribble: LLD specific data attached to SCSI request
206 * @pl_len: length of paload stored as zfcp_dbf_pay
207 * @fsf_rsp: response for fsf request
208 */
209struct zfcp_dbf_scsi {
210 u8 id;
211 char tag[ZFCP_DBF_TAG_LEN];
212 u32 scsi_id;
213 u32 scsi_lun;
214 u32 scsi_result;
215 u8 scsi_retries;
216 u8 scsi_allowed;
217 u8 fcp_rsp_info;
218#define ZFCP_DBF_SCSI_OPCODE 16
219 u8 scsi_opcode[ZFCP_DBF_SCSI_OPCODE];
220 u64 fsf_req_id;
221 u64 host_scribble;
222 u16 pl_len;
223 struct fcp_resp_with_ext fcp_rsp;
224} __packed;
225
226/**
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100227 * struct zfcp_dbf_pay - trace record for unformatted payload information
228 * @area: area this record is originated from
229 * @counter: ascending record number
230 * @fsf_req_id: request id of fsf request
231 * @data: unformatted data
232 */
233struct zfcp_dbf_pay {
Swen Schilligea4a3a62010-12-02 15:16:16 +0100234 u8 counter;
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100235 char area[ZFCP_DBF_TAG_LEN];
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100236 u64 fsf_req_id;
237#define ZFCP_DBF_PAY_MAX_REC 0x100
238 char data[ZFCP_DBF_PAY_MAX_REC];
239} __packed;
Christof Schmitt2b604c92008-03-31 11:15:28 +0200240
Swen Schilligea4a3a62010-12-02 15:16:16 +0100241/**
242 * struct zfcp_dbf - main dbf trace structure
243 * @pay: reference to payload trace area
244 * @rec: reference to recovery trace area
245 * @hba: reference to hba trace area
246 * @san: reference to san trace area
247 * @scsi: reference to scsi trace area
248 * @pay_lock: lock protecting payload trace buffer
249 * @rec_lock: lock protecting recovery trace buffer
250 * @hba_lock: lock protecting hba trace buffer
251 * @san_lock: lock protecting san trace buffer
252 * @scsi_lock: lock protecting scsi trace buffer
253 * @pay_buf: pre-allocated buffer for payload
254 * @rec_buf: pre-allocated buffer for recovery
255 * @hba_buf: pre-allocated buffer for hba
256 * @san_buf: pre-allocated buffer for san
257 * @scsi_buf: pre-allocated buffer for scsi
258 */
Christof Schmittd46f3842009-08-18 15:43:07 +0200259struct zfcp_dbf {
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100260 debug_info_t *pay;
Swen Schillig57717102009-08-18 15:43:21 +0200261 debug_info_t *rec;
262 debug_info_t *hba;
263 debug_info_t *san;
264 debug_info_t *scsi;
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100265 spinlock_t pay_lock;
Swen Schillig57717102009-08-18 15:43:21 +0200266 spinlock_t rec_lock;
267 spinlock_t hba_lock;
268 spinlock_t san_lock;
269 spinlock_t scsi_lock;
Swen Schilligea4a3a62010-12-02 15:16:16 +0100270 struct zfcp_dbf_pay pay_buf;
Swen Schilligae0904f2010-12-02 15:16:12 +0100271 struct zfcp_dbf_rec rec_buf;
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100272 struct zfcp_dbf_hba hba_buf;
Swen Schillig2c55b752010-12-02 15:16:13 +0100273 struct zfcp_dbf_san san_buf;
Swen Schillig250a1352010-12-02 15:16:15 +0100274 struct zfcp_dbf_scsi scsi_buf;
Christof Schmittd46f3842009-08-18 15:43:07 +0200275};
276
Christof Schmittdcd20e22009-08-18 15:43:08 +0200277static inline
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100278void zfcp_dbf_hba_fsf_resp(char *tag, int level, struct zfcp_fsf_req *req)
Christof Schmitt2e261af2009-08-18 15:43:09 +0200279{
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100280 if (level <= req->adapter->dbf->hba->level)
281 zfcp_dbf_hba_fsf_res(tag, req);
Christof Schmitt2e261af2009-08-18 15:43:09 +0200282}
283
284/**
Swen Schillig57717102009-08-18 15:43:21 +0200285 * zfcp_dbf_hba_fsf_response - trace event for request completion
Swen Schillig250a1352010-12-02 15:16:15 +0100286 * @req: request that has been completed
Christof Schmitt2e261af2009-08-18 15:43:09 +0200287 */
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100288static inline
289void zfcp_dbf_hba_fsf_response(struct zfcp_fsf_req *req)
Christof Schmitt2e261af2009-08-18 15:43:09 +0200290{
Christof Schmitt2e261af2009-08-18 15:43:09 +0200291 struct fsf_qtcb *qtcb = req->qtcb;
292
293 if ((qtcb->prefix.prot_status != FSF_PROT_GOOD) &&
294 (qtcb->prefix.prot_status != FSF_PROT_FSF_STATUS_PRESENTED)) {
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100295 zfcp_dbf_hba_fsf_resp("fs_perr", 1, req);
Christof Schmitt2e261af2009-08-18 15:43:09 +0200296
297 } else if (qtcb->header.fsf_status != FSF_GOOD) {
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100298 zfcp_dbf_hba_fsf_resp("fs_ferr", 1, req);
Christof Schmitt2e261af2009-08-18 15:43:09 +0200299
300 } else if ((req->fsf_command == FSF_QTCB_OPEN_PORT_WITH_DID) ||
301 (req->fsf_command == FSF_QTCB_OPEN_LUN)) {
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100302 zfcp_dbf_hba_fsf_resp("fs_open", 4, req);
Christof Schmitt2e261af2009-08-18 15:43:09 +0200303
304 } else if (qtcb->header.log_length) {
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100305 zfcp_dbf_hba_fsf_resp("fs_qtcb", 5, req);
Christof Schmitt2e261af2009-08-18 15:43:09 +0200306
307 } else {
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100308 zfcp_dbf_hba_fsf_resp("fs_norm", 6, req);
Christof Schmitt2e261af2009-08-18 15:43:09 +0200309 }
Christof Schmitt2e261af2009-08-18 15:43:09 +0200310}
311
312static inline
Swen Schillig250a1352010-12-02 15:16:15 +0100313void _zfcp_dbf_scsi(char *tag, int level, struct scsi_cmnd *scmd,
314 struct zfcp_fsf_req *req)
Christof Schmittdcd20e22009-08-18 15:43:08 +0200315{
Swen Schillig250a1352010-12-02 15:16:15 +0100316 struct zfcp_adapter *adapter = (struct zfcp_adapter *)
317 scmd->device->host->hostdata[0];
318
319 if (level <= adapter->dbf->scsi->level)
320 zfcp_dbf_scsi(tag, scmd, req);
Christof Schmittdcd20e22009-08-18 15:43:08 +0200321}
322
323/**
Swen Schillig57717102009-08-18 15:43:21 +0200324 * zfcp_dbf_scsi_result - trace event for SCSI command completion
Christof Schmittdcd20e22009-08-18 15:43:08 +0200325 * @scmd: SCSI command pointer
Christof Schmittab725282010-02-17 11:18:57 +0100326 * @req: FSF request used to issue SCSI command
Christof Schmittdcd20e22009-08-18 15:43:08 +0200327 */
328static inline
Swen Schillig250a1352010-12-02 15:16:15 +0100329void zfcp_dbf_scsi_result(struct scsi_cmnd *scmd, struct zfcp_fsf_req *req)
Christof Schmittdcd20e22009-08-18 15:43:08 +0200330{
Christof Schmittab725282010-02-17 11:18:57 +0100331 if (scmd->result != 0)
Swen Schillig250a1352010-12-02 15:16:15 +0100332 _zfcp_dbf_scsi("rsl_err", 3, scmd, req);
Christof Schmittab725282010-02-17 11:18:57 +0100333 else if (scmd->retries > 0)
Swen Schillig250a1352010-12-02 15:16:15 +0100334 _zfcp_dbf_scsi("rsl_ret", 4, scmd, req);
Christof Schmittab725282010-02-17 11:18:57 +0100335 else
Swen Schillig250a1352010-12-02 15:16:15 +0100336 _zfcp_dbf_scsi("rsl_nor", 6, scmd, req);
Christof Schmittab725282010-02-17 11:18:57 +0100337}
338
339/**
340 * zfcp_dbf_scsi_fail_send - trace event for failure to send SCSI command
Christof Schmittab725282010-02-17 11:18:57 +0100341 * @scmd: SCSI command pointer
342 */
343static inline
Swen Schillig250a1352010-12-02 15:16:15 +0100344void zfcp_dbf_scsi_fail_send(struct scsi_cmnd *scmd)
Christof Schmittab725282010-02-17 11:18:57 +0100345{
Swen Schillig250a1352010-12-02 15:16:15 +0100346 _zfcp_dbf_scsi("rsl_fai", 4, scmd, NULL);
Christof Schmittdcd20e22009-08-18 15:43:08 +0200347}
348
349/**
Swen Schillig57717102009-08-18 15:43:21 +0200350 * zfcp_dbf_scsi_abort - trace event for SCSI command abort
Christof Schmittdcd20e22009-08-18 15:43:08 +0200351 * @tag: tag indicating success or failure of abort operation
Christof Schmittdcd20e22009-08-18 15:43:08 +0200352 * @scmd: SCSI command to be aborted
Swen Schillig250a1352010-12-02 15:16:15 +0100353 * @fsf_req: request containing abort (might be NULL)
Christof Schmittdcd20e22009-08-18 15:43:08 +0200354 */
355static inline
Swen Schillig250a1352010-12-02 15:16:15 +0100356void zfcp_dbf_scsi_abort(char *tag, struct scsi_cmnd *scmd,
357 struct zfcp_fsf_req *fsf_req)
Christof Schmittdcd20e22009-08-18 15:43:08 +0200358{
Swen Schillig250a1352010-12-02 15:16:15 +0100359 _zfcp_dbf_scsi(tag, 1, scmd, fsf_req);
Christof Schmittdcd20e22009-08-18 15:43:08 +0200360}
361
362/**
Swen Schillig57717102009-08-18 15:43:21 +0200363 * zfcp_dbf_scsi_devreset - trace event for Logical Unit or Target Reset
Christof Schmittdcd20e22009-08-18 15:43:08 +0200364 * @tag: tag indicating success or failure of reset operation
Christof Schmittb62a8d92010-09-08 14:39:55 +0200365 * @scmnd: SCSI command which caused this error recovery
Christof Schmittdcd20e22009-08-18 15:43:08 +0200366 * @flag: indicates type of reset (Target Reset, Logical Unit Reset)
Christof Schmittdcd20e22009-08-18 15:43:08 +0200367 */
368static inline
Swen Schillig250a1352010-12-02 15:16:15 +0100369void zfcp_dbf_scsi_devreset(char *tag, struct scsi_cmnd *scmnd, u8 flag)
Christof Schmittdcd20e22009-08-18 15:43:08 +0200370{
Swen Schillig250a1352010-12-02 15:16:15 +0100371 char tmp_tag[ZFCP_DBF_TAG_LEN];
Christof Schmittb62a8d92010-09-08 14:39:55 +0200372
Swen Schillig250a1352010-12-02 15:16:15 +0100373 if (flag == FCP_TMF_TGT_RESET)
374 memcpy(tmp_tag, "tr_", 3);
375 else
376 memcpy(tmp_tag, "lr_", 3);
377
378 memcpy(&tmp_tag[3], tag, 4);
379 _zfcp_dbf_scsi(tmp_tag, 1, scmnd, NULL);
Christof Schmittdcd20e22009-08-18 15:43:08 +0200380}
381
Christof Schmitt2b604c92008-03-31 11:15:28 +0200382#endif /* ZFCP_DBF_H */