blob: 31012d58cfb760fb457862bfd596da12f8532310 [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
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02009#include <linux/ctype.h>
Heiko Carstens364c8552007-10-12 16:11:35 +020010#include <asm/debug.h>
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020011#include "zfcp_ext.h"
12
13static u32 dbfsize = 4;
14
15module_param(dbfsize, uint, 0400);
16MODULE_PARM_DESC(dbfsize,
17 "number of pages for each debug feature area (default 4)");
18
Martin Peschkec15450e2008-03-27 14:21:55 +010019static void zfcp_dbf_hexdump(debug_info_t *dbf, void *to, int to_len,
20 int level, char *from, int from_len)
21{
22 int offset;
23 struct zfcp_dbf_dump *dump = to;
24 int room = to_len - sizeof(*dump);
25
26 for (offset = 0; offset < from_len; offset += dump->size) {
27 memset(to, 0, to_len);
28 strncpy(dump->tag, "dump", ZFCP_DBF_TAG_SIZE);
29 dump->total_size = from_len;
30 dump->offset = offset;
31 dump->size = min(from_len - offset, room);
32 memcpy(dump->data, from + offset, dump->size);
Christof Schmittd94ce6c2008-11-04 16:35:12 +010033 debug_event(dbf, level, dump, dump->size + sizeof(*dump));
Martin Peschkec15450e2008-03-27 14:21:55 +010034 }
35}
36
Martin Peschke8fc5af12008-03-31 11:15:23 +020037/* FIXME: this duplicate this code in s390 debug feature */
38static void zfcp_dbf_timestamp(unsigned long long stck, struct timespec *time)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020039{
40 unsigned long long sec;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020041
42 stck -= 0x8126d60e46000000LL - (0x3c26700LL * 1000000 * 4096);
43 sec = stck >> 12;
44 do_div(sec, 1000000);
Martin Peschke8fc5af12008-03-31 11:15:23 +020045 time->tv_sec = sec;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020046 stck -= (sec * 1000000) << 12;
Martin Peschke8fc5af12008-03-31 11:15:23 +020047 time->tv_nsec = ((stck * 1000) >> 12);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020048}
49
Martin Peschkea9c85772008-03-31 11:15:27 +020050static void zfcp_dbf_tag(char **p, const char *label, const char *tag)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020051{
Martin Peschkea9c85772008-03-31 11:15:27 +020052 int i;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020053
Martin Peschkea9c85772008-03-31 11:15:27 +020054 *p += sprintf(*p, "%-24s", label);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020055 for (i = 0; i < ZFCP_DBF_TAG_SIZE; i++)
Martin Peschkea9c85772008-03-31 11:15:27 +020056 *p += sprintf(*p, "%c", tag[i]);
57 *p += sprintf(*p, "\n");
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020058}
59
Martin Peschke10223c62008-03-27 14:21:59 +010060static void zfcp_dbf_outs(char **buf, const char *s1, const char *s2)
61{
62 *buf += sprintf(*buf, "%-24s%s\n", s1, s2);
63}
64
65static void zfcp_dbf_out(char **buf, const char *s, const char *format, ...)
66{
67 va_list arg;
68
69 *buf += sprintf(*buf, "%-24s", s);
70 va_start(arg, format);
71 *buf += vsprintf(*buf, format, arg);
72 va_end(arg);
73 *buf += sprintf(*buf, "\n");
74}
75
Martin Peschkedf29f4a2008-03-31 11:15:26 +020076static void zfcp_dbf_outd(char **p, const char *label, char *buffer,
77 int buflen, int offset, int total_size)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020078{
Martin Peschkedf29f4a2008-03-31 11:15:26 +020079 if (!offset)
80 *p += sprintf(*p, "%-24s ", label);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020081 while (buflen--) {
82 if (offset > 0) {
83 if ((offset % 32) == 0)
Martin Peschkedf29f4a2008-03-31 11:15:26 +020084 *p += sprintf(*p, "\n%-24c ", ' ');
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020085 else if ((offset % 4) == 0)
Martin Peschkedf29f4a2008-03-31 11:15:26 +020086 *p += sprintf(*p, " ");
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020087 }
Martin Peschkedf29f4a2008-03-31 11:15:26 +020088 *p += sprintf(*p, "%02x", *buffer++);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020089 if (++offset == total_size) {
Martin Peschkedf29f4a2008-03-31 11:15:26 +020090 *p += sprintf(*p, "\n");
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020091 break;
92 }
93 }
Martin Peschkedf29f4a2008-03-31 11:15:26 +020094 if (!total_size)
95 *p += sprintf(*p, "\n");
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020096}
97
Martin Peschke92c7a832008-03-31 11:15:30 +020098static int zfcp_dbf_view_header(debug_info_t *id, struct debug_view *view,
99 int area, debug_entry_t *entry, char *out_buf)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200100{
101 struct zfcp_dbf_dump *dump = (struct zfcp_dbf_dump *)DEBUG_DATA(entry);
Martin Peschke8fc5af12008-03-31 11:15:23 +0200102 struct timespec t;
Martin Peschkeb634fff2008-03-31 11:15:24 +0200103 char *p = out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200104
105 if (strncmp(dump->tag, "dump", ZFCP_DBF_TAG_SIZE) != 0) {
Martin Peschke8fc5af12008-03-31 11:15:23 +0200106 zfcp_dbf_timestamp(entry->id.stck, &t);
Martin Peschkeb634fff2008-03-31 11:15:24 +0200107 zfcp_dbf_out(&p, "timestamp", "%011lu:%06lu",
108 t.tv_sec, t.tv_nsec);
109 zfcp_dbf_out(&p, "cpu", "%02i", entry->id.fields.cpuid);
110 } else {
Christof Schmittd94ce6c2008-11-04 16:35:12 +0100111 zfcp_dbf_outd(&p, "", dump->data, dump->size, dump->offset,
Martin Peschkedf29f4a2008-03-31 11:15:26 +0200112 dump->total_size);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200113 if ((dump->offset + dump->size) == dump->total_size)
Martin Peschkeb634fff2008-03-31 11:15:24 +0200114 p += sprintf(p, "\n");
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200115 }
Martin Peschkeb634fff2008-03-31 11:15:24 +0200116 return p - out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200117}
118
Martin Peschkebfab1632008-03-31 11:15:31 +0200119/**
120 * zfcp_hba_dbf_event_fsf_response - trace event for request completion
121 * @fsf_req: request that has been completed
122 */
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100123void zfcp_hba_dbf_event_fsf_response(struct zfcp_fsf_req *fsf_req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200124{
125 struct zfcp_adapter *adapter = fsf_req->adapter;
126 struct fsf_qtcb *qtcb = fsf_req->qtcb;
127 union fsf_prot_status_qual *prot_status_qual =
Martin Peschke92c7a832008-03-31 11:15:30 +0200128 &qtcb->prefix.prot_status_qual;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200129 union fsf_status_qual *fsf_status_qual = &qtcb->header.fsf_status_qual;
130 struct scsi_cmnd *scsi_cmnd;
131 struct zfcp_port *port;
132 struct zfcp_unit *unit;
133 struct zfcp_send_els *send_els;
134 struct zfcp_hba_dbf_record *rec = &adapter->hba_dbf_buf;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200135 struct zfcp_hba_dbf_record_response *response = &rec->u.response;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200136 int level;
137 unsigned long flags;
138
139 spin_lock_irqsave(&adapter->hba_dbf_lock, flags);
Martin Peschke6bc473d2008-03-31 11:15:29 +0200140 memset(rec, 0, sizeof(*rec));
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200141 strncpy(rec->tag, "resp", ZFCP_DBF_TAG_SIZE);
142
143 if ((qtcb->prefix.prot_status != FSF_PROT_GOOD) &&
144 (qtcb->prefix.prot_status != FSF_PROT_FSF_STATUS_PRESENTED)) {
145 strncpy(rec->tag2, "perr", ZFCP_DBF_TAG_SIZE);
146 level = 1;
147 } else if (qtcb->header.fsf_status != FSF_GOOD) {
148 strncpy(rec->tag2, "ferr", ZFCP_DBF_TAG_SIZE);
149 level = 1;
150 } else if ((fsf_req->fsf_command == FSF_QTCB_OPEN_PORT_WITH_DID) ||
151 (fsf_req->fsf_command == FSF_QTCB_OPEN_LUN)) {
152 strncpy(rec->tag2, "open", ZFCP_DBF_TAG_SIZE);
153 level = 4;
Martin Peschkeb75db732008-03-27 14:21:58 +0100154 } else if (qtcb->header.log_length) {
155 strncpy(rec->tag2, "qtcb", ZFCP_DBF_TAG_SIZE);
156 level = 5;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200157 } else {
158 strncpy(rec->tag2, "norm", ZFCP_DBF_TAG_SIZE);
159 level = 6;
160 }
161
162 response->fsf_command = fsf_req->fsf_command;
163 response->fsf_reqid = (unsigned long)fsf_req;
164 response->fsf_seqno = fsf_req->seq_no;
165 response->fsf_issued = fsf_req->issued;
166 response->fsf_prot_status = qtcb->prefix.prot_status;
167 response->fsf_status = qtcb->header.fsf_status;
168 memcpy(response->fsf_prot_status_qual,
169 prot_status_qual, FSF_PROT_STATUS_QUAL_SIZE);
170 memcpy(response->fsf_status_qual,
171 fsf_status_qual, FSF_STATUS_QUALIFIER_SIZE);
172 response->fsf_req_status = fsf_req->status;
173 response->sbal_first = fsf_req->sbal_first;
Martin Peschkee891bff2008-05-19 12:17:43 +0200174 response->sbal_last = fsf_req->sbal_last;
Martin Peschkec3baa9a22008-05-19 12:17:44 +0200175 response->sbal_response = fsf_req->sbal_response;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200176 response->pool = fsf_req->pool != NULL;
177 response->erp_action = (unsigned long)fsf_req->erp_action;
178
179 switch (fsf_req->fsf_command) {
180 case FSF_QTCB_FCP_CMND:
181 if (fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT)
182 break;
183 scsi_cmnd = (struct scsi_cmnd *)fsf_req->data;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200184 if (scsi_cmnd) {
185 response->u.fcp.cmnd = (unsigned long)scsi_cmnd;
186 response->u.fcp.serial = scsi_cmnd->serial_number;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200187 }
188 break;
189
190 case FSF_QTCB_OPEN_PORT_WITH_DID:
191 case FSF_QTCB_CLOSE_PORT:
192 case FSF_QTCB_CLOSE_PHYSICAL_PORT:
193 port = (struct zfcp_port *)fsf_req->data;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200194 response->u.port.wwpn = port->wwpn;
195 response->u.port.d_id = port->d_id;
196 response->u.port.port_handle = qtcb->header.port_handle;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200197 break;
198
199 case FSF_QTCB_OPEN_LUN:
200 case FSF_QTCB_CLOSE_LUN:
201 unit = (struct zfcp_unit *)fsf_req->data;
202 port = unit->port;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200203 response->u.unit.wwpn = port->wwpn;
204 response->u.unit.fcp_lun = unit->fcp_lun;
205 response->u.unit.port_handle = qtcb->header.port_handle;
206 response->u.unit.lun_handle = qtcb->header.lun_handle;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200207 break;
208
209 case FSF_QTCB_SEND_ELS:
210 send_els = (struct zfcp_send_els *)fsf_req->data;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200211 response->u.els.d_id = qtcb->bottom.support.d_id;
212 response->u.els.ls_code = send_els->ls_code >> 24;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200213 break;
214
215 case FSF_QTCB_ABORT_FCP_CMND:
216 case FSF_QTCB_SEND_GENERIC:
217 case FSF_QTCB_EXCHANGE_CONFIG_DATA:
218 case FSF_QTCB_EXCHANGE_PORT_DATA:
219 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
220 case FSF_QTCB_UPLOAD_CONTROL_FILE:
221 break;
222 }
223
Martin Peschke6bc473d2008-03-31 11:15:29 +0200224 debug_event(adapter->hba_dbf, level, rec, sizeof(*rec));
Martin Peschkeb75db732008-03-27 14:21:58 +0100225
226 /* have fcp channel microcode fixed to use as little as possible */
227 if (fsf_req->fsf_command != FSF_QTCB_FCP_CMND) {
228 /* adjust length skipping trailing zeros */
229 char *buf = (char *)qtcb + qtcb->header.log_start;
230 int len = qtcb->header.log_length;
231 for (; len && !buf[len - 1]; len--);
232 zfcp_dbf_hexdump(adapter->hba_dbf, rec, sizeof(*rec), level,
233 buf, len);
234 }
235
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200236 spin_unlock_irqrestore(&adapter->hba_dbf_lock, flags);
237}
238
Martin Peschkebfab1632008-03-31 11:15:31 +0200239/**
240 * zfcp_hba_dbf_event_fsf_unsol - trace event for an unsolicited status buffer
241 * @tag: tag indicating which kind of unsolicited status has been received
242 * @adapter: adapter that has issued the unsolicited status buffer
243 * @status_buffer: buffer containing payload of unsolicited status
244 */
Martin Peschke92c7a832008-03-31 11:15:30 +0200245void zfcp_hba_dbf_event_fsf_unsol(const char *tag, struct zfcp_adapter *adapter,
246 struct fsf_status_read_buffer *status_buffer)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200247{
248 struct zfcp_hba_dbf_record *rec = &adapter->hba_dbf_buf;
249 unsigned long flags;
250
251 spin_lock_irqsave(&adapter->hba_dbf_lock, flags);
Martin Peschke6bc473d2008-03-31 11:15:29 +0200252 memset(rec, 0, sizeof(*rec));
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200253 strncpy(rec->tag, "stat", ZFCP_DBF_TAG_SIZE);
254 strncpy(rec->tag2, tag, ZFCP_DBF_TAG_SIZE);
255
Swen Schilligd26ab062008-05-19 12:17:37 +0200256 rec->u.status.failed = atomic_read(&adapter->stat_miss);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200257 if (status_buffer != NULL) {
Martin Peschke6bc473d2008-03-31 11:15:29 +0200258 rec->u.status.status_type = status_buffer->status_type;
259 rec->u.status.status_subtype = status_buffer->status_subtype;
260 memcpy(&rec->u.status.queue_designator,
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200261 &status_buffer->queue_designator,
262 sizeof(struct fsf_queue_designator));
263
264 switch (status_buffer->status_type) {
265 case FSF_STATUS_READ_SENSE_DATA_AVAIL:
Martin Peschke6bc473d2008-03-31 11:15:29 +0200266 rec->u.status.payload_size =
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200267 ZFCP_DBF_UNSOL_PAYLOAD_SENSE_DATA_AVAIL;
268 break;
269
270 case FSF_STATUS_READ_BIT_ERROR_THRESHOLD:
Martin Peschke6bc473d2008-03-31 11:15:29 +0200271 rec->u.status.payload_size =
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200272 ZFCP_DBF_UNSOL_PAYLOAD_BIT_ERROR_THRESHOLD;
273 break;
274
275 case FSF_STATUS_READ_LINK_DOWN:
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200276 switch (status_buffer->status_subtype) {
277 case FSF_STATUS_READ_SUB_NO_PHYSICAL_LINK:
278 case FSF_STATUS_READ_SUB_FDISC_FAILED:
Martin Peschke6bc473d2008-03-31 11:15:29 +0200279 rec->u.status.payload_size =
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200280 sizeof(struct fsf_link_down_info);
281 }
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200282 break;
283
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200284 case FSF_STATUS_READ_FEATURE_UPDATE_ALERT:
Martin Peschke6bc473d2008-03-31 11:15:29 +0200285 rec->u.status.payload_size =
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200286 ZFCP_DBF_UNSOL_PAYLOAD_FEATURE_UPDATE_ALERT;
287 break;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200288 }
Martin Peschke6bc473d2008-03-31 11:15:29 +0200289 memcpy(&rec->u.status.payload,
290 &status_buffer->payload, rec->u.status.payload_size);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200291 }
292
Martin Peschke6bc473d2008-03-31 11:15:29 +0200293 debug_event(adapter->hba_dbf, 2, rec, sizeof(*rec));
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200294 spin_unlock_irqrestore(&adapter->hba_dbf_lock, flags);
295}
296
Martin Peschkebfab1632008-03-31 11:15:31 +0200297/**
298 * zfcp_hba_dbf_event_qdio - trace event for QDIO related failure
299 * @adapter: adapter affected by this QDIO related event
Martin Peschkebfab1632008-03-31 11:15:31 +0200300 * @qdio_error: as passed by qdio module
Martin Peschkebfab1632008-03-31 11:15:31 +0200301 * @sbal_index: first buffer with error condition, as passed by qdio module
302 * @sbal_count: number of buffers affected, as passed by qdio module
303 */
Jan Glauber779e6e12008-07-17 17:16:48 +0200304void zfcp_hba_dbf_event_qdio(struct zfcp_adapter *adapter,
305 unsigned int qdio_error, int sbal_index,
306 int sbal_count)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200307{
Martin Peschke6bc473d2008-03-31 11:15:29 +0200308 struct zfcp_hba_dbf_record *r = &adapter->hba_dbf_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200309 unsigned long flags;
310
311 spin_lock_irqsave(&adapter->hba_dbf_lock, flags);
Martin Peschke6bc473d2008-03-31 11:15:29 +0200312 memset(r, 0, sizeof(*r));
313 strncpy(r->tag, "qdio", ZFCP_DBF_TAG_SIZE);
Martin Peschke6bc473d2008-03-31 11:15:29 +0200314 r->u.qdio.qdio_error = qdio_error;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200315 r->u.qdio.sbal_index = sbal_index;
316 r->u.qdio.sbal_count = sbal_count;
317 debug_event(adapter->hba_dbf, 0, r, sizeof(*r));
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200318 spin_unlock_irqrestore(&adapter->hba_dbf_lock, flags);
319}
320
Swen Schillig57069382008-10-01 12:42:21 +0200321/**
322 * zfcp_hba_dbf_event_berr - trace event for bit error threshold
323 * @adapter: adapter affected by this QDIO related event
324 * @req: fsf request
325 */
326void zfcp_hba_dbf_event_berr(struct zfcp_adapter *adapter,
327 struct zfcp_fsf_req *req)
328{
329 struct zfcp_hba_dbf_record *r = &adapter->hba_dbf_buf;
330 struct fsf_status_read_buffer *sr_buf = req->data;
331 struct fsf_bit_error_payload *err = &sr_buf->payload.bit_error;
332 unsigned long flags;
333
334 spin_lock_irqsave(&adapter->hba_dbf_lock, flags);
335 memset(r, 0, sizeof(*r));
336 strncpy(r->tag, "berr", ZFCP_DBF_TAG_SIZE);
337 memcpy(&r->u.berr, err, sizeof(struct fsf_bit_error_payload));
338 debug_event(adapter->hba_dbf, 0, r, sizeof(*r));
339 spin_unlock_irqrestore(&adapter->hba_dbf_lock, flags);
340}
Martin Peschkea9c85772008-03-31 11:15:27 +0200341static void zfcp_hba_dbf_view_response(char **p,
342 struct zfcp_hba_dbf_record_response *r)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200343{
Martin Peschke8fc5af12008-03-31 11:15:23 +0200344 struct timespec t;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200345
Martin Peschkea9c85772008-03-31 11:15:27 +0200346 zfcp_dbf_out(p, "fsf_command", "0x%08x", r->fsf_command);
347 zfcp_dbf_out(p, "fsf_reqid", "0x%0Lx", r->fsf_reqid);
348 zfcp_dbf_out(p, "fsf_seqno", "0x%08x", r->fsf_seqno);
Martin Peschkeb634fff2008-03-31 11:15:24 +0200349 zfcp_dbf_timestamp(r->fsf_issued, &t);
Martin Peschkea9c85772008-03-31 11:15:27 +0200350 zfcp_dbf_out(p, "fsf_issued", "%011lu:%06lu", t.tv_sec, t.tv_nsec);
351 zfcp_dbf_out(p, "fsf_prot_status", "0x%08x", r->fsf_prot_status);
352 zfcp_dbf_out(p, "fsf_status", "0x%08x", r->fsf_status);
353 zfcp_dbf_outd(p, "fsf_prot_status_qual", r->fsf_prot_status_qual,
Martin Peschkedf29f4a2008-03-31 11:15:26 +0200354 FSF_PROT_STATUS_QUAL_SIZE, 0, FSF_PROT_STATUS_QUAL_SIZE);
Martin Peschkea9c85772008-03-31 11:15:27 +0200355 zfcp_dbf_outd(p, "fsf_status_qual", r->fsf_status_qual,
Martin Peschkedf29f4a2008-03-31 11:15:26 +0200356 FSF_STATUS_QUALIFIER_SIZE, 0, FSF_STATUS_QUALIFIER_SIZE);
Martin Peschkea9c85772008-03-31 11:15:27 +0200357 zfcp_dbf_out(p, "fsf_req_status", "0x%08x", r->fsf_req_status);
358 zfcp_dbf_out(p, "sbal_first", "0x%02x", r->sbal_first);
Martin Peschkee891bff2008-05-19 12:17:43 +0200359 zfcp_dbf_out(p, "sbal_last", "0x%02x", r->sbal_last);
Martin Peschkec3baa9a22008-05-19 12:17:44 +0200360 zfcp_dbf_out(p, "sbal_response", "0x%02x", r->sbal_response);
Martin Peschkea9c85772008-03-31 11:15:27 +0200361 zfcp_dbf_out(p, "pool", "0x%02x", r->pool);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200362
Martin Peschkeb634fff2008-03-31 11:15:24 +0200363 switch (r->fsf_command) {
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200364 case FSF_QTCB_FCP_CMND:
Martin Peschkeb634fff2008-03-31 11:15:24 +0200365 if (r->fsf_req_status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200366 break;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200367 zfcp_dbf_out(p, "scsi_cmnd", "0x%0Lx", r->u.fcp.cmnd);
368 zfcp_dbf_out(p, "scsi_serial", "0x%016Lx", r->u.fcp.serial);
Christof Schmittd94ce6c2008-11-04 16:35:12 +0100369 p += sprintf(*p, "\n");
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200370 break;
371
372 case FSF_QTCB_OPEN_PORT_WITH_DID:
373 case FSF_QTCB_CLOSE_PORT:
374 case FSF_QTCB_CLOSE_PHYSICAL_PORT:
Martin Peschke6bc473d2008-03-31 11:15:29 +0200375 zfcp_dbf_out(p, "wwpn", "0x%016Lx", r->u.port.wwpn);
376 zfcp_dbf_out(p, "d_id", "0x%06x", r->u.port.d_id);
377 zfcp_dbf_out(p, "port_handle", "0x%08x", r->u.port.port_handle);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200378 break;
379
380 case FSF_QTCB_OPEN_LUN:
381 case FSF_QTCB_CLOSE_LUN:
Martin Peschke6bc473d2008-03-31 11:15:29 +0200382 zfcp_dbf_out(p, "wwpn", "0x%016Lx", r->u.unit.wwpn);
383 zfcp_dbf_out(p, "fcp_lun", "0x%016Lx", r->u.unit.fcp_lun);
384 zfcp_dbf_out(p, "port_handle", "0x%08x", r->u.unit.port_handle);
385 zfcp_dbf_out(p, "lun_handle", "0x%08x", r->u.unit.lun_handle);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200386 break;
387
388 case FSF_QTCB_SEND_ELS:
Martin Peschke6bc473d2008-03-31 11:15:29 +0200389 zfcp_dbf_out(p, "d_id", "0x%06x", r->u.els.d_id);
390 zfcp_dbf_out(p, "ls_code", "0x%02x", r->u.els.ls_code);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200391 break;
392
393 case FSF_QTCB_ABORT_FCP_CMND:
394 case FSF_QTCB_SEND_GENERIC:
395 case FSF_QTCB_EXCHANGE_CONFIG_DATA:
396 case FSF_QTCB_EXCHANGE_PORT_DATA:
397 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
398 case FSF_QTCB_UPLOAD_CONTROL_FILE:
399 break;
400 }
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200401}
402
Martin Peschkea9c85772008-03-31 11:15:27 +0200403static void zfcp_hba_dbf_view_status(char **p,
404 struct zfcp_hba_dbf_record_status *r)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200405{
Martin Peschkea9c85772008-03-31 11:15:27 +0200406 zfcp_dbf_out(p, "failed", "0x%02x", r->failed);
407 zfcp_dbf_out(p, "status_type", "0x%08x", r->status_type);
408 zfcp_dbf_out(p, "status_subtype", "0x%08x", r->status_subtype);
409 zfcp_dbf_outd(p, "queue_designator", (char *)&r->queue_designator,
Martin Peschkedf29f4a2008-03-31 11:15:26 +0200410 sizeof(struct fsf_queue_designator), 0,
411 sizeof(struct fsf_queue_designator));
Martin Peschkea9c85772008-03-31 11:15:27 +0200412 zfcp_dbf_outd(p, "payload", (char *)&r->payload, r->payload_size, 0,
Martin Peschkedf29f4a2008-03-31 11:15:26 +0200413 r->payload_size);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200414}
415
Martin Peschkea9c85772008-03-31 11:15:27 +0200416static void zfcp_hba_dbf_view_qdio(char **p, struct zfcp_hba_dbf_record_qdio *r)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200417{
Martin Peschkea9c85772008-03-31 11:15:27 +0200418 zfcp_dbf_out(p, "qdio_error", "0x%08x", r->qdio_error);
Martin Peschkea9c85772008-03-31 11:15:27 +0200419 zfcp_dbf_out(p, "sbal_index", "0x%02x", r->sbal_index);
420 zfcp_dbf_out(p, "sbal_count", "0x%02x", r->sbal_count);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200421}
422
Swen Schillig57069382008-10-01 12:42:21 +0200423static void zfcp_hba_dbf_view_berr(char **p, struct fsf_bit_error_payload *r)
424{
425 zfcp_dbf_out(p, "link_failures", "%d", r->link_failure_error_count);
426 zfcp_dbf_out(p, "loss_of_sync_err", "%d", r->loss_of_sync_error_count);
427 zfcp_dbf_out(p, "loss_of_sig_err", "%d", r->loss_of_signal_error_count);
428 zfcp_dbf_out(p, "prim_seq_err", "%d",
429 r->primitive_sequence_error_count);
430 zfcp_dbf_out(p, "inval_trans_word_err", "%d",
431 r->invalid_transmission_word_error_count);
432 zfcp_dbf_out(p, "CRC_errors", "%d", r->crc_error_count);
433 zfcp_dbf_out(p, "prim_seq_event_to", "%d",
434 r->primitive_sequence_event_timeout_count);
435 zfcp_dbf_out(p, "elast_buf_overrun_err", "%d",
436 r->elastic_buffer_overrun_error_count);
437 zfcp_dbf_out(p, "adv_rec_buf2buf_cred", "%d",
438 r->advertised_receive_b2b_credit);
439 zfcp_dbf_out(p, "curr_rec_buf2buf_cred", "%d",
440 r->current_receive_b2b_credit);
441 zfcp_dbf_out(p, "adv_trans_buf2buf_cred", "%d",
442 r->advertised_transmit_b2b_credit);
443 zfcp_dbf_out(p, "curr_trans_buf2buf_cred", "%d",
444 r->current_transmit_b2b_credit);
445}
446
Martin Peschkea9c85772008-03-31 11:15:27 +0200447static int zfcp_hba_dbf_view_format(debug_info_t *id, struct debug_view *view,
448 char *out_buf, const char *in_buf)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200449{
Martin Peschkea9c85772008-03-31 11:15:27 +0200450 struct zfcp_hba_dbf_record *r = (struct zfcp_hba_dbf_record *)in_buf;
451 char *p = out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200452
Martin Peschkea9c85772008-03-31 11:15:27 +0200453 if (strncmp(r->tag, "dump", ZFCP_DBF_TAG_SIZE) == 0)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200454 return 0;
455
Martin Peschkea9c85772008-03-31 11:15:27 +0200456 zfcp_dbf_tag(&p, "tag", r->tag);
457 if (isalpha(r->tag2[0]))
458 zfcp_dbf_tag(&p, "tag2", r->tag2);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200459
Martin Peschkea9c85772008-03-31 11:15:27 +0200460 if (strncmp(r->tag, "resp", ZFCP_DBF_TAG_SIZE) == 0)
Martin Peschke6bc473d2008-03-31 11:15:29 +0200461 zfcp_hba_dbf_view_response(&p, &r->u.response);
Martin Peschkea9c85772008-03-31 11:15:27 +0200462 else if (strncmp(r->tag, "stat", ZFCP_DBF_TAG_SIZE) == 0)
Martin Peschke6bc473d2008-03-31 11:15:29 +0200463 zfcp_hba_dbf_view_status(&p, &r->u.status);
Martin Peschkea9c85772008-03-31 11:15:27 +0200464 else if (strncmp(r->tag, "qdio", ZFCP_DBF_TAG_SIZE) == 0)
Martin Peschke6bc473d2008-03-31 11:15:29 +0200465 zfcp_hba_dbf_view_qdio(&p, &r->u.qdio);
Swen Schillig57069382008-10-01 12:42:21 +0200466 else if (strncmp(r->tag, "berr", ZFCP_DBF_TAG_SIZE) == 0)
467 zfcp_hba_dbf_view_berr(&p, &r->u.berr);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200468
Christof Schmittd94ce6c2008-11-04 16:35:12 +0100469 if (strncmp(r->tag, "resp", ZFCP_DBF_TAG_SIZE) != 0)
470 p += sprintf(p, "\n");
Martin Peschkea9c85772008-03-31 11:15:27 +0200471 return p - out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200472}
473
Heiko Carstens2b67fc42007-02-05 21:16:47 +0100474static struct debug_view zfcp_hba_dbf_view = {
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200475 "structured",
476 NULL,
477 &zfcp_dbf_view_header,
478 &zfcp_hba_dbf_view_format,
479 NULL,
480 NULL
481};
482
Martin Peschked79a83d2008-03-27 14:22:00 +0100483static const char *zfcp_rec_dbf_tags[] = {
Martin Peschke348447e2008-03-27 14:22:01 +0100484 [ZFCP_REC_DBF_ID_THREAD] = "thread",
Martin Peschke698ec0162008-03-27 14:22:02 +0100485 [ZFCP_REC_DBF_ID_TARGET] = "target",
Martin Peschke9467a9b2008-03-27 14:22:03 +0100486 [ZFCP_REC_DBF_ID_TRIGGER] = "trigger",
Martin Peschke6f4f3652008-03-27 14:22:04 +0100487 [ZFCP_REC_DBF_ID_ACTION] = "action",
Martin Peschked79a83d2008-03-27 14:22:00 +0100488};
489
490static const char *zfcp_rec_dbf_ids[] = {
Martin Peschke348447e2008-03-27 14:22:01 +0100491 [1] = "new",
492 [2] = "ready",
493 [3] = "kill",
494 [4] = "down sleep",
495 [5] = "down wakeup",
496 [6] = "down sleep ecd",
497 [7] = "down wakeup ecd",
498 [8] = "down sleep epd",
499 [9] = "down wakeup epd",
Martin Peschke698ec0162008-03-27 14:22:02 +0100500 [10] = "online",
501 [11] = "operational",
502 [12] = "scsi slave destroy",
503 [13] = "propagate failed adapter",
504 [14] = "propagate failed port",
505 [15] = "block adapter",
506 [16] = "unblock adapter",
507 [17] = "block port",
508 [18] = "unblock port",
509 [19] = "block unit",
510 [20] = "unblock unit",
511 [21] = "unit recovery failed",
512 [22] = "port recovery failed",
513 [23] = "adapter recovery failed",
514 [24] = "qdio queues down",
515 [25] = "p2p failed",
516 [26] = "nameserver lookup failed",
517 [27] = "nameserver port failed",
518 [28] = "link up",
519 [29] = "link down",
520 [30] = "link up status read",
521 [31] = "open port failed",
522 [32] = "open port failed",
523 [33] = "close port",
524 [34] = "open unit failed",
525 [35] = "exclusive open unit failed",
526 [36] = "shared open unit failed",
527 [37] = "link down",
528 [38] = "link down status read no link",
529 [39] = "link down status read fdisc login",
530 [40] = "link down status read firmware update",
531 [41] = "link down status read unknown reason",
532 [42] = "link down ecd incomplete",
533 [43] = "link down epd incomplete",
534 [44] = "sysfs adapter recovery",
535 [45] = "sysfs port recovery",
536 [46] = "sysfs unit recovery",
537 [47] = "port boxed abort",
538 [48] = "unit boxed abort",
539 [49] = "port boxed ct",
540 [50] = "port boxed close physical",
541 [51] = "port boxed open unit",
542 [52] = "port boxed close unit",
543 [53] = "port boxed fcp",
544 [54] = "unit boxed fcp",
Christof Schmitt553448f2008-06-10 18:20:58 +0200545 [55] = "port access denied",
546 [56] = "",
547 [57] = "",
548 [58] = "",
549 [59] = "unit access denied",
Martin Peschke698ec0162008-03-27 14:22:02 +0100550 [60] = "shared unit access denied open unit",
Christof Schmitt553448f2008-06-10 18:20:58 +0200551 [61] = "",
Martin Peschke9467a9b2008-03-27 14:22:03 +0100552 [62] = "request timeout",
553 [63] = "adisc link test reject or timeout",
554 [64] = "adisc link test d_id changed",
555 [65] = "adisc link test failed",
556 [66] = "recovery out of memory",
557 [67] = "adapter recovery repeated after state change",
558 [68] = "port recovery repeated after state change",
559 [69] = "unit recovery repeated after state change",
560 [70] = "port recovery follow-up after successful adapter recovery",
561 [71] = "adapter recovery escalation after failed adapter recovery",
562 [72] = "port recovery follow-up after successful physical port "
563 "recovery",
564 [73] = "adapter recovery escalation after failed physical port "
565 "recovery",
566 [74] = "unit recovery follow-up after successful port recovery",
567 [75] = "physical port recovery escalation after failed port "
568 "recovery",
569 [76] = "port recovery escalation after failed unit recovery",
Swen Schillig5ab944f2008-10-01 12:42:17 +0200570 [77] = "",
Martin Peschke9467a9b2008-03-27 14:22:03 +0100571 [78] = "duplicate request id",
572 [79] = "link down",
573 [80] = "exclusive read-only unit access unsupported",
574 [81] = "shared read-write unit access unsupported",
575 [82] = "incoming rscn",
Christof Schmitt24073b42008-06-10 18:20:54 +0200576 [83] = "incoming wwpn",
Swen Schillig41bfcf92008-10-01 12:42:26 +0200577 [84] = "wka port handle not valid close port",
Martin Peschke9467a9b2008-03-27 14:22:03 +0100578 [85] = "online",
579 [86] = "offline",
580 [87] = "ccw device gone",
581 [88] = "ccw device no path",
582 [89] = "ccw device operational",
583 [90] = "ccw device shutdown",
584 [91] = "sysfs port addition",
585 [92] = "sysfs port removal",
586 [93] = "sysfs adapter recovery",
587 [94] = "sysfs unit addition",
588 [95] = "sysfs unit removal",
589 [96] = "sysfs port recovery",
590 [97] = "sysfs unit recovery",
591 [98] = "sequence number mismatch",
592 [99] = "link up",
593 [100] = "error state",
594 [101] = "status read physical port closed",
595 [102] = "link up status read",
596 [103] = "too many failed status read buffers",
597 [104] = "port handle not valid abort",
598 [105] = "lun handle not valid abort",
599 [106] = "port handle not valid ct",
600 [107] = "port handle not valid close port",
601 [108] = "port handle not valid close physical port",
602 [109] = "port handle not valid open unit",
603 [110] = "port handle not valid close unit",
604 [111] = "lun handle not valid close unit",
605 [112] = "port handle not valid fcp",
606 [113] = "lun handle not valid fcp",
607 [114] = "handle mismatch fcp",
608 [115] = "lun not valid fcp",
609 [116] = "qdio send failed",
610 [117] = "version mismatch",
611 [118] = "incompatible qtcb type",
612 [119] = "unknown protocol status",
613 [120] = "unknown fsf command",
614 [121] = "no recommendation for status qualifier",
615 [122] = "status read physical port closed in error",
Christof Schmitt553448f2008-06-10 18:20:58 +0200616 [123] = "fc service class not supported",
617 [124] = "",
Martin Peschke9467a9b2008-03-27 14:22:03 +0100618 [125] = "need newer zfcp",
619 [126] = "need newer microcode",
620 [127] = "arbitrated loop not supported",
Christof Schmittff3b24f2008-10-01 12:42:15 +0200621 [128] = "",
Martin Peschke9467a9b2008-03-27 14:22:03 +0100622 [129] = "qtcb size mismatch",
623 [130] = "unknown fsf status ecd",
624 [131] = "fcp request too big",
Christof Schmitt553448f2008-06-10 18:20:58 +0200625 [132] = "",
Martin Peschke9467a9b2008-03-27 14:22:03 +0100626 [133] = "data direction not valid fcp",
627 [134] = "command length not valid fcp",
628 [135] = "status read act update",
629 [136] = "status read cfdc update",
630 [137] = "hbaapi port open",
631 [138] = "hbaapi unit open",
632 [139] = "hbaapi unit shutdown",
Swen Schillig00bab912008-06-10 18:20:57 +0200633 [140] = "qdio error outbound",
Martin Peschke9467a9b2008-03-27 14:22:03 +0100634 [141] = "scsi host reset",
Martin Peschke6f4f3652008-03-27 14:22:04 +0100635 [142] = "dismissing fsf request for recovery action",
636 [143] = "recovery action timed out",
637 [144] = "recovery action gone",
638 [145] = "recovery action being processed",
639 [146] = "recovery action ready for next step",
Swen Schillig00bab912008-06-10 18:20:57 +0200640 [147] = "qdio error inbound",
Swen Schilligcc8c2822008-06-10 18:21:00 +0200641 [148] = "nameserver needed for port scan",
642 [149] = "port scan",
643 [150] = "ptp attach",
644 [151] = "port validation failed",
Martin Peschked79a83d2008-03-27 14:22:00 +0100645};
646
647static int zfcp_rec_dbf_view_format(debug_info_t *id, struct debug_view *view,
648 char *buf, const char *_rec)
649{
650 struct zfcp_rec_dbf_record *r = (struct zfcp_rec_dbf_record *)_rec;
651 char *p = buf;
652
653 zfcp_dbf_outs(&p, "tag", zfcp_rec_dbf_tags[r->id]);
654 zfcp_dbf_outs(&p, "hint", zfcp_rec_dbf_ids[r->id2]);
655 zfcp_dbf_out(&p, "id", "%d", r->id2);
656 switch (r->id) {
Martin Peschke348447e2008-03-27 14:22:01 +0100657 case ZFCP_REC_DBF_ID_THREAD:
Martin Peschke348447e2008-03-27 14:22:01 +0100658 zfcp_dbf_out(&p, "total", "%d", r->u.thread.total);
659 zfcp_dbf_out(&p, "ready", "%d", r->u.thread.ready);
660 zfcp_dbf_out(&p, "running", "%d", r->u.thread.running);
661 break;
Martin Peschke698ec0162008-03-27 14:22:02 +0100662 case ZFCP_REC_DBF_ID_TARGET:
663 zfcp_dbf_out(&p, "reference", "0x%016Lx", r->u.target.ref);
664 zfcp_dbf_out(&p, "status", "0x%08x", r->u.target.status);
665 zfcp_dbf_out(&p, "erp_count", "%d", r->u.target.erp_count);
666 zfcp_dbf_out(&p, "d_id", "0x%06x", r->u.target.d_id);
667 zfcp_dbf_out(&p, "wwpn", "0x%016Lx", r->u.target.wwpn);
668 zfcp_dbf_out(&p, "fcp_lun", "0x%016Lx", r->u.target.fcp_lun);
669 break;
Martin Peschke9467a9b2008-03-27 14:22:03 +0100670 case ZFCP_REC_DBF_ID_TRIGGER:
671 zfcp_dbf_out(&p, "reference", "0x%016Lx", r->u.trigger.ref);
672 zfcp_dbf_out(&p, "erp_action", "0x%016Lx", r->u.trigger.action);
673 zfcp_dbf_out(&p, "requested", "%d", r->u.trigger.want);
674 zfcp_dbf_out(&p, "executed", "%d", r->u.trigger.need);
675 zfcp_dbf_out(&p, "wwpn", "0x%016Lx", r->u.trigger.wwpn);
676 zfcp_dbf_out(&p, "fcp_lun", "0x%016Lx", r->u.trigger.fcp_lun);
677 zfcp_dbf_out(&p, "adapter_status", "0x%08x", r->u.trigger.as);
678 zfcp_dbf_out(&p, "port_status", "0x%08x", r->u.trigger.ps);
679 zfcp_dbf_out(&p, "unit_status", "0x%08x", r->u.trigger.us);
680 break;
Martin Peschke6f4f3652008-03-27 14:22:04 +0100681 case ZFCP_REC_DBF_ID_ACTION:
682 zfcp_dbf_out(&p, "erp_action", "0x%016Lx", r->u.action.action);
683 zfcp_dbf_out(&p, "fsf_req", "0x%016Lx", r->u.action.fsf_req);
684 zfcp_dbf_out(&p, "status", "0x%08Lx", r->u.action.status);
685 zfcp_dbf_out(&p, "step", "0x%08Lx", r->u.action.step);
686 break;
Martin Peschked79a83d2008-03-27 14:22:00 +0100687 }
Martin Peschkeb634fff2008-03-31 11:15:24 +0200688 p += sprintf(p, "\n");
689 return p - buf;
Martin Peschked79a83d2008-03-27 14:22:00 +0100690}
691
692static struct debug_view zfcp_rec_dbf_view = {
693 "structured",
694 NULL,
695 &zfcp_dbf_view_header,
696 &zfcp_rec_dbf_view_format,
697 NULL,
698 NULL
699};
700
Martin Peschke348447e2008-03-27 14:22:01 +0100701/**
702 * zfcp_rec_dbf_event_thread - trace event related to recovery thread operation
703 * @id2: identifier for event
704 * @adapter: adapter
Christof Schmittaa0fec62008-05-19 12:17:47 +0200705 * This function assumes that the caller is holding erp_lock.
Martin Peschke348447e2008-03-27 14:22:01 +0100706 */
Christof Schmittaa0fec62008-05-19 12:17:47 +0200707void zfcp_rec_dbf_event_thread(u8 id2, struct zfcp_adapter *adapter)
Martin Peschke348447e2008-03-27 14:22:01 +0100708{
709 struct zfcp_rec_dbf_record *r = &adapter->rec_dbf_buf;
710 unsigned long flags = 0;
711 struct list_head *entry;
712 unsigned ready = 0, running = 0, total;
713
Martin Peschke348447e2008-03-27 14:22:01 +0100714 list_for_each(entry, &adapter->erp_ready_head)
715 ready++;
716 list_for_each(entry, &adapter->erp_running_head)
717 running++;
718 total = adapter->erp_total_count;
Martin Peschke348447e2008-03-27 14:22:01 +0100719
720 spin_lock_irqsave(&adapter->rec_dbf_lock, flags);
721 memset(r, 0, sizeof(*r));
722 r->id = ZFCP_REC_DBF_ID_THREAD;
723 r->id2 = id2;
Martin Peschke348447e2008-03-27 14:22:01 +0100724 r->u.thread.total = total;
725 r->u.thread.ready = ready;
726 r->u.thread.running = running;
Martin Peschke70c66542008-05-19 12:17:45 +0200727 debug_event(adapter->rec_dbf, 6, r, sizeof(*r));
Martin Peschke348447e2008-03-27 14:22:01 +0100728 spin_unlock_irqrestore(&adapter->rec_dbf_lock, flags);
729}
730
Christof Schmittaa0fec62008-05-19 12:17:47 +0200731/**
732 * zfcp_rec_dbf_event_thread - trace event related to recovery thread operation
733 * @id2: identifier for event
734 * @adapter: adapter
735 * This function assumes that the caller does not hold erp_lock.
736 */
737void zfcp_rec_dbf_event_thread_lock(u8 id2, struct zfcp_adapter *adapter)
738{
739 unsigned long flags;
740
741 read_lock_irqsave(&adapter->erp_lock, flags);
742 zfcp_rec_dbf_event_thread(id2, adapter);
743 read_unlock_irqrestore(&adapter->erp_lock, flags);
744}
745
Martin Peschke1f6f7122008-04-18 12:51:55 +0200746static void zfcp_rec_dbf_event_target(u8 id2, void *ref,
Martin Peschke698ec0162008-03-27 14:22:02 +0100747 struct zfcp_adapter *adapter,
748 atomic_t *status, atomic_t *erp_count,
749 u64 wwpn, u32 d_id, u64 fcp_lun)
750{
751 struct zfcp_rec_dbf_record *r = &adapter->rec_dbf_buf;
752 unsigned long flags;
753
754 spin_lock_irqsave(&adapter->rec_dbf_lock, flags);
755 memset(r, 0, sizeof(*r));
756 r->id = ZFCP_REC_DBF_ID_TARGET;
757 r->id2 = id2;
Martin Peschke1f6f7122008-04-18 12:51:55 +0200758 r->u.target.ref = (unsigned long)ref;
Martin Peschke698ec0162008-03-27 14:22:02 +0100759 r->u.target.status = atomic_read(status);
760 r->u.target.wwpn = wwpn;
761 r->u.target.d_id = d_id;
762 r->u.target.fcp_lun = fcp_lun;
763 r->u.target.erp_count = atomic_read(erp_count);
764 debug_event(adapter->rec_dbf, 3, r, sizeof(*r));
765 spin_unlock_irqrestore(&adapter->rec_dbf_lock, flags);
766}
767
768/**
769 * zfcp_rec_dbf_event_adapter - trace event for adapter state change
770 * @id: identifier for trigger of state change
771 * @ref: additional reference (e.g. request)
772 * @adapter: adapter
773 */
Martin Peschke1f6f7122008-04-18 12:51:55 +0200774void zfcp_rec_dbf_event_adapter(u8 id, void *ref, struct zfcp_adapter *adapter)
Martin Peschke698ec0162008-03-27 14:22:02 +0100775{
776 zfcp_rec_dbf_event_target(id, ref, adapter, &adapter->status,
777 &adapter->erp_counter, 0, 0, 0);
778}
779
780/**
781 * zfcp_rec_dbf_event_port - trace event for port state change
782 * @id: identifier for trigger of state change
783 * @ref: additional reference (e.g. request)
784 * @port: port
785 */
Martin Peschke1f6f7122008-04-18 12:51:55 +0200786void zfcp_rec_dbf_event_port(u8 id, void *ref, struct zfcp_port *port)
Martin Peschke698ec0162008-03-27 14:22:02 +0100787{
788 struct zfcp_adapter *adapter = port->adapter;
789
790 zfcp_rec_dbf_event_target(id, ref, adapter, &port->status,
791 &port->erp_counter, port->wwpn, port->d_id,
792 0);
793}
794
795/**
796 * zfcp_rec_dbf_event_unit - trace event for unit state change
797 * @id: identifier for trigger of state change
798 * @ref: additional reference (e.g. request)
799 * @unit: unit
800 */
Martin Peschke1f6f7122008-04-18 12:51:55 +0200801void zfcp_rec_dbf_event_unit(u8 id, void *ref, struct zfcp_unit *unit)
Martin Peschke698ec0162008-03-27 14:22:02 +0100802{
803 struct zfcp_port *port = unit->port;
804 struct zfcp_adapter *adapter = port->adapter;
805
806 zfcp_rec_dbf_event_target(id, ref, adapter, &unit->status,
807 &unit->erp_counter, port->wwpn, port->d_id,
808 unit->fcp_lun);
809}
810
Martin Peschke9467a9b2008-03-27 14:22:03 +0100811/**
812 * zfcp_rec_dbf_event_trigger - trace event for triggered error recovery
813 * @id2: identifier for error recovery trigger
814 * @ref: additional reference (e.g. request)
815 * @want: originally requested error recovery action
816 * @need: error recovery action actually initiated
817 * @action: address of error recovery action struct
818 * @adapter: adapter
819 * @port: port
820 * @unit: unit
821 */
Martin Peschke1f6f7122008-04-18 12:51:55 +0200822void zfcp_rec_dbf_event_trigger(u8 id2, void *ref, u8 want, u8 need,
823 void *action, struct zfcp_adapter *adapter,
Martin Peschke9467a9b2008-03-27 14:22:03 +0100824 struct zfcp_port *port, struct zfcp_unit *unit)
825{
826 struct zfcp_rec_dbf_record *r = &adapter->rec_dbf_buf;
827 unsigned long flags;
828
829 spin_lock_irqsave(&adapter->rec_dbf_lock, flags);
830 memset(r, 0, sizeof(*r));
831 r->id = ZFCP_REC_DBF_ID_TRIGGER;
832 r->id2 = id2;
Martin Peschke1f6f7122008-04-18 12:51:55 +0200833 r->u.trigger.ref = (unsigned long)ref;
Martin Peschke9467a9b2008-03-27 14:22:03 +0100834 r->u.trigger.want = want;
835 r->u.trigger.need = need;
Martin Peschke1f6f7122008-04-18 12:51:55 +0200836 r->u.trigger.action = (unsigned long)action;
Martin Peschke9467a9b2008-03-27 14:22:03 +0100837 r->u.trigger.as = atomic_read(&adapter->status);
838 if (port) {
839 r->u.trigger.ps = atomic_read(&port->status);
840 r->u.trigger.wwpn = port->wwpn;
841 }
842 if (unit) {
843 r->u.trigger.us = atomic_read(&unit->status);
844 r->u.trigger.fcp_lun = unit->fcp_lun;
845 }
846 debug_event(adapter->rec_dbf, action ? 1 : 4, r, sizeof(*r));
847 spin_unlock_irqrestore(&adapter->rec_dbf_lock, flags);
848}
849
Martin Peschke6f4f3652008-03-27 14:22:04 +0100850/**
851 * zfcp_rec_dbf_event_action - trace event showing progress of recovery action
852 * @id2: identifier
853 * @erp_action: error recovery action struct pointer
854 */
855void zfcp_rec_dbf_event_action(u8 id2, struct zfcp_erp_action *erp_action)
856{
857 struct zfcp_adapter *adapter = erp_action->adapter;
858 struct zfcp_rec_dbf_record *r = &adapter->rec_dbf_buf;
859 unsigned long flags;
860
861 spin_lock_irqsave(&adapter->rec_dbf_lock, flags);
862 memset(r, 0, sizeof(*r));
863 r->id = ZFCP_REC_DBF_ID_ACTION;
864 r->id2 = id2;
Martin Peschke1f6f7122008-04-18 12:51:55 +0200865 r->u.action.action = (unsigned long)erp_action;
Martin Peschke6f4f3652008-03-27 14:22:04 +0100866 r->u.action.status = erp_action->status;
867 r->u.action.step = erp_action->step;
Martin Peschke1f6f7122008-04-18 12:51:55 +0200868 r->u.action.fsf_req = (unsigned long)erp_action->fsf_req;
Martin Peschke70c66542008-05-19 12:17:45 +0200869 debug_event(adapter->rec_dbf, 5, r, sizeof(*r));
Martin Peschke6f4f3652008-03-27 14:22:04 +0100870 spin_unlock_irqrestore(&adapter->rec_dbf_lock, flags);
871}
872
Martin Peschkebfab1632008-03-31 11:15:31 +0200873/**
874 * zfcp_san_dbf_event_ct_request - trace event for issued CT request
875 * @fsf_req: request containing issued CT data
876 */
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100877void zfcp_san_dbf_event_ct_request(struct zfcp_fsf_req *fsf_req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200878{
879 struct zfcp_send_ct *ct = (struct zfcp_send_ct *)fsf_req->data;
Swen Schillig5ab944f2008-10-01 12:42:17 +0200880 struct zfcp_wka_port *wka_port = ct->wka_port;
881 struct zfcp_adapter *adapter = wka_port->adapter;
Swen Schillig44cc76f2008-10-01 12:42:16 +0200882 struct ct_hdr *hdr = sg_virt(ct->req);
Martin Peschke6bc473d2008-03-31 11:15:29 +0200883 struct zfcp_san_dbf_record *r = &adapter->san_dbf_buf;
884 struct zfcp_san_dbf_record_ct_request *oct = &r->u.ct_req;
Christof Schmittd94ce6c2008-11-04 16:35:12 +0100885 int level = 3;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200886 unsigned long flags;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200887
Martin Peschke6bc473d2008-03-31 11:15:29 +0200888 spin_lock_irqsave(&adapter->san_dbf_lock, flags);
889 memset(r, 0, sizeof(*r));
890 strncpy(r->tag, "octc", ZFCP_DBF_TAG_SIZE);
891 r->fsf_reqid = (unsigned long)fsf_req;
892 r->fsf_seqno = fsf_req->seq_no;
893 r->s_id = fc_host_port_id(adapter->scsi_host);
Swen Schillig5ab944f2008-10-01 12:42:17 +0200894 r->d_id = wka_port->d_id;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200895 oct->cmd_req_code = hdr->cmd_rsp_code;
896 oct->revision = hdr->revision;
897 oct->gs_type = hdr->gs_type;
898 oct->gs_subtype = hdr->gs_subtype;
899 oct->options = hdr->options;
900 oct->max_res_size = hdr->max_res_size;
901 oct->len = min((int)ct->req->length - (int)sizeof(struct ct_hdr),
Christof Schmittd94ce6c2008-11-04 16:35:12 +0100902 ZFCP_DBF_SAN_MAX_PAYLOAD);
903 debug_event(adapter->san_dbf, level, r, sizeof(*r));
904 zfcp_dbf_hexdump(adapter->san_dbf, r, sizeof(*r), level,
905 (void *)hdr + sizeof(struct ct_hdr), oct->len);
Martin Peschke6bc473d2008-03-31 11:15:29 +0200906 spin_unlock_irqrestore(&adapter->san_dbf_lock, flags);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200907}
908
Martin Peschkebfab1632008-03-31 11:15:31 +0200909/**
910 * zfcp_san_dbf_event_ct_response - trace event for completion of CT request
911 * @fsf_req: request containing CT response
912 */
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100913void zfcp_san_dbf_event_ct_response(struct zfcp_fsf_req *fsf_req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200914{
915 struct zfcp_send_ct *ct = (struct zfcp_send_ct *)fsf_req->data;
Swen Schillig5ab944f2008-10-01 12:42:17 +0200916 struct zfcp_wka_port *wka_port = ct->wka_port;
917 struct zfcp_adapter *adapter = wka_port->adapter;
Swen Schillig44cc76f2008-10-01 12:42:16 +0200918 struct ct_hdr *hdr = sg_virt(ct->resp);
Martin Peschke6bc473d2008-03-31 11:15:29 +0200919 struct zfcp_san_dbf_record *r = &adapter->san_dbf_buf;
920 struct zfcp_san_dbf_record_ct_response *rct = &r->u.ct_resp;
Christof Schmittd94ce6c2008-11-04 16:35:12 +0100921 int level = 3;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200922 unsigned long flags;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200923
Martin Peschke6bc473d2008-03-31 11:15:29 +0200924 spin_lock_irqsave(&adapter->san_dbf_lock, flags);
925 memset(r, 0, sizeof(*r));
926 strncpy(r->tag, "rctc", ZFCP_DBF_TAG_SIZE);
927 r->fsf_reqid = (unsigned long)fsf_req;
928 r->fsf_seqno = fsf_req->seq_no;
Swen Schillig5ab944f2008-10-01 12:42:17 +0200929 r->s_id = wka_port->d_id;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200930 r->d_id = fc_host_port_id(adapter->scsi_host);
931 rct->cmd_rsp_code = hdr->cmd_rsp_code;
932 rct->revision = hdr->revision;
933 rct->reason_code = hdr->reason_code;
934 rct->expl = hdr->reason_code_expl;
935 rct->vendor_unique = hdr->vendor_unique;
936 rct->len = min((int)ct->resp->length - (int)sizeof(struct ct_hdr),
Christof Schmittd94ce6c2008-11-04 16:35:12 +0100937 ZFCP_DBF_SAN_MAX_PAYLOAD);
938 debug_event(adapter->san_dbf, level, r, sizeof(*r));
939 zfcp_dbf_hexdump(adapter->san_dbf, r, sizeof(*r), level,
940 (void *)hdr + sizeof(struct ct_hdr), rct->len);
Martin Peschke6bc473d2008-03-31 11:15:29 +0200941 spin_unlock_irqrestore(&adapter->san_dbf_lock, flags);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200942}
943
Martin Peschke92c7a832008-03-31 11:15:30 +0200944static void zfcp_san_dbf_event_els(const char *tag, int level,
945 struct zfcp_fsf_req *fsf_req, u32 s_id,
946 u32 d_id, u8 ls_code, void *buffer,
947 int buflen)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200948{
949 struct zfcp_adapter *adapter = fsf_req->adapter;
950 struct zfcp_san_dbf_record *rec = &adapter->san_dbf_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200951 unsigned long flags;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200952
953 spin_lock_irqsave(&adapter->san_dbf_lock, flags);
Martin Peschke6bc473d2008-03-31 11:15:29 +0200954 memset(rec, 0, sizeof(*rec));
Martin Peschke0f65e952008-03-27 14:21:56 +0100955 strncpy(rec->tag, tag, ZFCP_DBF_TAG_SIZE);
956 rec->fsf_reqid = (unsigned long)fsf_req;
957 rec->fsf_seqno = fsf_req->seq_no;
958 rec->s_id = s_id;
959 rec->d_id = d_id;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200960 rec->u.els.ls_code = ls_code;
Martin Peschke0f65e952008-03-27 14:21:56 +0100961 debug_event(adapter->san_dbf, level, rec, sizeof(*rec));
962 zfcp_dbf_hexdump(adapter->san_dbf, rec, sizeof(*rec), level,
Christof Schmittd94ce6c2008-11-04 16:35:12 +0100963 buffer, min(buflen, ZFCP_DBF_SAN_MAX_PAYLOAD));
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200964 spin_unlock_irqrestore(&adapter->san_dbf_lock, flags);
965}
966
Martin Peschkebfab1632008-03-31 11:15:31 +0200967/**
968 * zfcp_san_dbf_event_els_request - trace event for issued ELS
969 * @fsf_req: request containing issued ELS
970 */
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100971void zfcp_san_dbf_event_els_request(struct zfcp_fsf_req *fsf_req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200972{
973 struct zfcp_send_els *els = (struct zfcp_send_els *)fsf_req->data;
974
Martin Peschke92c7a832008-03-31 11:15:30 +0200975 zfcp_san_dbf_event_els("oels", 2, fsf_req,
976 fc_host_port_id(els->adapter->scsi_host),
Swen Schillig44cc76f2008-10-01 12:42:16 +0200977 els->d_id, *(u8 *) sg_virt(els->req),
978 sg_virt(els->req), els->req->length);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200979}
980
Martin Peschkebfab1632008-03-31 11:15:31 +0200981/**
982 * zfcp_san_dbf_event_els_response - trace event for completed ELS
983 * @fsf_req: request containing ELS response
984 */
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100985void zfcp_san_dbf_event_els_response(struct zfcp_fsf_req *fsf_req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200986{
987 struct zfcp_send_els *els = (struct zfcp_send_els *)fsf_req->data;
988
Martin Peschke92c7a832008-03-31 11:15:30 +0200989 zfcp_san_dbf_event_els("rels", 2, fsf_req, els->d_id,
990 fc_host_port_id(els->adapter->scsi_host),
Swen Schillig44cc76f2008-10-01 12:42:16 +0200991 *(u8 *)sg_virt(els->req), sg_virt(els->resp),
Martin Peschke92c7a832008-03-31 11:15:30 +0200992 els->resp->length);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200993}
994
Martin Peschkebfab1632008-03-31 11:15:31 +0200995/**
996 * zfcp_san_dbf_event_incoming_els - trace event for incomig ELS
997 * @fsf_req: request containing unsolicited status buffer with incoming ELS
998 */
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100999void zfcp_san_dbf_event_incoming_els(struct zfcp_fsf_req *fsf_req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001000{
1001 struct zfcp_adapter *adapter = fsf_req->adapter;
Martin Peschke92c7a832008-03-31 11:15:30 +02001002 struct fsf_status_read_buffer *buf =
1003 (struct fsf_status_read_buffer *)fsf_req->data;
1004 int length = (int)buf->length -
1005 (int)((void *)&buf->payload - (void *)buf);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001006
Martin Peschke92c7a832008-03-31 11:15:30 +02001007 zfcp_san_dbf_event_els("iels", 1, fsf_req, buf->d_id,
1008 fc_host_port_id(adapter->scsi_host),
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001009 buf->payload.data[0], (void *)buf->payload.data,
Martin Peschke92c7a832008-03-31 11:15:30 +02001010 length);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001011}
1012
Martin Peschke92c7a832008-03-31 11:15:30 +02001013static int zfcp_san_dbf_view_format(debug_info_t *id, struct debug_view *view,
1014 char *out_buf, const char *in_buf)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001015{
Martin Peschkeb634fff2008-03-31 11:15:24 +02001016 struct zfcp_san_dbf_record *r = (struct zfcp_san_dbf_record *)in_buf;
Martin Peschkeb634fff2008-03-31 11:15:24 +02001017 char *p = out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001018
Martin Peschkeb634fff2008-03-31 11:15:24 +02001019 if (strncmp(r->tag, "dump", ZFCP_DBF_TAG_SIZE) == 0)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001020 return 0;
1021
Martin Peschkea9c85772008-03-31 11:15:27 +02001022 zfcp_dbf_tag(&p, "tag", r->tag);
Martin Peschkeb634fff2008-03-31 11:15:24 +02001023 zfcp_dbf_out(&p, "fsf_reqid", "0x%0Lx", r->fsf_reqid);
1024 zfcp_dbf_out(&p, "fsf_seqno", "0x%08x", r->fsf_seqno);
1025 zfcp_dbf_out(&p, "s_id", "0x%06x", r->s_id);
1026 zfcp_dbf_out(&p, "d_id", "0x%06x", r->d_id);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001027
Martin Peschkeb634fff2008-03-31 11:15:24 +02001028 if (strncmp(r->tag, "octc", ZFCP_DBF_TAG_SIZE) == 0) {
Martin Peschke6bc473d2008-03-31 11:15:29 +02001029 struct zfcp_san_dbf_record_ct_request *ct = &r->u.ct_req;
1030 zfcp_dbf_out(&p, "cmd_req_code", "0x%04x", ct->cmd_req_code);
1031 zfcp_dbf_out(&p, "revision", "0x%02x", ct->revision);
1032 zfcp_dbf_out(&p, "gs_type", "0x%02x", ct->gs_type);
1033 zfcp_dbf_out(&p, "gs_subtype", "0x%02x", ct->gs_subtype);
1034 zfcp_dbf_out(&p, "options", "0x%02x", ct->options);
1035 zfcp_dbf_out(&p, "max_res_size", "0x%04x", ct->max_res_size);
Martin Peschkeb634fff2008-03-31 11:15:24 +02001036 } else if (strncmp(r->tag, "rctc", ZFCP_DBF_TAG_SIZE) == 0) {
Martin Peschke6bc473d2008-03-31 11:15:29 +02001037 struct zfcp_san_dbf_record_ct_response *ct = &r->u.ct_resp;
1038 zfcp_dbf_out(&p, "cmd_rsp_code", "0x%04x", ct->cmd_rsp_code);
1039 zfcp_dbf_out(&p, "revision", "0x%02x", ct->revision);
1040 zfcp_dbf_out(&p, "reason_code", "0x%02x", ct->reason_code);
1041 zfcp_dbf_out(&p, "reason_code_expl", "0x%02x", ct->expl);
1042 zfcp_dbf_out(&p, "vendor_unique", "0x%02x", ct->vendor_unique);
Martin Peschkeb634fff2008-03-31 11:15:24 +02001043 } else if (strncmp(r->tag, "oels", ZFCP_DBF_TAG_SIZE) == 0 ||
1044 strncmp(r->tag, "rels", ZFCP_DBF_TAG_SIZE) == 0 ||
1045 strncmp(r->tag, "iels", ZFCP_DBF_TAG_SIZE) == 0) {
Martin Peschke6bc473d2008-03-31 11:15:29 +02001046 struct zfcp_san_dbf_record_els *els = &r->u.els;
1047 zfcp_dbf_out(&p, "ls_code", "0x%02x", els->ls_code);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001048 }
Martin Peschkeb634fff2008-03-31 11:15:24 +02001049 return p - out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001050}
1051
Heiko Carstens2b67fc42007-02-05 21:16:47 +01001052static struct debug_view zfcp_san_dbf_view = {
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001053 "structured",
1054 NULL,
1055 &zfcp_dbf_view_header,
1056 &zfcp_san_dbf_view_format,
1057 NULL,
1058 NULL
1059};
1060
Martin Peschke92c7a832008-03-31 11:15:30 +02001061static void zfcp_scsi_dbf_event(const char *tag, const char *tag2, int level,
1062 struct zfcp_adapter *adapter,
1063 struct scsi_cmnd *scsi_cmnd,
1064 struct zfcp_fsf_req *fsf_req,
1065 unsigned long old_req_id)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001066{
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001067 struct zfcp_scsi_dbf_record *rec = &adapter->scsi_dbf_buf;
1068 struct zfcp_dbf_dump *dump = (struct zfcp_dbf_dump *)rec;
1069 unsigned long flags;
1070 struct fcp_rsp_iu *fcp_rsp;
1071 char *fcp_rsp_info = NULL, *fcp_sns_info = NULL;
1072 int offset = 0, buflen = 0;
1073
1074 spin_lock_irqsave(&adapter->scsi_dbf_lock, flags);
1075 do {
Martin Peschke6bc473d2008-03-31 11:15:29 +02001076 memset(rec, 0, sizeof(*rec));
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001077 if (offset == 0) {
1078 strncpy(rec->tag, tag, ZFCP_DBF_TAG_SIZE);
1079 strncpy(rec->tag2, tag2, ZFCP_DBF_TAG_SIZE);
Maxim Shchetynined829ad2006-02-11 01:42:58 +01001080 if (scsi_cmnd != NULL) {
1081 if (scsi_cmnd->device) {
1082 rec->scsi_id = scsi_cmnd->device->id;
1083 rec->scsi_lun = scsi_cmnd->device->lun;
1084 }
1085 rec->scsi_result = scsi_cmnd->result;
1086 rec->scsi_cmnd = (unsigned long)scsi_cmnd;
1087 rec->scsi_serial = scsi_cmnd->serial_number;
Boaz Harrosh64a87b22008-04-30 11:19:47 +03001088 memcpy(rec->scsi_opcode, scsi_cmnd->cmnd,
Maxim Shchetynined829ad2006-02-11 01:42:58 +01001089 min((int)scsi_cmnd->cmd_len,
1090 ZFCP_DBF_SCSI_OPCODE));
1091 rec->scsi_retries = scsi_cmnd->retries;
1092 rec->scsi_allowed = scsi_cmnd->allowed;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001093 }
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001094 if (fsf_req != NULL) {
1095 fcp_rsp = (struct fcp_rsp_iu *)
1096 &(fsf_req->qtcb->bottom.io.fcp_rsp);
Martin Petermannf76af7d2008-07-02 10:56:36 +02001097 fcp_rsp_info = (unsigned char *) &fcp_rsp[1];
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001098 fcp_sns_info =
1099 zfcp_get_fcp_sns_info_ptr(fcp_rsp);
1100
Martin Peschke6bc473d2008-03-31 11:15:29 +02001101 rec->rsp_validity = fcp_rsp->validity.value;
1102 rec->rsp_scsi_status = fcp_rsp->scsi_status;
1103 rec->rsp_resid = fcp_rsp->fcp_resid;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001104 if (fcp_rsp->validity.bits.fcp_rsp_len_valid)
Martin Peschke6bc473d2008-03-31 11:15:29 +02001105 rec->rsp_code = *(fcp_rsp_info + 3);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001106 if (fcp_rsp->validity.bits.fcp_sns_len_valid) {
1107 buflen = min((int)fcp_rsp->fcp_sns_len,
1108 ZFCP_DBF_SCSI_MAX_FCP_SNS_INFO);
Martin Peschke6bc473d2008-03-31 11:15:29 +02001109 rec->sns_info_len = buflen;
1110 memcpy(rec->sns_info, fcp_sns_info,
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001111 min(buflen,
1112 ZFCP_DBF_SCSI_FCP_SNS_INFO));
1113 offset += min(buflen,
1114 ZFCP_DBF_SCSI_FCP_SNS_INFO);
1115 }
1116
1117 rec->fsf_reqid = (unsigned long)fsf_req;
1118 rec->fsf_seqno = fsf_req->seq_no;
1119 rec->fsf_issued = fsf_req->issued;
1120 }
Martin Peschke6bc473d2008-03-31 11:15:29 +02001121 rec->old_fsf_reqid = old_req_id;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001122 } else {
1123 strncpy(dump->tag, "dump", ZFCP_DBF_TAG_SIZE);
1124 dump->total_size = buflen;
1125 dump->offset = offset;
1126 dump->size = min(buflen - offset,
1127 (int)sizeof(struct
1128 zfcp_scsi_dbf_record) -
1129 (int)sizeof(struct zfcp_dbf_dump));
1130 memcpy(dump->data, fcp_sns_info + offset, dump->size);
1131 offset += dump->size;
1132 }
Martin Peschke6bc473d2008-03-31 11:15:29 +02001133 debug_event(adapter->scsi_dbf, level, rec, sizeof(*rec));
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001134 } while (offset < buflen);
1135 spin_unlock_irqrestore(&adapter->scsi_dbf_lock, flags);
1136}
1137
Martin Peschkebfab1632008-03-31 11:15:31 +02001138/**
1139 * zfcp_scsi_dbf_event_result - trace event for SCSI command completion
1140 * @tag: tag indicating success or failure of SCSI command
1141 * @level: trace level applicable for this event
1142 * @adapter: adapter that has been used to issue the SCSI command
1143 * @scsi_cmnd: SCSI command pointer
1144 * @fsf_req: request used to issue SCSI command (might be NULL)
1145 */
Martin Peschke92c7a832008-03-31 11:15:30 +02001146void zfcp_scsi_dbf_event_result(const char *tag, int level,
1147 struct zfcp_adapter *adapter,
1148 struct scsi_cmnd *scsi_cmnd,
1149 struct zfcp_fsf_req *fsf_req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001150{
Martin Peschke92c7a832008-03-31 11:15:30 +02001151 zfcp_scsi_dbf_event("rslt", tag, level, adapter, scsi_cmnd, fsf_req, 0);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001152}
1153
Martin Peschkebfab1632008-03-31 11:15:31 +02001154/**
1155 * zfcp_scsi_dbf_event_abort - trace event for SCSI command abort
1156 * @tag: tag indicating success or failure of abort operation
1157 * @adapter: adapter thas has been used to issue SCSI command to be aborted
1158 * @scsi_cmnd: SCSI command to be aborted
1159 * @new_fsf_req: request containing abort (might be NULL)
1160 * @old_req_id: identifier of request containg SCSI command to be aborted
1161 */
Martin Peschke92c7a832008-03-31 11:15:30 +02001162void zfcp_scsi_dbf_event_abort(const char *tag, struct zfcp_adapter *adapter,
1163 struct scsi_cmnd *scsi_cmnd,
1164 struct zfcp_fsf_req *new_fsf_req,
1165 unsigned long old_req_id)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001166{
Martin Peschke92c7a832008-03-31 11:15:30 +02001167 zfcp_scsi_dbf_event("abrt", tag, 1, adapter, scsi_cmnd, new_fsf_req,
1168 old_req_id);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001169}
1170
Martin Peschkebfab1632008-03-31 11:15:31 +02001171/**
1172 * zfcp_scsi_dbf_event_devreset - trace event for Logical Unit or Target Reset
1173 * @tag: tag indicating success or failure of reset operation
1174 * @flag: indicates type of reset (Target Reset, Logical Unit Reset)
1175 * @unit: unit that needs reset
1176 * @scsi_cmnd: SCSI command which caused this error recovery
1177 */
Martin Peschke92c7a832008-03-31 11:15:30 +02001178void zfcp_scsi_dbf_event_devreset(const char *tag, u8 flag,
1179 struct zfcp_unit *unit,
1180 struct scsi_cmnd *scsi_cmnd)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001181{
Martin Peschke92c7a832008-03-31 11:15:30 +02001182 zfcp_scsi_dbf_event(flag == FCP_TARGET_RESET ? "trst" : "lrst", tag, 1,
1183 unit->port->adapter, scsi_cmnd, NULL, 0);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001184}
1185
Martin Peschke92c7a832008-03-31 11:15:30 +02001186static int zfcp_scsi_dbf_view_format(debug_info_t *id, struct debug_view *view,
1187 char *out_buf, const char *in_buf)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001188{
Martin Peschkeb634fff2008-03-31 11:15:24 +02001189 struct zfcp_scsi_dbf_record *r = (struct zfcp_scsi_dbf_record *)in_buf;
Martin Peschke8fc5af12008-03-31 11:15:23 +02001190 struct timespec t;
Martin Peschkeb634fff2008-03-31 11:15:24 +02001191 char *p = out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001192
Martin Peschkeb634fff2008-03-31 11:15:24 +02001193 if (strncmp(r->tag, "dump", ZFCP_DBF_TAG_SIZE) == 0)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001194 return 0;
1195
Martin Peschkea9c85772008-03-31 11:15:27 +02001196 zfcp_dbf_tag(&p, "tag", r->tag);
1197 zfcp_dbf_tag(&p, "tag2", r->tag2);
Martin Peschkeb634fff2008-03-31 11:15:24 +02001198 zfcp_dbf_out(&p, "scsi_id", "0x%08x", r->scsi_id);
1199 zfcp_dbf_out(&p, "scsi_lun", "0x%08x", r->scsi_lun);
1200 zfcp_dbf_out(&p, "scsi_result", "0x%08x", r->scsi_result);
1201 zfcp_dbf_out(&p, "scsi_cmnd", "0x%0Lx", r->scsi_cmnd);
1202 zfcp_dbf_out(&p, "scsi_serial", "0x%016Lx", r->scsi_serial);
Martin Peschkedf29f4a2008-03-31 11:15:26 +02001203 zfcp_dbf_outd(&p, "scsi_opcode", r->scsi_opcode, ZFCP_DBF_SCSI_OPCODE,
1204 0, ZFCP_DBF_SCSI_OPCODE);
Martin Peschkeb634fff2008-03-31 11:15:24 +02001205 zfcp_dbf_out(&p, "scsi_retries", "0x%02x", r->scsi_retries);
1206 zfcp_dbf_out(&p, "scsi_allowed", "0x%02x", r->scsi_allowed);
1207 if (strncmp(r->tag, "abrt", ZFCP_DBF_TAG_SIZE) == 0)
Martin Peschke6bc473d2008-03-31 11:15:29 +02001208 zfcp_dbf_out(&p, "old_fsf_reqid", "0x%0Lx", r->old_fsf_reqid);
Martin Peschkeb634fff2008-03-31 11:15:24 +02001209 zfcp_dbf_out(&p, "fsf_reqid", "0x%0Lx", r->fsf_reqid);
1210 zfcp_dbf_out(&p, "fsf_seqno", "0x%08x", r->fsf_seqno);
1211 zfcp_dbf_timestamp(r->fsf_issued, &t);
1212 zfcp_dbf_out(&p, "fsf_issued", "%011lu:%06lu", t.tv_sec, t.tv_nsec);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001213
Martin Peschkeb634fff2008-03-31 11:15:24 +02001214 if (strncmp(r->tag, "rslt", ZFCP_DBF_TAG_SIZE) == 0) {
Martin Peschke6bc473d2008-03-31 11:15:29 +02001215 zfcp_dbf_out(&p, "fcp_rsp_validity", "0x%02x", r->rsp_validity);
1216 zfcp_dbf_out(&p, "fcp_rsp_scsi_status", "0x%02x",
1217 r->rsp_scsi_status);
1218 zfcp_dbf_out(&p, "fcp_rsp_resid", "0x%08x", r->rsp_resid);
1219 zfcp_dbf_out(&p, "fcp_rsp_code", "0x%08x", r->rsp_code);
1220 zfcp_dbf_out(&p, "fcp_sns_info_len", "0x%08x", r->sns_info_len);
1221 zfcp_dbf_outd(&p, "fcp_sns_info", r->sns_info,
1222 min((int)r->sns_info_len,
Martin Peschkedf29f4a2008-03-31 11:15:26 +02001223 ZFCP_DBF_SCSI_FCP_SNS_INFO), 0,
Martin Peschke6bc473d2008-03-31 11:15:29 +02001224 r->sns_info_len);
Martin Peschkeb634fff2008-03-31 11:15:24 +02001225 }
1226 p += sprintf(p, "\n");
1227 return p - out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001228}
1229
Heiko Carstens2b67fc42007-02-05 21:16:47 +01001230static struct debug_view zfcp_scsi_dbf_view = {
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001231 "structured",
1232 NULL,
1233 &zfcp_dbf_view_header,
1234 &zfcp_scsi_dbf_view_format,
1235 NULL,
1236 NULL
1237};
1238
1239/**
1240 * zfcp_adapter_debug_register - registers debug feature for an adapter
1241 * @adapter: pointer to adapter for which debug features should be registered
1242 * return: -ENOMEM on error, 0 otherwise
1243 */
1244int zfcp_adapter_debug_register(struct zfcp_adapter *adapter)
1245{
1246 char dbf_name[DEBUG_MAX_NAME_LEN];
1247
1248 /* debug feature area which records recovery activity */
Martin Peschked79a83d2008-03-27 14:22:00 +01001249 sprintf(dbf_name, "zfcp_%s_rec", zfcp_get_busid_by_adapter(adapter));
1250 adapter->rec_dbf = debug_register(dbf_name, dbfsize, 1,
1251 sizeof(struct zfcp_rec_dbf_record));
1252 if (!adapter->rec_dbf)
1253 goto failed;
1254 debug_register_view(adapter->rec_dbf, &debug_hex_ascii_view);
1255 debug_register_view(adapter->rec_dbf, &zfcp_rec_dbf_view);
1256 debug_set_level(adapter->rec_dbf, 3);
1257
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001258 /* debug feature area which records HBA (FSF and QDIO) conditions */
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001259 sprintf(dbf_name, "zfcp_%s_hba", zfcp_get_busid_by_adapter(adapter));
1260 adapter->hba_dbf = debug_register(dbf_name, dbfsize, 1,
1261 sizeof(struct zfcp_hba_dbf_record));
1262 if (!adapter->hba_dbf)
1263 goto failed;
1264 debug_register_view(adapter->hba_dbf, &debug_hex_ascii_view);
1265 debug_register_view(adapter->hba_dbf, &zfcp_hba_dbf_view);
1266 debug_set_level(adapter->hba_dbf, 3);
1267
1268 /* debug feature area which records SAN command failures and recovery */
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001269 sprintf(dbf_name, "zfcp_%s_san", zfcp_get_busid_by_adapter(adapter));
1270 adapter->san_dbf = debug_register(dbf_name, dbfsize, 1,
1271 sizeof(struct zfcp_san_dbf_record));
1272 if (!adapter->san_dbf)
1273 goto failed;
1274 debug_register_view(adapter->san_dbf, &debug_hex_ascii_view);
1275 debug_register_view(adapter->san_dbf, &zfcp_san_dbf_view);
1276 debug_set_level(adapter->san_dbf, 6);
1277
1278 /* debug feature area which records SCSI command failures and recovery */
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001279 sprintf(dbf_name, "zfcp_%s_scsi", zfcp_get_busid_by_adapter(adapter));
1280 adapter->scsi_dbf = debug_register(dbf_name, dbfsize, 1,
1281 sizeof(struct zfcp_scsi_dbf_record));
1282 if (!adapter->scsi_dbf)
1283 goto failed;
1284 debug_register_view(adapter->scsi_dbf, &debug_hex_ascii_view);
1285 debug_register_view(adapter->scsi_dbf, &zfcp_scsi_dbf_view);
1286 debug_set_level(adapter->scsi_dbf, 3);
1287
1288 return 0;
1289
1290 failed:
1291 zfcp_adapter_debug_unregister(adapter);
1292
1293 return -ENOMEM;
1294}
1295
1296/**
1297 * zfcp_adapter_debug_unregister - unregisters debug feature for an adapter
1298 * @adapter: pointer to adapter for which debug features should be unregistered
1299 */
1300void zfcp_adapter_debug_unregister(struct zfcp_adapter *adapter)
1301{
1302 debug_unregister(adapter->scsi_dbf);
1303 debug_unregister(adapter->san_dbf);
1304 debug_unregister(adapter->hba_dbf);
Martin Peschked79a83d2008-03-27 14:22:00 +01001305 debug_unregister(adapter->rec_dbf);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001306 adapter->scsi_dbf = NULL;
1307 adapter->san_dbf = NULL;
1308 adapter->hba_dbf = NULL;
Martin Peschked79a83d2008-03-27 14:22:00 +01001309 adapter->rec_dbf = NULL;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001310}