blob: c066428b287803312b88ed8f2aa9d10a0deae97a [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"
16
17static u32 dbfsize = 4;
18
19module_param(dbfsize, uint, 0400);
20MODULE_PARM_DESC(dbfsize,
21 "number of pages for each debug feature area (default 4)");
22
Martin Peschkec15450e2008-03-27 14:21:55 +010023static void zfcp_dbf_hexdump(debug_info_t *dbf, void *to, int to_len,
24 int level, char *from, int from_len)
25{
26 int offset;
27 struct zfcp_dbf_dump *dump = to;
28 int room = to_len - sizeof(*dump);
29
30 for (offset = 0; offset < from_len; offset += dump->size) {
31 memset(to, 0, to_len);
32 strncpy(dump->tag, "dump", ZFCP_DBF_TAG_SIZE);
33 dump->total_size = from_len;
34 dump->offset = offset;
35 dump->size = min(from_len - offset, room);
36 memcpy(dump->data, from + offset, dump->size);
Christof Schmittd94ce6c2008-11-04 16:35:12 +010037 debug_event(dbf, level, dump, dump->size + sizeof(*dump));
Martin Peschkec15450e2008-03-27 14:21:55 +010038 }
39}
40
Martin Peschke8fc5af12008-03-31 11:15:23 +020041/* FIXME: this duplicate this code in s390 debug feature */
42static void zfcp_dbf_timestamp(unsigned long long stck, struct timespec *time)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020043{
44 unsigned long long sec;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020045
46 stck -= 0x8126d60e46000000LL - (0x3c26700LL * 1000000 * 4096);
47 sec = stck >> 12;
48 do_div(sec, 1000000);
Martin Peschke8fc5af12008-03-31 11:15:23 +020049 time->tv_sec = sec;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020050 stck -= (sec * 1000000) << 12;
Martin Peschke8fc5af12008-03-31 11:15:23 +020051 time->tv_nsec = ((stck * 1000) >> 12);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020052}
53
Martin Peschkea9c85772008-03-31 11:15:27 +020054static void zfcp_dbf_tag(char **p, const char *label, const char *tag)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020055{
Martin Peschkea9c85772008-03-31 11:15:27 +020056 int i;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020057
Martin Peschkea9c85772008-03-31 11:15:27 +020058 *p += sprintf(*p, "%-24s", label);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020059 for (i = 0; i < ZFCP_DBF_TAG_SIZE; i++)
Martin Peschkea9c85772008-03-31 11:15:27 +020060 *p += sprintf(*p, "%c", tag[i]);
61 *p += sprintf(*p, "\n");
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020062}
63
Martin Peschke10223c62008-03-27 14:21:59 +010064static void zfcp_dbf_outs(char **buf, const char *s1, const char *s2)
65{
66 *buf += sprintf(*buf, "%-24s%s\n", s1, s2);
67}
68
69static void zfcp_dbf_out(char **buf, const char *s, const char *format, ...)
70{
71 va_list arg;
72
73 *buf += sprintf(*buf, "%-24s", s);
74 va_start(arg, format);
75 *buf += vsprintf(*buf, format, arg);
76 va_end(arg);
77 *buf += sprintf(*buf, "\n");
78}
79
Martin Peschkedf29f4a2008-03-31 11:15:26 +020080static void zfcp_dbf_outd(char **p, const char *label, char *buffer,
81 int buflen, int offset, int total_size)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020082{
Martin Peschkedf29f4a2008-03-31 11:15:26 +020083 if (!offset)
84 *p += sprintf(*p, "%-24s ", label);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020085 while (buflen--) {
86 if (offset > 0) {
87 if ((offset % 32) == 0)
Martin Peschkedf29f4a2008-03-31 11:15:26 +020088 *p += sprintf(*p, "\n%-24c ", ' ');
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020089 else if ((offset % 4) == 0)
Martin Peschkedf29f4a2008-03-31 11:15:26 +020090 *p += sprintf(*p, " ");
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020091 }
Martin Peschkedf29f4a2008-03-31 11:15:26 +020092 *p += sprintf(*p, "%02x", *buffer++);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020093 if (++offset == total_size) {
Martin Peschkedf29f4a2008-03-31 11:15:26 +020094 *p += sprintf(*p, "\n");
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020095 break;
96 }
97 }
Martin Peschkedf29f4a2008-03-31 11:15:26 +020098 if (!total_size)
99 *p += sprintf(*p, "\n");
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200100}
101
Martin Peschke92c7a832008-03-31 11:15:30 +0200102static int zfcp_dbf_view_header(debug_info_t *id, struct debug_view *view,
103 int area, debug_entry_t *entry, char *out_buf)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200104{
105 struct zfcp_dbf_dump *dump = (struct zfcp_dbf_dump *)DEBUG_DATA(entry);
Martin Peschke8fc5af12008-03-31 11:15:23 +0200106 struct timespec t;
Martin Peschkeb634fff2008-03-31 11:15:24 +0200107 char *p = out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200108
109 if (strncmp(dump->tag, "dump", ZFCP_DBF_TAG_SIZE) != 0) {
Martin Peschke8fc5af12008-03-31 11:15:23 +0200110 zfcp_dbf_timestamp(entry->id.stck, &t);
Martin Peschkeb634fff2008-03-31 11:15:24 +0200111 zfcp_dbf_out(&p, "timestamp", "%011lu:%06lu",
112 t.tv_sec, t.tv_nsec);
113 zfcp_dbf_out(&p, "cpu", "%02i", entry->id.fields.cpuid);
114 } else {
Christof Schmittd94ce6c2008-11-04 16:35:12 +0100115 zfcp_dbf_outd(&p, "", dump->data, dump->size, dump->offset,
Martin Peschkedf29f4a2008-03-31 11:15:26 +0200116 dump->total_size);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200117 if ((dump->offset + dump->size) == dump->total_size)
Martin Peschkeb634fff2008-03-31 11:15:24 +0200118 p += sprintf(p, "\n");
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200119 }
Martin Peschkeb634fff2008-03-31 11:15:24 +0200120 return p - out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200121}
122
Swen Schillig57717102009-08-18 15:43:21 +0200123void _zfcp_dbf_hba_fsf_response(const char *tag2, int level,
124 struct zfcp_fsf_req *fsf_req,
125 struct zfcp_dbf *dbf)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200126{
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200127 struct fsf_qtcb *qtcb = fsf_req->qtcb;
128 union fsf_prot_status_qual *prot_status_qual =
Martin Peschke92c7a832008-03-31 11:15:30 +0200129 &qtcb->prefix.prot_status_qual;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200130 union fsf_status_qual *fsf_status_qual = &qtcb->header.fsf_status_qual;
131 struct scsi_cmnd *scsi_cmnd;
132 struct zfcp_port *port;
133 struct zfcp_unit *unit;
134 struct zfcp_send_els *send_els;
Swen Schillig57717102009-08-18 15:43:21 +0200135 struct zfcp_dbf_hba_record *rec = &dbf->hba_buf;
136 struct zfcp_dbf_hba_record_response *response = &rec->u.response;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200137 unsigned long flags;
138
Swen Schillig57717102009-08-18 15:43:21 +0200139 spin_lock_irqsave(&dbf->hba_lock, flags);
Martin Peschke6bc473d2008-03-31 11:15:29 +0200140 memset(rec, 0, sizeof(*rec));
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200141 strncpy(rec->tag, "resp", ZFCP_DBF_TAG_SIZE);
Christof Schmitt2e261af2009-08-18 15:43:09 +0200142 strncpy(rec->tag2, tag2, ZFCP_DBF_TAG_SIZE);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200143
144 response->fsf_command = fsf_req->fsf_command;
Christof Schmittf0216ae2009-05-15 13:18:14 +0200145 response->fsf_reqid = fsf_req->req_id;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200146 response->fsf_seqno = fsf_req->seq_no;
147 response->fsf_issued = fsf_req->issued;
148 response->fsf_prot_status = qtcb->prefix.prot_status;
149 response->fsf_status = qtcb->header.fsf_status;
150 memcpy(response->fsf_prot_status_qual,
151 prot_status_qual, FSF_PROT_STATUS_QUAL_SIZE);
152 memcpy(response->fsf_status_qual,
153 fsf_status_qual, FSF_STATUS_QUALIFIER_SIZE);
154 response->fsf_req_status = fsf_req->status;
Swen Schillig42428f72009-08-18 15:43:18 +0200155 response->sbal_first = fsf_req->queue_req.sbal_first;
156 response->sbal_last = fsf_req->queue_req.sbal_last;
157 response->sbal_response = fsf_req->queue_req.sbal_response;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200158 response->pool = fsf_req->pool != NULL;
159 response->erp_action = (unsigned long)fsf_req->erp_action;
160
161 switch (fsf_req->fsf_command) {
162 case FSF_QTCB_FCP_CMND:
163 if (fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT)
164 break;
165 scsi_cmnd = (struct scsi_cmnd *)fsf_req->data;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200166 if (scsi_cmnd) {
167 response->u.fcp.cmnd = (unsigned long)scsi_cmnd;
168 response->u.fcp.serial = scsi_cmnd->serial_number;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200169 }
170 break;
171
172 case FSF_QTCB_OPEN_PORT_WITH_DID:
173 case FSF_QTCB_CLOSE_PORT:
174 case FSF_QTCB_CLOSE_PHYSICAL_PORT:
175 port = (struct zfcp_port *)fsf_req->data;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200176 response->u.port.wwpn = port->wwpn;
177 response->u.port.d_id = port->d_id;
178 response->u.port.port_handle = qtcb->header.port_handle;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200179 break;
180
181 case FSF_QTCB_OPEN_LUN:
182 case FSF_QTCB_CLOSE_LUN:
183 unit = (struct zfcp_unit *)fsf_req->data;
184 port = unit->port;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200185 response->u.unit.wwpn = port->wwpn;
186 response->u.unit.fcp_lun = unit->fcp_lun;
187 response->u.unit.port_handle = qtcb->header.port_handle;
188 response->u.unit.lun_handle = qtcb->header.lun_handle;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200189 break;
190
191 case FSF_QTCB_SEND_ELS:
192 send_els = (struct zfcp_send_els *)fsf_req->data;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200193 response->u.els.d_id = qtcb->bottom.support.d_id;
194 response->u.els.ls_code = send_els->ls_code >> 24;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200195 break;
196
197 case FSF_QTCB_ABORT_FCP_CMND:
198 case FSF_QTCB_SEND_GENERIC:
199 case FSF_QTCB_EXCHANGE_CONFIG_DATA:
200 case FSF_QTCB_EXCHANGE_PORT_DATA:
201 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
202 case FSF_QTCB_UPLOAD_CONTROL_FILE:
203 break;
204 }
205
Swen Schillig57717102009-08-18 15:43:21 +0200206 debug_event(dbf->hba, level, rec, sizeof(*rec));
Martin Peschkeb75db732008-03-27 14:21:58 +0100207
208 /* have fcp channel microcode fixed to use as little as possible */
209 if (fsf_req->fsf_command != FSF_QTCB_FCP_CMND) {
210 /* adjust length skipping trailing zeros */
211 char *buf = (char *)qtcb + qtcb->header.log_start;
212 int len = qtcb->header.log_length;
213 for (; len && !buf[len - 1]; len--);
Swen Schillig57717102009-08-18 15:43:21 +0200214 zfcp_dbf_hexdump(dbf->hba, rec, sizeof(*rec), level, buf,
Christof Schmittd46f3842009-08-18 15:43:07 +0200215 len);
Martin Peschkeb75db732008-03-27 14:21:58 +0100216 }
217
Swen Schillig57717102009-08-18 15:43:21 +0200218 spin_unlock_irqrestore(&dbf->hba_lock, flags);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200219}
220
Swen Schillig57717102009-08-18 15:43:21 +0200221void _zfcp_dbf_hba_fsf_unsol(const char *tag, int level, struct zfcp_dbf *dbf,
222 struct fsf_status_read_buffer *status_buffer)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200223{
Swen Schillig57717102009-08-18 15:43:21 +0200224 struct zfcp_dbf_hba_record *rec = &dbf->hba_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200225 unsigned long flags;
226
Swen Schillig57717102009-08-18 15:43:21 +0200227 spin_lock_irqsave(&dbf->hba_lock, flags);
Martin Peschke6bc473d2008-03-31 11:15:29 +0200228 memset(rec, 0, sizeof(*rec));
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200229 strncpy(rec->tag, "stat", ZFCP_DBF_TAG_SIZE);
230 strncpy(rec->tag2, tag, ZFCP_DBF_TAG_SIZE);
231
Swen Schillig57717102009-08-18 15:43:21 +0200232 rec->u.status.failed = atomic_read(&dbf->adapter->stat_miss);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200233 if (status_buffer != NULL) {
Martin Peschke6bc473d2008-03-31 11:15:29 +0200234 rec->u.status.status_type = status_buffer->status_type;
235 rec->u.status.status_subtype = status_buffer->status_subtype;
236 memcpy(&rec->u.status.queue_designator,
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200237 &status_buffer->queue_designator,
238 sizeof(struct fsf_queue_designator));
239
240 switch (status_buffer->status_type) {
241 case FSF_STATUS_READ_SENSE_DATA_AVAIL:
Martin Peschke6bc473d2008-03-31 11:15:29 +0200242 rec->u.status.payload_size =
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200243 ZFCP_DBF_UNSOL_PAYLOAD_SENSE_DATA_AVAIL;
244 break;
245
246 case FSF_STATUS_READ_BIT_ERROR_THRESHOLD:
Martin Peschke6bc473d2008-03-31 11:15:29 +0200247 rec->u.status.payload_size =
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200248 ZFCP_DBF_UNSOL_PAYLOAD_BIT_ERROR_THRESHOLD;
249 break;
250
251 case FSF_STATUS_READ_LINK_DOWN:
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200252 switch (status_buffer->status_subtype) {
253 case FSF_STATUS_READ_SUB_NO_PHYSICAL_LINK:
254 case FSF_STATUS_READ_SUB_FDISC_FAILED:
Martin Peschke6bc473d2008-03-31 11:15:29 +0200255 rec->u.status.payload_size =
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200256 sizeof(struct fsf_link_down_info);
257 }
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200258 break;
259
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200260 case FSF_STATUS_READ_FEATURE_UPDATE_ALERT:
Martin Peschke6bc473d2008-03-31 11:15:29 +0200261 rec->u.status.payload_size =
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200262 ZFCP_DBF_UNSOL_PAYLOAD_FEATURE_UPDATE_ALERT;
263 break;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200264 }
Martin Peschke6bc473d2008-03-31 11:15:29 +0200265 memcpy(&rec->u.status.payload,
266 &status_buffer->payload, rec->u.status.payload_size);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200267 }
268
Swen Schillig57717102009-08-18 15:43:21 +0200269 debug_event(dbf->hba, level, rec, sizeof(*rec));
270 spin_unlock_irqrestore(&dbf->hba_lock, flags);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200271}
272
Martin Peschkebfab1632008-03-31 11:15:31 +0200273/**
Swen Schillig57717102009-08-18 15:43:21 +0200274 * zfcp_dbf_hba_qdio - trace event for QDIO related failure
Swen Schillig564e1c82009-08-18 15:43:19 +0200275 * @qdio: qdio structure affected by this QDIO related event
Martin Peschkebfab1632008-03-31 11:15:31 +0200276 * @qdio_error: as passed by qdio module
Martin Peschkebfab1632008-03-31 11:15:31 +0200277 * @sbal_index: first buffer with error condition, as passed by qdio module
278 * @sbal_count: number of buffers affected, as passed by qdio module
279 */
Swen Schillig57717102009-08-18 15:43:21 +0200280void zfcp_dbf_hba_qdio(struct zfcp_dbf *dbf, unsigned int qdio_error,
281 int sbal_index, int sbal_count)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200282{
Swen Schillig57717102009-08-18 15:43:21 +0200283 struct zfcp_dbf_hba_record *r = &dbf->hba_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200284 unsigned long flags;
285
Swen Schillig57717102009-08-18 15:43:21 +0200286 spin_lock_irqsave(&dbf->hba_lock, flags);
Martin Peschke6bc473d2008-03-31 11:15:29 +0200287 memset(r, 0, sizeof(*r));
288 strncpy(r->tag, "qdio", ZFCP_DBF_TAG_SIZE);
Martin Peschke6bc473d2008-03-31 11:15:29 +0200289 r->u.qdio.qdio_error = qdio_error;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200290 r->u.qdio.sbal_index = sbal_index;
291 r->u.qdio.sbal_count = sbal_count;
Swen Schillig57717102009-08-18 15:43:21 +0200292 debug_event(dbf->hba, 0, r, sizeof(*r));
293 spin_unlock_irqrestore(&dbf->hba_lock, flags);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200294}
295
Swen Schillig57069382008-10-01 12:42:21 +0200296/**
Swen Schillig57717102009-08-18 15:43:21 +0200297 * zfcp_dbf_hba_berr - trace event for bit error threshold
298 * @dbf: dbf structure affected by this QDIO related event
Swen Schillig57069382008-10-01 12:42:21 +0200299 * @req: fsf request
300 */
Swen Schillig57717102009-08-18 15:43:21 +0200301void zfcp_dbf_hba_berr(struct zfcp_dbf *dbf, struct zfcp_fsf_req *req)
Swen Schillig57069382008-10-01 12:42:21 +0200302{
Swen Schillig57717102009-08-18 15:43:21 +0200303 struct zfcp_dbf_hba_record *r = &dbf->hba_buf;
Swen Schillig57069382008-10-01 12:42:21 +0200304 struct fsf_status_read_buffer *sr_buf = req->data;
305 struct fsf_bit_error_payload *err = &sr_buf->payload.bit_error;
306 unsigned long flags;
307
Swen Schillig57717102009-08-18 15:43:21 +0200308 spin_lock_irqsave(&dbf->hba_lock, flags);
Swen Schillig57069382008-10-01 12:42:21 +0200309 memset(r, 0, sizeof(*r));
310 strncpy(r->tag, "berr", ZFCP_DBF_TAG_SIZE);
311 memcpy(&r->u.berr, err, sizeof(struct fsf_bit_error_payload));
Swen Schillig57717102009-08-18 15:43:21 +0200312 debug_event(dbf->hba, 0, r, sizeof(*r));
313 spin_unlock_irqrestore(&dbf->hba_lock, flags);
Swen Schillig57069382008-10-01 12:42:21 +0200314}
Swen Schillig57717102009-08-18 15:43:21 +0200315static void zfcp_dbf_hba_view_response(char **p,
316 struct zfcp_dbf_hba_record_response *r)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200317{
Martin Peschke8fc5af12008-03-31 11:15:23 +0200318 struct timespec t;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200319
Martin Peschkea9c85772008-03-31 11:15:27 +0200320 zfcp_dbf_out(p, "fsf_command", "0x%08x", r->fsf_command);
321 zfcp_dbf_out(p, "fsf_reqid", "0x%0Lx", r->fsf_reqid);
322 zfcp_dbf_out(p, "fsf_seqno", "0x%08x", r->fsf_seqno);
Martin Peschkeb634fff2008-03-31 11:15:24 +0200323 zfcp_dbf_timestamp(r->fsf_issued, &t);
Martin Peschkea9c85772008-03-31 11:15:27 +0200324 zfcp_dbf_out(p, "fsf_issued", "%011lu:%06lu", t.tv_sec, t.tv_nsec);
325 zfcp_dbf_out(p, "fsf_prot_status", "0x%08x", r->fsf_prot_status);
326 zfcp_dbf_out(p, "fsf_status", "0x%08x", r->fsf_status);
327 zfcp_dbf_outd(p, "fsf_prot_status_qual", r->fsf_prot_status_qual,
Martin Peschkedf29f4a2008-03-31 11:15:26 +0200328 FSF_PROT_STATUS_QUAL_SIZE, 0, FSF_PROT_STATUS_QUAL_SIZE);
Martin Peschkea9c85772008-03-31 11:15:27 +0200329 zfcp_dbf_outd(p, "fsf_status_qual", r->fsf_status_qual,
Martin Peschkedf29f4a2008-03-31 11:15:26 +0200330 FSF_STATUS_QUALIFIER_SIZE, 0, FSF_STATUS_QUALIFIER_SIZE);
Martin Peschkea9c85772008-03-31 11:15:27 +0200331 zfcp_dbf_out(p, "fsf_req_status", "0x%08x", r->fsf_req_status);
332 zfcp_dbf_out(p, "sbal_first", "0x%02x", r->sbal_first);
Martin Peschkee891bff2008-05-19 12:17:43 +0200333 zfcp_dbf_out(p, "sbal_last", "0x%02x", r->sbal_last);
Martin Peschkec3baa9a22008-05-19 12:17:44 +0200334 zfcp_dbf_out(p, "sbal_response", "0x%02x", r->sbal_response);
Martin Peschkea9c85772008-03-31 11:15:27 +0200335 zfcp_dbf_out(p, "pool", "0x%02x", r->pool);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200336
Martin Peschkeb634fff2008-03-31 11:15:24 +0200337 switch (r->fsf_command) {
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200338 case FSF_QTCB_FCP_CMND:
Martin Peschkeb634fff2008-03-31 11:15:24 +0200339 if (r->fsf_req_status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200340 break;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200341 zfcp_dbf_out(p, "scsi_cmnd", "0x%0Lx", r->u.fcp.cmnd);
342 zfcp_dbf_out(p, "scsi_serial", "0x%016Lx", r->u.fcp.serial);
Christof Schmittd94ce6c2008-11-04 16:35:12 +0100343 p += sprintf(*p, "\n");
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200344 break;
345
346 case FSF_QTCB_OPEN_PORT_WITH_DID:
347 case FSF_QTCB_CLOSE_PORT:
348 case FSF_QTCB_CLOSE_PHYSICAL_PORT:
Martin Peschke6bc473d2008-03-31 11:15:29 +0200349 zfcp_dbf_out(p, "wwpn", "0x%016Lx", r->u.port.wwpn);
350 zfcp_dbf_out(p, "d_id", "0x%06x", r->u.port.d_id);
351 zfcp_dbf_out(p, "port_handle", "0x%08x", r->u.port.port_handle);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200352 break;
353
354 case FSF_QTCB_OPEN_LUN:
355 case FSF_QTCB_CLOSE_LUN:
Martin Peschke6bc473d2008-03-31 11:15:29 +0200356 zfcp_dbf_out(p, "wwpn", "0x%016Lx", r->u.unit.wwpn);
357 zfcp_dbf_out(p, "fcp_lun", "0x%016Lx", r->u.unit.fcp_lun);
358 zfcp_dbf_out(p, "port_handle", "0x%08x", r->u.unit.port_handle);
359 zfcp_dbf_out(p, "lun_handle", "0x%08x", r->u.unit.lun_handle);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200360 break;
361
362 case FSF_QTCB_SEND_ELS:
Martin Peschke6bc473d2008-03-31 11:15:29 +0200363 zfcp_dbf_out(p, "d_id", "0x%06x", r->u.els.d_id);
364 zfcp_dbf_out(p, "ls_code", "0x%02x", r->u.els.ls_code);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200365 break;
366
367 case FSF_QTCB_ABORT_FCP_CMND:
368 case FSF_QTCB_SEND_GENERIC:
369 case FSF_QTCB_EXCHANGE_CONFIG_DATA:
370 case FSF_QTCB_EXCHANGE_PORT_DATA:
371 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
372 case FSF_QTCB_UPLOAD_CONTROL_FILE:
373 break;
374 }
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200375}
376
Swen Schillig57717102009-08-18 15:43:21 +0200377static void zfcp_dbf_hba_view_status(char **p,
378 struct zfcp_dbf_hba_record_status *r)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200379{
Martin Peschkea9c85772008-03-31 11:15:27 +0200380 zfcp_dbf_out(p, "failed", "0x%02x", r->failed);
381 zfcp_dbf_out(p, "status_type", "0x%08x", r->status_type);
382 zfcp_dbf_out(p, "status_subtype", "0x%08x", r->status_subtype);
383 zfcp_dbf_outd(p, "queue_designator", (char *)&r->queue_designator,
Martin Peschkedf29f4a2008-03-31 11:15:26 +0200384 sizeof(struct fsf_queue_designator), 0,
385 sizeof(struct fsf_queue_designator));
Martin Peschkea9c85772008-03-31 11:15:27 +0200386 zfcp_dbf_outd(p, "payload", (char *)&r->payload, r->payload_size, 0,
Martin Peschkedf29f4a2008-03-31 11:15:26 +0200387 r->payload_size);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200388}
389
Swen Schillig57717102009-08-18 15:43:21 +0200390static void zfcp_dbf_hba_view_qdio(char **p, struct zfcp_dbf_hba_record_qdio *r)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200391{
Martin Peschkea9c85772008-03-31 11:15:27 +0200392 zfcp_dbf_out(p, "qdio_error", "0x%08x", r->qdio_error);
Martin Peschkea9c85772008-03-31 11:15:27 +0200393 zfcp_dbf_out(p, "sbal_index", "0x%02x", r->sbal_index);
394 zfcp_dbf_out(p, "sbal_count", "0x%02x", r->sbal_count);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200395}
396
Swen Schillig57717102009-08-18 15:43:21 +0200397static void zfcp_dbf_hba_view_berr(char **p, struct fsf_bit_error_payload *r)
Swen Schillig57069382008-10-01 12:42:21 +0200398{
399 zfcp_dbf_out(p, "link_failures", "%d", r->link_failure_error_count);
400 zfcp_dbf_out(p, "loss_of_sync_err", "%d", r->loss_of_sync_error_count);
401 zfcp_dbf_out(p, "loss_of_sig_err", "%d", r->loss_of_signal_error_count);
402 zfcp_dbf_out(p, "prim_seq_err", "%d",
403 r->primitive_sequence_error_count);
404 zfcp_dbf_out(p, "inval_trans_word_err", "%d",
405 r->invalid_transmission_word_error_count);
406 zfcp_dbf_out(p, "CRC_errors", "%d", r->crc_error_count);
407 zfcp_dbf_out(p, "prim_seq_event_to", "%d",
408 r->primitive_sequence_event_timeout_count);
409 zfcp_dbf_out(p, "elast_buf_overrun_err", "%d",
410 r->elastic_buffer_overrun_error_count);
411 zfcp_dbf_out(p, "adv_rec_buf2buf_cred", "%d",
412 r->advertised_receive_b2b_credit);
413 zfcp_dbf_out(p, "curr_rec_buf2buf_cred", "%d",
414 r->current_receive_b2b_credit);
415 zfcp_dbf_out(p, "adv_trans_buf2buf_cred", "%d",
416 r->advertised_transmit_b2b_credit);
417 zfcp_dbf_out(p, "curr_trans_buf2buf_cred", "%d",
418 r->current_transmit_b2b_credit);
419}
420
Swen Schillig57717102009-08-18 15:43:21 +0200421static int zfcp_dbf_hba_view_format(debug_info_t *id, struct debug_view *view,
Martin Peschkea9c85772008-03-31 11:15:27 +0200422 char *out_buf, const char *in_buf)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200423{
Swen Schillig57717102009-08-18 15:43:21 +0200424 struct zfcp_dbf_hba_record *r = (struct zfcp_dbf_hba_record *)in_buf;
Martin Peschkea9c85772008-03-31 11:15:27 +0200425 char *p = out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200426
Martin Peschkea9c85772008-03-31 11:15:27 +0200427 if (strncmp(r->tag, "dump", ZFCP_DBF_TAG_SIZE) == 0)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200428 return 0;
429
Martin Peschkea9c85772008-03-31 11:15:27 +0200430 zfcp_dbf_tag(&p, "tag", r->tag);
431 if (isalpha(r->tag2[0]))
432 zfcp_dbf_tag(&p, "tag2", r->tag2);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200433
Martin Peschkea9c85772008-03-31 11:15:27 +0200434 if (strncmp(r->tag, "resp", ZFCP_DBF_TAG_SIZE) == 0)
Swen Schillig57717102009-08-18 15:43:21 +0200435 zfcp_dbf_hba_view_response(&p, &r->u.response);
Martin Peschkea9c85772008-03-31 11:15:27 +0200436 else if (strncmp(r->tag, "stat", ZFCP_DBF_TAG_SIZE) == 0)
Swen Schillig57717102009-08-18 15:43:21 +0200437 zfcp_dbf_hba_view_status(&p, &r->u.status);
Martin Peschkea9c85772008-03-31 11:15:27 +0200438 else if (strncmp(r->tag, "qdio", ZFCP_DBF_TAG_SIZE) == 0)
Swen Schillig57717102009-08-18 15:43:21 +0200439 zfcp_dbf_hba_view_qdio(&p, &r->u.qdio);
Swen Schillig57069382008-10-01 12:42:21 +0200440 else if (strncmp(r->tag, "berr", ZFCP_DBF_TAG_SIZE) == 0)
Swen Schillig57717102009-08-18 15:43:21 +0200441 zfcp_dbf_hba_view_berr(&p, &r->u.berr);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200442
Christof Schmittd94ce6c2008-11-04 16:35:12 +0100443 if (strncmp(r->tag, "resp", ZFCP_DBF_TAG_SIZE) != 0)
444 p += sprintf(p, "\n");
Martin Peschkea9c85772008-03-31 11:15:27 +0200445 return p - out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200446}
447
Swen Schillig57717102009-08-18 15:43:21 +0200448static struct debug_view zfcp_dbf_hba_view = {
449 .name = "structured",
450 .header_proc = zfcp_dbf_view_header,
451 .format_proc = zfcp_dbf_hba_view_format,
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200452};
453
Swen Schillig57717102009-08-18 15:43:21 +0200454static const char *zfcp_dbf_rec_tags[] = {
Martin Peschke348447e2008-03-27 14:22:01 +0100455 [ZFCP_REC_DBF_ID_THREAD] = "thread",
Martin Peschke698ec0162008-03-27 14:22:02 +0100456 [ZFCP_REC_DBF_ID_TARGET] = "target",
Martin Peschke9467a9b2008-03-27 14:22:03 +0100457 [ZFCP_REC_DBF_ID_TRIGGER] = "trigger",
Martin Peschke6f4f3652008-03-27 14:22:04 +0100458 [ZFCP_REC_DBF_ID_ACTION] = "action",
Martin Peschked79a83d2008-03-27 14:22:00 +0100459};
460
Swen Schillig57717102009-08-18 15:43:21 +0200461static int zfcp_dbf_rec_view_format(debug_info_t *id, struct debug_view *view,
Martin Peschked79a83d2008-03-27 14:22:00 +0100462 char *buf, const char *_rec)
463{
Swen Schillig57717102009-08-18 15:43:21 +0200464 struct zfcp_dbf_rec_record *r = (struct zfcp_dbf_rec_record *)_rec;
Martin Peschked79a83d2008-03-27 14:22:00 +0100465 char *p = buf;
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100466 char hint[ZFCP_DBF_ID_SIZE + 1];
Martin Peschked79a83d2008-03-27 14:22:00 +0100467
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100468 memcpy(hint, r->id2, ZFCP_DBF_ID_SIZE);
469 hint[ZFCP_DBF_ID_SIZE] = 0;
Swen Schillig57717102009-08-18 15:43:21 +0200470 zfcp_dbf_outs(&p, "tag", zfcp_dbf_rec_tags[r->id]);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100471 zfcp_dbf_outs(&p, "hint", hint);
Martin Peschked79a83d2008-03-27 14:22:00 +0100472 switch (r->id) {
Martin Peschke348447e2008-03-27 14:22:01 +0100473 case ZFCP_REC_DBF_ID_THREAD:
Martin Peschke348447e2008-03-27 14:22:01 +0100474 zfcp_dbf_out(&p, "total", "%d", r->u.thread.total);
475 zfcp_dbf_out(&p, "ready", "%d", r->u.thread.ready);
476 zfcp_dbf_out(&p, "running", "%d", r->u.thread.running);
477 break;
Martin Peschke698ec0162008-03-27 14:22:02 +0100478 case ZFCP_REC_DBF_ID_TARGET:
479 zfcp_dbf_out(&p, "reference", "0x%016Lx", r->u.target.ref);
480 zfcp_dbf_out(&p, "status", "0x%08x", r->u.target.status);
481 zfcp_dbf_out(&p, "erp_count", "%d", r->u.target.erp_count);
482 zfcp_dbf_out(&p, "d_id", "0x%06x", r->u.target.d_id);
483 zfcp_dbf_out(&p, "wwpn", "0x%016Lx", r->u.target.wwpn);
484 zfcp_dbf_out(&p, "fcp_lun", "0x%016Lx", r->u.target.fcp_lun);
485 break;
Martin Peschke9467a9b2008-03-27 14:22:03 +0100486 case ZFCP_REC_DBF_ID_TRIGGER:
487 zfcp_dbf_out(&p, "reference", "0x%016Lx", r->u.trigger.ref);
488 zfcp_dbf_out(&p, "erp_action", "0x%016Lx", r->u.trigger.action);
489 zfcp_dbf_out(&p, "requested", "%d", r->u.trigger.want);
490 zfcp_dbf_out(&p, "executed", "%d", r->u.trigger.need);
491 zfcp_dbf_out(&p, "wwpn", "0x%016Lx", r->u.trigger.wwpn);
492 zfcp_dbf_out(&p, "fcp_lun", "0x%016Lx", r->u.trigger.fcp_lun);
493 zfcp_dbf_out(&p, "adapter_status", "0x%08x", r->u.trigger.as);
494 zfcp_dbf_out(&p, "port_status", "0x%08x", r->u.trigger.ps);
495 zfcp_dbf_out(&p, "unit_status", "0x%08x", r->u.trigger.us);
496 break;
Martin Peschke6f4f3652008-03-27 14:22:04 +0100497 case ZFCP_REC_DBF_ID_ACTION:
498 zfcp_dbf_out(&p, "erp_action", "0x%016Lx", r->u.action.action);
499 zfcp_dbf_out(&p, "fsf_req", "0x%016Lx", r->u.action.fsf_req);
500 zfcp_dbf_out(&p, "status", "0x%08Lx", r->u.action.status);
501 zfcp_dbf_out(&p, "step", "0x%08Lx", r->u.action.step);
502 break;
Martin Peschked79a83d2008-03-27 14:22:00 +0100503 }
Martin Peschkeb634fff2008-03-31 11:15:24 +0200504 p += sprintf(p, "\n");
505 return p - buf;
Martin Peschked79a83d2008-03-27 14:22:00 +0100506}
507
Swen Schillig57717102009-08-18 15:43:21 +0200508static struct debug_view zfcp_dbf_rec_view = {
509 .name = "structured",
510 .header_proc = zfcp_dbf_view_header,
511 .format_proc = zfcp_dbf_rec_view_format,
Martin Peschked79a83d2008-03-27 14:22:00 +0100512};
513
Martin Peschke348447e2008-03-27 14:22:01 +0100514/**
Swen Schillig57717102009-08-18 15:43:21 +0200515 * zfcp_dbf_rec_thread - trace event related to recovery thread operation
Martin Peschke348447e2008-03-27 14:22:01 +0100516 * @id2: identifier for event
Swen Schillig57717102009-08-18 15:43:21 +0200517 * @dbf: reference to dbf structure
Christof Schmittaa0fec62008-05-19 12:17:47 +0200518 * This function assumes that the caller is holding erp_lock.
Martin Peschke348447e2008-03-27 14:22:01 +0100519 */
Swen Schillig57717102009-08-18 15:43:21 +0200520void zfcp_dbf_rec_thread(char *id2, struct zfcp_dbf *dbf)
Martin Peschke348447e2008-03-27 14:22:01 +0100521{
Swen Schillig57717102009-08-18 15:43:21 +0200522 struct zfcp_adapter *adapter = dbf->adapter;
523 struct zfcp_dbf_rec_record *r = &dbf->rec_buf;
Martin Peschke348447e2008-03-27 14:22:01 +0100524 unsigned long flags = 0;
525 struct list_head *entry;
526 unsigned ready = 0, running = 0, total;
527
Martin Peschke348447e2008-03-27 14:22:01 +0100528 list_for_each(entry, &adapter->erp_ready_head)
529 ready++;
530 list_for_each(entry, &adapter->erp_running_head)
531 running++;
532 total = adapter->erp_total_count;
Martin Peschke348447e2008-03-27 14:22:01 +0100533
Swen Schillig57717102009-08-18 15:43:21 +0200534 spin_lock_irqsave(&dbf->rec_lock, flags);
Martin Peschke348447e2008-03-27 14:22:01 +0100535 memset(r, 0, sizeof(*r));
536 r->id = ZFCP_REC_DBF_ID_THREAD;
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100537 memcpy(r->id2, id2, ZFCP_DBF_ID_SIZE);
Martin Peschke348447e2008-03-27 14:22:01 +0100538 r->u.thread.total = total;
539 r->u.thread.ready = ready;
540 r->u.thread.running = running;
Swen Schillig57717102009-08-18 15:43:21 +0200541 debug_event(dbf->rec, 6, r, sizeof(*r));
542 spin_unlock_irqrestore(&dbf->rec_lock, flags);
Martin Peschke348447e2008-03-27 14:22:01 +0100543}
544
Christof Schmittaa0fec62008-05-19 12:17:47 +0200545/**
Swen Schillig57717102009-08-18 15:43:21 +0200546 * zfcp_dbf_rec_thread - trace event related to recovery thread operation
Christof Schmittaa0fec62008-05-19 12:17:47 +0200547 * @id2: identifier for event
548 * @adapter: adapter
549 * This function assumes that the caller does not hold erp_lock.
550 */
Swen Schillig57717102009-08-18 15:43:21 +0200551void zfcp_dbf_rec_thread_lock(char *id2, struct zfcp_dbf *dbf)
Christof Schmittaa0fec62008-05-19 12:17:47 +0200552{
Swen Schillig57717102009-08-18 15:43:21 +0200553 struct zfcp_adapter *adapter = dbf->adapter;
Christof Schmittaa0fec62008-05-19 12:17:47 +0200554 unsigned long flags;
555
556 read_lock_irqsave(&adapter->erp_lock, flags);
Swen Schillig57717102009-08-18 15:43:21 +0200557 zfcp_dbf_rec_thread(id2, dbf);
Christof Schmittaa0fec62008-05-19 12:17:47 +0200558 read_unlock_irqrestore(&adapter->erp_lock, flags);
559}
560
Swen Schillig57717102009-08-18 15:43:21 +0200561static void zfcp_dbf_rec_target(char *id2, void *ref, struct zfcp_dbf *dbf,
562 atomic_t *status, atomic_t *erp_count, u64 wwpn,
563 u32 d_id, u64 fcp_lun)
Martin Peschke698ec0162008-03-27 14:22:02 +0100564{
Swen Schillig57717102009-08-18 15:43:21 +0200565 struct zfcp_dbf_rec_record *r = &dbf->rec_buf;
Martin Peschke698ec0162008-03-27 14:22:02 +0100566 unsigned long flags;
567
Swen Schillig57717102009-08-18 15:43:21 +0200568 spin_lock_irqsave(&dbf->rec_lock, flags);
Martin Peschke698ec0162008-03-27 14:22:02 +0100569 memset(r, 0, sizeof(*r));
570 r->id = ZFCP_REC_DBF_ID_TARGET;
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100571 memcpy(r->id2, id2, ZFCP_DBF_ID_SIZE);
Martin Peschke1f6f7122008-04-18 12:51:55 +0200572 r->u.target.ref = (unsigned long)ref;
Martin Peschke698ec0162008-03-27 14:22:02 +0100573 r->u.target.status = atomic_read(status);
574 r->u.target.wwpn = wwpn;
575 r->u.target.d_id = d_id;
576 r->u.target.fcp_lun = fcp_lun;
577 r->u.target.erp_count = atomic_read(erp_count);
Swen Schillig57717102009-08-18 15:43:21 +0200578 debug_event(dbf->rec, 3, r, sizeof(*r));
579 spin_unlock_irqrestore(&dbf->rec_lock, flags);
Martin Peschke698ec0162008-03-27 14:22:02 +0100580}
581
582/**
Swen Schillig57717102009-08-18 15:43:21 +0200583 * zfcp_dbf_rec_adapter - trace event for adapter state change
Martin Peschke698ec0162008-03-27 14:22:02 +0100584 * @id: identifier for trigger of state change
585 * @ref: additional reference (e.g. request)
Swen Schillig57717102009-08-18 15:43:21 +0200586 * @dbf: reference to dbf structure
Martin Peschke698ec0162008-03-27 14:22:02 +0100587 */
Swen Schillig57717102009-08-18 15:43:21 +0200588void zfcp_dbf_rec_adapter(char *id, void *ref, struct zfcp_dbf *dbf)
Martin Peschke698ec0162008-03-27 14:22:02 +0100589{
Swen Schillig57717102009-08-18 15:43:21 +0200590 struct zfcp_adapter *adapter = dbf->adapter;
591
592 zfcp_dbf_rec_target(id, ref, dbf, &adapter->status,
Martin Peschke698ec0162008-03-27 14:22:02 +0100593 &adapter->erp_counter, 0, 0, 0);
594}
595
596/**
Swen Schillig57717102009-08-18 15:43:21 +0200597 * zfcp_dbf_rec_port - trace event for port state change
Martin Peschke698ec0162008-03-27 14:22:02 +0100598 * @id: identifier for trigger of state change
599 * @ref: additional reference (e.g. request)
600 * @port: port
601 */
Swen Schillig57717102009-08-18 15:43:21 +0200602void zfcp_dbf_rec_port(char *id, void *ref, struct zfcp_port *port)
Martin Peschke698ec0162008-03-27 14:22:02 +0100603{
Swen Schillig57717102009-08-18 15:43:21 +0200604 struct zfcp_dbf *dbf = port->adapter->dbf;
Martin Peschke698ec0162008-03-27 14:22:02 +0100605
Swen Schillig57717102009-08-18 15:43:21 +0200606 zfcp_dbf_rec_target(id, ref, dbf, &port->status,
Martin Peschke698ec0162008-03-27 14:22:02 +0100607 &port->erp_counter, port->wwpn, port->d_id,
608 0);
609}
610
611/**
Swen Schillig57717102009-08-18 15:43:21 +0200612 * zfcp_dbf_rec_unit - trace event for unit state change
Martin Peschke698ec0162008-03-27 14:22:02 +0100613 * @id: identifier for trigger of state change
614 * @ref: additional reference (e.g. request)
615 * @unit: unit
616 */
Swen Schillig57717102009-08-18 15:43:21 +0200617void zfcp_dbf_rec_unit(char *id, void *ref, struct zfcp_unit *unit)
Martin Peschke698ec0162008-03-27 14:22:02 +0100618{
619 struct zfcp_port *port = unit->port;
Swen Schillig57717102009-08-18 15:43:21 +0200620 struct zfcp_dbf *dbf = port->adapter->dbf;
Martin Peschke698ec0162008-03-27 14:22:02 +0100621
Swen Schillig57717102009-08-18 15:43:21 +0200622 zfcp_dbf_rec_target(id, ref, dbf, &unit->status,
Martin Peschke698ec0162008-03-27 14:22:02 +0100623 &unit->erp_counter, port->wwpn, port->d_id,
624 unit->fcp_lun);
625}
626
Martin Peschke9467a9b2008-03-27 14:22:03 +0100627/**
Swen Schillig57717102009-08-18 15:43:21 +0200628 * zfcp_dbf_rec_trigger - trace event for triggered error recovery
Martin Peschke9467a9b2008-03-27 14:22:03 +0100629 * @id2: identifier for error recovery trigger
630 * @ref: additional reference (e.g. request)
631 * @want: originally requested error recovery action
632 * @need: error recovery action actually initiated
633 * @action: address of error recovery action struct
634 * @adapter: adapter
635 * @port: port
636 * @unit: unit
637 */
Swen Schillig57717102009-08-18 15:43:21 +0200638void zfcp_dbf_rec_trigger(char *id2, void *ref, u8 want, u8 need, void *action,
639 struct zfcp_adapter *adapter, struct zfcp_port *port,
640 struct zfcp_unit *unit)
Martin Peschke9467a9b2008-03-27 14:22:03 +0100641{
Christof Schmittd46f3842009-08-18 15:43:07 +0200642 struct zfcp_dbf *dbf = adapter->dbf;
Swen Schillig57717102009-08-18 15:43:21 +0200643 struct zfcp_dbf_rec_record *r = &dbf->rec_buf;
Martin Peschke9467a9b2008-03-27 14:22:03 +0100644 unsigned long flags;
645
Swen Schillig57717102009-08-18 15:43:21 +0200646 spin_lock_irqsave(&dbf->rec_lock, flags);
Martin Peschke9467a9b2008-03-27 14:22:03 +0100647 memset(r, 0, sizeof(*r));
648 r->id = ZFCP_REC_DBF_ID_TRIGGER;
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100649 memcpy(r->id2, id2, ZFCP_DBF_ID_SIZE);
Martin Peschke1f6f7122008-04-18 12:51:55 +0200650 r->u.trigger.ref = (unsigned long)ref;
Martin Peschke9467a9b2008-03-27 14:22:03 +0100651 r->u.trigger.want = want;
652 r->u.trigger.need = need;
Martin Peschke1f6f7122008-04-18 12:51:55 +0200653 r->u.trigger.action = (unsigned long)action;
Martin Peschke9467a9b2008-03-27 14:22:03 +0100654 r->u.trigger.as = atomic_read(&adapter->status);
655 if (port) {
656 r->u.trigger.ps = atomic_read(&port->status);
657 r->u.trigger.wwpn = port->wwpn;
658 }
659 if (unit) {
660 r->u.trigger.us = atomic_read(&unit->status);
661 r->u.trigger.fcp_lun = unit->fcp_lun;
662 }
Swen Schillig57717102009-08-18 15:43:21 +0200663 debug_event(dbf->rec, action ? 1 : 4, r, sizeof(*r));
664 spin_unlock_irqrestore(&dbf->rec_lock, flags);
Martin Peschke9467a9b2008-03-27 14:22:03 +0100665}
666
Martin Peschke6f4f3652008-03-27 14:22:04 +0100667/**
Swen Schillig57717102009-08-18 15:43:21 +0200668 * zfcp_dbf_rec_action - trace event showing progress of recovery action
Martin Peschke6f4f3652008-03-27 14:22:04 +0100669 * @id2: identifier
670 * @erp_action: error recovery action struct pointer
671 */
Swen Schillig57717102009-08-18 15:43:21 +0200672void zfcp_dbf_rec_action(char *id2, struct zfcp_erp_action *erp_action)
Martin Peschke6f4f3652008-03-27 14:22:04 +0100673{
Swen Schillig57717102009-08-18 15:43:21 +0200674 struct zfcp_dbf *dbf = erp_action->adapter->dbf;
675 struct zfcp_dbf_rec_record *r = &dbf->rec_buf;
Martin Peschke6f4f3652008-03-27 14:22:04 +0100676 unsigned long flags;
677
Swen Schillig57717102009-08-18 15:43:21 +0200678 spin_lock_irqsave(&dbf->rec_lock, flags);
Martin Peschke6f4f3652008-03-27 14:22:04 +0100679 memset(r, 0, sizeof(*r));
680 r->id = ZFCP_REC_DBF_ID_ACTION;
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100681 memcpy(r->id2, id2, ZFCP_DBF_ID_SIZE);
Martin Peschke1f6f7122008-04-18 12:51:55 +0200682 r->u.action.action = (unsigned long)erp_action;
Martin Peschke6f4f3652008-03-27 14:22:04 +0100683 r->u.action.status = erp_action->status;
684 r->u.action.step = erp_action->step;
Martin Peschke1f6f7122008-04-18 12:51:55 +0200685 r->u.action.fsf_req = (unsigned long)erp_action->fsf_req;
Swen Schillig57717102009-08-18 15:43:21 +0200686 debug_event(dbf->rec, 5, r, sizeof(*r));
687 spin_unlock_irqrestore(&dbf->rec_lock, flags);
Martin Peschke6f4f3652008-03-27 14:22:04 +0100688}
689
Martin Peschkebfab1632008-03-31 11:15:31 +0200690/**
Swen Schillig57717102009-08-18 15:43:21 +0200691 * zfcp_dbf_san_ct_request - trace event for issued CT request
Martin Peschkebfab1632008-03-31 11:15:31 +0200692 * @fsf_req: request containing issued CT data
693 */
Swen Schillig57717102009-08-18 15:43:21 +0200694void zfcp_dbf_san_ct_request(struct zfcp_fsf_req *fsf_req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200695{
696 struct zfcp_send_ct *ct = (struct zfcp_send_ct *)fsf_req->data;
Swen Schillig5ab944f2008-10-01 12:42:17 +0200697 struct zfcp_wka_port *wka_port = ct->wka_port;
698 struct zfcp_adapter *adapter = wka_port->adapter;
Christof Schmittd46f3842009-08-18 15:43:07 +0200699 struct zfcp_dbf *dbf = adapter->dbf;
Swen Schillig44cc76f2008-10-01 12:42:16 +0200700 struct ct_hdr *hdr = sg_virt(ct->req);
Swen Schillig57717102009-08-18 15:43:21 +0200701 struct zfcp_dbf_san_record *r = &dbf->san_buf;
702 struct zfcp_dbf_san_record_ct_request *oct = &r->u.ct_req;
Christof Schmittd94ce6c2008-11-04 16:35:12 +0100703 int level = 3;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200704 unsigned long flags;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200705
Swen Schillig57717102009-08-18 15:43:21 +0200706 spin_lock_irqsave(&dbf->san_lock, flags);
Martin Peschke6bc473d2008-03-31 11:15:29 +0200707 memset(r, 0, sizeof(*r));
708 strncpy(r->tag, "octc", ZFCP_DBF_TAG_SIZE);
Christof Schmittf0216ae2009-05-15 13:18:14 +0200709 r->fsf_reqid = fsf_req->req_id;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200710 r->fsf_seqno = fsf_req->seq_no;
711 r->s_id = fc_host_port_id(adapter->scsi_host);
Swen Schillig5ab944f2008-10-01 12:42:17 +0200712 r->d_id = wka_port->d_id;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200713 oct->cmd_req_code = hdr->cmd_rsp_code;
714 oct->revision = hdr->revision;
715 oct->gs_type = hdr->gs_type;
716 oct->gs_subtype = hdr->gs_subtype;
717 oct->options = hdr->options;
718 oct->max_res_size = hdr->max_res_size;
719 oct->len = min((int)ct->req->length - (int)sizeof(struct ct_hdr),
Christof Schmittd94ce6c2008-11-04 16:35:12 +0100720 ZFCP_DBF_SAN_MAX_PAYLOAD);
Swen Schillig57717102009-08-18 15:43:21 +0200721 debug_event(dbf->san, level, r, sizeof(*r));
722 zfcp_dbf_hexdump(dbf->san, r, sizeof(*r), level,
Christof Schmittd94ce6c2008-11-04 16:35:12 +0100723 (void *)hdr + sizeof(struct ct_hdr), oct->len);
Swen Schillig57717102009-08-18 15:43:21 +0200724 spin_unlock_irqrestore(&dbf->san_lock, flags);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200725}
726
Martin Peschkebfab1632008-03-31 11:15:31 +0200727/**
Swen Schillig57717102009-08-18 15:43:21 +0200728 * zfcp_dbf_san_ct_response - trace event for completion of CT request
Martin Peschkebfab1632008-03-31 11:15:31 +0200729 * @fsf_req: request containing CT response
730 */
Swen Schillig57717102009-08-18 15:43:21 +0200731void zfcp_dbf_san_ct_response(struct zfcp_fsf_req *fsf_req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200732{
733 struct zfcp_send_ct *ct = (struct zfcp_send_ct *)fsf_req->data;
Swen Schillig5ab944f2008-10-01 12:42:17 +0200734 struct zfcp_wka_port *wka_port = ct->wka_port;
735 struct zfcp_adapter *adapter = wka_port->adapter;
Swen Schillig44cc76f2008-10-01 12:42:16 +0200736 struct ct_hdr *hdr = sg_virt(ct->resp);
Christof Schmittd46f3842009-08-18 15:43:07 +0200737 struct zfcp_dbf *dbf = adapter->dbf;
Swen Schillig57717102009-08-18 15:43:21 +0200738 struct zfcp_dbf_san_record *r = &dbf->san_buf;
739 struct zfcp_dbf_san_record_ct_response *rct = &r->u.ct_resp;
Christof Schmittd94ce6c2008-11-04 16:35:12 +0100740 int level = 3;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200741 unsigned long flags;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200742
Swen Schillig57717102009-08-18 15:43:21 +0200743 spin_lock_irqsave(&dbf->san_lock, flags);
Martin Peschke6bc473d2008-03-31 11:15:29 +0200744 memset(r, 0, sizeof(*r));
745 strncpy(r->tag, "rctc", ZFCP_DBF_TAG_SIZE);
Christof Schmittf0216ae2009-05-15 13:18:14 +0200746 r->fsf_reqid = fsf_req->req_id;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200747 r->fsf_seqno = fsf_req->seq_no;
Swen Schillig5ab944f2008-10-01 12:42:17 +0200748 r->s_id = wka_port->d_id;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200749 r->d_id = fc_host_port_id(adapter->scsi_host);
750 rct->cmd_rsp_code = hdr->cmd_rsp_code;
751 rct->revision = hdr->revision;
752 rct->reason_code = hdr->reason_code;
753 rct->expl = hdr->reason_code_expl;
754 rct->vendor_unique = hdr->vendor_unique;
Christof Schmitt39eb7e9a2008-12-19 16:57:01 +0100755 rct->max_res_size = hdr->max_res_size;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200756 rct->len = min((int)ct->resp->length - (int)sizeof(struct ct_hdr),
Christof Schmittd94ce6c2008-11-04 16:35:12 +0100757 ZFCP_DBF_SAN_MAX_PAYLOAD);
Swen Schillig57717102009-08-18 15:43:21 +0200758 debug_event(dbf->san, level, r, sizeof(*r));
759 zfcp_dbf_hexdump(dbf->san, r, sizeof(*r), level,
Christof Schmittd94ce6c2008-11-04 16:35:12 +0100760 (void *)hdr + sizeof(struct ct_hdr), rct->len);
Swen Schillig57717102009-08-18 15:43:21 +0200761 spin_unlock_irqrestore(&dbf->san_lock, flags);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200762}
763
Swen Schillig57717102009-08-18 15:43:21 +0200764static void zfcp_dbf_san_els(const char *tag, int level,
765 struct zfcp_fsf_req *fsf_req, u32 s_id, u32 d_id,
766 u8 ls_code, void *buffer, int buflen)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200767{
768 struct zfcp_adapter *adapter = fsf_req->adapter;
Christof Schmittd46f3842009-08-18 15:43:07 +0200769 struct zfcp_dbf *dbf = adapter->dbf;
Swen Schillig57717102009-08-18 15:43:21 +0200770 struct zfcp_dbf_san_record *rec = &dbf->san_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200771 unsigned long flags;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200772
Swen Schillig57717102009-08-18 15:43:21 +0200773 spin_lock_irqsave(&dbf->san_lock, flags);
Martin Peschke6bc473d2008-03-31 11:15:29 +0200774 memset(rec, 0, sizeof(*rec));
Martin Peschke0f65e952008-03-27 14:21:56 +0100775 strncpy(rec->tag, tag, ZFCP_DBF_TAG_SIZE);
Christof Schmittf0216ae2009-05-15 13:18:14 +0200776 rec->fsf_reqid = fsf_req->req_id;
Martin Peschke0f65e952008-03-27 14:21:56 +0100777 rec->fsf_seqno = fsf_req->seq_no;
778 rec->s_id = s_id;
779 rec->d_id = d_id;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200780 rec->u.els.ls_code = ls_code;
Swen Schillig57717102009-08-18 15:43:21 +0200781 debug_event(dbf->san, level, rec, sizeof(*rec));
782 zfcp_dbf_hexdump(dbf->san, rec, sizeof(*rec), level,
Christof Schmittd94ce6c2008-11-04 16:35:12 +0100783 buffer, min(buflen, ZFCP_DBF_SAN_MAX_PAYLOAD));
Swen Schillig57717102009-08-18 15:43:21 +0200784 spin_unlock_irqrestore(&dbf->san_lock, flags);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200785}
786
Martin Peschkebfab1632008-03-31 11:15:31 +0200787/**
Swen Schillig57717102009-08-18 15:43:21 +0200788 * zfcp_dbf_san_els_request - trace event for issued ELS
Martin Peschkebfab1632008-03-31 11:15:31 +0200789 * @fsf_req: request containing issued ELS
790 */
Swen Schillig57717102009-08-18 15:43:21 +0200791void zfcp_dbf_san_els_request(struct zfcp_fsf_req *fsf_req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200792{
793 struct zfcp_send_els *els = (struct zfcp_send_els *)fsf_req->data;
794
Swen Schillig57717102009-08-18 15:43:21 +0200795 zfcp_dbf_san_els("oels", 2, fsf_req,
Martin Peschke92c7a832008-03-31 11:15:30 +0200796 fc_host_port_id(els->adapter->scsi_host),
Swen Schillig44cc76f2008-10-01 12:42:16 +0200797 els->d_id, *(u8 *) sg_virt(els->req),
798 sg_virt(els->req), els->req->length);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200799}
800
Martin Peschkebfab1632008-03-31 11:15:31 +0200801/**
Swen Schillig57717102009-08-18 15:43:21 +0200802 * zfcp_dbf_san_els_response - trace event for completed ELS
Martin Peschkebfab1632008-03-31 11:15:31 +0200803 * @fsf_req: request containing ELS response
804 */
Swen Schillig57717102009-08-18 15:43:21 +0200805void zfcp_dbf_san_els_response(struct zfcp_fsf_req *fsf_req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200806{
807 struct zfcp_send_els *els = (struct zfcp_send_els *)fsf_req->data;
808
Swen Schillig57717102009-08-18 15:43:21 +0200809 zfcp_dbf_san_els("rels", 2, fsf_req, els->d_id,
Martin Peschke92c7a832008-03-31 11:15:30 +0200810 fc_host_port_id(els->adapter->scsi_host),
Swen Schillig44cc76f2008-10-01 12:42:16 +0200811 *(u8 *)sg_virt(els->req), sg_virt(els->resp),
Martin Peschke92c7a832008-03-31 11:15:30 +0200812 els->resp->length);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200813}
814
Martin Peschkebfab1632008-03-31 11:15:31 +0200815/**
Swen Schillig57717102009-08-18 15:43:21 +0200816 * zfcp_dbf_san_incoming_els - trace event for incomig ELS
Martin Peschkebfab1632008-03-31 11:15:31 +0200817 * @fsf_req: request containing unsolicited status buffer with incoming ELS
818 */
Swen Schillig57717102009-08-18 15:43:21 +0200819void zfcp_dbf_san_incoming_els(struct zfcp_fsf_req *fsf_req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200820{
821 struct zfcp_adapter *adapter = fsf_req->adapter;
Martin Peschke92c7a832008-03-31 11:15:30 +0200822 struct fsf_status_read_buffer *buf =
823 (struct fsf_status_read_buffer *)fsf_req->data;
824 int length = (int)buf->length -
825 (int)((void *)&buf->payload - (void *)buf);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200826
Swen Schillig57717102009-08-18 15:43:21 +0200827 zfcp_dbf_san_els("iels", 1, fsf_req, buf->d_id,
Martin Peschke92c7a832008-03-31 11:15:30 +0200828 fc_host_port_id(adapter->scsi_host),
Swen Schilligc41f8cb2008-07-02 10:56:39 +0200829 buf->payload.data[0], (void *)buf->payload.data,
Martin Peschke92c7a832008-03-31 11:15:30 +0200830 length);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200831}
832
Swen Schillig57717102009-08-18 15:43:21 +0200833static int zfcp_dbf_san_view_format(debug_info_t *id, struct debug_view *view,
Martin Peschke92c7a832008-03-31 11:15:30 +0200834 char *out_buf, const char *in_buf)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200835{
Swen Schillig57717102009-08-18 15:43:21 +0200836 struct zfcp_dbf_san_record *r = (struct zfcp_dbf_san_record *)in_buf;
Martin Peschkeb634fff2008-03-31 11:15:24 +0200837 char *p = out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200838
Martin Peschkeb634fff2008-03-31 11:15:24 +0200839 if (strncmp(r->tag, "dump", ZFCP_DBF_TAG_SIZE) == 0)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200840 return 0;
841
Martin Peschkea9c85772008-03-31 11:15:27 +0200842 zfcp_dbf_tag(&p, "tag", r->tag);
Martin Peschkeb634fff2008-03-31 11:15:24 +0200843 zfcp_dbf_out(&p, "fsf_reqid", "0x%0Lx", r->fsf_reqid);
844 zfcp_dbf_out(&p, "fsf_seqno", "0x%08x", r->fsf_seqno);
845 zfcp_dbf_out(&p, "s_id", "0x%06x", r->s_id);
846 zfcp_dbf_out(&p, "d_id", "0x%06x", r->d_id);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200847
Martin Peschkeb634fff2008-03-31 11:15:24 +0200848 if (strncmp(r->tag, "octc", ZFCP_DBF_TAG_SIZE) == 0) {
Swen Schillig57717102009-08-18 15:43:21 +0200849 struct zfcp_dbf_san_record_ct_request *ct = &r->u.ct_req;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200850 zfcp_dbf_out(&p, "cmd_req_code", "0x%04x", ct->cmd_req_code);
851 zfcp_dbf_out(&p, "revision", "0x%02x", ct->revision);
852 zfcp_dbf_out(&p, "gs_type", "0x%02x", ct->gs_type);
853 zfcp_dbf_out(&p, "gs_subtype", "0x%02x", ct->gs_subtype);
854 zfcp_dbf_out(&p, "options", "0x%02x", ct->options);
855 zfcp_dbf_out(&p, "max_res_size", "0x%04x", ct->max_res_size);
Martin Peschkeb634fff2008-03-31 11:15:24 +0200856 } else if (strncmp(r->tag, "rctc", ZFCP_DBF_TAG_SIZE) == 0) {
Swen Schillig57717102009-08-18 15:43:21 +0200857 struct zfcp_dbf_san_record_ct_response *ct = &r->u.ct_resp;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200858 zfcp_dbf_out(&p, "cmd_rsp_code", "0x%04x", ct->cmd_rsp_code);
859 zfcp_dbf_out(&p, "revision", "0x%02x", ct->revision);
860 zfcp_dbf_out(&p, "reason_code", "0x%02x", ct->reason_code);
861 zfcp_dbf_out(&p, "reason_code_expl", "0x%02x", ct->expl);
862 zfcp_dbf_out(&p, "vendor_unique", "0x%02x", ct->vendor_unique);
Christof Schmitt39eb7e9a2008-12-19 16:57:01 +0100863 zfcp_dbf_out(&p, "max_res_size", "0x%04x", ct->max_res_size);
Martin Peschkeb634fff2008-03-31 11:15:24 +0200864 } else if (strncmp(r->tag, "oels", ZFCP_DBF_TAG_SIZE) == 0 ||
865 strncmp(r->tag, "rels", ZFCP_DBF_TAG_SIZE) == 0 ||
866 strncmp(r->tag, "iels", ZFCP_DBF_TAG_SIZE) == 0) {
Swen Schillig57717102009-08-18 15:43:21 +0200867 struct zfcp_dbf_san_record_els *els = &r->u.els;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200868 zfcp_dbf_out(&p, "ls_code", "0x%02x", els->ls_code);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200869 }
Martin Peschkeb634fff2008-03-31 11:15:24 +0200870 return p - out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200871}
872
Swen Schillig57717102009-08-18 15:43:21 +0200873static struct debug_view zfcp_dbf_san_view = {
874 .name = "structured",
875 .header_proc = zfcp_dbf_view_header,
876 .format_proc = zfcp_dbf_san_view_format,
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200877};
878
Swen Schillig57717102009-08-18 15:43:21 +0200879void _zfcp_dbf_scsi(const char *tag, const char *tag2, int level,
880 struct zfcp_dbf *dbf, struct scsi_cmnd *scsi_cmnd,
881 struct zfcp_fsf_req *fsf_req, unsigned long old_req_id)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200882{
Swen Schillig57717102009-08-18 15:43:21 +0200883 struct zfcp_dbf_scsi_record *rec = &dbf->scsi_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200884 struct zfcp_dbf_dump *dump = (struct zfcp_dbf_dump *)rec;
885 unsigned long flags;
886 struct fcp_rsp_iu *fcp_rsp;
887 char *fcp_rsp_info = NULL, *fcp_sns_info = NULL;
888 int offset = 0, buflen = 0;
889
Swen Schillig57717102009-08-18 15:43:21 +0200890 spin_lock_irqsave(&dbf->scsi_lock, flags);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200891 do {
Martin Peschke6bc473d2008-03-31 11:15:29 +0200892 memset(rec, 0, sizeof(*rec));
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200893 if (offset == 0) {
894 strncpy(rec->tag, tag, ZFCP_DBF_TAG_SIZE);
895 strncpy(rec->tag2, tag2, ZFCP_DBF_TAG_SIZE);
Maxim Shchetynined829ad2006-02-11 01:42:58 +0100896 if (scsi_cmnd != NULL) {
897 if (scsi_cmnd->device) {
898 rec->scsi_id = scsi_cmnd->device->id;
899 rec->scsi_lun = scsi_cmnd->device->lun;
900 }
901 rec->scsi_result = scsi_cmnd->result;
902 rec->scsi_cmnd = (unsigned long)scsi_cmnd;
903 rec->scsi_serial = scsi_cmnd->serial_number;
Boaz Harrosh64a87b22008-04-30 11:19:47 +0300904 memcpy(rec->scsi_opcode, scsi_cmnd->cmnd,
Maxim Shchetynined829ad2006-02-11 01:42:58 +0100905 min((int)scsi_cmnd->cmd_len,
906 ZFCP_DBF_SCSI_OPCODE));
907 rec->scsi_retries = scsi_cmnd->retries;
908 rec->scsi_allowed = scsi_cmnd->allowed;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200909 }
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200910 if (fsf_req != NULL) {
911 fcp_rsp = (struct fcp_rsp_iu *)
912 &(fsf_req->qtcb->bottom.io.fcp_rsp);
Martin Petermannf76af7d72008-07-02 10:56:36 +0200913 fcp_rsp_info = (unsigned char *) &fcp_rsp[1];
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200914 fcp_sns_info =
915 zfcp_get_fcp_sns_info_ptr(fcp_rsp);
916
Martin Peschke6bc473d2008-03-31 11:15:29 +0200917 rec->rsp_validity = fcp_rsp->validity.value;
918 rec->rsp_scsi_status = fcp_rsp->scsi_status;
919 rec->rsp_resid = fcp_rsp->fcp_resid;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200920 if (fcp_rsp->validity.bits.fcp_rsp_len_valid)
Martin Peschke6bc473d2008-03-31 11:15:29 +0200921 rec->rsp_code = *(fcp_rsp_info + 3);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200922 if (fcp_rsp->validity.bits.fcp_sns_len_valid) {
923 buflen = min((int)fcp_rsp->fcp_sns_len,
924 ZFCP_DBF_SCSI_MAX_FCP_SNS_INFO);
Martin Peschke6bc473d2008-03-31 11:15:29 +0200925 rec->sns_info_len = buflen;
926 memcpy(rec->sns_info, fcp_sns_info,
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200927 min(buflen,
928 ZFCP_DBF_SCSI_FCP_SNS_INFO));
929 offset += min(buflen,
930 ZFCP_DBF_SCSI_FCP_SNS_INFO);
931 }
932
Christof Schmittf0216ae2009-05-15 13:18:14 +0200933 rec->fsf_reqid = fsf_req->req_id;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200934 rec->fsf_seqno = fsf_req->seq_no;
935 rec->fsf_issued = fsf_req->issued;
936 }
Martin Peschke6bc473d2008-03-31 11:15:29 +0200937 rec->old_fsf_reqid = old_req_id;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200938 } else {
939 strncpy(dump->tag, "dump", ZFCP_DBF_TAG_SIZE);
940 dump->total_size = buflen;
941 dump->offset = offset;
942 dump->size = min(buflen - offset,
943 (int)sizeof(struct
Swen Schillig57717102009-08-18 15:43:21 +0200944 zfcp_dbf_scsi_record) -
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200945 (int)sizeof(struct zfcp_dbf_dump));
946 memcpy(dump->data, fcp_sns_info + offset, dump->size);
947 offset += dump->size;
948 }
Swen Schillig57717102009-08-18 15:43:21 +0200949 debug_event(dbf->scsi, level, rec, sizeof(*rec));
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200950 } while (offset < buflen);
Swen Schillig57717102009-08-18 15:43:21 +0200951 spin_unlock_irqrestore(&dbf->scsi_lock, flags);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200952}
953
Swen Schillig57717102009-08-18 15:43:21 +0200954static int zfcp_dbf_scsi_view_format(debug_info_t *id, struct debug_view *view,
Martin Peschke92c7a832008-03-31 11:15:30 +0200955 char *out_buf, const char *in_buf)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200956{
Swen Schillig57717102009-08-18 15:43:21 +0200957 struct zfcp_dbf_scsi_record *r = (struct zfcp_dbf_scsi_record *)in_buf;
Martin Peschke8fc5af12008-03-31 11:15:23 +0200958 struct timespec t;
Martin Peschkeb634fff2008-03-31 11:15:24 +0200959 char *p = out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200960
Martin Peschkeb634fff2008-03-31 11:15:24 +0200961 if (strncmp(r->tag, "dump", ZFCP_DBF_TAG_SIZE) == 0)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200962 return 0;
963
Martin Peschkea9c85772008-03-31 11:15:27 +0200964 zfcp_dbf_tag(&p, "tag", r->tag);
965 zfcp_dbf_tag(&p, "tag2", r->tag2);
Martin Peschkeb634fff2008-03-31 11:15:24 +0200966 zfcp_dbf_out(&p, "scsi_id", "0x%08x", r->scsi_id);
967 zfcp_dbf_out(&p, "scsi_lun", "0x%08x", r->scsi_lun);
968 zfcp_dbf_out(&p, "scsi_result", "0x%08x", r->scsi_result);
969 zfcp_dbf_out(&p, "scsi_cmnd", "0x%0Lx", r->scsi_cmnd);
970 zfcp_dbf_out(&p, "scsi_serial", "0x%016Lx", r->scsi_serial);
Martin Peschkedf29f4a2008-03-31 11:15:26 +0200971 zfcp_dbf_outd(&p, "scsi_opcode", r->scsi_opcode, ZFCP_DBF_SCSI_OPCODE,
972 0, ZFCP_DBF_SCSI_OPCODE);
Martin Peschkeb634fff2008-03-31 11:15:24 +0200973 zfcp_dbf_out(&p, "scsi_retries", "0x%02x", r->scsi_retries);
974 zfcp_dbf_out(&p, "scsi_allowed", "0x%02x", r->scsi_allowed);
975 if (strncmp(r->tag, "abrt", ZFCP_DBF_TAG_SIZE) == 0)
Martin Peschke6bc473d2008-03-31 11:15:29 +0200976 zfcp_dbf_out(&p, "old_fsf_reqid", "0x%0Lx", r->old_fsf_reqid);
Martin Peschkeb634fff2008-03-31 11:15:24 +0200977 zfcp_dbf_out(&p, "fsf_reqid", "0x%0Lx", r->fsf_reqid);
978 zfcp_dbf_out(&p, "fsf_seqno", "0x%08x", r->fsf_seqno);
979 zfcp_dbf_timestamp(r->fsf_issued, &t);
980 zfcp_dbf_out(&p, "fsf_issued", "%011lu:%06lu", t.tv_sec, t.tv_nsec);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200981
Martin Peschkeb634fff2008-03-31 11:15:24 +0200982 if (strncmp(r->tag, "rslt", ZFCP_DBF_TAG_SIZE) == 0) {
Martin Peschke6bc473d2008-03-31 11:15:29 +0200983 zfcp_dbf_out(&p, "fcp_rsp_validity", "0x%02x", r->rsp_validity);
984 zfcp_dbf_out(&p, "fcp_rsp_scsi_status", "0x%02x",
985 r->rsp_scsi_status);
986 zfcp_dbf_out(&p, "fcp_rsp_resid", "0x%08x", r->rsp_resid);
987 zfcp_dbf_out(&p, "fcp_rsp_code", "0x%08x", r->rsp_code);
988 zfcp_dbf_out(&p, "fcp_sns_info_len", "0x%08x", r->sns_info_len);
989 zfcp_dbf_outd(&p, "fcp_sns_info", r->sns_info,
990 min((int)r->sns_info_len,
Martin Peschkedf29f4a2008-03-31 11:15:26 +0200991 ZFCP_DBF_SCSI_FCP_SNS_INFO), 0,
Martin Peschke6bc473d2008-03-31 11:15:29 +0200992 r->sns_info_len);
Martin Peschkeb634fff2008-03-31 11:15:24 +0200993 }
994 p += sprintf(p, "\n");
995 return p - out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200996}
997
Swen Schillig57717102009-08-18 15:43:21 +0200998static struct debug_view zfcp_dbf_scsi_view = {
999 .name = "structured",
1000 .header_proc = zfcp_dbf_view_header,
1001 .format_proc = zfcp_dbf_scsi_view_format,
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001002};
1003
Christof Schmittd46f3842009-08-18 15:43:07 +02001004static debug_info_t *zfcp_dbf_reg(const char *name, int level,
1005 struct debug_view *view, int size)
1006{
1007 struct debug_info *d;
1008
1009 d = debug_register(name, dbfsize, level, size);
1010 if (!d)
1011 return NULL;
1012
1013 debug_register_view(d, &debug_hex_ascii_view);
1014 debug_register_view(d, view);
1015 debug_set_level(d, level);
1016
1017 return d;
1018}
1019
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001020/**
1021 * zfcp_adapter_debug_register - registers debug feature for an adapter
1022 * @adapter: pointer to adapter for which debug features should be registered
1023 * return: -ENOMEM on error, 0 otherwise
1024 */
Swen Schillig57717102009-08-18 15:43:21 +02001025int zfcp_dbf_adapter_register(struct zfcp_adapter *adapter)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001026{
1027 char dbf_name[DEBUG_MAX_NAME_LEN];
Christof Schmittd46f3842009-08-18 15:43:07 +02001028 struct zfcp_dbf *dbf;
1029
1030 dbf = kmalloc(sizeof(struct zfcp_dbf), GFP_KERNEL);
1031 if (!dbf)
1032 return -ENOMEM;
1033
Swen Schillig57717102009-08-18 15:43:21 +02001034 dbf->adapter = adapter;
1035
1036 spin_lock_init(&dbf->hba_lock);
1037 spin_lock_init(&dbf->san_lock);
1038 spin_lock_init(&dbf->scsi_lock);
1039 spin_lock_init(&dbf->rec_lock);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001040
1041 /* debug feature area which records recovery activity */
Christof Schmittb225cf92008-12-19 16:57:00 +01001042 sprintf(dbf_name, "zfcp_%s_rec", dev_name(&adapter->ccw_device->dev));
Swen Schillig57717102009-08-18 15:43:21 +02001043 dbf->rec = zfcp_dbf_reg(dbf_name, 3, &zfcp_dbf_rec_view,
1044 sizeof(struct zfcp_dbf_rec_record));
1045 if (!dbf->rec)
1046 goto err_out;
Martin Peschked79a83d2008-03-27 14:22:00 +01001047
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001048 /* debug feature area which records HBA (FSF and QDIO) conditions */
Christof Schmittb225cf92008-12-19 16:57:00 +01001049 sprintf(dbf_name, "zfcp_%s_hba", dev_name(&adapter->ccw_device->dev));
Swen Schillig57717102009-08-18 15:43:21 +02001050 dbf->hba = zfcp_dbf_reg(dbf_name, 3, &zfcp_dbf_hba_view,
1051 sizeof(struct zfcp_dbf_hba_record));
1052 if (!dbf->hba)
1053 goto err_out;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001054
1055 /* debug feature area which records SAN command failures and recovery */
Christof Schmittb225cf92008-12-19 16:57:00 +01001056 sprintf(dbf_name, "zfcp_%s_san", dev_name(&adapter->ccw_device->dev));
Swen Schillig57717102009-08-18 15:43:21 +02001057 dbf->san = zfcp_dbf_reg(dbf_name, 6, &zfcp_dbf_san_view,
1058 sizeof(struct zfcp_dbf_san_record));
1059 if (!dbf->san)
1060 goto err_out;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001061
1062 /* debug feature area which records SCSI command failures and recovery */
Christof Schmittb225cf92008-12-19 16:57:00 +01001063 sprintf(dbf_name, "zfcp_%s_scsi", dev_name(&adapter->ccw_device->dev));
Swen Schillig57717102009-08-18 15:43:21 +02001064 dbf->scsi = zfcp_dbf_reg(dbf_name, 3, &zfcp_dbf_scsi_view,
1065 sizeof(struct zfcp_dbf_scsi_record));
1066 if (!dbf->scsi)
1067 goto err_out;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001068
Christof Schmittd46f3842009-08-18 15:43:07 +02001069 adapter->dbf = dbf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001070 return 0;
1071
Swen Schillig57717102009-08-18 15:43:21 +02001072err_out:
1073 zfcp_dbf_adapter_unregister(dbf);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001074 return -ENOMEM;
1075}
1076
1077/**
1078 * zfcp_adapter_debug_unregister - unregisters debug feature for an adapter
Swen Schillig57717102009-08-18 15:43:21 +02001079 * @dbf: pointer to dbf for which debug features should be unregistered
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001080 */
Swen Schillig57717102009-08-18 15:43:21 +02001081void zfcp_dbf_adapter_unregister(struct zfcp_dbf *dbf)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001082{
Swen Schillig57717102009-08-18 15:43:21 +02001083 debug_unregister(dbf->scsi);
1084 debug_unregister(dbf->san);
1085 debug_unregister(dbf->hba);
1086 debug_unregister(dbf->rec);
1087 dbf->adapter->dbf = NULL;
1088 kfree(dbf);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001089}
Swen Schillig57717102009-08-18 15:43:21 +02001090