zfcp_dbf.c 35.1 KB
Newer Older
1
/*
C
Christof Schmitt 已提交
2
 * zfcp device driver
3
 *
C
Christof Schmitt 已提交
4
 * Debug traces for zfcp.
5
 *
6
 * Copyright IBM Corporation 2002, 2009
7 8
 */

9 10 11
#define KMSG_COMPONENT "zfcp"
#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt

12
#include <linux/ctype.h>
13
#include <linux/slab.h>
14
#include <asm/debug.h>
15
#include "zfcp_dbf.h"
16
#include "zfcp_ext.h"
17
#include "zfcp_fc.h"
18 19 20 21 22 23 24

static u32 dbfsize = 4;

module_param(dbfsize, uint, 0400);
MODULE_PARM_DESC(dbfsize,
		 "number of pages for each debug feature area (default 4)");

25 26 27 28 29 30 31 32 33 34 35 36 37 38
static void zfcp_dbf_hexdump(debug_info_t *dbf, void *to, int to_len,
			     int level, char *from, int from_len)
{
	int offset;
	struct zfcp_dbf_dump *dump = to;
	int room = to_len - sizeof(*dump);

	for (offset = 0; offset < from_len; offset += dump->size) {
		memset(to, 0, to_len);
		strncpy(dump->tag, "dump", ZFCP_DBF_TAG_SIZE);
		dump->total_size = from_len;
		dump->offset = offset;
		dump->size = min(from_len - offset, room);
		memcpy(dump->data, from + offset, dump->size);
39
		debug_event(dbf, level, dump, dump->size + sizeof(*dump));
40 41 42
	}
}

43
static void zfcp_dbf_tag(char **p, const char *label, const char *tag)
44
{
45
	int i;
46

47
	*p += sprintf(*p, "%-24s", label);
48
	for (i = 0; i < ZFCP_DBF_TAG_SIZE; i++)
49 50
		*p += sprintf(*p, "%c", tag[i]);
	*p += sprintf(*p, "\n");
51 52
}

53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
static void zfcp_dbf_outs(char **buf, const char *s1, const char *s2)
{
	*buf += sprintf(*buf, "%-24s%s\n", s1, s2);
}

static void zfcp_dbf_out(char **buf, const char *s, const char *format, ...)
{
	va_list arg;

	*buf += sprintf(*buf, "%-24s", s);
	va_start(arg, format);
	*buf += vsprintf(*buf, format, arg);
	va_end(arg);
	*buf += sprintf(*buf, "\n");
}

69 70
static void zfcp_dbf_outd(char **p, const char *label, char *buffer,
			  int buflen, int offset, int total_size)
71
{
72 73
	if (!offset)
		*p += sprintf(*p, "%-24s  ", label);
74 75 76
	while (buflen--) {
		if (offset > 0) {
			if ((offset % 32) == 0)
77
				*p += sprintf(*p, "\n%-24c  ", ' ');
78
			else if ((offset % 4) == 0)
79
				*p += sprintf(*p, " ");
80
		}
81
		*p += sprintf(*p, "%02x", *buffer++);
82
		if (++offset == total_size) {
83
			*p += sprintf(*p, "\n");
84 85 86
			break;
		}
	}
87 88
	if (!total_size)
		*p += sprintf(*p, "\n");
89 90
}

91 92
static int zfcp_dbf_view_header(debug_info_t *id, struct debug_view *view,
				int area, debug_entry_t *entry, char *out_buf)
93 94
{
	struct zfcp_dbf_dump *dump = (struct zfcp_dbf_dump *)DEBUG_DATA(entry);
95
	struct timespec t;
96
	char *p = out_buf;
97 98

	if (strncmp(dump->tag, "dump", ZFCP_DBF_TAG_SIZE) != 0) {
99
		stck_to_timespec(entry->id.stck, &t);
100 101 102 103
		zfcp_dbf_out(&p, "timestamp", "%011lu:%06lu",
			     t.tv_sec, t.tv_nsec);
		zfcp_dbf_out(&p, "cpu", "%02i", entry->id.fields.cpuid);
	} else	{
104
		zfcp_dbf_outd(&p, "", dump->data, dump->size, dump->offset,
105
			      dump->total_size);
106
		if ((dump->offset + dump->size) == dump->total_size)
107
			p += sprintf(p, "\n");
108
	}
109
	return p - out_buf;
110 111
}

S
Swen Schillig 已提交
112 113 114
void _zfcp_dbf_hba_fsf_response(const char *tag2, int level,
				struct zfcp_fsf_req *fsf_req,
				struct zfcp_dbf *dbf)
115 116 117
{
	struct fsf_qtcb *qtcb = fsf_req->qtcb;
	union fsf_prot_status_qual *prot_status_qual =
118
					&qtcb->prefix.prot_status_qual;
119 120 121 122 123
	union fsf_status_qual *fsf_status_qual = &qtcb->header.fsf_status_qual;
	struct scsi_cmnd *scsi_cmnd;
	struct zfcp_port *port;
	struct zfcp_unit *unit;
	struct zfcp_send_els *send_els;
S
Swen Schillig 已提交
124 125
	struct zfcp_dbf_hba_record *rec = &dbf->hba_buf;
	struct zfcp_dbf_hba_record_response *response = &rec->u.response;
126 127
	unsigned long flags;

S
Swen Schillig 已提交
128
	spin_lock_irqsave(&dbf->hba_lock, flags);
129
	memset(rec, 0, sizeof(*rec));
130
	strncpy(rec->tag, "resp", ZFCP_DBF_TAG_SIZE);
131
	strncpy(rec->tag2, tag2, ZFCP_DBF_TAG_SIZE);
132 133

	response->fsf_command = fsf_req->fsf_command;
134
	response->fsf_reqid = fsf_req->req_id;
135 136 137 138 139 140 141 142 143
	response->fsf_seqno = fsf_req->seq_no;
	response->fsf_issued = fsf_req->issued;
	response->fsf_prot_status = qtcb->prefix.prot_status;
	response->fsf_status = qtcb->header.fsf_status;
	memcpy(response->fsf_prot_status_qual,
	       prot_status_qual, FSF_PROT_STATUS_QUAL_SIZE);
	memcpy(response->fsf_status_qual,
	       fsf_status_qual, FSF_STATUS_QUALIFIER_SIZE);
	response->fsf_req_status = fsf_req->status;
144 145 146
	response->sbal_first = fsf_req->qdio_req.sbal_first;
	response->sbal_last = fsf_req->qdio_req.sbal_last;
	response->sbal_response = fsf_req->qdio_req.sbal_response;
147 148 149 150 151 152 153 154
	response->pool = fsf_req->pool != NULL;
	response->erp_action = (unsigned long)fsf_req->erp_action;

	switch (fsf_req->fsf_command) {
	case FSF_QTCB_FCP_CMND:
		if (fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT)
			break;
		scsi_cmnd = (struct scsi_cmnd *)fsf_req->data;
155 156 157
		if (scsi_cmnd) {
			response->u.fcp.cmnd = (unsigned long)scsi_cmnd;
			response->u.fcp.serial = scsi_cmnd->serial_number;
158 159
			response->u.fcp.data_dir =
				qtcb->bottom.io.data_direction;
160 161 162 163 164 165 166
		}
		break;

	case FSF_QTCB_OPEN_PORT_WITH_DID:
	case FSF_QTCB_CLOSE_PORT:
	case FSF_QTCB_CLOSE_PHYSICAL_PORT:
		port = (struct zfcp_port *)fsf_req->data;
167 168 169
		response->u.port.wwpn = port->wwpn;
		response->u.port.d_id = port->d_id;
		response->u.port.port_handle = qtcb->header.port_handle;
170 171 172 173 174 175
		break;

	case FSF_QTCB_OPEN_LUN:
	case FSF_QTCB_CLOSE_LUN:
		unit = (struct zfcp_unit *)fsf_req->data;
		port = unit->port;
176 177 178 179
		response->u.unit.wwpn = port->wwpn;
		response->u.unit.fcp_lun = unit->fcp_lun;
		response->u.unit.port_handle = qtcb->header.port_handle;
		response->u.unit.lun_handle = qtcb->header.lun_handle;
180 181 182 183
		break;

	case FSF_QTCB_SEND_ELS:
		send_els = (struct zfcp_send_els *)fsf_req->data;
184
		response->u.els.d_id = ntoh24(qtcb->bottom.support.d_id);
185 186 187 188 189 190 191 192 193 194 195
		break;

	case FSF_QTCB_ABORT_FCP_CMND:
	case FSF_QTCB_SEND_GENERIC:
	case FSF_QTCB_EXCHANGE_CONFIG_DATA:
	case FSF_QTCB_EXCHANGE_PORT_DATA:
	case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
	case FSF_QTCB_UPLOAD_CONTROL_FILE:
		break;
	}

S
Swen Schillig 已提交
196
	debug_event(dbf->hba, level, rec, sizeof(*rec));
197 198 199 200 201 202 203

	/* have fcp channel microcode fixed to use as little as possible */
	if (fsf_req->fsf_command != FSF_QTCB_FCP_CMND) {
		/* adjust length skipping trailing zeros */
		char *buf = (char *)qtcb + qtcb->header.log_start;
		int len = qtcb->header.log_length;
		for (; len && !buf[len - 1]; len--);
S
Swen Schillig 已提交
204
		zfcp_dbf_hexdump(dbf->hba, rec, sizeof(*rec), level, buf,
205
				 len);
206 207
	}

S
Swen Schillig 已提交
208
	spin_unlock_irqrestore(&dbf->hba_lock, flags);
209 210
}

