blob: 6ece47e5148c2cfd2892aaa0be07d8aacf2df592 [file] [log] [blame]
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001/*
Christof Schmitt553448f2008-06-10 18:20:58 +02002 * zfcp device driver
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02003 *
Christof Schmitt553448f2008-06-10 18:20:58 +02004 * Debug traces for zfcp.
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02005 *
Christof Schmittd46f3842009-08-18 15:43:07 +02006 * Copyright IBM Corporation 2002, 2009
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02007 */
8
Christof Schmittecf39d42008-12-25 13:39:53 +01009#define KMSG_COMPONENT "zfcp"
10#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
11
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020012#include <linux/ctype.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090013#include <linux/slab.h>
Heiko Carstens364c8552007-10-12 16:11:35 +020014#include <asm/debug.h>
Christof Schmittd46f3842009-08-18 15:43:07 +020015#include "zfcp_dbf.h"
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020016#include "zfcp_ext.h"
Christof Schmittbd0072e2009-11-24 16:54:11 +010017#include "zfcp_fc.h"
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020018
19static u32 dbfsize = 4;
20
21module_param(dbfsize, uint, 0400);
22MODULE_PARM_DESC(dbfsize,
23 "number of pages for each debug feature area (default 4)");
24
Martin Peschkec15450e2008-03-27 14:21:55 +010025static void zfcp_dbf_hexdump(debug_info_t *dbf, void *to, int to_len,
26 int level, char *from, int from_len)
27{
28 int offset;
29 struct zfcp_dbf_dump *dump = to;
30 int room = to_len - sizeof(*dump);
31
32 for (offset = 0; offset < from_len; offset += dump->size) {
33 memset(to, 0, to_len);
34 strncpy(dump->tag, "dump", ZFCP_DBF_TAG_SIZE);
35 dump->total_size = from_len;
36 dump->offset = offset;
37 dump->size = min(from_len - offset, room);
38 memcpy(dump->data, from + offset, dump->size);
Christof Schmittd94ce6c2008-11-04 16:35:12 +010039 debug_event(dbf, level, dump, dump->size + sizeof(*dump));
Martin Peschkec15450e2008-03-27 14:21:55 +010040 }
41}
42
Martin Peschkea9c85772008-03-31 11:15:27 +020043static void zfcp_dbf_tag(char **p, const char *label, const char *tag)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020044{
Martin Peschkea9c85772008-03-31 11:15:27 +020045 int i;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020046
Martin Peschkea9c85772008-03-31 11:15:27 +020047 *p += sprintf(*p, "%-24s", label);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020048 for (i = 0; i < ZFCP_DBF_TAG_SIZE; i++)
Martin Peschkea9c85772008-03-31 11:15:27 +020049 *p += sprintf(*p, "%c", tag[i]);
50 *p += sprintf(*p, "\n");
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020051}
52
Martin Peschke10223c62008-03-27 14:21:59 +010053static void zfcp_dbf_out(char **buf, const char *s, const char *format, ...)
54{
55 va_list arg;
56
57 *buf += sprintf(*buf, "%-24s", s);
58 va_start(arg, format);
59 *buf += vsprintf(*buf, format, arg);
60 va_end(arg);
61 *buf += sprintf(*buf, "\n");
62}
63
Martin Peschkedf29f4a2008-03-31 11:15:26 +020064static void zfcp_dbf_outd(char **p, const char *label, char *buffer,
65 int buflen, int offset, int total_size)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020066{
Martin Peschkedf29f4a2008-03-31 11:15:26 +020067 if (!offset)
68 *p += sprintf(*p, "%-24s ", label);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020069 while (buflen--) {
70 if (offset > 0) {
71 if ((offset % 32) == 0)
Martin Peschkedf29f4a2008-03-31 11:15:26 +020072 *p += sprintf(*p, "\n%-24c ", ' ');
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020073 else if ((offset % 4) == 0)
Martin Peschkedf29f4a2008-03-31 11:15:26 +020074 *p += sprintf(*p, " ");
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020075 }
Martin Peschkedf29f4a2008-03-31 11:15:26 +020076 *p += sprintf(*p, "%02x", *buffer++);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020077 if (++offset == total_size) {
Martin Peschkedf29f4a2008-03-31 11:15:26 +020078 *p += sprintf(*p, "\n");
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020079 break;
80 }
81 }
Martin Peschkedf29f4a2008-03-31 11:15:26 +020082 if (!total_size)
83 *p += sprintf(*p, "\n");
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020084}
85
Martin Peschke92c7a832008-03-31 11:15:30 +020086static int zfcp_dbf_view_header(debug_info_t *id, struct debug_view *view,
87 int area, debug_entry_t *entry, char *out_buf)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020088{
89 struct zfcp_dbf_dump *dump = (struct zfcp_dbf_dump *)DEBUG_DATA(entry);
Martin Peschke8fc5af12008-03-31 11:15:23 +020090 struct timespec t;
Martin Peschkeb634fff2008-03-31 11:15:24 +020091 char *p = out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020092
93 if (strncmp(dump->tag, "dump", ZFCP_DBF_TAG_SIZE) != 0) {
Christof Schmittb592e892009-08-18 15:43:31 +020094 stck_to_timespec(entry->id.stck, &t);
Martin Peschkeb634fff2008-03-31 11:15:24 +020095 zfcp_dbf_out(&p, "timestamp", "%011lu:%06lu",
96 t.tv_sec, t.tv_nsec);
97 zfcp_dbf_out(&p, "cpu", "%02i", entry->id.fields.cpuid);
98 } else {
Christof Schmittd94ce6c2008-11-04 16:35:12 +010099 zfcp_dbf_outd(&p, "", dump->data, dump->size, dump->offset,
Martin Peschkedf29f4a2008-03-31 11:15:26 +0200100 dump->total_size);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200101 if ((dump->offset + dump->size) == dump->total_size)
Martin Peschkeb634fff2008-03-31 11:15:24 +0200102 p += sprintf(p, "\n");
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200103 }
Martin Peschkeb634fff2008-03-31 11:15:24 +0200104 return p - out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200105}
106
Swen Schillig57717102009-08-18 15:43:21 +0200107void _zfcp_dbf_hba_fsf_response(const char *tag2, int level,
108 struct zfcp_fsf_req *fsf_req,
109 struct zfcp_dbf *dbf)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200110{
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200111 struct fsf_qtcb *qtcb = fsf_req->qtcb;
112 union fsf_prot_status_qual *prot_status_qual =
Martin Peschke92c7a832008-03-31 11:15:30 +0200113 &qtcb->prefix.prot_status_qual;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200114 union fsf_status_qual *fsf_status_qual = &qtcb->header.fsf_status_qual;
115 struct scsi_cmnd *scsi_cmnd;
116 struct zfcp_port *port;
117 struct zfcp_unit *unit;
118 struct zfcp_send_els *send_els;
Swen Schillig57717102009-08-18 15:43:21 +0200119 struct zfcp_dbf_hba_record *rec = &dbf->hba_buf;
120 struct zfcp_dbf_hba_record_response *response = &rec->u.response;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200121 unsigned long flags;
122
Swen Schillig57717102009-08-18 15:43:21 +0200123 spin_lock_irqsave(&dbf->hba_lock, flags);
Martin Peschke6bc473d2008-03-31 11:15:29 +0200124 memset(rec, 0, sizeof(*rec));
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200125 strncpy(rec->tag, "resp", ZFCP_DBF_TAG_SIZE);
Christof Schmitt2e261af2009-08-18 15:43:09 +0200126 strncpy(rec->tag2, tag2, ZFCP_DBF_TAG_SIZE);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200127
128 response->fsf_command = fsf_req->fsf_command;
Christof Schmittf0216ae2009-05-15 13:18:14 +0200129 response->fsf_reqid = fsf_req->req_id;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200130 response->fsf_seqno = fsf_req->seq_no;
131 response->fsf_issued = fsf_req->issued;
132 response->fsf_prot_status = qtcb->prefix.prot_status;
133 response->fsf_status = qtcb->header.fsf_status;
134 memcpy(response->fsf_prot_status_qual,
135 prot_status_qual, FSF_PROT_STATUS_QUAL_SIZE);
136 memcpy(response->fsf_status_qual,
137 fsf_status_qual, FSF_STATUS_QUALIFIER_SIZE);
138 response->fsf_req_status = fsf_req->status;
Christof Schmitt34c2b712010-02-17 11:18:59 +0100139 response->sbal_first = fsf_req->qdio_req.sbal_first;
140 response->sbal_last = fsf_req->qdio_req.sbal_last;
141 response->sbal_response = fsf_req->qdio_req.sbal_response;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200142 response->pool = fsf_req->pool != NULL;
143 response->erp_action = (unsigned long)fsf_req->erp_action;
144
145 switch (fsf_req->fsf_command) {
146 case FSF_QTCB_FCP_CMND:
147 if (fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT)
148 break;
149 scsi_cmnd = (struct scsi_cmnd *)fsf_req->data;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200150 if (scsi_cmnd) {
151 response->u.fcp.cmnd = (unsigned long)scsi_cmnd;
Felix Beckef3eb712010-07-16 15:37:42 +0200152 response->u.fcp.data_dir =
153 qtcb->bottom.io.data_direction;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200154 }
155 break;
156
157 case FSF_QTCB_OPEN_PORT_WITH_DID:
158 case FSF_QTCB_CLOSE_PORT:
159 case FSF_QTCB_CLOSE_PHYSICAL_PORT:
160 port = (struct zfcp_port *)fsf_req->data;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200161 response->u.port.wwpn = port->wwpn;
162 response->u.port.d_id = port->d_id;
163 response->u.port.port_handle = qtcb->header.port_handle;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200164 break;
165
166 case FSF_QTCB_OPEN_LUN:
167 case FSF_QTCB_CLOSE_LUN:
168 unit = (struct zfcp_unit *)fsf_req->data;
169 port = unit->port;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200170 response->u.unit.wwpn = port->wwpn;
171 response->u.unit.fcp_lun = unit->fcp_lun;
172 response->u.unit.port_handle = qtcb->header.port_handle;
173 response->u.unit.lun_handle = qtcb->header.lun_handle;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200174 break;
175
176 case FSF_QTCB_SEND_ELS:
177 send_els = (struct zfcp_send_els *)fsf_req->data;
Christof Schmitt800c0ca2009-11-24 16:54:12 +0100178 response->u.els.d_id = ntoh24(qtcb->bottom.support.d_id);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200179 break;
180
181 case FSF_QTCB_ABORT_FCP_CMND:
182 case FSF_QTCB_SEND_GENERIC:
183 case FSF_QTCB_EXCHANGE_CONFIG_DATA:
184 case FSF_QTCB_EXCHANGE_PORT_DATA:
185 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
186 case FSF_QTCB_UPLOAD_CONTROL_FILE:
187 break;
188 }
189
Swen Schillig57717102009-08-18 15:43:21 +0200190 debug_event(dbf->hba, level, rec, sizeof(*rec));
Martin Peschkeb75db732008-03-27 14:21:58 +0100191
192 /* have fcp channel microcode fixed to use as little as possible */
193 if (fsf_req->fsf_command != FSF_QTCB_FCP_CMND) {
194 /* adjust length skipping trailing zeros */
195 char *buf = (char *)qtcb + qtcb->header.log_start;
196 int len = qtcb->header.log_length;
197 for (; len && !buf[len - 1]; len--);
Swen Schillig57717102009-08-18 15:43:21 +0200198 zfcp_dbf_hexdump(dbf->hba, rec, sizeof(*rec), level, buf,
Christof Schmittd46f3842009-08-18 15:43:07 +0200199 len);
Martin Peschkeb75db732008-03-27 14:21:58 +0100200 }
201
Swen Schillig57717102009-08-18 15:43:21 +0200202 spin_unlock_irqrestore(&dbf->hba_lock, flags);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200203}
204
Swen Schillig57717102009-08-18 15:43:21 +0200205void _zfcp_dbf_hba_fsf_unsol(const char *tag, int level, struct zfcp_dbf *dbf,
206 struct fsf_status_read_buffer *status_buffer)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200207{
Swen Schillig57717102009-08-18 15:43:21 +0200208 struct zfcp_dbf_hba_record *rec = &dbf->hba_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200209 unsigned long flags;
210
Swen Schillig57717102009-08-18 15:43:21 +0200211 spin_lock_irqsave(&dbf->hba_lock, flags);
Martin Peschke6bc473d2008-03-31 11:15:29 +0200212 memset(rec, 0, sizeof(*rec));
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200213 strncpy(rec->tag, "stat", ZFCP_DBF_TAG_SIZE);
214 strncpy(rec->tag2, tag, ZFCP_DBF_TAG_SIZE);
215
Swen Schillig57717102009-08-18 15:43:21 +0200216 rec->u.status.failed = atomic_read(&dbf->adapter->stat_miss);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200217 if (status_buffer != NULL) {
Martin Peschke6bc473d2008-03-31 11:15:29 +0200218 rec->u.status.status_type = status_buffer->status_type;
219 rec->u.status.status_subtype = status_buffer->status_subtype;
220 memcpy(&rec->u.status.queue_designator,
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200221 &status_buffer->queue_designator,
222 sizeof(struct fsf_queue_designator));
223
224 switch (status_buffer->status_type) {
225 case FSF_STATUS_READ_SENSE_DATA_AVAIL:
Martin Peschke6bc473d2008-03-31 11:15:29 +0200226 rec->u.status.payload_size =
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200227 ZFCP_DBF_UNSOL_PAYLOAD_SENSE_DATA_AVAIL;
228 break;
229
230 case FSF_STATUS_READ_BIT_ERROR_THRESHOLD:
Martin Peschke6bc473d2008-03-31 11:15:29 +0200231 rec->u.status.payload_size =
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200232 ZFCP_DBF_UNSOL_PAYLOAD_BIT_ERROR_THRESHOLD;
233 break;
234
235 case FSF_STATUS_READ_LINK_DOWN:
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200236 switch (status_buffer->status_subtype) {
237 case FSF_STATUS_READ_SUB_NO_PHYSICAL_LINK:
238 case FSF_STATUS_READ_SUB_FDISC_FAILED:
Martin Peschke6bc473d2008-03-31 11:15:29 +0200239 rec->u.status.payload_size =
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200240 sizeof(struct fsf_link_down_info);
241 }
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200242 break;
243
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200244 case FSF_STATUS_READ_FEATURE_UPDATE_ALERT:
Martin Peschke6bc473d2008-03-31 11:15:29 +0200245 rec->u.status.payload_size =
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200246 ZFCP_DBF_UNSOL_PAYLOAD_FEATURE_UPDATE_ALERT;
247 break;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200248 }
Martin Peschke6bc473d2008-03-31 11:15:29 +0200249 memcpy(&rec->u.status.payload,
250 &status_buffer->payload, rec->u.status.payload_size);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200251 }
252
Swen Schillig57717102009-08-18 15:43:21 +0200253 debug_event(dbf->hba, level, rec, sizeof(*rec));
254 spin_unlock_irqrestore(&dbf->hba_lock, flags);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200255}
256
Martin Peschkebfab1632008-03-31 11:15:31 +0200257/**
Swen Schillig57717102009-08-18 15:43:21 +0200258 * zfcp_dbf_hba_qdio - trace event for QDIO related failure
Swen Schillig564e1c82009-08-18 15:43:19 +0200259 * @qdio: qdio structure affected by this QDIO related event
Martin Peschkebfab1632008-03-31 11:15:31 +0200260 * @qdio_error: as passed by qdio module
Martin Peschkebfab1632008-03-31 11:15:31 +0200261 * @sbal_index: first buffer with error condition, as passed by qdio module
262 * @sbal_count: number of buffers affected, as passed by qdio module
263 */
Swen Schillig57717102009-08-18 15:43:21 +0200264void zfcp_dbf_hba_qdio(struct zfcp_dbf *dbf, unsigned int qdio_error,
265 int sbal_index, int sbal_count)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200266{
Swen Schillig57717102009-08-18 15:43:21 +0200267 struct zfcp_dbf_hba_record *r = &dbf->hba_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200268 unsigned long flags;
269
Swen Schillig57717102009-08-18 15:43:21 +0200270 spin_lock_irqsave(&dbf->hba_lock, flags);
Martin Peschke6bc473d2008-03-31 11:15:29 +0200271 memset(r, 0, sizeof(*r));
272 strncpy(r->tag, "qdio", ZFCP_DBF_TAG_SIZE);
Martin Peschke6bc473d2008-03-31 11:15:29 +0200273 r->u.qdio.qdio_error = qdio_error;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200274 r->u.qdio.sbal_index = sbal_index;
275 r->u.qdio.sbal_count = sbal_count;
Swen Schillig57717102009-08-18 15:43:21 +0200276 debug_event(dbf->hba, 0, r, sizeof(*r));
277 spin_unlock_irqrestore(&dbf->hba_lock, flags);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200278}
279
Swen Schillig57069382008-10-01 12:42:21 +0200280/**
Swen Schillig57717102009-08-18 15:43:21 +0200281 * zfcp_dbf_hba_berr - trace event for bit error threshold
282 * @dbf: dbf structure affected by this QDIO related event
Swen Schillig57069382008-10-01 12:42:21 +0200283 * @req: fsf request
284 */
Swen Schillig57717102009-08-18 15:43:21 +0200285void zfcp_dbf_hba_berr(struct zfcp_dbf *dbf, struct zfcp_fsf_req *req)
Swen Schillig57069382008-10-01 12:42:21 +0200286{
Swen Schillig57717102009-08-18 15:43:21 +0200287 struct zfcp_dbf_hba_record *r = &dbf->hba_buf;
Swen Schillig57069382008-10-01 12:42:21 +0200288 struct fsf_status_read_buffer *sr_buf = req->data;
289 struct fsf_bit_error_payload *err = &sr_buf->payload.bit_error;
290 unsigned long flags;
291
Swen Schillig57717102009-08-18 15:43:21 +0200292 spin_lock_irqsave(&dbf->hba_lock, flags);
Swen Schillig57069382008-10-01 12:42:21 +0200293 memset(r, 0, sizeof(*r));
294 strncpy(r->tag, "berr", ZFCP_DBF_TAG_SIZE);
295 memcpy(&r->u.berr, err, sizeof(struct fsf_bit_error_payload));
Swen Schillig57717102009-08-18 15:43:21 +0200296 debug_event(dbf->hba, 0, r, sizeof(*r));
297 spin_unlock_irqrestore(&dbf->hba_lock, flags);
Swen Schillig57069382008-10-01 12:42:21 +0200298}
Swen Schillig57717102009-08-18 15:43:21 +0200299static void zfcp_dbf_hba_view_response(char **p,
300 struct zfcp_dbf_hba_record_response *r)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200301{
Martin Peschke8fc5af12008-03-31 11:15:23 +0200302 struct timespec t;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200303
Martin Peschkea9c85772008-03-31 11:15:27 +0200304 zfcp_dbf_out(p, "fsf_command", "0x%08x", r->fsf_command);
305 zfcp_dbf_out(p, "fsf_reqid", "0x%0Lx", r->fsf_reqid);
306 zfcp_dbf_out(p, "fsf_seqno", "0x%08x", r->fsf_seqno);
Christof Schmittb592e892009-08-18 15:43:31 +0200307 stck_to_timespec(r->fsf_issued, &t);
Martin Peschkea9c85772008-03-31 11:15:27 +0200308 zfcp_dbf_out(p, "fsf_issued", "%011lu:%06lu", t.tv_sec, t.tv_nsec);
309 zfcp_dbf_out(p, "fsf_prot_status", "0x%08x", r->fsf_prot_status);
310 zfcp_dbf_out(p, "fsf_status", "0x%08x", r->fsf_status);
311 zfcp_dbf_outd(p, "fsf_prot_status_qual", r->fsf_prot_status_qual,
Martin Peschkedf29f4a2008-03-31 11:15:26 +0200312 FSF_PROT_STATUS_QUAL_SIZE, 0, FSF_PROT_STATUS_QUAL_SIZE);
Martin Peschkea9c85772008-03-31 11:15:27 +0200313 zfcp_dbf_outd(p, "fsf_status_qual", r->fsf_status_qual,
Martin Peschkedf29f4a2008-03-31 11:15:26 +0200314 FSF_STATUS_QUALIFIER_SIZE, 0, FSF_STATUS_QUALIFIER_SIZE);
Martin Peschkea9c85772008-03-31 11:15:27 +0200315 zfcp_dbf_out(p, "fsf_req_status", "0x%08x", r->fsf_req_status);
316 zfcp_dbf_out(p, "sbal_first", "0x%02x", r->sbal_first);
Martin Peschkee891bff2008-05-19 12:17:43 +0200317 zfcp_dbf_out(p, "sbal_last", "0x%02x", r->sbal_last);
Martin Peschkec3baa9a22008-05-19 12:17:44 +0200318 zfcp_dbf_out(p, "sbal_response", "0x%02x", r->sbal_response);
Martin Peschkea9c85772008-03-31 11:15:27 +0200319 zfcp_dbf_out(p, "pool", "0x%02x", r->pool);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200320
Martin Peschkeb634fff2008-03-31 11:15:24 +0200321 switch (r->fsf_command) {
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200322 case FSF_QTCB_FCP_CMND:
Martin Peschkeb634fff2008-03-31 11:15:24 +0200323 if (r->fsf_req_status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200324 break;
Felix Beckef3eb712010-07-16 15:37:42 +0200325 zfcp_dbf_out(p, "data_direction", "0x%04x", r->u.fcp.data_dir);
Martin Peschke6bc473d2008-03-31 11:15:29 +0200326 zfcp_dbf_out(p, "scsi_cmnd", "0x%0Lx", r->u.fcp.cmnd);
Christof Schmitt5a3fb302010-01-13 17:52:37 +0100327 *p += sprintf(*p, "\n");
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200328 break;
329
330 case FSF_QTCB_OPEN_PORT_WITH_DID:
331 case FSF_QTCB_CLOSE_PORT:
332 case FSF_QTCB_CLOSE_PHYSICAL_PORT:
Martin Peschke6bc473d2008-03-31 11:15:29 +0200333 zfcp_dbf_out(p, "wwpn", "0x%016Lx", r->u.port.wwpn);
334 zfcp_dbf_out(p, "d_id", "0x%06x", r->u.port.d_id);
335 zfcp_dbf_out(p, "port_handle", "0x%08x", r->u.port.port_handle);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200336 break;
337
338 case FSF_QTCB_OPEN_LUN:
339 case FSF_QTCB_CLOSE_LUN:
Martin Peschke6bc473d2008-03-31 11:15:29 +0200340 zfcp_dbf_out(p, "wwpn", "0x%016Lx", r->u.unit.wwpn);
341 zfcp_dbf_out(p, "fcp_lun", "0x%016Lx", r->u.unit.fcp_lun);
342 zfcp_dbf_out(p, "port_handle", "0x%08x", r->u.unit.port_handle);
343 zfcp_dbf_out(p, "lun_handle", "0x%08x", r->u.unit.lun_handle);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200344 break;
345
346 case FSF_QTCB_SEND_ELS:
Martin Peschke6bc473d2008-03-31 11:15:29 +0200347 zfcp_dbf_out(p, "d_id", "0x%06x", r->u.els.d_id);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200348 break;
349
350 case FSF_QTCB_ABORT_FCP_CMND:
351 case FSF_QTCB_SEND_GENERIC:
352 case FSF_QTCB_EXCHANGE_CONFIG_DATA:
353 case FSF_QTCB_EXCHANGE_PORT_DATA:
354 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
355 case FSF_QTCB_UPLOAD_CONTROL_FILE:
356 break;
357 }
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200358}
359
Swen Schillig57717102009-08-18 15:43:21 +0200360static void zfcp_dbf_hba_view_status(char **p,
361 struct zfcp_dbf_hba_record_status *r)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200362{
Martin Peschkea9c85772008-03-31 11:15:27 +0200363 zfcp_dbf_out(p, "failed", "0x%02x", r->failed);
364 zfcp_dbf_out(p, "status_type", "0x%08x", r->status_type);
365 zfcp_dbf_out(p, "status_subtype", "0x%08x", r->status_subtype);
366 zfcp_dbf_outd(p, "queue_designator", (char *)&r->queue_designator,
Martin Peschkedf29f4a2008-03-31 11:15:26 +0200367 sizeof(struct fsf_queue_designator), 0,
368 sizeof(struct fsf_queue_designator));
Martin Peschkea9c85772008-03-31 11:15:27 +0200369 zfcp_dbf_outd(p, "payload", (char *)&r->payload, r->payload_size, 0,
Martin Peschkedf29f4a2008-03-31 11:15:26 +0200370 r->payload_size);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200371}
372
Swen Schillig57717102009-08-18 15:43:21 +0200373static void zfcp_dbf_hba_view_qdio(char **p, struct zfcp_dbf_hba_record_qdio *r)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200374{
Martin Peschkea9c85772008-03-31 11:15:27 +0200375 zfcp_dbf_out(p, "qdio_error", "0x%08x", r->qdio_error);
Martin Peschkea9c85772008-03-31 11:15:27 +0200376 zfcp_dbf_out(p, "sbal_index", "0x%02x", r->sbal_index);
377 zfcp_dbf_out(p, "sbal_count", "0x%02x", r->sbal_count);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200378}
379
Swen Schillig57717102009-08-18 15:43:21 +0200380static void zfcp_dbf_hba_view_berr(char **p, struct fsf_bit_error_payload *r)
Swen Schillig57069382008-10-01 12:42:21 +0200381{
382 zfcp_dbf_out(p, "link_failures", "%d", r->link_failure_error_count);
383 zfcp_dbf_out(p, "loss_of_sync_err", "%d", r->loss_of_sync_error_count);
384 zfcp_dbf_out(p, "loss_of_sig_err", "%d", r->loss_of_signal_error_count);
385 zfcp_dbf_out(p, "prim_seq_err", "%d",
386 r->primitive_sequence_error_count);
387 zfcp_dbf_out(p, "inval_trans_word_err", "%d",
388 r->invalid_transmission_word_error_count);
389 zfcp_dbf_out(p, "CRC_errors", "%d", r->crc_error_count);
390 zfcp_dbf_out(p, "prim_seq_event_to", "%d",
391 r->primitive_sequence_event_timeout_count);
392 zfcp_dbf_out(p, "elast_buf_overrun_err", "%d",
393 r->elastic_buffer_overrun_error_count);
394 zfcp_dbf_out(p, "adv_rec_buf2buf_cred", "%d",
395 r->advertised_receive_b2b_credit);
396 zfcp_dbf_out(p, "curr_rec_buf2buf_cred", "%d",
397 r->current_receive_b2b_credit);
398 zfcp_dbf_out(p, "adv_trans_buf2buf_cred", "%d",
399 r->advertised_transmit_b2b_credit);
400 zfcp_dbf_out(p, "curr_trans_buf2buf_cred", "%d",
401 r->current_transmit_b2b_credit);
402}
403
Swen Schillig57717102009-08-18 15:43:21 +0200404static int zfcp_dbf_hba_view_format(debug_info_t *id, struct debug_view *view,
Martin Peschkea9c85772008-03-31 11:15:27 +0200405 char *out_buf, const char *in_buf)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200406{
Swen Schillig57717102009-08-18 15:43:21 +0200407 struct zfcp_dbf_hba_record *r = (struct zfcp_dbf_hba_record *)in_buf;
Martin Peschkea9c85772008-03-31 11:15:27 +0200408 char *p = out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200409
Martin Peschkea9c85772008-03-31 11:15:27 +0200410 if (strncmp(r->tag, "dump", ZFCP_DBF_TAG_SIZE) == 0)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200411 return 0;
412
Martin Peschkea9c85772008-03-31 11:15:27 +0200413 zfcp_dbf_tag(&p, "tag", r->tag);
414 if (isalpha(r->tag2[0]))
415 zfcp_dbf_tag(&p, "tag2", r->tag2);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200416
Martin Peschkea9c85772008-03-31 11:15:27 +0200417 if (strncmp(r->tag, "resp", ZFCP_DBF_TAG_SIZE) == 0)
Swen Schillig57717102009-08-18 15:43:21 +0200418 zfcp_dbf_hba_view_response(&p, &r->u.response);
Martin Peschkea9c85772008-03-31 11:15:27 +0200419 else if (strncmp(r->tag, "stat", ZFCP_DBF_TAG_SIZE) == 0)
Swen Schillig57717102009-08-18 15:43:21 +0200420 zfcp_dbf_hba_view_status(&p, &r->u.status);
Martin Peschkea9c85772008-03-31 11:15:27 +0200421 else if (strncmp(r->tag, "qdio", ZFCP_DBF_TAG_SIZE) == 0)
Swen Schillig57717102009-08-18 15:43:21 +0200422 zfcp_dbf_hba_view_qdio(&p, &r->u.qdio);
Swen Schillig57069382008-10-01 12:42:21 +0200423 else if (strncmp(r->tag, "berr", ZFCP_DBF_TAG_SIZE) == 0)
Swen Schillig57717102009-08-18 15:43:21 +0200424 zfcp_dbf_hba_view_berr(&p, &r->u.berr);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200425
Christof Schmittd94ce6c2008-11-04 16:35:12 +0100426 if (strncmp(r->tag, "resp", ZFCP_DBF_TAG_SIZE) != 0)
427 p += sprintf(p, "\n");
Martin Peschkea9c85772008-03-31 11:15:27 +0200428 return p - out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200429}
430
Swen Schillig57717102009-08-18 15:43:21 +0200431static struct debug_view zfcp_dbf_hba_view = {
432 .name = "structured",
433 .header_proc = zfcp_dbf_view_header,
434 .format_proc = zfcp_dbf_hba_view_format,
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200435};
436
Swen Schilligae0904f2010-12-02 15:16:12 +0100437static void zfcp_dbf_set_common(struct zfcp_dbf_rec *rec,
438 struct zfcp_adapter *adapter,
439 struct zfcp_port *port,
440 struct scsi_device *sdev)
Martin Peschked79a83d2008-03-27 14:22:00 +0100441{
Swen Schilligae0904f2010-12-02 15:16:12 +0100442 rec->adapter_status = atomic_read(&adapter->status);
443 if (port) {
444 rec->port_status = atomic_read(&port->status);
445 rec->wwpn = port->wwpn;
446 rec->d_id = port->d_id;
Martin Peschked79a83d2008-03-27 14:22:00 +0100447 }
Swen Schilligae0904f2010-12-02 15:16:12 +0100448 if (sdev) {
449 rec->lun_status = atomic_read(&sdev_to_zfcp(sdev)->status);
450 rec->lun = zfcp_scsi_dev_lun(sdev);
451 }
Martin Peschke348447e2008-03-27 14:22:01 +0100452}
453
Christof Schmittaa0fec62008-05-19 12:17:47 +0200454/**
Swen Schilligae0904f2010-12-02 15:16:12 +0100455 * zfcp_dbf_rec_trig - trace event related to triggered recovery
456 * @tag: identifier for event
457 * @adapter: adapter on which the erp_action should run
458 * @port: remote port involved in the erp_action
459 * @sdev: scsi device involved in the erp_action
460 * @want: wanted erp_action
461 * @need: required erp_action
462 *
463 * The adapter->erp_lock has to be held.
Christof Schmittaa0fec62008-05-19 12:17:47 +0200464 */
Swen Schilligae0904f2010-12-02 15:16:12 +0100465void zfcp_dbf_rec_trig(char *tag, struct zfcp_adapter *adapter,
466 struct zfcp_port *port, struct scsi_device *sdev,
467 u8 want, u8 need)
Martin Peschke9467a9b2008-03-27 14:22:03 +0100468{
Christof Schmittd46f3842009-08-18 15:43:07 +0200469 struct zfcp_dbf *dbf = adapter->dbf;
Swen Schilligae0904f2010-12-02 15:16:12 +0100470 struct zfcp_dbf_rec *rec = &dbf->rec_buf;
471 struct list_head *entry;
Martin Peschke9467a9b2008-03-27 14:22:03 +0100472 unsigned long flags;
473
Swen Schillig57717102009-08-18 15:43:21 +0200474 spin_lock_irqsave(&dbf->rec_lock, flags);
Swen Schilligae0904f2010-12-02 15:16:12 +0100475 memset(rec, 0, sizeof(*rec));
476
477 rec->id = ZFCP_DBF_REC_TRIG;
478 memcpy(rec->tag, tag, ZFCP_DBF_TAG_LEN);
479 zfcp_dbf_set_common(rec, adapter, port, sdev);
480
481 list_for_each(entry, &adapter->erp_ready_head)
482 rec->u.trig.ready++;
483
484 list_for_each(entry, &adapter->erp_running_head)
485 rec->u.trig.running++;
486
487 rec->u.trig.want = want;
488 rec->u.trig.need = need;
489
490 debug_event(dbf->rec, 1, rec, sizeof(*rec));
Swen Schillig57717102009-08-18 15:43:21 +0200491 spin_unlock_irqrestore(&dbf->rec_lock, flags);
Martin Peschke9467a9b2008-03-27 14:22:03 +0100492}
493
Swen Schilligae0904f2010-12-02 15:16:12 +0100494
Martin Peschke6f4f3652008-03-27 14:22:04 +0100495/**
Swen Schilligae0904f2010-12-02 15:16:12 +0100496 * zfcp_dbf_rec_run - trace event related to running recovery
497 * @tag: identifier for event
498 * @erp: erp_action running
Martin Peschke6f4f3652008-03-27 14:22:04 +0100499 */
Swen Schilligae0904f2010-12-02 15:16:12 +0100500void zfcp_dbf_rec_run(char *tag, struct zfcp_erp_action *erp)
Martin Peschke6f4f3652008-03-27 14:22:04 +0100501{
Swen Schilligae0904f2010-12-02 15:16:12 +0100502 struct zfcp_dbf *dbf = erp->adapter->dbf;
503 struct zfcp_dbf_rec *rec = &dbf->rec_buf;
Martin Peschke6f4f3652008-03-27 14:22:04 +0100504 unsigned long flags;
505
Swen Schillig57717102009-08-18 15:43:21 +0200506 spin_lock_irqsave(&dbf->rec_lock, flags);
Swen Schilligae0904f2010-12-02 15:16:12 +0100507 memset(rec, 0, sizeof(*rec));
508
509 rec->id = ZFCP_DBF_REC_RUN;
510 memcpy(rec->tag, tag, ZFCP_DBF_TAG_LEN);
511 zfcp_dbf_set_common(rec, erp->adapter, erp->port, erp->sdev);
512
513 rec->u.run.fsf_req_id = erp->fsf_req_id;
514 rec->u.run.rec_status = erp->status;
515 rec->u.run.rec_step = erp->step;
516 rec->u.run.rec_action = erp->action;
517
518 if (erp->sdev)
519 rec->u.run.rec_count =
520 atomic_read(&sdev_to_zfcp(erp->sdev)->erp_counter);
521 else if (erp->port)
522 rec->u.run.rec_count = atomic_read(&erp->port->erp_counter);
523 else
524 rec->u.run.rec_count = atomic_read(&erp->adapter->erp_counter);
525
526 debug_event(dbf->rec, 1, rec, sizeof(*rec));
Swen Schillig57717102009-08-18 15:43:21 +0200527 spin_unlock_irqrestore(&dbf->rec_lock, flags);
Martin Peschke6f4f3652008-03-27 14:22:04 +0100528}
529
Swen Schillig2c55b752010-12-02 15:16:13 +0100530static inline
531void zfcp_dbf_san(char *tag, struct zfcp_dbf *dbf, void *data, u8 id, u16 len,
532 u64 req_id, u32 d_id)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200533{
Swen Schillig2c55b752010-12-02 15:16:13 +0100534 struct zfcp_dbf_san *rec = &dbf->san_buf;
535 u16 rec_len;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200536 unsigned long flags;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200537
Swen Schillig57717102009-08-18 15:43:21 +0200538 spin_lock_irqsave(&dbf->san_lock, flags);
Martin Peschke6bc473d2008-03-31 11:15:29 +0200539 memset(rec, 0, sizeof(*rec));
Swen Schillig2c55b752010-12-02 15:16:13 +0100540
541 rec->id = id;
542 rec->fsf_req_id = req_id;
543 rec->d_id = d_id;
544 rec_len = min(len, (u16)ZFCP_DBF_SAN_MAX_PAYLOAD);
545 memcpy(rec->payload, data, rec_len);
546 memcpy(rec->tag, tag, ZFCP_DBF_TAG_LEN);
547
548 debug_event(dbf->san, 1, rec, sizeof(*rec));
Swen Schillig57717102009-08-18 15:43:21 +0200549 spin_unlock_irqrestore(&dbf->san_lock, flags);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200550}
551
Martin Peschkebfab1632008-03-31 11:15:31 +0200552/**
Swen Schillig2c55b752010-12-02 15:16:13 +0100553 * zfcp_dbf_san_req - trace event for issued SAN request
554 * @tag: indentifier for event
555 * @fsf_req: request containing issued CT data
556 * d_id: destination ID
Martin Peschkebfab1632008-03-31 11:15:31 +0200557 */
Swen Schillig2c55b752010-12-02 15:16:13 +0100558void zfcp_dbf_san_req(char *tag, struct zfcp_fsf_req *fsf, u32 d_id)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200559{
Swen Schillig2c55b752010-12-02 15:16:13 +0100560 struct zfcp_dbf *dbf = fsf->adapter->dbf;
561 struct zfcp_fsf_ct_els *ct_els = fsf->data;
562 u16 length;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200563
Swen Schillig2c55b752010-12-02 15:16:13 +0100564 length = (u16)(ct_els->req->length + FC_CT_HDR_LEN);
565 zfcp_dbf_san(tag, dbf, sg_virt(ct_els->req), ZFCP_DBF_SAN_REQ, length,
566 fsf->req_id, d_id);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200567}
568
Martin Peschkebfab1632008-03-31 11:15:31 +0200569/**
Swen Schillig2c55b752010-12-02 15:16:13 +0100570 * zfcp_dbf_san_res - trace event for received SAN request
571 * @tag: indentifier for event
572 * @fsf_req: request containing issued CT data
Martin Peschkebfab1632008-03-31 11:15:31 +0200573 */
Swen Schillig2c55b752010-12-02 15:16:13 +0100574void zfcp_dbf_san_res(char *tag, struct zfcp_fsf_req *fsf)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200575{
Swen Schillig2c55b752010-12-02 15:16:13 +0100576 struct zfcp_dbf *dbf = fsf->adapter->dbf;
577 struct zfcp_fsf_ct_els *ct_els = fsf->data;
578 u16 length;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200579
Swen Schillig2c55b752010-12-02 15:16:13 +0100580 length = (u16)(ct_els->resp->length + FC_CT_HDR_LEN);
581 zfcp_dbf_san(tag, dbf, sg_virt(ct_els->resp), ZFCP_DBF_SAN_RES, length,
582 fsf->req_id, 0);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200583}
584
Martin Peschkebfab1632008-03-31 11:15:31 +0200585/**
Swen Schillig2c55b752010-12-02 15:16:13 +0100586 * zfcp_dbf_san_in_els - trace event for incoming ELS
587 * @tag: indentifier for event
588 * @fsf_req: request containing issued CT data
Martin Peschkebfab1632008-03-31 11:15:31 +0200589 */
Swen Schillig2c55b752010-12-02 15:16:13 +0100590void zfcp_dbf_san_in_els(char *tag, struct zfcp_fsf_req *fsf)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200591{
Swen Schillig2c55b752010-12-02 15:16:13 +0100592 struct zfcp_dbf *dbf = fsf->adapter->dbf;
593 struct fsf_status_read_buffer *srb =
594 (struct fsf_status_read_buffer *) fsf->data;
595 u16 length;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200596
Swen Schillig2c55b752010-12-02 15:16:13 +0100597 length = (u16)(srb->length -
598 offsetof(struct fsf_status_read_buffer, payload));
599 zfcp_dbf_san(tag, dbf, srb->payload.data, ZFCP_DBF_SAN_ELS, length,
600 fsf->req_id, ntoh24(srb->d_id));
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200601}
602
Swen Schillig57717102009-08-18 15:43:21 +0200603void _zfcp_dbf_scsi(const char *tag, const char *tag2, int level,
604 struct zfcp_dbf *dbf, struct scsi_cmnd *scsi_cmnd,
605 struct zfcp_fsf_req *fsf_req, unsigned long old_req_id)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200606{
Swen Schillig57717102009-08-18 15:43:21 +0200607 struct zfcp_dbf_scsi_record *rec = &dbf->scsi_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200608 struct zfcp_dbf_dump *dump = (struct zfcp_dbf_dump *)rec;
609 unsigned long flags;
Christof Schmitt4318e082009-11-24 16:54:08 +0100610 struct fcp_resp_with_ext *fcp_rsp;
611 struct fcp_resp_rsp_info *fcp_rsp_info = NULL;
612 char *fcp_sns_info = NULL;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200613 int offset = 0, buflen = 0;
614
Swen Schillig57717102009-08-18 15:43:21 +0200615 spin_lock_irqsave(&dbf->scsi_lock, flags);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200616 do {
Martin Peschke6bc473d2008-03-31 11:15:29 +0200617 memset(rec, 0, sizeof(*rec));
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200618 if (offset == 0) {
619 strncpy(rec->tag, tag, ZFCP_DBF_TAG_SIZE);
620 strncpy(rec->tag2, tag2, ZFCP_DBF_TAG_SIZE);
Maxim Shchetynined829ad2006-02-11 01:42:58 +0100621 if (scsi_cmnd != NULL) {
622 if (scsi_cmnd->device) {
623 rec->scsi_id = scsi_cmnd->device->id;
624 rec->scsi_lun = scsi_cmnd->device->lun;
625 }
626 rec->scsi_result = scsi_cmnd->result;
627 rec->scsi_cmnd = (unsigned long)scsi_cmnd;
Boaz Harrosh64a87b22008-04-30 11:19:47 +0300628 memcpy(rec->scsi_opcode, scsi_cmnd->cmnd,
Maxim Shchetynined829ad2006-02-11 01:42:58 +0100629 min((int)scsi_cmnd->cmd_len,
630 ZFCP_DBF_SCSI_OPCODE));
631 rec->scsi_retries = scsi_cmnd->retries;
632 rec->scsi_allowed = scsi_cmnd->allowed;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200633 }
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200634 if (fsf_req != NULL) {
Christof Schmitt4318e082009-11-24 16:54:08 +0100635 fcp_rsp = (struct fcp_resp_with_ext *)
636 &(fsf_req->qtcb->bottom.io.fcp_rsp);
637 fcp_rsp_info = (struct fcp_resp_rsp_info *)
638 &fcp_rsp[1];
639 fcp_sns_info = (char *) &fcp_rsp[1];
640 if (fcp_rsp->resp.fr_flags & FCP_RSP_LEN_VAL)
641 fcp_sns_info += fcp_rsp->ext.fr_sns_len;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200642
Christof Schmitt4318e082009-11-24 16:54:08 +0100643 rec->rsp_validity = fcp_rsp->resp.fr_flags;
644 rec->rsp_scsi_status = fcp_rsp->resp.fr_status;
645 rec->rsp_resid = fcp_rsp->ext.fr_resid;
646 if (fcp_rsp->resp.fr_flags & FCP_RSP_LEN_VAL)
647 rec->rsp_code = fcp_rsp_info->rsp_code;
648 if (fcp_rsp->resp.fr_flags & FCP_SNS_LEN_VAL) {
649 buflen = min(fcp_rsp->ext.fr_sns_len,
650 (u32)ZFCP_DBF_SCSI_MAX_FCP_SNS_INFO);
Martin Peschke6bc473d2008-03-31 11:15:29 +0200651 rec->sns_info_len = buflen;
652 memcpy(rec->sns_info, fcp_sns_info,
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200653 min(buflen,
654 ZFCP_DBF_SCSI_FCP_SNS_INFO));
655 offset += min(buflen,
656 ZFCP_DBF_SCSI_FCP_SNS_INFO);
657 }
658
Christof Schmittf0216ae2009-05-15 13:18:14 +0200659 rec->fsf_reqid = fsf_req->req_id;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200660 rec->fsf_seqno = fsf_req->seq_no;
661 rec->fsf_issued = fsf_req->issued;
662 }
Martin Peschke6bc473d2008-03-31 11:15:29 +0200663 rec->old_fsf_reqid = old_req_id;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200664 } else {
665 strncpy(dump->tag, "dump", ZFCP_DBF_TAG_SIZE);
666 dump->total_size = buflen;
667 dump->offset = offset;
668 dump->size = min(buflen - offset,
669 (int)sizeof(struct
Swen Schillig57717102009-08-18 15:43:21 +0200670 zfcp_dbf_scsi_record) -
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200671 (int)sizeof(struct zfcp_dbf_dump));
672 memcpy(dump->data, fcp_sns_info + offset, dump->size);
673 offset += dump->size;
674 }
Swen Schillig57717102009-08-18 15:43:21 +0200675 debug_event(dbf->scsi, level, rec, sizeof(*rec));
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200676 } while (offset < buflen);
Swen Schillig57717102009-08-18 15:43:21 +0200677 spin_unlock_irqrestore(&dbf->scsi_lock, flags);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200678}
679
Swen Schillig57717102009-08-18 15:43:21 +0200680static int zfcp_dbf_scsi_view_format(debug_info_t *id, struct debug_view *view,
Martin Peschke92c7a832008-03-31 11:15:30 +0200681 char *out_buf, const char *in_buf)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200682{
Swen Schillig57717102009-08-18 15:43:21 +0200683 struct zfcp_dbf_scsi_record *r = (struct zfcp_dbf_scsi_record *)in_buf;
Martin Peschke8fc5af12008-03-31 11:15:23 +0200684 struct timespec t;
Martin Peschkeb634fff2008-03-31 11:15:24 +0200685 char *p = out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200686
Martin Peschkeb634fff2008-03-31 11:15:24 +0200687 if (strncmp(r->tag, "dump", ZFCP_DBF_TAG_SIZE) == 0)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200688 return 0;
689
Martin Peschkea9c85772008-03-31 11:15:27 +0200690 zfcp_dbf_tag(&p, "tag", r->tag);
691 zfcp_dbf_tag(&p, "tag2", r->tag2);
Martin Peschkeb634fff2008-03-31 11:15:24 +0200692 zfcp_dbf_out(&p, "scsi_id", "0x%08x", r->scsi_id);
693 zfcp_dbf_out(&p, "scsi_lun", "0x%08x", r->scsi_lun);
694 zfcp_dbf_out(&p, "scsi_result", "0x%08x", r->scsi_result);
695 zfcp_dbf_out(&p, "scsi_cmnd", "0x%0Lx", r->scsi_cmnd);
Martin Peschkedf29f4a2008-03-31 11:15:26 +0200696 zfcp_dbf_outd(&p, "scsi_opcode", r->scsi_opcode, ZFCP_DBF_SCSI_OPCODE,
697 0, ZFCP_DBF_SCSI_OPCODE);
Martin Peschkeb634fff2008-03-31 11:15:24 +0200698 zfcp_dbf_out(&p, "scsi_retries", "0x%02x", r->scsi_retries);
699 zfcp_dbf_out(&p, "scsi_allowed", "0x%02x", r->scsi_allowed);
700 if (strncmp(r->tag, "abrt", ZFCP_DBF_TAG_SIZE) == 0)
Martin Peschke6bc473d2008-03-31 11:15:29 +0200701 zfcp_dbf_out(&p, "old_fsf_reqid", "0x%0Lx", r->old_fsf_reqid);
Martin Peschkeb634fff2008-03-31 11:15:24 +0200702 zfcp_dbf_out(&p, "fsf_reqid", "0x%0Lx", r->fsf_reqid);
703 zfcp_dbf_out(&p, "fsf_seqno", "0x%08x", r->fsf_seqno);
Christof Schmittb592e892009-08-18 15:43:31 +0200704 stck_to_timespec(r->fsf_issued, &t);
Martin Peschkeb634fff2008-03-31 11:15:24 +0200705 zfcp_dbf_out(&p, "fsf_issued", "%011lu:%06lu", t.tv_sec, t.tv_nsec);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200706
Martin Peschkeb634fff2008-03-31 11:15:24 +0200707 if (strncmp(r->tag, "rslt", ZFCP_DBF_TAG_SIZE) == 0) {
Martin Peschke6bc473d2008-03-31 11:15:29 +0200708 zfcp_dbf_out(&p, "fcp_rsp_validity", "0x%02x", r->rsp_validity);
709 zfcp_dbf_out(&p, "fcp_rsp_scsi_status", "0x%02x",
710 r->rsp_scsi_status);
711 zfcp_dbf_out(&p, "fcp_rsp_resid", "0x%08x", r->rsp_resid);
712 zfcp_dbf_out(&p, "fcp_rsp_code", "0x%08x", r->rsp_code);
713 zfcp_dbf_out(&p, "fcp_sns_info_len", "0x%08x", r->sns_info_len);
714 zfcp_dbf_outd(&p, "fcp_sns_info", r->sns_info,
715 min((int)r->sns_info_len,
Martin Peschkedf29f4a2008-03-31 11:15:26 +0200716 ZFCP_DBF_SCSI_FCP_SNS_INFO), 0,
Martin Peschke6bc473d2008-03-31 11:15:29 +0200717 r->sns_info_len);
Martin Peschkeb634fff2008-03-31 11:15:24 +0200718 }
719 p += sprintf(p, "\n");
720 return p - out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200721}
722
Swen Schillig57717102009-08-18 15:43:21 +0200723static struct debug_view zfcp_dbf_scsi_view = {
724 .name = "structured",
725 .header_proc = zfcp_dbf_view_header,
726 .format_proc = zfcp_dbf_scsi_view_format,
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200727};
728
Christof Schmittd46f3842009-08-18 15:43:07 +0200729static debug_info_t *zfcp_dbf_reg(const char *name, int level,
730 struct debug_view *view, int size)
731{
732 struct debug_info *d;
733
734 d = debug_register(name, dbfsize, level, size);
735 if (!d)
736 return NULL;
737
738 debug_register_view(d, &debug_hex_ascii_view);
739 debug_register_view(d, view);
740 debug_set_level(d, level);
741
742 return d;
743}
744
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200745/**
746 * zfcp_adapter_debug_register - registers debug feature for an adapter
747 * @adapter: pointer to adapter for which debug features should be registered
748 * return: -ENOMEM on error, 0 otherwise
749 */
Swen Schillig57717102009-08-18 15:43:21 +0200750int zfcp_dbf_adapter_register(struct zfcp_adapter *adapter)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200751{
752 char dbf_name[DEBUG_MAX_NAME_LEN];
Christof Schmittd46f3842009-08-18 15:43:07 +0200753 struct zfcp_dbf *dbf;
754
Swen Schilligd23948e2010-07-16 15:37:40 +0200755 dbf = kzalloc(sizeof(struct zfcp_dbf), GFP_KERNEL);
Christof Schmittd46f3842009-08-18 15:43:07 +0200756 if (!dbf)
757 return -ENOMEM;
758
Swen Schillig57717102009-08-18 15:43:21 +0200759 dbf->adapter = adapter;
760
761 spin_lock_init(&dbf->hba_lock);
762 spin_lock_init(&dbf->san_lock);
763 spin_lock_init(&dbf->scsi_lock);
764 spin_lock_init(&dbf->rec_lock);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200765
766 /* debug feature area which records recovery activity */
Christof Schmittb225cf92008-12-19 16:57:00 +0100767 sprintf(dbf_name, "zfcp_%s_rec", dev_name(&adapter->ccw_device->dev));
Swen Schilligae0904f2010-12-02 15:16:12 +0100768 dbf->rec = zfcp_dbf_reg(dbf_name, 3, NULL, sizeof(struct zfcp_dbf_rec));
Swen Schillig57717102009-08-18 15:43:21 +0200769 if (!dbf->rec)
770 goto err_out;
Martin Peschked79a83d2008-03-27 14:22:00 +0100771
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200772 /* debug feature area which records HBA (FSF and QDIO) conditions */
Christof Schmittb225cf92008-12-19 16:57:00 +0100773 sprintf(dbf_name, "zfcp_%s_hba", dev_name(&adapter->ccw_device->dev));
Swen Schillig57717102009-08-18 15:43:21 +0200774 dbf->hba = zfcp_dbf_reg(dbf_name, 3, &zfcp_dbf_hba_view,
775 sizeof(struct zfcp_dbf_hba_record));
776 if (!dbf->hba)
777 goto err_out;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200778
779 /* debug feature area which records SAN command failures and recovery */
Christof Schmittb225cf92008-12-19 16:57:00 +0100780 sprintf(dbf_name, "zfcp_%s_san", dev_name(&adapter->ccw_device->dev));
Swen Schillig2c55b752010-12-02 15:16:13 +0100781 dbf->san = zfcp_dbf_reg(dbf_name, 3, NULL, sizeof(struct zfcp_dbf_san));
Swen Schillig57717102009-08-18 15:43:21 +0200782 if (!dbf->san)
783 goto err_out;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200784
785 /* debug feature area which records SCSI command failures and recovery */
Christof Schmittb225cf92008-12-19 16:57:00 +0100786 sprintf(dbf_name, "zfcp_%s_scsi", dev_name(&adapter->ccw_device->dev));
Swen Schillig57717102009-08-18 15:43:21 +0200787 dbf->scsi = zfcp_dbf_reg(dbf_name, 3, &zfcp_dbf_scsi_view,
788 sizeof(struct zfcp_dbf_scsi_record));
789 if (!dbf->scsi)
790 goto err_out;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200791
Christof Schmittd46f3842009-08-18 15:43:07 +0200792 adapter->dbf = dbf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200793 return 0;
794
Swen Schillig57717102009-08-18 15:43:21 +0200795err_out:
796 zfcp_dbf_adapter_unregister(dbf);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200797 return -ENOMEM;
798}
799
800/**
801 * zfcp_adapter_debug_unregister - unregisters debug feature for an adapter
Swen Schillig57717102009-08-18 15:43:21 +0200802 * @dbf: pointer to dbf for which debug features should be unregistered
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200803 */
Swen Schillig57717102009-08-18 15:43:21 +0200804void zfcp_dbf_adapter_unregister(struct zfcp_dbf *dbf)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200805{
Swen Schilligf3450c72009-11-24 16:53:59 +0100806 if (!dbf)
807 return;
Swen Schillig57717102009-08-18 15:43:21 +0200808 debug_unregister(dbf->scsi);
809 debug_unregister(dbf->san);
810 debug_unregister(dbf->hba);
811 debug_unregister(dbf->rec);
812 dbf->adapter->dbf = NULL;
813 kfree(dbf);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200814}
Swen Schillig57717102009-08-18 15:43:21 +0200815