linux/drivers/s390/scsi/zfcp_dbf.h
<<
>>
Prefs
   1/* SPDX-License-Identifier: GPL-2.0 */
   2/*
   3 * zfcp device driver
   4 * debug feature declarations
   5 *
   6 * Copyright IBM Corp. 2008, 2017
   7 */
   8
   9#ifndef ZFCP_DBF_H
  10#define ZFCP_DBF_H
  11
  12#include <scsi/fc/fc_fcp.h>
  13#include "zfcp_ext.h"
  14#include "zfcp_fsf.h"
  15#include "zfcp_def.h"
  16
  17#define ZFCP_DBF_TAG_LEN       7
  18
  19#define ZFCP_DBF_INVALID_LUN    0xFFFFFFFFFFFFFFFFull
  20
  21enum zfcp_dbf_pseudo_erp_act_type {
  22        ZFCP_PSEUDO_ERP_ACTION_RPORT_ADD = 0xff,
  23        ZFCP_PSEUDO_ERP_ACTION_RPORT_DEL = 0xfe,
  24};
  25
  26/**
  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
  32 */
  33struct zfcp_dbf_rec_trigger {
  34        u32 ready;
  35        u32 running;
  36        u8 want;
  37        u8 need;
  38} __packed;
  39
  40/**
  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
  46 */
  47struct zfcp_dbf_rec_running {
  48        u64 fsf_req_id;
  49        u32 rec_status;
  50        u16 rec_step;
  51        u8 rec_action;
  52        u8 rec_count;
  53} __packed;
  54
  55/**
  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
  59 */
  60enum zfcp_dbf_rec_id {
  61        ZFCP_DBF_REC_TRIG       = 1,
  62        ZFCP_DBF_REC_RUN        = 2,
  63};
  64
  65/**
  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
  77 */
  78struct zfcp_dbf_rec {
  79        u8 id;
  80        char tag[ZFCP_DBF_TAG_LEN];
  81        u64 lun;
  82        u64 wwpn;
  83        u32 d_id;
  84        u32 adapter_status;
  85        u32 port_status;
  86        u32 lun_status;
  87        union {
  88                struct zfcp_dbf_rec_trigger trig;
  89                struct zfcp_dbf_rec_running run;
  90        } u;
  91} __packed;
  92
  93/**
  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
  98 */
  99enum zfcp_dbf_san_id {
 100        ZFCP_DBF_SAN_REQ        = 1,
 101        ZFCP_DBF_SAN_RES        = 2,
 102        ZFCP_DBF_SAN_ELS        = 3,
 103};
 104
 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
 111 */
 112struct zfcp_dbf_san {
 113        u8 id;
 114        char tag[ZFCP_DBF_TAG_LEN];
 115        u64 fsf_req_id;
 116        u32 d_id;
 117#define ZFCP_DBF_SAN_MAX_PAYLOAD (FC_CT_HDR_LEN + 32)
 118        char payload[ZFCP_DBF_SAN_MAX_PAYLOAD];
 119        u16 pl_len;
 120} __packed;
 121
 122/**
 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
 129 */
 130struct zfcp_dbf_hba_res {
 131        u64 req_issued;
 132        u32 prot_status;
 133        u8  prot_status_qual[FSF_PROT_STATUS_QUAL_SIZE];
 134        u32 fsf_status;
 135        u8  fsf_status_qual[FSF_STATUS_QUALIFIER_SIZE];
 136        u32 port_handle;
 137        u32 lun_handle;
 138} __packed;
 139
 140/**
 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
 147 */
 148struct zfcp_dbf_hba_uss {
 149        u32 status_type;
 150        u32 status_subtype;
 151        u32 d_id;
 152        u64 lun;
 153        u64 queue_designator;
 154} __packed;
 155
 156/**
 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
 161 */
 162enum 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,
 167};
 168
 169/**
 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
 179 */
 180struct zfcp_dbf_hba {
 181        u8 id;
 182        char tag[ZFCP_DBF_TAG_LEN];
 183        u64 fsf_req_id;
 184        u32 fsf_req_status;
 185        u32 fsf_cmd;
 186        u32 fsf_seq_no;
 187        u16 pl_len;
 188        union {
 189                struct zfcp_dbf_hba_res res;
 190                struct zfcp_dbf_hba_uss uss;
 191                struct fsf_bit_error_payload be;
 192        } u;
 193} __packed;
 194
 195/**
 196 * enum zfcp_dbf_scsi_id - scsi trace record identifier
 197 * @ZFCP_DBF_SCSI_CMND: scsi command trace record
 198 */
 199enum zfcp_dbf_scsi_id {
 200        ZFCP_DBF_SCSI_CMND      = 1,
 201};
 202
 203/**
 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
 219 */
 220struct zfcp_dbf_scsi {
 221        u8 id;
 222        char tag[ZFCP_DBF_TAG_LEN];
 223        u32 scsi_id;
 224        u32 scsi_lun;
 225        u32 scsi_result;
 226        u8 scsi_retries;
 227        u8 scsi_allowed;
 228        u8 fcp_rsp_info;
 229#define ZFCP_DBF_SCSI_OPCODE    16
 230        u8 scsi_opcode[ZFCP_DBF_SCSI_OPCODE];
 231        u64 fsf_req_id;
 232        u64 host_scribble;
 233        u16 pl_len;
 234        struct fcp_resp_with_ext fcp_rsp;
 235        u32 scsi_lun_64_hi;
 236} __packed;
 237
 238/**
 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
 244 */
 245struct zfcp_dbf_pay {
 246        u8 counter;
 247        char area[ZFCP_DBF_TAG_LEN];
 248        u64 fsf_req_id;
 249#define ZFCP_DBF_PAY_MAX_REC 0x100
 250        char data[ZFCP_DBF_PAY_MAX_REC];
 251} __packed;
 252
 253/**
 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
 270 */
 271struct zfcp_dbf {
 272        debug_info_t                    *pay;
 273        debug_info_t                    *rec;
 274        debug_info_t                    *hba;
 275        debug_info_t                    *san;
 276        debug_info_t                    *scsi;
 277        spinlock_t                      pay_lock;
 278        spinlock_t                      rec_lock;
 279        spinlock_t                      hba_lock;
 280        spinlock_t                      san_lock;
 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;
 287};
 288
 289/**
 290 * zfcp_dbf_hba_fsf_resp_suppress - true if we should not trace by default
 291 * @req: request that has been completed
 292 *
 293 * Returns true if FCP response with only benign residual under count.
 294 */
 295static inline
 296bool zfcp_dbf_hba_fsf_resp_suppress(struct zfcp_fsf_req *req)
 297{
 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;
 302
 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);
 311}
 312
 313static inline
 314void zfcp_dbf_hba_fsf_resp(char *tag, int level, struct zfcp_fsf_req *req)
 315{
 316        if (debug_level_enabled(req->adapter->dbf->hba, level))
 317                zfcp_dbf_hba_fsf_res(tag, level, req);
 318}
 319
 320/**
 321 * zfcp_dbf_hba_fsf_response - trace event for request completion
 322 * @req: request that has been completed
 323 */
 324static inline
 325void zfcp_dbf_hba_fsf_response(struct zfcp_fsf_req *req)
 326{
 327        struct fsf_qtcb *qtcb = req->qtcb;
 328
 329        if (unlikely(req->status & (ZFCP_STATUS_FSFREQ_DISMISSED |
 330                                    ZFCP_STATUS_FSFREQ_ERROR))) {
 331                zfcp_dbf_hba_fsf_resp("fs_rerr", 3, req);
 332
 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);
 336
 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)
 340                                      ? 5 : 1, req);
 341
 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);
 345
 346        } else if (qtcb->header.log_length) {
 347                zfcp_dbf_hba_fsf_resp("fs_qtcb", 5, req);
 348
 349        } else {
 350                zfcp_dbf_hba_fsf_resp("fs_norm", 6, req);
 351        }
 352}
 353
 354static inline
 355void _zfcp_dbf_scsi(char *tag, int level, struct scsi_cmnd *scmd,
 356                   struct zfcp_fsf_req *req)
 357{
 358        struct zfcp_adapter *adapter = (struct zfcp_adapter *)
 359                                        scmd->device->host->hostdata[0];
 360
 361        if (debug_level_enabled(adapter->dbf->scsi, level))
 362                zfcp_dbf_scsi(tag, level, scmd, req);
 363}
 364
 365/**
 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
 369 */
 370static inline
 371void zfcp_dbf_scsi_result(struct scsi_cmnd *scmd, struct zfcp_fsf_req *req)
 372{
 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);
 377        else
 378                _zfcp_dbf_scsi("rsl_nor", 6, scmd, req);
 379}
 380
 381/**
 382 * zfcp_dbf_scsi_fail_send - trace event for failure to send SCSI command
 383 * @scmd: SCSI command pointer
 384 */
 385static inline
 386void zfcp_dbf_scsi_fail_send(struct scsi_cmnd *scmd)
 387{
 388        _zfcp_dbf_scsi("rsl_fai", 4, scmd, NULL);
 389}
 390
 391/**
 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)
 396 */
 397static inline
 398void zfcp_dbf_scsi_abort(char *tag, struct scsi_cmnd *scmd,
 399                         struct zfcp_fsf_req *fsf_req)
 400{
 401        _zfcp_dbf_scsi(tag, 1, scmd, fsf_req);
 402}
 403
 404/**
 405 * zfcp_dbf_scsi_devreset - trace event for Logical Unit or Target Reset
 406 * @tag: tag indicating success or failure of reset operation
 407 * @scmnd: SCSI command which caused this error recovery
 408 * @flag: indicates type of reset (Target Reset, Logical Unit Reset)
 409 */
 410static inline
 411void zfcp_dbf_scsi_devreset(char *tag, struct scsi_cmnd *scmnd, u8 flag,
 412                            struct zfcp_fsf_req *fsf_req)
 413{
 414        char tmp_tag[ZFCP_DBF_TAG_LEN];
 415
 416        if (flag == FCP_TMF_TGT_RESET)
 417                memcpy(tmp_tag, "tr_", 3);
 418        else
 419                memcpy(tmp_tag, "lr_", 3);
 420
 421        memcpy(&tmp_tag[3], tag, 4);
 422        _zfcp_dbf_scsi(tmp_tag, 1, scmnd, fsf_req);
 423}
 424
 425/**
 426 * zfcp_dbf_scsi_nullcmnd() - trace NULLify of SCSI command in dev/tgt-reset.
 427 * @scmnd: SCSI command that was NULLified.
 428 * @fsf_req: request that owned @scmnd.
 429 */
 430static inline void zfcp_dbf_scsi_nullcmnd(struct scsi_cmnd *scmnd,
 431                                          struct zfcp_fsf_req *fsf_req)
 432{
 433        _zfcp_dbf_scsi("scfc__1", 3, scmnd, fsf_req);
 434}
 435
 436#endif /* ZFCP_DBF_H */
 437