4 * Debug traces for zfcp.
6 * Copyright IBM Corp. 2002, 2015
9 #define KMSG_COMPONENT "zfcp"
10 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
12 #include <linux/module.h>
13 #include <linux/ctype.h>
14 #include <linux/slab.h>
15 #include <asm/debug.h>
20 static u32 dbfsize = 4;
22 module_param(dbfsize, uint, 0400);
23 MODULE_PARM_DESC(dbfsize,
24 "number of pages for each debug feature area (default 4)");
26 static u32 dbflevel = 3;
28 module_param(dbflevel, uint, 0400);
29 MODULE_PARM_DESC(dbflevel,
30 "log level for each debug feature area "
31 "(default 3, range 0..6)");
33 static inline unsigned int zfcp_dbf_plen(unsigned int offset)
35 return sizeof(struct zfcp_dbf_pay) + offset - ZFCP_DBF_PAY_MAX_REC;
39 void zfcp_dbf_pl_write(struct zfcp_dbf *dbf, void *data, u16 length, char *area,
42 struct zfcp_dbf_pay *pl = &dbf->pay_buf;
43 u16 offset = 0, rec_length;
45 spin_lock(&dbf->pay_lock);
46 memset(pl, 0, sizeof(*pl));
47 pl->fsf_req_id = req_id;
48 memcpy(pl->area, area, ZFCP_DBF_TAG_LEN);
50 while (offset < length) {
51 rec_length = min((u16) ZFCP_DBF_PAY_MAX_REC,
52 (u16) (length - offset));
53 memcpy(pl->data, data + offset, rec_length);
54 debug_event(dbf->pay, 1, pl, zfcp_dbf_plen(rec_length));
60 spin_unlock(&dbf->pay_lock);
64 * zfcp_dbf_hba_fsf_res - trace event for fsf responses
65 * @tag: tag indicating which kind of unsolicited status has been received
66 * @req: request for which a response was received
68 void zfcp_dbf_hba_fsf_res(char *tag, int level, struct zfcp_fsf_req *req)
70 struct zfcp_dbf *dbf = req->adapter->dbf;
71 struct fsf_qtcb_prefix *q_pref = &req->qtcb->prefix;
72 struct fsf_qtcb_header *q_head = &req->qtcb->header;
73 struct zfcp_dbf_hba *rec = &dbf->hba_buf;
76 spin_lock_irqsave(&dbf->hba_lock, flags);
77 memset(rec, 0, sizeof(*rec));
79 memcpy(rec->tag, tag, ZFCP_DBF_TAG_LEN);
80 rec->id = ZFCP_DBF_HBA_RES;
81 rec->fsf_req_id = req->req_id;
82 rec->fsf_req_status = req->status;
83 rec->fsf_cmd = req->fsf_command;
84 rec->fsf_seq_no = req->seq_no;
85 rec->u.res.req_issued = req->issued;
86 rec->u.res.prot_status = q_pref->prot_status;
87 rec->u.res.fsf_status = q_head->fsf_status;
89 memcpy(rec->u.res.prot_status_qual, &q_pref->prot_status_qual,
90 FSF_PROT_STATUS_QUAL_SIZE);
91 memcpy(rec->u.res.fsf_status_qual, &q_head->fsf_status_qual,
92 FSF_STATUS_QUALIFIER_SIZE);
94 if (req->fsf_command != FSF_QTCB_FCP_CMND) {
95 rec->pl_len = q_head->log_length;
96 zfcp_dbf_pl_write(dbf, (char *)q_pref + q_head->log_start,
97 rec->pl_len, "fsf_res", req->req_id);
100 debug_event(dbf->hba, level, rec, sizeof(*rec));
101 spin_unlock_irqrestore(&dbf->hba_lock, flags);
105 * zfcp_dbf_hba_fsf_uss - trace event for an unsolicited status buffer
106 * @tag: tag indicating which kind of unsolicited status has been received
107 * @req: request providing the unsolicited status
109 void zfcp_dbf_hba_fsf_uss(char *tag, struct zfcp_fsf_req *req)
111 struct zfcp_dbf *dbf = req->adapter->dbf;
112 struct fsf_status_read_buffer *srb = req->data;
113 struct zfcp_dbf_hba *rec = &dbf->hba_buf;
116 spin_lock_irqsave(&dbf->hba_lock, flags);
117 memset(rec, 0, sizeof(*rec));
119 memcpy(rec->tag, tag, ZFCP_DBF_TAG_LEN);
120 rec->id = ZFCP_DBF_HBA_USS;
121 rec->fsf_req_id = req->req_id;
122 rec->fsf_req_status = req->status;
123 rec->fsf_cmd = req->fsf_command;
128 rec->u.uss.status_type = srb->status_type;
129 rec->u.uss.status_subtype = srb->status_subtype;
130 rec->u.uss.d_id = ntoh24(srb->d_id);
131 rec->u.uss.lun = srb->fcp_lun;
132 memcpy(&rec->u.uss.queue_designator, &srb->queue_designator,
133 sizeof(rec->u.uss.queue_designator));
135 /* status read buffer payload length */
136 rec->pl_len = (!srb->length) ? 0 : srb->length -
137 offsetof(struct fsf_status_read_buffer, payload);
140 zfcp_dbf_pl_write(dbf, srb->payload.data, rec->pl_len,
141 "fsf_uss", req->req_id);
143 debug_event(dbf->hba, 2, rec, sizeof(*rec));
144 spin_unlock_irqrestore(&dbf->hba_lock, flags);
148 * zfcp_dbf_hba_bit_err - trace event for bit error conditions
149 * @tag: tag indicating which kind of unsolicited status has been received
150 * @req: request which caused the bit_error condition
152 void zfcp_dbf_hba_bit_err(char *tag, struct zfcp_fsf_req *req)
154 struct zfcp_dbf *dbf = req->adapter->dbf;
155 struct zfcp_dbf_hba *rec = &dbf->hba_buf;
156 struct fsf_status_read_buffer *sr_buf = req->data;
159 spin_lock_irqsave(&dbf->hba_lock, flags);
160 memset(rec, 0, sizeof(*rec));
162 memcpy(rec->tag, tag, ZFCP_DBF_TAG_LEN);
163 rec->id = ZFCP_DBF_HBA_BIT;
164 rec->fsf_req_id = req->req_id;
165 rec->fsf_req_status = req->status;
166 rec->fsf_cmd = req->fsf_command;
167 memcpy(&rec->u.be, &sr_buf->payload.bit_error,
168 sizeof(struct fsf_bit_error_payload));
170 debug_event(dbf->hba, 1, rec, sizeof(*rec));
171 spin_unlock_irqrestore(&dbf->hba_lock, flags);
175 * zfcp_dbf_hba_def_err - trace event for deferred error messages
176 * @adapter: pointer to struct zfcp_adapter
177 * @req_id: request id which caused the deferred error message
178 * @scount: number of sbals incl. the signaling sbal
179 * @pl: array of all involved sbals
181 void zfcp_dbf_hba_def_err(struct zfcp_adapter *adapter, u64 req_id, u16 scount,
184 struct zfcp_dbf *dbf = adapter->dbf;
185 struct zfcp_dbf_pay *payload = &dbf->pay_buf;
192 spin_lock_irqsave(&dbf->pay_lock, flags);
193 memset(payload, 0, sizeof(*payload));
195 memcpy(payload->area, "def_err", 7);
196 payload->fsf_req_id = req_id;
197 payload->counter = 0;
198 length = min((u16)sizeof(struct qdio_buffer),
199 (u16)ZFCP_DBF_PAY_MAX_REC);
201 while (payload->counter < scount && (char *)pl[payload->counter]) {
202 memcpy(payload->data, (char *)pl[payload->counter], length);
203 debug_event(dbf->pay, 1, payload, zfcp_dbf_plen(length));
207 spin_unlock_irqrestore(&dbf->pay_lock, flags);
211 * zfcp_dbf_hba_basic - trace event for basic adapter events
212 * @adapter: pointer to struct zfcp_adapter
214 void zfcp_dbf_hba_basic(char *tag, struct zfcp_adapter *adapter)
216 struct zfcp_dbf *dbf = adapter->dbf;
217 struct zfcp_dbf_hba *rec = &dbf->hba_buf;
220 spin_lock_irqsave(&dbf->hba_lock, flags);
221 memset(rec, 0, sizeof(*rec));
223 memcpy(rec->tag, tag, ZFCP_DBF_TAG_LEN);
224 rec->id = ZFCP_DBF_HBA_BASIC;
226 debug_event(dbf->hba, 1, rec, sizeof(*rec));
227 spin_unlock_irqrestore(&dbf->hba_lock, flags);
230 static void zfcp_dbf_set_common(struct zfcp_dbf_rec *rec,
231 struct zfcp_adapter *adapter,
232 struct zfcp_port *port,
233 struct scsi_device *sdev)
235 rec->adapter_status = atomic_read(&adapter->status);
237 rec->port_status = atomic_read(&port->status);
238 rec->wwpn = port->wwpn;
239 rec->d_id = port->d_id;
242 rec->lun_status = atomic_read(&sdev_to_zfcp(sdev)->status);
243 rec->lun = zfcp_scsi_dev_lun(sdev);
245 rec->lun = ZFCP_DBF_INVALID_LUN;
249 * zfcp_dbf_rec_trig - trace event related to triggered recovery
250 * @tag: identifier for event
251 * @adapter: adapter on which the erp_action should run
252 * @port: remote port involved in the erp_action
253 * @sdev: scsi device involved in the erp_action
254 * @want: wanted erp_action
255 * @need: required erp_action
257 * The adapter->erp_lock has to be held.
259 void zfcp_dbf_rec_trig(char *tag, struct zfcp_adapter *adapter,
260 struct zfcp_port *port, struct scsi_device *sdev,
263 struct zfcp_dbf *dbf = adapter->dbf;
264 struct zfcp_dbf_rec *rec = &dbf->rec_buf;
265 struct list_head *entry;
268 spin_lock_irqsave(&dbf->rec_lock, flags);
269 memset(rec, 0, sizeof(*rec));
271 rec->id = ZFCP_DBF_REC_TRIG;
272 memcpy(rec->tag, tag, ZFCP_DBF_TAG_LEN);
273 zfcp_dbf_set_common(rec, adapter, port, sdev);
275 list_for_each(entry, &adapter->erp_ready_head)
278 list_for_each(entry, &adapter->erp_running_head)
279 rec->u.trig.running++;
281 rec->u.trig.want = want;
282 rec->u.trig.need = need;
284 debug_event(dbf->rec, 1, rec, sizeof(*rec));
285 spin_unlock_irqrestore(&dbf->rec_lock, flags);
290 * zfcp_dbf_rec_run - trace event related to running recovery
291 * @tag: identifier for event
292 * @erp: erp_action running
294 void zfcp_dbf_rec_run(char *tag, struct zfcp_erp_action *erp)
296 struct zfcp_dbf *dbf = erp->adapter->dbf;
297 struct zfcp_dbf_rec *rec = &dbf->rec_buf;
300 spin_lock_irqsave(&dbf->rec_lock, flags);
301 memset(rec, 0, sizeof(*rec));
303 rec->id = ZFCP_DBF_REC_RUN;
304 memcpy(rec->tag, tag, ZFCP_DBF_TAG_LEN);
305 zfcp_dbf_set_common(rec, erp->adapter, erp->port, erp->sdev);
307 rec->u.run.fsf_req_id = erp->fsf_req_id;
308 rec->u.run.rec_status = erp->status;
309 rec->u.run.rec_step = erp->step;
310 rec->u.run.rec_action = erp->action;
313 rec->u.run.rec_count =
314 atomic_read(&sdev_to_zfcp(erp->sdev)->erp_counter);
316 rec->u.run.rec_count = atomic_read(&erp->port->erp_counter);
318 rec->u.run.rec_count = atomic_read(&erp->adapter->erp_counter);
320 debug_event(dbf->rec, 1, rec, sizeof(*rec));
321 spin_unlock_irqrestore(&dbf->rec_lock, flags);
325 * zfcp_dbf_rec_run_wka - trace wka port event with info like running recovery
326 * @tag: identifier for event
327 * @wka_port: well known address port
328 * @req_id: request ID to correlate with potential HBA trace record
330 void zfcp_dbf_rec_run_wka(char *tag, struct zfcp_fc_wka_port *wka_port,
333 struct zfcp_dbf *dbf = wka_port->adapter->dbf;
334 struct zfcp_dbf_rec *rec = &dbf->rec_buf;
337 spin_lock_irqsave(&dbf->rec_lock, flags);
338 memset(rec, 0, sizeof(*rec));
340 rec->id = ZFCP_DBF_REC_RUN;
341 memcpy(rec->tag, tag, ZFCP_DBF_TAG_LEN);
342 rec->port_status = wka_port->status;
343 rec->d_id = wka_port->d_id;
344 rec->lun = ZFCP_DBF_INVALID_LUN;
346 rec->u.run.fsf_req_id = req_id;
347 rec->u.run.rec_status = ~0;
348 rec->u.run.rec_step = ~0;
349 rec->u.run.rec_action = ~0;
350 rec->u.run.rec_count = ~0;
352 debug_event(dbf->rec, 1, rec, sizeof(*rec));
353 spin_unlock_irqrestore(&dbf->rec_lock, flags);
357 void zfcp_dbf_san(char *tag, struct zfcp_dbf *dbf, void *data, u8 id, u16 len,
358 u64 req_id, u32 d_id)
360 struct zfcp_dbf_san *rec = &dbf->san_buf;
364 spin_lock_irqsave(&dbf->san_lock, flags);
365 memset(rec, 0, sizeof(*rec));
368 rec->fsf_req_id = req_id;
370 rec_len = min(len, (u16)ZFCP_DBF_SAN_MAX_PAYLOAD);
371 memcpy(rec->payload, data, rec_len);
372 memcpy(rec->tag, tag, ZFCP_DBF_TAG_LEN);
374 debug_event(dbf->san, 1, rec, sizeof(*rec));
375 spin_unlock_irqrestore(&dbf->san_lock, flags);
379 * zfcp_dbf_san_req - trace event for issued SAN request
380 * @tag: identifier for event
381 * @fsf_req: request containing issued CT data
382 * d_id: destination ID
384 void zfcp_dbf_san_req(char *tag, struct zfcp_fsf_req *fsf, u32 d_id)
386 struct zfcp_dbf *dbf = fsf->adapter->dbf;
387 struct zfcp_fsf_ct_els *ct_els = fsf->data;
390 length = (u16)(ct_els->req->length + FC_CT_HDR_LEN);
391 zfcp_dbf_san(tag, dbf, sg_virt(ct_els->req), ZFCP_DBF_SAN_REQ, length,
396 * zfcp_dbf_san_res - trace event for received SAN request
397 * @tag: identifier for event
398 * @fsf_req: request containing issued CT data
400 void zfcp_dbf_san_res(char *tag, struct zfcp_fsf_req *fsf)
402 struct zfcp_dbf *dbf = fsf->adapter->dbf;
403 struct zfcp_fsf_ct_els *ct_els = fsf->data;
406 length = (u16)(ct_els->resp->length + FC_CT_HDR_LEN);
407 zfcp_dbf_san(tag, dbf, sg_virt(ct_els->resp), ZFCP_DBF_SAN_RES, length,
412 * zfcp_dbf_san_in_els - trace event for incoming ELS
413 * @tag: identifier for event
414 * @fsf_req: request containing issued CT data
416 void zfcp_dbf_san_in_els(char *tag, struct zfcp_fsf_req *fsf)
418 struct zfcp_dbf *dbf = fsf->adapter->dbf;
419 struct fsf_status_read_buffer *srb =
420 (struct fsf_status_read_buffer *) fsf->data;
423 length = (u16)(srb->length -
424 offsetof(struct fsf_status_read_buffer, payload));
425 zfcp_dbf_san(tag, dbf, srb->payload.data, ZFCP_DBF_SAN_ELS, length,
426 fsf->req_id, ntoh24(srb->d_id));
430 * zfcp_dbf_scsi - trace event for scsi commands
431 * @tag: identifier for event
432 * @sc: pointer to struct scsi_cmnd
433 * @fsf: pointer to struct zfcp_fsf_req
435 void zfcp_dbf_scsi(char *tag, int level, struct scsi_cmnd *sc,
436 struct zfcp_fsf_req *fsf)
438 struct zfcp_adapter *adapter =
439 (struct zfcp_adapter *) sc->device->host->hostdata[0];
440 struct zfcp_dbf *dbf = adapter->dbf;
441 struct zfcp_dbf_scsi *rec = &dbf->scsi_buf;
442 struct fcp_resp_with_ext *fcp_rsp;
443 struct fcp_resp_rsp_info *fcp_rsp_info;
446 spin_lock_irqsave(&dbf->scsi_lock, flags);
447 memset(rec, 0, sizeof(*rec));
449 memcpy(rec->tag, tag, ZFCP_DBF_TAG_LEN);
450 rec->id = ZFCP_DBF_SCSI_CMND;
451 rec->scsi_result = sc->result;
452 rec->scsi_retries = sc->retries;
453 rec->scsi_allowed = sc->allowed;
454 rec->scsi_id = sc->device->id;
455 /* struct zfcp_dbf_scsi needs to be updated to handle 64bit LUNs */
456 rec->scsi_lun = (u32)sc->device->lun;
457 rec->host_scribble = (unsigned long)sc->host_scribble;
459 memcpy(rec->scsi_opcode, sc->cmnd,
460 min((int)sc->cmd_len, ZFCP_DBF_SCSI_OPCODE));
463 rec->fsf_req_id = fsf->req_id;
464 fcp_rsp = (struct fcp_resp_with_ext *)
465 &(fsf->qtcb->bottom.io.fcp_rsp);
466 memcpy(&rec->fcp_rsp, fcp_rsp, FCP_RESP_WITH_EXT);
467 if (fcp_rsp->resp.fr_flags & FCP_RSP_LEN_VAL) {
468 fcp_rsp_info = (struct fcp_resp_rsp_info *) &fcp_rsp[1];
469 rec->fcp_rsp_info = fcp_rsp_info->rsp_code;
471 if (fcp_rsp->resp.fr_flags & FCP_SNS_LEN_VAL) {
472 rec->pl_len = min((u16)SCSI_SENSE_BUFFERSIZE,
473 (u16)ZFCP_DBF_PAY_MAX_REC);
474 zfcp_dbf_pl_write(dbf, sc->sense_buffer, rec->pl_len,
475 "fcp_sns", fsf->req_id);
479 debug_event(dbf->scsi, level, rec, sizeof(*rec));
480 spin_unlock_irqrestore(&dbf->scsi_lock, flags);
483 static debug_info_t *zfcp_dbf_reg(const char *name, int size, int rec_size)
485 struct debug_info *d;
487 d = debug_register(name, size, 1, rec_size);
491 debug_register_view(d, &debug_hex_ascii_view);
492 debug_set_level(d, dbflevel);
497 static void zfcp_dbf_unregister(struct zfcp_dbf *dbf)
502 debug_unregister(dbf->scsi);
503 debug_unregister(dbf->san);
504 debug_unregister(dbf->hba);
505 debug_unregister(dbf->pay);
506 debug_unregister(dbf->rec);
511 * zfcp_adapter_debug_register - registers debug feature for an adapter
512 * @adapter: pointer to adapter for which debug features should be registered
513 * return: -ENOMEM on error, 0 otherwise
515 int zfcp_dbf_adapter_register(struct zfcp_adapter *adapter)
517 char name[DEBUG_MAX_NAME_LEN];
518 struct zfcp_dbf *dbf;
520 dbf = kzalloc(sizeof(struct zfcp_dbf), GFP_KERNEL);
524 spin_lock_init(&dbf->pay_lock);
525 spin_lock_init(&dbf->hba_lock);
526 spin_lock_init(&dbf->san_lock);
527 spin_lock_init(&dbf->scsi_lock);
528 spin_lock_init(&dbf->rec_lock);
530 /* debug feature area which records recovery activity */
531 sprintf(name, "zfcp_%s_rec", dev_name(&adapter->ccw_device->dev));
532 dbf->rec = zfcp_dbf_reg(name, dbfsize, sizeof(struct zfcp_dbf_rec));
536 /* debug feature area which records HBA (FSF and QDIO) conditions */
537 sprintf(name, "zfcp_%s_hba", dev_name(&adapter->ccw_device->dev));
538 dbf->hba = zfcp_dbf_reg(name, dbfsize, sizeof(struct zfcp_dbf_hba));
542 /* debug feature area which records payload info */
543 sprintf(name, "zfcp_%s_pay", dev_name(&adapter->ccw_device->dev));
544 dbf->pay = zfcp_dbf_reg(name, dbfsize * 2, sizeof(struct zfcp_dbf_pay));
548 /* debug feature area which records SAN command failures and recovery */
549 sprintf(name, "zfcp_%s_san", dev_name(&adapter->ccw_device->dev));
550 dbf->san = zfcp_dbf_reg(name, dbfsize, sizeof(struct zfcp_dbf_san));
554 /* debug feature area which records SCSI command failures and recovery */
555 sprintf(name, "zfcp_%s_scsi", dev_name(&adapter->ccw_device->dev));
556 dbf->scsi = zfcp_dbf_reg(name, dbfsize, sizeof(struct zfcp_dbf_scsi));
564 zfcp_dbf_unregister(dbf);
569 * zfcp_adapter_debug_unregister - unregisters debug feature for an adapter
570 * @adapter: pointer to adapter for which debug features should be unregistered
572 void zfcp_dbf_adapter_unregister(struct zfcp_adapter *adapter)
574 struct zfcp_dbf *dbf = adapter->dbf;
577 zfcp_dbf_unregister(dbf);