S
Swen Schillig 已提交
211 212
void _zfcp_dbf_hba_fsf_unsol(const char *tag, int level, struct zfcp_dbf *dbf,
			     struct fsf_status_read_buffer *status_buffer)
213
{
S
Swen Schillig 已提交
214
	struct zfcp_dbf_hba_record *rec = &dbf->hba_buf;
215 216
	unsigned long flags;

S
Swen Schillig 已提交
217
	spin_lock_irqsave(&dbf->hba_lock, flags);
218
	memset(rec, 0, sizeof(*rec));
219 220 221
	strncpy(rec->tag, "stat", ZFCP_DBF_TAG_SIZE);
	strncpy(rec->tag2, tag, ZFCP_DBF_TAG_SIZE);

S
Swen Schillig 已提交
222
	rec->u.status.failed = atomic_read(&dbf->adapter->stat_miss);
223
	if (status_buffer != NULL) {
224 225 226
		rec->u.status.status_type = status_buffer->status_type;
		rec->u.status.status_subtype = status_buffer->status_subtype;
		memcpy(&rec->u.status.queue_designator,
227 228 229 230 231
		       &status_buffer->queue_designator,
		       sizeof(struct fsf_queue_designator));

		switch (status_buffer->status_type) {
		case FSF_STATUS_READ_SENSE_DATA_AVAIL:
232
			rec->u.status.payload_size =
233 234 235 236
			    ZFCP_DBF_UNSOL_PAYLOAD_SENSE_DATA_AVAIL;
			break;

		case FSF_STATUS_READ_BIT_ERROR_THRESHOLD:
237
			rec->u.status.payload_size =
238 239 240 241
			    ZFCP_DBF_UNSOL_PAYLOAD_BIT_ERROR_THRESHOLD;
			break;

		case FSF_STATUS_READ_LINK_DOWN:
242 243 244
			switch (status_buffer->status_subtype) {
			case FSF_STATUS_READ_SUB_NO_PHYSICAL_LINK:
			case FSF_STATUS_READ_SUB_FDISC_FAILED:
245
				rec->u.status.payload_size =
246 247
					sizeof(struct fsf_link_down_info);
			}
248 249
			break;

250
		case FSF_STATUS_READ_FEATURE_UPDATE_ALERT:
251
			rec->u.status.payload_size =
252 253
			    ZFCP_DBF_UNSOL_PAYLOAD_FEATURE_UPDATE_ALERT;
			break;
254
		}
255 256
		memcpy(&rec->u.status.payload,
		       &status_buffer->payload, rec->u.status.payload_size);
257 258
	}

S
Swen Schillig 已提交
259 260
	debug_event(dbf->hba, level, rec, sizeof(*rec));
	spin_unlock_irqrestore(&dbf->hba_lock, flags);
261 262
}

263
/**
S
Swen Schillig 已提交
264
 * zfcp_dbf_hba_qdio - trace event for QDIO related failure
265
 * @qdio: qdio structure affected by this QDIO related event
266 267 268 269
 * @qdio_error: as passed by qdio module
 * @sbal_index: first buffer with error condition, as passed by qdio module
 * @sbal_count: number of buffers affected, as passed by qdio module
 */
S
Swen Schillig 已提交
270 271
void zfcp_dbf_hba_qdio(struct zfcp_dbf *dbf, unsigned int qdio_error,
		       int sbal_index, int sbal_count)
272
{
S
Swen Schillig 已提交
273
	struct zfcp_dbf_hba_record *r = &dbf->hba_buf;
274 275
	unsigned long flags;

S
Swen Schillig 已提交
276
	spin_lock_irqsave(&dbf->hba_lock, flags);
277 278 279 280 281
	memset(r, 0, sizeof(*r));
	strncpy(r->tag, "qdio", ZFCP_DBF_TAG_SIZE);
	r->u.qdio.qdio_error = qdio_error;
	r->u.qdio.sbal_index = sbal_index;
	r->u.qdio.sbal_count = sbal_count;
S
Swen Schillig 已提交
282 283
	debug_event(dbf->hba, 0, r, sizeof(*r));
	spin_unlock_irqrestore(&dbf->hba_lock, flags);
284 285
}

286
/**
S
Swen Schillig 已提交
287 288
 * zfcp_dbf_hba_berr - trace event for bit error threshold
 * @dbf: dbf structure affected by this QDIO related event
289 290
 * @req: fsf request
 */
S
Swen Schillig 已提交
291
void zfcp_dbf_hba_berr(struct zfcp_dbf *dbf, struct zfcp_fsf_req *req)
292
{
S
Swen Schillig 已提交
293
	struct zfcp_dbf_hba_record *r = &dbf->hba_buf;
294 295 296 297
	struct fsf_status_read_buffer *sr_buf = req->data;
	struct fsf_bit_error_payload *err = &sr_buf->payload.bit_error;
	unsigned long flags;

S
Swen Schillig 已提交
298
	spin_lock_irqsave(&dbf->hba_lock, flags);
299 300 301
	memset(r, 0, sizeof(*r));
	strncpy(r->tag, "berr", ZFCP_DBF_TAG_SIZE);
	memcpy(&r->u.berr, err, sizeof(struct fsf_bit_error_payload));
S
Swen Schillig 已提交
302 303
	debug_event(dbf->hba, 0, r, sizeof(*r));
	spin_unlock_irqrestore(&dbf->hba_lock, flags);
304
}
S
Swen Schillig 已提交
305 306
static void zfcp_dbf_hba_view_response(char **p,
				       struct zfcp_dbf_hba_record_response *r)
