zfcp_dbf.c 29.6 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
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");
}

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

86 87
static int zfcp_dbf_view_header(debug_info_t *id, struct debug_view *view,
				int area, debug_entry_t *entry, char *out_buf)
88 89
{
	struct zfcp_dbf_dump *dump = (struct zfcp_dbf_dump *)DEBUG_DATA(entry);
90
	struct timespec t;
91
	char *p = out_buf;
92 93

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

S
Swen Schillig 已提交
107 108 109
void _zfcp_dbf_hba_fsf_response(const char *tag2, int level,
				struct zfcp_fsf_req *fsf_req,
				struct zfcp_dbf *dbf)
110 111 112
{
	struct fsf_qtcb *qtcb = fsf_req->qtcb;
	union fsf_prot_status_qual *prot_status_qual =
113
					&qtcb->prefix.prot_status_qual;
114 115 116 117 118
	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 已提交
119 120
	struct zfcp_dbf_hba_record *rec = &dbf->hba_buf;
	struct zfcp_dbf_hba_record_response *response = &rec->u.response;
121 122
	unsigned long flags;

S
Swen Schillig 已提交
123
	spin_lock_irqsave(&dbf->hba_lock, flags);
124
	memset(rec, 0, sizeof(*rec));
125
	strncpy(rec->tag, "resp", ZFCP_DBF_TAG_SIZE);
126
	strncpy(rec->tag2, tag2, ZFCP_DBF_TAG_SIZE);
127 128

	response->fsf_command = fsf_req->fsf_command;
129
	response->fsf_reqid = fsf_req->req_id;
130 131 132 133 134 135 136 137 138
	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;
139 140 141
	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;
142 143 144 145 146 147 148 149
	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;
150 151
		if (scsi_cmnd) {
			response->u.fcp.cmnd = (unsigned long)scsi_cmnd;
152 153
			response->u.fcp.data_dir =
				qtcb->bottom.io.data_direction;
154 155 156 157 158 159 160
		}
		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;
161 162 163
		response->u.port.wwpn = port->wwpn;
		response->u.port.d_id = port->d_id;
		response->u.port.port_handle = qtcb->header.port_handle;
164 165 166 167 168 169
		break;

	case FSF_QTCB_OPEN_LUN:
	case FSF_QTCB_CLOSE_LUN:
		unit = (struct zfcp_unit *)fsf_req->data;
		port = unit->port;
170 171 172 173
		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;
174 175 176 177
		break;

	case FSF_QTCB_SEND_ELS:
		send_els = (struct zfcp_send_els *)fsf_req->data;
178
		response->u.els.d_id = ntoh24(qtcb->bottom.support.d_id);
179 180 181 182 183 184 185 186 187 188 189
		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 已提交
190
	debug_event(dbf->hba, level, rec, sizeof(*rec));
191 192 193 194 195 196 197

	/* 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 已提交
198
		zfcp_dbf_hexdump(dbf->hba, rec, sizeof(*rec), level, buf,
199
				 len);
200 201
	}

S
Swen Schillig 已提交
202
	spin_unlock_irqrestore(&dbf->hba_lock, flags);
203 204
}

S
Swen Schillig 已提交
205 206
void _zfcp_dbf_hba_fsf_unsol(const char *tag, int level, struct zfcp_dbf *dbf,
			     struct fsf_status_read_buffer *status_buffer)
207
{
S
Swen Schillig 已提交
208
	struct zfcp_dbf_hba_record *rec = &dbf->hba_buf;
209 210
	unsigned long flags;

S
Swen Schillig 已提交
211
	spin_lock_irqsave(&dbf->hba_lock, flags);
212
	memset(rec, 0, sizeof(*rec));
213 214 215
	strncpy(rec->tag, "stat", ZFCP_DBF_TAG_SIZE);
	strncpy(rec->tag2, tag, ZFCP_DBF_TAG_SIZE);

S
Swen Schillig 已提交
216
	rec->u.status.failed = atomic_read(&dbf->adapter->stat_miss);
217
	if (status_buffer != NULL) {
218 219 220
		rec->u.status.status_type = status_buffer->status_type;
		rec->u.status.status_subtype = status_buffer->status_subtype;
		memcpy(&rec->u.status.queue_designator,
221 222 223 224 225
		       &status_buffer->queue_designator,
		       sizeof(struct fsf_queue_designator));

		switch (status_buffer->status_type) {
		case FSF_STATUS_READ_SENSE_DATA_AVAIL:
226
			rec->u.status.payload_size =
227 228 229 230
			    ZFCP_DBF_UNSOL_PAYLOAD_SENSE_DATA_AVAIL;
			break;

		case FSF_STATUS_READ_BIT_ERROR_THRESHOLD:
231
			rec->u.status.payload_size =
232 233 234 235
			    ZFCP_DBF_UNSOL_PAYLOAD_BIT_ERROR_THRESHOLD;
			break;

		case FSF_STATUS_READ_LINK_DOWN:
236 237 238
			switch (status_buffer->status_subtype) {
			case FSF_STATUS_READ_SUB_NO_PHYSICAL_LINK:
			case FSF_STATUS_READ_SUB_FDISC_FAILED:
239
				rec->u.status.payload_size =
240 241
					sizeof(struct fsf_link_down_info);
			}
242 243
			break;

244
		case FSF_STATUS_READ_FEATURE_UPDATE_ALERT:
245
			rec->u.status.payload_size =
246 247
			    ZFCP_DBF_UNSOL_PAYLOAD_FEATURE_UPDATE_ALERT;
			break;
248
		}
249 250
		memcpy(&rec->u.status.payload,
		       &status_buffer->payload, rec->u.status.payload_size);
251 252
	}

S
Swen Schillig 已提交
253 254
	debug_event(dbf->hba, level, rec, sizeof(*rec));
	spin_unlock_irqrestore(&dbf->hba_lock, flags);
255 256
}

257
/**
S
Swen Schillig 已提交
258
 * zfcp_dbf_hba_qdio - trace event for QDIO related failure
259
 * @qdio: qdio structure affected by this QDIO related event
260 261 262 263
 * @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 已提交
264 265
void zfcp_dbf_hba_qdio(struct zfcp_dbf *dbf, unsigned int qdio_error,
		       int sbal_index, int sbal_count)
266
{
S
Swen Schillig 已提交
267
	struct zfcp_dbf_hba_record *r = &dbf->hba_buf;
268 269
	unsigned long flags;

S
Swen Schillig 已提交
270
	spin_lock_irqsave(&dbf->hba_lock, flags);
271 272 273 274 275
	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 已提交
276 277
	debug_event(dbf->hba, 0, r, sizeof(*r));
	spin_unlock_irqrestore(&dbf->hba_lock, flags);
278 279
}

280
/**
S
Swen Schillig 已提交
281 282
 * zfcp_dbf_hba_berr - trace event for bit error threshold
 * @dbf: dbf structure affected by this QDIO related event
283 284
 * @req: fsf request
 */
S
Swen Schillig 已提交
285
void zfcp_dbf_hba_berr(struct zfcp_dbf *dbf, struct zfcp_fsf_req *req)
286
{
S
Swen Schillig 已提交
287
	struct zfcp_dbf_hba_record *r = &dbf->hba_buf;
288 289 290 291
	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 已提交
292
	spin_lock_irqsave(&dbf->hba_lock, flags);
293 294 295
	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 已提交
296 297
	debug_event(dbf->hba, 0, r, sizeof(*r));
	spin_unlock_irqrestore(&dbf->hba_lock, flags);
298
}
S
Swen Schillig 已提交
299 300
static void zfcp_dbf_hba_view_response(char **p,
				       struct zfcp_dbf_hba_record_response *r)
301
{
302
	struct timespec t;
303

304 305 306
	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);
307
	stck_to_timespec(r->fsf_issued, &t);
308 309 310 311
	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,
312
		      FSF_PROT_STATUS_QUAL_SIZE, 0, FSF_PROT_STATUS_QUAL_SIZE);
313
	zfcp_dbf_outd(p, "fsf_status_qual", r->fsf_status_qual,
314
		      FSF_STATUS_QUALIFIER_SIZE, 0, FSF_STATUS_QUALIFIER_SIZE);
315 316
	zfcp_dbf_out(p, "fsf_req_status", "0x%08x", r->fsf_req_status);
	zfcp_dbf_out(p, "sbal_first", "0x%02x", r->sbal_first);
317
	zfcp_dbf_out(p, "sbal_last", "0x%02x", r->sbal_last);
318
	zfcp_dbf_out(p, "sbal_response", "0x%02x", r->sbal_response);
319
	zfcp_dbf_out(p, "pool", "0x%02x", r->pool);
320 321

	switch (r->fsf_command) {
322
	case FSF_QTCB_FCP_CMND:
323
		if (r->fsf_req_status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT)
324
			break;
325
		zfcp_dbf_out(p, "data_direction", "0x%04x", r->u.fcp.data_dir);
326
		zfcp_dbf_out(p, "scsi_cmnd", "0x%0Lx", r->u.fcp.cmnd);
327
		*p += sprintf(*p, "\n");
328 329 330 331 332
		break;

	case FSF_QTCB_OPEN_PORT_WITH_DID:
	case FSF_QTCB_CLOSE_PORT:
	case FSF_QTCB_CLOSE_PHYSICAL_PORT:
333 334 335
		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);
336 337 338 339
		break;

	case FSF_QTCB_OPEN_LUN:
	case FSF_QTCB_CLOSE_LUN:
340 341 342 343
		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);
