blob: 7e85e87b0ededb820591009e958dee00b0215691 [file] [log] [blame]
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001/*
Andreas Herrmann4a9d2d82006-05-22 18:14:08 +02002 * This file is part of the zfcp device driver for
3 * FCP adapters for IBM System z9 and zSeries.
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004 *
Andreas Herrmann4a9d2d82006-05-22 18:14:08 +02005 * (C) Copyright IBM Corp. 2002, 2006
Maxim Shchetynin8a36e452005-09-13 21:50:38 +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
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020022#include <linux/ctype.h>
Heiko Carstens364c8552007-10-12 16:11:35 +020023#include <asm/debug.h>
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020024#include "zfcp_ext.h"
25
26static u32 dbfsize = 4;
27
28module_param(dbfsize, uint, 0400);
29MODULE_PARM_DESC(dbfsize,
30 "number of pages for each debug feature area (default 4)");
31
32#define ZFCP_LOG_AREA ZFCP_LOG_AREA_OTHER
33
Martin Peschkec15450e2008-03-27 14:21:55 +010034static void zfcp_dbf_hexdump(debug_info_t *dbf, void *to, int to_len,
35 int level, char *from, int from_len)
36{
37 int offset;
38 struct zfcp_dbf_dump *dump = to;
39 int room = to_len - sizeof(*dump);
40
41 for (offset = 0; offset < from_len; offset += dump->size) {
42 memset(to, 0, to_len);
43 strncpy(dump->tag, "dump", ZFCP_DBF_TAG_SIZE);
44 dump->total_size = from_len;
45 dump->offset = offset;
46 dump->size = min(from_len - offset, room);
47 memcpy(dump->data, from + offset, dump->size);
48 debug_event(dbf, level, dump, dump->size);
49 }
50}
51
Martin Peschke8fc5af12008-03-31 11:15:23 +020052/* FIXME: this duplicate this code in s390 debug feature */
53static void zfcp_dbf_timestamp(unsigned long long stck, struct timespec *time)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020054{
55 unsigned long long sec;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020056
57 stck -= 0x8126d60e46000000LL - (0x3c26700LL * 1000000 * 4096);
58 sec = stck >> 12;
59 do_div(sec, 1000000);
Martin Peschke8fc5af12008-03-31 11:15:23 +020060 time->tv_sec = sec;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020061 stck -= (sec * 1000000) << 12;
Martin Peschke8fc5af12008-03-31 11:15:23 +020062 time->tv_nsec = ((stck * 1000) >> 12);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020063}
64
Martin Peschkea9c85772008-03-31 11:15:27 +020065static void zfcp_dbf_tag(char **p, const char *label, const char *tag)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020066{
Martin Peschkea9c85772008-03-31 11:15:27 +020067 int i;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020068
Martin Peschkea9c85772008-03-31 11:15:27 +020069 *p += sprintf(*p, "%-24s", label);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020070 for (i = 0; i < ZFCP_DBF_TAG_SIZE; i++)
Martin Peschkea9c85772008-03-31 11:15:27 +020071 *p += sprintf(*p, "%c", tag[i]);
72 *p += sprintf(*p, "\n");
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020073}
74
Martin Peschke10223c62008-03-27 14:21:59 +010075static void zfcp_dbf_outs(char **buf, const char *s1, const char *s2)
76{
77 *buf += sprintf(*buf, "%-24s%s\n", s1, s2);
78}
79
80static void zfcp_dbf_out(char **buf, const char *s, const char *format, ...)
81{
82 va_list arg;
83
84 *buf += sprintf(*buf, "%-24s", s);
85 va_start(arg, format);
86 *buf += vsprintf(*buf, format, arg);
87 va_end(arg);
88 *buf += sprintf(*buf, "\n");
89}
90
Martin Peschkedf29f4a2008-03-31 11:15:26 +020091static void zfcp_dbf_outd(char **p, const char *label, char *buffer,
92 int buflen, int offset, int total_size)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020093{
Martin Peschkedf29f4a2008-03-31 11:15:26 +020094 if (!offset)
95 *p += sprintf(*p, "%-24s ", label);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020096 while (buflen--) {
97 if (offset > 0) {
98 if ((offset % 32) == 0)
Martin Peschkedf29f4a2008-03-31 11:15:26 +020099 *p += sprintf(*p, "\n%-24c ", ' ');
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200100 else if ((offset % 4) == 0)
Martin Peschkedf29f4a2008-03-31 11:15:26 +0200101 *p += sprintf(*p, " ");
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200102 }
Martin Peschkedf29f4a2008-03-31 11:15:26 +0200103 *p += sprintf(*p, "%02x", *buffer++);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200104 if (++offset == total_size) {
Martin Peschkedf29f4a2008-03-31 11:15:26 +0200105 *p += sprintf(*p, "\n");
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200106 break;
107 }
108 }
Martin Peschkedf29f4a2008-03-31 11:15:26 +0200109 if (!total_size)
110 *p += sprintf(*p, "\n");
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200111}
112
Martin Peschke92c7a832008-03-31 11:15:30 +0200113static int zfcp_dbf_view_header(debug_info_t *id, struct debug_view *view,
114 int area, debug_entry_t *entry, char *out_buf)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200115{
116 struct zfcp_dbf_dump *dump = (struct zfcp_dbf_dump *)DEBUG_DATA(entry);
Martin Peschke8fc5af12008-03-31 11:15:23 +0200117 struct timespec t;
Martin Peschkeb634fff2008-03-31 11:15:24 +0200118 char *p = out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200119
120 if (strncmp(dump->tag, "dump", ZFCP_DBF_TAG_SIZE) != 0) {
Martin Peschke8fc5af12008-03-31 11:15:23 +0200121 zfcp_dbf_timestamp(entry->id.stck, &t);
Martin Peschkeb634fff2008-03-31 11:15:24 +0200122 zfcp_dbf_out(&p, "timestamp", "%011lu:%06lu",
123 t.tv_sec, t.tv_nsec);
124 zfcp_dbf_out(&p, "cpu", "%02i", entry->id.fields.cpuid);
125 } else {
Martin Peschkedf29f4a2008-03-31 11:15:26 +0200126 zfcp_dbf_outd(&p, NULL, dump->data, dump->size, dump->offset,
127 dump->total_size);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200128 if ((dump->offset + dump->size) == dump->total_size)
Martin Peschkeb634fff2008-03-31 11:15:24 +0200129 p += sprintf(p, "\n");
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200130 }
Martin Peschkeb634fff2008-03-31 11:15:24 +0200131 return p - out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200132}
133
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100134void zfcp_hba_dbf_event_fsf_response(struct zfcp_fsf_req *fsf_req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200135{
136 struct zfcp_adapter *adapter = fsf_req->adapter;
137 struct fsf_qtcb *qtcb = fsf_req->qtcb;
138 union fsf_prot_status_qual *prot_status_qual =
Martin Peschke92c7a832008-03-31 11:15:30 +0200139 &qtcb->prefix.prot_status_qual;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200140 union fsf_status_qual *fsf_status_qual = &qtcb->header.fsf_status_qual;
141 struct scsi_cmnd *scsi_cmnd;
142 struct zfcp_port *port;
143 struct zfcp_unit *unit;
144 struct zfcp_send_els *send_els;
145 struct zfcp_hba_dbf_record *rec = &adapter->hba_dbf_buf;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200146 struct zfcp_hba_dbf_record_response *response = &rec->u.response;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200147 int level;
148 unsigned long flags;
149
150 spin_lock_irqsave(&adapter->hba_dbf_lock, flags);
Martin Peschke6bc473d2008-03-31 11:15:29 +0200151 memset(rec, 0, sizeof(*rec));
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200152 strncpy(rec->tag, "resp", ZFCP_DBF_TAG_SIZE);
153
154 if ((qtcb->prefix.prot_status != FSF_PROT_GOOD) &&
155 (qtcb->prefix.prot_status != FSF_PROT_FSF_STATUS_PRESENTED)) {
156 strncpy(rec->tag2, "perr", ZFCP_DBF_TAG_SIZE);
157 level = 1;
158 } else if (qtcb->header.fsf_status != FSF_GOOD) {
159 strncpy(rec->tag2, "ferr", ZFCP_DBF_TAG_SIZE);
160 level = 1;
161 } else if ((fsf_req->fsf_command == FSF_QTCB_OPEN_PORT_WITH_DID) ||
162 (fsf_req->fsf_command == FSF_QTCB_OPEN_LUN)) {
163 strncpy(rec->tag2, "open", ZFCP_DBF_TAG_SIZE);
164 level = 4;
Martin Peschkeb75db732008-03-27 14:21:58 +0100165 } else if (qtcb->header.log_length) {
166 strncpy(rec->tag2, "qtcb", ZFCP_DBF_TAG_SIZE);
167 level = 5;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200168 } else {
169 strncpy(rec->tag2, "norm", ZFCP_DBF_TAG_SIZE);
170 level = 6;
171 }
172
173 response->fsf_command = fsf_req->fsf_command;
174 response->fsf_reqid = (unsigned long)fsf_req;
175 response->fsf_seqno = fsf_req->seq_no;
176 response->fsf_issued = fsf_req->issued;
177 response->fsf_prot_status = qtcb->prefix.prot_status;
178 response->fsf_status = qtcb->header.fsf_status;
179 memcpy(response->fsf_prot_status_qual,
180 prot_status_qual, FSF_PROT_STATUS_QUAL_SIZE);
181 memcpy(response->fsf_status_qual,
182 fsf_status_qual, FSF_STATUS_QUALIFIER_SIZE);
183 response->fsf_req_status = fsf_req->status;
184 response->sbal_first = fsf_req->sbal_first;
185 response->sbal_curr = fsf_req->sbal_curr;
186 response->sbal_last = fsf_req->sbal_last;
187 response->pool = fsf_req->pool != NULL;
188 response->erp_action = (unsigned long)fsf_req->erp_action;
189
190 switch (fsf_req->fsf_command) {
191 case FSF_QTCB_FCP_CMND:
192 if (fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT)
193 break;
194 scsi_cmnd = (struct scsi_cmnd *)fsf_req->data;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200195 if (scsi_cmnd) {
196 response->u.fcp.cmnd = (unsigned long)scsi_cmnd;
197 response->u.fcp.serial = scsi_cmnd->serial_number;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200198 }
199 break;
200
201 case FSF_QTCB_OPEN_PORT_WITH_DID:
202 case FSF_QTCB_CLOSE_PORT:
203 case FSF_QTCB_CLOSE_PHYSICAL_PORT:
204 port = (struct zfcp_port *)fsf_req->data;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200205 response->u.port.wwpn = port->wwpn;
206 response->u.port.d_id = port->d_id;
207 response->u.port.port_handle = qtcb->header.port_handle;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200208 break;
209
210 case FSF_QTCB_OPEN_LUN:
211 case FSF_QTCB_CLOSE_LUN:
212 unit = (struct zfcp_unit *)fsf_req->data;
213 port = unit->port;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200214 response->u.unit.wwpn = port->wwpn;
215 response->u.unit.fcp_lun = unit->fcp_lun;
216 response->u.unit.port_handle = qtcb->header.port_handle;
217 response->u.unit.lun_handle = qtcb->header.lun_handle;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200218 break;
219
220 case FSF_QTCB_SEND_ELS:
221 send_els = (struct zfcp_send_els *)fsf_req->data;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200222 response->u.els.d_id = qtcb->bottom.support.d_id;
223 response->u.els.ls_code = send_els->ls_code >> 24;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200224 break;
225
226 case FSF_QTCB_ABORT_FCP_CMND:
227 case FSF_QTCB_SEND_GENERIC:
228 case FSF_QTCB_EXCHANGE_CONFIG_DATA:
229 case FSF_QTCB_EXCHANGE_PORT_DATA:
230 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
231 case FSF_QTCB_UPLOAD_CONTROL_FILE:
232 break;
233 }
234
Martin Peschke6bc473d2008-03-31 11:15:29 +0200235 debug_event(adapter->hba_dbf, level, rec, sizeof(*rec));
Martin Peschkeb75db732008-03-27 14:21:58 +0100236
237 /* have fcp channel microcode fixed to use as little as possible */
238 if (fsf_req->fsf_command != FSF_QTCB_FCP_CMND) {
239 /* adjust length skipping trailing zeros */
240 char *buf = (char *)qtcb + qtcb->header.log_start;
241 int len = qtcb->header.log_length;
242 for (; len && !buf[len - 1]; len--);
243 zfcp_dbf_hexdump(adapter->hba_dbf, rec, sizeof(*rec), level,
244 buf, len);
245 }
246
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200247 spin_unlock_irqrestore(&adapter->hba_dbf_lock, flags);
248}
249
Martin Peschke92c7a832008-03-31 11:15:30 +0200250void zfcp_hba_dbf_event_fsf_unsol(const char *tag, struct zfcp_adapter *adapter,
251 struct fsf_status_read_buffer *status_buffer)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200252{
253 struct zfcp_hba_dbf_record *rec = &adapter->hba_dbf_buf;
254 unsigned long flags;
255
256 spin_lock_irqsave(&adapter->hba_dbf_lock, flags);
Martin Peschke6bc473d2008-03-31 11:15:29 +0200257 memset(rec, 0, sizeof(*rec));
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200258 strncpy(rec->tag, "stat", ZFCP_DBF_TAG_SIZE);
259 strncpy(rec->tag2, tag, ZFCP_DBF_TAG_SIZE);
260
Martin Peschke6bc473d2008-03-31 11:15:29 +0200261 rec->u.status.failed = adapter->status_read_failed;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200262 if (status_buffer != NULL) {
Martin Peschke6bc473d2008-03-31 11:15:29 +0200263 rec->u.status.status_type = status_buffer->status_type;
264 rec->u.status.status_subtype = status_buffer->status_subtype;
265 memcpy(&rec->u.status.queue_designator,
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200266 &status_buffer->queue_designator,
267 sizeof(struct fsf_queue_designator));
268
269 switch (status_buffer->status_type) {
270 case FSF_STATUS_READ_SENSE_DATA_AVAIL:
Martin Peschke6bc473d2008-03-31 11:15:29 +0200271 rec->u.status.payload_size =
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200272 ZFCP_DBF_UNSOL_PAYLOAD_SENSE_DATA_AVAIL;
273 break;
274
275 case FSF_STATUS_READ_BIT_ERROR_THRESHOLD:
Martin Peschke6bc473d2008-03-31 11:15:29 +0200276 rec->u.status.payload_size =
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200277 ZFCP_DBF_UNSOL_PAYLOAD_BIT_ERROR_THRESHOLD;
278 break;
279
280 case FSF_STATUS_READ_LINK_DOWN:
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200281 switch (status_buffer->status_subtype) {
282 case FSF_STATUS_READ_SUB_NO_PHYSICAL_LINK:
283 case FSF_STATUS_READ_SUB_FDISC_FAILED:
Martin Peschke6bc473d2008-03-31 11:15:29 +0200284 rec->u.status.payload_size =
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200285 sizeof(struct fsf_link_down_info);
286 }
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200287 break;
288
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200289 case FSF_STATUS_READ_FEATURE_UPDATE_ALERT:
Martin Peschke6bc473d2008-03-31 11:15:29 +0200290 rec->u.status.payload_size =
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200291 ZFCP_DBF_UNSOL_PAYLOAD_FEATURE_UPDATE_ALERT;
292 break;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200293 }
Martin Peschke6bc473d2008-03-31 11:15:29 +0200294 memcpy(&rec->u.status.payload,
295 &status_buffer->payload, rec->u.status.payload_size);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200296 }
297
Martin Peschke6bc473d2008-03-31 11:15:29 +0200298 debug_event(adapter->hba_dbf, 2, rec, sizeof(*rec));
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200299 spin_unlock_irqrestore(&adapter->hba_dbf_lock, flags);
300}
301
Martin Peschke92c7a832008-03-31 11:15:30 +0200302void zfcp_hba_dbf_event_qdio(struct zfcp_adapter *adapter, unsigned int status,
303 unsigned int qdio_error, unsigned int siga_error,
304 int sbal_index, int sbal_count)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200305{
Martin Peschke6bc473d2008-03-31 11:15:29 +0200306 struct zfcp_hba_dbf_record *r = &adapter->hba_dbf_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200307 unsigned long flags;
308
309 spin_lock_irqsave(&adapter->hba_dbf_lock, flags);
Martin Peschke6bc473d2008-03-31 11:15:29 +0200310 memset(r, 0, sizeof(*r));
311 strncpy(r->tag, "qdio", ZFCP_DBF_TAG_SIZE);
312 r->u.qdio.status = status;
313 r->u.qdio.qdio_error = qdio_error;
314 r->u.qdio.siga_error = siga_error;
315 r->u.qdio.sbal_index = sbal_index;
316 r->u.qdio.sbal_count = sbal_count;
317 debug_event(adapter->hba_dbf, 0, r, sizeof(*r));
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200318 spin_unlock_irqrestore(&adapter->hba_dbf_lock, flags);
319}
320
Martin Peschkea9c85772008-03-31 11:15:27 +0200321static void zfcp_hba_dbf_view_response(char **p,
322 struct zfcp_hba_dbf_record_response *r)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200323{
Martin Peschke8fc5af12008-03-31 11:15:23 +0200324 struct timespec t;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200325
Martin Peschkea9c85772008-03-31 11:15:27 +0200326 zfcp_dbf_out(p, "fsf_command", "0x%08x", r->fsf_command);
327 zfcp_dbf_out(p, "fsf_reqid", "0x%0Lx", r->fsf_reqid);
328 zfcp_dbf_out(p, "fsf_seqno", "0x%08x", r->fsf_seqno);
Martin Peschkeb634fff2008-03-31 11:15:24 +0200329 zfcp_dbf_timestamp(r->fsf_issued, &t);
Martin Peschkea9c85772008-03-31 11:15:27 +0200330 zfcp_dbf_out(p, "fsf_issued", "%011lu:%06lu", t.tv_sec, t.tv_nsec);
331 zfcp_dbf_out(p, "fsf_prot_status", "0x%08x", r->fsf_prot_status);
332 zfcp_dbf_out(p, "fsf_status", "0x%08x", r->fsf_status);
333 zfcp_dbf_outd(p, "fsf_prot_status_qual", r->fsf_prot_status_qual,
Martin Peschkedf29f4a2008-03-31 11:15:26 +0200334 FSF_PROT_STATUS_QUAL_SIZE, 0, FSF_PROT_STATUS_QUAL_SIZE);
Martin Peschkea9c85772008-03-31 11:15:27 +0200335 zfcp_dbf_outd(p, "fsf_status_qual", r->fsf_status_qual,
Martin Peschkedf29f4a2008-03-31 11:15:26 +0200336 FSF_STATUS_QUALIFIER_SIZE, 0, FSF_STATUS_QUALIFIER_SIZE);
Martin Peschkea9c85772008-03-31 11:15:27 +0200337 zfcp_dbf_out(p, "fsf_req_status", "0x%08x", r->fsf_req_status);
338 zfcp_dbf_out(p, "sbal_first", "0x%02x", r->sbal_first);
339 zfcp_dbf_out(p, "sbal_curr", "0x%02x", r->sbal_curr);
340 zfcp_dbf_out(p, "sbal_last", "0x%02x", r->sbal_last);
341 zfcp_dbf_out(p, "pool", "0x%02x", r->pool);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200342
Martin Peschkeb634fff2008-03-31 11:15:24 +0200343 switch (r->fsf_command) {
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200344 case FSF_QTCB_FCP_CMND:
Martin Peschkeb634fff2008-03-31 11:15:24 +0200345 if (r->fsf_req_status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200346 break;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200347 zfcp_dbf_out(p, "scsi_cmnd", "0x%0Lx", r->u.fcp.cmnd);
348 zfcp_dbf_out(p, "scsi_serial", "0x%016Lx", r->u.fcp.serial);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200349 break;
350
351 case FSF_QTCB_OPEN_PORT_WITH_DID:
352 case FSF_QTCB_CLOSE_PORT:
353 case FSF_QTCB_CLOSE_PHYSICAL_PORT:
Martin Peschke6bc473d2008-03-31 11:15:29 +0200354 zfcp_dbf_out(p, "wwpn", "0x%016Lx", r->u.port.wwpn);
355 zfcp_dbf_out(p, "d_id", "0x%06x", r->u.port.d_id);
356 zfcp_dbf_out(p, "port_handle", "0x%08x", r->u.port.port_handle);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200357 break;
358
359 case FSF_QTCB_OPEN_LUN:
360 case FSF_QTCB_CLOSE_LUN:
Martin Peschke6bc473d2008-03-31 11:15:29 +0200361 zfcp_dbf_out(p, "wwpn", "0x%016Lx", r->u.unit.wwpn);
362 zfcp_dbf_out(p, "fcp_lun", "0x%016Lx", r->u.unit.fcp_lun);
363 zfcp_dbf_out(p, "port_handle", "0x%08x", r->u.unit.port_handle);
364 zfcp_dbf_out(p, "lun_handle", "0x%08x", r->u.unit.lun_handle);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200365 break;
366
367 case FSF_QTCB_SEND_ELS:
Martin Peschke6bc473d2008-03-31 11:15:29 +0200368 zfcp_dbf_out(p, "d_id", "0x%06x", r->u.els.d_id);
369 zfcp_dbf_out(p, "ls_code", "0x%02x", r->u.els.ls_code);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200370 break;
371
372 case FSF_QTCB_ABORT_FCP_CMND:
373 case FSF_QTCB_SEND_GENERIC:
374 case FSF_QTCB_EXCHANGE_CONFIG_DATA:
375 case FSF_QTCB_EXCHANGE_PORT_DATA:
376 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
377 case FSF_QTCB_UPLOAD_CONTROL_FILE:
378 break;
379 }
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200380}
381
Martin Peschkea9c85772008-03-31 11:15:27 +0200382static void zfcp_hba_dbf_view_status(char **p,
383 struct zfcp_hba_dbf_record_status *r)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200384{
Martin Peschkea9c85772008-03-31 11:15:27 +0200385 zfcp_dbf_out(p, "failed", "0x%02x", r->failed);
386 zfcp_dbf_out(p, "status_type", "0x%08x", r->status_type);
387 zfcp_dbf_out(p, "status_subtype", "0x%08x", r->status_subtype);
388 zfcp_dbf_outd(p, "queue_designator", (char *)&r->queue_designator,
Martin Peschkedf29f4a2008-03-31 11:15:26 +0200389 sizeof(struct fsf_queue_designator), 0,
390 sizeof(struct fsf_queue_designator));
Martin Peschkea9c85772008-03-31 11:15:27 +0200391 zfcp_dbf_outd(p, "payload", (char *)&r->payload, r->payload_size, 0,
Martin Peschkedf29f4a2008-03-31 11:15:26 +0200392 r->payload_size);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200393}
394
Martin Peschkea9c85772008-03-31 11:15:27 +0200395static void zfcp_hba_dbf_view_qdio(char **p, struct zfcp_hba_dbf_record_qdio *r)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200396{
Martin Peschkea9c85772008-03-31 11:15:27 +0200397 zfcp_dbf_out(p, "status", "0x%08x", r->status);
398 zfcp_dbf_out(p, "qdio_error", "0x%08x", r->qdio_error);
399 zfcp_dbf_out(p, "siga_error", "0x%08x", r->siga_error);
400 zfcp_dbf_out(p, "sbal_index", "0x%02x", r->sbal_index);
401 zfcp_dbf_out(p, "sbal_count", "0x%02x", r->sbal_count);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200402}
403
Martin Peschkea9c85772008-03-31 11:15:27 +0200404static int zfcp_hba_dbf_view_format(debug_info_t *id, struct debug_view *view,
405 char *out_buf, const char *in_buf)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200406{
Martin Peschkea9c85772008-03-31 11:15:27 +0200407 struct zfcp_hba_dbf_record *r = (struct zfcp_hba_dbf_record *)in_buf;
408 char *p = out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200409
Martin Peschkea9c85772008-03-31 11:15:27 +0200410 if (strncmp(r->tag, "dump", ZFCP_DBF_TAG_SIZE) == 0)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200411 return 0;
412
Martin Peschkea9c85772008-03-31 11:15:27 +0200413 zfcp_dbf_tag(&p, "tag", r->tag);
414 if (isalpha(r->tag2[0]))
415 zfcp_dbf_tag(&p, "tag2", r->tag2);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200416
Martin Peschkea9c85772008-03-31 11:15:27 +0200417 if (strncmp(r->tag, "resp", ZFCP_DBF_TAG_SIZE) == 0)
Martin Peschke6bc473d2008-03-31 11:15:29 +0200418 zfcp_hba_dbf_view_response(&p, &r->u.response);
Martin Peschkea9c85772008-03-31 11:15:27 +0200419 else if (strncmp(r->tag, "stat", ZFCP_DBF_TAG_SIZE) == 0)
Martin Peschke6bc473d2008-03-31 11:15:29 +0200420 zfcp_hba_dbf_view_status(&p, &r->u.status);
Martin Peschkea9c85772008-03-31 11:15:27 +0200421 else if (strncmp(r->tag, "qdio", ZFCP_DBF_TAG_SIZE) == 0)
Martin Peschke6bc473d2008-03-31 11:15:29 +0200422 zfcp_hba_dbf_view_qdio(&p, &r->u.qdio);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200423
Martin Peschkea9c85772008-03-31 11:15:27 +0200424 p += sprintf(p, "\n");
425 return p - out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200426}
427
Heiko Carstens2b67fc42007-02-05 21:16:47 +0100428static struct debug_view zfcp_hba_dbf_view = {
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200429 "structured",
430 NULL,
431 &zfcp_dbf_view_header,
432 &zfcp_hba_dbf_view_format,
433 NULL,
434 NULL
435};
436
Martin Peschked79a83d2008-03-27 14:22:00 +0100437static const char *zfcp_rec_dbf_tags[] = {
Martin Peschke348447e2008-03-27 14:22:01 +0100438 [ZFCP_REC_DBF_ID_THREAD] = "thread",
Martin Peschke698ec0162008-03-27 14:22:02 +0100439 [ZFCP_REC_DBF_ID_TARGET] = "target",
Martin Peschke9467a9b2008-03-27 14:22:03 +0100440 [ZFCP_REC_DBF_ID_TRIGGER] = "trigger",
Martin Peschke6f4f3652008-03-27 14:22:04 +0100441 [ZFCP_REC_DBF_ID_ACTION] = "action",
Martin Peschked79a83d2008-03-27 14:22:00 +0100442};
443
444static const char *zfcp_rec_dbf_ids[] = {
Martin Peschke348447e2008-03-27 14:22:01 +0100445 [1] = "new",
446 [2] = "ready",
447 [3] = "kill",
448 [4] = "down sleep",
449 [5] = "down wakeup",
450 [6] = "down sleep ecd",
451 [7] = "down wakeup ecd",
452 [8] = "down sleep epd",
453 [9] = "down wakeup epd",
Martin Peschke698ec0162008-03-27 14:22:02 +0100454 [10] = "online",
455 [11] = "operational",
456 [12] = "scsi slave destroy",
457 [13] = "propagate failed adapter",
458 [14] = "propagate failed port",
459 [15] = "block adapter",
460 [16] = "unblock adapter",
461 [17] = "block port",
462 [18] = "unblock port",
463 [19] = "block unit",
464 [20] = "unblock unit",
465 [21] = "unit recovery failed",
466 [22] = "port recovery failed",
467 [23] = "adapter recovery failed",
468 [24] = "qdio queues down",
469 [25] = "p2p failed",
470 [26] = "nameserver lookup failed",
471 [27] = "nameserver port failed",
472 [28] = "link up",
473 [29] = "link down",
474 [30] = "link up status read",
475 [31] = "open port failed",
476 [32] = "open port failed",
477 [33] = "close port",
478 [34] = "open unit failed",
479 [35] = "exclusive open unit failed",
480 [36] = "shared open unit failed",
481 [37] = "link down",
482 [38] = "link down status read no link",
483 [39] = "link down status read fdisc login",
484 [40] = "link down status read firmware update",
485 [41] = "link down status read unknown reason",
486 [42] = "link down ecd incomplete",
487 [43] = "link down epd incomplete",
488 [44] = "sysfs adapter recovery",
489 [45] = "sysfs port recovery",
490 [46] = "sysfs unit recovery",
491 [47] = "port boxed abort",
492 [48] = "unit boxed abort",
493 [49] = "port boxed ct",
494 [50] = "port boxed close physical",
495 [51] = "port boxed open unit",
496 [52] = "port boxed close unit",
497 [53] = "port boxed fcp",
498 [54] = "unit boxed fcp",
499 [55] = "port access denied ct",
500 [56] = "port access denied els",
501 [57] = "port access denied open port",
502 [58] = "port access denied close physical",
503 [59] = "unit access denied open unit",
504 [60] = "shared unit access denied open unit",
505 [61] = "unit access denied fcp",
Martin Peschke9467a9b2008-03-27 14:22:03 +0100506 [62] = "request timeout",
507 [63] = "adisc link test reject or timeout",
508 [64] = "adisc link test d_id changed",
509 [65] = "adisc link test failed",
510 [66] = "recovery out of memory",
511 [67] = "adapter recovery repeated after state change",
512 [68] = "port recovery repeated after state change",
513 [69] = "unit recovery repeated after state change",
514 [70] = "port recovery follow-up after successful adapter recovery",
515 [71] = "adapter recovery escalation after failed adapter recovery",
516 [72] = "port recovery follow-up after successful physical port "
517 "recovery",
518 [73] = "adapter recovery escalation after failed physical port "
519 "recovery",
520 [74] = "unit recovery follow-up after successful port recovery",
521 [75] = "physical port recovery escalation after failed port "
522 "recovery",
523 [76] = "port recovery escalation after failed unit recovery",
524 [77] = "recovery opening nameserver port",
525 [78] = "duplicate request id",
526 [79] = "link down",
527 [80] = "exclusive read-only unit access unsupported",
528 [81] = "shared read-write unit access unsupported",
529 [82] = "incoming rscn",
530 [83] = "incoming plogi",
531 [84] = "incoming logo",
532 [85] = "online",
533 [86] = "offline",
534 [87] = "ccw device gone",
535 [88] = "ccw device no path",
536 [89] = "ccw device operational",
537 [90] = "ccw device shutdown",
538 [91] = "sysfs port addition",
539 [92] = "sysfs port removal",
540 [93] = "sysfs adapter recovery",
541 [94] = "sysfs unit addition",
542 [95] = "sysfs unit removal",
543 [96] = "sysfs port recovery",
544 [97] = "sysfs unit recovery",
545 [98] = "sequence number mismatch",
546 [99] = "link up",
547 [100] = "error state",
548 [101] = "status read physical port closed",
549 [102] = "link up status read",
550 [103] = "too many failed status read buffers",
551 [104] = "port handle not valid abort",
552 [105] = "lun handle not valid abort",
553 [106] = "port handle not valid ct",
554 [107] = "port handle not valid close port",
555 [108] = "port handle not valid close physical port",
556 [109] = "port handle not valid open unit",
557 [110] = "port handle not valid close unit",
558 [111] = "lun handle not valid close unit",
559 [112] = "port handle not valid fcp",
560 [113] = "lun handle not valid fcp",
561 [114] = "handle mismatch fcp",
562 [115] = "lun not valid fcp",
563 [116] = "qdio send failed",
564 [117] = "version mismatch",
565 [118] = "incompatible qtcb type",
566 [119] = "unknown protocol status",
567 [120] = "unknown fsf command",
568 [121] = "no recommendation for status qualifier",
569 [122] = "status read physical port closed in error",
570 [123] = "fc service class not supported ct",
571 [124] = "fc service class not supported els",
572 [125] = "need newer zfcp",
573 [126] = "need newer microcode",
574 [127] = "arbitrated loop not supported",
575 [128] = "unknown topology",
576 [129] = "qtcb size mismatch",
577 [130] = "unknown fsf status ecd",
578 [131] = "fcp request too big",
579 [132] = "fc service class not supported fcp",
580 [133] = "data direction not valid fcp",
581 [134] = "command length not valid fcp",
582 [135] = "status read act update",
583 [136] = "status read cfdc update",
584 [137] = "hbaapi port open",
585 [138] = "hbaapi unit open",
586 [139] = "hbaapi unit shutdown",
587 [140] = "qdio error",
588 [141] = "scsi host reset",
Martin Peschke6f4f3652008-03-27 14:22:04 +0100589 [142] = "dismissing fsf request for recovery action",
590 [143] = "recovery action timed out",
591 [144] = "recovery action gone",
592 [145] = "recovery action being processed",
593 [146] = "recovery action ready for next step",
Martin Peschked79a83d2008-03-27 14:22:00 +0100594};
595
596static int zfcp_rec_dbf_view_format(debug_info_t *id, struct debug_view *view,
597 char *buf, const char *_rec)
598{
599 struct zfcp_rec_dbf_record *r = (struct zfcp_rec_dbf_record *)_rec;
600 char *p = buf;
601
602 zfcp_dbf_outs(&p, "tag", zfcp_rec_dbf_tags[r->id]);
603 zfcp_dbf_outs(&p, "hint", zfcp_rec_dbf_ids[r->id2]);
604 zfcp_dbf_out(&p, "id", "%d", r->id2);
605 switch (r->id) {
Martin Peschke348447e2008-03-27 14:22:01 +0100606 case ZFCP_REC_DBF_ID_THREAD:
607 zfcp_dbf_out(&p, "sema", "%d", r->u.thread.sema);
608 zfcp_dbf_out(&p, "total", "%d", r->u.thread.total);
609 zfcp_dbf_out(&p, "ready", "%d", r->u.thread.ready);
610 zfcp_dbf_out(&p, "running", "%d", r->u.thread.running);
611 break;
Martin Peschke698ec0162008-03-27 14:22:02 +0100612 case ZFCP_REC_DBF_ID_TARGET:
613 zfcp_dbf_out(&p, "reference", "0x%016Lx", r->u.target.ref);
614 zfcp_dbf_out(&p, "status", "0x%08x", r->u.target.status);
615 zfcp_dbf_out(&p, "erp_count", "%d", r->u.target.erp_count);
616 zfcp_dbf_out(&p, "d_id", "0x%06x", r->u.target.d_id);
617 zfcp_dbf_out(&p, "wwpn", "0x%016Lx", r->u.target.wwpn);
618 zfcp_dbf_out(&p, "fcp_lun", "0x%016Lx", r->u.target.fcp_lun);
619 break;
Martin Peschke9467a9b2008-03-27 14:22:03 +0100620 case ZFCP_REC_DBF_ID_TRIGGER:
621 zfcp_dbf_out(&p, "reference", "0x%016Lx", r->u.trigger.ref);
622 zfcp_dbf_out(&p, "erp_action", "0x%016Lx", r->u.trigger.action);
623 zfcp_dbf_out(&p, "requested", "%d", r->u.trigger.want);
624 zfcp_dbf_out(&p, "executed", "%d", r->u.trigger.need);
625 zfcp_dbf_out(&p, "wwpn", "0x%016Lx", r->u.trigger.wwpn);
626 zfcp_dbf_out(&p, "fcp_lun", "0x%016Lx", r->u.trigger.fcp_lun);
627 zfcp_dbf_out(&p, "adapter_status", "0x%08x", r->u.trigger.as);
628 zfcp_dbf_out(&p, "port_status", "0x%08x", r->u.trigger.ps);
629 zfcp_dbf_out(&p, "unit_status", "0x%08x", r->u.trigger.us);
630 break;
Martin Peschke6f4f3652008-03-27 14:22:04 +0100631 case ZFCP_REC_DBF_ID_ACTION:
632 zfcp_dbf_out(&p, "erp_action", "0x%016Lx", r->u.action.action);
633 zfcp_dbf_out(&p, "fsf_req", "0x%016Lx", r->u.action.fsf_req);
634 zfcp_dbf_out(&p, "status", "0x%08Lx", r->u.action.status);
635 zfcp_dbf_out(&p, "step", "0x%08Lx", r->u.action.step);
636 break;
Martin Peschked79a83d2008-03-27 14:22:00 +0100637 }
Martin Peschkeb634fff2008-03-31 11:15:24 +0200638 p += sprintf(p, "\n");
639 return p - buf;
Martin Peschked79a83d2008-03-27 14:22:00 +0100640}
641
642static struct debug_view zfcp_rec_dbf_view = {
643 "structured",
644 NULL,
645 &zfcp_dbf_view_header,
646 &zfcp_rec_dbf_view_format,
647 NULL,
648 NULL
649};
650
Martin Peschke348447e2008-03-27 14:22:01 +0100651/**
652 * zfcp_rec_dbf_event_thread - trace event related to recovery thread operation
653 * @id2: identifier for event
654 * @adapter: adapter
655 * @lock: non-zero value indicates that erp_lock has not yet been acquired
656 */
657void zfcp_rec_dbf_event_thread(u8 id2, struct zfcp_adapter *adapter, int lock)
658{
659 struct zfcp_rec_dbf_record *r = &adapter->rec_dbf_buf;
660 unsigned long flags = 0;
661 struct list_head *entry;
662 unsigned ready = 0, running = 0, total;
663
664 if (lock)
665 read_lock_irqsave(&adapter->erp_lock, flags);
666 list_for_each(entry, &adapter->erp_ready_head)
667 ready++;
668 list_for_each(entry, &adapter->erp_running_head)
669 running++;
670 total = adapter->erp_total_count;
671 if (lock)
672 read_unlock_irqrestore(&adapter->erp_lock, flags);
673
674 spin_lock_irqsave(&adapter->rec_dbf_lock, flags);
675 memset(r, 0, sizeof(*r));
676 r->id = ZFCP_REC_DBF_ID_THREAD;
677 r->id2 = id2;
678 r->u.thread.sema = atomic_read(&adapter->erp_ready_sem.count);
679 r->u.thread.total = total;
680 r->u.thread.ready = ready;
681 r->u.thread.running = running;
682 debug_event(adapter->rec_dbf, 5, r, sizeof(*r));
683 spin_unlock_irqrestore(&adapter->rec_dbf_lock, flags);
684}
685
Martin Peschke698ec0162008-03-27 14:22:02 +0100686static void zfcp_rec_dbf_event_target(u8 id2, u64 ref,
687 struct zfcp_adapter *adapter,
688 atomic_t *status, atomic_t *erp_count,
689 u64 wwpn, u32 d_id, u64 fcp_lun)
690{
691 struct zfcp_rec_dbf_record *r = &adapter->rec_dbf_buf;
692 unsigned long flags;
693
694 spin_lock_irqsave(&adapter->rec_dbf_lock, flags);
695 memset(r, 0, sizeof(*r));
696 r->id = ZFCP_REC_DBF_ID_TARGET;
697 r->id2 = id2;
698 r->u.target.ref = ref;
699 r->u.target.status = atomic_read(status);
700 r->u.target.wwpn = wwpn;
701 r->u.target.d_id = d_id;
702 r->u.target.fcp_lun = fcp_lun;
703 r->u.target.erp_count = atomic_read(erp_count);
704 debug_event(adapter->rec_dbf, 3, r, sizeof(*r));
705 spin_unlock_irqrestore(&adapter->rec_dbf_lock, flags);
706}
707
708/**
709 * zfcp_rec_dbf_event_adapter - trace event for adapter state change
710 * @id: identifier for trigger of state change
711 * @ref: additional reference (e.g. request)
712 * @adapter: adapter
713 */
714void zfcp_rec_dbf_event_adapter(u8 id, u64 ref, struct zfcp_adapter *adapter)
715{
716 zfcp_rec_dbf_event_target(id, ref, adapter, &adapter->status,
717 &adapter->erp_counter, 0, 0, 0);
718}
719
720/**
721 * zfcp_rec_dbf_event_port - trace event for port state change
722 * @id: identifier for trigger of state change
723 * @ref: additional reference (e.g. request)
724 * @port: port
725 */
726void zfcp_rec_dbf_event_port(u8 id, u64 ref, struct zfcp_port *port)
727{
728 struct zfcp_adapter *adapter = port->adapter;
729
730 zfcp_rec_dbf_event_target(id, ref, adapter, &port->status,
731 &port->erp_counter, port->wwpn, port->d_id,
732 0);
733}
734
735/**
736 * zfcp_rec_dbf_event_unit - trace event for unit state change
737 * @id: identifier for trigger of state change
738 * @ref: additional reference (e.g. request)
739 * @unit: unit
740 */
741void zfcp_rec_dbf_event_unit(u8 id, u64 ref, struct zfcp_unit *unit)
742{
743 struct zfcp_port *port = unit->port;
744 struct zfcp_adapter *adapter = port->adapter;
745
746 zfcp_rec_dbf_event_target(id, ref, adapter, &unit->status,
747 &unit->erp_counter, port->wwpn, port->d_id,
748 unit->fcp_lun);
749}
750
Martin Peschke9467a9b2008-03-27 14:22:03 +0100751/**
752 * zfcp_rec_dbf_event_trigger - trace event for triggered error recovery
753 * @id2: identifier for error recovery trigger
754 * @ref: additional reference (e.g. request)
755 * @want: originally requested error recovery action
756 * @need: error recovery action actually initiated
757 * @action: address of error recovery action struct
758 * @adapter: adapter
759 * @port: port
760 * @unit: unit
761 */
762void zfcp_rec_dbf_event_trigger(u8 id2, u64 ref, u8 want, u8 need, u64 action,
763 struct zfcp_adapter *adapter,
764 struct zfcp_port *port, struct zfcp_unit *unit)
765{
766 struct zfcp_rec_dbf_record *r = &adapter->rec_dbf_buf;
767 unsigned long flags;
768
769 spin_lock_irqsave(&adapter->rec_dbf_lock, flags);
770 memset(r, 0, sizeof(*r));
771 r->id = ZFCP_REC_DBF_ID_TRIGGER;
772 r->id2 = id2;
773 r->u.trigger.ref = ref;
774 r->u.trigger.want = want;
775 r->u.trigger.need = need;
776 r->u.trigger.action = action;
777 r->u.trigger.as = atomic_read(&adapter->status);
778 if (port) {
779 r->u.trigger.ps = atomic_read(&port->status);
780 r->u.trigger.wwpn = port->wwpn;
781 }
782 if (unit) {
783 r->u.trigger.us = atomic_read(&unit->status);
784 r->u.trigger.fcp_lun = unit->fcp_lun;
785 }
786 debug_event(adapter->rec_dbf, action ? 1 : 4, r, sizeof(*r));
787 spin_unlock_irqrestore(&adapter->rec_dbf_lock, flags);
788}
789
Martin Peschke6f4f3652008-03-27 14:22:04 +0100790/**
791 * zfcp_rec_dbf_event_action - trace event showing progress of recovery action
792 * @id2: identifier
793 * @erp_action: error recovery action struct pointer
794 */
795void zfcp_rec_dbf_event_action(u8 id2, struct zfcp_erp_action *erp_action)
796{
797 struct zfcp_adapter *adapter = erp_action->adapter;
798 struct zfcp_rec_dbf_record *r = &adapter->rec_dbf_buf;
799 unsigned long flags;
800
801 spin_lock_irqsave(&adapter->rec_dbf_lock, flags);
802 memset(r, 0, sizeof(*r));
803 r->id = ZFCP_REC_DBF_ID_ACTION;
804 r->id2 = id2;
805 r->u.action.action = (u64)erp_action;
806 r->u.action.status = erp_action->status;
807 r->u.action.step = erp_action->step;
808 r->u.action.fsf_req = (u64)erp_action->fsf_req;
809 debug_event(adapter->rec_dbf, 4, r, sizeof(*r));
810 spin_unlock_irqrestore(&adapter->rec_dbf_lock, flags);
811}
812
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100813void zfcp_san_dbf_event_ct_request(struct zfcp_fsf_req *fsf_req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200814{
815 struct zfcp_send_ct *ct = (struct zfcp_send_ct *)fsf_req->data;
816 struct zfcp_port *port = ct->port;
817 struct zfcp_adapter *adapter = port->adapter;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200818 struct ct_hdr *hdr = zfcp_sg_to_address(ct->req);
819 struct zfcp_san_dbf_record *r = &adapter->san_dbf_buf;
820 struct zfcp_san_dbf_record_ct_request *oct = &r->u.ct_req;
821 unsigned long flags;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200822
Martin Peschke6bc473d2008-03-31 11:15:29 +0200823 spin_lock_irqsave(&adapter->san_dbf_lock, flags);
824 memset(r, 0, sizeof(*r));
825 strncpy(r->tag, "octc", ZFCP_DBF_TAG_SIZE);
826 r->fsf_reqid = (unsigned long)fsf_req;
827 r->fsf_seqno = fsf_req->seq_no;
828 r->s_id = fc_host_port_id(adapter->scsi_host);
829 r->d_id = port->d_id;
830 oct->cmd_req_code = hdr->cmd_rsp_code;
831 oct->revision = hdr->revision;
832 oct->gs_type = hdr->gs_type;
833 oct->gs_subtype = hdr->gs_subtype;
834 oct->options = hdr->options;
835 oct->max_res_size = hdr->max_res_size;
836 oct->len = min((int)ct->req->length - (int)sizeof(struct ct_hdr),
837 ZFCP_DBF_CT_PAYLOAD);
838 memcpy(oct->payload, (void *)hdr + sizeof(struct ct_hdr), oct->len);
839 debug_event(adapter->san_dbf, 3, r, sizeof(*r));
840 spin_unlock_irqrestore(&adapter->san_dbf_lock, flags);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200841}
842
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100843void zfcp_san_dbf_event_ct_response(struct zfcp_fsf_req *fsf_req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200844{
845 struct zfcp_send_ct *ct = (struct zfcp_send_ct *)fsf_req->data;
846 struct zfcp_port *port = ct->port;
847 struct zfcp_adapter *adapter = port->adapter;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200848 struct ct_hdr *hdr = zfcp_sg_to_address(ct->resp);
849 struct zfcp_san_dbf_record *r = &adapter->san_dbf_buf;
850 struct zfcp_san_dbf_record_ct_response *rct = &r->u.ct_resp;
851 unsigned long flags;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200852
Martin Peschke6bc473d2008-03-31 11:15:29 +0200853 spin_lock_irqsave(&adapter->san_dbf_lock, flags);
854 memset(r, 0, sizeof(*r));
855 strncpy(r->tag, "rctc", ZFCP_DBF_TAG_SIZE);
856 r->fsf_reqid = (unsigned long)fsf_req;
857 r->fsf_seqno = fsf_req->seq_no;
858 r->s_id = port->d_id;
859 r->d_id = fc_host_port_id(adapter->scsi_host);
860 rct->cmd_rsp_code = hdr->cmd_rsp_code;
861 rct->revision = hdr->revision;
862 rct->reason_code = hdr->reason_code;
863 rct->expl = hdr->reason_code_expl;
864 rct->vendor_unique = hdr->vendor_unique;
865 rct->len = min((int)ct->resp->length - (int)sizeof(struct ct_hdr),
866 ZFCP_DBF_CT_PAYLOAD);
867 memcpy(rct->payload, (void *)hdr + sizeof(struct ct_hdr), rct->len);
868 debug_event(adapter->san_dbf, 3, r, sizeof(*r));
869 spin_unlock_irqrestore(&adapter->san_dbf_lock, flags);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200870}
871
Martin Peschke92c7a832008-03-31 11:15:30 +0200872static void zfcp_san_dbf_event_els(const char *tag, int level,
873 struct zfcp_fsf_req *fsf_req, u32 s_id,
874 u32 d_id, u8 ls_code, void *buffer,
875 int buflen)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200876{
877 struct zfcp_adapter *adapter = fsf_req->adapter;
878 struct zfcp_san_dbf_record *rec = &adapter->san_dbf_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200879 unsigned long flags;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200880
881 spin_lock_irqsave(&adapter->san_dbf_lock, flags);
Martin Peschke6bc473d2008-03-31 11:15:29 +0200882 memset(rec, 0, sizeof(*rec));
Martin Peschke0f65e952008-03-27 14:21:56 +0100883 strncpy(rec->tag, tag, ZFCP_DBF_TAG_SIZE);
884 rec->fsf_reqid = (unsigned long)fsf_req;
885 rec->fsf_seqno = fsf_req->seq_no;
886 rec->s_id = s_id;
887 rec->d_id = d_id;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200888 rec->u.els.ls_code = ls_code;
Martin Peschke0f65e952008-03-27 14:21:56 +0100889 debug_event(adapter->san_dbf, level, rec, sizeof(*rec));
890 zfcp_dbf_hexdump(adapter->san_dbf, rec, sizeof(*rec), level,
891 buffer, min(buflen, ZFCP_DBF_ELS_MAX_PAYLOAD));
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200892 spin_unlock_irqrestore(&adapter->san_dbf_lock, flags);
893}
894
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100895void zfcp_san_dbf_event_els_request(struct zfcp_fsf_req *fsf_req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200896{
897 struct zfcp_send_els *els = (struct zfcp_send_els *)fsf_req->data;
898
Martin Peschke92c7a832008-03-31 11:15:30 +0200899 zfcp_san_dbf_event_els("oels", 2, fsf_req,
900 fc_host_port_id(els->adapter->scsi_host),
901 els->d_id, *(u8 *) zfcp_sg_to_address(els->req),
902 zfcp_sg_to_address(els->req), els->req->length);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200903}
904
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100905void zfcp_san_dbf_event_els_response(struct zfcp_fsf_req *fsf_req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200906{
907 struct zfcp_send_els *els = (struct zfcp_send_els *)fsf_req->data;
908
Martin Peschke92c7a832008-03-31 11:15:30 +0200909 zfcp_san_dbf_event_els("rels", 2, fsf_req, els->d_id,
910 fc_host_port_id(els->adapter->scsi_host),
911 *(u8 *)zfcp_sg_to_address(els->req),
912 zfcp_sg_to_address(els->resp),
913 els->resp->length);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200914}
915
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100916void zfcp_san_dbf_event_incoming_els(struct zfcp_fsf_req *fsf_req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200917{
918 struct zfcp_adapter *adapter = fsf_req->adapter;
Martin Peschke92c7a832008-03-31 11:15:30 +0200919 struct fsf_status_read_buffer *buf =
920 (struct fsf_status_read_buffer *)fsf_req->data;
921 int length = (int)buf->length -
922 (int)((void *)&buf->payload - (void *)buf);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200923
Martin Peschke92c7a832008-03-31 11:15:30 +0200924 zfcp_san_dbf_event_els("iels", 1, fsf_req, buf->d_id,
925 fc_host_port_id(adapter->scsi_host),
926 *(u8 *)buf->payload, (void *)buf->payload,
927 length);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200928}
929
Martin Peschke92c7a832008-03-31 11:15:30 +0200930static int zfcp_san_dbf_view_format(debug_info_t *id, struct debug_view *view,
931 char *out_buf, const char *in_buf)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200932{
Martin Peschkeb634fff2008-03-31 11:15:24 +0200933 struct zfcp_san_dbf_record *r = (struct zfcp_san_dbf_record *)in_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200934 char *buffer = NULL;
935 int buflen = 0, total = 0;
Martin Peschkeb634fff2008-03-31 11:15:24 +0200936 char *p = out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200937
Martin Peschkeb634fff2008-03-31 11:15:24 +0200938 if (strncmp(r->tag, "dump", ZFCP_DBF_TAG_SIZE) == 0)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200939 return 0;
940
Martin Peschkea9c85772008-03-31 11:15:27 +0200941 zfcp_dbf_tag(&p, "tag", r->tag);
Martin Peschkeb634fff2008-03-31 11:15:24 +0200942 zfcp_dbf_out(&p, "fsf_reqid", "0x%0Lx", r->fsf_reqid);
943 zfcp_dbf_out(&p, "fsf_seqno", "0x%08x", r->fsf_seqno);
944 zfcp_dbf_out(&p, "s_id", "0x%06x", r->s_id);
945 zfcp_dbf_out(&p, "d_id", "0x%06x", r->d_id);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200946
Martin Peschkeb634fff2008-03-31 11:15:24 +0200947 if (strncmp(r->tag, "octc", ZFCP_DBF_TAG_SIZE) == 0) {
Martin Peschke6bc473d2008-03-31 11:15:29 +0200948 struct zfcp_san_dbf_record_ct_request *ct = &r->u.ct_req;
949 zfcp_dbf_out(&p, "cmd_req_code", "0x%04x", ct->cmd_req_code);
950 zfcp_dbf_out(&p, "revision", "0x%02x", ct->revision);
951 zfcp_dbf_out(&p, "gs_type", "0x%02x", ct->gs_type);
952 zfcp_dbf_out(&p, "gs_subtype", "0x%02x", ct->gs_subtype);
953 zfcp_dbf_out(&p, "options", "0x%02x", ct->options);
954 zfcp_dbf_out(&p, "max_res_size", "0x%04x", ct->max_res_size);
955 total = ct->len;
956 buffer = ct->payload;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200957 buflen = min(total, ZFCP_DBF_CT_PAYLOAD);
Martin Peschkeb634fff2008-03-31 11:15:24 +0200958 } else if (strncmp(r->tag, "rctc", ZFCP_DBF_TAG_SIZE) == 0) {
Martin Peschke6bc473d2008-03-31 11:15:29 +0200959 struct zfcp_san_dbf_record_ct_response *ct = &r->u.ct_resp;
960 zfcp_dbf_out(&p, "cmd_rsp_code", "0x%04x", ct->cmd_rsp_code);
961 zfcp_dbf_out(&p, "revision", "0x%02x", ct->revision);
962 zfcp_dbf_out(&p, "reason_code", "0x%02x", ct->reason_code);
963 zfcp_dbf_out(&p, "reason_code_expl", "0x%02x", ct->expl);
964 zfcp_dbf_out(&p, "vendor_unique", "0x%02x", ct->vendor_unique);
965 total = ct->len;
966 buffer = ct->payload;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200967 buflen = min(total, ZFCP_DBF_CT_PAYLOAD);
Martin Peschkeb634fff2008-03-31 11:15:24 +0200968 } else if (strncmp(r->tag, "oels", ZFCP_DBF_TAG_SIZE) == 0 ||
969 strncmp(r->tag, "rels", ZFCP_DBF_TAG_SIZE) == 0 ||
970 strncmp(r->tag, "iels", ZFCP_DBF_TAG_SIZE) == 0) {
Martin Peschke6bc473d2008-03-31 11:15:29 +0200971 struct zfcp_san_dbf_record_els *els = &r->u.els;
972 zfcp_dbf_out(&p, "ls_code", "0x%02x", els->ls_code);
973 total = els->len;
974 buffer = els->payload;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200975 buflen = min(total, ZFCP_DBF_ELS_PAYLOAD);
976 }
977
Martin Peschkedf29f4a2008-03-31 11:15:26 +0200978 zfcp_dbf_outd(&p, "payload", buffer, buflen, 0, total);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200979 if (buflen == total)
Martin Peschkeb634fff2008-03-31 11:15:24 +0200980 p += sprintf(p, "\n");
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200981
Martin Peschkeb634fff2008-03-31 11:15:24 +0200982 return p - out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200983}
984
Heiko Carstens2b67fc42007-02-05 21:16:47 +0100985static struct debug_view zfcp_san_dbf_view = {
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200986 "structured",
987 NULL,
988 &zfcp_dbf_view_header,
989 &zfcp_san_dbf_view_format,
990 NULL,
991 NULL
992};
993
Martin Peschke92c7a832008-03-31 11:15:30 +0200994static void zfcp_scsi_dbf_event(const char *tag, const char *tag2, int level,
995 struct zfcp_adapter *adapter,
996 struct scsi_cmnd *scsi_cmnd,
997 struct zfcp_fsf_req *fsf_req,
998 unsigned long old_req_id)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200999{
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001000 struct zfcp_scsi_dbf_record *rec = &adapter->scsi_dbf_buf;
1001 struct zfcp_dbf_dump *dump = (struct zfcp_dbf_dump *)rec;
1002 unsigned long flags;
1003 struct fcp_rsp_iu *fcp_rsp;
1004 char *fcp_rsp_info = NULL, *fcp_sns_info = NULL;
1005 int offset = 0, buflen = 0;
1006
1007 spin_lock_irqsave(&adapter->scsi_dbf_lock, flags);
1008 do {
Martin Peschke6bc473d2008-03-31 11:15:29 +02001009 memset(rec, 0, sizeof(*rec));
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001010 if (offset == 0) {
1011 strncpy(rec->tag, tag, ZFCP_DBF_TAG_SIZE);
1012 strncpy(rec->tag2, tag2, ZFCP_DBF_TAG_SIZE);
Maxim Shchetynined829ad2006-02-11 01:42:58 +01001013 if (scsi_cmnd != NULL) {
1014 if (scsi_cmnd->device) {
1015 rec->scsi_id = scsi_cmnd->device->id;
1016 rec->scsi_lun = scsi_cmnd->device->lun;
1017 }
1018 rec->scsi_result = scsi_cmnd->result;
1019 rec->scsi_cmnd = (unsigned long)scsi_cmnd;
1020 rec->scsi_serial = scsi_cmnd->serial_number;
1021 memcpy(rec->scsi_opcode, &scsi_cmnd->cmnd,
1022 min((int)scsi_cmnd->cmd_len,
1023 ZFCP_DBF_SCSI_OPCODE));
1024 rec->scsi_retries = scsi_cmnd->retries;
1025 rec->scsi_allowed = scsi_cmnd->allowed;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001026 }
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001027 if (fsf_req != NULL) {
1028 fcp_rsp = (struct fcp_rsp_iu *)
1029 &(fsf_req->qtcb->bottom.io.fcp_rsp);
1030 fcp_rsp_info =
1031 zfcp_get_fcp_rsp_info_ptr(fcp_rsp);
1032 fcp_sns_info =
1033 zfcp_get_fcp_sns_info_ptr(fcp_rsp);
1034
Martin Peschke6bc473d2008-03-31 11:15:29 +02001035 rec->rsp_validity = fcp_rsp->validity.value;
1036 rec->rsp_scsi_status = fcp_rsp->scsi_status;
1037 rec->rsp_resid = fcp_rsp->fcp_resid;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001038 if (fcp_rsp->validity.bits.fcp_rsp_len_valid)
Martin Peschke6bc473d2008-03-31 11:15:29 +02001039 rec->rsp_code = *(fcp_rsp_info + 3);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001040 if (fcp_rsp->validity.bits.fcp_sns_len_valid) {
1041 buflen = min((int)fcp_rsp->fcp_sns_len,
1042 ZFCP_DBF_SCSI_MAX_FCP_SNS_INFO);
Martin Peschke6bc473d2008-03-31 11:15:29 +02001043 rec->sns_info_len = buflen;
1044 memcpy(rec->sns_info, fcp_sns_info,
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001045 min(buflen,
1046 ZFCP_DBF_SCSI_FCP_SNS_INFO));
1047 offset += min(buflen,
1048 ZFCP_DBF_SCSI_FCP_SNS_INFO);
1049 }
1050
1051 rec->fsf_reqid = (unsigned long)fsf_req;
1052 rec->fsf_seqno = fsf_req->seq_no;
1053 rec->fsf_issued = fsf_req->issued;
1054 }
Martin Peschke6bc473d2008-03-31 11:15:29 +02001055 rec->old_fsf_reqid = old_req_id;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001056 } else {
1057 strncpy(dump->tag, "dump", ZFCP_DBF_TAG_SIZE);
1058 dump->total_size = buflen;
1059 dump->offset = offset;
1060 dump->size = min(buflen - offset,
1061 (int)sizeof(struct
1062 zfcp_scsi_dbf_record) -
1063 (int)sizeof(struct zfcp_dbf_dump));
1064 memcpy(dump->data, fcp_sns_info + offset, dump->size);
1065 offset += dump->size;
1066 }
Martin Peschke6bc473d2008-03-31 11:15:29 +02001067 debug_event(adapter->scsi_dbf, level, rec, sizeof(*rec));
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001068 } while (offset < buflen);
1069 spin_unlock_irqrestore(&adapter->scsi_dbf_lock, flags);
1070}
1071
Martin Peschke92c7a832008-03-31 11:15:30 +02001072void zfcp_scsi_dbf_event_result(const char *tag, int level,
1073 struct zfcp_adapter *adapter,
1074 struct scsi_cmnd *scsi_cmnd,
1075 struct zfcp_fsf_req *fsf_req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001076{
Martin Peschke92c7a832008-03-31 11:15:30 +02001077 zfcp_scsi_dbf_event("rslt", tag, level, adapter, scsi_cmnd, fsf_req, 0);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001078}
1079
Martin Peschke92c7a832008-03-31 11:15:30 +02001080void zfcp_scsi_dbf_event_abort(const char *tag, struct zfcp_adapter *adapter,
1081 struct scsi_cmnd *scsi_cmnd,
1082 struct zfcp_fsf_req *new_fsf_req,
1083 unsigned long old_req_id)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001084{
Martin Peschke92c7a832008-03-31 11:15:30 +02001085 zfcp_scsi_dbf_event("abrt", tag, 1, adapter, scsi_cmnd, new_fsf_req,
1086 old_req_id);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001087}
1088
Martin Peschke92c7a832008-03-31 11:15:30 +02001089void zfcp_scsi_dbf_event_devreset(const char *tag, u8 flag,
1090 struct zfcp_unit *unit,
1091 struct scsi_cmnd *scsi_cmnd)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001092{
Martin Peschke92c7a832008-03-31 11:15:30 +02001093 zfcp_scsi_dbf_event(flag == FCP_TARGET_RESET ? "trst" : "lrst", tag, 1,
1094 unit->port->adapter, scsi_cmnd, NULL, 0);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001095}
1096
Martin Peschke92c7a832008-03-31 11:15:30 +02001097static int zfcp_scsi_dbf_view_format(debug_info_t *id, struct debug_view *view,
1098 char *out_buf, const char *in_buf)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001099{
Martin Peschkeb634fff2008-03-31 11:15:24 +02001100 struct zfcp_scsi_dbf_record *r = (struct zfcp_scsi_dbf_record *)in_buf;
Martin Peschke8fc5af12008-03-31 11:15:23 +02001101 struct timespec t;
Martin Peschkeb634fff2008-03-31 11:15:24 +02001102 char *p = out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001103
Martin Peschkeb634fff2008-03-31 11:15:24 +02001104 if (strncmp(r->tag, "dump", ZFCP_DBF_TAG_SIZE) == 0)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001105 return 0;
1106
Martin Peschkea9c85772008-03-31 11:15:27 +02001107 zfcp_dbf_tag(&p, "tag", r->tag);
1108 zfcp_dbf_tag(&p, "tag2", r->tag2);
Martin Peschkeb634fff2008-03-31 11:15:24 +02001109 zfcp_dbf_out(&p, "scsi_id", "0x%08x", r->scsi_id);
1110 zfcp_dbf_out(&p, "scsi_lun", "0x%08x", r->scsi_lun);
1111 zfcp_dbf_out(&p, "scsi_result", "0x%08x", r->scsi_result);
1112 zfcp_dbf_out(&p, "scsi_cmnd", "0x%0Lx", r->scsi_cmnd);
1113 zfcp_dbf_out(&p, "scsi_serial", "0x%016Lx", r->scsi_serial);
Martin Peschkedf29f4a2008-03-31 11:15:26 +02001114 zfcp_dbf_outd(&p, "scsi_opcode", r->scsi_opcode, ZFCP_DBF_SCSI_OPCODE,
1115 0, ZFCP_DBF_SCSI_OPCODE);
Martin Peschkeb634fff2008-03-31 11:15:24 +02001116 zfcp_dbf_out(&p, "scsi_retries", "0x%02x", r->scsi_retries);
1117 zfcp_dbf_out(&p, "scsi_allowed", "0x%02x", r->scsi_allowed);
1118 if (strncmp(r->tag, "abrt", ZFCP_DBF_TAG_SIZE) == 0)
Martin Peschke6bc473d2008-03-31 11:15:29 +02001119 zfcp_dbf_out(&p, "old_fsf_reqid", "0x%0Lx", r->old_fsf_reqid);
Martin Peschkeb634fff2008-03-31 11:15:24 +02001120 zfcp_dbf_out(&p, "fsf_reqid", "0x%0Lx", r->fsf_reqid);
1121 zfcp_dbf_out(&p, "fsf_seqno", "0x%08x", r->fsf_seqno);
1122 zfcp_dbf_timestamp(r->fsf_issued, &t);
1123 zfcp_dbf_out(&p, "fsf_issued", "%011lu:%06lu", t.tv_sec, t.tv_nsec);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001124
Martin Peschkeb634fff2008-03-31 11:15:24 +02001125 if (strncmp(r->tag, "rslt", ZFCP_DBF_TAG_SIZE) == 0) {
Martin Peschke6bc473d2008-03-31 11:15:29 +02001126 zfcp_dbf_out(&p, "fcp_rsp_validity", "0x%02x", r->rsp_validity);
1127 zfcp_dbf_out(&p, "fcp_rsp_scsi_status", "0x%02x",
1128 r->rsp_scsi_status);
1129 zfcp_dbf_out(&p, "fcp_rsp_resid", "0x%08x", r->rsp_resid);
1130 zfcp_dbf_out(&p, "fcp_rsp_code", "0x%08x", r->rsp_code);
1131 zfcp_dbf_out(&p, "fcp_sns_info_len", "0x%08x", r->sns_info_len);
1132 zfcp_dbf_outd(&p, "fcp_sns_info", r->sns_info,
1133 min((int)r->sns_info_len,
Martin Peschkedf29f4a2008-03-31 11:15:26 +02001134 ZFCP_DBF_SCSI_FCP_SNS_INFO), 0,
Martin Peschke6bc473d2008-03-31 11:15:29 +02001135 r->sns_info_len);
Martin Peschkeb634fff2008-03-31 11:15:24 +02001136 }
1137 p += sprintf(p, "\n");
1138 return p - out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001139}
1140
Heiko Carstens2b67fc42007-02-05 21:16:47 +01001141static struct debug_view zfcp_scsi_dbf_view = {
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001142 "structured",
1143 NULL,
1144 &zfcp_dbf_view_header,
1145 &zfcp_scsi_dbf_view_format,
1146 NULL,
1147 NULL
1148};
1149
1150/**
1151 * zfcp_adapter_debug_register - registers debug feature for an adapter
1152 * @adapter: pointer to adapter for which debug features should be registered
1153 * return: -ENOMEM on error, 0 otherwise
1154 */
1155int zfcp_adapter_debug_register(struct zfcp_adapter *adapter)
1156{
1157 char dbf_name[DEBUG_MAX_NAME_LEN];
1158
1159 /* debug feature area which records recovery activity */
Martin Peschked79a83d2008-03-27 14:22:00 +01001160 sprintf(dbf_name, "zfcp_%s_rec", zfcp_get_busid_by_adapter(adapter));
1161 adapter->rec_dbf = debug_register(dbf_name, dbfsize, 1,
1162 sizeof(struct zfcp_rec_dbf_record));
1163 if (!adapter->rec_dbf)
1164 goto failed;
1165 debug_register_view(adapter->rec_dbf, &debug_hex_ascii_view);
1166 debug_register_view(adapter->rec_dbf, &zfcp_rec_dbf_view);
1167 debug_set_level(adapter->rec_dbf, 3);
1168
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001169 /* debug feature area which records HBA (FSF and QDIO) conditions */
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001170 sprintf(dbf_name, "zfcp_%s_hba", zfcp_get_busid_by_adapter(adapter));
1171 adapter->hba_dbf = debug_register(dbf_name, dbfsize, 1,
1172 sizeof(struct zfcp_hba_dbf_record));
1173 if (!adapter->hba_dbf)
1174 goto failed;
1175 debug_register_view(adapter->hba_dbf, &debug_hex_ascii_view);
1176 debug_register_view(adapter->hba_dbf, &zfcp_hba_dbf_view);
1177 debug_set_level(adapter->hba_dbf, 3);
1178
1179 /* debug feature area which records SAN command failures and recovery */
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001180 sprintf(dbf_name, "zfcp_%s_san", zfcp_get_busid_by_adapter(adapter));
1181 adapter->san_dbf = debug_register(dbf_name, dbfsize, 1,
1182 sizeof(struct zfcp_san_dbf_record));
1183 if (!adapter->san_dbf)
1184 goto failed;
1185 debug_register_view(adapter->san_dbf, &debug_hex_ascii_view);
1186 debug_register_view(adapter->san_dbf, &zfcp_san_dbf_view);
1187 debug_set_level(adapter->san_dbf, 6);
1188
1189 /* debug feature area which records SCSI command failures and recovery */
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001190 sprintf(dbf_name, "zfcp_%s_scsi", zfcp_get_busid_by_adapter(adapter));
1191 adapter->scsi_dbf = debug_register(dbf_name, dbfsize, 1,
1192 sizeof(struct zfcp_scsi_dbf_record));
1193 if (!adapter->scsi_dbf)
1194 goto failed;
1195 debug_register_view(adapter->scsi_dbf, &debug_hex_ascii_view);
1196 debug_register_view(adapter->scsi_dbf, &zfcp_scsi_dbf_view);
1197 debug_set_level(adapter->scsi_dbf, 3);
1198
1199 return 0;
1200
1201 failed:
1202 zfcp_adapter_debug_unregister(adapter);
1203
1204 return -ENOMEM;
1205}
1206
1207/**
1208 * zfcp_adapter_debug_unregister - unregisters debug feature for an adapter
1209 * @adapter: pointer to adapter for which debug features should be unregistered
1210 */
1211void zfcp_adapter_debug_unregister(struct zfcp_adapter *adapter)
1212{
1213 debug_unregister(adapter->scsi_dbf);
1214 debug_unregister(adapter->san_dbf);
1215 debug_unregister(adapter->hba_dbf);
Martin Peschked79a83d2008-03-27 14:22:00 +01001216 debug_unregister(adapter->rec_dbf);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001217 adapter->scsi_dbf = NULL;
1218 adapter->san_dbf = NULL;
1219 adapter->hba_dbf = NULL;
Martin Peschked79a83d2008-03-27 14:22:00 +01001220 adapter->rec_dbf = NULL;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001221}
1222
1223#undef ZFCP_LOG_AREA