307
{
308
	struct timespec t;
309

310 311 312
	zfcp_dbf_out(p, "fsf_command", "0x%08x", r->fsf_command);
	zfcp_dbf_out(p, "fsf_reqid", "0x%0Lx", r->fsf_reqid);
	zfcp_dbf_out(p, "fsf_seqno", "0x%08x", r->fsf_seqno);
313
	stck_to_timespec(r->fsf_issued, &t);
314 315 316 317
	zfcp_dbf_out(p, "fsf_issued", "%011lu:%06lu", t.tv_sec, t.tv_nsec);
	zfcp_dbf_out(p, "fsf_prot_status", "0x%08x", r->fsf_prot_status);
	zfcp_dbf_out(p, "fsf_status", "0x%08x", r->fsf_status);
	zfcp_dbf_outd(p, "fsf_prot_status_qual", r->fsf_prot_status_qual,
318
		      FSF_PROT_STATUS_QUAL_SIZE, 0, FSF_PROT_STATUS_QUAL_SIZE);
319
	zfcp_dbf_outd(p, "fsf_status_qual", r->fsf_status_qual,
320
		      FSF_STATUS_QUALIFIER_SIZE, 0, FSF_STATUS_QUALIFIER_SIZE);
321 322
	zfcp_dbf_out(p, "fsf_req_status", "0x%08x", r->fsf_req_status);
	zfcp_dbf_out(p, "sbal_first", "0x%02x", r->sbal_first);
323
	zfcp_dbf_out(p, "sbal_last", "0x%02x", r->sbal_last);
324
	zfcp_dbf_out(p, "sbal_response", "0x%02x", r->sbal_response);
325
	zfcp_dbf_out(p, "pool", "0x%02x", r->pool);
326 327

	switch (r->fsf_command) {
328
	case FSF_QTCB_FCP_CMND:
329
		if (r->fsf_req_status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT)
330
			break;
331
		zfcp_dbf_out(p, "data_direction", "0x%04x", r->u.fcp.data_dir);
332 333
		zfcp_dbf_out(p, "scsi_cmnd", "0x%0Lx", r->u.fcp.cmnd);
		zfcp_dbf_out(p, "scsi_serial", "0x%016Lx", r->u.fcp.serial);
334
		*p += sprintf(*p, "\n");
335 336 337 338 339
		break;

	case FSF_QTCB_OPEN_PORT_WITH_DID:
	case FSF_QTCB_CLOSE_PORT:
	case FSF_QTCB_CLOSE_PHYSICAL_PORT:
340 341 342
		zfcp_dbf_out(p, "wwpn", "0x%016Lx", r->u.port.wwpn);
		zfcp_dbf_out(p, "d_id", "0x%06x", r->u.port.d_id);
		zfcp_dbf_out(p, "port_handle", "0x%08x", r->u.port.port_handle);
343 344 345 346
		break;

	case FSF_QTCB_OPEN_LUN:
	case FSF_QTCB_CLOSE_LUN:
347 348 349 350
		zfcp_dbf_out(p, "wwpn", "0x%016Lx", r->u.unit.wwpn);
		zfcp_dbf_out(p, "fcp_lun", "0x%016Lx", r->u.unit.fcp_lun);
		zfcp_dbf_out(p, "port_handle", "0x%08x", r->u.unit.port_handle);
		zfcp_dbf_out(p, "lun_handle", "0x%08x", r->u.unit.lun_handle);
351 352 353
		break;

	case FSF_QTCB_SEND_ELS:
354
		zfcp_dbf_out(p, "d_id", "0x%06x", r->u.els.d_id);
355 356 357 358 359 360 361 362 363 364 365 366
		break;

	case FSF_QTCB_ABORT_FCP_CMND:
	case FSF_QTCB_SEND_GENERIC:
	case FSF_QTCB_EXCHANGE_CONFIG_DATA:
	case FSF_QTCB_EXCHANGE_PORT_DATA:
	case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
	case FSF_QTCB_UPLOAD_CONTROL_FILE:
		break;
	}
}

S
Swen Schillig 已提交
367 368
static void zfcp_dbf_hba_view_status(char **p,
				     struct zfcp_dbf_hba_record_status *r)
369
{
370 371 372 373
	zfcp_dbf_out(p, "failed", "0x%02x", r->failed);
	zfcp_dbf_out(p, "status_type", "0x%08x", r->status_type);
	zfcp_dbf_out(p, "status_subtype", "0x%08x", r->status_subtype);
	zfcp_dbf_outd(p, "queue_designator", (char *)&r->queue_designator,
374 375
		      sizeof(struct fsf_queue_designator), 0,
		      sizeof(struct fsf_queue_designator));
376
	zfcp_dbf_outd(p, "payload", (char *)&r->payload, r->payload_size, 0,
377
		      r->payload_size);
378 379
}

S
Swen Schillig 已提交
380
static void zfcp_dbf_hba_view_qdio(char **p, struct zfcp_dbf_hba_record_qdio *r)
381
{
382 383 384
	zfcp_dbf_out(p, "qdio_error", "0x%08x", r->qdio_error);
	zfcp_dbf_out(p, "sbal_index", "0x%02x", r->sbal_index);
	zfcp_dbf_out(p, "sbal_count", "0x%02x", r->sbal_count);
385 386
}

S
Swen Schillig 已提交
387
static void zfcp_dbf_hba_view_berr(char **p, struct fsf_bit_error_payload *r)
388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410
{
	zfcp_dbf_out(p, "link_failures", "%d", r->link_failure_error_count);
	zfcp_dbf_out(p, "loss_of_sync_err", "%d", r->loss_of_sync_error_count);
	zfcp_dbf_out(p, "loss_of_sig_err", "%d", r->loss_of_signal_error_count);
	zfcp_dbf_out(p, "prim_seq_err", "%d",
		     r->primitive_sequence_error_count);
	zfcp_dbf_out(p, "inval_trans_word_err", "%d",
		     r->invalid_transmission_word_error_count);
	zfcp_dbf_out(p, "CRC_errors", "%d", r->crc_error_count);
	zfcp_dbf_out(p, "prim_seq_event_to", "%d",
		     r->primitive_sequence_event_timeout_count);
	zfcp_dbf_out(p, "elast_buf_overrun_err", "%d",
		     r->elastic_buffer_overrun_error_count);
	zfcp_dbf_out(p, "adv_rec_buf2buf_cred", "%d",
		     r->advertised_receive_b2b_credit);
	zfcp_dbf_out(p, "curr_rec_buf2buf_cred", "%d",
		     r->current_receive_b2b_credit);
	zfcp_dbf_out(p, "adv_trans_buf2buf_cred", "%d",
		     r->advertised_transmit_b2b_credit);
	zfcp_dbf_out(p, "curr_trans_buf2buf_cred", "%d",
		     r->current_transmit_b2b_credit);
}

S
Swen Schillig 已提交
411
static int zfcp_dbf_hba_view_format(debug_info_t *id, struct debug_view *view,
412
				    char *out_buf, const char *in_buf)
413
{
S
Swen Schillig 已提交
414
	struct zfcp_dbf_hba_record *r = (struct zfcp_dbf_hba_record *)in_buf;
415
	char *p = out_buf;
416

417
	if (strncmp(r->tag, "dump", ZFCP_DBF_TAG_SIZE) == 0)
418 419
		return 0;

420 421 422 423 424
	zfcp_dbf_tag(&p, "tag", r->tag);
	if (isalpha(r->tag2[0]))
		zfcp_dbf_tag(&p, "tag2", r->tag2);

	if (strncmp(r->tag, "resp", ZFCP_DBF_TAG_SIZE) == 0)
S
Swen Schillig 已提交
425
		zfcp_dbf_hba_view_response(&p, &r->u.response);
426
	else if (strncmp(r->tag, "stat", ZFCP_DBF_TAG_SIZE) == 0)
S
Swen Schillig 已提交
427
		zfcp_dbf_hba_view_status(&p, &r->u.status);
428
	else if (strncmp(r->tag, "qdio", ZFCP_DBF_TAG_SIZE) == 0)
S
Swen Schillig 已提交
429
		zfcp_dbf_hba_view_qdio(&p, &r->u.qdio);
430
	else if (strncmp(r->tag, "berr", ZFCP_DBF_TAG_SIZE) == 0)
S
Swen Schillig 已提交
431
		zfcp_dbf_hba_view_berr(&p, &r->u.berr);
432

433 434
	if (strncmp(r->tag, "resp", ZFCP_DBF_TAG_SIZE) != 0)
		p += sprintf(p, "\n");
435
	return p - out_buf;
436 437
}

