blob: 0ab985c037fe5b457dec676bfade2ebe14584918 [file] [log] [blame]
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001/*
Andreas Herrmann4a9d2d82006-05-22 18:14:08 +02002 * This file is part of the zfcp device driver for
3 * FCP adapters for IBM System z9 and zSeries.
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004 *
Andreas Herrmann4a9d2d82006-05-22 18:14:08 +02005 * (C) Copyright IBM Corp. 2002, 2006
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02006 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
10 * any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020022#include <linux/ctype.h>
Heiko Carstens364c8552007-10-12 16:11:35 +020023#include <asm/debug.h>
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020024#include "zfcp_ext.h"
25
26static u32 dbfsize = 4;
27
28module_param(dbfsize, uint, 0400);
29MODULE_PARM_DESC(dbfsize,
30 "number of pages for each debug feature area (default 4)");
31
32#define ZFCP_LOG_AREA ZFCP_LOG_AREA_OTHER
33
Martin Peschkec15450e2008-03-27 14:21:55 +010034static void zfcp_dbf_hexdump(debug_info_t *dbf, void *to, int to_len,
35 int level, char *from, int from_len)
36{
37 int offset;
38 struct zfcp_dbf_dump *dump = to;
39 int room = to_len - sizeof(*dump);
40
41 for (offset = 0; offset < from_len; offset += dump->size) {
42 memset(to, 0, to_len);
43 strncpy(dump->tag, "dump", ZFCP_DBF_TAG_SIZE);
44 dump->total_size = from_len;
45 dump->offset = offset;
46 dump->size = min(from_len - offset, room);
47 memcpy(dump->data, from + offset, dump->size);
48 debug_event(dbf, level, dump, dump->size);
49 }
50}
51
Martin Peschke8fc5af12008-03-31 11:15:23 +020052/* FIXME: this duplicate this code in s390 debug feature */
53static void zfcp_dbf_timestamp(unsigned long long stck, struct timespec *time)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020054{
55 unsigned long long sec;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020056
57 stck -= 0x8126d60e46000000LL - (0x3c26700LL * 1000000 * 4096);
58 sec = stck >> 12;
59 do_div(sec, 1000000);
Martin Peschke8fc5af12008-03-31 11:15:23 +020060 time->tv_sec = sec;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020061 stck -= (sec * 1000000) << 12;
Martin Peschke8fc5af12008-03-31 11:15:23 +020062 time->tv_nsec = ((stck * 1000) >> 12);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020063}
64
Martin Peschkea9c85772008-03-31 11:15:27 +020065static void zfcp_dbf_tag(char **p, const char *label, const char *tag)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020066{
Martin Peschkea9c85772008-03-31 11:15:27 +020067 int i;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020068
Martin Peschkea9c85772008-03-31 11:15:27 +020069 *p += sprintf(*p, "%-24s", label);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020070 for (i = 0; i < ZFCP_DBF_TAG_SIZE; i++)
Martin Peschkea9c85772008-03-31 11:15:27 +020071 *p += sprintf(*p, "%c", tag[i]);
72 *p += sprintf(*p, "\n");
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020073}
74
Martin Peschke10223c62008-03-27 14:21:59 +010075static void zfcp_dbf_outs(char **buf, const char *s1, const char *s2)
76{
77 *buf += sprintf(*buf, "%-24s%s\n", s1, s2);
78}
79
80static void zfcp_dbf_out(char **buf, const char *s, const char *format, ...)
81{
82 va_list arg;
83
84 *buf += sprintf(*buf, "%-24s", s);
85 va_start(arg, format);
86 *buf += vsprintf(*buf, format, arg);
87 va_end(arg);
88 *buf += sprintf(*buf, "\n");
89}
90
Martin Peschkedf29f4a2008-03-31 11:15:26 +020091static void zfcp_dbf_outd(char **p, const char *label, char *buffer,
92 int buflen, int offset, int total_size)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020093{
Martin Peschkedf29f4a2008-03-31 11:15:26 +020094 if (!offset)
95 *p += sprintf(*p, "%-24s ", label);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020096 while (buflen--) {
97 if (offset > 0) {
98 if ((offset % 32) == 0)
Martin Peschkedf29f4a2008-03-31 11:15:26 +020099 *p += sprintf(*p, "\n%-24c ", ' ');
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200100 else if ((offset % 4) == 0)
Martin Peschkedf29f4a2008-03-31 11:15:26 +0200101 *p += sprintf(*p, " ");
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200102 }
Martin Peschkedf29f4a2008-03-31 11:15:26 +0200103 *p += sprintf(*p, "%02x", *buffer++);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200104 if (++offset == total_size) {
Martin Peschkedf29f4a2008-03-31 11:15:26 +0200105 *p += sprintf(*p, "\n");
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200106 break;
107 }
108 }
Martin Peschkedf29f4a2008-03-31 11:15:26 +0200109 if (!total_size)
110 *p += sprintf(*p, "\n");
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200111}
112
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100113static int
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200114zfcp_dbf_view_header(debug_info_t * id, struct debug_view *view, int area,
115 debug_entry_t * entry, char *out_buf)
116{
117 struct zfcp_dbf_dump *dump = (struct zfcp_dbf_dump *)DEBUG_DATA(entry);
Martin Peschke8fc5af12008-03-31 11:15:23 +0200118 struct timespec t;
Martin Peschkeb634fff2008-03-31 11:15:24 +0200119 char *p = out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200120
121 if (strncmp(dump->tag, "dump", ZFCP_DBF_TAG_SIZE) != 0) {
Martin Peschke8fc5af12008-03-31 11:15:23 +0200122 zfcp_dbf_timestamp(entry->id.stck, &t);
Martin Peschkeb634fff2008-03-31 11:15:24 +0200123 zfcp_dbf_out(&p, "timestamp", "%011lu:%06lu",
124 t.tv_sec, t.tv_nsec);
125 zfcp_dbf_out(&p, "cpu", "%02i", entry->id.fields.cpuid);
126 } else {
Martin Peschkedf29f4a2008-03-31 11:15:26 +0200127 zfcp_dbf_outd(&p, NULL, dump->data, dump->size, dump->offset,
128 dump->total_size);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200129 if ((dump->offset + dump->size) == dump->total_size)
Martin Peschkeb634fff2008-03-31 11:15:24 +0200130 p += sprintf(p, "\n");
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200131 }
Martin Peschkeb634fff2008-03-31 11:15:24 +0200132 return p - out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200133}
134
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100135void zfcp_hba_dbf_event_fsf_response(struct zfcp_fsf_req *fsf_req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200136{
137 struct zfcp_adapter *adapter = fsf_req->adapter;
138 struct fsf_qtcb *qtcb = fsf_req->qtcb;
139 union fsf_prot_status_qual *prot_status_qual =
140 &qtcb->prefix.prot_status_qual;
141 union fsf_status_qual *fsf_status_qual = &qtcb->header.fsf_status_qual;
142 struct scsi_cmnd *scsi_cmnd;
143 struct zfcp_port *port;
144 struct zfcp_unit *unit;
145 struct zfcp_send_els *send_els;
146 struct zfcp_hba_dbf_record *rec = &adapter->hba_dbf_buf;
147 struct zfcp_hba_dbf_record_response *response = &rec->type.response;
148 int level;
149 unsigned long flags;
150
151 spin_lock_irqsave(&adapter->hba_dbf_lock, flags);
152 memset(rec, 0, sizeof(struct zfcp_hba_dbf_record));
153 strncpy(rec->tag, "resp", ZFCP_DBF_TAG_SIZE);
154
155 if ((qtcb->prefix.prot_status != FSF_PROT_GOOD) &&
156 (qtcb->prefix.prot_status != FSF_PROT_FSF_STATUS_PRESENTED)) {
157 strncpy(rec->tag2, "perr", ZFCP_DBF_TAG_SIZE);
158 level = 1;
159 } else if (qtcb->header.fsf_status != FSF_GOOD) {
160 strncpy(rec->tag2, "ferr", ZFCP_DBF_TAG_SIZE);
161 level = 1;
162 } else if ((fsf_req->fsf_command == FSF_QTCB_OPEN_PORT_WITH_DID) ||
163 (fsf_req->fsf_command == FSF_QTCB_OPEN_LUN)) {
164 strncpy(rec->tag2, "open", ZFCP_DBF_TAG_SIZE);
165 level = 4;
Martin Peschkeb75db732008-03-27 14:21:58 +0100166 } else if (qtcb->header.log_length) {
167 strncpy(rec->tag2, "qtcb", ZFCP_DBF_TAG_SIZE);
168 level = 5;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200169 } else {
170 strncpy(rec->tag2, "norm", ZFCP_DBF_TAG_SIZE);
171 level = 6;
172 }
173
174 response->fsf_command = fsf_req->fsf_command;
175 response->fsf_reqid = (unsigned long)fsf_req;
176 response->fsf_seqno = fsf_req->seq_no;
177 response->fsf_issued = fsf_req->issued;
178 response->fsf_prot_status = qtcb->prefix.prot_status;
179 response->fsf_status = qtcb->header.fsf_status;
180 memcpy(response->fsf_prot_status_qual,
181 prot_status_qual, FSF_PROT_STATUS_QUAL_SIZE);
182 memcpy(response->fsf_status_qual,
183 fsf_status_qual, FSF_STATUS_QUALIFIER_SIZE);
184 response->fsf_req_status = fsf_req->status;
185 response->sbal_first = fsf_req->sbal_first;
186 response->sbal_curr = fsf_req->sbal_curr;
187 response->sbal_last = fsf_req->sbal_last;
188 response->pool = fsf_req->pool != NULL;
189 response->erp_action = (unsigned long)fsf_req->erp_action;
190
191 switch (fsf_req->fsf_command) {
192 case FSF_QTCB_FCP_CMND:
193 if (fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT)
194 break;
195 scsi_cmnd = (struct scsi_cmnd *)fsf_req->data;
196 if (scsi_cmnd != NULL) {
197 response->data.send_fcp.scsi_cmnd
198 = (unsigned long)scsi_cmnd;
199 response->data.send_fcp.scsi_serial
200 = scsi_cmnd->serial_number;
201 }
202 break;
203
204 case FSF_QTCB_OPEN_PORT_WITH_DID:
205 case FSF_QTCB_CLOSE_PORT:
206 case FSF_QTCB_CLOSE_PHYSICAL_PORT:
207 port = (struct zfcp_port *)fsf_req->data;
208 response->data.port.wwpn = port->wwpn;
209 response->data.port.d_id = port->d_id;
210 response->data.port.port_handle = qtcb->header.port_handle;
211 break;
212
213 case FSF_QTCB_OPEN_LUN:
214 case FSF_QTCB_CLOSE_LUN:
215 unit = (struct zfcp_unit *)fsf_req->data;
216 port = unit->port;
217 response->data.unit.wwpn = port->wwpn;
218 response->data.unit.fcp_lun = unit->fcp_lun;
219 response->data.unit.port_handle = qtcb->header.port_handle;
220 response->data.unit.lun_handle = qtcb->header.lun_handle;
221 break;
222
223 case FSF_QTCB_SEND_ELS:
224 send_els = (struct zfcp_send_els *)fsf_req->data;
225 response->data.send_els.d_id = qtcb->bottom.support.d_id;
226 response->data.send_els.ls_code = send_els->ls_code >> 24;
227 break;
228
229 case FSF_QTCB_ABORT_FCP_CMND:
230 case FSF_QTCB_SEND_GENERIC:
231 case FSF_QTCB_EXCHANGE_CONFIG_DATA:
232 case FSF_QTCB_EXCHANGE_PORT_DATA:
233 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
234 case FSF_QTCB_UPLOAD_CONTROL_FILE:
235 break;
236 }
237
238 debug_event(adapter->hba_dbf, level,
239 rec, sizeof(struct zfcp_hba_dbf_record));
Martin Peschkeb75db732008-03-27 14:21:58 +0100240
241 /* have fcp channel microcode fixed to use as little as possible */
242 if (fsf_req->fsf_command != FSF_QTCB_FCP_CMND) {
243 /* adjust length skipping trailing zeros */
244 char *buf = (char *)qtcb + qtcb->header.log_start;
245 int len = qtcb->header.log_length;
246 for (; len && !buf[len - 1]; len--);
247 zfcp_dbf_hexdump(adapter->hba_dbf, rec, sizeof(*rec), level,
248 buf, len);
249 }
250
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200251 spin_unlock_irqrestore(&adapter->hba_dbf_lock, flags);
252}
253
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100254void
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200255zfcp_hba_dbf_event_fsf_unsol(const char *tag, struct zfcp_adapter *adapter,
256 struct fsf_status_read_buffer *status_buffer)
257{
258 struct zfcp_hba_dbf_record *rec = &adapter->hba_dbf_buf;
259 unsigned long flags;
260
261 spin_lock_irqsave(&adapter->hba_dbf_lock, flags);
262 memset(rec, 0, sizeof(struct zfcp_hba_dbf_record));
263 strncpy(rec->tag, "stat", ZFCP_DBF_TAG_SIZE);
264 strncpy(rec->tag2, tag, ZFCP_DBF_TAG_SIZE);
265
266 rec->type.status.failed = adapter->status_read_failed;
267 if (status_buffer != NULL) {
268 rec->type.status.status_type = status_buffer->status_type;
269 rec->type.status.status_subtype = status_buffer->status_subtype;
270 memcpy(&rec->type.status.queue_designator,
271 &status_buffer->queue_designator,
272 sizeof(struct fsf_queue_designator));
273
274 switch (status_buffer->status_type) {
275 case FSF_STATUS_READ_SENSE_DATA_AVAIL:
276 rec->type.status.payload_size =
277 ZFCP_DBF_UNSOL_PAYLOAD_SENSE_DATA_AVAIL;
278 break;
279
280 case FSF_STATUS_READ_BIT_ERROR_THRESHOLD:
281 rec->type.status.payload_size =
282 ZFCP_DBF_UNSOL_PAYLOAD_BIT_ERROR_THRESHOLD;
283 break;
284
285 case FSF_STATUS_READ_LINK_DOWN:
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200286 switch (status_buffer->status_subtype) {
287 case FSF_STATUS_READ_SUB_NO_PHYSICAL_LINK:
288 case FSF_STATUS_READ_SUB_FDISC_FAILED:
289 rec->type.status.payload_size =
290 sizeof(struct fsf_link_down_info);
291 }
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200292 break;
293
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200294 case FSF_STATUS_READ_FEATURE_UPDATE_ALERT:
295 rec->type.status.payload_size =
296 ZFCP_DBF_UNSOL_PAYLOAD_FEATURE_UPDATE_ALERT;
297 break;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200298 }
299 memcpy(&rec->type.status.payload,
300 &status_buffer->payload, rec->type.status.payload_size);
301 }
302
303 debug_event(adapter->hba_dbf, 2,
304 rec, sizeof(struct zfcp_hba_dbf_record));
305 spin_unlock_irqrestore(&adapter->hba_dbf_lock, flags);
306}
307
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100308void
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200309zfcp_hba_dbf_event_qdio(struct zfcp_adapter *adapter, unsigned int status,
310 unsigned int qdio_error, unsigned int siga_error,
311 int sbal_index, int sbal_count)
312{
313 struct zfcp_hba_dbf_record *rec = &adapter->hba_dbf_buf;
314 unsigned long flags;
315
316 spin_lock_irqsave(&adapter->hba_dbf_lock, flags);
317 memset(rec, 0, sizeof(struct zfcp_hba_dbf_record));
318 strncpy(rec->tag, "qdio", ZFCP_DBF_TAG_SIZE);
319 rec->type.qdio.status = status;
320 rec->type.qdio.qdio_error = qdio_error;
321 rec->type.qdio.siga_error = siga_error;
322 rec->type.qdio.sbal_index = sbal_index;
323 rec->type.qdio.sbal_count = sbal_count;
324 debug_event(adapter->hba_dbf, 0,
325 rec, sizeof(struct zfcp_hba_dbf_record));
326 spin_unlock_irqrestore(&adapter->hba_dbf_lock, flags);
327}
328
Martin Peschkea9c85772008-03-31 11:15:27 +0200329static void zfcp_hba_dbf_view_response(char **p,
330 struct zfcp_hba_dbf_record_response *r)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200331{
Martin Peschke8fc5af12008-03-31 11:15:23 +0200332 struct timespec t;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200333
Martin Peschkea9c85772008-03-31 11:15:27 +0200334 zfcp_dbf_out(p, "fsf_command", "0x%08x", r->fsf_command);
335 zfcp_dbf_out(p, "fsf_reqid", "0x%0Lx", r->fsf_reqid);
336 zfcp_dbf_out(p, "fsf_seqno", "0x%08x", r->fsf_seqno);
Martin Peschkeb634fff2008-03-31 11:15:24 +0200337 zfcp_dbf_timestamp(r->fsf_issued, &t);
Martin Peschkea9c85772008-03-31 11:15:27 +0200338 zfcp_dbf_out(p, "fsf_issued", "%011lu:%06lu", t.tv_sec, t.tv_nsec);
339 zfcp_dbf_out(p, "fsf_prot_status", "0x%08x", r->fsf_prot_status);
340 zfcp_dbf_out(p, "fsf_status", "0x%08x", r->fsf_status);
341 zfcp_dbf_outd(p, "fsf_prot_status_qual", r->fsf_prot_status_qual,
Martin Peschkedf29f4a2008-03-31 11:15:26 +0200342 FSF_PROT_STATUS_QUAL_SIZE, 0, FSF_PROT_STATUS_QUAL_SIZE);
Martin Peschkea9c85772008-03-31 11:15:27 +0200343 zfcp_dbf_outd(p, "fsf_status_qual", r->fsf_status_qual,
Martin Peschkedf29f4a2008-03-31 11:15:26 +0200344 FSF_STATUS_QUALIFIER_SIZE, 0, FSF_STATUS_QUALIFIER_SIZE);
Martin Peschkea9c85772008-03-31 11:15:27 +0200345 zfcp_dbf_out(p, "fsf_req_status", "0x%08x", r->fsf_req_status);
346 zfcp_dbf_out(p, "sbal_first", "0x%02x", r->sbal_first);
347 zfcp_dbf_out(p, "sbal_curr", "0x%02x", r->sbal_curr);
348 zfcp_dbf_out(p, "sbal_last", "0x%02x", r->sbal_last);
349 zfcp_dbf_out(p, "pool", "0x%02x", r->pool);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200350
Martin Peschkeb634fff2008-03-31 11:15:24 +0200351 switch (r->fsf_command) {
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200352 case FSF_QTCB_FCP_CMND:
Martin Peschkeb634fff2008-03-31 11:15:24 +0200353 if (r->fsf_req_status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200354 break;
Martin Peschkea9c85772008-03-31 11:15:27 +0200355 zfcp_dbf_out(p, "scsi_cmnd", "0x%0Lx",
Martin Peschkeb634fff2008-03-31 11:15:24 +0200356 r->data.send_fcp.scsi_cmnd);
Martin Peschkea9c85772008-03-31 11:15:27 +0200357 zfcp_dbf_out(p, "scsi_serial", "0x%016Lx",
Martin Peschkeb634fff2008-03-31 11:15:24 +0200358 r->data.send_fcp.scsi_serial);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200359 break;
360
361 case FSF_QTCB_OPEN_PORT_WITH_DID:
362 case FSF_QTCB_CLOSE_PORT:
363 case FSF_QTCB_CLOSE_PHYSICAL_PORT:
Martin Peschkea9c85772008-03-31 11:15:27 +0200364 zfcp_dbf_out(p, "wwpn", "0x%016Lx", r->data.port.wwpn);
365 zfcp_dbf_out(p, "d_id", "0x%06x", r->data.port.d_id);
366 zfcp_dbf_out(p, "port_handle", "0x%08x",
Martin Peschkeb634fff2008-03-31 11:15:24 +0200367 r->data.port.port_handle);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200368 break;
369
370 case FSF_QTCB_OPEN_LUN:
371 case FSF_QTCB_CLOSE_LUN:
Martin Peschkea9c85772008-03-31 11:15:27 +0200372 zfcp_dbf_out(p, "wwpn", "0x%016Lx", r->data.unit.wwpn);
373 zfcp_dbf_out(p, "fcp_lun", "0x%016Lx", r->data.unit.fcp_lun);
374 zfcp_dbf_out(p, "port_handle", "0x%08x",
Martin Peschkeb634fff2008-03-31 11:15:24 +0200375 r->data.unit.port_handle);
Martin Peschkea9c85772008-03-31 11:15:27 +0200376 zfcp_dbf_out(p, "lun_handle", "0x%08x",
Martin Peschkeb634fff2008-03-31 11:15:24 +0200377 r->data.unit.lun_handle);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200378 break;
379
380 case FSF_QTCB_SEND_ELS:
Martin Peschkea9c85772008-03-31 11:15:27 +0200381 zfcp_dbf_out(p, "d_id", "0x%06x", r->data.send_els.d_id);
382 zfcp_dbf_out(p, "ls_code", "0x%02x", r->data.send_els.ls_code);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200383 break;
384
385 case FSF_QTCB_ABORT_FCP_CMND:
386 case FSF_QTCB_SEND_GENERIC:
387 case FSF_QTCB_EXCHANGE_CONFIG_DATA:
388 case FSF_QTCB_EXCHANGE_PORT_DATA:
389 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
390 case FSF_QTCB_UPLOAD_CONTROL_FILE:
391 break;
392 }
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200393}
394
Martin Peschkea9c85772008-03-31 11:15:27 +0200395static void zfcp_hba_dbf_view_status(char **p,
396 struct zfcp_hba_dbf_record_status *r)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200397{
Martin Peschkea9c85772008-03-31 11:15:27 +0200398 zfcp_dbf_out(p, "failed", "0x%02x", r->failed);
399 zfcp_dbf_out(p, "status_type", "0x%08x", r->status_type);
400 zfcp_dbf_out(p, "status_subtype", "0x%08x", r->status_subtype);
401 zfcp_dbf_outd(p, "queue_designator", (char *)&r->queue_designator,
Martin Peschkedf29f4a2008-03-31 11:15:26 +0200402 sizeof(struct fsf_queue_designator), 0,
403 sizeof(struct fsf_queue_designator));
Martin Peschkea9c85772008-03-31 11:15:27 +0200404 zfcp_dbf_outd(p, "payload", (char *)&r->payload, r->payload_size, 0,
Martin Peschkedf29f4a2008-03-31 11:15:26 +0200405 r->payload_size);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200406}
407
Martin Peschkea9c85772008-03-31 11:15:27 +0200408static void zfcp_hba_dbf_view_qdio(char **p, struct zfcp_hba_dbf_record_qdio *r)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200409{
Martin Peschkea9c85772008-03-31 11:15:27 +0200410 zfcp_dbf_out(p, "status", "0x%08x", r->status);
411 zfcp_dbf_out(p, "qdio_error", "0x%08x", r->qdio_error);
412 zfcp_dbf_out(p, "siga_error", "0x%08x", r->siga_error);
413 zfcp_dbf_out(p, "sbal_index", "0x%02x", r->sbal_index);
414 zfcp_dbf_out(p, "sbal_count", "0x%02x", r->sbal_count);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200415}
416
Martin Peschkea9c85772008-03-31 11:15:27 +0200417static int zfcp_hba_dbf_view_format(debug_info_t *id, struct debug_view *view,
418 char *out_buf, const char *in_buf)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200419{
Martin Peschkea9c85772008-03-31 11:15:27 +0200420 struct zfcp_hba_dbf_record *r = (struct zfcp_hba_dbf_record *)in_buf;
421 char *p = out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200422
Martin Peschkea9c85772008-03-31 11:15:27 +0200423 if (strncmp(r->tag, "dump", ZFCP_DBF_TAG_SIZE) == 0)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200424 return 0;
425
Martin Peschkea9c85772008-03-31 11:15:27 +0200426 zfcp_dbf_tag(&p, "tag", r->tag);
427 if (isalpha(r->tag2[0]))
428 zfcp_dbf_tag(&p, "tag2", r->tag2);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200429
Martin Peschkea9c85772008-03-31 11:15:27 +0200430 if (strncmp(r->tag, "resp", ZFCP_DBF_TAG_SIZE) == 0)
431 zfcp_hba_dbf_view_response(&p, &r->type.response);
432 else if (strncmp(r->tag, "stat", ZFCP_DBF_TAG_SIZE) == 0)
433 zfcp_hba_dbf_view_status(&p, &r->type.status);
434 else if (strncmp(r->tag, "qdio", ZFCP_DBF_TAG_SIZE) == 0)
435 zfcp_hba_dbf_view_qdio(&p, &r->type.qdio);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200436
Martin Peschkea9c85772008-03-31 11:15:27 +0200437 p += sprintf(p, "\n");
438 return p - out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200439}
440
Heiko Carstens2b67fc42007-02-05 21:16:47 +0100441static struct debug_view zfcp_hba_dbf_view = {
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200442 "structured",
443 NULL,
444 &zfcp_dbf_view_header,
445 &zfcp_hba_dbf_view_format,
446 NULL,
447 NULL
448};
449
Martin Peschked79a83d2008-03-27 14:22:00 +0100450static const char *zfcp_rec_dbf_tags[] = {
Martin Peschke348447e2008-03-27 14:22:01 +0100451 [ZFCP_REC_DBF_ID_THREAD] = "thread",
Martin Peschke698ec0162008-03-27 14:22:02 +0100452 [ZFCP_REC_DBF_ID_TARGET] = "target",
Martin Peschke9467a9b2008-03-27 14:22:03 +0100453 [ZFCP_REC_DBF_ID_TRIGGER] = "trigger",
Martin Peschke6f4f3652008-03-27 14:22:04 +0100454 [ZFCP_REC_DBF_ID_ACTION] = "action",
Martin Peschked79a83d2008-03-27 14:22:00 +0100455};
456
457static const char *zfcp_rec_dbf_ids[] = {
Martin Peschke348447e2008-03-27 14:22:01 +0100458 [1] = "new",
459 [2] = "ready",
460 [3] = "kill",
461 [4] = "down sleep",
462 [5] = "down wakeup",
463 [6] = "down sleep ecd",
464 [7] = "down wakeup ecd",
465 [8] = "down sleep epd",
466 [9] = "down wakeup epd",
Martin Peschke698ec0162008-03-27 14:22:02 +0100467 [10] = "online",
468 [11] = "operational",
469 [12] = "scsi slave destroy",
470 [13] = "propagate failed adapter",
471 [14] = "propagate failed port",
472 [15] = "block adapter",
473 [16] = "unblock adapter",
474 [17] = "block port",
475 [18] = "unblock port",
476 [19] = "block unit",
477 [20] = "unblock unit",
478 [21] = "unit recovery failed",
479 [22] = "port recovery failed",
480 [23] = "adapter recovery failed",
481 [24] = "qdio queues down",
482 [25] = "p2p failed",
483 [26] = "nameserver lookup failed",
484 [27] = "nameserver port failed",
485 [28] = "link up",
486 [29] = "link down",
487 [30] = "link up status read",
488 [31] = "open port failed",
489 [32] = "open port failed",
490 [33] = "close port",
491 [34] = "open unit failed",
492 [35] = "exclusive open unit failed",
493 [36] = "shared open unit failed",
494 [37] = "link down",
495 [38] = "link down status read no link",
496 [39] = "link down status read fdisc login",
497 [40] = "link down status read firmware update",
498 [41] = "link down status read unknown reason",
499 [42] = "link down ecd incomplete",
500 [43] = "link down epd incomplete",
501 [44] = "sysfs adapter recovery",
502 [45] = "sysfs port recovery",
503 [46] = "sysfs unit recovery",
504 [47] = "port boxed abort",
505 [48] = "unit boxed abort",
506 [49] = "port boxed ct",
507 [50] = "port boxed close physical",
508 [51] = "port boxed open unit",
509 [52] = "port boxed close unit",
510 [53] = "port boxed fcp",
511 [54] = "unit boxed fcp",
512 [55] = "port access denied ct",
513 [56] = "port access denied els",
514 [57] = "port access denied open port",
515 [58] = "port access denied close physical",
516 [59] = "unit access denied open unit",
517 [60] = "shared unit access denied open unit",
518 [61] = "unit access denied fcp",
Martin Peschke9467a9b2008-03-27 14:22:03 +0100519 [62] = "request timeout",
520 [63] = "adisc link test reject or timeout",
521 [64] = "adisc link test d_id changed",
522 [65] = "adisc link test failed",
523 [66] = "recovery out of memory",
524 [67] = "adapter recovery repeated after state change",
525 [68] = "port recovery repeated after state change",
526 [69] = "unit recovery repeated after state change",
527 [70] = "port recovery follow-up after successful adapter recovery",
528 [71] = "adapter recovery escalation after failed adapter recovery",
529 [72] = "port recovery follow-up after successful physical port "
530 "recovery",
531 [73] = "adapter recovery escalation after failed physical port "
532 "recovery",
533 [74] = "unit recovery follow-up after successful port recovery",
534 [75] = "physical port recovery escalation after failed port "
535 "recovery",
536 [76] = "port recovery escalation after failed unit recovery",
537 [77] = "recovery opening nameserver port",
538 [78] = "duplicate request id",
539 [79] = "link down",
540 [80] = "exclusive read-only unit access unsupported",
541 [81] = "shared read-write unit access unsupported",
542 [82] = "incoming rscn",
543 [83] = "incoming plogi",
544 [84] = "incoming logo",
545 [85] = "online",
546 [86] = "offline",
547 [87] = "ccw device gone",
548 [88] = "ccw device no path",
549 [89] = "ccw device operational",
550 [90] = "ccw device shutdown",
551 [91] = "sysfs port addition",
552 [92] = "sysfs port removal",
553 [93] = "sysfs adapter recovery",
554 [94] = "sysfs unit addition",
555 [95] = "sysfs unit removal",
556 [96] = "sysfs port recovery",
557 [97] = "sysfs unit recovery",
558 [98] = "sequence number mismatch",
559 [99] = "link up",
560 [100] = "error state",
561 [101] = "status read physical port closed",
562 [102] = "link up status read",
563 [103] = "too many failed status read buffers",
564 [104] = "port handle not valid abort",
565 [105] = "lun handle not valid abort",
566 [106] = "port handle not valid ct",
567 [107] = "port handle not valid close port",
568 [108] = "port handle not valid close physical port",
569 [109] = "port handle not valid open unit",
570 [110] = "port handle not valid close unit",
571 [111] = "lun handle not valid close unit",
572 [112] = "port handle not valid fcp",
573 [113] = "lun handle not valid fcp",
574 [114] = "handle mismatch fcp",
575 [115] = "lun not valid fcp",
576 [116] = "qdio send failed",
577 [117] = "version mismatch",
578 [118] = "incompatible qtcb type",
579 [119] = "unknown protocol status",
580 [120] = "unknown fsf command",
581 [121] = "no recommendation for status qualifier",
582 [122] = "status read physical port closed in error",
583 [123] = "fc service class not supported ct",
584 [124] = "fc service class not supported els",
585 [125] = "need newer zfcp",
586 [126] = "need newer microcode",
587 [127] = "arbitrated loop not supported",
588 [128] = "unknown topology",
589 [129] = "qtcb size mismatch",
590 [130] = "unknown fsf status ecd",
591 [131] = "fcp request too big",
592 [132] = "fc service class not supported fcp",
593 [133] = "data direction not valid fcp",
594 [134] = "command length not valid fcp",
595 [135] = "status read act update",
596 [136] = "status read cfdc update",
597 [137] = "hbaapi port open",
598 [138] = "hbaapi unit open",
599 [139] = "hbaapi unit shutdown",
600 [140] = "qdio error",
601 [141] = "scsi host reset",
Martin Peschke6f4f3652008-03-27 14:22:04 +0100602 [142] = "dismissing fsf request for recovery action",
603 [143] = "recovery action timed out",
604 [144] = "recovery action gone",
605 [145] = "recovery action being processed",
606 [146] = "recovery action ready for next step",
Martin Peschked79a83d2008-03-27 14:22:00 +0100607};
608
609static int zfcp_rec_dbf_view_format(debug_info_t *id, struct debug_view *view,
610 char *buf, const char *_rec)
611{
612 struct zfcp_rec_dbf_record *r = (struct zfcp_rec_dbf_record *)_rec;
613 char *p = buf;
614
615 zfcp_dbf_outs(&p, "tag", zfcp_rec_dbf_tags[r->id]);
616 zfcp_dbf_outs(&p, "hint", zfcp_rec_dbf_ids[r->id2]);
617 zfcp_dbf_out(&p, "id", "%d", r->id2);
618 switch (r->id) {
Martin Peschke348447e2008-03-27 14:22:01 +0100619 case ZFCP_REC_DBF_ID_THREAD:
620 zfcp_dbf_out(&p, "sema", "%d", r->u.thread.sema);
621 zfcp_dbf_out(&p, "total", "%d", r->u.thread.total);
622 zfcp_dbf_out(&p, "ready", "%d", r->u.thread.ready);
623 zfcp_dbf_out(&p, "running", "%d", r->u.thread.running);
624 break;
Martin Peschke698ec0162008-03-27 14:22:02 +0100625 case ZFCP_REC_DBF_ID_TARGET:
626 zfcp_dbf_out(&p, "reference", "0x%016Lx", r->u.target.ref);
627 zfcp_dbf_out(&p, "status", "0x%08x", r->u.target.status);
628 zfcp_dbf_out(&p, "erp_count", "%d", r->u.target.erp_count);
629 zfcp_dbf_out(&p, "d_id", "0x%06x", r->u.target.d_id);
630 zfcp_dbf_out(&p, "wwpn", "0x%016Lx", r->u.target.wwpn);
631 zfcp_dbf_out(&p, "fcp_lun", "0x%016Lx", r->u.target.fcp_lun);
632 break;
Martin Peschke9467a9b2008-03-27 14:22:03 +0100633 case ZFCP_REC_DBF_ID_TRIGGER:
634 zfcp_dbf_out(&p, "reference", "0x%016Lx", r->u.trigger.ref);
635 zfcp_dbf_out(&p, "erp_action", "0x%016Lx", r->u.trigger.action);
636 zfcp_dbf_out(&p, "requested", "%d", r->u.trigger.want);
637 zfcp_dbf_out(&p, "executed", "%d", r->u.trigger.need);
638 zfcp_dbf_out(&p, "wwpn", "0x%016Lx", r->u.trigger.wwpn);
639 zfcp_dbf_out(&p, "fcp_lun", "0x%016Lx", r->u.trigger.fcp_lun);
640 zfcp_dbf_out(&p, "adapter_status", "0x%08x", r->u.trigger.as);
641 zfcp_dbf_out(&p, "port_status", "0x%08x", r->u.trigger.ps);
642 zfcp_dbf_out(&p, "unit_status", "0x%08x", r->u.trigger.us);
643 break;
Martin Peschke6f4f3652008-03-27 14:22:04 +0100644 case ZFCP_REC_DBF_ID_ACTION:
645 zfcp_dbf_out(&p, "erp_action", "0x%016Lx", r->u.action.action);
646 zfcp_dbf_out(&p, "fsf_req", "0x%016Lx", r->u.action.fsf_req);
647 zfcp_dbf_out(&p, "status", "0x%08Lx", r->u.action.status);
648 zfcp_dbf_out(&p, "step", "0x%08Lx", r->u.action.step);
649 break;
Martin Peschked79a83d2008-03-27 14:22:00 +0100650 }
Martin Peschkeb634fff2008-03-31 11:15:24 +0200651 p += sprintf(p, "\n");
652 return p - buf;
Martin Peschked79a83d2008-03-27 14:22:00 +0100653}
654
655static struct debug_view zfcp_rec_dbf_view = {
656 "structured",
657 NULL,
658 &zfcp_dbf_view_header,
659 &zfcp_rec_dbf_view_format,
660 NULL,
661 NULL
662};
663
Martin Peschke348447e2008-03-27 14:22:01 +0100664/**
665 * zfcp_rec_dbf_event_thread - trace event related to recovery thread operation
666 * @id2: identifier for event
667 * @adapter: adapter
668 * @lock: non-zero value indicates that erp_lock has not yet been acquired
669 */
670void zfcp_rec_dbf_event_thread(u8 id2, struct zfcp_adapter *adapter, int lock)
671{
672 struct zfcp_rec_dbf_record *r = &adapter->rec_dbf_buf;
673 unsigned long flags = 0;
674 struct list_head *entry;
675 unsigned ready = 0, running = 0, total;
676
677 if (lock)
678 read_lock_irqsave(&adapter->erp_lock, flags);
679 list_for_each(entry, &adapter->erp_ready_head)
680 ready++;
681 list_for_each(entry, &adapter->erp_running_head)
682 running++;
683 total = adapter->erp_total_count;
684 if (lock)
685 read_unlock_irqrestore(&adapter->erp_lock, flags);
686
687 spin_lock_irqsave(&adapter->rec_dbf_lock, flags);
688 memset(r, 0, sizeof(*r));
689 r->id = ZFCP_REC_DBF_ID_THREAD;
690 r->id2 = id2;
691 r->u.thread.sema = atomic_read(&adapter->erp_ready_sem.count);
692 r->u.thread.total = total;
693 r->u.thread.ready = ready;
694 r->u.thread.running = running;
695 debug_event(adapter->rec_dbf, 5, r, sizeof(*r));
696 spin_unlock_irqrestore(&adapter->rec_dbf_lock, flags);
697}
698
Martin Peschke698ec0162008-03-27 14:22:02 +0100699static void zfcp_rec_dbf_event_target(u8 id2, u64 ref,
700 struct zfcp_adapter *adapter,
701 atomic_t *status, atomic_t *erp_count,
702 u64 wwpn, u32 d_id, u64 fcp_lun)
703{
704 struct zfcp_rec_dbf_record *r = &adapter->rec_dbf_buf;
705 unsigned long flags;
706
707 spin_lock_irqsave(&adapter->rec_dbf_lock, flags);
708 memset(r, 0, sizeof(*r));
709 r->id = ZFCP_REC_DBF_ID_TARGET;
710 r->id2 = id2;
711 r->u.target.ref = ref;
712 r->u.target.status = atomic_read(status);
713 r->u.target.wwpn = wwpn;
714 r->u.target.d_id = d_id;
715 r->u.target.fcp_lun = fcp_lun;
716 r->u.target.erp_count = atomic_read(erp_count);
717 debug_event(adapter->rec_dbf, 3, r, sizeof(*r));
718 spin_unlock_irqrestore(&adapter->rec_dbf_lock, flags);
719}
720
721/**
722 * zfcp_rec_dbf_event_adapter - trace event for adapter state change
723 * @id: identifier for trigger of state change
724 * @ref: additional reference (e.g. request)
725 * @adapter: adapter
726 */
727void zfcp_rec_dbf_event_adapter(u8 id, u64 ref, struct zfcp_adapter *adapter)
728{
729 zfcp_rec_dbf_event_target(id, ref, adapter, &adapter->status,
730 &adapter->erp_counter, 0, 0, 0);
731}
732
733/**
734 * zfcp_rec_dbf_event_port - trace event for port state change
735 * @id: identifier for trigger of state change
736 * @ref: additional reference (e.g. request)
737 * @port: port
738 */
739void zfcp_rec_dbf_event_port(u8 id, u64 ref, struct zfcp_port *port)
740{
741 struct zfcp_adapter *adapter = port->adapter;
742
743 zfcp_rec_dbf_event_target(id, ref, adapter, &port->status,
744 &port->erp_counter, port->wwpn, port->d_id,
745 0);
746}
747
748/**
749 * zfcp_rec_dbf_event_unit - trace event for unit state change
750 * @id: identifier for trigger of state change
751 * @ref: additional reference (e.g. request)
752 * @unit: unit
753 */
754void zfcp_rec_dbf_event_unit(u8 id, u64 ref, struct zfcp_unit *unit)
755{
756 struct zfcp_port *port = unit->port;
757 struct zfcp_adapter *adapter = port->adapter;
758
759 zfcp_rec_dbf_event_target(id, ref, adapter, &unit->status,
760 &unit->erp_counter, port->wwpn, port->d_id,
761 unit->fcp_lun);
762}
763
Martin Peschke9467a9b2008-03-27 14:22:03 +0100764/**
765 * zfcp_rec_dbf_event_trigger - trace event for triggered error recovery
766 * @id2: identifier for error recovery trigger
767 * @ref: additional reference (e.g. request)
768 * @want: originally requested error recovery action
769 * @need: error recovery action actually initiated
770 * @action: address of error recovery action struct
771 * @adapter: adapter
772 * @port: port
773 * @unit: unit
774 */
775void zfcp_rec_dbf_event_trigger(u8 id2, u64 ref, u8 want, u8 need, u64 action,
776 struct zfcp_adapter *adapter,
777 struct zfcp_port *port, struct zfcp_unit *unit)
778{
779 struct zfcp_rec_dbf_record *r = &adapter->rec_dbf_buf;
780 unsigned long flags;
781
782 spin_lock_irqsave(&adapter->rec_dbf_lock, flags);
783 memset(r, 0, sizeof(*r));
784 r->id = ZFCP_REC_DBF_ID_TRIGGER;
785 r->id2 = id2;
786 r->u.trigger.ref = ref;
787 r->u.trigger.want = want;
788 r->u.trigger.need = need;
789 r->u.trigger.action = action;
790 r->u.trigger.as = atomic_read(&adapter->status);
791 if (port) {
792 r->u.trigger.ps = atomic_read(&port->status);
793 r->u.trigger.wwpn = port->wwpn;
794 }
795 if (unit) {
796 r->u.trigger.us = atomic_read(&unit->status);
797 r->u.trigger.fcp_lun = unit->fcp_lun;
798 }
799 debug_event(adapter->rec_dbf, action ? 1 : 4, r, sizeof(*r));
800 spin_unlock_irqrestore(&adapter->rec_dbf_lock, flags);
801}
802
Martin Peschke6f4f3652008-03-27 14:22:04 +0100803/**
804 * zfcp_rec_dbf_event_action - trace event showing progress of recovery action
805 * @id2: identifier
806 * @erp_action: error recovery action struct pointer
807 */
808void zfcp_rec_dbf_event_action(u8 id2, struct zfcp_erp_action *erp_action)
809{
810 struct zfcp_adapter *adapter = erp_action->adapter;
811 struct zfcp_rec_dbf_record *r = &adapter->rec_dbf_buf;
812 unsigned long flags;
813
814 spin_lock_irqsave(&adapter->rec_dbf_lock, flags);
815 memset(r, 0, sizeof(*r));
816 r->id = ZFCP_REC_DBF_ID_ACTION;
817 r->id2 = id2;
818 r->u.action.action = (u64)erp_action;
819 r->u.action.status = erp_action->status;
820 r->u.action.step = erp_action->step;
821 r->u.action.fsf_req = (u64)erp_action->fsf_req;
822 debug_event(adapter->rec_dbf, 4, r, sizeof(*r));
823 spin_unlock_irqrestore(&adapter->rec_dbf_lock, flags);
824}
825
Heiko Carstens763968e2007-05-10 15:45:46 +0200826static void
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200827_zfcp_san_dbf_event_common_ct(const char *tag, struct zfcp_fsf_req *fsf_req,
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200828 u32 s_id, u32 d_id, void *buffer, int buflen)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200829{
830 struct zfcp_send_ct *send_ct = (struct zfcp_send_ct *)fsf_req->data;
831 struct zfcp_port *port = send_ct->port;
832 struct zfcp_adapter *adapter = port->adapter;
833 struct ct_hdr *header = (struct ct_hdr *)buffer;
834 struct zfcp_san_dbf_record *rec = &adapter->san_dbf_buf;
835 struct zfcp_san_dbf_record_ct *ct = &rec->type.ct;
836 unsigned long flags;
837
838 spin_lock_irqsave(&adapter->san_dbf_lock, flags);
839 memset(rec, 0, sizeof(struct zfcp_san_dbf_record));
840 strncpy(rec->tag, tag, ZFCP_DBF_TAG_SIZE);
841 rec->fsf_reqid = (unsigned long)fsf_req;
842 rec->fsf_seqno = fsf_req->seq_no;
843 rec->s_id = s_id;
844 rec->d_id = d_id;
845 if (strncmp(tag, "octc", ZFCP_DBF_TAG_SIZE) == 0) {
846 ct->type.request.cmd_req_code = header->cmd_rsp_code;
847 ct->type.request.revision = header->revision;
848 ct->type.request.gs_type = header->gs_type;
849 ct->type.request.gs_subtype = header->gs_subtype;
850 ct->type.request.options = header->options;
851 ct->type.request.max_res_size = header->max_res_size;
852 } else if (strncmp(tag, "rctc", ZFCP_DBF_TAG_SIZE) == 0) {
853 ct->type.response.cmd_rsp_code = header->cmd_rsp_code;
854 ct->type.response.revision = header->revision;
855 ct->type.response.reason_code = header->reason_code;
856 ct->type.response.reason_code_expl = header->reason_code_expl;
857 ct->type.response.vendor_unique = header->vendor_unique;
858 }
859 ct->payload_size =
860 min(buflen - (int)sizeof(struct ct_hdr), ZFCP_DBF_CT_PAYLOAD);
861 memcpy(ct->payload, buffer + sizeof(struct ct_hdr), ct->payload_size);
862 debug_event(adapter->san_dbf, 3,
863 rec, sizeof(struct zfcp_san_dbf_record));
864 spin_unlock_irqrestore(&adapter->san_dbf_lock, flags);
865}
866
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100867void zfcp_san_dbf_event_ct_request(struct zfcp_fsf_req *fsf_req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200868{
869 struct zfcp_send_ct *ct = (struct zfcp_send_ct *)fsf_req->data;
870 struct zfcp_port *port = ct->port;
871 struct zfcp_adapter *adapter = port->adapter;
872
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200873 _zfcp_san_dbf_event_common_ct("octc", fsf_req,
874 fc_host_port_id(adapter->scsi_host),
875 port->d_id, zfcp_sg_to_address(ct->req),
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200876 ct->req->length);
877}
878
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100879void zfcp_san_dbf_event_ct_response(struct zfcp_fsf_req *fsf_req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200880{
881 struct zfcp_send_ct *ct = (struct zfcp_send_ct *)fsf_req->data;
882 struct zfcp_port *port = ct->port;
883 struct zfcp_adapter *adapter = port->adapter;
884
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200885 _zfcp_san_dbf_event_common_ct("rctc", fsf_req, port->d_id,
886 fc_host_port_id(adapter->scsi_host),
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200887 zfcp_sg_to_address(ct->resp),
888 ct->resp->length);
889}
890
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100891static void
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200892_zfcp_san_dbf_event_common_els(const char *tag, int level,
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200893 struct zfcp_fsf_req *fsf_req, u32 s_id,
894 u32 d_id, u8 ls_code, void *buffer, int buflen)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200895{
896 struct zfcp_adapter *adapter = fsf_req->adapter;
897 struct zfcp_san_dbf_record *rec = &adapter->san_dbf_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200898 unsigned long flags;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200899
900 spin_lock_irqsave(&adapter->san_dbf_lock, flags);
Martin Peschke0f65e952008-03-27 14:21:56 +0100901 memset(rec, 0, sizeof(struct zfcp_san_dbf_record));
902 strncpy(rec->tag, tag, ZFCP_DBF_TAG_SIZE);
903 rec->fsf_reqid = (unsigned long)fsf_req;
904 rec->fsf_seqno = fsf_req->seq_no;
905 rec->s_id = s_id;
906 rec->d_id = d_id;
907 rec->type.els.ls_code = ls_code;
908 debug_event(adapter->san_dbf, level, rec, sizeof(*rec));
909 zfcp_dbf_hexdump(adapter->san_dbf, rec, sizeof(*rec), level,
910 buffer, min(buflen, ZFCP_DBF_ELS_MAX_PAYLOAD));
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200911 spin_unlock_irqrestore(&adapter->san_dbf_lock, flags);
912}
913
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100914void zfcp_san_dbf_event_els_request(struct zfcp_fsf_req *fsf_req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200915{
916 struct zfcp_send_els *els = (struct zfcp_send_els *)fsf_req->data;
917
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200918 _zfcp_san_dbf_event_common_els("oels", 2, fsf_req,
919 fc_host_port_id(els->adapter->scsi_host),
920 els->d_id,
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200921 *(u8 *) zfcp_sg_to_address(els->req),
922 zfcp_sg_to_address(els->req),
923 els->req->length);
924}
925
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100926void zfcp_san_dbf_event_els_response(struct zfcp_fsf_req *fsf_req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200927{
928 struct zfcp_send_els *els = (struct zfcp_send_els *)fsf_req->data;
929
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200930 _zfcp_san_dbf_event_common_els("rels", 2, fsf_req, els->d_id,
931 fc_host_port_id(els->adapter->scsi_host),
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200932 *(u8 *) zfcp_sg_to_address(els->req),
933 zfcp_sg_to_address(els->resp),
934 els->resp->length);
935}
936
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100937void zfcp_san_dbf_event_incoming_els(struct zfcp_fsf_req *fsf_req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200938{
939 struct zfcp_adapter *adapter = fsf_req->adapter;
940 struct fsf_status_read_buffer *status_buffer =
941 (struct fsf_status_read_buffer *)fsf_req->data;
942 int length = (int)status_buffer->length -
943 (int)((void *)&status_buffer->payload - (void *)status_buffer);
944
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200945 _zfcp_san_dbf_event_common_els("iels", 1, fsf_req, status_buffer->d_id,
946 fc_host_port_id(adapter->scsi_host),
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200947 *(u8 *) status_buffer->payload,
948 (void *)status_buffer->payload, length);
949}
950
951static int
952zfcp_san_dbf_view_format(debug_info_t * id, struct debug_view *view,
953 char *out_buf, const char *in_buf)
954{
Martin Peschkeb634fff2008-03-31 11:15:24 +0200955 struct zfcp_san_dbf_record *r = (struct zfcp_san_dbf_record *)in_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200956 char *buffer = NULL;
957 int buflen = 0, total = 0;
Martin Peschkeb634fff2008-03-31 11:15:24 +0200958 char *p = out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200959
Martin Peschkeb634fff2008-03-31 11:15:24 +0200960 if (strncmp(r->tag, "dump", ZFCP_DBF_TAG_SIZE) == 0)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200961 return 0;
962
Martin Peschkea9c85772008-03-31 11:15:27 +0200963 zfcp_dbf_tag(&p, "tag", r->tag);
Martin Peschkeb634fff2008-03-31 11:15:24 +0200964 zfcp_dbf_out(&p, "fsf_reqid", "0x%0Lx", r->fsf_reqid);
965 zfcp_dbf_out(&p, "fsf_seqno", "0x%08x", r->fsf_seqno);
966 zfcp_dbf_out(&p, "s_id", "0x%06x", r->s_id);
967 zfcp_dbf_out(&p, "d_id", "0x%06x", r->d_id);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200968
Martin Peschkeb634fff2008-03-31 11:15:24 +0200969 if (strncmp(r->tag, "octc", ZFCP_DBF_TAG_SIZE) == 0) {
970 /* FIXME: struct zfcp_dbf_ct_req *ct = ...; */
971 zfcp_dbf_out(&p, "cmd_req_code", "0x%04x",
972 r->type.ct.type.request.cmd_req_code);
973 zfcp_dbf_out(&p, "revision", "0x%02x",
974 r->type.ct.type.request.revision);
975 zfcp_dbf_out(&p, "gs_type", "0x%02x",
976 r->type.ct.type.request.gs_type);
977 zfcp_dbf_out(&p, "gs_subtype", "0x%02x",
978 r->type.ct.type.request.gs_subtype);
979 zfcp_dbf_out(&p, "options", "0x%02x",
980 r->type.ct.type.request.options);
981 zfcp_dbf_out(&p, "max_res_size", "0x%04x",
982 r->type.ct.type.request.max_res_size);
983 total = r->type.ct.payload_size;
984 buffer = r->type.ct.payload;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200985 buflen = min(total, ZFCP_DBF_CT_PAYLOAD);
Martin Peschkeb634fff2008-03-31 11:15:24 +0200986 } else if (strncmp(r->tag, "rctc", ZFCP_DBF_TAG_SIZE) == 0) {
987 zfcp_dbf_out(&p, "cmd_rsp_code", "0x%04x",
988 r->type.ct.type.response.cmd_rsp_code);
989 zfcp_dbf_out(&p, "revision", "0x%02x",
990 r->type.ct.type.response.revision);
991 zfcp_dbf_out(&p, "reason_code", "0x%02x",
992 r->type.ct.type.response.reason_code);
993 zfcp_dbf_out(&p, "reason_code_expl", "0x%02x",
994 r->type.ct.type.response.reason_code_expl);
995 zfcp_dbf_out(&p, "vendor_unique", "0x%02x",
996 r->type.ct.type.response.vendor_unique);
997 total = r->type.ct.payload_size;
998 buffer = r->type.ct.payload;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200999 buflen = min(total, ZFCP_DBF_CT_PAYLOAD);
Martin Peschkeb634fff2008-03-31 11:15:24 +02001000 } else if (strncmp(r->tag, "oels", ZFCP_DBF_TAG_SIZE) == 0 ||
1001 strncmp(r->tag, "rels", ZFCP_DBF_TAG_SIZE) == 0 ||
1002 strncmp(r->tag, "iels", ZFCP_DBF_TAG_SIZE) == 0) {
1003 zfcp_dbf_out(&p, "ls_code", "0x%02x", r->type.els.ls_code);
1004 total = r->type.els.payload_size;
1005 buffer = r->type.els.payload;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001006 buflen = min(total, ZFCP_DBF_ELS_PAYLOAD);
1007 }
1008
Martin Peschkedf29f4a2008-03-31 11:15:26 +02001009 zfcp_dbf_outd(&p, "payload", buffer, buflen, 0, total);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001010 if (buflen == total)
Martin Peschkeb634fff2008-03-31 11:15:24 +02001011 p += sprintf(p, "\n");
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001012
Martin Peschkeb634fff2008-03-31 11:15:24 +02001013 return p - out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001014}
1015
Heiko Carstens2b67fc42007-02-05 21:16:47 +01001016static struct debug_view zfcp_san_dbf_view = {
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001017 "structured",
1018 NULL,
1019 &zfcp_dbf_view_header,
1020 &zfcp_san_dbf_view_format,
1021 NULL,
1022 NULL
1023};
1024
Heiko Carstens4d284ca2007-02-05 21:18:53 +01001025static void
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001026_zfcp_scsi_dbf_event_common(const char *tag, const char *tag2, int level,
1027 struct zfcp_adapter *adapter,
1028 struct scsi_cmnd *scsi_cmnd,
Maxim Shchetynined829ad2006-02-11 01:42:58 +01001029 struct zfcp_fsf_req *fsf_req,
Andreas Herrmann4eff4a32006-09-18 22:29:20 +02001030 unsigned long old_req_id)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001031{
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001032 struct zfcp_scsi_dbf_record *rec = &adapter->scsi_dbf_buf;
1033 struct zfcp_dbf_dump *dump = (struct zfcp_dbf_dump *)rec;
1034 unsigned long flags;
1035 struct fcp_rsp_iu *fcp_rsp;
1036 char *fcp_rsp_info = NULL, *fcp_sns_info = NULL;
1037 int offset = 0, buflen = 0;
1038
1039 spin_lock_irqsave(&adapter->scsi_dbf_lock, flags);
1040 do {
1041 memset(rec, 0, sizeof(struct zfcp_scsi_dbf_record));
1042 if (offset == 0) {
1043 strncpy(rec->tag, tag, ZFCP_DBF_TAG_SIZE);
1044 strncpy(rec->tag2, tag2, ZFCP_DBF_TAG_SIZE);
Maxim Shchetynined829ad2006-02-11 01:42:58 +01001045 if (scsi_cmnd != NULL) {
1046 if (scsi_cmnd->device) {
1047 rec->scsi_id = scsi_cmnd->device->id;
1048 rec->scsi_lun = scsi_cmnd->device->lun;
1049 }
1050 rec->scsi_result = scsi_cmnd->result;
1051 rec->scsi_cmnd = (unsigned long)scsi_cmnd;
1052 rec->scsi_serial = scsi_cmnd->serial_number;
1053 memcpy(rec->scsi_opcode, &scsi_cmnd->cmnd,
1054 min((int)scsi_cmnd->cmd_len,
1055 ZFCP_DBF_SCSI_OPCODE));
1056 rec->scsi_retries = scsi_cmnd->retries;
1057 rec->scsi_allowed = scsi_cmnd->allowed;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001058 }
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001059 if (fsf_req != NULL) {
1060 fcp_rsp = (struct fcp_rsp_iu *)
1061 &(fsf_req->qtcb->bottom.io.fcp_rsp);
1062 fcp_rsp_info =
1063 zfcp_get_fcp_rsp_info_ptr(fcp_rsp);
1064 fcp_sns_info =
1065 zfcp_get_fcp_sns_info_ptr(fcp_rsp);
1066
1067 rec->type.fcp.rsp_validity =
1068 fcp_rsp->validity.value;
1069 rec->type.fcp.rsp_scsi_status =
1070 fcp_rsp->scsi_status;
1071 rec->type.fcp.rsp_resid = fcp_rsp->fcp_resid;
1072 if (fcp_rsp->validity.bits.fcp_rsp_len_valid)
1073 rec->type.fcp.rsp_code =
1074 *(fcp_rsp_info + 3);
1075 if (fcp_rsp->validity.bits.fcp_sns_len_valid) {
1076 buflen = min((int)fcp_rsp->fcp_sns_len,
1077 ZFCP_DBF_SCSI_MAX_FCP_SNS_INFO);
1078 rec->type.fcp.sns_info_len = buflen;
1079 memcpy(rec->type.fcp.sns_info,
1080 fcp_sns_info,
1081 min(buflen,
1082 ZFCP_DBF_SCSI_FCP_SNS_INFO));
1083 offset += min(buflen,
1084 ZFCP_DBF_SCSI_FCP_SNS_INFO);
1085 }
1086
1087 rec->fsf_reqid = (unsigned long)fsf_req;
1088 rec->fsf_seqno = fsf_req->seq_no;
1089 rec->fsf_issued = fsf_req->issued;
1090 }
Andreas Herrmann4eff4a32006-09-18 22:29:20 +02001091 rec->type.old_fsf_reqid = old_req_id;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001092 } else {
1093 strncpy(dump->tag, "dump", ZFCP_DBF_TAG_SIZE);
1094 dump->total_size = buflen;
1095 dump->offset = offset;
1096 dump->size = min(buflen - offset,
1097 (int)sizeof(struct
1098 zfcp_scsi_dbf_record) -
1099 (int)sizeof(struct zfcp_dbf_dump));
1100 memcpy(dump->data, fcp_sns_info + offset, dump->size);
1101 offset += dump->size;
1102 }
1103 debug_event(adapter->scsi_dbf, level,
1104 rec, sizeof(struct zfcp_scsi_dbf_record));
1105 } while (offset < buflen);
1106 spin_unlock_irqrestore(&adapter->scsi_dbf_lock, flags);
1107}
1108
Heiko Carstens4d284ca2007-02-05 21:18:53 +01001109void
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001110zfcp_scsi_dbf_event_result(const char *tag, int level,
1111 struct zfcp_adapter *adapter,
Maxim Shchetynined829ad2006-02-11 01:42:58 +01001112 struct scsi_cmnd *scsi_cmnd,
1113 struct zfcp_fsf_req *fsf_req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001114{
Maxim Shchetynined829ad2006-02-11 01:42:58 +01001115 _zfcp_scsi_dbf_event_common("rslt", tag, level,
Andreas Herrmann4eff4a32006-09-18 22:29:20 +02001116 adapter, scsi_cmnd, fsf_req, 0);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001117}
1118
Heiko Carstens4d284ca2007-02-05 21:18:53 +01001119void
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001120zfcp_scsi_dbf_event_abort(const char *tag, struct zfcp_adapter *adapter,
1121 struct scsi_cmnd *scsi_cmnd,
Maxim Shchetynined829ad2006-02-11 01:42:58 +01001122 struct zfcp_fsf_req *new_fsf_req,
Andreas Herrmann4eff4a32006-09-18 22:29:20 +02001123 unsigned long old_req_id)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001124{
Maxim Shchetynined829ad2006-02-11 01:42:58 +01001125 _zfcp_scsi_dbf_event_common("abrt", tag, 1,
Andreas Herrmann4eff4a32006-09-18 22:29:20 +02001126 adapter, scsi_cmnd, new_fsf_req, old_req_id);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001127}
1128
Heiko Carstens4d284ca2007-02-05 21:18:53 +01001129void
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001130zfcp_scsi_dbf_event_devreset(const char *tag, u8 flag, struct zfcp_unit *unit,
1131 struct scsi_cmnd *scsi_cmnd)
1132{
1133 struct zfcp_adapter *adapter = unit->port->adapter;
1134
1135 _zfcp_scsi_dbf_event_common(flag == FCP_TARGET_RESET ? "trst" : "lrst",
Andreas Herrmann4eff4a32006-09-18 22:29:20 +02001136 tag, 1, adapter, scsi_cmnd, NULL, 0);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001137}
1138
1139static int
1140zfcp_scsi_dbf_view_format(debug_info_t * id, struct debug_view *view,
1141 char *out_buf, const char *in_buf)
1142{
Martin Peschkeb634fff2008-03-31 11:15:24 +02001143 struct zfcp_scsi_dbf_record *r = (struct zfcp_scsi_dbf_record *)in_buf;
Martin Peschke8fc5af12008-03-31 11:15:23 +02001144 struct timespec t;
Martin Peschkeb634fff2008-03-31 11:15:24 +02001145 char *p = out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001146
Martin Peschkeb634fff2008-03-31 11:15:24 +02001147 if (strncmp(r->tag, "dump", ZFCP_DBF_TAG_SIZE) == 0)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001148 return 0;
1149
Martin Peschkea9c85772008-03-31 11:15:27 +02001150 zfcp_dbf_tag(&p, "tag", r->tag);
1151 zfcp_dbf_tag(&p, "tag2", r->tag2);
Martin Peschkeb634fff2008-03-31 11:15:24 +02001152 zfcp_dbf_out(&p, "scsi_id", "0x%08x", r->scsi_id);
1153 zfcp_dbf_out(&p, "scsi_lun", "0x%08x", r->scsi_lun);
1154 zfcp_dbf_out(&p, "scsi_result", "0x%08x", r->scsi_result);
1155 zfcp_dbf_out(&p, "scsi_cmnd", "0x%0Lx", r->scsi_cmnd);
1156 zfcp_dbf_out(&p, "scsi_serial", "0x%016Lx", r->scsi_serial);
Martin Peschkedf29f4a2008-03-31 11:15:26 +02001157 zfcp_dbf_outd(&p, "scsi_opcode", r->scsi_opcode, ZFCP_DBF_SCSI_OPCODE,
1158 0, ZFCP_DBF_SCSI_OPCODE);
Martin Peschkeb634fff2008-03-31 11:15:24 +02001159 zfcp_dbf_out(&p, "scsi_retries", "0x%02x", r->scsi_retries);
1160 zfcp_dbf_out(&p, "scsi_allowed", "0x%02x", r->scsi_allowed);
1161 if (strncmp(r->tag, "abrt", ZFCP_DBF_TAG_SIZE) == 0)
1162 zfcp_dbf_out(&p, "old_fsf_reqid", "0x%0Lx",
1163 r->type.old_fsf_reqid);
1164 zfcp_dbf_out(&p, "fsf_reqid", "0x%0Lx", r->fsf_reqid);
1165 zfcp_dbf_out(&p, "fsf_seqno", "0x%08x", r->fsf_seqno);
1166 zfcp_dbf_timestamp(r->fsf_issued, &t);
1167 zfcp_dbf_out(&p, "fsf_issued", "%011lu:%06lu", t.tv_sec, t.tv_nsec);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001168
Martin Peschkeb634fff2008-03-31 11:15:24 +02001169 if (strncmp(r->tag, "rslt", ZFCP_DBF_TAG_SIZE) == 0) {
1170 zfcp_dbf_out(&p, "fcp_rsp_validity", "0x%02x",
1171 r->type.fcp.rsp_validity);
1172 zfcp_dbf_out(&p, "fcp_rsp_scsi_status",
1173 "0x%02x", r->type.fcp.rsp_scsi_status);
1174 zfcp_dbf_out(&p, "fcp_rsp_resid", "0x%08x",
1175 r->type.fcp.rsp_resid);
1176 zfcp_dbf_out(&p, "fcp_rsp_code", "0x%08x",
1177 r->type.fcp.rsp_code);
1178 zfcp_dbf_out(&p, "fcp_sns_info_len", "0x%08x",
1179 r->type.fcp.sns_info_len);
Martin Peschkedf29f4a2008-03-31 11:15:26 +02001180 zfcp_dbf_outd(&p, "fcp_sns_info", r->type.fcp.sns_info,
1181 min((int)r->type.fcp.sns_info_len,
1182 ZFCP_DBF_SCSI_FCP_SNS_INFO), 0,
1183 r->type.fcp.sns_info_len);
Martin Peschkeb634fff2008-03-31 11:15:24 +02001184 }
1185 p += sprintf(p, "\n");
1186 return p - out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001187}
1188
Heiko Carstens2b67fc42007-02-05 21:16:47 +01001189static struct debug_view zfcp_scsi_dbf_view = {
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001190 "structured",
1191 NULL,
1192 &zfcp_dbf_view_header,
1193 &zfcp_scsi_dbf_view_format,
1194 NULL,
1195 NULL
1196};
1197
1198/**
1199 * zfcp_adapter_debug_register - registers debug feature for an adapter
1200 * @adapter: pointer to adapter for which debug features should be registered
1201 * return: -ENOMEM on error, 0 otherwise
1202 */
1203int zfcp_adapter_debug_register(struct zfcp_adapter *adapter)
1204{
1205 char dbf_name[DEBUG_MAX_NAME_LEN];
1206
1207 /* debug feature area which records recovery activity */
Martin Peschked79a83d2008-03-27 14:22:00 +01001208 sprintf(dbf_name, "zfcp_%s_rec", zfcp_get_busid_by_adapter(adapter));
1209 adapter->rec_dbf = debug_register(dbf_name, dbfsize, 1,
1210 sizeof(struct zfcp_rec_dbf_record));
1211 if (!adapter->rec_dbf)
1212 goto failed;
1213 debug_register_view(adapter->rec_dbf, &debug_hex_ascii_view);
1214 debug_register_view(adapter->rec_dbf, &zfcp_rec_dbf_view);
1215 debug_set_level(adapter->rec_dbf, 3);
1216
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001217 /* debug feature area which records HBA (FSF and QDIO) conditions */
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001218 sprintf(dbf_name, "zfcp_%s_hba", zfcp_get_busid_by_adapter(adapter));
1219 adapter->hba_dbf = debug_register(dbf_name, dbfsize, 1,
1220 sizeof(struct zfcp_hba_dbf_record));
1221 if (!adapter->hba_dbf)
1222 goto failed;
1223 debug_register_view(adapter->hba_dbf, &debug_hex_ascii_view);
1224 debug_register_view(adapter->hba_dbf, &zfcp_hba_dbf_view);
1225 debug_set_level(adapter->hba_dbf, 3);
1226
1227 /* debug feature area which records SAN command failures and recovery */
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001228 sprintf(dbf_name, "zfcp_%s_san", zfcp_get_busid_by_adapter(adapter));
1229 adapter->san_dbf = debug_register(dbf_name, dbfsize, 1,
1230 sizeof(struct zfcp_san_dbf_record));
1231 if (!adapter->san_dbf)
1232 goto failed;
1233 debug_register_view(adapter->san_dbf, &debug_hex_ascii_view);
1234 debug_register_view(adapter->san_dbf, &zfcp_san_dbf_view);
1235 debug_set_level(adapter->san_dbf, 6);
1236
1237 /* debug feature area which records SCSI command failures and recovery */
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001238 sprintf(dbf_name, "zfcp_%s_scsi", zfcp_get_busid_by_adapter(adapter));
1239 adapter->scsi_dbf = debug_register(dbf_name, dbfsize, 1,
1240 sizeof(struct zfcp_scsi_dbf_record));
1241 if (!adapter->scsi_dbf)
1242 goto failed;
1243 debug_register_view(adapter->scsi_dbf, &debug_hex_ascii_view);
1244 debug_register_view(adapter->scsi_dbf, &zfcp_scsi_dbf_view);
1245 debug_set_level(adapter->scsi_dbf, 3);
1246
1247 return 0;
1248
1249 failed:
1250 zfcp_adapter_debug_unregister(adapter);
1251
1252 return -ENOMEM;
1253}
1254
1255/**
1256 * zfcp_adapter_debug_unregister - unregisters debug feature for an adapter
1257 * @adapter: pointer to adapter for which debug features should be unregistered
1258 */
1259void zfcp_adapter_debug_unregister(struct zfcp_adapter *adapter)
1260{
1261 debug_unregister(adapter->scsi_dbf);
1262 debug_unregister(adapter->san_dbf);
1263 debug_unregister(adapter->hba_dbf);
Martin Peschked79a83d2008-03-27 14:22:00 +01001264 debug_unregister(adapter->rec_dbf);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001265 adapter->scsi_dbf = NULL;
1266 adapter->san_dbf = NULL;
1267 adapter->hba_dbf = NULL;
Martin Peschked79a83d2008-03-27 14:22:00 +01001268 adapter->rec_dbf = NULL;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001269}
1270
1271#undef ZFCP_LOG_AREA