344 345 346
		break;

	case FSF_QTCB_SEND_ELS:
347
		zfcp_dbf_out(p, "d_id", "0x%06x", r->u.els.d_id);
348 349 350 351 352 353 354 355 356 357 358 359
		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 已提交
360 361
static void zfcp_dbf_hba_view_status(char **p,
				     struct zfcp_dbf_hba_record_status *r)
362
{
363 364 365 366
	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,
367 368
		      sizeof(struct fsf_queue_designator), 0,
		      sizeof(struct fsf_queue_designator));
369
	zfcp_dbf_outd(p, "payload", (char *)&r->payload, r->payload_size, 0,
370
		      r->payload_size);
371 372
}

S
Swen Schillig 已提交
373
static void zfcp_dbf_hba_view_qdio(char **p, struct zfcp_dbf_hba_record_qdio *r)
374
{
375 376 377
	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);
378 379
}

S
Swen Schillig 已提交
380
static void zfcp_dbf_hba_view_berr(char **p, struct fsf_bit_error_payload *r)
381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403
{
	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 已提交
404
static int zfcp_dbf_hba_view_format(debug_info_t *id, struct debug_view *view,
405
				    char *out_buf, const char *in_buf)
406
{
S
Swen Schillig 已提交
407
	struct zfcp_dbf_hba_record *r = (struct zfcp_dbf_hba_record *)in_buf;
408
	char *p = out_buf;
409

410
	if (strncmp(r->tag, "dump", ZFCP_DBF_TAG_SIZE) == 0)
411 412
		return 0;

413 414 415 416 417
	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 已提交
418
		zfcp_dbf_hba_view_response(&p, &r->u.response);
419
	else if (strncmp(r->tag, "stat", ZFCP_DBF_TAG_SIZE) == 0)
S
Swen Schillig 已提交
420
		zfcp_dbf_hba_view_status(&p, &r->u.status);
421
	else if (strncmp(r->tag, "qdio", ZFCP_DBF_TAG_SIZE) == 0)
S
Swen Schillig 已提交
422
		zfcp_dbf_hba_view_qdio(&p, &r->u.qdio);
423
	else if (strncmp(r->tag, "berr", ZFCP_DBF_TAG_SIZE) == 0)
S
Swen Schillig 已提交
424
		zfcp_dbf_hba_view_berr(&p, &r->u.berr);
425

426 427
	if (strncmp(r->tag, "resp", ZFCP_DBF_TAG_SIZE) != 0)
		p += sprintf(p, "\n");
428
	return p - out_buf;
429 430
}

S
Swen Schillig 已提交
431 432 433 434
static struct debug_view zfcp_dbf_hba_view = {
	.name = "structured",
	.header_proc = zfcp_dbf_view_header,
	.format_proc = zfcp_dbf_hba_view_format,
435 436
};

437 438 439 440
static void zfcp_dbf_set_common(struct zfcp_dbf_rec *rec,
				struct zfcp_adapter *adapter,
				struct zfcp_port *port,
				struct scsi_device *sdev)
441
{
442 443 444 445 446 447 448 449 450
	rec->adapter_status = atomic_read(&adapter->status);
	if (port) {
		rec->port_status = atomic_read(&port->status);
		rec->wwpn = port->wwpn;
		rec->d_id = port->d_id;
	}
	if (sdev) {
		rec->lun_status = atomic_read(&sdev_to_zfcp(sdev)->status);
		rec->lun = zfcp_scsi_dev_lun(sdev);
451 452 453
	}
}

454
/**
455 456 457 458 459 460 461 462 463
 * zfcp_dbf_rec_trig - trace event related to triggered recovery
 * @tag: identifier for event
 * @adapter: adapter on which the erp_action should run
 * @port: remote port involved in the erp_action
 * @sdev: scsi device involved in the erp_action
 * @want: wanted erp_action
 * @need: required erp_action
 *
 * The adapter->erp_lock has to be held.
464
 */
465 466 467
void zfcp_dbf_rec_trig(char *tag, struct zfcp_adapter *adapter,
		       struct zfcp_port *port, struct scsi_device *sdev,
		       u8 want, u8 need)
468
{
469 470
	struct zfcp_dbf *dbf = adapter->dbf;
	struct zfcp_dbf_rec *rec = &dbf->rec_buf;
471
	struct list_head *entry;
472 473
	unsigned long flags;

S
Swen Schillig 已提交
474
	spin_lock_irqsave(&dbf->rec_lock, flags);
475
	memset(rec, 0, sizeof(*rec));
S
Swen Schillig 已提交
476

477 478 479
	rec->id = ZFCP_DBF_REC_TRIG;
	memcpy(rec->tag, tag, ZFCP_DBF_TAG_LEN);
	zfcp_dbf_set_common(rec, adapter, port, sdev);
480

481 482
	list_for_each(entry, &adapter->erp_ready_head)
		rec->u.trig.ready++;
483

484 485
	list_for_each(entry, &adapter->erp_running_head)
		rec->u.trig.running++;
486

487 488
	rec->u.trig.want = want;
	rec->u.trig.need = need;
489

490 491
	debug_event(dbf->rec, 1, rec, sizeof(*rec));
	spin_unlock_irqrestore(&dbf->rec_lock, flags);
492 493
}

494

495
/**
496 497 498
 * zfcp_dbf_rec_run - trace event related to running recovery
 * @tag: identifier for event
 * @erp: erp_action running
499
 */
500
void zfcp_dbf_rec_run(char *tag, struct zfcp_erp_action *erp)
501
{
502 503
	struct zfcp_dbf *dbf = erp->adapter->dbf;
	struct zfcp_dbf_rec *rec = &dbf->rec_buf;
504 505
	unsigned long flags;

S
Swen Schillig 已提交
506
	spin_lock_irqsave(&dbf->rec_lock, flags);
507
	memset(rec, 0, sizeof(*rec));
508

509 510 511
	rec->id = ZFCP_DBF_REC_RUN;
	memcpy(rec->tag, tag, ZFCP_DBF_TAG_LEN);
	zfcp_dbf_set_common(rec, erp->adapter, erp->port, erp->sdev);
512

513 514 515 516 517 518 519 520 521 522 523 524 525 526
	rec->u.run.fsf_req_id = erp->fsf_req_id;
	rec->u.run.rec_status = erp->status;
	rec->u.run.rec_step = erp->step;
	rec->u.run.rec_action = erp->action;

	if (erp->sdev)
		rec->u.run.rec_count =
			atomic_read(&sdev_to_zfcp(erp->sdev)->erp_counter);
	else if (erp->port)
		rec->u.run.rec_count = atomic_read(&erp->port->erp_counter);
	else
		rec->u.run.rec_count = atomic_read(&erp->adapter->erp_counter);

	debug_event(dbf->rec, 1, rec, sizeof(*rec));
S
Swen Schillig 已提交
527
	spin_unlock_irqrestore(&dbf->rec_lock, flags);
528 529
}

530
/**
S
Swen Schillig 已提交
531
 * zfcp_dbf_san_ct_request - trace event for issued CT request
532
 * @fsf_req: request containing issued CT data
533
 * @d_id: destination id where ct request is sent to
534
 */
535
void zfcp_dbf_san_ct_request(struct zfcp_fsf_req *fsf_req, u32 d_id)
536
{
537 538
	struct zfcp_fsf_ct_els *ct = (struct zfcp_fsf_ct_els *)fsf_req->data;
	struct zfcp_adapter *adapter = fsf_req->adapter;
539
	struct zfcp_dbf *dbf = adapter->dbf;
540
	struct fc_ct_hdr *hdr = sg_virt(ct->req);
S
Swen Schillig 已提交
541 542
	struct zfcp_dbf_san_record *r = &dbf->san_buf;
	struct zfcp_dbf_san_record_ct_request *oct = &r->u.ct_req;
543
	int level = 3;
544
	unsigned long flags;
545

S
Swen Schillig 已提交
546
	spin_lock_irqsave(&dbf->san_lock, flags);
547 548
	memset(r, 0, sizeof(*r));
	strncpy(r->tag, "octc", ZFCP_DBF_TAG_SIZE);
549
	r->fsf_reqid = fsf_req->req_id;
550
	r->fsf_seqno = fsf_req->seq_no;
551
	oct->d_id = d_id;
552 553 554 555 556 557 558
	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),
559
		       ZFCP_DBF_SAN_MAX_PAYLOAD);