S
Swen Schillig 已提交
438 439 440 441
static struct debug_view zfcp_dbf_hba_view = {
	.name = "structured",
	.header_proc = zfcp_dbf_view_header,
	.format_proc = zfcp_dbf_hba_view_format,
442 443
};

S
Swen Schillig 已提交
444
static const char *zfcp_dbf_rec_tags[] = {
445
	[ZFCP_REC_DBF_ID_THREAD] = "thread",
446
	[ZFCP_REC_DBF_ID_TARGET] = "target",
447
	[ZFCP_REC_DBF_ID_TRIGGER] = "trigger",
448
	[ZFCP_REC_DBF_ID_ACTION] = "action",
449 450
};

S
Swen Schillig 已提交
451
static int zfcp_dbf_rec_view_format(debug_info_t *id, struct debug_view *view,
452 453
				    char *buf, const char *_rec)
{
S
Swen Schillig 已提交
454
	struct zfcp_dbf_rec_record *r = (struct zfcp_dbf_rec_record *)_rec;
455
	char *p = buf;
456
	char hint[ZFCP_DBF_ID_SIZE + 1];
457

458 459
	memcpy(hint, r->id2, ZFCP_DBF_ID_SIZE);
	hint[ZFCP_DBF_ID_SIZE] = 0;
S
Swen Schillig 已提交
460
	zfcp_dbf_outs(&p, "tag", zfcp_dbf_rec_tags[r->id]);
461
	zfcp_dbf_outs(&p, "hint", hint);
462
	switch (r->id) {
463 464 465 466 467
	case ZFCP_REC_DBF_ID_THREAD:
		zfcp_dbf_out(&p, "total", "%d", r->u.thread.total);
		zfcp_dbf_out(&p, "ready", "%d", r->u.thread.ready);
		zfcp_dbf_out(&p, "running", "%d", r->u.thread.running);
		break;
468 469 470 471 472 473 474 475
	case ZFCP_REC_DBF_ID_TARGET:
		zfcp_dbf_out(&p, "reference", "0x%016Lx", r->u.target.ref);
		zfcp_dbf_out(&p, "status", "0x%08x", r->u.target.status);
		zfcp_dbf_out(&p, "erp_count", "%d", r->u.target.erp_count);
		zfcp_dbf_out(&p, "d_id", "0x%06x", r->u.target.d_id);
		zfcp_dbf_out(&p, "wwpn", "0x%016Lx", r->u.target.wwpn);
		zfcp_dbf_out(&p, "fcp_lun", "0x%016Lx", r->u.target.fcp_lun);
		break;
476 477 478 479 480 481 482 483 484
	case ZFCP_REC_DBF_ID_TRIGGER:
		zfcp_dbf_out(&p, "reference", "0x%016Lx", r->u.trigger.ref);
		zfcp_dbf_out(&p, "erp_action", "0x%016Lx", r->u.trigger.action);
		zfcp_dbf_out(&p, "requested", "%d", r->u.trigger.want);
		zfcp_dbf_out(&p, "executed", "%d", r->u.trigger.need);
		zfcp_dbf_out(&p, "wwpn", "0x%016Lx", r->u.trigger.wwpn);
		zfcp_dbf_out(&p, "fcp_lun", "0x%016Lx", r->u.trigger.fcp_lun);
		zfcp_dbf_out(&p, "adapter_status", "0x%08x", r->u.trigger.as);
		zfcp_dbf_out(&p, "port_status", "0x%08x", r->u.trigger.ps);
485
		zfcp_dbf_out(&p, "lun_status", "0x%08x", r->u.trigger.ls);
486
		break;
487 488 489 490 491 492
	case ZFCP_REC_DBF_ID_ACTION:
		zfcp_dbf_out(&p, "erp_action", "0x%016Lx", r->u.action.action);
		zfcp_dbf_out(&p, "fsf_req", "0x%016Lx", r->u.action.fsf_req);
		zfcp_dbf_out(&p, "status", "0x%08Lx", r->u.action.status);
		zfcp_dbf_out(&p, "step", "0x%08Lx", r->u.action.step);
		break;
493
	}
494 495
	p += sprintf(p, "\n");
	return p - buf;
496 497
}

S
Swen Schillig 已提交
498 499 500 501
static struct debug_view zfcp_dbf_rec_view = {
	.name = "structured",
	.header_proc = zfcp_dbf_view_header,
	.format_proc = zfcp_dbf_rec_view_format,
502 503
};

504
/**
S
Swen Schillig 已提交
505
 * zfcp_dbf_rec_thread - trace event related to recovery thread operation
506
 * @id2: identifier for event
S
Swen Schillig 已提交
507
 * @dbf: reference to dbf structure
508
 * This function assumes that the caller is holding erp_lock.
509
 */
S
Swen Schillig 已提交
510
void zfcp_dbf_rec_thread(char *id2, struct zfcp_dbf *dbf)
511
{
S
Swen Schillig 已提交
512 513
	struct zfcp_adapter *adapter = dbf->adapter;
	struct zfcp_dbf_rec_record *r = &dbf->rec_buf;
514 515 516 517 518 519 520 521 522 523
	unsigned long flags = 0;
	struct list_head *entry;
	unsigned ready = 0, running = 0, total;

	list_for_each(entry, &adapter->erp_ready_head)
		ready++;
	list_for_each(entry, &adapter->erp_running_head)
		running++;
	total = adapter->erp_total_count;

S
Swen Schillig 已提交
524
	spin_lock_irqsave(&dbf->rec_lock, flags);
525 526
	memset(r, 0, sizeof(*r));
	r->id = ZFCP_REC_DBF_ID_THREAD;
527
	memcpy(r->id2, id2, ZFCP_DBF_ID_SIZE);
528 529 530
	r->u.thread.total = total;
	r->u.thread.ready = ready;
	r->u.thread.running = running;
S
Swen Schillig 已提交
531 532
	debug_event(dbf->rec, 6, r, sizeof(*r));
	spin_unlock_irqrestore(&dbf->rec_lock, flags);
533 534
}

535
/**
S
Swen Schillig 已提交
536
 * zfcp_dbf_rec_thread - trace event related to recovery thread operation
537 538 539 540
 * @id2: identifier for event
 * @adapter: adapter
 * This function assumes that the caller does not hold erp_lock.
 */
S
Swen Schillig 已提交
541
void zfcp_dbf_rec_thread_lock(char *id2, struct zfcp_dbf *dbf)
542
{
S
Swen Schillig 已提交
543
	struct zfcp_adapter *adapter = dbf->adapter;
544 545 546
	unsigned long flags;

	read_lock_irqsave(&adapter->erp_lock, flags);
S
Swen Schillig 已提交
547
	zfcp_dbf_rec_thread(id2, dbf);
548 549 550
	read_unlock_irqrestore(&adapter->erp_lock, flags);
}

S
Swen Schillig 已提交
551 552 553
static void zfcp_dbf_rec_target(char *id2, void *ref, struct zfcp_dbf *dbf,
				atomic_t *status, atomic_t *erp_count, u64 wwpn,
				u32 d_id, u64 fcp_lun)
