1 /* 2 * zfcp device driver 3 * 4 * Debug traces for zfcp. 5 * 6 * Copyright IBM Corporation 2002, 2009 7 */ 8 9 #define KMSG_COMPONENT "zfcp" 10 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt 11 12 #include <linux/ctype.h> 13 #include <asm/debug.h> 14 #include "zfcp_dbf.h" 15 #include "zfcp_ext.h" 16 #include "zfcp_fc.h" 17 18 static u32 dbfsize = 4; 19 20 module_param(dbfsize, uint, 0400); 21 MODULE_PARM_DESC(dbfsize, 22 "number of pages for each debug feature area (default 4)"); 23 24 static void zfcp_dbf_hexdump(debug_info_t *dbf, void *to, int to_len, 25 int level, char *from, int from_len) 26 { 27 int offset; 28 struct zfcp_dbf_dump *dump = to; 29 int room = to_len - sizeof(*dump); 30 31 for (offset = 0; offset < from_len; offset += dump->size) { 32 memset(to, 0, to_len); 33 strncpy(dump->tag, "dump", ZFCP_DBF_TAG_SIZE); 34 dump->total_size = from_len; 35 dump->offset = offset; 36 dump->size = min(from_len - offset, room); 37 memcpy(dump->data, from + offset, dump->size); 38 debug_event(dbf, level, dump, dump->size + sizeof(*dump)); 39 } 40 } 41 42 static void zfcp_dbf_tag(char **p, const char *label, const char *tag) 43 { 44 int i; 45 46 *p += sprintf(*p, "%-24s", label); 47 for (i = 0; i < ZFCP_DBF_TAG_SIZE; i++) 48 *p += sprintf(*p, "%c", tag[i]); 49 *p += sprintf(*p, "\n"); 50 } 51 52 static void zfcp_dbf_outs(char **buf, const char *s1, const char *s2) 53 { 54 *buf += sprintf(*buf, "%-24s%s\n", s1, s2); 55 } 56 57 static void zfcp_dbf_out(char **buf, const char *s, const char *format, ...) 58 { 59 va_list arg; 60 61 *buf += sprintf(*buf, "%-24s", s); 62 va_start(arg, format); 63 *buf += vsprintf(*buf, format, arg); 64 va_end(arg); 65 *buf += sprintf(*buf, "\n"); 66 } 67 68 static void zfcp_dbf_outd(char **p, const char *label, char *buffer, 69 int buflen, int offset, int total_size) 70 { 71 if (!offset) 72 *p += sprintf(*p, "%-24s ", label); 73 while (buflen--) { 74 if (offset > 0) { 75 if ((offset % 32) == 0) 76 *p += sprintf(*p, "\n%-24c ", ' '); 77 else if ((offset % 4) == 0) 78 *p += sprintf(*p, " "); 79 } 80 *p += sprintf(*p, "%02x", *buffer++); 81 if (++offset == total_size) { 82 *p += sprintf(*p, "\n"); 83 break; 84 } 85 } 86 if (!total_size) 87 *p += sprintf(*p, "\n"); 88 } 89 90 static int zfcp_dbf_view_header(debug_info_t *id, struct debug_view *view, 91 int area, debug_entry_t *entry, char *out_buf) 92 { 93 struct zfcp_dbf_dump *dump = (struct zfcp_dbf_dump *)DEBUG_DATA(entry); 94 struct timespec t; 95 char *p = out_buf; 96 97 if (strncmp(dump->tag, "dump", ZFCP_DBF_TAG_SIZE) != 0) { 98 stck_to_timespec(entry->id.stck, &t); 99 zfcp_dbf_out(&p, "timestamp", "%011lu:%06lu", 100 t.tv_sec, t.tv_nsec); 101 zfcp_dbf_out(&p, "cpu", "%02i", entry->id.fields.cpuid); 102 } else { 103 zfcp_dbf_outd(&p, "", dump->data, dump->size, dump->offset, 104 dump->total_size); 105 if ((dump->offset + dump->size) == dump->total_size) 106 p += sprintf(p, "\n"); 107 } 108 return p - out_buf; 109 } 110 111 void _zfcp_dbf_hba_fsf_response(const char *tag2, int level, 112 struct zfcp_fsf_req *fsf_req, 113 struct zfcp_dbf *dbf) 114 { 115 struct fsf_qtcb *qtcb = fsf_req->qtcb; 116 union fsf_prot_status_qual *prot_status_qual = 117 &qtcb->prefix.prot_status_qual; 118 union fsf_status_qual *fsf_status_qual = &qtcb->header.fsf_status_qual; 119 struct scsi_cmnd *scsi_cmnd; 120 struct zfcp_port *port; 121 struct zfcp_unit *unit; 122 struct zfcp_send_els *send_els; 123 struct zfcp_dbf_hba_record *rec = &dbf->hba_buf; 124 struct zfcp_dbf_hba_record_response *response = &rec->u.response; 125 unsigned long flags; 126 127 spin_lock_irqsave(&dbf->hba_lock, flags); 128 memset(rec, 0, sizeof(*rec)); 129 strncpy(rec->tag, "resp", ZFCP_DBF_TAG_SIZE); 130 strncpy(rec->tag2, tag2, ZFCP_DBF_TAG_SIZE); 131 132 response->fsf_command = fsf_req->fsf_command; 133 response->fsf_reqid = fsf_req->req_id; 134 response->fsf_seqno = fsf_req->seq_no; 135 response->fsf_issued = fsf_req->issued; 136 response->fsf_prot_status = qtcb->prefix.prot_status; 137 response->fsf_status = qtcb->header.fsf_status; 138 memcpy(response->fsf_prot_status_qual, 139 prot_status_qual, FSF_PROT_STATUS_QUAL_SIZE); 140 memcpy(response->fsf_status_qual, 141 fsf_status_qual, FSF_STATUS_QUALIFIER_SIZE); 142 response->fsf_req_status = fsf_req->status; 143 response->sbal_first = fsf_req->queue_req.sbal_first; 144 response->sbal_last = fsf_req->queue_req.sbal_last; 145 response->sbal_response = fsf_req->queue_req.sbal_response; 146 response->pool = fsf_req->pool != NULL; 147 response->erp_action = (unsigned long)fsf_req->erp_action; 148 149 switch (fsf_req->fsf_command) { 150 case FSF_QTCB_FCP_CMND: 151 if (fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT) 152 break; 153 scsi_cmnd = (struct scsi_cmnd *)fsf_req->data; 154 if (scsi_cmnd) { 155 response->u.fcp.cmnd = (unsigned long)scsi_cmnd; 156 response->u.fcp.serial = scsi_cmnd->serial_number; 157 } 158 break; 159 160 case FSF_QTCB_OPEN_PORT_WITH_DID: 161 case FSF_QTCB_CLOSE_PORT: 162 case FSF_QTCB_CLOSE_PHYSICAL_PORT: 163 port = (struct zfcp_port *)fsf_req->data; 164 response->u.port.wwpn = port->wwpn; 165 response->u.port.d_id = port->d_id; 166 response->u.port.port_handle = qtcb->header.port_handle; 167 break; 168 169 case FSF_QTCB_OPEN_LUN: 170 case FSF_QTCB_CLOSE_LUN: 171 unit = (struct zfcp_unit *)fsf_req->data; 172 port = unit->port; 173 response->u.unit.wwpn = port->wwpn; 174 response->u.unit.fcp_lun = unit->fcp_lun; 175 response->u.unit.port_handle = qtcb->header.port_handle; 176 response->u.unit.lun_handle = qtcb->header.lun_handle; 177 break; 178 179 case FSF_QTCB_SEND_ELS: 180 send_els = (struct zfcp_send_els *)fsf_req->data; 181 response->u.els.d_id = ntoh24(qtcb->bottom.support.d_id); 182 break; 183 184 case FSF_QTCB_ABORT_FCP_CMND: 185 case FSF_QTCB_SEND_GENERIC: 186 case FSF_QTCB_EXCHANGE_CONFIG_DATA: 187 case FSF_QTCB_EXCHANGE_PORT_DATA: 188 case FSF_QTCB_DOWNLOAD_CONTROL_FILE: 189 case FSF_QTCB_UPLOAD_CONTROL_FILE: 190 break; 191 } 192 193 debug_event(dbf->hba, level, rec, sizeof(*rec)); 194 195 /* have fcp channel microcode fixed to use as little as possible */ 196 if (fsf_req->fsf_command != FSF_QTCB_FCP_CMND) { 197 /* adjust length skipping trailing zeros */ 198 char *buf = (char *)qtcb + qtcb->header.log_start; 199 int len = qtcb->header.log_length; 200 for (; len && !buf[len - 1]; len--); 201 zfcp_dbf_hexdump(dbf->hba, rec, sizeof(*rec), level, buf, 202 len); 203 } 204 205 spin_unlock_irqrestore(&dbf->hba_lock, flags); 206 } 207 208 void _zfcp_dbf_hba_fsf_unsol(const char *tag, int level, struct zfcp_dbf *dbf, 209 struct fsf_status_read_buffer *status_buffer) 210 { 211 struct zfcp_dbf_hba_record *rec = &dbf->hba_buf; 212 unsigned long flags; 213 214 spin_lock_irqsave(&dbf->hba_lock, flags); 215 memset(rec, 0, sizeof(*rec)); 216 strncpy(rec->tag, "stat", ZFCP_DBF_TAG_SIZE); 217 strncpy(rec->tag2, tag, ZFCP_DBF_TAG_SIZE); 218 219 rec->u.status.failed = atomic_read(&dbf->adapter->stat_miss); 220 if (status_buffer != NULL) { 221 rec->u.status.status_type = status_buffer->status_type; 222 rec->u.status.status_subtype = status_buffer->status_subtype; 223 memcpy(&rec->u.status.queue_designator, 224 &status_buffer->queue_designator, 225 sizeof(struct fsf_queue_designator)); 226 227 switch (status_buffer->status_type) { 228 case FSF_STATUS_READ_SENSE_DATA_AVAIL: 229 rec->u.status.payload_size = 230 ZFCP_DBF_UNSOL_PAYLOAD_SENSE_DATA_AVAIL; 231 break; 232 233 case FSF_STATUS_READ_BIT_ERROR_THRESHOLD: 234 rec->u.status.payload_size = 235 ZFCP_DBF_UNSOL_PAYLOAD_BIT_ERROR_THRESHOLD; 236 break; 237 238 case FSF_STATUS_READ_LINK_DOWN: 239 switch (status_buffer->status_subtype) { 240 case FSF_STATUS_READ_SUB_NO_PHYSICAL_LINK: 241 case FSF_STATUS_READ_SUB_FDISC_FAILED: 242 rec->u.status.payload_size = 243 sizeof(struct fsf_link_down_info); 244 } 245 break; 246 247 case FSF_STATUS_READ_FEATURE_UPDATE_ALERT: 248 rec->u.status.payload_size = 249 ZFCP_DBF_UNSOL_PAYLOAD_FEATURE_UPDATE_ALERT; 250 break; 251 } 252 memcpy(&rec->u.status.payload, 253 &status_buffer->payload, rec->u.status.payload_size); 254 } 255 256 debug_event(dbf->hba, level, rec, sizeof(*rec)); 257 spin_unlock_irqrestore(&dbf->hba_lock, flags); 258 } 259 260 /** 261 * zfcp_dbf_hba_qdio - trace event for QDIO related failure 262 * @qdio: qdio structure affected by this QDIO related event 263 * @qdio_error: as passed by qdio module 264 * @sbal_index: first buffer with error condition, as passed by qdio module 265 * @sbal_count: number of buffers affected, as passed by qdio module 266 */ 267 void zfcp_dbf_hba_qdio(struct zfcp_dbf *dbf, unsigned int qdio_error, 268 int sbal_index, int sbal_count) 269 { 270 struct zfcp_dbf_hba_record *r = &dbf->hba_buf; 271 unsigned long flags; 272 273 spin_lock_irqsave(&dbf->hba_lock, flags); 274 memset(r, 0, sizeof(*r)); 275 strncpy(r->tag, "qdio", ZFCP_DBF_TAG_SIZE); 276 r->u.qdio.qdio_error = qdio_error; 277 r->u.qdio.sbal_index = sbal_index; 278 r->u.qdio.sbal_count = sbal_count; 279 debug_event(dbf->hba, 0, r, sizeof(*r)); 280 spin_unlock_irqrestore(&dbf->hba_lock, flags); 281 } 282 283 /** 284 * zfcp_dbf_hba_berr - trace event for bit error threshold 285 * @dbf: dbf structure affected by this QDIO related event 286 * @req: fsf request 287 */ 288 void zfcp_dbf_hba_berr(struct zfcp_dbf *dbf, struct zfcp_fsf_req *req) 289 { 290 struct zfcp_dbf_hba_record *r = &dbf->hba_buf; 291 struct fsf_status_read_buffer *sr_buf = req->data; 292 struct fsf_bit_error_payload *err = &sr_buf->payload.bit_error; 293 unsigned long flags; 294 295 spin_lock_irqsave(&dbf->hba_lock, flags); 296 memset(r, 0, sizeof(*r)); 297 strncpy(r->tag, "berr", ZFCP_DBF_TAG_SIZE); 298 memcpy(&r->u.berr, err, sizeof(struct fsf_bit_error_payload)); 299 debug_event(dbf->hba, 0, r, sizeof(*r)); 300 spin_unlock_irqrestore(&dbf->hba_lock, flags); 301 } 302 static void zfcp_dbf_hba_view_response(char **p, 303 struct zfcp_dbf_hba_record_response *r) 304 { 305 struct timespec t; 306 307 zfcp_dbf_out(p, "fsf_command", "0x%08x", r->fsf_command); 308 zfcp_dbf_out(p, "fsf_reqid", "0x%0Lx", r->fsf_reqid); 309 zfcp_dbf_out(p, "fsf_seqno", "0x%08x", r->fsf_seqno); 310 stck_to_timespec(r->fsf_issued, &t); 311 zfcp_dbf_out(p, "fsf_issued", "%011lu:%06lu", t.tv_sec, t.tv_nsec); 312 zfcp_dbf_out(p, "fsf_prot_status", "0x%08x", r->fsf_prot_status); 313 zfcp_dbf_out(p, "fsf_status", "0x%08x", r->fsf_status); 314 zfcp_dbf_outd(p, "fsf_prot_status_qual", r->fsf_prot_status_qual, 315 FSF_PROT_STATUS_QUAL_SIZE, 0, FSF_PROT_STATUS_QUAL_SIZE); 316 zfcp_dbf_outd(p, "fsf_status_qual", r->fsf_status_qual, 317 FSF_STATUS_QUALIFIER_SIZE, 0, FSF_STATUS_QUALIFIER_SIZE); 318 zfcp_dbf_out(p, "fsf_req_status", "0x%08x", r->fsf_req_status); 319 zfcp_dbf_out(p, "sbal_first", "0x%02x", r->sbal_first); 320 zfcp_dbf_out(p, "sbal_last", "0x%02x", r->sbal_last); 321 zfcp_dbf_out(p, "sbal_response", "0x%02x", r->sbal_response); 322 zfcp_dbf_out(p, "pool", "0x%02x", r->pool); 323 324 switch (r->fsf_command) { 325 case FSF_QTCB_FCP_CMND: 326 if (r->fsf_req_status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT) 327 break; 328 zfcp_dbf_out(p, "scsi_cmnd", "0x%0Lx", r->u.fcp.cmnd); 329 zfcp_dbf_out(p, "scsi_serial", "0x%016Lx", r->u.fcp.serial); 330 p += sprintf(*p, "\n"); 331 break; 332 333 case FSF_QTCB_OPEN_PORT_WITH_DID: 334 case FSF_QTCB_CLOSE_PORT: 335 case FSF_QTCB_CLOSE_PHYSICAL_PORT: 336 zfcp_dbf_out(p, "wwpn", "0x%016Lx", r->u.port.wwpn); 337 zfcp_dbf_out(p, "d_id", "0x%06x", r->u.port.d_id); 338 zfcp_dbf_out(p, "port_handle", "0x%08x", r->u.port.port_handle); 339 break; 340 341 case FSF_QTCB_OPEN_LUN: 342 case FSF_QTCB_CLOSE_LUN: 343 zfcp_dbf_out(p, "wwpn", "0x%016Lx", r->u.unit.wwpn); 344 zfcp_dbf_out(p, "fcp_lun", "0x%016Lx", r->u.unit.fcp_lun); 345 zfcp_dbf_out(p, "port_handle", "0x%08x", r->u.unit.port_handle); 346 zfcp_dbf_out(p, "lun_handle", "0x%08x", r->u.unit.lun_handle); 347 break; 348 349 case FSF_QTCB_SEND_ELS: 350 zfcp_dbf_out(p, "d_id", "0x%06x", r->u.els.d_id); 351 break; 352 353 case FSF_QTCB_ABORT_FCP_CMND: 354 case FSF_QTCB_SEND_GENERIC: 355 case FSF_QTCB_EXCHANGE_CONFIG_DATA: 356 case FSF_QTCB_EXCHANGE_PORT_DATA: 357 case FSF_QTCB_DOWNLOAD_CONTROL_FILE: 358 case FSF_QTCB_UPLOAD_CONTROL_FILE: 359 break; 360 } 361 } 362 363 static void zfcp_dbf_hba_view_status(char **p, 364 struct zfcp_dbf_hba_record_status *r) 365 { 366 zfcp_dbf_out(p, "failed", "0x%02x", r->failed); 367 zfcp_dbf_out(p, "status_type", "0x%08x", r->status_type); 368 zfcp_dbf_out(p, "status_subtype", "0x%08x", r->status_subtype); 369 zfcp_dbf_outd(p, "queue_designator", (char *)&r->queue_designator, 370 sizeof(struct fsf_queue_designator), 0, 371 sizeof(struct fsf_queue_designator)); 372 zfcp_dbf_outd(p, "payload", (char *)&r->payload, r->payload_size, 0, 373 r->payload_size); 374 } 375 376 static void zfcp_dbf_hba_view_qdio(char **p, struct zfcp_dbf_hba_record_qdio *r) 377 { 378 zfcp_dbf_out(p, "qdio_error", "0x%08x", r->qdio_error); 379 zfcp_dbf_out(p, "sbal_index", "0x%02x", r->sbal_index); 380 zfcp_dbf_out(p, "sbal_count", "0x%02x", r->sbal_count); 381 } 382 383 static void zfcp_dbf_hba_view_berr(char **p, struct fsf_bit_error_payload *r) 384 { 385 zfcp_dbf_out(p, "link_failures", "%d", r->link_failure_error_count); 386 zfcp_dbf_out(p, "loss_of_sync_err", "%d", r->loss_of_sync_error_count); 387 zfcp_dbf_out(p, "loss_of_sig_err", "%d", r->loss_of_signal_error_count); 388 zfcp_dbf_out(p, "prim_seq_err", "%d", 389 r->primitive_sequence_error_count); 390 zfcp_dbf_out(p, "inval_trans_word_err", "%d", 391 r->invalid_transmission_word_error_count); 392 zfcp_dbf_out(p, "CRC_errors", "%d", r->crc_error_count); 393 zfcp_dbf_out(p, "prim_seq_event_to", "%d", 394 r->primitive_sequence_event_timeout_count); 395 zfcp_dbf_out(p, "elast_buf_overrun_err", "%d", 396 r->elastic_buffer_overrun_error_count); 397 zfcp_dbf_out(p, "adv_rec_buf2buf_cred", "%d", 398 r->advertised_receive_b2b_credit); 399 zfcp_dbf_out(p, "curr_rec_buf2buf_cred", "%d", 400 r->current_receive_b2b_credit); 401 zfcp_dbf_out(p, "adv_trans_buf2buf_cred", "%d", 402 r->advertised_transmit_b2b_credit); 403 zfcp_dbf_out(p, "curr_trans_buf2buf_cred", "%d", 404 r->current_transmit_b2b_credit); 405 } 406 407 static int zfcp_dbf_hba_view_format(debug_info_t *id, struct debug_view *view, 408 char *out_buf, const char *in_buf) 409 { 410 struct zfcp_dbf_hba_record *r = (struct zfcp_dbf_hba_record *)in_buf; 411 char *p = out_buf; 412 413 if (strncmp(r->tag, "dump", ZFCP_DBF_TAG_SIZE) == 0) 414 return 0; 415 416 zfcp_dbf_tag(&p, "tag", r->tag); 417 if (isalpha(r->tag2[0])) 418 zfcp_dbf_tag(&p, "tag2", r->tag2); 419 420 if (strncmp(r->tag, "resp", ZFCP_DBF_TAG_SIZE) == 0) 421 zfcp_dbf_hba_view_response(&p, &r->u.response); 422 else if (strncmp(r->tag, "stat", ZFCP_DBF_TAG_SIZE) == 0) 423 zfcp_dbf_hba_view_status(&p, &r->u.status); 424 else if (strncmp(r->tag, "qdio", ZFCP_DBF_TAG_SIZE) == 0) 425 zfcp_dbf_hba_view_qdio(&p, &r->u.qdio); 426 else if (strncmp(r->tag, "berr", ZFCP_DBF_TAG_SIZE) == 0) 427 zfcp_dbf_hba_view_berr(&p, &r->u.berr); 428 429 if (strncmp(r->tag, "resp", ZFCP_DBF_TAG_SIZE) != 0) 430 p += sprintf(p, "\n"); 431 return p - out_buf; 432 } 433 434 static struct debug_view zfcp_dbf_hba_view = { 435 .name = "structured", 436 .header_proc = zfcp_dbf_view_header, 437 .format_proc = zfcp_dbf_hba_view_format, 438 }; 439 440 static const char *zfcp_dbf_rec_tags[] = { 441 [ZFCP_REC_DBF_ID_THREAD] = "thread", 442 [ZFCP_REC_DBF_ID_TARGET] = "target", 443 [ZFCP_REC_DBF_ID_TRIGGER] = "trigger", 444 [ZFCP_REC_DBF_ID_ACTION] = "action", 445 }; 446 447 static int zfcp_dbf_rec_view_format(debug_info_t *id, struct debug_view *view, 448 char *buf, const char *_rec) 449 { 450 struct zfcp_dbf_rec_record *r = (struct zfcp_dbf_rec_record *)_rec; 451 char *p = buf; 452 char hint[ZFCP_DBF_ID_SIZE + 1]; 453 454 memcpy(hint, r->id2, ZFCP_DBF_ID_SIZE); 455 hint[ZFCP_DBF_ID_SIZE] = 0; 456 zfcp_dbf_outs(&p, "tag", zfcp_dbf_rec_tags[r->id]); 457 zfcp_dbf_outs(&p, "hint", hint); 458 switch (r->id) { 459 case ZFCP_REC_DBF_ID_THREAD: 460 zfcp_dbf_out(&p, "total", "%d", r->u.thread.total); 461 zfcp_dbf_out(&p, "ready", "%d", r->u.thread.ready); 462 zfcp_dbf_out(&p, "running", "%d", r->u.thread.running); 463 break; 464 case ZFCP_REC_DBF_ID_TARGET: 465 zfcp_dbf_out(&p, "reference", "0x%016Lx", r->u.target.ref); 466 zfcp_dbf_out(&p, "status", "0x%08x", r->u.target.status); 467 zfcp_dbf_out(&p, "erp_count", "%d", r->u.target.erp_count); 468 zfcp_dbf_out(&p, "d_id", "0x%06x", r->u.target.d_id); 469 zfcp_dbf_out(&p, "wwpn", "0x%016Lx", r->u.target.wwpn); 470 zfcp_dbf_out(&p, "fcp_lun", "0x%016Lx", r->u.target.fcp_lun); 471 break; 472 case ZFCP_REC_DBF_ID_TRIGGER: 473 zfcp_dbf_out(&p, "reference", "0x%016Lx", r->u.trigger.ref); 474 zfcp_dbf_out(&p, "erp_action", "0x%016Lx", r->u.trigger.action); 475 zfcp_dbf_out(&p, "requested", "%d", r->u.trigger.want); 476 zfcp_dbf_out(&p, "executed", "%d", r->u.trigger.need); 477 zfcp_dbf_out(&p, "wwpn", "0x%016Lx", r->u.trigger.wwpn); 478 zfcp_dbf_out(&p, "fcp_lun", "0x%016Lx", r->u.trigger.fcp_lun); 479 zfcp_dbf_out(&p, "adapter_status", "0x%08x", r->u.trigger.as); 480 zfcp_dbf_out(&p, "port_status", "0x%08x", r->u.trigger.ps); 481 zfcp_dbf_out(&p, "unit_status", "0x%08x", r->u.trigger.us); 482 break; 483 case ZFCP_REC_DBF_ID_ACTION: 484 zfcp_dbf_out(&p, "erp_action", "0x%016Lx", r->u.action.action); 485 zfcp_dbf_out(&p, "fsf_req", "0x%016Lx", r->u.action.fsf_req); 486 zfcp_dbf_out(&p, "status", "0x%08Lx", r->u.action.status); 487 zfcp_dbf_out(&p, "step", "0x%08Lx", r->u.action.step); 488 break; 489 } 490 p += sprintf(p, "\n"); 491 return p - buf; 492 } 493 494 static struct debug_view zfcp_dbf_rec_view = { 495 .name = "structured", 496 .header_proc = zfcp_dbf_view_header, 497 .format_proc = zfcp_dbf_rec_view_format, 498 }; 499 500 /** 501 * zfcp_dbf_rec_thread - trace event related to recovery thread operation 502 * @id2: identifier for event 503 * @dbf: reference to dbf structure 504 * This function assumes that the caller is holding erp_lock. 505 */ 506 void zfcp_dbf_rec_thread(char *id2, struct zfcp_dbf *dbf) 507 { 508 struct zfcp_adapter *adapter = dbf->adapter; 509 struct zfcp_dbf_rec_record *r = &dbf->rec_buf; 510 unsigned long flags = 0; 511 struct list_head *entry; 512 unsigned ready = 0, running = 0, total; 513 514 list_for_each(entry, &adapter->erp_ready_head) 515 ready++; 516 list_for_each(entry, &adapter->erp_running_head) 517 running++; 518 total = adapter->erp_total_count; 519 520 spin_lock_irqsave(&dbf->rec_lock, flags); 521 memset(r, 0, sizeof(*r)); 522 r->id = ZFCP_REC_DBF_ID_THREAD; 523 memcpy(r->id2, id2, ZFCP_DBF_ID_SIZE); 524 r->u.thread.total = total; 525 r->u.thread.ready = ready; 526 r->u.thread.running = running; 527 debug_event(dbf->rec, 6, r, sizeof(*r)); 528 spin_unlock_irqrestore(&dbf->rec_lock, flags); 529 } 530 531 /** 532 * zfcp_dbf_rec_thread - trace event related to recovery thread operation 533 * @id2: identifier for event 534 * @adapter: adapter 535 * This function assumes that the caller does not hold erp_lock. 536 */ 537 void zfcp_dbf_rec_thread_lock(char *id2, struct zfcp_dbf *dbf) 538 { 539 struct zfcp_adapter *adapter = dbf->adapter; 540 unsigned long flags; 541 542 read_lock_irqsave(&adapter->erp_lock, flags); 543 zfcp_dbf_rec_thread(id2, dbf); 544 read_unlock_irqrestore(&adapter->erp_lock, flags); 545 } 546 547 static void zfcp_dbf_rec_target(char *id2, void *ref, struct zfcp_dbf *dbf, 548 atomic_t *status, atomic_t *erp_count, u64 wwpn, 549 u32 d_id, u64 fcp_lun) 550 { 551 struct zfcp_dbf_rec_record *r = &dbf->rec_buf; 552 unsigned long flags; 553 554 spin_lock_irqsave(&dbf->rec_lock, flags); 555 memset(r, 0, sizeof(*r)); 556 r->id = ZFCP_REC_DBF_ID_TARGET; 557 memcpy(r->id2, id2, ZFCP_DBF_ID_SIZE); 558 r->u.target.ref = (unsigned long)ref; 559 r->u.target.status = atomic_read(status); 560 r->u.target.wwpn = wwpn; 561 r->u.target.d_id = d_id; 562 r->u.target.fcp_lun = fcp_lun; 563 r->u.target.erp_count = atomic_read(erp_count); 564 debug_event(dbf->rec, 3, r, sizeof(*r)); 565 spin_unlock_irqrestore(&dbf->rec_lock, flags); 566 } 567 568 /** 569 * zfcp_dbf_rec_adapter - trace event for adapter state change 570 * @id: identifier for trigger of state change 571 * @ref: additional reference (e.g. request) 572 * @dbf: reference to dbf structure 573 */ 574 void zfcp_dbf_rec_adapter(char *id, void *ref, struct zfcp_dbf *dbf) 575 { 576 struct zfcp_adapter *adapter = dbf->adapter; 577 578 zfcp_dbf_rec_target(id, ref, dbf, &adapter->status, 579 &adapter->erp_counter, 0, 0, 0); 580 } 581 582 /** 583 * zfcp_dbf_rec_port - trace event for port state change 584 * @id: identifier for trigger of state change 585 * @ref: additional reference (e.g. request) 586 * @port: port 587 */ 588 void zfcp_dbf_rec_port(char *id, void *ref, struct zfcp_port *port) 589 { 590 struct zfcp_dbf *dbf = port->adapter->dbf; 591 592 zfcp_dbf_rec_target(id, ref, dbf, &port->status, 593 &port->erp_counter, port->wwpn, port->d_id, 594 0); 595 } 596 597 /** 598 * zfcp_dbf_rec_unit - trace event for unit state change 599 * @id: identifier for trigger of state change 600 * @ref: additional reference (e.g. request) 601 * @unit: unit 602 */ 603 void zfcp_dbf_rec_unit(char *id, void *ref, struct zfcp_unit *unit) 604 { 605 struct zfcp_port *port = unit->port; 606 struct zfcp_dbf *dbf = port->adapter->dbf; 607 608 zfcp_dbf_rec_target(id, ref, dbf, &unit->status, 609 &unit->erp_counter, port->wwpn, port->d_id, 610 unit->fcp_lun); 611 } 612 613 /** 614 * zfcp_dbf_rec_trigger - trace event for triggered error recovery 615 * @id2: identifier for error recovery trigger 616 * @ref: additional reference (e.g. request) 617 * @want: originally requested error recovery action 618 * @need: error recovery action actually initiated 619 * @action: address of error recovery action struct 620 * @adapter: adapter 621 * @port: port 622 * @unit: unit 623 */ 624 void zfcp_dbf_rec_trigger(char *id2, void *ref, u8 want, u8 need, void *action, 625 struct zfcp_adapter *adapter, struct zfcp_port *port, 626 struct zfcp_unit *unit) 627 { 628 struct zfcp_dbf *dbf = adapter->dbf; 629 struct zfcp_dbf_rec_record *r = &dbf->rec_buf; 630 unsigned long flags; 631 632 spin_lock_irqsave(&dbf->rec_lock, flags); 633 memset(r, 0, sizeof(*r)); 634 r->id = ZFCP_REC_DBF_ID_TRIGGER; 635 memcpy(r->id2, id2, ZFCP_DBF_ID_SIZE); 636 r->u.trigger.ref = (unsigned long)ref; 637 r->u.trigger.want = want; 638 r->u.trigger.need = need; 639 r->u.trigger.action = (unsigned long)action; 640 r->u.trigger.as = atomic_read(&adapter->status); 641 if (port) { 642 r->u.trigger.ps = atomic_read(&port->status); 643 r->u.trigger.wwpn = port->wwpn; 644 } 645 if (unit) { 646 r->u.trigger.us = atomic_read(&unit->status); 647 r->u.trigger.fcp_lun = unit->fcp_lun; 648 } 649 debug_event(dbf->rec, action ? 1 : 4, r, sizeof(*r)); 650 spin_unlock_irqrestore(&dbf->rec_lock, flags); 651 } 652 653 /** 654 * zfcp_dbf_rec_action - trace event showing progress of recovery action 655 * @id2: identifier 656 * @erp_action: error recovery action struct pointer 657 */ 658 void zfcp_dbf_rec_action(char *id2, struct zfcp_erp_action *erp_action) 659 { 660 struct zfcp_dbf *dbf = erp_action->adapter->dbf; 661 struct zfcp_dbf_rec_record *r = &dbf->rec_buf; 662 unsigned long flags; 663 664 spin_lock_irqsave(&dbf->rec_lock, flags); 665 memset(r, 0, sizeof(*r)); 666 r->id = ZFCP_REC_DBF_ID_ACTION; 667 memcpy(r->id2, id2, ZFCP_DBF_ID_SIZE); 668 r->u.action.action = (unsigned long)erp_action; 669 r->u.action.status = erp_action->status; 670 r->u.action.step = erp_action->step; 671 r->u.action.fsf_req = (unsigned long)erp_action->fsf_req; 672 debug_event(dbf->rec, 5, r, sizeof(*r)); 673 spin_unlock_irqrestore(&dbf->rec_lock, flags); 674 } 675 676 /** 677 * zfcp_dbf_san_ct_request - trace event for issued CT request 678 * @fsf_req: request containing issued CT data 679 * @d_id: destination id where ct request is sent to 680 */ 681 void zfcp_dbf_san_ct_request(struct zfcp_fsf_req *fsf_req, u32 d_id) 682 { 683 struct zfcp_fsf_ct_els *ct = (struct zfcp_fsf_ct_els *)fsf_req->data; 684 struct zfcp_adapter *adapter = fsf_req->adapter; 685 struct zfcp_dbf *dbf = adapter->dbf; 686 struct fc_ct_hdr *hdr = sg_virt(ct->req); 687 struct zfcp_dbf_san_record *r = &dbf->san_buf; 688 struct zfcp_dbf_san_record_ct_request *oct = &r->u.ct_req; 689 int level = 3; 690 unsigned long flags; 691 692 spin_lock_irqsave(&dbf->san_lock, flags); 693 memset(r, 0, sizeof(*r)); 694 strncpy(r->tag, "octc", ZFCP_DBF_TAG_SIZE); 695 r->fsf_reqid = fsf_req->req_id; 696 r->fsf_seqno = fsf_req->seq_no; 697 oct->d_id = d_id; 698 oct->cmd_req_code = hdr->ct_cmd; 699 oct->revision = hdr->ct_rev; 700 oct->gs_type = hdr->ct_fs_type; 701 oct->gs_subtype = hdr->ct_fs_subtype; 702 oct->options = hdr->ct_options; 703 oct->max_res_size = hdr->ct_mr_size; 704 oct->len = min((int)ct->req->length - (int)sizeof(struct fc_ct_hdr), 705 ZFCP_DBF_SAN_MAX_PAYLOAD); 706 debug_event(dbf->san, level, r, sizeof(*r)); 707 zfcp_dbf_hexdump(dbf->san, r, sizeof(*r), level, 708 (void *)hdr + sizeof(struct fc_ct_hdr), oct->len); 709 spin_unlock_irqrestore(&dbf->san_lock, flags); 710 } 711 712 /** 713 * zfcp_dbf_san_ct_response - trace event for completion of CT request 714 * @fsf_req: request containing CT response 715 */ 716 void zfcp_dbf_san_ct_response(struct zfcp_fsf_req *fsf_req) 717 { 718 struct zfcp_fsf_ct_els *ct = (struct zfcp_fsf_ct_els *)fsf_req->data; 719 struct zfcp_adapter *adapter = fsf_req->adapter; 720 struct fc_ct_hdr *hdr = sg_virt(ct->resp); 721 struct zfcp_dbf *dbf = adapter->dbf; 722 struct zfcp_dbf_san_record *r = &dbf->san_buf; 723 struct zfcp_dbf_san_record_ct_response *rct = &r->u.ct_resp; 724 int level = 3; 725 unsigned long flags; 726 727 spin_lock_irqsave(&dbf->san_lock, flags); 728 memset(r, 0, sizeof(*r)); 729 strncpy(r->tag, "rctc", ZFCP_DBF_TAG_SIZE); 730 r->fsf_reqid = fsf_req->req_id; 731 r->fsf_seqno = fsf_req->seq_no; 732 rct->cmd_rsp_code = hdr->ct_cmd; 733 rct->revision = hdr->ct_rev; 734 rct->reason_code = hdr->ct_reason; 735 rct->expl = hdr->ct_explan; 736 rct->vendor_unique = hdr->ct_vendor; 737 rct->max_res_size = hdr->ct_mr_size; 738 rct->len = min((int)ct->resp->length - (int)sizeof(struct fc_ct_hdr), 739 ZFCP_DBF_SAN_MAX_PAYLOAD); 740 debug_event(dbf->san, level, r, sizeof(*r)); 741 zfcp_dbf_hexdump(dbf->san, r, sizeof(*r), level, 742 (void *)hdr + sizeof(struct fc_ct_hdr), rct->len); 743 spin_unlock_irqrestore(&dbf->san_lock, flags); 744 } 745 746 static void zfcp_dbf_san_els(const char *tag, int level, 747 struct zfcp_fsf_req *fsf_req, u32 d_id, 748 void *buffer, int buflen) 749 { 750 struct zfcp_adapter *adapter = fsf_req->adapter; 751 struct zfcp_dbf *dbf = adapter->dbf; 752 struct zfcp_dbf_san_record *rec = &dbf->san_buf; 753 unsigned long flags; 754 755 spin_lock_irqsave(&dbf->san_lock, flags); 756 memset(rec, 0, sizeof(*rec)); 757 strncpy(rec->tag, tag, ZFCP_DBF_TAG_SIZE); 758 rec->fsf_reqid = fsf_req->req_id; 759 rec->fsf_seqno = fsf_req->seq_no; 760 rec->u.els.d_id = d_id; 761 debug_event(dbf->san, level, rec, sizeof(*rec)); 762 zfcp_dbf_hexdump(dbf->san, rec, sizeof(*rec), level, 763 buffer, min(buflen, ZFCP_DBF_SAN_MAX_PAYLOAD)); 764 spin_unlock_irqrestore(&dbf->san_lock, flags); 765 } 766 767 /** 768 * zfcp_dbf_san_els_request - trace event for issued ELS 769 * @fsf_req: request containing issued ELS 770 */ 771 void zfcp_dbf_san_els_request(struct zfcp_fsf_req *fsf_req) 772 { 773 struct zfcp_fsf_ct_els *els = (struct zfcp_fsf_ct_els *)fsf_req->data; 774 u32 d_id = ntoh24(fsf_req->qtcb->bottom.support.d_id); 775 776 zfcp_dbf_san_els("oels", 2, fsf_req, d_id, 777 sg_virt(els->req), els->req->length); 778 } 779 780 /** 781 * zfcp_dbf_san_els_response - trace event for completed ELS 782 * @fsf_req: request containing ELS response 783 */ 784 void zfcp_dbf_san_els_response(struct zfcp_fsf_req *fsf_req) 785 { 786 struct zfcp_fsf_ct_els *els = (struct zfcp_fsf_ct_els *)fsf_req->data; 787 u32 d_id = ntoh24(fsf_req->qtcb->bottom.support.d_id); 788 789 zfcp_dbf_san_els("rels", 2, fsf_req, d_id, 790 sg_virt(els->resp), els->resp->length); 791 } 792 793 /** 794 * zfcp_dbf_san_incoming_els - trace event for incomig ELS 795 * @fsf_req: request containing unsolicited status buffer with incoming ELS 796 */ 797 void zfcp_dbf_san_incoming_els(struct zfcp_fsf_req *fsf_req) 798 { 799 struct fsf_status_read_buffer *buf = 800 (struct fsf_status_read_buffer *)fsf_req->data; 801 int length = (int)buf->length - 802 (int)((void *)&buf->payload - (void *)buf); 803 804 zfcp_dbf_san_els("iels", 1, fsf_req, ntoh24(buf->d_id), 805 (void *)buf->payload.data, length); 806 } 807 808 static int zfcp_dbf_san_view_format(debug_info_t *id, struct debug_view *view, 809 char *out_buf, const char *in_buf) 810 { 811 struct zfcp_dbf_san_record *r = (struct zfcp_dbf_san_record *)in_buf; 812 char *p = out_buf; 813 814 if (strncmp(r->tag, "dump", ZFCP_DBF_TAG_SIZE) == 0) 815 return 0; 816 817 zfcp_dbf_tag(&p, "tag", r->tag); 818 zfcp_dbf_out(&p, "fsf_reqid", "0x%0Lx", r->fsf_reqid); 819 zfcp_dbf_out(&p, "fsf_seqno", "0x%08x", r->fsf_seqno); 820 821 if (strncmp(r->tag, "octc", ZFCP_DBF_TAG_SIZE) == 0) { 822 struct zfcp_dbf_san_record_ct_request *ct = &r->u.ct_req; 823 zfcp_dbf_out(&p, "d_id", "0x%06x", ct->d_id); 824 zfcp_dbf_out(&p, "cmd_req_code", "0x%04x", ct->cmd_req_code); 825 zfcp_dbf_out(&p, "revision", "0x%02x", ct->revision); 826 zfcp_dbf_out(&p, "gs_type", "0x%02x", ct->gs_type); 827 zfcp_dbf_out(&p, "gs_subtype", "0x%02x", ct->gs_subtype); 828 zfcp_dbf_out(&p, "options", "0x%02x", ct->options); 829 zfcp_dbf_out(&p, "max_res_size", "0x%04x", ct->max_res_size); 830 } else if (strncmp(r->tag, "rctc", ZFCP_DBF_TAG_SIZE) == 0) { 831 struct zfcp_dbf_san_record_ct_response *ct = &r->u.ct_resp; 832 zfcp_dbf_out(&p, "cmd_rsp_code", "0x%04x", ct->cmd_rsp_code); 833 zfcp_dbf_out(&p, "revision", "0x%02x", ct->revision); 834 zfcp_dbf_out(&p, "reason_code", "0x%02x", ct->reason_code); 835 zfcp_dbf_out(&p, "reason_code_expl", "0x%02x", ct->expl); 836 zfcp_dbf_out(&p, "vendor_unique", "0x%02x", ct->vendor_unique); 837 zfcp_dbf_out(&p, "max_res_size", "0x%04x", ct->max_res_size); 838 } else if (strncmp(r->tag, "oels", ZFCP_DBF_TAG_SIZE) == 0 || 839 strncmp(r->tag, "rels", ZFCP_DBF_TAG_SIZE) == 0 || 840 strncmp(r->tag, "iels", ZFCP_DBF_TAG_SIZE) == 0) { 841 struct zfcp_dbf_san_record_els *els = &r->u.els; 842 zfcp_dbf_out(&p, "d_id", "0x%06x", els->d_id); 843 } 844 return p - out_buf; 845 } 846 847 static struct debug_view zfcp_dbf_san_view = { 848 .name = "structured", 849 .header_proc = zfcp_dbf_view_header, 850 .format_proc = zfcp_dbf_san_view_format, 851 }; 852 853 void _zfcp_dbf_scsi(const char *tag, const char *tag2, int level, 854 struct zfcp_dbf *dbf, struct scsi_cmnd *scsi_cmnd, 855 struct zfcp_fsf_req *fsf_req, unsigned long old_req_id) 856 { 857 struct zfcp_dbf_scsi_record *rec = &dbf->scsi_buf; 858 struct zfcp_dbf_dump *dump = (struct zfcp_dbf_dump *)rec; 859 unsigned long flags; 860 struct fcp_resp_with_ext *fcp_rsp; 861 struct fcp_resp_rsp_info *fcp_rsp_info = NULL; 862 char *fcp_sns_info = NULL; 863 int offset = 0, buflen = 0; 864 865 spin_lock_irqsave(&dbf->scsi_lock, flags); 866 do { 867 memset(rec, 0, sizeof(*rec)); 868 if (offset == 0) { 869 strncpy(rec->tag, tag, ZFCP_DBF_TAG_SIZE); 870 strncpy(rec->tag2, tag2, ZFCP_DBF_TAG_SIZE); 871 if (scsi_cmnd != NULL) { 872 if (scsi_cmnd->device) { 873 rec->scsi_id = scsi_cmnd->device->id; 874 rec->scsi_lun = scsi_cmnd->device->lun; 875 } 876 rec->scsi_result = scsi_cmnd->result; 877 rec->scsi_cmnd = (unsigned long)scsi_cmnd; 878 rec->scsi_serial = scsi_cmnd->serial_number; 879 memcpy(rec->scsi_opcode, scsi_cmnd->cmnd, 880 min((int)scsi_cmnd->cmd_len, 881 ZFCP_DBF_SCSI_OPCODE)); 882 rec->scsi_retries = scsi_cmnd->retries; 883 rec->scsi_allowed = scsi_cmnd->allowed; 884 } 885 if (fsf_req != NULL) { 886 fcp_rsp = (struct fcp_resp_with_ext *) 887 &(fsf_req->qtcb->bottom.io.fcp_rsp); 888 fcp_rsp_info = (struct fcp_resp_rsp_info *) 889 &fcp_rsp[1]; 890 fcp_sns_info = (char *) &fcp_rsp[1]; 891 if (fcp_rsp->resp.fr_flags & FCP_RSP_LEN_VAL) 892 fcp_sns_info += fcp_rsp->ext.fr_sns_len; 893 894 rec->rsp_validity = fcp_rsp->resp.fr_flags; 895 rec->rsp_scsi_status = fcp_rsp->resp.fr_status; 896 rec->rsp_resid = fcp_rsp->ext.fr_resid; 897 if (fcp_rsp->resp.fr_flags & FCP_RSP_LEN_VAL) 898 rec->rsp_code = fcp_rsp_info->rsp_code; 899 if (fcp_rsp->resp.fr_flags & FCP_SNS_LEN_VAL) { 900 buflen = min(fcp_rsp->ext.fr_sns_len, 901 (u32)ZFCP_DBF_SCSI_MAX_FCP_SNS_INFO); 902 rec->sns_info_len = buflen; 903 memcpy(rec->sns_info, fcp_sns_info, 904 min(buflen, 905 ZFCP_DBF_SCSI_FCP_SNS_INFO)); 906 offset += min(buflen, 907 ZFCP_DBF_SCSI_FCP_SNS_INFO); 908 } 909 910 rec->fsf_reqid = fsf_req->req_id; 911 rec->fsf_seqno = fsf_req->seq_no; 912 rec->fsf_issued = fsf_req->issued; 913 } 914 rec->old_fsf_reqid = old_req_id; 915 } else { 916 strncpy(dump->tag, "dump", ZFCP_DBF_TAG_SIZE); 917 dump->total_size = buflen; 918 dump->offset = offset; 919 dump->size = min(buflen - offset, 920 (int)sizeof(struct 921 zfcp_dbf_scsi_record) - 922 (int)sizeof(struct zfcp_dbf_dump)); 923 memcpy(dump->data, fcp_sns_info + offset, dump->size); 924 offset += dump->size; 925 } 926 debug_event(dbf->scsi, level, rec, sizeof(*rec)); 927 } while (offset < buflen); 928 spin_unlock_irqrestore(&dbf->scsi_lock, flags); 929 } 930 931 static int zfcp_dbf_scsi_view_format(debug_info_t *id, struct debug_view *view, 932 char *out_buf, const char *in_buf) 933 { 934 struct zfcp_dbf_scsi_record *r = (struct zfcp_dbf_scsi_record *)in_buf; 935 struct timespec t; 936 char *p = out_buf; 937 938 if (strncmp(r->tag, "dump", ZFCP_DBF_TAG_SIZE) == 0) 939 return 0; 940 941 zfcp_dbf_tag(&p, "tag", r->tag); 942 zfcp_dbf_tag(&p, "tag2", r->tag2); 943 zfcp_dbf_out(&p, "scsi_id", "0x%08x", r->scsi_id); 944 zfcp_dbf_out(&p, "scsi_lun", "0x%08x", r->scsi_lun); 945 zfcp_dbf_out(&p, "scsi_result", "0x%08x", r->scsi_result); 946 zfcp_dbf_out(&p, "scsi_cmnd", "0x%0Lx", r->scsi_cmnd); 947 zfcp_dbf_out(&p, "scsi_serial", "0x%016Lx", r->scsi_serial); 948 zfcp_dbf_outd(&p, "scsi_opcode", r->scsi_opcode, ZFCP_DBF_SCSI_OPCODE, 949 0, ZFCP_DBF_SCSI_OPCODE); 950 zfcp_dbf_out(&p, "scsi_retries", "0x%02x", r->scsi_retries); 951 zfcp_dbf_out(&p, "scsi_allowed", "0x%02x", r->scsi_allowed); 952 if (strncmp(r->tag, "abrt", ZFCP_DBF_TAG_SIZE) == 0) 953 zfcp_dbf_out(&p, "old_fsf_reqid", "0x%0Lx", r->old_fsf_reqid); 954 zfcp_dbf_out(&p, "fsf_reqid", "0x%0Lx", r->fsf_reqid); 955 zfcp_dbf_out(&p, "fsf_seqno", "0x%08x", r->fsf_seqno); 956 stck_to_timespec(r->fsf_issued, &t); 957 zfcp_dbf_out(&p, "fsf_issued", "%011lu:%06lu", t.tv_sec, t.tv_nsec); 958 959 if (strncmp(r->tag, "rslt", ZFCP_DBF_TAG_SIZE) == 0) { 960 zfcp_dbf_out(&p, "fcp_rsp_validity", "0x%02x", r->rsp_validity); 961 zfcp_dbf_out(&p, "fcp_rsp_scsi_status", "0x%02x", 962 r->rsp_scsi_status); 963 zfcp_dbf_out(&p, "fcp_rsp_resid", "0x%08x", r->rsp_resid); 964 zfcp_dbf_out(&p, "fcp_rsp_code", "0x%08x", r->rsp_code); 965 zfcp_dbf_out(&p, "fcp_sns_info_len", "0x%08x", r->sns_info_len); 966 zfcp_dbf_outd(&p, "fcp_sns_info", r->sns_info, 967 min((int)r->sns_info_len, 968 ZFCP_DBF_SCSI_FCP_SNS_INFO), 0, 969 r->sns_info_len); 970 } 971 p += sprintf(p, "\n"); 972 return p - out_buf; 973 } 974 975 static struct debug_view zfcp_dbf_scsi_view = { 976 .name = "structured", 977 .header_proc = zfcp_dbf_view_header, 978 .format_proc = zfcp_dbf_scsi_view_format, 979 }; 980 981 static debug_info_t *zfcp_dbf_reg(const char *name, int level, 982 struct debug_view *view, int size) 983 { 984 struct debug_info *d; 985 986 d = debug_register(name, dbfsize, level, size); 987 if (!d) 988 return NULL; 989 990 debug_register_view(d, &debug_hex_ascii_view); 991 debug_register_view(d, view); 992 debug_set_level(d, level); 993 994 return d; 995 } 996 997 /** 998 * zfcp_adapter_debug_register - registers debug feature for an adapter 999 * @adapter: pointer to adapter for which debug features should be registered 1000 * return: -ENOMEM on error, 0 otherwise 1001 */ 1002 int zfcp_dbf_adapter_register(struct zfcp_adapter *adapter) 1003 { 1004 char dbf_name[DEBUG_MAX_NAME_LEN]; 1005 struct zfcp_dbf *dbf; 1006 1007 dbf = kmalloc(sizeof(struct zfcp_dbf), GFP_KERNEL); 1008 if (!dbf) 1009 return -ENOMEM; 1010 1011 dbf->adapter = adapter; 1012 1013 spin_lock_init(&dbf->hba_lock); 1014 spin_lock_init(&dbf->san_lock); 1015 spin_lock_init(&dbf->scsi_lock); 1016 spin_lock_init(&dbf->rec_lock); 1017 1018 /* debug feature area which records recovery activity */ 1019 sprintf(dbf_name, "zfcp_%s_rec", dev_name(&adapter->ccw_device->dev)); 1020 dbf->rec = zfcp_dbf_reg(dbf_name, 3, &zfcp_dbf_rec_view, 1021 sizeof(struct zfcp_dbf_rec_record)); 1022 if (!dbf->rec) 1023 goto err_out; 1024 1025 /* debug feature area which records HBA (FSF and QDIO) conditions */ 1026 sprintf(dbf_name, "zfcp_%s_hba", dev_name(&adapter->ccw_device->dev)); 1027 dbf->hba = zfcp_dbf_reg(dbf_name, 3, &zfcp_dbf_hba_view, 1028 sizeof(struct zfcp_dbf_hba_record)); 1029 if (!dbf->hba) 1030 goto err_out; 1031 1032 /* debug feature area which records SAN command failures and recovery */ 1033 sprintf(dbf_name, "zfcp_%s_san", dev_name(&adapter->ccw_device->dev)); 1034 dbf->san = zfcp_dbf_reg(dbf_name, 6, &zfcp_dbf_san_view, 1035 sizeof(struct zfcp_dbf_san_record)); 1036 if (!dbf->san) 1037 goto err_out; 1038 1039 /* debug feature area which records SCSI command failures and recovery */ 1040 sprintf(dbf_name, "zfcp_%s_scsi", dev_name(&adapter->ccw_device->dev)); 1041 dbf->scsi = zfcp_dbf_reg(dbf_name, 3, &zfcp_dbf_scsi_view, 1042 sizeof(struct zfcp_dbf_scsi_record)); 1043 if (!dbf->scsi) 1044 goto err_out; 1045 1046 adapter->dbf = dbf; 1047 return 0; 1048 1049 err_out: 1050 zfcp_dbf_adapter_unregister(dbf); 1051 return -ENOMEM; 1052 } 1053 1054 /** 1055 * zfcp_adapter_debug_unregister - unregisters debug feature for an adapter 1056 * @dbf: pointer to dbf for which debug features should be unregistered 1057 */ 1058 void zfcp_dbf_adapter_unregister(struct zfcp_dbf *dbf) 1059 { 1060 if (!dbf) 1061 return; 1062 debug_unregister(dbf->scsi); 1063 debug_unregister(dbf->san); 1064 debug_unregister(dbf->hba); 1065 debug_unregister(dbf->rec); 1066 dbf->adapter->dbf = NULL; 1067 kfree(dbf); 1068 } 1069 1070