blob: 15b534206b348af1486da3dfd751854f715b2fef [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
65static int zfcp_dbf_tag(char *out_buf, const char *label, const char *tag)
66{
67 int len = 0, i;
68
69 len += sprintf(out_buf + len, "%-24s", label);
70 for (i = 0; i < ZFCP_DBF_TAG_SIZE; i++)
71 len += sprintf(out_buf + len, "%c", tag[i]);
72 len += sprintf(out_buf + len, "\n");
73
74 return len;
75}
76
77static int
78zfcp_dbf_view(char *out_buf, const char *label, const char *format, ...)
79{
80 va_list arg;
81 int len = 0;
82
83 len += sprintf(out_buf + len, "%-24s", label);
84 va_start(arg, format);
85 len += vsprintf(out_buf + len, format, arg);
86 va_end(arg);
87 len += sprintf(out_buf + len, "\n");
88
89 return len;
90}
91
Martin Peschke10223c62008-03-27 14:21:59 +010092static void zfcp_dbf_outs(char **buf, const char *s1, const char *s2)
93{
94 *buf += sprintf(*buf, "%-24s%s\n", s1, s2);
95}
96
97static void zfcp_dbf_out(char **buf, const char *s, const char *format, ...)
98{
99 va_list arg;
100
101 *buf += sprintf(*buf, "%-24s", s);
102 va_start(arg, format);
103 *buf += vsprintf(*buf, format, arg);
104 va_end(arg);
105 *buf += sprintf(*buf, "\n");
106}
107
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200108static int
109zfcp_dbf_view_dump(char *out_buf, const char *label,
110 char *buffer, int buflen, int offset, int total_size)
111{
112 int len = 0;
113
114 if (offset == 0)
115 len += sprintf(out_buf + len, "%-24s ", label);
116
117 while (buflen--) {
118 if (offset > 0) {
119 if ((offset % 32) == 0)
120 len += sprintf(out_buf + len, "\n%-24c ", ' ');
121 else if ((offset % 4) == 0)
122 len += sprintf(out_buf + len, " ");
123 }
124 len += sprintf(out_buf + len, "%02x", *buffer++);
125 if (++offset == total_size) {
126 len += sprintf(out_buf + len, "\n");
127 break;
128 }
129 }
130
131 if (total_size == 0)
132 len += sprintf(out_buf + len, "\n");
133
134 return len;
135}
136
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100137static int
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200138zfcp_dbf_view_header(debug_info_t * id, struct debug_view *view, int area,
139 debug_entry_t * entry, char *out_buf)
140{
141 struct zfcp_dbf_dump *dump = (struct zfcp_dbf_dump *)DEBUG_DATA(entry);
Martin Peschke8fc5af12008-03-31 11:15:23 +0200142 struct timespec t;
Martin Peschkeb634fff2008-03-31 11:15:24 +0200143 char *p = out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200144
145 if (strncmp(dump->tag, "dump", ZFCP_DBF_TAG_SIZE) != 0) {
Martin Peschke8fc5af12008-03-31 11:15:23 +0200146 zfcp_dbf_timestamp(entry->id.stck, &t);
Martin Peschkeb634fff2008-03-31 11:15:24 +0200147 zfcp_dbf_out(&p, "timestamp", "%011lu:%06lu",
148 t.tv_sec, t.tv_nsec);
149 zfcp_dbf_out(&p, "cpu", "%02i", entry->id.fields.cpuid);
150 } else {
151 p += zfcp_dbf_view_dump(p, NULL, dump->data, dump->size,
152 dump->offset, dump->total_size);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200153 if ((dump->offset + dump->size) == dump->total_size)
Martin Peschkeb634fff2008-03-31 11:15:24 +0200154 p += sprintf(p, "\n");
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200155 }
Martin Peschkeb634fff2008-03-31 11:15:24 +0200156 return p - out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200157}
158
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100159void zfcp_hba_dbf_event_fsf_response(struct zfcp_fsf_req *fsf_req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200160{
161 struct zfcp_adapter *adapter = fsf_req->adapter;
162 struct fsf_qtcb *qtcb = fsf_req->qtcb;
163 union fsf_prot_status_qual *prot_status_qual =
164 &qtcb->prefix.prot_status_qual;
165 union fsf_status_qual *fsf_status_qual = &qtcb->header.fsf_status_qual;
166 struct scsi_cmnd *scsi_cmnd;
167 struct zfcp_port *port;
168 struct zfcp_unit *unit;
169 struct zfcp_send_els *send_els;
170 struct zfcp_hba_dbf_record *rec = &adapter->hba_dbf_buf;
171 struct zfcp_hba_dbf_record_response *response = &rec->type.response;
172 int level;
173 unsigned long flags;
174
175 spin_lock_irqsave(&adapter->hba_dbf_lock, flags);
176 memset(rec, 0, sizeof(struct zfcp_hba_dbf_record));
177 strncpy(rec->tag, "resp", ZFCP_DBF_TAG_SIZE);
178
179 if ((qtcb->prefix.prot_status != FSF_PROT_GOOD) &&
180 (qtcb->prefix.prot_status != FSF_PROT_FSF_STATUS_PRESENTED)) {
181 strncpy(rec->tag2, "perr", ZFCP_DBF_TAG_SIZE);
182 level = 1;
183 } else if (qtcb->header.fsf_status != FSF_GOOD) {
184 strncpy(rec->tag2, "ferr", ZFCP_DBF_TAG_SIZE);
185 level = 1;
186 } else if ((fsf_req->fsf_command == FSF_QTCB_OPEN_PORT_WITH_DID) ||
187 (fsf_req->fsf_command == FSF_QTCB_OPEN_LUN)) {
188 strncpy(rec->tag2, "open", ZFCP_DBF_TAG_SIZE);
189 level = 4;
Martin Peschkeb75db732008-03-27 14:21:58 +0100190 } else if (qtcb->header.log_length) {
191 strncpy(rec->tag2, "qtcb", ZFCP_DBF_TAG_SIZE);
192 level = 5;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200193 } else {
194 strncpy(rec->tag2, "norm", ZFCP_DBF_TAG_SIZE);
195 level = 6;
196 }
197
198 response->fsf_command = fsf_req->fsf_command;
199 response->fsf_reqid = (unsigned long)fsf_req;
200 response->fsf_seqno = fsf_req->seq_no;
201 response->fsf_issued = fsf_req->issued;
202 response->fsf_prot_status = qtcb->prefix.prot_status;
203 response->fsf_status = qtcb->header.fsf_status;
204 memcpy(response->fsf_prot_status_qual,
205 prot_status_qual, FSF_PROT_STATUS_QUAL_SIZE);
206 memcpy(response->fsf_status_qual,
207 fsf_status_qual, FSF_STATUS_QUALIFIER_SIZE);
208 response->fsf_req_status = fsf_req->status;
209 response->sbal_first = fsf_req->sbal_first;
210 response->sbal_curr = fsf_req->sbal_curr;
211 response->sbal_last = fsf_req->sbal_last;
212 response->pool = fsf_req->pool != NULL;
213 response->erp_action = (unsigned long)fsf_req->erp_action;
214
215 switch (fsf_req->fsf_command) {
216 case FSF_QTCB_FCP_CMND:
217 if (fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT)
218 break;
219 scsi_cmnd = (struct scsi_cmnd *)fsf_req->data;
220 if (scsi_cmnd != NULL) {
221 response->data.send_fcp.scsi_cmnd
222 = (unsigned long)scsi_cmnd;
223 response->data.send_fcp.scsi_serial
224 = scsi_cmnd->serial_number;
225 }
226 break;
227
228 case FSF_QTCB_OPEN_PORT_WITH_DID:
229 case FSF_QTCB_CLOSE_PORT:
230 case FSF_QTCB_CLOSE_PHYSICAL_PORT:
231 port = (struct zfcp_port *)fsf_req->data;
232 response->data.port.wwpn = port->wwpn;
233 response->data.port.d_id = port->d_id;
234 response->data.port.port_handle = qtcb->header.port_handle;
235 break;
236
237 case FSF_QTCB_OPEN_LUN:
238 case FSF_QTCB_CLOSE_LUN:
239 unit = (struct zfcp_unit *)fsf_req->data;
240 port = unit->port;
241 response->data.unit.wwpn = port->wwpn;
242 response->data.unit.fcp_lun = unit->fcp_lun;
243 response->data.unit.port_handle = qtcb->header.port_handle;
244 response->data.unit.lun_handle = qtcb->header.lun_handle;
245 break;
246
247 case FSF_QTCB_SEND_ELS:
248 send_els = (struct zfcp_send_els *)fsf_req->data;
249 response->data.send_els.d_id = qtcb->bottom.support.d_id;
250 response->data.send_els.ls_code = send_els->ls_code >> 24;
251 break;
252
253 case FSF_QTCB_ABORT_FCP_CMND:
254 case FSF_QTCB_SEND_GENERIC:
255 case FSF_QTCB_EXCHANGE_CONFIG_DATA:
256 case FSF_QTCB_EXCHANGE_PORT_DATA:
257 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
258 case FSF_QTCB_UPLOAD_CONTROL_FILE:
259 break;
260 }
261
262 debug_event(adapter->hba_dbf, level,
263 rec, sizeof(struct zfcp_hba_dbf_record));
Martin Peschkeb75db732008-03-27 14:21:58 +0100264
265 /* have fcp channel microcode fixed to use as little as possible */
266 if (fsf_req->fsf_command != FSF_QTCB_FCP_CMND) {
267 /* adjust length skipping trailing zeros */
268 char *buf = (char *)qtcb + qtcb->header.log_start;
269 int len = qtcb->header.log_length;
270 for (; len && !buf[len - 1]; len--);
271 zfcp_dbf_hexdump(adapter->hba_dbf, rec, sizeof(*rec), level,
272 buf, len);
273 }
274
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200275 spin_unlock_irqrestore(&adapter->hba_dbf_lock, flags);
276}
277
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100278void
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200279zfcp_hba_dbf_event_fsf_unsol(const char *tag, struct zfcp_adapter *adapter,
280 struct fsf_status_read_buffer *status_buffer)
281{
282 struct zfcp_hba_dbf_record *rec = &adapter->hba_dbf_buf;
283 unsigned long flags;
284
285 spin_lock_irqsave(&adapter->hba_dbf_lock, flags);
286 memset(rec, 0, sizeof(struct zfcp_hba_dbf_record));
287 strncpy(rec->tag, "stat", ZFCP_DBF_TAG_SIZE);
288 strncpy(rec->tag2, tag, ZFCP_DBF_TAG_SIZE);
289
290 rec->type.status.failed = adapter->status_read_failed;
291 if (status_buffer != NULL) {
292 rec->type.status.status_type = status_buffer->status_type;
293 rec->type.status.status_subtype = status_buffer->status_subtype;
294 memcpy(&rec->type.status.queue_designator,
295 &status_buffer->queue_designator,
296 sizeof(struct fsf_queue_designator));
297
298 switch (status_buffer->status_type) {
299 case FSF_STATUS_READ_SENSE_DATA_AVAIL:
300 rec->type.status.payload_size =
301 ZFCP_DBF_UNSOL_PAYLOAD_SENSE_DATA_AVAIL;
302 break;
303
304 case FSF_STATUS_READ_BIT_ERROR_THRESHOLD:
305 rec->type.status.payload_size =
306 ZFCP_DBF_UNSOL_PAYLOAD_BIT_ERROR_THRESHOLD;
307 break;
308
309 case FSF_STATUS_READ_LINK_DOWN:
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200310 switch (status_buffer->status_subtype) {
311 case FSF_STATUS_READ_SUB_NO_PHYSICAL_LINK:
312 case FSF_STATUS_READ_SUB_FDISC_FAILED:
313 rec->type.status.payload_size =
314 sizeof(struct fsf_link_down_info);
315 }
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200316 break;
317
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200318 case FSF_STATUS_READ_FEATURE_UPDATE_ALERT:
319 rec->type.status.payload_size =
320 ZFCP_DBF_UNSOL_PAYLOAD_FEATURE_UPDATE_ALERT;
321 break;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200322 }
323 memcpy(&rec->type.status.payload,
324 &status_buffer->payload, rec->type.status.payload_size);
325 }
326
327 debug_event(adapter->hba_dbf, 2,
328 rec, sizeof(struct zfcp_hba_dbf_record));
329 spin_unlock_irqrestore(&adapter->hba_dbf_lock, flags);
330}
331
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100332void
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200333zfcp_hba_dbf_event_qdio(struct zfcp_adapter *adapter, unsigned int status,
334 unsigned int qdio_error, unsigned int siga_error,
335 int sbal_index, int sbal_count)
336{
337 struct zfcp_hba_dbf_record *rec = &adapter->hba_dbf_buf;
338 unsigned long flags;
339
340 spin_lock_irqsave(&adapter->hba_dbf_lock, flags);
341 memset(rec, 0, sizeof(struct zfcp_hba_dbf_record));
342 strncpy(rec->tag, "qdio", ZFCP_DBF_TAG_SIZE);
343 rec->type.qdio.status = status;
344 rec->type.qdio.qdio_error = qdio_error;
345 rec->type.qdio.siga_error = siga_error;
346 rec->type.qdio.sbal_index = sbal_index;
347 rec->type.qdio.sbal_count = sbal_count;
348 debug_event(adapter->hba_dbf, 0,
349 rec, sizeof(struct zfcp_hba_dbf_record));
350 spin_unlock_irqrestore(&adapter->hba_dbf_lock, flags);
351}
352
Martin Peschkeb634fff2008-03-31 11:15:24 +0200353static int zfcp_hba_dbf_view_response(char *buf,
354 struct zfcp_hba_dbf_record_response *r)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200355{
Martin Peschke8fc5af12008-03-31 11:15:23 +0200356 struct timespec t;
Martin Peschkeb634fff2008-03-31 11:15:24 +0200357 char *p = buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200358
Martin Peschkeb634fff2008-03-31 11:15:24 +0200359 zfcp_dbf_out(&p, "fsf_command", "0x%08x", r->fsf_command);
360 zfcp_dbf_out(&p, "fsf_reqid", "0x%0Lx", r->fsf_reqid);
361 zfcp_dbf_out(&p, "fsf_seqno", "0x%08x", r->fsf_seqno);
362 zfcp_dbf_timestamp(r->fsf_issued, &t);
363 zfcp_dbf_out(&p, "fsf_issued", "%011lu:%06lu", t.tv_sec, t.tv_nsec);
364 zfcp_dbf_out(&p, "fsf_prot_status", "0x%08x", r->fsf_prot_status);
365 zfcp_dbf_out(&p, "fsf_status", "0x%08x", r->fsf_status);
366 p += zfcp_dbf_view_dump(p, "fsf_prot_status_qual",
367 r->fsf_prot_status_qual,
368 FSF_PROT_STATUS_QUAL_SIZE,
369 0, FSF_PROT_STATUS_QUAL_SIZE);
370 p += zfcp_dbf_view_dump(p, "fsf_status_qual",
371 r->fsf_status_qual,
372 FSF_STATUS_QUALIFIER_SIZE,
373 0, FSF_STATUS_QUALIFIER_SIZE);
374 zfcp_dbf_out(&p, "fsf_req_status", "0x%08x", r->fsf_req_status);
375 zfcp_dbf_out(&p, "sbal_first", "0x%02x", r->sbal_first);
376 zfcp_dbf_out(&p, "sbal_curr", "0x%02x", r->sbal_curr);
377 zfcp_dbf_out(&p, "sbal_last", "0x%02x", r->sbal_last);
378 zfcp_dbf_out(&p, "pool", "0x%02x", r->pool);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200379
Martin Peschkeb634fff2008-03-31 11:15:24 +0200380 switch (r->fsf_command) {
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200381 case FSF_QTCB_FCP_CMND:
Martin Peschkeb634fff2008-03-31 11:15:24 +0200382 if (r->fsf_req_status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200383 break;
Martin Peschkeb634fff2008-03-31 11:15:24 +0200384 zfcp_dbf_out(&p, "scsi_cmnd", "0x%0Lx",
385 r->data.send_fcp.scsi_cmnd);
386 zfcp_dbf_out(&p, "scsi_serial", "0x%016Lx",
387 r->data.send_fcp.scsi_serial);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200388 break;
389
390 case FSF_QTCB_OPEN_PORT_WITH_DID:
391 case FSF_QTCB_CLOSE_PORT:
392 case FSF_QTCB_CLOSE_PHYSICAL_PORT:
Martin Peschkeb634fff2008-03-31 11:15:24 +0200393 zfcp_dbf_out(&p, "wwpn", "0x%016Lx", r->data.port.wwpn);
394 zfcp_dbf_out(&p, "d_id", "0x%06x", r->data.port.d_id);
395 zfcp_dbf_out(&p, "port_handle", "0x%08x",
396 r->data.port.port_handle);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200397 break;
398
399 case FSF_QTCB_OPEN_LUN:
400 case FSF_QTCB_CLOSE_LUN:
Martin Peschkeb634fff2008-03-31 11:15:24 +0200401 zfcp_dbf_out(&p, "wwpn", "0x%016Lx", r->data.unit.wwpn);
402 zfcp_dbf_out(&p, "fcp_lun", "0x%016Lx", r->data.unit.fcp_lun);
403 zfcp_dbf_out(&p, "port_handle", "0x%08x",
404 r->data.unit.port_handle);
405 zfcp_dbf_out(&p, "lun_handle", "0x%08x",
406 r->data.unit.lun_handle);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200407 break;
408
409 case FSF_QTCB_SEND_ELS:
Martin Peschkeb634fff2008-03-31 11:15:24 +0200410 zfcp_dbf_out(&p, "d_id", "0x%06x", r->data.send_els.d_id);
411 zfcp_dbf_out(&p, "ls_code", "0x%02x", r->data.send_els.ls_code);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200412 break;
413
414 case FSF_QTCB_ABORT_FCP_CMND:
415 case FSF_QTCB_SEND_GENERIC:
416 case FSF_QTCB_EXCHANGE_CONFIG_DATA:
417 case FSF_QTCB_EXCHANGE_PORT_DATA:
418 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
419 case FSF_QTCB_UPLOAD_CONTROL_FILE:
420 break;
421 }
Martin Peschkeb634fff2008-03-31 11:15:24 +0200422 return p - buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200423}
424
Martin Peschkeb634fff2008-03-31 11:15:24 +0200425static int zfcp_hba_dbf_view_status(char *buf,
426 struct zfcp_hba_dbf_record_status *r)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200427{
Martin Peschkeb634fff2008-03-31 11:15:24 +0200428 char *p = buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200429
Martin Peschkeb634fff2008-03-31 11:15:24 +0200430 zfcp_dbf_out(&p, "failed", "0x%02x", r->failed);
431 zfcp_dbf_out(&p, "status_type", "0x%08x", r->status_type);
432 zfcp_dbf_out(&p, "status_subtype", "0x%08x", r->status_subtype);
433 p += zfcp_dbf_view_dump(p, "queue_designator",
434 (char *)&r->queue_designator,
435 sizeof(struct fsf_queue_designator),
436 0, sizeof(struct fsf_queue_designator));
437 p += zfcp_dbf_view_dump(p, "payload", (char *)&r->payload,
438 r->payload_size, 0, r->payload_size);
439 return p - buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200440}
441
Martin Peschkeb634fff2008-03-31 11:15:24 +0200442static int zfcp_hba_dbf_view_qdio(char *buf, struct zfcp_hba_dbf_record_qdio *r)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200443{
Martin Peschkeb634fff2008-03-31 11:15:24 +0200444 char *p = buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200445
Martin Peschkeb634fff2008-03-31 11:15:24 +0200446 zfcp_dbf_out(&p, "status", "0x%08x", r->status);
447 zfcp_dbf_out(&p, "qdio_error", "0x%08x", r->qdio_error);
448 zfcp_dbf_out(&p, "siga_error", "0x%08x", r->siga_error);
449 zfcp_dbf_out(&p, "sbal_index", "0x%02x", r->sbal_index);
450 zfcp_dbf_out(&p, "sbal_count", "0x%02x", r->sbal_count);
451 return p - buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200452}
453
454static int
455zfcp_hba_dbf_view_format(debug_info_t * id, struct debug_view *view,
456 char *out_buf, const char *in_buf)
457{
458 struct zfcp_hba_dbf_record *rec = (struct zfcp_hba_dbf_record *)in_buf;
459 int len = 0;
460
461 if (strncmp(rec->tag, "dump", ZFCP_DBF_TAG_SIZE) == 0)
462 return 0;
463
464 len += zfcp_dbf_tag(out_buf + len, "tag", rec->tag);
465 if (isalpha(rec->tag2[0]))
466 len += zfcp_dbf_tag(out_buf + len, "tag2", rec->tag2);
467 if (strncmp(rec->tag, "resp", ZFCP_DBF_TAG_SIZE) == 0)
468 len += zfcp_hba_dbf_view_response(out_buf + len,
469 &rec->type.response);
470 else if (strncmp(rec->tag, "stat", ZFCP_DBF_TAG_SIZE) == 0)
471 len += zfcp_hba_dbf_view_status(out_buf + len,
472 &rec->type.status);
473 else if (strncmp(rec->tag, "qdio", ZFCP_DBF_TAG_SIZE) == 0)
474 len += zfcp_hba_dbf_view_qdio(out_buf + len, &rec->type.qdio);
475
476 len += sprintf(out_buf + len, "\n");
477
478 return len;
479}
480
Heiko Carstens2b67fc42007-02-05 21:16:47 +0100481static struct debug_view zfcp_hba_dbf_view = {
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200482 "structured",
483 NULL,
484 &zfcp_dbf_view_header,
485 &zfcp_hba_dbf_view_format,
486 NULL,
487 NULL
488};
489
Martin Peschked79a83d2008-03-27 14:22:00 +0100490static const char *zfcp_rec_dbf_tags[] = {
Martin Peschke348447e2008-03-27 14:22:01 +0100491 [ZFCP_REC_DBF_ID_THREAD] = "thread",
Martin Peschke698ec0162008-03-27 14:22:02 +0100492 [ZFCP_REC_DBF_ID_TARGET] = "target",
Martin Peschke9467a9b2008-03-27 14:22:03 +0100493 [ZFCP_REC_DBF_ID_TRIGGER] = "trigger",
Martin Peschke6f4f3652008-03-27 14:22:04 +0100494 [ZFCP_REC_DBF_ID_ACTION] = "action",
Martin Peschked79a83d2008-03-27 14:22:00 +0100495};
496
497static const char *zfcp_rec_dbf_ids[] = {
Martin Peschke348447e2008-03-27 14:22:01 +0100498 [1] = "new",
499 [2] = "ready",
500 [3] = "kill",
501 [4] = "down sleep",
502 [5] = "down wakeup",
503 [6] = "down sleep ecd",
504 [7] = "down wakeup ecd",
505 [8] = "down sleep epd",
506 [9] = "down wakeup epd",
Martin Peschke698ec0162008-03-27 14:22:02 +0100507 [10] = "online",
508 [11] = "operational",
509 [12] = "scsi slave destroy",
510 [13] = "propagate failed adapter",
511 [14] = "propagate failed port",
512 [15] = "block adapter",
513 [16] = "unblock adapter",
514 [17] = "block port",
515 [18] = "unblock port",
516 [19] = "block unit",
517 [20] = "unblock unit",
518 [21] = "unit recovery failed",
519 [22] = "port recovery failed",
520 [23] = "adapter recovery failed",
521 [24] = "qdio queues down",
522 [25] = "p2p failed",
523 [26] = "nameserver lookup failed",
524 [27] = "nameserver port failed",
525 [28] = "link up",
526 [29] = "link down",
527 [30] = "link up status read",
528 [31] = "open port failed",
529 [32] = "open port failed",
530 [33] = "close port",
531 [34] = "open unit failed",
532 [35] = "exclusive open unit failed",
533 [36] = "shared open unit failed",
534 [37] = "link down",
535 [38] = "link down status read no link",
536 [39] = "link down status read fdisc login",
537 [40] = "link down status read firmware update",
538 [41] = "link down status read unknown reason",
539 [42] = "link down ecd incomplete",
540 [43] = "link down epd incomplete",
541 [44] = "sysfs adapter recovery",
542 [45] = "sysfs port recovery",
543 [46] = "sysfs unit recovery",
544 [47] = "port boxed abort",
545 [48] = "unit boxed abort",
546 [49] = "port boxed ct",
547 [50] = "port boxed close physical",
548 [51] = "port boxed open unit",
549 [52] = "port boxed close unit",
550 [53] = "port boxed fcp",
551 [54] = "unit boxed fcp",
552 [55] = "port access denied ct",
553 [56] = "port access denied els",
554 [57] = "port access denied open port",
555 [58] = "port access denied close physical",
556 [59] = "unit access denied open unit",
557 [60] = "shared unit access denied open unit",
558 [61] = "unit access denied fcp",
Martin Peschke9467a9b2008-03-27 14:22:03 +0100559 [62] = "request timeout",
560 [63] = "adisc link test reject or timeout",
561 [64] = "adisc link test d_id changed",
562 [65] = "adisc link test failed",
563 [66] = "recovery out of memory",
564 [67] = "adapter recovery repeated after state change",
565 [68] = "port recovery repeated after state change",
566 [69] = "unit recovery repeated after state change",
567 [70] = "port recovery follow-up after successful adapter recovery",
568 [71] = "adapter recovery escalation after failed adapter recovery",
569 [72] = "port recovery follow-up after successful physical port "
570 "recovery",
571 [73] = "adapter recovery escalation after failed physical port "
572 "recovery",
573 [74] = "unit recovery follow-up after successful port recovery",
574 [75] = "physical port recovery escalation after failed port "
575 "recovery",
576 [76] = "port recovery escalation after failed unit recovery",
577 [77] = "recovery opening nameserver port",
578 [78] = "duplicate request id",
579 [79] = "link down",
580 [80] = "exclusive read-only unit access unsupported",
581 [81] = "shared read-write unit access unsupported",
582 [82] = "incoming rscn",
583 [83] = "incoming plogi",
584 [84] = "incoming logo",
585 [85] = "online",
586 [86] = "offline",
587 [87] = "ccw device gone",
588 [88] = "ccw device no path",
589 [89] = "ccw device operational",
590 [90] = "ccw device shutdown",
591 [91] = "sysfs port addition",
592 [92] = "sysfs port removal",
593 [93] = "sysfs adapter recovery",
594 [94] = "sysfs unit addition",
595 [95] = "sysfs unit removal",
596 [96] = "sysfs port recovery",
597 [97] = "sysfs unit recovery",
598 [98] = "sequence number mismatch",
599 [99] = "link up",
600 [100] = "error state",
601 [101] = "status read physical port closed",
602 [102] = "link up status read",
603 [103] = "too many failed status read buffers",
604 [104] = "port handle not valid abort",
605 [105] = "lun handle not valid abort",
606 [106] = "port handle not valid ct",
607 [107] = "port handle not valid close port",
608 [108] = "port handle not valid close physical port",
609 [109] = "port handle not valid open unit",
610 [110] = "port handle not valid close unit",
611 [111] = "lun handle not valid close unit",
612 [112] = "port handle not valid fcp",
613 [113] = "lun handle not valid fcp",
614 [114] = "handle mismatch fcp",
615 [115] = "lun not valid fcp",
616 [116] = "qdio send failed",
617 [117] = "version mismatch",
618 [118] = "incompatible qtcb type",
619 [119] = "unknown protocol status",
620 [120] = "unknown fsf command",
621 [121] = "no recommendation for status qualifier",
622 [122] = "status read physical port closed in error",
623 [123] = "fc service class not supported ct",
624 [124] = "fc service class not supported els",
625 [125] = "need newer zfcp",
626 [126] = "need newer microcode",
627 [127] = "arbitrated loop not supported",
628 [128] = "unknown topology",
629 [129] = "qtcb size mismatch",
630 [130] = "unknown fsf status ecd",
631 [131] = "fcp request too big",
632 [132] = "fc service class not supported fcp",
633 [133] = "data direction not valid fcp",
634 [134] = "command length not valid fcp",
635 [135] = "status read act update",
636 [136] = "status read cfdc update",
637 [137] = "hbaapi port open",
638 [138] = "hbaapi unit open",
639 [139] = "hbaapi unit shutdown",
640 [140] = "qdio error",
641 [141] = "scsi host reset",
Martin Peschke6f4f3652008-03-27 14:22:04 +0100642 [142] = "dismissing fsf request for recovery action",
643 [143] = "recovery action timed out",
644 [144] = "recovery action gone",
645 [145] = "recovery action being processed",
646 [146] = "recovery action ready for next step",
Martin Peschked79a83d2008-03-27 14:22:00 +0100647};
648
649static int zfcp_rec_dbf_view_format(debug_info_t *id, struct debug_view *view,
650 char *buf, const char *_rec)
651{
652 struct zfcp_rec_dbf_record *r = (struct zfcp_rec_dbf_record *)_rec;
653 char *p = buf;
654
655 zfcp_dbf_outs(&p, "tag", zfcp_rec_dbf_tags[r->id]);
656 zfcp_dbf_outs(&p, "hint", zfcp_rec_dbf_ids[r->id2]);
657 zfcp_dbf_out(&p, "id", "%d", r->id2);
658 switch (r->id) {
Martin Peschke348447e2008-03-27 14:22:01 +0100659 case ZFCP_REC_DBF_ID_THREAD:
660 zfcp_dbf_out(&p, "sema", "%d", r->u.thread.sema);
661 zfcp_dbf_out(&p, "total", "%d", r->u.thread.total);
662 zfcp_dbf_out(&p, "ready", "%d", r->u.thread.ready);
663 zfcp_dbf_out(&p, "running", "%d", r->u.thread.running);
664 break;
Martin Peschke698ec0162008-03-27 14:22:02 +0100665 case ZFCP_REC_DBF_ID_TARGET:
666 zfcp_dbf_out(&p, "reference", "0x%016Lx", r->u.target.ref);
667 zfcp_dbf_out(&p, "status", "0x%08x", r->u.target.status);
668 zfcp_dbf_out(&p, "erp_count", "%d", r->u.target.erp_count);
669 zfcp_dbf_out(&p, "d_id", "0x%06x", r->u.target.d_id);
670 zfcp_dbf_out(&p, "wwpn", "0x%016Lx", r->u.target.wwpn);
671 zfcp_dbf_out(&p, "fcp_lun", "0x%016Lx", r->u.target.fcp_lun);
672 break;
Martin Peschke9467a9b2008-03-27 14:22:03 +0100673 case ZFCP_REC_DBF_ID_TRIGGER:
674 zfcp_dbf_out(&p, "reference", "0x%016Lx", r->u.trigger.ref);
675 zfcp_dbf_out(&p, "erp_action", "0x%016Lx", r->u.trigger.action);
676 zfcp_dbf_out(&p, "requested", "%d", r->u.trigger.want);
677 zfcp_dbf_out(&p, "executed", "%d", r->u.trigger.need);
678 zfcp_dbf_out(&p, "wwpn", "0x%016Lx", r->u.trigger.wwpn);
679 zfcp_dbf_out(&p, "fcp_lun", "0x%016Lx", r->u.trigger.fcp_lun);
680 zfcp_dbf_out(&p, "adapter_status", "0x%08x", r->u.trigger.as);
681 zfcp_dbf_out(&p, "port_status", "0x%08x", r->u.trigger.ps);
682 zfcp_dbf_out(&p, "unit_status", "0x%08x", r->u.trigger.us);
683 break;
Martin Peschke6f4f3652008-03-27 14:22:04 +0100684 case ZFCP_REC_DBF_ID_ACTION:
685 zfcp_dbf_out(&p, "erp_action", "0x%016Lx", r->u.action.action);
686 zfcp_dbf_out(&p, "fsf_req", "0x%016Lx", r->u.action.fsf_req);
687 zfcp_dbf_out(&p, "status", "0x%08Lx", r->u.action.status);
688 zfcp_dbf_out(&p, "step", "0x%08Lx", r->u.action.step);
689 break;
Martin Peschked79a83d2008-03-27 14:22:00 +0100690 }
Martin Peschkeb634fff2008-03-31 11:15:24 +0200691 p += sprintf(p, "\n");
692 return p - buf;
Martin Peschked79a83d2008-03-27 14:22:00 +0100693}
694
695static struct debug_view zfcp_rec_dbf_view = {
696 "structured",
697 NULL,
698 &zfcp_dbf_view_header,
699 &zfcp_rec_dbf_view_format,
700 NULL,
701 NULL
702};
703
Martin Peschke348447e2008-03-27 14:22:01 +0100704/**
705 * zfcp_rec_dbf_event_thread - trace event related to recovery thread operation
706 * @id2: identifier for event
707 * @adapter: adapter
708 * @lock: non-zero value indicates that erp_lock has not yet been acquired
709 */
710void zfcp_rec_dbf_event_thread(u8 id2, struct zfcp_adapter *adapter, int lock)
711{
712 struct zfcp_rec_dbf_record *r = &adapter->rec_dbf_buf;
713 unsigned long flags = 0;
714 struct list_head *entry;
715 unsigned ready = 0, running = 0, total;
716
717 if (lock)
718 read_lock_irqsave(&adapter->erp_lock, flags);
719 list_for_each(entry, &adapter->erp_ready_head)
720 ready++;
721 list_for_each(entry, &adapter->erp_running_head)
722 running++;
723 total = adapter->erp_total_count;
724 if (lock)
725 read_unlock_irqrestore(&adapter->erp_lock, flags);
726
727 spin_lock_irqsave(&adapter->rec_dbf_lock, flags);
728 memset(r, 0, sizeof(*r));
729 r->id = ZFCP_REC_DBF_ID_THREAD;
730 r->id2 = id2;
731 r->u.thread.sema = atomic_read(&adapter->erp_ready_sem.count);
732 r->u.thread.total = total;
733 r->u.thread.ready = ready;
734 r->u.thread.running = running;
735 debug_event(adapter->rec_dbf, 5, r, sizeof(*r));
736 spin_unlock_irqrestore(&adapter->rec_dbf_lock, flags);
737}
738
Martin Peschke698ec0162008-03-27 14:22:02 +0100739static void zfcp_rec_dbf_event_target(u8 id2, u64 ref,
740 struct zfcp_adapter *adapter,
741 atomic_t *status, atomic_t *erp_count,
742 u64 wwpn, u32 d_id, u64 fcp_lun)
743{
744 struct zfcp_rec_dbf_record *r = &adapter->rec_dbf_buf;
745 unsigned long flags;
746
747 spin_lock_irqsave(&adapter->rec_dbf_lock, flags);
748 memset(r, 0, sizeof(*r));
749 r->id = ZFCP_REC_DBF_ID_TARGET;
750 r->id2 = id2;
751 r->u.target.ref = ref;
752 r->u.target.status = atomic_read(status);
753 r->u.target.wwpn = wwpn;
754 r->u.target.d_id = d_id;
755 r->u.target.fcp_lun = fcp_lun;
756 r->u.target.erp_count = atomic_read(erp_count);
757 debug_event(adapter->rec_dbf, 3, r, sizeof(*r));
758 spin_unlock_irqrestore(&adapter->rec_dbf_lock, flags);
759}
760
761/**
762 * zfcp_rec_dbf_event_adapter - trace event for adapter state change
763 * @id: identifier for trigger of state change
764 * @ref: additional reference (e.g. request)
765 * @adapter: adapter
766 */
767void zfcp_rec_dbf_event_adapter(u8 id, u64 ref, struct zfcp_adapter *adapter)
768{
769 zfcp_rec_dbf_event_target(id, ref, adapter, &adapter->status,
770 &adapter->erp_counter, 0, 0, 0);
771}
772
773/**
774 * zfcp_rec_dbf_event_port - trace event for port state change
775 * @id: identifier for trigger of state change
776 * @ref: additional reference (e.g. request)
777 * @port: port
778 */
779void zfcp_rec_dbf_event_port(u8 id, u64 ref, struct zfcp_port *port)
780{
781 struct zfcp_adapter *adapter = port->adapter;
782
783 zfcp_rec_dbf_event_target(id, ref, adapter, &port->status,
784 &port->erp_counter, port->wwpn, port->d_id,
785 0);
786}
787
788/**
789 * zfcp_rec_dbf_event_unit - trace event for unit state change
790 * @id: identifier for trigger of state change
791 * @ref: additional reference (e.g. request)
792 * @unit: unit
793 */
794void zfcp_rec_dbf_event_unit(u8 id, u64 ref, struct zfcp_unit *unit)
795{
796 struct zfcp_port *port = unit->port;
797 struct zfcp_adapter *adapter = port->adapter;
798
799 zfcp_rec_dbf_event_target(id, ref, adapter, &unit->status,
800 &unit->erp_counter, port->wwpn, port->d_id,
801 unit->fcp_lun);
802}
803
Martin Peschke9467a9b2008-03-27 14:22:03 +0100804/**
805 * zfcp_rec_dbf_event_trigger - trace event for triggered error recovery
806 * @id2: identifier for error recovery trigger
807 * @ref: additional reference (e.g. request)
808 * @want: originally requested error recovery action
809 * @need: error recovery action actually initiated
810 * @action: address of error recovery action struct
811 * @adapter: adapter
812 * @port: port
813 * @unit: unit
814 */
815void zfcp_rec_dbf_event_trigger(u8 id2, u64 ref, u8 want, u8 need, u64 action,
816 struct zfcp_adapter *adapter,
817 struct zfcp_port *port, struct zfcp_unit *unit)
818{
819 struct zfcp_rec_dbf_record *r = &adapter->rec_dbf_buf;
820 unsigned long flags;
821
822 spin_lock_irqsave(&adapter->rec_dbf_lock, flags);
823 memset(r, 0, sizeof(*r));
824 r->id = ZFCP_REC_DBF_ID_TRIGGER;
825 r->id2 = id2;
826 r->u.trigger.ref = ref;
827 r->u.trigger.want = want;
828 r->u.trigger.need = need;
829 r->u.trigger.action = action;
830 r->u.trigger.as = atomic_read(&adapter->status);
831 if (port) {
832 r->u.trigger.ps = atomic_read(&port->status);
833 r->u.trigger.wwpn = port->wwpn;
834 }
835 if (unit) {
836 r->u.trigger.us = atomic_read(&unit->status);
837 r->u.trigger.fcp_lun = unit->fcp_lun;
838 }
839 debug_event(adapter->rec_dbf, action ? 1 : 4, r, sizeof(*r));
840 spin_unlock_irqrestore(&adapter->rec_dbf_lock, flags);
841}
842
Martin Peschke6f4f3652008-03-27 14:22:04 +0100843/**
844 * zfcp_rec_dbf_event_action - trace event showing progress of recovery action
845 * @id2: identifier
846 * @erp_action: error recovery action struct pointer
847 */
848void zfcp_rec_dbf_event_action(u8 id2, struct zfcp_erp_action *erp_action)
849{
850 struct zfcp_adapter *adapter = erp_action->adapter;
851 struct zfcp_rec_dbf_record *r = &adapter->rec_dbf_buf;
852 unsigned long flags;
853
854 spin_lock_irqsave(&adapter->rec_dbf_lock, flags);
855 memset(r, 0, sizeof(*r));
856 r->id = ZFCP_REC_DBF_ID_ACTION;
857 r->id2 = id2;
858 r->u.action.action = (u64)erp_action;
859 r->u.action.status = erp_action->status;
860 r->u.action.step = erp_action->step;
861 r->u.action.fsf_req = (u64)erp_action->fsf_req;
862 debug_event(adapter->rec_dbf, 4, r, sizeof(*r));
863 spin_unlock_irqrestore(&adapter->rec_dbf_lock, flags);
864}
865
Heiko Carstens763968e2007-05-10 15:45:46 +0200866static void
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200867_zfcp_san_dbf_event_common_ct(const char *tag, struct zfcp_fsf_req *fsf_req,
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200868 u32 s_id, u32 d_id, void *buffer, int buflen)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200869{
870 struct zfcp_send_ct *send_ct = (struct zfcp_send_ct *)fsf_req->data;
871 struct zfcp_port *port = send_ct->port;
872 struct zfcp_adapter *adapter = port->adapter;
873 struct ct_hdr *header = (struct ct_hdr *)buffer;
874 struct zfcp_san_dbf_record *rec = &adapter->san_dbf_buf;
875 struct zfcp_san_dbf_record_ct *ct = &rec->type.ct;
876 unsigned long flags;
877
878 spin_lock_irqsave(&adapter->san_dbf_lock, flags);
879 memset(rec, 0, sizeof(struct zfcp_san_dbf_record));
880 strncpy(rec->tag, tag, ZFCP_DBF_TAG_SIZE);
881 rec->fsf_reqid = (unsigned long)fsf_req;
882 rec->fsf_seqno = fsf_req->seq_no;
883 rec->s_id = s_id;
884 rec->d_id = d_id;
885 if (strncmp(tag, "octc", ZFCP_DBF_TAG_SIZE) == 0) {
886 ct->type.request.cmd_req_code = header->cmd_rsp_code;
887 ct->type.request.revision = header->revision;
888 ct->type.request.gs_type = header->gs_type;
889 ct->type.request.gs_subtype = header->gs_subtype;
890 ct->type.request.options = header->options;
891 ct->type.request.max_res_size = header->max_res_size;
892 } else if (strncmp(tag, "rctc", ZFCP_DBF_TAG_SIZE) == 0) {
893 ct->type.response.cmd_rsp_code = header->cmd_rsp_code;
894 ct->type.response.revision = header->revision;
895 ct->type.response.reason_code = header->reason_code;
896 ct->type.response.reason_code_expl = header->reason_code_expl;
897 ct->type.response.vendor_unique = header->vendor_unique;
898 }
899 ct->payload_size =
900 min(buflen - (int)sizeof(struct ct_hdr), ZFCP_DBF_CT_PAYLOAD);
901 memcpy(ct->payload, buffer + sizeof(struct ct_hdr), ct->payload_size);
902 debug_event(adapter->san_dbf, 3,
903 rec, sizeof(struct zfcp_san_dbf_record));
904 spin_unlock_irqrestore(&adapter->san_dbf_lock, flags);
905}
906
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100907void zfcp_san_dbf_event_ct_request(struct zfcp_fsf_req *fsf_req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200908{
909 struct zfcp_send_ct *ct = (struct zfcp_send_ct *)fsf_req->data;
910 struct zfcp_port *port = ct->port;
911 struct zfcp_adapter *adapter = port->adapter;
912
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200913 _zfcp_san_dbf_event_common_ct("octc", fsf_req,
914 fc_host_port_id(adapter->scsi_host),
915 port->d_id, zfcp_sg_to_address(ct->req),
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200916 ct->req->length);
917}
918
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100919void zfcp_san_dbf_event_ct_response(struct zfcp_fsf_req *fsf_req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200920{
921 struct zfcp_send_ct *ct = (struct zfcp_send_ct *)fsf_req->data;
922 struct zfcp_port *port = ct->port;
923 struct zfcp_adapter *adapter = port->adapter;
924
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200925 _zfcp_san_dbf_event_common_ct("rctc", fsf_req, port->d_id,
926 fc_host_port_id(adapter->scsi_host),
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200927 zfcp_sg_to_address(ct->resp),
928 ct->resp->length);
929}
930
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100931static void
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200932_zfcp_san_dbf_event_common_els(const char *tag, int level,
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200933 struct zfcp_fsf_req *fsf_req, u32 s_id,
934 u32 d_id, u8 ls_code, void *buffer, int buflen)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200935{
936 struct zfcp_adapter *adapter = fsf_req->adapter;
937 struct zfcp_san_dbf_record *rec = &adapter->san_dbf_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200938 unsigned long flags;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200939
940 spin_lock_irqsave(&adapter->san_dbf_lock, flags);
Martin Peschke0f65e952008-03-27 14:21:56 +0100941 memset(rec, 0, sizeof(struct zfcp_san_dbf_record));
942 strncpy(rec->tag, tag, ZFCP_DBF_TAG_SIZE);
943 rec->fsf_reqid = (unsigned long)fsf_req;
944 rec->fsf_seqno = fsf_req->seq_no;
945 rec->s_id = s_id;
946 rec->d_id = d_id;
947 rec->type.els.ls_code = ls_code;
948 debug_event(adapter->san_dbf, level, rec, sizeof(*rec));
949 zfcp_dbf_hexdump(adapter->san_dbf, rec, sizeof(*rec), level,
950 buffer, min(buflen, ZFCP_DBF_ELS_MAX_PAYLOAD));
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200951 spin_unlock_irqrestore(&adapter->san_dbf_lock, flags);
952}
953
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100954void zfcp_san_dbf_event_els_request(struct zfcp_fsf_req *fsf_req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200955{
956 struct zfcp_send_els *els = (struct zfcp_send_els *)fsf_req->data;
957
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200958 _zfcp_san_dbf_event_common_els("oels", 2, fsf_req,
959 fc_host_port_id(els->adapter->scsi_host),
960 els->d_id,
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200961 *(u8 *) zfcp_sg_to_address(els->req),
962 zfcp_sg_to_address(els->req),
963 els->req->length);
964}
965
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100966void zfcp_san_dbf_event_els_response(struct zfcp_fsf_req *fsf_req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200967{
968 struct zfcp_send_els *els = (struct zfcp_send_els *)fsf_req->data;
969
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200970 _zfcp_san_dbf_event_common_els("rels", 2, fsf_req, els->d_id,
971 fc_host_port_id(els->adapter->scsi_host),
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200972 *(u8 *) zfcp_sg_to_address(els->req),
973 zfcp_sg_to_address(els->resp),
974 els->resp->length);
975}
976
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100977void zfcp_san_dbf_event_incoming_els(struct zfcp_fsf_req *fsf_req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200978{
979 struct zfcp_adapter *adapter = fsf_req->adapter;
980 struct fsf_status_read_buffer *status_buffer =
981 (struct fsf_status_read_buffer *)fsf_req->data;
982 int length = (int)status_buffer->length -
983 (int)((void *)&status_buffer->payload - (void *)status_buffer);
984
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200985 _zfcp_san_dbf_event_common_els("iels", 1, fsf_req, status_buffer->d_id,
986 fc_host_port_id(adapter->scsi_host),
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200987 *(u8 *) status_buffer->payload,
988 (void *)status_buffer->payload, length);
989}
990
991static int
992zfcp_san_dbf_view_format(debug_info_t * id, struct debug_view *view,
993 char *out_buf, const char *in_buf)
994{
Martin Peschkeb634fff2008-03-31 11:15:24 +0200995 struct zfcp_san_dbf_record *r = (struct zfcp_san_dbf_record *)in_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200996 char *buffer = NULL;
997 int buflen = 0, total = 0;
Martin Peschkeb634fff2008-03-31 11:15:24 +0200998 char *p = out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200999
Martin Peschkeb634fff2008-03-31 11:15:24 +02001000 if (strncmp(r->tag, "dump", ZFCP_DBF_TAG_SIZE) == 0)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001001 return 0;
1002
Martin Peschkeb634fff2008-03-31 11:15:24 +02001003 p += zfcp_dbf_tag(p, "tag", r->tag);
1004 zfcp_dbf_out(&p, "fsf_reqid", "0x%0Lx", r->fsf_reqid);
1005 zfcp_dbf_out(&p, "fsf_seqno", "0x%08x", r->fsf_seqno);
1006 zfcp_dbf_out(&p, "s_id", "0x%06x", r->s_id);
1007 zfcp_dbf_out(&p, "d_id", "0x%06x", r->d_id);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001008
Martin Peschkeb634fff2008-03-31 11:15:24 +02001009 if (strncmp(r->tag, "octc", ZFCP_DBF_TAG_SIZE) == 0) {
1010 /* FIXME: struct zfcp_dbf_ct_req *ct = ...; */
1011 zfcp_dbf_out(&p, "cmd_req_code", "0x%04x",
1012 r->type.ct.type.request.cmd_req_code);
1013 zfcp_dbf_out(&p, "revision", "0x%02x",
1014 r->type.ct.type.request.revision);
1015 zfcp_dbf_out(&p, "gs_type", "0x%02x",
1016 r->type.ct.type.request.gs_type);
1017 zfcp_dbf_out(&p, "gs_subtype", "0x%02x",
1018 r->type.ct.type.request.gs_subtype);
1019 zfcp_dbf_out(&p, "options", "0x%02x",
1020 r->type.ct.type.request.options);
1021 zfcp_dbf_out(&p, "max_res_size", "0x%04x",
1022 r->type.ct.type.request.max_res_size);
1023 total = r->type.ct.payload_size;
1024 buffer = r->type.ct.payload;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001025 buflen = min(total, ZFCP_DBF_CT_PAYLOAD);
Martin Peschkeb634fff2008-03-31 11:15:24 +02001026 } else if (strncmp(r->tag, "rctc", ZFCP_DBF_TAG_SIZE) == 0) {
1027 zfcp_dbf_out(&p, "cmd_rsp_code", "0x%04x",
1028 r->type.ct.type.response.cmd_rsp_code);
1029 zfcp_dbf_out(&p, "revision", "0x%02x",
1030 r->type.ct.type.response.revision);
1031 zfcp_dbf_out(&p, "reason_code", "0x%02x",
1032 r->type.ct.type.response.reason_code);
1033 zfcp_dbf_out(&p, "reason_code_expl", "0x%02x",
1034 r->type.ct.type.response.reason_code_expl);
1035 zfcp_dbf_out(&p, "vendor_unique", "0x%02x",
1036 r->type.ct.type.response.vendor_unique);
1037 total = r->type.ct.payload_size;
1038 buffer = r->type.ct.payload;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001039 buflen = min(total, ZFCP_DBF_CT_PAYLOAD);
Martin Peschkeb634fff2008-03-31 11:15:24 +02001040 } else if (strncmp(r->tag, "oels", ZFCP_DBF_TAG_SIZE) == 0 ||
1041 strncmp(r->tag, "rels", ZFCP_DBF_TAG_SIZE) == 0 ||
1042 strncmp(r->tag, "iels", ZFCP_DBF_TAG_SIZE) == 0) {
1043 zfcp_dbf_out(&p, "ls_code", "0x%02x", r->type.els.ls_code);
1044 total = r->type.els.payload_size;
1045 buffer = r->type.els.payload;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001046 buflen = min(total, ZFCP_DBF_ELS_PAYLOAD);
1047 }
1048
Martin Peschkeb634fff2008-03-31 11:15:24 +02001049 p += zfcp_dbf_view_dump(p, "payload", buffer, buflen, 0, total);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001050 if (buflen == total)
Martin Peschkeb634fff2008-03-31 11:15:24 +02001051 p += sprintf(p, "\n");
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001052
Martin Peschkeb634fff2008-03-31 11:15:24 +02001053 return p - out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001054}
1055
Heiko Carstens2b67fc42007-02-05 21:16:47 +01001056static struct debug_view zfcp_san_dbf_view = {
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001057 "structured",
1058 NULL,
1059 &zfcp_dbf_view_header,
1060 &zfcp_san_dbf_view_format,
1061 NULL,
1062 NULL
1063};
1064
Heiko Carstens4d284ca2007-02-05 21:18:53 +01001065static void
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001066_zfcp_scsi_dbf_event_common(const char *tag, const char *tag2, int level,
1067 struct zfcp_adapter *adapter,
1068 struct scsi_cmnd *scsi_cmnd,
Maxim Shchetynined829ad2006-02-11 01:42:58 +01001069 struct zfcp_fsf_req *fsf_req,
Andreas Herrmann4eff4a32006-09-18 22:29:20 +02001070 unsigned long old_req_id)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001071{
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001072 struct zfcp_scsi_dbf_record *rec = &adapter->scsi_dbf_buf;
1073 struct zfcp_dbf_dump *dump = (struct zfcp_dbf_dump *)rec;
1074 unsigned long flags;
1075 struct fcp_rsp_iu *fcp_rsp;
1076 char *fcp_rsp_info = NULL, *fcp_sns_info = NULL;
1077 int offset = 0, buflen = 0;
1078
1079 spin_lock_irqsave(&adapter->scsi_dbf_lock, flags);
1080 do {
1081 memset(rec, 0, sizeof(struct zfcp_scsi_dbf_record));
1082 if (offset == 0) {
1083 strncpy(rec->tag, tag, ZFCP_DBF_TAG_SIZE);
1084 strncpy(rec->tag2, tag2, ZFCP_DBF_TAG_SIZE);
Maxim Shchetynined829ad2006-02-11 01:42:58 +01001085 if (scsi_cmnd != NULL) {
1086 if (scsi_cmnd->device) {
1087 rec->scsi_id = scsi_cmnd->device->id;
1088 rec->scsi_lun = scsi_cmnd->device->lun;
1089 }
1090 rec->scsi_result = scsi_cmnd->result;
1091 rec->scsi_cmnd = (unsigned long)scsi_cmnd;
1092 rec->scsi_serial = scsi_cmnd->serial_number;
1093 memcpy(rec->scsi_opcode, &scsi_cmnd->cmnd,
1094 min((int)scsi_cmnd->cmd_len,
1095 ZFCP_DBF_SCSI_OPCODE));
1096 rec->scsi_retries = scsi_cmnd->retries;
1097 rec->scsi_allowed = scsi_cmnd->allowed;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001098 }
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001099 if (fsf_req != NULL) {
1100 fcp_rsp = (struct fcp_rsp_iu *)
1101 &(fsf_req->qtcb->bottom.io.fcp_rsp);
1102 fcp_rsp_info =
1103 zfcp_get_fcp_rsp_info_ptr(fcp_rsp);
1104 fcp_sns_info =
1105 zfcp_get_fcp_sns_info_ptr(fcp_rsp);
1106
1107 rec->type.fcp.rsp_validity =
1108 fcp_rsp->validity.value;
1109 rec->type.fcp.rsp_scsi_status =
1110 fcp_rsp->scsi_status;
1111 rec->type.fcp.rsp_resid = fcp_rsp->fcp_resid;
1112 if (fcp_rsp->validity.bits.fcp_rsp_len_valid)
1113 rec->type.fcp.rsp_code =
1114 *(fcp_rsp_info + 3);
1115 if (fcp_rsp->validity.bits.fcp_sns_len_valid) {
1116 buflen = min((int)fcp_rsp->fcp_sns_len,
1117 ZFCP_DBF_SCSI_MAX_FCP_SNS_INFO);
1118 rec->type.fcp.sns_info_len = buflen;
1119 memcpy(rec->type.fcp.sns_info,
1120 fcp_sns_info,
1121 min(buflen,
1122 ZFCP_DBF_SCSI_FCP_SNS_INFO));
1123 offset += min(buflen,
1124 ZFCP_DBF_SCSI_FCP_SNS_INFO);
1125 }
1126
1127 rec->fsf_reqid = (unsigned long)fsf_req;
1128 rec->fsf_seqno = fsf_req->seq_no;
1129 rec->fsf_issued = fsf_req->issued;
1130 }
Andreas Herrmann4eff4a32006-09-18 22:29:20 +02001131 rec->type.old_fsf_reqid = old_req_id;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001132 } else {
1133 strncpy(dump->tag, "dump", ZFCP_DBF_TAG_SIZE);
1134 dump->total_size = buflen;
1135 dump->offset = offset;
1136 dump->size = min(buflen - offset,
1137 (int)sizeof(struct
1138 zfcp_scsi_dbf_record) -
1139 (int)sizeof(struct zfcp_dbf_dump));
1140 memcpy(dump->data, fcp_sns_info + offset, dump->size);
1141 offset += dump->size;
1142 }
1143 debug_event(adapter->scsi_dbf, level,
1144 rec, sizeof(struct zfcp_scsi_dbf_record));
1145 } while (offset < buflen);
1146 spin_unlock_irqrestore(&adapter->scsi_dbf_lock, flags);
1147}
1148
Heiko Carstens4d284ca2007-02-05 21:18:53 +01001149void
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001150zfcp_scsi_dbf_event_result(const char *tag, int level,
1151 struct zfcp_adapter *adapter,
Maxim Shchetynined829ad2006-02-11 01:42:58 +01001152 struct scsi_cmnd *scsi_cmnd,
1153 struct zfcp_fsf_req *fsf_req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001154{
Maxim Shchetynined829ad2006-02-11 01:42:58 +01001155 _zfcp_scsi_dbf_event_common("rslt", tag, level,
Andreas Herrmann4eff4a32006-09-18 22:29:20 +02001156 adapter, scsi_cmnd, fsf_req, 0);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001157}
1158
Heiko Carstens4d284ca2007-02-05 21:18:53 +01001159void
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001160zfcp_scsi_dbf_event_abort(const char *tag, struct zfcp_adapter *adapter,
1161 struct scsi_cmnd *scsi_cmnd,
Maxim Shchetynined829ad2006-02-11 01:42:58 +01001162 struct zfcp_fsf_req *new_fsf_req,
Andreas Herrmann4eff4a32006-09-18 22:29:20 +02001163 unsigned long old_req_id)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001164{
Maxim Shchetynined829ad2006-02-11 01:42:58 +01001165 _zfcp_scsi_dbf_event_common("abrt", tag, 1,
Andreas Herrmann4eff4a32006-09-18 22:29:20 +02001166 adapter, scsi_cmnd, new_fsf_req, old_req_id);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001167}
1168
Heiko Carstens4d284ca2007-02-05 21:18:53 +01001169void
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001170zfcp_scsi_dbf_event_devreset(const char *tag, u8 flag, struct zfcp_unit *unit,
1171 struct scsi_cmnd *scsi_cmnd)
1172{
1173 struct zfcp_adapter *adapter = unit->port->adapter;
1174
1175 _zfcp_scsi_dbf_event_common(flag == FCP_TARGET_RESET ? "trst" : "lrst",
Andreas Herrmann4eff4a32006-09-18 22:29:20 +02001176 tag, 1, adapter, scsi_cmnd, NULL, 0);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001177}
1178
1179static int
1180zfcp_scsi_dbf_view_format(debug_info_t * id, struct debug_view *view,
1181 char *out_buf, const char *in_buf)
1182{
Martin Peschkeb634fff2008-03-31 11:15:24 +02001183 struct zfcp_scsi_dbf_record *r = (struct zfcp_scsi_dbf_record *)in_buf;
Martin Peschke8fc5af12008-03-31 11:15:23 +02001184 struct timespec t;
Martin Peschkeb634fff2008-03-31 11:15:24 +02001185 char *p = out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001186
Martin Peschkeb634fff2008-03-31 11:15:24 +02001187 if (strncmp(r->tag, "dump", ZFCP_DBF_TAG_SIZE) == 0)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001188 return 0;
1189
Martin Peschkeb634fff2008-03-31 11:15:24 +02001190 p += zfcp_dbf_tag(p, "tag", r->tag);
1191 p += zfcp_dbf_tag(p, "tag2", r->tag2);
1192 zfcp_dbf_out(&p, "scsi_id", "0x%08x", r->scsi_id);
1193 zfcp_dbf_out(&p, "scsi_lun", "0x%08x", r->scsi_lun);
1194 zfcp_dbf_out(&p, "scsi_result", "0x%08x", r->scsi_result);
1195 zfcp_dbf_out(&p, "scsi_cmnd", "0x%0Lx", r->scsi_cmnd);
1196 zfcp_dbf_out(&p, "scsi_serial", "0x%016Lx", r->scsi_serial);
1197 p += zfcp_dbf_view_dump(p, "scsi_opcode", r->scsi_opcode,
1198 ZFCP_DBF_SCSI_OPCODE, 0, ZFCP_DBF_SCSI_OPCODE);
1199 zfcp_dbf_out(&p, "scsi_retries", "0x%02x", r->scsi_retries);
1200 zfcp_dbf_out(&p, "scsi_allowed", "0x%02x", r->scsi_allowed);
1201 if (strncmp(r->tag, "abrt", ZFCP_DBF_TAG_SIZE) == 0)
1202 zfcp_dbf_out(&p, "old_fsf_reqid", "0x%0Lx",
1203 r->type.old_fsf_reqid);
1204 zfcp_dbf_out(&p, "fsf_reqid", "0x%0Lx", r->fsf_reqid);
1205 zfcp_dbf_out(&p, "fsf_seqno", "0x%08x", r->fsf_seqno);
1206 zfcp_dbf_timestamp(r->fsf_issued, &t);
1207 zfcp_dbf_out(&p, "fsf_issued", "%011lu:%06lu", t.tv_sec, t.tv_nsec);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001208
Martin Peschkeb634fff2008-03-31 11:15:24 +02001209 if (strncmp(r->tag, "rslt", ZFCP_DBF_TAG_SIZE) == 0) {
1210 zfcp_dbf_out(&p, "fcp_rsp_validity", "0x%02x",
1211 r->type.fcp.rsp_validity);
1212 zfcp_dbf_out(&p, "fcp_rsp_scsi_status",
1213 "0x%02x", r->type.fcp.rsp_scsi_status);
1214 zfcp_dbf_out(&p, "fcp_rsp_resid", "0x%08x",
1215 r->type.fcp.rsp_resid);
1216 zfcp_dbf_out(&p, "fcp_rsp_code", "0x%08x",
1217 r->type.fcp.rsp_code);
1218 zfcp_dbf_out(&p, "fcp_sns_info_len", "0x%08x",
1219 r->type.fcp.sns_info_len);
1220 p += zfcp_dbf_view_dump(p, "fcp_sns_info",
1221 r->type.fcp.sns_info,
1222 min((int)r->type.fcp.sns_info_len,
1223 ZFCP_DBF_SCSI_FCP_SNS_INFO), 0,
1224 r->type.fcp.sns_info_len);
1225 }
1226 p += sprintf(p, "\n");
1227 return p - out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001228}
1229
Heiko Carstens2b67fc42007-02-05 21:16:47 +01001230static struct debug_view zfcp_scsi_dbf_view = {
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001231 "structured",
1232 NULL,
1233 &zfcp_dbf_view_header,
1234 &zfcp_scsi_dbf_view_format,
1235 NULL,
1236 NULL
1237};
1238
1239/**
1240 * zfcp_adapter_debug_register - registers debug feature for an adapter
1241 * @adapter: pointer to adapter for which debug features should be registered
1242 * return: -ENOMEM on error, 0 otherwise
1243 */
1244int zfcp_adapter_debug_register(struct zfcp_adapter *adapter)
1245{
1246 char dbf_name[DEBUG_MAX_NAME_LEN];
1247
1248 /* debug feature area which records recovery activity */
Martin Peschked79a83d2008-03-27 14:22:00 +01001249 sprintf(dbf_name, "zfcp_%s_rec", zfcp_get_busid_by_adapter(adapter));
1250 adapter->rec_dbf = debug_register(dbf_name, dbfsize, 1,
1251 sizeof(struct zfcp_rec_dbf_record));
1252 if (!adapter->rec_dbf)
1253 goto failed;
1254 debug_register_view(adapter->rec_dbf, &debug_hex_ascii_view);
1255 debug_register_view(adapter->rec_dbf, &zfcp_rec_dbf_view);
1256 debug_set_level(adapter->rec_dbf, 3);
1257
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001258 /* debug feature area which records HBA (FSF and QDIO) conditions */
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001259 sprintf(dbf_name, "zfcp_%s_hba", zfcp_get_busid_by_adapter(adapter));
1260 adapter->hba_dbf = debug_register(dbf_name, dbfsize, 1,
1261 sizeof(struct zfcp_hba_dbf_record));
1262 if (!adapter->hba_dbf)
1263 goto failed;
1264 debug_register_view(adapter->hba_dbf, &debug_hex_ascii_view);
1265 debug_register_view(adapter->hba_dbf, &zfcp_hba_dbf_view);
1266 debug_set_level(adapter->hba_dbf, 3);
1267
1268 /* debug feature area which records SAN command failures and recovery */
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001269 sprintf(dbf_name, "zfcp_%s_san", zfcp_get_busid_by_adapter(adapter));
1270 adapter->san_dbf = debug_register(dbf_name, dbfsize, 1,
1271 sizeof(struct zfcp_san_dbf_record));
1272 if (!adapter->san_dbf)
1273 goto failed;
1274 debug_register_view(adapter->san_dbf, &debug_hex_ascii_view);
1275 debug_register_view(adapter->san_dbf, &zfcp_san_dbf_view);
1276 debug_set_level(adapter->san_dbf, 6);
1277
1278 /* debug feature area which records SCSI command failures and recovery */
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001279 sprintf(dbf_name, "zfcp_%s_scsi", zfcp_get_busid_by_adapter(adapter));
1280 adapter->scsi_dbf = debug_register(dbf_name, dbfsize, 1,
1281 sizeof(struct zfcp_scsi_dbf_record));
1282 if (!adapter->scsi_dbf)
1283 goto failed;
1284 debug_register_view(adapter->scsi_dbf, &debug_hex_ascii_view);
1285 debug_register_view(adapter->scsi_dbf, &zfcp_scsi_dbf_view);
1286 debug_set_level(adapter->scsi_dbf, 3);
1287
1288 return 0;
1289
1290 failed:
1291 zfcp_adapter_debug_unregister(adapter);
1292
1293 return -ENOMEM;
1294}
1295
1296/**
1297 * zfcp_adapter_debug_unregister - unregisters debug feature for an adapter
1298 * @adapter: pointer to adapter for which debug features should be unregistered
1299 */
1300void zfcp_adapter_debug_unregister(struct zfcp_adapter *adapter)
1301{
1302 debug_unregister(adapter->scsi_dbf);
1303 debug_unregister(adapter->san_dbf);
1304 debug_unregister(adapter->hba_dbf);
Martin Peschked79a83d2008-03-27 14:22:00 +01001305 debug_unregister(adapter->rec_dbf);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001306 adapter->scsi_dbf = NULL;
1307 adapter->san_dbf = NULL;
1308 adapter->hba_dbf = NULL;
Martin Peschked79a83d2008-03-27 14:22:00 +01001309 adapter->rec_dbf = NULL;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001310}
1311
1312#undef ZFCP_LOG_AREA