554
{
S
Swen Schillig 已提交
555
	struct zfcp_dbf_rec_record *r = &dbf->rec_buf;
556 557
	unsigned long flags;

S
Swen Schillig 已提交
558
	spin_lock_irqsave(&dbf->rec_lock, flags);
559 560
	memset(r, 0, sizeof(*r));
	r->id = ZFCP_REC_DBF_ID_TARGET;
561
	memcpy(r->id2, id2, ZFCP_DBF_ID_SIZE);
562
	r->u.target.ref = (unsigned long)ref;
563 564 565 566 567
	r->u.target.status = atomic_read(status);
	r->u.target.wwpn = wwpn;
	r->u.target.d_id = d_id;
	r->u.target.fcp_lun = fcp_lun;
	r->u.target.erp_count = atomic_read(erp_count);
S
Swen Schillig 已提交
568 569
	debug_event(dbf->rec, 3, r, sizeof(*r));
	spin_unlock_irqrestore(&dbf->rec_lock, flags);
570 571 572
}

/**
S
Swen Schillig 已提交
573
 * zfcp_dbf_rec_adapter - trace event for adapter state change
574 575
 * @id: identifier for trigger of state change
 * @ref: additional reference (e.g. request)
S
Swen Schillig 已提交
576
 * @dbf: reference to dbf structure
577
 */
S
Swen Schillig 已提交
578
void zfcp_dbf_rec_adapter(char *id, void *ref, struct zfcp_dbf *dbf)
579
{
S
Swen Schillig 已提交
580 581 582
	struct zfcp_adapter *adapter = dbf->adapter;

	zfcp_dbf_rec_target(id, ref, dbf, &adapter->status,
583 584
			    &adapter->erp_counter, 0, 0,
			    ZFCP_DBF_INVALID_LUN);
585 586 587
}

/**
S
Swen Schillig 已提交
588
 * zfcp_dbf_rec_port - trace event for port state change
589 590 591 592
 * @id: identifier for trigger of state change
 * @ref: additional reference (e.g. request)
 * @port: port
 */
S
Swen Schillig 已提交
593
void zfcp_dbf_rec_port(char *id, void *ref, struct zfcp_port *port)
594
{
S
Swen Schillig 已提交
595
	struct zfcp_dbf *dbf = port->adapter->dbf;
596

S
Swen Schillig 已提交
597
	zfcp_dbf_rec_target(id, ref, dbf, &port->status,
598 599
			    &port->erp_counter, port->wwpn, port->d_id,
			    ZFCP_DBF_INVALID_LUN);
600 601 602
}

/**
603
 * zfcp_dbf_rec_lun - trace event for LUN state change
604 605
 * @id: identifier for trigger of state change
 * @ref: additional reference (e.g. request)
606
 * @sdev: SCSI device
607
 */
608
void zfcp_dbf_rec_lun(char *id, void *ref, struct scsi_device *sdev)
609
{
610 611
	struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev);
	struct zfcp_port *port = zfcp_sdev->port;
S
Swen Schillig 已提交
612
	struct zfcp_dbf *dbf = port->adapter->dbf;
613

614 615 616
	zfcp_dbf_rec_target(id, ref, dbf, &zfcp_sdev->status,
			    &zfcp_sdev->erp_counter, port->wwpn, port->d_id,
			    zfcp_scsi_dev_lun(sdev));
617 618
}

619
/**
S
Swen Schillig 已提交
620
 * zfcp_dbf_rec_trigger - trace event for triggered error recovery
621 622 623 624 625 626 627
 * @id2: identifier for error recovery trigger
 * @ref: additional reference (e.g. request)
 * @want: originally requested error recovery action
 * @need: error recovery action actually initiated
 * @action: address of error recovery action struct
 * @adapter: adapter
 * @port: port
628
 * @sdev: SCSI device
629
 */
S
Swen Schillig 已提交
630 631
void zfcp_dbf_rec_trigger(char *id2, void *ref, u8 want, u8 need, void *action,
			  struct zfcp_adapter *adapter, struct zfcp_port *port,
632
			  struct scsi_device *sdev)
633
{
634
	struct zfcp_dbf *dbf = adapter->dbf;
S
Swen Schillig 已提交
635
	struct zfcp_dbf_rec_record *r = &dbf->rec_buf;
636 637
	unsigned long flags;

S
Swen Schillig 已提交
638
	spin_lock_irqsave(&dbf->rec_lock, flags);
639 640
	memset(r, 0, sizeof(*r));
	r->id = ZFCP_REC_DBF_ID_TRIGGER;
641
	memcpy(r->id2, id2, ZFCP_DBF_ID_SIZE);
642
	r->u.trigger.ref = (unsigned long)ref;
643 644
	r->u.trigger.want = want;
	r->u.trigger.need = need;
645
	r->u.trigger.action = (unsigned long)action;
646 647 648 649 650
	r->u.trigger.as = atomic_read(&adapter->status);
	if (port) {
		r->u.trigger.ps = atomic_read(&port->status);
		r->u.trigger.wwpn = port->wwpn;
	}
651 652 653 654
	if (sdev)
		r->u.trigger.ls = atomic_read(&sdev_to_zfcp(sdev)->status);
	r->u.trigger.fcp_lun = sdev ? zfcp_scsi_dev_lun(sdev) :
				      ZFCP_DBF_INVALID_LUN;
S
Swen Schillig 已提交
655 656
	debug_event(dbf->rec, action ? 1 : 4, r, sizeof(*r));
	spin_unlock_irqrestore(&dbf->rec_lock, flags);
657 658
}

659
/**
S
Swen Schillig 已提交
660
 * zfcp_dbf_rec_action - trace event showing progress of recovery action
661 662 663
 * @id2: identifier
 * @erp_action: error recovery action struct pointer
 */
S
Swen Schillig 已提交
664
void zfcp_dbf_rec_action(char *id2, struct zfcp_erp_action *erp_action)
665
{
S
Swen Schillig 已提交
666 667
	struct zfcp_dbf *dbf = erp_action->adapter->dbf;
	struct zfcp_dbf_rec_record *r = &dbf->rec_buf;
668 669
	unsigned long flags;

S
Swen Schillig 已提交
670
	spin_lock_irqsave(&dbf->rec_lock, flags);
671 672
	memset(r, 0, sizeof(*r));
	r->id = ZFCP_REC_DBF_ID_ACTION;
673
	memcpy(r->id2, id2, ZFCP_DBF_ID_SIZE);
674
	r->u.action.action = (unsigned long)erp_action;
675 676
	r->u.action.status = erp_action->status;
	r->u.action.step = erp_action->step;
677
	r->u.action.fsf_req = erp_action->fsf_req_id;
S
Swen Schillig 已提交
678 679
	debug_event(dbf->rec, 5, r, sizeof(*r));
	spin_unlock_irqrestore(&dbf->rec_lock, flags);
680 681
}

682
/**
S
Swen Schillig 已提交
683
 * zfcp_dbf_san_ct_request - trace event for issued CT request
684
 * @fsf_req: request containing issued CT data
685
 * @d_id: destination id where ct request is sent to
686
 */
