blob: 075852f6968c478d5920c9b5230470bf3e1c73d6 [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 Schmittd46f3842009-08-18 15:43:07 +02006 * Copyright IBM Corporation 2002, 2009
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02007 */
8
Christof Schmittecf39d42008-12-25 13:39:53 +01009#define KMSG_COMPONENT "zfcp"
10#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
11
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020012#include <linux/ctype.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090013#include <linux/slab.h>
Heiko Carstens364c8552007-10-12 16:11:35 +020014#include <asm/debug.h>
Christof Schmittd46f3842009-08-18 15:43:07 +020015#include "zfcp_dbf.h"
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020016#include "zfcp_ext.h"
Christof Schmittbd0072e2009-11-24 16:54:11 +010017#include "zfcp_fc.h"
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020018
19static u32 dbfsize = 4;
20
21module_param(dbfsize, uint, 0400);
22MODULE_PARM_DESC(dbfsize,
23 "number of pages for each debug feature area (default 4)");
24
Martin Peschkec15450e2008-03-27 14:21:55 +010025static void zfcp_dbf_hexdump(debug_info_t *dbf, void *to, int to_len,
26 int level, char *from, int from_len)
27{
28 int offset;
29 struct zfcp_dbf_dump *dump = to;
30 int room = to_len - sizeof(*dump);
31
32 for (offset = 0; offset < from_len; offset += dump->size) {
33 memset(to, 0, to_len);
34 strncpy(dump->tag, "dump", ZFCP_DBF_TAG_SIZE);
35 dump->total_size = from_len;
36 dump->offset = offset;
37 dump->size = min(from_len - offset, room);
38 memcpy(dump->data, from + offset, dump->size);
Christof Schmittd94ce6c2008-11-04 16:35:12 +010039 debug_event(dbf, level, dump, dump->size + sizeof(*dump));
Martin Peschkec15450e2008-03-27 14:21:55 +010040 }
41}
42
Martin Peschkea9c85772008-03-31 11:15:27 +020043static void zfcp_dbf_tag(char **p, const char *label, const char *tag)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020044{
Martin Peschkea9c85772008-03-31 11:15:27 +020045 int i;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020046
Martin Peschkea9c85772008-03-31 11:15:27 +020047 *p += sprintf(*p, "%-24s", label);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020048 for (i = 0; i < ZFCP_DBF_TAG_SIZE; i++)
Martin Peschkea9c85772008-03-31 11:15:27 +020049 *p += sprintf(*p, "%c", tag[i]);
50 *p += sprintf(*p, "\n");
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020051}
52
Martin Peschke10223c62008-03-27 14:21:59 +010053static void zfcp_dbf_outs(char **buf, const char *s1, const char *s2)
54{
55 *buf += sprintf(*buf, "%-24s%s\n", s1, s2);
56}
57
58static void zfcp_dbf_out(char **buf, const char *s, const char *format, ...)
59{
60 va_list arg;
61
62 *buf += sprintf(*buf, "%-24s", s);
63 va_start(arg, format);
64 *buf += vsprintf(*buf, format, arg);
65 va_end(arg);
66 *buf += sprintf(*buf, "\n");
67}
68
Martin Peschkedf29f4a2008-03-31 11:15:26 +020069static void zfcp_dbf_outd(char **p, const char *label, char *buffer,
70 int buflen, int offset, int total_size)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020071{
Martin Peschkedf29f4a2008-03-31 11:15:26 +020072 if (!offset)
73 *p += sprintf(*p, "%-24s ", label);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020074 while (buflen--) {
75 if (offset > 0) {
76 if ((offset % 32) == 0)
Martin Peschkedf29f4a2008-03-31 11:15:26 +020077 *p += sprintf(*p, "\n%-24c ", ' ');
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020078 else if ((offset % 4) == 0)
Martin Peschkedf29f4a2008-03-31 11:15:26 +020079 *p += sprintf(*p, " ");
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020080 }
Martin Peschkedf29f4a2008-03-31 11:15:26 +020081 *p += sprintf(*p, "%02x", *buffer++);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020082 if (++offset == total_size) {
Martin Peschkedf29f4a2008-03-31 11:15:26 +020083 *p += sprintf(*p, "\n");
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020084 break;
85 }
86 }
Martin Peschkedf29f4a2008-03-31 11:15:26 +020087 if (!total_size)
88 *p += sprintf(*p, "\n");
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020089}
90
Martin Peschke92c7a832008-03-31 11:15:30 +020091static int zfcp_dbf_view_header(debug_info_t *id, struct debug_view *view,
92 int area, debug_entry_t *entry, char *out_buf)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020093{
94 struct zfcp_dbf_dump *dump = (struct zfcp_dbf_dump *)DEBUG_DATA(entry);
Martin Peschke8fc5af12008-03-31 11:15:23 +020095 struct timespec t;
Martin Peschkeb634fff2008-03-31 11:15:24 +020096 char *p = out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020097
98 if (strncmp(dump->tag, "dump", ZFCP_DBF_TAG_SIZE) != 0) {
Christof Schmittb592e892009-08-18 15:43:31 +020099 stck_to_timespec(entry->id.stck, &t);
Martin Peschkeb634fff2008-03-31 11:15:24 +0200100 zfcp_dbf_out(&p, "timestamp", "%011lu:%06lu",
101 t.tv_sec, t.tv_nsec);
102 zfcp_dbf_out(&p, "cpu", "%02i", entry->id.fields.cpuid);
103 } else {
Christof Schmittd94ce6c2008-11-04 16:35:12 +0100104 zfcp_dbf_outd(&p, "", dump->data, dump->size, dump->offset,
Martin Peschkedf29f4a2008-03-31 11:15:26 +0200105 dump->total_size);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200106 if ((dump->offset + dump->size) == dump->total_size)
Martin Peschkeb634fff2008-03-31 11:15:24 +0200107 p += sprintf(p, "\n");
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200108 }
Martin Peschkeb634fff2008-03-31 11:15:24 +0200109 return p - out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200110}
111
Swen Schillig57717102009-08-18 15:43:21 +0200112void _zfcp_dbf_hba_fsf_response(const char *tag2, int level,
113 struct zfcp_fsf_req *fsf_req,
114 struct zfcp_dbf *dbf)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200115{
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200116 struct fsf_qtcb *qtcb = fsf_req->qtcb;
117 union fsf_prot_status_qual *prot_status_qual =
Martin Peschke92c7a832008-03-31 11:15:30 +0200118 &qtcb->prefix.prot_status_qual;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200119 union fsf_status_qual *fsf_status_qual = &qtcb->header.fsf_status_qual;
120 struct scsi_cmnd *scsi_cmnd;
121 struct zfcp_port *port;
122 struct zfcp_unit *unit;
123 struct zfcp_send_els *send_els;
Swen Schillig57717102009-08-18 15:43:21 +0200124 struct zfcp_dbf_hba_record *rec = &dbf->hba_buf;
125 struct zfcp_dbf_hba_record_response *response = &rec->u.response;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200126 unsigned long flags;
127
Swen Schillig57717102009-08-18 15:43:21 +0200128 spin_lock_irqsave(&dbf->hba_lock, flags);
Martin Peschke6bc473d2008-03-31 11:15:29 +0200129 memset(rec, 0, sizeof(*rec));
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200130 strncpy(rec->tag, "resp", ZFCP_DBF_TAG_SIZE);
Christof Schmitt2e261af2009-08-18 15:43:09 +0200131 strncpy(rec->tag2, tag2, ZFCP_DBF_TAG_SIZE);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200132
133 response->fsf_command = fsf_req->fsf_command;
Christof Schmittf0216ae2009-05-15 13:18:14 +0200134 response->fsf_reqid = fsf_req->req_id;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200135 response->fsf_seqno = fsf_req->seq_no;
136 response->fsf_issued = fsf_req->issued;
137 response->fsf_prot_status = qtcb->prefix.prot_status;
138 response->fsf_status = qtcb->header.fsf_status;
139 memcpy(response->fsf_prot_status_qual,
140 prot_status_qual, FSF_PROT_STATUS_QUAL_SIZE);
141 memcpy(response->fsf_status_qual,
142 fsf_status_qual, FSF_STATUS_QUALIFIER_SIZE);
143 response->fsf_req_status = fsf_req->status;
Christof Schmitt34c2b712010-02-17 11:18:59 +0100144 response->sbal_first = fsf_req->qdio_req.sbal_first;
145 response->sbal_last = fsf_req->qdio_req.sbal_last;
146 response->sbal_response = fsf_req->qdio_req.sbal_response;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200147 response->pool = fsf_req->pool != NULL;
148 response->erp_action = (unsigned long)fsf_req->erp_action;
149
150 switch (fsf_req->fsf_command) {
151 case FSF_QTCB_FCP_CMND:
152 if (fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT)
153 break;
154 scsi_cmnd = (struct scsi_cmnd *)fsf_req->data;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200155 if (scsi_cmnd) {
156 response->u.fcp.cmnd = (unsigned long)scsi_cmnd;
157 response->u.fcp.serial = scsi_cmnd->serial_number;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200158 }
159 break;
160
161 case FSF_QTCB_OPEN_PORT_WITH_DID:
162 case FSF_QTCB_CLOSE_PORT:
163 case FSF_QTCB_CLOSE_PHYSICAL_PORT:
164 port = (struct zfcp_port *)fsf_req->data;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200165 response->u.port.wwpn = port->wwpn;
166 response->u.port.d_id = port->d_id;
167 response->u.port.port_handle = qtcb->header.port_handle;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200168 break;
169
170 case FSF_QTCB_OPEN_LUN:
171 case FSF_QTCB_CLOSE_LUN:
172 unit = (struct zfcp_unit *)fsf_req->data;
173 port = unit->port;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200174 response->u.unit.wwpn = port->wwpn;
175 response->u.unit.fcp_lun = unit->fcp_lun;
176 response->u.unit.port_handle = qtcb->header.port_handle;
177 response->u.unit.lun_handle = qtcb->header.lun_handle;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200178 break;
179
180 case FSF_QTCB_SEND_ELS:
181 send_els = (struct zfcp_send_els *)fsf_req->data;
Christof Schmitt800c0ca2009-11-24 16:54:12 +0100182 response->u.els.d_id = ntoh24(qtcb->bottom.support.d_id);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200183 break;
184
185 case FSF_QTCB_ABORT_FCP_CMND:
186 case FSF_QTCB_SEND_GENERIC:
187 case FSF_QTCB_EXCHANGE_CONFIG_DATA:
188 case FSF_QTCB_EXCHANGE_PORT_DATA:
189 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
190 case FSF_QTCB_UPLOAD_CONTROL_FILE:
191 break;
192 }
193
Swen Schillig57717102009-08-18 15:43:21 +0200194 debug_event(dbf->hba, level, rec, sizeof(*rec));
Martin Peschkeb75db732008-03-27 14:21:58 +0100195
196 /* have fcp channel microcode fixed to use as little as possible */
197 if (fsf_req->fsf_command != FSF_QTCB_FCP_CMND) {
198 /* adjust length skipping trailing zeros */
199 char *buf = (char *)qtcb + qtcb->header.log_start;
200 int len = qtcb->header.log_length;
201 for (; len && !buf[len - 1]; len--);
Swen Schillig57717102009-08-18 15:43:21 +0200202 zfcp_dbf_hexdump(dbf->hba, rec, sizeof(*rec), level, buf,
Christof Schmittd46f3842009-08-18 15:43:07 +0200203 len);
Martin Peschkeb75db732008-03-27 14:21:58 +0100204 }
205
Swen Schillig57717102009-08-18 15:43:21 +0200206 spin_unlock_irqrestore(&dbf->hba_lock, flags);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200207}
208
Swen Schillig57717102009-08-18 15:43:21 +0200209void _zfcp_dbf_hba_fsf_unsol(const char *tag, int level, struct zfcp_dbf *dbf,
210 struct fsf_status_read_buffer *status_buffer)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200211{
Swen Schillig57717102009-08-18 15:43:21 +0200212 struct zfcp_dbf_hba_record *rec = &dbf->hba_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200213 unsigned long flags;
214
Swen Schillig57717102009-08-18 15:43:21 +0200215 spin_lock_irqsave(&dbf->hba_lock, flags);
Martin Peschke6bc473d2008-03-31 11:15:29 +0200216 memset(rec, 0, sizeof(*rec));
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200217 strncpy(rec->tag, "stat", ZFCP_DBF_TAG_SIZE);
218 strncpy(rec->tag2, tag, ZFCP_DBF_TAG_SIZE);
219
Swen Schillig57717102009-08-18 15:43:21 +0200220 rec->u.status.failed = atomic_read(&dbf->adapter->stat_miss);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200221 if (status_buffer != NULL) {
Martin Peschke6bc473d2008-03-31 11:15:29 +0200222 rec->u.status.status_type = status_buffer->status_type;
223 rec->u.status.status_subtype = status_buffer->status_subtype;
224 memcpy(&rec->u.status.queue_designator,
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200225 &status_buffer->queue_designator,
226 sizeof(struct fsf_queue_designator));
227
228 switch (status_buffer->status_type) {
229 case FSF_STATUS_READ_SENSE_DATA_AVAIL:
Martin Peschke6bc473d2008-03-31 11:15:29 +0200230 rec->u.status.payload_size =
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200231 ZFCP_DBF_UNSOL_PAYLOAD_SENSE_DATA_AVAIL;
232 break;
233
234 case FSF_STATUS_READ_BIT_ERROR_THRESHOLD:
Martin Peschke6bc473d2008-03-31 11:15:29 +0200235 rec->u.status.payload_size =
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200236 ZFCP_DBF_UNSOL_PAYLOAD_BIT_ERROR_THRESHOLD;
237 break;
238
239 case FSF_STATUS_READ_LINK_DOWN:
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200240 switch (status_buffer->status_subtype) {
241 case FSF_STATUS_READ_SUB_NO_PHYSICAL_LINK:
242 case FSF_STATUS_READ_SUB_FDISC_FAILED:
Martin Peschke6bc473d2008-03-31 11:15:29 +0200243 rec->u.status.payload_size =
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200244 sizeof(struct fsf_link_down_info);
245 }
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200246 break;
247
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200248 case FSF_STATUS_READ_FEATURE_UPDATE_ALERT:
Martin Peschke6bc473d2008-03-31 11:15:29 +0200249 rec->u.status.payload_size =
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200250 ZFCP_DBF_UNSOL_PAYLOAD_FEATURE_UPDATE_ALERT;
251 break;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200252 }
Martin Peschke6bc473d2008-03-31 11:15:29 +0200253 memcpy(&rec->u.status.payload,
254 &status_buffer->payload, rec->u.status.payload_size);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200255 }
256
Swen Schillig57717102009-08-18 15:43:21 +0200257 debug_event(dbf->hba, level, rec, sizeof(*rec));
258 spin_unlock_irqrestore(&dbf->hba_lock, flags);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200259}
260
Martin Peschkebfab1632008-03-31 11:15:31 +0200261/**
Swen Schillig57717102009-08-18 15:43:21 +0200262 * zfcp_dbf_hba_qdio - trace event for QDIO related failure
Swen Schillig564e1c82009-08-18 15:43:19 +0200263 * @qdio: qdio structure affected by this QDIO related event
Martin Peschkebfab1632008-03-31 11:15:31 +0200264 * @qdio_error: as passed by qdio module
Martin Peschkebfab1632008-03-31 11:15:31 +0200265 * @sbal_index: first buffer with error condition, as passed by qdio module
266 * @sbal_count: number of buffers affected, as passed by qdio module
267 */
Swen Schillig57717102009-08-18 15:43:21 +0200268void zfcp_dbf_hba_qdio(struct zfcp_dbf *dbf, unsigned int qdio_error,
269 int sbal_index, int sbal_count)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200270{
Swen Schillig57717102009-08-18 15:43:21 +0200271 struct zfcp_dbf_hba_record *r = &dbf->hba_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200272 unsigned long flags;
273
Swen Schillig57717102009-08-18 15:43:21 +0200274 spin_lock_irqsave(&dbf->hba_lock, flags);
Martin Peschke6bc473d2008-03-31 11:15:29 +0200275 memset(r, 0, sizeof(*r));
276 strncpy(r->tag, "qdio", ZFCP_DBF_TAG_SIZE);
Martin Peschke6bc473d2008-03-31 11:15:29 +0200277 r->u.qdio.qdio_error = qdio_error;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200278 r->u.qdio.sbal_index = sbal_index;
279 r->u.qdio.sbal_count = sbal_count;
Swen Schillig57717102009-08-18 15:43:21 +0200280 debug_event(dbf->hba, 0, r, sizeof(*r));
281 spin_unlock_irqrestore(&dbf->hba_lock, flags);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200282}
283
Swen Schillig57069382008-10-01 12:42:21 +0200284/**
Swen Schillig57717102009-08-18 15:43:21 +0200285 * zfcp_dbf_hba_berr - trace event for bit error threshold
286 * @dbf: dbf structure affected by this QDIO related event
Swen Schillig57069382008-10-01 12:42:21 +0200287 * @req: fsf request
288 */
Swen Schillig57717102009-08-18 15:43:21 +0200289void zfcp_dbf_hba_berr(struct zfcp_dbf *dbf, struct zfcp_fsf_req *req)
Swen Schillig57069382008-10-01 12:42:21 +0200290{
Swen Schillig57717102009-08-18 15:43:21 +0200291 struct zfcp_dbf_hba_record *r = &dbf->hba_buf;
Swen Schillig57069382008-10-01 12:42:21 +0200292 struct fsf_status_read_buffer *sr_buf = req->data;
293 struct fsf_bit_error_payload *err = &sr_buf->payload.bit_error;
294 unsigned long flags;
295
Swen Schillig57717102009-08-18 15:43:21 +0200296 spin_lock_irqsave(&dbf->hba_lock, flags);
Swen Schillig57069382008-10-01 12:42:21 +0200297 memset(r, 0, sizeof(*r));
298 strncpy(r->tag, "berr", ZFCP_DBF_TAG_SIZE);
299 memcpy(&r->u.berr, err, sizeof(struct fsf_bit_error_payload));
Swen Schillig57717102009-08-18 15:43:21 +0200300 debug_event(dbf->hba, 0, r, sizeof(*r));
301 spin_unlock_irqrestore(&dbf->hba_lock, flags);
Swen Schillig57069382008-10-01 12:42:21 +0200302}
Swen Schillig57717102009-08-18 15:43:21 +0200303static void zfcp_dbf_hba_view_response(char **p,
304 struct zfcp_dbf_hba_record_response *r)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200305{
Martin Peschke8fc5af12008-03-31 11:15:23 +0200306 struct timespec t;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200307
Martin Peschkea9c85772008-03-31 11:15:27 +0200308 zfcp_dbf_out(p, "fsf_command", "0x%08x", r->fsf_command);
309 zfcp_dbf_out(p, "fsf_reqid", "0x%0Lx", r->fsf_reqid);
310 zfcp_dbf_out(p, "fsf_seqno", "0x%08x", r->fsf_seqno);
Christof Schmittb592e892009-08-18 15:43:31 +0200311 stck_to_timespec(r->fsf_issued, &t);
Martin Peschkea9c85772008-03-31 11:15:27 +0200312 zfcp_dbf_out(p, "fsf_issued", "%011lu:%06lu", t.tv_sec, t.tv_nsec);
313 zfcp_dbf_out(p, "fsf_prot_status", "0x%08x", r->fsf_prot_status);
314 zfcp_dbf_out(p, "fsf_status", "0x%08x", r->fsf_status);
315 zfcp_dbf_outd(p, "fsf_prot_status_qual", r->fsf_prot_status_qual,
Martin Peschkedf29f4a2008-03-31 11:15:26 +0200316 FSF_PROT_STATUS_QUAL_SIZE, 0, FSF_PROT_STATUS_QUAL_SIZE);
Martin Peschkea9c85772008-03-31 11:15:27 +0200317 zfcp_dbf_outd(p, "fsf_status_qual", r->fsf_status_qual,
Martin Peschkedf29f4a2008-03-31 11:15:26 +0200318 FSF_STATUS_QUALIFIER_SIZE, 0, FSF_STATUS_QUALIFIER_SIZE);
Martin Peschkea9c85772008-03-31 11:15:27 +0200319 zfcp_dbf_out(p, "fsf_req_status", "0x%08x", r->fsf_req_status);
320 zfcp_dbf_out(p, "sbal_first", "0x%02x", r->sbal_first);
Martin Peschkee891bff2008-05-19 12:17:43 +0200321 zfcp_dbf_out(p, "sbal_last", "0x%02x", r->sbal_last);
Martin Peschkec3baa9a22008-05-19 12:17:44 +0200322 zfcp_dbf_out(p, "sbal_response", "0x%02x", r->sbal_response);
Martin Peschkea9c85772008-03-31 11:15:27 +0200323 zfcp_dbf_out(p, "pool", "0x%02x", r->pool);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200324
Martin Peschkeb634fff2008-03-31 11:15:24 +0200325 switch (r->fsf_command) {
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200326 case FSF_QTCB_FCP_CMND:
Martin Peschkeb634fff2008-03-31 11:15:24 +0200327 if (r->fsf_req_status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200328 break;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200329 zfcp_dbf_out(p, "scsi_cmnd", "0x%0Lx", r->u.fcp.cmnd);
330 zfcp_dbf_out(p, "scsi_serial", "0x%016Lx", r->u.fcp.serial);
Christof Schmitt5a3fb302010-01-13 17:52:37 +0100331 *p += sprintf(*p, "\n");
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200332 break;
333
334 case FSF_QTCB_OPEN_PORT_WITH_DID:
335 case FSF_QTCB_CLOSE_PORT:
336 case FSF_QTCB_CLOSE_PHYSICAL_PORT:
Martin Peschke6bc473d2008-03-31 11:15:29 +0200337 zfcp_dbf_out(p, "wwpn", "0x%016Lx", r->u.port.wwpn);
338 zfcp_dbf_out(p, "d_id", "0x%06x", r->u.port.d_id);
339 zfcp_dbf_out(p, "port_handle", "0x%08x", r->u.port.port_handle);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200340 break;
341
342 case FSF_QTCB_OPEN_LUN:
343 case FSF_QTCB_CLOSE_LUN:
Martin Peschke6bc473d2008-03-31 11:15:29 +0200344 zfcp_dbf_out(p, "wwpn", "0x%016Lx", r->u.unit.wwpn);
345 zfcp_dbf_out(p, "fcp_lun", "0x%016Lx", r->u.unit.fcp_lun);
346 zfcp_dbf_out(p, "port_handle", "0x%08x", r->u.unit.port_handle);
347 zfcp_dbf_out(p, "lun_handle", "0x%08x", r->u.unit.lun_handle);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200348 break;
349
350 case FSF_QTCB_SEND_ELS:
Martin Peschke6bc473d2008-03-31 11:15:29 +0200351 zfcp_dbf_out(p, "d_id", "0x%06x", r->u.els.d_id);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200352 break;
353
354 case FSF_QTCB_ABORT_FCP_CMND:
355 case FSF_QTCB_SEND_GENERIC:
356 case FSF_QTCB_EXCHANGE_CONFIG_DATA:
357 case FSF_QTCB_EXCHANGE_PORT_DATA:
358 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
359 case FSF_QTCB_UPLOAD_CONTROL_FILE:
360 break;
361 }
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200362}
363
Swen Schillig57717102009-08-18 15:43:21 +0200364static void zfcp_dbf_hba_view_status(char **p,
365 struct zfcp_dbf_hba_record_status *r)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200366{
Martin Peschkea9c85772008-03-31 11:15:27 +0200367 zfcp_dbf_out(p, "failed", "0x%02x", r->failed);
368 zfcp_dbf_out(p, "status_type", "0x%08x", r->status_type);
369 zfcp_dbf_out(p, "status_subtype", "0x%08x", r->status_subtype);
370 zfcp_dbf_outd(p, "queue_designator", (char *)&r->queue_designator,
Martin Peschkedf29f4a2008-03-31 11:15:26 +0200371 sizeof(struct fsf_queue_designator), 0,
372 sizeof(struct fsf_queue_designator));
Martin Peschkea9c85772008-03-31 11:15:27 +0200373 zfcp_dbf_outd(p, "payload", (char *)&r->payload, r->payload_size, 0,
Martin Peschkedf29f4a2008-03-31 11:15:26 +0200374 r->payload_size);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200375}
376
Swen Schillig57717102009-08-18 15:43:21 +0200377static void zfcp_dbf_hba_view_qdio(char **p, struct zfcp_dbf_hba_record_qdio *r)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200378{
Martin Peschkea9c85772008-03-31 11:15:27 +0200379 zfcp_dbf_out(p, "qdio_error", "0x%08x", r->qdio_error);
Martin Peschkea9c85772008-03-31 11:15:27 +0200380 zfcp_dbf_out(p, "sbal_index", "0x%02x", r->sbal_index);
381 zfcp_dbf_out(p, "sbal_count", "0x%02x", r->sbal_count);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200382}
383
Swen Schillig57717102009-08-18 15:43:21 +0200384static void zfcp_dbf_hba_view_berr(char **p, struct fsf_bit_error_payload *r)
Swen Schillig57069382008-10-01 12:42:21 +0200385{
386 zfcp_dbf_out(p, "link_failures", "%d", r->link_failure_error_count);
387 zfcp_dbf_out(p, "loss_of_sync_err", "%d", r->loss_of_sync_error_count);
388 zfcp_dbf_out(p, "loss_of_sig_err", "%d", r->loss_of_signal_error_count);
389 zfcp_dbf_out(p, "prim_seq_err", "%d",
390 r->primitive_sequence_error_count);
391 zfcp_dbf_out(p, "inval_trans_word_err", "%d",
392 r->invalid_transmission_word_error_count);
393 zfcp_dbf_out(p, "CRC_errors", "%d", r->crc_error_count);
394 zfcp_dbf_out(p, "prim_seq_event_to", "%d",
395 r->primitive_sequence_event_timeout_count);
396 zfcp_dbf_out(p, "elast_buf_overrun_err", "%d",
397 r->elastic_buffer_overrun_error_count);
398 zfcp_dbf_out(p, "adv_rec_buf2buf_cred", "%d",
399 r->advertised_receive_b2b_credit);
400 zfcp_dbf_out(p, "curr_rec_buf2buf_cred", "%d",
401 r->current_receive_b2b_credit);
402 zfcp_dbf_out(p, "adv_trans_buf2buf_cred", "%d",
403 r->advertised_transmit_b2b_credit);
404 zfcp_dbf_out(p, "curr_trans_buf2buf_cred", "%d",
405 r->current_transmit_b2b_credit);
406}
407
Swen Schillig57717102009-08-18 15:43:21 +0200408static int zfcp_dbf_hba_view_format(debug_info_t *id, struct debug_view *view,
Martin Peschkea9c85772008-03-31 11:15:27 +0200409 char *out_buf, const char *in_buf)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200410{
Swen Schillig57717102009-08-18 15:43:21 +0200411 struct zfcp_dbf_hba_record *r = (struct zfcp_dbf_hba_record *)in_buf;
Martin Peschkea9c85772008-03-31 11:15:27 +0200412 char *p = out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200413
Martin Peschkea9c85772008-03-31 11:15:27 +0200414 if (strncmp(r->tag, "dump", ZFCP_DBF_TAG_SIZE) == 0)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200415 return 0;
416
Martin Peschkea9c85772008-03-31 11:15:27 +0200417 zfcp_dbf_tag(&p, "tag", r->tag);
418 if (isalpha(r->tag2[0]))
419 zfcp_dbf_tag(&p, "tag2", r->tag2);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200420
Martin Peschkea9c85772008-03-31 11:15:27 +0200421 if (strncmp(r->tag, "resp", ZFCP_DBF_TAG_SIZE) == 0)
Swen Schillig57717102009-08-18 15:43:21 +0200422 zfcp_dbf_hba_view_response(&p, &r->u.response);
Martin Peschkea9c85772008-03-31 11:15:27 +0200423 else if (strncmp(r->tag, "stat", ZFCP_DBF_TAG_SIZE) == 0)
Swen Schillig57717102009-08-18 15:43:21 +0200424 zfcp_dbf_hba_view_status(&p, &r->u.status);
Martin Peschkea9c85772008-03-31 11:15:27 +0200425 else if (strncmp(r->tag, "qdio", ZFCP_DBF_TAG_SIZE) == 0)
Swen Schillig57717102009-08-18 15:43:21 +0200426 zfcp_dbf_hba_view_qdio(&p, &r->u.qdio);
Swen Schillig57069382008-10-01 12:42:21 +0200427 else if (strncmp(r->tag, "berr", ZFCP_DBF_TAG_SIZE) == 0)
Swen Schillig57717102009-08-18 15:43:21 +0200428 zfcp_dbf_hba_view_berr(&p, &r->u.berr);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200429
Christof Schmittd94ce6c2008-11-04 16:35:12 +0100430 if (strncmp(r->tag, "resp", ZFCP_DBF_TAG_SIZE) != 0)
431 p += sprintf(p, "\n");
Martin Peschkea9c85772008-03-31 11:15:27 +0200432 return p - out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200433}
434
Swen Schillig57717102009-08-18 15:43:21 +0200435static struct debug_view zfcp_dbf_hba_view = {
436 .name = "structured",
437 .header_proc = zfcp_dbf_view_header,
438 .format_proc = zfcp_dbf_hba_view_format,
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200439};
440
Swen Schillig57717102009-08-18 15:43:21 +0200441static const char *zfcp_dbf_rec_tags[] = {
Martin Peschke348447e2008-03-27 14:22:01 +0100442 [ZFCP_REC_DBF_ID_THREAD] = "thread",
Martin Peschke698ec0162008-03-27 14:22:02 +0100443 [ZFCP_REC_DBF_ID_TARGET] = "target",
Martin Peschke9467a9b2008-03-27 14:22:03 +0100444 [ZFCP_REC_DBF_ID_TRIGGER] = "trigger",
Martin Peschke6f4f3652008-03-27 14:22:04 +0100445 [ZFCP_REC_DBF_ID_ACTION] = "action",
Martin Peschked79a83d2008-03-27 14:22:00 +0100446};
447
Swen Schillig57717102009-08-18 15:43:21 +0200448static int zfcp_dbf_rec_view_format(debug_info_t *id, struct debug_view *view,
Martin Peschked79a83d2008-03-27 14:22:00 +0100449 char *buf, const char *_rec)
450{
Swen Schillig57717102009-08-18 15:43:21 +0200451 struct zfcp_dbf_rec_record *r = (struct zfcp_dbf_rec_record *)_rec;
Martin Peschked79a83d2008-03-27 14:22:00 +0100452 char *p = buf;
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100453 char hint[ZFCP_DBF_ID_SIZE + 1];
Martin Peschked79a83d2008-03-27 14:22:00 +0100454
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100455 memcpy(hint, r->id2, ZFCP_DBF_ID_SIZE);
456 hint[ZFCP_DBF_ID_SIZE] = 0;
Swen Schillig57717102009-08-18 15:43:21 +0200457 zfcp_dbf_outs(&p, "tag", zfcp_dbf_rec_tags[r->id]);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100458 zfcp_dbf_outs(&p, "hint", hint);
Martin Peschked79a83d2008-03-27 14:22:00 +0100459 switch (r->id) {
Martin Peschke348447e2008-03-27 14:22:01 +0100460 case ZFCP_REC_DBF_ID_THREAD:
Martin Peschke348447e2008-03-27 14:22:01 +0100461 zfcp_dbf_out(&p, "total", "%d", r->u.thread.total);
462 zfcp_dbf_out(&p, "ready", "%d", r->u.thread.ready);
463 zfcp_dbf_out(&p, "running", "%d", r->u.thread.running);
464 break;
Martin Peschke698ec0162008-03-27 14:22:02 +0100465 case ZFCP_REC_DBF_ID_TARGET:
466 zfcp_dbf_out(&p, "reference", "0x%016Lx", r->u.target.ref);
467 zfcp_dbf_out(&p, "status", "0x%08x", r->u.target.status);
468 zfcp_dbf_out(&p, "erp_count", "%d", r->u.target.erp_count);
469 zfcp_dbf_out(&p, "d_id", "0x%06x", r->u.target.d_id);
470 zfcp_dbf_out(&p, "wwpn", "0x%016Lx", r->u.target.wwpn);
471 zfcp_dbf_out(&p, "fcp_lun", "0x%016Lx", r->u.target.fcp_lun);
472 break;
Martin Peschke9467a9b2008-03-27 14:22:03 +0100473 case ZFCP_REC_DBF_ID_TRIGGER:
474 zfcp_dbf_out(&p, "reference", "0x%016Lx", r->u.trigger.ref);
475 zfcp_dbf_out(&p, "erp_action", "0x%016Lx", r->u.trigger.action);
476 zfcp_dbf_out(&p, "requested", "%d", r->u.trigger.want);
477 zfcp_dbf_out(&p, "executed", "%d", r->u.trigger.need);
478 zfcp_dbf_out(&p, "wwpn", "0x%016Lx", r->u.trigger.wwpn);
479 zfcp_dbf_out(&p, "fcp_lun", "0x%016Lx", r->u.trigger.fcp_lun);
480 zfcp_dbf_out(&p, "adapter_status", "0x%08x", r->u.trigger.as);
481 zfcp_dbf_out(&p, "port_status", "0x%08x", r->u.trigger.ps);
482 zfcp_dbf_out(&p, "unit_status", "0x%08x", r->u.trigger.us);
483 break;
Martin Peschke6f4f3652008-03-27 14:22:04 +0100484 case ZFCP_REC_DBF_ID_ACTION:
485 zfcp_dbf_out(&p, "erp_action", "0x%016Lx", r->u.action.action);
486 zfcp_dbf_out(&p, "fsf_req", "0x%016Lx", r->u.action.fsf_req);
487 zfcp_dbf_out(&p, "status", "0x%08Lx", r->u.action.status);
488 zfcp_dbf_out(&p, "step", "0x%08Lx", r->u.action.step);
489 break;
Martin Peschked79a83d2008-03-27 14:22:00 +0100490 }
Martin Peschkeb634fff2008-03-31 11:15:24 +0200491 p += sprintf(p, "\n");
492 return p - buf;
Martin Peschked79a83d2008-03-27 14:22:00 +0100493}
494
Swen Schillig57717102009-08-18 15:43:21 +0200495static struct debug_view zfcp_dbf_rec_view = {
496 .name = "structured",
497 .header_proc = zfcp_dbf_view_header,
498 .format_proc = zfcp_dbf_rec_view_format,
Martin Peschked79a83d2008-03-27 14:22:00 +0100499};
500
Martin Peschke348447e2008-03-27 14:22:01 +0100501/**
Swen Schillig57717102009-08-18 15:43:21 +0200502 * zfcp_dbf_rec_thread - trace event related to recovery thread operation
Martin Peschke348447e2008-03-27 14:22:01 +0100503 * @id2: identifier for event
Swen Schillig57717102009-08-18 15:43:21 +0200504 * @dbf: reference to dbf structure
Christof Schmittaa0fec62008-05-19 12:17:47 +0200505 * This function assumes that the caller is holding erp_lock.
Martin Peschke348447e2008-03-27 14:22:01 +0100506 */
Swen Schillig57717102009-08-18 15:43:21 +0200507void zfcp_dbf_rec_thread(char *id2, struct zfcp_dbf *dbf)
Martin Peschke348447e2008-03-27 14:22:01 +0100508{
Swen Schillig57717102009-08-18 15:43:21 +0200509 struct zfcp_adapter *adapter = dbf->adapter;
510 struct zfcp_dbf_rec_record *r = &dbf->rec_buf;
Martin Peschke348447e2008-03-27 14:22:01 +0100511 unsigned long flags = 0;
512 struct list_head *entry;
513 unsigned ready = 0, running = 0, total;
514
Martin Peschke348447e2008-03-27 14:22:01 +0100515 list_for_each(entry, &adapter->erp_ready_head)
516 ready++;
517 list_for_each(entry, &adapter->erp_running_head)
518 running++;
519 total = adapter->erp_total_count;
Martin Peschke348447e2008-03-27 14:22:01 +0100520
Swen Schillig57717102009-08-18 15:43:21 +0200521 spin_lock_irqsave(&dbf->rec_lock, flags);
Martin Peschke348447e2008-03-27 14:22:01 +0100522 memset(r, 0, sizeof(*r));
523 r->id = ZFCP_REC_DBF_ID_THREAD;
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100524 memcpy(r->id2, id2, ZFCP_DBF_ID_SIZE);
Martin Peschke348447e2008-03-27 14:22:01 +0100525 r->u.thread.total = total;
526 r->u.thread.ready = ready;
527 r->u.thread.running = running;
Swen Schillig57717102009-08-18 15:43:21 +0200528 debug_event(dbf->rec, 6, r, sizeof(*r));
529 spin_unlock_irqrestore(&dbf->rec_lock, flags);
Martin Peschke348447e2008-03-27 14:22:01 +0100530}
531
Christof Schmittaa0fec62008-05-19 12:17:47 +0200532/**
Swen Schillig57717102009-08-18 15:43:21 +0200533 * zfcp_dbf_rec_thread - trace event related to recovery thread operation
Christof Schmittaa0fec62008-05-19 12:17:47 +0200534 * @id2: identifier for event
535 * @adapter: adapter
536 * This function assumes that the caller does not hold erp_lock.
537 */
Swen Schillig57717102009-08-18 15:43:21 +0200538void zfcp_dbf_rec_thread_lock(char *id2, struct zfcp_dbf *dbf)
Christof Schmittaa0fec62008-05-19 12:17:47 +0200539{
Swen Schillig57717102009-08-18 15:43:21 +0200540 struct zfcp_adapter *adapter = dbf->adapter;
Christof Schmittaa0fec62008-05-19 12:17:47 +0200541 unsigned long flags;
542
543 read_lock_irqsave(&adapter->erp_lock, flags);
Swen Schillig57717102009-08-18 15:43:21 +0200544 zfcp_dbf_rec_thread(id2, dbf);
Christof Schmittaa0fec62008-05-19 12:17:47 +0200545 read_unlock_irqrestore(&adapter->erp_lock, flags);
546}
547
Swen Schillig57717102009-08-18 15:43:21 +0200548static void zfcp_dbf_rec_target(char *id2, void *ref, struct zfcp_dbf *dbf,
549 atomic_t *status, atomic_t *erp_count, u64 wwpn,
550 u32 d_id, u64 fcp_lun)
Martin Peschke698ec0162008-03-27 14:22:02 +0100551{
Swen Schillig57717102009-08-18 15:43:21 +0200552 struct zfcp_dbf_rec_record *r = &dbf->rec_buf;
Martin Peschke698ec0162008-03-27 14:22:02 +0100553 unsigned long flags;
554
Swen Schillig57717102009-08-18 15:43:21 +0200555 spin_lock_irqsave(&dbf->rec_lock, flags);
Martin Peschke698ec0162008-03-27 14:22:02 +0100556 memset(r, 0, sizeof(*r));
557 r->id = ZFCP_REC_DBF_ID_TARGET;
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100558 memcpy(r->id2, id2, ZFCP_DBF_ID_SIZE);
Martin Peschke1f6f7122008-04-18 12:51:55 +0200559 r->u.target.ref = (unsigned long)ref;
Martin Peschke698ec0162008-03-27 14:22:02 +0100560 r->u.target.status = atomic_read(status);
561 r->u.target.wwpn = wwpn;
562 r->u.target.d_id = d_id;
563 r->u.target.fcp_lun = fcp_lun;
564 r->u.target.erp_count = atomic_read(erp_count);
Swen Schillig57717102009-08-18 15:43:21 +0200565 debug_event(dbf->rec, 3, r, sizeof(*r));
566 spin_unlock_irqrestore(&dbf->rec_lock, flags);
Martin Peschke698ec0162008-03-27 14:22:02 +0100567}
568
569/**
Swen Schillig57717102009-08-18 15:43:21 +0200570 * zfcp_dbf_rec_adapter - trace event for adapter state change
Martin Peschke698ec0162008-03-27 14:22:02 +0100571 * @id: identifier for trigger of state change
572 * @ref: additional reference (e.g. request)
Swen Schillig57717102009-08-18 15:43:21 +0200573 * @dbf: reference to dbf structure
Martin Peschke698ec0162008-03-27 14:22:02 +0100574 */
Swen Schillig57717102009-08-18 15:43:21 +0200575void zfcp_dbf_rec_adapter(char *id, void *ref, struct zfcp_dbf *dbf)
Martin Peschke698ec0162008-03-27 14:22:02 +0100576{
Swen Schillig57717102009-08-18 15:43:21 +0200577 struct zfcp_adapter *adapter = dbf->adapter;
578
579 zfcp_dbf_rec_target(id, ref, dbf, &adapter->status,
Christof Schmittd21e9da2010-02-17 11:18:54 +0100580 &adapter->erp_counter, 0, 0,
581 ZFCP_DBF_INVALID_LUN);
Martin Peschke698ec0162008-03-27 14:22:02 +0100582}
583
584/**
Swen Schillig57717102009-08-18 15:43:21 +0200585 * zfcp_dbf_rec_port - trace event for port state change
Martin Peschke698ec0162008-03-27 14:22:02 +0100586 * @id: identifier for trigger of state change
587 * @ref: additional reference (e.g. request)
588 * @port: port
589 */
Swen Schillig57717102009-08-18 15:43:21 +0200590void zfcp_dbf_rec_port(char *id, void *ref, struct zfcp_port *port)
Martin Peschke698ec0162008-03-27 14:22:02 +0100591{
Swen Schillig57717102009-08-18 15:43:21 +0200592 struct zfcp_dbf *dbf = port->adapter->dbf;
Martin Peschke698ec0162008-03-27 14:22:02 +0100593
Swen Schillig57717102009-08-18 15:43:21 +0200594 zfcp_dbf_rec_target(id, ref, dbf, &port->status,
Christof Schmittd21e9da2010-02-17 11:18:54 +0100595 &port->erp_counter, port->wwpn, port->d_id,
596 ZFCP_DBF_INVALID_LUN);
Martin Peschke698ec0162008-03-27 14:22:02 +0100597}
598
599/**
Swen Schillig57717102009-08-18 15:43:21 +0200600 * zfcp_dbf_rec_unit - trace event for unit state change
Martin Peschke698ec0162008-03-27 14:22:02 +0100601 * @id: identifier for trigger of state change
602 * @ref: additional reference (e.g. request)
603 * @unit: unit
604 */
Swen Schillig57717102009-08-18 15:43:21 +0200605void zfcp_dbf_rec_unit(char *id, void *ref, struct zfcp_unit *unit)
Martin Peschke698ec0162008-03-27 14:22:02 +0100606{
607 struct zfcp_port *port = unit->port;
Swen Schillig57717102009-08-18 15:43:21 +0200608 struct zfcp_dbf *dbf = port->adapter->dbf;
Martin Peschke698ec0162008-03-27 14:22:02 +0100609
Swen Schillig57717102009-08-18 15:43:21 +0200610 zfcp_dbf_rec_target(id, ref, dbf, &unit->status,
Martin Peschke698ec0162008-03-27 14:22:02 +0100611 &unit->erp_counter, port->wwpn, port->d_id,
612 unit->fcp_lun);
613}
614
Martin Peschke9467a9b2008-03-27 14:22:03 +0100615/**
Swen Schillig57717102009-08-18 15:43:21 +0200616 * zfcp_dbf_rec_trigger - trace event for triggered error recovery
Martin Peschke9467a9b2008-03-27 14:22:03 +0100617 * @id2: identifier for error recovery trigger
618 * @ref: additional reference (e.g. request)
619 * @want: originally requested error recovery action
620 * @need: error recovery action actually initiated
621 * @action: address of error recovery action struct
622 * @adapter: adapter
623 * @port: port
624 * @unit: unit
625 */
Swen Schillig57717102009-08-18 15:43:21 +0200626void zfcp_dbf_rec_trigger(char *id2, void *ref, u8 want, u8 need, void *action,
627 struct zfcp_adapter *adapter, struct zfcp_port *port,
628 struct zfcp_unit *unit)
Martin Peschke9467a9b2008-03-27 14:22:03 +0100629{
Christof Schmittd46f3842009-08-18 15:43:07 +0200630 struct zfcp_dbf *dbf = adapter->dbf;
Swen Schillig57717102009-08-18 15:43:21 +0200631 struct zfcp_dbf_rec_record *r = &dbf->rec_buf;
Martin Peschke9467a9b2008-03-27 14:22:03 +0100632 unsigned long flags;
633
Swen Schillig57717102009-08-18 15:43:21 +0200634 spin_lock_irqsave(&dbf->rec_lock, flags);
Martin Peschke9467a9b2008-03-27 14:22:03 +0100635 memset(r, 0, sizeof(*r));
636 r->id = ZFCP_REC_DBF_ID_TRIGGER;
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100637 memcpy(r->id2, id2, ZFCP_DBF_ID_SIZE);
Martin Peschke1f6f7122008-04-18 12:51:55 +0200638 r->u.trigger.ref = (unsigned long)ref;
Martin Peschke9467a9b2008-03-27 14:22:03 +0100639 r->u.trigger.want = want;
640 r->u.trigger.need = need;
Martin Peschke1f6f7122008-04-18 12:51:55 +0200641 r->u.trigger.action = (unsigned long)action;
Martin Peschke9467a9b2008-03-27 14:22:03 +0100642 r->u.trigger.as = atomic_read(&adapter->status);
643 if (port) {
644 r->u.trigger.ps = atomic_read(&port->status);
645 r->u.trigger.wwpn = port->wwpn;
646 }
Christof Schmittd21e9da2010-02-17 11:18:54 +0100647 if (unit)
Martin Peschke9467a9b2008-03-27 14:22:03 +0100648 r->u.trigger.us = atomic_read(&unit->status);
Christof Schmittd21e9da2010-02-17 11:18:54 +0100649 r->u.trigger.fcp_lun = unit ? unit->fcp_lun : ZFCP_DBF_INVALID_LUN;
Swen Schillig57717102009-08-18 15:43:21 +0200650 debug_event(dbf->rec, action ? 1 : 4, r, sizeof(*r));
651 spin_unlock_irqrestore(&dbf->rec_lock, flags);
Martin Peschke9467a9b2008-03-27 14:22:03 +0100652}
653
Martin Peschke6f4f3652008-03-27 14:22:04 +0100654/**
Swen Schillig57717102009-08-18 15:43:21 +0200655 * zfcp_dbf_rec_action - trace event showing progress of recovery action
Martin Peschke6f4f3652008-03-27 14:22:04 +0100656 * @id2: identifier
657 * @erp_action: error recovery action struct pointer
658 */
Swen Schillig57717102009-08-18 15:43:21 +0200659void zfcp_dbf_rec_action(char *id2, struct zfcp_erp_action *erp_action)
Martin Peschke6f4f3652008-03-27 14:22:04 +0100660{
Swen Schillig57717102009-08-18 15:43:21 +0200661 struct zfcp_dbf *dbf = erp_action->adapter->dbf;
662 struct zfcp_dbf_rec_record *r = &dbf->rec_buf;
Martin Peschke6f4f3652008-03-27 14:22:04 +0100663 unsigned long flags;
664
Swen Schillig57717102009-08-18 15:43:21 +0200665 spin_lock_irqsave(&dbf->rec_lock, flags);
Martin Peschke6f4f3652008-03-27 14:22:04 +0100666 memset(r, 0, sizeof(*r));
667 r->id = ZFCP_REC_DBF_ID_ACTION;
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100668 memcpy(r->id2, id2, ZFCP_DBF_ID_SIZE);
Martin Peschke1f6f7122008-04-18 12:51:55 +0200669 r->u.action.action = (unsigned long)erp_action;
Martin Peschke6f4f3652008-03-27 14:22:04 +0100670 r->u.action.status = erp_action->status;
671 r->u.action.step = erp_action->step;
Christof Schmitte60a6d62010-02-17 11:18:49 +0100672 r->u.action.fsf_req = erp_action->fsf_req_id;
Swen Schillig57717102009-08-18 15:43:21 +0200673 debug_event(dbf->rec, 5, r, sizeof(*r));
674 spin_unlock_irqrestore(&dbf->rec_lock, flags);
Martin Peschke6f4f3652008-03-27 14:22:04 +0100675}
676
Martin Peschkebfab1632008-03-31 11:15:31 +0200677/**
Swen Schillig57717102009-08-18 15:43:21 +0200678 * zfcp_dbf_san_ct_request - trace event for issued CT request
Martin Peschkebfab1632008-03-31 11:15:31 +0200679 * @fsf_req: request containing issued CT data
Christof Schmitt7c7dc192009-11-24 16:54:13 +0100680 * @d_id: destination id where ct request is sent to
Martin Peschkebfab1632008-03-31 11:15:31 +0200681 */
Christof Schmitt7c7dc192009-11-24 16:54:13 +0100682void zfcp_dbf_san_ct_request(struct zfcp_fsf_req *fsf_req, u32 d_id)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200683{
Christof Schmitt7c7dc192009-11-24 16:54:13 +0100684 struct zfcp_fsf_ct_els *ct = (struct zfcp_fsf_ct_els *)fsf_req->data;
685 struct zfcp_adapter *adapter = fsf_req->adapter;
Christof Schmittd46f3842009-08-18 15:43:07 +0200686 struct zfcp_dbf *dbf = adapter->dbf;
Christof Schmittdbf5dfe2009-11-24 16:54:10 +0100687 struct fc_ct_hdr *hdr = sg_virt(ct->req);
Swen Schillig57717102009-08-18 15:43:21 +0200688 struct zfcp_dbf_san_record *r = &dbf->san_buf;
689 struct zfcp_dbf_san_record_ct_request *oct = &r->u.ct_req;
Christof Schmittd94ce6c2008-11-04 16:35:12 +0100690 int level = 3;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200691 unsigned long flags;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200692
Swen Schillig57717102009-08-18 15:43:21 +0200693 spin_lock_irqsave(&dbf->san_lock, flags);
Martin Peschke6bc473d2008-03-31 11:15:29 +0200694 memset(r, 0, sizeof(*r));
695 strncpy(r->tag, "octc", ZFCP_DBF_TAG_SIZE);
Christof Schmittf0216ae2009-05-15 13:18:14 +0200696 r->fsf_reqid = fsf_req->req_id;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200697 r->fsf_seqno = fsf_req->seq_no;
Christof Schmitt7c7dc192009-11-24 16:54:13 +0100698 oct->d_id = d_id;
Christof Schmittdbf5dfe2009-11-24 16:54:10 +0100699 oct->cmd_req_code = hdr->ct_cmd;
700 oct->revision = hdr->ct_rev;
701 oct->gs_type = hdr->ct_fs_type;
702 oct->gs_subtype = hdr->ct_fs_subtype;
703 oct->options = hdr->ct_options;
704 oct->max_res_size = hdr->ct_mr_size;
705 oct->len = min((int)ct->req->length - (int)sizeof(struct fc_ct_hdr),
Christof Schmittd94ce6c2008-11-04 16:35:12 +0100706 ZFCP_DBF_SAN_MAX_PAYLOAD);
Swen Schillig57717102009-08-18 15:43:21 +0200707 debug_event(dbf->san, level, r, sizeof(*r));
708 zfcp_dbf_hexdump(dbf->san, r, sizeof(*r), level,
Christof Schmittdbf5dfe2009-11-24 16:54:10 +0100709 (void *)hdr + sizeof(struct fc_ct_hdr), oct->len);
Swen Schillig57717102009-08-18 15:43:21 +0200710 spin_unlock_irqrestore(&dbf->san_lock, flags);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200711}
712
Martin Peschkebfab1632008-03-31 11:15:31 +0200713/**
Swen Schillig57717102009-08-18 15:43:21 +0200714 * zfcp_dbf_san_ct_response - trace event for completion of CT request
Martin Peschkebfab1632008-03-31 11:15:31 +0200715 * @fsf_req: request containing CT response
716 */
Swen Schillig57717102009-08-18 15:43:21 +0200717void zfcp_dbf_san_ct_response(struct zfcp_fsf_req *fsf_req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200718{
Christof Schmitt7c7dc192009-11-24 16:54:13 +0100719 struct zfcp_fsf_ct_els *ct = (struct zfcp_fsf_ct_els *)fsf_req->data;
720 struct zfcp_adapter *adapter = fsf_req->adapter;
Christof Schmittdbf5dfe2009-11-24 16:54:10 +0100721 struct fc_ct_hdr *hdr = sg_virt(ct->resp);
Christof Schmittd46f3842009-08-18 15:43:07 +0200722 struct zfcp_dbf *dbf = adapter->dbf;
Swen Schillig57717102009-08-18 15:43:21 +0200723 struct zfcp_dbf_san_record *r = &dbf->san_buf;
724 struct zfcp_dbf_san_record_ct_response *rct = &r->u.ct_resp;
Christof Schmittd94ce6c2008-11-04 16:35:12 +0100725 int level = 3;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200726 unsigned long flags;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200727
Swen Schillig57717102009-08-18 15:43:21 +0200728 spin_lock_irqsave(&dbf->san_lock, flags);
Martin Peschke6bc473d2008-03-31 11:15:29 +0200729 memset(r, 0, sizeof(*r));
730 strncpy(r->tag, "rctc", ZFCP_DBF_TAG_SIZE);
Christof Schmittf0216ae2009-05-15 13:18:14 +0200731 r->fsf_reqid = fsf_req->req_id;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200732 r->fsf_seqno = fsf_req->seq_no;
Christof Schmittdbf5dfe2009-11-24 16:54:10 +0100733 rct->cmd_rsp_code = hdr->ct_cmd;
734 rct->revision = hdr->ct_rev;
735 rct->reason_code = hdr->ct_reason;
736 rct->expl = hdr->ct_explan;
737 rct->vendor_unique = hdr->ct_vendor;
738 rct->max_res_size = hdr->ct_mr_size;
739 rct->len = min((int)ct->resp->length - (int)sizeof(struct fc_ct_hdr),
Christof Schmittd94ce6c2008-11-04 16:35:12 +0100740 ZFCP_DBF_SAN_MAX_PAYLOAD);
Swen Schillig57717102009-08-18 15:43:21 +0200741 debug_event(dbf->san, level, r, sizeof(*r));
742 zfcp_dbf_hexdump(dbf->san, r, sizeof(*r), level,
Christof Schmittdbf5dfe2009-11-24 16:54:10 +0100743 (void *)hdr + sizeof(struct fc_ct_hdr), rct->len);
Swen Schillig57717102009-08-18 15:43:21 +0200744 spin_unlock_irqrestore(&dbf->san_lock, flags);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200745}
746
Swen Schillig57717102009-08-18 15:43:21 +0200747static void zfcp_dbf_san_els(const char *tag, int level,
Christof Schmitt7c7dc192009-11-24 16:54:13 +0100748 struct zfcp_fsf_req *fsf_req, u32 d_id,
749 void *buffer, int buflen)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200750{
751 struct zfcp_adapter *adapter = fsf_req->adapter;
Christof Schmittd46f3842009-08-18 15:43:07 +0200752 struct zfcp_dbf *dbf = adapter->dbf;
Swen Schillig57717102009-08-18 15:43:21 +0200753 struct zfcp_dbf_san_record *rec = &dbf->san_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200754 unsigned long flags;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200755
Swen Schillig57717102009-08-18 15:43:21 +0200756 spin_lock_irqsave(&dbf->san_lock, flags);
Martin Peschke6bc473d2008-03-31 11:15:29 +0200757 memset(rec, 0, sizeof(*rec));
Martin Peschke0f65e952008-03-27 14:21:56 +0100758 strncpy(rec->tag, tag, ZFCP_DBF_TAG_SIZE);
Christof Schmittf0216ae2009-05-15 13:18:14 +0200759 rec->fsf_reqid = fsf_req->req_id;
Martin Peschke0f65e952008-03-27 14:21:56 +0100760 rec->fsf_seqno = fsf_req->seq_no;
Christof Schmitt7c7dc192009-11-24 16:54:13 +0100761 rec->u.els.d_id = d_id;
Swen Schillig57717102009-08-18 15:43:21 +0200762 debug_event(dbf->san, level, rec, sizeof(*rec));
763 zfcp_dbf_hexdump(dbf->san, rec, sizeof(*rec), level,
Christof Schmittd94ce6c2008-11-04 16:35:12 +0100764 buffer, min(buflen, ZFCP_DBF_SAN_MAX_PAYLOAD));
Swen Schillig57717102009-08-18 15:43:21 +0200765 spin_unlock_irqrestore(&dbf->san_lock, flags);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200766}
767
Martin Peschkebfab1632008-03-31 11:15:31 +0200768/**
Swen Schillig57717102009-08-18 15:43:21 +0200769 * zfcp_dbf_san_els_request - trace event for issued ELS
Martin Peschkebfab1632008-03-31 11:15:31 +0200770 * @fsf_req: request containing issued ELS
771 */
Swen Schillig57717102009-08-18 15:43:21 +0200772void zfcp_dbf_san_els_request(struct zfcp_fsf_req *fsf_req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200773{
Christof Schmitt7c7dc192009-11-24 16:54:13 +0100774 struct zfcp_fsf_ct_els *els = (struct zfcp_fsf_ct_els *)fsf_req->data;
775 u32 d_id = ntoh24(fsf_req->qtcb->bottom.support.d_id);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200776
Christof Schmitt7c7dc192009-11-24 16:54:13 +0100777 zfcp_dbf_san_els("oels", 2, fsf_req, d_id,
778 sg_virt(els->req), els->req->length);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200779}
780
Martin Peschkebfab1632008-03-31 11:15:31 +0200781/**
Swen Schillig57717102009-08-18 15:43:21 +0200782 * zfcp_dbf_san_els_response - trace event for completed ELS
Martin Peschkebfab1632008-03-31 11:15:31 +0200783 * @fsf_req: request containing ELS response
784 */
Swen Schillig57717102009-08-18 15:43:21 +0200785void zfcp_dbf_san_els_response(struct zfcp_fsf_req *fsf_req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200786{
Christof Schmitt7c7dc192009-11-24 16:54:13 +0100787 struct zfcp_fsf_ct_els *els = (struct zfcp_fsf_ct_els *)fsf_req->data;
788 u32 d_id = ntoh24(fsf_req->qtcb->bottom.support.d_id);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200789
Christof Schmitt7c7dc192009-11-24 16:54:13 +0100790 zfcp_dbf_san_els("rels", 2, fsf_req, d_id,
791 sg_virt(els->resp), els->resp->length);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200792}
793
Martin Peschkebfab1632008-03-31 11:15:31 +0200794/**
Swen Schillig57717102009-08-18 15:43:21 +0200795 * zfcp_dbf_san_incoming_els - trace event for incomig ELS
Martin Peschkebfab1632008-03-31 11:15:31 +0200796 * @fsf_req: request containing unsolicited status buffer with incoming ELS
797 */
Swen Schillig57717102009-08-18 15:43:21 +0200798void zfcp_dbf_san_incoming_els(struct zfcp_fsf_req *fsf_req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200799{
Martin Peschke92c7a832008-03-31 11:15:30 +0200800 struct fsf_status_read_buffer *buf =
801 (struct fsf_status_read_buffer *)fsf_req->data;
802 int length = (int)buf->length -
803 (int)((void *)&buf->payload - (void *)buf);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200804
Christof Schmitt800c0ca2009-11-24 16:54:12 +0100805 zfcp_dbf_san_els("iels", 1, fsf_req, ntoh24(buf->d_id),
Christof Schmitt7c7dc192009-11-24 16:54:13 +0100806 (void *)buf->payload.data, length);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200807}
808
Swen Schillig57717102009-08-18 15:43:21 +0200809static int zfcp_dbf_san_view_format(debug_info_t *id, struct debug_view *view,
Martin Peschke92c7a832008-03-31 11:15:30 +0200810 char *out_buf, const char *in_buf)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200811{
Swen Schillig57717102009-08-18 15:43:21 +0200812 struct zfcp_dbf_san_record *r = (struct zfcp_dbf_san_record *)in_buf;
Martin Peschkeb634fff2008-03-31 11:15:24 +0200813 char *p = out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200814
Martin Peschkeb634fff2008-03-31 11:15:24 +0200815 if (strncmp(r->tag, "dump", ZFCP_DBF_TAG_SIZE) == 0)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200816 return 0;
817
Martin Peschkea9c85772008-03-31 11:15:27 +0200818 zfcp_dbf_tag(&p, "tag", r->tag);
Martin Peschkeb634fff2008-03-31 11:15:24 +0200819 zfcp_dbf_out(&p, "fsf_reqid", "0x%0Lx", r->fsf_reqid);
820 zfcp_dbf_out(&p, "fsf_seqno", "0x%08x", r->fsf_seqno);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200821
Martin Peschkeb634fff2008-03-31 11:15:24 +0200822 if (strncmp(r->tag, "octc", ZFCP_DBF_TAG_SIZE) == 0) {
Swen Schillig57717102009-08-18 15:43:21 +0200823 struct zfcp_dbf_san_record_ct_request *ct = &r->u.ct_req;
Christof Schmitt7c7dc192009-11-24 16:54:13 +0100824 zfcp_dbf_out(&p, "d_id", "0x%06x", ct->d_id);
Martin Peschke6bc473d2008-03-31 11:15:29 +0200825 zfcp_dbf_out(&p, "cmd_req_code", "0x%04x", ct->cmd_req_code);
826 zfcp_dbf_out(&p, "revision", "0x%02x", ct->revision);
827 zfcp_dbf_out(&p, "gs_type", "0x%02x", ct->gs_type);
828 zfcp_dbf_out(&p, "gs_subtype", "0x%02x", ct->gs_subtype);
829 zfcp_dbf_out(&p, "options", "0x%02x", ct->options);
830 zfcp_dbf_out(&p, "max_res_size", "0x%04x", ct->max_res_size);
Martin Peschkeb634fff2008-03-31 11:15:24 +0200831 } else if (strncmp(r->tag, "rctc", ZFCP_DBF_TAG_SIZE) == 0) {
Swen Schillig57717102009-08-18 15:43:21 +0200832 struct zfcp_dbf_san_record_ct_response *ct = &r->u.ct_resp;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200833 zfcp_dbf_out(&p, "cmd_rsp_code", "0x%04x", ct->cmd_rsp_code);
834 zfcp_dbf_out(&p, "revision", "0x%02x", ct->revision);
835 zfcp_dbf_out(&p, "reason_code", "0x%02x", ct->reason_code);
836 zfcp_dbf_out(&p, "reason_code_expl", "0x%02x", ct->expl);
837 zfcp_dbf_out(&p, "vendor_unique", "0x%02x", ct->vendor_unique);
Christof Schmitt39eb7e9a2008-12-19 16:57:01 +0100838 zfcp_dbf_out(&p, "max_res_size", "0x%04x", ct->max_res_size);
Martin Peschkeb634fff2008-03-31 11:15:24 +0200839 } else if (strncmp(r->tag, "oels", ZFCP_DBF_TAG_SIZE) == 0 ||
840 strncmp(r->tag, "rels", ZFCP_DBF_TAG_SIZE) == 0 ||
841 strncmp(r->tag, "iels", ZFCP_DBF_TAG_SIZE) == 0) {
Swen Schillig57717102009-08-18 15:43:21 +0200842 struct zfcp_dbf_san_record_els *els = &r->u.els;
Christof Schmitt7c7dc192009-11-24 16:54:13 +0100843 zfcp_dbf_out(&p, "d_id", "0x%06x", els->d_id);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200844 }
Martin Peschkeb634fff2008-03-31 11:15:24 +0200845 return p - out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200846}
847
Swen Schillig57717102009-08-18 15:43:21 +0200848static struct debug_view zfcp_dbf_san_view = {
849 .name = "structured",
850 .header_proc = zfcp_dbf_view_header,
851 .format_proc = zfcp_dbf_san_view_format,
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200852};
853
Swen Schillig57717102009-08-18 15:43:21 +0200854void _zfcp_dbf_scsi(const char *tag, const char *tag2, int level,
855 struct zfcp_dbf *dbf, struct scsi_cmnd *scsi_cmnd,
856 struct zfcp_fsf_req *fsf_req, unsigned long old_req_id)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200857{
Swen Schillig57717102009-08-18 15:43:21 +0200858 struct zfcp_dbf_scsi_record *rec = &dbf->scsi_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200859 struct zfcp_dbf_dump *dump = (struct zfcp_dbf_dump *)rec;
860 unsigned long flags;
Christof Schmitt4318e082009-11-24 16:54:08 +0100861 struct fcp_resp_with_ext *fcp_rsp;
862 struct fcp_resp_rsp_info *fcp_rsp_info = NULL;
863 char *fcp_sns_info = NULL;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200864 int offset = 0, buflen = 0;
865
Swen Schillig57717102009-08-18 15:43:21 +0200866 spin_lock_irqsave(&dbf->scsi_lock, flags);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200867 do {
Martin Peschke6bc473d2008-03-31 11:15:29 +0200868 memset(rec, 0, sizeof(*rec));
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200869 if (offset == 0) {
870 strncpy(rec->tag, tag, ZFCP_DBF_TAG_SIZE);
871 strncpy(rec->tag2, tag2, ZFCP_DBF_TAG_SIZE);
Maxim Shchetynined829ad2006-02-11 01:42:58 +0100872 if (scsi_cmnd != NULL) {
873 if (scsi_cmnd->device) {
874 rec->scsi_id = scsi_cmnd->device->id;
875 rec->scsi_lun = scsi_cmnd->device->lun;
876 }
877 rec->scsi_result = scsi_cmnd->result;
878 rec->scsi_cmnd = (unsigned long)scsi_cmnd;
879 rec->scsi_serial = scsi_cmnd->serial_number;
Boaz Harrosh64a87b22008-04-30 11:19:47 +0300880 memcpy(rec->scsi_opcode, scsi_cmnd->cmnd,
Maxim Shchetynined829ad2006-02-11 01:42:58 +0100881 min((int)scsi_cmnd->cmd_len,
882 ZFCP_DBF_SCSI_OPCODE));
883 rec->scsi_retries = scsi_cmnd->retries;
884 rec->scsi_allowed = scsi_cmnd->allowed;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200885 }
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200886 if (fsf_req != NULL) {
Christof Schmitt4318e082009-11-24 16:54:08 +0100887 fcp_rsp = (struct fcp_resp_with_ext *)
888 &(fsf_req->qtcb->bottom.io.fcp_rsp);
889 fcp_rsp_info = (struct fcp_resp_rsp_info *)
890 &fcp_rsp[1];
891 fcp_sns_info = (char *) &fcp_rsp[1];
892 if (fcp_rsp->resp.fr_flags & FCP_RSP_LEN_VAL)
893 fcp_sns_info += fcp_rsp->ext.fr_sns_len;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200894
Christof Schmitt4318e082009-11-24 16:54:08 +0100895 rec->rsp_validity = fcp_rsp->resp.fr_flags;
896 rec->rsp_scsi_status = fcp_rsp->resp.fr_status;
897 rec->rsp_resid = fcp_rsp->ext.fr_resid;
898 if (fcp_rsp->resp.fr_flags & FCP_RSP_LEN_VAL)
899 rec->rsp_code = fcp_rsp_info->rsp_code;
900 if (fcp_rsp->resp.fr_flags & FCP_SNS_LEN_VAL) {
901 buflen = min(fcp_rsp->ext.fr_sns_len,
902 (u32)ZFCP_DBF_SCSI_MAX_FCP_SNS_INFO);
Martin Peschke6bc473d2008-03-31 11:15:29 +0200903 rec->sns_info_len = buflen;
904 memcpy(rec->sns_info, fcp_sns_info,
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200905 min(buflen,
906 ZFCP_DBF_SCSI_FCP_SNS_INFO));
907 offset += min(buflen,
908 ZFCP_DBF_SCSI_FCP_SNS_INFO);
909 }
910
Christof Schmittf0216ae2009-05-15 13:18:14 +0200911 rec->fsf_reqid = fsf_req->req_id;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200912 rec->fsf_seqno = fsf_req->seq_no;
913 rec->fsf_issued = fsf_req->issued;
914 }
Martin Peschke6bc473d2008-03-31 11:15:29 +0200915 rec->old_fsf_reqid = old_req_id;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200916 } else {
917 strncpy(dump->tag, "dump", ZFCP_DBF_TAG_SIZE);
918 dump->total_size = buflen;
919 dump->offset = offset;
920 dump->size = min(buflen - offset,
921 (int)sizeof(struct
Swen Schillig57717102009-08-18 15:43:21 +0200922 zfcp_dbf_scsi_record) -
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200923 (int)sizeof(struct zfcp_dbf_dump));
924 memcpy(dump->data, fcp_sns_info + offset, dump->size);
925 offset += dump->size;
926 }
Swen Schillig57717102009-08-18 15:43:21 +0200927 debug_event(dbf->scsi, level, rec, sizeof(*rec));
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200928 } while (offset < buflen);
Swen Schillig57717102009-08-18 15:43:21 +0200929 spin_unlock_irqrestore(&dbf->scsi_lock, flags);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200930}
931
Swen Schillig57717102009-08-18 15:43:21 +0200932static int zfcp_dbf_scsi_view_format(debug_info_t *id, struct debug_view *view,
Martin Peschke92c7a832008-03-31 11:15:30 +0200933 char *out_buf, const char *in_buf)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200934{
Swen Schillig57717102009-08-18 15:43:21 +0200935 struct zfcp_dbf_scsi_record *r = (struct zfcp_dbf_scsi_record *)in_buf;
Martin Peschke8fc5af12008-03-31 11:15:23 +0200936 struct timespec t;
Martin Peschkeb634fff2008-03-31 11:15:24 +0200937 char *p = out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200938
Martin Peschkeb634fff2008-03-31 11:15:24 +0200939 if (strncmp(r->tag, "dump", ZFCP_DBF_TAG_SIZE) == 0)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200940 return 0;
941
Martin Peschkea9c85772008-03-31 11:15:27 +0200942 zfcp_dbf_tag(&p, "tag", r->tag);
943 zfcp_dbf_tag(&p, "tag2", r->tag2);
Martin Peschkeb634fff2008-03-31 11:15:24 +0200944 zfcp_dbf_out(&p, "scsi_id", "0x%08x", r->scsi_id);
945 zfcp_dbf_out(&p, "scsi_lun", "0x%08x", r->scsi_lun);
946 zfcp_dbf_out(&p, "scsi_result", "0x%08x", r->scsi_result);
947 zfcp_dbf_out(&p, "scsi_cmnd", "0x%0Lx", r->scsi_cmnd);
948 zfcp_dbf_out(&p, "scsi_serial", "0x%016Lx", r->scsi_serial);
Martin Peschkedf29f4a2008-03-31 11:15:26 +0200949 zfcp_dbf_outd(&p, "scsi_opcode", r->scsi_opcode, ZFCP_DBF_SCSI_OPCODE,
950 0, ZFCP_DBF_SCSI_OPCODE);
Martin Peschkeb634fff2008-03-31 11:15:24 +0200951 zfcp_dbf_out(&p, "scsi_retries", "0x%02x", r->scsi_retries);
952 zfcp_dbf_out(&p, "scsi_allowed", "0x%02x", r->scsi_allowed);
953 if (strncmp(r->tag, "abrt", ZFCP_DBF_TAG_SIZE) == 0)
Martin Peschke6bc473d2008-03-31 11:15:29 +0200954 zfcp_dbf_out(&p, "old_fsf_reqid", "0x%0Lx", r->old_fsf_reqid);
Martin Peschkeb634fff2008-03-31 11:15:24 +0200955 zfcp_dbf_out(&p, "fsf_reqid", "0x%0Lx", r->fsf_reqid);
956 zfcp_dbf_out(&p, "fsf_seqno", "0x%08x", r->fsf_seqno);
Christof Schmittb592e892009-08-18 15:43:31 +0200957 stck_to_timespec(r->fsf_issued, &t);
Martin Peschkeb634fff2008-03-31 11:15:24 +0200958 zfcp_dbf_out(&p, "fsf_issued", "%011lu:%06lu", t.tv_sec, t.tv_nsec);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200959
Martin Peschkeb634fff2008-03-31 11:15:24 +0200960 if (strncmp(r->tag, "rslt", ZFCP_DBF_TAG_SIZE) == 0) {
Martin Peschke6bc473d2008-03-31 11:15:29 +0200961 zfcp_dbf_out(&p, "fcp_rsp_validity", "0x%02x", r->rsp_validity);
962 zfcp_dbf_out(&p, "fcp_rsp_scsi_status", "0x%02x",
963 r->rsp_scsi_status);
964 zfcp_dbf_out(&p, "fcp_rsp_resid", "0x%08x", r->rsp_resid);
965 zfcp_dbf_out(&p, "fcp_rsp_code", "0x%08x", r->rsp_code);
966 zfcp_dbf_out(&p, "fcp_sns_info_len", "0x%08x", r->sns_info_len);
967 zfcp_dbf_outd(&p, "fcp_sns_info", r->sns_info,
968 min((int)r->sns_info_len,
Martin Peschkedf29f4a2008-03-31 11:15:26 +0200969 ZFCP_DBF_SCSI_FCP_SNS_INFO), 0,
Martin Peschke6bc473d2008-03-31 11:15:29 +0200970 r->sns_info_len);
Martin Peschkeb634fff2008-03-31 11:15:24 +0200971 }
972 p += sprintf(p, "\n");
973 return p - out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200974}
975
Swen Schillig57717102009-08-18 15:43:21 +0200976static struct debug_view zfcp_dbf_scsi_view = {
977 .name = "structured",
978 .header_proc = zfcp_dbf_view_header,
979 .format_proc = zfcp_dbf_scsi_view_format,
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200980};
981
Christof Schmittd46f3842009-08-18 15:43:07 +0200982static debug_info_t *zfcp_dbf_reg(const char *name, int level,
983 struct debug_view *view, int size)
984{
985 struct debug_info *d;
986
987 d = debug_register(name, dbfsize, level, size);
988 if (!d)
989 return NULL;
990
991 debug_register_view(d, &debug_hex_ascii_view);
992 debug_register_view(d, view);
993 debug_set_level(d, level);
994
995 return d;
996}
997
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200998/**
999 * zfcp_adapter_debug_register - registers debug feature for an adapter
1000 * @adapter: pointer to adapter for which debug features should be registered
1001 * return: -ENOMEM on error, 0 otherwise
1002 */
Swen Schillig57717102009-08-18 15:43:21 +02001003int zfcp_dbf_adapter_register(struct zfcp_adapter *adapter)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001004{
1005 char dbf_name[DEBUG_MAX_NAME_LEN];
Christof Schmittd46f3842009-08-18 15:43:07 +02001006 struct zfcp_dbf *dbf;
1007
1008 dbf = kmalloc(sizeof(struct zfcp_dbf), GFP_KERNEL);
1009 if (!dbf)
1010 return -ENOMEM;
1011
Swen Schillig57717102009-08-18 15:43:21 +02001012 dbf->adapter = adapter;
1013
1014 spin_lock_init(&dbf->hba_lock);
1015 spin_lock_init(&dbf->san_lock);
1016 spin_lock_init(&dbf->scsi_lock);
1017 spin_lock_init(&dbf->rec_lock);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001018
1019 /* debug feature area which records recovery activity */
Christof Schmittb225cf92008-12-19 16:57:00 +01001020 sprintf(dbf_name, "zfcp_%s_rec", dev_name(&adapter->ccw_device->dev));
Swen Schillig57717102009-08-18 15:43:21 +02001021 dbf->rec = zfcp_dbf_reg(dbf_name, 3, &zfcp_dbf_rec_view,
1022 sizeof(struct zfcp_dbf_rec_record));
1023 if (!dbf->rec)
1024 goto err_out;
Martin Peschked79a83d2008-03-27 14:22:00 +01001025
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001026 /* debug feature area which records HBA (FSF and QDIO) conditions */
Christof Schmittb225cf92008-12-19 16:57:00 +01001027 sprintf(dbf_name, "zfcp_%s_hba", dev_name(&adapter->ccw_device->dev));
Swen Schillig57717102009-08-18 15:43:21 +02001028 dbf->hba = zfcp_dbf_reg(dbf_name, 3, &zfcp_dbf_hba_view,
1029 sizeof(struct zfcp_dbf_hba_record));
1030 if (!dbf->hba)
1031 goto err_out;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001032
1033 /* debug feature area which records SAN command failures and recovery */
Christof Schmittb225cf92008-12-19 16:57:00 +01001034 sprintf(dbf_name, "zfcp_%s_san", dev_name(&adapter->ccw_device->dev));
Swen Schillig57717102009-08-18 15:43:21 +02001035 dbf->san = zfcp_dbf_reg(dbf_name, 6, &zfcp_dbf_san_view,
1036 sizeof(struct zfcp_dbf_san_record));
1037 if (!dbf->san)
1038 goto err_out;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001039
1040 /* debug feature area which records SCSI command failures and recovery */
Christof Schmittb225cf92008-12-19 16:57:00 +01001041 sprintf(dbf_name, "zfcp_%s_scsi", dev_name(&adapter->ccw_device->dev));
Swen Schillig57717102009-08-18 15:43:21 +02001042 dbf->scsi = zfcp_dbf_reg(dbf_name, 3, &zfcp_dbf_scsi_view,
1043 sizeof(struct zfcp_dbf_scsi_record));
1044 if (!dbf->scsi)
1045 goto err_out;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001046
Christof Schmittd46f3842009-08-18 15:43:07 +02001047 adapter->dbf = dbf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001048 return 0;
1049
Swen Schillig57717102009-08-18 15:43:21 +02001050err_out:
1051 zfcp_dbf_adapter_unregister(dbf);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001052 return -ENOMEM;
1053}
1054
1055/**
1056 * zfcp_adapter_debug_unregister - unregisters debug feature for an adapter
Swen Schillig57717102009-08-18 15:43:21 +02001057 * @dbf: pointer to dbf for which debug features should be unregistered
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001058 */
Swen Schillig57717102009-08-18 15:43:21 +02001059void zfcp_dbf_adapter_unregister(struct zfcp_dbf *dbf)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001060{
Swen Schilligf3450c72009-11-24 16:53:59 +01001061 if (!dbf)
1062 return;
Swen Schillig57717102009-08-18 15:43:21 +02001063 debug_unregister(dbf->scsi);
1064 debug_unregister(dbf->san);
1065 debug_unregister(dbf->hba);
1066 debug_unregister(dbf->rec);
1067 dbf->adapter->dbf = NULL;
1068 kfree(dbf);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001069}
Swen Schillig57717102009-08-18 15:43:21 +02001070