blob: a3af6bd3d5aa47f294a99d03e3b540c057a632b8 [file] [log] [blame]
Christof Schmitt2b604c92008-03-31 11:15:28 +02001/*
2 * This file is part of the zfcp device driver for
3 * FCP adapters for IBM System z9 and zSeries.
4 *
Christof Schmittd46f3842009-08-18 15:43:07 +02005 * Copyright IBM Corp. 2008, 2009
Christof Schmitt2b604c92008-03-31 11:15:28 +02006 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
10 * any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22#ifndef ZFCP_DBF_H
23#define ZFCP_DBF_H
24
Christof Schmitt4318e082009-11-24 16:54:08 +010025#include <scsi/fc/fc_fcp.h>
Christof Schmittdcd20e22009-08-18 15:43:08 +020026#include "zfcp_ext.h"
Christof Schmitt2b604c92008-03-31 11:15:28 +020027#include "zfcp_fsf.h"
Christof Schmittdcd20e22009-08-18 15:43:08 +020028#include "zfcp_def.h"
Christof Schmitt2b604c92008-03-31 11:15:28 +020029
Swen Schilligae0904f2010-12-02 15:16:12 +010030#define ZFCP_DBF_TAG_LEN 7
Christof Schmitt2b604c92008-03-31 11:15:28 +020031#define ZFCP_DBF_TAG_SIZE 4
Swen Schillig5ffd51a2009-03-02 13:09:04 +010032#define ZFCP_DBF_ID_SIZE 7
Christof Schmitt2b604c92008-03-31 11:15:28 +020033
Christof Schmittd21e9da2010-02-17 11:18:54 +010034#define ZFCP_DBF_INVALID_LUN 0xFFFFFFFFFFFFFFFFull
35
Christof Schmitt2b604c92008-03-31 11:15:28 +020036struct zfcp_dbf_dump {
37 u8 tag[ZFCP_DBF_TAG_SIZE];
38 u32 total_size; /* size of total dump data */
39 u32 offset; /* how much data has being already dumped */
40 u32 size; /* how much data comes with this record */
41 u8 data[]; /* dump data */
42} __attribute__ ((packed));
43
Swen Schilligae0904f2010-12-02 15:16:12 +010044/**
45 * struct zfcp_dbf_rec_trigger - trace record for triggered recovery action
46 * @ready: number of ready recovery actions
47 * @running: number of running recovery actions
48 * @want: wanted recovery action
49 * @need: needed recovery action
50 */
51struct zfcp_dbf_rec_trigger {
Christof Schmitt2b604c92008-03-31 11:15:28 +020052 u32 ready;
53 u32 running;
Christof Schmitt2b604c92008-03-31 11:15:28 +020054 u8 want;
55 u8 need;
Swen Schilligae0904f2010-12-02 15:16:12 +010056} __packed;
57
58/**
59 * struct zfcp_dbf_rec_running - trace record for running recovery
60 * @fsf_req_id: request id for fsf requests
61 * @rec_status: status of the fsf request
62 * @rec_step: current step of the recovery action
63 * rec_count: recovery counter
64 */
65struct zfcp_dbf_rec_running {
66 u64 fsf_req_id;
67 u32 rec_status;
68 u16 rec_step;
69 u8 rec_action;
70 u8 rec_count;
71} __packed;
72
73/**
74 * enum zfcp_dbf_rec_id - recovery trace record id
75 * @ZFCP_DBF_REC_TRIG: triggered recovery identifier
76 * @ZFCP_DBF_REC_RUN: running recovery identifier
77 */
78enum zfcp_dbf_rec_id {
79 ZFCP_DBF_REC_TRIG = 1,
80 ZFCP_DBF_REC_RUN = 2,
Martin Peschke73378912008-05-19 12:17:46 +020081};
Christof Schmitt2b604c92008-03-31 11:15:28 +020082
Swen Schilligae0904f2010-12-02 15:16:12 +010083/**
84 * struct zfcp_dbf_rec - trace record for error recovery actions
85 * @id: unique number of recovery record type
86 * @tag: identifier string specifying the location of initiation
87 * @lun: logical unit number
88 * @wwpn: word wide port number
89 * @d_id: destination ID
90 * @adapter_status: current status of the adapter
91 * @port_status: current status of the port
92 * @lun_status: current status of the lun
93 * @u.trig: structure zfcp_dbf_rec_trigger
94 * @u.run: structure zfcp_dbf_rec_running
95 */
96struct zfcp_dbf_rec {
Christof Schmitt2b604c92008-03-31 11:15:28 +020097 u8 id;
Swen Schilligae0904f2010-12-02 15:16:12 +010098 char tag[ZFCP_DBF_TAG_LEN];
99 u64 lun;
100 u64 wwpn;
101 u32 d_id;
102 u32 adapter_status;
103 u32 port_status;
104 u32 lun_status;
Christof Schmitt2b604c92008-03-31 11:15:28 +0200105 union {
Swen Schilligae0904f2010-12-02 15:16:12 +0100106 struct zfcp_dbf_rec_trigger trig;
107 struct zfcp_dbf_rec_running run;
Christof Schmitt2b604c92008-03-31 11:15:28 +0200108 } u;
Swen Schilligae0904f2010-12-02 15:16:12 +0100109} __packed;
Christof Schmitt2b604c92008-03-31 11:15:28 +0200110
Swen Schillig2c55b752010-12-02 15:16:13 +0100111/**
112 * enum zfcp_dbf_san_id - SAN trace record identifier
113 * @ZFCP_DBF_SAN_REQ: request trace record id
114 * @ZFCP_DBF_SAN_RES: response trace record id
115 * @ZFCP_DBF_SAN_ELS: extended link service record id
116 */
117enum zfcp_dbf_san_id {
118 ZFCP_DBF_SAN_REQ = 1,
119 ZFCP_DBF_SAN_RES = 2,
120 ZFCP_DBF_SAN_ELS = 3,
121};
122
123/** struct zfcp_dbf_san - trace record for SAN requests and responses
124 * @id: unique number of recovery record type
125 * @tag: identifier string specifying the location of initiation
126 * @fsf_req_id: request id for fsf requests
127 * @payload: unformatted information related to request/response
128 * @d_id: destination id
129 */
130struct zfcp_dbf_san {
131 u8 id;
132 char tag[ZFCP_DBF_TAG_LEN];
133 u64 fsf_req_id;
134 u32 d_id;
135#define ZFCP_DBF_SAN_MAX_PAYLOAD (FC_CT_HDR_LEN + 32)
136 char payload[ZFCP_DBF_SAN_MAX_PAYLOAD];
137} __packed;
138
Swen Schillig57717102009-08-18 15:43:21 +0200139struct zfcp_dbf_hba_record_response {
Christof Schmitt2b604c92008-03-31 11:15:28 +0200140 u32 fsf_command;
141 u64 fsf_reqid;
142 u32 fsf_seqno;
143 u64 fsf_issued;
144 u32 fsf_prot_status;
145 u32 fsf_status;
146 u8 fsf_prot_status_qual[FSF_PROT_STATUS_QUAL_SIZE];
147 u8 fsf_status_qual[FSF_STATUS_QUALIFIER_SIZE];
148 u32 fsf_req_status;
149 u8 sbal_first;
Martin Peschkee891bff2008-05-19 12:17:43 +0200150 u8 sbal_last;
Martin Peschkec3baa9a22008-05-19 12:17:44 +0200151 u8 sbal_response;
Christof Schmitt2b604c92008-03-31 11:15:28 +0200152 u8 pool;
153 u64 erp_action;
154 union {
155 struct {
Martin Peschke6bc473d2008-03-31 11:15:29 +0200156 u64 cmnd;
Felix Beckef3eb712010-07-16 15:37:42 +0200157 u32 data_dir;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200158 } fcp;
Christof Schmitt2b604c92008-03-31 11:15:28 +0200159 struct {
160 u64 wwpn;
161 u32 d_id;
162 u32 port_handle;
163 } port;
164 struct {
165 u64 wwpn;
166 u64 fcp_lun;
167 u32 port_handle;
168 u32 lun_handle;
169 } unit;
170 struct {
171 u32 d_id;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200172 } els;
173 } u;
Christof Schmitt2b604c92008-03-31 11:15:28 +0200174} __attribute__ ((packed));
175
Swen Schillig57717102009-08-18 15:43:21 +0200176struct zfcp_dbf_hba_record_status {
Christof Schmitt2b604c92008-03-31 11:15:28 +0200177 u8 failed;
178 u32 status_type;
179 u32 status_subtype;
180 struct fsf_queue_designator
181 queue_designator;
182 u32 payload_size;
183#define ZFCP_DBF_UNSOL_PAYLOAD 80
184#define ZFCP_DBF_UNSOL_PAYLOAD_SENSE_DATA_AVAIL 32
185#define ZFCP_DBF_UNSOL_PAYLOAD_BIT_ERROR_THRESHOLD 56
186#define ZFCP_DBF_UNSOL_PAYLOAD_FEATURE_UPDATE_ALERT 2 * sizeof(u32)
187 u8 payload[ZFCP_DBF_UNSOL_PAYLOAD];
188} __attribute__ ((packed));
189
Swen Schillig57717102009-08-18 15:43:21 +0200190struct zfcp_dbf_hba_record_qdio {
Christof Schmitt2b604c92008-03-31 11:15:28 +0200191 u32 qdio_error;
Christof Schmitt2b604c92008-03-31 11:15:28 +0200192 u8 sbal_index;
193 u8 sbal_count;
194} __attribute__ ((packed));
195
Swen Schillig57717102009-08-18 15:43:21 +0200196struct zfcp_dbf_hba_record {
Christof Schmitt2b604c92008-03-31 11:15:28 +0200197 u8 tag[ZFCP_DBF_TAG_SIZE];
198 u8 tag2[ZFCP_DBF_TAG_SIZE];
199 union {
Swen Schillig57717102009-08-18 15:43:21 +0200200 struct zfcp_dbf_hba_record_response response;
201 struct zfcp_dbf_hba_record_status status;
202 struct zfcp_dbf_hba_record_qdio qdio;
Swen Schillig57069382008-10-01 12:42:21 +0200203 struct fsf_bit_error_payload berr;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200204 } u;
Christof Schmitt2b604c92008-03-31 11:15:28 +0200205} __attribute__ ((packed));
206
Swen Schillig57717102009-08-18 15:43:21 +0200207struct zfcp_dbf_scsi_record {
Christof Schmitt2b604c92008-03-31 11:15:28 +0200208 u8 tag[ZFCP_DBF_TAG_SIZE];
209 u8 tag2[ZFCP_DBF_TAG_SIZE];
210 u32 scsi_id;
211 u32 scsi_lun;
212 u32 scsi_result;
213 u64 scsi_cmnd;
Christof Schmitt2b604c92008-03-31 11:15:28 +0200214#define ZFCP_DBF_SCSI_OPCODE 16
215 u8 scsi_opcode[ZFCP_DBF_SCSI_OPCODE];
216 u8 scsi_retries;
217 u8 scsi_allowed;
218 u64 fsf_reqid;
219 u32 fsf_seqno;
220 u64 fsf_issued;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200221 u64 old_fsf_reqid;
222 u8 rsp_validity;
223 u8 rsp_scsi_status;
224 u32 rsp_resid;
225 u8 rsp_code;
Christof Schmitt2b604c92008-03-31 11:15:28 +0200226#define ZFCP_DBF_SCSI_FCP_SNS_INFO 16
227#define ZFCP_DBF_SCSI_MAX_FCP_SNS_INFO 256
Martin Peschke6bc473d2008-03-31 11:15:29 +0200228 u32 sns_info_len;
229 u8 sns_info[ZFCP_DBF_SCSI_FCP_SNS_INFO];
Christof Schmitt2b604c92008-03-31 11:15:28 +0200230} __attribute__ ((packed));
231
Christof Schmittd46f3842009-08-18 15:43:07 +0200232struct zfcp_dbf {
Swen Schillig57717102009-08-18 15:43:21 +0200233 debug_info_t *rec;
234 debug_info_t *hba;
235 debug_info_t *san;
236 debug_info_t *scsi;
237 spinlock_t rec_lock;
238 spinlock_t hba_lock;
239 spinlock_t san_lock;
240 spinlock_t scsi_lock;
Swen Schilligae0904f2010-12-02 15:16:12 +0100241 struct zfcp_dbf_rec rec_buf;
Swen Schillig57717102009-08-18 15:43:21 +0200242 struct zfcp_dbf_hba_record hba_buf;
Swen Schillig2c55b752010-12-02 15:16:13 +0100243 struct zfcp_dbf_san san_buf;
Swen Schillig57717102009-08-18 15:43:21 +0200244 struct zfcp_dbf_scsi_record scsi_buf;
245 struct zfcp_adapter *adapter;
Christof Schmittd46f3842009-08-18 15:43:07 +0200246};
247
Christof Schmittdcd20e22009-08-18 15:43:08 +0200248static inline
Swen Schillig57717102009-08-18 15:43:21 +0200249void zfcp_dbf_hba_fsf_resp(const char *tag2, int level,
250 struct zfcp_fsf_req *req, struct zfcp_dbf *dbf)
Christof Schmitt2e261af2009-08-18 15:43:09 +0200251{
Swen Schillig57717102009-08-18 15:43:21 +0200252 if (level <= dbf->hba->level)
253 _zfcp_dbf_hba_fsf_response(tag2, level, req, dbf);
Christof Schmitt2e261af2009-08-18 15:43:09 +0200254}
255
256/**
Swen Schillig57717102009-08-18 15:43:21 +0200257 * zfcp_dbf_hba_fsf_response - trace event for request completion
Christof Schmitt2e261af2009-08-18 15:43:09 +0200258 * @fsf_req: request that has been completed
259 */
Swen Schillig57717102009-08-18 15:43:21 +0200260static inline void zfcp_dbf_hba_fsf_response(struct zfcp_fsf_req *req)
Christof Schmitt2e261af2009-08-18 15:43:09 +0200261{
262 struct zfcp_dbf *dbf = req->adapter->dbf;
263 struct fsf_qtcb *qtcb = req->qtcb;
264
265 if ((qtcb->prefix.prot_status != FSF_PROT_GOOD) &&
266 (qtcb->prefix.prot_status != FSF_PROT_FSF_STATUS_PRESENTED)) {
Swen Schillig57717102009-08-18 15:43:21 +0200267 zfcp_dbf_hba_fsf_resp("perr", 1, req, dbf);
Christof Schmitt2e261af2009-08-18 15:43:09 +0200268
269 } else if (qtcb->header.fsf_status != FSF_GOOD) {
Swen Schillig57717102009-08-18 15:43:21 +0200270 zfcp_dbf_hba_fsf_resp("ferr", 1, req, dbf);
Christof Schmitt2e261af2009-08-18 15:43:09 +0200271
272 } else if ((req->fsf_command == FSF_QTCB_OPEN_PORT_WITH_DID) ||
273 (req->fsf_command == FSF_QTCB_OPEN_LUN)) {
Swen Schillig57717102009-08-18 15:43:21 +0200274 zfcp_dbf_hba_fsf_resp("open", 4, req, dbf);
Christof Schmitt2e261af2009-08-18 15:43:09 +0200275
276 } else if (qtcb->header.log_length) {
Swen Schillig57717102009-08-18 15:43:21 +0200277 zfcp_dbf_hba_fsf_resp("qtcb", 5, req, dbf);
Christof Schmitt2e261af2009-08-18 15:43:09 +0200278
279 } else {
Swen Schillig57717102009-08-18 15:43:21 +0200280 zfcp_dbf_hba_fsf_resp("norm", 6, req, dbf);
Christof Schmitt2e261af2009-08-18 15:43:09 +0200281 }
282 }
283
284/**
Swen Schillig57717102009-08-18 15:43:21 +0200285 * zfcp_dbf_hba_fsf_unsol - trace event for an unsolicited status buffer
Christof Schmitt2e261af2009-08-18 15:43:09 +0200286 * @tag: tag indicating which kind of unsolicited status has been received
Swen Schillig57717102009-08-18 15:43:21 +0200287 * @dbf: reference to dbf structure
Christof Schmitt2e261af2009-08-18 15:43:09 +0200288 * @status_buffer: buffer containing payload of unsolicited status
289 */
290static inline
Swen Schillig57717102009-08-18 15:43:21 +0200291void zfcp_dbf_hba_fsf_unsol(const char *tag, struct zfcp_dbf *dbf,
292 struct fsf_status_read_buffer *buf)
Christof Schmitt2e261af2009-08-18 15:43:09 +0200293{
Christof Schmitt2e261af2009-08-18 15:43:09 +0200294 int level = 2;
295
Swen Schillig57717102009-08-18 15:43:21 +0200296 if (level <= dbf->hba->level)
297 _zfcp_dbf_hba_fsf_unsol(tag, level, dbf, buf);
Christof Schmitt2e261af2009-08-18 15:43:09 +0200298}
299
300static inline
Swen Schillig57717102009-08-18 15:43:21 +0200301void zfcp_dbf_scsi(const char *tag, const char *tag2, int level,
302 struct zfcp_dbf *dbf, struct scsi_cmnd *scmd,
303 struct zfcp_fsf_req *req, unsigned long old_id)
Christof Schmittdcd20e22009-08-18 15:43:08 +0200304{
Swen Schillig57717102009-08-18 15:43:21 +0200305 if (level <= dbf->scsi->level)
306 _zfcp_dbf_scsi(tag, tag2, level, dbf, scmd, req, old_id);
Christof Schmittdcd20e22009-08-18 15:43:08 +0200307}
308
309/**
Swen Schillig57717102009-08-18 15:43:21 +0200310 * zfcp_dbf_scsi_result - trace event for SCSI command completion
Christof Schmittab725282010-02-17 11:18:57 +0100311 * @dbf: adapter dbf trace
Christof Schmittdcd20e22009-08-18 15:43:08 +0200312 * @scmd: SCSI command pointer
Christof Schmittab725282010-02-17 11:18:57 +0100313 * @req: FSF request used to issue SCSI command
Christof Schmittdcd20e22009-08-18 15:43:08 +0200314 */
315static inline
Christof Schmittab725282010-02-17 11:18:57 +0100316void zfcp_dbf_scsi_result(struct zfcp_dbf *dbf, struct scsi_cmnd *scmd,
317 struct zfcp_fsf_req *req)
Christof Schmittdcd20e22009-08-18 15:43:08 +0200318{
Christof Schmittab725282010-02-17 11:18:57 +0100319 if (scmd->result != 0)
320 zfcp_dbf_scsi("rslt", "erro", 3, dbf, scmd, req, 0);
321 else if (scmd->retries > 0)
322 zfcp_dbf_scsi("rslt", "retr", 4, dbf, scmd, req, 0);
323 else
324 zfcp_dbf_scsi("rslt", "norm", 6, dbf, scmd, req, 0);
325}
326
327/**
328 * zfcp_dbf_scsi_fail_send - trace event for failure to send SCSI command
329 * @dbf: adapter dbf trace
330 * @scmd: SCSI command pointer
331 */
332static inline
333void zfcp_dbf_scsi_fail_send(struct zfcp_dbf *dbf, struct scsi_cmnd *scmd)
334{
335 zfcp_dbf_scsi("rslt", "fail", 4, dbf, scmd, NULL, 0);
Christof Schmittdcd20e22009-08-18 15:43:08 +0200336}
337
338/**
Swen Schillig57717102009-08-18 15:43:21 +0200339 * zfcp_dbf_scsi_abort - trace event for SCSI command abort
Christof Schmittdcd20e22009-08-18 15:43:08 +0200340 * @tag: tag indicating success or failure of abort operation
341 * @adapter: adapter thas has been used to issue SCSI command to be aborted
342 * @scmd: SCSI command to be aborted
343 * @new_req: request containing abort (might be NULL)
344 * @old_id: identifier of request containg SCSI command to be aborted
345 */
346static inline
Swen Schillig57717102009-08-18 15:43:21 +0200347void zfcp_dbf_scsi_abort(const char *tag, struct zfcp_dbf *dbf,
348 struct scsi_cmnd *scmd, struct zfcp_fsf_req *new_req,
349 unsigned long old_id)
Christof Schmittdcd20e22009-08-18 15:43:08 +0200350{
Swen Schillig57717102009-08-18 15:43:21 +0200351 zfcp_dbf_scsi("abrt", tag, 1, dbf, scmd, new_req, old_id);
Christof Schmittdcd20e22009-08-18 15:43:08 +0200352}
353
354/**
Swen Schillig57717102009-08-18 15:43:21 +0200355 * zfcp_dbf_scsi_devreset - trace event for Logical Unit or Target Reset
Christof Schmittdcd20e22009-08-18 15:43:08 +0200356 * @tag: tag indicating success or failure of reset operation
Christof Schmittb62a8d92010-09-08 14:39:55 +0200357 * @scmnd: SCSI command which caused this error recovery
Christof Schmittdcd20e22009-08-18 15:43:08 +0200358 * @flag: indicates type of reset (Target Reset, Logical Unit Reset)
Christof Schmittdcd20e22009-08-18 15:43:08 +0200359 */
360static inline
Christof Schmittb62a8d92010-09-08 14:39:55 +0200361void zfcp_dbf_scsi_devreset(const char *tag, struct scsi_cmnd *scmnd, u8 flag)
Christof Schmittdcd20e22009-08-18 15:43:08 +0200362{
Christof Schmittb62a8d92010-09-08 14:39:55 +0200363 struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(scmnd->device);
364
Christof Schmitt4318e082009-11-24 16:54:08 +0100365 zfcp_dbf_scsi(flag == FCP_TMF_TGT_RESET ? "trst" : "lrst", tag, 1,
Christof Schmittb62a8d92010-09-08 14:39:55 +0200366 zfcp_sdev->port->adapter->dbf, scmnd, NULL, 0);
Christof Schmittdcd20e22009-08-18 15:43:08 +0200367}
368
Christof Schmitt2b604c92008-03-31 11:15:28 +0200369#endif /* ZFCP_DBF_H */