blob: 060f5f2352ecb590b74e8667bb703fb1c0e62bc1 [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);
33 debug_event(dbf, level, dump, dump->size);
34 }
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 {
Martin Peschkedf29f4a2008-03-31 11:15:26 +0200111 zfcp_dbf_outd(&p, NULL, dump->data, dump->size, dump->offset,
112 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);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200369 break;
370
371 case FSF_QTCB_OPEN_PORT_WITH_DID:
372 case FSF_QTCB_CLOSE_PORT:
373 case FSF_QTCB_CLOSE_PHYSICAL_PORT:
Martin Peschke6bc473d2008-03-31 11:15:29 +0200374 zfcp_dbf_out(p, "wwpn", "0x%016Lx", r->u.port.wwpn);
375 zfcp_dbf_out(p, "d_id", "0x%06x", r->u.port.d_id);
376 zfcp_dbf_out(p, "port_handle", "0x%08x", r->u.port.port_handle);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200377 break;
378
379 case FSF_QTCB_OPEN_LUN:
380 case FSF_QTCB_CLOSE_LUN:
Martin Peschke6bc473d2008-03-31 11:15:29 +0200381 zfcp_dbf_out(p, "wwpn", "0x%016Lx", r->u.unit.wwpn);
382 zfcp_dbf_out(p, "fcp_lun", "0x%016Lx", r->u.unit.fcp_lun);
383 zfcp_dbf_out(p, "port_handle", "0x%08x", r->u.unit.port_handle);
384 zfcp_dbf_out(p, "lun_handle", "0x%08x", r->u.unit.lun_handle);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200385 break;
386
387 case FSF_QTCB_SEND_ELS:
Martin Peschke6bc473d2008-03-31 11:15:29 +0200388 zfcp_dbf_out(p, "d_id", "0x%06x", r->u.els.d_id);
389 zfcp_dbf_out(p, "ls_code", "0x%02x", r->u.els.ls_code);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200390 break;
391
392 case FSF_QTCB_ABORT_FCP_CMND:
393 case FSF_QTCB_SEND_GENERIC:
394 case FSF_QTCB_EXCHANGE_CONFIG_DATA:
395 case FSF_QTCB_EXCHANGE_PORT_DATA:
396 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
397 case FSF_QTCB_UPLOAD_CONTROL_FILE:
398 break;
399 }
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200400}
401
Martin Peschkea9c85772008-03-31 11:15:27 +0200402static void zfcp_hba_dbf_view_status(char **p,
403 struct zfcp_hba_dbf_record_status *r)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200404{
Martin Peschkea9c85772008-03-31 11:15:27 +0200405 zfcp_dbf_out(p, "failed", "0x%02x", r->failed);
406 zfcp_dbf_out(p, "status_type", "0x%08x", r->status_type);
407 zfcp_dbf_out(p, "status_subtype", "0x%08x", r->status_subtype);
408 zfcp_dbf_outd(p, "queue_designator", (char *)&r->queue_designator,
Martin Peschkedf29f4a2008-03-31 11:15:26 +0200409 sizeof(struct fsf_queue_designator), 0,
410 sizeof(struct fsf_queue_designator));
Martin Peschkea9c85772008-03-31 11:15:27 +0200411 zfcp_dbf_outd(p, "payload", (char *)&r->payload, r->payload_size, 0,
Martin Peschkedf29f4a2008-03-31 11:15:26 +0200412 r->payload_size);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200413}
414
Martin Peschkea9c85772008-03-31 11:15:27 +0200415static void zfcp_hba_dbf_view_qdio(char **p, struct zfcp_hba_dbf_record_qdio *r)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200416{
Martin Peschkea9c85772008-03-31 11:15:27 +0200417 zfcp_dbf_out(p, "qdio_error", "0x%08x", r->qdio_error);
Martin Peschkea9c85772008-03-31 11:15:27 +0200418 zfcp_dbf_out(p, "sbal_index", "0x%02x", r->sbal_index);
419 zfcp_dbf_out(p, "sbal_count", "0x%02x", r->sbal_count);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200420}
421
Swen Schillig57069382008-10-01 12:42:21 +0200422static void zfcp_hba_dbf_view_berr(char **p, struct fsf_bit_error_payload *r)
423{
424 zfcp_dbf_out(p, "link_failures", "%d", r->link_failure_error_count);
425 zfcp_dbf_out(p, "loss_of_sync_err", "%d", r->loss_of_sync_error_count);
426 zfcp_dbf_out(p, "loss_of_sig_err", "%d", r->loss_of_signal_error_count);
427 zfcp_dbf_out(p, "prim_seq_err", "%d",
428 r->primitive_sequence_error_count);
429 zfcp_dbf_out(p, "inval_trans_word_err", "%d",
430 r->invalid_transmission_word_error_count);
431 zfcp_dbf_out(p, "CRC_errors", "%d", r->crc_error_count);
432 zfcp_dbf_out(p, "prim_seq_event_to", "%d",
433 r->primitive_sequence_event_timeout_count);
434 zfcp_dbf_out(p, "elast_buf_overrun_err", "%d",
435 r->elastic_buffer_overrun_error_count);
436 zfcp_dbf_out(p, "adv_rec_buf2buf_cred", "%d",
437 r->advertised_receive_b2b_credit);
438 zfcp_dbf_out(p, "curr_rec_buf2buf_cred", "%d",
439 r->current_receive_b2b_credit);
440 zfcp_dbf_out(p, "adv_trans_buf2buf_cred", "%d",
441 r->advertised_transmit_b2b_credit);
442 zfcp_dbf_out(p, "curr_trans_buf2buf_cred", "%d",
443 r->current_transmit_b2b_credit);
444}
445
Martin Peschkea9c85772008-03-31 11:15:27 +0200446static int zfcp_hba_dbf_view_format(debug_info_t *id, struct debug_view *view,
447 char *out_buf, const char *in_buf)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200448{
Martin Peschkea9c85772008-03-31 11:15:27 +0200449 struct zfcp_hba_dbf_record *r = (struct zfcp_hba_dbf_record *)in_buf;
450 char *p = out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200451
Martin Peschkea9c85772008-03-31 11:15:27 +0200452 if (strncmp(r->tag, "dump", ZFCP_DBF_TAG_SIZE) == 0)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200453 return 0;
454
Martin Peschkea9c85772008-03-31 11:15:27 +0200455 zfcp_dbf_tag(&p, "tag", r->tag);
456 if (isalpha(r->tag2[0]))
457 zfcp_dbf_tag(&p, "tag2", r->tag2);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200458
Martin Peschkea9c85772008-03-31 11:15:27 +0200459 if (strncmp(r->tag, "resp", ZFCP_DBF_TAG_SIZE) == 0)
Martin Peschke6bc473d2008-03-31 11:15:29 +0200460 zfcp_hba_dbf_view_response(&p, &r->u.response);
Martin Peschkea9c85772008-03-31 11:15:27 +0200461 else if (strncmp(r->tag, "stat", ZFCP_DBF_TAG_SIZE) == 0)
Martin Peschke6bc473d2008-03-31 11:15:29 +0200462 zfcp_hba_dbf_view_status(&p, &r->u.status);
Martin Peschkea9c85772008-03-31 11:15:27 +0200463 else if (strncmp(r->tag, "qdio", ZFCP_DBF_TAG_SIZE) == 0)
Martin Peschke6bc473d2008-03-31 11:15:29 +0200464 zfcp_hba_dbf_view_qdio(&p, &r->u.qdio);
Swen Schillig57069382008-10-01 12:42:21 +0200465 else if (strncmp(r->tag, "berr", ZFCP_DBF_TAG_SIZE) == 0)
466 zfcp_hba_dbf_view_berr(&p, &r->u.berr);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200467
Martin Peschkea9c85772008-03-31 11:15:27 +0200468 p += sprintf(p, "\n");
469 return p - out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200470}
471
Heiko Carstens2b67fc42007-02-05 21:16:47 +0100472static struct debug_view zfcp_hba_dbf_view = {
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200473 "structured",
474 NULL,
475 &zfcp_dbf_view_header,
476 &zfcp_hba_dbf_view_format,
477 NULL,
478 NULL
479};
480
Martin Peschked79a83d2008-03-27 14:22:00 +0100481static const char *zfcp_rec_dbf_tags[] = {
Martin Peschke348447e2008-03-27 14:22:01 +0100482 [ZFCP_REC_DBF_ID_THREAD] = "thread",
Martin Peschke698ec0162008-03-27 14:22:02 +0100483 [ZFCP_REC_DBF_ID_TARGET] = "target",
Martin Peschke9467a9b2008-03-27 14:22:03 +0100484 [ZFCP_REC_DBF_ID_TRIGGER] = "trigger",
Martin Peschke6f4f3652008-03-27 14:22:04 +0100485 [ZFCP_REC_DBF_ID_ACTION] = "action",
Martin Peschked79a83d2008-03-27 14:22:00 +0100486};
487
488static const char *zfcp_rec_dbf_ids[] = {
Martin Peschke348447e2008-03-27 14:22:01 +0100489 [1] = "new",
490 [2] = "ready",
491 [3] = "kill",
492 [4] = "down sleep",
493 [5] = "down wakeup",
494 [6] = "down sleep ecd",
495 [7] = "down wakeup ecd",
496 [8] = "down sleep epd",
497 [9] = "down wakeup epd",
Martin Peschke698ec0162008-03-27 14:22:02 +0100498 [10] = "online",
499 [11] = "operational",
500 [12] = "scsi slave destroy",
501 [13] = "propagate failed adapter",
502 [14] = "propagate failed port",
503 [15] = "block adapter",
504 [16] = "unblock adapter",
505 [17] = "block port",
506 [18] = "unblock port",
507 [19] = "block unit",
508 [20] = "unblock unit",
509 [21] = "unit recovery failed",
510 [22] = "port recovery failed",
511 [23] = "adapter recovery failed",
512 [24] = "qdio queues down",
513 [25] = "p2p failed",
514 [26] = "nameserver lookup failed",
515 [27] = "nameserver port failed",
516 [28] = "link up",
517 [29] = "link down",
518 [30] = "link up status read",
519 [31] = "open port failed",
520 [32] = "open port failed",
521 [33] = "close port",
522 [34] = "open unit failed",
523 [35] = "exclusive open unit failed",
524 [36] = "shared open unit failed",
525 [37] = "link down",
526 [38] = "link down status read no link",
527 [39] = "link down status read fdisc login",
528 [40] = "link down status read firmware update",
529 [41] = "link down status read unknown reason",
530 [42] = "link down ecd incomplete",
531 [43] = "link down epd incomplete",
532 [44] = "sysfs adapter recovery",
533 [45] = "sysfs port recovery",
534 [46] = "sysfs unit recovery",
535 [47] = "port boxed abort",
536 [48] = "unit boxed abort",
537 [49] = "port boxed ct",
538 [50] = "port boxed close physical",
539 [51] = "port boxed open unit",
540 [52] = "port boxed close unit",
541 [53] = "port boxed fcp",
542 [54] = "unit boxed fcp",
Christof Schmitt553448f2008-06-10 18:20:58 +0200543 [55] = "port access denied",
544 [56] = "",
545 [57] = "",
546 [58] = "",
547 [59] = "unit access denied",
Martin Peschke698ec0162008-03-27 14:22:02 +0100548 [60] = "shared unit access denied open unit",
Christof Schmitt553448f2008-06-10 18:20:58 +0200549 [61] = "",
Martin Peschke9467a9b2008-03-27 14:22:03 +0100550 [62] = "request timeout",
551 [63] = "adisc link test reject or timeout",
552 [64] = "adisc link test d_id changed",
553 [65] = "adisc link test failed",
554 [66] = "recovery out of memory",
555 [67] = "adapter recovery repeated after state change",
556 [68] = "port recovery repeated after state change",
557 [69] = "unit recovery repeated after state change",
558 [70] = "port recovery follow-up after successful adapter recovery",
559 [71] = "adapter recovery escalation after failed adapter recovery",
560 [72] = "port recovery follow-up after successful physical port "
561 "recovery",
562 [73] = "adapter recovery escalation after failed physical port "
563 "recovery",
564 [74] = "unit recovery follow-up after successful port recovery",
565 [75] = "physical port recovery escalation after failed port "
566 "recovery",
567 [76] = "port recovery escalation after failed unit recovery",
Swen Schillig5ab944f2008-10-01 12:42:17 +0200568 [77] = "",
Martin Peschke9467a9b2008-03-27 14:22:03 +0100569 [78] = "duplicate request id",
570 [79] = "link down",
571 [80] = "exclusive read-only unit access unsupported",
572 [81] = "shared read-write unit access unsupported",
573 [82] = "incoming rscn",
Christof Schmitt24073b42008-06-10 18:20:54 +0200574 [83] = "incoming wwpn",
Swen Schillig41bfcf92008-10-01 12:42:26 +0200575 [84] = "wka port handle not valid close port",
Martin Peschke9467a9b2008-03-27 14:22:03 +0100576 [85] = "online",
577 [86] = "offline",
578 [87] = "ccw device gone",
579 [88] = "ccw device no path",
580 [89] = "ccw device operational",
581 [90] = "ccw device shutdown",
582 [91] = "sysfs port addition",
583 [92] = "sysfs port removal",
584 [93] = "sysfs adapter recovery",
585 [94] = "sysfs unit addition",
586 [95] = "sysfs unit removal",
587 [96] = "sysfs port recovery",
588 [97] = "sysfs unit recovery",
589 [98] = "sequence number mismatch",
590 [99] = "link up",
591 [100] = "error state",
592 [101] = "status read physical port closed",
593 [102] = "link up status read",
594 [103] = "too many failed status read buffers",
595 [104] = "port handle not valid abort",
596 [105] = "lun handle not valid abort",
597 [106] = "port handle not valid ct",
598 [107] = "port handle not valid close port",
599 [108] = "port handle not valid close physical port",
600 [109] = "port handle not valid open unit",
601 [110] = "port handle not valid close unit",
602 [111] = "lun handle not valid close unit",
603 [112] = "port handle not valid fcp",
604 [113] = "lun handle not valid fcp",
605 [114] = "handle mismatch fcp",
606 [115] = "lun not valid fcp",
607 [116] = "qdio send failed",
608 [117] = "version mismatch",
609 [118] = "incompatible qtcb type",
610 [119] = "unknown protocol status",
611 [120] = "unknown fsf command",
612 [121] = "no recommendation for status qualifier",
613 [122] = "status read physical port closed in error",
Christof Schmitt553448f2008-06-10 18:20:58 +0200614 [123] = "fc service class not supported",
615 [124] = "",
Martin Peschke9467a9b2008-03-27 14:22:03 +0100616 [125] = "need newer zfcp",
617 [126] = "need newer microcode",
618 [127] = "arbitrated loop not supported",
Christof Schmittff3b24f2008-10-01 12:42:15 +0200619 [128] = "",
Martin Peschke9467a9b2008-03-27 14:22:03 +0100620 [129] = "qtcb size mismatch",
621 [130] = "unknown fsf status ecd",
622 [131] = "fcp request too big",
Christof Schmitt553448f2008-06-10 18:20:58 +0200623 [132] = "",
Martin Peschke9467a9b2008-03-27 14:22:03 +0100624 [133] = "data direction not valid fcp",
625 [134] = "command length not valid fcp",
626 [135] = "status read act update",
627 [136] = "status read cfdc update",
628 [137] = "hbaapi port open",
629 [138] = "hbaapi unit open",
630 [139] = "hbaapi unit shutdown",
Swen Schillig00bab912008-06-10 18:20:57 +0200631 [140] = "qdio error outbound",
Martin Peschke9467a9b2008-03-27 14:22:03 +0100632 [141] = "scsi host reset",
Martin Peschke6f4f3652008-03-27 14:22:04 +0100633 [142] = "dismissing fsf request for recovery action",
634 [143] = "recovery action timed out",
635 [144] = "recovery action gone",
636 [145] = "recovery action being processed",
637 [146] = "recovery action ready for next step",
Swen Schillig00bab912008-06-10 18:20:57 +0200638 [147] = "qdio error inbound",
Swen Schilligcc8c2822008-06-10 18:21:00 +0200639 [148] = "nameserver needed for port scan",
640 [149] = "port scan",
641 [150] = "ptp attach",
642 [151] = "port validation failed",
Martin Peschked79a83d2008-03-27 14:22:00 +0100643};
644
645static int zfcp_rec_dbf_view_format(debug_info_t *id, struct debug_view *view,
646 char *buf, const char *_rec)
647{
648 struct zfcp_rec_dbf_record *r = (struct zfcp_rec_dbf_record *)_rec;
649 char *p = buf;
650
651 zfcp_dbf_outs(&p, "tag", zfcp_rec_dbf_tags[r->id]);
652 zfcp_dbf_outs(&p, "hint", zfcp_rec_dbf_ids[r->id2]);
653 zfcp_dbf_out(&p, "id", "%d", r->id2);
654 switch (r->id) {
Martin Peschke348447e2008-03-27 14:22:01 +0100655 case ZFCP_REC_DBF_ID_THREAD:
Martin Peschke348447e2008-03-27 14:22:01 +0100656 zfcp_dbf_out(&p, "total", "%d", r->u.thread.total);
657 zfcp_dbf_out(&p, "ready", "%d", r->u.thread.ready);
658 zfcp_dbf_out(&p, "running", "%d", r->u.thread.running);
659 break;
Martin Peschke698ec0162008-03-27 14:22:02 +0100660 case ZFCP_REC_DBF_ID_TARGET:
661 zfcp_dbf_out(&p, "reference", "0x%016Lx", r->u.target.ref);
662 zfcp_dbf_out(&p, "status", "0x%08x", r->u.target.status);
663 zfcp_dbf_out(&p, "erp_count", "%d", r->u.target.erp_count);
664 zfcp_dbf_out(&p, "d_id", "0x%06x", r->u.target.d_id);
665 zfcp_dbf_out(&p, "wwpn", "0x%016Lx", r->u.target.wwpn);
666 zfcp_dbf_out(&p, "fcp_lun", "0x%016Lx", r->u.target.fcp_lun);
667 break;
Martin Peschke9467a9b2008-03-27 14:22:03 +0100668 case ZFCP_REC_DBF_ID_TRIGGER:
669 zfcp_dbf_out(&p, "reference", "0x%016Lx", r->u.trigger.ref);
670 zfcp_dbf_out(&p, "erp_action", "0x%016Lx", r->u.trigger.action);
671 zfcp_dbf_out(&p, "requested", "%d", r->u.trigger.want);
672 zfcp_dbf_out(&p, "executed", "%d", r->u.trigger.need);
673 zfcp_dbf_out(&p, "wwpn", "0x%016Lx", r->u.trigger.wwpn);
674 zfcp_dbf_out(&p, "fcp_lun", "0x%016Lx", r->u.trigger.fcp_lun);
675 zfcp_dbf_out(&p, "adapter_status", "0x%08x", r->u.trigger.as);
676 zfcp_dbf_out(&p, "port_status", "0x%08x", r->u.trigger.ps);
677 zfcp_dbf_out(&p, "unit_status", "0x%08x", r->u.trigger.us);
678 break;
Martin Peschke6f4f3652008-03-27 14:22:04 +0100679 case ZFCP_REC_DBF_ID_ACTION:
680 zfcp_dbf_out(&p, "erp_action", "0x%016Lx", r->u.action.action);
681 zfcp_dbf_out(&p, "fsf_req", "0x%016Lx", r->u.action.fsf_req);
682 zfcp_dbf_out(&p, "status", "0x%08Lx", r->u.action.status);
683 zfcp_dbf_out(&p, "step", "0x%08Lx", r->u.action.step);
684 break;
Martin Peschked79a83d2008-03-27 14:22:00 +0100685 }
Martin Peschkeb634fff2008-03-31 11:15:24 +0200686 p += sprintf(p, "\n");
687 return p - buf;
Martin Peschked79a83d2008-03-27 14:22:00 +0100688}
689
690static struct debug_view zfcp_rec_dbf_view = {
691 "structured",
692 NULL,
693 &zfcp_dbf_view_header,
694 &zfcp_rec_dbf_view_format,
695 NULL,
696 NULL
697};
698
Martin Peschke348447e2008-03-27 14:22:01 +0100699/**
700 * zfcp_rec_dbf_event_thread - trace event related to recovery thread operation
701 * @id2: identifier for event
702 * @adapter: adapter
Christof Schmittaa0fec62008-05-19 12:17:47 +0200703 * This function assumes that the caller is holding erp_lock.
Martin Peschke348447e2008-03-27 14:22:01 +0100704 */
Christof Schmittaa0fec62008-05-19 12:17:47 +0200705void zfcp_rec_dbf_event_thread(u8 id2, struct zfcp_adapter *adapter)
Martin Peschke348447e2008-03-27 14:22:01 +0100706{
707 struct zfcp_rec_dbf_record *r = &adapter->rec_dbf_buf;
708 unsigned long flags = 0;
709 struct list_head *entry;
710 unsigned ready = 0, running = 0, total;
711
Martin Peschke348447e2008-03-27 14:22:01 +0100712 list_for_each(entry, &adapter->erp_ready_head)
713 ready++;
714 list_for_each(entry, &adapter->erp_running_head)
715 running++;
716 total = adapter->erp_total_count;
Martin Peschke348447e2008-03-27 14:22:01 +0100717
718 spin_lock_irqsave(&adapter->rec_dbf_lock, flags);
719 memset(r, 0, sizeof(*r));
720 r->id = ZFCP_REC_DBF_ID_THREAD;
721 r->id2 = id2;
Martin Peschke348447e2008-03-27 14:22:01 +0100722 r->u.thread.total = total;
723 r->u.thread.ready = ready;
724 r->u.thread.running = running;
Martin Peschke70c66542008-05-19 12:17:45 +0200725 debug_event(adapter->rec_dbf, 6, r, sizeof(*r));
Martin Peschke348447e2008-03-27 14:22:01 +0100726 spin_unlock_irqrestore(&adapter->rec_dbf_lock, flags);
727}
728
Christof Schmittaa0fec62008-05-19 12:17:47 +0200729/**
730 * zfcp_rec_dbf_event_thread - trace event related to recovery thread operation
731 * @id2: identifier for event
732 * @adapter: adapter
733 * This function assumes that the caller does not hold erp_lock.
734 */
735void zfcp_rec_dbf_event_thread_lock(u8 id2, struct zfcp_adapter *adapter)
736{
737 unsigned long flags;
738
739 read_lock_irqsave(&adapter->erp_lock, flags);
740 zfcp_rec_dbf_event_thread(id2, adapter);
741 read_unlock_irqrestore(&adapter->erp_lock, flags);
742}
743
Martin Peschke1f6f7122008-04-18 12:51:55 +0200744static void zfcp_rec_dbf_event_target(u8 id2, void *ref,
Martin Peschke698ec0162008-03-27 14:22:02 +0100745 struct zfcp_adapter *adapter,
746 atomic_t *status, atomic_t *erp_count,
747 u64 wwpn, u32 d_id, u64 fcp_lun)
748{
749 struct zfcp_rec_dbf_record *r = &adapter->rec_dbf_buf;
750 unsigned long flags;
751
752 spin_lock_irqsave(&adapter->rec_dbf_lock, flags);
753 memset(r, 0, sizeof(*r));
754 r->id = ZFCP_REC_DBF_ID_TARGET;
755 r->id2 = id2;
Martin Peschke1f6f7122008-04-18 12:51:55 +0200756 r->u.target.ref = (unsigned long)ref;
Martin Peschke698ec0162008-03-27 14:22:02 +0100757 r->u.target.status = atomic_read(status);
758 r->u.target.wwpn = wwpn;
759 r->u.target.d_id = d_id;
760 r->u.target.fcp_lun = fcp_lun;
761 r->u.target.erp_count = atomic_read(erp_count);
762 debug_event(adapter->rec_dbf, 3, r, sizeof(*r));
763 spin_unlock_irqrestore(&adapter->rec_dbf_lock, flags);
764}
765
766/**
767 * zfcp_rec_dbf_event_adapter - trace event for adapter state change
768 * @id: identifier for trigger of state change
769 * @ref: additional reference (e.g. request)
770 * @adapter: adapter
771 */
Martin Peschke1f6f7122008-04-18 12:51:55 +0200772void zfcp_rec_dbf_event_adapter(u8 id, void *ref, struct zfcp_adapter *adapter)
Martin Peschke698ec0162008-03-27 14:22:02 +0100773{
774 zfcp_rec_dbf_event_target(id, ref, adapter, &adapter->status,
775 &adapter->erp_counter, 0, 0, 0);
776}
777
778/**
779 * zfcp_rec_dbf_event_port - trace event for port state change
780 * @id: identifier for trigger of state change
781 * @ref: additional reference (e.g. request)
782 * @port: port
783 */
Martin Peschke1f6f7122008-04-18 12:51:55 +0200784void zfcp_rec_dbf_event_port(u8 id, void *ref, struct zfcp_port *port)
Martin Peschke698ec0162008-03-27 14:22:02 +0100785{
786 struct zfcp_adapter *adapter = port->adapter;
787
788 zfcp_rec_dbf_event_target(id, ref, adapter, &port->status,
789 &port->erp_counter, port->wwpn, port->d_id,
790 0);
791}
792
793/**
794 * zfcp_rec_dbf_event_unit - trace event for unit state change
795 * @id: identifier for trigger of state change
796 * @ref: additional reference (e.g. request)
797 * @unit: unit
798 */
Martin Peschke1f6f7122008-04-18 12:51:55 +0200799void zfcp_rec_dbf_event_unit(u8 id, void *ref, struct zfcp_unit *unit)
Martin Peschke698ec0162008-03-27 14:22:02 +0100800{
801 struct zfcp_port *port = unit->port;
802 struct zfcp_adapter *adapter = port->adapter;
803
804 zfcp_rec_dbf_event_target(id, ref, adapter, &unit->status,
805 &unit->erp_counter, port->wwpn, port->d_id,
806 unit->fcp_lun);
807}
808
Martin Peschke9467a9b2008-03-27 14:22:03 +0100809/**
810 * zfcp_rec_dbf_event_trigger - trace event for triggered error recovery
811 * @id2: identifier for error recovery trigger
812 * @ref: additional reference (e.g. request)
813 * @want: originally requested error recovery action
814 * @need: error recovery action actually initiated
815 * @action: address of error recovery action struct
816 * @adapter: adapter
817 * @port: port
818 * @unit: unit
819 */
Martin Peschke1f6f7122008-04-18 12:51:55 +0200820void zfcp_rec_dbf_event_trigger(u8 id2, void *ref, u8 want, u8 need,
821 void *action, struct zfcp_adapter *adapter,
Martin Peschke9467a9b2008-03-27 14:22:03 +0100822 struct zfcp_port *port, struct zfcp_unit *unit)
823{
824 struct zfcp_rec_dbf_record *r = &adapter->rec_dbf_buf;
825 unsigned long flags;
826
827 spin_lock_irqsave(&adapter->rec_dbf_lock, flags);
828 memset(r, 0, sizeof(*r));
829 r->id = ZFCP_REC_DBF_ID_TRIGGER;
830 r->id2 = id2;
Martin Peschke1f6f7122008-04-18 12:51:55 +0200831 r->u.trigger.ref = (unsigned long)ref;
Martin Peschke9467a9b2008-03-27 14:22:03 +0100832 r->u.trigger.want = want;
833 r->u.trigger.need = need;
Martin Peschke1f6f7122008-04-18 12:51:55 +0200834 r->u.trigger.action = (unsigned long)action;
Martin Peschke9467a9b2008-03-27 14:22:03 +0100835 r->u.trigger.as = atomic_read(&adapter->status);
836 if (port) {
837 r->u.trigger.ps = atomic_read(&port->status);
838 r->u.trigger.wwpn = port->wwpn;
839 }
840 if (unit) {
841 r->u.trigger.us = atomic_read(&unit->status);
842 r->u.trigger.fcp_lun = unit->fcp_lun;
843 }
844 debug_event(adapter->rec_dbf, action ? 1 : 4, r, sizeof(*r));
845 spin_unlock_irqrestore(&adapter->rec_dbf_lock, flags);
846}
847
Martin Peschke6f4f3652008-03-27 14:22:04 +0100848/**
849 * zfcp_rec_dbf_event_action - trace event showing progress of recovery action
850 * @id2: identifier
851 * @erp_action: error recovery action struct pointer
852 */
853void zfcp_rec_dbf_event_action(u8 id2, struct zfcp_erp_action *erp_action)
854{
855 struct zfcp_adapter *adapter = erp_action->adapter;
856 struct zfcp_rec_dbf_record *r = &adapter->rec_dbf_buf;
857 unsigned long flags;
858
859 spin_lock_irqsave(&adapter->rec_dbf_lock, flags);
860 memset(r, 0, sizeof(*r));
861 r->id = ZFCP_REC_DBF_ID_ACTION;
862 r->id2 = id2;
Martin Peschke1f6f7122008-04-18 12:51:55 +0200863 r->u.action.action = (unsigned long)erp_action;
Martin Peschke6f4f3652008-03-27 14:22:04 +0100864 r->u.action.status = erp_action->status;
865 r->u.action.step = erp_action->step;
Martin Peschke1f6f7122008-04-18 12:51:55 +0200866 r->u.action.fsf_req = (unsigned long)erp_action->fsf_req;
Martin Peschke70c66542008-05-19 12:17:45 +0200867 debug_event(adapter->rec_dbf, 5, r, sizeof(*r));
Martin Peschke6f4f3652008-03-27 14:22:04 +0100868 spin_unlock_irqrestore(&adapter->rec_dbf_lock, flags);
869}
870
Martin Peschkebfab1632008-03-31 11:15:31 +0200871/**
872 * zfcp_san_dbf_event_ct_request - trace event for issued CT request
873 * @fsf_req: request containing issued CT data
874 */
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100875void zfcp_san_dbf_event_ct_request(struct zfcp_fsf_req *fsf_req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200876{
877 struct zfcp_send_ct *ct = (struct zfcp_send_ct *)fsf_req->data;
Swen Schillig5ab944f2008-10-01 12:42:17 +0200878 struct zfcp_wka_port *wka_port = ct->wka_port;
879 struct zfcp_adapter *adapter = wka_port->adapter;
Swen Schillig44cc76f2008-10-01 12:42:16 +0200880 struct ct_hdr *hdr = sg_virt(ct->req);
Martin Peschke6bc473d2008-03-31 11:15:29 +0200881 struct zfcp_san_dbf_record *r = &adapter->san_dbf_buf;
882 struct zfcp_san_dbf_record_ct_request *oct = &r->u.ct_req;
883 unsigned long flags;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200884
Martin Peschke6bc473d2008-03-31 11:15:29 +0200885 spin_lock_irqsave(&adapter->san_dbf_lock, flags);
886 memset(r, 0, sizeof(*r));
887 strncpy(r->tag, "octc", ZFCP_DBF_TAG_SIZE);
888 r->fsf_reqid = (unsigned long)fsf_req;
889 r->fsf_seqno = fsf_req->seq_no;
890 r->s_id = fc_host_port_id(adapter->scsi_host);
Swen Schillig5ab944f2008-10-01 12:42:17 +0200891 r->d_id = wka_port->d_id;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200892 oct->cmd_req_code = hdr->cmd_rsp_code;
893 oct->revision = hdr->revision;
894 oct->gs_type = hdr->gs_type;
895 oct->gs_subtype = hdr->gs_subtype;
896 oct->options = hdr->options;
897 oct->max_res_size = hdr->max_res_size;
898 oct->len = min((int)ct->req->length - (int)sizeof(struct ct_hdr),
899 ZFCP_DBF_CT_PAYLOAD);
900 memcpy(oct->payload, (void *)hdr + sizeof(struct ct_hdr), oct->len);
901 debug_event(adapter->san_dbf, 3, r, sizeof(*r));
902 spin_unlock_irqrestore(&adapter->san_dbf_lock, flags);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200903}
904
Martin Peschkebfab1632008-03-31 11:15:31 +0200905/**
906 * zfcp_san_dbf_event_ct_response - trace event for completion of CT request
907 * @fsf_req: request containing CT response
908 */
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100909void zfcp_san_dbf_event_ct_response(struct zfcp_fsf_req *fsf_req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200910{
911 struct zfcp_send_ct *ct = (struct zfcp_send_ct *)fsf_req->data;
Swen Schillig5ab944f2008-10-01 12:42:17 +0200912 struct zfcp_wka_port *wka_port = ct->wka_port;
913 struct zfcp_adapter *adapter = wka_port->adapter;
Swen Schillig44cc76f2008-10-01 12:42:16 +0200914 struct ct_hdr *hdr = sg_virt(ct->resp);
Martin Peschke6bc473d2008-03-31 11:15:29 +0200915 struct zfcp_san_dbf_record *r = &adapter->san_dbf_buf;
916 struct zfcp_san_dbf_record_ct_response *rct = &r->u.ct_resp;
917 unsigned long flags;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200918
Martin Peschke6bc473d2008-03-31 11:15:29 +0200919 spin_lock_irqsave(&adapter->san_dbf_lock, flags);
920 memset(r, 0, sizeof(*r));
921 strncpy(r->tag, "rctc", ZFCP_DBF_TAG_SIZE);
922 r->fsf_reqid = (unsigned long)fsf_req;
923 r->fsf_seqno = fsf_req->seq_no;
Swen Schillig5ab944f2008-10-01 12:42:17 +0200924 r->s_id = wka_port->d_id;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200925 r->d_id = fc_host_port_id(adapter->scsi_host);
926 rct->cmd_rsp_code = hdr->cmd_rsp_code;
927 rct->revision = hdr->revision;
928 rct->reason_code = hdr->reason_code;
929 rct->expl = hdr->reason_code_expl;
930 rct->vendor_unique = hdr->vendor_unique;
931 rct->len = min((int)ct->resp->length - (int)sizeof(struct ct_hdr),
932 ZFCP_DBF_CT_PAYLOAD);
933 memcpy(rct->payload, (void *)hdr + sizeof(struct ct_hdr), rct->len);
934 debug_event(adapter->san_dbf, 3, r, sizeof(*r));
935 spin_unlock_irqrestore(&adapter->san_dbf_lock, flags);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200936}
937
Martin Peschke92c7a832008-03-31 11:15:30 +0200938static void zfcp_san_dbf_event_els(const char *tag, int level,
939 struct zfcp_fsf_req *fsf_req, u32 s_id,
940 u32 d_id, u8 ls_code, void *buffer,
941 int buflen)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200942{
943 struct zfcp_adapter *adapter = fsf_req->adapter;
944 struct zfcp_san_dbf_record *rec = &adapter->san_dbf_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200945 unsigned long flags;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200946
947 spin_lock_irqsave(&adapter->san_dbf_lock, flags);
Martin Peschke6bc473d2008-03-31 11:15:29 +0200948 memset(rec, 0, sizeof(*rec));
Martin Peschke0f65e952008-03-27 14:21:56 +0100949 strncpy(rec->tag, tag, ZFCP_DBF_TAG_SIZE);
950 rec->fsf_reqid = (unsigned long)fsf_req;
951 rec->fsf_seqno = fsf_req->seq_no;
952 rec->s_id = s_id;
953 rec->d_id = d_id;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200954 rec->u.els.ls_code = ls_code;
Martin Peschke0f65e952008-03-27 14:21:56 +0100955 debug_event(adapter->san_dbf, level, rec, sizeof(*rec));
956 zfcp_dbf_hexdump(adapter->san_dbf, rec, sizeof(*rec), level,
957 buffer, min(buflen, ZFCP_DBF_ELS_MAX_PAYLOAD));
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200958 spin_unlock_irqrestore(&adapter->san_dbf_lock, flags);
959}
960
Martin Peschkebfab1632008-03-31 11:15:31 +0200961/**
962 * zfcp_san_dbf_event_els_request - trace event for issued ELS
963 * @fsf_req: request containing issued ELS
964 */
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100965void zfcp_san_dbf_event_els_request(struct zfcp_fsf_req *fsf_req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200966{
967 struct zfcp_send_els *els = (struct zfcp_send_els *)fsf_req->data;
968
Martin Peschke92c7a832008-03-31 11:15:30 +0200969 zfcp_san_dbf_event_els("oels", 2, fsf_req,
970 fc_host_port_id(els->adapter->scsi_host),
Swen Schillig44cc76f2008-10-01 12:42:16 +0200971 els->d_id, *(u8 *) sg_virt(els->req),
972 sg_virt(els->req), els->req->length);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200973}
974
Martin Peschkebfab1632008-03-31 11:15:31 +0200975/**
976 * zfcp_san_dbf_event_els_response - trace event for completed ELS
977 * @fsf_req: request containing ELS response
978 */
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100979void zfcp_san_dbf_event_els_response(struct zfcp_fsf_req *fsf_req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200980{
981 struct zfcp_send_els *els = (struct zfcp_send_els *)fsf_req->data;
982
Martin Peschke92c7a832008-03-31 11:15:30 +0200983 zfcp_san_dbf_event_els("rels", 2, fsf_req, els->d_id,
984 fc_host_port_id(els->adapter->scsi_host),
Swen Schillig44cc76f2008-10-01 12:42:16 +0200985 *(u8 *)sg_virt(els->req), sg_virt(els->resp),
Martin Peschke92c7a832008-03-31 11:15:30 +0200986 els->resp->length);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200987}
988
Martin Peschkebfab1632008-03-31 11:15:31 +0200989/**
990 * zfcp_san_dbf_event_incoming_els - trace event for incomig ELS
991 * @fsf_req: request containing unsolicited status buffer with incoming ELS
992 */
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100993void zfcp_san_dbf_event_incoming_els(struct zfcp_fsf_req *fsf_req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200994{
995 struct zfcp_adapter *adapter = fsf_req->adapter;
Martin Peschke92c7a832008-03-31 11:15:30 +0200996 struct fsf_status_read_buffer *buf =
997 (struct fsf_status_read_buffer *)fsf_req->data;
998 int length = (int)buf->length -
999 (int)((void *)&buf->payload - (void *)buf);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001000
Martin Peschke92c7a832008-03-31 11:15:30 +02001001 zfcp_san_dbf_event_els("iels", 1, fsf_req, buf->d_id,
1002 fc_host_port_id(adapter->scsi_host),
Swen Schilligc41f8cb2008-07-02 10:56:39 +02001003 buf->payload.data[0], (void *)buf->payload.data,
Martin Peschke92c7a832008-03-31 11:15:30 +02001004 length);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001005}
1006
Martin Peschke92c7a832008-03-31 11:15:30 +02001007static int zfcp_san_dbf_view_format(debug_info_t *id, struct debug_view *view,
1008 char *out_buf, const char *in_buf)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001009{
Martin Peschkeb634fff2008-03-31 11:15:24 +02001010 struct zfcp_san_dbf_record *r = (struct zfcp_san_dbf_record *)in_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001011 char *buffer = NULL;
1012 int buflen = 0, total = 0;
Martin Peschkeb634fff2008-03-31 11:15:24 +02001013 char *p = out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001014
Martin Peschkeb634fff2008-03-31 11:15:24 +02001015 if (strncmp(r->tag, "dump", ZFCP_DBF_TAG_SIZE) == 0)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001016 return 0;
1017
Martin Peschkea9c85772008-03-31 11:15:27 +02001018 zfcp_dbf_tag(&p, "tag", r->tag);
Martin Peschkeb634fff2008-03-31 11:15:24 +02001019 zfcp_dbf_out(&p, "fsf_reqid", "0x%0Lx", r->fsf_reqid);
1020 zfcp_dbf_out(&p, "fsf_seqno", "0x%08x", r->fsf_seqno);
1021 zfcp_dbf_out(&p, "s_id", "0x%06x", r->s_id);
1022 zfcp_dbf_out(&p, "d_id", "0x%06x", r->d_id);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001023
Martin Peschkeb634fff2008-03-31 11:15:24 +02001024 if (strncmp(r->tag, "octc", ZFCP_DBF_TAG_SIZE) == 0) {
Martin Peschke6bc473d2008-03-31 11:15:29 +02001025 struct zfcp_san_dbf_record_ct_request *ct = &r->u.ct_req;
1026 zfcp_dbf_out(&p, "cmd_req_code", "0x%04x", ct->cmd_req_code);
1027 zfcp_dbf_out(&p, "revision", "0x%02x", ct->revision);
1028 zfcp_dbf_out(&p, "gs_type", "0x%02x", ct->gs_type);
1029 zfcp_dbf_out(&p, "gs_subtype", "0x%02x", ct->gs_subtype);
1030 zfcp_dbf_out(&p, "options", "0x%02x", ct->options);
1031 zfcp_dbf_out(&p, "max_res_size", "0x%04x", ct->max_res_size);
1032 total = ct->len;
1033 buffer = ct->payload;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001034 buflen = min(total, ZFCP_DBF_CT_PAYLOAD);
Martin Peschkeb634fff2008-03-31 11:15:24 +02001035 } else if (strncmp(r->tag, "rctc", ZFCP_DBF_TAG_SIZE) == 0) {
Martin Peschke6bc473d2008-03-31 11:15:29 +02001036 struct zfcp_san_dbf_record_ct_response *ct = &r->u.ct_resp;
1037 zfcp_dbf_out(&p, "cmd_rsp_code", "0x%04x", ct->cmd_rsp_code);
1038 zfcp_dbf_out(&p, "revision", "0x%02x", ct->revision);
1039 zfcp_dbf_out(&p, "reason_code", "0x%02x", ct->reason_code);
1040 zfcp_dbf_out(&p, "reason_code_expl", "0x%02x", ct->expl);
1041 zfcp_dbf_out(&p, "vendor_unique", "0x%02x", ct->vendor_unique);
1042 total = ct->len;
1043 buffer = ct->payload;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001044 buflen = min(total, ZFCP_DBF_CT_PAYLOAD);
Martin Peschkeb634fff2008-03-31 11:15:24 +02001045 } else if (strncmp(r->tag, "oels", ZFCP_DBF_TAG_SIZE) == 0 ||
1046 strncmp(r->tag, "rels", ZFCP_DBF_TAG_SIZE) == 0 ||
1047 strncmp(r->tag, "iels", ZFCP_DBF_TAG_SIZE) == 0) {
Martin Peschke6bc473d2008-03-31 11:15:29 +02001048 struct zfcp_san_dbf_record_els *els = &r->u.els;
1049 zfcp_dbf_out(&p, "ls_code", "0x%02x", els->ls_code);
1050 total = els->len;
1051 buffer = els->payload;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001052 buflen = min(total, ZFCP_DBF_ELS_PAYLOAD);
1053 }
1054
Martin Peschkedf29f4a2008-03-31 11:15:26 +02001055 zfcp_dbf_outd(&p, "payload", buffer, buflen, 0, total);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001056 if (buflen == total)
Martin Peschkeb634fff2008-03-31 11:15:24 +02001057 p += sprintf(p, "\n");
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001058
Martin Peschkeb634fff2008-03-31 11:15:24 +02001059 return p - out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001060}
1061
Heiko Carstens2b67fc42007-02-05 21:16:47 +01001062static struct debug_view zfcp_san_dbf_view = {
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001063 "structured",
1064 NULL,
1065 &zfcp_dbf_view_header,
1066 &zfcp_san_dbf_view_format,
1067 NULL,
1068 NULL
1069};
1070
Martin Peschke92c7a832008-03-31 11:15:30 +02001071static void zfcp_scsi_dbf_event(const char *tag, const char *tag2, int level,
1072 struct zfcp_adapter *adapter,
1073 struct scsi_cmnd *scsi_cmnd,
1074 struct zfcp_fsf_req *fsf_req,
1075 unsigned long old_req_id)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001076{
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001077 struct zfcp_scsi_dbf_record *rec = &adapter->scsi_dbf_buf;
1078 struct zfcp_dbf_dump *dump = (struct zfcp_dbf_dump *)rec;
1079 unsigned long flags;
1080 struct fcp_rsp_iu *fcp_rsp;
1081 char *fcp_rsp_info = NULL, *fcp_sns_info = NULL;
1082 int offset = 0, buflen = 0;
1083
1084 spin_lock_irqsave(&adapter->scsi_dbf_lock, flags);
1085 do {
Martin Peschke6bc473d2008-03-31 11:15:29 +02001086 memset(rec, 0, sizeof(*rec));
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001087 if (offset == 0) {
1088 strncpy(rec->tag, tag, ZFCP_DBF_TAG_SIZE);
1089 strncpy(rec->tag2, tag2, ZFCP_DBF_TAG_SIZE);
Maxim Shchetynined829ad2006-02-11 01:42:58 +01001090 if (scsi_cmnd != NULL) {
1091 if (scsi_cmnd->device) {
1092 rec->scsi_id = scsi_cmnd->device->id;
1093 rec->scsi_lun = scsi_cmnd->device->lun;
1094 }
1095 rec->scsi_result = scsi_cmnd->result;
1096 rec->scsi_cmnd = (unsigned long)scsi_cmnd;
1097 rec->scsi_serial = scsi_cmnd->serial_number;
Boaz Harrosh64a87b22008-04-30 11:19:47 +03001098 memcpy(rec->scsi_opcode, scsi_cmnd->cmnd,
Maxim Shchetynined829ad2006-02-11 01:42:58 +01001099 min((int)scsi_cmnd->cmd_len,
1100 ZFCP_DBF_SCSI_OPCODE));
1101 rec->scsi_retries = scsi_cmnd->retries;
1102 rec->scsi_allowed = scsi_cmnd->allowed;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001103 }
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001104 if (fsf_req != NULL) {
1105 fcp_rsp = (struct fcp_rsp_iu *)
1106 &(fsf_req->qtcb->bottom.io.fcp_rsp);
Martin Petermannf76af7d72008-07-02 10:56:36 +02001107 fcp_rsp_info = (unsigned char *) &fcp_rsp[1];
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001108 fcp_sns_info =
1109 zfcp_get_fcp_sns_info_ptr(fcp_rsp);
1110
Martin Peschke6bc473d2008-03-31 11:15:29 +02001111 rec->rsp_validity = fcp_rsp->validity.value;
1112 rec->rsp_scsi_status = fcp_rsp->scsi_status;
1113 rec->rsp_resid = fcp_rsp->fcp_resid;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001114 if (fcp_rsp->validity.bits.fcp_rsp_len_valid)
Martin Peschke6bc473d2008-03-31 11:15:29 +02001115 rec->rsp_code = *(fcp_rsp_info + 3);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001116 if (fcp_rsp->validity.bits.fcp_sns_len_valid) {
1117 buflen = min((int)fcp_rsp->fcp_sns_len,
1118 ZFCP_DBF_SCSI_MAX_FCP_SNS_INFO);
Martin Peschke6bc473d2008-03-31 11:15:29 +02001119 rec->sns_info_len = buflen;
1120 memcpy(rec->sns_info, fcp_sns_info,
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001121 min(buflen,
1122 ZFCP_DBF_SCSI_FCP_SNS_INFO));
1123 offset += min(buflen,
1124 ZFCP_DBF_SCSI_FCP_SNS_INFO);
1125 }
1126
1127 rec->fsf_reqid = (unsigned long)fsf_req;
1128 rec->fsf_seqno = fsf_req->seq_no;
1129 rec->fsf_issued = fsf_req->issued;
1130 }
Martin Peschke6bc473d2008-03-31 11:15:29 +02001131 rec->old_fsf_reqid = old_req_id;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001132 } else {
1133 strncpy(dump->tag, "dump", ZFCP_DBF_TAG_SIZE);
1134 dump->total_size = buflen;
1135 dump->offset = offset;
1136 dump->size = min(buflen - offset,
1137 (int)sizeof(struct
1138 zfcp_scsi_dbf_record) -
1139 (int)sizeof(struct zfcp_dbf_dump));
1140 memcpy(dump->data, fcp_sns_info + offset, dump->size);
1141 offset += dump->size;
1142 }
Martin Peschke6bc473d2008-03-31 11:15:29 +02001143 debug_event(adapter->scsi_dbf, level, rec, sizeof(*rec));
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001144 } while (offset < buflen);
1145 spin_unlock_irqrestore(&adapter->scsi_dbf_lock, flags);
1146}
1147
Martin Peschkebfab1632008-03-31 11:15:31 +02001148/**
1149 * zfcp_scsi_dbf_event_result - trace event for SCSI command completion
1150 * @tag: tag indicating success or failure of SCSI command
1151 * @level: trace level applicable for this event
1152 * @adapter: adapter that has been used to issue the SCSI command
1153 * @scsi_cmnd: SCSI command pointer
1154 * @fsf_req: request used to issue SCSI command (might be NULL)
1155 */
Martin Peschke92c7a832008-03-31 11:15:30 +02001156void zfcp_scsi_dbf_event_result(const char *tag, int level,
1157 struct zfcp_adapter *adapter,
1158 struct scsi_cmnd *scsi_cmnd,
1159 struct zfcp_fsf_req *fsf_req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001160{
Martin Peschke92c7a832008-03-31 11:15:30 +02001161 zfcp_scsi_dbf_event("rslt", tag, level, adapter, scsi_cmnd, fsf_req, 0);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001162}
1163
Martin Peschkebfab1632008-03-31 11:15:31 +02001164/**
1165 * zfcp_scsi_dbf_event_abort - trace event for SCSI command abort
1166 * @tag: tag indicating success or failure of abort operation
1167 * @adapter: adapter thas has been used to issue SCSI command to be aborted
1168 * @scsi_cmnd: SCSI command to be aborted
1169 * @new_fsf_req: request containing abort (might be NULL)
1170 * @old_req_id: identifier of request containg SCSI command to be aborted
1171 */
Martin Peschke92c7a832008-03-31 11:15:30 +02001172void zfcp_scsi_dbf_event_abort(const char *tag, struct zfcp_adapter *adapter,
1173 struct scsi_cmnd *scsi_cmnd,
1174 struct zfcp_fsf_req *new_fsf_req,
1175 unsigned long old_req_id)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001176{
Martin Peschke92c7a832008-03-31 11:15:30 +02001177 zfcp_scsi_dbf_event("abrt", tag, 1, adapter, scsi_cmnd, new_fsf_req,
1178 old_req_id);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001179}
1180
Martin Peschkebfab1632008-03-31 11:15:31 +02001181/**
1182 * zfcp_scsi_dbf_event_devreset - trace event for Logical Unit or Target Reset
1183 * @tag: tag indicating success or failure of reset operation
1184 * @flag: indicates type of reset (Target Reset, Logical Unit Reset)
1185 * @unit: unit that needs reset
1186 * @scsi_cmnd: SCSI command which caused this error recovery
1187 */
Martin Peschke92c7a832008-03-31 11:15:30 +02001188void zfcp_scsi_dbf_event_devreset(const char *tag, u8 flag,
1189 struct zfcp_unit *unit,
1190 struct scsi_cmnd *scsi_cmnd)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001191{
Martin Peschke92c7a832008-03-31 11:15:30 +02001192 zfcp_scsi_dbf_event(flag == FCP_TARGET_RESET ? "trst" : "lrst", tag, 1,
1193 unit->port->adapter, scsi_cmnd, NULL, 0);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001194}
1195
Martin Peschke92c7a832008-03-31 11:15:30 +02001196static int zfcp_scsi_dbf_view_format(debug_info_t *id, struct debug_view *view,
1197 char *out_buf, const char *in_buf)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001198{
Martin Peschkeb634fff2008-03-31 11:15:24 +02001199 struct zfcp_scsi_dbf_record *r = (struct zfcp_scsi_dbf_record *)in_buf;
Martin Peschke8fc5af12008-03-31 11:15:23 +02001200 struct timespec t;
Martin Peschkeb634fff2008-03-31 11:15:24 +02001201 char *p = out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001202
Martin Peschkeb634fff2008-03-31 11:15:24 +02001203 if (strncmp(r->tag, "dump", ZFCP_DBF_TAG_SIZE) == 0)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001204 return 0;
1205
Martin Peschkea9c85772008-03-31 11:15:27 +02001206 zfcp_dbf_tag(&p, "tag", r->tag);
1207 zfcp_dbf_tag(&p, "tag2", r->tag2);
Martin Peschkeb634fff2008-03-31 11:15:24 +02001208 zfcp_dbf_out(&p, "scsi_id", "0x%08x", r->scsi_id);
1209 zfcp_dbf_out(&p, "scsi_lun", "0x%08x", r->scsi_lun);
1210 zfcp_dbf_out(&p, "scsi_result", "0x%08x", r->scsi_result);
1211 zfcp_dbf_out(&p, "scsi_cmnd", "0x%0Lx", r->scsi_cmnd);
1212 zfcp_dbf_out(&p, "scsi_serial", "0x%016Lx", r->scsi_serial);
Martin Peschkedf29f4a2008-03-31 11:15:26 +02001213 zfcp_dbf_outd(&p, "scsi_opcode", r->scsi_opcode, ZFCP_DBF_SCSI_OPCODE,
1214 0, ZFCP_DBF_SCSI_OPCODE);
Martin Peschkeb634fff2008-03-31 11:15:24 +02001215 zfcp_dbf_out(&p, "scsi_retries", "0x%02x", r->scsi_retries);
1216 zfcp_dbf_out(&p, "scsi_allowed", "0x%02x", r->scsi_allowed);
1217 if (strncmp(r->tag, "abrt", ZFCP_DBF_TAG_SIZE) == 0)
Martin Peschke6bc473d2008-03-31 11:15:29 +02001218 zfcp_dbf_out(&p, "old_fsf_reqid", "0x%0Lx", r->old_fsf_reqid);
Martin Peschkeb634fff2008-03-31 11:15:24 +02001219 zfcp_dbf_out(&p, "fsf_reqid", "0x%0Lx", r->fsf_reqid);
1220 zfcp_dbf_out(&p, "fsf_seqno", "0x%08x", r->fsf_seqno);
1221 zfcp_dbf_timestamp(r->fsf_issued, &t);
1222 zfcp_dbf_out(&p, "fsf_issued", "%011lu:%06lu", t.tv_sec, t.tv_nsec);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001223
Martin Peschkeb634fff2008-03-31 11:15:24 +02001224 if (strncmp(r->tag, "rslt", ZFCP_DBF_TAG_SIZE) == 0) {
Martin Peschke6bc473d2008-03-31 11:15:29 +02001225 zfcp_dbf_out(&p, "fcp_rsp_validity", "0x%02x", r->rsp_validity);
1226 zfcp_dbf_out(&p, "fcp_rsp_scsi_status", "0x%02x",
1227 r->rsp_scsi_status);
1228 zfcp_dbf_out(&p, "fcp_rsp_resid", "0x%08x", r->rsp_resid);
1229 zfcp_dbf_out(&p, "fcp_rsp_code", "0x%08x", r->rsp_code);
1230 zfcp_dbf_out(&p, "fcp_sns_info_len", "0x%08x", r->sns_info_len);
1231 zfcp_dbf_outd(&p, "fcp_sns_info", r->sns_info,
1232 min((int)r->sns_info_len,
Martin Peschkedf29f4a2008-03-31 11:15:26 +02001233 ZFCP_DBF_SCSI_FCP_SNS_INFO), 0,
Martin Peschke6bc473d2008-03-31 11:15:29 +02001234 r->sns_info_len);
Martin Peschkeb634fff2008-03-31 11:15:24 +02001235 }
1236 p += sprintf(p, "\n");
1237 return p - out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001238}
1239
Heiko Carstens2b67fc42007-02-05 21:16:47 +01001240static struct debug_view zfcp_scsi_dbf_view = {
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001241 "structured",
1242 NULL,
1243 &zfcp_dbf_view_header,
1244 &zfcp_scsi_dbf_view_format,
1245 NULL,
1246 NULL
1247};
1248
1249/**
1250 * zfcp_adapter_debug_register - registers debug feature for an adapter
1251 * @adapter: pointer to adapter for which debug features should be registered
1252 * return: -ENOMEM on error, 0 otherwise
1253 */
1254int zfcp_adapter_debug_register(struct zfcp_adapter *adapter)
1255{
1256 char dbf_name[DEBUG_MAX_NAME_LEN];
1257
1258 /* debug feature area which records recovery activity */
Martin Peschked79a83d2008-03-27 14:22:00 +01001259 sprintf(dbf_name, "zfcp_%s_rec", zfcp_get_busid_by_adapter(adapter));
1260 adapter->rec_dbf = debug_register(dbf_name, dbfsize, 1,
1261 sizeof(struct zfcp_rec_dbf_record));
1262 if (!adapter->rec_dbf)
1263 goto failed;
1264 debug_register_view(adapter->rec_dbf, &debug_hex_ascii_view);
1265 debug_register_view(adapter->rec_dbf, &zfcp_rec_dbf_view);
1266 debug_set_level(adapter->rec_dbf, 3);
1267
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001268 /* debug feature area which records HBA (FSF and QDIO) conditions */
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001269 sprintf(dbf_name, "zfcp_%s_hba", zfcp_get_busid_by_adapter(adapter));
1270 adapter->hba_dbf = debug_register(dbf_name, dbfsize, 1,
1271 sizeof(struct zfcp_hba_dbf_record));
1272 if (!adapter->hba_dbf)
1273 goto failed;
1274 debug_register_view(adapter->hba_dbf, &debug_hex_ascii_view);
1275 debug_register_view(adapter->hba_dbf, &zfcp_hba_dbf_view);
1276 debug_set_level(adapter->hba_dbf, 3);
1277
1278 /* debug feature area which records SAN command failures and recovery */
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001279 sprintf(dbf_name, "zfcp_%s_san", zfcp_get_busid_by_adapter(adapter));
1280 adapter->san_dbf = debug_register(dbf_name, dbfsize, 1,
1281 sizeof(struct zfcp_san_dbf_record));
1282 if (!adapter->san_dbf)
1283 goto failed;
1284 debug_register_view(adapter->san_dbf, &debug_hex_ascii_view);
1285 debug_register_view(adapter->san_dbf, &zfcp_san_dbf_view);
1286 debug_set_level(adapter->san_dbf, 6);
1287
1288 /* debug feature area which records SCSI command failures and recovery */
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001289 sprintf(dbf_name, "zfcp_%s_scsi", zfcp_get_busid_by_adapter(adapter));
1290 adapter->scsi_dbf = debug_register(dbf_name, dbfsize, 1,
1291 sizeof(struct zfcp_scsi_dbf_record));
1292 if (!adapter->scsi_dbf)
1293 goto failed;
1294 debug_register_view(adapter->scsi_dbf, &debug_hex_ascii_view);
1295 debug_register_view(adapter->scsi_dbf, &zfcp_scsi_dbf_view);
1296 debug_set_level(adapter->scsi_dbf, 3);
1297
1298 return 0;
1299
1300 failed:
1301 zfcp_adapter_debug_unregister(adapter);
1302
1303 return -ENOMEM;
1304}
1305
1306/**
1307 * zfcp_adapter_debug_unregister - unregisters debug feature for an adapter
1308 * @adapter: pointer to adapter for which debug features should be unregistered
1309 */
1310void zfcp_adapter_debug_unregister(struct zfcp_adapter *adapter)
1311{
1312 debug_unregister(adapter->scsi_dbf);
1313 debug_unregister(adapter->san_dbf);
1314 debug_unregister(adapter->hba_dbf);
Martin Peschked79a83d2008-03-27 14:22:00 +01001315 debug_unregister(adapter->rec_dbf);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001316 adapter->scsi_dbf = NULL;
1317 adapter->san_dbf = NULL;
1318 adapter->hba_dbf = NULL;
Martin Peschked79a83d2008-03-27 14:22:00 +01001319 adapter->rec_dbf = NULL;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001320}