blob: e945344ff711202e1387b0a22e381777b966d59a [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>
Heiko Carstens364c8552007-10-12 16:11:35 +020013#include <asm/debug.h>
Christof Schmittd46f3842009-08-18 15:43:07 +020014#include "zfcp_dbf.h"
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020015#include "zfcp_ext.h"
Christof Schmittbd0072e2009-11-24 16:54:11 +010016#include "zfcp_fc.h"
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020017
18static u32 dbfsize = 4;
19
20module_param(dbfsize, uint, 0400);
21MODULE_PARM_DESC(dbfsize,
22 "number of pages for each debug feature area (default 4)");
23
Martin Peschkec15450e2008-03-27 14:21:55 +010024static void zfcp_dbf_hexdump(debug_info_t *dbf, void *to, int to_len,
25 int level, char *from, int from_len)
26{
27 int offset;
28 struct zfcp_dbf_dump *dump = to;
29 int room = to_len - sizeof(*dump);
30
31 for (offset = 0; offset < from_len; offset += dump->size) {
32 memset(to, 0, to_len);
33 strncpy(dump->tag, "dump", ZFCP_DBF_TAG_SIZE);
34 dump->total_size = from_len;
35 dump->offset = offset;
36 dump->size = min(from_len - offset, room);
37 memcpy(dump->data, from + offset, dump->size);
Christof Schmittd94ce6c2008-11-04 16:35:12 +010038 debug_event(dbf, level, dump, dump->size + sizeof(*dump));
Martin Peschkec15450e2008-03-27 14:21:55 +010039 }
40}
41
Martin Peschkea9c85772008-03-31 11:15:27 +020042static void zfcp_dbf_tag(char **p, const char *label, const char *tag)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020043{
Martin Peschkea9c85772008-03-31 11:15:27 +020044 int i;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020045
Martin Peschkea9c85772008-03-31 11:15:27 +020046 *p += sprintf(*p, "%-24s", label);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020047 for (i = 0; i < ZFCP_DBF_TAG_SIZE; i++)
Martin Peschkea9c85772008-03-31 11:15:27 +020048 *p += sprintf(*p, "%c", tag[i]);
49 *p += sprintf(*p, "\n");
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020050}
51
Martin Peschke10223c62008-03-27 14:21:59 +010052static void zfcp_dbf_outs(char **buf, const char *s1, const char *s2)
53{
54 *buf += sprintf(*buf, "%-24s%s\n", s1, s2);
55}
56
57static void zfcp_dbf_out(char **buf, const char *s, const char *format, ...)
58{
59 va_list arg;
60
61 *buf += sprintf(*buf, "%-24s", s);
62 va_start(arg, format);
63 *buf += vsprintf(*buf, format, arg);
64 va_end(arg);
65 *buf += sprintf(*buf, "\n");
66}
67
Martin Peschkedf29f4a2008-03-31 11:15:26 +020068static void zfcp_dbf_outd(char **p, const char *label, char *buffer,
69 int buflen, int offset, int total_size)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020070{
Martin Peschkedf29f4a2008-03-31 11:15:26 +020071 if (!offset)
72 *p += sprintf(*p, "%-24s ", label);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020073 while (buflen--) {
74 if (offset > 0) {
75 if ((offset % 32) == 0)
Martin Peschkedf29f4a2008-03-31 11:15:26 +020076 *p += sprintf(*p, "\n%-24c ", ' ');
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020077 else if ((offset % 4) == 0)
Martin Peschkedf29f4a2008-03-31 11:15:26 +020078 *p += sprintf(*p, " ");
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020079 }
Martin Peschkedf29f4a2008-03-31 11:15:26 +020080 *p += sprintf(*p, "%02x", *buffer++);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020081 if (++offset == total_size) {
Martin Peschkedf29f4a2008-03-31 11:15:26 +020082 *p += sprintf(*p, "\n");
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020083 break;
84 }
85 }
Martin Peschkedf29f4a2008-03-31 11:15:26 +020086 if (!total_size)
87 *p += sprintf(*p, "\n");
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020088}
89
Martin Peschke92c7a832008-03-31 11:15:30 +020090static int zfcp_dbf_view_header(debug_info_t *id, struct debug_view *view,
91 int area, debug_entry_t *entry, char *out_buf)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020092{
93 struct zfcp_dbf_dump *dump = (struct zfcp_dbf_dump *)DEBUG_DATA(entry);
Martin Peschke8fc5af12008-03-31 11:15:23 +020094 struct timespec t;
Martin Peschkeb634fff2008-03-31 11:15:24 +020095 char *p = out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020096
97 if (strncmp(dump->tag, "dump", ZFCP_DBF_TAG_SIZE) != 0) {
Christof Schmittb592e892009-08-18 15:43:31 +020098 stck_to_timespec(entry->id.stck, &t);
Martin Peschkeb634fff2008-03-31 11:15:24 +020099 zfcp_dbf_out(&p, "timestamp", "%011lu:%06lu",
100 t.tv_sec, t.tv_nsec);
101 zfcp_dbf_out(&p, "cpu", "%02i", entry->id.fields.cpuid);
102 } else {
Christof Schmittd94ce6c2008-11-04 16:35:12 +0100103 zfcp_dbf_outd(&p, "", dump->data, dump->size, dump->offset,
Martin Peschkedf29f4a2008-03-31 11:15:26 +0200104 dump->total_size);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200105 if ((dump->offset + dump->size) == dump->total_size)
Martin Peschkeb634fff2008-03-31 11:15:24 +0200106 p += sprintf(p, "\n");
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200107 }
Martin Peschkeb634fff2008-03-31 11:15:24 +0200108 return p - out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200109}
110
Swen Schillig57717102009-08-18 15:43:21 +0200111void _zfcp_dbf_hba_fsf_response(const char *tag2, int level,
112 struct zfcp_fsf_req *fsf_req,
113 struct zfcp_dbf *dbf)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200114{
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200115 struct fsf_qtcb *qtcb = fsf_req->qtcb;
116 union fsf_prot_status_qual *prot_status_qual =
Martin Peschke92c7a832008-03-31 11:15:30 +0200117 &qtcb->prefix.prot_status_qual;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200118 union fsf_status_qual *fsf_status_qual = &qtcb->header.fsf_status_qual;
119 struct scsi_cmnd *scsi_cmnd;
120 struct zfcp_port *port;
121 struct zfcp_unit *unit;
122 struct zfcp_send_els *send_els;
Swen Schillig57717102009-08-18 15:43:21 +0200123 struct zfcp_dbf_hba_record *rec = &dbf->hba_buf;
124 struct zfcp_dbf_hba_record_response *response = &rec->u.response;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200125 unsigned long flags;
126
Swen Schillig57717102009-08-18 15:43:21 +0200127 spin_lock_irqsave(&dbf->hba_lock, flags);
Martin Peschke6bc473d2008-03-31 11:15:29 +0200128 memset(rec, 0, sizeof(*rec));
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200129 strncpy(rec->tag, "resp", ZFCP_DBF_TAG_SIZE);
Christof Schmitt2e261af2009-08-18 15:43:09 +0200130 strncpy(rec->tag2, tag2, ZFCP_DBF_TAG_SIZE);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200131
132 response->fsf_command = fsf_req->fsf_command;
Christof Schmittf0216ae2009-05-15 13:18:14 +0200133 response->fsf_reqid = fsf_req->req_id;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200134 response->fsf_seqno = fsf_req->seq_no;
135 response->fsf_issued = fsf_req->issued;
136 response->fsf_prot_status = qtcb->prefix.prot_status;
137 response->fsf_status = qtcb->header.fsf_status;
138 memcpy(response->fsf_prot_status_qual,
139 prot_status_qual, FSF_PROT_STATUS_QUAL_SIZE);
140 memcpy(response->fsf_status_qual,
141 fsf_status_qual, FSF_STATUS_QUALIFIER_SIZE);
142 response->fsf_req_status = fsf_req->status;
Swen Schillig42428f72009-08-18 15:43:18 +0200143 response->sbal_first = fsf_req->queue_req.sbal_first;
144 response->sbal_last = fsf_req->queue_req.sbal_last;
145 response->sbal_response = fsf_req->queue_req.sbal_response;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200146 response->pool = fsf_req->pool != NULL;
147 response->erp_action = (unsigned long)fsf_req->erp_action;
148
149 switch (fsf_req->fsf_command) {
150 case FSF_QTCB_FCP_CMND:
151 if (fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT)
152 break;
153 scsi_cmnd = (struct scsi_cmnd *)fsf_req->data;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200154 if (scsi_cmnd) {
155 response->u.fcp.cmnd = (unsigned long)scsi_cmnd;
156 response->u.fcp.serial = scsi_cmnd->serial_number;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200157 }
158 break;
159
160 case FSF_QTCB_OPEN_PORT_WITH_DID:
161 case FSF_QTCB_CLOSE_PORT:
162 case FSF_QTCB_CLOSE_PHYSICAL_PORT:
163 port = (struct zfcp_port *)fsf_req->data;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200164 response->u.port.wwpn = port->wwpn;
165 response->u.port.d_id = port->d_id;
166 response->u.port.port_handle = qtcb->header.port_handle;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200167 break;
168
169 case FSF_QTCB_OPEN_LUN:
170 case FSF_QTCB_CLOSE_LUN:
171 unit = (struct zfcp_unit *)fsf_req->data;
172 port = unit->port;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200173 response->u.unit.wwpn = port->wwpn;
174 response->u.unit.fcp_lun = unit->fcp_lun;
175 response->u.unit.port_handle = qtcb->header.port_handle;
176 response->u.unit.lun_handle = qtcb->header.lun_handle;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200177 break;
178
179 case FSF_QTCB_SEND_ELS:
180 send_els = (struct zfcp_send_els *)fsf_req->data;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200181 response->u.els.d_id = qtcb->bottom.support.d_id;
182 response->u.els.ls_code = send_els->ls_code >> 24;
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 Schmittd94ce6c2008-11-04 16:35:12 +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);
352 zfcp_dbf_out(p, "ls_code", "0x%02x", r->u.els.ls_code);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200353 break;
354
355 case FSF_QTCB_ABORT_FCP_CMND:
356 case FSF_QTCB_SEND_GENERIC:
357 case FSF_QTCB_EXCHANGE_CONFIG_DATA:
358 case FSF_QTCB_EXCHANGE_PORT_DATA:
359 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
360 case FSF_QTCB_UPLOAD_CONTROL_FILE:
361 break;
362 }
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200363}
364
Swen Schillig57717102009-08-18 15:43:21 +0200365static void zfcp_dbf_hba_view_status(char **p,
366 struct zfcp_dbf_hba_record_status *r)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200367{
Martin Peschkea9c85772008-03-31 11:15:27 +0200368 zfcp_dbf_out(p, "failed", "0x%02x", r->failed);
369 zfcp_dbf_out(p, "status_type", "0x%08x", r->status_type);
370 zfcp_dbf_out(p, "status_subtype", "0x%08x", r->status_subtype);
371 zfcp_dbf_outd(p, "queue_designator", (char *)&r->queue_designator,
Martin Peschkedf29f4a2008-03-31 11:15:26 +0200372 sizeof(struct fsf_queue_designator), 0,
373 sizeof(struct fsf_queue_designator));
Martin Peschkea9c85772008-03-31 11:15:27 +0200374 zfcp_dbf_outd(p, "payload", (char *)&r->payload, r->payload_size, 0,
Martin Peschkedf29f4a2008-03-31 11:15:26 +0200375 r->payload_size);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200376}
377
Swen Schillig57717102009-08-18 15:43:21 +0200378static void zfcp_dbf_hba_view_qdio(char **p, struct zfcp_dbf_hba_record_qdio *r)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200379{
Martin Peschkea9c85772008-03-31 11:15:27 +0200380 zfcp_dbf_out(p, "qdio_error", "0x%08x", r->qdio_error);
Martin Peschkea9c85772008-03-31 11:15:27 +0200381 zfcp_dbf_out(p, "sbal_index", "0x%02x", r->sbal_index);
382 zfcp_dbf_out(p, "sbal_count", "0x%02x", r->sbal_count);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200383}
384
Swen Schillig57717102009-08-18 15:43:21 +0200385static void zfcp_dbf_hba_view_berr(char **p, struct fsf_bit_error_payload *r)
Swen Schillig57069382008-10-01 12:42:21 +0200386{
387 zfcp_dbf_out(p, "link_failures", "%d", r->link_failure_error_count);
388 zfcp_dbf_out(p, "loss_of_sync_err", "%d", r->loss_of_sync_error_count);
389 zfcp_dbf_out(p, "loss_of_sig_err", "%d", r->loss_of_signal_error_count);
390 zfcp_dbf_out(p, "prim_seq_err", "%d",
391 r->primitive_sequence_error_count);
392 zfcp_dbf_out(p, "inval_trans_word_err", "%d",
393 r->invalid_transmission_word_error_count);
394 zfcp_dbf_out(p, "CRC_errors", "%d", r->crc_error_count);
395 zfcp_dbf_out(p, "prim_seq_event_to", "%d",
396 r->primitive_sequence_event_timeout_count);
397 zfcp_dbf_out(p, "elast_buf_overrun_err", "%d",
398 r->elastic_buffer_overrun_error_count);
399 zfcp_dbf_out(p, "adv_rec_buf2buf_cred", "%d",
400 r->advertised_receive_b2b_credit);
401 zfcp_dbf_out(p, "curr_rec_buf2buf_cred", "%d",
402 r->current_receive_b2b_credit);
403 zfcp_dbf_out(p, "adv_trans_buf2buf_cred", "%d",
404 r->advertised_transmit_b2b_credit);
405 zfcp_dbf_out(p, "curr_trans_buf2buf_cred", "%d",
406 r->current_transmit_b2b_credit);
407}
408
Swen Schillig57717102009-08-18 15:43:21 +0200409static int zfcp_dbf_hba_view_format(debug_info_t *id, struct debug_view *view,
Martin Peschkea9c85772008-03-31 11:15:27 +0200410 char *out_buf, const char *in_buf)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200411{
Swen Schillig57717102009-08-18 15:43:21 +0200412 struct zfcp_dbf_hba_record *r = (struct zfcp_dbf_hba_record *)in_buf;
Martin Peschkea9c85772008-03-31 11:15:27 +0200413 char *p = out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200414
Martin Peschkea9c85772008-03-31 11:15:27 +0200415 if (strncmp(r->tag, "dump", ZFCP_DBF_TAG_SIZE) == 0)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200416 return 0;
417
Martin Peschkea9c85772008-03-31 11:15:27 +0200418 zfcp_dbf_tag(&p, "tag", r->tag);
419 if (isalpha(r->tag2[0]))
420 zfcp_dbf_tag(&p, "tag2", r->tag2);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200421
Martin Peschkea9c85772008-03-31 11:15:27 +0200422 if (strncmp(r->tag, "resp", ZFCP_DBF_TAG_SIZE) == 0)
Swen Schillig57717102009-08-18 15:43:21 +0200423 zfcp_dbf_hba_view_response(&p, &r->u.response);
Martin Peschkea9c85772008-03-31 11:15:27 +0200424 else if (strncmp(r->tag, "stat", ZFCP_DBF_TAG_SIZE) == 0)
Swen Schillig57717102009-08-18 15:43:21 +0200425 zfcp_dbf_hba_view_status(&p, &r->u.status);
Martin Peschkea9c85772008-03-31 11:15:27 +0200426 else if (strncmp(r->tag, "qdio", ZFCP_DBF_TAG_SIZE) == 0)
Swen Schillig57717102009-08-18 15:43:21 +0200427 zfcp_dbf_hba_view_qdio(&p, &r->u.qdio);
Swen Schillig57069382008-10-01 12:42:21 +0200428 else if (strncmp(r->tag, "berr", ZFCP_DBF_TAG_SIZE) == 0)
Swen Schillig57717102009-08-18 15:43:21 +0200429 zfcp_dbf_hba_view_berr(&p, &r->u.berr);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200430
Christof Schmittd94ce6c2008-11-04 16:35:12 +0100431 if (strncmp(r->tag, "resp", ZFCP_DBF_TAG_SIZE) != 0)
432 p += sprintf(p, "\n");
Martin Peschkea9c85772008-03-31 11:15:27 +0200433 return p - out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200434}
435
Swen Schillig57717102009-08-18 15:43:21 +0200436static struct debug_view zfcp_dbf_hba_view = {
437 .name = "structured",
438 .header_proc = zfcp_dbf_view_header,
439 .format_proc = zfcp_dbf_hba_view_format,
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200440};
441
Swen Schillig57717102009-08-18 15:43:21 +0200442static const char *zfcp_dbf_rec_tags[] = {
Martin Peschke348447e2008-03-27 14:22:01 +0100443 [ZFCP_REC_DBF_ID_THREAD] = "thread",
Martin Peschke698ec0162008-03-27 14:22:02 +0100444 [ZFCP_REC_DBF_ID_TARGET] = "target",
Martin Peschke9467a9b2008-03-27 14:22:03 +0100445 [ZFCP_REC_DBF_ID_TRIGGER] = "trigger",
Martin Peschke6f4f3652008-03-27 14:22:04 +0100446 [ZFCP_REC_DBF_ID_ACTION] = "action",
Martin Peschked79a83d2008-03-27 14:22:00 +0100447};
448
Swen Schillig57717102009-08-18 15:43:21 +0200449static int zfcp_dbf_rec_view_format(debug_info_t *id, struct debug_view *view,
Martin Peschked79a83d2008-03-27 14:22:00 +0100450 char *buf, const char *_rec)
451{
Swen Schillig57717102009-08-18 15:43:21 +0200452 struct zfcp_dbf_rec_record *r = (struct zfcp_dbf_rec_record *)_rec;
Martin Peschked79a83d2008-03-27 14:22:00 +0100453 char *p = buf;
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100454 char hint[ZFCP_DBF_ID_SIZE + 1];
Martin Peschked79a83d2008-03-27 14:22:00 +0100455
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100456 memcpy(hint, r->id2, ZFCP_DBF_ID_SIZE);
457 hint[ZFCP_DBF_ID_SIZE] = 0;
Swen Schillig57717102009-08-18 15:43:21 +0200458 zfcp_dbf_outs(&p, "tag", zfcp_dbf_rec_tags[r->id]);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100459 zfcp_dbf_outs(&p, "hint", hint);
Martin Peschked79a83d2008-03-27 14:22:00 +0100460 switch (r->id) {
Martin Peschke348447e2008-03-27 14:22:01 +0100461 case ZFCP_REC_DBF_ID_THREAD:
Martin Peschke348447e2008-03-27 14:22:01 +0100462 zfcp_dbf_out(&p, "total", "%d", r->u.thread.total);
463 zfcp_dbf_out(&p, "ready", "%d", r->u.thread.ready);
464 zfcp_dbf_out(&p, "running", "%d", r->u.thread.running);
465 break;
Martin Peschke698ec0162008-03-27 14:22:02 +0100466 case ZFCP_REC_DBF_ID_TARGET:
467 zfcp_dbf_out(&p, "reference", "0x%016Lx", r->u.target.ref);
468 zfcp_dbf_out(&p, "status", "0x%08x", r->u.target.status);
469 zfcp_dbf_out(&p, "erp_count", "%d", r->u.target.erp_count);
470 zfcp_dbf_out(&p, "d_id", "0x%06x", r->u.target.d_id);
471 zfcp_dbf_out(&p, "wwpn", "0x%016Lx", r->u.target.wwpn);
472 zfcp_dbf_out(&p, "fcp_lun", "0x%016Lx", r->u.target.fcp_lun);
473 break;
Martin Peschke9467a9b2008-03-27 14:22:03 +0100474 case ZFCP_REC_DBF_ID_TRIGGER:
475 zfcp_dbf_out(&p, "reference", "0x%016Lx", r->u.trigger.ref);
476 zfcp_dbf_out(&p, "erp_action", "0x%016Lx", r->u.trigger.action);
477 zfcp_dbf_out(&p, "requested", "%d", r->u.trigger.want);
478 zfcp_dbf_out(&p, "executed", "%d", r->u.trigger.need);
479 zfcp_dbf_out(&p, "wwpn", "0x%016Lx", r->u.trigger.wwpn);
480 zfcp_dbf_out(&p, "fcp_lun", "0x%016Lx", r->u.trigger.fcp_lun);
481 zfcp_dbf_out(&p, "adapter_status", "0x%08x", r->u.trigger.as);
482 zfcp_dbf_out(&p, "port_status", "0x%08x", r->u.trigger.ps);
483 zfcp_dbf_out(&p, "unit_status", "0x%08x", r->u.trigger.us);
484 break;
Martin Peschke6f4f3652008-03-27 14:22:04 +0100485 case ZFCP_REC_DBF_ID_ACTION:
486 zfcp_dbf_out(&p, "erp_action", "0x%016Lx", r->u.action.action);
487 zfcp_dbf_out(&p, "fsf_req", "0x%016Lx", r->u.action.fsf_req);
488 zfcp_dbf_out(&p, "status", "0x%08Lx", r->u.action.status);
489 zfcp_dbf_out(&p, "step", "0x%08Lx", r->u.action.step);
490 break;
Martin Peschked79a83d2008-03-27 14:22:00 +0100491 }
Martin Peschkeb634fff2008-03-31 11:15:24 +0200492 p += sprintf(p, "\n");
493 return p - buf;
Martin Peschked79a83d2008-03-27 14:22:00 +0100494}
495
Swen Schillig57717102009-08-18 15:43:21 +0200496static struct debug_view zfcp_dbf_rec_view = {
497 .name = "structured",
498 .header_proc = zfcp_dbf_view_header,
499 .format_proc = zfcp_dbf_rec_view_format,
Martin Peschked79a83d2008-03-27 14:22:00 +0100500};
501
Martin Peschke348447e2008-03-27 14:22:01 +0100502/**
Swen Schillig57717102009-08-18 15:43:21 +0200503 * zfcp_dbf_rec_thread - trace event related to recovery thread operation
Martin Peschke348447e2008-03-27 14:22:01 +0100504 * @id2: identifier for event
Swen Schillig57717102009-08-18 15:43:21 +0200505 * @dbf: reference to dbf structure
Christof Schmittaa0fec62008-05-19 12:17:47 +0200506 * This function assumes that the caller is holding erp_lock.
Martin Peschke348447e2008-03-27 14:22:01 +0100507 */
Swen Schillig57717102009-08-18 15:43:21 +0200508void zfcp_dbf_rec_thread(char *id2, struct zfcp_dbf *dbf)
Martin Peschke348447e2008-03-27 14:22:01 +0100509{
Swen Schillig57717102009-08-18 15:43:21 +0200510 struct zfcp_adapter *adapter = dbf->adapter;
511 struct zfcp_dbf_rec_record *r = &dbf->rec_buf;
Martin Peschke348447e2008-03-27 14:22:01 +0100512 unsigned long flags = 0;
513 struct list_head *entry;
514 unsigned ready = 0, running = 0, total;
515
Martin Peschke348447e2008-03-27 14:22:01 +0100516 list_for_each(entry, &adapter->erp_ready_head)
517 ready++;
518 list_for_each(entry, &adapter->erp_running_head)
519 running++;
520 total = adapter->erp_total_count;
Martin Peschke348447e2008-03-27 14:22:01 +0100521
Swen Schillig57717102009-08-18 15:43:21 +0200522 spin_lock_irqsave(&dbf->rec_lock, flags);
Martin Peschke348447e2008-03-27 14:22:01 +0100523 memset(r, 0, sizeof(*r));
524 r->id = ZFCP_REC_DBF_ID_THREAD;
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100525 memcpy(r->id2, id2, ZFCP_DBF_ID_SIZE);
Martin Peschke348447e2008-03-27 14:22:01 +0100526 r->u.thread.total = total;
527 r->u.thread.ready = ready;
528 r->u.thread.running = running;
Swen Schillig57717102009-08-18 15:43:21 +0200529 debug_event(dbf->rec, 6, r, sizeof(*r));
530 spin_unlock_irqrestore(&dbf->rec_lock, flags);
Martin Peschke348447e2008-03-27 14:22:01 +0100531}
532
Christof Schmittaa0fec62008-05-19 12:17:47 +0200533/**
Swen Schillig57717102009-08-18 15:43:21 +0200534 * zfcp_dbf_rec_thread - trace event related to recovery thread operation
Christof Schmittaa0fec62008-05-19 12:17:47 +0200535 * @id2: identifier for event
536 * @adapter: adapter
537 * This function assumes that the caller does not hold erp_lock.
538 */
Swen Schillig57717102009-08-18 15:43:21 +0200539void zfcp_dbf_rec_thread_lock(char *id2, struct zfcp_dbf *dbf)
Christof Schmittaa0fec62008-05-19 12:17:47 +0200540{
Swen Schillig57717102009-08-18 15:43:21 +0200541 struct zfcp_adapter *adapter = dbf->adapter;
Christof Schmittaa0fec62008-05-19 12:17:47 +0200542 unsigned long flags;
543
544 read_lock_irqsave(&adapter->erp_lock, flags);
Swen Schillig57717102009-08-18 15:43:21 +0200545 zfcp_dbf_rec_thread(id2, dbf);
Christof Schmittaa0fec62008-05-19 12:17:47 +0200546 read_unlock_irqrestore(&adapter->erp_lock, flags);
547}
548
Swen Schillig57717102009-08-18 15:43:21 +0200549static void zfcp_dbf_rec_target(char *id2, void *ref, struct zfcp_dbf *dbf,
550 atomic_t *status, atomic_t *erp_count, u64 wwpn,
551 u32 d_id, u64 fcp_lun)
Martin Peschke698ec0162008-03-27 14:22:02 +0100552{
Swen Schillig57717102009-08-18 15:43:21 +0200553 struct zfcp_dbf_rec_record *r = &dbf->rec_buf;
Martin Peschke698ec0162008-03-27 14:22:02 +0100554 unsigned long flags;
555
Swen Schillig57717102009-08-18 15:43:21 +0200556 spin_lock_irqsave(&dbf->rec_lock, flags);
Martin Peschke698ec0162008-03-27 14:22:02 +0100557 memset(r, 0, sizeof(*r));
558 r->id = ZFCP_REC_DBF_ID_TARGET;
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100559 memcpy(r->id2, id2, ZFCP_DBF_ID_SIZE);
Martin Peschke1f6f7122008-04-18 12:51:55 +0200560 r->u.target.ref = (unsigned long)ref;
Martin Peschke698ec0162008-03-27 14:22:02 +0100561 r->u.target.status = atomic_read(status);
562 r->u.target.wwpn = wwpn;
563 r->u.target.d_id = d_id;
564 r->u.target.fcp_lun = fcp_lun;
565 r->u.target.erp_count = atomic_read(erp_count);
Swen Schillig57717102009-08-18 15:43:21 +0200566 debug_event(dbf->rec, 3, r, sizeof(*r));
567 spin_unlock_irqrestore(&dbf->rec_lock, flags);
Martin Peschke698ec0162008-03-27 14:22:02 +0100568}
569
570/**
Swen Schillig57717102009-08-18 15:43:21 +0200571 * zfcp_dbf_rec_adapter - trace event for adapter state change
Martin Peschke698ec0162008-03-27 14:22:02 +0100572 * @id: identifier for trigger of state change
573 * @ref: additional reference (e.g. request)
Swen Schillig57717102009-08-18 15:43:21 +0200574 * @dbf: reference to dbf structure
Martin Peschke698ec0162008-03-27 14:22:02 +0100575 */
Swen Schillig57717102009-08-18 15:43:21 +0200576void zfcp_dbf_rec_adapter(char *id, void *ref, struct zfcp_dbf *dbf)
Martin Peschke698ec0162008-03-27 14:22:02 +0100577{
Swen Schillig57717102009-08-18 15:43:21 +0200578 struct zfcp_adapter *adapter = dbf->adapter;
579
580 zfcp_dbf_rec_target(id, ref, dbf, &adapter->status,
Martin Peschke698ec0162008-03-27 14:22:02 +0100581 &adapter->erp_counter, 0, 0, 0);
582}
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,
Martin Peschke698ec0162008-03-27 14:22:02 +0100595 &port->erp_counter, port->wwpn, port->d_id,
596 0);
597}
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 }
647 if (unit) {
648 r->u.trigger.us = atomic_read(&unit->status);
649 r->u.trigger.fcp_lun = unit->fcp_lun;
650 }
Swen Schillig57717102009-08-18 15:43:21 +0200651 debug_event(dbf->rec, action ? 1 : 4, r, sizeof(*r));
652 spin_unlock_irqrestore(&dbf->rec_lock, flags);
Martin Peschke9467a9b2008-03-27 14:22:03 +0100653}
654
Martin Peschke6f4f3652008-03-27 14:22:04 +0100655/**
Swen Schillig57717102009-08-18 15:43:21 +0200656 * zfcp_dbf_rec_action - trace event showing progress of recovery action
Martin Peschke6f4f3652008-03-27 14:22:04 +0100657 * @id2: identifier
658 * @erp_action: error recovery action struct pointer
659 */
Swen Schillig57717102009-08-18 15:43:21 +0200660void zfcp_dbf_rec_action(char *id2, struct zfcp_erp_action *erp_action)
Martin Peschke6f4f3652008-03-27 14:22:04 +0100661{
Swen Schillig57717102009-08-18 15:43:21 +0200662 struct zfcp_dbf *dbf = erp_action->adapter->dbf;
663 struct zfcp_dbf_rec_record *r = &dbf->rec_buf;
Martin Peschke6f4f3652008-03-27 14:22:04 +0100664 unsigned long flags;
665
Swen Schillig57717102009-08-18 15:43:21 +0200666 spin_lock_irqsave(&dbf->rec_lock, flags);
Martin Peschke6f4f3652008-03-27 14:22:04 +0100667 memset(r, 0, sizeof(*r));
668 r->id = ZFCP_REC_DBF_ID_ACTION;
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100669 memcpy(r->id2, id2, ZFCP_DBF_ID_SIZE);
Martin Peschke1f6f7122008-04-18 12:51:55 +0200670 r->u.action.action = (unsigned long)erp_action;
Martin Peschke6f4f3652008-03-27 14:22:04 +0100671 r->u.action.status = erp_action->status;
672 r->u.action.step = erp_action->step;
Martin Peschke1f6f7122008-04-18 12:51:55 +0200673 r->u.action.fsf_req = (unsigned long)erp_action->fsf_req;
Swen Schillig57717102009-08-18 15:43:21 +0200674 debug_event(dbf->rec, 5, r, sizeof(*r));
675 spin_unlock_irqrestore(&dbf->rec_lock, flags);
Martin Peschke6f4f3652008-03-27 14:22:04 +0100676}
677
Martin Peschkebfab1632008-03-31 11:15:31 +0200678/**
Swen Schillig57717102009-08-18 15:43:21 +0200679 * zfcp_dbf_san_ct_request - trace event for issued CT request
Martin Peschkebfab1632008-03-31 11:15:31 +0200680 * @fsf_req: request containing issued CT data
681 */
Swen Schillig57717102009-08-18 15:43:21 +0200682void zfcp_dbf_san_ct_request(struct zfcp_fsf_req *fsf_req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200683{
684 struct zfcp_send_ct *ct = (struct zfcp_send_ct *)fsf_req->data;
Christof Schmittbd0072e2009-11-24 16:54:11 +0100685 struct zfcp_fc_wka_port *wka_port = ct->wka_port;
Swen Schillig5ab944f2008-10-01 12:42:17 +0200686 struct zfcp_adapter *adapter = wka_port->adapter;
Christof Schmittd46f3842009-08-18 15:43:07 +0200687 struct zfcp_dbf *dbf = adapter->dbf;
Christof Schmittdbf5dfe2009-11-24 16:54:10 +0100688 struct fc_ct_hdr *hdr = sg_virt(ct->req);
Swen Schillig57717102009-08-18 15:43:21 +0200689 struct zfcp_dbf_san_record *r = &dbf->san_buf;
690 struct zfcp_dbf_san_record_ct_request *oct = &r->u.ct_req;
Christof Schmittd94ce6c2008-11-04 16:35:12 +0100691 int level = 3;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200692 unsigned long flags;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200693
Swen Schillig57717102009-08-18 15:43:21 +0200694 spin_lock_irqsave(&dbf->san_lock, flags);
Martin Peschke6bc473d2008-03-31 11:15:29 +0200695 memset(r, 0, sizeof(*r));
696 strncpy(r->tag, "octc", ZFCP_DBF_TAG_SIZE);
Christof Schmittf0216ae2009-05-15 13:18:14 +0200697 r->fsf_reqid = fsf_req->req_id;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200698 r->fsf_seqno = fsf_req->seq_no;
699 r->s_id = fc_host_port_id(adapter->scsi_host);
Swen Schillig5ab944f2008-10-01 12:42:17 +0200700 r->d_id = wka_port->d_id;
Christof Schmittdbf5dfe2009-11-24 16:54:10 +0100701 oct->cmd_req_code = hdr->ct_cmd;
702 oct->revision = hdr->ct_rev;
703 oct->gs_type = hdr->ct_fs_type;
704 oct->gs_subtype = hdr->ct_fs_subtype;
705 oct->options = hdr->ct_options;
706 oct->max_res_size = hdr->ct_mr_size;
707 oct->len = min((int)ct->req->length - (int)sizeof(struct fc_ct_hdr),
Christof Schmittd94ce6c2008-11-04 16:35:12 +0100708 ZFCP_DBF_SAN_MAX_PAYLOAD);
Swen Schillig57717102009-08-18 15:43:21 +0200709 debug_event(dbf->san, level, r, sizeof(*r));
710 zfcp_dbf_hexdump(dbf->san, r, sizeof(*r), level,
Christof Schmittdbf5dfe2009-11-24 16:54:10 +0100711 (void *)hdr + sizeof(struct fc_ct_hdr), oct->len);
Swen Schillig57717102009-08-18 15:43:21 +0200712 spin_unlock_irqrestore(&dbf->san_lock, flags);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200713}
714
Martin Peschkebfab1632008-03-31 11:15:31 +0200715/**
Swen Schillig57717102009-08-18 15:43:21 +0200716 * zfcp_dbf_san_ct_response - trace event for completion of CT request
Martin Peschkebfab1632008-03-31 11:15:31 +0200717 * @fsf_req: request containing CT response
718 */
Swen Schillig57717102009-08-18 15:43:21 +0200719void zfcp_dbf_san_ct_response(struct zfcp_fsf_req *fsf_req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200720{
721 struct zfcp_send_ct *ct = (struct zfcp_send_ct *)fsf_req->data;
Christof Schmittbd0072e2009-11-24 16:54:11 +0100722 struct zfcp_fc_wka_port *wka_port = ct->wka_port;
Swen Schillig5ab944f2008-10-01 12:42:17 +0200723 struct zfcp_adapter *adapter = wka_port->adapter;
Christof Schmittdbf5dfe2009-11-24 16:54:10 +0100724 struct fc_ct_hdr *hdr = sg_virt(ct->resp);
Christof Schmittd46f3842009-08-18 15:43:07 +0200725 struct zfcp_dbf *dbf = adapter->dbf;
Swen Schillig57717102009-08-18 15:43:21 +0200726 struct zfcp_dbf_san_record *r = &dbf->san_buf;
727 struct zfcp_dbf_san_record_ct_response *rct = &r->u.ct_resp;
Christof Schmittd94ce6c2008-11-04 16:35:12 +0100728 int level = 3;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200729 unsigned long flags;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200730
Swen Schillig57717102009-08-18 15:43:21 +0200731 spin_lock_irqsave(&dbf->san_lock, flags);
Martin Peschke6bc473d2008-03-31 11:15:29 +0200732 memset(r, 0, sizeof(*r));
733 strncpy(r->tag, "rctc", ZFCP_DBF_TAG_SIZE);
Christof Schmittf0216ae2009-05-15 13:18:14 +0200734 r->fsf_reqid = fsf_req->req_id;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200735 r->fsf_seqno = fsf_req->seq_no;
Swen Schillig5ab944f2008-10-01 12:42:17 +0200736 r->s_id = wka_port->d_id;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200737 r->d_id = fc_host_port_id(adapter->scsi_host);
Christof Schmittdbf5dfe2009-11-24 16:54:10 +0100738 rct->cmd_rsp_code = hdr->ct_cmd;
739 rct->revision = hdr->ct_rev;
740 rct->reason_code = hdr->ct_reason;
741 rct->expl = hdr->ct_explan;
742 rct->vendor_unique = hdr->ct_vendor;
743 rct->max_res_size = hdr->ct_mr_size;
744 rct->len = min((int)ct->resp->length - (int)sizeof(struct fc_ct_hdr),
Christof Schmittd94ce6c2008-11-04 16:35:12 +0100745 ZFCP_DBF_SAN_MAX_PAYLOAD);
Swen Schillig57717102009-08-18 15:43:21 +0200746 debug_event(dbf->san, level, r, sizeof(*r));
747 zfcp_dbf_hexdump(dbf->san, r, sizeof(*r), level,
Christof Schmittdbf5dfe2009-11-24 16:54:10 +0100748 (void *)hdr + sizeof(struct fc_ct_hdr), rct->len);
Swen Schillig57717102009-08-18 15:43:21 +0200749 spin_unlock_irqrestore(&dbf->san_lock, flags);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200750}
751
Swen Schillig57717102009-08-18 15:43:21 +0200752static void zfcp_dbf_san_els(const char *tag, int level,
753 struct zfcp_fsf_req *fsf_req, u32 s_id, u32 d_id,
754 u8 ls_code, void *buffer, int buflen)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200755{
756 struct zfcp_adapter *adapter = fsf_req->adapter;
Christof Schmittd46f3842009-08-18 15:43:07 +0200757 struct zfcp_dbf *dbf = adapter->dbf;
Swen Schillig57717102009-08-18 15:43:21 +0200758 struct zfcp_dbf_san_record *rec = &dbf->san_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200759 unsigned long flags;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200760
Swen Schillig57717102009-08-18 15:43:21 +0200761 spin_lock_irqsave(&dbf->san_lock, flags);
Martin Peschke6bc473d2008-03-31 11:15:29 +0200762 memset(rec, 0, sizeof(*rec));
Martin Peschke0f65e952008-03-27 14:21:56 +0100763 strncpy(rec->tag, tag, ZFCP_DBF_TAG_SIZE);
Christof Schmittf0216ae2009-05-15 13:18:14 +0200764 rec->fsf_reqid = fsf_req->req_id;
Martin Peschke0f65e952008-03-27 14:21:56 +0100765 rec->fsf_seqno = fsf_req->seq_no;
766 rec->s_id = s_id;
767 rec->d_id = d_id;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200768 rec->u.els.ls_code = ls_code;
Swen Schillig57717102009-08-18 15:43:21 +0200769 debug_event(dbf->san, level, rec, sizeof(*rec));
770 zfcp_dbf_hexdump(dbf->san, rec, sizeof(*rec), level,
Christof Schmittd94ce6c2008-11-04 16:35:12 +0100771 buffer, min(buflen, ZFCP_DBF_SAN_MAX_PAYLOAD));
Swen Schillig57717102009-08-18 15:43:21 +0200772 spin_unlock_irqrestore(&dbf->san_lock, flags);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200773}
774
Martin Peschkebfab1632008-03-31 11:15:31 +0200775/**
Swen Schillig57717102009-08-18 15:43:21 +0200776 * zfcp_dbf_san_els_request - trace event for issued ELS
Martin Peschkebfab1632008-03-31 11:15:31 +0200777 * @fsf_req: request containing issued ELS
778 */
Swen Schillig57717102009-08-18 15:43:21 +0200779void zfcp_dbf_san_els_request(struct zfcp_fsf_req *fsf_req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200780{
781 struct zfcp_send_els *els = (struct zfcp_send_els *)fsf_req->data;
782
Swen Schillig57717102009-08-18 15:43:21 +0200783 zfcp_dbf_san_els("oels", 2, fsf_req,
Martin Peschke92c7a832008-03-31 11:15:30 +0200784 fc_host_port_id(els->adapter->scsi_host),
Swen Schillig44cc76f2008-10-01 12:42:16 +0200785 els->d_id, *(u8 *) sg_virt(els->req),
786 sg_virt(els->req), els->req->length);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200787}
788
Martin Peschkebfab1632008-03-31 11:15:31 +0200789/**
Swen Schillig57717102009-08-18 15:43:21 +0200790 * zfcp_dbf_san_els_response - trace event for completed ELS
Martin Peschkebfab1632008-03-31 11:15:31 +0200791 * @fsf_req: request containing ELS response
792 */
Swen Schillig57717102009-08-18 15:43:21 +0200793void zfcp_dbf_san_els_response(struct zfcp_fsf_req *fsf_req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200794{
795 struct zfcp_send_els *els = (struct zfcp_send_els *)fsf_req->data;
796
Swen Schillig57717102009-08-18 15:43:21 +0200797 zfcp_dbf_san_els("rels", 2, fsf_req, els->d_id,
Martin Peschke92c7a832008-03-31 11:15:30 +0200798 fc_host_port_id(els->adapter->scsi_host),
Swen Schillig44cc76f2008-10-01 12:42:16 +0200799 *(u8 *)sg_virt(els->req), sg_virt(els->resp),
Martin Peschke92c7a832008-03-31 11:15:30 +0200800 els->resp->length);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200801}
802
Martin Peschkebfab1632008-03-31 11:15:31 +0200803/**
Swen Schillig57717102009-08-18 15:43:21 +0200804 * zfcp_dbf_san_incoming_els - trace event for incomig ELS
Martin Peschkebfab1632008-03-31 11:15:31 +0200805 * @fsf_req: request containing unsolicited status buffer with incoming ELS
806 */
Swen Schillig57717102009-08-18 15:43:21 +0200807void zfcp_dbf_san_incoming_els(struct zfcp_fsf_req *fsf_req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200808{
809 struct zfcp_adapter *adapter = fsf_req->adapter;
Martin Peschke92c7a832008-03-31 11:15:30 +0200810 struct fsf_status_read_buffer *buf =
811 (struct fsf_status_read_buffer *)fsf_req->data;
812 int length = (int)buf->length -
813 (int)((void *)&buf->payload - (void *)buf);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200814
Swen Schillig57717102009-08-18 15:43:21 +0200815 zfcp_dbf_san_els("iels", 1, fsf_req, buf->d_id,
Martin Peschke92c7a832008-03-31 11:15:30 +0200816 fc_host_port_id(adapter->scsi_host),
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200817 buf->payload.data[0], (void *)buf->payload.data,
Martin Peschke92c7a832008-03-31 11:15:30 +0200818 length);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200819}
820
Swen Schillig57717102009-08-18 15:43:21 +0200821static int zfcp_dbf_san_view_format(debug_info_t *id, struct debug_view *view,
Martin Peschke92c7a832008-03-31 11:15:30 +0200822 char *out_buf, const char *in_buf)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200823{
Swen Schillig57717102009-08-18 15:43:21 +0200824 struct zfcp_dbf_san_record *r = (struct zfcp_dbf_san_record *)in_buf;
Martin Peschkeb634fff2008-03-31 11:15:24 +0200825 char *p = out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200826
Martin Peschkeb634fff2008-03-31 11:15:24 +0200827 if (strncmp(r->tag, "dump", ZFCP_DBF_TAG_SIZE) == 0)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200828 return 0;
829
Martin Peschkea9c85772008-03-31 11:15:27 +0200830 zfcp_dbf_tag(&p, "tag", r->tag);
Martin Peschkeb634fff2008-03-31 11:15:24 +0200831 zfcp_dbf_out(&p, "fsf_reqid", "0x%0Lx", r->fsf_reqid);
832 zfcp_dbf_out(&p, "fsf_seqno", "0x%08x", r->fsf_seqno);
833 zfcp_dbf_out(&p, "s_id", "0x%06x", r->s_id);
834 zfcp_dbf_out(&p, "d_id", "0x%06x", r->d_id);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200835
Martin Peschkeb634fff2008-03-31 11:15:24 +0200836 if (strncmp(r->tag, "octc", ZFCP_DBF_TAG_SIZE) == 0) {
Swen Schillig57717102009-08-18 15:43:21 +0200837 struct zfcp_dbf_san_record_ct_request *ct = &r->u.ct_req;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200838 zfcp_dbf_out(&p, "cmd_req_code", "0x%04x", ct->cmd_req_code);
839 zfcp_dbf_out(&p, "revision", "0x%02x", ct->revision);
840 zfcp_dbf_out(&p, "gs_type", "0x%02x", ct->gs_type);
841 zfcp_dbf_out(&p, "gs_subtype", "0x%02x", ct->gs_subtype);
842 zfcp_dbf_out(&p, "options", "0x%02x", ct->options);
843 zfcp_dbf_out(&p, "max_res_size", "0x%04x", ct->max_res_size);
Martin Peschkeb634fff2008-03-31 11:15:24 +0200844 } else if (strncmp(r->tag, "rctc", ZFCP_DBF_TAG_SIZE) == 0) {
Swen Schillig57717102009-08-18 15:43:21 +0200845 struct zfcp_dbf_san_record_ct_response *ct = &r->u.ct_resp;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200846 zfcp_dbf_out(&p, "cmd_rsp_code", "0x%04x", ct->cmd_rsp_code);
847 zfcp_dbf_out(&p, "revision", "0x%02x", ct->revision);
848 zfcp_dbf_out(&p, "reason_code", "0x%02x", ct->reason_code);
849 zfcp_dbf_out(&p, "reason_code_expl", "0x%02x", ct->expl);
850 zfcp_dbf_out(&p, "vendor_unique", "0x%02x", ct->vendor_unique);
Christof Schmitt39eb7e9a2008-12-19 16:57:01 +0100851 zfcp_dbf_out(&p, "max_res_size", "0x%04x", ct->max_res_size);
Martin Peschkeb634fff2008-03-31 11:15:24 +0200852 } else if (strncmp(r->tag, "oels", ZFCP_DBF_TAG_SIZE) == 0 ||
853 strncmp(r->tag, "rels", ZFCP_DBF_TAG_SIZE) == 0 ||
854 strncmp(r->tag, "iels", ZFCP_DBF_TAG_SIZE) == 0) {
Swen Schillig57717102009-08-18 15:43:21 +0200855 struct zfcp_dbf_san_record_els *els = &r->u.els;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200856 zfcp_dbf_out(&p, "ls_code", "0x%02x", els->ls_code);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200857 }
Martin Peschkeb634fff2008-03-31 11:15:24 +0200858 return p - out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200859}
860
Swen Schillig57717102009-08-18 15:43:21 +0200861static struct debug_view zfcp_dbf_san_view = {
862 .name = "structured",
863 .header_proc = zfcp_dbf_view_header,
864 .format_proc = zfcp_dbf_san_view_format,
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200865};
866
Swen Schillig57717102009-08-18 15:43:21 +0200867void _zfcp_dbf_scsi(const char *tag, const char *tag2, int level,
868 struct zfcp_dbf *dbf, struct scsi_cmnd *scsi_cmnd,
869 struct zfcp_fsf_req *fsf_req, unsigned long old_req_id)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200870{
Swen Schillig57717102009-08-18 15:43:21 +0200871 struct zfcp_dbf_scsi_record *rec = &dbf->scsi_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200872 struct zfcp_dbf_dump *dump = (struct zfcp_dbf_dump *)rec;
873 unsigned long flags;
Christof Schmitt4318e082009-11-24 16:54:08 +0100874 struct fcp_resp_with_ext *fcp_rsp;
875 struct fcp_resp_rsp_info *fcp_rsp_info = NULL;
876 char *fcp_sns_info = NULL;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200877 int offset = 0, buflen = 0;
878
Swen Schillig57717102009-08-18 15:43:21 +0200879 spin_lock_irqsave(&dbf->scsi_lock, flags);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200880 do {
Martin Peschke6bc473d2008-03-31 11:15:29 +0200881 memset(rec, 0, sizeof(*rec));
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200882 if (offset == 0) {
883 strncpy(rec->tag, tag, ZFCP_DBF_TAG_SIZE);
884 strncpy(rec->tag2, tag2, ZFCP_DBF_TAG_SIZE);
Maxim Shchetynined829ad2006-02-11 01:42:58 +0100885 if (scsi_cmnd != NULL) {
886 if (scsi_cmnd->device) {
887 rec->scsi_id = scsi_cmnd->device->id;
888 rec->scsi_lun = scsi_cmnd->device->lun;
889 }
890 rec->scsi_result = scsi_cmnd->result;
891 rec->scsi_cmnd = (unsigned long)scsi_cmnd;
892 rec->scsi_serial = scsi_cmnd->serial_number;
Boaz Harrosh64a87b22008-04-30 11:19:47 +0300893 memcpy(rec->scsi_opcode, scsi_cmnd->cmnd,
Maxim Shchetynined829ad2006-02-11 01:42:58 +0100894 min((int)scsi_cmnd->cmd_len,
895 ZFCP_DBF_SCSI_OPCODE));
896 rec->scsi_retries = scsi_cmnd->retries;
897 rec->scsi_allowed = scsi_cmnd->allowed;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200898 }
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200899 if (fsf_req != NULL) {
Christof Schmitt4318e082009-11-24 16:54:08 +0100900 fcp_rsp = (struct fcp_resp_with_ext *)
901 &(fsf_req->qtcb->bottom.io.fcp_rsp);
902 fcp_rsp_info = (struct fcp_resp_rsp_info *)
903 &fcp_rsp[1];
904 fcp_sns_info = (char *) &fcp_rsp[1];
905 if (fcp_rsp->resp.fr_flags & FCP_RSP_LEN_VAL)
906 fcp_sns_info += fcp_rsp->ext.fr_sns_len;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200907
Christof Schmitt4318e082009-11-24 16:54:08 +0100908 rec->rsp_validity = fcp_rsp->resp.fr_flags;
909 rec->rsp_scsi_status = fcp_rsp->resp.fr_status;
910 rec->rsp_resid = fcp_rsp->ext.fr_resid;
911 if (fcp_rsp->resp.fr_flags & FCP_RSP_LEN_VAL)
912 rec->rsp_code = fcp_rsp_info->rsp_code;
913 if (fcp_rsp->resp.fr_flags & FCP_SNS_LEN_VAL) {
914 buflen = min(fcp_rsp->ext.fr_sns_len,
915 (u32)ZFCP_DBF_SCSI_MAX_FCP_SNS_INFO);
Martin Peschke6bc473d2008-03-31 11:15:29 +0200916 rec->sns_info_len = buflen;
917 memcpy(rec->sns_info, fcp_sns_info,
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200918 min(buflen,
919 ZFCP_DBF_SCSI_FCP_SNS_INFO));
920 offset += min(buflen,
921 ZFCP_DBF_SCSI_FCP_SNS_INFO);
922 }
923
Christof Schmittf0216ae2009-05-15 13:18:14 +0200924 rec->fsf_reqid = fsf_req->req_id;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200925 rec->fsf_seqno = fsf_req->seq_no;
926 rec->fsf_issued = fsf_req->issued;
927 }
Martin Peschke6bc473d2008-03-31 11:15:29 +0200928 rec->old_fsf_reqid = old_req_id;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200929 } else {
930 strncpy(dump->tag, "dump", ZFCP_DBF_TAG_SIZE);
931 dump->total_size = buflen;
932 dump->offset = offset;
933 dump->size = min(buflen - offset,
934 (int)sizeof(struct
Swen Schillig57717102009-08-18 15:43:21 +0200935 zfcp_dbf_scsi_record) -
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200936 (int)sizeof(struct zfcp_dbf_dump));
937 memcpy(dump->data, fcp_sns_info + offset, dump->size);
938 offset += dump->size;
939 }
Swen Schillig57717102009-08-18 15:43:21 +0200940 debug_event(dbf->scsi, level, rec, sizeof(*rec));
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200941 } while (offset < buflen);
Swen Schillig57717102009-08-18 15:43:21 +0200942 spin_unlock_irqrestore(&dbf->scsi_lock, flags);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200943}
944
Swen Schillig57717102009-08-18 15:43:21 +0200945static int zfcp_dbf_scsi_view_format(debug_info_t *id, struct debug_view *view,
Martin Peschke92c7a832008-03-31 11:15:30 +0200946 char *out_buf, const char *in_buf)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200947{
Swen Schillig57717102009-08-18 15:43:21 +0200948 struct zfcp_dbf_scsi_record *r = (struct zfcp_dbf_scsi_record *)in_buf;
Martin Peschke8fc5af12008-03-31 11:15:23 +0200949 struct timespec t;
Martin Peschkeb634fff2008-03-31 11:15:24 +0200950 char *p = out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200951
Martin Peschkeb634fff2008-03-31 11:15:24 +0200952 if (strncmp(r->tag, "dump", ZFCP_DBF_TAG_SIZE) == 0)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200953 return 0;
954
Martin Peschkea9c85772008-03-31 11:15:27 +0200955 zfcp_dbf_tag(&p, "tag", r->tag);
956 zfcp_dbf_tag(&p, "tag2", r->tag2);
Martin Peschkeb634fff2008-03-31 11:15:24 +0200957 zfcp_dbf_out(&p, "scsi_id", "0x%08x", r->scsi_id);
958 zfcp_dbf_out(&p, "scsi_lun", "0x%08x", r->scsi_lun);
959 zfcp_dbf_out(&p, "scsi_result", "0x%08x", r->scsi_result);
960 zfcp_dbf_out(&p, "scsi_cmnd", "0x%0Lx", r->scsi_cmnd);
961 zfcp_dbf_out(&p, "scsi_serial", "0x%016Lx", r->scsi_serial);
Martin Peschkedf29f4a2008-03-31 11:15:26 +0200962 zfcp_dbf_outd(&p, "scsi_opcode", r->scsi_opcode, ZFCP_DBF_SCSI_OPCODE,
963 0, ZFCP_DBF_SCSI_OPCODE);
Martin Peschkeb634fff2008-03-31 11:15:24 +0200964 zfcp_dbf_out(&p, "scsi_retries", "0x%02x", r->scsi_retries);
965 zfcp_dbf_out(&p, "scsi_allowed", "0x%02x", r->scsi_allowed);
966 if (strncmp(r->tag, "abrt", ZFCP_DBF_TAG_SIZE) == 0)
Martin Peschke6bc473d2008-03-31 11:15:29 +0200967 zfcp_dbf_out(&p, "old_fsf_reqid", "0x%0Lx", r->old_fsf_reqid);
Martin Peschkeb634fff2008-03-31 11:15:24 +0200968 zfcp_dbf_out(&p, "fsf_reqid", "0x%0Lx", r->fsf_reqid);
969 zfcp_dbf_out(&p, "fsf_seqno", "0x%08x", r->fsf_seqno);
Christof Schmittb592e892009-08-18 15:43:31 +0200970 stck_to_timespec(r->fsf_issued, &t);
Martin Peschkeb634fff2008-03-31 11:15:24 +0200971 zfcp_dbf_out(&p, "fsf_issued", "%011lu:%06lu", t.tv_sec, t.tv_nsec);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200972
Martin Peschkeb634fff2008-03-31 11:15:24 +0200973 if (strncmp(r->tag, "rslt", ZFCP_DBF_TAG_SIZE) == 0) {
Martin Peschke6bc473d2008-03-31 11:15:29 +0200974 zfcp_dbf_out(&p, "fcp_rsp_validity", "0x%02x", r->rsp_validity);
975 zfcp_dbf_out(&p, "fcp_rsp_scsi_status", "0x%02x",
976 r->rsp_scsi_status);
977 zfcp_dbf_out(&p, "fcp_rsp_resid", "0x%08x", r->rsp_resid);
978 zfcp_dbf_out(&p, "fcp_rsp_code", "0x%08x", r->rsp_code);
979 zfcp_dbf_out(&p, "fcp_sns_info_len", "0x%08x", r->sns_info_len);
980 zfcp_dbf_outd(&p, "fcp_sns_info", r->sns_info,
981 min((int)r->sns_info_len,
Martin Peschkedf29f4a2008-03-31 11:15:26 +0200982 ZFCP_DBF_SCSI_FCP_SNS_INFO), 0,
Martin Peschke6bc473d2008-03-31 11:15:29 +0200983 r->sns_info_len);
Martin Peschkeb634fff2008-03-31 11:15:24 +0200984 }
985 p += sprintf(p, "\n");
986 return p - out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200987}
988
Swen Schillig57717102009-08-18 15:43:21 +0200989static struct debug_view zfcp_dbf_scsi_view = {
990 .name = "structured",
991 .header_proc = zfcp_dbf_view_header,
992 .format_proc = zfcp_dbf_scsi_view_format,
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200993};
994
Christof Schmittd46f3842009-08-18 15:43:07 +0200995static debug_info_t *zfcp_dbf_reg(const char *name, int level,
996 struct debug_view *view, int size)
997{
998 struct debug_info *d;
999
1000 d = debug_register(name, dbfsize, level, size);
1001 if (!d)
1002 return NULL;
1003
1004 debug_register_view(d, &debug_hex_ascii_view);
1005 debug_register_view(d, view);
1006 debug_set_level(d, level);
1007
1008 return d;
1009}
1010
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001011/**
1012 * zfcp_adapter_debug_register - registers debug feature for an adapter
1013 * @adapter: pointer to adapter for which debug features should be registered
1014 * return: -ENOMEM on error, 0 otherwise
1015 */
Swen Schillig57717102009-08-18 15:43:21 +02001016int zfcp_dbf_adapter_register(struct zfcp_adapter *adapter)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001017{
1018 char dbf_name[DEBUG_MAX_NAME_LEN];
Christof Schmittd46f3842009-08-18 15:43:07 +02001019 struct zfcp_dbf *dbf;
1020
1021 dbf = kmalloc(sizeof(struct zfcp_dbf), GFP_KERNEL);
1022 if (!dbf)
1023 return -ENOMEM;
1024
Swen Schillig57717102009-08-18 15:43:21 +02001025 dbf->adapter = adapter;
1026
1027 spin_lock_init(&dbf->hba_lock);
1028 spin_lock_init(&dbf->san_lock);
1029 spin_lock_init(&dbf->scsi_lock);
1030 spin_lock_init(&dbf->rec_lock);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001031
1032 /* debug feature area which records recovery activity */
Christof Schmittb225cf92008-12-19 16:57:00 +01001033 sprintf(dbf_name, "zfcp_%s_rec", dev_name(&adapter->ccw_device->dev));
Swen Schillig57717102009-08-18 15:43:21 +02001034 dbf->rec = zfcp_dbf_reg(dbf_name, 3, &zfcp_dbf_rec_view,
1035 sizeof(struct zfcp_dbf_rec_record));
1036 if (!dbf->rec)
1037 goto err_out;
Martin Peschked79a83d2008-03-27 14:22:00 +01001038
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001039 /* debug feature area which records HBA (FSF and QDIO) conditions */
Christof Schmittb225cf92008-12-19 16:57:00 +01001040 sprintf(dbf_name, "zfcp_%s_hba", dev_name(&adapter->ccw_device->dev));
Swen Schillig57717102009-08-18 15:43:21 +02001041 dbf->hba = zfcp_dbf_reg(dbf_name, 3, &zfcp_dbf_hba_view,
1042 sizeof(struct zfcp_dbf_hba_record));
1043 if (!dbf->hba)
1044 goto err_out;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001045
1046 /* debug feature area which records SAN command failures and recovery */
Christof Schmittb225cf92008-12-19 16:57:00 +01001047 sprintf(dbf_name, "zfcp_%s_san", dev_name(&adapter->ccw_device->dev));
Swen Schillig57717102009-08-18 15:43:21 +02001048 dbf->san = zfcp_dbf_reg(dbf_name, 6, &zfcp_dbf_san_view,
1049 sizeof(struct zfcp_dbf_san_record));
1050 if (!dbf->san)
1051 goto err_out;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001052
1053 /* debug feature area which records SCSI command failures and recovery */
Christof Schmittb225cf92008-12-19 16:57:00 +01001054 sprintf(dbf_name, "zfcp_%s_scsi", dev_name(&adapter->ccw_device->dev));
Swen Schillig57717102009-08-18 15:43:21 +02001055 dbf->scsi = zfcp_dbf_reg(dbf_name, 3, &zfcp_dbf_scsi_view,
1056 sizeof(struct zfcp_dbf_scsi_record));
1057 if (!dbf->scsi)
1058 goto err_out;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001059
Christof Schmittd46f3842009-08-18 15:43:07 +02001060 adapter->dbf = dbf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001061 return 0;
1062
Swen Schillig57717102009-08-18 15:43:21 +02001063err_out:
1064 zfcp_dbf_adapter_unregister(dbf);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001065 return -ENOMEM;
1066}
1067
1068/**
1069 * zfcp_adapter_debug_unregister - unregisters debug feature for an adapter
Swen Schillig57717102009-08-18 15:43:21 +02001070 * @dbf: pointer to dbf for which debug features should be unregistered
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001071 */
Swen Schillig57717102009-08-18 15:43:21 +02001072void zfcp_dbf_adapter_unregister(struct zfcp_dbf *dbf)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001073{
Swen Schilligf3450c72009-11-24 16:53:59 +01001074 if (!dbf)
1075 return;
Swen Schillig57717102009-08-18 15:43:21 +02001076 debug_unregister(dbf->scsi);
1077 debug_unregister(dbf->san);
1078 debug_unregister(dbf->hba);
1079 debug_unregister(dbf->rec);
1080 dbf->adapter->dbf = NULL;
1081 kfree(dbf);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001082}
Swen Schillig57717102009-08-18 15:43:21 +02001083