blob: a39a3e33a5b61b5c2ac7973e98a73a244884b620 [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;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200147 struct zfcp_hba_dbf_record_response *response = &rec->u.response;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200148 int level;
149 unsigned long flags;
150
151 spin_lock_irqsave(&adapter->hba_dbf_lock, flags);
Martin Peschke6bc473d2008-03-31 11:15:29 +0200152 memset(rec, 0, sizeof(*rec));
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200153 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;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200196 if (scsi_cmnd) {
197 response->u.fcp.cmnd = (unsigned long)scsi_cmnd;
198 response->u.fcp.serial = scsi_cmnd->serial_number;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200199 }
200 break;
201
202 case FSF_QTCB_OPEN_PORT_WITH_DID:
203 case FSF_QTCB_CLOSE_PORT:
204 case FSF_QTCB_CLOSE_PHYSICAL_PORT:
205 port = (struct zfcp_port *)fsf_req->data;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200206 response->u.port.wwpn = port->wwpn;
207 response->u.port.d_id = port->d_id;
208 response->u.port.port_handle = qtcb->header.port_handle;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200209 break;
210
211 case FSF_QTCB_OPEN_LUN:
212 case FSF_QTCB_CLOSE_LUN:
213 unit = (struct zfcp_unit *)fsf_req->data;
214 port = unit->port;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200215 response->u.unit.wwpn = port->wwpn;
216 response->u.unit.fcp_lun = unit->fcp_lun;
217 response->u.unit.port_handle = qtcb->header.port_handle;
218 response->u.unit.lun_handle = qtcb->header.lun_handle;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200219 break;
220
221 case FSF_QTCB_SEND_ELS:
222 send_els = (struct zfcp_send_els *)fsf_req->data;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200223 response->u.els.d_id = qtcb->bottom.support.d_id;
224 response->u.els.ls_code = send_els->ls_code >> 24;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200225 break;
226
227 case FSF_QTCB_ABORT_FCP_CMND:
228 case FSF_QTCB_SEND_GENERIC:
229 case FSF_QTCB_EXCHANGE_CONFIG_DATA:
230 case FSF_QTCB_EXCHANGE_PORT_DATA:
231 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
232 case FSF_QTCB_UPLOAD_CONTROL_FILE:
233 break;
234 }
235
Martin Peschke6bc473d2008-03-31 11:15:29 +0200236 debug_event(adapter->hba_dbf, level, rec, sizeof(*rec));
Martin Peschkeb75db732008-03-27 14:21:58 +0100237
238 /* have fcp channel microcode fixed to use as little as possible */
239 if (fsf_req->fsf_command != FSF_QTCB_FCP_CMND) {
240 /* adjust length skipping trailing zeros */
241 char *buf = (char *)qtcb + qtcb->header.log_start;
242 int len = qtcb->header.log_length;
243 for (; len && !buf[len - 1]; len--);
244 zfcp_dbf_hexdump(adapter->hba_dbf, rec, sizeof(*rec), level,
245 buf, len);
246 }
247
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200248 spin_unlock_irqrestore(&adapter->hba_dbf_lock, flags);
249}
250
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100251void
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200252zfcp_hba_dbf_event_fsf_unsol(const char *tag, struct zfcp_adapter *adapter,
253 struct fsf_status_read_buffer *status_buffer)
254{
255 struct zfcp_hba_dbf_record *rec = &adapter->hba_dbf_buf;
256 unsigned long flags;
257
258 spin_lock_irqsave(&adapter->hba_dbf_lock, flags);
Martin Peschke6bc473d2008-03-31 11:15:29 +0200259 memset(rec, 0, sizeof(*rec));
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200260 strncpy(rec->tag, "stat", ZFCP_DBF_TAG_SIZE);
261 strncpy(rec->tag2, tag, ZFCP_DBF_TAG_SIZE);
262
Martin Peschke6bc473d2008-03-31 11:15:29 +0200263 rec->u.status.failed = adapter->status_read_failed;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200264 if (status_buffer != NULL) {
Martin Peschke6bc473d2008-03-31 11:15:29 +0200265 rec->u.status.status_type = status_buffer->status_type;
266 rec->u.status.status_subtype = status_buffer->status_subtype;
267 memcpy(&rec->u.status.queue_designator,
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200268 &status_buffer->queue_designator,
269 sizeof(struct fsf_queue_designator));
270
271 switch (status_buffer->status_type) {
272 case FSF_STATUS_READ_SENSE_DATA_AVAIL:
Martin Peschke6bc473d2008-03-31 11:15:29 +0200273 rec->u.status.payload_size =
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200274 ZFCP_DBF_UNSOL_PAYLOAD_SENSE_DATA_AVAIL;
275 break;
276
277 case FSF_STATUS_READ_BIT_ERROR_THRESHOLD:
Martin Peschke6bc473d2008-03-31 11:15:29 +0200278 rec->u.status.payload_size =
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200279 ZFCP_DBF_UNSOL_PAYLOAD_BIT_ERROR_THRESHOLD;
280 break;
281
282 case FSF_STATUS_READ_LINK_DOWN:
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200283 switch (status_buffer->status_subtype) {
284 case FSF_STATUS_READ_SUB_NO_PHYSICAL_LINK:
285 case FSF_STATUS_READ_SUB_FDISC_FAILED:
Martin Peschke6bc473d2008-03-31 11:15:29 +0200286 rec->u.status.payload_size =
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200287 sizeof(struct fsf_link_down_info);
288 }
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200289 break;
290
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200291 case FSF_STATUS_READ_FEATURE_UPDATE_ALERT:
Martin Peschke6bc473d2008-03-31 11:15:29 +0200292 rec->u.status.payload_size =
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200293 ZFCP_DBF_UNSOL_PAYLOAD_FEATURE_UPDATE_ALERT;
294 break;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200295 }
Martin Peschke6bc473d2008-03-31 11:15:29 +0200296 memcpy(&rec->u.status.payload,
297 &status_buffer->payload, rec->u.status.payload_size);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200298 }
299
Martin Peschke6bc473d2008-03-31 11:15:29 +0200300 debug_event(adapter->hba_dbf, 2, rec, sizeof(*rec));
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200301 spin_unlock_irqrestore(&adapter->hba_dbf_lock, flags);
302}
303
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100304void
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200305zfcp_hba_dbf_event_qdio(struct zfcp_adapter *adapter, unsigned int status,
306 unsigned int qdio_error, unsigned int siga_error,
307 int sbal_index, int sbal_count)
308{
Martin Peschke6bc473d2008-03-31 11:15:29 +0200309 struct zfcp_hba_dbf_record *r = &adapter->hba_dbf_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200310 unsigned long flags;
311
312 spin_lock_irqsave(&adapter->hba_dbf_lock, flags);
Martin Peschke6bc473d2008-03-31 11:15:29 +0200313 memset(r, 0, sizeof(*r));
314 strncpy(r->tag, "qdio", ZFCP_DBF_TAG_SIZE);
315 r->u.qdio.status = status;
316 r->u.qdio.qdio_error = qdio_error;
317 r->u.qdio.siga_error = siga_error;
318 r->u.qdio.sbal_index = sbal_index;
319 r->u.qdio.sbal_count = sbal_count;
320 debug_event(adapter->hba_dbf, 0, r, sizeof(*r));
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200321 spin_unlock_irqrestore(&adapter->hba_dbf_lock, flags);
322}
323
Martin Peschkea9c85772008-03-31 11:15:27 +0200324static void zfcp_hba_dbf_view_response(char **p,
325 struct zfcp_hba_dbf_record_response *r)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200326{
Martin Peschke8fc5af12008-03-31 11:15:23 +0200327 struct timespec t;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200328
Martin Peschkea9c85772008-03-31 11:15:27 +0200329 zfcp_dbf_out(p, "fsf_command", "0x%08x", r->fsf_command);
330 zfcp_dbf_out(p, "fsf_reqid", "0x%0Lx", r->fsf_reqid);
331 zfcp_dbf_out(p, "fsf_seqno", "0x%08x", r->fsf_seqno);
Martin Peschkeb634fff2008-03-31 11:15:24 +0200332 zfcp_dbf_timestamp(r->fsf_issued, &t);
Martin Peschkea9c85772008-03-31 11:15:27 +0200333 zfcp_dbf_out(p, "fsf_issued", "%011lu:%06lu", t.tv_sec, t.tv_nsec);
334 zfcp_dbf_out(p, "fsf_prot_status", "0x%08x", r->fsf_prot_status);
335 zfcp_dbf_out(p, "fsf_status", "0x%08x", r->fsf_status);
336 zfcp_dbf_outd(p, "fsf_prot_status_qual", r->fsf_prot_status_qual,
Martin Peschkedf29f4a2008-03-31 11:15:26 +0200337 FSF_PROT_STATUS_QUAL_SIZE, 0, FSF_PROT_STATUS_QUAL_SIZE);
Martin Peschkea9c85772008-03-31 11:15:27 +0200338 zfcp_dbf_outd(p, "fsf_status_qual", r->fsf_status_qual,
Martin Peschkedf29f4a2008-03-31 11:15:26 +0200339 FSF_STATUS_QUALIFIER_SIZE, 0, FSF_STATUS_QUALIFIER_SIZE);
Martin Peschkea9c85772008-03-31 11:15:27 +0200340 zfcp_dbf_out(p, "fsf_req_status", "0x%08x", r->fsf_req_status);
341 zfcp_dbf_out(p, "sbal_first", "0x%02x", r->sbal_first);
342 zfcp_dbf_out(p, "sbal_curr", "0x%02x", r->sbal_curr);
343 zfcp_dbf_out(p, "sbal_last", "0x%02x", r->sbal_last);
344 zfcp_dbf_out(p, "pool", "0x%02x", r->pool);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200345
Martin Peschkeb634fff2008-03-31 11:15:24 +0200346 switch (r->fsf_command) {
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200347 case FSF_QTCB_FCP_CMND:
Martin Peschkeb634fff2008-03-31 11:15:24 +0200348 if (r->fsf_req_status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200349 break;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200350 zfcp_dbf_out(p, "scsi_cmnd", "0x%0Lx", r->u.fcp.cmnd);
351 zfcp_dbf_out(p, "scsi_serial", "0x%016Lx", r->u.fcp.serial);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200352 break;
353
354 case FSF_QTCB_OPEN_PORT_WITH_DID:
355 case FSF_QTCB_CLOSE_PORT:
356 case FSF_QTCB_CLOSE_PHYSICAL_PORT:
Martin Peschke6bc473d2008-03-31 11:15:29 +0200357 zfcp_dbf_out(p, "wwpn", "0x%016Lx", r->u.port.wwpn);
358 zfcp_dbf_out(p, "d_id", "0x%06x", r->u.port.d_id);
359 zfcp_dbf_out(p, "port_handle", "0x%08x", r->u.port.port_handle);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200360 break;
361
362 case FSF_QTCB_OPEN_LUN:
363 case FSF_QTCB_CLOSE_LUN:
Martin Peschke6bc473d2008-03-31 11:15:29 +0200364 zfcp_dbf_out(p, "wwpn", "0x%016Lx", r->u.unit.wwpn);
365 zfcp_dbf_out(p, "fcp_lun", "0x%016Lx", r->u.unit.fcp_lun);
366 zfcp_dbf_out(p, "port_handle", "0x%08x", r->u.unit.port_handle);
367 zfcp_dbf_out(p, "lun_handle", "0x%08x", r->u.unit.lun_handle);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200368 break;
369
370 case FSF_QTCB_SEND_ELS:
Martin Peschke6bc473d2008-03-31 11:15:29 +0200371 zfcp_dbf_out(p, "d_id", "0x%06x", r->u.els.d_id);
372 zfcp_dbf_out(p, "ls_code", "0x%02x", r->u.els.ls_code);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200373 break;
374
375 case FSF_QTCB_ABORT_FCP_CMND:
376 case FSF_QTCB_SEND_GENERIC:
377 case FSF_QTCB_EXCHANGE_CONFIG_DATA:
378 case FSF_QTCB_EXCHANGE_PORT_DATA:
379 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
380 case FSF_QTCB_UPLOAD_CONTROL_FILE:
381 break;
382 }
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200383}
384
Martin Peschkea9c85772008-03-31 11:15:27 +0200385static void zfcp_hba_dbf_view_status(char **p,
386 struct zfcp_hba_dbf_record_status *r)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200387{
Martin Peschkea9c85772008-03-31 11:15:27 +0200388 zfcp_dbf_out(p, "failed", "0x%02x", r->failed);
389 zfcp_dbf_out(p, "status_type", "0x%08x", r->status_type);
390 zfcp_dbf_out(p, "status_subtype", "0x%08x", r->status_subtype);
391 zfcp_dbf_outd(p, "queue_designator", (char *)&r->queue_designator,
Martin Peschkedf29f4a2008-03-31 11:15:26 +0200392 sizeof(struct fsf_queue_designator), 0,
393 sizeof(struct fsf_queue_designator));
Martin Peschkea9c85772008-03-31 11:15:27 +0200394 zfcp_dbf_outd(p, "payload", (char *)&r->payload, r->payload_size, 0,
Martin Peschkedf29f4a2008-03-31 11:15:26 +0200395 r->payload_size);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200396}
397
Martin Peschkea9c85772008-03-31 11:15:27 +0200398static void zfcp_hba_dbf_view_qdio(char **p, struct zfcp_hba_dbf_record_qdio *r)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200399{
Martin Peschkea9c85772008-03-31 11:15:27 +0200400 zfcp_dbf_out(p, "status", "0x%08x", r->status);
401 zfcp_dbf_out(p, "qdio_error", "0x%08x", r->qdio_error);
402 zfcp_dbf_out(p, "siga_error", "0x%08x", r->siga_error);
403 zfcp_dbf_out(p, "sbal_index", "0x%02x", r->sbal_index);
404 zfcp_dbf_out(p, "sbal_count", "0x%02x", r->sbal_count);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200405}
406
Martin Peschkea9c85772008-03-31 11:15:27 +0200407static int zfcp_hba_dbf_view_format(debug_info_t *id, struct debug_view *view,
408 char *out_buf, const char *in_buf)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200409{
Martin Peschkea9c85772008-03-31 11:15:27 +0200410 struct zfcp_hba_dbf_record *r = (struct zfcp_hba_dbf_record *)in_buf;
411 char *p = out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200412
Martin Peschkea9c85772008-03-31 11:15:27 +0200413 if (strncmp(r->tag, "dump", ZFCP_DBF_TAG_SIZE) == 0)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200414 return 0;
415
Martin Peschkea9c85772008-03-31 11:15:27 +0200416 zfcp_dbf_tag(&p, "tag", r->tag);
417 if (isalpha(r->tag2[0]))
418 zfcp_dbf_tag(&p, "tag2", r->tag2);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200419
Martin Peschkea9c85772008-03-31 11:15:27 +0200420 if (strncmp(r->tag, "resp", ZFCP_DBF_TAG_SIZE) == 0)
Martin Peschke6bc473d2008-03-31 11:15:29 +0200421 zfcp_hba_dbf_view_response(&p, &r->u.response);
Martin Peschkea9c85772008-03-31 11:15:27 +0200422 else if (strncmp(r->tag, "stat", ZFCP_DBF_TAG_SIZE) == 0)
Martin Peschke6bc473d2008-03-31 11:15:29 +0200423 zfcp_hba_dbf_view_status(&p, &r->u.status);
Martin Peschkea9c85772008-03-31 11:15:27 +0200424 else if (strncmp(r->tag, "qdio", ZFCP_DBF_TAG_SIZE) == 0)
Martin Peschke6bc473d2008-03-31 11:15:29 +0200425 zfcp_hba_dbf_view_qdio(&p, &r->u.qdio);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200426
Martin Peschkea9c85772008-03-31 11:15:27 +0200427 p += sprintf(p, "\n");
428 return p - out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200429}
430
Heiko Carstens2b67fc42007-02-05 21:16:47 +0100431static struct debug_view zfcp_hba_dbf_view = {
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200432 "structured",
433 NULL,
434 &zfcp_dbf_view_header,
435 &zfcp_hba_dbf_view_format,
436 NULL,
437 NULL
438};
439
Martin Peschked79a83d2008-03-27 14:22:00 +0100440static const char *zfcp_rec_dbf_tags[] = {
Martin Peschke348447e2008-03-27 14:22:01 +0100441 [ZFCP_REC_DBF_ID_THREAD] = "thread",
Martin Peschke698ec0162008-03-27 14:22:02 +0100442 [ZFCP_REC_DBF_ID_TARGET] = "target",
Martin Peschke9467a9b2008-03-27 14:22:03 +0100443 [ZFCP_REC_DBF_ID_TRIGGER] = "trigger",
Martin Peschke6f4f3652008-03-27 14:22:04 +0100444 [ZFCP_REC_DBF_ID_ACTION] = "action",
Martin Peschked79a83d2008-03-27 14:22:00 +0100445};
446
447static const char *zfcp_rec_dbf_ids[] = {
Martin Peschke348447e2008-03-27 14:22:01 +0100448 [1] = "new",
449 [2] = "ready",
450 [3] = "kill",
451 [4] = "down sleep",
452 [5] = "down wakeup",
453 [6] = "down sleep ecd",
454 [7] = "down wakeup ecd",
455 [8] = "down sleep epd",
456 [9] = "down wakeup epd",
Martin Peschke698ec0162008-03-27 14:22:02 +0100457 [10] = "online",
458 [11] = "operational",
459 [12] = "scsi slave destroy",
460 [13] = "propagate failed adapter",
461 [14] = "propagate failed port",
462 [15] = "block adapter",
463 [16] = "unblock adapter",
464 [17] = "block port",
465 [18] = "unblock port",
466 [19] = "block unit",
467 [20] = "unblock unit",
468 [21] = "unit recovery failed",
469 [22] = "port recovery failed",
470 [23] = "adapter recovery failed",
471 [24] = "qdio queues down",
472 [25] = "p2p failed",
473 [26] = "nameserver lookup failed",
474 [27] = "nameserver port failed",
475 [28] = "link up",
476 [29] = "link down",
477 [30] = "link up status read",
478 [31] = "open port failed",
479 [32] = "open port failed",
480 [33] = "close port",
481 [34] = "open unit failed",
482 [35] = "exclusive open unit failed",
483 [36] = "shared open unit failed",
484 [37] = "link down",
485 [38] = "link down status read no link",
486 [39] = "link down status read fdisc login",
487 [40] = "link down status read firmware update",
488 [41] = "link down status read unknown reason",
489 [42] = "link down ecd incomplete",
490 [43] = "link down epd incomplete",
491 [44] = "sysfs adapter recovery",
492 [45] = "sysfs port recovery",
493 [46] = "sysfs unit recovery",
494 [47] = "port boxed abort",
495 [48] = "unit boxed abort",
496 [49] = "port boxed ct",
497 [50] = "port boxed close physical",
498 [51] = "port boxed open unit",
499 [52] = "port boxed close unit",
500 [53] = "port boxed fcp",
501 [54] = "unit boxed fcp",
502 [55] = "port access denied ct",
503 [56] = "port access denied els",
504 [57] = "port access denied open port",
505 [58] = "port access denied close physical",
506 [59] = "unit access denied open unit",
507 [60] = "shared unit access denied open unit",
508 [61] = "unit access denied fcp",
Martin Peschke9467a9b2008-03-27 14:22:03 +0100509 [62] = "request timeout",
510 [63] = "adisc link test reject or timeout",
511 [64] = "adisc link test d_id changed",
512 [65] = "adisc link test failed",
513 [66] = "recovery out of memory",
514 [67] = "adapter recovery repeated after state change",
515 [68] = "port recovery repeated after state change",
516 [69] = "unit recovery repeated after state change",
517 [70] = "port recovery follow-up after successful adapter recovery",
518 [71] = "adapter recovery escalation after failed adapter recovery",
519 [72] = "port recovery follow-up after successful physical port "
520 "recovery",
521 [73] = "adapter recovery escalation after failed physical port "
522 "recovery",
523 [74] = "unit recovery follow-up after successful port recovery",
524 [75] = "physical port recovery escalation after failed port "
525 "recovery",
526 [76] = "port recovery escalation after failed unit recovery",
527 [77] = "recovery opening nameserver port",
528 [78] = "duplicate request id",
529 [79] = "link down",
530 [80] = "exclusive read-only unit access unsupported",
531 [81] = "shared read-write unit access unsupported",
532 [82] = "incoming rscn",
533 [83] = "incoming plogi",
534 [84] = "incoming logo",
535 [85] = "online",
536 [86] = "offline",
537 [87] = "ccw device gone",
538 [88] = "ccw device no path",
539 [89] = "ccw device operational",
540 [90] = "ccw device shutdown",
541 [91] = "sysfs port addition",
542 [92] = "sysfs port removal",
543 [93] = "sysfs adapter recovery",
544 [94] = "sysfs unit addition",
545 [95] = "sysfs unit removal",
546 [96] = "sysfs port recovery",
547 [97] = "sysfs unit recovery",
548 [98] = "sequence number mismatch",
549 [99] = "link up",
550 [100] = "error state",
551 [101] = "status read physical port closed",
552 [102] = "link up status read",
553 [103] = "too many failed status read buffers",
554 [104] = "port handle not valid abort",
555 [105] = "lun handle not valid abort",
556 [106] = "port handle not valid ct",
557 [107] = "port handle not valid close port",
558 [108] = "port handle not valid close physical port",
559 [109] = "port handle not valid open unit",
560 [110] = "port handle not valid close unit",
561 [111] = "lun handle not valid close unit",
562 [112] = "port handle not valid fcp",
563 [113] = "lun handle not valid fcp",
564 [114] = "handle mismatch fcp",
565 [115] = "lun not valid fcp",
566 [116] = "qdio send failed",
567 [117] = "version mismatch",
568 [118] = "incompatible qtcb type",
569 [119] = "unknown protocol status",
570 [120] = "unknown fsf command",
571 [121] = "no recommendation for status qualifier",
572 [122] = "status read physical port closed in error",
573 [123] = "fc service class not supported ct",
574 [124] = "fc service class not supported els",
575 [125] = "need newer zfcp",
576 [126] = "need newer microcode",
577 [127] = "arbitrated loop not supported",
578 [128] = "unknown topology",
579 [129] = "qtcb size mismatch",
580 [130] = "unknown fsf status ecd",
581 [131] = "fcp request too big",
582 [132] = "fc service class not supported fcp",
583 [133] = "data direction not valid fcp",
584 [134] = "command length not valid fcp",
585 [135] = "status read act update",
586 [136] = "status read cfdc update",
587 [137] = "hbaapi port open",
588 [138] = "hbaapi unit open",
589 [139] = "hbaapi unit shutdown",
590 [140] = "qdio error",
591 [141] = "scsi host reset",
Martin Peschke6f4f3652008-03-27 14:22:04 +0100592 [142] = "dismissing fsf request for recovery action",
593 [143] = "recovery action timed out",
594 [144] = "recovery action gone",
595 [145] = "recovery action being processed",
596 [146] = "recovery action ready for next step",
Martin Peschked79a83d2008-03-27 14:22:00 +0100597};
598
599static int zfcp_rec_dbf_view_format(debug_info_t *id, struct debug_view *view,
600 char *buf, const char *_rec)
601{
602 struct zfcp_rec_dbf_record *r = (struct zfcp_rec_dbf_record *)_rec;
603 char *p = buf;
604
605 zfcp_dbf_outs(&p, "tag", zfcp_rec_dbf_tags[r->id]);
606 zfcp_dbf_outs(&p, "hint", zfcp_rec_dbf_ids[r->id2]);
607 zfcp_dbf_out(&p, "id", "%d", r->id2);
608 switch (r->id) {
Martin Peschke348447e2008-03-27 14:22:01 +0100609 case ZFCP_REC_DBF_ID_THREAD:
610 zfcp_dbf_out(&p, "sema", "%d", r->u.thread.sema);
611 zfcp_dbf_out(&p, "total", "%d", r->u.thread.total);
612 zfcp_dbf_out(&p, "ready", "%d", r->u.thread.ready);
613 zfcp_dbf_out(&p, "running", "%d", r->u.thread.running);
614 break;
Martin Peschke698ec0162008-03-27 14:22:02 +0100615 case ZFCP_REC_DBF_ID_TARGET:
616 zfcp_dbf_out(&p, "reference", "0x%016Lx", r->u.target.ref);
617 zfcp_dbf_out(&p, "status", "0x%08x", r->u.target.status);
618 zfcp_dbf_out(&p, "erp_count", "%d", r->u.target.erp_count);
619 zfcp_dbf_out(&p, "d_id", "0x%06x", r->u.target.d_id);
620 zfcp_dbf_out(&p, "wwpn", "0x%016Lx", r->u.target.wwpn);
621 zfcp_dbf_out(&p, "fcp_lun", "0x%016Lx", r->u.target.fcp_lun);
622 break;
Martin Peschke9467a9b2008-03-27 14:22:03 +0100623 case ZFCP_REC_DBF_ID_TRIGGER:
624 zfcp_dbf_out(&p, "reference", "0x%016Lx", r->u.trigger.ref);
625 zfcp_dbf_out(&p, "erp_action", "0x%016Lx", r->u.trigger.action);
626 zfcp_dbf_out(&p, "requested", "%d", r->u.trigger.want);
627 zfcp_dbf_out(&p, "executed", "%d", r->u.trigger.need);
628 zfcp_dbf_out(&p, "wwpn", "0x%016Lx", r->u.trigger.wwpn);
629 zfcp_dbf_out(&p, "fcp_lun", "0x%016Lx", r->u.trigger.fcp_lun);
630 zfcp_dbf_out(&p, "adapter_status", "0x%08x", r->u.trigger.as);
631 zfcp_dbf_out(&p, "port_status", "0x%08x", r->u.trigger.ps);
632 zfcp_dbf_out(&p, "unit_status", "0x%08x", r->u.trigger.us);
633 break;
Martin Peschke6f4f3652008-03-27 14:22:04 +0100634 case ZFCP_REC_DBF_ID_ACTION:
635 zfcp_dbf_out(&p, "erp_action", "0x%016Lx", r->u.action.action);
636 zfcp_dbf_out(&p, "fsf_req", "0x%016Lx", r->u.action.fsf_req);
637 zfcp_dbf_out(&p, "status", "0x%08Lx", r->u.action.status);
638 zfcp_dbf_out(&p, "step", "0x%08Lx", r->u.action.step);
639 break;
Martin Peschked79a83d2008-03-27 14:22:00 +0100640 }
Martin Peschkeb634fff2008-03-31 11:15:24 +0200641 p += sprintf(p, "\n");
642 return p - buf;
Martin Peschked79a83d2008-03-27 14:22:00 +0100643}
644
645static struct debug_view zfcp_rec_dbf_view = {
646 "structured",
647 NULL,
648 &zfcp_dbf_view_header,
649 &zfcp_rec_dbf_view_format,
650 NULL,
651 NULL
652};
653
Martin Peschke348447e2008-03-27 14:22:01 +0100654/**
655 * zfcp_rec_dbf_event_thread - trace event related to recovery thread operation
656 * @id2: identifier for event
657 * @adapter: adapter
658 * @lock: non-zero value indicates that erp_lock has not yet been acquired
659 */
660void zfcp_rec_dbf_event_thread(u8 id2, struct zfcp_adapter *adapter, int lock)
661{
662 struct zfcp_rec_dbf_record *r = &adapter->rec_dbf_buf;
663 unsigned long flags = 0;
664 struct list_head *entry;
665 unsigned ready = 0, running = 0, total;
666
667 if (lock)
668 read_lock_irqsave(&adapter->erp_lock, flags);
669 list_for_each(entry, &adapter->erp_ready_head)
670 ready++;
671 list_for_each(entry, &adapter->erp_running_head)
672 running++;
673 total = adapter->erp_total_count;
674 if (lock)
675 read_unlock_irqrestore(&adapter->erp_lock, flags);
676
677 spin_lock_irqsave(&adapter->rec_dbf_lock, flags);
678 memset(r, 0, sizeof(*r));
679 r->id = ZFCP_REC_DBF_ID_THREAD;
680 r->id2 = id2;
681 r->u.thread.sema = atomic_read(&adapter->erp_ready_sem.count);
682 r->u.thread.total = total;
683 r->u.thread.ready = ready;
684 r->u.thread.running = running;
685 debug_event(adapter->rec_dbf, 5, r, sizeof(*r));
686 spin_unlock_irqrestore(&adapter->rec_dbf_lock, flags);
687}
688
Martin Peschke698ec0162008-03-27 14:22:02 +0100689static void zfcp_rec_dbf_event_target(u8 id2, u64 ref,
690 struct zfcp_adapter *adapter,
691 atomic_t *status, atomic_t *erp_count,
692 u64 wwpn, u32 d_id, u64 fcp_lun)
693{
694 struct zfcp_rec_dbf_record *r = &adapter->rec_dbf_buf;
695 unsigned long flags;
696
697 spin_lock_irqsave(&adapter->rec_dbf_lock, flags);
698 memset(r, 0, sizeof(*r));
699 r->id = ZFCP_REC_DBF_ID_TARGET;
700 r->id2 = id2;
701 r->u.target.ref = ref;
702 r->u.target.status = atomic_read(status);
703 r->u.target.wwpn = wwpn;
704 r->u.target.d_id = d_id;
705 r->u.target.fcp_lun = fcp_lun;
706 r->u.target.erp_count = atomic_read(erp_count);
707 debug_event(adapter->rec_dbf, 3, r, sizeof(*r));
708 spin_unlock_irqrestore(&adapter->rec_dbf_lock, flags);
709}
710
711/**
712 * zfcp_rec_dbf_event_adapter - trace event for adapter state change
713 * @id: identifier for trigger of state change
714 * @ref: additional reference (e.g. request)
715 * @adapter: adapter
716 */
717void zfcp_rec_dbf_event_adapter(u8 id, u64 ref, struct zfcp_adapter *adapter)
718{
719 zfcp_rec_dbf_event_target(id, ref, adapter, &adapter->status,
720 &adapter->erp_counter, 0, 0, 0);
721}
722
723/**
724 * zfcp_rec_dbf_event_port - trace event for port state change
725 * @id: identifier for trigger of state change
726 * @ref: additional reference (e.g. request)
727 * @port: port
728 */
729void zfcp_rec_dbf_event_port(u8 id, u64 ref, struct zfcp_port *port)
730{
731 struct zfcp_adapter *adapter = port->adapter;
732
733 zfcp_rec_dbf_event_target(id, ref, adapter, &port->status,
734 &port->erp_counter, port->wwpn, port->d_id,
735 0);
736}
737
738/**
739 * zfcp_rec_dbf_event_unit - trace event for unit state change
740 * @id: identifier for trigger of state change
741 * @ref: additional reference (e.g. request)
742 * @unit: unit
743 */
744void zfcp_rec_dbf_event_unit(u8 id, u64 ref, struct zfcp_unit *unit)
745{
746 struct zfcp_port *port = unit->port;
747 struct zfcp_adapter *adapter = port->adapter;
748
749 zfcp_rec_dbf_event_target(id, ref, adapter, &unit->status,
750 &unit->erp_counter, port->wwpn, port->d_id,
751 unit->fcp_lun);
752}
753
Martin Peschke9467a9b2008-03-27 14:22:03 +0100754/**
755 * zfcp_rec_dbf_event_trigger - trace event for triggered error recovery
756 * @id2: identifier for error recovery trigger
757 * @ref: additional reference (e.g. request)
758 * @want: originally requested error recovery action
759 * @need: error recovery action actually initiated
760 * @action: address of error recovery action struct
761 * @adapter: adapter
762 * @port: port
763 * @unit: unit
764 */
765void zfcp_rec_dbf_event_trigger(u8 id2, u64 ref, u8 want, u8 need, u64 action,
766 struct zfcp_adapter *adapter,
767 struct zfcp_port *port, struct zfcp_unit *unit)
768{
769 struct zfcp_rec_dbf_record *r = &adapter->rec_dbf_buf;
770 unsigned long flags;
771
772 spin_lock_irqsave(&adapter->rec_dbf_lock, flags);
773 memset(r, 0, sizeof(*r));
774 r->id = ZFCP_REC_DBF_ID_TRIGGER;
775 r->id2 = id2;
776 r->u.trigger.ref = ref;
777 r->u.trigger.want = want;
778 r->u.trigger.need = need;
779 r->u.trigger.action = action;
780 r->u.trigger.as = atomic_read(&adapter->status);
781 if (port) {
782 r->u.trigger.ps = atomic_read(&port->status);
783 r->u.trigger.wwpn = port->wwpn;
784 }
785 if (unit) {
786 r->u.trigger.us = atomic_read(&unit->status);
787 r->u.trigger.fcp_lun = unit->fcp_lun;
788 }
789 debug_event(adapter->rec_dbf, action ? 1 : 4, r, sizeof(*r));
790 spin_unlock_irqrestore(&adapter->rec_dbf_lock, flags);
791}
792
Martin Peschke6f4f3652008-03-27 14:22:04 +0100793/**
794 * zfcp_rec_dbf_event_action - trace event showing progress of recovery action
795 * @id2: identifier
796 * @erp_action: error recovery action struct pointer
797 */
798void zfcp_rec_dbf_event_action(u8 id2, struct zfcp_erp_action *erp_action)
799{
800 struct zfcp_adapter *adapter = erp_action->adapter;
801 struct zfcp_rec_dbf_record *r = &adapter->rec_dbf_buf;
802 unsigned long flags;
803
804 spin_lock_irqsave(&adapter->rec_dbf_lock, flags);
805 memset(r, 0, sizeof(*r));
806 r->id = ZFCP_REC_DBF_ID_ACTION;
807 r->id2 = id2;
808 r->u.action.action = (u64)erp_action;
809 r->u.action.status = erp_action->status;
810 r->u.action.step = erp_action->step;
811 r->u.action.fsf_req = (u64)erp_action->fsf_req;
812 debug_event(adapter->rec_dbf, 4, r, sizeof(*r));
813 spin_unlock_irqrestore(&adapter->rec_dbf_lock, flags);
814}
815
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100816void zfcp_san_dbf_event_ct_request(struct zfcp_fsf_req *fsf_req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200817{
818 struct zfcp_send_ct *ct = (struct zfcp_send_ct *)fsf_req->data;
819 struct zfcp_port *port = ct->port;
820 struct zfcp_adapter *adapter = port->adapter;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200821 struct ct_hdr *hdr = zfcp_sg_to_address(ct->req);
822 struct zfcp_san_dbf_record *r = &adapter->san_dbf_buf;
823 struct zfcp_san_dbf_record_ct_request *oct = &r->u.ct_req;
824 unsigned long flags;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200825
Martin Peschke6bc473d2008-03-31 11:15:29 +0200826 spin_lock_irqsave(&adapter->san_dbf_lock, flags);
827 memset(r, 0, sizeof(*r));
828 strncpy(r->tag, "octc", ZFCP_DBF_TAG_SIZE);
829 r->fsf_reqid = (unsigned long)fsf_req;
830 r->fsf_seqno = fsf_req->seq_no;
831 r->s_id = fc_host_port_id(adapter->scsi_host);
832 r->d_id = port->d_id;
833 oct->cmd_req_code = hdr->cmd_rsp_code;
834 oct->revision = hdr->revision;
835 oct->gs_type = hdr->gs_type;
836 oct->gs_subtype = hdr->gs_subtype;
837 oct->options = hdr->options;
838 oct->max_res_size = hdr->max_res_size;
839 oct->len = min((int)ct->req->length - (int)sizeof(struct ct_hdr),
840 ZFCP_DBF_CT_PAYLOAD);
841 memcpy(oct->payload, (void *)hdr + sizeof(struct ct_hdr), oct->len);
842 debug_event(adapter->san_dbf, 3, r, sizeof(*r));
843 spin_unlock_irqrestore(&adapter->san_dbf_lock, flags);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200844}
845
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100846void zfcp_san_dbf_event_ct_response(struct zfcp_fsf_req *fsf_req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200847{
848 struct zfcp_send_ct *ct = (struct zfcp_send_ct *)fsf_req->data;
849 struct zfcp_port *port = ct->port;
850 struct zfcp_adapter *adapter = port->adapter;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200851 struct ct_hdr *hdr = zfcp_sg_to_address(ct->resp);
852 struct zfcp_san_dbf_record *r = &adapter->san_dbf_buf;
853 struct zfcp_san_dbf_record_ct_response *rct = &r->u.ct_resp;
854 unsigned long flags;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200855
Martin Peschke6bc473d2008-03-31 11:15:29 +0200856 spin_lock_irqsave(&adapter->san_dbf_lock, flags);
857 memset(r, 0, sizeof(*r));
858 strncpy(r->tag, "rctc", ZFCP_DBF_TAG_SIZE);
859 r->fsf_reqid = (unsigned long)fsf_req;
860 r->fsf_seqno = fsf_req->seq_no;
861 r->s_id = port->d_id;
862 r->d_id = fc_host_port_id(adapter->scsi_host);
863 rct->cmd_rsp_code = hdr->cmd_rsp_code;
864 rct->revision = hdr->revision;
865 rct->reason_code = hdr->reason_code;
866 rct->expl = hdr->reason_code_expl;
867 rct->vendor_unique = hdr->vendor_unique;
868 rct->len = min((int)ct->resp->length - (int)sizeof(struct ct_hdr),
869 ZFCP_DBF_CT_PAYLOAD);
870 memcpy(rct->payload, (void *)hdr + sizeof(struct ct_hdr), rct->len);
871 debug_event(adapter->san_dbf, 3, r, sizeof(*r));
872 spin_unlock_irqrestore(&adapter->san_dbf_lock, flags);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200873}
874
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100875static void
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200876_zfcp_san_dbf_event_common_els(const char *tag, int level,
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200877 struct zfcp_fsf_req *fsf_req, u32 s_id,
878 u32 d_id, u8 ls_code, void *buffer, int buflen)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200879{
880 struct zfcp_adapter *adapter = fsf_req->adapter;
881 struct zfcp_san_dbf_record *rec = &adapter->san_dbf_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200882 unsigned long flags;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200883
884 spin_lock_irqsave(&adapter->san_dbf_lock, flags);
Martin Peschke6bc473d2008-03-31 11:15:29 +0200885 memset(rec, 0, sizeof(*rec));
Martin Peschke0f65e952008-03-27 14:21:56 +0100886 strncpy(rec->tag, tag, ZFCP_DBF_TAG_SIZE);
887 rec->fsf_reqid = (unsigned long)fsf_req;
888 rec->fsf_seqno = fsf_req->seq_no;
889 rec->s_id = s_id;
890 rec->d_id = d_id;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200891 rec->u.els.ls_code = ls_code;
Martin Peschke0f65e952008-03-27 14:21:56 +0100892 debug_event(adapter->san_dbf, level, rec, sizeof(*rec));
893 zfcp_dbf_hexdump(adapter->san_dbf, rec, sizeof(*rec), level,
894 buffer, min(buflen, ZFCP_DBF_ELS_MAX_PAYLOAD));
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200895 spin_unlock_irqrestore(&adapter->san_dbf_lock, flags);
896}
897
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100898void zfcp_san_dbf_event_els_request(struct zfcp_fsf_req *fsf_req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200899{
900 struct zfcp_send_els *els = (struct zfcp_send_els *)fsf_req->data;
901
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200902 _zfcp_san_dbf_event_common_els("oels", 2, fsf_req,
903 fc_host_port_id(els->adapter->scsi_host),
904 els->d_id,
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200905 *(u8 *) zfcp_sg_to_address(els->req),
906 zfcp_sg_to_address(els->req),
907 els->req->length);
908}
909
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100910void zfcp_san_dbf_event_els_response(struct zfcp_fsf_req *fsf_req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200911{
912 struct zfcp_send_els *els = (struct zfcp_send_els *)fsf_req->data;
913
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200914 _zfcp_san_dbf_event_common_els("rels", 2, fsf_req, els->d_id,
915 fc_host_port_id(els->adapter->scsi_host),
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200916 *(u8 *) zfcp_sg_to_address(els->req),
917 zfcp_sg_to_address(els->resp),
918 els->resp->length);
919}
920
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100921void zfcp_san_dbf_event_incoming_els(struct zfcp_fsf_req *fsf_req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200922{
923 struct zfcp_adapter *adapter = fsf_req->adapter;
924 struct fsf_status_read_buffer *status_buffer =
925 (struct fsf_status_read_buffer *)fsf_req->data;
926 int length = (int)status_buffer->length -
927 (int)((void *)&status_buffer->payload - (void *)status_buffer);
928
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200929 _zfcp_san_dbf_event_common_els("iels", 1, fsf_req, status_buffer->d_id,
930 fc_host_port_id(adapter->scsi_host),
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200931 *(u8 *) status_buffer->payload,
932 (void *)status_buffer->payload, length);
933}
934
935static int
936zfcp_san_dbf_view_format(debug_info_t * id, struct debug_view *view,
937 char *out_buf, const char *in_buf)
938{
Martin Peschkeb634fff2008-03-31 11:15:24 +0200939 struct zfcp_san_dbf_record *r = (struct zfcp_san_dbf_record *)in_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200940 char *buffer = NULL;
941 int buflen = 0, total = 0;
Martin Peschkeb634fff2008-03-31 11:15:24 +0200942 char *p = out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200943
Martin Peschkeb634fff2008-03-31 11:15:24 +0200944 if (strncmp(r->tag, "dump", ZFCP_DBF_TAG_SIZE) == 0)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200945 return 0;
946
Martin Peschkea9c85772008-03-31 11:15:27 +0200947 zfcp_dbf_tag(&p, "tag", r->tag);
Martin Peschkeb634fff2008-03-31 11:15:24 +0200948 zfcp_dbf_out(&p, "fsf_reqid", "0x%0Lx", r->fsf_reqid);
949 zfcp_dbf_out(&p, "fsf_seqno", "0x%08x", r->fsf_seqno);
950 zfcp_dbf_out(&p, "s_id", "0x%06x", r->s_id);
951 zfcp_dbf_out(&p, "d_id", "0x%06x", r->d_id);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200952
Martin Peschkeb634fff2008-03-31 11:15:24 +0200953 if (strncmp(r->tag, "octc", ZFCP_DBF_TAG_SIZE) == 0) {
Martin Peschke6bc473d2008-03-31 11:15:29 +0200954 struct zfcp_san_dbf_record_ct_request *ct = &r->u.ct_req;
955 zfcp_dbf_out(&p, "cmd_req_code", "0x%04x", ct->cmd_req_code);
956 zfcp_dbf_out(&p, "revision", "0x%02x", ct->revision);
957 zfcp_dbf_out(&p, "gs_type", "0x%02x", ct->gs_type);
958 zfcp_dbf_out(&p, "gs_subtype", "0x%02x", ct->gs_subtype);
959 zfcp_dbf_out(&p, "options", "0x%02x", ct->options);
960 zfcp_dbf_out(&p, "max_res_size", "0x%04x", ct->max_res_size);
961 total = ct->len;
962 buffer = ct->payload;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200963 buflen = min(total, ZFCP_DBF_CT_PAYLOAD);
Martin Peschkeb634fff2008-03-31 11:15:24 +0200964 } else if (strncmp(r->tag, "rctc", ZFCP_DBF_TAG_SIZE) == 0) {
Martin Peschke6bc473d2008-03-31 11:15:29 +0200965 struct zfcp_san_dbf_record_ct_response *ct = &r->u.ct_resp;
966 zfcp_dbf_out(&p, "cmd_rsp_code", "0x%04x", ct->cmd_rsp_code);
967 zfcp_dbf_out(&p, "revision", "0x%02x", ct->revision);
968 zfcp_dbf_out(&p, "reason_code", "0x%02x", ct->reason_code);
969 zfcp_dbf_out(&p, "reason_code_expl", "0x%02x", ct->expl);
970 zfcp_dbf_out(&p, "vendor_unique", "0x%02x", ct->vendor_unique);
971 total = ct->len;
972 buffer = ct->payload;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200973 buflen = min(total, ZFCP_DBF_CT_PAYLOAD);
Martin Peschkeb634fff2008-03-31 11:15:24 +0200974 } else if (strncmp(r->tag, "oels", ZFCP_DBF_TAG_SIZE) == 0 ||
975 strncmp(r->tag, "rels", ZFCP_DBF_TAG_SIZE) == 0 ||
976 strncmp(r->tag, "iels", ZFCP_DBF_TAG_SIZE) == 0) {
Martin Peschke6bc473d2008-03-31 11:15:29 +0200977 struct zfcp_san_dbf_record_els *els = &r->u.els;
978 zfcp_dbf_out(&p, "ls_code", "0x%02x", els->ls_code);
979 total = els->len;
980 buffer = els->payload;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200981 buflen = min(total, ZFCP_DBF_ELS_PAYLOAD);
982 }
983
Martin Peschkedf29f4a2008-03-31 11:15:26 +0200984 zfcp_dbf_outd(&p, "payload", buffer, buflen, 0, total);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200985 if (buflen == total)
Martin Peschkeb634fff2008-03-31 11:15:24 +0200986 p += sprintf(p, "\n");
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200987
Martin Peschkeb634fff2008-03-31 11:15:24 +0200988 return p - out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200989}
990
Heiko Carstens2b67fc42007-02-05 21:16:47 +0100991static struct debug_view zfcp_san_dbf_view = {
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200992 "structured",
993 NULL,
994 &zfcp_dbf_view_header,
995 &zfcp_san_dbf_view_format,
996 NULL,
997 NULL
998};
999
Heiko Carstens4d284ca2007-02-05 21:18:53 +01001000static void
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001001_zfcp_scsi_dbf_event_common(const char *tag, const char *tag2, int level,
1002 struct zfcp_adapter *adapter,
1003 struct scsi_cmnd *scsi_cmnd,
Maxim Shchetynined829ad2006-02-11 01:42:58 +01001004 struct zfcp_fsf_req *fsf_req,
Andreas Herrmann4eff4a32006-09-18 22:29:20 +02001005 unsigned long old_req_id)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001006{
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001007 struct zfcp_scsi_dbf_record *rec = &adapter->scsi_dbf_buf;
1008 struct zfcp_dbf_dump *dump = (struct zfcp_dbf_dump *)rec;
1009 unsigned long flags;
1010 struct fcp_rsp_iu *fcp_rsp;
1011 char *fcp_rsp_info = NULL, *fcp_sns_info = NULL;
1012 int offset = 0, buflen = 0;
1013
1014 spin_lock_irqsave(&adapter->scsi_dbf_lock, flags);
1015 do {
Martin Peschke6bc473d2008-03-31 11:15:29 +02001016 memset(rec, 0, sizeof(*rec));
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001017 if (offset == 0) {
1018 strncpy(rec->tag, tag, ZFCP_DBF_TAG_SIZE);
1019 strncpy(rec->tag2, tag2, ZFCP_DBF_TAG_SIZE);
Maxim Shchetynined829ad2006-02-11 01:42:58 +01001020 if (scsi_cmnd != NULL) {
1021 if (scsi_cmnd->device) {
1022 rec->scsi_id = scsi_cmnd->device->id;
1023 rec->scsi_lun = scsi_cmnd->device->lun;
1024 }
1025 rec->scsi_result = scsi_cmnd->result;
1026 rec->scsi_cmnd = (unsigned long)scsi_cmnd;
1027 rec->scsi_serial = scsi_cmnd->serial_number;
1028 memcpy(rec->scsi_opcode, &scsi_cmnd->cmnd,
1029 min((int)scsi_cmnd->cmd_len,
1030 ZFCP_DBF_SCSI_OPCODE));
1031 rec->scsi_retries = scsi_cmnd->retries;
1032 rec->scsi_allowed = scsi_cmnd->allowed;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001033 }
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001034 if (fsf_req != NULL) {
1035 fcp_rsp = (struct fcp_rsp_iu *)
1036 &(fsf_req->qtcb->bottom.io.fcp_rsp);
1037 fcp_rsp_info =
1038 zfcp_get_fcp_rsp_info_ptr(fcp_rsp);
1039 fcp_sns_info =
1040 zfcp_get_fcp_sns_info_ptr(fcp_rsp);
1041
Martin Peschke6bc473d2008-03-31 11:15:29 +02001042 rec->rsp_validity = fcp_rsp->validity.value;
1043 rec->rsp_scsi_status = fcp_rsp->scsi_status;
1044 rec->rsp_resid = fcp_rsp->fcp_resid;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001045 if (fcp_rsp->validity.bits.fcp_rsp_len_valid)
Martin Peschke6bc473d2008-03-31 11:15:29 +02001046 rec->rsp_code = *(fcp_rsp_info + 3);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001047 if (fcp_rsp->validity.bits.fcp_sns_len_valid) {
1048 buflen = min((int)fcp_rsp->fcp_sns_len,
1049 ZFCP_DBF_SCSI_MAX_FCP_SNS_INFO);
Martin Peschke6bc473d2008-03-31 11:15:29 +02001050 rec->sns_info_len = buflen;
1051 memcpy(rec->sns_info, fcp_sns_info,
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001052 min(buflen,
1053 ZFCP_DBF_SCSI_FCP_SNS_INFO));
1054 offset += min(buflen,
1055 ZFCP_DBF_SCSI_FCP_SNS_INFO);
1056 }
1057
1058 rec->fsf_reqid = (unsigned long)fsf_req;
1059 rec->fsf_seqno = fsf_req->seq_no;
1060 rec->fsf_issued = fsf_req->issued;
1061 }
Martin Peschke6bc473d2008-03-31 11:15:29 +02001062 rec->old_fsf_reqid = old_req_id;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001063 } else {
1064 strncpy(dump->tag, "dump", ZFCP_DBF_TAG_SIZE);
1065 dump->total_size = buflen;
1066 dump->offset = offset;
1067 dump->size = min(buflen - offset,
1068 (int)sizeof(struct
1069 zfcp_scsi_dbf_record) -
1070 (int)sizeof(struct zfcp_dbf_dump));
1071 memcpy(dump->data, fcp_sns_info + offset, dump->size);
1072 offset += dump->size;
1073 }
Martin Peschke6bc473d2008-03-31 11:15:29 +02001074 debug_event(adapter->scsi_dbf, level, rec, sizeof(*rec));
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001075 } while (offset < buflen);
1076 spin_unlock_irqrestore(&adapter->scsi_dbf_lock, flags);
1077}
1078
Heiko Carstens4d284ca2007-02-05 21:18:53 +01001079void
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001080zfcp_scsi_dbf_event_result(const char *tag, int level,
1081 struct zfcp_adapter *adapter,
Maxim Shchetynined829ad2006-02-11 01:42:58 +01001082 struct scsi_cmnd *scsi_cmnd,
1083 struct zfcp_fsf_req *fsf_req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001084{
Maxim Shchetynined829ad2006-02-11 01:42:58 +01001085 _zfcp_scsi_dbf_event_common("rslt", tag, level,
Andreas Herrmann4eff4a32006-09-18 22:29:20 +02001086 adapter, scsi_cmnd, fsf_req, 0);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001087}
1088
Heiko Carstens4d284ca2007-02-05 21:18:53 +01001089void
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001090zfcp_scsi_dbf_event_abort(const char *tag, struct zfcp_adapter *adapter,
1091 struct scsi_cmnd *scsi_cmnd,
Maxim Shchetynined829ad2006-02-11 01:42:58 +01001092 struct zfcp_fsf_req *new_fsf_req,
Andreas Herrmann4eff4a32006-09-18 22:29:20 +02001093 unsigned long old_req_id)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001094{
Maxim Shchetynined829ad2006-02-11 01:42:58 +01001095 _zfcp_scsi_dbf_event_common("abrt", tag, 1,
Andreas Herrmann4eff4a32006-09-18 22:29:20 +02001096 adapter, scsi_cmnd, new_fsf_req, old_req_id);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001097}
1098
Heiko Carstens4d284ca2007-02-05 21:18:53 +01001099void
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001100zfcp_scsi_dbf_event_devreset(const char *tag, u8 flag, struct zfcp_unit *unit,
1101 struct scsi_cmnd *scsi_cmnd)
1102{
1103 struct zfcp_adapter *adapter = unit->port->adapter;
1104
1105 _zfcp_scsi_dbf_event_common(flag == FCP_TARGET_RESET ? "trst" : "lrst",
Andreas Herrmann4eff4a32006-09-18 22:29:20 +02001106 tag, 1, adapter, scsi_cmnd, NULL, 0);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001107}
1108
1109static int
1110zfcp_scsi_dbf_view_format(debug_info_t * id, struct debug_view *view,
1111 char *out_buf, const char *in_buf)
1112{
Martin Peschkeb634fff2008-03-31 11:15:24 +02001113 struct zfcp_scsi_dbf_record *r = (struct zfcp_scsi_dbf_record *)in_buf;
Martin Peschke8fc5af12008-03-31 11:15:23 +02001114 struct timespec t;
Martin Peschkeb634fff2008-03-31 11:15:24 +02001115 char *p = out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001116
Martin Peschkeb634fff2008-03-31 11:15:24 +02001117 if (strncmp(r->tag, "dump", ZFCP_DBF_TAG_SIZE) == 0)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001118 return 0;
1119
Martin Peschkea9c85772008-03-31 11:15:27 +02001120 zfcp_dbf_tag(&p, "tag", r->tag);
1121 zfcp_dbf_tag(&p, "tag2", r->tag2);
Martin Peschkeb634fff2008-03-31 11:15:24 +02001122 zfcp_dbf_out(&p, "scsi_id", "0x%08x", r->scsi_id);
1123 zfcp_dbf_out(&p, "scsi_lun", "0x%08x", r->scsi_lun);
1124 zfcp_dbf_out(&p, "scsi_result", "0x%08x", r->scsi_result);
1125 zfcp_dbf_out(&p, "scsi_cmnd", "0x%0Lx", r->scsi_cmnd);
1126 zfcp_dbf_out(&p, "scsi_serial", "0x%016Lx", r->scsi_serial);
Martin Peschkedf29f4a2008-03-31 11:15:26 +02001127 zfcp_dbf_outd(&p, "scsi_opcode", r->scsi_opcode, ZFCP_DBF_SCSI_OPCODE,
1128 0, ZFCP_DBF_SCSI_OPCODE);
Martin Peschkeb634fff2008-03-31 11:15:24 +02001129 zfcp_dbf_out(&p, "scsi_retries", "0x%02x", r->scsi_retries);
1130 zfcp_dbf_out(&p, "scsi_allowed", "0x%02x", r->scsi_allowed);
1131 if (strncmp(r->tag, "abrt", ZFCP_DBF_TAG_SIZE) == 0)
Martin Peschke6bc473d2008-03-31 11:15:29 +02001132 zfcp_dbf_out(&p, "old_fsf_reqid", "0x%0Lx", r->old_fsf_reqid);
Martin Peschkeb634fff2008-03-31 11:15:24 +02001133 zfcp_dbf_out(&p, "fsf_reqid", "0x%0Lx", r->fsf_reqid);
1134 zfcp_dbf_out(&p, "fsf_seqno", "0x%08x", r->fsf_seqno);
1135 zfcp_dbf_timestamp(r->fsf_issued, &t);
1136 zfcp_dbf_out(&p, "fsf_issued", "%011lu:%06lu", t.tv_sec, t.tv_nsec);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001137
Martin Peschkeb634fff2008-03-31 11:15:24 +02001138 if (strncmp(r->tag, "rslt", ZFCP_DBF_TAG_SIZE) == 0) {
Martin Peschke6bc473d2008-03-31 11:15:29 +02001139 zfcp_dbf_out(&p, "fcp_rsp_validity", "0x%02x", r->rsp_validity);
1140 zfcp_dbf_out(&p, "fcp_rsp_scsi_status", "0x%02x",
1141 r->rsp_scsi_status);
1142 zfcp_dbf_out(&p, "fcp_rsp_resid", "0x%08x", r->rsp_resid);
1143 zfcp_dbf_out(&p, "fcp_rsp_code", "0x%08x", r->rsp_code);
1144 zfcp_dbf_out(&p, "fcp_sns_info_len", "0x%08x", r->sns_info_len);
1145 zfcp_dbf_outd(&p, "fcp_sns_info", r->sns_info,
1146 min((int)r->sns_info_len,
Martin Peschkedf29f4a2008-03-31 11:15:26 +02001147 ZFCP_DBF_SCSI_FCP_SNS_INFO), 0,
Martin Peschke6bc473d2008-03-31 11:15:29 +02001148 r->sns_info_len);
Martin Peschkeb634fff2008-03-31 11:15:24 +02001149 }
1150 p += sprintf(p, "\n");
1151 return p - out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001152}
1153
Heiko Carstens2b67fc42007-02-05 21:16:47 +01001154static struct debug_view zfcp_scsi_dbf_view = {
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001155 "structured",
1156 NULL,
1157 &zfcp_dbf_view_header,
1158 &zfcp_scsi_dbf_view_format,
1159 NULL,
1160 NULL
1161};
1162
1163/**
1164 * zfcp_adapter_debug_register - registers debug feature for an adapter
1165 * @adapter: pointer to adapter for which debug features should be registered
1166 * return: -ENOMEM on error, 0 otherwise
1167 */
1168int zfcp_adapter_debug_register(struct zfcp_adapter *adapter)
1169{
1170 char dbf_name[DEBUG_MAX_NAME_LEN];
1171
1172 /* debug feature area which records recovery activity */
Martin Peschked79a83d2008-03-27 14:22:00 +01001173 sprintf(dbf_name, "zfcp_%s_rec", zfcp_get_busid_by_adapter(adapter));
1174 adapter->rec_dbf = debug_register(dbf_name, dbfsize, 1,
1175 sizeof(struct zfcp_rec_dbf_record));
1176 if (!adapter->rec_dbf)
1177 goto failed;
1178 debug_register_view(adapter->rec_dbf, &debug_hex_ascii_view);
1179 debug_register_view(adapter->rec_dbf, &zfcp_rec_dbf_view);
1180 debug_set_level(adapter->rec_dbf, 3);
1181
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001182 /* debug feature area which records HBA (FSF and QDIO) conditions */
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001183 sprintf(dbf_name, "zfcp_%s_hba", zfcp_get_busid_by_adapter(adapter));
1184 adapter->hba_dbf = debug_register(dbf_name, dbfsize, 1,
1185 sizeof(struct zfcp_hba_dbf_record));
1186 if (!adapter->hba_dbf)
1187 goto failed;
1188 debug_register_view(adapter->hba_dbf, &debug_hex_ascii_view);
1189 debug_register_view(adapter->hba_dbf, &zfcp_hba_dbf_view);
1190 debug_set_level(adapter->hba_dbf, 3);
1191
1192 /* debug feature area which records SAN command failures and recovery */
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001193 sprintf(dbf_name, "zfcp_%s_san", zfcp_get_busid_by_adapter(adapter));
1194 adapter->san_dbf = debug_register(dbf_name, dbfsize, 1,
1195 sizeof(struct zfcp_san_dbf_record));
1196 if (!adapter->san_dbf)
1197 goto failed;
1198 debug_register_view(adapter->san_dbf, &debug_hex_ascii_view);
1199 debug_register_view(adapter->san_dbf, &zfcp_san_dbf_view);
1200 debug_set_level(adapter->san_dbf, 6);
1201
1202 /* debug feature area which records SCSI command failures and recovery */
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001203 sprintf(dbf_name, "zfcp_%s_scsi", zfcp_get_busid_by_adapter(adapter));
1204 adapter->scsi_dbf = debug_register(dbf_name, dbfsize, 1,
1205 sizeof(struct zfcp_scsi_dbf_record));
1206 if (!adapter->scsi_dbf)
1207 goto failed;
1208 debug_register_view(adapter->scsi_dbf, &debug_hex_ascii_view);
1209 debug_register_view(adapter->scsi_dbf, &zfcp_scsi_dbf_view);
1210 debug_set_level(adapter->scsi_dbf, 3);
1211
1212 return 0;
1213
1214 failed:
1215 zfcp_adapter_debug_unregister(adapter);
1216
1217 return -ENOMEM;
1218}
1219
1220/**
1221 * zfcp_adapter_debug_unregister - unregisters debug feature for an adapter
1222 * @adapter: pointer to adapter for which debug features should be unregistered
1223 */
1224void zfcp_adapter_debug_unregister(struct zfcp_adapter *adapter)
1225{
1226 debug_unregister(adapter->scsi_dbf);
1227 debug_unregister(adapter->san_dbf);
1228 debug_unregister(adapter->hba_dbf);
Martin Peschked79a83d2008-03-27 14:22:00 +01001229 debug_unregister(adapter->rec_dbf);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001230 adapter->scsi_dbf = NULL;
1231 adapter->san_dbf = NULL;
1232 adapter->hba_dbf = NULL;
Martin Peschked79a83d2008-03-27 14:22:00 +01001233 adapter->rec_dbf = NULL;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001234}
1235
1236#undef ZFCP_LOG_AREA