S
Swen Schillig 已提交
560 561
	debug_event(dbf->san, level, r, sizeof(*r));
	zfcp_dbf_hexdump(dbf->san, r, sizeof(*r), level,
562
			 (void *)hdr + sizeof(struct fc_ct_hdr), oct->len);
S
Swen Schillig 已提交
563
	spin_unlock_irqrestore(&dbf->san_lock, flags);
564 565
}

566
/**
S
Swen Schillig 已提交
567
 * zfcp_dbf_san_ct_response - trace event for completion of CT request
568 569
 * @fsf_req: request containing CT response
 */
S
Swen Schillig 已提交
570
void zfcp_dbf_san_ct_response(struct zfcp_fsf_req *fsf_req)
571
{
572 573
	struct zfcp_fsf_ct_els *ct = (struct zfcp_fsf_ct_els *)fsf_req->data;
	struct zfcp_adapter *adapter = fsf_req->adapter;
574
	struct fc_ct_hdr *hdr = sg_virt(ct->resp);
575
	struct zfcp_dbf *dbf = adapter->dbf;
S
Swen Schillig 已提交
576 577
	struct zfcp_dbf_san_record *r = &dbf->san_buf;
	struct zfcp_dbf_san_record_ct_response *rct = &r->u.ct_resp;
578
	int level = 3;
579
	unsigned long flags;
580

S
Swen Schillig 已提交
581
	spin_lock_irqsave(&dbf->san_lock, flags);
582 583
	memset(r, 0, sizeof(*r));
	strncpy(r->tag, "rctc", ZFCP_DBF_TAG_SIZE);
584
	r->fsf_reqid = fsf_req->req_id;
585
	r->fsf_seqno = fsf_req->seq_no;
586 587 588 589 590 591 592
	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),
