blob: 5a4b1e9a8b503c0c512f2d441f1b2691220b54fd [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
Heiko Carstens4d284ca2007-02-05 21:18:53 +010052static int
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020053zfcp_dbf_stck(char *out_buf, const char *label, unsigned long long stck)
54{
55 unsigned long long sec;
Heiko Carstens364c8552007-10-12 16:11:35 +020056 struct timespec dbftime;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020057 int len = 0;
58
59 stck -= 0x8126d60e46000000LL - (0x3c26700LL * 1000000 * 4096);
60 sec = stck >> 12;
61 do_div(sec, 1000000);
Heiko Carstens364c8552007-10-12 16:11:35 +020062 dbftime.tv_sec = sec;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020063 stck -= (sec * 1000000) << 12;
Heiko Carstens364c8552007-10-12 16:11:35 +020064 dbftime.tv_nsec = ((stck * 1000) >> 12);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020065 len += sprintf(out_buf + len, "%-24s%011lu:%06lu\n",
Heiko Carstens364c8552007-10-12 16:11:35 +020066 label, dbftime.tv_sec, dbftime.tv_nsec);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020067
68 return len;
69}
70
71static int zfcp_dbf_tag(char *out_buf, const char *label, const char *tag)
72{
73 int len = 0, i;
74
75 len += sprintf(out_buf + len, "%-24s", label);
76 for (i = 0; i < ZFCP_DBF_TAG_SIZE; i++)
77 len += sprintf(out_buf + len, "%c", tag[i]);
78 len += sprintf(out_buf + len, "\n");
79
80 return len;
81}
82
83static int
84zfcp_dbf_view(char *out_buf, const char *label, const char *format, ...)
85{
86 va_list arg;
87 int len = 0;
88
89 len += sprintf(out_buf + len, "%-24s", label);
90 va_start(arg, format);
91 len += vsprintf(out_buf + len, format, arg);
92 va_end(arg);
93 len += sprintf(out_buf + len, "\n");
94
95 return len;
96}
97
Martin Peschke10223c62008-03-27 14:21:59 +010098static void zfcp_dbf_outs(char **buf, const char *s1, const char *s2)
99{
100 *buf += sprintf(*buf, "%-24s%s\n", s1, s2);
101}
102
103static void zfcp_dbf_out(char **buf, const char *s, const char *format, ...)
104{
105 va_list arg;
106
107 *buf += sprintf(*buf, "%-24s", s);
108 va_start(arg, format);
109 *buf += vsprintf(*buf, format, arg);
110 va_end(arg);
111 *buf += sprintf(*buf, "\n");
112}
113
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200114static int
115zfcp_dbf_view_dump(char *out_buf, const char *label,
116 char *buffer, int buflen, int offset, int total_size)
117{
118 int len = 0;
119
120 if (offset == 0)
121 len += sprintf(out_buf + len, "%-24s ", label);
122
123 while (buflen--) {
124 if (offset > 0) {
125 if ((offset % 32) == 0)
126 len += sprintf(out_buf + len, "\n%-24c ", ' ');
127 else if ((offset % 4) == 0)
128 len += sprintf(out_buf + len, " ");
129 }
130 len += sprintf(out_buf + len, "%02x", *buffer++);
131 if (++offset == total_size) {
132 len += sprintf(out_buf + len, "\n");
133 break;
134 }
135 }
136
137 if (total_size == 0)
138 len += sprintf(out_buf + len, "\n");
139
140 return len;
141}
142
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100143static int
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200144zfcp_dbf_view_header(debug_info_t * id, struct debug_view *view, int area,
145 debug_entry_t * entry, char *out_buf)
146{
147 struct zfcp_dbf_dump *dump = (struct zfcp_dbf_dump *)DEBUG_DATA(entry);
148 int len = 0;
149
150 if (strncmp(dump->tag, "dump", ZFCP_DBF_TAG_SIZE) != 0) {
151 len += zfcp_dbf_stck(out_buf + len, "timestamp",
152 entry->id.stck);
153 len += zfcp_dbf_view(out_buf + len, "cpu", "%02i",
154 entry->id.fields.cpuid);
155 } else {
156 len += zfcp_dbf_view_dump(out_buf + len, NULL,
157 dump->data,
158 dump->size,
159 dump->offset, dump->total_size);
160 if ((dump->offset + dump->size) == dump->total_size)
161 len += sprintf(out_buf + len, "\n");
162 }
163
164 return len;
165}
166
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100167void zfcp_hba_dbf_event_fsf_response(struct zfcp_fsf_req *fsf_req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200168{
169 struct zfcp_adapter *adapter = fsf_req->adapter;
170 struct fsf_qtcb *qtcb = fsf_req->qtcb;
171 union fsf_prot_status_qual *prot_status_qual =
172 &qtcb->prefix.prot_status_qual;
173 union fsf_status_qual *fsf_status_qual = &qtcb->header.fsf_status_qual;
174 struct scsi_cmnd *scsi_cmnd;
175 struct zfcp_port *port;
176 struct zfcp_unit *unit;
177 struct zfcp_send_els *send_els;
178 struct zfcp_hba_dbf_record *rec = &adapter->hba_dbf_buf;
179 struct zfcp_hba_dbf_record_response *response = &rec->type.response;
180 int level;
181 unsigned long flags;
182
183 spin_lock_irqsave(&adapter->hba_dbf_lock, flags);
184 memset(rec, 0, sizeof(struct zfcp_hba_dbf_record));
185 strncpy(rec->tag, "resp", ZFCP_DBF_TAG_SIZE);
186
187 if ((qtcb->prefix.prot_status != FSF_PROT_GOOD) &&
188 (qtcb->prefix.prot_status != FSF_PROT_FSF_STATUS_PRESENTED)) {
189 strncpy(rec->tag2, "perr", ZFCP_DBF_TAG_SIZE);
190 level = 1;
191 } else if (qtcb->header.fsf_status != FSF_GOOD) {
192 strncpy(rec->tag2, "ferr", ZFCP_DBF_TAG_SIZE);
193 level = 1;
194 } else if ((fsf_req->fsf_command == FSF_QTCB_OPEN_PORT_WITH_DID) ||
195 (fsf_req->fsf_command == FSF_QTCB_OPEN_LUN)) {
196 strncpy(rec->tag2, "open", ZFCP_DBF_TAG_SIZE);
197 level = 4;
Martin Peschkeb75db732008-03-27 14:21:58 +0100198 } else if (qtcb->header.log_length) {
199 strncpy(rec->tag2, "qtcb", ZFCP_DBF_TAG_SIZE);
200 level = 5;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200201 } else {
202 strncpy(rec->tag2, "norm", ZFCP_DBF_TAG_SIZE);
203 level = 6;
204 }
205
206 response->fsf_command = fsf_req->fsf_command;
207 response->fsf_reqid = (unsigned long)fsf_req;
208 response->fsf_seqno = fsf_req->seq_no;
209 response->fsf_issued = fsf_req->issued;
210 response->fsf_prot_status = qtcb->prefix.prot_status;
211 response->fsf_status = qtcb->header.fsf_status;
212 memcpy(response->fsf_prot_status_qual,
213 prot_status_qual, FSF_PROT_STATUS_QUAL_SIZE);
214 memcpy(response->fsf_status_qual,
215 fsf_status_qual, FSF_STATUS_QUALIFIER_SIZE);
216 response->fsf_req_status = fsf_req->status;
217 response->sbal_first = fsf_req->sbal_first;
218 response->sbal_curr = fsf_req->sbal_curr;
219 response->sbal_last = fsf_req->sbal_last;
220 response->pool = fsf_req->pool != NULL;
221 response->erp_action = (unsigned long)fsf_req->erp_action;
222
223 switch (fsf_req->fsf_command) {
224 case FSF_QTCB_FCP_CMND:
225 if (fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT)
226 break;
227 scsi_cmnd = (struct scsi_cmnd *)fsf_req->data;
228 if (scsi_cmnd != NULL) {
229 response->data.send_fcp.scsi_cmnd
230 = (unsigned long)scsi_cmnd;
231 response->data.send_fcp.scsi_serial
232 = scsi_cmnd->serial_number;
233 }
234 break;
235
236 case FSF_QTCB_OPEN_PORT_WITH_DID:
237 case FSF_QTCB_CLOSE_PORT:
238 case FSF_QTCB_CLOSE_PHYSICAL_PORT:
239 port = (struct zfcp_port *)fsf_req->data;
240 response->data.port.wwpn = port->wwpn;
241 response->data.port.d_id = port->d_id;
242 response->data.port.port_handle = qtcb->header.port_handle;
243 break;
244
245 case FSF_QTCB_OPEN_LUN:
246 case FSF_QTCB_CLOSE_LUN:
247 unit = (struct zfcp_unit *)fsf_req->data;
248 port = unit->port;
249 response->data.unit.wwpn = port->wwpn;
250 response->data.unit.fcp_lun = unit->fcp_lun;
251 response->data.unit.port_handle = qtcb->header.port_handle;
252 response->data.unit.lun_handle = qtcb->header.lun_handle;
253 break;
254
255 case FSF_QTCB_SEND_ELS:
256 send_els = (struct zfcp_send_els *)fsf_req->data;
257 response->data.send_els.d_id = qtcb->bottom.support.d_id;
258 response->data.send_els.ls_code = send_els->ls_code >> 24;
259 break;
260
261 case FSF_QTCB_ABORT_FCP_CMND:
262 case FSF_QTCB_SEND_GENERIC:
263 case FSF_QTCB_EXCHANGE_CONFIG_DATA:
264 case FSF_QTCB_EXCHANGE_PORT_DATA:
265 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
266 case FSF_QTCB_UPLOAD_CONTROL_FILE:
267 break;
268 }
269
270 debug_event(adapter->hba_dbf, level,
271 rec, sizeof(struct zfcp_hba_dbf_record));
Martin Peschkeb75db732008-03-27 14:21:58 +0100272
273 /* have fcp channel microcode fixed to use as little as possible */
274 if (fsf_req->fsf_command != FSF_QTCB_FCP_CMND) {
275 /* adjust length skipping trailing zeros */
276 char *buf = (char *)qtcb + qtcb->header.log_start;
277 int len = qtcb->header.log_length;
278 for (; len && !buf[len - 1]; len--);
279 zfcp_dbf_hexdump(adapter->hba_dbf, rec, sizeof(*rec), level,
280 buf, len);
281 }
282
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200283 spin_unlock_irqrestore(&adapter->hba_dbf_lock, flags);
284}
285
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100286void
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200287zfcp_hba_dbf_event_fsf_unsol(const char *tag, struct zfcp_adapter *adapter,
288 struct fsf_status_read_buffer *status_buffer)
289{
290 struct zfcp_hba_dbf_record *rec = &adapter->hba_dbf_buf;
291 unsigned long flags;
292
293 spin_lock_irqsave(&adapter->hba_dbf_lock, flags);
294 memset(rec, 0, sizeof(struct zfcp_hba_dbf_record));
295 strncpy(rec->tag, "stat", ZFCP_DBF_TAG_SIZE);
296 strncpy(rec->tag2, tag, ZFCP_DBF_TAG_SIZE);
297
298 rec->type.status.failed = adapter->status_read_failed;
299 if (status_buffer != NULL) {
300 rec->type.status.status_type = status_buffer->status_type;
301 rec->type.status.status_subtype = status_buffer->status_subtype;
302 memcpy(&rec->type.status.queue_designator,
303 &status_buffer->queue_designator,
304 sizeof(struct fsf_queue_designator));
305
306 switch (status_buffer->status_type) {
307 case FSF_STATUS_READ_SENSE_DATA_AVAIL:
308 rec->type.status.payload_size =
309 ZFCP_DBF_UNSOL_PAYLOAD_SENSE_DATA_AVAIL;
310 break;
311
312 case FSF_STATUS_READ_BIT_ERROR_THRESHOLD:
313 rec->type.status.payload_size =
314 ZFCP_DBF_UNSOL_PAYLOAD_BIT_ERROR_THRESHOLD;
315 break;
316
317 case FSF_STATUS_READ_LINK_DOWN:
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200318 switch (status_buffer->status_subtype) {
319 case FSF_STATUS_READ_SUB_NO_PHYSICAL_LINK:
320 case FSF_STATUS_READ_SUB_FDISC_FAILED:
321 rec->type.status.payload_size =
322 sizeof(struct fsf_link_down_info);
323 }
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200324 break;
325
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200326 case FSF_STATUS_READ_FEATURE_UPDATE_ALERT:
327 rec->type.status.payload_size =
328 ZFCP_DBF_UNSOL_PAYLOAD_FEATURE_UPDATE_ALERT;
329 break;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200330 }
331 memcpy(&rec->type.status.payload,
332 &status_buffer->payload, rec->type.status.payload_size);
333 }
334
335 debug_event(adapter->hba_dbf, 2,
336 rec, sizeof(struct zfcp_hba_dbf_record));
337 spin_unlock_irqrestore(&adapter->hba_dbf_lock, flags);
338}
339
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100340void
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200341zfcp_hba_dbf_event_qdio(struct zfcp_adapter *adapter, unsigned int status,
342 unsigned int qdio_error, unsigned int siga_error,
343 int sbal_index, int sbal_count)
344{
345 struct zfcp_hba_dbf_record *rec = &adapter->hba_dbf_buf;
346 unsigned long flags;
347
348 spin_lock_irqsave(&adapter->hba_dbf_lock, flags);
349 memset(rec, 0, sizeof(struct zfcp_hba_dbf_record));
350 strncpy(rec->tag, "qdio", ZFCP_DBF_TAG_SIZE);
351 rec->type.qdio.status = status;
352 rec->type.qdio.qdio_error = qdio_error;
353 rec->type.qdio.siga_error = siga_error;
354 rec->type.qdio.sbal_index = sbal_index;
355 rec->type.qdio.sbal_count = sbal_count;
356 debug_event(adapter->hba_dbf, 0,
357 rec, sizeof(struct zfcp_hba_dbf_record));
358 spin_unlock_irqrestore(&adapter->hba_dbf_lock, flags);
359}
360
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100361static int
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200362zfcp_hba_dbf_view_response(char *out_buf,
363 struct zfcp_hba_dbf_record_response *rec)
364{
365 int len = 0;
366
367 len += zfcp_dbf_view(out_buf + len, "fsf_command", "0x%08x",
368 rec->fsf_command);
369 len += zfcp_dbf_view(out_buf + len, "fsf_reqid", "0x%0Lx",
370 rec->fsf_reqid);
371 len += zfcp_dbf_view(out_buf + len, "fsf_seqno", "0x%08x",
372 rec->fsf_seqno);
373 len += zfcp_dbf_stck(out_buf + len, "fsf_issued", rec->fsf_issued);
374 len += zfcp_dbf_view(out_buf + len, "fsf_prot_status", "0x%08x",
375 rec->fsf_prot_status);
376 len += zfcp_dbf_view(out_buf + len, "fsf_status", "0x%08x",
377 rec->fsf_status);
378 len += zfcp_dbf_view_dump(out_buf + len, "fsf_prot_status_qual",
379 rec->fsf_prot_status_qual,
380 FSF_PROT_STATUS_QUAL_SIZE,
381 0, FSF_PROT_STATUS_QUAL_SIZE);
382 len += zfcp_dbf_view_dump(out_buf + len, "fsf_status_qual",
383 rec->fsf_status_qual,
384 FSF_STATUS_QUALIFIER_SIZE,
385 0, FSF_STATUS_QUALIFIER_SIZE);
386 len += zfcp_dbf_view(out_buf + len, "fsf_req_status", "0x%08x",
387 rec->fsf_req_status);
388 len += zfcp_dbf_view(out_buf + len, "sbal_first", "0x%02x",
389 rec->sbal_first);
390 len += zfcp_dbf_view(out_buf + len, "sbal_curr", "0x%02x",
391 rec->sbal_curr);
392 len += zfcp_dbf_view(out_buf + len, "sbal_last", "0x%02x",
393 rec->sbal_last);
394 len += zfcp_dbf_view(out_buf + len, "pool", "0x%02x", rec->pool);
395
396 switch (rec->fsf_command) {
397 case FSF_QTCB_FCP_CMND:
398 if (rec->fsf_req_status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT)
399 break;
400 len += zfcp_dbf_view(out_buf + len, "scsi_cmnd", "0x%0Lx",
401 rec->data.send_fcp.scsi_cmnd);
402 len += zfcp_dbf_view(out_buf + len, "scsi_serial", "0x%016Lx",
403 rec->data.send_fcp.scsi_serial);
404 break;
405
406 case FSF_QTCB_OPEN_PORT_WITH_DID:
407 case FSF_QTCB_CLOSE_PORT:
408 case FSF_QTCB_CLOSE_PHYSICAL_PORT:
409 len += zfcp_dbf_view(out_buf + len, "wwpn", "0x%016Lx",
410 rec->data.port.wwpn);
411 len += zfcp_dbf_view(out_buf + len, "d_id", "0x%06x",
412 rec->data.port.d_id);
413 len += zfcp_dbf_view(out_buf + len, "port_handle", "0x%08x",
414 rec->data.port.port_handle);
415 break;
416
417 case FSF_QTCB_OPEN_LUN:
418 case FSF_QTCB_CLOSE_LUN:
419 len += zfcp_dbf_view(out_buf + len, "wwpn", "0x%016Lx",
420 rec->data.unit.wwpn);
421 len += zfcp_dbf_view(out_buf + len, "fcp_lun", "0x%016Lx",
422 rec->data.unit.fcp_lun);
423 len += zfcp_dbf_view(out_buf + len, "port_handle", "0x%08x",
424 rec->data.unit.port_handle);
425 len += zfcp_dbf_view(out_buf + len, "lun_handle", "0x%08x",
426 rec->data.unit.lun_handle);
427 break;
428
429 case FSF_QTCB_SEND_ELS:
430 len += zfcp_dbf_view(out_buf + len, "d_id", "0x%06x",
431 rec->data.send_els.d_id);
432 len += zfcp_dbf_view(out_buf + len, "ls_code", "0x%02x",
433 rec->data.send_els.ls_code);
434 break;
435
436 case FSF_QTCB_ABORT_FCP_CMND:
437 case FSF_QTCB_SEND_GENERIC:
438 case FSF_QTCB_EXCHANGE_CONFIG_DATA:
439 case FSF_QTCB_EXCHANGE_PORT_DATA:
440 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
441 case FSF_QTCB_UPLOAD_CONTROL_FILE:
442 break;
443 }
444
445 return len;
446}
447
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100448static int
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200449zfcp_hba_dbf_view_status(char *out_buf, struct zfcp_hba_dbf_record_status *rec)
450{
451 int len = 0;
452
453 len += zfcp_dbf_view(out_buf + len, "failed", "0x%02x", rec->failed);
454 len += zfcp_dbf_view(out_buf + len, "status_type", "0x%08x",
455 rec->status_type);
456 len += zfcp_dbf_view(out_buf + len, "status_subtype", "0x%08x",
457 rec->status_subtype);
458 len += zfcp_dbf_view_dump(out_buf + len, "queue_designator",
459 (char *)&rec->queue_designator,
460 sizeof(struct fsf_queue_designator),
461 0, sizeof(struct fsf_queue_designator));
462 len += zfcp_dbf_view_dump(out_buf + len, "payload",
463 (char *)&rec->payload,
464 rec->payload_size, 0, rec->payload_size);
465
466 return len;
467}
468
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100469static int
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200470zfcp_hba_dbf_view_qdio(char *out_buf, struct zfcp_hba_dbf_record_qdio *rec)
471{
472 int len = 0;
473
474 len += zfcp_dbf_view(out_buf + len, "status", "0x%08x", rec->status);
475 len += zfcp_dbf_view(out_buf + len, "qdio_error", "0x%08x",
476 rec->qdio_error);
477 len += zfcp_dbf_view(out_buf + len, "siga_error", "0x%08x",
478 rec->siga_error);
479 len += zfcp_dbf_view(out_buf + len, "sbal_index", "0x%02x",
480 rec->sbal_index);
481 len += zfcp_dbf_view(out_buf + len, "sbal_count", "0x%02x",
482 rec->sbal_count);
483
484 return len;
485}
486
487static int
488zfcp_hba_dbf_view_format(debug_info_t * id, struct debug_view *view,
489 char *out_buf, const char *in_buf)
490{
491 struct zfcp_hba_dbf_record *rec = (struct zfcp_hba_dbf_record *)in_buf;
492 int len = 0;
493
494 if (strncmp(rec->tag, "dump", ZFCP_DBF_TAG_SIZE) == 0)
495 return 0;
496
497 len += zfcp_dbf_tag(out_buf + len, "tag", rec->tag);
498 if (isalpha(rec->tag2[0]))
499 len += zfcp_dbf_tag(out_buf + len, "tag2", rec->tag2);
500 if (strncmp(rec->tag, "resp", ZFCP_DBF_TAG_SIZE) == 0)
501 len += zfcp_hba_dbf_view_response(out_buf + len,
502 &rec->type.response);
503 else if (strncmp(rec->tag, "stat", ZFCP_DBF_TAG_SIZE) == 0)
504 len += zfcp_hba_dbf_view_status(out_buf + len,
505 &rec->type.status);
506 else if (strncmp(rec->tag, "qdio", ZFCP_DBF_TAG_SIZE) == 0)
507 len += zfcp_hba_dbf_view_qdio(out_buf + len, &rec->type.qdio);
508
509 len += sprintf(out_buf + len, "\n");
510
511 return len;
512}
513
Heiko Carstens2b67fc42007-02-05 21:16:47 +0100514static struct debug_view zfcp_hba_dbf_view = {
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200515 "structured",
516 NULL,
517 &zfcp_dbf_view_header,
518 &zfcp_hba_dbf_view_format,
519 NULL,
520 NULL
521};
522
Martin Peschked79a83d2008-03-27 14:22:00 +0100523static const char *zfcp_rec_dbf_tags[] = {
Martin Peschke348447e2008-03-27 14:22:01 +0100524 [ZFCP_REC_DBF_ID_THREAD] = "thread",
Martin Peschked79a83d2008-03-27 14:22:00 +0100525};
526
527static const char *zfcp_rec_dbf_ids[] = {
Martin Peschke348447e2008-03-27 14:22:01 +0100528 [1] = "new",
529 [2] = "ready",
530 [3] = "kill",
531 [4] = "down sleep",
532 [5] = "down wakeup",
533 [6] = "down sleep ecd",
534 [7] = "down wakeup ecd",
535 [8] = "down sleep epd",
536 [9] = "down wakeup epd",
Martin Peschked79a83d2008-03-27 14:22:00 +0100537};
538
539static int zfcp_rec_dbf_view_format(debug_info_t *id, struct debug_view *view,
540 char *buf, const char *_rec)
541{
542 struct zfcp_rec_dbf_record *r = (struct zfcp_rec_dbf_record *)_rec;
543 char *p = buf;
544
545 zfcp_dbf_outs(&p, "tag", zfcp_rec_dbf_tags[r->id]);
546 zfcp_dbf_outs(&p, "hint", zfcp_rec_dbf_ids[r->id2]);
547 zfcp_dbf_out(&p, "id", "%d", r->id2);
548 switch (r->id) {
Martin Peschke348447e2008-03-27 14:22:01 +0100549 case ZFCP_REC_DBF_ID_THREAD:
550 zfcp_dbf_out(&p, "sema", "%d", r->u.thread.sema);
551 zfcp_dbf_out(&p, "total", "%d", r->u.thread.total);
552 zfcp_dbf_out(&p, "ready", "%d", r->u.thread.ready);
553 zfcp_dbf_out(&p, "running", "%d", r->u.thread.running);
554 break;
Martin Peschked79a83d2008-03-27 14:22:00 +0100555 }
556 sprintf(p, "\n");
557 return (p - buf) + 1;
558}
559
560static struct debug_view zfcp_rec_dbf_view = {
561 "structured",
562 NULL,
563 &zfcp_dbf_view_header,
564 &zfcp_rec_dbf_view_format,
565 NULL,
566 NULL
567};
568
Martin Peschke348447e2008-03-27 14:22:01 +0100569/**
570 * zfcp_rec_dbf_event_thread - trace event related to recovery thread operation
571 * @id2: identifier for event
572 * @adapter: adapter
573 * @lock: non-zero value indicates that erp_lock has not yet been acquired
574 */
575void zfcp_rec_dbf_event_thread(u8 id2, struct zfcp_adapter *adapter, int lock)
576{
577 struct zfcp_rec_dbf_record *r = &adapter->rec_dbf_buf;
578 unsigned long flags = 0;
579 struct list_head *entry;
580 unsigned ready = 0, running = 0, total;
581
582 if (lock)
583 read_lock_irqsave(&adapter->erp_lock, flags);
584 list_for_each(entry, &adapter->erp_ready_head)
585 ready++;
586 list_for_each(entry, &adapter->erp_running_head)
587 running++;
588 total = adapter->erp_total_count;
589 if (lock)
590 read_unlock_irqrestore(&adapter->erp_lock, flags);
591
592 spin_lock_irqsave(&adapter->rec_dbf_lock, flags);
593 memset(r, 0, sizeof(*r));
594 r->id = ZFCP_REC_DBF_ID_THREAD;
595 r->id2 = id2;
596 r->u.thread.sema = atomic_read(&adapter->erp_ready_sem.count);
597 r->u.thread.total = total;
598 r->u.thread.ready = ready;
599 r->u.thread.running = running;
600 debug_event(adapter->rec_dbf, 5, r, sizeof(*r));
601 spin_unlock_irqrestore(&adapter->rec_dbf_lock, flags);
602}
603
Heiko Carstens763968e2007-05-10 15:45:46 +0200604static void
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200605_zfcp_san_dbf_event_common_ct(const char *tag, struct zfcp_fsf_req *fsf_req,
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200606 u32 s_id, u32 d_id, void *buffer, int buflen)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200607{
608 struct zfcp_send_ct *send_ct = (struct zfcp_send_ct *)fsf_req->data;
609 struct zfcp_port *port = send_ct->port;
610 struct zfcp_adapter *adapter = port->adapter;
611 struct ct_hdr *header = (struct ct_hdr *)buffer;
612 struct zfcp_san_dbf_record *rec = &adapter->san_dbf_buf;
613 struct zfcp_san_dbf_record_ct *ct = &rec->type.ct;
614 unsigned long flags;
615
616 spin_lock_irqsave(&adapter->san_dbf_lock, flags);
617 memset(rec, 0, sizeof(struct zfcp_san_dbf_record));
618 strncpy(rec->tag, tag, ZFCP_DBF_TAG_SIZE);
619 rec->fsf_reqid = (unsigned long)fsf_req;
620 rec->fsf_seqno = fsf_req->seq_no;
621 rec->s_id = s_id;
622 rec->d_id = d_id;
623 if (strncmp(tag, "octc", ZFCP_DBF_TAG_SIZE) == 0) {
624 ct->type.request.cmd_req_code = header->cmd_rsp_code;
625 ct->type.request.revision = header->revision;
626 ct->type.request.gs_type = header->gs_type;
627 ct->type.request.gs_subtype = header->gs_subtype;
628 ct->type.request.options = header->options;
629 ct->type.request.max_res_size = header->max_res_size;
630 } else if (strncmp(tag, "rctc", ZFCP_DBF_TAG_SIZE) == 0) {
631 ct->type.response.cmd_rsp_code = header->cmd_rsp_code;
632 ct->type.response.revision = header->revision;
633 ct->type.response.reason_code = header->reason_code;
634 ct->type.response.reason_code_expl = header->reason_code_expl;
635 ct->type.response.vendor_unique = header->vendor_unique;
636 }
637 ct->payload_size =
638 min(buflen - (int)sizeof(struct ct_hdr), ZFCP_DBF_CT_PAYLOAD);
639 memcpy(ct->payload, buffer + sizeof(struct ct_hdr), ct->payload_size);
640 debug_event(adapter->san_dbf, 3,
641 rec, sizeof(struct zfcp_san_dbf_record));
642 spin_unlock_irqrestore(&adapter->san_dbf_lock, flags);
643}
644
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100645void zfcp_san_dbf_event_ct_request(struct zfcp_fsf_req *fsf_req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200646{
647 struct zfcp_send_ct *ct = (struct zfcp_send_ct *)fsf_req->data;
648 struct zfcp_port *port = ct->port;
649 struct zfcp_adapter *adapter = port->adapter;
650
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200651 _zfcp_san_dbf_event_common_ct("octc", fsf_req,
652 fc_host_port_id(adapter->scsi_host),
653 port->d_id, zfcp_sg_to_address(ct->req),
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200654 ct->req->length);
655}
656
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100657void zfcp_san_dbf_event_ct_response(struct zfcp_fsf_req *fsf_req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200658{
659 struct zfcp_send_ct *ct = (struct zfcp_send_ct *)fsf_req->data;
660 struct zfcp_port *port = ct->port;
661 struct zfcp_adapter *adapter = port->adapter;
662
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200663 _zfcp_san_dbf_event_common_ct("rctc", fsf_req, port->d_id,
664 fc_host_port_id(adapter->scsi_host),
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200665 zfcp_sg_to_address(ct->resp),
666 ct->resp->length);
667}
668
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100669static void
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200670_zfcp_san_dbf_event_common_els(const char *tag, int level,
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200671 struct zfcp_fsf_req *fsf_req, u32 s_id,
672 u32 d_id, u8 ls_code, void *buffer, int buflen)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200673{
674 struct zfcp_adapter *adapter = fsf_req->adapter;
675 struct zfcp_san_dbf_record *rec = &adapter->san_dbf_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200676 unsigned long flags;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200677
678 spin_lock_irqsave(&adapter->san_dbf_lock, flags);
Martin Peschke0f65e952008-03-27 14:21:56 +0100679 memset(rec, 0, sizeof(struct zfcp_san_dbf_record));
680 strncpy(rec->tag, tag, ZFCP_DBF_TAG_SIZE);
681 rec->fsf_reqid = (unsigned long)fsf_req;
682 rec->fsf_seqno = fsf_req->seq_no;
683 rec->s_id = s_id;
684 rec->d_id = d_id;
685 rec->type.els.ls_code = ls_code;
686 debug_event(adapter->san_dbf, level, rec, sizeof(*rec));
687 zfcp_dbf_hexdump(adapter->san_dbf, rec, sizeof(*rec), level,
688 buffer, min(buflen, ZFCP_DBF_ELS_MAX_PAYLOAD));
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200689 spin_unlock_irqrestore(&adapter->san_dbf_lock, flags);
690}
691
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100692void zfcp_san_dbf_event_els_request(struct zfcp_fsf_req *fsf_req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200693{
694 struct zfcp_send_els *els = (struct zfcp_send_els *)fsf_req->data;
695
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200696 _zfcp_san_dbf_event_common_els("oels", 2, fsf_req,
697 fc_host_port_id(els->adapter->scsi_host),
698 els->d_id,
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200699 *(u8 *) zfcp_sg_to_address(els->req),
700 zfcp_sg_to_address(els->req),
701 els->req->length);
702}
703
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100704void zfcp_san_dbf_event_els_response(struct zfcp_fsf_req *fsf_req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200705{
706 struct zfcp_send_els *els = (struct zfcp_send_els *)fsf_req->data;
707
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200708 _zfcp_san_dbf_event_common_els("rels", 2, fsf_req, els->d_id,
709 fc_host_port_id(els->adapter->scsi_host),
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200710 *(u8 *) zfcp_sg_to_address(els->req),
711 zfcp_sg_to_address(els->resp),
712 els->resp->length);
713}
714
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100715void zfcp_san_dbf_event_incoming_els(struct zfcp_fsf_req *fsf_req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200716{
717 struct zfcp_adapter *adapter = fsf_req->adapter;
718 struct fsf_status_read_buffer *status_buffer =
719 (struct fsf_status_read_buffer *)fsf_req->data;
720 int length = (int)status_buffer->length -
721 (int)((void *)&status_buffer->payload - (void *)status_buffer);
722
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200723 _zfcp_san_dbf_event_common_els("iels", 1, fsf_req, status_buffer->d_id,
724 fc_host_port_id(adapter->scsi_host),
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200725 *(u8 *) status_buffer->payload,
726 (void *)status_buffer->payload, length);
727}
728
729static int
730zfcp_san_dbf_view_format(debug_info_t * id, struct debug_view *view,
731 char *out_buf, const char *in_buf)
732{
733 struct zfcp_san_dbf_record *rec = (struct zfcp_san_dbf_record *)in_buf;
734 char *buffer = NULL;
735 int buflen = 0, total = 0;
736 int len = 0;
737
738 if (strncmp(rec->tag, "dump", ZFCP_DBF_TAG_SIZE) == 0)
739 return 0;
740
741 len += zfcp_dbf_tag(out_buf + len, "tag", rec->tag);
742 len += zfcp_dbf_view(out_buf + len, "fsf_reqid", "0x%0Lx",
743 rec->fsf_reqid);
744 len += zfcp_dbf_view(out_buf + len, "fsf_seqno", "0x%08x",
745 rec->fsf_seqno);
746 len += zfcp_dbf_view(out_buf + len, "s_id", "0x%06x", rec->s_id);
747 len += zfcp_dbf_view(out_buf + len, "d_id", "0x%06x", rec->d_id);
748
749 if (strncmp(rec->tag, "octc", ZFCP_DBF_TAG_SIZE) == 0) {
750 len += zfcp_dbf_view(out_buf + len, "cmd_req_code", "0x%04x",
751 rec->type.ct.type.request.cmd_req_code);
752 len += zfcp_dbf_view(out_buf + len, "revision", "0x%02x",
753 rec->type.ct.type.request.revision);
754 len += zfcp_dbf_view(out_buf + len, "gs_type", "0x%02x",
755 rec->type.ct.type.request.gs_type);
756 len += zfcp_dbf_view(out_buf + len, "gs_subtype", "0x%02x",
757 rec->type.ct.type.request.gs_subtype);
758 len += zfcp_dbf_view(out_buf + len, "options", "0x%02x",
759 rec->type.ct.type.request.options);
760 len += zfcp_dbf_view(out_buf + len, "max_res_size", "0x%04x",
761 rec->type.ct.type.request.max_res_size);
762 total = rec->type.ct.payload_size;
763 buffer = rec->type.ct.payload;
764 buflen = min(total, ZFCP_DBF_CT_PAYLOAD);
765 } else if (strncmp(rec->tag, "rctc", ZFCP_DBF_TAG_SIZE) == 0) {
766 len += zfcp_dbf_view(out_buf + len, "cmd_rsp_code", "0x%04x",
767 rec->type.ct.type.response.cmd_rsp_code);
768 len += zfcp_dbf_view(out_buf + len, "revision", "0x%02x",
769 rec->type.ct.type.response.revision);
770 len += zfcp_dbf_view(out_buf + len, "reason_code", "0x%02x",
771 rec->type.ct.type.response.reason_code);
772 len +=
773 zfcp_dbf_view(out_buf + len, "reason_code_expl", "0x%02x",
774 rec->type.ct.type.response.reason_code_expl);
775 len +=
776 zfcp_dbf_view(out_buf + len, "vendor_unique", "0x%02x",
777 rec->type.ct.type.response.vendor_unique);
778 total = rec->type.ct.payload_size;
779 buffer = rec->type.ct.payload;
780 buflen = min(total, ZFCP_DBF_CT_PAYLOAD);
781 } else if (strncmp(rec->tag, "oels", ZFCP_DBF_TAG_SIZE) == 0 ||
782 strncmp(rec->tag, "rels", ZFCP_DBF_TAG_SIZE) == 0 ||
783 strncmp(rec->tag, "iels", ZFCP_DBF_TAG_SIZE) == 0) {
784 len += zfcp_dbf_view(out_buf + len, "ls_code", "0x%02x",
785 rec->type.els.ls_code);
786 total = rec->type.els.payload_size;
787 buffer = rec->type.els.payload;
788 buflen = min(total, ZFCP_DBF_ELS_PAYLOAD);
789 }
790
791 len += zfcp_dbf_view_dump(out_buf + len, "payload",
792 buffer, buflen, 0, total);
793
794 if (buflen == total)
795 len += sprintf(out_buf + len, "\n");
796
797 return len;
798}
799
Heiko Carstens2b67fc42007-02-05 21:16:47 +0100800static struct debug_view zfcp_san_dbf_view = {
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200801 "structured",
802 NULL,
803 &zfcp_dbf_view_header,
804 &zfcp_san_dbf_view_format,
805 NULL,
806 NULL
807};
808
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100809static void
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200810_zfcp_scsi_dbf_event_common(const char *tag, const char *tag2, int level,
811 struct zfcp_adapter *adapter,
812 struct scsi_cmnd *scsi_cmnd,
Maxim Shchetynined829ad2006-02-11 01:42:58 +0100813 struct zfcp_fsf_req *fsf_req,
Andreas Herrmann4eff4a32006-09-18 22:29:20 +0200814 unsigned long old_req_id)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200815{
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200816 struct zfcp_scsi_dbf_record *rec = &adapter->scsi_dbf_buf;
817 struct zfcp_dbf_dump *dump = (struct zfcp_dbf_dump *)rec;
818 unsigned long flags;
819 struct fcp_rsp_iu *fcp_rsp;
820 char *fcp_rsp_info = NULL, *fcp_sns_info = NULL;
821 int offset = 0, buflen = 0;
822
823 spin_lock_irqsave(&adapter->scsi_dbf_lock, flags);
824 do {
825 memset(rec, 0, sizeof(struct zfcp_scsi_dbf_record));
826 if (offset == 0) {
827 strncpy(rec->tag, tag, ZFCP_DBF_TAG_SIZE);
828 strncpy(rec->tag2, tag2, ZFCP_DBF_TAG_SIZE);
Maxim Shchetynined829ad2006-02-11 01:42:58 +0100829 if (scsi_cmnd != NULL) {
830 if (scsi_cmnd->device) {
831 rec->scsi_id = scsi_cmnd->device->id;
832 rec->scsi_lun = scsi_cmnd->device->lun;
833 }
834 rec->scsi_result = scsi_cmnd->result;
835 rec->scsi_cmnd = (unsigned long)scsi_cmnd;
836 rec->scsi_serial = scsi_cmnd->serial_number;
837 memcpy(rec->scsi_opcode, &scsi_cmnd->cmnd,
838 min((int)scsi_cmnd->cmd_len,
839 ZFCP_DBF_SCSI_OPCODE));
840 rec->scsi_retries = scsi_cmnd->retries;
841 rec->scsi_allowed = scsi_cmnd->allowed;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200842 }
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200843 if (fsf_req != NULL) {
844 fcp_rsp = (struct fcp_rsp_iu *)
845 &(fsf_req->qtcb->bottom.io.fcp_rsp);
846 fcp_rsp_info =
847 zfcp_get_fcp_rsp_info_ptr(fcp_rsp);
848 fcp_sns_info =
849 zfcp_get_fcp_sns_info_ptr(fcp_rsp);
850
851 rec->type.fcp.rsp_validity =
852 fcp_rsp->validity.value;
853 rec->type.fcp.rsp_scsi_status =
854 fcp_rsp->scsi_status;
855 rec->type.fcp.rsp_resid = fcp_rsp->fcp_resid;
856 if (fcp_rsp->validity.bits.fcp_rsp_len_valid)
857 rec->type.fcp.rsp_code =
858 *(fcp_rsp_info + 3);
859 if (fcp_rsp->validity.bits.fcp_sns_len_valid) {
860 buflen = min((int)fcp_rsp->fcp_sns_len,
861 ZFCP_DBF_SCSI_MAX_FCP_SNS_INFO);
862 rec->type.fcp.sns_info_len = buflen;
863 memcpy(rec->type.fcp.sns_info,
864 fcp_sns_info,
865 min(buflen,
866 ZFCP_DBF_SCSI_FCP_SNS_INFO));
867 offset += min(buflen,
868 ZFCP_DBF_SCSI_FCP_SNS_INFO);
869 }
870
871 rec->fsf_reqid = (unsigned long)fsf_req;
872 rec->fsf_seqno = fsf_req->seq_no;
873 rec->fsf_issued = fsf_req->issued;
874 }
Andreas Herrmann4eff4a32006-09-18 22:29:20 +0200875 rec->type.old_fsf_reqid = old_req_id;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200876 } else {
877 strncpy(dump->tag, "dump", ZFCP_DBF_TAG_SIZE);
878 dump->total_size = buflen;
879 dump->offset = offset;
880 dump->size = min(buflen - offset,
881 (int)sizeof(struct
882 zfcp_scsi_dbf_record) -
883 (int)sizeof(struct zfcp_dbf_dump));
884 memcpy(dump->data, fcp_sns_info + offset, dump->size);
885 offset += dump->size;
886 }
887 debug_event(adapter->scsi_dbf, level,
888 rec, sizeof(struct zfcp_scsi_dbf_record));
889 } while (offset < buflen);
890 spin_unlock_irqrestore(&adapter->scsi_dbf_lock, flags);
891}
892
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100893void
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200894zfcp_scsi_dbf_event_result(const char *tag, int level,
895 struct zfcp_adapter *adapter,
Maxim Shchetynined829ad2006-02-11 01:42:58 +0100896 struct scsi_cmnd *scsi_cmnd,
897 struct zfcp_fsf_req *fsf_req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200898{
Maxim Shchetynined829ad2006-02-11 01:42:58 +0100899 _zfcp_scsi_dbf_event_common("rslt", tag, level,
Andreas Herrmann4eff4a32006-09-18 22:29:20 +0200900 adapter, scsi_cmnd, fsf_req, 0);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200901}
902
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100903void
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200904zfcp_scsi_dbf_event_abort(const char *tag, struct zfcp_adapter *adapter,
905 struct scsi_cmnd *scsi_cmnd,
Maxim Shchetynined829ad2006-02-11 01:42:58 +0100906 struct zfcp_fsf_req *new_fsf_req,
Andreas Herrmann4eff4a32006-09-18 22:29:20 +0200907 unsigned long old_req_id)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200908{
Maxim Shchetynined829ad2006-02-11 01:42:58 +0100909 _zfcp_scsi_dbf_event_common("abrt", tag, 1,
Andreas Herrmann4eff4a32006-09-18 22:29:20 +0200910 adapter, scsi_cmnd, new_fsf_req, old_req_id);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200911}
912
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100913void
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200914zfcp_scsi_dbf_event_devreset(const char *tag, u8 flag, struct zfcp_unit *unit,
915 struct scsi_cmnd *scsi_cmnd)
916{
917 struct zfcp_adapter *adapter = unit->port->adapter;
918
919 _zfcp_scsi_dbf_event_common(flag == FCP_TARGET_RESET ? "trst" : "lrst",
Andreas Herrmann4eff4a32006-09-18 22:29:20 +0200920 tag, 1, adapter, scsi_cmnd, NULL, 0);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200921}
922
923static int
924zfcp_scsi_dbf_view_format(debug_info_t * id, struct debug_view *view,
925 char *out_buf, const char *in_buf)
926{
927 struct zfcp_scsi_dbf_record *rec =
928 (struct zfcp_scsi_dbf_record *)in_buf;
929 int len = 0;
930
931 if (strncmp(rec->tag, "dump", ZFCP_DBF_TAG_SIZE) == 0)
932 return 0;
933
934 len += zfcp_dbf_tag(out_buf + len, "tag", rec->tag);
935 len += zfcp_dbf_tag(out_buf + len, "tag2", rec->tag2);
936 len += zfcp_dbf_view(out_buf + len, "scsi_id", "0x%08x", rec->scsi_id);
937 len += zfcp_dbf_view(out_buf + len, "scsi_lun", "0x%08x",
938 rec->scsi_lun);
939 len += zfcp_dbf_view(out_buf + len, "scsi_result", "0x%08x",
940 rec->scsi_result);
941 len += zfcp_dbf_view(out_buf + len, "scsi_cmnd", "0x%0Lx",
942 rec->scsi_cmnd);
943 len += zfcp_dbf_view(out_buf + len, "scsi_serial", "0x%016Lx",
944 rec->scsi_serial);
945 len += zfcp_dbf_view_dump(out_buf + len, "scsi_opcode",
946 rec->scsi_opcode,
947 ZFCP_DBF_SCSI_OPCODE,
948 0, ZFCP_DBF_SCSI_OPCODE);
949 len += zfcp_dbf_view(out_buf + len, "scsi_retries", "0x%02x",
950 rec->scsi_retries);
951 len += zfcp_dbf_view(out_buf + len, "scsi_allowed", "0x%02x",
952 rec->scsi_allowed);
Maxim Shchetynined829ad2006-02-11 01:42:58 +0100953 if (strncmp(rec->tag, "abrt", ZFCP_DBF_TAG_SIZE) == 0) {
954 len += zfcp_dbf_view(out_buf + len, "old_fsf_reqid", "0x%0Lx",
955 rec->type.old_fsf_reqid);
956 }
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200957 len += zfcp_dbf_view(out_buf + len, "fsf_reqid", "0x%0Lx",
958 rec->fsf_reqid);
959 len += zfcp_dbf_view(out_buf + len, "fsf_seqno", "0x%08x",
960 rec->fsf_seqno);
961 len += zfcp_dbf_stck(out_buf + len, "fsf_issued", rec->fsf_issued);
962 if (strncmp(rec->tag, "rslt", ZFCP_DBF_TAG_SIZE) == 0) {
963 len +=
964 zfcp_dbf_view(out_buf + len, "fcp_rsp_validity", "0x%02x",
965 rec->type.fcp.rsp_validity);
966 len +=
967 zfcp_dbf_view(out_buf + len, "fcp_rsp_scsi_status",
968 "0x%02x", rec->type.fcp.rsp_scsi_status);
969 len +=
970 zfcp_dbf_view(out_buf + len, "fcp_rsp_resid", "0x%08x",
971 rec->type.fcp.rsp_resid);
972 len +=
973 zfcp_dbf_view(out_buf + len, "fcp_rsp_code", "0x%08x",
974 rec->type.fcp.rsp_code);
975 len +=
976 zfcp_dbf_view(out_buf + len, "fcp_sns_info_len", "0x%08x",
977 rec->type.fcp.sns_info_len);
978 len +=
979 zfcp_dbf_view_dump(out_buf + len, "fcp_sns_info",
980 rec->type.fcp.sns_info,
981 min((int)rec->type.fcp.sns_info_len,
982 ZFCP_DBF_SCSI_FCP_SNS_INFO), 0,
983 rec->type.fcp.sns_info_len);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200984 }
985
986 len += sprintf(out_buf + len, "\n");
987
988 return len;
989}
990
Heiko Carstens2b67fc42007-02-05 21:16:47 +0100991static struct debug_view zfcp_scsi_dbf_view = {
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200992 "structured",
993 NULL,
994 &zfcp_dbf_view_header,
995 &zfcp_scsi_dbf_view_format,
996 NULL,
997 NULL
998};
999
1000/**
1001 * zfcp_adapter_debug_register - registers debug feature for an adapter
1002 * @adapter: pointer to adapter for which debug features should be registered
1003 * return: -ENOMEM on error, 0 otherwise
1004 */
1005int zfcp_adapter_debug_register(struct zfcp_adapter *adapter)
1006{
1007 char dbf_name[DEBUG_MAX_NAME_LEN];
1008
1009 /* debug feature area which records recovery activity */
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001010 sprintf(dbf_name, "zfcp_%s_erp", zfcp_get_busid_by_adapter(adapter));
1011 adapter->erp_dbf = debug_register(dbf_name, dbfsize, 2,
1012 sizeof(struct zfcp_erp_dbf_record));
1013 if (!adapter->erp_dbf)
1014 goto failed;
1015 debug_register_view(adapter->erp_dbf, &debug_hex_ascii_view);
1016 debug_set_level(adapter->erp_dbf, 3);
1017
Martin Peschked79a83d2008-03-27 14:22:00 +01001018 /* debug feature area which records recovery activity */
1019 sprintf(dbf_name, "zfcp_%s_rec", zfcp_get_busid_by_adapter(adapter));
1020 adapter->rec_dbf = debug_register(dbf_name, dbfsize, 1,
1021 sizeof(struct zfcp_rec_dbf_record));
1022 if (!adapter->rec_dbf)
1023 goto failed;
1024 debug_register_view(adapter->rec_dbf, &debug_hex_ascii_view);
1025 debug_register_view(adapter->rec_dbf, &zfcp_rec_dbf_view);
1026 debug_set_level(adapter->rec_dbf, 3);
1027
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001028 /* debug feature area which records HBA (FSF and QDIO) conditions */
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001029 sprintf(dbf_name, "zfcp_%s_hba", zfcp_get_busid_by_adapter(adapter));
1030 adapter->hba_dbf = debug_register(dbf_name, dbfsize, 1,
1031 sizeof(struct zfcp_hba_dbf_record));
1032 if (!adapter->hba_dbf)
1033 goto failed;
1034 debug_register_view(adapter->hba_dbf, &debug_hex_ascii_view);
1035 debug_register_view(adapter->hba_dbf, &zfcp_hba_dbf_view);
1036 debug_set_level(adapter->hba_dbf, 3);
1037
1038 /* debug feature area which records SAN command failures and recovery */
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001039 sprintf(dbf_name, "zfcp_%s_san", zfcp_get_busid_by_adapter(adapter));
1040 adapter->san_dbf = debug_register(dbf_name, dbfsize, 1,
1041 sizeof(struct zfcp_san_dbf_record));
1042 if (!adapter->san_dbf)
1043 goto failed;
1044 debug_register_view(adapter->san_dbf, &debug_hex_ascii_view);
1045 debug_register_view(adapter->san_dbf, &zfcp_san_dbf_view);
1046 debug_set_level(adapter->san_dbf, 6);
1047
1048 /* debug feature area which records SCSI command failures and recovery */
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001049 sprintf(dbf_name, "zfcp_%s_scsi", zfcp_get_busid_by_adapter(adapter));
1050 adapter->scsi_dbf = debug_register(dbf_name, dbfsize, 1,
1051 sizeof(struct zfcp_scsi_dbf_record));
1052 if (!adapter->scsi_dbf)
1053 goto failed;
1054 debug_register_view(adapter->scsi_dbf, &debug_hex_ascii_view);
1055 debug_register_view(adapter->scsi_dbf, &zfcp_scsi_dbf_view);
1056 debug_set_level(adapter->scsi_dbf, 3);
1057
1058 return 0;
1059
1060 failed:
1061 zfcp_adapter_debug_unregister(adapter);
1062
1063 return -ENOMEM;
1064}
1065
1066/**
1067 * zfcp_adapter_debug_unregister - unregisters debug feature for an adapter
1068 * @adapter: pointer to adapter for which debug features should be unregistered
1069 */
1070void zfcp_adapter_debug_unregister(struct zfcp_adapter *adapter)
1071{
1072 debug_unregister(adapter->scsi_dbf);
1073 debug_unregister(adapter->san_dbf);
1074 debug_unregister(adapter->hba_dbf);
Martin Peschked79a83d2008-03-27 14:22:00 +01001075 debug_unregister(adapter->rec_dbf);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001076 debug_unregister(adapter->erp_dbf);
1077 adapter->scsi_dbf = NULL;
1078 adapter->san_dbf = NULL;
1079 adapter->hba_dbf = NULL;
Martin Peschked79a83d2008-03-27 14:22:00 +01001080 adapter->rec_dbf = NULL;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001081 adapter->erp_dbf = NULL;
1082}
1083
1084#undef ZFCP_LOG_AREA