blob: 0341fc5e06ceb58b03bd2d9516a9db0f0c97df59 [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
Martin Peschke10223c62008-03-27 14:21:59 +010077static void zfcp_dbf_outs(char **buf, const char *s1, const char *s2)
78{
79 *buf += sprintf(*buf, "%-24s%s\n", s1, s2);
80}
81
82static void zfcp_dbf_out(char **buf, const char *s, const char *format, ...)
83{
84 va_list arg;
85
86 *buf += sprintf(*buf, "%-24s", s);
87 va_start(arg, format);
88 *buf += vsprintf(*buf, format, arg);
89 va_end(arg);
90 *buf += sprintf(*buf, "\n");
91}
92
Martin Peschkedf29f4a2008-03-31 11:15:26 +020093static void zfcp_dbf_outd(char **p, const char *label, char *buffer,
94 int buflen, int offset, int total_size)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020095{
Martin Peschkedf29f4a2008-03-31 11:15:26 +020096 if (!offset)
97 *p += sprintf(*p, "%-24s ", label);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020098 while (buflen--) {
99 if (offset > 0) {
100 if ((offset % 32) == 0)
Martin Peschkedf29f4a2008-03-31 11:15:26 +0200101 *p += sprintf(*p, "\n%-24c ", ' ');
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200102 else if ((offset % 4) == 0)
Martin Peschkedf29f4a2008-03-31 11:15:26 +0200103 *p += sprintf(*p, " ");
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200104 }
Martin Peschkedf29f4a2008-03-31 11:15:26 +0200105 *p += sprintf(*p, "%02x", *buffer++);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200106 if (++offset == total_size) {
Martin Peschkedf29f4a2008-03-31 11:15:26 +0200107 *p += sprintf(*p, "\n");
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200108 break;
109 }
110 }
Martin Peschkedf29f4a2008-03-31 11:15:26 +0200111 if (!total_size)
112 *p += sprintf(*p, "\n");
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200113}
114
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100115static int
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200116zfcp_dbf_view_header(debug_info_t * id, struct debug_view *view, int area,
117 debug_entry_t * entry, char *out_buf)
118{
119 struct zfcp_dbf_dump *dump = (struct zfcp_dbf_dump *)DEBUG_DATA(entry);
Martin Peschke8fc5af12008-03-31 11:15:23 +0200120 struct timespec t;
Martin Peschkeb634fff2008-03-31 11:15:24 +0200121 char *p = out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200122
123 if (strncmp(dump->tag, "dump", ZFCP_DBF_TAG_SIZE) != 0) {
Martin Peschke8fc5af12008-03-31 11:15:23 +0200124 zfcp_dbf_timestamp(entry->id.stck, &t);
Martin Peschkeb634fff2008-03-31 11:15:24 +0200125 zfcp_dbf_out(&p, "timestamp", "%011lu:%06lu",
126 t.tv_sec, t.tv_nsec);
127 zfcp_dbf_out(&p, "cpu", "%02i", entry->id.fields.cpuid);
128 } else {
Martin Peschkedf29f4a2008-03-31 11:15:26 +0200129 zfcp_dbf_outd(&p, NULL, dump->data, dump->size, dump->offset,
130 dump->total_size);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200131 if ((dump->offset + dump->size) == dump->total_size)
Martin Peschkeb634fff2008-03-31 11:15:24 +0200132 p += sprintf(p, "\n");
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200133 }
Martin Peschkeb634fff2008-03-31 11:15:24 +0200134 return p - out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200135}
136
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100137void zfcp_hba_dbf_event_fsf_response(struct zfcp_fsf_req *fsf_req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200138{
139 struct zfcp_adapter *adapter = fsf_req->adapter;
140 struct fsf_qtcb *qtcb = fsf_req->qtcb;
141 union fsf_prot_status_qual *prot_status_qual =
142 &qtcb->prefix.prot_status_qual;
143 union fsf_status_qual *fsf_status_qual = &qtcb->header.fsf_status_qual;
144 struct scsi_cmnd *scsi_cmnd;
145 struct zfcp_port *port;
146 struct zfcp_unit *unit;
147 struct zfcp_send_els *send_els;
148 struct zfcp_hba_dbf_record *rec = &adapter->hba_dbf_buf;
149 struct zfcp_hba_dbf_record_response *response = &rec->type.response;
150 int level;
151 unsigned long flags;
152
153 spin_lock_irqsave(&adapter->hba_dbf_lock, flags);
154 memset(rec, 0, sizeof(struct zfcp_hba_dbf_record));
155 strncpy(rec->tag, "resp", ZFCP_DBF_TAG_SIZE);
156
157 if ((qtcb->prefix.prot_status != FSF_PROT_GOOD) &&
158 (qtcb->prefix.prot_status != FSF_PROT_FSF_STATUS_PRESENTED)) {
159 strncpy(rec->tag2, "perr", ZFCP_DBF_TAG_SIZE);
160 level = 1;
161 } else if (qtcb->header.fsf_status != FSF_GOOD) {
162 strncpy(rec->tag2, "ferr", ZFCP_DBF_TAG_SIZE);
163 level = 1;
164 } else if ((fsf_req->fsf_command == FSF_QTCB_OPEN_PORT_WITH_DID) ||
165 (fsf_req->fsf_command == FSF_QTCB_OPEN_LUN)) {
166 strncpy(rec->tag2, "open", ZFCP_DBF_TAG_SIZE);
167 level = 4;
Martin Peschkeb75db732008-03-27 14:21:58 +0100168 } else if (qtcb->header.log_length) {
169 strncpy(rec->tag2, "qtcb", ZFCP_DBF_TAG_SIZE);
170 level = 5;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200171 } else {
172 strncpy(rec->tag2, "norm", ZFCP_DBF_TAG_SIZE);
173 level = 6;
174 }
175
176 response->fsf_command = fsf_req->fsf_command;
177 response->fsf_reqid = (unsigned long)fsf_req;
178 response->fsf_seqno = fsf_req->seq_no;
179 response->fsf_issued = fsf_req->issued;
180 response->fsf_prot_status = qtcb->prefix.prot_status;
181 response->fsf_status = qtcb->header.fsf_status;
182 memcpy(response->fsf_prot_status_qual,
183 prot_status_qual, FSF_PROT_STATUS_QUAL_SIZE);
184 memcpy(response->fsf_status_qual,
185 fsf_status_qual, FSF_STATUS_QUALIFIER_SIZE);
186 response->fsf_req_status = fsf_req->status;
187 response->sbal_first = fsf_req->sbal_first;
188 response->sbal_curr = fsf_req->sbal_curr;
189 response->sbal_last = fsf_req->sbal_last;
190 response->pool = fsf_req->pool != NULL;
191 response->erp_action = (unsigned long)fsf_req->erp_action;
192
193 switch (fsf_req->fsf_command) {
194 case FSF_QTCB_FCP_CMND:
195 if (fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT)
196 break;
197 scsi_cmnd = (struct scsi_cmnd *)fsf_req->data;
198 if (scsi_cmnd != NULL) {
199 response->data.send_fcp.scsi_cmnd
200 = (unsigned long)scsi_cmnd;
201 response->data.send_fcp.scsi_serial
202 = scsi_cmnd->serial_number;
203 }
204 break;
205
206 case FSF_QTCB_OPEN_PORT_WITH_DID:
207 case FSF_QTCB_CLOSE_PORT:
208 case FSF_QTCB_CLOSE_PHYSICAL_PORT:
209 port = (struct zfcp_port *)fsf_req->data;
210 response->data.port.wwpn = port->wwpn;
211 response->data.port.d_id = port->d_id;
212 response->data.port.port_handle = qtcb->header.port_handle;
213 break;
214
215 case FSF_QTCB_OPEN_LUN:
216 case FSF_QTCB_CLOSE_LUN:
217 unit = (struct zfcp_unit *)fsf_req->data;
218 port = unit->port;
219 response->data.unit.wwpn = port->wwpn;
220 response->data.unit.fcp_lun = unit->fcp_lun;
221 response->data.unit.port_handle = qtcb->header.port_handle;
222 response->data.unit.lun_handle = qtcb->header.lun_handle;
223 break;
224
225 case FSF_QTCB_SEND_ELS:
226 send_els = (struct zfcp_send_els *)fsf_req->data;
227 response->data.send_els.d_id = qtcb->bottom.support.d_id;
228 response->data.send_els.ls_code = send_els->ls_code >> 24;
229 break;
230
231 case FSF_QTCB_ABORT_FCP_CMND:
232 case FSF_QTCB_SEND_GENERIC:
233 case FSF_QTCB_EXCHANGE_CONFIG_DATA:
234 case FSF_QTCB_EXCHANGE_PORT_DATA:
235 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
236 case FSF_QTCB_UPLOAD_CONTROL_FILE:
237 break;
238 }
239
240 debug_event(adapter->hba_dbf, level,
241 rec, sizeof(struct zfcp_hba_dbf_record));
Martin Peschkeb75db732008-03-27 14:21:58 +0100242
243 /* have fcp channel microcode fixed to use as little as possible */
244 if (fsf_req->fsf_command != FSF_QTCB_FCP_CMND) {
245 /* adjust length skipping trailing zeros */
246 char *buf = (char *)qtcb + qtcb->header.log_start;
247 int len = qtcb->header.log_length;
248 for (; len && !buf[len - 1]; len--);
249 zfcp_dbf_hexdump(adapter->hba_dbf, rec, sizeof(*rec), level,
250 buf, len);
251 }
252
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200253 spin_unlock_irqrestore(&adapter->hba_dbf_lock, flags);
254}
255
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100256void
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200257zfcp_hba_dbf_event_fsf_unsol(const char *tag, struct zfcp_adapter *adapter,
258 struct fsf_status_read_buffer *status_buffer)
259{
260 struct zfcp_hba_dbf_record *rec = &adapter->hba_dbf_buf;
261 unsigned long flags;
262
263 spin_lock_irqsave(&adapter->hba_dbf_lock, flags);
264 memset(rec, 0, sizeof(struct zfcp_hba_dbf_record));
265 strncpy(rec->tag, "stat", ZFCP_DBF_TAG_SIZE);
266 strncpy(rec->tag2, tag, ZFCP_DBF_TAG_SIZE);
267
268 rec->type.status.failed = adapter->status_read_failed;
269 if (status_buffer != NULL) {
270 rec->type.status.status_type = status_buffer->status_type;
271 rec->type.status.status_subtype = status_buffer->status_subtype;
272 memcpy(&rec->type.status.queue_designator,
273 &status_buffer->queue_designator,
274 sizeof(struct fsf_queue_designator));
275
276 switch (status_buffer->status_type) {
277 case FSF_STATUS_READ_SENSE_DATA_AVAIL:
278 rec->type.status.payload_size =
279 ZFCP_DBF_UNSOL_PAYLOAD_SENSE_DATA_AVAIL;
280 break;
281
282 case FSF_STATUS_READ_BIT_ERROR_THRESHOLD:
283 rec->type.status.payload_size =
284 ZFCP_DBF_UNSOL_PAYLOAD_BIT_ERROR_THRESHOLD;
285 break;
286
287 case FSF_STATUS_READ_LINK_DOWN:
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200288 switch (status_buffer->status_subtype) {
289 case FSF_STATUS_READ_SUB_NO_PHYSICAL_LINK:
290 case FSF_STATUS_READ_SUB_FDISC_FAILED:
291 rec->type.status.payload_size =
292 sizeof(struct fsf_link_down_info);
293 }
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200294 break;
295
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200296 case FSF_STATUS_READ_FEATURE_UPDATE_ALERT:
297 rec->type.status.payload_size =
298 ZFCP_DBF_UNSOL_PAYLOAD_FEATURE_UPDATE_ALERT;
299 break;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200300 }
301 memcpy(&rec->type.status.payload,
302 &status_buffer->payload, rec->type.status.payload_size);
303 }
304
305 debug_event(adapter->hba_dbf, 2,
306 rec, sizeof(struct zfcp_hba_dbf_record));
307 spin_unlock_irqrestore(&adapter->hba_dbf_lock, flags);
308}
309
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100310void
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200311zfcp_hba_dbf_event_qdio(struct zfcp_adapter *adapter, unsigned int status,
312 unsigned int qdio_error, unsigned int siga_error,
313 int sbal_index, int sbal_count)
314{
315 struct zfcp_hba_dbf_record *rec = &adapter->hba_dbf_buf;
316 unsigned long flags;
317
318 spin_lock_irqsave(&adapter->hba_dbf_lock, flags);
319 memset(rec, 0, sizeof(struct zfcp_hba_dbf_record));
320 strncpy(rec->tag, "qdio", ZFCP_DBF_TAG_SIZE);
321 rec->type.qdio.status = status;
322 rec->type.qdio.qdio_error = qdio_error;
323 rec->type.qdio.siga_error = siga_error;
324 rec->type.qdio.sbal_index = sbal_index;
325 rec->type.qdio.sbal_count = sbal_count;
326 debug_event(adapter->hba_dbf, 0,
327 rec, sizeof(struct zfcp_hba_dbf_record));
328 spin_unlock_irqrestore(&adapter->hba_dbf_lock, flags);
329}
330
Martin Peschkeb634fff2008-03-31 11:15:24 +0200331static int zfcp_hba_dbf_view_response(char *buf,
332 struct zfcp_hba_dbf_record_response *r)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200333{
Martin Peschke8fc5af12008-03-31 11:15:23 +0200334 struct timespec t;
Martin Peschkeb634fff2008-03-31 11:15:24 +0200335 char *p = buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200336
Martin Peschkeb634fff2008-03-31 11:15:24 +0200337 zfcp_dbf_out(&p, "fsf_command", "0x%08x", r->fsf_command);
338 zfcp_dbf_out(&p, "fsf_reqid", "0x%0Lx", r->fsf_reqid);
339 zfcp_dbf_out(&p, "fsf_seqno", "0x%08x", r->fsf_seqno);
340 zfcp_dbf_timestamp(r->fsf_issued, &t);
341 zfcp_dbf_out(&p, "fsf_issued", "%011lu:%06lu", t.tv_sec, t.tv_nsec);
342 zfcp_dbf_out(&p, "fsf_prot_status", "0x%08x", r->fsf_prot_status);
343 zfcp_dbf_out(&p, "fsf_status", "0x%08x", r->fsf_status);
Martin Peschkedf29f4a2008-03-31 11:15:26 +0200344 zfcp_dbf_outd(&p, "fsf_prot_status_qual", r->fsf_prot_status_qual,
345 FSF_PROT_STATUS_QUAL_SIZE, 0, FSF_PROT_STATUS_QUAL_SIZE);
346 zfcp_dbf_outd(&p, "fsf_status_qual", r->fsf_status_qual,
347 FSF_STATUS_QUALIFIER_SIZE, 0, FSF_STATUS_QUALIFIER_SIZE);
Martin Peschkeb634fff2008-03-31 11:15:24 +0200348 zfcp_dbf_out(&p, "fsf_req_status", "0x%08x", r->fsf_req_status);
349 zfcp_dbf_out(&p, "sbal_first", "0x%02x", r->sbal_first);
350 zfcp_dbf_out(&p, "sbal_curr", "0x%02x", r->sbal_curr);
351 zfcp_dbf_out(&p, "sbal_last", "0x%02x", r->sbal_last);
352 zfcp_dbf_out(&p, "pool", "0x%02x", r->pool);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200353
Martin Peschkeb634fff2008-03-31 11:15:24 +0200354 switch (r->fsf_command) {
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200355 case FSF_QTCB_FCP_CMND:
Martin Peschkeb634fff2008-03-31 11:15:24 +0200356 if (r->fsf_req_status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200357 break;
Martin Peschkeb634fff2008-03-31 11:15:24 +0200358 zfcp_dbf_out(&p, "scsi_cmnd", "0x%0Lx",
359 r->data.send_fcp.scsi_cmnd);
360 zfcp_dbf_out(&p, "scsi_serial", "0x%016Lx",
361 r->data.send_fcp.scsi_serial);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200362 break;
363
364 case FSF_QTCB_OPEN_PORT_WITH_DID:
365 case FSF_QTCB_CLOSE_PORT:
366 case FSF_QTCB_CLOSE_PHYSICAL_PORT:
Martin Peschkeb634fff2008-03-31 11:15:24 +0200367 zfcp_dbf_out(&p, "wwpn", "0x%016Lx", r->data.port.wwpn);
368 zfcp_dbf_out(&p, "d_id", "0x%06x", r->data.port.d_id);
369 zfcp_dbf_out(&p, "port_handle", "0x%08x",
370 r->data.port.port_handle);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200371 break;
372
373 case FSF_QTCB_OPEN_LUN:
374 case FSF_QTCB_CLOSE_LUN:
Martin Peschkeb634fff2008-03-31 11:15:24 +0200375 zfcp_dbf_out(&p, "wwpn", "0x%016Lx", r->data.unit.wwpn);
376 zfcp_dbf_out(&p, "fcp_lun", "0x%016Lx", r->data.unit.fcp_lun);
377 zfcp_dbf_out(&p, "port_handle", "0x%08x",
378 r->data.unit.port_handle);
379 zfcp_dbf_out(&p, "lun_handle", "0x%08x",
380 r->data.unit.lun_handle);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200381 break;
382
383 case FSF_QTCB_SEND_ELS:
Martin Peschkeb634fff2008-03-31 11:15:24 +0200384 zfcp_dbf_out(&p, "d_id", "0x%06x", r->data.send_els.d_id);
385 zfcp_dbf_out(&p, "ls_code", "0x%02x", r->data.send_els.ls_code);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200386 break;
387
388 case FSF_QTCB_ABORT_FCP_CMND:
389 case FSF_QTCB_SEND_GENERIC:
390 case FSF_QTCB_EXCHANGE_CONFIG_DATA:
391 case FSF_QTCB_EXCHANGE_PORT_DATA:
392 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
393 case FSF_QTCB_UPLOAD_CONTROL_FILE:
394 break;
395 }
Martin Peschkeb634fff2008-03-31 11:15:24 +0200396 return p - buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200397}
398
Martin Peschkeb634fff2008-03-31 11:15:24 +0200399static int zfcp_hba_dbf_view_status(char *buf,
400 struct zfcp_hba_dbf_record_status *r)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200401{
Martin Peschkeb634fff2008-03-31 11:15:24 +0200402 char *p = buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200403
Martin Peschkeb634fff2008-03-31 11:15:24 +0200404 zfcp_dbf_out(&p, "failed", "0x%02x", r->failed);
405 zfcp_dbf_out(&p, "status_type", "0x%08x", r->status_type);
406 zfcp_dbf_out(&p, "status_subtype", "0x%08x", r->status_subtype);
Martin Peschkedf29f4a2008-03-31 11:15:26 +0200407 zfcp_dbf_outd(&p, "queue_designator", (char *)&r->queue_designator,
408 sizeof(struct fsf_queue_designator), 0,
409 sizeof(struct fsf_queue_designator));
410 zfcp_dbf_outd(&p, "payload", (char *)&r->payload, r->payload_size, 0,
411 r->payload_size);
Martin Peschkeb634fff2008-03-31 11:15:24 +0200412 return p - buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200413}
414
Martin Peschkeb634fff2008-03-31 11:15:24 +0200415static int zfcp_hba_dbf_view_qdio(char *buf, struct zfcp_hba_dbf_record_qdio *r)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200416{
Martin Peschkeb634fff2008-03-31 11:15:24 +0200417 char *p = buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200418
Martin Peschkeb634fff2008-03-31 11:15:24 +0200419 zfcp_dbf_out(&p, "status", "0x%08x", r->status);
420 zfcp_dbf_out(&p, "qdio_error", "0x%08x", r->qdio_error);
421 zfcp_dbf_out(&p, "siga_error", "0x%08x", r->siga_error);
422 zfcp_dbf_out(&p, "sbal_index", "0x%02x", r->sbal_index);
423 zfcp_dbf_out(&p, "sbal_count", "0x%02x", r->sbal_count);
424 return p - buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200425}
426
427static int
428zfcp_hba_dbf_view_format(debug_info_t * id, struct debug_view *view,
429 char *out_buf, const char *in_buf)
430{
431 struct zfcp_hba_dbf_record *rec = (struct zfcp_hba_dbf_record *)in_buf;
432 int len = 0;
433
434 if (strncmp(rec->tag, "dump", ZFCP_DBF_TAG_SIZE) == 0)
435 return 0;
436
437 len += zfcp_dbf_tag(out_buf + len, "tag", rec->tag);
438 if (isalpha(rec->tag2[0]))
439 len += zfcp_dbf_tag(out_buf + len, "tag2", rec->tag2);
440 if (strncmp(rec->tag, "resp", ZFCP_DBF_TAG_SIZE) == 0)
441 len += zfcp_hba_dbf_view_response(out_buf + len,
442 &rec->type.response);
443 else if (strncmp(rec->tag, "stat", ZFCP_DBF_TAG_SIZE) == 0)
444 len += zfcp_hba_dbf_view_status(out_buf + len,
445 &rec->type.status);
446 else if (strncmp(rec->tag, "qdio", ZFCP_DBF_TAG_SIZE) == 0)
447 len += zfcp_hba_dbf_view_qdio(out_buf + len, &rec->type.qdio);
448
449 len += sprintf(out_buf + len, "\n");
450
451 return len;
452}
453
Heiko Carstens2b67fc42007-02-05 21:16:47 +0100454static struct debug_view zfcp_hba_dbf_view = {
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200455 "structured",
456 NULL,
457 &zfcp_dbf_view_header,
458 &zfcp_hba_dbf_view_format,
459 NULL,
460 NULL
461};
462
Martin Peschked79a83d2008-03-27 14:22:00 +0100463static const char *zfcp_rec_dbf_tags[] = {
Martin Peschke348447e2008-03-27 14:22:01 +0100464 [ZFCP_REC_DBF_ID_THREAD] = "thread",
Martin Peschke698ec0162008-03-27 14:22:02 +0100465 [ZFCP_REC_DBF_ID_TARGET] = "target",
Martin Peschke9467a9b2008-03-27 14:22:03 +0100466 [ZFCP_REC_DBF_ID_TRIGGER] = "trigger",
Martin Peschke6f4f3652008-03-27 14:22:04 +0100467 [ZFCP_REC_DBF_ID_ACTION] = "action",
Martin Peschked79a83d2008-03-27 14:22:00 +0100468};
469
470static const char *zfcp_rec_dbf_ids[] = {
Martin Peschke348447e2008-03-27 14:22:01 +0100471 [1] = "new",
472 [2] = "ready",
473 [3] = "kill",
474 [4] = "down sleep",
475 [5] = "down wakeup",
476 [6] = "down sleep ecd",
477 [7] = "down wakeup ecd",
478 [8] = "down sleep epd",
479 [9] = "down wakeup epd",
Martin Peschke698ec0162008-03-27 14:22:02 +0100480 [10] = "online",
481 [11] = "operational",
482 [12] = "scsi slave destroy",
483 [13] = "propagate failed adapter",
484 [14] = "propagate failed port",
485 [15] = "block adapter",
486 [16] = "unblock adapter",
487 [17] = "block port",
488 [18] = "unblock port",
489 [19] = "block unit",
490 [20] = "unblock unit",
491 [21] = "unit recovery failed",
492 [22] = "port recovery failed",
493 [23] = "adapter recovery failed",
494 [24] = "qdio queues down",
495 [25] = "p2p failed",
496 [26] = "nameserver lookup failed",
497 [27] = "nameserver port failed",
498 [28] = "link up",
499 [29] = "link down",
500 [30] = "link up status read",
501 [31] = "open port failed",
502 [32] = "open port failed",
503 [33] = "close port",
504 [34] = "open unit failed",
505 [35] = "exclusive open unit failed",
506 [36] = "shared open unit failed",
507 [37] = "link down",
508 [38] = "link down status read no link",
509 [39] = "link down status read fdisc login",
510 [40] = "link down status read firmware update",
511 [41] = "link down status read unknown reason",
512 [42] = "link down ecd incomplete",
513 [43] = "link down epd incomplete",
514 [44] = "sysfs adapter recovery",
515 [45] = "sysfs port recovery",
516 [46] = "sysfs unit recovery",
517 [47] = "port boxed abort",
518 [48] = "unit boxed abort",
519 [49] = "port boxed ct",
520 [50] = "port boxed close physical",
521 [51] = "port boxed open unit",
522 [52] = "port boxed close unit",
523 [53] = "port boxed fcp",
524 [54] = "unit boxed fcp",
525 [55] = "port access denied ct",
526 [56] = "port access denied els",
527 [57] = "port access denied open port",
528 [58] = "port access denied close physical",
529 [59] = "unit access denied open unit",
530 [60] = "shared unit access denied open unit",
531 [61] = "unit access denied fcp",
Martin Peschke9467a9b2008-03-27 14:22:03 +0100532 [62] = "request timeout",
533 [63] = "adisc link test reject or timeout",
534 [64] = "adisc link test d_id changed",
535 [65] = "adisc link test failed",
536 [66] = "recovery out of memory",
537 [67] = "adapter recovery repeated after state change",
538 [68] = "port recovery repeated after state change",
539 [69] = "unit recovery repeated after state change",
540 [70] = "port recovery follow-up after successful adapter recovery",
541 [71] = "adapter recovery escalation after failed adapter recovery",
542 [72] = "port recovery follow-up after successful physical port "
543 "recovery",
544 [73] = "adapter recovery escalation after failed physical port "
545 "recovery",
546 [74] = "unit recovery follow-up after successful port recovery",
547 [75] = "physical port recovery escalation after failed port "
548 "recovery",
549 [76] = "port recovery escalation after failed unit recovery",
550 [77] = "recovery opening nameserver port",
551 [78] = "duplicate request id",
552 [79] = "link down",
553 [80] = "exclusive read-only unit access unsupported",
554 [81] = "shared read-write unit access unsupported",
555 [82] = "incoming rscn",
556 [83] = "incoming plogi",
557 [84] = "incoming logo",
558 [85] = "online",
559 [86] = "offline",
560 [87] = "ccw device gone",
561 [88] = "ccw device no path",
562 [89] = "ccw device operational",
563 [90] = "ccw device shutdown",
564 [91] = "sysfs port addition",
565 [92] = "sysfs port removal",
566 [93] = "sysfs adapter recovery",
567 [94] = "sysfs unit addition",
568 [95] = "sysfs unit removal",
569 [96] = "sysfs port recovery",
570 [97] = "sysfs unit recovery",
571 [98] = "sequence number mismatch",
572 [99] = "link up",
573 [100] = "error state",
574 [101] = "status read physical port closed",
575 [102] = "link up status read",
576 [103] = "too many failed status read buffers",
577 [104] = "port handle not valid abort",
578 [105] = "lun handle not valid abort",
579 [106] = "port handle not valid ct",
580 [107] = "port handle not valid close port",
581 [108] = "port handle not valid close physical port",
582 [109] = "port handle not valid open unit",
583 [110] = "port handle not valid close unit",
584 [111] = "lun handle not valid close unit",
585 [112] = "port handle not valid fcp",
586 [113] = "lun handle not valid fcp",
587 [114] = "handle mismatch fcp",
588 [115] = "lun not valid fcp",
589 [116] = "qdio send failed",
590 [117] = "version mismatch",
591 [118] = "incompatible qtcb type",
592 [119] = "unknown protocol status",
593 [120] = "unknown fsf command",
594 [121] = "no recommendation for status qualifier",
595 [122] = "status read physical port closed in error",
596 [123] = "fc service class not supported ct",
597 [124] = "fc service class not supported els",
598 [125] = "need newer zfcp",
599 [126] = "need newer microcode",
600 [127] = "arbitrated loop not supported",
601 [128] = "unknown topology",
602 [129] = "qtcb size mismatch",
603 [130] = "unknown fsf status ecd",
604 [131] = "fcp request too big",
605 [132] = "fc service class not supported fcp",
606 [133] = "data direction not valid fcp",
607 [134] = "command length not valid fcp",
608 [135] = "status read act update",
609 [136] = "status read cfdc update",
610 [137] = "hbaapi port open",
611 [138] = "hbaapi unit open",
612 [139] = "hbaapi unit shutdown",
613 [140] = "qdio error",
614 [141] = "scsi host reset",
Martin Peschke6f4f3652008-03-27 14:22:04 +0100615 [142] = "dismissing fsf request for recovery action",
616 [143] = "recovery action timed out",
617 [144] = "recovery action gone",
618 [145] = "recovery action being processed",
619 [146] = "recovery action ready for next step",
Martin Peschked79a83d2008-03-27 14:22:00 +0100620};
621
622static int zfcp_rec_dbf_view_format(debug_info_t *id, struct debug_view *view,
623 char *buf, const char *_rec)
624{
625 struct zfcp_rec_dbf_record *r = (struct zfcp_rec_dbf_record *)_rec;
626 char *p = buf;
627
628 zfcp_dbf_outs(&p, "tag", zfcp_rec_dbf_tags[r->id]);
629 zfcp_dbf_outs(&p, "hint", zfcp_rec_dbf_ids[r->id2]);
630 zfcp_dbf_out(&p, "id", "%d", r->id2);
631 switch (r->id) {
Martin Peschke348447e2008-03-27 14:22:01 +0100632 case ZFCP_REC_DBF_ID_THREAD:
633 zfcp_dbf_out(&p, "sema", "%d", r->u.thread.sema);
634 zfcp_dbf_out(&p, "total", "%d", r->u.thread.total);
635 zfcp_dbf_out(&p, "ready", "%d", r->u.thread.ready);
636 zfcp_dbf_out(&p, "running", "%d", r->u.thread.running);
637 break;
Martin Peschke698ec0162008-03-27 14:22:02 +0100638 case ZFCP_REC_DBF_ID_TARGET:
639 zfcp_dbf_out(&p, "reference", "0x%016Lx", r->u.target.ref);
640 zfcp_dbf_out(&p, "status", "0x%08x", r->u.target.status);
641 zfcp_dbf_out(&p, "erp_count", "%d", r->u.target.erp_count);
642 zfcp_dbf_out(&p, "d_id", "0x%06x", r->u.target.d_id);
643 zfcp_dbf_out(&p, "wwpn", "0x%016Lx", r->u.target.wwpn);
644 zfcp_dbf_out(&p, "fcp_lun", "0x%016Lx", r->u.target.fcp_lun);
645 break;
Martin Peschke9467a9b2008-03-27 14:22:03 +0100646 case ZFCP_REC_DBF_ID_TRIGGER:
647 zfcp_dbf_out(&p, "reference", "0x%016Lx", r->u.trigger.ref);
648 zfcp_dbf_out(&p, "erp_action", "0x%016Lx", r->u.trigger.action);
649 zfcp_dbf_out(&p, "requested", "%d", r->u.trigger.want);
650 zfcp_dbf_out(&p, "executed", "%d", r->u.trigger.need);
651 zfcp_dbf_out(&p, "wwpn", "0x%016Lx", r->u.trigger.wwpn);
652 zfcp_dbf_out(&p, "fcp_lun", "0x%016Lx", r->u.trigger.fcp_lun);
653 zfcp_dbf_out(&p, "adapter_status", "0x%08x", r->u.trigger.as);
654 zfcp_dbf_out(&p, "port_status", "0x%08x", r->u.trigger.ps);
655 zfcp_dbf_out(&p, "unit_status", "0x%08x", r->u.trigger.us);
656 break;
Martin Peschke6f4f3652008-03-27 14:22:04 +0100657 case ZFCP_REC_DBF_ID_ACTION:
658 zfcp_dbf_out(&p, "erp_action", "0x%016Lx", r->u.action.action);
659 zfcp_dbf_out(&p, "fsf_req", "0x%016Lx", r->u.action.fsf_req);
660 zfcp_dbf_out(&p, "status", "0x%08Lx", r->u.action.status);
661 zfcp_dbf_out(&p, "step", "0x%08Lx", r->u.action.step);
662 break;
Martin Peschked79a83d2008-03-27 14:22:00 +0100663 }
Martin Peschkeb634fff2008-03-31 11:15:24 +0200664 p += sprintf(p, "\n");
665 return p - buf;
Martin Peschked79a83d2008-03-27 14:22:00 +0100666}
667
668static struct debug_view zfcp_rec_dbf_view = {
669 "structured",
670 NULL,
671 &zfcp_dbf_view_header,
672 &zfcp_rec_dbf_view_format,
673 NULL,
674 NULL
675};
676
Martin Peschke348447e2008-03-27 14:22:01 +0100677/**
678 * zfcp_rec_dbf_event_thread - trace event related to recovery thread operation
679 * @id2: identifier for event
680 * @adapter: adapter
681 * @lock: non-zero value indicates that erp_lock has not yet been acquired
682 */
683void zfcp_rec_dbf_event_thread(u8 id2, struct zfcp_adapter *adapter, int lock)
684{
685 struct zfcp_rec_dbf_record *r = &adapter->rec_dbf_buf;
686 unsigned long flags = 0;
687 struct list_head *entry;
688 unsigned ready = 0, running = 0, total;
689
690 if (lock)
691 read_lock_irqsave(&adapter->erp_lock, flags);
692 list_for_each(entry, &adapter->erp_ready_head)
693 ready++;
694 list_for_each(entry, &adapter->erp_running_head)
695 running++;
696 total = adapter->erp_total_count;
697 if (lock)
698 read_unlock_irqrestore(&adapter->erp_lock, flags);
699
700 spin_lock_irqsave(&adapter->rec_dbf_lock, flags);
701 memset(r, 0, sizeof(*r));
702 r->id = ZFCP_REC_DBF_ID_THREAD;
703 r->id2 = id2;
704 r->u.thread.sema = atomic_read(&adapter->erp_ready_sem.count);
705 r->u.thread.total = total;
706 r->u.thread.ready = ready;
707 r->u.thread.running = running;
708 debug_event(adapter->rec_dbf, 5, r, sizeof(*r));
709 spin_unlock_irqrestore(&adapter->rec_dbf_lock, flags);
710}
711
Martin Peschke698ec0162008-03-27 14:22:02 +0100712static void zfcp_rec_dbf_event_target(u8 id2, u64 ref,
713 struct zfcp_adapter *adapter,
714 atomic_t *status, atomic_t *erp_count,
715 u64 wwpn, u32 d_id, u64 fcp_lun)
716{
717 struct zfcp_rec_dbf_record *r = &adapter->rec_dbf_buf;
718 unsigned long flags;
719
720 spin_lock_irqsave(&adapter->rec_dbf_lock, flags);
721 memset(r, 0, sizeof(*r));
722 r->id = ZFCP_REC_DBF_ID_TARGET;
723 r->id2 = id2;
724 r->u.target.ref = ref;
725 r->u.target.status = atomic_read(status);
726 r->u.target.wwpn = wwpn;
727 r->u.target.d_id = d_id;
728 r->u.target.fcp_lun = fcp_lun;
729 r->u.target.erp_count = atomic_read(erp_count);
730 debug_event(adapter->rec_dbf, 3, r, sizeof(*r));
731 spin_unlock_irqrestore(&adapter->rec_dbf_lock, flags);
732}
733
734/**
735 * zfcp_rec_dbf_event_adapter - trace event for adapter state change
736 * @id: identifier for trigger of state change
737 * @ref: additional reference (e.g. request)
738 * @adapter: adapter
739 */
740void zfcp_rec_dbf_event_adapter(u8 id, u64 ref, struct zfcp_adapter *adapter)
741{
742 zfcp_rec_dbf_event_target(id, ref, adapter, &adapter->status,
743 &adapter->erp_counter, 0, 0, 0);
744}
745
746/**
747 * zfcp_rec_dbf_event_port - trace event for port state change
748 * @id: identifier for trigger of state change
749 * @ref: additional reference (e.g. request)
750 * @port: port
751 */
752void zfcp_rec_dbf_event_port(u8 id, u64 ref, struct zfcp_port *port)
753{
754 struct zfcp_adapter *adapter = port->adapter;
755
756 zfcp_rec_dbf_event_target(id, ref, adapter, &port->status,
757 &port->erp_counter, port->wwpn, port->d_id,
758 0);
759}
760
761/**
762 * zfcp_rec_dbf_event_unit - trace event for unit state change
763 * @id: identifier for trigger of state change
764 * @ref: additional reference (e.g. request)
765 * @unit: unit
766 */
767void zfcp_rec_dbf_event_unit(u8 id, u64 ref, struct zfcp_unit *unit)
768{
769 struct zfcp_port *port = unit->port;
770 struct zfcp_adapter *adapter = port->adapter;
771
772 zfcp_rec_dbf_event_target(id, ref, adapter, &unit->status,
773 &unit->erp_counter, port->wwpn, port->d_id,
774 unit->fcp_lun);
775}
776
Martin Peschke9467a9b2008-03-27 14:22:03 +0100777/**
778 * zfcp_rec_dbf_event_trigger - trace event for triggered error recovery
779 * @id2: identifier for error recovery trigger
780 * @ref: additional reference (e.g. request)
781 * @want: originally requested error recovery action
782 * @need: error recovery action actually initiated
783 * @action: address of error recovery action struct
784 * @adapter: adapter
785 * @port: port
786 * @unit: unit
787 */
788void zfcp_rec_dbf_event_trigger(u8 id2, u64 ref, u8 want, u8 need, u64 action,
789 struct zfcp_adapter *adapter,
790 struct zfcp_port *port, struct zfcp_unit *unit)
791{
792 struct zfcp_rec_dbf_record *r = &adapter->rec_dbf_buf;
793 unsigned long flags;
794
795 spin_lock_irqsave(&adapter->rec_dbf_lock, flags);
796 memset(r, 0, sizeof(*r));
797 r->id = ZFCP_REC_DBF_ID_TRIGGER;
798 r->id2 = id2;
799 r->u.trigger.ref = ref;
800 r->u.trigger.want = want;
801 r->u.trigger.need = need;
802 r->u.trigger.action = action;
803 r->u.trigger.as = atomic_read(&adapter->status);
804 if (port) {
805 r->u.trigger.ps = atomic_read(&port->status);
806 r->u.trigger.wwpn = port->wwpn;
807 }
808 if (unit) {
809 r->u.trigger.us = atomic_read(&unit->status);
810 r->u.trigger.fcp_lun = unit->fcp_lun;
811 }
812 debug_event(adapter->rec_dbf, action ? 1 : 4, r, sizeof(*r));
813 spin_unlock_irqrestore(&adapter->rec_dbf_lock, flags);
814}
815
Martin Peschke6f4f3652008-03-27 14:22:04 +0100816/**
817 * zfcp_rec_dbf_event_action - trace event showing progress of recovery action
818 * @id2: identifier
819 * @erp_action: error recovery action struct pointer
820 */
821void zfcp_rec_dbf_event_action(u8 id2, struct zfcp_erp_action *erp_action)
822{
823 struct zfcp_adapter *adapter = erp_action->adapter;
824 struct zfcp_rec_dbf_record *r = &adapter->rec_dbf_buf;
825 unsigned long flags;
826
827 spin_lock_irqsave(&adapter->rec_dbf_lock, flags);
828 memset(r, 0, sizeof(*r));
829 r->id = ZFCP_REC_DBF_ID_ACTION;
830 r->id2 = id2;
831 r->u.action.action = (u64)erp_action;
832 r->u.action.status = erp_action->status;
833 r->u.action.step = erp_action->step;
834 r->u.action.fsf_req = (u64)erp_action->fsf_req;
835 debug_event(adapter->rec_dbf, 4, r, sizeof(*r));
836 spin_unlock_irqrestore(&adapter->rec_dbf_lock, flags);
837}
838
Heiko Carstens763968e2007-05-10 15:45:46 +0200839static void
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200840_zfcp_san_dbf_event_common_ct(const char *tag, struct zfcp_fsf_req *fsf_req,
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200841 u32 s_id, u32 d_id, void *buffer, int buflen)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200842{
843 struct zfcp_send_ct *send_ct = (struct zfcp_send_ct *)fsf_req->data;
844 struct zfcp_port *port = send_ct->port;
845 struct zfcp_adapter *adapter = port->adapter;
846 struct ct_hdr *header = (struct ct_hdr *)buffer;
847 struct zfcp_san_dbf_record *rec = &adapter->san_dbf_buf;
848 struct zfcp_san_dbf_record_ct *ct = &rec->type.ct;
849 unsigned long flags;
850
851 spin_lock_irqsave(&adapter->san_dbf_lock, flags);
852 memset(rec, 0, sizeof(struct zfcp_san_dbf_record));
853 strncpy(rec->tag, tag, ZFCP_DBF_TAG_SIZE);
854 rec->fsf_reqid = (unsigned long)fsf_req;
855 rec->fsf_seqno = fsf_req->seq_no;
856 rec->s_id = s_id;
857 rec->d_id = d_id;
858 if (strncmp(tag, "octc", ZFCP_DBF_TAG_SIZE) == 0) {
859 ct->type.request.cmd_req_code = header->cmd_rsp_code;
860 ct->type.request.revision = header->revision;
861 ct->type.request.gs_type = header->gs_type;
862 ct->type.request.gs_subtype = header->gs_subtype;
863 ct->type.request.options = header->options;
864 ct->type.request.max_res_size = header->max_res_size;
865 } else if (strncmp(tag, "rctc", ZFCP_DBF_TAG_SIZE) == 0) {
866 ct->type.response.cmd_rsp_code = header->cmd_rsp_code;
867 ct->type.response.revision = header->revision;
868 ct->type.response.reason_code = header->reason_code;
869 ct->type.response.reason_code_expl = header->reason_code_expl;
870 ct->type.response.vendor_unique = header->vendor_unique;
871 }
872 ct->payload_size =
873 min(buflen - (int)sizeof(struct ct_hdr), ZFCP_DBF_CT_PAYLOAD);
874 memcpy(ct->payload, buffer + sizeof(struct ct_hdr), ct->payload_size);
875 debug_event(adapter->san_dbf, 3,
876 rec, sizeof(struct zfcp_san_dbf_record));
877 spin_unlock_irqrestore(&adapter->san_dbf_lock, flags);
878}
879
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100880void zfcp_san_dbf_event_ct_request(struct zfcp_fsf_req *fsf_req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200881{
882 struct zfcp_send_ct *ct = (struct zfcp_send_ct *)fsf_req->data;
883 struct zfcp_port *port = ct->port;
884 struct zfcp_adapter *adapter = port->adapter;
885
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200886 _zfcp_san_dbf_event_common_ct("octc", fsf_req,
887 fc_host_port_id(adapter->scsi_host),
888 port->d_id, zfcp_sg_to_address(ct->req),
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200889 ct->req->length);
890}
891
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100892void zfcp_san_dbf_event_ct_response(struct zfcp_fsf_req *fsf_req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200893{
894 struct zfcp_send_ct *ct = (struct zfcp_send_ct *)fsf_req->data;
895 struct zfcp_port *port = ct->port;
896 struct zfcp_adapter *adapter = port->adapter;
897
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200898 _zfcp_san_dbf_event_common_ct("rctc", fsf_req, port->d_id,
899 fc_host_port_id(adapter->scsi_host),
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200900 zfcp_sg_to_address(ct->resp),
901 ct->resp->length);
902}
903
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100904static void
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200905_zfcp_san_dbf_event_common_els(const char *tag, int level,
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200906 struct zfcp_fsf_req *fsf_req, u32 s_id,
907 u32 d_id, u8 ls_code, void *buffer, int buflen)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200908{
909 struct zfcp_adapter *adapter = fsf_req->adapter;
910 struct zfcp_san_dbf_record *rec = &adapter->san_dbf_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200911 unsigned long flags;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200912
913 spin_lock_irqsave(&adapter->san_dbf_lock, flags);
Martin Peschke0f65e952008-03-27 14:21:56 +0100914 memset(rec, 0, sizeof(struct zfcp_san_dbf_record));
915 strncpy(rec->tag, tag, ZFCP_DBF_TAG_SIZE);
916 rec->fsf_reqid = (unsigned long)fsf_req;
917 rec->fsf_seqno = fsf_req->seq_no;
918 rec->s_id = s_id;
919 rec->d_id = d_id;
920 rec->type.els.ls_code = ls_code;
921 debug_event(adapter->san_dbf, level, rec, sizeof(*rec));
922 zfcp_dbf_hexdump(adapter->san_dbf, rec, sizeof(*rec), level,
923 buffer, min(buflen, ZFCP_DBF_ELS_MAX_PAYLOAD));
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200924 spin_unlock_irqrestore(&adapter->san_dbf_lock, flags);
925}
926
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100927void zfcp_san_dbf_event_els_request(struct zfcp_fsf_req *fsf_req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200928{
929 struct zfcp_send_els *els = (struct zfcp_send_els *)fsf_req->data;
930
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200931 _zfcp_san_dbf_event_common_els("oels", 2, fsf_req,
932 fc_host_port_id(els->adapter->scsi_host),
933 els->d_id,
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200934 *(u8 *) zfcp_sg_to_address(els->req),
935 zfcp_sg_to_address(els->req),
936 els->req->length);
937}
938
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100939void zfcp_san_dbf_event_els_response(struct zfcp_fsf_req *fsf_req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200940{
941 struct zfcp_send_els *els = (struct zfcp_send_els *)fsf_req->data;
942
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200943 _zfcp_san_dbf_event_common_els("rels", 2, fsf_req, els->d_id,
944 fc_host_port_id(els->adapter->scsi_host),
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200945 *(u8 *) zfcp_sg_to_address(els->req),
946 zfcp_sg_to_address(els->resp),
947 els->resp->length);
948}
949
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100950void zfcp_san_dbf_event_incoming_els(struct zfcp_fsf_req *fsf_req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200951{
952 struct zfcp_adapter *adapter = fsf_req->adapter;
953 struct fsf_status_read_buffer *status_buffer =
954 (struct fsf_status_read_buffer *)fsf_req->data;
955 int length = (int)status_buffer->length -
956 (int)((void *)&status_buffer->payload - (void *)status_buffer);
957
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200958 _zfcp_san_dbf_event_common_els("iels", 1, fsf_req, status_buffer->d_id,
959 fc_host_port_id(adapter->scsi_host),
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200960 *(u8 *) status_buffer->payload,
961 (void *)status_buffer->payload, length);
962}
963
964static int
965zfcp_san_dbf_view_format(debug_info_t * id, struct debug_view *view,
966 char *out_buf, const char *in_buf)
967{
Martin Peschkeb634fff2008-03-31 11:15:24 +0200968 struct zfcp_san_dbf_record *r = (struct zfcp_san_dbf_record *)in_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200969 char *buffer = NULL;
970 int buflen = 0, total = 0;
Martin Peschkeb634fff2008-03-31 11:15:24 +0200971 char *p = out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200972
Martin Peschkeb634fff2008-03-31 11:15:24 +0200973 if (strncmp(r->tag, "dump", ZFCP_DBF_TAG_SIZE) == 0)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200974 return 0;
975
Martin Peschkeb634fff2008-03-31 11:15:24 +0200976 p += zfcp_dbf_tag(p, "tag", r->tag);
977 zfcp_dbf_out(&p, "fsf_reqid", "0x%0Lx", r->fsf_reqid);
978 zfcp_dbf_out(&p, "fsf_seqno", "0x%08x", r->fsf_seqno);
979 zfcp_dbf_out(&p, "s_id", "0x%06x", r->s_id);
980 zfcp_dbf_out(&p, "d_id", "0x%06x", r->d_id);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200981
Martin Peschkeb634fff2008-03-31 11:15:24 +0200982 if (strncmp(r->tag, "octc", ZFCP_DBF_TAG_SIZE) == 0) {
983 /* FIXME: struct zfcp_dbf_ct_req *ct = ...; */
984 zfcp_dbf_out(&p, "cmd_req_code", "0x%04x",
985 r->type.ct.type.request.cmd_req_code);
986 zfcp_dbf_out(&p, "revision", "0x%02x",
987 r->type.ct.type.request.revision);
988 zfcp_dbf_out(&p, "gs_type", "0x%02x",
989 r->type.ct.type.request.gs_type);
990 zfcp_dbf_out(&p, "gs_subtype", "0x%02x",
991 r->type.ct.type.request.gs_subtype);
992 zfcp_dbf_out(&p, "options", "0x%02x",
993 r->type.ct.type.request.options);
994 zfcp_dbf_out(&p, "max_res_size", "0x%04x",
995 r->type.ct.type.request.max_res_size);
996 total = r->type.ct.payload_size;
997 buffer = r->type.ct.payload;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200998 buflen = min(total, ZFCP_DBF_CT_PAYLOAD);
Martin Peschkeb634fff2008-03-31 11:15:24 +0200999 } else if (strncmp(r->tag, "rctc", ZFCP_DBF_TAG_SIZE) == 0) {
1000 zfcp_dbf_out(&p, "cmd_rsp_code", "0x%04x",
1001 r->type.ct.type.response.cmd_rsp_code);
1002 zfcp_dbf_out(&p, "revision", "0x%02x",
1003 r->type.ct.type.response.revision);
1004 zfcp_dbf_out(&p, "reason_code", "0x%02x",
1005 r->type.ct.type.response.reason_code);
1006 zfcp_dbf_out(&p, "reason_code_expl", "0x%02x",
1007 r->type.ct.type.response.reason_code_expl);
1008 zfcp_dbf_out(&p, "vendor_unique", "0x%02x",
1009 r->type.ct.type.response.vendor_unique);
1010 total = r->type.ct.payload_size;
1011 buffer = r->type.ct.payload;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001012 buflen = min(total, ZFCP_DBF_CT_PAYLOAD);
Martin Peschkeb634fff2008-03-31 11:15:24 +02001013 } else if (strncmp(r->tag, "oels", ZFCP_DBF_TAG_SIZE) == 0 ||
1014 strncmp(r->tag, "rels", ZFCP_DBF_TAG_SIZE) == 0 ||
1015 strncmp(r->tag, "iels", ZFCP_DBF_TAG_SIZE) == 0) {
1016 zfcp_dbf_out(&p, "ls_code", "0x%02x", r->type.els.ls_code);
1017 total = r->type.els.payload_size;
1018 buffer = r->type.els.payload;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001019 buflen = min(total, ZFCP_DBF_ELS_PAYLOAD);
1020 }
1021
Martin Peschkedf29f4a2008-03-31 11:15:26 +02001022 zfcp_dbf_outd(&p, "payload", buffer, buflen, 0, total);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001023 if (buflen == total)
Martin Peschkeb634fff2008-03-31 11:15:24 +02001024 p += sprintf(p, "\n");
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001025
Martin Peschkeb634fff2008-03-31 11:15:24 +02001026 return p - out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001027}
1028
Heiko Carstens2b67fc42007-02-05 21:16:47 +01001029static struct debug_view zfcp_san_dbf_view = {
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001030 "structured",
1031 NULL,
1032 &zfcp_dbf_view_header,
1033 &zfcp_san_dbf_view_format,
1034 NULL,
1035 NULL
1036};
1037
Heiko Carstens4d284ca2007-02-05 21:18:53 +01001038static void
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001039_zfcp_scsi_dbf_event_common(const char *tag, const char *tag2, int level,
1040 struct zfcp_adapter *adapter,
1041 struct scsi_cmnd *scsi_cmnd,
Maxim Shchetynined829ad2006-02-11 01:42:58 +01001042 struct zfcp_fsf_req *fsf_req,
Andreas Herrmann4eff4a32006-09-18 22:29:20 +02001043 unsigned long old_req_id)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001044{
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001045 struct zfcp_scsi_dbf_record *rec = &adapter->scsi_dbf_buf;
1046 struct zfcp_dbf_dump *dump = (struct zfcp_dbf_dump *)rec;
1047 unsigned long flags;
1048 struct fcp_rsp_iu *fcp_rsp;
1049 char *fcp_rsp_info = NULL, *fcp_sns_info = NULL;
1050 int offset = 0, buflen = 0;
1051
1052 spin_lock_irqsave(&adapter->scsi_dbf_lock, flags);
1053 do {
1054 memset(rec, 0, sizeof(struct zfcp_scsi_dbf_record));
1055 if (offset == 0) {
1056 strncpy(rec->tag, tag, ZFCP_DBF_TAG_SIZE);
1057 strncpy(rec->tag2, tag2, ZFCP_DBF_TAG_SIZE);
Maxim Shchetynined829ad2006-02-11 01:42:58 +01001058 if (scsi_cmnd != NULL) {
1059 if (scsi_cmnd->device) {
1060 rec->scsi_id = scsi_cmnd->device->id;
1061 rec->scsi_lun = scsi_cmnd->device->lun;
1062 }
1063 rec->scsi_result = scsi_cmnd->result;
1064 rec->scsi_cmnd = (unsigned long)scsi_cmnd;
1065 rec->scsi_serial = scsi_cmnd->serial_number;
1066 memcpy(rec->scsi_opcode, &scsi_cmnd->cmnd,
1067 min((int)scsi_cmnd->cmd_len,
1068 ZFCP_DBF_SCSI_OPCODE));
1069 rec->scsi_retries = scsi_cmnd->retries;
1070 rec->scsi_allowed = scsi_cmnd->allowed;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001071 }
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001072 if (fsf_req != NULL) {
1073 fcp_rsp = (struct fcp_rsp_iu *)
1074 &(fsf_req->qtcb->bottom.io.fcp_rsp);
1075 fcp_rsp_info =
1076 zfcp_get_fcp_rsp_info_ptr(fcp_rsp);
1077 fcp_sns_info =
1078 zfcp_get_fcp_sns_info_ptr(fcp_rsp);
1079
1080 rec->type.fcp.rsp_validity =
1081 fcp_rsp->validity.value;
1082 rec->type.fcp.rsp_scsi_status =
1083 fcp_rsp->scsi_status;
1084 rec->type.fcp.rsp_resid = fcp_rsp->fcp_resid;
1085 if (fcp_rsp->validity.bits.fcp_rsp_len_valid)
1086 rec->type.fcp.rsp_code =
1087 *(fcp_rsp_info + 3);
1088 if (fcp_rsp->validity.bits.fcp_sns_len_valid) {
1089 buflen = min((int)fcp_rsp->fcp_sns_len,
1090 ZFCP_DBF_SCSI_MAX_FCP_SNS_INFO);
1091 rec->type.fcp.sns_info_len = buflen;
1092 memcpy(rec->type.fcp.sns_info,
1093 fcp_sns_info,
1094 min(buflen,
1095 ZFCP_DBF_SCSI_FCP_SNS_INFO));
1096 offset += min(buflen,
1097 ZFCP_DBF_SCSI_FCP_SNS_INFO);
1098 }
1099
1100 rec->fsf_reqid = (unsigned long)fsf_req;
1101 rec->fsf_seqno = fsf_req->seq_no;
1102 rec->fsf_issued = fsf_req->issued;
1103 }
Andreas Herrmann4eff4a32006-09-18 22:29:20 +02001104 rec->type.old_fsf_reqid = old_req_id;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001105 } else {
1106 strncpy(dump->tag, "dump", ZFCP_DBF_TAG_SIZE);
1107 dump->total_size = buflen;
1108 dump->offset = offset;
1109 dump->size = min(buflen - offset,
1110 (int)sizeof(struct
1111 zfcp_scsi_dbf_record) -
1112 (int)sizeof(struct zfcp_dbf_dump));
1113 memcpy(dump->data, fcp_sns_info + offset, dump->size);
1114 offset += dump->size;
1115 }
1116 debug_event(adapter->scsi_dbf, level,
1117 rec, sizeof(struct zfcp_scsi_dbf_record));
1118 } while (offset < buflen);
1119 spin_unlock_irqrestore(&adapter->scsi_dbf_lock, flags);
1120}
1121
Heiko Carstens4d284ca2007-02-05 21:18:53 +01001122void
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001123zfcp_scsi_dbf_event_result(const char *tag, int level,
1124 struct zfcp_adapter *adapter,
Maxim Shchetynined829ad2006-02-11 01:42:58 +01001125 struct scsi_cmnd *scsi_cmnd,
1126 struct zfcp_fsf_req *fsf_req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001127{
Maxim Shchetynined829ad2006-02-11 01:42:58 +01001128 _zfcp_scsi_dbf_event_common("rslt", tag, level,
Andreas Herrmann4eff4a32006-09-18 22:29:20 +02001129 adapter, scsi_cmnd, fsf_req, 0);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001130}
1131
Heiko Carstens4d284ca2007-02-05 21:18:53 +01001132void
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001133zfcp_scsi_dbf_event_abort(const char *tag, struct zfcp_adapter *adapter,
1134 struct scsi_cmnd *scsi_cmnd,
Maxim Shchetynined829ad2006-02-11 01:42:58 +01001135 struct zfcp_fsf_req *new_fsf_req,
Andreas Herrmann4eff4a32006-09-18 22:29:20 +02001136 unsigned long old_req_id)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001137{
Maxim Shchetynined829ad2006-02-11 01:42:58 +01001138 _zfcp_scsi_dbf_event_common("abrt", tag, 1,
Andreas Herrmann4eff4a32006-09-18 22:29:20 +02001139 adapter, scsi_cmnd, new_fsf_req, old_req_id);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001140}
1141
Heiko Carstens4d284ca2007-02-05 21:18:53 +01001142void
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001143zfcp_scsi_dbf_event_devreset(const char *tag, u8 flag, struct zfcp_unit *unit,
1144 struct scsi_cmnd *scsi_cmnd)
1145{
1146 struct zfcp_adapter *adapter = unit->port->adapter;
1147
1148 _zfcp_scsi_dbf_event_common(flag == FCP_TARGET_RESET ? "trst" : "lrst",
Andreas Herrmann4eff4a32006-09-18 22:29:20 +02001149 tag, 1, adapter, scsi_cmnd, NULL, 0);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001150}
1151
1152static int
1153zfcp_scsi_dbf_view_format(debug_info_t * id, struct debug_view *view,
1154 char *out_buf, const char *in_buf)
1155{
Martin Peschkeb634fff2008-03-31 11:15:24 +02001156 struct zfcp_scsi_dbf_record *r = (struct zfcp_scsi_dbf_record *)in_buf;
Martin Peschke8fc5af12008-03-31 11:15:23 +02001157 struct timespec t;
Martin Peschkeb634fff2008-03-31 11:15:24 +02001158 char *p = out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001159
Martin Peschkeb634fff2008-03-31 11:15:24 +02001160 if (strncmp(r->tag, "dump", ZFCP_DBF_TAG_SIZE) == 0)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001161 return 0;
1162
Martin Peschkeb634fff2008-03-31 11:15:24 +02001163 p += zfcp_dbf_tag(p, "tag", r->tag);
1164 p += zfcp_dbf_tag(p, "tag2", r->tag2);
1165 zfcp_dbf_out(&p, "scsi_id", "0x%08x", r->scsi_id);
1166 zfcp_dbf_out(&p, "scsi_lun", "0x%08x", r->scsi_lun);
1167 zfcp_dbf_out(&p, "scsi_result", "0x%08x", r->scsi_result);
1168 zfcp_dbf_out(&p, "scsi_cmnd", "0x%0Lx", r->scsi_cmnd);
1169 zfcp_dbf_out(&p, "scsi_serial", "0x%016Lx", r->scsi_serial);
Martin Peschkedf29f4a2008-03-31 11:15:26 +02001170 zfcp_dbf_outd(&p, "scsi_opcode", r->scsi_opcode, ZFCP_DBF_SCSI_OPCODE,
1171 0, ZFCP_DBF_SCSI_OPCODE);
Martin Peschkeb634fff2008-03-31 11:15:24 +02001172 zfcp_dbf_out(&p, "scsi_retries", "0x%02x", r->scsi_retries);
1173 zfcp_dbf_out(&p, "scsi_allowed", "0x%02x", r->scsi_allowed);
1174 if (strncmp(r->tag, "abrt", ZFCP_DBF_TAG_SIZE) == 0)
1175 zfcp_dbf_out(&p, "old_fsf_reqid", "0x%0Lx",
1176 r->type.old_fsf_reqid);
1177 zfcp_dbf_out(&p, "fsf_reqid", "0x%0Lx", r->fsf_reqid);
1178 zfcp_dbf_out(&p, "fsf_seqno", "0x%08x", r->fsf_seqno);
1179 zfcp_dbf_timestamp(r->fsf_issued, &t);
1180 zfcp_dbf_out(&p, "fsf_issued", "%011lu:%06lu", t.tv_sec, t.tv_nsec);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001181
Martin Peschkeb634fff2008-03-31 11:15:24 +02001182 if (strncmp(r->tag, "rslt", ZFCP_DBF_TAG_SIZE) == 0) {
1183 zfcp_dbf_out(&p, "fcp_rsp_validity", "0x%02x",
1184 r->type.fcp.rsp_validity);
1185 zfcp_dbf_out(&p, "fcp_rsp_scsi_status",
1186 "0x%02x", r->type.fcp.rsp_scsi_status);
1187 zfcp_dbf_out(&p, "fcp_rsp_resid", "0x%08x",
1188 r->type.fcp.rsp_resid);
1189 zfcp_dbf_out(&p, "fcp_rsp_code", "0x%08x",
1190 r->type.fcp.rsp_code);
1191 zfcp_dbf_out(&p, "fcp_sns_info_len", "0x%08x",
1192 r->type.fcp.sns_info_len);
Martin Peschkedf29f4a2008-03-31 11:15:26 +02001193 zfcp_dbf_outd(&p, "fcp_sns_info", r->type.fcp.sns_info,
1194 min((int)r->type.fcp.sns_info_len,
1195 ZFCP_DBF_SCSI_FCP_SNS_INFO), 0,
1196 r->type.fcp.sns_info_len);
Martin Peschkeb634fff2008-03-31 11:15:24 +02001197 }
1198 p += sprintf(p, "\n");
1199 return p - out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001200}
1201
Heiko Carstens2b67fc42007-02-05 21:16:47 +01001202static struct debug_view zfcp_scsi_dbf_view = {
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001203 "structured",
1204 NULL,
1205 &zfcp_dbf_view_header,
1206 &zfcp_scsi_dbf_view_format,
1207 NULL,
1208 NULL
1209};
1210
1211/**
1212 * zfcp_adapter_debug_register - registers debug feature for an adapter
1213 * @adapter: pointer to adapter for which debug features should be registered
1214 * return: -ENOMEM on error, 0 otherwise
1215 */
1216int zfcp_adapter_debug_register(struct zfcp_adapter *adapter)
1217{
1218 char dbf_name[DEBUG_MAX_NAME_LEN];
1219
1220 /* debug feature area which records recovery activity */
Martin Peschked79a83d2008-03-27 14:22:00 +01001221 sprintf(dbf_name, "zfcp_%s_rec", zfcp_get_busid_by_adapter(adapter));
1222 adapter->rec_dbf = debug_register(dbf_name, dbfsize, 1,
1223 sizeof(struct zfcp_rec_dbf_record));
1224 if (!adapter->rec_dbf)
1225 goto failed;
1226 debug_register_view(adapter->rec_dbf, &debug_hex_ascii_view);
1227 debug_register_view(adapter->rec_dbf, &zfcp_rec_dbf_view);
1228 debug_set_level(adapter->rec_dbf, 3);
1229
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001230 /* debug feature area which records HBA (FSF and QDIO) conditions */
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001231 sprintf(dbf_name, "zfcp_%s_hba", zfcp_get_busid_by_adapter(adapter));
1232 adapter->hba_dbf = debug_register(dbf_name, dbfsize, 1,
1233 sizeof(struct zfcp_hba_dbf_record));
1234 if (!adapter->hba_dbf)
1235 goto failed;
1236 debug_register_view(adapter->hba_dbf, &debug_hex_ascii_view);
1237 debug_register_view(adapter->hba_dbf, &zfcp_hba_dbf_view);
1238 debug_set_level(adapter->hba_dbf, 3);
1239
1240 /* debug feature area which records SAN command failures and recovery */
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001241 sprintf(dbf_name, "zfcp_%s_san", zfcp_get_busid_by_adapter(adapter));
1242 adapter->san_dbf = debug_register(dbf_name, dbfsize, 1,
1243 sizeof(struct zfcp_san_dbf_record));
1244 if (!adapter->san_dbf)
1245 goto failed;
1246 debug_register_view(adapter->san_dbf, &debug_hex_ascii_view);
1247 debug_register_view(adapter->san_dbf, &zfcp_san_dbf_view);
1248 debug_set_level(adapter->san_dbf, 6);
1249
1250 /* debug feature area which records SCSI command failures and recovery */
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001251 sprintf(dbf_name, "zfcp_%s_scsi", zfcp_get_busid_by_adapter(adapter));
1252 adapter->scsi_dbf = debug_register(dbf_name, dbfsize, 1,
1253 sizeof(struct zfcp_scsi_dbf_record));
1254 if (!adapter->scsi_dbf)
1255 goto failed;
1256 debug_register_view(adapter->scsi_dbf, &debug_hex_ascii_view);
1257 debug_register_view(adapter->scsi_dbf, &zfcp_scsi_dbf_view);
1258 debug_set_level(adapter->scsi_dbf, 3);
1259
1260 return 0;
1261
1262 failed:
1263 zfcp_adapter_debug_unregister(adapter);
1264
1265 return -ENOMEM;
1266}
1267
1268/**
1269 * zfcp_adapter_debug_unregister - unregisters debug feature for an adapter
1270 * @adapter: pointer to adapter for which debug features should be unregistered
1271 */
1272void zfcp_adapter_debug_unregister(struct zfcp_adapter *adapter)
1273{
1274 debug_unregister(adapter->scsi_dbf);
1275 debug_unregister(adapter->san_dbf);
1276 debug_unregister(adapter->hba_dbf);
Martin Peschked79a83d2008-03-27 14:22:00 +01001277 debug_unregister(adapter->rec_dbf);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001278 adapter->scsi_dbf = NULL;
1279 adapter->san_dbf = NULL;
1280 adapter->hba_dbf = NULL;
Martin Peschked79a83d2008-03-27 14:22:00 +01001281 adapter->rec_dbf = NULL;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001282}
1283
1284#undef ZFCP_LOG_AREA