593
		       ZFCP_DBF_SAN_MAX_PAYLOAD);
S
Swen Schillig 已提交
594 595
	debug_event(dbf->san, level, r, sizeof(*r));
	zfcp_dbf_hexdump(dbf->san, r, sizeof(*r), level,
596
			 (void *)hdr + sizeof(struct fc_ct_hdr), rct->len);
S
Swen Schillig 已提交
597
	spin_unlock_irqrestore(&dbf->san_lock, flags);
598 599
}

S
Swen Schillig 已提交
600
static void zfcp_dbf_san_els(const char *tag, int level,
601 602
			     struct zfcp_fsf_req *fsf_req, u32 d_id,
			     void *buffer, int buflen)
603 604
{
	struct zfcp_adapter *adapter = fsf_req->adapter;
605
	struct zfcp_dbf *dbf = adapter->dbf;
S
Swen Schillig 已提交
606
	struct zfcp_dbf_san_record *rec = &dbf->san_buf;
607 608
	unsigned long flags;

S
Swen Schillig 已提交
609
	spin_lock_irqsave(&dbf->san_lock, flags);
610
	memset(rec, 0, sizeof(*rec));
611
	strncpy(rec->tag, tag, ZFCP_DBF_TAG_SIZE);
612
	rec->fsf_reqid = fsf_req->req_id;
613
	rec->fsf_seqno = fsf_req->seq_no;
614
	rec->u.els.d_id = d_id;
S
Swen Schillig 已提交
615 616
	debug_event(dbf->san, level, rec, sizeof(*rec));
	zfcp_dbf_hexdump(dbf->san, rec, sizeof(*rec), level,
617
			 buffer, min(buflen, ZFCP_DBF_SAN_MAX_PAYLOAD));
S
Swen Schillig 已提交
618
	spin_unlock_irqrestore(&dbf->san_lock, flags);
619 620
}

