blob: 0a1a5dd8d01831b9e13986ba9fd553b7ffc55342 [file] [log] [blame]
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001/*
Christof Schmitt553448f2008-06-10 18:20:58 +02002 * zfcp device driver
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02003 *
Christof Schmitt553448f2008-06-10 18:20:58 +02004 * Debug traces for zfcp.
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02005 *
Christof Schmitt553448f2008-06-10 18:20:58 +02006 * Copyright IBM Corporation 2002, 2008
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02007 */
8
Christof Schmittecf39d42008-12-25 13:39:53 +01009#define KMSG_COMPONENT "zfcp"
10#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
11
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020012#include <linux/ctype.h>
Heiko Carstens364c8552007-10-12 16:11:35 +020013#include <asm/debug.h>
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020014#include "zfcp_ext.h"
15
16static u32 dbfsize = 4;
17
18module_param(dbfsize, uint, 0400);
19MODULE_PARM_DESC(dbfsize,
20 "number of pages for each debug feature area (default 4)");
21
Martin Peschkec15450e2008-03-27 14:21:55 +010022static void zfcp_dbf_hexdump(debug_info_t *dbf, void *to, int to_len,
23 int level, char *from, int from_len)
24{
25 int offset;
26 struct zfcp_dbf_dump *dump = to;
27 int room = to_len - sizeof(*dump);
28
29 for (offset = 0; offset < from_len; offset += dump->size) {
30 memset(to, 0, to_len);
31 strncpy(dump->tag, "dump", ZFCP_DBF_TAG_SIZE);
32 dump->total_size = from_len;
33 dump->offset = offset;
34 dump->size = min(from_len - offset, room);
35 memcpy(dump->data, from + offset, dump->size);
Christof Schmittd94ce6c2008-11-04 16:35:12 +010036 debug_event(dbf, level, dump, dump->size + sizeof(*dump));
Martin Peschkec15450e2008-03-27 14:21:55 +010037 }
38}
39
Martin Peschke8fc5af12008-03-31 11:15:23 +020040/* FIXME: this duplicate this code in s390 debug feature */
41static void zfcp_dbf_timestamp(unsigned long long stck, struct timespec *time)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020042{
43 unsigned long long sec;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020044
45 stck -= 0x8126d60e46000000LL - (0x3c26700LL * 1000000 * 4096);
46 sec = stck >> 12;
47 do_div(sec, 1000000);
Martin Peschke8fc5af12008-03-31 11:15:23 +020048 time->tv_sec = sec;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020049 stck -= (sec * 1000000) << 12;
Martin Peschke8fc5af12008-03-31 11:15:23 +020050 time->tv_nsec = ((stck * 1000) >> 12);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020051}
52
Martin Peschkea9c85772008-03-31 11:15:27 +020053static void zfcp_dbf_tag(char **p, const char *label, const char *tag)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020054{
Martin Peschkea9c85772008-03-31 11:15:27 +020055 int i;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020056
Martin Peschkea9c85772008-03-31 11:15:27 +020057 *p += sprintf(*p, "%-24s", label);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020058 for (i = 0; i < ZFCP_DBF_TAG_SIZE; i++)
Martin Peschkea9c85772008-03-31 11:15:27 +020059 *p += sprintf(*p, "%c", tag[i]);
60 *p += sprintf(*p, "\n");
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020061}
62
Martin Peschke10223c62008-03-27 14:21:59 +010063static void zfcp_dbf_outs(char **buf, const char *s1, const char *s2)
64{
65 *buf += sprintf(*buf, "%-24s%s\n", s1, s2);
66}
67
68static void zfcp_dbf_out(char **buf, const char *s, const char *format, ...)
69{
70 va_list arg;
71
72 *buf += sprintf(*buf, "%-24s", s);
73 va_start(arg, format);
74 *buf += vsprintf(*buf, format, arg);
75 va_end(arg);
76 *buf += sprintf(*buf, "\n");
77}
78
Martin Peschkedf29f4a2008-03-31 11:15:26 +020079static void zfcp_dbf_outd(char **p, const char *label, char *buffer,
80 int buflen, int offset, int total_size)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020081{
Martin Peschkedf29f4a2008-03-31 11:15:26 +020082 if (!offset)
83 *p += sprintf(*p, "%-24s ", label);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020084 while (buflen--) {
85 if (offset > 0) {
86 if ((offset % 32) == 0)
Martin Peschkedf29f4a2008-03-31 11:15:26 +020087 *p += sprintf(*p, "\n%-24c ", ' ');
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020088 else if ((offset % 4) == 0)
Martin Peschkedf29f4a2008-03-31 11:15:26 +020089 *p += sprintf(*p, " ");
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020090 }
Martin Peschkedf29f4a2008-03-31 11:15:26 +020091 *p += sprintf(*p, "%02x", *buffer++);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020092 if (++offset == total_size) {
Martin Peschkedf29f4a2008-03-31 11:15:26 +020093 *p += sprintf(*p, "\n");
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020094 break;
95 }
96 }
Martin Peschkedf29f4a2008-03-31 11:15:26 +020097 if (!total_size)
98 *p += sprintf(*p, "\n");
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020099}
100
Martin Peschke92c7a832008-03-31 11:15:30 +0200101static int zfcp_dbf_view_header(debug_info_t *id, struct debug_view *view,
102 int area, debug_entry_t *entry, char *out_buf)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200103{
104 struct zfcp_dbf_dump *dump = (struct zfcp_dbf_dump *)DEBUG_DATA(entry);
Martin Peschke8fc5af12008-03-31 11:15:23 +0200105 struct timespec t;
Martin Peschkeb634fff2008-03-31 11:15:24 +0200106 char *p = out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200107
108 if (strncmp(dump->tag, "dump", ZFCP_DBF_TAG_SIZE) != 0) {
Martin Peschke8fc5af12008-03-31 11:15:23 +0200109 zfcp_dbf_timestamp(entry->id.stck, &t);
Martin Peschkeb634fff2008-03-31 11:15:24 +0200110 zfcp_dbf_out(&p, "timestamp", "%011lu:%06lu",
111 t.tv_sec, t.tv_nsec);
112 zfcp_dbf_out(&p, "cpu", "%02i", entry->id.fields.cpuid);
113 } else {
Christof Schmittd94ce6c2008-11-04 16:35:12 +0100114 zfcp_dbf_outd(&p, "", dump->data, dump->size, dump->offset,
Martin Peschkedf29f4a2008-03-31 11:15:26 +0200115 dump->total_size);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200116 if ((dump->offset + dump->size) == dump->total_size)
Martin Peschkeb634fff2008-03-31 11:15:24 +0200117 p += sprintf(p, "\n");
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200118 }
Martin Peschkeb634fff2008-03-31 11:15:24 +0200119 return p - out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200120}
121
Martin Peschkebfab1632008-03-31 11:15:31 +0200122/**
123 * zfcp_hba_dbf_event_fsf_response - trace event for request completion
124 * @fsf_req: request that has been completed
125 */
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100126void zfcp_hba_dbf_event_fsf_response(struct zfcp_fsf_req *fsf_req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200127{
128 struct zfcp_adapter *adapter = fsf_req->adapter;
129 struct fsf_qtcb *qtcb = fsf_req->qtcb;
130 union fsf_prot_status_qual *prot_status_qual =
Martin Peschke92c7a832008-03-31 11:15:30 +0200131 &qtcb->prefix.prot_status_qual;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200132 union fsf_status_qual *fsf_status_qual = &qtcb->header.fsf_status_qual;
133 struct scsi_cmnd *scsi_cmnd;
134 struct zfcp_port *port;
135 struct zfcp_unit *unit;
136 struct zfcp_send_els *send_els;
137 struct zfcp_hba_dbf_record *rec = &adapter->hba_dbf_buf;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200138 struct zfcp_hba_dbf_record_response *response = &rec->u.response;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200139 int level;
140 unsigned long flags;
141
142 spin_lock_irqsave(&adapter->hba_dbf_lock, flags);
Martin Peschke6bc473d2008-03-31 11:15:29 +0200143 memset(rec, 0, sizeof(*rec));
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200144 strncpy(rec->tag, "resp", ZFCP_DBF_TAG_SIZE);
145
146 if ((qtcb->prefix.prot_status != FSF_PROT_GOOD) &&
147 (qtcb->prefix.prot_status != FSF_PROT_FSF_STATUS_PRESENTED)) {
148 strncpy(rec->tag2, "perr", ZFCP_DBF_TAG_SIZE);
149 level = 1;
150 } else if (qtcb->header.fsf_status != FSF_GOOD) {
151 strncpy(rec->tag2, "ferr", ZFCP_DBF_TAG_SIZE);
152 level = 1;
153 } else if ((fsf_req->fsf_command == FSF_QTCB_OPEN_PORT_WITH_DID) ||
154 (fsf_req->fsf_command == FSF_QTCB_OPEN_LUN)) {
155 strncpy(rec->tag2, "open", ZFCP_DBF_TAG_SIZE);
156 level = 4;
Martin Peschkeb75db732008-03-27 14:21:58 +0100157 } else if (qtcb->header.log_length) {
158 strncpy(rec->tag2, "qtcb", ZFCP_DBF_TAG_SIZE);
159 level = 5;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200160 } else {
161 strncpy(rec->tag2, "norm", ZFCP_DBF_TAG_SIZE);
162 level = 6;
163 }
164
165 response->fsf_command = fsf_req->fsf_command;
166 response->fsf_reqid = (unsigned long)fsf_req;
167 response->fsf_seqno = fsf_req->seq_no;
168 response->fsf_issued = fsf_req->issued;
169 response->fsf_prot_status = qtcb->prefix.prot_status;
170 response->fsf_status = qtcb->header.fsf_status;
171 memcpy(response->fsf_prot_status_qual,
172 prot_status_qual, FSF_PROT_STATUS_QUAL_SIZE);
173 memcpy(response->fsf_status_qual,
174 fsf_status_qual, FSF_STATUS_QUALIFIER_SIZE);
175 response->fsf_req_status = fsf_req->status;
176 response->sbal_first = fsf_req->sbal_first;
Martin Peschkee891bff2008-05-19 12:17:43 +0200177 response->sbal_last = fsf_req->sbal_last;
Martin Peschkec3baa9a22008-05-19 12:17:44 +0200178 response->sbal_response = fsf_req->sbal_response;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200179 response->pool = fsf_req->pool != NULL;
180 response->erp_action = (unsigned long)fsf_req->erp_action;
181
182 switch (fsf_req->fsf_command) {
183 case FSF_QTCB_FCP_CMND:
184 if (fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT)
185 break;
186 scsi_cmnd = (struct scsi_cmnd *)fsf_req->data;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200187 if (scsi_cmnd) {
188 response->u.fcp.cmnd = (unsigned long)scsi_cmnd;
189 response->u.fcp.serial = scsi_cmnd->serial_number;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200190 }
191 break;
192
193 case FSF_QTCB_OPEN_PORT_WITH_DID:
194 case FSF_QTCB_CLOSE_PORT:
195 case FSF_QTCB_CLOSE_PHYSICAL_PORT:
196 port = (struct zfcp_port *)fsf_req->data;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200197 response->u.port.wwpn = port->wwpn;
198 response->u.port.d_id = port->d_id;
199 response->u.port.port_handle = qtcb->header.port_handle;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200200 break;
201
202 case FSF_QTCB_OPEN_LUN:
203 case FSF_QTCB_CLOSE_LUN:
204 unit = (struct zfcp_unit *)fsf_req->data;
205 port = unit->port;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200206 response->u.unit.wwpn = port->wwpn;
207 response->u.unit.fcp_lun = unit->fcp_lun;
208 response->u.unit.port_handle = qtcb->header.port_handle;
209 response->u.unit.lun_handle = qtcb->header.lun_handle;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200210 break;
211
212 case FSF_QTCB_SEND_ELS:
213 send_els = (struct zfcp_send_els *)fsf_req->data;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200214 response->u.els.d_id = qtcb->bottom.support.d_id;
215 response->u.els.ls_code = send_els->ls_code >> 24;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200216 break;
217
218 case FSF_QTCB_ABORT_FCP_CMND:
219 case FSF_QTCB_SEND_GENERIC:
220 case FSF_QTCB_EXCHANGE_CONFIG_DATA:
221 case FSF_QTCB_EXCHANGE_PORT_DATA:
222 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
223 case FSF_QTCB_UPLOAD_CONTROL_FILE:
224 break;
225 }
226
Martin Peschke6bc473d2008-03-31 11:15:29 +0200227 debug_event(adapter->hba_dbf, level, rec, sizeof(*rec));
Martin Peschkeb75db732008-03-27 14:21:58 +0100228
229 /* have fcp channel microcode fixed to use as little as possible */
230 if (fsf_req->fsf_command != FSF_QTCB_FCP_CMND) {
231 /* adjust length skipping trailing zeros */
232 char *buf = (char *)qtcb + qtcb->header.log_start;
233 int len = qtcb->header.log_length;
234 for (; len && !buf[len - 1]; len--);
235 zfcp_dbf_hexdump(adapter->hba_dbf, rec, sizeof(*rec), level,
236 buf, len);
237 }
238
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200239 spin_unlock_irqrestore(&adapter->hba_dbf_lock, flags);
240}
241
Martin Peschkebfab1632008-03-31 11:15:31 +0200242/**
243 * zfcp_hba_dbf_event_fsf_unsol - trace event for an unsolicited status buffer
244 * @tag: tag indicating which kind of unsolicited status has been received
245 * @adapter: adapter that has issued the unsolicited status buffer
246 * @status_buffer: buffer containing payload of unsolicited status
247 */
Martin Peschke92c7a832008-03-31 11:15:30 +0200248void zfcp_hba_dbf_event_fsf_unsol(const char *tag, struct zfcp_adapter *adapter,
249 struct fsf_status_read_buffer *status_buffer)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200250{
251 struct zfcp_hba_dbf_record *rec = &adapter->hba_dbf_buf;
252 unsigned long flags;
253
254 spin_lock_irqsave(&adapter->hba_dbf_lock, flags);
Martin Peschke6bc473d2008-03-31 11:15:29 +0200255 memset(rec, 0, sizeof(*rec));
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200256 strncpy(rec->tag, "stat", ZFCP_DBF_TAG_SIZE);
257 strncpy(rec->tag2, tag, ZFCP_DBF_TAG_SIZE);
258
Swen Schilligd26ab062008-05-19 12:17:37 +0200259 rec->u.status.failed = atomic_read(&adapter->stat_miss);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200260 if (status_buffer != NULL) {
Martin Peschke6bc473d2008-03-31 11:15:29 +0200261 rec->u.status.status_type = status_buffer->status_type;
262 rec->u.status.status_subtype = status_buffer->status_subtype;
263 memcpy(&rec->u.status.queue_designator,
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200264 &status_buffer->queue_designator,
265 sizeof(struct fsf_queue_designator));
266
267 switch (status_buffer->status_type) {
268 case FSF_STATUS_READ_SENSE_DATA_AVAIL:
Martin Peschke6bc473d2008-03-31 11:15:29 +0200269 rec->u.status.payload_size =
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200270 ZFCP_DBF_UNSOL_PAYLOAD_SENSE_DATA_AVAIL;
271 break;
272
273 case FSF_STATUS_READ_BIT_ERROR_THRESHOLD:
Martin Peschke6bc473d2008-03-31 11:15:29 +0200274 rec->u.status.payload_size =
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200275 ZFCP_DBF_UNSOL_PAYLOAD_BIT_ERROR_THRESHOLD;
276 break;
277
278 case FSF_STATUS_READ_LINK_DOWN:
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200279 switch (status_buffer->status_subtype) {
280 case FSF_STATUS_READ_SUB_NO_PHYSICAL_LINK:
281 case FSF_STATUS_READ_SUB_FDISC_FAILED:
Martin Peschke6bc473d2008-03-31 11:15:29 +0200282 rec->u.status.payload_size =
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200283 sizeof(struct fsf_link_down_info);
284 }
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200285 break;
286
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200287 case FSF_STATUS_READ_FEATURE_UPDATE_ALERT:
Martin Peschke6bc473d2008-03-31 11:15:29 +0200288 rec->u.status.payload_size =
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200289 ZFCP_DBF_UNSOL_PAYLOAD_FEATURE_UPDATE_ALERT;
290 break;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200291 }
Martin Peschke6bc473d2008-03-31 11:15:29 +0200292 memcpy(&rec->u.status.payload,
293 &status_buffer->payload, rec->u.status.payload_size);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200294 }
295
Martin Peschke6bc473d2008-03-31 11:15:29 +0200296 debug_event(adapter->hba_dbf, 2, rec, sizeof(*rec));
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200297 spin_unlock_irqrestore(&adapter->hba_dbf_lock, flags);
298}
299
Martin Peschkebfab1632008-03-31 11:15:31 +0200300/**
301 * zfcp_hba_dbf_event_qdio - trace event for QDIO related failure
302 * @adapter: adapter affected by this QDIO related event
Martin Peschkebfab1632008-03-31 11:15:31 +0200303 * @qdio_error: as passed by qdio module
Martin Peschkebfab1632008-03-31 11:15:31 +0200304 * @sbal_index: first buffer with error condition, as passed by qdio module
305 * @sbal_count: number of buffers affected, as passed by qdio module
306 */
Jan Glauber779e6e12008-07-17 17:16:48 +0200307void zfcp_hba_dbf_event_qdio(struct zfcp_adapter *adapter,
308 unsigned int qdio_error, int sbal_index,
309 int sbal_count)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200310{
Martin Peschke6bc473d2008-03-31 11:15:29 +0200311 struct zfcp_hba_dbf_record *r = &adapter->hba_dbf_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200312 unsigned long flags;
313
314 spin_lock_irqsave(&adapter->hba_dbf_lock, flags);
Martin Peschke6bc473d2008-03-31 11:15:29 +0200315 memset(r, 0, sizeof(*r));
316 strncpy(r->tag, "qdio", ZFCP_DBF_TAG_SIZE);
Martin Peschke6bc473d2008-03-31 11:15:29 +0200317 r->u.qdio.qdio_error = qdio_error;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200318 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
Swen Schillig57069382008-10-01 12:42:21 +0200324/**
325 * zfcp_hba_dbf_event_berr - trace event for bit error threshold
326 * @adapter: adapter affected by this QDIO related event
327 * @req: fsf request
328 */
329void zfcp_hba_dbf_event_berr(struct zfcp_adapter *adapter,
330 struct zfcp_fsf_req *req)
331{
332 struct zfcp_hba_dbf_record *r = &adapter->hba_dbf_buf;
333 struct fsf_status_read_buffer *sr_buf = req->data;
334 struct fsf_bit_error_payload *err = &sr_buf->payload.bit_error;
335 unsigned long flags;
336
337 spin_lock_irqsave(&adapter->hba_dbf_lock, flags);
338 memset(r, 0, sizeof(*r));
339 strncpy(r->tag, "berr", ZFCP_DBF_TAG_SIZE);
340 memcpy(&r->u.berr, err, sizeof(struct fsf_bit_error_payload));
341 debug_event(adapter->hba_dbf, 0, r, sizeof(*r));
342 spin_unlock_irqrestore(&adapter->hba_dbf_lock, flags);
343}
Martin Peschkea9c85772008-03-31 11:15:27 +0200344static void zfcp_hba_dbf_view_response(char **p,
345 struct zfcp_hba_dbf_record_response *r)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200346{
Martin Peschke8fc5af12008-03-31 11:15:23 +0200347 struct timespec t;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200348
Martin Peschkea9c85772008-03-31 11:15:27 +0200349 zfcp_dbf_out(p, "fsf_command", "0x%08x", r->fsf_command);
350 zfcp_dbf_out(p, "fsf_reqid", "0x%0Lx", r->fsf_reqid);
351 zfcp_dbf_out(p, "fsf_seqno", "0x%08x", r->fsf_seqno);
Martin Peschkeb634fff2008-03-31 11:15:24 +0200352 zfcp_dbf_timestamp(r->fsf_issued, &t);
Martin Peschkea9c85772008-03-31 11:15:27 +0200353 zfcp_dbf_out(p, "fsf_issued", "%011lu:%06lu", t.tv_sec, t.tv_nsec);
354 zfcp_dbf_out(p, "fsf_prot_status", "0x%08x", r->fsf_prot_status);
355 zfcp_dbf_out(p, "fsf_status", "0x%08x", r->fsf_status);
356 zfcp_dbf_outd(p, "fsf_prot_status_qual", r->fsf_prot_status_qual,
Martin Peschkedf29f4a2008-03-31 11:15:26 +0200357 FSF_PROT_STATUS_QUAL_SIZE, 0, FSF_PROT_STATUS_QUAL_SIZE);
Martin Peschkea9c85772008-03-31 11:15:27 +0200358 zfcp_dbf_outd(p, "fsf_status_qual", r->fsf_status_qual,
Martin Peschkedf29f4a2008-03-31 11:15:26 +0200359 FSF_STATUS_QUALIFIER_SIZE, 0, FSF_STATUS_QUALIFIER_SIZE);
Martin Peschkea9c85772008-03-31 11:15:27 +0200360 zfcp_dbf_out(p, "fsf_req_status", "0x%08x", r->fsf_req_status);
361 zfcp_dbf_out(p, "sbal_first", "0x%02x", r->sbal_first);
Martin Peschkee891bff2008-05-19 12:17:43 +0200362 zfcp_dbf_out(p, "sbal_last", "0x%02x", r->sbal_last);
Martin Peschkec3baa9a22008-05-19 12:17:44 +0200363 zfcp_dbf_out(p, "sbal_response", "0x%02x", r->sbal_response);
Martin Peschkea9c85772008-03-31 11:15:27 +0200364 zfcp_dbf_out(p, "pool", "0x%02x", r->pool);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200365
Martin Peschkeb634fff2008-03-31 11:15:24 +0200366 switch (r->fsf_command) {
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200367 case FSF_QTCB_FCP_CMND:
Martin Peschkeb634fff2008-03-31 11:15:24 +0200368 if (r->fsf_req_status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200369 break;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200370 zfcp_dbf_out(p, "scsi_cmnd", "0x%0Lx", r->u.fcp.cmnd);
371 zfcp_dbf_out(p, "scsi_serial", "0x%016Lx", r->u.fcp.serial);
Christof Schmittd94ce6c2008-11-04 16:35:12 +0100372 p += sprintf(*p, "\n");
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200373 break;
374
375 case FSF_QTCB_OPEN_PORT_WITH_DID:
376 case FSF_QTCB_CLOSE_PORT:
377 case FSF_QTCB_CLOSE_PHYSICAL_PORT:
Martin Peschke6bc473d2008-03-31 11:15:29 +0200378 zfcp_dbf_out(p, "wwpn", "0x%016Lx", r->u.port.wwpn);
379 zfcp_dbf_out(p, "d_id", "0x%06x", r->u.port.d_id);
380 zfcp_dbf_out(p, "port_handle", "0x%08x", r->u.port.port_handle);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200381 break;
382
383 case FSF_QTCB_OPEN_LUN:
384 case FSF_QTCB_CLOSE_LUN:
Martin Peschke6bc473d2008-03-31 11:15:29 +0200385 zfcp_dbf_out(p, "wwpn", "0x%016Lx", r->u.unit.wwpn);
386 zfcp_dbf_out(p, "fcp_lun", "0x%016Lx", r->u.unit.fcp_lun);
387 zfcp_dbf_out(p, "port_handle", "0x%08x", r->u.unit.port_handle);
388 zfcp_dbf_out(p, "lun_handle", "0x%08x", r->u.unit.lun_handle);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200389 break;
390
391 case FSF_QTCB_SEND_ELS:
Martin Peschke6bc473d2008-03-31 11:15:29 +0200392 zfcp_dbf_out(p, "d_id", "0x%06x", r->u.els.d_id);
393 zfcp_dbf_out(p, "ls_code", "0x%02x", r->u.els.ls_code);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200394 break;
395
396 case FSF_QTCB_ABORT_FCP_CMND:
397 case FSF_QTCB_SEND_GENERIC:
398 case FSF_QTCB_EXCHANGE_CONFIG_DATA:
399 case FSF_QTCB_EXCHANGE_PORT_DATA:
400 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
401 case FSF_QTCB_UPLOAD_CONTROL_FILE:
402 break;
403 }
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200404}
405
Martin Peschkea9c85772008-03-31 11:15:27 +0200406static void zfcp_hba_dbf_view_status(char **p,
407 struct zfcp_hba_dbf_record_status *r)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200408{
Martin Peschkea9c85772008-03-31 11:15:27 +0200409 zfcp_dbf_out(p, "failed", "0x%02x", r->failed);
410 zfcp_dbf_out(p, "status_type", "0x%08x", r->status_type);
411 zfcp_dbf_out(p, "status_subtype", "0x%08x", r->status_subtype);
412 zfcp_dbf_outd(p, "queue_designator", (char *)&r->queue_designator,
Martin Peschkedf29f4a2008-03-31 11:15:26 +0200413 sizeof(struct fsf_queue_designator), 0,
414 sizeof(struct fsf_queue_designator));
Martin Peschkea9c85772008-03-31 11:15:27 +0200415 zfcp_dbf_outd(p, "payload", (char *)&r->payload, r->payload_size, 0,
Martin Peschkedf29f4a2008-03-31 11:15:26 +0200416 r->payload_size);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200417}
418
Martin Peschkea9c85772008-03-31 11:15:27 +0200419static void zfcp_hba_dbf_view_qdio(char **p, struct zfcp_hba_dbf_record_qdio *r)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200420{
Martin Peschkea9c85772008-03-31 11:15:27 +0200421 zfcp_dbf_out(p, "qdio_error", "0x%08x", r->qdio_error);
Martin Peschkea9c85772008-03-31 11:15:27 +0200422 zfcp_dbf_out(p, "sbal_index", "0x%02x", r->sbal_index);
423 zfcp_dbf_out(p, "sbal_count", "0x%02x", r->sbal_count);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200424}
425
Swen Schillig57069382008-10-01 12:42:21 +0200426static void zfcp_hba_dbf_view_berr(char **p, struct fsf_bit_error_payload *r)
427{
428 zfcp_dbf_out(p, "link_failures", "%d", r->link_failure_error_count);
429 zfcp_dbf_out(p, "loss_of_sync_err", "%d", r->loss_of_sync_error_count);
430 zfcp_dbf_out(p, "loss_of_sig_err", "%d", r->loss_of_signal_error_count);
431 zfcp_dbf_out(p, "prim_seq_err", "%d",
432 r->primitive_sequence_error_count);
433 zfcp_dbf_out(p, "inval_trans_word_err", "%d",
434 r->invalid_transmission_word_error_count);
435 zfcp_dbf_out(p, "CRC_errors", "%d", r->crc_error_count);
436 zfcp_dbf_out(p, "prim_seq_event_to", "%d",
437 r->primitive_sequence_event_timeout_count);
438 zfcp_dbf_out(p, "elast_buf_overrun_err", "%d",
439 r->elastic_buffer_overrun_error_count);
440 zfcp_dbf_out(p, "adv_rec_buf2buf_cred", "%d",
441 r->advertised_receive_b2b_credit);
442 zfcp_dbf_out(p, "curr_rec_buf2buf_cred", "%d",
443 r->current_receive_b2b_credit);
444 zfcp_dbf_out(p, "adv_trans_buf2buf_cred", "%d",
445 r->advertised_transmit_b2b_credit);
446 zfcp_dbf_out(p, "curr_trans_buf2buf_cred", "%d",
447 r->current_transmit_b2b_credit);
448}
449
Martin Peschkea9c85772008-03-31 11:15:27 +0200450static int zfcp_hba_dbf_view_format(debug_info_t *id, struct debug_view *view,
451 char *out_buf, const char *in_buf)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200452{
Martin Peschkea9c85772008-03-31 11:15:27 +0200453 struct zfcp_hba_dbf_record *r = (struct zfcp_hba_dbf_record *)in_buf;
454 char *p = out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200455
Martin Peschkea9c85772008-03-31 11:15:27 +0200456 if (strncmp(r->tag, "dump", ZFCP_DBF_TAG_SIZE) == 0)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200457 return 0;
458
Martin Peschkea9c85772008-03-31 11:15:27 +0200459 zfcp_dbf_tag(&p, "tag", r->tag);
460 if (isalpha(r->tag2[0]))
461 zfcp_dbf_tag(&p, "tag2", r->tag2);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200462
Martin Peschkea9c85772008-03-31 11:15:27 +0200463 if (strncmp(r->tag, "resp", ZFCP_DBF_TAG_SIZE) == 0)
Martin Peschke6bc473d2008-03-31 11:15:29 +0200464 zfcp_hba_dbf_view_response(&p, &r->u.response);
Martin Peschkea9c85772008-03-31 11:15:27 +0200465 else if (strncmp(r->tag, "stat", ZFCP_DBF_TAG_SIZE) == 0)
Martin Peschke6bc473d2008-03-31 11:15:29 +0200466 zfcp_hba_dbf_view_status(&p, &r->u.status);
Martin Peschkea9c85772008-03-31 11:15:27 +0200467 else if (strncmp(r->tag, "qdio", ZFCP_DBF_TAG_SIZE) == 0)
Martin Peschke6bc473d2008-03-31 11:15:29 +0200468 zfcp_hba_dbf_view_qdio(&p, &r->u.qdio);
Swen Schillig57069382008-10-01 12:42:21 +0200469 else if (strncmp(r->tag, "berr", ZFCP_DBF_TAG_SIZE) == 0)
470 zfcp_hba_dbf_view_berr(&p, &r->u.berr);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200471
Christof Schmittd94ce6c2008-11-04 16:35:12 +0100472 if (strncmp(r->tag, "resp", ZFCP_DBF_TAG_SIZE) != 0)
473 p += sprintf(p, "\n");
Martin Peschkea9c85772008-03-31 11:15:27 +0200474 return p - out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200475}
476
Heiko Carstens2b67fc42007-02-05 21:16:47 +0100477static struct debug_view zfcp_hba_dbf_view = {
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200478 "structured",
479 NULL,
480 &zfcp_dbf_view_header,
481 &zfcp_hba_dbf_view_format,
482 NULL,
483 NULL
484};
485
Martin Peschked79a83d2008-03-27 14:22:00 +0100486static const char *zfcp_rec_dbf_tags[] = {
Martin Peschke348447e2008-03-27 14:22:01 +0100487 [ZFCP_REC_DBF_ID_THREAD] = "thread",
Martin Peschke698ec0162008-03-27 14:22:02 +0100488 [ZFCP_REC_DBF_ID_TARGET] = "target",
Martin Peschke9467a9b2008-03-27 14:22:03 +0100489 [ZFCP_REC_DBF_ID_TRIGGER] = "trigger",
Martin Peschke6f4f3652008-03-27 14:22:04 +0100490 [ZFCP_REC_DBF_ID_ACTION] = "action",
Martin Peschked79a83d2008-03-27 14:22:00 +0100491};
492
Martin Peschked79a83d2008-03-27 14:22:00 +0100493static int zfcp_rec_dbf_view_format(debug_info_t *id, struct debug_view *view,
494 char *buf, const char *_rec)
495{
496 struct zfcp_rec_dbf_record *r = (struct zfcp_rec_dbf_record *)_rec;
497 char *p = buf;
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100498 char hint[ZFCP_DBF_ID_SIZE + 1];
Martin Peschked79a83d2008-03-27 14:22:00 +0100499
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100500 memcpy(hint, r->id2, ZFCP_DBF_ID_SIZE);
501 hint[ZFCP_DBF_ID_SIZE] = 0;
Martin Peschked79a83d2008-03-27 14:22:00 +0100502 zfcp_dbf_outs(&p, "tag", zfcp_rec_dbf_tags[r->id]);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100503 zfcp_dbf_outs(&p, "hint", hint);
Martin Peschked79a83d2008-03-27 14:22:00 +0100504 switch (r->id) {
Martin Peschke348447e2008-03-27 14:22:01 +0100505 case ZFCP_REC_DBF_ID_THREAD:
Martin Peschke348447e2008-03-27 14:22:01 +0100506 zfcp_dbf_out(&p, "total", "%d", r->u.thread.total);
507 zfcp_dbf_out(&p, "ready", "%d", r->u.thread.ready);
508 zfcp_dbf_out(&p, "running", "%d", r->u.thread.running);
509 break;
Martin Peschke698ec0162008-03-27 14:22:02 +0100510 case ZFCP_REC_DBF_ID_TARGET:
511 zfcp_dbf_out(&p, "reference", "0x%016Lx", r->u.target.ref);
512 zfcp_dbf_out(&p, "status", "0x%08x", r->u.target.status);
513 zfcp_dbf_out(&p, "erp_count", "%d", r->u.target.erp_count);
514 zfcp_dbf_out(&p, "d_id", "0x%06x", r->u.target.d_id);
515 zfcp_dbf_out(&p, "wwpn", "0x%016Lx", r->u.target.wwpn);
516 zfcp_dbf_out(&p, "fcp_lun", "0x%016Lx", r->u.target.fcp_lun);
517 break;
Martin Peschke9467a9b2008-03-27 14:22:03 +0100518 case ZFCP_REC_DBF_ID_TRIGGER:
519 zfcp_dbf_out(&p, "reference", "0x%016Lx", r->u.trigger.ref);
520 zfcp_dbf_out(&p, "erp_action", "0x%016Lx", r->u.trigger.action);
521 zfcp_dbf_out(&p, "requested", "%d", r->u.trigger.want);
522 zfcp_dbf_out(&p, "executed", "%d", r->u.trigger.need);
523 zfcp_dbf_out(&p, "wwpn", "0x%016Lx", r->u.trigger.wwpn);
524 zfcp_dbf_out(&p, "fcp_lun", "0x%016Lx", r->u.trigger.fcp_lun);
525 zfcp_dbf_out(&p, "adapter_status", "0x%08x", r->u.trigger.as);
526 zfcp_dbf_out(&p, "port_status", "0x%08x", r->u.trigger.ps);
527 zfcp_dbf_out(&p, "unit_status", "0x%08x", r->u.trigger.us);
528 break;
Martin Peschke6f4f3652008-03-27 14:22:04 +0100529 case ZFCP_REC_DBF_ID_ACTION:
530 zfcp_dbf_out(&p, "erp_action", "0x%016Lx", r->u.action.action);
531 zfcp_dbf_out(&p, "fsf_req", "0x%016Lx", r->u.action.fsf_req);
532 zfcp_dbf_out(&p, "status", "0x%08Lx", r->u.action.status);
533 zfcp_dbf_out(&p, "step", "0x%08Lx", r->u.action.step);
534 break;
Martin Peschked79a83d2008-03-27 14:22:00 +0100535 }
Martin Peschkeb634fff2008-03-31 11:15:24 +0200536 p += sprintf(p, "\n");
537 return p - buf;
Martin Peschked79a83d2008-03-27 14:22:00 +0100538}
539
540static struct debug_view zfcp_rec_dbf_view = {
541 "structured",
542 NULL,
543 &zfcp_dbf_view_header,
544 &zfcp_rec_dbf_view_format,
545 NULL,
546 NULL
547};
548
Martin Peschke348447e2008-03-27 14:22:01 +0100549/**
550 * zfcp_rec_dbf_event_thread - trace event related to recovery thread operation
551 * @id2: identifier for event
552 * @adapter: adapter
Christof Schmittaa0fec62008-05-19 12:17:47 +0200553 * This function assumes that the caller is holding erp_lock.
Martin Peschke348447e2008-03-27 14:22:01 +0100554 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100555void zfcp_rec_dbf_event_thread(char *id2, struct zfcp_adapter *adapter)
Martin Peschke348447e2008-03-27 14:22:01 +0100556{
557 struct zfcp_rec_dbf_record *r = &adapter->rec_dbf_buf;
558 unsigned long flags = 0;
559 struct list_head *entry;
560 unsigned ready = 0, running = 0, total;
561
Martin Peschke348447e2008-03-27 14:22:01 +0100562 list_for_each(entry, &adapter->erp_ready_head)
563 ready++;
564 list_for_each(entry, &adapter->erp_running_head)
565 running++;
566 total = adapter->erp_total_count;
Martin Peschke348447e2008-03-27 14:22:01 +0100567
568 spin_lock_irqsave(&adapter->rec_dbf_lock, flags);
569 memset(r, 0, sizeof(*r));
570 r->id = ZFCP_REC_DBF_ID_THREAD;
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100571 memcpy(r->id2, id2, ZFCP_DBF_ID_SIZE);
Martin Peschke348447e2008-03-27 14:22:01 +0100572 r->u.thread.total = total;
573 r->u.thread.ready = ready;
574 r->u.thread.running = running;
Martin Peschke70c66542008-05-19 12:17:45 +0200575 debug_event(adapter->rec_dbf, 6, r, sizeof(*r));
Martin Peschke348447e2008-03-27 14:22:01 +0100576 spin_unlock_irqrestore(&adapter->rec_dbf_lock, flags);
577}
578
Christof Schmittaa0fec62008-05-19 12:17:47 +0200579/**
580 * zfcp_rec_dbf_event_thread - trace event related to recovery thread operation
581 * @id2: identifier for event
582 * @adapter: adapter
583 * This function assumes that the caller does not hold erp_lock.
584 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100585void zfcp_rec_dbf_event_thread_lock(char *id2, struct zfcp_adapter *adapter)
Christof Schmittaa0fec62008-05-19 12:17:47 +0200586{
587 unsigned long flags;
588
589 read_lock_irqsave(&adapter->erp_lock, flags);
590 zfcp_rec_dbf_event_thread(id2, adapter);
591 read_unlock_irqrestore(&adapter->erp_lock, flags);
592}
593
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100594static void zfcp_rec_dbf_event_target(char *id2, void *ref,
Martin Peschke698ec0162008-03-27 14:22:02 +0100595 struct zfcp_adapter *adapter,
596 atomic_t *status, atomic_t *erp_count,
597 u64 wwpn, u32 d_id, u64 fcp_lun)
598{
599 struct zfcp_rec_dbf_record *r = &adapter->rec_dbf_buf;
600 unsigned long flags;
601
602 spin_lock_irqsave(&adapter->rec_dbf_lock, flags);
603 memset(r, 0, sizeof(*r));
604 r->id = ZFCP_REC_DBF_ID_TARGET;
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100605 memcpy(r->id2, id2, ZFCP_DBF_ID_SIZE);
Martin Peschke1f6f7122008-04-18 12:51:55 +0200606 r->u.target.ref = (unsigned long)ref;
Martin Peschke698ec0162008-03-27 14:22:02 +0100607 r->u.target.status = atomic_read(status);
608 r->u.target.wwpn = wwpn;
609 r->u.target.d_id = d_id;
610 r->u.target.fcp_lun = fcp_lun;
611 r->u.target.erp_count = atomic_read(erp_count);
612 debug_event(adapter->rec_dbf, 3, r, sizeof(*r));
613 spin_unlock_irqrestore(&adapter->rec_dbf_lock, flags);
614}
615
616/**
617 * zfcp_rec_dbf_event_adapter - trace event for adapter state change
618 * @id: identifier for trigger of state change
619 * @ref: additional reference (e.g. request)
620 * @adapter: adapter
621 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100622void zfcp_rec_dbf_event_adapter(char *id, void *ref,
623 struct zfcp_adapter *adapter)
Martin Peschke698ec0162008-03-27 14:22:02 +0100624{
625 zfcp_rec_dbf_event_target(id, ref, adapter, &adapter->status,
626 &adapter->erp_counter, 0, 0, 0);
627}
628
629/**
630 * zfcp_rec_dbf_event_port - trace event for port state change
631 * @id: identifier for trigger of state change
632 * @ref: additional reference (e.g. request)
633 * @port: port
634 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100635void zfcp_rec_dbf_event_port(char *id, void *ref, struct zfcp_port *port)
Martin Peschke698ec0162008-03-27 14:22:02 +0100636{
637 struct zfcp_adapter *adapter = port->adapter;
638
639 zfcp_rec_dbf_event_target(id, ref, adapter, &port->status,
640 &port->erp_counter, port->wwpn, port->d_id,
641 0);
642}
643
644/**
645 * zfcp_rec_dbf_event_unit - trace event for unit state change
646 * @id: identifier for trigger of state change
647 * @ref: additional reference (e.g. request)
648 * @unit: unit
649 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100650void zfcp_rec_dbf_event_unit(char *id, void *ref, struct zfcp_unit *unit)
Martin Peschke698ec0162008-03-27 14:22:02 +0100651{
652 struct zfcp_port *port = unit->port;
653 struct zfcp_adapter *adapter = port->adapter;
654
655 zfcp_rec_dbf_event_target(id, ref, adapter, &unit->status,
656 &unit->erp_counter, port->wwpn, port->d_id,
657 unit->fcp_lun);
658}
659
Martin Peschke9467a9b2008-03-27 14:22:03 +0100660/**
661 * zfcp_rec_dbf_event_trigger - trace event for triggered error recovery
662 * @id2: identifier for error recovery trigger
663 * @ref: additional reference (e.g. request)
664 * @want: originally requested error recovery action
665 * @need: error recovery action actually initiated
666 * @action: address of error recovery action struct
667 * @adapter: adapter
668 * @port: port
669 * @unit: unit
670 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100671void zfcp_rec_dbf_event_trigger(char *id2, void *ref, u8 want, u8 need,
Martin Peschke1f6f7122008-04-18 12:51:55 +0200672 void *action, struct zfcp_adapter *adapter,
Martin Peschke9467a9b2008-03-27 14:22:03 +0100673 struct zfcp_port *port, struct zfcp_unit *unit)
674{
675 struct zfcp_rec_dbf_record *r = &adapter->rec_dbf_buf;
676 unsigned long flags;
677
678 spin_lock_irqsave(&adapter->rec_dbf_lock, flags);
679 memset(r, 0, sizeof(*r));
680 r->id = ZFCP_REC_DBF_ID_TRIGGER;
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100681 memcpy(r->id2, id2, ZFCP_DBF_ID_SIZE);
Martin Peschke1f6f7122008-04-18 12:51:55 +0200682 r->u.trigger.ref = (unsigned long)ref;
Martin Peschke9467a9b2008-03-27 14:22:03 +0100683 r->u.trigger.want = want;
684 r->u.trigger.need = need;
Martin Peschke1f6f7122008-04-18 12:51:55 +0200685 r->u.trigger.action = (unsigned long)action;
Martin Peschke9467a9b2008-03-27 14:22:03 +0100686 r->u.trigger.as = atomic_read(&adapter->status);
687 if (port) {
688 r->u.trigger.ps = atomic_read(&port->status);
689 r->u.trigger.wwpn = port->wwpn;
690 }
691 if (unit) {
692 r->u.trigger.us = atomic_read(&unit->status);
693 r->u.trigger.fcp_lun = unit->fcp_lun;
694 }
695 debug_event(adapter->rec_dbf, action ? 1 : 4, r, sizeof(*r));
696 spin_unlock_irqrestore(&adapter->rec_dbf_lock, flags);
697}
698
Martin Peschke6f4f3652008-03-27 14:22:04 +0100699/**
700 * zfcp_rec_dbf_event_action - trace event showing progress of recovery action
701 * @id2: identifier
702 * @erp_action: error recovery action struct pointer
703 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100704void zfcp_rec_dbf_event_action(char *id2, struct zfcp_erp_action *erp_action)
Martin Peschke6f4f3652008-03-27 14:22:04 +0100705{
706 struct zfcp_adapter *adapter = erp_action->adapter;
707 struct zfcp_rec_dbf_record *r = &adapter->rec_dbf_buf;
708 unsigned long flags;
709
710 spin_lock_irqsave(&adapter->rec_dbf_lock, flags);
711 memset(r, 0, sizeof(*r));
712 r->id = ZFCP_REC_DBF_ID_ACTION;
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100713 memcpy(r->id2, id2, ZFCP_DBF_ID_SIZE);
Martin Peschke1f6f7122008-04-18 12:51:55 +0200714 r->u.action.action = (unsigned long)erp_action;
Martin Peschke6f4f3652008-03-27 14:22:04 +0100715 r->u.action.status = erp_action->status;
716 r->u.action.step = erp_action->step;
Martin Peschke1f6f7122008-04-18 12:51:55 +0200717 r->u.action.fsf_req = (unsigned long)erp_action->fsf_req;
Martin Peschke70c66542008-05-19 12:17:45 +0200718 debug_event(adapter->rec_dbf, 5, r, sizeof(*r));
Martin Peschke6f4f3652008-03-27 14:22:04 +0100719 spin_unlock_irqrestore(&adapter->rec_dbf_lock, flags);
720}
721
Martin Peschkebfab1632008-03-31 11:15:31 +0200722/**
723 * zfcp_san_dbf_event_ct_request - trace event for issued CT request
724 * @fsf_req: request containing issued CT data
725 */
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100726void zfcp_san_dbf_event_ct_request(struct zfcp_fsf_req *fsf_req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200727{
728 struct zfcp_send_ct *ct = (struct zfcp_send_ct *)fsf_req->data;
Swen Schillig5ab944f2008-10-01 12:42:17 +0200729 struct zfcp_wka_port *wka_port = ct->wka_port;
730 struct zfcp_adapter *adapter = wka_port->adapter;
Swen Schillig44cc76f2008-10-01 12:42:16 +0200731 struct ct_hdr *hdr = sg_virt(ct->req);
Martin Peschke6bc473d2008-03-31 11:15:29 +0200732 struct zfcp_san_dbf_record *r = &adapter->san_dbf_buf;
733 struct zfcp_san_dbf_record_ct_request *oct = &r->u.ct_req;
Christof Schmittd94ce6c2008-11-04 16:35:12 +0100734 int level = 3;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200735 unsigned long flags;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200736
Martin Peschke6bc473d2008-03-31 11:15:29 +0200737 spin_lock_irqsave(&adapter->san_dbf_lock, flags);
738 memset(r, 0, sizeof(*r));
739 strncpy(r->tag, "octc", ZFCP_DBF_TAG_SIZE);
740 r->fsf_reqid = (unsigned long)fsf_req;
741 r->fsf_seqno = fsf_req->seq_no;
742 r->s_id = fc_host_port_id(adapter->scsi_host);
Swen Schillig5ab944f2008-10-01 12:42:17 +0200743 r->d_id = wka_port->d_id;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200744 oct->cmd_req_code = hdr->cmd_rsp_code;
745 oct->revision = hdr->revision;
746 oct->gs_type = hdr->gs_type;
747 oct->gs_subtype = hdr->gs_subtype;
748 oct->options = hdr->options;
749 oct->max_res_size = hdr->max_res_size;
750 oct->len = min((int)ct->req->length - (int)sizeof(struct ct_hdr),
Christof Schmittd94ce6c2008-11-04 16:35:12 +0100751 ZFCP_DBF_SAN_MAX_PAYLOAD);
752 debug_event(adapter->san_dbf, level, r, sizeof(*r));
753 zfcp_dbf_hexdump(adapter->san_dbf, r, sizeof(*r), level,
754 (void *)hdr + sizeof(struct ct_hdr), oct->len);
Martin Peschke6bc473d2008-03-31 11:15:29 +0200755 spin_unlock_irqrestore(&adapter->san_dbf_lock, flags);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200756}
757
Martin Peschkebfab1632008-03-31 11:15:31 +0200758/**
759 * zfcp_san_dbf_event_ct_response - trace event for completion of CT request
760 * @fsf_req: request containing CT response
761 */
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100762void zfcp_san_dbf_event_ct_response(struct zfcp_fsf_req *fsf_req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200763{
764 struct zfcp_send_ct *ct = (struct zfcp_send_ct *)fsf_req->data;
Swen Schillig5ab944f2008-10-01 12:42:17 +0200765 struct zfcp_wka_port *wka_port = ct->wka_port;
766 struct zfcp_adapter *adapter = wka_port->adapter;
Swen Schillig44cc76f2008-10-01 12:42:16 +0200767 struct ct_hdr *hdr = sg_virt(ct->resp);
Martin Peschke6bc473d2008-03-31 11:15:29 +0200768 struct zfcp_san_dbf_record *r = &adapter->san_dbf_buf;
769 struct zfcp_san_dbf_record_ct_response *rct = &r->u.ct_resp;
Christof Schmittd94ce6c2008-11-04 16:35:12 +0100770 int level = 3;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200771 unsigned long flags;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200772
Martin Peschke6bc473d2008-03-31 11:15:29 +0200773 spin_lock_irqsave(&adapter->san_dbf_lock, flags);
774 memset(r, 0, sizeof(*r));
775 strncpy(r->tag, "rctc", ZFCP_DBF_TAG_SIZE);
776 r->fsf_reqid = (unsigned long)fsf_req;
777 r->fsf_seqno = fsf_req->seq_no;
Swen Schillig5ab944f2008-10-01 12:42:17 +0200778 r->s_id = wka_port->d_id;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200779 r->d_id = fc_host_port_id(adapter->scsi_host);
780 rct->cmd_rsp_code = hdr->cmd_rsp_code;
781 rct->revision = hdr->revision;
782 rct->reason_code = hdr->reason_code;
783 rct->expl = hdr->reason_code_expl;
784 rct->vendor_unique = hdr->vendor_unique;
Christof Schmitt39eb7e9a2008-12-19 16:57:01 +0100785 rct->max_res_size = hdr->max_res_size;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200786 rct->len = min((int)ct->resp->length - (int)sizeof(struct ct_hdr),
Christof Schmittd94ce6c2008-11-04 16:35:12 +0100787 ZFCP_DBF_SAN_MAX_PAYLOAD);
788 debug_event(adapter->san_dbf, level, r, sizeof(*r));
789 zfcp_dbf_hexdump(adapter->san_dbf, r, sizeof(*r), level,
790 (void *)hdr + sizeof(struct ct_hdr), rct->len);
Martin Peschke6bc473d2008-03-31 11:15:29 +0200791 spin_unlock_irqrestore(&adapter->san_dbf_lock, flags);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200792}
793
Martin Peschke92c7a832008-03-31 11:15:30 +0200794static void zfcp_san_dbf_event_els(const char *tag, int level,
795 struct zfcp_fsf_req *fsf_req, u32 s_id,
796 u32 d_id, u8 ls_code, void *buffer,
797 int buflen)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200798{
799 struct zfcp_adapter *adapter = fsf_req->adapter;
800 struct zfcp_san_dbf_record *rec = &adapter->san_dbf_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200801 unsigned long flags;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200802
803 spin_lock_irqsave(&adapter->san_dbf_lock, flags);
Martin Peschke6bc473d2008-03-31 11:15:29 +0200804 memset(rec, 0, sizeof(*rec));
Martin Peschke0f65e952008-03-27 14:21:56 +0100805 strncpy(rec->tag, tag, ZFCP_DBF_TAG_SIZE);
806 rec->fsf_reqid = (unsigned long)fsf_req;
807 rec->fsf_seqno = fsf_req->seq_no;
808 rec->s_id = s_id;
809 rec->d_id = d_id;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200810 rec->u.els.ls_code = ls_code;
Martin Peschke0f65e952008-03-27 14:21:56 +0100811 debug_event(adapter->san_dbf, level, rec, sizeof(*rec));
812 zfcp_dbf_hexdump(adapter->san_dbf, rec, sizeof(*rec), level,
Christof Schmittd94ce6c2008-11-04 16:35:12 +0100813 buffer, min(buflen, ZFCP_DBF_SAN_MAX_PAYLOAD));
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200814 spin_unlock_irqrestore(&adapter->san_dbf_lock, flags);
815}
816
Martin Peschkebfab1632008-03-31 11:15:31 +0200817/**
818 * zfcp_san_dbf_event_els_request - trace event for issued ELS
819 * @fsf_req: request containing issued ELS
820 */
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100821void zfcp_san_dbf_event_els_request(struct zfcp_fsf_req *fsf_req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200822{
823 struct zfcp_send_els *els = (struct zfcp_send_els *)fsf_req->data;
824
Martin Peschke92c7a832008-03-31 11:15:30 +0200825 zfcp_san_dbf_event_els("oels", 2, fsf_req,
826 fc_host_port_id(els->adapter->scsi_host),
Swen Schillig44cc76f2008-10-01 12:42:16 +0200827 els->d_id, *(u8 *) sg_virt(els->req),
828 sg_virt(els->req), els->req->length);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200829}
830
Martin Peschkebfab1632008-03-31 11:15:31 +0200831/**
832 * zfcp_san_dbf_event_els_response - trace event for completed ELS
833 * @fsf_req: request containing ELS response
834 */
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100835void zfcp_san_dbf_event_els_response(struct zfcp_fsf_req *fsf_req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200836{
837 struct zfcp_send_els *els = (struct zfcp_send_els *)fsf_req->data;
838
Martin Peschke92c7a832008-03-31 11:15:30 +0200839 zfcp_san_dbf_event_els("rels", 2, fsf_req, els->d_id,
840 fc_host_port_id(els->adapter->scsi_host),
Swen Schillig44cc76f2008-10-01 12:42:16 +0200841 *(u8 *)sg_virt(els->req), sg_virt(els->resp),
Martin Peschke92c7a832008-03-31 11:15:30 +0200842 els->resp->length);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200843}
844
Martin Peschkebfab1632008-03-31 11:15:31 +0200845/**
846 * zfcp_san_dbf_event_incoming_els - trace event for incomig ELS
847 * @fsf_req: request containing unsolicited status buffer with incoming ELS
848 */
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100849void zfcp_san_dbf_event_incoming_els(struct zfcp_fsf_req *fsf_req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200850{
851 struct zfcp_adapter *adapter = fsf_req->adapter;
Martin Peschke92c7a832008-03-31 11:15:30 +0200852 struct fsf_status_read_buffer *buf =
853 (struct fsf_status_read_buffer *)fsf_req->data;
854 int length = (int)buf->length -
855 (int)((void *)&buf->payload - (void *)buf);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200856
Martin Peschke92c7a832008-03-31 11:15:30 +0200857 zfcp_san_dbf_event_els("iels", 1, fsf_req, buf->d_id,
858 fc_host_port_id(adapter->scsi_host),
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200859 buf->payload.data[0], (void *)buf->payload.data,
Martin Peschke92c7a832008-03-31 11:15:30 +0200860 length);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200861}
862
Martin Peschke92c7a832008-03-31 11:15:30 +0200863static int zfcp_san_dbf_view_format(debug_info_t *id, struct debug_view *view,
864 char *out_buf, const char *in_buf)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200865{
Martin Peschkeb634fff2008-03-31 11:15:24 +0200866 struct zfcp_san_dbf_record *r = (struct zfcp_san_dbf_record *)in_buf;
Martin Peschkeb634fff2008-03-31 11:15:24 +0200867 char *p = out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200868
Martin Peschkeb634fff2008-03-31 11:15:24 +0200869 if (strncmp(r->tag, "dump", ZFCP_DBF_TAG_SIZE) == 0)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200870 return 0;
871
Martin Peschkea9c85772008-03-31 11:15:27 +0200872 zfcp_dbf_tag(&p, "tag", r->tag);
Martin Peschkeb634fff2008-03-31 11:15:24 +0200873 zfcp_dbf_out(&p, "fsf_reqid", "0x%0Lx", r->fsf_reqid);
874 zfcp_dbf_out(&p, "fsf_seqno", "0x%08x", r->fsf_seqno);
875 zfcp_dbf_out(&p, "s_id", "0x%06x", r->s_id);
876 zfcp_dbf_out(&p, "d_id", "0x%06x", r->d_id);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200877
Martin Peschkeb634fff2008-03-31 11:15:24 +0200878 if (strncmp(r->tag, "octc", ZFCP_DBF_TAG_SIZE) == 0) {
Martin Peschke6bc473d2008-03-31 11:15:29 +0200879 struct zfcp_san_dbf_record_ct_request *ct = &r->u.ct_req;
880 zfcp_dbf_out(&p, "cmd_req_code", "0x%04x", ct->cmd_req_code);
881 zfcp_dbf_out(&p, "revision", "0x%02x", ct->revision);
882 zfcp_dbf_out(&p, "gs_type", "0x%02x", ct->gs_type);
883 zfcp_dbf_out(&p, "gs_subtype", "0x%02x", ct->gs_subtype);
884 zfcp_dbf_out(&p, "options", "0x%02x", ct->options);
885 zfcp_dbf_out(&p, "max_res_size", "0x%04x", ct->max_res_size);
Martin Peschkeb634fff2008-03-31 11:15:24 +0200886 } else if (strncmp(r->tag, "rctc", ZFCP_DBF_TAG_SIZE) == 0) {
Martin Peschke6bc473d2008-03-31 11:15:29 +0200887 struct zfcp_san_dbf_record_ct_response *ct = &r->u.ct_resp;
888 zfcp_dbf_out(&p, "cmd_rsp_code", "0x%04x", ct->cmd_rsp_code);
889 zfcp_dbf_out(&p, "revision", "0x%02x", ct->revision);
890 zfcp_dbf_out(&p, "reason_code", "0x%02x", ct->reason_code);
891 zfcp_dbf_out(&p, "reason_code_expl", "0x%02x", ct->expl);
892 zfcp_dbf_out(&p, "vendor_unique", "0x%02x", ct->vendor_unique);
Christof Schmitt39eb7e9a2008-12-19 16:57:01 +0100893 zfcp_dbf_out(&p, "max_res_size", "0x%04x", ct->max_res_size);
Martin Peschkeb634fff2008-03-31 11:15:24 +0200894 } else if (strncmp(r->tag, "oels", ZFCP_DBF_TAG_SIZE) == 0 ||
895 strncmp(r->tag, "rels", ZFCP_DBF_TAG_SIZE) == 0 ||
896 strncmp(r->tag, "iels", ZFCP_DBF_TAG_SIZE) == 0) {
Martin Peschke6bc473d2008-03-31 11:15:29 +0200897 struct zfcp_san_dbf_record_els *els = &r->u.els;
898 zfcp_dbf_out(&p, "ls_code", "0x%02x", els->ls_code);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200899 }
Martin Peschkeb634fff2008-03-31 11:15:24 +0200900 return p - out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200901}
902
Heiko Carstens2b67fc42007-02-05 21:16:47 +0100903static struct debug_view zfcp_san_dbf_view = {
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200904 "structured",
905 NULL,
906 &zfcp_dbf_view_header,
907 &zfcp_san_dbf_view_format,
908 NULL,
909 NULL
910};
911
Martin Peschke92c7a832008-03-31 11:15:30 +0200912static void zfcp_scsi_dbf_event(const char *tag, const char *tag2, int level,
913 struct zfcp_adapter *adapter,
914 struct scsi_cmnd *scsi_cmnd,
915 struct zfcp_fsf_req *fsf_req,
916 unsigned long old_req_id)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200917{
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200918 struct zfcp_scsi_dbf_record *rec = &adapter->scsi_dbf_buf;
919 struct zfcp_dbf_dump *dump = (struct zfcp_dbf_dump *)rec;
920 unsigned long flags;
921 struct fcp_rsp_iu *fcp_rsp;
922 char *fcp_rsp_info = NULL, *fcp_sns_info = NULL;
923 int offset = 0, buflen = 0;
924
925 spin_lock_irqsave(&adapter->scsi_dbf_lock, flags);
926 do {
Martin Peschke6bc473d2008-03-31 11:15:29 +0200927 memset(rec, 0, sizeof(*rec));
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200928 if (offset == 0) {
929 strncpy(rec->tag, tag, ZFCP_DBF_TAG_SIZE);
930 strncpy(rec->tag2, tag2, ZFCP_DBF_TAG_SIZE);
Maxim Shchetynined829ad2006-02-11 01:42:58 +0100931 if (scsi_cmnd != NULL) {
932 if (scsi_cmnd->device) {
933 rec->scsi_id = scsi_cmnd->device->id;
934 rec->scsi_lun = scsi_cmnd->device->lun;
935 }
936 rec->scsi_result = scsi_cmnd->result;
937 rec->scsi_cmnd = (unsigned long)scsi_cmnd;
938 rec->scsi_serial = scsi_cmnd->serial_number;
Boaz Harrosh64a87b22008-04-30 11:19:47 +0300939 memcpy(rec->scsi_opcode, scsi_cmnd->cmnd,
Maxim Shchetynined829ad2006-02-11 01:42:58 +0100940 min((int)scsi_cmnd->cmd_len,
941 ZFCP_DBF_SCSI_OPCODE));
942 rec->scsi_retries = scsi_cmnd->retries;
943 rec->scsi_allowed = scsi_cmnd->allowed;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200944 }
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200945 if (fsf_req != NULL) {
946 fcp_rsp = (struct fcp_rsp_iu *)
947 &(fsf_req->qtcb->bottom.io.fcp_rsp);
Martin Petermannf76af7d72008-07-02 10:56:36 +0200948 fcp_rsp_info = (unsigned char *) &fcp_rsp[1];
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200949 fcp_sns_info =
950 zfcp_get_fcp_sns_info_ptr(fcp_rsp);
951
Martin Peschke6bc473d2008-03-31 11:15:29 +0200952 rec->rsp_validity = fcp_rsp->validity.value;
953 rec->rsp_scsi_status = fcp_rsp->scsi_status;
954 rec->rsp_resid = fcp_rsp->fcp_resid;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200955 if (fcp_rsp->validity.bits.fcp_rsp_len_valid)
Martin Peschke6bc473d2008-03-31 11:15:29 +0200956 rec->rsp_code = *(fcp_rsp_info + 3);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200957 if (fcp_rsp->validity.bits.fcp_sns_len_valid) {
958 buflen = min((int)fcp_rsp->fcp_sns_len,
959 ZFCP_DBF_SCSI_MAX_FCP_SNS_INFO);
Martin Peschke6bc473d2008-03-31 11:15:29 +0200960 rec->sns_info_len = buflen;
961 memcpy(rec->sns_info, fcp_sns_info,
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200962 min(buflen,
963 ZFCP_DBF_SCSI_FCP_SNS_INFO));
964 offset += min(buflen,
965 ZFCP_DBF_SCSI_FCP_SNS_INFO);
966 }
967
968 rec->fsf_reqid = (unsigned long)fsf_req;
969 rec->fsf_seqno = fsf_req->seq_no;
970 rec->fsf_issued = fsf_req->issued;
971 }
Martin Peschke6bc473d2008-03-31 11:15:29 +0200972 rec->old_fsf_reqid = old_req_id;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200973 } else {
974 strncpy(dump->tag, "dump", ZFCP_DBF_TAG_SIZE);
975 dump->total_size = buflen;
976 dump->offset = offset;
977 dump->size = min(buflen - offset,
978 (int)sizeof(struct
979 zfcp_scsi_dbf_record) -
980 (int)sizeof(struct zfcp_dbf_dump));
981 memcpy(dump->data, fcp_sns_info + offset, dump->size);
982 offset += dump->size;
983 }
Martin Peschke6bc473d2008-03-31 11:15:29 +0200984 debug_event(adapter->scsi_dbf, level, rec, sizeof(*rec));
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200985 } while (offset < buflen);
986 spin_unlock_irqrestore(&adapter->scsi_dbf_lock, flags);
987}
988
Martin Peschkebfab1632008-03-31 11:15:31 +0200989/**
990 * zfcp_scsi_dbf_event_result - trace event for SCSI command completion
991 * @tag: tag indicating success or failure of SCSI command
992 * @level: trace level applicable for this event
993 * @adapter: adapter that has been used to issue the SCSI command
994 * @scsi_cmnd: SCSI command pointer
995 * @fsf_req: request used to issue SCSI command (might be NULL)
996 */
Martin Peschke92c7a832008-03-31 11:15:30 +0200997void zfcp_scsi_dbf_event_result(const char *tag, int level,
998 struct zfcp_adapter *adapter,
999 struct scsi_cmnd *scsi_cmnd,
1000 struct zfcp_fsf_req *fsf_req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001001{
Martin Peschke92c7a832008-03-31 11:15:30 +02001002 zfcp_scsi_dbf_event("rslt", tag, level, adapter, scsi_cmnd, fsf_req, 0);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001003}
1004
Martin Peschkebfab1632008-03-31 11:15:31 +02001005/**
1006 * zfcp_scsi_dbf_event_abort - trace event for SCSI command abort
1007 * @tag: tag indicating success or failure of abort operation
1008 * @adapter: adapter thas has been used to issue SCSI command to be aborted
1009 * @scsi_cmnd: SCSI command to be aborted
1010 * @new_fsf_req: request containing abort (might be NULL)
1011 * @old_req_id: identifier of request containg SCSI command to be aborted
1012 */
Martin Peschke92c7a832008-03-31 11:15:30 +02001013void zfcp_scsi_dbf_event_abort(const char *tag, struct zfcp_adapter *adapter,
1014 struct scsi_cmnd *scsi_cmnd,
1015 struct zfcp_fsf_req *new_fsf_req,
1016 unsigned long old_req_id)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001017{
Martin Peschke92c7a832008-03-31 11:15:30 +02001018 zfcp_scsi_dbf_event("abrt", tag, 1, adapter, scsi_cmnd, new_fsf_req,
1019 old_req_id);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001020}
1021
Martin Peschkebfab1632008-03-31 11:15:31 +02001022/**
1023 * zfcp_scsi_dbf_event_devreset - trace event for Logical Unit or Target Reset
1024 * @tag: tag indicating success or failure of reset operation
1025 * @flag: indicates type of reset (Target Reset, Logical Unit Reset)
1026 * @unit: unit that needs reset
1027 * @scsi_cmnd: SCSI command which caused this error recovery
1028 */
Martin Peschke92c7a832008-03-31 11:15:30 +02001029void zfcp_scsi_dbf_event_devreset(const char *tag, u8 flag,
1030 struct zfcp_unit *unit,
1031 struct scsi_cmnd *scsi_cmnd)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001032{
Martin Peschke92c7a832008-03-31 11:15:30 +02001033 zfcp_scsi_dbf_event(flag == FCP_TARGET_RESET ? "trst" : "lrst", tag, 1,
1034 unit->port->adapter, scsi_cmnd, NULL, 0);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001035}
1036
Martin Peschke92c7a832008-03-31 11:15:30 +02001037static int zfcp_scsi_dbf_view_format(debug_info_t *id, struct debug_view *view,
1038 char *out_buf, const char *in_buf)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001039{
Martin Peschkeb634fff2008-03-31 11:15:24 +02001040 struct zfcp_scsi_dbf_record *r = (struct zfcp_scsi_dbf_record *)in_buf;
Martin Peschke8fc5af12008-03-31 11:15:23 +02001041 struct timespec t;
Martin Peschkeb634fff2008-03-31 11:15:24 +02001042 char *p = out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001043
Martin Peschkeb634fff2008-03-31 11:15:24 +02001044 if (strncmp(r->tag, "dump", ZFCP_DBF_TAG_SIZE) == 0)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001045 return 0;
1046
Martin Peschkea9c85772008-03-31 11:15:27 +02001047 zfcp_dbf_tag(&p, "tag", r->tag);
1048 zfcp_dbf_tag(&p, "tag2", r->tag2);
Martin Peschkeb634fff2008-03-31 11:15:24 +02001049 zfcp_dbf_out(&p, "scsi_id", "0x%08x", r->scsi_id);
1050 zfcp_dbf_out(&p, "scsi_lun", "0x%08x", r->scsi_lun);
1051 zfcp_dbf_out(&p, "scsi_result", "0x%08x", r->scsi_result);
1052 zfcp_dbf_out(&p, "scsi_cmnd", "0x%0Lx", r->scsi_cmnd);
1053 zfcp_dbf_out(&p, "scsi_serial", "0x%016Lx", r->scsi_serial);
Martin Peschkedf29f4a2008-03-31 11:15:26 +02001054 zfcp_dbf_outd(&p, "scsi_opcode", r->scsi_opcode, ZFCP_DBF_SCSI_OPCODE,
1055 0, ZFCP_DBF_SCSI_OPCODE);
Martin Peschkeb634fff2008-03-31 11:15:24 +02001056 zfcp_dbf_out(&p, "scsi_retries", "0x%02x", r->scsi_retries);
1057 zfcp_dbf_out(&p, "scsi_allowed", "0x%02x", r->scsi_allowed);
1058 if (strncmp(r->tag, "abrt", ZFCP_DBF_TAG_SIZE) == 0)
Martin Peschke6bc473d2008-03-31 11:15:29 +02001059 zfcp_dbf_out(&p, "old_fsf_reqid", "0x%0Lx", r->old_fsf_reqid);
Martin Peschkeb634fff2008-03-31 11:15:24 +02001060 zfcp_dbf_out(&p, "fsf_reqid", "0x%0Lx", r->fsf_reqid);
1061 zfcp_dbf_out(&p, "fsf_seqno", "0x%08x", r->fsf_seqno);
1062 zfcp_dbf_timestamp(r->fsf_issued, &t);
1063 zfcp_dbf_out(&p, "fsf_issued", "%011lu:%06lu", t.tv_sec, t.tv_nsec);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001064
Martin Peschkeb634fff2008-03-31 11:15:24 +02001065 if (strncmp(r->tag, "rslt", ZFCP_DBF_TAG_SIZE) == 0) {
Martin Peschke6bc473d2008-03-31 11:15:29 +02001066 zfcp_dbf_out(&p, "fcp_rsp_validity", "0x%02x", r->rsp_validity);
1067 zfcp_dbf_out(&p, "fcp_rsp_scsi_status", "0x%02x",
1068 r->rsp_scsi_status);
1069 zfcp_dbf_out(&p, "fcp_rsp_resid", "0x%08x", r->rsp_resid);
1070 zfcp_dbf_out(&p, "fcp_rsp_code", "0x%08x", r->rsp_code);
1071 zfcp_dbf_out(&p, "fcp_sns_info_len", "0x%08x", r->sns_info_len);
1072 zfcp_dbf_outd(&p, "fcp_sns_info", r->sns_info,
1073 min((int)r->sns_info_len,
Martin Peschkedf29f4a2008-03-31 11:15:26 +02001074 ZFCP_DBF_SCSI_FCP_SNS_INFO), 0,
Martin Peschke6bc473d2008-03-31 11:15:29 +02001075 r->sns_info_len);
Martin Peschkeb634fff2008-03-31 11:15:24 +02001076 }
1077 p += sprintf(p, "\n");
1078 return p - out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001079}
1080
Heiko Carstens2b67fc42007-02-05 21:16:47 +01001081static struct debug_view zfcp_scsi_dbf_view = {
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001082 "structured",
1083 NULL,
1084 &zfcp_dbf_view_header,
1085 &zfcp_scsi_dbf_view_format,
1086 NULL,
1087 NULL
1088};
1089
1090/**
1091 * zfcp_adapter_debug_register - registers debug feature for an adapter
1092 * @adapter: pointer to adapter for which debug features should be registered
1093 * return: -ENOMEM on error, 0 otherwise
1094 */
1095int zfcp_adapter_debug_register(struct zfcp_adapter *adapter)
1096{
1097 char dbf_name[DEBUG_MAX_NAME_LEN];
1098
1099 /* debug feature area which records recovery activity */
Christof Schmittb225cf92008-12-19 16:57:00 +01001100 sprintf(dbf_name, "zfcp_%s_rec", dev_name(&adapter->ccw_device->dev));
Martin Peschked79a83d2008-03-27 14:22:00 +01001101 adapter->rec_dbf = debug_register(dbf_name, dbfsize, 1,
1102 sizeof(struct zfcp_rec_dbf_record));
1103 if (!adapter->rec_dbf)
1104 goto failed;
1105 debug_register_view(adapter->rec_dbf, &debug_hex_ascii_view);
1106 debug_register_view(adapter->rec_dbf, &zfcp_rec_dbf_view);
1107 debug_set_level(adapter->rec_dbf, 3);
1108
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001109 /* debug feature area which records HBA (FSF and QDIO) conditions */
Christof Schmittb225cf92008-12-19 16:57:00 +01001110 sprintf(dbf_name, "zfcp_%s_hba", dev_name(&adapter->ccw_device->dev));
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001111 adapter->hba_dbf = debug_register(dbf_name, dbfsize, 1,
1112 sizeof(struct zfcp_hba_dbf_record));
1113 if (!adapter->hba_dbf)
1114 goto failed;
1115 debug_register_view(adapter->hba_dbf, &debug_hex_ascii_view);
1116 debug_register_view(adapter->hba_dbf, &zfcp_hba_dbf_view);
1117 debug_set_level(adapter->hba_dbf, 3);
1118
1119 /* debug feature area which records SAN command failures and recovery */
Christof Schmittb225cf92008-12-19 16:57:00 +01001120 sprintf(dbf_name, "zfcp_%s_san", dev_name(&adapter->ccw_device->dev));
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001121 adapter->san_dbf = debug_register(dbf_name, dbfsize, 1,
1122 sizeof(struct zfcp_san_dbf_record));
1123 if (!adapter->san_dbf)
1124 goto failed;
1125 debug_register_view(adapter->san_dbf, &debug_hex_ascii_view);
1126 debug_register_view(adapter->san_dbf, &zfcp_san_dbf_view);
1127 debug_set_level(adapter->san_dbf, 6);
1128
1129 /* debug feature area which records SCSI command failures and recovery */
Christof Schmittb225cf92008-12-19 16:57:00 +01001130 sprintf(dbf_name, "zfcp_%s_scsi", dev_name(&adapter->ccw_device->dev));
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001131 adapter->scsi_dbf = debug_register(dbf_name, dbfsize, 1,
1132 sizeof(struct zfcp_scsi_dbf_record));
1133 if (!adapter->scsi_dbf)
1134 goto failed;
1135 debug_register_view(adapter->scsi_dbf, &debug_hex_ascii_view);
1136 debug_register_view(adapter->scsi_dbf, &zfcp_scsi_dbf_view);
1137 debug_set_level(adapter->scsi_dbf, 3);
1138
1139 return 0;
1140
1141 failed:
1142 zfcp_adapter_debug_unregister(adapter);
1143
1144 return -ENOMEM;
1145}
1146
1147/**
1148 * zfcp_adapter_debug_unregister - unregisters debug feature for an adapter
1149 * @adapter: pointer to adapter for which debug features should be unregistered
1150 */
1151void zfcp_adapter_debug_unregister(struct zfcp_adapter *adapter)
1152{
1153 debug_unregister(adapter->scsi_dbf);
1154 debug_unregister(adapter->san_dbf);
1155 debug_unregister(adapter->hba_dbf);
Martin Peschked79a83d2008-03-27 14:22:00 +01001156 debug_unregister(adapter->rec_dbf);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001157 adapter->scsi_dbf = NULL;
1158 adapter->san_dbf = NULL;
1159 adapter->hba_dbf = NULL;
Martin Peschked79a83d2008-03-27 14:22:00 +01001160 adapter->rec_dbf = NULL;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001161}