687
void zfcp_dbf_san_ct_request(struct zfcp_fsf_req *fsf_req, u32 d_id)
688
{
689 690
	struct zfcp_fsf_ct_els *ct = (struct zfcp_fsf_ct_els *)fsf_req->data;
	struct zfcp_adapter *adapter = fsf_req->adapter;
691
	struct zfcp_dbf *dbf = adapter->dbf;
692
	struct fc_ct_hdr *hdr = sg_virt(ct->req);
S
Swen Schillig 已提交
693 694
	struct zfcp_dbf_san_record *r = &dbf->san_buf;
	struct zfcp_dbf_san_record_ct_request *oct = &r->u.ct_req;
695
	int level = 3;
696
	unsigned long flags;
697

S
Swen Schillig 已提交
698
	spin_lock_irqsave(&dbf->san_lock, flags);
699 700
	memset(r, 0, sizeof(*r));
	strncpy(r->tag, "octc", ZFCP_DBF_TAG_SIZE);
701
	r->fsf_reqid = fsf_req->req_id;
702
	r->fsf_seqno = fsf_req->seq_no;
703
	oct->d_id = d_id;
704 705 706 707 708 709 710
	oct->cmd_req_code = hdr->ct_cmd;
	oct->revision = hdr->ct_rev;
	oct->gs_type = hdr->ct_fs_type;
	oct->gs_subtype = hdr->ct_fs_subtype;
	oct->options = hdr->ct_options;
	oct->max_res_size = hdr->ct_mr_size;
	oct->len = min((int)ct->req->length - (int)sizeof(struct fc_ct_hdr),
711
		       ZFCP_DBF_SAN_MAX_PAYLOAD);
S
Swen Schillig 已提交
712 713
	debug_event(dbf->san, level, r, sizeof(*r));
	zfcp_dbf_hexdump(dbf->san, r, sizeof(*r), level,
714
			 (void *)hdr + sizeof(struct fc_ct_hdr), oct->len);
S
Swen Schillig 已提交
715
	spin_unlock_irqrestore(&dbf->san_lock, flags);
716 717
}

718
/**
S
Swen Schillig 已提交
719
 * zfcp_dbf_san_ct_response - trace event for completion of CT request
720 721
 * @fsf_req: request containing CT response
 */
S
Swen Schillig 已提交
722
void zfcp_dbf_san_ct_response(struct zfcp_fsf_req *fsf_req)
723
{
724 725
	struct zfcp_fsf_ct_els *ct = (struct zfcp_fsf_ct_els *)fsf_req->data;
	struct zfcp_adapter *adapter = fsf_req->adapter;
726
	struct fc_ct_hdr *hdr = sg_virt(ct->resp);
727
	struct zfcp_dbf *dbf = adapter->dbf;
S
Swen Schillig 已提交
728 729
	struct zfcp_dbf_san_record *r = &dbf->san_buf;
	struct zfcp_dbf_san_record_ct_response *rct = &r->u.ct_resp;
730
	int level = 3;
731
	unsigned long flags;
732

S
Swen Schillig 已提交
733
	spin_lock_irqsave(&dbf->san_lock, flags);
734 735
	memset(r, 0, sizeof(*r));
	strncpy(r->tag, "rctc", ZFCP_DBF_TAG_SIZE);
736
	r->fsf_reqid = fsf_req->req_id;
737
	r->fsf_seqno = fsf_req->seq_no;
738 739 740 741 742 743 744
	rct->cmd_rsp_code = hdr->ct_cmd;
	rct->revision = hdr->ct_rev;
	rct->reason_code = hdr->ct_reason;
	rct->expl = hdr->ct_explan;
	rct->vendor_unique = hdr->ct_vendor;
	rct->max_res_size = hdr->ct_mr_size;
	rct->len = min((int)ct->resp->length - (int)sizeof(struct fc_ct_hdr),
745
		       ZFCP_DBF_SAN_MAX_PAYLOAD);
S
Swen Schillig 已提交
746 747
	debug_event(dbf->san, level, r, sizeof(*r));
	zfcp_dbf_hexdump(dbf->san, r, sizeof(*r), level,
748
			 (void *)hdr + sizeof(struct fc_ct_hdr), rct->len);
S
Swen Schillig 已提交
749
	spin_unlock_irqrestore(&dbf->san_lock, flags);
750 751
}

S
Swen Schillig 已提交
752
static void zfcp_dbf_san_els(const char *tag, int level,
753 754
			     struct zfcp_fsf_req *fsf_req, u32 d_id,
			     void *buffer, int buflen)
755 756
{
	struct zfcp_adapter *adapter = fsf_req->adapter;
757
	struct zfcp_dbf *dbf = adapter->dbf;
S
Swen Schillig 已提交
758
	struct zfcp_dbf_san_record *rec = &dbf->san_buf;
759 760
	unsigned long flags;

S
Swen Schillig 已提交
761
	spin_lock_irqsave(&dbf->san_lock, flags);
762
	memset(rec, 0, sizeof(*rec));
763
	strncpy(rec->tag, tag, ZFCP_DBF_TAG_SIZE);
764
	rec->fsf_reqid = fsf_req->req_id;
765
	rec->fsf_seqno = fsf_req->seq_no;
766
	rec->u.els.d_id = d_id;
S
Swen Schillig 已提交
767 768
	debug_event(dbf->san, level, rec, sizeof(*rec));
	zfcp_dbf_hexdump(dbf->san, rec, sizeof(*rec), level,
769
			 buffer, min(buflen, ZFCP_DBF_SAN_MAX_PAYLOAD));
S
Swen Schillig 已提交
770
	spin_unlock_irqrestore(&dbf->san_lock, flags);
771 772
}

773
/**
S
Swen Schillig 已提交
774
 * zfcp_dbf_san_els_request - trace event for issued ELS
775 776
 * @fsf_req: request containing issued ELS
 */
S
Swen Schillig 已提交
777
void zfcp_dbf_san_els_request(struct zfcp_fsf_req *fsf_req)
778
{
779 780
	struct zfcp_fsf_ct_els *els = (struct zfcp_fsf_ct_els *)fsf_req->data;
	u32 d_id = ntoh24(fsf_req->qtcb->bottom.support.d_id);
781

782 783
	zfcp_dbf_san_els("oels", 2, fsf_req, d_id,
			 sg_virt(els->req), els->req->length);
784 785
}

786
/**
S
Swen Schillig 已提交
787
 * zfcp_dbf_san_els_response - trace event for completed ELS
788 789
 * @fsf_req: request containing ELS response
 */
S
Swen Schillig 已提交
790
void zfcp_dbf_san_els_response(struct zfcp_fsf_req *fsf_req)
791
{
792 793
	struct zfcp_fsf_ct_els *els = (struct zfcp_fsf_ct_els *)fsf_req->data;
	u32 d_id = ntoh24(fsf_req->qtcb->bottom.support.d_id);
794

795 796
	zfcp_dbf_san_els("rels", 2, fsf_req, d_id,
			       sg_virt(els->resp), els->resp->length);
797 798
}

799
/**
S
Swen Schillig 已提交
800
 * zfcp_dbf_san_incoming_els - trace event for incomig ELS
801 802
 * @fsf_req: request containing unsolicited status buffer with incoming ELS
 */
S
Swen Schillig 已提交
803
void zfcp_dbf_san_incoming_els(struct zfcp_fsf_req *fsf_req)
804
{
805 806 807 808 809
	struct fsf_status_read_buffer *buf =
			(struct fsf_status_read_buffer *)fsf_req->data;
	int length = (int)buf->length -
		     (int)((void *)&buf->payload - (void *)buf);

810
	zfcp_dbf_san_els("iels", 1, fsf_req, ntoh24(buf->d_id),
811
			       (void *)buf->payload.data, length);
812 813
}

S
Swen Schillig 已提交
814
static int zfcp_dbf_san_view_format(debug_info_t *id, struct debug_view *view,
815
				    char *out_buf, const char *in_buf)