621
/**
S
Swen Schillig 已提交
622
 * zfcp_dbf_san_els_request - trace event for issued ELS
623 624
 * @fsf_req: request containing issued ELS
 */
S
Swen Schillig 已提交
625
void zfcp_dbf_san_els_request(struct zfcp_fsf_req *fsf_req)
626
{
627 628
	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);
629

630 631
	zfcp_dbf_san_els("oels", 2, fsf_req, d_id,
			 sg_virt(els->req), els->req->length);
632 633
}

634
/**
S
Swen Schillig 已提交
635
 * zfcp_dbf_san_els_response - trace event for completed ELS
636 637
 * @fsf_req: request containing ELS response
 */
S
Swen Schillig 已提交
638
void zfcp_dbf_san_els_response(struct zfcp_fsf_req *fsf_req)
639
{
640 641
	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);
642

643 644
	zfcp_dbf_san_els("rels", 2, fsf_req, d_id,
			       sg_virt(els->resp), els->resp->length);
645 646
}

647
/**
S
Swen Schillig 已提交
648
 * zfcp_dbf_san_incoming_els - trace event for incomig ELS
649 650
 * @fsf_req: request containing unsolicited status buffer with incoming ELS
 */
S
Swen Schillig 已提交
651
void zfcp_dbf_san_incoming_els(struct zfcp_fsf_req *fsf_req)
652
{
653 654 655 656 657
	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);

