blob: 2cee8197dd027d42668e984e5cc4b3b0c543cbbf [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
Swen Schilligae0904f2010-12-02 15:16:12 +010022/**
23 * struct zfcp_dbf_rec_trigger - trace record for triggered recovery action
24 * @ready: number of ready recovery actions
25 * @running: number of running recovery actions
26 * @want: wanted recovery action
27 * @need: needed recovery action
28 */
29struct zfcp_dbf_rec_trigger {
Christof Schmitt2b604c92008-03-31 11:15:28 +020030 u32 ready;
31 u32 running;
Christof Schmitt2b604c92008-03-31 11:15:28 +020032 u8 want;
33 u8 need;
Swen Schilligae0904f2010-12-02 15:16:12 +010034} __packed;
35
36/**
37 * struct zfcp_dbf_rec_running - trace record for running recovery
38 * @fsf_req_id: request id for fsf requests
39 * @rec_status: status of the fsf request
40 * @rec_step: current step of the recovery action
41 * rec_count: recovery counter
42 */
43struct zfcp_dbf_rec_running {
44 u64 fsf_req_id;
45 u32 rec_status;
46 u16 rec_step;
47 u8 rec_action;
48 u8 rec_count;
49} __packed;
50
51/**
52 * enum zfcp_dbf_rec_id - recovery trace record id
53 * @ZFCP_DBF_REC_TRIG: triggered recovery identifier
54 * @ZFCP_DBF_REC_RUN: running recovery identifier
55 */
56enum zfcp_dbf_rec_id {
57 ZFCP_DBF_REC_TRIG = 1,
58 ZFCP_DBF_REC_RUN = 2,
Martin Peschke73378912008-05-19 12:17:46 +020059};
Christof Schmitt2b604c92008-03-31 11:15:28 +020060
Swen Schilligae0904f2010-12-02 15:16:12 +010061/**
62 * struct zfcp_dbf_rec - trace record for error recovery actions
63 * @id: unique number of recovery record type
64 * @tag: identifier string specifying the location of initiation
65 * @lun: logical unit number
66 * @wwpn: word wide port number
67 * @d_id: destination ID
68 * @adapter_status: current status of the adapter
69 * @port_status: current status of the port
70 * @lun_status: current status of the lun
71 * @u.trig: structure zfcp_dbf_rec_trigger
72 * @u.run: structure zfcp_dbf_rec_running
73 */
74struct zfcp_dbf_rec {
Christof Schmitt2b604c92008-03-31 11:15:28 +020075 u8 id;
Swen Schilligae0904f2010-12-02 15:16:12 +010076 char tag[ZFCP_DBF_TAG_LEN];
77 u64 lun;
78 u64 wwpn;
79 u32 d_id;
80 u32 adapter_status;
81 u32 port_status;
82 u32 lun_status;
Christof Schmitt2b604c92008-03-31 11:15:28 +020083 union {
Swen Schilligae0904f2010-12-02 15:16:12 +010084 struct zfcp_dbf_rec_trigger trig;
85 struct zfcp_dbf_rec_running run;
Christof Schmitt2b604c92008-03-31 11:15:28 +020086 } u;
Swen Schilligae0904f2010-12-02 15:16:12 +010087} __packed;
Christof Schmitt2b604c92008-03-31 11:15:28 +020088
Swen Schillig2c55b752010-12-02 15:16:13 +010089/**
90 * enum zfcp_dbf_san_id - SAN trace record identifier
91 * @ZFCP_DBF_SAN_REQ: request trace record id
92 * @ZFCP_DBF_SAN_RES: response trace record id
93 * @ZFCP_DBF_SAN_ELS: extended link service record id
94 */
95enum zfcp_dbf_san_id {
96 ZFCP_DBF_SAN_REQ = 1,
97 ZFCP_DBF_SAN_RES = 2,
98 ZFCP_DBF_SAN_ELS = 3,
99};
100
101/** struct zfcp_dbf_san - trace record for SAN requests and responses
102 * @id: unique number of recovery record type
103 * @tag: identifier string specifying the location of initiation
104 * @fsf_req_id: request id for fsf requests
105 * @payload: unformatted information related to request/response
106 * @d_id: destination id
107 */
108struct zfcp_dbf_san {
109 u8 id;
110 char tag[ZFCP_DBF_TAG_LEN];
111 u64 fsf_req_id;
112 u32 d_id;
113#define ZFCP_DBF_SAN_MAX_PAYLOAD (FC_CT_HDR_LEN + 32)
114 char payload[ZFCP_DBF_SAN_MAX_PAYLOAD];
115} __packed;
116
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100117/**
118 * struct zfcp_dbf_hba_res - trace record for hba responses
119 * @req_issued: timestamp when request was issued
120 * @prot_status: protocol status
121 * @prot_status_qual: protocol status qualifier
122 * @fsf_status: fsf status
123 * @fsf_status_qual: fsf status qualifier
124 */
125struct zfcp_dbf_hba_res {
126 u64 req_issued;
127 u32 prot_status;
128 u8 prot_status_qual[FSF_PROT_STATUS_QUAL_SIZE];
Christof Schmitt2b604c92008-03-31 11:15:28 +0200129 u32 fsf_status;
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100130 u8 fsf_status_qual[FSF_STATUS_QUALIFIER_SIZE];
131} __packed;
Christof Schmitt2b604c92008-03-31 11:15:28 +0200132
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100133/**
134 * struct zfcp_dbf_hba_uss - trace record for unsolicited status
135 * @status_type: type of unsolicited status
136 * @status_subtype: subtype of unsolicited status
137 * @d_id: destination ID
138 * @lun: logical unit number
139 * @queue_designator: queue designator
140 */
141struct zfcp_dbf_hba_uss {
Christof Schmitt2b604c92008-03-31 11:15:28 +0200142 u32 status_type;
143 u32 status_subtype;
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100144 u32 d_id;
145 u64 lun;
146 u64 queue_designator;
147} __packed;
Christof Schmitt2b604c92008-03-31 11:15:28 +0200148
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100149/**
150 * enum zfcp_dbf_hba_id - HBA trace record identifier
151 * @ZFCP_DBF_HBA_RES: response trace record
152 * @ZFCP_DBF_HBA_USS: unsolicited status trace record
153 * @ZFCP_DBF_HBA_BIT: bit error trace record
154 */
155enum zfcp_dbf_hba_id {
156 ZFCP_DBF_HBA_RES = 1,
157 ZFCP_DBF_HBA_USS = 2,
158 ZFCP_DBF_HBA_BIT = 3,
159};
Christof Schmitt2b604c92008-03-31 11:15:28 +0200160
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100161/**
162 * struct zfcp_dbf_hba - common trace record for HBA records
163 * @id: unique number of recovery record type
164 * @tag: identifier string specifying the location of initiation
165 * @fsf_req_id: request id for fsf requests
166 * @fsf_req_status: status of fsf request
167 * @fsf_cmd: fsf command
168 * @fsf_seq_no: fsf sequence number
169 * @pl_len: length of payload stored as zfcp_dbf_pay
170 * @u: record type specific data
171 */
172struct zfcp_dbf_hba {
173 u8 id;
174 char tag[ZFCP_DBF_TAG_LEN];
175 u64 fsf_req_id;
176 u32 fsf_req_status;
177 u32 fsf_cmd;
178 u32 fsf_seq_no;
179 u16 pl_len;
Christof Schmitt2b604c92008-03-31 11:15:28 +0200180 union {
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100181 struct zfcp_dbf_hba_res res;
182 struct zfcp_dbf_hba_uss uss;
183 struct fsf_bit_error_payload be;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200184 } u;
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100185} __packed;
186
187/**
Swen Schillig250a1352010-12-02 15:16:15 +0100188 * enum zfcp_dbf_scsi_id - scsi trace record identifier
189 * @ZFCP_DBF_SCSI_CMND: scsi command trace record
190 */
191enum zfcp_dbf_scsi_id {
192 ZFCP_DBF_SCSI_CMND = 1,
193};
194
195/**
196 * struct zfcp_dbf_scsi - common trace record for SCSI records
197 * @id: unique number of recovery record type
198 * @tag: identifier string specifying the location of initiation
199 * @scsi_id: scsi device id
200 * @scsi_lun: scsi device logical unit number
201 * @scsi_result: scsi result
202 * @scsi_retries: current retry number of scsi request
203 * @scsi_allowed: allowed retries
204 * @fcp_rsp_info: FCP response info
205 * @scsi_opcode: scsi opcode
206 * @fsf_req_id: request id of fsf request
207 * @host_scribble: LLD specific data attached to SCSI request
208 * @pl_len: length of paload stored as zfcp_dbf_pay
209 * @fsf_rsp: response for fsf request
210 */
211struct zfcp_dbf_scsi {
212 u8 id;
213 char tag[ZFCP_DBF_TAG_LEN];
214 u32 scsi_id;
215 u32 scsi_lun;
216 u32 scsi_result;
217 u8 scsi_retries;
218 u8 scsi_allowed;
219 u8 fcp_rsp_info;
220#define ZFCP_DBF_SCSI_OPCODE 16
221 u8 scsi_opcode[ZFCP_DBF_SCSI_OPCODE];
222 u64 fsf_req_id;
223 u64 host_scribble;
224 u16 pl_len;
225 struct fcp_resp_with_ext fcp_rsp;
226} __packed;
227
228/**
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100229 * struct zfcp_dbf_pay - trace record for unformatted payload information
230 * @area: area this record is originated from
231 * @counter: ascending record number
232 * @fsf_req_id: request id of fsf request
233 * @data: unformatted data
234 */
235struct zfcp_dbf_pay {
236 char area[ZFCP_DBF_TAG_LEN];
237 char counter;
238 u64 fsf_req_id;
239#define ZFCP_DBF_PAY_MAX_REC 0x100
240 char data[ZFCP_DBF_PAY_MAX_REC];
241} __packed;
Christof Schmitt2b604c92008-03-31 11:15:28 +0200242
Christof Schmittd46f3842009-08-18 15:43:07 +0200243struct zfcp_dbf {
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100244 debug_info_t *pay;
Swen Schillig57717102009-08-18 15:43:21 +0200245 debug_info_t *rec;
246 debug_info_t *hba;
247 debug_info_t *san;
248 debug_info_t *scsi;
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100249 spinlock_t pay_lock;
Swen Schillig57717102009-08-18 15:43:21 +0200250 spinlock_t rec_lock;
251 spinlock_t hba_lock;
252 spinlock_t san_lock;
253 spinlock_t scsi_lock;
Swen Schilligae0904f2010-12-02 15:16:12 +0100254 struct zfcp_dbf_rec rec_buf;
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100255 struct zfcp_dbf_hba hba_buf;
Swen Schillig2c55b752010-12-02 15:16:13 +0100256 struct zfcp_dbf_san san_buf;
Swen Schillig250a1352010-12-02 15:16:15 +0100257 struct zfcp_dbf_scsi scsi_buf;
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100258 struct zfcp_dbf_pay pay_buf;
Swen Schillig57717102009-08-18 15:43:21 +0200259 struct zfcp_adapter *adapter;
Christof Schmittd46f3842009-08-18 15:43:07 +0200260};
261
Christof Schmittdcd20e22009-08-18 15:43:08 +0200262static inline
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100263void zfcp_dbf_hba_fsf_resp(char *tag, int level, struct zfcp_fsf_req *req)
Christof Schmitt2e261af2009-08-18 15:43:09 +0200264{
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100265 if (level <= req->adapter->dbf->hba->level)
266 zfcp_dbf_hba_fsf_res(tag, req);
Christof Schmitt2e261af2009-08-18 15:43:09 +0200267}
268
269/**
Swen Schillig57717102009-08-18 15:43:21 +0200270 * zfcp_dbf_hba_fsf_response - trace event for request completion
Swen Schillig250a1352010-12-02 15:16:15 +0100271 * @req: request that has been completed
Christof Schmitt2e261af2009-08-18 15:43:09 +0200272 */
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100273static inline
274void zfcp_dbf_hba_fsf_response(struct zfcp_fsf_req *req)
Christof Schmitt2e261af2009-08-18 15:43:09 +0200275{
Christof Schmitt2e261af2009-08-18 15:43:09 +0200276 struct fsf_qtcb *qtcb = req->qtcb;
277
278 if ((qtcb->prefix.prot_status != FSF_PROT_GOOD) &&
279 (qtcb->prefix.prot_status != FSF_PROT_FSF_STATUS_PRESENTED)) {
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100280 zfcp_dbf_hba_fsf_resp("fs_perr", 1, req);
Christof Schmitt2e261af2009-08-18 15:43:09 +0200281
282 } else if (qtcb->header.fsf_status != FSF_GOOD) {
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100283 zfcp_dbf_hba_fsf_resp("fs_ferr", 1, req);
Christof Schmitt2e261af2009-08-18 15:43:09 +0200284
285 } else if ((req->fsf_command == FSF_QTCB_OPEN_PORT_WITH_DID) ||
286 (req->fsf_command == FSF_QTCB_OPEN_LUN)) {
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100287 zfcp_dbf_hba_fsf_resp("fs_open", 4, req);
Christof Schmitt2e261af2009-08-18 15:43:09 +0200288
289 } else if (qtcb->header.log_length) {
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100290 zfcp_dbf_hba_fsf_resp("fs_qtcb", 5, req);
Christof Schmitt2e261af2009-08-18 15:43:09 +0200291
292 } else {
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100293 zfcp_dbf_hba_fsf_resp("fs_norm", 6, req);
Christof Schmitt2e261af2009-08-18 15:43:09 +0200294 }
Christof Schmitt2e261af2009-08-18 15:43:09 +0200295}
296
297static inline
Swen Schillig250a1352010-12-02 15:16:15 +0100298void _zfcp_dbf_scsi(char *tag, int level, struct scsi_cmnd *scmd,
299 struct zfcp_fsf_req *req)
Christof Schmittdcd20e22009-08-18 15:43:08 +0200300{
Swen Schillig250a1352010-12-02 15:16:15 +0100301 struct zfcp_adapter *adapter = (struct zfcp_adapter *)
302 scmd->device->host->hostdata[0];
303
304 if (level <= adapter->dbf->scsi->level)
305 zfcp_dbf_scsi(tag, scmd, req);
Christof Schmittdcd20e22009-08-18 15:43:08 +0200306}
307
308/**
Swen Schillig57717102009-08-18 15:43:21 +0200309 * zfcp_dbf_scsi_result - trace event for SCSI command completion
Christof Schmittdcd20e22009-08-18 15:43:08 +0200310 * @scmd: SCSI command pointer
Christof Schmittab725282010-02-17 11:18:57 +0100311 * @req: FSF request used to issue SCSI command
Christof Schmittdcd20e22009-08-18 15:43:08 +0200312 */
313static inline
Swen Schillig250a1352010-12-02 15:16:15 +0100314void zfcp_dbf_scsi_result(struct scsi_cmnd *scmd, struct zfcp_fsf_req *req)
Christof Schmittdcd20e22009-08-18 15:43:08 +0200315{
Christof Schmittab725282010-02-17 11:18:57 +0100316 if (scmd->result != 0)
Swen Schillig250a1352010-12-02 15:16:15 +0100317 _zfcp_dbf_scsi("rsl_err", 3, scmd, req);
Christof Schmittab725282010-02-17 11:18:57 +0100318 else if (scmd->retries > 0)
Swen Schillig250a1352010-12-02 15:16:15 +0100319 _zfcp_dbf_scsi("rsl_ret", 4, scmd, req);
Christof Schmittab725282010-02-17 11:18:57 +0100320 else
Swen Schillig250a1352010-12-02 15:16:15 +0100321 _zfcp_dbf_scsi("rsl_nor", 6, scmd, req);
Christof Schmittab725282010-02-17 11:18:57 +0100322}
323
324/**
325 * zfcp_dbf_scsi_fail_send - trace event for failure to send SCSI command
Christof Schmittab725282010-02-17 11:18:57 +0100326 * @scmd: SCSI command pointer
327 */
328static inline
Swen Schillig250a1352010-12-02 15:16:15 +0100329void zfcp_dbf_scsi_fail_send(struct scsi_cmnd *scmd)
Christof Schmittab725282010-02-17 11:18:57 +0100330{
Swen Schillig250a1352010-12-02 15:16:15 +0100331 _zfcp_dbf_scsi("rsl_fai", 4, scmd, NULL);
Christof Schmittdcd20e22009-08-18 15:43:08 +0200332}
333
334/**
Swen Schillig57717102009-08-18 15:43:21 +0200335 * zfcp_dbf_scsi_abort - trace event for SCSI command abort
Christof Schmittdcd20e22009-08-18 15:43:08 +0200336 * @tag: tag indicating success or failure of abort operation
Christof Schmittdcd20e22009-08-18 15:43:08 +0200337 * @scmd: SCSI command to be aborted
Swen Schillig250a1352010-12-02 15:16:15 +0100338 * @fsf_req: request containing abort (might be NULL)
Christof Schmittdcd20e22009-08-18 15:43:08 +0200339 */
340static inline
Swen Schillig250a1352010-12-02 15:16:15 +0100341void zfcp_dbf_scsi_abort(char *tag, struct scsi_cmnd *scmd,
342 struct zfcp_fsf_req *fsf_req)
Christof Schmittdcd20e22009-08-18 15:43:08 +0200343{
Swen Schillig250a1352010-12-02 15:16:15 +0100344 _zfcp_dbf_scsi(tag, 1, scmd, fsf_req);
Christof Schmittdcd20e22009-08-18 15:43:08 +0200345}
346
347/**
Swen Schillig57717102009-08-18 15:43:21 +0200348 * zfcp_dbf_scsi_devreset - trace event for Logical Unit or Target Reset
Christof Schmittdcd20e22009-08-18 15:43:08 +0200349 * @tag: tag indicating success or failure of reset operation
Christof Schmittb62a8d92010-09-08 14:39:55 +0200350 * @scmnd: SCSI command which caused this error recovery
Christof Schmittdcd20e22009-08-18 15:43:08 +0200351 * @flag: indicates type of reset (Target Reset, Logical Unit Reset)
Christof Schmittdcd20e22009-08-18 15:43:08 +0200352 */
353static inline
Swen Schillig250a1352010-12-02 15:16:15 +0100354void zfcp_dbf_scsi_devreset(char *tag, struct scsi_cmnd *scmnd, u8 flag)
Christof Schmittdcd20e22009-08-18 15:43:08 +0200355{
Swen Schillig250a1352010-12-02 15:16:15 +0100356 char tmp_tag[ZFCP_DBF_TAG_LEN];
Christof Schmittb62a8d92010-09-08 14:39:55 +0200357
Swen Schillig250a1352010-12-02 15:16:15 +0100358 if (flag == FCP_TMF_TGT_RESET)
359 memcpy(tmp_tag, "tr_", 3);
360 else
361 memcpy(tmp_tag, "lr_", 3);
362
363 memcpy(&tmp_tag[3], tag, 4);
364 _zfcp_dbf_scsi(tmp_tag, 1, scmnd, NULL);
Christof Schmittdcd20e22009-08-18 15:43:08 +0200365}
366
Christof Schmitt2b604c92008-03-31 11:15:28 +0200367#endif /* ZFCP_DBF_H */