816
{
S
Swen Schillig 已提交
817
	struct zfcp_dbf_san_record *r = (struct zfcp_dbf_san_record *)in_buf;
818
	char *p = out_buf;
819

820
	if (strncmp(r->tag, "dump", ZFCP_DBF_TAG_SIZE) == 0)
821 822
		return 0;

823
	zfcp_dbf_tag(&p, "tag", r->tag);
824 825 826 827
	zfcp_dbf_out(&p, "fsf_reqid", "0x%0Lx", r->fsf_reqid);
	zfcp_dbf_out(&p, "fsf_seqno", "0x%08x", r->fsf_seqno);

	if (strncmp(r->tag, "octc", ZFCP_DBF_TAG_SIZE) == 0) {
S
Swen Schillig 已提交
828
		struct zfcp_dbf_san_record_ct_request *ct = &r->u.ct_req;
829
		zfcp_dbf_out(&p, "d_id", "0x%06x", ct->d_id);
830 831 832 833 834 835
		zfcp_dbf_out(&p, "cmd_req_code", "0x%04x", ct->cmd_req_code);
		zfcp_dbf_out(&p, "revision", "0x%02x", ct->revision);
		zfcp_dbf_out(&p, "gs_type", "0x%02x", ct->gs_type);
		zfcp_dbf_out(&p, "gs_subtype", "0x%02x", ct->gs_subtype);
		zfcp_dbf_out(&p, "options", "0x%02x", ct->options);
		zfcp_dbf_out(&p, "max_res_size", "0x%04x", ct->max_res_size);
836
	} else if (strncmp(r->tag, "rctc", ZFCP_DBF_TAG_SIZE) == 0) {
S
Swen Schillig 已提交
837
		struct zfcp_dbf_san_record_ct_response *ct = &r->u.ct_resp;
838 839 840 841 842
		zfcp_dbf_out(&p, "cmd_rsp_code", "0x%04x", ct->cmd_rsp_code);
		zfcp_dbf_out(&p, "revision", "0x%02x", ct->revision);
		zfcp_dbf_out(&p, "reason_code", "0x%02x", ct->reason_code);
		zfcp_dbf_out(&p, "reason_code_expl", "0x%02x", ct->expl);
		zfcp_dbf_out(&p, "vendor_unique", "0x%02x", ct->vendor_unique);
843
		zfcp_dbf_out(&p, "max_res_size", "0x%04x", ct->max_res_size);
844 845 846
	} else if (strncmp(r->tag, "oels", ZFCP_DBF_TAG_SIZE) == 0 ||
		   strncmp(r->tag, "rels", ZFCP_DBF_TAG_SIZE) == 0 ||
		   strncmp(r->tag, "iels", ZFCP_DBF_TAG_SIZE) == 0) {
S
Swen Schillig 已提交
847
		struct zfcp_dbf_san_record_els *els = &r->u.els;
848
		zfcp_dbf_out(&p, "d_id", "0x%06x", els->d_id);
849
	}
850
	return p - out_buf;
851 852
}

S
Swen Schillig 已提交
853 854 855 856
static struct debug_view zfcp_dbf_san_view = {
	.name = "structured",
	.header_proc = zfcp_dbf_view_header,
	.format_proc = zfcp_dbf_san_view_format,
857 858
};

S
Swen Schillig 已提交
859 860 861
void _zfcp_dbf_scsi(const char *tag, const char *tag2, int level,
		    struct zfcp_dbf *dbf, struct scsi_cmnd *scsi_cmnd,
		    struct zfcp_fsf_req *fsf_req, unsigned long old_req_id)
862
{
S
Swen Schillig 已提交
863
	struct zfcp_dbf_scsi_record *rec = &dbf->scsi_buf;
864 865
	struct zfcp_dbf_dump *dump = (struct zfcp_dbf_dump *)rec;
	unsigned long flags;
866 867 868
	struct fcp_resp_with_ext *fcp_rsp;
	struct fcp_resp_rsp_info *fcp_rsp_info = NULL;
	char *fcp_sns_info = NULL;
869 870
	int offset = 0, buflen = 0;

S
Swen Schillig 已提交
871
	spin_lock_irqsave(&dbf->scsi_lock, flags);
872
	do {
873
		memset(rec, 0, sizeof(*rec));
874 875 876
		if (offset == 0) {
			strncpy(rec->tag, tag, ZFCP_DBF_TAG_SIZE);
			strncpy(rec->tag2, tag2, ZFCP_DBF_TAG_SIZE);
877 878 879 880 881 882 883 884
			if (scsi_cmnd != NULL) {
				if (scsi_cmnd->device) {
					rec->scsi_id = scsi_cmnd->device->id;
					rec->scsi_lun = scsi_cmnd->device->lun;
				}
				rec->scsi_result = scsi_cmnd->result;
				rec->scsi_cmnd = (unsigned long)scsi_cmnd;
				rec->scsi_serial = scsi_cmnd->serial_number;
885
				memcpy(rec->scsi_opcode, scsi_cmnd->cmnd,
886 887 888 889
					min((int)scsi_cmnd->cmd_len,
						ZFCP_DBF_SCSI_OPCODE));
				rec->scsi_retries = scsi_cmnd->retries;
				rec->scsi_allowed = scsi_cmnd->allowed;
890 891
			}
			if (fsf_req != NULL) {
892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907
				fcp_rsp = (struct fcp_resp_with_ext *)
					&(fsf_req->qtcb->bottom.io.fcp_rsp);
				fcp_rsp_info = (struct fcp_resp_rsp_info *)
					&fcp_rsp[1];
				fcp_sns_info = (char *) &fcp_rsp[1];
				if (fcp_rsp->resp.fr_flags & FCP_RSP_LEN_VAL)
					fcp_sns_info += fcp_rsp->ext.fr_sns_len;

				rec->rsp_validity = fcp_rsp->resp.fr_flags;
				rec->rsp_scsi_status = fcp_rsp->resp.fr_status;
				rec->rsp_resid = fcp_rsp->ext.fr_resid;
				if (fcp_rsp->resp.fr_flags & FCP_RSP_LEN_VAL)
					rec->rsp_code = fcp_rsp_info->rsp_code;
				if (fcp_rsp->resp.fr_flags & FCP_SNS_LEN_VAL) {
					buflen = min(fcp_rsp->ext.fr_sns_len,
					   (u32)ZFCP_DBF_SCSI_MAX_FCP_SNS_INFO);
908 909
					rec->sns_info_len = buflen;
					memcpy(rec->sns_info, fcp_sns_info,
910 911 912 913 914 915
					       min(buflen,
						   ZFCP_DBF_SCSI_FCP_SNS_INFO));
					offset += min(buflen,
						      ZFCP_DBF_SCSI_FCP_SNS_INFO);
				}

916
				rec->fsf_reqid = fsf_req->req_id;
917 918 919
				rec->fsf_seqno = fsf_req->seq_no;
				rec->fsf_issued = fsf_req->issued;
			}
920
			rec->old_fsf_reqid = old_req_id;
921 922 923 924 925 926
		} else {
			strncpy(dump->tag, "dump", ZFCP_DBF_TAG_SIZE);
			dump->total_size = buflen;
			dump->offset = offset;
			dump->size = min(buflen - offset,
					 (int)sizeof(struct
S
Swen Schillig 已提交
927
						     zfcp_dbf_scsi_record) -
928 929 930 931
					 (int)sizeof(struct zfcp_dbf_dump));
			memcpy(dump->data, fcp_sns_info + offset, dump->size);
			offset += dump->size;
		}
S
Swen Schillig 已提交
932
		debug_event(dbf->scsi, level, rec, sizeof(*rec));
933
	} while (offset < buflen);
S
Swen Schillig 已提交
934
	spin_unlock_irqrestore(&dbf->scsi_lock, flags);
935 936
}

S
Swen Schillig 已提交
937
static int zfcp_dbf_scsi_view_format(debug_info_t *id, struct debug_view *view,
938
				     char *out_buf, const char *in_buf)
