blob: 818b6ad935ad21243f7c2933a653ad3800c301d5 [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;
Christof Schmitt800c0ca2009-11-24 16:54:12 +0100181 response->u.els.d_id = ntoh24(qtcb->bottom.support.d_id);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200182 break;
183
184 case FSF_QTCB_ABORT_FCP_CMND:
185 case FSF_QTCB_SEND_GENERIC:
186 case FSF_QTCB_EXCHANGE_CONFIG_DATA:
187 case FSF_QTCB_EXCHANGE_PORT_DATA:
188 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
189 case FSF_QTCB_UPLOAD_CONTROL_FILE:
190 break;
191 }
192
Swen Schillig57717102009-08-18 15:43:21 +0200193 debug_event(dbf->hba, level, rec, sizeof(*rec));
Martin Peschkeb75db732008-03-27 14:21:58 +0100194
195 /* have fcp channel microcode fixed to use as little as possible */
196 if (fsf_req->fsf_command != FSF_QTCB_FCP_CMND) {
197 /* adjust length skipping trailing zeros */
198 char *buf = (char *)qtcb + qtcb->header.log_start;
199 int len = qtcb->header.log_length;
200 for (; len && !buf[len - 1]; len--);
Swen Schillig57717102009-08-18 15:43:21 +0200201 zfcp_dbf_hexdump(dbf->hba, rec, sizeof(*rec), level, buf,
Christof Schmittd46f3842009-08-18 15:43:07 +0200202 len);
Martin Peschkeb75db732008-03-27 14:21:58 +0100203 }
204
Swen Schillig57717102009-08-18 15:43:21 +0200205 spin_unlock_irqrestore(&dbf->hba_lock, flags);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200206}
207
Swen Schillig57717102009-08-18 15:43:21 +0200208void _zfcp_dbf_hba_fsf_unsol(const char *tag, int level, struct zfcp_dbf *dbf,
209 struct fsf_status_read_buffer *status_buffer)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200210{
Swen Schillig57717102009-08-18 15:43:21 +0200211 struct zfcp_dbf_hba_record *rec = &dbf->hba_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200212 unsigned long flags;
213
Swen Schillig57717102009-08-18 15:43:21 +0200214 spin_lock_irqsave(&dbf->hba_lock, flags);
Martin Peschke6bc473d2008-03-31 11:15:29 +0200215 memset(rec, 0, sizeof(*rec));
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200216 strncpy(rec->tag, "stat", ZFCP_DBF_TAG_SIZE);
217 strncpy(rec->tag2, tag, ZFCP_DBF_TAG_SIZE);
218
Swen Schillig57717102009-08-18 15:43:21 +0200219 rec->u.status.failed = atomic_read(&dbf->adapter->stat_miss);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200220 if (status_buffer != NULL) {
Martin Peschke6bc473d2008-03-31 11:15:29 +0200221 rec->u.status.status_type = status_buffer->status_type;
222 rec->u.status.status_subtype = status_buffer->status_subtype;
223 memcpy(&rec->u.status.queue_designator,
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200224 &status_buffer->queue_designator,
225 sizeof(struct fsf_queue_designator));
226
227 switch (status_buffer->status_type) {
228 case FSF_STATUS_READ_SENSE_DATA_AVAIL:
Martin Peschke6bc473d2008-03-31 11:15:29 +0200229 rec->u.status.payload_size =
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200230 ZFCP_DBF_UNSOL_PAYLOAD_SENSE_DATA_AVAIL;
231 break;
232
233 case FSF_STATUS_READ_BIT_ERROR_THRESHOLD:
Martin Peschke6bc473d2008-03-31 11:15:29 +0200234 rec->u.status.payload_size =
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200235 ZFCP_DBF_UNSOL_PAYLOAD_BIT_ERROR_THRESHOLD;
236 break;
237
238 case FSF_STATUS_READ_LINK_DOWN:
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200239 switch (status_buffer->status_subtype) {
240 case FSF_STATUS_READ_SUB_NO_PHYSICAL_LINK:
241 case FSF_STATUS_READ_SUB_FDISC_FAILED:
Martin Peschke6bc473d2008-03-31 11:15:29 +0200242 rec->u.status.payload_size =
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200243 sizeof(struct fsf_link_down_info);
244 }
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200245 break;
246
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200247 case FSF_STATUS_READ_FEATURE_UPDATE_ALERT:
Martin Peschke6bc473d2008-03-31 11:15:29 +0200248 rec->u.status.payload_size =
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200249 ZFCP_DBF_UNSOL_PAYLOAD_FEATURE_UPDATE_ALERT;
250 break;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200251 }
Martin Peschke6bc473d2008-03-31 11:15:29 +0200252 memcpy(&rec->u.status.payload,
253 &status_buffer->payload, rec->u.status.payload_size);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200254 }
255
Swen Schillig57717102009-08-18 15:43:21 +0200256 debug_event(dbf->hba, level, rec, sizeof(*rec));
257 spin_unlock_irqrestore(&dbf->hba_lock, flags);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200258}
259
Martin Peschkebfab1632008-03-31 11:15:31 +0200260/**
Swen Schillig57717102009-08-18 15:43:21 +0200261 * zfcp_dbf_hba_qdio - trace event for QDIO related failure
Swen Schillig564e1c82009-08-18 15:43:19 +0200262 * @qdio: qdio structure affected by this QDIO related event
Martin Peschkebfab1632008-03-31 11:15:31 +0200263 * @qdio_error: as passed by qdio module
Martin Peschkebfab1632008-03-31 11:15:31 +0200264 * @sbal_index: first buffer with error condition, as passed by qdio module
265 * @sbal_count: number of buffers affected, as passed by qdio module
266 */
Swen Schillig57717102009-08-18 15:43:21 +0200267void zfcp_dbf_hba_qdio(struct zfcp_dbf *dbf, unsigned int qdio_error,
268 int sbal_index, int sbal_count)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200269{
Swen Schillig57717102009-08-18 15:43:21 +0200270 struct zfcp_dbf_hba_record *r = &dbf->hba_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200271 unsigned long flags;
272
Swen Schillig57717102009-08-18 15:43:21 +0200273 spin_lock_irqsave(&dbf->hba_lock, flags);
Martin Peschke6bc473d2008-03-31 11:15:29 +0200274 memset(r, 0, sizeof(*r));
275 strncpy(r->tag, "qdio", ZFCP_DBF_TAG_SIZE);
Martin Peschke6bc473d2008-03-31 11:15:29 +0200276 r->u.qdio.qdio_error = qdio_error;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200277 r->u.qdio.sbal_index = sbal_index;
278 r->u.qdio.sbal_count = sbal_count;
Swen Schillig57717102009-08-18 15:43:21 +0200279 debug_event(dbf->hba, 0, r, sizeof(*r));
280 spin_unlock_irqrestore(&dbf->hba_lock, flags);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200281}
282
Swen Schillig57069382008-10-01 12:42:21 +0200283/**
Swen Schillig57717102009-08-18 15:43:21 +0200284 * zfcp_dbf_hba_berr - trace event for bit error threshold
285 * @dbf: dbf structure affected by this QDIO related event
Swen Schillig57069382008-10-01 12:42:21 +0200286 * @req: fsf request
287 */
Swen Schillig57717102009-08-18 15:43:21 +0200288void zfcp_dbf_hba_berr(struct zfcp_dbf *dbf, struct zfcp_fsf_req *req)
Swen Schillig57069382008-10-01 12:42:21 +0200289{
Swen Schillig57717102009-08-18 15:43:21 +0200290 struct zfcp_dbf_hba_record *r = &dbf->hba_buf;
Swen Schillig57069382008-10-01 12:42:21 +0200291 struct fsf_status_read_buffer *sr_buf = req->data;
292 struct fsf_bit_error_payload *err = &sr_buf->payload.bit_error;
293 unsigned long flags;
294
Swen Schillig57717102009-08-18 15:43:21 +0200295 spin_lock_irqsave(&dbf->hba_lock, flags);
Swen Schillig57069382008-10-01 12:42:21 +0200296 memset(r, 0, sizeof(*r));
297 strncpy(r->tag, "berr", ZFCP_DBF_TAG_SIZE);
298 memcpy(&r->u.berr, err, sizeof(struct fsf_bit_error_payload));
Swen Schillig57717102009-08-18 15:43:21 +0200299 debug_event(dbf->hba, 0, r, sizeof(*r));
300 spin_unlock_irqrestore(&dbf->hba_lock, flags);
Swen Schillig57069382008-10-01 12:42:21 +0200301}
Swen Schillig57717102009-08-18 15:43:21 +0200302static void zfcp_dbf_hba_view_response(char **p,
303 struct zfcp_dbf_hba_record_response *r)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200304{
Martin Peschke8fc5af12008-03-31 11:15:23 +0200305 struct timespec t;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200306
Martin Peschkea9c85772008-03-31 11:15:27 +0200307 zfcp_dbf_out(p, "fsf_command", "0x%08x", r->fsf_command);
308 zfcp_dbf_out(p, "fsf_reqid", "0x%0Lx", r->fsf_reqid);
309 zfcp_dbf_out(p, "fsf_seqno", "0x%08x", r->fsf_seqno);
Christof Schmittb592e892009-08-18 15:43:31 +0200310 stck_to_timespec(r->fsf_issued, &t);
Martin Peschkea9c85772008-03-31 11:15:27 +0200311 zfcp_dbf_out(p, "fsf_issued", "%011lu:%06lu", t.tv_sec, t.tv_nsec);
312 zfcp_dbf_out(p, "fsf_prot_status", "0x%08x", r->fsf_prot_status);
313 zfcp_dbf_out(p, "fsf_status", "0x%08x", r->fsf_status);
314 zfcp_dbf_outd(p, "fsf_prot_status_qual", r->fsf_prot_status_qual,
Martin Peschkedf29f4a2008-03-31 11:15:26 +0200315 FSF_PROT_STATUS_QUAL_SIZE, 0, FSF_PROT_STATUS_QUAL_SIZE);
Martin Peschkea9c85772008-03-31 11:15:27 +0200316 zfcp_dbf_outd(p, "fsf_status_qual", r->fsf_status_qual,
Martin Peschkedf29f4a2008-03-31 11:15:26 +0200317 FSF_STATUS_QUALIFIER_SIZE, 0, FSF_STATUS_QUALIFIER_SIZE);
Martin Peschkea9c85772008-03-31 11:15:27 +0200318 zfcp_dbf_out(p, "fsf_req_status", "0x%08x", r->fsf_req_status);
319 zfcp_dbf_out(p, "sbal_first", "0x%02x", r->sbal_first);
Martin Peschkee891bff2008-05-19 12:17:43 +0200320 zfcp_dbf_out(p, "sbal_last", "0x%02x", r->sbal_last);
Martin Peschkec3baa9a22008-05-19 12:17:44 +0200321 zfcp_dbf_out(p, "sbal_response", "0x%02x", r->sbal_response);
Martin Peschkea9c85772008-03-31 11:15:27 +0200322 zfcp_dbf_out(p, "pool", "0x%02x", r->pool);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200323
Martin Peschkeb634fff2008-03-31 11:15:24 +0200324 switch (r->fsf_command) {
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200325 case FSF_QTCB_FCP_CMND:
Martin Peschkeb634fff2008-03-31 11:15:24 +0200326 if (r->fsf_req_status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200327 break;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200328 zfcp_dbf_out(p, "scsi_cmnd", "0x%0Lx", r->u.fcp.cmnd);
329 zfcp_dbf_out(p, "scsi_serial", "0x%016Lx", r->u.fcp.serial);
Christof Schmitt5a3fb302010-01-13 17:52:37 +0100330 *p += sprintf(*p, "\n");
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200331 break;
332
333 case FSF_QTCB_OPEN_PORT_WITH_DID:
334 case FSF_QTCB_CLOSE_PORT:
335 case FSF_QTCB_CLOSE_PHYSICAL_PORT:
Martin Peschke6bc473d2008-03-31 11:15:29 +0200336 zfcp_dbf_out(p, "wwpn", "0x%016Lx", r->u.port.wwpn);
337 zfcp_dbf_out(p, "d_id", "0x%06x", r->u.port.d_id);
338 zfcp_dbf_out(p, "port_handle", "0x%08x", r->u.port.port_handle);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200339 break;
340
341 case FSF_QTCB_OPEN_LUN:
342 case FSF_QTCB_CLOSE_LUN:
Martin Peschke6bc473d2008-03-31 11:15:29 +0200343 zfcp_dbf_out(p, "wwpn", "0x%016Lx", r->u.unit.wwpn);
344 zfcp_dbf_out(p, "fcp_lun", "0x%016Lx", r->u.unit.fcp_lun);
345 zfcp_dbf_out(p, "port_handle", "0x%08x", r->u.unit.port_handle);
346 zfcp_dbf_out(p, "lun_handle", "0x%08x", r->u.unit.lun_handle);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200347 break;
348
349 case FSF_QTCB_SEND_ELS:
Martin Peschke6bc473d2008-03-31 11:15:29 +0200350 zfcp_dbf_out(p, "d_id", "0x%06x", r->u.els.d_id);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200351 break;
352
353 case FSF_QTCB_ABORT_FCP_CMND:
354 case FSF_QTCB_SEND_GENERIC:
355 case FSF_QTCB_EXCHANGE_CONFIG_DATA:
356 case FSF_QTCB_EXCHANGE_PORT_DATA:
357 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
358 case FSF_QTCB_UPLOAD_CONTROL_FILE:
359 break;
360 }
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200361}
362
Swen Schillig57717102009-08-18 15:43:21 +0200363static void zfcp_dbf_hba_view_status(char **p,
364 struct zfcp_dbf_hba_record_status *r)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200365{
Martin Peschkea9c85772008-03-31 11:15:27 +0200366 zfcp_dbf_out(p, "failed", "0x%02x", r->failed);
367 zfcp_dbf_out(p, "status_type", "0x%08x", r->status_type);
368 zfcp_dbf_out(p, "status_subtype", "0x%08x", r->status_subtype);
369 zfcp_dbf_outd(p, "queue_designator", (char *)&r->queue_designator,
Martin Peschkedf29f4a2008-03-31 11:15:26 +0200370 sizeof(struct fsf_queue_designator), 0,
371 sizeof(struct fsf_queue_designator));
Martin Peschkea9c85772008-03-31 11:15:27 +0200372 zfcp_dbf_outd(p, "payload", (char *)&r->payload, r->payload_size, 0,
Martin Peschkedf29f4a2008-03-31 11:15:26 +0200373 r->payload_size);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200374}
375
Swen Schillig57717102009-08-18 15:43:21 +0200376static void zfcp_dbf_hba_view_qdio(char **p, struct zfcp_dbf_hba_record_qdio *r)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200377{
Martin Peschkea9c85772008-03-31 11:15:27 +0200378 zfcp_dbf_out(p, "qdio_error", "0x%08x", r->qdio_error);
Martin Peschkea9c85772008-03-31 11:15:27 +0200379 zfcp_dbf_out(p, "sbal_index", "0x%02x", r->sbal_index);
380 zfcp_dbf_out(p, "sbal_count", "0x%02x", r->sbal_count);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200381}
382
Swen Schillig57717102009-08-18 15:43:21 +0200383static void zfcp_dbf_hba_view_berr(char **p, struct fsf_bit_error_payload *r)
Swen Schillig57069382008-10-01 12:42:21 +0200384{
385 zfcp_dbf_out(p, "link_failures", "%d", r->link_failure_error_count);
386 zfcp_dbf_out(p, "loss_of_sync_err", "%d", r->loss_of_sync_error_count);
387 zfcp_dbf_out(p, "loss_of_sig_err", "%d", r->loss_of_signal_error_count);
388 zfcp_dbf_out(p, "prim_seq_err", "%d",
389 r->primitive_sequence_error_count);
390 zfcp_dbf_out(p, "inval_trans_word_err", "%d",
391 r->invalid_transmission_word_error_count);
392 zfcp_dbf_out(p, "CRC_errors", "%d", r->crc_error_count);
393 zfcp_dbf_out(p, "prim_seq_event_to", "%d",
394 r->primitive_sequence_event_timeout_count);
395 zfcp_dbf_out(p, "elast_buf_overrun_err", "%d",
396 r->elastic_buffer_overrun_error_count);
397 zfcp_dbf_out(p, "adv_rec_buf2buf_cred", "%d",
398 r->advertised_receive_b2b_credit);
399 zfcp_dbf_out(p, "curr_rec_buf2buf_cred", "%d",
400 r->current_receive_b2b_credit);
401 zfcp_dbf_out(p, "adv_trans_buf2buf_cred", "%d",
402 r->advertised_transmit_b2b_credit);
403 zfcp_dbf_out(p, "curr_trans_buf2buf_cred", "%d",
404 r->current_transmit_b2b_credit);
405}
406
Swen Schillig57717102009-08-18 15:43:21 +0200407static int zfcp_dbf_hba_view_format(debug_info_t *id, struct debug_view *view,
Martin Peschkea9c85772008-03-31 11:15:27 +0200408 char *out_buf, const char *in_buf)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200409{
Swen Schillig57717102009-08-18 15:43:21 +0200410 struct zfcp_dbf_hba_record *r = (struct zfcp_dbf_hba_record *)in_buf;
Martin Peschkea9c85772008-03-31 11:15:27 +0200411 char *p = out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200412
Martin Peschkea9c85772008-03-31 11:15:27 +0200413 if (strncmp(r->tag, "dump", ZFCP_DBF_TAG_SIZE) == 0)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200414 return 0;
415
Martin Peschkea9c85772008-03-31 11:15:27 +0200416 zfcp_dbf_tag(&p, "tag", r->tag);
417 if (isalpha(r->tag2[0]))
418 zfcp_dbf_tag(&p, "tag2", r->tag2);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200419
Martin Peschkea9c85772008-03-31 11:15:27 +0200420 if (strncmp(r->tag, "resp", ZFCP_DBF_TAG_SIZE) == 0)
Swen Schillig57717102009-08-18 15:43:21 +0200421 zfcp_dbf_hba_view_response(&p, &r->u.response);
Martin Peschkea9c85772008-03-31 11:15:27 +0200422 else if (strncmp(r->tag, "stat", ZFCP_DBF_TAG_SIZE) == 0)
Swen Schillig57717102009-08-18 15:43:21 +0200423 zfcp_dbf_hba_view_status(&p, &r->u.status);
Martin Peschkea9c85772008-03-31 11:15:27 +0200424 else if (strncmp(r->tag, "qdio", ZFCP_DBF_TAG_SIZE) == 0)
Swen Schillig57717102009-08-18 15:43:21 +0200425 zfcp_dbf_hba_view_qdio(&p, &r->u.qdio);
Swen Schillig57069382008-10-01 12:42:21 +0200426 else if (strncmp(r->tag, "berr", ZFCP_DBF_TAG_SIZE) == 0)
Swen Schillig57717102009-08-18 15:43:21 +0200427 zfcp_dbf_hba_view_berr(&p, &r->u.berr);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200428
Christof Schmittd94ce6c2008-11-04 16:35:12 +0100429 if (strncmp(r->tag, "resp", ZFCP_DBF_TAG_SIZE) != 0)
430 p += sprintf(p, "\n");
Martin Peschkea9c85772008-03-31 11:15:27 +0200431 return p - out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200432}
433
Swen Schillig57717102009-08-18 15:43:21 +0200434static struct debug_view zfcp_dbf_hba_view = {
435 .name = "structured",
436 .header_proc = zfcp_dbf_view_header,
437 .format_proc = zfcp_dbf_hba_view_format,
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200438};
439
Swen Schillig57717102009-08-18 15:43:21 +0200440static const char *zfcp_dbf_rec_tags[] = {
Martin Peschke348447e2008-03-27 14:22:01 +0100441 [ZFCP_REC_DBF_ID_THREAD] = "thread",
Martin Peschke698ec0162008-03-27 14:22:02 +0100442 [ZFCP_REC_DBF_ID_TARGET] = "target",
Martin Peschke9467a9b2008-03-27 14:22:03 +0100443 [ZFCP_REC_DBF_ID_TRIGGER] = "trigger",
Martin Peschke6f4f3652008-03-27 14:22:04 +0100444 [ZFCP_REC_DBF_ID_ACTION] = "action",
Martin Peschked79a83d2008-03-27 14:22:00 +0100445};
446
Swen Schillig57717102009-08-18 15:43:21 +0200447static int zfcp_dbf_rec_view_format(debug_info_t *id, struct debug_view *view,
Martin Peschked79a83d2008-03-27 14:22:00 +0100448 char *buf, const char *_rec)
449{
Swen Schillig57717102009-08-18 15:43:21 +0200450 struct zfcp_dbf_rec_record *r = (struct zfcp_dbf_rec_record *)_rec;
Martin Peschked79a83d2008-03-27 14:22:00 +0100451 char *p = buf;
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100452 char hint[ZFCP_DBF_ID_SIZE + 1];
Martin Peschked79a83d2008-03-27 14:22:00 +0100453
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100454 memcpy(hint, r->id2, ZFCP_DBF_ID_SIZE);
455 hint[ZFCP_DBF_ID_SIZE] = 0;
Swen Schillig57717102009-08-18 15:43:21 +0200456 zfcp_dbf_outs(&p, "tag", zfcp_dbf_rec_tags[r->id]);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100457 zfcp_dbf_outs(&p, "hint", hint);
Martin Peschked79a83d2008-03-27 14:22:00 +0100458 switch (r->id) {
Martin Peschke348447e2008-03-27 14:22:01 +0100459 case ZFCP_REC_DBF_ID_THREAD:
Martin Peschke348447e2008-03-27 14:22:01 +0100460 zfcp_dbf_out(&p, "total", "%d", r->u.thread.total);
461 zfcp_dbf_out(&p, "ready", "%d", r->u.thread.ready);
462 zfcp_dbf_out(&p, "running", "%d", r->u.thread.running);
463 break;
Martin Peschke698ec0162008-03-27 14:22:02 +0100464 case ZFCP_REC_DBF_ID_TARGET:
465 zfcp_dbf_out(&p, "reference", "0x%016Lx", r->u.target.ref);
466 zfcp_dbf_out(&p, "status", "0x%08x", r->u.target.status);
467 zfcp_dbf_out(&p, "erp_count", "%d", r->u.target.erp_count);
468 zfcp_dbf_out(&p, "d_id", "0x%06x", r->u.target.d_id);
469 zfcp_dbf_out(&p, "wwpn", "0x%016Lx", r->u.target.wwpn);
470 zfcp_dbf_out(&p, "fcp_lun", "0x%016Lx", r->u.target.fcp_lun);
471 break;
Martin Peschke9467a9b2008-03-27 14:22:03 +0100472 case ZFCP_REC_DBF_ID_TRIGGER:
473 zfcp_dbf_out(&p, "reference", "0x%016Lx", r->u.trigger.ref);
474 zfcp_dbf_out(&p, "erp_action", "0x%016Lx", r->u.trigger.action);
475 zfcp_dbf_out(&p, "requested", "%d", r->u.trigger.want);
476 zfcp_dbf_out(&p, "executed", "%d", r->u.trigger.need);
477 zfcp_dbf_out(&p, "wwpn", "0x%016Lx", r->u.trigger.wwpn);
478 zfcp_dbf_out(&p, "fcp_lun", "0x%016Lx", r->u.trigger.fcp_lun);
479 zfcp_dbf_out(&p, "adapter_status", "0x%08x", r->u.trigger.as);
480 zfcp_dbf_out(&p, "port_status", "0x%08x", r->u.trigger.ps);
481 zfcp_dbf_out(&p, "unit_status", "0x%08x", r->u.trigger.us);
482 break;
Martin Peschke6f4f3652008-03-27 14:22:04 +0100483 case ZFCP_REC_DBF_ID_ACTION:
484 zfcp_dbf_out(&p, "erp_action", "0x%016Lx", r->u.action.action);
485 zfcp_dbf_out(&p, "fsf_req", "0x%016Lx", r->u.action.fsf_req);
486 zfcp_dbf_out(&p, "status", "0x%08Lx", r->u.action.status);
487 zfcp_dbf_out(&p, "step", "0x%08Lx", r->u.action.step);
488 break;
Martin Peschked79a83d2008-03-27 14:22:00 +0100489 }
Martin Peschkeb634fff2008-03-31 11:15:24 +0200490 p += sprintf(p, "\n");
491 return p - buf;
Martin Peschked79a83d2008-03-27 14:22:00 +0100492}
493
Swen Schillig57717102009-08-18 15:43:21 +0200494static struct debug_view zfcp_dbf_rec_view = {
495 .name = "structured",
496 .header_proc = zfcp_dbf_view_header,
497 .format_proc = zfcp_dbf_rec_view_format,
Martin Peschked79a83d2008-03-27 14:22:00 +0100498};
499
Martin Peschke348447e2008-03-27 14:22:01 +0100500/**
Swen Schillig57717102009-08-18 15:43:21 +0200501 * zfcp_dbf_rec_thread - trace event related to recovery thread operation
Martin Peschke348447e2008-03-27 14:22:01 +0100502 * @id2: identifier for event
Swen Schillig57717102009-08-18 15:43:21 +0200503 * @dbf: reference to dbf structure
Christof Schmittaa0fec62008-05-19 12:17:47 +0200504 * This function assumes that the caller is holding erp_lock.
Martin Peschke348447e2008-03-27 14:22:01 +0100505 */
Swen Schillig57717102009-08-18 15:43:21 +0200506void zfcp_dbf_rec_thread(char *id2, struct zfcp_dbf *dbf)
Martin Peschke348447e2008-03-27 14:22:01 +0100507{
Swen Schillig57717102009-08-18 15:43:21 +0200508 struct zfcp_adapter *adapter = dbf->adapter;
509 struct zfcp_dbf_rec_record *r = &dbf->rec_buf;
Martin Peschke348447e2008-03-27 14:22:01 +0100510 unsigned long flags = 0;
511 struct list_head *entry;
512 unsigned ready = 0, running = 0, total;
513
Martin Peschke348447e2008-03-27 14:22:01 +0100514 list_for_each(entry, &adapter->erp_ready_head)
515 ready++;
516 list_for_each(entry, &adapter->erp_running_head)
517 running++;
518 total = adapter->erp_total_count;
Martin Peschke348447e2008-03-27 14:22:01 +0100519
Swen Schillig57717102009-08-18 15:43:21 +0200520 spin_lock_irqsave(&dbf->rec_lock, flags);
Martin Peschke348447e2008-03-27 14:22:01 +0100521 memset(r, 0, sizeof(*r));
522 r->id = ZFCP_REC_DBF_ID_THREAD;
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100523 memcpy(r->id2, id2, ZFCP_DBF_ID_SIZE);
Martin Peschke348447e2008-03-27 14:22:01 +0100524 r->u.thread.total = total;
525 r->u.thread.ready = ready;
526 r->u.thread.running = running;
Swen Schillig57717102009-08-18 15:43:21 +0200527 debug_event(dbf->rec, 6, r, sizeof(*r));
528 spin_unlock_irqrestore(&dbf->rec_lock, flags);
Martin Peschke348447e2008-03-27 14:22:01 +0100529}
530
Christof Schmittaa0fec62008-05-19 12:17:47 +0200531/**
Swen Schillig57717102009-08-18 15:43:21 +0200532 * zfcp_dbf_rec_thread - trace event related to recovery thread operation
Christof Schmittaa0fec62008-05-19 12:17:47 +0200533 * @id2: identifier for event
534 * @adapter: adapter
535 * This function assumes that the caller does not hold erp_lock.
536 */
Swen Schillig57717102009-08-18 15:43:21 +0200537void zfcp_dbf_rec_thread_lock(char *id2, struct zfcp_dbf *dbf)
Christof Schmittaa0fec62008-05-19 12:17:47 +0200538{
Swen Schillig57717102009-08-18 15:43:21 +0200539 struct zfcp_adapter *adapter = dbf->adapter;
Christof Schmittaa0fec62008-05-19 12:17:47 +0200540 unsigned long flags;
541
542 read_lock_irqsave(&adapter->erp_lock, flags);
Swen Schillig57717102009-08-18 15:43:21 +0200543 zfcp_dbf_rec_thread(id2, dbf);
Christof Schmittaa0fec62008-05-19 12:17:47 +0200544 read_unlock_irqrestore(&adapter->erp_lock, flags);
545}
546
Swen Schillig57717102009-08-18 15:43:21 +0200547static void zfcp_dbf_rec_target(char *id2, void *ref, struct zfcp_dbf *dbf,
548 atomic_t *status, atomic_t *erp_count, u64 wwpn,
549 u32 d_id, u64 fcp_lun)
Martin Peschke698ec0162008-03-27 14:22:02 +0100550{
Swen Schillig57717102009-08-18 15:43:21 +0200551 struct zfcp_dbf_rec_record *r = &dbf->rec_buf;
Martin Peschke698ec0162008-03-27 14:22:02 +0100552 unsigned long flags;
553
Swen Schillig57717102009-08-18 15:43:21 +0200554 spin_lock_irqsave(&dbf->rec_lock, flags);
Martin Peschke698ec0162008-03-27 14:22:02 +0100555 memset(r, 0, sizeof(*r));
556 r->id = ZFCP_REC_DBF_ID_TARGET;
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100557 memcpy(r->id2, id2, ZFCP_DBF_ID_SIZE);
Martin Peschke1f6f7122008-04-18 12:51:55 +0200558 r->u.target.ref = (unsigned long)ref;
Martin Peschke698ec0162008-03-27 14:22:02 +0100559 r->u.target.status = atomic_read(status);
560 r->u.target.wwpn = wwpn;
561 r->u.target.d_id = d_id;
562 r->u.target.fcp_lun = fcp_lun;
563 r->u.target.erp_count = atomic_read(erp_count);
Swen Schillig57717102009-08-18 15:43:21 +0200564 debug_event(dbf->rec, 3, r, sizeof(*r));
565 spin_unlock_irqrestore(&dbf->rec_lock, flags);
Martin Peschke698ec0162008-03-27 14:22:02 +0100566}
567
568/**
Swen Schillig57717102009-08-18 15:43:21 +0200569 * zfcp_dbf_rec_adapter - trace event for adapter state change
Martin Peschke698ec0162008-03-27 14:22:02 +0100570 * @id: identifier for trigger of state change
571 * @ref: additional reference (e.g. request)
Swen Schillig57717102009-08-18 15:43:21 +0200572 * @dbf: reference to dbf structure
Martin Peschke698ec0162008-03-27 14:22:02 +0100573 */
Swen Schillig57717102009-08-18 15:43:21 +0200574void zfcp_dbf_rec_adapter(char *id, void *ref, struct zfcp_dbf *dbf)
Martin Peschke698ec0162008-03-27 14:22:02 +0100575{
Swen Schillig57717102009-08-18 15:43:21 +0200576 struct zfcp_adapter *adapter = dbf->adapter;
577
578 zfcp_dbf_rec_target(id, ref, dbf, &adapter->status,
Martin Peschke698ec0162008-03-27 14:22:02 +0100579 &adapter->erp_counter, 0, 0, 0);
580}
581
582/**
Swen Schillig57717102009-08-18 15:43:21 +0200583 * zfcp_dbf_rec_port - trace event for port state change
Martin Peschke698ec0162008-03-27 14:22:02 +0100584 * @id: identifier for trigger of state change
585 * @ref: additional reference (e.g. request)
586 * @port: port
587 */
Swen Schillig57717102009-08-18 15:43:21 +0200588void zfcp_dbf_rec_port(char *id, void *ref, struct zfcp_port *port)
Martin Peschke698ec0162008-03-27 14:22:02 +0100589{
Swen Schillig57717102009-08-18 15:43:21 +0200590 struct zfcp_dbf *dbf = port->adapter->dbf;
Martin Peschke698ec0162008-03-27 14:22:02 +0100591
Swen Schillig57717102009-08-18 15:43:21 +0200592 zfcp_dbf_rec_target(id, ref, dbf, &port->status,
Martin Peschke698ec0162008-03-27 14:22:02 +0100593 &port->erp_counter, port->wwpn, port->d_id,
594 0);
595}
596
597/**
Swen Schillig57717102009-08-18 15:43:21 +0200598 * zfcp_dbf_rec_unit - trace event for unit state change
Martin Peschke698ec0162008-03-27 14:22:02 +0100599 * @id: identifier for trigger of state change
600 * @ref: additional reference (e.g. request)
601 * @unit: unit
602 */
Swen Schillig57717102009-08-18 15:43:21 +0200603void zfcp_dbf_rec_unit(char *id, void *ref, struct zfcp_unit *unit)
Martin Peschke698ec0162008-03-27 14:22:02 +0100604{
605 struct zfcp_port *port = unit->port;
Swen Schillig57717102009-08-18 15:43:21 +0200606 struct zfcp_dbf *dbf = port->adapter->dbf;
Martin Peschke698ec0162008-03-27 14:22:02 +0100607
Swen Schillig57717102009-08-18 15:43:21 +0200608 zfcp_dbf_rec_target(id, ref, dbf, &unit->status,
Martin Peschke698ec0162008-03-27 14:22:02 +0100609 &unit->erp_counter, port->wwpn, port->d_id,
610 unit->fcp_lun);
611}
612
Martin Peschke9467a9b2008-03-27 14:22:03 +0100613/**
Swen Schillig57717102009-08-18 15:43:21 +0200614 * zfcp_dbf_rec_trigger - trace event for triggered error recovery
Martin Peschke9467a9b2008-03-27 14:22:03 +0100615 * @id2: identifier for error recovery trigger
616 * @ref: additional reference (e.g. request)
617 * @want: originally requested error recovery action
618 * @need: error recovery action actually initiated
619 * @action: address of error recovery action struct
620 * @adapter: adapter
621 * @port: port
622 * @unit: unit
623 */
Swen Schillig57717102009-08-18 15:43:21 +0200624void zfcp_dbf_rec_trigger(char *id2, void *ref, u8 want, u8 need, void *action,
625 struct zfcp_adapter *adapter, struct zfcp_port *port,
626 struct zfcp_unit *unit)
Martin Peschke9467a9b2008-03-27 14:22:03 +0100627{
Christof Schmittd46f3842009-08-18 15:43:07 +0200628 struct zfcp_dbf *dbf = adapter->dbf;
Swen Schillig57717102009-08-18 15:43:21 +0200629 struct zfcp_dbf_rec_record *r = &dbf->rec_buf;
Martin Peschke9467a9b2008-03-27 14:22:03 +0100630 unsigned long flags;
631
Swen Schillig57717102009-08-18 15:43:21 +0200632 spin_lock_irqsave(&dbf->rec_lock, flags);
Martin Peschke9467a9b2008-03-27 14:22:03 +0100633 memset(r, 0, sizeof(*r));
634 r->id = ZFCP_REC_DBF_ID_TRIGGER;
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100635 memcpy(r->id2, id2, ZFCP_DBF_ID_SIZE);
Martin Peschke1f6f7122008-04-18 12:51:55 +0200636 r->u.trigger.ref = (unsigned long)ref;
Martin Peschke9467a9b2008-03-27 14:22:03 +0100637 r->u.trigger.want = want;
638 r->u.trigger.need = need;
Martin Peschke1f6f7122008-04-18 12:51:55 +0200639 r->u.trigger.action = (unsigned long)action;
Martin Peschke9467a9b2008-03-27 14:22:03 +0100640 r->u.trigger.as = atomic_read(&adapter->status);
641 if (port) {
642 r->u.trigger.ps = atomic_read(&port->status);
643 r->u.trigger.wwpn = port->wwpn;
644 }
645 if (unit) {
646 r->u.trigger.us = atomic_read(&unit->status);
647 r->u.trigger.fcp_lun = unit->fcp_lun;
648 }
Swen Schillig57717102009-08-18 15:43:21 +0200649 debug_event(dbf->rec, action ? 1 : 4, r, sizeof(*r));
650 spin_unlock_irqrestore(&dbf->rec_lock, flags);
Martin Peschke9467a9b2008-03-27 14:22:03 +0100651}
652
Martin Peschke6f4f3652008-03-27 14:22:04 +0100653/**
Swen Schillig57717102009-08-18 15:43:21 +0200654 * zfcp_dbf_rec_action - trace event showing progress of recovery action
Martin Peschke6f4f3652008-03-27 14:22:04 +0100655 * @id2: identifier
656 * @erp_action: error recovery action struct pointer
657 */
Swen Schillig57717102009-08-18 15:43:21 +0200658void zfcp_dbf_rec_action(char *id2, struct zfcp_erp_action *erp_action)
Martin Peschke6f4f3652008-03-27 14:22:04 +0100659{
Swen Schillig57717102009-08-18 15:43:21 +0200660 struct zfcp_dbf *dbf = erp_action->adapter->dbf;
661 struct zfcp_dbf_rec_record *r = &dbf->rec_buf;
Martin Peschke6f4f3652008-03-27 14:22:04 +0100662 unsigned long flags;
663
Swen Schillig57717102009-08-18 15:43:21 +0200664 spin_lock_irqsave(&dbf->rec_lock, flags);
Martin Peschke6f4f3652008-03-27 14:22:04 +0100665 memset(r, 0, sizeof(*r));
666 r->id = ZFCP_REC_DBF_ID_ACTION;
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100667 memcpy(r->id2, id2, ZFCP_DBF_ID_SIZE);
Martin Peschke1f6f7122008-04-18 12:51:55 +0200668 r->u.action.action = (unsigned long)erp_action;
Martin Peschke6f4f3652008-03-27 14:22:04 +0100669 r->u.action.status = erp_action->status;
670 r->u.action.step = erp_action->step;
Christof Schmitte60a6d62010-02-17 11:18:49 +0100671 r->u.action.fsf_req = erp_action->fsf_req_id;
Swen Schillig57717102009-08-18 15:43:21 +0200672 debug_event(dbf->rec, 5, r, sizeof(*r));
673 spin_unlock_irqrestore(&dbf->rec_lock, flags);
Martin Peschke6f4f3652008-03-27 14:22:04 +0100674}
675
Martin Peschkebfab1632008-03-31 11:15:31 +0200676/**
Swen Schillig57717102009-08-18 15:43:21 +0200677 * zfcp_dbf_san_ct_request - trace event for issued CT request
Martin Peschkebfab1632008-03-31 11:15:31 +0200678 * @fsf_req: request containing issued CT data
Christof Schmitt7c7dc192009-11-24 16:54:13 +0100679 * @d_id: destination id where ct request is sent to
Martin Peschkebfab1632008-03-31 11:15:31 +0200680 */
Christof Schmitt7c7dc192009-11-24 16:54:13 +0100681void zfcp_dbf_san_ct_request(struct zfcp_fsf_req *fsf_req, u32 d_id)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200682{
Christof Schmitt7c7dc192009-11-24 16:54:13 +0100683 struct zfcp_fsf_ct_els *ct = (struct zfcp_fsf_ct_els *)fsf_req->data;
684 struct zfcp_adapter *adapter = fsf_req->adapter;
Christof Schmittd46f3842009-08-18 15:43:07 +0200685 struct zfcp_dbf *dbf = adapter->dbf;
Christof Schmittdbf5dfe2009-11-24 16:54:10 +0100686 struct fc_ct_hdr *hdr = sg_virt(ct->req);
Swen Schillig57717102009-08-18 15:43:21 +0200687 struct zfcp_dbf_san_record *r = &dbf->san_buf;
688 struct zfcp_dbf_san_record_ct_request *oct = &r->u.ct_req;
Christof Schmittd94ce6c2008-11-04 16:35:12 +0100689 int level = 3;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200690 unsigned long flags;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200691
Swen Schillig57717102009-08-18 15:43:21 +0200692 spin_lock_irqsave(&dbf->san_lock, flags);
Martin Peschke6bc473d2008-03-31 11:15:29 +0200693 memset(r, 0, sizeof(*r));
694 strncpy(r->tag, "octc", ZFCP_DBF_TAG_SIZE);
Christof Schmittf0216ae2009-05-15 13:18:14 +0200695 r->fsf_reqid = fsf_req->req_id;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200696 r->fsf_seqno = fsf_req->seq_no;
Christof Schmitt7c7dc192009-11-24 16:54:13 +0100697 oct->d_id = d_id;
Christof Schmittdbf5dfe2009-11-24 16:54:10 +0100698 oct->cmd_req_code = hdr->ct_cmd;
699 oct->revision = hdr->ct_rev;
700 oct->gs_type = hdr->ct_fs_type;
701 oct->gs_subtype = hdr->ct_fs_subtype;
702 oct->options = hdr->ct_options;
703 oct->max_res_size = hdr->ct_mr_size;
704 oct->len = min((int)ct->req->length - (int)sizeof(struct fc_ct_hdr),
Christof Schmittd94ce6c2008-11-04 16:35:12 +0100705 ZFCP_DBF_SAN_MAX_PAYLOAD);
Swen Schillig57717102009-08-18 15:43:21 +0200706 debug_event(dbf->san, level, r, sizeof(*r));
707 zfcp_dbf_hexdump(dbf->san, r, sizeof(*r), level,
Christof Schmittdbf5dfe2009-11-24 16:54:10 +0100708 (void *)hdr + sizeof(struct fc_ct_hdr), oct->len);
Swen Schillig57717102009-08-18 15:43:21 +0200709 spin_unlock_irqrestore(&dbf->san_lock, flags);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200710}
711
Martin Peschkebfab1632008-03-31 11:15:31 +0200712/**
Swen Schillig57717102009-08-18 15:43:21 +0200713 * zfcp_dbf_san_ct_response - trace event for completion of CT request
Martin Peschkebfab1632008-03-31 11:15:31 +0200714 * @fsf_req: request containing CT response
715 */
Swen Schillig57717102009-08-18 15:43:21 +0200716void zfcp_dbf_san_ct_response(struct zfcp_fsf_req *fsf_req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200717{
Christof Schmitt7c7dc192009-11-24 16:54:13 +0100718 struct zfcp_fsf_ct_els *ct = (struct zfcp_fsf_ct_els *)fsf_req->data;
719 struct zfcp_adapter *adapter = fsf_req->adapter;
Christof Schmittdbf5dfe2009-11-24 16:54:10 +0100720 struct fc_ct_hdr *hdr = sg_virt(ct->resp);
Christof Schmittd46f3842009-08-18 15:43:07 +0200721 struct zfcp_dbf *dbf = adapter->dbf;
Swen Schillig57717102009-08-18 15:43:21 +0200722 struct zfcp_dbf_san_record *r = &dbf->san_buf;
723 struct zfcp_dbf_san_record_ct_response *rct = &r->u.ct_resp;
Christof Schmittd94ce6c2008-11-04 16:35:12 +0100724 int level = 3;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200725 unsigned long flags;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200726
Swen Schillig57717102009-08-18 15:43:21 +0200727 spin_lock_irqsave(&dbf->san_lock, flags);
Martin Peschke6bc473d2008-03-31 11:15:29 +0200728 memset(r, 0, sizeof(*r));
729 strncpy(r->tag, "rctc", ZFCP_DBF_TAG_SIZE);
Christof Schmittf0216ae2009-05-15 13:18:14 +0200730 r->fsf_reqid = fsf_req->req_id;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200731 r->fsf_seqno = fsf_req->seq_no;
Christof Schmittdbf5dfe2009-11-24 16:54:10 +0100732 rct->cmd_rsp_code = hdr->ct_cmd;
733 rct->revision = hdr->ct_rev;
734 rct->reason_code = hdr->ct_reason;
735 rct->expl = hdr->ct_explan;
736 rct->vendor_unique = hdr->ct_vendor;
737 rct->max_res_size = hdr->ct_mr_size;
738 rct->len = min((int)ct->resp->length - (int)sizeof(struct fc_ct_hdr),
Christof Schmittd94ce6c2008-11-04 16:35:12 +0100739 ZFCP_DBF_SAN_MAX_PAYLOAD);
Swen Schillig57717102009-08-18 15:43:21 +0200740 debug_event(dbf->san, level, r, sizeof(*r));
741 zfcp_dbf_hexdump(dbf->san, r, sizeof(*r), level,
Christof Schmittdbf5dfe2009-11-24 16:54:10 +0100742 (void *)hdr + sizeof(struct fc_ct_hdr), rct->len);
Swen Schillig57717102009-08-18 15:43:21 +0200743 spin_unlock_irqrestore(&dbf->san_lock, flags);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200744}
745
Swen Schillig57717102009-08-18 15:43:21 +0200746static void zfcp_dbf_san_els(const char *tag, int level,
Christof Schmitt7c7dc192009-11-24 16:54:13 +0100747 struct zfcp_fsf_req *fsf_req, u32 d_id,
748 void *buffer, int buflen)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200749{
750 struct zfcp_adapter *adapter = fsf_req->adapter;
Christof Schmittd46f3842009-08-18 15:43:07 +0200751 struct zfcp_dbf *dbf = adapter->dbf;
Swen Schillig57717102009-08-18 15:43:21 +0200752 struct zfcp_dbf_san_record *rec = &dbf->san_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200753 unsigned long flags;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200754
Swen Schillig57717102009-08-18 15:43:21 +0200755 spin_lock_irqsave(&dbf->san_lock, flags);
Martin Peschke6bc473d2008-03-31 11:15:29 +0200756 memset(rec, 0, sizeof(*rec));
Martin Peschke0f65e952008-03-27 14:21:56 +0100757 strncpy(rec->tag, tag, ZFCP_DBF_TAG_SIZE);
Christof Schmittf0216ae2009-05-15 13:18:14 +0200758 rec->fsf_reqid = fsf_req->req_id;
Martin Peschke0f65e952008-03-27 14:21:56 +0100759 rec->fsf_seqno = fsf_req->seq_no;
Christof Schmitt7c7dc192009-11-24 16:54:13 +0100760 rec->u.els.d_id = d_id;
Swen Schillig57717102009-08-18 15:43:21 +0200761 debug_event(dbf->san, level, rec, sizeof(*rec));
762 zfcp_dbf_hexdump(dbf->san, rec, sizeof(*rec), level,
Christof Schmittd94ce6c2008-11-04 16:35:12 +0100763 buffer, min(buflen, ZFCP_DBF_SAN_MAX_PAYLOAD));
Swen Schillig57717102009-08-18 15:43:21 +0200764 spin_unlock_irqrestore(&dbf->san_lock, flags);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200765}
766
Martin Peschkebfab1632008-03-31 11:15:31 +0200767/**
Swen Schillig57717102009-08-18 15:43:21 +0200768 * zfcp_dbf_san_els_request - trace event for issued ELS
Martin Peschkebfab1632008-03-31 11:15:31 +0200769 * @fsf_req: request containing issued ELS
770 */
Swen Schillig57717102009-08-18 15:43:21 +0200771void zfcp_dbf_san_els_request(struct zfcp_fsf_req *fsf_req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200772{
Christof Schmitt7c7dc192009-11-24 16:54:13 +0100773 struct zfcp_fsf_ct_els *els = (struct zfcp_fsf_ct_els *)fsf_req->data;
774 u32 d_id = ntoh24(fsf_req->qtcb->bottom.support.d_id);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200775
Christof Schmitt7c7dc192009-11-24 16:54:13 +0100776 zfcp_dbf_san_els("oels", 2, fsf_req, d_id,
777 sg_virt(els->req), els->req->length);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200778}
779
Martin Peschkebfab1632008-03-31 11:15:31 +0200780/**
Swen Schillig57717102009-08-18 15:43:21 +0200781 * zfcp_dbf_san_els_response - trace event for completed ELS
Martin Peschkebfab1632008-03-31 11:15:31 +0200782 * @fsf_req: request containing ELS response
783 */
Swen Schillig57717102009-08-18 15:43:21 +0200784void zfcp_dbf_san_els_response(struct zfcp_fsf_req *fsf_req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200785{
Christof Schmitt7c7dc192009-11-24 16:54:13 +0100786 struct zfcp_fsf_ct_els *els = (struct zfcp_fsf_ct_els *)fsf_req->data;
787 u32 d_id = ntoh24(fsf_req->qtcb->bottom.support.d_id);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200788
Christof Schmitt7c7dc192009-11-24 16:54:13 +0100789 zfcp_dbf_san_els("rels", 2, fsf_req, d_id,
790 sg_virt(els->resp), els->resp->length);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200791}
792
Martin Peschkebfab1632008-03-31 11:15:31 +0200793/**
Swen Schillig57717102009-08-18 15:43:21 +0200794 * zfcp_dbf_san_incoming_els - trace event for incomig ELS
Martin Peschkebfab1632008-03-31 11:15:31 +0200795 * @fsf_req: request containing unsolicited status buffer with incoming ELS
796 */
Swen Schillig57717102009-08-18 15:43:21 +0200797void zfcp_dbf_san_incoming_els(struct zfcp_fsf_req *fsf_req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200798{
Martin Peschke92c7a832008-03-31 11:15:30 +0200799 struct fsf_status_read_buffer *buf =
800 (struct fsf_status_read_buffer *)fsf_req->data;
801 int length = (int)buf->length -
802 (int)((void *)&buf->payload - (void *)buf);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200803
Christof Schmitt800c0ca2009-11-24 16:54:12 +0100804 zfcp_dbf_san_els("iels", 1, fsf_req, ntoh24(buf->d_id),
Christof Schmitt7c7dc192009-11-24 16:54:13 +0100805 (void *)buf->payload.data, length);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200806}
807
Swen Schillig57717102009-08-18 15:43:21 +0200808static int zfcp_dbf_san_view_format(debug_info_t *id, struct debug_view *view,
Martin Peschke92c7a832008-03-31 11:15:30 +0200809 char *out_buf, const char *in_buf)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200810{
Swen Schillig57717102009-08-18 15:43:21 +0200811 struct zfcp_dbf_san_record *r = (struct zfcp_dbf_san_record *)in_buf;
Martin Peschkeb634fff2008-03-31 11:15:24 +0200812 char *p = out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200813
Martin Peschkeb634fff2008-03-31 11:15:24 +0200814 if (strncmp(r->tag, "dump", ZFCP_DBF_TAG_SIZE) == 0)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200815 return 0;
816
Martin Peschkea9c85772008-03-31 11:15:27 +0200817 zfcp_dbf_tag(&p, "tag", r->tag);
Martin Peschkeb634fff2008-03-31 11:15:24 +0200818 zfcp_dbf_out(&p, "fsf_reqid", "0x%0Lx", r->fsf_reqid);
819 zfcp_dbf_out(&p, "fsf_seqno", "0x%08x", r->fsf_seqno);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200820
Martin Peschkeb634fff2008-03-31 11:15:24 +0200821 if (strncmp(r->tag, "octc", ZFCP_DBF_TAG_SIZE) == 0) {
Swen Schillig57717102009-08-18 15:43:21 +0200822 struct zfcp_dbf_san_record_ct_request *ct = &r->u.ct_req;
Christof Schmitt7c7dc192009-11-24 16:54:13 +0100823 zfcp_dbf_out(&p, "d_id", "0x%06x", ct->d_id);
Martin Peschke6bc473d2008-03-31 11:15:29 +0200824 zfcp_dbf_out(&p, "cmd_req_code", "0x%04x", ct->cmd_req_code);
825 zfcp_dbf_out(&p, "revision", "0x%02x", ct->revision);
826 zfcp_dbf_out(&p, "gs_type", "0x%02x", ct->gs_type);
827 zfcp_dbf_out(&p, "gs_subtype", "0x%02x", ct->gs_subtype);
828 zfcp_dbf_out(&p, "options", "0x%02x", ct->options);
829 zfcp_dbf_out(&p, "max_res_size", "0x%04x", ct->max_res_size);
Martin Peschkeb634fff2008-03-31 11:15:24 +0200830 } else if (strncmp(r->tag, "rctc", ZFCP_DBF_TAG_SIZE) == 0) {
Swen Schillig57717102009-08-18 15:43:21 +0200831 struct zfcp_dbf_san_record_ct_response *ct = &r->u.ct_resp;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200832 zfcp_dbf_out(&p, "cmd_rsp_code", "0x%04x", ct->cmd_rsp_code);
833 zfcp_dbf_out(&p, "revision", "0x%02x", ct->revision);
834 zfcp_dbf_out(&p, "reason_code", "0x%02x", ct->reason_code);
835 zfcp_dbf_out(&p, "reason_code_expl", "0x%02x", ct->expl);
836 zfcp_dbf_out(&p, "vendor_unique", "0x%02x", ct->vendor_unique);
Christof Schmitt39eb7e9a2008-12-19 16:57:01 +0100837 zfcp_dbf_out(&p, "max_res_size", "0x%04x", ct->max_res_size);
Martin Peschkeb634fff2008-03-31 11:15:24 +0200838 } else if (strncmp(r->tag, "oels", ZFCP_DBF_TAG_SIZE) == 0 ||
839 strncmp(r->tag, "rels", ZFCP_DBF_TAG_SIZE) == 0 ||
840 strncmp(r->tag, "iels", ZFCP_DBF_TAG_SIZE) == 0) {
Swen Schillig57717102009-08-18 15:43:21 +0200841 struct zfcp_dbf_san_record_els *els = &r->u.els;
Christof Schmitt7c7dc192009-11-24 16:54:13 +0100842 zfcp_dbf_out(&p, "d_id", "0x%06x", els->d_id);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200843 }
Martin Peschkeb634fff2008-03-31 11:15:24 +0200844 return p - out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200845}
846
Swen Schillig57717102009-08-18 15:43:21 +0200847static struct debug_view zfcp_dbf_san_view = {
848 .name = "structured",
849 .header_proc = zfcp_dbf_view_header,
850 .format_proc = zfcp_dbf_san_view_format,
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200851};
852
Swen Schillig57717102009-08-18 15:43:21 +0200853void _zfcp_dbf_scsi(const char *tag, const char *tag2, int level,
854 struct zfcp_dbf *dbf, struct scsi_cmnd *scsi_cmnd,
855 struct zfcp_fsf_req *fsf_req, unsigned long old_req_id)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200856{
Swen Schillig57717102009-08-18 15:43:21 +0200857 struct zfcp_dbf_scsi_record *rec = &dbf->scsi_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200858 struct zfcp_dbf_dump *dump = (struct zfcp_dbf_dump *)rec;
859 unsigned long flags;
Christof Schmitt4318e082009-11-24 16:54:08 +0100860 struct fcp_resp_with_ext *fcp_rsp;
861 struct fcp_resp_rsp_info *fcp_rsp_info = NULL;
862 char *fcp_sns_info = NULL;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200863 int offset = 0, buflen = 0;
864
Swen Schillig57717102009-08-18 15:43:21 +0200865 spin_lock_irqsave(&dbf->scsi_lock, flags);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200866 do {
Martin Peschke6bc473d2008-03-31 11:15:29 +0200867 memset(rec, 0, sizeof(*rec));
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200868 if (offset == 0) {
869 strncpy(rec->tag, tag, ZFCP_DBF_TAG_SIZE);
870 strncpy(rec->tag2, tag2, ZFCP_DBF_TAG_SIZE);
Maxim Shchetynined829ad2006-02-11 01:42:58 +0100871 if (scsi_cmnd != NULL) {
872 if (scsi_cmnd->device) {
873 rec->scsi_id = scsi_cmnd->device->id;
874 rec->scsi_lun = scsi_cmnd->device->lun;
875 }
876 rec->scsi_result = scsi_cmnd->result;
877 rec->scsi_cmnd = (unsigned long)scsi_cmnd;
878 rec->scsi_serial = scsi_cmnd->serial_number;
Boaz Harrosh64a87b22008-04-30 11:19:47 +0300879 memcpy(rec->scsi_opcode, scsi_cmnd->cmnd,
Maxim Shchetynined829ad2006-02-11 01:42:58 +0100880 min((int)scsi_cmnd->cmd_len,
881 ZFCP_DBF_SCSI_OPCODE));
882 rec->scsi_retries = scsi_cmnd->retries;
883 rec->scsi_allowed = scsi_cmnd->allowed;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200884 }
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200885 if (fsf_req != NULL) {
Christof Schmitt4318e082009-11-24 16:54:08 +0100886 fcp_rsp = (struct fcp_resp_with_ext *)
887 &(fsf_req->qtcb->bottom.io.fcp_rsp);
888 fcp_rsp_info = (struct fcp_resp_rsp_info *)
889 &fcp_rsp[1];
890 fcp_sns_info = (char *) &fcp_rsp[1];
891 if (fcp_rsp->resp.fr_flags & FCP_RSP_LEN_VAL)
892 fcp_sns_info += fcp_rsp->ext.fr_sns_len;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200893
Christof Schmitt4318e082009-11-24 16:54:08 +0100894 rec->rsp_validity = fcp_rsp->resp.fr_flags;
895 rec->rsp_scsi_status = fcp_rsp->resp.fr_status;
896 rec->rsp_resid = fcp_rsp->ext.fr_resid;
897 if (fcp_rsp->resp.fr_flags & FCP_RSP_LEN_VAL)
898 rec->rsp_code = fcp_rsp_info->rsp_code;
899 if (fcp_rsp->resp.fr_flags & FCP_SNS_LEN_VAL) {
900 buflen = min(fcp_rsp->ext.fr_sns_len,
901 (u32)ZFCP_DBF_SCSI_MAX_FCP_SNS_INFO);
Martin Peschke6bc473d2008-03-31 11:15:29 +0200902 rec->sns_info_len = buflen;
903 memcpy(rec->sns_info, fcp_sns_info,
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200904 min(buflen,
905 ZFCP_DBF_SCSI_FCP_SNS_INFO));
906 offset += min(buflen,
907 ZFCP_DBF_SCSI_FCP_SNS_INFO);
908 }
909
Christof Schmittf0216ae2009-05-15 13:18:14 +0200910 rec->fsf_reqid = fsf_req->req_id;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200911 rec->fsf_seqno = fsf_req->seq_no;
912 rec->fsf_issued = fsf_req->issued;
913 }
Martin Peschke6bc473d2008-03-31 11:15:29 +0200914 rec->old_fsf_reqid = old_req_id;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200915 } else {
916 strncpy(dump->tag, "dump", ZFCP_DBF_TAG_SIZE);
917 dump->total_size = buflen;
918 dump->offset = offset;
919 dump->size = min(buflen - offset,
920 (int)sizeof(struct
Swen Schillig57717102009-08-18 15:43:21 +0200921 zfcp_dbf_scsi_record) -
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200922 (int)sizeof(struct zfcp_dbf_dump));
923 memcpy(dump->data, fcp_sns_info + offset, dump->size);
924 offset += dump->size;
925 }
Swen Schillig57717102009-08-18 15:43:21 +0200926 debug_event(dbf->scsi, level, rec, sizeof(*rec));
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200927 } while (offset < buflen);
Swen Schillig57717102009-08-18 15:43:21 +0200928 spin_unlock_irqrestore(&dbf->scsi_lock, flags);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200929}
930
Swen Schillig57717102009-08-18 15:43:21 +0200931static int zfcp_dbf_scsi_view_format(debug_info_t *id, struct debug_view *view,
Martin Peschke92c7a832008-03-31 11:15:30 +0200932 char *out_buf, const char *in_buf)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200933{
Swen Schillig57717102009-08-18 15:43:21 +0200934 struct zfcp_dbf_scsi_record *r = (struct zfcp_dbf_scsi_record *)in_buf;
Martin Peschke8fc5af12008-03-31 11:15:23 +0200935 struct timespec t;
Martin Peschkeb634fff2008-03-31 11:15:24 +0200936 char *p = out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200937
Martin Peschkeb634fff2008-03-31 11:15:24 +0200938 if (strncmp(r->tag, "dump", ZFCP_DBF_TAG_SIZE) == 0)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200939 return 0;
940
Martin Peschkea9c85772008-03-31 11:15:27 +0200941 zfcp_dbf_tag(&p, "tag", r->tag);
942 zfcp_dbf_tag(&p, "tag2", r->tag2);
Martin Peschkeb634fff2008-03-31 11:15:24 +0200943 zfcp_dbf_out(&p, "scsi_id", "0x%08x", r->scsi_id);
944 zfcp_dbf_out(&p, "scsi_lun", "0x%08x", r->scsi_lun);
945 zfcp_dbf_out(&p, "scsi_result", "0x%08x", r->scsi_result);
946 zfcp_dbf_out(&p, "scsi_cmnd", "0x%0Lx", r->scsi_cmnd);
947 zfcp_dbf_out(&p, "scsi_serial", "0x%016Lx", r->scsi_serial);
Martin Peschkedf29f4a2008-03-31 11:15:26 +0200948 zfcp_dbf_outd(&p, "scsi_opcode", r->scsi_opcode, ZFCP_DBF_SCSI_OPCODE,
949 0, ZFCP_DBF_SCSI_OPCODE);
Martin Peschkeb634fff2008-03-31 11:15:24 +0200950 zfcp_dbf_out(&p, "scsi_retries", "0x%02x", r->scsi_retries);
951 zfcp_dbf_out(&p, "scsi_allowed", "0x%02x", r->scsi_allowed);
952 if (strncmp(r->tag, "abrt", ZFCP_DBF_TAG_SIZE) == 0)
Martin Peschke6bc473d2008-03-31 11:15:29 +0200953 zfcp_dbf_out(&p, "old_fsf_reqid", "0x%0Lx", r->old_fsf_reqid);
Martin Peschkeb634fff2008-03-31 11:15:24 +0200954 zfcp_dbf_out(&p, "fsf_reqid", "0x%0Lx", r->fsf_reqid);
955 zfcp_dbf_out(&p, "fsf_seqno", "0x%08x", r->fsf_seqno);
Christof Schmittb592e892009-08-18 15:43:31 +0200956 stck_to_timespec(r->fsf_issued, &t);
Martin Peschkeb634fff2008-03-31 11:15:24 +0200957 zfcp_dbf_out(&p, "fsf_issued", "%011lu:%06lu", t.tv_sec, t.tv_nsec);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200958
Martin Peschkeb634fff2008-03-31 11:15:24 +0200959 if (strncmp(r->tag, "rslt", ZFCP_DBF_TAG_SIZE) == 0) {
Martin Peschke6bc473d2008-03-31 11:15:29 +0200960 zfcp_dbf_out(&p, "fcp_rsp_validity", "0x%02x", r->rsp_validity);
961 zfcp_dbf_out(&p, "fcp_rsp_scsi_status", "0x%02x",
962 r->rsp_scsi_status);
963 zfcp_dbf_out(&p, "fcp_rsp_resid", "0x%08x", r->rsp_resid);
964 zfcp_dbf_out(&p, "fcp_rsp_code", "0x%08x", r->rsp_code);
965 zfcp_dbf_out(&p, "fcp_sns_info_len", "0x%08x", r->sns_info_len);
966 zfcp_dbf_outd(&p, "fcp_sns_info", r->sns_info,
967 min((int)r->sns_info_len,
Martin Peschkedf29f4a2008-03-31 11:15:26 +0200968 ZFCP_DBF_SCSI_FCP_SNS_INFO), 0,
Martin Peschke6bc473d2008-03-31 11:15:29 +0200969 r->sns_info_len);
Martin Peschkeb634fff2008-03-31 11:15:24 +0200970 }
971 p += sprintf(p, "\n");
972 return p - out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200973}
974
Swen Schillig57717102009-08-18 15:43:21 +0200975static struct debug_view zfcp_dbf_scsi_view = {
976 .name = "structured",
977 .header_proc = zfcp_dbf_view_header,
978 .format_proc = zfcp_dbf_scsi_view_format,
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200979};
980
Christof Schmittd46f3842009-08-18 15:43:07 +0200981static debug_info_t *zfcp_dbf_reg(const char *name, int level,
982 struct debug_view *view, int size)
983{
984 struct debug_info *d;
985
986 d = debug_register(name, dbfsize, level, size);
987 if (!d)
988 return NULL;
989
990 debug_register_view(d, &debug_hex_ascii_view);
991 debug_register_view(d, view);
992 debug_set_level(d, level);
993
994 return d;
995}
996
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200997/**
998 * zfcp_adapter_debug_register - registers debug feature for an adapter
999 * @adapter: pointer to adapter for which debug features should be registered
1000 * return: -ENOMEM on error, 0 otherwise
1001 */
Swen Schillig57717102009-08-18 15:43:21 +02001002int zfcp_dbf_adapter_register(struct zfcp_adapter *adapter)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001003{
1004 char dbf_name[DEBUG_MAX_NAME_LEN];
Christof Schmittd46f3842009-08-18 15:43:07 +02001005 struct zfcp_dbf *dbf;
1006
1007 dbf = kmalloc(sizeof(struct zfcp_dbf), GFP_KERNEL);
1008 if (!dbf)
1009 return -ENOMEM;
1010
Swen Schillig57717102009-08-18 15:43:21 +02001011 dbf->adapter = adapter;
1012
1013 spin_lock_init(&dbf->hba_lock);
1014 spin_lock_init(&dbf->san_lock);
1015 spin_lock_init(&dbf->scsi_lock);
1016 spin_lock_init(&dbf->rec_lock);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001017
1018 /* debug feature area which records recovery activity */
Christof Schmittb225cf92008-12-19 16:57:00 +01001019 sprintf(dbf_name, "zfcp_%s_rec", dev_name(&adapter->ccw_device->dev));
Swen Schillig57717102009-08-18 15:43:21 +02001020 dbf->rec = zfcp_dbf_reg(dbf_name, 3, &zfcp_dbf_rec_view,
1021 sizeof(struct zfcp_dbf_rec_record));
1022 if (!dbf->rec)
1023 goto err_out;
Martin Peschked79a83d2008-03-27 14:22:00 +01001024
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001025 /* debug feature area which records HBA (FSF and QDIO) conditions */
Christof Schmittb225cf92008-12-19 16:57:00 +01001026 sprintf(dbf_name, "zfcp_%s_hba", dev_name(&adapter->ccw_device->dev));
Swen Schillig57717102009-08-18 15:43:21 +02001027 dbf->hba = zfcp_dbf_reg(dbf_name, 3, &zfcp_dbf_hba_view,
1028 sizeof(struct zfcp_dbf_hba_record));
1029 if (!dbf->hba)
1030 goto err_out;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001031
1032 /* debug feature area which records SAN command failures and recovery */
Christof Schmittb225cf92008-12-19 16:57:00 +01001033 sprintf(dbf_name, "zfcp_%s_san", dev_name(&adapter->ccw_device->dev));
Swen Schillig57717102009-08-18 15:43:21 +02001034 dbf->san = zfcp_dbf_reg(dbf_name, 6, &zfcp_dbf_san_view,
1035 sizeof(struct zfcp_dbf_san_record));
1036 if (!dbf->san)
1037 goto err_out;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001038
1039 /* debug feature area which records SCSI command failures and recovery */
Christof Schmittb225cf92008-12-19 16:57:00 +01001040 sprintf(dbf_name, "zfcp_%s_scsi", dev_name(&adapter->ccw_device->dev));
Swen Schillig57717102009-08-18 15:43:21 +02001041 dbf->scsi = zfcp_dbf_reg(dbf_name, 3, &zfcp_dbf_scsi_view,
1042 sizeof(struct zfcp_dbf_scsi_record));
1043 if (!dbf->scsi)
1044 goto err_out;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001045
Christof Schmittd46f3842009-08-18 15:43:07 +02001046 adapter->dbf = dbf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001047 return 0;
1048
Swen Schillig57717102009-08-18 15:43:21 +02001049err_out:
1050 zfcp_dbf_adapter_unregister(dbf);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001051 return -ENOMEM;
1052}
1053
1054/**
1055 * zfcp_adapter_debug_unregister - unregisters debug feature for an adapter
Swen Schillig57717102009-08-18 15:43:21 +02001056 * @dbf: pointer to dbf for which debug features should be unregistered
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001057 */
Swen Schillig57717102009-08-18 15:43:21 +02001058void zfcp_dbf_adapter_unregister(struct zfcp_dbf *dbf)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001059{
Swen Schilligf3450c72009-11-24 16:53:59 +01001060 if (!dbf)
1061 return;
Swen Schillig57717102009-08-18 15:43:21 +02001062 debug_unregister(dbf->scsi);
1063 debug_unregister(dbf->san);
1064 debug_unregister(dbf->hba);
1065 debug_unregister(dbf->rec);
1066 dbf->adapter->dbf = NULL;
1067 kfree(dbf);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001068}
Swen Schillig57717102009-08-18 15:43:21 +02001069