blob: 2bcc3403126aa84f24e8ba75726116a1594177a9 [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
30#define ZFCP_DBF_TAG_SIZE 4
Swen Schillig5ffd51a2009-03-02 13:09:04 +010031#define ZFCP_DBF_ID_SIZE 7
Christof Schmitt2b604c92008-03-31 11:15:28 +020032
Christof Schmittd21e9da2010-02-17 11:18:54 +010033#define ZFCP_DBF_INVALID_LUN 0xFFFFFFFFFFFFFFFFull
34
Christof Schmitt2b604c92008-03-31 11:15:28 +020035struct zfcp_dbf_dump {
36 u8 tag[ZFCP_DBF_TAG_SIZE];
37 u32 total_size; /* size of total dump data */
38 u32 offset; /* how much data has being already dumped */
39 u32 size; /* how much data comes with this record */
40 u8 data[]; /* dump data */
41} __attribute__ ((packed));
42
Swen Schillig57717102009-08-18 15:43:21 +020043struct zfcp_dbf_rec_record_thread {
Christof Schmitt2b604c92008-03-31 11:15:28 +020044 u32 total;
45 u32 ready;
46 u32 running;
Martin Peschke73378912008-05-19 12:17:46 +020047};
Christof Schmitt2b604c92008-03-31 11:15:28 +020048
Swen Schillig57717102009-08-18 15:43:21 +020049struct zfcp_dbf_rec_record_target {
Christof Schmitt2b604c92008-03-31 11:15:28 +020050 u64 ref;
51 u32 status;
52 u32 d_id;
53 u64 wwpn;
54 u64 fcp_lun;
55 u32 erp_count;
Martin Peschke73378912008-05-19 12:17:46 +020056};
Christof Schmitt2b604c92008-03-31 11:15:28 +020057
Swen Schillig57717102009-08-18 15:43:21 +020058struct zfcp_dbf_rec_record_trigger {
Christof Schmitt2b604c92008-03-31 11:15:28 +020059 u8 want;
60 u8 need;
61 u32 as;
62 u32 ps;
63 u32 us;
64 u64 ref;
65 u64 action;
66 u64 wwpn;
67 u64 fcp_lun;
Martin Peschke73378912008-05-19 12:17:46 +020068};
Christof Schmitt2b604c92008-03-31 11:15:28 +020069
Swen Schillig57717102009-08-18 15:43:21 +020070struct zfcp_dbf_rec_record_action {
Christof Schmitt2b604c92008-03-31 11:15:28 +020071 u32 status;
72 u32 step;
73 u64 action;
74 u64 fsf_req;
Martin Peschke73378912008-05-19 12:17:46 +020075};
Christof Schmitt2b604c92008-03-31 11:15:28 +020076
Swen Schillig57717102009-08-18 15:43:21 +020077struct zfcp_dbf_rec_record {
Christof Schmitt2b604c92008-03-31 11:15:28 +020078 u8 id;
Swen Schillig5ffd51a2009-03-02 13:09:04 +010079 char id2[7];
Christof Schmitt2b604c92008-03-31 11:15:28 +020080 union {
Swen Schillig57717102009-08-18 15:43:21 +020081 struct zfcp_dbf_rec_record_action action;
82 struct zfcp_dbf_rec_record_thread thread;
83 struct zfcp_dbf_rec_record_target target;
84 struct zfcp_dbf_rec_record_trigger trigger;
Christof Schmitt2b604c92008-03-31 11:15:28 +020085 } u;
Martin Peschke73378912008-05-19 12:17:46 +020086};
Christof Schmitt2b604c92008-03-31 11:15:28 +020087
88enum {
89 ZFCP_REC_DBF_ID_ACTION,
90 ZFCP_REC_DBF_ID_THREAD,
91 ZFCP_REC_DBF_ID_TARGET,
92 ZFCP_REC_DBF_ID_TRIGGER,
93};
94
Swen Schillig57717102009-08-18 15:43:21 +020095struct zfcp_dbf_hba_record_response {
Christof Schmitt2b604c92008-03-31 11:15:28 +020096 u32 fsf_command;
97 u64 fsf_reqid;
98 u32 fsf_seqno;
99 u64 fsf_issued;
100 u32 fsf_prot_status;
101 u32 fsf_status;
102 u8 fsf_prot_status_qual[FSF_PROT_STATUS_QUAL_SIZE];
103 u8 fsf_status_qual[FSF_STATUS_QUALIFIER_SIZE];
104 u32 fsf_req_status;
105 u8 sbal_first;
Martin Peschkee891bff2008-05-19 12:17:43 +0200106 u8 sbal_last;
Martin Peschkec3baa9a22008-05-19 12:17:44 +0200107 u8 sbal_response;
Christof Schmitt2b604c92008-03-31 11:15:28 +0200108 u8 pool;
109 u64 erp_action;
110 union {
111 struct {
Martin Peschke6bc473d2008-03-31 11:15:29 +0200112 u64 cmnd;
113 u64 serial;
Felix Beckef3eb712010-07-16 15:37:42 +0200114 u32 data_dir;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200115 } fcp;
Christof Schmitt2b604c92008-03-31 11:15:28 +0200116 struct {
117 u64 wwpn;
118 u32 d_id;
119 u32 port_handle;
120 } port;
121 struct {
122 u64 wwpn;
123 u64 fcp_lun;
124 u32 port_handle;
125 u32 lun_handle;
126 } unit;
127 struct {
128 u32 d_id;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200129 } els;
130 } u;
Christof Schmitt2b604c92008-03-31 11:15:28 +0200131} __attribute__ ((packed));
132
Swen Schillig57717102009-08-18 15:43:21 +0200133struct zfcp_dbf_hba_record_status {
Christof Schmitt2b604c92008-03-31 11:15:28 +0200134 u8 failed;
135 u32 status_type;
136 u32 status_subtype;
137 struct fsf_queue_designator
138 queue_designator;
139 u32 payload_size;
140#define ZFCP_DBF_UNSOL_PAYLOAD 80
141#define ZFCP_DBF_UNSOL_PAYLOAD_SENSE_DATA_AVAIL 32
142#define ZFCP_DBF_UNSOL_PAYLOAD_BIT_ERROR_THRESHOLD 56
143#define ZFCP_DBF_UNSOL_PAYLOAD_FEATURE_UPDATE_ALERT 2 * sizeof(u32)
144 u8 payload[ZFCP_DBF_UNSOL_PAYLOAD];
145} __attribute__ ((packed));
146
Swen Schillig57717102009-08-18 15:43:21 +0200147struct zfcp_dbf_hba_record_qdio {
Christof Schmitt2b604c92008-03-31 11:15:28 +0200148 u32 qdio_error;
Christof Schmitt2b604c92008-03-31 11:15:28 +0200149 u8 sbal_index;
150 u8 sbal_count;
151} __attribute__ ((packed));
152
Swen Schillig57717102009-08-18 15:43:21 +0200153struct zfcp_dbf_hba_record {
Christof Schmitt2b604c92008-03-31 11:15:28 +0200154 u8 tag[ZFCP_DBF_TAG_SIZE];
155 u8 tag2[ZFCP_DBF_TAG_SIZE];
156 union {
Swen Schillig57717102009-08-18 15:43:21 +0200157 struct zfcp_dbf_hba_record_response response;
158 struct zfcp_dbf_hba_record_status status;
159 struct zfcp_dbf_hba_record_qdio qdio;
Swen Schillig57069382008-10-01 12:42:21 +0200160 struct fsf_bit_error_payload berr;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200161 } u;
Christof Schmitt2b604c92008-03-31 11:15:28 +0200162} __attribute__ ((packed));
163
Swen Schillig57717102009-08-18 15:43:21 +0200164struct zfcp_dbf_san_record_ct_request {
Martin Peschke6bc473d2008-03-31 11:15:29 +0200165 u16 cmd_req_code;
166 u8 revision;
167 u8 gs_type;
168 u8 gs_subtype;
169 u8 options;
170 u16 max_res_size;
171 u32 len;
Christof Schmitt7c7dc192009-11-24 16:54:13 +0100172 u32 d_id;
Christof Schmitt2b604c92008-03-31 11:15:28 +0200173} __attribute__ ((packed));
174
Swen Schillig57717102009-08-18 15:43:21 +0200175struct zfcp_dbf_san_record_ct_response {
Martin Peschke6bc473d2008-03-31 11:15:29 +0200176 u16 cmd_rsp_code;
177 u8 revision;
178 u8 reason_code;
179 u8 expl;
180 u8 vendor_unique;
Christof Schmitt39eb7e9a2008-12-19 16:57:01 +0100181 u16 max_res_size;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200182 u32 len;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200183} __attribute__ ((packed));
184
Swen Schillig57717102009-08-18 15:43:21 +0200185struct zfcp_dbf_san_record_els {
Christof Schmitt7c7dc192009-11-24 16:54:13 +0100186 u32 d_id;
Christof Schmitt2b604c92008-03-31 11:15:28 +0200187} __attribute__ ((packed));
188
Swen Schillig57717102009-08-18 15:43:21 +0200189struct zfcp_dbf_san_record {
Christof Schmitt2b604c92008-03-31 11:15:28 +0200190 u8 tag[ZFCP_DBF_TAG_SIZE];
191 u64 fsf_reqid;
192 u32 fsf_seqno;
Christof Schmitt2b604c92008-03-31 11:15:28 +0200193 union {
Swen Schillig57717102009-08-18 15:43:21 +0200194 struct zfcp_dbf_san_record_ct_request ct_req;
195 struct zfcp_dbf_san_record_ct_response ct_resp;
196 struct zfcp_dbf_san_record_els els;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200197 } u;
Christof Schmitt2b604c92008-03-31 11:15:28 +0200198} __attribute__ ((packed));
199
Christof Schmitt67feeeb2010-02-17 11:18:52 +0100200#define ZFCP_DBF_SAN_MAX_PAYLOAD 1024
201
Swen Schillig57717102009-08-18 15:43:21 +0200202struct zfcp_dbf_scsi_record {
Christof Schmitt2b604c92008-03-31 11:15:28 +0200203 u8 tag[ZFCP_DBF_TAG_SIZE];
204 u8 tag2[ZFCP_DBF_TAG_SIZE];
205 u32 scsi_id;
206 u32 scsi_lun;
207 u32 scsi_result;
208 u64 scsi_cmnd;
209 u64 scsi_serial;
210#define ZFCP_DBF_SCSI_OPCODE 16
211 u8 scsi_opcode[ZFCP_DBF_SCSI_OPCODE];
212 u8 scsi_retries;
213 u8 scsi_allowed;
214 u64 fsf_reqid;
215 u32 fsf_seqno;
216 u64 fsf_issued;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200217 u64 old_fsf_reqid;
218 u8 rsp_validity;
219 u8 rsp_scsi_status;
220 u32 rsp_resid;
221 u8 rsp_code;
Christof Schmitt2b604c92008-03-31 11:15:28 +0200222#define ZFCP_DBF_SCSI_FCP_SNS_INFO 16
223#define ZFCP_DBF_SCSI_MAX_FCP_SNS_INFO 256
Martin Peschke6bc473d2008-03-31 11:15:29 +0200224 u32 sns_info_len;
225 u8 sns_info[ZFCP_DBF_SCSI_FCP_SNS_INFO];
Christof Schmitt2b604c92008-03-31 11:15:28 +0200226} __attribute__ ((packed));
227
Christof Schmittd46f3842009-08-18 15:43:07 +0200228struct zfcp_dbf {
Swen Schillig57717102009-08-18 15:43:21 +0200229 debug_info_t *rec;
230 debug_info_t *hba;
231 debug_info_t *san;
232 debug_info_t *scsi;
233 spinlock_t rec_lock;
234 spinlock_t hba_lock;
235 spinlock_t san_lock;
236 spinlock_t scsi_lock;
237 struct zfcp_dbf_rec_record rec_buf;
238 struct zfcp_dbf_hba_record hba_buf;
239 struct zfcp_dbf_san_record san_buf;
240 struct zfcp_dbf_scsi_record scsi_buf;
241 struct zfcp_adapter *adapter;
Christof Schmittd46f3842009-08-18 15:43:07 +0200242};
243
Christof Schmittdcd20e22009-08-18 15:43:08 +0200244static inline
Swen Schillig57717102009-08-18 15:43:21 +0200245void zfcp_dbf_hba_fsf_resp(const char *tag2, int level,
246 struct zfcp_fsf_req *req, struct zfcp_dbf *dbf)
Christof Schmitt2e261af2009-08-18 15:43:09 +0200247{
Swen Schillig57717102009-08-18 15:43:21 +0200248 if (level <= dbf->hba->level)
249 _zfcp_dbf_hba_fsf_response(tag2, level, req, dbf);
Christof Schmitt2e261af2009-08-18 15:43:09 +0200250}
251
252/**
Swen Schillig57717102009-08-18 15:43:21 +0200253 * zfcp_dbf_hba_fsf_response - trace event for request completion
Christof Schmitt2e261af2009-08-18 15:43:09 +0200254 * @fsf_req: request that has been completed
255 */
Swen Schillig57717102009-08-18 15:43:21 +0200256static inline void zfcp_dbf_hba_fsf_response(struct zfcp_fsf_req *req)
Christof Schmitt2e261af2009-08-18 15:43:09 +0200257{
258 struct zfcp_dbf *dbf = req->adapter->dbf;
259 struct fsf_qtcb *qtcb = req->qtcb;
260
261 if ((qtcb->prefix.prot_status != FSF_PROT_GOOD) &&
262 (qtcb->prefix.prot_status != FSF_PROT_FSF_STATUS_PRESENTED)) {
Swen Schillig57717102009-08-18 15:43:21 +0200263 zfcp_dbf_hba_fsf_resp("perr", 1, req, dbf);
Christof Schmitt2e261af2009-08-18 15:43:09 +0200264
265 } else if (qtcb->header.fsf_status != FSF_GOOD) {
Swen Schillig57717102009-08-18 15:43:21 +0200266 zfcp_dbf_hba_fsf_resp("ferr", 1, req, dbf);
Christof Schmitt2e261af2009-08-18 15:43:09 +0200267
268 } else if ((req->fsf_command == FSF_QTCB_OPEN_PORT_WITH_DID) ||
269 (req->fsf_command == FSF_QTCB_OPEN_LUN)) {
Swen Schillig57717102009-08-18 15:43:21 +0200270 zfcp_dbf_hba_fsf_resp("open", 4, req, dbf);
Christof Schmitt2e261af2009-08-18 15:43:09 +0200271
272 } else if (qtcb->header.log_length) {
Swen Schillig57717102009-08-18 15:43:21 +0200273 zfcp_dbf_hba_fsf_resp("qtcb", 5, req, dbf);
Christof Schmitt2e261af2009-08-18 15:43:09 +0200274
275 } else {
Swen Schillig57717102009-08-18 15:43:21 +0200276 zfcp_dbf_hba_fsf_resp("norm", 6, req, dbf);
Christof Schmitt2e261af2009-08-18 15:43:09 +0200277 }
278 }
279
280/**
Swen Schillig57717102009-08-18 15:43:21 +0200281 * zfcp_dbf_hba_fsf_unsol - trace event for an unsolicited status buffer
Christof Schmitt2e261af2009-08-18 15:43:09 +0200282 * @tag: tag indicating which kind of unsolicited status has been received
Swen Schillig57717102009-08-18 15:43:21 +0200283 * @dbf: reference to dbf structure
Christof Schmitt2e261af2009-08-18 15:43:09 +0200284 * @status_buffer: buffer containing payload of unsolicited status
285 */
286static inline
Swen Schillig57717102009-08-18 15:43:21 +0200287void zfcp_dbf_hba_fsf_unsol(const char *tag, struct zfcp_dbf *dbf,
288 struct fsf_status_read_buffer *buf)
Christof Schmitt2e261af2009-08-18 15:43:09 +0200289{
Christof Schmitt2e261af2009-08-18 15:43:09 +0200290 int level = 2;
291
Swen Schillig57717102009-08-18 15:43:21 +0200292 if (level <= dbf->hba->level)
293 _zfcp_dbf_hba_fsf_unsol(tag, level, dbf, buf);
Christof Schmitt2e261af2009-08-18 15:43:09 +0200294}
295
296static inline
Swen Schillig57717102009-08-18 15:43:21 +0200297void zfcp_dbf_scsi(const char *tag, const char *tag2, int level,
298 struct zfcp_dbf *dbf, struct scsi_cmnd *scmd,
299 struct zfcp_fsf_req *req, unsigned long old_id)
Christof Schmittdcd20e22009-08-18 15:43:08 +0200300{
Swen Schillig57717102009-08-18 15:43:21 +0200301 if (level <= dbf->scsi->level)
302 _zfcp_dbf_scsi(tag, tag2, level, dbf, scmd, req, old_id);
Christof Schmittdcd20e22009-08-18 15:43:08 +0200303}
304
305/**
Swen Schillig57717102009-08-18 15:43:21 +0200306 * zfcp_dbf_scsi_result - trace event for SCSI command completion
Christof Schmittab725282010-02-17 11:18:57 +0100307 * @dbf: adapter dbf trace
Christof Schmittdcd20e22009-08-18 15:43:08 +0200308 * @scmd: SCSI command pointer
Christof Schmittab725282010-02-17 11:18:57 +0100309 * @req: FSF request used to issue SCSI command
Christof Schmittdcd20e22009-08-18 15:43:08 +0200310 */
311static inline
Christof Schmittab725282010-02-17 11:18:57 +0100312void zfcp_dbf_scsi_result(struct zfcp_dbf *dbf, struct scsi_cmnd *scmd,
313 struct zfcp_fsf_req *req)
Christof Schmittdcd20e22009-08-18 15:43:08 +0200314{
Christof Schmittab725282010-02-17 11:18:57 +0100315 if (scmd->result != 0)
316 zfcp_dbf_scsi("rslt", "erro", 3, dbf, scmd, req, 0);
317 else if (scmd->retries > 0)
318 zfcp_dbf_scsi("rslt", "retr", 4, dbf, scmd, req, 0);
319 else
320 zfcp_dbf_scsi("rslt", "norm", 6, dbf, scmd, req, 0);
321}
322
323/**
324 * zfcp_dbf_scsi_fail_send - trace event for failure to send SCSI command
325 * @dbf: adapter dbf trace
326 * @scmd: SCSI command pointer
327 */
328static inline
329void zfcp_dbf_scsi_fail_send(struct zfcp_dbf *dbf, struct scsi_cmnd *scmd)
330{
331 zfcp_dbf_scsi("rslt", "fail", 4, dbf, scmd, NULL, 0);
Christof Schmittdcd20e22009-08-18 15:43:08 +0200332}
333
334/**
Swen Schillig57717102009-08-18 15:43:21 +0200335 * zfcp_dbf_scsi_abort - trace event for SCSI command abort
Christof Schmittdcd20e22009-08-18 15:43:08 +0200336 * @tag: tag indicating success or failure of abort operation
337 * @adapter: adapter thas has been used to issue SCSI command to be aborted
338 * @scmd: SCSI command to be aborted
339 * @new_req: request containing abort (might be NULL)
340 * @old_id: identifier of request containg SCSI command to be aborted
341 */
342static inline
Swen Schillig57717102009-08-18 15:43:21 +0200343void zfcp_dbf_scsi_abort(const char *tag, struct zfcp_dbf *dbf,
344 struct scsi_cmnd *scmd, struct zfcp_fsf_req *new_req,
345 unsigned long old_id)
Christof Schmittdcd20e22009-08-18 15:43:08 +0200346{
Swen Schillig57717102009-08-18 15:43:21 +0200347 zfcp_dbf_scsi("abrt", tag, 1, dbf, scmd, new_req, old_id);
Christof Schmittdcd20e22009-08-18 15:43:08 +0200348}
349
350/**
Swen Schillig57717102009-08-18 15:43:21 +0200351 * zfcp_dbf_scsi_devreset - trace event for Logical Unit or Target Reset
Christof Schmittdcd20e22009-08-18 15:43:08 +0200352 * @tag: tag indicating success or failure of reset operation
353 * @flag: indicates type of reset (Target Reset, Logical Unit Reset)
354 * @unit: unit that needs reset
355 * @scsi_cmnd: SCSI command which caused this error recovery
356 */
357static inline
Swen Schillig57717102009-08-18 15:43:21 +0200358void zfcp_dbf_scsi_devreset(const char *tag, u8 flag, struct zfcp_unit *unit,
359 struct scsi_cmnd *scsi_cmnd)
Christof Schmittdcd20e22009-08-18 15:43:08 +0200360{
Christof Schmitt4318e082009-11-24 16:54:08 +0100361 zfcp_dbf_scsi(flag == FCP_TMF_TGT_RESET ? "trst" : "lrst", tag, 1,
Swen Schillig57717102009-08-18 15:43:21 +0200362 unit->port->adapter->dbf, scsi_cmnd, NULL, 0);
Christof Schmittdcd20e22009-08-18 15:43:08 +0200363}
364
Christof Schmitt2b604c92008-03-31 11:15:28 +0200365#endif /* ZFCP_DBF_H */