1 /* SPDX-License-Identifier: GPL-2.0 */
4 * debug feature declarations
6 * Copyright IBM Corp. 2008, 2020
12 #include <scsi/fc/fc_fcp.h>
17 #define ZFCP_DBF_TAG_LEN 7
19 #define ZFCP_DBF_INVALID_WWPN 0x0000000000000000ull
20 #define ZFCP_DBF_INVALID_LUN 0xFFFFFFFFFFFFFFFFull
22 enum zfcp_dbf_pseudo_erp_act_type
{
23 ZFCP_PSEUDO_ERP_ACTION_RPORT_ADD
= 0xff,
24 ZFCP_PSEUDO_ERP_ACTION_RPORT_DEL
= 0xfe,
28 * struct zfcp_dbf_rec_trigger - trace record for triggered recovery action
29 * @ready: number of ready recovery actions
30 * @running: number of running recovery actions
31 * @want: wanted recovery action
32 * @need: needed recovery action
34 struct zfcp_dbf_rec_trigger
{
42 * struct zfcp_dbf_rec_running - trace record for running recovery
43 * @fsf_req_id: request id for fsf requests
44 * @rec_status: status of the fsf request
45 * @rec_step: current step of the recovery action
46 * @rec_action: ERP action type
47 * @rec_count: recoveries including retries for particular @rec_action
49 struct zfcp_dbf_rec_running
{
58 * enum zfcp_dbf_rec_id - recovery trace record id
59 * @ZFCP_DBF_REC_TRIG: triggered recovery identifier
60 * @ZFCP_DBF_REC_RUN: running recovery identifier
62 enum zfcp_dbf_rec_id
{
63 ZFCP_DBF_REC_TRIG
= 1,
68 * struct zfcp_dbf_rec - trace record for error recovery actions
69 * @id: unique number of recovery record type
70 * @tag: identifier string specifying the location of initiation
71 * @lun: logical unit number
72 * @wwpn: word wide port number
73 * @d_id: destination ID
74 * @adapter_status: current status of the adapter
75 * @port_status: current status of the port
76 * @lun_status: current status of the lun
77 * @u: record type specific data
78 * @u.trig: structure zfcp_dbf_rec_trigger
79 * @u.run: structure zfcp_dbf_rec_running
83 char tag
[ZFCP_DBF_TAG_LEN
];
91 struct zfcp_dbf_rec_trigger trig
;
92 struct zfcp_dbf_rec_running run
;
97 * enum zfcp_dbf_san_id - SAN trace record identifier
98 * @ZFCP_DBF_SAN_REQ: request trace record id
99 * @ZFCP_DBF_SAN_RES: response trace record id
100 * @ZFCP_DBF_SAN_ELS: extended link service record id
102 enum zfcp_dbf_san_id
{
103 ZFCP_DBF_SAN_REQ
= 1,
104 ZFCP_DBF_SAN_RES
= 2,
105 ZFCP_DBF_SAN_ELS
= 3,
108 /** struct zfcp_dbf_san - trace record for SAN requests and responses
109 * @id: unique number of recovery record type
110 * @tag: identifier string specifying the location of initiation
111 * @fsf_req_id: request id for fsf requests
112 * @payload: unformatted information related to request/response
113 * @d_id: destination id
115 struct zfcp_dbf_san
{
117 char tag
[ZFCP_DBF_TAG_LEN
];
120 #define ZFCP_DBF_SAN_MAX_PAYLOAD (FC_CT_HDR_LEN + 32)
121 char payload
[ZFCP_DBF_SAN_MAX_PAYLOAD
];
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 * @port_handle: handle for port
133 * @lun_handle: handle for LUN
135 struct zfcp_dbf_hba_res
{
138 u8 prot_status_qual
[FSF_PROT_STATUS_QUAL_SIZE
];
140 u8 fsf_status_qual
[FSF_STATUS_QUALIFIER_SIZE
];
146 * struct zfcp_dbf_hba_uss - trace record for unsolicited status
147 * @status_type: type of unsolicited status
148 * @status_subtype: subtype of unsolicited status
149 * @d_id: destination ID
150 * @lun: logical unit number
151 * @queue_designator: queue designator
153 struct zfcp_dbf_hba_uss
{
158 u64 queue_designator
;
162 * struct zfcp_dbf_hba_fces - trace record for FC Endpoint Security
163 * @req_issued: timestamp when request was issued
164 * @fsf_status: fsf status
165 * @port_handle: handle for port
166 * @wwpn: remote FC port WWPN
167 * @fc_security_old: old FC Endpoint Security
168 * @fc_security_new: new FC Endpoint Security
171 struct zfcp_dbf_hba_fces
{
181 * enum zfcp_dbf_hba_id - HBA trace record identifier
182 * @ZFCP_DBF_HBA_RES: response trace record
183 * @ZFCP_DBF_HBA_USS: unsolicited status trace record
184 * @ZFCP_DBF_HBA_BIT: bit error trace record
185 * @ZFCP_DBF_HBA_BASIC: basic adapter event, only trace tag, no other data
186 * @ZFCP_DBF_HBA_FCES: FC Endpoint Security trace record
188 enum zfcp_dbf_hba_id
{
189 ZFCP_DBF_HBA_RES
= 1,
190 ZFCP_DBF_HBA_USS
= 2,
191 ZFCP_DBF_HBA_BIT
= 3,
192 ZFCP_DBF_HBA_BASIC
= 4,
193 ZFCP_DBF_HBA_FCES
= 5,
197 * struct zfcp_dbf_hba - common trace record for HBA records
198 * @id: unique number of recovery record type
199 * @tag: identifier string specifying the location of initiation
200 * @fsf_req_id: request id for fsf requests
201 * @fsf_req_status: status of fsf request
202 * @fsf_cmd: fsf command
203 * @fsf_seq_no: fsf sequence number
204 * @pl_len: length of payload stored as zfcp_dbf_pay
205 * @u: record type specific data
206 * @u.res: data for fsf responses
207 * @u.uss: data for unsolicited status buffer
208 * @u.be: data for bit error unsolicited status buffer
209 * @u.fces: data for FC Endpoint Security
211 struct zfcp_dbf_hba
{
213 char tag
[ZFCP_DBF_TAG_LEN
];
220 struct zfcp_dbf_hba_res res
;
221 struct zfcp_dbf_hba_uss uss
;
222 struct fsf_bit_error_payload be
;
223 struct zfcp_dbf_hba_fces fces
;
228 * enum zfcp_dbf_scsi_id - scsi trace record identifier
229 * @ZFCP_DBF_SCSI_CMND: scsi command trace record
231 enum zfcp_dbf_scsi_id
{
232 ZFCP_DBF_SCSI_CMND
= 1,
236 * struct zfcp_dbf_scsi - common trace record for SCSI records
237 * @id: unique number of recovery record type
238 * @tag: identifier string specifying the location of initiation
239 * @scsi_id: scsi device id
240 * @scsi_lun: scsi device logical unit number, low part of 64 bit, old 32 bit
241 * @scsi_result: scsi result
242 * @scsi_retries: current retry number of scsi request
243 * @scsi_allowed: allowed retries
244 * @fcp_rsp_info: FCP response info code
245 * @scsi_opcode: scsi opcode
246 * @fsf_req_id: request id of fsf request
247 * @host_scribble: LLD specific data attached to SCSI request
248 * @pl_len: length of payload stored as zfcp_dbf_pay
249 * @fcp_rsp: response for FCP request
250 * @scsi_lun_64_hi: scsi device logical unit number, high part of 64 bit
252 struct zfcp_dbf_scsi
{
254 char tag
[ZFCP_DBF_TAG_LEN
];
261 #define ZFCP_DBF_SCSI_OPCODE 16
262 u8 scsi_opcode
[ZFCP_DBF_SCSI_OPCODE
];
266 struct fcp_resp_with_ext fcp_rsp
;
271 * struct zfcp_dbf_pay - trace record for unformatted payload information
272 * @area: area this record is originated from
273 * @counter: ascending record number
274 * @fsf_req_id: request id of fsf request
275 * @data: unformatted data
277 struct zfcp_dbf_pay
{
279 char area
[ZFCP_DBF_TAG_LEN
];
281 #define ZFCP_DBF_PAY_MAX_REC 0x100
282 char data
[ZFCP_DBF_PAY_MAX_REC
];
286 * struct zfcp_dbf - main dbf trace structure
287 * @pay: reference to payload trace area
288 * @rec: reference to recovery trace area
289 * @hba: reference to hba trace area
290 * @san: reference to san trace area
291 * @scsi: reference to scsi trace area
292 * @pay_lock: lock protecting payload trace buffer
293 * @rec_lock: lock protecting recovery trace buffer
294 * @hba_lock: lock protecting hba trace buffer
295 * @san_lock: lock protecting san trace buffer
296 * @scsi_lock: lock protecting scsi trace buffer
297 * @pay_buf: pre-allocated buffer for payload
298 * @rec_buf: pre-allocated buffer for recovery
299 * @hba_buf: pre-allocated buffer for hba
300 * @san_buf: pre-allocated buffer for san
301 * @scsi_buf: pre-allocated buffer for scsi
313 spinlock_t scsi_lock
;
314 struct zfcp_dbf_pay pay_buf
;
315 struct zfcp_dbf_rec rec_buf
;
316 struct zfcp_dbf_hba hba_buf
;
317 struct zfcp_dbf_san san_buf
;
318 struct zfcp_dbf_scsi scsi_buf
;
322 * zfcp_dbf_hba_fsf_resp_suppress - true if we should not trace by default
323 * @req: request that has been completed
325 * Returns true if FCP response with only benign residual under count.
328 bool zfcp_dbf_hba_fsf_resp_suppress(struct zfcp_fsf_req
*req
)
330 struct fsf_qtcb
*qtcb
= req
->qtcb
;
331 u32 fsf_stat
= qtcb
->header
.fsf_status
;
332 struct fcp_resp
*fcp_rsp
;
333 u8 rsp_flags
, fr_status
;
335 if (qtcb
->prefix
.qtcb_type
!= FSF_IO_COMMAND
)
336 return false; /* not an FCP response */
337 fcp_rsp
= &qtcb
->bottom
.io
.fcp_rsp
.iu
.resp
;
338 rsp_flags
= fcp_rsp
->fr_flags
;
339 fr_status
= fcp_rsp
->fr_status
;
340 return (fsf_stat
== FSF_FCP_RSP_AVAILABLE
) &&
341 (rsp_flags
== FCP_RESID_UNDER
) &&
342 (fr_status
== SAM_STAT_GOOD
);
346 void zfcp_dbf_hba_fsf_resp(char *tag
, int level
, struct zfcp_fsf_req
*req
)
348 if (debug_level_enabled(req
->adapter
->dbf
->hba
, level
))
349 zfcp_dbf_hba_fsf_res(tag
, level
, req
);
353 * zfcp_dbf_hba_fsf_response - trace event for request completion
354 * @req: request that has been completed
357 void zfcp_dbf_hba_fsf_response(struct zfcp_fsf_req
*req
)
359 struct fsf_qtcb
*qtcb
= req
->qtcb
;
361 if (unlikely(req
->status
& (ZFCP_STATUS_FSFREQ_DISMISSED
|
362 ZFCP_STATUS_FSFREQ_ERROR
))) {
363 zfcp_dbf_hba_fsf_resp("fs_rerr", 3, req
);
365 } else if ((qtcb
->prefix
.prot_status
!= FSF_PROT_GOOD
) &&
366 (qtcb
->prefix
.prot_status
!= FSF_PROT_FSF_STATUS_PRESENTED
)) {
367 zfcp_dbf_hba_fsf_resp("fs_perr", 1, req
);
369 } else if (qtcb
->header
.fsf_status
!= FSF_GOOD
) {
370 zfcp_dbf_hba_fsf_resp("fs_ferr",
371 zfcp_dbf_hba_fsf_resp_suppress(req
)
374 } else if ((qtcb
->header
.fsf_command
== FSF_QTCB_OPEN_PORT_WITH_DID
) ||
375 (qtcb
->header
.fsf_command
== FSF_QTCB_OPEN_LUN
)) {
376 zfcp_dbf_hba_fsf_resp("fs_open", 4, req
);
378 } else if (qtcb
->header
.log_length
) {
379 zfcp_dbf_hba_fsf_resp("fs_qtcb", 5, req
);
382 zfcp_dbf_hba_fsf_resp("fs_norm", 6, req
);
387 void _zfcp_dbf_scsi(char *tag
, int level
, struct scsi_cmnd
*scmd
,
388 struct zfcp_fsf_req
*req
)
390 struct zfcp_adapter
*adapter
= (struct zfcp_adapter
*)
391 scmd
->device
->host
->hostdata
[0];
393 if (debug_level_enabled(adapter
->dbf
->scsi
, level
))
394 zfcp_dbf_scsi_common(tag
, level
, scmd
->device
, scmd
, req
);
398 * zfcp_dbf_scsi_result - trace event for SCSI command completion
399 * @scmd: SCSI command pointer
400 * @req: FSF request used to issue SCSI command
403 void zfcp_dbf_scsi_result(struct scsi_cmnd
*scmd
, struct zfcp_fsf_req
*req
)
405 if (scmd
->result
!= 0)
406 _zfcp_dbf_scsi("rsl_err", 3, scmd
, req
);
407 else if (scmd
->retries
> 0)
408 _zfcp_dbf_scsi("rsl_ret", 4, scmd
, req
);
410 _zfcp_dbf_scsi("rsl_nor", 6, scmd
, req
);
414 * zfcp_dbf_scsi_fail_send - trace event for failure to send SCSI command
415 * @scmd: SCSI command pointer
418 void zfcp_dbf_scsi_fail_send(struct scsi_cmnd
*scmd
)
420 _zfcp_dbf_scsi("rsl_fai", 4, scmd
, NULL
);
424 * zfcp_dbf_scsi_abort - trace event for SCSI command abort
425 * @tag: tag indicating success or failure of abort operation
426 * @scmd: SCSI command to be aborted
427 * @fsf_req: request containing abort (might be NULL)
430 void zfcp_dbf_scsi_abort(char *tag
, struct scsi_cmnd
*scmd
,
431 struct zfcp_fsf_req
*fsf_req
)
433 _zfcp_dbf_scsi(tag
, 1, scmd
, fsf_req
);
437 * zfcp_dbf_scsi_devreset() - Trace event for Logical Unit or Target Reset.
438 * @tag: Tag indicating success or failure of reset operation.
439 * @sdev: Pointer to SCSI device as context for this event.
440 * @flag: Indicates type of reset (Target Reset, Logical Unit Reset).
441 * @fsf_req: Pointer to FSF request representing the TMF, or NULL.
444 void zfcp_dbf_scsi_devreset(char *tag
, struct scsi_device
*sdev
, u8 flag
,
445 struct zfcp_fsf_req
*fsf_req
)
447 struct zfcp_adapter
*adapter
= (struct zfcp_adapter
*)
448 sdev
->host
->hostdata
[0];
449 char tmp_tag
[ZFCP_DBF_TAG_LEN
];
450 static int const level
= 1;
452 if (unlikely(!debug_level_enabled(adapter
->dbf
->scsi
, level
)))
455 if (flag
== FCP_TMF_TGT_RESET
)
456 memcpy(tmp_tag
, "tr_", 3);
458 memcpy(tmp_tag
, "lr_", 3);
460 memcpy(&tmp_tag
[3], tag
, 4);
461 zfcp_dbf_scsi_common(tmp_tag
, level
, sdev
, NULL
, fsf_req
);
465 * zfcp_dbf_scsi_nullcmnd() - trace NULLify of SCSI command in dev/tgt-reset.
466 * @scmnd: SCSI command that was NULLified.
467 * @fsf_req: request that owned @scmnd.
469 static inline void zfcp_dbf_scsi_nullcmnd(struct scsi_cmnd
*scmnd
,
470 struct zfcp_fsf_req
*fsf_req
)
472 _zfcp_dbf_scsi("scfc__1", 3, scmnd
, fsf_req
);
475 #endif /* ZFCP_DBF_H */