658
	zfcp_dbf_san_els("iels", 1, fsf_req, ntoh24(buf->d_id),
659
			       (void *)buf->payload.data, length);
660 661
}

S
Swen Schillig 已提交
662
static int zfcp_dbf_san_view_format(debug_info_t *id, struct debug_view *view,
663
				    char *out_buf, const char *in_buf)
664
{
S
Swen Schillig 已提交
665
	struct zfcp_dbf_san_record *r = (struct zfcp_dbf_san_record *)in_buf;
666
	char *p = out_buf;
667

668
	if (strncmp(r->tag, "dump", ZFCP_DBF_TAG_SIZE) == 0)
669 670
		return 0;

671
	zfcp_dbf_tag(&p, "tag", r->tag);
672 673 674 675
	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 已提交
676
		struct zfcp_dbf_san_record_ct_request *ct = &r->u.ct_req;
677
		zfcp_dbf_out(&p, "d_id", "0x%06x", ct->d_id);
678 679 680 681 682 683
		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);
684
	} else if (strncmp(r->tag, "rctc", ZFCP_DBF_TAG_SIZE) == 0) {
S
Swen Schillig 已提交
685
		struct zfcp_dbf_san_record_ct_response *ct = &r->u.ct_resp;
686 687 688 689 690
		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);
691
		zfcp_dbf_out(&p, "max_res_size", "0x%04x", ct->max_res_size);
692 693 694
	} 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 已提交
