4 * Debug traces for zfcp.
6 * Copyright IBM Corporation 2002, 2010
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 inline unsigned int zfcp_dbf_plen(unsigned int offset
)
28 return sizeof(struct zfcp_dbf_pay
) + offset
- ZFCP_DBF_PAY_MAX_REC
;
32 void zfcp_dbf_pl_write(struct zfcp_dbf
*dbf
, void *data
, u16 length
, char *area
,
35 struct zfcp_dbf_pay
*pl
= &dbf
->pay_buf
;
36 u16 offset
= 0, rec_length
;
38 spin_lock(&dbf
->pay_lock
);
39 memset(pl
, 0, sizeof(*pl
));
40 pl
->fsf_req_id
= req_id
;
41 memcpy(pl
->area
, area
, ZFCP_DBF_TAG_LEN
);
43 while (offset
< length
) {
44 rec_length
= min((u16
) ZFCP_DBF_PAY_MAX_REC
,
45 (u16
) (length
- offset
));
46 memcpy(pl
->data
, data
+ offset
, rec_length
);
47 debug_event(dbf
->pay
, 1, pl
, zfcp_dbf_plen(rec_length
));
53 spin_unlock(&dbf
->pay_lock
);
57 * zfcp_dbf_hba_fsf_res - trace event for fsf responses
58 * @tag: tag indicating which kind of unsolicited status has been received
59 * @req: request for which a response was received
61 void zfcp_dbf_hba_fsf_res(char *tag
, struct zfcp_fsf_req
*req
)
63 struct zfcp_dbf
*dbf
= req
->adapter
->dbf
;
64 struct fsf_qtcb_prefix
*q_pref
= &req
->qtcb
->prefix
;
65 struct fsf_qtcb_header
*q_head
= &req
->qtcb
->header
;
66 struct zfcp_dbf_hba
*rec
= &dbf
->hba_buf
;
69 spin_lock_irqsave(&dbf
->hba_lock
, flags
);
70 memset(rec
, 0, sizeof(*rec
));
72 memcpy(rec
->tag
, tag
, ZFCP_DBF_TAG_LEN
);
73 rec
->id
= ZFCP_DBF_HBA_RES
;
74 rec
->fsf_req_id
= req
->req_id
;
75 rec
->fsf_req_status
= req
->status
;
76 rec
->fsf_cmd
= req
->fsf_command
;
77 rec
->fsf_seq_no
= req
->seq_no
;
78 rec
->u
.res
.req_issued
= req
->issued
;
79 rec
->u
.res
.prot_status
= q_pref
->prot_status
;
80 rec
->u
.res
.fsf_status
= q_head
->fsf_status
;
82 memcpy(rec
->u
.res
.prot_status_qual
, &q_pref
->prot_status_qual
,
83 FSF_PROT_STATUS_QUAL_SIZE
);
84 memcpy(rec
->u
.res
.fsf_status_qual
, &q_head
->fsf_status_qual
,
85 FSF_STATUS_QUALIFIER_SIZE
);
87 if (req
->fsf_command
!= FSF_QTCB_FCP_CMND
) {
88 rec
->pl_len
= q_head
->log_length
;
89 zfcp_dbf_pl_write(dbf
, (char *)q_pref
+ q_head
->log_start
,
90 rec
->pl_len
, "fsf_res", req
->req_id
);
93 debug_event(dbf
->hba
, 1, rec
, sizeof(*rec
));
94 spin_unlock_irqrestore(&dbf
->hba_lock
, flags
);
98 * zfcp_dbf_hba_fsf_uss - trace event for an unsolicited status buffer
99 * @tag: tag indicating which kind of unsolicited status has been received
100 * @req: request providing the unsolicited status
102 void zfcp_dbf_hba_fsf_uss(char *tag
, struct zfcp_fsf_req
*req
)
104 struct zfcp_dbf
*dbf
= req
->adapter
->dbf
;
105 struct fsf_status_read_buffer
*srb
= req
->data
;
106 struct zfcp_dbf_hba
*rec
= &dbf
->hba_buf
;
109 spin_lock_irqsave(&dbf
->hba_lock
, flags
);
110 memset(rec
, 0, sizeof(*rec
));
112 memcpy(rec
->tag
, tag
, ZFCP_DBF_TAG_LEN
);
113 rec
->id
= ZFCP_DBF_HBA_USS
;
114 rec
->fsf_req_id
= req
->req_id
;
115 rec
->fsf_req_status
= req
->status
;
116 rec
->fsf_cmd
= req
->fsf_command
;
121 rec
->u
.uss
.status_type
= srb
->status_type
;
122 rec
->u
.uss
.status_subtype
= srb
->status_subtype
;
123 rec
->u
.uss
.d_id
= ntoh24(srb
->d_id
);
124 rec
->u
.uss
.lun
= srb
->fcp_lun
;
125 memcpy(&rec
->u
.uss
.queue_designator
, &srb
->queue_designator
,
126 sizeof(rec
->u
.uss
.queue_designator
));
128 /* status read buffer payload length */
129 rec
->pl_len
= (!srb
->length
) ? 0 : srb
->length
-
130 offsetof(struct fsf_status_read_buffer
, payload
);
133 zfcp_dbf_pl_write(dbf
, srb
->payload
.data
, rec
->pl_len
,
134 "fsf_uss", req
->req_id
);
136 debug_event(dbf
->hba
, 2, rec
, sizeof(*rec
));
137 spin_unlock_irqrestore(&dbf
->hba_lock
, flags
);
141 * zfcp_dbf_hba_bit_err - trace event for bit error conditions
142 * @tag: tag indicating which kind of unsolicited status has been received
143 * @req: request which caused the bit_error condition
145 void zfcp_dbf_hba_bit_err(char *tag
, struct zfcp_fsf_req
*req
)
147 struct zfcp_dbf
*dbf
= req
->adapter
->dbf
;
148 struct zfcp_dbf_hba
*rec
= &dbf
->hba_buf
;
149 struct fsf_status_read_buffer
*sr_buf
= req
->data
;
152 spin_lock_irqsave(&dbf
->hba_lock
, flags
);
153 memset(rec
, 0, sizeof(*rec
));
155 memcpy(rec
->tag
, tag
, ZFCP_DBF_TAG_LEN
);
156 rec
->id
= ZFCP_DBF_HBA_BIT
;
157 rec
->fsf_req_id
= req
->req_id
;
158 rec
->fsf_req_status
= req
->status
;
159 rec
->fsf_cmd
= req
->fsf_command
;
160 memcpy(&rec
->u
.be
, &sr_buf
->payload
.bit_error
,
161 sizeof(struct fsf_bit_error_payload
));
163 debug_event(dbf
->hba
, 1, rec
, sizeof(*rec
));
164 spin_unlock_irqrestore(&dbf
->hba_lock
, flags
);
167 static void zfcp_dbf_set_common(struct zfcp_dbf_rec
*rec
,
168 struct zfcp_adapter
*adapter
,
169 struct zfcp_port
*port
,
170 struct scsi_device
*sdev
)
172 rec
->adapter_status
= atomic_read(&adapter
->status
);
174 rec
->port_status
= atomic_read(&port
->status
);
175 rec
->wwpn
= port
->wwpn
;
176 rec
->d_id
= port
->d_id
;
179 rec
->lun_status
= atomic_read(&sdev_to_zfcp(sdev
)->status
);
180 rec
->lun
= zfcp_scsi_dev_lun(sdev
);
185 * zfcp_dbf_rec_trig - trace event related to triggered recovery
186 * @tag: identifier for event
187 * @adapter: adapter on which the erp_action should run
188 * @port: remote port involved in the erp_action
189 * @sdev: scsi device involved in the erp_action
190 * @want: wanted erp_action
191 * @need: required erp_action
193 * The adapter->erp_lock has to be held.
195 void zfcp_dbf_rec_trig(char *tag
, struct zfcp_adapter
*adapter
,
196 struct zfcp_port
*port
, struct scsi_device
*sdev
,
199 struct zfcp_dbf
*dbf
= adapter
->dbf
;
200 struct zfcp_dbf_rec
*rec
= &dbf
->rec_buf
;
201 struct list_head
*entry
;
204 spin_lock_irqsave(&dbf
->rec_lock
, flags
);
205 memset(rec
, 0, sizeof(*rec
));
207 rec
->id
= ZFCP_DBF_REC_TRIG
;
208 memcpy(rec
->tag
, tag
, ZFCP_DBF_TAG_LEN
);
209 zfcp_dbf_set_common(rec
, adapter
, port
, sdev
);
211 list_for_each(entry
, &adapter
->erp_ready_head
)
214 list_for_each(entry
, &adapter
->erp_running_head
)
215 rec
->u
.trig
.running
++;
217 rec
->u
.trig
.want
= want
;
218 rec
->u
.trig
.need
= need
;
220 debug_event(dbf
->rec
, 1, rec
, sizeof(*rec
));
221 spin_unlock_irqrestore(&dbf
->rec_lock
, flags
);
226 * zfcp_dbf_rec_run - trace event related to running recovery
227 * @tag: identifier for event
228 * @erp: erp_action running
230 void zfcp_dbf_rec_run(char *tag
, struct zfcp_erp_action
*erp
)
232 struct zfcp_dbf
*dbf
= erp
->adapter
->dbf
;
233 struct zfcp_dbf_rec
*rec
= &dbf
->rec_buf
;
236 spin_lock_irqsave(&dbf
->rec_lock
, flags
);
237 memset(rec
, 0, sizeof(*rec
));
239 rec
->id
= ZFCP_DBF_REC_RUN
;
240 memcpy(rec
->tag
, tag
, ZFCP_DBF_TAG_LEN
);
241 zfcp_dbf_set_common(rec
, erp
->adapter
, erp
->port
, erp
->sdev
);
243 rec
->u
.run
.fsf_req_id
= erp
->fsf_req_id
;
244 rec
->u
.run
.rec_status
= erp
->status
;
245 rec
->u
.run
.rec_step
= erp
->step
;
246 rec
->u
.run
.rec_action
= erp
->action
;
249 rec
->u
.run
.rec_count
=
250 atomic_read(&sdev_to_zfcp(erp
->sdev
)->erp_counter
);
252 rec
->u
.run
.rec_count
= atomic_read(&erp
->port
->erp_counter
);
254 rec
->u
.run
.rec_count
= atomic_read(&erp
->adapter
->erp_counter
);
256 debug_event(dbf
->rec
, 1, rec
, sizeof(*rec
));
257 spin_unlock_irqrestore(&dbf
->rec_lock
, flags
);
261 void zfcp_dbf_san(char *tag
, struct zfcp_dbf
*dbf
, void *data
, u8 id
, u16 len
,
262 u64 req_id
, u32 d_id
)
264 struct zfcp_dbf_san
*rec
= &dbf
->san_buf
;
268 spin_lock_irqsave(&dbf
->san_lock
, flags
);
269 memset(rec
, 0, sizeof(*rec
));
272 rec
->fsf_req_id
= req_id
;
274 rec_len
= min(len
, (u16
)ZFCP_DBF_SAN_MAX_PAYLOAD
);
275 memcpy(rec
->payload
, data
, rec_len
);
276 memcpy(rec
->tag
, tag
, ZFCP_DBF_TAG_LEN
);
278 debug_event(dbf
->san
, 1, rec
, sizeof(*rec
));
279 spin_unlock_irqrestore(&dbf
->san_lock
, flags
);
283 * zfcp_dbf_san_req - trace event for issued SAN request
284 * @tag: indentifier for event
285 * @fsf_req: request containing issued CT data
286 * d_id: destination ID
288 void zfcp_dbf_san_req(char *tag
, struct zfcp_fsf_req
*fsf
, u32 d_id
)
290 struct zfcp_dbf
*dbf
= fsf
->adapter
->dbf
;
291 struct zfcp_fsf_ct_els
*ct_els
= fsf
->data
;
294 length
= (u16
)(ct_els
->req
->length
+ FC_CT_HDR_LEN
);
295 zfcp_dbf_san(tag
, dbf
, sg_virt(ct_els
->req
), ZFCP_DBF_SAN_REQ
, length
,
300 * zfcp_dbf_san_res - trace event for received SAN request
301 * @tag: indentifier for event
302 * @fsf_req: request containing issued CT data
304 void zfcp_dbf_san_res(char *tag
, struct zfcp_fsf_req
*fsf
)
306 struct zfcp_dbf
*dbf
= fsf
->adapter
->dbf
;
307 struct zfcp_fsf_ct_els
*ct_els
= fsf
->data
;
310 length
= (u16
)(ct_els
->resp
->length
+ FC_CT_HDR_LEN
);
311 zfcp_dbf_san(tag
, dbf
, sg_virt(ct_els
->resp
), ZFCP_DBF_SAN_RES
, length
,
316 * zfcp_dbf_san_in_els - trace event for incoming ELS
317 * @tag: indentifier for event
318 * @fsf_req: request containing issued CT data
320 void zfcp_dbf_san_in_els(char *tag
, struct zfcp_fsf_req
*fsf
)
322 struct zfcp_dbf
*dbf
= fsf
->adapter
->dbf
;
323 struct fsf_status_read_buffer
*srb
=
324 (struct fsf_status_read_buffer
*) fsf
->data
;
327 length
= (u16
)(srb
->length
-
328 offsetof(struct fsf_status_read_buffer
, payload
));
329 zfcp_dbf_san(tag
, dbf
, srb
->payload
.data
, ZFCP_DBF_SAN_ELS
, length
,
330 fsf
->req_id
, ntoh24(srb
->d_id
));
334 * zfcp_dbf_scsi - trace event for scsi commands
335 * @tag: identifier for event
336 * @sc: pointer to struct scsi_cmnd
337 * @fsf: pointer to struct zfcp_fsf_req
339 void zfcp_dbf_scsi(char *tag
, struct scsi_cmnd
*sc
, struct zfcp_fsf_req
*fsf
)
341 struct zfcp_adapter
*adapter
=
342 (struct zfcp_adapter
*) sc
->device
->host
->hostdata
[0];
343 struct zfcp_dbf
*dbf
= adapter
->dbf
;
344 struct zfcp_dbf_scsi
*rec
= &dbf
->scsi_buf
;
345 struct fcp_resp_with_ext
*fcp_rsp
;
346 struct fcp_resp_rsp_info
*fcp_rsp_info
;
349 spin_lock_irqsave(&dbf
->scsi_lock
, flags
);
350 memset(rec
, 0, sizeof(*rec
));
352 memcpy(rec
->tag
, tag
, ZFCP_DBF_TAG_LEN
);
353 rec
->id
= ZFCP_DBF_SCSI_CMND
;
354 rec
->scsi_result
= sc
->result
;
355 rec
->scsi_retries
= sc
->retries
;
356 rec
->scsi_allowed
= sc
->allowed
;
357 rec
->scsi_id
= sc
->device
->id
;
358 rec
->scsi_lun
= sc
->device
->lun
;
359 rec
->host_scribble
= (unsigned long)sc
->host_scribble
;
361 memcpy(rec
->scsi_opcode
, sc
->cmnd
,
362 min((int)sc
->cmd_len
, ZFCP_DBF_SCSI_OPCODE
));
365 rec
->fsf_req_id
= fsf
->req_id
;
366 fcp_rsp
= (struct fcp_resp_with_ext
*)
367 &(fsf
->qtcb
->bottom
.io
.fcp_rsp
);
368 memcpy(&rec
->fcp_rsp
, fcp_rsp
, FCP_RESP_WITH_EXT
);
369 if (fcp_rsp
->resp
.fr_flags
& FCP_RSP_LEN_VAL
) {
370 fcp_rsp_info
= (struct fcp_resp_rsp_info
*) &fcp_rsp
[1];
371 rec
->fcp_rsp_info
= fcp_rsp_info
->rsp_code
;
373 if (fcp_rsp
->resp
.fr_flags
& FCP_SNS_LEN_VAL
) {
374 rec
->pl_len
= min((u16
)SCSI_SENSE_BUFFERSIZE
,
375 (u16
)ZFCP_DBF_PAY_MAX_REC
);
376 zfcp_dbf_pl_write(dbf
, sc
->sense_buffer
, rec
->pl_len
,
377 "fcp_sns", fsf
->req_id
);
381 debug_event(dbf
->scsi
, 1, rec
, sizeof(*rec
));
382 spin_unlock_irqrestore(&dbf
->scsi_lock
, flags
);
385 static debug_info_t
*zfcp_dbf_reg(const char *name
, int size
, int rec_size
)
387 struct debug_info
*d
;
389 d
= debug_register(name
, size
, 1, rec_size
);
393 debug_register_view(d
, &debug_hex_ascii_view
);
394 debug_set_level(d
, 3);
399 static void zfcp_dbf_unregister(struct zfcp_dbf
*dbf
)
404 debug_unregister(dbf
->scsi
);
405 debug_unregister(dbf
->san
);
406 debug_unregister(dbf
->hba
);
407 debug_unregister(dbf
->pay
);
408 debug_unregister(dbf
->rec
);
413 * zfcp_adapter_debug_register - registers debug feature for an adapter
414 * @adapter: pointer to adapter for which debug features should be registered
415 * return: -ENOMEM on error, 0 otherwise
417 int zfcp_dbf_adapter_register(struct zfcp_adapter
*adapter
)
419 char name
[DEBUG_MAX_NAME_LEN
];
420 struct zfcp_dbf
*dbf
;
422 dbf
= kzalloc(sizeof(struct zfcp_dbf
), GFP_KERNEL
);
426 spin_lock_init(&dbf
->pay_lock
);
427 spin_lock_init(&dbf
->hba_lock
);
428 spin_lock_init(&dbf
->san_lock
);
429 spin_lock_init(&dbf
->scsi_lock
);
430 spin_lock_init(&dbf
->rec_lock
);
432 /* debug feature area which records recovery activity */
433 sprintf(name
, "zfcp_%s_rec", dev_name(&adapter
->ccw_device
->dev
));
434 dbf
->rec
= zfcp_dbf_reg(name
, dbfsize
, sizeof(struct zfcp_dbf_rec
));
438 /* debug feature area which records HBA (FSF and QDIO) conditions */
439 sprintf(name
, "zfcp_%s_hba", dev_name(&adapter
->ccw_device
->dev
));
440 dbf
->hba
= zfcp_dbf_reg(name
, dbfsize
, sizeof(struct zfcp_dbf_hba
));
444 /* debug feature area which records payload info */
445 sprintf(name
, "zfcp_%s_pay", dev_name(&adapter
->ccw_device
->dev
));
446 dbf
->pay
= zfcp_dbf_reg(name
, dbfsize
* 2, sizeof(struct zfcp_dbf_pay
));
450 /* debug feature area which records SAN command failures and recovery */
451 sprintf(name
, "zfcp_%s_san", dev_name(&adapter
->ccw_device
->dev
));
452 dbf
->san
= zfcp_dbf_reg(name
, dbfsize
, sizeof(struct zfcp_dbf_san
));
456 /* debug feature area which records SCSI command failures and recovery */
457 sprintf(name
, "zfcp_%s_scsi", dev_name(&adapter
->ccw_device
->dev
));
458 dbf
->scsi
= zfcp_dbf_reg(name
, dbfsize
, sizeof(struct zfcp_dbf_scsi
));
466 zfcp_dbf_unregister(dbf
);
471 * zfcp_adapter_debug_unregister - unregisters debug feature for an adapter
472 * @adapter: pointer to adapter for which debug features should be unregistered
474 void zfcp_dbf_adapter_unregister(struct zfcp_adapter
*adapter
)
476 struct zfcp_dbf
*dbf
= adapter
->dbf
;
479 zfcp_dbf_unregister(dbf
);