blob: 0a2ffc635c77d38648c54dd59ebaeff35cc6d52d [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
Martin Peschke92c7a832008-03-31 11:15:30 +0200113static int zfcp_dbf_view_header(debug_info_t *id, struct debug_view *view,
114 int area, debug_entry_t *entry, char *out_buf)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200115{
116 struct zfcp_dbf_dump *dump = (struct zfcp_dbf_dump *)DEBUG_DATA(entry);
Martin Peschke8fc5af12008-03-31 11:15:23 +0200117 struct timespec t;
Martin Peschkeb634fff2008-03-31 11:15:24 +0200118 char *p = out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200119
120 if (strncmp(dump->tag, "dump", ZFCP_DBF_TAG_SIZE) != 0) {
Martin Peschke8fc5af12008-03-31 11:15:23 +0200121 zfcp_dbf_timestamp(entry->id.stck, &t);
Martin Peschkeb634fff2008-03-31 11:15:24 +0200122 zfcp_dbf_out(&p, "timestamp", "%011lu:%06lu",
123 t.tv_sec, t.tv_nsec);
124 zfcp_dbf_out(&p, "cpu", "%02i", entry->id.fields.cpuid);
125 } else {
Martin Peschkedf29f4a2008-03-31 11:15:26 +0200126 zfcp_dbf_outd(&p, NULL, dump->data, dump->size, dump->offset,
127 dump->total_size);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200128 if ((dump->offset + dump->size) == dump->total_size)
Martin Peschkeb634fff2008-03-31 11:15:24 +0200129 p += sprintf(p, "\n");
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200130 }
Martin Peschkeb634fff2008-03-31 11:15:24 +0200131 return p - out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200132}
133
Martin Peschkebfab1632008-03-31 11:15:31 +0200134/**
135 * zfcp_hba_dbf_event_fsf_response - trace event for request completion
136 * @fsf_req: request that has been completed
137 */
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100138void zfcp_hba_dbf_event_fsf_response(struct zfcp_fsf_req *fsf_req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200139{
140 struct zfcp_adapter *adapter = fsf_req->adapter;
141 struct fsf_qtcb *qtcb = fsf_req->qtcb;
142 union fsf_prot_status_qual *prot_status_qual =
Martin Peschke92c7a832008-03-31 11:15:30 +0200143 &qtcb->prefix.prot_status_qual;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200144 union fsf_status_qual *fsf_status_qual = &qtcb->header.fsf_status_qual;
145 struct scsi_cmnd *scsi_cmnd;
146 struct zfcp_port *port;
147 struct zfcp_unit *unit;
148 struct zfcp_send_els *send_els;
149 struct zfcp_hba_dbf_record *rec = &adapter->hba_dbf_buf;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200150 struct zfcp_hba_dbf_record_response *response = &rec->u.response;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200151 int level;
152 unsigned long flags;
153
154 spin_lock_irqsave(&adapter->hba_dbf_lock, flags);
Martin Peschke6bc473d2008-03-31 11:15:29 +0200155 memset(rec, 0, sizeof(*rec));
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200156 strncpy(rec->tag, "resp", ZFCP_DBF_TAG_SIZE);
157
158 if ((qtcb->prefix.prot_status != FSF_PROT_GOOD) &&
159 (qtcb->prefix.prot_status != FSF_PROT_FSF_STATUS_PRESENTED)) {
160 strncpy(rec->tag2, "perr", ZFCP_DBF_TAG_SIZE);
161 level = 1;
162 } else if (qtcb->header.fsf_status != FSF_GOOD) {
163 strncpy(rec->tag2, "ferr", ZFCP_DBF_TAG_SIZE);
164 level = 1;
165 } else if ((fsf_req->fsf_command == FSF_QTCB_OPEN_PORT_WITH_DID) ||
166 (fsf_req->fsf_command == FSF_QTCB_OPEN_LUN)) {
167 strncpy(rec->tag2, "open", ZFCP_DBF_TAG_SIZE);
168 level = 4;
Martin Peschkeb75db732008-03-27 14:21:58 +0100169 } else if (qtcb->header.log_length) {
170 strncpy(rec->tag2, "qtcb", ZFCP_DBF_TAG_SIZE);
171 level = 5;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200172 } else {
173 strncpy(rec->tag2, "norm", ZFCP_DBF_TAG_SIZE);
174 level = 6;
175 }
176
177 response->fsf_command = fsf_req->fsf_command;
178 response->fsf_reqid = (unsigned long)fsf_req;
179 response->fsf_seqno = fsf_req->seq_no;
180 response->fsf_issued = fsf_req->issued;
181 response->fsf_prot_status = qtcb->prefix.prot_status;
182 response->fsf_status = qtcb->header.fsf_status;
183 memcpy(response->fsf_prot_status_qual,
184 prot_status_qual, FSF_PROT_STATUS_QUAL_SIZE);
185 memcpy(response->fsf_status_qual,
186 fsf_status_qual, FSF_STATUS_QUALIFIER_SIZE);
187 response->fsf_req_status = fsf_req->status;
188 response->sbal_first = fsf_req->sbal_first;
Martin Peschkee891bff2008-05-19 12:17:43 +0200189 response->sbal_last = fsf_req->sbal_last;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200190 response->pool = fsf_req->pool != NULL;
191 response->erp_action = (unsigned long)fsf_req->erp_action;
192
193 switch (fsf_req->fsf_command) {
194 case FSF_QTCB_FCP_CMND:
195 if (fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT)
196 break;
197 scsi_cmnd = (struct scsi_cmnd *)fsf_req->data;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200198 if (scsi_cmnd) {
199 response->u.fcp.cmnd = (unsigned long)scsi_cmnd;
200 response->u.fcp.serial = scsi_cmnd->serial_number;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200201 }
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;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200208 response->u.port.wwpn = port->wwpn;
209 response->u.port.d_id = port->d_id;
210 response->u.port.port_handle = qtcb->header.port_handle;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200211 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;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200217 response->u.unit.wwpn = port->wwpn;
218 response->u.unit.fcp_lun = unit->fcp_lun;
219 response->u.unit.port_handle = qtcb->header.port_handle;
220 response->u.unit.lun_handle = qtcb->header.lun_handle;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200221 break;
222
223 case FSF_QTCB_SEND_ELS:
224 send_els = (struct zfcp_send_els *)fsf_req->data;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200225 response->u.els.d_id = qtcb->bottom.support.d_id;
226 response->u.els.ls_code = send_els->ls_code >> 24;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200227 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
Martin Peschke6bc473d2008-03-31 11:15:29 +0200238 debug_event(adapter->hba_dbf, level, rec, sizeof(*rec));
Martin Peschkeb75db732008-03-27 14:21:58 +0100239
240 /* have fcp channel microcode fixed to use as little as possible */
241 if (fsf_req->fsf_command != FSF_QTCB_FCP_CMND) {
242 /* adjust length skipping trailing zeros */
243 char *buf = (char *)qtcb + qtcb->header.log_start;
244 int len = qtcb->header.log_length;
245 for (; len && !buf[len - 1]; len--);
246 zfcp_dbf_hexdump(adapter->hba_dbf, rec, sizeof(*rec), level,
247 buf, len);
248 }
249
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200250 spin_unlock_irqrestore(&adapter->hba_dbf_lock, flags);
251}
252
Martin Peschkebfab1632008-03-31 11:15:31 +0200253/**
254 * zfcp_hba_dbf_event_fsf_unsol - trace event for an unsolicited status buffer
255 * @tag: tag indicating which kind of unsolicited status has been received
256 * @adapter: adapter that has issued the unsolicited status buffer
257 * @status_buffer: buffer containing payload of unsolicited status
258 */
Martin Peschke92c7a832008-03-31 11:15:30 +0200259void zfcp_hba_dbf_event_fsf_unsol(const char *tag, struct zfcp_adapter *adapter,
260 struct fsf_status_read_buffer *status_buffer)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200261{
262 struct zfcp_hba_dbf_record *rec = &adapter->hba_dbf_buf;
263 unsigned long flags;
264
265 spin_lock_irqsave(&adapter->hba_dbf_lock, flags);
Martin Peschke6bc473d2008-03-31 11:15:29 +0200266 memset(rec, 0, sizeof(*rec));
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200267 strncpy(rec->tag, "stat", ZFCP_DBF_TAG_SIZE);
268 strncpy(rec->tag2, tag, ZFCP_DBF_TAG_SIZE);
269
Swen Schilligd26ab062008-05-19 12:17:37 +0200270 rec->u.status.failed = atomic_read(&adapter->stat_miss);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200271 if (status_buffer != NULL) {
Martin Peschke6bc473d2008-03-31 11:15:29 +0200272 rec->u.status.status_type = status_buffer->status_type;
273 rec->u.status.status_subtype = status_buffer->status_subtype;
274 memcpy(&rec->u.status.queue_designator,
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200275 &status_buffer->queue_designator,
276 sizeof(struct fsf_queue_designator));
277
278 switch (status_buffer->status_type) {
279 case FSF_STATUS_READ_SENSE_DATA_AVAIL:
Martin Peschke6bc473d2008-03-31 11:15:29 +0200280 rec->u.status.payload_size =
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200281 ZFCP_DBF_UNSOL_PAYLOAD_SENSE_DATA_AVAIL;
282 break;
283
284 case FSF_STATUS_READ_BIT_ERROR_THRESHOLD:
Martin Peschke6bc473d2008-03-31 11:15:29 +0200285 rec->u.status.payload_size =
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200286 ZFCP_DBF_UNSOL_PAYLOAD_BIT_ERROR_THRESHOLD;
287 break;
288
289 case FSF_STATUS_READ_LINK_DOWN:
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200290 switch (status_buffer->status_subtype) {
291 case FSF_STATUS_READ_SUB_NO_PHYSICAL_LINK:
292 case FSF_STATUS_READ_SUB_FDISC_FAILED:
Martin Peschke6bc473d2008-03-31 11:15:29 +0200293 rec->u.status.payload_size =
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200294 sizeof(struct fsf_link_down_info);
295 }
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200296 break;
297
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200298 case FSF_STATUS_READ_FEATURE_UPDATE_ALERT:
Martin Peschke6bc473d2008-03-31 11:15:29 +0200299 rec->u.status.payload_size =
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200300 ZFCP_DBF_UNSOL_PAYLOAD_FEATURE_UPDATE_ALERT;
301 break;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200302 }
Martin Peschke6bc473d2008-03-31 11:15:29 +0200303 memcpy(&rec->u.status.payload,
304 &status_buffer->payload, rec->u.status.payload_size);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200305 }
306
Martin Peschke6bc473d2008-03-31 11:15:29 +0200307 debug_event(adapter->hba_dbf, 2, rec, sizeof(*rec));
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200308 spin_unlock_irqrestore(&adapter->hba_dbf_lock, flags);
309}
310
Martin Peschkebfab1632008-03-31 11:15:31 +0200311/**
312 * zfcp_hba_dbf_event_qdio - trace event for QDIO related failure
313 * @adapter: adapter affected by this QDIO related event
314 * @status: as passed by qdio module
315 * @qdio_error: as passed by qdio module
316 * @siga_error: as passed by qdio module
317 * @sbal_index: first buffer with error condition, as passed by qdio module
318 * @sbal_count: number of buffers affected, as passed by qdio module
319 */
Martin Peschke92c7a832008-03-31 11:15:30 +0200320void zfcp_hba_dbf_event_qdio(struct zfcp_adapter *adapter, unsigned int status,
321 unsigned int qdio_error, unsigned int siga_error,
322 int sbal_index, int sbal_count)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200323{
Martin Peschke6bc473d2008-03-31 11:15:29 +0200324 struct zfcp_hba_dbf_record *r = &adapter->hba_dbf_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200325 unsigned long flags;
326
327 spin_lock_irqsave(&adapter->hba_dbf_lock, flags);
Martin Peschke6bc473d2008-03-31 11:15:29 +0200328 memset(r, 0, sizeof(*r));
329 strncpy(r->tag, "qdio", ZFCP_DBF_TAG_SIZE);
330 r->u.qdio.status = status;
331 r->u.qdio.qdio_error = qdio_error;
332 r->u.qdio.siga_error = siga_error;
333 r->u.qdio.sbal_index = sbal_index;
334 r->u.qdio.sbal_count = sbal_count;
335 debug_event(adapter->hba_dbf, 0, r, sizeof(*r));
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200336 spin_unlock_irqrestore(&adapter->hba_dbf_lock, flags);
337}
338
Martin Peschkea9c85772008-03-31 11:15:27 +0200339static void zfcp_hba_dbf_view_response(char **p,
340 struct zfcp_hba_dbf_record_response *r)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200341{
Martin Peschke8fc5af12008-03-31 11:15:23 +0200342 struct timespec t;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200343
Martin Peschkea9c85772008-03-31 11:15:27 +0200344 zfcp_dbf_out(p, "fsf_command", "0x%08x", r->fsf_command);
345 zfcp_dbf_out(p, "fsf_reqid", "0x%0Lx", r->fsf_reqid);
346 zfcp_dbf_out(p, "fsf_seqno", "0x%08x", r->fsf_seqno);
Martin Peschkeb634fff2008-03-31 11:15:24 +0200347 zfcp_dbf_timestamp(r->fsf_issued, &t);
Martin Peschkea9c85772008-03-31 11:15:27 +0200348 zfcp_dbf_out(p, "fsf_issued", "%011lu:%06lu", t.tv_sec, t.tv_nsec);
349 zfcp_dbf_out(p, "fsf_prot_status", "0x%08x", r->fsf_prot_status);
350 zfcp_dbf_out(p, "fsf_status", "0x%08x", r->fsf_status);
351 zfcp_dbf_outd(p, "fsf_prot_status_qual", r->fsf_prot_status_qual,
Martin Peschkedf29f4a2008-03-31 11:15:26 +0200352 FSF_PROT_STATUS_QUAL_SIZE, 0, FSF_PROT_STATUS_QUAL_SIZE);
Martin Peschkea9c85772008-03-31 11:15:27 +0200353 zfcp_dbf_outd(p, "fsf_status_qual", r->fsf_status_qual,
Martin Peschkedf29f4a2008-03-31 11:15:26 +0200354 FSF_STATUS_QUALIFIER_SIZE, 0, FSF_STATUS_QUALIFIER_SIZE);
Martin Peschkea9c85772008-03-31 11:15:27 +0200355 zfcp_dbf_out(p, "fsf_req_status", "0x%08x", r->fsf_req_status);
356 zfcp_dbf_out(p, "sbal_first", "0x%02x", r->sbal_first);
Martin Peschkee891bff2008-05-19 12:17:43 +0200357 zfcp_dbf_out(p, "sbal_last", "0x%02x", r->sbal_last);
Martin Peschkea9c85772008-03-31 11:15:27 +0200358 zfcp_dbf_out(p, "pool", "0x%02x", r->pool);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200359
Martin Peschkeb634fff2008-03-31 11:15:24 +0200360 switch (r->fsf_command) {
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200361 case FSF_QTCB_FCP_CMND:
Martin Peschkeb634fff2008-03-31 11:15:24 +0200362 if (r->fsf_req_status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200363 break;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200364 zfcp_dbf_out(p, "scsi_cmnd", "0x%0Lx", r->u.fcp.cmnd);
365 zfcp_dbf_out(p, "scsi_serial", "0x%016Lx", r->u.fcp.serial);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200366 break;
367
368 case FSF_QTCB_OPEN_PORT_WITH_DID:
369 case FSF_QTCB_CLOSE_PORT:
370 case FSF_QTCB_CLOSE_PHYSICAL_PORT:
Martin Peschke6bc473d2008-03-31 11:15:29 +0200371 zfcp_dbf_out(p, "wwpn", "0x%016Lx", r->u.port.wwpn);
372 zfcp_dbf_out(p, "d_id", "0x%06x", r->u.port.d_id);
373 zfcp_dbf_out(p, "port_handle", "0x%08x", r->u.port.port_handle);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200374 break;
375
376 case FSF_QTCB_OPEN_LUN:
377 case FSF_QTCB_CLOSE_LUN:
Martin Peschke6bc473d2008-03-31 11:15:29 +0200378 zfcp_dbf_out(p, "wwpn", "0x%016Lx", r->u.unit.wwpn);
379 zfcp_dbf_out(p, "fcp_lun", "0x%016Lx", r->u.unit.fcp_lun);
380 zfcp_dbf_out(p, "port_handle", "0x%08x", r->u.unit.port_handle);
381 zfcp_dbf_out(p, "lun_handle", "0x%08x", r->u.unit.lun_handle);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200382 break;
383
384 case FSF_QTCB_SEND_ELS:
Martin Peschke6bc473d2008-03-31 11:15:29 +0200385 zfcp_dbf_out(p, "d_id", "0x%06x", r->u.els.d_id);
386 zfcp_dbf_out(p, "ls_code", "0x%02x", r->u.els.ls_code);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200387 break;
388
389 case FSF_QTCB_ABORT_FCP_CMND:
390 case FSF_QTCB_SEND_GENERIC:
391 case FSF_QTCB_EXCHANGE_CONFIG_DATA:
392 case FSF_QTCB_EXCHANGE_PORT_DATA:
393 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
394 case FSF_QTCB_UPLOAD_CONTROL_FILE:
395 break;
396 }
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200397}
398
Martin Peschkea9c85772008-03-31 11:15:27 +0200399static void zfcp_hba_dbf_view_status(char **p,
400 struct zfcp_hba_dbf_record_status *r)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200401{
Martin Peschkea9c85772008-03-31 11:15:27 +0200402 zfcp_dbf_out(p, "failed", "0x%02x", r->failed);
403 zfcp_dbf_out(p, "status_type", "0x%08x", r->status_type);
404 zfcp_dbf_out(p, "status_subtype", "0x%08x", r->status_subtype);
405 zfcp_dbf_outd(p, "queue_designator", (char *)&r->queue_designator,
Martin Peschkedf29f4a2008-03-31 11:15:26 +0200406 sizeof(struct fsf_queue_designator), 0,
407 sizeof(struct fsf_queue_designator));
Martin Peschkea9c85772008-03-31 11:15:27 +0200408 zfcp_dbf_outd(p, "payload", (char *)&r->payload, r->payload_size, 0,
Martin Peschkedf29f4a2008-03-31 11:15:26 +0200409 r->payload_size);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200410}
411
Martin Peschkea9c85772008-03-31 11:15:27 +0200412static void zfcp_hba_dbf_view_qdio(char **p, struct zfcp_hba_dbf_record_qdio *r)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200413{
Martin Peschkea9c85772008-03-31 11:15:27 +0200414 zfcp_dbf_out(p, "status", "0x%08x", r->status);
415 zfcp_dbf_out(p, "qdio_error", "0x%08x", r->qdio_error);
416 zfcp_dbf_out(p, "siga_error", "0x%08x", r->siga_error);
417 zfcp_dbf_out(p, "sbal_index", "0x%02x", r->sbal_index);
418 zfcp_dbf_out(p, "sbal_count", "0x%02x", r->sbal_count);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200419}
420
Martin Peschkea9c85772008-03-31 11:15:27 +0200421static int zfcp_hba_dbf_view_format(debug_info_t *id, struct debug_view *view,
422 char *out_buf, const char *in_buf)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200423{
Martin Peschkea9c85772008-03-31 11:15:27 +0200424 struct zfcp_hba_dbf_record *r = (struct zfcp_hba_dbf_record *)in_buf;
425 char *p = out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200426
Martin Peschkea9c85772008-03-31 11:15:27 +0200427 if (strncmp(r->tag, "dump", ZFCP_DBF_TAG_SIZE) == 0)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200428 return 0;
429
Martin Peschkea9c85772008-03-31 11:15:27 +0200430 zfcp_dbf_tag(&p, "tag", r->tag);
431 if (isalpha(r->tag2[0]))
432 zfcp_dbf_tag(&p, "tag2", r->tag2);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200433
Martin Peschkea9c85772008-03-31 11:15:27 +0200434 if (strncmp(r->tag, "resp", ZFCP_DBF_TAG_SIZE) == 0)
Martin Peschke6bc473d2008-03-31 11:15:29 +0200435 zfcp_hba_dbf_view_response(&p, &r->u.response);
Martin Peschkea9c85772008-03-31 11:15:27 +0200436 else if (strncmp(r->tag, "stat", ZFCP_DBF_TAG_SIZE) == 0)
Martin Peschke6bc473d2008-03-31 11:15:29 +0200437 zfcp_hba_dbf_view_status(&p, &r->u.status);
Martin Peschkea9c85772008-03-31 11:15:27 +0200438 else if (strncmp(r->tag, "qdio", ZFCP_DBF_TAG_SIZE) == 0)
Martin Peschke6bc473d2008-03-31 11:15:29 +0200439 zfcp_hba_dbf_view_qdio(&p, &r->u.qdio);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200440
Martin Peschkea9c85772008-03-31 11:15:27 +0200441 p += sprintf(p, "\n");
442 return p - out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200443}
444
Heiko Carstens2b67fc42007-02-05 21:16:47 +0100445static struct debug_view zfcp_hba_dbf_view = {
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200446 "structured",
447 NULL,
448 &zfcp_dbf_view_header,
449 &zfcp_hba_dbf_view_format,
450 NULL,
451 NULL
452};
453
Martin Peschked79a83d2008-03-27 14:22:00 +0100454static const char *zfcp_rec_dbf_tags[] = {
Martin Peschke348447e2008-03-27 14:22:01 +0100455 [ZFCP_REC_DBF_ID_THREAD] = "thread",
Martin Peschke698ec0162008-03-27 14:22:02 +0100456 [ZFCP_REC_DBF_ID_TARGET] = "target",
Martin Peschke9467a9b2008-03-27 14:22:03 +0100457 [ZFCP_REC_DBF_ID_TRIGGER] = "trigger",
Martin Peschke6f4f3652008-03-27 14:22:04 +0100458 [ZFCP_REC_DBF_ID_ACTION] = "action",
Martin Peschked79a83d2008-03-27 14:22:00 +0100459};
460
461static const char *zfcp_rec_dbf_ids[] = {
Martin Peschke348447e2008-03-27 14:22:01 +0100462 [1] = "new",
463 [2] = "ready",
464 [3] = "kill",
465 [4] = "down sleep",
466 [5] = "down wakeup",
467 [6] = "down sleep ecd",
468 [7] = "down wakeup ecd",
469 [8] = "down sleep epd",
470 [9] = "down wakeup epd",
Martin Peschke698ec0162008-03-27 14:22:02 +0100471 [10] = "online",
472 [11] = "operational",
473 [12] = "scsi slave destroy",
474 [13] = "propagate failed adapter",
475 [14] = "propagate failed port",
476 [15] = "block adapter",
477 [16] = "unblock adapter",
478 [17] = "block port",
479 [18] = "unblock port",
480 [19] = "block unit",
481 [20] = "unblock unit",
482 [21] = "unit recovery failed",
483 [22] = "port recovery failed",
484 [23] = "adapter recovery failed",
485 [24] = "qdio queues down",
486 [25] = "p2p failed",
487 [26] = "nameserver lookup failed",
488 [27] = "nameserver port failed",
489 [28] = "link up",
490 [29] = "link down",
491 [30] = "link up status read",
492 [31] = "open port failed",
493 [32] = "open port failed",
494 [33] = "close port",
495 [34] = "open unit failed",
496 [35] = "exclusive open unit failed",
497 [36] = "shared open unit failed",
498 [37] = "link down",
499 [38] = "link down status read no link",
500 [39] = "link down status read fdisc login",
501 [40] = "link down status read firmware update",
502 [41] = "link down status read unknown reason",
503 [42] = "link down ecd incomplete",
504 [43] = "link down epd incomplete",
505 [44] = "sysfs adapter recovery",
506 [45] = "sysfs port recovery",
507 [46] = "sysfs unit recovery",
508 [47] = "port boxed abort",
509 [48] = "unit boxed abort",
510 [49] = "port boxed ct",
511 [50] = "port boxed close physical",
512 [51] = "port boxed open unit",
513 [52] = "port boxed close unit",
514 [53] = "port boxed fcp",
515 [54] = "unit boxed fcp",
516 [55] = "port access denied ct",
517 [56] = "port access denied els",
518 [57] = "port access denied open port",
519 [58] = "port access denied close physical",
520 [59] = "unit access denied open unit",
521 [60] = "shared unit access denied open unit",
522 [61] = "unit access denied fcp",
Martin Peschke9467a9b2008-03-27 14:22:03 +0100523 [62] = "request timeout",
524 [63] = "adisc link test reject or timeout",
525 [64] = "adisc link test d_id changed",
526 [65] = "adisc link test failed",
527 [66] = "recovery out of memory",
528 [67] = "adapter recovery repeated after state change",
529 [68] = "port recovery repeated after state change",
530 [69] = "unit recovery repeated after state change",
531 [70] = "port recovery follow-up after successful adapter recovery",
532 [71] = "adapter recovery escalation after failed adapter recovery",
533 [72] = "port recovery follow-up after successful physical port "
534 "recovery",
535 [73] = "adapter recovery escalation after failed physical port "
536 "recovery",
537 [74] = "unit recovery follow-up after successful port recovery",
538 [75] = "physical port recovery escalation after failed port "
539 "recovery",
540 [76] = "port recovery escalation after failed unit recovery",
541 [77] = "recovery opening nameserver port",
542 [78] = "duplicate request id",
543 [79] = "link down",
544 [80] = "exclusive read-only unit access unsupported",
545 [81] = "shared read-write unit access unsupported",
546 [82] = "incoming rscn",
547 [83] = "incoming plogi",
548 [84] = "incoming logo",
549 [85] = "online",
550 [86] = "offline",
551 [87] = "ccw device gone",
552 [88] = "ccw device no path",
553 [89] = "ccw device operational",
554 [90] = "ccw device shutdown",
555 [91] = "sysfs port addition",
556 [92] = "sysfs port removal",
557 [93] = "sysfs adapter recovery",
558 [94] = "sysfs unit addition",
559 [95] = "sysfs unit removal",
560 [96] = "sysfs port recovery",
561 [97] = "sysfs unit recovery",
562 [98] = "sequence number mismatch",
563 [99] = "link up",
564 [100] = "error state",
565 [101] = "status read physical port closed",
566 [102] = "link up status read",
567 [103] = "too many failed status read buffers",
568 [104] = "port handle not valid abort",
569 [105] = "lun handle not valid abort",
570 [106] = "port handle not valid ct",
571 [107] = "port handle not valid close port",
572 [108] = "port handle not valid close physical port",
573 [109] = "port handle not valid open unit",
574 [110] = "port handle not valid close unit",
575 [111] = "lun handle not valid close unit",
576 [112] = "port handle not valid fcp",
577 [113] = "lun handle not valid fcp",
578 [114] = "handle mismatch fcp",
579 [115] = "lun not valid fcp",
580 [116] = "qdio send failed",
581 [117] = "version mismatch",
582 [118] = "incompatible qtcb type",
583 [119] = "unknown protocol status",
584 [120] = "unknown fsf command",
585 [121] = "no recommendation for status qualifier",
586 [122] = "status read physical port closed in error",
587 [123] = "fc service class not supported ct",
588 [124] = "fc service class not supported els",
589 [125] = "need newer zfcp",
590 [126] = "need newer microcode",
591 [127] = "arbitrated loop not supported",
592 [128] = "unknown topology",
593 [129] = "qtcb size mismatch",
594 [130] = "unknown fsf status ecd",
595 [131] = "fcp request too big",
596 [132] = "fc service class not supported fcp",
597 [133] = "data direction not valid fcp",
598 [134] = "command length not valid fcp",
599 [135] = "status read act update",
600 [136] = "status read cfdc update",
601 [137] = "hbaapi port open",
602 [138] = "hbaapi unit open",
603 [139] = "hbaapi unit shutdown",
604 [140] = "qdio error",
605 [141] = "scsi host reset",
Martin Peschke6f4f3652008-03-27 14:22:04 +0100606 [142] = "dismissing fsf request for recovery action",
607 [143] = "recovery action timed out",
608 [144] = "recovery action gone",
609 [145] = "recovery action being processed",
610 [146] = "recovery action ready for next step",
Martin Peschked79a83d2008-03-27 14:22:00 +0100611};
612
613static int zfcp_rec_dbf_view_format(debug_info_t *id, struct debug_view *view,
614 char *buf, const char *_rec)
615{
616 struct zfcp_rec_dbf_record *r = (struct zfcp_rec_dbf_record *)_rec;
617 char *p = buf;
618
619 zfcp_dbf_outs(&p, "tag", zfcp_rec_dbf_tags[r->id]);
620 zfcp_dbf_outs(&p, "hint", zfcp_rec_dbf_ids[r->id2]);
621 zfcp_dbf_out(&p, "id", "%d", r->id2);
622 switch (r->id) {
Martin Peschke348447e2008-03-27 14:22:01 +0100623 case ZFCP_REC_DBF_ID_THREAD:
Martin Peschke348447e2008-03-27 14:22:01 +0100624 zfcp_dbf_out(&p, "total", "%d", r->u.thread.total);
625 zfcp_dbf_out(&p, "ready", "%d", r->u.thread.ready);
626 zfcp_dbf_out(&p, "running", "%d", r->u.thread.running);
627 break;
Martin Peschke698ec0162008-03-27 14:22:02 +0100628 case ZFCP_REC_DBF_ID_TARGET:
629 zfcp_dbf_out(&p, "reference", "0x%016Lx", r->u.target.ref);
630 zfcp_dbf_out(&p, "status", "0x%08x", r->u.target.status);
631 zfcp_dbf_out(&p, "erp_count", "%d", r->u.target.erp_count);
632 zfcp_dbf_out(&p, "d_id", "0x%06x", r->u.target.d_id);
633 zfcp_dbf_out(&p, "wwpn", "0x%016Lx", r->u.target.wwpn);
634 zfcp_dbf_out(&p, "fcp_lun", "0x%016Lx", r->u.target.fcp_lun);
635 break;
Martin Peschke9467a9b2008-03-27 14:22:03 +0100636 case ZFCP_REC_DBF_ID_TRIGGER:
637 zfcp_dbf_out(&p, "reference", "0x%016Lx", r->u.trigger.ref);
638 zfcp_dbf_out(&p, "erp_action", "0x%016Lx", r->u.trigger.action);
639 zfcp_dbf_out(&p, "requested", "%d", r->u.trigger.want);
640 zfcp_dbf_out(&p, "executed", "%d", r->u.trigger.need);
641 zfcp_dbf_out(&p, "wwpn", "0x%016Lx", r->u.trigger.wwpn);
642 zfcp_dbf_out(&p, "fcp_lun", "0x%016Lx", r->u.trigger.fcp_lun);
643 zfcp_dbf_out(&p, "adapter_status", "0x%08x", r->u.trigger.as);
644 zfcp_dbf_out(&p, "port_status", "0x%08x", r->u.trigger.ps);
645 zfcp_dbf_out(&p, "unit_status", "0x%08x", r->u.trigger.us);
646 break;
Martin Peschke6f4f3652008-03-27 14:22:04 +0100647 case ZFCP_REC_DBF_ID_ACTION:
648 zfcp_dbf_out(&p, "erp_action", "0x%016Lx", r->u.action.action);
649 zfcp_dbf_out(&p, "fsf_req", "0x%016Lx", r->u.action.fsf_req);
650 zfcp_dbf_out(&p, "status", "0x%08Lx", r->u.action.status);
651 zfcp_dbf_out(&p, "step", "0x%08Lx", r->u.action.step);
652 break;
Martin Peschked79a83d2008-03-27 14:22:00 +0100653 }
Martin Peschkeb634fff2008-03-31 11:15:24 +0200654 p += sprintf(p, "\n");
655 return p - buf;
Martin Peschked79a83d2008-03-27 14:22:00 +0100656}
657
658static struct debug_view zfcp_rec_dbf_view = {
659 "structured",
660 NULL,
661 &zfcp_dbf_view_header,
662 &zfcp_rec_dbf_view_format,
663 NULL,
664 NULL
665};
666
Martin Peschke348447e2008-03-27 14:22:01 +0100667/**
668 * zfcp_rec_dbf_event_thread - trace event related to recovery thread operation
669 * @id2: identifier for event
670 * @adapter: adapter
671 * @lock: non-zero value indicates that erp_lock has not yet been acquired
672 */
673void zfcp_rec_dbf_event_thread(u8 id2, struct zfcp_adapter *adapter, int lock)
674{
675 struct zfcp_rec_dbf_record *r = &adapter->rec_dbf_buf;
676 unsigned long flags = 0;
677 struct list_head *entry;
678 unsigned ready = 0, running = 0, total;
679
680 if (lock)
681 read_lock_irqsave(&adapter->erp_lock, flags);
682 list_for_each(entry, &adapter->erp_ready_head)
683 ready++;
684 list_for_each(entry, &adapter->erp_running_head)
685 running++;
686 total = adapter->erp_total_count;
687 if (lock)
688 read_unlock_irqrestore(&adapter->erp_lock, flags);
689
690 spin_lock_irqsave(&adapter->rec_dbf_lock, flags);
691 memset(r, 0, sizeof(*r));
692 r->id = ZFCP_REC_DBF_ID_THREAD;
693 r->id2 = id2;
Martin Peschke348447e2008-03-27 14:22:01 +0100694 r->u.thread.total = total;
695 r->u.thread.ready = ready;
696 r->u.thread.running = running;
697 debug_event(adapter->rec_dbf, 5, r, sizeof(*r));
698 spin_unlock_irqrestore(&adapter->rec_dbf_lock, flags);
699}
700
Martin Peschke1f6f7122008-04-18 12:51:55 +0200701static void zfcp_rec_dbf_event_target(u8 id2, void *ref,
Martin Peschke698ec0162008-03-27 14:22:02 +0100702 struct zfcp_adapter *adapter,
703 atomic_t *status, atomic_t *erp_count,
704 u64 wwpn, u32 d_id, u64 fcp_lun)
705{
706 struct zfcp_rec_dbf_record *r = &adapter->rec_dbf_buf;
707 unsigned long flags;
708
709 spin_lock_irqsave(&adapter->rec_dbf_lock, flags);
710 memset(r, 0, sizeof(*r));
711 r->id = ZFCP_REC_DBF_ID_TARGET;
712 r->id2 = id2;
Martin Peschke1f6f7122008-04-18 12:51:55 +0200713 r->u.target.ref = (unsigned long)ref;
Martin Peschke698ec0162008-03-27 14:22:02 +0100714 r->u.target.status = atomic_read(status);
715 r->u.target.wwpn = wwpn;
716 r->u.target.d_id = d_id;
717 r->u.target.fcp_lun = fcp_lun;
718 r->u.target.erp_count = atomic_read(erp_count);
719 debug_event(adapter->rec_dbf, 3, r, sizeof(*r));
720 spin_unlock_irqrestore(&adapter->rec_dbf_lock, flags);
721}
722
723/**
724 * zfcp_rec_dbf_event_adapter - trace event for adapter state change
725 * @id: identifier for trigger of state change
726 * @ref: additional reference (e.g. request)
727 * @adapter: adapter
728 */
Martin Peschke1f6f7122008-04-18 12:51:55 +0200729void zfcp_rec_dbf_event_adapter(u8 id, void *ref, struct zfcp_adapter *adapter)
Martin Peschke698ec0162008-03-27 14:22:02 +0100730{
731 zfcp_rec_dbf_event_target(id, ref, adapter, &adapter->status,
732 &adapter->erp_counter, 0, 0, 0);
733}
734
735/**
736 * zfcp_rec_dbf_event_port - trace event for port state change
737 * @id: identifier for trigger of state change
738 * @ref: additional reference (e.g. request)
739 * @port: port
740 */
Martin Peschke1f6f7122008-04-18 12:51:55 +0200741void zfcp_rec_dbf_event_port(u8 id, void *ref, struct zfcp_port *port)
Martin Peschke698ec0162008-03-27 14:22:02 +0100742{
743 struct zfcp_adapter *adapter = port->adapter;
744
745 zfcp_rec_dbf_event_target(id, ref, adapter, &port->status,
746 &port->erp_counter, port->wwpn, port->d_id,
747 0);
748}
749
750/**
751 * zfcp_rec_dbf_event_unit - trace event for unit state change
752 * @id: identifier for trigger of state change
753 * @ref: additional reference (e.g. request)
754 * @unit: unit
755 */
Martin Peschke1f6f7122008-04-18 12:51:55 +0200756void zfcp_rec_dbf_event_unit(u8 id, void *ref, struct zfcp_unit *unit)
Martin Peschke698ec0162008-03-27 14:22:02 +0100757{
758 struct zfcp_port *port = unit->port;
759 struct zfcp_adapter *adapter = port->adapter;
760
761 zfcp_rec_dbf_event_target(id, ref, adapter, &unit->status,
762 &unit->erp_counter, port->wwpn, port->d_id,
763 unit->fcp_lun);
764}
765
Martin Peschke9467a9b2008-03-27 14:22:03 +0100766/**
767 * zfcp_rec_dbf_event_trigger - trace event for triggered error recovery
768 * @id2: identifier for error recovery trigger
769 * @ref: additional reference (e.g. request)
770 * @want: originally requested error recovery action
771 * @need: error recovery action actually initiated
772 * @action: address of error recovery action struct
773 * @adapter: adapter
774 * @port: port
775 * @unit: unit
776 */
Martin Peschke1f6f7122008-04-18 12:51:55 +0200777void zfcp_rec_dbf_event_trigger(u8 id2, void *ref, u8 want, u8 need,
778 void *action, struct zfcp_adapter *adapter,
Martin Peschke9467a9b2008-03-27 14:22:03 +0100779 struct zfcp_port *port, struct zfcp_unit *unit)
780{
781 struct zfcp_rec_dbf_record *r = &adapter->rec_dbf_buf;
782 unsigned long flags;
783
784 spin_lock_irqsave(&adapter->rec_dbf_lock, flags);
785 memset(r, 0, sizeof(*r));
786 r->id = ZFCP_REC_DBF_ID_TRIGGER;
787 r->id2 = id2;
Martin Peschke1f6f7122008-04-18 12:51:55 +0200788 r->u.trigger.ref = (unsigned long)ref;
Martin Peschke9467a9b2008-03-27 14:22:03 +0100789 r->u.trigger.want = want;
790 r->u.trigger.need = need;
Martin Peschke1f6f7122008-04-18 12:51:55 +0200791 r->u.trigger.action = (unsigned long)action;
Martin Peschke9467a9b2008-03-27 14:22:03 +0100792 r->u.trigger.as = atomic_read(&adapter->status);
793 if (port) {
794 r->u.trigger.ps = atomic_read(&port->status);
795 r->u.trigger.wwpn = port->wwpn;
796 }
797 if (unit) {
798 r->u.trigger.us = atomic_read(&unit->status);
799 r->u.trigger.fcp_lun = unit->fcp_lun;
800 }
801 debug_event(adapter->rec_dbf, action ? 1 : 4, r, sizeof(*r));
802 spin_unlock_irqrestore(&adapter->rec_dbf_lock, flags);
803}
804
Martin Peschke6f4f3652008-03-27 14:22:04 +0100805/**
806 * zfcp_rec_dbf_event_action - trace event showing progress of recovery action
807 * @id2: identifier
808 * @erp_action: error recovery action struct pointer
809 */
810void zfcp_rec_dbf_event_action(u8 id2, struct zfcp_erp_action *erp_action)
811{
812 struct zfcp_adapter *adapter = erp_action->adapter;
813 struct zfcp_rec_dbf_record *r = &adapter->rec_dbf_buf;
814 unsigned long flags;
815
816 spin_lock_irqsave(&adapter->rec_dbf_lock, flags);
817 memset(r, 0, sizeof(*r));
818 r->id = ZFCP_REC_DBF_ID_ACTION;
819 r->id2 = id2;
Martin Peschke1f6f7122008-04-18 12:51:55 +0200820 r->u.action.action = (unsigned long)erp_action;
Martin Peschke6f4f3652008-03-27 14:22:04 +0100821 r->u.action.status = erp_action->status;
822 r->u.action.step = erp_action->step;
Martin Peschke1f6f7122008-04-18 12:51:55 +0200823 r->u.action.fsf_req = (unsigned long)erp_action->fsf_req;
Martin Peschke6f4f3652008-03-27 14:22:04 +0100824 debug_event(adapter->rec_dbf, 4, r, sizeof(*r));
825 spin_unlock_irqrestore(&adapter->rec_dbf_lock, flags);
826}
827
Martin Peschkebfab1632008-03-31 11:15:31 +0200828/**
829 * zfcp_san_dbf_event_ct_request - trace event for issued CT request
830 * @fsf_req: request containing issued CT data
831 */
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100832void zfcp_san_dbf_event_ct_request(struct zfcp_fsf_req *fsf_req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200833{
834 struct zfcp_send_ct *ct = (struct zfcp_send_ct *)fsf_req->data;
835 struct zfcp_port *port = ct->port;
836 struct zfcp_adapter *adapter = port->adapter;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200837 struct ct_hdr *hdr = zfcp_sg_to_address(ct->req);
838 struct zfcp_san_dbf_record *r = &adapter->san_dbf_buf;
839 struct zfcp_san_dbf_record_ct_request *oct = &r->u.ct_req;
840 unsigned long flags;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200841
Martin Peschke6bc473d2008-03-31 11:15:29 +0200842 spin_lock_irqsave(&adapter->san_dbf_lock, flags);
843 memset(r, 0, sizeof(*r));
844 strncpy(r->tag, "octc", ZFCP_DBF_TAG_SIZE);
845 r->fsf_reqid = (unsigned long)fsf_req;
846 r->fsf_seqno = fsf_req->seq_no;
847 r->s_id = fc_host_port_id(adapter->scsi_host);
848 r->d_id = port->d_id;
849 oct->cmd_req_code = hdr->cmd_rsp_code;
850 oct->revision = hdr->revision;
851 oct->gs_type = hdr->gs_type;
852 oct->gs_subtype = hdr->gs_subtype;
853 oct->options = hdr->options;
854 oct->max_res_size = hdr->max_res_size;
855 oct->len = min((int)ct->req->length - (int)sizeof(struct ct_hdr),
856 ZFCP_DBF_CT_PAYLOAD);
857 memcpy(oct->payload, (void *)hdr + sizeof(struct ct_hdr), oct->len);
858 debug_event(adapter->san_dbf, 3, r, sizeof(*r));
859 spin_unlock_irqrestore(&adapter->san_dbf_lock, flags);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200860}
861
Martin Peschkebfab1632008-03-31 11:15:31 +0200862/**
863 * zfcp_san_dbf_event_ct_response - trace event for completion of CT request
864 * @fsf_req: request containing CT response
865 */
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100866void zfcp_san_dbf_event_ct_response(struct zfcp_fsf_req *fsf_req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200867{
868 struct zfcp_send_ct *ct = (struct zfcp_send_ct *)fsf_req->data;
869 struct zfcp_port *port = ct->port;
870 struct zfcp_adapter *adapter = port->adapter;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200871 struct ct_hdr *hdr = zfcp_sg_to_address(ct->resp);
872 struct zfcp_san_dbf_record *r = &adapter->san_dbf_buf;
873 struct zfcp_san_dbf_record_ct_response *rct = &r->u.ct_resp;
874 unsigned long flags;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200875
Martin Peschke6bc473d2008-03-31 11:15:29 +0200876 spin_lock_irqsave(&adapter->san_dbf_lock, flags);
877 memset(r, 0, sizeof(*r));
878 strncpy(r->tag, "rctc", ZFCP_DBF_TAG_SIZE);
879 r->fsf_reqid = (unsigned long)fsf_req;
880 r->fsf_seqno = fsf_req->seq_no;
881 r->s_id = port->d_id;
882 r->d_id = fc_host_port_id(adapter->scsi_host);
883 rct->cmd_rsp_code = hdr->cmd_rsp_code;
884 rct->revision = hdr->revision;
885 rct->reason_code = hdr->reason_code;
886 rct->expl = hdr->reason_code_expl;
887 rct->vendor_unique = hdr->vendor_unique;
888 rct->len = min((int)ct->resp->length - (int)sizeof(struct ct_hdr),
889 ZFCP_DBF_CT_PAYLOAD);
890 memcpy(rct->payload, (void *)hdr + sizeof(struct ct_hdr), rct->len);
891 debug_event(adapter->san_dbf, 3, r, sizeof(*r));
892 spin_unlock_irqrestore(&adapter->san_dbf_lock, flags);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200893}
894
Martin Peschke92c7a832008-03-31 11:15:30 +0200895static void zfcp_san_dbf_event_els(const char *tag, int level,
896 struct zfcp_fsf_req *fsf_req, u32 s_id,
897 u32 d_id, u8 ls_code, void *buffer,
898 int buflen)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200899{
900 struct zfcp_adapter *adapter = fsf_req->adapter;
901 struct zfcp_san_dbf_record *rec = &adapter->san_dbf_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200902 unsigned long flags;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200903
904 spin_lock_irqsave(&adapter->san_dbf_lock, flags);
Martin Peschke6bc473d2008-03-31 11:15:29 +0200905 memset(rec, 0, sizeof(*rec));
Martin Peschke0f65e952008-03-27 14:21:56 +0100906 strncpy(rec->tag, tag, ZFCP_DBF_TAG_SIZE);
907 rec->fsf_reqid = (unsigned long)fsf_req;
908 rec->fsf_seqno = fsf_req->seq_no;
909 rec->s_id = s_id;
910 rec->d_id = d_id;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200911 rec->u.els.ls_code = ls_code;
Martin Peschke0f65e952008-03-27 14:21:56 +0100912 debug_event(adapter->san_dbf, level, rec, sizeof(*rec));
913 zfcp_dbf_hexdump(adapter->san_dbf, rec, sizeof(*rec), level,
914 buffer, min(buflen, ZFCP_DBF_ELS_MAX_PAYLOAD));
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200915 spin_unlock_irqrestore(&adapter->san_dbf_lock, flags);
916}
917
Martin Peschkebfab1632008-03-31 11:15:31 +0200918/**
919 * zfcp_san_dbf_event_els_request - trace event for issued ELS
920 * @fsf_req: request containing issued ELS
921 */
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100922void zfcp_san_dbf_event_els_request(struct zfcp_fsf_req *fsf_req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200923{
924 struct zfcp_send_els *els = (struct zfcp_send_els *)fsf_req->data;
925
Martin Peschke92c7a832008-03-31 11:15:30 +0200926 zfcp_san_dbf_event_els("oels", 2, fsf_req,
927 fc_host_port_id(els->adapter->scsi_host),
928 els->d_id, *(u8 *) zfcp_sg_to_address(els->req),
929 zfcp_sg_to_address(els->req), els->req->length);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200930}
931
Martin Peschkebfab1632008-03-31 11:15:31 +0200932/**
933 * zfcp_san_dbf_event_els_response - trace event for completed ELS
934 * @fsf_req: request containing ELS response
935 */
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100936void zfcp_san_dbf_event_els_response(struct zfcp_fsf_req *fsf_req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200937{
938 struct zfcp_send_els *els = (struct zfcp_send_els *)fsf_req->data;
939
Martin Peschke92c7a832008-03-31 11:15:30 +0200940 zfcp_san_dbf_event_els("rels", 2, fsf_req, els->d_id,
941 fc_host_port_id(els->adapter->scsi_host),
942 *(u8 *)zfcp_sg_to_address(els->req),
943 zfcp_sg_to_address(els->resp),
944 els->resp->length);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200945}
946
Martin Peschkebfab1632008-03-31 11:15:31 +0200947/**
948 * zfcp_san_dbf_event_incoming_els - trace event for incomig ELS
949 * @fsf_req: request containing unsolicited status buffer with incoming ELS
950 */
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100951void zfcp_san_dbf_event_incoming_els(struct zfcp_fsf_req *fsf_req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200952{
953 struct zfcp_adapter *adapter = fsf_req->adapter;
Martin Peschke92c7a832008-03-31 11:15:30 +0200954 struct fsf_status_read_buffer *buf =
955 (struct fsf_status_read_buffer *)fsf_req->data;
956 int length = (int)buf->length -
957 (int)((void *)&buf->payload - (void *)buf);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200958
Martin Peschke92c7a832008-03-31 11:15:30 +0200959 zfcp_san_dbf_event_els("iels", 1, fsf_req, buf->d_id,
960 fc_host_port_id(adapter->scsi_host),
961 *(u8 *)buf->payload, (void *)buf->payload,
962 length);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200963}
964
Martin Peschke92c7a832008-03-31 11:15:30 +0200965static int zfcp_san_dbf_view_format(debug_info_t *id, struct debug_view *view,
966 char *out_buf, const char *in_buf)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200967{
Martin Peschkeb634fff2008-03-31 11:15:24 +0200968 struct zfcp_san_dbf_record *r = (struct zfcp_san_dbf_record *)in_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200969 char *buffer = NULL;
970 int buflen = 0, total = 0;
Martin Peschkeb634fff2008-03-31 11:15:24 +0200971 char *p = out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200972
Martin Peschkeb634fff2008-03-31 11:15:24 +0200973 if (strncmp(r->tag, "dump", ZFCP_DBF_TAG_SIZE) == 0)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200974 return 0;
975
Martin Peschkea9c85772008-03-31 11:15:27 +0200976 zfcp_dbf_tag(&p, "tag", r->tag);
Martin Peschkeb634fff2008-03-31 11:15:24 +0200977 zfcp_dbf_out(&p, "fsf_reqid", "0x%0Lx", r->fsf_reqid);
978 zfcp_dbf_out(&p, "fsf_seqno", "0x%08x", r->fsf_seqno);
979 zfcp_dbf_out(&p, "s_id", "0x%06x", r->s_id);
980 zfcp_dbf_out(&p, "d_id", "0x%06x", r->d_id);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200981
Martin Peschkeb634fff2008-03-31 11:15:24 +0200982 if (strncmp(r->tag, "octc", ZFCP_DBF_TAG_SIZE) == 0) {
Martin Peschke6bc473d2008-03-31 11:15:29 +0200983 struct zfcp_san_dbf_record_ct_request *ct = &r->u.ct_req;
984 zfcp_dbf_out(&p, "cmd_req_code", "0x%04x", ct->cmd_req_code);
985 zfcp_dbf_out(&p, "revision", "0x%02x", ct->revision);
986 zfcp_dbf_out(&p, "gs_type", "0x%02x", ct->gs_type);
987 zfcp_dbf_out(&p, "gs_subtype", "0x%02x", ct->gs_subtype);
988 zfcp_dbf_out(&p, "options", "0x%02x", ct->options);
989 zfcp_dbf_out(&p, "max_res_size", "0x%04x", ct->max_res_size);
990 total = ct->len;
991 buffer = ct->payload;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200992 buflen = min(total, ZFCP_DBF_CT_PAYLOAD);
Martin Peschkeb634fff2008-03-31 11:15:24 +0200993 } else if (strncmp(r->tag, "rctc", ZFCP_DBF_TAG_SIZE) == 0) {
Martin Peschke6bc473d2008-03-31 11:15:29 +0200994 struct zfcp_san_dbf_record_ct_response *ct = &r->u.ct_resp;
995 zfcp_dbf_out(&p, "cmd_rsp_code", "0x%04x", ct->cmd_rsp_code);
996 zfcp_dbf_out(&p, "revision", "0x%02x", ct->revision);
997 zfcp_dbf_out(&p, "reason_code", "0x%02x", ct->reason_code);
998 zfcp_dbf_out(&p, "reason_code_expl", "0x%02x", ct->expl);
999 zfcp_dbf_out(&p, "vendor_unique", "0x%02x", ct->vendor_unique);
1000 total = ct->len;
1001 buffer = ct->payload;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001002 buflen = min(total, ZFCP_DBF_CT_PAYLOAD);
Martin Peschkeb634fff2008-03-31 11:15:24 +02001003 } else if (strncmp(r->tag, "oels", ZFCP_DBF_TAG_SIZE) == 0 ||
1004 strncmp(r->tag, "rels", ZFCP_DBF_TAG_SIZE) == 0 ||
1005 strncmp(r->tag, "iels", ZFCP_DBF_TAG_SIZE) == 0) {
Martin Peschke6bc473d2008-03-31 11:15:29 +02001006 struct zfcp_san_dbf_record_els *els = &r->u.els;
1007 zfcp_dbf_out(&p, "ls_code", "0x%02x", els->ls_code);
1008 total = els->len;
1009 buffer = els->payload;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001010 buflen = min(total, ZFCP_DBF_ELS_PAYLOAD);
1011 }
1012
Martin Peschkedf29f4a2008-03-31 11:15:26 +02001013 zfcp_dbf_outd(&p, "payload", buffer, buflen, 0, total);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001014 if (buflen == total)
Martin Peschkeb634fff2008-03-31 11:15:24 +02001015 p += sprintf(p, "\n");
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001016
Martin Peschkeb634fff2008-03-31 11:15:24 +02001017 return p - out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001018}
1019
Heiko Carstens2b67fc42007-02-05 21:16:47 +01001020static struct debug_view zfcp_san_dbf_view = {
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001021 "structured",
1022 NULL,
1023 &zfcp_dbf_view_header,
1024 &zfcp_san_dbf_view_format,
1025 NULL,
1026 NULL
1027};
1028
Martin Peschke92c7a832008-03-31 11:15:30 +02001029static void zfcp_scsi_dbf_event(const char *tag, const char *tag2, int level,
1030 struct zfcp_adapter *adapter,
1031 struct scsi_cmnd *scsi_cmnd,
1032 struct zfcp_fsf_req *fsf_req,
1033 unsigned long old_req_id)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001034{
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001035 struct zfcp_scsi_dbf_record *rec = &adapter->scsi_dbf_buf;
1036 struct zfcp_dbf_dump *dump = (struct zfcp_dbf_dump *)rec;
1037 unsigned long flags;
1038 struct fcp_rsp_iu *fcp_rsp;
1039 char *fcp_rsp_info = NULL, *fcp_sns_info = NULL;
1040 int offset = 0, buflen = 0;
1041
1042 spin_lock_irqsave(&adapter->scsi_dbf_lock, flags);
1043 do {
Martin Peschke6bc473d2008-03-31 11:15:29 +02001044 memset(rec, 0, sizeof(*rec));
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001045 if (offset == 0) {
1046 strncpy(rec->tag, tag, ZFCP_DBF_TAG_SIZE);
1047 strncpy(rec->tag2, tag2, ZFCP_DBF_TAG_SIZE);
Maxim Shchetynined829ad2006-02-11 01:42:58 +01001048 if (scsi_cmnd != NULL) {
1049 if (scsi_cmnd->device) {
1050 rec->scsi_id = scsi_cmnd->device->id;
1051 rec->scsi_lun = scsi_cmnd->device->lun;
1052 }
1053 rec->scsi_result = scsi_cmnd->result;
1054 rec->scsi_cmnd = (unsigned long)scsi_cmnd;
1055 rec->scsi_serial = scsi_cmnd->serial_number;
Boaz Harrosh64a87b22008-04-30 11:19:47 +03001056 memcpy(rec->scsi_opcode, scsi_cmnd->cmnd,
Maxim Shchetynined829ad2006-02-11 01:42:58 +01001057 min((int)scsi_cmnd->cmd_len,
1058 ZFCP_DBF_SCSI_OPCODE));
1059 rec->scsi_retries = scsi_cmnd->retries;
1060 rec->scsi_allowed = scsi_cmnd->allowed;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001061 }
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001062 if (fsf_req != NULL) {
1063 fcp_rsp = (struct fcp_rsp_iu *)
1064 &(fsf_req->qtcb->bottom.io.fcp_rsp);
1065 fcp_rsp_info =
1066 zfcp_get_fcp_rsp_info_ptr(fcp_rsp);
1067 fcp_sns_info =
1068 zfcp_get_fcp_sns_info_ptr(fcp_rsp);
1069
Martin Peschke6bc473d2008-03-31 11:15:29 +02001070 rec->rsp_validity = fcp_rsp->validity.value;
1071 rec->rsp_scsi_status = fcp_rsp->scsi_status;
1072 rec->rsp_resid = fcp_rsp->fcp_resid;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001073 if (fcp_rsp->validity.bits.fcp_rsp_len_valid)
Martin Peschke6bc473d2008-03-31 11:15:29 +02001074 rec->rsp_code = *(fcp_rsp_info + 3);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001075 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);
Martin Peschke6bc473d2008-03-31 11:15:29 +02001078 rec->sns_info_len = buflen;
1079 memcpy(rec->sns_info, fcp_sns_info,
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001080 min(buflen,
1081 ZFCP_DBF_SCSI_FCP_SNS_INFO));
1082 offset += min(buflen,
1083 ZFCP_DBF_SCSI_FCP_SNS_INFO);
1084 }
1085
1086 rec->fsf_reqid = (unsigned long)fsf_req;
1087 rec->fsf_seqno = fsf_req->seq_no;
1088 rec->fsf_issued = fsf_req->issued;
1089 }
Martin Peschke6bc473d2008-03-31 11:15:29 +02001090 rec->old_fsf_reqid = old_req_id;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001091 } else {
1092 strncpy(dump->tag, "dump", ZFCP_DBF_TAG_SIZE);
1093 dump->total_size = buflen;
1094 dump->offset = offset;
1095 dump->size = min(buflen - offset,
1096 (int)sizeof(struct
1097 zfcp_scsi_dbf_record) -
1098 (int)sizeof(struct zfcp_dbf_dump));
1099 memcpy(dump->data, fcp_sns_info + offset, dump->size);
1100 offset += dump->size;
1101 }
Martin Peschke6bc473d2008-03-31 11:15:29 +02001102 debug_event(adapter->scsi_dbf, level, rec, sizeof(*rec));
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001103 } while (offset < buflen);
1104 spin_unlock_irqrestore(&adapter->scsi_dbf_lock, flags);
1105}
1106
Martin Peschkebfab1632008-03-31 11:15:31 +02001107/**
1108 * zfcp_scsi_dbf_event_result - trace event for SCSI command completion
1109 * @tag: tag indicating success or failure of SCSI command
1110 * @level: trace level applicable for this event
1111 * @adapter: adapter that has been used to issue the SCSI command
1112 * @scsi_cmnd: SCSI command pointer
1113 * @fsf_req: request used to issue SCSI command (might be NULL)
1114 */
Martin Peschke92c7a832008-03-31 11:15:30 +02001115void zfcp_scsi_dbf_event_result(const char *tag, int level,
1116 struct zfcp_adapter *adapter,
1117 struct scsi_cmnd *scsi_cmnd,
1118 struct zfcp_fsf_req *fsf_req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001119{
Martin Peschke92c7a832008-03-31 11:15:30 +02001120 zfcp_scsi_dbf_event("rslt", tag, level, adapter, scsi_cmnd, fsf_req, 0);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001121}
1122
Martin Peschkebfab1632008-03-31 11:15:31 +02001123/**
1124 * zfcp_scsi_dbf_event_abort - trace event for SCSI command abort
1125 * @tag: tag indicating success or failure of abort operation
1126 * @adapter: adapter thas has been used to issue SCSI command to be aborted
1127 * @scsi_cmnd: SCSI command to be aborted
1128 * @new_fsf_req: request containing abort (might be NULL)
1129 * @old_req_id: identifier of request containg SCSI command to be aborted
1130 */
Martin Peschke92c7a832008-03-31 11:15:30 +02001131void zfcp_scsi_dbf_event_abort(const char *tag, struct zfcp_adapter *adapter,
1132 struct scsi_cmnd *scsi_cmnd,
1133 struct zfcp_fsf_req *new_fsf_req,
1134 unsigned long old_req_id)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001135{
Martin Peschke92c7a832008-03-31 11:15:30 +02001136 zfcp_scsi_dbf_event("abrt", tag, 1, adapter, scsi_cmnd, new_fsf_req,
1137 old_req_id);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001138}
1139
Martin Peschkebfab1632008-03-31 11:15:31 +02001140/**
1141 * zfcp_scsi_dbf_event_devreset - trace event for Logical Unit or Target Reset
1142 * @tag: tag indicating success or failure of reset operation
1143 * @flag: indicates type of reset (Target Reset, Logical Unit Reset)
1144 * @unit: unit that needs reset
1145 * @scsi_cmnd: SCSI command which caused this error recovery
1146 */
Martin Peschke92c7a832008-03-31 11:15:30 +02001147void zfcp_scsi_dbf_event_devreset(const char *tag, u8 flag,
1148 struct zfcp_unit *unit,
1149 struct scsi_cmnd *scsi_cmnd)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001150{
Martin Peschke92c7a832008-03-31 11:15:30 +02001151 zfcp_scsi_dbf_event(flag == FCP_TARGET_RESET ? "trst" : "lrst", tag, 1,
1152 unit->port->adapter, scsi_cmnd, NULL, 0);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001153}
1154
Martin Peschke92c7a832008-03-31 11:15:30 +02001155static int zfcp_scsi_dbf_view_format(debug_info_t *id, struct debug_view *view,
1156 char *out_buf, const char *in_buf)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001157{
Martin Peschkeb634fff2008-03-31 11:15:24 +02001158 struct zfcp_scsi_dbf_record *r = (struct zfcp_scsi_dbf_record *)in_buf;
Martin Peschke8fc5af12008-03-31 11:15:23 +02001159 struct timespec t;
Martin Peschkeb634fff2008-03-31 11:15:24 +02001160 char *p = out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001161
Martin Peschkeb634fff2008-03-31 11:15:24 +02001162 if (strncmp(r->tag, "dump", ZFCP_DBF_TAG_SIZE) == 0)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001163 return 0;
1164
Martin Peschkea9c85772008-03-31 11:15:27 +02001165 zfcp_dbf_tag(&p, "tag", r->tag);
1166 zfcp_dbf_tag(&p, "tag2", r->tag2);
Martin Peschkeb634fff2008-03-31 11:15:24 +02001167 zfcp_dbf_out(&p, "scsi_id", "0x%08x", r->scsi_id);
1168 zfcp_dbf_out(&p, "scsi_lun", "0x%08x", r->scsi_lun);
1169 zfcp_dbf_out(&p, "scsi_result", "0x%08x", r->scsi_result);
1170 zfcp_dbf_out(&p, "scsi_cmnd", "0x%0Lx", r->scsi_cmnd);
1171 zfcp_dbf_out(&p, "scsi_serial", "0x%016Lx", r->scsi_serial);
Martin Peschkedf29f4a2008-03-31 11:15:26 +02001172 zfcp_dbf_outd(&p, "scsi_opcode", r->scsi_opcode, ZFCP_DBF_SCSI_OPCODE,
1173 0, ZFCP_DBF_SCSI_OPCODE);
Martin Peschkeb634fff2008-03-31 11:15:24 +02001174 zfcp_dbf_out(&p, "scsi_retries", "0x%02x", r->scsi_retries);
1175 zfcp_dbf_out(&p, "scsi_allowed", "0x%02x", r->scsi_allowed);
1176 if (strncmp(r->tag, "abrt", ZFCP_DBF_TAG_SIZE) == 0)
Martin Peschke6bc473d2008-03-31 11:15:29 +02001177 zfcp_dbf_out(&p, "old_fsf_reqid", "0x%0Lx", r->old_fsf_reqid);
Martin Peschkeb634fff2008-03-31 11:15:24 +02001178 zfcp_dbf_out(&p, "fsf_reqid", "0x%0Lx", r->fsf_reqid);
1179 zfcp_dbf_out(&p, "fsf_seqno", "0x%08x", r->fsf_seqno);
1180 zfcp_dbf_timestamp(r->fsf_issued, &t);
1181 zfcp_dbf_out(&p, "fsf_issued", "%011lu:%06lu", t.tv_sec, t.tv_nsec);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001182
Martin Peschkeb634fff2008-03-31 11:15:24 +02001183 if (strncmp(r->tag, "rslt", ZFCP_DBF_TAG_SIZE) == 0) {
Martin Peschke6bc473d2008-03-31 11:15:29 +02001184 zfcp_dbf_out(&p, "fcp_rsp_validity", "0x%02x", r->rsp_validity);
1185 zfcp_dbf_out(&p, "fcp_rsp_scsi_status", "0x%02x",
1186 r->rsp_scsi_status);
1187 zfcp_dbf_out(&p, "fcp_rsp_resid", "0x%08x", r->rsp_resid);
1188 zfcp_dbf_out(&p, "fcp_rsp_code", "0x%08x", r->rsp_code);
1189 zfcp_dbf_out(&p, "fcp_sns_info_len", "0x%08x", r->sns_info_len);
1190 zfcp_dbf_outd(&p, "fcp_sns_info", r->sns_info,
1191 min((int)r->sns_info_len,
Martin Peschkedf29f4a2008-03-31 11:15:26 +02001192 ZFCP_DBF_SCSI_FCP_SNS_INFO), 0,
Martin Peschke6bc473d2008-03-31 11:15:29 +02001193 r->sns_info_len);
Martin Peschkeb634fff2008-03-31 11:15:24 +02001194 }
1195 p += sprintf(p, "\n");
1196 return p - out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001197}
1198
Heiko Carstens2b67fc42007-02-05 21:16:47 +01001199static struct debug_view zfcp_scsi_dbf_view = {
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001200 "structured",
1201 NULL,
1202 &zfcp_dbf_view_header,
1203 &zfcp_scsi_dbf_view_format,
1204 NULL,
1205 NULL
1206};
1207
1208/**
1209 * zfcp_adapter_debug_register - registers debug feature for an adapter
1210 * @adapter: pointer to adapter for which debug features should be registered
1211 * return: -ENOMEM on error, 0 otherwise
1212 */
1213int zfcp_adapter_debug_register(struct zfcp_adapter *adapter)
1214{
1215 char dbf_name[DEBUG_MAX_NAME_LEN];
1216
1217 /* debug feature area which records recovery activity */
Martin Peschked79a83d2008-03-27 14:22:00 +01001218 sprintf(dbf_name, "zfcp_%s_rec", zfcp_get_busid_by_adapter(adapter));
1219 adapter->rec_dbf = debug_register(dbf_name, dbfsize, 1,
1220 sizeof(struct zfcp_rec_dbf_record));
1221 if (!adapter->rec_dbf)
1222 goto failed;
1223 debug_register_view(adapter->rec_dbf, &debug_hex_ascii_view);
1224 debug_register_view(adapter->rec_dbf, &zfcp_rec_dbf_view);
1225 debug_set_level(adapter->rec_dbf, 3);
1226
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001227 /* debug feature area which records HBA (FSF and QDIO) conditions */
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001228 sprintf(dbf_name, "zfcp_%s_hba", zfcp_get_busid_by_adapter(adapter));
1229 adapter->hba_dbf = debug_register(dbf_name, dbfsize, 1,
1230 sizeof(struct zfcp_hba_dbf_record));
1231 if (!adapter->hba_dbf)
1232 goto failed;
1233 debug_register_view(adapter->hba_dbf, &debug_hex_ascii_view);
1234 debug_register_view(adapter->hba_dbf, &zfcp_hba_dbf_view);
1235 debug_set_level(adapter->hba_dbf, 3);
1236
1237 /* debug feature area which records SAN command failures and recovery */
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001238 sprintf(dbf_name, "zfcp_%s_san", zfcp_get_busid_by_adapter(adapter));
1239 adapter->san_dbf = debug_register(dbf_name, dbfsize, 1,
1240 sizeof(struct zfcp_san_dbf_record));
1241 if (!adapter->san_dbf)
1242 goto failed;
1243 debug_register_view(adapter->san_dbf, &debug_hex_ascii_view);
1244 debug_register_view(adapter->san_dbf, &zfcp_san_dbf_view);
1245 debug_set_level(adapter->san_dbf, 6);
1246
1247 /* debug feature area which records SCSI command failures and recovery */
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001248 sprintf(dbf_name, "zfcp_%s_scsi", zfcp_get_busid_by_adapter(adapter));
1249 adapter->scsi_dbf = debug_register(dbf_name, dbfsize, 1,
1250 sizeof(struct zfcp_scsi_dbf_record));
1251 if (!adapter->scsi_dbf)
1252 goto failed;
1253 debug_register_view(adapter->scsi_dbf, &debug_hex_ascii_view);
1254 debug_register_view(adapter->scsi_dbf, &zfcp_scsi_dbf_view);
1255 debug_set_level(adapter->scsi_dbf, 3);
1256
1257 return 0;
1258
1259 failed:
1260 zfcp_adapter_debug_unregister(adapter);
1261
1262 return -ENOMEM;
1263}
1264
1265/**
1266 * zfcp_adapter_debug_unregister - unregisters debug feature for an adapter
1267 * @adapter: pointer to adapter for which debug features should be unregistered
1268 */
1269void zfcp_adapter_debug_unregister(struct zfcp_adapter *adapter)
1270{
1271 debug_unregister(adapter->scsi_dbf);
1272 debug_unregister(adapter->san_dbf);
1273 debug_unregister(adapter->hba_dbf);
Martin Peschked79a83d2008-03-27 14:22:00 +01001274 debug_unregister(adapter->rec_dbf);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001275 adapter->scsi_dbf = NULL;
1276 adapter->san_dbf = NULL;
1277 adapter->hba_dbf = NULL;
Martin Peschked79a83d2008-03-27 14:22:00 +01001278 adapter->rec_dbf = NULL;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001279}
1280
1281#undef ZFCP_LOG_AREA