695
		struct zfcp_dbf_san_record_els *els = &r->u.els;
696
		zfcp_dbf_out(&p, "d_id", "0x%06x", els->d_id);
697
	}
698
	return p - out_buf;
699 700
}

S
Swen Schillig 已提交
701 702 703 704
static struct debug_view zfcp_dbf_san_view = {
	.name = "structured",
	.header_proc = zfcp_dbf_view_header,
	.format_proc = zfcp_dbf_san_view_format,
705 706
};

S
Swen Schillig 已提交
707 708 709
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)
710
{
S
Swen Schillig 已提交
711
	struct zfcp_dbf_scsi_record *rec = &dbf->scsi_buf;
712 713
	struct zfcp_dbf_dump *dump = (struct zfcp_dbf_dump *)rec;
	unsigned long flags;
714 715 716
	struct fcp_resp_with_ext *fcp_rsp;
	struct fcp_resp_rsp_info *fcp_rsp_info = NULL;
	char *fcp_sns_info = NULL;
717 718
	int offset = 0, buflen = 0;

S
Swen Schillig 已提交
719
	spin_lock_irqsave(&dbf->scsi_lock, flags);
720
	do {
721
		memset(rec, 0, sizeof(*rec));
722 723 724
		if (offset == 0) {
			strncpy(rec->tag, tag, ZFCP_DBF_TAG_SIZE);
			strncpy(rec->tag2, tag2, ZFCP_DBF_TAG_SIZE);
725 726 727 728 729 730 731
			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;
732
				memcpy(rec->scsi_opcode, scsi_cmnd->cmnd,
733 734 735 736
					min((int)scsi_cmnd->cmd_len,
						ZFCP_DBF_SCSI_OPCODE));
				rec->scsi_retries = scsi_cmnd->retries;
				rec->scsi_allowed = scsi_cmnd->allowed;
737 738
			}
			if (fsf_req != NULL) {
739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754
				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);
755 756
					rec->sns_info_len = buflen;
					memcpy(rec->sns_info, fcp_sns_info,
757 758 759 760 761 762
					       min(buflen,
						   ZFCP_DBF_SCSI_FCP_SNS_INFO));
					offset += min(buflen,
						      ZFCP_DBF_SCSI_FCP_SNS_INFO);
				}

763
				rec->fsf_reqid = fsf_req->req_id;
764 765 766
				rec->fsf_seqno = fsf_req->seq_no;
				rec->fsf_issued = fsf_req->issued;
			}
767
			rec->old_fsf_reqid = old_req_id;
768 769 770 771 772 773
		} 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 已提交
774
						     zfcp_dbf_scsi_record) -
775 776 777 778
					 (int)sizeof(struct zfcp_dbf_dump));
			memcpy(dump->data, fcp_sns_info + offset, dump->size);
			offset += dump->size;
		}
S
Swen Schillig 已提交
779
		debug_event(dbf->scsi, level, rec, sizeof(*rec));
780
	} while (offset < buflen);
S
Swen Schillig 已提交
781
	spin_unlock_irqrestore(&dbf->scsi_lock, flags);
782 783
}

S
Swen Schillig 已提交
784
static int zfcp_dbf_scsi_view_format(debug_info_t *id, struct debug_view *view,
785
				     char *out_buf, const char *in_buf)
786
{
S
Swen Schillig 已提交
787
	struct zfcp_dbf_scsi_record *r = (struct zfcp_dbf_scsi_record *)in_buf;
788
	struct timespec t;
789
	char *p = out_buf;
790

791
	if (strncmp(r->tag, "dump", ZFCP_DBF_TAG_SIZE) == 0)
792 793
		return 0;

794 795
	zfcp_dbf_tag(&p, "tag", r->tag);
	zfcp_dbf_tag(&p, "tag2", r->tag2);
796 797 798 799
	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);
800 801
	zfcp_dbf_outd(&p, "scsi_opcode", r->scsi_opcode, ZFCP_DBF_SCSI_OPCODE,
		      0, ZFCP_DBF_SCSI_OPCODE);
802 803 804
	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)
