Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  * zfcp device driver
0004  * debug feature declarations
0005  *
0006  * Copyright IBM Corp. 2008, 2020
0007  */
0008 
0009 #ifndef ZFCP_DBF_H
0010 #define ZFCP_DBF_H
0011 
0012 #include <scsi/fc/fc_fcp.h>
0013 #include "zfcp_ext.h"
0014 #include "zfcp_fsf.h"
0015 #include "zfcp_def.h"
0016 
0017 #define ZFCP_DBF_TAG_LEN       7
0018 
0019 #define ZFCP_DBF_INVALID_WWPN   0x0000000000000000ull
0020 #define ZFCP_DBF_INVALID_LUN    0xFFFFFFFFFFFFFFFFull
0021 
0022 enum zfcp_dbf_pseudo_erp_act_type {
0023     ZFCP_PSEUDO_ERP_ACTION_RPORT_ADD = 0xff,
0024     ZFCP_PSEUDO_ERP_ACTION_RPORT_DEL = 0xfe,
0025 };
0026 
0027 /**
0028  * struct zfcp_dbf_rec_trigger - trace record for triggered recovery action
0029  * @ready: number of ready recovery actions
0030  * @running: number of running recovery actions
0031  * @want: wanted recovery action
0032  * @need: needed recovery action
0033  */
0034 struct zfcp_dbf_rec_trigger {
0035     u32 ready;
0036     u32 running;
0037     u8 want;
0038     u8 need;
0039 } __packed;
0040 
0041 /**
0042  * struct zfcp_dbf_rec_running - trace record for running recovery
0043  * @fsf_req_id: request id for fsf requests
0044  * @rec_status: status of the fsf request
0045  * @rec_step: current step of the recovery action
0046  * @rec_action: ERP action type
0047  * @rec_count: recoveries including retries for particular @rec_action
0048  */
0049 struct zfcp_dbf_rec_running {
0050     u64 fsf_req_id;
0051     u32 rec_status;
0052     u16 rec_step;
0053     u8 rec_action;
0054     u8 rec_count;
0055 } __packed;
0056 
0057 /**
0058  * enum zfcp_dbf_rec_id - recovery trace record id
0059  * @ZFCP_DBF_REC_TRIG: triggered recovery identifier
0060  * @ZFCP_DBF_REC_RUN: running recovery identifier
0061  */
0062 enum zfcp_dbf_rec_id {
0063     ZFCP_DBF_REC_TRIG   = 1,
0064     ZFCP_DBF_REC_RUN    = 2,
0065 };
0066 
0067 /**
0068  * struct zfcp_dbf_rec - trace record for error recovery actions
0069  * @id: unique number of recovery record type
0070  * @tag: identifier string specifying the location of initiation
0071  * @lun: logical unit number
0072  * @wwpn: word wide port number
0073  * @d_id: destination ID
0074  * @adapter_status: current status of the adapter
0075  * @port_status: current status of the port
0076  * @lun_status: current status of the lun
0077  * @u: record type specific data
0078  * @u.trig: structure zfcp_dbf_rec_trigger
0079  * @u.run: structure zfcp_dbf_rec_running
0080  */
0081 struct zfcp_dbf_rec {
0082     u8 id;
0083     char tag[ZFCP_DBF_TAG_LEN];
0084     u64 lun;
0085     u64 wwpn;
0086     u32 d_id;
0087     u32 adapter_status;
0088     u32 port_status;
0089     u32 lun_status;
0090     union {
0091         struct zfcp_dbf_rec_trigger trig;
0092         struct zfcp_dbf_rec_running run;
0093     } u;
0094 } __packed;
0095 
0096 /**
0097  * enum zfcp_dbf_san_id - SAN trace record identifier
0098  * @ZFCP_DBF_SAN_REQ: request trace record id
0099  * @ZFCP_DBF_SAN_RES: response trace record id
0100  * @ZFCP_DBF_SAN_ELS: extended link service record id
0101  */
0102 enum zfcp_dbf_san_id {
0103     ZFCP_DBF_SAN_REQ    = 1,
0104     ZFCP_DBF_SAN_RES    = 2,
0105     ZFCP_DBF_SAN_ELS    = 3,
0106 };
0107 
0108 /** struct zfcp_dbf_san - trace record for SAN requests and responses
0109  * @id: unique number of recovery record type
0110  * @tag: identifier string specifying the location of initiation
0111  * @fsf_req_id: request id for fsf requests
0112  * @payload: unformatted information related to request/response
0113  * @d_id: destination id
0114  */
0115 struct zfcp_dbf_san {
0116     u8 id;
0117     char tag[ZFCP_DBF_TAG_LEN];
0118     u64 fsf_req_id;
0119     u32 d_id;
0120 #define ZFCP_DBF_SAN_MAX_PAYLOAD (FC_CT_HDR_LEN + 32)
0121     char payload[ZFCP_DBF_SAN_MAX_PAYLOAD];
0122     u16 pl_len;
0123 } __packed;
0124 
0125 /**
0126  * struct zfcp_dbf_hba_res - trace record for hba responses
0127  * @req_issued: timestamp when request was issued
0128  * @prot_status: protocol status
0129  * @prot_status_qual: protocol status qualifier
0130  * @fsf_status: fsf status
0131  * @fsf_status_qual: fsf status qualifier
0132  * @port_handle: handle for port
0133  * @lun_handle: handle for LUN
0134  */
0135 struct zfcp_dbf_hba_res {
0136     u64 req_issued;
0137     u32 prot_status;
0138     u8  prot_status_qual[FSF_PROT_STATUS_QUAL_SIZE];
0139     u32 fsf_status;
0140     u8  fsf_status_qual[FSF_STATUS_QUALIFIER_SIZE];
0141     u32 port_handle;
0142     u32 lun_handle;
0143 } __packed;
0144 
0145 /**
0146  * struct zfcp_dbf_hba_uss - trace record for unsolicited status
0147  * @status_type: type of unsolicited status
0148  * @status_subtype: subtype of unsolicited status
0149  * @d_id: destination ID
0150  * @lun: logical unit number
0151  * @queue_designator: queue designator
0152  */
0153 struct zfcp_dbf_hba_uss {
0154     u32 status_type;
0155     u32 status_subtype;
0156     u32 d_id;
0157     u64 lun;
0158     u64 queue_designator;
0159 } __packed;
0160 
0161 /**
0162  * struct zfcp_dbf_hba_fces - trace record for FC Endpoint Security
0163  * @req_issued: timestamp when request was issued
0164  * @fsf_status: fsf status
0165  * @port_handle: handle for port
0166  * @wwpn: remote FC port WWPN
0167  * @fc_security_old: old FC Endpoint Security
0168  * @fc_security_new: new FC Endpoint Security
0169  *
0170  */
0171 struct zfcp_dbf_hba_fces {
0172     u64 req_issued;
0173     u32 fsf_status;
0174     u32 port_handle;
0175     u64 wwpn;
0176     u32 fc_security_old;
0177     u32 fc_security_new;
0178 } __packed;
0179 
0180 /**
0181  * enum zfcp_dbf_hba_id - HBA trace record identifier
0182  * @ZFCP_DBF_HBA_RES: response trace record
0183  * @ZFCP_DBF_HBA_USS: unsolicited status trace record
0184  * @ZFCP_DBF_HBA_BIT: bit error trace record
0185  * @ZFCP_DBF_HBA_BASIC: basic adapter event, only trace tag, no other data
0186  * @ZFCP_DBF_HBA_FCES: FC Endpoint Security trace record
0187  */
0188 enum zfcp_dbf_hba_id {
0189     ZFCP_DBF_HBA_RES    = 1,
0190     ZFCP_DBF_HBA_USS    = 2,
0191     ZFCP_DBF_HBA_BIT    = 3,
0192     ZFCP_DBF_HBA_BASIC  = 4,
0193     ZFCP_DBF_HBA_FCES   = 5,
0194 };
0195 
0196 /**
0197  * struct zfcp_dbf_hba - common trace record for HBA records
0198  * @id: unique number of recovery record type
0199  * @tag: identifier string specifying the location of initiation
0200  * @fsf_req_id: request id for fsf requests
0201  * @fsf_req_status: status of fsf request
0202  * @fsf_cmd: fsf command
0203  * @fsf_seq_no: fsf sequence number
0204  * @pl_len: length of payload stored as zfcp_dbf_pay
0205  * @u: record type specific data
0206  * @u.res:  data for fsf responses
0207  * @u.uss:  data for unsolicited status buffer
0208  * @u.be:   data for bit error unsolicited status buffer
0209  * @u.fces: data for FC Endpoint Security
0210  */
0211 struct zfcp_dbf_hba {
0212     u8 id;
0213     char tag[ZFCP_DBF_TAG_LEN];
0214     u64 fsf_req_id;
0215     u32 fsf_req_status;
0216     u32 fsf_cmd;
0217     u32 fsf_seq_no;
0218     u16 pl_len;
0219     union {
0220         struct zfcp_dbf_hba_res res;
0221         struct zfcp_dbf_hba_uss uss;
0222         struct fsf_bit_error_payload be;
0223         struct zfcp_dbf_hba_fces fces;
0224     } u;
0225 } __packed;
0226 
0227 /**
0228  * enum zfcp_dbf_scsi_id - scsi trace record identifier
0229  * @ZFCP_DBF_SCSI_CMND: scsi command trace record
0230  */
0231 enum zfcp_dbf_scsi_id {
0232     ZFCP_DBF_SCSI_CMND  = 1,
0233 };
0234 
0235 /**
0236  * struct zfcp_dbf_scsi - common trace record for SCSI records
0237  * @id: unique number of recovery record type
0238  * @tag: identifier string specifying the location of initiation
0239  * @scsi_id: scsi device id
0240  * @scsi_lun: scsi device logical unit number, low part of 64 bit, old 32 bit
0241  * @scsi_result: scsi result
0242  * @scsi_retries: current retry number of scsi request
0243  * @scsi_allowed: allowed retries
0244  * @fcp_rsp_info: FCP response info code
0245  * @scsi_opcode: scsi opcode
0246  * @fsf_req_id: request id of fsf request
0247  * @host_scribble: LLD specific data attached to SCSI request
0248  * @pl_len: length of payload stored as zfcp_dbf_pay
0249  * @fcp_rsp: response for FCP request
0250  * @scsi_lun_64_hi: scsi device logical unit number, high part of 64 bit
0251  */
0252 struct zfcp_dbf_scsi {
0253     u8 id;
0254     char tag[ZFCP_DBF_TAG_LEN];
0255     u32 scsi_id;
0256     u32 scsi_lun;
0257     u32 scsi_result;
0258     u8 scsi_retries;
0259     u8 scsi_allowed;
0260     u8 fcp_rsp_info;
0261 #define ZFCP_DBF_SCSI_OPCODE    16
0262     u8 scsi_opcode[ZFCP_DBF_SCSI_OPCODE];
0263     u64 fsf_req_id;
0264     u64 host_scribble;
0265     u16 pl_len;
0266     struct fcp_resp_with_ext fcp_rsp;
0267     u32 scsi_lun_64_hi;
0268 } __packed;
0269 
0270 /**
0271  * struct zfcp_dbf_pay - trace record for unformatted payload information
0272  * @area: area this record is originated from
0273  * @counter: ascending record number
0274  * @fsf_req_id: request id of fsf request
0275  * @data: unformatted data
0276  */
0277 struct zfcp_dbf_pay {
0278     u8 counter;
0279     char area[ZFCP_DBF_TAG_LEN];
0280     u64 fsf_req_id;
0281 #define ZFCP_DBF_PAY_MAX_REC 0x100
0282     char data[ZFCP_DBF_PAY_MAX_REC];
0283 } __packed;
0284 
0285 /**
0286  * struct zfcp_dbf - main dbf trace structure
0287  * @pay: reference to payload trace area
0288  * @rec: reference to recovery trace area
0289  * @hba: reference to hba trace area
0290  * @san: reference to san trace area
0291  * @scsi: reference to scsi trace area
0292  * @pay_lock: lock protecting payload trace buffer
0293  * @rec_lock: lock protecting recovery trace buffer
0294  * @hba_lock: lock protecting hba trace buffer
0295  * @san_lock: lock protecting san trace buffer
0296  * @scsi_lock: lock protecting scsi trace buffer
0297  * @pay_buf: pre-allocated buffer for payload
0298  * @rec_buf: pre-allocated buffer for recovery
0299  * @hba_buf: pre-allocated buffer for hba
0300  * @san_buf: pre-allocated buffer for san
0301  * @scsi_buf: pre-allocated buffer for scsi
0302  */
0303 struct zfcp_dbf {
0304     debug_info_t            *pay;
0305     debug_info_t            *rec;
0306     debug_info_t            *hba;
0307     debug_info_t            *san;
0308     debug_info_t            *scsi;
0309     spinlock_t          pay_lock;
0310     spinlock_t          rec_lock;
0311     spinlock_t          hba_lock;
0312     spinlock_t          san_lock;
0313     spinlock_t          scsi_lock;
0314     struct zfcp_dbf_pay     pay_buf;
0315     struct zfcp_dbf_rec     rec_buf;
0316     struct zfcp_dbf_hba     hba_buf;
0317     struct zfcp_dbf_san     san_buf;
0318     struct zfcp_dbf_scsi        scsi_buf;
0319 };
0320 
0321 /**
0322  * zfcp_dbf_hba_fsf_resp_suppress - true if we should not trace by default
0323  * @req: request that has been completed
0324  *
0325  * Returns true if FCP response with only benign residual under count.
0326  */
0327 static inline
0328 bool zfcp_dbf_hba_fsf_resp_suppress(struct zfcp_fsf_req *req)
0329 {
0330     struct fsf_qtcb *qtcb = req->qtcb;
0331     u32 fsf_stat = qtcb->header.fsf_status;
0332     struct fcp_resp *fcp_rsp;
0333     u8 rsp_flags, fr_status;
0334 
0335     if (qtcb->prefix.qtcb_type != FSF_IO_COMMAND)
0336         return false; /* not an FCP response */
0337     fcp_rsp = &qtcb->bottom.io.fcp_rsp.iu.resp;
0338     rsp_flags = fcp_rsp->fr_flags;
0339     fr_status = fcp_rsp->fr_status;
0340     return (fsf_stat == FSF_FCP_RSP_AVAILABLE) &&
0341         (rsp_flags == FCP_RESID_UNDER) &&
0342         (fr_status == SAM_STAT_GOOD);
0343 }
0344 
0345 static inline
0346 void zfcp_dbf_hba_fsf_resp(char *tag, int level, struct zfcp_fsf_req *req)
0347 {
0348     if (debug_level_enabled(req->adapter->dbf->hba, level))
0349         zfcp_dbf_hba_fsf_res(tag, level, req);
0350 }
0351 
0352 /**
0353  * zfcp_dbf_hba_fsf_response - trace event for request completion
0354  * @req: request that has been completed
0355  */
0356 static inline
0357 void zfcp_dbf_hba_fsf_response(struct zfcp_fsf_req *req)
0358 {
0359     struct fsf_qtcb *qtcb = req->qtcb;
0360 
0361     if (unlikely(req->status & (ZFCP_STATUS_FSFREQ_DISMISSED |
0362                     ZFCP_STATUS_FSFREQ_ERROR))) {
0363         zfcp_dbf_hba_fsf_resp("fs_rerr", 3, req);
0364 
0365     } else if ((qtcb->prefix.prot_status != FSF_PROT_GOOD) &&
0366         (qtcb->prefix.prot_status != FSF_PROT_FSF_STATUS_PRESENTED)) {
0367         zfcp_dbf_hba_fsf_resp("fs_perr", 1, req);
0368 
0369     } else if (qtcb->header.fsf_status != FSF_GOOD) {
0370         zfcp_dbf_hba_fsf_resp("fs_ferr",
0371                       zfcp_dbf_hba_fsf_resp_suppress(req)
0372                       ? 5 : 1, req);
0373 
0374     } else if ((qtcb->header.fsf_command == FSF_QTCB_OPEN_PORT_WITH_DID) ||
0375            (qtcb->header.fsf_command == FSF_QTCB_OPEN_LUN)) {
0376         zfcp_dbf_hba_fsf_resp("fs_open", 4, req);
0377 
0378     } else if (qtcb->header.log_length) {
0379         zfcp_dbf_hba_fsf_resp("fs_qtcb", 5, req);
0380 
0381     } else {
0382         zfcp_dbf_hba_fsf_resp("fs_norm", 6, req);
0383     }
0384 }
0385 
0386 static inline
0387 void _zfcp_dbf_scsi(char *tag, int level, struct scsi_cmnd *scmd,
0388            struct zfcp_fsf_req *req)
0389 {
0390     struct zfcp_adapter *adapter = (struct zfcp_adapter *)
0391                     scmd->device->host->hostdata[0];
0392 
0393     if (debug_level_enabled(adapter->dbf->scsi, level))
0394         zfcp_dbf_scsi_common(tag, level, scmd->device, scmd, req);
0395 }
0396 
0397 /**
0398  * zfcp_dbf_scsi_result - trace event for SCSI command completion
0399  * @scmd: SCSI command pointer
0400  * @req: FSF request used to issue SCSI command
0401  */
0402 static inline
0403 void zfcp_dbf_scsi_result(struct scsi_cmnd *scmd, struct zfcp_fsf_req *req)
0404 {
0405     if (scmd->result != 0)
0406         _zfcp_dbf_scsi("rsl_err", 3, scmd, req);
0407     else if (scmd->retries > 0)
0408         _zfcp_dbf_scsi("rsl_ret", 4, scmd, req);
0409     else
0410         _zfcp_dbf_scsi("rsl_nor", 6, scmd, req);
0411 }
0412 
0413 /**
0414  * zfcp_dbf_scsi_fail_send - trace event for failure to send SCSI command
0415  * @scmd: SCSI command pointer
0416  */
0417 static inline
0418 void zfcp_dbf_scsi_fail_send(struct scsi_cmnd *scmd)
0419 {
0420     _zfcp_dbf_scsi("rsl_fai", 4, scmd, NULL);
0421 }
0422 
0423 /**
0424  * zfcp_dbf_scsi_abort - trace event for SCSI command abort
0425  * @tag: tag indicating success or failure of abort operation
0426  * @scmd: SCSI command to be aborted
0427  * @fsf_req: request containing abort (might be NULL)
0428  */
0429 static inline
0430 void zfcp_dbf_scsi_abort(char *tag, struct scsi_cmnd *scmd,
0431              struct zfcp_fsf_req *fsf_req)
0432 {
0433     _zfcp_dbf_scsi(tag, 1, scmd, fsf_req);
0434 }
0435 
0436 /**
0437  * zfcp_dbf_scsi_devreset() - Trace event for Logical Unit or Target Reset.
0438  * @tag: Tag indicating success or failure of reset operation.
0439  * @sdev: Pointer to SCSI device as context for this event.
0440  * @flag: Indicates type of reset (Target Reset, Logical Unit Reset).
0441  * @fsf_req: Pointer to FSF request representing the TMF, or NULL.
0442  */
0443 static inline
0444 void zfcp_dbf_scsi_devreset(char *tag, struct scsi_device *sdev, u8 flag,
0445                 struct zfcp_fsf_req *fsf_req)
0446 {
0447     struct zfcp_adapter *adapter = (struct zfcp_adapter *)
0448                     sdev->host->hostdata[0];
0449     char tmp_tag[ZFCP_DBF_TAG_LEN];
0450     static int const level = 1;
0451 
0452     if (unlikely(!debug_level_enabled(adapter->dbf->scsi, level)))
0453         return;
0454 
0455     if (flag == FCP_TMF_TGT_RESET)
0456         memcpy(tmp_tag, "tr_", 3);
0457     else
0458         memcpy(tmp_tag, "lr_", 3);
0459 
0460     memcpy(&tmp_tag[3], tag, 4);
0461     zfcp_dbf_scsi_common(tmp_tag, level, sdev, NULL, fsf_req);
0462 }
0463 
0464 /**
0465  * zfcp_dbf_scsi_nullcmnd() - trace NULLify of SCSI command in dev/tgt-reset.
0466  * @scmnd: SCSI command that was NULLified.
0467  * @fsf_req: request that owned @scmnd.
0468  */
0469 static inline void zfcp_dbf_scsi_nullcmnd(struct scsi_cmnd *scmnd,
0470                       struct zfcp_fsf_req *fsf_req)
0471 {
0472     _zfcp_dbf_scsi("scfc__1", 3, scmnd, fsf_req);
0473 }
0474 
0475 #endif /* ZFCP_DBF_H */