1 /* SPDX-License-Identifier: GPL-2.0 */
4 * debug feature declarations
6 * Copyright IBM Corp. 2008, 2017
12 #include <scsi/fc/fc_fcp.h>
17 #define ZFCP_DBF_TAG_LEN 7
19 #define ZFCP_DBF_INVALID_LUN 0xFFFFFFFFFFFFFFFFull
21 enum zfcp_dbf_pseudo_erp_act_type
{
22 ZFCP_PSEUDO_ERP_ACTION_RPORT_ADD
= 0xff,
23 ZFCP_PSEUDO_ERP_ACTION_RPORT_DEL
= 0xfe,
27 * struct zfcp_dbf_rec_trigger - trace record for triggered recovery action
28 * @ready: number of ready recovery actions
29 * @running: number of running recovery actions
30 * @want: wanted recovery action
31 * @need: needed recovery action
33 struct zfcp_dbf_rec_trigger
{
41 * struct zfcp_dbf_rec_running - trace record for running recovery
42 * @fsf_req_id: request id for fsf requests
43 * @rec_status: status of the fsf request
44 * @rec_step: current step of the recovery action
45 * rec_count: recovery counter
47 struct zfcp_dbf_rec_running
{
56 * enum zfcp_dbf_rec_id - recovery trace record id
57 * @ZFCP_DBF_REC_TRIG: triggered recovery identifier
58 * @ZFCP_DBF_REC_RUN: running recovery identifier
60 enum zfcp_dbf_rec_id
{
61 ZFCP_DBF_REC_TRIG
= 1,
66 * struct zfcp_dbf_rec - trace record for error recovery actions
67 * @id: unique number of recovery record type
68 * @tag: identifier string specifying the location of initiation
69 * @lun: logical unit number
70 * @wwpn: word wide port number
71 * @d_id: destination ID
72 * @adapter_status: current status of the adapter
73 * @port_status: current status of the port
74 * @lun_status: current status of the lun
75 * @u.trig: structure zfcp_dbf_rec_trigger
76 * @u.run: structure zfcp_dbf_rec_running
80 char tag
[ZFCP_DBF_TAG_LEN
];
88 struct zfcp_dbf_rec_trigger trig
;
89 struct zfcp_dbf_rec_running run
;
94 * enum zfcp_dbf_san_id - SAN trace record identifier
95 * @ZFCP_DBF_SAN_REQ: request trace record id
96 * @ZFCP_DBF_SAN_RES: response trace record id
97 * @ZFCP_DBF_SAN_ELS: extended link service record id
99 enum zfcp_dbf_san_id
{
100 ZFCP_DBF_SAN_REQ
= 1,
101 ZFCP_DBF_SAN_RES
= 2,
102 ZFCP_DBF_SAN_ELS
= 3,
105 /** struct zfcp_dbf_san - trace record for SAN requests and responses
106 * @id: unique number of recovery record type
107 * @tag: identifier string specifying the location of initiation
108 * @fsf_req_id: request id for fsf requests
109 * @payload: unformatted information related to request/response
110 * @d_id: destination id
112 struct zfcp_dbf_san
{
114 char tag
[ZFCP_DBF_TAG_LEN
];
117 #define ZFCP_DBF_SAN_MAX_PAYLOAD (FC_CT_HDR_LEN + 32)
118 char payload
[ZFCP_DBF_SAN_MAX_PAYLOAD
];
123 * struct zfcp_dbf_hba_res - trace record for hba responses
124 * @req_issued: timestamp when request was issued
125 * @prot_status: protocol status
126 * @prot_status_qual: protocol status qualifier
127 * @fsf_status: fsf status
128 * @fsf_status_qual: fsf status qualifier
130 struct zfcp_dbf_hba_res
{
133 u8 prot_status_qual
[FSF_PROT_STATUS_QUAL_SIZE
];
135 u8 fsf_status_qual
[FSF_STATUS_QUALIFIER_SIZE
];
141 * struct zfcp_dbf_hba_uss - trace record for unsolicited status
142 * @status_type: type of unsolicited status
143 * @status_subtype: subtype of unsolicited status
144 * @d_id: destination ID
145 * @lun: logical unit number
146 * @queue_designator: queue designator
148 struct zfcp_dbf_hba_uss
{
153 u64 queue_designator
;
157 * enum zfcp_dbf_hba_id - HBA trace record identifier
158 * @ZFCP_DBF_HBA_RES: response trace record
159 * @ZFCP_DBF_HBA_USS: unsolicited status trace record
160 * @ZFCP_DBF_HBA_BIT: bit error trace record
162 enum zfcp_dbf_hba_id
{
163 ZFCP_DBF_HBA_RES
= 1,
164 ZFCP_DBF_HBA_USS
= 2,
165 ZFCP_DBF_HBA_BIT
= 3,
166 ZFCP_DBF_HBA_BASIC
= 4,
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
180 struct zfcp_dbf_hba
{
182 char tag
[ZFCP_DBF_TAG_LEN
];
189 struct zfcp_dbf_hba_res res
;
190 struct zfcp_dbf_hba_uss uss
;
191 struct fsf_bit_error_payload be
;
196 * enum zfcp_dbf_scsi_id - scsi trace record identifier
197 * @ZFCP_DBF_SCSI_CMND: scsi command trace record
199 enum zfcp_dbf_scsi_id
{
200 ZFCP_DBF_SCSI_CMND
= 1,
204 * struct zfcp_dbf_scsi - common trace record for SCSI records
205 * @id: unique number of recovery record type
206 * @tag: identifier string specifying the location of initiation
207 * @scsi_id: scsi device id
208 * @scsi_lun: scsi device logical unit number, low part of 64 bit, old 32 bit
209 * @scsi_result: scsi result
210 * @scsi_retries: current retry number of scsi request
211 * @scsi_allowed: allowed retries
212 * @fcp_rsp_info: FCP response info code
213 * @scsi_opcode: scsi opcode
214 * @fsf_req_id: request id of fsf request
215 * @host_scribble: LLD specific data attached to SCSI request
216 * @pl_len: length of payload stored as zfcp_dbf_pay
217 * @fcp_rsp: response for FCP request
218 * @scsi_lun_64_hi: scsi device logical unit number, high part of 64 bit
220 struct zfcp_dbf_scsi
{
222 char tag
[ZFCP_DBF_TAG_LEN
];
229 #define ZFCP_DBF_SCSI_OPCODE 16
230 u8 scsi_opcode
[ZFCP_DBF_SCSI_OPCODE
];
234 struct fcp_resp_with_ext fcp_rsp
;
239 * struct zfcp_dbf_pay - trace record for unformatted payload information
240 * @area: area this record is originated from
241 * @counter: ascending record number
242 * @fsf_req_id: request id of fsf request
243 * @data: unformatted data
245 struct zfcp_dbf_pay
{
247 char area
[ZFCP_DBF_TAG_LEN
];
249 #define ZFCP_DBF_PAY_MAX_REC 0x100
250 char data
[ZFCP_DBF_PAY_MAX_REC
];
254 * struct zfcp_dbf - main dbf trace structure
255 * @pay: reference to payload trace area
256 * @rec: reference to recovery trace area
257 * @hba: reference to hba trace area
258 * @san: reference to san trace area
259 * @scsi: reference to scsi trace area
260 * @pay_lock: lock protecting payload trace buffer
261 * @rec_lock: lock protecting recovery trace buffer
262 * @hba_lock: lock protecting hba trace buffer
263 * @san_lock: lock protecting san trace buffer
264 * @scsi_lock: lock protecting scsi trace buffer
265 * @pay_buf: pre-allocated buffer for payload
266 * @rec_buf: pre-allocated buffer for recovery
267 * @hba_buf: pre-allocated buffer for hba
268 * @san_buf: pre-allocated buffer for san
269 * @scsi_buf: pre-allocated buffer for scsi
281 spinlock_t scsi_lock
;
282 struct zfcp_dbf_pay pay_buf
;
283 struct zfcp_dbf_rec rec_buf
;
284 struct zfcp_dbf_hba hba_buf
;
285 struct zfcp_dbf_san san_buf
;
286 struct zfcp_dbf_scsi scsi_buf
;
290 * zfcp_dbf_hba_fsf_resp_suppress - true if we should not trace by default
291 * @req: request that has been completed
293 * Returns true if FCP response with only benign residual under count.
296 bool zfcp_dbf_hba_fsf_resp_suppress(struct zfcp_fsf_req
*req
)
298 struct fsf_qtcb
*qtcb
= req
->qtcb
;
299 u32 fsf_stat
= qtcb
->header
.fsf_status
;
300 struct fcp_resp
*fcp_rsp
;
301 u8 rsp_flags
, fr_status
;
303 if (qtcb
->prefix
.qtcb_type
!= FSF_IO_COMMAND
)
304 return false; /* not an FCP response */
305 fcp_rsp
= &qtcb
->bottom
.io
.fcp_rsp
.iu
.resp
;
306 rsp_flags
= fcp_rsp
->fr_flags
;
307 fr_status
= fcp_rsp
->fr_status
;
308 return (fsf_stat
== FSF_FCP_RSP_AVAILABLE
) &&
309 (rsp_flags
== FCP_RESID_UNDER
) &&
310 (fr_status
== SAM_STAT_GOOD
);
314 void zfcp_dbf_hba_fsf_resp(char *tag
, int level
, struct zfcp_fsf_req
*req
)
316 if (debug_level_enabled(req
->adapter
->dbf
->hba
, level
))
317 zfcp_dbf_hba_fsf_res(tag
, level
, req
);
321 * zfcp_dbf_hba_fsf_response - trace event for request completion
322 * @req: request that has been completed
325 void zfcp_dbf_hba_fsf_response(struct zfcp_fsf_req
*req
)
327 struct fsf_qtcb
*qtcb
= req
->qtcb
;
329 if (unlikely(req
->status
& (ZFCP_STATUS_FSFREQ_DISMISSED
|
330 ZFCP_STATUS_FSFREQ_ERROR
))) {
331 zfcp_dbf_hba_fsf_resp("fs_rerr", 3, req
);
333 } else if ((qtcb
->prefix
.prot_status
!= FSF_PROT_GOOD
) &&
334 (qtcb
->prefix
.prot_status
!= FSF_PROT_FSF_STATUS_PRESENTED
)) {
335 zfcp_dbf_hba_fsf_resp("fs_perr", 1, req
);
337 } else if (qtcb
->header
.fsf_status
!= FSF_GOOD
) {
338 zfcp_dbf_hba_fsf_resp("fs_ferr",
339 zfcp_dbf_hba_fsf_resp_suppress(req
)
342 } else if ((req
->fsf_command
== FSF_QTCB_OPEN_PORT_WITH_DID
) ||
343 (req
->fsf_command
== FSF_QTCB_OPEN_LUN
)) {
344 zfcp_dbf_hba_fsf_resp("fs_open", 4, req
);
346 } else if (qtcb
->header
.log_length
) {
347 zfcp_dbf_hba_fsf_resp("fs_qtcb", 5, req
);
350 zfcp_dbf_hba_fsf_resp("fs_norm", 6, req
);
355 void _zfcp_dbf_scsi(char *tag
, int level
, struct scsi_cmnd
*scmd
,
356 struct zfcp_fsf_req
*req
)
358 struct zfcp_adapter
*adapter
= (struct zfcp_adapter
*)
359 scmd
->device
->host
->hostdata
[0];
361 if (debug_level_enabled(adapter
->dbf
->scsi
, level
))
362 zfcp_dbf_scsi_common(tag
, level
, scmd
->device
, scmd
, req
);
366 * zfcp_dbf_scsi_result - trace event for SCSI command completion
367 * @scmd: SCSI command pointer
368 * @req: FSF request used to issue SCSI command
371 void zfcp_dbf_scsi_result(struct scsi_cmnd
*scmd
, struct zfcp_fsf_req
*req
)
373 if (scmd
->result
!= 0)
374 _zfcp_dbf_scsi("rsl_err", 3, scmd
, req
);
375 else if (scmd
->retries
> 0)
376 _zfcp_dbf_scsi("rsl_ret", 4, scmd
, req
);
378 _zfcp_dbf_scsi("rsl_nor", 6, scmd
, req
);
382 * zfcp_dbf_scsi_fail_send - trace event for failure to send SCSI command
383 * @scmd: SCSI command pointer
386 void zfcp_dbf_scsi_fail_send(struct scsi_cmnd
*scmd
)
388 _zfcp_dbf_scsi("rsl_fai", 4, scmd
, NULL
);
392 * zfcp_dbf_scsi_abort - trace event for SCSI command abort
393 * @tag: tag indicating success or failure of abort operation
394 * @scmd: SCSI command to be aborted
395 * @fsf_req: request containing abort (might be NULL)
398 void zfcp_dbf_scsi_abort(char *tag
, struct scsi_cmnd
*scmd
,
399 struct zfcp_fsf_req
*fsf_req
)
401 _zfcp_dbf_scsi(tag
, 1, scmd
, fsf_req
);
405 * zfcp_dbf_scsi_devreset() - Trace event for Logical Unit or Target Reset.
406 * @tag: Tag indicating success or failure of reset operation.
407 * @sdev: Pointer to SCSI device as context for this event.
408 * @flag: Indicates type of reset (Target Reset, Logical Unit Reset).
409 * @fsf_req: Pointer to FSF request representing the TMF, or NULL.
412 void zfcp_dbf_scsi_devreset(char *tag
, struct scsi_device
*sdev
, u8 flag
,
413 struct zfcp_fsf_req
*fsf_req
)
415 struct zfcp_adapter
*adapter
= (struct zfcp_adapter
*)
416 sdev
->host
->hostdata
[0];
417 char tmp_tag
[ZFCP_DBF_TAG_LEN
];
418 static int const level
= 1;
420 if (unlikely(!debug_level_enabled(adapter
->dbf
->scsi
, level
)))
423 if (flag
== FCP_TMF_TGT_RESET
)
424 memcpy(tmp_tag
, "tr_", 3);
426 memcpy(tmp_tag
, "lr_", 3);
428 memcpy(&tmp_tag
[3], tag
, 4);
429 zfcp_dbf_scsi_common(tmp_tag
, level
, sdev
, NULL
, fsf_req
);
433 * zfcp_dbf_scsi_nullcmnd() - trace NULLify of SCSI command in dev/tgt-reset.
434 * @scmnd: SCSI command that was NULLified.
435 * @fsf_req: request that owned @scmnd.
437 static inline void zfcp_dbf_scsi_nullcmnd(struct scsi_cmnd
*scmnd
,
438 struct zfcp_fsf_req
*fsf_req
)
440 _zfcp_dbf_scsi("scfc__1", 3, scmnd
, fsf_req
);
443 #endif /* ZFCP_DBF_H */