blob: 7c72f502eb0f5593373f0e3dd1fe750583dcf59a [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 Schmitt553448f2008-06-10 18:20:58 +02006 * Copyright IBM Corporation 2002, 2008
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02007 */
8
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02009#include <linux/ctype.h>
Heiko Carstens364c8552007-10-12 16:11:35 +020010#include <asm/debug.h>
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020011#include "zfcp_ext.h"
12
13static u32 dbfsize = 4;
14
15module_param(dbfsize, uint, 0400);
16MODULE_PARM_DESC(dbfsize,
17 "number of pages for each debug feature area (default 4)");
18
Martin Peschkec15450e2008-03-27 14:21:55 +010019static void zfcp_dbf_hexdump(debug_info_t *dbf, void *to, int to_len,
20 int level, char *from, int from_len)
21{
22 int offset;
23 struct zfcp_dbf_dump *dump = to;
24 int room = to_len - sizeof(*dump);
25
26 for (offset = 0; offset < from_len; offset += dump->size) {
27 memset(to, 0, to_len);
28 strncpy(dump->tag, "dump", ZFCP_DBF_TAG_SIZE);
29 dump->total_size = from_len;
30 dump->offset = offset;
31 dump->size = min(from_len - offset, room);
32 memcpy(dump->data, from + offset, dump->size);
33 debug_event(dbf, level, dump, dump->size);
34 }
35}
36
Martin Peschke8fc5af12008-03-31 11:15:23 +020037/* FIXME: this duplicate this code in s390 debug feature */
38static void zfcp_dbf_timestamp(unsigned long long stck, struct timespec *time)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020039{
40 unsigned long long sec;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020041
42 stck -= 0x8126d60e46000000LL - (0x3c26700LL * 1000000 * 4096);
43 sec = stck >> 12;
44 do_div(sec, 1000000);
Martin Peschke8fc5af12008-03-31 11:15:23 +020045 time->tv_sec = sec;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020046 stck -= (sec * 1000000) << 12;
Martin Peschke8fc5af12008-03-31 11:15:23 +020047 time->tv_nsec = ((stck * 1000) >> 12);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020048}
49
Martin Peschkea9c85772008-03-31 11:15:27 +020050static void zfcp_dbf_tag(char **p, const char *label, const char *tag)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020051{
Martin Peschkea9c85772008-03-31 11:15:27 +020052 int i;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020053
Martin Peschkea9c85772008-03-31 11:15:27 +020054 *p += sprintf(*p, "%-24s", label);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020055 for (i = 0; i < ZFCP_DBF_TAG_SIZE; i++)
Martin Peschkea9c85772008-03-31 11:15:27 +020056 *p += sprintf(*p, "%c", tag[i]);
57 *p += sprintf(*p, "\n");
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020058}
59
Martin Peschke10223c62008-03-27 14:21:59 +010060static void zfcp_dbf_outs(char **buf, const char *s1, const char *s2)
61{
62 *buf += sprintf(*buf, "%-24s%s\n", s1, s2);
63}
64
65static void zfcp_dbf_out(char **buf, const char *s, const char *format, ...)
66{
67 va_list arg;
68
69 *buf += sprintf(*buf, "%-24s", s);
70 va_start(arg, format);
71 *buf += vsprintf(*buf, format, arg);
72 va_end(arg);
73 *buf += sprintf(*buf, "\n");
74}
75
Martin Peschkedf29f4a2008-03-31 11:15:26 +020076static void zfcp_dbf_outd(char **p, const char *label, char *buffer,
77 int buflen, int offset, int total_size)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020078{
Martin Peschkedf29f4a2008-03-31 11:15:26 +020079 if (!offset)
80 *p += sprintf(*p, "%-24s ", label);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020081 while (buflen--) {
82 if (offset > 0) {
83 if ((offset % 32) == 0)
Martin Peschkedf29f4a2008-03-31 11:15:26 +020084 *p += sprintf(*p, "\n%-24c ", ' ');
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020085 else if ((offset % 4) == 0)
Martin Peschkedf29f4a2008-03-31 11:15:26 +020086 *p += sprintf(*p, " ");
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020087 }
Martin Peschkedf29f4a2008-03-31 11:15:26 +020088 *p += sprintf(*p, "%02x", *buffer++);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020089 if (++offset == total_size) {
Martin Peschkedf29f4a2008-03-31 11:15:26 +020090 *p += sprintf(*p, "\n");
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020091 break;
92 }
93 }
Martin Peschkedf29f4a2008-03-31 11:15:26 +020094 if (!total_size)
95 *p += sprintf(*p, "\n");
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020096}
97
Martin Peschke92c7a832008-03-31 11:15:30 +020098static int zfcp_dbf_view_header(debug_info_t *id, struct debug_view *view,
99 int area, debug_entry_t *entry, char *out_buf)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200100{
101 struct zfcp_dbf_dump *dump = (struct zfcp_dbf_dump *)DEBUG_DATA(entry);
Martin Peschke8fc5af12008-03-31 11:15:23 +0200102 struct timespec t;
Martin Peschkeb634fff2008-03-31 11:15:24 +0200103 char *p = out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200104
105 if (strncmp(dump->tag, "dump", ZFCP_DBF_TAG_SIZE) != 0) {
Martin Peschke8fc5af12008-03-31 11:15:23 +0200106 zfcp_dbf_timestamp(entry->id.stck, &t);
Martin Peschkeb634fff2008-03-31 11:15:24 +0200107 zfcp_dbf_out(&p, "timestamp", "%011lu:%06lu",
108 t.tv_sec, t.tv_nsec);
109 zfcp_dbf_out(&p, "cpu", "%02i", entry->id.fields.cpuid);
110 } else {
Martin Peschkedf29f4a2008-03-31 11:15:26 +0200111 zfcp_dbf_outd(&p, NULL, dump->data, dump->size, dump->offset,
112 dump->total_size);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200113 if ((dump->offset + dump->size) == dump->total_size)
Martin Peschkeb634fff2008-03-31 11:15:24 +0200114 p += sprintf(p, "\n");
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200115 }
Martin Peschkeb634fff2008-03-31 11:15:24 +0200116 return p - out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200117}
118
Martin Peschkebfab1632008-03-31 11:15:31 +0200119/**
120 * zfcp_hba_dbf_event_fsf_response - trace event for request completion
121 * @fsf_req: request that has been completed
122 */
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100123void zfcp_hba_dbf_event_fsf_response(struct zfcp_fsf_req *fsf_req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200124{
125 struct zfcp_adapter *adapter = fsf_req->adapter;
126 struct fsf_qtcb *qtcb = fsf_req->qtcb;
127 union fsf_prot_status_qual *prot_status_qual =
Martin Peschke92c7a832008-03-31 11:15:30 +0200128 &qtcb->prefix.prot_status_qual;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200129 union fsf_status_qual *fsf_status_qual = &qtcb->header.fsf_status_qual;
130 struct scsi_cmnd *scsi_cmnd;
131 struct zfcp_port *port;
132 struct zfcp_unit *unit;
133 struct zfcp_send_els *send_els;
134 struct zfcp_hba_dbf_record *rec = &adapter->hba_dbf_buf;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200135 struct zfcp_hba_dbf_record_response *response = &rec->u.response;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200136 int level;
137 unsigned long flags;
138
139 spin_lock_irqsave(&adapter->hba_dbf_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);
142
143 if ((qtcb->prefix.prot_status != FSF_PROT_GOOD) &&
144 (qtcb->prefix.prot_status != FSF_PROT_FSF_STATUS_PRESENTED)) {
145 strncpy(rec->tag2, "perr", ZFCP_DBF_TAG_SIZE);
146 level = 1;
147 } else if (qtcb->header.fsf_status != FSF_GOOD) {
148 strncpy(rec->tag2, "ferr", ZFCP_DBF_TAG_SIZE);
149 level = 1;
150 } else if ((fsf_req->fsf_command == FSF_QTCB_OPEN_PORT_WITH_DID) ||
151 (fsf_req->fsf_command == FSF_QTCB_OPEN_LUN)) {
152 strncpy(rec->tag2, "open", ZFCP_DBF_TAG_SIZE);
153 level = 4;
Martin Peschkeb75db732008-03-27 14:21:58 +0100154 } else if (qtcb->header.log_length) {
155 strncpy(rec->tag2, "qtcb", ZFCP_DBF_TAG_SIZE);
156 level = 5;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200157 } else {
158 strncpy(rec->tag2, "norm", ZFCP_DBF_TAG_SIZE);
159 level = 6;
160 }
161
162 response->fsf_command = fsf_req->fsf_command;
163 response->fsf_reqid = (unsigned long)fsf_req;
164 response->fsf_seqno = fsf_req->seq_no;
165 response->fsf_issued = fsf_req->issued;
166 response->fsf_prot_status = qtcb->prefix.prot_status;
167 response->fsf_status = qtcb->header.fsf_status;
168 memcpy(response->fsf_prot_status_qual,
169 prot_status_qual, FSF_PROT_STATUS_QUAL_SIZE);
170 memcpy(response->fsf_status_qual,
171 fsf_status_qual, FSF_STATUS_QUALIFIER_SIZE);
172 response->fsf_req_status = fsf_req->status;
173 response->sbal_first = fsf_req->sbal_first;
Martin Peschkee891bff2008-05-19 12:17:43 +0200174 response->sbal_last = fsf_req->sbal_last;
Martin Peschkec3baa9a22008-05-19 12:17:44 +0200175 response->sbal_response = fsf_req->sbal_response;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200176 response->pool = fsf_req->pool != NULL;
177 response->erp_action = (unsigned long)fsf_req->erp_action;
178
179 switch (fsf_req->fsf_command) {
180 case FSF_QTCB_FCP_CMND:
181 if (fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT)
182 break;
183 scsi_cmnd = (struct scsi_cmnd *)fsf_req->data;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200184 if (scsi_cmnd) {
185 response->u.fcp.cmnd = (unsigned long)scsi_cmnd;
186 response->u.fcp.serial = scsi_cmnd->serial_number;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200187 }
188 break;
189
190 case FSF_QTCB_OPEN_PORT_WITH_DID:
191 case FSF_QTCB_CLOSE_PORT:
192 case FSF_QTCB_CLOSE_PHYSICAL_PORT:
193 port = (struct zfcp_port *)fsf_req->data;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200194 response->u.port.wwpn = port->wwpn;
195 response->u.port.d_id = port->d_id;
196 response->u.port.port_handle = qtcb->header.port_handle;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200197 break;
198
199 case FSF_QTCB_OPEN_LUN:
200 case FSF_QTCB_CLOSE_LUN:
201 unit = (struct zfcp_unit *)fsf_req->data;
202 port = unit->port;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200203 response->u.unit.wwpn = port->wwpn;
204 response->u.unit.fcp_lun = unit->fcp_lun;
205 response->u.unit.port_handle = qtcb->header.port_handle;
206 response->u.unit.lun_handle = qtcb->header.lun_handle;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200207 break;
208
209 case FSF_QTCB_SEND_ELS:
210 send_els = (struct zfcp_send_els *)fsf_req->data;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200211 response->u.els.d_id = qtcb->bottom.support.d_id;
212 response->u.els.ls_code = send_els->ls_code >> 24;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200213 break;
214
215 case FSF_QTCB_ABORT_FCP_CMND:
216 case FSF_QTCB_SEND_GENERIC:
217 case FSF_QTCB_EXCHANGE_CONFIG_DATA:
218 case FSF_QTCB_EXCHANGE_PORT_DATA:
219 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
220 case FSF_QTCB_UPLOAD_CONTROL_FILE:
221 break;
222 }
223
Martin Peschke6bc473d2008-03-31 11:15:29 +0200224 debug_event(adapter->hba_dbf, level, rec, sizeof(*rec));
Martin Peschkeb75db732008-03-27 14:21:58 +0100225
226 /* have fcp channel microcode fixed to use as little as possible */
227 if (fsf_req->fsf_command != FSF_QTCB_FCP_CMND) {
228 /* adjust length skipping trailing zeros */
229 char *buf = (char *)qtcb + qtcb->header.log_start;
230 int len = qtcb->header.log_length;
231 for (; len && !buf[len - 1]; len--);
232 zfcp_dbf_hexdump(adapter->hba_dbf, rec, sizeof(*rec), level,
233 buf, len);
234 }
235
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200236 spin_unlock_irqrestore(&adapter->hba_dbf_lock, flags);
237}
238
Martin Peschkebfab1632008-03-31 11:15:31 +0200239/**
240 * zfcp_hba_dbf_event_fsf_unsol - trace event for an unsolicited status buffer
241 * @tag: tag indicating which kind of unsolicited status has been received
242 * @adapter: adapter that has issued the unsolicited status buffer
243 * @status_buffer: buffer containing payload of unsolicited status
244 */
Martin Peschke92c7a832008-03-31 11:15:30 +0200245void zfcp_hba_dbf_event_fsf_unsol(const char *tag, struct zfcp_adapter *adapter,
246 struct fsf_status_read_buffer *status_buffer)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200247{
248 struct zfcp_hba_dbf_record *rec = &adapter->hba_dbf_buf;
249 unsigned long flags;
250
251 spin_lock_irqsave(&adapter->hba_dbf_lock, flags);
Martin Peschke6bc473d2008-03-31 11:15:29 +0200252 memset(rec, 0, sizeof(*rec));
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200253 strncpy(rec->tag, "stat", ZFCP_DBF_TAG_SIZE);
254 strncpy(rec->tag2, tag, ZFCP_DBF_TAG_SIZE);
255
Swen Schilligd26ab062008-05-19 12:17:37 +0200256 rec->u.status.failed = atomic_read(&adapter->stat_miss);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200257 if (status_buffer != NULL) {
Martin Peschke6bc473d2008-03-31 11:15:29 +0200258 rec->u.status.status_type = status_buffer->status_type;
259 rec->u.status.status_subtype = status_buffer->status_subtype;
260 memcpy(&rec->u.status.queue_designator,
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200261 &status_buffer->queue_designator,
262 sizeof(struct fsf_queue_designator));
263
264 switch (status_buffer->status_type) {
265 case FSF_STATUS_READ_SENSE_DATA_AVAIL:
Martin Peschke6bc473d2008-03-31 11:15:29 +0200266 rec->u.status.payload_size =
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200267 ZFCP_DBF_UNSOL_PAYLOAD_SENSE_DATA_AVAIL;
268 break;
269
270 case FSF_STATUS_READ_BIT_ERROR_THRESHOLD:
Martin Peschke6bc473d2008-03-31 11:15:29 +0200271 rec->u.status.payload_size =
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200272 ZFCP_DBF_UNSOL_PAYLOAD_BIT_ERROR_THRESHOLD;
273 break;
274
275 case FSF_STATUS_READ_LINK_DOWN:
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200276 switch (status_buffer->status_subtype) {
277 case FSF_STATUS_READ_SUB_NO_PHYSICAL_LINK:
278 case FSF_STATUS_READ_SUB_FDISC_FAILED:
Martin Peschke6bc473d2008-03-31 11:15:29 +0200279 rec->u.status.payload_size =
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200280 sizeof(struct fsf_link_down_info);
281 }
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200282 break;
283
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200284 case FSF_STATUS_READ_FEATURE_UPDATE_ALERT:
Martin Peschke6bc473d2008-03-31 11:15:29 +0200285 rec->u.status.payload_size =
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200286 ZFCP_DBF_UNSOL_PAYLOAD_FEATURE_UPDATE_ALERT;
287 break;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200288 }
Martin Peschke6bc473d2008-03-31 11:15:29 +0200289 memcpy(&rec->u.status.payload,
290 &status_buffer->payload, rec->u.status.payload_size);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200291 }
292
Martin Peschke6bc473d2008-03-31 11:15:29 +0200293 debug_event(adapter->hba_dbf, 2, rec, sizeof(*rec));
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200294 spin_unlock_irqrestore(&adapter->hba_dbf_lock, flags);
295}
296
Martin Peschkebfab1632008-03-31 11:15:31 +0200297/**
298 * zfcp_hba_dbf_event_qdio - trace event for QDIO related failure
299 * @adapter: adapter affected by this QDIO related event
300 * @status: as passed by qdio module
301 * @qdio_error: as passed by qdio module
302 * @siga_error: as passed by qdio module
303 * @sbal_index: first buffer with error condition, as passed by qdio module
304 * @sbal_count: number of buffers affected, as passed by qdio module
305 */
Martin Peschke92c7a832008-03-31 11:15:30 +0200306void zfcp_hba_dbf_event_qdio(struct zfcp_adapter *adapter, unsigned int status,
307 unsigned int qdio_error, unsigned int siga_error,
308 int sbal_index, int sbal_count)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200309{
Martin Peschke6bc473d2008-03-31 11:15:29 +0200310 struct zfcp_hba_dbf_record *r = &adapter->hba_dbf_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200311 unsigned long flags;
312
313 spin_lock_irqsave(&adapter->hba_dbf_lock, flags);
Martin Peschke6bc473d2008-03-31 11:15:29 +0200314 memset(r, 0, sizeof(*r));
315 strncpy(r->tag, "qdio", ZFCP_DBF_TAG_SIZE);
316 r->u.qdio.status = status;
317 r->u.qdio.qdio_error = qdio_error;
318 r->u.qdio.siga_error = siga_error;
319 r->u.qdio.sbal_index = sbal_index;
320 r->u.qdio.sbal_count = sbal_count;
321 debug_event(adapter->hba_dbf, 0, r, sizeof(*r));
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200322 spin_unlock_irqrestore(&adapter->hba_dbf_lock, flags);
323}
324
Martin Peschkea9c85772008-03-31 11:15:27 +0200325static void zfcp_hba_dbf_view_response(char **p,
326 struct zfcp_hba_dbf_record_response *r)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200327{
Martin Peschke8fc5af12008-03-31 11:15:23 +0200328 struct timespec t;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200329
Martin Peschkea9c85772008-03-31 11:15:27 +0200330 zfcp_dbf_out(p, "fsf_command", "0x%08x", r->fsf_command);
331 zfcp_dbf_out(p, "fsf_reqid", "0x%0Lx", r->fsf_reqid);
332 zfcp_dbf_out(p, "fsf_seqno", "0x%08x", r->fsf_seqno);
Martin Peschkeb634fff2008-03-31 11:15:24 +0200333 zfcp_dbf_timestamp(r->fsf_issued, &t);
Martin Peschkea9c85772008-03-31 11:15:27 +0200334 zfcp_dbf_out(p, "fsf_issued", "%011lu:%06lu", t.tv_sec, t.tv_nsec);
335 zfcp_dbf_out(p, "fsf_prot_status", "0x%08x", r->fsf_prot_status);
336 zfcp_dbf_out(p, "fsf_status", "0x%08x", r->fsf_status);
337 zfcp_dbf_outd(p, "fsf_prot_status_qual", r->fsf_prot_status_qual,
Martin Peschkedf29f4a2008-03-31 11:15:26 +0200338 FSF_PROT_STATUS_QUAL_SIZE, 0, FSF_PROT_STATUS_QUAL_SIZE);
Martin Peschkea9c85772008-03-31 11:15:27 +0200339 zfcp_dbf_outd(p, "fsf_status_qual", r->fsf_status_qual,
Martin Peschkedf29f4a2008-03-31 11:15:26 +0200340 FSF_STATUS_QUALIFIER_SIZE, 0, FSF_STATUS_QUALIFIER_SIZE);
Martin Peschkea9c85772008-03-31 11:15:27 +0200341 zfcp_dbf_out(p, "fsf_req_status", "0x%08x", r->fsf_req_status);
342 zfcp_dbf_out(p, "sbal_first", "0x%02x", r->sbal_first);
Martin Peschkee891bff2008-05-19 12:17:43 +0200343 zfcp_dbf_out(p, "sbal_last", "0x%02x", r->sbal_last);
Martin Peschkec3baa9a22008-05-19 12:17:44 +0200344 zfcp_dbf_out(p, "sbal_response", "0x%02x", r->sbal_response);
Martin Peschkea9c85772008-03-31 11:15:27 +0200345 zfcp_dbf_out(p, "pool", "0x%02x", r->pool);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200346
Martin Peschkeb634fff2008-03-31 11:15:24 +0200347 switch (r->fsf_command) {
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200348 case FSF_QTCB_FCP_CMND:
Martin Peschkeb634fff2008-03-31 11:15:24 +0200349 if (r->fsf_req_status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200350 break;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200351 zfcp_dbf_out(p, "scsi_cmnd", "0x%0Lx", r->u.fcp.cmnd);
352 zfcp_dbf_out(p, "scsi_serial", "0x%016Lx", r->u.fcp.serial);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200353 break;
354
355 case FSF_QTCB_OPEN_PORT_WITH_DID:
356 case FSF_QTCB_CLOSE_PORT:
357 case FSF_QTCB_CLOSE_PHYSICAL_PORT:
Martin Peschke6bc473d2008-03-31 11:15:29 +0200358 zfcp_dbf_out(p, "wwpn", "0x%016Lx", r->u.port.wwpn);
359 zfcp_dbf_out(p, "d_id", "0x%06x", r->u.port.d_id);
360 zfcp_dbf_out(p, "port_handle", "0x%08x", r->u.port.port_handle);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200361 break;
362
363 case FSF_QTCB_OPEN_LUN:
364 case FSF_QTCB_CLOSE_LUN:
Martin Peschke6bc473d2008-03-31 11:15:29 +0200365 zfcp_dbf_out(p, "wwpn", "0x%016Lx", r->u.unit.wwpn);
366 zfcp_dbf_out(p, "fcp_lun", "0x%016Lx", r->u.unit.fcp_lun);
367 zfcp_dbf_out(p, "port_handle", "0x%08x", r->u.unit.port_handle);
368 zfcp_dbf_out(p, "lun_handle", "0x%08x", r->u.unit.lun_handle);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200369 break;
370
371 case FSF_QTCB_SEND_ELS:
Martin Peschke6bc473d2008-03-31 11:15:29 +0200372 zfcp_dbf_out(p, "d_id", "0x%06x", r->u.els.d_id);
373 zfcp_dbf_out(p, "ls_code", "0x%02x", r->u.els.ls_code);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200374 break;
375
376 case FSF_QTCB_ABORT_FCP_CMND:
377 case FSF_QTCB_SEND_GENERIC:
378 case FSF_QTCB_EXCHANGE_CONFIG_DATA:
379 case FSF_QTCB_EXCHANGE_PORT_DATA:
380 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
381 case FSF_QTCB_UPLOAD_CONTROL_FILE:
382 break;
383 }
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200384}
385
Martin Peschkea9c85772008-03-31 11:15:27 +0200386static void zfcp_hba_dbf_view_status(char **p,
387 struct zfcp_hba_dbf_record_status *r)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200388{
Martin Peschkea9c85772008-03-31 11:15:27 +0200389 zfcp_dbf_out(p, "failed", "0x%02x", r->failed);
390 zfcp_dbf_out(p, "status_type", "0x%08x", r->status_type);
391 zfcp_dbf_out(p, "status_subtype", "0x%08x", r->status_subtype);
392 zfcp_dbf_outd(p, "queue_designator", (char *)&r->queue_designator,
Martin Peschkedf29f4a2008-03-31 11:15:26 +0200393 sizeof(struct fsf_queue_designator), 0,
394 sizeof(struct fsf_queue_designator));
Martin Peschkea9c85772008-03-31 11:15:27 +0200395 zfcp_dbf_outd(p, "payload", (char *)&r->payload, r->payload_size, 0,
Martin Peschkedf29f4a2008-03-31 11:15:26 +0200396 r->payload_size);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200397}
398
Martin Peschkea9c85772008-03-31 11:15:27 +0200399static void zfcp_hba_dbf_view_qdio(char **p, struct zfcp_hba_dbf_record_qdio *r)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200400{
Martin Peschkea9c85772008-03-31 11:15:27 +0200401 zfcp_dbf_out(p, "status", "0x%08x", r->status);
402 zfcp_dbf_out(p, "qdio_error", "0x%08x", r->qdio_error);
403 zfcp_dbf_out(p, "siga_error", "0x%08x", r->siga_error);
404 zfcp_dbf_out(p, "sbal_index", "0x%02x", r->sbal_index);
405 zfcp_dbf_out(p, "sbal_count", "0x%02x", r->sbal_count);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200406}
407
Martin Peschkea9c85772008-03-31 11:15:27 +0200408static int zfcp_hba_dbf_view_format(debug_info_t *id, struct debug_view *view,
409 char *out_buf, const char *in_buf)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200410{
Martin Peschkea9c85772008-03-31 11:15:27 +0200411 struct zfcp_hba_dbf_record *r = (struct zfcp_hba_dbf_record *)in_buf;
412 char *p = out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200413
Martin Peschkea9c85772008-03-31 11:15:27 +0200414 if (strncmp(r->tag, "dump", ZFCP_DBF_TAG_SIZE) == 0)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200415 return 0;
416
Martin Peschkea9c85772008-03-31 11:15:27 +0200417 zfcp_dbf_tag(&p, "tag", r->tag);
418 if (isalpha(r->tag2[0]))
419 zfcp_dbf_tag(&p, "tag2", r->tag2);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200420
Martin Peschkea9c85772008-03-31 11:15:27 +0200421 if (strncmp(r->tag, "resp", ZFCP_DBF_TAG_SIZE) == 0)
Martin Peschke6bc473d2008-03-31 11:15:29 +0200422 zfcp_hba_dbf_view_response(&p, &r->u.response);
Martin Peschkea9c85772008-03-31 11:15:27 +0200423 else if (strncmp(r->tag, "stat", ZFCP_DBF_TAG_SIZE) == 0)
Martin Peschke6bc473d2008-03-31 11:15:29 +0200424 zfcp_hba_dbf_view_status(&p, &r->u.status);
Martin Peschkea9c85772008-03-31 11:15:27 +0200425 else if (strncmp(r->tag, "qdio", ZFCP_DBF_TAG_SIZE) == 0)
Martin Peschke6bc473d2008-03-31 11:15:29 +0200426 zfcp_hba_dbf_view_qdio(&p, &r->u.qdio);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200427
Martin Peschkea9c85772008-03-31 11:15:27 +0200428 p += sprintf(p, "\n");
429 return p - out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200430}
431
Heiko Carstens2b67fc42007-02-05 21:16:47 +0100432static struct debug_view zfcp_hba_dbf_view = {
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200433 "structured",
434 NULL,
435 &zfcp_dbf_view_header,
436 &zfcp_hba_dbf_view_format,
437 NULL,
438 NULL
439};
440
Martin Peschked79a83d2008-03-27 14:22:00 +0100441static const char *zfcp_rec_dbf_tags[] = {
Martin Peschke348447e2008-03-27 14:22:01 +0100442 [ZFCP_REC_DBF_ID_THREAD] = "thread",
Martin Peschke698ec0162008-03-27 14:22:02 +0100443 [ZFCP_REC_DBF_ID_TARGET] = "target",
Martin Peschke9467a9b2008-03-27 14:22:03 +0100444 [ZFCP_REC_DBF_ID_TRIGGER] = "trigger",
Martin Peschke6f4f3652008-03-27 14:22:04 +0100445 [ZFCP_REC_DBF_ID_ACTION] = "action",
Martin Peschked79a83d2008-03-27 14:22:00 +0100446};
447
448static const char *zfcp_rec_dbf_ids[] = {
Martin Peschke348447e2008-03-27 14:22:01 +0100449 [1] = "new",
450 [2] = "ready",
451 [3] = "kill",
452 [4] = "down sleep",
453 [5] = "down wakeup",
454 [6] = "down sleep ecd",
455 [7] = "down wakeup ecd",
456 [8] = "down sleep epd",
457 [9] = "down wakeup epd",
Martin Peschke698ec0162008-03-27 14:22:02 +0100458 [10] = "online",
459 [11] = "operational",
460 [12] = "scsi slave destroy",
461 [13] = "propagate failed adapter",
462 [14] = "propagate failed port",
463 [15] = "block adapter",
464 [16] = "unblock adapter",
465 [17] = "block port",
466 [18] = "unblock port",
467 [19] = "block unit",
468 [20] = "unblock unit",
469 [21] = "unit recovery failed",
470 [22] = "port recovery failed",
471 [23] = "adapter recovery failed",
472 [24] = "qdio queues down",
473 [25] = "p2p failed",
474 [26] = "nameserver lookup failed",
475 [27] = "nameserver port failed",
476 [28] = "link up",
477 [29] = "link down",
478 [30] = "link up status read",
479 [31] = "open port failed",
480 [32] = "open port failed",
481 [33] = "close port",
482 [34] = "open unit failed",
483 [35] = "exclusive open unit failed",
484 [36] = "shared open unit failed",
485 [37] = "link down",
486 [38] = "link down status read no link",
487 [39] = "link down status read fdisc login",
488 [40] = "link down status read firmware update",
489 [41] = "link down status read unknown reason",
490 [42] = "link down ecd incomplete",
491 [43] = "link down epd incomplete",
492 [44] = "sysfs adapter recovery",
493 [45] = "sysfs port recovery",
494 [46] = "sysfs unit recovery",
495 [47] = "port boxed abort",
496 [48] = "unit boxed abort",
497 [49] = "port boxed ct",
498 [50] = "port boxed close physical",
499 [51] = "port boxed open unit",
500 [52] = "port boxed close unit",
501 [53] = "port boxed fcp",
502 [54] = "unit boxed fcp",
Christof Schmitt553448f2008-06-10 18:20:58 +0200503 [55] = "port access denied",
504 [56] = "",
505 [57] = "",
506 [58] = "",
507 [59] = "unit access denied",
Martin Peschke698ec0162008-03-27 14:22:02 +0100508 [60] = "shared unit access denied open unit",
Christof Schmitt553448f2008-06-10 18:20:58 +0200509 [61] = "",
Martin Peschke9467a9b2008-03-27 14:22:03 +0100510 [62] = "request timeout",
511 [63] = "adisc link test reject or timeout",
512 [64] = "adisc link test d_id changed",
513 [65] = "adisc link test failed",
514 [66] = "recovery out of memory",
515 [67] = "adapter recovery repeated after state change",
516 [68] = "port recovery repeated after state change",
517 [69] = "unit recovery repeated after state change",
518 [70] = "port recovery follow-up after successful adapter recovery",
519 [71] = "adapter recovery escalation after failed adapter recovery",
520 [72] = "port recovery follow-up after successful physical port "
521 "recovery",
522 [73] = "adapter recovery escalation after failed physical port "
523 "recovery",
524 [74] = "unit recovery follow-up after successful port recovery",
525 [75] = "physical port recovery escalation after failed port "
526 "recovery",
527 [76] = "port recovery escalation after failed unit recovery",
528 [77] = "recovery opening nameserver port",
529 [78] = "duplicate request id",
530 [79] = "link down",
531 [80] = "exclusive read-only unit access unsupported",
532 [81] = "shared read-write unit access unsupported",
533 [82] = "incoming rscn",
Christof Schmitt24073b42008-06-10 18:20:54 +0200534 [83] = "incoming wwpn",
535 [84] = "",
Martin Peschke9467a9b2008-03-27 14:22:03 +0100536 [85] = "online",
537 [86] = "offline",
538 [87] = "ccw device gone",
539 [88] = "ccw device no path",
540 [89] = "ccw device operational",
541 [90] = "ccw device shutdown",
542 [91] = "sysfs port addition",
543 [92] = "sysfs port removal",
544 [93] = "sysfs adapter recovery",
545 [94] = "sysfs unit addition",
546 [95] = "sysfs unit removal",
547 [96] = "sysfs port recovery",
548 [97] = "sysfs unit recovery",
549 [98] = "sequence number mismatch",
550 [99] = "link up",
551 [100] = "error state",
552 [101] = "status read physical port closed",
553 [102] = "link up status read",
554 [103] = "too many failed status read buffers",
555 [104] = "port handle not valid abort",
556 [105] = "lun handle not valid abort",
557 [106] = "port handle not valid ct",
558 [107] = "port handle not valid close port",
559 [108] = "port handle not valid close physical port",
560 [109] = "port handle not valid open unit",
561 [110] = "port handle not valid close unit",
562 [111] = "lun handle not valid close unit",
563 [112] = "port handle not valid fcp",
564 [113] = "lun handle not valid fcp",
565 [114] = "handle mismatch fcp",
566 [115] = "lun not valid fcp",
567 [116] = "qdio send failed",
568 [117] = "version mismatch",
569 [118] = "incompatible qtcb type",
570 [119] = "unknown protocol status",
571 [120] = "unknown fsf command",
572 [121] = "no recommendation for status qualifier",
573 [122] = "status read physical port closed in error",
Christof Schmitt553448f2008-06-10 18:20:58 +0200574 [123] = "fc service class not supported",
575 [124] = "",
Martin Peschke9467a9b2008-03-27 14:22:03 +0100576 [125] = "need newer zfcp",
577 [126] = "need newer microcode",
578 [127] = "arbitrated loop not supported",
579 [128] = "unknown topology",
580 [129] = "qtcb size mismatch",
581 [130] = "unknown fsf status ecd",
582 [131] = "fcp request too big",
Christof Schmitt553448f2008-06-10 18:20:58 +0200583 [132] = "",
Martin Peschke9467a9b2008-03-27 14:22:03 +0100584 [133] = "data direction not valid fcp",
585 [134] = "command length not valid fcp",
586 [135] = "status read act update",
587 [136] = "status read cfdc update",
588 [137] = "hbaapi port open",
589 [138] = "hbaapi unit open",
590 [139] = "hbaapi unit shutdown",
Swen Schillig00bab912008-06-10 18:20:57 +0200591 [140] = "qdio error outbound",
Martin Peschke9467a9b2008-03-27 14:22:03 +0100592 [141] = "scsi host reset",
Martin Peschke6f4f3652008-03-27 14:22:04 +0100593 [142] = "dismissing fsf request for recovery action",
594 [143] = "recovery action timed out",
595 [144] = "recovery action gone",
596 [145] = "recovery action being processed",
597 [146] = "recovery action ready for next step",
Swen Schillig00bab912008-06-10 18:20:57 +0200598 [147] = "qdio error inbound",
Martin Peschked79a83d2008-03-27 14:22:00 +0100599};
600
601static int zfcp_rec_dbf_view_format(debug_info_t *id, struct debug_view *view,
602 char *buf, const char *_rec)
603{
604 struct zfcp_rec_dbf_record *r = (struct zfcp_rec_dbf_record *)_rec;
605 char *p = buf;
606
607 zfcp_dbf_outs(&p, "tag", zfcp_rec_dbf_tags[r->id]);
608 zfcp_dbf_outs(&p, "hint", zfcp_rec_dbf_ids[r->id2]);
609 zfcp_dbf_out(&p, "id", "%d", r->id2);
610 switch (r->id) {
Martin Peschke348447e2008-03-27 14:22:01 +0100611 case ZFCP_REC_DBF_ID_THREAD:
Martin Peschke348447e2008-03-27 14:22:01 +0100612 zfcp_dbf_out(&p, "total", "%d", r->u.thread.total);
613 zfcp_dbf_out(&p, "ready", "%d", r->u.thread.ready);
614 zfcp_dbf_out(&p, "running", "%d", r->u.thread.running);
615 break;
Martin Peschke698ec0162008-03-27 14:22:02 +0100616 case ZFCP_REC_DBF_ID_TARGET:
617 zfcp_dbf_out(&p, "reference", "0x%016Lx", r->u.target.ref);
618 zfcp_dbf_out(&p, "status", "0x%08x", r->u.target.status);
619 zfcp_dbf_out(&p, "erp_count", "%d", r->u.target.erp_count);
620 zfcp_dbf_out(&p, "d_id", "0x%06x", r->u.target.d_id);
621 zfcp_dbf_out(&p, "wwpn", "0x%016Lx", r->u.target.wwpn);
622 zfcp_dbf_out(&p, "fcp_lun", "0x%016Lx", r->u.target.fcp_lun);
623 break;
Martin Peschke9467a9b2008-03-27 14:22:03 +0100624 case ZFCP_REC_DBF_ID_TRIGGER:
625 zfcp_dbf_out(&p, "reference", "0x%016Lx", r->u.trigger.ref);
626 zfcp_dbf_out(&p, "erp_action", "0x%016Lx", r->u.trigger.action);
627 zfcp_dbf_out(&p, "requested", "%d", r->u.trigger.want);
628 zfcp_dbf_out(&p, "executed", "%d", r->u.trigger.need);
629 zfcp_dbf_out(&p, "wwpn", "0x%016Lx", r->u.trigger.wwpn);
630 zfcp_dbf_out(&p, "fcp_lun", "0x%016Lx", r->u.trigger.fcp_lun);
631 zfcp_dbf_out(&p, "adapter_status", "0x%08x", r->u.trigger.as);
632 zfcp_dbf_out(&p, "port_status", "0x%08x", r->u.trigger.ps);
633 zfcp_dbf_out(&p, "unit_status", "0x%08x", r->u.trigger.us);
634 break;
Martin Peschke6f4f3652008-03-27 14:22:04 +0100635 case ZFCP_REC_DBF_ID_ACTION:
636 zfcp_dbf_out(&p, "erp_action", "0x%016Lx", r->u.action.action);
637 zfcp_dbf_out(&p, "fsf_req", "0x%016Lx", r->u.action.fsf_req);
638 zfcp_dbf_out(&p, "status", "0x%08Lx", r->u.action.status);
639 zfcp_dbf_out(&p, "step", "0x%08Lx", r->u.action.step);
640 break;
Martin Peschked79a83d2008-03-27 14:22:00 +0100641 }
Martin Peschkeb634fff2008-03-31 11:15:24 +0200642 p += sprintf(p, "\n");
643 return p - buf;
Martin Peschked79a83d2008-03-27 14:22:00 +0100644}
645
646static struct debug_view zfcp_rec_dbf_view = {
647 "structured",
648 NULL,
649 &zfcp_dbf_view_header,
650 &zfcp_rec_dbf_view_format,
651 NULL,
652 NULL
653};
654
Martin Peschke348447e2008-03-27 14:22:01 +0100655/**
656 * zfcp_rec_dbf_event_thread - trace event related to recovery thread operation
657 * @id2: identifier for event
658 * @adapter: adapter
Christof Schmittaa0fec62008-05-19 12:17:47 +0200659 * This function assumes that the caller is holding erp_lock.
Martin Peschke348447e2008-03-27 14:22:01 +0100660 */
Christof Schmittaa0fec62008-05-19 12:17:47 +0200661void zfcp_rec_dbf_event_thread(u8 id2, struct zfcp_adapter *adapter)
Martin Peschke348447e2008-03-27 14:22:01 +0100662{
663 struct zfcp_rec_dbf_record *r = &adapter->rec_dbf_buf;
664 unsigned long flags = 0;
665 struct list_head *entry;
666 unsigned ready = 0, running = 0, total;
667
Martin Peschke348447e2008-03-27 14:22:01 +0100668 list_for_each(entry, &adapter->erp_ready_head)
669 ready++;
670 list_for_each(entry, &adapter->erp_running_head)
671 running++;
672 total = adapter->erp_total_count;
Martin Peschke348447e2008-03-27 14:22:01 +0100673
674 spin_lock_irqsave(&adapter->rec_dbf_lock, flags);
675 memset(r, 0, sizeof(*r));
676 r->id = ZFCP_REC_DBF_ID_THREAD;
677 r->id2 = id2;
Martin Peschke348447e2008-03-27 14:22:01 +0100678 r->u.thread.total = total;
679 r->u.thread.ready = ready;
680 r->u.thread.running = running;
Martin Peschke70c66542008-05-19 12:17:45 +0200681 debug_event(adapter->rec_dbf, 6, r, sizeof(*r));
Martin Peschke348447e2008-03-27 14:22:01 +0100682 spin_unlock_irqrestore(&adapter->rec_dbf_lock, flags);
683}
684
Christof Schmittaa0fec62008-05-19 12:17:47 +0200685/**
686 * zfcp_rec_dbf_event_thread - trace event related to recovery thread operation
687 * @id2: identifier for event
688 * @adapter: adapter
689 * This function assumes that the caller does not hold erp_lock.
690 */
691void zfcp_rec_dbf_event_thread_lock(u8 id2, struct zfcp_adapter *adapter)
692{
693 unsigned long flags;
694
695 read_lock_irqsave(&adapter->erp_lock, flags);
696 zfcp_rec_dbf_event_thread(id2, adapter);
697 read_unlock_irqrestore(&adapter->erp_lock, flags);
698}
699
Martin Peschke1f6f7122008-04-18 12:51:55 +0200700static void zfcp_rec_dbf_event_target(u8 id2, void *ref,
Martin Peschke698ec0162008-03-27 14:22:02 +0100701 struct zfcp_adapter *adapter,
702 atomic_t *status, atomic_t *erp_count,
703 u64 wwpn, u32 d_id, u64 fcp_lun)
704{
705 struct zfcp_rec_dbf_record *r = &adapter->rec_dbf_buf;
706 unsigned long flags;
707
708 spin_lock_irqsave(&adapter->rec_dbf_lock, flags);
709 memset(r, 0, sizeof(*r));
710 r->id = ZFCP_REC_DBF_ID_TARGET;
711 r->id2 = id2;
Martin Peschke1f6f7122008-04-18 12:51:55 +0200712 r->u.target.ref = (unsigned long)ref;
Martin Peschke698ec0162008-03-27 14:22:02 +0100713 r->u.target.status = atomic_read(status);
714 r->u.target.wwpn = wwpn;
715 r->u.target.d_id = d_id;
716 r->u.target.fcp_lun = fcp_lun;
717 r->u.target.erp_count = atomic_read(erp_count);
718 debug_event(adapter->rec_dbf, 3, r, sizeof(*r));
719 spin_unlock_irqrestore(&adapter->rec_dbf_lock, flags);
720}
721
722/**
723 * zfcp_rec_dbf_event_adapter - trace event for adapter state change
724 * @id: identifier for trigger of state change
725 * @ref: additional reference (e.g. request)
726 * @adapter: adapter
727 */
Martin Peschke1f6f7122008-04-18 12:51:55 +0200728void zfcp_rec_dbf_event_adapter(u8 id, void *ref, struct zfcp_adapter *adapter)
Martin Peschke698ec0162008-03-27 14:22:02 +0100729{
730 zfcp_rec_dbf_event_target(id, ref, adapter, &adapter->status,
731 &adapter->erp_counter, 0, 0, 0);
732}
733
734/**
735 * zfcp_rec_dbf_event_port - trace event for port state change
736 * @id: identifier for trigger of state change
737 * @ref: additional reference (e.g. request)
738 * @port: port
739 */
Martin Peschke1f6f7122008-04-18 12:51:55 +0200740void zfcp_rec_dbf_event_port(u8 id, void *ref, struct zfcp_port *port)
Martin Peschke698ec0162008-03-27 14:22:02 +0100741{
742 struct zfcp_adapter *adapter = port->adapter;
743
744 zfcp_rec_dbf_event_target(id, ref, adapter, &port->status,
745 &port->erp_counter, port->wwpn, port->d_id,
746 0);
747}
748
749/**
750 * zfcp_rec_dbf_event_unit - trace event for unit state change
751 * @id: identifier for trigger of state change
752 * @ref: additional reference (e.g. request)
753 * @unit: unit
754 */
Martin Peschke1f6f7122008-04-18 12:51:55 +0200755void zfcp_rec_dbf_event_unit(u8 id, void *ref, struct zfcp_unit *unit)
Martin Peschke698ec0162008-03-27 14:22:02 +0100756{
757 struct zfcp_port *port = unit->port;
758 struct zfcp_adapter *adapter = port->adapter;
759
760 zfcp_rec_dbf_event_target(id, ref, adapter, &unit->status,
761 &unit->erp_counter, port->wwpn, port->d_id,
762 unit->fcp_lun);
763}
764
Martin Peschke9467a9b2008-03-27 14:22:03 +0100765/**
766 * zfcp_rec_dbf_event_trigger - trace event for triggered error recovery
767 * @id2: identifier for error recovery trigger
768 * @ref: additional reference (e.g. request)
769 * @want: originally requested error recovery action
770 * @need: error recovery action actually initiated
771 * @action: address of error recovery action struct
772 * @adapter: adapter
773 * @port: port
774 * @unit: unit
775 */
Martin Peschke1f6f7122008-04-18 12:51:55 +0200776void zfcp_rec_dbf_event_trigger(u8 id2, void *ref, u8 want, u8 need,
777 void *action, struct zfcp_adapter *adapter,
Martin Peschke9467a9b2008-03-27 14:22:03 +0100778 struct zfcp_port *port, struct zfcp_unit *unit)
779{
780 struct zfcp_rec_dbf_record *r = &adapter->rec_dbf_buf;
781 unsigned long flags;
782
783 spin_lock_irqsave(&adapter->rec_dbf_lock, flags);
784 memset(r, 0, sizeof(*r));
785 r->id = ZFCP_REC_DBF_ID_TRIGGER;
786 r->id2 = id2;
Martin Peschke1f6f7122008-04-18 12:51:55 +0200787 r->u.trigger.ref = (unsigned long)ref;
Martin Peschke9467a9b2008-03-27 14:22:03 +0100788 r->u.trigger.want = want;
789 r->u.trigger.need = need;
Martin Peschke1f6f7122008-04-18 12:51:55 +0200790 r->u.trigger.action = (unsigned long)action;
Martin Peschke9467a9b2008-03-27 14:22:03 +0100791 r->u.trigger.as = atomic_read(&adapter->status);
792 if (port) {
793 r->u.trigger.ps = atomic_read(&port->status);
794 r->u.trigger.wwpn = port->wwpn;
795 }
796 if (unit) {
797 r->u.trigger.us = atomic_read(&unit->status);
798 r->u.trigger.fcp_lun = unit->fcp_lun;
799 }
800 debug_event(adapter->rec_dbf, action ? 1 : 4, r, sizeof(*r));
801 spin_unlock_irqrestore(&adapter->rec_dbf_lock, flags);
802}
803
Martin Peschke6f4f3652008-03-27 14:22:04 +0100804/**
805 * zfcp_rec_dbf_event_action - trace event showing progress of recovery action
806 * @id2: identifier
807 * @erp_action: error recovery action struct pointer
808 */
809void zfcp_rec_dbf_event_action(u8 id2, struct zfcp_erp_action *erp_action)
810{
811 struct zfcp_adapter *adapter = erp_action->adapter;
812 struct zfcp_rec_dbf_record *r = &adapter->rec_dbf_buf;
813 unsigned long flags;
814
815 spin_lock_irqsave(&adapter->rec_dbf_lock, flags);
816 memset(r, 0, sizeof(*r));
817 r->id = ZFCP_REC_DBF_ID_ACTION;
818 r->id2 = id2;
Martin Peschke1f6f7122008-04-18 12:51:55 +0200819 r->u.action.action = (unsigned long)erp_action;
Martin Peschke6f4f3652008-03-27 14:22:04 +0100820 r->u.action.status = erp_action->status;
821 r->u.action.step = erp_action->step;
Martin Peschke1f6f7122008-04-18 12:51:55 +0200822 r->u.action.fsf_req = (unsigned long)erp_action->fsf_req;
Martin Peschke70c66542008-05-19 12:17:45 +0200823 debug_event(adapter->rec_dbf, 5, r, sizeof(*r));
Martin Peschke6f4f3652008-03-27 14:22:04 +0100824 spin_unlock_irqrestore(&adapter->rec_dbf_lock, flags);
825}
826
Martin Peschkebfab1632008-03-31 11:15:31 +0200827/**
828 * zfcp_san_dbf_event_ct_request - trace event for issued CT request
829 * @fsf_req: request containing issued CT data
830 */
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100831void zfcp_san_dbf_event_ct_request(struct zfcp_fsf_req *fsf_req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200832{
833 struct zfcp_send_ct *ct = (struct zfcp_send_ct *)fsf_req->data;
834 struct zfcp_port *port = ct->port;
835 struct zfcp_adapter *adapter = port->adapter;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200836 struct ct_hdr *hdr = zfcp_sg_to_address(ct->req);
837 struct zfcp_san_dbf_record *r = &adapter->san_dbf_buf;
838 struct zfcp_san_dbf_record_ct_request *oct = &r->u.ct_req;
839 unsigned long flags;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200840
Martin Peschke6bc473d2008-03-31 11:15:29 +0200841 spin_lock_irqsave(&adapter->san_dbf_lock, flags);
842 memset(r, 0, sizeof(*r));
843 strncpy(r->tag, "octc", ZFCP_DBF_TAG_SIZE);
844 r->fsf_reqid = (unsigned long)fsf_req;
845 r->fsf_seqno = fsf_req->seq_no;
846 r->s_id = fc_host_port_id(adapter->scsi_host);
847 r->d_id = port->d_id;
848 oct->cmd_req_code = hdr->cmd_rsp_code;
849 oct->revision = hdr->revision;
850 oct->gs_type = hdr->gs_type;
851 oct->gs_subtype = hdr->gs_subtype;
852 oct->options = hdr->options;
853 oct->max_res_size = hdr->max_res_size;
854 oct->len = min((int)ct->req->length - (int)sizeof(struct ct_hdr),
855 ZFCP_DBF_CT_PAYLOAD);
856 memcpy(oct->payload, (void *)hdr + sizeof(struct ct_hdr), oct->len);
857 debug_event(adapter->san_dbf, 3, r, sizeof(*r));
858 spin_unlock_irqrestore(&adapter->san_dbf_lock, flags);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200859}
860
Martin Peschkebfab1632008-03-31 11:15:31 +0200861/**
862 * zfcp_san_dbf_event_ct_response - trace event for completion of CT request
863 * @fsf_req: request containing CT response
864 */
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100865void zfcp_san_dbf_event_ct_response(struct zfcp_fsf_req *fsf_req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200866{
867 struct zfcp_send_ct *ct = (struct zfcp_send_ct *)fsf_req->data;
868 struct zfcp_port *port = ct->port;
869 struct zfcp_adapter *adapter = port->adapter;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200870 struct ct_hdr *hdr = zfcp_sg_to_address(ct->resp);
871 struct zfcp_san_dbf_record *r = &adapter->san_dbf_buf;
872 struct zfcp_san_dbf_record_ct_response *rct = &r->u.ct_resp;
873 unsigned long flags;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200874
Martin Peschke6bc473d2008-03-31 11:15:29 +0200875 spin_lock_irqsave(&adapter->san_dbf_lock, flags);
876 memset(r, 0, sizeof(*r));
877 strncpy(r->tag, "rctc", ZFCP_DBF_TAG_SIZE);
878 r->fsf_reqid = (unsigned long)fsf_req;
879 r->fsf_seqno = fsf_req->seq_no;
880 r->s_id = port->d_id;
881 r->d_id = fc_host_port_id(adapter->scsi_host);
882 rct->cmd_rsp_code = hdr->cmd_rsp_code;
883 rct->revision = hdr->revision;
884 rct->reason_code = hdr->reason_code;
885 rct->expl = hdr->reason_code_expl;
886 rct->vendor_unique = hdr->vendor_unique;
887 rct->len = min((int)ct->resp->length - (int)sizeof(struct ct_hdr),
888 ZFCP_DBF_CT_PAYLOAD);
889 memcpy(rct->payload, (void *)hdr + sizeof(struct ct_hdr), rct->len);
890 debug_event(adapter->san_dbf, 3, r, sizeof(*r));
891 spin_unlock_irqrestore(&adapter->san_dbf_lock, flags);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200892}
893
Martin Peschke92c7a832008-03-31 11:15:30 +0200894static void zfcp_san_dbf_event_els(const char *tag, int level,
895 struct zfcp_fsf_req *fsf_req, u32 s_id,
896 u32 d_id, u8 ls_code, void *buffer,
897 int buflen)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200898{
899 struct zfcp_adapter *adapter = fsf_req->adapter;
900 struct zfcp_san_dbf_record *rec = &adapter->san_dbf_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200901 unsigned long flags;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200902
903 spin_lock_irqsave(&adapter->san_dbf_lock, flags);
Martin Peschke6bc473d2008-03-31 11:15:29 +0200904 memset(rec, 0, sizeof(*rec));
Martin Peschke0f65e952008-03-27 14:21:56 +0100905 strncpy(rec->tag, tag, ZFCP_DBF_TAG_SIZE);
906 rec->fsf_reqid = (unsigned long)fsf_req;
907 rec->fsf_seqno = fsf_req->seq_no;
908 rec->s_id = s_id;
909 rec->d_id = d_id;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200910 rec->u.els.ls_code = ls_code;
Martin Peschke0f65e952008-03-27 14:21:56 +0100911 debug_event(adapter->san_dbf, level, rec, sizeof(*rec));
912 zfcp_dbf_hexdump(adapter->san_dbf, rec, sizeof(*rec), level,
913 buffer, min(buflen, ZFCP_DBF_ELS_MAX_PAYLOAD));
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200914 spin_unlock_irqrestore(&adapter->san_dbf_lock, flags);
915}
916
Martin Peschkebfab1632008-03-31 11:15:31 +0200917/**
918 * zfcp_san_dbf_event_els_request - trace event for issued ELS
919 * @fsf_req: request containing issued ELS
920 */
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100921void zfcp_san_dbf_event_els_request(struct zfcp_fsf_req *fsf_req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200922{
923 struct zfcp_send_els *els = (struct zfcp_send_els *)fsf_req->data;
924
Martin Peschke92c7a832008-03-31 11:15:30 +0200925 zfcp_san_dbf_event_els("oels", 2, fsf_req,
926 fc_host_port_id(els->adapter->scsi_host),
927 els->d_id, *(u8 *) zfcp_sg_to_address(els->req),
928 zfcp_sg_to_address(els->req), els->req->length);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200929}
930
Martin Peschkebfab1632008-03-31 11:15:31 +0200931/**
932 * zfcp_san_dbf_event_els_response - trace event for completed ELS
933 * @fsf_req: request containing ELS response
934 */
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100935void zfcp_san_dbf_event_els_response(struct zfcp_fsf_req *fsf_req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200936{
937 struct zfcp_send_els *els = (struct zfcp_send_els *)fsf_req->data;
938
Martin Peschke92c7a832008-03-31 11:15:30 +0200939 zfcp_san_dbf_event_els("rels", 2, fsf_req, els->d_id,
940 fc_host_port_id(els->adapter->scsi_host),
941 *(u8 *)zfcp_sg_to_address(els->req),
942 zfcp_sg_to_address(els->resp),
943 els->resp->length);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200944}
945
Martin Peschkebfab1632008-03-31 11:15:31 +0200946/**
947 * zfcp_san_dbf_event_incoming_els - trace event for incomig ELS
948 * @fsf_req: request containing unsolicited status buffer with incoming ELS
949 */
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100950void zfcp_san_dbf_event_incoming_els(struct zfcp_fsf_req *fsf_req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200951{
952 struct zfcp_adapter *adapter = fsf_req->adapter;
Martin Peschke92c7a832008-03-31 11:15:30 +0200953 struct fsf_status_read_buffer *buf =
954 (struct fsf_status_read_buffer *)fsf_req->data;
955 int length = (int)buf->length -
956 (int)((void *)&buf->payload - (void *)buf);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200957
Martin Peschke92c7a832008-03-31 11:15:30 +0200958 zfcp_san_dbf_event_els("iels", 1, fsf_req, buf->d_id,
959 fc_host_port_id(adapter->scsi_host),
960 *(u8 *)buf->payload, (void *)buf->payload,
961 length);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200962}
963
Martin Peschke92c7a832008-03-31 11:15:30 +0200964static int zfcp_san_dbf_view_format(debug_info_t *id, struct debug_view *view,
965 char *out_buf, const char *in_buf)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200966{
Martin Peschkeb634fff2008-03-31 11:15:24 +0200967 struct zfcp_san_dbf_record *r = (struct zfcp_san_dbf_record *)in_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200968 char *buffer = NULL;
969 int buflen = 0, total = 0;
Martin Peschkeb634fff2008-03-31 11:15:24 +0200970 char *p = out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200971
Martin Peschkeb634fff2008-03-31 11:15:24 +0200972 if (strncmp(r->tag, "dump", ZFCP_DBF_TAG_SIZE) == 0)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200973 return 0;
974
Martin Peschkea9c85772008-03-31 11:15:27 +0200975 zfcp_dbf_tag(&p, "tag", r->tag);
Martin Peschkeb634fff2008-03-31 11:15:24 +0200976 zfcp_dbf_out(&p, "fsf_reqid", "0x%0Lx", r->fsf_reqid);
977 zfcp_dbf_out(&p, "fsf_seqno", "0x%08x", r->fsf_seqno);
978 zfcp_dbf_out(&p, "s_id", "0x%06x", r->s_id);
979 zfcp_dbf_out(&p, "d_id", "0x%06x", r->d_id);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200980
Martin Peschkeb634fff2008-03-31 11:15:24 +0200981 if (strncmp(r->tag, "octc", ZFCP_DBF_TAG_SIZE) == 0) {
Martin Peschke6bc473d2008-03-31 11:15:29 +0200982 struct zfcp_san_dbf_record_ct_request *ct = &r->u.ct_req;
983 zfcp_dbf_out(&p, "cmd_req_code", "0x%04x", ct->cmd_req_code);
984 zfcp_dbf_out(&p, "revision", "0x%02x", ct->revision);
985 zfcp_dbf_out(&p, "gs_type", "0x%02x", ct->gs_type);
986 zfcp_dbf_out(&p, "gs_subtype", "0x%02x", ct->gs_subtype);
987 zfcp_dbf_out(&p, "options", "0x%02x", ct->options);
988 zfcp_dbf_out(&p, "max_res_size", "0x%04x", ct->max_res_size);
989 total = ct->len;
990 buffer = ct->payload;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200991 buflen = min(total, ZFCP_DBF_CT_PAYLOAD);
Martin Peschkeb634fff2008-03-31 11:15:24 +0200992 } else if (strncmp(r->tag, "rctc", ZFCP_DBF_TAG_SIZE) == 0) {
Martin Peschke6bc473d2008-03-31 11:15:29 +0200993 struct zfcp_san_dbf_record_ct_response *ct = &r->u.ct_resp;
994 zfcp_dbf_out(&p, "cmd_rsp_code", "0x%04x", ct->cmd_rsp_code);
995 zfcp_dbf_out(&p, "revision", "0x%02x", ct->revision);
996 zfcp_dbf_out(&p, "reason_code", "0x%02x", ct->reason_code);
997 zfcp_dbf_out(&p, "reason_code_expl", "0x%02x", ct->expl);
998 zfcp_dbf_out(&p, "vendor_unique", "0x%02x", ct->vendor_unique);
999 total = ct->len;
1000 buffer = ct->payload;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001001 buflen = min(total, ZFCP_DBF_CT_PAYLOAD);
Martin Peschkeb634fff2008-03-31 11:15:24 +02001002 } else if (strncmp(r->tag, "oels", ZFCP_DBF_TAG_SIZE) == 0 ||
1003 strncmp(r->tag, "rels", ZFCP_DBF_TAG_SIZE) == 0 ||
1004 strncmp(r->tag, "iels", ZFCP_DBF_TAG_SIZE) == 0) {
Martin Peschke6bc473d2008-03-31 11:15:29 +02001005 struct zfcp_san_dbf_record_els *els = &r->u.els;
1006 zfcp_dbf_out(&p, "ls_code", "0x%02x", els->ls_code);
1007 total = els->len;
1008 buffer = els->payload;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001009 buflen = min(total, ZFCP_DBF_ELS_PAYLOAD);
1010 }
1011
Martin Peschkedf29f4a2008-03-31 11:15:26 +02001012 zfcp_dbf_outd(&p, "payload", buffer, buflen, 0, total);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001013 if (buflen == total)
Martin Peschkeb634fff2008-03-31 11:15:24 +02001014 p += sprintf(p, "\n");
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001015
Martin Peschkeb634fff2008-03-31 11:15:24 +02001016 return p - out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001017}
1018
Heiko Carstens2b67fc42007-02-05 21:16:47 +01001019static struct debug_view zfcp_san_dbf_view = {
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001020 "structured",
1021 NULL,
1022 &zfcp_dbf_view_header,
1023 &zfcp_san_dbf_view_format,
1024 NULL,
1025 NULL
1026};
1027
Martin Peschke92c7a832008-03-31 11:15:30 +02001028static void zfcp_scsi_dbf_event(const char *tag, const char *tag2, int level,
1029 struct zfcp_adapter *adapter,
1030 struct scsi_cmnd *scsi_cmnd,
1031 struct zfcp_fsf_req *fsf_req,
1032 unsigned long old_req_id)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001033{
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001034 struct zfcp_scsi_dbf_record *rec = &adapter->scsi_dbf_buf;
1035 struct zfcp_dbf_dump *dump = (struct zfcp_dbf_dump *)rec;
1036 unsigned long flags;
1037 struct fcp_rsp_iu *fcp_rsp;
1038 char *fcp_rsp_info = NULL, *fcp_sns_info = NULL;
1039 int offset = 0, buflen = 0;
1040
1041 spin_lock_irqsave(&adapter->scsi_dbf_lock, flags);
1042 do {
Martin Peschke6bc473d2008-03-31 11:15:29 +02001043 memset(rec, 0, sizeof(*rec));
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001044 if (offset == 0) {
1045 strncpy(rec->tag, tag, ZFCP_DBF_TAG_SIZE);
1046 strncpy(rec->tag2, tag2, ZFCP_DBF_TAG_SIZE);
Maxim Shchetynined829ad2006-02-11 01:42:58 +01001047 if (scsi_cmnd != NULL) {
1048 if (scsi_cmnd->device) {
1049 rec->scsi_id = scsi_cmnd->device->id;
1050 rec->scsi_lun = scsi_cmnd->device->lun;
1051 }
1052 rec->scsi_result = scsi_cmnd->result;
1053 rec->scsi_cmnd = (unsigned long)scsi_cmnd;
1054 rec->scsi_serial = scsi_cmnd->serial_number;
Boaz Harrosh64a87b22008-04-30 11:19:47 +03001055 memcpy(rec->scsi_opcode, scsi_cmnd->cmnd,
Maxim Shchetynined829ad2006-02-11 01:42:58 +01001056 min((int)scsi_cmnd->cmd_len,
1057 ZFCP_DBF_SCSI_OPCODE));
1058 rec->scsi_retries = scsi_cmnd->retries;
1059 rec->scsi_allowed = scsi_cmnd->allowed;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001060 }
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001061 if (fsf_req != NULL) {
1062 fcp_rsp = (struct fcp_rsp_iu *)
1063 &(fsf_req->qtcb->bottom.io.fcp_rsp);
1064 fcp_rsp_info =
1065 zfcp_get_fcp_rsp_info_ptr(fcp_rsp);
1066 fcp_sns_info =
1067 zfcp_get_fcp_sns_info_ptr(fcp_rsp);
1068
Martin Peschke6bc473d2008-03-31 11:15:29 +02001069 rec->rsp_validity = fcp_rsp->validity.value;
1070 rec->rsp_scsi_status = fcp_rsp->scsi_status;
1071 rec->rsp_resid = fcp_rsp->fcp_resid;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001072 if (fcp_rsp->validity.bits.fcp_rsp_len_valid)
Martin Peschke6bc473d2008-03-31 11:15:29 +02001073 rec->rsp_code = *(fcp_rsp_info + 3);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001074 if (fcp_rsp->validity.bits.fcp_sns_len_valid) {
1075 buflen = min((int)fcp_rsp->fcp_sns_len,
1076 ZFCP_DBF_SCSI_MAX_FCP_SNS_INFO);
Martin Peschke6bc473d2008-03-31 11:15:29 +02001077 rec->sns_info_len = buflen;
1078 memcpy(rec->sns_info, fcp_sns_info,
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001079 min(buflen,
1080 ZFCP_DBF_SCSI_FCP_SNS_INFO));
1081 offset += min(buflen,
1082 ZFCP_DBF_SCSI_FCP_SNS_INFO);
1083 }
1084
1085 rec->fsf_reqid = (unsigned long)fsf_req;
1086 rec->fsf_seqno = fsf_req->seq_no;
1087 rec->fsf_issued = fsf_req->issued;
1088 }
Martin Peschke6bc473d2008-03-31 11:15:29 +02001089 rec->old_fsf_reqid = old_req_id;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001090 } else {
1091 strncpy(dump->tag, "dump", ZFCP_DBF_TAG_SIZE);
1092 dump->total_size = buflen;
1093 dump->offset = offset;
1094 dump->size = min(buflen - offset,
1095 (int)sizeof(struct
1096 zfcp_scsi_dbf_record) -
1097 (int)sizeof(struct zfcp_dbf_dump));
1098 memcpy(dump->data, fcp_sns_info + offset, dump->size);
1099 offset += dump->size;
1100 }
Martin Peschke6bc473d2008-03-31 11:15:29 +02001101 debug_event(adapter->scsi_dbf, level, rec, sizeof(*rec));
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001102 } while (offset < buflen);
1103 spin_unlock_irqrestore(&adapter->scsi_dbf_lock, flags);
1104}
1105
Martin Peschkebfab1632008-03-31 11:15:31 +02001106/**
1107 * zfcp_scsi_dbf_event_result - trace event for SCSI command completion
1108 * @tag: tag indicating success or failure of SCSI command
1109 * @level: trace level applicable for this event
1110 * @adapter: adapter that has been used to issue the SCSI command
1111 * @scsi_cmnd: SCSI command pointer
1112 * @fsf_req: request used to issue SCSI command (might be NULL)
1113 */
Martin Peschke92c7a832008-03-31 11:15:30 +02001114void zfcp_scsi_dbf_event_result(const char *tag, int level,
1115 struct zfcp_adapter *adapter,
1116 struct scsi_cmnd *scsi_cmnd,
1117 struct zfcp_fsf_req *fsf_req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001118{
Martin Peschke92c7a832008-03-31 11:15:30 +02001119 zfcp_scsi_dbf_event("rslt", tag, level, adapter, scsi_cmnd, fsf_req, 0);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001120}
1121
Martin Peschkebfab1632008-03-31 11:15:31 +02001122/**
1123 * zfcp_scsi_dbf_event_abort - trace event for SCSI command abort
1124 * @tag: tag indicating success or failure of abort operation
1125 * @adapter: adapter thas has been used to issue SCSI command to be aborted
1126 * @scsi_cmnd: SCSI command to be aborted
1127 * @new_fsf_req: request containing abort (might be NULL)
1128 * @old_req_id: identifier of request containg SCSI command to be aborted
1129 */
Martin Peschke92c7a832008-03-31 11:15:30 +02001130void zfcp_scsi_dbf_event_abort(const char *tag, struct zfcp_adapter *adapter,
1131 struct scsi_cmnd *scsi_cmnd,
1132 struct zfcp_fsf_req *new_fsf_req,
1133 unsigned long old_req_id)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001134{
Martin Peschke92c7a832008-03-31 11:15:30 +02001135 zfcp_scsi_dbf_event("abrt", tag, 1, adapter, scsi_cmnd, new_fsf_req,
1136 old_req_id);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001137}
1138
Martin Peschkebfab1632008-03-31 11:15:31 +02001139/**
1140 * zfcp_scsi_dbf_event_devreset - trace event for Logical Unit or Target Reset
1141 * @tag: tag indicating success or failure of reset operation
1142 * @flag: indicates type of reset (Target Reset, Logical Unit Reset)
1143 * @unit: unit that needs reset
1144 * @scsi_cmnd: SCSI command which caused this error recovery
1145 */
Martin Peschke92c7a832008-03-31 11:15:30 +02001146void zfcp_scsi_dbf_event_devreset(const char *tag, u8 flag,
1147 struct zfcp_unit *unit,
1148 struct scsi_cmnd *scsi_cmnd)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001149{
Martin Peschke92c7a832008-03-31 11:15:30 +02001150 zfcp_scsi_dbf_event(flag == FCP_TARGET_RESET ? "trst" : "lrst", tag, 1,
1151 unit->port->adapter, scsi_cmnd, NULL, 0);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001152}
1153
Martin Peschke92c7a832008-03-31 11:15:30 +02001154static int zfcp_scsi_dbf_view_format(debug_info_t *id, struct debug_view *view,
1155 char *out_buf, const char *in_buf)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001156{
Martin Peschkeb634fff2008-03-31 11:15:24 +02001157 struct zfcp_scsi_dbf_record *r = (struct zfcp_scsi_dbf_record *)in_buf;
Martin Peschke8fc5af12008-03-31 11:15:23 +02001158 struct timespec t;
Martin Peschkeb634fff2008-03-31 11:15:24 +02001159 char *p = out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001160
Martin Peschkeb634fff2008-03-31 11:15:24 +02001161 if (strncmp(r->tag, "dump", ZFCP_DBF_TAG_SIZE) == 0)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001162 return 0;
1163
Martin Peschkea9c85772008-03-31 11:15:27 +02001164 zfcp_dbf_tag(&p, "tag", r->tag);
1165 zfcp_dbf_tag(&p, "tag2", r->tag2);
Martin Peschkeb634fff2008-03-31 11:15:24 +02001166 zfcp_dbf_out(&p, "scsi_id", "0x%08x", r->scsi_id);
1167 zfcp_dbf_out(&p, "scsi_lun", "0x%08x", r->scsi_lun);
1168 zfcp_dbf_out(&p, "scsi_result", "0x%08x", r->scsi_result);
1169 zfcp_dbf_out(&p, "scsi_cmnd", "0x%0Lx", r->scsi_cmnd);
1170 zfcp_dbf_out(&p, "scsi_serial", "0x%016Lx", r->scsi_serial);
Martin Peschkedf29f4a2008-03-31 11:15:26 +02001171 zfcp_dbf_outd(&p, "scsi_opcode", r->scsi_opcode, ZFCP_DBF_SCSI_OPCODE,
1172 0, ZFCP_DBF_SCSI_OPCODE);
Martin Peschkeb634fff2008-03-31 11:15:24 +02001173 zfcp_dbf_out(&p, "scsi_retries", "0x%02x", r->scsi_retries);
1174 zfcp_dbf_out(&p, "scsi_allowed", "0x%02x", r->scsi_allowed);
1175 if (strncmp(r->tag, "abrt", ZFCP_DBF_TAG_SIZE) == 0)
Martin Peschke6bc473d2008-03-31 11:15:29 +02001176 zfcp_dbf_out(&p, "old_fsf_reqid", "0x%0Lx", r->old_fsf_reqid);
Martin Peschkeb634fff2008-03-31 11:15:24 +02001177 zfcp_dbf_out(&p, "fsf_reqid", "0x%0Lx", r->fsf_reqid);
1178 zfcp_dbf_out(&p, "fsf_seqno", "0x%08x", r->fsf_seqno);
1179 zfcp_dbf_timestamp(r->fsf_issued, &t);
1180 zfcp_dbf_out(&p, "fsf_issued", "%011lu:%06lu", t.tv_sec, t.tv_nsec);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001181
Martin Peschkeb634fff2008-03-31 11:15:24 +02001182 if (strncmp(r->tag, "rslt", ZFCP_DBF_TAG_SIZE) == 0) {
Martin Peschke6bc473d2008-03-31 11:15:29 +02001183 zfcp_dbf_out(&p, "fcp_rsp_validity", "0x%02x", r->rsp_validity);
1184 zfcp_dbf_out(&p, "fcp_rsp_scsi_status", "0x%02x",
1185 r->rsp_scsi_status);
1186 zfcp_dbf_out(&p, "fcp_rsp_resid", "0x%08x", r->rsp_resid);
1187 zfcp_dbf_out(&p, "fcp_rsp_code", "0x%08x", r->rsp_code);
1188 zfcp_dbf_out(&p, "fcp_sns_info_len", "0x%08x", r->sns_info_len);
1189 zfcp_dbf_outd(&p, "fcp_sns_info", r->sns_info,
1190 min((int)r->sns_info_len,
Martin Peschkedf29f4a2008-03-31 11:15:26 +02001191 ZFCP_DBF_SCSI_FCP_SNS_INFO), 0,
Martin Peschke6bc473d2008-03-31 11:15:29 +02001192 r->sns_info_len);
Martin Peschkeb634fff2008-03-31 11:15:24 +02001193 }
1194 p += sprintf(p, "\n");
1195 return p - out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001196}
1197
Heiko Carstens2b67fc42007-02-05 21:16:47 +01001198static struct debug_view zfcp_scsi_dbf_view = {
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001199 "structured",
1200 NULL,
1201 &zfcp_dbf_view_header,
1202 &zfcp_scsi_dbf_view_format,
1203 NULL,
1204 NULL
1205};
1206
1207/**
1208 * zfcp_adapter_debug_register - registers debug feature for an adapter
1209 * @adapter: pointer to adapter for which debug features should be registered
1210 * return: -ENOMEM on error, 0 otherwise
1211 */
1212int zfcp_adapter_debug_register(struct zfcp_adapter *adapter)
1213{
1214 char dbf_name[DEBUG_MAX_NAME_LEN];
1215
1216 /* debug feature area which records recovery activity */
Martin Peschked79a83d2008-03-27 14:22:00 +01001217 sprintf(dbf_name, "zfcp_%s_rec", zfcp_get_busid_by_adapter(adapter));
1218 adapter->rec_dbf = debug_register(dbf_name, dbfsize, 1,
1219 sizeof(struct zfcp_rec_dbf_record));
1220 if (!adapter->rec_dbf)
1221 goto failed;
1222 debug_register_view(adapter->rec_dbf, &debug_hex_ascii_view);
1223 debug_register_view(adapter->rec_dbf, &zfcp_rec_dbf_view);
1224 debug_set_level(adapter->rec_dbf, 3);
1225
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001226 /* debug feature area which records HBA (FSF and QDIO) conditions */
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001227 sprintf(dbf_name, "zfcp_%s_hba", zfcp_get_busid_by_adapter(adapter));
1228 adapter->hba_dbf = debug_register(dbf_name, dbfsize, 1,
1229 sizeof(struct zfcp_hba_dbf_record));
1230 if (!adapter->hba_dbf)
1231 goto failed;
1232 debug_register_view(adapter->hba_dbf, &debug_hex_ascii_view);
1233 debug_register_view(adapter->hba_dbf, &zfcp_hba_dbf_view);
1234 debug_set_level(adapter->hba_dbf, 3);
1235
1236 /* debug feature area which records SAN command failures and recovery */
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001237 sprintf(dbf_name, "zfcp_%s_san", zfcp_get_busid_by_adapter(adapter));
1238 adapter->san_dbf = debug_register(dbf_name, dbfsize, 1,
1239 sizeof(struct zfcp_san_dbf_record));
1240 if (!adapter->san_dbf)
1241 goto failed;
1242 debug_register_view(adapter->san_dbf, &debug_hex_ascii_view);
1243 debug_register_view(adapter->san_dbf, &zfcp_san_dbf_view);
1244 debug_set_level(adapter->san_dbf, 6);
1245
1246 /* debug feature area which records SCSI command failures and recovery */
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001247 sprintf(dbf_name, "zfcp_%s_scsi", zfcp_get_busid_by_adapter(adapter));
1248 adapter->scsi_dbf = debug_register(dbf_name, dbfsize, 1,
1249 sizeof(struct zfcp_scsi_dbf_record));
1250 if (!adapter->scsi_dbf)
1251 goto failed;
1252 debug_register_view(adapter->scsi_dbf, &debug_hex_ascii_view);
1253 debug_register_view(adapter->scsi_dbf, &zfcp_scsi_dbf_view);
1254 debug_set_level(adapter->scsi_dbf, 3);
1255
1256 return 0;
1257
1258 failed:
1259 zfcp_adapter_debug_unregister(adapter);
1260
1261 return -ENOMEM;
1262}
1263
1264/**
1265 * zfcp_adapter_debug_unregister - unregisters debug feature for an adapter
1266 * @adapter: pointer to adapter for which debug features should be unregistered
1267 */
1268void zfcp_adapter_debug_unregister(struct zfcp_adapter *adapter)
1269{
1270 debug_unregister(adapter->scsi_dbf);
1271 debug_unregister(adapter->san_dbf);
1272 debug_unregister(adapter->hba_dbf);
Martin Peschked79a83d2008-03-27 14:22:00 +01001273 debug_unregister(adapter->rec_dbf);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001274 adapter->scsi_dbf = NULL;
1275 adapter->san_dbf = NULL;
1276 adapter->hba_dbf = NULL;
Martin Peschked79a83d2008-03-27 14:22:00 +01001277 adapter->rec_dbf = NULL;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001278}