1 // SPDX-License-Identifier: GPL-2.0
5 * Debug traces for zfcp.
7 * Copyright IBM Corp. 2002, 2020
10 #define KMSG_COMPONENT "zfcp"
11 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
13 #include <linux/module.h>
14 #include <linux/ctype.h>
15 #include <linux/slab.h>
16 #include <asm/debug.h>
21 static u32 dbfsize = 4;
23 module_param(dbfsize, uint, 0400);
24 MODULE_PARM_DESC(dbfsize,
25 "number of pages for each debug feature area (default 4)");
27 static u32 dbflevel = 3;
29 module_param(dbflevel, uint, 0400);
30 MODULE_PARM_DESC(dbflevel,
31 "log level for each debug feature area "
32 "(default 3, range 0..6)");
34 static inline unsigned int zfcp_dbf_plen(unsigned int offset)
36 return sizeof(struct zfcp_dbf_pay) + offset - ZFCP_DBF_PAY_MAX_REC;
40 void zfcp_dbf_pl_write(struct zfcp_dbf *dbf, void *data, u16 length, char *area,
43 struct zfcp_dbf_pay *pl = &dbf->pay_buf;
44 u16 offset = 0, rec_length;
46 spin_lock(&dbf->pay_lock);
47 memset(pl, 0, sizeof(*pl));
48 pl->fsf_req_id = req_id;
49 memcpy(pl->area, area, ZFCP_DBF_TAG_LEN);
51 while (offset < length) {
52 rec_length = min((u16) ZFCP_DBF_PAY_MAX_REC,
53 (u16) (length - offset));
54 memcpy(pl->data, data + offset, rec_length);
55 debug_event(dbf->pay, 1, pl, zfcp_dbf_plen(rec_length));
61 spin_unlock(&dbf->pay_lock);
65 * zfcp_dbf_hba_fsf_res - trace event for fsf responses
66 * @tag: tag indicating which kind of FSF response has been received
67 * @level: trace level to be used for event
68 * @req: request for which a response was received
70 void zfcp_dbf_hba_fsf_res(char *tag, int level, struct zfcp_fsf_req *req)
72 struct zfcp_dbf *dbf = req->adapter->dbf;
73 struct fsf_qtcb_prefix *q_pref = &req->qtcb->prefix;
74 struct fsf_qtcb_header *q_head = &req->qtcb->header;
75 struct zfcp_dbf_hba *rec = &dbf->hba_buf;
78 spin_lock_irqsave(&dbf->hba_lock, flags);
79 memset(rec, 0, sizeof(*rec));
81 memcpy(rec->tag, tag, ZFCP_DBF_TAG_LEN);
82 rec->id = ZFCP_DBF_HBA_RES;
83 rec->fsf_req_id = req->req_id;
84 rec->fsf_req_status = req->status;
85 rec->fsf_cmd = q_head->fsf_command;
86 rec->fsf_seq_no = q_pref->req_seq_no;
87 rec->u.res.req_issued = req->issued;
88 rec->u.res.prot_status = q_pref->prot_status;
89 rec->u.res.fsf_status = q_head->fsf_status;
90 rec->u.res.port_handle = q_head->port_handle;
91 rec->u.res.lun_handle = q_head->lun_handle;
93 memcpy(rec->u.res.prot_status_qual, &q_pref->prot_status_qual,
94 FSF_PROT_STATUS_QUAL_SIZE);
95 memcpy(rec->u.res.fsf_status_qual, &q_head->fsf_status_qual,
96 FSF_STATUS_QUALIFIER_SIZE);
98 rec->pl_len = q_head->log_length;
99 zfcp_dbf_pl_write(dbf, (char *)q_pref + q_head->log_start,
100 rec->pl_len, "fsf_res", req->req_id);
102 debug_event(dbf->hba, level, rec, sizeof(*rec));
103 spin_unlock_irqrestore(&dbf->hba_lock, flags);
107 * zfcp_dbf_hba_fsf_fces - trace event for fsf responses related to
108 * FC Endpoint Security (FCES)
109 * @tag: tag indicating which kind of FC Endpoint Security event has occurred
110 * @req: request for which a response was received
111 * @wwpn: remote port or ZFCP_DBF_INVALID_WWPN
112 * @fc_security_old: old FC Endpoint Security of FCP device or connection
113 * @fc_security_new: new FC Endpoint Security of FCP device or connection
115 void zfcp_dbf_hba_fsf_fces(char *tag, const struct zfcp_fsf_req *req, u64 wwpn,
116 u32 fc_security_old, u32 fc_security_new)
118 struct zfcp_dbf *dbf = req->adapter->dbf;
119 struct fsf_qtcb_prefix *q_pref = &req->qtcb->prefix;
120 struct fsf_qtcb_header *q_head = &req->qtcb->header;
121 struct zfcp_dbf_hba *rec = &dbf->hba_buf;
122 static int const level = 3;
125 if (unlikely(!debug_level_enabled(dbf->hba, level)))
128 spin_lock_irqsave(&dbf->hba_lock, flags);
129 memset(rec, 0, sizeof(*rec));
131 memcpy(rec->tag, tag, ZFCP_DBF_TAG_LEN);
132 rec->id = ZFCP_DBF_HBA_FCES;
133 rec->fsf_req_id = req->req_id;
134 rec->fsf_req_status = req->status;
135 rec->fsf_cmd = q_head->fsf_command;
136 rec->fsf_seq_no = q_pref->req_seq_no;
137 rec->u.fces.req_issued = req->issued;
138 rec->u.fces.fsf_status = q_head->fsf_status;
139 rec->u.fces.port_handle = q_head->port_handle;
140 rec->u.fces.wwpn = wwpn;
141 rec->u.fces.fc_security_old = fc_security_old;
142 rec->u.fces.fc_security_new = fc_security_new;
144 debug_event(dbf->hba, level, rec, sizeof(*rec));
145 spin_unlock_irqrestore(&dbf->hba_lock, flags);
149 * zfcp_dbf_hba_fsf_uss - trace event for an unsolicited status buffer
150 * @tag: tag indicating which kind of unsolicited status has been received
151 * @req: request providing the unsolicited status
153 void zfcp_dbf_hba_fsf_uss(char *tag, struct zfcp_fsf_req *req)
155 struct zfcp_dbf *dbf = req->adapter->dbf;
156 struct fsf_status_read_buffer *srb = req->data;
157 struct zfcp_dbf_hba *rec = &dbf->hba_buf;
158 static int const level = 2;
161 if (unlikely(!debug_level_enabled(dbf->hba, level)))
164 spin_lock_irqsave(&dbf->hba_lock, flags);
165 memset(rec, 0, sizeof(*rec));
167 memcpy(rec->tag, tag, ZFCP_DBF_TAG_LEN);
168 rec->id = ZFCP_DBF_HBA_USS;
169 rec->fsf_req_id = req->req_id;
170 rec->fsf_req_status = req->status;
171 rec->fsf_cmd = FSF_QTCB_UNSOLICITED_STATUS;
176 rec->u.uss.status_type = srb->status_type;
177 rec->u.uss.status_subtype = srb->status_subtype;
178 rec->u.uss.d_id = ntoh24(srb->d_id);
179 rec->u.uss.lun = srb->fcp_lun;
180 memcpy(&rec->u.uss.queue_designator, &srb->queue_designator,
181 sizeof(rec->u.uss.queue_designator));
183 /* status read buffer payload length */
184 rec->pl_len = (!srb->length) ? 0 : srb->length -
185 offsetof(struct fsf_status_read_buffer, payload);
188 zfcp_dbf_pl_write(dbf, srb->payload.data, rec->pl_len,
189 "fsf_uss", req->req_id);
191 debug_event(dbf->hba, level, rec, sizeof(*rec));
192 spin_unlock_irqrestore(&dbf->hba_lock, flags);
196 * zfcp_dbf_hba_bit_err - trace event for bit error conditions
197 * @tag: tag indicating which kind of bit error unsolicited status was received
198 * @req: request which caused the bit_error condition
200 void zfcp_dbf_hba_bit_err(char *tag, struct zfcp_fsf_req *req)
202 struct zfcp_dbf *dbf = req->adapter->dbf;
203 struct zfcp_dbf_hba *rec = &dbf->hba_buf;
204 struct fsf_status_read_buffer *sr_buf = req->data;
205 static int const level = 1;
208 if (unlikely(!debug_level_enabled(dbf->hba, level)))
211 spin_lock_irqsave(&dbf->hba_lock, flags);
212 memset(rec, 0, sizeof(*rec));
214 memcpy(rec->tag, tag, ZFCP_DBF_TAG_LEN);
215 rec->id = ZFCP_DBF_HBA_BIT;
216 rec->fsf_req_id = req->req_id;
217 rec->fsf_req_status = req->status;
218 rec->fsf_cmd = FSF_QTCB_UNSOLICITED_STATUS;
219 memcpy(&rec->u.be, &sr_buf->payload.bit_error,
220 sizeof(struct fsf_bit_error_payload));
222 debug_event(dbf->hba, level, rec, sizeof(*rec));
223 spin_unlock_irqrestore(&dbf->hba_lock, flags);
227 * zfcp_dbf_hba_def_err - trace event for deferred error messages
228 * @adapter: pointer to struct zfcp_adapter
229 * @req_id: request id which caused the deferred error message
230 * @scount: number of sbals incl. the signaling sbal
231 * @pl: array of all involved sbals
233 void zfcp_dbf_hba_def_err(struct zfcp_adapter *adapter, u64 req_id, u16 scount,
236 struct zfcp_dbf *dbf = adapter->dbf;
237 struct zfcp_dbf_pay *payload = &dbf->pay_buf;
239 static int const level = 1;
242 if (unlikely(!debug_level_enabled(dbf->pay, level)))
248 spin_lock_irqsave(&dbf->pay_lock, flags);
249 memset(payload, 0, sizeof(*payload));
251 memcpy(payload->area, "def_err", 7);
252 payload->fsf_req_id = req_id;
253 payload->counter = 0;
254 length = min((u16)sizeof(struct qdio_buffer),
255 (u16)ZFCP_DBF_PAY_MAX_REC);
257 while (payload->counter < scount && (char *)pl[payload->counter]) {
258 memcpy(payload->data, (char *)pl[payload->counter], length);
259 debug_event(dbf->pay, level, payload, zfcp_dbf_plen(length));
263 spin_unlock_irqrestore(&dbf->pay_lock, flags);
267 * zfcp_dbf_hba_basic - trace event for basic adapter events
268 * @tag: identifier for event
269 * @adapter: pointer to struct zfcp_adapter
271 void zfcp_dbf_hba_basic(char *tag, struct zfcp_adapter *adapter)
273 struct zfcp_dbf *dbf = adapter->dbf;
274 struct zfcp_dbf_hba *rec = &dbf->hba_buf;
275 static int const level = 1;
278 if (unlikely(!debug_level_enabled(dbf->hba, level)))
281 spin_lock_irqsave(&dbf->hba_lock, flags);
282 memset(rec, 0, sizeof(*rec));
284 memcpy(rec->tag, tag, ZFCP_DBF_TAG_LEN);
285 rec->id = ZFCP_DBF_HBA_BASIC;
287 debug_event(dbf->hba, level, rec, sizeof(*rec));
288 spin_unlock_irqrestore(&dbf->hba_lock, flags);
291 static void zfcp_dbf_set_common(struct zfcp_dbf_rec *rec,
292 struct zfcp_adapter *adapter,
293 struct zfcp_port *port,
294 struct scsi_device *sdev)
296 rec->adapter_status = atomic_read(&adapter->status);
298 rec->port_status = atomic_read(&port->status);
299 rec->wwpn = port->wwpn;
300 rec->d_id = port->d_id;
303 rec->lun_status = atomic_read(&sdev_to_zfcp(sdev)->status);
304 rec->lun = zfcp_scsi_dev_lun(sdev);
306 rec->lun = ZFCP_DBF_INVALID_LUN;
310 * zfcp_dbf_rec_trig - trace event related to triggered recovery
311 * @tag: identifier for event
312 * @adapter: adapter on which the erp_action should run
313 * @port: remote port involved in the erp_action
314 * @sdev: scsi device involved in the erp_action
315 * @want: wanted erp_action
316 * @need: required erp_action
318 * The adapter->erp_lock has to be held.
320 void zfcp_dbf_rec_trig(char *tag, struct zfcp_adapter *adapter,
321 struct zfcp_port *port, struct scsi_device *sdev,
324 struct zfcp_dbf *dbf = adapter->dbf;
325 struct zfcp_dbf_rec *rec = &dbf->rec_buf;
326 static int const level = 1;
327 struct list_head *entry;
330 lockdep_assert_held(&adapter->erp_lock);
332 if (unlikely(!debug_level_enabled(dbf->rec, level)))
335 spin_lock_irqsave(&dbf->rec_lock, flags);
336 memset(rec, 0, sizeof(*rec));
338 rec->id = ZFCP_DBF_REC_TRIG;
339 memcpy(rec->tag, tag, ZFCP_DBF_TAG_LEN);
340 zfcp_dbf_set_common(rec, adapter, port, sdev);
342 list_for_each(entry, &adapter->erp_ready_head)
345 list_for_each(entry, &adapter->erp_running_head)
346 rec->u.trig.running++;
348 rec->u.trig.want = want;
349 rec->u.trig.need = need;
351 debug_event(dbf->rec, level, rec, sizeof(*rec));
352 spin_unlock_irqrestore(&dbf->rec_lock, flags);
356 * zfcp_dbf_rec_trig_lock - trace event related to triggered recovery with lock
357 * @tag: identifier for event
358 * @adapter: adapter on which the erp_action should run
359 * @port: remote port involved in the erp_action
360 * @sdev: scsi device involved in the erp_action
361 * @want: wanted erp_action
362 * @need: required erp_action
364 * The adapter->erp_lock must not be held.
366 void zfcp_dbf_rec_trig_lock(char *tag, struct zfcp_adapter *adapter,
367 struct zfcp_port *port, struct scsi_device *sdev,
372 read_lock_irqsave(&adapter->erp_lock, flags);
373 zfcp_dbf_rec_trig(tag, adapter, port, sdev, want, need);
374 read_unlock_irqrestore(&adapter->erp_lock, flags);
378 * zfcp_dbf_rec_run_lvl - trace event related to running recovery
379 * @level: trace level to be used for event
380 * @tag: identifier for event
381 * @erp: erp_action running
383 void zfcp_dbf_rec_run_lvl(int level, char *tag, struct zfcp_erp_action *erp)
385 struct zfcp_dbf *dbf = erp->adapter->dbf;
386 struct zfcp_dbf_rec *rec = &dbf->rec_buf;
389 if (!debug_level_enabled(dbf->rec, level))
392 spin_lock_irqsave(&dbf->rec_lock, flags);
393 memset(rec, 0, sizeof(*rec));
395 rec->id = ZFCP_DBF_REC_RUN;
396 memcpy(rec->tag, tag, ZFCP_DBF_TAG_LEN);
397 zfcp_dbf_set_common(rec, erp->adapter, erp->port, erp->sdev);
399 rec->u.run.fsf_req_id = erp->fsf_req_id;
400 rec->u.run.rec_status = erp->status;
401 rec->u.run.rec_step = erp->step;
402 rec->u.run.rec_action = erp->type;
405 rec->u.run.rec_count =
406 atomic_read(&sdev_to_zfcp(erp->sdev)->erp_counter);
408 rec->u.run.rec_count = atomic_read(&erp->port->erp_counter);
410 rec->u.run.rec_count = atomic_read(&erp->adapter->erp_counter);
412 debug_event(dbf->rec, level, rec, sizeof(*rec));
413 spin_unlock_irqrestore(&dbf->rec_lock, flags);
417 * zfcp_dbf_rec_run - trace event related to running recovery
418 * @tag: identifier for event
419 * @erp: erp_action running
421 void zfcp_dbf_rec_run(char *tag, struct zfcp_erp_action *erp)
423 zfcp_dbf_rec_run_lvl(1, tag, erp);
427 * zfcp_dbf_rec_run_wka - trace wka port event with info like running recovery
428 * @tag: identifier for event
429 * @wka_port: well known address port
430 * @req_id: request ID to correlate with potential HBA trace record
432 void zfcp_dbf_rec_run_wka(char *tag, struct zfcp_fc_wka_port *wka_port,
435 struct zfcp_dbf *dbf = wka_port->adapter->dbf;
436 struct zfcp_dbf_rec *rec = &dbf->rec_buf;
437 static int const level = 1;
440 if (unlikely(!debug_level_enabled(dbf->rec, level)))
443 spin_lock_irqsave(&dbf->rec_lock, flags);
444 memset(rec, 0, sizeof(*rec));
446 rec->id = ZFCP_DBF_REC_RUN;
447 memcpy(rec->tag, tag, ZFCP_DBF_TAG_LEN);
448 rec->port_status = wka_port->status;
449 rec->d_id = wka_port->d_id;
450 rec->lun = ZFCP_DBF_INVALID_LUN;
452 rec->u.run.fsf_req_id = req_id;
453 rec->u.run.rec_status = ~0;
454 rec->u.run.rec_step = ~0;
455 rec->u.run.rec_action = ~0;
456 rec->u.run.rec_count = ~0;
458 debug_event(dbf->rec, level, rec, sizeof(*rec));
459 spin_unlock_irqrestore(&dbf->rec_lock, flags);
462 #define ZFCP_DBF_SAN_LEVEL 1
465 void zfcp_dbf_san(char *tag, struct zfcp_dbf *dbf,
466 char *paytag, struct scatterlist *sg, u8 id, u16 len,
467 u64 req_id, u32 d_id, u16 cap_len)
469 struct zfcp_dbf_san *rec = &dbf->san_buf;
472 struct zfcp_dbf_pay *payload = &dbf->pay_buf;
475 spin_lock_irqsave(&dbf->san_lock, flags);
476 memset(rec, 0, sizeof(*rec));
479 rec->fsf_req_id = req_id;
481 memcpy(rec->tag, tag, ZFCP_DBF_TAG_LEN);
482 rec->pl_len = len; /* full length even if we cap pay below */
485 rec_len = min_t(unsigned int, sg->length, ZFCP_DBF_SAN_MAX_PAYLOAD);
486 memcpy(rec->payload, sg_virt(sg), rec_len); /* part of 1st sg entry */
488 goto out; /* skip pay record if full content in rec->payload */
490 /* if (len > rec_len):
491 * dump data up to cap_len ignoring small duplicate in rec->payload
493 spin_lock(&dbf->pay_lock);
494 memset(payload, 0, sizeof(*payload));
495 memcpy(payload->area, paytag, ZFCP_DBF_TAG_LEN);
496 payload->fsf_req_id = req_id;
497 payload->counter = 0;
498 for (; sg && pay_sum < cap_len; sg = sg_next(sg)) {
499 u16 pay_len, offset = 0;
501 while (offset < sg->length && pay_sum < cap_len) {
502 pay_len = min((u16)ZFCP_DBF_PAY_MAX_REC,
503 (u16)(sg->length - offset));
504 /* cap_len <= pay_sum < cap_len+ZFCP_DBF_PAY_MAX_REC */
505 memcpy(payload->data, sg_virt(sg) + offset, pay_len);
506 debug_event(dbf->pay, ZFCP_DBF_SAN_LEVEL, payload,
507 zfcp_dbf_plen(pay_len));
513 spin_unlock(&dbf->pay_lock);
516 debug_event(dbf->san, ZFCP_DBF_SAN_LEVEL, rec, sizeof(*rec));
517 spin_unlock_irqrestore(&dbf->san_lock, flags);
521 * zfcp_dbf_san_req - trace event for issued SAN request
522 * @tag: identifier for event
523 * @fsf: request containing issued CT or ELS data
524 * @d_id: N_Port_ID where SAN request is sent to
525 * d_id: destination ID
527 void zfcp_dbf_san_req(char *tag, struct zfcp_fsf_req *fsf, u32 d_id)
529 struct zfcp_dbf *dbf = fsf->adapter->dbf;
530 struct zfcp_fsf_ct_els *ct_els = fsf->data;
533 if (unlikely(!debug_level_enabled(dbf->san, ZFCP_DBF_SAN_LEVEL)))
536 length = (u16)zfcp_qdio_real_bytes(ct_els->req);
537 zfcp_dbf_san(tag, dbf, "san_req", ct_els->req, ZFCP_DBF_SAN_REQ,
538 length, fsf->req_id, d_id, length);
541 static u16 zfcp_dbf_san_res_cap_len_if_gpn_ft(char *tag,
542 struct zfcp_fsf_req *fsf,
545 struct zfcp_fsf_ct_els *ct_els = fsf->data;
546 struct fc_ct_hdr *reqh = sg_virt(ct_els->req);
547 struct fc_ns_gid_ft *reqn = (struct fc_ns_gid_ft *)(reqh + 1);
548 struct scatterlist *resp_entry = ct_els->resp;
549 struct fc_ct_hdr *resph;
550 struct fc_gpn_ft_resp *acc;
551 int max_entries, x, last = 0;
553 if (!(memcmp(tag, "fsscth2", 7) == 0
554 && ct_els->d_id == FC_FID_DIR_SERV
555 && reqh->ct_rev == FC_CT_REV
556 && reqh->ct_in_id[0] == 0
557 && reqh->ct_in_id[1] == 0
558 && reqh->ct_in_id[2] == 0
559 && reqh->ct_fs_type == FC_FST_DIR
560 && reqh->ct_fs_subtype == FC_NS_SUBTYPE
561 && reqh->ct_options == 0
562 && reqh->_ct_resvd1 == 0
563 && reqh->ct_cmd == cpu_to_be16(FC_NS_GPN_FT)
564 /* reqh->ct_mr_size can vary so do not match but read below */
565 && reqh->_ct_resvd2 == 0
566 && reqh->ct_reason == 0
567 && reqh->ct_explan == 0
568 && reqh->ct_vendor == 0
569 && reqn->fn_resvd == 0
570 && reqn->fn_domain_id_scope == 0
571 && reqn->fn_area_id_scope == 0
572 && reqn->fn_fc4_type == FC_TYPE_FCP))
573 return len; /* not GPN_FT response so do not cap */
575 acc = sg_virt(resp_entry);
577 /* cap all but accept CT responses to at least the CT header */
578 resph = (struct fc_ct_hdr *)acc;
579 if ((ct_els->status) ||
580 (resph->ct_cmd != cpu_to_be16(FC_FS_ACC)))
581 return max(FC_CT_HDR_LEN, ZFCP_DBF_SAN_MAX_PAYLOAD);
583 max_entries = (be16_to_cpu(reqh->ct_mr_size) * 4 /
584 sizeof(struct fc_gpn_ft_resp))
585 + 1 /* zfcp_fc_scan_ports: bytes correct, entries off-by-one
586 * to account for header as 1st pseudo "entry" */;
588 /* the basic CT_IU preamble is the same size as one entry in the GPN_FT
589 * response, allowing us to skip special handling for it - just skip it
591 for (x = 1; x < max_entries && !last; x++) {
592 if (x % (ZFCP_FC_GPN_FT_ENT_PAGE + 1))
595 acc = sg_virt(++resp_entry);
597 last = acc->fp_flags & FC_NS_FID_LAST;
599 len = min(len, (u16)(x * sizeof(struct fc_gpn_ft_resp)));
600 return len; /* cap after last entry */
604 * zfcp_dbf_san_res - trace event for received SAN request
605 * @tag: identifier for event
606 * @fsf: request containing received CT or ELS data
608 void zfcp_dbf_san_res(char *tag, struct zfcp_fsf_req *fsf)
610 struct zfcp_dbf *dbf = fsf->adapter->dbf;
611 struct zfcp_fsf_ct_els *ct_els = fsf->data;
614 if (unlikely(!debug_level_enabled(dbf->san, ZFCP_DBF_SAN_LEVEL)))
617 length = (u16)zfcp_qdio_real_bytes(ct_els->resp);
618 zfcp_dbf_san(tag, dbf, "san_res", ct_els->resp, ZFCP_DBF_SAN_RES,
619 length, fsf->req_id, ct_els->d_id,
620 zfcp_dbf_san_res_cap_len_if_gpn_ft(tag, fsf, length));
624 * zfcp_dbf_san_in_els - trace event for incoming ELS
625 * @tag: identifier for event
626 * @fsf: request containing received ELS data
628 void zfcp_dbf_san_in_els(char *tag, struct zfcp_fsf_req *fsf)
630 struct zfcp_dbf *dbf = fsf->adapter->dbf;
631 struct fsf_status_read_buffer *srb =
632 (struct fsf_status_read_buffer *) fsf->data;
634 struct scatterlist sg;
636 if (unlikely(!debug_level_enabled(dbf->san, ZFCP_DBF_SAN_LEVEL)))
639 length = (u16)(srb->length -
640 offsetof(struct fsf_status_read_buffer, payload));
641 sg_init_one(&sg, srb->payload.data, length);
642 zfcp_dbf_san(tag, dbf, "san_els", &sg, ZFCP_DBF_SAN_ELS, length,
643 fsf->req_id, ntoh24(srb->d_id), length);
647 * zfcp_dbf_scsi_common() - Common trace event helper for scsi.
648 * @tag: Identifier for event.
649 * @level: trace level of event.
650 * @sdev: Pointer to SCSI device as context for this event.
651 * @sc: Pointer to SCSI command, or NULL with task management function (TMF).
652 * @fsf: Pointer to FSF request, or NULL.
654 void zfcp_dbf_scsi_common(char *tag, int level, struct scsi_device *sdev,
655 struct scsi_cmnd *sc, struct zfcp_fsf_req *fsf)
657 struct zfcp_adapter *adapter =
658 (struct zfcp_adapter *) sdev->host->hostdata[0];
659 struct zfcp_dbf *dbf = adapter->dbf;
660 struct zfcp_dbf_scsi *rec = &dbf->scsi_buf;
661 struct fcp_resp_with_ext *fcp_rsp;
662 struct fcp_resp_rsp_info *fcp_rsp_info;
665 spin_lock_irqsave(&dbf->scsi_lock, flags);
666 memset(rec, 0, sizeof(*rec));
668 memcpy(rec->tag, tag, ZFCP_DBF_TAG_LEN);
669 rec->id = ZFCP_DBF_SCSI_CMND;
671 rec->scsi_result = sc->result;
672 rec->scsi_retries = sc->retries;
673 rec->scsi_allowed = sc->allowed;
674 rec->scsi_id = sc->device->id;
675 rec->scsi_lun = (u32)sc->device->lun;
676 rec->scsi_lun_64_hi = (u32)(sc->device->lun >> 32);
677 rec->host_scribble = (unsigned long)sc->host_scribble;
679 memcpy(rec->scsi_opcode, sc->cmnd,
680 min_t(int, sc->cmd_len, ZFCP_DBF_SCSI_OPCODE));
682 rec->scsi_result = ~0;
683 rec->scsi_retries = ~0;
684 rec->scsi_allowed = ~0;
685 rec->scsi_id = sdev->id;
686 rec->scsi_lun = (u32)sdev->lun;
687 rec->scsi_lun_64_hi = (u32)(sdev->lun >> 32);
688 rec->host_scribble = ~0;
690 memset(rec->scsi_opcode, 0xff, ZFCP_DBF_SCSI_OPCODE);
694 rec->fsf_req_id = fsf->req_id;
695 rec->pl_len = FCP_RESP_WITH_EXT;
696 fcp_rsp = &(fsf->qtcb->bottom.io.fcp_rsp.iu);
697 /* mandatory parts of FCP_RSP IU in this SCSI record */
698 memcpy(&rec->fcp_rsp, fcp_rsp, FCP_RESP_WITH_EXT);
699 if (fcp_rsp->resp.fr_flags & FCP_RSP_LEN_VAL) {
700 fcp_rsp_info = (struct fcp_resp_rsp_info *) &fcp_rsp[1];
701 rec->fcp_rsp_info = fcp_rsp_info->rsp_code;
702 rec->pl_len += be32_to_cpu(fcp_rsp->ext.fr_rsp_len);
704 if (fcp_rsp->resp.fr_flags & FCP_SNS_LEN_VAL) {
705 rec->pl_len += be32_to_cpu(fcp_rsp->ext.fr_sns_len);
707 /* complete FCP_RSP IU in associated PAYload record
708 * but only if there are optional parts
710 if (fcp_rsp->resp.fr_flags != 0)
713 /* at least one full PAY record
714 * but not beyond hardware response field
716 min_t(u16, max_t(u16, rec->pl_len,
717 ZFCP_DBF_PAY_MAX_REC),
719 "fcp_riu", fsf->req_id);
722 debug_event(dbf->scsi, level, rec, sizeof(*rec));
723 spin_unlock_irqrestore(&dbf->scsi_lock, flags);
727 * zfcp_dbf_scsi_eh() - Trace event for special cases of scsi_eh callbacks.
728 * @tag: Identifier for event.
729 * @adapter: Pointer to zfcp adapter as context for this event.
730 * @scsi_id: SCSI ID/target to indicate scope of task management function (TMF).
731 * @ret: Return value of calling function.
733 * This SCSI trace variant does not depend on any of:
734 * scsi_cmnd, zfcp_fsf_req, scsi_device.
736 void zfcp_dbf_scsi_eh(char *tag, struct zfcp_adapter *adapter,
737 unsigned int scsi_id, int ret)
739 struct zfcp_dbf *dbf = adapter->dbf;
740 struct zfcp_dbf_scsi *rec = &dbf->scsi_buf;
742 static int const level = 1;
744 if (unlikely(!debug_level_enabled(adapter->dbf->scsi, level)))
747 spin_lock_irqsave(&dbf->scsi_lock, flags);
748 memset(rec, 0, sizeof(*rec));
750 memcpy(rec->tag, tag, ZFCP_DBF_TAG_LEN);
751 rec->id = ZFCP_DBF_SCSI_CMND;
752 rec->scsi_result = ret; /* re-use field, int is 4 bytes and fits */
753 rec->scsi_retries = ~0;
754 rec->scsi_allowed = ~0;
755 rec->fcp_rsp_info = ~0;
756 rec->scsi_id = scsi_id;
757 rec->scsi_lun = (u32)ZFCP_DBF_INVALID_LUN;
758 rec->scsi_lun_64_hi = (u32)(ZFCP_DBF_INVALID_LUN >> 32);
759 rec->host_scribble = ~0;
760 memset(rec->scsi_opcode, 0xff, ZFCP_DBF_SCSI_OPCODE);
762 debug_event(dbf->scsi, level, rec, sizeof(*rec));
763 spin_unlock_irqrestore(&dbf->scsi_lock, flags);
766 static debug_info_t *zfcp_dbf_reg(const char *name, int size, int rec_size)
768 struct debug_info *d;
770 d = debug_register(name, size, 1, rec_size);
774 debug_register_view(d, &debug_hex_ascii_view);
775 debug_set_level(d, dbflevel);
780 static void zfcp_dbf_unregister(struct zfcp_dbf *dbf)
785 debug_unregister(dbf->scsi);
786 debug_unregister(dbf->san);
787 debug_unregister(dbf->hba);
788 debug_unregister(dbf->pay);
789 debug_unregister(dbf->rec);
794 * zfcp_adapter_debug_register - registers debug feature for an adapter
795 * @adapter: pointer to adapter for which debug features should be registered
796 * return: -ENOMEM on error, 0 otherwise
798 int zfcp_dbf_adapter_register(struct zfcp_adapter *adapter)
800 char name[DEBUG_MAX_NAME_LEN];
801 struct zfcp_dbf *dbf;
803 dbf = kzalloc(sizeof(struct zfcp_dbf), GFP_KERNEL);
807 spin_lock_init(&dbf->pay_lock);
808 spin_lock_init(&dbf->hba_lock);
809 spin_lock_init(&dbf->san_lock);
810 spin_lock_init(&dbf->scsi_lock);
811 spin_lock_init(&dbf->rec_lock);
813 /* debug feature area which records recovery activity */
814 sprintf(name, "zfcp_%s_rec", dev_name(&adapter->ccw_device->dev));
815 dbf->rec = zfcp_dbf_reg(name, dbfsize, sizeof(struct zfcp_dbf_rec));
819 /* debug feature area which records HBA (FSF and QDIO) conditions */
820 sprintf(name, "zfcp_%s_hba", dev_name(&adapter->ccw_device->dev));
821 dbf->hba = zfcp_dbf_reg(name, dbfsize, sizeof(struct zfcp_dbf_hba));
825 /* debug feature area which records payload info */
826 sprintf(name, "zfcp_%s_pay", dev_name(&adapter->ccw_device->dev));
827 dbf->pay = zfcp_dbf_reg(name, dbfsize * 2, sizeof(struct zfcp_dbf_pay));
831 /* debug feature area which records SAN command failures and recovery */
832 sprintf(name, "zfcp_%s_san", dev_name(&adapter->ccw_device->dev));
833 dbf->san = zfcp_dbf_reg(name, dbfsize, sizeof(struct zfcp_dbf_san));
837 /* debug feature area which records SCSI command failures and recovery */
838 sprintf(name, "zfcp_%s_scsi", dev_name(&adapter->ccw_device->dev));
839 dbf->scsi = zfcp_dbf_reg(name, dbfsize, sizeof(struct zfcp_dbf_scsi));
847 zfcp_dbf_unregister(dbf);
852 * zfcp_adapter_debug_unregister - unregisters debug feature for an adapter
853 * @adapter: pointer to adapter for which debug features should be unregistered
855 void zfcp_dbf_adapter_unregister(struct zfcp_adapter *adapter)
857 struct zfcp_dbf *dbf = adapter->dbf;
860 zfcp_dbf_unregister(dbf);