• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
18 #define ZFCP_DBF_INVALID_LUN	0xFFFFFFFFFFFFFFFFull
19 
20 /**
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  */
27 struct zfcp_dbf_rec_trigger {
28 	u32 ready;
29 	u32 running;
30 	u8 want;
31 	u8 need;
32 } __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  */
41 struct 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  */
54 enum zfcp_dbf_rec_id {
55 	ZFCP_DBF_REC_TRIG	= 1,
56 	ZFCP_DBF_REC_RUN	= 2,
57 };
58 
59 /**
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  */
72 struct zfcp_dbf_rec {
73 	u8 id;
74 	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;
81 	union {
82 		struct zfcp_dbf_rec_trigger trig;
83 		struct zfcp_dbf_rec_running run;
84 	} u;
85 } __packed;
86 
87 /**
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  */
93 enum 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  */
106 struct 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 
115 /**
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  */
123 struct zfcp_dbf_hba_res {
124 	u64 req_issued;
125 	u32 prot_status;
126 	u8  prot_status_qual[FSF_PROT_STATUS_QUAL_SIZE];
127 	u32 fsf_status;
128 	u8  fsf_status_qual[FSF_STATUS_QUALIFIER_SIZE];
129 } __packed;
130 
131 /**
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  */
139 struct zfcp_dbf_hba_uss {
140 	u32 status_type;
141 	u32 status_subtype;
142 	u32 d_id;
143 	u64 lun;
144 	u64 queue_designator;
145 } __packed;
146 
147 /**
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  */
153 enum zfcp_dbf_hba_id {
154 	ZFCP_DBF_HBA_RES	= 1,
155 	ZFCP_DBF_HBA_USS	= 2,
156 	ZFCP_DBF_HBA_BIT	= 3,
157 	ZFCP_DBF_HBA_BASIC	= 4,
158 };
159 
160 /**
161  * struct zfcp_dbf_hba - common trace record for HBA records
162  * @id: unique number of recovery record type
163  * @tag: identifier string specifying the location of initiation
164  * @fsf_req_id: request id for fsf requests
165  * @fsf_req_status: status of fsf request
166  * @fsf_cmd: fsf command
167  * @fsf_seq_no: fsf sequence number
168  * @pl_len: length of payload stored as zfcp_dbf_pay
169  * @u: record type specific data
170  */
171 struct zfcp_dbf_hba {
172 	u8 id;
173 	char tag[ZFCP_DBF_TAG_LEN];
174 	u64 fsf_req_id;
175 	u32 fsf_req_status;
176 	u32 fsf_cmd;
177 	u32 fsf_seq_no;
178 	u16 pl_len;
179 	union {
180 		struct zfcp_dbf_hba_res res;
181 		struct zfcp_dbf_hba_uss uss;
182 		struct fsf_bit_error_payload be;
183 	} u;
184 } __packed;
185 
186 /**
187  * enum zfcp_dbf_scsi_id - scsi trace record identifier
188  * @ZFCP_DBF_SCSI_CMND: scsi command trace record
189  */
190 enum zfcp_dbf_scsi_id {
191 	ZFCP_DBF_SCSI_CMND	= 1,
192 };
193 
194 /**
195  * struct zfcp_dbf_scsi - common trace record for SCSI records
196  * @id: unique number of recovery record type
197  * @tag: identifier string specifying the location of initiation
198  * @scsi_id: scsi device id
199  * @scsi_lun: scsi device logical unit number, low part of 64 bit, old 32 bit
200  * @scsi_result: scsi result
201  * @scsi_retries: current retry number of scsi request
202  * @scsi_allowed: allowed retries
203  * @fcp_rsp_info: FCP response info
204  * @scsi_opcode: scsi opcode
205  * @fsf_req_id: request id of fsf request
206  * @host_scribble: LLD specific data attached to SCSI request
207  * @pl_len: length of paload stored as zfcp_dbf_pay
208  * @fsf_rsp: response for fsf request
209  * @scsi_lun_64_hi: scsi device logical unit number, high part of 64 bit
210  */
211 struct 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 	u32 scsi_lun_64_hi;
227 } __packed;
228 
229 /**
230  * struct zfcp_dbf_pay - trace record for unformatted payload information
231  * @area: area this record is originated from
232  * @counter: ascending record number
233  * @fsf_req_id: request id of fsf request
234  * @data: unformatted data
235  */
236 struct zfcp_dbf_pay {
237 	u8 counter;
238 	char area[ZFCP_DBF_TAG_LEN];
239 	u64 fsf_req_id;
240 #define ZFCP_DBF_PAY_MAX_REC 0x100
241 	char data[ZFCP_DBF_PAY_MAX_REC];
242 } __packed;
243 
244 /**
245  * struct zfcp_dbf - main dbf trace structure
246  * @pay: reference to payload trace area
247  * @rec: reference to recovery trace area
248  * @hba: reference to hba trace area
249  * @san: reference to san trace area
250  * @scsi: reference to scsi trace area
251  * @pay_lock: lock protecting payload trace buffer
252  * @rec_lock: lock protecting recovery trace buffer
253  * @hba_lock: lock protecting hba trace buffer
254  * @san_lock: lock protecting san trace buffer
255  * @scsi_lock: lock protecting scsi trace buffer
256  * @pay_buf: pre-allocated buffer for payload
257  * @rec_buf: pre-allocated buffer for recovery
258  * @hba_buf: pre-allocated buffer for hba
259  * @san_buf: pre-allocated buffer for san
260  * @scsi_buf: pre-allocated buffer for scsi
261  */
262 struct zfcp_dbf {
263 	debug_info_t			*pay;
264 	debug_info_t			*rec;
265 	debug_info_t			*hba;
266 	debug_info_t			*san;
267 	debug_info_t			*scsi;
268 	spinlock_t			pay_lock;
269 	spinlock_t			rec_lock;
270 	spinlock_t			hba_lock;
271 	spinlock_t			san_lock;
272 	spinlock_t			scsi_lock;
273 	struct zfcp_dbf_pay		pay_buf;
274 	struct zfcp_dbf_rec		rec_buf;
275 	struct zfcp_dbf_hba		hba_buf;
276 	struct zfcp_dbf_san		san_buf;
277 	struct zfcp_dbf_scsi		scsi_buf;
278 };
279 
280 static inline
zfcp_dbf_hba_fsf_resp(char * tag,int level,struct zfcp_fsf_req * req)281 void zfcp_dbf_hba_fsf_resp(char *tag, int level, struct zfcp_fsf_req *req)
282 {
283 	if (debug_level_enabled(req->adapter->dbf->hba, level))
284 		zfcp_dbf_hba_fsf_res(tag, req);
285 }
286 
287 /**
288  * zfcp_dbf_hba_fsf_response - trace event for request completion
289  * @req: request that has been completed
290  */
291 static inline
zfcp_dbf_hba_fsf_response(struct zfcp_fsf_req * req)292 void zfcp_dbf_hba_fsf_response(struct zfcp_fsf_req *req)
293 {
294 	struct fsf_qtcb *qtcb = req->qtcb;
295 
296 	if (unlikely(req->status & (ZFCP_STATUS_FSFREQ_DISMISSED |
297 				    ZFCP_STATUS_FSFREQ_ERROR))) {
298 		zfcp_dbf_hba_fsf_resp("fs_rerr", 3, req);
299 
300 	} else if ((qtcb->prefix.prot_status != FSF_PROT_GOOD) &&
301 	    (qtcb->prefix.prot_status != FSF_PROT_FSF_STATUS_PRESENTED)) {
302 		zfcp_dbf_hba_fsf_resp("fs_perr", 1, req);
303 
304 	} else if (qtcb->header.fsf_status != FSF_GOOD) {
305 		zfcp_dbf_hba_fsf_resp("fs_ferr", 1, req);
306 
307 	} else if ((req->fsf_command == FSF_QTCB_OPEN_PORT_WITH_DID) ||
308 		   (req->fsf_command == FSF_QTCB_OPEN_LUN)) {
309 		zfcp_dbf_hba_fsf_resp("fs_open", 4, req);
310 
311 	} else if (qtcb->header.log_length) {
312 		zfcp_dbf_hba_fsf_resp("fs_qtcb", 5, req);
313 
314 	} else {
315 		zfcp_dbf_hba_fsf_resp("fs_norm", 6, req);
316 	}
317 }
318 
319 static inline
_zfcp_dbf_scsi(char * tag,int level,struct scsi_cmnd * scmd,struct zfcp_fsf_req * req)320 void _zfcp_dbf_scsi(char *tag, int level, struct scsi_cmnd *scmd,
321 		   struct zfcp_fsf_req *req)
322 {
323 	struct zfcp_adapter *adapter = (struct zfcp_adapter *)
324 					scmd->device->host->hostdata[0];
325 
326 	if (debug_level_enabled(adapter->dbf->scsi, level))
327 		zfcp_dbf_scsi(tag, scmd, req);
328 }
329 
330 /**
331  * zfcp_dbf_scsi_result - trace event for SCSI command completion
332  * @scmd: SCSI command pointer
333  * @req: FSF request used to issue SCSI command
334  */
335 static inline
zfcp_dbf_scsi_result(struct scsi_cmnd * scmd,struct zfcp_fsf_req * req)336 void zfcp_dbf_scsi_result(struct scsi_cmnd *scmd, struct zfcp_fsf_req *req)
337 {
338 	if (scmd->result != 0)
339 		_zfcp_dbf_scsi("rsl_err", 3, scmd, req);
340 	else if (scmd->retries > 0)
341 		_zfcp_dbf_scsi("rsl_ret", 4, scmd, req);
342 	else
343 		_zfcp_dbf_scsi("rsl_nor", 6, scmd, req);
344 }
345 
346 /**
347  * zfcp_dbf_scsi_fail_send - trace event for failure to send SCSI command
348  * @scmd: SCSI command pointer
349  */
350 static inline
zfcp_dbf_scsi_fail_send(struct scsi_cmnd * scmd)351 void zfcp_dbf_scsi_fail_send(struct scsi_cmnd *scmd)
352 {
353 	_zfcp_dbf_scsi("rsl_fai", 4, scmd, NULL);
354 }
355 
356 /**
357  * zfcp_dbf_scsi_abort - trace event for SCSI command abort
358  * @tag: tag indicating success or failure of abort operation
359  * @scmd: SCSI command to be aborted
360  * @fsf_req: request containing abort (might be NULL)
361  */
362 static inline
zfcp_dbf_scsi_abort(char * tag,struct scsi_cmnd * scmd,struct zfcp_fsf_req * fsf_req)363 void zfcp_dbf_scsi_abort(char *tag, struct scsi_cmnd *scmd,
364 			 struct zfcp_fsf_req *fsf_req)
365 {
366 	_zfcp_dbf_scsi(tag, 1, scmd, fsf_req);
367 }
368 
369 /**
370  * zfcp_dbf_scsi_devreset - trace event for Logical Unit or Target Reset
371  * @tag: tag indicating success or failure of reset operation
372  * @scmnd: SCSI command which caused this error recovery
373  * @flag: indicates type of reset (Target Reset, Logical Unit Reset)
374  */
375 static inline
zfcp_dbf_scsi_devreset(char * tag,struct scsi_cmnd * scmnd,u8 flag)376 void zfcp_dbf_scsi_devreset(char *tag, struct scsi_cmnd *scmnd, u8 flag)
377 {
378 	char tmp_tag[ZFCP_DBF_TAG_LEN];
379 
380 	if (flag == FCP_TMF_TGT_RESET)
381 		memcpy(tmp_tag, "tr_", 3);
382 	else
383 		memcpy(tmp_tag, "lr_", 3);
384 
385 	memcpy(&tmp_tag[3], tag, 4);
386 	_zfcp_dbf_scsi(tmp_tag, 1, scmnd, NULL);
387 }
388 
389 #endif /* ZFCP_DBF_H */
390