805
		zfcp_dbf_out(&p, "old_fsf_reqid", "0x%0Lx", r->old_fsf_reqid);
806 807
	zfcp_dbf_out(&p, "fsf_reqid", "0x%0Lx", r->fsf_reqid);
	zfcp_dbf_out(&p, "fsf_seqno", "0x%08x", r->fsf_seqno);
808
	stck_to_timespec(r->fsf_issued, &t);
809 810 811
	zfcp_dbf_out(&p, "fsf_issued", "%011lu:%06lu", t.tv_sec, t.tv_nsec);

	if (strncmp(r->tag, "rslt", ZFCP_DBF_TAG_SIZE) == 0) {
812 813 814 815 816 817 818 819
		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,
820
			      ZFCP_DBF_SCSI_FCP_SNS_INFO), 0,
821
			      r->sns_info_len);
822
	}
823 824
	p += sprintf(p, "\n");
	return p - out_buf;
825 826
}

S
Swen Schillig 已提交
827 828 829 830
static struct debug_view zfcp_dbf_scsi_view = {
	.name = "structured",
	.header_proc = zfcp_dbf_view_header,
	.format_proc = zfcp_dbf_scsi_view_format,
831 832
};

833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848
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;
}

849 850 851 852 853
/**
 * 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 已提交
854
int zfcp_dbf_adapter_register(struct zfcp_adapter *adapter)
855 856
{
	char dbf_name[DEBUG_MAX_NAME_LEN];
857 858
	struct zfcp_dbf *dbf;

859
	dbf = kzalloc(sizeof(struct zfcp_dbf), GFP_KERNEL);
860 861 862
	if (!dbf)
		return -ENOMEM;

S
Swen Schillig 已提交
863 864 865 866 867 868
	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);
869

870
	/* debug feature area which records recovery activity */
C
Christof Schmitt 已提交
871
	sprintf(dbf_name, "zfcp_%s_rec", dev_name(&adapter->ccw_device->dev));
872
	dbf->rec = zfcp_dbf_reg(dbf_name, 3, NULL, sizeof(struct zfcp_dbf_rec));
S
Swen Schillig 已提交
873 874
	if (!dbf->rec)
		goto err_out;
875

876
	/* debug feature area which records HBA (FSF and QDIO) conditions */
C
Christof Schmitt 已提交
877
	sprintf(dbf_name, "zfcp_%s_hba", dev_name(&adapter->ccw_device->dev));
S
Swen Schillig 已提交
878 879 880 881
	dbf->hba = zfcp_dbf_reg(dbf_name, 3, &zfcp_dbf_hba_view,
				sizeof(struct zfcp_dbf_hba_record));
	if (!dbf->hba)
		goto err_out;
882 883

	/* debug feature area which records SAN command failures and recovery */
C
Christof Schmitt 已提交
884
	sprintf(dbf_name, "zfcp_%s_san", dev_name(&adapter->ccw_device->dev));
S
Swen Schillig 已提交
885 886 887 888
	dbf->san = zfcp_dbf_reg(dbf_name, 6, &zfcp_dbf_san_view,
				sizeof(struct zfcp_dbf_san_record));
	if (!dbf->san)
		goto err_out;
889 890

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

897
	adapter->dbf = dbf;
898 899
	return 0;

S
Swen Schillig 已提交
900 901
err_out:
	zfcp_dbf_adapter_unregister(dbf);
902 903 904 905 906
	return -ENOMEM;
}

/**
 * zfcp_adapter_debug_unregister - unregisters debug feature for an adapter
S
Swen Schillig 已提交
907
 * @dbf: pointer to dbf for which debug features should be unregistered
908
 */
S
Swen Schillig 已提交
909
void zfcp_dbf_adapter_unregister(struct zfcp_dbf *dbf)
910
{
911 912
	if (!dbf)
		return;
S
Swen Schillig 已提交
913 914 915 916 917 918
	debug_unregister(dbf->scsi);
	debug_unregister(dbf->san);
	debug_unregister(dbf->hba);
	debug_unregister(dbf->rec);
	dbf->adapter->dbf = NULL;
	kfree(dbf);
919
}
S
Swen Schillig 已提交
920