blob: 6b1461e8f8470a939fbfca11d99d0289d6acd970 [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 Schmittdcd20e22009-08-18 15:43:08 +020025#include "zfcp_ext.h"
Christof Schmitt2b604c92008-03-31 11:15:28 +020026#include "zfcp_fsf.h"
Christof Schmittdcd20e22009-08-18 15:43:08 +020027#include "zfcp_def.h"
Christof Schmitt2b604c92008-03-31 11:15:28 +020028
29#define ZFCP_DBF_TAG_SIZE 4
Swen Schillig5ffd51a2009-03-02 13:09:04 +010030#define ZFCP_DBF_ID_SIZE 7
Christof Schmitt2b604c92008-03-31 11:15:28 +020031
32struct zfcp_dbf_dump {
33 u8 tag[ZFCP_DBF_TAG_SIZE];
34 u32 total_size; /* size of total dump data */
35 u32 offset; /* how much data has being already dumped */
36 u32 size; /* how much data comes with this record */
37 u8 data[]; /* dump data */
38} __attribute__ ((packed));
39
Swen Schillig57717102009-08-18 15:43:21 +020040struct zfcp_dbf_rec_record_thread {
Christof Schmitt2b604c92008-03-31 11:15:28 +020041 u32 total;
42 u32 ready;
43 u32 running;
Martin Peschke73378912008-05-19 12:17:46 +020044};
Christof Schmitt2b604c92008-03-31 11:15:28 +020045
Swen Schillig57717102009-08-18 15:43:21 +020046struct zfcp_dbf_rec_record_target {
Christof Schmitt2b604c92008-03-31 11:15:28 +020047 u64 ref;
48 u32 status;
49 u32 d_id;
50 u64 wwpn;
51 u64 fcp_lun;
52 u32 erp_count;
Martin Peschke73378912008-05-19 12:17:46 +020053};
Christof Schmitt2b604c92008-03-31 11:15:28 +020054
Swen Schillig57717102009-08-18 15:43:21 +020055struct zfcp_dbf_rec_record_trigger {
Christof Schmitt2b604c92008-03-31 11:15:28 +020056 u8 want;
57 u8 need;
58 u32 as;
59 u32 ps;
60 u32 us;
61 u64 ref;
62 u64 action;
63 u64 wwpn;
64 u64 fcp_lun;
Martin Peschke73378912008-05-19 12:17:46 +020065};
Christof Schmitt2b604c92008-03-31 11:15:28 +020066
Swen Schillig57717102009-08-18 15:43:21 +020067struct zfcp_dbf_rec_record_action {
Christof Schmitt2b604c92008-03-31 11:15:28 +020068 u32 status;
69 u32 step;
70 u64 action;
71 u64 fsf_req;
Martin Peschke73378912008-05-19 12:17:46 +020072};
Christof Schmitt2b604c92008-03-31 11:15:28 +020073
Swen Schillig57717102009-08-18 15:43:21 +020074struct zfcp_dbf_rec_record {
Christof Schmitt2b604c92008-03-31 11:15:28 +020075 u8 id;
Swen Schillig5ffd51a2009-03-02 13:09:04 +010076 char id2[7];
Christof Schmitt2b604c92008-03-31 11:15:28 +020077 union {
Swen Schillig57717102009-08-18 15:43:21 +020078 struct zfcp_dbf_rec_record_action action;
79 struct zfcp_dbf_rec_record_thread thread;
80 struct zfcp_dbf_rec_record_target target;
81 struct zfcp_dbf_rec_record_trigger trigger;
Christof Schmitt2b604c92008-03-31 11:15:28 +020082 } u;
Martin Peschke73378912008-05-19 12:17:46 +020083};
Christof Schmitt2b604c92008-03-31 11:15:28 +020084
85enum {
86 ZFCP_REC_DBF_ID_ACTION,
87 ZFCP_REC_DBF_ID_THREAD,
88 ZFCP_REC_DBF_ID_TARGET,
89 ZFCP_REC_DBF_ID_TRIGGER,
90};
91
Swen Schillig57717102009-08-18 15:43:21 +020092struct zfcp_dbf_hba_record_response {
Christof Schmitt2b604c92008-03-31 11:15:28 +020093 u32 fsf_command;
94 u64 fsf_reqid;
95 u32 fsf_seqno;
96 u64 fsf_issued;
97 u32 fsf_prot_status;
98 u32 fsf_status;
99 u8 fsf_prot_status_qual[FSF_PROT_STATUS_QUAL_SIZE];
100 u8 fsf_status_qual[FSF_STATUS_QUALIFIER_SIZE];
101 u32 fsf_req_status;
102 u8 sbal_first;
Martin Peschkee891bff2008-05-19 12:17:43 +0200103 u8 sbal_last;
Martin Peschkec3baa9a22008-05-19 12:17:44 +0200104 u8 sbal_response;
Christof Schmitt2b604c92008-03-31 11:15:28 +0200105 u8 pool;
106 u64 erp_action;
107 union {
108 struct {
Martin Peschke6bc473d2008-03-31 11:15:29 +0200109 u64 cmnd;
110 u64 serial;
111 } fcp;
Christof Schmitt2b604c92008-03-31 11:15:28 +0200112 struct {
113 u64 wwpn;
114 u32 d_id;
115 u32 port_handle;
116 } port;
117 struct {
118 u64 wwpn;
119 u64 fcp_lun;
120 u32 port_handle;
121 u32 lun_handle;
122 } unit;
123 struct {
124 u32 d_id;
125 u8 ls_code;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200126 } els;
127 } u;
Christof Schmitt2b604c92008-03-31 11:15:28 +0200128} __attribute__ ((packed));
129
Swen Schillig57717102009-08-18 15:43:21 +0200130struct zfcp_dbf_hba_record_status {
Christof Schmitt2b604c92008-03-31 11:15:28 +0200131 u8 failed;
132 u32 status_type;
133 u32 status_subtype;
134 struct fsf_queue_designator
135 queue_designator;
136 u32 payload_size;
137#define ZFCP_DBF_UNSOL_PAYLOAD 80
138#define ZFCP_DBF_UNSOL_PAYLOAD_SENSE_DATA_AVAIL 32
139#define ZFCP_DBF_UNSOL_PAYLOAD_BIT_ERROR_THRESHOLD 56
140#define ZFCP_DBF_UNSOL_PAYLOAD_FEATURE_UPDATE_ALERT 2 * sizeof(u32)
141 u8 payload[ZFCP_DBF_UNSOL_PAYLOAD];
142} __attribute__ ((packed));
143
Swen Schillig57717102009-08-18 15:43:21 +0200144struct zfcp_dbf_hba_record_qdio {
Christof Schmitt2b604c92008-03-31 11:15:28 +0200145 u32 qdio_error;
Christof Schmitt2b604c92008-03-31 11:15:28 +0200146 u8 sbal_index;
147 u8 sbal_count;
148} __attribute__ ((packed));
149
Swen Schillig57717102009-08-18 15:43:21 +0200150struct zfcp_dbf_hba_record {
Christof Schmitt2b604c92008-03-31 11:15:28 +0200151 u8 tag[ZFCP_DBF_TAG_SIZE];
152 u8 tag2[ZFCP_DBF_TAG_SIZE];
153 union {
Swen Schillig57717102009-08-18 15:43:21 +0200154 struct zfcp_dbf_hba_record_response response;
155 struct zfcp_dbf_hba_record_status status;
156 struct zfcp_dbf_hba_record_qdio qdio;
Swen Schillig57069382008-10-01 12:42:21 +0200157 struct fsf_bit_error_payload berr;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200158 } u;
Christof Schmitt2b604c92008-03-31 11:15:28 +0200159} __attribute__ ((packed));
160
Swen Schillig57717102009-08-18 15:43:21 +0200161struct zfcp_dbf_san_record_ct_request {
Martin Peschke6bc473d2008-03-31 11:15:29 +0200162 u16 cmd_req_code;
163 u8 revision;
164 u8 gs_type;
165 u8 gs_subtype;
166 u8 options;
167 u16 max_res_size;
168 u32 len;
Christof Schmitt2b604c92008-03-31 11:15:28 +0200169} __attribute__ ((packed));
170
Swen Schillig57717102009-08-18 15:43:21 +0200171struct zfcp_dbf_san_record_ct_response {
Martin Peschke6bc473d2008-03-31 11:15:29 +0200172 u16 cmd_rsp_code;
173 u8 revision;
174 u8 reason_code;
175 u8 expl;
176 u8 vendor_unique;
Christof Schmitt39eb7e9a2008-12-19 16:57:01 +0100177 u16 max_res_size;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200178 u32 len;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200179} __attribute__ ((packed));
180
Swen Schillig57717102009-08-18 15:43:21 +0200181struct zfcp_dbf_san_record_els {
Christof Schmitt2b604c92008-03-31 11:15:28 +0200182 u8 ls_code;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200183 u32 len;
Christof Schmitt2b604c92008-03-31 11:15:28 +0200184} __attribute__ ((packed));
185
Swen Schillig57717102009-08-18 15:43:21 +0200186struct zfcp_dbf_san_record {
Christof Schmitt2b604c92008-03-31 11:15:28 +0200187 u8 tag[ZFCP_DBF_TAG_SIZE];
188 u64 fsf_reqid;
189 u32 fsf_seqno;
190 u32 s_id;
191 u32 d_id;
192 union {
Swen Schillig57717102009-08-18 15:43:21 +0200193 struct zfcp_dbf_san_record_ct_request ct_req;
194 struct zfcp_dbf_san_record_ct_response ct_resp;
195 struct zfcp_dbf_san_record_els els;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200196 } u;
Christof Schmittd94ce6c2008-11-04 16:35:12 +0100197#define ZFCP_DBF_SAN_MAX_PAYLOAD 1024
198 u8 payload[32];
Christof Schmitt2b604c92008-03-31 11:15:28 +0200199} __attribute__ ((packed));
200
Swen Schillig57717102009-08-18 15:43:21 +0200201struct zfcp_dbf_scsi_record {
Christof Schmitt2b604c92008-03-31 11:15:28 +0200202 u8 tag[ZFCP_DBF_TAG_SIZE];
203 u8 tag2[ZFCP_DBF_TAG_SIZE];
204 u32 scsi_id;
205 u32 scsi_lun;
206 u32 scsi_result;
207 u64 scsi_cmnd;
208 u64 scsi_serial;
209#define ZFCP_DBF_SCSI_OPCODE 16
210 u8 scsi_opcode[ZFCP_DBF_SCSI_OPCODE];
211 u8 scsi_retries;
212 u8 scsi_allowed;
213 u64 fsf_reqid;
214 u32 fsf_seqno;
215 u64 fsf_issued;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200216 u64 old_fsf_reqid;
217 u8 rsp_validity;
218 u8 rsp_scsi_status;
219 u32 rsp_resid;
220 u8 rsp_code;
Christof Schmitt2b604c92008-03-31 11:15:28 +0200221#define ZFCP_DBF_SCSI_FCP_SNS_INFO 16
222#define ZFCP_DBF_SCSI_MAX_FCP_SNS_INFO 256
Martin Peschke6bc473d2008-03-31 11:15:29 +0200223 u32 sns_info_len;
224 u8 sns_info[ZFCP_DBF_SCSI_FCP_SNS_INFO];
Christof Schmitt2b604c92008-03-31 11:15:28 +0200225} __attribute__ ((packed));
226
Christof Schmittd46f3842009-08-18 15:43:07 +0200227struct zfcp_dbf {
Swen Schillig57717102009-08-18 15:43:21 +0200228 debug_info_t *rec;
229 debug_info_t *hba;
230 debug_info_t *san;
231 debug_info_t *scsi;
232 spinlock_t rec_lock;
233 spinlock_t hba_lock;
234 spinlock_t san_lock;
235 spinlock_t scsi_lock;
236 struct zfcp_dbf_rec_record rec_buf;
237 struct zfcp_dbf_hba_record hba_buf;
238 struct zfcp_dbf_san_record san_buf;
239 struct zfcp_dbf_scsi_record scsi_buf;
240 struct zfcp_adapter *adapter;
Christof Schmittd46f3842009-08-18 15:43:07 +0200241};
242
Christof Schmittdcd20e22009-08-18 15:43:08 +0200243static inline
Swen Schillig57717102009-08-18 15:43:21 +0200244void zfcp_dbf_hba_fsf_resp(const char *tag2, int level,
245 struct zfcp_fsf_req *req, struct zfcp_dbf *dbf)
Christof Schmitt2e261af2009-08-18 15:43:09 +0200246{
Swen Schillig57717102009-08-18 15:43:21 +0200247 if (level <= dbf->hba->level)
248 _zfcp_dbf_hba_fsf_response(tag2, level, req, dbf);
Christof Schmitt2e261af2009-08-18 15:43:09 +0200249}
250
251/**
Swen Schillig57717102009-08-18 15:43:21 +0200252 * zfcp_dbf_hba_fsf_response - trace event for request completion
Christof Schmitt2e261af2009-08-18 15:43:09 +0200253 * @fsf_req: request that has been completed
254 */
Swen Schillig57717102009-08-18 15:43:21 +0200255static inline void zfcp_dbf_hba_fsf_response(struct zfcp_fsf_req *req)
Christof Schmitt2e261af2009-08-18 15:43:09 +0200256{
257 struct zfcp_dbf *dbf = req->adapter->dbf;
258 struct fsf_qtcb *qtcb = req->qtcb;
259
260 if ((qtcb->prefix.prot_status != FSF_PROT_GOOD) &&
261 (qtcb->prefix.prot_status != FSF_PROT_FSF_STATUS_PRESENTED)) {
Swen Schillig57717102009-08-18 15:43:21 +0200262 zfcp_dbf_hba_fsf_resp("perr", 1, req, dbf);
Christof Schmitt2e261af2009-08-18 15:43:09 +0200263
264 } else if (qtcb->header.fsf_status != FSF_GOOD) {
Swen Schillig57717102009-08-18 15:43:21 +0200265 zfcp_dbf_hba_fsf_resp("ferr", 1, req, dbf);
Christof Schmitt2e261af2009-08-18 15:43:09 +0200266
267 } else if ((req->fsf_command == FSF_QTCB_OPEN_PORT_WITH_DID) ||
268 (req->fsf_command == FSF_QTCB_OPEN_LUN)) {
Swen Schillig57717102009-08-18 15:43:21 +0200269 zfcp_dbf_hba_fsf_resp("open", 4, req, dbf);
Christof Schmitt2e261af2009-08-18 15:43:09 +0200270
271 } else if (qtcb->header.log_length) {
Swen Schillig57717102009-08-18 15:43:21 +0200272 zfcp_dbf_hba_fsf_resp("qtcb", 5, req, dbf);
Christof Schmitt2e261af2009-08-18 15:43:09 +0200273
274 } else {
Swen Schillig57717102009-08-18 15:43:21 +0200275 zfcp_dbf_hba_fsf_resp("norm", 6, req, dbf);
Christof Schmitt2e261af2009-08-18 15:43:09 +0200276 }
277 }
278
279/**
Swen Schillig57717102009-08-18 15:43:21 +0200280 * zfcp_dbf_hba_fsf_unsol - trace event for an unsolicited status buffer
Christof Schmitt2e261af2009-08-18 15:43:09 +0200281 * @tag: tag indicating which kind of unsolicited status has been received
Swen Schillig57717102009-08-18 15:43:21 +0200282 * @dbf: reference to dbf structure
Christof Schmitt2e261af2009-08-18 15:43:09 +0200283 * @status_buffer: buffer containing payload of unsolicited status
284 */
285static inline
Swen Schillig57717102009-08-18 15:43:21 +0200286void zfcp_dbf_hba_fsf_unsol(const char *tag, struct zfcp_dbf *dbf,
287 struct fsf_status_read_buffer *buf)
Christof Schmitt2e261af2009-08-18 15:43:09 +0200288{
Christof Schmitt2e261af2009-08-18 15:43:09 +0200289 int level = 2;
290
Swen Schillig57717102009-08-18 15:43:21 +0200291 if (level <= dbf->hba->level)
292 _zfcp_dbf_hba_fsf_unsol(tag, level, dbf, buf);
Christof Schmitt2e261af2009-08-18 15:43:09 +0200293}
294
295static inline
Swen Schillig57717102009-08-18 15:43:21 +0200296void zfcp_dbf_scsi(const char *tag, const char *tag2, int level,
297 struct zfcp_dbf *dbf, struct scsi_cmnd *scmd,
298 struct zfcp_fsf_req *req, unsigned long old_id)
Christof Schmittdcd20e22009-08-18 15:43:08 +0200299{
Swen Schillig57717102009-08-18 15:43:21 +0200300 if (level <= dbf->scsi->level)
301 _zfcp_dbf_scsi(tag, tag2, level, dbf, scmd, req, old_id);
Christof Schmittdcd20e22009-08-18 15:43:08 +0200302}
303
304/**
Swen Schillig57717102009-08-18 15:43:21 +0200305 * zfcp_dbf_scsi_result - trace event for SCSI command completion
Christof Schmittdcd20e22009-08-18 15:43:08 +0200306 * @tag: tag indicating success or failure of SCSI command
307 * @level: trace level applicable for this event
308 * @adapter: adapter that has been used to issue the SCSI command
309 * @scmd: SCSI command pointer
310 * @fsf_req: request used to issue SCSI command (might be NULL)
311 */
312static inline
Swen Schillig57717102009-08-18 15:43:21 +0200313void zfcp_dbf_scsi_result(const char *tag, int level, struct zfcp_dbf *dbf,
314 struct scsi_cmnd *scmd, struct zfcp_fsf_req *fsf_req)
Christof Schmittdcd20e22009-08-18 15:43:08 +0200315{
Swen Schillig57717102009-08-18 15:43:21 +0200316 zfcp_dbf_scsi("rslt", tag, level, dbf, scmd, fsf_req, 0);
Christof Schmittdcd20e22009-08-18 15:43:08 +0200317}
318
319/**
Swen Schillig57717102009-08-18 15:43:21 +0200320 * zfcp_dbf_scsi_abort - trace event for SCSI command abort
Christof Schmittdcd20e22009-08-18 15:43:08 +0200321 * @tag: tag indicating success or failure of abort operation
322 * @adapter: adapter thas has been used to issue SCSI command to be aborted
323 * @scmd: SCSI command to be aborted
324 * @new_req: request containing abort (might be NULL)
325 * @old_id: identifier of request containg SCSI command to be aborted
326 */
327static inline
Swen Schillig57717102009-08-18 15:43:21 +0200328void zfcp_dbf_scsi_abort(const char *tag, struct zfcp_dbf *dbf,
329 struct scsi_cmnd *scmd, struct zfcp_fsf_req *new_req,
330 unsigned long old_id)
Christof Schmittdcd20e22009-08-18 15:43:08 +0200331{
Swen Schillig57717102009-08-18 15:43:21 +0200332 zfcp_dbf_scsi("abrt", tag, 1, dbf, scmd, new_req, old_id);
Christof Schmittdcd20e22009-08-18 15:43:08 +0200333}
334
335/**
Swen Schillig57717102009-08-18 15:43:21 +0200336 * zfcp_dbf_scsi_devreset - trace event for Logical Unit or Target Reset
Christof Schmittdcd20e22009-08-18 15:43:08 +0200337 * @tag: tag indicating success or failure of reset operation
338 * @flag: indicates type of reset (Target Reset, Logical Unit Reset)
339 * @unit: unit that needs reset
340 * @scsi_cmnd: SCSI command which caused this error recovery
341 */
342static inline
Swen Schillig57717102009-08-18 15:43:21 +0200343void zfcp_dbf_scsi_devreset(const char *tag, u8 flag, struct zfcp_unit *unit,
344 struct scsi_cmnd *scsi_cmnd)
Christof Schmittdcd20e22009-08-18 15:43:08 +0200345{
Swen Schillig57717102009-08-18 15:43:21 +0200346 zfcp_dbf_scsi(flag == FCP_TARGET_RESET ? "trst" : "lrst", tag, 1,
347 unit->port->adapter->dbf, scsi_cmnd, NULL, 0);
Christof Schmittdcd20e22009-08-18 15:43:08 +0200348}
349
Christof Schmitt2b604c92008-03-31 11:15:28 +0200350#endif /* ZFCP_DBF_H */