939
{
S
Swen Schillig 已提交
940
	struct zfcp_dbf_scsi_record *r = (struct zfcp_dbf_scsi_record *)in_buf;
941
	struct timespec t;
942
	char *p = out_buf;
943

944
	if (strncmp(r->tag, "dump", ZFCP_DBF_TAG_SIZE) == 0)
945 946
		return 0;

947 948
	zfcp_dbf_tag(&p, "tag", r->tag);
	zfcp_dbf_tag(&p, "tag2", r->tag2);
949 950 951 952 953
	zfcp_dbf_out(&p, "scsi_id", "0x%08x", r->scsi_id);
	zfcp_dbf_out(&p, "scsi_lun", "0x%08x", r->scsi_lun);
	zfcp_dbf_out(&p, "scsi_result", "0x%08x", r->scsi_result);
	zfcp_dbf_out(&p, "scsi_cmnd", "0x%0Lx", r->scsi_cmnd);
	zfcp_dbf_out(&p, "scsi_serial", "0x%016Lx", r->scsi_serial);
954 955
	zfcp_dbf_outd(&p, "scsi_opcode", r->scsi_opcode, ZFCP_DBF_SCSI_OPCODE,
		      0, ZFCP_DBF_SCSI_OPCODE);
956 957 958
	zfcp_dbf_out(&p, "scsi_retries", "0x%02x", r->scsi_retries);
	zfcp_dbf_out(&p, "scsi_allowed", "0x%02x", r->scsi_allowed);
	if (strncmp(r->tag, "abrt", ZFCP_DBF_TAG_SIZE) == 0)
959
		zfcp_dbf_out(&p, "old_fsf_reqid", "0x%0Lx", r->old_fsf_reqid);
960 961
	zfcp_dbf_out(&p, "fsf_reqid", "0x%0Lx", r->fsf_reqid);
	zfcp_dbf_out(&p, "fsf_seqno", "0x%08x", r->fsf_seqno);
962
	stck_to_timespec(r->fsf_issued, &t);
963 964 965
	zfcp_dbf_out(&p, "fsf_issued", "%011lu:%06lu", t.tv_sec, t.tv_nsec);

	if (strncmp(r->tag, "rslt", ZFCP_DBF_TAG_SIZE) == 0) {
966 967 968 969 970 971 972 973
		zfcp_dbf_out(&p, "fcp_rsp_validity", "0x%02x", r->rsp_validity);
		zfcp_dbf_out(&p, "fcp_rsp_scsi_status", "0x%02x",
			     r->rsp_scsi_status);
		zfcp_dbf_out(&p, "fcp_rsp_resid", "0x%08x", r->rsp_resid);
		zfcp_dbf_out(&p, "fcp_rsp_code", "0x%08x", r->rsp_code);
		zfcp_dbf_out(&p, "fcp_sns_info_len", "0x%08x", r->sns_info_len);
		zfcp_dbf_outd(&p, "fcp_sns_info", r->sns_info,
			      min((int)r->sns_info_len,
974
			      ZFCP_DBF_SCSI_FCP_SNS_INFO), 0,
975
			      r->sns_info_len);
976
	}
977 978
	p += sprintf(p, "\n");
	return p - out_buf;
979 980
}

S
Swen Schillig 已提交
981 982 983 984
static struct debug_view zfcp_dbf_scsi_view = {
	.name = "structured",
	.header_proc = zfcp_dbf_view_header,
	.format_proc = zfcp_dbf_scsi_view_format,
985 986
};

987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002
static debug_info_t *zfcp_dbf_reg(const char *name, int level,
				  struct debug_view *view, int size)
{
	struct debug_info *d;

	d = debug_register(name, dbfsize, level, size);
	if (!d)
		return NULL;

	debug_register_view(d, &debug_hex_ascii_view);
	debug_register_view(d, view);
	debug_set_level(d, level);

	return d;
}

1003 1004 1005 1006 1007
/**
 * zfcp_adapter_debug_register - registers debug feature for an adapter
 * @adapter: pointer to adapter for which debug features should be registered
 * return: -ENOMEM on error, 0 otherwise
 */
S
Swen Schillig 已提交
1008
int zfcp_dbf_adapter_register(struct zfcp_adapter *adapter)
1009 1010
{
	char dbf_name[DEBUG_MAX_NAME_LEN];
1011 1012
	struct zfcp_dbf *dbf;

1013
	dbf = kzalloc(sizeof(struct zfcp_dbf), GFP_KERNEL);
1014 1015 1016
	if (!dbf)
		return -ENOMEM;

S
Swen Schillig 已提交
1017 1018 1019 1020 1021 1022
	dbf->adapter = adapter;

	spin_lock_init(&dbf->hba_lock);
	spin_lock_init(&dbf->san_lock);
	spin_lock_init(&dbf->scsi_lock);
	spin_lock_init(&dbf->rec_lock);
1023

1024
	/* debug feature area which records recovery activity */
C
Christof Schmitt 已提交
1025
	sprintf(dbf_name, "zfcp_%s_rec", dev_name(&adapter->ccw_device->dev));
S
Swen Schillig 已提交
1026 1027 1028 1029
	dbf->rec = zfcp_dbf_reg(dbf_name, 3, &zfcp_dbf_rec_view,
				sizeof(struct zfcp_dbf_rec_record));
	if (!dbf->rec)
		goto err_out;
1030

1031
	/* debug feature area which records HBA (FSF and QDIO) conditions */
C
Christof Schmitt 已提交
1032
	sprintf(dbf_name, "zfcp_%s_hba", dev_name(&adapter->ccw_device->dev));
S
Swen Schillig 已提交
1033 1034 1035 1036
	dbf->hba = zfcp_dbf_reg(dbf_name, 3, &zfcp_dbf_hba_view,
				sizeof(struct zfcp_dbf_hba_record));
	if (!dbf->hba)
		goto err_out;
1037 1038

	/* debug feature area which records SAN command failures and recovery */
C
Christof Schmitt 已提交
1039
	sprintf(dbf_name, "zfcp_%s_san", dev_name(&adapter->ccw_device->dev));
S
Swen Schillig 已提交
1040 1041 1042 1043
	dbf->san = zfcp_dbf_reg(dbf_name, 6, &zfcp_dbf_san_view,
				sizeof(struct zfcp_dbf_san_record));
	if (!dbf->san)
		goto err_out;
1044 1045

	/* debug feature area which records SCSI command failures and recovery */
C
Christof Schmitt 已提交
1046
	sprintf(dbf_name, "zfcp_%s_scsi", dev_name(&adapter->ccw_device->dev));
S
Swen Schillig 已提交
1047 1048 1049 1050
	dbf->scsi = zfcp_dbf_reg(dbf_name, 3, &zfcp_dbf_scsi_view,
				 sizeof(struct zfcp_dbf_scsi_record));
	if (!dbf->scsi)
		goto err_out;
1051

1052
	adapter->dbf = dbf;
1053 1054
	return 0;

S
Swen Schillig 已提交
1055 1056
err_out:
	zfcp_dbf_adapter_unregister(dbf);
1057 1058 1059 1060 1061
	return -ENOMEM;
}

/**
 * zfcp_adapter_debug_unregister - unregisters debug feature for an adapter
S
Swen Schillig 已提交
1062
 * @dbf: pointer to dbf for which debug features should be unregistered
1063
 */
S
Swen Schillig 已提交
1064
void zfcp_dbf_adapter_unregister(struct zfcp_dbf *dbf)
1065
{
1066 1067
	if (!dbf)
		return;
S
Swen Schillig 已提交
1068 1069 1070 1071 1072 1073
	debug_unregister(dbf->scsi);
	debug_unregister(dbf->san);
	debug_unregister(dbf->hba);
	debug_unregister(dbf->rec);
	dbf->adapter->dbf = NULL;
	kfree(dbf);
1074
}
S
Swen Schillig 已提交
1075